@mlut/core 2.0.0 → 2.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/dist/jit/JitEngine.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export declare class JitEngine {
|
|
|
13
13
|
updateSassConfig(content: string): Promise<void>;
|
|
14
14
|
generateCss(): Promise<string>;
|
|
15
15
|
private extractUtils;
|
|
16
|
-
private
|
|
16
|
+
private filterAndProcessClassStr;
|
|
17
17
|
private extractUserSassConfig;
|
|
18
18
|
private loadUtils;
|
|
19
19
|
}
|
package/dist/jit/JitEngine.js
CHANGED
|
@@ -14,16 +14,23 @@ export class JitEngine {
|
|
|
14
14
|
defaultSassConfig = '@use "sass:map";\n @use "../sass/tools/settings" as ml;';
|
|
15
15
|
utilsByFile = new Map();
|
|
16
16
|
utilsRegexps = {
|
|
17
|
-
quotedContent: /"\n?[^"]
|
|
18
|
-
singleQuotedContent: /'\n?[^']
|
|
17
|
+
quotedContent: /"\n?[^"]*[^"\n]*\n?"/g,
|
|
18
|
+
singleQuotedContent: /'\n?[^']*[^'\n]*\n?'/g,
|
|
19
|
+
backtickQuotedContent: /`\n?[^`]*[^`\n]*\n?`/g,
|
|
19
20
|
tooMoreSpaces: /\s{2,}|\n/g,
|
|
21
|
+
escapedQuotes: /\\['"`]/g,
|
|
20
22
|
utilName: /^-?[A-Z]{1}[a-zA-Z]*/,
|
|
23
|
+
uppercaseLetter: /[A-Z]/,
|
|
24
|
+
contextUtil: /-Ctx([\d\-#]|$)/,
|
|
21
25
|
};
|
|
22
26
|
configRegexps = {
|
|
23
27
|
userSettings: /@use ['"][^'"]*(tools|mlut|core)['"](\s*as\s+[\w]+)?\s+with\s*\(([^;]+)\);/s,
|
|
24
28
|
sassModuleName: /@use ['"][^'"]*(tools|mlut|core)['"]\s*;/s,
|
|
25
29
|
};
|
|
26
30
|
async init([inputPath, inputContent] = ['', '']) {
|
|
31
|
+
if (this.utils.size) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
27
34
|
let sassConfig = this.defaultSassConfig;
|
|
28
35
|
if (inputPath && inputContent) {
|
|
29
36
|
this.inputFileDir = path.dirname(path.resolve(process.cwd(), inputPath));
|
|
@@ -59,39 +66,39 @@ export class JitEngine {
|
|
|
59
66
|
}
|
|
60
67
|
const allUniqueUtils = [...new Set([...this.utilsByFile.values()].flat())];
|
|
61
68
|
const applyStr = `\n@include ${this.sassModuleName}.apply(${JSON.stringify(allUniqueUtils)},(),true);`;
|
|
62
|
-
// `compileStringAsync` is almost always faster than `compile` in sass-embedded
|
|
63
69
|
return sass.compileStringAsync(this.inputFileCache + applyStr, { loadPaths: [this.inputFileDir, 'node_modules'] }).then(({ css }) => css, (e) => (logger.error('Sass compilation error.', e), ''));
|
|
64
70
|
}
|
|
65
71
|
extractUtils(content) {
|
|
66
|
-
|
|
67
|
-
const
|
|
72
|
+
let fixedContent = content.replace(this.utilsRegexps.escapedQuotes, '');
|
|
73
|
+
const allClassNames = fixedContent
|
|
68
74
|
.match(this.utilsRegexps.quotedContent)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
.replace(this.utilsRegexps.quotedContent, '')
|
|
75
|
+
?.reduce(this.filterAndProcessClassStr, []) ?? [];
|
|
76
|
+
fixedContent = fixedContent.replace(this.utilsRegexps.quotedContent, '');
|
|
77
|
+
fixedContent
|
|
73
78
|
.match(this.utilsRegexps.singleQuotedContent)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
}
|
|
79
|
+
?.reduce(this.filterAndProcessClassStr, allClassNames);
|
|
80
|
+
fixedContent
|
|
81
|
+
.replace(this.utilsRegexps.singleQuotedContent, '')
|
|
82
|
+
.match(this.utilsRegexps.backtickQuotedContent)
|
|
83
|
+
?.reduce(this.filterAndProcessClassStr, allClassNames);
|
|
81
84
|
return [...allClassNames.join(' ').split(' ').reduce((acc, cssClass) => {
|
|
82
85
|
const utility = cssClass.split('_').find((str) => (this.utilsRegexps.utilName.test(str)));
|
|
83
86
|
if (utility) {
|
|
84
87
|
const utilName = utility.match(this.utilsRegexps.utilName)?.[0];
|
|
85
|
-
if (this.utils.has(utilName) ||
|
|
88
|
+
if (this.utils.has(utilName) ||
|
|
89
|
+
(utilName[0] === '-' && !this.utilsRegexps.contextUtil.test(utilName))) {
|
|
86
90
|
acc.add(cssClass);
|
|
87
91
|
}
|
|
88
92
|
}
|
|
89
93
|
return acc;
|
|
90
94
|
}, new Set())];
|
|
91
95
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
96
|
+
filterAndProcessClassStr = (acc, str) => {
|
|
97
|
+
if (this.utilsRegexps.uppercaseLetter.test(str)) {
|
|
98
|
+
acc.push(str.replace(this.utilsRegexps.tooMoreSpaces, ' ').slice(1, -1));
|
|
99
|
+
}
|
|
100
|
+
return acc;
|
|
101
|
+
};
|
|
95
102
|
extractUserSassConfig(content) {
|
|
96
103
|
let matchResult = content.match(this.configRegexps.userSettings);
|
|
97
104
|
if (matchResult != null) {
|
|
@@ -1591,6 +1591,18 @@ $utils-db: (
|
|
|
1591
1591
|
'nn': none,
|
|
1592
1592
|
),
|
|
1593
1593
|
),
|
|
1594
|
+
'Coi': (
|
|
1595
|
+
'properties': counter-increment,
|
|
1596
|
+
'conversion': 'num-length',
|
|
1597
|
+
),
|
|
1598
|
+
'Cor': (
|
|
1599
|
+
'properties': counter-reset,
|
|
1600
|
+
'conversion': 'num-length',
|
|
1601
|
+
),
|
|
1602
|
+
'Cos': (
|
|
1603
|
+
'properties': counter-set,
|
|
1604
|
+
'conversion': 'num-length',
|
|
1605
|
+
),
|
|
1594
1606
|
|
|
1595
1607
|
// SVG
|
|
1596
1608
|
'Fi': (
|