Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request]: Minify unicode-ranges #1470

Open
1 task done
strarsis opened this issue Mar 5, 2023 · 5 comments
Open
1 task done

[Feature Request]: Minify unicode-ranges #1470

strarsis opened this issue Mar 5, 2023 · 5 comments

Comments

@strarsis
Copy link

strarsis commented Mar 5, 2023

What should be improved?

unicode-ranges can be minified by mixing codepoints, wildcards and ranges.

(https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/unicode-range)

Describe the solution you would like

Simplify unicode ranges as much as possible.

E.g. (ABCD 1234):
unicode-range: U+20,U+31,U+32,U+33,U+34,U+35,U+41,U+42,U+43,U+44;

Can be minified to:
unicode-range: U+20,U+31-35,U+41-44;

With a wildcard (e.g. @ABCDEFGHIJKLMNO):
unicode-range: U+40,U+41,U+42,U+43,U+44,U+45,U+46,U+47,U+48,U+49,U+4A,U+4B,U+4C,U+4D,U+4E,U+4F

Can be minified to a range:
unicode-range: U+40-4F;

And even to a wildcard, shorter yet:
unicode-range: U+4?;

Possible alternatives

Well, just not minifying unicode ranges, but this leaves basically risk-free minification on the table.

Additional context

The Unicode Range Interchange library/tool from @zachleat can already minify those unicode ranges,
so that functionality could be reused:
https://www.zachleat.com/unicode-range-interchange/
Though it does not support wildcards, which can minify even further, when applicable.

Are you willing to work on this?

  • Yes, I would like to help
@zachleat
Copy link

zachleat commented Mar 5, 2023

https://www.npmjs.com/package/characterset/ is the upstream dependency you want!

@strarsis
Copy link
Author

strarsis commented Mar 5, 2023

@zachleat: Thanks! I moved a related issue to that repository by the way: bramstein/characterset#5

@ludofischer
Copy link
Collaborator

Thank you for teaching me about yet another CSS 'descriptor'. My first instinct is to say that the size improvements are likely going to be negligible, as the unicode-range seems to be useful only inside @font-face, so it is unlikely that there are going to be many instances in a single stylesheet. cssnano can't include the https://www.npmjs.com/package/characterset/ as it seems to be ES6 only.

@zachleat
Copy link

fwiw if you use the 1.x release it works fine in CJS (and I’ve used it for many years)

@ben-eb
Copy link
Collaborator

ben-eb commented Nov 17, 2023

We do some of that already with https://github.com/cssnano/cssnano/tree/master/packages/postcss-normalize-unicode - the last example you mentioned with wildcards is already transformed 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants