@pikacss/core 0.0.50 → 0.0.51
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/README.md +1 -1
- package/dist/index.d.mts +26 -9
- package/dist/index.mjs +71 -7
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -418,23 +418,27 @@ declare module '@pikacss/core' {
|
|
|
418
418
|
declare function shortcuts(): EnginePlugin;
|
|
419
419
|
declare class ShortcutResolver extends RecursiveResolver<InternalStyleItem> {}
|
|
420
420
|
//#endregion
|
|
421
|
-
//#region src/internal/generated-property-semantics.d.ts
|
|
422
|
-
declare const VARIABLE_SEMANTIC_FAMILIES: readonly ["color", "length", "time", "number", "percentage", "angle", "image", "url", "position", "easing", "font-family"];
|
|
423
|
-
type VariableSemanticFamily = typeof VARIABLE_SEMANTIC_FAMILIES[number];
|
|
424
|
-
//#endregion
|
|
425
421
|
//#region src/internal/plugins/variables.d.ts
|
|
426
422
|
type ResolvedCSSProperty = keyof ResolvedCSSProperties;
|
|
423
|
+
declare const VARIABLE_SEMANTIC_TYPE_PROPERTIES: {
|
|
424
|
+
readonly color: readonly ["accent-color", "background-color", "border-block-color", "border-block-end-color", "border-block-start-color", "border-bottom-color", "border-inline-color", "border-inline-end-color", "border-inline-start-color", "border-left-color", "border-right-color", "border-top-color", "caret-color", "color", "column-rule-color", "flood-color", "lighting-color", "outline-color", "stop-color", "stroke-color", "text-decoration-color", "text-emphasis-color"];
|
|
425
|
+
readonly length: readonly ["block-size", "border-bottom-width", "border-left-width", "border-right-width", "border-spacing", "border-top-width", "bottom", "font-size", "height", "inline-size", "inset-block-end", "inset-block-start", "inset-inline-end", "inset-inline-start", "left", "letter-spacing", "max-height", "max-width", "min-height", "min-width", "outline-offset", "right", "top", "width"];
|
|
426
|
+
readonly time: readonly ["animation-delay", "animation-duration", "transition-delay", "transition-duration"];
|
|
427
|
+
readonly number: readonly ["fill-opacity", "flex-grow", "flex-shrink", "flood-opacity", "opacity", "order", "orphans", "stop-opacity", "stroke-opacity", "widows"];
|
|
428
|
+
readonly easing: readonly ["animation-timing-function", "transition-timing-function"];
|
|
429
|
+
readonly 'font-family': readonly ["font-family"];
|
|
430
|
+
};
|
|
427
431
|
/**
|
|
428
432
|
* Semantic type label for a CSS variable, used to derive which CSS properties it can auto-complete as a value for.
|
|
429
433
|
*
|
|
430
|
-
* @remarks
|
|
434
|
+
* @remarks Supported semantic families are `'color'`, `'length'`, `'time'`, `'number'`, `'easing'`, and `'font-family'`. Each expands to the CSS properties with a real autocomplete mapping at registration time.
|
|
431
435
|
*
|
|
432
436
|
* @example
|
|
433
437
|
* ```ts
|
|
434
438
|
* const type: VariableSemanticType = 'color'
|
|
435
439
|
* ```
|
|
436
440
|
*/
|
|
437
|
-
type VariableSemanticType =
|
|
441
|
+
type VariableSemanticType = keyof typeof VARIABLE_SEMANTIC_TYPE_PROPERTIES;
|
|
438
442
|
/**
|
|
439
443
|
* Controls how a CSS variable participates in the autocomplete type surface.
|
|
440
444
|
*
|
|
@@ -534,15 +538,28 @@ type VariablesDefinition = { [key in UnionString | ResolvedSelector]?: Variable
|
|
|
534
538
|
* @example
|
|
535
539
|
* ```ts
|
|
536
540
|
* const config: VariablesConfig = {
|
|
537
|
-
*
|
|
541
|
+
* colors: { '--color-primary': '#3b82f6' },
|
|
542
|
+
* others: { '--shadow-elevated': '0 12px 40px rgb(0 0 0 / 0.12)' },
|
|
538
543
|
* pruneUnused: true,
|
|
539
544
|
* safeList: ['--color-primary'],
|
|
540
545
|
* }
|
|
541
546
|
* ```
|
|
542
547
|
*/
|
|
543
548
|
interface VariablesConfig {
|
|
544
|
-
/**
|
|
545
|
-
|
|
549
|
+
/** Color variables. These automatically infer `semanticType: 'color'`. */
|
|
550
|
+
colors?: Arrayable<VariablesDefinition>;
|
|
551
|
+
/** Length variables. These automatically infer `semanticType: 'length'`. */
|
|
552
|
+
lengths?: Arrayable<VariablesDefinition>;
|
|
553
|
+
/** Time variables. These automatically infer `semanticType: 'time'`. */
|
|
554
|
+
times?: Arrayable<VariablesDefinition>;
|
|
555
|
+
/** Number variables. These automatically infer `semanticType: 'number'`. */
|
|
556
|
+
numbers?: Arrayable<VariablesDefinition>;
|
|
557
|
+
/** Easing variables. These automatically infer `semanticType: 'easing'`. */
|
|
558
|
+
easings?: Arrayable<VariablesDefinition>;
|
|
559
|
+
/** Font-family variables. These automatically infer `semanticType: 'font-family'`. */
|
|
560
|
+
fontFamilies?: Arrayable<VariablesDefinition>;
|
|
561
|
+
/** Variables without a semantic bucket. These keep the default untyped autocomplete behaviour. */
|
|
562
|
+
others?: Arrayable<VariablesDefinition>;
|
|
546
563
|
/**
|
|
547
564
|
* Default pruning policy for variables that are not referenced by any atomic style or preflight.
|
|
548
565
|
*
|
package/dist/index.mjs
CHANGED
|
@@ -2438,6 +2438,14 @@ const VARIABLE_SEMANTIC_FAMILY_PROPERTIES = {
|
|
|
2438
2438
|
};
|
|
2439
2439
|
//#endregion
|
|
2440
2440
|
//#region src/internal/plugins/variables.ts
|
|
2441
|
+
const VARIABLE_SEMANTIC_TYPE_PROPERTIES = {
|
|
2442
|
+
"color": VARIABLE_SEMANTIC_FAMILY_PROPERTIES.color,
|
|
2443
|
+
"length": VARIABLE_SEMANTIC_FAMILY_PROPERTIES.length,
|
|
2444
|
+
"time": VARIABLE_SEMANTIC_FAMILY_PROPERTIES.time,
|
|
2445
|
+
"number": VARIABLE_SEMANTIC_FAMILY_PROPERTIES.number,
|
|
2446
|
+
"easing": VARIABLE_SEMANTIC_FAMILY_PROPERTIES.easing,
|
|
2447
|
+
"font-family": VARIABLE_SEMANTIC_FAMILY_PROPERTIES["font-family"]
|
|
2448
|
+
};
|
|
2441
2449
|
/**
|
|
2442
2450
|
* Built-in engine plugin that provides CSS custom properties (variables) with smart pruning and autocomplete integration.
|
|
2443
2451
|
*
|
|
@@ -2458,7 +2466,7 @@ function variables() {
|
|
|
2458
2466
|
name: "core:variables",
|
|
2459
2467
|
rawConfigConfigured(config) {
|
|
2460
2468
|
resolveVariables = createResolveVariablesFn({ pruneUnused: config.variables?.pruneUnused });
|
|
2461
|
-
rawVariables =
|
|
2469
|
+
rawVariables = normalizeVariablesConfig(config.variables);
|
|
2462
2470
|
safeSet = new Set(config.variables?.safeList ?? []);
|
|
2463
2471
|
},
|
|
2464
2472
|
configureEngine(engine) {
|
|
@@ -2526,13 +2534,69 @@ function variables() {
|
|
|
2526
2534
|
}
|
|
2527
2535
|
});
|
|
2528
2536
|
}
|
|
2529
|
-
function
|
|
2530
|
-
|
|
2531
|
-
|
|
2537
|
+
function normalizeVariablesConfig(config) {
|
|
2538
|
+
if (config == null) return [];
|
|
2539
|
+
const merged = {};
|
|
2540
|
+
mergeVariablesBucket(merged, config.colors, "color");
|
|
2541
|
+
mergeVariablesBucket(merged, config.lengths, "length");
|
|
2542
|
+
mergeVariablesBucket(merged, config.times, "time");
|
|
2543
|
+
mergeVariablesBucket(merged, config.numbers, "number");
|
|
2544
|
+
mergeVariablesBucket(merged, config.easings, "easing");
|
|
2545
|
+
mergeVariablesBucket(merged, config.fontFamilies, "font-family");
|
|
2546
|
+
mergeVariablesBucket(merged, config.others);
|
|
2547
|
+
return Object.keys(merged).length > 0 ? [merged] : [];
|
|
2548
|
+
}
|
|
2549
|
+
function mergeVariablesBucket(target, definitions, semanticType) {
|
|
2550
|
+
if (definitions == null) return;
|
|
2551
|
+
[definitions].flat().forEach((definition) => mergeVariablesDefinition(target, applyBucketSemanticType(definition, semanticType)));
|
|
2552
|
+
}
|
|
2553
|
+
function mergeVariablesDefinition(target, source) {
|
|
2554
|
+
for (const [key, value] of Object.entries(source)) {
|
|
2555
|
+
if (!key.startsWith("--") && isPlainObjectRecord(value) && isPlainObjectRecord(target[key])) {
|
|
2556
|
+
mergeVariablesDefinition(target[key], value);
|
|
2557
|
+
continue;
|
|
2558
|
+
}
|
|
2559
|
+
target[key] = value;
|
|
2532
2560
|
}
|
|
2561
|
+
return target;
|
|
2562
|
+
}
|
|
2563
|
+
function applyBucketSemanticType(definition, semanticType) {
|
|
2564
|
+
const result = {};
|
|
2565
|
+
for (const [key, value] of Object.entries(definition)) {
|
|
2566
|
+
if (key.startsWith("--")) {
|
|
2567
|
+
if (semanticType == null) {
|
|
2568
|
+
result[key] = value;
|
|
2569
|
+
continue;
|
|
2570
|
+
}
|
|
2571
|
+
if (isPlainObjectRecord(value)) {
|
|
2572
|
+
const variableValue = value;
|
|
2573
|
+
result[key] = {
|
|
2574
|
+
...variableValue,
|
|
2575
|
+
semanticType: mergeSemanticTypes(semanticType, variableValue.semanticType)
|
|
2576
|
+
};
|
|
2577
|
+
continue;
|
|
2578
|
+
}
|
|
2579
|
+
result[key] = {
|
|
2580
|
+
value,
|
|
2581
|
+
semanticType
|
|
2582
|
+
};
|
|
2583
|
+
continue;
|
|
2584
|
+
}
|
|
2585
|
+
result[key] = isPlainObjectRecord(value) ? applyBucketSemanticType(value, semanticType) : value;
|
|
2586
|
+
}
|
|
2587
|
+
return result;
|
|
2588
|
+
}
|
|
2589
|
+
function mergeSemanticTypes(semanticType, existingSemanticType) {
|
|
2590
|
+
const merged = Array.from(new Set([semanticType, ...existingSemanticType == null ? [] : [existingSemanticType].flat()]));
|
|
2591
|
+
return merged.length === 1 ? merged[0] : merged;
|
|
2592
|
+
}
|
|
2593
|
+
function isPlainObjectRecord(value) {
|
|
2594
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2595
|
+
}
|
|
2596
|
+
function createResolveVariablesFn({ pruneUnused: defaultPruneUnused = true } = {}) {
|
|
2533
2597
|
function _resolveVariables(variables, levels, result) {
|
|
2534
2598
|
for (const [key, value] of Object.entries(variables)) if (key.startsWith("--")) {
|
|
2535
|
-
const { value: varValue, semanticType, autocomplete = {}, pruneUnused = defaultPruneUnused } =
|
|
2599
|
+
const { value: varValue, semanticType, autocomplete = {}, pruneUnused = defaultPruneUnused } = isPlainObjectRecord(value) ? value : { value };
|
|
2536
2600
|
result.push({
|
|
2537
2601
|
name: key,
|
|
2538
2602
|
value: varValue,
|
|
@@ -2548,7 +2612,7 @@ function createResolveVariablesFn({ pruneUnused: defaultPruneUnused = true } = {
|
|
|
2548
2612
|
pruneUnused
|
|
2549
2613
|
});
|
|
2550
2614
|
} else {
|
|
2551
|
-
if (!
|
|
2615
|
+
if (!isPlainObjectRecord(value)) {
|
|
2552
2616
|
log.warn(`Invalid variables scope for selector "${key}". Expected a nested object, received ${typeof value}. Skipping.`);
|
|
2553
2617
|
continue;
|
|
2554
2618
|
}
|
|
@@ -2570,7 +2634,7 @@ function resolveAutocompleteValueTargets({ name, asValueOf, semanticType }) {
|
|
|
2570
2634
|
targets.add(target);
|
|
2571
2635
|
});
|
|
2572
2636
|
semanticTypes.forEach((family) => {
|
|
2573
|
-
const properties =
|
|
2637
|
+
const properties = VARIABLE_SEMANTIC_TYPE_PROPERTIES[family];
|
|
2574
2638
|
if (properties != null) {
|
|
2575
2639
|
properties.forEach((property) => targets.add(property));
|
|
2576
2640
|
return;
|