@barocss/browser 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.
@@ -599,6 +599,9 @@ function hasCommentDelimiter(text) {
599
599
  }
600
600
  return false;
601
601
  }
602
+ function hasHtmlEndTagOpener(text) {
603
+ return text.includes("</");
604
+ }
602
605
  function isStructureSafeValue(value) {
603
606
  if (hasCommentToken(value)) return false;
604
607
  return isSafeVariantValue(value, true);
@@ -746,8 +749,11 @@ function parseUtility(value, ctx) {
746
749
  priority
747
750
  };
748
751
  }
749
- const isSafePrelude = (text) => !hasCommentDelimiter(String(text ?? ""));
750
- const isSafeDecl = (prop, value) => isStructureSafeValue(String(prop)) && isStructureSafeValue(String(value ?? ""));
752
+ const isSafePrelude = (text) => {
753
+ const t = String(text ?? "");
754
+ return !hasCommentDelimiter(t) && !hasHtmlEndTagOpener(t);
755
+ };
756
+ const isSafeDecl = (prop, value) => isStructureSafeValue(String(prop)) && isStructureSafeValue(String(value ?? "")) && !hasHtmlEndTagOpener(String(prop)) && !hasHtmlEndTagOpener(String(value ?? ""));
751
757
  const importantPrefix = "!important";
752
758
  function astToCss(ast, baseSelector, opts, _indent = "") {
753
759
  const minify = opts?.minify;
@@ -1047,7 +1053,7 @@ function animationToCssVars(animations2) {
1047
1053
  }
1048
1054
  return result;
1049
1055
  }
1050
- const COMMENT_OR_BLOCK = /\/\*|\*\/|[{};]/;
1056
+ const COMMENT_OR_BLOCK = /\/\*|\*\/|[{};]|<\//;
1051
1057
  function keyframesBlock(name, frames) {
1052
1058
  if (!name || COMMENT_OR_BLOCK.test(name) || /\s/.test(name) || !frames || typeof frames !== "object") return "";
1053
1059
  let body = "";
@@ -1165,8 +1171,15 @@ function isSelfReferencingVar(name, value) {
1165
1171
  const m = /^var\(\s*(--[\w-]+)\s*(?:,[\s\S]*)?\)$/.exec(value.trim());
1166
1172
  return !!m && m[1] === name.trim();
1167
1173
  }
1174
+ const SAFE_VAR_NAME = /^--(?:[\w-]|\\\.)+$/;
1175
+ function isSafeThemeVar(name, value) {
1176
+ if (typeof name !== "string" || !SAFE_VAR_NAME.test(name) || hasHtmlEndTagOpener(name)) return false;
1177
+ if (typeof value !== "string" && typeof value !== "number") return false;
1178
+ const v2 = String(value);
1179
+ return v2.trim() !== "" && isStructureSafeValue(v2) && !hasCommentDelimiter(v2) && !hasHtmlEndTagOpener(v2);
1180
+ }
1168
1181
  function toCssVarsBlock(vars, extra = "") {
1169
- return ":root,:host {\n" + Object.entries(vars).filter(([k, v2]) => !isSelfReferencingVar(k, v2)).map(([k, v2]) => ` ${k}: ${v2};`).join("\n") + "\n}\n" + extra + "\n";
1182
+ 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";
1170
1183
  }
1171
1184
  const BARO_VAR = /--baro-/g;
1172
1185
  const PREFIXED_KEYS = /* @__PURE__ */ new Set(["prop", "value", "params", "selector", "nodes", "items"]);