@tenphi/tasty 0.0.0-snapshot.4b32dee → 0.0.0-snapshot.4b75cd6

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.
Files changed (138) hide show
  1. package/README.md +418 -381
  2. package/dist/babel-types-Dc5zghyE.d.ts +18 -0
  3. package/dist/chunks/async-storage-f9j9JRtq.js +37 -0
  4. package/dist/chunks/async-storage-f9j9JRtq.js.map +1 -0
  5. package/dist/chunks/build-config--0qoqt_P.js +60 -0
  6. package/dist/chunks/build-config--0qoqt_P.js.map +1 -0
  7. package/dist/{collector-B3OsM252.js → chunks/collector-zp5BrLF0.js} +10 -127
  8. package/dist/chunks/collector-zp5BrLF0.js.map +1 -0
  9. package/dist/chunks/config-engine-BaLq8HrX.js +272 -0
  10. package/dist/chunks/config-engine-BaLq8HrX.js.map +1 -0
  11. package/dist/chunks/config-file-DlZXJMj8.js +25 -0
  12. package/dist/chunks/config-file-DlZXJMj8.js.map +1 -0
  13. package/dist/chunks/css-definitions-CfXZ3tU9.js +910 -0
  14. package/dist/chunks/css-definitions-CfXZ3tU9.js.map +1 -0
  15. package/dist/{css-resources-Cyl_axbI.js → chunks/css-resources-P7IBUUZs.js} +2 -9
  16. package/dist/chunks/css-resources-P7IBUUZs.js.map +1 -0
  17. package/dist/chunks/debug--OC-WA-Q.js +502 -0
  18. package/dist/chunks/debug--OC-WA-Q.js.map +1 -0
  19. package/dist/chunks/dsl-CsFl9LGn.js +1458 -0
  20. package/dist/chunks/dsl-CsFl9LGn.js.map +1 -0
  21. package/dist/chunks/hydration-TRcz5vnk.js +41 -0
  22. package/dist/chunks/hydration-TRcz5vnk.js.map +1 -0
  23. package/dist/chunks/react-runtime-DnZ6M1Iv.js +691 -0
  24. package/dist/chunks/react-runtime-DnZ6M1Iv.js.map +1 -0
  25. package/dist/chunks/runtime-engine-J9X_h-Pw.js +2435 -0
  26. package/dist/chunks/runtime-engine-J9X_h-Pw.js.map +1 -0
  27. package/dist/chunks/runtime-state-o_v3Bj7b.js +152 -0
  28. package/dist/chunks/runtime-state-o_v3Bj7b.js.map +1 -0
  29. package/dist/{merge-styles-DuoZEsm9.js → chunks/shared-utils-y-HjvPN4.js} +60 -55
  30. package/dist/chunks/shared-utils-y-HjvPN4.js.map +1 -0
  31. package/dist/chunks/style-engine-D6lC3O3G.js +5626 -0
  32. package/dist/chunks/style-engine-D6lC3O3G.js.map +1 -0
  33. package/dist/{css-writer-Bgowobbx.js → chunks/zero-engine-BnjoV04F.js} +65 -145
  34. package/dist/chunks/zero-engine-BnjoV04F.js.map +1 -0
  35. package/dist/{collector-BTVXj2hS.d.ts → collector-D2OT6I2G.d.ts} +6 -5
  36. package/dist/{config-LfIDmVHx.d.ts → config-C4ftFxgI.d.ts} +51 -47
  37. package/dist/core/index.d.ts +5 -5
  38. package/dist/core/index.js +9 -6
  39. package/dist/hydrate-CRyjjAyl.d.ts +22 -0
  40. package/dist/{index-Bm9ltvdH.d.ts → index-DxQNRj50.d.ts} +275 -244
  41. package/dist/index.d.ts +5 -5
  42. package/dist/index.js +11 -922
  43. package/dist/{merge-styles-BcLl1u_d.d.ts → merge-styles-D39qBtox.d.ts} +2 -3
  44. package/dist/ssr/astro-client.d.ts +1 -1
  45. package/dist/ssr/astro-client.js +1 -14
  46. package/dist/ssr/astro-client.js.map +1 -1
  47. package/dist/ssr/astro-middleware-extract-static.d.ts +1 -2
  48. package/dist/ssr/astro-middleware-extract-static.js +1 -1
  49. package/dist/ssr/astro-middleware-extract.d.ts +1 -2
  50. package/dist/ssr/astro-middleware-extract.js +1 -1
  51. package/dist/ssr/astro-middleware-static.d.ts +1 -2
  52. package/dist/ssr/astro-middleware-static.js +1 -12
  53. package/dist/ssr/astro-middleware-static.js.map +1 -1
  54. package/dist/ssr/astro-middleware.d.ts +1 -2
  55. package/dist/ssr/astro-middleware.js +1 -13
  56. package/dist/ssr/astro-middleware.js.map +1 -1
  57. package/dist/ssr/astro.d.ts +8 -16
  58. package/dist/ssr/astro.js +220 -1
  59. package/dist/ssr/astro.js.map +1 -0
  60. package/dist/ssr/client.d.ts +2 -0
  61. package/dist/ssr/client.js +2 -0
  62. package/dist/ssr/index.d.ts +5 -25
  63. package/dist/ssr/index.js +5 -5
  64. package/dist/ssr/index.js.map +1 -1
  65. package/dist/ssr/next-config.d.ts +3 -5
  66. package/dist/ssr/next-config.js +43 -35
  67. package/dist/ssr/next-config.js.map +1 -1
  68. package/dist/ssr/next.d.ts +3 -9
  69. package/dist/ssr/next.js +7 -38
  70. package/dist/ssr/next.js.map +1 -1
  71. package/dist/static/index.d.ts +8 -9
  72. package/dist/static/index.js +4 -22
  73. package/dist/static/index.js.map +1 -1
  74. package/dist/static/inject.d.ts +1 -2
  75. package/dist/{index-BmogEzTo.d.ts → types-CYQIhUg1.d.ts} +856 -862
  76. package/dist/zero/babel.d.ts +73 -2
  77. package/dist/zero/babel.js +81 -144
  78. package/dist/zero/babel.js.map +1 -1
  79. package/dist/zero/index.d.ts +63 -8
  80. package/dist/zero/index.js +25 -2
  81. package/dist/zero/index.js.map +1 -0
  82. package/dist/zero/next.d.ts +4 -5
  83. package/dist/zero/next.js +3 -38
  84. package/dist/zero/next.js.map +1 -1
  85. package/docs/README.md +4 -1
  86. package/docs/adoption.md +25 -17
  87. package/docs/ai-agents.md +69 -34
  88. package/docs/comparison.md +9 -8
  89. package/docs/configuration.md +204 -70
  90. package/docs/debug.md +5 -7
  91. package/docs/design-system.md +129 -15
  92. package/docs/dsl.md +327 -117
  93. package/docs/getting-started.md +81 -22
  94. package/docs/injector.md +41 -40
  95. package/docs/llms.txt +31 -0
  96. package/docs/methodology.md +48 -23
  97. package/docs/migration-v3.md +3 -3
  98. package/docs/pipeline.md +55 -28
  99. package/docs/plugins.md +22 -42
  100. package/docs/react-api.md +76 -11
  101. package/docs/runtime-benchmarks.md +182 -105
  102. package/docs/ssr.md +92 -66
  103. package/docs/styles.md +169 -33
  104. package/docs/tasty-static.md +176 -58
  105. package/harness/dev.harnesspm/rules/usage.md +12 -0
  106. package/harness/dev.harnesspm/scripts/render.mjs +329 -0
  107. package/harness/dev.harnesspm/scripts/styles.mjs +409 -0
  108. package/harness/plugin.json +20 -0
  109. package/package.json +109 -49
  110. package/tasty.config.ts +1 -0
  111. package/dist/astro-CeYENy2x.js +0 -301
  112. package/dist/astro-CeYENy2x.js.map +0 -1
  113. package/dist/async-storage-DKK-wTD4.js +0 -44
  114. package/dist/async-storage-DKK-wTD4.js.map +0 -1
  115. package/dist/babel-DWCsafYw.d.ts +0 -83
  116. package/dist/collector-B3OsM252.js.map +0 -1
  117. package/dist/config-B3gPdCqd.js +0 -12421
  118. package/dist/config-B3gPdCqd.js.map +0 -1
  119. package/dist/context-CA8YKeMn.js +0 -24
  120. package/dist/context-CA8YKeMn.js.map +0 -1
  121. package/dist/core-pCOhTNoz.js +0 -1723
  122. package/dist/core-pCOhTNoz.js.map +0 -1
  123. package/dist/css-resources-Cyl_axbI.js.map +0 -1
  124. package/dist/css-writer-Bgowobbx.js.map +0 -1
  125. package/dist/format-global-rules-DklyaXv-.js +0 -22
  126. package/dist/format-global-rules-DklyaXv-.js.map +0 -1
  127. package/dist/format-rules-XRw9u7d4.js +0 -104
  128. package/dist/format-rules-XRw9u7d4.js.map +0 -1
  129. package/dist/hydrate-CNOmZprz.js +0 -37
  130. package/dist/hydrate-CNOmZprz.js.map +0 -1
  131. package/dist/index.js.map +0 -1
  132. package/dist/keyframes-DE-OE76F.js +0 -535
  133. package/dist/keyframes-DE-OE76F.js.map +0 -1
  134. package/dist/merge-styles-DuoZEsm9.js.map +0 -1
  135. package/dist/resolve-recipes-H9NqOQuP.js +0 -144
  136. package/dist/resolve-recipes-H9NqOQuP.js.map +0 -1
  137. package/dist/ssr-collector-ref-COs_ioWl.js +0 -29
  138. package/dist/ssr-collector-ref-COs_ioWl.js.map +0 -1
@@ -0,0 +1,1458 @@
1
+ import { a as warnOnceDev, o as isDevEnv } from "./shared-utils-y-HjvPN4.js";
2
+ //#region src/parser/const.ts
3
+ const VALUE_KEYWORDS = /* @__PURE__ */ new Set([
4
+ "auto",
5
+ "max-content",
6
+ "min-content",
7
+ "fit-content",
8
+ "stretch",
9
+ "initial",
10
+ "inherit",
11
+ "revert",
12
+ "unset",
13
+ "revert-layer"
14
+ ]);
15
+ const CSS_WIDE_KEYWORDS = /* @__PURE__ */ new Set([
16
+ "initial",
17
+ "inherit",
18
+ "revert",
19
+ "unset",
20
+ "revert-layer"
21
+ ]);
22
+ const DERIVED_COLOR_FUNCS_LIST = [
23
+ "color-mix",
24
+ "color-contrast",
25
+ "contrast-color",
26
+ "light-dark"
27
+ ];
28
+ const DERIVED_COLOR_FUNCS = new Set(DERIVED_COLOR_FUNCS_LIST);
29
+ const COLOR_FUNCS = /* @__PURE__ */ new Set([
30
+ "rgb",
31
+ "rgba",
32
+ "hsl",
33
+ "hsla",
34
+ "hwb",
35
+ "lab",
36
+ "lch",
37
+ "oklab",
38
+ "oklch",
39
+ "color",
40
+ "device-cmyk",
41
+ "gray",
42
+ ...DERIVED_COLOR_FUNCS_LIST
43
+ ]);
44
+ const RE_FUNC_CALL = /^([a-z][a-z0-9-]*)\((.+)\)$/i;
45
+ const RE_UNIT_NUM = /^[+-]?(?:\d*\.\d+|\d+)([a-z][a-z0-9]*)$/;
46
+ const RE_NUMBER = /^[+-]?(?:\d*\.\d+|\d+)$/;
47
+ const RE_HEX = /^(?:[0-9a-f]{3,4}|[0-9a-f]{6}(?:[0-9a-f]{2})?)$/;
48
+ const RE_RAW_UNIT = /^([+-]?(?:\d*\.\d+|\d+))([a-z%]+)$/;
49
+ const CANONICAL_FUNC_CASE = /* @__PURE__ */ new Map([
50
+ ["translatex", "translateX"],
51
+ ["translatey", "translateY"],
52
+ ["translatez", "translateZ"],
53
+ ["scalex", "scaleX"],
54
+ ["scaley", "scaleY"],
55
+ ["scalez", "scaleZ"],
56
+ ["rotatex", "rotateX"],
57
+ ["rotatey", "rotateY"],
58
+ ["rotatez", "rotateZ"],
59
+ ["skewx", "skewX"],
60
+ ["skewy", "skewY"]
61
+ ]);
62
+ function canonicalFuncName(lowered) {
63
+ return CANONICAL_FUNC_CASE.get(lowered) ?? lowered;
64
+ }
65
+ //#endregion
66
+ //#region src/utils/string.ts
67
+ function toSnakeCase(str) {
68
+ return str.replace(/[A-Z]/g, (s) => `-${s.toLowerCase()}`);
69
+ }
70
+ function normalizeDslName(name) {
71
+ if (!name) return name;
72
+ const first = name[0];
73
+ const lower = first.toLowerCase();
74
+ return lower === first ? name : lower + name.slice(1);
75
+ }
76
+ const RE_DSL_IDENTIFIER = /(\$\$?|##?|--)([a-zA-Z_][a-zA-Z0-9_-]*)/g;
77
+ function foldDslCase(src) {
78
+ const folded = src.toLowerCase();
79
+ if (folded === src || !src.includes("$") && !src.includes("#") && !src.includes("--")) return folded;
80
+ RE_DSL_IDENTIFIER.lastIndex = 0;
81
+ let out = "";
82
+ let last = 0;
83
+ let match;
84
+ while (match = RE_DSL_IDENTIFIER.exec(src)) {
85
+ const [whole, prefix, body] = match;
86
+ out += src.slice(last, match.index).toLowerCase();
87
+ out += prefix + (prefix === "--" ? body : prefix[0] === "#" && RE_HEX.test(body.toLowerCase()) ? body.toLowerCase() : normalizeDslName(body));
88
+ last = match.index + whole.length;
89
+ }
90
+ return out + src.slice(last).toLowerCase();
91
+ }
92
+ //#endregion
93
+ //#region src/utils/color-math.ts
94
+ const OKLab_to_LMS_ab = [
95
+ [.3963377773761749, .2158037573099136],
96
+ [-.1055613458156586, -.0638541728258133],
97
+ [-.0894841775298119, -1.2914855480194092]
98
+ ];
99
+ const LMS_to_linear_sRGB_M = [
100
+ [
101
+ 4.076741636075959,
102
+ -3.307711539258062,
103
+ .2309699031821041
104
+ ],
105
+ [
106
+ -1.2684379732850313,
107
+ 2.6097573492876878,
108
+ -.3413193760026569
109
+ ],
110
+ [
111
+ -.004196076138675526,
112
+ -.703418617935936,
113
+ 1.7076146940746113
114
+ ]
115
+ ];
116
+ const OKLab_to_linear_sRGB_coefficients = [
117
+ [[-1.8817030993265873, -.8093650129914302], [
118
+ 1.19086277,
119
+ 1.76576728,
120
+ .59662641,
121
+ .75515197,
122
+ .56771245
123
+ ]],
124
+ [[1.8144407988010998, -1.194452667805235], [
125
+ .73956515,
126
+ -.45954404,
127
+ .08285427,
128
+ .1254107,
129
+ .14503204
130
+ ]],
131
+ [[.13110757611180954, 1.813339709266608], [
132
+ 1.35733652,
133
+ -.00915799,
134
+ -1.1513021,
135
+ -.50559606,
136
+ .00692167
137
+ ]]
138
+ ];
139
+ const dotXY = (vector, x, y) => vector[0] * x + vector[1] * y;
140
+ const dotXYZ = (matrix, x, y, z) => matrix[0] * x + matrix[1] * y + matrix[2] * z;
141
+ const INV_GAMMA = 1 / 2.4;
142
+ function srgbLinearToGamma(val) {
143
+ const sign = val < 0 ? -1 : 1;
144
+ const abs = Math.abs(val);
145
+ return abs > .0031308 ? sign * (1.055 * abs ** INV_GAMMA - .055) : 12.92 * val;
146
+ }
147
+ const TAU = 2 * Math.PI;
148
+ const K1 = .206;
149
+ const K2 = .03;
150
+ const K3 = 1.206 / 1.03;
151
+ const clamp$1 = (value, min, max) => Math.max(Math.min(value, max), min);
152
+ const constrainAngle = (angle) => (angle % 360 + 360) % 360;
153
+ const toe = (x) => .5 * (K3 * x - K1 + Math.sqrt((K3 * x - K1) * (K3 * x - K1) + 4 * K2 * K3 * x));
154
+ const toeInv = (x) => (x ** 2 + K1 * x) / (K3 * (x + K2));
155
+ const OKHST_REF_EPS = .05;
156
+ function yToL(y) {
157
+ return toe(Math.cbrt(Math.max(0, y)));
158
+ }
159
+ function yFromTone(t, eps = OKHST_REF_EPS) {
160
+ const den = Math.log(1 + eps) - Math.log(eps);
161
+ return Math.exp(t / 100 * den + Math.log(eps)) - eps;
162
+ }
163
+ function fromTone(t, eps = OKHST_REF_EPS) {
164
+ return yToL(yFromTone(t, eps));
165
+ }
166
+ const oklabToLinearSrgb = (lab) => {
167
+ const L = lab[0];
168
+ const a = lab[1];
169
+ const b = lab[2];
170
+ const l_ = L + .3963377773761749 * a + .2158037573099136 * b;
171
+ const m_ = L - .1055613458156586 * a - .0638541728258133 * b;
172
+ const s_ = L - .0894841775298119 * a - 1.2914855480194092 * b;
173
+ const l = l_ * l_ * l_;
174
+ const m = m_ * m_ * m_;
175
+ const s = s_ * s_ * s_;
176
+ return [
177
+ 4.076741636075959 * l - 3.307711539258062 * m + .2309699031821041 * s,
178
+ -1.2684379732850313 * l + 2.6097573492876878 * m - .3413193760026569 * s,
179
+ -.004196076138675526 * l - .703418617935936 * m + 1.7076146940746113 * s
180
+ ];
181
+ };
182
+ const computeMaxSaturationOKLC = (a, b) => {
183
+ const okCoeff = OKLab_to_linear_sRGB_coefficients;
184
+ const lmsToRgb = LMS_to_linear_sRGB_M;
185
+ let chnlCoeff;
186
+ let chnlLMS;
187
+ if (dotXY(okCoeff[0][0], a, b) > 1) {
188
+ chnlCoeff = okCoeff[0][1];
189
+ chnlLMS = lmsToRgb[0];
190
+ } else if (dotXY(okCoeff[1][0], a, b) > 1) {
191
+ chnlCoeff = okCoeff[1][1];
192
+ chnlLMS = lmsToRgb[1];
193
+ } else {
194
+ chnlCoeff = okCoeff[2][1];
195
+ chnlLMS = lmsToRgb[2];
196
+ }
197
+ const [k0, k1, k2, k3, k4] = chnlCoeff;
198
+ const [wl, wm, ws] = chnlLMS;
199
+ let sat = k0 + k1 * a + k2 * b + k3 * (a * a) + k4 * a * b;
200
+ const kl = dotXY(OKLab_to_LMS_ab[0], a, b);
201
+ const km = dotXY(OKLab_to_LMS_ab[1], a, b);
202
+ const ks = dotXY(OKLab_to_LMS_ab[2], a, b);
203
+ const l_ = 1 + sat * kl;
204
+ const m_ = 1 + sat * km;
205
+ const s_ = 1 + sat * ks;
206
+ const l = l_ ** 3;
207
+ const m = m_ ** 3;
208
+ const s = s_ ** 3;
209
+ const lds = 3 * kl * (l_ * l_);
210
+ const mds = 3 * km * (m_ * m_);
211
+ const sds = 3 * ks * (s_ * s_);
212
+ const lds2 = 6 * (kl * kl) * l_;
213
+ const mds2 = 6 * (km * km) * m_;
214
+ const sds2 = 6 * (ks * ks) * s_;
215
+ const f = wl * l + wm * m + ws * s;
216
+ const f1 = wl * lds + wm * mds + ws * sds;
217
+ const f2 = wl * lds2 + wm * mds2 + ws * sds2;
218
+ sat = sat - f * f1 / (f1 * f1 - .5 * f * f2);
219
+ return sat;
220
+ };
221
+ const findCuspOKLCH = (a, b) => {
222
+ const S_cusp = computeMaxSaturationOKLC(a, b);
223
+ const lab = [
224
+ 1,
225
+ S_cusp * a,
226
+ S_cusp * b
227
+ ];
228
+ const rgb_at_max = oklabToLinearSrgb(lab);
229
+ const L_cusp = Math.cbrt(1 / Math.max(Math.max(rgb_at_max[0], rgb_at_max[1]), Math.max(rgb_at_max[2], 0)));
230
+ return [L_cusp, L_cusp * S_cusp];
231
+ };
232
+ const findGamutIntersectionOKLCH = (a, b, l1, c1, l0, cusp) => {
233
+ const lmsToRgb = LMS_to_linear_sRGB_M;
234
+ let t;
235
+ if ((l1 - l0) * cusp[1] - (cusp[0] - l0) * c1 <= 0) {
236
+ const denom = c1 * cusp[0] + cusp[1] * (l0 - l1);
237
+ t = denom === 0 ? 0 : cusp[1] * l0 / denom;
238
+ } else {
239
+ const denom = c1 * (cusp[0] - 1) + cusp[1] * (l0 - l1);
240
+ t = denom === 0 ? 0 : cusp[1] * (l0 - 1) / denom;
241
+ const dl = l1 - l0;
242
+ const dc = c1;
243
+ const kl = dotXY(OKLab_to_LMS_ab[0], a, b);
244
+ const km = dotXY(OKLab_to_LMS_ab[1], a, b);
245
+ const ks = dotXY(OKLab_to_LMS_ab[2], a, b);
246
+ const ldt_ = dl + dc * kl;
247
+ const mdt_ = dl + dc * km;
248
+ const sdt_ = dl + dc * ks;
249
+ const L = l0 * (1 - t) + t * l1;
250
+ const C = t * c1;
251
+ const l_ = L + C * kl;
252
+ const m_ = L + C * km;
253
+ const s_ = L + C * ks;
254
+ const l = l_ ** 3;
255
+ const m = m_ ** 3;
256
+ const s = s_ ** 3;
257
+ const ldt = 3 * ldt_ * l_ * l_;
258
+ const mdt = 3 * mdt_ * m_ * m_;
259
+ const sdt = 3 * sdt_ * s_ * s_;
260
+ const ldt2 = 6 * ldt_ * ldt_ * l_;
261
+ const mdt2 = 6 * mdt_ * mdt_ * m_;
262
+ const sdt2 = 6 * sdt_ * sdt_ * s_;
263
+ let correction = Number.MAX_VALUE;
264
+ for (const matrix of lmsToRgb) {
265
+ const value = dotXYZ(matrix, l, m, s) - 1;
266
+ const slope = dotXYZ(matrix, ldt, mdt, sdt);
267
+ const slope2 = dotXYZ(matrix, ldt2, mdt2, sdt2);
268
+ const u = slope / (slope * slope - .5 * value * slope2);
269
+ if (u >= 0) correction = Math.min(correction, -value * u);
270
+ }
271
+ t += correction;
272
+ }
273
+ return t;
274
+ };
275
+ const computeSt = (cusp) => [cusp[1] / cusp[0], cusp[1] / (1 - cusp[0])];
276
+ const computeStMid = (a, b) => [.11516993 + 1 / (7.4477897 + 4.1590124 * b + a * (-2.19557347 + 1.75198401 * b + a * (-2.13704948 - 10.02301043 * b + a * (-4.24894561 + 5.38770819 * b + 4.69891013 * a)))), .11239642 + 1 / (1.6132032 - .68124379 * b + a * (.40370612 + .90148123 * b + a * (-.27087943 + .6122399 * b + a * (.00299215 - .45399568 * b - .14661872 * a))))];
277
+ const getCs = (L, a, b, cusp) => {
278
+ const cMax = findGamutIntersectionOKLCH(a, b, L, 1, L, cusp);
279
+ const stMax = computeSt(cusp);
280
+ const k = cMax / Math.min(L * stMax[0], (1 - L) * stMax[1]);
281
+ const stMid = computeStMid(a, b);
282
+ let ca = L * stMid[0];
283
+ let cb = (1 - L) * stMid[1];
284
+ const cMid = .9 * k * Math.sqrt(Math.sqrt(1 / (1 / ca ** 4 + 1 / cb ** 4)));
285
+ ca = L * .4;
286
+ cb = (1 - L) * .8;
287
+ return [
288
+ Math.sqrt(1 / (1 / ca ** 2 + 1 / cb ** 2)),
289
+ cMid,
290
+ cMax
291
+ ];
292
+ };
293
+ const okhslToOklab = (hsl) => {
294
+ let h = hsl[0];
295
+ const s = hsl[1];
296
+ const l = hsl[2];
297
+ const L = toeInv(l);
298
+ let a = 0;
299
+ let b = 0;
300
+ h = constrainAngle(h) / 360;
301
+ if (L !== 0 && L !== 1 && s !== 0) {
302
+ const a_ = Math.cos(TAU * h);
303
+ const b_ = Math.sin(TAU * h);
304
+ const cusp = findCuspOKLCH(a_, b_);
305
+ const [c0, cMid, cMax] = getCs(L, a_, b_, cusp);
306
+ const mid = .8;
307
+ const midInv = 1.25;
308
+ let t, k0, k1, k2;
309
+ if (s < mid) {
310
+ t = midInv * s;
311
+ k0 = 0;
312
+ k1 = mid * c0;
313
+ k2 = 1 - k1 / cMid;
314
+ } else {
315
+ t = 5 * (s - .8);
316
+ k0 = cMid;
317
+ k1 = .2 * cMid ** 2 * 1.25 ** 2 / c0;
318
+ k2 = 1 - k1 / (cMax - cMid);
319
+ }
320
+ const c = k0 + t * k1 / (1 - k2 * t);
321
+ a = c * a_;
322
+ b = c * b_;
323
+ }
324
+ return [
325
+ L,
326
+ a,
327
+ b
328
+ ];
329
+ };
330
+ function hslToRgbValues(h, s, l) {
331
+ const a = s * Math.min(l, 1 - l);
332
+ const f = (n) => {
333
+ const k = (n + h / 30) % 12;
334
+ return l - a * Math.max(-1, Math.min(k - 3, 9 - k, 1));
335
+ };
336
+ return [
337
+ f(0) * 255,
338
+ f(8) * 255,
339
+ f(4) * 255
340
+ ];
341
+ }
342
+ function okhslToSrgb(h, s, l) {
343
+ const oklab = okhslToOklab([
344
+ h,
345
+ s,
346
+ l
347
+ ]);
348
+ const linearRGB = oklabToLinearSrgb(oklab);
349
+ return [
350
+ clamp$1(srgbLinearToGamma(linearRGB[0]), 0, 1),
351
+ clamp$1(srgbLinearToGamma(linearRGB[1]), 0, 1),
352
+ clamp$1(srgbLinearToGamma(linearRGB[2]), 0, 1)
353
+ ];
354
+ }
355
+ function okhstToSrgb(h, s, t) {
356
+ return okhslToSrgb(h, clamp$1(s, 0, 1), clamp$1(fromTone(t * 100), 0, 1));
357
+ }
358
+ function oklchToRgbValues(L, C, H) {
359
+ const hRad = H * Math.PI / 180;
360
+ const a = C * Math.cos(hRad);
361
+ const b = C * Math.sin(hRad);
362
+ const linear = oklabToLinearSrgb([
363
+ L,
364
+ a,
365
+ b
366
+ ]);
367
+ return [
368
+ clamp$1(srgbLinearToGamma(linear[0]), 0, 1) * 255,
369
+ clamp$1(srgbLinearToGamma(linear[1]), 0, 1) * 255,
370
+ clamp$1(srgbLinearToGamma(linear[2]), 0, 1) * 255
371
+ ];
372
+ }
373
+ let _namedColorHex = null;
374
+ function getNamedColorHex() {
375
+ if (_namedColorHex) return _namedColorHex;
376
+ const names = "aliceblue antiquewhite aqua aquamarine azure beige bisque black blanchedalmond blue blueviolet brown burlywood cadetblue chartreuse chocolate coral cornflowerblue cornsilk crimson cyan darkblue darkcyan darkgoldenrod darkgray darkgreen darkgrey darkkhaki darkmagenta darkolivegreen darkorange darkorchid darkred darksalmon darkseagreen darkslateblue darkslategray darkslategrey darkturquoise darkviolet deeppink deepskyblue dimgray dimgrey dodgerblue firebrick floralwhite forestgreen fuchsia gainsboro ghostwhite gold goldenrod gray green greenyellow grey honeydew hotpink indianred indigo ivory khaki lavender lavenderblush lawngreen lemonchiffon lightblue lightcoral lightcyan lightgoldenrodyellow lightgray lightgreen lightgrey lightpink lightsalmon lightseagreen lightskyblue lightslategray lightslategrey lightsteelblue lightyellow lime limegreen linen magenta maroon mediumaquamarine mediumblue mediumorchid mediumpurple mediumseagreen mediumslateblue mediumspringgreen mediumturquoise mediumvioletred midnightblue mintcream mistyrose moccasin navajowhite navy oldlace olive olivedrab orange orangered orchid palegoldenrod palegreen paleturquoise palevioletred papayawhip peachpuff peru pink plum powderblue purple rebeccapurple red rosybrown royalblue saddlebrown salmon sandybrown seagreen seashell sienna silver skyblue slateblue slategray slategrey snow springgreen steelblue tan teal thistle tomato turquoise violet wheat white whitesmoke yellow yellowgreen".split(" ");
377
+ const hex = "f0f8fffaebd700ffff7fffd4f0fffff5f5dcffe4c4000000ffebcd0000ff8a2be2a52a2adeb8875f9ea07fff00d2691eff7f506495edfff8dcdc143c00ffff00008b008b8bb8860ba9a9a9006400a9a9a9bdb76b8b008b556b2fff8c009932cc8b0000e9967a8fbc8f483d8b2f4f4f2f4f4f00ced19400d3ff149300bfff6969696969691e90ffb22222fffaf0228b22ff00ffdcdcdcf8f8ffffd700daa520808080008000adff2f808080f0fff0ff69b4cd5c5c4b0082fffff0f0e68ce6e6fafff0f57cfc00fffacdadd8e6f08080e0fffffafad2d3d3d390ee90d3d3d3ffb6c1ffa07a20b2aa87cefa778899778899b0c4deffffe000ff0032cd32faf0e6ff00ff80000066cdaa0000cdba55d39370db3cb3717b68ee00fa9a48d1ccc71585191970f5fffaffe4e1ffe4b5ffdead000080fdf5e68080006b8e23ffa500ff4500da70d6eee8aa98fb98afeeeedb7093ffefd5ffdab9cd853fffc0cbdda0ddb0e0e6800080663399ff0000bc8f8f4169e18b4513fa8072f4a4602e8b57fff5eea0522dc0c0c087ceeb6a5acd708090708090fffafa00ff7f4682b4d2b48c008080d8bfd8ff634740e0d0ee82eef5deb3fffffff5f5f5ffff009acd32";
378
+ const colors = /* @__PURE__ */ new Map();
379
+ for (let i = 0; i < names.length; i++) colors.set(names[i], `#${hex.slice(i * 6, i * 6 + 6)}`);
380
+ return _namedColorHex = colors;
381
+ }
382
+ const SYSTEM_COLORS = new Set("accentcolor accentcolortext activetext buttonborder buttonface buttontext canvas canvastext field fieldtext graytext highlight highlighttext linktext mark marktext selecteditem selecteditemtext visitedtext".split(" "));
383
+ function isColorKeyword(name) {
384
+ const lower = name.toLowerCase();
385
+ return getNamedColorHex().has(lower) || SYSTEM_COLORS.has(lower);
386
+ }
387
+ function hexToRgb(hex) {
388
+ const matched = hex.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i, (_m, r, g, b) => "#" + r + r + g + g + b + b).substring(1).match(/.{2}/g);
389
+ if (!matched) return null;
390
+ const rgba = matched.map((x, i) => parseInt(x, 16) * (i === 3 ? 1 / 255 : 1));
391
+ if (rgba.some((v) => Number.isNaN(v))) return null;
392
+ if (rgba.length >= 3) return `rgb(${rgba.slice(0, 3).join(" ")}${rgba.length > 3 ? ` / ${rgba[3]}` : ""})`;
393
+ return null;
394
+ }
395
+ function getRgbValuesFromRgbaString(str) {
396
+ const match = str.match(/rgba?\(([^)]+)\)/i);
397
+ if (!match) return [];
398
+ const [colorPart] = match[1].trim().split("/");
399
+ return colorPart.trim().split(/[,\s]+/).filter(Boolean).slice(0, 3).map((part) => {
400
+ part = part.trim();
401
+ if (part.endsWith("%")) return parseFloat(part) / 100 * 255;
402
+ return parseFloat(part);
403
+ });
404
+ }
405
+ function strToRgb(color, _ignoreAlpha = false) {
406
+ if (!color) return void 0;
407
+ if (color.startsWith("rgb")) return color;
408
+ if (color.startsWith("#")) return hexToRgb(color);
409
+ if (color.startsWith("oklch(")) return oklchStringToRgb(color);
410
+ if (color.startsWith("hsl")) return hslStringToRgb(color);
411
+ const namedHex = getNamedColorHex().get(color.toLowerCase());
412
+ if (namedHex) return hexToRgb(namedHex);
413
+ return null;
414
+ }
415
+ function hslStringToRgb(hslStr) {
416
+ const match = hslStr.match(/hsla?\(([^)]+)\)/i);
417
+ if (!match) return null;
418
+ const [colorPart, slashAlpha] = match[1].trim().split("/");
419
+ const parts = colorPart.trim().split(/[,\s]+/).filter(Boolean);
420
+ if (parts.length < 3) return null;
421
+ const alphaPart = slashAlpha?.trim() || (parts.length >= 4 ? parts[3] : null);
422
+ let h = parseFloat(parts[0]);
423
+ const hueStr = parts[0].toLowerCase();
424
+ if (hueStr.endsWith("turn")) h = parseFloat(hueStr) * 360;
425
+ else if (hueStr.endsWith("rad")) h = parseFloat(hueStr) * 180 / Math.PI;
426
+ h = (h % 360 + 360) % 360;
427
+ const parsePercent = (val) => {
428
+ const num = parseFloat(val);
429
+ return val.includes("%") ? num / 100 : num;
430
+ };
431
+ const s = Math.max(0, Math.min(1, parsePercent(parts[1])));
432
+ const l = Math.max(0, Math.min(1, parsePercent(parts[2])));
433
+ const [r, g, b] = hslToRgbValues(h, s, l);
434
+ if (alphaPart) {
435
+ const alpha = parseFloat(alphaPart.trim());
436
+ return `rgba(${Math.round(r)}, ${Math.round(g)}, ${Math.round(b)}, ${alpha})`;
437
+ }
438
+ return `rgb(${Math.round(r)} ${Math.round(g)} ${Math.round(b)})`;
439
+ }
440
+ function oklchStringToRgb(oklchStr) {
441
+ const match = oklchStr.match(/oklch\(([^)]+)\)/i);
442
+ if (!match) return null;
443
+ const [colorPart, alphaPart] = match[1].trim().split("/");
444
+ const parts = colorPart.trim().split(/[,\s]+/).filter(Boolean);
445
+ if (parts.length < 3) return null;
446
+ const parsePercent = (val) => {
447
+ const num = parseFloat(val);
448
+ return val.includes("%") ? num / 100 : num;
449
+ };
450
+ const L = Math.max(0, Math.min(1, parsePercent(parts[0])));
451
+ const C = Math.max(0, parseFloat(parts[1]));
452
+ let H = parseFloat(parts[2]);
453
+ const hueStr = parts[2].toLowerCase();
454
+ if (hueStr.endsWith("turn")) H = parseFloat(hueStr) * 360;
455
+ else if (hueStr.endsWith("rad")) H = parseFloat(hueStr) * 180 / Math.PI;
456
+ else if (hueStr.endsWith("deg")) H = parseFloat(hueStr);
457
+ const [r, g, b] = oklchToRgbValues(L, C, H);
458
+ if (alphaPart) {
459
+ const alpha = parseFloat(alphaPart.trim());
460
+ return `rgba(${Math.round(r)}, ${Math.round(g)}, ${Math.round(b)}, ${alpha})`;
461
+ }
462
+ return `rgb(${Math.round(r)} ${Math.round(g)} ${Math.round(b)})`;
463
+ }
464
+ //#endregion
465
+ //#region src/utils/color-space.ts
466
+ function mixColorAlpha(color, percentage) {
467
+ return `color-mix(in oklab, ${color} ${percentage}, transparent)`;
468
+ }
469
+ const RE_ALPHA_MIX = /^color-mix\(in oklab,\s*(.+) (\S+%|calc\(.+ \* 100%\)),\s*transparent\)$/;
470
+ function parseAlphaMix(value) {
471
+ const match = value.match(RE_ALPHA_MIX);
472
+ return match ? {
473
+ color: match[1],
474
+ percentage: match[2]
475
+ } : null;
476
+ }
477
+ const ZERO_ALPHA = String.raw`(?:0+(?:\.0*)?|\.0+)%?|none`;
478
+ const RE_SLASH_ZERO_ALPHA = new RegExp(String.raw`\/\s*(?:${ZERO_ALPHA})\s*\)$`, "i");
479
+ const RE_LEGACY_ZERO_ALPHA = new RegExp(String.raw`^(?:rgba|hsla)\([^(),]*,[^(),]*,[^(),]*,\s*(?:${ZERO_ALPHA})\s*\)$`, "i");
480
+ function isTransparent(color) {
481
+ return color === "transparent" || parseAlphaMix(color)?.percentage === "0%" || RE_SLASH_ZERO_ALPHA.test(color) || RE_LEGACY_ZERO_ALPHA.test(color);
482
+ }
483
+ function alphaToPercentage(alpha) {
484
+ return `${Number(((Number.isNaN(alpha) ? 1 : Math.min(1, Math.max(0, alpha))) * 100).toFixed(6))}%`;
485
+ }
486
+ //#endregion
487
+ //#region src/parser/types.ts
488
+ const makeEmptyPart = () => ({
489
+ mods: [],
490
+ values: [],
491
+ colors: [],
492
+ all: [],
493
+ output: ""
494
+ });
495
+ const makeEmptyDetails = () => ({
496
+ input: "",
497
+ output: "",
498
+ mods: [],
499
+ values: [],
500
+ colors: [],
501
+ all: [],
502
+ parts: []
503
+ });
504
+ //#endregion
505
+ //#region src/parser/classify.ts
506
+ function alphaSuffixToPercentage(rawAlpha) {
507
+ if (rawAlpha.startsWith("$")) return `calc(var(--${rawAlpha.slice(1)}) * 100%)`;
508
+ if (rawAlpha === "0") return "0%";
509
+ const digits = rawAlpha.length === 1 ? `${rawAlpha}0` : rawAlpha;
510
+ const whole = String(Number(digits.slice(0, 2)));
511
+ const fraction = digits.slice(2).replace(/0+$/, "");
512
+ return `${fraction ? `${whole}.${fraction}` : whole}%`;
513
+ }
514
+ function fadeColor(color, rawAlpha) {
515
+ return mixColorAlpha(color, alphaSuffixToPercentage(rawAlpha));
516
+ }
517
+ const ALPHA_SUFFIX = String.raw`(\$[a-z_][a-z0-9-_]*|[0-9]+)`;
518
+ const RE_CURRENT_ALPHA = new RegExp(`^#current\\.${ALPHA_SUFFIX}$`, "i");
519
+ const RE_TOKEN_ALPHA = new RegExp(`^(#[a-z0-9-]+)\\.${ALPHA_SUFFIX}$`, "i");
520
+ const RE_COLOR_LAYER = new RegExp(`^(#[a-z0-9-]+)(?:\\.${ALPHA_SUFFIX})?$`, "i");
521
+ function layerColors(token, opts, recurse) {
522
+ const operands = token.split("+").map((part) => part.match(RE_COLOR_LAYER));
523
+ if (operands.some((match) => !match)) return null;
524
+ const colorOf = (input) => {
525
+ const { bucket, processed } = classify(input, opts, recurse);
526
+ return bucket === 0 || bucket === 3 ? processed : null;
527
+ };
528
+ const [base, ...layers] = operands;
529
+ let result = colorOf(base[0]);
530
+ if (result === null) return null;
531
+ for (const [layerInput, name, rawAlpha] of layers) {
532
+ const color = colorOf(name);
533
+ if (color === null) return null;
534
+ if (isTransparent(color)) continue;
535
+ if (rawAlpha === void 0) {
536
+ warnOnceDev(`compound-color-opaque:${token}`, `"${token}": "${layerInput}" has no opacity, so it covers everything before it and the color is just "${layerInput}". Give the layer an opacity, such as "${layerInput}.04".`);
537
+ result = color;
538
+ continue;
539
+ }
540
+ const opacity = alphaSuffixToPercentage(rawAlpha);
541
+ if (opacity === "0%") continue;
542
+ result = isTransparent(result) ? mixColorAlpha(color, opacity) : `color-mix(in srgb, ${color} ${opacity}, ${result})`;
543
+ }
544
+ return result;
545
+ }
546
+ function hasColorArgs(parsed) {
547
+ return parsed.groups.some((group) => group.colors.length > 0);
548
+ }
549
+ function isSingleColor(group) {
550
+ return !!group && group.all.length === 1 && group.colors.length === 1;
551
+ }
552
+ function resolveUntilStable(value, opts, recurse, maxIterations = 10) {
553
+ let current = value;
554
+ for (let i = 0; i < maxIterations; i++) {
555
+ const unitMatch = current.match(RE_UNIT_NUM);
556
+ if (!unitMatch) break;
557
+ const unitName = unitMatch[1];
558
+ if (!opts.units || !(unitName in opts.units)) break;
559
+ const result = recurse(current);
560
+ if (result.output === current) break;
561
+ current = result.output;
562
+ }
563
+ return current;
564
+ }
565
+ function classify(raw, opts, recurse) {
566
+ const token = raw.trim();
567
+ if (!token) return {
568
+ bucket: 2,
569
+ processed: ""
570
+ };
571
+ if (token.includes("(")) {
572
+ let depth = 0;
573
+ let inQuote = 0;
574
+ for (let i = 0; i < token.length; i++) {
575
+ const ch = token[i];
576
+ if (inQuote) {
577
+ if (ch === inQuote && token[i - 1] !== "\\") inQuote = 0;
578
+ continue;
579
+ }
580
+ if (ch === "\"" || ch === "'") {
581
+ inQuote = ch;
582
+ continue;
583
+ }
584
+ if (ch === "(") depth++;
585
+ else if (ch === ")" && depth) depth--;
586
+ }
587
+ if (depth !== 0) {
588
+ if (process.env.NODE_ENV !== "production") console.warn("[Tasty] skipped invalid function token with unmatched parentheses:", token);
589
+ return {
590
+ bucket: 2,
591
+ processed: ""
592
+ };
593
+ }
594
+ }
595
+ if (token.startsWith("\"") && token.endsWith("\"") || token.startsWith("'") && token.endsWith("'")) return {
596
+ bucket: 1,
597
+ processed: token
598
+ };
599
+ if (token.startsWith("$$")) {
600
+ const rest = token.slice(2);
601
+ const openIdx = rest.indexOf("(");
602
+ if (openIdx > 0 && rest.endsWith(")")) {
603
+ const fname = rest.slice(0, openIdx);
604
+ if (/^[a-z_][a-z0-9-_]*$/i.test(fname)) {
605
+ const inner = rest.slice(openIdx + 1, -1).trim();
606
+ const cssName = `--${fname}`;
607
+ if (opts.functions && cssName in opts.functions) {
608
+ const groups = inner ? new StyleParser(opts).process(inner).groups : [];
609
+ const funcResult = opts.functions[cssName](groups);
610
+ if (funcResult !== "") return classify(funcResult, {
611
+ ...opts,
612
+ functions: void 0
613
+ }, recurse);
614
+ }
615
+ return {
616
+ bucket: 1,
617
+ processed: `--${fname}(${inner ? recurse(inner).output : ""})`
618
+ };
619
+ }
620
+ }
621
+ if (/^[a-z_][a-z0-9-_]*$/i.test(rest)) return {
622
+ bucket: 1,
623
+ processed: `--${rest}`
624
+ };
625
+ }
626
+ if (token.startsWith("##")) {
627
+ const rest = token.slice(2);
628
+ const openIdx = rest.indexOf("(");
629
+ if (openIdx > 0 && rest.endsWith(")")) {
630
+ const fname = rest.slice(0, openIdx);
631
+ if (/^[a-z_][a-z0-9-_]*$/i.test(fname)) {
632
+ const inner = rest.slice(openIdx + 1, -1).trim();
633
+ return {
634
+ bucket: 1,
635
+ processed: `--${fname}-color(${inner ? recurse(inner).output : ""})`
636
+ };
637
+ }
638
+ }
639
+ if (/^[a-z_][a-z0-9-_]*$/i.test(rest)) return {
640
+ bucket: 1,
641
+ processed: `--${rest}-color`
642
+ };
643
+ }
644
+ if (token[0] === "#" && token.includes("+")) {
645
+ const layered = layerColors(token, opts, recurse);
646
+ if (layered !== null) return {
647
+ bucket: 0,
648
+ processed: layered
649
+ };
650
+ warnOnceDev(`compound-color-invalid:${token}`, `"${token}" is not a compound color and is ignored: every part joined by "+" must be a color token with an optional opacity, such as "#surface+#dark.04".`);
651
+ return {
652
+ bucket: 2,
653
+ processed: ""
654
+ };
655
+ }
656
+ if (token === "#current") return {
657
+ bucket: 0,
658
+ processed: "currentcolor"
659
+ };
660
+ const currentAlphaMatch = token.match(RE_CURRENT_ALPHA);
661
+ if (currentAlphaMatch) return {
662
+ bucket: 0,
663
+ processed: fadeColor("currentcolor", currentAlphaMatch[1])
664
+ };
665
+ if (token[0] === "$" || token[0] === "#") {
666
+ const predefinedTokens = getGlobalPredefinedTokens();
667
+ if (predefinedTokens) {
668
+ const lookupKey = token.toLowerCase();
669
+ if (lookupKey in predefinedTokens) {
670
+ const tokenValue = predefinedTokens[lookupKey];
671
+ return classify(foldDslCase(tokenValue), opts, recurse);
672
+ }
673
+ if (token[0] === "#") {
674
+ const alphaMatch = token.match(RE_TOKEN_ALPHA);
675
+ if (alphaMatch) {
676
+ const [, baseToken, rawAlpha] = alphaMatch;
677
+ const baseKey = baseToken.toLowerCase();
678
+ if (baseKey in predefinedTokens) {
679
+ const resolvedValue = predefinedTokens[baseKey];
680
+ if (resolvedValue.trim().toLowerCase() === "transparent") return {
681
+ bucket: 0,
682
+ processed: "transparent"
683
+ };
684
+ const fadeWhole = () => {
685
+ const { bucket, processed } = classify(foldDslCase(resolvedValue), opts, recurse);
686
+ return bucket === 0 || bucket === 3 ? {
687
+ bucket: 0,
688
+ processed: fadeColor(processed, rawAlpha)
689
+ } : {
690
+ bucket: 2,
691
+ processed: ""
692
+ };
693
+ };
694
+ if (resolvedValue.startsWith("#") && resolvedValue.includes("+")) return fadeWhole();
695
+ if (resolvedValue.startsWith("#")) return classify(`${foldDslCase(resolvedValue)}.${rawAlpha}`, opts, recurse);
696
+ const funcMatch = resolvedValue.match(RE_FUNC_CALL);
697
+ if (funcMatch) {
698
+ const [, funcName, args] = funcMatch;
699
+ const lowerFunc = funcName.toLowerCase();
700
+ if (DERIVED_COLOR_FUNCS.has(lowerFunc)) return fadeWhole();
701
+ const isCustomFunc = !!(opts.functions && lowerFunc in opts.functions && !COLOR_FUNCS.has(lowerFunc) && !COLOR_FUNCS.has(funcName.replace(/a$/i, "").toLowerCase()));
702
+ const normalizedFunc = isCustomFunc ? lowerFunc : funcName.replace(/a$/i, "").toLowerCase();
703
+ if (!(COLOR_FUNCS.has(normalizedFunc) || COLOR_FUNCS.has(lowerFunc) || isCustomFunc)) return classify(`${resolvedValue}.${rawAlpha}`, opts, recurse);
704
+ let alpha;
705
+ if (rawAlpha.startsWith("$")) alpha = `var(--${rawAlpha.slice(1)})`;
706
+ else alpha = rawAlpha === "0" ? "0" : `.${rawAlpha}`;
707
+ const normalizeArgs = (a) => {
708
+ let result = "";
709
+ let depth = 0;
710
+ for (let i = 0; i < a.length; i++) {
711
+ const c = a[i];
712
+ if (c === "(") {
713
+ depth++;
714
+ result += c;
715
+ } else if (c === ")") {
716
+ depth = Math.max(0, depth - 1);
717
+ result += c;
718
+ } else if (c === "," && depth === 0) {
719
+ while (i + 1 < a.length && /\s/.test(a[i + 1])) i++;
720
+ result += " ";
721
+ } else result += c;
722
+ }
723
+ return result;
724
+ };
725
+ const findLastTopLevel = (str, ch) => {
726
+ let depth = 0;
727
+ for (let i = str.length - 1; i >= 0; i--) {
728
+ const c = str[i];
729
+ if (c === ")") depth++;
730
+ else if (c === "(") depth = Math.max(0, depth - 1);
731
+ else if (c === ch && depth === 0) return i;
732
+ }
733
+ return -1;
734
+ };
735
+ const slashIdx = findLastTopLevel(args, "/");
736
+ const hasModernAlpha = slashIdx !== -1;
737
+ let topLevelCommaCount = 0;
738
+ let lastTopLevelComma = -1;
739
+ {
740
+ let depth = 0;
741
+ for (let i = 0; i < args.length; i++) {
742
+ const c = args[i];
743
+ if (c === "(") depth++;
744
+ else if (c === ")") depth = Math.max(0, depth - 1);
745
+ else if (c === "," && depth === 0) {
746
+ topLevelCommaCount++;
747
+ lastTopLevelComma = i;
748
+ }
749
+ }
750
+ }
751
+ const hasLegacyAlpha = !hasModernAlpha && /a$/i.test(funcName) && topLevelCommaCount === 3;
752
+ const constructed = `${normalizedFunc}(${hasModernAlpha || hasLegacyAlpha ? normalizeArgs(hasModernAlpha ? args.slice(0, slashIdx).trim() : args.slice(0, lastTopLevelComma).trim()) : normalizeArgs(args)} / ${alpha})`;
753
+ if (!COLOR_FUNCS.has(normalizedFunc) && opts.functions && normalizedFunc in opts.functions) return classify(constructed, opts, recurse);
754
+ return {
755
+ bucket: 0,
756
+ processed: constructed
757
+ };
758
+ }
759
+ const keyword = resolvedValue.trim().toLowerCase();
760
+ if (keyword === "currentcolor" || isColorKeyword(keyword)) return {
761
+ bucket: 0,
762
+ processed: fadeColor(keyword, rawAlpha)
763
+ };
764
+ return classify(`${resolvedValue}.${rawAlpha}`, opts, recurse);
765
+ }
766
+ }
767
+ }
768
+ }
769
+ }
770
+ if (token.match(/^var\(--([a-zA-Z0-9-]+)-color\)$/)) return {
771
+ bucket: 0,
772
+ processed: token
773
+ };
774
+ if (token.startsWith("url(")) return {
775
+ bucket: 1,
776
+ processed: token
777
+ };
778
+ if (token[0] === "$") {
779
+ const identMatch = token.match(/^\$([a-z_][a-zA-Z0-9-_]*)$/);
780
+ if (identMatch) {
781
+ const name = identMatch[1];
782
+ const processed = `var(--${name})`;
783
+ return {
784
+ bucket: name.endsWith("-color") ? 3 : 1,
785
+ processed
786
+ };
787
+ }
788
+ }
789
+ if (token[0] === "#" && token.length > 1) {
790
+ const alphaMatch = token.match(RE_TOKEN_ALPHA);
791
+ if (alphaMatch) {
792
+ const [, baseToken, rawAlpha] = alphaMatch;
793
+ const base = baseToken.slice(1);
794
+ return {
795
+ bucket: 0,
796
+ processed: fadeColor(RE_HEX.test(base) ? `var(--${base}-color, #${base})` : `var(--${base}-color)`, rawAlpha)
797
+ };
798
+ }
799
+ const name = token.slice(1);
800
+ if (RE_HEX.test(name)) return {
801
+ bucket: 0,
802
+ processed: `var(--${name}-color, #${name})`
803
+ };
804
+ return {
805
+ bucket: 0,
806
+ processed: `var(--${name}-color)`
807
+ };
808
+ }
809
+ const openIdx = token.indexOf("(");
810
+ if (openIdx > 0 && token.endsWith(")")) {
811
+ const fname = token.slice(0, openIdx);
812
+ const inner = token.slice(openIdx + 1, -1);
813
+ if (COLOR_FUNCS.has(fname)) {
814
+ const parsedInner = recurse(inner);
815
+ const argProcessed = parsedInner.output.replace(/,\s+/g, ",");
816
+ const processed = `${canonicalFuncName(fname)}(${argProcessed})`;
817
+ return {
818
+ bucket: fname === "light-dark" && !hasColorArgs(parsedInner) ? 1 : 0,
819
+ processed
820
+ };
821
+ }
822
+ if (opts.functions && fname in opts.functions) {
823
+ const tmp = new StyleParser(opts).process(inner);
824
+ return classify(opts.functions[fname](tmp.groups), {
825
+ ...opts,
826
+ functions: void 0
827
+ }, recurse);
828
+ }
829
+ const parsedInner = recurse(inner);
830
+ return {
831
+ bucket: fname === "var" && parsedInner.groups.length === 2 && isSingleColor(parsedInner.groups[1]) ? 0 : 1,
832
+ processed: `${canonicalFuncName(fname)}(${parsedInner.output})`
833
+ };
834
+ }
835
+ if (token.startsWith("(") && token.endsWith(")")) {
836
+ const colorMatch = token.slice(1, -1).match(/^#([a-z0-9-]+)\s*,\s*(.*)$/i);
837
+ if (colorMatch) {
838
+ const [, name, fallback] = colorMatch;
839
+ return {
840
+ bucket: 0,
841
+ processed: `var(--${name}-color, ${recurse(fallback).output})`
842
+ };
843
+ }
844
+ }
845
+ if (token.startsWith("(") && token.endsWith(")")) {
846
+ const match = token.slice(1, -1).match(/^\$([a-z_][a-zA-Z0-9-_]*)\s*,\s*(.*)$/);
847
+ if (match) {
848
+ const [, name, fallback] = match;
849
+ const parsedFallback = recurse(fallback);
850
+ return {
851
+ bucket: name.endsWith("-color") ? 3 : parsedFallback.groups.length === 1 && isSingleColor(parsedFallback.groups[0]) ? 0 : 1,
852
+ processed: `var(--${name}, ${parsedFallback.output})`
853
+ };
854
+ }
855
+ }
856
+ if (token[0] === "(" && token[token.length - 1] === ")") return {
857
+ bucket: 1,
858
+ processed: `calc(${recurse(token.slice(1, -1)).output})`
859
+ };
860
+ const um = token.match(RE_UNIT_NUM);
861
+ if (um) {
862
+ const unit = um[1];
863
+ const numericPart = parseFloat(token.slice(0, -unit.length));
864
+ const handler = opts.units && opts.units[unit];
865
+ if (handler) {
866
+ if (typeof handler === "string") {
867
+ const rawMatch = handler.match(RE_RAW_UNIT);
868
+ if (rawMatch) {
869
+ const [, baseNum, cssUnit] = rawMatch;
870
+ return {
871
+ bucket: 1,
872
+ processed: resolveUntilStable(`${numericPart * parseFloat(baseNum)}${cssUnit}`, opts, recurse)
873
+ };
874
+ }
875
+ const base = handler;
876
+ if (numericPart === 1) return {
877
+ bucket: 1,
878
+ processed: base
879
+ };
880
+ return {
881
+ bucket: 1,
882
+ processed: `calc(${numericPart} * ${base})`
883
+ };
884
+ } else return {
885
+ bucket: 1,
886
+ processed: handler(numericPart)
887
+ };
888
+ }
889
+ }
890
+ if (/^[+-]?(?:\d*\.\d+|\d+)[a-z%]+$/.test(token)) return {
891
+ bucket: 1,
892
+ processed: token
893
+ };
894
+ if (RE_NUMBER.test(token)) return {
895
+ bucket: 1,
896
+ processed: token
897
+ };
898
+ if (VALUE_KEYWORDS.has(token)) return {
899
+ bucket: 1,
900
+ processed: token
901
+ };
902
+ if (token === "transparent" || token === "currentcolor" || isColorKeyword(token)) return {
903
+ bucket: 0,
904
+ processed: token
905
+ };
906
+ return {
907
+ bucket: 2,
908
+ processed: token
909
+ };
910
+ }
911
+ //#endregion
912
+ //#region src/parser/lru.ts
913
+ var Lru = class {
914
+ limit;
915
+ map = /* @__PURE__ */ new Map();
916
+ head = null;
917
+ tail = null;
918
+ onEvict;
919
+ constructor(limit = 1e3, onEvict) {
920
+ this.limit = limit;
921
+ let normalized = Number.isFinite(this.limit) ? Math.floor(this.limit) : 1e3;
922
+ if (normalized <= 0) normalized = 1e3;
923
+ this.limit = normalized;
924
+ this.onEvict = onEvict;
925
+ }
926
+ setOnEvict(fn) {
927
+ this.onEvict = fn;
928
+ }
929
+ get(key) {
930
+ const node = this.map.get(key);
931
+ if (node === void 0) return void 0;
932
+ if (this.head !== node) this.moveToHead(node);
933
+ return node.value;
934
+ }
935
+ set(key, value) {
936
+ const existing = this.map.get(key);
937
+ if (existing !== void 0) {
938
+ existing.value = value;
939
+ if (this.head !== existing) this.moveToHead(existing);
940
+ return;
941
+ }
942
+ const node = {
943
+ key,
944
+ prev: null,
945
+ next: this.head,
946
+ value
947
+ };
948
+ if (this.head) this.head.prev = node;
949
+ this.head = node;
950
+ if (!this.tail) this.tail = node;
951
+ this.map.set(key, node);
952
+ if (this.map.size > this.limit) this.evict();
953
+ }
954
+ delete(key) {
955
+ const node = this.map.get(key);
956
+ if (node === void 0) return;
957
+ this.detach(node);
958
+ this.map.delete(key);
959
+ }
960
+ keys() {
961
+ return this.map.keys();
962
+ }
963
+ detach(node) {
964
+ if (node.prev) node.prev.next = node.next;
965
+ if (node.next) node.next.prev = node.prev;
966
+ if (this.head === node) this.head = node.next;
967
+ if (this.tail === node) this.tail = node.prev;
968
+ node.prev = null;
969
+ node.next = null;
970
+ }
971
+ moveToHead(node) {
972
+ this.detach(node);
973
+ node.next = this.head;
974
+ if (this.head) this.head.prev = node;
975
+ this.head = node;
976
+ if (!this.tail) this.tail = node;
977
+ }
978
+ evict() {
979
+ const node = this.tail;
980
+ if (!node) return;
981
+ this.detach(node);
982
+ this.map.delete(node.key);
983
+ if (this.onEvict) try {
984
+ this.onEvict(node.key, node.value);
985
+ } catch {}
986
+ }
987
+ clear() {
988
+ this.map.clear();
989
+ this.head = this.tail = null;
990
+ }
991
+ };
992
+ //#endregion
993
+ //#region src/parser/tokenizer.ts
994
+ const isWhitespace = (ch) => ch === " " || ch === "\n" || ch === " " || ch === "\r" || ch === "\f";
995
+ function scan(src, cb) {
996
+ let depth = 0;
997
+ let inQuote = 0;
998
+ let start = 0;
999
+ let i = 0;
1000
+ let pendingSlash = false;
1001
+ const flush = (isComma, isSlash) => {
1002
+ const actualSlash = isSlash || pendingSlash;
1003
+ pendingSlash = false;
1004
+ if (start < i) cb(src.slice(start, i), isComma, actualSlash);
1005
+ else if (isComma) cb("", true, false);
1006
+ else if (actualSlash) cb("", false, true);
1007
+ start = i + 1;
1008
+ };
1009
+ for (; i < src.length; i++) {
1010
+ const ch = src[i];
1011
+ if (inQuote) {
1012
+ if (ch === inQuote && src[i - 1] !== "\\") inQuote = 0;
1013
+ continue;
1014
+ }
1015
+ if (ch === "\"" || ch === "'") {
1016
+ inQuote = ch;
1017
+ continue;
1018
+ }
1019
+ if (ch === "(") {
1020
+ depth++;
1021
+ continue;
1022
+ }
1023
+ if (ch === ")") {
1024
+ if (depth) depth--;
1025
+ continue;
1026
+ }
1027
+ if (!depth) {
1028
+ if (ch === ",") {
1029
+ flush(true, false);
1030
+ continue;
1031
+ }
1032
+ if (ch === "/") {
1033
+ const prevIsWhitespace = isWhitespace(src[i - 1]);
1034
+ const nextIsWhitespace = isWhitespace(src[i + 1]);
1035
+ if (prevIsWhitespace && nextIsWhitespace) {
1036
+ pendingSlash = true;
1037
+ start = i + 1;
1038
+ continue;
1039
+ }
1040
+ continue;
1041
+ }
1042
+ if (isWhitespace(ch)) {
1043
+ flush(false, false);
1044
+ continue;
1045
+ }
1046
+ }
1047
+ }
1048
+ flush(false, false);
1049
+ }
1050
+ //#endregion
1051
+ //#region src/parser/parser.ts
1052
+ function warnSpacedCompound(src, tokens) {
1053
+ for (let i = 1; i < tokens.length; i++) {
1054
+ const prev = tokens[i - 1];
1055
+ const tok = tokens[i];
1056
+ if (prev[0] === "#" && (tok.startsWith("+#") || tok === "+" && tokens[i + 1]?.[0] === "#" || prev.endsWith("+") && tok[0] === "#")) {
1057
+ warnOnceDev(`compound-color-spaced:${src}`, `"${src}": a "+" joins colors only without spaces around it. Write "${src.replace(/(#[^\s,()+#]+)\s*\+\s*(?=#)/g, "$1+")}".`);
1058
+ return;
1059
+ }
1060
+ }
1061
+ }
1062
+ var StyleParser = class {
1063
+ opts;
1064
+ cache;
1065
+ constructor(opts = {}) {
1066
+ this.opts = opts;
1067
+ this.cache = new Lru(this.opts.cacheSize ?? 1e3);
1068
+ }
1069
+ process(src) {
1070
+ const key = String(src);
1071
+ const hit = this.cache.get(key);
1072
+ if (hit) return hit;
1073
+ const stripped = foldDslCase(src.replace(/\/\*[^*]*\*+(?:[^/*][^*]*\*+)*\//g, ""));
1074
+ const groups = [];
1075
+ let currentGroup = makeEmptyDetails();
1076
+ let currentPart = makeEmptyPart();
1077
+ let parts = [];
1078
+ const pushToken = (bucket, processed) => {
1079
+ if (!processed) return;
1080
+ if (currentPart.values.length > 0 && currentPart.values[currentPart.values.length - 1].startsWith("url(")) {
1081
+ currentPart.values[currentPart.values.length - 1] += ` ${processed}`;
1082
+ currentPart.all[currentPart.all.length - 1] += ` ${processed}`;
1083
+ return;
1084
+ }
1085
+ switch (bucket) {
1086
+ case 0:
1087
+ currentPart.colors.push(processed);
1088
+ break;
1089
+ case 1:
1090
+ currentPart.values.push(processed);
1091
+ break;
1092
+ case 2:
1093
+ currentPart.mods.push(processed);
1094
+ break;
1095
+ case 3:
1096
+ currentPart.colors.push(processed);
1097
+ currentPart.values.push(processed);
1098
+ }
1099
+ currentPart.all.push(processed);
1100
+ };
1101
+ const endPart = (reset = true) => {
1102
+ if (currentPart.all.length > 0) {
1103
+ currentPart.output = currentPart.all.join(" ");
1104
+ parts.push(currentPart);
1105
+ }
1106
+ if (reset) currentPart = makeEmptyPart();
1107
+ };
1108
+ const endGroup = (reset = true) => {
1109
+ endPart(reset);
1110
+ if (parts.length === 0) parts.push(makeEmptyPart());
1111
+ currentGroup.parts = parts;
1112
+ for (const part of parts) {
1113
+ currentGroup.mods.push(...part.mods);
1114
+ currentGroup.values.push(...part.values);
1115
+ currentGroup.colors.push(...part.colors);
1116
+ currentGroup.all.push(...part.all);
1117
+ }
1118
+ currentGroup.output = parts.length === 1 ? parts[0].output : parts.map((part) => part.output).join(" / ");
1119
+ groups.push(currentGroup);
1120
+ if (reset) {
1121
+ currentGroup = makeEmptyDetails();
1122
+ parts = [];
1123
+ }
1124
+ };
1125
+ const tokens = [];
1126
+ scan(stripped, (tok, isComma, isSlash) => {
1127
+ if (tok) {
1128
+ tokens.push(tok);
1129
+ if (currentGroup.input) currentGroup.input += ` ${tok}`;
1130
+ else currentGroup.input = tok;
1131
+ const { bucket, processed } = classify(tok, this.opts, (sub) => this.process(sub));
1132
+ pushToken(bucket, processed);
1133
+ }
1134
+ if (isSlash) endPart();
1135
+ if (isComma) endGroup();
1136
+ });
1137
+ if (currentPart.all.length || parts.length || !groups.length) endGroup(false);
1138
+ warnSpacedCompound(src, tokens);
1139
+ const result = {
1140
+ output: groups.length === 1 ? groups[0].output : groups.map((group) => group.output).join(", "),
1141
+ groups
1142
+ };
1143
+ Object.freeze(result);
1144
+ this.cache.set(key, result);
1145
+ return result;
1146
+ }
1147
+ setFunctions(functions) {
1148
+ this.opts.functions = functions;
1149
+ this.cache.clear();
1150
+ }
1151
+ setUnits(units) {
1152
+ this.opts.units = units;
1153
+ this.cache.clear();
1154
+ }
1155
+ updateOptions(patch) {
1156
+ Object.assign(this.opts, patch);
1157
+ if (patch.cacheSize) this.cache = new Lru(patch.cacheSize);
1158
+ else this.cache.clear();
1159
+ }
1160
+ clearCache() {
1161
+ this.cache.clear();
1162
+ }
1163
+ getUnits() {
1164
+ return this.opts.units;
1165
+ }
1166
+ };
1167
+ //#endregion
1168
+ //#region src/plugins/color-func.ts
1169
+ const clamp = (value, min, max) => Math.max(Math.min(value, max), min);
1170
+ const parseAngle = (value) => {
1171
+ const match = value.match(/^([+-]?\d*\.?\d+)(deg|turn|rad)?$/);
1172
+ if (!match) return 0;
1173
+ const num = parseFloat(match[1]);
1174
+ switch (match[2]) {
1175
+ case "turn": return num * 360;
1176
+ case "rad": return num * 180 / Math.PI;
1177
+ default: return num;
1178
+ }
1179
+ };
1180
+ const parsePercentage = (value) => {
1181
+ const match = value.match(/^([+-]?\d*\.?\d+)%?$/);
1182
+ if (!match) return 0;
1183
+ const num = parseFloat(match[1]);
1184
+ return value.includes("%") ? num / 100 : num;
1185
+ };
1186
+ function createColorFunc(name, convert, label) {
1187
+ const conversionCache = new Lru(500);
1188
+ const expected = label ? ` (${label})` : "";
1189
+ return (groups) => {
1190
+ if (groups.length === 0 || groups[0].all.length < 3) {
1191
+ if (isDevEnv()) console.warn(`[Tasty] ${name}(): expected 3 values${expected}, got:`, groups);
1192
+ return "rgb(0% 0% 0%)";
1193
+ }
1194
+ const group = groups[0];
1195
+ const tokens = group.all;
1196
+ const alpha = group.parts.length > 1 && group.parts[1].all.length > 0 ? group.parts[1].output : void 0;
1197
+ const cacheKey = tokens.slice(0, 3).join(" ") + (alpha ? ` / ${alpha}` : "");
1198
+ const cached = conversionCache.get(cacheKey);
1199
+ if (cached) return cached;
1200
+ const h = parseAngle(tokens[0]);
1201
+ const c2 = parsePercentage(tokens[1]);
1202
+ const c3 = parsePercentage(tokens[2]);
1203
+ const misscaled = [tokens[1], tokens[2]].filter((raw, i) => !raw.includes("%") && (i === 0 ? c2 : c3) > 1);
1204
+ 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.`);
1205
+ const [r, g, b] = convert(h, clamp(c2, 0, 1), clamp(c3, 0, 1));
1206
+ const format = (n) => {
1207
+ const pct = n * 100;
1208
+ return parseFloat(pct.toFixed(1)).toString() + "%";
1209
+ };
1210
+ const result = alpha ? `rgb(${format(r)} ${format(g)} ${format(b)} / ${alpha})` : `rgb(${format(r)} ${format(g)} ${format(b)})`;
1211
+ conversionCache.set(cacheKey, result);
1212
+ return result;
1213
+ };
1214
+ }
1215
+ //#endregion
1216
+ //#region src/plugins/okhsl-plugin.ts
1217
+ const okhslFunction = createColorFunc("okhsl", okhslToSrgb, "H S L");
1218
+ const okhslPlugin = () => ({
1219
+ name: "okhsl",
1220
+ functions: { okhsl: okhslFunction }
1221
+ });
1222
+ //#endregion
1223
+ //#region src/plugins/okhst-plugin.ts
1224
+ const okhstFunction = createColorFunc("okhst", okhstToSrgb, "H S T");
1225
+ const okhstPlugin = () => ({
1226
+ name: "okhst",
1227
+ functions: { okhst: okhstFunction }
1228
+ });
1229
+ //#endregion
1230
+ //#region src/plugins/defaults.ts
1231
+ function registerDefaultFunctions() {
1232
+ customFunction("okhsl", okhslFunction);
1233
+ customFunction("okhst", okhstFunction);
1234
+ }
1235
+ //#endregion
1236
+ //#region src/utils/styles.ts
1237
+ function normalizeColorTokenValue(value) {
1238
+ if (value === true) return "transparent";
1239
+ if (value === false) return null;
1240
+ return value;
1241
+ }
1242
+ const devMode = process.env.NODE_ENV !== "production";
1243
+ const COLOR_VAR_PATTERN = /^var\(--([a-z0-9-]+)-color[,)]/;
1244
+ const RGB_ALPHA_PATTERN = /\/\s*([0-9.]+)\)/;
1245
+ const RE_HEX_COLOR = /^#[0-9a-fA-F]{3,8}$/;
1246
+ const RE_VAR_COLOR = /^var\(--[a-z0-9-]+-color/;
1247
+ function isSimpleColorFast(val) {
1248
+ switch (val.charCodeAt(0)) {
1249
+ case 35: return RE_HEX_COLOR.test(val);
1250
+ case 114:
1251
+ if (val.charCodeAt(1) === 103 && val.charCodeAt(2) === 98) return true;
1252
+ break;
1253
+ case 104:
1254
+ if (val.charCodeAt(1) === 115 && val.charCodeAt(2) === 108) return true;
1255
+ break;
1256
+ case 108:
1257
+ if (val.charCodeAt(1) === 99 && val.charCodeAt(2) === 104) return true;
1258
+ break;
1259
+ case 111:
1260
+ if (val.startsWith("oklch(")) return true;
1261
+ break;
1262
+ case 118:
1263
+ if (RE_VAR_COLOR.test(val)) return true;
1264
+ break;
1265
+ case 99:
1266
+ if (val === "currentColor" || val === "currentcolor") return true;
1267
+ break;
1268
+ case 116: if (val === "transparent") return true;
1269
+ }
1270
+ return isColorKeyword(val);
1271
+ }
1272
+ let colorWarningCount = 0;
1273
+ const MAX_COLOR_WARNINGS = 10;
1274
+ const CUSTOM_UNITS = {
1275
+ r: "6px",
1276
+ cr: "10px",
1277
+ bw: "1px",
1278
+ ow: "3px",
1279
+ x: "8px",
1280
+ sf: function sf(num) {
1281
+ return `minmax(0, ${num}fr)`;
1282
+ }
1283
+ };
1284
+ const DIRECTIONS = [
1285
+ "top",
1286
+ "right",
1287
+ "bottom",
1288
+ "left"
1289
+ ];
1290
+ let __tastyParser = null;
1291
+ function getOrCreateParser() {
1292
+ if (!__tastyParser) {
1293
+ __tastyParser = new StyleParser({ units: CUSTOM_UNITS });
1294
+ __tastyParser.setFunctions(__tastyParseFunctions);
1295
+ registerDefaultFunctions();
1296
+ }
1297
+ return __tastyParser;
1298
+ }
1299
+ const __tastyParseFunctions = {};
1300
+ function customFunction(name, fn) {
1301
+ __tastyParseFunctions[name] = fn;
1302
+ getOrCreateParser().setFunctions(__tastyParseFunctions);
1303
+ }
1304
+ function resetGlobalParseFunctions() {
1305
+ for (const key of Object.keys(__tastyParseFunctions)) delete __tastyParseFunctions[key];
1306
+ registerDefaultFunctions();
1307
+ getOrCreateParser().setFunctions(__tastyParseFunctions);
1308
+ }
1309
+ function getGlobalParser() {
1310
+ return getOrCreateParser();
1311
+ }
1312
+ function getGlobalParseFunctions() {
1313
+ return __tastyParseFunctions;
1314
+ }
1315
+ const DEFAULT_PREDEFINED_TOKENS = { "#clear": "transparent" };
1316
+ let __globalPredefinedTokens = { ...DEFAULT_PREDEFINED_TOKENS };
1317
+ function setGlobalPredefinedTokens(tokens) {
1318
+ const normalizedTokens = {};
1319
+ for (const [key, value] of Object.entries(tokens)) {
1320
+ const lowerKey = key.toLowerCase();
1321
+ const lowerValue = value.toLowerCase();
1322
+ if (lowerKey.startsWith("#") && lowerValue === "#current") {
1323
+ if (process.env.NODE_ENV !== "production") console.warn(`[Tasty] Using #current to define color token "${key}" is not supported. The #current token represents currentcolor which cannot be used as a base for other tokens.`);
1324
+ continue;
1325
+ }
1326
+ normalizedTokens[lowerKey] = value;
1327
+ }
1328
+ __globalPredefinedTokens = {
1329
+ ...__globalPredefinedTokens,
1330
+ ...normalizedTokens
1331
+ };
1332
+ getOrCreateParser().clearCache();
1333
+ }
1334
+ function getGlobalPredefinedTokens() {
1335
+ return __globalPredefinedTokens;
1336
+ }
1337
+ function resetGlobalPredefinedTokens() {
1338
+ __globalPredefinedTokens = { ...DEFAULT_PREDEFINED_TOKENS };
1339
+ getOrCreateParser().clearCache();
1340
+ }
1341
+ function parseStyle(value) {
1342
+ let str;
1343
+ if (typeof value === "string") str = value;
1344
+ else if (typeof value === "number") str = String(value);
1345
+ else str = "";
1346
+ return getOrCreateParser().process(str);
1347
+ }
1348
+ const RE_CUSTOM_PROPERTY_REF = /\$[a-zA-Z_$]/;
1349
+ function resolveCustomProperties(value) {
1350
+ if (!RE_CUSTOM_PROPERTY_REF.test(value)) return value;
1351
+ return parseStyle(value).output || value;
1352
+ }
1353
+ function isDroppedValue(value) {
1354
+ return parseStyle(value).groups.every((group) => group.all.length === 0);
1355
+ }
1356
+ function parseColor(val, ignoreError = false) {
1357
+ if (typeof val !== "string") val = String(val ?? "");
1358
+ val = val.trim();
1359
+ if (!val) return {};
1360
+ const isSimpleColor = isSimpleColorFast(val);
1361
+ let firstColor;
1362
+ if (isSimpleColor) firstColor = val;
1363
+ else {
1364
+ const extractedColor = parseStyle(val).groups.find((g) => g.colors.length)?.colors[0];
1365
+ if (!extractedColor) {
1366
+ if (!ignoreError && devMode && colorWarningCount < MAX_COLOR_WARNINGS) {
1367
+ console.warn("[Tasty] unable to parse color:", val);
1368
+ colorWarningCount++;
1369
+ if (colorWarningCount === MAX_COLOR_WARNINGS) console.warn("[Tasty] color parsing warnings will be suppressed from now on");
1370
+ }
1371
+ return {};
1372
+ }
1373
+ firstColor = extractedColor;
1374
+ }
1375
+ const faded = parseAlphaMix(firstColor);
1376
+ const baseColor = faded ? faded.color : firstColor;
1377
+ const nameMatch = baseColor.match(COLOR_VAR_PATTERN);
1378
+ let opacity;
1379
+ if (faded) {
1380
+ const v = parseFloat(faded.percentage);
1381
+ if (!isNaN(v)) opacity = v;
1382
+ } else if (baseColor.startsWith("rgb") || baseColor.startsWith("hsl") || baseColor.startsWith("lch") || baseColor.startsWith("oklch")) {
1383
+ const alphaMatch = baseColor.match(RGB_ALPHA_PATTERN);
1384
+ if (alphaMatch) {
1385
+ const v = parseFloat(alphaMatch[1]);
1386
+ if (!isNaN(v)) opacity = v * 100;
1387
+ }
1388
+ }
1389
+ return {
1390
+ color: firstColor,
1391
+ name: nameMatch ? nameMatch[1] : void 0,
1392
+ opacity
1393
+ };
1394
+ }
1395
+ function filterMods(mods, allowedMods) {
1396
+ const filtered = [];
1397
+ for (const mod of mods) if (allowedMods.includes(mod)) filtered.push(mod);
1398
+ return filtered;
1399
+ }
1400
+ const _innerCache = /* @__PURE__ */ new WeakMap();
1401
+ const _topLevelCache = /* @__PURE__ */ new WeakMap();
1402
+ function stringifyStyles(styles) {
1403
+ if (styles == null || typeof styles !== "object") return "";
1404
+ const cached = _topLevelCache.get(styles);
1405
+ if (cached !== void 0) return cached;
1406
+ const obj = styles;
1407
+ const keys = Object.keys(obj).sort();
1408
+ const parts = [];
1409
+ for (const k of keys) {
1410
+ const v = obj[k];
1411
+ if (v === void 0 || typeof v === "function" || typeof v === "symbol") continue;
1412
+ const c0 = k.charCodeAt(0);
1413
+ const needsInnerSort = (c0 >= 65 && c0 <= 90 || c0 === 38) && v && typeof v === "object" && !Array.isArray(v);
1414
+ let sv;
1415
+ if (needsInnerSort) {
1416
+ sv = _innerCache.get(v);
1417
+ if (sv === void 0) {
1418
+ const innerObj = v;
1419
+ const innerKeys = Object.keys(innerObj).sort();
1420
+ const innerParts = [];
1421
+ for (const ik of innerKeys) {
1422
+ const ivs = JSON.stringify(innerObj[ik]);
1423
+ if (ivs !== void 0) innerParts.push(JSON.stringify(ik) + ":" + ivs);
1424
+ }
1425
+ sv = "{" + innerParts.join(",") + "}";
1426
+ _innerCache.set(v, sv);
1427
+ }
1428
+ } else sv = JSON.stringify(v);
1429
+ parts.push(JSON.stringify(k) + ":" + sv);
1430
+ }
1431
+ const result = "{" + parts.join(",") + "}";
1432
+ _topLevelCache.set(styles, result);
1433
+ return result;
1434
+ }
1435
+ //#endregion
1436
+ //#region src/utils/function-color.ts
1437
+ const RE_FUNC_NAME = /^([a-z][a-z0-9-]*)\s*\(/i;
1438
+ const RE_COLOR_OUT = /^(?:rgb|hsl|hwb|lab|lch|oklab|oklch|color)\(|^#|^var\(--/i;
1439
+ function resolveFunctionColor(str) {
1440
+ const m = RE_FUNC_NAME.exec(str);
1441
+ if (!m) return null;
1442
+ const name = m[1].toLowerCase();
1443
+ getGlobalParser();
1444
+ if (!(name in getGlobalParseFunctions())) return null;
1445
+ const out = getGlobalParser().process(str).output;
1446
+ if (!out || !RE_COLOR_OUT.test(out)) return null;
1447
+ return out;
1448
+ }
1449
+ //#endregion
1450
+ //#region src/utils/colors.ts
1451
+ function color(name, opacity = 1) {
1452
+ if (opacity !== 1) return mixColorAlpha(`var(--${name}-color)`, alphaToPercentage(opacity));
1453
+ return `var(--${name}-color)`;
1454
+ }
1455
+ //#endregion
1456
+ export { getRgbValuesFromRgbaString as A, createColorFunc as C, isTransparent as D, makeEmptyDetails as E, normalizeDslName as F, toSnakeCase as I, CSS_WIDE_KEYWORDS as L, hslToRgbValues as M, isColorKeyword as N, parseAlphaMix as O, strToRgb as P, RE_NUMBER as R, okhslPlugin as S, Lru as T, setGlobalPredefinedTokens as _, customFunction as a, okhstPlugin as b, getGlobalParser as c, normalizeColorTokenValue as d, parseColor as f, resolveCustomProperties as g, resetGlobalPredefinedTokens as h, DIRECTIONS as i, hexToRgb as j, getNamedColorHex as k, getGlobalPredefinedTokens as l, resetGlobalParseFunctions as m, resolveFunctionColor as n, filterMods as o, parseStyle as p, CUSTOM_UNITS as r, getGlobalParseFunctions as s, color as t, isDroppedValue as u, stringifyStyles as v, StyleParser as w, okhslFunction as x, okhstFunction as y, RE_RAW_UNIT as z };
1457
+
1458
+ //# sourceMappingURL=dsl-CsFl9LGn.js.map