@pikacss/core 0.0.12 → 0.0.14

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
@@ -224,10 +224,10 @@ function execSyncHook(plugins, hook, payload) {
224
224
  return payload;
225
225
  }
226
226
  const hooks = {
227
- config: (plugins, config) => execAsyncHook(plugins, "config", config),
228
- beforeConfigResolving: (plugins, config) => execSyncHook(plugins, "beforeConfigResolving", config),
229
- configResolved: (plugins, resolvedConfig) => execAsyncHook(plugins, "configResolved", resolvedConfig),
230
- engineInitialized: (plugins, engine) => execSyncHook(plugins, "engineInitialized", engine),
227
+ configureRawConfig: (plugins, config) => execAsyncHook(plugins, "configureRawConfig", config),
228
+ rawConfigConfigured: (plugins, config) => execSyncHook(plugins, "rawConfigConfigured", config),
229
+ configureResolvedConfig: (plugins, resolvedConfig) => execAsyncHook(plugins, "configureResolvedConfig", resolvedConfig),
230
+ configureEngine: (plugins, engine) => execAsyncHook(plugins, "configureEngine", engine),
231
231
  transformSelectors: (plugins, selectors) => execAsyncHook(plugins, "transformSelectors", selectors),
232
232
  transformStyleItems: (plugins, styleItems) => execAsyncHook(plugins, "transformStyleItems", styleItems),
233
233
  transformStyleDefinitions: (plugins, styleDefinitions) => execAsyncHook(plugins, "transformStyleDefinitions", styleDefinitions),
@@ -243,26 +243,26 @@ const orderMap = /* @__PURE__ */ new Map([
243
243
  function resolvePlugins(plugins) {
244
244
  return plugins.sort((a, b) => orderMap.get(a.order) - orderMap.get(b.order));
245
245
  }
246
- function defineEnginePlugin$1(plugin) {
246
+ function defineEnginePlugin(plugin) {
247
247
  return plugin;
248
248
  }
249
249
 
250
250
  function important() {
251
- let _default;
252
- return defineEnginePlugin$1({
251
+ let defaultValue;
252
+ return defineEnginePlugin({
253
253
  name: "core:important",
254
- beforeConfigResolving(config) {
255
- _default = config.important?.default ?? false;
254
+ rawConfigConfigured(config) {
255
+ defaultValue = config.important?.default ?? false;
256
256
  },
257
- configResolved(resolvedConfig) {
258
- appendAutocompleteExtraProperties(resolvedConfig, "__important");
259
- appendAutocompletePropertyValues(resolvedConfig, "__important", "boolean");
257
+ configureEngine(engine) {
258
+ engine.appendAutocompleteExtraProperties("__important");
259
+ engine.appendAutocompletePropertyValues("__important", "boolean");
260
260
  },
261
261
  transformStyleDefinitions(styleDefinitions) {
262
262
  return styleDefinitions.map((styleDefinition) => {
263
263
  const { __important, ...rest } = styleDefinition;
264
- const theImportant = __important;
265
- const important2 = theImportant == null ? _default : theImportant;
264
+ const value = __important;
265
+ const important2 = value == null ? defaultValue : value;
266
266
  if (important2 === false)
267
267
  return rest;
268
268
  return Object.fromEntries(
@@ -278,47 +278,43 @@ function important() {
278
278
  });
279
279
  }
280
280
 
281
- function resolveKeyframesConfig(config) {
282
- if (typeof config === "string")
283
- return { name: config, frames: null, autocomplete: [] };
284
- if (Array.isArray(config)) {
285
- const [name2, frames2, autocomplete2 = []] = config;
286
- return { name: name2, frames: frames2, autocomplete: autocomplete2 };
287
- }
288
- const { name, frames, autocomplete = [] } = config;
289
- return { name, frames, autocomplete };
290
- }
291
281
  function keyframes() {
292
- const allKeyframes = /* @__PURE__ */ new Map();
282
+ let resolveKeyframesConfig;
293
283
  let configList;
294
- return defineEnginePlugin$1({
284
+ return defineEnginePlugin({
295
285
  name: "core:keyframes",
296
- beforeConfigResolving(config) {
297
- configList = config.keyframes ?? [];
286
+ rawConfigConfigured(config) {
287
+ resolveKeyframesConfig = createResolveConfigFn$1({
288
+ pruneUnused: config.keyframes?.pruneUnused
289
+ });
290
+ configList = config.keyframes?.keyframes ?? [];
298
291
  },
299
- configResolved(resolvedConfig) {
300
- const autocomplete = {
301
- animationName: [],
302
- animation: []
303
- };
304
- configList.forEach((config) => {
305
- const { name, frames, autocomplete: autocompleteAnimation } = resolveKeyframesConfig(config);
306
- if (frames != null) {
307
- allKeyframes.set(name, frames);
292
+ configureEngine(engine) {
293
+ engine.keyframes = {
294
+ store: /* @__PURE__ */ new Map(),
295
+ add: (...list) => {
296
+ list.forEach((config) => {
297
+ const resolved = resolveKeyframesConfig(config);
298
+ const { name, frames, autocomplete: autocompleteAnimation } = resolved;
299
+ if (frames != null)
300
+ engine.keyframes.store.set(name, resolved);
301
+ engine.appendAutocompleteCssPropertyValues("animationName", name);
302
+ engine.appendAutocompleteCssPropertyValues("animation", `${name} `);
303
+ if (autocompleteAnimation != null)
304
+ engine.appendAutocompleteCssPropertyValues("animation", ...autocompleteAnimation);
305
+ });
306
+ engine.notifyPreflightUpdated();
308
307
  }
309
- autocomplete.animationName.push(name);
310
- autocomplete.animation.push(`${name} `);
311
- if (autocompleteAnimation != null)
312
- autocomplete.animation.push(...autocompleteAnimation);
313
- });
314
- appendAutocompleteCssPropertyValues(resolvedConfig, "animationName", ...autocomplete.animationName);
315
- appendAutocompleteCssPropertyValues(resolvedConfig, "animation", ...autocomplete.animation);
316
- resolvedConfig.preflights.push((engine, isFormatted) => {
308
+ };
309
+ engine.keyframes.add(...configList);
310
+ engine.addPreflight((engine2, isFormatted) => {
317
311
  const used = /* @__PURE__ */ new Set();
318
- engine.store.atomicStyles.forEach(({ content: { property, value } }) => {
312
+ engine2.store.atomicStyles.forEach(({ content: { property, value } }) => {
319
313
  if (property === "animationName") {
320
314
  value.forEach((name) => used.add(name));
321
- } else if (property === "animation") {
315
+ return;
316
+ }
317
+ if (property === "animation") {
322
318
  value.forEach((value2) => {
323
319
  const animations = value2.split(",").map((v) => v.trim());
324
320
  animations.forEach((animation) => {
@@ -330,7 +326,7 @@ function keyframes() {
330
326
  }
331
327
  });
332
328
  return renderCSSStyleBlocks(
333
- new Map(Array.from(allKeyframes.entries()).filter(([name]) => used.has(name)).map(([name, frames]) => [
329
+ new Map(Array.from(engine2.keyframes.store.entries()).filter(([name]) => used.has(name)).map(([name, frames]) => [
334
330
  `@keyframes ${name}`,
335
331
  {
336
332
  properties: [],
@@ -352,6 +348,20 @@ function keyframes() {
352
348
  }
353
349
  });
354
350
  }
351
+ function createResolveConfigFn$1({
352
+ pruneUnused: defaultPruneUnused = true
353
+ } = {}) {
354
+ return function resolveKeyframesConfig(config) {
355
+ if (typeof config === "string")
356
+ return { name: config, frames: null, autocomplete: [], pruneUnused: defaultPruneUnused };
357
+ if (Array.isArray(config)) {
358
+ const [name2, frames2, autocomplete2 = [], pruneUnused2 = defaultPruneUnused] = config;
359
+ return { name: name2, frames: frames2, autocomplete: autocomplete2, pruneUnused: pruneUnused2 };
360
+ }
361
+ const { name, frames, autocomplete = [], pruneUnused = defaultPruneUnused } = config;
362
+ return { name, frames, autocomplete, pruneUnused };
363
+ };
364
+ }
355
365
 
356
366
  class AbstractResolver {
357
367
  _resolvedResultsMap = /* @__PURE__ */ new Map();
@@ -428,6 +438,51 @@ class AbstractResolver {
428
438
  }
429
439
  }
430
440
 
441
+ function selectors() {
442
+ let engine;
443
+ let configList;
444
+ return defineEnginePlugin({
445
+ name: "core:selectors",
446
+ rawConfigConfigured(config) {
447
+ configList = config.selectors?.selectors ?? [];
448
+ },
449
+ configureEngine(_engine) {
450
+ engine = _engine;
451
+ engine.selectors = {
452
+ resolver: new SelectorResolver(),
453
+ add: (...list) => {
454
+ list.forEach((config) => {
455
+ const resolved = resolveSelectorConfig(config);
456
+ if (resolved == null)
457
+ return;
458
+ if (typeof resolved === "string") {
459
+ engine.appendAutocompleteSelectors(resolved);
460
+ return;
461
+ }
462
+ if (resolved.type === "static")
463
+ engine.selectors.resolver.addStaticRule(resolved.rule);
464
+ else if (resolved.type === "dynamic")
465
+ engine.selectors.resolver.addDynamicRule(resolved.rule);
466
+ engine.appendAutocompleteSelectors(...resolved.autocomplete);
467
+ });
468
+ }
469
+ };
470
+ engine.selectors.add(...configList);
471
+ engine.selectors.resolver.onResolved = (string, type) => {
472
+ if (type === "dynamic") {
473
+ engine.appendAutocompleteSelectors(string);
474
+ }
475
+ };
476
+ },
477
+ async transformSelectors(selectors2) {
478
+ const result = [];
479
+ for (const selector of selectors2) {
480
+ result.push(...await engine.selectors.resolver.resolve(selector));
481
+ }
482
+ return result;
483
+ }
484
+ });
485
+ }
431
486
  class SelectorResolver extends AbstractResolver {
432
487
  async resolve(selector) {
433
488
  const resolved = await this._resolve(selector).catch((error) => {
@@ -498,47 +553,76 @@ function resolveSelectorConfig(config) {
498
553
  }
499
554
  return void 0;
500
555
  }
501
- function selectors() {
502
- const selectorResolver = new SelectorResolver();
556
+
557
+ function shortcuts() {
558
+ let engine;
503
559
  let configList;
504
- return defineEnginePlugin$1({
505
- name: "core:selectors",
506
- beforeConfigResolving(config) {
507
- configList = config.selectors ?? [];
560
+ return defineEnginePlugin({
561
+ name: "core:shortcuts",
562
+ rawConfigConfigured(config) {
563
+ configList = config.shortcuts?.shortcuts ?? [];
508
564
  },
509
- configResolved(resolvedConfig) {
510
- configList.forEach((config) => {
511
- const resolved = resolveSelectorConfig(config);
512
- if (resolved == null)
513
- return;
514
- if (typeof resolved === "string") {
515
- appendAutocompleteSelectors(resolvedConfig, resolved);
516
- return;
565
+ configureEngine(_engine) {
566
+ engine = _engine;
567
+ engine.shortcuts = {
568
+ resolver: new ShortcutResolver(),
569
+ add: (...list) => {
570
+ list.forEach((config) => {
571
+ const resolved = resolveShortcutConfig(config);
572
+ if (resolved == null)
573
+ return;
574
+ if (typeof resolved === "string") {
575
+ engine.appendAutocompleteStyleItemStrings(resolved);
576
+ return;
577
+ }
578
+ if (resolved.type === "static")
579
+ engine.shortcuts.resolver.addStaticRule(resolved.rule);
580
+ else if (resolved.type === "dynamic")
581
+ engine.shortcuts.resolver.addDynamicRule(resolved.rule);
582
+ engine.appendAutocompleteStyleItemStrings(...resolved.autocomplete);
583
+ });
517
584
  }
518
- if (resolved.type === "static")
519
- selectorResolver.addStaticRule(resolved.rule);
520
- else if (resolved.type === "dynamic")
521
- selectorResolver.addDynamicRule(resolved.rule);
522
- appendAutocompleteSelectors(resolvedConfig, ...resolved.autocomplete);
523
- });
524
- },
525
- engineInitialized(engine) {
526
- selectorResolver.onResolved = (string, type) => {
585
+ };
586
+ engine.shortcuts.add(...configList);
587
+ engine.shortcuts.resolver.onResolved = (string, type) => {
527
588
  if (type === "dynamic") {
528
- engine.appendAutocompleteSelectors(string);
589
+ engine.appendAutocompleteStyleItemStrings(string);
529
590
  }
530
591
  };
592
+ engine.appendAutocompleteExtraProperties("__shortcut");
593
+ const unionType = ["(string & {})", "Autocomplete['StyleItemString']"].join(" | ");
594
+ engine.appendAutocompletePropertyValues("__shortcut", unionType, `(${unionType})[]`);
531
595
  },
532
- async transformSelectors(selectors2) {
596
+ async transformStyleItems(styleItems) {
533
597
  const result = [];
534
- for (const selector of selectors2) {
535
- result.push(...await selectorResolver.resolve(selector));
598
+ for (const styleItem of styleItems) {
599
+ if (typeof styleItem === "string") {
600
+ result.push(...await engine.shortcuts.resolver.resolve(styleItem));
601
+ continue;
602
+ }
603
+ result.push(styleItem);
604
+ }
605
+ return result;
606
+ },
607
+ async transformStyleDefinitions(styleDefinitions) {
608
+ const result = [];
609
+ for (const styleDefinition of styleDefinitions) {
610
+ if ("__shortcut" in styleDefinition) {
611
+ const { __shortcut, ...rest } = styleDefinition;
612
+ const applied = [];
613
+ for (const shortcut of __shortcut == null ? [] : [__shortcut].flat(1)) {
614
+ const resolved = (await engine.shortcuts.resolver.resolve(shortcut)).filter(isNotString);
615
+ applied.push(...resolved);
616
+ }
617
+ result.push(...applied, rest);
618
+ } else {
619
+ result.push(styleDefinition);
620
+ }
536
621
  }
537
622
  return result;
538
623
  }
539
624
  });
540
625
  }
541
-
542
626
  class ShortcutResolver extends AbstractResolver {
543
627
  async resolve(shortcut) {
544
628
  const resolved = await this._resolve(shortcut).catch((error) => {
@@ -609,82 +693,70 @@ function resolveShortcutConfig(config) {
609
693
  }
610
694
  return void 0;
611
695
  }
612
- function shortcuts() {
613
- const shortcutResolver = new ShortcutResolver();
696
+
697
+ function variables() {
698
+ let resolveVariableConfig;
614
699
  let configList;
615
- return defineEnginePlugin$1({
616
- name: "core:shortcuts",
617
- beforeConfigResolving(config) {
618
- configList = config.shortcuts ?? [];
619
- },
620
- configResolved(resolvedConfig) {
621
- const autocompleteShortcuts = /* @__PURE__ */ new Set();
622
- configList.forEach((config) => {
623
- const resolved = resolveShortcutConfig(config);
624
- if (resolved == null)
625
- return;
626
- if (typeof resolved === "string") {
627
- addToSet(autocompleteShortcuts, resolved);
628
- return;
629
- }
630
- if (resolved.type === "static")
631
- shortcutResolver.addStaticRule(resolved.rule);
632
- else if (resolved.type === "dynamic")
633
- shortcutResolver.addDynamicRule(resolved.rule);
634
- addToSet(autocompleteShortcuts, ...resolved.autocomplete);
700
+ return defineEnginePlugin({
701
+ name: "core:variables",
702
+ rawConfigConfigured(config) {
703
+ resolveVariableConfig = createResolveConfigFn({
704
+ pruneUnused: config.variables?.pruneUnused
635
705
  });
636
- appendAutocompleteStyleItemStrings(resolvedConfig, ...autocompleteShortcuts);
637
- appendAutocompleteExtraProperties(resolvedConfig, "__shortcut");
638
- const unionType = ["(string & {})", "Autocomplete['StyleItemString']"].join(" | ");
639
- appendAutocompletePropertyValues(resolvedConfig, "__shortcut", unionType, `(${unionType})[]`);
706
+ configList = config.variables?.variables ?? [];
640
707
  },
641
- engineInitialized(engine) {
642
- shortcutResolver.onResolved = (string, type) => {
643
- if (type === "dynamic") {
644
- engine.appendAutocompleteStyleItemStrings(string);
708
+ configureEngine(engine) {
709
+ engine.variables = {
710
+ store: /* @__PURE__ */ new Map(),
711
+ add: (...list) => {
712
+ list.forEach((config) => {
713
+ const resolved = resolveVariableConfig(config);
714
+ const { name: _name, value, autocomplete: { asValueOf, asProperty } } = resolved;
715
+ const name = normalizeVariableName(_name);
716
+ asValueOf.forEach((p) => {
717
+ if (p !== "-")
718
+ engine.appendAutocompleteCssPropertyValues(p, `var(${name})`);
719
+ });
720
+ if (asProperty)
721
+ engine.appendAutocompleteExtraCssProperties(name);
722
+ if (value != null)
723
+ engine.variables.store.set(name, resolved);
724
+ });
725
+ engine.notifyPreflightUpdated();
645
726
  }
646
727
  };
647
- },
648
- async transformStyleItems(styleItems) {
649
- const result = [];
650
- for (const styleItem of styleItems) {
651
- if (typeof styleItem === "string") {
652
- result.push(...await shortcutResolver.resolve(styleItem));
653
- continue;
654
- }
655
- result.push(styleItem);
656
- }
657
- return result;
658
- },
659
- async transformStyleDefinitions(styleDefinitions) {
660
- const result = [];
661
- for (const styleDefinition of styleDefinitions) {
662
- if ("__shortcut" in styleDefinition) {
663
- const { __shortcut, ...rest } = styleDefinition;
664
- const applied = [];
665
- for (const shortcut of __shortcut == null ? [] : [__shortcut].flat(1)) {
666
- const resolved = (await shortcutResolver.resolve(shortcut)).filter(isNotString);
667
- applied.push(...resolved);
668
- }
669
- result.push(...applied, rest);
670
- } else {
671
- result.push(styleDefinition);
672
- }
673
- }
674
- return result;
728
+ engine.variables.add(...configList);
729
+ engine.addPreflight((engine2, isFormatted) => {
730
+ const used = /* @__PURE__ */ new Set();
731
+ engine2.store.atomicStyles.forEach(({ content: { value } }) => {
732
+ value.flatMap(extractUsedVarNames).forEach((name) => used.add(normalizeVariableName(name)));
733
+ });
734
+ return renderCSSStyleBlocks(
735
+ /* @__PURE__ */ new Map([[
736
+ ":root",
737
+ {
738
+ properties: Array.from(engine2.variables.store.entries()).filter(([name, { value }]) => used.has(name) && value != null).map(([name, { value }]) => ({ property: name, value }))
739
+ }
740
+ ]]),
741
+ isFormatted
742
+ );
743
+ });
675
744
  }
676
745
  });
677
746
  }
678
-
679
- function resolveVariableConfig(config) {
680
- if (typeof config === "string")
681
- return { name: config, value: null, autocomplete: { asValueOf: ["*"], asProperty: true } };
682
- if (Array.isArray(config)) {
683
- const [name2, value2, { asValueOf: asValueOf2 = "*", asProperty: asProperty2 = true } = {}] = config;
684
- return { name: name2, value: value2, autocomplete: { asValueOf: [asValueOf2].flat(), asProperty: asProperty2 } };
685
- }
686
- const { name, value, autocomplete: { asValueOf = "*", asProperty = true } = {} } = config;
687
- return { name, value, autocomplete: { asValueOf: [asValueOf].flat(), asProperty } };
747
+ function createResolveConfigFn({
748
+ pruneUnused: defaultPruneUnused = true
749
+ } = {}) {
750
+ return function resolveVariableConfig(config) {
751
+ if (typeof config === "string")
752
+ return { name: config, value: null, autocomplete: { asValueOf: ["*"], asProperty: true }, pruneUnused: defaultPruneUnused };
753
+ if (Array.isArray(config)) {
754
+ const [name2, value2, { asValueOf: asValueOf2 = "*", asProperty: asProperty2 = true } = {}, pruneUnused2 = defaultPruneUnused] = config;
755
+ return { name: name2, value: value2, autocomplete: { asValueOf: [asValueOf2].flat(), asProperty: asProperty2 }, pruneUnused: pruneUnused2 };
756
+ }
757
+ const { name, value, autocomplete: { asValueOf = "*", asProperty = true } = {}, pruneUnused = defaultPruneUnused } = config;
758
+ return { name, value, autocomplete: { asValueOf: [asValueOf].flat(), asProperty }, pruneUnused };
759
+ };
688
760
  }
689
761
  const VAR_NAME_RE = /var\((--[\w-]+)/g;
690
762
  function extractUsedVarNames(input) {
@@ -696,52 +768,15 @@ function extractUsedVarNames(input) {
696
768
  return varNameMatch ? varNameMatch[0] : "";
697
769
  }).filter(Boolean);
698
770
  }
699
- function normalizeVariableName(name, prefix) {
771
+ function normalizeVariableName(name) {
700
772
  if (name.startsWith("--"))
701
773
  return name;
702
- if (prefix)
703
- return `--${prefix}-${name}`;
704
774
  return `--${name}`;
705
775
  }
706
- function variables() {
707
- const allVariables = /* @__PURE__ */ new Map();
708
- let prefix;
709
- let configList;
710
- return defineEnginePlugin$1({
711
- name: "core:variables",
712
- beforeConfigResolving(config) {
713
- prefix = config.variablesPrefix;
714
- configList = config.variables ?? [];
715
- },
716
- configResolved(resolvedConfig) {
717
- configList.forEach((config) => {
718
- const { name: _name, value, autocomplete: { asValueOf, asProperty } } = resolveVariableConfig(config);
719
- const name = normalizeVariableName(_name, prefix);
720
- asValueOf.forEach((p) => appendAutocompleteCssPropertyValues(resolvedConfig, p, `var(${name})`));
721
- if (asProperty)
722
- appendAutocompleteExtraCssProperties(resolvedConfig, name);
723
- if (value != null)
724
- allVariables.set(name, value);
725
- });
726
- resolvedConfig.preflights.push((engine, isFormatted) => {
727
- const used = /* @__PURE__ */ new Set();
728
- engine.store.atomicStyles.forEach(({ content: { value } }) => {
729
- value.flatMap(extractUsedVarNames).forEach((name) => used.add(normalizeVariableName(name)));
730
- });
731
- return renderCSSStyleBlocks(
732
- /* @__PURE__ */ new Map([[
733
- ":root",
734
- {
735
- properties: Array.from(allVariables.entries()).filter(([name]) => used.has(name)).map(([name, value]) => ({ property: name, value }))
736
- }
737
- ]]),
738
- isFormatted
739
- );
740
- });
741
- }
742
- });
743
- }
744
776
 
777
+ function defineEngineConfig(config) {
778
+ return config;
779
+ }
745
780
  async function createEngine(config = {}) {
746
781
  const corePlugins = [
747
782
  important(),
@@ -752,20 +787,25 @@ async function createEngine(config = {}) {
752
787
  ];
753
788
  const plugins = resolvePlugins([...corePlugins, ...config.plugins || []]);
754
789
  config.plugins = plugins;
755
- config = await hooks.config(
790
+ config = await hooks.configureRawConfig(
756
791
  config.plugins,
757
792
  config
758
793
  );
759
- hooks.beforeConfigResolving(
794
+ hooks.rawConfigConfigured(
760
795
  resolvePlugins(config.plugins || []),
761
796
  config
762
797
  );
763
798
  let resolvedConfig = await resolveEngineConfig(config);
764
- resolvedConfig = await hooks.configResolved(
799
+ resolvedConfig = await hooks.configureResolvedConfig(
765
800
  resolvedConfig.plugins,
766
801
  resolvedConfig
767
802
  );
768
- return new Engine(resolvedConfig);
803
+ let engine = new Engine(resolvedConfig);
804
+ engine = await hooks.configureEngine(
805
+ engine.config.plugins,
806
+ engine
807
+ );
808
+ return engine;
769
809
  }
770
810
  class Engine {
771
811
  config;
@@ -782,13 +822,12 @@ class Engine {
782
822
  transformStyleItems: (styleItems) => hooks.transformStyleItems(this.config.plugins, styleItems),
783
823
  transformStyleDefinitions: (styleDefinitions) => hooks.transformStyleDefinitions(this.config.plugins, styleDefinitions)
784
824
  });
785
- hooks.engineInitialized(this.config.plugins, this);
786
825
  }
787
826
  notifyPreflightUpdated() {
788
827
  hooks.preflightUpdated(this.config.plugins);
789
828
  }
790
- notifyAtomicStyleAdded() {
791
- hooks.atomicStyleAdded(this.config.plugins);
829
+ notifyAtomicStyleAdded(atomicStyle) {
830
+ hooks.atomicStyleAdded(this.config.plugins, atomicStyle);
792
831
  }
793
832
  notifyAutocompleteConfigUpdated() {
794
833
  hooks.autocompleteConfigUpdated(this.config.plugins);
@@ -817,6 +856,10 @@ class Engine {
817
856
  appendAutocompleteCssPropertyValues(this.config, property, ...values);
818
857
  this.notifyAutocompleteConfigUpdated();
819
858
  }
859
+ addPreflight(preflight) {
860
+ this.config.preflights.push(resolvePreflight(preflight));
861
+ this.notifyPreflightUpdated();
862
+ }
820
863
  async use(...itemList) {
821
864
  const {
822
865
  unknown,
@@ -835,8 +878,9 @@ class Engine {
835
878
  });
836
879
  resolvedIds.push(id);
837
880
  if (!this.store.atomicStyles.has(id)) {
838
- this.store.atomicStyles.set(id, { id, content });
839
- this.notifyAtomicStyleAdded();
881
+ const atomicStyle = { id, content };
882
+ this.store.atomicStyles.set(id, atomicStyle);
883
+ this.notifyAtomicStyleAdded(atomicStyle);
840
884
  }
841
885
  });
842
886
  return [...unknown, ...resolvedIds];
@@ -855,13 +899,15 @@ class Engine {
855
899
  });
856
900
  }
857
901
  }
902
+ function resolvePreflight(preflight) {
903
+ return typeof preflight === "function" ? preflight : () => preflight;
904
+ }
858
905
  async function resolveEngineConfig(config) {
859
906
  const {
860
907
  prefix = "",
861
908
  defaultSelector = `.${ATOMIC_STYLE_ID_PLACEHOLDER}`,
862
909
  plugins = [],
863
- preflights = [],
864
- autocomplete = {}
910
+ preflights = []
865
911
  } = config;
866
912
  const resolvedConfig = {
867
913
  rawConfig: config,
@@ -878,14 +924,8 @@ async function resolveEngineConfig(config) {
878
924
  cssProperties: /* @__PURE__ */ new Map()
879
925
  }
880
926
  };
881
- const resolvedPreflights = preflights.map((p) => typeof p === "function" ? p : () => p);
927
+ const resolvedPreflights = preflights.map(resolvePreflight);
882
928
  resolvedConfig.preflights.push(...resolvedPreflights);
883
- appendAutocompleteSelectors(resolvedConfig, ...autocomplete.selectors || []);
884
- appendAutocompleteStyleItemStrings(resolvedConfig, ...autocomplete.styleItemStrings || []);
885
- appendAutocompleteExtraProperties(resolvedConfig, ...autocomplete.extraProperties || []);
886
- appendAutocompleteExtraCssProperties(resolvedConfig, ...autocomplete.extraCssProperties || []);
887
- autocomplete.properties?.forEach(([property, value]) => appendAutocompletePropertyValues(resolvedConfig, property, ...[value].flat()));
888
- autocomplete.cssProperties?.forEach(([property, value]) => appendAutocompleteCssPropertyValues(resolvedConfig, property, ...[value].flat()));
889
929
  return resolvedConfig;
890
930
  }
891
931
  function getAtomicStyleId({
@@ -959,27 +999,12 @@ function renderAtomicStyles(payload) {
959
999
  return renderCSSStyleBlocks(blocks, isFormatted);
960
1000
  }
961
1001
 
962
- function createDefineEnginePluginFn() {
963
- return function defineEnginePlugin2(plugin) {
964
- return plugin;
965
- };
966
- }
967
- const defineEnginePlugin = createDefineEnginePluginFn();
968
- function createDefineEngineConfigFn() {
969
- return function defineEngineConfig2(config) {
970
- return config;
971
- };
972
- }
973
- const defineEngineConfig = createDefineEngineConfigFn();
974
-
975
1002
  exports.appendAutocompleteCssPropertyValues = appendAutocompleteCssPropertyValues;
976
1003
  exports.appendAutocompleteExtraCssProperties = appendAutocompleteExtraCssProperties;
977
1004
  exports.appendAutocompleteExtraProperties = appendAutocompleteExtraProperties;
978
1005
  exports.appendAutocompletePropertyValues = appendAutocompletePropertyValues;
979
1006
  exports.appendAutocompleteSelectors = appendAutocompleteSelectors;
980
1007
  exports.appendAutocompleteStyleItemStrings = appendAutocompleteStyleItemStrings;
981
- exports.createDefineEngineConfigFn = createDefineEngineConfigFn;
982
- exports.createDefineEnginePluginFn = createDefineEnginePluginFn;
983
1008
  exports.createEngine = createEngine;
984
1009
  exports.defineEngineConfig = defineEngineConfig;
985
1010
  exports.defineEnginePlugin = defineEnginePlugin;