Blame view

天文台pc/tianwentai-ui/node_modules/motion-dom/dist/es/animation/utils/is-css-variable.mjs 1.19 KB
bc518174   王天杨   提交两个项目文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  const checkStringStartsWith = (token) => (key) => typeof key === "string" && key.startsWith(token);
  const isCSSVariableName = 
  /*@__PURE__*/ checkStringStartsWith("--");
  const startsAsVariableToken = 
  /*@__PURE__*/ checkStringStartsWith("var(--");
  const isCSSVariableToken = (value) => {
      const startsWithToken = startsAsVariableToken(value);
      if (!startsWithToken)
          return false;
      // Ensure any comments are stripped from the value as this can harm performance of the regex.
      return singleCssVariableRegex.test(value.split("/*")[0].trim());
  };
  const singleCssVariableRegex = /var\(--(?:[\w-]+\s*|[\w-]+\s*,(?:\s*[^)(\s]|\s*\((?:[^)(]|\([^)(]*\))*\))+\s*)\)$/iu;
  /**
   * Check if a value contains a CSS variable anywhere (e.g. inside calc()).
   * Unlike isCSSVariableToken which checks if the value IS a var() token,
   * this checks if the value CONTAINS var() somewhere in the string.
   */
  function containsCSSVariable(value) {
      if (typeof value !== "string")
          return false;
      // Strip comments to avoid false positives
      return value.split("/*")[0].includes("var(--");
  }
  
  export { containsCSSVariable, isCSSVariableName, isCSSVariableToken };
  //# sourceMappingURL=is-css-variable.mjs.map