tempo-sdk 0.0.99 → 0.0.102

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-CXCUJCXD.js +1 -0
  37. package/dist/chunk-FH6TMWFA.js +1 -0
  38. package/dist/chunk-FL7FSJSL.js +1 -0
  39. package/dist/chunk-GQIOB5SV.js +1 -0
  40. package/dist/chunk-HBQ7FFH7.js +1 -0
  41. package/dist/chunk-JRJOWLCN.js +1 -0
  42. package/dist/chunk-LJCBFTMP.js +1 -0
  43. package/dist/chunk-M3GN2KUH.js +1 -0
  44. package/dist/chunk-MPIHFFML.js +1 -0
  45. package/dist/chunk-T5TY3U2H.js +1 -0
  46. package/dist/chunk-XO2BSHWM.js +1 -0
  47. package/dist/chunk-XUSV3KOD.js +1 -0
  48. package/dist/chunk-ZXBMP6RV.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,573 +1 @@
1
- import {
2
- ASSET_SDK_IMPORT_SOURCE,
3
- collectIdentifierNames,
4
- collectTopLevelScope,
5
- hasTopLevelDefineAssetCallFor,
6
- parseAssetFile,
7
- parseAssetProgram,
8
- readAssetImports,
9
- toSourceSpan,
10
- unwrapTsExpression
11
- } from "../chunk-PYAJHLXO.js";
12
- import {
13
- isUnresolvedValue
14
- } from "../chunk-DI2ZFAWL.js";
15
-
16
- // assets/editor.ts
17
- function ensureNamedDefaultExport(options) {
18
- const { program, errors } = parseAssetProgram(options.filePath, options.source);
19
- if (!program) {
20
- return failure(
21
- "not_definable",
22
- errors[0]?.message ?? "asset source has syntax errors"
23
- );
24
- }
25
- const statement = (program.body ?? []).find(
26
- (node) => node?.type === "ExportDefaultDeclaration"
27
- );
28
- if (!statement) {
29
- return failure("export_not_found", `no default export in ${options.filePath}`);
30
- }
31
- const declaration = statement.declaration;
32
- const isDeclarationForm = declaration?.type === "FunctionDeclaration" || declaration?.type === "ClassDeclaration";
33
- if (isDeclarationForm && typeof declaration.id?.name === "string") {
34
- return {
35
- ok: true,
36
- source: options.source,
37
- changed: false,
38
- bindingName: declaration.id.name
39
- };
40
- }
41
- if (!isDeclarationForm) {
42
- const expression = unwrapTsExpression(declaration);
43
- if (expression?.type === "Identifier") {
44
- return {
45
- ok: true,
46
- source: options.source,
47
- changed: false,
48
- bindingName: expression.name
49
- };
50
- }
51
- }
52
- const statementSpan = toSourceSpan(statement);
53
- const declarationSpan = toSourceSpan(declaration);
54
- if (!statementSpan || !declarationSpan) {
55
- return failure("not_definable", "default export has no source span");
56
- }
57
- const bindingName = pickAvailableName(
58
- deriveDefaultExportName(options.filePath),
59
- collectIdentifierNames(program)
60
- );
61
- if (bindingName === void 0) {
62
- return failure(
63
- "not_definable",
64
- "could not derive a free identifier for the default export"
65
- );
66
- }
67
- const newline = detectNewline(options.source);
68
- let edits;
69
- if (isDeclarationForm) {
70
- const head = options.source.slice(
71
- declarationSpan.start,
72
- declarationSpan.start + 64
73
- );
74
- const keyword = declaration.type === "FunctionDeclaration" ? head.match(/^(?:async\s+)?function(?:\s*\*)?/) : head.match(/^class\b/);
75
- if (!keyword) {
76
- return failure("not_definable", "unsupported default export shape");
77
- }
78
- const nameOffset = declarationSpan.start + keyword[0].length;
79
- let nameEnd = nameOffset;
80
- while (nameEnd < options.source.length && /\s/.test(options.source[nameEnd] ?? "")) {
81
- nameEnd++;
82
- }
83
- const nameValue = options.source[nameEnd] === "(" ? ` ${bindingName}` : ` ${bindingName} `;
84
- edits = [
85
- { start: statementSpan.start, end: declarationSpan.start, value: "" },
86
- { start: nameOffset, end: nameEnd, value: nameValue },
87
- {
88
- start: statementSpan.end,
89
- end: statementSpan.end,
90
- value: `${newline}export default ${bindingName};`
91
- }
92
- ];
93
- } else {
94
- edits = [
95
- {
96
- start: statementSpan.start,
97
- end: declarationSpan.start,
98
- value: `const ${bindingName} = `
99
- },
100
- {
101
- start: declarationSpan.end,
102
- end: statementSpan.end,
103
- value: `;${newline}export default ${bindingName};`
104
- }
105
- ];
106
- }
107
- return { ...applyEdits(options.source, edits), bindingName };
108
- }
109
- function ensureAssetDeclaration(options) {
110
- const { program, errors } = parseAssetProgram(options.filePath, options.source);
111
- if (!program) {
112
- return failure(
113
- "not_definable",
114
- errors[0]?.message ?? "asset source has syntax errors"
115
- );
116
- }
117
- const parsed = parseAssetFile(options.filePath, options.source);
118
- if (parsed.declarations.some(
119
- (declaration) => declaration.bindingName === options.bindingName
120
- )) {
121
- return { ok: true, source: options.source, changed: false };
122
- }
123
- const imports = readAssetImports(program);
124
- if (hasTopLevelDefineAssetCallFor(
125
- program,
126
- imports.trustedDefineAssetNames,
127
- options.bindingName
128
- )) {
129
- return failure(
130
- "config_not_editable",
131
- `an existing defineAsset declaration for "${options.bindingName}" has structural errors \u2014 fix it instead of adding another`
132
- );
133
- }
134
- const binding = collectTopLevelScope(program).bindings.get(
135
- options.bindingName
136
- );
137
- if (!binding) {
138
- const importSource = imports.importedBindings.get(options.bindingName);
139
- return failure(
140
- "not_definable",
141
- importSource !== void 0 ? `"${options.bindingName}" is imported from "${importSource}" \u2014 defineAsset must live in the file that defines the component` : `no top-level binding "${options.bindingName}" in ${options.filePath}`
142
- );
143
- }
144
- const style = detectCodeStyle(options.source);
145
- const edits = [];
146
- let callName;
147
- if (imports.trustedDefineAssetNames.size > 0) {
148
- callName = imports.trustedDefineAssetNames.values().next().value;
149
- } else {
150
- const identifiers = collectIdentifierNames(program);
151
- if (identifiers.has("defineAsset")) {
152
- const picked = pickAvailableName("defineAsset", identifiers);
153
- if (picked === void 0) {
154
- return failure(
155
- "not_definable",
156
- "could not derive a free identifier for the defineAsset import"
157
- );
158
- }
159
- callName = picked;
160
- } else {
161
- callName = "defineAsset";
162
- }
163
- const specifier = callName === "defineAsset" ? "defineAsset" : `defineAsset as ${callName}`;
164
- const importLine = `import { ${specifier} } from ${quoteString(
165
- ASSET_SDK_IMPORT_SOURCE,
166
- style.quote
167
- )};`;
168
- edits.push(
169
- buildImportInsertionEdit(
170
- options.source,
171
- imports.importDeclarationSpans,
172
- importLine,
173
- style.newline
174
- )
175
- );
176
- }
177
- const callText = serializeDefineAssetCall(
178
- callName,
179
- options.bindingName,
180
- options.initialConfig ?? {},
181
- style
182
- );
183
- const insertionOffset = statementInsertionOffset(
184
- options.source,
185
- binding.statementSpan.end
186
- );
187
- edits.push({
188
- start: insertionOffset,
189
- end: insertionOffset,
190
- value: `${style.newline}${style.newline}${callText}`
191
- });
192
- return applyEdits(options.source, edits);
193
- }
194
- function addLibraries(options) {
195
- const located = locateDeclaration(options);
196
- if (!located.ok) return located;
197
- const { declaration } = located;
198
- const names = [];
199
- for (const name of options.libraries) {
200
- if (name === "") continue;
201
- if (declaration.libraries.includes(name)) continue;
202
- if (names.includes(name)) continue;
203
- names.push(name);
204
- }
205
- if (names.length === 0) {
206
- return { ok: true, source: options.source, changed: false };
207
- }
208
- const style = detectCodeStyle(options.source);
209
- const serialized = names.map((name) => quoteString(name, style.quote)).join(", ");
210
- const spans = declaration.spans;
211
- if (spans.libraries) {
212
- const lastItem = spans.libraryItems[spans.libraryItems.length - 1];
213
- if (lastItem) {
214
- return applyEdits(options.source, [
215
- { start: lastItem.end, end: lastItem.end, value: `, ${serialized}` }
216
- ]);
217
- }
218
- const inner = options.source.slice(
219
- spans.libraries.start + 1,
220
- spans.libraries.end - 1
221
- );
222
- const offset = spans.libraries.start + 1;
223
- const value = inner.trim() === "" ? serialized : `${serialized}, `;
224
- return applyEdits(options.source, [{ start: offset, end: offset, value }]);
225
- }
226
- if (spans.librariesProperty) {
227
- return failure(
228
- "config_not_editable",
229
- `the libraries property of "${options.bindingName}" is not an editable array literal`
230
- );
231
- }
232
- return applyEdits(options.source, [
233
- insertConfigProperty(
234
- options.source,
235
- spans.config,
236
- `libraries: [${serialized}]`,
237
- style
238
- )
239
- ]);
240
- }
241
- function removeLibraries(options) {
242
- const targets = new Set(options.libraries.filter((name) => name !== ""));
243
- let located = locateDeclaration(options);
244
- if (!located.ok) return located;
245
- if (targets.size > 0 && located.declaration.spans.librariesProperty && !located.declaration.spans.libraries) {
246
- return failure(
247
- "config_not_editable",
248
- `the libraries property of "${options.bindingName}" is not an editable array literal`
249
- );
250
- }
251
- let source = options.source;
252
- let changed = false;
253
- for (let iteration = 0; iteration < 32; iteration++) {
254
- const declaration = located.declaration;
255
- const removals = [];
256
- declaration.libraries.forEach((name, index) => {
257
- const span = declaration.spans.libraryItems[index];
258
- if (targets.has(name) && span) {
259
- removals.push(expandListItemRemoval(source, span));
260
- }
261
- });
262
- if (removals.length === 0) break;
263
- source = spliceRemovals(source, removals);
264
- changed = true;
265
- const relocated = locateDeclaration({ ...options, source });
266
- if (!relocated.ok) return relocated;
267
- located = relocated;
268
- }
269
- if (changed) {
270
- const spans = located.declaration.spans;
271
- if (spans.libraries && spans.librariesProperty && /^\s*$/.test(
272
- source.slice(spans.libraries.start + 1, spans.libraries.end - 1)
273
- )) {
274
- source = spliceRemovals(source, [
275
- expandListItemRemoval(source, spans.librariesProperty)
276
- ]);
277
- }
278
- }
279
- return { ok: true, source, changed };
280
- }
281
- function locateDeclaration(options) {
282
- const { program, errors } = parseAssetProgram(options.filePath, options.source);
283
- if (!program) {
284
- return failure(
285
- "config_not_editable",
286
- errors[0]?.message ?? "asset source has syntax errors"
287
- );
288
- }
289
- const parsed = parseAssetFile(options.filePath, options.source);
290
- const declaration = parsed.declarations.find(
291
- (candidate) => candidate.bindingName === options.bindingName
292
- );
293
- if (declaration) return { ok: true, declaration };
294
- const imports = readAssetImports(program);
295
- if (hasTopLevelDefineAssetCallFor(
296
- program,
297
- imports.trustedDefineAssetNames,
298
- options.bindingName
299
- )) {
300
- return failure(
301
- "config_not_editable",
302
- `the defineAsset declaration for "${options.bindingName}" has structural errors and cannot be edited`
303
- );
304
- }
305
- return failure(
306
- "asset_not_found",
307
- `no defineAsset declaration for "${options.bindingName}" in ${options.filePath}`
308
- );
309
- }
310
- function failure(code, message) {
311
- return { ok: false, code, message };
312
- }
313
- function applyEdits(source, edits) {
314
- const sorted = [...edits].sort((left, right) => right.start - left.start);
315
- let previousStart = source.length + 1;
316
- let next = source;
317
- for (const edit of sorted) {
318
- if (edit.start < 0 || edit.end < edit.start || edit.end > previousStart) {
319
- throw new Error(
320
- `Invalid overlapping asset source edit ${edit.start}:${edit.end}`
321
- );
322
- }
323
- next = next.slice(0, edit.start) + edit.value + next.slice(edit.end);
324
- previousStart = edit.start;
325
- }
326
- return { ok: true, source: next, changed: next !== source };
327
- }
328
- function spliceRemovals(source, spans) {
329
- const sorted = [...spans].sort((left, right) => left.start - right.start);
330
- const merged = [];
331
- for (const span of sorted) {
332
- const last = merged[merged.length - 1];
333
- if (last && span.start <= last.end) {
334
- last.end = Math.max(last.end, span.end);
335
- } else {
336
- merged.push({ ...span });
337
- }
338
- }
339
- let result = source;
340
- for (let index = merged.length - 1; index >= 0; index--) {
341
- const span = merged[index];
342
- result = result.slice(0, span.start) + result.slice(span.end);
343
- }
344
- return result;
345
- }
346
- function expandListItemRemoval(source, span) {
347
- let { start, end } = span;
348
- let forward = end;
349
- while (forward < source.length && /\s/.test(source[forward] ?? "")) forward++;
350
- if (source[forward] === ",") {
351
- end = forward + 1;
352
- while (end < source.length && (source[end] === " " || source[end] === " ")) {
353
- end++;
354
- }
355
- return expandBlankLine(source, { start, end });
356
- }
357
- let backward = start;
358
- while (backward > 0 && /\s/.test(source[backward - 1] ?? "")) backward--;
359
- if (source[backward - 1] === ",") {
360
- return { start: backward - 1, end };
361
- }
362
- while (start > 0 && /\s/.test(source[start - 1] ?? "")) start--;
363
- while (end < source.length && /\s/.test(source[end] ?? "")) end++;
364
- return { start, end };
365
- }
366
- function expandBlankLine(source, span) {
367
- const lineStart = source.lastIndexOf("\n", span.start - 1) + 1;
368
- if (!/^[ \t]*$/.test(source.slice(lineStart, span.start))) return span;
369
- if (source.startsWith("\r\n", span.end)) {
370
- return { start: lineStart, end: span.end + 2 };
371
- }
372
- if (source[span.end] === "\n") {
373
- return { start: lineStart, end: span.end + 1 };
374
- }
375
- return span;
376
- }
377
- function insertConfigProperty(source, configSpan, propertyText, style) {
378
- const closeOffset = configSpan.end - 1;
379
- let offset = closeOffset;
380
- while (offset > configSpan.start + 1 && /\s/.test(source[offset - 1] ?? "")) {
381
- offset--;
382
- }
383
- const previous = source[offset - 1] ?? "";
384
- const multiline = source.slice(configSpan.start, configSpan.end).includes("\n");
385
- if (!multiline) {
386
- if (previous === "{") {
387
- return { start: offset, end: closeOffset, value: ` ${propertyText} ` };
388
- }
389
- return {
390
- start: offset,
391
- end: offset,
392
- value: previous === "," ? ` ${propertyText}` : `, ${propertyText}`
393
- };
394
- }
395
- if (previous === "{") {
396
- const baseIndent = lineIndentAt(source, configSpan.start);
397
- return {
398
- start: offset,
399
- end: offset,
400
- value: `${style.newline}${baseIndent}${style.indent}${propertyText},`
401
- };
402
- }
403
- const propertyIndent = lineIndentAt(source, offset);
404
- return {
405
- start: offset,
406
- end: offset,
407
- value: `${previous === "," ? "" : ","}${style.newline}${propertyIndent}${propertyText},`
408
- };
409
- }
410
- function buildImportInsertionEdit(source, importSpans, importLine, newline) {
411
- const last = importSpans[importSpans.length - 1];
412
- if (last) {
413
- return { start: last.end, end: last.end, value: `${newline}${importLine}` };
414
- }
415
- const offset = topLevelInsertionOffset(source);
416
- const nextChar = source[offset] ?? "";
417
- const prefix = offset > 0 ? newline : "";
418
- const suffix = nextChar === "\n" || nextChar === "\r" || nextChar === "" ? newline : `${newline}${newline}`;
419
- return {
420
- start: offset,
421
- end: offset,
422
- value: `${prefix}${importLine}${suffix}`
423
- };
424
- }
425
- function topLevelInsertionOffset(source) {
426
- let offset = 0;
427
- if (source.startsWith("#!")) {
428
- const newline = source.indexOf("\n");
429
- offset = newline >= 0 ? newline + 1 : source.length;
430
- }
431
- while (true) {
432
- const nextLineEnd = source.indexOf("\n", offset);
433
- const end = nextLineEnd >= 0 ? nextLineEnd + 1 : source.length;
434
- const line = source.slice(offset, end).trim();
435
- if (!/^["']use [^"']+["'];?$/.test(line)) break;
436
- offset = end;
437
- }
438
- return offset;
439
- }
440
- function statementInsertionOffset(source, statementEnd) {
441
- let offset = statementEnd;
442
- while (offset < source.length && (source[offset] === " " || source[offset] === " ")) {
443
- offset++;
444
- }
445
- if (source[offset] === "/" && source[offset + 1] === "/") {
446
- while (offset < source.length && source[offset] !== "\n" && source[offset] !== "\r") {
447
- offset++;
448
- }
449
- return offset;
450
- }
451
- return statementEnd;
452
- }
453
- function serializeDefineAssetCall(callName, bindingName, config, style) {
454
- const entries = [];
455
- if (config.usageInstructions !== void 0) {
456
- entries.push(["usageInstructions", config.usageInstructions]);
457
- }
458
- if (config.libraries !== void 0) {
459
- entries.push(["libraries", config.libraries]);
460
- }
461
- if (config.variants !== void 0) {
462
- entries.push(["variants", config.variants]);
463
- }
464
- if (entries.length === 0) return `${callName}(${bindingName}, {});`;
465
- const body = entries.map(
466
- ([key, value]) => `${style.indent}${key}: ${serializeStaticValue(value, style, 1)},`
467
- ).join(style.newline);
468
- return `${callName}(${bindingName}, {${style.newline}${body}${style.newline}});`;
469
- }
470
- function serializeStaticValue(value, style, depth) {
471
- if (isUnresolvedValue(value)) {
472
- throw new Error(
473
- "ensureAssetDeclaration initialConfig values must be fully static"
474
- );
475
- }
476
- if (value === null) return "null";
477
- if (typeof value === "string") return quoteString(value, style.quote);
478
- if (typeof value === "number" || typeof value === "boolean") {
479
- return String(value);
480
- }
481
- if (Array.isArray(value)) {
482
- if (value.length === 0) return "[]";
483
- if (value.every(isPrimitiveStaticValue)) {
484
- return `[${value.map((item) => serializeStaticValue(item, style, depth)).join(", ")}]`;
485
- }
486
- const inner2 = value.map(
487
- (item) => `${style.indent.repeat(depth + 1)}${serializeStaticValue(item, style, depth + 1)},`
488
- ).join(style.newline);
489
- return `[${style.newline}${inner2}${style.newline}${style.indent.repeat(depth)}]`;
490
- }
491
- const entries = Object.entries(value);
492
- if (entries.length === 0) return "{}";
493
- if (entries.every(([, item]) => isPrimitiveStaticValue(item))) {
494
- return `{ ${entries.map(
495
- ([key, item]) => `${serializeObjectKey(key, style)}: ${serializeStaticValue(item, style, depth)}`
496
- ).join(", ")} }`;
497
- }
498
- const inner = entries.map(
499
- ([key, item]) => `${style.indent.repeat(depth + 1)}${serializeObjectKey(key, style)}: ${serializeStaticValue(item, style, depth + 1)},`
500
- ).join(style.newline);
501
- return `{${style.newline}${inner}${style.newline}${style.indent.repeat(depth)}}`;
502
- }
503
- function isPrimitiveStaticValue(value) {
504
- return value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
505
- }
506
- function serializeObjectKey(key, style) {
507
- return /^[A-Za-z_$][\w$]*$/.test(key) ? key : quoteString(key, style.quote);
508
- }
509
- function quoteString(value, quote) {
510
- const json = JSON.stringify(value);
511
- if (quote === '"') return json;
512
- const inner = json.slice(1, -1).replace(/\\"/g, '"').replace(/'/g, "\\'");
513
- return `'${inner}'`;
514
- }
515
- function detectCodeStyle(source) {
516
- const doubles = (source.match(/"/g) ?? []).length;
517
- const singles = (source.match(/'/g) ?? []).length;
518
- let sawTab = false;
519
- let minSpaces = Number.POSITIVE_INFINITY;
520
- for (const line of source.split("\n")) {
521
- const match = line.match(/^([ \t]+)\S/);
522
- if (!match) continue;
523
- if (match[1].includes(" ")) {
524
- sawTab = true;
525
- break;
526
- }
527
- minSpaces = Math.min(minSpaces, match[1].length);
528
- }
529
- return {
530
- quote: singles > doubles ? "'" : '"',
531
- indent: sawTab ? " " : Number.isFinite(minSpaces) ? " ".repeat(minSpaces) : " ",
532
- newline: detectNewline(source)
533
- };
534
- }
535
- function detectNewline(source) {
536
- return source.includes("\r\n") ? "\r\n" : "\n";
537
- }
538
- function lineIndentAt(source, offset) {
539
- const lineStart = Math.max(source.lastIndexOf("\n", offset - 1) + 1, 0);
540
- const linePrefix = source.slice(lineStart, offset);
541
- return linePrefix.match(/^[ \t]*/)?.[0] ?? "";
542
- }
543
- function pickAvailableName(base, taken) {
544
- if (!taken.has(base)) return base;
545
- for (let index = 2; index < 1e4; index++) {
546
- const candidate = `${base}${index}`;
547
- if (!taken.has(candidate)) return candidate;
548
- }
549
- return void 0;
550
- }
551
- function deriveDefaultExportName(filePath) {
552
- const normalized = filePath.replace(/\\/g, "/");
553
- const segments = normalized.split("/").filter(Boolean);
554
- const fileName = segments[segments.length - 1] ?? "";
555
- if (/^index\.canvas\.[tj]sx?$/.test(fileName)) {
556
- const parent = segments[segments.length - 2] ?? "";
557
- const base = pascalCase(parent);
558
- return base === "" ? "Canvas" : `${base}Canvas`;
559
- }
560
- const name = pascalCase(fileName.replace(/\.[tj]sx?$/, ""));
561
- if (name === "") return "DefaultExport";
562
- return /^[0-9]/.test(name) ? `Component${name}` : name;
563
- }
564
- function pascalCase(value) {
565
- return value.split(/[^A-Za-z0-9]+/).filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
566
- }
567
- export {
568
- addLibraries,
569
- ensureAssetDeclaration,
570
- ensureNamedDefaultExport,
571
- removeLibraries
572
- };
573
- //# sourceMappingURL=editor.js.map
1
+ import{b as e}from"../chunk-ZXBMP6RV.js";import"../chunk-XUSV3KOD.js";var r=e("assets/editor","ensureNamedDefaultExport"),o=e("assets/editor","ensureAssetDeclaration"),s=e("assets/editor","addLibraries"),a=e("assets/editor","removeLibraries");export{s as addLibraries,o as ensureAssetDeclaration,r as ensureNamedDefaultExport,a as removeLibraries};
@@ -1,26 +1,25 @@
1
- import { A as AssetControls, a as AssetComponentProps, b as AssetControlDefinition } from '../controls-uCaQ3CNX.js';
2
- export { c as AssetPropControl } from '../controls-uCaQ3CNX.js';
1
+ import { A as AssetControls, a as AssetComponentProps, b as AssetControlDefinition } from '../controls-DKslABtM.js';
2
+ export { c as AssetPropControl } from '../controls-DKslABtM.js';
3
3
  import * as react from 'react';
4
4
  import { ComponentType, ComponentProps, ReactNode } from 'react';
5
5
  import { AstroComponent } from '../canvas/astro-contract.js';
6
- import { S as StaticValue } from '../types-C8OIU-kc.js';
6
+ import { S as StaticValue } from '../types-CfUgM2w4.js';
7
7
 
8
- /** One mounted component, driven by its editor. No file writes or captures on
9
- * variant/prop changes. Imports and source updates remain owned by Vite. */
10
- declare function AssetLivePreview({ component, sessionId, }: {
8
+ declare function AssetLivePreview$1({ component, sessionId, }: {
11
9
  component: ComponentType<any>;
12
10
  sessionId: string;
13
11
  }): react.JSX.Element;
14
12
 
15
- declare function getComponentControlsSnapshot(component: unknown): StaticValue;
16
- declare function getAssetConfigSnapshot(component: unknown): StaticValue;
13
+ declare const AssetLivePreview: typeof AssetLivePreview$1;
14
+
15
+ declare function getComponentControlsSnapshot$1(component: unknown): StaticValue;
16
+ declare function getAssetConfigSnapshot$1(component: unknown): StaticValue;
17
+
18
+ declare const getComponentControlsSnapshot: typeof getComponentControlsSnapshot$1;
19
+ declare const getAssetConfigSnapshot: typeof getAssetConfigSnapshot$1;
17
20
 
18
- /** Property key `defineAsset` attaches its config under. Non-enumerable so it
19
- * never leaks into spreads or serialization of the component value. */
20
21
  declare const TEMPO_ASSET_CONFIG_PROPERTY = "__tempoAssetConfig";
21
22
  type AssetVariant<P> = {
22
- /** Must satisfy the component's prop types. Kept required for source
23
- * compatibility with the original public asset-reader contract. */
24
23
  props: P;
25
24
  };
26
25
  type AssetRenderVariant = {
@@ -32,21 +31,9 @@ type AssetDefinitionVariant<P> = (AssetVariant<P> & {
32
31
  }) | AssetRenderVariant;
33
32
  type AssetVariants<P> = Record<string, AssetVariant<P>>;
34
33
  type AssetConfigBase = {
35
- /** What this asset is and when to reach for it — and when not (e.g. "form
36
- * submits, CTAs — not navigation (use Link)"). Shown on the asset detail
37
- * page and returned by the asset MCP tools. */
38
34
  usageInstructions?: string;
39
- /** Library names this asset belongs to. Arbitrary non-empty strings; a
40
- * library exists iff some asset names it. Unset/empty = library-less
41
- * (still an asset, still shown in the Assets tab). */
42
35
  libraries?: string[];
43
36
  };
44
- /**
45
- * `variants` is required exactly when the component has required props. This
46
- * preserves the public reader guarantees from the first published asset API.
47
- * `defineAsset` also accepts metadata-only and render-only declarations through
48
- * its additive authoring input below.
49
- */
50
37
  type AssetConfig<C extends ComponentType<any>> = AssetConfigBase & ({} extends ComponentProps<C> ? {
51
38
  variants?: AssetVariants<ComponentProps<C>>;
52
39
  } : {
@@ -57,43 +44,12 @@ type AssetDefinitionConfig<C extends ComponentType<any>> = AssetConfigBase & {
57
44
  };
58
45
  type AssetTarget = ComponentType<any> | AstroComponent<any>;
59
46
  type AssetTargetProps<C extends AssetTarget> = C extends ComponentType<any> ? ComponentProps<C> : C extends AstroComponent<infer Props> ? Props : never;
60
- /**
61
- * Declare a component or canvas as a design asset.
62
- *
63
- * Two supported shapes, both top-level statements. Prefer a declaration in a
64
- * canvas that curates the component — the
65
- * declaring canvas becomes the component's linked canvas:
66
- *
67
- * import { Button } from "@/components/Button";
68
- *
69
- * defineAsset(Button, {
70
- * usageInstructions: "form submits, CTAs — not navigation (use Link)",
71
- * variants: { Primary: { props: { label: "Buy now" } } },
72
- * });
73
- *
74
- * A legacy shape is the same statement in the file that defines the
75
- * component, placed after its definition — keeps working:
76
- *
77
- * export const Button = ({ label }: ButtonProps) => <button>{label}</button>;
78
- *
79
- * defineAsset(Button, {
80
- * libraries: ["core"],
81
- * variants: { Primary: { props: { label: "Buy now" } } },
82
- * });
83
- *
84
- * Returns void deliberately: `export default defineAsset(App, {...})` would
85
- * turn the export into a call expression and break React Fast Refresh's
86
- * component-only export analysis, so the wrapper form is a type error.
87
- */
88
47
  declare function defineAsset<C extends AssetTarget>(component: C, config: AssetConfigBase & {
89
48
  variants?: Record<string, C extends AstroComponent<any> ? AssetVariant<AssetTargetProps<C>> : AssetDefinitionVariant<AssetTargetProps<C>>>;
90
49
  }): void;
91
- /** Loosely-typed read shape: callers of getAssetConfig don't know the
92
- * component's prop types. */
93
50
  type ReadAssetConfig = AssetConfigBase & {
94
51
  variants?: AssetVariants<Record<string, unknown>>;
95
52
  };
96
- /** Read a config previously attached by `defineAsset`, if any. */
97
53
  declare function getAssetConfig(component: unknown): ReadAssetConfig | undefined;
98
54
 
99
55
  type ComponentControls<P> = AssetControls<P>;
@@ -103,12 +59,6 @@ type ComponentControlsTarget = {
103
59
  exportName?: string;
104
60
  };
105
61
  declare const TEMPO_CONTROLS_CONFIG_PROPERTY = "__tempoControlsConfig";
106
- /** Describe real prop editors once, independently of assets and libraries.
107
- * New components keep this call in their own file. Existing components may use
108
- * tempo/controls.ts to avoid editing app source. Both work across every canvas.
109
- * Legacy canvas declarations remain supported.
110
- * The returned cleanup is used by Tempo's development transform during HMR.
111
- */
112
62
  declare function defineControls<C extends AssetTarget, const Controls extends AssetControls<AssetTargetProps<NoInfer<C>>>>(component: C, controls: Controls & Record<Exclude<keyof Controls, keyof AssetComponentProps<AssetTargetProps<NoInfer<C>>>>, never>): () => void;
113
63
  declare function getComponentControls(component: unknown): {
114
64
  controls?: Record<string, AssetControlDefinition>;