styimat 9.2.0 → 10.1.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/README.md +8 -8
- package/dist/build-manifest.json +57 -0
- package/dist/styimat.amd.js +124 -112
- package/dist/styimat.amd.min.js +10 -11
- package/dist/styimat.browser.js +124 -112
- package/dist/styimat.browser.min.js +10 -11
- package/dist/styimat.cjs +124 -112
- package/dist/styimat.js +124 -112
- package/dist/styimat.min.cjs +10 -11
- package/dist/styimat.min.js +10 -11
- package/dist/styimat.min.mjs +10 -11
- package/dist/styimat.mjs +126 -112
- package/dist/styimat.umd.js +124 -112
- package/dist/styimat.umd.min.js +10 -11
- package/package.json +5 -16
- package/src/styimat.js +1702 -0
package/README.md
CHANGED
|
@@ -249,16 +249,16 @@ $font-family: 'Inter', sans-serif;
|
|
|
249
249
|
|
|
250
250
|
### 2. 配置头语法
|
|
251
251
|
|
|
252
|
-
|
|
252
|
+
变量定义要用`@config name value`的格式,写在css顶部
|
|
253
253
|
|
|
254
254
|
```css
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
255
|
+
@config indent-size 4
|
|
256
|
+
@config auto-process-style-tags true
|
|
257
|
+
@config preserve-original true
|
|
258
|
+
@config enable-p3 false
|
|
259
|
+
@config root-selector :root
|
|
260
|
+
@config enable-nesting true
|
|
261
|
+
@config enable-math true
|
|
262
262
|
|
|
263
263
|
/* 然后写您的CSS代码 */
|
|
264
264
|
$primary-color: lab#32a852;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"generatedAt": "2026-01-07T01:54:45.791Z",
|
|
3
|
+
"files": [
|
|
4
|
+
{
|
|
5
|
+
"name": "dist/styimat.js",
|
|
6
|
+
"size": "55.73 KB"
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"name": "dist/styimat.min.js",
|
|
10
|
+
"size": "17.43 KB"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"name": "dist/styimat.mjs",
|
|
14
|
+
"size": "55.89 KB"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"name": "dist/styimat.min.mjs",
|
|
18
|
+
"size": "17.55 KB"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"name": "dist/styimat.cjs",
|
|
22
|
+
"size": "55.75 KB"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"name": "dist/styimat.min.cjs",
|
|
26
|
+
"size": "17.45 KB"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"name": "dist/styimat.umd.js",
|
|
30
|
+
"size": "56.07 KB"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"name": "dist/styimat.umd.min.js",
|
|
34
|
+
"size": "17.66 KB"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"name": "dist/styimat.amd.js",
|
|
38
|
+
"size": "55.75 KB"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"name": "dist/styimat.amd.min.js",
|
|
42
|
+
"size": "17.45 KB"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"name": "dist/styimat.browser.js",
|
|
46
|
+
"size": "55.88 KB"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"name": "dist/styimat.browser.min.js",
|
|
50
|
+
"size": "17.54 KB"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"name": "bin/cli.min.js",
|
|
54
|
+
"size": "4.55 KB"
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
}
|
package/dist/styimat.amd.js
CHANGED
|
@@ -39,7 +39,7 @@ const styimat = (function() {
|
|
|
39
39
|
|
|
40
40
|
const REGEX = {
|
|
41
41
|
IMPORT: /@import\s+([^;]+?)\s*;/g,
|
|
42
|
-
ALIAS: /^@alias\s+([a-zA-Z_][a-zA-Z0-9_]*)\s+(.+?)\s
|
|
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
44
|
COMMENT: /\/\*[\s\S]*?\*\//g,
|
|
45
45
|
MATH_SYMBOL: /([\da-z])([+-])(-?[\da-z])/g,
|
|
@@ -102,8 +102,8 @@ const styimat = (function() {
|
|
|
102
102
|
for (let line of lines) {
|
|
103
103
|
const trimmed = line.trim();
|
|
104
104
|
|
|
105
|
-
if (trimmed.startsWith('
|
|
106
|
-
const configLine = trimmed.substring(
|
|
105
|
+
if (trimmed.startsWith('@config ')) {
|
|
106
|
+
const configLine = trimmed.substring(8).trim();
|
|
107
107
|
const firstSpace = configLine.indexOf(' ');
|
|
108
108
|
|
|
109
109
|
if (~firstSpace) {
|
|
@@ -134,37 +134,6 @@ const styimat = (function() {
|
|
|
134
134
|
};
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
/**
|
|
138
|
-
* 解析 @alias 语句
|
|
139
|
-
*/
|
|
140
|
-
function parseAliasStatements(cssText) {
|
|
141
|
-
const aliases = new Map();
|
|
142
|
-
const lines = splitLines(cssText);
|
|
143
|
-
const cleanLines = [];
|
|
144
|
-
|
|
145
|
-
for (let line of lines) {
|
|
146
|
-
const trimmed = line.trim();
|
|
147
|
-
|
|
148
|
-
if (trimmed.startsWith('@alias')) {
|
|
149
|
-
const aliasMatch = trimmed.match(REGEX.ALIAS);
|
|
150
|
-
if (aliasMatch) {
|
|
151
|
-
const aliasName = aliasMatch[1];
|
|
152
|
-
const originalProperty = aliasMatch[2];
|
|
153
|
-
|
|
154
|
-
aliases.set(aliasName, originalProperty);
|
|
155
|
-
continue;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
cleanLines.push(line);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return {
|
|
163
|
-
aliases,
|
|
164
|
-
css: cleanLines.join('\n')
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
|
|
168
137
|
/**
|
|
169
138
|
* 解析 @macro 语句
|
|
170
139
|
*/
|
|
@@ -355,7 +324,7 @@ const styimat = (function() {
|
|
|
355
324
|
/**
|
|
356
325
|
* 解析一行CSS
|
|
357
326
|
*/
|
|
358
|
-
function parseSingleLineCSS(cssString, aliases, macros) {
|
|
327
|
+
function parseSingleLineCSS(cssString, aliases, macros, config) {
|
|
359
328
|
let str = cssString.trim();
|
|
360
329
|
|
|
361
330
|
if (str.endsWith(';')) {
|
|
@@ -405,7 +374,7 @@ const styimat = (function() {
|
|
|
405
374
|
declarations.push(currentDeclaration.trim());
|
|
406
375
|
}
|
|
407
376
|
|
|
408
|
-
const result =
|
|
377
|
+
const result = {};
|
|
409
378
|
|
|
410
379
|
for (let declaration of declarations) {
|
|
411
380
|
declaration = declaration.replace(REGEX.COMMENT, '');
|
|
@@ -438,7 +407,7 @@ const styimat = (function() {
|
|
|
438
407
|
value = "";
|
|
439
408
|
}
|
|
440
409
|
|
|
441
|
-
result
|
|
410
|
+
result[property] = value;
|
|
442
411
|
}
|
|
443
412
|
|
|
444
413
|
return result;
|
|
@@ -703,12 +672,12 @@ const styimat = (function() {
|
|
|
703
672
|
const kappa = 903.3;
|
|
704
673
|
|
|
705
674
|
const fy = (L + 16) / 116;
|
|
706
|
-
const fx = a
|
|
707
|
-
const fz = fy - b
|
|
675
|
+
const fx = a * 0.002 + fy;
|
|
676
|
+
const fz = fy - b * 0.005;
|
|
708
677
|
|
|
709
|
-
const xr = fx
|
|
678
|
+
const xr = (fx * fx * fx) > epsilon ? (fx * fx * fx) : (116 * fx - 16) / kappa;
|
|
710
679
|
const yr = L > kappa * epsilon ? ((L + 16) / 116) ** 3 : L / kappa;
|
|
711
|
-
const zr = fz
|
|
680
|
+
const zr = (fz * fz * fz) > epsilon ? fz * fz * fz : (116 * fz - 16) / kappa;
|
|
712
681
|
|
|
713
682
|
return [
|
|
714
683
|
xr * refX,
|
|
@@ -773,7 +742,7 @@ const styimat = (function() {
|
|
|
773
742
|
const kappa = 903.3;
|
|
774
743
|
|
|
775
744
|
const fy = (L + 16) / 116;
|
|
776
|
-
const fx = a
|
|
745
|
+
const fx = a * 0.002 + fy;
|
|
777
746
|
const fz = fy - b / 200;
|
|
778
747
|
|
|
779
748
|
const xr = fx ** 3 > epsilon ? fx ** 3 : (116 * fx - 16) / kappa;
|
|
@@ -897,15 +866,30 @@ function parseNestedRules(cssText, config, aliases, macros) {
|
|
|
897
866
|
if (charCode === 123) { // 123: "{"的码点
|
|
898
867
|
braceDepth++;
|
|
899
868
|
|
|
900
|
-
// 在处理{
|
|
869
|
+
// 在处理{之前,检查当前行是否有变量定义或@alias(仅限全局作用域)
|
|
901
870
|
if (isGlobalScope && currentLine.trim()) {
|
|
902
|
-
const
|
|
871
|
+
const trimmedLine = currentLine.trim();
|
|
872
|
+
|
|
873
|
+
// 检查是否是变量定义
|
|
874
|
+
const varMatch = trimmedLine.match(/^\$([a-zA-Z_][a-zA-Z0-9_]*)\s*:\s*(.+?);?$/);
|
|
903
875
|
if (varMatch) {
|
|
904
876
|
const [, varName, varValue] = varMatch;
|
|
905
877
|
globalVariables[varName] = processCSSValue(varValue.trim(), config);
|
|
906
878
|
currentLine = '';
|
|
907
879
|
continue;
|
|
908
880
|
}
|
|
881
|
+
|
|
882
|
+
// 检查是否是 @alias 语句
|
|
883
|
+
if (config.enableAlias && trimmedLine.startsWith('@alias')) {
|
|
884
|
+
const aliasMatch = trimmedLine.match(REGEX.ALIAS);
|
|
885
|
+
if (aliasMatch) {
|
|
886
|
+
const aliasName = aliasMatch[1];
|
|
887
|
+
const originalProperty = aliasMatch[2];
|
|
888
|
+
aliases.set(aliasName, originalProperty);
|
|
889
|
+
currentLine = '';
|
|
890
|
+
continue;
|
|
891
|
+
}
|
|
892
|
+
}
|
|
909
893
|
}
|
|
910
894
|
|
|
911
895
|
if (!inRuleBlock) {
|
|
@@ -917,18 +901,17 @@ function parseNestedRules(cssText, config, aliases, macros) {
|
|
|
917
901
|
};
|
|
918
902
|
stack.push(currentRule);
|
|
919
903
|
inRuleBlock = true;
|
|
920
|
-
isGlobalScope = false;
|
|
904
|
+
isGlobalScope = false;
|
|
921
905
|
} else {
|
|
922
906
|
// 嵌套规则开始,需要先处理当前行的属性
|
|
923
907
|
if (currentLine.trim() && currentLine.includes(':')) {
|
|
924
|
-
const parsed = parseSingleLineCSS(currentLine.trim(), aliases, macros);
|
|
925
|
-
|
|
926
|
-
const
|
|
927
|
-
const value = processCSSValue(obj[key], config);
|
|
908
|
+
const parsed = parseSingleLineCSS(currentLine.trim(), aliases, macros, config);
|
|
909
|
+
for (let key of Object.keys(parsed)){
|
|
910
|
+
const value = processCSSValue(parsed[key], config);
|
|
928
911
|
if (currentRule) {
|
|
929
912
|
currentRule.properties[key] = value;
|
|
930
913
|
}
|
|
931
|
-
}
|
|
914
|
+
}
|
|
932
915
|
}
|
|
933
916
|
// 开始嵌套规则
|
|
934
917
|
const nestedRule = {
|
|
@@ -945,14 +928,13 @@ function parseNestedRules(cssText, config, aliases, macros) {
|
|
|
945
928
|
|
|
946
929
|
// 处理当前行的属性(在}之前的属性)
|
|
947
930
|
if (currentLine.trim() && currentLine.includes(':')) {
|
|
948
|
-
const parsed = parseSingleLineCSS(currentLine.trim(), aliases, macros);
|
|
949
|
-
|
|
950
|
-
const
|
|
951
|
-
const value = processCSSValue(obj[key], config);
|
|
931
|
+
const parsed = parseSingleLineCSS(currentLine.trim(), aliases, macros, config);
|
|
932
|
+
for (let key of Object.keys(parsed)){
|
|
933
|
+
const value = processCSSValue(parsed[key], config);
|
|
952
934
|
if (currentRule) {
|
|
953
935
|
currentRule.properties[key] = value;
|
|
954
936
|
}
|
|
955
|
-
}
|
|
937
|
+
}
|
|
956
938
|
}
|
|
957
939
|
|
|
958
940
|
// 规则结束
|
|
@@ -979,25 +961,38 @@ function parseNestedRules(cssText, config, aliases, macros) {
|
|
|
979
961
|
isGlobalScope = true;
|
|
980
962
|
}
|
|
981
963
|
} else if (charCode === 10 || charCode === 59) {
|
|
982
|
-
//
|
|
964
|
+
// 行结束,处理当前行的属性、变量或 @alias
|
|
983
965
|
if (inRuleBlock && currentLine.trim() && currentLine.includes(':')) {
|
|
984
|
-
const parsed = parseSingleLineCSS(currentLine.trim(), aliases, macros);
|
|
985
|
-
|
|
986
|
-
const
|
|
987
|
-
const value = processCSSValue(obj[key], config);
|
|
966
|
+
const parsed = parseSingleLineCSS(currentLine.trim(), aliases, macros, config);
|
|
967
|
+
for (let key of Object.keys(parsed)){
|
|
968
|
+
const value = processCSSValue(parsed[key], config);
|
|
988
969
|
if (currentRule) {
|
|
989
970
|
currentRule.properties[key] = value;
|
|
990
971
|
}
|
|
991
|
-
}
|
|
972
|
+
}
|
|
992
973
|
} else if (isGlobalScope && currentLine.trim()) {
|
|
974
|
+
const trimmedLine = currentLine.trim();
|
|
975
|
+
|
|
993
976
|
// 全局作用域中检查变量定义
|
|
994
|
-
const varMatch =
|
|
977
|
+
const varMatch = trimmedLine.match(/^\$([a-zA-Z_][a-zA-Z0-9_]*)\s*:\s*(.+?);?$/);
|
|
995
978
|
if (varMatch) {
|
|
996
979
|
const [, varName, varValue] = varMatch;
|
|
997
980
|
globalVariables[varName] = processCSSValue(varValue.trim(), config);
|
|
998
981
|
currentLine = '';
|
|
999
982
|
continue;
|
|
1000
983
|
}
|
|
984
|
+
|
|
985
|
+
// 全局作用域中检查 @alias 语句
|
|
986
|
+
if (config.enableAlias && trimmedLine.startsWith('@alias')) {
|
|
987
|
+
const aliasMatch = trimmedLine.match(REGEX.ALIAS);
|
|
988
|
+
if (aliasMatch) {
|
|
989
|
+
const aliasName = aliasMatch[1];
|
|
990
|
+
const originalProperty = aliasMatch[2];
|
|
991
|
+
aliases.set(aliasName, originalProperty);
|
|
992
|
+
currentLine = '';
|
|
993
|
+
continue;
|
|
994
|
+
}
|
|
995
|
+
}
|
|
1001
996
|
}
|
|
1002
997
|
currentLine = '';
|
|
1003
998
|
} else {
|
|
@@ -1005,22 +1000,34 @@ function parseNestedRules(cssText, config, aliases, macros) {
|
|
|
1005
1000
|
}
|
|
1006
1001
|
}
|
|
1007
1002
|
|
|
1008
|
-
//
|
|
1003
|
+
// 处理最后一行(可能在全局作用域中的变量或 @alias)
|
|
1009
1004
|
if (isGlobalScope && currentLine.trim()) {
|
|
1010
|
-
const
|
|
1005
|
+
const trimmedLine = currentLine.trim();
|
|
1006
|
+
|
|
1007
|
+
// 检查变量定义
|
|
1008
|
+
const varMatch = trimmedLine.match(/^\$([a-zA-Z_][a-zA-Z0-9_]*)\s*:\s*(.+?);?$/);
|
|
1011
1009
|
if (varMatch) {
|
|
1012
1010
|
const [, varName, varValue] = varMatch;
|
|
1013
1011
|
globalVariables[varName] = processCSSValue(varValue.trim(), config);
|
|
1014
1012
|
}
|
|
1013
|
+
|
|
1014
|
+
// 检查 @alias 语句
|
|
1015
|
+
if (config.enableAlias && trimmedLine.startsWith('@alias')) {
|
|
1016
|
+
const aliasMatch = trimmedLine.match(REGEX.ALIAS);
|
|
1017
|
+
if (aliasMatch) {
|
|
1018
|
+
const aliasName = aliasMatch[1];
|
|
1019
|
+
const originalProperty = aliasMatch[2];
|
|
1020
|
+
aliases.set(aliasName, originalProperty);
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1015
1023
|
} else if (inRuleBlock && currentLine.trim() && currentLine.includes(':')) {
|
|
1016
|
-
const parsed = parseSingleLineCSS(currentLine.trim(), aliases, macros);
|
|
1017
|
-
|
|
1018
|
-
const
|
|
1019
|
-
const value = processCSSValue(obj[key], config);
|
|
1024
|
+
const parsed = parseSingleLineCSS(currentLine.trim(), aliases, macros, config);
|
|
1025
|
+
for (let key of Object.keys(parsed)){
|
|
1026
|
+
const value = processCSSValue(parsed[key], config);
|
|
1020
1027
|
if (currentRule) {
|
|
1021
1028
|
currentRule.properties[key] = value;
|
|
1022
1029
|
}
|
|
1023
|
-
}
|
|
1030
|
+
}
|
|
1024
1031
|
}
|
|
1025
1032
|
|
|
1026
1033
|
// 如果存在全局变量,创建:root规则并添加到rootRules开头
|
|
@@ -1216,54 +1223,59 @@ function parseNestedRules(cssText, config, aliases, macros) {
|
|
|
1216
1223
|
/**
|
|
1217
1224
|
* 主转换函数
|
|
1218
1225
|
*/
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1226
|
+
/**
|
|
1227
|
+
* 主转换函数
|
|
1228
|
+
*/
|
|
1229
|
+
async function convert(cssText, customConfig = {}) {
|
|
1230
|
+
let { config: headerConfig, css: cleanedCSS } = parseConfigHeader(cssText);
|
|
1231
|
+
const finalConfig = { ...defaultConfig, ...customConfig, ...headerConfig };
|
|
1232
|
+
cleanedCSS = await processImports(cleanedCSS, finalConfig);
|
|
1233
|
+
|
|
1234
|
+
let aliases = new Map();
|
|
1235
|
+
|
|
1236
|
+
let cssWithMacros = cleanedCSS;
|
|
1237
|
+
let macros = new Map();
|
|
1238
|
+
if (finalConfig.enableMacros) {
|
|
1239
|
+
const { macros: parsedMacros, css: cssWithoutMacros } = parseMacroStatements(cssWithMacros, finalConfig);
|
|
1240
|
+
macros = parsedMacros;
|
|
1241
|
+
cssWithMacros = cssWithoutMacros;
|
|
1242
|
+
|
|
1243
|
+
for (const [name, macro] of macros) {
|
|
1244
|
+
macroRegistry.set(name, macro);
|
|
1230
1245
|
}
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
macroRegistry.set(name, macro);
|
|
1241
|
-
}
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
let processedCSS = cssWithMacros.trim();
|
|
1249
|
+
if (finalConfig.enableNesting && cssWithMacros.includes('{')) {
|
|
1250
|
+
try {
|
|
1251
|
+
// parseNestedRules 现在会在内部处理 @alias 语句
|
|
1252
|
+
processedCSS = parseNestedRules(cssWithMacros, finalConfig, aliases, macros);
|
|
1253
|
+
} catch (error) {
|
|
1254
|
+
console.warn('嵌套解析失败,使用原始CSS:', error);
|
|
1242
1255
|
}
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
if (finalConfig.
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
console.warn('嵌套解析失败,使用原始CSS:', error);
|
|
1250
|
-
}
|
|
1256
|
+
} else {
|
|
1257
|
+
// 对于非嵌套CSS,仍然需要单独处理 @alias
|
|
1258
|
+
if (finalConfig.enableAlias) {
|
|
1259
|
+
const { aliases: parsedAliases, css: cssWithoutAliases } = parseAliasStatements(cssWithMacros);
|
|
1260
|
+
aliases = parsedAliases;
|
|
1261
|
+
cssWithMacros = cssWithoutAliases;
|
|
1251
1262
|
}
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
let finalCSS = processedCSS;
|
|
1266
|
+
|
|
1267
|
+
finalCSS = replaceVariableUses(finalCSS, finalConfig);
|
|
1268
|
+
|
|
1269
|
+
for (const [name, plugin] of pluginMap) {
|
|
1270
|
+
try {
|
|
1271
|
+
finalCSS = plugin.convert(finalCSS, finalConfig);
|
|
1272
|
+
} catch (error) {
|
|
1273
|
+
console.error('插件处理失败:', error);
|
|
1263
1274
|
}
|
|
1264
|
-
|
|
1265
|
-
return finalCSS;
|
|
1266
1275
|
}
|
|
1276
|
+
|
|
1277
|
+
return finalCSS;
|
|
1278
|
+
}
|
|
1267
1279
|
|
|
1268
1280
|
/**
|
|
1269
1281
|
* 自动处理带有特定属性的 style 标签
|
package/dist/styimat.amd.min.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* MIT License
|
|
3
3
|
* Copyright (c) 2025 王小玗
|
|
4
|
-
*/const styimat=(function(){let
|
|
5
|
-
`){const
|
|
6
|
-
`)}}function
|
|
7
|
-
`)}
|
|
8
|
-
`)}),o=!1,l="",a=[],c=[]):c.push(
|
|
9
|
-
`)
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
`:`${i}
|
|
4
|
+
*/const styimat=(function(){let A={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*\{$/,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 O=new Map,F=new Map,L=new Map,v=new Map;function H(r,e=`
|
|
5
|
+
`){const t=[],n=e.charCodeAt(0);let s=0;for(let o=0,l=r.length;o<l;o++)r.charCodeAt(o)===n&&((o>s||r.charAt(s)!=="\r")&&t.push(r.slice(s,o)),s=o+1);return s<r.length?t.push(r.substring(s)):s===r.length&&r.charCodeAt(r.length-1)===10&&t.push(""),t}function Q(r){const e={...A},t=H(r),n=[];for(let s of t){const o=s.trim();if(o.startsWith("@config ")){const l=o.substring(8).trim(),a=l.indexOf(" ");if(~a){const c=l.substring(0,a).trim(),i=l.substring(a+1).trim(),u=ee(c);i==="true"||i==="false"?e[u]=i==="true":!isNaN(i)&&i.trim()!==""?e[u]=Number(i):e[u]=i}else console.warn(`\u65E0\u6548\u7684\u914D\u7F6E\u884C: ${o}`)}else n.push(s)}return{config:e,css:n.join(`
|
|
6
|
+
`)}}function V(r,e){if(!e.enableMacros)return{macros:new Map,css:r};const t=new Map,n=H(r),s=[];let o=!1,l="",a=[],c=[],i=0;for(let u of n){const p=u.trim();if(!o&&p.startsWith("@macro")){const h=p.match(C.MACRO);if(h){o=!0,l=h[1],a=H(h[2],",").map(f=>f.trim()).filter(f=>f).map(f=>{const g=H(f,":").map(M=>M.trim());return{name:g[0].slice(1),defaultValue:g[1]||null}}),c=[],i=1;continue}}if(o){for(const h of u)h==="{"&&i++,h==="}"&&i--;i===0?(t.set(l,{params:a,body:c.join(`
|
|
7
|
+
`)}),o=!1,l="",a=[],c=[]):c.push(u);continue}s.push(u)}return{macros:t,css:s.join(`
|
|
8
|
+
`)}}function K(r,e,t=","){const n=new Map,s=J(r,t);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",n.set(a.name,c)}return n}function J(r,e){const t=[];let n="",s=!1,o="",l=0,a=0;for(let c=0,i=r.length;c<i;c++){const u=r[c];(u==='"'||u==="'")&&!s?(s=!0,o=u):u===o&&s&&(s=!1,o=""),s||(u==="("&&l++,u===")"&&l--,u==="["&&a++,u==="]"&&a--),u===e&&!s&&l===0&&a===0?(t.push(n.trim()),n=""):n+=u}return n.trim()&&t.push(n.trim()),t}function W(r,e,t){let n=r;return n=n.replace(C.VARIABLE,(s,o)=>e.get(o)?e.get(o):s),n=w(n,t),n}function ee(r){return r.replace(C.HYPHEN,function(e,t){return t.toUpperCase()})}function z(){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 I(r,e,t,n){let s=r.trim();if(s.endsWith(";")&&(s=s.slice(0,-1)),!s)return[];const o=[];let l="",a=0,c=!1,i="";for(let p=0,h=s.length;p<h;p++){const f=s[p];(f==='"'||f==="'")&&!c?(c=!0,i=f):f===i&&c&&(c=!1,i=""),c||(f==="("?a++:f===")"&&a--),f===";"&&!c&&a===0?l.trim()&&(o.push(l.trim()),l=""):l+=f}l.trim()&&o.push(l.trim());const u={};for(let p of o){if(p=p.replace(C.COMMENT,""),!p.trim())continue;const h=te(p);if(!~h){console.warn(`\u65E0\u6548\u7684CSS\u58F0\u660E: "${p}"`);continue}let f=p.substring(0,h).trim(),g=p.substring(h+1).trim();if(g.endsWith(";")&&(g=g.slice(0,-1).trim()),f.startsWith("$")&&(f="--"+f.slice(1)),f=e.get(f)??f,f.startsWith("@")&&t.get(f.slice(1))){const M=t.get(f.slice(1)),m=K(g,M.params," ");f=W(M.body,m,n),g=""}u[f]=g}return u}function te(r){let e=!1,t="";for(let n=0,s=r.length;n<s;n++){const o=r[n];if((o==='"'||o==="'")&&!e?(e=!0,t=o):o===t&&e&&(e=!1,t=""),o===":"&&!e)return n}return-1}function Z(r,e){let t=r.replace(C.SPACE,"");return re(t)}function re(r){return`calc(${r.replace(C.MATH_SYMBOL,"$1 $2 $3")})`}function ne(r,e){let t=r;return t=(s=>s.replace(C.MATH,(o,l)=>Z(l,e)))(t),t}function se(r,e){if(!e.convertLabToRGB&&!e.convertLchToRGB)return r;let t=r;t=oe(t,e);const n=new Map,s=l=>l.replace(C.COLOR,a=>{if(n.has(a))return n.get(a);let c=a;return a.toLowerCase().startsWith("lab(")?e.convertLabToRGB&&(c=ae(a,e)):a.toLowerCase().startsWith("lch(")&&e.convertLchToRGB&&(c=ce(a,e)),n.set(a,c),c});let o;do o=t,t=s(t);while(t!==o);return t}function oe(r,e){let t=r;const n=new Map;return t=t.replace(C.HEXLAB,(s,o,l,a)=>{if(n.has(s))return n.get(s);try{const c=parseInt(o,16)/255*100,i=(parseInt(l,16)-128)*1.5,u=(parseInt(a,16)-128)*1.5,p=T(c,i,u,e);return n.set(s,p),p}catch(c){return console.warn(`\u65E0\u6CD5\u89E3\u6790lab#\u5341\u516D\u8FDB\u5236\u989C\u8272: ${s}`,c),s}}),t=t.replace(C.HEXLCH,(s,o,l,a)=>{if(n.has(s))return n.get(s);try{const c=parseInt(o,16)/255*100,i=parseInt(l,16)/255*150,u=parseInt(a)/100*360,p=P(c,i,u),h=T(p.L,p.a,p.b,e);return n.set(s,h),h}catch(c){return console.warn(`\u65E0\u6CD5\u89E3\u6790lch#\u5341\u516D\u8FDB\u5236\u989C\u8272: ${s}`,c),s}}),t}function ae(r,e){const t=/lab\(\s*([\d.]+)(%?)\s+([\d.-]+)\s+([\d.-]+)(?:\s*\/\s*([\d.%]+))?\s*\)/i,n=r.match(t);if(!n)return r;try{let s=parseFloat(n[1]);n[2]!=="%"&&(s<0&&(s=0),s>100&&(s=100));const o=parseFloat(n[3]),l=parseFloat(n[4]),a=n[5]!==void 0?n[5].includes("%")?parseFloat(n[5])/100:parseFloat(n[5]):null;return T(s,o,l,e,a)}catch(s){return console.warn(`\u65E0\u6CD5\u8F6C\u6362LAB\u989C\u8272: ${r}`,s),r}}function ce(r,e){const t=/lch\(\s*([\d.]+)(%?)\s+([\d.]+)\s+([\d.]+)(deg)?(?:\s*\/\s*([\d.%]+))?\s*\)/i,n=r.match(t);if(!n)return r;try{let s=parseFloat(n[1]);n[2]==="%"?s=s:(s<0&&(s=0),s>100&&(s=100));const o=parseFloat(n[3]);let l=parseFloat(n[4]);o<0&&console.warn(`LCH\u4E2D\u7684C\u503C\u4E0D\u80FD\u4E3A\u8D1F: ${o}`),l=(l%360+360)%360;const a=P(s,o,l),c=n[6]!==void 0?n[6].includes("%")?parseFloat(n[6])/100:parseFloat(n[6]):null;return T(a.L,a.a,a.b,e,c)}catch(s){return console.warn(`\u65E0\u6CD5\u8F6C\u6362LCH\u989C\u8272: ${r}`,s),r}}function P(r,e,t){const n=t*Math.PI/180,s=e*Math.cos(n),o=e*Math.sin(n);return{L:r,a:s,b:o}}function S(r,e,t){const n=(m,d,b)=>{const q=(m+16)/116,R=d*.002+q,x=q-b*.005,he=R*R*R>.008856?R*R*R:(116*R-16)/903.3,me=m>903.3*.008856?((m+16)/116)**3:m/903.3,de=x*x*x>.008856?x*x*x:(116*x-16)/903.3;return[he*.95047,me*1,de*1.08883]},s=(m,d,b)=>{const y=[[3.2404542,-1.5371385,-.4985314],[-.969266,1.8760108,.041556],[.0556434,-.2040259,1.0572252]],$=y[0][0]*m+y[0][1]*d+y[0][2]*b,U=y[1][0]*m+y[1][1]*d+y[1][2]*b,Y=y[2][0]*m+y[2][1]*d+y[2][2]*b;return[$,U,Y]},o=m=>{const d=m<0?-1:1,b=d*m;return b<=.0031308?12.92*b:d*(1.055*Math.pow(b,.4166666666666667)-.055)},l=m=>Math.max(0,Math.min(255,m*255|0)),[a,c,i]=n(r,e,t),[u,p,h]=s(a,c,i),f=o(u),g=o(p),M=o(h);return{r:l(f),g:l(g),b:l(M)}}function _(r,e,t){const n=(a,c,i)=>{const M=(a+16)/116,m=c*.002+M,d=M-i/200,b=m**3>.008856?m**3:(116*m-16)/903.3,y=a>903.3*.008856?((a+16)/116)**3:a/903.3,$=d**3>.008856?d**3:(116*d-16)/903.3;return[b*.95047,y*1,$*1.08883]},s=(a,c,i)=>{const u=[[2.493496911941425,-.9313836179191239,-.40271078445071684],[-.8294889695615747,1.7626640603183463,.023624685841943577],[.03584583024378447,-.07617238926804182,.9568845240076872]],p=u[0][0]*a+u[0][1]*c+u[0][2]*i,h=u[1][0]*a+u[1][1]*c+u[1][2]*i,f=u[2][0]*a+u[2][1]*c+u[2][2]*i;return[p,h,f]},o=a=>{const c=a<0?-1:1,i=Math.abs(a);return i<=.0031308?c*12.92*i:c*(1.055*Math.pow(i,.4166666666666667)-.055)},l=a=>Math.max(0,Math.min(255,a*255|0));try{const[a,c,i]=n(r,e,t),[u,p,h]=s(a,c,i),f=o(u),g=o(p),M=o(h);return{r:Math.max(0,Math.min(1,f)),g:Math.max(0,Math.min(1,g)),b:Math.max(0,Math.min(1,M))}}catch(a){console.warn("P3\u8F6C\u6362\u5931\u8D25:",a);const c=S(r,e,t);return{r:c.r/255,g:c.g/255,b:c.b/255}}}function T(r,e,t,n,s=null){if(!n.enableP3||!z()){const o=S(r,e,t);return s!==null?`rgba(${o.r}, ${o.g}, ${o.b}, ${s})`:`rgb(${o.r}, ${o.g}, ${o.b})`}else{const o=_(r,e,t);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(r,e){let t=r;return e.enableMath&&(t=ne(t,e)),(e.convertLabToRGB||e.convertLchToRGB)&&(t=se(t,e)),t}function le(r,e,t,n){const s=[],o=[],l={};let a=null,c="",i=!1,u=0,p=!0;for(let h=0,f=r.length;h<f;h++){const g=r[h],M=r.charCodeAt(h);if(M===123){if(u++,p&&c.trim()){const m=c.trim(),d=m.match(/^\$([a-zA-Z_][a-zA-Z0-9_]*)\s*:\s*(.+?);?$/);if(d){const[,b,y]=d;l[b]=w(y.trim(),e),c="";continue}if(e.enableAlias&&m.startsWith("@alias")){const b=m.match(C.ALIAS);if(b){const y=b[1],$=b[2];t.set(y,$),c="";continue}}}if(!i)a={selector:c.trim(),properties:{},children:[]},o.push(a),i=!0,p=!1;else{if(c.trim()&&c.includes(":")){const d=I(c.trim(),t,n,e);for(let b of Object.keys(d)){const y=w(d[b],e);a&&(a.properties[b]=y)}}const m={selector:c.trim(),properties:{},children:[]};o.push(m),a=m}c=""}else if(M===125){if(u--,c.trim()&&c.includes(":")){const d=I(c.trim(),t,n,e);for(let b of Object.keys(d)){const y=w(d[b],e);a&&(a.properties[b]=y)}}const m=o.pop();if(o.length===0)s.push(m),i=!1,a=null,p=!0;else{const d=o[o.length-1];d.children||(d.children=[]),d.children.push(m),a=d}c="",u===0&&(i=!1,p=!0)}else if(M===10||M===59){if(i&&c.trim()&&c.includes(":")){const m=I(c.trim(),t,n,e);for(let d of Object.keys(m)){const b=w(m[d],e);a&&(a.properties[d]=b)}}else if(p&&c.trim()){const m=c.trim(),d=m.match(/^\$([a-zA-Z_][a-zA-Z0-9_]*)\s*:\s*(.+?);?$/);if(d){const[,b,y]=d;l[b]=w(y.trim(),e),c="";continue}if(e.enableAlias&&m.startsWith("@alias")){const b=m.match(C.ALIAS);if(b){const y=b[1],$=b[2];t.set(y,$),c="";continue}}}c=""}else c+=g}if(p&&c.trim()){const h=c.trim(),f=h.match(/^\$([a-zA-Z_][a-zA-Z0-9_]*)\s*:\s*(.+?);?$/);if(f){const[,g,M]=f;l[g]=w(M.trim(),e)}if(e.enableAlias&&h.startsWith("@alias")){const g=h.match(C.ALIAS);if(g){const M=g[1],m=g[2];t.set(M,m)}}}else if(i&&c.trim()&&c.includes(":")){const h=I(c.trim(),t,n,e);for(let f of Object.keys(h)){const g=w(h[f],e);a&&(a.properties[f]=g)}}if(Object.keys(l).length>0){const h={selector:e.rootSelector,properties:{},children:[]};Object.entries(l).forEach(([f,g])=>{h.properties["--"+f]=g}),s.unshift(h)}return j(s,e,"",t,n)}function j(r,e,t="",n,s,o=!1){let l="";for(const a of r){const c=a.selector.startsWith("@");c&&(l+=a.selector+` {
|
|
9
|
+
`);let i=a.selector;if(t&&(i.includes("&")?i=i.replace(C.AND,t):i.trim().startsWith(":")?i=t+i:i=t+" "+i),i=i,Object.keys(a.properties).length>0){l+=(o?" ".repeat(e.indentSize):"")+i+` {
|
|
10
|
+
`;for(let u in a.properties)if(a.properties.hasOwnProperty(u)){const p=w(a.properties[u],e);l+=(o?" ".repeat(e.indentSize):"")+" ".repeat(e.indentSize)+(p.length?`${u}: ${p};
|
|
11
|
+
`:`${u}
|
|
13
12
|
`)}l+=o?" ".repeat(e.indentSize)+`}
|
|
14
13
|
`:`}
|
|
15
14
|
|
|
16
|
-
`}a.children&&a.children.length>0&&(l+=
|
|
15
|
+
`}a.children&&a.children.length>0&&(l+=j(a.children,e,c?"":i,n,s,o||c)),c&&(l+=`}
|
|
17
16
|
|
|
18
|
-
`)}return l}function
|
|
17
|
+
`)}return l}function ie(r,e){let t=r;return t=t.replace(C.VARIABLE,(n,s)=>n.startsWith("$$")?`attr(${s})`:`var(--${s})`),t=w(t,e),t}async function G(r,e){const t=C.IMPORT;return(async s=>{const o=[],l=s.replace(t,(a,c)=>{const i=ue(c,e).then(u=>G(u,e)).catch(u=>(console.warn(`\u65E0\u6CD5\u5BFC\u5165CSS\u6587\u4EF6: ${c}`,u),""));return o.push(i),`__IMPORT_PLACEHOLDER_${o.length-1}__`});if(o.length>0){const a=await Promise.all(o);let c=l;for(let i=a.length;i--;)c=c.replace(`__IMPORT_PLACEHOLDER_${i}__`,a[i]);return c}return l})(r)}async function ue(r,e){if(e.importCache&&O.has(r))return O.get(r);const t=e.importBaseUrl?new URL(r,e.importBaseUrl).href:r;let n;if(typeof process<"u"&&process.versions&&process.versions.node&&typeof require<"u")try{const o=require("fs"),l=require("path");let a=t;t.startsWith(".")&&(a=l.join(process.cwd(),t)),n=o.readFileSync(a,"utf-8")}catch(o){throw new Error(`Node.js\u6587\u4EF6\u8BFB\u53D6\u5931\u8D25: ${t} - ${o.message}`)}else try{const o=new AbortController,l=setTimeout(()=>o.abort(),e.importTimeout),a=await fetch(t,{signal:o.signal,headers:{Accept:"text/css"}});if(clearTimeout(l),!a.ok)throw new Error(`HTTP\u9519\u8BEF: ${a.status} ${a.statusText}`);n=await a.text()}catch(o){throw o.name==="AbortError"?new Error(`\u5BFC\u5165\u8D85\u65F6: ${t}`):new Error(`\u65E0\u6CD5\u83B7\u53D6CSS: ${t} - ${o.message}`)}return e.importCache&&O.set(r,n),n}async function B(r,e={}){let{config:t,css:n}=Q(r);const s={...A,...e,...t};n=await G(n,s);let o=new Map,l=n,a=new Map;if(s.enableMacros){const{macros:u,css:p}=V(l,s);a=u,l=p;for(const[h,f]of a)L.set(h,f)}let c=l.trim();if(s.enableNesting&&l.includes("{"))try{c=le(l,s,o,a)}catch(u){console.warn("\u5D4C\u5957\u89E3\u6790\u5931\u8D25\uFF0C\u4F7F\u7528\u539F\u59CBCSS:",u)}else if(s.enableAlias){const{aliases:u,css:p}=parseAliasStatements(l);o=u,l=p}let i=c;i=ie(i,s);for(const[u,p]of v)try{i=p.convert(i,s)}catch(h){console.error("\u63D2\u4EF6\u5904\u7406\u5931\u8D25:",h)}return i}function X(r={}){const e={...A,...r},t=document.querySelectorAll(`style[${e.styleTagAttribute||"e"}]`);return t.forEach(n=>{let s=n.textContent;(async()=>{try{n.getAttribute("src")&&(s="@import "+n.getAttribute("src")+";");const l=await B(s,e),a=document.createElement("style");a.textContent=l,n.parentNode.insertBefore(a,n.nextSibling),e.preserveOriginal?n.style.display="none":n.remove()}catch(l){console.error("\u5904\u7406style\u6807\u7B7E\u5931\u8D25:",l)}})()}),t.length}function fe(r={}){A={...A,...r}}function N(r,e={}){const t={...A,...e};if(r)return(async()=>{try{const n=await B(r,t),s=document.createElement("style");return s.textContent=n,document.head.appendChild(s),s}catch(n){return console.error("\u5E94\u7528CSS\u5931\u8D25:",n),null}})();document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{X(t)}):X(t)}const D={convert:B,apply:N,config:fe,supportsP3:z(),detectP3Support:z,imports:{clearCache:function(){O.clear()},setBaseUrl:function(r){A.importBaseUrl=r},setCacheEnabled:function(r){A.importCache=r},setTimeout:function(r){A.importTimeout=r}},plugins:{use(r){const e=new r;return v.set(e.name??r.name,e),!0},remove(r){return v.get(r)?.destroy&&v.get(r).destroy(),v.delete(r),!0},getAll:function(){return Array.from(v.entries())},clear:function(){v.clear()}},aliases:{add:function(r,e){F.set(r,e)},remove:function(r){F.delete(r)},getAll:function(){return Array.from(F.entries())},clear:function(){F.clear()}},macros:{define:function(r,e,t=[]){if(typeof e=="function"){const s=e.toString().match(/{([\s\S]*)}/);s&&L.set(r,{params:t.map(o=>typeof o=="string"?{name:o}:o),body:s[1].trim()})}else L.set(r,{params:t.map(n=>typeof n=="string"?{name:n}:n),body:e})},call:function(r,...e){const t=L.get(r);if(!t)throw new Error(`\u672A\u5B9A\u4E49\u7684\u5B8F: ${r}`);const n=new Map;for(let s=0,o=t.params.length;s<o;s++){const l=t.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}`);n.set(l.name,a!==void 0?a:"")}return W(t.body,n,A)},getAll:function(){return Array.from(L.entries())},remove:function(r){L.delete(r)},clear:function(){L.clear()},parse:function(r){const{macros:e}=V(r,A);for(const[t,n]of e)L.set(t,n)}},math:{evaluate:function(r){return Z(r,A)}},colorUtils:{labToRGB:S,lchToLab:P,lchToRGB:function(r,e,t){const n=P(r,e,t);return S(n.L,n.a,n.b)},labToP3:_,lchToP3:function(r,e,t){const n=P(r,e,t);return _(n.L,n.a,n.b)},parseHexLab:function(r){const e=r.match(/lab#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i);if(!e)return null;const t=e[1],n=e[2],s=e[3],o=parseInt(t,16)/255*100,l=(parseInt(n,16)-128)*1.5,a=(parseInt(s,16)-128)*1.5;return S(o,l,a)},parseHexLch:function(r){const e=r.match(/lch#([0-9a-f]{2})([0-9a-f]{2})(\d{1,3})/i);if(!e)return null;const t=e[1],n=e[2],s=e[3],o=parseInt(t,16)/255*100,l=parseInt(n,16)/255*150,a=parseInt(s)/100*360,c=P(o,l,a);return S(c.L,c.a,c.b)},generateColor:function(r,e,t,n=null,s=!0){return T(r,e,t,{enableP3:s},n)},parseColor:function(r){try{const e=r.match(/lab\(\s*([\d.]+)(%?)\s+([\d.-]+)\s+([\d.-]+)(?:\s*\/\s*([\d.%]+))?\s*\)/i);if(e){let n=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=T(n,s,o,A,l);return{L:n,A:s,B:o,alpha:l,rgb:S(n,s,o),p3:_(n,s,o),colorString:a}}const t=r.match(/lch\(\s*([\d.]+)(%?)\s+([\d.]+)\s+([\d.]+)(deg)?(?:\s*\/\s*([\d.%]+))?\s*\)/i);if(t){let n=parseFloat(t[1]);const s=parseFloat(t[3]);let o=parseFloat(t[4]);const l=t[6]?t[6].includes("%")?parseFloat(t[6])/100:parseFloat(t[6]):null,a=P(n,s,o),c=T(a.L,a.a,a.b,A,l);return{L:n,C:s,H:o,alpha:l,lab:a,rgb:S(a.L,a.a,a.b),p3:_(a.L,a.a,a.b),colorString:c}}return null}catch(e){return console.warn("\u65E0\u6CD5\u89E3\u6790\u989C\u8272:",r,e),null}}}};D.Plugin=class{name="Plugin";constructor(){this.createdAt=Date.now(),this.install()}install(){}destroy(){}convert(r,e){throw new Error(`${this.name}.convert() \u5FC5\u987B\u88AB\u5B9E\u73B0`)}};const k=async function(...r){if(r.length>1||r[0]&&r[0].raw)return await pe(...r);const e=r[0];if(typeof e=="string"){const t=await B(e,r[1]);return t&&typeof t.then=="function",t}return typeof e=="object"&&e!==null?(A={...A,...e},k):r.length===0?N():k};async function pe(r,...e){let t=r[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"),t+=a+r[s+1]}const n=await B(t,A);return n&&typeof n.then=="function",n}return Object.assign(k,D),typeof window<"u"&&(N(),Object.defineProperty(window.HTMLElement.prototype,"cssVar",{get(){const r=this;return new Proxy(()=>{},{get(e,t){const n=t.startsWith("--")?t:`--${t}`;return r.style.getPropertyValue(n)},set(e,t,n){const s=t.startsWith("--")?t:`--${t}`;return r.style.setProperty(s,n),!0},apply(e,t,n){const s=n[0],o=n[1],l=s.startsWith("--")?s:`--${s}`;if(o===void 0)return r.style.getPropertyValue(l);r.style.setProperty(l,o)}})}})),k})();define([],A=>styimat);
|