@tenphi/tasty 0.0.0-snapshot.b6cc3cd → 0.0.0-snapshot.b70adcb
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +147 -129
- package/dist/astro-DmdDJ6uY.js +301 -0
- package/dist/astro-DmdDJ6uY.js.map +1 -0
- package/dist/{babel-D8dm92E_.d.ts → babel-BOfdfseh.d.ts} +2 -2
- package/dist/collector-B0ehMgiy.js +530 -0
- package/dist/collector-B0ehMgiy.js.map +1 -0
- package/dist/{collector-BFuqdF2F.d.ts → collector-DlH0WfI4.d.ts} +94 -11
- package/dist/{config-DH7I0Ggx.d.ts → config-CJKXZDrM.d.ts} +183 -40
- package/dist/{config-BrDt11hO.js → config-pEfUVSK_.js} +918 -1134
- package/dist/config-pEfUVSK_.js.map +1 -0
- package/dist/core/index.d.ts +5 -5
- package/dist/core/index.js +6 -6
- package/dist/{core-YWn1zgh4.js → core-k3upKydI.js} +454 -151
- package/dist/core-k3upKydI.js.map +1 -0
- package/dist/css-resources-Cyl_axbI.js +149 -0
- package/dist/css-resources-Cyl_axbI.js.map +1 -0
- package/dist/{css-writer-CQYbT4g_.js → css-writer-mJs2wklg.js} +3 -3
- package/dist/{css-writer-CQYbT4g_.js.map → css-writer-mJs2wklg.js.map} +1 -1
- package/dist/{format-rules-DdmLdntR.js → format-rules-13uxeuU9.js} +25 -50
- package/dist/format-rules-13uxeuU9.js.map +1 -0
- package/dist/{hydrate-D2ivfS-B.js → hydrate-C3iKO38t.js} +3 -3
- package/dist/{hydrate-D2ivfS-B.js.map → hydrate-C3iKO38t.js.map} +1 -1
- package/dist/{index-LC3O3Jj4.d.ts → index-C8RFYeFW.d.ts} +87 -16
- package/dist/{index-DljBkZhV.d.ts → index-Do1d1v9f.d.ts} +66 -22
- package/dist/index.d.ts +5 -5
- package/dist/index.js +45 -28
- package/dist/index.js.map +1 -1
- package/dist/{keyframes-CoLLjBcd.js → keyframes-gFeuFSzE.js} +132 -21
- package/dist/keyframes-gFeuFSzE.js.map +1 -0
- package/dist/{merge-styles-Cx_6ySBv.d.ts → merge-styles-BQv7d3fx.d.ts} +2 -2
- package/dist/{merge-styles-bdh7-1uh.js → merge-styles-p0pofQ3S.js} +2 -2
- package/dist/{merge-styles-bdh7-1uh.js.map → merge-styles-p0pofQ3S.js.map} +1 -1
- package/dist/precompile/index.d.ts +11 -0
- package/dist/precompile/index.js +82 -0
- package/dist/precompile/index.js.map +1 -0
- package/dist/precompile/register.d.ts +13 -0
- package/dist/precompile/register.js +2 -0
- package/dist/register-DRrc1VWt.js +340 -0
- package/dist/register-DRrc1VWt.js.map +1 -0
- package/dist/{resolve-recipes-9JYSgubn.js → resolve-recipes-CldVRsBq.js} +3 -3
- package/dist/{resolve-recipes-9JYSgubn.js.map → resolve-recipes-CldVRsBq.js.map} +1 -1
- package/dist/ssr/astro-client.js +1 -1
- package/dist/ssr/astro-middleware-extract-static.d.ts +11 -0
- package/dist/ssr/astro-middleware-extract-static.js +9 -0
- package/dist/ssr/astro-middleware-extract-static.js.map +1 -0
- package/dist/ssr/astro-middleware-extract.d.ts +11 -0
- package/dist/ssr/astro-middleware-extract.js +9 -0
- package/dist/ssr/astro-middleware-extract.js.map +1 -0
- package/dist/ssr/astro-middleware-static.d.ts +3 -1
- package/dist/ssr/astro-middleware-static.js +1 -1
- package/dist/ssr/astro-middleware.d.ts +3 -1
- package/dist/ssr/astro-middleware.js +1 -1
- package/dist/ssr/astro.d.ts +45 -3
- package/dist/ssr/astro.js +1 -156
- package/dist/ssr/index.d.ts +2 -2
- package/dist/ssr/index.js +3 -3
- package/dist/ssr/index.js.map +1 -1
- package/dist/ssr/next-config.d.ts +66 -0
- package/dist/ssr/next-config.js +115 -0
- package/dist/ssr/next-config.js.map +1 -0
- package/dist/ssr/next.d.ts +9 -2
- package/dist/ssr/next.js +26 -9
- package/dist/ssr/next.js.map +1 -1
- package/dist/ssr-collector-ref-COs_ioWl.js +29 -0
- package/dist/ssr-collector-ref-COs_ioWl.js.map +1 -0
- package/dist/static/index.d.ts +2 -2
- package/dist/static/index.js +1 -1
- package/dist/types-_uR064Sd.d.ts +129 -0
- package/dist/zero/babel.d.ts +1 -1
- package/dist/zero/babel.js +4 -4
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +1 -1
- package/dist/zero/index.js +1 -1
- package/dist/zero/next.d.ts +1 -1
- package/docs/README.md +15 -8
- package/docs/adoption.md +56 -31
- package/docs/ai-agents.md +78 -77
- package/docs/comparison.md +69 -40
- package/docs/configuration.md +164 -101
- package/docs/debug.md +21 -8
- package/docs/design-system.md +41 -22
- package/docs/dsl.md +263 -198
- package/docs/getting-started.md +60 -39
- package/docs/injector.md +63 -26
- package/docs/methodology.md +43 -37
- package/docs/migration-v3.md +49 -49
- package/docs/pipeline.md +1 -4
- package/docs/plugins.md +37 -33
- package/docs/precompile.md +213 -0
- package/docs/react-api.md +66 -45
- package/docs/runtime-benchmarks.md +287 -0
- package/docs/ssr.md +219 -61
- package/docs/styles.md +9 -2
- package/docs/tasty-static.md +137 -104
- package/package.json +52 -12
- package/dist/collector-Di3C8btw.js +0 -304
- package/dist/collector-Di3C8btw.js.map +0 -1
- package/dist/config-BrDt11hO.js.map +0 -1
- package/dist/core-YWn1zgh4.js.map +0 -1
- package/dist/format-rules-DdmLdntR.js.map +0 -1
- package/dist/keyframes-CoLLjBcd.js.map +0 -1
- package/dist/ssr/astro.js.map +0 -1
|
@@ -52,16 +52,6 @@ const COLOR_FUNCS = new Set([
|
|
|
52
52
|
]);
|
|
53
53
|
/** A value that is a single `name(args)` call: captures the name and the args. */
|
|
54
54
|
const RE_FUNC_CALL = /^([a-z][a-z0-9-]*)\((.+)\)$/i;
|
|
55
|
-
/**
|
|
56
|
-
* The color function a value calls at its top level, lowercased — or `null` when
|
|
57
|
-
* the value is not a single color function call.
|
|
58
|
-
*/
|
|
59
|
-
function colorFuncName(value) {
|
|
60
|
-
const match = value.match(RE_FUNC_CALL);
|
|
61
|
-
if (!match) return null;
|
|
62
|
-
const name = match[1].toLowerCase();
|
|
63
|
-
return COLOR_FUNCS.has(name) ? name : null;
|
|
64
|
-
}
|
|
65
55
|
const RE_UNIT_NUM = /^[+-]?(?:\d*\.\d+|\d+)([a-z][a-z0-9]*)$/;
|
|
66
56
|
const RE_NUMBER = /^[+-]?(?:\d*\.\d+|\d+)$/;
|
|
67
57
|
const RE_HEX = /^(?:[0-9a-f]{3,4}|[0-9a-f]{6}(?:[0-9a-f]{2})?)$/;
|
|
@@ -197,9 +187,6 @@ const OKLab_to_linear_sRGB_coefficients = [
|
|
|
197
187
|
]]
|
|
198
188
|
];
|
|
199
189
|
const dotXY = (a, b) => a[0] * b[0] + a[1] * b[1];
|
|
200
|
-
function srgbToLinear(c) {
|
|
201
|
-
return c <= .04045 ? c / 12.92 : ((c + .055) / 1.055) ** 2.4;
|
|
202
|
-
}
|
|
203
190
|
const INV_GAMMA = 1 / 2.4;
|
|
204
191
|
function srgbLinearToGamma(val) {
|
|
205
192
|
const sign = val < 0 ? -1 : 1;
|
|
@@ -241,22 +228,6 @@ const oklabToLinearSrgb = (lab) => {
|
|
|
241
228
|
-.004196076138675526 * l - .703418617935936 * m + 1.7076146940746113 * s
|
|
242
229
|
];
|
|
243
230
|
};
|
|
244
|
-
const linearSrgbToOklab = (rgb) => {
|
|
245
|
-
const r = rgb[0];
|
|
246
|
-
const g = rgb[1];
|
|
247
|
-
const b = rgb[2];
|
|
248
|
-
const l = .4122214708 * r + .5363325363 * g + .0514459929 * b;
|
|
249
|
-
const m = .2119034982 * r + .6806995451 * g + .1073969566 * b;
|
|
250
|
-
const s = .0883024619 * r + .2817188376 * g + .6299787005 * b;
|
|
251
|
-
const l_ = Math.cbrt(l);
|
|
252
|
-
const m_ = Math.cbrt(m);
|
|
253
|
-
const s_ = Math.cbrt(s);
|
|
254
|
-
return [
|
|
255
|
-
.2104542553 * l_ + .793617785 * m_ - .0040720468 * s_,
|
|
256
|
-
1.9779984951 * l_ - 2.428592205 * m_ + .4505937099 * s_,
|
|
257
|
-
.0259040371 * l_ + .7827717662 * m_ - .808675766 * s_
|
|
258
|
-
];
|
|
259
|
-
};
|
|
260
231
|
const computeMaxSaturationOKLC = (a, b) => {
|
|
261
232
|
const okCoeff = OKLab_to_linear_sRGB_coefficients;
|
|
262
233
|
const lmsToRgb = LMS_to_linear_sRGB_M;
|
|
@@ -450,53 +421,6 @@ function hslToRgbValues(h, s, l) {
|
|
|
450
421
|
];
|
|
451
422
|
}
|
|
452
423
|
/**
|
|
453
|
-
* RGB (0-255) to HSL.
|
|
454
|
-
* @returns [h (0-360), s (0-1), l (0-1)]
|
|
455
|
-
*/
|
|
456
|
-
function rgbToHsl(r, g, b) {
|
|
457
|
-
r /= 255;
|
|
458
|
-
g /= 255;
|
|
459
|
-
b /= 255;
|
|
460
|
-
const max = Math.max(r, g, b);
|
|
461
|
-
const min = Math.min(r, g, b);
|
|
462
|
-
const l = (max + min) / 2;
|
|
463
|
-
if (max === min) return [
|
|
464
|
-
0,
|
|
465
|
-
0,
|
|
466
|
-
l
|
|
467
|
-
];
|
|
468
|
-
const d = max - min;
|
|
469
|
-
const s = l > .5 ? d / (2 - max - min) : d / (max + min);
|
|
470
|
-
let h;
|
|
471
|
-
if (max === r) h = ((g - b) / d + (g < b ? 6 : 0)) / 6;
|
|
472
|
-
else if (max === g) h = ((b - r) / d + 2) / 6;
|
|
473
|
-
else h = ((r - g) / d + 4) / 6;
|
|
474
|
-
return [
|
|
475
|
-
h * 360,
|
|
476
|
-
s,
|
|
477
|
-
l
|
|
478
|
-
];
|
|
479
|
-
}
|
|
480
|
-
/**
|
|
481
|
-
* RGB (0-255) to OKLCH via sRGB -> linear sRGB -> OKLab -> OKLCH.
|
|
482
|
-
* @returns [L, C, H] where H is in degrees (0-360)
|
|
483
|
-
*/
|
|
484
|
-
function rgbToOklch(r, g, b) {
|
|
485
|
-
const [L, a, bLab] = linearSrgbToOklab([
|
|
486
|
-
srgbToLinear(r / 255),
|
|
487
|
-
srgbToLinear(g / 255),
|
|
488
|
-
srgbToLinear(b / 255)
|
|
489
|
-
]);
|
|
490
|
-
const C = Math.sqrt(a * a + bLab * bLab);
|
|
491
|
-
let H = Math.atan2(bLab, a) * 180 / Math.PI;
|
|
492
|
-
if (H < 0) H += 360;
|
|
493
|
-
return [
|
|
494
|
-
L,
|
|
495
|
-
C,
|
|
496
|
-
H
|
|
497
|
-
];
|
|
498
|
-
}
|
|
499
|
-
/**
|
|
500
424
|
* OKHSL to sRGB (0-1 range).
|
|
501
425
|
* @param h - Hue in degrees (0-360)
|
|
502
426
|
* @param s - Saturation (0-1)
|
|
@@ -700,80 +624,6 @@ function getNamedColorHex() {
|
|
|
700
624
|
]);
|
|
701
625
|
return _namedColorHex;
|
|
702
626
|
}
|
|
703
|
-
const hexCharToNum = (c) => {
|
|
704
|
-
if (c >= 48 && c <= 57) return c - 48;
|
|
705
|
-
if (c >= 65 && c <= 70) return c - 55;
|
|
706
|
-
if (c >= 97 && c <= 102) return c - 87;
|
|
707
|
-
return -1;
|
|
708
|
-
};
|
|
709
|
-
/**
|
|
710
|
-
* Parse a hex color string to RGBA values (RGB 0-255, alpha 0-1).
|
|
711
|
-
* Supports 3, 4, 6, and 8 character hex values (with or without `#`).
|
|
712
|
-
* For 3/6-char hex (no alpha channel), alpha defaults to 1.
|
|
713
|
-
*/
|
|
714
|
-
function hexToRgbaValues(hex) {
|
|
715
|
-
let start = 0;
|
|
716
|
-
if (hex.charCodeAt(0) === 35) start = 1;
|
|
717
|
-
const len = hex.length - start;
|
|
718
|
-
if (len === 3) {
|
|
719
|
-
const r = hexCharToNum(hex.charCodeAt(start));
|
|
720
|
-
const g = hexCharToNum(hex.charCodeAt(start + 1));
|
|
721
|
-
const b = hexCharToNum(hex.charCodeAt(start + 2));
|
|
722
|
-
if (r < 0 || g < 0 || b < 0) return null;
|
|
723
|
-
return [
|
|
724
|
-
r * 17,
|
|
725
|
-
g * 17,
|
|
726
|
-
b * 17,
|
|
727
|
-
1
|
|
728
|
-
];
|
|
729
|
-
}
|
|
730
|
-
if (len === 4) {
|
|
731
|
-
const r = hexCharToNum(hex.charCodeAt(start));
|
|
732
|
-
const g = hexCharToNum(hex.charCodeAt(start + 1));
|
|
733
|
-
const b = hexCharToNum(hex.charCodeAt(start + 2));
|
|
734
|
-
const a = hexCharToNum(hex.charCodeAt(start + 3));
|
|
735
|
-
if (r < 0 || g < 0 || b < 0 || a < 0) return null;
|
|
736
|
-
return [
|
|
737
|
-
r * 17,
|
|
738
|
-
g * 17,
|
|
739
|
-
b * 17,
|
|
740
|
-
a * 17 / 255
|
|
741
|
-
];
|
|
742
|
-
}
|
|
743
|
-
if (len === 6) {
|
|
744
|
-
const r1 = hexCharToNum(hex.charCodeAt(start));
|
|
745
|
-
const r2 = hexCharToNum(hex.charCodeAt(start + 1));
|
|
746
|
-
const g1 = hexCharToNum(hex.charCodeAt(start + 2));
|
|
747
|
-
const g2 = hexCharToNum(hex.charCodeAt(start + 3));
|
|
748
|
-
const b1 = hexCharToNum(hex.charCodeAt(start + 4));
|
|
749
|
-
const b2 = hexCharToNum(hex.charCodeAt(start + 5));
|
|
750
|
-
if (r1 < 0 || r2 < 0 || g1 < 0 || g2 < 0 || b1 < 0 || b2 < 0) return null;
|
|
751
|
-
return [
|
|
752
|
-
r1 * 16 + r2,
|
|
753
|
-
g1 * 16 + g2,
|
|
754
|
-
b1 * 16 + b2,
|
|
755
|
-
1
|
|
756
|
-
];
|
|
757
|
-
}
|
|
758
|
-
if (len === 8) {
|
|
759
|
-
const r1 = hexCharToNum(hex.charCodeAt(start));
|
|
760
|
-
const r2 = hexCharToNum(hex.charCodeAt(start + 1));
|
|
761
|
-
const g1 = hexCharToNum(hex.charCodeAt(start + 2));
|
|
762
|
-
const g2 = hexCharToNum(hex.charCodeAt(start + 3));
|
|
763
|
-
const b1 = hexCharToNum(hex.charCodeAt(start + 4));
|
|
764
|
-
const b2 = hexCharToNum(hex.charCodeAt(start + 5));
|
|
765
|
-
const a1 = hexCharToNum(hex.charCodeAt(start + 6));
|
|
766
|
-
const a2 = hexCharToNum(hex.charCodeAt(start + 7));
|
|
767
|
-
if (r1 < 0 || r2 < 0 || g1 < 0 || g2 < 0 || b1 < 0 || b2 < 0 || a1 < 0 || a2 < 0) return null;
|
|
768
|
-
return [
|
|
769
|
-
r1 * 16 + r2,
|
|
770
|
-
g1 * 16 + g2,
|
|
771
|
-
b1 * 16 + b2,
|
|
772
|
-
(a1 * 16 + a2) / 255
|
|
773
|
-
];
|
|
774
|
-
}
|
|
775
|
-
return null;
|
|
776
|
-
}
|
|
777
627
|
/**
|
|
778
628
|
* Convert hex color string to `rgb()` CSS string.
|
|
779
629
|
* Supports 3, 4, 6, and 8 character hex values (with or without `#`).
|
|
@@ -877,415 +727,7 @@ function oklchStringToRgb(oklchStr) {
|
|
|
877
727
|
return `rgb(${Math.round(r)} ${Math.round(g)} ${Math.round(b)})`;
|
|
878
728
|
}
|
|
879
729
|
//#endregion
|
|
880
|
-
//#region src/parser/lru.ts
|
|
881
|
-
var Lru = class {
|
|
882
|
-
limit;
|
|
883
|
-
map = /* @__PURE__ */ new Map();
|
|
884
|
-
head = null;
|
|
885
|
-
tail = null;
|
|
886
|
-
onEvict;
|
|
887
|
-
constructor(limit = 1e3, onEvict) {
|
|
888
|
-
this.limit = limit;
|
|
889
|
-
let normalized = Number.isFinite(this.limit) ? Math.floor(this.limit) : 1e3;
|
|
890
|
-
if (normalized <= 0) normalized = 1e3;
|
|
891
|
-
this.limit = normalized;
|
|
892
|
-
this.onEvict = onEvict;
|
|
893
|
-
}
|
|
894
|
-
setOnEvict(fn) {
|
|
895
|
-
this.onEvict = fn;
|
|
896
|
-
}
|
|
897
|
-
get(key) {
|
|
898
|
-
const node = this.map.get(key);
|
|
899
|
-
if (!node) return void 0;
|
|
900
|
-
this.touch(key, node);
|
|
901
|
-
return node.value;
|
|
902
|
-
}
|
|
903
|
-
set(key, value) {
|
|
904
|
-
let node = this.map.get(key);
|
|
905
|
-
if (node) {
|
|
906
|
-
node.value = value;
|
|
907
|
-
this.touch(key, node);
|
|
908
|
-
return;
|
|
909
|
-
}
|
|
910
|
-
node = {
|
|
911
|
-
prev: null,
|
|
912
|
-
next: this.head,
|
|
913
|
-
value
|
|
914
|
-
};
|
|
915
|
-
if (this.head) {
|
|
916
|
-
const headNode = this.map.get(this.head);
|
|
917
|
-
if (headNode) headNode.prev = key;
|
|
918
|
-
}
|
|
919
|
-
this.head = key;
|
|
920
|
-
if (!this.tail) this.tail = key;
|
|
921
|
-
this.map.set(key, node);
|
|
922
|
-
if (this.map.size > this.limit) this.evict();
|
|
923
|
-
}
|
|
924
|
-
delete(key) {
|
|
925
|
-
const node = this.map.get(key);
|
|
926
|
-
if (!node) return;
|
|
927
|
-
if (node.prev) {
|
|
928
|
-
const prevNode = this.map.get(node.prev);
|
|
929
|
-
if (prevNode) prevNode.next = node.next;
|
|
930
|
-
}
|
|
931
|
-
if (node.next) {
|
|
932
|
-
const nextNode = this.map.get(node.next);
|
|
933
|
-
if (nextNode) nextNode.prev = node.prev;
|
|
934
|
-
}
|
|
935
|
-
if (this.head === key) this.head = node.next;
|
|
936
|
-
if (this.tail === key) this.tail = node.prev;
|
|
937
|
-
this.map.delete(key);
|
|
938
|
-
}
|
|
939
|
-
keys() {
|
|
940
|
-
return this.map.keys();
|
|
941
|
-
}
|
|
942
|
-
touch(key, node) {
|
|
943
|
-
if (this.head === key) return;
|
|
944
|
-
if (node.prev) {
|
|
945
|
-
const prevNode = this.map.get(node.prev);
|
|
946
|
-
if (prevNode) prevNode.next = node.next;
|
|
947
|
-
}
|
|
948
|
-
if (node.next) {
|
|
949
|
-
const nextNode = this.map.get(node.next);
|
|
950
|
-
if (nextNode) nextNode.prev = node.prev;
|
|
951
|
-
}
|
|
952
|
-
if (this.tail === key) this.tail = node.prev;
|
|
953
|
-
node.prev = null;
|
|
954
|
-
node.next = this.head;
|
|
955
|
-
if (this.head) {
|
|
956
|
-
const headNode = this.map.get(this.head);
|
|
957
|
-
if (headNode) headNode.prev = key;
|
|
958
|
-
}
|
|
959
|
-
this.head = key;
|
|
960
|
-
}
|
|
961
|
-
evict() {
|
|
962
|
-
const old = this.tail;
|
|
963
|
-
if (!old) return;
|
|
964
|
-
const node = this.map.get(old);
|
|
965
|
-
if (!node) {
|
|
966
|
-
if (this.head === old) this.head = null;
|
|
967
|
-
this.tail = null;
|
|
968
|
-
return;
|
|
969
|
-
}
|
|
970
|
-
if (node.prev) {
|
|
971
|
-
const prevNode = this.map.get(node.prev);
|
|
972
|
-
if (prevNode) prevNode.next = null;
|
|
973
|
-
}
|
|
974
|
-
this.tail = node.prev;
|
|
975
|
-
if (this.head === old) this.head = null;
|
|
976
|
-
this.map.delete(old);
|
|
977
|
-
if (this.onEvict) try {
|
|
978
|
-
this.onEvict(old, node.value);
|
|
979
|
-
} catch {}
|
|
980
|
-
}
|
|
981
|
-
clear() {
|
|
982
|
-
this.map.clear();
|
|
983
|
-
this.head = this.tail = null;
|
|
984
|
-
}
|
|
985
|
-
};
|
|
986
|
-
//#endregion
|
|
987
|
-
//#region src/utils/function-color.ts
|
|
988
|
-
const RE_FUNC_NAME = /^([a-z][a-z0-9-]*)\s*\(/i;
|
|
989
|
-
const RE_COLOR_OUT = /^(?:rgb|hsl|hwb|lab|lch|oklab|oklch|color)\(|^#|^var\(--/i;
|
|
990
|
-
/**
|
|
991
|
-
* Resolve a `name(...)` value produced by a registered custom parse function
|
|
992
|
-
* into its concrete color output.
|
|
993
|
-
*
|
|
994
|
-
* A color function is just a `functions` entry whose output is an already
|
|
995
|
-
* supported color (`rgb`, `hsl`, `#…`, `oklch`, …). This helper delegates the
|
|
996
|
-
* value to the global parser (which already runs the registered parse function)
|
|
997
|
-
* and returns the result only when it looks like a color. Returns `null` when
|
|
998
|
-
* `str` is not a registered custom function or its output is not a color.
|
|
999
|
-
*
|
|
1000
|
-
* This is the generic replacement for the previously hardcoded okhsl/okhst
|
|
1001
|
-
* conversion branches scattered across `strToRgb`, `resolveToRgbaValues`, and
|
|
1002
|
-
* the `#token.alpha` injection path.
|
|
1003
|
-
*/
|
|
1004
|
-
function resolveFunctionColor(str) {
|
|
1005
|
-
const m = RE_FUNC_NAME.exec(str);
|
|
1006
|
-
if (!m) return null;
|
|
1007
|
-
const name = m[1].toLowerCase();
|
|
1008
|
-
getGlobalParser();
|
|
1009
|
-
if (!(name in getGlobalParseFunctions())) return null;
|
|
1010
|
-
const out = getGlobalParser().process(str).output;
|
|
1011
|
-
if (!out || !RE_COLOR_OUT.test(out)) return null;
|
|
1012
|
-
return out;
|
|
1013
|
-
}
|
|
1014
|
-
//#endregion
|
|
1015
730
|
//#region src/utils/color-space.ts
|
|
1016
|
-
let currentColorSpace = "oklch";
|
|
1017
|
-
const colorSpaceCache = new Lru(500);
|
|
1018
|
-
const componentsCache = new Lru(500);
|
|
1019
|
-
function clearColorCaches() {
|
|
1020
|
-
colorSpaceCache.clear();
|
|
1021
|
-
componentsCache.clear();
|
|
1022
|
-
}
|
|
1023
|
-
function setColorSpace(space) {
|
|
1024
|
-
currentColorSpace = space;
|
|
1025
|
-
clearColorCaches();
|
|
1026
|
-
}
|
|
1027
|
-
function resetColorSpace() {
|
|
1028
|
-
currentColorSpace = "oklch";
|
|
1029
|
-
clearColorCaches();
|
|
1030
|
-
}
|
|
1031
|
-
function getColorSpaceSuffix() {
|
|
1032
|
-
return currentColorSpace;
|
|
1033
|
-
}
|
|
1034
|
-
function formatNum(n, precision) {
|
|
1035
|
-
return parseFloat(n.toFixed(precision)).toString();
|
|
1036
|
-
}
|
|
1037
|
-
function formatRgbComponent(n) {
|
|
1038
|
-
return parseFloat(n.toFixed(1)).toString();
|
|
1039
|
-
}
|
|
1040
|
-
function formatAlpha(a) {
|
|
1041
|
-
if (a === 0) return "0";
|
|
1042
|
-
return parseFloat(a.toFixed(4)).toString();
|
|
1043
|
-
}
|
|
1044
|
-
function rgbValuesToColorString(r, g, b, space, alpha) {
|
|
1045
|
-
const alphaSuffix = alpha != null && alpha < 1 ? ` / ${formatAlpha(alpha)}` : "";
|
|
1046
|
-
switch (space) {
|
|
1047
|
-
case "rgb": return `rgb(${Math.round(r)} ${Math.round(g)} ${Math.round(b)}${alphaSuffix})`;
|
|
1048
|
-
case "hsl": {
|
|
1049
|
-
const [h, s, l] = rgbToHsl(r, g, b);
|
|
1050
|
-
return `hsl(${formatNum(h, 2)} ${formatNum(s * 100, 2)}% ${formatNum(l * 100, 2)}%${alphaSuffix})`;
|
|
1051
|
-
}
|
|
1052
|
-
case "oklch": {
|
|
1053
|
-
const [L, C, H] = rgbToOklch(r, g, b);
|
|
1054
|
-
return `oklch(${formatNum(L, 5)} ${formatNum(C, 5)} ${formatNum(H, 2)}${alphaSuffix})`;
|
|
1055
|
-
}
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
|
-
function rgbValuesToComponents(r, g, b, space) {
|
|
1059
|
-
switch (space) {
|
|
1060
|
-
case "rgb": return `${formatRgbComponent(r)} ${formatRgbComponent(g)} ${formatRgbComponent(b)}`;
|
|
1061
|
-
case "hsl": {
|
|
1062
|
-
const [h, s, l] = rgbToHsl(r, g, b);
|
|
1063
|
-
return `${formatNum(h, 2)} ${formatNum(s * 100, 2)}% ${formatNum(l * 100, 2)}%`;
|
|
1064
|
-
}
|
|
1065
|
-
case "oklch": {
|
|
1066
|
-
const [L, C, H] = rgbToOklch(r, g, b);
|
|
1067
|
-
return `${formatNum(L, 5)} ${formatNum(C, 5)} ${formatNum(H, 2)}`;
|
|
1068
|
-
}
|
|
1069
|
-
}
|
|
1070
|
-
}
|
|
1071
|
-
const parseColorFuncArgs = (str, prefix) => {
|
|
1072
|
-
const start = str.indexOf("(", prefix.length - 1);
|
|
1073
|
-
const end = str.lastIndexOf(")");
|
|
1074
|
-
if (start < 0 || end < 0) return null;
|
|
1075
|
-
const inner = str.slice(start + 1, end).trim();
|
|
1076
|
-
const slashIdx = inner.indexOf("/");
|
|
1077
|
-
let colorPart;
|
|
1078
|
-
let alpha = 1;
|
|
1079
|
-
if (slashIdx >= 0) {
|
|
1080
|
-
colorPart = inner.slice(0, slashIdx);
|
|
1081
|
-
const alphaStr = inner.slice(slashIdx + 1).trim();
|
|
1082
|
-
if (alphaStr) {
|
|
1083
|
-
alpha = alphaStr.endsWith("%") ? parseFloat(alphaStr) / 100 : parseFloat(alphaStr);
|
|
1084
|
-
if (Number.isNaN(alpha)) alpha = 1;
|
|
1085
|
-
}
|
|
1086
|
-
} else colorPart = inner;
|
|
1087
|
-
const parts = colorPart.trim().split(/[,\s]+/).filter(Boolean);
|
|
1088
|
-
if (parts.length < 3) return null;
|
|
1089
|
-
if (parts.length >= 4 && slashIdx < 0) {
|
|
1090
|
-
const legacyAlpha = parseFloat(parts[3]);
|
|
1091
|
-
if (!Number.isNaN(legacyAlpha)) alpha = legacyAlpha;
|
|
1092
|
-
}
|
|
1093
|
-
return {
|
|
1094
|
-
parts,
|
|
1095
|
-
alpha
|
|
1096
|
-
};
|
|
1097
|
-
};
|
|
1098
|
-
const parseHue = (hueStr) => {
|
|
1099
|
-
let h = parseFloat(hueStr);
|
|
1100
|
-
const lower = hueStr.toLowerCase();
|
|
1101
|
-
if (lower.endsWith("turn")) h = parseFloat(lower) * 360;
|
|
1102
|
-
else if (lower.endsWith("rad")) h = parseFloat(lower) * 180 / Math.PI;
|
|
1103
|
-
return (h % 360 + 360) % 360;
|
|
1104
|
-
};
|
|
1105
|
-
const parsePercent = (val) => {
|
|
1106
|
-
const num = parseFloat(val);
|
|
1107
|
-
return val.includes("%") ? num / 100 : num;
|
|
1108
|
-
};
|
|
1109
|
-
const clamp01 = (n) => Math.max(0, Math.min(1, n));
|
|
1110
|
-
function resolveToRgbaValues(color) {
|
|
1111
|
-
const trimmed = color.trim().toLowerCase();
|
|
1112
|
-
if (trimmed.startsWith("rgb")) {
|
|
1113
|
-
const parsed = parseColorFuncArgs(trimmed, "rgb");
|
|
1114
|
-
if (!parsed || parsed.parts.length < 3) return null;
|
|
1115
|
-
return [
|
|
1116
|
-
parsed.parts[0].endsWith("%") ? parseFloat(parsed.parts[0]) / 100 * 255 : parseFloat(parsed.parts[0]),
|
|
1117
|
-
parsed.parts[1].endsWith("%") ? parseFloat(parsed.parts[1]) / 100 * 255 : parseFloat(parsed.parts[1]),
|
|
1118
|
-
parsed.parts[2].endsWith("%") ? parseFloat(parsed.parts[2]) / 100 * 255 : parseFloat(parsed.parts[2]),
|
|
1119
|
-
parsed.alpha
|
|
1120
|
-
];
|
|
1121
|
-
}
|
|
1122
|
-
if (trimmed.startsWith("#")) return hexToRgbaValues(trimmed);
|
|
1123
|
-
if (trimmed.startsWith("hsl")) {
|
|
1124
|
-
const parsed = parseColorFuncArgs(trimmed, "hsl");
|
|
1125
|
-
if (!parsed) return null;
|
|
1126
|
-
const [r, g, b] = hslToRgbValues(parseHue(parsed.parts[0]), clamp01(parsePercent(parsed.parts[1])), clamp01(parsePercent(parsed.parts[2])));
|
|
1127
|
-
return [
|
|
1128
|
-
r,
|
|
1129
|
-
g,
|
|
1130
|
-
b,
|
|
1131
|
-
parsed.alpha
|
|
1132
|
-
];
|
|
1133
|
-
}
|
|
1134
|
-
if (trimmed.startsWith("oklch(")) {
|
|
1135
|
-
const parsed = parseColorFuncArgs(trimmed, "oklch");
|
|
1136
|
-
if (!parsed) return null;
|
|
1137
|
-
const [r, g, b] = oklchToRgbValues(clamp01(parsePercent(parsed.parts[0])), Math.max(0, parseFloat(parsed.parts[1])), parseHue(parsed.parts[2]));
|
|
1138
|
-
return [
|
|
1139
|
-
r,
|
|
1140
|
-
g,
|
|
1141
|
-
b,
|
|
1142
|
-
parsed.alpha
|
|
1143
|
-
];
|
|
1144
|
-
}
|
|
1145
|
-
const resolved = resolveFunctionColor(trimmed);
|
|
1146
|
-
if (resolved && resolved !== trimmed) return resolveToRgbaValues(resolved);
|
|
1147
|
-
const fallback = strToRgb(trimmed);
|
|
1148
|
-
if (fallback) {
|
|
1149
|
-
if (fallback !== trimmed) return resolveToRgbaValues(fallback);
|
|
1150
|
-
const vals = getRgbValuesFromRgbaString(fallback);
|
|
1151
|
-
if (vals.length >= 3) return [
|
|
1152
|
-
vals[0],
|
|
1153
|
-
vals[1],
|
|
1154
|
-
vals[2],
|
|
1155
|
-
1
|
|
1156
|
-
];
|
|
1157
|
-
}
|
|
1158
|
-
return null;
|
|
1159
|
-
}
|
|
1160
|
-
const SPACE_FUNCS = {
|
|
1161
|
-
rgb: ["rgb", "rgba"],
|
|
1162
|
-
hsl: ["hsl", "hsla"],
|
|
1163
|
-
oklch: ["oklch", "oklcha"]
|
|
1164
|
-
};
|
|
1165
|
-
const CANONICAL_FUNC = {
|
|
1166
|
-
rgb: "rgb",
|
|
1167
|
-
hsl: "hsl",
|
|
1168
|
-
oklch: "oklch"
|
|
1169
|
-
};
|
|
1170
|
-
/**
|
|
1171
|
-
* Parse a native CSS color function ONLY when its name matches the configured
|
|
1172
|
-
* output space. Splits arguments at the top level, preserving every token
|
|
1173
|
-
* (numbers, percentages, `var()`, `calc()`, `min()`, …) verbatim — no numeric
|
|
1174
|
-
* parsing or normalization is performed.
|
|
1175
|
-
*
|
|
1176
|
-
* Returns null when the input is not a same-space function (caller falls back
|
|
1177
|
-
* to the sRGB round-trip for genuine cross-space conversion / hex / named colors).
|
|
1178
|
-
*/
|
|
1179
|
-
function parseSameSpaceFunc(color, space) {
|
|
1180
|
-
const original = color.trim();
|
|
1181
|
-
const lower = original.toLowerCase();
|
|
1182
|
-
const funcs = SPACE_FUNCS[space];
|
|
1183
|
-
let funcName = null;
|
|
1184
|
-
for (const f of funcs) if (lower.startsWith(`${f}(`)) {
|
|
1185
|
-
funcName = f;
|
|
1186
|
-
break;
|
|
1187
|
-
}
|
|
1188
|
-
if (!funcName) return null;
|
|
1189
|
-
const start = funcName.length;
|
|
1190
|
-
const end = original.lastIndexOf(")");
|
|
1191
|
-
if (end < start) return null;
|
|
1192
|
-
const inner = original.slice(start + 1, end).trim();
|
|
1193
|
-
if (!inner) return null;
|
|
1194
|
-
const rawTokens = [];
|
|
1195
|
-
let depth = 0;
|
|
1196
|
-
let buf = "";
|
|
1197
|
-
for (const c of inner) if (c === "(") {
|
|
1198
|
-
depth++;
|
|
1199
|
-
buf += c;
|
|
1200
|
-
} else if (c === ")") {
|
|
1201
|
-
depth--;
|
|
1202
|
-
buf += c;
|
|
1203
|
-
} else if (depth === 0 && (c === " " || c === "," || c === " " || c === "\n")) {
|
|
1204
|
-
if (buf) {
|
|
1205
|
-
rawTokens.push(buf);
|
|
1206
|
-
buf = "";
|
|
1207
|
-
}
|
|
1208
|
-
} else buf += c;
|
|
1209
|
-
if (buf) rawTokens.push(buf);
|
|
1210
|
-
let alpha = null;
|
|
1211
|
-
const parts = [];
|
|
1212
|
-
for (let i = 0; i < rawTokens.length; i++) {
|
|
1213
|
-
const tok = rawTokens[i];
|
|
1214
|
-
if (tok === "/") {
|
|
1215
|
-
alpha = rawTokens[i + 1] ?? null;
|
|
1216
|
-
break;
|
|
1217
|
-
}
|
|
1218
|
-
parts.push(tok);
|
|
1219
|
-
}
|
|
1220
|
-
if (alpha === null && parts.length === 4) {
|
|
1221
|
-
alpha = parts[3];
|
|
1222
|
-
parts.length = 3;
|
|
1223
|
-
}
|
|
1224
|
-
if (parts.length !== 3) return null;
|
|
1225
|
-
if (parts.some((p) => !p)) return null;
|
|
1226
|
-
return {
|
|
1227
|
-
parts,
|
|
1228
|
-
alpha
|
|
1229
|
-
};
|
|
1230
|
-
}
|
|
1231
|
-
function buildSameSpaceString(parsed, space) {
|
|
1232
|
-
const func = CANONICAL_FUNC[space];
|
|
1233
|
-
const body = parsed.parts.join(" ");
|
|
1234
|
-
return parsed.alpha != null ? `${func}(${body} / ${parsed.alpha})` : `${func}(${body})`;
|
|
1235
|
-
}
|
|
1236
|
-
/**
|
|
1237
|
-
* Build the decomposed component list for a same-space value.
|
|
1238
|
-
*
|
|
1239
|
-
* Dynamic tokens (`var()` / `calc()` / …) are preserved verbatim — they can't
|
|
1240
|
-
* be parsed and must survive into the CSS output. Purely static components are
|
|
1241
|
-
* normalized to the canonical numeric form for the space so the companion
|
|
1242
|
-
* `--*-color-{space}` variable stays a valid `<number>+` value (rgb/oklch) —
|
|
1243
|
-
* WITHOUT round-tripping through sRGB, which would clamp wide-gamut oklch.
|
|
1244
|
-
*
|
|
1245
|
-
* Non-native, parse-time-only functions (`okhsl()` / `okhst()`) are always
|
|
1246
|
-
* resolved to a static `rgb(...%)` upstream, so this is the path that turns
|
|
1247
|
-
* their percentage channels back into 0-255 numbers.
|
|
1248
|
-
*/
|
|
1249
|
-
function buildSameSpaceComponents(parsed, space) {
|
|
1250
|
-
const parts = parsed.parts;
|
|
1251
|
-
if (parts.some((p) => p.includes("("))) return parts.join(" ");
|
|
1252
|
-
switch (space) {
|
|
1253
|
-
case "rgb": return parts.map((p) => p.endsWith("%") ? formatRgbComponent(parseFloat(p) / 100 * 255) : p).join(" ");
|
|
1254
|
-
case "hsl": return parts.join(" ");
|
|
1255
|
-
case "oklch": {
|
|
1256
|
-
const [l, c, h] = parts;
|
|
1257
|
-
return [
|
|
1258
|
-
l.endsWith("%") ? formatNum(parseFloat(l) / 100, 5) : l,
|
|
1259
|
-
c,
|
|
1260
|
-
h
|
|
1261
|
-
].join(" ");
|
|
1262
|
-
}
|
|
1263
|
-
}
|
|
1264
|
-
}
|
|
1265
|
-
/**
|
|
1266
|
-
* Convert any supported color string to the configured color space CSS format.
|
|
1267
|
-
* Preserves alpha channel when present in the input.
|
|
1268
|
-
* Returns null if the input cannot be parsed.
|
|
1269
|
-
*/
|
|
1270
|
-
function strToColorSpace(color) {
|
|
1271
|
-
if (!color) return void 0;
|
|
1272
|
-
const cached = colorSpaceCache.get(color);
|
|
1273
|
-
if (cached !== void 0) return cached;
|
|
1274
|
-
const sameSpace = parseSameSpaceFunc(color, currentColorSpace);
|
|
1275
|
-
if (sameSpace) {
|
|
1276
|
-
const result = buildSameSpaceString(sameSpace, currentColorSpace);
|
|
1277
|
-
colorSpaceCache.set(color, result);
|
|
1278
|
-
return result;
|
|
1279
|
-
}
|
|
1280
|
-
const rgba = resolveToRgbaValues(color);
|
|
1281
|
-
if (!rgba) {
|
|
1282
|
-
colorSpaceCache.set(color, null);
|
|
1283
|
-
return null;
|
|
1284
|
-
}
|
|
1285
|
-
const result = rgbValuesToColorString(rgba[0], rgba[1], rgba[2], currentColorSpace, rgba[3]);
|
|
1286
|
-
colorSpaceCache.set(color, result);
|
|
1287
|
-
return result;
|
|
1288
|
-
}
|
|
1289
731
|
/**
|
|
1290
732
|
* Set the alpha of a whole color, replacing any it already carries.
|
|
1291
733
|
*
|
|
@@ -1293,14 +735,13 @@ function strToColorSpace(color) {
|
|
|
1293
735
|
* emits. `oklch(from <color> l c h / <alpha>)` copies the channels over and
|
|
1294
736
|
* writes the alpha slot, which needs nothing from the color except that it *is*
|
|
1295
737
|
* a color: a `color-mix()`, a `light-dark()`, a `currentcolor`, a
|
|
1296
|
-
* `--name-color` written by hand-authored CSS
|
|
1297
|
-
*
|
|
1298
|
-
* the engine
|
|
738
|
+
* `--name-color` written by hand-authored CSS that Tasty never defined — all of
|
|
739
|
+
* them work, where writing into a channel slot directly would require channels
|
|
740
|
+
* the engine has no way to compute.
|
|
1299
741
|
*
|
|
1300
742
|
* Alpha is *replaced*, not composed. A token holding `rgb(255 0 0 / .8)` faded
|
|
1301
|
-
* to `.5` is alpha `.5
|
|
1302
|
-
*
|
|
1303
|
-
* cannot do this — it would multiply the two to `.4`.
|
|
743
|
+
* to `.5` is alpha `.5`. `color-mix()` against `transparent` cannot do this —
|
|
744
|
+
* it would multiply the two to `.4`.
|
|
1304
745
|
*
|
|
1305
746
|
* The alpha slot takes a `<number>` or a `<percentage>`, so an opacity custom
|
|
1306
747
|
* property passes straight through in whichever form the author declared it.
|
|
@@ -1350,115 +791,6 @@ function parseAlphaOverride(value) {
|
|
|
1350
791
|
alpha: match[2]
|
|
1351
792
|
} : null;
|
|
1352
793
|
}
|
|
1353
|
-
/** Channel names of each color space, in `<func>()` argument order. */
|
|
1354
|
-
const COLOR_SPACE_CHANNELS = {
|
|
1355
|
-
rgb: "r g b",
|
|
1356
|
-
hsl: "h s l",
|
|
1357
|
-
oklch: "l c h"
|
|
1358
|
-
};
|
|
1359
|
-
/**
|
|
1360
|
-
* Express a color as components of the configured color space *by reference*,
|
|
1361
|
-
* using CSS relative color syntax: `from <color> l c h`.
|
|
1362
|
-
*
|
|
1363
|
-
* Static colors are decomposed into numbers (see `getColorSpaceComponents`), but
|
|
1364
|
-
* a color the engine cannot evaluate at build time — a `color-mix()`, a
|
|
1365
|
-
* `light-dark()`, a `color()` in a space with no conversion, anything reached
|
|
1366
|
-
* through `var()` — has no numbers to decompose. Handing back the relative form
|
|
1367
|
-
* keeps the `--name-color-{space}` companion usable anyway: the browser resolves
|
|
1368
|
-
* the channels, so `oklch(var(--name-color-oklch) / .5)` still applies opacity to
|
|
1369
|
-
* whatever the color turns out to be.
|
|
1370
|
-
*/
|
|
1371
|
-
function toRelativeColorSpaceComponents(color) {
|
|
1372
|
-
return `from ${color} ${COLOR_SPACE_CHANNELS[currentColorSpace]}`;
|
|
1373
|
-
}
|
|
1374
|
-
/**
|
|
1375
|
-
* Extract the decomposed components of a color in the configured color space.
|
|
1376
|
-
* Returns a space-separated string of components without the wrapping function.
|
|
1377
|
-
* Alpha is NOT included — components are used for alpha composition via `/ alpha`.
|
|
1378
|
-
*/
|
|
1379
|
-
function getColorSpaceComponents(color) {
|
|
1380
|
-
const cached = componentsCache.get(color);
|
|
1381
|
-
if (cached !== void 0) return cached;
|
|
1382
|
-
const sameSpace = parseSameSpaceFunc(color, currentColorSpace);
|
|
1383
|
-
if (sameSpace) {
|
|
1384
|
-
const result = buildSameSpaceComponents(sameSpace, currentColorSpace);
|
|
1385
|
-
componentsCache.set(color, result);
|
|
1386
|
-
return result;
|
|
1387
|
-
}
|
|
1388
|
-
const rgba = resolveToRgbaValues(color);
|
|
1389
|
-
if (!rgba) return color;
|
|
1390
|
-
const result = rgbValuesToComponents(rgba[0], rgba[1], rgba[2], currentColorSpace);
|
|
1391
|
-
componentsCache.set(color, result);
|
|
1392
|
-
return result;
|
|
1393
|
-
}
|
|
1394
|
-
/**
|
|
1395
|
-
* Rewrite a color into the `--name-color-{space}` components that `#name.alpha`
|
|
1396
|
-
* composes opacity onto.
|
|
1397
|
-
*
|
|
1398
|
-
* A `var()` chain is rewritten reference by reference so the fallback order
|
|
1399
|
-
* survives; a color the engine can evaluate is decomposed into numbers; anything
|
|
1400
|
-
* left — a derived color function, a `color()` in a space with no conversion —
|
|
1401
|
-
* falls back to relative color syntax and lets the browser do it.
|
|
1402
|
-
*
|
|
1403
|
-
* Returns the input unchanged when there is nothing to rewrite, so callers can
|
|
1404
|
-
* tell whether the conversion found anything.
|
|
1405
|
-
*
|
|
1406
|
-
* Example: `var(--primary-color, var(--secondary-color))`
|
|
1407
|
-
* → `var(--primary-color-oklch, var(--secondary-color-oklch))`
|
|
1408
|
-
*/
|
|
1409
|
-
function convertColorChainToComponentChain(colorValue) {
|
|
1410
|
-
const suffix = getColorSpaceSuffix();
|
|
1411
|
-
const faded = parseAlphaOverride(colorValue);
|
|
1412
|
-
if (faded) return convertColorChainToComponentChain(faded.color);
|
|
1413
|
-
const componentVarMatch = colorValue.match(/^(?:rgb|hsl|oklch)a?\(\s*(var\(--[a-z0-9-]+-color-(?:rgb|hsl|oklch)\))\s*\//);
|
|
1414
|
-
if (componentVarMatch) return componentVarMatch[1];
|
|
1415
|
-
if (colorFuncName(colorValue)) {
|
|
1416
|
-
const components = getColorSpaceComponents(colorValue);
|
|
1417
|
-
return components !== colorValue ? components : toRelativeColorSpaceComponents(colorValue);
|
|
1418
|
-
}
|
|
1419
|
-
const match = colorValue.match(/var\(--([a-z0-9-]+)-color\s*(?:,\s*(.+))?\)/);
|
|
1420
|
-
if (!match) {
|
|
1421
|
-
const components = getColorSpaceComponents(colorValue);
|
|
1422
|
-
if (components !== colorValue) return components;
|
|
1423
|
-
return colorValue;
|
|
1424
|
-
}
|
|
1425
|
-
const [, name, fallback] = match;
|
|
1426
|
-
if (!fallback) return `var(--${name}-color-${suffix})`;
|
|
1427
|
-
return `var(--${name}-color-${suffix}, ${convertColorChainToComponentChain(fallback.trim())})`;
|
|
1428
|
-
}
|
|
1429
|
-
/**
|
|
1430
|
-
* Convert a color initial value (from @property definitions) to components
|
|
1431
|
-
* in the configured color space.
|
|
1432
|
-
*/
|
|
1433
|
-
function colorInitialValueToComponents(initialValue) {
|
|
1434
|
-
if (initialValue == null) return getDefaultComponents();
|
|
1435
|
-
const val = String(initialValue).trim().toLowerCase();
|
|
1436
|
-
if (val === "transparent" || val === "rgba(0,0,0,0)" || val === "") return getDefaultComponents();
|
|
1437
|
-
if (val === "white") return rgbValuesToComponents(255, 255, 255, currentColorSpace);
|
|
1438
|
-
if (val === "black") return rgbValuesToComponents(0, 0, 0, currentColorSpace);
|
|
1439
|
-
const rgbMatch = val.match(/^rgba?\(\s*(\d+)[,\s]+(\d+)[,\s]+(\d+)/);
|
|
1440
|
-
if (rgbMatch) return rgbValuesToComponents(parseInt(rgbMatch[1]), parseInt(rgbMatch[2]), parseInt(rgbMatch[3]), currentColorSpace);
|
|
1441
|
-
return getDefaultComponents();
|
|
1442
|
-
}
|
|
1443
|
-
function getDefaultComponents() {
|
|
1444
|
-
switch (currentColorSpace) {
|
|
1445
|
-
case "rgb": return "0 0 0";
|
|
1446
|
-
case "hsl": return "0 0% 0%";
|
|
1447
|
-
case "oklch": return "0 0 0";
|
|
1448
|
-
}
|
|
1449
|
-
}
|
|
1450
|
-
/**
|
|
1451
|
-
* Get the CSS @property syntax for the companion components variable.
|
|
1452
|
-
* RGB and OKLCH components are all plain numbers, so `<number>+` works.
|
|
1453
|
-
* HSL includes percentages (`h s% l%`), so `*` is the only safe choice.
|
|
1454
|
-
*/
|
|
1455
|
-
function getComponentPropertySyntax() {
|
|
1456
|
-
switch (currentColorSpace) {
|
|
1457
|
-
case "rgb":
|
|
1458
|
-
case "oklch": return "<number>+";
|
|
1459
|
-
default: return "*";
|
|
1460
|
-
}
|
|
1461
|
-
}
|
|
1462
794
|
//#endregion
|
|
1463
795
|
//#region src/parser/types.ts
|
|
1464
796
|
const makeEmptyPart = () => ({
|
|
@@ -1878,6 +1210,96 @@ function classify(raw, opts, recurse) {
|
|
|
1878
1210
|
};
|
|
1879
1211
|
}
|
|
1880
1212
|
//#endregion
|
|
1213
|
+
//#region src/parser/lru.ts
|
|
1214
|
+
/**
|
|
1215
|
+
* Doubly-linked-list LRU.
|
|
1216
|
+
*
|
|
1217
|
+
* The list holds direct node references rather than keys, so rewiring on a
|
|
1218
|
+
* `get()` of a non-MRU entry is pure pointer work. Storing keys instead cost
|
|
1219
|
+
* three extra `Map.get()` lookups per read (prev, next and the current head),
|
|
1220
|
+
* which is measurable on these read-mostly caches: they are hit on every
|
|
1221
|
+
* render once the style pipeline is warm.
|
|
1222
|
+
*/
|
|
1223
|
+
var Lru = class {
|
|
1224
|
+
limit;
|
|
1225
|
+
map = /* @__PURE__ */ new Map();
|
|
1226
|
+
head = null;
|
|
1227
|
+
tail = null;
|
|
1228
|
+
onEvict;
|
|
1229
|
+
constructor(limit = 1e3, onEvict) {
|
|
1230
|
+
this.limit = limit;
|
|
1231
|
+
let normalized = Number.isFinite(this.limit) ? Math.floor(this.limit) : 1e3;
|
|
1232
|
+
if (normalized <= 0) normalized = 1e3;
|
|
1233
|
+
this.limit = normalized;
|
|
1234
|
+
this.onEvict = onEvict;
|
|
1235
|
+
}
|
|
1236
|
+
setOnEvict(fn) {
|
|
1237
|
+
this.onEvict = fn;
|
|
1238
|
+
}
|
|
1239
|
+
get(key) {
|
|
1240
|
+
const node = this.map.get(key);
|
|
1241
|
+
if (node === void 0) return void 0;
|
|
1242
|
+
if (this.head !== node) this.moveToHead(node);
|
|
1243
|
+
return node.value;
|
|
1244
|
+
}
|
|
1245
|
+
set(key, value) {
|
|
1246
|
+
const existing = this.map.get(key);
|
|
1247
|
+
if (existing !== void 0) {
|
|
1248
|
+
existing.value = value;
|
|
1249
|
+
if (this.head !== existing) this.moveToHead(existing);
|
|
1250
|
+
return;
|
|
1251
|
+
}
|
|
1252
|
+
const node = {
|
|
1253
|
+
key,
|
|
1254
|
+
prev: null,
|
|
1255
|
+
next: this.head,
|
|
1256
|
+
value
|
|
1257
|
+
};
|
|
1258
|
+
if (this.head) this.head.prev = node;
|
|
1259
|
+
this.head = node;
|
|
1260
|
+
if (!this.tail) this.tail = node;
|
|
1261
|
+
this.map.set(key, node);
|
|
1262
|
+
if (this.map.size > this.limit) this.evict();
|
|
1263
|
+
}
|
|
1264
|
+
delete(key) {
|
|
1265
|
+
const node = this.map.get(key);
|
|
1266
|
+
if (node === void 0) return;
|
|
1267
|
+
this.detach(node);
|
|
1268
|
+
this.map.delete(key);
|
|
1269
|
+
}
|
|
1270
|
+
keys() {
|
|
1271
|
+
return this.map.keys();
|
|
1272
|
+
}
|
|
1273
|
+
detach(node) {
|
|
1274
|
+
if (node.prev) node.prev.next = node.next;
|
|
1275
|
+
if (node.next) node.next.prev = node.prev;
|
|
1276
|
+
if (this.head === node) this.head = node.next;
|
|
1277
|
+
if (this.tail === node) this.tail = node.prev;
|
|
1278
|
+
node.prev = null;
|
|
1279
|
+
node.next = null;
|
|
1280
|
+
}
|
|
1281
|
+
moveToHead(node) {
|
|
1282
|
+
this.detach(node);
|
|
1283
|
+
node.next = this.head;
|
|
1284
|
+
if (this.head) this.head.prev = node;
|
|
1285
|
+
this.head = node;
|
|
1286
|
+
if (!this.tail) this.tail = node;
|
|
1287
|
+
}
|
|
1288
|
+
evict() {
|
|
1289
|
+
const node = this.tail;
|
|
1290
|
+
if (!node) return;
|
|
1291
|
+
this.detach(node);
|
|
1292
|
+
this.map.delete(node.key);
|
|
1293
|
+
if (this.onEvict) try {
|
|
1294
|
+
this.onEvict(node.key, node.value);
|
|
1295
|
+
} catch {}
|
|
1296
|
+
}
|
|
1297
|
+
clear() {
|
|
1298
|
+
this.map.clear();
|
|
1299
|
+
this.head = this.tail = null;
|
|
1300
|
+
}
|
|
1301
|
+
};
|
|
1302
|
+
//#endregion
|
|
1881
1303
|
//#region src/parser/tokenizer.ts
|
|
1882
1304
|
const isWhitespace = (ch) => ch === " " || ch === "\n" || ch === " " || ch === "\r" || ch === "\f";
|
|
1883
1305
|
function scan(src, cb) {
|
|
@@ -2059,17 +1481,127 @@ var StyleParser = class {
|
|
|
2059
1481
|
//#endregion
|
|
2060
1482
|
//#region src/utils/is-dev-env.ts
|
|
2061
1483
|
/**
|
|
2062
|
-
* Check if we're in a development environment at runtime
|
|
2063
|
-
* Uses bracket notation to avoid bundler compilation
|
|
2064
|
-
* Also checks for TASTY_DEBUG localStorage setting
|
|
1484
|
+
* Check if we're in a development environment at runtime
|
|
1485
|
+
* Uses bracket notation to avoid bundler compilation
|
|
1486
|
+
* Also checks for TASTY_DEBUG localStorage setting
|
|
1487
|
+
*/
|
|
1488
|
+
function isDevEnv() {
|
|
1489
|
+
if (typeof window !== "undefined" && window.localStorage) try {
|
|
1490
|
+
const forceTastyDebug = window.localStorage.getItem("TASTY_DEBUG");
|
|
1491
|
+
if (forceTastyDebug !== null && forceTastyDebug.toLowerCase() === "true") return true;
|
|
1492
|
+
} catch {}
|
|
1493
|
+
if (typeof process === "undefined") return false;
|
|
1494
|
+
return true;
|
|
1495
|
+
}
|
|
1496
|
+
//#endregion
|
|
1497
|
+
//#region src/styles/shared.ts
|
|
1498
|
+
/**
|
|
1499
|
+
* If the group contains exactly one value that is a CSS-wide keyword
|
|
1500
|
+
* and no colors, return the keyword. Otherwise null.
|
|
1501
|
+
*
|
|
1502
|
+
* Direction mods (top/right/bottom/left) may coexist with the keyword
|
|
1503
|
+
* for directional application like `padding="inherit top"`.
|
|
1504
|
+
*/
|
|
1505
|
+
function extractCSSWideKeyword(group) {
|
|
1506
|
+
if (group.values.length !== 1 || group.colors.length > 0) return null;
|
|
1507
|
+
return CSS_WIDE_KEYWORDS.has(group.values[0]) ? group.values[0] : null;
|
|
1508
|
+
}
|
|
1509
|
+
/** A resolved custom-property reference, i.e. `var(--name)` or `var(--name, …)`. */
|
|
1510
|
+
const RE_VAR_REFERENCE = /^var\(/;
|
|
1511
|
+
/**
|
|
1512
|
+
* Assign custom-property references to the style and color slots of a
|
|
1513
|
+
* `<line-width> <line-style> <line-color>` shorthand (`border`, `outline`).
|
|
1514
|
+
*
|
|
1515
|
+
* The parser cannot type a reference, so it buckets `$name` as a plain value and
|
|
1516
|
+
* the handler has to place it. A reference fills the first slot still free, in
|
|
1517
|
+
* shorthand order: the width takes `values[0]`, then the style, then the color.
|
|
1518
|
+
* The style would otherwise arrive as a keyword (`solid`, `dashed`, …) that a
|
|
1519
|
+
* reference has no way to match, and the color as `#name` — the `$name-color`
|
|
1520
|
+
* form the parser buckets as a color exists to reference a raw CSS custom
|
|
1521
|
+
* property, not as the way colors are written, so a reference should not reach
|
|
1522
|
+
* for the color slot until the style slot is taken.
|
|
1523
|
+
*
|
|
1524
|
+
* Lengths are left alone: a second length is not valid in these shorthands, and
|
|
1525
|
+
* promoting one would emit an invalid declaration instead of ignoring an extra
|
|
1526
|
+
* value. Callers supply their own slot defaults.
|
|
1527
|
+
*/
|
|
1528
|
+
function assignLineSlots(values, styleKeyword, colorToken) {
|
|
1529
|
+
if (styleKeyword && colorToken) return {
|
|
1530
|
+
style: styleKeyword,
|
|
1531
|
+
color: colorToken
|
|
1532
|
+
};
|
|
1533
|
+
const spare = values.slice(1).filter((value) => RE_VAR_REFERENCE.test(value) && value !== colorToken);
|
|
1534
|
+
return {
|
|
1535
|
+
style: styleKeyword || spare.shift(),
|
|
1536
|
+
color: colorToken || spare.shift()
|
|
1537
|
+
};
|
|
1538
|
+
}
|
|
1539
|
+
/** Warning keys already emitted, so each distinct offending value warns once. */
|
|
1540
|
+
const emittedWarnings$2 = /* @__PURE__ */ new Set();
|
|
1541
|
+
/** A resolved custom-property reference anywhere in a token. */
|
|
1542
|
+
const RE_HAS_VAR_REFERENCE = /var\(/;
|
|
1543
|
+
/**
|
|
1544
|
+
* Reject a custom-property reference used where a *token name* is expected.
|
|
1545
|
+
*
|
|
1546
|
+
* `preset` and `transition` take the name of a design token (`t3`, `fill`) and
|
|
1547
|
+
* interpolate it into a CSS custom property — `var(--t3-font-size)`. A reference
|
|
1548
|
+
* substituted into that position builds `var(--var(--x)-font-size)`, which is not
|
|
1549
|
+
* a valid custom-property name, so the browser drops the declaration and the
|
|
1550
|
+
* style silently does nothing. The DSL has no way to indirect a token name
|
|
1551
|
+
* through a custom property: the name is needed at build time, and a reference
|
|
1552
|
+
* only resolves in the browser.
|
|
1553
|
+
*
|
|
1554
|
+
* Returns true (warning once per value in dev) so the caller can fall back
|
|
1555
|
+
* instead of emitting a declaration that cannot work.
|
|
1556
|
+
*/
|
|
1557
|
+
function isTokenNameReference(property, name) {
|
|
1558
|
+
if (!RE_HAS_VAR_REFERENCE.test(name)) return false;
|
|
1559
|
+
warnOnceDev(`token-name-reference:${property}:${name}`, `${property}="${name}": a custom property cannot name a token. The name is interpolated into a CSS custom property at build time, so a reference would build an unusable name. It is ignored.`);
|
|
1560
|
+
return true;
|
|
1561
|
+
}
|
|
1562
|
+
/**
|
|
1563
|
+
* Emit a style-level warning at most once per `key`. No-op outside dev mode.
|
|
1564
|
+
*
|
|
1565
|
+
* Style handlers run once per state combination and their results are cached,
|
|
1566
|
+
* but the same value can arrive from many components, so dedupe is required.
|
|
1567
|
+
*
|
|
1568
|
+
* `isDevEnv()` is called lazily rather than captured at module load (the pattern
|
|
1569
|
+
* used in `config.ts` and `states/index.ts`) so that tests can enable it with
|
|
1570
|
+
* `vi.stubEnv('NODE_ENV', 'development')` — `isDevEnv()` returns `false` for
|
|
1571
|
+
* `NODE_ENV=test`, which is why every module-load-gated warning in this repo is
|
|
1572
|
+
* currently untestable. The key is registered *before* the dev check, so
|
|
1573
|
+
* production pays at most one `isDevEnv()` call per distinct offending value and
|
|
1574
|
+
* never touches the console.
|
|
1575
|
+
*/
|
|
1576
|
+
function warnOnceDev(key, message) {
|
|
1577
|
+
if (emittedWarnings$2.has(key)) return;
|
|
1578
|
+
emittedWarnings$2.add(key);
|
|
1579
|
+
if (!isDevEnv()) return;
|
|
1580
|
+
console.warn(`[Tasty] ${message}`);
|
|
1581
|
+
}
|
|
1582
|
+
/** Forget emitted style warnings. Called by `resetConfig()`; test isolation. */
|
|
1583
|
+
function resetStyleWarnings() {
|
|
1584
|
+
emittedWarnings$2.clear();
|
|
1585
|
+
}
|
|
1586
|
+
/**
|
|
1587
|
+
* Report a comma group that names direction modifiers together with more values
|
|
1588
|
+
* than the group can use.
|
|
1589
|
+
*
|
|
1590
|
+
* The parser buckets values and modifiers into separate arrays per comma group,
|
|
1591
|
+
* so `padding: '2x 4x top right'`, `padding: '2x top 4x right'` and
|
|
1592
|
+
* `padding: 'top 2x right 4x'` all reach a handler identically — the pairing a
|
|
1593
|
+
* reader infers from source order does not survive parsing. Such a group
|
|
1594
|
+
* therefore carries a single value, applied to every direction it names.
|
|
1595
|
+
*
|
|
1596
|
+
* `maxValues` is 2 only for a span modifier (`inset: '2x 4x bottom dock'`),
|
|
1597
|
+
* where the second value insets the sides the dock spans.
|
|
1598
|
+
*
|
|
1599
|
+
* Callers must guard on the count themselves so the valid path costs one integer
|
|
1600
|
+
* comparison; everything expensive happens here, on the misuse path only.
|
|
2065
1601
|
*/
|
|
2066
|
-
function
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
if (forceTastyDebug !== null && forceTastyDebug.toLowerCase() === "true") return true;
|
|
2070
|
-
} catch {}
|
|
2071
|
-
if (typeof process === "undefined") return false;
|
|
2072
|
-
return true;
|
|
1602
|
+
function warnExtraGroupValues(property, input, maxValues) {
|
|
1603
|
+
const message = maxValues === 2 ? `${property}="${input}": with a span modifier a group takes at most two values — one for the named edge and one for the spanned sides. The extra values are ignored.` : `${property}="${input}": a group that names directions takes a single value, applied to every direction it names. The extra values are ignored — use comma-separated groups instead, e.g. ${property}="2x top, 4x right".`;
|
|
1604
|
+
warnOnceDev(`extra-values:${property}:${input}`, message);
|
|
2073
1605
|
}
|
|
2074
1606
|
//#endregion
|
|
2075
1607
|
//#region src/plugins/color-func.ts
|
|
@@ -2089,7 +1621,9 @@ const parseAngle = (value) => {
|
|
|
2089
1621
|
}
|
|
2090
1622
|
};
|
|
2091
1623
|
/**
|
|
2092
|
-
* Parse a percentage value (e.g., "50%") to a 0-1 range.
|
|
1624
|
+
* Parse a percentage value (e.g., "50%") to a 0-1 range. A unitless number is
|
|
1625
|
+
* read as the factor it already looks like, so `okhsl(280 .8 .52)` and
|
|
1626
|
+
* `okhsl(280 80% 52%)` are the same color.
|
|
2093
1627
|
*/
|
|
2094
1628
|
const parsePercentage = (value) => {
|
|
2095
1629
|
const match = value.match(/^([+-]?\d*\.?\d+)%?$/);
|
|
@@ -2128,6 +1662,8 @@ function createColorFunc(name, convert, label) {
|
|
|
2128
1662
|
const h = parseAngle(tokens[0]);
|
|
2129
1663
|
const c2 = parsePercentage(tokens[1]);
|
|
2130
1664
|
const c3 = parsePercentage(tokens[2]);
|
|
1665
|
+
const misscaled = [tokens[1], tokens[2]].filter((raw, i) => !raw.includes("%") && (i === 0 ? c2 : c3) > 1);
|
|
1666
|
+
if (misscaled.length) warnOnceDev(`${name}:percent-scale`, `${name}(): channels are factors (0-1) or percentages, so ${misscaled.map((v) => `"${v}"`).join(" and ")} ${misscaled.length > 1 ? "clamp" : "clamps"} to 1 — add the missing '%', or write the value as a 0-1 number.`);
|
|
2131
1667
|
const [r, g, b] = convert(h, clamp(c2, 0, 1), clamp(c3, 0, 1));
|
|
2132
1668
|
const format = (n) => {
|
|
2133
1669
|
const pct = n * 100;
|
|
@@ -2264,22 +1800,35 @@ function normalizeColorTokenValue(value) {
|
|
|
2264
1800
|
return value;
|
|
2265
1801
|
}
|
|
2266
1802
|
const COLOR_VAR_PATTERN = /^var\(--([a-z0-9-]+)-color[,)]/;
|
|
2267
|
-
const COLOR_VAR_COMPONENTS_PATTERN = /^(?:[a-z-]+\(\s*)?var\(--([a-z0-9-]+)-color-(?:rgb|hsl|oklch)[,)]/;
|
|
2268
1803
|
const RGB_ALPHA_PATTERN = /\/\s*([0-9.]+)\)/;
|
|
2269
1804
|
const RE_HEX_COLOR = /^#[0-9a-fA-F]{3,8}$/;
|
|
2270
1805
|
const RE_VAR_COLOR = /^var\(--[a-z0-9-]+-color/;
|
|
2271
1806
|
function isSimpleColorFast(val) {
|
|
2272
1807
|
switch (val.charCodeAt(0)) {
|
|
2273
1808
|
case 35: return RE_HEX_COLOR.test(val);
|
|
2274
|
-
case 114:
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
case
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
case
|
|
2281
|
-
|
|
1809
|
+
case 114:
|
|
1810
|
+
if (val.charCodeAt(1) === 103 && val.charCodeAt(2) === 98) return true;
|
|
1811
|
+
break;
|
|
1812
|
+
case 104:
|
|
1813
|
+
if (val.charCodeAt(1) === 115 && val.charCodeAt(2) === 108) return true;
|
|
1814
|
+
break;
|
|
1815
|
+
case 108:
|
|
1816
|
+
if (val.charCodeAt(1) === 99 && val.charCodeAt(2) === 104) return true;
|
|
1817
|
+
break;
|
|
1818
|
+
case 111:
|
|
1819
|
+
if (val.startsWith("oklch(")) return true;
|
|
1820
|
+
break;
|
|
1821
|
+
case 118:
|
|
1822
|
+
if (RE_VAR_COLOR.test(val)) return true;
|
|
1823
|
+
break;
|
|
1824
|
+
case 99:
|
|
1825
|
+
if (val === "currentColor" || val === "currentcolor") return true;
|
|
1826
|
+
break;
|
|
1827
|
+
case 116:
|
|
1828
|
+
if (val === "transparent") return true;
|
|
1829
|
+
break;
|
|
2282
1830
|
}
|
|
1831
|
+
return getNamedColorHex().has(val.toLowerCase());
|
|
2283
1832
|
}
|
|
2284
1833
|
let colorWarningCount = 0;
|
|
2285
1834
|
const MAX_COLOR_WARNINGS = 10;
|
|
@@ -2456,8 +2005,7 @@ function parseColor(val, ignoreError = false) {
|
|
|
2456
2005
|
}
|
|
2457
2006
|
const faded = parseAlphaOverride(firstColor);
|
|
2458
2007
|
const baseColor = faded ? faded.color : firstColor;
|
|
2459
|
-
|
|
2460
|
-
if (!nameMatch) nameMatch = baseColor.match(COLOR_VAR_COMPONENTS_PATTERN);
|
|
2008
|
+
const nameMatch = baseColor.match(COLOR_VAR_PATTERN);
|
|
2461
2009
|
let opacity;
|
|
2462
2010
|
if (faded) {
|
|
2463
2011
|
const { alpha } = faded;
|
|
@@ -3013,8 +2561,8 @@ function resetStyleChunks() {
|
|
|
3013
2561
|
* unused is one property load and one branch.
|
|
3014
2562
|
*/
|
|
3015
2563
|
const GTKEY$1 = "__tasty_prop_handlers__";
|
|
3016
|
-
const globalStore$
|
|
3017
|
-
const propHandlerRegistry = globalStore$
|
|
2564
|
+
const globalStore$2 = globalThis;
|
|
2565
|
+
const propHandlerRegistry = globalStore$2[GTKEY$1] ?? (globalStore$2[GTKEY$1] = {
|
|
3018
2566
|
apply: null,
|
|
3019
2567
|
list: []
|
|
3020
2568
|
});
|
|
@@ -3224,7 +2772,6 @@ function getEffectiveDefinition(token, userDefinition) {
|
|
|
3224
2772
|
if (!parsed.isValid) return {
|
|
3225
2773
|
cssName: "",
|
|
3226
2774
|
definition: userDefinition,
|
|
3227
|
-
isColor: false,
|
|
3228
2775
|
isValid: false,
|
|
3229
2776
|
error: parsed.error
|
|
3230
2777
|
};
|
|
@@ -3235,13 +2782,11 @@ function getEffectiveDefinition(token, userDefinition) {
|
|
|
3235
2782
|
inherits: userDefinition.inherits,
|
|
3236
2783
|
initialValue: userDefinition.initialValue ?? "transparent"
|
|
3237
2784
|
},
|
|
3238
|
-
isColor: true,
|
|
3239
2785
|
isValid: true
|
|
3240
2786
|
};
|
|
3241
2787
|
return {
|
|
3242
2788
|
cssName: parsed.cssName,
|
|
3243
2789
|
definition: userDefinition,
|
|
3244
|
-
isColor: false,
|
|
3245
2790
|
isValid: true
|
|
3246
2791
|
};
|
|
3247
2792
|
}
|
|
@@ -3641,221 +3186,105 @@ function resetStyleBatch() {
|
|
|
3641
3186
|
* Automatically infers CSS @property types from custom property values.
|
|
3642
3187
|
* Supports deferred resolution for var() reference chains of arbitrary depth.
|
|
3643
3188
|
*/
|
|
3644
|
-
const CUSTOM_PROP_DECL = /^\s*(--[a-z0-9_-]+)\s*:\s*(.+?)\s*$/i;
|
|
3645
|
-
const SINGLE_VAR_REF = /^var\((--[a-z0-9_-]+)\)$/i;
|
|
3646
|
-
/** A `--name-color-{space}` companion holding a color's channel components. */
|
|
3647
|
-
const COLOR_COMPONENTS_DECL = /^\s*(--[a-z0-9_-]+-color-(?:rgb|hsl|oklch))\s*:\s*(.+?)\s*$/i;
|
|
3648
|
-
/** A component list the browser can type as `<number>+`. */
|
|
3649
|
-
const NUMERIC_COMPONENTS = /^[\d\s.+-]+$/;
|
|
3650
|
-
var PropertyTypeResolver = class {
|
|
3651
|
-
/** propName → the prop it depends on */
|
|
3652
|
-
pendingDeps = /* @__PURE__ */ new Map();
|
|
3653
|
-
/** propName → list of props waiting on it */
|
|
3654
|
-
reverseDeps = /* @__PURE__ */ new Map();
|
|
3655
|
-
/**
|
|
3656
|
-
* Scan CSS declarations and auto-register @property for custom properties
|
|
3657
|
-
* whose types can be inferred from their values.
|
|
3658
|
-
*/
|
|
3659
|
-
scanDeclarations(declarations, isPropertyDefined, registerProperty) {
|
|
3660
|
-
if (!declarations.includes("--")) return;
|
|
3661
|
-
const parts = declarations.split(/;+/);
|
|
3662
|
-
for (const part of parts) {
|
|
3663
|
-
const match = COLOR_COMPONENTS_DECL.exec(part);
|
|
3664
|
-
if (!match) continue;
|
|
3665
|
-
const propName = match[1];
|
|
3666
|
-
if (isPropertyDefined(propName)) continue;
|
|
3667
|
-
if (NUMERIC_COMPONENTS.test(match[2])) continue;
|
|
3668
|
-
if (isPropertyDefined(propName.slice(0, propName.lastIndexOf("-")))) continue;
|
|
3669
|
-
registerProperty(propName, "*", getDefaultComponents());
|
|
3670
|
-
}
|
|
3671
|
-
for (const part of parts) {
|
|
3672
|
-
if (!part.trim()) continue;
|
|
3673
|
-
const match = CUSTOM_PROP_DECL.exec(part);
|
|
3674
|
-
if (!match) continue;
|
|
3675
|
-
const propName = match[1];
|
|
3676
|
-
const value = match[2].trim();
|
|
3677
|
-
if (isPropertyDefined(propName)) continue;
|
|
3678
|
-
if (propName.endsWith("-color")) {
|
|
3679
|
-
registerProperty(propName, "<color>", "transparent");
|
|
3680
|
-
continue;
|
|
3681
|
-
}
|
|
3682
|
-
if (propName.endsWith("-line-height")) {
|
|
3683
|
-
registerProperty(propName, "<number> | <length-percentage>", "0");
|
|
3684
|
-
continue;
|
|
3685
|
-
}
|
|
3686
|
-
if (propName.endsWith("-opacity")) {
|
|
3687
|
-
registerProperty(propName, "<number> | <percentage>", "0");
|
|
3688
|
-
continue;
|
|
3689
|
-
}
|
|
3690
|
-
const varMatch = SINGLE_VAR_REF.exec(value);
|
|
3691
|
-
if (varMatch) {
|
|
3692
|
-
const depName = varMatch[1];
|
|
3693
|
-
this.addDependency(propName, depName);
|
|
3694
|
-
continue;
|
|
3695
|
-
}
|
|
3696
|
-
if (this.isComplexValue(value)) continue;
|
|
3697
|
-
const inferred = inferSyntaxFromValue(value);
|
|
3698
|
-
if (!inferred) continue;
|
|
3699
|
-
this.resolve(propName, inferred.syntax, inferred.initialValue, isPropertyDefined, registerProperty);
|
|
3700
|
-
}
|
|
3701
|
-
}
|
|
3702
|
-
addDependency(propName, depName) {
|
|
3703
|
-
if (propName === depName) return;
|
|
3704
|
-
this.pendingDeps.set(propName, depName);
|
|
3705
|
-
let dependents = this.reverseDeps.get(depName);
|
|
3706
|
-
if (!dependents) {
|
|
3707
|
-
dependents = [];
|
|
3708
|
-
this.reverseDeps.set(depName, dependents);
|
|
3709
|
-
}
|
|
3710
|
-
if (!dependents.includes(propName)) dependents.push(propName);
|
|
3711
|
-
}
|
|
3712
|
-
resolve(propName, syntax, initialValue, isPropertyDefined, registerProperty, resolving) {
|
|
3713
|
-
if (!resolving) resolving = /* @__PURE__ */ new Set();
|
|
3714
|
-
if (resolving.has(propName)) return;
|
|
3715
|
-
resolving.add(propName);
|
|
3716
|
-
if (!isPropertyDefined(propName)) registerProperty(propName, syntax, initialValue);
|
|
3717
|
-
const dependents = this.reverseDeps.get(propName);
|
|
3718
|
-
if (dependents) {
|
|
3719
|
-
this.reverseDeps.delete(propName);
|
|
3720
|
-
for (const dependent of dependents) {
|
|
3721
|
-
this.pendingDeps.delete(dependent);
|
|
3722
|
-
if (isPropertyDefined(dependent)) continue;
|
|
3723
|
-
this.resolve(dependent, syntax, initialValue, isPropertyDefined, registerProperty, resolving);
|
|
3724
|
-
}
|
|
3725
|
-
}
|
|
3726
|
-
}
|
|
3727
|
-
isComplexValue(value) {
|
|
3728
|
-
if (value.includes("calc(")) return true;
|
|
3729
|
-
const firstVar = value.indexOf("var(");
|
|
3730
|
-
if (firstVar === -1) return false;
|
|
3731
|
-
if (value.indexOf("var(", firstVar + 4) !== -1) return true;
|
|
3732
|
-
return !SINGLE_VAR_REF.test(value);
|
|
3733
|
-
}
|
|
3734
|
-
};
|
|
3735
|
-
//#endregion
|
|
3736
|
-
//#region src/styles/const.ts
|
|
3737
|
-
const BORDER_STYLES = [
|
|
3738
|
-
"none",
|
|
3739
|
-
"hidden",
|
|
3740
|
-
"dotted",
|
|
3741
|
-
"dashed",
|
|
3742
|
-
"solid",
|
|
3743
|
-
"double",
|
|
3744
|
-
"groove",
|
|
3745
|
-
"ridge",
|
|
3746
|
-
"inset",
|
|
3747
|
-
"outset"
|
|
3748
|
-
];
|
|
3749
|
-
//#endregion
|
|
3750
|
-
//#region src/styles/shared.ts
|
|
3751
|
-
/**
|
|
3752
|
-
* If the group contains exactly one value that is a CSS-wide keyword
|
|
3753
|
-
* and no colors, return the keyword. Otherwise null.
|
|
3754
|
-
*
|
|
3755
|
-
* Direction mods (top/right/bottom/left) may coexist with the keyword
|
|
3756
|
-
* for directional application like `padding="inherit top"`.
|
|
3757
|
-
*/
|
|
3758
|
-
function extractCSSWideKeyword(group) {
|
|
3759
|
-
if (group.values.length !== 1 || group.colors.length > 0) return null;
|
|
3760
|
-
return CSS_WIDE_KEYWORDS.has(group.values[0]) ? group.values[0] : null;
|
|
3761
|
-
}
|
|
3762
|
-
/** A resolved custom-property reference, i.e. `var(--name)` or `var(--name, …)`. */
|
|
3763
|
-
const RE_VAR_REFERENCE = /^var\(/;
|
|
3764
|
-
/**
|
|
3765
|
-
* Assign custom-property references to the style and color slots of a
|
|
3766
|
-
* `<line-width> <line-style> <line-color>` shorthand (`border`, `outline`).
|
|
3767
|
-
*
|
|
3768
|
-
* The parser cannot type a reference, so it buckets `$name` as a plain value and
|
|
3769
|
-
* the handler has to place it. A reference fills the first slot still free, in
|
|
3770
|
-
* shorthand order: the width takes `values[0]`, then the style, then the color.
|
|
3771
|
-
* The style would otherwise arrive as a keyword (`solid`, `dashed`, …) that a
|
|
3772
|
-
* reference has no way to match, and the color as `#name` — the `$name-color`
|
|
3773
|
-
* form the parser buckets as a color exists to reference a raw CSS custom
|
|
3774
|
-
* property, not as the way colors are written, so a reference should not reach
|
|
3775
|
-
* for the color slot until the style slot is taken.
|
|
3776
|
-
*
|
|
3777
|
-
* Lengths are left alone: a second length is not valid in these shorthands, and
|
|
3778
|
-
* promoting one would emit an invalid declaration instead of ignoring an extra
|
|
3779
|
-
* value. Callers supply their own slot defaults.
|
|
3780
|
-
*/
|
|
3781
|
-
function assignLineSlots(values, styleKeyword, colorToken) {
|
|
3782
|
-
if (styleKeyword && colorToken) return {
|
|
3783
|
-
style: styleKeyword,
|
|
3784
|
-
color: colorToken
|
|
3785
|
-
};
|
|
3786
|
-
const spare = values.slice(1).filter((value) => RE_VAR_REFERENCE.test(value) && value !== colorToken);
|
|
3787
|
-
return {
|
|
3788
|
-
style: styleKeyword || spare.shift(),
|
|
3789
|
-
color: colorToken || spare.shift()
|
|
3790
|
-
};
|
|
3791
|
-
}
|
|
3792
|
-
/** Warning keys already emitted, so each distinct offending value warns once. */
|
|
3793
|
-
const emittedWarnings$2 = /* @__PURE__ */ new Set();
|
|
3794
|
-
/** A resolved custom-property reference anywhere in a token. */
|
|
3795
|
-
const RE_HAS_VAR_REFERENCE = /var\(/;
|
|
3796
|
-
/**
|
|
3797
|
-
* Reject a custom-property reference used where a *token name* is expected.
|
|
3798
|
-
*
|
|
3799
|
-
* `preset` and `transition` take the name of a design token (`t3`, `fill`) and
|
|
3800
|
-
* interpolate it into a CSS custom property — `var(--t3-font-size)`. A reference
|
|
3801
|
-
* substituted into that position builds `var(--var(--x)-font-size)`, which is not
|
|
3802
|
-
* a valid custom-property name, so the browser drops the declaration and the
|
|
3803
|
-
* style silently does nothing. The DSL has no way to indirect a token name
|
|
3804
|
-
* through a custom property: the name is needed at build time, and a reference
|
|
3805
|
-
* only resolves in the browser.
|
|
3806
|
-
*
|
|
3807
|
-
* Returns true (warning once per value in dev) so the caller can fall back
|
|
3808
|
-
* instead of emitting a declaration that cannot work.
|
|
3809
|
-
*/
|
|
3810
|
-
function isTokenNameReference(property, name) {
|
|
3811
|
-
if (!RE_HAS_VAR_REFERENCE.test(name)) return false;
|
|
3812
|
-
warnOnceDev(`token-name-reference:${property}:${name}`, `${property}="${name}": a custom property cannot name a token. The name is interpolated into a CSS custom property at build time, so a reference would build an unusable name. It is ignored.`);
|
|
3813
|
-
return true;
|
|
3814
|
-
}
|
|
3815
|
-
/**
|
|
3816
|
-
* Emit a style-level warning at most once per `key`. No-op outside dev mode.
|
|
3817
|
-
*
|
|
3818
|
-
* Style handlers run once per state combination and their results are cached,
|
|
3819
|
-
* but the same value can arrive from many components, so dedupe is required.
|
|
3820
|
-
*
|
|
3821
|
-
* `isDevEnv()` is called lazily rather than captured at module load (the pattern
|
|
3822
|
-
* used in `config.ts` and `states/index.ts`) so that tests can enable it with
|
|
3823
|
-
* `vi.stubEnv('NODE_ENV', 'development')` — `isDevEnv()` returns `false` for
|
|
3824
|
-
* `NODE_ENV=test`, which is why every module-load-gated warning in this repo is
|
|
3825
|
-
* currently untestable. The key is registered *before* the dev check, so
|
|
3826
|
-
* production pays at most one `isDevEnv()` call per distinct offending value and
|
|
3827
|
-
* never touches the console.
|
|
3828
|
-
*/
|
|
3829
|
-
function warnOnceDev(key, message) {
|
|
3830
|
-
if (emittedWarnings$2.has(key)) return;
|
|
3831
|
-
emittedWarnings$2.add(key);
|
|
3832
|
-
if (!isDevEnv()) return;
|
|
3833
|
-
console.warn(`[Tasty] ${message}`);
|
|
3834
|
-
}
|
|
3835
|
-
/** Forget emitted style warnings. Called by `resetConfig()`; test isolation. */
|
|
3836
|
-
function resetStyleWarnings() {
|
|
3837
|
-
emittedWarnings$2.clear();
|
|
3838
|
-
}
|
|
3839
3189
|
/**
|
|
3840
|
-
*
|
|
3841
|
-
* than the group can use.
|
|
3842
|
-
*
|
|
3843
|
-
* The parser buckets values and modifiers into separate arrays per comma group,
|
|
3844
|
-
* so `padding: '2x 4x top right'`, `padding: '2x top 4x right'` and
|
|
3845
|
-
* `padding: 'top 2x right 4x'` all reach a handler identically — the pairing a
|
|
3846
|
-
* reader infers from source order does not survive parsing. Such a group
|
|
3847
|
-
* therefore carries a single value, applied to every direction it names.
|
|
3190
|
+
* One `--name: value` declaration, with the surrounding whitespace dropped.
|
|
3848
3191
|
*
|
|
3849
|
-
*
|
|
3850
|
-
*
|
|
3851
|
-
*
|
|
3852
|
-
* Callers must guard on the count themselves so the valid path costs one integer
|
|
3853
|
-
* comparison; everything expensive happens here, on the misuse path only.
|
|
3192
|
+
* The value is anchored on `\S` at both ends so no two quantifiers can claim
|
|
3193
|
+
* the same character. A lazy `(.+?)\s*$` is quadratic on a value of nothing
|
|
3194
|
+
* but spaces — every split point gets tried (CodeQL `js/polynomial-redos`).
|
|
3854
3195
|
*/
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3196
|
+
const CUSTOM_PROP_DECL = /^\s*(--[a-z0-9_-]+)\s*:\s*(\S|\S.*\S)\s*$/i;
|
|
3197
|
+
const SINGLE_VAR_REF = /^var\((--[a-z0-9_-]+)\)$/i;
|
|
3198
|
+
var PropertyTypeResolver = class {
|
|
3199
|
+
/** propName → the prop it depends on */
|
|
3200
|
+
pendingDeps = /* @__PURE__ */ new Map();
|
|
3201
|
+
/** propName → list of props waiting on it */
|
|
3202
|
+
reverseDeps = /* @__PURE__ */ new Map();
|
|
3203
|
+
/**
|
|
3204
|
+
* Scan CSS declarations and auto-register @property for custom properties
|
|
3205
|
+
* whose types can be inferred from their values.
|
|
3206
|
+
*/
|
|
3207
|
+
scanDeclarations(declarations, isPropertyDefined, registerProperty) {
|
|
3208
|
+
if (!declarations.includes("--")) return;
|
|
3209
|
+
const parts = declarations.split(/;+/);
|
|
3210
|
+
for (const part of parts) {
|
|
3211
|
+
if (!part.trim()) continue;
|
|
3212
|
+
const match = CUSTOM_PROP_DECL.exec(part);
|
|
3213
|
+
if (!match) continue;
|
|
3214
|
+
const propName = match[1];
|
|
3215
|
+
const value = match[2].trim();
|
|
3216
|
+
if (isPropertyDefined(propName)) continue;
|
|
3217
|
+
if (propName.endsWith("-color")) {
|
|
3218
|
+
registerProperty(propName, "<color>", "transparent");
|
|
3219
|
+
continue;
|
|
3220
|
+
}
|
|
3221
|
+
if (propName.endsWith("-line-height")) {
|
|
3222
|
+
registerProperty(propName, "<number> | <length-percentage>", "0");
|
|
3223
|
+
continue;
|
|
3224
|
+
}
|
|
3225
|
+
if (propName.endsWith("-opacity")) {
|
|
3226
|
+
registerProperty(propName, "<number> | <percentage>", "0");
|
|
3227
|
+
continue;
|
|
3228
|
+
}
|
|
3229
|
+
const varMatch = SINGLE_VAR_REF.exec(value);
|
|
3230
|
+
if (varMatch) {
|
|
3231
|
+
const depName = varMatch[1];
|
|
3232
|
+
this.addDependency(propName, depName);
|
|
3233
|
+
continue;
|
|
3234
|
+
}
|
|
3235
|
+
if (this.isComplexValue(value)) continue;
|
|
3236
|
+
const inferred = inferSyntaxFromValue(value);
|
|
3237
|
+
if (!inferred) continue;
|
|
3238
|
+
this.resolve(propName, inferred.syntax, inferred.initialValue, isPropertyDefined, registerProperty);
|
|
3239
|
+
}
|
|
3240
|
+
}
|
|
3241
|
+
addDependency(propName, depName) {
|
|
3242
|
+
if (propName === depName) return;
|
|
3243
|
+
this.pendingDeps.set(propName, depName);
|
|
3244
|
+
let dependents = this.reverseDeps.get(depName);
|
|
3245
|
+
if (!dependents) {
|
|
3246
|
+
dependents = [];
|
|
3247
|
+
this.reverseDeps.set(depName, dependents);
|
|
3248
|
+
}
|
|
3249
|
+
if (!dependents.includes(propName)) dependents.push(propName);
|
|
3250
|
+
}
|
|
3251
|
+
resolve(propName, syntax, initialValue, isPropertyDefined, registerProperty, resolving) {
|
|
3252
|
+
if (!resolving) resolving = /* @__PURE__ */ new Set();
|
|
3253
|
+
if (resolving.has(propName)) return;
|
|
3254
|
+
resolving.add(propName);
|
|
3255
|
+
if (!isPropertyDefined(propName)) registerProperty(propName, syntax, initialValue);
|
|
3256
|
+
const dependents = this.reverseDeps.get(propName);
|
|
3257
|
+
if (dependents) {
|
|
3258
|
+
this.reverseDeps.delete(propName);
|
|
3259
|
+
for (const dependent of dependents) {
|
|
3260
|
+
this.pendingDeps.delete(dependent);
|
|
3261
|
+
if (isPropertyDefined(dependent)) continue;
|
|
3262
|
+
this.resolve(dependent, syntax, initialValue, isPropertyDefined, registerProperty, resolving);
|
|
3263
|
+
}
|
|
3264
|
+
}
|
|
3265
|
+
}
|
|
3266
|
+
isComplexValue(value) {
|
|
3267
|
+
if (value.includes("calc(")) return true;
|
|
3268
|
+
const firstVar = value.indexOf("var(");
|
|
3269
|
+
if (firstVar === -1) return false;
|
|
3270
|
+
if (value.indexOf("var(", firstVar + 4) !== -1) return true;
|
|
3271
|
+
return !SINGLE_VAR_REF.test(value);
|
|
3272
|
+
}
|
|
3273
|
+
};
|
|
3274
|
+
//#endregion
|
|
3275
|
+
//#region src/styles/const.ts
|
|
3276
|
+
const BORDER_STYLES = [
|
|
3277
|
+
"none",
|
|
3278
|
+
"hidden",
|
|
3279
|
+
"dotted",
|
|
3280
|
+
"dashed",
|
|
3281
|
+
"solid",
|
|
3282
|
+
"double",
|
|
3283
|
+
"groove",
|
|
3284
|
+
"ridge",
|
|
3285
|
+
"inset",
|
|
3286
|
+
"outset"
|
|
3287
|
+
];
|
|
3859
3288
|
//#endregion
|
|
3860
3289
|
//#region src/styles/border.ts
|
|
3861
3290
|
/**
|
|
@@ -3971,21 +3400,19 @@ function borderStyle({ border }) {
|
|
|
3971
3400
|
borderStyle.__lookupStyles = ["border"];
|
|
3972
3401
|
//#endregion
|
|
3973
3402
|
//#region src/styles/color.ts
|
|
3403
|
+
/**
|
|
3404
|
+
* A color that already resolves against the color the element inherits, and so
|
|
3405
|
+
* must not be republished as `--current-color`: a descendant reading the
|
|
3406
|
+
* variable would resolve it a second time against its own color. Covers the
|
|
3407
|
+
* keyword and the variable alike — the latter would also be a self-reference.
|
|
3408
|
+
*/
|
|
3409
|
+
const RE_READS_CURRENT = /var\(--current-color[,)]|currentcolor/i;
|
|
3974
3410
|
function colorStyle({ color }) {
|
|
3975
3411
|
if (!color) return null;
|
|
3976
3412
|
if (color === true) color = "currentColor";
|
|
3977
3413
|
color = parseColor(color, true).color || resolveCustomProperties(color);
|
|
3978
|
-
const match = color.match(/var\(--(.+?)-color/);
|
|
3979
|
-
let name = "";
|
|
3980
|
-
if (match) name = match[1];
|
|
3981
3414
|
const styles = { color };
|
|
3982
|
-
if (
|
|
3983
|
-
const suffix = getColorSpaceSuffix();
|
|
3984
|
-
Object.assign(styles, {
|
|
3985
|
-
"--current-color": color,
|
|
3986
|
-
[`--current-color-${suffix}`]: convertColorChainToComponentChain(color)
|
|
3987
|
-
});
|
|
3988
|
-
}
|
|
3415
|
+
if (!RE_READS_CURRENT.test(color)) styles["--current-color"] = color;
|
|
3989
3416
|
return styles;
|
|
3990
3417
|
}
|
|
3991
3418
|
colorStyle.__lookupStyles = ["color"];
|
|
@@ -4015,31 +3442,7 @@ function createStyle(styleName, cssStyle, converter) {
|
|
|
4015
3442
|
}
|
|
4016
3443
|
if (typeof styleValue === "string" && finalCssStyle.startsWith("--") && finalCssStyle.endsWith("-color")) {
|
|
4017
3444
|
styleValue = styleValue.trim();
|
|
4018
|
-
|
|
4019
|
-
const colorSpaceStr = strToColorSpace(styleValue);
|
|
4020
|
-
const { color, name } = parseColor(styleValue);
|
|
4021
|
-
if (name && colorSpaceStr) return {
|
|
4022
|
-
[finalCssStyle]: `var(--${name}-color, ${colorSpaceStr})`,
|
|
4023
|
-
[`${finalCssStyle}-${suffix}`]: `var(--${name}-color-${suffix}, ${getColorSpaceComponents(colorSpaceStr)})`
|
|
4024
|
-
};
|
|
4025
|
-
else if (name) {
|
|
4026
|
-
if (color) return {
|
|
4027
|
-
[finalCssStyle]: color,
|
|
4028
|
-
[`${finalCssStyle}-${suffix}`]: convertColorChainToComponentChain(color)
|
|
4029
|
-
};
|
|
4030
|
-
return {
|
|
4031
|
-
[finalCssStyle]: `var(--${name}-color)`,
|
|
4032
|
-
[`${finalCssStyle}-${suffix}`]: `var(--${name}-color-${suffix})`
|
|
4033
|
-
};
|
|
4034
|
-
} else if (colorSpaceStr) return {
|
|
4035
|
-
[finalCssStyle]: colorSpaceStr,
|
|
4036
|
-
[`${finalCssStyle}-${suffix}`]: getColorSpaceComponents(colorSpaceStr)
|
|
4037
|
-
};
|
|
4038
|
-
if (color && colorFuncName(color)) return {
|
|
4039
|
-
[finalCssStyle]: color,
|
|
4040
|
-
[`${finalCssStyle}-${suffix}`]: convertColorChainToComponentChain(color)
|
|
4041
|
-
};
|
|
4042
|
-
return { [finalCssStyle]: color ?? "" };
|
|
3445
|
+
return { [finalCssStyle]: parseColor(styleValue).color ?? "" };
|
|
4043
3446
|
}
|
|
4044
3447
|
const processed = parseStyle(styleValue);
|
|
4045
3448
|
return { [finalCssStyle]: processed.output };
|
|
@@ -5634,6 +5037,8 @@ var SheetManager = class {
|
|
|
5634
5037
|
if (!registry) {
|
|
5635
5038
|
const metrics = this.config.devMode ? {
|
|
5636
5039
|
hits: 0,
|
|
5040
|
+
precompiledHits: 0,
|
|
5041
|
+
precompiledUniqueHits: 0,
|
|
5637
5042
|
misses: 0,
|
|
5638
5043
|
bulkCleanups: 0,
|
|
5639
5044
|
totalInsertions: 0,
|
|
@@ -5644,7 +5049,7 @@ var SheetManager = class {
|
|
|
5644
5049
|
} : void 0;
|
|
5645
5050
|
registry = {
|
|
5646
5051
|
sheets: [],
|
|
5647
|
-
|
|
5052
|
+
pinCounts: /* @__PURE__ */ new Map(),
|
|
5648
5053
|
rules: /* @__PURE__ */ new Map(),
|
|
5649
5054
|
cacheKeyToClassName: /* @__PURE__ */ new Map(),
|
|
5650
5055
|
ruleTextSet: /* @__PURE__ */ new Set(),
|
|
@@ -5658,10 +5063,9 @@ var SheetManager = class {
|
|
|
5658
5063
|
injectedFunctions: /* @__PURE__ */ new Map(),
|
|
5659
5064
|
globalRules: /* @__PURE__ */ new Map(),
|
|
5660
5065
|
propertyTypeResolver: new PropertyTypeResolver(),
|
|
5661
|
-
|
|
5066
|
+
unusedSince: /* @__PURE__ */ new Map(),
|
|
5067
|
+
localKeyframes: /* @__PURE__ */ new Map(),
|
|
5662
5068
|
touchCount: 0,
|
|
5663
|
-
touchTick: -1,
|
|
5664
|
-
touchedTick: /* @__PURE__ */ new Set(),
|
|
5665
5069
|
serverClassSyncIndex: 0,
|
|
5666
5070
|
rscStylesScanned: false,
|
|
5667
5071
|
injectionMode: this.detectInjectionMode(root)
|
|
@@ -6043,25 +5447,26 @@ var SheetManager = class {
|
|
|
6043
5447
|
return registry.atPropertySupported;
|
|
6044
5448
|
}
|
|
6045
5449
|
/**
|
|
6046
|
-
*
|
|
6047
|
-
|
|
6048
|
-
|
|
6049
|
-
|
|
6050
|
-
|
|
6051
|
-
|
|
6052
|
-
*
|
|
5450
|
+
* Delete the given classes: their rules leave the sheets and every registry
|
|
5451
|
+
* entry pointing at them is dropped.
|
|
5452
|
+
*
|
|
5453
|
+
* Deciding *what* is unused belongs to `StyleInjector.gc()`, which owns the
|
|
5454
|
+
* DOM scan and the capacity policy. This only re-checks that each class is
|
|
5455
|
+
* still safe to delete, and reports how many were.
|
|
5456
|
+
*
|
|
5457
|
+
* @returns Number of classes actually deleted.
|
|
6053
5458
|
*/
|
|
6054
|
-
|
|
5459
|
+
deleteClasses(registry, classNames) {
|
|
6055
5460
|
const cleanupStartTime = Date.now();
|
|
6056
|
-
const
|
|
6057
|
-
if (unusedClassNames.length === 0) return;
|
|
6058
|
-
const selected = unusedClassNames.map((className) => {
|
|
5461
|
+
const selected = Array.from(classNames).map((className) => {
|
|
6059
5462
|
const ruleInfo = registry.rules.get(className);
|
|
6060
5463
|
return ruleInfo ? {
|
|
6061
5464
|
className,
|
|
6062
5465
|
ruleInfo
|
|
6063
5466
|
} : null;
|
|
6064
5467
|
}).filter((entry) => entry != null);
|
|
5468
|
+
if (selected.length === 0) return 0;
|
|
5469
|
+
const deleted = /* @__PURE__ */ new Set();
|
|
6065
5470
|
let cleanedUpCount = 0;
|
|
6066
5471
|
let totalCssSize = 0;
|
|
6067
5472
|
let totalRulesDeleted = 0;
|
|
@@ -6082,7 +5487,7 @@ var SheetManager = class {
|
|
|
6082
5487
|
for (const [_sheetIndex, rulesInSheet] of rulesBySheet) {
|
|
6083
5488
|
rulesInSheet.sort((a, b) => b.ruleInfo.ruleIndex - a.ruleInfo.ruleIndex);
|
|
6084
5489
|
for (const { className, ruleInfo } of rulesInSheet) {
|
|
6085
|
-
if ((registry.
|
|
5490
|
+
if ((registry.pinCounts.get(className) ?? 0) > 0) continue;
|
|
6086
5491
|
if (registry.rules.get(className) !== ruleInfo) continue;
|
|
6087
5492
|
const sheetInfo = registry.sheets[ruleInfo.sheetIndex];
|
|
6088
5493
|
if (!sheetInfo || !sheetInfo.sheet && !sheetInfo.constructableSheet) continue;
|
|
@@ -6094,13 +5499,22 @@ var SheetManager = class {
|
|
|
6094
5499
|
if (startIdx < 0 || endIdx > maxRuleIndex || startIdx > endIdx) continue;
|
|
6095
5500
|
this.deleteRule(registry, ruleInfo);
|
|
6096
5501
|
registry.rules.delete(className);
|
|
6097
|
-
registry.
|
|
6098
|
-
|
|
6099
|
-
for (const [key,
|
|
6100
|
-
|
|
5502
|
+
registry.pinCounts.delete(className);
|
|
5503
|
+
registry.unusedSince.delete(className);
|
|
5504
|
+
for (const [key, entry] of registry.localKeyframes) {
|
|
5505
|
+
if (!entry.owners.delete(className)) continue;
|
|
5506
|
+
if (entry.owners.size === 0) {
|
|
5507
|
+
entry.dispose();
|
|
5508
|
+
registry.localKeyframes.delete(key);
|
|
5509
|
+
}
|
|
5510
|
+
}
|
|
5511
|
+
deleted.add(className);
|
|
6101
5512
|
cleanedUpCount++;
|
|
6102
5513
|
}
|
|
6103
5514
|
}
|
|
5515
|
+
if (deleted.size > 0) {
|
|
5516
|
+
for (const [key, mappedClassName] of registry.cacheKeyToClassName) if (deleted.has(mappedClassName)) registry.cacheKeyToClassName.delete(key);
|
|
5517
|
+
}
|
|
6104
5518
|
if (registry.metrics) {
|
|
6105
5519
|
registry.metrics.bulkCleanups++;
|
|
6106
5520
|
registry.metrics.stylesCleanedUp += cleanedUpCount;
|
|
@@ -6111,6 +5525,7 @@ var SheetManager = class {
|
|
|
6111
5525
|
rulesDeleted: totalRulesDeleted
|
|
6112
5526
|
});
|
|
6113
5527
|
}
|
|
5528
|
+
return cleanedUpCount;
|
|
6114
5529
|
}
|
|
6115
5530
|
/**
|
|
6116
5531
|
* Get total number of rules across all sheets
|
|
@@ -6119,25 +5534,31 @@ var SheetManager = class {
|
|
|
6119
5534
|
return registry.sheets.reduce((total, sheet) => total + sheet.ruleCount - sheet.holes.length, 0);
|
|
6120
5535
|
}
|
|
6121
5536
|
/**
|
|
6122
|
-
*
|
|
5537
|
+
* The CSS of one managed sheet, or `null` when it holds none this can read —
|
|
5538
|
+
* an empty style element, or a sheet the engine refuses to hand over.
|
|
6123
5539
|
*/
|
|
6124
|
-
|
|
6125
|
-
|
|
6126
|
-
|
|
6127
|
-
if (sheetInfo.
|
|
6128
|
-
const rules = Array.from(sheetInfo.constructableSheet.cssRules);
|
|
6129
|
-
cssChunks.push(rules.map((rule) => rule.cssText).join("\n"));
|
|
6130
|
-
} else if (sheetInfo.sheet) {
|
|
5540
|
+
readSheetCSS(sheetInfo) {
|
|
5541
|
+
try {
|
|
5542
|
+
if (sheetInfo.constructableSheet) return Array.from(sheetInfo.constructableSheet.cssRules).map((rule) => rule.cssText).join("\n");
|
|
5543
|
+
if (sheetInfo.sheet) {
|
|
6131
5544
|
const styleElement = sheetInfo.sheet;
|
|
6132
|
-
if (styleElement.textContent)
|
|
6133
|
-
|
|
6134
|
-
const rules = Array.from(styleElement.sheet.cssRules);
|
|
6135
|
-
cssChunks.push(rules.map((rule) => rule.cssText).join("\n"));
|
|
6136
|
-
}
|
|
5545
|
+
if (styleElement.textContent) return styleElement.textContent;
|
|
5546
|
+
if (styleElement.sheet) return Array.from(styleElement.sheet.cssRules).map((rule) => rule.cssText).join("\n");
|
|
6137
5547
|
}
|
|
6138
5548
|
} catch (error) {
|
|
6139
5549
|
console.warn("[Tasty] Failed to read CSS from sheet:", error);
|
|
6140
5550
|
}
|
|
5551
|
+
return null;
|
|
5552
|
+
}
|
|
5553
|
+
/**
|
|
5554
|
+
* Get CSS text from all sheets (for SSR)
|
|
5555
|
+
*/
|
|
5556
|
+
getCSSText(registry) {
|
|
5557
|
+
const cssChunks = [];
|
|
5558
|
+
for (const sheetInfo of registry.sheets) {
|
|
5559
|
+
const css = this.readSheetCSS(sheetInfo);
|
|
5560
|
+
if (css !== null) cssChunks.push(css);
|
|
5561
|
+
}
|
|
6141
5562
|
return cssChunks.join("\n");
|
|
6142
5563
|
}
|
|
6143
5564
|
/**
|
|
@@ -6145,26 +5566,30 @@ var SheetManager = class {
|
|
|
6145
5566
|
*/
|
|
6146
5567
|
getMetrics(registry) {
|
|
6147
5568
|
if (!registry.metrics) return null;
|
|
6148
|
-
const unusedRulesCount = Array.from(registry.refCounts.values()).filter((count) => count === 0).length;
|
|
6149
5569
|
return {
|
|
6150
5570
|
...registry.metrics,
|
|
6151
|
-
unusedHits:
|
|
5571
|
+
unusedHits: 0
|
|
6152
5572
|
};
|
|
6153
5573
|
}
|
|
6154
5574
|
/**
|
|
6155
5575
|
* Reset cache performance metrics
|
|
6156
5576
|
*/
|
|
6157
5577
|
resetMetrics(registry) {
|
|
6158
|
-
if (registry.metrics)
|
|
6159
|
-
|
|
6160
|
-
|
|
6161
|
-
|
|
6162
|
-
|
|
6163
|
-
|
|
6164
|
-
|
|
6165
|
-
|
|
6166
|
-
|
|
6167
|
-
|
|
5578
|
+
if (registry.metrics) {
|
|
5579
|
+
registry.metrics = {
|
|
5580
|
+
hits: 0,
|
|
5581
|
+
precompiledHits: 0,
|
|
5582
|
+
precompiledUniqueHits: 0,
|
|
5583
|
+
misses: 0,
|
|
5584
|
+
bulkCleanups: 0,
|
|
5585
|
+
totalInsertions: 0,
|
|
5586
|
+
totalUnused: 0,
|
|
5587
|
+
stylesCleanedUp: 0,
|
|
5588
|
+
cleanupHistory: [],
|
|
5589
|
+
startTime: Date.now()
|
|
5590
|
+
};
|
|
5591
|
+
registry.precompiledUsedClasses = void 0;
|
|
5592
|
+
}
|
|
6168
5593
|
}
|
|
6169
5594
|
/**
|
|
6170
5595
|
* Convert keyframes steps to CSS string.
|
|
@@ -6450,6 +5875,49 @@ var SheetManager = class {
|
|
|
6450
5875
|
/**
|
|
6451
5876
|
* Get the raw CSS content
|
|
6452
5877
|
*/
|
|
5878
|
+
/**
|
|
5879
|
+
* The CSS this injector owns in `root`, one entry per sheet, in the order the
|
|
5880
|
+
* engine applies them.
|
|
5881
|
+
*
|
|
5882
|
+
* `getCSSText()` walks the managed sheets only, and raw CSS has its own —
|
|
5883
|
+
* which sits before, after, or *between* them depending on how it got there:
|
|
5884
|
+
* prepended to `adoptedStyleSheets`, or wherever in `<head>` the first raw
|
|
5885
|
+
* injection happened to land, with every managed sheet opened afterwards
|
|
5886
|
+
* following it. Reporting a fixed order would describe the opposite winner
|
|
5887
|
+
* from the live page whenever two rules of equal specificity meet, so the raw
|
|
5888
|
+
* sheet is spliced in at the position the DOM actually gives it.
|
|
5889
|
+
*/
|
|
5890
|
+
getOwnedCSSInOrder(registry, root) {
|
|
5891
|
+
const raw = this.getRawCSSText(root);
|
|
5892
|
+
const rawElement = this.isAdoptedMode(root) ? null : this.rawStyleElements.get(root);
|
|
5893
|
+
let rawIndex = raw && !rawElement ? 0 : -1;
|
|
5894
|
+
const chunks = [];
|
|
5895
|
+
for (const sheetInfo of registry.sheets) {
|
|
5896
|
+
const css = this.readSheetCSS(sheetInfo);
|
|
5897
|
+
if (css === null) continue;
|
|
5898
|
+
if (rawIndex < 0 && rawElement && sheetInfo.sheet && rawElement.compareDocumentPosition(sheetInfo.sheet) & Node.DOCUMENT_POSITION_FOLLOWING) rawIndex = chunks.length;
|
|
5899
|
+
chunks.push(css);
|
|
5900
|
+
}
|
|
5901
|
+
if (!raw) return chunks;
|
|
5902
|
+
chunks.splice(rawIndex < 0 ? chunks.length : rawIndex, 0, raw);
|
|
5903
|
+
return chunks;
|
|
5904
|
+
}
|
|
5905
|
+
/**
|
|
5906
|
+
* Top-level rules in the raw sheet.
|
|
5907
|
+
*
|
|
5908
|
+
* Read from the sheet the engine parsed, not from the text: a raw block is
|
|
5909
|
+
* one string but any number of rules, and one rule — `@keyframes`, `@media` —
|
|
5910
|
+
* can contain any number of blocks, so counting braces answers neither
|
|
5911
|
+
* question.
|
|
5912
|
+
*/
|
|
5913
|
+
getRawRuleCount(root) {
|
|
5914
|
+
const sheet = this.isAdoptedMode(root) ? this.rawConstructableSheets.get(root) : this.rawStyleElements.get(root)?.sheet;
|
|
5915
|
+
try {
|
|
5916
|
+
return sheet?.cssRules.length ?? 0;
|
|
5917
|
+
} catch {
|
|
5918
|
+
return 0;
|
|
5919
|
+
}
|
|
5920
|
+
}
|
|
6453
5921
|
getRawCSSText(root) {
|
|
6454
5922
|
if (this.isAdoptedMode(root)) {
|
|
6455
5923
|
const blocksMap = this.rawCSSBlocks.get(root);
|
|
@@ -6572,6 +6040,13 @@ function formatCounterStyleRule(name, descriptors) {
|
|
|
6572
6040
|
//#endregion
|
|
6573
6041
|
//#region src/injector/injector.ts
|
|
6574
6042
|
/**
|
|
6043
|
+
* How long a class is left alone after it was last known to be wanted.
|
|
6044
|
+
* Long enough that a render cannot plausibly still be waiting to commit one.
|
|
6045
|
+
*/
|
|
6046
|
+
const DEFAULT_GC_GRACE = 1e4;
|
|
6047
|
+
/** Dispose handle handed back for injections that took no pin. */
|
|
6048
|
+
const noop = () => {};
|
|
6049
|
+
/**
|
|
6575
6050
|
* Placeholder `KeyframesInfo` for a cache entry reserved by a batched write and
|
|
6576
6051
|
* not yet backed by a real rule. Only ever read through `entry.pending`, which
|
|
6577
6052
|
* is checked before the info is used.
|
|
@@ -6628,21 +6103,54 @@ function registerHydratedClass(registry, className) {
|
|
|
6628
6103
|
ruleIndex: -2,
|
|
6629
6104
|
sheetIndex: -2
|
|
6630
6105
|
});
|
|
6631
|
-
registry.
|
|
6106
|
+
registry.pinCounts.set(className, 0);
|
|
6632
6107
|
}
|
|
6633
6108
|
var StyleInjector = class {
|
|
6634
6109
|
sheetManager;
|
|
6635
6110
|
config;
|
|
6636
6111
|
globalRuleCounter = 0;
|
|
6637
|
-
|
|
6112
|
+
/** Cancels the scheduled sweep, whichever timer scheduled it. */
|
|
6113
|
+
cancelPendingGC = null;
|
|
6638
6114
|
namePrefix;
|
|
6639
6115
|
classRegex;
|
|
6640
6116
|
rscClassRegex;
|
|
6117
|
+
precompiledRevision = -1;
|
|
6641
6118
|
/** @internal — exposed for debug utilities only */
|
|
6642
6119
|
get _sheetManager() {
|
|
6643
6120
|
return this.sheetManager;
|
|
6644
6121
|
}
|
|
6645
6122
|
/**
|
|
6123
|
+
* Seed deduplication metadata for rules supplied by an immutable external
|
|
6124
|
+
* stylesheet. This records no owned sheet entries and performs no CSS work.
|
|
6125
|
+
* @internal
|
|
6126
|
+
*/
|
|
6127
|
+
registerPrecompiledDependencies(dependencies, revision) {
|
|
6128
|
+
if (typeof document === "undefined" || this.precompiledRevision === revision) return;
|
|
6129
|
+
const registry = this.sheetManager.getRegistry(document);
|
|
6130
|
+
for (const item of dependencies.properties) if (!registry.injectedProperties.has(item.name)) registry.injectedProperties.set(item.name, item.definition);
|
|
6131
|
+
for (const hash of dependencies.fontFaces) registry.injectedFontFaces.add(hash);
|
|
6132
|
+
for (const item of dependencies.counterStyles) if (!registry.injectedCounterStyles.has(item.name)) registry.injectedCounterStyles.set(item.name, true);
|
|
6133
|
+
for (const name of dependencies.functions) if (!registry.injectedFunctions.has(name)) registry.injectedFunctions.set(name, true);
|
|
6134
|
+
for (const item of dependencies.keyframes) {
|
|
6135
|
+
if (!registry.keyframesCache.has(item.contentKey)) registry.keyframesCache.set(item.contentKey, {
|
|
6136
|
+
name: item.name,
|
|
6137
|
+
refCount: Number.POSITIVE_INFINITY,
|
|
6138
|
+
info: {
|
|
6139
|
+
name: item.name,
|
|
6140
|
+
ruleIndex: -2,
|
|
6141
|
+
sheetIndex: -2
|
|
6142
|
+
}
|
|
6143
|
+
});
|
|
6144
|
+
if (!registry.keyframesNameToContent.has(item.name)) registry.keyframesNameToContent.set(item.name, item.contentKey);
|
|
6145
|
+
if (!registry.localKeyframes.has(item.name)) registry.localKeyframes.set(item.name, {
|
|
6146
|
+
name: item.name,
|
|
6147
|
+
dispose: () => {},
|
|
6148
|
+
owners: /* @__PURE__ */ new Set()
|
|
6149
|
+
});
|
|
6150
|
+
}
|
|
6151
|
+
this.precompiledRevision = revision;
|
|
6152
|
+
}
|
|
6153
|
+
/**
|
|
6646
6154
|
* Whether sheet writes should be queued instead of applied immediately.
|
|
6647
6155
|
*
|
|
6648
6156
|
* Only ever true on the client: SSR collects CSS as text and the RSC path
|
|
@@ -6722,6 +6230,28 @@ var StyleInjector = class {
|
|
|
6722
6230
|
return false;
|
|
6723
6231
|
}
|
|
6724
6232
|
/**
|
|
6233
|
+
* Resolve an already-owned or server-hydrated class before its declarations
|
|
6234
|
+
* are rendered. A miss does not reserve a class or mutate the rule cache.
|
|
6235
|
+
* @internal
|
|
6236
|
+
*/
|
|
6237
|
+
prepareClassName(cacheKey, options) {
|
|
6238
|
+
const root = options?.root || document;
|
|
6239
|
+
const registry = this.sheetManager.getRegistry(root);
|
|
6240
|
+
const mapped = registry.cacheKeyToClassName.get(cacheKey);
|
|
6241
|
+
if (mapped) {
|
|
6242
|
+
const info = registry.rules.get(mapped);
|
|
6243
|
+
if (info && !(info.ruleIndex === -1 && info.sheetIndex === -1)) return {
|
|
6244
|
+
className: mapped,
|
|
6245
|
+
isExisting: true
|
|
6246
|
+
};
|
|
6247
|
+
}
|
|
6248
|
+
const className = this.generateClassName(cacheKey);
|
|
6249
|
+
return {
|
|
6250
|
+
className,
|
|
6251
|
+
isExisting: this.tryHydratedHit(registry, cacheKey, className)
|
|
6252
|
+
};
|
|
6253
|
+
}
|
|
6254
|
+
/**
|
|
6725
6255
|
* Allocate a className for a cacheKey without injecting styles yet.
|
|
6726
6256
|
* This allows separating className allocation (render phase) from style injection (insertion phase).
|
|
6727
6257
|
*/
|
|
@@ -6763,40 +6293,47 @@ var StyleInjector = class {
|
|
|
6763
6293
|
inject(rules, options) {
|
|
6764
6294
|
const root = options?.root || document;
|
|
6765
6295
|
const registry = this.sheetManager.getRegistry(root);
|
|
6296
|
+
const pin = options?.pin ?? true;
|
|
6766
6297
|
if (rules.length === 0) return {
|
|
6767
6298
|
className: "",
|
|
6768
6299
|
dispose: () => {}
|
|
6769
6300
|
};
|
|
6770
6301
|
const cacheKey = options?.cacheKey;
|
|
6302
|
+
const preparedClassName = options?.preparedClassName;
|
|
6771
6303
|
let className;
|
|
6772
|
-
if (
|
|
6304
|
+
if (preparedClassName) className = preparedClassName;
|
|
6305
|
+
else if (cacheKey && registry.cacheKeyToClassName.has(cacheKey)) {
|
|
6773
6306
|
className = registry.cacheKeyToClassName.get(cacheKey);
|
|
6774
6307
|
const existingRuleInfo = registry.rules.get(className);
|
|
6775
6308
|
if (existingRuleInfo.ruleIndex === -3) {
|
|
6776
|
-
registry.
|
|
6309
|
+
registry.unusedSince.delete(className);
|
|
6310
|
+
if (pin) registry.pinCounts.set(className, (registry.pinCounts.get(className) || 0) + 1);
|
|
6777
6311
|
if (registry.metrics) registry.metrics.hits++;
|
|
6778
6312
|
return {
|
|
6779
6313
|
className,
|
|
6780
|
-
dispose: () => this.
|
|
6314
|
+
dispose: pin ? () => this.unpin(className, registry) : noop
|
|
6781
6315
|
};
|
|
6782
6316
|
}
|
|
6783
6317
|
if (!(existingRuleInfo.ruleIndex === -1 && existingRuleInfo.sheetIndex === -1)) {
|
|
6784
|
-
|
|
6785
|
-
|
|
6318
|
+
registry.unusedSince.delete(className);
|
|
6319
|
+
if (pin) {
|
|
6320
|
+
const pins = registry.pinCounts.get(className) || 0;
|
|
6321
|
+
registry.pinCounts.set(className, pins + 1);
|
|
6322
|
+
}
|
|
6786
6323
|
if (registry.metrics) registry.metrics.hits++;
|
|
6787
6324
|
return {
|
|
6788
6325
|
className,
|
|
6789
|
-
dispose: () => this.
|
|
6326
|
+
dispose: pin ? () => this.unpin(className, registry) : noop
|
|
6790
6327
|
};
|
|
6791
6328
|
}
|
|
6792
6329
|
} else if (cacheKey) {
|
|
6793
6330
|
className = this.generateClassName(cacheKey);
|
|
6794
6331
|
if (this.tryHydratedHit(registry, cacheKey, className)) {
|
|
6795
|
-
registry.
|
|
6332
|
+
if (pin) registry.pinCounts.set(className, (registry.pinCounts.get(className) || 0) + 1);
|
|
6796
6333
|
if (registry.metrics) registry.metrics.hits++;
|
|
6797
6334
|
return {
|
|
6798
6335
|
className,
|
|
6799
|
-
dispose: () => this.
|
|
6336
|
+
dispose: pin ? () => this.unpin(className, registry) : noop
|
|
6800
6337
|
};
|
|
6801
6338
|
}
|
|
6802
6339
|
} else {
|
|
@@ -6857,7 +6394,8 @@ var StyleInjector = class {
|
|
|
6857
6394
|
sheetIndex: -3
|
|
6858
6395
|
});
|
|
6859
6396
|
if (cacheKey) registry.cacheKeyToClassName.set(cacheKey, className);
|
|
6860
|
-
registry.
|
|
6397
|
+
if (pin) registry.pinCounts.set(className, 1);
|
|
6398
|
+
registry.unusedSince.set(className, Date.now());
|
|
6861
6399
|
const queued = enqueueStyleWrite(() => {
|
|
6862
6400
|
if (applySheetWrite()) return;
|
|
6863
6401
|
registry.rules.set(className, {
|
|
@@ -6868,26 +6406,27 @@ var StyleInjector = class {
|
|
|
6868
6406
|
});
|
|
6869
6407
|
return {
|
|
6870
6408
|
className,
|
|
6871
|
-
dispose: () => {
|
|
6872
|
-
if (!queued.done && registry.
|
|
6409
|
+
dispose: pin ? () => {
|
|
6410
|
+
if (!queued.done && registry.pinCounts.get(className) === 1 && registry.rules.get(className)?.ruleIndex === -3) {
|
|
6873
6411
|
queued.cancelled = true;
|
|
6874
6412
|
registry.rules.delete(className);
|
|
6875
6413
|
if (cacheKey) registry.cacheKeyToClassName.delete(cacheKey);
|
|
6876
|
-
registry.
|
|
6414
|
+
registry.pinCounts.set(className, 0);
|
|
6877
6415
|
return;
|
|
6878
6416
|
}
|
|
6879
|
-
this.
|
|
6880
|
-
}
|
|
6417
|
+
this.unpin(className, registry);
|
|
6418
|
+
} : noop
|
|
6881
6419
|
};
|
|
6882
6420
|
}
|
|
6883
6421
|
if (!applySheetWrite()) return {
|
|
6884
6422
|
className,
|
|
6885
6423
|
dispose: () => {}
|
|
6886
6424
|
};
|
|
6887
|
-
registry.
|
|
6425
|
+
if (pin) registry.pinCounts.set(className, 1);
|
|
6426
|
+
registry.unusedSince.set(className, Date.now());
|
|
6888
6427
|
return {
|
|
6889
6428
|
className,
|
|
6890
|
-
dispose: () => this.
|
|
6429
|
+
dispose: pin ? () => this.unpin(className, registry) : noop
|
|
6891
6430
|
};
|
|
6892
6431
|
}
|
|
6893
6432
|
/**
|
|
@@ -6967,41 +6506,100 @@ var StyleInjector = class {
|
|
|
6967
6506
|
return this.sheetManager.getRawCSSText(root);
|
|
6968
6507
|
}
|
|
6969
6508
|
/**
|
|
6970
|
-
*
|
|
6971
|
-
*
|
|
6972
|
-
*
|
|
6973
|
-
*
|
|
6509
|
+
* Take a reference on local `@keyframes`, under the deterministic names the
|
|
6510
|
+
* caller resolved.
|
|
6511
|
+
*
|
|
6512
|
+
* One reference per distinct set of steps, shared by every class that ends up
|
|
6513
|
+
* animating it, so a repeat render takes nothing further. Ownership is
|
|
6514
|
+
* assigned by `ownKeyframes()` once the rules exist to be inspected.
|
|
6515
|
+
*/
|
|
6516
|
+
holdKeyframes(steps, names, options) {
|
|
6517
|
+
const root = options?.root || document;
|
|
6518
|
+
const registry = this.sheetManager.getRegistry(root);
|
|
6519
|
+
const keys = /* @__PURE__ */ new Map();
|
|
6520
|
+
for (const [authored, definition] of Object.entries(steps)) {
|
|
6521
|
+
const resolved = names.get(authored) ?? authored;
|
|
6522
|
+
let entry = registry.localKeyframes.get(resolved);
|
|
6523
|
+
if (!entry) {
|
|
6524
|
+
const injected = this.keyframes(definition, {
|
|
6525
|
+
name: resolved,
|
|
6526
|
+
root,
|
|
6527
|
+
distinctByName: true
|
|
6528
|
+
});
|
|
6529
|
+
entry = {
|
|
6530
|
+
name: injected.toString(),
|
|
6531
|
+
dispose: injected.dispose,
|
|
6532
|
+
owners: /* @__PURE__ */ new Set()
|
|
6533
|
+
};
|
|
6534
|
+
registry.localKeyframes.set(resolved, entry);
|
|
6535
|
+
}
|
|
6536
|
+
keys.set(authored, resolved);
|
|
6537
|
+
}
|
|
6538
|
+
return keys;
|
|
6539
|
+
}
|
|
6540
|
+
/**
|
|
6541
|
+
* Record that `className` animates these keyframes, so the reference is
|
|
6542
|
+
* released when the last such class is collected.
|
|
6543
|
+
*
|
|
6544
|
+
* Only classes whose rules actually reference the animation should be here:
|
|
6545
|
+
* a class that merely rendered alongside one would otherwise keep the
|
|
6546
|
+
* keyframes alive for as long as it lives.
|
|
6547
|
+
*/
|
|
6548
|
+
ownKeyframes(key, className, options) {
|
|
6549
|
+
this.sheetManager.getRegistry(options?.root || document).localKeyframes.get(key)?.owners.add(className);
|
|
6550
|
+
}
|
|
6551
|
+
/** Record a chunk lookup served by an immutable external stylesheet. */
|
|
6552
|
+
recordPrecompiledHit(className, options) {
|
|
6553
|
+
if (!this.config.devMode) return;
|
|
6554
|
+
const registry = this.sheetManager.getRegistry(options?.root || document);
|
|
6555
|
+
if (registry.metrics) {
|
|
6556
|
+
registry.metrics.hits++;
|
|
6557
|
+
registry.metrics.precompiledHits++;
|
|
6558
|
+
const used = registry.precompiledUsedClasses ??= /* @__PURE__ */ new Set();
|
|
6559
|
+
if (!used.has(className)) {
|
|
6560
|
+
used.add(className);
|
|
6561
|
+
registry.metrics.precompiledUniqueHits++;
|
|
6562
|
+
}
|
|
6563
|
+
}
|
|
6564
|
+
}
|
|
6565
|
+
/**
|
|
6566
|
+
* Pin an already-injected cacheKey and return the handle that releases it.
|
|
6567
|
+
* For callers that skipped the pipeline on a cache hit but still need the
|
|
6568
|
+
* class held. Returns null if the cacheKey is not found.
|
|
6974
6569
|
*/
|
|
6975
6570
|
trackRef(cacheKey, options) {
|
|
6976
6571
|
const root = options?.root || document;
|
|
6977
6572
|
const registry = this.sheetManager.getRegistry(root);
|
|
6978
6573
|
if (!registry.cacheKeyToClassName.has(cacheKey)) return null;
|
|
6979
6574
|
const className = registry.cacheKeyToClassName.get(cacheKey);
|
|
6980
|
-
const
|
|
6981
|
-
registry.
|
|
6575
|
+
const pins = registry.pinCounts.get(className) || 0;
|
|
6576
|
+
registry.pinCounts.set(className, pins + 1);
|
|
6982
6577
|
if (registry.metrics) registry.metrics.hits++;
|
|
6983
6578
|
return {
|
|
6984
6579
|
className,
|
|
6985
|
-
dispose: () => this.
|
|
6580
|
+
dispose: () => this.unpin(className, registry)
|
|
6986
6581
|
};
|
|
6987
6582
|
}
|
|
6988
6583
|
/**
|
|
6989
|
-
*
|
|
6584
|
+
* Release one pin on a className. At zero pins the class is not deleted — it
|
|
6585
|
+
* stays cached and collectible, and `gc()` decides when it actually goes.
|
|
6990
6586
|
*/
|
|
6991
|
-
|
|
6992
|
-
const
|
|
6993
|
-
if (
|
|
6994
|
-
const
|
|
6995
|
-
registry.
|
|
6996
|
-
if (
|
|
6587
|
+
unpin(className, registry) {
|
|
6588
|
+
const pins = registry.pinCounts.get(className);
|
|
6589
|
+
if (pins == null || pins <= 0) return;
|
|
6590
|
+
const remaining = pins - 1;
|
|
6591
|
+
registry.pinCounts.set(className, remaining);
|
|
6592
|
+
if (remaining === 0 && registry.metrics) registry.metrics.totalUnused++;
|
|
6997
6593
|
}
|
|
6998
6594
|
/**
|
|
6999
|
-
*
|
|
6595
|
+
* Remove every style that is neither in the DOM nor referenced by an
|
|
6596
|
+
* outstanding `inject()` handle, ignoring the GC capacity threshold.
|
|
7000
6597
|
*/
|
|
7001
6598
|
cleanup(root) {
|
|
7002
|
-
|
|
7003
|
-
|
|
7004
|
-
|
|
6599
|
+
this.gc({
|
|
6600
|
+
root,
|
|
6601
|
+
force: true
|
|
6602
|
+
});
|
|
7005
6603
|
}
|
|
7006
6604
|
/**
|
|
7007
6605
|
* Get CSS text from all sheets (for SSR)
|
|
@@ -7044,7 +6642,9 @@ var StyleInjector = class {
|
|
|
7044
6642
|
flushStyles();
|
|
7045
6643
|
const root = options?.root || document;
|
|
7046
6644
|
const registry = this.sheetManager.getRegistry(root);
|
|
7047
|
-
|
|
6645
|
+
const metrics = this.sheetManager.getMetrics(registry);
|
|
6646
|
+
if (metrics && typeof document !== "undefined") metrics.unusedHits = this.collectUnused(registry, root).length;
|
|
6647
|
+
return metrics;
|
|
7048
6648
|
}
|
|
7049
6649
|
/**
|
|
7050
6650
|
* Reset cache performance metrics
|
|
@@ -7085,15 +6685,6 @@ var StyleInjector = class {
|
|
|
7085
6685
|
const cssName = effectiveResult.cssName;
|
|
7086
6686
|
const definition = effectiveResult.definition;
|
|
7087
6687
|
this.insertPropertyRule(registry, root, cssName, definition, name);
|
|
7088
|
-
if (effectiveResult.isColor) {
|
|
7089
|
-
const companionCssName = `${cssName}-${getColorSpaceSuffix()}`;
|
|
7090
|
-
const companionDefinition = {
|
|
7091
|
-
syntax: getComponentPropertySyntax(),
|
|
7092
|
-
inherits: definition.inherits,
|
|
7093
|
-
initialValue: colorInitialValueToComponents(definition.initialValue)
|
|
7094
|
-
};
|
|
7095
|
-
this.insertPropertyRule(registry, root, companionCssName, companionDefinition, `${name}:components`);
|
|
7096
|
-
}
|
|
7097
6688
|
}
|
|
7098
6689
|
/**
|
|
7099
6690
|
* Build and insert a single `@property` rule into the given registry.
|
|
@@ -7227,13 +6818,14 @@ var StyleInjector = class {
|
|
|
7227
6818
|
keyframes(steps, nameOrOptions) {
|
|
7228
6819
|
const isStringName = typeof nameOrOptions === "string";
|
|
7229
6820
|
const providedName = isStringName ? nameOrOptions : nameOrOptions?.name;
|
|
6821
|
+
const distinctByName = isStringName ? false : nameOrOptions?.distinctByName ?? false;
|
|
7230
6822
|
const root = isStringName ? document : nameOrOptions?.root || document;
|
|
7231
6823
|
const registry = this.sheetManager.getRegistry(root);
|
|
7232
6824
|
if (Object.keys(steps).length === 0) return {
|
|
7233
6825
|
toString: () => "",
|
|
7234
6826
|
dispose: () => {}
|
|
7235
6827
|
};
|
|
7236
|
-
const contentHash = JSON.stringify(steps);
|
|
6828
|
+
const contentHash = distinctByName && providedName ? `${providedName}\u0000${JSON.stringify(steps)}` : JSON.stringify(steps);
|
|
7237
6829
|
const existing = registry.keyframesCache.get(contentHash);
|
|
7238
6830
|
if (existing) {
|
|
7239
6831
|
existing.refCount++;
|
|
@@ -7250,7 +6842,7 @@ var StyleInjector = class {
|
|
|
7250
6842
|
actualName = providedName;
|
|
7251
6843
|
registry.keyframesNameToContent.set(providedName, contentHash);
|
|
7252
6844
|
}
|
|
7253
|
-
} else actualName = makeKeyframeName(this.namePrefix,
|
|
6845
|
+
} else actualName = makeKeyframeName(this.namePrefix, hashString(contentHash));
|
|
7254
6846
|
const applyWrite = () => {
|
|
7255
6847
|
const result = this.sheetManager.insertKeyframes(registry, steps, actualName, root);
|
|
7256
6848
|
if (!result) return false;
|
|
@@ -7325,108 +6917,132 @@ var StyleInjector = class {
|
|
|
7325
6917
|
}
|
|
7326
6918
|
}
|
|
7327
6919
|
/**
|
|
7328
|
-
*
|
|
7329
|
-
*
|
|
7330
|
-
*
|
|
7331
|
-
*
|
|
7332
|
-
*
|
|
6920
|
+
* Count a render, and schedule a collection pass every `touchInterval` of
|
|
6921
|
+
* them. Nothing else: what a class is worth keeping is decided by the sweep's
|
|
6922
|
+
* own DOM scan, so rendering does not track usage at all.
|
|
6923
|
+
*
|
|
6924
|
+
* @deprecated The class name is ignored — pass anything, or stop calling it.
|
|
6925
|
+
* Collection no longer records per-class usage, and scheduling does not need
|
|
6926
|
+
* to know which class was rendered. A class handed back by `inject()` is
|
|
6927
|
+
* marked wanted there, which is what reuse actually goes through.
|
|
7333
6928
|
*/
|
|
7334
|
-
touch(
|
|
6929
|
+
touch(_className, options) {
|
|
7335
6930
|
if (typeof document === "undefined") return;
|
|
7336
6931
|
if (!this.config.gc) return;
|
|
7337
|
-
const
|
|
7338
|
-
|
|
7339
|
-
const now = Date.now();
|
|
7340
|
-
if (registry.touchTick !== now) {
|
|
7341
|
-
registry.touchTick = now;
|
|
7342
|
-
registry.touchedTick.clear();
|
|
7343
|
-
} else if (registry.touchedTick.has(className)) return;
|
|
7344
|
-
registry.touchedTick.add(className);
|
|
7345
|
-
const parts = className.indexOf(" ") === -1 ? [className] : className.split(" ");
|
|
7346
|
-
for (const cls of parts) {
|
|
7347
|
-
if (!this.classRegex.test(cls)) continue;
|
|
7348
|
-
if (!registry.rules.has(cls)) continue;
|
|
7349
|
-
const entry = registry.usageMap.get(cls);
|
|
7350
|
-
if (entry) entry.lastTouchedAt = now;
|
|
7351
|
-
else registry.usageMap.set(cls, { lastTouchedAt: now });
|
|
7352
|
-
registry.touchCount++;
|
|
7353
|
-
}
|
|
7354
|
-
const touchInterval = this.config.gc.touchInterval ?? 1e3;
|
|
7355
|
-
if (registry.touchCount >= touchInterval) {
|
|
6932
|
+
const registry = this.sheetManager.getRegistry(options?.root || document);
|
|
6933
|
+
if (++registry.touchCount >= (this.config.gc.touchInterval ?? 1e3)) {
|
|
7356
6934
|
registry.touchCount = 0;
|
|
7357
6935
|
this.scheduleGC();
|
|
7358
6936
|
}
|
|
7359
6937
|
}
|
|
7360
6938
|
/**
|
|
7361
|
-
* Schedule a GC
|
|
7362
|
-
*
|
|
6939
|
+
* Schedule a GC in idle time. Runs GC on all active roots, and avoids
|
|
6940
|
+
* double-scheduling.
|
|
6941
|
+
*
|
|
6942
|
+
* Idle only. Without `requestIdleCallback` nothing is collected
|
|
6943
|
+
* automatically: running the sweep inline here would put it inside the render
|
|
6944
|
+
* that touched the class, and collection is never urgent enough for that.
|
|
7363
6945
|
*/
|
|
7364
6946
|
scheduleGC() {
|
|
7365
|
-
if (this.
|
|
6947
|
+
if (this.cancelPendingGC) return;
|
|
7366
6948
|
const runGC = () => {
|
|
7367
|
-
this.
|
|
6949
|
+
this.cancelPendingGC = null;
|
|
7368
6950
|
this.sheetManager.pruneDisconnectedRoots();
|
|
7369
6951
|
for (const root of this.sheetManager.getActiveRoots()) this.gc({ root });
|
|
7370
6952
|
};
|
|
7371
|
-
if (typeof requestIdleCallback !== "undefined")
|
|
7372
|
-
|
|
6953
|
+
if (typeof requestIdleCallback !== "undefined") {
|
|
6954
|
+
const handle = requestIdleCallback(() => runGC());
|
|
6955
|
+
this.cancelPendingGC = () => cancelIdleCallback(handle);
|
|
6956
|
+
}
|
|
6957
|
+
}
|
|
6958
|
+
/**
|
|
6959
|
+
* The one definition of "unused": this injector owns the class's rules, no
|
|
6960
|
+
* element in `root` carries it, and nobody pinned it.
|
|
6961
|
+
*
|
|
6962
|
+
* `gc()` evicts from this set, `getMetrics()` counts it, and `tastyDebug`
|
|
6963
|
+
* reports it — all through here, so the three can never disagree about what
|
|
6964
|
+
* "unused" means. Entries carry their last `touch()` so callers can drop the
|
|
6965
|
+
* oldest first; a class that was never touched sorts as oldest.
|
|
6966
|
+
*/
|
|
6967
|
+
/**
|
|
6968
|
+
* Everything the injector holds falls into one of five bands, and only the
|
|
6969
|
+
* last of them is ever deleted:
|
|
6970
|
+
*
|
|
6971
|
+
* 1. rendered — some element carries the class right now
|
|
6972
|
+
* 2. not ours — queued for a batched write, pre-allocated, or server-rendered
|
|
6973
|
+
* 3. hot — nothing carries it, but that was noticed less than `grace` ago
|
|
6974
|
+
* 4. cached — cold, but within `capacity` when ordered by when it went cold
|
|
6975
|
+
* 5. the rest
|
|
6976
|
+
*
|
|
6977
|
+
* This returns bands 4 and 5 together, most recently cold first; `gc()` draws
|
|
6978
|
+
* the capacity line through them. Band 3 is what makes collection safe
|
|
6979
|
+
* without a commit signal: a render can resolve a class and commit it a
|
|
6980
|
+
* little later, and during that gap nothing on the page carries it.
|
|
6981
|
+
*/
|
|
6982
|
+
collectUnused(registry, root) {
|
|
6983
|
+
const now = Date.now();
|
|
6984
|
+
const grace = this.config.gc?.grace ?? DEFAULT_GC_GRACE;
|
|
6985
|
+
const liveClasses = /* @__PURE__ */ new Set();
|
|
6986
|
+
for (const el of root.querySelectorAll("[class]")) for (const token of el.classList) if (this.classRegex.test(token)) liveClasses.add(token);
|
|
6987
|
+
const unused = [];
|
|
6988
|
+
for (const [className, ruleInfo] of registry.rules) {
|
|
6989
|
+
if (ruleInfo.sheetIndex < 0) continue;
|
|
6990
|
+
if (liveClasses.has(className)) {
|
|
6991
|
+
registry.unusedSince.delete(className);
|
|
6992
|
+
continue;
|
|
6993
|
+
}
|
|
6994
|
+
if ((registry.pinCounts.get(className) ?? 0) > 0) continue;
|
|
6995
|
+
let since = registry.unusedSince.get(className);
|
|
6996
|
+
if (since === void 0) {
|
|
6997
|
+
since = now;
|
|
6998
|
+
registry.unusedSince.set(className, now);
|
|
6999
|
+
}
|
|
7000
|
+
if (now - since < grace) continue;
|
|
7001
|
+
unused.push(className);
|
|
7002
|
+
}
|
|
7003
|
+
unused.sort((a, b) => (registry.unusedSince.get(b) ?? 0) - (registry.unusedSince.get(a) ?? 0));
|
|
7004
|
+
return unused;
|
|
7005
|
+
}
|
|
7006
|
+
/**
|
|
7007
|
+
* Class names this injector holds CSS for that nothing renders and nobody
|
|
7008
|
+
* pinned — exactly what `gc({ force: true })` would delete. Unordered.
|
|
7009
|
+
*/
|
|
7010
|
+
getUnusedClasses(options) {
|
|
7011
|
+
flushStyles();
|
|
7012
|
+
if (typeof document === "undefined") return [];
|
|
7013
|
+
const root = options?.root || document;
|
|
7014
|
+
const registry = this.sheetManager.getRegistry(root);
|
|
7015
|
+
return this.collectUnused(registry, root);
|
|
7373
7016
|
}
|
|
7374
7017
|
/**
|
|
7375
7018
|
* Synchronous garbage collection.
|
|
7376
7019
|
*
|
|
7377
|
-
* 1. Quick upper-bound check: skip if
|
|
7378
|
-
* 2. Scans the DOM for live tasty classNames
|
|
7379
|
-
*
|
|
7380
|
-
*
|
|
7020
|
+
* 1. Quick upper-bound check: skip if the registry is smaller than capacity.
|
|
7021
|
+
* 2. Scans the DOM for live tasty classNames — the DOM, not a ref count, is
|
|
7022
|
+
* what says a class rendered by a component is still in use.
|
|
7023
|
+
* 3. With `force: true`: deletes every unused class.
|
|
7024
|
+
* Without `force`: keeps the `capacity` most recently touched and deletes
|
|
7025
|
+
* the rest, oldest first.
|
|
7381
7026
|
*
|
|
7382
7027
|
* @returns Number of styles evicted.
|
|
7383
7028
|
*/
|
|
7384
7029
|
gc(options) {
|
|
7385
7030
|
flushStyles();
|
|
7386
7031
|
if (typeof document === "undefined") return 0;
|
|
7387
|
-
|
|
7388
|
-
|
|
7389
|
-
this.pendingGCHandle = null;
|
|
7390
|
-
}
|
|
7032
|
+
this.cancelPendingGC?.();
|
|
7033
|
+
this.cancelPendingGC = null;
|
|
7391
7034
|
const root = options?.root || document;
|
|
7392
|
-
const force = options?.force
|
|
7035
|
+
const force = options?.force;
|
|
7393
7036
|
const registry = this.sheetManager.getRegistry(root);
|
|
7394
7037
|
const capacity = this.config.gc?.capacity ?? 1e3;
|
|
7395
|
-
if (!force)
|
|
7396
|
-
|
|
7397
|
-
|
|
7398
|
-
|
|
7399
|
-
|
|
7400
|
-
|
|
7401
|
-
|
|
7402
|
-
|
|
7403
|
-
if (force) for (const [className] of registry.usageMap) {
|
|
7404
|
-
if (liveClasses.has(className)) continue;
|
|
7405
|
-
if ((registry.refCounts.get(className) ?? 0) > 0) continue;
|
|
7406
|
-
registry.usageMap.delete(className);
|
|
7407
|
-
swept++;
|
|
7408
|
-
}
|
|
7409
|
-
else {
|
|
7410
|
-
const unused = [];
|
|
7411
|
-
for (const [className, usage] of registry.usageMap) {
|
|
7412
|
-
if (liveClasses.has(className)) continue;
|
|
7413
|
-
if ((registry.refCounts.get(className) ?? 0) > 0) continue;
|
|
7414
|
-
unused.push({
|
|
7415
|
-
className,
|
|
7416
|
-
lastTouchedAt: usage.lastTouchedAt
|
|
7417
|
-
});
|
|
7418
|
-
}
|
|
7419
|
-
if (unused.length > capacity) {
|
|
7420
|
-
unused.sort((a, b) => a.lastTouchedAt - b.lastTouchedAt);
|
|
7421
|
-
const toEvict = unused.length - capacity;
|
|
7422
|
-
for (let i = 0; i < toEvict; i++) {
|
|
7423
|
-
registry.usageMap.delete(unused[i].className);
|
|
7424
|
-
swept++;
|
|
7425
|
-
}
|
|
7426
|
-
}
|
|
7427
|
-
}
|
|
7428
|
-
if (swept > 0) this.sheetManager.forceCleanup(registry);
|
|
7429
|
-
return swept;
|
|
7038
|
+
if (!force && registry.rules.size <= capacity) return 0;
|
|
7039
|
+
const unused = this.collectUnused(registry, root);
|
|
7040
|
+
let doomed;
|
|
7041
|
+
if (force) doomed = unused;
|
|
7042
|
+
else if (unused.length > capacity) doomed = unused.slice(capacity);
|
|
7043
|
+
else return 0;
|
|
7044
|
+
if (doomed.length === 0) return 0;
|
|
7045
|
+
return this.sheetManager.deleteClasses(registry, doomed);
|
|
7430
7046
|
}
|
|
7431
7047
|
/**
|
|
7432
7048
|
* Destroy all resources for a root
|
|
@@ -7435,13 +7051,142 @@ var StyleInjector = class {
|
|
|
7435
7051
|
flushStyles();
|
|
7436
7052
|
const targetRoot = root || document;
|
|
7437
7053
|
this.sheetManager.cleanup(targetRoot);
|
|
7438
|
-
if (this.
|
|
7439
|
-
|
|
7440
|
-
this.
|
|
7054
|
+
if (this.cancelPendingGC && !this.sheetManager.hasActiveRoots()) {
|
|
7055
|
+
this.cancelPendingGC();
|
|
7056
|
+
this.cancelPendingGC = null;
|
|
7441
7057
|
}
|
|
7442
7058
|
}
|
|
7443
7059
|
};
|
|
7444
7060
|
//#endregion
|
|
7061
|
+
//#region src/precompile/runtime.ts
|
|
7062
|
+
const STORE_KEY = Symbol.for("@tenphi/tasty/precompiled/v1");
|
|
7063
|
+
const globalStore$1 = globalThis;
|
|
7064
|
+
const store = globalStore$1[STORE_KEY] ??= {
|
|
7065
|
+
manifests: null,
|
|
7066
|
+
chunks: null,
|
|
7067
|
+
dependencies: null,
|
|
7068
|
+
buildCount: 0,
|
|
7069
|
+
active: false,
|
|
7070
|
+
validatedRevision: -1,
|
|
7071
|
+
validate: null,
|
|
7072
|
+
revision: 0,
|
|
7073
|
+
warnings: null
|
|
7074
|
+
};
|
|
7075
|
+
const EMPTY_DEPENDENCIES = Object.freeze({
|
|
7076
|
+
properties: Object.freeze([]),
|
|
7077
|
+
keyframes: Object.freeze([]),
|
|
7078
|
+
fontFaces: Object.freeze([]),
|
|
7079
|
+
counterStyles: Object.freeze([]),
|
|
7080
|
+
functions: Object.freeze([]),
|
|
7081
|
+
rscKeys: Object.freeze([])
|
|
7082
|
+
});
|
|
7083
|
+
function getPrecompileStore() {
|
|
7084
|
+
return store;
|
|
7085
|
+
}
|
|
7086
|
+
function warnPrecompileOnce(key, message) {
|
|
7087
|
+
if (!isDevEnv()) return;
|
|
7088
|
+
const warnings = store.warnings ??= /* @__PURE__ */ new Set();
|
|
7089
|
+
if (warnings.has(key)) return;
|
|
7090
|
+
warnings.add(key);
|
|
7091
|
+
console.warn(message);
|
|
7092
|
+
}
|
|
7093
|
+
/** Shared single-read gate for the unregistered render hot path. */
|
|
7094
|
+
const precompileRuntimeState = store;
|
|
7095
|
+
/** @internal Keep catalog recording on the isolated compiler path. */
|
|
7096
|
+
function beginPrecompileBuild() {
|
|
7097
|
+
store.buildCount = (store.buildCount ?? 0) + 1;
|
|
7098
|
+
store.active = true;
|
|
7099
|
+
}
|
|
7100
|
+
/** @internal Balance beginPrecompileBuild(), including failed catalog cases. */
|
|
7101
|
+
function endPrecompileBuild() {
|
|
7102
|
+
store.buildCount--;
|
|
7103
|
+
if (store.buildCount === 0 && store.chunks === null) store.active = false;
|
|
7104
|
+
}
|
|
7105
|
+
function findPrecompiledChunk(lookupKey, namePrefix) {
|
|
7106
|
+
store.validate?.();
|
|
7107
|
+
const chunk = store.chunks?.get(hashString(lookupKey));
|
|
7108
|
+
if (!chunk) return null;
|
|
7109
|
+
if (chunk.namePrefix !== namePrefix) {
|
|
7110
|
+
warnPrecompileOnce(`prefix:${chunk.manifestId}:${namePrefix}`, `[Tasty] Ignoring precompiled styles "${chunk.manifestId}": generated with namePrefix "${chunk.namePrefix}", but the runtime uses "${namePrefix}".`);
|
|
7111
|
+
return null;
|
|
7112
|
+
}
|
|
7113
|
+
return chunk;
|
|
7114
|
+
}
|
|
7115
|
+
/** The class name a chunk resolves to — recorded, or derived from its key. */
|
|
7116
|
+
function resolveChunkClassName(chunk, namePrefix) {
|
|
7117
|
+
return chunk.className ?? namePrefix + chunk.key;
|
|
7118
|
+
}
|
|
7119
|
+
function getPrecompiledRevision() {
|
|
7120
|
+
return store.revision;
|
|
7121
|
+
}
|
|
7122
|
+
function getRegisteredPrecompiledDependencies(namePrefix) {
|
|
7123
|
+
store.validate?.();
|
|
7124
|
+
return store.dependencies?.get(namePrefix) ?? EMPTY_DEPENDENCIES;
|
|
7125
|
+
}
|
|
7126
|
+
/** @internal Metadata used by tastyDebug without reading or parsing CSSOM. */
|
|
7127
|
+
function getRegisteredPrecompiledStats(namePrefix) {
|
|
7128
|
+
const classNames = /* @__PURE__ */ new Set();
|
|
7129
|
+
let manifestCount = 0;
|
|
7130
|
+
let cssSize = 0;
|
|
7131
|
+
let ruleCount = 0;
|
|
7132
|
+
for (const manifest of store.manifests?.values() ?? []) {
|
|
7133
|
+
if (manifest.namePrefix !== namePrefix) continue;
|
|
7134
|
+
manifestCount++;
|
|
7135
|
+
cssSize += manifest.stats.cssSize;
|
|
7136
|
+
ruleCount += manifest.stats.ruleCount;
|
|
7137
|
+
for (const chunk of manifest.chunks) classNames.add(resolveChunkClassName(chunk, manifest.namePrefix));
|
|
7138
|
+
}
|
|
7139
|
+
return {
|
|
7140
|
+
manifestCount,
|
|
7141
|
+
classNames: [...classNames],
|
|
7142
|
+
cssSize,
|
|
7143
|
+
ruleCount
|
|
7144
|
+
};
|
|
7145
|
+
}
|
|
7146
|
+
function applyRegisteredDependenciesToInjector(injector, namePrefix) {
|
|
7147
|
+
if (!store.manifests) return;
|
|
7148
|
+
injector.registerPrecompiledDependencies(getRegisteredPrecompiledDependencies(namePrefix), store.revision);
|
|
7149
|
+
}
|
|
7150
|
+
function applyRegisteredDependenciesToRSC(cache, namePrefix) {
|
|
7151
|
+
if (cache.precompiledRevision === store.revision) return;
|
|
7152
|
+
for (const key of cache.precompiledEmittedKeys) cache.emittedKeys.delete(key);
|
|
7153
|
+
for (const [key, name] of cache.precompiledGeneratedNames) if (cache.generatedNames.get(key) === name) cache.generatedNames.delete(key);
|
|
7154
|
+
cache.precompiledEmittedKeys.clear();
|
|
7155
|
+
cache.precompiledGeneratedNames.clear();
|
|
7156
|
+
if (!store.manifests) {
|
|
7157
|
+
cache.precompiledRevision = store.revision;
|
|
7158
|
+
return;
|
|
7159
|
+
}
|
|
7160
|
+
const dependencies = getRegisteredPrecompiledDependencies(namePrefix);
|
|
7161
|
+
for (const key of dependencies.rscKeys) {
|
|
7162
|
+
cache.emittedKeys.add(key);
|
|
7163
|
+
cache.precompiledEmittedKeys.add(key);
|
|
7164
|
+
}
|
|
7165
|
+
for (const item of dependencies.keyframes) for (const key of item.rscKeys) {
|
|
7166
|
+
cache.emittedKeys.add(key);
|
|
7167
|
+
cache.generatedNames.set(key, item.name);
|
|
7168
|
+
cache.precompiledEmittedKeys.add(key);
|
|
7169
|
+
cache.precompiledGeneratedNames.set(key, item.name);
|
|
7170
|
+
}
|
|
7171
|
+
for (const item of dependencies.counterStyles) for (const key of item.rscKeys) {
|
|
7172
|
+
cache.emittedKeys.add(key);
|
|
7173
|
+
cache.generatedNames.set(key, item.name);
|
|
7174
|
+
cache.precompiledEmittedKeys.add(key);
|
|
7175
|
+
cache.precompiledGeneratedNames.set(key, item.name);
|
|
7176
|
+
}
|
|
7177
|
+
cache.precompiledRevision = store.revision;
|
|
7178
|
+
}
|
|
7179
|
+
/** @internal Test-only reset; resetConfig() calls this to isolate suites. */
|
|
7180
|
+
function resetPrecompiledStyles() {
|
|
7181
|
+
store.manifests = null;
|
|
7182
|
+
store.chunks = null;
|
|
7183
|
+
store.dependencies = null;
|
|
7184
|
+
store.buildCount = 0;
|
|
7185
|
+
store.active = false;
|
|
7186
|
+
store.revision++;
|
|
7187
|
+
store.warnings?.clear();
|
|
7188
|
+
}
|
|
7189
|
+
//#endregion
|
|
7445
7190
|
//#region src/states/index.ts
|
|
7446
7191
|
/**
|
|
7447
7192
|
* Advanced State Mapping - Predefined States Management
|
|
@@ -12160,6 +11905,36 @@ function warnOnce(key, message) {
|
|
|
12160
11905
|
}
|
|
12161
11906
|
}
|
|
12162
11907
|
let stylesGenerated = false;
|
|
11908
|
+
/**
|
|
11909
|
+
* What the host passed to `configure()`, for the settings whose live registry
|
|
11910
|
+
* is not a faithful record of it. Accumulated across every `configure()` call.
|
|
11911
|
+
*
|
|
11912
|
+
* - Handlers and props middleware: `configure()` applies them into the handler
|
|
11913
|
+
* registry and then strips them from the stored config, and that registry is
|
|
11914
|
+
* populated lazily as styles are encountered — so neither is a stable record
|
|
11915
|
+
* of what the host asked for.
|
|
11916
|
+
* - Declarative `@function` definitions: with `polyfills.functions` enabled,
|
|
11917
|
+
* `configure()` compiles each into a parse-function closure and deliberately
|
|
11918
|
+
* leaves `getGlobalFunctions()` empty, so the definition body survives
|
|
11919
|
+
* nowhere a fingerprint can read it.
|
|
11920
|
+
*
|
|
11921
|
+
* A precompiled catalog needs exactly that record: replacing a built-in handler
|
|
11922
|
+
* or rewriting a function body changes what an already-compiled chunk should
|
|
11923
|
+
* contain without changing its lookup key.
|
|
11924
|
+
*/
|
|
11925
|
+
const configuredOverrides = {
|
|
11926
|
+
handlers: [],
|
|
11927
|
+
propHandlers: [],
|
|
11928
|
+
functions: []
|
|
11929
|
+
};
|
|
11930
|
+
/** @internal */
|
|
11931
|
+
function getConfiguredOverrides() {
|
|
11932
|
+
return {
|
|
11933
|
+
handlers: configuredOverrides.handlers,
|
|
11934
|
+
propHandlers: configuredOverrides.propHandlers,
|
|
11935
|
+
functions: configuredOverrides.functions
|
|
11936
|
+
};
|
|
11937
|
+
}
|
|
12163
11938
|
let currentConfig = null;
|
|
12164
11939
|
let globalKeyframes = null;
|
|
12165
11940
|
let globalFontFace = null;
|
|
@@ -12208,7 +11983,7 @@ const DEFAULT_PROPERTIES = {
|
|
|
12208
11983
|
},
|
|
12209
11984
|
"#current": {
|
|
12210
11985
|
inherits: true,
|
|
12211
|
-
initialValue: "
|
|
11986
|
+
initialValue: "currentcolor"
|
|
12212
11987
|
},
|
|
12213
11988
|
"#white": {
|
|
12214
11989
|
inherits: true,
|
|
@@ -12310,7 +12085,7 @@ function createDefaultConfig(isTest) {
|
|
|
12310
12085
|
function markStylesGenerated() {
|
|
12311
12086
|
if (stylesGenerated) return;
|
|
12312
12087
|
stylesGenerated = true;
|
|
12313
|
-
if (typeof document !== "undefined" && document.querySelector("
|
|
12088
|
+
if (typeof document !== "undefined" && document.querySelector("[data-tasty-ssr]")) {
|
|
12314
12089
|
warnOnce("ssr-globals-skip", "[Tasty] SSR styles detected — skipping client-side global CSS injection to avoid duplicates.");
|
|
12315
12090
|
return;
|
|
12316
12091
|
}
|
|
@@ -12758,10 +12533,7 @@ function configure(config = {}) {
|
|
|
12758
12533
|
const tokenKeys = new Set(Object.keys(mergedConfigTokens));
|
|
12759
12534
|
for (const key of Object.keys(mergedReplaceTokens)) if (tokenKeys.has(key)) warnOnce(`token-conflict-${key}`, `[Tasty] Token "${key}" is defined in both \`tokens\` and \`replaceTokens\`. \`replaceTokens\` performs parse-time substitution, so the \`tokens\` CSS custom property will be injected but never used by Tasty styles. Remove it from one of the two.`);
|
|
12760
12535
|
}
|
|
12761
|
-
if (config.colorSpace) {
|
|
12762
|
-
setColorSpace(config.colorSpace);
|
|
12763
|
-
getGlobalParser().clearCache();
|
|
12764
|
-
}
|
|
12536
|
+
if (config.colorSpace) warnOnce("colorSpace-deprecated", "[Tasty] configure({ colorSpace }) no longer has any effect and will be removed in the next major. Colors are emitted as authored, and opacity is applied with relative color syntax, which reads a color's channels in the browser. To address channels yourself, write `oklch(from var(--name-color) l c h)` against the token.");
|
|
12765
12537
|
if (Object.keys(mergedStates).length > 0) setGlobalPredefinedStates(mergedStates);
|
|
12766
12538
|
const parser = getGlobalParser();
|
|
12767
12539
|
if (config.parserCacheSize !== void 0) parser.updateOptions({ cacheSize: config.parserCacheSize });
|
|
@@ -12785,17 +12557,26 @@ function configure(config = {}) {
|
|
|
12785
12557
|
parser.setFunctions(finalFuncs);
|
|
12786
12558
|
Object.assign(currentFuncs, parseFuncs);
|
|
12787
12559
|
}
|
|
12788
|
-
if (Object.keys(functionDefs).length > 0)
|
|
12789
|
-
|
|
12560
|
+
if (Object.keys(functionDefs).length > 0) {
|
|
12561
|
+
for (const entry of Object.entries(functionDefs)) configuredOverrides.functions.push(entry);
|
|
12562
|
+
if (isFunctionsPolyfillEnabled()) for (const [name, definition] of Object.entries(functionDefs)) registerFunctionPolyfill(name, definition);
|
|
12563
|
+
else setGlobalFunction(functionDefs);
|
|
12564
|
+
}
|
|
12790
12565
|
if (Object.keys(mergedKeyframes).length > 0) setGlobalKeyframes(mergedKeyframes);
|
|
12791
12566
|
if (Object.keys(mergedProperties).length > 0) setGlobalProperties(mergedProperties);
|
|
12792
12567
|
if (Object.keys(mergedFontFaces).length > 0) setGlobalFontFace(mergedFontFaces);
|
|
12793
12568
|
if (Object.keys(mergedCounterStyles).length > 0) setGlobalCounterStyle(mergedCounterStyles);
|
|
12794
|
-
if (Object.keys(mergedHandlers).length > 0) for (const [name, definition] of Object.entries(mergedHandlers))
|
|
12795
|
-
|
|
12796
|
-
|
|
12797
|
-
|
|
12798
|
-
|
|
12569
|
+
if (Object.keys(mergedHandlers).length > 0) for (const [name, definition] of Object.entries(mergedHandlers)) {
|
|
12570
|
+
configuredOverrides.handlers.push([name, definition]);
|
|
12571
|
+
registerHandler(normalizeHandlerDefinition(name, definition), {
|
|
12572
|
+
key: name,
|
|
12573
|
+
source: handlerSources.get(name)
|
|
12574
|
+
});
|
|
12575
|
+
}
|
|
12576
|
+
if (Object.keys(mergedPropHandlers).length > 0) for (const [name, definition] of Object.entries(mergedPropHandlers)) {
|
|
12577
|
+
configuredOverrides.propHandlers.push([name, definition]);
|
|
12578
|
+
registerPropHandler(name, definition, { source: propHandlerSources.get(name) });
|
|
12579
|
+
}
|
|
12799
12580
|
if (mergedBaseStyleProps.length > 0) registerBaseStyleProps(mergedBaseStyleProps);
|
|
12800
12581
|
if (Object.keys(mergedReplaceTokens).length > 0) {
|
|
12801
12582
|
const processedTokens = {};
|
|
@@ -12872,15 +12653,18 @@ function resetConfig() {
|
|
|
12872
12653
|
resetHandlers();
|
|
12873
12654
|
resetStyleChunks();
|
|
12874
12655
|
resetPropHandlers();
|
|
12656
|
+
configuredOverrides.handlers.length = 0;
|
|
12657
|
+
configuredOverrides.propHandlers.length = 0;
|
|
12658
|
+
configuredOverrides.functions.length = 0;
|
|
12875
12659
|
resetBaseStyleProps();
|
|
12876
|
-
resetColorSpace();
|
|
12877
12660
|
clearPipelineCache();
|
|
12661
|
+
resetPrecompiledStyles();
|
|
12878
12662
|
emittedWarnings.clear();
|
|
12879
12663
|
resetStyleWarnings();
|
|
12880
12664
|
const storage = typeof window !== "undefined" ? window : globalThis;
|
|
12881
12665
|
delete storage[GLOBAL_INJECTOR_KEY];
|
|
12882
12666
|
}
|
|
12883
12667
|
//#endregion
|
|
12884
|
-
export {
|
|
12668
|
+
export { getRegisteredPrecompiledDependencies as $, filterMods as $t, DIMENSION_STYLES as A, hashString as At, camelToKebab as B, DISPLAY_CHUNK_STYLES as Bt, baseStylePropsRegistry as C, DEFAULT_NAME_PREFIX as Ct, BLOCK_STYLES as D, makeKeyframeName as Dt, BLOCK_OUTER_STYLES as E, makeCounterStyleName as Et, TEXT_STYLES as F, parsePropertyToken as Ft, setGlobalPredefinedStates as G, extractLocalFunctions as Gt, extractLocalPredefinedStates as H, LAYOUT_CHUNK_STYLES as Ht, hasPipelineCacheEntry as I, propHandlerRegistry as It, beginPrecompileBuild as J, parseFunctionName as Jt, applyRegisteredDependenciesToInjector as K, formatFunctionRule as Kt, isSelector as L, APPEARANCE_CHUNK_STYLES as Lt, INNER_STYLES as M, getEffectiveDefinition as Mt, OUTER_STYLES as N, hasLocalProperties as Nt, COLOR_STYLES as O, tastyClassRegex as Ot, POSITION_STYLES as P, normalizePropertyDefinition as Pt, getPrecompiledRevision as Q, DIRECTIONS as Qt, renderStyles as R, CHUNK_NAMES as Rt, generateTypographyTokens as S, resetStyleBatch as St, BLOCK_INNER_STYLES as T, makeClassName as Tt, extractPredefinedStateRefs as U, POSITION_CHUNK_STYLES as Ut, createStateParserContext as V, FONT_CHUNK_STYLES as Vt, getGlobalPredefinedStates as W, STYLE_TO_CHUNK as Wt, findPrecompiledChunk as X, registerLocalFunctionPolyfills as Xt, endPrecompileBuild as Y, registerFunctionPolyfill as Yt, getPrecompileStore as Z, CUSTOM_UNITS as Zt, isConfigLocked as _, getRgbValuesFromRgbaString as _n, PropertyTypeResolver as _t, getGlobalConfigTokens as a, parseStyle as an, extractLocalCounterStyle as at, markStylesGenerated as b, strToRgb as bn, hasPendingStyleWrites as bt, getGlobalFunctions as c, okhstPlugin as cn, extractLocalFontFace as ct, getGlobalRecipes as d, createColorFunc as dn, hasLocalFontFace as dt, getGlobalParseFunctions as en, getRegisteredPrecompiledStats as et, getGlobalStyles as f, isDevEnv as fn, SheetManager as ft, hasStylesGenerated as g, getNamedColorHex as gn, createStyle as gt, hasGlobalRecipes as h, overrideColorAlpha as hn, styleHandlers as ht, getEffectiveProperties as i, parseColor as in, StyleInjector as it, FLOW_STYLES as j, extractLocalProperties as jt, CONTAINER_STYLES as k, validateNamePrefix as kt, getGlobalInjector as l, okhslFunction as ln, fontFaceContentHash as lt, hasGlobalKeyframes as m, Lru as mn, defineHandler as mt, getConfig as n, getGlobalPredefinedTokens as nn, resolveChunkClassName as nt, getGlobalCounterStyles as o, stringifyStyles as on, formatCounterStyleRule as ot, getNamePrefix as p, StyleParser as pn, STYLE_HANDLER_MAP as pt, applyRegisteredDependenciesToRSC as q, hasLocalFunctions as qt, getConfiguredOverrides as r, normalizeColorTokenValue as rn, warnPrecompileOnce as rt, getGlobalFontFaces as s, okhstFunction as sn, hasLocalCounterStyle as st, configure as t, getGlobalParser as tn, precompileRuntimeState as tt, getGlobalKeyframes as u, okhslPlugin as un, formatFontFaceRule as ut, isFunctionsPolyfillEnabled as v, hexToRgb as vn, closeBatchWindow as vt, BASE_STYLES as w, DEFAULT_ZERO_NAME_PREFIX as wt, resetConfig as x, normalizeDslName as xn, openBatchWindow as xt, isTestEnvironment as y, hslToRgbValues as yn, flushStyles as yt, parseStateKey as z, DIMENSION_CHUNK_STYLES as zt };
|
|
12885
12669
|
|
|
12886
|
-
//# sourceMappingURL=config-
|
|
12670
|
+
//# sourceMappingURL=config-pEfUVSK_.js.map
|