tempo-sdk 0.0.16 → 0.0.19

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 (71) hide show
  1. package/dist/assets/editor.d.ts +79 -0
  2. package/dist/assets/editor.js +571 -0
  3. package/dist/assets/editor.js.map +1 -0
  4. package/dist/assets/index.d.ts +83 -0
  5. package/dist/assets/index.js +26 -0
  6. package/dist/assets/index.js.map +1 -0
  7. package/dist/assets/parser.d.ts +78 -0
  8. package/dist/assets/parser.js +29 -0
  9. package/dist/assets/parser.js.map +1 -0
  10. package/dist/canvas/editor.d.ts +44 -9
  11. package/dist/canvas/editor.js +116 -416
  12. package/dist/canvas/editor.js.map +1 -1
  13. package/dist/canvas/index.d.ts +1 -0
  14. package/dist/canvas/index.js +237 -56
  15. package/dist/canvas/index.js.map +1 -1
  16. package/dist/canvas/parser.d.ts +25 -2
  17. package/dist/canvas/parser.js +3 -3
  18. package/dist/{chunk-77BNMPBS.js → chunk-CB5NJJJT.js} +31 -5
  19. package/dist/chunk-CB5NJJJT.js.map +1 -0
  20. package/dist/chunk-IWULHYPW.js +650 -0
  21. package/dist/chunk-IWULHYPW.js.map +1 -0
  22. package/dist/{chunk-ICP7LCPJ.js → chunk-P277UVZE.js} +279 -40
  23. package/dist/chunk-P277UVZE.js.map +1 -0
  24. package/dist/expo/plugin.cjs +30 -4
  25. package/dist/expo/plugin.cjs.map +1 -1
  26. package/dist/expo/plugin.js +1 -1
  27. package/dist/expo-babel-plugin.cjs +30 -4
  28. package/dist/expo-babel-plugin.cjs.map +1 -1
  29. package/dist/expo-babel-plugin.d.cts +1 -1
  30. package/dist/expo-babel-plugin.d.ts +1 -1
  31. package/dist/expo-babel-plugin.js +1 -1
  32. package/dist/index.js +26 -6
  33. package/dist/index.js.map +1 -1
  34. package/dist/nextjs-loader.cjs +29 -4
  35. package/dist/nextjs-loader.cjs.map +1 -1
  36. package/dist/types-B-dRoF2T.d.ts +102 -0
  37. package/package.json +16 -3
  38. package/dist/annotation-strategy-DCJHc--2.d.cts +0 -13
  39. package/dist/annotation-strategy-DCJHc--2.d.ts +0 -13
  40. package/dist/chunk-2LP5G6CD.js +0 -748
  41. package/dist/chunk-2LP5G6CD.js.map +0 -1
  42. package/dist/chunk-77BNMPBS.js.map +0 -1
  43. package/dist/chunk-B3PHU7XX.js +0 -571
  44. package/dist/chunk-B3PHU7XX.js.map +0 -1
  45. package/dist/chunk-EJBWZCEE.js +0 -434
  46. package/dist/chunk-EJBWZCEE.js.map +0 -1
  47. package/dist/chunk-F64WRL4H.js +0 -884
  48. package/dist/chunk-F64WRL4H.js.map +0 -1
  49. package/dist/chunk-G7M57ARC.js +0 -902
  50. package/dist/chunk-G7M57ARC.js.map +0 -1
  51. package/dist/chunk-GHPL4LGE.js +0 -205
  52. package/dist/chunk-GHPL4LGE.js.map +0 -1
  53. package/dist/chunk-ICP7LCPJ.js.map +0 -1
  54. package/dist/chunk-IG3JZVZI.js +0 -846
  55. package/dist/chunk-IG3JZVZI.js.map +0 -1
  56. package/dist/chunk-MBTLXFNP.js +0 -605
  57. package/dist/chunk-MBTLXFNP.js.map +0 -1
  58. package/dist/chunk-MD3HJ7L3.js +0 -457
  59. package/dist/chunk-MD3HJ7L3.js.map +0 -1
  60. package/dist/chunk-O3HYJ6BU.js +0 -433
  61. package/dist/chunk-O3HYJ6BU.js.map +0 -1
  62. package/dist/chunk-WGGLHHC5.js +0 -337
  63. package/dist/chunk-WGGLHHC5.js.map +0 -1
  64. package/dist/chunk-X3K7Z2BH.js +0 -900
  65. package/dist/chunk-X3K7Z2BH.js.map +0 -1
  66. package/dist/chunk-ZHORRCQG.js +0 -756
  67. package/dist/chunk-ZHORRCQG.js.map +0 -1
  68. package/dist/index.cjs +0 -1170
  69. package/dist/index.cjs.map +0 -1
  70. package/dist/index.d.cts +0 -99
  71. package/dist/page-BokkL6FZ.d.ts +0 -35
@@ -1,605 +0,0 @@
1
- // canvas/parser.ts
2
- import { parseSync } from "oxc-parser";
3
- var SDK_IMPORT_SOURCES = /* @__PURE__ */ new Set(["tempo-sdk/canvas"]);
4
- var SDK_COMPONENTS = /* @__PURE__ */ new Set([
5
- "Canvas",
6
- "Storyboard",
7
- "LegacyStoryboardV1",
8
- "RouteStoryboard",
9
- "HtmlStoryboard"
10
- ]);
11
- var DEFAULT_LAYOUT = {
12
- x: 0,
13
- y: 0,
14
- width: 600,
15
- height: 400
16
- };
17
- function parseCanvasFile(filePath, source) {
18
- const errors = [];
19
- let program;
20
- try {
21
- const result = parseSync(filePath, source);
22
- program = result.program;
23
- for (const error of result.errors ?? []) {
24
- errors.push({
25
- message: error.message ?? "Unable to parse canvas source",
26
- span: toSpan(error) ?? toSpan(error?.labels?.[0])
27
- });
28
- }
29
- } catch (error) {
30
- return {
31
- filePath,
32
- pageName: fallbackPageName(filePath),
33
- imports: [],
34
- storyboards: [],
35
- errors: [
36
- {
37
- message: error instanceof Error ? error.message : "Unable to parse canvas source"
38
- }
39
- ]
40
- };
41
- }
42
- const imports = readImports(program);
43
- const legacyObjects = readLegacyStoryboardObjects(program);
44
- const objectStringBindings = readObjectStringBindings(program);
45
- const storyboards = [];
46
- let canvasElement = null;
47
- walk(program, (node) => {
48
- if (node.type !== "JSXElement") return;
49
- const component = resolveSdkComponent(node.openingElement?.name, imports);
50
- if (component === "Canvas" && !canvasElement) {
51
- canvasElement = node;
52
- return;
53
- }
54
- if (component === "Storyboard" || component === "LegacyStoryboardV1" || component === "RouteStoryboard" || component === "HtmlStoryboard") {
55
- storyboards.push(
56
- readStoryboard(node, component, imports, legacyObjects, source, errors)
57
- );
58
- }
59
- });
60
- if (!canvasElement) {
61
- errors.push({ message: "No <Canvas> declaration found in canvas file" });
62
- } else {
63
- errors.push(...validateCanvasChildren(canvasElement, imports));
64
- }
65
- const openingElement = canvasElement?.openingElement;
66
- const name = readResolvableStringAttribute(
67
- openingElement,
68
- "name",
69
- objectStringBindings
70
- );
71
- const path = readStringAttribute(openingElement, "path");
72
- const backgroundColor = readResolvableStringAttribute(
73
- openingElement,
74
- "backgroundColor",
75
- objectStringBindings
76
- ) ?? readResolvableStringAttribute(openingElement, "background", objectStringBindings);
77
- if (openingElement && !name) {
78
- errors.push({
79
- message: '<Canvas> must include a literal "name" prop',
80
- span: toSpan(openingElement)
81
- });
82
- }
83
- return {
84
- filePath,
85
- canvasPath: path?.value,
86
- pageName: name?.value ?? fallbackPageName(filePath),
87
- backgroundColor: backgroundColor?.value,
88
- canvasElementSpan: toSpan(canvasElement),
89
- canvasOpeningElementSpan: toSpan(openingElement),
90
- canvasChildrenInsertionOffset: typeof canvasElement?.closingElement?.start === "number" ? canvasElement.closingElement.start : void 0,
91
- nameSpan: name?.valueSpan,
92
- nameAttributeSpan: name?.attributeSpan,
93
- pathSpan: path?.valueSpan,
94
- pathAttributeSpan: path?.attributeSpan,
95
- backgroundColorSpan: backgroundColor?.valueSpan,
96
- backgroundColorAttributeSpan: backgroundColor?.attributeSpan,
97
- imports: imports.all,
98
- storyboards,
99
- errors
100
- };
101
- }
102
- var parseCanvasSource = parseCanvasFile;
103
- function readImports(program) {
104
- const all = [];
105
- const byLocalName = /* @__PURE__ */ new Map();
106
- const sdkLocalNames = /* @__PURE__ */ new Map();
107
- const sdkNamespaces = /* @__PURE__ */ new Set();
108
- for (const statement of program?.body ?? []) {
109
- if (statement?.type !== "ImportDeclaration" || typeof statement.source?.value !== "string") {
110
- continue;
111
- }
112
- const source = statement.source.value;
113
- const isSdkImport = isSdkImportSource(source);
114
- for (const specifier of statement.specifiers ?? []) {
115
- const localName = specifier.local?.name;
116
- if (typeof localName !== "string") continue;
117
- const importedName = readImportedName(specifier);
118
- const imported = {
119
- localName,
120
- source,
121
- importedName,
122
- kind: readImportKind(specifier),
123
- importKind: specifier.importKind === "type" ? "type" : "value",
124
- span: toSpan(specifier) ?? toSpan(statement) ?? { start: 0, end: 0 },
125
- declarationSpan: toSpan(statement) ?? { start: 0, end: 0 },
126
- specifierCount: statement.specifiers?.length ?? 0,
127
- namedSpecifierCount: (statement.specifiers ?? []).filter(
128
- (item) => item?.type === "ImportSpecifier"
129
- ).length,
130
- hasDefaultSpecifier: (statement.specifiers ?? []).some(
131
- (item) => item?.type === "ImportDefaultSpecifier"
132
- ),
133
- hasNamespaceSpecifier: (statement.specifiers ?? []).some(
134
- (item) => item?.type === "ImportNamespaceSpecifier"
135
- )
136
- };
137
- all.push(imported);
138
- byLocalName.set(localName, imported);
139
- if (!isSdkImport) continue;
140
- if (specifier.type === "ImportNamespaceSpecifier") {
141
- sdkNamespaces.add(localName);
142
- continue;
143
- }
144
- if (SDK_COMPONENTS.has(importedName)) {
145
- sdkLocalNames.set(localName, importedName);
146
- }
147
- }
148
- }
149
- return { all, byLocalName, sdkLocalNames, sdkNamespaces };
150
- }
151
- function readLegacyStoryboardObjects(program) {
152
- const objects = /* @__PURE__ */ new Map();
153
- walk(program, (node) => {
154
- if (node?.type !== "VariableDeclarator" || node.id?.type !== "Identifier" || unwrapTsExpression(node.init)?.type !== "ObjectExpression") {
155
- return;
156
- }
157
- const bindingName = node.id.name;
158
- const objectExpression = unwrapTsExpression(node.init);
159
- const errors = [];
160
- const nameProperty = getObjectProperty(objectExpression, "name");
161
- const name = nameProperty ? readStringLiteralValue(nameProperty.value) : null;
162
- const layoutProperty = getObjectProperty(objectExpression, "layout");
163
- const layout = layoutProperty ? readLayoutExpression(layoutProperty.value, "LegacyStoryboardV1") : {
164
- value: DEFAULT_LAYOUT,
165
- errors: [
166
- {
167
- message: '<LegacyStoryboardV1> storyboard object must include a literal "layout" object',
168
- span: toSpan(objectExpression)
169
- }
170
- ]
171
- };
172
- if (nameProperty && !name) {
173
- errors.push({
174
- message: "<LegacyStoryboardV1> storyboard.name must be a string literal when set",
175
- span: toSpan(nameProperty)
176
- });
177
- }
178
- errors.push(...layout.errors);
179
- objects.set(bindingName, {
180
- bindingName,
181
- displayName: name?.value,
182
- objectSpan: toSpan(objectExpression),
183
- objectClose: readLayoutClose(objectExpression),
184
- nameSpan: name?.span,
185
- namePropertySpan: toSpan(nameProperty),
186
- layoutPropertySpan: toSpan(layoutProperty),
187
- layout: layout.value,
188
- layoutSpans: layout.spans,
189
- errors
190
- });
191
- });
192
- return objects;
193
- }
194
- function readObjectStringBindings(program) {
195
- const bindings = /* @__PURE__ */ new Map();
196
- walk(program, (node) => {
197
- if (node?.type !== "VariableDeclarator" || node.id?.type !== "Identifier" || unwrapTsExpression(node.init)?.type !== "ObjectExpression") {
198
- return;
199
- }
200
- const objectExpression = unwrapTsExpression(node.init);
201
- const properties = /* @__PURE__ */ new Map();
202
- for (const property of objectExpression.properties ?? []) {
203
- if (property?.type !== "Property" || property.computed) continue;
204
- const propertyName = property.key?.type === "Identifier" ? property.key.name : property.key?.type === "Literal" && typeof property.key.value === "string" ? property.key.value : null;
205
- const value = readStringLiteralValue(property.value);
206
- if (!propertyName || !value) continue;
207
- properties.set(propertyName, value);
208
- }
209
- if (properties.size > 0) {
210
- bindings.set(node.id.name, properties);
211
- }
212
- });
213
- return bindings;
214
- }
215
- function readStoryboard(element, component, imports, legacyObjects, source, globalErrors) {
216
- const openingElement = element.openingElement;
217
- const errors = [];
218
- const id = readStringAttribute(openingElement, "id");
219
- const name = readStringAttribute(openingElement, "name");
220
- const legacyReference = component === "LegacyStoryboardV1" ? readExpressionReference(openingElement, "storyboard", source) : void 0;
221
- const legacyObject = legacyReference?.expression && isIdentifierExpression(legacyReference.expression) ? legacyObjects.get(legacyReference.expression) : void 0;
222
- const layout = component === "LegacyStoryboardV1" ? {
223
- value: legacyObject?.layout ?? DEFAULT_LAYOUT,
224
- spans: legacyObject?.layoutSpans,
225
- attributeSpan: void 0,
226
- errors: legacyObject?.errors ?? (legacyReference ? [
227
- {
228
- message: "<LegacyStoryboardV1> storyboard prop must reference a same-file object literal",
229
- span: legacyReference.span
230
- }
231
- ] : [
232
- {
233
- message: '<LegacyStoryboardV1> must include a "storyboard" expression prop',
234
- span: toSpan(openingElement)
235
- }
236
- ])
237
- } : readLayout(openingElement, component);
238
- const kind = component === "Storyboard" || component === "LegacyStoryboardV1" ? "component" : component === "RouteStoryboard" ? "route" : "html";
239
- if (!id) {
240
- errors.push({
241
- message: `<${component}> must include a literal "id" prop`,
242
- span: toSpan(openingElement)
243
- });
244
- }
245
- if (layout.errors.length > 0) {
246
- errors.push(...layout.errors);
247
- }
248
- const storyboard = {
249
- storyboardKey: id?.value ?? "",
250
- displayName: name?.value ?? legacyObject?.displayName,
251
- kind,
252
- layout: layout.value,
253
- editable: Boolean(id) && layout.errors.length === 0,
254
- jsxElementSpan: toSpan(element) ?? { start: 0, end: 0 },
255
- openingElementSpan: toSpan(openingElement),
256
- idSpan: id?.valueSpan,
257
- idAttributeSpan: id?.attributeSpan,
258
- nameSpan: name?.valueSpan ?? legacyObject?.nameSpan,
259
- nameAttributeSpan: name?.attributeSpan ?? legacyObject?.namePropertySpan,
260
- layoutAttributeSpan: layout.attributeSpan,
261
- layoutSpans: layout.spans,
262
- props: readExpressionReference(openingElement, "props", source),
263
- legacyV1: legacyReference ? {
264
- storyboard: legacyReference,
265
- objectName: legacyObject?.bindingName,
266
- objectSpan: legacyObject?.objectSpan,
267
- objectClose: legacyObject?.objectClose,
268
- namePropertySpan: legacyObject?.namePropertySpan,
269
- layoutPropertySpan: legacyObject?.layoutPropertySpan
270
- } : void 0,
271
- errors
272
- };
273
- if (component === "Storyboard") {
274
- const componentReference = readComponentReference(
275
- openingElement,
276
- imports,
277
- source
278
- );
279
- if (componentReference) {
280
- storyboard.component = componentReference;
281
- } else {
282
- errors.push({
283
- message: '<Storyboard> must include a "component" expression prop',
284
- span: toSpan(openingElement)
285
- });
286
- }
287
- }
288
- if (component === "RouteStoryboard") {
289
- const route = readStringAttribute(openingElement, "route");
290
- if (route) {
291
- storyboard.route = route.value;
292
- storyboard.routeSpan = route.valueSpan;
293
- storyboard.routeAttributeSpan = route.attributeSpan;
294
- } else {
295
- errors.push({
296
- message: '<RouteStoryboard> must include a literal "route" prop',
297
- span: toSpan(openingElement)
298
- });
299
- }
300
- }
301
- if (component === "HtmlStoryboard") {
302
- const filepath = readStringAttribute(openingElement, "filepath");
303
- const src = readStringAttribute(openingElement, "src");
304
- storyboard.filepath = filepath?.value;
305
- storyboard.filepathSpan = filepath?.valueSpan;
306
- storyboard.filepathAttributeSpan = filepath?.attributeSpan;
307
- storyboard.src = src?.value;
308
- storyboard.srcSpan = src?.valueSpan;
309
- storyboard.srcAttributeSpan = src?.attributeSpan;
310
- if (!filepath && !src) {
311
- errors.push({
312
- message: '<HtmlStoryboard> must include a literal "filepath" or "src" prop',
313
- span: toSpan(openingElement)
314
- });
315
- }
316
- }
317
- globalErrors.push(...errors);
318
- return storyboard;
319
- }
320
- function validateCanvasChildren(canvasElement, imports) {
321
- const errors = [];
322
- for (const child of canvasElement.children ?? []) {
323
- if (!child) continue;
324
- if (child.type === "JSXText") {
325
- if (typeof child.value === "string" && child.value.trim() === "") {
326
- continue;
327
- }
328
- }
329
- if (child.type === "JSXExpressionContainer") {
330
- if (child.expression?.type === "JSXEmptyExpression") {
331
- continue;
332
- }
333
- errors.push({
334
- message: "<Canvas> children must be static storyboard declarations, not expressions",
335
- span: toSpan(child)
336
- });
337
- continue;
338
- }
339
- if (child.type === "JSXElement") {
340
- const component = resolveSdkComponent(child.openingElement?.name, imports);
341
- if (component === "Storyboard" || component === "LegacyStoryboardV1" || component === "RouteStoryboard" || component === "HtmlStoryboard") {
342
- continue;
343
- }
344
- }
345
- errors.push({
346
- message: "<Canvas> children must be <Storyboard>, <RouteStoryboard>, <HtmlStoryboard>, or <LegacyStoryboardV1> declarations",
347
- span: toSpan(child)
348
- });
349
- }
350
- return errors;
351
- }
352
- function readComponentReference(openingElement, imports, source) {
353
- const attribute = getAttribute(openingElement, "component");
354
- const expression = unwrapAttributeExpression(attribute?.value);
355
- const span = toSpan(expression);
356
- if (!expression || !span) return null;
357
- const localName = expression.type === "Identifier" ? expression.name : expression.type === "MemberExpression" && expression.object?.type === "Identifier" ? expression.object.name : void 0;
358
- return {
359
- expression: source.slice(span.start, span.end),
360
- span,
361
- attributeSpan: toSpan(attribute),
362
- localName,
363
- import: localName ? imports.byLocalName.get(localName) : void 0
364
- };
365
- }
366
- function readExpressionReference(openingElement, name, source) {
367
- const attribute = getAttribute(openingElement, name);
368
- const expression = unwrapAttributeExpression(attribute?.value);
369
- const span = toSpan(expression);
370
- if (!expression || !span) return void 0;
371
- return {
372
- expression: source.slice(span.start, span.end),
373
- span,
374
- attributeSpan: toSpan(attribute)
375
- };
376
- }
377
- function isIdentifierExpression(expression) {
378
- return /^[A-Za-z_$][\w$]*$/.test(expression);
379
- }
380
- function readLayout(openingElement, componentName) {
381
- const errors = [];
382
- const attribute = getAttribute(openingElement, "layout");
383
- const expression = unwrapAttributeExpression(attribute?.value);
384
- if (!expression) {
385
- return {
386
- value: DEFAULT_LAYOUT,
387
- attributeSpan: toSpan(attribute),
388
- errors: [
389
- {
390
- message: `<${componentName}> must include a literal "layout" object prop`,
391
- span: toSpan(openingElement)
392
- }
393
- ]
394
- };
395
- }
396
- const layout = readLayoutExpression(expression, componentName);
397
- return {
398
- ...layout,
399
- attributeSpan: toSpan(attribute)
400
- };
401
- }
402
- function readLayoutExpression(expression, componentName) {
403
- const errors = [];
404
- if (expression.type !== "ObjectExpression") {
405
- return {
406
- value: DEFAULT_LAYOUT,
407
- spans: { layoutClose: readLayoutClose(expression) },
408
- errors: [
409
- {
410
- message: `<${componentName}> layout must be an object literal`,
411
- span: toSpan(expression)
412
- }
413
- ]
414
- };
415
- }
416
- const spans = {
417
- layoutClose: readLayoutClose(expression)
418
- };
419
- const layout = { ...DEFAULT_LAYOUT };
420
- for (const key of ["x", "y", "width", "height"]) {
421
- const property = getObjectProperty(expression, key);
422
- const value = property ? readNumberLiteral(property.value) : null;
423
- if (value) {
424
- layout[key] = value.value;
425
- spans[key] = value.span;
426
- } else {
427
- errors.push({
428
- message: `<${componentName}> layout.${key} must be a number literal`,
429
- span: toSpan(property ?? expression)
430
- });
431
- }
432
- }
433
- const zIndex = getObjectProperty(expression, "zIndex");
434
- if (zIndex) {
435
- const value = readNumberLiteral(zIndex.value);
436
- if (value) {
437
- layout.zIndex = value.value;
438
- spans.zIndex = value.span;
439
- } else {
440
- errors.push({
441
- message: `<${componentName}> layout.zIndex must be a number literal`,
442
- span: toSpan(zIndex)
443
- });
444
- }
445
- }
446
- const intrinsicSizing = getObjectProperty(expression, "intrinsicSizing");
447
- if (intrinsicSizing) {
448
- if (intrinsicSizing.value?.type === "Literal" && intrinsicSizing.value.value === "root-element") {
449
- layout.intrinsicSizing = "root-element";
450
- spans.intrinsicSizing = toSpan(intrinsicSizing.value);
451
- } else {
452
- errors.push({
453
- message: `<${componentName}> layout.intrinsicSizing must be "root-element" when set`,
454
- span: toSpan(intrinsicSizing)
455
- });
456
- }
457
- }
458
- return { value: layout, spans, errors };
459
- }
460
- function readStringLiteralValue(node) {
461
- return node?.type === "Literal" && typeof node.value === "string" ? { value: node.value, span: toSpan(node) ?? { start: 0, end: 0 } } : null;
462
- }
463
- function unwrapTsExpression(node) {
464
- let current = node;
465
- while (current?.type === "TSSatisfiesExpression" || current?.type === "TSAsExpression" || current?.type === "TSNonNullExpression" || current?.type === "ParenthesizedExpression") {
466
- current = current.expression;
467
- }
468
- return current;
469
- }
470
- function readResolvableStringAttribute(openingElement, name, bindings) {
471
- const literal = readStringAttribute(openingElement, name);
472
- if (literal) return literal;
473
- const attribute = getAttribute(openingElement, name);
474
- const expression = unwrapAttributeExpression(attribute?.value);
475
- const expressionSpan = toSpan(expression);
476
- const attributeSpan = toSpan(attribute);
477
- if (!expression || !expressionSpan || !attributeSpan) return null;
478
- const resolved = resolveStringMemberExpression(expression, bindings);
479
- return resolved ? {
480
- value: resolved.value,
481
- valueSpan: expressionSpan,
482
- attributeSpan
483
- } : null;
484
- }
485
- function resolveStringMemberExpression(expression, bindings) {
486
- if (expression?.type !== "MemberExpression") return null;
487
- if (expression.object?.type !== "Identifier") return null;
488
- const propertyName = expression.property?.type === "Identifier" ? expression.property.name : expression.property?.type === "Literal" && typeof expression.property.value === "string" ? expression.property.value : null;
489
- if (!propertyName) return null;
490
- return bindings.get(expression.object.name)?.get(propertyName) ?? null;
491
- }
492
- function readStringAttribute(openingElement, name) {
493
- const attribute = getAttribute(openingElement, name);
494
- if (!attribute) return null;
495
- const value = attribute.value;
496
- if (value?.type === "Literal" && typeof value.value === "string") {
497
- return {
498
- value: value.value,
499
- valueSpan: toSpan(value) ?? toSpan(attribute) ?? { start: 0, end: 0 },
500
- attributeSpan: toSpan(attribute) ?? { start: 0, end: 0 }
501
- };
502
- }
503
- const expression = unwrapAttributeExpression(value);
504
- if (expression?.type === "Literal" && typeof expression.value === "string") {
505
- return {
506
- value: expression.value,
507
- valueSpan: toSpan(expression) ?? toSpan(attribute) ?? { start: 0, end: 0 },
508
- attributeSpan: toSpan(attribute) ?? { start: 0, end: 0 }
509
- };
510
- }
511
- return null;
512
- }
513
- function getAttribute(openingElement, name) {
514
- for (const attribute of openingElement?.attributes ?? []) {
515
- if (attribute?.type === "JSXAttribute" && attribute.name?.type === "JSXIdentifier" && attribute.name.name === name) {
516
- return attribute;
517
- }
518
- }
519
- return null;
520
- }
521
- function unwrapAttributeExpression(value) {
522
- if (!value) return null;
523
- if (value.type === "JSXExpressionContainer") {
524
- return value.expression;
525
- }
526
- return value;
527
- }
528
- function getObjectProperty(objectExpression, name) {
529
- if (objectExpression?.type !== "ObjectExpression") return null;
530
- for (const property of objectExpression.properties ?? []) {
531
- if (property?.type !== "Property" || property.computed) continue;
532
- const propertyName = property.key?.type === "Identifier" ? property.key.name : property.key?.type === "Literal" && typeof property.key.value === "string" ? property.key.value : null;
533
- if (propertyName === name) return property;
534
- }
535
- return null;
536
- }
537
- function readNumberLiteral(node) {
538
- if (node?.type === "Literal" && typeof node.value === "number" && Number.isFinite(node.value)) {
539
- return { value: node.value, span: toSpan(node) ?? { start: 0, end: 0 } };
540
- }
541
- if (node?.type === "UnaryExpression" && node.operator === "-" && node.argument?.type === "Literal" && typeof node.argument.value === "number" && Number.isFinite(node.argument.value)) {
542
- return {
543
- value: -node.argument.value,
544
- span: toSpan(node) ?? { start: 0, end: 0 }
545
- };
546
- }
547
- return null;
548
- }
549
- function resolveSdkComponent(nameNode, imports) {
550
- if (nameNode?.type === "JSXIdentifier") {
551
- return imports.sdkLocalNames.get(nameNode.name) ?? null;
552
- }
553
- if (nameNode?.type === "JSXMemberExpression" && nameNode.object?.type === "JSXIdentifier" && nameNode.property?.type === "JSXIdentifier" && imports.sdkNamespaces.has(nameNode.object.name) && SDK_COMPONENTS.has(nameNode.property.name)) {
554
- return nameNode.property.name;
555
- }
556
- return null;
557
- }
558
- function readImportedName(specifier) {
559
- if (specifier.type === "ImportDefaultSpecifier") return "default";
560
- if (specifier.type === "ImportNamespaceSpecifier") return "*";
561
- return specifier.imported?.name ?? specifier.local?.name ?? "unknown";
562
- }
563
- function readImportKind(specifier) {
564
- if (specifier.type === "ImportDefaultSpecifier") return "default";
565
- if (specifier.type === "ImportNamespaceSpecifier") return "namespace";
566
- return "named";
567
- }
568
- function isSdkImportSource(source) {
569
- return SDK_IMPORT_SOURCES.has(source) || source.endsWith("/tempo-sdk/canvas");
570
- }
571
- function readLayoutClose(node) {
572
- return typeof node?.end === "number" && Number.isFinite(node.end) ? node.end - 1 : void 0;
573
- }
574
- function fallbackPageName(filePath) {
575
- const normalized = filePath.replace(/\\/g, "/");
576
- const segments = normalized.split("/").filter(Boolean);
577
- const fileName = segments.length > 0 ? segments[segments.length - 1] : filePath;
578
- const parentName = segments.length > 1 ? segments[segments.length - 2] : fileName;
579
- const baseName = /^index\.canvas\.[tj]sx?$/.test(fileName) ? parentName : fileName.replace(/\.canvas\.[tj]sx?$/, "");
580
- return baseName.split(/[-_\s]+/).filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
581
- }
582
- function toSpan(node) {
583
- 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;
584
- }
585
- function walk(node, visitor, seen = /* @__PURE__ */ new Set()) {
586
- if (!node || typeof node !== "object" || seen.has(node)) return;
587
- seen.add(node);
588
- visitor(node);
589
- for (const value of Object.values(node)) {
590
- if (!value) continue;
591
- if (Array.isArray(value)) {
592
- for (const item of value) {
593
- walk(item, visitor, seen);
594
- }
595
- } else if (typeof value === "object") {
596
- walk(value, visitor, seen);
597
- }
598
- }
599
- }
600
-
601
- export {
602
- parseCanvasFile,
603
- parseCanvasSource
604
- };
605
- //# sourceMappingURL=chunk-MBTLXFNP.js.map