@plumeria/utils 7.0.2 → 7.1.1
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.ts +2 -1
- package/dist/index.js +3 -1
- package/dist/variants.d.ts +4 -0
- package/dist/variants.js +121 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export type { CSSObject, FileStyles, StaticTable, KeyframesHashTable,
|
|
1
|
+
export type { CSSObject, FileStyles, StaticTable, KeyframesHashTable, ViewTransitionHashTable, CreateHashTable, VariantsHashTable, CreateThemeHashTable, CreateStaticHashTable, } from './types';
|
|
2
2
|
export { objectExpressionToObject, collectLocalConsts, traverse, t, extractOndemandStyles, deepMerge, scanAll, } from './parser';
|
|
3
3
|
export type { StyleRecord } from './create';
|
|
4
4
|
export { getStyleRecords } from './create';
|
|
5
5
|
export { createTheme } from './createTheme';
|
|
6
6
|
export { resolveImportPath } from './resolver';
|
|
7
7
|
export { optimizer } from './optimizer';
|
|
8
|
+
export { processVariants } from './variants';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.optimizer = exports.resolveImportPath = exports.createTheme = exports.getStyleRecords = exports.scanAll = exports.deepMerge = exports.extractOndemandStyles = exports.t = exports.traverse = exports.collectLocalConsts = exports.objectExpressionToObject = void 0;
|
|
3
|
+
exports.processVariants = exports.optimizer = exports.resolveImportPath = exports.createTheme = exports.getStyleRecords = exports.scanAll = exports.deepMerge = exports.extractOndemandStyles = exports.t = exports.traverse = exports.collectLocalConsts = exports.objectExpressionToObject = void 0;
|
|
4
4
|
var parser_1 = require("./parser");
|
|
5
5
|
Object.defineProperty(exports, "objectExpressionToObject", { enumerable: true, get: function () { return parser_1.objectExpressionToObject; } });
|
|
6
6
|
Object.defineProperty(exports, "collectLocalConsts", { enumerable: true, get: function () { return parser_1.collectLocalConsts; } });
|
|
@@ -17,3 +17,5 @@ var resolver_1 = require("./resolver");
|
|
|
17
17
|
Object.defineProperty(exports, "resolveImportPath", { enumerable: true, get: function () { return resolver_1.resolveImportPath; } });
|
|
18
18
|
var optimizer_1 = require("./optimizer");
|
|
19
19
|
Object.defineProperty(exports, "optimizer", { enumerable: true, get: function () { return optimizer_1.optimizer; } });
|
|
20
|
+
var variants_1 = require("./variants");
|
|
21
|
+
Object.defineProperty(exports, "processVariants", { enumerable: true, get: function () { return variants_1.processVariants; } });
|
package/dist/variants.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.processVariants = processVariants;
|
|
4
|
+
const parser_1 = require("./parser");
|
|
5
|
+
const create_1 = require("./create");
|
|
6
|
+
function processVariants(variants) {
|
|
7
|
+
const sheets = [];
|
|
8
|
+
const variantKeys = Object.keys(variants);
|
|
9
|
+
const variantProperties = {};
|
|
10
|
+
variantKeys.forEach((key) => {
|
|
11
|
+
variantProperties[key] = new Set();
|
|
12
|
+
Object.values(variants[key]).forEach((style) => {
|
|
13
|
+
Object.keys(style).forEach((prop) => variantProperties[key].add(prop));
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
const conflicts = {};
|
|
17
|
+
variantKeys.forEach((key) => (conflicts[key] = new Set()));
|
|
18
|
+
for (let i = 0; i < variantKeys.length; i++) {
|
|
19
|
+
for (let j = i + 1; j < variantKeys.length; j++) {
|
|
20
|
+
const keyA = variantKeys[i];
|
|
21
|
+
const keyB = variantKeys[j];
|
|
22
|
+
let hasConflict = false;
|
|
23
|
+
for (const prop of variantProperties[keyA]) {
|
|
24
|
+
if (variantProperties[keyB].has(prop)) {
|
|
25
|
+
hasConflict = true;
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (hasConflict) {
|
|
30
|
+
conflicts[keyA].add(keyB);
|
|
31
|
+
conflicts[keyB].add(keyA);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const visited = new Set();
|
|
36
|
+
const independentKeys = [];
|
|
37
|
+
const compoundGroups = [];
|
|
38
|
+
variantKeys.forEach((key) => {
|
|
39
|
+
if (visited.has(key))
|
|
40
|
+
return;
|
|
41
|
+
const queue = [key];
|
|
42
|
+
const component = new Set();
|
|
43
|
+
while (queue.length > 0) {
|
|
44
|
+
const curr = queue.shift();
|
|
45
|
+
if (component.has(curr))
|
|
46
|
+
continue;
|
|
47
|
+
component.add(curr);
|
|
48
|
+
visited.add(curr);
|
|
49
|
+
conflicts[curr].forEach((neighbor) => {
|
|
50
|
+
if (!visited.has(neighbor)) {
|
|
51
|
+
queue.push(neighbor);
|
|
52
|
+
}
|
|
53
|
+
else if (!component.has(neighbor)) {
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
if (component.size === 1) {
|
|
58
|
+
independentKeys.push(key);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
compoundGroups.push(Array.from(component));
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
const hashMap = {};
|
|
65
|
+
independentKeys.forEach((key) => {
|
|
66
|
+
const optionMap = {};
|
|
67
|
+
Object.entries(variants[key]).forEach(([optKey, style]) => {
|
|
68
|
+
const records = (0, create_1.getStyleRecords)(style);
|
|
69
|
+
records.forEach((r) => {
|
|
70
|
+
if (!sheets.includes(r.sheet))
|
|
71
|
+
sheets.push(r.sheet);
|
|
72
|
+
});
|
|
73
|
+
optionMap[optKey] = records.map((r) => r.hash).join(' ');
|
|
74
|
+
});
|
|
75
|
+
hashMap[key] = optionMap;
|
|
76
|
+
});
|
|
77
|
+
if (compoundGroups.length > 0) {
|
|
78
|
+
hashMap._compound = compoundGroups.map((groupKeys) => {
|
|
79
|
+
const compoundMap = {};
|
|
80
|
+
const generateCombinations = (depth, currentCombo) => {
|
|
81
|
+
if (depth === groupKeys.length) {
|
|
82
|
+
let mergedStyle = {};
|
|
83
|
+
const comboKeyParts = [];
|
|
84
|
+
groupKeys.forEach((k) => {
|
|
85
|
+
const opt = currentCombo[k];
|
|
86
|
+
comboKeyParts.push(opt || 'default');
|
|
87
|
+
if (opt && variants[k][opt]) {
|
|
88
|
+
mergedStyle = (0, parser_1.deepMerge)(mergedStyle, variants[k][opt]);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
const records = (0, create_1.getStyleRecords)(mergedStyle);
|
|
92
|
+
records.forEach((r) => {
|
|
93
|
+
if (!sheets.includes(r.sheet))
|
|
94
|
+
sheets.push(r.sheet);
|
|
95
|
+
});
|
|
96
|
+
const className = records.map((r) => r.hash).join(' ');
|
|
97
|
+
if (className) {
|
|
98
|
+
compoundMap[comboKeyParts.join(':')] = className;
|
|
99
|
+
}
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const key = groupKeys[depth];
|
|
103
|
+
const options = Object.keys(variants[key]);
|
|
104
|
+
const effectiveOptions = new Set(options);
|
|
105
|
+
effectiveOptions.add('default');
|
|
106
|
+
effectiveOptions.forEach((opt) => {
|
|
107
|
+
generateCombinations(depth + 1, { ...currentCombo, [key]: opt });
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
generateCombinations(0, {});
|
|
111
|
+
return {
|
|
112
|
+
keys: groupKeys,
|
|
113
|
+
map: compoundMap,
|
|
114
|
+
};
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
hashMap,
|
|
119
|
+
sheets,
|
|
120
|
+
};
|
|
121
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/utils",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.1.1",
|
|
4
4
|
"description": "Plumeria Utils",
|
|
5
5
|
"author": "Refirst 11",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@swc/core": "1.15.8",
|
|
25
|
-
"zss-engine": "2.2.
|
|
25
|
+
"zss-engine": "2.2.4",
|
|
26
26
|
"postcss": "8.5.6",
|
|
27
27
|
"postcss-combine-media-query": "^2.1.0",
|
|
28
28
|
"lightningcss": "^1.30.2"
|