styimat 9.0.0 → 9.2.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.
@@ -41,7 +41,6 @@ const styimat = (function() {
41
41
  IMPORT: /@import\s+([^;]+?)\s*;/g,
42
42
  ALIAS: /^@alias\s+([a-zA-Z_][a-zA-Z0-9_]*)\s+(.+?)\s*;$/,
43
43
  MACRO: /^@macro\s+([a-zA-Z_][a-zA-Z0-9_]*)\s*\(([^)]*)\)\s*\{$/,
44
- SPECHAR: /[.*+?^${}()|[\]\\]/g,
45
44
  COMMENT: /\/\*[\s\S]*?\*\//g,
46
45
  MATH_SYMBOL: /([\da-z])([+-])(-?[\da-z])/g,
47
46
  MATH: /math\(([^)]+)\)/gi,
@@ -475,19 +474,15 @@ const styimat = (function() {
475
474
  * 增强的数学表达式解析和计算
476
475
  */
477
476
  function evaluateMathExpression(expression, config) {
478
- if (!config.enableMath) {
479
- return `math(${expression})`;
480
- }
481
-
482
477
  let cleanExpr = expression.replace(REGEX.SPACE, '');
483
478
 
484
- return parseMathExpression(cleanExpr, config.enableMath);
479
+ return parseMathExpression(cleanExpr);
485
480
  }
486
481
 
487
482
  /**
488
483
  * 解析数学表达式
489
484
  */
490
- function parseMathExpression(expr, enableMath) {
485
+ function parseMathExpression(expr) {
491
486
  return `calc(${expr
492
487
  .replace(REGEX.MATH_SYMBOL, '$1 $2 $3')})`;
493
488
  }
@@ -496,10 +491,6 @@ const styimat = (function() {
496
491
  * 处理所有的math()函数
497
492
  */
498
493
  function processMathFunctions(cssValue, config) {
499
- if (!config.enableMath) {
500
- return cssValue;
501
- }
502
-
503
494
  let result = cssValue;
504
495
 
505
496
  const processMath = (str) => {
@@ -622,9 +613,7 @@ const styimat = (function() {
622
613
  try {
623
614
  let L = parseFloat(match[1]);
624
615
 
625
- if (match[2] === '%') {
626
- L = L;
627
- } else {
616
+ if (match[2] !== '%') {
628
617
  if (L < 0) L = 0;
629
618
  if (L > 100) L = 100;
630
619
  }
@@ -886,104 +875,49 @@ const styimat = (function() {
886
875
 
887
876
  return result;
888
877
  }
889
-
890
- /**
891
- * 提取变量定义并移除
892
- */
893
- function extractVariablesAndCSS(cssText, config) {
894
- const lines = splitLines(cssText);
895
- const globalVariables = {};
896
- const selectorVariables = new Map();
897
- let cssWithoutVars = '';
898
- let inSelectorBlock = false;
899
- let currentIndent = 0;
900
- let currentSelector = null;
901
-
902
- for (let line of lines) {
903
- const trimmed = line.trim();
904
-
905
- const varMatch = trimmed.match(/^\$([a-zA-Z_][a-zA-Z0-9_]*)\s*:\s*(.+?);?$/);
906
-
907
- if (varMatch) {
908
- const [, varName, varValue] = varMatch;
909
- const processedValue = processCSSValue(varValue.trim(), config);
910
-
911
- if (!currentSelector) {
912
- globalVariables[varName] = processedValue;
913
- }
914
- continue;
915
- }
916
-
917
- if (trimmed.endsWith('{')) {
918
- currentSelector = trimmed.slice(0, -1).trim();
919
- inSelectorBlock = true;
920
- cssWithoutVars += line + '\n';
921
- continue;
922
- }
923
-
924
- if (trimmed === '}') {
925
- if (inSelectorBlock) {
926
- if (currentSelector && selectorVariables.has(currentSelector)) {
927
- const vars = selectorVariables.get(currentSelector);
928
- const indent = ' '.repeat(currentIndent);
929
- for (const [varName, varValue] of Object.entries(vars)) {
930
- cssWithoutVars += `${indent} --${varName}: ${varValue};\n`;
931
- }
932
- }
933
- }
934
- inSelectorBlock = false;
935
- currentSelector = null;
936
- }
937
-
938
- cssWithoutVars += line + '\n';
939
-
940
- if (line.includes('{')) {
941
- currentIndent += config.indentSize;
942
- }
943
- if (line.includes('}')) {
944
- currentIndent = Math.max(0, currentIndent - config.indentSize);
945
- }
946
- }
947
-
948
- cssWithoutVars = cssText;
949
-
950
- return {
951
- globalVariables,
952
- selectorVariables,
953
- cssWithoutVars: cssWithoutVars.trim()
954
- };
955
- }
956
-
957
- /**
958
- * 解析嵌套规则
959
- */
878
+
960
879
  /**
961
- * 状态机解析嵌套规则
880
+ * 解析嵌套规则
962
881
  */
963
882
  function parseNestedRules(cssText, config, aliases, macros) {
964
883
  const rootRules = [];
965
884
  const stack = [];
885
+ const globalVariables = {}; // 存储全局变量
966
886
 
967
887
  let currentRule = null;
968
888
  let currentLine = '';
969
889
  let inRuleBlock = false;
970
890
  let braceDepth = 0;
891
+ let isGlobalScope = true; // 标记是否在全局作用域
971
892
 
972
893
  for (let i = 0, length = cssText.length; i < length; i++) {
973
894
  const char = cssText[i];
974
895
  const charCode = cssText.charCodeAt(i);
975
896
 
976
- if (charCode === 123) { // 123: "{"的码点"
897
+ if (charCode === 123) { // 123: "{"的码点
977
898
  braceDepth++;
899
+
900
+ // 在处理{之前,检查当前行是否有变量定义(仅限全局作用域)
901
+ if (isGlobalScope && currentLine.trim()) {
902
+ const varMatch = currentLine.trim().match(/^\$([a-zA-Z_][a-zA-Z0-9_]*)\s*:\s*(.+?);?$/);
903
+ if (varMatch) {
904
+ const [, varName, varValue] = varMatch;
905
+ globalVariables[varName] = processCSSValue(varValue.trim(), config);
906
+ currentLine = '';
907
+ continue;
908
+ }
909
+ }
910
+
978
911
  if (!inRuleBlock) {
979
912
  // 新规则开始
980
913
  currentRule = {
981
914
  selector: currentLine.trim(),
982
- properties: [],
915
+ properties: {},
983
916
  children: []
984
917
  };
985
918
  stack.push(currentRule);
986
919
  inRuleBlock = true;
920
+ isGlobalScope = false; // 进入选择器块,不再是全局作用域
987
921
  } else {
988
922
  // 嵌套规则开始,需要先处理当前行的属性
989
923
  if (currentLine.trim() && currentLine.includes(':')) {
@@ -992,21 +926,21 @@ function parseNestedRules(cssText, config, aliases, macros) {
992
926
  const key = Object.keys(obj)[0];
993
927
  const value = processCSSValue(obj[key], config);
994
928
  if (currentRule) {
995
- currentRule.properties.push(!value.length ? key : `${key}: ${value}`);
929
+ currentRule.properties[key] = value;
996
930
  }
997
931
  });
998
932
  }
999
933
  // 开始嵌套规则
1000
934
  const nestedRule = {
1001
935
  selector: currentLine.trim(),
1002
- properties: [],
936
+ properties: {},
1003
937
  children: []
1004
938
  };
1005
939
  stack.push(nestedRule);
1006
940
  currentRule = nestedRule;
1007
941
  }
1008
942
  currentLine = '';
1009
- } else if (charCode === 125) { // 125: "}"的码点"
943
+ } else if (charCode === 125) { // 125: "}"的码点
1010
944
  braceDepth--;
1011
945
 
1012
946
  // 处理当前行的属性(在}之前的属性)
@@ -1016,7 +950,7 @@ function parseNestedRules(cssText, config, aliases, macros) {
1016
950
  const key = Object.keys(obj)[0];
1017
951
  const value = processCSSValue(obj[key], config);
1018
952
  if (currentRule) {
1019
- currentRule.properties.push(!value.length ? key : `${key}: ${value}`);
953
+ currentRule.properties[key] = value;
1020
954
  }
1021
955
  });
1022
956
  }
@@ -1028,6 +962,7 @@ function parseNestedRules(cssText, config, aliases, macros) {
1028
962
  rootRules.push(finishedRule);
1029
963
  inRuleBlock = false;
1030
964
  currentRule = null;
965
+ isGlobalScope = true; // 回到全局作用域
1031
966
  } else {
1032
967
  const parentRule = stack[stack.length - 1];
1033
968
  if (!parentRule.children) {
@@ -1041,18 +976,28 @@ function parseNestedRules(cssText, config, aliases, macros) {
1041
976
 
1042
977
  if (braceDepth === 0) {
1043
978
  inRuleBlock = false;
979
+ isGlobalScope = true;
1044
980
  }
1045
981
  } else if (charCode === 10 || charCode === 59) {
1046
- // 行结束,处理当前行的属性
982
+ // 行结束,处理当前行的属性或变量
1047
983
  if (inRuleBlock && currentLine.trim() && currentLine.includes(':')) {
1048
984
  const parsed = parseSingleLineCSS(currentLine.trim(), aliases, macros);
1049
985
  parsed.forEach(obj => {
1050
986
  const key = Object.keys(obj)[0];
1051
987
  const value = processCSSValue(obj[key], config);
1052
988
  if (currentRule) {
1053
- currentRule.properties.push(!value.length ? key : `${key}: ${value}`);
989
+ currentRule.properties[key] = value;
1054
990
  }
1055
991
  });
992
+ } else if (isGlobalScope && currentLine.trim()) {
993
+ // 全局作用域中检查变量定义
994
+ const varMatch = currentLine.trim().match(/^\$([a-zA-Z_][a-zA-Z0-9_]*)\s*:\s*(.+?);?$/);
995
+ if (varMatch) {
996
+ const [, varName, varValue] = varMatch;
997
+ globalVariables[varName] = processCSSValue(varValue.trim(), config);
998
+ currentLine = '';
999
+ continue;
1000
+ }
1056
1001
  }
1057
1002
  currentLine = '';
1058
1003
  } else {
@@ -1060,18 +1005,40 @@ function parseNestedRules(cssText, config, aliases, macros) {
1060
1005
  }
1061
1006
  }
1062
1007
 
1063
- // 处理最后一行
1064
- if (inRuleBlock && currentLine.trim() && currentLine.includes(':')) {
1008
+ // 处理最后一行(可能在全局作用域中的变量)
1009
+ if (isGlobalScope && currentLine.trim()) {
1010
+ const varMatch = currentLine.trim().match(/^\$([a-zA-Z_][a-zA-Z0-9_]*)\s*:\s*(.+?);?$/);
1011
+ if (varMatch) {
1012
+ const [, varName, varValue] = varMatch;
1013
+ globalVariables[varName] = processCSSValue(varValue.trim(), config);
1014
+ }
1015
+ } else if (inRuleBlock && currentLine.trim() && currentLine.includes(':')) {
1065
1016
  const parsed = parseSingleLineCSS(currentLine.trim(), aliases, macros);
1066
1017
  parsed.forEach(obj => {
1067
1018
  const key = Object.keys(obj)[0];
1068
1019
  const value = processCSSValue(obj[key], config);
1069
1020
  if (currentRule) {
1070
- currentRule.properties.push(!value.length ? key : `${key}: ${value}`);
1021
+ currentRule.properties[key] = value;
1071
1022
  }
1072
1023
  });
1073
1024
  }
1074
1025
 
1026
+ // 如果存在全局变量,创建:root规则并添加到rootRules开头
1027
+ if (Object.keys(globalVariables).length > 0) {
1028
+ const rootVarsRule = {
1029
+ selector: config.rootSelector,
1030
+ properties: {},
1031
+ children: []
1032
+ };
1033
+ // 将变量转换为CSS属性
1034
+ Object.entries(globalVariables).forEach(([name, value]) => {
1035
+ rootVarsRule.properties["--" + name] = value;
1036
+ });
1037
+
1038
+ // 添加到rootRules的开头
1039
+ rootRules.unshift(rootVarsRule);
1040
+ }
1041
+
1075
1042
  return convertRulesToCSS(rootRules, config, '', aliases, macros);
1076
1043
  }
1077
1044
 
@@ -1102,15 +1069,13 @@ function parseNestedRules(cssText, config, aliases, macros) {
1102
1069
 
1103
1070
  fullSelector = fullSelector;
1104
1071
 
1105
- if (rule.properties.length > 0) {
1072
+ if (Object.keys(rule.properties).length > 0) {
1106
1073
  result += (isRootAt ? " ".repeat(config.indentSize) : '') + fullSelector + ' {\n';
1107
- for (const prop of rule.properties) {
1108
- const parsed = parseSingleLineCSS(prop, aliases, macros);
1109
- parsed.forEach(obj => {
1110
- const key = Object.keys(obj)[0];
1111
- const value = processCSSValue(obj[key], config);
1112
- result += (isRootAt ? " ".repeat(config.indentSize) : '') + " ".repeat(config.indentSize) + (!value.length ? key : `${key}: ${value};\n`);
1113
- });
1074
+ for (let key in rule.properties) {
1075
+ if (rule.properties.hasOwnProperty(key)) {
1076
+ const value = processCSSValue(rule.properties[key], config);
1077
+ result += (isRootAt ? " ".repeat(config.indentSize) : '') + " ".repeat(config.indentSize) + (!value.length ? `${key}\n` : `${key}: ${value};\n`);
1078
+ }
1114
1079
  }
1115
1080
  result += isRootAt ? " ".repeat(config.indentSize) + '}\n' : '}\n\n';
1116
1081
  }
@@ -1141,24 +1106,6 @@ function parseNestedRules(cssText, config, aliases, macros) {
1141
1106
  return result;
1142
1107
  }
1143
1108
 
1144
- /**
1145
- * 生成根规则
1146
- */
1147
- function generateRootRule(variables, config) {
1148
- if (Object.keys(variables).length === 0) {
1149
- return '';
1150
- }
1151
-
1152
- const declarations = Object.entries(variables)
1153
- .map(([name, value]) => {
1154
- const processedValue = processCSSValue(value, config);
1155
- return " ".repeat(config.indentSize) + `--${name}: ${processedValue};`;
1156
- })
1157
- .join('\n');
1158
-
1159
- return `${config.rootSelector} {\n${declarations}\n}\n\n`;
1160
- }
1161
-
1162
1109
  /**
1163
1110
  * 处理 @import 语句
1164
1111
  */
@@ -1293,36 +1240,29 @@ function parseNestedRules(cssText, config, aliases, macros) {
1293
1240
  macroRegistry.set(name, macro);
1294
1241
  }
1295
1242
  }
1296
-
1297
- const { globalVariables, selectorVariables, cssWithoutVars } =
1298
- extractVariablesAndCSS(cssWithMacros, finalConfig);
1299
1243
 
1300
- let processedCSS = cssWithoutVars.trim();
1301
- if (finalConfig.enableNesting && cssWithoutVars.includes('{')) {
1244
+ let processedCSS = cssWithMacros.trim();
1245
+ if (finalConfig.enableNesting && cssWithMacros.includes('{')) {
1302
1246
  try {
1303
- processedCSS = parseNestedRules(cssWithoutVars, finalConfig, aliases, macros);
1247
+ processedCSS = parseNestedRules(cssWithMacros, finalConfig, aliases, macros);
1304
1248
  } catch (error) {
1305
1249
  console.warn('嵌套解析失败,使用原始CSS:', error);
1306
1250
  }
1307
1251
  }
1308
1252
 
1309
- const rootRule = generateRootRule(globalVariables, finalConfig);
1310
-
1311
1253
  let finalCSS = processedCSS;
1312
1254
 
1313
1255
  finalCSS = replaceVariableUses(finalCSS, finalConfig);
1314
-
1315
- let fullCSS = rootRule + finalCSS;
1316
1256
 
1317
1257
  for (const [name, plugin] of pluginMap) {
1318
1258
  try {
1319
- fullCSS = plugin.convert(fullCSS, finalConfig);
1259
+ finalCSS = plugin.convert(finalCSS, finalConfig);
1320
1260
  } catch (error) {
1321
1261
  console.error('插件处理失败:', error);
1322
1262
  }
1323
1263
  }
1324
1264
 
1325
- return fullCSS;
1265
+ return finalCSS;
1326
1266
  }
1327
1267
 
1328
1268
  /**
@@ -1616,6 +1556,48 @@ function parseNestedRules(cssText, config, aliases, macros) {
1616
1556
  }
1617
1557
  }
1618
1558
  };
1559
+
1560
+ /**
1561
+ * Styimat 插件基类
1562
+ */
1563
+ api.Plugin = class {
1564
+ /**
1565
+ * 插件名称
1566
+ */
1567
+ name = 'Plugin';
1568
+
1569
+ /**
1570
+ * 构造函数 - use时调用
1571
+ */
1572
+ constructor() {
1573
+ this.createdAt = Date.now();
1574
+ this.install();
1575
+ }
1576
+
1577
+ /**
1578
+ * 下载插件时调用
1579
+ */
1580
+ install() {
1581
+ // 清理资源
1582
+ }
1583
+
1584
+ /**
1585
+ * 卸载插件时调用
1586
+ */
1587
+ destroy() {
1588
+ // 清理资源
1589
+ }
1590
+
1591
+ /**
1592
+ * CSS 转换方法 - 必须由子类实现
1593
+ * @param {string} cssText - CSS 文本
1594
+ * @param {Object} config - 配置
1595
+ * @returns {string} 转换结果
1596
+ */
1597
+ convert(cssText, config) {
1598
+ throw new Error(`${this.name}.convert() 必须被实现`);
1599
+ }
1600
+ };
1619
1601
 
1620
1602
  // 创建主函数
1621
1603
  const styimat = async function(...args) {
@@ -1626,7 +1608,7 @@ function parseNestedRules(cssText, config, aliases, macros) {
1626
1608
  const firstArg = args[0];
1627
1609
 
1628
1610
  if (typeof firstArg === 'string') {
1629
- const result = await convert(firstArg, { ...defaultConfig, ...args[1] });
1611
+ const result = await convert(firstArg, args[1]);
1630
1612
 
1631
1613
  if (result && typeof result.then === 'function') {
1632
1614
  return result;
@@ -1658,7 +1640,7 @@ function parseNestedRules(cssText, config, aliases, macros) {
1658
1640
  } else if (Array.isArray(value)) {
1659
1641
  result = value.join(' ');
1660
1642
  } else {
1661
- result = String(value != null ? value : '');
1643
+ result = String(value != null ? value : 'none');
1662
1644
  }
1663
1645
 
1664
1646
  cssText += result + strings[i + 1];
@@ -1,25 +1,18 @@
1
1
  /*!
2
2
  * MIT License
3
3
  * Copyright (c) 2025 王小玗
4
- */const styimat=(function(){let M={rootSelector:":root",variablePrefix:"--",preserveOriginal:!1,indentSize:4,enableNesting:!0,autoProcessStyleTags:!0,styleTagAttribute:"e",convertLabToRGB:!0,convertLchToRGB:!0,enableP3:!0,enableMath:!0,importBaseUrl:"",importCache:!0,importTimeout:5e3,enableAlias:!0,enableMacros:!0};const C={IMPORT:/@import\s+([^;]+?)\s*;/g,ALIAS:/^@alias\s+([a-zA-Z_][a-zA-Z0-9_]*)\s+(.+?)\s*;$/,MACRO:/^@macro\s+([a-zA-Z_][a-zA-Z0-9_]*)\s*\(([^)]*)\)\s*\{$/,SPECHAR:/[.*+?^${}()|[\]\\]/g,COMMENT:/\/\*[\s\S]*?\*\//g,MATH_SYMBOL:/([\da-z])([+-])(-?[\da-z])/g,MATH:/math\(([^)]+)\)/gi,COLOR:/(lab|lch)\([^)]+\)/gi,HEXLAB:/lab#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/gi,HEXLCH:/lch#([0-9a-f]{2})([0-9a-f]{2})(\d{1,3})/gi,SPACE:/\s+/g,AND:/&/g,HYPHEN:/-([a-z])/g,VARIABLE:/(?:\$\$|\$)([a-zA-Z_][a-zA-Z0-9_]*)(?=[^a-zA-Z0-9_])/g};let T=null;const O=new Map,H=new Map,S=new Map,L=new Map;function E(n,e=`
5
- `){const r=[],t=e.charCodeAt(0);let s=0;for(let o=0,c=n.length;o<c;o++)n.charCodeAt(o)===t&&((o>s||n.charAt(s)!=="\r")&&r.push(n.slice(s,o)),s=o+1);return s<n.length?r.push(n.substring(s)):s===n.length&&n.charCodeAt(n.length-1)===10&&r.push(""),r}function Q(n){const e={...M},r=E(n),t=[];for(let s of r){const o=s.trim();if(o.startsWith("#")){const c=o.substring(1).trim(),a=c.indexOf(" ");if(~a){const l=c.substring(0,a).trim(),u=c.substring(a+1).trim(),i=te(l);u==="true"||u==="false"?e[i]=u==="true":!isNaN(u)&&u.trim()!==""?e[i]=Number(u):e[i]=u}else console.warn(`\u65E0\u6548\u7684\u914D\u7F6E\u884C: ${o}`)}else t.push(s)}return{config:e,css:t.join(`
6
- `)}}function K(n){const e=new Map,r=E(n),t=[];for(let s of r){const o=s.trim();if(o.startsWith("@alias")){const c=o.match(C.ALIAS);if(c){const a=c[1],l=c[2];e.set(a,l);continue}}t.push(s)}return{aliases:e,css:t.join(`
7
- `)}}function W(n,e){if(!e.enableMacros)return{macros:new Map,css:n};const r=new Map,t=E(n),s=[];let o=!1,c="",a=[],l=[],u=0;for(let i of t){const h=i.trim();if(!o&&h.startsWith("@macro")){const f=h.match(C.MACRO);if(f){o=!0,c=f[1],a=E(f[2],",").map(p=>p.trim()).filter(p=>p).map(p=>{const g=E(p,":").map(b=>b.trim());return{name:g[0].slice(1),defaultValue:g[1]||null}}),l=[],u=1;continue}}if(o){for(const f of i)f==="{"&&u++,f==="}"&&u--;u===0?(r.set(c,{params:a,body:l.join(`
8
- `)}),o=!1,c="",a=[],l=[]):l.push(i);continue}s.push(i)}return{macros:r,css:s.join(`
9
- `)}}function J(n,e,r=","){const t=new Map,s=ee(n,r);for(let o=0,c=e.length;o<c;o++){const a=e[o];let l;o<s.length?l=s[o]:a.defaultValue!==null?l=a.defaultValue:l="none",t.set(a.name,l)}return t}function ee(n,e){const r=[];let t="",s=!1,o="",c=0,a=0;for(let l=0,u=n.length;l<u;l++){const i=n[l];(i==='"'||i==="'")&&!s?(s=!0,o=i):i===o&&s&&(s=!1,o=""),s||(i==="("&&c++,i===")"&&c--,i==="["&&a++,i==="]"&&a--),i===e&&!s&&c===0&&a===0?(r.push(t.trim()),t=""):t+=i}return t.trim()&&r.push(t.trim()),r}function N(n,e,r){let t=n;return t=t.replace(C.VARIABLE,(s,o)=>e.get(o)?e.get(o):s),t=$(t,r),t}function te(n){return n.replace(C.HYPHEN,function(e,r){return r.toUpperCase()})}function V(){if(T!==null)return T;if(typeof window>"u"||!window.CSS)return T=!1,!1;try{T=CSS.supports("color","color(display-p3 1 0 0)")}catch{T=!1}return T}function P(n,e,r){let t=n.trim();if(t.endsWith(";")&&(t=t.slice(0,-1)),!t)return[];const s=[];let o="",c=0,a=!1,l="";for(let i=0,h=t.length;i<h;i++){const f=t[i];(f==='"'||f==="'")&&!a?(a=!0,l=f):f===l&&a&&(a=!1,l=""),a||(f==="("?c++:f===")"&&c--),f===";"&&!a&&c===0?o.trim()&&(s.push(o.trim()),o=""):o+=f}o.trim()&&s.push(o.trim());const u=[];for(let i of s){if(i=i.replace(C.COMMENT,""),!i.trim())continue;const h=ne(i);if(!~h){console.warn(`\u65E0\u6548\u7684CSS\u58F0\u660E: "${i}"`);continue}let f=i.substring(0,h).trim(),p=i.substring(h+1).trim();if(p.endsWith(";")&&(p=p.slice(0,-1).trim()),f.startsWith("$")&&(f="--"+f.slice(1)),f=e.get(f)??f,f.startsWith("@")&&r.get(f.slice(1))){const g=r.get(f.slice(1)),b=J(p,g.params," ");f=N(g.body,b,D),p=""}u.push({[f]:p})}return u}function ne(n){let e=!1,r="";for(let t=0,s=n.length;t<s;t++){const o=n[t];if((o==='"'||o==="'")&&!e?(e=!0,r=o):o===r&&e&&(e=!1,r=""),o===":"&&!e)return t}return-1}function j(n,e){if(!e.enableMath)return`math(${n})`;let r=n.replace(C.SPACE,"");return re(r,e.enableMath)}function re(n,e){return`calc(${n.replace(C.MATH_SYMBOL,"$1 $2 $3")})`}function se(n,e){if(!e.enableMath)return n;let r=n;return r=(s=>s.replace(C.MATH,(o,c)=>j(c,e)))(r),r}function oe(n,e){if(!e.convertLabToRGB&&!e.convertLchToRGB)return n;let r=n;r=ae(r,e);const t=new Map,s=c=>c.replace(C.COLOR,a=>{if(t.has(a))return t.get(a);let l=a;return a.toLowerCase().startsWith("lab(")?e.convertLabToRGB&&(l=ce(a,e)):a.toLowerCase().startsWith("lch(")&&e.convertLchToRGB&&(l=le(a,e)),t.set(a,l),l});let o;do o=r,r=s(r);while(r!==o);return r}function ae(n,e){let r=n;const t=new Map;return r=r.replace(C.HEXLAB,(s,o,c,a)=>{if(t.has(s))return t.get(s);try{const l=parseInt(o,16)/255*100,u=(parseInt(c,16)-128)*1.5,i=(parseInt(a,16)-128)*1.5,h=R(l,u,i,e);return t.set(s,h),h}catch(l){return console.warn(`\u65E0\u6CD5\u89E3\u6790lab#\u5341\u516D\u8FDB\u5236\u989C\u8272: ${s}`,l),s}}),r=r.replace(C.HEXLCH,(s,o,c,a)=>{if(t.has(s))return t.get(s);try{const l=parseInt(o,16)/255*100,u=parseInt(c,16)/255*150,i=parseInt(a)/100*360,h=v(l,u,i),f=R(h.L,h.a,h.b,e);return t.set(s,f),f}catch(l){return console.warn(`\u65E0\u6CD5\u89E3\u6790lch#\u5341\u516D\u8FDB\u5236\u989C\u8272: ${s}`,l),s}}),r}function ce(n,e){const r=/lab\(\s*([\d.]+)(%?)\s+([\d.-]+)\s+([\d.-]+)(?:\s*\/\s*([\d.%]+))?\s*\)/i,t=n.match(r);if(!t)return n;try{let s=parseFloat(t[1]);t[2]==="%"?s=s:(s<0&&(s=0),s>100&&(s=100));const o=parseFloat(t[3]),c=parseFloat(t[4]),a=t[5]!==void 0?t[5].includes("%")?parseFloat(t[5])/100:parseFloat(t[5]):null;return R(s,o,c,e,a)}catch(s){return console.warn(`\u65E0\u6CD5\u8F6C\u6362LAB\u989C\u8272: ${n}`,s),n}}function le(n,e){const r=/lch\(\s*([\d.]+)(%?)\s+([\d.]+)\s+([\d.]+)(deg)?(?:\s*\/\s*([\d.%]+))?\s*\)/i,t=n.match(r);if(!t)return n;try{let s=parseFloat(t[1]);t[2]==="%"?s=s:(s<0&&(s=0),s>100&&(s=100));const o=parseFloat(t[3]);let c=parseFloat(t[4]);o<0&&console.warn(`LCH\u4E2D\u7684C\u503C\u4E0D\u80FD\u4E3A\u8D1F: ${o}`),c=(c%360+360)%360;const a=v(s,o,c),l=t[6]!==void 0?t[6].includes("%")?parseFloat(t[6])/100:parseFloat(t[6]):null;return R(a.L,a.a,a.b,e,l)}catch(s){return console.warn(`\u65E0\u6CD5\u8F6C\u6362LCH\u989C\u8272: ${n}`,s),n}}function v(n,e,r){const t=r*Math.PI/180,s=e*Math.cos(t),o=e*Math.sin(t);return{L:n,a:s,b:o}}function w(n,e,r){const t=(d,m,y)=>{const q=(d+16)/116,I=m/500+q,z=q-y/200,ge=I**3>.008856?I**3:(116*I-16)/903.3,be=d>903.3*.008856?((d+16)/116)**3:d/903.3,ye=z**3>.008856?z**3:(116*z-16)/903.3;return[ge*.95047,be*1,ye*1.08883]},s=(d,m,y)=>{const A=[[3.2404542,-1.5371385,-.4985314],[-.969266,1.8760108,.041556],[.0556434,-.2040259,1.0572252]],_=A[0][0]*d+A[0][1]*m+A[0][2]*y,U=A[1][0]*d+A[1][1]*m+A[1][2]*y,Y=A[2][0]*d+A[2][1]*m+A[2][2]*y;return[_,U,Y]},o=d=>{const m=d<0?-1:1,y=m*d;return y<=.0031308?12.92*y:m*(1.055*Math.pow(y,.4166666666666667)-.055)},c=d=>Math.max(0,Math.min(255,d*255|0)),[a,l,u]=t(n,e,r),[i,h,f]=s(a,l,u),p=o(i),g=o(h),b=o(f);return{r:c(p),g:c(g),b:c(b)}}function x(n,e,r){const t=(a,l,u)=>{const b=(a+16)/116,d=l/500+b,m=b-u/200,y=d**3>.008856?d**3:(116*d-16)/903.3,A=a>903.3*.008856?((a+16)/116)**3:a/903.3,_=m**3>.008856?m**3:(116*m-16)/903.3;return[y*.95047,A*1,_*1.08883]},s=(a,l,u)=>{const i=[[2.493496911941425,-.9313836179191239,-.40271078445071684],[-.8294889695615747,1.7626640603183463,.023624685841943577],[.03584583024378447,-.07617238926804182,.9568845240076872]],h=i[0][0]*a+i[0][1]*l+i[0][2]*u,f=i[1][0]*a+i[1][1]*l+i[1][2]*u,p=i[2][0]*a+i[2][1]*l+i[2][2]*u;return[h,f,p]},o=a=>{const l=a<0?-1:1,u=Math.abs(a);return u<=.0031308?l*12.92*u:l*(1.055*Math.pow(u,.4166666666666667)-.055)},c=a=>Math.max(0,Math.min(255,a*255|0));try{const[a,l,u]=t(n,e,r),[i,h,f]=s(a,l,u),p=o(i),g=o(h),b=o(f);return{r:Math.max(0,Math.min(1,p)),g:Math.max(0,Math.min(1,g)),b:Math.max(0,Math.min(1,b))}}catch(a){console.warn("P3\u8F6C\u6362\u5931\u8D25:",a);const l=w(n,e,r);return{r:l.r/255,g:l.g/255,b:l.b/255}}}function R(n,e,r,t,s=null){if(!t.enableP3||!V()){const o=w(n,e,r);return s!==null?`rgba(${o.r}, ${o.g}, ${o.b}, ${s})`:`rgb(${o.r}, ${o.g}, ${o.b})`}else{const o=x(n,e,r);return s!==null?`color(display-p3 ${o.r.toFixed(4)} ${o.g.toFixed(4)} ${o.b.toFixed(4)} / ${s})`:`color(display-p3 ${o.r.toFixed(4)} ${o.g.toFixed(4)} ${o.b.toFixed(4)})`}}function $(n,e){let r=n;return e.enableMath&&(r=se(r,e)),(e.convertLabToRGB||e.convertLchToRGB)&&(r=oe(r,e)),r}function ie(n,e){const r=E(n),t={},s=new Map;let o="",c=!1,a=0,l=null;for(let u of r){const i=u.trim(),h=i.match(/^\$([a-zA-Z_][a-zA-Z0-9_]*)\s*:\s*(.+?);?$/);if(h){const[,f,p]=h,g=$(p.trim(),e);l||(t[f]=g);continue}if(i.endsWith("{")){l=i.slice(0,-1).trim(),c=!0,o+=u+`
10
- `;continue}if(i==="}"){if(c&&l&&s.has(l)){const f=s.get(l),p=" ".repeat(a);for(const[g,b]of Object.entries(f))o+=`${p} --${g}: ${b};
11
- `}c=!1,l=null}o+=u+`
12
- `,u.includes("{")&&(a+=e.indentSize),u.includes("}")&&(a=Math.max(0,a-e.indentSize))}return o=n,{globalVariables:t,selectorVariables:s,cssWithoutVars:o.trim()}}function ue(n,e,r,t){const s=[],o=[];let c=null,a="",l=!1,u=0;for(let i=0,h=n.length;i<h;i++){const f=n[i],p=n.charCodeAt(i);if(p===123){if(u++,!l)c={selector:a.trim(),properties:[],children:[]},o.push(c),l=!0;else{a.trim()&&a.includes(":")&&P(a.trim(),r,t).forEach(d=>{const m=Object.keys(d)[0],y=$(d[m],e);c&&c.properties.push(y.length?`${m}: ${y}`:m)});const g={selector:a.trim(),properties:[],children:[]};o.push(g),c=g}a=""}else if(p===125){u--,a.trim()&&a.includes(":")&&P(a.trim(),r,t).forEach(d=>{const m=Object.keys(d)[0],y=$(d[m],e);c&&c.properties.push(y.length?`${m}: ${y}`:m)});const g=o.pop();if(o.length===0)s.push(g),l=!1,c=null;else{const b=o[o.length-1];b.children||(b.children=[]),b.children.push(g),c=b}a="",u===0&&(l=!1)}else p===10||p===59?(l&&a.trim()&&a.includes(":")&&P(a.trim(),r,t).forEach(b=>{const d=Object.keys(b)[0],m=$(b[d],e);c&&c.properties.push(m.length?`${d}: ${m}`:d)}),a=""):a+=f}return l&&a.trim()&&a.includes(":")&&P(a.trim(),r,t).forEach(h=>{const f=Object.keys(h)[0],p=$(h[f],e);c&&c.properties.push(p.length?`${f}: ${p}`:f)}),G(s,e,"",r,t)}function G(n,e,r="",t,s,o=!1){let c="";for(const a of n){const l=a.selector.startsWith("@");l&&(c+=a.selector+` {
13
- `);let u=a.selector;if(r&&(u.includes("&")?u=u.replace(C.AND,r):u.trim().startsWith(":")?u=r+u:u=r+" "+u),u=u,a.properties.length>0){c+=(o?" ".repeat(e.indentSize):"")+u+` {
14
- `;for(const i of a.properties)P(i,t,s).forEach(f=>{const p=Object.keys(f)[0],g=$(f[p],e);c+=(o?" ".repeat(e.indentSize):"")+" ".repeat(e.indentSize)+(g.length?`${p}: ${g};
15
- `:p)});c+=o?" ".repeat(e.indentSize)+`}
4
+ */const styimat=(function(){let M={rootSelector:":root",variablePrefix:"--",preserveOriginal:!1,indentSize:4,enableNesting:!0,autoProcessStyleTags:!0,styleTagAttribute:"e",convertLabToRGB:!0,convertLchToRGB:!0,enableP3:!0,enableMath:!0,importBaseUrl:"",importCache:!0,importTimeout:5e3,enableAlias:!0,enableMacros:!0};const A={IMPORT:/@import\s+([^;]+?)\s*;/g,ALIAS:/^@alias\s+([a-zA-Z_][a-zA-Z0-9_]*)\s+(.+?)\s*;$/,MACRO:/^@macro\s+([a-zA-Z_][a-zA-Z0-9_]*)\s*\(([^)]*)\)\s*\{$/,COMMENT:/\/\*[\s\S]*?\*\//g,MATH_SYMBOL:/([\da-z])([+-])(-?[\da-z])/g,MATH:/math\(([^)]+)\)/gi,COLOR:/(lab|lch)\([^)]+\)/gi,HEXLAB:/lab#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/gi,HEXLCH:/lch#([0-9a-f]{2})([0-9a-f]{2})(\d{1,3})/gi,SPACE:/\s+/g,AND:/&/g,HYPHEN:/-([a-z])/g,VARIABLE:/(?:\$\$|\$)([a-zA-Z_][a-zA-Z0-9_]*)(?=[^a-zA-Z0-9_])/g};let E=null;const B=new Map,_=new Map,L=new Map,v=new Map;function R(n,e=`
5
+ `){const r=[],t=e.charCodeAt(0);let s=0;for(let o=0,l=n.length;o<l;o++)n.charCodeAt(o)===t&&((o>s||n.charAt(s)!=="\r")&&r.push(n.slice(s,o)),s=o+1);return s<n.length?r.push(n.substring(s)):s===n.length&&n.charCodeAt(n.length-1)===10&&r.push(""),r}function K(n){const e={...M},r=R(n),t=[];for(let s of r){const o=s.trim();if(o.startsWith("#")){const l=o.substring(1).trim(),a=l.indexOf(" ");if(~a){const c=l.substring(0,a).trim(),u=l.substring(a+1).trim(),i=re(c);u==="true"||u==="false"?e[i]=u==="true":!isNaN(u)&&u.trim()!==""?e[i]=Number(u):e[i]=u}else console.warn(`\u65E0\u6548\u7684\u914D\u7F6E\u884C: ${o}`)}else t.push(s)}return{config:e,css:t.join(`
6
+ `)}}function J(n){const e=new Map,r=R(n),t=[];for(let s of r){const o=s.trim();if(o.startsWith("@alias")){const l=o.match(A.ALIAS);if(l){const a=l[1],c=l[2];e.set(a,c);continue}}t.push(s)}return{aliases:e,css:t.join(`
7
+ `)}}function V(n,e){if(!e.enableMacros)return{macros:new Map,css:n};const r=new Map,t=R(n),s=[];let o=!1,l="",a=[],c=[],u=0;for(let i of t){const p=i.trim();if(!o&&p.startsWith("@macro")){const f=p.match(A.MACRO);if(f){o=!0,l=f[1],a=R(f[2],",").map(h=>h.trim()).filter(h=>h).map(h=>{const b=R(h,":").map(C=>C.trim());return{name:b[0].slice(1),defaultValue:b[1]||null}}),c=[],u=1;continue}}if(o){for(const f of i)f==="{"&&u++,f==="}"&&u--;u===0?(r.set(l,{params:a,body:c.join(`
8
+ `)}),o=!1,l="",a=[],c=[]):c.push(i);continue}s.push(i)}return{macros:r,css:s.join(`
9
+ `)}}function ee(n,e,r=","){const t=new Map,s=te(n,r);for(let o=0,l=e.length;o<l;o++){const a=e[o];let c;o<s.length?c=s[o]:a.defaultValue!==null?c=a.defaultValue:c="none",t.set(a.name,c)}return t}function te(n,e){const r=[];let t="",s=!1,o="",l=0,a=0;for(let c=0,u=n.length;c<u;c++){const i=n[c];(i==='"'||i==="'")&&!s?(s=!0,o=i):i===o&&s&&(s=!1,o=""),s||(i==="("&&l++,i===")"&&l--,i==="["&&a++,i==="]"&&a--),i===e&&!s&&l===0&&a===0?(r.push(t.trim()),t=""):t+=i}return t.trim()&&r.push(t.trim()),r}function W(n,e,r){let t=n;return t=t.replace(A.VARIABLE,(s,o)=>e.get(o)?e.get(o):s),t=w(t,r),t}function re(n){return n.replace(A.HYPHEN,function(e,r){return r.toUpperCase()})}function k(){if(E!==null)return E;if(typeof window>"u"||!window.CSS)return E=!1,!1;try{E=CSS.supports("color","color(display-p3 1 0 0)")}catch{E=!1}return E}function F(n,e,r){let t=n.trim();if(t.endsWith(";")&&(t=t.slice(0,-1)),!t)return[];const s=[];let o="",l=0,a=!1,c="";for(let i=0,p=t.length;i<p;i++){const f=t[i];(f==='"'||f==="'")&&!a?(a=!0,c=f):f===c&&a&&(a=!1,c=""),a||(f==="("?l++:f===")"&&l--),f===";"&&!a&&l===0?o.trim()&&(s.push(o.trim()),o=""):o+=f}o.trim()&&s.push(o.trim());const u=[];for(let i of s){if(i=i.replace(A.COMMENT,""),!i.trim())continue;const p=ne(i);if(!~p){console.warn(`\u65E0\u6548\u7684CSS\u58F0\u660E: "${i}"`);continue}let f=i.substring(0,p).trim(),h=i.substring(p+1).trim();if(h.endsWith(";")&&(h=h.slice(0,-1).trim()),f.startsWith("$")&&(f="--"+f.slice(1)),f=e.get(f)??f,f.startsWith("@")&&r.get(f.slice(1))){const b=r.get(f.slice(1)),C=ee(h,b.params," ");f=W(b.body,C,D),h=""}u.push({[f]:h})}return u}function ne(n){let e=!1,r="";for(let t=0,s=n.length;t<s;t++){const o=n[t];if((o==='"'||o==="'")&&!e?(e=!0,r=o):o===r&&e&&(e=!1,r=""),o===":"&&!e)return t}return-1}function Z(n,e){let r=n.replace(A.SPACE,"");return se(r)}function se(n){return`calc(${n.replace(A.MATH_SYMBOL,"$1 $2 $3")})`}function oe(n,e){let r=n;return r=(s=>s.replace(A.MATH,(o,l)=>Z(l,e)))(r),r}function ae(n,e){if(!e.convertLabToRGB&&!e.convertLchToRGB)return n;let r=n;r=ce(r,e);const t=new Map,s=l=>l.replace(A.COLOR,a=>{if(t.has(a))return t.get(a);let c=a;return a.toLowerCase().startsWith("lab(")?e.convertLabToRGB&&(c=le(a,e)):a.toLowerCase().startsWith("lch(")&&e.convertLchToRGB&&(c=ie(a,e)),t.set(a,c),c});let o;do o=r,r=s(r);while(r!==o);return r}function ce(n,e){let r=n;const t=new Map;return r=r.replace(A.HEXLAB,(s,o,l,a)=>{if(t.has(s))return t.get(s);try{const c=parseInt(o,16)/255*100,u=(parseInt(l,16)-128)*1.5,i=(parseInt(a,16)-128)*1.5,p=P(c,u,i,e);return t.set(s,p),p}catch(c){return console.warn(`\u65E0\u6CD5\u89E3\u6790lab#\u5341\u516D\u8FDB\u5236\u989C\u8272: ${s}`,c),s}}),r=r.replace(A.HEXLCH,(s,o,l,a)=>{if(t.has(s))return t.get(s);try{const c=parseInt(o,16)/255*100,u=parseInt(l,16)/255*150,i=parseInt(a)/100*360,p=T(c,u,i),f=P(p.L,p.a,p.b,e);return t.set(s,f),f}catch(c){return console.warn(`\u65E0\u6CD5\u89E3\u6790lch#\u5341\u516D\u8FDB\u5236\u989C\u8272: ${s}`,c),s}}),r}function le(n,e){const r=/lab\(\s*([\d.]+)(%?)\s+([\d.-]+)\s+([\d.-]+)(?:\s*\/\s*([\d.%]+))?\s*\)/i,t=n.match(r);if(!t)return n;try{let s=parseFloat(t[1]);t[2]!=="%"&&(s<0&&(s=0),s>100&&(s=100));const o=parseFloat(t[3]),l=parseFloat(t[4]),a=t[5]!==void 0?t[5].includes("%")?parseFloat(t[5])/100:parseFloat(t[5]):null;return P(s,o,l,e,a)}catch(s){return console.warn(`\u65E0\u6CD5\u8F6C\u6362LAB\u989C\u8272: ${n}`,s),n}}function ie(n,e){const r=/lch\(\s*([\d.]+)(%?)\s+([\d.]+)\s+([\d.]+)(deg)?(?:\s*\/\s*([\d.%]+))?\s*\)/i,t=n.match(r);if(!t)return n;try{let s=parseFloat(t[1]);t[2]==="%"?s=s:(s<0&&(s=0),s>100&&(s=100));const o=parseFloat(t[3]);let l=parseFloat(t[4]);o<0&&console.warn(`LCH\u4E2D\u7684C\u503C\u4E0D\u80FD\u4E3A\u8D1F: ${o}`),l=(l%360+360)%360;const a=T(s,o,l),c=t[6]!==void 0?t[6].includes("%")?parseFloat(t[6])/100:parseFloat(t[6]):null;return P(a.L,a.a,a.b,e,c)}catch(s){return console.warn(`\u65E0\u6CD5\u8F6C\u6362LCH\u989C\u8272: ${n}`,s),n}}function T(n,e,r){const t=r*Math.PI/180,s=e*Math.cos(t),o=e*Math.sin(t);return{L:n,a:s,b:o}}function S(n,e,r){const t=(d,m,g)=>{const Q=(d+16)/116,z=m/500+Q,N=Q-g/200,de=z**3>.008856?z**3:(116*z-16)/903.3,me=d>903.3*.008856?((d+16)/116)**3:d/903.3,ge=N**3>.008856?N**3:(116*N-16)/903.3;return[de*.95047,me*1,ge*1.08883]},s=(d,m,g)=>{const y=[[3.2404542,-1.5371385,-.4985314],[-.969266,1.8760108,.041556],[.0556434,-.2040259,1.0572252]],$=y[0][0]*d+y[0][1]*m+y[0][2]*g,Y=y[1][0]*d+y[1][1]*m+y[1][2]*g,q=y[2][0]*d+y[2][1]*m+y[2][2]*g;return[$,Y,q]},o=d=>{const m=d<0?-1:1,g=m*d;return g<=.0031308?12.92*g:m*(1.055*Math.pow(g,.4166666666666667)-.055)},l=d=>Math.max(0,Math.min(255,d*255|0)),[a,c,u]=t(n,e,r),[i,p,f]=s(a,c,u),h=o(i),b=o(p),C=o(f);return{r:l(h),g:l(b),b:l(C)}}function x(n,e,r){const t=(a,c,u)=>{const C=(a+16)/116,d=c/500+C,m=C-u/200,g=d**3>.008856?d**3:(116*d-16)/903.3,y=a>903.3*.008856?((a+16)/116)**3:a/903.3,$=m**3>.008856?m**3:(116*m-16)/903.3;return[g*.95047,y*1,$*1.08883]},s=(a,c,u)=>{const i=[[2.493496911941425,-.9313836179191239,-.40271078445071684],[-.8294889695615747,1.7626640603183463,.023624685841943577],[.03584583024378447,-.07617238926804182,.9568845240076872]],p=i[0][0]*a+i[0][1]*c+i[0][2]*u,f=i[1][0]*a+i[1][1]*c+i[1][2]*u,h=i[2][0]*a+i[2][1]*c+i[2][2]*u;return[p,f,h]},o=a=>{const c=a<0?-1:1,u=Math.abs(a);return u<=.0031308?c*12.92*u:c*(1.055*Math.pow(u,.4166666666666667)-.055)},l=a=>Math.max(0,Math.min(255,a*255|0));try{const[a,c,u]=t(n,e,r),[i,p,f]=s(a,c,u),h=o(i),b=o(p),C=o(f);return{r:Math.max(0,Math.min(1,h)),g:Math.max(0,Math.min(1,b)),b:Math.max(0,Math.min(1,C))}}catch(a){console.warn("P3\u8F6C\u6362\u5931\u8D25:",a);const c=S(n,e,r);return{r:c.r/255,g:c.g/255,b:c.b/255}}}function P(n,e,r,t,s=null){if(!t.enableP3||!k()){const o=S(n,e,r);return s!==null?`rgba(${o.r}, ${o.g}, ${o.b}, ${s})`:`rgb(${o.r}, ${o.g}, ${o.b})`}else{const o=x(n,e,r);return s!==null?`color(display-p3 ${o.r.toFixed(4)} ${o.g.toFixed(4)} ${o.b.toFixed(4)} / ${s})`:`color(display-p3 ${o.r.toFixed(4)} ${o.g.toFixed(4)} ${o.b.toFixed(4)})`}}function w(n,e){let r=n;return e.enableMath&&(r=oe(r,e)),(e.convertLabToRGB||e.convertLchToRGB)&&(r=ae(r,e)),r}function ue(n,e,r,t){const s=[],o=[],l={};let a=null,c="",u=!1,i=0,p=!0;for(let f=0,h=n.length;f<h;f++){const b=n[f],C=n.charCodeAt(f);if(C===123){if(i++,p&&c.trim()){const d=c.trim().match(/^\$([a-zA-Z_][a-zA-Z0-9_]*)\s*:\s*(.+?);?$/);if(d){const[,m,g]=d;l[m]=w(g.trim(),e),c="";continue}}if(!u)a={selector:c.trim(),properties:{},children:[]},o.push(a),u=!0,p=!1;else{c.trim()&&c.includes(":")&&F(c.trim(),r,t).forEach(g=>{const y=Object.keys(g)[0],$=w(g[y],e);a&&(a.properties[y]=$)});const d={selector:c.trim(),properties:{},children:[]};o.push(d),a=d}c=""}else if(C===125){i--,c.trim()&&c.includes(":")&&F(c.trim(),r,t).forEach(g=>{const y=Object.keys(g)[0],$=w(g[y],e);a&&(a.properties[y]=$)});const d=o.pop();if(o.length===0)s.push(d),u=!1,a=null,p=!0;else{const m=o[o.length-1];m.children||(m.children=[]),m.children.push(d),a=m}c="",i===0&&(u=!1,p=!0)}else if(C===10||C===59){if(u&&c.trim()&&c.includes(":"))F(c.trim(),r,t).forEach(m=>{const g=Object.keys(m)[0],y=w(m[g],e);a&&(a.properties[g]=y)});else if(p&&c.trim()){const d=c.trim().match(/^\$([a-zA-Z_][a-zA-Z0-9_]*)\s*:\s*(.+?);?$/);if(d){const[,m,g]=d;l[m]=w(g.trim(),e),c="";continue}}c=""}else c+=b}if(p&&c.trim()){const f=c.trim().match(/^\$([a-zA-Z_][a-zA-Z0-9_]*)\s*:\s*(.+?);?$/);if(f){const[,h,b]=f;l[h]=w(b.trim(),e)}}else u&&c.trim()&&c.includes(":")&&F(c.trim(),r,t).forEach(h=>{const b=Object.keys(h)[0],C=w(h[b],e);a&&(a.properties[b]=C)});if(Object.keys(l).length>0){const f={selector:e.rootSelector,properties:{},children:[]};Object.entries(l).forEach(([h,b])=>{f.properties["--"+h]=b}),s.unshift(f)}return G(s,e,"",r,t)}function G(n,e,r="",t,s,o=!1){let l="";for(const a of n){const c=a.selector.startsWith("@");c&&(l+=a.selector+` {
10
+ `);let u=a.selector;if(r&&(u.includes("&")?u=u.replace(A.AND,r):u.trim().startsWith(":")?u=r+u:u=r+" "+u),u=u,Object.keys(a.properties).length>0){l+=(o?" ".repeat(e.indentSize):"")+u+` {
11
+ `;for(let i in a.properties)if(a.properties.hasOwnProperty(i)){const p=w(a.properties[i],e);l+=(o?" ".repeat(e.indentSize):"")+" ".repeat(e.indentSize)+(p.length?`${i}: ${p};
12
+ `:`${i}
13
+ `)}l+=o?" ".repeat(e.indentSize)+`}
16
14
  `:`}
17
15
 
18
- `}a.children&&a.children.length>0&&(c+=G(a.children,e,l?"":u,t,s,o||l)),l&&(c+=`}
16
+ `}a.children&&a.children.length>0&&(l+=G(a.children,e,c?"":u,t,s,o||c)),c&&(l+=`}
19
17
 
20
- `)}return c}function fe(n,e){let r=n;return r=r.replace(C.VARIABLE,(t,s)=>t.startsWith("$$")?`attr(${s})`:`var(--${s})`),r=$(r,e),r}function pe(n,e){if(Object.keys(n).length===0)return"";const r=Object.entries(n).map(([t,s])=>{const o=$(s,e);return" ".repeat(e.indentSize)+`--${t}: ${o};`}).join(`
21
- `);return`${e.rootSelector} {
22
- ${r}
23
- }
24
-
25
- `}async function Z(n,e){const r=C.IMPORT;return(async s=>{const o=[],c=s.replace(r,(a,l)=>{const u=he(l,e).then(i=>Z(i,e)).catch(i=>(console.warn(`\u65E0\u6CD5\u5BFC\u5165CSS\u6587\u4EF6: ${l}`,i),""));return o.push(u),`__IMPORT_PLACEHOLDER_${o.length-1}__`});if(o.length>0){const a=await Promise.all(o);let l=c;for(let u=a.length;u--;)l=l.replace(`__IMPORT_PLACEHOLDER_${u}__`,a[u]);return l}return c})(n)}async function he(n,e){if(e.importCache&&O.has(n))return O.get(n);const r=e.importBaseUrl?new URL(n,e.importBaseUrl).href:n;let t;if(typeof process<"u"&&process.versions&&process.versions.node&&typeof require<"u")try{const o=require("fs"),c=require("path");let a=r;r.startsWith(".")&&(a=c.join(process.cwd(),r)),t=o.readFileSync(a,"utf-8")}catch(o){throw new Error(`Node.js\u6587\u4EF6\u8BFB\u53D6\u5931\u8D25: ${r} - ${o.message}`)}else try{const o=new AbortController,c=setTimeout(()=>o.abort(),e.importTimeout),a=await fetch(r,{signal:o.signal,headers:{Accept:"text/css"}});if(clearTimeout(c),!a.ok)throw new Error(`HTTP\u9519\u8BEF: ${a.status} ${a.statusText}`);t=await a.text()}catch(o){throw o.name==="AbortError"?new Error(`\u5BFC\u5165\u8D85\u65F6: ${r}`):new Error(`\u65E0\u6CD5\u83B7\u53D6CSS: ${r} - ${o.message}`)}return e.importCache&&O.set(n,t),t}async function B(n,e={}){let{config:r,css:t}=Q(n);const s={...M,...e,...r};t=await Z(t,s);let o=t,c=new Map;if(s.enableAlias){const{aliases:d,css:m}=K(o);c=d,o=m}let a=o,l=new Map;if(s.enableMacros){const{macros:d,css:m}=W(a,s);l=d,a=m;for(const[y,A]of l)S.set(y,A)}const{globalVariables:u,selectorVariables:i,cssWithoutVars:h}=ie(a,s);let f=h.trim();if(s.enableNesting&&h.includes("{"))try{f=ue(h,s,c,l)}catch(d){console.warn("\u5D4C\u5957\u89E3\u6790\u5931\u8D25\uFF0C\u4F7F\u7528\u539F\u59CBCSS:",d)}const p=pe(u,s);let g=f;g=fe(g,s);let b=p+g;for(const[d,m]of L)try{b=m.convert(b,s)}catch(y){console.error("\u63D2\u4EF6\u5904\u7406\u5931\u8D25:",y)}return b}function X(n={}){const e={...M,...n},r=document.querySelectorAll(`style[${e.styleTagAttribute||"e"}]`);return r.forEach(t=>{let s=t.textContent;(async()=>{try{t.getAttribute("src")&&(s="@import "+t.getAttribute("src")+";");const c=await B(s,e),a=document.createElement("style");a.textContent=c,t.parentNode.insertBefore(a,t.nextSibling),e.preserveOriginal?t.style.display="none":t.remove()}catch(c){console.error("\u5904\u7406style\u6807\u7B7E\u5931\u8D25:",c)}})()}),r.length}function D(n={}){M={...M,...n}}function k(n,e={}){const r={...M,...e};if(n)return(async()=>{try{const t=await B(n,r),s=document.createElement("style");return s.textContent=t,document.head.appendChild(s),s}catch(t){return console.error("\u5E94\u7528CSS\u5931\u8D25:",t),null}})();document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{X(r)}):X(r)}const de={convert:B,apply:k,config:D,supportsP3:V(),detectP3Support:V,imports:{clearCache:function(){O.clear()},setBaseUrl:function(n){M.importBaseUrl=n},setCacheEnabled:function(n){M.importCache=n},setTimeout:function(n){M.importTimeout=n}},plugins:{use(n){const e=new n;return L.set(e.name??n.name,e),!0},remove(n){return L.get(n)?.destroy&&L.get(n).destroy(),L.delete(n),!0},getAll:function(){return Array.from(L.entries())},clear:function(){L.clear()}},aliases:{add:function(n,e){H.set(n,e)},remove:function(n){H.delete(n)},getAll:function(){return Array.from(H.entries())},clear:function(){H.clear()}},macros:{define:function(n,e,r=[]){if(typeof e=="function"){const s=e.toString().match(/{([\s\S]*)}/);s&&S.set(n,{params:r.map(o=>typeof o=="string"?{name:o}:o),body:s[1].trim()})}else S.set(n,{params:r.map(t=>typeof t=="string"?{name:t}:t),body:e})},call:function(n,...e){const r=S.get(n);if(!r)throw new Error(`\u672A\u5B9A\u4E49\u7684\u5B8F: ${n}`);const t=new Map;for(let s=0,o=r.params.length;s<o;s++){const c=r.params[s],a=s<e.length?e[s]:c.defaultValue;if(a===void 0&&c.defaultValue===null)throw new Error(`\u7F3A\u5C11\u5FC5\u9700\u53C2\u6570: ${c.name}`);t.set(c.name,a!==void 0?a:"")}return N(r.body,t,M)},getAll:function(){return Array.from(S.entries())},remove:function(n){S.delete(n)},clear:function(){S.clear()},parse:function(n){const{macros:e}=W(n,M);for(const[r,t]of e)S.set(r,t)}},math:{evaluate:function(n){return j(n,M)}},colorUtils:{labToRGB:w,lchToLab:v,lchToRGB:function(n,e,r){const t=v(n,e,r);return w(t.L,t.a,t.b)},labToP3:x,lchToP3:function(n,e,r){const t=v(n,e,r);return x(t.L,t.a,t.b)},parseHexLab:function(n){const e=n.match(/lab#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i);if(!e)return null;const r=e[1],t=e[2],s=e[3],o=parseInt(r,16)/255*100,c=(parseInt(t,16)-128)*1.5,a=(parseInt(s,16)-128)*1.5;return w(o,c,a)},parseHexLch:function(n){const e=n.match(/lch#([0-9a-f]{2})([0-9a-f]{2})(\d{1,3})/i);if(!e)return null;const r=e[1],t=e[2],s=e[3],o=parseInt(r,16)/255*100,c=parseInt(t,16)/255*150,a=parseInt(s)/100*360,l=v(o,c,a);return w(l.L,l.a,l.b)},generateColor:function(n,e,r,t=null,s=!0){return R(n,e,r,{enableP3:s},t)},parseColor:function(n){try{const e=n.match(/lab\(\s*([\d.]+)(%?)\s+([\d.-]+)\s+([\d.-]+)(?:\s*\/\s*([\d.%]+))?\s*\)/i);if(e){let t=parseFloat(e[1]);const s=parseFloat(e[3]),o=parseFloat(e[4]),c=e[5]?e[5].includes("%")?parseFloat(e[5])/100:parseFloat(e[5]):null,a=R(t,s,o,M,c);return{L:t,A:s,B:o,alpha:c,rgb:w(t,s,o),p3:x(t,s,o),colorString:a}}const r=n.match(/lch\(\s*([\d.]+)(%?)\s+([\d.]+)\s+([\d.]+)(deg)?(?:\s*\/\s*([\d.%]+))?\s*\)/i);if(r){let t=parseFloat(r[1]);const s=parseFloat(r[3]);let o=parseFloat(r[4]);const c=r[6]?r[6].includes("%")?parseFloat(r[6])/100:parseFloat(r[6]):null,a=v(t,s,o),l=R(a.L,a.a,a.b,M,c);return{L:t,C:s,H:o,alpha:c,lab:a,rgb:w(a.L,a.a,a.b),p3:x(a.L,a.a,a.b),colorString:l}}return null}catch(e){return console.warn("\u65E0\u6CD5\u89E3\u6790\u989C\u8272:",n,e),null}}}},F=async function(...n){if(n.length>1||n[0]&&n[0].raw)return await me(...n);const e=n[0];if(typeof e=="string"){const r=await B(e,{...M,...n[1]});return r&&typeof r.then=="function",r}return typeof e=="object"&&e!==null?(M={...M,...e},F):n.length===0?k():F};async function me(n,...e){let r=n[0];for(let s=0,o=e.length;s<o;s++){const c=e[s];let a="";typeof c=="function"?a=c():Array.isArray(c)?a=c.join(" "):a=String(c??""),r+=a+n[s+1]}const t=await B(r,M);return t&&typeof t.then=="function",t}return Object.assign(F,de),typeof window<"u"&&(k(),Object.defineProperty(window.HTMLElement.prototype,"cssVar",{get(){const n=this;return new Proxy(()=>{},{get(e,r){const t=r.startsWith("--")?r:`--${r}`;return n.style.getPropertyValue(t)},set(e,r,t){const s=r.startsWith("--")?r:`--${r}`;return n.style.setProperty(s,t),!0},apply(e,r,t){const s=t[0],o=t[1],c=s.startsWith("--")?s:`--${s}`;if(o===void 0)return n.style.getPropertyValue(c);n.style.setProperty(c,o)}})}})),F})(),globalObj=globalThis??(typeof self<"u"&&self)??(typeof window<"u"&&window)??global??{};globalObj.styimat=styimat;
18
+ `)}return l}function fe(n,e){let r=n;return r=r.replace(A.VARIABLE,(t,s)=>t.startsWith("$$")?`attr(${s})`:`var(--${s})`),r=w(r,e),r}async function j(n,e){const r=A.IMPORT;return(async s=>{const o=[],l=s.replace(r,(a,c)=>{const u=pe(c,e).then(i=>j(i,e)).catch(i=>(console.warn(`\u65E0\u6CD5\u5BFC\u5165CSS\u6587\u4EF6: ${c}`,i),""));return o.push(u),`__IMPORT_PLACEHOLDER_${o.length-1}__`});if(o.length>0){const a=await Promise.all(o);let c=l;for(let u=a.length;u--;)c=c.replace(`__IMPORT_PLACEHOLDER_${u}__`,a[u]);return c}return l})(n)}async function pe(n,e){if(e.importCache&&B.has(n))return B.get(n);const r=e.importBaseUrl?new URL(n,e.importBaseUrl).href:n;let t;if(typeof process<"u"&&process.versions&&process.versions.node&&typeof require<"u")try{const o=require("fs"),l=require("path");let a=r;r.startsWith(".")&&(a=l.join(process.cwd(),r)),t=o.readFileSync(a,"utf-8")}catch(o){throw new Error(`Node.js\u6587\u4EF6\u8BFB\u53D6\u5931\u8D25: ${r} - ${o.message}`)}else try{const o=new AbortController,l=setTimeout(()=>o.abort(),e.importTimeout),a=await fetch(r,{signal:o.signal,headers:{Accept:"text/css"}});if(clearTimeout(l),!a.ok)throw new Error(`HTTP\u9519\u8BEF: ${a.status} ${a.statusText}`);t=await a.text()}catch(o){throw o.name==="AbortError"?new Error(`\u5BFC\u5165\u8D85\u65F6: ${r}`):new Error(`\u65E0\u6CD5\u83B7\u53D6CSS: ${r} - ${o.message}`)}return e.importCache&&B.set(n,t),t}async function O(n,e={}){let{config:r,css:t}=K(n);const s={...M,...e,...r};t=await j(t,s);let o=t,l=new Map;if(s.enableAlias){const{aliases:p,css:f}=J(o);l=p,o=f}let a=o,c=new Map;if(s.enableMacros){const{macros:p,css:f}=V(a,s);c=p,a=f;for(const[h,b]of c)L.set(h,b)}let u=a.trim();if(s.enableNesting&&a.includes("{"))try{u=ue(a,s,l,c)}catch(p){console.warn("\u5D4C\u5957\u89E3\u6790\u5931\u8D25\uFF0C\u4F7F\u7528\u539F\u59CBCSS:",p)}let i=u;i=fe(i,s);for(const[p,f]of v)try{i=f.convert(i,s)}catch(h){console.error("\u63D2\u4EF6\u5904\u7406\u5931\u8D25:",h)}return i}function X(n={}){const e={...M,...n},r=document.querySelectorAll(`style[${e.styleTagAttribute||"e"}]`);return r.forEach(t=>{let s=t.textContent;(async()=>{try{t.getAttribute("src")&&(s="@import "+t.getAttribute("src")+";");const l=await O(s,e),a=document.createElement("style");a.textContent=l,t.parentNode.insertBefore(a,t.nextSibling),e.preserveOriginal?t.style.display="none":t.remove()}catch(l){console.error("\u5904\u7406style\u6807\u7B7E\u5931\u8D25:",l)}})()}),r.length}function D(n={}){M={...M,...n}}function I(n,e={}){const r={...M,...e};if(n)return(async()=>{try{const t=await O(n,r),s=document.createElement("style");return s.textContent=t,document.head.appendChild(s),s}catch(t){return console.error("\u5E94\u7528CSS\u5931\u8D25:",t),null}})();document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{X(r)}):X(r)}const U={convert:O,apply:I,config:D,supportsP3:k(),detectP3Support:k,imports:{clearCache:function(){B.clear()},setBaseUrl:function(n){M.importBaseUrl=n},setCacheEnabled:function(n){M.importCache=n},setTimeout:function(n){M.importTimeout=n}},plugins:{use(n){const e=new n;return v.set(e.name??n.name,e),!0},remove(n){return v.get(n)?.destroy&&v.get(n).destroy(),v.delete(n),!0},getAll:function(){return Array.from(v.entries())},clear:function(){v.clear()}},aliases:{add:function(n,e){_.set(n,e)},remove:function(n){_.delete(n)},getAll:function(){return Array.from(_.entries())},clear:function(){_.clear()}},macros:{define:function(n,e,r=[]){if(typeof e=="function"){const s=e.toString().match(/{([\s\S]*)}/);s&&L.set(n,{params:r.map(o=>typeof o=="string"?{name:o}:o),body:s[1].trim()})}else L.set(n,{params:r.map(t=>typeof t=="string"?{name:t}:t),body:e})},call:function(n,...e){const r=L.get(n);if(!r)throw new Error(`\u672A\u5B9A\u4E49\u7684\u5B8F: ${n}`);const t=new Map;for(let s=0,o=r.params.length;s<o;s++){const l=r.params[s],a=s<e.length?e[s]:l.defaultValue;if(a===void 0&&l.defaultValue===null)throw new Error(`\u7F3A\u5C11\u5FC5\u9700\u53C2\u6570: ${l.name}`);t.set(l.name,a!==void 0?a:"")}return W(r.body,t,M)},getAll:function(){return Array.from(L.entries())},remove:function(n){L.delete(n)},clear:function(){L.clear()},parse:function(n){const{macros:e}=V(n,M);for(const[r,t]of e)L.set(r,t)}},math:{evaluate:function(n){return Z(n,M)}},colorUtils:{labToRGB:S,lchToLab:T,lchToRGB:function(n,e,r){const t=T(n,e,r);return S(t.L,t.a,t.b)},labToP3:x,lchToP3:function(n,e,r){const t=T(n,e,r);return x(t.L,t.a,t.b)},parseHexLab:function(n){const e=n.match(/lab#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i);if(!e)return null;const r=e[1],t=e[2],s=e[3],o=parseInt(r,16)/255*100,l=(parseInt(t,16)-128)*1.5,a=(parseInt(s,16)-128)*1.5;return S(o,l,a)},parseHexLch:function(n){const e=n.match(/lch#([0-9a-f]{2})([0-9a-f]{2})(\d{1,3})/i);if(!e)return null;const r=e[1],t=e[2],s=e[3],o=parseInt(r,16)/255*100,l=parseInt(t,16)/255*150,a=parseInt(s)/100*360,c=T(o,l,a);return S(c.L,c.a,c.b)},generateColor:function(n,e,r,t=null,s=!0){return P(n,e,r,{enableP3:s},t)},parseColor:function(n){try{const e=n.match(/lab\(\s*([\d.]+)(%?)\s+([\d.-]+)\s+([\d.-]+)(?:\s*\/\s*([\d.%]+))?\s*\)/i);if(e){let t=parseFloat(e[1]);const s=parseFloat(e[3]),o=parseFloat(e[4]),l=e[5]?e[5].includes("%")?parseFloat(e[5])/100:parseFloat(e[5]):null,a=P(t,s,o,M,l);return{L:t,A:s,B:o,alpha:l,rgb:S(t,s,o),p3:x(t,s,o),colorString:a}}const r=n.match(/lch\(\s*([\d.]+)(%?)\s+([\d.]+)\s+([\d.]+)(deg)?(?:\s*\/\s*([\d.%]+))?\s*\)/i);if(r){let t=parseFloat(r[1]);const s=parseFloat(r[3]);let o=parseFloat(r[4]);const l=r[6]?r[6].includes("%")?parseFloat(r[6])/100:parseFloat(r[6]):null,a=T(t,s,o),c=P(a.L,a.a,a.b,M,l);return{L:t,C:s,H:o,alpha:l,lab:a,rgb:S(a.L,a.a,a.b),p3:x(a.L,a.a,a.b),colorString:c}}return null}catch(e){return console.warn("\u65E0\u6CD5\u89E3\u6790\u989C\u8272:",n,e),null}}}};U.Plugin=class{name="Plugin";constructor(){this.createdAt=Date.now(),this.install()}install(){}destroy(){}convert(n,e){throw new Error(`${this.name}.convert() \u5FC5\u987B\u88AB\u5B9E\u73B0`)}};const H=async function(...n){if(n.length>1||n[0]&&n[0].raw)return await he(...n);const e=n[0];if(typeof e=="string"){const r=await O(e,n[1]);return r&&typeof r.then=="function",r}return typeof e=="object"&&e!==null?(M={...M,...e},H):n.length===0?I():H};async function he(n,...e){let r=n[0];for(let s=0,o=e.length;s<o;s++){const l=e[s];let a="";typeof l=="function"?a=l():Array.isArray(l)?a=l.join(" "):a=String(l??"none"),r+=a+n[s+1]}const t=await O(r,M);return t&&typeof t.then=="function",t}return Object.assign(H,U),typeof window<"u"&&(I(),Object.defineProperty(window.HTMLElement.prototype,"cssVar",{get(){const n=this;return new Proxy(()=>{},{get(e,r){const t=r.startsWith("--")?r:`--${r}`;return n.style.getPropertyValue(t)},set(e,r,t){const s=r.startsWith("--")?r:`--${r}`;return n.style.setProperty(s,t),!0},apply(e,r,t){const s=t[0],o=t[1],l=s.startsWith("--")?s:`--${s}`;if(o===void 0)return n.style.getPropertyValue(l);n.style.setProperty(l,o)}})}})),H})(),globalObj=globalThis??(typeof self<"u"&&self)??(typeof window<"u"&&window)??global??{};globalObj.styimat=styimat;