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