@mlut/core 1.0.0 → 2.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/dist/jit/JitEngine.d.ts +4 -3
- package/dist/jit/JitEngine.js +25 -31
- package/package.json +6 -6
package/dist/jit/JitEngine.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
export declare class JitEngine {
|
|
2
2
|
private utils;
|
|
3
|
-
private inputFilePath;
|
|
4
3
|
private inputFileDir;
|
|
5
4
|
private sassModuleName;
|
|
6
5
|
private inputFileCache;
|
|
7
|
-
private generationDebounce;
|
|
8
6
|
private readonly defaultSassConfig;
|
|
9
7
|
private readonly utilsByFile;
|
|
10
8
|
private readonly utilsRegexps;
|
|
11
9
|
private readonly configRegexps;
|
|
12
10
|
init([inputPath, inputContent]?: [string | undefined, string | undefined]): Promise<void>;
|
|
13
|
-
|
|
11
|
+
putContent(id: string, content: string | undefined): void;
|
|
12
|
+
deleteContent(id: string): boolean;
|
|
13
|
+
updateSassConfig(content: string): Promise<void>;
|
|
14
|
+
generateCss(): Promise<string>;
|
|
14
15
|
private extractUtils;
|
|
15
16
|
private normalizeClassNameStr;
|
|
16
17
|
private extractUserSassConfig;
|
package/dist/jit/JitEngine.js
CHANGED
|
@@ -8,11 +8,9 @@ const sass = await import('sass-embedded')
|
|
|
8
8
|
const __dirname = new URL('.', import.meta.url).pathname;
|
|
9
9
|
export class JitEngine {
|
|
10
10
|
utils = new Set();
|
|
11
|
-
inputFilePath = '';
|
|
12
11
|
inputFileDir = __dirname;
|
|
13
12
|
sassModuleName = 'tools';
|
|
14
13
|
inputFileCache = '@use "../sass/tools";';
|
|
15
|
-
generationDebounce;
|
|
16
14
|
defaultSassConfig = '@use "sass:map";\n @use "../sass/tools/settings" as ml;';
|
|
17
15
|
utilsByFile = new Map();
|
|
18
16
|
utilsRegexps = {
|
|
@@ -28,45 +26,41 @@ export class JitEngine {
|
|
|
28
26
|
async init([inputPath, inputContent] = ['', '']) {
|
|
29
27
|
let sassConfig = this.defaultSassConfig;
|
|
30
28
|
if (inputPath && inputContent) {
|
|
31
|
-
this.
|
|
32
|
-
this.inputFileDir = path.dirname(this.inputFilePath);
|
|
29
|
+
this.inputFileDir = path.dirname(path.resolve(process.cwd(), inputPath));
|
|
33
30
|
this.inputFileCache = inputContent;
|
|
34
31
|
sassConfig = this.extractUserSassConfig(inputContent);
|
|
35
32
|
}
|
|
36
33
|
await this.loadUtils(sassConfig);
|
|
37
34
|
}
|
|
38
|
-
|
|
35
|
+
putContent(id, content) {
|
|
36
|
+
if (!content) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
this.utilsByFile.set(id, this.extractUtils(content));
|
|
40
|
+
}
|
|
41
|
+
deleteContent(id) {
|
|
42
|
+
return this.utilsByFile.delete(id);
|
|
43
|
+
}
|
|
44
|
+
async updateSassConfig(content) {
|
|
45
|
+
this.inputFileCache = content;
|
|
46
|
+
const sassConfig = this.extractUserSassConfig(content);
|
|
47
|
+
if (sassConfig) {
|
|
48
|
+
await this.loadUtils(sassConfig);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async generateCss() {
|
|
39
52
|
if (this.utils.size === 0) {
|
|
40
53
|
logger.warn('Config with utilities is not loaded!');
|
|
41
54
|
return '';
|
|
42
55
|
}
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (sassConfig) {
|
|
47
|
-
await this.loadUtils(sassConfig);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
else if (content) {
|
|
51
|
-
this.utilsByFile.set(id, this.extractUtils(content));
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
this.utilsByFile.delete(id);
|
|
56
|
+
if (this.utilsByFile.size === 0) {
|
|
57
|
+
logger.warn('No content to generate CSS was found!');
|
|
58
|
+
return '';
|
|
55
59
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
this.generationDebounce = setTimeout(async () => {
|
|
61
|
-
clearTimeout(timeout);
|
|
62
|
-
const allUniqueUtils = [...new Set([...this.utilsByFile.values()].flat())];
|
|
63
|
-
const applyStr = `\n@include ${this.sassModuleName}.apply(${JSON.stringify(allUniqueUtils)},(),true);`;
|
|
64
|
-
// `compileStringAsync` is almost always faster than `compile` in sass-embedded
|
|
65
|
-
const css = await sass.compileStringAsync(this.inputFileCache + applyStr, { loadPaths: [this.inputFileDir, 'node_modules'] }).then(({ css }) => css, (e) => (logger.error('Sass compilation error.', e), undefined));
|
|
66
|
-
resolve(css);
|
|
67
|
-
}, 100);
|
|
68
|
-
timeout = setTimeout(() => resolve(undefined), 300);
|
|
69
|
-
});
|
|
60
|
+
const allUniqueUtils = [...new Set([...this.utilsByFile.values()].flat())];
|
|
61
|
+
const applyStr = `\n@include ${this.sassModuleName}.apply(${JSON.stringify(allUniqueUtils)},(),true);`;
|
|
62
|
+
// `compileStringAsync` is almost always faster than `compile` in sass-embedded
|
|
63
|
+
return sass.compileStringAsync(this.inputFileCache + applyStr, { loadPaths: [this.inputFileDir, 'node_modules'] }).then(({ css }) => css, (e) => (logger.error('Sass compilation error.', e), ''));
|
|
70
64
|
}
|
|
71
65
|
extractUtils(content) {
|
|
72
66
|
const allClassNames = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mlut/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Atomic CSS toolkit with Sass and ergonomics for creating styles of any complexity",
|
|
5
5
|
"author": "mr150",
|
|
6
6
|
"type": "module",
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
"url": "https://github.com/mr150/mlut/issues"
|
|
28
28
|
},
|
|
29
29
|
"exports": {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
".": {
|
|
31
|
+
"default": "./dist/index.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
34
|
"scripts": {
|
|
35
35
|
"build": "rm -rf dist && tsc && cp src/sass dist/ -r"
|
|
36
36
|
},
|
|
@@ -43,6 +43,6 @@
|
|
|
43
43
|
"@types/node": "^20.10.5",
|
|
44
44
|
"sass-embedded": "^1.71.0",
|
|
45
45
|
"sass": "^1.71.0",
|
|
46
|
-
"typescript": "^
|
|
46
|
+
"typescript": "^4.8.0"
|
|
47
47
|
}
|
|
48
48
|
}
|