@pikacss/core 0.0.49 → 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 +2487 -1160
- package/dist/index.mjs +75 -12
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1293,13 +1293,13 @@ function getAtomicStyleId({ content, prefix, stored }) {
|
|
|
1293
1293
|
* ```
|
|
1294
1294
|
*/
|
|
1295
1295
|
function resolveAtomicStyle({ content, prefix, store, resolvedIdsByBaseKey }) {
|
|
1296
|
-
const reusableId =
|
|
1296
|
+
const reusableId = findReusableAtomicStyleId({
|
|
1297
1297
|
content,
|
|
1298
1298
|
store,
|
|
1299
1299
|
resolvedIdsByBaseKey
|
|
1300
1300
|
});
|
|
1301
1301
|
if (reusableId != null) {
|
|
1302
|
-
log.debug(`
|
|
1302
|
+
log.debug(`Atomic style reused: ${reusableId}`);
|
|
1303
1303
|
return { id: reusableId };
|
|
1304
1304
|
}
|
|
1305
1305
|
const id = getAtomicStyleId({
|
|
@@ -1405,11 +1405,10 @@ function getRequiredAtomicStyleOrder({ dependencyKeys, store, resolvedIdsByBaseK
|
|
|
1405
1405
|
}
|
|
1406
1406
|
return requiredOrder;
|
|
1407
1407
|
}
|
|
1408
|
-
function
|
|
1409
|
-
if (isOrderSensitiveContent(content) === false) return void 0;
|
|
1408
|
+
function findReusableAtomicStyleId({ content, store, resolvedIdsByBaseKey }) {
|
|
1410
1409
|
const baseKey = getAtomicStyleBaseKey(content);
|
|
1411
1410
|
const requiredOrder = getRequiredAtomicStyleOrder({
|
|
1412
|
-
dependencyKeys: content.orderSensitiveTo,
|
|
1411
|
+
dependencyKeys: content.orderSensitiveTo ?? [],
|
|
1413
1412
|
store,
|
|
1414
1413
|
resolvedIdsByBaseKey
|
|
1415
1414
|
});
|
|
@@ -2439,6 +2438,14 @@ const VARIABLE_SEMANTIC_FAMILY_PROPERTIES = {
|
|
|
2439
2438
|
};
|
|
2440
2439
|
//#endregion
|
|
2441
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
|
+
};
|
|
2442
2449
|
/**
|
|
2443
2450
|
* Built-in engine plugin that provides CSS custom properties (variables) with smart pruning and autocomplete integration.
|
|
2444
2451
|
*
|
|
@@ -2459,7 +2466,7 @@ function variables() {
|
|
|
2459
2466
|
name: "core:variables",
|
|
2460
2467
|
rawConfigConfigured(config) {
|
|
2461
2468
|
resolveVariables = createResolveVariablesFn({ pruneUnused: config.variables?.pruneUnused });
|
|
2462
|
-
rawVariables =
|
|
2469
|
+
rawVariables = normalizeVariablesConfig(config.variables);
|
|
2463
2470
|
safeSet = new Set(config.variables?.safeList ?? []);
|
|
2464
2471
|
},
|
|
2465
2472
|
configureEngine(engine) {
|
|
@@ -2527,13 +2534,69 @@ function variables() {
|
|
|
2527
2534
|
}
|
|
2528
2535
|
});
|
|
2529
2536
|
}
|
|
2530
|
-
function
|
|
2531
|
-
|
|
2532
|
-
|
|
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;
|
|
2533
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 } = {}) {
|
|
2534
2597
|
function _resolveVariables(variables, levels, result) {
|
|
2535
2598
|
for (const [key, value] of Object.entries(variables)) if (key.startsWith("--")) {
|
|
2536
|
-
const { value: varValue, semanticType, autocomplete = {}, pruneUnused = defaultPruneUnused } =
|
|
2599
|
+
const { value: varValue, semanticType, autocomplete = {}, pruneUnused = defaultPruneUnused } = isPlainObjectRecord(value) ? value : { value };
|
|
2537
2600
|
result.push({
|
|
2538
2601
|
name: key,
|
|
2539
2602
|
value: varValue,
|
|
@@ -2549,7 +2612,7 @@ function createResolveVariablesFn({ pruneUnused: defaultPruneUnused = true } = {
|
|
|
2549
2612
|
pruneUnused
|
|
2550
2613
|
});
|
|
2551
2614
|
} else {
|
|
2552
|
-
if (!
|
|
2615
|
+
if (!isPlainObjectRecord(value)) {
|
|
2553
2616
|
log.warn(`Invalid variables scope for selector "${key}". Expected a nested object, received ${typeof value}. Skipping.`);
|
|
2554
2617
|
continue;
|
|
2555
2618
|
}
|
|
@@ -2571,7 +2634,7 @@ function resolveAutocompleteValueTargets({ name, asValueOf, semanticType }) {
|
|
|
2571
2634
|
targets.add(target);
|
|
2572
2635
|
});
|
|
2573
2636
|
semanticTypes.forEach((family) => {
|
|
2574
|
-
const properties =
|
|
2637
|
+
const properties = VARIABLE_SEMANTIC_TYPE_PROPERTIES[family];
|
|
2575
2638
|
if (properties != null) {
|
|
2576
2639
|
properties.forEach((property) => targets.add(property));
|
|
2577
2640
|
return;
|