@pikacss/core 0.0.42 → 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.d.mts +18 -21
- package/dist/index.mjs +101 -149
- package/package.json +1 -6
- package/dist/index.cjs +0 -1197
- package/dist/index.d.cts +0 -637
package/dist/index.d.mts
CHANGED
|
@@ -39,6 +39,18 @@ declare abstract class AbstractResolver<T> {
|
|
|
39
39
|
_resolve(string: string): Promise<ResolvedResult<T> | Nullish>;
|
|
40
40
|
_setResolvedResult(string: string, resolved: T): void;
|
|
41
41
|
}
|
|
42
|
+
declare abstract class RecursiveResolver<T> extends AbstractResolver<T[]> {
|
|
43
|
+
resolve(string: string): Promise<T[]>;
|
|
44
|
+
}
|
|
45
|
+
type ResolvedRuleConfig<T> = {
|
|
46
|
+
type: 'static';
|
|
47
|
+
rule: StaticRule<T[]>;
|
|
48
|
+
autocomplete: string[];
|
|
49
|
+
} | {
|
|
50
|
+
type: 'dynamic';
|
|
51
|
+
rule: DynamicRule<T[]>;
|
|
52
|
+
autocomplete: string[];
|
|
53
|
+
};
|
|
42
54
|
//#endregion
|
|
43
55
|
//#region src/internal/plugins/selectors.d.ts
|
|
44
56
|
type Selector = string | [selector: RegExp, value: (matched: RegExpMatchArray) => Awaitable<Arrayable<UnionString | ResolvedSelector>>, autocomplete?: Arrayable<string>] | [selector: string, value: Arrayable<UnionString | ResolvedSelector>] | {
|
|
@@ -81,21 +93,8 @@ declare module '@pikacss/core' {
|
|
|
81
93
|
}
|
|
82
94
|
}
|
|
83
95
|
declare function selectors$1(): EnginePlugin;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
declare class SelectorResolver extends AbstractResolver<string[]> {
|
|
87
|
-
resolve(selector: string): Promise<string[]>;
|
|
88
|
-
}
|
|
89
|
-
type ResolvedSelectorConfig = {
|
|
90
|
-
type: 'static';
|
|
91
|
-
rule: StaticSelectorRule;
|
|
92
|
-
autocomplete: string[];
|
|
93
|
-
} | {
|
|
94
|
-
type: 'dynamic';
|
|
95
|
-
rule: DynamicSelectorRule;
|
|
96
|
-
autocomplete: string[];
|
|
97
|
-
};
|
|
98
|
-
declare function resolveSelectorConfig(config: Selector): ResolvedSelectorConfig | string | Nullish;
|
|
96
|
+
declare class SelectorResolver extends RecursiveResolver<string> {}
|
|
97
|
+
declare function resolveSelectorConfig(config: Selector): string | Nullish | ResolvedRuleConfig<string>;
|
|
99
98
|
//#endregion
|
|
100
99
|
//#region src/internal/plugins/shortcuts.d.ts
|
|
101
100
|
type Shortcut = string | [shortcut: RegExp, value: (matched: RegExpMatchArray) => Awaitable<Arrayable<ResolvedStyleItem>>, autocomplete?: Arrayable<string>] | {
|
|
@@ -142,9 +141,7 @@ declare module '@pikacss/core' {
|
|
|
142
141
|
}
|
|
143
142
|
}
|
|
144
143
|
declare function shortcuts(): EnginePlugin;
|
|
145
|
-
declare class ShortcutResolver extends
|
|
146
|
-
resolve(shortcut: string): Promise<InternalStyleItem[]>;
|
|
147
|
-
}
|
|
144
|
+
declare class ShortcutResolver extends RecursiveResolver<InternalStyleItem> {}
|
|
148
145
|
//#endregion
|
|
149
146
|
//#region src/internal/plugins/variables.d.ts
|
|
150
147
|
type ResolvedCSSProperty = keyof ResolvedCSSProperties;
|
|
@@ -252,8 +249,8 @@ type IsNever<T> = [T] extends [never] ? true : false;
|
|
|
252
249
|
type Simplify<T> = { [K in keyof T]: T[K] } & {};
|
|
253
250
|
type ToKebab<T extends string> = T extends `${infer A}${infer B}` ? [A extends Uppercase<A> ? 1 : 0, A extends Lowercase<A> ? 1 : 0] extends [1, 0] ? `-${Lowercase<A>}${ToKebab<`${B}`>}` : `${A}${ToKebab<`${B}`>}` : T;
|
|
254
251
|
type FromKebab<T extends string> = T extends `--${string}` ? T : T extends `-${infer A}${infer B}` ? `${Uppercase<A>}${FromKebab<`${B}`>}` : T extends `${infer A}${infer B}` ? `${A}${FromKebab<`${B}`>}` : T;
|
|
255
|
-
type GetValue<Obj extends Record<string, any>, K
|
|
256
|
-
type ResolveFrom<T, Key
|
|
252
|
+
type GetValue<Obj extends Record<string, any>, K extends string> = (IsEqual<Obj, object> | IsEqual<Obj, {}> | IsEqual<Obj[K], unknown>) extends false ? Obj[K] : never;
|
|
253
|
+
type ResolveFrom<T, Key extends string, I, Fallback extends I> = Key extends keyof T ? T[Key] extends I ? T[Key] : Fallback : Fallback;
|
|
257
254
|
//#endregion
|
|
258
255
|
//#region src/internal/types/autocomplete.d.ts
|
|
259
256
|
interface ResolvedAutocompleteConfig {
|
|
@@ -273,7 +270,7 @@ interface _Autocomplete {
|
|
|
273
270
|
PropertiesValue: Record<string, unknown>;
|
|
274
271
|
CssPropertiesValue: Record<string, UnionString | UnionNumber>;
|
|
275
272
|
}
|
|
276
|
-
type DefineAutocomplete<A
|
|
273
|
+
type DefineAutocomplete<A extends _Autocomplete> = A;
|
|
277
274
|
type EmptyAutocomplete = DefineAutocomplete<{
|
|
278
275
|
Selector: never;
|
|
279
276
|
StyleItemString: never;
|
package/dist/index.mjs
CHANGED
|
@@ -80,8 +80,8 @@ function serialize(value) {
|
|
|
80
80
|
function addToSet(set, ...values) {
|
|
81
81
|
values.forEach((value) => set.add(value));
|
|
82
82
|
}
|
|
83
|
-
function appendAutocompleteSelectors(config, ...selectors
|
|
84
|
-
addToSet(config.autocomplete.selectors, ...selectors
|
|
83
|
+
function appendAutocompleteSelectors(config, ...selectors) {
|
|
84
|
+
addToSet(config.autocomplete.selectors, ...selectors);
|
|
85
85
|
}
|
|
86
86
|
function appendAutocompleteStyleItemStrings(config, ...styleItemStrings) {
|
|
87
87
|
addToSet(config.autocomplete.styleItemStrings, ...styleItemStrings);
|
|
@@ -130,8 +130,8 @@ const RE_SPLIT = /\s*,\s*/g;
|
|
|
130
130
|
const DEFAULT_SELECTOR_PLACEHOLDER_RE_GLOBAL = /\$/g;
|
|
131
131
|
const ATTRIBUTE_SUFFIX_MATCH = "$=";
|
|
132
132
|
const ATTRIBUTE_SUFFIX_MATCH_RE_GLOBAL = /\$=/g;
|
|
133
|
-
function normalizeSelectors({ selectors
|
|
134
|
-
return selectors
|
|
133
|
+
function normalizeSelectors({ selectors, defaultSelector }) {
|
|
134
|
+
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
135
|
}
|
|
136
136
|
function normalizeValue(value) {
|
|
137
137
|
if (value == null) return value;
|
|
@@ -218,7 +218,7 @@ const hooks = {
|
|
|
218
218
|
rawConfigConfigured: (plugins, config) => execSyncHook(plugins, "rawConfigConfigured", config),
|
|
219
219
|
configureResolvedConfig: (plugins, resolvedConfig) => execAsyncHook(plugins, "configureResolvedConfig", resolvedConfig),
|
|
220
220
|
configureEngine: (plugins, engine) => execAsyncHook(plugins, "configureEngine", engine),
|
|
221
|
-
transformSelectors: (plugins, selectors
|
|
221
|
+
transformSelectors: (plugins, selectors) => execAsyncHook(plugins, "transformSelectors", selectors),
|
|
222
222
|
transformStyleItems: (plugins, styleItems) => execAsyncHook(plugins, "transformStyleItems", styleItems),
|
|
223
223
|
transformStyleDefinitions: (plugins, styleDefinitions) => execAsyncHook(plugins, "transformStyleDefinitions", styleDefinitions),
|
|
224
224
|
preflightUpdated: (plugins) => execSyncHook(plugins, "preflightUpdated", void 0),
|
|
@@ -298,20 +298,20 @@ function keyframes() {
|
|
|
298
298
|
}
|
|
299
299
|
};
|
|
300
300
|
engine.keyframes.add(...configList);
|
|
301
|
-
engine.addPreflight((engine
|
|
301
|
+
engine.addPreflight((engine) => {
|
|
302
302
|
const maybeUsedName = /* @__PURE__ */ new Set();
|
|
303
|
-
engine
|
|
303
|
+
engine.store.atomicStyles.forEach(({ content: { property, value } }) => {
|
|
304
304
|
if (property === "animationName") {
|
|
305
305
|
value.forEach((name) => maybeUsedName.add(name));
|
|
306
306
|
return;
|
|
307
307
|
}
|
|
308
|
-
if (property === "animation") value.forEach((value
|
|
309
|
-
value
|
|
308
|
+
if (property === "animation") value.forEach((value) => {
|
|
309
|
+
value.split(",").map((v) => v.trim()).forEach((animation) => {
|
|
310
310
|
addToSet(maybeUsedName, ...animation.split(" "));
|
|
311
311
|
});
|
|
312
312
|
});
|
|
313
313
|
});
|
|
314
|
-
const maybeUsedKeyframes = Array.from(engine
|
|
314
|
+
const maybeUsedKeyframes = Array.from(engine.keyframes.store.values()).filter(({ name, frames, pruneUnused }) => (pruneUnused === false || maybeUsedName.has(name)) && frames != null);
|
|
315
315
|
const preflightDefinition = {};
|
|
316
316
|
maybeUsedKeyframes.forEach(({ name, frames }) => {
|
|
317
317
|
preflightDefinition[`@keyframes ${name}`] = Object.fromEntries(Object.entries(frames).map(([frame, properties]) => [frame, properties]));
|
|
@@ -330,12 +330,12 @@ function createResolveConfigFn({ pruneUnused: defaultPruneUnused = true } = {})
|
|
|
330
330
|
pruneUnused: defaultPruneUnused
|
|
331
331
|
};
|
|
332
332
|
if (Array.isArray(config)) {
|
|
333
|
-
const [name
|
|
333
|
+
const [name, frames, autocomplete = [], pruneUnused = defaultPruneUnused] = config;
|
|
334
334
|
return {
|
|
335
|
-
name
|
|
336
|
-
frames
|
|
337
|
-
autocomplete
|
|
338
|
-
pruneUnused
|
|
335
|
+
name,
|
|
336
|
+
frames,
|
|
337
|
+
autocomplete,
|
|
338
|
+
pruneUnused
|
|
339
339
|
};
|
|
340
340
|
}
|
|
341
341
|
const { name, frames, autocomplete = [], pruneUnused = defaultPruneUnused } = config;
|
|
@@ -436,60 +436,20 @@ var AbstractResolver = class {
|
|
|
436
436
|
this._resolvedResultsMap.set(string, { value: resolved });
|
|
437
437
|
}
|
|
438
438
|
};
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
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;
|
|
477
|
-
}
|
|
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);
|
|
439
|
+
var RecursiveResolver = class extends AbstractResolver {
|
|
440
|
+
async resolve(string) {
|
|
441
|
+
const resolved = await this._resolve(string).catch((error) => {
|
|
442
|
+
log.warn(`Failed to resolve "${string}": ${error.message}`, error);
|
|
484
443
|
});
|
|
485
|
-
if (resolved == null) return [
|
|
444
|
+
if (resolved == null) return [string];
|
|
486
445
|
const result = [];
|
|
487
|
-
for (const
|
|
488
|
-
|
|
446
|
+
for (const partial of resolved.value) if (typeof partial === "string") result.push(...await this.resolve(partial));
|
|
447
|
+
else result.push(partial);
|
|
448
|
+
this._setResolvedResult(string, result);
|
|
489
449
|
return result;
|
|
490
450
|
}
|
|
491
451
|
};
|
|
492
|
-
function
|
|
452
|
+
function resolveRuleConfig(config, keyName) {
|
|
493
453
|
if (typeof config === "string") return config;
|
|
494
454
|
if (Array.isArray(config)) {
|
|
495
455
|
if (typeof config[0] === "string" && typeof config[1] !== "function") return {
|
|
@@ -515,22 +475,24 @@ function resolveSelectorConfig(config) {
|
|
|
515
475
|
}
|
|
516
476
|
return;
|
|
517
477
|
}
|
|
518
|
-
if (typeof config
|
|
478
|
+
if (typeof config !== "object" || config === null) return;
|
|
479
|
+
const configKey = config[keyName];
|
|
480
|
+
if (typeof configKey === "string" && typeof config.value !== "function") return {
|
|
519
481
|
type: "static",
|
|
520
482
|
rule: {
|
|
521
|
-
key:
|
|
522
|
-
string:
|
|
483
|
+
key: configKey,
|
|
484
|
+
string: configKey,
|
|
523
485
|
resolved: [config.value].flat(1)
|
|
524
486
|
},
|
|
525
|
-
autocomplete: [
|
|
487
|
+
autocomplete: [configKey]
|
|
526
488
|
};
|
|
527
|
-
if (
|
|
489
|
+
if (configKey instanceof RegExp && typeof config.value === "function") {
|
|
528
490
|
const fn = config.value;
|
|
529
491
|
return {
|
|
530
492
|
type: "dynamic",
|
|
531
493
|
rule: {
|
|
532
|
-
key:
|
|
533
|
-
stringPattern:
|
|
494
|
+
key: configKey.source,
|
|
495
|
+
stringPattern: configKey,
|
|
534
496
|
createResolved: async (match) => [await fn(match)].flat(1)
|
|
535
497
|
},
|
|
536
498
|
autocomplete: "autocomplete" in config && config.autocomplete != null ? [config.autocomplete].flat(1) : []
|
|
@@ -538,6 +500,51 @@ function resolveSelectorConfig(config) {
|
|
|
538
500
|
}
|
|
539
501
|
}
|
|
540
502
|
|
|
503
|
+
//#endregion
|
|
504
|
+
//#region src/internal/plugins/selectors.ts
|
|
505
|
+
function selectors() {
|
|
506
|
+
let engine;
|
|
507
|
+
let configList;
|
|
508
|
+
return defineEnginePlugin({
|
|
509
|
+
name: "core:selectors",
|
|
510
|
+
rawConfigConfigured(config) {
|
|
511
|
+
configList = config.selectors?.selectors ?? [];
|
|
512
|
+
},
|
|
513
|
+
configureEngine(_engine) {
|
|
514
|
+
engine = _engine;
|
|
515
|
+
engine.selectors = {
|
|
516
|
+
resolver: new SelectorResolver(),
|
|
517
|
+
add: (...list) => {
|
|
518
|
+
list.forEach((config) => {
|
|
519
|
+
const resolved = resolveSelectorConfig(config);
|
|
520
|
+
if (resolved == null) return;
|
|
521
|
+
if (typeof resolved === "string") {
|
|
522
|
+
engine.appendAutocompleteSelectors(resolved);
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
if (resolved.type === "static") engine.selectors.resolver.addStaticRule(resolved.rule);
|
|
526
|
+
else if (resolved.type === "dynamic") engine.selectors.resolver.addDynamicRule(resolved.rule);
|
|
527
|
+
engine.appendAutocompleteSelectors(...resolved.autocomplete);
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
engine.selectors.add(...configList);
|
|
532
|
+
engine.selectors.resolver.onResolved = (string, type) => {
|
|
533
|
+
if (type === "dynamic") engine.appendAutocompleteSelectors(string);
|
|
534
|
+
};
|
|
535
|
+
},
|
|
536
|
+
async transformSelectors(selectors) {
|
|
537
|
+
const result = [];
|
|
538
|
+
for (const selector of selectors) result.push(...await engine.selectors.resolver.resolve(selector));
|
|
539
|
+
return result;
|
|
540
|
+
}
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
var SelectorResolver = class extends RecursiveResolver {};
|
|
544
|
+
function resolveSelectorConfig(config) {
|
|
545
|
+
return resolveRuleConfig(config, "selector");
|
|
546
|
+
}
|
|
547
|
+
|
|
541
548
|
//#endregion
|
|
542
549
|
//#region src/internal/plugins/shortcuts.ts
|
|
543
550
|
function shortcuts() {
|
|
@@ -600,64 +607,9 @@ function shortcuts() {
|
|
|
600
607
|
}
|
|
601
608
|
});
|
|
602
609
|
}
|
|
603
|
-
var ShortcutResolver = class extends
|
|
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
|
-
};
|
|
610
|
+
var ShortcutResolver = class extends RecursiveResolver {};
|
|
616
611
|
function resolveShortcutConfig(config) {
|
|
617
|
-
|
|
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
|
-
}
|
|
612
|
+
return resolveRuleConfig(config, "shortcut");
|
|
661
613
|
}
|
|
662
614
|
|
|
663
615
|
//#endregion
|
|
@@ -676,8 +628,8 @@ function variables() {
|
|
|
676
628
|
configureEngine(engine) {
|
|
677
629
|
engine.variables = {
|
|
678
630
|
store: /* @__PURE__ */ new Map(),
|
|
679
|
-
add: (variables
|
|
680
|
-
resolveVariables(variables
|
|
631
|
+
add: (variables) => {
|
|
632
|
+
resolveVariables(variables).forEach((resolved) => {
|
|
681
633
|
const { name, value, autocomplete: { asValueOf, asProperty } } = resolved;
|
|
682
634
|
asValueOf.forEach((p) => {
|
|
683
635
|
if (p !== "-") engine.appendAutocompleteCssPropertyValues(p, `var(${name})`);
|
|
@@ -692,16 +644,16 @@ function variables() {
|
|
|
692
644
|
engine.notifyPreflightUpdated();
|
|
693
645
|
}
|
|
694
646
|
};
|
|
695
|
-
rawVariables.forEach((variables
|
|
696
|
-
engine.addPreflight(async (engine
|
|
647
|
+
rawVariables.forEach((variables) => engine.variables.add(variables));
|
|
648
|
+
engine.addPreflight(async (engine) => {
|
|
697
649
|
const used = /* @__PURE__ */ new Set();
|
|
698
|
-
engine
|
|
650
|
+
engine.store.atomicStyles.forEach(({ content: { value } }) => {
|
|
699
651
|
value.flatMap(extractUsedVarNames).forEach((name) => used.add(normalizeVariableName(name)));
|
|
700
652
|
});
|
|
701
|
-
const usedVariables = Array.from(engine
|
|
653
|
+
const usedVariables = Array.from(engine.variables.store.values()).flat().filter(({ name, pruneUnused, value }) => (safeSet.has(name) || pruneUnused === false || used.has(name)) && value != null);
|
|
702
654
|
const preflightDefinition = {};
|
|
703
655
|
for (const { name, value, selector: _selector } of usedVariables) {
|
|
704
|
-
const selector = await engine
|
|
656
|
+
const selector = await engine.pluginHooks.transformSelectors(engine.config.plugins, _selector);
|
|
705
657
|
let current = preflightDefinition;
|
|
706
658
|
selector.forEach((s) => {
|
|
707
659
|
current[s] ||= {};
|
|
@@ -715,8 +667,8 @@ function variables() {
|
|
|
715
667
|
});
|
|
716
668
|
}
|
|
717
669
|
function createResolveVariablesFn({ pruneUnused: defaultPruneUnused = true } = {}) {
|
|
718
|
-
function _resolveVariables(variables
|
|
719
|
-
for (const [key, value] of Object.entries(variables
|
|
670
|
+
function _resolveVariables(variables, levels, result) {
|
|
671
|
+
for (const [key, value] of Object.entries(variables)) if (key.startsWith("--")) {
|
|
720
672
|
const { value: varValue, autocomplete = {}, pruneUnused = defaultPruneUnused } = typeof value === "object" && value !== null && !Array.isArray(value) ? value : { value };
|
|
721
673
|
result.push({
|
|
722
674
|
name: key,
|
|
@@ -731,8 +683,8 @@ function createResolveVariablesFn({ pruneUnused: defaultPruneUnused = true } = {
|
|
|
731
683
|
} else _resolveVariables(value, [...levels, key], result);
|
|
732
684
|
return result;
|
|
733
685
|
}
|
|
734
|
-
return function resolveVariables(variables
|
|
735
|
-
return _resolveVariables(variables
|
|
686
|
+
return function resolveVariables(variables) {
|
|
687
|
+
return _resolveVariables(variables, [], []);
|
|
736
688
|
};
|
|
737
689
|
}
|
|
738
690
|
const VAR_NAME_RE = /var\((--[\w-]+)/g;
|
|
@@ -795,7 +747,7 @@ var Engine = class {
|
|
|
795
747
|
this.config = config;
|
|
796
748
|
this.extract = createExtractFn({
|
|
797
749
|
defaultSelector: this.config.defaultSelector,
|
|
798
|
-
transformSelectors: (selectors
|
|
750
|
+
transformSelectors: (selectors) => hooks.transformSelectors(this.config.plugins, selectors),
|
|
799
751
|
transformStyleItems: (styleItems) => hooks.transformStyleItems(this.config.plugins, styleItems),
|
|
800
752
|
transformStyleDefinitions: (styleDefinitions) => hooks.transformStyleDefinitions(this.config.plugins, styleDefinitions)
|
|
801
753
|
});
|
|
@@ -809,8 +761,8 @@ var Engine = class {
|
|
|
809
761
|
notifyAutocompleteConfigUpdated() {
|
|
810
762
|
hooks.autocompleteConfigUpdated(this.config.plugins);
|
|
811
763
|
}
|
|
812
|
-
appendAutocompleteSelectors(...selectors
|
|
813
|
-
appendAutocompleteSelectors(this.config, ...selectors
|
|
764
|
+
appendAutocompleteSelectors(...selectors) {
|
|
765
|
+
appendAutocompleteSelectors(this.config, ...selectors);
|
|
814
766
|
this.notifyAutocompleteConfigUpdated();
|
|
815
767
|
}
|
|
816
768
|
appendAutocompleteStyleItemStrings(...styleItemStrings) {
|
|
@@ -1107,14 +1059,14 @@ function renderAtomicStyles(payload) {
|
|
|
1107
1059
|
async function _renderPreflightDefinition({ engine, preflightDefinition, blocks = /* @__PURE__ */ new Map() }) {
|
|
1108
1060
|
for (const [selector, propertiesOrDefinition] of Object.entries(preflightDefinition)) {
|
|
1109
1061
|
if (propertiesOrDefinition == null) continue;
|
|
1110
|
-
const selectors
|
|
1062
|
+
const selectors = normalizeSelectors({
|
|
1111
1063
|
selectors: await hooks.transformSelectors(engine.config.plugins, [selector]),
|
|
1112
1064
|
defaultSelector: ""
|
|
1113
1065
|
}).filter(Boolean);
|
|
1114
1066
|
let currentBlocks = blocks;
|
|
1115
1067
|
let currentBlockBody = null;
|
|
1116
|
-
selectors
|
|
1117
|
-
const isLast = i === selectors
|
|
1068
|
+
selectors.forEach((s, i) => {
|
|
1069
|
+
const isLast = i === selectors.length - 1;
|
|
1118
1070
|
currentBlocks.set(s, currentBlocks.get(s) || { properties: [] });
|
|
1119
1071
|
if (isLast) {
|
|
1120
1072
|
currentBlockBody = currentBlocks.get(s);
|
|
@@ -1160,8 +1112,8 @@ function defineStyleDefinition(styleDefinition) {
|
|
|
1160
1112
|
function definePreflight(preflight) {
|
|
1161
1113
|
return preflight;
|
|
1162
1114
|
}
|
|
1163
|
-
function defineKeyframes(keyframes
|
|
1164
|
-
return keyframes
|
|
1115
|
+
function defineKeyframes(keyframes) {
|
|
1116
|
+
return keyframes;
|
|
1165
1117
|
}
|
|
1166
1118
|
function defineSelector(selector) {
|
|
1167
1119
|
return selector;
|
|
@@ -1169,8 +1121,8 @@ function defineSelector(selector) {
|
|
|
1169
1121
|
function defineShortcut(shortcut) {
|
|
1170
1122
|
return shortcut;
|
|
1171
1123
|
}
|
|
1172
|
-
function defineVariables(variables
|
|
1173
|
-
return variables
|
|
1124
|
+
function defineVariables(variables) {
|
|
1125
|
+
return variables;
|
|
1174
1126
|
}
|
|
1175
1127
|
/* c8 ignore end */
|
|
1176
1128
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pikacss/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.44",
|
|
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": {
|