tempo-sdk 0.0.14 → 0.0.16

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 (56) hide show
  1. package/dist/annotation-strategy-DCJHc--2.d.cts +13 -0
  2. package/dist/annotation-strategy-DCJHc--2.d.ts +13 -0
  3. package/dist/canvas/editor.d.ts +129 -0
  4. package/dist/canvas/editor.js +1198 -0
  5. package/dist/canvas/editor.js.map +1 -0
  6. package/dist/canvas/index.d.ts +173 -0
  7. package/dist/canvas/index.js +2193 -0
  8. package/dist/canvas/index.js.map +1 -0
  9. package/dist/canvas/parser.d.ts +109 -0
  10. package/dist/canvas/parser.js +13 -0
  11. package/dist/canvas/parser.js.map +1 -0
  12. package/dist/chunk-2LP5G6CD.js +748 -0
  13. package/dist/chunk-2LP5G6CD.js.map +1 -0
  14. package/dist/chunk-77BNMPBS.js +319 -0
  15. package/dist/chunk-77BNMPBS.js.map +1 -0
  16. package/dist/chunk-B3PHU7XX.js +571 -0
  17. package/dist/chunk-B3PHU7XX.js.map +1 -0
  18. package/dist/chunk-EJBWZCEE.js +434 -0
  19. package/dist/chunk-EJBWZCEE.js.map +1 -0
  20. package/dist/chunk-F64WRL4H.js +884 -0
  21. package/dist/chunk-F64WRL4H.js.map +1 -0
  22. package/dist/chunk-GHPL4LGE.js +205 -0
  23. package/dist/chunk-GHPL4LGE.js.map +1 -0
  24. package/dist/chunk-ICP7LCPJ.js +615 -0
  25. package/dist/chunk-ICP7LCPJ.js.map +1 -0
  26. package/dist/chunk-IG3JZVZI.js +846 -0
  27. package/dist/chunk-IG3JZVZI.js.map +1 -0
  28. package/dist/chunk-MBTLXFNP.js +605 -0
  29. package/dist/chunk-MBTLXFNP.js.map +1 -0
  30. package/dist/chunk-MD3HJ7L3.js +457 -0
  31. package/dist/chunk-MD3HJ7L3.js.map +1 -0
  32. package/dist/chunk-O3HYJ6BU.js +433 -0
  33. package/dist/chunk-O3HYJ6BU.js.map +1 -0
  34. package/dist/chunk-X3K7Z2BH.js +900 -0
  35. package/dist/chunk-X3K7Z2BH.js.map +1 -0
  36. package/dist/chunk-ZHORRCQG.js +756 -0
  37. package/dist/chunk-ZHORRCQG.js.map +1 -0
  38. package/dist/expo/plugin.cjs +4 -22
  39. package/dist/expo/plugin.cjs.map +1 -1
  40. package/dist/expo/plugin.js +1 -1
  41. package/dist/expo-babel-plugin.cjs +4 -22
  42. package/dist/expo-babel-plugin.cjs.map +1 -1
  43. package/dist/expo-babel-plugin.d.cts +0 -6
  44. package/dist/expo-babel-plugin.d.ts +0 -6
  45. package/dist/expo-babel-plugin.js +1 -1
  46. package/dist/index.cjs +1170 -0
  47. package/dist/index.cjs.map +1 -0
  48. package/dist/index.d.cts +99 -0
  49. package/dist/index.d.ts +3 -28
  50. package/dist/index.js +0 -2
  51. package/dist/index.js.map +1 -1
  52. package/dist/nextjs-loader.cjs +0 -2
  53. package/dist/nextjs-loader.cjs.map +1 -1
  54. package/dist/page-BokkL6FZ.d.ts +35 -0
  55. package/dist/page-xi1aI5a7.d.ts +36 -0
  56. package/package.json +17 -3
@@ -0,0 +1,1198 @@
1
+ import {
2
+ fallbackPageName,
3
+ parseCanvasFile,
4
+ unwrapTsExpression
5
+ } from "../chunk-ICP7LCPJ.js";
6
+
7
+ // canvas/editor.ts
8
+ import { parseSync } from "oxc-parser";
9
+ function applyCanvasSourceEdits(source, edits) {
10
+ const sorted = [...edits].sort((left, right) => right.start - left.start);
11
+ let previousStart = source.length + 1;
12
+ let nextSource = source;
13
+ for (const edit of sorted) {
14
+ if (edit.start < 0 || edit.end < edit.start || edit.end > source.length || edit.end > previousStart) {
15
+ throw new Error(`Invalid overlapping canvas source edit ${edit.start}:${edit.end}`);
16
+ }
17
+ nextSource = nextSource.slice(0, edit.start) + edit.value + nextSource.slice(edit.end);
18
+ previousStart = edit.start;
19
+ }
20
+ return nextSource;
21
+ }
22
+ function migrateLegacyCanvasToReact(options) {
23
+ const existing = parseCanvasFile(options.filePath, options.source);
24
+ if (existing.canvasElementSpan) {
25
+ return {
26
+ source: options.source,
27
+ edits: [],
28
+ parsed: existing,
29
+ migrated: false
30
+ };
31
+ }
32
+ const legacy = readLegacyCanvasMigration(options.filePath, options.source);
33
+ if (legacy.unsupported.length > 0) {
34
+ throw new Error(legacy.unsupported.join("\n"));
35
+ }
36
+ const newline = detectNewline(options.source);
37
+ const edits = [...legacy.exportEdits];
38
+ const importPrefix = legacy.importInsertionOffset === 0 || options.source.slice(0, legacy.importInsertionOffset).endsWith(newline) ? "" : newline;
39
+ edits.push({
40
+ start: legacy.importInsertionOffset,
41
+ end: legacy.importInsertionOffset,
42
+ value: `${importPrefix}${legacy.importSource}${newline}`
43
+ });
44
+ edits.push({
45
+ start: options.source.length,
46
+ end: options.source.length,
47
+ value: `${newline}${buildMigratedCanvasComponent(legacy, newline)}`
48
+ });
49
+ const source = collapseBlankLines(
50
+ applyCanvasSourceEdits(options.source, edits),
51
+ newline
52
+ );
53
+ return {
54
+ source,
55
+ edits,
56
+ parsed: parseCanvasFile(options.filePath, source),
57
+ migrated: true
58
+ };
59
+ }
60
+ function updateCanvasName(options) {
61
+ return editCanvasStringAttribute(
62
+ options,
63
+ "name",
64
+ requireNonEmpty(options.name, "Canvas name"),
65
+ (parsed) => ({
66
+ valueSpan: parsed.nameSpan,
67
+ attributeSpan: parsed.nameAttributeSpan
68
+ })
69
+ );
70
+ }
71
+ function updateCanvasPath(options) {
72
+ return editCanvasStringAttribute(
73
+ options,
74
+ "path",
75
+ requireNonEmpty(options.path, "Canvas path"),
76
+ (parsed) => ({
77
+ valueSpan: parsed.pathSpan,
78
+ attributeSpan: parsed.pathAttributeSpan
79
+ })
80
+ );
81
+ }
82
+ function updateCanvasBackgroundColor(options) {
83
+ return editCanvasStringAttribute(
84
+ options,
85
+ "backgroundColor",
86
+ options.backgroundColor && options.backgroundColor.trim() !== "" ? options.backgroundColor : void 0,
87
+ (parsed) => ({
88
+ valueSpan: parsed.backgroundColorSpan,
89
+ attributeSpan: parsed.backgroundColorAttributeSpan
90
+ })
91
+ );
92
+ }
93
+ function editCanvasStringAttribute(options, attributeName, value, selectSpans) {
94
+ const parsed = parseCanvasFile(options.filePath, options.source);
95
+ const spans = selectSpans(parsed);
96
+ const edit = upsertJsxStringAttribute({
97
+ source: options.source,
98
+ openingElementSpan: requiredSpan(
99
+ parsed.canvasOpeningElementSpan,
100
+ "Canvas opening element not found"
101
+ ),
102
+ valueSpan: spans.valueSpan,
103
+ attributeSpan: spans.attributeSpan,
104
+ name: attributeName,
105
+ value
106
+ });
107
+ return applyResult(options.source, parsed, edit ? [edit] : []);
108
+ }
109
+ function updateStoryboardName(options) {
110
+ const parsed = parseCanvasFile(options.filePath, options.source);
111
+ const storyboard = findStoryboard(parsed, options.storyboardId);
112
+ if (storyboard.legacyV1) {
113
+ const edit2 = upsertObjectStringProperty({
114
+ source: options.source,
115
+ objectClose: storyboard.legacyV1.objectClose,
116
+ valueSpan: storyboard.nameSpan,
117
+ propertySpan: storyboard.legacyV1.namePropertySpan,
118
+ name: "name",
119
+ value: options.name && options.name.trim() !== "" ? options.name : void 0
120
+ });
121
+ return applyResult(options.source, parsed, edit2 ? [edit2] : []);
122
+ }
123
+ const edit = upsertJsxStringAttribute({
124
+ source: options.source,
125
+ openingElementSpan: requireStoryboardOpeningSpan(
126
+ storyboard,
127
+ options.storyboardId
128
+ ),
129
+ valueSpan: storyboard.nameSpan,
130
+ attributeSpan: storyboard.nameAttributeSpan,
131
+ name: "name",
132
+ value: options.name && options.name.trim() !== "" ? options.name : void 0
133
+ });
134
+ return applyResult(options.source, parsed, edit ? [edit] : []);
135
+ }
136
+ function updateStoryboardId(options) {
137
+ const nextId = requireNonEmpty(options.nextId, "Storyboard id");
138
+ const parsed = parseCanvasFile(options.filePath, options.source);
139
+ const storyboard = findStoryboard(parsed, options.storyboardId);
140
+ const duplicate = parsed.storyboards.find(
141
+ (item) => item.storyboardKey === nextId && item.storyboardKey !== storyboard.storyboardKey
142
+ );
143
+ if (duplicate) {
144
+ throw new Error(`Storyboard id "${nextId}" already exists`);
145
+ }
146
+ const edit = upsertJsxStringAttribute({
147
+ source: options.source,
148
+ openingElementSpan: requireStoryboardOpeningSpan(
149
+ storyboard,
150
+ options.storyboardId
151
+ ),
152
+ valueSpan: storyboard.idSpan,
153
+ attributeSpan: storyboard.idAttributeSpan,
154
+ name: "id",
155
+ value: nextId
156
+ });
157
+ return applyResult(options.source, parsed, [edit]);
158
+ }
159
+ function updateStoryboardLayout(options) {
160
+ const parsed = parseCanvasFile(options.filePath, options.source);
161
+ const storyboard = findStoryboard(parsed, options.storyboardId);
162
+ const spans = storyboard.layoutSpans;
163
+ if (!spans) {
164
+ throw new Error(`Storyboard "${options.storyboardId}" has no editable layout`);
165
+ }
166
+ const edits = [];
167
+ for (const key of ["x", "y", "width", "height"]) {
168
+ if (options.layout[key] === void 0) continue;
169
+ const span = spans[key];
170
+ if (!span) {
171
+ throw new Error(
172
+ `Storyboard "${options.storyboardId}" layout.${key} is not editable`
173
+ );
174
+ }
175
+ edits.push({
176
+ start: span.start,
177
+ end: span.end,
178
+ value: String(roundLayoutNumber(options.layout[key]))
179
+ });
180
+ }
181
+ if (options.layout.zIndex !== void 0) {
182
+ const value = String(roundLayoutNumber(options.layout.zIndex));
183
+ edits.push(
184
+ spans.zIndex ? { start: spans.zIndex.start, end: spans.zIndex.end, value } : insertLayoutProperty(options.source, spans, `zIndex: ${value}`)
185
+ );
186
+ }
187
+ if (options.layout.intrinsicSizing !== void 0) {
188
+ const value = JSON.stringify(options.layout.intrinsicSizing);
189
+ edits.push(
190
+ spans.intrinsicSizing ? {
191
+ start: spans.intrinsicSizing.start,
192
+ end: spans.intrinsicSizing.end,
193
+ value
194
+ } : insertLayoutProperty(
195
+ options.source,
196
+ spans,
197
+ `intrinsicSizing: ${value}`
198
+ )
199
+ );
200
+ }
201
+ return applyResult(options.source, parsed, edits);
202
+ }
203
+ function updateStoryboardComponent(options) {
204
+ const parsed = parseCanvasFile(options.filePath, options.source);
205
+ const storyboard = findStoryboard(parsed, options.storyboardId);
206
+ if (storyboard.kind !== "component") {
207
+ throw new Error(`Storyboard "${options.storyboardId}" is not a component storyboard`);
208
+ }
209
+ const imports = [];
210
+ if (options.componentImport) {
211
+ const importLine = buildMissingComponentImportLine(
212
+ parsed,
213
+ options.source,
214
+ options.componentImport
215
+ );
216
+ if (importLine) imports.push(importLine);
217
+ }
218
+ const importEdit = buildImportInsertionEdit(options.source, parsed, imports);
219
+ const componentEdit = upsertJsxExpressionAttribute({
220
+ source: options.source,
221
+ openingElementSpan: requireStoryboardOpeningSpan(
222
+ storyboard,
223
+ options.storyboardId
224
+ ),
225
+ expressionSpan: storyboard.component?.span,
226
+ attributeSpan: storyboard.component?.attributeSpan,
227
+ name: "component",
228
+ value: requireNonEmpty(
229
+ options.componentExpression,
230
+ "Storyboard component expression"
231
+ )
232
+ });
233
+ return applyResult(options.source, parsed, [
234
+ ...importEdit ? [importEdit] : [],
235
+ componentEdit
236
+ ]);
237
+ }
238
+ function updateStoryboardProps(options) {
239
+ const parsed = parseCanvasFile(options.filePath, options.source);
240
+ const storyboard = findStoryboard(parsed, options.storyboardId);
241
+ const edit = upsertJsxExpressionAttribute({
242
+ source: options.source,
243
+ openingElementSpan: requireStoryboardOpeningSpan(
244
+ storyboard,
245
+ options.storyboardId
246
+ ),
247
+ expressionSpan: storyboard.props?.span,
248
+ attributeSpan: storyboard.props?.attributeSpan,
249
+ name: "props",
250
+ value: options.propsExpression && options.propsExpression.trim() !== "" ? options.propsExpression.trim() : void 0
251
+ });
252
+ return applyResult(options.source, parsed, edit ? [edit] : []);
253
+ }
254
+ function updateRouteStoryboardRoute(options) {
255
+ const parsed = parseCanvasFile(options.filePath, options.source);
256
+ const storyboard = findStoryboard(parsed, options.storyboardId);
257
+ if (storyboard.kind !== "route") {
258
+ throw new Error(`Storyboard "${options.storyboardId}" is not a route storyboard`);
259
+ }
260
+ const edit = upsertJsxStringAttribute({
261
+ source: options.source,
262
+ openingElementSpan: requireStoryboardOpeningSpan(
263
+ storyboard,
264
+ options.storyboardId
265
+ ),
266
+ valueSpan: storyboard.routeSpan,
267
+ attributeSpan: storyboard.routeAttributeSpan,
268
+ name: "route",
269
+ value: requireNonEmpty(options.route, "Route storyboard route")
270
+ });
271
+ return applyResult(options.source, parsed, [edit]);
272
+ }
273
+ function updateHtmlStoryboardSource(options) {
274
+ const parsed = parseCanvasFile(options.filePath, options.source);
275
+ const storyboard = findStoryboard(parsed, options.storyboardId);
276
+ if (storyboard.kind !== "html") {
277
+ throw new Error(`Storyboard "${options.storyboardId}" is not an html storyboard`);
278
+ }
279
+ const filepath = options.filepath && options.filepath.trim() !== "" ? options.filepath.trim() : void 0;
280
+ const src = options.src && options.src.trim() !== "" ? options.src : void 0;
281
+ if (!filepath && !src) {
282
+ throw new Error("HTML storyboard source requires filepath or src");
283
+ }
284
+ const openingElementSpan = requireStoryboardOpeningSpan(
285
+ storyboard,
286
+ options.storyboardId
287
+ );
288
+ const filepathEdit = upsertJsxStringAttribute({
289
+ source: options.source,
290
+ openingElementSpan,
291
+ valueSpan: storyboard.filepathSpan,
292
+ attributeSpan: storyboard.filepathAttributeSpan,
293
+ name: "filepath",
294
+ value: filepath
295
+ });
296
+ const srcEdit = upsertJsxStringAttribute({
297
+ source: options.source,
298
+ openingElementSpan,
299
+ valueSpan: storyboard.srcSpan,
300
+ attributeSpan: storyboard.srcAttributeSpan,
301
+ name: "src",
302
+ value: src
303
+ });
304
+ return applyResult(options.source, parsed, [filepathEdit, srcEdit]);
305
+ }
306
+ function addCanvasStoryboard(options) {
307
+ const parsed = parseCanvasFile(options.filePath, options.source);
308
+ if (parsed.storyboards.some((item) => item.storyboardKey === options.storyboard.id)) {
309
+ throw new Error(`Storyboard id "${options.storyboard.id}" already exists`);
310
+ }
311
+ const imports = [];
312
+ const sdkComponent = sdkComponentForStoryboard(options.storyboard.kind);
313
+ const sdkTag = resolveSdkTag(parsed, sdkComponent);
314
+ let storyboardTag = sdkTag.tag;
315
+ if (sdkTag.importLine) {
316
+ imports.push(sdkTag.importLine);
317
+ storyboardTag = sdkTag.tag;
318
+ }
319
+ let componentExpression;
320
+ if (options.storyboard.kind === "component") {
321
+ componentExpression = options.storyboard.componentExpression ?? options.storyboard.componentImport?.localName;
322
+ if (!componentExpression) {
323
+ throw new Error("Component storyboard requires componentExpression or componentImport");
324
+ }
325
+ if (options.storyboard.componentImport) {
326
+ const importLine = buildMissingComponentImportLine(
327
+ parsed,
328
+ options.source,
329
+ options.storyboard.componentImport
330
+ );
331
+ if (importLine) imports.push(importLine);
332
+ }
333
+ }
334
+ const importEdit = buildImportInsertionEdit(options.source, parsed, imports);
335
+ const insertionEdit = buildCanvasChildInsertionEdit({
336
+ source: options.source,
337
+ parsed,
338
+ tag: storyboardTag,
339
+ storyboard: options.storyboard,
340
+ componentExpression
341
+ });
342
+ const edits = [
343
+ ...importEdit ? [importEdit] : [],
344
+ insertionEdit
345
+ ];
346
+ return applyResult(options.source, parsed, edits);
347
+ }
348
+ function removeCanvasStoryboard(options) {
349
+ const parsed = parseCanvasFile(options.filePath, options.source);
350
+ const storyboard = findStoryboard(parsed, options.storyboardId);
351
+ const edits = [
352
+ {
353
+ ...expandToFullLines(options.source, storyboard.jsxElementSpan),
354
+ value: ""
355
+ }
356
+ ];
357
+ if (options.removeUnusedComponentImport ?? true) {
358
+ const importEdit = buildUnusedComponentImportRemoval({
359
+ source: options.source,
360
+ parsed,
361
+ deletedStoryboard: storyboard,
362
+ deletionEdit: edits[0]
363
+ });
364
+ if (importEdit) edits.push(importEdit);
365
+ }
366
+ const result = applyResult(options.source, parsed, edits);
367
+ return {
368
+ ...result,
369
+ source: collapseBlankLines(result.source, detectNewline(options.source))
370
+ };
371
+ }
372
+ function applyResult(source, parsed, edits) {
373
+ const compactEdits = edits.filter((edit) => {
374
+ if (!edit) return false;
375
+ return source.slice(edit.start, edit.end) !== edit.value;
376
+ });
377
+ return {
378
+ source: applyCanvasSourceEdits(source, compactEdits),
379
+ edits: compactEdits,
380
+ parsed
381
+ };
382
+ }
383
+ function findStoryboard(parsed, storyboardId) {
384
+ const storyboard = parsed.storyboards.find(
385
+ (item) => item.storyboardKey === storyboardId
386
+ );
387
+ if (!storyboard) {
388
+ throw new Error(`Storyboard "${storyboardId}" not found`);
389
+ }
390
+ return storyboard;
391
+ }
392
+ function requireStoryboardOpeningSpan(storyboard, storyboardId) {
393
+ return requiredSpan(
394
+ storyboard.openingElementSpan,
395
+ `Storyboard "${storyboardId}" opening element not found`
396
+ );
397
+ }
398
+ function upsertJsxStringAttribute(options) {
399
+ if (options.value === void 0) {
400
+ if (!options.attributeSpan) return null;
401
+ return {
402
+ ...expandJsxAttributeRemoval(options.source, options.attributeSpan),
403
+ value: ""
404
+ };
405
+ }
406
+ const value = JSON.stringify(options.value);
407
+ if (options.valueSpan) {
408
+ return { start: options.valueSpan.start, end: options.valueSpan.end, value };
409
+ }
410
+ const offset = findOpeningElementAttributeInsertionOffset(
411
+ options.source,
412
+ options.openingElementSpan
413
+ );
414
+ return {
415
+ start: offset,
416
+ end: offset,
417
+ value: ` ${options.name}={${value}}`
418
+ };
419
+ }
420
+ function upsertObjectStringProperty(options) {
421
+ if (options.value === void 0) {
422
+ if (!options.propertySpan) return null;
423
+ return {
424
+ ...expandObjectPropertyRemoval(options.source, options.propertySpan),
425
+ value: ""
426
+ };
427
+ }
428
+ const value = JSON.stringify(options.value);
429
+ if (options.valueSpan) {
430
+ return { start: options.valueSpan.start, end: options.valueSpan.end, value };
431
+ }
432
+ if (typeof options.objectClose !== "number") {
433
+ throw new Error(`Object close not found for "${options.name}" property`);
434
+ }
435
+ return insertObjectProperty(
436
+ options.source,
437
+ options.objectClose,
438
+ `${options.name}: ${value}`
439
+ );
440
+ }
441
+ function upsertJsxExpressionAttribute(options) {
442
+ if (options.value === void 0) {
443
+ if (!options.attributeSpan) return null;
444
+ return {
445
+ ...expandJsxAttributeRemoval(options.source, options.attributeSpan),
446
+ value: ""
447
+ };
448
+ }
449
+ if (options.expressionSpan) {
450
+ return {
451
+ start: options.expressionSpan.start,
452
+ end: options.expressionSpan.end,
453
+ value: options.value
454
+ };
455
+ }
456
+ const offset = findOpeningElementAttributeInsertionOffset(
457
+ options.source,
458
+ options.openingElementSpan
459
+ );
460
+ return {
461
+ start: offset,
462
+ end: offset,
463
+ value: ` ${options.name}={${options.value}}`
464
+ };
465
+ }
466
+ function insertLayoutProperty(source, spans, propertySource) {
467
+ if (typeof spans.layoutClose !== "number") {
468
+ throw new Error("Layout object close span not found");
469
+ }
470
+ return insertObjectProperty(source, spans.layoutClose, propertySource);
471
+ }
472
+ function insertObjectProperty(source, objectClose, propertySource) {
473
+ const offset = trimWhitespaceBeforeOffset(source, objectClose);
474
+ const previous = previousMeaningfulCharacter(source, offset);
475
+ return {
476
+ start: offset,
477
+ end: offset,
478
+ value: `${previous === "{" || previous === "," ? " " : ", "}${propertySource}`
479
+ };
480
+ }
481
+ function formatStoryboardElement(options) {
482
+ const newline = detectNewline(options.source);
483
+ const closingIndent = lineIndentAt(options.source, options.insertionOffset);
484
+ const indent = `${closingIndent} `;
485
+ const firstLineIndent = " ";
486
+ const propIndent = `${indent} `;
487
+ const props = storyboardElementProps(
488
+ options.storyboard,
489
+ options.componentExpression
490
+ );
491
+ return `${firstLineIndent}<${options.tag}${newline}${props.map((prop) => `${propIndent}${prop}`).join(newline)}${newline}${indent}/>${newline}${closingIndent}`;
492
+ }
493
+ function buildCanvasChildInsertionEdit(options) {
494
+ const insertionOffset = options.parsed.canvasChildrenInsertionOffset;
495
+ if (typeof insertionOffset === "number") {
496
+ return {
497
+ start: insertionOffset,
498
+ end: insertionOffset,
499
+ value: formatStoryboardElement({
500
+ source: options.source,
501
+ insertionOffset,
502
+ tag: options.tag,
503
+ storyboard: options.storyboard,
504
+ componentExpression: options.componentExpression
505
+ })
506
+ };
507
+ }
508
+ const openingSpan = options.parsed.canvasOpeningElementSpan;
509
+ if (!openingSpan) {
510
+ throw new Error("Canvas closing element not found");
511
+ }
512
+ const openingSource = options.source.slice(openingSpan.start, openingSpan.end);
513
+ const selfClosingMatch = openingSource.match(/\s*\/\s*>$/);
514
+ const canvasName = openingSource.match(/^<\s*([A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*)/)?.[1];
515
+ if (!selfClosingMatch || !canvasName) {
516
+ throw new Error("Canvas closing element not found");
517
+ }
518
+ const newline = detectNewline(options.source);
519
+ const replacementStart = openingSpan.end - selfClosingMatch[0].length;
520
+ const closingIndent = lineIndentAt(options.source, openingSpan.start);
521
+ const childIndent = `${closingIndent} `;
522
+ const propIndent = `${childIndent} `;
523
+ const props = storyboardElementProps(
524
+ options.storyboard,
525
+ options.componentExpression
526
+ );
527
+ return {
528
+ start: replacementStart,
529
+ end: openingSpan.end,
530
+ value: `>${newline}${childIndent}<${options.tag}${newline}${props.map((prop) => `${propIndent}${prop}`).join(newline)}${newline}${childIndent}/>${newline}${closingIndent}</${canvasName}>`
531
+ };
532
+ }
533
+ function storyboardElementProps(storyboard, componentExpression) {
534
+ return [
535
+ `id={${JSON.stringify(requireNonEmpty(storyboard.id, "Storyboard id"))}}`,
536
+ ...storyboard.name && storyboard.name.trim() !== "" ? [`name={${JSON.stringify(storyboard.name)}}`] : [],
537
+ ...storyboardKindProps(storyboard, componentExpression),
538
+ `layout={{ ${formatLayout(storyboard.layout)} }}`
539
+ ];
540
+ }
541
+ function storyboardKindProps(storyboard, componentExpression) {
542
+ if (storyboard.kind === "component") {
543
+ return [`component={${componentExpression}}`];
544
+ }
545
+ if (storyboard.kind === "route") {
546
+ return [`route={${JSON.stringify(storyboard.route)}}`];
547
+ }
548
+ return [
549
+ ...storyboard.filepath ? [`filepath={${JSON.stringify(storyboard.filepath)}}`] : [],
550
+ ...storyboard.src ? [`src={${JSON.stringify(storyboard.src)}}`] : []
551
+ ];
552
+ }
553
+ function formatLayout(layout) {
554
+ return [
555
+ `x: ${roundLayoutNumber(layout.x)}`,
556
+ `y: ${roundLayoutNumber(layout.y)}`,
557
+ `width: ${roundLayoutNumber(layout.width)}`,
558
+ `height: ${roundLayoutNumber(layout.height)}`,
559
+ ...layout.zIndex === void 0 ? [] : [`zIndex: ${roundLayoutNumber(layout.zIndex)}`],
560
+ ...layout.intrinsicSizing ? [`intrinsicSizing: ${JSON.stringify(layout.intrinsicSizing)}`] : []
561
+ ].join(", ");
562
+ }
563
+ function sdkComponentForStoryboard(kind) {
564
+ if (kind === "route") return "RouteStoryboard";
565
+ if (kind === "html") return "HtmlStoryboard";
566
+ return "Storyboard";
567
+ }
568
+ function resolveSdkTag(parsed, component) {
569
+ for (const item of parsed.imports) {
570
+ if (item.source !== "tempo-sdk/canvas") continue;
571
+ if (item.kind === "namespace") return { tag: `${item.localName}.${component}` };
572
+ if (item.importedName === component) return { tag: item.localName };
573
+ }
574
+ const localName = pickAvailableIdentifier(
575
+ parsed,
576
+ `TempoCanvas${component}`
577
+ );
578
+ return {
579
+ tag: localName,
580
+ importLine: `import { ${component} as ${localName} } from "tempo-sdk/canvas";`
581
+ };
582
+ }
583
+ function buildMissingComponentImportLine(parsed, source, componentImport) {
584
+ const existing = parsed.imports.find(
585
+ (item) => item.localName === componentImport.localName
586
+ );
587
+ if (existing) {
588
+ if (existing.source !== componentImport.source) {
589
+ throw new Error(`Import binding "${componentImport.localName}" already exists`);
590
+ }
591
+ return null;
592
+ }
593
+ if (hasIdentifier(source, componentImport.localName)) {
594
+ throw new Error(`Identifier "${componentImport.localName}" already exists`);
595
+ }
596
+ if (!componentImport.importedName || componentImport.importedName === "default") {
597
+ return `import ${componentImport.localName} from ${JSON.stringify(
598
+ componentImport.source
599
+ )};`;
600
+ }
601
+ const specifier = componentImport.importedName === componentImport.localName ? componentImport.localName : `${componentImport.importedName} as ${componentImport.localName}`;
602
+ return `import { ${specifier} } from ${JSON.stringify(componentImport.source)};`;
603
+ }
604
+ function buildImportInsertionEdit(source, parsed, importLines) {
605
+ if (importLines.length === 0) return null;
606
+ const newline = detectNewline(source);
607
+ const uniqueLines = Array.from(new Set(importLines));
608
+ const lastImport = parsed.imports.reduce(
609
+ (latest, item) => !latest || item.declarationSpan.end > latest.declarationSpan.end ? item : latest,
610
+ null
611
+ );
612
+ if (lastImport) {
613
+ return {
614
+ start: lastImport.declarationSpan.end,
615
+ end: lastImport.declarationSpan.end,
616
+ value: `${newline}${uniqueLines.join(newline)}`
617
+ };
618
+ }
619
+ const offset = topLevelInsertionOffset(source);
620
+ return {
621
+ start: offset,
622
+ end: offset,
623
+ value: `${uniqueLines.join(newline)}${newline}`
624
+ };
625
+ }
626
+ function buildUnusedComponentImportRemoval(options) {
627
+ const componentImport = options.deletedStoryboard.component?.import;
628
+ if (!componentImport || componentImport.importKind === "type") return null;
629
+ const usedByRemainingStoryboard = options.parsed.storyboards.some(
630
+ (storyboard) => storyboard.storyboardKey !== options.deletedStoryboard.storyboardKey && storyboard.component?.import?.localName === componentImport.localName
631
+ );
632
+ if (usedByRemainingStoryboard) return null;
633
+ const sourceAfterStoryboardDelete = applyCanvasSourceEdits(options.source, [
634
+ options.deletionEdit
635
+ ]);
636
+ if (componentImport.specifierCount === 1) {
637
+ const sourceWithoutImport2 = removeSpanText(
638
+ sourceAfterStoryboardDelete,
639
+ componentImport.declarationSpan
640
+ );
641
+ if (hasIdentifier(sourceWithoutImport2, componentImport.localName)) return null;
642
+ return {
643
+ ...expandToFullLines(options.source, componentImport.declarationSpan),
644
+ value: ""
645
+ };
646
+ }
647
+ if (componentImport.kind !== "named" || componentImport.hasDefaultSpecifier || componentImport.hasNamespaceSpecifier || componentImport.namedSpecifierCount <= 1) {
648
+ return null;
649
+ }
650
+ const specifierRange = expandImportSpecifierRemovalRange(
651
+ options.source,
652
+ componentImport.span
653
+ );
654
+ const sourceWithoutImport = removeSpanText(
655
+ sourceAfterStoryboardDelete,
656
+ specifierRange
657
+ );
658
+ if (hasIdentifier(sourceWithoutImport, componentImport.localName)) return null;
659
+ return {
660
+ ...specifierRange,
661
+ value: ""
662
+ };
663
+ }
664
+ function expandImportSpecifierRemovalRange(source, span) {
665
+ const lineStart = Math.max(source.lastIndexOf("\n", span.start - 1) + 1, 0);
666
+ const nextNewline = source.indexOf("\n", span.end);
667
+ const lineEnd = nextNewline >= 0 ? nextNewline + 1 : source.length;
668
+ const before = source.slice(lineStart, span.start);
669
+ const after = source.slice(span.end, lineEnd);
670
+ if (/^[ \t]*$/.test(before) && /^[ \t]*(,)?[ \t]*(\r?\n)?$/.test(after)) {
671
+ return { start: lineStart, end: lineEnd };
672
+ }
673
+ let start = span.start;
674
+ let end = span.end;
675
+ while (end < source.length && /\s/.test(source[end] ?? "")) end++;
676
+ if (source[end] === ",") {
677
+ end++;
678
+ while (end < source.length && (source[end] === " " || source[end] === " ")) {
679
+ end++;
680
+ }
681
+ return { start, end };
682
+ }
683
+ while (start > 0 && (source[start - 1] === " " || source[start - 1] === " ")) {
684
+ start--;
685
+ }
686
+ if (source[start - 1] === ",") {
687
+ start--;
688
+ while (start > 0 && (source[start - 1] === " " || source[start - 1] === " ")) {
689
+ start--;
690
+ }
691
+ }
692
+ return { start, end };
693
+ }
694
+ function removeSpanText(source, span) {
695
+ return source.slice(0, span.start) + source.slice(span.end);
696
+ }
697
+ function findOpeningElementAttributeInsertionOffset(source, span) {
698
+ const close = source.lastIndexOf(">", span.end - 1);
699
+ if (close < span.start) {
700
+ throw new Error("JSX opening element close not found");
701
+ }
702
+ return source[close - 1] === "/" ? close - 1 : close;
703
+ }
704
+ function expandJsxAttributeRemoval(source, span) {
705
+ let start = span.start;
706
+ let end = span.end;
707
+ while (start > 0 && (source[start - 1] === " " || source[start - 1] === " ")) {
708
+ start--;
709
+ }
710
+ while (end < source.length && (source[end] === " " || source[end] === " ")) {
711
+ end++;
712
+ }
713
+ return { start, end };
714
+ }
715
+ function expandObjectPropertyRemoval(source, span) {
716
+ let start = span.start;
717
+ let end = span.end;
718
+ while (start > 0 && /\s/.test(source[start - 1] ?? "")) start--;
719
+ while (end < source.length && /\s/.test(source[end] ?? "")) end++;
720
+ if (source[end] === ",") {
721
+ end++;
722
+ while (end < source.length && (source[end] === " " || source[end] === " ")) {
723
+ end++;
724
+ }
725
+ return { start, end };
726
+ }
727
+ let comma = start - 1;
728
+ while (comma >= 0 && /\s/.test(source[comma] ?? "")) comma--;
729
+ if (source[comma] === ",") {
730
+ start = comma;
731
+ }
732
+ return { start, end };
733
+ }
734
+ function expandToFullLines(source, span) {
735
+ let start = span.start;
736
+ let end = span.end;
737
+ while (start > 0 && source[start - 1] !== "\n" && source[start - 1] !== "\r") {
738
+ start--;
739
+ }
740
+ if (start > 0) {
741
+ if (source[start - 1] === "\n") start--;
742
+ if (start > 0 && source[start - 1] === "\r") start--;
743
+ }
744
+ while (end < source.length && (source[end] === " " || source[end] === " ")) {
745
+ end++;
746
+ }
747
+ if (source.slice(end, end + 2) === "\r\n") {
748
+ end += 2;
749
+ } else if (source[end] === "\n" || source[end] === "\r") {
750
+ end++;
751
+ }
752
+ return { start, end };
753
+ }
754
+ function expandStatementForward(source, span) {
755
+ let end = span.end;
756
+ while (end < source.length && (source[end] === " " || source[end] === " ")) {
757
+ end++;
758
+ }
759
+ if (source.slice(end, end + 2) === "\r\n") {
760
+ end += 2;
761
+ } else if (source[end] === "\n" || source[end] === "\r") {
762
+ end++;
763
+ }
764
+ return { start: span.start, end };
765
+ }
766
+ function readLegacyCanvasMigration(filePath, source) {
767
+ const result = parseSync(filePath, source);
768
+ const program = result.program;
769
+ const programBody = Array.isArray(program?.body) ? program.body : [];
770
+ const bindings = collectLegacyBindings(programBody);
771
+ const usedIdentifiers = collectSourceIdentifiers(source);
772
+ const canvasTag = pickAvailableSourceIdentifier(usedIdentifiers, "TempoCanvas");
773
+ const legacyTag = pickAvailableSourceIdentifier(
774
+ usedIdentifiers,
775
+ "TempoLegacyStoryboardV1"
776
+ );
777
+ const routeTag = pickAvailableSourceIdentifier(
778
+ usedIdentifiers,
779
+ "TempoRouteStoryboard"
780
+ );
781
+ const htmlTag = pickAvailableSourceIdentifier(
782
+ usedIdentifiers,
783
+ "TempoHtmlStoryboard"
784
+ );
785
+ usedIdentifiers.add(canvasTag);
786
+ usedIdentifiers.add(legacyTag);
787
+ usedIdentifiers.add(routeTag);
788
+ usedIdentifiers.add(htmlTag);
789
+ const componentName = pickAvailableSourceIdentifier(
790
+ usedIdentifiers,
791
+ `${toPascalIdentifier(fallbackPageName(filePath))}Canvas`
792
+ );
793
+ const pageBindingName = pickAvailableSourceIdentifier(usedIdentifiers, "page");
794
+ const migration = {
795
+ storyboards: [],
796
+ exportEdits: [],
797
+ unsupported: [],
798
+ importInsertionOffset: lastImportEnd(programBody) ?? topLevelInsertionOffset(source),
799
+ importSource: `import { Canvas as ${canvasTag}, LegacyStoryboardV1 as ${legacyTag}, RouteStoryboard as ${routeTag}, HtmlStoryboard as ${htmlTag} } from "tempo-sdk/canvas";`,
800
+ componentName,
801
+ canvasTag,
802
+ legacyTag,
803
+ routeTag,
804
+ htmlTag,
805
+ canvasName: fallbackPageName(filePath),
806
+ hasPageBackgroundColor: false
807
+ };
808
+ let defaultExportCount = 0;
809
+ const seenStoryboardIds = /* @__PURE__ */ new Set();
810
+ const addStoryboard = (id, localName, typeName) => {
811
+ if (seenStoryboardIds.has(id)) return;
812
+ if (typeName !== "TempoStoryboard" && typeName !== "TempoRouteStoryboard" && typeName !== "TempoHtmlStoryboard") {
813
+ return;
814
+ }
815
+ seenStoryboardIds.add(id);
816
+ const binding = bindings.get(localName);
817
+ const pageName = readObjectStringProperty(binding?.init, "name");
818
+ if (!migration.pageExpression && pageName) {
819
+ migration.canvasName = pageName;
820
+ }
821
+ if (typeName === "TempoStoryboard") {
822
+ migration.storyboards.push({ kind: "component", id, localName });
823
+ return;
824
+ }
825
+ const layout = readObjectLayoutProperty(binding?.init);
826
+ if (!layout) {
827
+ migration.unsupported.push(
828
+ `Legacy ${typeName} export "${id}" requires a literal layout object`
829
+ );
830
+ return;
831
+ }
832
+ if (typeName === "TempoRouteStoryboard") {
833
+ const route = readObjectStringProperty(binding?.init, "route");
834
+ if (!route) {
835
+ migration.unsupported.push(
836
+ `Legacy TempoRouteStoryboard export "${id}" requires a literal route string`
837
+ );
838
+ return;
839
+ }
840
+ migration.storyboards.push({
841
+ kind: "route",
842
+ id,
843
+ route,
844
+ ...pageName ? { name: pageName } : {},
845
+ layout
846
+ });
847
+ return;
848
+ }
849
+ const filepath = readObjectStringProperty(binding?.init, "filepath");
850
+ if (!filepath) {
851
+ migration.unsupported.push(
852
+ `Legacy TempoHtmlStoryboard export "${id}" requires a literal filepath string`
853
+ );
854
+ return;
855
+ }
856
+ migration.storyboards.push({
857
+ kind: "html",
858
+ id,
859
+ filepath,
860
+ ...pageName ? { name: pageName } : {},
861
+ layout
862
+ });
863
+ };
864
+ for (const statement of programBody) {
865
+ const span = nodeSpan(statement);
866
+ if (!span) continue;
867
+ if (statement?.type === "ExportAllDeclaration") {
868
+ migration.unsupported.push("export * declarations require manual migration");
869
+ continue;
870
+ }
871
+ if (statement?.type === "ExportDefaultDeclaration") {
872
+ defaultExportCount += 1;
873
+ if (defaultExportCount > 1) {
874
+ migration.unsupported.push("Multiple default exports require manual migration");
875
+ continue;
876
+ }
877
+ const declaration = unwrapTsExpression(statement.declaration);
878
+ if (declaration?.type === "Identifier") {
879
+ migration.pageExpression = declaration.name;
880
+ const binding = bindings.get(declaration.name);
881
+ const pageName = readObjectStringProperty(binding?.init, "name");
882
+ if (pageName) migration.canvasName = pageName;
883
+ migration.hasPageBackgroundColor = hasObjectProperty(
884
+ binding?.init,
885
+ "backgroundColor"
886
+ );
887
+ migration.exportEdits.push({
888
+ ...expandStatementForward(source, span),
889
+ value: ""
890
+ });
891
+ continue;
892
+ }
893
+ if (declaration?.type === "ObjectExpression") {
894
+ migration.pageExpression = pageBindingName;
895
+ const pageName = readObjectStringProperty(declaration, "name");
896
+ if (pageName) migration.canvasName = pageName;
897
+ migration.hasPageBackgroundColor = hasObjectProperty(
898
+ declaration,
899
+ "backgroundColor"
900
+ );
901
+ migration.exportEdits.push({
902
+ start: statement.start,
903
+ end: declaration.start,
904
+ value: `const ${pageBindingName} = `
905
+ });
906
+ continue;
907
+ }
908
+ migration.unsupported.push("Default export must be a page object or identifier");
909
+ continue;
910
+ }
911
+ if (statement?.type !== "ExportNamedDeclaration") {
912
+ continue;
913
+ }
914
+ if (statement.source) {
915
+ migration.unsupported.push(
916
+ "Re-export declarations with a source require manual migration"
917
+ );
918
+ continue;
919
+ }
920
+ if (statement.declaration) {
921
+ const declarationSpan = nodeSpan(statement.declaration);
922
+ if (declarationSpan) {
923
+ migration.exportEdits.push({
924
+ start: statement.start,
925
+ end: declarationSpan.start,
926
+ value: ""
927
+ });
928
+ }
929
+ if (statement.declaration.type === "VariableDeclaration") {
930
+ for (const declaration of statement.declaration.declarations ?? []) {
931
+ if (declaration?.id?.type !== "Identifier") continue;
932
+ const localName = declaration.id.name;
933
+ const typeName = legacyTypeName(
934
+ declaration.id.typeAnnotation?.typeAnnotation
935
+ );
936
+ addStoryboard(localName, localName, typeName);
937
+ }
938
+ }
939
+ continue;
940
+ }
941
+ migration.exportEdits.push({
942
+ ...expandStatementForward(source, span),
943
+ value: ""
944
+ });
945
+ for (const specifier of statement.specifiers ?? []) {
946
+ const localName = legacyIdentifierName(specifier.local);
947
+ const exportedName = legacyIdentifierName(
948
+ specifier.exported ?? specifier.local
949
+ );
950
+ if (!localName || !exportedName) continue;
951
+ addStoryboard(
952
+ exportedName,
953
+ localName,
954
+ bindings.get(localName)?.typeName ?? null
955
+ );
956
+ }
957
+ }
958
+ return migration;
959
+ }
960
+ function buildMigratedCanvasComponent(migration, newline) {
961
+ const canvasProps = [
962
+ migration.pageExpression ? `name={${migration.pageExpression}.name}` : `name={${JSON.stringify(migration.canvasName)}}`,
963
+ ...migration.pageExpression && migration.hasPageBackgroundColor ? [`backgroundColor={${migration.pageExpression}.backgroundColor}`] : []
964
+ ].join(" ");
965
+ if (migration.storyboards.length === 0) {
966
+ return `export default function ${migration.componentName}() {
967
+ return <${migration.canvasTag} ${canvasProps} />;
968
+ }
969
+ `;
970
+ }
971
+ const storyboards = migration.storyboards.map((storyboard) => ` ${formatMigratedStoryboard(migration, storyboard)}`).join(newline);
972
+ return `export default function ${migration.componentName}() {
973
+ return (
974
+ <${migration.canvasTag} ${canvasProps}>
975
+ ${storyboards}
976
+ </${migration.canvasTag}>
977
+ );
978
+ }
979
+ `;
980
+ }
981
+ function formatMigratedStoryboard(migration, storyboard) {
982
+ if (storyboard.kind === "component") {
983
+ return `<${migration.legacyTag} id=${JSON.stringify(storyboard.id)} storyboard={${storyboard.localName}} />`;
984
+ }
985
+ if (storyboard.kind === "route") {
986
+ return `<${migration.routeTag} id=${JSON.stringify(storyboard.id)}${formatOptionalJsxStringAttribute("name", storyboard.name)} route=${JSON.stringify(storyboard.route)} layout={{ ${formatLayout(storyboard.layout)} }} />`;
987
+ }
988
+ return `<${migration.htmlTag} id=${JSON.stringify(storyboard.id)}${formatOptionalJsxStringAttribute("name", storyboard.name)} filepath=${JSON.stringify(storyboard.filepath)} layout={{ ${formatLayout(storyboard.layout)} }} />`;
989
+ }
990
+ function formatOptionalJsxStringAttribute(name, value) {
991
+ return value ? ` ${name}=${JSON.stringify(value)}` : "";
992
+ }
993
+ function collectLegacyBindings(programBody) {
994
+ const bindings = /* @__PURE__ */ new Map();
995
+ const collect = (node) => {
996
+ if (node?.type !== "VariableDeclaration") return;
997
+ for (const declaration of node.declarations ?? []) {
998
+ if (declaration?.id?.type !== "Identifier") continue;
999
+ bindings.set(declaration.id.name, {
1000
+ typeName: legacyTypeName(declaration.id.typeAnnotation?.typeAnnotation),
1001
+ init: declaration.init
1002
+ });
1003
+ }
1004
+ };
1005
+ for (const statement of programBody) {
1006
+ collect(statement);
1007
+ if (statement?.type === "ExportNamedDeclaration") {
1008
+ collect(statement.declaration);
1009
+ }
1010
+ }
1011
+ return bindings;
1012
+ }
1013
+ function legacyTypeName(typeAnnotation) {
1014
+ if (!typeAnnotation || typeAnnotation.type !== "TSTypeReference") return null;
1015
+ const typeName = typeAnnotation.typeName;
1016
+ if (typeName?.type === "Identifier") return typeName.name;
1017
+ if (typeName?.type === "TSQualifiedName" && typeName.right?.type === "Identifier") {
1018
+ return typeName.right.name;
1019
+ }
1020
+ return null;
1021
+ }
1022
+ function legacyIdentifierName(node) {
1023
+ if (node?.type === "Identifier") return node.name;
1024
+ if (node?.type === "Literal" && typeof node.value === "string") {
1025
+ return node.value;
1026
+ }
1027
+ return null;
1028
+ }
1029
+ function readObjectStringProperty(node, propertyName) {
1030
+ const property = getObjectPropertyFromNode(node, propertyName);
1031
+ return property?.value?.type === "Literal" && typeof property.value.value === "string" ? property.value.value : null;
1032
+ }
1033
+ function hasObjectProperty(node, propertyName) {
1034
+ return getObjectPropertyFromNode(node, propertyName) !== null;
1035
+ }
1036
+ function readObjectLayoutProperty(node) {
1037
+ const property = getObjectPropertyFromNode(node, "layout");
1038
+ const layout = unwrapTsExpression(property?.value);
1039
+ if (!layout || layout.type !== "ObjectExpression") return null;
1040
+ const x = readObjectNumberProperty(layout, "x");
1041
+ const y = readObjectNumberProperty(layout, "y");
1042
+ const width = readObjectNumberProperty(layout, "width");
1043
+ const height = readObjectNumberProperty(layout, "height");
1044
+ if (x == null || y == null || width == null || height == null) {
1045
+ return null;
1046
+ }
1047
+ const zIndex = readObjectNumberProperty(layout, "zIndex");
1048
+ return {
1049
+ x,
1050
+ y,
1051
+ width,
1052
+ height,
1053
+ ...zIndex == null ? {} : { zIndex }
1054
+ };
1055
+ }
1056
+ function readObjectNumberProperty(node, propertyName) {
1057
+ const property = getObjectPropertyFromNode(node, propertyName);
1058
+ const value = unwrapTsExpression(property?.value);
1059
+ if (value?.type === "Literal" && typeof value.value === "number") {
1060
+ return value.value;
1061
+ }
1062
+ if (value?.type === "UnaryExpression" && value.operator === "-" && value.argument?.type === "Literal" && typeof value.argument.value === "number") {
1063
+ return -value.argument.value;
1064
+ }
1065
+ return null;
1066
+ }
1067
+ function getObjectPropertyFromNode(node, propertyName) {
1068
+ const objectNode = unwrapTsExpression(node);
1069
+ if (!objectNode || objectNode.type !== "ObjectExpression") return null;
1070
+ for (const property of objectNode.properties ?? []) {
1071
+ if (property?.type !== "Property" || property.computed) continue;
1072
+ const key = property.key?.type === "Identifier" ? property.key.name : property.key?.type === "Literal" && typeof property.key.value === "string" ? property.key.value : null;
1073
+ if (key === propertyName) return property;
1074
+ }
1075
+ return null;
1076
+ }
1077
+ function lastImportEnd(programBody) {
1078
+ let end = null;
1079
+ for (const statement of programBody) {
1080
+ if (statement?.type !== "ImportDeclaration") continue;
1081
+ const span = nodeSpan(statement);
1082
+ if (span) end = Math.max(end ?? 0, span.end);
1083
+ }
1084
+ return end;
1085
+ }
1086
+ function nodeSpan(node) {
1087
+ return typeof node?.start === "number" && typeof node?.end === "number" && Number.isFinite(node.start) && Number.isFinite(node.end) ? { start: node.start, end: node.end } : null;
1088
+ }
1089
+ function collectSourceIdentifiers(source) {
1090
+ return new Set(
1091
+ Array.from(source.matchAll(/\b[A-Za-z_$][\w$]*\b/g), (match) => match[0])
1092
+ );
1093
+ }
1094
+ function pickAvailableSourceIdentifier(used, base) {
1095
+ const normalizedBase = /^[A-Za-z_$]/.test(base) ? base : `Canvas${base}`;
1096
+ if (!used.has(normalizedBase)) return normalizedBase;
1097
+ for (let index = 2; index < 1e4; index += 1) {
1098
+ const candidate = `${normalizedBase}${index}`;
1099
+ if (!used.has(candidate)) return candidate;
1100
+ }
1101
+ throw new Error(`Unable to find available identifier for ${base}`);
1102
+ }
1103
+ function toPascalIdentifier(value) {
1104
+ const identifier = value.split(/[^A-Za-z0-9_$]+/).filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
1105
+ return identifier || "Canvas";
1106
+ }
1107
+ function lineIndentAt(source, offset) {
1108
+ const lineStart = Math.max(source.lastIndexOf("\n", offset - 1) + 1, 0);
1109
+ const linePrefix = source.slice(lineStart, offset);
1110
+ const match = linePrefix.match(/^[ \t]*/);
1111
+ return match?.[0] ?? "";
1112
+ }
1113
+ function previousMeaningfulCharacter(source, offset) {
1114
+ for (let index = offset - 1; index >= 0; index -= 1) {
1115
+ const character = source[index] ?? "";
1116
+ if (!/\s/.test(character)) return character;
1117
+ }
1118
+ return "";
1119
+ }
1120
+ function trimWhitespaceBeforeOffset(source, offset) {
1121
+ let nextOffset = offset;
1122
+ while (nextOffset > 0 && /\s/.test(source[nextOffset - 1] ?? "")) {
1123
+ nextOffset--;
1124
+ }
1125
+ return nextOffset;
1126
+ }
1127
+ function collapseBlankLines(source, newline) {
1128
+ return newline === "\r\n" ? source.replace(/(\r\n){3,}/g, "\r\n\r\n") : source.replace(/\n{3,}/g, "\n\n");
1129
+ }
1130
+ function detectNewline(source) {
1131
+ return source.includes("\r\n") ? "\r\n" : "\n";
1132
+ }
1133
+ function topLevelInsertionOffset(source) {
1134
+ let offset = 0;
1135
+ if (source.startsWith("#!")) {
1136
+ const newline = source.indexOf("\n");
1137
+ offset = newline >= 0 ? newline + 1 : source.length;
1138
+ }
1139
+ while (true) {
1140
+ const nextLineEnd = source.indexOf("\n", offset);
1141
+ const end = nextLineEnd >= 0 ? nextLineEnd + 1 : source.length;
1142
+ const line = source.slice(offset, end).trim();
1143
+ if (!/^["']use [^"']+["'];?$/.test(line)) break;
1144
+ offset = end;
1145
+ }
1146
+ return offset;
1147
+ }
1148
+ function pickAvailableIdentifier(parsed, base) {
1149
+ const usedImports = new Set(parsed.imports.map((item) => item.localName));
1150
+ if (!usedImports.has(base)) return base;
1151
+ for (let index = 2; index < 1e4; index += 1) {
1152
+ const candidate = `${base}${index}`;
1153
+ if (!usedImports.has(candidate)) return candidate;
1154
+ }
1155
+ throw new Error(`Unable to find available identifier for ${base}`);
1156
+ }
1157
+ function hasIdentifier(source, identifier) {
1158
+ return new RegExp(`\\b${escapeRegExp(identifier)}\\b`).test(source);
1159
+ }
1160
+ function escapeRegExp(value) {
1161
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1162
+ }
1163
+ function roundLayoutNumber(value) {
1164
+ if (typeof value !== "number" || !Number.isFinite(value)) {
1165
+ throw new Error("Layout values must be finite numbers");
1166
+ }
1167
+ return Math.round(value);
1168
+ }
1169
+ function requireNonEmpty(value, label) {
1170
+ const trimmed = value.trim();
1171
+ if (!trimmed) {
1172
+ throw new Error(`${label} must be non-empty`);
1173
+ }
1174
+ return trimmed;
1175
+ }
1176
+ function requiredSpan(value, message) {
1177
+ if (value === void 0) {
1178
+ throw new Error(message);
1179
+ }
1180
+ return value;
1181
+ }
1182
+ export {
1183
+ addCanvasStoryboard,
1184
+ applyCanvasSourceEdits,
1185
+ migrateLegacyCanvasToReact,
1186
+ removeCanvasStoryboard,
1187
+ updateCanvasBackgroundColor,
1188
+ updateCanvasName,
1189
+ updateCanvasPath,
1190
+ updateHtmlStoryboardSource,
1191
+ updateRouteStoryboardRoute,
1192
+ updateStoryboardComponent,
1193
+ updateStoryboardId,
1194
+ updateStoryboardLayout,
1195
+ updateStoryboardName,
1196
+ updateStoryboardProps
1197
+ };
1198
+ //# sourceMappingURL=editor.js.map