tempo-sdk 0.0.52 → 0.0.60

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.
Files changed (75) hide show
  1. package/dist/assets/index.js +4 -2
  2. package/dist/assets/index.js.map +1 -1
  3. package/dist/canvas/editor.d.ts +11 -16
  4. package/dist/canvas/editor.js +79 -49
  5. package/dist/canvas/editor.js.map +1 -1
  6. package/dist/canvas/index.d.ts +13 -7
  7. package/dist/canvas/index.js +227 -64
  8. package/dist/canvas/index.js.map +1 -1
  9. package/dist/canvas/interact-projection.js +4 -3
  10. package/dist/canvas/parser.d.ts +10 -5
  11. package/dist/canvas/parser.js +3 -1
  12. package/dist/canvas/svelte.d.ts +8 -5
  13. package/dist/canvas/svelte.js +20 -5
  14. package/dist/canvas/svelte.js.map +1 -1
  15. package/dist/chunk-2IQD2KPS.js +219 -0
  16. package/dist/chunk-2IQD2KPS.js.map +1 -0
  17. package/dist/chunk-5BHIHP25.js +410 -0
  18. package/dist/chunk-5BHIHP25.js.map +1 -0
  19. package/dist/{chunk-PULSTDX2.js → chunk-7DT5DDSH.js} +284 -46
  20. package/dist/chunk-7DT5DDSH.js.map +1 -0
  21. package/dist/{chunk-7Y7XNHUM.js → chunk-FQSZRVSL.js} +18 -3
  22. package/dist/chunk-FQSZRVSL.js.map +1 -0
  23. package/dist/{chunk-ZZYNOX24.js → chunk-MXKZZOLM.js} +1717 -2460
  24. package/dist/chunk-MXKZZOLM.js.map +1 -0
  25. package/dist/{chunk-DX6XAXCK.js → chunk-N2TYN3RB.js} +189 -420
  26. package/dist/chunk-N2TYN3RB.js.map +1 -0
  27. package/dist/chunk-OTVBSF7U.js +1585 -0
  28. package/dist/chunk-OTVBSF7U.js.map +1 -0
  29. package/dist/chunk-TL4MGN7E.js +2570 -0
  30. package/dist/chunk-TL4MGN7E.js.map +1 -0
  31. package/dist/{chunk-QP2NTODB.js → chunk-VMTQDG4U.js} +117 -27
  32. package/dist/chunk-VMTQDG4U.js.map +1 -0
  33. package/dist/expo/plugin.cjs +1256 -16
  34. package/dist/expo/plugin.cjs.map +1 -1
  35. package/dist/expo/plugin.d.cts +0 -1
  36. package/dist/expo/plugin.d.ts +0 -1
  37. package/dist/expo/plugin.js +1 -1
  38. package/dist/expo-babel-plugin.cjs +1258 -16
  39. package/dist/expo-babel-plugin.cjs.map +1 -1
  40. package/dist/expo-babel-plugin.d.cts +8 -5
  41. package/dist/expo-babel-plugin.d.ts +8 -5
  42. package/dist/expo-babel-plugin.js +1 -1
  43. package/dist/index.d.ts +5 -1
  44. package/dist/index.js +647 -166
  45. package/dist/index.js.map +1 -1
  46. package/dist/nextjs/plugin.cjs +151 -0
  47. package/dist/nextjs/plugin.cjs.map +1 -1
  48. package/dist/nextjs/plugin.d.cts +1 -1
  49. package/dist/nextjs/plugin.d.ts +1 -1
  50. package/dist/nextjs/plugin.js +1 -1
  51. package/dist/nextjs-loader.cjs +1432 -35
  52. package/dist/nextjs-loader.cjs.map +1 -1
  53. package/dist/nextjs.cjs +17 -2
  54. package/dist/nextjs.cjs.map +1 -1
  55. package/dist/nextjs.d.cts +14 -3
  56. package/dist/nextjs.d.ts +14 -3
  57. package/dist/nextjs.js +1 -1
  58. package/dist/{page-xi1aI5a7.d.ts → page-DwLnOM5d.d.ts} +12 -6
  59. package/dist/{storyboard-DbtzTPvI.d.ts → storyboard-DjOF61B_.d.ts} +35 -15
  60. package/dist/svelte.d.ts +3 -2
  61. package/dist/svelte.js +103 -29
  62. package/dist/svelte.js.map +1 -1
  63. package/dist/v1-client-compat-qxaXEDm_.d.ts +23 -0
  64. package/package.json +5 -2
  65. package/dist/chunk-57KAYXHF.js +0 -19
  66. package/dist/chunk-57KAYXHF.js.map +0 -1
  67. package/dist/chunk-7Y7XNHUM.js.map +0 -1
  68. package/dist/chunk-CB5NJJJT.js +0 -345
  69. package/dist/chunk-CB5NJJJT.js.map +0 -1
  70. package/dist/chunk-DX6XAXCK.js.map +0 -1
  71. package/dist/chunk-F3KJDCMU.js +0 -19
  72. package/dist/chunk-F3KJDCMU.js.map +0 -1
  73. package/dist/chunk-PULSTDX2.js.map +0 -1
  74. package/dist/chunk-QP2NTODB.js.map +0 -1
  75. package/dist/chunk-ZZYNOX24.js.map +0 -1
@@ -37,12 +37,1063 @@ __export(nextjs_loader_exports, {
37
37
  nextjsLoader: () => nextjsLoader
38
38
  });
39
39
  module.exports = __toCommonJS(nextjs_loader_exports);
40
- var import_node_fs3 = require("fs");
40
+
41
+ // canvas-component-reference.ts
42
+ var import_node_fs = require("fs");
43
+ var import_node_path = require("path");
44
+
45
+ // canvas/parser.ts
46
+ var import_oxc_parser = require("oxc-parser");
47
+ var SDK_IMPORT_SOURCES = /* @__PURE__ */ new Set([
48
+ "tempo-sdk/canvas",
49
+ "tempo-sdk/canvas/svelte"
50
+ ]);
51
+ var SDK_COMPONENTS = /* @__PURE__ */ new Set([
52
+ "Canvas",
53
+ "Storyboard",
54
+ "SvelteStoryboard",
55
+ "LegacyStoryboardV1",
56
+ "RouteStoryboard",
57
+ "HtmlStoryboard"
58
+ ]);
59
+ var SDK_CANVAS_VALUE_EXPORTS = /* @__PURE__ */ new Set([
60
+ "Canvas",
61
+ "CanvasContext",
62
+ "getCanvasStoryboardRenderId",
63
+ "CanvasHost",
64
+ "buildRenderContentFiberSelector",
65
+ "buildRenderContentSelector",
66
+ "buildRenderSelector",
67
+ "captureStoryboardCombined",
68
+ "captureStoryboardHtml",
69
+ "captureStoryboardImage",
70
+ "stripRenderContentWrapperAttributes",
71
+ "stripRenderContentWrapperFromCombinedCapture",
72
+ "watchStoryboardCombined",
73
+ "getCanvasHostRuntime",
74
+ "getOptionalCanvasHostRuntime",
75
+ "useActiveState",
76
+ "HtmlStoryboard",
77
+ "LegacyStoryboardV1",
78
+ "RouteStoryboard",
79
+ "Storyboard",
80
+ "StoryboardSlot"
81
+ ]);
82
+ var DEFAULT_LAYOUT = {
83
+ x: 0,
84
+ y: 0
85
+ };
86
+ var DEFAULT_VIEWPORT_LAYOUT = {
87
+ ...DEFAULT_LAYOUT,
88
+ width: 600,
89
+ height: 400
90
+ };
91
+ var NO_CANVAS_DECLARATION_ERROR = "No <Canvas> declaration found in canvas file";
92
+ function parseCanvasFile(filePath, source) {
93
+ const errors = [];
94
+ let program;
95
+ try {
96
+ const result = (0, import_oxc_parser.parseSync)(filePath, source);
97
+ program = result.program;
98
+ for (const error of result.errors ?? []) {
99
+ errors.push({
100
+ message: error.message ?? "Unable to parse canvas source",
101
+ span: toSpan(error) ?? toSpan(error?.labels?.[0]),
102
+ kind: "structural"
103
+ });
104
+ }
105
+ } catch (error) {
106
+ return {
107
+ filePath,
108
+ pageName: fallbackPageName(filePath),
109
+ imports: [],
110
+ misimportedSdkCanvasImports: [],
111
+ storyboards: [],
112
+ errors: [
113
+ {
114
+ message: error instanceof Error ? error.message : "Unable to parse canvas source",
115
+ kind: "structural"
116
+ }
117
+ ]
118
+ };
119
+ }
120
+ const imports = readImports(program);
121
+ const misimportedSdkCanvasImports = readMisimportedSdkCanvasImports(program);
122
+ const { legacyObjects, stringBindings: objectStringBindings } = readObjectExpressionBindings(program, imports, source);
123
+ let canvasElement = null;
124
+ const allStoryboardElements = [];
125
+ walk(program, (node) => {
126
+ if (node.type !== "JSXElement") return;
127
+ const component = resolveSdkComponent(node.openingElement?.name, imports);
128
+ const namespaceMisimport = resolveMisimportedNamespaceSdkComponent(
129
+ node.openingElement?.name,
130
+ imports,
131
+ misimportedSdkCanvasImports
132
+ );
133
+ if (namespaceMisimport) {
134
+ misimportedSdkCanvasImports.add(namespaceMisimport);
135
+ }
136
+ if (component === "Canvas") {
137
+ if (!canvasElement) {
138
+ canvasElement = node;
139
+ } else {
140
+ errors.push({
141
+ message: "Canvas file must declare exactly one <Canvas> element",
142
+ span: toSpan(node),
143
+ kind: "structural"
144
+ });
145
+ }
146
+ return;
147
+ }
148
+ if (isStoryboardSdkComponent(component)) {
149
+ allStoryboardElements.push({ element: node, component });
150
+ }
151
+ });
152
+ const directStoryboardElements = canvasElement ? readDirectCanvasStoryboardElements(canvasElement, imports) : [];
153
+ const directStoryboardElementSet = new Set(
154
+ directStoryboardElements.map((item) => item.element)
155
+ );
156
+ const storyboards = directStoryboardElements.map(
157
+ (item) => readStoryboard(
158
+ item.element,
159
+ item.component,
160
+ imports,
161
+ legacyObjects,
162
+ source,
163
+ errors
164
+ )
165
+ );
166
+ for (const item of allStoryboardElements) {
167
+ if (directStoryboardElementSet.has(item.element)) continue;
168
+ errors.push({
169
+ message: `<${item.component}> declarations must be direct children of the <Canvas> element`,
170
+ span: toSpan(item.element),
171
+ kind: "structural"
172
+ });
173
+ }
174
+ reportDuplicateStoryboardIds(storyboards, errors);
175
+ if (!canvasElement) {
176
+ if (misimportedSdkCanvasImports.all.length > 0) {
177
+ for (const entry of misimportedSdkCanvasImports.all) {
178
+ errors.push({
179
+ message: misimportedSdkCanvasImportMessage(entry),
180
+ span: entry.sourceSpan,
181
+ kind: "structural"
182
+ });
183
+ }
184
+ } else {
185
+ errors.push({
186
+ message: NO_CANVAS_DECLARATION_ERROR,
187
+ kind: "structural"
188
+ });
189
+ }
190
+ } else {
191
+ errors.push(...validateCanvasChildren(canvasElement, imports));
192
+ }
193
+ const openingElement = canvasElement?.openingElement;
194
+ const name = readResolvableStringAttribute(
195
+ openingElement,
196
+ "name",
197
+ objectStringBindings
198
+ );
199
+ const path = readStringAttribute(openingElement, "path");
200
+ const backgroundColor = readResolvableStringAttribute(
201
+ openingElement,
202
+ "backgroundColor",
203
+ objectStringBindings
204
+ ) ?? readResolvableStringAttribute(
205
+ openingElement,
206
+ "background",
207
+ objectStringBindings
208
+ );
209
+ if (openingElement && !name) {
210
+ errors.push({
211
+ message: '<Canvas> must include a literal "name" prop',
212
+ span: toSpan(openingElement),
213
+ kind: "degraded"
214
+ });
215
+ }
216
+ return {
217
+ filePath,
218
+ canvasPath: path?.value,
219
+ pageName: name?.value ?? fallbackPageName(filePath),
220
+ backgroundColor: backgroundColor?.value,
221
+ canvasElementSpan: toSpan(canvasElement),
222
+ canvasOpeningElementSpan: toSpan(openingElement),
223
+ canvasChildrenInsertionOffset: typeof canvasElement?.closingElement?.start === "number" ? canvasElement.closingElement.start : void 0,
224
+ nameSpan: name?.valueSpan,
225
+ nameAttributeSpan: name?.attributeSpan,
226
+ pathSpan: path?.valueSpan,
227
+ pathAttributeSpan: path?.attributeSpan,
228
+ backgroundColorSpan: backgroundColor?.valueSpan,
229
+ backgroundColorAttributeSpan: backgroundColor?.attributeSpan,
230
+ imports: imports.all,
231
+ misimportedSdkCanvasImports: misimportedSdkCanvasImports.all,
232
+ storyboards,
233
+ errors
234
+ };
235
+ }
236
+ function misimportedSdkCanvasImportMessage(entry) {
237
+ return `Tempo canvas components must be imported from "tempo-sdk/canvas" \u2014 found import of ${entry.importedNames.join(", ")} from "${entry.source}"`;
238
+ }
239
+ function readMisimportedSdkCanvasImports(program) {
240
+ const all = [];
241
+ const byDeclarationKey = /* @__PURE__ */ new Map();
242
+ const namespaceCandidatesByLocalName = /* @__PURE__ */ new Map();
243
+ const add = (entry) => {
244
+ const key = spanKey(entry.sourceSpan);
245
+ if (byDeclarationKey.has(key)) return;
246
+ byDeclarationKey.set(key, entry);
247
+ all.push(entry);
248
+ };
249
+ for (const statement of program?.body ?? []) {
250
+ if (statement?.type !== "ImportDeclaration" || typeof statement.source?.value !== "string" || !isWrongTempoSdkCanvasImportSource(statement.source.value) || statement.importKind === "type") {
251
+ continue;
252
+ }
253
+ const source = statement.source.value;
254
+ const sourceSpan = toSpan(statement.source);
255
+ if (!sourceSpan) continue;
256
+ const valueSpecifiers = (statement.specifiers ?? []).filter(
257
+ (specifier) => specifier?.importKind !== "type"
258
+ );
259
+ const importedNames = valueSpecifiers.map(readImportedName);
260
+ const entry = {
261
+ source,
262
+ sourceSpan,
263
+ importedNames,
264
+ rewritable: valueSpecifiers.length > 0 && valueSpecifiers.every(
265
+ (specifier) => specifier?.type === "ImportSpecifier" && SDK_CANVAS_VALUE_EXPORTS.has(readImportedName(specifier))
266
+ )
267
+ };
268
+ const hasMisimportedNamedSdkComponent = valueSpecifiers.some(
269
+ (specifier) => specifier?.type === "ImportSpecifier" && SDK_COMPONENTS.has(readImportedName(specifier))
270
+ );
271
+ if (hasMisimportedNamedSdkComponent) {
272
+ add(entry);
273
+ }
274
+ for (const specifier of valueSpecifiers) {
275
+ if (specifier?.type !== "ImportNamespaceSpecifier") continue;
276
+ const localName = specifier.local?.name;
277
+ if (typeof localName === "string") {
278
+ namespaceCandidatesByLocalName.set(localName, entry);
279
+ }
280
+ }
281
+ }
282
+ return { all, byDeclarationKey, namespaceCandidatesByLocalName, add };
283
+ }
284
+ function readImports(program) {
285
+ const all = [];
286
+ const byLocalName = /* @__PURE__ */ new Map();
287
+ const sdkLocalNames = /* @__PURE__ */ new Map();
288
+ const sdkNamespaces = /* @__PURE__ */ new Set();
289
+ for (const statement of program?.body ?? []) {
290
+ if (statement?.type !== "ImportDeclaration" || typeof statement.source?.value !== "string") {
291
+ continue;
292
+ }
293
+ const source = statement.source.value;
294
+ const isSdkImport = isSdkImportSource(source);
295
+ for (const specifier of statement.specifiers ?? []) {
296
+ const localName = specifier.local?.name;
297
+ if (typeof localName !== "string") continue;
298
+ const importedName = readImportedName(specifier);
299
+ const imported = {
300
+ localName,
301
+ source,
302
+ importedName,
303
+ kind: readImportKind(specifier),
304
+ importKind: specifier.importKind === "type" ? "type" : "value",
305
+ span: toSpan(specifier) ?? toSpan(statement) ?? { start: 0, end: 0 },
306
+ declarationSpan: toSpan(statement) ?? { start: 0, end: 0 },
307
+ specifierCount: statement.specifiers?.length ?? 0,
308
+ namedSpecifierCount: (statement.specifiers ?? []).filter(
309
+ (item) => item?.type === "ImportSpecifier"
310
+ ).length,
311
+ hasDefaultSpecifier: (statement.specifiers ?? []).some(
312
+ (item) => item?.type === "ImportDefaultSpecifier"
313
+ ),
314
+ hasNamespaceSpecifier: (statement.specifiers ?? []).some(
315
+ (item) => item?.type === "ImportNamespaceSpecifier"
316
+ )
317
+ };
318
+ all.push(imported);
319
+ byLocalName.set(localName, imported);
320
+ if (!isSdkImport) continue;
321
+ if (specifier.type === "ImportNamespaceSpecifier") {
322
+ sdkNamespaces.add(localName);
323
+ continue;
324
+ }
325
+ if (SDK_COMPONENTS.has(importedName)) {
326
+ sdkLocalNames.set(localName, importedName);
327
+ }
328
+ }
329
+ }
330
+ return { all, byLocalName, sdkLocalNames, sdkNamespaces };
331
+ }
332
+ function readObjectExpressionBindings(program, imports, source) {
333
+ const legacyObjects = /* @__PURE__ */ new Map();
334
+ const stringBindings = /* @__PURE__ */ new Map();
335
+ for (const node of readTopLevelVariableDeclarators(program)) {
336
+ if (node.id?.type !== "Identifier") {
337
+ continue;
338
+ }
339
+ const objectExpression = unwrapTsExpression(node.init);
340
+ if (objectExpression?.type !== "ObjectExpression") continue;
341
+ const bindingName = node.id.name;
342
+ legacyObjects.set(
343
+ bindingName,
344
+ readLegacyStoryboardObject(
345
+ bindingName,
346
+ objectExpression,
347
+ imports,
348
+ source
349
+ )
350
+ );
351
+ const stringProperties = readObjectStringProperties(objectExpression);
352
+ if (stringProperties.size > 0) {
353
+ stringBindings.set(bindingName, stringProperties);
354
+ }
355
+ }
356
+ return { legacyObjects, stringBindings };
357
+ }
358
+ function readTopLevelVariableDeclarators(program) {
359
+ const declarators = [];
360
+ for (const statement of program?.body ?? []) {
361
+ const declaration = statement?.type === "VariableDeclaration" ? statement : statement?.type === "ExportNamedDeclaration" && statement.declaration?.type === "VariableDeclaration" ? statement.declaration : null;
362
+ if (!declaration) continue;
363
+ declarators.push(...declaration.declarations ?? []);
364
+ }
365
+ return declarators;
366
+ }
367
+ function readLegacyStoryboardObject(bindingName, objectExpression, imports, source) {
368
+ const errors = [];
369
+ const nameProperty = getObjectProperty(objectExpression, "name");
370
+ const name = nameProperty ? readStringLiteralValue(nameProperty.value) : null;
371
+ const layoutProperty = getObjectProperty(objectExpression, "layout");
372
+ const layout = layoutProperty ? readLayoutExpression(layoutProperty.value, "LegacyStoryboardV1") : {
373
+ value: DEFAULT_LAYOUT,
374
+ errors: [
375
+ {
376
+ message: '<LegacyStoryboardV1> storyboard object must include a literal "layout" object',
377
+ span: toSpan(objectExpression),
378
+ kind: "degraded"
379
+ }
380
+ ]
381
+ };
382
+ const renderProperty = getObjectProperty(objectExpression, "render");
383
+ const component = readRenderComponentReference(
384
+ renderProperty?.value,
385
+ imports,
386
+ source
387
+ );
388
+ if (nameProperty && !name) {
389
+ errors.push({
390
+ message: "<LegacyStoryboardV1> storyboard.name must be a string literal when set",
391
+ span: toSpan(nameProperty),
392
+ kind: "degraded"
393
+ });
394
+ }
395
+ errors.push(...layout.errors);
396
+ return {
397
+ bindingName,
398
+ displayName: name?.value,
399
+ component: component ?? void 0,
400
+ objectSpan: toSpan(objectExpression),
401
+ objectClose: readLayoutClose(objectExpression),
402
+ nameSpan: name?.span,
403
+ namePropertySpan: toSpan(nameProperty),
404
+ layoutPropertySpan: toSpan(layoutProperty),
405
+ layout: layout.value,
406
+ layoutSpans: layout.spans,
407
+ errors
408
+ };
409
+ }
410
+ function readObjectStringProperties(objectExpression) {
411
+ const properties = /* @__PURE__ */ new Map();
412
+ for (const property of objectExpression.properties ?? []) {
413
+ if (property?.type !== "Property" || property.computed) continue;
414
+ const propertyName = readPropertyKeyName(property.key);
415
+ const value = readStringLiteralValue(property.value);
416
+ if (!propertyName || !value) continue;
417
+ properties.set(propertyName, value);
418
+ }
419
+ return properties;
420
+ }
421
+ function readStoryboard(element, component, imports, legacyObjects, source, globalErrors) {
422
+ const openingElement = element.openingElement;
423
+ const errors = [];
424
+ const id = readStringAttribute(openingElement, "id");
425
+ const name = readStringAttribute(openingElement, "name");
426
+ const legacyReference = component === "LegacyStoryboardV1" ? readExpressionReference(openingElement, "storyboard", source) : void 0;
427
+ const legacyObject = legacyReference?.expression && isIdentifierExpression(legacyReference.expression) ? legacyObjects.get(legacyReference.expression) : void 0;
428
+ const layout = component === "LegacyStoryboardV1" ? {
429
+ value: legacyObject?.layout ?? DEFAULT_LAYOUT,
430
+ spans: legacyObject?.layoutSpans,
431
+ attributeSpan: void 0,
432
+ errors: legacyObject?.errors ?? (legacyReference ? [
433
+ {
434
+ message: "<LegacyStoryboardV1> storyboard prop must reference a same-file object literal",
435
+ span: legacyReference.span,
436
+ kind: "degraded"
437
+ }
438
+ ] : [
439
+ {
440
+ message: '<LegacyStoryboardV1> must include a "storyboard" expression prop',
441
+ span: toSpan(openingElement),
442
+ kind: "degraded"
443
+ }
444
+ ])
445
+ } : readLayout(openingElement, component);
446
+ const kind = component === "Storyboard" || component === "SvelteStoryboard" || component === "LegacyStoryboardV1" ? "component" : component === "RouteStoryboard" ? "route" : "html";
447
+ if (!id) {
448
+ errors.push({
449
+ message: `<${component}> must include a literal "id" prop`,
450
+ span: toSpan(openingElement),
451
+ kind: "structural"
452
+ });
453
+ }
454
+ if (layout.errors.length > 0) {
455
+ errors.push(...layout.errors);
456
+ }
457
+ const storyboard = {
458
+ storyboardKey: id?.value ?? "",
459
+ displayName: name?.value ?? legacyObject?.displayName,
460
+ kind,
461
+ ...component === "SvelteStoryboard" ? { uiFramework: "svelte" } : {},
462
+ layout: layout.value,
463
+ editable: Boolean(id) && layout.errors.length === 0,
464
+ jsxElementSpan: toSpan(element) ?? { start: 0, end: 0 },
465
+ openingElementSpan: toSpan(openingElement),
466
+ idSpan: id?.valueSpan,
467
+ idAttributeSpan: id?.attributeSpan,
468
+ nameSpan: name?.valueSpan ?? legacyObject?.nameSpan,
469
+ nameAttributeSpan: name?.attributeSpan ?? legacyObject?.namePropertySpan,
470
+ layoutAttributeSpan: layout.attributeSpan,
471
+ layoutSpans: layout.spans,
472
+ props: readExpressionReference(openingElement, "props", source),
473
+ component: legacyObject?.component,
474
+ legacyV1: legacyReference ? {
475
+ storyboard: legacyReference,
476
+ objectName: legacyObject?.bindingName,
477
+ objectSpan: legacyObject?.objectSpan,
478
+ objectClose: legacyObject?.objectClose,
479
+ namePropertySpan: legacyObject?.namePropertySpan,
480
+ layoutPropertySpan: legacyObject?.layoutPropertySpan
481
+ } : void 0,
482
+ errors
483
+ };
484
+ if (component === "Storyboard" || component === "SvelteStoryboard") {
485
+ const componentReference = readComponentReference(
486
+ openingElement,
487
+ imports,
488
+ source
489
+ );
490
+ if (componentReference) {
491
+ storyboard.component = componentReference;
492
+ } else {
493
+ errors.push({
494
+ message: `<${component}> must include a "component" expression prop`,
495
+ span: toSpan(openingElement),
496
+ kind: "degraded"
497
+ });
498
+ }
499
+ }
500
+ if (component === "Storyboard" || component === "SvelteStoryboard" || component === "HtmlStoryboard") {
501
+ const vrt = readVrt(openingElement, errors);
502
+ if (vrt) {
503
+ if (vrt.value) {
504
+ storyboard.vrt = vrt.value;
505
+ }
506
+ storyboard.vrtAttributeSpan = vrt.attributeSpan;
507
+ }
508
+ }
509
+ if (component === "RouteStoryboard") {
510
+ const route = readStringAttribute(openingElement, "route");
511
+ if (route) {
512
+ storyboard.route = route.value;
513
+ storyboard.routeSpan = route.valueSpan;
514
+ storyboard.routeAttributeSpan = route.attributeSpan;
515
+ } else {
516
+ errors.push({
517
+ message: '<RouteStoryboard> must include a literal "route" prop',
518
+ span: toSpan(openingElement),
519
+ kind: "degraded"
520
+ });
521
+ }
522
+ }
523
+ if (component === "HtmlStoryboard") {
524
+ const filepath = readStringAttribute(openingElement, "filepath");
525
+ const src = readStringAttribute(openingElement, "src");
526
+ storyboard.filepath = filepath?.value.trim() ? filepath.value : void 0;
527
+ storyboard.filepathSpan = filepath?.valueSpan;
528
+ storyboard.filepathAttributeSpan = filepath?.attributeSpan;
529
+ storyboard.src = src?.value;
530
+ storyboard.srcSpan = src?.valueSpan;
531
+ storyboard.srcAttributeSpan = src?.attributeSpan;
532
+ if (!filepath?.value.trim() && !src?.value.trim()) {
533
+ errors.push({
534
+ message: '<HtmlStoryboard> must include a literal "filepath" or "src" prop',
535
+ span: toSpan(openingElement),
536
+ kind: "degraded"
537
+ });
538
+ }
539
+ }
540
+ globalErrors.push(...errors);
541
+ return storyboard;
542
+ }
543
+ function readDirectCanvasStoryboardElements(canvasElement, imports) {
544
+ const elements = [];
545
+ for (const child of canvasElement.children ?? []) {
546
+ if (child?.type !== "JSXElement") continue;
547
+ const component = resolveSdkComponent(child.openingElement?.name, imports);
548
+ if (isStoryboardSdkComponent(component)) {
549
+ elements.push({ element: child, component });
550
+ }
551
+ }
552
+ return elements;
553
+ }
554
+ function reportDuplicateStoryboardIds(storyboards, errors) {
555
+ const byId = /* @__PURE__ */ new Map();
556
+ for (const storyboard of storyboards) {
557
+ if (!storyboard.storyboardKey) continue;
558
+ const matching = byId.get(storyboard.storyboardKey);
559
+ if (matching) {
560
+ matching.push(storyboard);
561
+ } else {
562
+ byId.set(storyboard.storyboardKey, [storyboard]);
563
+ }
564
+ }
565
+ for (const [storyboardKey, matching] of byId) {
566
+ if (matching.length < 2) continue;
567
+ errors.push({
568
+ message: `Duplicate storyboard id "${storyboardKey}" (${matching.length} declarations) \u2014 storyboard ids must be unique`,
569
+ span: matching[1]?.jsxElementSpan,
570
+ kind: "structural"
571
+ });
572
+ }
573
+ }
574
+ function validateCanvasChildren(canvasElement, imports) {
575
+ const errors = [];
576
+ for (const child of canvasElement.children ?? []) {
577
+ if (!child) continue;
578
+ if (child.type === "JSXText") {
579
+ if (typeof child.value === "string" && child.value.trim() === "") {
580
+ continue;
581
+ }
582
+ }
583
+ if (child.type === "JSXExpressionContainer") {
584
+ if (child.expression?.type === "JSXEmptyExpression") {
585
+ continue;
586
+ }
587
+ errors.push({
588
+ message: "<Canvas> children must be static storyboard declarations, not expressions",
589
+ span: toSpan(child),
590
+ kind: "structural"
591
+ });
592
+ continue;
593
+ }
594
+ if (child.type === "JSXElement") {
595
+ const component = resolveSdkComponent(
596
+ child.openingElement?.name,
597
+ imports
598
+ );
599
+ if (component === "Storyboard" || component === "SvelteStoryboard" || component === "LegacyStoryboardV1" || component === "RouteStoryboard" || component === "HtmlStoryboard") {
600
+ continue;
601
+ }
602
+ }
603
+ errors.push({
604
+ message: "<Canvas> children must be <Storyboard>, <SvelteStoryboard>, <RouteStoryboard>, <HtmlStoryboard>, or <LegacyStoryboardV1> declarations",
605
+ span: toSpan(child),
606
+ kind: "structural"
607
+ });
608
+ }
609
+ return errors;
610
+ }
611
+ function readVrt(openingElement, errors) {
612
+ const attribute = getAttribute(openingElement, "vrt");
613
+ if (!attribute) return null;
614
+ const attributeSpan = toSpan(attribute);
615
+ if (attribute.value == null) {
616
+ return { value: {}, attributeSpan };
617
+ }
618
+ const expression = unwrapTsExpression(
619
+ unwrapAttributeExpression(attribute.value)
620
+ );
621
+ if (expression?.type === "Literal" && expression.value === true) {
622
+ return { value: {}, attributeSpan };
623
+ }
624
+ if (expression?.type === "Literal" && expression.value === false) {
625
+ return { value: null, attributeSpan };
626
+ }
627
+ if (expression?.type !== "ObjectExpression") {
628
+ errors.push({
629
+ message: "<Storyboard> vrt must be a boolean literal or an object literal ({ threshold?, skip?, ignore? })",
630
+ span: toSpan(expression) ?? attributeSpan,
631
+ kind: "degraded"
632
+ });
633
+ return { value: null, attributeSpan };
634
+ }
635
+ const value = {};
636
+ for (const property of expression.properties ?? []) {
637
+ if (property?.type !== "Property" || property.computed) {
638
+ errors.push({
639
+ message: "<Storyboard> vrt must contain only literal properties",
640
+ span: toSpan(property ?? expression),
641
+ kind: "degraded"
642
+ });
643
+ continue;
644
+ }
645
+ const key = readPropertyKeyName(property.key);
646
+ if (key === "threshold") {
647
+ const threshold = readNumberLiteral(property.value);
648
+ if (threshold && threshold.value >= 0 && threshold.value <= 0.5) {
649
+ value.threshold = threshold.value;
650
+ } else {
651
+ errors.push({
652
+ message: "<Storyboard> vrt.threshold must be a number literal between 0 and 0.5",
653
+ span: toSpan(property),
654
+ kind: "degraded"
655
+ });
656
+ }
657
+ continue;
658
+ }
659
+ if (key === "skip") {
660
+ if (property.value?.type === "Literal" && typeof property.value.value === "boolean") {
661
+ if (property.value.value) value.skip = true;
662
+ } else {
663
+ errors.push({
664
+ message: "<Storyboard> vrt.skip must be a boolean literal",
665
+ span: toSpan(property),
666
+ kind: "degraded"
667
+ });
668
+ }
669
+ continue;
670
+ }
671
+ if (key === "ignore") {
672
+ const regions = readVrtIgnoreRegions(property.value, errors);
673
+ if (regions) value.ignore = regions;
674
+ continue;
675
+ }
676
+ errors.push({
677
+ message: `<Storyboard> vrt has unknown property "${key ?? "?"}" \u2014 expected threshold, skip, or ignore`,
678
+ span: toSpan(property),
679
+ kind: "degraded"
680
+ });
681
+ }
682
+ return { value, attributeSpan };
683
+ }
684
+ function readVrtIgnoreRegions(node, errors) {
685
+ if (node?.type !== "ArrayExpression") {
686
+ errors.push({
687
+ message: "<Storyboard> vrt.ignore must be an array of { x, y, w, h } literals",
688
+ span: toSpan(node),
689
+ kind: "degraded"
690
+ });
691
+ return null;
692
+ }
693
+ const regions = [];
694
+ for (const element of node.elements ?? []) {
695
+ const region = {};
696
+ for (const key of ["x", "y", "w", "h"]) {
697
+ const property = getObjectProperty(element, key);
698
+ const number = property ? readNumberLiteral(property.value) : null;
699
+ if (number) region[key] = number.value;
700
+ }
701
+ if (region.x === void 0 || region.y === void 0 || region.w === void 0 || region.h === void 0) {
702
+ errors.push({
703
+ message: "<Storyboard> vrt.ignore regions must be { x, y, w, h } number literals",
704
+ span: toSpan(element) ?? toSpan(node),
705
+ kind: "degraded"
706
+ });
707
+ return null;
708
+ }
709
+ regions.push(region);
710
+ }
711
+ return regions;
712
+ }
713
+ function readComponentReference(openingElement, imports, source) {
714
+ const attribute = getAttribute(openingElement, "component");
715
+ const expression = unwrapAttributeExpression(attribute?.value);
716
+ const span = toSpan(expression);
717
+ if (!expression || !span) return null;
718
+ const localName = expression.type === "Identifier" ? expression.name : expression.type === "MemberExpression" && expression.object?.type === "Identifier" ? expression.object.name : void 0;
719
+ return {
720
+ expression: source.slice(span.start, span.end),
721
+ span,
722
+ attributeSpan: toSpan(attribute),
723
+ localName,
724
+ import: localName ? imports.byLocalName.get(localName) : void 0
725
+ };
726
+ }
727
+ function readRenderComponentReference(renderValue, imports, source) {
728
+ if (renderValue?.type !== "ArrowFunctionExpression") return null;
729
+ const body = unwrapTsExpression(renderValue.body);
730
+ if (body?.type !== "JSXElement") return null;
731
+ const name = body.openingElement?.name;
732
+ if (name?.type !== "JSXIdentifier") return null;
733
+ const span = toSpan(name);
734
+ if (!span || typeof name.name !== "string") return null;
735
+ return {
736
+ expression: source.slice(span.start, span.end),
737
+ span,
738
+ localName: name.name,
739
+ import: imports.byLocalName.get(name.name)
740
+ };
741
+ }
742
+ function readExpressionReference(openingElement, name, source) {
743
+ const attribute = getAttribute(openingElement, name);
744
+ const expression = unwrapAttributeExpression(attribute?.value);
745
+ const span = toSpan(expression);
746
+ if (!expression || !span) return void 0;
747
+ return {
748
+ expression: source.slice(span.start, span.end),
749
+ span,
750
+ attributeSpan: toSpan(attribute)
751
+ };
752
+ }
753
+ function isIdentifierExpression(expression) {
754
+ return /^[A-Za-z_$][\w$]*$/.test(expression);
755
+ }
756
+ function readLayout(openingElement, componentName) {
757
+ const isViewport = componentName === "RouteStoryboard" || componentName === "HtmlStoryboard";
758
+ const attribute = getAttribute(openingElement, "layout");
759
+ const expression = unwrapAttributeExpression(attribute?.value);
760
+ if (!expression) {
761
+ return {
762
+ value: isViewport ? DEFAULT_VIEWPORT_LAYOUT : DEFAULT_LAYOUT,
763
+ attributeSpan: toSpan(attribute),
764
+ errors: [
765
+ {
766
+ message: `<${componentName}> must include a literal "layout" object prop`,
767
+ span: toSpan(openingElement),
768
+ kind: "degraded"
769
+ }
770
+ ]
771
+ };
772
+ }
773
+ const layout = readLayoutExpression(expression, componentName);
774
+ return {
775
+ ...layout,
776
+ attributeSpan: toSpan(attribute)
777
+ };
778
+ }
779
+ function readLayoutExpression(expression, componentName) {
780
+ const errors = [];
781
+ const isViewport = componentName === "RouteStoryboard" || componentName === "HtmlStoryboard";
782
+ if (expression.type !== "ObjectExpression") {
783
+ return {
784
+ value: isViewport ? DEFAULT_VIEWPORT_LAYOUT : DEFAULT_LAYOUT,
785
+ spans: { layoutClose: readLayoutClose(expression) },
786
+ errors: [
787
+ {
788
+ message: `<${componentName}> layout must be an object literal`,
789
+ span: toSpan(expression),
790
+ kind: "degraded"
791
+ }
792
+ ]
793
+ };
794
+ }
795
+ const spans = {
796
+ layoutClose: readLayoutClose(expression)
797
+ };
798
+ const layout = { ...DEFAULT_LAYOUT };
799
+ const width = getObjectProperty(expression, "width");
800
+ const height = getObjectProperty(expression, "height");
801
+ const legacySizing = getObjectProperty(expression, "intrinsicSizing");
802
+ const legacyResponsiveFlag = legacySizing?.value?.value === "root-element";
803
+ const hasBothSizes = Boolean(width && height);
804
+ const readSize = isViewport || hasBothSizes && !legacyResponsiveFlag;
805
+ const incompleteSize = !isViewport && Boolean(width) !== Boolean(height);
806
+ if (incompleteSize) {
807
+ errors.push({
808
+ message: "layout.width and layout.height must be set together",
809
+ span: toSpan(expression),
810
+ kind: "degraded"
811
+ });
812
+ }
813
+ const size = readSize ? {
814
+ width: width ? readNumberLiteral(width.value) : null,
815
+ height: height ? readNumberLiteral(height.value) : null
816
+ } : null;
817
+ const keys = readSize ? ["x", "y", "width", "height"] : ["x", "y"];
818
+ for (const key of keys) {
819
+ const property = key === "width" ? width : key === "height" ? height : getObjectProperty(expression, key);
820
+ const value = key === "width" || key === "height" ? size?.[key] : property ? readNumberLiteral(property.value) : null;
821
+ const keepValue = key === "x" || key === "y" || isViewport || Boolean(size?.width && size.height);
822
+ if (!value) {
823
+ errors.push({
824
+ message: `<${componentName}> layout.${key} must be a number literal`,
825
+ span: toSpan(property ?? expression),
826
+ kind: "degraded"
827
+ });
828
+ continue;
829
+ }
830
+ if (!keepValue) continue;
831
+ layout[key] = value.value;
832
+ spans[key] = value.span;
833
+ }
834
+ const zIndex = getObjectProperty(expression, "zIndex");
835
+ if (zIndex) {
836
+ const value = readNumberLiteral(zIndex.value);
837
+ if (value) {
838
+ layout.zIndex = value.value;
839
+ spans.zIndex = value.span;
840
+ } else {
841
+ errors.push({
842
+ message: `<${componentName}> layout.zIndex must be a number literal`,
843
+ span: toSpan(zIndex),
844
+ kind: "degraded"
845
+ });
846
+ }
847
+ }
848
+ const invalidLegacyFlag = legacySizing && (legacySizing.value?.type !== "Literal" || !legacyResponsiveFlag);
849
+ if (invalidLegacyFlag) {
850
+ errors.push({
851
+ message: `<${componentName}> layout.intrinsicSizing must be "root-element" when set`,
852
+ span: toSpan(legacySizing),
853
+ kind: "degraded"
854
+ });
855
+ }
856
+ return { value: layout, spans, errors };
857
+ }
858
+ function readStringLiteralValue(node) {
859
+ return node?.type === "Literal" && typeof node.value === "string" ? { value: node.value, span: toSpan(node) ?? { start: 0, end: 0 } } : null;
860
+ }
861
+ function unwrapTsExpression(node) {
862
+ let current = node;
863
+ while (current?.type === "TSSatisfiesExpression" || current?.type === "TSAsExpression" || current?.type === "TSNonNullExpression" || current?.type === "ParenthesizedExpression") {
864
+ current = current.expression;
865
+ }
866
+ return current;
867
+ }
868
+ function readResolvableStringAttribute(openingElement, name, bindings) {
869
+ const literal = readStringAttribute(openingElement, name);
870
+ if (literal) return literal;
871
+ const attribute = getAttribute(openingElement, name);
872
+ const expression = unwrapAttributeExpression(attribute?.value);
873
+ const expressionSpan = toSpan(expression);
874
+ const attributeSpan = toSpan(attribute);
875
+ if (!expression || !expressionSpan || !attributeSpan) return null;
876
+ const resolved = resolveStringMemberExpression(expression, bindings);
877
+ return resolved ? {
878
+ value: resolved.value,
879
+ valueSpan: expressionSpan,
880
+ attributeSpan
881
+ } : null;
882
+ }
883
+ function resolveStringMemberExpression(expression, bindings) {
884
+ if (expression?.type !== "MemberExpression") return null;
885
+ if (expression.object?.type !== "Identifier") return null;
886
+ const propertyName = readPropertyKeyName(expression.property);
887
+ if (!propertyName) return null;
888
+ return bindings.get(expression.object.name)?.get(propertyName) ?? null;
889
+ }
890
+ function readStringAttribute(openingElement, name) {
891
+ const attribute = getAttribute(openingElement, name);
892
+ if (!attribute) return null;
893
+ const value = attribute.value;
894
+ if (value?.type === "Literal" && typeof value.value === "string") {
895
+ return {
896
+ value: value.value,
897
+ valueSpan: toSpan(value) ?? toSpan(attribute) ?? { start: 0, end: 0 },
898
+ attributeSpan: toSpan(attribute) ?? { start: 0, end: 0 }
899
+ };
900
+ }
901
+ const expression = unwrapAttributeExpression(value);
902
+ if (expression?.type === "Literal" && typeof expression.value === "string") {
903
+ return {
904
+ value: expression.value,
905
+ valueSpan: toSpan(expression) ?? toSpan(attribute) ?? { start: 0, end: 0 },
906
+ attributeSpan: toSpan(attribute) ?? { start: 0, end: 0 }
907
+ };
908
+ }
909
+ return null;
910
+ }
911
+ function getAttribute(openingElement, name) {
912
+ for (const attribute of openingElement?.attributes ?? []) {
913
+ if (attribute?.type === "JSXAttribute" && attribute.name?.type === "JSXIdentifier" && attribute.name.name === name) {
914
+ return attribute;
915
+ }
916
+ }
917
+ return null;
918
+ }
919
+ function unwrapAttributeExpression(value) {
920
+ if (!value) return null;
921
+ if (value.type === "JSXExpressionContainer") {
922
+ return value.expression;
923
+ }
924
+ return value;
925
+ }
926
+ function readPropertyKeyName(key) {
927
+ if (key?.type === "Identifier") return key.name;
928
+ if (key?.type === "Literal" && typeof key.value === "string") {
929
+ return key.value;
930
+ }
931
+ return null;
932
+ }
933
+ function getObjectProperty(objectExpression, name) {
934
+ if (objectExpression?.type !== "ObjectExpression") return null;
935
+ for (const property of objectExpression.properties ?? []) {
936
+ if (property?.type !== "Property" || property.computed) continue;
937
+ const propertyName = readPropertyKeyName(property.key);
938
+ if (propertyName === name) return property;
939
+ }
940
+ return null;
941
+ }
942
+ function readNumberLiteral(node) {
943
+ if (node?.type === "Literal" && typeof node.value === "number" && Number.isFinite(node.value)) {
944
+ return { value: node.value, span: toSpan(node) ?? { start: 0, end: 0 } };
945
+ }
946
+ if (node?.type === "UnaryExpression" && node.operator === "-" && node.argument?.type === "Literal" && typeof node.argument.value === "number" && Number.isFinite(node.argument.value)) {
947
+ return {
948
+ value: -node.argument.value,
949
+ span: toSpan(node) ?? { start: 0, end: 0 }
950
+ };
951
+ }
952
+ return null;
953
+ }
954
+ function resolveSdkComponent(nameNode, imports) {
955
+ if (nameNode?.type === "JSXIdentifier") {
956
+ return imports.sdkLocalNames.get(nameNode.name) ?? null;
957
+ }
958
+ if (nameNode?.type === "JSXMemberExpression" && nameNode.object?.type === "JSXIdentifier" && nameNode.property?.type === "JSXIdentifier" && imports.sdkNamespaces.has(nameNode.object.name) && SDK_COMPONENTS.has(nameNode.property.name)) {
959
+ return nameNode.property.name;
960
+ }
961
+ return null;
962
+ }
963
+ function resolveMisimportedNamespaceSdkComponent(nameNode, imports, misimportedSdkCanvasImports) {
964
+ if (nameNode?.type !== "JSXMemberExpression" || nameNode.object?.type !== "JSXIdentifier" || nameNode.property?.type !== "JSXIdentifier" || !SDK_COMPONENTS.has(nameNode.property.name)) {
965
+ return null;
966
+ }
967
+ const imported = imports.byLocalName.get(nameNode.object.name);
968
+ if (imported?.kind !== "namespace" || !isWrongTempoSdkCanvasImportSource(imported.source)) {
969
+ return null;
970
+ }
971
+ return misimportedSdkCanvasImports.namespaceCandidatesByLocalName.get(
972
+ nameNode.object.name
973
+ ) ?? null;
974
+ }
975
+ function isStoryboardSdkComponent(component) {
976
+ return component === "Storyboard" || component === "SvelteStoryboard" || component === "LegacyStoryboardV1" || component === "RouteStoryboard" || component === "HtmlStoryboard";
977
+ }
978
+ function readImportedName(specifier) {
979
+ if (specifier.type === "ImportDefaultSpecifier") return "default";
980
+ if (specifier.type === "ImportNamespaceSpecifier") return "*";
981
+ return specifier.imported?.name ?? specifier.local?.name ?? "unknown";
982
+ }
983
+ function readImportKind(specifier) {
984
+ if (specifier.type === "ImportDefaultSpecifier") return "default";
985
+ if (specifier.type === "ImportNamespaceSpecifier") return "namespace";
986
+ return "named";
987
+ }
988
+ function isSdkImportSource(source) {
989
+ return SDK_IMPORT_SOURCES.has(source) || source.endsWith("/tempo-sdk/canvas") || source.endsWith("/tempo-sdk/canvas/svelte");
990
+ }
991
+ function isWrongTempoSdkCanvasImportSource(source) {
992
+ return (source === "tempo-sdk" || source.startsWith("tempo-sdk/")) && !isSdkImportSource(source);
993
+ }
994
+ function spanKey(span) {
995
+ return `${span.start}:${span.end}`;
996
+ }
997
+ function readLayoutClose(node) {
998
+ return typeof node?.end === "number" && Number.isFinite(node.end) ? node.end - 1 : void 0;
999
+ }
1000
+ function fallbackPageName(filePath) {
1001
+ const normalized = filePath.replace(/\\/g, "/");
1002
+ const segments = normalized.split("/").filter(Boolean);
1003
+ const fileName = segments.length > 0 ? segments[segments.length - 1] : filePath;
1004
+ const parentName = segments.length > 1 ? segments[segments.length - 2] : fileName;
1005
+ const baseName = /^index\.canvas\.[tj]sx?$/.test(fileName) ? parentName : fileName.replace(/\.canvas\.[tj]sx?$/, "");
1006
+ return baseName.split(/[-_\s]+/).filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
1007
+ }
1008
+ function toSpan(node) {
1009
+ 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;
1010
+ }
1011
+ function walk(node, visitor, seen = /* @__PURE__ */ new Set()) {
1012
+ if (!node || typeof node !== "object" || seen.has(node)) return;
1013
+ seen.add(node);
1014
+ visitor(node);
1015
+ for (const value of Object.values(node)) {
1016
+ if (!value) continue;
1017
+ if (Array.isArray(value)) {
1018
+ for (const item of value) {
1019
+ walk(item, visitor, seen);
1020
+ }
1021
+ } else if (typeof value === "object") {
1022
+ walk(value, visitor, seen);
1023
+ }
1024
+ }
1025
+ }
1026
+
1027
+ // canvas-component-reference.ts
1028
+ var COMPONENT_REFERENCE_ATTRIBUTE = "data-tempo-component-reference";
1029
+ function moduleIdentity(file, specifier, resolved) {
1030
+ const bundled = resolved?.get(specifier);
1031
+ const target = bundled === void 0 ? specifier : bundled.replace(/\bt=\d{13}&?\b/, "").replace(/[?&]$/, "");
1032
+ if (target.startsWith("\0")) return target;
1033
+ const suffixAt = target.search(/[?#]/);
1034
+ let path = (suffixAt < 0 ? target : target.slice(0, suffixAt)).replace(
1035
+ /\\/g,
1036
+ "/"
1037
+ );
1038
+ const suffix = suffixAt < 0 ? "" : target.slice(suffixAt);
1039
+ if (bundled === void 0 && path.startsWith("."))
1040
+ path = (0, import_node_path.resolve)((0, import_node_path.dirname)(file), path);
1041
+ if (!(0, import_node_path.isAbsolute)(path) && !/^[A-Za-z]:\//.test(path)) return target;
1042
+ if (bundled !== void 0) {
1043
+ try {
1044
+ path = import_node_fs.realpathSync.native(path);
1045
+ } catch {
1046
+ }
1047
+ }
1048
+ return (0, import_node_path.normalize)(path).replace(/\\/g, "/") + suffix;
1049
+ }
1050
+ function canvasComponentAnnotations(file, source, resolved) {
1051
+ const result = /* @__PURE__ */ new Map();
1052
+ if (!source.includes("tempo-sdk/canvas")) return result;
1053
+ const parsed = parseCanvasFile(file, source);
1054
+ for (const board of parsed.storyboards) {
1055
+ const ref = board.component;
1056
+ if (board.kind !== "component" || !ref?.localName || board.openingElementSpan === void 0)
1057
+ continue;
1058
+ const member = ref.expression.match(
1059
+ /^\s*([$\w]+)(?:\s*\.\s*([$\w]+))?\s*$/
1060
+ );
1061
+ if (!member) continue;
1062
+ let name;
1063
+ if (ref.import) {
1064
+ if (ref.import.kind === "namespace") {
1065
+ if (!member[2]) continue;
1066
+ name = member[2];
1067
+ } else {
1068
+ if (member[2]) continue;
1069
+ name = ref.import.importedName;
1070
+ }
1071
+ } else {
1072
+ if (member[2]) continue;
1073
+ name = ref.localName;
1074
+ }
1075
+ const specifier = ref.import?.source.replace(/\\/g, "/").replace(/[?#].*/, "");
1076
+ const canvasDir = import_node_path.posix.dirname(file.replace(/\\/g, "/"));
1077
+ const external = specifier !== void 0 && (!specifier.startsWith(".") || !import_node_path.posix.join(canvasDir, specifier).startsWith(`${canvasDir}/`));
1078
+ result.set(board.openingElementSpan.start, {
1079
+ [COMPONENT_REFERENCE_ATTRIBUTE]: JSON.stringify([
1080
+ ref.import ? "import" : "local",
1081
+ moduleIdentity(file, ref.import?.source ?? file, resolved),
1082
+ name
1083
+ ]),
1084
+ ...external ? { "data-tempo-external-component": "true" } : {}
1085
+ });
1086
+ }
1087
+ return result;
1088
+ }
1089
+
1090
+ // nextjs-loader.ts
1091
+ var import_node_fs5 = require("fs");
41
1092
  var import_node_module = require("module");
42
- var import_node_path3 = require("path");
1093
+ var import_node_path5 = require("path");
43
1094
 
44
1095
  // ../../modules/annotation/annotate-file.ts
45
- var import_oxc_parser2 = require("oxc-parser");
1096
+ var import_oxc_parser3 = require("oxc-parser");
46
1097
 
47
1098
  // ../../modules/file-parser/utils.ts
48
1099
  function getTagName(name) {
@@ -61,22 +1112,26 @@ function getJSXMemberExpressionName(node) {
61
1112
  }
62
1113
 
63
1114
  // ../../modules/file-parser/walk.ts
64
- function walk(node, callbacks) {
1115
+ var import_keys = __toESM(require("oxc-parser/src-js/generated/visit/keys.js"), 1);
1116
+ var importedKeys = import_keys.default;
1117
+ var visitorKeys = importedKeys.default ?? importedKeys;
1118
+ function walk2(node, callbacks, parent = null) {
65
1119
  if (node === null || node === void 0 || typeof node !== "object") return;
66
1120
  if (Array.isArray(node)) {
67
1121
  for (const child of node) {
68
- walk(child, callbacks);
1122
+ walk2(child, callbacks, parent);
69
1123
  }
70
1124
  return;
71
1125
  }
72
1126
  const record = node;
73
1127
  const type = record.type;
74
1128
  if (typeof type === "string" && type in callbacks) {
75
- callbacks[type](node);
1129
+ callbacks[type](node, parent);
76
1130
  }
1131
+ const enclosing = typeof type === "string" ? node : parent;
77
1132
  for (const value of Object.values(record)) {
78
1133
  if (value !== null && typeof value === "object") {
79
- walk(value, callbacks);
1134
+ walk2(value, callbacks, enclosing);
80
1135
  }
81
1136
  }
82
1137
  }
@@ -100,8 +1155,7 @@ var ScopeFlags = {
100
1155
  };
101
1156
 
102
1157
  // ../../modules/file-parser/scope-analyzer/scopeAnalyzer.ts
103
- var import_oxc_parser = require("oxc-parser");
104
- var import_keys = __toESM(require("oxc-parser/src-js/generated/visit/keys.js"), 1);
1158
+ var import_oxc_parser2 = require("oxc-parser");
105
1159
 
106
1160
  // ../../modules/annotation/annotate-file.ts
107
1161
  function formatPropValue(value) {
@@ -131,15 +1185,16 @@ function removeExistingProps(props, existingNames) {
131
1185
  }
132
1186
  var FRAGMENT_TAG_NAMES = /* @__PURE__ */ new Set(["Fragment", "React.Fragment"]);
133
1187
  function annotateFile(source, filename, computeAnnotatedProps) {
134
- const parseResult = (0, import_oxc_parser2.parseSync)(filename, source);
1188
+ const parseResult = (0, import_oxc_parser3.parseSync)(filename, source);
135
1189
  const insertions = [];
136
- walk(parseResult.program, {
137
- JSXElement(node) {
1190
+ walk2(parseResult.program, {
1191
+ JSXElement(node, parent) {
138
1192
  const element = node;
139
1193
  const tagName = getTagName(element.openingElement.name);
140
1194
  if (FRAGMENT_TAG_NAMES.has(tagName)) return;
1195
+ const parentType = parent?.type ?? null;
141
1196
  const props = removeExistingProps(
142
- computeAnnotatedProps({ element, tagName }),
1197
+ computeAnnotatedProps({ element, tagName, parentType }),
143
1198
  getExistingAttributeNames(element)
144
1199
  );
145
1200
  if (Object.keys(props).length === 0) return;
@@ -166,6 +1221,105 @@ function annotateFile(source, filename, computeAnnotatedProps) {
166
1221
  return { annotatedSource: chunks.join(""), elementsAnnotated: insertions.length, parseResult };
167
1222
  }
168
1223
 
1224
+ // ../../modules/annotation/expression-facts.ts
1225
+ var EXPRESSION_FACTS_ATTRIBUTE = "data-tempo-expr";
1226
+ var DYNAMIC_SLOT_FACT = "#slot";
1227
+ function expressionFacts(element, parentType) {
1228
+ const opening = element.openingElement;
1229
+ const attributes = opening.attributes;
1230
+ const facts = [];
1231
+ if (parentType !== "JSXElement" && parentType !== "JSXFragment")
1232
+ facts.push(DYNAMIC_SLOT_FACT);
1233
+ const last = /* @__PURE__ */ new Map();
1234
+ attributes.forEach((attribute, index) => {
1235
+ const name = attributeName(attribute);
1236
+ if (name !== null) last.set(name, index);
1237
+ });
1238
+ let lastSpread = -1;
1239
+ attributes.forEach((attribute, index) => {
1240
+ if (attribute.type === "JSXSpreadAttribute") lastSpread = index;
1241
+ });
1242
+ for (const [name, index] of last) {
1243
+ if (unstamped(name)) continue;
1244
+ const overridden = index < lastSpread;
1245
+ const value = attributes[index].value;
1246
+ if (value === null) continue;
1247
+ if (name === "style" && !overridden) {
1248
+ facts.push(...styleFacts(value));
1249
+ continue;
1250
+ }
1251
+ if (overridden || !isLiteralValue(value)) facts.push(name);
1252
+ }
1253
+ if (facts.length > 0) return facts.join(" ");
1254
+ return lastSpread >= 0 ? "" : void 0;
1255
+ }
1256
+ function attributeName(attribute) {
1257
+ if (attribute.type !== "JSXAttribute") return null;
1258
+ const name = attribute.name;
1259
+ if (name.type === "JSXIdentifier") return name.name;
1260
+ if (name.type === "JSXNamespacedName") {
1261
+ const namespace = name.namespace.name;
1262
+ return `${namespace}:${name.name.name}`;
1263
+ }
1264
+ return null;
1265
+ }
1266
+ function unstamped(name) {
1267
+ return name === "key" || name.startsWith("data-tempo-");
1268
+ }
1269
+ function styleFacts(value) {
1270
+ const expression = value.type === "JSXExpressionContainer" ? unwrap(value.expression) : value;
1271
+ if (expression.type !== "ObjectExpression") return ["style"];
1272
+ const properties = expression.properties;
1273
+ const last = /* @__PURE__ */ new Map();
1274
+ properties.forEach((property, index) => {
1275
+ const key = styleKey(property);
1276
+ if (key !== null) last.set(key, index);
1277
+ });
1278
+ const facts = [];
1279
+ for (const [key, index] of last) {
1280
+ const property = properties[index];
1281
+ const overridden = properties.slice(index + 1).some((later) => later.type === "SpreadElement" || later.computed);
1282
+ const literal = property.type !== "ObjectMethod" && !property.shorthand && isLiteral(property.value);
1283
+ if (overridden || !literal) facts.push(`style.${key}`);
1284
+ }
1285
+ return facts;
1286
+ }
1287
+ function styleKey(property) {
1288
+ const isProperty = property.type === "Property" || property.type === "ObjectProperty" || property.type === "ObjectMethod";
1289
+ if (!isProperty || property.computed) return null;
1290
+ const key = property.key;
1291
+ if (key.type === "Identifier") return key.name;
1292
+ const isString = (key.type === "Literal" || key.type === "StringLiteral") && typeof key.value === "string";
1293
+ return isString ? key.value : null;
1294
+ }
1295
+ function isLiteralValue(value) {
1296
+ if (value.type === "Literal" || value.type === "StringLiteral") return true;
1297
+ if (value.type !== "JSXExpressionContainer") return false;
1298
+ return isLiteral(value.expression);
1299
+ }
1300
+ function isLiteral(node) {
1301
+ const current = unwrap(node);
1302
+ if (current.type === "UnaryExpression") {
1303
+ const signed = current.operator === "-" || current.operator === "+";
1304
+ return signed && isNumber(current.argument);
1305
+ }
1306
+ if (isNumber(current)) return true;
1307
+ if (current.type === "StringLiteral" || current.type === "BooleanLiteral")
1308
+ return true;
1309
+ const value = current.value;
1310
+ return current.type === "Literal" && (typeof value === "string" || typeof value === "boolean");
1311
+ }
1312
+ function isNumber(node) {
1313
+ const numeric = node.type === "Literal" || node.type === "NumericLiteral";
1314
+ return numeric && typeof node.value === "number" && Number.isFinite(node.value);
1315
+ }
1316
+ function unwrap(node) {
1317
+ let current = node;
1318
+ while (current.type === "ParenthesizedExpression")
1319
+ current = current.expression;
1320
+ return current;
1321
+ }
1322
+
169
1323
  // ../../modules/annotation/source-version.ts
170
1324
  function sourceVersionHash(content) {
171
1325
  let djb2 = 5381;
@@ -182,11 +1336,11 @@ function toHex8(n) {
182
1336
  }
183
1337
 
184
1338
  // nextjs-loader.ts
185
- var import_oxc_parser3 = require("oxc-parser");
1339
+ var import_oxc_parser4 = require("oxc-parser");
186
1340
 
187
1341
  // annotation-strategy.ts
188
- var import_node_fs = require("fs");
189
- var import_node_path = require("path");
1342
+ var import_node_fs2 = require("fs");
1343
+ var import_node_path2 = require("path");
190
1344
  var HTML_VOID_ELEMENTS = /* @__PURE__ */ new Set([
191
1345
  "area",
192
1346
  "base",
@@ -224,6 +1378,16 @@ function defaultComputeAnnotatedProps(info, filepath, modifiedtsMs, sourceVersio
224
1378
  "data-tempo-source-version": sourceVersion
225
1379
  };
226
1380
  }
1381
+ function appendModuleVersionRecord(source, filepath, modifiedtsMs, sourceVersion) {
1382
+ const record = JSON.stringify({
1383
+ file: filepath,
1384
+ modifiedTs: modifiedtsMs,
1385
+ sourceVersion
1386
+ });
1387
+ return `${source}
1388
+ ;typeof window !== "undefined" && (globalThis.__TEMPO_MODULE_VERSIONS__ || (globalThis.__TEMPO_MODULE_VERSIONS__ = [])).push(${record});
1389
+ `;
1390
+ }
227
1391
  function computeTempoAnnotatedProps(params) {
228
1392
  const {
229
1393
  info,
@@ -233,7 +1397,22 @@ function computeTempoAnnotatedProps(params) {
233
1397
  computeAnnotatedProps,
234
1398
  elementSupportOverrides
235
1399
  } = params;
236
- const userProps = computeAnnotatedProps ? computeAnnotatedProps(info, filepath, modifiedtsMs, sourceVersion) : defaultComputeAnnotatedProps(info, filepath, modifiedtsMs, sourceVersion);
1400
+ const userProps = {
1401
+ ...computeAnnotatedProps ? computeAnnotatedProps(info, filepath, modifiedtsMs, sourceVersion) : defaultComputeAnnotatedProps(
1402
+ info,
1403
+ filepath,
1404
+ modifiedtsMs,
1405
+ sourceVersion
1406
+ ),
1407
+ // Only a caller that knows the parent can say whether the slot is a JSX
1408
+ // child; without it every element would read as a dynamic slot.
1409
+ ...info.parentType !== void 0 && !hasJsxAttribute(info, EXPRESSION_FACTS_ATTRIBUTE) ? {
1410
+ [EXPRESSION_FACTS_ATTRIBUTE]: expressionFacts(
1411
+ info.element,
1412
+ info.parentType
1413
+ )
1414
+ } : {}
1415
+ };
237
1416
  if (isIntrinsicElement(info.tagName)) {
238
1417
  return {
239
1418
  ...userProps,
@@ -257,8 +1436,161 @@ function computeTempoAnnotatedProps(params) {
257
1436
  }
258
1437
 
259
1438
  // host-identity.ts
260
- var import_node_fs2 = require("fs");
261
- var import_node_path2 = require("path");
1439
+ var import_node_fs3 = require("fs");
1440
+ var import_node_path3 = require("path");
1441
+
1442
+ // package.json
1443
+ var package_default = {
1444
+ name: "tempo-sdk",
1445
+ version: "0.0.60",
1446
+ publishConfig: {
1447
+ tag: "sdk-v2-latest"
1448
+ },
1449
+ type: "module",
1450
+ description: "Tempo SDK \u2014 Vite, Next.js, and Expo plugins for JSX annotation and shared page/storyboard types",
1451
+ repository: {
1452
+ type: "git",
1453
+ url: "git+https://github.com/TempoLabsAI/tempo-monorepo.git",
1454
+ directory: "tempo-modules/tempo-sdk"
1455
+ },
1456
+ exports: {
1457
+ ".": {
1458
+ types: "./dist/index.d.ts",
1459
+ import: "./dist/index.js"
1460
+ },
1461
+ "./canvas": {
1462
+ types: "./dist/canvas/index.d.ts",
1463
+ import: "./dist/canvas/index.js"
1464
+ },
1465
+ "./canvas/svelte": {
1466
+ types: "./dist/canvas/svelte.d.ts",
1467
+ import: "./dist/canvas/svelte.js"
1468
+ },
1469
+ "./canvas/interact-projection": {
1470
+ types: "./dist/canvas/interact-projection.d.ts",
1471
+ import: "./dist/canvas/interact-projection.js"
1472
+ },
1473
+ "./canvas/parser": {
1474
+ types: "./dist/canvas/parser.d.ts",
1475
+ import: "./dist/canvas/parser.js"
1476
+ },
1477
+ "./canvas/editor": {
1478
+ types: "./dist/canvas/editor.d.ts",
1479
+ import: "./dist/canvas/editor.js"
1480
+ },
1481
+ "./assets": {
1482
+ types: "./dist/assets/index.d.ts",
1483
+ import: "./dist/assets/index.js"
1484
+ },
1485
+ "./assets/parser": {
1486
+ types: "./dist/assets/parser.d.ts",
1487
+ import: "./dist/assets/parser.js"
1488
+ },
1489
+ "./assets/editor": {
1490
+ types: "./dist/assets/editor.d.ts",
1491
+ import: "./dist/assets/editor.js"
1492
+ },
1493
+ "./nextjs": {
1494
+ types: "./dist/nextjs.d.ts",
1495
+ import: "./dist/nextjs.js",
1496
+ require: "./dist/nextjs.cjs"
1497
+ },
1498
+ "./nextjs/plugin": {
1499
+ types: "./dist/nextjs/plugin.d.ts",
1500
+ import: "./dist/nextjs/plugin.js"
1501
+ },
1502
+ "./expo": {
1503
+ types: "./dist/expo-babel-plugin.d.ts",
1504
+ import: "./dist/expo-babel-plugin.js",
1505
+ require: "./dist/expo-babel-plugin.cjs"
1506
+ },
1507
+ "./expo/plugin": {
1508
+ types: "./dist/expo/plugin.d.ts",
1509
+ import: "./dist/expo/plugin.js",
1510
+ require: "./dist/expo/plugin.cjs"
1511
+ },
1512
+ "./svelte": {
1513
+ types: "./dist/svelte.d.ts",
1514
+ import: "./dist/svelte.js"
1515
+ }
1516
+ },
1517
+ files: [
1518
+ "dist"
1519
+ ],
1520
+ scripts: {
1521
+ clean: "rm -rf dist",
1522
+ build: "pnpm run clean && tsup",
1523
+ "build:if-missing": "test -f dist/index.js || pnpm run build",
1524
+ prepare: "pnpm run build",
1525
+ prepublishOnly: "pnpm build",
1526
+ demo: "TEMPO=true pnpm --filter @tempo-modules/vite-annotate-plugin-demo dev",
1527
+ "demo:nextjs": "TEMPO=true pnpm --filter @tempo-modules/tempo-sdk-nextjs-demo dev",
1528
+ test: "vitest run",
1529
+ "test:browser": "vitest run canvas-dependency-scan-browser.test.ts pruned-module-deletion-browser.test.ts asset-live-preview-browser.test.ts asset-popover-lifecycle-browser.test.ts component-controls-browser.test.ts canvas-controls-browser.test.ts canvas-capture-determinism-browser.test.ts canvas-host-vite-e2e.test.ts canvas-host-packed-sdk-e2e.test.ts error-tracking-e2e.test.ts",
1530
+ "test:watch": "vitest",
1531
+ "test:nextjs:unit": "vitest run nextjs-loader.test.ts nextjs-wrapper.test.ts nextjs-fixtures.test.ts nextjs-published.test.ts",
1532
+ "test:nextjs:integration": "vitest run nextjs-e2e-correctness.test.ts",
1533
+ "test:nextjs:production": "vitest run nextjs-production.test.ts",
1534
+ "test:nextjs": "vitest run nextjs-loader.test.ts nextjs-wrapper.test.ts nextjs-fixtures.test.ts nextjs-published.test.ts nextjs-e2e-correctness.test.ts nextjs-production.test.ts"
1535
+ },
1536
+ dependencies: {
1537
+ "@rollup/pluginutils": "^5.1.0",
1538
+ "oxc-parser": "^0.110.0"
1539
+ },
1540
+ peerDependencies: {
1541
+ "@babel/core": "^7.0.0",
1542
+ next: "^13 || ^14 || ^15 || ^16",
1543
+ react: "^18 || ^19",
1544
+ svelte: "^5.0.0",
1545
+ vite: "^5 || ^6 || ^7 || ^8"
1546
+ },
1547
+ peerDependenciesMeta: {
1548
+ "@babel/core": {
1549
+ optional: true
1550
+ },
1551
+ next: {
1552
+ optional: true
1553
+ },
1554
+ svelte: {
1555
+ optional: true
1556
+ },
1557
+ vite: {
1558
+ optional: true
1559
+ }
1560
+ },
1561
+ devDependencies: {
1562
+ "@babel/core": "^7.29.0",
1563
+ "@babel/types": "^7.29.0",
1564
+ "@modules/annotation": "workspace:*",
1565
+ "@modules/file-parser": "workspace:*",
1566
+ "@modules/svelte-editor": "workspace:*",
1567
+ "@types/babel__core": "^7.20.5",
1568
+ "@types/node": "^25.0.8",
1569
+ "@types/react": "catalog:",
1570
+ "@types/react-dom": "catalog:",
1571
+ "@vitejs/plugin-react": "catalog:",
1572
+ playwright: "^1.58.2",
1573
+ "react-dom": "catalog:",
1574
+ svelte: "5.56.9",
1575
+ tsup: "^8.5.1",
1576
+ typescript: "catalog:",
1577
+ vite: "catalog:",
1578
+ vitest: "catalog:"
1579
+ }
1580
+ };
1581
+
1582
+ // release-channel.ts
1583
+ var TEMPO_SDK_CHANNEL = package_default.publishConfig.tag;
1584
+ function sdkChannelGeneration(channel) {
1585
+ if (typeof channel !== "string") return null;
1586
+ const match = /^sdk-v([1-9]\d*)-latest$/.exec(channel);
1587
+ return match ? Number(match[1]) : null;
1588
+ }
1589
+ if (sdkChannelGeneration(TEMPO_SDK_CHANNEL) === null) {
1590
+ throw new Error("tempo-sdk publishConfig.tag must be sdk-v<N>-latest");
1591
+ }
1592
+
1593
+ // host-identity.ts
262
1594
  var TEMPO_WORKSPACE_NONCE_ENV = "TEMPO_WORKSPACE_NONCE";
263
1595
  var TEMPO_WORKSPACE_NONCE_META_NAME = "tempo-workspace-nonce";
264
1596
  var WORKSPACE_NONCE_RELATIVE_PATH = ".tempo/workspace-nonce";
@@ -274,18 +1606,76 @@ function readTempoWorkspaceNonce(root = process.cwd()) {
274
1606
  if (fromEnvironment) return fromEnvironment;
275
1607
  try {
276
1608
  return normalizeWorkspaceNonce(
277
- (0, import_node_fs2.readFileSync)((0, import_node_path2.resolve)(root, WORKSPACE_NONCE_RELATIVE_PATH), "utf-8")
1609
+ (0, import_node_fs3.readFileSync)((0, import_node_path3.resolve)(root, WORKSPACE_NONCE_RELATIVE_PATH), "utf-8")
278
1610
  );
279
1611
  } catch {
280
1612
  return "";
281
1613
  }
282
1614
  }
283
1615
 
1616
+ // sdk-package-files.ts
1617
+ var import_node_fs4 = require("fs");
1618
+ var import_node_path4 = require("path");
1619
+ var SDK_PACKAGE_NAME = "tempo-sdk";
1620
+ var SDK_NODE_MODULES_SEGMENT = `/node_modules/${SDK_PACKAGE_NAME}/`;
1621
+ function createSdkFileMatcher() {
1622
+ const ownerIsSdkByDirectory = /* @__PURE__ */ new Map();
1623
+ const nearestPackageIsSdk = (startDirectory) => {
1624
+ const visited = [];
1625
+ let directory = startDirectory;
1626
+ let isSdk = false;
1627
+ while (true) {
1628
+ const cached = ownerIsSdkByDirectory.get(directory);
1629
+ if (cached !== void 0) {
1630
+ isSdk = cached;
1631
+ break;
1632
+ }
1633
+ visited.push(directory);
1634
+ const manifest = readPackageManifest(directory);
1635
+ if (manifest !== void 0) {
1636
+ isSdk = manifest?.name === SDK_PACKAGE_NAME;
1637
+ break;
1638
+ }
1639
+ const parent = (0, import_node_path4.dirname)(directory);
1640
+ if (parent === directory) break;
1641
+ directory = parent;
1642
+ }
1643
+ for (const entry of visited) ownerIsSdkByDirectory.set(entry, isSdk);
1644
+ return isSdk;
1645
+ };
1646
+ return (file) => {
1647
+ if (file.replace(/\\/g, "/").includes(SDK_NODE_MODULES_SEGMENT)) {
1648
+ return true;
1649
+ }
1650
+ let realFile = file;
1651
+ try {
1652
+ realFile = import_node_fs4.realpathSync.native(file);
1653
+ } catch {
1654
+ }
1655
+ return nearestPackageIsSdk((0, import_node_path4.dirname)(realFile));
1656
+ };
1657
+ }
1658
+ function readPackageManifest(directory) {
1659
+ let text;
1660
+ try {
1661
+ text = (0, import_node_fs4.readFileSync)((0, import_node_path4.join)(directory, "package.json"), "utf8");
1662
+ } catch {
1663
+ return void 0;
1664
+ }
1665
+ try {
1666
+ const manifest = JSON.parse(text);
1667
+ return manifest && typeof manifest === "object" ? manifest : null;
1668
+ } catch {
1669
+ return null;
1670
+ }
1671
+ }
1672
+
284
1673
  // nextjs-loader.ts
285
1674
  var ROOT_META_NAME = "tempo-project-root";
286
1675
  var cachedCanonicalRoot = null;
287
1676
  var cachedUserComputeProps;
288
1677
  var cachedComputeModulePath = null;
1678
+ var isSdkFile = createSdkFileMatcher();
289
1679
  function _resetLoaderState() {
290
1680
  cachedCanonicalRoot = null;
291
1681
  cachedUserComputeProps = void 0;
@@ -301,17 +1691,17 @@ function stripQueryAndHash(path) {
301
1691
  }
302
1692
  function resolveCanonicalRoot(rootContext) {
303
1693
  try {
304
- return import_node_fs3.realpathSync.native(rootContext);
1694
+ return import_node_fs5.realpathSync.native(rootContext);
305
1695
  } catch {
306
1696
  return rootContext;
307
1697
  }
308
1698
  }
309
1699
  function isInNodeModules(path) {
310
- return path.includes(`${import_node_path3.sep}node_modules${import_node_path3.sep}`);
1700
+ return path.includes(`${import_node_path5.sep}node_modules${import_node_path5.sep}`);
311
1701
  }
312
1702
  function findFirstJSXElement(program, tagName) {
313
1703
  let result = null;
314
- walk(program, {
1704
+ walk2(program, {
315
1705
  JSXElement(node) {
316
1706
  if (result) return;
317
1707
  const element = node;
@@ -351,7 +1741,7 @@ function injectFirstChildMarkup(source, element, childMarkup) {
351
1741
  function injectRootMetaIntoSource(source, filename, root) {
352
1742
  let parseResult;
353
1743
  try {
354
- parseResult = (0, import_oxc_parser3.parseSync)(filename, source);
1744
+ parseResult = (0, import_oxc_parser4.parseSync)(filename, source);
355
1745
  } catch {
356
1746
  return source;
357
1747
  }
@@ -383,7 +1773,7 @@ function injectRootMetaIntoAnnotatedSource(annotatedSource, filename, root) {
383
1773
  return injectRootMetaIntoSource(annotatedSource, filename, root);
384
1774
  }
385
1775
  function loadUserComputeProps(modulePath, canonicalRoot) {
386
- const resolved = (0, import_node_path3.resolve)(canonicalRoot, modulePath);
1776
+ const resolved = (0, import_node_path5.resolve)(canonicalRoot, modulePath);
387
1777
  const requireFromRoot = (0, import_node_module.createRequire)(`${canonicalRoot}/__tempo_loader__.js`);
388
1778
  const mod = requireFromRoot(resolved);
389
1779
  const fn = mod && (mod.default ?? mod);
@@ -406,7 +1796,7 @@ function nextjsLoader(source) {
406
1796
  if (!process.env.TEMPO) return source;
407
1797
  const cleanPath = stripQueryAndHash(this.resourcePath ?? "");
408
1798
  if (!/\.(tsx|jsx)$/.test(cleanPath)) return source;
409
- if (isInNodeModules(cleanPath)) return source;
1799
+ if (isInNodeModules(cleanPath) || isSdkFile(cleanPath)) return source;
410
1800
  const options = readOptions.call(this);
411
1801
  try {
412
1802
  if (cachedCanonicalRoot === null) {
@@ -428,20 +1818,22 @@ function nextjsLoader(source) {
428
1818
  cachedUserComputeProps = null;
429
1819
  }
430
1820
  const userComputeProps = cachedUserComputeProps;
431
- const filepath = (0, import_node_path3.relative)(canonicalRoot, cleanPath);
432
- const modifiedtsMs = Math.trunc((0, import_node_fs3.statSync)(cleanPath).mtimeMs);
1821
+ const filepath = (0, import_node_path5.relative)(canonicalRoot, cleanPath);
1822
+ const modifiedtsMs = Math.trunc((0, import_node_fs5.statSync)(cleanPath).mtimeMs);
433
1823
  const sourceVersion = sourceVersionHash(source);
434
- const annotated = annotateFile(
435
- source,
436
- cleanPath,
437
- (info) => computeTempoAnnotatedProps({
1824
+ const componentReferences = canvasComponentAnnotations(cleanPath, source);
1825
+ const annotated = annotateFile(source, cleanPath, (info) => ({
1826
+ ...componentReferences.get(
1827
+ info.element.openingElement.start
1828
+ ),
1829
+ ...computeTempoAnnotatedProps({
438
1830
  info,
439
1831
  filepath,
440
1832
  modifiedtsMs,
441
1833
  sourceVersion,
442
1834
  computeAnnotatedProps: userComputeProps ?? void 0
443
1835
  })
444
- );
1836
+ }));
445
1837
  let finalSource = annotated.annotatedSource;
446
1838
  if (options.autoInjectRootMeta !== false) {
447
1839
  finalSource = injectRootMetaIntoAnnotatedSource(
@@ -450,8 +1842,13 @@ function nextjsLoader(source) {
450
1842
  canonicalRoot
451
1843
  );
452
1844
  }
453
- if (finalSource === source) return source;
454
- return finalSource;
1845
+ if (annotated.parseResult.errors.length > 0) return source;
1846
+ return appendModuleVersionRecord(
1847
+ finalSource,
1848
+ filepath,
1849
+ modifiedtsMs,
1850
+ sourceVersion
1851
+ );
455
1852
  } catch {
456
1853
  return source;
457
1854
  }