@plumeria/utils 20.0.0 → 21.1.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 +84 -1
- package/dist/parser.d.ts +1 -0
- package/dist/parser.js +42 -21
- package/dist/propertyPolicy.js +6 -1
- package/dist/transform.js +137 -21
- package/dist/viewTransition.js +4 -4
- package/package.json +1 -1
package/dist/compile.js
CHANGED
|
@@ -44,6 +44,7 @@ const index_1 = require("./index");
|
|
|
44
44
|
const index_2 = require("./index");
|
|
45
45
|
const dynamicKey_1 = require("./dynamicKey");
|
|
46
46
|
const varType_1 = require("./varType");
|
|
47
|
+
const references_1 = require("./references");
|
|
47
48
|
const unwrapExport = (node) => {
|
|
48
49
|
if (node?.type === 'ExportDeclaration')
|
|
49
50
|
return node.declaration;
|
|
@@ -264,6 +265,8 @@ const applyWrites = (tables, writes) => {
|
|
|
264
265
|
const sheetCache = new Map();
|
|
265
266
|
let sheetCacheContext = '';
|
|
266
267
|
let sheetGlobals = '';
|
|
268
|
+
const VIEW_TRANSITION_ELEMENTS = ['ViewTransition', 'unstable_ViewTransition'];
|
|
269
|
+
const VIEW_TRANSITION_PROPS = ['default', 'enter', 'exit', 'update', 'share'];
|
|
267
270
|
function compileCSS(options) {
|
|
268
271
|
const { include, exclude, cwd = process.cwd(), styleProp = index_1.DEFAULT_STYLE_PROP, } = options;
|
|
269
272
|
const propertyPolicy = (0, index_1.resolvePropertyPolicy)(options);
|
|
@@ -358,9 +361,30 @@ function compileCSS(options) {
|
|
|
358
361
|
const localImports = {};
|
|
359
362
|
const localStyleAliases = {};
|
|
360
363
|
const registeredStyleCalls = new Set();
|
|
364
|
+
const viewTransitionElements = new Set();
|
|
365
|
+
const reactNamespaces = new Set();
|
|
361
366
|
(0, index_1.traverse)(ast, {
|
|
362
367
|
ImportDeclaration({ node }) {
|
|
363
368
|
const sourcePath = node.source.value;
|
|
369
|
+
if (sourcePath === 'react') {
|
|
370
|
+
if (node.typeOnly)
|
|
371
|
+
return;
|
|
372
|
+
node.specifiers.forEach((specifier) => {
|
|
373
|
+
if (specifier.type === 'ImportSpecifier') {
|
|
374
|
+
const importedName = specifier.imported
|
|
375
|
+
? specifier.imported.value
|
|
376
|
+
: specifier.local.value;
|
|
377
|
+
if (!specifier.isTypeOnly &&
|
|
378
|
+
VIEW_TRANSITION_ELEMENTS.includes(importedName)) {
|
|
379
|
+
viewTransitionElements.add(specifier.local.value);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
else {
|
|
383
|
+
reactNamespaces.add(specifier.local.value);
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
364
388
|
if (sourcePath === '@plumeria/core') {
|
|
365
389
|
node.specifiers.forEach((specifier) => {
|
|
366
390
|
if (specifier.type === 'ImportNamespaceSpecifier') {
|
|
@@ -605,6 +629,54 @@ function compileCSS(options) {
|
|
|
605
629
|
}
|
|
606
630
|
const ownerComponentOf = (at) => components.find((c) => at.span.start >= c.node.span.start &&
|
|
607
631
|
at.span.start <= c.node.span.end)?.name;
|
|
632
|
+
const isViewTransition = (name) => name.type === 'Identifier'
|
|
633
|
+
? viewTransitionElements.has(name.value)
|
|
634
|
+
: name.type === 'JSXMemberExpression' &&
|
|
635
|
+
name.object.type === 'Identifier' &&
|
|
636
|
+
reactNamespaces.has(name.object.value) &&
|
|
637
|
+
VIEW_TRANSITION_ELEMENTS.includes(name.property.value);
|
|
638
|
+
let viewTransitionReferences;
|
|
639
|
+
const processViewTransitionClass = (expr) => {
|
|
640
|
+
switch (expr.type) {
|
|
641
|
+
case 'ParenthesisExpression':
|
|
642
|
+
case 'TsAsExpression':
|
|
643
|
+
case 'TsSatisfiesExpression':
|
|
644
|
+
case 'TsNonNullExpression':
|
|
645
|
+
return processViewTransitionClass(expr.expression);
|
|
646
|
+
case 'ConditionalExpression':
|
|
647
|
+
processViewTransitionClass(expr.consequent);
|
|
648
|
+
return processViewTransitionClass(expr.alternate);
|
|
649
|
+
case 'TemplateLiteral':
|
|
650
|
+
return expr.expressions.forEach(processViewTransitionClass);
|
|
651
|
+
case 'BinaryExpression':
|
|
652
|
+
if (['&&', '||', '??'].includes(expr.operator)) {
|
|
653
|
+
processViewTransitionClass(expr.left);
|
|
654
|
+
processViewTransitionClass(expr.right);
|
|
655
|
+
}
|
|
656
|
+
return;
|
|
657
|
+
case 'ObjectExpression':
|
|
658
|
+
expr.properties.forEach((property) => {
|
|
659
|
+
if (property.type === 'KeyValueProperty') {
|
|
660
|
+
processViewTransitionClass(property.value);
|
|
661
|
+
}
|
|
662
|
+
else if (property.type === 'Identifier') {
|
|
663
|
+
processViewTransitionClass(property);
|
|
664
|
+
}
|
|
665
|
+
});
|
|
666
|
+
return;
|
|
667
|
+
case 'Identifier': {
|
|
668
|
+
viewTransitionReferences ??=
|
|
669
|
+
(0, references_1.collectReferenceIdentifiers)(ast).references;
|
|
670
|
+
if (!viewTransitionReferences.has(expr.span.start))
|
|
671
|
+
return;
|
|
672
|
+
const hash = mergedViewTransitionTable[expr.value];
|
|
673
|
+
if (typeof hash === 'string' && hash) {
|
|
674
|
+
(0, index_1.extractOndemandStyles)({ viewTransitionClass: `vt-${hash}` }, (0, index_1.appendSheet)(extractedSheets), scannedTables);
|
|
675
|
+
}
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
};
|
|
608
680
|
const processStyle = (style) => {
|
|
609
681
|
(0, index_1.extractOndemandStyles)(style, (0, index_1.appendSheet)(extractedSheets), scannedTables);
|
|
610
682
|
const records = (0, index_1.getStyleRecords)(style);
|
|
@@ -1039,7 +1111,7 @@ function compileCSS(options) {
|
|
|
1039
1111
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
1040
1112
|
writes.keyframesObjectTable[hash] = obj;
|
|
1041
1113
|
}
|
|
1042
|
-
else if (propName === '
|
|
1114
|
+
else if (propName === 'viewTransitionClass' &&
|
|
1043
1115
|
args.length > 0 &&
|
|
1044
1116
|
index_1.t.isObjectExpression(args[0].expression)) {
|
|
1045
1117
|
const obj = (0, index_1.objectExpressionToObject)(args[0].expression, ctx.mergedStaticTable, ctx.mergedKeyframesTable, ctx.mergedViewTransitionTable, ctx.mergedCreateThemeHashTable, ctx.scannedTables.createThemeObjectTable, ctx.mergedCreateTable, ctx.mergedCreateStaticHashTable, ctx.scannedTables.createStaticObjectTable, undefined, ctx.mergedVarTypeTable, ctx.mergedPositionTryTable);
|
|
@@ -1206,6 +1278,17 @@ function compileCSS(options) {
|
|
|
1206
1278
|
processCall(path.node);
|
|
1207
1279
|
},
|
|
1208
1280
|
JSXOpeningElement({ node }) {
|
|
1281
|
+
if (isViewTransition(node.name)) {
|
|
1282
|
+
node.attributes.forEach((attr) => {
|
|
1283
|
+
if (attr.type === 'JSXAttribute' &&
|
|
1284
|
+
attr.name.type === 'Identifier' &&
|
|
1285
|
+
VIEW_TRANSITION_PROPS.includes(attr.name.value) &&
|
|
1286
|
+
attr.value?.type === 'JSXExpressionContainer' &&
|
|
1287
|
+
attr.value.expression.type !== 'JSXEmptyExpression') {
|
|
1288
|
+
processViewTransitionClass(attr.value.expression);
|
|
1289
|
+
}
|
|
1290
|
+
});
|
|
1291
|
+
}
|
|
1209
1292
|
if (node.name.type === 'Identifier') {
|
|
1210
1293
|
const tagName = node.name.value;
|
|
1211
1294
|
if (tagName[0] !== tagName[0].toUpperCase())
|
package/dist/parser.d.ts
CHANGED
|
@@ -58,6 +58,7 @@ export declare function fileTableKeys(filePath: string, tableName: string): Read
|
|
|
58
58
|
export declare function scanOverlay(scanCwd?: string, styleProp?: string): Tables;
|
|
59
59
|
export declare function scanAll(scanCwd?: string, styleProp?: string): Tables;
|
|
60
60
|
export declare function getFileDependencies(filePath: string): string[];
|
|
61
|
+
export declare function exportNames(filePath: string, withDefault?: boolean, visited?: Set<string>): string[];
|
|
61
62
|
export declare function resolveExport(filePath: string, exportName: string, visited?: Set<string>): {
|
|
62
63
|
filePath: string;
|
|
63
64
|
localName: string;
|
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;
|
|
@@ -1731,7 +1732,7 @@ function runScan(scanCwd, styleProp) {
|
|
|
1731
1732
|
'createTheme',
|
|
1732
1733
|
'createStatic',
|
|
1733
1734
|
'keyframes',
|
|
1734
|
-
'
|
|
1735
|
+
'viewTransitionClass',
|
|
1735
1736
|
'positionTry',
|
|
1736
1737
|
'varType',
|
|
1737
1738
|
].includes(method)) {
|
|
@@ -1763,7 +1764,7 @@ function runScan(scanCwd, styleProp) {
|
|
|
1763
1764
|
const isPassOneMethod = method === 'createStatic' ||
|
|
1764
1765
|
method === 'createTheme' ||
|
|
1765
1766
|
method === 'keyframes' ||
|
|
1766
|
-
method === '
|
|
1767
|
+
method === 'viewTransitionClass' ||
|
|
1767
1768
|
method === 'positionTry' ||
|
|
1768
1769
|
method === 'varType';
|
|
1769
1770
|
if (isFirstPass && !isPassOneMethod)
|
|
@@ -1812,7 +1813,7 @@ function runScan(scanCwd, styleProp) {
|
|
|
1812
1813
|
localPositionTryObjectTable[hash] = obj;
|
|
1813
1814
|
registerObjectOwner('positionTryObjectTable', hash, filePath);
|
|
1814
1815
|
}
|
|
1815
|
-
else if (method === '
|
|
1816
|
+
else if (method === 'viewTransitionClass') {
|
|
1816
1817
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
1817
1818
|
localViewTransitionHashTable[name] = hash;
|
|
1818
1819
|
localTables.viewTransitionHashTable[uniqueKey] = hash;
|
|
@@ -2581,29 +2582,49 @@ function extractAndCacheExports(filePath, ast, mtimeMs) {
|
|
|
2581
2582
|
}
|
|
2582
2583
|
fileCache[filePath].exportsMtimeMs = mtimeMs;
|
|
2583
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
|
+
}
|
|
2584
2622
|
function resolveExport(filePath, exportName, visited = new Set()) {
|
|
2585
2623
|
const key = `${filePath}-${exportName}`;
|
|
2586
2624
|
if (visited.has(key))
|
|
2587
2625
|
return null;
|
|
2588
2626
|
visited.add(key);
|
|
2589
|
-
|
|
2590
|
-
try {
|
|
2591
|
-
const stats = statFile(filePath);
|
|
2592
|
-
if ((!fileCache[filePath]?.exports ||
|
|
2593
|
-
fileCache[filePath].exportsMtimeMs !== stats.mtimeMs) &&
|
|
2594
|
-
stats.isFile()) {
|
|
2595
|
-
const source = (0, sourceCache_1.readSource)(filePath);
|
|
2596
|
-
const ast = (0, core_1.parseSync)(source, {
|
|
2597
|
-
syntax: 'typescript',
|
|
2598
|
-
tsx: true,
|
|
2599
|
-
target: 'es2022',
|
|
2600
|
-
});
|
|
2601
|
-
extractAndCacheExports(filePath, ast, stats.mtimeMs);
|
|
2602
|
-
}
|
|
2603
|
-
}
|
|
2604
|
-
catch (e) {
|
|
2605
|
-
}
|
|
2606
|
-
}
|
|
2627
|
+
refreshExports(filePath);
|
|
2607
2628
|
const cached = fileCache[filePath];
|
|
2608
2629
|
if (!cached || !cached.exports)
|
|
2609
2630
|
return null;
|
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}'.`,
|
package/dist/transform.js
CHANGED
|
@@ -599,6 +599,14 @@ const transformSource = async (env) => {
|
|
|
599
599
|
: null;
|
|
600
600
|
};
|
|
601
601
|
const registeredStyleCalls = new Set();
|
|
602
|
+
const dropDefinition = (init, declSpan, isExported) => {
|
|
603
|
+
const span = isExported ? init.span : declSpan;
|
|
604
|
+
replacements.push({
|
|
605
|
+
start: span.start - baseByteOffset,
|
|
606
|
+
end: span.end - baseByteOffset,
|
|
607
|
+
content: isExported ? '""' : '',
|
|
608
|
+
});
|
|
609
|
+
};
|
|
602
610
|
const registerStyle = (node, declSpan, isExported) => {
|
|
603
611
|
let propName;
|
|
604
612
|
const init = unwrapStyleExpression(node.init);
|
|
@@ -777,11 +785,12 @@ const transformSource = async (env) => {
|
|
|
777
785
|
}
|
|
778
786
|
mergedVarTypeTable[node.id.value] = hash;
|
|
779
787
|
(scannedTables.varTypeObjectTable ??= {})[hash] = obj;
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
788
|
+
dropDefinition(init, declSpan, isExported);
|
|
789
|
+
}
|
|
790
|
+
else if (['keyframes', 'viewTransitionClass', 'positionTry'].includes(propName) &&
|
|
791
|
+
parser_1.t.isObjectExpression(init.arguments[0].expression)) {
|
|
792
|
+
registeredStyleCalls.add(init.span.start);
|
|
793
|
+
dropDefinition(init, declSpan, isExported);
|
|
785
794
|
}
|
|
786
795
|
else if (propName === 'createStatic' &&
|
|
787
796
|
parser_1.t.isObjectExpression(init.arguments[0].expression)) {
|
|
@@ -929,14 +938,16 @@ const transformSource = async (env) => {
|
|
|
929
938
|
], localConstNodes, getSource));
|
|
930
939
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
931
940
|
scannedTables.keyframesObjectTable[hash] = obj;
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
941
|
+
if (!registeredStyleCalls.has(node.span.start)) {
|
|
942
|
+
replacements.push({
|
|
943
|
+
start: node.span.start - baseByteOffset,
|
|
944
|
+
end: node.span.end - baseByteOffset,
|
|
945
|
+
content: JSON.stringify(`kf-${hash}`),
|
|
946
|
+
});
|
|
947
|
+
}
|
|
937
948
|
}
|
|
938
949
|
}
|
|
939
|
-
else if (propName === '
|
|
950
|
+
else if (propName === 'viewTransitionClass' &&
|
|
940
951
|
args.length > 0 &&
|
|
941
952
|
parser_1.t.isObjectExpression(args[0].expression)) {
|
|
942
953
|
const obj = (0, parser_1.objectExpressionToObject)(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, undefined, mergedVarTypeTable, mergedPositionTryTable);
|
|
@@ -955,11 +966,13 @@ const transformSource = async (env) => {
|
|
|
955
966
|
], localConstNodes, getSource));
|
|
956
967
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
957
968
|
scannedTables.viewTransitionObjectTable[hash] = obj;
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
969
|
+
if (!registeredStyleCalls.has(node.span.start)) {
|
|
970
|
+
replacements.push({
|
|
971
|
+
start: node.span.start - baseByteOffset,
|
|
972
|
+
end: node.span.end - baseByteOffset,
|
|
973
|
+
content: JSON.stringify(`vt-${hash}`),
|
|
974
|
+
});
|
|
975
|
+
}
|
|
963
976
|
}
|
|
964
977
|
else if (propName === 'positionTry' &&
|
|
965
978
|
args.length > 0 &&
|
|
@@ -980,11 +993,13 @@ const transformSource = async (env) => {
|
|
|
980
993
|
], localConstNodes, getSource));
|
|
981
994
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
982
995
|
(scannedTables.positionTryObjectTable ??= {})[hash] = obj;
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
996
|
+
if (!registeredStyleCalls.has(node.span.start)) {
|
|
997
|
+
replacements.push({
|
|
998
|
+
start: node.span.start - baseByteOffset,
|
|
999
|
+
end: node.span.end - baseByteOffset,
|
|
1000
|
+
content: JSON.stringify(`--pt-${hash}`),
|
|
1001
|
+
});
|
|
1002
|
+
}
|
|
988
1003
|
}
|
|
989
1004
|
else if (propName === 'createTheme' &&
|
|
990
1005
|
args.length >= 2 &&
|
|
@@ -2065,6 +2080,70 @@ const transformSource = async (env) => {
|
|
|
2065
2080
|
propVarSpreads,
|
|
2066
2081
|
};
|
|
2067
2082
|
};
|
|
2083
|
+
const definitionTables = [
|
|
2084
|
+
'keyframesHashTable',
|
|
2085
|
+
'viewTransitionHashTable',
|
|
2086
|
+
'positionTryHashTable',
|
|
2087
|
+
'varTypeHashTable',
|
|
2088
|
+
'createThemeHashTable',
|
|
2089
|
+
'createHashTable',
|
|
2090
|
+
'createStaticHashTable',
|
|
2091
|
+
];
|
|
2092
|
+
const namespacePath = (name) => {
|
|
2093
|
+
const namespaceImport = localImports[name];
|
|
2094
|
+
return namespaceImport?.importedName === '*'
|
|
2095
|
+
? namespaceImport.actualPath
|
|
2096
|
+
: undefined;
|
|
2097
|
+
};
|
|
2098
|
+
const definitionKey = (actualPath, propName) => {
|
|
2099
|
+
const resolved = (0, parser_1.resolveExport)(actualPath, propName);
|
|
2100
|
+
return resolved
|
|
2101
|
+
? `${resolved.filePath}-${resolved.localName}`
|
|
2102
|
+
: `${actualPath}-${propName}`;
|
|
2103
|
+
};
|
|
2104
|
+
const isDefinitionKey = (uniqueKey) => definitionTables.some((table) => Boolean(scannedTables[table]?.[uniqueKey]));
|
|
2105
|
+
const namespaceReads = new Set();
|
|
2106
|
+
const staticKey = (expr) => expr.type === 'StringLiteral'
|
|
2107
|
+
? expr.value
|
|
2108
|
+
: expr.type === 'TemplateLiteral' && expr.expressions.length === 0
|
|
2109
|
+
? (expr.quasis[0]?.cooked ?? undefined)
|
|
2110
|
+
: undefined;
|
|
2111
|
+
const patternKey = (key) => key.type === 'Identifier' || key.type === 'StringLiteral'
|
|
2112
|
+
? key.value
|
|
2113
|
+
: key.type === 'Computed'
|
|
2114
|
+
? staticKey(key.expression)
|
|
2115
|
+
: undefined;
|
|
2116
|
+
const exportedDefinition = (actualPath) => (0, parser_1.exportNames)(actualPath).find((exportName) => isDefinitionKey(definitionKey(actualPath, exportName)));
|
|
2117
|
+
const namespaceKeys = (namespace, actualPath, keys) => {
|
|
2118
|
+
for (const [key, node] of keys) {
|
|
2119
|
+
if (key !== undefined) {
|
|
2120
|
+
if (isDefinitionKey(definitionKey(actualPath, key)))
|
|
2121
|
+
throwNamespaceRead(namespace, key, node);
|
|
2122
|
+
continue;
|
|
2123
|
+
}
|
|
2124
|
+
const name = exportedDefinition(actualPath);
|
|
2125
|
+
if (name)
|
|
2126
|
+
throwNamespaceRead(namespace, name, node);
|
|
2127
|
+
}
|
|
2128
|
+
};
|
|
2129
|
+
const namespacePattern = (pattern, init) => {
|
|
2130
|
+
if (!parser_1.t.isIdentifier(init) ||
|
|
2131
|
+
!referenceIdents.references.has(init.span.start))
|
|
2132
|
+
return;
|
|
2133
|
+
const actualPath = namespacePath(init.value);
|
|
2134
|
+
if (!actualPath)
|
|
2135
|
+
return;
|
|
2136
|
+
namespaceKeys(init.value, actualPath, pattern.properties.map((prop) => [
|
|
2137
|
+
prop.type === 'RestElement'
|
|
2138
|
+
? undefined
|
|
2139
|
+
: prop.type === 'AssignmentPatternProperty'
|
|
2140
|
+
? prop.key.value
|
|
2141
|
+
: patternKey(prop.key),
|
|
2142
|
+
prop.type === 'KeyValuePatternProperty' ? prop.key : prop,
|
|
2143
|
+
]));
|
|
2144
|
+
namespaceReads.add(init.span.start);
|
|
2145
|
+
};
|
|
2146
|
+
const throwNamespaceRead = (namespace, propName, node) => throwCompilationError(`[plumeria] ${namespace}.${propName} reads a Plumeria definition through a namespace import, which cannot be compiled. Import it by name: import { ${propName} } from '...'.`, node);
|
|
2068
2147
|
(0, parser_1.traverse)(ast, {
|
|
2069
2148
|
JSXOpeningElement({ node }) {
|
|
2070
2149
|
const owner = {
|
|
@@ -2075,9 +2154,29 @@ const transformSource = async (env) => {
|
|
|
2075
2154
|
if (attribute.type === 'JSXAttribute')
|
|
2076
2155
|
jsxAttributeOwnerMap.set(attribute.span.start, owner);
|
|
2077
2156
|
},
|
|
2157
|
+
VariableDeclarator({ node }) {
|
|
2158
|
+
if (node.id.type === 'ObjectPattern' && node.init)
|
|
2159
|
+
namespacePattern(node.id, node.init);
|
|
2160
|
+
},
|
|
2161
|
+
AssignmentExpression({ node }) {
|
|
2162
|
+
if (node.left.type === 'ObjectPattern')
|
|
2163
|
+
namespacePattern(node.left, node.right);
|
|
2164
|
+
},
|
|
2078
2165
|
MemberExpression({ node }) {
|
|
2079
2166
|
if (!isVisibleReference(node))
|
|
2080
2167
|
return;
|
|
2168
|
+
if (parser_1.t.isIdentifier(node.object)) {
|
|
2169
|
+
const actualPath = namespacePath(node.object.value);
|
|
2170
|
+
const propName = parser_1.t.isIdentifier(node.property)
|
|
2171
|
+
? node.property.value
|
|
2172
|
+
: node.property.type === 'Computed'
|
|
2173
|
+
? staticKey(node.property.expression)
|
|
2174
|
+
: undefined;
|
|
2175
|
+
if (actualPath && propName !== undefined) {
|
|
2176
|
+
namespaceKeys(node.object.value, actualPath, [[propName, node]]);
|
|
2177
|
+
namespaceReads.add(node.object.span.start);
|
|
2178
|
+
}
|
|
2179
|
+
}
|
|
2081
2180
|
if (parser_1.t.isIdentifier(node.object) &&
|
|
2082
2181
|
(parser_1.t.isIdentifier(node.property) || node.property.type === 'Computed')) {
|
|
2083
2182
|
const varName = node.object.value;
|
|
@@ -2192,6 +2291,13 @@ const transformSource = async (env) => {
|
|
|
2192
2291
|
return;
|
|
2193
2292
|
if (!referenceIdents.references.has(node.span.start))
|
|
2194
2293
|
return;
|
|
2294
|
+
if (!namespaceReads.has(node.span.start)) {
|
|
2295
|
+
const actualPath = namespacePath(node.value);
|
|
2296
|
+
const name = actualPath && exportedDefinition(actualPath);
|
|
2297
|
+
if (name) {
|
|
2298
|
+
throwCompilationError(`[plumeria] ${node.value} is used as a whole, but it holds ${node.value}.${name}, a Plumeria definition that cannot be compiled through a namespace import. Import the names it needs instead: import { ${name} } from '...'.`, node);
|
|
2299
|
+
}
|
|
2300
|
+
}
|
|
2195
2301
|
const prefix = referenceIdents.shorthands.has(node.span.start)
|
|
2196
2302
|
? `${node.value}: `
|
|
2197
2303
|
: '';
|
|
@@ -2202,6 +2308,16 @@ const transformSource = async (env) => {
|
|
|
2202
2308
|
content: `${prefix}${content}`,
|
|
2203
2309
|
});
|
|
2204
2310
|
};
|
|
2311
|
+
const definition = [
|
|
2312
|
+
['kf-', mergedKeyframesTable[node.value]],
|
|
2313
|
+
['vt-', mergedViewTransitionTable[node.value]],
|
|
2314
|
+
['--pt-', mergedPositionTryTable[node.value]],
|
|
2315
|
+
['--pr-', mergedVarTypeTable[node.value]],
|
|
2316
|
+
].find(([, hash]) => typeof hash === 'string' && hash);
|
|
2317
|
+
if (definition) {
|
|
2318
|
+
pushReplacement(JSON.stringify(`${definition[0]}${definition[1]}`));
|
|
2319
|
+
return;
|
|
2320
|
+
}
|
|
2205
2321
|
const styleInfo = localCreateStyles[node.value];
|
|
2206
2322
|
if (styleInfo) {
|
|
2207
2323
|
pushReplacement(`(${JSON.stringify(styleInfo.hashMap)})`);
|
package/dist/viewTransition.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createViewTransition = void 0;
|
|
4
4
|
const createViewTransition = (rule, hash) => ({
|
|
5
|
-
[`::view-transition-group(vt-${hash})`]: rule.group,
|
|
6
|
-
[`::view-transition-image-pair(vt-${hash})`]: rule.imagePair,
|
|
7
|
-
[`::view-transition-old(vt-${hash})`]: rule.old,
|
|
8
|
-
[`::view-transition-new(vt-${hash})`]: rule.new,
|
|
5
|
+
[`::view-transition-group(*.vt-${hash})`]: rule.group,
|
|
6
|
+
[`::view-transition-image-pair(*.vt-${hash})`]: rule.imagePair,
|
|
7
|
+
[`::view-transition-old(*.vt-${hash})`]: rule.old,
|
|
8
|
+
[`::view-transition-new(*.vt-${hash})`]: rule.new,
|
|
9
9
|
});
|
|
10
10
|
exports.createViewTransition = createViewTransition;
|