styimat 4.3.0 → 6.0.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 +14 -21
- package/dist/styimat.js +92 -214
- package/dist/styimat.min.js +23 -23
- package/dist/styimat.min.mjs +23 -23
- package/dist/styimat.mjs +92 -214
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
2
|
# Styimat
|
|
2
3
|
[](https://gitee.com/wxy6987/styimat/stargazers)
|
|
3
4
|
[](https://gitee.com/wxy6987/styimat/members)
|
|
@@ -62,7 +63,7 @@ const css = `
|
|
|
62
63
|
.button { background-color: $primary; }
|
|
63
64
|
`;
|
|
64
65
|
|
|
65
|
-
const result = styimat.convert(css);
|
|
66
|
+
const result = await styimat.convert(css);
|
|
66
67
|
console.log(result);
|
|
67
68
|
```
|
|
68
69
|
|
|
@@ -110,8 +111,7 @@ const css = await styimat(`
|
|
|
110
111
|
// 方式2:传入配置对象(返回函数本身)
|
|
111
112
|
styimat({
|
|
112
113
|
enableP3: true,
|
|
113
|
-
enableMath: true
|
|
114
|
-
mathPrecision: 8
|
|
114
|
+
enableMath: true
|
|
115
115
|
});
|
|
116
116
|
|
|
117
117
|
// 方式3:无参数调用(自动处理页面中所有标记的<style>标签)
|
|
@@ -162,7 +162,7 @@ styimat.config({
|
|
|
162
162
|
});
|
|
163
163
|
|
|
164
164
|
// 4. 使用工具方法
|
|
165
|
-
const mathResult = styimat.math.evaluate('100px
|
|
165
|
+
const mathResult = styimat.math.evaluate('100px/2'); // "calc(100px / 2)"
|
|
166
166
|
const rgbColor = styimat.colorUtils.labToRGB(54.7, 77.9, 80.1);
|
|
167
167
|
```
|
|
168
168
|
|
|
@@ -254,18 +254,17 @@ $font-family: 'Inter', sans-serif;
|
|
|
254
254
|
#root-selector :root
|
|
255
255
|
#enable-nesting true
|
|
256
256
|
#enable-math true
|
|
257
|
-
#math-precision 8
|
|
258
257
|
|
|
259
258
|
/* 然后写您的CSS代码 */
|
|
260
259
|
$primary-color: lab#32a852;
|
|
261
|
-
$spacing: math(16px
|
|
260
|
+
$spacing: math(16px*2+4px);
|
|
262
261
|
|
|
263
262
|
body {
|
|
264
263
|
color: $primary-color;
|
|
265
264
|
padding: $spacing;
|
|
266
265
|
|
|
267
266
|
.container {
|
|
268
|
-
margin: math($spacing
|
|
267
|
+
margin: math($spacing/2);
|
|
269
268
|
}
|
|
270
269
|
}
|
|
271
270
|
```
|
|
@@ -278,14 +277,14 @@ body {
|
|
|
278
277
|
|
|
279
278
|
/* 然后写您的CSS代码 */
|
|
280
279
|
$primary-color: lab#32a852;
|
|
281
|
-
$spacing: math(16px
|
|
280
|
+
$spacing: math(16px*2+4px);
|
|
282
281
|
|
|
283
282
|
body {
|
|
284
283
|
color: $primary-color;
|
|
285
284
|
padding: $spacing;
|
|
286
285
|
|
|
287
286
|
.container {
|
|
288
|
-
margin: math($spacing
|
|
287
|
+
margin: math($spacing/2);
|
|
289
288
|
}
|
|
290
289
|
}
|
|
291
290
|
```
|
|
@@ -413,7 +412,7 @@ $padding-large: math(2rem * 1.5);
|
|
|
413
412
|
const styimat = require('styimat');
|
|
414
413
|
|
|
415
414
|
// 转换 CSS
|
|
416
|
-
const
|
|
415
|
+
const cssPromise = styimat.convert(cssString, config);
|
|
417
416
|
|
|
418
417
|
// 应用到页面
|
|
419
418
|
styimat.apply(cssString, config);
|
|
@@ -426,7 +425,6 @@ styimat.config({
|
|
|
426
425
|
convertLchToRGB: true,
|
|
427
426
|
enableP3: true,
|
|
428
427
|
enableMath: true,
|
|
429
|
-
mathPrecision: 6,
|
|
430
428
|
indentSize: 4,
|
|
431
429
|
enableNesting: true,
|
|
432
430
|
importBaseUrl: '', // 导入基础URL
|
|
@@ -438,8 +436,8 @@ styimat.config({
|
|
|
438
436
|
});
|
|
439
437
|
|
|
440
438
|
// 数学工具
|
|
441
|
-
styimat.math.evaluate('100px
|
|
442
|
-
styimat.math.evaluate('(16px
|
|
439
|
+
styimat.math.evaluate('100px/2'); // "calc(100px / 2)"
|
|
440
|
+
styimat.math.evaluate('(16px*1.5)+4px'); // "calc((16px * 1.5) + 4px)"
|
|
443
441
|
|
|
444
442
|
// 颜色工具
|
|
445
443
|
const rgb = styimat.colorUtils.labToRGB(54.7, 77.9, 80.1);
|
|
@@ -456,8 +454,8 @@ styimat.imports.setCacheEnabled(false); // 禁用导入缓存
|
|
|
456
454
|
styimat.imports.setTimeout(10000); // 设置导入超时时间
|
|
457
455
|
|
|
458
456
|
// 设置插件
|
|
459
|
-
styimat.plugins.
|
|
460
|
-
|
|
457
|
+
styimat.plugins.use({
|
|
458
|
+
name: "compress",
|
|
461
459
|
convert: function(css, config) {
|
|
462
460
|
return css.replace(/[\n\b]/g, "");
|
|
463
461
|
},
|
|
@@ -469,11 +467,7 @@ styimat.plugins.compress = {
|
|
|
469
467
|
}
|
|
470
468
|
};
|
|
471
469
|
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
for(const name in styimat.plugins) {
|
|
475
|
-
console.log(name);
|
|
476
|
-
}
|
|
470
|
+
styimat.plugins.remove("compress"); // 删除插件
|
|
477
471
|
```
|
|
478
472
|
|
|
479
473
|
### 配置选项
|
|
@@ -491,7 +485,6 @@ for(const name in styimat.plugins) {
|
|
|
491
485
|
| `convertLchToRGB` | boolean | `true` | 是否转换 LCH 颜色为 RGB |
|
|
492
486
|
| `enableP3` | boolean | `true` | 是否启用 Display P3 广色域支持 |
|
|
493
487
|
| `enableMath` | boolean | `true` | 是否启用 `math()` 函数增强 |
|
|
494
|
-
| `mathPrecision` | number | `6` | 数学计算的精度 |
|
|
495
488
|
| `importBaseUrl` | string | ` | 导入的基础URL |
|
|
496
489
|
| `importCache` | boolean | `true` | 是否缓存导入的文件 |
|
|
497
490
|
| `importTimeout` | number | `5000` | 导入超时时间(毫秒) |
|
package/dist/styimat.js
CHANGED
|
@@ -29,7 +29,6 @@ const styimat = (function() {
|
|
|
29
29
|
convertLchToRGB: true,
|
|
30
30
|
enableP3: true,
|
|
31
31
|
enableMath: true,
|
|
32
|
-
mathPrecision: 6,
|
|
33
32
|
importBaseUrl: '',
|
|
34
33
|
importCache: true,
|
|
35
34
|
importTimeout: 5000,
|
|
@@ -72,16 +71,13 @@ const styimat = (function() {
|
|
|
72
71
|
|
|
73
72
|
const configKey = camelCase(key);
|
|
74
73
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
} else {
|
|
81
|
-
config[configKey] = value;
|
|
82
|
-
}
|
|
74
|
+
|
|
75
|
+
if (value === 'true' || value === 'false') {
|
|
76
|
+
config[configKey] = value === 'true';
|
|
77
|
+
} else if (!isNaN(value) && value.trim() !== '') {
|
|
78
|
+
config[configKey] = Number(value);
|
|
83
79
|
} else {
|
|
84
|
-
|
|
80
|
+
config[configKey] = value;
|
|
85
81
|
}
|
|
86
82
|
} else {
|
|
87
83
|
console.warn(`无效的配置行: ${trimmed}`);
|
|
@@ -510,71 +506,23 @@ const styimat = (function() {
|
|
|
510
506
|
|
|
511
507
|
try {
|
|
512
508
|
let cleanExpr = expression.replace(/\s+/g, '');
|
|
513
|
-
const result = parseMathExpression(cleanExpr, config);
|
|
514
509
|
|
|
515
|
-
|
|
516
|
-
return processUnitExpression(cleanExpr, result);
|
|
517
|
-
} else {
|
|
518
|
-
return roundNumber(result, config.mathPrecision);
|
|
519
|
-
}
|
|
510
|
+
return parseMathExpression(cleanExpr, config.enableMath);
|
|
520
511
|
} catch (error) {
|
|
521
512
|
console.warn('math()表达式解析失败:', expression, error);
|
|
522
|
-
return `
|
|
513
|
+
return `calc(${expression})`;
|
|
523
514
|
}
|
|
524
515
|
}
|
|
525
516
|
|
|
526
517
|
/**
|
|
527
518
|
* 解析数学表达式
|
|
528
519
|
*/
|
|
529
|
-
function parseMathExpression(expr,
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
if (end === -1) break;
|
|
535
|
-
|
|
536
|
-
const inner = expr.substring(start + 1, end);
|
|
537
|
-
const innerResult = parseMathExpression(inner, config);
|
|
538
|
-
|
|
539
|
-
expr = expr.substring(0, start) + innerResult + expr.substring(end + 1);
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
return evaluateSimpleExpression(expr, config);
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
/**
|
|
546
|
-
* 评估简单表达式(无括号)
|
|
547
|
-
*/
|
|
548
|
-
function evaluateSimpleExpression(expr, config) {
|
|
549
|
-
const operators = [
|
|
550
|
-
{ regex: /([\d.]+(?:[a-zA-Z%]+)?)\*([\d.]+(?:[a-zA-Z%]+)?)/, handler: multiply },
|
|
551
|
-
{ regex: /([\d.]+(?:[a-zA-Z%]+)?)\/([\d.]+(?:[a-zA-Z%]+)?)/, handler: divide },
|
|
552
|
-
{ regex: /([\d.]+(?:[a-zA-Z%]+)?)\+([\d.]+(?:[a-zA-Z%]+)?)/, handler: add },
|
|
553
|
-
{ regex: /([\d.]+(?:[a-zA-Z%]+)?)-([\d.]+(?:[a-zA-Z%]+)?)/, handler: subtract }
|
|
554
|
-
];
|
|
555
|
-
|
|
556
|
-
let lastExpr = expr;
|
|
557
|
-
|
|
558
|
-
for (const op of operators) {
|
|
559
|
-
let match;
|
|
560
|
-
while ((match = expr.match(op.regex)) !== null) {
|
|
561
|
-
const left = parseValueWithUnit(match[1]);
|
|
562
|
-
const right = parseValueWithUnit(match[2]);
|
|
563
|
-
const result = op.handler(left, right);
|
|
564
|
-
|
|
565
|
-
expr = expr.substring(0, match.index) +
|
|
566
|
-
result.value +
|
|
567
|
-
expr.substring(match.index + match[0].length);
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
if (expr !== lastExpr) {
|
|
572
|
-
return evaluateSimpleExpression(expr, config);
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
const parsed = parseValueWithUnit(expr);
|
|
576
|
-
return parsed.value;
|
|
520
|
+
function parseMathExpression(expr, enableMath) {
|
|
521
|
+
return `calc(${expr
|
|
522
|
+
.replace(/([\da-z])([+-])(-?[\da-z])/g, '$1 $2 $3')
|
|
523
|
+
.replace(/([\da-z])([+-])(-?[\da-z])/g, '$1 $2 $3')})`;
|
|
577
524
|
}
|
|
525
|
+
|
|
578
526
|
|
|
579
527
|
/**
|
|
580
528
|
* 解析带单位的数值
|
|
@@ -592,30 +540,6 @@ const styimat = (function() {
|
|
|
592
540
|
return { value, unit };
|
|
593
541
|
}
|
|
594
542
|
|
|
595
|
-
/**
|
|
596
|
-
* 检查表达式是否包含单位
|
|
597
|
-
*/
|
|
598
|
-
function hasUnits(expr) {
|
|
599
|
-
return /[a-zA-Z%]/.test(expr);
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
/**
|
|
603
|
-
* 处理带单位的表达式
|
|
604
|
-
*/
|
|
605
|
-
function processUnitExpression(originalExpr, result) {
|
|
606
|
-
const unitMatch = originalExpr.match(/([a-zA-Z%]+)(?!.*[a-zA-Z%])/);
|
|
607
|
-
|
|
608
|
-
if (unitMatch) {
|
|
609
|
-
return result + unitMatch[1];
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
if (originalExpr.includes('%')) {
|
|
613
|
-
return result + '%';
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
return result + 'px';
|
|
617
|
-
}
|
|
618
|
-
|
|
619
543
|
// 数学运算函数
|
|
620
544
|
function multiply(a, b) {
|
|
621
545
|
if (a.unit === b.unit || (!a.unit && !b.unit)) {
|
|
@@ -682,6 +606,7 @@ const styimat = (function() {
|
|
|
682
606
|
|
|
683
607
|
const processMath = (str) => {
|
|
684
608
|
return str.replace(mathRegex, (match, expression) => {
|
|
609
|
+
|
|
685
610
|
return evaluateMathExpression(expression, config);
|
|
686
611
|
});
|
|
687
612
|
};
|
|
@@ -1456,86 +1381,68 @@ const styimat = (function() {
|
|
|
1456
1381
|
/**
|
|
1457
1382
|
* 主转换函数
|
|
1458
1383
|
*/
|
|
1459
|
-
function convert(cssText, customConfig = {}) {
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1384
|
+
async function convert(cssText, customConfig = {}) {
|
|
1385
|
+
let { config: headerConfig, css: cleanedCSS } = parseConfigHeader(cssText);
|
|
1386
|
+
const finalConfig = { ...defaultConfig, ...customConfig, ...headerConfig };
|
|
1387
|
+
cleanedCSS = await processImports(cleanedCSS, finalConfig);
|
|
1388
|
+
|
|
1389
|
+
let cssWithAliases = cleanedCSS;
|
|
1390
|
+
let aliases = new Map();
|
|
1391
|
+
if (finalConfig.enableAlias) {
|
|
1392
|
+
const { aliases: parsedAliases, css: cssWithoutAliases } = parseAliasStatements(cssWithAliases);
|
|
1393
|
+
aliases = parsedAliases;
|
|
1394
|
+
cssWithAliases = cssWithoutAliases;
|
|
1395
|
+
}
|
|
1471
1396
|
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1397
|
+
let cssWithMacros = cssWithAliases;
|
|
1398
|
+
let macros = new Map();
|
|
1399
|
+
if (finalConfig.enableMacros) {
|
|
1400
|
+
const { macros: parsedMacros, css: cssWithoutMacros } = parseMacroStatements(cssWithMacros, finalConfig);
|
|
1401
|
+
macros = parsedMacros;
|
|
1402
|
+
cssWithMacros = cssWithoutMacros;
|
|
1478
1403
|
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
}
|
|
1482
|
-
}
|
|
1483
|
-
|
|
1484
|
-
let cssAfterMacros = cssWithMacros;
|
|
1485
|
-
if (finalConfig.enableMacros && macros.size > 0) {
|
|
1486
|
-
cssAfterMacros = applyMacroCalls(cssAfterMacros, macros, finalConfig);
|
|
1487
|
-
}
|
|
1488
|
-
|
|
1489
|
-
const { globalVariables, selectorVariables, cssWithoutVars } =
|
|
1490
|
-
extractVariablesAndCSS(cssAfterMacros, finalConfig);
|
|
1491
|
-
|
|
1492
|
-
let processedCSS = cssWithoutVars.trim();
|
|
1493
|
-
if (finalConfig.enableNesting && cssWithoutVars.includes('{')) {
|
|
1494
|
-
try {
|
|
1495
|
-
processedCSS = parseNestedRules(cssWithoutVars, finalConfig, aliases, macros);
|
|
1496
|
-
} catch (error) {
|
|
1497
|
-
console.warn('嵌套解析失败,使用原始CSS:', error);
|
|
1498
|
-
}
|
|
1404
|
+
for (const [name, macro] of macros) {
|
|
1405
|
+
macroRegistry.set(name, macro);
|
|
1499
1406
|
}
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1409
|
+
let cssAfterMacros = cssWithMacros;
|
|
1410
|
+
if (finalConfig.enableMacros && macros.size > 0) {
|
|
1411
|
+
cssAfterMacros = applyMacroCalls(cssAfterMacros, macros, finalConfig);
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1414
|
+
const { globalVariables, selectorVariables, cssWithoutVars } =
|
|
1415
|
+
extractVariablesAndCSS(cssAfterMacros, finalConfig);
|
|
1500
1416
|
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
finalCSS = replaceVariableUses(finalCSS, globalVariables, selectorVariables, finalConfig);
|
|
1509
|
-
|
|
1510
|
-
for (const [name, plugin] of pluginMap) {
|
|
1511
|
-
try {
|
|
1512
|
-
if(plugin.enable) finalCSS = plugin.convert(finalCSS, finalConfig);
|
|
1513
|
-
} catch (error) {
|
|
1514
|
-
console.error('插件处理失败:', error);
|
|
1515
|
-
}
|
|
1417
|
+
let processedCSS = cssWithoutVars.trim();
|
|
1418
|
+
if (finalConfig.enableNesting && cssWithoutVars.includes('{')) {
|
|
1419
|
+
try {
|
|
1420
|
+
processedCSS = parseNestedRules(cssWithoutVars, finalConfig, aliases, macros);
|
|
1421
|
+
} catch (error) {
|
|
1422
|
+
console.warn('嵌套解析失败,使用原始CSS:', error);
|
|
1516
1423
|
}
|
|
1517
|
-
|
|
1518
|
-
let fullCSS = rootRule + finalCSS;
|
|
1519
|
-
|
|
1520
|
-
return fullCSS;
|
|
1521
|
-
};
|
|
1424
|
+
}
|
|
1522
1425
|
|
|
1523
|
-
const
|
|
1524
|
-
const finalConfig = { ...defaultConfig, ...customConfig };
|
|
1426
|
+
const rootRule = generateRootRule(globalVariables, finalConfig);
|
|
1525
1427
|
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1428
|
+
let finalCSS = processedCSS;
|
|
1429
|
+
if (selectorVariables.size > 0) {
|
|
1430
|
+
finalCSS = injectSelectorVariables(processedCSS, selectorVariables, finalConfig);
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
finalCSS = replaceVariableUses(finalCSS, globalVariables, selectorVariables, finalConfig);
|
|
1434
|
+
|
|
1435
|
+
let fullCSS = rootRule + finalCSS;
|
|
1436
|
+
|
|
1437
|
+
for (const [name, plugin] of pluginMap) {
|
|
1438
|
+
try {
|
|
1439
|
+
fullCSS = plugin.convert(fullCSS, finalConfig);
|
|
1440
|
+
} catch (error) {
|
|
1441
|
+
console.error('插件处理失败:', error);
|
|
1442
|
+
}
|
|
1538
1443
|
}
|
|
1444
|
+
|
|
1445
|
+
return fullCSS;
|
|
1539
1446
|
}
|
|
1540
1447
|
|
|
1541
1448
|
/**
|
|
@@ -1587,28 +1494,18 @@ const styimat = (function() {
|
|
|
1587
1494
|
const config = { ...defaultConfig, ...customConfig };
|
|
1588
1495
|
|
|
1589
1496
|
if (cssText) {
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
return null;
|
|
1603
|
-
}
|
|
1604
|
-
})();
|
|
1605
|
-
} else {
|
|
1606
|
-
const converted = convert(cssText, config);
|
|
1607
|
-
const styleEl = document.createElement('style');
|
|
1608
|
-
styleEl.textContent = converted;
|
|
1609
|
-
document.head.appendChild(styleEl);
|
|
1610
|
-
return styleEl;
|
|
1611
|
-
}
|
|
1497
|
+
return (async () => {
|
|
1498
|
+
try {
|
|
1499
|
+
const converted = await convert(cssText, config);
|
|
1500
|
+
const styleEl = document.createElement('style');
|
|
1501
|
+
styleEl.textContent = converted;
|
|
1502
|
+
document.head.appendChild(styleEl);
|
|
1503
|
+
return styleEl;
|
|
1504
|
+
} catch (error) {
|
|
1505
|
+
console.error('应用CSS失败:', error);
|
|
1506
|
+
return null;
|
|
1507
|
+
}
|
|
1508
|
+
})();
|
|
1612
1509
|
} else {
|
|
1613
1510
|
if (document.readyState === 'loading') {
|
|
1614
1511
|
document.addEventListener('DOMContentLoaded', () => {
|
|
@@ -1645,39 +1542,20 @@ const styimat = (function() {
|
|
|
1645
1542
|
}
|
|
1646
1543
|
},
|
|
1647
1544
|
|
|
1648
|
-
plugins:
|
|
1649
|
-
|
|
1545
|
+
plugins: {
|
|
1546
|
+
use(plugin) {
|
|
1650
1547
|
const createdFunc = plugin.created ?? (() => {});
|
|
1651
1548
|
createdFunc();
|
|
1652
|
-
pluginMap.set(name, plugin);
|
|
1549
|
+
pluginMap.set(plugin.name, plugin);
|
|
1653
1550
|
return true;
|
|
1654
1551
|
},
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
deleteProperty(target, name) {
|
|
1659
|
-
pluginMap.get(name)?.deleted();
|
|
1552
|
+
remove(name) {
|
|
1553
|
+
const deletedFunc = pluginMap.get(name).deleted ?? (() => {});
|
|
1554
|
+
deletedFunc();
|
|
1660
1555
|
pluginMap.delete(name);
|
|
1661
1556
|
return true;
|
|
1662
|
-
},
|
|
1663
|
-
has(terget, name) {
|
|
1664
|
-
return pluginMap.has(name);
|
|
1665
|
-
},
|
|
1666
|
-
ownKeys() {
|
|
1667
|
-
return Array.from(pluginMap.keys());
|
|
1668
|
-
},
|
|
1669
|
-
getOwnPropertyDescriptor(target, prop) {
|
|
1670
|
-
if (pluginMap.has(prop)) {
|
|
1671
|
-
return {
|
|
1672
|
-
enumerable: true,
|
|
1673
|
-
configurable: true,
|
|
1674
|
-
writable: true,
|
|
1675
|
-
value: pluginMap.get(prop)
|
|
1676
|
-
};
|
|
1677
|
-
}
|
|
1678
|
-
return undefined;
|
|
1679
1557
|
}
|
|
1680
|
-
}
|
|
1558
|
+
},
|
|
1681
1559
|
|
|
1682
1560
|
aliases: {
|
|
1683
1561
|
add: function(alias, property) {
|
|
@@ -1874,15 +1752,15 @@ const styimat = (function() {
|
|
|
1874
1752
|
};
|
|
1875
1753
|
|
|
1876
1754
|
// 创建主函数
|
|
1877
|
-
const styimat = function(...args) {
|
|
1755
|
+
const styimat = async function(...args) {
|
|
1878
1756
|
if (args.length > 1 || (args[0] && args[0].raw)) {
|
|
1879
|
-
return handleTemplateTag(...args);
|
|
1757
|
+
return await handleTemplateTag(...args);
|
|
1880
1758
|
}
|
|
1881
1759
|
|
|
1882
1760
|
const firstArg = args[0];
|
|
1883
1761
|
|
|
1884
1762
|
if (typeof firstArg === 'string') {
|
|
1885
|
-
const result = convert(firstArg, { ...defaultConfig, ...args[1] });
|
|
1763
|
+
const result = await convert(firstArg, { ...defaultConfig, ...args[1] });
|
|
1886
1764
|
|
|
1887
1765
|
if (result && typeof result.then === 'function') {
|
|
1888
1766
|
return result;
|
|
@@ -1902,7 +1780,7 @@ const styimat = (function() {
|
|
|
1902
1780
|
return styimat;
|
|
1903
1781
|
};
|
|
1904
1782
|
|
|
1905
|
-
function handleTemplateTag(strings, ...values) {
|
|
1783
|
+
async function handleTemplateTag(strings, ...values) {
|
|
1906
1784
|
let cssText = strings[0];
|
|
1907
1785
|
|
|
1908
1786
|
for (let i = 0; i < values.length; i++) {
|
|
@@ -1920,7 +1798,7 @@ const styimat = (function() {
|
|
|
1920
1798
|
cssText += result + strings[i + 1];
|
|
1921
1799
|
}
|
|
1922
1800
|
|
|
1923
|
-
const result = convert(cssText, defaultConfig);
|
|
1801
|
+
const result = await convert(cssText, defaultConfig);
|
|
1924
1802
|
|
|
1925
1803
|
if (result && typeof result.then === 'function') {
|
|
1926
1804
|
return result;
|