@barocss/kit 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -339,6 +339,11 @@ function staticUtility(name, decls, opts, ctx) {
339
339
  priority: opts?.priority
340
340
  }, ctx);
341
341
  }
342
+ function spacingKeyValue(ctx, key, negative) {
343
+ if (key === "px" || !/^[a-zA-Z][\w-]*$/.test(key) || ctx.theme("spacing", key) == null) return null;
344
+ const ref = `var(--spacing-${key})`;
345
+ return negative ? `calc(${ref} * -1)` : ref;
346
+ }
342
347
  function functionalUtility(opts, ctx) {
343
348
  registerUtility({
344
349
  name: opts.name,
@@ -407,14 +412,17 @@ function functionalUtility(opts, ctx) {
407
412
  if (opts.supportsFraction && /^-?\d+\/\d+$/.test(value)) {
408
413
  finalValue = value;
409
414
  }
415
+ const spacingKey = opts.spacingKeys ? spacingKeyValue(ctx2, String(finalValue).replace(/^-/, ""), !!parsedUtility.negative) : null;
410
416
  if (parsedUtility.negative && opts.supportsNegative && opts.handleNegativeBareValue) {
411
- const bare = opts.handleNegativeBareValue({ value: String(finalValue).replace(/^-/, ""), ctx: ctx2, token, extra });
417
+ const bare = opts.handleNegativeBareValue({ value: String(finalValue).replace(/^-/, ""), ctx: ctx2, token, extra }) ?? spacingKey;
412
418
  if (bare == null) return [];
413
419
  finalValue = bare;
414
420
  } else if (opts.handleBareValue) {
415
- const bare = opts.handleBareValue({ value: finalValue, ctx: ctx2, token, extra });
421
+ const bare = opts.handleBareValue({ value: finalValue, ctx: ctx2, token, extra }) ?? spacingKey;
416
422
  if (bare == null) return [];
417
423
  finalValue = bare;
424
+ } else if (spacingKey) {
425
+ finalValue = spacingKey;
418
426
  } else if (!/^-?(\d|\.\d)/.test(String(finalValue))) {
419
427
  return [];
420
428
  }
@@ -549,14 +557,23 @@ function parseClassName(className, ctx) {
549
557
  if (cache.has(className)) {
550
558
  return cache.get(className);
551
559
  }
552
- let important = false;
553
560
  let realClassName = className;
554
- if (className.startsWith("!")) {
561
+ const classPrefix = ctx ? configuredClassPrefix(ctx) : "";
562
+ if (classPrefix) {
563
+ if (!className.startsWith(classPrefix + ":")) {
564
+ const none = { modifiers: [], utility: null };
565
+ cache.set(className, none);
566
+ return none;
567
+ }
568
+ realClassName = className.slice(classPrefix.length + 1);
569
+ }
570
+ let important = false;
571
+ if (realClassName.startsWith("!")) {
555
572
  important = true;
556
- realClassName = className.slice(1);
557
- } else if (className.length > 1 && className.endsWith("!")) {
573
+ realClassName = realClassName.slice(1);
574
+ } else if (realClassName.length > 1 && realClassName.endsWith("!")) {
558
575
  important = true;
559
- realClassName = className.slice(0, -1);
576
+ realClassName = realClassName.slice(0, -1);
560
577
  }
561
578
  const tokens = tokenize(realClassName);
562
579
  const result = parseTokens(tokens, ctx);
@@ -566,6 +583,10 @@ function parseClassName(className, ctx) {
566
583
  cache.set(className, result);
567
584
  return result;
568
585
  }
586
+ function configuredClassPrefix(ctx) {
587
+ const configured = ctx.config("prefix");
588
+ return typeof configured === "string" && /^[a-z]+$/.test(configured) ? configured : "";
589
+ }
569
590
  function parseTokens(tokens, ctx) {
570
591
  const modifiers = [];
571
592
  let utility = null;
@@ -625,6 +646,18 @@ function isSafeVariantToken(value) {
625
646
  function hasCommentToken(value) {
626
647
  return value.includes("/*") || value.includes("*/");
627
648
  }
649
+ function hasCommentDelimiter(text) {
650
+ for (let i = 0; i < text.length - 1; i++) {
651
+ const c = text[i];
652
+ if (c === "\\") {
653
+ i++;
654
+ continue;
655
+ }
656
+ const n = text[i + 1];
657
+ if (c === "/" && n === "*" || c === "*" && n === "/") return true;
658
+ }
659
+ return false;
660
+ }
628
661
  function isStructureSafeValue(value) {
629
662
  if (hasCommentToken(value)) return false;
630
663
  return isSafeVariantValue(value, true);
@@ -772,6 +805,7 @@ function parseUtility(value, ctx) {
772
805
  priority
773
806
  };
774
807
  }
808
+ const isSafePrelude = (text) => !hasCommentDelimiter(String(text ?? ""));
775
809
  const isSafeDecl = (prop, value) => isStructureSafeValue(String(prop)) && isStructureSafeValue(String(value ?? ""));
776
810
  const importantPrefix = "!important";
777
811
  function astToCss(ast, baseSelector, opts, _indent = "") {
@@ -835,6 +869,7 @@ function astToCss(ast, baseSelector, opts, _indent = "") {
835
869
  }).join(", ");
836
870
  }
837
871
  }
872
+ if (!isSafePrelude(selector)) return "";
838
873
  if (minify) {
839
874
  const css = `${indent}${selector}{${astToCss(
840
875
  node.nodes,
@@ -859,6 +894,7 @@ ${astToCss(
859
894
  }
860
895
  }
861
896
  case "style-rule": {
897
+ if (!isSafePrelude(node.selector)) return "";
862
898
  if (minify) {
863
899
  const css = `${indent}${node.selector} {${astToCss(
864
900
  node.nodes,
@@ -883,6 +919,7 @@ ${astToCss(
883
919
  }
884
920
  }
885
921
  case "at-rule": {
922
+ if (!isSafePrelude(node.name) || !isSafePrelude(node.params)) return "";
886
923
  if (minify) {
887
924
  const css = `${indent}@${node.name} ${node.params}{${astToCss(
888
925
  node.nodes,
@@ -936,7 +973,7 @@ function rootToCss(nodes, opts) {
936
973
  if (isSafeDecl(node.prop, node.value)) {
937
974
  list.push(minify ? `${node.prop}:${node.value};` : `${node.prop}: ${node.value};`);
938
975
  }
939
- } else if (node.type === "at-rule") {
976
+ } else if (node.type === "at-rule" && isSafePrelude(node.name) && isSafePrelude(node.params)) {
940
977
  if (minify) {
941
978
  const body = node.nodes.filter((child) => child.type === "decl" && isSafeDecl(child.prop, child.value)).map((child) => child.type === "decl" ? `${child.prop}:${child.value};` : "").join("");
942
979
  list.push(`@${node.name} ${node.params}{${body}}`);
@@ -1073,24 +1110,41 @@ function animationToCssVars(animations) {
1073
1110
  }
1074
1111
  return result;
1075
1112
  }
1076
- function keyframesToCss(keyframes) {
1077
- if (!keyframes) return "";
1078
- let css = "";
1079
- for (const name in keyframes) {
1080
- const frames = keyframes[name];
1081
- css += `@keyframes ${name} {
1113
+ const COMMENT_OR_BLOCK = /\/\*|\*\/|[{};]/;
1114
+ function keyframesBlock(name, frames) {
1115
+ if (!name || COMMENT_OR_BLOCK.test(name) || /\s/.test(name) || !frames || typeof frames !== "object") return "";
1116
+ let body = "";
1117
+ for (const [step, props] of Object.entries(frames)) {
1118
+ if (COMMENT_OR_BLOCK.test(step) || !props || typeof props !== "object") return "";
1119
+ let decls = "";
1120
+ for (const [prop, value] of Object.entries(props)) {
1121
+ const v2 = String(value);
1122
+ if (COMMENT_OR_BLOCK.test(prop) || COMMENT_OR_BLOCK.test(v2)) return "";
1123
+ decls += ` ${prop}: ${v2};
1082
1124
  `;
1083
- for (const step in frames) {
1084
- css += ` ${step} {`;
1085
- const props = frames[step];
1086
- for (const prop in props) {
1087
- css += ` ${prop}: ${props[prop]};`;
1088
- }
1089
- css += " }\n";
1090
1125
  }
1091
- css += "}\n";
1126
+ body += ` ${step} {
1127
+ ${decls} }
1128
+ `;
1092
1129
  }
1093
- return css;
1130
+ return `@keyframes ${name} {
1131
+ ${body}}`;
1132
+ }
1133
+ function referencedKeyframes(css, ctx) {
1134
+ if (!css.includes("animation")) return [];
1135
+ const all = ctx.theme("keyframes");
1136
+ if (!all || typeof all !== "object") return [];
1137
+ const names = /* @__PURE__ */ new Set();
1138
+ for (const m of css.matchAll(/(?:^|[\s;{])animation(?:-name)?\s*:\s*([^;}]+)/g)) {
1139
+ const value = m[1].replace(/var\(--animate-([\w-]+)\)/g, (whole, key) => {
1140
+ const v2 = ctx.theme("animations", key) ?? ctx.theme("animation", key);
1141
+ return typeof v2 === "string" ? v2 : whole;
1142
+ });
1143
+ for (const word of value.split(/[\s,()]+/)) {
1144
+ if (word && Object.prototype.hasOwnProperty.call(all, word)) names.add(word);
1145
+ }
1146
+ }
1147
+ return [...names].map((n) => keyframesBlock(n, all[n])).filter(Boolean);
1094
1148
  }
1095
1149
  function transitionTimingFunctionToCssVars(transition) {
1096
1150
  const result = {};
@@ -1158,7 +1212,7 @@ function themeToCssVarsAll(theme) {
1158
1212
  ...borderRadiusToCssVars(theme.borderRadius),
1159
1213
  ...zIndexToCssVars(theme.zIndex),
1160
1214
  ...opacityToCssVars(theme.opacity),
1161
- ...animationToCssVars(theme.animations),
1215
+ ...animationToCssVars({ ...theme.animations, ...theme.animation }),
1162
1216
  ...transitionTimingFunctionToCssVars(theme.transitionTimingFunction),
1163
1217
  ...transitionDurationToCssVars(theme.transitionDuration),
1164
1218
  ...transitionDelayToCssVars(theme.transitionDelay),
@@ -1167,8 +1221,13 @@ function themeToCssVarsAll(theme) {
1167
1221
  // keyframes handled separately
1168
1222
  };
1169
1223
  }
1224
+ function isSelfReferencingVar(name, value) {
1225
+ if (typeof value !== "string") return false;
1226
+ const m = /^var\(\s*(--[\w-]+)\s*(?:,[\s\S]*)?\)$/.exec(value.trim());
1227
+ return !!m && m[1] === name.trim();
1228
+ }
1170
1229
  function toCssVarsBlock(vars, extra = "") {
1171
- return ":root,:host {\n" + Object.entries(vars).map(([k, v2]) => ` ${k}: ${v2};`).join("\n") + "\n}\n" + extra + "\n";
1230
+ return ":root,:host {\n" + Object.entries(vars).filter(([k, v2]) => !isSelfReferencingVar(k, v2)).map(([k, v2]) => ` ${k}: ${v2};`).join("\n") + "\n}\n" + extra + "\n";
1172
1231
  }
1173
1232
  const BARO_VAR = /--baro-/g;
1174
1233
  const PREFIXED_KEYS = /* @__PURE__ */ new Set(["prop", "value", "params", "selector", "nodes", "items"]);
@@ -1523,7 +1582,11 @@ function generateCss(classList, ctx, opts) {
1523
1582
  }
1524
1583
  return result;
1525
1584
  }).join(opts?.minify ? "" : "\n");
1526
- const rootRules = [...new Set(allAtRootNodes.filter((node) => node.type === "at-rule").map((node) => rootToCss([node], { minify: opts?.minify })))];
1585
+ const rootRules = [.../* @__PURE__ */ new Set([
1586
+ ...allAtRootNodes.filter((node) => node.type === "at-rule").map((node) => rootToCss([node], { minify: opts?.minify })),
1587
+ // #274: the @keyframes the class rules reference, once per sheet.
1588
+ ...referencedKeyframes(results, ctx)
1589
+ ])];
1527
1590
  const rootDeclarations = [...new Set(allAtRootNodes.filter((node) => node.type === "decl").map((node) => rootToCss([node], { minify: opts?.minify })).filter((decl2) => decl2 !== ""))];
1528
1591
  const rootCss = [
1529
1592
  ...rootRules,
@@ -1581,6 +1644,7 @@ function generateCssRules(classList, ctx, opts) {
1581
1644
  const css = rootToCss([node]);
1582
1645
  rootCssList.push(css);
1583
1646
  }
1647
+ rootCssList.push(...referencedKeyframes(cssList.join("\n"), ctx));
1584
1648
  return {
1585
1649
  cls,
1586
1650
  ast: allCleanAst,
@@ -1843,6 +1907,15 @@ class IncrementalParser {
1843
1907
  markProcessed(cls) {
1844
1908
  this.processedClasses.add(cls);
1845
1909
  }
1910
+ /**
1911
+ * Forgets that a class was processed, so a later request generates it again
1912
+ * (used when the browser runtime reclaims an unused class's rules, #269).
1913
+ *
1914
+ * @param cls - The CSS class name to forget
1915
+ */
1916
+ unmarkProcessed(cls) {
1917
+ this.processedClasses.delete(cls);
1918
+ }
1846
1919
  /**
1847
1920
  * Process classes synchronously and update BrowserRuntime cache
1848
1921
  * This method is used by ChangeDetector for scan operations
@@ -1862,6 +1935,48 @@ class IncrementalParser {
1862
1935
  return Array.from(this.processedClasses);
1863
1936
  }
1864
1937
  }
1938
+ const customUtilityName = /^[A-Za-z_][A-Za-z0-9_-]*$/;
1939
+ const customUtilityProp = /^(--[A-Za-z0-9_-]+|-?[A-Za-z][A-Za-z0-9-]*)$/;
1940
+ function validateCustomUtility(name, decls) {
1941
+ if (typeof name !== "string" || !customUtilityName.test(name)) return null;
1942
+ if (!decls || typeof decls !== "object" || Array.isArray(decls)) return null;
1943
+ const out = [];
1944
+ for (const [prop, raw2] of Object.entries(decls)) {
1945
+ if (typeof raw2 !== "string" && typeof raw2 !== "number") return null;
1946
+ const value = String(raw2).trim();
1947
+ if (!customUtilityProp.test(prop) || !value || !isStructureSafeValue(value) || hasCommentDelimiter(value)) return null;
1948
+ out.push([prop, value]);
1949
+ }
1950
+ return out.length ? out : null;
1951
+ }
1952
+ function registerCustomUtilities(ctx, utilities) {
1953
+ if (!utilities || typeof utilities !== "object" || Array.isArray(utilities)) return;
1954
+ const list = getUtility(ctx);
1955
+ const builtins = [...list];
1956
+ const before = list.length;
1957
+ for (const [name, decls] of Object.entries(utilities)) {
1958
+ const safe = validateCustomUtility(name, decls);
1959
+ if (!safe) {
1960
+ debugWarn(`[BAROCSS] Ignoring invalid custom utility "${name}"`);
1961
+ continue;
1962
+ }
1963
+ const shadowed = builtins.filter((u) => u.match(name));
1964
+ registerUtility({
1965
+ name,
1966
+ category: "custom",
1967
+ match: (className) => className === name,
1968
+ handler: (value, c, token) => {
1969
+ let base = [];
1970
+ for (const reg of shadowed) {
1971
+ base = reg.handler(value, c, token, reg) || [];
1972
+ if (base.length > 0) break;
1973
+ }
1974
+ return [...base, ...safe.map(([prop, v]) => decl(prop, v))];
1975
+ }
1976
+ }, ctx);
1977
+ }
1978
+ if (list.length > before) list.unshift(...list.splice(before));
1979
+ }
1865
1980
  const preflightMinimalCSS = `
1866
1981
  /* BaroCSS Preflight - Minimal Reset */
1867
1982
  /* ================================= */
@@ -2647,7 +2762,6 @@ function getPreflightCSS(level = true) {
2647
2762
  return "";
2648
2763
  }
2649
2764
  const defaultConfig = {
2650
- prefix: "barocss-",
2651
2765
  darkMode: "media"
2652
2766
  // same as default
2653
2767
  };
@@ -2749,9 +2863,7 @@ function resolveTheme(config) {
2749
2863
  }
2750
2864
  function themeToCssVars(theme) {
2751
2865
  const vars = themeToCssVarsAll(theme);
2752
- const result = toCssVarsBlock(vars, `
2753
- ${keyframesToCss(theme.keyframes || {})}
2754
- `);
2866
+ const result = toCssVarsBlock(vars);
2755
2867
  return result;
2756
2868
  }
2757
2869
  function createContext(configObj) {
@@ -2805,6 +2917,7 @@ function createContext(configObj) {
2805
2917
  }
2806
2918
  };
2807
2919
  initializeContextState(ctx, getUtility(), getModifier());
2920
+ registerCustomUtilities(ctx, configObj.utilities);
2808
2921
  return ctx;
2809
2922
  }
2810
2923
  function jsonToAst(input, ctx) {
@@ -3389,6 +3502,7 @@ staticUtility("snap-proximity", [["--baro-scroll-snap-strictness", "proximity"]]
3389
3502
  ].forEach(([name, prop]) => {
3390
3503
  functionalUtility({
3391
3504
  name: `scroll-${name}`,
3505
+ spacingKeys: true,
3392
3506
  prop,
3393
3507
  supportsArbitrary: true,
3394
3508
  supportsCustomProperty: true,
@@ -3416,6 +3530,7 @@ staticUtility("snap-proximity", [["--baro-scroll-snap-strictness", "proximity"]]
3416
3530
  ].forEach(([name, prop]) => {
3417
3531
  functionalUtility({
3418
3532
  name: `scroll-${name}`,
3533
+ spacingKeys: true,
3419
3534
  prop,
3420
3535
  supportsArbitrary: true,
3421
3536
  supportsCustomProperty: true,
@@ -3574,10 +3689,12 @@ staticUtility("animate-bounce", [["animation", "var(--animate-bounce)"]], { cate
3574
3689
  staticUtility("animate-none", [["animation", "none"]], { category: "transitions" });
3575
3690
  functionalUtility({
3576
3691
  name: "animate",
3577
- prop: "animation",
3692
+ // #274: theme.animations (and Tailwind's theme.animation) names, e.g. theme.extend.animation.wiggle.
3693
+ themeKeys: ["animations", "animation"],
3578
3694
  supportsArbitrary: true,
3579
3695
  supportsCustomProperty: true,
3580
- handle: (value, ctx, token) => {
3696
+ handle: (value, ctx, token, extra) => {
3697
+ if (extra?.realThemeValue) return [decl("animation", `var(--animate-${extra.realThemeValue})`)];
3581
3698
  if (token.customProperty) {
3582
3699
  return [decl("animation", `var(${value})`)];
3583
3700
  }
@@ -4949,6 +5066,7 @@ staticUtility("sticky", [["position", "sticky"]], { category: "layout" });
4949
5066
  staticUtility(`-${name}-px`, [[prop, "-1px"]], { category: "layout" });
4950
5067
  functionalUtility({
4951
5068
  name,
5069
+ spacingKeys: true,
4952
5070
  prop,
4953
5071
  supportsNegative: true,
4954
5072
  supportsFraction: true,
@@ -4979,6 +5097,7 @@ staticUtility("invisible", [["visibility", "hidden"]], { category: "layout" });
4979
5097
  staticUtility("collapse", [["visibility", "collapse"]], { category: "layout" });
4980
5098
  functionalUtility({
4981
5099
  name: "gap-x",
5100
+ spacingKeys: true,
4982
5101
  prop: "column-gap",
4983
5102
  supportsArbitrary: true,
4984
5103
  // gap-x-[10vw]
@@ -4995,6 +5114,7 @@ functionalUtility({
4995
5114
  });
4996
5115
  functionalUtility({
4997
5116
  name: "gap-y",
5117
+ spacingKeys: true,
4998
5118
  prop: "row-gap",
4999
5119
  supportsArbitrary: true,
5000
5120
  // gap-y-[10vw]
@@ -5011,6 +5131,7 @@ functionalUtility({
5011
5131
  });
5012
5132
  functionalUtility({
5013
5133
  name: "gap",
5134
+ spacingKeys: true,
5014
5135
  prop: "gap",
5015
5136
  supportsArbitrary: true,
5016
5137
  // gap-[10vw]
@@ -5528,6 +5649,7 @@ functionalUtility({
5528
5649
  ].forEach(([name, prop]) => {
5529
5650
  staticUtility(`${name}-px`, [[prop, "1px"]], { category: "spacing" });
5530
5651
  functionalUtility({
5652
+ spacingKeys: true,
5531
5653
  name,
5532
5654
  prop,
5533
5655
  supportsArbitrary: true,
@@ -5552,6 +5674,7 @@ functionalUtility({
5552
5674
  staticUtility(`${name}-px`, [[prop, "1px"]], { category: "spacing" });
5553
5675
  staticUtility(`-${name}-px`, [[prop, "-1px"]], { category: "spacing" });
5554
5676
  functionalUtility({
5677
+ spacingKeys: true,
5555
5678
  name,
5556
5679
  prop,
5557
5680
  supportsNegative: true,
@@ -5582,6 +5705,7 @@ const SPACE_SELECTOR = ":where(& > :not(:last-child))";
5582
5705
  () => rule(SPACE_SELECTOR, [decl(rev, "1")])
5583
5706
  ], { category: "spacing" });
5584
5707
  functionalUtility({
5708
+ spacingKeys: true,
5585
5709
  name,
5586
5710
  supportsNegative: true,
5587
5711
  supportsArbitrary: true,
@@ -5631,6 +5755,7 @@ const SPACE_SELECTOR = ":where(& > :not(:last-child))";
5631
5755
  staticUtility(name, [["width", value]]);
5632
5756
  });
5633
5757
  functionalUtility({
5758
+ spacingKeys: true,
5634
5759
  name: "w",
5635
5760
  prop: "width",
5636
5761
  supportsArbitrary: true,
@@ -5663,6 +5788,7 @@ functionalUtility({
5663
5788
  staticUtility(name, [["width", w], ["height", h]]);
5664
5789
  });
5665
5790
  functionalUtility({
5791
+ spacingKeys: true,
5666
5792
  name: "size",
5667
5793
  supportsArbitrary: true,
5668
5794
  supportsCustomProperty: true,
@@ -5702,6 +5828,7 @@ functionalUtility({
5702
5828
  staticUtility(name, [["height", value]]);
5703
5829
  });
5704
5830
  functionalUtility({
5831
+ spacingKeys: true,
5705
5832
  name: "h",
5706
5833
  prop: "height",
5707
5834
  supportsArbitrary: true,
@@ -5732,6 +5859,7 @@ functionalUtility({
5732
5859
  staticUtility(name, [["min-height", value]], { category: "sizing" });
5733
5860
  });
5734
5861
  functionalUtility({
5862
+ spacingKeys: true,
5735
5863
  name: "min-h",
5736
5864
  prop: "min-height",
5737
5865
  supportsArbitrary: true,
@@ -5762,6 +5890,7 @@ functionalUtility({
5762
5890
  staticUtility(name, [["max-height", value]], { category: "sizing" });
5763
5891
  });
5764
5892
  functionalUtility({
5893
+ spacingKeys: true,
5765
5894
  name: "max-h",
5766
5895
  prop: "max-height",
5767
5896
  supportsArbitrary: true,
@@ -5808,6 +5937,7 @@ functionalUtility({
5808
5937
  staticUtility(name, [["min-width", value]], { category: "sizing" });
5809
5938
  });
5810
5939
  functionalUtility({
5940
+ spacingKeys: true,
5811
5941
  name: "min-w",
5812
5942
  prop: "min-width",
5813
5943
  supportsArbitrary: true,
@@ -5843,6 +5973,7 @@ functionalUtility({
5843
5973
  staticUtility(name, [["max-width", value]], { category: "sizing" });
5844
5974
  });
5845
5975
  functionalUtility({
5976
+ spacingKeys: true,
5846
5977
  name: "max-w",
5847
5978
  prop: "max-width",
5848
5979
  supportsArbitrary: true,
@@ -8266,6 +8397,51 @@ functionalModifier(
8266
8397
  },
8267
8398
  void 0
8268
8399
  );
8400
+ const LEADING_AT = /^\s*@(media|container)\s+([^{]*)\{/;
8401
+ const LATE_MEDIA = /prefers-color-scheme|\bprint\b|forced-colors|orientation/;
8402
+ const MIN_W = /(?:min-width\s*:\s*|width\s*>=?\s*)([\d.]+)(px|rem|em)?/;
8403
+ const MAX_W = /(?:max-width\s*:\s*|width\s*<=?\s*)([\d.]+)(px|rem|em)?/;
8404
+ function toPx(n, unit) {
8405
+ const v = parseFloat(n);
8406
+ return unit === "rem" || unit === "em" ? v * 16 : v;
8407
+ }
8408
+ function preludeKey(kind, prelude) {
8409
+ const container = kind === "container";
8410
+ const min = MIN_W.exec(prelude);
8411
+ if (min) return [container ? 4 : 2, toPx(min[1], min[2])];
8412
+ const max = MAX_W.exec(prelude);
8413
+ if (max) return [container ? 3 : 1, -toPx(max[1], max[2])];
8414
+ if (!container && LATE_MEDIA.test(prelude)) return [5, 0];
8415
+ return [0, 0];
8416
+ }
8417
+ function ruleSortKey(rule2) {
8418
+ const key = [];
8419
+ let rest = rule2;
8420
+ let m;
8421
+ while (m = LEADING_AT.exec(rest)) {
8422
+ const [g, v] = preludeKey(m[1], m[2]);
8423
+ key.push(g, v);
8424
+ rest = rest.slice(m[0].length);
8425
+ }
8426
+ return key;
8427
+ }
8428
+ function compareKeys(a, b) {
8429
+ const n = Math.min(a.length, b.length);
8430
+ for (let i = 0; i < n; i++) {
8431
+ if (a[i] !== b[i]) return a[i] - b[i];
8432
+ }
8433
+ return a.length - b.length;
8434
+ }
8435
+ function upperBound(keys, key) {
8436
+ let lo = 0;
8437
+ let hi = keys.length;
8438
+ while (lo < hi) {
8439
+ const mid = lo + hi >> 1;
8440
+ if (compareKeys(keys[mid], key) <= 0) lo = mid + 1;
8441
+ else hi = mid;
8442
+ }
8443
+ return lo;
8444
+ }
8269
8445
  exports.AstCache = AstCache;
8270
8446
  exports.IncrementalParser = IncrementalParser;
8271
8447
  exports.ParseResultCache = ParseResultCache;
@@ -8280,6 +8456,7 @@ exports.clearAllCaches = clearAllCaches;
8280
8456
  exports.clearAstCache = clearAstCache;
8281
8457
  exports.collectDeclPaths = collectDeclPaths;
8282
8458
  exports.comment = comment;
8459
+ exports.compareKeys = compareKeys;
8283
8460
  exports.configGetter = configGetter;
8284
8461
  exports.createContext = createContext;
8285
8462
  exports.decl = decl;
@@ -8297,6 +8474,7 @@ exports.getAstCacheStats = getAstCacheStats;
8297
8474
  exports.getModifier = getModifier;
8298
8475
  exports.getPreflightCSS = getPreflightCSS;
8299
8476
  exports.getUtility = getUtility;
8477
+ exports.hasCommentDelimiter = hasCommentDelimiter;
8300
8478
  exports.hasCommentToken = hasCommentToken;
8301
8479
  exports.hasPreset = hasPreset;
8302
8480
  exports.isDebug = isDebug;
@@ -8318,6 +8496,7 @@ exports.registerUtility = registerUtility;
8318
8496
  exports.resolveTheme = resolveTheme;
8319
8497
  exports.rootToCss = rootToCss;
8320
8498
  exports.rule = rule;
8499
+ exports.ruleSortKey = ruleSortKey;
8321
8500
  exports.setContextCacheReset = setContextCacheReset;
8322
8501
  exports.setDebug = setDebug;
8323
8502
  exports.staticModifier = staticModifier;
@@ -8326,5 +8505,6 @@ exports.styleRule = styleRule;
8326
8505
  exports.themeGetter = themeGetter;
8327
8506
  exports.themeToCssVars = themeToCssVars;
8328
8507
  exports.tokenize = tokenize;
8508
+ exports.upperBound = upperBound;
8329
8509
  exports.utilityCache = utilityCache;
8330
8510
  //# sourceMappingURL=index.cjs.map