tempo-sdk 0.0.99 → 0.0.101

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 (170) hide show
  1. package/README.md +3 -403
  2. package/dist/assets/editor.d.ts +43 -65
  3. package/dist/assets/editor.js +1 -573
  4. package/dist/assets/index.d.ts +11 -61
  5. package/dist/assets/index.js +1 -338
  6. package/dist/assets/parser.d.ts +68 -78
  7. package/dist/assets/parser.js +1 -33
  8. package/dist/astro/asset-preview-client.d.ts +3 -2
  9. package/dist/astro/asset-preview-client.js +1 -93
  10. package/dist/astro/controls.d.ts +1 -3
  11. package/dist/astro/controls.js +1 -7
  12. package/dist/astro/document-client.d.ts +5 -6
  13. package/dist/astro/document-client.js +1 -78
  14. package/dist/astro/runtime.d.ts +23 -11
  15. package/dist/astro/runtime.js +1 -86
  16. package/dist/astro.d.ts +19 -13
  17. package/dist/astro.js +1 -818
  18. package/dist/canvas/astro-contract.d.ts +0 -3
  19. package/dist/canvas/astro-contract.js +1 -9
  20. package/dist/canvas/astro.d.ts +3 -4
  21. package/dist/canvas/astro.js +1 -42
  22. package/dist/canvas/editor.d.ts +187 -183
  23. package/dist/canvas/editor.js +1 -1094
  24. package/dist/canvas/flutter-preview.d.ts +0 -1
  25. package/dist/canvas/flutter-preview.js +1 -9
  26. package/dist/canvas/index.d.ts +46 -100
  27. package/dist/canvas/index.js +1 -3926
  28. package/dist/canvas/interact-projection.d.ts +7 -5
  29. package/dist/canvas/interact-projection.js +1 -12
  30. package/dist/canvas/parser.d.ts +10 -303
  31. package/dist/canvas/parser.js +1 -30
  32. package/dist/canvas/svelte.d.ts +6 -7
  33. package/dist/canvas/svelte.js +1 -91
  34. package/dist/canvas/vue.d.ts +9 -49
  35. package/dist/canvas/vue.js +1 -264
  36. package/dist/chunk-FH6TMWFA.js +1 -0
  37. package/dist/chunk-GQIOB5SV.js +1 -0
  38. package/dist/chunk-HBQ7FFH7.js +1 -0
  39. package/dist/chunk-JRJOWLCN.js +1 -0
  40. package/dist/chunk-M3GN2KUH.js +1 -0
  41. package/dist/chunk-MPIHFFML.js +1 -0
  42. package/dist/chunk-N2V6XXRK.js +1 -0
  43. package/dist/chunk-QNVQ7U2W.js +1 -0
  44. package/dist/chunk-T5TY3U2H.js +1 -0
  45. package/dist/chunk-TK37FQAR.js +1 -0
  46. package/dist/chunk-XO2BSHWM.js +1 -0
  47. package/dist/chunk-XUSV3KOD.js +1 -0
  48. package/dist/chunk-YRBEBVG4.js +1 -0
  49. package/dist/{controls-uCaQ3CNX.d.ts → controls-DKslABtM.d.ts} +0 -3
  50. package/dist/expo/plugin.cjs +1 -1928
  51. package/dist/expo/plugin.js +1 -8
  52. package/dist/expo-babel-plugin.cjs +1 -1928
  53. package/dist/expo-babel-plugin.d.cts +46 -40
  54. package/dist/expo-babel-plugin.d.ts +46 -40
  55. package/dist/expo-babel-plugin.js +1 -8
  56. package/dist/flutter-preview-path.d.ts +23 -7
  57. package/dist/flutter-preview-path.js +1 -16
  58. package/dist/index.d.ts +33 -45
  59. package/dist/index.js +1 -20
  60. package/dist/nextjs/plugin.cjs +1 -413
  61. package/dist/nextjs/plugin.js +1 -7
  62. package/dist/nextjs-loader.cjs +1 -2277
  63. package/dist/nextjs.cjs +1 -484
  64. package/dist/nextjs.d.cts +2 -58
  65. package/dist/nextjs.d.ts +2 -58
  66. package/dist/nextjs.js +1 -17
  67. package/dist/nuxt/runtime/identity.d.ts +2 -4
  68. package/dist/nuxt/runtime/identity.js +1 -18
  69. package/dist/nuxt.d.ts +31 -92
  70. package/dist/nuxt.js +1 -5854
  71. package/dist/{page-DwLnOM5d.d.ts → page-Bc8PekIX.d.ts} +1 -5
  72. package/dist/parser.d-MO5ciJ5n.d.ts +236 -0
  73. package/dist/{storyboard-CMJVBSXn.d.ts → storyboard.contract.d-UQ4MUYN5.d.ts} +3 -25
  74. package/dist/svelte.d.ts +8 -18
  75. package/dist/svelte.js +1 -917
  76. package/dist/types-CfUgM2w4.d.ts +57 -0
  77. package/dist/v1-client-compat-n0E0XxuX.d.ts +5 -0
  78. package/dist/vue.d.ts +17 -58
  79. package/dist/vue.js +1 -1501
  80. package/package.json +12 -62
  81. package/dist/assets/editor.js.map +0 -1
  82. package/dist/assets/index.js.map +0 -1
  83. package/dist/assets/parser.js.map +0 -1
  84. package/dist/astro/asset-preview-client.js.map +0 -1
  85. package/dist/astro/controls.js.map +0 -1
  86. package/dist/astro/document-client.js.map +0 -1
  87. package/dist/astro/runtime.js.map +0 -1
  88. package/dist/astro.js.map +0 -1
  89. package/dist/canvas/astro-contract.js.map +0 -1
  90. package/dist/canvas/astro.js.map +0 -1
  91. package/dist/canvas/editor.js.map +0 -1
  92. package/dist/canvas/flutter-preview.js.map +0 -1
  93. package/dist/canvas/index.js.map +0 -1
  94. package/dist/canvas/interact-projection.js.map +0 -1
  95. package/dist/canvas/parser.js.map +0 -1
  96. package/dist/canvas/svelte.js.map +0 -1
  97. package/dist/canvas/vue.js.map +0 -1
  98. package/dist/chunk-27WT3XUG.js +0 -455
  99. package/dist/chunk-27WT3XUG.js.map +0 -1
  100. package/dist/chunk-5HIIF354.js +0 -67
  101. package/dist/chunk-5HIIF354.js.map +0 -1
  102. package/dist/chunk-65B52AR7.js +0 -11
  103. package/dist/chunk-65B52AR7.js.map +0 -1
  104. package/dist/chunk-6HYKKP5N.js +0 -2658
  105. package/dist/chunk-6HYKKP5N.js.map +0 -1
  106. package/dist/chunk-6SOP4XU6.js +0 -1891
  107. package/dist/chunk-6SOP4XU6.js.map +0 -1
  108. package/dist/chunk-AFXE462X.js +0 -1253
  109. package/dist/chunk-AFXE462X.js.map +0 -1
  110. package/dist/chunk-BQPKOVI5.js +0 -115
  111. package/dist/chunk-BQPKOVI5.js.map +0 -1
  112. package/dist/chunk-CYDF4LYJ.js +0 -342
  113. package/dist/chunk-CYDF4LYJ.js.map +0 -1
  114. package/dist/chunk-CYQE3TLC.js +0 -37
  115. package/dist/chunk-CYQE3TLC.js.map +0 -1
  116. package/dist/chunk-DI2ZFAWL.js +0 -14
  117. package/dist/chunk-DI2ZFAWL.js.map +0 -1
  118. package/dist/chunk-EGRHWZRV.js +0 -1
  119. package/dist/chunk-EGRHWZRV.js.map +0 -1
  120. package/dist/chunk-FGWGY3G3.js +0 -157
  121. package/dist/chunk-FGWGY3G3.js.map +0 -1
  122. package/dist/chunk-HOBTDB6G.js +0 -112
  123. package/dist/chunk-HOBTDB6G.js.map +0 -1
  124. package/dist/chunk-I7VF4ZOV.js +0 -630
  125. package/dist/chunk-I7VF4ZOV.js.map +0 -1
  126. package/dist/chunk-JVVHU3A7.js +0 -1077
  127. package/dist/chunk-JVVHU3A7.js.map +0 -1
  128. package/dist/chunk-MIXQVPDH.js +0 -8606
  129. package/dist/chunk-MIXQVPDH.js.map +0 -1
  130. package/dist/chunk-MU7S7NU7.js +0 -183
  131. package/dist/chunk-MU7S7NU7.js.map +0 -1
  132. package/dist/chunk-OX2YKYSL.js +0 -13
  133. package/dist/chunk-OX2YKYSL.js.map +0 -1
  134. package/dist/chunk-PYAJHLXO.js +0 -903
  135. package/dist/chunk-PYAJHLXO.js.map +0 -1
  136. package/dist/chunk-SGN7BDRE.js +0 -16
  137. package/dist/chunk-SGN7BDRE.js.map +0 -1
  138. package/dist/chunk-SGTGDLOX.js +0 -285
  139. package/dist/chunk-SGTGDLOX.js.map +0 -1
  140. package/dist/chunk-T364NBR3.js +0 -1440
  141. package/dist/chunk-T364NBR3.js.map +0 -1
  142. package/dist/chunk-U66QI3EN.js +0 -1524
  143. package/dist/chunk-U66QI3EN.js.map +0 -1
  144. package/dist/chunk-WTXOWQ7N.js +0 -47
  145. package/dist/chunk-WTXOWQ7N.js.map +0 -1
  146. package/dist/chunk-X5DJKVBT.js +0 -1308
  147. package/dist/chunk-X5DJKVBT.js.map +0 -1
  148. package/dist/chunk-ZT7HJ6YU.js +0 -38
  149. package/dist/chunk-ZT7HJ6YU.js.map +0 -1
  150. package/dist/chunk-ZW26VZHX.js +0 -3169
  151. package/dist/chunk-ZW26VZHX.js.map +0 -1
  152. package/dist/controls-reader-5MFHYBZZ.js +0 -192
  153. package/dist/controls-reader-5MFHYBZZ.js.map +0 -1
  154. package/dist/expo/plugin.cjs.map +0 -1
  155. package/dist/expo/plugin.js.map +0 -1
  156. package/dist/expo-babel-plugin.cjs.map +0 -1
  157. package/dist/expo-babel-plugin.js.map +0 -1
  158. package/dist/flutter-preview-path.js.map +0 -1
  159. package/dist/index.js.map +0 -1
  160. package/dist/nextjs/plugin.cjs.map +0 -1
  161. package/dist/nextjs/plugin.js.map +0 -1
  162. package/dist/nextjs-loader.cjs.map +0 -1
  163. package/dist/nextjs.cjs.map +0 -1
  164. package/dist/nextjs.js.map +0 -1
  165. package/dist/nuxt/runtime/identity.js.map +0 -1
  166. package/dist/nuxt.js.map +0 -1
  167. package/dist/svelte.js.map +0 -1
  168. package/dist/types-C8OIU-kc.d.ts +0 -106
  169. package/dist/v1-client-compat-qxaXEDm_.d.ts +0 -23
  170. package/dist/vue.js.map +0 -1
@@ -1,1094 +1 @@
1
- import {
2
- STORYBOARD_SDK_COMPONENTS,
3
- parseCanvasFile,
4
- storyboardComponentForFramework
5
- } from "../chunk-AFXE462X.js";
6
- import "../chunk-CYQE3TLC.js";
7
-
8
- // canvas/editor.ts
9
- import { parseSync } from "oxc-parser";
10
-
11
- // canvas/v1-file-compat.ts
12
- function v1ReadableLayout(layout, hint) {
13
- const fixed = layout.width !== void 0 && layout.height !== void 0;
14
- if (fixed || !hint) return layout;
15
- return {
16
- ...layout,
17
- width: hint.width,
18
- height: hint.height,
19
- intrinsicSizing: "root-element"
20
- };
21
- }
22
- function v1LayoutHint(layoutSource) {
23
- const width = readNumberProperty(layoutSource, "width");
24
- const height = readNumberProperty(layoutSource, "height");
25
- return width === void 0 || height === void 0 ? void 0 : { width, height };
26
- }
27
- function readNumberProperty(source, key) {
28
- const match = source.match(
29
- new RegExp(`(?:^|[{,\\s])${key}\\s*:\\s*(-?[0-9]*\\.?[0-9]+)`)
30
- );
31
- return match ? Number(match[1]) : void 0;
32
- }
33
-
34
- // canvas/editor.ts
35
- function applyCanvasSourceEdits(source, edits) {
36
- const sorted = [...edits].sort((left, right) => right.start - left.start);
37
- let previousStart = source.length + 1;
38
- let nextSource = source;
39
- for (const edit of sorted) {
40
- if (edit.start < 0 || edit.end < edit.start || edit.end > source.length || edit.end > previousStart) {
41
- throw new Error(
42
- `Invalid overlapping canvas source edit ${edit.start}:${edit.end}`
43
- );
44
- }
45
- nextSource = nextSource.slice(0, edit.start) + edit.value + nextSource.slice(edit.end);
46
- previousStart = edit.start;
47
- }
48
- return nextSource;
49
- }
50
- function updateCanvasName(options) {
51
- return editCanvasStringAttribute(
52
- options,
53
- "name",
54
- requireNonEmpty(options.name, "Canvas name"),
55
- (parsed) => ({
56
- valueSpan: parsed.nameSpan,
57
- attributeSpan: parsed.nameAttributeSpan
58
- })
59
- );
60
- }
61
- function updateCanvasPath(options) {
62
- return editCanvasStringAttribute(
63
- options,
64
- "path",
65
- requireNonEmpty(options.path, "Canvas path"),
66
- (parsed) => ({
67
- valueSpan: parsed.pathSpan,
68
- attributeSpan: parsed.pathAttributeSpan
69
- })
70
- );
71
- }
72
- function updateCanvasBackgroundColor(options) {
73
- return editCanvasStringAttribute(
74
- options,
75
- "backgroundColor",
76
- options.backgroundColor && options.backgroundColor.trim() !== "" ? options.backgroundColor : void 0,
77
- (parsed) => ({
78
- valueSpan: parsed.backgroundColorSpan,
79
- attributeSpan: parsed.backgroundColorAttributeSpan
80
- })
81
- );
82
- }
83
- function editCanvasStringAttribute(options, attributeName, value, selectSpans) {
84
- const parsed = parseCanvasFile(options.filePath, options.source);
85
- const spans = selectSpans(parsed);
86
- const edit = upsertJsxStringAttribute({
87
- source: options.source,
88
- openingElementSpan: requiredSpan(
89
- parsed.canvasOpeningElementSpan,
90
- "Canvas opening element not found"
91
- ),
92
- valueSpan: spans.valueSpan,
93
- attributeSpan: spans.attributeSpan,
94
- name: attributeName,
95
- value
96
- });
97
- return applyResult(options.source, parsed, edit ? [edit] : []);
98
- }
99
- function updateStoryboardName(options) {
100
- const parsed = parseCanvasFile(options.filePath, options.source);
101
- const storyboard = findStoryboard(parsed, options.storyboardId);
102
- if (storyboard.legacyV1) {
103
- const edit2 = upsertObjectStringProperty({
104
- source: options.source,
105
- objectClose: storyboard.legacyV1.objectClose,
106
- valueSpan: storyboard.nameSpan,
107
- propertySpan: storyboard.legacyV1.namePropertySpan,
108
- name: "name",
109
- value: options.name && options.name.trim() !== "" ? options.name : void 0
110
- });
111
- return applyResult(options.source, parsed, edit2 ? [edit2] : []);
112
- }
113
- const edit = upsertJsxStringAttribute({
114
- source: options.source,
115
- openingElementSpan: requireStoryboardOpeningSpan(
116
- storyboard,
117
- options.storyboardId
118
- ),
119
- valueSpan: storyboard.nameSpan,
120
- attributeSpan: storyboard.nameAttributeSpan,
121
- name: "name",
122
- value: options.name && options.name.trim() !== "" ? options.name : void 0
123
- });
124
- return applyResult(options.source, parsed, edit ? [edit] : []);
125
- }
126
- function updateStoryboardId(options) {
127
- const nextId = requireNonEmpty(options.nextId, "Storyboard id");
128
- const parsed = parseCanvasFile(options.filePath, options.source);
129
- const storyboard = findStoryboard(parsed, options.storyboardId);
130
- const duplicate = parsed.storyboards.find(
131
- (item) => item.storyboardKey === nextId && item.storyboardKey !== storyboard.storyboardKey
132
- );
133
- if (duplicate) {
134
- throw new Error(`Storyboard id "${nextId}" already exists`);
135
- }
136
- const edit = upsertJsxStringAttribute({
137
- source: options.source,
138
- openingElementSpan: requireStoryboardOpeningSpan(
139
- storyboard,
140
- options.storyboardId
141
- ),
142
- valueSpan: storyboard.idSpan,
143
- attributeSpan: storyboard.idAttributeSpan,
144
- name: "id",
145
- value: nextId
146
- });
147
- return applyResult(options.source, parsed, [edit]);
148
- }
149
- function updateStoryboardLayout(options) {
150
- const parsed = parseCanvasFile(options.filePath, options.source);
151
- const storyboard = findStoryboard(parsed, options.storyboardId);
152
- const spans = storyboard.layoutSpans;
153
- if (!spans) {
154
- throw new Error(
155
- `Storyboard "${options.storyboardId}" has no editable layout`
156
- );
157
- }
158
- const span = storyboard.legacyV1?.layoutPropertySpan ?? storyboard.layoutAttributeSpan;
159
- if (!span || spans.layoutClose === void 0) {
160
- throw new Error(
161
- `Storyboard "${options.storyboardId}" has no editable layout`
162
- );
163
- }
164
- for (const key of ["x", "y", "width", "height", "zIndex"]) {
165
- if (parsed.errors.some(
166
- (error) => error.span && error.span.start >= span.start && error.span.end <= span.end && error.message.includes(`layout.${key} must be a number literal`)
167
- )) {
168
- throw new Error(
169
- `Storyboard "${options.storyboardId}" layout.${key} is not editable`
170
- );
171
- }
172
- }
173
- const layout = { ...storyboard.layout, ...options.layout };
174
- if (storyboard.kind === "component" && storyboard.layout.width === void 0 && storyboard.layout.height === void 0) {
175
- delete layout.width;
176
- delete layout.height;
177
- }
178
- if (layout.width === void 0 !== (layout.height === void 0)) {
179
- throw new Error("layout.width and layout.height must be set together");
180
- }
181
- if (storyboard.kind !== "component" && layout.width === void 0) {
182
- throw new Error("Route and HTML layouts require width and height");
183
- }
184
- for (const key of ["x", "y"]) {
185
- if (options.layout[key] !== void 0 && !spans[key]) {
186
- throw new Error(
187
- `Storyboard "${options.storyboardId}" layout.${key} is not editable`
188
- );
189
- }
190
- }
191
- const written = v1ReadableLayout(
192
- layout,
193
- v1LayoutHint(options.source.slice(span.start, span.end))
194
- );
195
- return applyResult(options.source, parsed, [
196
- {
197
- start: span.start,
198
- end: span.end,
199
- value: storyboard.legacyV1 ? `layout: { ${formatLayout(written)} }` : `layout={{ ${formatLayout(written)} }}`
200
- }
201
- ]);
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(
208
- `Storyboard "${options.storyboardId}" is not a component storyboard`
209
- );
210
- }
211
- const imports = [];
212
- if (options.componentImport) {
213
- const importLine = buildMissingComponentImportLine(
214
- parsed,
215
- options.source,
216
- options.componentImport
217
- );
218
- if (importLine) imports.push(importLine);
219
- }
220
- const importEdit = buildImportInsertionEdit(options.source, parsed, imports);
221
- const componentEdit = upsertJsxExpressionAttribute({
222
- source: options.source,
223
- openingElementSpan: requireStoryboardOpeningSpan(
224
- storyboard,
225
- options.storyboardId
226
- ),
227
- expressionSpan: storyboard.component?.span,
228
- attributeSpan: storyboard.component?.attributeSpan,
229
- name: "component",
230
- value: requireNonEmpty(
231
- options.componentExpression,
232
- "Storyboard component expression"
233
- )
234
- });
235
- return applyResult(options.source, parsed, [
236
- ...importEdit ? [importEdit] : [],
237
- componentEdit
238
- ]);
239
- }
240
- function updateStoryboardProps(options) {
241
- const parsed = parseCanvasFile(options.filePath, options.source);
242
- const storyboard = findStoryboard(parsed, options.storyboardId);
243
- const edit = upsertJsxExpressionAttribute({
244
- source: options.source,
245
- openingElementSpan: requireStoryboardOpeningSpan(
246
- storyboard,
247
- options.storyboardId
248
- ),
249
- expressionSpan: storyboard.props?.span,
250
- attributeSpan: storyboard.props?.attributeSpan,
251
- name: "props",
252
- value: options.propsExpression && options.propsExpression.trim() !== "" ? options.propsExpression.trim() : void 0
253
- });
254
- return applyResult(options.source, parsed, edit ? [edit] : []);
255
- }
256
- function updateStoryboardVrt(options) {
257
- const parsed = parseCanvasFile(options.filePath, options.source);
258
- const storyboard = findStoryboard(parsed, options.storyboardId);
259
- if (storyboard.kind === "route") {
260
- throw new Error(
261
- `Storyboard "${options.storyboardId}" is a route storyboard; VRT supports component and local HTML storyboards`
262
- );
263
- }
264
- if (typeof options.tracked === "object") {
265
- const literal = formatStoryboardVrtConfig(options.tracked);
266
- const attributeText = literal === null ? "vrt" : `vrt={${literal}}`;
267
- if (storyboard.vrtAttributeSpan) {
268
- return applyResult(options.source, parsed, [
269
- {
270
- start: storyboard.vrtAttributeSpan.start,
271
- end: storyboard.vrtAttributeSpan.end,
272
- value: attributeText
273
- }
274
- ]);
275
- }
276
- return applyResult(options.source, parsed, [
277
- insertBareJsxAttributeLine({
278
- source: options.source,
279
- openingElementSpan: requireStoryboardOpeningSpan(
280
- storyboard,
281
- options.storyboardId
282
- ),
283
- name: attributeText
284
- })
285
- ]);
286
- }
287
- if (!options.tracked) {
288
- if (!storyboard.vrtAttributeSpan) {
289
- return applyResult(options.source, parsed, []);
290
- }
291
- return applyResult(options.source, parsed, [
292
- {
293
- ...expandJsxAttributeRemoval(
294
- options.source,
295
- storyboard.vrtAttributeSpan
296
- ),
297
- value: ""
298
- }
299
- ]);
300
- }
301
- if (storyboard.vrt) {
302
- return applyResult(options.source, parsed, []);
303
- }
304
- const openingElementSpan = requireStoryboardOpeningSpan(
305
- storyboard,
306
- options.storyboardId
307
- );
308
- if (storyboard.vrtAttributeSpan) {
309
- return applyResult(options.source, parsed, [
310
- {
311
- ...expandJsxAttributeRemoval(
312
- options.source,
313
- storyboard.vrtAttributeSpan
314
- ),
315
- value: ""
316
- },
317
- insertBareJsxAttributeLine({
318
- source: options.source,
319
- openingElementSpan,
320
- name: "vrt"
321
- })
322
- ]);
323
- }
324
- return applyResult(options.source, parsed, [
325
- insertBareJsxAttributeLine({
326
- source: options.source,
327
- openingElementSpan,
328
- name: "vrt"
329
- })
330
- ]);
331
- }
332
- function formatStoryboardVrtConfig(config) {
333
- const parts = [];
334
- if (config.threshold !== void 0) {
335
- if (typeof config.threshold !== "number" || !Number.isFinite(config.threshold) || config.threshold < 0 || config.threshold > 0.5) {
336
- throw new Error("vrt.threshold must be a number between 0 and 0.5");
337
- }
338
- parts.push(`threshold: ${config.threshold}`);
339
- }
340
- if (config.skip !== void 0) {
341
- if (typeof config.skip !== "boolean") {
342
- throw new Error("vrt.skip must be a boolean");
343
- }
344
- parts.push(`skip: ${config.skip}`);
345
- }
346
- if (config.ignore !== void 0) {
347
- if (!Array.isArray(config.ignore)) {
348
- throw new Error("vrt.ignore must be an array of { x, y, w, h } regions");
349
- }
350
- const regions = config.ignore.map((region) => {
351
- for (const key of ["x", "y", "w", "h"]) {
352
- const value = region?.[key];
353
- if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
354
- throw new Error(
355
- `vrt.ignore regions must be { x, y, w, h } non-negative numbers (bad ${key})`
356
- );
357
- }
358
- }
359
- return `{ x: ${region.x}, y: ${region.y}, w: ${region.w}, h: ${region.h} }`;
360
- });
361
- if (regions.length > 0) {
362
- parts.push(`ignore: [${regions.join(", ")}]`);
363
- }
364
- }
365
- return parts.length === 0 ? null : `{ ${parts.join(", ")} }`;
366
- }
367
- function updateRouteStoryboardRoute(options) {
368
- const parsed = parseCanvasFile(options.filePath, options.source);
369
- const storyboard = findStoryboard(parsed, options.storyboardId);
370
- if (storyboard.kind !== "route") {
371
- throw new Error(
372
- `Storyboard "${options.storyboardId}" is not a route storyboard`
373
- );
374
- }
375
- const edit = upsertJsxStringAttribute({
376
- source: options.source,
377
- openingElementSpan: requireStoryboardOpeningSpan(
378
- storyboard,
379
- options.storyboardId
380
- ),
381
- valueSpan: storyboard.routeSpan,
382
- attributeSpan: storyboard.routeAttributeSpan,
383
- name: "route",
384
- value: requireNonEmpty(options.route, "Route storyboard route")
385
- });
386
- return applyResult(options.source, parsed, [edit]);
387
- }
388
- function updateHtmlStoryboardSource(options) {
389
- const parsed = parseCanvasFile(options.filePath, options.source);
390
- const storyboard = findStoryboard(parsed, options.storyboardId);
391
- if (storyboard.kind !== "html") {
392
- throw new Error(
393
- `Storyboard "${options.storyboardId}" is not an html storyboard`
394
- );
395
- }
396
- const filepath = options.filepath && options.filepath.trim() !== "" ? options.filepath.trim() : void 0;
397
- const src = options.src && options.src.trim() !== "" ? options.src : void 0;
398
- if (!filepath && !src) {
399
- throw new Error("HTML storyboard source requires filepath or src");
400
- }
401
- const openingElementSpan = requireStoryboardOpeningSpan(
402
- storyboard,
403
- options.storyboardId
404
- );
405
- const filepathEdit = upsertJsxStringAttribute({
406
- source: options.source,
407
- openingElementSpan,
408
- valueSpan: storyboard.filepathSpan,
409
- attributeSpan: storyboard.filepathAttributeSpan,
410
- name: "filepath",
411
- value: filepath
412
- });
413
- const srcEdit = upsertJsxStringAttribute({
414
- source: options.source,
415
- openingElementSpan,
416
- valueSpan: storyboard.srcSpan,
417
- attributeSpan: storyboard.srcAttributeSpan,
418
- name: "src",
419
- value: src
420
- });
421
- return applyResult(options.source, parsed, [filepathEdit, srcEdit]);
422
- }
423
- function addCanvasStoryboard(options) {
424
- const parsed = parseCanvasFile(options.filePath, options.source);
425
- if (parsed.storyboards.some(
426
- (item) => item.storyboardKey === options.storyboard.id
427
- )) {
428
- throw new Error(`Storyboard id "${options.storyboard.id}" already exists`);
429
- }
430
- const imports = [];
431
- const sdkComponent = sdkComponentForStoryboard(options.storyboard);
432
- const sdkTag = resolveSdkTag(parsed, sdkComponent);
433
- let storyboardTag = sdkTag.tag;
434
- if (sdkTag.importLine) {
435
- imports.push(sdkTag.importLine);
436
- storyboardTag = sdkTag.tag;
437
- }
438
- let componentExpression;
439
- if (options.storyboard.kind === "component") {
440
- componentExpression = options.storyboard.componentExpression ?? options.storyboard.componentImport?.localName;
441
- if (!componentExpression) {
442
- throw new Error(
443
- "Component storyboard requires componentExpression or componentImport"
444
- );
445
- }
446
- if (options.storyboard.componentImport) {
447
- const importLine = buildMissingComponentImportLine(
448
- parsed,
449
- options.source,
450
- options.storyboard.componentImport
451
- );
452
- if (importLine) imports.push(importLine);
453
- }
454
- }
455
- const importEdit = buildImportInsertionEdit(options.source, parsed, imports);
456
- const insertionEdit = buildCanvasChildInsertionEdit({
457
- source: options.source,
458
- parsed,
459
- tag: storyboardTag,
460
- storyboard: options.storyboard,
461
- componentExpression
462
- });
463
- const edits = [...importEdit ? [importEdit] : [], insertionEdit];
464
- return applyResult(options.source, parsed, edits);
465
- }
466
- function removeCanvasStoryboard(options) {
467
- const parsed = parseCanvasFile(options.filePath, options.source);
468
- const storyboard = findStoryboard(parsed, options.storyboardId);
469
- const edits = [
470
- {
471
- ...expandToFullLines(options.source, storyboard.jsxElementSpan),
472
- value: ""
473
- }
474
- ];
475
- if (options.removeUnusedComponentImport ?? true) {
476
- const importEdit = buildUnusedComponentImportRemoval({
477
- source: options.source,
478
- parsed,
479
- deletedStoryboard: storyboard,
480
- deletionEdit: edits[0]
481
- });
482
- if (importEdit) edits.push(importEdit);
483
- }
484
- const result = applyResult(options.source, parsed, edits);
485
- return {
486
- ...result,
487
- source: collapseBlankLines(result.source, detectNewline(options.source))
488
- };
489
- }
490
- function applyResult(source, parsed, edits) {
491
- const compactEdits = edits.filter((edit) => {
492
- if (!edit) return false;
493
- return source.slice(edit.start, edit.end) !== edit.value;
494
- });
495
- return {
496
- source: applyCanvasSourceEdits(source, compactEdits),
497
- edits: compactEdits,
498
- parsed
499
- };
500
- }
501
- function findStoryboard(parsed, storyboardId) {
502
- const storyboard = parsed.storyboards.find(
503
- (item) => item.storyboardKey === storyboardId
504
- );
505
- if (!storyboard) {
506
- throw new Error(`Storyboard "${storyboardId}" not found`);
507
- }
508
- return storyboard;
509
- }
510
- function requireStoryboardOpeningSpan(storyboard, storyboardId) {
511
- return requiredSpan(
512
- storyboard.openingElementSpan,
513
- `Storyboard "${storyboardId}" opening element not found`
514
- );
515
- }
516
- function upsertJsxStringAttribute(options) {
517
- if (options.value === void 0) {
518
- if (!options.attributeSpan) return null;
519
- return {
520
- ...expandJsxAttributeRemoval(options.source, options.attributeSpan),
521
- value: ""
522
- };
523
- }
524
- const value = JSON.stringify(options.value);
525
- if (options.valueSpan) {
526
- return {
527
- start: options.valueSpan.start,
528
- end: options.valueSpan.end,
529
- value
530
- };
531
- }
532
- const offset = findOpeningElementAttributeInsertionOffset(
533
- options.source,
534
- options.openingElementSpan
535
- );
536
- return {
537
- start: offset,
538
- end: offset,
539
- value: ` ${options.name}={${value}}`
540
- };
541
- }
542
- function upsertObjectStringProperty(options) {
543
- if (options.value === void 0) {
544
- if (!options.propertySpan) return null;
545
- return {
546
- ...expandObjectPropertyRemoval(options.source, options.propertySpan),
547
- value: ""
548
- };
549
- }
550
- const value = JSON.stringify(options.value);
551
- if (options.valueSpan) {
552
- return {
553
- start: options.valueSpan.start,
554
- end: options.valueSpan.end,
555
- value
556
- };
557
- }
558
- if (typeof options.objectClose !== "number") {
559
- throw new Error(`Object close not found for "${options.name}" property`);
560
- }
561
- return insertObjectProperty(
562
- options.source,
563
- options.objectClose,
564
- `${options.name}: ${value}`
565
- );
566
- }
567
- function upsertJsxExpressionAttribute(options) {
568
- if (options.value === void 0) {
569
- if (!options.attributeSpan) return null;
570
- return {
571
- ...expandJsxAttributeRemoval(options.source, options.attributeSpan),
572
- value: ""
573
- };
574
- }
575
- if (options.expressionSpan) {
576
- return {
577
- start: options.expressionSpan.start,
578
- end: options.expressionSpan.end,
579
- value: options.value
580
- };
581
- }
582
- const offset = findOpeningElementAttributeInsertionOffset(
583
- options.source,
584
- options.openingElementSpan
585
- );
586
- return {
587
- start: offset,
588
- end: offset,
589
- value: ` ${options.name}={${options.value}}`
590
- };
591
- }
592
- function insertObjectProperty(source, objectClose, propertySource) {
593
- const offset = trimWhitespaceBeforeOffset(source, objectClose);
594
- const previous = previousMeaningfulCharacter(source, offset);
595
- return {
596
- start: offset,
597
- end: offset,
598
- value: `${previous === "{" || previous === "," ? " " : ", "}${propertySource}`
599
- };
600
- }
601
- function formatStoryboardElement(options) {
602
- const newline = detectNewline(options.source);
603
- const closingIndent = lineIndentAt(options.source, options.insertionOffset);
604
- const indent = `${closingIndent} `;
605
- const firstLineIndent = " ";
606
- const propIndent = `${indent} `;
607
- const props = storyboardElementProps(
608
- options.storyboard,
609
- options.componentExpression
610
- );
611
- return `${firstLineIndent}<${options.tag}${newline}${props.map((prop) => `${propIndent}${prop}`).join(newline)}${newline}${indent}/>${newline}${closingIndent}`;
612
- }
613
- function buildCanvasChildInsertionEdit(options) {
614
- const insertionOffset = options.parsed.canvasChildrenInsertionOffset;
615
- if (typeof insertionOffset === "number") {
616
- return {
617
- start: insertionOffset,
618
- end: insertionOffset,
619
- value: formatStoryboardElement({
620
- source: options.source,
621
- insertionOffset,
622
- tag: options.tag,
623
- storyboard: options.storyboard,
624
- componentExpression: options.componentExpression
625
- })
626
- };
627
- }
628
- const openingSpan = options.parsed.canvasOpeningElementSpan;
629
- if (!openingSpan) {
630
- throw new Error("Canvas closing element not found");
631
- }
632
- const openingSource = options.source.slice(
633
- openingSpan.start,
634
- openingSpan.end
635
- );
636
- const selfClosingMatch = openingSource.match(/\s*\/\s*>$/);
637
- const canvasName = openingSource.match(
638
- /^<\s*([A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*)/
639
- )?.[1];
640
- if (!selfClosingMatch || !canvasName) {
641
- throw new Error("Canvas closing element not found");
642
- }
643
- const newline = detectNewline(options.source);
644
- const replacementStart = openingSpan.end - selfClosingMatch[0].length;
645
- const closingIndent = lineIndentAt(options.source, openingSpan.start);
646
- const childIndent = `${closingIndent} `;
647
- const propIndent = `${childIndent} `;
648
- const props = storyboardElementProps(
649
- options.storyboard,
650
- options.componentExpression
651
- );
652
- return {
653
- start: replacementStart,
654
- end: openingSpan.end,
655
- value: `>${newline}${childIndent}<${options.tag}${newline}${props.map((prop) => `${propIndent}${prop}`).join(
656
- newline
657
- )}${newline}${childIndent}/>${newline}${closingIndent}</${canvasName}>`
658
- };
659
- }
660
- function storyboardElementProps(storyboard, componentExpression) {
661
- const idProp = formatJsxStringAttribute(
662
- "id",
663
- requireNonEmpty(storyboard.id, "Storyboard id")
664
- );
665
- if (storyboard.kind === "legacy-v1") {
666
- return [idProp, `storyboard={${storyboard.storyboardExpression}}`];
667
- }
668
- if ((storyboard.kind === "route" || storyboard.kind === "html" || storyboard.kind === "flutter") && (storyboard.layout.width === void 0 || storyboard.layout.height === void 0)) {
669
- throw new Error("Route, HTML and Flutter layouts require width and height");
670
- }
671
- return [
672
- idProp,
673
- ...storyboard.name && storyboard.name.trim() !== "" ? [formatJsxStringAttribute("name", storyboard.name)] : [],
674
- ...storyboardKindProps(storyboard, componentExpression),
675
- `layout={{ ${formatLayout(storyboard.layout)} }}`
676
- ];
677
- }
678
- function formatJsxStringAttribute(name, value) {
679
- const encoded = JSON.stringify(value);
680
- const plainSafe = encoded === `"${value}"` && !value.includes("&");
681
- return plainSafe ? `${name}=${encoded}` : `${name}={${encoded}}`;
682
- }
683
- function storyboardKindProps(storyboard, componentExpression) {
684
- if (storyboard.kind === "component") {
685
- return [
686
- `component={${componentExpression}}`,
687
- ...storyboard.props && storyboard.props.trim() !== "" ? [`props={${storyboard.props.trim()}}`] : []
688
- ];
689
- }
690
- if (storyboard.kind === "route") {
691
- return [formatJsxStringAttribute("route", storyboard.route)];
692
- }
693
- if (storyboard.kind === "flutter") {
694
- return [formatJsxStringAttribute("preview", storyboard.preview)];
695
- }
696
- return [
697
- ...storyboard.filepath ? [formatJsxStringAttribute("filepath", storyboard.filepath)] : [],
698
- ...storyboard.src ? [formatJsxStringAttribute("src", storyboard.src)] : []
699
- ];
700
- }
701
- function formatLayout(layout) {
702
- return [
703
- `x: ${roundLayoutNumber(layout.x)}`,
704
- `y: ${roundLayoutNumber(layout.y)}`,
705
- ...layout.width === void 0 ? [] : [`width: ${roundLayoutNumber(layout.width)}`],
706
- ...layout.height === void 0 ? [] : [`height: ${roundLayoutNumber(layout.height)}`],
707
- ...layout.zIndex === void 0 ? [] : [`zIndex: ${roundLayoutNumber(layout.zIndex)}`],
708
- ...layout.intrinsicSizing === void 0 ? [] : [`intrinsicSizing: ${JSON.stringify(layout.intrinsicSizing)}`]
709
- ].join(", ");
710
- }
711
- function sdkComponentForStoryboard(storyboard) {
712
- if (storyboard.kind === "route") return "RouteStoryboard";
713
- if (storyboard.kind === "html") return "HtmlStoryboard";
714
- if (storyboard.kind === "flutter") return "FlutterStoryboard";
715
- if (storyboard.kind === "legacy-v1") return "LegacyStoryboardV1";
716
- return storyboardComponentForFramework(storyboard.uiFramework);
717
- }
718
- function resolveSdkTag(parsed, component) {
719
- const sdkSource = STORYBOARD_SDK_COMPONENTS[component].importSource;
720
- for (const item of parsed.imports) {
721
- if (item.source !== sdkSource) continue;
722
- if (item.kind === "namespace")
723
- return { tag: `${item.localName}.${component}` };
724
- if (item.importedName === component) return { tag: item.localName };
725
- }
726
- const localName = pickAvailableIdentifier(parsed, `TempoCanvas${component}`);
727
- return {
728
- tag: localName,
729
- importLine: `import { ${component} as ${localName} } from "${sdkSource}";`
730
- };
731
- }
732
- function buildMissingComponentImportLine(parsed, source, componentImport) {
733
- const existing = parsed.imports.find(
734
- (item) => item.localName === componentImport.localName
735
- );
736
- if (existing) {
737
- if (existing.source !== componentImport.source) {
738
- throw new Error(
739
- `Import binding "${componentImport.localName}" already exists`
740
- );
741
- }
742
- return null;
743
- }
744
- if (sourceContainsIdentifierNode(
745
- parsed.filePath,
746
- source,
747
- componentImport.localName
748
- )) {
749
- throw new Error(`Identifier "${componentImport.localName}" already exists`);
750
- }
751
- if (!componentImport.importedName || componentImport.importedName === "default") {
752
- return `import ${componentImport.localName} from ${JSON.stringify(
753
- componentImport.source
754
- )};`;
755
- }
756
- const specifier = componentImport.importedName === componentImport.localName ? componentImport.localName : `${componentImport.importedName} as ${componentImport.localName}`;
757
- return `import { ${specifier} } from ${JSON.stringify(componentImport.source)};`;
758
- }
759
- function buildImportInsertionEdit(source, parsed, importLines) {
760
- if (importLines.length === 0) return null;
761
- const newline = detectNewline(source);
762
- const uniqueLines = Array.from(new Set(importLines));
763
- const lastImport = parsed.imports.reduce(
764
- (latest, item) => !latest || item.declarationSpan.end > latest.declarationSpan.end ? item : latest,
765
- null
766
- );
767
- if (lastImport) {
768
- return {
769
- start: lastImport.declarationSpan.end,
770
- end: lastImport.declarationSpan.end,
771
- value: `${newline}${uniqueLines.join(newline)}`
772
- };
773
- }
774
- const offset = topLevelInsertionOffset(source);
775
- return {
776
- start: offset,
777
- end: offset,
778
- value: `${uniqueLines.join(newline)}${newline}`
779
- };
780
- }
781
- function buildUnusedComponentImportRemoval(options) {
782
- const componentImport = options.deletedStoryboard.component?.import;
783
- if (!componentImport || componentImport.importKind === "type") return null;
784
- const usedByRemainingStoryboard = options.parsed.storyboards.some(
785
- (storyboard) => storyboard.storyboardKey !== options.deletedStoryboard.storyboardKey && storyboard.component?.import?.localName === componentImport.localName
786
- );
787
- if (usedByRemainingStoryboard) return null;
788
- const sourceAfterStoryboardDelete = applyCanvasSourceEdits(options.source, [
789
- options.deletionEdit
790
- ]);
791
- if (componentImport.specifierCount === 1) {
792
- const sourceWithoutImport2 = removeSpanText(
793
- sourceAfterStoryboardDelete,
794
- componentImport.declarationSpan
795
- );
796
- if (hasIdentifier(sourceWithoutImport2, componentImport.localName))
797
- return null;
798
- return {
799
- ...expandToFullLines(options.source, componentImport.declarationSpan),
800
- value: ""
801
- };
802
- }
803
- if (componentImport.kind !== "named" || componentImport.hasDefaultSpecifier || componentImport.hasNamespaceSpecifier || componentImport.namedSpecifierCount <= 1) {
804
- return null;
805
- }
806
- const specifierRange = expandImportSpecifierRemovalRange(
807
- options.source,
808
- componentImport.span
809
- );
810
- const sourceWithoutImport = removeSpanText(
811
- sourceAfterStoryboardDelete,
812
- specifierRange
813
- );
814
- if (hasIdentifier(sourceWithoutImport, componentImport.localName))
815
- return null;
816
- return {
817
- ...specifierRange,
818
- value: ""
819
- };
820
- }
821
- function expandImportSpecifierRemovalRange(source, span) {
822
- const lineStart = Math.max(source.lastIndexOf("\n", span.start - 1) + 1, 0);
823
- const nextNewline = source.indexOf("\n", span.end);
824
- const lineEnd = nextNewline >= 0 ? nextNewline + 1 : source.length;
825
- const before = source.slice(lineStart, span.start);
826
- const after = source.slice(span.end, lineEnd);
827
- if (/^[ \t]*$/.test(before) && /^[ \t]*(,)?[ \t]*(\r?\n)?$/.test(after)) {
828
- return { start: lineStart, end: lineEnd };
829
- }
830
- let start = span.start;
831
- let end = span.end;
832
- while (end < source.length && /\s/.test(source[end] ?? "")) end++;
833
- if (source[end] === ",") {
834
- end++;
835
- while (end < source.length && (source[end] === " " || source[end] === " ")) {
836
- end++;
837
- }
838
- return { start, end };
839
- }
840
- while (start > 0 && (source[start - 1] === " " || source[start - 1] === " ")) {
841
- start--;
842
- }
843
- if (source[start - 1] === ",") {
844
- start--;
845
- while (start > 0 && (source[start - 1] === " " || source[start - 1] === " ")) {
846
- start--;
847
- }
848
- }
849
- return { start, end };
850
- }
851
- function removeSpanText(source, span) {
852
- return source.slice(0, span.start) + source.slice(span.end);
853
- }
854
- function findOpeningElementAttributeInsertionOffset(source, span) {
855
- const close = source.lastIndexOf(">", span.end - 1);
856
- if (close < span.start) {
857
- throw new Error("JSX opening element close not found");
858
- }
859
- return source[close - 1] === "/" ? close - 1 : close;
860
- }
861
- function insertBareJsxAttributeLine(options) {
862
- const offset = findOpeningElementAttributeInsertionOffset(
863
- options.source,
864
- options.openingElementSpan
865
- );
866
- const newline = detectNewline(options.source);
867
- const openingIndent = lineIndentAt(
868
- options.source,
869
- options.openingElementSpan.start
870
- );
871
- const openingLineEnd = options.source.indexOf(
872
- "\n",
873
- options.openingElementSpan.start
874
- );
875
- const existingAttributeIndent = openingLineEnd >= 0 && openingLineEnd < offset ? options.source.slice(openingLineEnd + 1, offset).split(/\r?\n/).find((line) => line.trim() !== "")?.match(/^[ \t]*/)?.[0] : void 0;
876
- const attributeIndent = existingAttributeIndent && existingAttributeIndent.length > openingIndent.length ? existingAttributeIndent : `${openingIndent}${openingIndent.includes(" ") ? " " : " "}`;
877
- const closingLineStart = Math.max(
878
- options.source.lastIndexOf("\n", offset - 1) + 1,
879
- 0
880
- );
881
- if (/^[ \t]*$/.test(options.source.slice(closingLineStart, offset))) {
882
- return {
883
- start: closingLineStart,
884
- end: closingLineStart,
885
- value: `${attributeIndent}${options.name}${newline}`
886
- };
887
- }
888
- let start = offset;
889
- while (start > options.openingElementSpan.start && (options.source[start - 1] === " " || options.source[start - 1] === " ")) {
890
- start--;
891
- }
892
- return {
893
- start,
894
- end: offset,
895
- value: `${newline}${attributeIndent}${options.name}${newline}${openingIndent}`
896
- };
897
- }
898
- function expandJsxAttributeRemoval(source, span) {
899
- const lineStart = Math.max(source.lastIndexOf("\n", span.start - 1) + 1, 0);
900
- const nextNewline = source.indexOf("\n", span.end);
901
- const lineEnd = nextNewline >= 0 ? nextNewline : source.length;
902
- if (/^[ \t]*$/.test(source.slice(lineStart, span.start)) && /^[ \t]*$/.test(source.slice(span.end, lineEnd))) {
903
- return {
904
- start: lineStart,
905
- end: nextNewline >= 0 ? nextNewline + 1 : lineEnd
906
- };
907
- }
908
- let start = span.start;
909
- let end = span.end;
910
- while (start > 0 && (source[start - 1] === " " || source[start - 1] === " ")) {
911
- start--;
912
- }
913
- while (end < source.length && (source[end] === " " || source[end] === " ")) {
914
- end++;
915
- }
916
- return { start, end };
917
- }
918
- function expandObjectPropertyRemoval(source, span) {
919
- let start = span.start;
920
- let end = span.end;
921
- while (start > 0 && /\s/.test(source[start - 1] ?? "")) start--;
922
- while (end < source.length && /\s/.test(source[end] ?? "")) end++;
923
- if (source[end] === ",") {
924
- end++;
925
- while (end < source.length && (source[end] === " " || source[end] === " ")) {
926
- end++;
927
- }
928
- return { start, end };
929
- }
930
- let comma = start - 1;
931
- while (comma >= 0 && /\s/.test(source[comma] ?? "")) comma--;
932
- if (source[comma] === ",") {
933
- start = comma;
934
- }
935
- return { start, end };
936
- }
937
- function expandToFullLines(source, span) {
938
- let start = span.start;
939
- let end = span.end;
940
- while (start > 0 && source[start - 1] !== "\n" && source[start - 1] !== "\r") {
941
- start--;
942
- }
943
- if (start > 0) {
944
- if (source[start - 1] === "\n") start--;
945
- if (start > 0 && source[start - 1] === "\r") start--;
946
- }
947
- while (end < source.length && (source[end] === " " || source[end] === " ")) {
948
- end++;
949
- }
950
- if (source.slice(end, end + 2) === "\r\n") {
951
- end += 2;
952
- } else if (source[end] === "\n" || source[end] === "\r") {
953
- end++;
954
- }
955
- return { start, end };
956
- }
957
- function expandStatementForward(source, span) {
958
- let end = span.end;
959
- while (end < source.length && (source[end] === " " || source[end] === " ")) {
960
- end++;
961
- }
962
- if (source.slice(end, end + 2) === "\r\n") {
963
- end += 2;
964
- } else if (source[end] === "\n" || source[end] === "\r") {
965
- end++;
966
- }
967
- return { start: span.start, end };
968
- }
969
- function lineIndentAt(source, offset) {
970
- const lineStart = Math.max(source.lastIndexOf("\n", offset - 1) + 1, 0);
971
- const linePrefix = source.slice(lineStart, offset);
972
- const match = linePrefix.match(/^[ \t]*/);
973
- return match?.[0] ?? "";
974
- }
975
- function previousMeaningfulCharacter(source, offset) {
976
- for (let index = offset - 1; index >= 0; index -= 1) {
977
- const character = source[index] ?? "";
978
- if (!/\s/.test(character)) return character;
979
- }
980
- return "";
981
- }
982
- function trimWhitespaceBeforeOffset(source, offset) {
983
- let nextOffset = offset;
984
- while (nextOffset > 0 && /\s/.test(source[nextOffset - 1] ?? "")) {
985
- nextOffset--;
986
- }
987
- return nextOffset;
988
- }
989
- function collapseBlankLines(source, newline) {
990
- return newline === "\r\n" ? source.replace(/(\r\n){3,}/g, "\r\n\r\n") : source.replace(/\n{3,}/g, "\n\n");
991
- }
992
- function detectNewline(source) {
993
- return source.includes("\r\n") ? "\r\n" : "\n";
994
- }
995
- function topLevelInsertionOffset(source) {
996
- let offset = 0;
997
- if (source.startsWith("#!")) {
998
- const newline = source.indexOf("\n");
999
- offset = newline >= 0 ? newline + 1 : source.length;
1000
- }
1001
- while (true) {
1002
- const nextLineEnd = source.indexOf("\n", offset);
1003
- const end = nextLineEnd >= 0 ? nextLineEnd + 1 : source.length;
1004
- const line = source.slice(offset, end).trim();
1005
- if (!/^["']use [^"']+["'];?$/.test(line)) break;
1006
- offset = end;
1007
- }
1008
- return offset;
1009
- }
1010
- function pickAvailableIdentifier(parsed, base) {
1011
- const usedImports = new Set(parsed.imports.map((item) => item.localName));
1012
- if (!usedImports.has(base)) return base;
1013
- for (let index = 2; index < 1e4; index += 1) {
1014
- const candidate = `${base}${index}`;
1015
- if (!usedImports.has(candidate)) return candidate;
1016
- }
1017
- throw new Error(`Unable to find available identifier for ${base}`);
1018
- }
1019
- function hasIdentifier(source, identifier) {
1020
- return new RegExp(`\\b${escapeRegExp(identifier)}\\b`).test(source);
1021
- }
1022
- function sourceContainsIdentifierNode(filePath, source, name) {
1023
- const program = parseSync(filePath, source).program;
1024
- let found = false;
1025
- walkWithParent(program, (node) => {
1026
- if (found) return;
1027
- if ((node.type === "Identifier" || node.type === "JSXIdentifier") && node.name === name) {
1028
- found = true;
1029
- }
1030
- });
1031
- return found;
1032
- }
1033
- function walkWithParent(node, visit, parent = null, key = null, seen = /* @__PURE__ */ new Set()) {
1034
- if (!node || typeof node !== "object" || seen.has(node)) return;
1035
- seen.add(node);
1036
- if (typeof node.type === "string") visit(node, parent, key);
1037
- for (const [childKey, value] of Object.entries(node)) {
1038
- if (!value || typeof value !== "object") continue;
1039
- if (Array.isArray(value)) {
1040
- for (const item of value)
1041
- walkWithParent(item, visit, node, childKey, seen);
1042
- } else {
1043
- walkWithParent(value, visit, node, childKey, seen);
1044
- }
1045
- }
1046
- }
1047
- function escapeRegExp(value) {
1048
- return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1049
- }
1050
- function roundLayoutNumber(value) {
1051
- if (typeof value !== "number" || !Number.isFinite(value)) {
1052
- throw new Error("Layout values must be finite numbers");
1053
- }
1054
- return Math.round(value);
1055
- }
1056
- function requireNonEmpty(value, label) {
1057
- const trimmed = value.trim();
1058
- if (!trimmed) {
1059
- throw new Error(`${label} must be non-empty`);
1060
- }
1061
- return trimmed;
1062
- }
1063
- function requiredSpan(value, message) {
1064
- if (value === void 0) {
1065
- throw new Error(message);
1066
- }
1067
- return value;
1068
- }
1069
- export {
1070
- addCanvasStoryboard,
1071
- applyCanvasSourceEdits,
1072
- collapseBlankLines,
1073
- detectNewline,
1074
- expandStatementForward,
1075
- expandToFullLines,
1076
- formatJsxStringAttribute,
1077
- hasIdentifier,
1078
- removeCanvasStoryboard,
1079
- sourceContainsIdentifierNode,
1080
- topLevelInsertionOffset,
1081
- updateCanvasBackgroundColor,
1082
- updateCanvasName,
1083
- updateCanvasPath,
1084
- updateHtmlStoryboardSource,
1085
- updateRouteStoryboardRoute,
1086
- updateStoryboardComponent,
1087
- updateStoryboardId,
1088
- updateStoryboardLayout,
1089
- updateStoryboardName,
1090
- updateStoryboardProps,
1091
- updateStoryboardVrt,
1092
- walkWithParent
1093
- };
1094
- //# sourceMappingURL=editor.js.map
1
+ import{b as t}from"../chunk-QNVQ7U2W.js";import"../chunk-XUSV3KOD.js";var a=t("canvas/editor","applyCanvasSourceEdits"),e=t("canvas/editor","updateCanvasName"),r=t("canvas/editor","updateCanvasPath"),n=t("canvas/editor","updateCanvasBackgroundColor"),d=t("canvas/editor","updateStoryboardName"),p=t("canvas/editor","updateStoryboardId"),s=t("canvas/editor","updateStoryboardLayout"),c=t("canvas/editor","updateStoryboardComponent"),i=t("canvas/editor","updateStoryboardProps"),u=t("canvas/editor","updateStoryboardVrt"),y=t("canvas/editor","updateRouteStoryboardRoute"),C=t("canvas/editor","updateHtmlStoryboardSource"),v=t("canvas/editor","addCanvasStoryboard"),S=t("canvas/editor","removeCanvasStoryboard"),f=t("canvas/editor","formatJsxStringAttribute"),b=t("canvas/editor","expandToFullLines"),l=t("canvas/editor","expandStatementForward"),x=t("canvas/editor","collapseBlankLines"),m=t("canvas/editor","detectNewline"),I=t("canvas/editor","topLevelInsertionOffset"),L=t("canvas/editor","hasIdentifier"),N=t("canvas/editor","sourceContainsIdentifierNode"),h=t("canvas/editor","walkWithParent");export{v as addCanvasStoryboard,a as applyCanvasSourceEdits,x as collapseBlankLines,m as detectNewline,l as expandStatementForward,b as expandToFullLines,f as formatJsxStringAttribute,L as hasIdentifier,S as removeCanvasStoryboard,N as sourceContainsIdentifierNode,I as topLevelInsertionOffset,n as updateCanvasBackgroundColor,e as updateCanvasName,r as updateCanvasPath,C as updateHtmlStoryboardSource,y as updateRouteStoryboardRoute,c as updateStoryboardComponent,p as updateStoryboardId,s as updateStoryboardLayout,d as updateStoryboardName,i as updateStoryboardProps,u as updateStoryboardVrt,h as walkWithParent};