@mlut/core 2.1.1 → 2.1.3
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 +3 -3
- package/dist/jit/JitEngine.d.ts +3 -0
- package/dist/jit/JitEngine.js +61 -7
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# mlut core #
|
|
2
2
|
|
|
3
|
-
<img alt="Logo" src="https://github.com/
|
|
3
|
+
<img alt="Logo" src="https://github.com/mlutcss/mlut/raw/master/docs/img/logo-full.png" width="350"/>
|
|
4
4
|
|
|
5
|
-
The [mlut](https://github.com/
|
|
5
|
+
The [mlut](https://github.com/mlutcss/mlut) core contains:
|
|
6
6
|
- Sass tools
|
|
7
7
|
- CSS library
|
|
8
8
|
- JIT engine
|
|
@@ -18,7 +18,7 @@ When using this package, you will need to install Sass separately. We recommend
|
|
|
18
18
|
This allows you to control the versions of all your dependencies, and to choose which Sass implementation to use.
|
|
19
19
|
|
|
20
20
|
## Documentation ##
|
|
21
|
-
Full documentation available [here](https://
|
|
21
|
+
Full documentation available [here](https://mlutcss.github.io/mlut/)
|
|
22
22
|
|
|
23
23
|
## License ##
|
|
24
24
|
MIT
|
package/dist/jit/JitEngine.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export declare class JitEngine {
|
|
2
2
|
private utils;
|
|
3
|
+
private breakpoints;
|
|
4
|
+
private breakpointsMap;
|
|
3
5
|
private inputFileDir;
|
|
4
6
|
private sassModuleName;
|
|
5
7
|
private inputFileCache;
|
|
@@ -13,6 +15,7 @@ export declare class JitEngine {
|
|
|
13
15
|
updateSassConfig(content: string): Promise<void>;
|
|
14
16
|
generateCss(): Promise<string>;
|
|
15
17
|
private extractUtils;
|
|
18
|
+
private compareUtilsWithAtRule;
|
|
16
19
|
private filterAndProcessClassStr;
|
|
17
20
|
private extractUserSassConfig;
|
|
18
21
|
private loadUtils;
|
package/dist/jit/JitEngine.js
CHANGED
|
@@ -9,6 +9,8 @@ const sass = await import('sass-embedded')
|
|
|
9
9
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
10
10
|
export class JitEngine {
|
|
11
11
|
utils = new Set();
|
|
12
|
+
breakpoints = [];
|
|
13
|
+
breakpointsMap = {};
|
|
12
14
|
inputFileDir = __dirname;
|
|
13
15
|
sassModuleName = 'tools';
|
|
14
16
|
inputFileCache = '@use "../sass/tools";';
|
|
@@ -66,7 +68,14 @@ export class JitEngine {
|
|
|
66
68
|
logger.warn('No content to generate CSS was found!');
|
|
67
69
|
return '';
|
|
68
70
|
}
|
|
69
|
-
const
|
|
71
|
+
const mainUtils = [];
|
|
72
|
+
const atRuleUtils = [];
|
|
73
|
+
for (const [main, withAr] of this.utilsByFile.values()) {
|
|
74
|
+
mainUtils.push(main);
|
|
75
|
+
atRuleUtils.push(withAr);
|
|
76
|
+
}
|
|
77
|
+
const sortedAtRuleUtils = atRuleUtils.flat().sort(this.compareUtilsWithAtRule);
|
|
78
|
+
const allUniqueUtils = [...new Set(mainUtils.flat().concat(sortedAtRuleUtils))];
|
|
70
79
|
const applyStr = `\n@include ${this.sassModuleName}.apply(${JSON.stringify(allUniqueUtils)},(),true);`;
|
|
71
80
|
return sass.compileStringAsync(this.inputFileCache + applyStr, { loadPaths: [this.inputFileDir, 'node_modules'] }).then(({ css }) => css, (e) => (logger.error('Sass compilation error.', e), ''));
|
|
72
81
|
}
|
|
@@ -83,8 +92,10 @@ export class JitEngine {
|
|
|
83
92
|
.replace(this.utilsRegexps.singleQuotedContent, '')
|
|
84
93
|
.match(this.utilsRegexps.backtickQuotedContent)
|
|
85
94
|
?.reduce(this.filterAndProcessClassStr, allClassNames);
|
|
86
|
-
|
|
87
|
-
|
|
95
|
+
const utilsWithAtRule = new Set();
|
|
96
|
+
const mainUtils = [...allClassNames.join(' ').split(' ').reduce((acc, cssClass) => {
|
|
97
|
+
const utilComponents = cssClass.split('_');
|
|
98
|
+
const utility = utilComponents.find((str) => (this.utilsRegexps.utilName.test(str)));
|
|
88
99
|
if (utility) {
|
|
89
100
|
const separator = utility.replace(this.utilsRegexps.utilName, '')[0];
|
|
90
101
|
if (separator && !this.utilsRegexps.valueSeparator.test(separator)) {
|
|
@@ -93,12 +104,42 @@ export class JitEngine {
|
|
|
93
104
|
const utilName = utility.match(this.utilsRegexps.utilName)?.[0];
|
|
94
105
|
if (this.utils.has(utilName) ||
|
|
95
106
|
(utilName[0] === '-' && !this.utilsRegexps.contextUtil.test(utilName))) {
|
|
96
|
-
|
|
107
|
+
const [atRule] = utilComponents;
|
|
108
|
+
if (utilComponents.length > 1 && !atRule.startsWith(utilName) && (atRule[0] === '@' ||
|
|
109
|
+
atRule[0] === '<' ||
|
|
110
|
+
(atRule in this.breakpointsMap) ||
|
|
111
|
+
this.breakpoints.find((item) => atRule.startsWith(item)))) {
|
|
112
|
+
utilsWithAtRule.add(cssClass);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
acc.add(cssClass);
|
|
116
|
+
}
|
|
97
117
|
}
|
|
98
118
|
}
|
|
99
119
|
return acc;
|
|
100
120
|
}, new Set())];
|
|
121
|
+
return [mainUtils, [...utilsWithAtRule]];
|
|
101
122
|
}
|
|
123
|
+
compareUtilsWithAtRule = (a, b) => {
|
|
124
|
+
if (a[0] === '@' && b[0] === '@') {
|
|
125
|
+
return 0;
|
|
126
|
+
}
|
|
127
|
+
if (a[0] === '@') {
|
|
128
|
+
return 1;
|
|
129
|
+
}
|
|
130
|
+
if (b[0] === '@') {
|
|
131
|
+
return -1;
|
|
132
|
+
}
|
|
133
|
+
const bpA = a.split('_')[0];
|
|
134
|
+
const bpB = b.split('_')[0];
|
|
135
|
+
if (!(bpA in this.breakpointsMap)) {
|
|
136
|
+
return 1;
|
|
137
|
+
}
|
|
138
|
+
if (!(bpB in this.breakpointsMap)) {
|
|
139
|
+
return -1;
|
|
140
|
+
}
|
|
141
|
+
return this.breakpointsMap[bpA] - this.breakpointsMap[bpB];
|
|
142
|
+
};
|
|
102
143
|
filterAndProcessClassStr = (acc, str) => {
|
|
103
144
|
if (this.utilsRegexps.uppercaseLetter.test(str)) {
|
|
104
145
|
acc.push(str.replace(this.utilsRegexps.tooMoreSpaces, ' ').slice(1, -1));
|
|
@@ -120,12 +161,25 @@ export class JitEngine {
|
|
|
120
161
|
}
|
|
121
162
|
}
|
|
122
163
|
async loadUtils(userConfig = this.defaultSassConfig) {
|
|
123
|
-
const
|
|
164
|
+
const placeholderRules = `
|
|
165
|
+
\n a{ all: map.keys(map.get(ml.$utils-db, "utils", "registry")); }
|
|
166
|
+
\n b{ all: map.keys(map.get(ml.$at-rules-cfg, "breakpoints")); }
|
|
167
|
+
`;
|
|
168
|
+
const { css } = (await sass.compileStringAsync(userConfig + placeholderRules, {
|
|
124
169
|
style: 'compressed',
|
|
125
170
|
loadPaths: [__dirname, 'node_modules'],
|
|
126
171
|
}));
|
|
127
|
-
const
|
|
128
|
-
|
|
172
|
+
const [, rawUtils, rawBreakpoints] = css.split('all:');
|
|
173
|
+
const rawUtilsStrEnd = rawUtils.lastIndexOf('"') - rawUtils.length + 1;
|
|
174
|
+
const rawBpsStrEnd = rawBreakpoints.lastIndexOf('"') - rawBreakpoints.length + 1;
|
|
175
|
+
this.utils = new Set(JSON.parse('[' + rawUtils.slice(0, rawUtilsStrEnd) + ']'));
|
|
176
|
+
this.breakpoints =
|
|
177
|
+
JSON.parse('[' + rawBreakpoints.slice(0, rawBpsStrEnd) + ']');
|
|
178
|
+
this.breakpointsMap = this.breakpoints.reduce((acc, item, i) => {
|
|
179
|
+
acc['<' + item] = i - 0.1;
|
|
180
|
+
acc[item] = i;
|
|
181
|
+
return acc;
|
|
182
|
+
}, {});
|
|
129
183
|
}
|
|
130
184
|
}
|
|
131
185
|
export const jitEngine = new JitEngine();
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mlut/core",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.3",
|
|
4
4
|
"description": "Atomic CSS toolkit with Sass and ergonomics for creating styles of any complexity",
|
|
5
5
|
"author": "mr150",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"homepage": "https://
|
|
8
|
+
"homepage": "https://mlut.style/",
|
|
9
9
|
"types": "dist/index.d.ts",
|
|
10
10
|
"keywords": [
|
|
11
11
|
"mlut",
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
"repository": {
|
|
22
22
|
"type": "git",
|
|
23
23
|
"directory": "packages/core",
|
|
24
|
-
"url": "https://github.com/
|
|
24
|
+
"url": "https://github.com/mlutcss/mlut.git"
|
|
25
25
|
},
|
|
26
26
|
"bugs": {
|
|
27
|
-
"url": "https://github.com/
|
|
27
|
+
"url": "https://github.com/mlutcss/mlut/issues"
|
|
28
28
|
},
|
|
29
29
|
"exports": {
|
|
30
30
|
".": {
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
],
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/node": "^20.10.5",
|
|
44
|
-
"sass
|
|
45
|
-
"sass": "^1.
|
|
44
|
+
"sass": "^1.93.0",
|
|
45
|
+
"sass-embedded": "^1.93.0",
|
|
46
46
|
"typescript": "^4.8.0"
|
|
47
47
|
}
|
|
48
48
|
}
|