@plumeria/utils 6.3.2 → 7.0.0
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/create.d.ts +1 -1
- package/dist/create.js +12 -34
- package/dist/parser.js +62 -3
- package/package.json +2 -2
package/dist/create.d.ts
CHANGED
package/dist/create.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getStyleRecords = getStyleRecords;
|
|
4
4
|
const zss_engine_1 = require("zss-engine");
|
|
5
|
-
function getStyleRecords(
|
|
5
|
+
function getStyleRecords(styleRule) {
|
|
6
6
|
const flat = {};
|
|
7
7
|
const nonFlat = {};
|
|
8
8
|
const notNormalize = ':not(#\\#)';
|
|
@@ -13,11 +13,12 @@ function getStyleRecords(key, styleRule) {
|
|
|
13
13
|
if (prop.startsWith('@media') || prop.startsWith('@container')) {
|
|
14
14
|
Object.entries(value).forEach(([innerProp, innerValue]) => {
|
|
15
15
|
const atomicMap = new Map();
|
|
16
|
+
const notSuffix = innerProp.startsWith('--') ? '' : notNormalize;
|
|
16
17
|
(0, zss_engine_1.processAtomicProps)({ [innerProp]: innerValue }, atomicMap, prop);
|
|
17
18
|
const querySheets = [];
|
|
18
19
|
const queryHashes = [];
|
|
19
20
|
for (const [hash, sheet] of atomicMap) {
|
|
20
|
-
querySheets.push(sheet.replace(`.${hash}`, `.${hash}${
|
|
21
|
+
querySheets.push(sheet.replace(`.${hash}`, `.${hash}${notSuffix}`));
|
|
21
22
|
queryHashes.push(hash);
|
|
22
23
|
}
|
|
23
24
|
const queryKey = prop + ':' + innerProp;
|
|
@@ -59,12 +60,9 @@ function getStyleRecords(key, styleRule) {
|
|
|
59
60
|
nonFlatBase[atRule] = nestedObj;
|
|
60
61
|
}
|
|
61
62
|
});
|
|
62
|
-
const processSelectorStyle = (selector, style, atRule
|
|
63
|
-
const isAtomic = selector.startsWith(':') ||
|
|
64
|
-
(selector.startsWith('&') &&
|
|
65
|
-
(selector.startsWith('&:') || selector.startsWith('&[')));
|
|
63
|
+
const processSelectorStyle = (selector, style, atRule) => {
|
|
64
|
+
const isAtomic = selector.startsWith(':') || selector.startsWith('[');
|
|
66
65
|
if (isAtomic) {
|
|
67
|
-
const normalizedSelector = selector.replace('&', '');
|
|
68
66
|
Object.entries(style).forEach(([prop, value]) => {
|
|
69
67
|
let hashSource = { [prop]: value };
|
|
70
68
|
if (atRule) {
|
|
@@ -74,8 +72,9 @@ function getStyleRecords(key, styleRule) {
|
|
|
74
72
|
hashSource = { [selector]: hashSource };
|
|
75
73
|
}
|
|
76
74
|
const hash = (0, zss_engine_1.genBase36Hash)(hashSource, 1, 8);
|
|
77
|
-
|
|
78
|
-
sheet =
|
|
75
|
+
const notSuffix = prop.startsWith('--') ? '' : notNormalize;
|
|
76
|
+
let sheet = (0, zss_engine_1.transpileAtomic)(prop, value, hash, selector);
|
|
77
|
+
sheet = sheet.replace(`.${hash}`, `.${hash}${notSuffix}`);
|
|
79
78
|
if (atRule) {
|
|
80
79
|
sheet = `${atRule} { ${sheet} }`;
|
|
81
80
|
}
|
|
@@ -88,34 +87,13 @@ function getStyleRecords(key, styleRule) {
|
|
|
88
87
|
});
|
|
89
88
|
});
|
|
90
89
|
}
|
|
91
|
-
else {
|
|
92
|
-
const hashObj = {
|
|
93
|
-
[key]: { [atRule || 'base']: { [selector]: style, index } },
|
|
94
|
-
};
|
|
95
|
-
const hash = (0, zss_engine_1.genBase36Hash)(hashObj, 1, 7);
|
|
96
|
-
const transpileObj = atRule
|
|
97
|
-
? { [key]: { [atRule]: { [selector]: style } } }
|
|
98
|
-
: { [key]: { [selector]: style } };
|
|
99
|
-
const { styleSheet } = (0, zss_engine_1.transpile)(transpileObj, hash);
|
|
100
|
-
const sheet = atRule
|
|
101
|
-
? styleSheet.replace(`.${hash}`, `.${hash}${notNormalize}`)
|
|
102
|
-
: styleSheet;
|
|
103
|
-
const recordKey = atRule
|
|
104
|
-
? `${atRule}:${selector}:${index}`
|
|
105
|
-
: `${selector}:${index}`;
|
|
106
|
-
records.push({
|
|
107
|
-
key: recordKey,
|
|
108
|
-
hash: hash,
|
|
109
|
-
sheet: sheet,
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
90
|
};
|
|
113
|
-
Object.entries(nonFlatBase).forEach(([selector, style]
|
|
114
|
-
processSelectorStyle(selector, style, undefined
|
|
91
|
+
Object.entries(nonFlatBase).forEach(([selector, style]) => {
|
|
92
|
+
processSelectorStyle(selector, style, undefined);
|
|
115
93
|
});
|
|
116
94
|
Object.entries(nonFlatQuery).forEach(([atRule, nestedStyles]) => {
|
|
117
|
-
Object.entries(nestedStyles).forEach(([selector, style]
|
|
118
|
-
processSelectorStyle(selector, style, atRule
|
|
95
|
+
Object.entries(nestedStyles).forEach(([selector, style]) => {
|
|
96
|
+
processSelectorStyle(selector, style, atRule);
|
|
119
97
|
});
|
|
120
98
|
});
|
|
121
99
|
}
|
package/dist/parser.js
CHANGED
|
@@ -18,6 +18,10 @@ const zss_engine_1 = require("zss-engine");
|
|
|
18
18
|
const viewTransition_1 = require("./viewTransition");
|
|
19
19
|
const create_1 = require("./create");
|
|
20
20
|
const resolver_1 = require("./resolver");
|
|
21
|
+
const getMarkerVar = (id, pseudo) => {
|
|
22
|
+
const state = pseudo.replace(/:/g, '');
|
|
23
|
+
return `--${id}-${state}`;
|
|
24
|
+
};
|
|
21
25
|
exports.t = {
|
|
22
26
|
isObjectExpression: (node) => node?.type === 'ObjectExpression',
|
|
23
27
|
isObjectProperty: (node) => node?.type === 'KeyValueProperty',
|
|
@@ -80,6 +84,14 @@ const GLOB_OPTIONS = {
|
|
|
80
84
|
function objectExpressionToObject(node, staticTable, keyframesHashTable, viewTransitionHashTable, createThemeHashTable, createThemeObjectTable, createHashTable, createStaticHashTable, createStaticObjectTable, variantsHashTable, resolveVariable) {
|
|
81
85
|
const obj = {};
|
|
82
86
|
node.properties.forEach((prop) => {
|
|
87
|
+
if (prop.type === 'SpreadElement') {
|
|
88
|
+
const arg = prop.arguments;
|
|
89
|
+
const spreadVal = evaluateExpression(arg, staticTable, keyframesHashTable, viewTransitionHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
90
|
+
if (typeof spreadVal === 'object' && spreadVal !== null) {
|
|
91
|
+
Object.assign(obj, spreadVal);
|
|
92
|
+
}
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
83
95
|
if (!exports.t.isObjectProperty(prop))
|
|
84
96
|
return;
|
|
85
97
|
const key = getPropertyKey(prop.key, staticTable, keyframesHashTable, viewTransitionHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
@@ -220,6 +232,11 @@ function getPropertyKey(node, staticTable, keyframesHashTable, viewTransitionHas
|
|
|
220
232
|
return staticTable[expr.value];
|
|
221
233
|
}
|
|
222
234
|
}
|
|
235
|
+
if (exports.t.isCallExpression(expr)) {
|
|
236
|
+
const result = evaluateExpression(expr, staticTable, keyframesHashTable, viewTransitionHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
237
|
+
if (typeof result === 'string')
|
|
238
|
+
return result;
|
|
239
|
+
}
|
|
223
240
|
if (exports.t.isMemberExpression(expr)) {
|
|
224
241
|
const result = resolveStaticTableMemberExpression(expr, staticTable);
|
|
225
242
|
if (typeof result === 'string')
|
|
@@ -267,7 +284,49 @@ function evaluateBinaryExpression(node, staticTable, keyframesHashTable, viewTra
|
|
|
267
284
|
}
|
|
268
285
|
throw new Error(`Unsupported binary operator: ${node.operator}`);
|
|
269
286
|
}
|
|
287
|
+
function evaluateCallExpression(node, staticTable) {
|
|
288
|
+
const callee = node.callee;
|
|
289
|
+
let method;
|
|
290
|
+
if (exports.t.isIdentifier(callee)) {
|
|
291
|
+
method = callee.value;
|
|
292
|
+
}
|
|
293
|
+
else if (exports.t.isMemberExpression(callee) && exports.t.isIdentifier(callee.property)) {
|
|
294
|
+
method = callee.property.value;
|
|
295
|
+
}
|
|
296
|
+
if (!method)
|
|
297
|
+
return null;
|
|
298
|
+
if (method === 'marker') {
|
|
299
|
+
const args = node.arguments;
|
|
300
|
+
if (args.length >= 2) {
|
|
301
|
+
const id = evaluateExpression(args[0].expression, staticTable, {}, {}, {}, {}, {}, {});
|
|
302
|
+
const pseudo = evaluateExpression(args[1].expression, staticTable, {}, {}, {}, {}, {}, {});
|
|
303
|
+
if (typeof id === 'string' && typeof pseudo === 'string') {
|
|
304
|
+
const varName = getMarkerVar(id, pseudo);
|
|
305
|
+
return {
|
|
306
|
+
[pseudo]: {
|
|
307
|
+
[varName]: 1,
|
|
308
|
+
},
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
if (method === 'extended') {
|
|
314
|
+
const args = node.arguments;
|
|
315
|
+
if (args.length >= 2) {
|
|
316
|
+
const id = evaluateExpression(args[0].expression, staticTable, {}, {}, {}, {}, {}, {});
|
|
317
|
+
const pseudo = evaluateExpression(args[1].expression, staticTable, {}, {}, {}, {}, {}, {});
|
|
318
|
+
if (typeof id === 'string' && typeof pseudo === 'string') {
|
|
319
|
+
const varName = getMarkerVar(id, pseudo);
|
|
320
|
+
return `@container style(${varName}: 1)`;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
return null;
|
|
325
|
+
}
|
|
270
326
|
function evaluateExpression(node, staticTable, keyframesHashTable, viewTransitionHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable) {
|
|
327
|
+
if (exports.t.isCallExpression(node)) {
|
|
328
|
+
return evaluateCallExpression(node, staticTable);
|
|
329
|
+
}
|
|
271
330
|
if (exports.t.isStringLiteral(node)) {
|
|
272
331
|
return node.value;
|
|
273
332
|
}
|
|
@@ -759,7 +818,7 @@ function scanAll() {
|
|
|
759
818
|
localCreateObjectTable[hash] = obj;
|
|
760
819
|
const hashMap = {};
|
|
761
820
|
Object.entries(obj).forEach(([key, style]) => {
|
|
762
|
-
const records = (0, create_1.getStyleRecords)(
|
|
821
|
+
const records = (0, create_1.getStyleRecords)(style);
|
|
763
822
|
const atomMap = {};
|
|
764
823
|
records.forEach((r) => (atomMap[r.key] = r.hash));
|
|
765
824
|
hashMap[key] = atomMap;
|
|
@@ -883,8 +942,8 @@ function extractOndemandStyles(obj, extractedSheets, t) {
|
|
|
883
942
|
for (const hash of createHashes) {
|
|
884
943
|
const obj = t.createObjectTable[hash];
|
|
885
944
|
if (obj) {
|
|
886
|
-
Object.entries(obj).forEach(([
|
|
887
|
-
const records = (0, create_1.getStyleRecords)(
|
|
945
|
+
Object.entries(obj).forEach(([_key, style]) => {
|
|
946
|
+
const records = (0, create_1.getStyleRecords)(style);
|
|
888
947
|
records.forEach((r) => addSheet(r.sheet));
|
|
889
948
|
});
|
|
890
949
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
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.3",
|
|
26
26
|
"postcss": "8.5.6",
|
|
27
27
|
"postcss-combine-media-query": "^2.1.0",
|
|
28
28
|
"lightningcss": "^1.30.2"
|