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