@barocss/kit 0.8.0 → 0.8.1
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 +18 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.js +18 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -576,6 +576,13 @@ export declare type AstNode = {
|
|
|
576
576
|
/** #248: a comment opener or closer anywhere in a variant (quoted or not) could leave a comment unclosed in the output. */
|
|
577
577
|
export declare function hasCommentToken(value: string): boolean;
|
|
578
578
|
|
|
579
|
+
/**
|
|
580
|
+
* #323: true when emitted text contains a markup end-tag opener (less-than then slash). Generated CSS can be
|
|
581
|
+
* placed inside an HTML style element, where that sequence could end the element early. CSS escapes in the
|
|
582
|
+
* output never form it, and a lone less-than (range media queries) stays allowed.
|
|
583
|
+
*/
|
|
584
|
+
export declare function hasHtmlEndTagOpener(text: string): boolean;
|
|
585
|
+
|
|
579
586
|
export declare type HasItems = {
|
|
580
587
|
items?: AstNode[];
|
|
581
588
|
};
|
package/dist/index.js
CHANGED
|
@@ -657,6 +657,9 @@ function hasCommentDelimiter(text) {
|
|
|
657
657
|
}
|
|
658
658
|
return false;
|
|
659
659
|
}
|
|
660
|
+
function hasHtmlEndTagOpener(text) {
|
|
661
|
+
return text.includes("</");
|
|
662
|
+
}
|
|
660
663
|
function isStructureSafeValue(value) {
|
|
661
664
|
if (hasCommentToken(value)) return false;
|
|
662
665
|
return isSafeVariantValue(value, true);
|
|
@@ -804,8 +807,11 @@ function parseUtility(value, ctx) {
|
|
|
804
807
|
priority
|
|
805
808
|
};
|
|
806
809
|
}
|
|
807
|
-
const isSafePrelude = (text) =>
|
|
808
|
-
const
|
|
810
|
+
const isSafePrelude = (text) => {
|
|
811
|
+
const t = String(text ?? "");
|
|
812
|
+
return !hasCommentDelimiter(t) && !hasHtmlEndTagOpener(t);
|
|
813
|
+
};
|
|
814
|
+
const isSafeDecl = (prop, value) => isStructureSafeValue(String(prop)) && isStructureSafeValue(String(value ?? "")) && !hasHtmlEndTagOpener(String(prop)) && !hasHtmlEndTagOpener(String(value ?? ""));
|
|
809
815
|
const importantPrefix = "!important";
|
|
810
816
|
function astToCss(ast, baseSelector, opts, _indent = "") {
|
|
811
817
|
const minify = opts?.minify;
|
|
@@ -1109,7 +1115,7 @@ function animationToCssVars(animations) {
|
|
|
1109
1115
|
}
|
|
1110
1116
|
return result;
|
|
1111
1117
|
}
|
|
1112
|
-
const COMMENT_OR_BLOCK = /\/\*|\*\/|[{};]
|
|
1118
|
+
const COMMENT_OR_BLOCK = /\/\*|\*\/|[{};]|<\//;
|
|
1113
1119
|
function keyframesBlock(name, frames) {
|
|
1114
1120
|
if (!name || COMMENT_OR_BLOCK.test(name) || /\s/.test(name) || !frames || typeof frames !== "object") return "";
|
|
1115
1121
|
let body = "";
|
|
@@ -1227,8 +1233,15 @@ function isSelfReferencingVar(name, value) {
|
|
|
1227
1233
|
const m = /^var\(\s*(--[\w-]+)\s*(?:,[\s\S]*)?\)$/.exec(value.trim());
|
|
1228
1234
|
return !!m && m[1] === name.trim();
|
|
1229
1235
|
}
|
|
1236
|
+
const SAFE_VAR_NAME = /^--(?:[\w-]|\\\.)+$/;
|
|
1237
|
+
function isSafeThemeVar(name, value) {
|
|
1238
|
+
if (typeof name !== "string" || !SAFE_VAR_NAME.test(name) || hasHtmlEndTagOpener(name)) return false;
|
|
1239
|
+
if (typeof value !== "string" && typeof value !== "number") return false;
|
|
1240
|
+
const v2 = String(value);
|
|
1241
|
+
return v2.trim() !== "" && isStructureSafeValue(v2) && !hasCommentDelimiter(v2) && !hasHtmlEndTagOpener(v2);
|
|
1242
|
+
}
|
|
1230
1243
|
function toCssVarsBlock(vars, extra = "") {
|
|
1231
|
-
return ":root,:host {\n" + Object.entries(vars).filter(([k, v2]) => !isSelfReferencingVar(k, v2)).map(([k, v2]) => ` ${k}: ${v2};`).join("\n") + "\n}\n" + extra + "\n";
|
|
1244
|
+
return ":root,:host {\n" + Object.entries(vars).filter(([k, v2]) => isSafeThemeVar(k, v2) && !isSelfReferencingVar(k, v2)).map(([k, v2]) => ` ${k}: ${v2};`).join("\n") + "\n}\n" + extra + "\n";
|
|
1232
1245
|
}
|
|
1233
1246
|
const BARO_VAR = /--baro-/g;
|
|
1234
1247
|
const PREFIXED_KEYS = /* @__PURE__ */ new Set(["prop", "value", "params", "selector", "nodes", "items"]);
|
|
@@ -8638,6 +8651,7 @@ export {
|
|
|
8638
8651
|
getUtility,
|
|
8639
8652
|
hasCommentDelimiter,
|
|
8640
8653
|
hasCommentToken,
|
|
8654
|
+
hasHtmlEndTagOpener,
|
|
8641
8655
|
hasPreset,
|
|
8642
8656
|
isDebug,
|
|
8643
8657
|
isSafeVariantToken,
|