@barocss/kit 0.5.0 → 0.6.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 +107 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +46 -14
- package/dist/index.js +107 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
}
|
|
@@ -625,6 +633,18 @@ function isSafeVariantToken(value) {
|
|
|
625
633
|
function hasCommentToken(value) {
|
|
626
634
|
return value.includes("/*") || value.includes("*/");
|
|
627
635
|
}
|
|
636
|
+
function hasCommentDelimiter(text) {
|
|
637
|
+
for (let i = 0; i < text.length - 1; i++) {
|
|
638
|
+
const c = text[i];
|
|
639
|
+
if (c === "\\") {
|
|
640
|
+
i++;
|
|
641
|
+
continue;
|
|
642
|
+
}
|
|
643
|
+
const n = text[i + 1];
|
|
644
|
+
if (c === "/" && n === "*" || c === "*" && n === "/") return true;
|
|
645
|
+
}
|
|
646
|
+
return false;
|
|
647
|
+
}
|
|
628
648
|
function isStructureSafeValue(value) {
|
|
629
649
|
if (hasCommentToken(value)) return false;
|
|
630
650
|
return isSafeVariantValue(value, true);
|
|
@@ -772,6 +792,7 @@ function parseUtility(value, ctx) {
|
|
|
772
792
|
priority
|
|
773
793
|
};
|
|
774
794
|
}
|
|
795
|
+
const isSafePrelude = (text) => !hasCommentDelimiter(String(text ?? ""));
|
|
775
796
|
const isSafeDecl = (prop, value) => isStructureSafeValue(String(prop)) && isStructureSafeValue(String(value ?? ""));
|
|
776
797
|
const importantPrefix = "!important";
|
|
777
798
|
function astToCss(ast, baseSelector, opts, _indent = "") {
|
|
@@ -835,6 +856,7 @@ function astToCss(ast, baseSelector, opts, _indent = "") {
|
|
|
835
856
|
}).join(", ");
|
|
836
857
|
}
|
|
837
858
|
}
|
|
859
|
+
if (!isSafePrelude(selector)) return "";
|
|
838
860
|
if (minify) {
|
|
839
861
|
const css = `${indent}${selector}{${astToCss(
|
|
840
862
|
node.nodes,
|
|
@@ -859,6 +881,7 @@ ${astToCss(
|
|
|
859
881
|
}
|
|
860
882
|
}
|
|
861
883
|
case "style-rule": {
|
|
884
|
+
if (!isSafePrelude(node.selector)) return "";
|
|
862
885
|
if (minify) {
|
|
863
886
|
const css = `${indent}${node.selector} {${astToCss(
|
|
864
887
|
node.nodes,
|
|
@@ -883,6 +906,7 @@ ${astToCss(
|
|
|
883
906
|
}
|
|
884
907
|
}
|
|
885
908
|
case "at-rule": {
|
|
909
|
+
if (!isSafePrelude(node.name) || !isSafePrelude(node.params)) return "";
|
|
886
910
|
if (minify) {
|
|
887
911
|
const css = `${indent}@${node.name} ${node.params}{${astToCss(
|
|
888
912
|
node.nodes,
|
|
@@ -936,7 +960,7 @@ function rootToCss(nodes, opts) {
|
|
|
936
960
|
if (isSafeDecl(node.prop, node.value)) {
|
|
937
961
|
list.push(minify ? `${node.prop}:${node.value};` : `${node.prop}: ${node.value};`);
|
|
938
962
|
}
|
|
939
|
-
} else if (node.type === "at-rule") {
|
|
963
|
+
} else if (node.type === "at-rule" && isSafePrelude(node.name) && isSafePrelude(node.params)) {
|
|
940
964
|
if (minify) {
|
|
941
965
|
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
966
|
list.push(`@${node.name} ${node.params}{${body}}`);
|
|
@@ -1167,8 +1191,13 @@ function themeToCssVarsAll(theme) {
|
|
|
1167
1191
|
// keyframes handled separately
|
|
1168
1192
|
};
|
|
1169
1193
|
}
|
|
1194
|
+
function isSelfReferencingVar(name, value) {
|
|
1195
|
+
if (typeof value !== "string") return false;
|
|
1196
|
+
const m = /^var\(\s*(--[\w-]+)\s*(?:,[\s\S]*)?\)$/.exec(value.trim());
|
|
1197
|
+
return !!m && m[1] === name.trim();
|
|
1198
|
+
}
|
|
1170
1199
|
function toCssVarsBlock(vars, extra = "") {
|
|
1171
|
-
return ":root,:host {\n" + Object.entries(vars).map(([k, v2]) => ` ${k}: ${v2};`).join("\n") + "\n}\n" + extra + "\n";
|
|
1200
|
+
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
1201
|
}
|
|
1173
1202
|
const BARO_VAR = /--baro-/g;
|
|
1174
1203
|
const PREFIXED_KEYS = /* @__PURE__ */ new Set(["prop", "value", "params", "selector", "nodes", "items"]);
|
|
@@ -1843,6 +1872,15 @@ class IncrementalParser {
|
|
|
1843
1872
|
markProcessed(cls) {
|
|
1844
1873
|
this.processedClasses.add(cls);
|
|
1845
1874
|
}
|
|
1875
|
+
/**
|
|
1876
|
+
* Forgets that a class was processed, so a later request generates it again
|
|
1877
|
+
* (used when the browser runtime reclaims an unused class's rules, #269).
|
|
1878
|
+
*
|
|
1879
|
+
* @param cls - The CSS class name to forget
|
|
1880
|
+
*/
|
|
1881
|
+
unmarkProcessed(cls) {
|
|
1882
|
+
this.processedClasses.delete(cls);
|
|
1883
|
+
}
|
|
1846
1884
|
/**
|
|
1847
1885
|
* Process classes synchronously and update BrowserRuntime cache
|
|
1848
1886
|
* This method is used by ChangeDetector for scan operations
|
|
@@ -3389,6 +3427,7 @@ staticUtility("snap-proximity", [["--baro-scroll-snap-strictness", "proximity"]]
|
|
|
3389
3427
|
].forEach(([name, prop]) => {
|
|
3390
3428
|
functionalUtility({
|
|
3391
3429
|
name: `scroll-${name}`,
|
|
3430
|
+
spacingKeys: true,
|
|
3392
3431
|
prop,
|
|
3393
3432
|
supportsArbitrary: true,
|
|
3394
3433
|
supportsCustomProperty: true,
|
|
@@ -3416,6 +3455,7 @@ staticUtility("snap-proximity", [["--baro-scroll-snap-strictness", "proximity"]]
|
|
|
3416
3455
|
].forEach(([name, prop]) => {
|
|
3417
3456
|
functionalUtility({
|
|
3418
3457
|
name: `scroll-${name}`,
|
|
3458
|
+
spacingKeys: true,
|
|
3419
3459
|
prop,
|
|
3420
3460
|
supportsArbitrary: true,
|
|
3421
3461
|
supportsCustomProperty: true,
|
|
@@ -4949,6 +4989,7 @@ staticUtility("sticky", [["position", "sticky"]], { category: "layout" });
|
|
|
4949
4989
|
staticUtility(`-${name}-px`, [[prop, "-1px"]], { category: "layout" });
|
|
4950
4990
|
functionalUtility({
|
|
4951
4991
|
name,
|
|
4992
|
+
spacingKeys: true,
|
|
4952
4993
|
prop,
|
|
4953
4994
|
supportsNegative: true,
|
|
4954
4995
|
supportsFraction: true,
|
|
@@ -4979,6 +5020,7 @@ staticUtility("invisible", [["visibility", "hidden"]], { category: "layout" });
|
|
|
4979
5020
|
staticUtility("collapse", [["visibility", "collapse"]], { category: "layout" });
|
|
4980
5021
|
functionalUtility({
|
|
4981
5022
|
name: "gap-x",
|
|
5023
|
+
spacingKeys: true,
|
|
4982
5024
|
prop: "column-gap",
|
|
4983
5025
|
supportsArbitrary: true,
|
|
4984
5026
|
// gap-x-[10vw]
|
|
@@ -4995,6 +5037,7 @@ functionalUtility({
|
|
|
4995
5037
|
});
|
|
4996
5038
|
functionalUtility({
|
|
4997
5039
|
name: "gap-y",
|
|
5040
|
+
spacingKeys: true,
|
|
4998
5041
|
prop: "row-gap",
|
|
4999
5042
|
supportsArbitrary: true,
|
|
5000
5043
|
// gap-y-[10vw]
|
|
@@ -5011,6 +5054,7 @@ functionalUtility({
|
|
|
5011
5054
|
});
|
|
5012
5055
|
functionalUtility({
|
|
5013
5056
|
name: "gap",
|
|
5057
|
+
spacingKeys: true,
|
|
5014
5058
|
prop: "gap",
|
|
5015
5059
|
supportsArbitrary: true,
|
|
5016
5060
|
// gap-[10vw]
|
|
@@ -5528,6 +5572,7 @@ functionalUtility({
|
|
|
5528
5572
|
].forEach(([name, prop]) => {
|
|
5529
5573
|
staticUtility(`${name}-px`, [[prop, "1px"]], { category: "spacing" });
|
|
5530
5574
|
functionalUtility({
|
|
5575
|
+
spacingKeys: true,
|
|
5531
5576
|
name,
|
|
5532
5577
|
prop,
|
|
5533
5578
|
supportsArbitrary: true,
|
|
@@ -5552,6 +5597,7 @@ functionalUtility({
|
|
|
5552
5597
|
staticUtility(`${name}-px`, [[prop, "1px"]], { category: "spacing" });
|
|
5553
5598
|
staticUtility(`-${name}-px`, [[prop, "-1px"]], { category: "spacing" });
|
|
5554
5599
|
functionalUtility({
|
|
5600
|
+
spacingKeys: true,
|
|
5555
5601
|
name,
|
|
5556
5602
|
prop,
|
|
5557
5603
|
supportsNegative: true,
|
|
@@ -5582,6 +5628,7 @@ const SPACE_SELECTOR = ":where(& > :not(:last-child))";
|
|
|
5582
5628
|
() => rule(SPACE_SELECTOR, [decl(rev, "1")])
|
|
5583
5629
|
], { category: "spacing" });
|
|
5584
5630
|
functionalUtility({
|
|
5631
|
+
spacingKeys: true,
|
|
5585
5632
|
name,
|
|
5586
5633
|
supportsNegative: true,
|
|
5587
5634
|
supportsArbitrary: true,
|
|
@@ -5631,6 +5678,7 @@ const SPACE_SELECTOR = ":where(& > :not(:last-child))";
|
|
|
5631
5678
|
staticUtility(name, [["width", value]]);
|
|
5632
5679
|
});
|
|
5633
5680
|
functionalUtility({
|
|
5681
|
+
spacingKeys: true,
|
|
5634
5682
|
name: "w",
|
|
5635
5683
|
prop: "width",
|
|
5636
5684
|
supportsArbitrary: true,
|
|
@@ -5663,6 +5711,7 @@ functionalUtility({
|
|
|
5663
5711
|
staticUtility(name, [["width", w], ["height", h]]);
|
|
5664
5712
|
});
|
|
5665
5713
|
functionalUtility({
|
|
5714
|
+
spacingKeys: true,
|
|
5666
5715
|
name: "size",
|
|
5667
5716
|
supportsArbitrary: true,
|
|
5668
5717
|
supportsCustomProperty: true,
|
|
@@ -5702,6 +5751,7 @@ functionalUtility({
|
|
|
5702
5751
|
staticUtility(name, [["height", value]]);
|
|
5703
5752
|
});
|
|
5704
5753
|
functionalUtility({
|
|
5754
|
+
spacingKeys: true,
|
|
5705
5755
|
name: "h",
|
|
5706
5756
|
prop: "height",
|
|
5707
5757
|
supportsArbitrary: true,
|
|
@@ -5732,6 +5782,7 @@ functionalUtility({
|
|
|
5732
5782
|
staticUtility(name, [["min-height", value]], { category: "sizing" });
|
|
5733
5783
|
});
|
|
5734
5784
|
functionalUtility({
|
|
5785
|
+
spacingKeys: true,
|
|
5735
5786
|
name: "min-h",
|
|
5736
5787
|
prop: "min-height",
|
|
5737
5788
|
supportsArbitrary: true,
|
|
@@ -5762,6 +5813,7 @@ functionalUtility({
|
|
|
5762
5813
|
staticUtility(name, [["max-height", value]], { category: "sizing" });
|
|
5763
5814
|
});
|
|
5764
5815
|
functionalUtility({
|
|
5816
|
+
spacingKeys: true,
|
|
5765
5817
|
name: "max-h",
|
|
5766
5818
|
prop: "max-height",
|
|
5767
5819
|
supportsArbitrary: true,
|
|
@@ -5808,6 +5860,7 @@ functionalUtility({
|
|
|
5808
5860
|
staticUtility(name, [["min-width", value]], { category: "sizing" });
|
|
5809
5861
|
});
|
|
5810
5862
|
functionalUtility({
|
|
5863
|
+
spacingKeys: true,
|
|
5811
5864
|
name: "min-w",
|
|
5812
5865
|
prop: "min-width",
|
|
5813
5866
|
supportsArbitrary: true,
|
|
@@ -5843,6 +5896,7 @@ functionalUtility({
|
|
|
5843
5896
|
staticUtility(name, [["max-width", value]], { category: "sizing" });
|
|
5844
5897
|
});
|
|
5845
5898
|
functionalUtility({
|
|
5899
|
+
spacingKeys: true,
|
|
5846
5900
|
name: "max-w",
|
|
5847
5901
|
prop: "max-width",
|
|
5848
5902
|
supportsArbitrary: true,
|
|
@@ -8266,6 +8320,51 @@ functionalModifier(
|
|
|
8266
8320
|
},
|
|
8267
8321
|
void 0
|
|
8268
8322
|
);
|
|
8323
|
+
const LEADING_AT = /^\s*@(media|container)\s+([^{]*)\{/;
|
|
8324
|
+
const LATE_MEDIA = /prefers-color-scheme|\bprint\b|forced-colors|orientation/;
|
|
8325
|
+
const MIN_W = /(?:min-width\s*:\s*|width\s*>=?\s*)([\d.]+)(px|rem|em)?/;
|
|
8326
|
+
const MAX_W = /(?:max-width\s*:\s*|width\s*<=?\s*)([\d.]+)(px|rem|em)?/;
|
|
8327
|
+
function toPx(n, unit) {
|
|
8328
|
+
const v = parseFloat(n);
|
|
8329
|
+
return unit === "rem" || unit === "em" ? v * 16 : v;
|
|
8330
|
+
}
|
|
8331
|
+
function preludeKey(kind, prelude) {
|
|
8332
|
+
const container = kind === "container";
|
|
8333
|
+
const min = MIN_W.exec(prelude);
|
|
8334
|
+
if (min) return [container ? 4 : 2, toPx(min[1], min[2])];
|
|
8335
|
+
const max = MAX_W.exec(prelude);
|
|
8336
|
+
if (max) return [container ? 3 : 1, -toPx(max[1], max[2])];
|
|
8337
|
+
if (!container && LATE_MEDIA.test(prelude)) return [5, 0];
|
|
8338
|
+
return [0, 0];
|
|
8339
|
+
}
|
|
8340
|
+
function ruleSortKey(rule2) {
|
|
8341
|
+
const key = [];
|
|
8342
|
+
let rest = rule2;
|
|
8343
|
+
let m;
|
|
8344
|
+
while (m = LEADING_AT.exec(rest)) {
|
|
8345
|
+
const [g, v] = preludeKey(m[1], m[2]);
|
|
8346
|
+
key.push(g, v);
|
|
8347
|
+
rest = rest.slice(m[0].length);
|
|
8348
|
+
}
|
|
8349
|
+
return key;
|
|
8350
|
+
}
|
|
8351
|
+
function compareKeys(a, b) {
|
|
8352
|
+
const n = Math.min(a.length, b.length);
|
|
8353
|
+
for (let i = 0; i < n; i++) {
|
|
8354
|
+
if (a[i] !== b[i]) return a[i] - b[i];
|
|
8355
|
+
}
|
|
8356
|
+
return a.length - b.length;
|
|
8357
|
+
}
|
|
8358
|
+
function upperBound(keys, key) {
|
|
8359
|
+
let lo = 0;
|
|
8360
|
+
let hi = keys.length;
|
|
8361
|
+
while (lo < hi) {
|
|
8362
|
+
const mid = lo + hi >> 1;
|
|
8363
|
+
if (compareKeys(keys[mid], key) <= 0) lo = mid + 1;
|
|
8364
|
+
else hi = mid;
|
|
8365
|
+
}
|
|
8366
|
+
return lo;
|
|
8367
|
+
}
|
|
8269
8368
|
exports.AstCache = AstCache;
|
|
8270
8369
|
exports.IncrementalParser = IncrementalParser;
|
|
8271
8370
|
exports.ParseResultCache = ParseResultCache;
|
|
@@ -8280,6 +8379,7 @@ exports.clearAllCaches = clearAllCaches;
|
|
|
8280
8379
|
exports.clearAstCache = clearAstCache;
|
|
8281
8380
|
exports.collectDeclPaths = collectDeclPaths;
|
|
8282
8381
|
exports.comment = comment;
|
|
8382
|
+
exports.compareKeys = compareKeys;
|
|
8283
8383
|
exports.configGetter = configGetter;
|
|
8284
8384
|
exports.createContext = createContext;
|
|
8285
8385
|
exports.decl = decl;
|
|
@@ -8297,6 +8397,7 @@ exports.getAstCacheStats = getAstCacheStats;
|
|
|
8297
8397
|
exports.getModifier = getModifier;
|
|
8298
8398
|
exports.getPreflightCSS = getPreflightCSS;
|
|
8299
8399
|
exports.getUtility = getUtility;
|
|
8400
|
+
exports.hasCommentDelimiter = hasCommentDelimiter;
|
|
8300
8401
|
exports.hasCommentToken = hasCommentToken;
|
|
8301
8402
|
exports.hasPreset = hasPreset;
|
|
8302
8403
|
exports.isDebug = isDebug;
|
|
@@ -8318,6 +8419,7 @@ exports.registerUtility = registerUtility;
|
|
|
8318
8419
|
exports.resolveTheme = resolveTheme;
|
|
8319
8420
|
exports.rootToCss = rootToCss;
|
|
8320
8421
|
exports.rule = rule;
|
|
8422
|
+
exports.ruleSortKey = ruleSortKey;
|
|
8321
8423
|
exports.setContextCacheReset = setContextCacheReset;
|
|
8322
8424
|
exports.setDebug = setDebug;
|
|
8323
8425
|
exports.staticModifier = staticModifier;
|
|
@@ -8326,5 +8428,6 @@ exports.styleRule = styleRule;
|
|
|
8326
8428
|
exports.themeGetter = themeGetter;
|
|
8327
8429
|
exports.themeToCssVars = themeToCssVars;
|
|
8328
8430
|
exports.tokenize = tokenize;
|
|
8431
|
+
exports.upperBound = upperBound;
|
|
8329
8432
|
exports.utilityCache = utilityCache;
|
|
8330
8433
|
//# sourceMappingURL=index.cjs.map
|