@pikacss/core 0.0.43 → 0.0.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -60,6 +60,7 @@ function numberToChars(num) {
60
60
  }
61
61
  const UPPER_CASE = /[A-Z]/g;
62
62
  function toKebab(str) {
63
+ if (str.startsWith("--")) return str;
63
64
  return str.replace(UPPER_CASE, (c) => `-${c.toLowerCase()}`);
64
65
  }
65
66
  function isNotNullish(value) {
@@ -69,9 +70,9 @@ function isNotString(value) {
69
70
  return typeof value !== "string";
70
71
  }
71
72
  function isPropertyValue(v) {
72
- if (Array.isArray(v)) return v.length === 2 && isPropertyValue(v[0]) && Array.isArray(v[1]) && v[1].every(isPropertyValue);
73
+ if (Array.isArray(v)) return v.length === 2 && typeof v[0] === "string" && Array.isArray(v[1]) && v[1].every((i) => typeof i === "string");
73
74
  if (v == null) return true;
74
- if (typeof v === "string" || typeof v === "number") return true;
75
+ if (typeof v === "string") return true;
75
76
  return false;
76
77
  }
77
78
  function serialize(value) {
@@ -80,8 +81,8 @@ function serialize(value) {
80
81
  function addToSet(set, ...values) {
81
82
  values.forEach((value) => set.add(value));
82
83
  }
83
- function appendAutocompleteSelectors(config, ...selectors$1) {
84
- addToSet(config.autocomplete.selectors, ...selectors$1);
84
+ function appendAutocompleteSelectors(config, ...selectors) {
85
+ addToSet(config.autocomplete.selectors, ...selectors);
85
86
  }
86
87
  function appendAutocompleteStyleItemStrings(config, ...styleItemStrings) {
87
88
  addToSet(config.autocomplete.styleItemStrings, ...styleItemStrings);
@@ -130,12 +131,27 @@ const RE_SPLIT = /\s*,\s*/g;
130
131
  const DEFAULT_SELECTOR_PLACEHOLDER_RE_GLOBAL = /\$/g;
131
132
  const ATTRIBUTE_SUFFIX_MATCH = "$=";
132
133
  const ATTRIBUTE_SUFFIX_MATCH_RE_GLOBAL = /\$=/g;
133
- function normalizeSelectors({ selectors: selectors$1, defaultSelector }) {
134
- 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));
134
+ function normalizeSelectors({ selectors, defaultSelector }) {
135
+ return selectors.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));
135
136
  }
136
137
  function normalizeValue(value) {
137
138
  if (value == null) return value;
138
- return [...new Set([value].flat(2).map((v) => String(v).trim()))];
139
+ if (Array.isArray(value)) {
140
+ const [primary, fallbacks] = value;
141
+ const p = primary.trim();
142
+ const seen = new Set([p]);
143
+ const result = [];
144
+ for (const v of fallbacks) {
145
+ const s = v.trim();
146
+ if (!seen.has(s)) {
147
+ seen.add(s);
148
+ result.push(s);
149
+ }
150
+ }
151
+ result.push(p);
152
+ return result;
153
+ }
154
+ return [value.trim()];
139
155
  }
140
156
  async function extract({ styleDefinition, levels = [], result = [], defaultSelector, transformSelectors, transformStyleItems, transformStyleDefinitions }) {
141
157
  for (const definition of await transformStyleDefinitions([styleDefinition])) for (const [k, v] of Object.entries(definition)) if (isPropertyValue(v)) {
@@ -183,42 +199,48 @@ function createExtractFn(options) {
183
199
  //#region src/internal/plugin.ts
184
200
  async function execAsyncHook(plugins, hook, payload) {
185
201
  log.debug(`Executing async hook: ${hook}`);
202
+ let current = payload;
186
203
  for (const plugin of plugins) {
187
- if (plugin[hook] == null) continue;
204
+ const pluginRecord = plugin;
205
+ if (pluginRecord[hook] == null) continue;
188
206
  try {
189
207
  log.debug(` - Plugin "${plugin.name}" executing ${hook}`);
190
- const newPayload = await plugin[hook](payload);
191
- if (newPayload != null) payload = newPayload;
208
+ const hookFn = pluginRecord[hook];
209
+ const newPayload = await hookFn(current);
210
+ if (newPayload != null) current = newPayload;
192
211
  log.debug(` - Plugin "${plugin.name}" completed ${hook}`);
193
212
  } catch (error) {
194
- log.error(`Plugin "${plugin.name}" failed to execute hook "${hook}": ${error.message}`, error);
213
+ log.error(`Plugin "${plugin.name}" failed to execute hook "${hook}": ${error instanceof Error ? error.message : error}`, error);
195
214
  }
196
215
  }
197
216
  log.debug(`Async hook "${hook}" completed`);
198
- return payload;
217
+ return current;
199
218
  }
200
219
  function execSyncHook(plugins, hook, payload) {
201
220
  log.debug(`Executing sync hook: ${hook}`);
221
+ let current = payload;
202
222
  for (const plugin of plugins) {
203
- if (plugin[hook] == null) continue;
223
+ const pluginRecord = plugin;
224
+ if (pluginRecord[hook] == null) continue;
204
225
  try {
205
226
  log.debug(` - Plugin "${plugin.name}" executing ${hook}`);
206
- const newPayload = plugin[hook](payload);
207
- if (newPayload != null) payload = newPayload;
227
+ const hookFn = pluginRecord[hook];
228
+ const newPayload = hookFn(current);
229
+ if (newPayload != null) current = newPayload;
208
230
  log.debug(` - Plugin "${plugin.name}" completed ${hook}`);
209
231
  } catch (error) {
210
- log.error(`Plugin "${plugin.name}" failed to execute hook "${hook}": ${error.message}`, error);
232
+ log.error(`Plugin "${plugin.name}" failed to execute hook "${hook}": ${error instanceof Error ? error.message : error}`, error);
211
233
  }
212
234
  }
213
235
  log.debug(`Sync hook "${hook}" completed`);
214
- return payload;
236
+ return current;
215
237
  }
216
238
  const hooks = {
217
239
  configureRawConfig: (plugins, config) => execAsyncHook(plugins, "configureRawConfig", config),
218
240
  rawConfigConfigured: (plugins, config) => execSyncHook(plugins, "rawConfigConfigured", config),
219
241
  configureResolvedConfig: (plugins, resolvedConfig) => execAsyncHook(plugins, "configureResolvedConfig", resolvedConfig),
220
242
  configureEngine: (plugins, engine) => execAsyncHook(plugins, "configureEngine", engine),
221
- transformSelectors: (plugins, selectors$1) => execAsyncHook(plugins, "transformSelectors", selectors$1),
243
+ transformSelectors: (plugins, selectors) => execAsyncHook(plugins, "transformSelectors", selectors),
222
244
  transformStyleItems: (plugins, styleItems) => execAsyncHook(plugins, "transformStyleItems", styleItems),
223
245
  transformStyleDefinitions: (plugins, styleDefinitions) => execAsyncHook(plugins, "transformStyleDefinitions", styleDefinitions),
224
246
  preflightUpdated: (plugins) => execSyncHook(plugins, "preflightUpdated", void 0),
@@ -231,7 +253,7 @@ const orderMap = new Map([
231
253
  ["post", 2]
232
254
  ]);
233
255
  function resolvePlugins(plugins) {
234
- return plugins.sort((a, b) => orderMap.get(a.order) - orderMap.get(b.order));
256
+ return [...plugins].sort((a, b) => orderMap.get(a.order) - orderMap.get(b.order));
235
257
  }
236
258
  /* c8 ignore start */
237
259
  function defineEnginePlugin(plugin) {
@@ -241,10 +263,13 @@ function defineEnginePlugin(plugin) {
241
263
 
242
264
  //#endregion
243
265
  //#region src/internal/plugins/important.ts
266
+ function appendImportant(v) {
267
+ return v.endsWith("!important") ? v : `${v} !important`;
268
+ }
244
269
  function modifyPropertyValue(value) {
245
270
  if (value == null) return null;
246
- if (Array.isArray(value)) return [`${value[0]} !important`, value[1].map((i) => `${i} !important`)];
247
- return `${value} !important`;
271
+ if (Array.isArray(value)) return [appendImportant(value[0]), value[1].map((i) => appendImportant(i))];
272
+ return appendImportant(value);
248
273
  }
249
274
  function important() {
250
275
  let defaultValue;
@@ -298,20 +323,20 @@ function keyframes() {
298
323
  }
299
324
  };
300
325
  engine.keyframes.add(...configList);
301
- engine.addPreflight((engine$1) => {
326
+ engine.addPreflight((engine) => {
302
327
  const maybeUsedName = /* @__PURE__ */ new Set();
303
- engine$1.store.atomicStyles.forEach(({ content: { property, value } }) => {
304
- if (property === "animationName") {
328
+ engine.store.atomicStyles.forEach(({ content: { property, value } }) => {
329
+ if (property === "animation-name") {
305
330
  value.forEach((name) => maybeUsedName.add(name));
306
331
  return;
307
332
  }
308
- if (property === "animation") value.forEach((value$1) => {
309
- value$1.split(",").map((v) => v.trim()).forEach((animation) => {
333
+ if (property === "animation") value.forEach((value) => {
334
+ value.split(",").map((v) => v.trim()).forEach((animation) => {
310
335
  addToSet(maybeUsedName, ...animation.split(" "));
311
336
  });
312
337
  });
313
338
  });
314
- const maybeUsedKeyframes = Array.from(engine$1.keyframes.store.values()).filter(({ name, frames, pruneUnused }) => (pruneUnused === false || maybeUsedName.has(name)) && frames != null);
339
+ const maybeUsedKeyframes = Array.from(engine.keyframes.store.values()).filter(({ name, frames, pruneUnused }) => (pruneUnused === false || maybeUsedName.has(name)) && frames != null);
315
340
  const preflightDefinition = {};
316
341
  maybeUsedKeyframes.forEach(({ name, frames }) => {
317
342
  preflightDefinition[`@keyframes ${name}`] = Object.fromEntries(Object.entries(frames).map(([frame, properties]) => [frame, properties]));
@@ -330,12 +355,12 @@ function createResolveConfigFn({ pruneUnused: defaultPruneUnused = true } = {})
330
355
  pruneUnused: defaultPruneUnused
331
356
  };
332
357
  if (Array.isArray(config)) {
333
- const [name$1, frames$1, autocomplete$1 = [], pruneUnused$1 = defaultPruneUnused] = config;
358
+ const [name, frames, autocomplete = [], pruneUnused = defaultPruneUnused] = config;
334
359
  return {
335
- name: name$1,
336
- frames: frames$1,
337
- autocomplete: autocomplete$1,
338
- pruneUnused: pruneUnused$1
360
+ name,
361
+ frames,
362
+ autocomplete,
363
+ pruneUnused
339
364
  };
340
365
  }
341
366
  const { name, frames, autocomplete = [], pruneUnused = defaultPruneUnused } = config;
@@ -350,6 +375,10 @@ function createResolveConfigFn({ pruneUnused: defaultPruneUnused = true } = {})
350
375
 
351
376
  //#endregion
352
377
  //#region src/internal/resolver.ts
378
+ function stripGlobalFlag(re) {
379
+ if (!re.global) return re;
380
+ return new RegExp(re.source, re.flags.replace("g", ""));
381
+ }
353
382
  var AbstractResolver = class {
354
383
  _resolvedResultsMap = /* @__PURE__ */ new Map();
355
384
  staticRulesMap = /* @__PURE__ */ new Map();
@@ -389,7 +418,10 @@ var AbstractResolver = class {
389
418
  return this;
390
419
  }
391
420
  log.debug(`Removing dynamic rule: ${key}`);
392
- const matchedResolvedStringList = Array.from(this._resolvedResultsMap.keys()).filter((string) => rule.stringPattern.test(string));
421
+ const matchedResolvedStringList = Array.from(this._resolvedResultsMap.keys()).filter((string) => {
422
+ rule.stringPattern.lastIndex = 0;
423
+ return rule.stringPattern.test(string);
424
+ });
393
425
  this.dynamicRulesMap.delete(key);
394
426
  matchedResolvedStringList.forEach((string) => this._resolvedResultsMap.delete(string));
395
427
  log.debug(` - Cleared ${matchedResolvedStringList.length} cached results`);
@@ -412,7 +444,8 @@ var AbstractResolver = class {
412
444
  let dynamicRule;
413
445
  let matched;
414
446
  for (const rule of this.dynamicRulesMap.values()) {
415
- matched = string.match(rule.stringPattern);
447
+ rule.stringPattern.lastIndex = 0;
448
+ matched = rule.stringPattern.exec(string);
416
449
  if (matched != null) {
417
450
  dynamicRule = rule;
418
451
  break;
@@ -436,60 +469,26 @@ var AbstractResolver = class {
436
469
  this._resolvedResultsMap.set(string, { value: resolved });
437
470
  }
438
471
  };
439
-
440
- //#endregion
441
- //#region src/internal/plugins/selectors.ts
442
- function selectors() {
443
- let engine;
444
- let configList;
445
- return defineEnginePlugin({
446
- name: "core:selectors",
447
- rawConfigConfigured(config) {
448
- configList = config.selectors?.selectors ?? [];
449
- },
450
- configureEngine(_engine) {
451
- engine = _engine;
452
- engine.selectors = {
453
- resolver: new SelectorResolver(),
454
- add: (...list) => {
455
- list.forEach((config) => {
456
- const resolved = resolveSelectorConfig(config);
457
- if (resolved == null) return;
458
- if (typeof resolved === "string") {
459
- engine.appendAutocompleteSelectors(resolved);
460
- return;
461
- }
462
- if (resolved.type === "static") engine.selectors.resolver.addStaticRule(resolved.rule);
463
- else if (resolved.type === "dynamic") engine.selectors.resolver.addDynamicRule(resolved.rule);
464
- engine.appendAutocompleteSelectors(...resolved.autocomplete);
465
- });
466
- }
467
- };
468
- engine.selectors.add(...configList);
469
- engine.selectors.resolver.onResolved = (string, type) => {
470
- if (type === "dynamic") engine.appendAutocompleteSelectors(string);
471
- };
472
- },
473
- async transformSelectors(selectors$1) {
474
- const result = [];
475
- for (const selector of selectors$1) result.push(...await engine.selectors.resolver.resolve(selector));
476
- return result;
472
+ var RecursiveResolver = class extends AbstractResolver {
473
+ async resolve(string, _visited) {
474
+ const visited = _visited ?? /* @__PURE__ */ new Set();
475
+ if (visited.has(string)) {
476
+ log.warn(`Circular reference detected for "${string}", returning as-is`);
477
+ return [string];
477
478
  }
478
- });
479
- }
480
- var SelectorResolver = class extends AbstractResolver {
481
- async resolve(selector) {
482
- const resolved = await this._resolve(selector).catch((error) => {
483
- log.warn(`Failed to resolve selector "${selector}": ${error.message}`, error);
479
+ visited.add(string);
480
+ const resolved = await this._resolve(string).catch((error) => {
481
+ log.warn(`Failed to resolve "${string}": ${error.message}`, error);
484
482
  });
485
- if (resolved == null) return [selector];
483
+ if (resolved == null) return [string];
486
484
  const result = [];
487
- for (const s of resolved.value) result.push(...await this.resolve(s));
488
- this._setResolvedResult(selector, result);
485
+ for (const partial of resolved.value) if (typeof partial === "string") result.push(...await this.resolve(partial, new Set(visited)));
486
+ else result.push(partial);
487
+ this._setResolvedResult(string, result);
489
488
  return result;
490
489
  }
491
490
  };
492
- function resolveSelectorConfig(config) {
491
+ function resolveRuleConfig(config, keyName) {
493
492
  if (typeof config === "string") return config;
494
493
  if (Array.isArray(config)) {
495
494
  if (typeof config[0] === "string" && typeof config[1] !== "function") return {
@@ -507,7 +506,7 @@ function resolveSelectorConfig(config) {
507
506
  type: "dynamic",
508
507
  rule: {
509
508
  key: config[0].source,
510
- stringPattern: config[0],
509
+ stringPattern: stripGlobalFlag(config[0]),
511
510
  createResolved: async (match) => [await fn(match)].flat(1)
512
511
  },
513
512
  autocomplete: config[2] != null ? [config[2]].flat(1) : []
@@ -515,22 +514,24 @@ function resolveSelectorConfig(config) {
515
514
  }
516
515
  return;
517
516
  }
518
- if (typeof config.selector === "string" && typeof config.value !== "function") return {
517
+ if (typeof config !== "object" || config === null) return;
518
+ const configKey = config[keyName];
519
+ if (typeof configKey === "string" && typeof config.value !== "function") return {
519
520
  type: "static",
520
521
  rule: {
521
- key: config.selector,
522
- string: config.selector,
522
+ key: configKey,
523
+ string: configKey,
523
524
  resolved: [config.value].flat(1)
524
525
  },
525
- autocomplete: [config.selector]
526
+ autocomplete: [configKey]
526
527
  };
527
- if (config.selector instanceof RegExp && typeof config.value === "function") {
528
+ if (configKey instanceof RegExp && typeof config.value === "function") {
528
529
  const fn = config.value;
529
530
  return {
530
531
  type: "dynamic",
531
532
  rule: {
532
- key: config.selector.source,
533
- stringPattern: config.selector,
533
+ key: configKey.source,
534
+ stringPattern: stripGlobalFlag(configKey),
534
535
  createResolved: async (match) => [await fn(match)].flat(1)
535
536
  },
536
537
  autocomplete: "autocomplete" in config && config.autocomplete != null ? [config.autocomplete].flat(1) : []
@@ -538,6 +539,51 @@ function resolveSelectorConfig(config) {
538
539
  }
539
540
  }
540
541
 
542
+ //#endregion
543
+ //#region src/internal/plugins/selectors.ts
544
+ function selectors() {
545
+ let engine;
546
+ let configList;
547
+ return defineEnginePlugin({
548
+ name: "core:selectors",
549
+ rawConfigConfigured(config) {
550
+ configList = config.selectors?.selectors ?? [];
551
+ },
552
+ configureEngine(_engine) {
553
+ engine = _engine;
554
+ engine.selectors = {
555
+ resolver: new SelectorResolver(),
556
+ add: (...list) => {
557
+ list.forEach((config) => {
558
+ const resolved = resolveSelectorConfig(config);
559
+ if (resolved == null) return;
560
+ if (typeof resolved === "string") {
561
+ engine.appendAutocompleteSelectors(resolved);
562
+ return;
563
+ }
564
+ if (resolved.type === "static") engine.selectors.resolver.addStaticRule(resolved.rule);
565
+ else if (resolved.type === "dynamic") engine.selectors.resolver.addDynamicRule(resolved.rule);
566
+ engine.appendAutocompleteSelectors(...resolved.autocomplete);
567
+ });
568
+ }
569
+ };
570
+ engine.selectors.add(...configList);
571
+ engine.selectors.resolver.onResolved = (string, type) => {
572
+ if (type === "dynamic") engine.appendAutocompleteSelectors(string);
573
+ };
574
+ },
575
+ async transformSelectors(selectors) {
576
+ const result = [];
577
+ for (const selector of selectors) result.push(...await engine.selectors.resolver.resolve(selector));
578
+ return result;
579
+ }
580
+ });
581
+ }
582
+ var SelectorResolver = class extends RecursiveResolver {};
583
+ function resolveSelectorConfig(config) {
584
+ return resolveRuleConfig(config, "selector");
585
+ }
586
+
541
587
  //#endregion
542
588
  //#region src/internal/plugins/shortcuts.ts
543
589
  function shortcuts() {
@@ -600,64 +646,9 @@ function shortcuts() {
600
646
  }
601
647
  });
602
648
  }
603
- var ShortcutResolver = class extends AbstractResolver {
604
- async resolve(shortcut) {
605
- const resolved = await this._resolve(shortcut).catch((error) => {
606
- log.warn(`Failed to resolve shortcut "${shortcut}": ${error.message}`, error);
607
- });
608
- if (resolved == null) return [shortcut];
609
- const result = [];
610
- for (const partial of resolved.value) if (typeof partial === "string") result.push(...await this.resolve(partial));
611
- else result.push(partial);
612
- this._setResolvedResult(shortcut, result);
613
- return result;
614
- }
615
- };
649
+ var ShortcutResolver = class extends RecursiveResolver {};
616
650
  function resolveShortcutConfig(config) {
617
- if (typeof config === "string") return config;
618
- else if (Array.isArray(config)) {
619
- if (typeof config[0] === "string" && typeof config[1] !== "function") return {
620
- type: "static",
621
- rule: {
622
- key: config[0],
623
- string: config[0],
624
- resolved: [config[1]].flat(1)
625
- },
626
- autocomplete: [config[0]]
627
- };
628
- if (config[0] instanceof RegExp && typeof config[1] === "function") {
629
- const fn = config[1];
630
- return {
631
- type: "dynamic",
632
- rule: {
633
- key: config[0].source,
634
- stringPattern: config[0],
635
- createResolved: async (match) => [await fn(match)].flat(1)
636
- },
637
- autocomplete: config[2] != null ? [config[2]].flat(1) : []
638
- };
639
- }
640
- } else if (typeof config.shortcut === "string" && typeof config.value !== "function") return {
641
- type: "static",
642
- rule: {
643
- key: config.shortcut,
644
- string: config.shortcut,
645
- resolved: [config.value].flat(1)
646
- },
647
- autocomplete: [config.shortcut]
648
- };
649
- else if (config.shortcut instanceof RegExp && typeof config.value === "function") {
650
- const fn = config.value;
651
- return {
652
- type: "dynamic",
653
- rule: {
654
- key: config.shortcut.source,
655
- stringPattern: config.shortcut,
656
- createResolved: async (match) => [await fn(match)].flat(1)
657
- },
658
- autocomplete: "autocomplete" in config && config.autocomplete != null ? [config.autocomplete].flat(1) : []
659
- };
660
- }
651
+ return resolveRuleConfig(config, "shortcut");
661
652
  }
662
653
 
663
654
  //#endregion
@@ -676,8 +667,8 @@ function variables() {
676
667
  configureEngine(engine) {
677
668
  engine.variables = {
678
669
  store: /* @__PURE__ */ new Map(),
679
- add: (variables$1) => {
680
- resolveVariables(variables$1).forEach((resolved) => {
670
+ add: (variables) => {
671
+ resolveVariables(variables).forEach((resolved) => {
681
672
  const { name, value, autocomplete: { asValueOf, asProperty } } = resolved;
682
673
  asValueOf.forEach((p) => {
683
674
  if (p !== "-") engine.appendAutocompleteCssPropertyValues(p, `var(${name})`);
@@ -692,16 +683,16 @@ function variables() {
692
683
  engine.notifyPreflightUpdated();
693
684
  }
694
685
  };
695
- rawVariables.forEach((variables$1) => engine.variables.add(variables$1));
696
- engine.addPreflight(async (engine$1) => {
686
+ rawVariables.forEach((variables) => engine.variables.add(variables));
687
+ engine.addPreflight(async (engine) => {
697
688
  const used = /* @__PURE__ */ new Set();
698
- engine$1.store.atomicStyles.forEach(({ content: { value } }) => {
689
+ engine.store.atomicStyles.forEach(({ content: { value } }) => {
699
690
  value.flatMap(extractUsedVarNames).forEach((name) => used.add(normalizeVariableName(name)));
700
691
  });
701
- const usedVariables = Array.from(engine$1.variables.store.values()).flat().filter(({ name, pruneUnused, value }) => (safeSet.has(name) || pruneUnused === false || used.has(name)) && value != null);
692
+ const usedVariables = Array.from(engine.variables.store.values()).flat().filter(({ name, pruneUnused, value }) => (safeSet.has(name) || pruneUnused === false || used.has(name)) && value != null);
702
693
  const preflightDefinition = {};
703
694
  for (const { name, value, selector: _selector } of usedVariables) {
704
- const selector = await engine$1.pluginHooks.transformSelectors(engine$1.config.plugins, _selector);
695
+ const selector = await engine.pluginHooks.transformSelectors(engine.config.plugins, _selector);
705
696
  let current = preflightDefinition;
706
697
  selector.forEach((s) => {
707
698
  current[s] ||= {};
@@ -715,8 +706,8 @@ function variables() {
715
706
  });
716
707
  }
717
708
  function createResolveVariablesFn({ pruneUnused: defaultPruneUnused = true } = {}) {
718
- function _resolveVariables(variables$1, levels, result) {
719
- for (const [key, value] of Object.entries(variables$1)) if (key.startsWith("--")) {
709
+ function _resolveVariables(variables, levels, result) {
710
+ for (const [key, value] of Object.entries(variables)) if (key.startsWith("--")) {
720
711
  const { value: varValue, autocomplete = {}, pruneUnused = defaultPruneUnused } = typeof value === "object" && value !== null && !Array.isArray(value) ? value : { value };
721
712
  result.push({
722
713
  name: key,
@@ -731,18 +722,13 @@ function createResolveVariablesFn({ pruneUnused: defaultPruneUnused = true } = {
731
722
  } else _resolveVariables(value, [...levels, key], result);
732
723
  return result;
733
724
  }
734
- return function resolveVariables(variables$1) {
735
- return _resolveVariables(variables$1, [], []);
725
+ return function resolveVariables(variables) {
726
+ return _resolveVariables(variables, [], []);
736
727
  };
737
728
  }
738
729
  const VAR_NAME_RE = /var\((--[\w-]+)/g;
739
730
  function extractUsedVarNames(input) {
740
- const matched = input.match(VAR_NAME_RE);
741
- if (!matched) return [];
742
- return matched.map((match) => {
743
- const varNameMatch = match.match(/--[^,)]+/);
744
- return varNameMatch ? varNameMatch[0] : "";
745
- }).filter(Boolean);
731
+ return Array.from(input.matchAll(VAR_NAME_RE), (m) => m[1]);
746
732
  }
747
733
  function normalizeVariableName(name) {
748
734
  if (name.startsWith("--")) return name;
@@ -768,10 +754,13 @@ async function createEngine(config = {}) {
768
754
  ];
769
755
  log.debug("Core plugins loaded:", corePlugins.length);
770
756
  const plugins = resolvePlugins([...corePlugins, ...config.plugins || []]);
771
- config.plugins = plugins;
757
+ config = {
758
+ ...config,
759
+ plugins
760
+ };
772
761
  log.debug(`Total plugins resolved: ${plugins.length}`);
773
762
  config = await hooks.configureRawConfig(config.plugins, config);
774
- hooks.rawConfigConfigured(resolvePlugins(config.plugins || []), config);
763
+ hooks.rawConfigConfigured(resolvePlugins(config.plugins ?? []), config);
775
764
  let resolvedConfig = await resolveEngineConfig(config);
776
765
  log.debug("Engine config resolved with prefix:", resolvedConfig.prefix);
777
766
  resolvedConfig = await hooks.configureResolvedConfig(resolvedConfig.plugins, resolvedConfig);
@@ -795,7 +784,7 @@ var Engine = class {
795
784
  this.config = config;
796
785
  this.extract = createExtractFn({
797
786
  defaultSelector: this.config.defaultSelector,
798
- transformSelectors: (selectors$1) => hooks.transformSelectors(this.config.plugins, selectors$1),
787
+ transformSelectors: (selectors) => hooks.transformSelectors(this.config.plugins, selectors),
799
788
  transformStyleItems: (styleItems) => hooks.transformStyleItems(this.config.plugins, styleItems),
800
789
  transformStyleDefinitions: (styleDefinitions) => hooks.transformStyleDefinitions(this.config.plugins, styleDefinitions)
801
790
  });
@@ -809,8 +798,8 @@ var Engine = class {
809
798
  notifyAutocompleteConfigUpdated() {
810
799
  hooks.autocompleteConfigUpdated(this.config.plugins);
811
800
  }
812
- appendAutocompleteSelectors(...selectors$1) {
813
- appendAutocompleteSelectors(this.config, ...selectors$1);
801
+ appendAutocompleteSelectors(...selectors) {
802
+ appendAutocompleteSelectors(this.config, ...selectors);
814
803
  this.notifyAutocompleteConfigUpdated();
815
804
  }
816
805
  appendAutocompleteStyleItemStrings(...styleItemStrings) {
@@ -934,7 +923,7 @@ function sortLayerNames(layers) {
934
923
  function isWithLayer(p) {
935
924
  if (typeof p !== "object" || p === null) return false;
936
925
  const record = p;
937
- return typeof record.layer === "string" && "preflight" in record;
926
+ return typeof record.layer === "string" && record.preflight !== void 0;
938
927
  }
939
928
  function resolvePreflight(preflight) {
940
929
  if (isWithLayer(preflight)) {
@@ -1107,14 +1096,15 @@ function renderAtomicStyles(payload) {
1107
1096
  async function _renderPreflightDefinition({ engine, preflightDefinition, blocks = /* @__PURE__ */ new Map() }) {
1108
1097
  for (const [selector, propertiesOrDefinition] of Object.entries(preflightDefinition)) {
1109
1098
  if (propertiesOrDefinition == null) continue;
1110
- const selectors$1 = normalizeSelectors({
1099
+ const selectors = normalizeSelectors({
1111
1100
  selectors: await hooks.transformSelectors(engine.config.plugins, [selector]),
1112
1101
  defaultSelector: ""
1113
1102
  }).filter(Boolean);
1103
+ if (selectors.length === 0) continue;
1114
1104
  let currentBlocks = blocks;
1115
1105
  let currentBlockBody = null;
1116
- selectors$1.forEach((s, i) => {
1117
- const isLast = i === selectors$1.length - 1;
1106
+ selectors.forEach((s, i) => {
1107
+ const isLast = i === selectors.length - 1;
1118
1108
  currentBlocks.set(s, currentBlocks.get(s) || { properties: [] });
1119
1109
  if (isLast) {
1120
1110
  currentBlockBody = currentBlocks.get(s);
@@ -1160,8 +1150,8 @@ function defineStyleDefinition(styleDefinition) {
1160
1150
  function definePreflight(preflight) {
1161
1151
  return preflight;
1162
1152
  }
1163
- function defineKeyframes(keyframes$1) {
1164
- return keyframes$1;
1153
+ function defineKeyframes(keyframes) {
1154
+ return keyframes;
1165
1155
  }
1166
1156
  function defineSelector(selector) {
1167
1157
  return selector;
@@ -1169,8 +1159,8 @@ function defineSelector(selector) {
1169
1159
  function defineShortcut(shortcut) {
1170
1160
  return shortcut;
1171
1161
  }
1172
- function defineVariables(variables$1) {
1173
- return variables$1;
1162
+ function defineVariables(variables) {
1163
+ return variables;
1174
1164
  }
1175
1165
  /* c8 ignore end */
1176
1166
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pikacss/core",
3
3
  "type": "module",
4
- "version": "0.0.43",
4
+ "version": "0.0.45",
5
5
  "author": "DevilTea <ch19980814@gmail.com>",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -23,14 +23,9 @@
23
23
  "import": {
24
24
  "types": "./dist/index.d.mts",
25
25
  "default": "./dist/index.mjs"
26
- },
27
- "require": {
28
- "types": "./dist/index.d.cts",
29
- "default": "./dist/index.cjs"
30
26
  }
31
27
  }
32
28
  },
33
- "main": "dist/index.cjs",
34
29
  "module": "dist/index.mjs",
35
30
  "types": "dist/index.d.mts",
36
31
  "publishConfig": {
@@ -39,10 +34,8 @@
39
34
  "files": [
40
35
  "dist"
41
36
  ],
42
- "dependencies": {
43
- "csstype": "^3.2.3"
44
- },
45
37
  "scripts": {
38
+ "generate:csstype": "tsx ./scripts/generate-csstype.ts",
46
39
  "build": "tsdown && pnpm exec publint",
47
40
  "build:watch": "tsdown --watch",
48
41
  "typecheck": "pnpm typecheck:package && pnpm typecheck:test",