parcel-bundler / lightningcss

An extremely fast CSS parser, transformer, bundler, and minifier written in Rust.
https://lightningcss.dev
Mozilla Public License 2.0
6.55k stars 190 forks source link

Support `@font-feature-values` #837

Open yisibl opened 1 month ago

yisibl commented 1 month ago
@font-feature-values Inter {
    @character-variant {
        cv05: 5;
        cv08: 8;
        cv10: 10;
    }
    @styleset {
        ss01: 1;
        ss08: 8;
    }
}

image

image

yisibl commented 1 month ago

Test case:

yisibl commented 1 month ago

Also, following the principle of retaining only the last-defined value, as well as the principle of shortest representation, multiply-specified tuples and multiple blocks are serialized as a single block containing only the last-defined value.

For example, the declaration: https://drafts.csswg.org/css-fonts/#ex-serialize-same-font-feature-values

/* Repeated declaration names, and multiple blocks of the same type*/
@font-feature-values foo {
  @swash { pretty: 0; cool: 2; }
  @swash { pretty: 1; }
}

would be serialized as:

/* Canonical serialization */
@font-feature-values foo {
    @swash { cool: 2; pretty: 1; }
}
yisibl commented 1 month ago

Note that when compressing, we also need to handle special versions of Firefox that don't remove the ending semicolon.

@font-feature-values FontName {
  font-display: whatever;
}

https://x.com/pjchrobak/status/1059229076987301888