@plumeria/utils 19.15.0 → 21.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/compile.js +112 -13
- package/dist/dynamicKey.d.ts +2 -1
- package/dist/dynamicKey.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/parser.d.ts +3 -2
- package/dist/parser.js +133 -54
- package/dist/positionTry.d.ts +4 -0
- package/dist/positionTry.js +7 -0
- package/dist/propertyPolicy.js +10 -1
- package/dist/transform.js +190 -26
- package/dist/types.d.ts +3 -0
- package/dist/viewTransition.js +4 -4
- package/package.json +2 -2
package/dist/parser.js
CHANGED
|
@@ -50,6 +50,7 @@ exports.fileTableKeys = fileTableKeys;
|
|
|
50
50
|
exports.scanOverlay = scanOverlay;
|
|
51
51
|
exports.scanAll = scanAll;
|
|
52
52
|
exports.getFileDependencies = getFileDependencies;
|
|
53
|
+
exports.exportNames = exportNames;
|
|
53
54
|
exports.resolveExport = resolveExport;
|
|
54
55
|
exports.extractOndemandStyles = extractOndemandStyles;
|
|
55
56
|
exports.deepMerge = deepMerge;
|
|
@@ -62,6 +63,7 @@ const rs = __importStar(require("@rust-gear/glob"));
|
|
|
62
63
|
const zss_engine_1 = require("zss-engine");
|
|
63
64
|
const viewTransition_1 = require("./viewTransition");
|
|
64
65
|
const varType_1 = require("./varType");
|
|
66
|
+
const positionTry_1 = require("./positionTry");
|
|
65
67
|
const constants_1 = require("./constants");
|
|
66
68
|
const stylePropFilter_1 = require("./stylePropFilter");
|
|
67
69
|
const create_1 = require("./create");
|
|
@@ -275,12 +277,12 @@ function traverse(node, visitor) {
|
|
|
275
277
|
}
|
|
276
278
|
walk(node);
|
|
277
279
|
}
|
|
278
|
-
function objectExpressionToObject(node, staticTable, keyframesHashTable, viewTransitionHashTable, createThemeHashTable, createThemeObjectTable, createHashTable, createStaticHashTable, createStaticObjectTable, resolveVariable, varTypeHashTable = {}) {
|
|
280
|
+
function objectExpressionToObject(node, staticTable, keyframesHashTable, viewTransitionHashTable, createThemeHashTable, createThemeObjectTable, createHashTable, createStaticHashTable, createStaticObjectTable, resolveVariable, varTypeHashTable = {}, positionTryHashTable = {}) {
|
|
279
281
|
const obj = Object.create(null);
|
|
280
282
|
node.properties.forEach((prop) => {
|
|
281
283
|
if (prop.type === 'SpreadElement') {
|
|
282
284
|
const arg = prop.arguments;
|
|
283
|
-
const spreadVal = evaluateExpression(arg, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
285
|
+
const spreadVal = evaluateExpression(arg, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, positionTryHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
284
286
|
if (typeof spreadVal === 'object' && spreadVal !== null) {
|
|
285
287
|
Object.assign(obj, spreadVal);
|
|
286
288
|
}
|
|
@@ -302,7 +304,7 @@ function objectExpressionToObject(node, staticTable, keyframesHashTable, viewTra
|
|
|
302
304
|
}
|
|
303
305
|
if (!exports.t.isObjectProperty(prop))
|
|
304
306
|
return;
|
|
305
|
-
const rawKey = getPropertyKey(prop.key, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
307
|
+
const rawKey = getPropertyKey(prop.key, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, positionTryHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
306
308
|
if (!rawKey)
|
|
307
309
|
return;
|
|
308
310
|
const key = typeof rawKey === 'string' ? (0, zss_engine_1.stripSelectorComments)(rawKey) : rawKey;
|
|
@@ -345,6 +347,11 @@ function objectExpressionToObject(node, staticTable, keyframesHashTable, viewTra
|
|
|
345
347
|
obj[key] = '--pr-' + varTypeHashTable[val.value];
|
|
346
348
|
return;
|
|
347
349
|
}
|
|
350
|
+
if (exports.t.isIdentifier(val) &&
|
|
351
|
+
positionTryHashTable[val.value] !== undefined) {
|
|
352
|
+
obj[key] = '--pt-' + positionTryHashTable[val.value];
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
348
355
|
const resolvedCreate = resolveCreateTableMemberExpression(val, createHashTable);
|
|
349
356
|
if (resolvedCreate !== undefined) {
|
|
350
357
|
obj[key] = 'cr-' + resolvedCreate;
|
|
@@ -367,13 +374,13 @@ function objectExpressionToObject(node, staticTable, keyframesHashTable, viewTra
|
|
|
367
374
|
obj[key] = val.value;
|
|
368
375
|
}
|
|
369
376
|
else if (exports.t.isUnaryExpression(val)) {
|
|
370
|
-
obj[key] = evaluateExpression(val, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
377
|
+
obj[key] = evaluateExpression(val, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, positionTryHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
371
378
|
}
|
|
372
379
|
else if (exports.t.isObjectExpression(val)) {
|
|
373
|
-
obj[key] = objectExpressionToObject(val, staticTable, keyframesHashTable, viewTransitionHashTable, createThemeHashTable, createThemeObjectTable, createHashTable, createStaticHashTable, createStaticObjectTable, resolveVariable, varTypeHashTable);
|
|
380
|
+
obj[key] = objectExpressionToObject(val, staticTable, keyframesHashTable, viewTransitionHashTable, createThemeHashTable, createThemeObjectTable, createHashTable, createStaticHashTable, createStaticObjectTable, resolveVariable, varTypeHashTable, positionTryHashTable);
|
|
374
381
|
}
|
|
375
382
|
else if (exports.t.isBinaryExpression(val) || exports.t.isTemplateLiteral(val)) {
|
|
376
|
-
obj[key] = evaluateExpression(val, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
383
|
+
obj[key] = evaluateExpression(val, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, positionTryHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
377
384
|
}
|
|
378
385
|
else if (exports.t.isMemberExpression(val)) {
|
|
379
386
|
const resolved = resolveStaticTableMemberExpression(val, staticTable);
|
|
@@ -444,7 +451,7 @@ function collectLocalConsts(ast) {
|
|
|
444
451
|
else if (exports.t.isBinaryExpression(init) ||
|
|
445
452
|
exports.t.isTemplateLiteral(init) ||
|
|
446
453
|
exports.t.isUnaryExpression(init)) {
|
|
447
|
-
result = evaluateExpression(init, localConsts, {}, {}, {}, {}, {}, {}, {});
|
|
454
|
+
result = evaluateExpression(init, localConsts, {}, {}, {}, {}, {}, {}, {}, {});
|
|
448
455
|
}
|
|
449
456
|
}
|
|
450
457
|
catch (e) {
|
|
@@ -675,7 +682,7 @@ function inlineOuterScope(objExpression, resolveProperty) {
|
|
|
675
682
|
});
|
|
676
683
|
return changed ? { ...objExpression, properties } : objExpression;
|
|
677
684
|
}
|
|
678
|
-
function getPropertyKey(node, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable) {
|
|
685
|
+
function getPropertyKey(node, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, positionTryHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable) {
|
|
679
686
|
if (exports.t.isIdentifier(node)) {
|
|
680
687
|
return node.value;
|
|
681
688
|
}
|
|
@@ -698,9 +705,12 @@ function getPropertyKey(node, staticTable, keyframesHashTable, viewTransitionHas
|
|
|
698
705
|
if (varTypeHashTable[expr.value] !== undefined) {
|
|
699
706
|
return '--pr-' + varTypeHashTable[expr.value];
|
|
700
707
|
}
|
|
708
|
+
if (positionTryHashTable[expr.value] !== undefined) {
|
|
709
|
+
return '--pt-' + positionTryHashTable[expr.value];
|
|
710
|
+
}
|
|
701
711
|
}
|
|
702
712
|
if (exports.t.isCallExpression(expr)) {
|
|
703
|
-
const result = evaluateExpression(expr, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
713
|
+
const result = evaluateExpression(expr, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, positionTryHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
704
714
|
if (typeof result === 'string')
|
|
705
715
|
return result;
|
|
706
716
|
}
|
|
@@ -716,28 +726,28 @@ function getPropertyKey(node, staticTable, keyframesHashTable, viewTransitionHas
|
|
|
716
726
|
return themeResult;
|
|
717
727
|
}
|
|
718
728
|
if (exports.t.isTemplateLiteral(expr)) {
|
|
719
|
-
return evaluateTemplateLiteral(expr, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
729
|
+
return evaluateTemplateLiteral(expr, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, positionTryHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
720
730
|
}
|
|
721
731
|
if (exports.t.isBinaryExpression(expr)) {
|
|
722
|
-
return evaluateBinaryExpression(expr, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
732
|
+
return evaluateBinaryExpression(expr, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, positionTryHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
723
733
|
}
|
|
724
734
|
return '';
|
|
725
735
|
}
|
|
726
736
|
if (exports.t.isTemplateLiteral(node)) {
|
|
727
|
-
return evaluateTemplateLiteral(node, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
737
|
+
return evaluateTemplateLiteral(node, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, positionTryHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
728
738
|
}
|
|
729
739
|
if (exports.t.isBinaryExpression(node)) {
|
|
730
|
-
return evaluateBinaryExpression(node, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
740
|
+
return evaluateBinaryExpression(node, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, positionTryHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
731
741
|
}
|
|
732
742
|
return '';
|
|
733
743
|
}
|
|
734
|
-
function evaluateTemplateLiteral(node, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable) {
|
|
744
|
+
function evaluateTemplateLiteral(node, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, positionTryHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable) {
|
|
735
745
|
let result = '';
|
|
736
746
|
for (let i = 0; i < node.quasis.length; i++) {
|
|
737
747
|
result += node.quasis[i].cooked || node.quasis[i].raw;
|
|
738
748
|
if (i < node.expressions.length) {
|
|
739
749
|
const expr = node.expressions[i];
|
|
740
|
-
const evaluatedExpr = evaluateExpression(expr, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
750
|
+
const evaluatedExpr = evaluateExpression(expr, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, positionTryHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
741
751
|
if (evaluatedExpr === null || typeof evaluatedExpr === 'object')
|
|
742
752
|
throw new Error(`[plumeria] Template value cannot be resolved to a primitive: ${(0, exports.expressionLabel)(expr)} inside \${} must resolve to a string or number at build time.`);
|
|
743
753
|
result += String(evaluatedExpr);
|
|
@@ -745,15 +755,15 @@ function evaluateTemplateLiteral(node, staticTable, keyframesHashTable, viewTran
|
|
|
745
755
|
}
|
|
746
756
|
return result;
|
|
747
757
|
}
|
|
748
|
-
function evaluateBinaryExpression(node, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable) {
|
|
749
|
-
const left = evaluateExpression(node.left, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
758
|
+
function evaluateBinaryExpression(node, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, positionTryHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable) {
|
|
759
|
+
const left = evaluateExpression(node.left, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, positionTryHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
750
760
|
if (node.operator === '&&' && !left)
|
|
751
761
|
return left;
|
|
752
762
|
if (node.operator === '||' && left)
|
|
753
763
|
return left;
|
|
754
764
|
if (node.operator === '??' && left !== null)
|
|
755
765
|
return left;
|
|
756
|
-
const right = evaluateExpression(node.right, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
766
|
+
const right = evaluateExpression(node.right, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, positionTryHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
757
767
|
if (['&&', '||', '??'].includes(node.operator))
|
|
758
768
|
return right;
|
|
759
769
|
if (typeof left === 'number' && typeof right === 'number') {
|
|
@@ -823,8 +833,8 @@ function evaluateCallExpression(node, staticTable) {
|
|
|
823
833
|
if (method === 'marker') {
|
|
824
834
|
const args = node.arguments;
|
|
825
835
|
if (args.length >= 2) {
|
|
826
|
-
const id = evaluateExpression(args[0].expression, staticTable, {}, {}, {}, {}, {}, {}, {});
|
|
827
|
-
const pseudo = evaluateExpression(args[1].expression, staticTable, {}, {}, {}, {}, {}, {}, {});
|
|
836
|
+
const id = evaluateExpression(args[0].expression, staticTable, {}, {}, {}, {}, {}, {}, {}, {});
|
|
837
|
+
const pseudo = evaluateExpression(args[1].expression, staticTable, {}, {}, {}, {}, {}, {}, {}, {});
|
|
828
838
|
if (typeof id === 'string' && typeof pseudo === 'string') {
|
|
829
839
|
const varName = getMarkerVar(id, pseudo);
|
|
830
840
|
return {
|
|
@@ -838,8 +848,8 @@ function evaluateCallExpression(node, staticTable) {
|
|
|
838
848
|
if (method === 'extended') {
|
|
839
849
|
const args = node.arguments;
|
|
840
850
|
if (args.length >= 2) {
|
|
841
|
-
const id = evaluateExpression(args[0].expression, staticTable, {}, {}, {}, {}, {}, {}, {});
|
|
842
|
-
const pseudo = evaluateExpression(args[1].expression, staticTable, {}, {}, {}, {}, {}, {}, {});
|
|
851
|
+
const id = evaluateExpression(args[0].expression, staticTable, {}, {}, {}, {}, {}, {}, {}, {});
|
|
852
|
+
const pseudo = evaluateExpression(args[1].expression, staticTable, {}, {}, {}, {}, {}, {}, {}, {});
|
|
843
853
|
if (typeof id === 'string' && typeof pseudo === 'string') {
|
|
844
854
|
const varName = getMarkerVar(id, pseudo);
|
|
845
855
|
return `@container style(${varName}: 1)`;
|
|
@@ -848,7 +858,7 @@ function evaluateCallExpression(node, staticTable) {
|
|
|
848
858
|
}
|
|
849
859
|
return null;
|
|
850
860
|
}
|
|
851
|
-
function evaluateExpression(node, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable) {
|
|
861
|
+
function evaluateExpression(node, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, positionTryHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable) {
|
|
852
862
|
node = unwrapExpression(node);
|
|
853
863
|
if (exports.t.isCallExpression(node)) {
|
|
854
864
|
return evaluateCallExpression(node, staticTable);
|
|
@@ -878,6 +888,9 @@ function evaluateExpression(node, staticTable, keyframesHashTable, viewTransitio
|
|
|
878
888
|
if (varTypeHashTable[node.value] !== undefined) {
|
|
879
889
|
return '--pr-' + varTypeHashTable[node.value];
|
|
880
890
|
}
|
|
891
|
+
if (positionTryHashTable[node.value] !== undefined) {
|
|
892
|
+
return '--pt-' + positionTryHashTable[node.value];
|
|
893
|
+
}
|
|
881
894
|
if (createStaticHashTable[node.value] !== undefined) {
|
|
882
895
|
const hash = createStaticHashTable[node.value];
|
|
883
896
|
if (createStaticObjectTable[hash] !== undefined) {
|
|
@@ -902,13 +915,13 @@ function evaluateExpression(node, staticTable, keyframesHashTable, viewTransitio
|
|
|
902
915
|
throw new Error(`[plumeria] Cannot resolve static member expression: ${(0, exports.expressionLabel)(node)}. Its object must be a const or a value created by css.createStatic or css.createTheme.`);
|
|
903
916
|
}
|
|
904
917
|
if (exports.t.isBinaryExpression(node)) {
|
|
905
|
-
return evaluateBinaryExpression(node, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
918
|
+
return evaluateBinaryExpression(node, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, positionTryHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
906
919
|
}
|
|
907
920
|
if (exports.t.isTemplateLiteral(node)) {
|
|
908
|
-
return evaluateTemplateLiteral(node, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
921
|
+
return evaluateTemplateLiteral(node, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, positionTryHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
909
922
|
}
|
|
910
923
|
if (exports.t.isUnaryExpression(node)) {
|
|
911
|
-
const value = evaluateExpression(node.argument, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
924
|
+
const value = evaluateExpression(node.argument, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, positionTryHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
912
925
|
if (node.operator === '!')
|
|
913
926
|
return !value;
|
|
914
927
|
if (typeof value === 'number') {
|
|
@@ -922,7 +935,7 @@ function evaluateExpression(node, staticTable, keyframesHashTable, viewTransitio
|
|
|
922
935
|
throw new Error(`[plumeria] Unsupported unary operand for ${node.operator}: ${(0, exports.expressionLabel)(node.argument)} must resolve to a number at build time.`);
|
|
923
936
|
}
|
|
924
937
|
if (exports.t.isParenthesisExpression(node)) {
|
|
925
|
-
return evaluateExpression(node.expression, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
938
|
+
return evaluateExpression(node.expression, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, positionTryHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
926
939
|
}
|
|
927
940
|
throw new Error(`[plumeria] Unsupported expression type: ${(0, exports.expressionLabel)(node)}. Style values must be literals, consts, or arithmetic and template expressions of them.`);
|
|
928
941
|
}
|
|
@@ -1034,7 +1047,7 @@ function resolveCreateStaticTableMemberExpression(node, createStaticHashTable, c
|
|
|
1034
1047
|
}
|
|
1035
1048
|
function resolveThemeSelector(node, staticTable, createStaticHashTable, createStaticObjectTable) {
|
|
1036
1049
|
try {
|
|
1037
|
-
const value = evaluateExpression(node, staticTable, {}, {}, {}, {}, {}, createStaticHashTable, createStaticObjectTable);
|
|
1050
|
+
const value = evaluateExpression(node, staticTable, {}, {}, {}, {}, {}, {}, createStaticHashTable, createStaticObjectTable);
|
|
1038
1051
|
return typeof value === 'string' ? value : '';
|
|
1039
1052
|
}
|
|
1040
1053
|
catch {
|
|
@@ -1086,8 +1099,10 @@ const globalAgregatedTables = {
|
|
|
1086
1099
|
keyframesObjectTable: {},
|
|
1087
1100
|
viewTransitionHashTable: {},
|
|
1088
1101
|
varTypeHashTable: {},
|
|
1102
|
+
positionTryHashTable: {},
|
|
1089
1103
|
viewTransitionObjectTable: {},
|
|
1090
1104
|
varTypeObjectTable: {},
|
|
1105
|
+
positionTryObjectTable: {},
|
|
1091
1106
|
createThemeObjectTable: {},
|
|
1092
1107
|
createThemeSelectorTable: {},
|
|
1093
1108
|
createHashTable: {},
|
|
@@ -1112,6 +1127,7 @@ const detachedTables = new Set([
|
|
|
1112
1127
|
'keyframesHashTable',
|
|
1113
1128
|
'viewTransitionHashTable',
|
|
1114
1129
|
'varTypeHashTable',
|
|
1130
|
+
'positionTryHashTable',
|
|
1115
1131
|
'createHashTable',
|
|
1116
1132
|
'createObjectTable',
|
|
1117
1133
|
'createFunctionTable',
|
|
@@ -1448,6 +1464,7 @@ function runScan(scanCwd, styleProp) {
|
|
|
1448
1464
|
keyframesObjectTable: {},
|
|
1449
1465
|
viewTransitionHashTable: {},
|
|
1450
1466
|
varTypeHashTable: {},
|
|
1467
|
+
positionTryHashTable: {},
|
|
1451
1468
|
viewTransitionObjectTable: {},
|
|
1452
1469
|
createThemeHashTable: {},
|
|
1453
1470
|
createThemeSelectorTable: {},
|
|
@@ -1510,6 +1527,8 @@ function runScan(scanCwd, styleProp) {
|
|
|
1510
1527
|
const localVarTypeHashTable = {};
|
|
1511
1528
|
const localViewTransitionObjectTable = {};
|
|
1512
1529
|
const localVarTypeObjectTable = {};
|
|
1530
|
+
const localPositionTryHashTable = {};
|
|
1531
|
+
const localPositionTryObjectTable = {};
|
|
1513
1532
|
const localCreateThemeObjectTable = {};
|
|
1514
1533
|
const localCreateThemeSelectorTable = {};
|
|
1515
1534
|
const localCreateHashTable = {};
|
|
@@ -1603,6 +1622,14 @@ function runScan(scanCwd, styleProp) {
|
|
|
1603
1622
|
localTables.varTypeObjectTable[hash];
|
|
1604
1623
|
}
|
|
1605
1624
|
}
|
|
1625
|
+
if (localTables.positionTryHashTable?.[uniqueKey]) {
|
|
1626
|
+
const hash = localTables.positionTryHashTable[uniqueKey];
|
|
1627
|
+
localPositionTryHashTable[localName] = hash;
|
|
1628
|
+
if (localTables.positionTryObjectTable?.[hash]) {
|
|
1629
|
+
localPositionTryObjectTable[hash] =
|
|
1630
|
+
localTables.positionTryObjectTable[hash];
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1606
1633
|
if (localTables.viewTransitionHashTable[uniqueKey]) {
|
|
1607
1634
|
const hash = localTables.viewTransitionHashTable[uniqueKey];
|
|
1608
1635
|
localViewTransitionHashTable[localName] = hash;
|
|
@@ -1705,7 +1732,8 @@ function runScan(scanCwd, styleProp) {
|
|
|
1705
1732
|
'createTheme',
|
|
1706
1733
|
'createStatic',
|
|
1707
1734
|
'keyframes',
|
|
1708
|
-
'
|
|
1735
|
+
'viewTransitionClass',
|
|
1736
|
+
'positionTry',
|
|
1709
1737
|
'varType',
|
|
1710
1738
|
].includes(method)) {
|
|
1711
1739
|
const argument = decl.init.arguments[method === 'createTheme' ? 1 : 0];
|
|
@@ -1736,14 +1764,15 @@ function runScan(scanCwd, styleProp) {
|
|
|
1736
1764
|
const isPassOneMethod = method === 'createStatic' ||
|
|
1737
1765
|
method === 'createTheme' ||
|
|
1738
1766
|
method === 'keyframes' ||
|
|
1739
|
-
method === '
|
|
1767
|
+
method === 'viewTransitionClass' ||
|
|
1768
|
+
method === 'positionTry' ||
|
|
1740
1769
|
method === 'varType';
|
|
1741
1770
|
if (isFirstPass && !isPassOneMethod)
|
|
1742
1771
|
continue;
|
|
1743
1772
|
const objExpression = isCreateTheme
|
|
1744
1773
|
? init.arguments[1].expression
|
|
1745
1774
|
: init.arguments[0].expression;
|
|
1746
|
-
const obj = objectExpressionToObject(objExpression, scopedStaticTable, localKeyframesHashTable, localViewTransitionHashTable, localCreateThemeHashTable, localCreateThemeObjectTable, localCreateHashTable, localCreateStaticHashTable, localCreateStaticObjectTable, resolveVariable, localVarTypeHashTable);
|
|
1775
|
+
const obj = objectExpressionToObject(objExpression, scopedStaticTable, localKeyframesHashTable, localViewTransitionHashTable, localCreateThemeHashTable, localCreateThemeObjectTable, localCreateHashTable, localCreateStaticHashTable, localCreateStaticObjectTable, resolveVariable, localVarTypeHashTable, localPositionTryHashTable);
|
|
1747
1776
|
const uniqueKey = `${filePath}-${name}`;
|
|
1748
1777
|
if (method === 'createStatic') {
|
|
1749
1778
|
localStaticTable[name] = obj;
|
|
@@ -1775,7 +1804,16 @@ function runScan(scanCwd, styleProp) {
|
|
|
1775
1804
|
localVarTypeObjectTable[hash] = obj;
|
|
1776
1805
|
registerObjectOwner('varTypeObjectTable', hash, filePath);
|
|
1777
1806
|
}
|
|
1778
|
-
else if (method === '
|
|
1807
|
+
else if (method === 'positionTry') {
|
|
1808
|
+
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
1809
|
+
localPositionTryHashTable[name] = hash;
|
|
1810
|
+
localTables.positionTryHashTable[uniqueKey] = hash;
|
|
1811
|
+
registerFileKey('positionTryHashTable', uniqueKey, filePath);
|
|
1812
|
+
(localTables.positionTryObjectTable ??= {})[hash] = obj;
|
|
1813
|
+
localPositionTryObjectTable[hash] = obj;
|
|
1814
|
+
registerObjectOwner('positionTryObjectTable', hash, filePath);
|
|
1815
|
+
}
|
|
1816
|
+
else if (method === 'viewTransitionClass') {
|
|
1779
1817
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
1780
1818
|
localViewTransitionHashTable[name] = hash;
|
|
1781
1819
|
localTables.viewTransitionHashTable[uniqueKey] = hash;
|
|
@@ -1824,7 +1862,7 @@ function runScan(scanCwd, styleProp) {
|
|
|
1824
1862
|
inlineOuterScope(objExpression, (property) => objectExpressionToObject({
|
|
1825
1863
|
...objExpression,
|
|
1826
1864
|
properties: [property],
|
|
1827
|
-
}, scopedStaticTable, localKeyframesHashTable, localViewTransitionHashTable, localCreateThemeHashTable, localCreateThemeObjectTable, localCreateHashTable, localCreateStaticHashTable, localCreateStaticObjectTable, resolveVariable, localVarTypeHashTable));
|
|
1865
|
+
}, scopedStaticTable, localKeyframesHashTable, localViewTransitionHashTable, localCreateThemeHashTable, localCreateThemeObjectTable, localCreateHashTable, localCreateStaticHashTable, localCreateStaticObjectTable, resolveVariable, localVarTypeHashTable, localPositionTryHashTable));
|
|
1828
1866
|
registerFileKey('createFunctionTable', uniqueKey, filePath);
|
|
1829
1867
|
}
|
|
1830
1868
|
const hashMap = {};
|
|
@@ -1854,8 +1892,10 @@ function runScan(scanCwd, styleProp) {
|
|
|
1854
1892
|
localKeyframesObjectTable,
|
|
1855
1893
|
localViewTransitionHashTable,
|
|
1856
1894
|
localVarTypeHashTable,
|
|
1895
|
+
localPositionTryHashTable,
|
|
1857
1896
|
localViewTransitionObjectTable,
|
|
1858
1897
|
localVarTypeObjectTable,
|
|
1898
|
+
localPositionTryObjectTable,
|
|
1859
1899
|
localCreateThemeObjectTable,
|
|
1860
1900
|
localCreateThemeSelectorTable,
|
|
1861
1901
|
localCreateHashTable,
|
|
@@ -1875,7 +1915,7 @@ function runScan(scanCwd, styleProp) {
|
|
|
1875
1915
|
for (const entry of jsxPhaseQueue) {
|
|
1876
1916
|
try {
|
|
1877
1917
|
delete fileErrors[entry.filePath];
|
|
1878
|
-
const { filePath, ast, mtimeMs, localDependencies, localStaticTable, localKeyframesHashTable, localKeyframesObjectTable, localViewTransitionHashTable, localVarTypeHashTable, localViewTransitionObjectTable, localVarTypeObjectTable, localCreateThemeObjectTable, localCreateThemeSelectorTable, localCreateHashTable, localCreateObjectTable, localCreateAtomicMapTable, localCreateThemeHashTable, localCreateStaticHashTable, localCreateStaticObjectTable, localImports, } = entry;
|
|
1918
|
+
const { filePath, ast, mtimeMs, localDependencies, localStaticTable, localKeyframesHashTable, localKeyframesObjectTable, localViewTransitionHashTable, localVarTypeHashTable, localPositionTryHashTable, localViewTransitionObjectTable, localVarTypeObjectTable, localPositionTryObjectTable, localCreateThemeObjectTable, localCreateThemeSelectorTable, localCreateHashTable, localCreateObjectTable, localCreateAtomicMapTable, localCreateThemeHashTable, localCreateStaticHashTable, localCreateStaticObjectTable, localImports, } = entry;
|
|
1879
1919
|
const localCreateFunctionTable = {};
|
|
1880
1920
|
for (const localName of Object.keys(localImports)) {
|
|
1881
1921
|
const { actualPath, importedName } = localImports[localName];
|
|
@@ -1897,6 +1937,7 @@ function runScan(scanCwd, styleProp) {
|
|
|
1897
1937
|
keyframesHashTable: localKeyframesHashTable,
|
|
1898
1938
|
viewTransitionHashTable: localViewTransitionHashTable,
|
|
1899
1939
|
varTypeHashTable: localVarTypeHashTable,
|
|
1940
|
+
positionTryHashTable: localPositionTryHashTable,
|
|
1900
1941
|
createThemeHashTable: localCreateThemeHashTable,
|
|
1901
1942
|
createThemeObjectTable: localTables.createThemeObjectTable,
|
|
1902
1943
|
createHashTable: localCreateHashTable,
|
|
@@ -2313,8 +2354,10 @@ function runScan(scanCwd, styleProp) {
|
|
|
2313
2354
|
keyframesObjectTable: localKeyframesObjectTable,
|
|
2314
2355
|
viewTransitionHashTable: localViewTransitionHashTable,
|
|
2315
2356
|
varTypeHashTable: localVarTypeHashTable,
|
|
2357
|
+
positionTryHashTable: localPositionTryHashTable,
|
|
2316
2358
|
viewTransitionObjectTable: localViewTransitionObjectTable,
|
|
2317
2359
|
varTypeObjectTable: localVarTypeObjectTable,
|
|
2360
|
+
positionTryObjectTable: localPositionTryObjectTable,
|
|
2318
2361
|
createThemeHashTable: localCreateThemeHashTable,
|
|
2319
2362
|
createThemeSelectorTable: localCreateThemeSelectorTable,
|
|
2320
2363
|
createThemeObjectTable: localCreateThemeObjectTable,
|
|
@@ -2514,6 +2557,7 @@ function extractAndCacheExports(filePath, ast, mtimeMs) {
|
|
|
2514
2557
|
keyframesObjectTable: {},
|
|
2515
2558
|
viewTransitionHashTable: {},
|
|
2516
2559
|
varTypeHashTable: {},
|
|
2560
|
+
positionTryHashTable: {},
|
|
2517
2561
|
viewTransitionObjectTable: {},
|
|
2518
2562
|
createThemeHashTable: {},
|
|
2519
2563
|
createThemeSelectorTable: {},
|
|
@@ -2538,29 +2582,49 @@ function extractAndCacheExports(filePath, ast, mtimeMs) {
|
|
|
2538
2582
|
}
|
|
2539
2583
|
fileCache[filePath].exportsMtimeMs = mtimeMs;
|
|
2540
2584
|
}
|
|
2585
|
+
function refreshExports(filePath) {
|
|
2586
|
+
try {
|
|
2587
|
+
const stats = statFile(filePath);
|
|
2588
|
+
if ((!fileCache[filePath]?.exports ||
|
|
2589
|
+
fileCache[filePath].exportsMtimeMs !== stats.mtimeMs) &&
|
|
2590
|
+
stats.isFile()) {
|
|
2591
|
+
const source = (0, sourceCache_1.readSource)(filePath);
|
|
2592
|
+
const ast = (0, core_1.parseSync)(source, {
|
|
2593
|
+
syntax: 'typescript',
|
|
2594
|
+
tsx: true,
|
|
2595
|
+
target: 'es2022',
|
|
2596
|
+
});
|
|
2597
|
+
extractAndCacheExports(filePath, ast, stats.mtimeMs);
|
|
2598
|
+
}
|
|
2599
|
+
}
|
|
2600
|
+
catch (e) {
|
|
2601
|
+
}
|
|
2602
|
+
}
|
|
2603
|
+
function exportNames(filePath, withDefault = true, visited = new Set()) {
|
|
2604
|
+
if (visited.has(filePath))
|
|
2605
|
+
return [];
|
|
2606
|
+
visited.add(filePath);
|
|
2607
|
+
refreshExports(filePath);
|
|
2608
|
+
const exports = fileCache[filePath]?.exports;
|
|
2609
|
+
if (!exports)
|
|
2610
|
+
return [];
|
|
2611
|
+
const names = [
|
|
2612
|
+
...exports.localExports,
|
|
2613
|
+
...Object.keys(exports.reExports),
|
|
2614
|
+
].filter((name) => withDefault || name !== 'default');
|
|
2615
|
+
for (const source of exports.starExports) {
|
|
2616
|
+
const actualPath = (0, resolver_1.resolveImportPath)(source, filePath);
|
|
2617
|
+
if (actualPath)
|
|
2618
|
+
names.push(...exportNames(actualPath, false, visited));
|
|
2619
|
+
}
|
|
2620
|
+
return names;
|
|
2621
|
+
}
|
|
2541
2622
|
function resolveExport(filePath, exportName, visited = new Set()) {
|
|
2542
2623
|
const key = `${filePath}-${exportName}`;
|
|
2543
2624
|
if (visited.has(key))
|
|
2544
2625
|
return null;
|
|
2545
2626
|
visited.add(key);
|
|
2546
|
-
|
|
2547
|
-
try {
|
|
2548
|
-
const stats = statFile(filePath);
|
|
2549
|
-
if ((!fileCache[filePath]?.exports ||
|
|
2550
|
-
fileCache[filePath].exportsMtimeMs !== stats.mtimeMs) &&
|
|
2551
|
-
stats.isFile()) {
|
|
2552
|
-
const source = (0, sourceCache_1.readSource)(filePath);
|
|
2553
|
-
const ast = (0, core_1.parseSync)(source, {
|
|
2554
|
-
syntax: 'typescript',
|
|
2555
|
-
tsx: true,
|
|
2556
|
-
target: 'es2022',
|
|
2557
|
-
});
|
|
2558
|
-
extractAndCacheExports(filePath, ast, stats.mtimeMs);
|
|
2559
|
-
}
|
|
2560
|
-
}
|
|
2561
|
-
catch (e) {
|
|
2562
|
-
}
|
|
2563
|
-
}
|
|
2627
|
+
refreshExports(filePath);
|
|
2564
2628
|
const cached = fileCache[filePath];
|
|
2565
2629
|
if (!cached || !cached.exports)
|
|
2566
2630
|
return null;
|
|
@@ -2590,7 +2654,7 @@ function resolveExport(filePath, exportName, visited = new Set()) {
|
|
|
2590
2654
|
}
|
|
2591
2655
|
return null;
|
|
2592
2656
|
}
|
|
2593
|
-
const REFERENCE_MARKER = /(kf|vt|cr|pr)-([0-9a-z]+)/g;
|
|
2657
|
+
const REFERENCE_MARKER = /(kf|vt|pt|cr|pr)-([0-9a-z]+)/g;
|
|
2594
2658
|
const CUSTOM_PROPERTY = /var\(\s*(--[^\s,)]+)/g;
|
|
2595
2659
|
const appendSheet = (sheets) => {
|
|
2596
2660
|
const existingSheets = new Set(sheets);
|
|
@@ -2608,6 +2672,7 @@ function extractOndemandStyles(obj, addSheet, t) {
|
|
|
2608
2672
|
const visited = new Set();
|
|
2609
2673
|
const keyframesHashes = new Set();
|
|
2610
2674
|
const viewTransitionHashes = new Set();
|
|
2675
|
+
const positionTryHashes = new Set();
|
|
2611
2676
|
const varTypeHashes = new Set();
|
|
2612
2677
|
const createHashes = new Set();
|
|
2613
2678
|
const usedVariables = new Set();
|
|
@@ -2629,7 +2694,10 @@ function extractOndemandStyles(obj, addSheet, t) {
|
|
|
2629
2694
|
if (typeof val === 'string') {
|
|
2630
2695
|
if (val.includes('pr-'))
|
|
2631
2696
|
findVarTypes(val);
|
|
2632
|
-
if (val.includes('kf-') ||
|
|
2697
|
+
if (val.includes('kf-') ||
|
|
2698
|
+
val.includes('vt-') ||
|
|
2699
|
+
val.includes('pt-') ||
|
|
2700
|
+
val.includes('cr-')) {
|
|
2633
2701
|
for (const [, kind, hash] of val.matchAll(REFERENCE_MARKER)) {
|
|
2634
2702
|
if (kind === 'pr')
|
|
2635
2703
|
continue;
|
|
@@ -2646,6 +2714,13 @@ function extractOndemandStyles(obj, addSheet, t) {
|
|
|
2646
2714
|
walk(t.viewTransitionObjectTable[hash]);
|
|
2647
2715
|
}
|
|
2648
2716
|
}
|
|
2717
|
+
else if (kind === 'pt') {
|
|
2718
|
+
if (!positionTryHashes.has(hash) &&
|
|
2719
|
+
t.positionTryObjectTable?.[hash]) {
|
|
2720
|
+
positionTryHashes.add(hash);
|
|
2721
|
+
walk(t.positionTryObjectTable[hash]);
|
|
2722
|
+
}
|
|
2723
|
+
}
|
|
2649
2724
|
else if (!createHashes.has(hash) && t.createObjectTable[hash]) {
|
|
2650
2725
|
createHashes.add(hash);
|
|
2651
2726
|
walk(t.createObjectTable[hash]);
|
|
@@ -2686,6 +2761,10 @@ function extractOndemandStyles(obj, addSheet, t) {
|
|
|
2686
2761
|
}
|
|
2687
2762
|
}
|
|
2688
2763
|
}
|
|
2764
|
+
for (const hash of positionTryHashes) {
|
|
2765
|
+
const { styleSheet } = (0, zss_engine_1.transpile)((0, positionTry_1.createPositionTry)(t.positionTryObjectTable[hash], hash), undefined, '--global');
|
|
2766
|
+
addSheet(styleSheet);
|
|
2767
|
+
}
|
|
2689
2768
|
if (createHashes.size > 0) {
|
|
2690
2769
|
for (const hash of createHashes) {
|
|
2691
2770
|
const obj = t.createObjectTable[hash];
|
package/dist/propertyPolicy.js
CHANGED
|
@@ -37,7 +37,12 @@ exports.assertPropertyPolicy = exports.resolvePropertyPolicy = void 0;
|
|
|
37
37
|
const path = __importStar(require("path"));
|
|
38
38
|
const zss_engine_1 = require("zss-engine");
|
|
39
39
|
const parser_1 = require("./parser");
|
|
40
|
-
const STYLE_APIS = [
|
|
40
|
+
const STYLE_APIS = [
|
|
41
|
+
'create',
|
|
42
|
+
'keyframes',
|
|
43
|
+
'viewTransitionClass',
|
|
44
|
+
'positionTry',
|
|
45
|
+
];
|
|
41
46
|
const MESSAGES = {
|
|
42
47
|
physical: (name, counterpart) => `'${name}' is the physical name of this property. Write it as '${counterpart}', which follows the writing mode.`,
|
|
43
48
|
logical: (name, counterpart) => `'${name}' is the logical name of this property. This project is written in physical properties; use '${counterpart}'.`,
|
|
@@ -137,6 +142,10 @@ const assertPropertyPolicy = (ast, policy, resourcePath) => {
|
|
|
137
142
|
node.arguments.forEach(({ expression }) => {
|
|
138
143
|
if (!parser_1.t.isObjectExpression(expression))
|
|
139
144
|
return;
|
|
145
|
+
if (apiName === 'positionTry') {
|
|
146
|
+
check(expression);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
140
149
|
expression.properties.forEach((prop) => {
|
|
141
150
|
if (!parser_1.t.isObjectProperty(prop))
|
|
142
151
|
return;
|