@pikacss/core 0.0.43 → 0.0.44

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