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