@pikacss/core 0.0.23 → 0.0.25
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 +75 -27
- package/dist/index.d.cts +11 -8
- package/dist/index.d.mts +11 -8
- package/dist/index.d.ts +11 -8
- package/dist/index.mjs +75 -27
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -97,7 +97,6 @@ function replaceBySplitAndJoin(str, split, mapFn, join) {
|
|
|
97
97
|
return splitted.join(join);
|
|
98
98
|
}
|
|
99
99
|
const RE_SPLIT = /\s*,\s*/g;
|
|
100
|
-
const DEFAULT_SELECTOR_PLACEHOLDER = "$";
|
|
101
100
|
const DEFAULT_SELECTOR_PLACEHOLDER_RE_GLOBAL = /\$/g;
|
|
102
101
|
const ATTRIBUTE_SUFFIX_MATCH = "$=";
|
|
103
102
|
const ATTRIBUTE_SUFFIX_MATCH_RE_GLOBAL = /\$=/g;
|
|
@@ -105,16 +104,9 @@ function normalizeSelectors({
|
|
|
105
104
|
selectors,
|
|
106
105
|
defaultSelector
|
|
107
106
|
}) {
|
|
108
|
-
|
|
109
|
-
return [defaultSelector];
|
|
110
|
-
const normalized = selectors.map((s) => s.replace(RE_SPLIT, ","));
|
|
111
|
-
const lastSelector = selectors[selectors.length - 1];
|
|
112
|
-
if (lastSelector.includes(ATOMIC_STYLE_ID_PLACEHOLDER) === false && lastSelector.includes(DEFAULT_SELECTOR_PLACEHOLDER) === false) {
|
|
113
|
-
normalized.push(DEFAULT_SELECTOR_PLACEHOLDER);
|
|
114
|
-
}
|
|
115
|
-
return normalized.map(
|
|
107
|
+
const normalized = selectors.map(
|
|
116
108
|
(s) => replaceBySplitAndJoin(
|
|
117
|
-
s,
|
|
109
|
+
s.replace(RE_SPLIT, ","),
|
|
118
110
|
ATOMIC_STYLE_ID_PLACEHOLDER_RE_GLOBAL,
|
|
119
111
|
(a) => replaceBySplitAndJoin(
|
|
120
112
|
a,
|
|
@@ -130,6 +122,7 @@ function normalizeSelectors({
|
|
|
130
122
|
ATOMIC_STYLE_ID_PLACEHOLDER
|
|
131
123
|
)
|
|
132
124
|
);
|
|
125
|
+
return normalized;
|
|
133
126
|
}
|
|
134
127
|
function normalizeValue(value) {
|
|
135
128
|
if (value == null)
|
|
@@ -145,19 +138,19 @@ async function extract({
|
|
|
145
138
|
transformStyleItems,
|
|
146
139
|
transformStyleDefinitions
|
|
147
140
|
}) {
|
|
148
|
-
const selector = normalizeSelectors({
|
|
149
|
-
selectors: await transformSelectors(levels),
|
|
150
|
-
defaultSelector
|
|
151
|
-
});
|
|
152
141
|
for (const definition of await transformStyleDefinitions([styleDefinition])) {
|
|
153
142
|
for (const [k, v] of Object.entries(definition)) {
|
|
154
143
|
if (isPropertyValue(v)) {
|
|
155
|
-
const
|
|
156
|
-
|
|
144
|
+
const selector = normalizeSelectors({
|
|
145
|
+
selectors: await transformSelectors(levels),
|
|
146
|
+
defaultSelector
|
|
147
|
+
});
|
|
148
|
+
if (selector.length === 0 || selector.every((s) => s.includes(ATOMIC_STYLE_ID_PLACEHOLDER) === false))
|
|
149
|
+
selector.push(defaultSelector);
|
|
157
150
|
result.push({
|
|
158
151
|
selector,
|
|
159
|
-
property,
|
|
160
|
-
value
|
|
152
|
+
property: toKebab(k),
|
|
153
|
+
value: normalizeValue(v)
|
|
161
154
|
});
|
|
162
155
|
} else if (Array.isArray(v)) {
|
|
163
156
|
for (const styleItem of await transformStyleItems(v)) {
|
|
@@ -308,25 +301,23 @@ function keyframes() {
|
|
|
308
301
|
};
|
|
309
302
|
engine.keyframes.add(...configList);
|
|
310
303
|
engine.addPreflight((engine2, isFormatted) => {
|
|
311
|
-
const
|
|
304
|
+
const maybeUsedName = /* @__PURE__ */ new Set();
|
|
312
305
|
engine2.store.atomicStyles.forEach(({ content: { property, value } }) => {
|
|
313
306
|
if (property === "animationName") {
|
|
314
|
-
value.forEach((name) =>
|
|
307
|
+
value.forEach((name) => maybeUsedName.add(name));
|
|
315
308
|
return;
|
|
316
309
|
}
|
|
317
310
|
if (property === "animation") {
|
|
318
311
|
value.forEach((value2) => {
|
|
319
312
|
const animations = value2.split(",").map((v) => v.trim());
|
|
320
313
|
animations.forEach((animation) => {
|
|
321
|
-
|
|
322
|
-
if (isNotNullish(name))
|
|
323
|
-
used.add(name);
|
|
314
|
+
addToSet(maybeUsedName, ...animation.split(" "));
|
|
324
315
|
});
|
|
325
316
|
});
|
|
326
317
|
}
|
|
327
318
|
});
|
|
328
319
|
return renderCSSStyleBlocks(
|
|
329
|
-
new Map(Array.from(engine2.keyframes.store.entries()).filter(([name, { pruneUnused }]) => pruneUnused === false ||
|
|
320
|
+
new Map(Array.from(engine2.keyframes.store.entries()).filter(([name, { pruneUnused }]) => pruneUnused === false || maybeUsedName.has(name)).map(([name, { frames }]) => [
|
|
330
321
|
`@keyframes ${name}`,
|
|
331
322
|
{
|
|
332
323
|
properties: [],
|
|
@@ -885,11 +876,20 @@ class Engine {
|
|
|
885
876
|
});
|
|
886
877
|
return [...unknown, ...resolvedIds];
|
|
887
878
|
}
|
|
888
|
-
renderPreflights(isFormatted) {
|
|
879
|
+
async renderPreflights(isFormatted) {
|
|
889
880
|
const lineEnd = isFormatted ? "\n" : "";
|
|
890
|
-
return this.config.preflights.map((p) =>
|
|
881
|
+
return (await Promise.all(this.config.preflights.map((p) => {
|
|
882
|
+
const result = p(this, isFormatted);
|
|
883
|
+
if (typeof result === "string")
|
|
884
|
+
return result;
|
|
885
|
+
return renderPreflight({
|
|
886
|
+
engine: this,
|
|
887
|
+
preflight: result,
|
|
888
|
+
isFormatted
|
|
889
|
+
});
|
|
890
|
+
}))).join(lineEnd);
|
|
891
891
|
}
|
|
892
|
-
renderAtomicStyles(isFormatted, options = {}) {
|
|
892
|
+
async renderAtomicStyles(isFormatted, options = {}) {
|
|
893
893
|
const { atomicStyleIds = null, isPreview = false } = options;
|
|
894
894
|
const atomicStyles = atomicStyleIds == null ? [...this.store.atomicStyles.values()] : atomicStyleIds.map((id) => this.store.atomicStyles.get(id)).filter(isNotNullish);
|
|
895
895
|
return renderAtomicStyles({
|
|
@@ -1008,6 +1008,54 @@ function renderAtomicStyles(payload) {
|
|
|
1008
1008
|
});
|
|
1009
1009
|
return renderCSSStyleBlocks(blocks, isFormatted);
|
|
1010
1010
|
}
|
|
1011
|
+
async function _renderPreflight({
|
|
1012
|
+
engine,
|
|
1013
|
+
preflightDefinition,
|
|
1014
|
+
blocks = /* @__PURE__ */ new Map()
|
|
1015
|
+
}) {
|
|
1016
|
+
for (const [selector, propertiesOrDefinition] of Object.entries(preflightDefinition)) {
|
|
1017
|
+
const selectors2 = normalizeSelectors({
|
|
1018
|
+
selectors: await hooks.transformSelectors(engine.config.plugins, [selector]),
|
|
1019
|
+
defaultSelector: ""
|
|
1020
|
+
}).filter(Boolean);
|
|
1021
|
+
let currentBlocks = blocks;
|
|
1022
|
+
let currentBlockBody = null;
|
|
1023
|
+
selectors2.forEach((s, i) => {
|
|
1024
|
+
const isLast = i === selectors2.length - 1;
|
|
1025
|
+
currentBlocks.set(s, currentBlocks.get(s) || { properties: [] });
|
|
1026
|
+
if (isLast) {
|
|
1027
|
+
currentBlockBody = currentBlocks.get(s);
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
1030
|
+
currentBlocks = currentBlocks.get(s).children ||= /* @__PURE__ */ new Map();
|
|
1031
|
+
});
|
|
1032
|
+
for (const [k, v] of Object.entries(propertiesOrDefinition)) {
|
|
1033
|
+
if (isPropertyValue(v)) {
|
|
1034
|
+
const property = toKebab(k);
|
|
1035
|
+
const normalizedValue = normalizeValue(v);
|
|
1036
|
+
if (normalizedValue != null) {
|
|
1037
|
+
normalizedValue.forEach((value) => currentBlockBody.properties.push({ property, value }));
|
|
1038
|
+
}
|
|
1039
|
+
} else {
|
|
1040
|
+
currentBlockBody.children ||= /* @__PURE__ */ new Map();
|
|
1041
|
+
_renderPreflight({
|
|
1042
|
+
engine,
|
|
1043
|
+
preflightDefinition: v,
|
|
1044
|
+
blocks: currentBlockBody.children
|
|
1045
|
+
});
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
return blocks;
|
|
1050
|
+
}
|
|
1051
|
+
async function renderPreflight(payload) {
|
|
1052
|
+
const { engine, preflight, isFormatted } = payload;
|
|
1053
|
+
const blocks = await _renderPreflight({
|
|
1054
|
+
engine,
|
|
1055
|
+
preflightDefinition: preflight
|
|
1056
|
+
});
|
|
1057
|
+
return renderCSSStyleBlocks(blocks, isFormatted);
|
|
1058
|
+
}
|
|
1011
1059
|
|
|
1012
1060
|
exports.appendAutocompleteCssPropertyValues = appendAutocompleteCssPropertyValues;
|
|
1013
1061
|
exports.appendAutocompleteExtraCssProperties = appendAutocompleteExtraCssProperties;
|
package/dist/index.d.cts
CHANGED
|
@@ -281,19 +281,19 @@ interface StyleDefinition$1 {
|
|
|
281
281
|
[K: string]: PropertyValue | StyleDefinition$1 | StyleItem$1[];
|
|
282
282
|
}
|
|
283
283
|
type StyleItem$1 = string | StyleDefinition$1;
|
|
284
|
-
interface
|
|
284
|
+
interface ExtractedStyleContent {
|
|
285
285
|
selector: string[];
|
|
286
286
|
property: string;
|
|
287
287
|
value: string[] | Nullish;
|
|
288
288
|
}
|
|
289
|
-
interface
|
|
289
|
+
interface StyleContent {
|
|
290
290
|
selector: string[];
|
|
291
291
|
property: string;
|
|
292
292
|
value: string[];
|
|
293
293
|
}
|
|
294
294
|
interface AtomicStyle {
|
|
295
295
|
id: string;
|
|
296
|
-
content:
|
|
296
|
+
content: StyleContent;
|
|
297
297
|
}
|
|
298
298
|
interface CSSStyleBlockBody {
|
|
299
299
|
properties: {
|
|
@@ -358,14 +358,17 @@ interface EnginePlugin extends EnginePluginHooksOptions {
|
|
|
358
358
|
}
|
|
359
359
|
declare function defineEnginePlugin(plugin: EnginePlugin): EnginePlugin;
|
|
360
360
|
|
|
361
|
-
|
|
361
|
+
interface PreflightDefinition {
|
|
362
|
+
[selector: UnionString | ResolvedSelector]: ResolvedProperties | PreflightDefinition;
|
|
363
|
+
}
|
|
364
|
+
type PreflightFn = (engine: Engine, isFormatted: boolean) => string | PreflightDefinition;
|
|
362
365
|
/**
|
|
363
366
|
* PreflightConfig can be a string or a function that returns a string.
|
|
364
367
|
*
|
|
365
368
|
* 1. A string is a static preflight style.
|
|
366
369
|
* 2. A function is a dynamic preflight style that can use the engine instance to generate styles.
|
|
367
370
|
*/
|
|
368
|
-
type Preflight = string | PreflightFn;
|
|
371
|
+
type Preflight = string | PreflightDefinition | PreflightFn;
|
|
369
372
|
|
|
370
373
|
interface EngineConfig {
|
|
371
374
|
/**
|
|
@@ -436,7 +439,7 @@ interface ResolvedEngineConfig {
|
|
|
436
439
|
autocomplete: ResolvedAutocompleteConfig;
|
|
437
440
|
}
|
|
438
441
|
|
|
439
|
-
type ExtractFn = (styleDefinition: StyleDefinition$1) => Promise<
|
|
442
|
+
type ExtractFn = (styleDefinition: StyleDefinition$1) => Promise<ExtractedStyleContent[]>;
|
|
440
443
|
|
|
441
444
|
declare function defineEngineConfig(config: EngineConfig): EngineConfig;
|
|
442
445
|
declare function createEngine(config?: EngineConfig): Promise<Engine>;
|
|
@@ -459,11 +462,11 @@ declare class Engine {
|
|
|
459
462
|
appendAutocompleteCssPropertyValues(property: string, ...values: (string | number)[]): void;
|
|
460
463
|
addPreflight(preflight: Preflight): void;
|
|
461
464
|
use(...itemList: StyleItem$1[]): Promise<string[]>;
|
|
462
|
-
renderPreflights(isFormatted: boolean): string
|
|
465
|
+
renderPreflights(isFormatted: boolean): Promise<string>;
|
|
463
466
|
renderAtomicStyles(isFormatted: boolean, options?: {
|
|
464
467
|
atomicStyleIds?: string[];
|
|
465
468
|
isPreview?: boolean;
|
|
466
|
-
}): string
|
|
469
|
+
}): Promise<string>;
|
|
467
470
|
}
|
|
468
471
|
|
|
469
472
|
declare function setWarnFn(fn: (...args: any[]) => void): void;
|
package/dist/index.d.mts
CHANGED
|
@@ -281,19 +281,19 @@ interface StyleDefinition$1 {
|
|
|
281
281
|
[K: string]: PropertyValue | StyleDefinition$1 | StyleItem$1[];
|
|
282
282
|
}
|
|
283
283
|
type StyleItem$1 = string | StyleDefinition$1;
|
|
284
|
-
interface
|
|
284
|
+
interface ExtractedStyleContent {
|
|
285
285
|
selector: string[];
|
|
286
286
|
property: string;
|
|
287
287
|
value: string[] | Nullish;
|
|
288
288
|
}
|
|
289
|
-
interface
|
|
289
|
+
interface StyleContent {
|
|
290
290
|
selector: string[];
|
|
291
291
|
property: string;
|
|
292
292
|
value: string[];
|
|
293
293
|
}
|
|
294
294
|
interface AtomicStyle {
|
|
295
295
|
id: string;
|
|
296
|
-
content:
|
|
296
|
+
content: StyleContent;
|
|
297
297
|
}
|
|
298
298
|
interface CSSStyleBlockBody {
|
|
299
299
|
properties: {
|
|
@@ -358,14 +358,17 @@ interface EnginePlugin extends EnginePluginHooksOptions {
|
|
|
358
358
|
}
|
|
359
359
|
declare function defineEnginePlugin(plugin: EnginePlugin): EnginePlugin;
|
|
360
360
|
|
|
361
|
-
|
|
361
|
+
interface PreflightDefinition {
|
|
362
|
+
[selector: UnionString | ResolvedSelector]: ResolvedProperties | PreflightDefinition;
|
|
363
|
+
}
|
|
364
|
+
type PreflightFn = (engine: Engine, isFormatted: boolean) => string | PreflightDefinition;
|
|
362
365
|
/**
|
|
363
366
|
* PreflightConfig can be a string or a function that returns a string.
|
|
364
367
|
*
|
|
365
368
|
* 1. A string is a static preflight style.
|
|
366
369
|
* 2. A function is a dynamic preflight style that can use the engine instance to generate styles.
|
|
367
370
|
*/
|
|
368
|
-
type Preflight = string | PreflightFn;
|
|
371
|
+
type Preflight = string | PreflightDefinition | PreflightFn;
|
|
369
372
|
|
|
370
373
|
interface EngineConfig {
|
|
371
374
|
/**
|
|
@@ -436,7 +439,7 @@ interface ResolvedEngineConfig {
|
|
|
436
439
|
autocomplete: ResolvedAutocompleteConfig;
|
|
437
440
|
}
|
|
438
441
|
|
|
439
|
-
type ExtractFn = (styleDefinition: StyleDefinition$1) => Promise<
|
|
442
|
+
type ExtractFn = (styleDefinition: StyleDefinition$1) => Promise<ExtractedStyleContent[]>;
|
|
440
443
|
|
|
441
444
|
declare function defineEngineConfig(config: EngineConfig): EngineConfig;
|
|
442
445
|
declare function createEngine(config?: EngineConfig): Promise<Engine>;
|
|
@@ -459,11 +462,11 @@ declare class Engine {
|
|
|
459
462
|
appendAutocompleteCssPropertyValues(property: string, ...values: (string | number)[]): void;
|
|
460
463
|
addPreflight(preflight: Preflight): void;
|
|
461
464
|
use(...itemList: StyleItem$1[]): Promise<string[]>;
|
|
462
|
-
renderPreflights(isFormatted: boolean): string
|
|
465
|
+
renderPreflights(isFormatted: boolean): Promise<string>;
|
|
463
466
|
renderAtomicStyles(isFormatted: boolean, options?: {
|
|
464
467
|
atomicStyleIds?: string[];
|
|
465
468
|
isPreview?: boolean;
|
|
466
|
-
}): string
|
|
469
|
+
}): Promise<string>;
|
|
467
470
|
}
|
|
468
471
|
|
|
469
472
|
declare function setWarnFn(fn: (...args: any[]) => void): void;
|
package/dist/index.d.ts
CHANGED
|
@@ -281,19 +281,19 @@ interface StyleDefinition$1 {
|
|
|
281
281
|
[K: string]: PropertyValue | StyleDefinition$1 | StyleItem$1[];
|
|
282
282
|
}
|
|
283
283
|
type StyleItem$1 = string | StyleDefinition$1;
|
|
284
|
-
interface
|
|
284
|
+
interface ExtractedStyleContent {
|
|
285
285
|
selector: string[];
|
|
286
286
|
property: string;
|
|
287
287
|
value: string[] | Nullish;
|
|
288
288
|
}
|
|
289
|
-
interface
|
|
289
|
+
interface StyleContent {
|
|
290
290
|
selector: string[];
|
|
291
291
|
property: string;
|
|
292
292
|
value: string[];
|
|
293
293
|
}
|
|
294
294
|
interface AtomicStyle {
|
|
295
295
|
id: string;
|
|
296
|
-
content:
|
|
296
|
+
content: StyleContent;
|
|
297
297
|
}
|
|
298
298
|
interface CSSStyleBlockBody {
|
|
299
299
|
properties: {
|
|
@@ -358,14 +358,17 @@ interface EnginePlugin extends EnginePluginHooksOptions {
|
|
|
358
358
|
}
|
|
359
359
|
declare function defineEnginePlugin(plugin: EnginePlugin): EnginePlugin;
|
|
360
360
|
|
|
361
|
-
|
|
361
|
+
interface PreflightDefinition {
|
|
362
|
+
[selector: UnionString | ResolvedSelector]: ResolvedProperties | PreflightDefinition;
|
|
363
|
+
}
|
|
364
|
+
type PreflightFn = (engine: Engine, isFormatted: boolean) => string | PreflightDefinition;
|
|
362
365
|
/**
|
|
363
366
|
* PreflightConfig can be a string or a function that returns a string.
|
|
364
367
|
*
|
|
365
368
|
* 1. A string is a static preflight style.
|
|
366
369
|
* 2. A function is a dynamic preflight style that can use the engine instance to generate styles.
|
|
367
370
|
*/
|
|
368
|
-
type Preflight = string | PreflightFn;
|
|
371
|
+
type Preflight = string | PreflightDefinition | PreflightFn;
|
|
369
372
|
|
|
370
373
|
interface EngineConfig {
|
|
371
374
|
/**
|
|
@@ -436,7 +439,7 @@ interface ResolvedEngineConfig {
|
|
|
436
439
|
autocomplete: ResolvedAutocompleteConfig;
|
|
437
440
|
}
|
|
438
441
|
|
|
439
|
-
type ExtractFn = (styleDefinition: StyleDefinition$1) => Promise<
|
|
442
|
+
type ExtractFn = (styleDefinition: StyleDefinition$1) => Promise<ExtractedStyleContent[]>;
|
|
440
443
|
|
|
441
444
|
declare function defineEngineConfig(config: EngineConfig): EngineConfig;
|
|
442
445
|
declare function createEngine(config?: EngineConfig): Promise<Engine>;
|
|
@@ -459,11 +462,11 @@ declare class Engine {
|
|
|
459
462
|
appendAutocompleteCssPropertyValues(property: string, ...values: (string | number)[]): void;
|
|
460
463
|
addPreflight(preflight: Preflight): void;
|
|
461
464
|
use(...itemList: StyleItem$1[]): Promise<string[]>;
|
|
462
|
-
renderPreflights(isFormatted: boolean): string
|
|
465
|
+
renderPreflights(isFormatted: boolean): Promise<string>;
|
|
463
466
|
renderAtomicStyles(isFormatted: boolean, options?: {
|
|
464
467
|
atomicStyleIds?: string[];
|
|
465
468
|
isPreview?: boolean;
|
|
466
|
-
}): string
|
|
469
|
+
}): Promise<string>;
|
|
467
470
|
}
|
|
468
471
|
|
|
469
472
|
declare function setWarnFn(fn: (...args: any[]) => void): void;
|
package/dist/index.mjs
CHANGED
|
@@ -95,7 +95,6 @@ function replaceBySplitAndJoin(str, split, mapFn, join) {
|
|
|
95
95
|
return splitted.join(join);
|
|
96
96
|
}
|
|
97
97
|
const RE_SPLIT = /\s*,\s*/g;
|
|
98
|
-
const DEFAULT_SELECTOR_PLACEHOLDER = "$";
|
|
99
98
|
const DEFAULT_SELECTOR_PLACEHOLDER_RE_GLOBAL = /\$/g;
|
|
100
99
|
const ATTRIBUTE_SUFFIX_MATCH = "$=";
|
|
101
100
|
const ATTRIBUTE_SUFFIX_MATCH_RE_GLOBAL = /\$=/g;
|
|
@@ -103,16 +102,9 @@ function normalizeSelectors({
|
|
|
103
102
|
selectors,
|
|
104
103
|
defaultSelector
|
|
105
104
|
}) {
|
|
106
|
-
|
|
107
|
-
return [defaultSelector];
|
|
108
|
-
const normalized = selectors.map((s) => s.replace(RE_SPLIT, ","));
|
|
109
|
-
const lastSelector = selectors[selectors.length - 1];
|
|
110
|
-
if (lastSelector.includes(ATOMIC_STYLE_ID_PLACEHOLDER) === false && lastSelector.includes(DEFAULT_SELECTOR_PLACEHOLDER) === false) {
|
|
111
|
-
normalized.push(DEFAULT_SELECTOR_PLACEHOLDER);
|
|
112
|
-
}
|
|
113
|
-
return normalized.map(
|
|
105
|
+
const normalized = selectors.map(
|
|
114
106
|
(s) => replaceBySplitAndJoin(
|
|
115
|
-
s,
|
|
107
|
+
s.replace(RE_SPLIT, ","),
|
|
116
108
|
ATOMIC_STYLE_ID_PLACEHOLDER_RE_GLOBAL,
|
|
117
109
|
(a) => replaceBySplitAndJoin(
|
|
118
110
|
a,
|
|
@@ -128,6 +120,7 @@ function normalizeSelectors({
|
|
|
128
120
|
ATOMIC_STYLE_ID_PLACEHOLDER
|
|
129
121
|
)
|
|
130
122
|
);
|
|
123
|
+
return normalized;
|
|
131
124
|
}
|
|
132
125
|
function normalizeValue(value) {
|
|
133
126
|
if (value == null)
|
|
@@ -143,19 +136,19 @@ async function extract({
|
|
|
143
136
|
transformStyleItems,
|
|
144
137
|
transformStyleDefinitions
|
|
145
138
|
}) {
|
|
146
|
-
const selector = normalizeSelectors({
|
|
147
|
-
selectors: await transformSelectors(levels),
|
|
148
|
-
defaultSelector
|
|
149
|
-
});
|
|
150
139
|
for (const definition of await transformStyleDefinitions([styleDefinition])) {
|
|
151
140
|
for (const [k, v] of Object.entries(definition)) {
|
|
152
141
|
if (isPropertyValue(v)) {
|
|
153
|
-
const
|
|
154
|
-
|
|
142
|
+
const selector = normalizeSelectors({
|
|
143
|
+
selectors: await transformSelectors(levels),
|
|
144
|
+
defaultSelector
|
|
145
|
+
});
|
|
146
|
+
if (selector.length === 0 || selector.every((s) => s.includes(ATOMIC_STYLE_ID_PLACEHOLDER) === false))
|
|
147
|
+
selector.push(defaultSelector);
|
|
155
148
|
result.push({
|
|
156
149
|
selector,
|
|
157
|
-
property,
|
|
158
|
-
value
|
|
150
|
+
property: toKebab(k),
|
|
151
|
+
value: normalizeValue(v)
|
|
159
152
|
});
|
|
160
153
|
} else if (Array.isArray(v)) {
|
|
161
154
|
for (const styleItem of await transformStyleItems(v)) {
|
|
@@ -306,25 +299,23 @@ function keyframes() {
|
|
|
306
299
|
};
|
|
307
300
|
engine.keyframes.add(...configList);
|
|
308
301
|
engine.addPreflight((engine2, isFormatted) => {
|
|
309
|
-
const
|
|
302
|
+
const maybeUsedName = /* @__PURE__ */ new Set();
|
|
310
303
|
engine2.store.atomicStyles.forEach(({ content: { property, value } }) => {
|
|
311
304
|
if (property === "animationName") {
|
|
312
|
-
value.forEach((name) =>
|
|
305
|
+
value.forEach((name) => maybeUsedName.add(name));
|
|
313
306
|
return;
|
|
314
307
|
}
|
|
315
308
|
if (property === "animation") {
|
|
316
309
|
value.forEach((value2) => {
|
|
317
310
|
const animations = value2.split(",").map((v) => v.trim());
|
|
318
311
|
animations.forEach((animation) => {
|
|
319
|
-
|
|
320
|
-
if (isNotNullish(name))
|
|
321
|
-
used.add(name);
|
|
312
|
+
addToSet(maybeUsedName, ...animation.split(" "));
|
|
322
313
|
});
|
|
323
314
|
});
|
|
324
315
|
}
|
|
325
316
|
});
|
|
326
317
|
return renderCSSStyleBlocks(
|
|
327
|
-
new Map(Array.from(engine2.keyframes.store.entries()).filter(([name, { pruneUnused }]) => pruneUnused === false ||
|
|
318
|
+
new Map(Array.from(engine2.keyframes.store.entries()).filter(([name, { pruneUnused }]) => pruneUnused === false || maybeUsedName.has(name)).map(([name, { frames }]) => [
|
|
328
319
|
`@keyframes ${name}`,
|
|
329
320
|
{
|
|
330
321
|
properties: [],
|
|
@@ -883,11 +874,20 @@ class Engine {
|
|
|
883
874
|
});
|
|
884
875
|
return [...unknown, ...resolvedIds];
|
|
885
876
|
}
|
|
886
|
-
renderPreflights(isFormatted) {
|
|
877
|
+
async renderPreflights(isFormatted) {
|
|
887
878
|
const lineEnd = isFormatted ? "\n" : "";
|
|
888
|
-
return this.config.preflights.map((p) =>
|
|
879
|
+
return (await Promise.all(this.config.preflights.map((p) => {
|
|
880
|
+
const result = p(this, isFormatted);
|
|
881
|
+
if (typeof result === "string")
|
|
882
|
+
return result;
|
|
883
|
+
return renderPreflight({
|
|
884
|
+
engine: this,
|
|
885
|
+
preflight: result,
|
|
886
|
+
isFormatted
|
|
887
|
+
});
|
|
888
|
+
}))).join(lineEnd);
|
|
889
889
|
}
|
|
890
|
-
renderAtomicStyles(isFormatted, options = {}) {
|
|
890
|
+
async renderAtomicStyles(isFormatted, options = {}) {
|
|
891
891
|
const { atomicStyleIds = null, isPreview = false } = options;
|
|
892
892
|
const atomicStyles = atomicStyleIds == null ? [...this.store.atomicStyles.values()] : atomicStyleIds.map((id) => this.store.atomicStyles.get(id)).filter(isNotNullish);
|
|
893
893
|
return renderAtomicStyles({
|
|
@@ -1006,5 +1006,53 @@ function renderAtomicStyles(payload) {
|
|
|
1006
1006
|
});
|
|
1007
1007
|
return renderCSSStyleBlocks(blocks, isFormatted);
|
|
1008
1008
|
}
|
|
1009
|
+
async function _renderPreflight({
|
|
1010
|
+
engine,
|
|
1011
|
+
preflightDefinition,
|
|
1012
|
+
blocks = /* @__PURE__ */ new Map()
|
|
1013
|
+
}) {
|
|
1014
|
+
for (const [selector, propertiesOrDefinition] of Object.entries(preflightDefinition)) {
|
|
1015
|
+
const selectors2 = normalizeSelectors({
|
|
1016
|
+
selectors: await hooks.transformSelectors(engine.config.plugins, [selector]),
|
|
1017
|
+
defaultSelector: ""
|
|
1018
|
+
}).filter(Boolean);
|
|
1019
|
+
let currentBlocks = blocks;
|
|
1020
|
+
let currentBlockBody = null;
|
|
1021
|
+
selectors2.forEach((s, i) => {
|
|
1022
|
+
const isLast = i === selectors2.length - 1;
|
|
1023
|
+
currentBlocks.set(s, currentBlocks.get(s) || { properties: [] });
|
|
1024
|
+
if (isLast) {
|
|
1025
|
+
currentBlockBody = currentBlocks.get(s);
|
|
1026
|
+
return;
|
|
1027
|
+
}
|
|
1028
|
+
currentBlocks = currentBlocks.get(s).children ||= /* @__PURE__ */ new Map();
|
|
1029
|
+
});
|
|
1030
|
+
for (const [k, v] of Object.entries(propertiesOrDefinition)) {
|
|
1031
|
+
if (isPropertyValue(v)) {
|
|
1032
|
+
const property = toKebab(k);
|
|
1033
|
+
const normalizedValue = normalizeValue(v);
|
|
1034
|
+
if (normalizedValue != null) {
|
|
1035
|
+
normalizedValue.forEach((value) => currentBlockBody.properties.push({ property, value }));
|
|
1036
|
+
}
|
|
1037
|
+
} else {
|
|
1038
|
+
currentBlockBody.children ||= /* @__PURE__ */ new Map();
|
|
1039
|
+
_renderPreflight({
|
|
1040
|
+
engine,
|
|
1041
|
+
preflightDefinition: v,
|
|
1042
|
+
blocks: currentBlockBody.children
|
|
1043
|
+
});
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
return blocks;
|
|
1048
|
+
}
|
|
1049
|
+
async function renderPreflight(payload) {
|
|
1050
|
+
const { engine, preflight, isFormatted } = payload;
|
|
1051
|
+
const blocks = await _renderPreflight({
|
|
1052
|
+
engine,
|
|
1053
|
+
preflightDefinition: preflight
|
|
1054
|
+
});
|
|
1055
|
+
return renderCSSStyleBlocks(blocks, isFormatted);
|
|
1056
|
+
}
|
|
1009
1057
|
|
|
1010
1058
|
export { appendAutocompleteCssPropertyValues, appendAutocompleteExtraCssProperties, appendAutocompleteExtraProperties, appendAutocompletePropertyValues, appendAutocompleteSelectors, appendAutocompleteStyleItemStrings, createEngine, defineEngineConfig, defineEnginePlugin, renderCSSStyleBlocks, setWarnFn, warn };
|