@pikacss/core 0.0.45 → 0.0.46
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 -6
- package/dist/index.mjs +70 -22
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -233,6 +233,11 @@ interface ResolvedVariable {
|
|
|
233
233
|
}
|
|
234
234
|
declare function extractUsedVarNames(input: string): string[];
|
|
235
235
|
declare function normalizeVariableName(name: string): string;
|
|
236
|
+
/**
|
|
237
|
+
* Recursively extract all CSS variable names referenced inside a preflight
|
|
238
|
+
* result (either a plain CSS string or a `PreflightDefinition` object).
|
|
239
|
+
*/
|
|
240
|
+
declare function extractUsedVarNamesFromPreflightResult(result: string | PreflightDefinition): string[];
|
|
236
241
|
//#endregion
|
|
237
242
|
//#region src/internal/types/utils.d.ts
|
|
238
243
|
type Nullish = null | undefined;
|
|
@@ -8561,14 +8566,21 @@ type ResolvedStyleItem = ResolveFrom<PikaAugment, 'StyleItem', any, InternalStyl
|
|
|
8561
8566
|
//#region src/internal/types/preflight.d.ts
|
|
8562
8567
|
type PreflightDefinition = { [selector in UnionString | ResolvedSelector]?: ResolvedCSSProperties | PreflightDefinition };
|
|
8563
8568
|
type PreflightFn = (engine: Engine, isFormatted: boolean) => Awaitable<string | PreflightDefinition>;
|
|
8564
|
-
interface WithLayer<T extends string | PreflightDefinition | PreflightFn> {
|
|
8565
|
-
layer: string;
|
|
8566
|
-
preflight: T;
|
|
8567
|
-
}
|
|
8568
8569
|
interface ResolvedPreflight {
|
|
8569
8570
|
layer?: string;
|
|
8571
|
+
id?: string;
|
|
8570
8572
|
fn: PreflightFn;
|
|
8571
8573
|
}
|
|
8574
|
+
interface WithId<T> {
|
|
8575
|
+
id: string;
|
|
8576
|
+
preflight: T;
|
|
8577
|
+
}
|
|
8578
|
+
type MaybeWithId<T> = WithId<T> | T;
|
|
8579
|
+
interface WithLayer<T> {
|
|
8580
|
+
layer: string;
|
|
8581
|
+
preflight: T;
|
|
8582
|
+
}
|
|
8583
|
+
type MaybeWithLayer<T> = WithLayer<T> | T;
|
|
8572
8584
|
/**
|
|
8573
8585
|
* Preflight can be a string, object, function, or a layer-wrapped variant.
|
|
8574
8586
|
*
|
|
@@ -8577,7 +8589,7 @@ interface ResolvedPreflight {
|
|
|
8577
8589
|
* 3. A `PreflightFn` is a dynamic preflight that receives the engine instance.
|
|
8578
8590
|
* 4. A `WithLayer` wrapper assigns any of the above to a specific CSS `@layer`.
|
|
8579
8591
|
*/
|
|
8580
|
-
type Preflight =
|
|
8592
|
+
type Preflight = MaybeWithLayer<MaybeWithId<string | PreflightDefinition | PreflightFn>>;
|
|
8581
8593
|
//#endregion
|
|
8582
8594
|
//#region src/internal/types/engine.d.ts
|
|
8583
8595
|
interface EngineConfig$1 {
|
|
@@ -8784,4 +8796,4 @@ declare function defineSelector<const T extends Selector>(selector: T): T;
|
|
|
8784
8796
|
declare function defineShortcut<const T extends Shortcut>(shortcut: T): T;
|
|
8785
8797
|
declare function defineVariables<const T extends VariablesDefinition>(variables: T): T;
|
|
8786
8798
|
//#endregion
|
|
8787
|
-
export { Arrayable, Awaitable, type CSSProperty, type CSSSelector, type CSSStyleBlockBody, type CSSStyleBlocks, type DefineAutocomplete, type Engine, type EngineConfig$1 as EngineConfig, type EnginePlugin, FromKebab, GetValue, IsEqual, IsNever, Keyframes, KeyframesConfig, KeyframesProgress, Nullish, type PikaAugment, type Preflight, type PreflightDefinition, type PreflightFn, type Properties, type PropertyValue, ResolveFrom, type ResolvedLayerName, type ResolvedPreflight, Selector, SelectorsConfig, Shortcut, ShortcutsConfig, Simplify, type StyleDefinition, type StyleDefinitionMap, type StyleItem, ToKebab, UnionString, UnionToIntersection, Variable, VariableAutocomplete, VariableObject, VariablesConfig, VariablesDefinition,
|
|
8799
|
+
export { Arrayable, Awaitable, type CSSProperty, type CSSSelector, type CSSStyleBlockBody, type CSSStyleBlocks, type DefineAutocomplete, type Engine, type EngineConfig$1 as EngineConfig, type EnginePlugin, FromKebab, GetValue, IsEqual, IsNever, Keyframes, KeyframesConfig, KeyframesProgress, Nullish, type PikaAugment, type Preflight, type PreflightDefinition, type PreflightFn, type Properties, type PropertyValue, ResolveFrom, type ResolvedLayerName, type ResolvedPreflight, Selector, SelectorsConfig, Shortcut, ShortcutsConfig, Simplify, type StyleDefinition, type StyleDefinitionMap, type StyleItem, ToKebab, UnionString, UnionToIntersection, Variable, VariableAutocomplete, VariableObject, VariablesConfig, VariablesDefinition, appendAutocompleteCssPropertyValues, appendAutocompleteExtraCssProperties, appendAutocompleteExtraProperties, appendAutocompletePropertyValues, appendAutocompleteSelectors, appendAutocompleteStyleItemStrings, createEngine, createLogger, defineEngineConfig, defineEnginePlugin, defineKeyframes, definePreflight, defineSelector, defineShortcut, defineStyleDefinition, defineVariables, extractUsedVarNames, extractUsedVarNamesFromPreflightResult, important, keyframes, log, normalizeVariableName, renderCSSStyleBlocks, resolveSelectorConfig, selectors$1 as selectors, shortcuts, sortLayerNames, variables };
|
package/dist/index.mjs
CHANGED
|
@@ -684,23 +684,46 @@ function variables() {
|
|
|
684
684
|
}
|
|
685
685
|
};
|
|
686
686
|
rawVariables.forEach((variables) => engine.variables.add(variables));
|
|
687
|
-
engine.addPreflight(
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
current[s] ||= {};
|
|
699
|
-
current = current[s];
|
|
687
|
+
engine.addPreflight({
|
|
688
|
+
id: "core:variables",
|
|
689
|
+
preflight: async (engine) => {
|
|
690
|
+
const used = /* @__PURE__ */ new Set();
|
|
691
|
+
engine.store.atomicStyles.forEach(({ content: { value } }) => {
|
|
692
|
+
value.flatMap(extractUsedVarNames).forEach((name) => used.add(normalizeVariableName(name)));
|
|
693
|
+
});
|
|
694
|
+
const otherPreflights = engine.config.preflights.filter((p) => p.id !== "core:variables");
|
|
695
|
+
(await Promise.all(otherPreflights.map(({ fn }) => Promise.resolve(fn(engine, false)).catch(() => null)))).forEach((result) => {
|
|
696
|
+
if (result == null) return;
|
|
697
|
+
extractUsedVarNamesFromPreflightResult(result).forEach((name) => used.add(name));
|
|
700
698
|
});
|
|
701
|
-
|
|
699
|
+
const varMap = /* @__PURE__ */ new Map();
|
|
700
|
+
for (const [name, list] of engine.variables.store.entries()) varMap.set(name, list);
|
|
701
|
+
const queue = Array.from(used);
|
|
702
|
+
while (queue.length > 0) {
|
|
703
|
+
const name = queue.pop();
|
|
704
|
+
const entries = varMap.get(name);
|
|
705
|
+
if (!entries) continue;
|
|
706
|
+
for (const { value } of entries) {
|
|
707
|
+
if (value == null) continue;
|
|
708
|
+
for (const refName of extractUsedVarNames(String(value)).map(normalizeVariableName)) if (!used.has(refName)) {
|
|
709
|
+
used.add(refName);
|
|
710
|
+
queue.push(refName);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
const usedVariables = Array.from(engine.variables.store.values()).flat().filter(({ name, pruneUnused, value }) => (safeSet.has(name) || pruneUnused === false || used.has(name)) && value != null);
|
|
715
|
+
const preflightDefinition = {};
|
|
716
|
+
for (const { name, value, selector: _selector } of usedVariables) {
|
|
717
|
+
const selector = await engine.pluginHooks.transformSelectors(engine.config.plugins, _selector);
|
|
718
|
+
let current = preflightDefinition;
|
|
719
|
+
selector.forEach((s) => {
|
|
720
|
+
current[s] ||= {};
|
|
721
|
+
current = current[s];
|
|
722
|
+
});
|
|
723
|
+
Object.assign(current, { [name]: value });
|
|
724
|
+
}
|
|
725
|
+
return preflightDefinition;
|
|
702
726
|
}
|
|
703
|
-
return preflightDefinition;
|
|
704
727
|
});
|
|
705
728
|
}
|
|
706
729
|
});
|
|
@@ -734,6 +757,20 @@ function normalizeVariableName(name) {
|
|
|
734
757
|
if (name.startsWith("--")) return name;
|
|
735
758
|
return `--${name}`;
|
|
736
759
|
}
|
|
760
|
+
/**
|
|
761
|
+
* Recursively extract all CSS variable names referenced inside a preflight
|
|
762
|
+
* result (either a plain CSS string or a `PreflightDefinition` object).
|
|
763
|
+
*/
|
|
764
|
+
function extractUsedVarNamesFromPreflightResult(result) {
|
|
765
|
+
if (typeof result === "string") return extractUsedVarNames(result).map(normalizeVariableName);
|
|
766
|
+
const names = [];
|
|
767
|
+
for (const value of Object.values(result)) {
|
|
768
|
+
if (value == null) continue;
|
|
769
|
+
if (typeof value === "string" || typeof value === "number") extractUsedVarNames(String(value)).forEach((n) => names.push(normalizeVariableName(n)));
|
|
770
|
+
else if (typeof value === "object") extractUsedVarNamesFromPreflightResult(value).forEach((n) => names.push(n));
|
|
771
|
+
}
|
|
772
|
+
return names;
|
|
773
|
+
}
|
|
737
774
|
|
|
738
775
|
//#endregion
|
|
739
776
|
//#region src/internal/engine.ts
|
|
@@ -925,16 +962,27 @@ function isWithLayer(p) {
|
|
|
925
962
|
const record = p;
|
|
926
963
|
return typeof record.layer === "string" && record.preflight !== void 0;
|
|
927
964
|
}
|
|
965
|
+
function isWithId(p) {
|
|
966
|
+
if (typeof p !== "object" || p === null) return false;
|
|
967
|
+
const record = p;
|
|
968
|
+
return typeof record.id === "string" && record.preflight !== void 0;
|
|
969
|
+
}
|
|
928
970
|
function resolvePreflight(preflight) {
|
|
971
|
+
let layer;
|
|
972
|
+
let id;
|
|
929
973
|
if (isWithLayer(preflight)) {
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
return {
|
|
933
|
-
layer: preflight.layer,
|
|
934
|
-
fn
|
|
935
|
-
};
|
|
974
|
+
layer = preflight.layer;
|
|
975
|
+
preflight = preflight.preflight;
|
|
936
976
|
}
|
|
937
|
-
|
|
977
|
+
if (isWithId(preflight)) {
|
|
978
|
+
id = preflight.id;
|
|
979
|
+
preflight = preflight.preflight;
|
|
980
|
+
}
|
|
981
|
+
return {
|
|
982
|
+
layer,
|
|
983
|
+
id,
|
|
984
|
+
fn: typeof preflight === "function" ? preflight : () => preflight
|
|
985
|
+
};
|
|
938
986
|
}
|
|
939
987
|
async function resolveEngineConfig(config) {
|
|
940
988
|
const { prefix = "", defaultSelector = `.${ATOMIC_STYLE_ID_PLACEHOLDER}`, plugins = [], preflights = [] } = config;
|