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