@tenphi/tasty 0.0.0-snapshot.b49e579 → 0.0.0-snapshot.b6cc3cd

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 (49) hide show
  1. package/README.md +1 -0
  2. package/dist/{babel-R2qT7yLN.d.ts → babel-D8dm92E_.d.ts} +2 -2
  3. package/dist/{collector-D8o4Wdq-.d.ts → collector-BFuqdF2F.d.ts} +2 -2
  4. package/dist/{collector-D6fpuCdp.js → collector-Di3C8btw.js} +3 -3
  5. package/dist/{collector-D6fpuCdp.js.map → collector-Di3C8btw.js.map} +1 -1
  6. package/dist/{config-Bxme0Moq.js → config-BrDt11hO.js} +559 -115
  7. package/dist/config-BrDt11hO.js.map +1 -0
  8. package/dist/{config-De8L9NWM.d.ts → config-DH7I0Ggx.d.ts} +73 -2
  9. package/dist/core/index.d.ts +5 -5
  10. package/dist/core/index.js +6 -6
  11. package/dist/{core-BR4waa0Q.js → core-YWn1zgh4.js} +6 -9
  12. package/dist/core-YWn1zgh4.js.map +1 -0
  13. package/dist/{css-writer-DB4ZVUYy.js → css-writer-CQYbT4g_.js} +3 -3
  14. package/dist/{css-writer-DB4ZVUYy.js.map → css-writer-CQYbT4g_.js.map} +1 -1
  15. package/dist/{format-rules-BXSRL8KZ.js → format-rules-DdmLdntR.js} +2 -2
  16. package/dist/{format-rules-BXSRL8KZ.js.map → format-rules-DdmLdntR.js.map} +1 -1
  17. package/dist/{hydrate-D_EWjD6z.js → hydrate-D2ivfS-B.js} +2 -2
  18. package/dist/{hydrate-D_EWjD6z.js.map → hydrate-D2ivfS-B.js.map} +1 -1
  19. package/dist/{index-DzGxoeyN.d.ts → index-DljBkZhV.d.ts} +59 -6
  20. package/dist/{index-KUYya3x7.d.ts → index-LC3O3Jj4.d.ts} +102 -2
  21. package/dist/index.d.ts +5 -5
  22. package/dist/index.js +62 -8
  23. package/dist/index.js.map +1 -1
  24. package/dist/{keyframes-DrUITLCz.js → keyframes-CoLLjBcd.js} +2 -2
  25. package/dist/{keyframes-DrUITLCz.js.map → keyframes-CoLLjBcd.js.map} +1 -1
  26. package/dist/{merge-styles-DLm4wdnb.d.ts → merge-styles-Cx_6ySBv.d.ts} +2 -2
  27. package/dist/{merge-styles-biRwSixM.js → merge-styles-bdh7-1uh.js} +2 -2
  28. package/dist/{merge-styles-biRwSixM.js.map → merge-styles-bdh7-1uh.js.map} +1 -1
  29. package/dist/{resolve-recipes-CBVdPz67.js → resolve-recipes-9JYSgubn.js} +3 -3
  30. package/dist/{resolve-recipes-CBVdPz67.js.map → resolve-recipes-9JYSgubn.js.map} +1 -1
  31. package/dist/ssr/astro-client.js +1 -1
  32. package/dist/ssr/astro.js +3 -3
  33. package/dist/ssr/index.d.ts +1 -1
  34. package/dist/ssr/index.js +3 -3
  35. package/dist/ssr/next.d.ts +1 -1
  36. package/dist/ssr/next.js +4 -4
  37. package/dist/static/index.d.ts +2 -2
  38. package/dist/static/index.js +1 -1
  39. package/dist/zero/babel.d.ts +1 -1
  40. package/dist/zero/babel.js +4 -4
  41. package/dist/zero/index.d.ts +1 -1
  42. package/dist/zero/index.js +1 -1
  43. package/dist/zero/next.d.ts +1 -1
  44. package/docs/configuration.md +128 -1
  45. package/docs/dsl.md +37 -11
  46. package/docs/injector.md +11 -0
  47. package/package.json +4 -4
  48. package/dist/config-Bxme0Moq.js.map +0 -1
  49. package/dist/core-BR4waa0Q.js.map +0 -1
@@ -1287,30 +1287,69 @@ function strToColorSpace(color) {
1287
1287
  return result;
1288
1288
  }
1289
1289
  /**
1290
- * Apply an alpha value to a whole color.
1291
- *
1292
- * `color-mix()` against `transparent` is how opacity is applied to every color
1293
- * Tasty emits. Mixing premultiplied against a fully transparent color leaves the
1294
- * channels untouched and sets the alpha to the given percentage, so the result
1295
- * is the same color the equivalent `<func>(… / <alpha>)` would produce — but it
1296
- * needs nothing from the color except that it *is* a color. A `color-mix()`, a
1297
- * `light-dark()`, a `currentcolor`, a `--name-color` written by hand-authored
1298
- * CSS with no companion variable: all of them work, where writing into a channel
1299
- * slot requires components the engine may have no way to compute.
1300
- *
1301
- * The mixing space is always `oklab`, regardless of the configured
1302
- * {@link ColorSpace}: alpha application is space-independent, and oklab is
1303
- * unbounded, so a wide-gamut color survives the round trip that `in srgb` would
1304
- * clamp.
1290
+ * Set the alpha of a whole color, replacing any it already carries.
1291
+ *
1292
+ * CSS relative color syntax is how opacity is applied to every color Tasty
1293
+ * emits. `oklch(from <color> l c h / <alpha>)` copies the channels over and
1294
+ * writes the alpha slot, which needs nothing from the color except that it *is*
1295
+ * a color: a `color-mix()`, a `light-dark()`, a `currentcolor`, a
1296
+ * `--name-color` written by hand-authored CSS with no companion variable — all
1297
+ * of them work, where writing into a channel slot directly requires components
1298
+ * the engine may have no way to compute.
1299
+ *
1300
+ * Alpha is *replaced*, not composed. A token holding `rgb(255 0 0 / .8)` faded
1301
+ * to `.5` is alpha `.5`, matching what the channel-components form did and what
1302
+ * a statically-known color still does. `color-mix()` against `transparent`
1303
+ * cannot do this — it would multiply the two to `.4`.
1304
+ *
1305
+ * The alpha slot takes a `<number>` or a `<percentage>`, so an opacity custom
1306
+ * property passes straight through in whichever form the author declared it.
1307
+ *
1308
+ * The space is always `oklch`, regardless of the configured {@link ColorSpace}:
1309
+ * it is unbounded, so a wide-gamut color survives the round trip that a
1310
+ * gamut-limited space would clamp, and it is the space the computed value used
1311
+ * to be reported in. Channels are copied rather than interpolated, so the polar
1312
+ * form costs nothing even for an achromatic color, whose hue is carried through
1313
+ * untouched.
1314
+ */
1315
+ function overrideColorAlpha(color, alpha) {
1316
+ return `oklch(from ${color} l c h / ${alpha})`;
1317
+ }
1318
+ /**
1319
+ * Compose an alpha onto a color, multiplying with any it already carries.
1320
+ *
1321
+ * This is the counterpart to {@link overrideColorAlpha}, and the difference is
1322
+ * the point. A design token names a color, so fading it *sets* its alpha. But
1323
+ * `currentcolor` is the color an element **inherits**, which an ancestor may
1324
+ * already have faded — `#current.4` there means "40% of what reaches me", and a
1325
+ * nested `#current.18` under it composes to `.072`. Design systems build ramps
1326
+ * out of exactly that, so `#current` composes and a token replaces.
1327
+ *
1328
+ * `color-mix()` against `transparent` is what composes: mixing premultiplied
1329
+ * leaves the channels alone and multiplies the alphas. Its percentage slot takes
1330
+ * no `<number>`, so a `$prop` alpha has to be scaled — which is why an opacity
1331
+ * property used as `#current.$prop` has to hold a unitless number, where a token
1332
+ * accepts either form.
1305
1333
  */
1306
1334
  function mixColorAlpha(color, percentage) {
1307
1335
  return `color-mix(in oklab, ${color} ${percentage}, transparent)`;
1308
1336
  }
1309
1337
  /**
1310
- * Matches what {@link mixColorAlpha} builds, capturing the color and the alpha
1311
- * percentage so the two can be recovered separately.
1338
+ * Matches what {@link overrideColorAlpha} builds. The first group is greedy so a
1339
+ * nested override splits on its outermost layer.
1312
1340
  */
1313
- const RE_ALPHA_MIX = /^color-mix\(in oklab, (.+) ([^\s,]+), transparent\)$/;
1341
+ const RE_ALPHA_OVERRIDE = /^oklch\(from (.+) l c h \/ (.+)\)$/;
1342
+ /**
1343
+ * Split what {@link overrideColorAlpha} builds back into the color it faded and
1344
+ * the alpha, or `null` when the value is not one of those.
1345
+ */
1346
+ function parseAlphaOverride(value) {
1347
+ const match = value.match(RE_ALPHA_OVERRIDE);
1348
+ return match ? {
1349
+ color: match[1],
1350
+ alpha: match[2]
1351
+ } : null;
1352
+ }
1314
1353
  /** Channel names of each color space, in `<func>()` argument order. */
1315
1354
  const COLOR_SPACE_CHANNELS = {
1316
1355
  rgb: "r g b",
@@ -1369,8 +1408,8 @@ function getColorSpaceComponents(color) {
1369
1408
  */
1370
1409
  function convertColorChainToComponentChain(colorValue) {
1371
1410
  const suffix = getColorSpaceSuffix();
1372
- const alphaMix = colorValue.match(RE_ALPHA_MIX);
1373
- if (alphaMix) return convertColorChainToComponentChain(alphaMix[1].trim());
1411
+ const faded = parseAlphaOverride(colorValue);
1412
+ if (faded) return convertColorChainToComponentChain(faded.color);
1374
1413
  const componentVarMatch = colorValue.match(/^(?:rgb|hsl|oklch)a?\(\s*(var\(--[a-z0-9-]+-color-(?:rgb|hsl|oklch)\))\s*\//);
1375
1414
  if (componentVarMatch) return componentVarMatch[1];
1376
1415
  if (colorFuncName(colorValue)) {
@@ -1460,17 +1499,42 @@ const finalizeGroup = (d, parts) => {
1460
1499
  //#endregion
1461
1500
  //#region src/parser/classify.ts
1462
1501
  /**
1463
- * Convert an opacity suffix (`.5`, `.05`, `.$disabled`) to the percentage
1464
- * `color-mix()` needs.
1502
+ * Convert an opacity suffix to the alpha value it denotes.
1503
+ *
1504
+ * The authored digits are kept verbatim — `.07` stays `.07` rather than being
1505
+ * multiplied into `7.000000000000001%` — and a `$prop` suffix passes the
1506
+ * reference straight through, so it works whether the property holds a
1507
+ * `<number>` or a `<percentage>`. Both are what the alpha slot accepts.
1508
+ */
1509
+ function alphaSuffixToAlpha(rawAlpha) {
1510
+ if (rawAlpha.startsWith("$")) return `var(--${rawAlpha.slice(1)})`;
1511
+ if (rawAlpha === "0") return "0";
1512
+ return `.${rawAlpha}`;
1513
+ }
1514
+ /** Apply an opacity suffix to a color, replacing any alpha it already carries. */
1515
+ function fadeColor(color, rawAlpha) {
1516
+ return overrideColorAlpha(color, alphaSuffixToAlpha(rawAlpha));
1517
+ }
1518
+ /**
1519
+ * Convert an opacity suffix to the percentage `color-mix()` needs, by shifting
1520
+ * the decimal point rather than multiplying: `.07` is `7%`, not the
1521
+ * `7.000000000000001%` that `parseFloat('.07') * 100` produces.
1465
1522
  */
1466
1523
  function alphaSuffixToPercentage(rawAlpha) {
1467
1524
  if (rawAlpha.startsWith("$")) return `calc(var(--${rawAlpha.slice(1)}) * 100%)`;
1468
1525
  if (rawAlpha === "0") return "0%";
1469
- return `${parseFloat("." + rawAlpha) * 100}%`;
1526
+ const digits = rawAlpha.length === 1 ? `${rawAlpha}0` : rawAlpha;
1527
+ const whole = String(Number(digits.slice(0, 2)));
1528
+ const fraction = digits.slice(2);
1529
+ return `${fraction ? `${whole}.${fraction}` : whole}%`;
1470
1530
  }
1471
- /** Apply an opacity suffix to a color. */
1472
- function mixAlpha(color, rawAlpha) {
1473
- return mixColorAlpha(color, alphaSuffixToPercentage(rawAlpha));
1531
+ /**
1532
+ * Apply an opacity suffix to `currentcolor`, composing with any alpha an
1533
+ * ancestor already applied. See {@link mixColorAlpha} for why this differs from
1534
+ * how a token is faded.
1535
+ */
1536
+ function fadeCurrentColor(rawAlpha) {
1537
+ return mixColorAlpha("currentcolor", alphaSuffixToPercentage(rawAlpha));
1474
1538
  }
1475
1539
  /**
1476
1540
  * Whether parsed function arguments hold a color. Colors reach either the color
@@ -1585,7 +1649,7 @@ function classify(raw, opts, recurse) {
1585
1649
  const currentAlphaMatch = token.match(/^#current\.(\$[a-z_][a-z0-9-_]*|[0-9]+)$/i);
1586
1650
  if (currentAlphaMatch) return {
1587
1651
  bucket: 0,
1588
- processed: mixAlpha("currentcolor", currentAlphaMatch[1])
1652
+ processed: fadeCurrentColor(currentAlphaMatch[1])
1589
1653
  };
1590
1654
  if (token[0] === "$" || token[0] === "#") {
1591
1655
  const predefinedTokens = getGlobalPredefinedTokens();
@@ -1609,7 +1673,7 @@ function classify(raw, opts, recurse) {
1609
1673
  const lowerFunc = funcName.toLowerCase();
1610
1674
  if (DERIVED_COLOR_FUNCS.has(lowerFunc)) return {
1611
1675
  bucket: 0,
1612
- processed: mixAlpha(classify(foldDslCase(resolvedValue), opts, recurse).processed, rawAlpha)
1676
+ processed: fadeColor(classify(foldDslCase(resolvedValue), opts, recurse).processed, rawAlpha)
1613
1677
  };
1614
1678
  const isCustomFunc = !!(opts.functions && lowerFunc in opts.functions && !COLOR_FUNCS.has(lowerFunc) && !COLOR_FUNCS.has(funcName.replace(/a$/i, "").toLowerCase()));
1615
1679
  const normalizedFunc = isCustomFunc ? lowerFunc : funcName.replace(/a$/i, "").toLowerCase();
@@ -1700,7 +1764,7 @@ function classify(raw, opts, recurse) {
1700
1764
  const [, base, rawAlpha] = alphaMatch;
1701
1765
  return {
1702
1766
  bucket: 0,
1703
- processed: mixAlpha(`var(--${base}-color)`, rawAlpha)
1767
+ processed: fadeColor(`var(--${base}-color)`, rawAlpha)
1704
1768
  };
1705
1769
  }
1706
1770
  const name = token.slice(1);
@@ -2390,15 +2454,15 @@ function parseColor(val, ignoreError = false) {
2390
2454
  }
2391
2455
  firstColor = extractedColor;
2392
2456
  }
2393
- const alphaMix = firstColor.match(RE_ALPHA_MIX);
2394
- const baseColor = alphaMix ? alphaMix[1].trim() : firstColor;
2457
+ const faded = parseAlphaOverride(firstColor);
2458
+ const baseColor = faded ? faded.color : firstColor;
2395
2459
  let nameMatch = baseColor.match(COLOR_VAR_PATTERN);
2396
2460
  if (!nameMatch) nameMatch = baseColor.match(COLOR_VAR_COMPONENTS_PATTERN);
2397
2461
  let opacity;
2398
- if (alphaMix) {
2399
- const percentage = alphaMix[2];
2400
- const v = parseFloat(percentage);
2401
- if (percentage.endsWith("%") && !isNaN(v)) opacity = v;
2462
+ if (faded) {
2463
+ const { alpha } = faded;
2464
+ const v = parseFloat(alpha);
2465
+ if (!isNaN(v)) opacity = alpha.endsWith("%") ? v : v * 100;
2402
2466
  } else if (baseColor.startsWith("rgb") || baseColor.startsWith("hsl") || baseColor.startsWith("lch") || baseColor.startsWith("oklch")) {
2403
2467
  const alphaMatch = baseColor.match(RGB_ALPHA_PATTERN);
2404
2468
  if (alphaMatch) {
@@ -3359,6 +3423,217 @@ function rscClassRegexGlobal(prefix) {
3359
3423
  return new RegExp(`\\.(${escapeRegex(prefix)}[a-z0-9]+)\\.\\1`, "g");
3360
3424
  }
3361
3425
  //#endregion
3426
+ //#region src/utils/warnings.ts
3427
+ const PREFIX = "[Tasty]";
3428
+ function warn(...args) {
3429
+ console.warn(PREFIX, ...args);
3430
+ }
3431
+ //#endregion
3432
+ //#region src/injector/batch.ts
3433
+ /**
3434
+ * Deferred CSSOM writes ("batched injection").
3435
+ *
3436
+ * Every `insertRule()` on a live stylesheet invalidates style for the sheet's
3437
+ * scope, so Blink recalculates style the next time anything reads layout or
3438
+ * computed style. When components inject during React's render phase and other
3439
+ * components read layout in the same pass, the two interleave:
3440
+ *
3441
+ * inject -> read (forced recalc) -> inject -> read (forced recalc) -> ...
3442
+ *
3443
+ * Batching moves every sheet write out from between those reads. Writes are
3444
+ * queued in FIFO order and drained in one go, so the tree is invalidated once
3445
+ * per flush instead of once per component.
3446
+ *
3447
+ * ## Ordering
3448
+ *
3449
+ * A single queue holds *all* writes — component rules, global rules, keyframes,
3450
+ * `@property`, `@font-face`, `@counter-style`, `@function` and raw CSS. Draining
3451
+ * it in insertion order keeps the sheet byte-identical to unbatched output,
3452
+ * which matters because equal-specificity rules resolve by document order.
3453
+ *
3454
+ * ## Batch windows — why queuing is safe
3455
+ *
3456
+ * Deferring a write past React's layout phase would let a `useLayoutEffect`
3457
+ * measure an element whose rules are not in the sheet yet, reading the unstyled
3458
+ * box. `<TastyBatchProvider>` closes that hole by opening a *window* during its
3459
+ * render and closing it — flushing — in its `useInsertionEffect`, which React
3460
+ * runs in the mutation phase, before any layout effect:
3461
+ *
3462
+ * provider renders -> window OPEN
3463
+ * children render -> injections queued
3464
+ * provider insertionEffect -> FLUSH, window CLOSED
3465
+ * layout effects run -> rules are in the sheet
3466
+ *
3467
+ * So in the default (`batchInjection: true`) mode a write is only ever queued
3468
+ * inside a commit whose flush is already guaranteed by that same commit. Every
3469
+ * injection outside a window — a deep update the provider did not re-render
3470
+ * for, a `useLayoutEffect` that injects, an event handler, an async callback —
3471
+ * is written straight through, exactly as with batching off.
3472
+ *
3473
+ * `batchInjection: 'always'` opts out of the gate and queues unconditionally.
3474
+ * That wins on more commits, at the cost of the measurement hazard above.
3475
+ *
3476
+ * ## Flush points (earliest wins)
3477
+ *
3478
+ * 1. `<TastyBatchProvider>`'s `useInsertionEffect` — closes the window.
3479
+ * 2. A microtask — a backstop for a render that was aborted or suspended and
3480
+ * therefore never reached its insertion effect. An aborted render mounts
3481
+ * nothing, so nothing can measure what it queued. Microtasks also always
3482
+ * drain before paint, so styles are never visually missing.
3483
+ * 3. `flushStyles()` — explicit, and called internally by every injector read
3484
+ * API (`getCSSText`, `cleanup`, `gc`, `destroy`, ...).
3485
+ */
3486
+ /**
3487
+ * FIFO of pending writes. Drained with a moving `head` index rather than
3488
+ * `shift()` so a large batch stays O(n) instead of O(n²).
3489
+ */
3490
+ let queue = [];
3491
+ let head = 0;
3492
+ let microtaskScheduled = false;
3493
+ let flushing = false;
3494
+ /**
3495
+ * Whether a `<TastyBatchProvider>` has rendered in the current commit and will
3496
+ * therefore flush in its insertion effect, making it safe to queue a write.
3497
+ *
3498
+ * A flag rather than a depth count, because renders and insertion effects do
3499
+ * not pair up one-to-one. StrictMode double-invokes render but runs the
3500
+ * insertion effect once, so a counter ends the commit stuck above zero — and a
3501
+ * window that stays open past its commit turns the next provider-less commit
3502
+ * into `'always'` mode behind the user's back, which is exactly the measurement
3503
+ * hazard `true` exists to avoid.
3504
+ *
3505
+ * Clearing on the first close is safe with nested or sibling providers: React
3506
+ * finishes every render in a commit before running any insertion effect, so once
3507
+ * one closes, no further render-phase injection can arrive in that commit.
3508
+ */
3509
+ let windowOpen = false;
3510
+ /** Whether any window has ever been opened, i.e. a provider is in the tree. */
3511
+ let everOpened = false;
3512
+ /** Dev-only: warn at most once that batching is on with no provider mounted. */
3513
+ let warnedNoProvider = false;
3514
+ /**
3515
+ * Queue a sheet write.
3516
+ *
3517
+ * Returns a handle whose `cancel()` drops the write if the caller disposes
3518
+ * before the flush. The handle is intentionally tiny — one is allocated per
3519
+ * injected class, on the cache-miss path only.
3520
+ */
3521
+ function enqueueStyleWrite(run) {
3522
+ if (flushing) {
3523
+ run();
3524
+ return {
3525
+ run,
3526
+ cancelled: false,
3527
+ done: true
3528
+ };
3529
+ }
3530
+ const entry = {
3531
+ run,
3532
+ cancelled: false,
3533
+ done: false
3534
+ };
3535
+ queue.push(entry);
3536
+ scheduleMicrotaskFlush();
3537
+ return entry;
3538
+ }
3539
+ /** Whether any write is still waiting to hit a stylesheet. */
3540
+ function hasPendingStyleWrites() {
3541
+ return head < queue.length;
3542
+ }
3543
+ /**
3544
+ * Open a batch window. Called from `<TastyBatchProvider>`'s render, so every
3545
+ * descendant injection in this commit is covered by the provider's insertion
3546
+ * effect.
3547
+ *
3548
+ * Called during render on purpose: the window must be open before children
3549
+ * render. It is idempotent — so StrictMode's double render costs nothing — and
3550
+ * carries no other side effect. A render that is thrown away is recovered by the
3551
+ * microtask backstop.
3552
+ *
3553
+ * A no-op without a `document`. On the server there is no sheet to batch
3554
+ * against, and `useInsertionEffect` never runs, so nothing would ever close a
3555
+ * window this opened. Skipping it keeps the provider inert during SSR and RSC
3556
+ * instead of merely harmless.
3557
+ */
3558
+ function openBatchWindow() {
3559
+ if (typeof document === "undefined") return;
3560
+ windowOpen = true;
3561
+ everOpened = true;
3562
+ }
3563
+ /**
3564
+ * Close a batch window and flush. Called from the provider's
3565
+ * `useInsertionEffect`, i.e. after every render in the commit and before any
3566
+ * layout effect.
3567
+ */
3568
+ function closeBatchWindow() {
3569
+ windowOpen = false;
3570
+ flushStyles();
3571
+ }
3572
+ /** Whether a batch window is currently open. */
3573
+ function isBatchWindowOpen() {
3574
+ return windowOpen;
3575
+ }
3576
+ function scheduleMicrotaskFlush() {
3577
+ if (microtaskScheduled || flushing) return;
3578
+ microtaskScheduled = true;
3579
+ queueMicrotask(() => {
3580
+ microtaskScheduled = false;
3581
+ windowOpen = false;
3582
+ flushStyles();
3583
+ });
3584
+ }
3585
+ /**
3586
+ * Drain every pending sheet write, in insertion order.
3587
+ *
3588
+ * Safe to call when the queue is empty (the common case, so the guard comes
3589
+ * first) and safe to call re-entrantly: a nested `flushStyles()` is a no-op,
3590
+ * and work a draining write triggers is written in place by
3591
+ * `enqueueStyleWrite` rather than queued behind the rest of the batch.
3592
+ */
3593
+ function flushStyles() {
3594
+ if (head >= queue.length) return;
3595
+ if (flushing) return;
3596
+ flushing = true;
3597
+ try {
3598
+ while (head < queue.length) {
3599
+ const entry = queue[head++];
3600
+ if (entry.cancelled) {
3601
+ entry.done = true;
3602
+ continue;
3603
+ }
3604
+ entry.run();
3605
+ entry.done = true;
3606
+ }
3607
+ } finally {
3608
+ queue = [];
3609
+ head = 0;
3610
+ flushing = false;
3611
+ }
3612
+ }
3613
+ /**
3614
+ * Dev-only: `batchInjection: true` batches nothing unless a window opens, and no
3615
+ * window has ever opened, so no provider is in the tree. Called by the injector
3616
+ * the first time it declines to batch.
3617
+ */
3618
+ function warnBatchProviderMissing() {
3619
+ if (everOpened || warnedNoProvider || !isDevEnv()) return;
3620
+ warnedNoProvider = true;
3621
+ warn("[Tasty] batchInjection needs <TastyBatchProvider> mounted to batch.");
3622
+ }
3623
+ /**
3624
+ * Drop every pending write without applying it. Test helper — production code
3625
+ * should call `flushStyles()` instead.
3626
+ */
3627
+ function resetStyleBatch() {
3628
+ queue = [];
3629
+ head = 0;
3630
+ microtaskScheduled = false;
3631
+ flushing = false;
3632
+ windowOpen = false;
3633
+ everOpened = false;
3634
+ warnedNoProvider = false;
3635
+ }
3636
+ //#endregion
3362
3637
  //#region src/properties/property-type-resolver.ts
3363
3638
  /**
3364
3639
  * PropertyTypeResolver
@@ -4713,12 +4988,6 @@ scrollMarginStyle.__lookupStyles = [
4713
4988
  "scrollMarginInline"
4714
4989
  ];
4715
4990
  //#endregion
4716
- //#region src/utils/warnings.ts
4717
- const PREFIX = "[Tasty]";
4718
- function warn(...args) {
4719
- console.warn(PREFIX, ...args);
4720
- }
4721
- //#endregion
4722
4991
  //#region src/styles/scrollbar.ts
4723
4992
  /**
4724
4993
  * Standard CSS scrollbar styling via `scrollbar-width`, `scrollbar-color`,
@@ -5391,6 +5660,8 @@ var SheetManager = class {
5391
5660
  propertyTypeResolver: new PropertyTypeResolver(),
5392
5661
  usageMap: /* @__PURE__ */ new Map(),
5393
5662
  touchCount: 0,
5663
+ touchTick: -1,
5664
+ touchedTick: /* @__PURE__ */ new Set(),
5394
5665
  serverClassSyncIndex: 0,
5395
5666
  rscStylesScanned: false,
5396
5667
  injectionMode: this.detectInjectionMode(root)
@@ -6301,6 +6572,16 @@ function formatCounterStyleRule(name, descriptors) {
6301
6572
  //#endregion
6302
6573
  //#region src/injector/injector.ts
6303
6574
  /**
6575
+ * Placeholder `KeyframesInfo` for a cache entry reserved by a batched write and
6576
+ * not yet backed by a real rule. Only ever read through `entry.pending`, which
6577
+ * is checked before the info is used.
6578
+ */
6579
+ const EMPTY_KEYFRAMES_INFO = {
6580
+ name: "",
6581
+ ruleIndex: -3,
6582
+ sheetIndex: -3
6583
+ };
6584
+ /**
6304
6585
  * Extract class names from `<style data-tasty-rsc>` tags.
6305
6586
  * The doubled-specificity pattern `.tXXX.tXXX` makes extraction reliable.
6306
6587
  */
@@ -6361,6 +6642,56 @@ var StyleInjector = class {
6361
6642
  get _sheetManager() {
6362
6643
  return this.sheetManager;
6363
6644
  }
6645
+ /**
6646
+ * Whether sheet writes should be queued instead of applied immediately.
6647
+ *
6648
+ * Only ever true on the client: SSR collects CSS as text and the RSC path
6649
+ * returns it as strings, so neither has a live sheet to batch writes against.
6650
+ *
6651
+ * In the default `true` mode a write is only queued inside an open batch
6652
+ * window — a commit in which `<TastyBatchProvider>` rendered and will
6653
+ * therefore flush in its insertion effect, before any layout effect can
6654
+ * measure. Everything else falls through to a synchronous write, so enabling
6655
+ * the flag cannot make a `useLayoutEffect` read an unstyled element.
6656
+ * `'always'` drops the gate and accepts that trade for wider coverage.
6657
+ */
6658
+ get batching() {
6659
+ const mode = this.config.batchInjection;
6660
+ if (!mode || typeof document === "undefined") return false;
6661
+ if (mode === "always") return true;
6662
+ if (isBatchWindowOpen()) return true;
6663
+ warnBatchProviderMissing();
6664
+ return false;
6665
+ }
6666
+ /**
6667
+ * Apply a sheet write now, or queue it when batching is on.
6668
+ * Returns the queue handle when deferred, so the caller can cancel it if it
6669
+ * disposes before the flush.
6670
+ */
6671
+ writeSheet(task) {
6672
+ if (this.batching) return enqueueStyleWrite(task);
6673
+ task();
6674
+ return null;
6675
+ }
6676
+ /**
6677
+ * Insert a global (non-class) rule, honouring batching.
6678
+ *
6679
+ * `onApplied` records the caller's dedupe bookkeeping. When the write is
6680
+ * queued it runs eagerly, so a repeat call before the flush bails out instead
6681
+ * of queueing the same rule twice — the same reasoning as
6682
+ * `insertPropertyRule`'s eager marking. When written synchronously it runs
6683
+ * only on success, preserving the existing retry-on-failure behaviour.
6684
+ */
6685
+ writeGlobalRule(registry, rules, key, root, onApplied) {
6686
+ if (this.batching) {
6687
+ onApplied?.();
6688
+ enqueueStyleWrite(() => {
6689
+ this.sheetManager.insertGlobalRule(registry, rules, key, root);
6690
+ });
6691
+ return;
6692
+ }
6693
+ if (this.sheetManager.insertGlobalRule(registry, rules, key, root)) onApplied?.();
6694
+ }
6364
6695
  constructor(config = {}) {
6365
6696
  if (config.namePrefix !== void 0) validateNamePrefix(config.namePrefix);
6366
6697
  this.config = config;
@@ -6438,12 +6769,18 @@ var StyleInjector = class {
6438
6769
  };
6439
6770
  const cacheKey = options?.cacheKey;
6440
6771
  let className;
6441
- let isPreAllocated = false;
6442
6772
  if (cacheKey && registry.cacheKeyToClassName.has(cacheKey)) {
6443
6773
  className = registry.cacheKeyToClassName.get(cacheKey);
6444
6774
  const existingRuleInfo = registry.rules.get(className);
6445
- isPreAllocated = existingRuleInfo.ruleIndex === -1 && existingRuleInfo.sheetIndex === -1;
6446
- if (!isPreAllocated) {
6775
+ if (existingRuleInfo.ruleIndex === -3) {
6776
+ registry.refCounts.set(className, (registry.refCounts.get(className) || 0) + 1);
6777
+ if (registry.metrics) registry.metrics.hits++;
6778
+ return {
6779
+ className,
6780
+ dispose: () => this.dispose(className, registry)
6781
+ };
6782
+ }
6783
+ if (!(existingRuleInfo.ruleIndex === -1 && existingRuleInfo.sheetIndex === -1)) {
6447
6784
  const currentRefCount = registry.refCounts.get(className) || 0;
6448
6785
  registry.refCounts.set(className, currentRefCount + 1);
6449
6786
  if (registry.metrics) registry.metrics.hits++;
@@ -6484,39 +6821,70 @@ var StyleInjector = class {
6484
6821
  rootPrefix: void 0
6485
6822
  };
6486
6823
  });
6487
- if (this.config.autoPropertyTypes !== false) {
6488
- const resolver = registry.propertyTypeResolver;
6489
- const defined = registry.injectedProperties;
6490
- for (const rule of rulesToInsert) {
6491
- if (!rule.declarations) continue;
6492
- resolver.scanDeclarations(rule.declarations, (name) => defined.has(name), (name, syntax, initialValue) => {
6493
- this.property(name, {
6494
- syntax,
6495
- inherits: true,
6496
- initialValue,
6497
- root
6824
+ const applySheetWrite = () => {
6825
+ if (this.config.autoPropertyTypes !== false) {
6826
+ const resolver = registry.propertyTypeResolver;
6827
+ const defined = registry.injectedProperties;
6828
+ for (const rule of rulesToInsert) {
6829
+ if (!rule.declarations) continue;
6830
+ resolver.scanDeclarations(rule.declarations, (name) => defined.has(name), (name, syntax, initialValue) => {
6831
+ this.property(name, {
6832
+ syntax,
6833
+ inherits: true,
6834
+ initialValue,
6835
+ root
6836
+ });
6498
6837
  });
6499
- });
6838
+ }
6500
6839
  }
6501
- }
6502
- const ruleInfo = this.sheetManager.insertRule(registry, rulesToInsert, className, root);
6503
- if (!ruleInfo) {
6504
- if (registry.metrics) registry.metrics.misses++;
6840
+ const ruleInfo = this.sheetManager.insertRule(registry, rulesToInsert, className, root);
6841
+ if (!ruleInfo) {
6842
+ if (registry.metrics) registry.metrics.misses++;
6843
+ return null;
6844
+ }
6845
+ registry.rules.set(className, ruleInfo);
6846
+ if (cacheKey) registry.cacheKeyToClassName.set(cacheKey, className);
6847
+ if (registry.metrics) {
6848
+ registry.metrics.totalInsertions++;
6849
+ registry.metrics.misses++;
6850
+ }
6851
+ return ruleInfo;
6852
+ };
6853
+ if (this.batching) {
6854
+ registry.rules.set(className, {
6855
+ className,
6856
+ ruleIndex: -3,
6857
+ sheetIndex: -3
6858
+ });
6859
+ if (cacheKey) registry.cacheKeyToClassName.set(cacheKey, className);
6860
+ registry.refCounts.set(className, 1);
6861
+ const queued = enqueueStyleWrite(() => {
6862
+ if (applySheetWrite()) return;
6863
+ registry.rules.set(className, {
6864
+ className,
6865
+ ruleIndex: -1,
6866
+ sheetIndex: -1
6867
+ });
6868
+ });
6505
6869
  return {
6506
6870
  className,
6507
- dispose: () => {}
6871
+ dispose: () => {
6872
+ if (!queued.done && registry.refCounts.get(className) === 1 && registry.rules.get(className)?.ruleIndex === -3) {
6873
+ queued.cancelled = true;
6874
+ registry.rules.delete(className);
6875
+ if (cacheKey) registry.cacheKeyToClassName.delete(cacheKey);
6876
+ registry.refCounts.set(className, 0);
6877
+ return;
6878
+ }
6879
+ this.dispose(className, registry);
6880
+ }
6508
6881
  };
6509
6882
  }
6883
+ if (!applySheetWrite()) return {
6884
+ className,
6885
+ dispose: () => {}
6886
+ };
6510
6887
  registry.refCounts.set(className, 1);
6511
- if (isPreAllocated) registry.rules.set(className, ruleInfo);
6512
- else {
6513
- registry.rules.set(className, ruleInfo);
6514
- if (cacheKey) registry.cacheKeyToClassName.set(cacheKey, className);
6515
- }
6516
- if (registry.metrics) {
6517
- registry.metrics.totalInsertions++;
6518
- registry.metrics.misses++;
6519
- }
6520
6888
  return {
6521
6889
  className,
6522
6890
  dispose: () => this.dispose(className, registry)
@@ -6531,24 +6899,41 @@ var StyleInjector = class {
6531
6899
  const root = options?.root || document;
6532
6900
  const registry = this.sheetManager.getRegistry(root);
6533
6901
  if (!rules || rules.length === 0) return { dispose: () => {} };
6534
- if (this.config.autoPropertyTypes !== false) {
6535
- const resolver = registry.propertyTypeResolver;
6536
- const defined = registry.injectedProperties;
6537
- for (const rule of rules) {
6538
- if (!rule.declarations) continue;
6539
- resolver.scanDeclarations(rule.declarations, (name) => defined.has(name), (name, syntax, initialValue) => {
6540
- this.property(name, {
6541
- syntax,
6542
- inherits: true,
6543
- initialValue,
6544
- root
6902
+ const key = `global:${this.globalRuleCounter++}`;
6903
+ const applyWrite = () => {
6904
+ if (this.config.autoPropertyTypes !== false) {
6905
+ const resolver = registry.propertyTypeResolver;
6906
+ const defined = registry.injectedProperties;
6907
+ for (const rule of rules) {
6908
+ if (!rule.declarations) continue;
6909
+ resolver.scanDeclarations(rule.declarations, (name) => defined.has(name), (name, syntax, initialValue) => {
6910
+ this.property(name, {
6911
+ syntax,
6912
+ inherits: true,
6913
+ initialValue,
6914
+ root
6915
+ });
6545
6916
  });
6546
- });
6917
+ }
6547
6918
  }
6919
+ const inserted = this.sheetManager.insertGlobalRule(registry, rules, key, root);
6920
+ if (registry.metrics) registry.metrics.totalInsertions++;
6921
+ return inserted;
6922
+ };
6923
+ if (this.batching) {
6924
+ let info = null;
6925
+ const queued = enqueueStyleWrite(() => {
6926
+ info = applyWrite();
6927
+ });
6928
+ return { dispose: () => {
6929
+ if (!queued.done) {
6930
+ queued.cancelled = true;
6931
+ return;
6932
+ }
6933
+ if (info) this.sheetManager.deleteGlobalRule(registry, key);
6934
+ } };
6548
6935
  }
6549
- const key = `global:${this.globalRuleCounter++}`;
6550
- const info = this.sheetManager.insertGlobalRule(registry, rules, key, root);
6551
- if (registry.metrics) registry.metrics.totalInsertions++;
6936
+ const info = applyWrite();
6552
6937
  return { dispose: () => {
6553
6938
  if (info) this.sheetManager.deleteGlobalRule(registry, key);
6554
6939
  } };
@@ -6560,12 +6945,24 @@ var StyleInjector = class {
6560
6945
  */
6561
6946
  injectRawCSS(css, options) {
6562
6947
  const root = options?.root || document;
6563
- return this.sheetManager.injectRawCSS(css, root);
6948
+ if (!this.batching) return this.sheetManager.injectRawCSS(css, root);
6949
+ let result = null;
6950
+ const queued = enqueueStyleWrite(() => {
6951
+ result = this.sheetManager.injectRawCSS(css, root);
6952
+ });
6953
+ return { dispose: () => {
6954
+ if (!queued.done) {
6955
+ queued.cancelled = true;
6956
+ return;
6957
+ }
6958
+ result?.dispose();
6959
+ } };
6564
6960
  }
6565
6961
  /**
6566
6962
  * Get raw CSS text for SSR
6567
6963
  */
6568
6964
  getRawCSSText(options) {
6965
+ flushStyles();
6569
6966
  const root = options?.root || document;
6570
6967
  return this.sheetManager.getRawCSSText(root);
6571
6968
  }
@@ -6602,6 +6999,7 @@ var StyleInjector = class {
6602
6999
  * Force bulk cleanup of unused styles
6603
7000
  */
6604
7001
  cleanup(root) {
7002
+ flushStyles();
6605
7003
  const registry = this.sheetManager.getRegistry(root || document);
6606
7004
  this.sheetManager.forceCleanup(registry);
6607
7005
  }
@@ -6609,6 +7007,7 @@ var StyleInjector = class {
6609
7007
  * Get CSS text from all sheets (for SSR)
6610
7008
  */
6611
7009
  getCSSText(options) {
7010
+ flushStyles();
6612
7011
  const root = options?.root || document;
6613
7012
  const registry = this.sheetManager.getRegistry(root);
6614
7013
  return this.sheetManager.getCSSText(registry);
@@ -6617,6 +7016,7 @@ var StyleInjector = class {
6617
7016
  * Get CSS only for the provided tasty classNames (e.g., ["t0","t3"])
6618
7017
  */
6619
7018
  getCSSTextForClasses(classNames, options) {
7019
+ flushStyles();
6620
7020
  const root = options?.root || document;
6621
7021
  const registry = this.sheetManager.getRegistry(root);
6622
7022
  const cssChunks = [];
@@ -6641,6 +7041,7 @@ var StyleInjector = class {
6641
7041
  * Get cache performance metrics
6642
7042
  */
6643
7043
  getMetrics(options) {
7044
+ flushStyles();
6644
7045
  const root = options?.root || document;
6645
7046
  const registry = this.sheetManager.getRegistry(root);
6646
7047
  return this.sheetManager.getMetrics(registry);
@@ -6720,7 +7121,7 @@ var StyleInjector = class {
6720
7121
  declarations
6721
7122
  };
6722
7123
  registry.injectedProperties.set(cssName, normalizePropertyDefinition(definition));
6723
- this.sheetManager.insertGlobalRule(registry, [rule], `property:${cacheKey}`, root);
7124
+ this.writeGlobalRule(registry, [rule], `property:${cacheKey}`, root);
6724
7125
  }
6725
7126
  /**
6726
7127
  * Check whether a given @property name was already injected by this injector.
@@ -6731,6 +7132,7 @@ var StyleInjector = class {
6731
7132
  * - `--name` → checks `--name` (legacy format)
6732
7133
  */
6733
7134
  isPropertyDefined(name, options) {
7135
+ flushStyles();
6734
7136
  const root = options?.root || document;
6735
7137
  const registry = this.sheetManager.getRegistry(root);
6736
7138
  const effectiveResult = getEffectiveDefinition(name, {});
@@ -6752,7 +7154,9 @@ var StyleInjector = class {
6752
7154
  selector: "@font-face",
6753
7155
  declarations: formatFontFaceDeclarations(family, descriptors)
6754
7156
  };
6755
- if (this.sheetManager.insertGlobalRule(registry, [rule], `fontface:${hash}`, root)) registry.injectedFontFaces.add(hash);
7157
+ this.writeGlobalRule(registry, [rule], `fontface:${hash}`, root, () => {
7158
+ registry.injectedFontFaces.add(hash);
7159
+ });
6756
7160
  }
6757
7161
  /**
6758
7162
  * Inject a CSS @counter-style rule.
@@ -6770,13 +7174,17 @@ var StyleInjector = class {
6770
7174
  const existingIsStrong = registry.injectedCounterStyles.get(name);
6771
7175
  if (existingIsStrong !== void 0) {
6772
7176
  if (isWeak || existingIsStrong === true) return;
6773
- this.sheetManager.deleteGlobalRule(registry, `counterstyle:${name}`);
7177
+ this.writeSheet(() => {
7178
+ this.sheetManager.deleteGlobalRule(registry, `counterstyle:${name}`);
7179
+ });
6774
7180
  }
6775
7181
  const rule = {
6776
7182
  selector: `@counter-style ${name}`,
6777
7183
  declarations: formatCounterStyleDeclarations(descriptors)
6778
7184
  };
6779
- if (this.sheetManager.insertGlobalRule(registry, [rule], `counterstyle:${name}`, root)) registry.injectedCounterStyles.set(name, !isWeak);
7185
+ this.writeGlobalRule(registry, [rule], `counterstyle:${name}`, root, () => {
7186
+ registry.injectedCounterStyles.set(name, !isWeak);
7187
+ });
6780
7188
  }
6781
7189
  /**
6782
7190
  * Inject a CSS @function rule (custom function).
@@ -6795,13 +7203,17 @@ var StyleInjector = class {
6795
7203
  const existingIsStrong = registry.injectedFunctions.get(cssName);
6796
7204
  if (existingIsStrong !== void 0) {
6797
7205
  if (isWeak || existingIsStrong === true) return;
6798
- this.sheetManager.deleteGlobalRule(registry, `function:${cssName}`);
7206
+ this.writeSheet(() => {
7207
+ this.sheetManager.deleteGlobalRule(registry, `function:${cssName}`);
7208
+ });
6799
7209
  }
6800
7210
  const rule = {
6801
7211
  selector: formatFunctionPrelude(name, definition.args, definition.returns),
6802
7212
  declarations: formatFunctionDeclarations(definition)
6803
7213
  };
6804
- if (this.sheetManager.insertGlobalRule(registry, [rule], `function:${cssName}`, root)) registry.injectedFunctions.set(cssName, !isWeak);
7214
+ this.writeGlobalRule(registry, [rule], `function:${cssName}`, root, () => {
7215
+ registry.injectedFunctions.set(cssName, !isWeak);
7216
+ });
6805
7217
  }
6806
7218
  /**
6807
7219
  * Inject keyframes and return object with toString() and dispose()
@@ -6839,29 +7251,53 @@ var StyleInjector = class {
6839
7251
  registry.keyframesNameToContent.set(providedName, contentHash);
6840
7252
  }
6841
7253
  } else actualName = makeKeyframeName(this.namePrefix, String(registry.keyframesCounter++));
6842
- const result = this.sheetManager.insertKeyframes(registry, steps, actualName, root);
6843
- if (!result) return {
6844
- toString: () => "",
6845
- dispose: () => {}
7254
+ const applyWrite = () => {
7255
+ const result = this.sheetManager.insertKeyframes(registry, steps, actualName, root);
7256
+ if (!result) return false;
7257
+ const { info, declarations } = result;
7258
+ if (this.config.autoPropertyTypes !== false && declarations) registry.propertyTypeResolver.scanDeclarations(declarations, (name) => registry.injectedProperties.has(name), (name, syntax, initialValue) => {
7259
+ this.property(name, {
7260
+ syntax,
7261
+ inherits: true,
7262
+ initialValue,
7263
+ root
7264
+ });
7265
+ });
7266
+ const entry = registry.keyframesCache.get(contentHash);
7267
+ if (entry) {
7268
+ entry.info = info;
7269
+ entry.pending = void 0;
7270
+ } else registry.keyframesCache.set(contentHash, {
7271
+ name: actualName,
7272
+ refCount: 1,
7273
+ info
7274
+ });
7275
+ if (registry.metrics) {
7276
+ registry.metrics.totalInsertions++;
7277
+ registry.metrics.misses++;
7278
+ }
7279
+ return true;
6846
7280
  };
6847
- const { info, declarations } = result;
6848
- if (this.config.autoPropertyTypes !== false && declarations) registry.propertyTypeResolver.scanDeclarations(declarations, (name) => registry.injectedProperties.has(name), (name, syntax, initialValue) => {
6849
- this.property(name, {
6850
- syntax,
6851
- inherits: true,
6852
- initialValue,
6853
- root
7281
+ if (this.batching) {
7282
+ const entry = {
7283
+ name: actualName,
7284
+ refCount: 1,
7285
+ info: EMPTY_KEYFRAMES_INFO
7286
+ };
7287
+ registry.keyframesCache.set(contentHash, entry);
7288
+ entry.pending = enqueueStyleWrite(() => {
7289
+ if (applyWrite()) return;
7290
+ if (registry.keyframesCache.get(contentHash) === entry) registry.keyframesCache.delete(contentHash);
6854
7291
  });
6855
- });
6856
- registry.keyframesCache.set(contentHash, {
6857
- name: actualName,
6858
- refCount: 1,
6859
- info
6860
- });
6861
- if (registry.metrics) {
6862
- registry.metrics.totalInsertions++;
6863
- registry.metrics.misses++;
7292
+ return {
7293
+ toString: () => actualName,
7294
+ dispose: () => this.disposeKeyframes(contentHash, registry)
7295
+ };
6864
7296
  }
7297
+ if (!applyWrite()) return {
7298
+ toString: () => "",
7299
+ dispose: () => {}
7300
+ };
6865
7301
  return {
6866
7302
  toString: () => actualName,
6867
7303
  dispose: () => this.disposeKeyframes(contentHash, registry)
@@ -6875,7 +7311,8 @@ var StyleInjector = class {
6875
7311
  if (!entry) return;
6876
7312
  entry.refCount--;
6877
7313
  if (entry.refCount <= 0) {
6878
- this.sheetManager.deleteKeyframes(registry, entry.info);
7314
+ if (entry.pending && !entry.pending.done) entry.pending.cancelled = true;
7315
+ else this.sheetManager.deleteKeyframes(registry, entry.info);
6879
7316
  registry.keyframesCache.delete(contentHash);
6880
7317
  for (const [name, hash] of registry.keyframesNameToContent.entries()) if (hash === contentHash) {
6881
7318
  registry.keyframesNameToContent.delete(name);
@@ -6900,6 +7337,11 @@ var StyleInjector = class {
6900
7337
  const root = options?.root || document;
6901
7338
  const registry = this.sheetManager.getRegistry(root);
6902
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);
6903
7345
  const parts = className.indexOf(" ") === -1 ? [className] : className.split(" ");
6904
7346
  for (const cls of parts) {
6905
7347
  if (!this.classRegex.test(cls)) continue;
@@ -6940,6 +7382,7 @@ var StyleInjector = class {
6940
7382
  * @returns Number of styles evicted.
6941
7383
  */
6942
7384
  gc(options) {
7385
+ flushStyles();
6943
7386
  if (typeof document === "undefined") return 0;
6944
7387
  if (this.pendingGCHandle != null) {
6945
7388
  if (typeof cancelIdleCallback !== "undefined") cancelIdleCallback(this.pendingGCHandle);
@@ -6989,6 +7432,7 @@ var StyleInjector = class {
6989
7432
  * Destroy all resources for a root
6990
7433
  */
6991
7434
  destroy(root) {
7435
+ flushStyles();
6992
7436
  const targetRoot = root || document;
6993
7437
  this.sheetManager.cleanup(targetRoot);
6994
7438
  if (this.pendingGCHandle != null && !this.sheetManager.hasActiveRoots()) {
@@ -12437,6 +12881,6 @@ function resetConfig() {
12437
12881
  delete storage[GLOBAL_INJECTOR_KEY];
12438
12882
  }
12439
12883
  //#endregion
12440
- export { SheetManager as $, mixColorAlpha as $t, FLOW_STYLES as A, registerFunctionPolyfill as At, createStateParserContext as B, stringifyStyles as Bt, BASE_STYLES as C, LAYOUT_CHUNK_STYLES as Ct, COLOR_STYLES as D, formatFunctionRule as Dt, BLOCK_STYLES as E, extractLocalFunctions as Et, hasPipelineCacheEntry as F, getGlobalParser as Ft, StyleInjector as G, createColorFunc as Gt, extractPredefinedStateRefs as H, okhstPlugin as Ht, isSelector as I, getGlobalPredefinedTokens as It, hasLocalCounterStyle as J, colorInitialValueToComponents as Jt, extractLocalCounterStyle as K, isDevEnv as Kt, renderStyles as L, normalizeColorTokenValue as Lt, OUTER_STYLES as M, CUSTOM_UNITS as Mt, POSITION_STYLES as N, DIRECTIONS as Nt, CONTAINER_STYLES as O, hasLocalFunctions as Ot, TEXT_STYLES as P, filterMods as Pt, hasLocalFontFace as Q, getComponentPropertySyntax as Qt, parseStateKey as R, parseColor as Rt, baseStylePropsRegistry as S, FONT_CHUNK_STYLES as St, BLOCK_OUTER_STYLES as T, STYLE_TO_CHUNK as Tt, getGlobalPredefinedStates as U, okhslFunction as Ut, extractLocalPredefinedStates as V, okhstFunction as Vt, setGlobalPredefinedStates as W, okhslPlugin as Wt, fontFaceContentHash as X, getColorSpaceComponents as Xt, extractLocalFontFace as Y, convertColorChainToComponentChain as Yt, formatFontFaceRule as Z, getColorSpaceSuffix as Zt, isFunctionsPolyfillEnabled as _, propHandlerRegistry as _t, getGlobalCounterStyles as a, hslToRgbValues as an, DEFAULT_NAME_PREFIX as at, resetConfig as b, DIMENSION_CHUNK_STYLES as bt, getGlobalInjector as c, makeCounterStyleName as ct, getGlobalStyles as d, validateNamePrefix as dt, resolveFunctionColor as en, STYLE_HANDLER_MAP as et, getNamePrefix as f, hashString as ft, isConfigLocked as g, parsePropertyToken as gt, hasStylesGenerated as h, hasLocalProperties as ht, getGlobalConfigTokens as i, hexToRgb as in, PropertyTypeResolver as it, INNER_STYLES as j, registerLocalFunctionPolyfills as jt, DIMENSION_STYLES as k, parseFunctionName as kt, getGlobalKeyframes as l, makeKeyframeName as lt, hasGlobalRecipes as m, getEffectiveDefinition as mt, getConfig as n, getNamedColorHex as nn, styleHandlers as nt, getGlobalFontFaces as o, strToRgb as on, DEFAULT_ZERO_NAME_PREFIX as ot, hasGlobalKeyframes as p, extractLocalProperties as pt, formatCounterStyleRule as q, StyleParser as qt, getEffectiveProperties as r, getRgbValuesFromRgbaString as rn, createStyle as rt, getGlobalFunctions as s, normalizeDslName as sn, makeClassName as st, configure as t, Lru as tn, defineHandler as tt, getGlobalRecipes as u, tastyClassRegex as ut, isTestEnvironment as v, APPEARANCE_CHUNK_STYLES as vt, BLOCK_INNER_STYLES as w, POSITION_CHUNK_STYLES as wt, generateTypographyTokens as x, DISPLAY_CHUNK_STYLES as xt, markStylesGenerated as y, CHUNK_NAMES as yt, camelToKebab as z, parseStyle as zt };
12884
+ export { SheetManager as $, colorInitialValueToComponents as $t, FLOW_STYLES as A, STYLE_TO_CHUNK as At, createStateParserContext as B, getGlobalParser as Bt, BASE_STYLES as C, APPEARANCE_CHUNK_STYLES as Ct, COLOR_STYLES as D, FONT_CHUNK_STYLES as Dt, BLOCK_STYLES as E, DISPLAY_CHUNK_STYLES as Et, hasPipelineCacheEntry as F, registerFunctionPolyfill as Ft, StyleInjector as G, stringifyStyles as Gt, extractPredefinedStateRefs as H, normalizeColorTokenValue as Ht, isSelector as I, registerLocalFunctionPolyfills as It, hasLocalCounterStyle as J, okhslFunction as Jt, extractLocalCounterStyle as K, okhstFunction as Kt, renderStyles as L, CUSTOM_UNITS as Lt, OUTER_STYLES as M, formatFunctionRule as Mt, POSITION_STYLES as N, hasLocalFunctions as Nt, CONTAINER_STYLES as O, LAYOUT_CHUNK_STYLES as Ot, TEXT_STYLES as P, parseFunctionName as Pt, hasLocalFontFace as Q, StyleParser as Qt, parseStateKey as R, DIRECTIONS as Rt, baseStylePropsRegistry as S, propHandlerRegistry as St, BLOCK_OUTER_STYLES as T, DIMENSION_CHUNK_STYLES as Tt, getGlobalPredefinedStates as U, parseColor as Ut, extractLocalPredefinedStates as V, getGlobalPredefinedTokens as Vt, setGlobalPredefinedStates as W, parseStyle as Wt, fontFaceContentHash as X, createColorFunc as Xt, extractLocalFontFace as Y, okhslPlugin as Yt, formatFontFaceRule as Z, isDevEnv as Zt, isFunctionsPolyfillEnabled as _, hashString as _t, getGlobalCounterStyles as a, resolveFunctionColor as an, closeBatchWindow as at, resetConfig as b, hasLocalProperties as bt, getGlobalInjector as c, getRgbValuesFromRgbaString as cn, openBatchWindow as ct, getGlobalStyles as d, strToRgb as dn, DEFAULT_ZERO_NAME_PREFIX as dt, convertColorChainToComponentChain as en, STYLE_HANDLER_MAP as et, getNamePrefix as f, normalizeDslName as fn, makeClassName as ft, isConfigLocked as g, validateNamePrefix as gt, hasStylesGenerated as h, tastyClassRegex as ht, getGlobalConfigTokens as i, overrideColorAlpha as in, PropertyTypeResolver as it, INNER_STYLES as j, extractLocalFunctions as jt, DIMENSION_STYLES as k, POSITION_CHUNK_STYLES as kt, getGlobalKeyframes as l, hexToRgb as ln, resetStyleBatch as lt, hasGlobalRecipes as m, makeKeyframeName as mt, getConfig as n, getColorSpaceSuffix as nn, styleHandlers as nt, getGlobalFontFaces as o, Lru as on, flushStyles as ot, hasGlobalKeyframes as p, makeCounterStyleName as pt, formatCounterStyleRule as q, okhstPlugin as qt, getEffectiveProperties as r, getComponentPropertySyntax as rn, createStyle as rt, getGlobalFunctions as s, getNamedColorHex as sn, hasPendingStyleWrites as st, configure as t, getColorSpaceComponents as tn, defineHandler as tt, getGlobalRecipes as u, hslToRgbValues as un, DEFAULT_NAME_PREFIX as ut, isTestEnvironment as v, extractLocalProperties as vt, BLOCK_INNER_STYLES as w, CHUNK_NAMES as wt, generateTypographyTokens as x, parsePropertyToken as xt, markStylesGenerated as y, getEffectiveDefinition as yt, camelToKebab as z, filterMods as zt };
12441
12885
 
12442
- //# sourceMappingURL=config-Bxme0Moq.js.map
12886
+ //# sourceMappingURL=config-BrDt11hO.js.map