Skip to content

Commit 804e825

Browse files
feat(css): lower a spelling the browserslist target cannot read (#21926)
* feat(css): lower a spelling the browserslist target cannot read The target's CSS abilities only ever held the printer back from reaching for a newer spelling; one the author had already written was left as it was, even where the selection says no target can read it. Each is now written the way the target does read it: a hex alpha as its `rgba()`, a media range as the `min-` / `max-` prefixes (an interval as the two bounds it names), `place-*` / two-value `overflow` / `inset` as their longhands, a two-position color stop as the two stops it names, and a multi-keyword `display` as the one keyword naming the same box. Each is refused where the longhands would not say what the shorthand does — a substitution across a slot boundary, a keyword only some of the longhands take — and a strict `>` / `<` media comparison is left alone, its negation being Media Queries 4 as much as the range spelling it would replace. * feat(css): write a fallback for a color the browserslist target cannot read A `lab()` / `lch()` / `oklab()` / `oklch()` / `hwb()` color only converts to hex where the two agree exactly, so a target reading none of those functions was left with a declaration it drops. The color each names is now written as an extra declaration before it — `color:#c65d06;color:oklch(59.686% .15619 49.7694)` — so the modern spelling still reaches the engines that read it while the others get a color. The two refusals the conversion makes are about replacing the function, not standing before it: a fallback is only ever read where there is no better answer, so it clips into the sRGB gamut and takes whichever byte rounding picks, and writes an `rgba()` where the target has no hex alpha either. Nothing is written where the author already set the property earlier in the block, where the color holds a relative reference or a call this cannot fold, or where the fallback would still name a function the target cannot read — the engine drops such a fallback exactly as it drops the declaration it precedes. `optimization.minimize.css.colorFallbacks` turns it off.
1 parent f6b470a commit 804e825

20 files changed

Lines changed: 1132 additions & 159 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webpack": minor
3+
---
4+
5+
Lower a CSS spelling a target cannot read and write a color fallback before one.

‎declarations/WebpackOptions.d.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,6 +2413,11 @@ export interface OptimizationMinimizeOptions {
24132413
* @since 5.110.0
24142414
*/
24152415
export interface OptimizationMinimizeCss {
2416+
/**
2417+
* Write a color the `browserslist` target cannot read as an extra declaration before the one naming it, in a spelling it does read: `color: oklch(59.686% 0.15619 49.7694)` is written as `color: #c65d06` and then the `oklch()` itself, so an engine reading neither the Lab family nor `hwb()` is left with a color rather than with nothing. The fallback is that color clipped into the sRGB gamut and rounded, which the declaration standing after it corrects wherever it is read. Nothing is written where the author already set the property earlier in the same block, where the color holds a substitution or a relative reference this cannot fold, or where the fallback would still name a function the target cannot read. On by default, and only in effect for a `browserslist` target — any other target names no browsers to answer for.
2418+
* @since 5.111.0
2419+
*/
2420+
colorFallbacks?: boolean;
24162421
/**
24172422
* Which comments survive. `"some"`, the default, keeps a `/*!` banner and a comment annotated `@license` or `@preserve`; `true` (or `"all"`) keeps every comment and `false` keeps none; a string is read as a regular expression source, and it, a `RegExp` or a `(comment) => boolean` predicate is asked about each comment's own text and keeps the ones it accepts — standing in for the default rule rather than beside it, as terser's `format.comments` does, so a pattern that names nothing else drops the ones `"some"` would have kept. A `/*#` source-map pragma is a link rather than a comment, so `"some"` and `"all"` keep it; `false`, a pattern or a predicate decides it like any other. A predicate is handed to the minimizer's worker pool as source, so it must not close over anything.
24182423
* @since 5.110.0

‎lib/css/data.js‎

Lines changed: 143 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,9 +1325,12 @@ const DISPLAY_SHORT_FORMS = new Map([
13251325
["block flow-root", "flow-root"],
13261326
["block grid", "grid"],
13271327
["block table", "table"],
1328+
["inline flex", "inline-flex"],
13281329
["inline flow", "inline"],
13291330
["inline flow-root", "inline-block"],
1331+
["inline grid", "inline-grid"],
13301332
["inline ruby", "ruby"],
1333+
["inline table", "inline-table"],
13311334
["run-in flow", "run-in"]
13321335
]);
13331336

@@ -4526,30 +4529,39 @@ const SUPPORT_PROFILES = new Float64Array([
45264529
6200000, 4900000, 6200000, 6200000, 7900000, 4900000, 1e15, 1e15, 900003,
45274530
4700000, 4900000, 1000000, 800000, 7200000, 8300000, 7200000, 7200000,
45284531
7900000, 8300000, 1e15, 1e15, 1200002, 5100000, 6000000, 1200001, 1100000,
4529-
8700000, 6600000, 8700000, 8700000, 8700000, 6600000, 1e15, 1e15, 1400005,
4530-
6200000, 7300000, 1400001, 1400000, 10400000, 10200000, 10400000, 10400000,
4531-
10400000, 10200000, 1e15, 1e15, 1600004, 7100000, 9000000, 1600004, 2000000,
4532-
6800000, 6100000, 6800000, 6800000, 7900000, 6100000, 1e15, 1e15, 1300004,
4533-
4800000, 5500000, 1300001, 1000000, 5900000, 4500000, 5900000, 5900000,
4534-
7900000, 4500000, 1e15, 1e15, 1100000, 4300000, 4600000, 1100000, 700000,
4535-
1800000, 400000, 400004, 100000, 1200000, 100005, 900000, 900000, 300002,
4536-
1000001, 700000, 400000, 100000, 3700000, 4700000, 3700000, 3700000, 7900000,
4537-
4700000, 1e15, 1e15, 1500004, 2400000, 2400000, 1500004, 300000, 1800000,
4538-
400000, 400004, 100000, 1200000, 100005, 900000, 900000, 300000, 1000001,
4539-
700000, 400000, 100000, 13300000, 1e15, 13300000, 13300000, 13300000, 1e15,
4540-
1e15, 1e15, 2700000, 8800000, 11800000, 2700000, 2900000, 2600000, 5500000,
4541-
400004, 2600000, 7900000, 5500000, 1e15, 1e15, 700000, 1400000, 1500000,
4542-
700000, 100005, 13100000, 14300000, 13100000, 13100000, 13100000, 14300000,
4543-
1e15, 1e15, 1800004, 8700000, 11600000, 1800004, 2900000, 8900000, 8200000,
4544-
8900000, 8900000, 8900000, 8200000, 1e15, 1e15, 1400005, 6300000, 7500000,
4545-
1400001, 1500000, 1800000, 400000, 3700000, 100000, 1200000, 100000, 900000,
4546-
900000, 100000, 1000001, 700000, 100000, 100000, 1800000, 400000, 400004,
4547-
100000, 1200000, 100000, 900000, 900000, 100000, 1000001, 700000, 100000,
4548-
100000, 12100000, 1e15, 12100000, 12100000, 12100000, 1e15, 1e15, 1e15,
4549-
1700004, 8100000, 10700000, 1700004, 2500000, 10500000, 14900000, 10500000,
4550-
10500000, 10500000, 14900000, 1e15, 1e15, 1700002, 7200000, 9100000, 1700002,
4551-
2000000, 8600000, 6800000, 8600000, 8600000, 8600000, 6800000, 1e15, 1e15,
4552-
1100003, 6100000, 7200000, 1100001, 1400000, 7300000, 7900000, 7300000,
4532+
11500000, 7900000, 11500000, 11500000, 11500000, 7000000, 1e15, 1e15, 1500000,
4533+
7700000, 10100000, 1500000, 2300000, 11100000, 11300000, 11100000, 11100000,
4534+
11100000, 11300000, 1e15, 1e15, 1500000, 7500000, 9700000, 1500000, 2200000,
4535+
11100000, 11300000, 11100000, 11100000, 11100000, 11300000, 1e15, 1e15,
4536+
1600002, 7500000, 9700000, 1600002, 2200000, 10100000, 9600000, 10100000,
4537+
10100000, 10100000, 9600000, 1e15, 1e15, 1500000, 7000000, 8700000, 1500000,
4538+
1900000, 12300000, 12000000, 12300000, 12300000, 12300000, 12000000, 1e15,
4539+
1e15, 1700005, 8200000, 10900000, 1700005, 2700000, 11100000, 11300000,
4540+
11100000, 11100000, 11100000, 11300000, 1e15, 1e15, 1500004, 7500000, 9700000,
4541+
1500004, 2200000, 8700000, 6600000, 8700000, 8700000, 8700000, 6600000, 1e15,
4542+
1e15, 1400005, 6200000, 7300000, 1400001, 1400000, 10400000, 10200000,
4543+
10400000, 10400000, 10400000, 10200000, 1e15, 1e15, 1600004, 7100000, 9000000,
4544+
1600004, 2000000, 6800000, 6100000, 6800000, 6800000, 7900000, 6100000, 1e15,
4545+
1e15, 1300004, 4800000, 5500000, 1300001, 1000000, 5900000, 4500000, 5900000,
4546+
5900000, 7900000, 4500000, 1e15, 1e15, 1100000, 4300000, 4600000, 1100000,
4547+
700000, 1800000, 400000, 400004, 100000, 1200000, 100005, 900000, 900000,
4548+
300002, 1000001, 700000, 400000, 100000, 3700000, 4700000, 3700000, 3700000,
4549+
7900000, 4700000, 1e15, 1e15, 1500004, 2400000, 2400000, 1500004, 300000,
4550+
1800000, 400000, 400004, 100000, 1200000, 100005, 900000, 900000, 300000,
4551+
1000001, 700000, 400000, 100000, 13300000, 1e15, 13300000, 13300000, 13300000,
4552+
1e15, 1e15, 1e15, 2700000, 8800000, 11800000, 2700000, 2900000, 2600000,
4553+
5500000, 400004, 2600000, 7900000, 5500000, 1e15, 1e15, 700000, 1400000,
4554+
1500000, 700000, 100005, 13100000, 14300000, 13100000, 13100000, 13100000,
4555+
14300000, 1e15, 1e15, 1800004, 8700000, 11600000, 1800004, 2900000, 8900000,
4556+
8200000, 8900000, 8900000, 8900000, 8200000, 1e15, 1e15, 1400005, 6300000,
4557+
7500000, 1400001, 1500000, 1800000, 400000, 3700000, 100000, 1200000, 100000,
4558+
900000, 900000, 100000, 1000001, 700000, 100000, 100000, 1800000, 400000,
4559+
400004, 100000, 1200000, 100000, 900000, 900000, 100000, 1000001, 700000,
4560+
100000, 100000, 12100000, 1e15, 12100000, 12100000, 12100000, 1e15, 1e15,
4561+
1e15, 1700004, 8100000, 10700000, 1700004, 2500000, 10500000, 14900000,
4562+
10500000, 10500000, 10500000, 14900000, 1e15, 1e15, 1700002, 7200000, 9100000,
4563+
1700002, 2000000, 8600000, 6800000, 8600000, 8600000, 8600000, 6800000, 1e15,
4564+
1e15, 1100003, 6100000, 7200000, 1100001, 1400000, 7300000, 7900000, 7300000,
45534565
7300000, 7900000, 7200000, 1e15, 1e15, 1300004, 5200000, 6000000, 1300001,
45544566
1100000, 13500000, 1e15, 13500000, 13500000, 13500000, 1e15, 1e15, 1e15,
45554567
2700000, 8900000, 12000000, 2700000, 2900000, 5700000, 5100000, 5700000,
@@ -4636,113 +4648,120 @@ const SUPPORT_PROFILES = new Float64Array([
46364648
const SUPPORTED_FROM = new Map([
46374649
["colorHexAlpha", 0],
46384650
["gradientDoublePosition", 1],
4639-
["insetShorthand", 2],
4640-
["mediaQueryRange", 3],
4641-
["overflowTwoValues", 4],
4642-
["placeShorthand", 5]
4651+
["displayTwoValues", 2],
4652+
["colorFunction", 3],
4653+
["colorMix", 4],
4654+
["hwbColors", 5],
4655+
["lightDark", 6],
4656+
["labColors", 3],
4657+
["oklabColors", 7],
4658+
["insetShorthand", 8],
4659+
["mediaQueryRange", 9],
4660+
["overflowTwoValues", 10],
4661+
["placeShorthand", 11]
46434662
]);
46444663

46454664
// When each browser first read a pseudo-class or pseudo-element, by the spelling
46464665
// a selector carries. A pseudo missing here is one no target is known to read,
46474666
// so it never joins a selector list.
46484667
/** @type {Map<string, number>} */
46494668
const SELECTOR_SUPPORTED_FROM = new Map([
4650-
["::after", 6],
4651-
["::backdrop", 7],
4652-
["::before", 8],
4653-
["::checkmark", 9],
4654-
["::cue", 10],
4655-
["::cue", 10],
4656-
["::details-content", 11],
4657-
["::file-selector-button", 12],
4658-
["::first-letter", 13],
4659-
["::first-line", 14],
4660-
["::grammar-error", 15],
4661-
["::highlight", 16],
4662-
["::marker", 17],
4663-
["::part", 18],
4664-
["::picker", 19],
4665-
["::picker-icon", 9],
4666-
["::placeholder", 20],
4667-
["::selection", 21],
4668-
["::slotted", 22],
4669-
["::spelling-error", 15],
4670-
["::target-text", 23],
4671-
["::view-transition", 24],
4672-
["::view-transition-group", 24],
4673-
["::view-transition-image-pair", 24],
4674-
["::view-transition-new", 24],
4675-
["::view-transition-old", 24],
4676-
[":active", 25],
4677-
[":active-view-transition", 26],
4678-
[":active-view-transition-type", 27],
4679-
[":any-link", 28],
4680-
[":autofill", 29],
4681-
[":buffering", 30],
4682-
[":checked", 31],
4683-
[":default", 32],
4684-
[":defined", 33],
4685-
[":dir", 34],
4686-
[":disabled", 31],
4687-
[":empty", 35],
4688-
[":enabled", 31],
4689-
[":first", 36],
4690-
[":first-child", 37],
4691-
[":first-of-type", 38],
4692-
[":focus", 39],
4693-
[":focus-visible", 40],
4694-
[":focus-within", 41],
4695-
[":fullscreen", 42],
4696-
[":future", 43],
4697-
[":has", 44],
4698-
[":has-slotted", 45],
4699-
[":host", 33],
4700-
[":host", 33],
4701-
[":host-context", 46],
4702-
[":hover", 47],
4703-
[":in-range", 48],
4704-
[":indeterminate", 49],
4705-
[":invalid", 50],
4706-
[":is", 51],
4707-
[":lang", 52],
4708-
[":last-child", 53],
4709-
[":last-of-type", 38],
4710-
[":left", 54],
4711-
[":link", 55],
4712-
[":modal", 56],
4713-
[":muted", 30],
4714-
[":not", 35],
4715-
[":nth-child", 57],
4716-
[":nth-last-child", 58],
4717-
[":nth-last-of-type", 59],
4718-
[":nth-of-type", 38],
4719-
[":only-child", 60],
4720-
[":only-of-type", 38],
4721-
[":open", 61],
4722-
[":optional", 50],
4723-
[":out-of-range", 48],
4724-
[":past", 43],
4725-
[":paused", 30],
4726-
[":picture-in-picture", 62],
4727-
[":placeholder-shown", 63],
4728-
[":playing", 30],
4729-
[":popover-open", 64],
4730-
[":read-only", 65],
4731-
[":read-write", 65],
4732-
[":required", 66],
4733-
[":right", 54],
4734-
[":root", 67],
4735-
[":scope", 68],
4736-
[":seeking", 30],
4737-
[":stalled", 30],
4738-
[":state", 69],
4739-
[":target", 70],
4740-
[":user-invalid", 71],
4741-
[":user-valid", 71],
4742-
[":valid", 50],
4743-
[":visited", 72],
4744-
[":volume-locked", 30],
4745-
[":where", 51]
4669+
["::after", 12],
4670+
["::backdrop", 13],
4671+
["::before", 14],
4672+
["::checkmark", 15],
4673+
["::cue", 16],
4674+
["::cue", 16],
4675+
["::details-content", 17],
4676+
["::file-selector-button", 18],
4677+
["::first-letter", 19],
4678+
["::first-line", 20],
4679+
["::grammar-error", 21],
4680+
["::highlight", 22],
4681+
["::marker", 23],
4682+
["::part", 24],
4683+
["::picker", 25],
4684+
["::picker-icon", 15],
4685+
["::placeholder", 26],
4686+
["::selection", 27],
4687+
["::slotted", 28],
4688+
["::spelling-error", 21],
4689+
["::target-text", 29],
4690+
["::view-transition", 30],
4691+
["::view-transition-group", 30],
4692+
["::view-transition-image-pair", 30],
4693+
["::view-transition-new", 30],
4694+
["::view-transition-old", 30],
4695+
[":active", 31],
4696+
[":active-view-transition", 32],
4697+
[":active-view-transition-type", 33],
4698+
[":any-link", 34],
4699+
[":autofill", 35],
4700+
[":buffering", 36],
4701+
[":checked", 37],
4702+
[":default", 38],
4703+
[":defined", 39],
4704+
[":dir", 40],
4705+
[":disabled", 37],
4706+
[":empty", 41],
4707+
[":enabled", 37],
4708+
[":first", 42],
4709+
[":first-child", 43],
4710+
[":first-of-type", 44],
4711+
[":focus", 45],
4712+
[":focus-visible", 46],
4713+
[":focus-within", 47],
4714+
[":fullscreen", 48],
4715+
[":future", 49],
4716+
[":has", 50],
4717+
[":has-slotted", 51],
4718+
[":host", 39],
4719+
[":host", 39],
4720+
[":host-context", 52],
4721+
[":hover", 53],
4722+
[":in-range", 54],
4723+
[":indeterminate", 55],
4724+
[":invalid", 56],
4725+
[":is", 57],
4726+
[":lang", 58],
4727+
[":last-child", 59],
4728+
[":last-of-type", 44],
4729+
[":left", 60],
4730+
[":link", 61],
4731+
[":modal", 62],
4732+
[":muted", 36],
4733+
[":not", 41],
4734+
[":nth-child", 63],
4735+
[":nth-last-child", 64],
4736+
[":nth-last-of-type", 65],
4737+
[":nth-of-type", 44],
4738+
[":only-child", 66],
4739+
[":only-of-type", 44],
4740+
[":open", 67],
4741+
[":optional", 56],
4742+
[":out-of-range", 54],
4743+
[":past", 49],
4744+
[":paused", 36],
4745+
[":picture-in-picture", 68],
4746+
[":placeholder-shown", 69],
4747+
[":playing", 36],
4748+
[":popover-open", 70],
4749+
[":read-only", 71],
4750+
[":read-write", 71],
4751+
[":required", 72],
4752+
[":right", 60],
4753+
[":root", 73],
4754+
[":scope", 74],
4755+
[":seeking", 36],
4756+
[":stalled", 36],
4757+
[":state", 75],
4758+
[":target", 76],
4759+
[":user-invalid", 77],
4760+
[":user-valid", 77],
4761+
[":valid", 56],
4762+
[":visited", 78],
4763+
[":volume-locked", 36],
4764+
[":where", 57]
47464765
]);
47474766

47484767
// The vendor spellings of a property's own keyword values, as `property ->

0 commit comments

Comments
 (0)