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,903 +0,0 @@
1
- import {
2
- UNRESOLVED_VALUE,
3
- isUnresolvedValue
4
- } from "./chunk-DI2ZFAWL.js";
5
-
6
- // assets/parser.ts
7
- import { parseSync } from "oxc-parser";
8
- import { createRequire } from "module";
9
- function parseAstroAssetSource(source) {
10
- const result = createRequire(import.meta.url)("@astrojs/compiler-rs").parse(
11
- source
12
- );
13
- const errors = result.diagnostics.filter(
14
- (diagnostic) => diagnostic.severity === "error"
15
- );
16
- if (errors.length)
17
- throw new Error(errors.map((error) => error.text).join("\n"));
18
- return result.ast;
19
- }
20
- var ASSET_SDK_IMPORT_SOURCE = "tempo-sdk/assets";
21
- function parseAssetFile(filePath, source, parsed = parseAssetProgram(filePath, source)) {
22
- const { program } = parsed;
23
- const errors = [...parsed.errors];
24
- if (!program) {
25
- return { filePath, declarations: [], errors };
26
- }
27
- const imports = readAssetImports(program);
28
- for (const misimport of imports.misimports) {
29
- errors.push({
30
- code: "misimported_define_asset",
31
- severity: "structural",
32
- message: `defineAsset must be imported from "${ASSET_SDK_IMPORT_SOURCE}" \u2014 found import from "${misimport.source}"`,
33
- span: misimport.span
34
- });
35
- }
36
- const constants = /* @__PURE__ */ new Map();
37
- for (const statement of program.body) {
38
- const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
39
- if (declaration?.type !== "VariableDeclaration" || declaration.kind !== "const")
40
- continue;
41
- for (const binding of declaration.declarations)
42
- if (binding.id.type === "Identifier" && binding.init)
43
- constants.set(binding.id.name, binding.init);
44
- }
45
- const resolveConstants = (node, seen = /* @__PURE__ */ new Set(), depth = 0) => {
46
- if (!node || depth > 16) return node;
47
- if (node.type === "Identifier" && constants.has(node.name) && !seen.has(node.name))
48
- return resolveConstants(
49
- constants.get(node.name),
50
- new Set(seen).add(node.name),
51
- depth + 1
52
- );
53
- if (node.type === "JSXElement" || node.type === "JSXFragment") {
54
- const element = node.openingElement;
55
- const tag = element?.name?.type === "JSXIdentifier" ? element.name.name : "";
56
- if (element && !tag) return node;
57
- const reference = tag && /^[A-Z]/.test(tag) ? imports.referenceableImports.get(tag) : void 0;
58
- if (tag && /^[A-Z]/.test(tag) && !reference) return node;
59
- const props = {};
60
- for (const attribute of element?.attributes ?? []) {
61
- if (attribute.type !== "JSXAttribute" || attribute.name.type !== "JSXIdentifier")
62
- return node;
63
- props[attribute.name.name] = !attribute.value ? true : readStaticValue(
64
- resolveConstants(
65
- attribute.value.type === "JSXExpressionContainer" ? attribute.value.expression : attribute.value,
66
- seen,
67
- depth + 1
68
- )
69
- );
70
- }
71
- const children = [];
72
- for (const child of node.children) {
73
- if (child.type === "JSXText") {
74
- const lines = child.value.replace(/\t/g, " ").split(/\r\n|\n|\r/);
75
- const text = lines.map(
76
- (line, i) => (i ? line.trimStart() : line).replace(
77
- i < lines.length - 1 ? / +$/ : /$^/,
78
- ""
79
- )
80
- ).filter(Boolean).join(" ");
81
- if (text) children.push(text);
82
- } else if (child.type === "JSXExpressionContainer" && child.expression.type === "JSXEmptyExpression")
83
- continue;
84
- else
85
- children.push(
86
- readStaticValue(
87
- resolveConstants(
88
- child.type === "JSXExpressionContainer" ? child.expression : child,
89
- seen,
90
- depth + 1
91
- )
92
- )
93
- );
94
- }
95
- if (children.length)
96
- props.children = children.length === 1 ? children[0] : children;
97
- let source2 = reference?.importSpecifier;
98
- if (source2?.startsWith(".")) {
99
- const parts = filePath.replace(/\\/g, "/").split("/").slice(0, -1);
100
- for (const part of source2.split("/")) {
101
- if (part === "..") parts.pop();
102
- else if (part !== ".") parts.push(part);
103
- }
104
- source2 = parts.join("/");
105
- } else if (source2) source2 = `pkg:${source2}`;
106
- return {
107
- type: "TempoJsxValue",
108
- value: {
109
- $jsx: {
110
- tag,
111
- ...reference ? { reference: { source: source2, importedName: reference.importedName } } : {},
112
- props
113
- }
114
- }
115
- };
116
- }
117
- if (node.type === "ArrowFunctionExpression" && !node.async && node.params.length === 0)
118
- return { ...node, body: resolveConstants(node.body, seen, depth + 1) };
119
- if (node.type === "ObjectExpression")
120
- return {
121
- ...node,
122
- properties: node.properties.map(
123
- (property) => property.type === "Property" ? {
124
- ...property,
125
- value: resolveConstants(property.value, seen, depth + 1),
126
- shorthand: false
127
- } : property
128
- )
129
- };
130
- if (node.type === "ArrayExpression")
131
- return {
132
- ...node,
133
- elements: node.elements.map(
134
- (item) => resolveConstants(item, seen, depth + 1)
135
- )
136
- };
137
- if ([
138
- "TSAsExpression",
139
- "TSSatisfiesExpression",
140
- "ParenthesizedExpression"
141
- ].includes(node.type))
142
- return {
143
- ...node,
144
- expression: resolveConstants(node.expression, seen, depth + 1)
145
- };
146
- return node;
147
- };
148
- const scope = collectTopLevelScope(program);
149
- const declarations = [];
150
- const declaredBindings = /* @__PURE__ */ new Set();
151
- const topLevelCalls = /* @__PURE__ */ new Set();
152
- for (const statement of program.body ?? []) {
153
- const call = readTopLevelTrustedCall(
154
- statement,
155
- imports.trustedDefineAssetNames
156
- );
157
- if (!call) continue;
158
- topLevelCalls.add(call);
159
- const declaration = readAssetDeclaration({
160
- statement,
161
- call: {
162
- ...call,
163
- arguments: call.arguments.map(
164
- (argument, index) => index === 1 && argument.type === "ObjectExpression" ? {
165
- ...argument,
166
- properties: argument.properties.map(
167
- (property) => property.type === "Property" && ["controls", "variants"].includes(
168
- property.key.name ?? property.key.value
169
- ) ? { ...property, value: resolveConstants(property.value) } : property
170
- )
171
- } : argument
172
- )
173
- },
174
- scope,
175
- imports,
176
- program,
177
- source,
178
- errors,
179
- declaredBindings
180
- });
181
- if (declaration) declarations.push(declaration);
182
- }
183
- walk(program, (node) => {
184
- if (node.type === "CallExpression" && node.callee?.type === "Identifier" && imports.trustedDefineAssetNames.has(node.callee.name) && !topLevelCalls.has(node)) {
185
- errors.push({
186
- code: "non_top_level_call",
187
- severity: "structural",
188
- message: "defineAsset must be called as a top-level statement \u2014 in the file that defines the component, or in a canvas file that imports it",
189
- span: toSourceSpan(node)
190
- });
191
- }
192
- });
193
- for (const declaration of declarations) {
194
- const duplicate = errors.find(
195
- (error) => error.code === "duplicate_declaration" && error.message.includes(`"${declaration.bindingName}"`)
196
- );
197
- if (duplicate)
198
- declaration.warnings.push({
199
- ...duplicate,
200
- code: "duplicate_asset_declaration"
201
- });
202
- }
203
- return { filePath, declarations, errors };
204
- }
205
- function parseAssetProgram(filePath, source) {
206
- try {
207
- if (filePath.endsWith(".astro")) {
208
- const root = parseAstroAssetSource(source);
209
- return {
210
- program: root.frontmatter?.program ?? { type: "Program", body: [] },
211
- errors: []
212
- };
213
- }
214
- const result = parseSync(filePath, source);
215
- const errors = (result.errors ?? []).map(
216
- (error) => ({
217
- code: "unparseable_source",
218
- severity: "structural",
219
- message: error?.message ?? "Unable to parse asset source",
220
- span: toSourceSpan(error) ?? toSourceSpan(error?.labels?.[0])
221
- })
222
- );
223
- if (errors.length > 0) return { program: null, errors };
224
- return { program: result.program, errors: [] };
225
- } catch (error) {
226
- return {
227
- program: null,
228
- errors: [
229
- {
230
- code: "unparseable_source",
231
- severity: "structural",
232
- message: error instanceof Error ? error.message : "Unable to parse asset source"
233
- }
234
- ]
235
- };
236
- }
237
- }
238
- function readSourceComments(filePath, source) {
239
- try {
240
- if (filePath.endsWith(".astro")) {
241
- const root = parseAstroAssetSource(source);
242
- const comments = [...root.comments];
243
- const visit = (node) => {
244
- if (!node || typeof node !== "object") return;
245
- if (node.type === "AstroComment") comments.push(node);
246
- for (const [key, value] of Object.entries(node)) {
247
- if (key === "comments") continue;
248
- if (Array.isArray(value)) value.forEach(visit);
249
- else if (value && typeof value === "object") visit(value);
250
- }
251
- };
252
- visit(root);
253
- return comments.map((comment) => ({
254
- value: comment.value,
255
- span: { start: comment.start, end: comment.end }
256
- }));
257
- }
258
- const result = parseSync(filePath, source);
259
- if ((result.errors ?? []).length > 0) return null;
260
- return (result.comments ?? []).flatMap(
261
- (comment) => typeof comment?.value === "string" ? [
262
- {
263
- value: comment.value,
264
- span: toSourceSpan(comment) ?? { start: 0, end: 0 }
265
- }
266
- ] : []
267
- );
268
- } catch {
269
- return null;
270
- }
271
- }
272
- function readAssetImports(program) {
273
- const info = {
274
- trustedDefineControlsNames: /* @__PURE__ */ new Set(),
275
- trustedDefineAssetNames: /* @__PURE__ */ new Set(),
276
- importedBindings: /* @__PURE__ */ new Map(),
277
- referenceableImports: /* @__PURE__ */ new Map(),
278
- importDeclarationSpans: [],
279
- misimports: []
280
- };
281
- for (const statement of program?.body ?? []) {
282
- if (statement?.type !== "ImportDeclaration" || typeof statement.source?.value !== "string") {
283
- continue;
284
- }
285
- const declarationSpan = toSourceSpan(statement);
286
- if (declarationSpan) info.importDeclarationSpans.push(declarationSpan);
287
- if (statement.importKind === "type") continue;
288
- const source = statement.source.value;
289
- const trusted = isTrustedAssetImportSource(source);
290
- for (const specifier of statement.specifiers ?? []) {
291
- if (specifier?.importKind === "type") continue;
292
- const localName = specifier?.local?.name;
293
- if (typeof localName !== "string") continue;
294
- info.importedBindings.set(localName, source);
295
- if (specifier.type === "ImportDefaultSpecifier") {
296
- info.referenceableImports.set(localName, {
297
- importSpecifier: source,
298
- importedName: "default"
299
- });
300
- continue;
301
- }
302
- if (specifier.type !== "ImportSpecifier") continue;
303
- const importedName = specifier.imported?.name ?? specifier.imported?.value ?? localName;
304
- info.referenceableImports.set(localName, {
305
- importSpecifier: source,
306
- importedName
307
- });
308
- if (trusted && importedName === "defineControls")
309
- info.trustedDefineControlsNames.add(localName);
310
- if (importedName !== "defineAsset") continue;
311
- if (trusted) {
312
- info.trustedDefineAssetNames.add(localName);
313
- } else if (isMisimportedAssetSdkSource(source)) {
314
- info.misimports.push({
315
- source,
316
- span: toSourceSpan(statement.source) ?? declarationSpan ?? { start: 0, end: 0 }
317
- });
318
- }
319
- }
320
- }
321
- return info;
322
- }
323
- function parseControlsFile(filePath, source, parsed = parseAssetProgram(filePath, source)) {
324
- const { program } = parsed;
325
- const imports = readAssetImports(program);
326
- const scope = program ? collectTopLevelScope(program) : null;
327
- const astroNames = /* @__PURE__ */ new Set();
328
- if (filePath.endsWith(".astro"))
329
- for (const statement of program?.body ?? []) {
330
- if (statement.type !== "ImportDeclaration" || statement.source.value !== "tempo-sdk/astro/controls" || statement.importKind === "type")
331
- continue;
332
- for (const specifier of statement.specifiers)
333
- if (specifier.type === "ImportSpecifier" && specifier.importKind !== "type" && (specifier.imported.name ?? specifier.imported.value) === "defineAstroControls")
334
- astroNames.add(specifier.local.name);
335
- }
336
- return (program?.body ?? []).flatMap((statement) => {
337
- const call = statement.type === "ExpressionStatement" ? statement.expression : null;
338
- if (call?.type === "CallExpression" && call.callee.type === "Identifier" && astroNames.has(call.callee.name) && call.arguments.length === 1)
339
- return [
340
- {
341
- bindingName: "default",
342
- exportKind: "default",
343
- start: call.start,
344
- end: call.end
345
- }
346
- ];
347
- if (call?.type !== "CallExpression" || call.callee.type !== "Identifier" || !imports.trustedDefineControlsNames?.has(call.callee.name) || call.arguments.length !== 2 || call.arguments[0]?.type !== "Identifier")
348
- return [];
349
- const bindingName = call.arguments[0].name;
350
- const reference = imports.referenceableImports.get(bindingName);
351
- const binding = scope?.bindings.get(bindingName);
352
- if (!reference && !binding) return [];
353
- return [
354
- {
355
- bindingName,
356
- reference,
357
- exportKind: reference?.importedName === "default" ? "default" : binding?.exportKind ?? "named",
358
- start: call.start,
359
- end: call.end
360
- }
361
- ];
362
- });
363
- }
364
- function isTrustedAssetImportSource(source) {
365
- return source === ASSET_SDK_IMPORT_SOURCE || source.endsWith(`/${ASSET_SDK_IMPORT_SOURCE}`);
366
- }
367
- function isMisimportedAssetSdkSource(source) {
368
- return (source === "tempo-sdk" || source.startsWith("tempo-sdk/")) && !isTrustedAssetImportSource(source);
369
- }
370
- function collectTopLevelScope(program) {
371
- const bindings = /* @__PURE__ */ new Map();
372
- const nonSimpleNames = /* @__PURE__ */ new Set();
373
- const namedExports = /* @__PURE__ */ new Set();
374
- const defaultExports = /* @__PURE__ */ new Set();
375
- const register = (declaration, statementSpan, exported) => {
376
- const markExported = (name) => {
377
- if (exported === "named") namedExports.add(name);
378
- if (exported === "default") defaultExports.add(name);
379
- };
380
- if (declaration?.type === "FunctionDeclaration" || declaration?.type === "ClassDeclaration") {
381
- const name = declaration.id?.name;
382
- if (typeof name === "string") {
383
- bindings.set(name, { name, statementSpan, exportKind: "none" });
384
- markExported(name);
385
- }
386
- return;
387
- }
388
- if (declaration?.type === "VariableDeclaration") {
389
- for (const declarator of declaration.declarations ?? []) {
390
- if (declarator?.id?.type === "Identifier") {
391
- const name = declarator.id.name;
392
- if (declarator.init) {
393
- bindings.set(name, { name, statementSpan, exportKind: "none" });
394
- markExported(name);
395
- } else {
396
- nonSimpleNames.add(name);
397
- }
398
- } else {
399
- collectPatternNames(declarator?.id, nonSimpleNames);
400
- }
401
- }
402
- }
403
- };
404
- for (const statement of program?.body ?? []) {
405
- const statementSpan = toSourceSpan(statement) ?? { start: 0, end: 0 };
406
- if (statement?.type === "ExportNamedDeclaration") {
407
- if (statement.declaration) {
408
- register(statement.declaration, statementSpan, "named");
409
- }
410
- if (!statement.source) {
411
- for (const specifier of statement.specifiers ?? []) {
412
- if (specifier?.type !== "ExportSpecifier") continue;
413
- const localName = specifier.local?.name;
414
- if (typeof localName !== "string") continue;
415
- const exportedName = specifier.exported?.name ?? specifier.exported?.value;
416
- (exportedName === "default" ? defaultExports : namedExports).add(
417
- localName
418
- );
419
- }
420
- }
421
- continue;
422
- }
423
- if (statement?.type === "ExportDefaultDeclaration") {
424
- const declaration = statement.declaration;
425
- if (declaration?.type === "FunctionDeclaration" || declaration?.type === "ClassDeclaration") {
426
- register(declaration, statementSpan, "default");
427
- } else {
428
- const expression = unwrapTsExpression(declaration);
429
- if (expression?.type === "Identifier") {
430
- defaultExports.add(expression.name);
431
- }
432
- }
433
- continue;
434
- }
435
- register(statement, statementSpan, null);
436
- }
437
- for (const binding of bindings.values()) {
438
- binding.exportKind = defaultExports.has(binding.name) ? "default" : namedExports.has(binding.name) ? "named" : "none";
439
- }
440
- return { bindings, nonSimpleNames };
441
- }
442
- function collectPatternNames(pattern, names) {
443
- if (!pattern || typeof pattern !== "object") return;
444
- if (pattern.type === "Identifier" && typeof pattern.name === "string") {
445
- names.add(pattern.name);
446
- return;
447
- }
448
- if (pattern.type === "ObjectPattern") {
449
- for (const property of pattern.properties ?? []) {
450
- collectPatternNames(property?.value ?? property?.argument, names);
451
- }
452
- return;
453
- }
454
- if (pattern.type === "ArrayPattern") {
455
- for (const element of pattern.elements ?? []) {
456
- collectPatternNames(element, names);
457
- }
458
- return;
459
- }
460
- if (pattern.type === "AssignmentPattern") {
461
- collectPatternNames(pattern.left, names);
462
- return;
463
- }
464
- if (pattern.type === "RestElement") {
465
- collectPatternNames(pattern.argument, names);
466
- }
467
- }
468
- function hasTopLevelDefineAssetCallFor(program, trustedNames, bindingName) {
469
- for (const statement of program?.body ?? []) {
470
- const call = readTopLevelTrustedCall(statement, trustedNames);
471
- if (!call) continue;
472
- const componentArg = unwrapTsExpression(call.arguments?.[0]);
473
- if (componentArg?.type === "Identifier" && componentArg.name === bindingName) {
474
- return true;
475
- }
476
- }
477
- return false;
478
- }
479
- function collectIdentifierNames(program) {
480
- const names = /* @__PURE__ */ new Set();
481
- walk(program, (node) => {
482
- if ((node.type === "Identifier" || node.type === "JSXIdentifier") && typeof node.name === "string") {
483
- names.add(node.name);
484
- }
485
- });
486
- return names;
487
- }
488
- function readTopLevelTrustedCall(statement, trustedNames) {
489
- if (statement?.type !== "ExpressionStatement") return null;
490
- const expression = unwrapTsExpression(statement.expression);
491
- if (expression?.type === "CallExpression" && expression.callee?.type === "Identifier" && trustedNames.has(expression.callee.name)) {
492
- return expression;
493
- }
494
- return null;
495
- }
496
- function readAssetDeclaration(input) {
497
- const { statement, call, scope, imports, program, source, errors } = input;
498
- const callSpan = statementSpanWithSemicolon(source, statement);
499
- const args = call.arguments ?? [];
500
- if (args.length !== 2) {
501
- errors.push({
502
- code: "invalid_call_arguments",
503
- severity: "structural",
504
- message: `defineAsset takes exactly two arguments (component, config) \u2014 found ${args.length}`,
505
- span: callSpan
506
- });
507
- return null;
508
- }
509
- const componentArg = unwrapTsExpression(args[0]);
510
- if (componentArg?.type !== "Identifier") {
511
- errors.push({
512
- code: "non_identifier_component",
513
- severity: "structural",
514
- message: "defineAsset's first argument must be an identifier naming a component defined in this file",
515
- span: toSourceSpan(args[0]) ?? callSpan
516
- });
517
- return null;
518
- }
519
- const bindingName = componentArg.name;
520
- const binding = scope.bindings.get(bindingName);
521
- const reference = binding ? void 0 : imports.referenceableImports.get(bindingName);
522
- if (!binding && !reference) {
523
- errors.push(
524
- classifyMissingBinding(
525
- bindingName,
526
- scope,
527
- imports,
528
- program,
529
- toSourceSpan(componentArg) ?? callSpan
530
- )
531
- );
532
- return null;
533
- }
534
- const configArg = unwrapTsExpression(args[1]);
535
- if (configArg?.type !== "ObjectExpression") {
536
- errors.push({
537
- code: "config_not_object_literal",
538
- severity: "structural",
539
- message: "defineAsset's config must be an inline object literal \u2014 the span-based editor needs literal spans to mutate",
540
- span: toSourceSpan(args[1]) ?? callSpan
541
- });
542
- return null;
543
- }
544
- if (input.declaredBindings.has(bindingName)) {
545
- errors.push({
546
- code: "duplicate_declaration",
547
- severity: "structural",
548
- message: `duplicate defineAsset call for "${bindingName}" \u2014 keep one asset declaration`,
549
- span: callSpan
550
- });
551
- return null;
552
- }
553
- input.declaredBindings.add(bindingName);
554
- const warnings = [];
555
- const spans = {
556
- call: callSpan,
557
- config: toSourceSpan(configArg) ?? callSpan,
558
- libraryItems: []
559
- };
560
- const usageInstructions = readUsageInstructions(configArg);
561
- const libraries = readLibraries(configArg, spans, warnings);
562
- const variants = readVariants(configArg, warnings);
563
- if (getObjectProperty(configArg, "controls")) {
564
- errors.push({
565
- code: "invalid_control",
566
- severity: "structural",
567
- message: "Move controls to defineControls(Component, controls) in the component file or tempo/controls.ts."
568
- });
569
- return null;
570
- }
571
- const structural = warnings.filter(
572
- (warning) => warning.severity === "structural"
573
- );
574
- if (structural.length) {
575
- errors.push(...structural);
576
- return null;
577
- }
578
- if (binding && binding.exportKind === "none") {
579
- warnings.push({
580
- code: "not_exported",
581
- severity: "degraded",
582
- message: `"${bindingName}" is not exported \u2014 other files cannot import this asset`,
583
- span: callSpan
584
- });
585
- }
586
- return {
587
- bindingName,
588
- exportKind: binding ? binding.exportKind : referenceExportKind(reference),
589
- libraries,
590
- ...usageInstructions === void 0 ? {} : { usageInstructions },
591
- variants,
592
- ...reference ? { reference } : {},
593
- spans,
594
- warnings
595
- };
596
- }
597
- function referenceExportKind(reference) {
598
- return reference.importedName === "default" ? "default" : "named";
599
- }
600
- function classifyMissingBinding(name, scope, imports, program, span) {
601
- const importSource = imports.importedBindings.get(name);
602
- if (importSource !== void 0) {
603
- return {
604
- code: "imported_binding",
605
- severity: "structural",
606
- message: `"${name}" is a namespace import from "${importSource}" \u2014 declare the asset on a named or default import of the component instead`,
607
- span
608
- };
609
- }
610
- if (scope.nonSimpleNames.has(name)) {
611
- return {
612
- code: "unknown_binding",
613
- severity: "structural",
614
- message: `"${name}" is not a plain initialized top-level binding \u2014 destructured and uninitialized declarations are not supported`,
615
- span
616
- };
617
- }
618
- if (hasNestedBinding(program, name)) {
619
- return {
620
- code: "non_top_level_binding",
621
- severity: "structural",
622
- message: `"${name}" is not declared at the top level of the module`,
623
- span
624
- };
625
- }
626
- return {
627
- code: "unknown_binding",
628
- severity: "structural",
629
- message: `no top-level declaration of "${name}" found in this file`,
630
- span
631
- };
632
- }
633
- function hasNestedBinding(program, name) {
634
- let found = false;
635
- walk(program, (node) => {
636
- if (found) return;
637
- if ((node.type === "VariableDeclarator" || node.type === "FunctionDeclaration" || node.type === "ClassDeclaration") && node.id?.type === "Identifier" && node.id.name === name) {
638
- found = true;
639
- }
640
- });
641
- return found;
642
- }
643
- function readUsageInstructions(configNode) {
644
- return readStaticStringProperty(configNode, "usageInstructions");
645
- }
646
- function readStaticStringProperty(configNode, name) {
647
- const property = getObjectProperty(configNode, name);
648
- if (!property) return void 0;
649
- const value = readStaticValue(property.value);
650
- return typeof value === "string" ? value : void 0;
651
- }
652
- function readLibraries(configNode, spans, warnings) {
653
- const property = getObjectProperty(configNode, "libraries");
654
- if (!property) return [];
655
- spans.librariesProperty = toSourceSpan(property);
656
- const value = unwrapTsExpression(property.value);
657
- if (value?.type !== "ArrayExpression") {
658
- warnings.push({
659
- code: "non_literal_library",
660
- severity: "degraded",
661
- message: "libraries must be an inline array literal of string literals \u2014 its entries were dropped",
662
- span: toSourceSpan(property.value) ?? spans.librariesProperty
663
- });
664
- return [];
665
- }
666
- spans.libraries = toSourceSpan(value);
667
- const names = [];
668
- for (const element of value.elements ?? []) {
669
- const elementSpan = toSourceSpan(element) ?? spans.libraries;
670
- const name = readStaticString(element);
671
- if (name === null) {
672
- warnings.push({
673
- code: "non_literal_library",
674
- severity: "degraded",
675
- message: "libraries entries must be string literals \u2014 dropped a non-literal entry",
676
- span: elementSpan
677
- });
678
- continue;
679
- }
680
- if (name === "") {
681
- warnings.push({
682
- code: "empty_library_name",
683
- severity: "degraded",
684
- message: "libraries entries must be non-empty \u2014 dropped an empty entry",
685
- span: elementSpan
686
- });
687
- continue;
688
- }
689
- if (names.includes(name)) {
690
- warnings.push({
691
- code: "duplicate_library",
692
- severity: "degraded",
693
- message: `duplicate library name "${name}" \u2014 deduplicated`,
694
- span: elementSpan
695
- });
696
- continue;
697
- }
698
- names.push(name);
699
- if (elementSpan) spans.libraryItems.push(elementSpan);
700
- }
701
- return names;
702
- }
703
- function readVariants(configNode, warnings) {
704
- const property = getObjectProperty(configNode, "variants");
705
- if (!property) return [];
706
- const value = unwrapTsExpression(property.value);
707
- if (value?.type !== "ObjectExpression") {
708
- warnings.push({
709
- code: "unresolved_prop_value",
710
- severity: "degraded",
711
- message: "variants is not an inline object literal \u2014 variant props are not statically readable",
712
- span: toSourceSpan(property.value) ?? toSourceSpan(property)
713
- });
714
- return [];
715
- }
716
- const properties = value.properties ?? [];
717
- if (properties.length === 0) {
718
- warnings.push({
719
- code: "empty_variants",
720
- severity: "degraded",
721
- message: "variants is present but empty",
722
- span: toSourceSpan(value)
723
- });
724
- return [];
725
- }
726
- const variants = [];
727
- for (const entry of properties) {
728
- const name = entry?.type === "Property" && !entry.computed ? readPropertyKeyName(entry.key) : null;
729
- if (name === null) {
730
- warnings.push({
731
- code: "unresolved_prop_value",
732
- severity: "degraded",
733
- message: "variant names must be identifier or string keys \u2014 skipped an entry that is not statically readable",
734
- span: toSourceSpan(entry) ?? toSourceSpan(value)
735
- });
736
- continue;
737
- }
738
- variants.push(readVariant(name, entry, warnings));
739
- }
740
- return variants;
741
- }
742
- function readVariant(name, entry, warnings) {
743
- const value = unwrapTsExpression(entry.value);
744
- for (const property of value?.type === "ObjectExpression" ? value.properties : []) {
745
- if (property.type !== "Property" || property.computed || !["props", "render"].includes(readPropertyKeyName(property.key) ?? "")) {
746
- warnings.push({
747
- code: "invalid_variant_config",
748
- severity: "structural",
749
- message: `Variant "${name}" accepts either props or render, with explicit keys and no spreads or inheritance`,
750
- span: toSourceSpan(property)
751
- });
752
- }
753
- }
754
- const renderProperty = value?.type === "ObjectExpression" ? getObjectProperty(value, "render") : null;
755
- const propsProperty = value?.type === "ObjectExpression" ? getObjectProperty(value, "props") : null;
756
- const fn = unwrapTsExpression(renderProperty?.value);
757
- const body = unwrapTsExpression(fn?.body);
758
- const jsx = body?.type === "TempoJsxValue" ? readStaticValue(body) : UNRESOLVED_VALUE;
759
- const validRender = fn?.type === "ArrowFunctionExpression" && !fn.async && fn.params.length === 0 && !propsProperty && !containsUnresolvedValue(jsx);
760
- if (renderProperty && !validRender)
761
- warnings.push({
762
- code: "invalid_variant_config",
763
- severity: "structural",
764
- message: `Variant "${name}" render must be a parameterless arrow returning static JSX, without props, statements, hooks, callbacks, or computed expressions. Move logic into an imported component.`,
765
- span: toSourceSpan(renderProperty)
766
- });
767
- const render = renderProperty && validRender ? { jsx } : void 0;
768
- const propsValue = propsProperty ? readStaticValue(propsProperty.value) : render ? {} : UNRESOLVED_VALUE;
769
- const props = isPlainRecord(propsValue) ? propsValue : {};
770
- const hasUnresolvedValues = !isPlainRecord(propsValue) || containsUnresolvedValue(propsValue);
771
- if (hasUnresolvedValues) {
772
- warnings.push({
773
- code: "unresolved_prop_value",
774
- severity: "degraded",
775
- message: `variant "${name}" has prop values that are not statically readable`,
776
- span: toSourceSpan(entry)
777
- });
778
- }
779
- return { name, props, hasUnresolvedValues, ...render ? { render } : {} };
780
- }
781
- function readStaticValue(node) {
782
- const expression = unwrapTsExpression(node);
783
- if (!expression) return UNRESOLVED_VALUE;
784
- switch (expression.type) {
785
- case "TempoJsxValue":
786
- return expression.value;
787
- case "Literal": {
788
- if (expression.regex || expression.bigint) return UNRESOLVED_VALUE;
789
- const { value } = expression;
790
- return value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? value : UNRESOLVED_VALUE;
791
- }
792
- case "TemplateLiteral": {
793
- if ((expression.expressions ?? []).length > 0) return UNRESOLVED_VALUE;
794
- const cooked = expression.quasis?.[0]?.value?.cooked;
795
- return typeof cooked === "string" ? cooked : UNRESOLVED_VALUE;
796
- }
797
- case "UnaryExpression": {
798
- if (expression.operator !== "-") return UNRESOLVED_VALUE;
799
- const argument = unwrapTsExpression(expression.argument);
800
- return argument?.type === "Literal" && typeof argument.value === "number" && Number.isFinite(argument.value) ? -argument.value : UNRESOLVED_VALUE;
801
- }
802
- case "ArrayExpression":
803
- return (expression.elements ?? []).map(
804
- (element) => element == null || element.type === "SpreadElement" ? UNRESOLVED_VALUE : readStaticValue(element)
805
- );
806
- case "ObjectExpression": {
807
- const record = {};
808
- for (const property of expression.properties ?? []) {
809
- if (property?.type !== "Property" || property.computed) {
810
- return UNRESOLVED_VALUE;
811
- }
812
- const key = readPropertyKeyName(property.key);
813
- if (key === null) return UNRESOLVED_VALUE;
814
- Object.defineProperty(record, key, {
815
- value: readStaticValue(property.value),
816
- enumerable: true,
817
- configurable: true
818
- });
819
- }
820
- return record;
821
- }
822
- default:
823
- return UNRESOLVED_VALUE;
824
- }
825
- }
826
- function readStaticString(node) {
827
- const value = node == null ? UNRESOLVED_VALUE : readStaticValue(node);
828
- return typeof value === "string" ? value : null;
829
- }
830
- function isPlainRecord(value) {
831
- return typeof value === "object" && value !== null && !Array.isArray(value) && !isUnresolvedValue(value);
832
- }
833
- function containsUnresolvedValue(value) {
834
- if (isUnresolvedValue(value)) return true;
835
- if (Array.isArray(value)) return value.some(containsUnresolvedValue);
836
- if (typeof value === "object" && value !== null) {
837
- return Object.values(value).some(containsUnresolvedValue);
838
- }
839
- return false;
840
- }
841
- function statementSpanWithSemicolon(source, statement) {
842
- const span = toSourceSpan(statement) ?? { start: 0, end: 0 };
843
- if (source[span.end - 1] === ";") return span;
844
- let end = span.end;
845
- while (end < source.length && (source[end] === " " || source[end] === " ")) {
846
- end++;
847
- }
848
- return source[end] === ";" ? { start: span.start, end: end + 1 } : span;
849
- }
850
- function unwrapTsExpression(node) {
851
- let current = node;
852
- while (current?.type === "TSSatisfiesExpression" || current?.type === "TSAsExpression" || current?.type === "TSNonNullExpression" || current?.type === "ParenthesizedExpression") {
853
- current = current.expression;
854
- }
855
- return current;
856
- }
857
- function readPropertyKeyName(key) {
858
- if (key?.type === "Identifier") return key.name;
859
- if (key?.type === "Literal") {
860
- if (typeof key.value === "string") return key.value;
861
- if (typeof key.value === "number") return String(key.value);
862
- }
863
- return null;
864
- }
865
- function getObjectProperty(objectExpression, name) {
866
- if (objectExpression?.type !== "ObjectExpression") return null;
867
- for (const property of objectExpression.properties ?? []) {
868
- if (property?.type !== "Property" || property.computed) continue;
869
- if (readPropertyKeyName(property.key) === name) return property;
870
- }
871
- return null;
872
- }
873
- function toSourceSpan(node) {
874
- return typeof node?.start === "number" && Number.isFinite(node.start) && typeof node?.end === "number" && Number.isFinite(node.end) ? { start: node.start, end: node.end } : void 0;
875
- }
876
- function walk(node, visitor, seen = /* @__PURE__ */ new Set()) {
877
- if (!node || typeof node !== "object" || seen.has(node)) return;
878
- seen.add(node);
879
- if (typeof node.type === "string") visitor(node);
880
- for (const value of Object.values(node)) {
881
- if (!value || typeof value !== "object") continue;
882
- if (Array.isArray(value)) {
883
- for (const item of value) walk(item, visitor, seen);
884
- } else {
885
- walk(value, visitor, seen);
886
- }
887
- }
888
- }
889
-
890
- export {
891
- ASSET_SDK_IMPORT_SOURCE,
892
- parseAssetFile,
893
- parseAssetProgram,
894
- readSourceComments,
895
- readAssetImports,
896
- parseControlsFile,
897
- collectTopLevelScope,
898
- hasTopLevelDefineAssetCallFor,
899
- collectIdentifierNames,
900
- unwrapTsExpression,
901
- toSourceSpan
902
- };
903
- //# sourceMappingURL=chunk-PYAJHLXO.js.map