tempo-sdk 0.0.52 → 0.0.57
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/assets/index.js +4 -2
- package/dist/assets/index.js.map +1 -1
- package/dist/canvas/editor.d.ts +11 -16
- package/dist/canvas/editor.js +79 -49
- package/dist/canvas/editor.js.map +1 -1
- package/dist/canvas/index.d.ts +10 -6
- package/dist/canvas/index.js +130 -47
- package/dist/canvas/index.js.map +1 -1
- package/dist/canvas/interact-projection.js +4 -3
- package/dist/canvas/parser.d.ts +10 -5
- package/dist/canvas/parser.js +3 -1
- package/dist/canvas/svelte.d.ts +8 -5
- package/dist/canvas/svelte.js +20 -5
- package/dist/canvas/svelte.js.map +1 -1
- package/dist/chunk-2IQD2KPS.js +219 -0
- package/dist/chunk-2IQD2KPS.js.map +1 -0
- package/dist/chunk-5BHIHP25.js +410 -0
- package/dist/chunk-5BHIHP25.js.map +1 -0
- package/dist/chunk-EMYYTS6D.js +1585 -0
- package/dist/chunk-EMYYTS6D.js.map +1 -0
- package/dist/{chunk-DX6XAXCK.js → chunk-N2TYN3RB.js} +189 -420
- package/dist/chunk-N2TYN3RB.js.map +1 -0
- package/dist/{chunk-7Y7XNHUM.js → chunk-QXL6GL2P.js} +18 -3
- package/dist/chunk-QXL6GL2P.js.map +1 -0
- package/dist/{chunk-QP2NTODB.js → chunk-RHHVVWAC.js} +115 -25
- package/dist/chunk-RHHVVWAC.js.map +1 -0
- package/dist/chunk-TL4MGN7E.js +2570 -0
- package/dist/chunk-TL4MGN7E.js.map +1 -0
- package/dist/{chunk-PULSTDX2.js → chunk-U3SLJNRS.js} +284 -46
- package/dist/chunk-U3SLJNRS.js.map +1 -0
- package/dist/{chunk-ZZYNOX24.js → chunk-U64AHDHZ.js} +1708 -2461
- package/dist/chunk-U64AHDHZ.js.map +1 -0
- package/dist/expo/plugin.cjs +1256 -16
- package/dist/expo/plugin.cjs.map +1 -1
- package/dist/expo/plugin.d.cts +0 -1
- package/dist/expo/plugin.d.ts +0 -1
- package/dist/expo/plugin.js +1 -1
- package/dist/expo-babel-plugin.cjs +1258 -16
- package/dist/expo-babel-plugin.cjs.map +1 -1
- package/dist/expo-babel-plugin.d.cts +8 -5
- package/dist/expo-babel-plugin.d.ts +8 -5
- package/dist/expo-babel-plugin.js +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +463 -153
- package/dist/index.js.map +1 -1
- package/dist/nextjs/plugin.cjs +151 -0
- package/dist/nextjs/plugin.cjs.map +1 -1
- package/dist/nextjs/plugin.d.cts +1 -1
- package/dist/nextjs/plugin.d.ts +1 -1
- package/dist/nextjs/plugin.js +1 -1
- package/dist/nextjs-loader.cjs +1432 -35
- package/dist/nextjs-loader.cjs.map +1 -1
- package/dist/nextjs.cjs +17 -2
- package/dist/nextjs.cjs.map +1 -1
- package/dist/nextjs.d.cts +14 -3
- package/dist/nextjs.d.ts +14 -3
- package/dist/nextjs.js +1 -1
- package/dist/{page-xi1aI5a7.d.ts → page-DwLnOM5d.d.ts} +12 -6
- package/dist/{storyboard-DbtzTPvI.d.ts → storyboard-BtQuVGpl.d.ts} +33 -15
- package/dist/svelte.d.ts +3 -2
- package/dist/svelte.js +103 -29
- package/dist/svelte.js.map +1 -1
- package/dist/v1-client-compat-qxaXEDm_.d.ts +23 -0
- package/package.json +5 -2
- package/dist/chunk-57KAYXHF.js +0 -19
- package/dist/chunk-57KAYXHF.js.map +0 -1
- package/dist/chunk-7Y7XNHUM.js.map +0 -1
- package/dist/chunk-CB5NJJJT.js +0 -345
- package/dist/chunk-CB5NJJJT.js.map +0 -1
- package/dist/chunk-DX6XAXCK.js.map +0 -1
- package/dist/chunk-F3KJDCMU.js +0 -19
- package/dist/chunk-F3KJDCMU.js.map +0 -1
- package/dist/chunk-PULSTDX2.js.map +0 -1
- package/dist/chunk-QP2NTODB.js.map +0 -1
- package/dist/chunk-ZZYNOX24.js.map +0 -1
|
@@ -24,14 +24,1164 @@ __export(expo_babel_plugin_exports, {
|
|
|
24
24
|
tempoExpoBabelPlugin: () => tempoExpoBabelPlugin
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(expo_babel_plugin_exports);
|
|
27
|
-
var import_node_fs2 = require("fs");
|
|
28
|
-
var import_node_path2 = require("path");
|
|
29
|
-
var import_pluginutils = require("@rollup/pluginutils");
|
|
30
27
|
|
|
31
|
-
//
|
|
28
|
+
// canvas-component-reference.ts
|
|
32
29
|
var import_node_fs = require("fs");
|
|
33
30
|
var import_node_path = require("path");
|
|
34
31
|
|
|
32
|
+
// canvas/parser.ts
|
|
33
|
+
var import_oxc_parser = require("oxc-parser");
|
|
34
|
+
var SDK_IMPORT_SOURCES = /* @__PURE__ */ new Set([
|
|
35
|
+
"tempo-sdk/canvas",
|
|
36
|
+
"tempo-sdk/canvas/svelte"
|
|
37
|
+
]);
|
|
38
|
+
var SDK_COMPONENTS = /* @__PURE__ */ new Set([
|
|
39
|
+
"Canvas",
|
|
40
|
+
"Storyboard",
|
|
41
|
+
"SvelteStoryboard",
|
|
42
|
+
"LegacyStoryboardV1",
|
|
43
|
+
"RouteStoryboard",
|
|
44
|
+
"HtmlStoryboard"
|
|
45
|
+
]);
|
|
46
|
+
var SDK_CANVAS_VALUE_EXPORTS = /* @__PURE__ */ new Set([
|
|
47
|
+
"Canvas",
|
|
48
|
+
"CanvasContext",
|
|
49
|
+
"getCanvasStoryboardRenderId",
|
|
50
|
+
"CanvasHost",
|
|
51
|
+
"buildRenderContentFiberSelector",
|
|
52
|
+
"buildRenderContentSelector",
|
|
53
|
+
"buildRenderSelector",
|
|
54
|
+
"captureStoryboardCombined",
|
|
55
|
+
"captureStoryboardHtml",
|
|
56
|
+
"captureStoryboardImage",
|
|
57
|
+
"stripRenderContentWrapperAttributes",
|
|
58
|
+
"stripRenderContentWrapperFromCombinedCapture",
|
|
59
|
+
"watchStoryboardCombined",
|
|
60
|
+
"getCanvasHostRuntime",
|
|
61
|
+
"getOptionalCanvasHostRuntime",
|
|
62
|
+
"useActiveState",
|
|
63
|
+
"HtmlStoryboard",
|
|
64
|
+
"LegacyStoryboardV1",
|
|
65
|
+
"RouteStoryboard",
|
|
66
|
+
"Storyboard",
|
|
67
|
+
"StoryboardSlot"
|
|
68
|
+
]);
|
|
69
|
+
var DEFAULT_LAYOUT = {
|
|
70
|
+
x: 0,
|
|
71
|
+
y: 0
|
|
72
|
+
};
|
|
73
|
+
var DEFAULT_VIEWPORT_LAYOUT = {
|
|
74
|
+
...DEFAULT_LAYOUT,
|
|
75
|
+
width: 600,
|
|
76
|
+
height: 400
|
|
77
|
+
};
|
|
78
|
+
var NO_CANVAS_DECLARATION_ERROR = "No <Canvas> declaration found in canvas file";
|
|
79
|
+
function parseCanvasFile(filePath, source) {
|
|
80
|
+
const errors = [];
|
|
81
|
+
let program;
|
|
82
|
+
try {
|
|
83
|
+
const result = (0, import_oxc_parser.parseSync)(filePath, source);
|
|
84
|
+
program = result.program;
|
|
85
|
+
for (const error of result.errors ?? []) {
|
|
86
|
+
errors.push({
|
|
87
|
+
message: error.message ?? "Unable to parse canvas source",
|
|
88
|
+
span: toSpan(error) ?? toSpan(error?.labels?.[0]),
|
|
89
|
+
kind: "structural"
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
} catch (error) {
|
|
93
|
+
return {
|
|
94
|
+
filePath,
|
|
95
|
+
pageName: fallbackPageName(filePath),
|
|
96
|
+
imports: [],
|
|
97
|
+
misimportedSdkCanvasImports: [],
|
|
98
|
+
storyboards: [],
|
|
99
|
+
errors: [
|
|
100
|
+
{
|
|
101
|
+
message: error instanceof Error ? error.message : "Unable to parse canvas source",
|
|
102
|
+
kind: "structural"
|
|
103
|
+
}
|
|
104
|
+
]
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
const imports = readImports(program);
|
|
108
|
+
const misimportedSdkCanvasImports = readMisimportedSdkCanvasImports(program);
|
|
109
|
+
const { legacyObjects, stringBindings: objectStringBindings } = readObjectExpressionBindings(program, imports, source);
|
|
110
|
+
let canvasElement = null;
|
|
111
|
+
const allStoryboardElements = [];
|
|
112
|
+
walk(program, (node) => {
|
|
113
|
+
if (node.type !== "JSXElement") return;
|
|
114
|
+
const component = resolveSdkComponent(node.openingElement?.name, imports);
|
|
115
|
+
const namespaceMisimport = resolveMisimportedNamespaceSdkComponent(
|
|
116
|
+
node.openingElement?.name,
|
|
117
|
+
imports,
|
|
118
|
+
misimportedSdkCanvasImports
|
|
119
|
+
);
|
|
120
|
+
if (namespaceMisimport) {
|
|
121
|
+
misimportedSdkCanvasImports.add(namespaceMisimport);
|
|
122
|
+
}
|
|
123
|
+
if (component === "Canvas") {
|
|
124
|
+
if (!canvasElement) {
|
|
125
|
+
canvasElement = node;
|
|
126
|
+
} else {
|
|
127
|
+
errors.push({
|
|
128
|
+
message: "Canvas file must declare exactly one <Canvas> element",
|
|
129
|
+
span: toSpan(node),
|
|
130
|
+
kind: "structural"
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (isStoryboardSdkComponent(component)) {
|
|
136
|
+
allStoryboardElements.push({ element: node, component });
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
const directStoryboardElements = canvasElement ? readDirectCanvasStoryboardElements(canvasElement, imports) : [];
|
|
140
|
+
const directStoryboardElementSet = new Set(
|
|
141
|
+
directStoryboardElements.map((item) => item.element)
|
|
142
|
+
);
|
|
143
|
+
const storyboards = directStoryboardElements.map(
|
|
144
|
+
(item) => readStoryboard(
|
|
145
|
+
item.element,
|
|
146
|
+
item.component,
|
|
147
|
+
imports,
|
|
148
|
+
legacyObjects,
|
|
149
|
+
source,
|
|
150
|
+
errors
|
|
151
|
+
)
|
|
152
|
+
);
|
|
153
|
+
for (const item of allStoryboardElements) {
|
|
154
|
+
if (directStoryboardElementSet.has(item.element)) continue;
|
|
155
|
+
errors.push({
|
|
156
|
+
message: `<${item.component}> declarations must be direct children of the <Canvas> element`,
|
|
157
|
+
span: toSpan(item.element),
|
|
158
|
+
kind: "structural"
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
reportDuplicateStoryboardIds(storyboards, errors);
|
|
162
|
+
if (!canvasElement) {
|
|
163
|
+
if (misimportedSdkCanvasImports.all.length > 0) {
|
|
164
|
+
for (const entry of misimportedSdkCanvasImports.all) {
|
|
165
|
+
errors.push({
|
|
166
|
+
message: misimportedSdkCanvasImportMessage(entry),
|
|
167
|
+
span: entry.sourceSpan,
|
|
168
|
+
kind: "structural"
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
} else {
|
|
172
|
+
errors.push({
|
|
173
|
+
message: NO_CANVAS_DECLARATION_ERROR,
|
|
174
|
+
kind: "structural"
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
} else {
|
|
178
|
+
errors.push(...validateCanvasChildren(canvasElement, imports));
|
|
179
|
+
}
|
|
180
|
+
const openingElement = canvasElement?.openingElement;
|
|
181
|
+
const name = readResolvableStringAttribute(
|
|
182
|
+
openingElement,
|
|
183
|
+
"name",
|
|
184
|
+
objectStringBindings
|
|
185
|
+
);
|
|
186
|
+
const path = readStringAttribute(openingElement, "path");
|
|
187
|
+
const backgroundColor = readResolvableStringAttribute(
|
|
188
|
+
openingElement,
|
|
189
|
+
"backgroundColor",
|
|
190
|
+
objectStringBindings
|
|
191
|
+
) ?? readResolvableStringAttribute(
|
|
192
|
+
openingElement,
|
|
193
|
+
"background",
|
|
194
|
+
objectStringBindings
|
|
195
|
+
);
|
|
196
|
+
if (openingElement && !name) {
|
|
197
|
+
errors.push({
|
|
198
|
+
message: '<Canvas> must include a literal "name" prop',
|
|
199
|
+
span: toSpan(openingElement),
|
|
200
|
+
kind: "degraded"
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
return {
|
|
204
|
+
filePath,
|
|
205
|
+
canvasPath: path?.value,
|
|
206
|
+
pageName: name?.value ?? fallbackPageName(filePath),
|
|
207
|
+
backgroundColor: backgroundColor?.value,
|
|
208
|
+
canvasElementSpan: toSpan(canvasElement),
|
|
209
|
+
canvasOpeningElementSpan: toSpan(openingElement),
|
|
210
|
+
canvasChildrenInsertionOffset: typeof canvasElement?.closingElement?.start === "number" ? canvasElement.closingElement.start : void 0,
|
|
211
|
+
nameSpan: name?.valueSpan,
|
|
212
|
+
nameAttributeSpan: name?.attributeSpan,
|
|
213
|
+
pathSpan: path?.valueSpan,
|
|
214
|
+
pathAttributeSpan: path?.attributeSpan,
|
|
215
|
+
backgroundColorSpan: backgroundColor?.valueSpan,
|
|
216
|
+
backgroundColorAttributeSpan: backgroundColor?.attributeSpan,
|
|
217
|
+
imports: imports.all,
|
|
218
|
+
misimportedSdkCanvasImports: misimportedSdkCanvasImports.all,
|
|
219
|
+
storyboards,
|
|
220
|
+
errors
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
function misimportedSdkCanvasImportMessage(entry) {
|
|
224
|
+
return `Tempo canvas components must be imported from "tempo-sdk/canvas" \u2014 found import of ${entry.importedNames.join(", ")} from "${entry.source}"`;
|
|
225
|
+
}
|
|
226
|
+
function readMisimportedSdkCanvasImports(program) {
|
|
227
|
+
const all = [];
|
|
228
|
+
const byDeclarationKey = /* @__PURE__ */ new Map();
|
|
229
|
+
const namespaceCandidatesByLocalName = /* @__PURE__ */ new Map();
|
|
230
|
+
const add = (entry) => {
|
|
231
|
+
const key = spanKey(entry.sourceSpan);
|
|
232
|
+
if (byDeclarationKey.has(key)) return;
|
|
233
|
+
byDeclarationKey.set(key, entry);
|
|
234
|
+
all.push(entry);
|
|
235
|
+
};
|
|
236
|
+
for (const statement of program?.body ?? []) {
|
|
237
|
+
if (statement?.type !== "ImportDeclaration" || typeof statement.source?.value !== "string" || !isWrongTempoSdkCanvasImportSource(statement.source.value) || statement.importKind === "type") {
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
const source = statement.source.value;
|
|
241
|
+
const sourceSpan = toSpan(statement.source);
|
|
242
|
+
if (!sourceSpan) continue;
|
|
243
|
+
const valueSpecifiers = (statement.specifiers ?? []).filter(
|
|
244
|
+
(specifier) => specifier?.importKind !== "type"
|
|
245
|
+
);
|
|
246
|
+
const importedNames = valueSpecifiers.map(readImportedName);
|
|
247
|
+
const entry = {
|
|
248
|
+
source,
|
|
249
|
+
sourceSpan,
|
|
250
|
+
importedNames,
|
|
251
|
+
rewritable: valueSpecifiers.length > 0 && valueSpecifiers.every(
|
|
252
|
+
(specifier) => specifier?.type === "ImportSpecifier" && SDK_CANVAS_VALUE_EXPORTS.has(readImportedName(specifier))
|
|
253
|
+
)
|
|
254
|
+
};
|
|
255
|
+
const hasMisimportedNamedSdkComponent = valueSpecifiers.some(
|
|
256
|
+
(specifier) => specifier?.type === "ImportSpecifier" && SDK_COMPONENTS.has(readImportedName(specifier))
|
|
257
|
+
);
|
|
258
|
+
if (hasMisimportedNamedSdkComponent) {
|
|
259
|
+
add(entry);
|
|
260
|
+
}
|
|
261
|
+
for (const specifier of valueSpecifiers) {
|
|
262
|
+
if (specifier?.type !== "ImportNamespaceSpecifier") continue;
|
|
263
|
+
const localName = specifier.local?.name;
|
|
264
|
+
if (typeof localName === "string") {
|
|
265
|
+
namespaceCandidatesByLocalName.set(localName, entry);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return { all, byDeclarationKey, namespaceCandidatesByLocalName, add };
|
|
270
|
+
}
|
|
271
|
+
function readImports(program) {
|
|
272
|
+
const all = [];
|
|
273
|
+
const byLocalName = /* @__PURE__ */ new Map();
|
|
274
|
+
const sdkLocalNames = /* @__PURE__ */ new Map();
|
|
275
|
+
const sdkNamespaces = /* @__PURE__ */ new Set();
|
|
276
|
+
for (const statement of program?.body ?? []) {
|
|
277
|
+
if (statement?.type !== "ImportDeclaration" || typeof statement.source?.value !== "string") {
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
const source = statement.source.value;
|
|
281
|
+
const isSdkImport = isSdkImportSource(source);
|
|
282
|
+
for (const specifier of statement.specifiers ?? []) {
|
|
283
|
+
const localName = specifier.local?.name;
|
|
284
|
+
if (typeof localName !== "string") continue;
|
|
285
|
+
const importedName = readImportedName(specifier);
|
|
286
|
+
const imported = {
|
|
287
|
+
localName,
|
|
288
|
+
source,
|
|
289
|
+
importedName,
|
|
290
|
+
kind: readImportKind(specifier),
|
|
291
|
+
importKind: specifier.importKind === "type" ? "type" : "value",
|
|
292
|
+
span: toSpan(specifier) ?? toSpan(statement) ?? { start: 0, end: 0 },
|
|
293
|
+
declarationSpan: toSpan(statement) ?? { start: 0, end: 0 },
|
|
294
|
+
specifierCount: statement.specifiers?.length ?? 0,
|
|
295
|
+
namedSpecifierCount: (statement.specifiers ?? []).filter(
|
|
296
|
+
(item) => item?.type === "ImportSpecifier"
|
|
297
|
+
).length,
|
|
298
|
+
hasDefaultSpecifier: (statement.specifiers ?? []).some(
|
|
299
|
+
(item) => item?.type === "ImportDefaultSpecifier"
|
|
300
|
+
),
|
|
301
|
+
hasNamespaceSpecifier: (statement.specifiers ?? []).some(
|
|
302
|
+
(item) => item?.type === "ImportNamespaceSpecifier"
|
|
303
|
+
)
|
|
304
|
+
};
|
|
305
|
+
all.push(imported);
|
|
306
|
+
byLocalName.set(localName, imported);
|
|
307
|
+
if (!isSdkImport) continue;
|
|
308
|
+
if (specifier.type === "ImportNamespaceSpecifier") {
|
|
309
|
+
sdkNamespaces.add(localName);
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
if (SDK_COMPONENTS.has(importedName)) {
|
|
313
|
+
sdkLocalNames.set(localName, importedName);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return { all, byLocalName, sdkLocalNames, sdkNamespaces };
|
|
318
|
+
}
|
|
319
|
+
function readObjectExpressionBindings(program, imports, source) {
|
|
320
|
+
const legacyObjects = /* @__PURE__ */ new Map();
|
|
321
|
+
const stringBindings = /* @__PURE__ */ new Map();
|
|
322
|
+
for (const node of readTopLevelVariableDeclarators(program)) {
|
|
323
|
+
if (node.id?.type !== "Identifier") {
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
const objectExpression = unwrapTsExpression(node.init);
|
|
327
|
+
if (objectExpression?.type !== "ObjectExpression") continue;
|
|
328
|
+
const bindingName = node.id.name;
|
|
329
|
+
legacyObjects.set(
|
|
330
|
+
bindingName,
|
|
331
|
+
readLegacyStoryboardObject(
|
|
332
|
+
bindingName,
|
|
333
|
+
objectExpression,
|
|
334
|
+
imports,
|
|
335
|
+
source
|
|
336
|
+
)
|
|
337
|
+
);
|
|
338
|
+
const stringProperties = readObjectStringProperties(objectExpression);
|
|
339
|
+
if (stringProperties.size > 0) {
|
|
340
|
+
stringBindings.set(bindingName, stringProperties);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return { legacyObjects, stringBindings };
|
|
344
|
+
}
|
|
345
|
+
function readTopLevelVariableDeclarators(program) {
|
|
346
|
+
const declarators = [];
|
|
347
|
+
for (const statement of program?.body ?? []) {
|
|
348
|
+
const declaration = statement?.type === "VariableDeclaration" ? statement : statement?.type === "ExportNamedDeclaration" && statement.declaration?.type === "VariableDeclaration" ? statement.declaration : null;
|
|
349
|
+
if (!declaration) continue;
|
|
350
|
+
declarators.push(...declaration.declarations ?? []);
|
|
351
|
+
}
|
|
352
|
+
return declarators;
|
|
353
|
+
}
|
|
354
|
+
function readLegacyStoryboardObject(bindingName, objectExpression, imports, source) {
|
|
355
|
+
const errors = [];
|
|
356
|
+
const nameProperty = getObjectProperty(objectExpression, "name");
|
|
357
|
+
const name = nameProperty ? readStringLiteralValue(nameProperty.value) : null;
|
|
358
|
+
const layoutProperty = getObjectProperty(objectExpression, "layout");
|
|
359
|
+
const layout = layoutProperty ? readLayoutExpression(layoutProperty.value, "LegacyStoryboardV1") : {
|
|
360
|
+
value: DEFAULT_LAYOUT,
|
|
361
|
+
errors: [
|
|
362
|
+
{
|
|
363
|
+
message: '<LegacyStoryboardV1> storyboard object must include a literal "layout" object',
|
|
364
|
+
span: toSpan(objectExpression),
|
|
365
|
+
kind: "degraded"
|
|
366
|
+
}
|
|
367
|
+
]
|
|
368
|
+
};
|
|
369
|
+
const renderProperty = getObjectProperty(objectExpression, "render");
|
|
370
|
+
const component = readRenderComponentReference(
|
|
371
|
+
renderProperty?.value,
|
|
372
|
+
imports,
|
|
373
|
+
source
|
|
374
|
+
);
|
|
375
|
+
if (nameProperty && !name) {
|
|
376
|
+
errors.push({
|
|
377
|
+
message: "<LegacyStoryboardV1> storyboard.name must be a string literal when set",
|
|
378
|
+
span: toSpan(nameProperty),
|
|
379
|
+
kind: "degraded"
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
errors.push(...layout.errors);
|
|
383
|
+
return {
|
|
384
|
+
bindingName,
|
|
385
|
+
displayName: name?.value,
|
|
386
|
+
component: component ?? void 0,
|
|
387
|
+
objectSpan: toSpan(objectExpression),
|
|
388
|
+
objectClose: readLayoutClose(objectExpression),
|
|
389
|
+
nameSpan: name?.span,
|
|
390
|
+
namePropertySpan: toSpan(nameProperty),
|
|
391
|
+
layoutPropertySpan: toSpan(layoutProperty),
|
|
392
|
+
layout: layout.value,
|
|
393
|
+
layoutSpans: layout.spans,
|
|
394
|
+
errors
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
function readObjectStringProperties(objectExpression) {
|
|
398
|
+
const properties = /* @__PURE__ */ new Map();
|
|
399
|
+
for (const property of objectExpression.properties ?? []) {
|
|
400
|
+
if (property?.type !== "Property" || property.computed) continue;
|
|
401
|
+
const propertyName = readPropertyKeyName(property.key);
|
|
402
|
+
const value = readStringLiteralValue(property.value);
|
|
403
|
+
if (!propertyName || !value) continue;
|
|
404
|
+
properties.set(propertyName, value);
|
|
405
|
+
}
|
|
406
|
+
return properties;
|
|
407
|
+
}
|
|
408
|
+
function readStoryboard(element, component, imports, legacyObjects, source, globalErrors) {
|
|
409
|
+
const openingElement = element.openingElement;
|
|
410
|
+
const errors = [];
|
|
411
|
+
const id = readStringAttribute(openingElement, "id");
|
|
412
|
+
const name = readStringAttribute(openingElement, "name");
|
|
413
|
+
const legacyReference = component === "LegacyStoryboardV1" ? readExpressionReference(openingElement, "storyboard", source) : void 0;
|
|
414
|
+
const legacyObject = legacyReference?.expression && isIdentifierExpression(legacyReference.expression) ? legacyObjects.get(legacyReference.expression) : void 0;
|
|
415
|
+
const layout = component === "LegacyStoryboardV1" ? {
|
|
416
|
+
value: legacyObject?.layout ?? DEFAULT_LAYOUT,
|
|
417
|
+
spans: legacyObject?.layoutSpans,
|
|
418
|
+
attributeSpan: void 0,
|
|
419
|
+
errors: legacyObject?.errors ?? (legacyReference ? [
|
|
420
|
+
{
|
|
421
|
+
message: "<LegacyStoryboardV1> storyboard prop must reference a same-file object literal",
|
|
422
|
+
span: legacyReference.span,
|
|
423
|
+
kind: "degraded"
|
|
424
|
+
}
|
|
425
|
+
] : [
|
|
426
|
+
{
|
|
427
|
+
message: '<LegacyStoryboardV1> must include a "storyboard" expression prop',
|
|
428
|
+
span: toSpan(openingElement),
|
|
429
|
+
kind: "degraded"
|
|
430
|
+
}
|
|
431
|
+
])
|
|
432
|
+
} : readLayout(openingElement, component);
|
|
433
|
+
const kind = component === "Storyboard" || component === "SvelteStoryboard" || component === "LegacyStoryboardV1" ? "component" : component === "RouteStoryboard" ? "route" : "html";
|
|
434
|
+
if (!id) {
|
|
435
|
+
errors.push({
|
|
436
|
+
message: `<${component}> must include a literal "id" prop`,
|
|
437
|
+
span: toSpan(openingElement),
|
|
438
|
+
kind: "structural"
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
if (layout.errors.length > 0) {
|
|
442
|
+
errors.push(...layout.errors);
|
|
443
|
+
}
|
|
444
|
+
const storyboard = {
|
|
445
|
+
storyboardKey: id?.value ?? "",
|
|
446
|
+
displayName: name?.value ?? legacyObject?.displayName,
|
|
447
|
+
kind,
|
|
448
|
+
...component === "SvelteStoryboard" ? { uiFramework: "svelte" } : {},
|
|
449
|
+
layout: layout.value,
|
|
450
|
+
editable: Boolean(id) && layout.errors.length === 0,
|
|
451
|
+
jsxElementSpan: toSpan(element) ?? { start: 0, end: 0 },
|
|
452
|
+
openingElementSpan: toSpan(openingElement),
|
|
453
|
+
idSpan: id?.valueSpan,
|
|
454
|
+
idAttributeSpan: id?.attributeSpan,
|
|
455
|
+
nameSpan: name?.valueSpan ?? legacyObject?.nameSpan,
|
|
456
|
+
nameAttributeSpan: name?.attributeSpan ?? legacyObject?.namePropertySpan,
|
|
457
|
+
layoutAttributeSpan: layout.attributeSpan,
|
|
458
|
+
layoutSpans: layout.spans,
|
|
459
|
+
props: readExpressionReference(openingElement, "props", source),
|
|
460
|
+
component: legacyObject?.component,
|
|
461
|
+
legacyV1: legacyReference ? {
|
|
462
|
+
storyboard: legacyReference,
|
|
463
|
+
objectName: legacyObject?.bindingName,
|
|
464
|
+
objectSpan: legacyObject?.objectSpan,
|
|
465
|
+
objectClose: legacyObject?.objectClose,
|
|
466
|
+
namePropertySpan: legacyObject?.namePropertySpan,
|
|
467
|
+
layoutPropertySpan: legacyObject?.layoutPropertySpan
|
|
468
|
+
} : void 0,
|
|
469
|
+
errors
|
|
470
|
+
};
|
|
471
|
+
if (component === "Storyboard" || component === "SvelteStoryboard") {
|
|
472
|
+
const componentReference = readComponentReference(
|
|
473
|
+
openingElement,
|
|
474
|
+
imports,
|
|
475
|
+
source
|
|
476
|
+
);
|
|
477
|
+
if (componentReference) {
|
|
478
|
+
storyboard.component = componentReference;
|
|
479
|
+
} else {
|
|
480
|
+
errors.push({
|
|
481
|
+
message: `<${component}> must include a "component" expression prop`,
|
|
482
|
+
span: toSpan(openingElement),
|
|
483
|
+
kind: "degraded"
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
if (component === "Storyboard" || component === "SvelteStoryboard" || component === "HtmlStoryboard") {
|
|
488
|
+
const vrt = readVrt(openingElement, errors);
|
|
489
|
+
if (vrt) {
|
|
490
|
+
if (vrt.value) {
|
|
491
|
+
storyboard.vrt = vrt.value;
|
|
492
|
+
}
|
|
493
|
+
storyboard.vrtAttributeSpan = vrt.attributeSpan;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
if (component === "RouteStoryboard") {
|
|
497
|
+
const route = readStringAttribute(openingElement, "route");
|
|
498
|
+
if (route) {
|
|
499
|
+
storyboard.route = route.value;
|
|
500
|
+
storyboard.routeSpan = route.valueSpan;
|
|
501
|
+
storyboard.routeAttributeSpan = route.attributeSpan;
|
|
502
|
+
} else {
|
|
503
|
+
errors.push({
|
|
504
|
+
message: '<RouteStoryboard> must include a literal "route" prop',
|
|
505
|
+
span: toSpan(openingElement),
|
|
506
|
+
kind: "degraded"
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
if (component === "HtmlStoryboard") {
|
|
511
|
+
const filepath = readStringAttribute(openingElement, "filepath");
|
|
512
|
+
const src = readStringAttribute(openingElement, "src");
|
|
513
|
+
storyboard.filepath = filepath?.value;
|
|
514
|
+
storyboard.filepathSpan = filepath?.valueSpan;
|
|
515
|
+
storyboard.filepathAttributeSpan = filepath?.attributeSpan;
|
|
516
|
+
storyboard.src = src?.value;
|
|
517
|
+
storyboard.srcSpan = src?.valueSpan;
|
|
518
|
+
storyboard.srcAttributeSpan = src?.attributeSpan;
|
|
519
|
+
if (!filepath && !src) {
|
|
520
|
+
errors.push({
|
|
521
|
+
message: '<HtmlStoryboard> must include a literal "filepath" or "src" prop',
|
|
522
|
+
span: toSpan(openingElement),
|
|
523
|
+
kind: "degraded"
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
globalErrors.push(...errors);
|
|
528
|
+
return storyboard;
|
|
529
|
+
}
|
|
530
|
+
function readDirectCanvasStoryboardElements(canvasElement, imports) {
|
|
531
|
+
const elements = [];
|
|
532
|
+
for (const child of canvasElement.children ?? []) {
|
|
533
|
+
if (child?.type !== "JSXElement") continue;
|
|
534
|
+
const component = resolveSdkComponent(child.openingElement?.name, imports);
|
|
535
|
+
if (isStoryboardSdkComponent(component)) {
|
|
536
|
+
elements.push({ element: child, component });
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
return elements;
|
|
540
|
+
}
|
|
541
|
+
function reportDuplicateStoryboardIds(storyboards, errors) {
|
|
542
|
+
const byId = /* @__PURE__ */ new Map();
|
|
543
|
+
for (const storyboard of storyboards) {
|
|
544
|
+
if (!storyboard.storyboardKey) continue;
|
|
545
|
+
const matching = byId.get(storyboard.storyboardKey);
|
|
546
|
+
if (matching) {
|
|
547
|
+
matching.push(storyboard);
|
|
548
|
+
} else {
|
|
549
|
+
byId.set(storyboard.storyboardKey, [storyboard]);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
for (const [storyboardKey, matching] of byId) {
|
|
553
|
+
if (matching.length < 2) continue;
|
|
554
|
+
errors.push({
|
|
555
|
+
message: `Duplicate storyboard id "${storyboardKey}" (${matching.length} declarations) \u2014 storyboard ids must be unique`,
|
|
556
|
+
span: matching[1]?.jsxElementSpan,
|
|
557
|
+
kind: "structural"
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
function validateCanvasChildren(canvasElement, imports) {
|
|
562
|
+
const errors = [];
|
|
563
|
+
for (const child of canvasElement.children ?? []) {
|
|
564
|
+
if (!child) continue;
|
|
565
|
+
if (child.type === "JSXText") {
|
|
566
|
+
if (typeof child.value === "string" && child.value.trim() === "") {
|
|
567
|
+
continue;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
if (child.type === "JSXExpressionContainer") {
|
|
571
|
+
if (child.expression?.type === "JSXEmptyExpression") {
|
|
572
|
+
continue;
|
|
573
|
+
}
|
|
574
|
+
errors.push({
|
|
575
|
+
message: "<Canvas> children must be static storyboard declarations, not expressions",
|
|
576
|
+
span: toSpan(child),
|
|
577
|
+
kind: "structural"
|
|
578
|
+
});
|
|
579
|
+
continue;
|
|
580
|
+
}
|
|
581
|
+
if (child.type === "JSXElement") {
|
|
582
|
+
const component = resolveSdkComponent(
|
|
583
|
+
child.openingElement?.name,
|
|
584
|
+
imports
|
|
585
|
+
);
|
|
586
|
+
if (component === "Storyboard" || component === "SvelteStoryboard" || component === "LegacyStoryboardV1" || component === "RouteStoryboard" || component === "HtmlStoryboard") {
|
|
587
|
+
continue;
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
errors.push({
|
|
591
|
+
message: "<Canvas> children must be <Storyboard>, <SvelteStoryboard>, <RouteStoryboard>, <HtmlStoryboard>, or <LegacyStoryboardV1> declarations",
|
|
592
|
+
span: toSpan(child),
|
|
593
|
+
kind: "structural"
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
return errors;
|
|
597
|
+
}
|
|
598
|
+
function readVrt(openingElement, errors) {
|
|
599
|
+
const attribute = getAttribute(openingElement, "vrt");
|
|
600
|
+
if (!attribute) return null;
|
|
601
|
+
const attributeSpan = toSpan(attribute);
|
|
602
|
+
if (attribute.value == null) {
|
|
603
|
+
return { value: {}, attributeSpan };
|
|
604
|
+
}
|
|
605
|
+
const expression = unwrapTsExpression(
|
|
606
|
+
unwrapAttributeExpression(attribute.value)
|
|
607
|
+
);
|
|
608
|
+
if (expression?.type === "Literal" && expression.value === true) {
|
|
609
|
+
return { value: {}, attributeSpan };
|
|
610
|
+
}
|
|
611
|
+
if (expression?.type === "Literal" && expression.value === false) {
|
|
612
|
+
return { value: null, attributeSpan };
|
|
613
|
+
}
|
|
614
|
+
if (expression?.type !== "ObjectExpression") {
|
|
615
|
+
errors.push({
|
|
616
|
+
message: "<Storyboard> vrt must be a boolean literal or an object literal ({ threshold?, skip?, ignore? })",
|
|
617
|
+
span: toSpan(expression) ?? attributeSpan,
|
|
618
|
+
kind: "degraded"
|
|
619
|
+
});
|
|
620
|
+
return { value: null, attributeSpan };
|
|
621
|
+
}
|
|
622
|
+
const value = {};
|
|
623
|
+
for (const property of expression.properties ?? []) {
|
|
624
|
+
if (property?.type !== "Property" || property.computed) {
|
|
625
|
+
errors.push({
|
|
626
|
+
message: "<Storyboard> vrt must contain only literal properties",
|
|
627
|
+
span: toSpan(property ?? expression),
|
|
628
|
+
kind: "degraded"
|
|
629
|
+
});
|
|
630
|
+
continue;
|
|
631
|
+
}
|
|
632
|
+
const key = readPropertyKeyName(property.key);
|
|
633
|
+
if (key === "threshold") {
|
|
634
|
+
const threshold = readNumberLiteral(property.value);
|
|
635
|
+
if (threshold && threshold.value >= 0 && threshold.value <= 0.5) {
|
|
636
|
+
value.threshold = threshold.value;
|
|
637
|
+
} else {
|
|
638
|
+
errors.push({
|
|
639
|
+
message: "<Storyboard> vrt.threshold must be a number literal between 0 and 0.5",
|
|
640
|
+
span: toSpan(property),
|
|
641
|
+
kind: "degraded"
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
continue;
|
|
645
|
+
}
|
|
646
|
+
if (key === "skip") {
|
|
647
|
+
if (property.value?.type === "Literal" && typeof property.value.value === "boolean") {
|
|
648
|
+
if (property.value.value) value.skip = true;
|
|
649
|
+
} else {
|
|
650
|
+
errors.push({
|
|
651
|
+
message: "<Storyboard> vrt.skip must be a boolean literal",
|
|
652
|
+
span: toSpan(property),
|
|
653
|
+
kind: "degraded"
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
continue;
|
|
657
|
+
}
|
|
658
|
+
if (key === "ignore") {
|
|
659
|
+
const regions = readVrtIgnoreRegions(property.value, errors);
|
|
660
|
+
if (regions) value.ignore = regions;
|
|
661
|
+
continue;
|
|
662
|
+
}
|
|
663
|
+
errors.push({
|
|
664
|
+
message: `<Storyboard> vrt has unknown property "${key ?? "?"}" \u2014 expected threshold, skip, or ignore`,
|
|
665
|
+
span: toSpan(property),
|
|
666
|
+
kind: "degraded"
|
|
667
|
+
});
|
|
668
|
+
}
|
|
669
|
+
return { value, attributeSpan };
|
|
670
|
+
}
|
|
671
|
+
function readVrtIgnoreRegions(node, errors) {
|
|
672
|
+
if (node?.type !== "ArrayExpression") {
|
|
673
|
+
errors.push({
|
|
674
|
+
message: "<Storyboard> vrt.ignore must be an array of { x, y, w, h } literals",
|
|
675
|
+
span: toSpan(node),
|
|
676
|
+
kind: "degraded"
|
|
677
|
+
});
|
|
678
|
+
return null;
|
|
679
|
+
}
|
|
680
|
+
const regions = [];
|
|
681
|
+
for (const element of node.elements ?? []) {
|
|
682
|
+
const region = {};
|
|
683
|
+
for (const key of ["x", "y", "w", "h"]) {
|
|
684
|
+
const property = getObjectProperty(element, key);
|
|
685
|
+
const number = property ? readNumberLiteral(property.value) : null;
|
|
686
|
+
if (number) region[key] = number.value;
|
|
687
|
+
}
|
|
688
|
+
if (region.x === void 0 || region.y === void 0 || region.w === void 0 || region.h === void 0) {
|
|
689
|
+
errors.push({
|
|
690
|
+
message: "<Storyboard> vrt.ignore regions must be { x, y, w, h } number literals",
|
|
691
|
+
span: toSpan(element) ?? toSpan(node),
|
|
692
|
+
kind: "degraded"
|
|
693
|
+
});
|
|
694
|
+
return null;
|
|
695
|
+
}
|
|
696
|
+
regions.push(region);
|
|
697
|
+
}
|
|
698
|
+
return regions;
|
|
699
|
+
}
|
|
700
|
+
function readComponentReference(openingElement, imports, source) {
|
|
701
|
+
const attribute = getAttribute(openingElement, "component");
|
|
702
|
+
const expression = unwrapAttributeExpression(attribute?.value);
|
|
703
|
+
const span = toSpan(expression);
|
|
704
|
+
if (!expression || !span) return null;
|
|
705
|
+
const localName = expression.type === "Identifier" ? expression.name : expression.type === "MemberExpression" && expression.object?.type === "Identifier" ? expression.object.name : void 0;
|
|
706
|
+
return {
|
|
707
|
+
expression: source.slice(span.start, span.end),
|
|
708
|
+
span,
|
|
709
|
+
attributeSpan: toSpan(attribute),
|
|
710
|
+
localName,
|
|
711
|
+
import: localName ? imports.byLocalName.get(localName) : void 0
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
function readRenderComponentReference(renderValue, imports, source) {
|
|
715
|
+
if (renderValue?.type !== "ArrowFunctionExpression") return null;
|
|
716
|
+
const body = unwrapTsExpression(renderValue.body);
|
|
717
|
+
if (body?.type !== "JSXElement") return null;
|
|
718
|
+
const name = body.openingElement?.name;
|
|
719
|
+
if (name?.type !== "JSXIdentifier") return null;
|
|
720
|
+
const span = toSpan(name);
|
|
721
|
+
if (!span || typeof name.name !== "string") return null;
|
|
722
|
+
return {
|
|
723
|
+
expression: source.slice(span.start, span.end),
|
|
724
|
+
span,
|
|
725
|
+
localName: name.name,
|
|
726
|
+
import: imports.byLocalName.get(name.name)
|
|
727
|
+
};
|
|
728
|
+
}
|
|
729
|
+
function readExpressionReference(openingElement, name, source) {
|
|
730
|
+
const attribute = getAttribute(openingElement, name);
|
|
731
|
+
const expression = unwrapAttributeExpression(attribute?.value);
|
|
732
|
+
const span = toSpan(expression);
|
|
733
|
+
if (!expression || !span) return void 0;
|
|
734
|
+
return {
|
|
735
|
+
expression: source.slice(span.start, span.end),
|
|
736
|
+
span,
|
|
737
|
+
attributeSpan: toSpan(attribute)
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
function isIdentifierExpression(expression) {
|
|
741
|
+
return /^[A-Za-z_$][\w$]*$/.test(expression);
|
|
742
|
+
}
|
|
743
|
+
function readLayout(openingElement, componentName) {
|
|
744
|
+
const isViewport = componentName === "RouteStoryboard" || componentName === "HtmlStoryboard";
|
|
745
|
+
const attribute = getAttribute(openingElement, "layout");
|
|
746
|
+
const expression = unwrapAttributeExpression(attribute?.value);
|
|
747
|
+
if (!expression) {
|
|
748
|
+
return {
|
|
749
|
+
value: isViewport ? DEFAULT_VIEWPORT_LAYOUT : DEFAULT_LAYOUT,
|
|
750
|
+
attributeSpan: toSpan(attribute),
|
|
751
|
+
errors: [
|
|
752
|
+
{
|
|
753
|
+
message: `<${componentName}> must include a literal "layout" object prop`,
|
|
754
|
+
span: toSpan(openingElement),
|
|
755
|
+
kind: "degraded"
|
|
756
|
+
}
|
|
757
|
+
]
|
|
758
|
+
};
|
|
759
|
+
}
|
|
760
|
+
const layout = readLayoutExpression(expression, componentName);
|
|
761
|
+
return {
|
|
762
|
+
...layout,
|
|
763
|
+
attributeSpan: toSpan(attribute)
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
function readLayoutExpression(expression, componentName) {
|
|
767
|
+
const errors = [];
|
|
768
|
+
const isViewport = componentName === "RouteStoryboard" || componentName === "HtmlStoryboard";
|
|
769
|
+
if (expression.type !== "ObjectExpression") {
|
|
770
|
+
return {
|
|
771
|
+
value: isViewport ? DEFAULT_VIEWPORT_LAYOUT : DEFAULT_LAYOUT,
|
|
772
|
+
spans: { layoutClose: readLayoutClose(expression) },
|
|
773
|
+
errors: [
|
|
774
|
+
{
|
|
775
|
+
message: `<${componentName}> layout must be an object literal`,
|
|
776
|
+
span: toSpan(expression),
|
|
777
|
+
kind: "degraded"
|
|
778
|
+
}
|
|
779
|
+
]
|
|
780
|
+
};
|
|
781
|
+
}
|
|
782
|
+
const spans = {
|
|
783
|
+
layoutClose: readLayoutClose(expression)
|
|
784
|
+
};
|
|
785
|
+
const layout = { ...DEFAULT_LAYOUT };
|
|
786
|
+
const width = getObjectProperty(expression, "width");
|
|
787
|
+
const height = getObjectProperty(expression, "height");
|
|
788
|
+
const legacySizing = getObjectProperty(expression, "intrinsicSizing");
|
|
789
|
+
const legacyResponsiveFlag = legacySizing?.value?.value === "root-element";
|
|
790
|
+
const hasBothSizes = Boolean(width && height);
|
|
791
|
+
const readSize = isViewport || hasBothSizes && !legacyResponsiveFlag;
|
|
792
|
+
const incompleteSize = !isViewport && Boolean(width) !== Boolean(height);
|
|
793
|
+
if (incompleteSize) {
|
|
794
|
+
errors.push({
|
|
795
|
+
message: "layout.width and layout.height must be set together",
|
|
796
|
+
span: toSpan(expression),
|
|
797
|
+
kind: "degraded"
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
const size = readSize ? {
|
|
801
|
+
width: width ? readNumberLiteral(width.value) : null,
|
|
802
|
+
height: height ? readNumberLiteral(height.value) : null
|
|
803
|
+
} : null;
|
|
804
|
+
const keys = readSize ? ["x", "y", "width", "height"] : ["x", "y"];
|
|
805
|
+
for (const key of keys) {
|
|
806
|
+
const property = key === "width" ? width : key === "height" ? height : getObjectProperty(expression, key);
|
|
807
|
+
const value = key === "width" || key === "height" ? size?.[key] : property ? readNumberLiteral(property.value) : null;
|
|
808
|
+
const keepValue = key === "x" || key === "y" || isViewport || Boolean(size?.width && size.height);
|
|
809
|
+
if (!value) {
|
|
810
|
+
errors.push({
|
|
811
|
+
message: `<${componentName}> layout.${key} must be a number literal`,
|
|
812
|
+
span: toSpan(property ?? expression),
|
|
813
|
+
kind: "degraded"
|
|
814
|
+
});
|
|
815
|
+
continue;
|
|
816
|
+
}
|
|
817
|
+
if (!keepValue) continue;
|
|
818
|
+
layout[key] = value.value;
|
|
819
|
+
spans[key] = value.span;
|
|
820
|
+
}
|
|
821
|
+
const zIndex = getObjectProperty(expression, "zIndex");
|
|
822
|
+
if (zIndex) {
|
|
823
|
+
const value = readNumberLiteral(zIndex.value);
|
|
824
|
+
if (value) {
|
|
825
|
+
layout.zIndex = value.value;
|
|
826
|
+
spans.zIndex = value.span;
|
|
827
|
+
} else {
|
|
828
|
+
errors.push({
|
|
829
|
+
message: `<${componentName}> layout.zIndex must be a number literal`,
|
|
830
|
+
span: toSpan(zIndex),
|
|
831
|
+
kind: "degraded"
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
const invalidLegacyFlag = legacySizing && (legacySizing.value?.type !== "Literal" || !legacyResponsiveFlag);
|
|
836
|
+
if (invalidLegacyFlag) {
|
|
837
|
+
errors.push({
|
|
838
|
+
message: `<${componentName}> layout.intrinsicSizing must be "root-element" when set`,
|
|
839
|
+
span: toSpan(legacySizing),
|
|
840
|
+
kind: "degraded"
|
|
841
|
+
});
|
|
842
|
+
}
|
|
843
|
+
return { value: layout, spans, errors };
|
|
844
|
+
}
|
|
845
|
+
function readStringLiteralValue(node) {
|
|
846
|
+
return node?.type === "Literal" && typeof node.value === "string" ? { value: node.value, span: toSpan(node) ?? { start: 0, end: 0 } } : null;
|
|
847
|
+
}
|
|
848
|
+
function unwrapTsExpression(node) {
|
|
849
|
+
let current = node;
|
|
850
|
+
while (current?.type === "TSSatisfiesExpression" || current?.type === "TSAsExpression" || current?.type === "TSNonNullExpression" || current?.type === "ParenthesizedExpression") {
|
|
851
|
+
current = current.expression;
|
|
852
|
+
}
|
|
853
|
+
return current;
|
|
854
|
+
}
|
|
855
|
+
function readResolvableStringAttribute(openingElement, name, bindings) {
|
|
856
|
+
const literal = readStringAttribute(openingElement, name);
|
|
857
|
+
if (literal) return literal;
|
|
858
|
+
const attribute = getAttribute(openingElement, name);
|
|
859
|
+
const expression = unwrapAttributeExpression(attribute?.value);
|
|
860
|
+
const expressionSpan = toSpan(expression);
|
|
861
|
+
const attributeSpan = toSpan(attribute);
|
|
862
|
+
if (!expression || !expressionSpan || !attributeSpan) return null;
|
|
863
|
+
const resolved = resolveStringMemberExpression(expression, bindings);
|
|
864
|
+
return resolved ? {
|
|
865
|
+
value: resolved.value,
|
|
866
|
+
valueSpan: expressionSpan,
|
|
867
|
+
attributeSpan
|
|
868
|
+
} : null;
|
|
869
|
+
}
|
|
870
|
+
function resolveStringMemberExpression(expression, bindings) {
|
|
871
|
+
if (expression?.type !== "MemberExpression") return null;
|
|
872
|
+
if (expression.object?.type !== "Identifier") return null;
|
|
873
|
+
const propertyName = readPropertyKeyName(expression.property);
|
|
874
|
+
if (!propertyName) return null;
|
|
875
|
+
return bindings.get(expression.object.name)?.get(propertyName) ?? null;
|
|
876
|
+
}
|
|
877
|
+
function readStringAttribute(openingElement, name) {
|
|
878
|
+
const attribute = getAttribute(openingElement, name);
|
|
879
|
+
if (!attribute) return null;
|
|
880
|
+
const value = attribute.value;
|
|
881
|
+
if (value?.type === "Literal" && typeof value.value === "string") {
|
|
882
|
+
return {
|
|
883
|
+
value: value.value,
|
|
884
|
+
valueSpan: toSpan(value) ?? toSpan(attribute) ?? { start: 0, end: 0 },
|
|
885
|
+
attributeSpan: toSpan(attribute) ?? { start: 0, end: 0 }
|
|
886
|
+
};
|
|
887
|
+
}
|
|
888
|
+
const expression = unwrapAttributeExpression(value);
|
|
889
|
+
if (expression?.type === "Literal" && typeof expression.value === "string") {
|
|
890
|
+
return {
|
|
891
|
+
value: expression.value,
|
|
892
|
+
valueSpan: toSpan(expression) ?? toSpan(attribute) ?? { start: 0, end: 0 },
|
|
893
|
+
attributeSpan: toSpan(attribute) ?? { start: 0, end: 0 }
|
|
894
|
+
};
|
|
895
|
+
}
|
|
896
|
+
return null;
|
|
897
|
+
}
|
|
898
|
+
function getAttribute(openingElement, name) {
|
|
899
|
+
for (const attribute of openingElement?.attributes ?? []) {
|
|
900
|
+
if (attribute?.type === "JSXAttribute" && attribute.name?.type === "JSXIdentifier" && attribute.name.name === name) {
|
|
901
|
+
return attribute;
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
return null;
|
|
905
|
+
}
|
|
906
|
+
function unwrapAttributeExpression(value) {
|
|
907
|
+
if (!value) return null;
|
|
908
|
+
if (value.type === "JSXExpressionContainer") {
|
|
909
|
+
return value.expression;
|
|
910
|
+
}
|
|
911
|
+
return value;
|
|
912
|
+
}
|
|
913
|
+
function readPropertyKeyName(key) {
|
|
914
|
+
if (key?.type === "Identifier") return key.name;
|
|
915
|
+
if (key?.type === "Literal" && typeof key.value === "string") {
|
|
916
|
+
return key.value;
|
|
917
|
+
}
|
|
918
|
+
return null;
|
|
919
|
+
}
|
|
920
|
+
function getObjectProperty(objectExpression, name) {
|
|
921
|
+
if (objectExpression?.type !== "ObjectExpression") return null;
|
|
922
|
+
for (const property of objectExpression.properties ?? []) {
|
|
923
|
+
if (property?.type !== "Property" || property.computed) continue;
|
|
924
|
+
const propertyName = readPropertyKeyName(property.key);
|
|
925
|
+
if (propertyName === name) return property;
|
|
926
|
+
}
|
|
927
|
+
return null;
|
|
928
|
+
}
|
|
929
|
+
function readNumberLiteral(node) {
|
|
930
|
+
if (node?.type === "Literal" && typeof node.value === "number" && Number.isFinite(node.value)) {
|
|
931
|
+
return { value: node.value, span: toSpan(node) ?? { start: 0, end: 0 } };
|
|
932
|
+
}
|
|
933
|
+
if (node?.type === "UnaryExpression" && node.operator === "-" && node.argument?.type === "Literal" && typeof node.argument.value === "number" && Number.isFinite(node.argument.value)) {
|
|
934
|
+
return {
|
|
935
|
+
value: -node.argument.value,
|
|
936
|
+
span: toSpan(node) ?? { start: 0, end: 0 }
|
|
937
|
+
};
|
|
938
|
+
}
|
|
939
|
+
return null;
|
|
940
|
+
}
|
|
941
|
+
function resolveSdkComponent(nameNode, imports) {
|
|
942
|
+
if (nameNode?.type === "JSXIdentifier") {
|
|
943
|
+
return imports.sdkLocalNames.get(nameNode.name) ?? null;
|
|
944
|
+
}
|
|
945
|
+
if (nameNode?.type === "JSXMemberExpression" && nameNode.object?.type === "JSXIdentifier" && nameNode.property?.type === "JSXIdentifier" && imports.sdkNamespaces.has(nameNode.object.name) && SDK_COMPONENTS.has(nameNode.property.name)) {
|
|
946
|
+
return nameNode.property.name;
|
|
947
|
+
}
|
|
948
|
+
return null;
|
|
949
|
+
}
|
|
950
|
+
function resolveMisimportedNamespaceSdkComponent(nameNode, imports, misimportedSdkCanvasImports) {
|
|
951
|
+
if (nameNode?.type !== "JSXMemberExpression" || nameNode.object?.type !== "JSXIdentifier" || nameNode.property?.type !== "JSXIdentifier" || !SDK_COMPONENTS.has(nameNode.property.name)) {
|
|
952
|
+
return null;
|
|
953
|
+
}
|
|
954
|
+
const imported = imports.byLocalName.get(nameNode.object.name);
|
|
955
|
+
if (imported?.kind !== "namespace" || !isWrongTempoSdkCanvasImportSource(imported.source)) {
|
|
956
|
+
return null;
|
|
957
|
+
}
|
|
958
|
+
return misimportedSdkCanvasImports.namespaceCandidatesByLocalName.get(
|
|
959
|
+
nameNode.object.name
|
|
960
|
+
) ?? null;
|
|
961
|
+
}
|
|
962
|
+
function isStoryboardSdkComponent(component) {
|
|
963
|
+
return component === "Storyboard" || component === "SvelteStoryboard" || component === "LegacyStoryboardV1" || component === "RouteStoryboard" || component === "HtmlStoryboard";
|
|
964
|
+
}
|
|
965
|
+
function readImportedName(specifier) {
|
|
966
|
+
if (specifier.type === "ImportDefaultSpecifier") return "default";
|
|
967
|
+
if (specifier.type === "ImportNamespaceSpecifier") return "*";
|
|
968
|
+
return specifier.imported?.name ?? specifier.local?.name ?? "unknown";
|
|
969
|
+
}
|
|
970
|
+
function readImportKind(specifier) {
|
|
971
|
+
if (specifier.type === "ImportDefaultSpecifier") return "default";
|
|
972
|
+
if (specifier.type === "ImportNamespaceSpecifier") return "namespace";
|
|
973
|
+
return "named";
|
|
974
|
+
}
|
|
975
|
+
function isSdkImportSource(source) {
|
|
976
|
+
return SDK_IMPORT_SOURCES.has(source) || source.endsWith("/tempo-sdk/canvas") || source.endsWith("/tempo-sdk/canvas/svelte");
|
|
977
|
+
}
|
|
978
|
+
function isWrongTempoSdkCanvasImportSource(source) {
|
|
979
|
+
return (source === "tempo-sdk" || source.startsWith("tempo-sdk/")) && !isSdkImportSource(source);
|
|
980
|
+
}
|
|
981
|
+
function spanKey(span) {
|
|
982
|
+
return `${span.start}:${span.end}`;
|
|
983
|
+
}
|
|
984
|
+
function readLayoutClose(node) {
|
|
985
|
+
return typeof node?.end === "number" && Number.isFinite(node.end) ? node.end - 1 : void 0;
|
|
986
|
+
}
|
|
987
|
+
function fallbackPageName(filePath) {
|
|
988
|
+
const normalized = filePath.replace(/\\/g, "/");
|
|
989
|
+
const segments = normalized.split("/").filter(Boolean);
|
|
990
|
+
const fileName = segments.length > 0 ? segments[segments.length - 1] : filePath;
|
|
991
|
+
const parentName = segments.length > 1 ? segments[segments.length - 2] : fileName;
|
|
992
|
+
const baseName = /^index\.canvas\.[tj]sx?$/.test(fileName) ? parentName : fileName.replace(/\.canvas\.[tj]sx?$/, "");
|
|
993
|
+
return baseName.split(/[-_\s]+/).filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
|
|
994
|
+
}
|
|
995
|
+
function toSpan(node) {
|
|
996
|
+
return typeof node?.start === "number" && Number.isFinite(node.start) && typeof node?.end === "number" && Number.isFinite(node.end) ? { start: node.start, end: node.end } : void 0;
|
|
997
|
+
}
|
|
998
|
+
function walk(node, visitor, seen = /* @__PURE__ */ new Set()) {
|
|
999
|
+
if (!node || typeof node !== "object" || seen.has(node)) return;
|
|
1000
|
+
seen.add(node);
|
|
1001
|
+
visitor(node);
|
|
1002
|
+
for (const value of Object.values(node)) {
|
|
1003
|
+
if (!value) continue;
|
|
1004
|
+
if (Array.isArray(value)) {
|
|
1005
|
+
for (const item of value) {
|
|
1006
|
+
walk(item, visitor, seen);
|
|
1007
|
+
}
|
|
1008
|
+
} else if (typeof value === "object") {
|
|
1009
|
+
walk(value, visitor, seen);
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
// canvas-component-reference.ts
|
|
1015
|
+
var COMPONENT_REFERENCE_ATTRIBUTE = "data-tempo-component-reference";
|
|
1016
|
+
function moduleIdentity(file, specifier, resolved) {
|
|
1017
|
+
const bundled = resolved?.get(specifier);
|
|
1018
|
+
const target = bundled === void 0 ? specifier : bundled.replace(/\bt=\d{13}&?\b/, "").replace(/[?&]$/, "");
|
|
1019
|
+
if (target.startsWith("\0")) return target;
|
|
1020
|
+
const suffixAt = target.search(/[?#]/);
|
|
1021
|
+
let path = (suffixAt < 0 ? target : target.slice(0, suffixAt)).replace(
|
|
1022
|
+
/\\/g,
|
|
1023
|
+
"/"
|
|
1024
|
+
);
|
|
1025
|
+
const suffix = suffixAt < 0 ? "" : target.slice(suffixAt);
|
|
1026
|
+
if (bundled === void 0 && path.startsWith("."))
|
|
1027
|
+
path = (0, import_node_path.resolve)((0, import_node_path.dirname)(file), path);
|
|
1028
|
+
if (!(0, import_node_path.isAbsolute)(path) && !/^[A-Za-z]:\//.test(path)) return target;
|
|
1029
|
+
if (bundled !== void 0) {
|
|
1030
|
+
try {
|
|
1031
|
+
path = import_node_fs.realpathSync.native(path);
|
|
1032
|
+
} catch {
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
return (0, import_node_path.normalize)(path).replace(/\\/g, "/") + suffix;
|
|
1036
|
+
}
|
|
1037
|
+
function canvasComponentAnnotations(file, source, resolved) {
|
|
1038
|
+
const result = /* @__PURE__ */ new Map();
|
|
1039
|
+
if (!source.includes("tempo-sdk/canvas")) return result;
|
|
1040
|
+
const parsed = parseCanvasFile(file, source);
|
|
1041
|
+
for (const board of parsed.storyboards) {
|
|
1042
|
+
const ref = board.component;
|
|
1043
|
+
if (board.kind !== "component" || !ref?.localName || board.openingElementSpan === void 0)
|
|
1044
|
+
continue;
|
|
1045
|
+
const member = ref.expression.match(
|
|
1046
|
+
/^\s*([$\w]+)(?:\s*\.\s*([$\w]+))?\s*$/
|
|
1047
|
+
);
|
|
1048
|
+
if (!member) continue;
|
|
1049
|
+
let name;
|
|
1050
|
+
if (ref.import) {
|
|
1051
|
+
if (ref.import.kind === "namespace") {
|
|
1052
|
+
if (!member[2]) continue;
|
|
1053
|
+
name = member[2];
|
|
1054
|
+
} else {
|
|
1055
|
+
if (member[2]) continue;
|
|
1056
|
+
name = ref.import.importedName;
|
|
1057
|
+
}
|
|
1058
|
+
} else {
|
|
1059
|
+
if (member[2]) continue;
|
|
1060
|
+
name = ref.localName;
|
|
1061
|
+
}
|
|
1062
|
+
const specifier = ref.import?.source.replace(/\\/g, "/").replace(/[?#].*/, "");
|
|
1063
|
+
const canvasDir = import_node_path.posix.dirname(file.replace(/\\/g, "/"));
|
|
1064
|
+
const external = specifier !== void 0 && (!specifier.startsWith(".") || !import_node_path.posix.join(canvasDir, specifier).startsWith(`${canvasDir}/`));
|
|
1065
|
+
result.set(board.openingElementSpan.start, {
|
|
1066
|
+
[COMPONENT_REFERENCE_ATTRIBUTE]: JSON.stringify([
|
|
1067
|
+
ref.import ? "import" : "local",
|
|
1068
|
+
moduleIdentity(file, ref.import?.source ?? file, resolved),
|
|
1069
|
+
name
|
|
1070
|
+
]),
|
|
1071
|
+
...external ? { "data-tempo-external-component": "true" } : {}
|
|
1072
|
+
});
|
|
1073
|
+
}
|
|
1074
|
+
return result;
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
// expo-babel-plugin.ts
|
|
1078
|
+
var import_node_fs4 = require("fs");
|
|
1079
|
+
var import_node_path4 = require("path");
|
|
1080
|
+
var import_pluginutils = require("@rollup/pluginutils");
|
|
1081
|
+
|
|
1082
|
+
// annotation-strategy.ts
|
|
1083
|
+
var import_node_fs2 = require("fs");
|
|
1084
|
+
var import_node_path2 = require("path");
|
|
1085
|
+
|
|
1086
|
+
// ../../modules/annotation/expression-facts.ts
|
|
1087
|
+
var EXPRESSION_FACTS_ATTRIBUTE = "data-tempo-expr";
|
|
1088
|
+
var DYNAMIC_SLOT_FACT = "#slot";
|
|
1089
|
+
function expressionFacts(element, parentType) {
|
|
1090
|
+
const opening = element.openingElement;
|
|
1091
|
+
const attributes = opening.attributes;
|
|
1092
|
+
const facts = [];
|
|
1093
|
+
if (parentType !== "JSXElement" && parentType !== "JSXFragment")
|
|
1094
|
+
facts.push(DYNAMIC_SLOT_FACT);
|
|
1095
|
+
const last = /* @__PURE__ */ new Map();
|
|
1096
|
+
attributes.forEach((attribute, index) => {
|
|
1097
|
+
const name = attributeName(attribute);
|
|
1098
|
+
if (name !== null) last.set(name, index);
|
|
1099
|
+
});
|
|
1100
|
+
let lastSpread = -1;
|
|
1101
|
+
attributes.forEach((attribute, index) => {
|
|
1102
|
+
if (attribute.type === "JSXSpreadAttribute") lastSpread = index;
|
|
1103
|
+
});
|
|
1104
|
+
for (const [name, index] of last) {
|
|
1105
|
+
if (unstamped(name)) continue;
|
|
1106
|
+
const overridden = index < lastSpread;
|
|
1107
|
+
const value = attributes[index].value;
|
|
1108
|
+
if (value === null) continue;
|
|
1109
|
+
if (name === "style" && !overridden) {
|
|
1110
|
+
facts.push(...styleFacts(value));
|
|
1111
|
+
continue;
|
|
1112
|
+
}
|
|
1113
|
+
if (overridden || !isLiteralValue(value)) facts.push(name);
|
|
1114
|
+
}
|
|
1115
|
+
if (facts.length > 0) return facts.join(" ");
|
|
1116
|
+
return lastSpread >= 0 ? "" : void 0;
|
|
1117
|
+
}
|
|
1118
|
+
function attributeName(attribute) {
|
|
1119
|
+
if (attribute.type !== "JSXAttribute") return null;
|
|
1120
|
+
const name = attribute.name;
|
|
1121
|
+
if (name.type === "JSXIdentifier") return name.name;
|
|
1122
|
+
if (name.type === "JSXNamespacedName") {
|
|
1123
|
+
const namespace = name.namespace.name;
|
|
1124
|
+
return `${namespace}:${name.name.name}`;
|
|
1125
|
+
}
|
|
1126
|
+
return null;
|
|
1127
|
+
}
|
|
1128
|
+
function unstamped(name) {
|
|
1129
|
+
return name === "key" || name.startsWith("data-tempo-");
|
|
1130
|
+
}
|
|
1131
|
+
function styleFacts(value) {
|
|
1132
|
+
const expression = value.type === "JSXExpressionContainer" ? unwrap(value.expression) : value;
|
|
1133
|
+
if (expression.type !== "ObjectExpression") return ["style"];
|
|
1134
|
+
const properties = expression.properties;
|
|
1135
|
+
const last = /* @__PURE__ */ new Map();
|
|
1136
|
+
properties.forEach((property, index) => {
|
|
1137
|
+
const key = styleKey(property);
|
|
1138
|
+
if (key !== null) last.set(key, index);
|
|
1139
|
+
});
|
|
1140
|
+
const facts = [];
|
|
1141
|
+
for (const [key, index] of last) {
|
|
1142
|
+
const property = properties[index];
|
|
1143
|
+
const overridden = properties.slice(index + 1).some((later) => later.type === "SpreadElement" || later.computed);
|
|
1144
|
+
const literal = property.type !== "ObjectMethod" && !property.shorthand && isLiteral(property.value);
|
|
1145
|
+
if (overridden || !literal) facts.push(`style.${key}`);
|
|
1146
|
+
}
|
|
1147
|
+
return facts;
|
|
1148
|
+
}
|
|
1149
|
+
function styleKey(property) {
|
|
1150
|
+
const isProperty = property.type === "Property" || property.type === "ObjectProperty" || property.type === "ObjectMethod";
|
|
1151
|
+
if (!isProperty || property.computed) return null;
|
|
1152
|
+
const key = property.key;
|
|
1153
|
+
if (key.type === "Identifier") return key.name;
|
|
1154
|
+
const isString = (key.type === "Literal" || key.type === "StringLiteral") && typeof key.value === "string";
|
|
1155
|
+
return isString ? key.value : null;
|
|
1156
|
+
}
|
|
1157
|
+
function isLiteralValue(value) {
|
|
1158
|
+
if (value.type === "Literal" || value.type === "StringLiteral") return true;
|
|
1159
|
+
if (value.type !== "JSXExpressionContainer") return false;
|
|
1160
|
+
return isLiteral(value.expression);
|
|
1161
|
+
}
|
|
1162
|
+
function isLiteral(node) {
|
|
1163
|
+
const current = unwrap(node);
|
|
1164
|
+
if (current.type === "UnaryExpression") {
|
|
1165
|
+
const signed = current.operator === "-" || current.operator === "+";
|
|
1166
|
+
return signed && isNumber(current.argument);
|
|
1167
|
+
}
|
|
1168
|
+
if (isNumber(current)) return true;
|
|
1169
|
+
if (current.type === "StringLiteral" || current.type === "BooleanLiteral")
|
|
1170
|
+
return true;
|
|
1171
|
+
const value = current.value;
|
|
1172
|
+
return current.type === "Literal" && (typeof value === "string" || typeof value === "boolean");
|
|
1173
|
+
}
|
|
1174
|
+
function isNumber(node) {
|
|
1175
|
+
const numeric = node.type === "Literal" || node.type === "NumericLiteral";
|
|
1176
|
+
return numeric && typeof node.value === "number" && Number.isFinite(node.value);
|
|
1177
|
+
}
|
|
1178
|
+
function unwrap(node) {
|
|
1179
|
+
let current = node;
|
|
1180
|
+
while (current.type === "ParenthesizedExpression")
|
|
1181
|
+
current = current.expression;
|
|
1182
|
+
return current;
|
|
1183
|
+
}
|
|
1184
|
+
|
|
35
1185
|
// ../../modules/annotation/source-version.ts
|
|
36
1186
|
function sourceVersionHash(content) {
|
|
37
1187
|
let djb2 = 5381;
|
|
@@ -70,7 +1220,7 @@ function cleanModuleId(id) {
|
|
|
70
1220
|
}
|
|
71
1221
|
function resolveCanonicalRoot(root) {
|
|
72
1222
|
try {
|
|
73
|
-
return
|
|
1223
|
+
return import_node_fs2.realpathSync.native(root);
|
|
74
1224
|
} catch {
|
|
75
1225
|
return root;
|
|
76
1226
|
}
|
|
@@ -105,7 +1255,22 @@ function computeTempoAnnotatedProps(params) {
|
|
|
105
1255
|
computeAnnotatedProps,
|
|
106
1256
|
elementSupportOverrides
|
|
107
1257
|
} = params;
|
|
108
|
-
const userProps =
|
|
1258
|
+
const userProps = {
|
|
1259
|
+
...computeAnnotatedProps ? computeAnnotatedProps(info, filepath, modifiedtsMs, sourceVersion) : defaultComputeAnnotatedProps(
|
|
1260
|
+
info,
|
|
1261
|
+
filepath,
|
|
1262
|
+
modifiedtsMs,
|
|
1263
|
+
sourceVersion
|
|
1264
|
+
),
|
|
1265
|
+
// Only a caller that knows the parent can say whether the slot is a JSX
|
|
1266
|
+
// child; without it every element would read as a dynamic slot.
|
|
1267
|
+
...info.parentType !== void 0 && !hasJsxAttribute(info, EXPRESSION_FACTS_ATTRIBUTE) ? {
|
|
1268
|
+
[EXPRESSION_FACTS_ATTRIBUTE]: expressionFacts(
|
|
1269
|
+
info.element,
|
|
1270
|
+
info.parentType
|
|
1271
|
+
)
|
|
1272
|
+
} : {}
|
|
1273
|
+
};
|
|
109
1274
|
if (isIntrinsicElement(info.tagName)) {
|
|
110
1275
|
return {
|
|
111
1276
|
...userProps,
|
|
@@ -132,21 +1297,78 @@ function getFileAnnotationContext(params) {
|
|
|
132
1297
|
let cleanFilename = rawCleanFilename;
|
|
133
1298
|
if (params.canonicalizeFilename) {
|
|
134
1299
|
try {
|
|
135
|
-
cleanFilename =
|
|
1300
|
+
cleanFilename = import_node_fs2.realpathSync.native(rawCleanFilename);
|
|
136
1301
|
} catch {
|
|
137
1302
|
cleanFilename = rawCleanFilename;
|
|
138
1303
|
}
|
|
139
1304
|
}
|
|
140
1305
|
return {
|
|
141
1306
|
cleanFilename,
|
|
142
|
-
filepath: (0,
|
|
143
|
-
modifiedtsMs: Math.trunc((0,
|
|
1307
|
+
filepath: (0, import_node_path2.relative)(params.root, cleanFilename),
|
|
1308
|
+
modifiedtsMs: Math.trunc((0, import_node_fs2.statSync)(cleanFilename).mtimeMs),
|
|
144
1309
|
// Hashed once per file per transform (the context is built once, reused
|
|
145
1310
|
// for every element) so the per-element funnel just forwards the token.
|
|
146
1311
|
sourceVersion: sourceVersionHash(params.source)
|
|
147
1312
|
};
|
|
148
1313
|
}
|
|
149
1314
|
|
|
1315
|
+
// sdk-package-files.ts
|
|
1316
|
+
var import_node_fs3 = require("fs");
|
|
1317
|
+
var import_node_path3 = require("path");
|
|
1318
|
+
var SDK_PACKAGE_NAME = "tempo-sdk";
|
|
1319
|
+
var SDK_NODE_MODULES_SEGMENT = `/node_modules/${SDK_PACKAGE_NAME}/`;
|
|
1320
|
+
function createSdkFileMatcher() {
|
|
1321
|
+
const ownerIsSdkByDirectory = /* @__PURE__ */ new Map();
|
|
1322
|
+
const nearestPackageIsSdk = (startDirectory) => {
|
|
1323
|
+
const visited = [];
|
|
1324
|
+
let directory = startDirectory;
|
|
1325
|
+
let isSdk = false;
|
|
1326
|
+
while (true) {
|
|
1327
|
+
const cached = ownerIsSdkByDirectory.get(directory);
|
|
1328
|
+
if (cached !== void 0) {
|
|
1329
|
+
isSdk = cached;
|
|
1330
|
+
break;
|
|
1331
|
+
}
|
|
1332
|
+
visited.push(directory);
|
|
1333
|
+
const manifest = readPackageManifest(directory);
|
|
1334
|
+
if (manifest !== void 0) {
|
|
1335
|
+
isSdk = manifest?.name === SDK_PACKAGE_NAME;
|
|
1336
|
+
break;
|
|
1337
|
+
}
|
|
1338
|
+
const parent = (0, import_node_path3.dirname)(directory);
|
|
1339
|
+
if (parent === directory) break;
|
|
1340
|
+
directory = parent;
|
|
1341
|
+
}
|
|
1342
|
+
for (const entry of visited) ownerIsSdkByDirectory.set(entry, isSdk);
|
|
1343
|
+
return isSdk;
|
|
1344
|
+
};
|
|
1345
|
+
return (file) => {
|
|
1346
|
+
if (file.replace(/\\/g, "/").includes(SDK_NODE_MODULES_SEGMENT)) {
|
|
1347
|
+
return true;
|
|
1348
|
+
}
|
|
1349
|
+
let realFile = file;
|
|
1350
|
+
try {
|
|
1351
|
+
realFile = import_node_fs3.realpathSync.native(file);
|
|
1352
|
+
} catch {
|
|
1353
|
+
}
|
|
1354
|
+
return nearestPackageIsSdk((0, import_node_path3.dirname)(realFile));
|
|
1355
|
+
};
|
|
1356
|
+
}
|
|
1357
|
+
function readPackageManifest(directory) {
|
|
1358
|
+
let text;
|
|
1359
|
+
try {
|
|
1360
|
+
text = (0, import_node_fs3.readFileSync)((0, import_node_path3.join)(directory, "package.json"), "utf8");
|
|
1361
|
+
} catch {
|
|
1362
|
+
return void 0;
|
|
1363
|
+
}
|
|
1364
|
+
try {
|
|
1365
|
+
const manifest = JSON.parse(text);
|
|
1366
|
+
return manifest && typeof manifest === "object" ? manifest : null;
|
|
1367
|
+
} catch {
|
|
1368
|
+
return null;
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
|
|
150
1372
|
// expo-babel-plugin.ts
|
|
151
1373
|
var EXPO_DEFAULT_INCLUDE = ["**/*.tsx", "**/*.jsx", "**/*.js"];
|
|
152
1374
|
var FRAGMENT_TAG_NAMES = /* @__PURE__ */ new Set(["Fragment", "React.Fragment"]);
|
|
@@ -278,16 +1500,16 @@ function injectProjectRootMeta(api, programPath, root) {
|
|
|
278
1500
|
}
|
|
279
1501
|
function resolveBabelRoot(state, options, filename) {
|
|
280
1502
|
return resolveCanonicalRoot(
|
|
281
|
-
(0,
|
|
1503
|
+
(0, import_node_path4.resolve)(
|
|
282
1504
|
options.root ?? findNearestPackageRoot(filename) ?? state.cwd ?? state.file.opts.cwd ?? state.file.opts.root ?? process.cwd()
|
|
283
1505
|
)
|
|
284
1506
|
);
|
|
285
1507
|
}
|
|
286
1508
|
function findNearestPackageRoot(filename) {
|
|
287
|
-
let current = (0,
|
|
1509
|
+
let current = (0, import_node_path4.dirname)(filename);
|
|
288
1510
|
while (true) {
|
|
289
|
-
if ((0,
|
|
290
|
-
const parent = (0,
|
|
1511
|
+
if ((0, import_node_fs4.existsSync)((0, import_node_path4.resolve)(current, "package.json"))) return current;
|
|
1512
|
+
const parent = (0, import_node_path4.dirname)(current);
|
|
291
1513
|
if (parent === current) return null;
|
|
292
1514
|
current = parent;
|
|
293
1515
|
}
|
|
@@ -295,14 +1517,16 @@ function findNearestPackageRoot(filename) {
|
|
|
295
1517
|
function resolveFilename(state) {
|
|
296
1518
|
const filename = state.filename ?? state.file.opts.filename;
|
|
297
1519
|
if (!filename) return null;
|
|
298
|
-
return (0,
|
|
1520
|
+
return (0, import_node_path4.resolve)(cleanModuleId(filename));
|
|
299
1521
|
}
|
|
300
1522
|
function tempoExpoBabelPlugin(api, rawOptions = {}) {
|
|
301
1523
|
api.assertVersion(7);
|
|
302
1524
|
const enabled = rawOptions.enabled ?? !!process.env.TEMPO;
|
|
303
1525
|
const include = rawOptions.include === void 0 ? EXPO_DEFAULT_INCLUDE : rawOptions.include;
|
|
304
1526
|
const exclude = rawOptions.exclude === void 0 ? DEFAULT_EXCLUDE : rawOptions.exclude;
|
|
305
|
-
const
|
|
1527
|
+
const userFilter = (0, import_pluginutils.createFilter)(include, exclude);
|
|
1528
|
+
const isSdkFile = createSdkFileMatcher();
|
|
1529
|
+
const filter = (id) => userFilter(id) && !isSdkFile(id);
|
|
306
1530
|
return {
|
|
307
1531
|
name: "tempo-expo-annotate",
|
|
308
1532
|
manipulateOptions(opts, parserOpts) {
|
|
@@ -338,6 +1562,10 @@ function tempoExpoBabelPlugin(api, rawOptions = {}) {
|
|
|
338
1562
|
if (context.filepath === "index.js") {
|
|
339
1563
|
injectProjectRootMeta(api, path, root);
|
|
340
1564
|
}
|
|
1565
|
+
const componentReferences = canvasComponentAnnotations(
|
|
1566
|
+
filename,
|
|
1567
|
+
source
|
|
1568
|
+
);
|
|
341
1569
|
path.traverse({
|
|
342
1570
|
JSXElement(elementPath) {
|
|
343
1571
|
const element = elementPath.node;
|
|
@@ -345,7 +1573,8 @@ function tempoExpoBabelPlugin(api, rawOptions = {}) {
|
|
|
345
1573
|
if (FRAGMENT_TAG_NAMES.has(tagName)) return;
|
|
346
1574
|
const info = {
|
|
347
1575
|
element,
|
|
348
|
-
tagName
|
|
1576
|
+
tagName,
|
|
1577
|
+
parentType: elementPath.parent.type
|
|
349
1578
|
};
|
|
350
1579
|
const props = computeTempoAnnotatedProps({
|
|
351
1580
|
info,
|
|
@@ -356,6 +1585,19 @@ function tempoExpoBabelPlugin(api, rawOptions = {}) {
|
|
|
356
1585
|
elementSupportOverrides: REACT_NATIVE_SUPPORT_OVERRIDES
|
|
357
1586
|
});
|
|
358
1587
|
addAnnotations(api, tagName, element.openingElement, props);
|
|
1588
|
+
const annotations = componentReferences.get(
|
|
1589
|
+
element.openingElement.start ?? -1
|
|
1590
|
+
);
|
|
1591
|
+
for (const [name, value] of Object.entries(annotations ?? {})) {
|
|
1592
|
+
element.openingElement.attributes.push(
|
|
1593
|
+
api.types.jsxAttribute(
|
|
1594
|
+
api.types.jsxIdentifier(name),
|
|
1595
|
+
api.types.jsxExpressionContainer(
|
|
1596
|
+
api.types.stringLiteral(value)
|
|
1597
|
+
)
|
|
1598
|
+
)
|
|
1599
|
+
);
|
|
1600
|
+
}
|
|
359
1601
|
}
|
|
360
1602
|
});
|
|
361
1603
|
}
|