@pikacss/core 0.0.30 → 0.0.32
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/index.cjs +851 -983
- package/dist/index.d.cts +429 -427
- package/dist/index.d.mts +429 -427
- package/dist/index.mjs +851 -982
- package/package.json +4 -5
- package/dist/index.d.ts +0 -539
package/dist/index.mjs
CHANGED
|
@@ -1,1087 +1,956 @@
|
|
|
1
|
+
//#region src/internal/constants.ts
|
|
1
2
|
const ATOMIC_STYLE_ID_PLACEHOLDER = "%";
|
|
2
3
|
const ATOMIC_STYLE_ID_PLACEHOLDER_RE_GLOBAL = /%/g;
|
|
3
4
|
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region src/internal/utils.ts
|
|
4
7
|
let _warn = (...args) => {
|
|
5
|
-
|
|
8
|
+
console.warn("[@pikacss/core]", ...args);
|
|
6
9
|
};
|
|
7
10
|
function setWarnFn(fn) {
|
|
8
|
-
|
|
11
|
+
_warn = fn;
|
|
9
12
|
}
|
|
10
13
|
function warn(...args) {
|
|
11
|
-
|
|
14
|
+
_warn(...args);
|
|
12
15
|
}
|
|
13
16
|
const chars = [..."abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"];
|
|
14
17
|
const numOfChars = chars.length;
|
|
15
18
|
function numberToChars(num) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return result;
|
|
19
|
+
if (num < numOfChars) return chars[num];
|
|
20
|
+
let result = "";
|
|
21
|
+
let n = num;
|
|
22
|
+
while (n >= 0) {
|
|
23
|
+
result += chars[n % numOfChars];
|
|
24
|
+
n = Math.floor(n / numOfChars) - 1;
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
25
27
|
}
|
|
26
28
|
const UPPER_CASE = /[A-Z]/g;
|
|
27
29
|
function toKebab(str) {
|
|
28
|
-
|
|
30
|
+
return str.replace(UPPER_CASE, (c) => `-${c.toLowerCase()}`);
|
|
29
31
|
}
|
|
30
32
|
function isNotNullish(value) {
|
|
31
|
-
|
|
33
|
+
return value != null;
|
|
32
34
|
}
|
|
33
35
|
function isNotString(value) {
|
|
34
|
-
|
|
36
|
+
return typeof value !== "string";
|
|
35
37
|
}
|
|
36
38
|
function isPropertyValue(v) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (typeof v === "string" || typeof v === "number")
|
|
42
|
-
return true;
|
|
43
|
-
return false;
|
|
39
|
+
if (Array.isArray(v)) return v.length === 2 && isPropertyValue(v[0]) && Array.isArray(v[1]) && v[1].every(isPropertyValue);
|
|
40
|
+
if (v == null) return true;
|
|
41
|
+
if (typeof v === "string" || typeof v === "number") return true;
|
|
42
|
+
return false;
|
|
44
43
|
}
|
|
45
44
|
function serialize(value) {
|
|
46
|
-
|
|
45
|
+
return JSON.stringify(value);
|
|
47
46
|
}
|
|
48
47
|
function addToSet(set, ...values) {
|
|
49
|
-
|
|
48
|
+
values.forEach((value) => set.add(value));
|
|
50
49
|
}
|
|
51
|
-
function appendAutocompleteSelectors(config, ...selectors) {
|
|
52
|
-
|
|
50
|
+
function appendAutocompleteSelectors(config, ...selectors$1) {
|
|
51
|
+
addToSet(config.autocomplete.selectors, ...selectors$1);
|
|
53
52
|
}
|
|
54
53
|
function appendAutocompleteStyleItemStrings(config, ...styleItemStrings) {
|
|
55
|
-
|
|
54
|
+
addToSet(config.autocomplete.styleItemStrings, ...styleItemStrings);
|
|
56
55
|
}
|
|
57
56
|
function appendAutocompleteExtraProperties(config, ...properties) {
|
|
58
|
-
|
|
57
|
+
addToSet(config.autocomplete.extraProperties, ...properties);
|
|
59
58
|
}
|
|
60
59
|
function appendAutocompleteExtraCssProperties(config, ...properties) {
|
|
61
|
-
|
|
60
|
+
addToSet(config.autocomplete.extraCssProperties, ...properties);
|
|
62
61
|
}
|
|
63
62
|
function appendAutocompletePropertyValues(config, property, ...tsTypes) {
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
const current = config.autocomplete.properties.get(property) || [];
|
|
64
|
+
config.autocomplete.properties.set(property, [...current, ...tsTypes]);
|
|
66
65
|
}
|
|
67
66
|
function appendAutocompleteCssPropertyValues(config, property, ...values) {
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
const current = config.autocomplete.cssProperties.get(property) || [];
|
|
68
|
+
config.autocomplete.cssProperties.set(property, [...current, ...values]);
|
|
70
69
|
}
|
|
71
70
|
function renderCSSStyleBlocks(blocks, isFormatted, depth = 0) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return lines.join(lineEnd);
|
|
71
|
+
const blockIndent = isFormatted ? " ".repeat(depth) : "";
|
|
72
|
+
const blockBodyIndent = isFormatted ? " ".repeat(depth + 1) : "";
|
|
73
|
+
const selectorEnd = isFormatted ? " " : "";
|
|
74
|
+
const propertySpace = isFormatted ? " " : "";
|
|
75
|
+
const lineEnd = isFormatted ? "\n" : "";
|
|
76
|
+
const lines = [];
|
|
77
|
+
blocks.forEach(({ properties, children }, selector) => {
|
|
78
|
+
if (properties.length === 0 && (children == null || children.size === 0)) return;
|
|
79
|
+
lines.push(...[
|
|
80
|
+
`${blockIndent}${selector}${selectorEnd}{`,
|
|
81
|
+
...properties.map(({ property, value }) => `${blockBodyIndent}${property}:${propertySpace}${value};`),
|
|
82
|
+
...children != null && children.size > 0 ? [renderCSSStyleBlocks(children, isFormatted, depth + 1)] : [],
|
|
83
|
+
`${blockIndent}}`
|
|
84
|
+
]);
|
|
85
|
+
});
|
|
86
|
+
return lines.join(lineEnd);
|
|
89
87
|
}
|
|
90
88
|
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/internal/extractor.ts
|
|
91
91
|
function replaceBySplitAndJoin(str, split, mapFn, join) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return splitted.join(join);
|
|
92
|
+
let splitted = str.split(split);
|
|
93
|
+
if (mapFn != null) splitted = splitted.map(mapFn);
|
|
94
|
+
return splitted.join(join);
|
|
96
95
|
}
|
|
97
96
|
const RE_SPLIT = /\s*,\s*/g;
|
|
98
97
|
const DEFAULT_SELECTOR_PLACEHOLDER_RE_GLOBAL = /\$/g;
|
|
99
98
|
const ATTRIBUTE_SUFFIX_MATCH = "$=";
|
|
100
99
|
const ATTRIBUTE_SUFFIX_MATCH_RE_GLOBAL = /\$=/g;
|
|
101
|
-
function normalizeSelectors({
|
|
102
|
-
|
|
103
|
-
defaultSelector
|
|
104
|
-
}) {
|
|
105
|
-
const normalized = selectors.map(
|
|
106
|
-
(s) => replaceBySplitAndJoin(
|
|
107
|
-
s.replace(RE_SPLIT, ","),
|
|
108
|
-
ATOMIC_STYLE_ID_PLACEHOLDER_RE_GLOBAL,
|
|
109
|
-
(a) => replaceBySplitAndJoin(
|
|
110
|
-
a,
|
|
111
|
-
ATTRIBUTE_SUFFIX_MATCH_RE_GLOBAL,
|
|
112
|
-
(b) => replaceBySplitAndJoin(
|
|
113
|
-
b,
|
|
114
|
-
DEFAULT_SELECTOR_PLACEHOLDER_RE_GLOBAL,
|
|
115
|
-
null,
|
|
116
|
-
defaultSelector
|
|
117
|
-
),
|
|
118
|
-
ATTRIBUTE_SUFFIX_MATCH
|
|
119
|
-
),
|
|
120
|
-
ATOMIC_STYLE_ID_PLACEHOLDER
|
|
121
|
-
)
|
|
122
|
-
);
|
|
123
|
-
return normalized;
|
|
100
|
+
function normalizeSelectors({ selectors: selectors$1, defaultSelector }) {
|
|
101
|
+
return selectors$1.map((s) => replaceBySplitAndJoin(s.replace(RE_SPLIT, ","), ATOMIC_STYLE_ID_PLACEHOLDER_RE_GLOBAL, (a) => replaceBySplitAndJoin(a, ATTRIBUTE_SUFFIX_MATCH_RE_GLOBAL, (b) => replaceBySplitAndJoin(b, DEFAULT_SELECTOR_PLACEHOLDER_RE_GLOBAL, null, defaultSelector), ATTRIBUTE_SUFFIX_MATCH), ATOMIC_STYLE_ID_PLACEHOLDER));
|
|
124
102
|
}
|
|
125
103
|
function normalizeValue(value) {
|
|
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
|
-
transformStyleDefinitions,
|
|
164
|
-
defaultSelector
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
} else {
|
|
168
|
-
await extract({
|
|
169
|
-
styleDefinition: v,
|
|
170
|
-
levels: [...levels, k],
|
|
171
|
-
result,
|
|
172
|
-
transformSelectors,
|
|
173
|
-
transformStyleItems,
|
|
174
|
-
transformStyleDefinitions,
|
|
175
|
-
defaultSelector
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return result;
|
|
104
|
+
if (value == null) return value;
|
|
105
|
+
return [...new Set([value].flat(2).map((v) => String(v).trim()))];
|
|
106
|
+
}
|
|
107
|
+
async function extract({ styleDefinition, levels = [], result = [], defaultSelector, transformSelectors, transformStyleItems, transformStyleDefinitions }) {
|
|
108
|
+
for (const definition of await transformStyleDefinitions([styleDefinition])) for (const [k, v] of Object.entries(definition)) if (isPropertyValue(v)) {
|
|
109
|
+
const selector = normalizeSelectors({
|
|
110
|
+
selectors: await transformSelectors(levels),
|
|
111
|
+
defaultSelector
|
|
112
|
+
});
|
|
113
|
+
if (selector.length === 0 || selector.every((s) => s.includes(ATOMIC_STYLE_ID_PLACEHOLDER) === false)) selector.push(defaultSelector);
|
|
114
|
+
result.push({
|
|
115
|
+
selector,
|
|
116
|
+
property: toKebab(k),
|
|
117
|
+
value: normalizeValue(v)
|
|
118
|
+
});
|
|
119
|
+
} else if (Array.isArray(v)) for (const styleItem of await transformStyleItems(v)) {
|
|
120
|
+
if (typeof styleItem === "string") continue;
|
|
121
|
+
await extract({
|
|
122
|
+
styleDefinition: styleItem,
|
|
123
|
+
levels: [...levels, k],
|
|
124
|
+
result,
|
|
125
|
+
transformSelectors,
|
|
126
|
+
transformStyleItems,
|
|
127
|
+
transformStyleDefinitions,
|
|
128
|
+
defaultSelector
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
else await extract({
|
|
132
|
+
styleDefinition: v,
|
|
133
|
+
levels: [...levels, k],
|
|
134
|
+
result,
|
|
135
|
+
transformSelectors,
|
|
136
|
+
transformStyleItems,
|
|
137
|
+
transformStyleDefinitions,
|
|
138
|
+
defaultSelector
|
|
139
|
+
});
|
|
140
|
+
return result;
|
|
181
141
|
}
|
|
182
142
|
function createExtractFn(options) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
143
|
+
return (styleDefinition) => extract({
|
|
144
|
+
styleDefinition,
|
|
145
|
+
...options
|
|
146
|
+
});
|
|
187
147
|
}
|
|
188
148
|
|
|
149
|
+
//#endregion
|
|
150
|
+
//#region src/internal/plugin.ts
|
|
189
151
|
async function execAsyncHook(plugins, hook, payload) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
return payload;
|
|
152
|
+
for (const plugin of plugins) {
|
|
153
|
+
if (plugin[hook] == null) continue;
|
|
154
|
+
try {
|
|
155
|
+
const newPayload = await plugin[hook](payload);
|
|
156
|
+
if (newPayload != null) payload = newPayload;
|
|
157
|
+
} catch (error) {
|
|
158
|
+
warn(`Plugin "${plugin.name}" failed to execute hook "${hook}": ${error.message}`, error);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return payload;
|
|
202
162
|
}
|
|
203
163
|
function execSyncHook(plugins, hook, payload) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
return payload;
|
|
164
|
+
for (const plugin of plugins) {
|
|
165
|
+
if (plugin[hook] == null) continue;
|
|
166
|
+
try {
|
|
167
|
+
const newPayload = plugin[hook](payload);
|
|
168
|
+
if (newPayload != null) payload = newPayload;
|
|
169
|
+
} catch (error) {
|
|
170
|
+
warn(`Plugin "${plugin.name}" failed to execute hook "${hook}": ${error.message}`, error);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return payload;
|
|
216
174
|
}
|
|
217
175
|
const hooks = {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
176
|
+
configureRawConfig: (plugins, config) => execAsyncHook(plugins, "configureRawConfig", config),
|
|
177
|
+
rawConfigConfigured: (plugins, config) => execSyncHook(plugins, "rawConfigConfigured", config),
|
|
178
|
+
configureResolvedConfig: (plugins, resolvedConfig) => execAsyncHook(plugins, "configureResolvedConfig", resolvedConfig),
|
|
179
|
+
configureEngine: (plugins, engine) => execAsyncHook(plugins, "configureEngine", engine),
|
|
180
|
+
transformSelectors: (plugins, selectors$1) => execAsyncHook(plugins, "transformSelectors", selectors$1),
|
|
181
|
+
transformStyleItems: (plugins, styleItems) => execAsyncHook(plugins, "transformStyleItems", styleItems),
|
|
182
|
+
transformStyleDefinitions: (plugins, styleDefinitions) => execAsyncHook(plugins, "transformStyleDefinitions", styleDefinitions),
|
|
183
|
+
preflightUpdated: (plugins) => execSyncHook(plugins, "preflightUpdated", void 0),
|
|
184
|
+
atomicStyleAdded: (plugins) => execSyncHook(plugins, "atomicStyleAdded", void 0),
|
|
185
|
+
autocompleteConfigUpdated: (plugins) => execSyncHook(plugins, "autocompleteConfigUpdated", void 0)
|
|
228
186
|
};
|
|
229
|
-
const orderMap =
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
187
|
+
const orderMap = new Map([
|
|
188
|
+
[void 0, 1],
|
|
189
|
+
["pre", 0],
|
|
190
|
+
["post", 2]
|
|
233
191
|
]);
|
|
234
192
|
function resolvePlugins(plugins) {
|
|
235
|
-
|
|
193
|
+
return plugins.sort((a, b) => orderMap.get(a.order) - orderMap.get(b.order));
|
|
236
194
|
}
|
|
195
|
+
/* c8 ignore start */
|
|
237
196
|
function defineEnginePlugin(plugin) {
|
|
238
|
-
|
|
197
|
+
return plugin;
|
|
239
198
|
}
|
|
199
|
+
/* c8 ignore end */
|
|
240
200
|
|
|
201
|
+
//#endregion
|
|
202
|
+
//#region src/internal/plugins/important.ts
|
|
241
203
|
function modifyPropertyValue(value) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
return [`${value[0]} !important`, value[1].map((i) => `${i} !important`)];
|
|
246
|
-
}
|
|
247
|
-
return `${value} !important`;
|
|
204
|
+
if (value == null) return null;
|
|
205
|
+
if (Array.isArray(value)) return [`${value[0]} !important`, value[1].map((i) => `${i} !important`)];
|
|
206
|
+
return `${value} !important`;
|
|
248
207
|
}
|
|
249
208
|
function important() {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
return [k, v];
|
|
273
|
-
})
|
|
274
|
-
);
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
});
|
|
209
|
+
let defaultValue;
|
|
210
|
+
return defineEnginePlugin({
|
|
211
|
+
name: "core:important",
|
|
212
|
+
rawConfigConfigured(config) {
|
|
213
|
+
defaultValue = config.important?.default ?? false;
|
|
214
|
+
},
|
|
215
|
+
configureEngine(engine) {
|
|
216
|
+
engine.appendAutocompleteExtraProperties("__important");
|
|
217
|
+
engine.appendAutocompletePropertyValues("__important", "boolean");
|
|
218
|
+
},
|
|
219
|
+
transformStyleDefinitions(styleDefinitions) {
|
|
220
|
+
return styleDefinitions.map((styleDefinition) => {
|
|
221
|
+
const { __important, ...rest } = styleDefinition;
|
|
222
|
+
const value = __important;
|
|
223
|
+
if ((value == null ? defaultValue : value) === false) return rest;
|
|
224
|
+
return Object.fromEntries(Object.entries(rest).map(([k, v]) => {
|
|
225
|
+
if (isPropertyValue(v)) return [k, modifyPropertyValue(v)];
|
|
226
|
+
return [k, v];
|
|
227
|
+
}));
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
});
|
|
278
231
|
}
|
|
279
232
|
|
|
233
|
+
//#endregion
|
|
234
|
+
//#region src/internal/plugins/keyframes.ts
|
|
280
235
|
function keyframes() {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
236
|
+
let resolveKeyframesConfig;
|
|
237
|
+
let configList;
|
|
238
|
+
return defineEnginePlugin({
|
|
239
|
+
name: "core:keyframes",
|
|
240
|
+
rawConfigConfigured(config) {
|
|
241
|
+
resolveKeyframesConfig = createResolveConfigFn({ pruneUnused: config.keyframes?.pruneUnused });
|
|
242
|
+
configList = config.keyframes?.keyframes ?? [];
|
|
243
|
+
},
|
|
244
|
+
configureEngine(engine) {
|
|
245
|
+
engine.keyframes = {
|
|
246
|
+
store: /* @__PURE__ */ new Map(),
|
|
247
|
+
add: (...list) => {
|
|
248
|
+
list.forEach((config) => {
|
|
249
|
+
const resolved = resolveKeyframesConfig(config);
|
|
250
|
+
const { name, frames, autocomplete: autocompleteAnimation } = resolved;
|
|
251
|
+
if (frames != null) engine.keyframes.store.set(name, resolved);
|
|
252
|
+
engine.appendAutocompleteCssPropertyValues("animationName", name);
|
|
253
|
+
engine.appendAutocompleteCssPropertyValues("animation", `${name} `);
|
|
254
|
+
if (autocompleteAnimation != null) engine.appendAutocompleteCssPropertyValues("animation", ...autocompleteAnimation);
|
|
255
|
+
});
|
|
256
|
+
engine.notifyPreflightUpdated();
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
engine.keyframes.add(...configList);
|
|
260
|
+
engine.addPreflight((engine$1) => {
|
|
261
|
+
const maybeUsedName = /* @__PURE__ */ new Set();
|
|
262
|
+
engine$1.store.atomicStyles.forEach(({ content: { property, value } }) => {
|
|
263
|
+
if (property === "animationName") {
|
|
264
|
+
value.forEach((name) => maybeUsedName.add(name));
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
if (property === "animation") value.forEach((value$1) => {
|
|
268
|
+
value$1.split(",").map((v) => v.trim()).forEach((animation) => {
|
|
269
|
+
addToSet(maybeUsedName, ...animation.split(" "));
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
const maybeUsedKeyframes = Array.from(engine$1.keyframes.store.values()).filter(({ name, frames, pruneUnused }) => (pruneUnused === false || maybeUsedName.has(name)) && frames != null);
|
|
274
|
+
const preflightDefinition = {};
|
|
275
|
+
maybeUsedKeyframes.forEach(({ name, frames }) => {
|
|
276
|
+
preflightDefinition[`@keyframes ${name}`] = Object.fromEntries(Object.entries(frames).map(([frame, properties]) => [frame, properties]));
|
|
277
|
+
});
|
|
278
|
+
return preflightDefinition;
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
function createResolveConfigFn({ pruneUnused: defaultPruneUnused = true } = {}) {
|
|
284
|
+
return function resolveKeyframesConfig(config) {
|
|
285
|
+
if (typeof config === "string") return {
|
|
286
|
+
name: config,
|
|
287
|
+
frames: null,
|
|
288
|
+
autocomplete: [],
|
|
289
|
+
pruneUnused: defaultPruneUnused
|
|
290
|
+
};
|
|
291
|
+
if (Array.isArray(config)) {
|
|
292
|
+
const [name$1, frames$1, autocomplete$1 = [], pruneUnused$1 = defaultPruneUnused] = config;
|
|
293
|
+
return {
|
|
294
|
+
name: name$1,
|
|
295
|
+
frames: frames$1,
|
|
296
|
+
autocomplete: autocomplete$1,
|
|
297
|
+
pruneUnused: pruneUnused$1
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
const { name, frames, autocomplete = [], pruneUnused = defaultPruneUnused } = config;
|
|
301
|
+
return {
|
|
302
|
+
name,
|
|
303
|
+
frames,
|
|
304
|
+
autocomplete,
|
|
305
|
+
pruneUnused
|
|
306
|
+
};
|
|
307
|
+
};
|
|
353
308
|
}
|
|
354
309
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
}
|
|
310
|
+
//#endregion
|
|
311
|
+
//#region src/internal/resolver.ts
|
|
312
|
+
var AbstractResolver = class {
|
|
313
|
+
constructor() {
|
|
314
|
+
this._resolvedResultsMap = /* @__PURE__ */ new Map();
|
|
315
|
+
this.staticRulesMap = /* @__PURE__ */ new Map();
|
|
316
|
+
this.dynamicRulesMap = /* @__PURE__ */ new Map();
|
|
317
|
+
this.onResolved = () => {};
|
|
318
|
+
}
|
|
319
|
+
get staticRules() {
|
|
320
|
+
return [...this.staticRulesMap.values()];
|
|
321
|
+
}
|
|
322
|
+
get dynamicRules() {
|
|
323
|
+
return [...this.dynamicRulesMap.values()];
|
|
324
|
+
}
|
|
325
|
+
addStaticRule(rule) {
|
|
326
|
+
this.staticRulesMap.set(rule.key, rule);
|
|
327
|
+
return this;
|
|
328
|
+
}
|
|
329
|
+
removeStaticRule(key) {
|
|
330
|
+
const rule = this.staticRulesMap.get(key);
|
|
331
|
+
if (rule == null) return this;
|
|
332
|
+
this.staticRulesMap.delete(key);
|
|
333
|
+
this._resolvedResultsMap.delete(rule.string);
|
|
334
|
+
return this;
|
|
335
|
+
}
|
|
336
|
+
addDynamicRule(rule) {
|
|
337
|
+
this.dynamicRulesMap.set(rule.key, rule);
|
|
338
|
+
return this;
|
|
339
|
+
}
|
|
340
|
+
removeDynamicRule(key) {
|
|
341
|
+
const rule = this.dynamicRulesMap.get(key);
|
|
342
|
+
if (rule == null) return this;
|
|
343
|
+
const matchedResolvedStringList = Array.from(this._resolvedResultsMap.keys()).filter((string) => rule.stringPattern.test(string));
|
|
344
|
+
this.dynamicRulesMap.delete(key);
|
|
345
|
+
matchedResolvedStringList.forEach((string) => this._resolvedResultsMap.delete(string));
|
|
346
|
+
return this;
|
|
347
|
+
}
|
|
348
|
+
async _resolve(string) {
|
|
349
|
+
const existedResult = this._resolvedResultsMap.get(string);
|
|
350
|
+
if (existedResult != null) return existedResult;
|
|
351
|
+
const staticRule = Array.from(this.staticRulesMap.values()).find((rule) => rule.string === string);
|
|
352
|
+
if (staticRule != null) {
|
|
353
|
+
const resolvedResult = { value: staticRule.resolved };
|
|
354
|
+
this._resolvedResultsMap.set(string, resolvedResult);
|
|
355
|
+
this.onResolved(string, "static", resolvedResult);
|
|
356
|
+
return resolvedResult;
|
|
357
|
+
}
|
|
358
|
+
let dynamicRule;
|
|
359
|
+
let matched;
|
|
360
|
+
for (const rule of this.dynamicRulesMap.values()) {
|
|
361
|
+
matched = string.match(rule.stringPattern);
|
|
362
|
+
if (matched != null) {
|
|
363
|
+
dynamicRule = rule;
|
|
364
|
+
break;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
if (dynamicRule != null && matched != null) {
|
|
368
|
+
const resolvedResult = { value: await dynamicRule.createResolved(matched) };
|
|
369
|
+
this._resolvedResultsMap.set(string, resolvedResult);
|
|
370
|
+
this.onResolved(string, "dynamic", resolvedResult);
|
|
371
|
+
return resolvedResult;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
_setResolvedResult(string, resolved) {
|
|
375
|
+
const resolvedResult = this._resolvedResultsMap.get(string);
|
|
376
|
+
if (resolvedResult) {
|
|
377
|
+
resolvedResult.value = resolved;
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
this._resolvedResultsMap.set(string, { value: resolved });
|
|
381
|
+
}
|
|
382
|
+
};
|
|
429
383
|
|
|
384
|
+
//#endregion
|
|
385
|
+
//#region src/internal/plugins/selectors.ts
|
|
430
386
|
function selectors() {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
});
|
|
481
|
-
if (resolved == null)
|
|
482
|
-
return [selector];
|
|
483
|
-
const result = [];
|
|
484
|
-
for (const s of resolved.value)
|
|
485
|
-
result.push(...await this.resolve(s));
|
|
486
|
-
this._setResolvedResult(selector, result);
|
|
487
|
-
return result;
|
|
488
|
-
}
|
|
489
|
-
}
|
|
387
|
+
let engine;
|
|
388
|
+
let configList;
|
|
389
|
+
return defineEnginePlugin({
|
|
390
|
+
name: "core:selectors",
|
|
391
|
+
rawConfigConfigured(config) {
|
|
392
|
+
configList = config.selectors?.selectors ?? [];
|
|
393
|
+
},
|
|
394
|
+
configureEngine(_engine) {
|
|
395
|
+
engine = _engine;
|
|
396
|
+
engine.selectors = {
|
|
397
|
+
resolver: new SelectorResolver(),
|
|
398
|
+
add: (...list) => {
|
|
399
|
+
list.forEach((config) => {
|
|
400
|
+
const resolved = resolveSelectorConfig(config);
|
|
401
|
+
if (resolved == null) return;
|
|
402
|
+
if (typeof resolved === "string") {
|
|
403
|
+
engine.appendAutocompleteSelectors(resolved);
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
if (resolved.type === "static") engine.selectors.resolver.addStaticRule(resolved.rule);
|
|
407
|
+
else if (resolved.type === "dynamic") engine.selectors.resolver.addDynamicRule(resolved.rule);
|
|
408
|
+
engine.appendAutocompleteSelectors(...resolved.autocomplete);
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
engine.selectors.add(...configList);
|
|
413
|
+
engine.selectors.resolver.onResolved = (string, type) => {
|
|
414
|
+
if (type === "dynamic") engine.appendAutocompleteSelectors(string);
|
|
415
|
+
};
|
|
416
|
+
},
|
|
417
|
+
async transformSelectors(selectors$1) {
|
|
418
|
+
const result = [];
|
|
419
|
+
for (const selector of selectors$1) result.push(...await engine.selectors.resolver.resolve(selector));
|
|
420
|
+
return result;
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
var SelectorResolver = class extends AbstractResolver {
|
|
425
|
+
async resolve(selector) {
|
|
426
|
+
const resolved = await this._resolve(selector).catch((error) => {
|
|
427
|
+
warn(`Failed to resolve selector "${selector}": ${error.message}`, error);
|
|
428
|
+
});
|
|
429
|
+
if (resolved == null) return [selector];
|
|
430
|
+
const result = [];
|
|
431
|
+
for (const s of resolved.value) result.push(...await this.resolve(s));
|
|
432
|
+
this._setResolvedResult(selector, result);
|
|
433
|
+
return result;
|
|
434
|
+
}
|
|
435
|
+
};
|
|
490
436
|
function resolveSelectorConfig(config) {
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
stringPattern: config.selector,
|
|
538
|
-
createResolved: async (match) => [await fn(match)].flat(1)
|
|
539
|
-
},
|
|
540
|
-
autocomplete: "autocomplete" in config && config.autocomplete != null ? [config.autocomplete].flat(1) : []
|
|
541
|
-
};
|
|
542
|
-
}
|
|
543
|
-
return void 0;
|
|
437
|
+
if (typeof config === "string") return config;
|
|
438
|
+
if (Array.isArray(config)) {
|
|
439
|
+
if (typeof config[0] === "string" && typeof config[1] !== "function") return {
|
|
440
|
+
type: "static",
|
|
441
|
+
rule: {
|
|
442
|
+
key: config[0],
|
|
443
|
+
string: config[0],
|
|
444
|
+
resolved: [config[1]].flat(1)
|
|
445
|
+
},
|
|
446
|
+
autocomplete: [config[0]]
|
|
447
|
+
};
|
|
448
|
+
if (config[0] instanceof RegExp && typeof config[1] === "function") {
|
|
449
|
+
const fn = config[1];
|
|
450
|
+
return {
|
|
451
|
+
type: "dynamic",
|
|
452
|
+
rule: {
|
|
453
|
+
key: config[0].source,
|
|
454
|
+
stringPattern: config[0],
|
|
455
|
+
createResolved: async (match) => [await fn(match)].flat(1)
|
|
456
|
+
},
|
|
457
|
+
autocomplete: config[2] != null ? [config[2]].flat(1) : []
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
if (typeof config.selector === "string" && typeof config.value !== "function") return {
|
|
463
|
+
type: "static",
|
|
464
|
+
rule: {
|
|
465
|
+
key: config.selector,
|
|
466
|
+
string: config.selector,
|
|
467
|
+
resolved: [config.value].flat(1)
|
|
468
|
+
},
|
|
469
|
+
autocomplete: [config.selector]
|
|
470
|
+
};
|
|
471
|
+
if (config.selector instanceof RegExp && typeof config.value === "function") {
|
|
472
|
+
const fn = config.value;
|
|
473
|
+
return {
|
|
474
|
+
type: "dynamic",
|
|
475
|
+
rule: {
|
|
476
|
+
key: config.selector.source,
|
|
477
|
+
stringPattern: config.selector,
|
|
478
|
+
createResolved: async (match) => [await fn(match)].flat(1)
|
|
479
|
+
},
|
|
480
|
+
autocomplete: "autocomplete" in config && config.autocomplete != null ? [config.autocomplete].flat(1) : []
|
|
481
|
+
};
|
|
482
|
+
}
|
|
544
483
|
}
|
|
545
484
|
|
|
485
|
+
//#endregion
|
|
486
|
+
//#region src/internal/plugins/shortcuts.ts
|
|
546
487
|
function shortcuts() {
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
return void 0;
|
|
620
|
-
});
|
|
621
|
-
if (resolved == null)
|
|
622
|
-
return [shortcut];
|
|
623
|
-
const result = [];
|
|
624
|
-
for (const partial of resolved.value) {
|
|
625
|
-
if (typeof partial === "string")
|
|
626
|
-
result.push(...await this.resolve(partial));
|
|
627
|
-
else
|
|
628
|
-
result.push(partial);
|
|
629
|
-
}
|
|
630
|
-
this._setResolvedResult(shortcut, result);
|
|
631
|
-
return result;
|
|
632
|
-
}
|
|
633
|
-
}
|
|
488
|
+
let engine;
|
|
489
|
+
let configList;
|
|
490
|
+
return defineEnginePlugin({
|
|
491
|
+
name: "core:shortcuts",
|
|
492
|
+
rawConfigConfigured(config) {
|
|
493
|
+
configList = config.shortcuts?.shortcuts ?? [];
|
|
494
|
+
},
|
|
495
|
+
configureEngine(_engine) {
|
|
496
|
+
engine = _engine;
|
|
497
|
+
engine.shortcuts = {
|
|
498
|
+
resolver: new ShortcutResolver(),
|
|
499
|
+
add: (...list) => {
|
|
500
|
+
list.forEach((config) => {
|
|
501
|
+
const resolved = resolveShortcutConfig(config);
|
|
502
|
+
if (resolved == null) return;
|
|
503
|
+
if (typeof resolved === "string") {
|
|
504
|
+
engine.appendAutocompleteStyleItemStrings(resolved);
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
if (resolved.type === "static") engine.shortcuts.resolver.addStaticRule(resolved.rule);
|
|
508
|
+
else if (resolved.type === "dynamic") engine.shortcuts.resolver.addDynamicRule(resolved.rule);
|
|
509
|
+
engine.appendAutocompleteStyleItemStrings(...resolved.autocomplete);
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
engine.shortcuts.add(...configList);
|
|
514
|
+
engine.shortcuts.resolver.onResolved = (string, type) => {
|
|
515
|
+
if (type === "dynamic") engine.appendAutocompleteStyleItemStrings(string);
|
|
516
|
+
};
|
|
517
|
+
engine.appendAutocompleteExtraProperties("__shortcut");
|
|
518
|
+
const unionType = ["(string & {})", "Autocomplete['StyleItemString']"].join(" | ");
|
|
519
|
+
engine.appendAutocompletePropertyValues("__shortcut", unionType, `(${unionType})[]`);
|
|
520
|
+
},
|
|
521
|
+
async transformStyleItems(styleItems) {
|
|
522
|
+
const result = [];
|
|
523
|
+
for (const styleItem of styleItems) {
|
|
524
|
+
if (typeof styleItem === "string") {
|
|
525
|
+
result.push(...await engine.shortcuts.resolver.resolve(styleItem));
|
|
526
|
+
continue;
|
|
527
|
+
}
|
|
528
|
+
result.push(styleItem);
|
|
529
|
+
}
|
|
530
|
+
return result;
|
|
531
|
+
},
|
|
532
|
+
async transformStyleDefinitions(styleDefinitions) {
|
|
533
|
+
const result = [];
|
|
534
|
+
for (const styleDefinition of styleDefinitions) if ("__shortcut" in styleDefinition) {
|
|
535
|
+
const { __shortcut, ...rest } = styleDefinition;
|
|
536
|
+
const applied = [];
|
|
537
|
+
for (const shortcut of __shortcut == null ? [] : [__shortcut].flat(1)) {
|
|
538
|
+
const resolved = (await engine.shortcuts.resolver.resolve(shortcut)).filter(isNotString);
|
|
539
|
+
applied.push(...resolved);
|
|
540
|
+
}
|
|
541
|
+
result.push(...applied, rest);
|
|
542
|
+
} else result.push(styleDefinition);
|
|
543
|
+
return result;
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
var ShortcutResolver = class extends AbstractResolver {
|
|
548
|
+
async resolve(shortcut) {
|
|
549
|
+
const resolved = await this._resolve(shortcut).catch((error) => {
|
|
550
|
+
warn(`Failed to resolve shortcut "${shortcut}": ${error.message}`, error);
|
|
551
|
+
});
|
|
552
|
+
if (resolved == null) return [shortcut];
|
|
553
|
+
const result = [];
|
|
554
|
+
for (const partial of resolved.value) if (typeof partial === "string") result.push(...await this.resolve(partial));
|
|
555
|
+
else result.push(partial);
|
|
556
|
+
this._setResolvedResult(shortcut, result);
|
|
557
|
+
return result;
|
|
558
|
+
}
|
|
559
|
+
};
|
|
634
560
|
function resolveShortcutConfig(config) {
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
},
|
|
680
|
-
autocomplete: "autocomplete" in config && config.autocomplete != null ? [config.autocomplete].flat(1) : []
|
|
681
|
-
};
|
|
682
|
-
}
|
|
683
|
-
return void 0;
|
|
561
|
+
if (typeof config === "string") return config;
|
|
562
|
+
else if (Array.isArray(config)) {
|
|
563
|
+
if (typeof config[0] === "string" && typeof config[1] !== "function") return {
|
|
564
|
+
type: "static",
|
|
565
|
+
rule: {
|
|
566
|
+
key: config[0],
|
|
567
|
+
string: config[0],
|
|
568
|
+
resolved: [config[1]].flat(1)
|
|
569
|
+
},
|
|
570
|
+
autocomplete: [config[0]]
|
|
571
|
+
};
|
|
572
|
+
if (config[0] instanceof RegExp && typeof config[1] === "function") {
|
|
573
|
+
const fn = config[1];
|
|
574
|
+
return {
|
|
575
|
+
type: "dynamic",
|
|
576
|
+
rule: {
|
|
577
|
+
key: config[0].source,
|
|
578
|
+
stringPattern: config[0],
|
|
579
|
+
createResolved: async (match) => [await fn(match)].flat(1)
|
|
580
|
+
},
|
|
581
|
+
autocomplete: config[2] != null ? [config[2]].flat(1) : []
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
} else if (typeof config.shortcut === "string" && typeof config.value !== "function") return {
|
|
585
|
+
type: "static",
|
|
586
|
+
rule: {
|
|
587
|
+
key: config.shortcut,
|
|
588
|
+
string: config.shortcut,
|
|
589
|
+
resolved: [config.value].flat(1)
|
|
590
|
+
},
|
|
591
|
+
autocomplete: [config.shortcut]
|
|
592
|
+
};
|
|
593
|
+
else if (config.shortcut instanceof RegExp && typeof config.value === "function") {
|
|
594
|
+
const fn = config.value;
|
|
595
|
+
return {
|
|
596
|
+
type: "dynamic",
|
|
597
|
+
rule: {
|
|
598
|
+
key: config.shortcut.source,
|
|
599
|
+
stringPattern: config.shortcut,
|
|
600
|
+
createResolved: async (match) => [await fn(match)].flat(1)
|
|
601
|
+
},
|
|
602
|
+
autocomplete: "autocomplete" in config && config.autocomplete != null ? [config.autocomplete].flat(1) : []
|
|
603
|
+
};
|
|
604
|
+
}
|
|
684
605
|
}
|
|
685
606
|
|
|
607
|
+
//#endregion
|
|
608
|
+
//#region src/internal/plugins/variables.ts
|
|
686
609
|
function variables() {
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
selector: levels.length > 0 ? levels : [":root"],
|
|
759
|
-
autocomplete: {
|
|
760
|
-
asValueOf: autocomplete.asValueOf ? [autocomplete.asValueOf].flat() : ["*"],
|
|
761
|
-
asProperty: autocomplete.asProperty ?? true
|
|
762
|
-
},
|
|
763
|
-
pruneUnused
|
|
764
|
-
});
|
|
765
|
-
} else {
|
|
766
|
-
_resolveVariables(value, [...levels, key], result);
|
|
767
|
-
}
|
|
768
|
-
}
|
|
769
|
-
return result;
|
|
770
|
-
}
|
|
771
|
-
return function resolveVariables(variables2) {
|
|
772
|
-
return _resolveVariables(variables2, [], []);
|
|
773
|
-
};
|
|
610
|
+
let resolveVariables;
|
|
611
|
+
let rawVariables;
|
|
612
|
+
let safeSet;
|
|
613
|
+
return defineEnginePlugin({
|
|
614
|
+
name: "core:variables",
|
|
615
|
+
rawConfigConfigured(config) {
|
|
616
|
+
resolveVariables = createResolveVariablesFn({ pruneUnused: config.variables?.pruneUnused });
|
|
617
|
+
rawVariables = config.variables?.variables ?? {};
|
|
618
|
+
safeSet = new Set(config.variables?.safeList ?? []);
|
|
619
|
+
},
|
|
620
|
+
configureEngine(engine) {
|
|
621
|
+
engine.variables = {
|
|
622
|
+
store: /* @__PURE__ */ new Map(),
|
|
623
|
+
add: (variables$1) => {
|
|
624
|
+
resolveVariables(variables$1).forEach((resolved) => {
|
|
625
|
+
const { name, value, autocomplete: { asValueOf, asProperty } } = resolved;
|
|
626
|
+
asValueOf.forEach((p) => {
|
|
627
|
+
if (p !== "-") engine.appendAutocompleteCssPropertyValues(p, `var(${name})`);
|
|
628
|
+
});
|
|
629
|
+
if (asProperty) engine.appendAutocompleteExtraCssProperties(name);
|
|
630
|
+
if (value != null) {
|
|
631
|
+
const list = engine.variables.store.get(name) ?? [];
|
|
632
|
+
list.push(resolved);
|
|
633
|
+
engine.variables.store.set(name, list);
|
|
634
|
+
}
|
|
635
|
+
});
|
|
636
|
+
engine.notifyPreflightUpdated();
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
engine.variables.add(rawVariables);
|
|
640
|
+
engine.addPreflight(async (engine$1) => {
|
|
641
|
+
const used = /* @__PURE__ */ new Set();
|
|
642
|
+
engine$1.store.atomicStyles.forEach(({ content: { value } }) => {
|
|
643
|
+
value.flatMap(extractUsedVarNames).forEach((name) => used.add(normalizeVariableName(name)));
|
|
644
|
+
});
|
|
645
|
+
const usedVariables = Array.from(engine$1.variables.store.values()).flat().filter(({ name, pruneUnused, value }) => (safeSet.has(name) || pruneUnused === false || used.has(name)) && value != null);
|
|
646
|
+
const preflightDefinition = {};
|
|
647
|
+
for (const { name, value, selector: _selector } of usedVariables) {
|
|
648
|
+
const selector = await engine$1.pluginHooks.transformSelectors(engine$1.config.plugins, _selector);
|
|
649
|
+
let current = preflightDefinition;
|
|
650
|
+
selector.forEach((s) => {
|
|
651
|
+
current[s] ||= {};
|
|
652
|
+
current = current[s];
|
|
653
|
+
});
|
|
654
|
+
Object.assign(current, { [name]: value });
|
|
655
|
+
}
|
|
656
|
+
return preflightDefinition;
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
function createResolveVariablesFn({ pruneUnused: defaultPruneUnused = true } = {}) {
|
|
662
|
+
function _resolveVariables(variables$1, levels, result) {
|
|
663
|
+
for (const [key, value] of Object.entries(variables$1)) if (key.startsWith("--")) {
|
|
664
|
+
const { value: varValue, autocomplete = {}, pruneUnused = defaultPruneUnused } = typeof value === "object" && value !== null && !Array.isArray(value) ? value : { value };
|
|
665
|
+
result.push({
|
|
666
|
+
name: key,
|
|
667
|
+
value: varValue,
|
|
668
|
+
selector: levels.length > 0 ? levels : [":root"],
|
|
669
|
+
autocomplete: {
|
|
670
|
+
asValueOf: autocomplete.asValueOf ? [autocomplete.asValueOf].flat() : ["*"],
|
|
671
|
+
asProperty: autocomplete.asProperty ?? true
|
|
672
|
+
},
|
|
673
|
+
pruneUnused
|
|
674
|
+
});
|
|
675
|
+
} else _resolveVariables(value, [...levels, key], result);
|
|
676
|
+
return result;
|
|
677
|
+
}
|
|
678
|
+
return function resolveVariables(variables$1) {
|
|
679
|
+
return _resolveVariables(variables$1, [], []);
|
|
680
|
+
};
|
|
774
681
|
}
|
|
775
682
|
const VAR_NAME_RE = /var\((--[\w-]+)/g;
|
|
776
683
|
function extractUsedVarNames(input) {
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
}).filter(Boolean);
|
|
684
|
+
const matched = input.match(VAR_NAME_RE);
|
|
685
|
+
if (!matched) return [];
|
|
686
|
+
return matched.map((match) => {
|
|
687
|
+
const varNameMatch = match.match(/--[^,)]+/);
|
|
688
|
+
return varNameMatch ? varNameMatch[0] : "";
|
|
689
|
+
}).filter(Boolean);
|
|
784
690
|
}
|
|
785
691
|
function normalizeVariableName(name) {
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
return `--${name}`;
|
|
692
|
+
if (name.startsWith("--")) return name;
|
|
693
|
+
return `--${name}`;
|
|
789
694
|
}
|
|
790
695
|
|
|
696
|
+
//#endregion
|
|
697
|
+
//#region src/internal/engine.ts
|
|
698
|
+
/* c8 ignore start */
|
|
791
699
|
function defineEngineConfig(config) {
|
|
792
|
-
|
|
700
|
+
return config;
|
|
793
701
|
}
|
|
702
|
+
/* c8 ignore end */
|
|
794
703
|
async function createEngine(config = {}) {
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
return renderPreflightDefinition({
|
|
910
|
-
engine: this,
|
|
911
|
-
preflightDefinition: result,
|
|
912
|
-
isFormatted
|
|
913
|
-
});
|
|
914
|
-
}))).join(lineEnd);
|
|
915
|
-
}
|
|
916
|
-
async renderAtomicStyles(isFormatted, options = {}) {
|
|
917
|
-
const { atomicStyleIds = null, isPreview = false } = options;
|
|
918
|
-
const atomicStyles = atomicStyleIds == null ? [...this.store.atomicStyles.values()] : atomicStyleIds.map((id) => this.store.atomicStyles.get(id)).filter(isNotNullish);
|
|
919
|
-
return renderAtomicStyles({
|
|
920
|
-
atomicStyles,
|
|
921
|
-
isPreview,
|
|
922
|
-
isFormatted,
|
|
923
|
-
defaultSelector: this.config.defaultSelector
|
|
924
|
-
});
|
|
925
|
-
}
|
|
926
|
-
}
|
|
704
|
+
config.plugins = resolvePlugins([...[
|
|
705
|
+
important(),
|
|
706
|
+
variables(),
|
|
707
|
+
keyframes(),
|
|
708
|
+
selectors(),
|
|
709
|
+
shortcuts()
|
|
710
|
+
], ...config.plugins || []]);
|
|
711
|
+
config = await hooks.configureRawConfig(config.plugins, config);
|
|
712
|
+
hooks.rawConfigConfigured(resolvePlugins(config.plugins || []), config);
|
|
713
|
+
let resolvedConfig = await resolveEngineConfig(config);
|
|
714
|
+
resolvedConfig = await hooks.configureResolvedConfig(resolvedConfig.plugins, resolvedConfig);
|
|
715
|
+
let engine = new Engine(resolvedConfig);
|
|
716
|
+
engine = await hooks.configureEngine(engine.config.plugins, engine);
|
|
717
|
+
return engine;
|
|
718
|
+
}
|
|
719
|
+
var Engine = class {
|
|
720
|
+
constructor(config) {
|
|
721
|
+
this.pluginHooks = hooks;
|
|
722
|
+
this.store = {
|
|
723
|
+
atomicStyleIds: /* @__PURE__ */ new Map(),
|
|
724
|
+
atomicStyles: /* @__PURE__ */ new Map()
|
|
725
|
+
};
|
|
726
|
+
this.config = config;
|
|
727
|
+
this.extract = createExtractFn({
|
|
728
|
+
defaultSelector: this.config.defaultSelector,
|
|
729
|
+
transformSelectors: (selectors$1) => hooks.transformSelectors(this.config.plugins, selectors$1),
|
|
730
|
+
transformStyleItems: (styleItems) => hooks.transformStyleItems(this.config.plugins, styleItems),
|
|
731
|
+
transformStyleDefinitions: (styleDefinitions) => hooks.transformStyleDefinitions(this.config.plugins, styleDefinitions)
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
notifyPreflightUpdated() {
|
|
735
|
+
hooks.preflightUpdated(this.config.plugins);
|
|
736
|
+
}
|
|
737
|
+
notifyAtomicStyleAdded(atomicStyle) {
|
|
738
|
+
hooks.atomicStyleAdded(this.config.plugins, atomicStyle);
|
|
739
|
+
}
|
|
740
|
+
notifyAutocompleteConfigUpdated() {
|
|
741
|
+
hooks.autocompleteConfigUpdated(this.config.plugins);
|
|
742
|
+
}
|
|
743
|
+
appendAutocompleteSelectors(...selectors$1) {
|
|
744
|
+
appendAutocompleteSelectors(this.config, ...selectors$1);
|
|
745
|
+
this.notifyAutocompleteConfigUpdated();
|
|
746
|
+
}
|
|
747
|
+
appendAutocompleteStyleItemStrings(...styleItemStrings) {
|
|
748
|
+
appendAutocompleteStyleItemStrings(this.config, ...styleItemStrings);
|
|
749
|
+
this.notifyAutocompleteConfigUpdated();
|
|
750
|
+
}
|
|
751
|
+
appendAutocompleteExtraProperties(...properties) {
|
|
752
|
+
appendAutocompleteExtraProperties(this.config, ...properties);
|
|
753
|
+
this.notifyAutocompleteConfigUpdated();
|
|
754
|
+
}
|
|
755
|
+
appendAutocompleteExtraCssProperties(...properties) {
|
|
756
|
+
appendAutocompleteExtraCssProperties(this.config, ...properties);
|
|
757
|
+
this.notifyAutocompleteConfigUpdated();
|
|
758
|
+
}
|
|
759
|
+
appendAutocompletePropertyValues(property, ...tsTypes) {
|
|
760
|
+
appendAutocompletePropertyValues(this.config, property, ...tsTypes);
|
|
761
|
+
this.notifyAutocompleteConfigUpdated();
|
|
762
|
+
}
|
|
763
|
+
appendAutocompleteCssPropertyValues(property, ...values) {
|
|
764
|
+
appendAutocompleteCssPropertyValues(this.config, property, ...values);
|
|
765
|
+
this.notifyAutocompleteConfigUpdated();
|
|
766
|
+
}
|
|
767
|
+
addPreflight(preflight) {
|
|
768
|
+
this.config.preflights.push(resolvePreflight(preflight));
|
|
769
|
+
this.notifyPreflightUpdated();
|
|
770
|
+
}
|
|
771
|
+
async use(...itemList) {
|
|
772
|
+
const { unknown, contents } = await resolveStyleItemList({
|
|
773
|
+
itemList,
|
|
774
|
+
transformStyleItems: (styleItems) => hooks.transformStyleItems(this.config.plugins, styleItems),
|
|
775
|
+
extractStyleDefinition: (styleDefinition) => this.extract(styleDefinition)
|
|
776
|
+
});
|
|
777
|
+
const resolvedIds = [];
|
|
778
|
+
contents.forEach((content) => {
|
|
779
|
+
const id = getAtomicStyleId({
|
|
780
|
+
content,
|
|
781
|
+
prefix: this.config.prefix,
|
|
782
|
+
stored: this.store.atomicStyleIds
|
|
783
|
+
});
|
|
784
|
+
resolvedIds.push(id);
|
|
785
|
+
if (!this.store.atomicStyles.has(id)) {
|
|
786
|
+
const atomicStyle = {
|
|
787
|
+
id,
|
|
788
|
+
content
|
|
789
|
+
};
|
|
790
|
+
this.store.atomicStyles.set(id, atomicStyle);
|
|
791
|
+
this.notifyAtomicStyleAdded(atomicStyle);
|
|
792
|
+
}
|
|
793
|
+
});
|
|
794
|
+
return [...unknown, ...resolvedIds];
|
|
795
|
+
}
|
|
796
|
+
async renderPreflights(isFormatted) {
|
|
797
|
+
const lineEnd = isFormatted ? "\n" : "";
|
|
798
|
+
return (await Promise.all(this.config.preflights.map(async (p) => {
|
|
799
|
+
const result = await p(this, isFormatted);
|
|
800
|
+
if (typeof result === "string") return result;
|
|
801
|
+
return renderPreflightDefinition({
|
|
802
|
+
engine: this,
|
|
803
|
+
preflightDefinition: result,
|
|
804
|
+
isFormatted
|
|
805
|
+
});
|
|
806
|
+
}))).join(lineEnd);
|
|
807
|
+
}
|
|
808
|
+
async renderAtomicStyles(isFormatted, options = {}) {
|
|
809
|
+
const { atomicStyleIds = null, isPreview = false } = options;
|
|
810
|
+
return renderAtomicStyles({
|
|
811
|
+
atomicStyles: atomicStyleIds == null ? [...this.store.atomicStyles.values()] : atomicStyleIds.map((id) => this.store.atomicStyles.get(id)).filter(isNotNullish),
|
|
812
|
+
isPreview,
|
|
813
|
+
isFormatted,
|
|
814
|
+
defaultSelector: this.config.defaultSelector
|
|
815
|
+
});
|
|
816
|
+
}
|
|
817
|
+
};
|
|
927
818
|
function calcAtomicStyleRenderingWeight(style, defaultSelector) {
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
return isDefaultSelector ? 0 : selector.length;
|
|
819
|
+
const { selector } = style.content;
|
|
820
|
+
return selector.length === 1 && selector[0] === defaultSelector ? 0 : selector.length;
|
|
931
821
|
}
|
|
932
822
|
function resolvePreflight(preflight) {
|
|
933
|
-
|
|
823
|
+
return typeof preflight === "function" ? preflight : () => preflight;
|
|
934
824
|
}
|
|
935
825
|
async function resolveEngineConfig(config) {
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
})
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
if (cached != null)
|
|
969
|
-
return cached;
|
|
970
|
-
const num = stored.size;
|
|
971
|
-
const id = `${prefix}${numberToChars(num)}`;
|
|
972
|
-
stored.set(key, id);
|
|
973
|
-
return id;
|
|
826
|
+
const { prefix = "", defaultSelector = `.${ATOMIC_STYLE_ID_PLACEHOLDER}`, plugins = [], preflights = [] } = config;
|
|
827
|
+
const resolvedConfig = {
|
|
828
|
+
rawConfig: config,
|
|
829
|
+
plugins: resolvePlugins(plugins),
|
|
830
|
+
prefix,
|
|
831
|
+
defaultSelector,
|
|
832
|
+
preflights: [],
|
|
833
|
+
autocomplete: {
|
|
834
|
+
selectors: /* @__PURE__ */ new Set(),
|
|
835
|
+
styleItemStrings: /* @__PURE__ */ new Set(),
|
|
836
|
+
extraProperties: /* @__PURE__ */ new Set(),
|
|
837
|
+
extraCssProperties: /* @__PURE__ */ new Set(),
|
|
838
|
+
properties: /* @__PURE__ */ new Map(),
|
|
839
|
+
cssProperties: /* @__PURE__ */ new Map()
|
|
840
|
+
}
|
|
841
|
+
};
|
|
842
|
+
const resolvedPreflights = preflights.map(resolvePreflight);
|
|
843
|
+
resolvedConfig.preflights.push(...resolvedPreflights);
|
|
844
|
+
return resolvedConfig;
|
|
845
|
+
}
|
|
846
|
+
function getAtomicStyleId({ content, prefix, stored }) {
|
|
847
|
+
const key = serialize([
|
|
848
|
+
content.selector,
|
|
849
|
+
content.property,
|
|
850
|
+
content.value
|
|
851
|
+
]);
|
|
852
|
+
const cached = stored.get(key);
|
|
853
|
+
if (cached != null) return cached;
|
|
854
|
+
const num = stored.size;
|
|
855
|
+
const id = `${prefix}${numberToChars(num)}`;
|
|
856
|
+
stored.set(key, id);
|
|
857
|
+
return id;
|
|
974
858
|
}
|
|
975
859
|
function optimizeAtomicStyleContents(list) {
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
}
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
if (typeof styleItem === "string")
|
|
995
|
-
unknown.add(styleItem);
|
|
996
|
-
else
|
|
997
|
-
list.push(...await extractStyleDefinition(styleItem));
|
|
998
|
-
}
|
|
999
|
-
return {
|
|
1000
|
-
unknown,
|
|
1001
|
-
contents: optimizeAtomicStyleContents(list)
|
|
1002
|
-
};
|
|
860
|
+
const map = /* @__PURE__ */ new Map();
|
|
861
|
+
list.forEach((content) => {
|
|
862
|
+
const key = serialize([content.selector, content.property]);
|
|
863
|
+
map.delete(key);
|
|
864
|
+
if (content.value == null) return;
|
|
865
|
+
map.set(key, content);
|
|
866
|
+
});
|
|
867
|
+
return [...map.values()];
|
|
868
|
+
}
|
|
869
|
+
async function resolveStyleItemList({ itemList, transformStyleItems, extractStyleDefinition }) {
|
|
870
|
+
const unknown = /* @__PURE__ */ new Set();
|
|
871
|
+
const list = [];
|
|
872
|
+
for (const styleItem of await transformStyleItems(itemList)) if (typeof styleItem === "string") unknown.add(styleItem);
|
|
873
|
+
else list.push(...await extractStyleDefinition(styleItem));
|
|
874
|
+
return {
|
|
875
|
+
unknown,
|
|
876
|
+
contents: optimizeAtomicStyleContents(list)
|
|
877
|
+
};
|
|
1003
878
|
}
|
|
1004
879
|
function renderAtomicStyles(payload) {
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
currentBlockBody.children.set(k, currentBlockBody.children.get(k) || { properties: [] });
|
|
1068
|
-
await _renderPreflightDefinition({
|
|
1069
|
-
engine,
|
|
1070
|
-
preflightDefinition: { [k]: v },
|
|
1071
|
-
blocks: currentBlockBody.children
|
|
1072
|
-
});
|
|
1073
|
-
}
|
|
1074
|
-
}
|
|
1075
|
-
}
|
|
1076
|
-
return blocks;
|
|
880
|
+
const { atomicStyles, isPreview, isFormatted, defaultSelector } = payload;
|
|
881
|
+
const blocks = /* @__PURE__ */ new Map();
|
|
882
|
+
Array.from(atomicStyles).sort((a, b) => {
|
|
883
|
+
return calcAtomicStyleRenderingWeight(a, defaultSelector) - calcAtomicStyleRenderingWeight(b, defaultSelector);
|
|
884
|
+
}).forEach(({ id, content: { selector, property, value } }) => {
|
|
885
|
+
if (selector.some((s) => s.includes(ATOMIC_STYLE_ID_PLACEHOLDER)) === false || value == null) return;
|
|
886
|
+
const renderObject = {
|
|
887
|
+
selector: isPreview ? selector : selector.map((s) => s.replace(ATOMIC_STYLE_ID_PLACEHOLDER_RE_GLOBAL, id)),
|
|
888
|
+
properties: value.map((v) => ({
|
|
889
|
+
property,
|
|
890
|
+
value: v
|
|
891
|
+
}))
|
|
892
|
+
};
|
|
893
|
+
let currentBlocks = blocks;
|
|
894
|
+
for (let i = 0; i < renderObject.selector.length; i++) {
|
|
895
|
+
const s = renderObject.selector[i];
|
|
896
|
+
const blockBody = currentBlocks.get(s) || { properties: [] };
|
|
897
|
+
const isLastSelector = i === renderObject.selector.length - 1;
|
|
898
|
+
if (isLastSelector) blockBody.properties.push(...renderObject.properties);
|
|
899
|
+
else blockBody.children ||= /* @__PURE__ */ new Map();
|
|
900
|
+
currentBlocks.set(s, blockBody);
|
|
901
|
+
if (isLastSelector === false) currentBlocks = blockBody.children;
|
|
902
|
+
}
|
|
903
|
+
});
|
|
904
|
+
return renderCSSStyleBlocks(blocks, isFormatted);
|
|
905
|
+
}
|
|
906
|
+
async function _renderPreflightDefinition({ engine, preflightDefinition, blocks = /* @__PURE__ */ new Map() }) {
|
|
907
|
+
for (const [selector, propertiesOrDefinition] of Object.entries(preflightDefinition)) {
|
|
908
|
+
if (propertiesOrDefinition == null) continue;
|
|
909
|
+
const selectors$1 = normalizeSelectors({
|
|
910
|
+
selectors: await hooks.transformSelectors(engine.config.plugins, [selector]),
|
|
911
|
+
defaultSelector: ""
|
|
912
|
+
}).filter(Boolean);
|
|
913
|
+
let currentBlocks = blocks;
|
|
914
|
+
let currentBlockBody = null;
|
|
915
|
+
selectors$1.forEach((s, i) => {
|
|
916
|
+
const isLast = i === selectors$1.length - 1;
|
|
917
|
+
currentBlocks.set(s, currentBlocks.get(s) || { properties: [] });
|
|
918
|
+
if (isLast) {
|
|
919
|
+
currentBlockBody = currentBlocks.get(s);
|
|
920
|
+
return;
|
|
921
|
+
}
|
|
922
|
+
currentBlocks = currentBlocks.get(s).children ||= /* @__PURE__ */ new Map();
|
|
923
|
+
});
|
|
924
|
+
for (const [k, v] of Object.entries(propertiesOrDefinition)) if (isPropertyValue(v)) {
|
|
925
|
+
const property = toKebab(k);
|
|
926
|
+
const normalizedValue = normalizeValue(v);
|
|
927
|
+
if (normalizedValue != null) normalizedValue.forEach((value) => currentBlockBody.properties.push({
|
|
928
|
+
property,
|
|
929
|
+
value
|
|
930
|
+
}));
|
|
931
|
+
} else {
|
|
932
|
+
currentBlockBody.children ||= /* @__PURE__ */ new Map();
|
|
933
|
+
currentBlockBody.children.set(k, currentBlockBody.children.get(k) || { properties: [] });
|
|
934
|
+
await _renderPreflightDefinition({
|
|
935
|
+
engine,
|
|
936
|
+
preflightDefinition: { [k]: v },
|
|
937
|
+
blocks: currentBlockBody.children
|
|
938
|
+
});
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
return blocks;
|
|
1077
942
|
}
|
|
1078
943
|
async function renderPreflightDefinition(payload) {
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
return renderCSSStyleBlocks(blocks, isFormatted);
|
|
944
|
+
const { engine, preflightDefinition, isFormatted } = payload;
|
|
945
|
+
return renderCSSStyleBlocks(await _renderPreflightDefinition({
|
|
946
|
+
engine,
|
|
947
|
+
preflightDefinition
|
|
948
|
+
}), isFormatted);
|
|
1085
949
|
}
|
|
1086
950
|
|
|
1087
|
-
|
|
951
|
+
//#endregion
|
|
952
|
+
//#region src/index.ts
|
|
953
|
+
/* c8 ignore end */
|
|
954
|
+
|
|
955
|
+
//#endregion
|
|
956
|
+
export { appendAutocompleteCssPropertyValues, appendAutocompleteExtraCssProperties, appendAutocompleteExtraProperties, appendAutocompletePropertyValues, appendAutocompleteSelectors, appendAutocompleteStyleItemStrings, createEngine, defineEngineConfig, defineEnginePlugin, renderCSSStyleBlocks, setWarnFn, warn };
|