@navita/engine 0.2.2 → 3.0.0-next.1
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/_virtual/_rolldown/runtime.cjs +23 -0
- package/cache.cjs +26 -26
- package/cache.mjs +28 -24
- package/helpers/declarationsToBlock.cjs +10 -14
- package/helpers/declarationsToBlock.mjs +12 -12
- package/helpers/generateCombinedAtRules.cjs +5 -7
- package/helpers/generateCombinedAtRules.mjs +7 -5
- package/helpers/getPropertyPriority.cjs +221 -260
- package/helpers/getPropertyPriority.mjs +223 -258
- package/helpers/hyphenateProperty.cjs +8 -9
- package/helpers/hyphenateProperty.mjs +10 -7
- package/helpers/isContainerQuery.cjs +4 -4
- package/helpers/isContainerQuery.mjs +6 -2
- package/helpers/isMediaQuery.cjs +4 -4
- package/helpers/isMediaQuery.mjs +6 -2
- package/helpers/isNestedSelector.cjs +5 -5
- package/helpers/isNestedSelector.mjs +7 -3
- package/helpers/isObject.cjs +4 -4
- package/helpers/isObject.mjs +6 -2
- package/helpers/isSupportsQuery.cjs +4 -4
- package/helpers/isSupportsQuery.mjs +6 -2
- package/helpers/normalizeCSSVarsProperty.cjs +7 -11
- package/helpers/normalizeCSSVarsProperty.mjs +9 -9
- package/helpers/normalizeCSSVarsValue.cjs +6 -8
- package/helpers/normalizeCSSVarsValue.mjs +8 -6
- package/helpers/normalizeNestedProperty.cjs +5 -7
- package/helpers/normalizeNestedProperty.mjs +7 -5
- package/helpers/pixelifyProperties.cjs +50 -53
- package/helpers/pixelifyProperties.mjs +52 -51
- package/helpers/splitSelectorList.cjs +55 -0
- package/helpers/splitSelectorList.mjs +57 -0
- package/helpers/splitStyleBlocks.cjs +23 -25
- package/helpers/splitStyleBlocks.mjs +25 -23
- package/helpers/transformContentProperty.cjs +4 -5
- package/helpers/transformContentProperty.mjs +6 -3
- package/identifiers/IDGenerator.cjs +9 -9
- package/identifiers/IDGenerator.mjs +11 -7
- package/identifiers/alphaIDGenerator.cjs +23 -26
- package/identifiers/alphaIDGenerator.mjs +25 -24
- package/identifiers/propertyValueIDGenerator.cjs +18 -23
- package/identifiers/propertyValueIDGenerator.mjs +20 -21
- package/index.cjs +187 -238
- package/index.d.ts +91 -84
- package/index.mjs +184 -234
- package/package.json +1 -1
- package/printers/printFontFaces.cjs +7 -12
- package/printers/printFontFaces.mjs +9 -10
- package/printers/printKeyFrames.cjs +10 -16
- package/printers/printKeyFrames.mjs +12 -14
- package/printers/printSourceMap.cjs +34 -39
- package/printers/printSourceMap.mjs +36 -37
- package/printers/printStyleBlocks.cjs +71 -70
- package/printers/printStyleBlocks.mjs +73 -68
- package/printers/sortAtRules.cjs +8 -7
- package/printers/sortAtRules.mjs +7 -4
- package/processKeyframes.cjs +16 -22
- package/processKeyframes.mjs +19 -20
- package/processStyles.cjs +99 -105
- package/processStyles.mjs +101 -103
- package/types.cjs +0 -2
- package/types.mjs +4 -1
- package/wrappers/classList.cjs +4 -5
- package/wrappers/classList.mjs +6 -3
- package/wrappers/static.cjs +4 -5
- package/wrappers/static.mjs +6 -3
- package/printers/sortStatic.cjs +0 -7
- package/printers/sortStatic.mjs +0 -5
package/index.d.ts
CHANGED
|
@@ -1,98 +1,105 @@
|
|
|
1
|
-
import { CSSKeyframes, FontFaceRule, StyleRule } from
|
|
1
|
+
import { CSSKeyframes, FontFaceRule, StyleRule } from "@navita/types";
|
|
2
2
|
|
|
3
|
+
//#region src/types.d.ts
|
|
3
4
|
interface StyleBlock {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
type: "rule" | "static";
|
|
6
|
+
selector: string;
|
|
7
|
+
property: string;
|
|
8
|
+
value: string;
|
|
9
|
+
pseudo: string;
|
|
10
|
+
media: string;
|
|
11
|
+
support: string;
|
|
12
|
+
container: string;
|
|
13
|
+
id: string | number;
|
|
13
14
|
}
|
|
14
15
|
interface KeyframesBlock {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
type: "keyframes";
|
|
17
|
+
rule: CSSKeyframes;
|
|
18
|
+
id: string;
|
|
18
19
|
}
|
|
19
20
|
interface FontFaceBlock {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
type: "fontFace";
|
|
22
|
+
rule: FontFaceRule[];
|
|
23
|
+
id: string;
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/wrappers/classList.d.ts
|
|
27
|
+
declare class ClassList extends String {}
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/wrappers/static.d.ts
|
|
30
|
+
declare class Static {}
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/index.d.ts
|
|
31
33
|
type CacheKeys = keyof Engine["caches"];
|
|
32
|
-
type UsedIdCache = {
|
|
33
|
-
[key in CacheKeys]?: (string | number)[];
|
|
34
|
-
};
|
|
34
|
+
type UsedIdCache = { [key in CacheKeys]?: (string | number)[] };
|
|
35
35
|
interface Identifier {
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
value: string;
|
|
37
|
+
id: string;
|
|
38
38
|
}
|
|
39
39
|
type Options = {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
context?: string;
|
|
41
|
+
enableSourceMaps?: boolean;
|
|
42
|
+
enableDebugIdentifiers?: boolean;
|
|
43
43
|
};
|
|
44
44
|
declare class Engine {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
45
|
+
private readonly caches;
|
|
46
|
+
private readonly usedIds;
|
|
47
|
+
private filePath;
|
|
48
|
+
private identifierCount;
|
|
49
|
+
private readonly options;
|
|
50
|
+
private sourceMapReferences;
|
|
51
|
+
constructor(options?: Options);
|
|
52
|
+
addStatic(selector: string, styles: StyleRule): Static;
|
|
53
|
+
addStyle(styles: StyleRule): ClassList;
|
|
54
|
+
addFontFace(fontFace: FontFaceRule | FontFaceRule[]): string;
|
|
55
|
+
addKeyframes(keyframes: CSSKeyframes): string;
|
|
56
|
+
addSourceMapReference({
|
|
57
|
+
filePath,
|
|
58
|
+
identifier,
|
|
59
|
+
classList,
|
|
60
|
+
line,
|
|
61
|
+
column,
|
|
62
|
+
index
|
|
63
|
+
}: {
|
|
64
|
+
index: number;
|
|
65
|
+
identifier: string;
|
|
66
|
+
classList: ClassList;
|
|
67
|
+
filePath: string;
|
|
68
|
+
line: number;
|
|
69
|
+
column: number;
|
|
70
|
+
}): string | false;
|
|
71
|
+
private clearSourceMapReferences;
|
|
72
|
+
clearCache(filePath: string): void;
|
|
73
|
+
generateIdentifier(value: unknown): string;
|
|
74
|
+
renderCssToString(options?: {
|
|
75
|
+
filePaths?: string[];
|
|
76
|
+
usedIds?: UsedIdCache;
|
|
77
|
+
opinionatedLayers?: boolean;
|
|
78
|
+
}): string;
|
|
79
|
+
serialize(): string;
|
|
80
|
+
deserialize(buffer: Buffer | string): Promise<void>;
|
|
81
|
+
setFilePath(filePath: string | undefined): void;
|
|
82
|
+
getUsedFilePaths(): string[];
|
|
83
|
+
getItems(caches: UsedIdCache): {
|
|
84
|
+
rule?: (StyleBlock & {
|
|
85
|
+
id: string | number;
|
|
86
|
+
})[];
|
|
87
|
+
static?: (StyleBlock & {
|
|
88
|
+
id: string | number;
|
|
89
|
+
})[];
|
|
90
|
+
keyframes?: (KeyframesBlock & {
|
|
91
|
+
id: string | number;
|
|
92
|
+
})[];
|
|
93
|
+
fontFace?: (FontFaceBlock & {
|
|
94
|
+
id: string | number;
|
|
95
|
+
})[];
|
|
96
|
+
identifiers?: (Identifier & {
|
|
97
|
+
id: string | number;
|
|
98
|
+
})[];
|
|
99
|
+
};
|
|
100
|
+
clearUsedIds(filePath: string): void;
|
|
101
|
+
private addUsedIds;
|
|
102
|
+
getCacheIds(filePaths?: string[]): UsedIdCache;
|
|
96
103
|
}
|
|
97
|
-
|
|
98
|
-
export { ClassList, Engine, Options, Static, UsedIdCache };
|
|
104
|
+
//#endregion
|
|
105
|
+
export { ClassList, Engine, Options, Static, UsedIdCache };
|
package/index.mjs
CHANGED
|
@@ -1,237 +1,187 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { AlphaIDGenerator } from
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
|
|
1
|
+
import "node:path";
|
|
2
|
+
import "node:url";
|
|
3
|
+
import.meta.url;
|
|
4
|
+
import { Cache } from "./cache.mjs";
|
|
5
|
+
import { isObject } from "./helpers/isObject.mjs";
|
|
6
|
+
import { splitStyleBlocks } from "./helpers/splitStyleBlocks.mjs";
|
|
7
|
+
import { AlphaIDGenerator } from "./identifiers/alphaIDGenerator.mjs";
|
|
8
|
+
import { IDGenerator } from "./identifiers/IDGenerator.mjs";
|
|
9
|
+
import { PropertyValueIDGenerator } from "./identifiers/propertyValueIDGenerator.mjs";
|
|
10
|
+
import { printFontFaces } from "./printers/printFontFaces.mjs";
|
|
11
|
+
import { printKeyFrames } from "./printers/printKeyFrames.mjs";
|
|
12
|
+
import { printSourceMap } from "./printers/printSourceMap.mjs";
|
|
13
|
+
import { printStyleBlocks } from "./printers/printStyleBlocks.mjs";
|
|
14
|
+
import { sortAtRules } from "./printers/sortAtRules.mjs";
|
|
15
|
+
import { processKeyframes } from "./processKeyframes.mjs";
|
|
16
|
+
import { processStyles } from "./processStyles.mjs";
|
|
17
|
+
import { ClassList } from "./wrappers/classList.mjs";
|
|
18
|
+
import { Static } from "./wrappers/static.mjs";
|
|
19
|
+
import path from "node:path";
|
|
20
|
+
import hash from "@emotion/hash";
|
|
21
|
+
//#region src/index.ts
|
|
19
22
|
const defaultOptions = {
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
enableSourceMaps: false,
|
|
24
|
+
enableDebugIdentifiers: false
|
|
22
25
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
setFilePath(filePath) {
|
|
185
|
-
this.filePath = filePath;
|
|
186
|
-
}
|
|
187
|
-
getUsedFilePaths() {
|
|
188
|
-
return Object.keys(this.usedIds);
|
|
189
|
-
}
|
|
190
|
-
getItems(caches) {
|
|
191
|
-
return Object.keys(caches).reduce((acc, key)=>({
|
|
192
|
-
...acc,
|
|
193
|
-
[key]: this.caches[key].items(caches[key])
|
|
194
|
-
}), {});
|
|
195
|
-
}
|
|
196
|
-
clearUsedIds(filePath) {
|
|
197
|
-
if (filePath === undefined) {
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
this.usedIds[filePath] = {};
|
|
201
|
-
}
|
|
202
|
-
addUsedIds(cacheType, identifiers) {
|
|
203
|
-
const { filePath } = this;
|
|
204
|
-
if (filePath === undefined) {
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
if (this.usedIds[filePath] === undefined) {
|
|
208
|
-
this.usedIds[filePath] = {};
|
|
209
|
-
}
|
|
210
|
-
if (this.usedIds[filePath][cacheType] === undefined) {
|
|
211
|
-
this.usedIds[filePath][cacheType] = [];
|
|
212
|
-
}
|
|
213
|
-
this.usedIds[filePath][cacheType] = [
|
|
214
|
-
...new Set([
|
|
215
|
-
...this.usedIds[filePath][cacheType],
|
|
216
|
-
...identifiers
|
|
217
|
-
])
|
|
218
|
-
];
|
|
219
|
-
}
|
|
220
|
-
getCacheIds(filePaths = []) {
|
|
221
|
-
return filePaths.reduce((acc, filePath)=>({
|
|
222
|
-
...acc,
|
|
223
|
-
...Object.keys(this.usedIds[filePath] || []).reduce((cache, key)=>({
|
|
224
|
-
...cache,
|
|
225
|
-
[key]: [
|
|
226
|
-
...acc[key] || [],
|
|
227
|
-
...this.usedIds[filePath][key] || []
|
|
228
|
-
]
|
|
229
|
-
}), {})
|
|
230
|
-
}), Object.keys(this.caches).reduce((acc, key)=>({
|
|
231
|
-
...acc,
|
|
232
|
-
[key]: []
|
|
233
|
-
}), {}));
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
26
|
+
var Engine = class {
|
|
27
|
+
caches = {
|
|
28
|
+
rule: new Cache(new PropertyValueIDGenerator()),
|
|
29
|
+
static: new Cache(new IDGenerator()),
|
|
30
|
+
keyframes: new Cache(new AlphaIDGenerator()),
|
|
31
|
+
fontFace: new Cache(new AlphaIDGenerator()),
|
|
32
|
+
identifiers: new Cache(new AlphaIDGenerator())
|
|
33
|
+
};
|
|
34
|
+
usedIds = {};
|
|
35
|
+
filePath;
|
|
36
|
+
identifierCount = 0;
|
|
37
|
+
options = {};
|
|
38
|
+
sourceMapReferences = {};
|
|
39
|
+
constructor(options = {}) {
|
|
40
|
+
this.options = {
|
|
41
|
+
...defaultOptions,
|
|
42
|
+
...Object.keys(options).reduce((acc, key) => {
|
|
43
|
+
if (options[key] !== void 0) acc[key] = options[key];
|
|
44
|
+
return acc;
|
|
45
|
+
}, {})
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
addStatic(selector, styles) {
|
|
49
|
+
this.addUsedIds("static", processStyles({
|
|
50
|
+
type: "static",
|
|
51
|
+
cache: this.caches.static
|
|
52
|
+
})({
|
|
53
|
+
styles,
|
|
54
|
+
selector
|
|
55
|
+
}).map((style) => style.id));
|
|
56
|
+
return new Static();
|
|
57
|
+
}
|
|
58
|
+
addStyle(styles) {
|
|
59
|
+
const ids = processStyles({
|
|
60
|
+
type: "rule",
|
|
61
|
+
cache: this.caches.rule
|
|
62
|
+
})({ styles }).map((rule) => rule.id);
|
|
63
|
+
this.addUsedIds("rule", ids);
|
|
64
|
+
return new ClassList(ids.join(" "));
|
|
65
|
+
}
|
|
66
|
+
addFontFace(fontFace) {
|
|
67
|
+
const { id } = this.caches.fontFace.getOrStore({
|
|
68
|
+
type: "fontFace",
|
|
69
|
+
rule: Array.isArray(fontFace) ? fontFace : [fontFace]
|
|
70
|
+
});
|
|
71
|
+
this.addUsedIds("fontFace", [id]);
|
|
72
|
+
return id;
|
|
73
|
+
}
|
|
74
|
+
addKeyframes(keyframes) {
|
|
75
|
+
const { id } = this.caches.keyframes.getOrStore({
|
|
76
|
+
type: "keyframes",
|
|
77
|
+
rule: processKeyframes(keyframes)
|
|
78
|
+
});
|
|
79
|
+
this.addUsedIds("keyframes", [id]);
|
|
80
|
+
return id;
|
|
81
|
+
}
|
|
82
|
+
addSourceMapReference({ filePath, identifier, classList, line, column, index }) {
|
|
83
|
+
if (!this.options.enableSourceMaps) return false;
|
|
84
|
+
const { name } = path.parse(filePath);
|
|
85
|
+
const extraClass = this.options.enableDebugIdentifiers ? `${name}_${identifier}` : "";
|
|
86
|
+
const selector = "." + classList.toString().split(" ").concat(extraClass).filter(Boolean).join(".");
|
|
87
|
+
const newFilePath = path.relative(this.options.context || process.cwd(), filePath);
|
|
88
|
+
if (index === 0 || !this.sourceMapReferences[newFilePath]) this.sourceMapReferences[newFilePath] = [];
|
|
89
|
+
this.sourceMapReferences[newFilePath][index] = {
|
|
90
|
+
selector,
|
|
91
|
+
line,
|
|
92
|
+
column
|
|
93
|
+
};
|
|
94
|
+
return extraClass;
|
|
95
|
+
}
|
|
96
|
+
clearSourceMapReferences(filePath) {
|
|
97
|
+
const newFilePath = path.relative(this.options.context || process.cwd(), filePath);
|
|
98
|
+
this.sourceMapReferences[newFilePath] = [];
|
|
99
|
+
}
|
|
100
|
+
clearCache(filePath) {
|
|
101
|
+
this.clearUsedIds(filePath);
|
|
102
|
+
this.clearSourceMapReferences(filePath);
|
|
103
|
+
}
|
|
104
|
+
generateIdentifier(value) {
|
|
105
|
+
if (typeof value === "undefined") {
|
|
106
|
+
let identifier = hash((this.identifierCount++).toString(36));
|
|
107
|
+
if (identifier.match(/^\d/)) identifier = `_${identifier}`;
|
|
108
|
+
return identifier;
|
|
109
|
+
}
|
|
110
|
+
const newValue = JSON.stringify(value);
|
|
111
|
+
const { id } = this.caches.identifiers.getOrStore({ value: newValue });
|
|
112
|
+
this.addUsedIds("identifiers", [id]);
|
|
113
|
+
return `_${id}`;
|
|
114
|
+
}
|
|
115
|
+
renderCssToString(options) {
|
|
116
|
+
const { filePaths, usedIds, opinionatedLayers = false } = options || {};
|
|
117
|
+
const { keyframes: keyframesCache, fontFace: fontFaceCache, static: staticCache, rule: ruleCache } = usedIds ?? this.getCacheIds(filePaths ?? Object.keys(this.usedIds));
|
|
118
|
+
const { atRules, lowPrioRules, rules } = splitStyleBlocks(this.caches.rule.items(ruleCache));
|
|
119
|
+
const keyFrameCss = printKeyFrames(this.caches.keyframes.items(keyframesCache));
|
|
120
|
+
const fontFaceCss = printFontFaces(this.caches.fontFace.items(fontFaceCache));
|
|
121
|
+
const staticCss = printStyleBlocks(this.caches.static.items(staticCache));
|
|
122
|
+
const atRulesCss = printStyleBlocks(sortAtRules(atRules));
|
|
123
|
+
const lowPrioRulesCss = printStyleBlocks(lowPrioRules);
|
|
124
|
+
const rulesCss = printStyleBlocks(rules);
|
|
125
|
+
if (opinionatedLayers) {
|
|
126
|
+
const result = `${keyFrameCss}${fontFaceCss}` + (staticCss.length > 0 ? `@layer s{${staticCss}}` : "") + (lowPrioRulesCss.length > 0 ? `@layer lpr{${lowPrioRulesCss}}` : "") + (rulesCss.length > 0 ? `@layer r{${rulesCss}}` : "") + (atRulesCss.length > 0 ? `@layer at{${atRulesCss}}` : "");
|
|
127
|
+
if (result.length > 0) return `@layer s,lpr,r,at;${result}`;
|
|
128
|
+
return "";
|
|
129
|
+
}
|
|
130
|
+
const content = keyFrameCss + fontFaceCss + staticCss + lowPrioRulesCss + rulesCss + atRulesCss;
|
|
131
|
+
if (this.options.enableSourceMaps) return printSourceMap(this.sourceMapReferences, content);
|
|
132
|
+
return content;
|
|
133
|
+
}
|
|
134
|
+
serialize() {
|
|
135
|
+
const { caches, usedIds, identifierCount, sourceMapReferences: sourceMapReferencesData } = this;
|
|
136
|
+
const sourceMapReferences = this.options.enableSourceMaps ? sourceMapReferencesData : void 0;
|
|
137
|
+
return JSON.stringify({
|
|
138
|
+
caches,
|
|
139
|
+
usedIds,
|
|
140
|
+
identifierCount,
|
|
141
|
+
sourceMapReferences
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
async deserialize(buffer) {
|
|
145
|
+
const data = JSON.parse(buffer.toString());
|
|
146
|
+
function assign(target, source) {
|
|
147
|
+
for (const key in source) if (isObject(target[key]) && isObject(source[key])) assign(target[key], source[key]);
|
|
148
|
+
else target[key] = source[key];
|
|
149
|
+
return target;
|
|
150
|
+
}
|
|
151
|
+
assign(this, data);
|
|
152
|
+
}
|
|
153
|
+
setFilePath(filePath) {
|
|
154
|
+
this.filePath = filePath;
|
|
155
|
+
}
|
|
156
|
+
getUsedFilePaths() {
|
|
157
|
+
return Object.keys(this.usedIds);
|
|
158
|
+
}
|
|
159
|
+
getItems(caches) {
|
|
160
|
+
const result = {};
|
|
161
|
+
for (const key of Object.keys(caches)) result[key] = this.caches[key].items(caches[key]);
|
|
162
|
+
return result;
|
|
163
|
+
}
|
|
164
|
+
clearUsedIds(filePath) {
|
|
165
|
+
if (filePath === void 0) return;
|
|
166
|
+
this.usedIds[filePath] = {};
|
|
167
|
+
}
|
|
168
|
+
addUsedIds(cacheType, identifiers) {
|
|
169
|
+
const { filePath } = this;
|
|
170
|
+
if (filePath === void 0) return;
|
|
171
|
+
if (this.usedIds[filePath] === void 0) this.usedIds[filePath] = {};
|
|
172
|
+
if (this.usedIds[filePath][cacheType] === void 0) this.usedIds[filePath][cacheType] = [];
|
|
173
|
+
this.usedIds[filePath][cacheType] = [.../* @__PURE__ */ new Set([...this.usedIds[filePath][cacheType], ...identifiers])];
|
|
174
|
+
}
|
|
175
|
+
getCacheIds(filePaths = []) {
|
|
176
|
+
const result = {};
|
|
177
|
+
for (const key of Object.keys(this.caches)) result[key] = [];
|
|
178
|
+
for (const filePath of filePaths) {
|
|
179
|
+
const used = this.usedIds[filePath];
|
|
180
|
+
if (!used) continue;
|
|
181
|
+
for (const key of Object.keys(used)) result[key] = [...result[key] || [], ...used[key] || []];
|
|
182
|
+
}
|
|
183
|
+
return result;
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
//#endregion
|
|
237
187
|
export { ClassList, Engine, Static };
|
package/package.json
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_helpers_declarationsToBlock = require("../helpers/declarationsToBlock.cjs");
|
|
3
|
+
//#region src/printers/printFontFaces.ts
|
|
5
4
|
function printFontFaces(blocks) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
fontFaces += `@font-face{font-family:${block.id};${declarationsToBlock.declarationsToBlock(rule)}}`;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
return fontFaces;
|
|
5
|
+
let fontFaces = "";
|
|
6
|
+
for (const block of blocks) for (const rule of block.rule) fontFaces += `@font-face{font-family:${block.id};${require_helpers_declarationsToBlock.declarationsToBlock(rule)}}`;
|
|
7
|
+
return fontFaces;
|
|
13
8
|
}
|
|
14
|
-
|
|
9
|
+
//#endregion
|
|
15
10
|
exports.printFontFaces = printFontFaces;
|