@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.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
- console.warn("[@pikacss/core]", ...args);
8
+ console.warn("[@pikacss/core]", ...args);
6
9
  };
7
10
  function setWarnFn(fn) {
8
- _warn = fn;
11
+ _warn = fn;
9
12
  }
10
13
  function warn(...args) {
11
- _warn(...args);
14
+ _warn(...args);
12
15
  }
13
16
  const chars = [..."abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"];
14
17
  const numOfChars = chars.length;
15
18
  function numberToChars(num) {
16
- if (num < numOfChars)
17
- return chars[num];
18
- let result = "";
19
- let n = num;
20
- while (n >= 0) {
21
- result += chars[n % numOfChars];
22
- n = Math.floor(n / numOfChars) - 1;
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
- return str.replace(UPPER_CASE, (c) => `-${c.toLowerCase()}`);
30
+ return str.replace(UPPER_CASE, (c) => `-${c.toLowerCase()}`);
29
31
  }
30
32
  function isNotNullish(value) {
31
- return value != null;
33
+ return value != null;
32
34
  }
33
35
  function isNotString(value) {
34
- return typeof value !== "string";
36
+ return typeof value !== "string";
35
37
  }
36
38
  function isPropertyValue(v) {
37
- if (Array.isArray(v))
38
- return v.length === 2 && isPropertyValue(v[0]) && Array.isArray(v[1]) && v[1].every(isPropertyValue);
39
- if (v == null)
40
- return true;
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
- return JSON.stringify(value);
45
+ return JSON.stringify(value);
47
46
  }
48
47
  function addToSet(set, ...values) {
49
- values.forEach((value) => set.add(value));
48
+ values.forEach((value) => set.add(value));
50
49
  }
51
- function appendAutocompleteSelectors(config, ...selectors) {
52
- addToSet(config.autocomplete.selectors, ...selectors);
50
+ function appendAutocompleteSelectors(config, ...selectors$1) {
51
+ addToSet(config.autocomplete.selectors, ...selectors$1);
53
52
  }
54
53
  function appendAutocompleteStyleItemStrings(config, ...styleItemStrings) {
55
- addToSet(config.autocomplete.styleItemStrings, ...styleItemStrings);
54
+ addToSet(config.autocomplete.styleItemStrings, ...styleItemStrings);
56
55
  }
57
56
  function appendAutocompleteExtraProperties(config, ...properties) {
58
- addToSet(config.autocomplete.extraProperties, ...properties);
57
+ addToSet(config.autocomplete.extraProperties, ...properties);
59
58
  }
60
59
  function appendAutocompleteExtraCssProperties(config, ...properties) {
61
- addToSet(config.autocomplete.extraCssProperties, ...properties);
60
+ addToSet(config.autocomplete.extraCssProperties, ...properties);
62
61
  }
63
62
  function appendAutocompletePropertyValues(config, property, ...tsTypes) {
64
- const current = config.autocomplete.properties.get(property) || [];
65
- config.autocomplete.properties.set(property, [...current, ...tsTypes]);
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
- const current = config.autocomplete.cssProperties.get(property) || [];
69
- config.autocomplete.cssProperties.set(property, [...current, ...values]);
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
- 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))
80
- return;
81
- lines.push(...[
82
- `${blockIndent}${selector}${selectorEnd}{`,
83
- ...properties.map(({ property, value }) => `${blockBodyIndent}${property}:${propertySpace}${value};`),
84
- ...children != null && children.size > 0 ? [renderCSSStyleBlocks(children, isFormatted, depth + 1)] : [],
85
- `${blockIndent}}`
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
- let splitted = str.split(split);
93
- if (mapFn != null)
94
- splitted = splitted.map(mapFn);
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
- selectors,
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
- if (value == null)
127
- return value;
128
- return [...new Set([value].flat(2).map((v) => String(v).trim()))];
129
- }
130
- async function extract({
131
- styleDefinition,
132
- levels = [],
133
- result = [],
134
- defaultSelector,
135
- transformSelectors,
136
- transformStyleItems,
137
- transformStyleDefinitions
138
- }) {
139
- for (const definition of await transformStyleDefinitions([styleDefinition])) {
140
- for (const [k, v] of Object.entries(definition)) {
141
- if (isPropertyValue(v)) {
142
- const selector = normalizeSelectors({
143
- selectors: await transformSelectors(levels),
144
- defaultSelector
145
- });
146
- if (selector.length === 0 || selector.every((s) => s.includes(ATOMIC_STYLE_ID_PLACEHOLDER) === false))
147
- selector.push(defaultSelector);
148
- result.push({
149
- selector,
150
- property: toKebab(k),
151
- value: normalizeValue(v)
152
- });
153
- } else if (Array.isArray(v)) {
154
- for (const styleItem of await transformStyleItems(v)) {
155
- if (typeof styleItem === "string")
156
- continue;
157
- await extract({
158
- styleDefinition: styleItem,
159
- levels: [...levels, k],
160
- result,
161
- transformSelectors,
162
- transformStyleItems,
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
- return (styleDefinition) => extract({
184
- styleDefinition,
185
- ...options
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
- for (const plugin of plugins) {
191
- if (plugin[hook] == null)
192
- continue;
193
- try {
194
- const newPayload = await plugin[hook](payload);
195
- if (newPayload != null)
196
- payload = newPayload;
197
- } catch (error) {
198
- warn(`Plugin "${plugin.name}" failed to execute hook "${hook}": ${error.message}`, error);
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
- for (const plugin of plugins) {
205
- if (plugin[hook] == null)
206
- continue;
207
- try {
208
- const newPayload = plugin[hook](payload);
209
- if (newPayload != null)
210
- payload = newPayload;
211
- } catch (error) {
212
- warn(`Plugin "${plugin.name}" failed to execute hook "${hook}": ${error.message}`, error);
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
- configureRawConfig: (plugins, config) => execAsyncHook(plugins, "configureRawConfig", config),
219
- rawConfigConfigured: (plugins, config) => execSyncHook(plugins, "rawConfigConfigured", config),
220
- configureResolvedConfig: (plugins, resolvedConfig) => execAsyncHook(plugins, "configureResolvedConfig", resolvedConfig),
221
- configureEngine: (plugins, engine) => execAsyncHook(plugins, "configureEngine", engine),
222
- transformSelectors: (plugins, selectors) => execAsyncHook(plugins, "transformSelectors", selectors),
223
- transformStyleItems: (plugins, styleItems) => execAsyncHook(plugins, "transformStyleItems", styleItems),
224
- transformStyleDefinitions: (plugins, styleDefinitions) => execAsyncHook(plugins, "transformStyleDefinitions", styleDefinitions),
225
- preflightUpdated: (plugins) => execSyncHook(plugins, "preflightUpdated", void 0),
226
- atomicStyleAdded: (plugins) => execSyncHook(plugins, "atomicStyleAdded", void 0),
227
- autocompleteConfigUpdated: (plugins) => execSyncHook(plugins, "autocompleteConfigUpdated", void 0)
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 = /* @__PURE__ */ new Map([
230
- [void 0, 1],
231
- ["pre", 0],
232
- ["post", 2]
187
+ const orderMap = new Map([
188
+ [void 0, 1],
189
+ ["pre", 0],
190
+ ["post", 2]
233
191
  ]);
234
192
  function resolvePlugins(plugins) {
235
- return plugins.sort((a, b) => orderMap.get(a.order) - orderMap.get(b.order));
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
- return plugin;
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
- if (value == null)
243
- return null;
244
- if (Array.isArray(value)) {
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
- let defaultValue;
251
- return defineEnginePlugin({
252
- name: "core:important",
253
- rawConfigConfigured(config) {
254
- defaultValue = config.important?.default ?? false;
255
- },
256
- configureEngine(engine) {
257
- engine.appendAutocompleteExtraProperties("__important");
258
- engine.appendAutocompletePropertyValues("__important", "boolean");
259
- },
260
- transformStyleDefinitions(styleDefinitions) {
261
- return styleDefinitions.map((styleDefinition) => {
262
- const { __important, ...rest } = styleDefinition;
263
- const value = __important;
264
- const important2 = value == null ? defaultValue : value;
265
- if (important2 === false)
266
- return rest;
267
- return Object.fromEntries(
268
- Object.entries(rest).map(([k, v]) => {
269
- if (isPropertyValue(v)) {
270
- return [k, modifyPropertyValue(v)];
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
- let resolveKeyframesConfig;
282
- let configList;
283
- return defineEnginePlugin({
284
- name: "core:keyframes",
285
- rawConfigConfigured(config) {
286
- resolveKeyframesConfig = createResolveConfigFn({
287
- pruneUnused: config.keyframes?.pruneUnused
288
- });
289
- configList = config.keyframes?.keyframes ?? [];
290
- },
291
- configureEngine(engine) {
292
- engine.keyframes = {
293
- store: /* @__PURE__ */ new Map(),
294
- add: (...list) => {
295
- list.forEach((config) => {
296
- const resolved = resolveKeyframesConfig(config);
297
- const { name, frames, autocomplete: autocompleteAnimation } = resolved;
298
- if (frames != null)
299
- engine.keyframes.store.set(name, resolved);
300
- engine.appendAutocompleteCssPropertyValues("animationName", name);
301
- engine.appendAutocompleteCssPropertyValues("animation", `${name} `);
302
- if (autocompleteAnimation != null)
303
- engine.appendAutocompleteCssPropertyValues("animation", ...autocompleteAnimation);
304
- });
305
- engine.notifyPreflightUpdated();
306
- }
307
- };
308
- engine.keyframes.add(...configList);
309
- engine.addPreflight((engine2) => {
310
- const maybeUsedName = /* @__PURE__ */ new Set();
311
- engine2.store.atomicStyles.forEach(({ content: { property, value } }) => {
312
- if (property === "animationName") {
313
- value.forEach((name) => maybeUsedName.add(name));
314
- return;
315
- }
316
- if (property === "animation") {
317
- value.forEach((value2) => {
318
- const animations = value2.split(",").map((v) => v.trim());
319
- animations.forEach((animation) => {
320
- addToSet(maybeUsedName, ...animation.split(" "));
321
- });
322
- });
323
- }
324
- });
325
- const maybeUsedKeyframes = Array.from(engine2.keyframes.store.values()).filter(({ name, frames, pruneUnused }) => (pruneUnused === false || maybeUsedName.has(name)) && frames != null);
326
- const preflightDefinition = {};
327
- maybeUsedKeyframes.forEach(({ name, frames }) => {
328
- preflightDefinition[`@keyframes ${name}`] = Object.fromEntries(
329
- Object.entries(frames).map(([frame, properties]) => [
330
- frame,
331
- properties
332
- ])
333
- );
334
- });
335
- return preflightDefinition;
336
- });
337
- }
338
- });
339
- }
340
- function createResolveConfigFn({
341
- pruneUnused: defaultPruneUnused = true
342
- } = {}) {
343
- return function resolveKeyframesConfig(config) {
344
- if (typeof config === "string")
345
- return { name: config, frames: null, autocomplete: [], pruneUnused: defaultPruneUnused };
346
- if (Array.isArray(config)) {
347
- const [name2, frames2, autocomplete2 = [], pruneUnused2 = defaultPruneUnused] = config;
348
- return { name: name2, frames: frames2, autocomplete: autocomplete2, pruneUnused: pruneUnused2 };
349
- }
350
- const { name, frames, autocomplete = [], pruneUnused = defaultPruneUnused } = config;
351
- return { name, frames, autocomplete, pruneUnused };
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
- class AbstractResolver {
356
- _resolvedResultsMap = /* @__PURE__ */ new Map();
357
- staticRulesMap = /* @__PURE__ */ new Map();
358
- dynamicRulesMap = /* @__PURE__ */ new Map();
359
- onResolved = () => {
360
- };
361
- get staticRules() {
362
- return [...this.staticRulesMap.values()];
363
- }
364
- get dynamicRules() {
365
- return [...this.dynamicRulesMap.values()];
366
- }
367
- addStaticRule(rule) {
368
- this.staticRulesMap.set(rule.key, rule);
369
- return this;
370
- }
371
- removeStaticRule(key) {
372
- const rule = this.staticRulesMap.get(key);
373
- if (rule == null)
374
- return this;
375
- this.staticRulesMap.delete(key);
376
- this._resolvedResultsMap.delete(rule.string);
377
- return this;
378
- }
379
- addDynamicRule(rule) {
380
- this.dynamicRulesMap.set(rule.key, rule);
381
- return this;
382
- }
383
- removeDynamicRule(key) {
384
- const rule = this.dynamicRulesMap.get(key);
385
- if (rule == null)
386
- return this;
387
- const matchedResolvedStringList = Array.from(this._resolvedResultsMap.keys()).filter((string) => rule.stringPattern.test(string));
388
- this.dynamicRulesMap.delete(key);
389
- matchedResolvedStringList.forEach((string) => this._resolvedResultsMap.delete(string));
390
- return this;
391
- }
392
- async _resolve(string) {
393
- const existedResult = this._resolvedResultsMap.get(string);
394
- if (existedResult != null)
395
- return existedResult;
396
- const staticRule = Array.from(this.staticRulesMap.values()).find((rule) => rule.string === string);
397
- if (staticRule != null) {
398
- const resolvedResult = { value: staticRule.resolved };
399
- this._resolvedResultsMap.set(string, resolvedResult);
400
- this.onResolved(string, "static", resolvedResult);
401
- return resolvedResult;
402
- }
403
- let dynamicRule;
404
- let matched;
405
- for (const rule of this.dynamicRulesMap.values()) {
406
- matched = string.match(rule.stringPattern);
407
- if (matched != null) {
408
- dynamicRule = rule;
409
- break;
410
- }
411
- }
412
- if (dynamicRule != null && matched != null) {
413
- const resolvedResult = { value: await dynamicRule.createResolved(matched) };
414
- this._resolvedResultsMap.set(string, resolvedResult);
415
- this.onResolved(string, "dynamic", resolvedResult);
416
- return resolvedResult;
417
- }
418
- return void 0;
419
- }
420
- _setResolvedResult(string, resolved) {
421
- const resolvedResult = this._resolvedResultsMap.get(string);
422
- if (resolvedResult) {
423
- resolvedResult.value = resolved;
424
- return;
425
- }
426
- this._resolvedResultsMap.set(string, { value: resolved });
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
- let engine;
432
- let configList;
433
- return defineEnginePlugin({
434
- name: "core:selectors",
435
- rawConfigConfigured(config) {
436
- configList = config.selectors?.selectors ?? [];
437
- },
438
- configureEngine(_engine) {
439
- engine = _engine;
440
- engine.selectors = {
441
- resolver: new SelectorResolver(),
442
- add: (...list) => {
443
- list.forEach((config) => {
444
- const resolved = resolveSelectorConfig(config);
445
- if (resolved == null)
446
- return;
447
- if (typeof resolved === "string") {
448
- engine.appendAutocompleteSelectors(resolved);
449
- return;
450
- }
451
- if (resolved.type === "static")
452
- engine.selectors.resolver.addStaticRule(resolved.rule);
453
- else if (resolved.type === "dynamic")
454
- engine.selectors.resolver.addDynamicRule(resolved.rule);
455
- engine.appendAutocompleteSelectors(...resolved.autocomplete);
456
- });
457
- }
458
- };
459
- engine.selectors.add(...configList);
460
- engine.selectors.resolver.onResolved = (string, type) => {
461
- if (type === "dynamic") {
462
- engine.appendAutocompleteSelectors(string);
463
- }
464
- };
465
- },
466
- async transformSelectors(selectors2) {
467
- const result = [];
468
- for (const selector of selectors2) {
469
- result.push(...await engine.selectors.resolver.resolve(selector));
470
- }
471
- return result;
472
- }
473
- });
474
- }
475
- class SelectorResolver extends AbstractResolver {
476
- async resolve(selector) {
477
- const resolved = await this._resolve(selector).catch((error) => {
478
- warn(`Failed to resolve selector "${selector}": ${error.message}`, error);
479
- return void 0;
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
- if (typeof config === "string") {
492
- return config;
493
- }
494
- if (Array.isArray(config)) {
495
- if (typeof config[0] === "string" && typeof config[1] !== "function") {
496
- return {
497
- type: "static",
498
- rule: {
499
- key: config[0],
500
- string: config[0],
501
- resolved: [config[1]].flat(1)
502
- },
503
- autocomplete: [config[0]]
504
- };
505
- }
506
- if (config[0] instanceof RegExp && typeof config[1] === "function") {
507
- const fn = config[1];
508
- return {
509
- type: "dynamic",
510
- rule: {
511
- key: config[0].source,
512
- stringPattern: config[0],
513
- createResolved: async (match) => [await fn(match)].flat(1)
514
- },
515
- autocomplete: config[2] != null ? [config[2]].flat(1) : []
516
- };
517
- }
518
- return void 0;
519
- }
520
- if (typeof config.selector === "string" && typeof config.value !== "function") {
521
- return {
522
- type: "static",
523
- rule: {
524
- key: config.selector,
525
- string: config.selector,
526
- resolved: [config.value].flat(1)
527
- },
528
- autocomplete: [config.selector]
529
- };
530
- }
531
- if (config.selector instanceof RegExp && typeof config.value === "function") {
532
- const fn = config.value;
533
- return {
534
- type: "dynamic",
535
- rule: {
536
- key: config.selector.source,
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
- let engine;
548
- let configList;
549
- return defineEnginePlugin({
550
- name: "core:shortcuts",
551
- rawConfigConfigured(config) {
552
- configList = config.shortcuts?.shortcuts ?? [];
553
- },
554
- configureEngine(_engine) {
555
- engine = _engine;
556
- engine.shortcuts = {
557
- resolver: new ShortcutResolver(),
558
- add: (...list) => {
559
- list.forEach((config) => {
560
- const resolved = resolveShortcutConfig(config);
561
- if (resolved == null)
562
- return;
563
- if (typeof resolved === "string") {
564
- engine.appendAutocompleteStyleItemStrings(resolved);
565
- return;
566
- }
567
- if (resolved.type === "static")
568
- engine.shortcuts.resolver.addStaticRule(resolved.rule);
569
- else if (resolved.type === "dynamic")
570
- engine.shortcuts.resolver.addDynamicRule(resolved.rule);
571
- engine.appendAutocompleteStyleItemStrings(...resolved.autocomplete);
572
- });
573
- }
574
- };
575
- engine.shortcuts.add(...configList);
576
- engine.shortcuts.resolver.onResolved = (string, type) => {
577
- if (type === "dynamic") {
578
- engine.appendAutocompleteStyleItemStrings(string);
579
- }
580
- };
581
- engine.appendAutocompleteExtraProperties("__shortcut");
582
- const unionType = ["(string & {})", "Autocomplete['StyleItemString']"].join(" | ");
583
- engine.appendAutocompletePropertyValues("__shortcut", unionType, `(${unionType})[]`);
584
- },
585
- async transformStyleItems(styleItems) {
586
- const result = [];
587
- for (const styleItem of styleItems) {
588
- if (typeof styleItem === "string") {
589
- result.push(...await engine.shortcuts.resolver.resolve(styleItem));
590
- continue;
591
- }
592
- result.push(styleItem);
593
- }
594
- return result;
595
- },
596
- async transformStyleDefinitions(styleDefinitions) {
597
- const result = [];
598
- for (const styleDefinition of styleDefinitions) {
599
- if ("__shortcut" in styleDefinition) {
600
- const { __shortcut, ...rest } = styleDefinition;
601
- const applied = [];
602
- for (const shortcut of __shortcut == null ? [] : [__shortcut].flat(1)) {
603
- const resolved = (await engine.shortcuts.resolver.resolve(shortcut)).filter(isNotString);
604
- applied.push(...resolved);
605
- }
606
- result.push(...applied, rest);
607
- } else {
608
- result.push(styleDefinition);
609
- }
610
- }
611
- return result;
612
- }
613
- });
614
- }
615
- class ShortcutResolver extends AbstractResolver {
616
- async resolve(shortcut) {
617
- const resolved = await this._resolve(shortcut).catch((error) => {
618
- warn(`Failed to resolve shortcut "${shortcut}": ${error.message}`, error);
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
- if (typeof config === "string") {
636
- return config;
637
- } else if (Array.isArray(config)) {
638
- if (typeof config[0] === "string" && typeof config[1] !== "function") {
639
- return {
640
- type: "static",
641
- rule: {
642
- key: config[0],
643
- string: config[0],
644
- resolved: [config[1]].flat(1)
645
- },
646
- autocomplete: [config[0]]
647
- };
648
- }
649
- if (config[0] instanceof RegExp && typeof config[1] === "function") {
650
- const fn = config[1];
651
- return {
652
- type: "dynamic",
653
- rule: {
654
- key: config[0].source,
655
- stringPattern: config[0],
656
- createResolved: async (match) => [await fn(match)].flat(1)
657
- },
658
- autocomplete: config[2] != null ? [config[2]].flat(1) : []
659
- };
660
- }
661
- } else if (typeof config.shortcut === "string" && typeof config.value !== "function") {
662
- return {
663
- type: "static",
664
- rule: {
665
- key: config.shortcut,
666
- string: config.shortcut,
667
- resolved: [config.value].flat(1)
668
- },
669
- autocomplete: [config.shortcut]
670
- };
671
- } else if (config.shortcut instanceof RegExp && typeof config.value === "function") {
672
- const fn = config.value;
673
- return {
674
- type: "dynamic",
675
- rule: {
676
- key: config.shortcut.source,
677
- stringPattern: config.shortcut,
678
- createResolved: async (match) => [await fn(match)].flat(1)
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
- let resolveVariables;
688
- let rawVariables;
689
- let safeSet;
690
- return defineEnginePlugin({
691
- name: "core:variables",
692
- rawConfigConfigured(config) {
693
- resolveVariables = createResolveVariablesFn({
694
- pruneUnused: config.variables?.pruneUnused
695
- });
696
- rawVariables = config.variables?.variables ?? {};
697
- safeSet = new Set(config.variables?.safeList ?? []);
698
- },
699
- configureEngine(engine) {
700
- engine.variables = {
701
- store: /* @__PURE__ */ new Map(),
702
- add: (variables2) => {
703
- const list = resolveVariables(variables2);
704
- list.forEach((resolved) => {
705
- const { name, value, autocomplete: { asValueOf, asProperty } } = resolved;
706
- asValueOf.forEach((p) => {
707
- if (p !== "-")
708
- engine.appendAutocompleteCssPropertyValues(p, `var(${name})`);
709
- });
710
- if (asProperty)
711
- engine.appendAutocompleteExtraCssProperties(name);
712
- if (value != null) {
713
- const list2 = engine.variables.store.get(name) ?? [];
714
- list2.push(resolved);
715
- engine.variables.store.set(name, list2);
716
- }
717
- });
718
- engine.notifyPreflightUpdated();
719
- }
720
- };
721
- engine.variables.add(rawVariables);
722
- engine.addPreflight(async (engine2) => {
723
- const used = /* @__PURE__ */ new Set();
724
- engine2.store.atomicStyles.forEach(({ content: { value } }) => {
725
- value.flatMap(extractUsedVarNames).forEach((name) => used.add(normalizeVariableName(name)));
726
- });
727
- const usedVariables = Array.from(engine2.variables.store.values()).flat().filter(({ name, pruneUnused, value }) => (safeSet.has(name) || pruneUnused === false || used.has(name)) && value != null);
728
- const preflightDefinition = {};
729
- for (const { name, value, selector: _selector } of usedVariables) {
730
- const selector = await engine2.pluginHooks.transformSelectors(engine2.config.plugins, _selector);
731
- let current = preflightDefinition;
732
- selector.forEach((s) => {
733
- current[s] ||= {};
734
- current = current[s];
735
- });
736
- Object.assign(current, { [name]: value });
737
- }
738
- return preflightDefinition;
739
- });
740
- }
741
- });
742
- }
743
- function createResolveVariablesFn({
744
- pruneUnused: defaultPruneUnused = true
745
- } = {}) {
746
- function _resolveVariables(variables2, levels, result) {
747
- for (const [key, value] of Object.entries(variables2)) {
748
- if (key.startsWith("--")) {
749
- const isObject = typeof value === "object" && value !== null && !Array.isArray(value);
750
- const {
751
- value: varValue,
752
- autocomplete = {},
753
- pruneUnused = defaultPruneUnused
754
- } = isObject ? value : { value };
755
- result.push({
756
- name: key,
757
- value: varValue,
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
- const matched = input.match(VAR_NAME_RE);
778
- if (!matched)
779
- return [];
780
- return matched.map((match) => {
781
- const varNameMatch = match.match(/--[^,)]+/);
782
- return varNameMatch ? varNameMatch[0] : "";
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
- if (name.startsWith("--"))
787
- return name;
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
- return config;
700
+ return config;
793
701
  }
702
+ /* c8 ignore end */
794
703
  async function createEngine(config = {}) {
795
- const corePlugins = [
796
- important(),
797
- variables(),
798
- keyframes(),
799
- selectors(),
800
- shortcuts()
801
- ];
802
- const plugins = resolvePlugins([...corePlugins, ...config.plugins || []]);
803
- config.plugins = plugins;
804
- config = await hooks.configureRawConfig(
805
- config.plugins,
806
- config
807
- );
808
- hooks.rawConfigConfigured(
809
- resolvePlugins(config.plugins || []),
810
- config
811
- );
812
- let resolvedConfig = await resolveEngineConfig(config);
813
- resolvedConfig = await hooks.configureResolvedConfig(
814
- resolvedConfig.plugins,
815
- resolvedConfig
816
- );
817
- let engine = new Engine(resolvedConfig);
818
- engine = await hooks.configureEngine(
819
- engine.config.plugins,
820
- engine
821
- );
822
- return engine;
823
- }
824
- class Engine {
825
- config;
826
- pluginHooks = hooks;
827
- extract;
828
- store = {
829
- atomicStyleIds: /* @__PURE__ */ new Map(),
830
- atomicStyles: /* @__PURE__ */ new Map()
831
- };
832
- constructor(config) {
833
- this.config = config;
834
- this.extract = createExtractFn({
835
- defaultSelector: this.config.defaultSelector,
836
- transformSelectors: (selectors2) => hooks.transformSelectors(this.config.plugins, selectors2),
837
- transformStyleItems: (styleItems) => hooks.transformStyleItems(this.config.plugins, styleItems),
838
- transformStyleDefinitions: (styleDefinitions) => hooks.transformStyleDefinitions(this.config.plugins, styleDefinitions)
839
- });
840
- }
841
- notifyPreflightUpdated() {
842
- hooks.preflightUpdated(this.config.plugins);
843
- }
844
- notifyAtomicStyleAdded(atomicStyle) {
845
- hooks.atomicStyleAdded(this.config.plugins, atomicStyle);
846
- }
847
- notifyAutocompleteConfigUpdated() {
848
- hooks.autocompleteConfigUpdated(this.config.plugins);
849
- }
850
- appendAutocompleteSelectors(...selectors2) {
851
- appendAutocompleteSelectors(this.config, ...selectors2);
852
- this.notifyAutocompleteConfigUpdated();
853
- }
854
- appendAutocompleteStyleItemStrings(...styleItemStrings) {
855
- appendAutocompleteStyleItemStrings(this.config, ...styleItemStrings);
856
- this.notifyAutocompleteConfigUpdated();
857
- }
858
- appendAutocompleteExtraProperties(...properties) {
859
- appendAutocompleteExtraProperties(this.config, ...properties);
860
- this.notifyAutocompleteConfigUpdated();
861
- }
862
- appendAutocompleteExtraCssProperties(...properties) {
863
- appendAutocompleteExtraCssProperties(this.config, ...properties);
864
- this.notifyAutocompleteConfigUpdated();
865
- }
866
- appendAutocompletePropertyValues(property, ...tsTypes) {
867
- appendAutocompletePropertyValues(this.config, property, ...tsTypes);
868
- this.notifyAutocompleteConfigUpdated();
869
- }
870
- appendAutocompleteCssPropertyValues(property, ...values) {
871
- appendAutocompleteCssPropertyValues(this.config, property, ...values);
872
- this.notifyAutocompleteConfigUpdated();
873
- }
874
- addPreflight(preflight) {
875
- this.config.preflights.push(resolvePreflight(preflight));
876
- this.notifyPreflightUpdated();
877
- }
878
- async use(...itemList) {
879
- const {
880
- unknown,
881
- contents
882
- } = await resolveStyleItemList({
883
- itemList,
884
- transformStyleItems: (styleItems) => hooks.transformStyleItems(this.config.plugins, styleItems),
885
- extractStyleDefinition: (styleDefinition) => this.extract(styleDefinition)
886
- });
887
- const resolvedIds = [];
888
- contents.forEach((content) => {
889
- const id = getAtomicStyleId({
890
- content,
891
- prefix: this.config.prefix,
892
- stored: this.store.atomicStyleIds
893
- });
894
- resolvedIds.push(id);
895
- if (!this.store.atomicStyles.has(id)) {
896
- const atomicStyle = { id, content };
897
- this.store.atomicStyles.set(id, atomicStyle);
898
- this.notifyAtomicStyleAdded(atomicStyle);
899
- }
900
- });
901
- return [...unknown, ...resolvedIds];
902
- }
903
- async renderPreflights(isFormatted) {
904
- const lineEnd = isFormatted ? "\n" : "";
905
- return (await Promise.all(this.config.preflights.map(async (p) => {
906
- const result = await p(this, isFormatted);
907
- if (typeof result === "string")
908
- return result;
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
- const { selector } = style.content;
929
- const isDefaultSelector = selector.length === 1 && selector[0] === defaultSelector;
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
- return typeof preflight === "function" ? preflight : () => preflight;
823
+ return typeof preflight === "function" ? preflight : () => preflight;
934
824
  }
935
825
  async function resolveEngineConfig(config) {
936
- const {
937
- prefix = "",
938
- defaultSelector = `.${ATOMIC_STYLE_ID_PLACEHOLDER}`,
939
- plugins = [],
940
- preflights = []
941
- } = config;
942
- const resolvedConfig = {
943
- rawConfig: config,
944
- plugins: resolvePlugins(plugins),
945
- prefix,
946
- defaultSelector,
947
- preflights: [],
948
- autocomplete: {
949
- selectors: /* @__PURE__ */ new Set(),
950
- styleItemStrings: /* @__PURE__ */ new Set(),
951
- extraProperties: /* @__PURE__ */ new Set(),
952
- extraCssProperties: /* @__PURE__ */ new Set(),
953
- properties: /* @__PURE__ */ new Map(),
954
- cssProperties: /* @__PURE__ */ new Map()
955
- }
956
- };
957
- const resolvedPreflights = preflights.map(resolvePreflight);
958
- resolvedConfig.preflights.push(...resolvedPreflights);
959
- return resolvedConfig;
960
- }
961
- function getAtomicStyleId({
962
- content,
963
- prefix,
964
- stored
965
- }) {
966
- const key = serialize([content.selector, content.property, content.value]);
967
- const cached = stored.get(key);
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
- const map = /* @__PURE__ */ new Map();
977
- list.forEach((content) => {
978
- const key = serialize([content.selector, content.property]);
979
- map.delete(key);
980
- if (content.value == null)
981
- return;
982
- map.set(key, content);
983
- });
984
- return [...map.values()];
985
- }
986
- async function resolveStyleItemList({
987
- itemList,
988
- transformStyleItems,
989
- extractStyleDefinition
990
- }) {
991
- const unknown = /* @__PURE__ */ new Set();
992
- const list = [];
993
- for (const styleItem of await transformStyleItems(itemList)) {
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
- const { atomicStyles, isPreview, isFormatted, defaultSelector } = payload;
1006
- const blocks = /* @__PURE__ */ new Map();
1007
- Array.from(atomicStyles).sort((a, b) => {
1008
- const weightA = calcAtomicStyleRenderingWeight(a, defaultSelector);
1009
- const weightB = calcAtomicStyleRenderingWeight(b, defaultSelector);
1010
- return weightA - weightB;
1011
- }).forEach(({ id, content: { selector, property, value } }) => {
1012
- const isValidSelector = selector.some((s) => s.includes(ATOMIC_STYLE_ID_PLACEHOLDER));
1013
- if (isValidSelector === false || value == null)
1014
- return;
1015
- const renderObject = {
1016
- selector: isPreview ? selector : selector.map((s) => s.replace(ATOMIC_STYLE_ID_PLACEHOLDER_RE_GLOBAL, id)),
1017
- properties: value.map((v) => ({ property, value: v }))
1018
- };
1019
- let currentBlocks = blocks;
1020
- for (let i = 0; i < renderObject.selector.length; i++) {
1021
- const s = renderObject.selector[i];
1022
- const blockBody = currentBlocks.get(s) || { properties: [] };
1023
- const isLastSelector = i === renderObject.selector.length - 1;
1024
- if (isLastSelector)
1025
- blockBody.properties.push(...renderObject.properties);
1026
- else
1027
- blockBody.children ||= /* @__PURE__ */ new Map();
1028
- currentBlocks.set(s, blockBody);
1029
- if (isLastSelector === false)
1030
- currentBlocks = blockBody.children;
1031
- }
1032
- });
1033
- return renderCSSStyleBlocks(blocks, isFormatted);
1034
- }
1035
- async function _renderPreflightDefinition({
1036
- engine,
1037
- preflightDefinition,
1038
- blocks = /* @__PURE__ */ new Map()
1039
- }) {
1040
- for (const [selector, propertiesOrDefinition] of Object.entries(preflightDefinition)) {
1041
- if (propertiesOrDefinition == null)
1042
- continue;
1043
- const selectors2 = normalizeSelectors({
1044
- selectors: await hooks.transformSelectors(engine.config.plugins, [selector]),
1045
- defaultSelector: ""
1046
- }).filter(Boolean);
1047
- let currentBlocks = blocks;
1048
- let currentBlockBody = null;
1049
- selectors2.forEach((s, i) => {
1050
- const isLast = i === selectors2.length - 1;
1051
- currentBlocks.set(s, currentBlocks.get(s) || { properties: [] });
1052
- if (isLast) {
1053
- currentBlockBody = currentBlocks.get(s);
1054
- return;
1055
- }
1056
- currentBlocks = currentBlocks.get(s).children ||= /* @__PURE__ */ new Map();
1057
- });
1058
- for (const [k, v] of Object.entries(propertiesOrDefinition)) {
1059
- if (isPropertyValue(v)) {
1060
- const property = toKebab(k);
1061
- const normalizedValue = normalizeValue(v);
1062
- if (normalizedValue != null) {
1063
- normalizedValue.forEach((value) => currentBlockBody.properties.push({ property, value }));
1064
- }
1065
- } else {
1066
- currentBlockBody.children ||= /* @__PURE__ */ new Map();
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
- const { engine, preflightDefinition, isFormatted } = payload;
1080
- const blocks = await _renderPreflightDefinition({
1081
- engine,
1082
- preflightDefinition
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
- export { appendAutocompleteCssPropertyValues, appendAutocompleteExtraCssProperties, appendAutocompleteExtraProperties, appendAutocompletePropertyValues, appendAutocompleteSelectors, appendAutocompleteStyleItemStrings, createEngine, defineEngineConfig, defineEnginePlugin, renderCSSStyleBlocks, setWarnFn, warn };
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 };