tempo-sdk 0.0.66 → 0.0.75

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 (110) hide show
  1. package/dist/assets/index.js +27 -5
  2. package/dist/assets/index.js.map +1 -1
  3. package/dist/astro/asset-preview-client.js +2 -2
  4. package/dist/astro.js +96 -31
  5. package/dist/astro.js.map +1 -1
  6. package/dist/canvas/astro.d.ts +1 -1
  7. package/dist/canvas/astro.js +2 -2
  8. package/dist/canvas/editor.d.ts +15 -5
  9. package/dist/canvas/editor.js +13 -8
  10. package/dist/canvas/editor.js.map +1 -1
  11. package/dist/canvas/flutter-preview.d.ts +18 -0
  12. package/dist/canvas/flutter-preview.js +9 -0
  13. package/dist/canvas/flutter-preview.js.map +1 -0
  14. package/dist/canvas/index.d.ts +33 -2
  15. package/dist/canvas/index.js +1134 -26
  16. package/dist/canvas/index.js.map +1 -1
  17. package/dist/canvas/interact-projection.js +5 -4
  18. package/dist/canvas/parser.d.ts +142 -3
  19. package/dist/canvas/parser.js +14 -1
  20. package/dist/canvas/svelte.d.ts +1 -1
  21. package/dist/canvas/svelte.js +2 -2
  22. package/dist/canvas/vue.d.ts +74 -0
  23. package/dist/canvas/vue.js +264 -0
  24. package/dist/canvas/vue.js.map +1 -0
  25. package/dist/{chunk-6W6UKDSY.js → chunk-2YX4WVFH.js} +49 -7
  26. package/dist/chunk-2YX4WVFH.js.map +1 -0
  27. package/dist/chunk-5HIIF354.js +67 -0
  28. package/dist/chunk-5HIIF354.js.map +1 -0
  29. package/dist/{chunk-FE6TYCLF.js → chunk-5VIBKVFO.js} +2 -2
  30. package/dist/{chunk-FE6TYCLF.js.map → chunk-5VIBKVFO.js.map} +1 -1
  31. package/dist/{chunk-77DZCV5Z.js → chunk-CXIW4IKC.js} +2 -2
  32. package/dist/chunk-CYQE3TLC.js +37 -0
  33. package/dist/chunk-CYQE3TLC.js.map +1 -0
  34. package/dist/{chunk-DELFOKU3.js → chunk-DNSCVLKV.js} +1571 -1410
  35. package/dist/chunk-DNSCVLKV.js.map +1 -0
  36. package/dist/chunk-EGRHWZRV.js +1 -0
  37. package/dist/chunk-EGRHWZRV.js.map +1 -0
  38. package/dist/{chunk-EYKOOLPL.js → chunk-GKDDNDG3.js} +1039 -134
  39. package/dist/chunk-GKDDNDG3.js.map +1 -0
  40. package/dist/{chunk-KOSJXE4G.js → chunk-H6BQZOAW.js} +4 -3
  41. package/dist/chunk-HOBTDB6G.js +112 -0
  42. package/dist/chunk-HOBTDB6G.js.map +1 -0
  43. package/dist/chunk-HZXQPM4W.js +285 -0
  44. package/dist/chunk-HZXQPM4W.js.map +1 -0
  45. package/dist/chunk-SGN7BDRE.js +16 -0
  46. package/dist/chunk-SGN7BDRE.js.map +1 -0
  47. package/dist/{chunk-F23JGM4U.js → chunk-UBTL6JUF.js} +6 -2
  48. package/dist/{chunk-F23JGM4U.js.map → chunk-UBTL6JUF.js.map} +1 -1
  49. package/dist/{chunk-2JRAG36X.js → chunk-WBMO4ZYO.js} +2 -2
  50. package/dist/chunk-WBMO4ZYO.js.map +1 -0
  51. package/dist/{chunk-K3EYTZLL.js → chunk-WTXOWQ7N.js} +3 -1
  52. package/dist/chunk-WTXOWQ7N.js.map +1 -0
  53. package/dist/{chunk-Q2A46HHW.js → chunk-XFPFWTWX.js} +276 -43
  54. package/dist/chunk-XFPFWTWX.js.map +1 -0
  55. package/dist/chunk-XMFVWJUY.js +342 -0
  56. package/dist/chunk-XMFVWJUY.js.map +1 -0
  57. package/dist/{chunk-PXDTH36X.js → chunk-Y72PIE3I.js} +212 -20
  58. package/dist/chunk-Y72PIE3I.js.map +1 -0
  59. package/dist/{chunk-6IR5JY6W.js → chunk-YECMP34I.js} +41 -9
  60. package/dist/chunk-YECMP34I.js.map +1 -0
  61. package/dist/{chunk-NSKYOKG5.js → chunk-ZXC7SZIT.js} +278 -26
  62. package/dist/chunk-ZXC7SZIT.js.map +1 -0
  63. package/dist/{controls-reader-SNMI2UY7.js → controls-reader-Z7OQWYWQ.js} +4 -3
  64. package/dist/{controls-reader-SNMI2UY7.js.map → controls-reader-Z7OQWYWQ.js.map} +1 -1
  65. package/dist/expo/plugin.cjs +301 -58
  66. package/dist/expo/plugin.cjs.map +1 -1
  67. package/dist/expo/plugin.js +1 -1
  68. package/dist/expo-babel-plugin.cjs +301 -58
  69. package/dist/expo-babel-plugin.cjs.map +1 -1
  70. package/dist/expo-babel-plugin.js +1 -1
  71. package/dist/flutter-preview-path.d.ts +9 -0
  72. package/dist/flutter-preview-path.js +16 -0
  73. package/dist/flutter-preview-path.js.map +1 -0
  74. package/dist/index.d.ts +16 -15
  75. package/dist/index.js +9 -6
  76. package/dist/nextjs/plugin.cjs +46 -5
  77. package/dist/nextjs/plugin.cjs.map +1 -1
  78. package/dist/nextjs/plugin.js +1 -1
  79. package/dist/nextjs-loader.cjs +343 -68
  80. package/dist/nextjs-loader.cjs.map +1 -1
  81. package/dist/nextjs.cjs +48 -6
  82. package/dist/nextjs.cjs.map +1 -1
  83. package/dist/nextjs.d.cts +9 -1
  84. package/dist/nextjs.d.ts +9 -1
  85. package/dist/nextjs.js +1 -1
  86. package/dist/nuxt/runtime/identity.d.ts +24 -0
  87. package/dist/nuxt/runtime/identity.js +18 -0
  88. package/dist/nuxt/runtime/identity.js.map +1 -0
  89. package/dist/nuxt.d.ts +102 -0
  90. package/dist/nuxt.js +5673 -0
  91. package/dist/nuxt.js.map +1 -0
  92. package/dist/{storyboard-4YdTYq_e.d.ts → storyboard-CMJVBSXn.d.ts} +9 -3
  93. package/dist/svelte.d.ts +4 -2
  94. package/dist/svelte.js +21 -88
  95. package/dist/svelte.js.map +1 -1
  96. package/dist/vue.d.ts +66 -0
  97. package/dist/vue.js +1403 -0
  98. package/dist/vue.js.map +1 -0
  99. package/package.json +48 -5
  100. package/dist/chunk-2JRAG36X.js.map +0 -1
  101. package/dist/chunk-6IR5JY6W.js.map +0 -1
  102. package/dist/chunk-6W6UKDSY.js.map +0 -1
  103. package/dist/chunk-DELFOKU3.js.map +0 -1
  104. package/dist/chunk-EYKOOLPL.js.map +0 -1
  105. package/dist/chunk-K3EYTZLL.js.map +0 -1
  106. package/dist/chunk-NSKYOKG5.js.map +0 -1
  107. package/dist/chunk-PXDTH36X.js.map +0 -1
  108. package/dist/chunk-Q2A46HHW.js.map +0 -1
  109. /package/dist/{chunk-77DZCV5Z.js.map → chunk-CXIW4IKC.js.map} +0 -0
  110. /package/dist/{chunk-KOSJXE4G.js.map → chunk-H6BQZOAW.js.map} +0 -0
package/dist/vue.js ADDED
@@ -0,0 +1,1403 @@
1
+ import {
2
+ defaultSourceRoot,
3
+ readModifiedTs,
4
+ resolveAnnotationIdentity
5
+ } from "./chunk-HOBTDB6G.js";
6
+ import "./chunk-EGRHWZRV.js";
7
+ import {
8
+ MagicString
9
+ } from "./chunk-JVVHU3A7.js";
10
+ import {
11
+ TEMPO_VUE_ANNOTATION_PLUGIN_NAME,
12
+ createSdkFileMatcher
13
+ } from "./chunk-XMFVWJUY.js";
14
+ import {
15
+ appendModuleVersionRecord
16
+ } from "./chunk-UBTL6JUF.js";
17
+ import {
18
+ DYNAMIC_SLOT_FACT,
19
+ EXPRESSION_FACTS_ATTRIBUTE,
20
+ sourceVersionHash
21
+ } from "./chunk-H6BQZOAW.js";
22
+ import {
23
+ TEMPO_VUE_INVOCATION_MARKER_PREFIX,
24
+ TEMPO_VUE_SOURCE_REGISTRY_GLOBAL
25
+ } from "./chunk-SGN7BDRE.js";
26
+
27
+ // vue.ts
28
+ import { readFileSync } from "fs";
29
+ import { isAbsolute as isAbsolute2, relative as relative2, resolve as resolve2 } from "path";
30
+
31
+ // ../../modules/vue-editor/escape.ts
32
+ function escapeVueAttributeValue(value, quote = '"') {
33
+ const escaped = value.split("&").join("&amp;").split('"').join("&quot;").split("<").join("&lt;").split(">").join("&gt;");
34
+ return quote === "'" ? escaped.split("'").join("&#39;") : escaped;
35
+ }
36
+
37
+ // ../../modules/annotation/style-keys.ts
38
+ function camelCaseStyleKey(property) {
39
+ if (property.startsWith("--")) return property;
40
+ return property.replace(/^-ms-/, "ms-").replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
41
+ }
42
+
43
+ // ../../modules/vue-editor/compiler.ts
44
+ import { babelParse, compileTemplate, parse } from "vue/compiler-sfc";
45
+
46
+ // ../../modules/vue-editor/parse.ts
47
+ var ELEMENT_NODE = 1;
48
+ var TEXT_NODE = 2;
49
+ var COMMENT_NODE = 3;
50
+ var SIMPLE_EXPRESSION_NODE = 4;
51
+ var INTERPOLATION_NODE = 5;
52
+ var ATTRIBUTE_NODE = 6;
53
+ var NATIVE_TAG = 0;
54
+ var COMPONENT_TAG = 1;
55
+ var STRUCTURAL_TEMPLATE_TAG = 3;
56
+ var BUILT_IN_COMPONENT_TAGS = /* @__PURE__ */ new Set([
57
+ "Teleport",
58
+ "teleport",
59
+ "KeepAlive",
60
+ "keep-alive",
61
+ "Transition",
62
+ "transition",
63
+ "TransitionGroup",
64
+ "transition-group",
65
+ "Suspense",
66
+ "suspense",
67
+ "BaseTransition",
68
+ "base-transition"
69
+ ]);
70
+ var DYNAMIC_COMPONENT_TAGS = /* @__PURE__ */ new Set(["component", "Component"]);
71
+ var STRUCTURAL_DIRECTIVES = /* @__PURE__ */ new Set(["if", "else-if", "else", "for"]);
72
+ var CHAIN_OPENING_DIRECTIVES = /* @__PURE__ */ new Set(["if", "else-if"]);
73
+ var CHAIN_CONTINUING_DIRECTIVES = /* @__PURE__ */ new Set(["else-if", "else"]);
74
+ var LIST_DIRECTIVE = /* @__PURE__ */ new Set(["for"]);
75
+ var SLOT_DIRECTIVE = /* @__PURE__ */ new Set(["slot"]);
76
+ var SCOPE_DIRECTIVES = /* @__PURE__ */ new Set(["if", "else-if", "else", "for", "slot"]);
77
+ var VUE_MERGED_PROP_NAMES = /* @__PURE__ */ new Set([
78
+ "class",
79
+ "style"
80
+ ]);
81
+ function parseVueSource(source, filename = "Component.vue") {
82
+ const { descriptor, errors } = parse(source, {
83
+ filename,
84
+ sourceMap: false
85
+ });
86
+ if (errors.length > 0) {
87
+ return {
88
+ kind: "invalid",
89
+ code: "invalid_vue",
90
+ message: errors.map((error) => error.message).join("\n")
91
+ };
92
+ }
93
+ const template = descriptor.template;
94
+ if (template?.src) {
95
+ return {
96
+ kind: "unsupported",
97
+ code: "unsupported_template",
98
+ message: `<template src="${template.src}"> is outside this file, so its offsets cannot describe it`
99
+ };
100
+ }
101
+ if (template?.lang && template.lang !== "html") {
102
+ return {
103
+ kind: "unsupported",
104
+ code: "unsupported_template",
105
+ message: `<template lang="${template.lang}"> offsets would describe the generated HTML, not this file`
106
+ };
107
+ }
108
+ if (template && !template.ast) {
109
+ return {
110
+ kind: "unsupported",
111
+ code: "unsupported_template",
112
+ message: "the template has no parsed AST"
113
+ };
114
+ }
115
+ const targets = /* @__PURE__ */ new Map();
116
+ let templateBindsAttrs = false;
117
+ const visit = (children, parent, parentNode) => {
118
+ let allStatic = true;
119
+ for (const child of children) {
120
+ if (child.type === INTERPOLATION_NODE) allStatic = false;
121
+ if (child.type !== ELEMENT_NODE) continue;
122
+ const props = child.props.map(readProp);
123
+ if (props.some(
124
+ (prop) => prop.kind === "bind" && /\$attrs\b/.test(prop.expression ?? "")
125
+ )) {
126
+ templateBindsAttrs = true;
127
+ }
128
+ const start = child.loc.start.offset;
129
+ const end = child.loc.end.offset;
130
+ const propsEnd = props.length > 0 ? Math.max(...props.map((prop) => prop.end)) : start + 1 + child.tag.length;
131
+ const openingEnd = source.indexOf(">", propsEnd) + 1;
132
+ const selfClosing = child.isSelfClosing === true;
133
+ const hasClosingTag = !selfClosing && end > openingEnd;
134
+ const kind = vueTargetKind(child);
135
+ const vPre = carriesVPre(
136
+ source,
137
+ start + 1 + child.tag.length,
138
+ props,
139
+ openingEnd
140
+ );
141
+ const inVPre = parent !== null && (parent.vPre || parent.inVPre);
142
+ const opensScope = kind === "component" || kind === "dynamic-element" || isBuiltInComponent(child) || child.tag === "template" || vPre || hasDirective(child, SCOPE_DIRECTIVES);
143
+ const info = {
144
+ kind,
145
+ tagName: child.tag,
146
+ start,
147
+ end,
148
+ propsEnd,
149
+ props,
150
+ dynamicSlot: carriesStructuralDirective(child) || ownsDynamicSlot(parentNode),
151
+ expressionSlot: hasDirective(child, LIST_DIRECTIVE) || ownsDynamicSlot(parentNode),
152
+ parentStart: parent?.start ?? null,
153
+ openingEnd,
154
+ selfClosing,
155
+ // The closing tag is the last `</` of the element's own bytes, even
156
+ // in a <textarea> whose text may hold one.
157
+ childrenStart: hasClosingTag ? openingEnd : null,
158
+ childrenEnd: hasClosingTag ? start + child.loc.source.lastIndexOf("</") : null,
159
+ vPre,
160
+ inVPre,
161
+ opensScope,
162
+ scopeOwner: parent === null ? -1 : parent.opensScope ? parent.start : parent.scopeOwner,
163
+ staticSubtree: false
164
+ };
165
+ targets.set(start, info);
166
+ const childrenStatic = visit(child.children, info, child);
167
+ const ownStatic = !vPre && props.every((prop) => prop.kind === "attribute") && (kind === "native-element" || child.tag === "template");
168
+ info.staticSubtree = ownStatic && childrenStatic;
169
+ if (!info.staticSubtree) allStatic = false;
170
+ }
171
+ return allStatic;
172
+ };
173
+ if (template?.ast) visit(template.ast.children, null, null);
174
+ const setupBody = descriptor.scriptSetup ? parseScriptBody(descriptor.scriptSetup) : null;
175
+ return {
176
+ kind: "ok",
177
+ template: template ? {
178
+ contentStart: template.loc.start.offset,
179
+ contentEnd: template.loc.end.offset
180
+ } : null,
181
+ targets,
182
+ rootFallthrough: readRootFallthrough({
183
+ descriptor,
184
+ setupBody,
185
+ templateBindsAttrs
186
+ }),
187
+ script: readScriptFacts(descriptor, setupBody)
188
+ };
189
+ }
190
+ function carriesVPre(source, tagNameEnd, props, openingEnd) {
191
+ const written = /(?:^|[\s/])v-pre(?=[\s/=>]|$)/;
192
+ let cursor = tagNameEnd;
193
+ for (const prop of [...props].sort((a, b) => a.start - b.start)) {
194
+ if (written.test(source.slice(cursor, prop.start))) return true;
195
+ cursor = prop.end;
196
+ }
197
+ return written.test(source.slice(cursor, openingEnd));
198
+ }
199
+ function isBuiltInComponent(node) {
200
+ return node.tagType === COMPONENT_TAG && BUILT_IN_COMPONENT_TAGS.has(node.tag);
201
+ }
202
+ function blockFacts(block) {
203
+ return {
204
+ contentStart: block.loc.start.offset,
205
+ contentEnd: block.loc.end.offset,
206
+ lang: block.lang ?? null,
207
+ src: block.src ?? null
208
+ };
209
+ }
210
+ function readScriptFacts(descriptor, setupBody) {
211
+ const setup = descriptor.scriptSetup;
212
+ const imports = [];
213
+ for (const statement of setupBody ?? []) {
214
+ if (statement.type !== "ImportDeclaration") continue;
215
+ if (statement.importKind === "type") continue;
216
+ for (const specifier of statement.specifiers) {
217
+ if (specifier.type === "ImportSpecifier" && specifier.importKind === "type")
218
+ continue;
219
+ imports.push({
220
+ local: specifier.local.name,
221
+ source: statement.source.value,
222
+ kind: specifier.type === "ImportDefaultSpecifier" ? "default" : specifier.type === "ImportNamespaceSpecifier" ? "namespace" : "named"
223
+ });
224
+ }
225
+ }
226
+ return {
227
+ setup: setup ? { ...blockFacts(setup), imports } : null,
228
+ classic: descriptor.script ? blockFacts(descriptor.script) : null
229
+ };
230
+ }
231
+ function readProp(prop) {
232
+ const start = prop.loc.start.offset;
233
+ const end = prop.loc.end.offset;
234
+ if (prop.type === ATTRIBUTE_NODE) {
235
+ const valueLoc = prop.value?.loc;
236
+ const delimiter = valueLoc?.source[0];
237
+ const quote = delimiter === '"' || delimiter === "'" ? delimiter : null;
238
+ return {
239
+ kind: "attribute",
240
+ name: prop.name,
241
+ value: prop.value ? prop.value.content : true,
242
+ start,
243
+ end,
244
+ valueStart: valueLoc ? valueLoc.start.offset + (quote ? 1 : 0) : null,
245
+ valueEnd: valueLoc ? valueLoc.end.offset - (quote ? 1 : 0) : null,
246
+ quote
247
+ };
248
+ }
249
+ const rawName = prop.rawName ?? prop.loc.source.split("=")[0].trim();
250
+ const decoded = prop.exp?.type === SIMPLE_EXPRESSION_NODE ? prop.exp.content : void 0;
251
+ const expression = prop.exp === void 0 ? {} : {
252
+ expression: prop.exp.loc.source,
253
+ ...decoded !== void 0 && decoded !== prop.exp.loc.source ? { decodedExpression: decoded } : {}
254
+ };
255
+ if (prop.name === "bind") {
256
+ const arg = prop.arg;
257
+ const staticName = arg?.type === SIMPLE_EXPRESSION_NODE && arg.isStatic ? arg.content : null;
258
+ return {
259
+ kind: "bind",
260
+ name: staticName,
261
+ objectBind: arg === void 0,
262
+ rawName,
263
+ ...expression,
264
+ ...staticName === "style" ? { styleKeys: boundStyleKeys(prop) } : {},
265
+ start,
266
+ end
267
+ };
268
+ }
269
+ return {
270
+ kind: "directive",
271
+ name: prop.name,
272
+ rawName,
273
+ ...expression,
274
+ start,
275
+ end
276
+ };
277
+ }
278
+ function boundStyleKeys(prop) {
279
+ const exp = prop.exp;
280
+ if (!exp || exp.type !== SIMPLE_EXPRESSION_NODE) return null;
281
+ let ast = exp.ast;
282
+ if (ast === void 0) {
283
+ try {
284
+ const program = babelParse(`(${exp.content})`, {
285
+ plugins: ["typescript"]
286
+ }).program;
287
+ const statement = program.body[0];
288
+ ast = statement?.type === "ExpressionStatement" ? statement.expression : null;
289
+ } catch {
290
+ ast = null;
291
+ }
292
+ }
293
+ if (!ast) return null;
294
+ const expression = unwrapTypeScript(ast);
295
+ if (expression.type !== "ObjectExpression") return null;
296
+ const keys = [];
297
+ for (const property of expression.properties) {
298
+ if (property.type === "SpreadElement" || property.computed) return null;
299
+ if (property.key.type === "Identifier") keys.push(property.key.name);
300
+ else if (property.key.type === "StringLiteral")
301
+ keys.push(camelCaseStyleKey(property.key.value));
302
+ else return null;
303
+ }
304
+ return keys;
305
+ }
306
+ function vueTargetKind(node) {
307
+ if (node.tag === "template" || node.tag === "slot") return "special-element";
308
+ if (node.tagType === NATIVE_TAG) return "native-element";
309
+ if (node.tagType !== COMPONENT_TAG) return "special-element";
310
+ if (BUILT_IN_COMPONENT_TAGS.has(node.tag)) return "special-element";
311
+ if (DYNAMIC_COMPONENT_TAGS.has(node.tag)) return "dynamic-element";
312
+ return "component";
313
+ }
314
+ function hasDirective(node, names) {
315
+ return node.props.some(
316
+ (prop) => prop.type !== ATTRIBUTE_NODE && names.has(prop.name)
317
+ );
318
+ }
319
+ function carriesStructuralDirective(node) {
320
+ return hasDirective(node, STRUCTURAL_DIRECTIVES);
321
+ }
322
+ function ownsDynamicSlot(parent) {
323
+ if (!parent) return false;
324
+ if (parent.tagType === STRUCTURAL_TEMPLATE_TAG) return true;
325
+ return parent.tagType === COMPONENT_TAG && hasDirective(parent, SLOT_DIRECTIVE);
326
+ }
327
+ function readRootFallthrough(options) {
328
+ const inheritAttrs = readInheritAttrs(options.descriptor, options.setupBody);
329
+ if (inheritAttrs === "unknown") return "unknown";
330
+ if (options.templateBindsAttrs) return "explicit-attrs";
331
+ if (inheritAttrs === false) return "inherit-attrs-false";
332
+ const ast = options.descriptor.template?.ast;
333
+ if (!ast) return "unknown";
334
+ return classifyTemplateRoots(ast.children);
335
+ }
336
+ function classifyTemplateRoots(children) {
337
+ const groups = [];
338
+ let chainOpen = false;
339
+ for (const child of children) {
340
+ const isComment = child.type === COMMENT_NODE;
341
+ const isBlankText = child.type === TEXT_NODE && child.content.trim() === "";
342
+ if (isComment || isBlankText) continue;
343
+ const element = child.type === ELEMENT_NODE ? child : null;
344
+ const continuesChain = chainOpen && element !== null && hasDirective(element, CHAIN_CONTINUING_DIRECTIVES);
345
+ const lastGroup = groups[groups.length - 1];
346
+ if (continuesChain && lastGroup) lastGroup.push(child);
347
+ else groups.push([child]);
348
+ chainOpen = element !== null && hasDirective(element, CHAIN_OPENING_DIRECTIVES);
349
+ }
350
+ const [only, ...others] = groups;
351
+ if (!only) return "unknown";
352
+ if (others.length > 0) return "multi-root";
353
+ const branches = only.map(classifyRootBranch);
354
+ if (branches.includes("list")) return "multi-root";
355
+ if (branches.every((branch) => branch === "element")) return "single-element";
356
+ if (branches.every((branch) => branch === "component"))
357
+ return "single-component";
358
+ return "unknown";
359
+ }
360
+ function classifyRootBranch(node) {
361
+ if (node.type !== ELEMENT_NODE) return "other";
362
+ if (hasDirective(node, LIST_DIRECTIVE)) return "list";
363
+ const kind = vueTargetKind(node);
364
+ if (kind === "native-element") return "element";
365
+ if (kind === "component") return "component";
366
+ return "other";
367
+ }
368
+ function readInheritAttrs(descriptor, setupBody) {
369
+ const fromSetup = descriptor.scriptSetup ? readScriptInheritAttrs(setupBody, defineOptionsArgument) : "absent";
370
+ if (fromSetup !== "absent") return fromSetup;
371
+ const fromOptions = descriptor.script ? readScriptInheritAttrs(
372
+ parseScriptBody(descriptor.script),
373
+ defaultExportOptions
374
+ ) : "absent";
375
+ return fromOptions === "absent" ? true : fromOptions;
376
+ }
377
+ function parseScriptBody(block) {
378
+ if (block.src) return null;
379
+ try {
380
+ return babelParse(block.content, {
381
+ sourceType: "module",
382
+ plugins: babelPluginsFor(block.lang)
383
+ }).program.body;
384
+ } catch {
385
+ return null;
386
+ }
387
+ }
388
+ function readScriptInheritAttrs(body, findOptions) {
389
+ if (body === null) return "unknown";
390
+ const options = findOptions(body);
391
+ if (options === "absent" || options === "unknown") return options;
392
+ return readObjectInheritAttrs(options);
393
+ }
394
+ function babelPluginsFor(lang) {
395
+ if (lang === "ts") return ["typescript"];
396
+ if (lang === "tsx") return ["typescript", "jsx"];
397
+ if (lang === "jsx") return ["jsx"];
398
+ return [];
399
+ }
400
+ function defineOptionsArgument(body) {
401
+ let found = "absent";
402
+ for (const statement of body) {
403
+ if (statement.type !== "ExpressionStatement") continue;
404
+ const call = unwrapTypeScript(statement.expression);
405
+ if (call.type !== "CallExpression") continue;
406
+ if (call.callee.type !== "Identifier") continue;
407
+ if (call.callee.name !== "defineOptions") continue;
408
+ const argument = call.arguments[0];
409
+ const options = argument && argument.type !== "SpreadElement" ? unwrapTypeScript(argument) : null;
410
+ found = options?.type === "ObjectExpression" ? options : "unknown";
411
+ }
412
+ return found;
413
+ }
414
+ function defaultExportOptions(body) {
415
+ for (const statement of body) {
416
+ if (statement.type === "ExportNamedDeclaration") {
417
+ const reExportsDefault = statement.specifiers.some(
418
+ (specifier) => specifier.exported.type === "Identifier" && specifier.exported.name === "default"
419
+ );
420
+ if (reExportsDefault) return "unknown";
421
+ continue;
422
+ }
423
+ if (statement.type !== "ExportDefaultDeclaration") continue;
424
+ const declaration = statement.declaration;
425
+ if (!isExpression(declaration)) return "unknown";
426
+ const exported = unwrapTypeScript(declaration);
427
+ if (exported.type === "ObjectExpression") return exported;
428
+ const options = defineComponentArgument(exported);
429
+ return options ?? "unknown";
430
+ }
431
+ return "absent";
432
+ }
433
+ function defineComponentArgument(expression) {
434
+ if (expression.type !== "CallExpression") return null;
435
+ const callee = expression.callee;
436
+ const calleeName = callee.type === "Identifier" ? callee.name : callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier" ? callee.property.name : null;
437
+ if (calleeName !== "defineComponent") return null;
438
+ const argument = expression.arguments[0];
439
+ if (!argument || argument.type === "SpreadElement") return null;
440
+ const options = unwrapTypeScript(argument);
441
+ return options.type === "ObjectExpression" ? options : null;
442
+ }
443
+ function readObjectInheritAttrs(options) {
444
+ let fact = "absent";
445
+ let inherits = false;
446
+ for (const property of options.properties) {
447
+ if (property.type === "SpreadElement" || property.computed) {
448
+ fact = "unknown";
449
+ continue;
450
+ }
451
+ const key = property.key.type === "Identifier" ? property.key.name : property.key.type === "StringLiteral" ? property.key.value : null;
452
+ if (key === "extends" || key === "mixins") inherits = true;
453
+ if (key !== "inheritAttrs") continue;
454
+ fact = property.type === "ObjectProperty" && property.value.type === "BooleanLiteral" ? property.value.value : "unknown";
455
+ }
456
+ if (fact === "absent" && inherits) return "unknown";
457
+ return fact;
458
+ }
459
+ function isExpression(node) {
460
+ return node.type !== "FunctionDeclaration" && node.type !== "ClassDeclaration" && node.type !== "TSDeclareFunction" && node.type !== "TSInterfaceDeclaration" && node.type !== "TSTypeAliasDeclaration" && node.type !== "TSEnumDeclaration" && node.type !== "TSModuleDeclaration";
461
+ }
462
+ function unwrapTypeScript(expression) {
463
+ let current = expression;
464
+ while (current.type === "TSAsExpression" || current.type === "TSSatisfiesExpression" || current.type === "TSTypeAssertion" || current.type === "TSNonNullExpression" || current.type === "ParenthesizedExpression") {
465
+ current = current.expression;
466
+ }
467
+ return current;
468
+ }
469
+
470
+ // ../../modules/vue-editor/component-props.ts
471
+ import { babelParse as babelParse2 } from "vue/compiler-sfc";
472
+ var NOT_PROPS = /* @__PURE__ */ new Set([
473
+ "key",
474
+ "ref",
475
+ "ref_for",
476
+ "ref_key",
477
+ "is",
478
+ "class",
479
+ "style",
480
+ "slot"
481
+ ]);
482
+ function readVuePassedProps(source, props) {
483
+ const result = {
484
+ props: /* @__PURE__ */ Object.create(null)
485
+ };
486
+ for (const prop of props) {
487
+ if (opensEverything(prop)) {
488
+ const spread = source.slice(prop.start, prop.end);
489
+ result.spread = result.spread ? `${result.spread} ${spread}` : spread;
490
+ for (const name2 of Object.keys(result.props))
491
+ result.props[name2] = { expression: result.spread };
492
+ continue;
493
+ }
494
+ const passed = passedProp(prop);
495
+ if (!passed) continue;
496
+ const name = camelize(passed.written);
497
+ result.props[name] = passed.value === void 0 ? { expression: expressionText(prop) } : { value: passed.value };
498
+ }
499
+ return result;
500
+ }
501
+ function opensEverything(prop) {
502
+ return prop.kind === "bind" && (prop.objectBind || prop.name === null);
503
+ }
504
+ function passedProp(prop) {
505
+ if (prop.kind === "attribute")
506
+ return NOT_PROPS.has(prop.name) ? null : { prop, written: prop.name, value: prop.value };
507
+ if (prop.kind === "bind") {
508
+ if (prop.name === null || NOT_PROPS.has(prop.name)) return null;
509
+ return {
510
+ prop,
511
+ written: prop.name,
512
+ value: prop.expression === void 0 ? void 0 : literalValue(prop.decodedExpression ?? prop.expression)
513
+ };
514
+ }
515
+ if (prop.name !== "model") return null;
516
+ const argument = /^v-model(?::([^.\s[]+))?/.exec(prop.rawName);
517
+ if (!argument) return null;
518
+ return { prop, written: argument[1] ?? "modelValue", value: void 0 };
519
+ }
520
+ function expressionText(prop) {
521
+ if (prop.kind !== "attribute" && prop.expression !== void 0)
522
+ return prop.decodedExpression ?? prop.expression;
523
+ if (prop.kind === "attribute") return prop.name;
524
+ return prop.kind === "bind" && prop.name !== null ? camelize(prop.name) : prop.rawName;
525
+ }
526
+ function literalValue(expression) {
527
+ let node;
528
+ try {
529
+ const statement = babelParse2(`(${expression})`, {
530
+ sourceType: "module"
531
+ }).program.body[0];
532
+ node = statement?.type === "ExpressionStatement" ? statement.expression : void 0;
533
+ } catch {
534
+ return void 0;
535
+ }
536
+ return node ? literalOf(node) : void 0;
537
+ }
538
+ function literalOf(node) {
539
+ switch (node.type) {
540
+ case "StringLiteral":
541
+ case "BooleanLiteral":
542
+ return node.value;
543
+ case "NumericLiteral":
544
+ return Number.isFinite(node.value) ? node.value : void 0;
545
+ case "NullLiteral":
546
+ return null;
547
+ case "TemplateLiteral":
548
+ return node.expressions.length === 0 ? node.quasis[0]?.value.cooked ?? void 0 : void 0;
549
+ case "UnaryExpression":
550
+ return node.operator === "-" && node.argument.type === "NumericLiteral" ? -node.argument.value : void 0;
551
+ case "ArrayExpression": {
552
+ const values = node.elements.map(
553
+ (element) => element && element.type !== "SpreadElement" ? literalOf(element) : void 0
554
+ );
555
+ return values.includes(void 0) ? void 0 : values;
556
+ }
557
+ case "ObjectExpression": {
558
+ const object = /* @__PURE__ */ Object.create(null);
559
+ for (const property of node.properties) {
560
+ if (property.type !== "ObjectProperty" || property.computed)
561
+ return void 0;
562
+ const key = property.key.type === "Identifier" ? property.key.name : property.key.type === "StringLiteral" ? property.key.value : null;
563
+ const value = literalOf(property.value);
564
+ if (key === null || value === void 0) return void 0;
565
+ object[key] = value;
566
+ }
567
+ return object;
568
+ }
569
+ default:
570
+ return void 0;
571
+ }
572
+ }
573
+ function camelize(name) {
574
+ return name.replace(/-(\w)/g, (_, char) => char.toUpperCase());
575
+ }
576
+
577
+ // ../../modules/vue-editor/annotate.ts
578
+ var TEMPO_STAMP_NAMES = [
579
+ "data-tempo-filepath",
580
+ "data-tempo-position",
581
+ "data-tempo-modifiedts",
582
+ "data-tempo-source-version"
583
+ ];
584
+ var TEMPO_ANNOTATION_NAMES = /* @__PURE__ */ new Set([
585
+ ...TEMPO_STAMP_NAMES,
586
+ EXPRESSION_FACTS_ATTRIBUTE
587
+ ]);
588
+ var INVOCATION_MARKER_SPELLINGS = [
589
+ "@vue:before-mount",
590
+ "v-on:vue:before-mount",
591
+ "@vue:beforeMount",
592
+ "v-on:vue:beforeMount"
593
+ ];
594
+ var INVOCATION_MARKER_EXPRESSION = /^function __tempo_c(\d+)\(\)\{\}$/;
595
+ var UNRENDERED_PROP_NAMES = /* @__PURE__ */ new Set(["key", "ref", "ref_for", "ref_key"]);
596
+ function annotateVueSource(options) {
597
+ if (!options.filepath || !options.filename || !Number.isSafeInteger(options.modifiedTs) || options.modifiedTs < 0 || options.sourceVersion === "") {
598
+ return refused(
599
+ "invalid_metadata",
600
+ "filename, filepath, a non-negative integer modifiedTs, and a non-empty sourceVersion are required"
601
+ );
602
+ }
603
+ const parsed = parseVueSource(options.source, options.filename);
604
+ if (parsed.kind === "invalid")
605
+ return refused("invalid_source", parsed.message);
606
+ if (parsed.kind === "unsupported")
607
+ return refused("unsupported_template", parsed.message);
608
+ const existing = /* @__PURE__ */ new Map();
609
+ for (const target of parsed.targets.values()) {
610
+ const read = readExistingAnnotation(options.source, target);
611
+ if (read === null) continue;
612
+ if (read.kind === "refused") return read;
613
+ existing.set(target.start, read);
614
+ }
615
+ const removals = [...existing.values()].map((read) => read.removal);
616
+ const baseOffset = (offset) => offset - removals.filter((removal) => removal.end <= offset).reduce((total, removal) => total + removal.end - removal.start, 0);
617
+ const version = options.sourceVersion ?? sourceVersionHash(removeRanges(options.source, removals));
618
+ const edits = [];
619
+ const hosts = [];
620
+ const components = [];
621
+ const skippedExistingAnnotations = [];
622
+ let elementsAnnotated = 0;
623
+ for (const target of parsed.targets.values()) {
624
+ const isHost = target.kind === "native-element";
625
+ const isInvocation = target.kind === "component" || target.kind === "dynamic-element";
626
+ if (!isHost && !isInvocation) continue;
627
+ const position = baseOffset(target.start);
628
+ const isAnnotation = isHost ? isStampProp : isMarkerProp;
629
+ const authored = target.props.filter((prop) => !isAnnotation(prop));
630
+ const facts = authoredFacts(target, authored, position);
631
+ const prior = existing.get(target.start);
632
+ if (isHost) {
633
+ const metadata = {
634
+ filepath: options.filepath,
635
+ position,
636
+ modifiedTs: options.modifiedTs,
637
+ sourceVersion: version
638
+ };
639
+ hosts.push({ kind: "host", ...facts.record });
640
+ if (prior) {
641
+ const matches = prior.kind === "stamps" && sameStampMetadata(prior.metadata, metadata) && prior.expressions === facts.expressions;
642
+ if (!matches) return identityConflict(target.start);
643
+ skippedExistingAnnotations.push(position);
644
+ continue;
645
+ }
646
+ edits.push({
647
+ start: target.propsEnd,
648
+ end: target.propsEnd,
649
+ replacement: serializeStamps(metadata, facts.expressions)
650
+ });
651
+ elementsAnnotated += 1;
652
+ continue;
653
+ }
654
+ const spelling = markerSpellingFor(authored);
655
+ if (spelling === null) continue;
656
+ const literalProps = literalPropsOf(options.source, authored);
657
+ components.push({
658
+ kind: "component",
659
+ ...facts.record,
660
+ ...facts.locked,
661
+ expressions: facts.expressions,
662
+ ...literalProps ? { literalProps } : {}
663
+ });
664
+ if (prior) {
665
+ const matches = prior.kind === "marker" && prior.position === position && prior.spelling === spelling;
666
+ if (!matches) return identityConflict(target.start);
667
+ skippedExistingAnnotations.push(position);
668
+ continue;
669
+ }
670
+ edits.push({
671
+ start: target.propsEnd,
672
+ end: target.propsEnd,
673
+ replacement: serializeMarker(spelling, position)
674
+ });
675
+ }
676
+ const magic = new MagicString(options.source);
677
+ for (const edit of edits) magic.appendLeft(edit.start, edit.replacement);
678
+ const code = magic.toString();
679
+ const reparsed = parseVueSource(code, options.filename);
680
+ if (reparsed.kind !== "ok" || reparsed.targets.size !== parsed.targets.size) {
681
+ return refused(
682
+ "invalid_output",
683
+ reparsed.kind === "ok" ? "annotation changed the template's tag structure" : reparsed.message
684
+ );
685
+ }
686
+ return {
687
+ kind: "ok",
688
+ code,
689
+ map: magic.generateMap({
690
+ source: options.filename,
691
+ includeContent: true,
692
+ hires: true
693
+ }),
694
+ edits,
695
+ elementsAnnotated,
696
+ skippedExistingAnnotations,
697
+ sourceVersion: version,
698
+ registry: {
699
+ filename: options.filename,
700
+ filepath: options.filepath,
701
+ modifiedTs: options.modifiedTs,
702
+ sourceVersion: version,
703
+ components,
704
+ hosts,
705
+ rootFallthrough: parsed.rootFallthrough
706
+ }
707
+ };
708
+ }
709
+ function literalPropsOf(source, props) {
710
+ const passing = props.filter(
711
+ (prop) => !(prop.kind === "attribute" && prop.name.startsWith("data-tempo-"))
712
+ );
713
+ const literals = Object.entries(readVuePassedProps(source, passing).props).filter(([, passed]) => "value" in passed).map(([name, passed]) => [name, passed.value]);
714
+ return literals.length > 0 ? Object.fromEntries(literals) : void 0;
715
+ }
716
+ function appendVueSourceRegistryRecord(source, registry) {
717
+ const registryObject = `(globalThis.${TEMPO_VUE_SOURCE_REGISTRY_GLOBAL} || (globalThis.${TEMPO_VUE_SOURCE_REGISTRY_GLOBAL} = {}))`;
718
+ return `${source}
719
+ ;typeof window !== "undefined" && (${registryObject}[${JSON.stringify(registry.filepath)}] = ${JSON.stringify(registry)});
720
+ `;
721
+ }
722
+ function authoredFacts(target, props, position) {
723
+ const lastObjectBind = lastIndexWhere(
724
+ props,
725
+ (prop) => prop.kind === "bind" && prop.objectBind
726
+ );
727
+ const lastComputedName = lastIndexWhere(
728
+ props,
729
+ (prop) => prop.kind === "bind" && prop.name === null && !prop.objectBind
730
+ );
731
+ const canOverrideAnything = lastObjectBind >= 0 || lastComputedName >= 0;
732
+ const facts = /* @__PURE__ */ new Set();
733
+ if (target.expressionSlot) facts.add(DYNAMIC_SLOT_FACT);
734
+ const literals = /* @__PURE__ */ new Map();
735
+ const bound = /* @__PURE__ */ new Set();
736
+ props.forEach((prop, index) => {
737
+ if (prop.kind === "directive") {
738
+ if (prop.name !== "for") facts.add(prop.rawName);
739
+ return;
740
+ }
741
+ if (prop.name === null || !isRenderedName(prop.name)) return;
742
+ if (prop.kind === "bind") {
743
+ if (prop.name === "style" && Array.isArray(prop.styleKeys)) {
744
+ for (const key of prop.styleKeys) facts.add(`style.${key}`);
745
+ return;
746
+ }
747
+ bound.add(prop.name);
748
+ facts.add(factName(prop.name));
749
+ return;
750
+ }
751
+ literals.set(prop.name, prop.value);
752
+ const overriddenByObject = index < lastObjectBind && !VUE_MERGED_PROP_NAMES.has(prop.name);
753
+ const overriddenByComputedName = index < lastComputedName;
754
+ if (overriddenByObject || overriddenByComputedName)
755
+ facts.add(factName(prop.name));
756
+ });
757
+ const className = literals.get("class");
758
+ const style = literals.get("style");
759
+ const lock = target.props.find(
760
+ (prop) => prop.kind === "attribute" && prop.name === "data-tempo-locked"
761
+ );
762
+ const lockValue = lock?.kind === "attribute" ? lock.value : void 0;
763
+ const expressions = [...facts].join(" ");
764
+ return {
765
+ record: {
766
+ name: target.tagName,
767
+ position,
768
+ ...typeof className === "string" ? { className } : {},
769
+ ...typeof style === "string" ? { style } : {},
770
+ supportsClassName: !canOverrideAnything && !bound.has("class") && (className === void 0 || typeof className === "string"),
771
+ supportsStyle: !canOverrideAnything && !bound.has("style") && (style === void 0 || typeof style === "string")
772
+ },
773
+ // An object bind or computed name gets a stamp even with no fact, as a
774
+ // JSX spread does: what it sets is unknown until runtime.
775
+ expressions: expressions || canOverrideAnything ? expressions : void 0,
776
+ locked: lockValue === true || lockValue === "true" || lockValue === "" ? { locked: true } : lockValue === "false" ? { locked: false } : {}
777
+ };
778
+ }
779
+ function lastIndexWhere(items, predicate) {
780
+ for (let index = items.length - 1; index >= 0; index--) {
781
+ if (predicate(items[index])) return index;
782
+ }
783
+ return -1;
784
+ }
785
+ function isRenderedName(name) {
786
+ return !UNRENDERED_PROP_NAMES.has(name) && !name.startsWith("data-tempo-");
787
+ }
788
+ function factName(name) {
789
+ return name === "class" ? "className" : name;
790
+ }
791
+ function isStampProp(prop) {
792
+ return prop.kind !== "directive" && prop.name !== null && TEMPO_ANNOTATION_NAMES.has(prop.name);
793
+ }
794
+ function isMarkerProp(prop) {
795
+ return prop.kind === "directive" && INVOCATION_MARKER_SPELLINGS.includes(prop.rawName) && INVOCATION_MARKER_EXPRESSION.test(prop.expression ?? "");
796
+ }
797
+ function markerSpellingFor(authored) {
798
+ const taken = new Set(
799
+ authored.flatMap(
800
+ (prop) => prop.kind === "attribute" ? [] : [prop.rawName]
801
+ )
802
+ );
803
+ return INVOCATION_MARKER_SPELLINGS.find((spelling) => !taken.has(spelling)) ?? null;
804
+ }
805
+ function readExistingAnnotation(source, target) {
806
+ if (target.kind === "native-element")
807
+ return readExistingStamps(source, target);
808
+ if (target.kind === "component" || target.kind === "dynamic-element")
809
+ return readExistingMarker(source, target);
810
+ return null;
811
+ }
812
+ function readExistingStamps(source, target) {
813
+ const annotation = target.props.filter(isStampProp);
814
+ if (annotation.length === 0) return null;
815
+ const expectedNames = [
816
+ ...TEMPO_STAMP_NAMES,
817
+ ...annotation.length > TEMPO_STAMP_NAMES.length ? [EXPRESSION_FACTS_ATTRIBUTE] : []
818
+ ];
819
+ const trailing = target.props.slice(-annotation.length);
820
+ const values = trailing.map(
821
+ (prop) => prop.kind === "attribute" && typeof prop.value === "string" ? prop.value : null
822
+ );
823
+ const wellFormed = annotation.length === expectedNames.length && trailing.every(
824
+ (prop, index) => prop === annotation[index] && prop.kind === "attribute" && prop.name === expectedNames[index] && values[index] !== null
825
+ );
826
+ if (!wellFormed) return annotationConflict(target.start);
827
+ const [filepath, positionText, modifiedText, sourceVersion, expressions] = values;
828
+ const position = Number(positionText);
829
+ const modifiedTs = Number(modifiedText);
830
+ const first = trailing[0];
831
+ const last = trailing[trailing.length - 1];
832
+ if (!filepath || !sourceVersion || !Number.isSafeInteger(position) || position < 0 || !Number.isSafeInteger(modifiedTs) || modifiedTs < 0) {
833
+ return annotationConflict(target.start);
834
+ }
835
+ const metadata = { filepath, position, modifiedTs, sourceVersion };
836
+ const removal = { start: first.start - 1, end: last.end, replacement: "" };
837
+ const written = source.slice(removal.start, removal.end);
838
+ if (written !== serializeStamps(metadata, expressions))
839
+ return annotationConflict(target.start);
840
+ return { kind: "stamps", metadata, expressions, removal };
841
+ }
842
+ function readExistingMarker(source, target) {
843
+ const markers = target.props.filter(isMarkerProp);
844
+ if (markers.length === 0) return null;
845
+ const marker = markers[0];
846
+ if (markers.length > 1 || marker !== target.props[target.props.length - 1] || marker.kind !== "directive") {
847
+ return annotationConflict(target.start);
848
+ }
849
+ const position = Number(
850
+ INVOCATION_MARKER_EXPRESSION.exec(marker.expression ?? "")?.[1]
851
+ );
852
+ const removal = { start: marker.start - 1, end: marker.end, replacement: "" };
853
+ if (source.slice(removal.start, removal.end) !== serializeMarker(marker.rawName, position))
854
+ return annotationConflict(target.start);
855
+ return { kind: "marker", spelling: marker.rawName, position, removal };
856
+ }
857
+ function sameStampMetadata(a, b) {
858
+ return a.filepath === b.filepath && a.position === b.position && a.modifiedTs === b.modifiedTs && a.sourceVersion === b.sourceVersion;
859
+ }
860
+ function serializeStamps(metadata, expressions) {
861
+ const values = [
862
+ ["data-tempo-filepath", metadata.filepath],
863
+ ["data-tempo-position", String(metadata.position)],
864
+ ["data-tempo-modifiedts", String(metadata.modifiedTs)],
865
+ ["data-tempo-source-version", metadata.sourceVersion],
866
+ ...expressions === void 0 ? [] : [[EXPRESSION_FACTS_ATTRIBUTE, expressions]]
867
+ ];
868
+ return values.map(([name, value]) => ` ${name}="${escapeVueAttributeValue(value)}"`).join("");
869
+ }
870
+ function serializeMarker(spelling, position) {
871
+ return ` ${spelling}="function ${TEMPO_VUE_INVOCATION_MARKER_PREFIX}${position}(){}"`;
872
+ }
873
+ function removeRanges(source, ranges) {
874
+ let result = "";
875
+ let cursor = 0;
876
+ for (const range of ranges) {
877
+ result += source.slice(cursor, range.start);
878
+ cursor = range.end;
879
+ }
880
+ return result + source.slice(cursor);
881
+ }
882
+ function refused(code, message) {
883
+ return { kind: "refused", code, message };
884
+ }
885
+ function annotationConflict(offset) {
886
+ return refused(
887
+ "annotation_conflict",
888
+ `tag at UTF-16 offset ${offset} has partial, dynamic, reordered, or conflicting Tempo annotations`
889
+ );
890
+ }
891
+ function identityConflict(offset) {
892
+ return refused(
893
+ "annotation_conflict",
894
+ `existing Tempo annotation at UTF-16 offset ${offset} does not exactly match the recovered source identity`
895
+ );
896
+ }
897
+
898
+ // ../../modules/vue-editor/transfer.ts
899
+ import {
900
+ babelParse as babelParse3,
901
+ compileScript,
902
+ extractIdentifiers,
903
+ parse as parseSfc,
904
+ walkIdentifiers
905
+ } from "vue/compiler-sfc";
906
+ var TEMPLATE_GLOBALS = new Set(
907
+ "Infinity,undefined,NaN,isFinite,isNaN,parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt,console,Error,Symbol".split(",")
908
+ );
909
+
910
+ // ../../modules/vue-editor/copy.ts
911
+ import { parse as parseSfc2 } from "vue/compiler-sfc";
912
+
913
+ // app-vite-plugins.ts
914
+ import { existsSync, realpathSync } from "fs";
915
+ import { isAbsolute, join, relative, resolve } from "path";
916
+ var TEMPO_APP_VITE_PLUGINS_ENDPOINT = "/__tempo/app-vite-plugins";
917
+ var VITE_CONFIG_FILES = [
918
+ "vite.config.js",
919
+ "vite.config.mjs",
920
+ "vite.config.ts",
921
+ "vite.config.cjs",
922
+ "vite.config.mts",
923
+ "vite.config.cts"
924
+ ];
925
+ var DROPPED_APP_PLUGINS = [
926
+ {
927
+ // Route-board setup adds them to the app config; the host runs its own
928
+ // copies with host roots.
929
+ names: [
930
+ "tempo-annotate",
931
+ "tempo-vue-source-annotation",
932
+ "tempo-vue-source-records"
933
+ ],
934
+ reason: "Tempo's own plugin, which the host already runs"
935
+ },
936
+ {
937
+ names: [
938
+ "vite:react",
939
+ "@vitejs/plugin-react",
940
+ "vite-tsconfig-paths",
941
+ "@tailwindcss/vite"
942
+ ],
943
+ reason: "the host runs its own copy"
944
+ },
945
+ {
946
+ // Its config hook takes `.tsx` from the React JSX transform that the
947
+ // canvas files need. Vue JSX components are unsupported on the canvas.
948
+ names: ["vite:vue-jsx"],
949
+ reason: "Vue JSX would take .tsx canvas files from React"
950
+ },
951
+ {
952
+ // An overlay injected into the host page, template rewrites after
953
+ // Tempo's stamps, hooks wrapped around every plugin, lint findings
954
+ // turned into board errors.
955
+ names: [
956
+ "vite-plugin-vue-devtools",
957
+ "vite-plugin-vue-inspector",
958
+ "vite-plugin-inspect",
959
+ "vite-plugin-checker",
960
+ "vite:eslint",
961
+ "vite-plugin-eslint",
962
+ "vite-plugin-stylelint"
963
+ ],
964
+ reason: "a dev tool"
965
+ },
966
+ {
967
+ names: ["vite:html", "vite-plugin-html", "vite-plugin-pwa"],
968
+ reason: "serves the app's index.html or service worker"
969
+ },
970
+ {
971
+ // Tempo connects to the host over HTTP.
972
+ names: ["vite:basic-ssl", "vite:mkcert", "vite-plugin-mkcert"],
973
+ reason: "switches the server to HTTPS"
974
+ }
975
+ ];
976
+ var SETUP_HOOKS = /* @__PURE__ */ new Set([
977
+ "config",
978
+ "configResolved",
979
+ "configureServer",
980
+ "buildStart"
981
+ ]);
982
+ var ROOT_VIEW_HOOKS = /* @__PURE__ */ new Set(["config", "configResolved"]);
983
+ var CANVAS_MODULE = /\.canvas\.[jt]sx$/;
984
+ async function loadAppVitePlugins(options) {
985
+ const appRoot = resolve(options.appRoot);
986
+ const configFile = findViteConfigFile(appRoot);
987
+ const report = {
988
+ configFile,
989
+ status: "missing",
990
+ plugins: [],
991
+ disabled: []
992
+ };
993
+ if (!configFile) {
994
+ return [
995
+ createHostSettingsPlugin(report, null, []),
996
+ options.compiler.fallback()
997
+ ];
998
+ }
999
+ let loaded;
1000
+ try {
1001
+ loaded = await loadAppConfig(configFile, appRoot);
1002
+ } catch (error) {
1003
+ report.status = "failed";
1004
+ report.error = errorMessage(error);
1005
+ console.warn(
1006
+ `[tempo] Could not load the app's Vite config ${configFile}; component boards render without the app's Vite plugins until it loads: ${report.error}`
1007
+ );
1008
+ return [
1009
+ createHostSettingsPlugin(report, null, [configFile]),
1010
+ options.compiler.fallback()
1011
+ ];
1012
+ }
1013
+ report.status = "loaded";
1014
+ const appViteRoot = resolve(appRoot, loaded.config.root ?? ".");
1015
+ const isTempoOwned = createTempoOwnedModuleMatcher(options.hostRoot);
1016
+ const adopted = [];
1017
+ let hasCompiler = false;
1018
+ for (const plugin of loaded.plugins) {
1019
+ const name = plugin.name ?? "";
1020
+ const dropReason = droppedReason(name, options.exclude ?? []);
1021
+ if (dropReason) {
1022
+ report.plugins.push({ name, kept: false, reason: dropReason });
1023
+ continue;
1024
+ }
1025
+ report.plugins.push({ name, kept: true });
1026
+ const isCompiler = name === options.compiler.name;
1027
+ hasCompiler || (hasCompiler = isCompiler);
1028
+ adopted.push(
1029
+ adoptAppPlugin(plugin, {
1030
+ rootView: isCompiler ? null : appViteRoot,
1031
+ isTempoOwned,
1032
+ report
1033
+ })
1034
+ );
1035
+ }
1036
+ return [
1037
+ createHostSettingsPlugin(
1038
+ report,
1039
+ hostSettingsFromAppConfig(loaded.config, appViteRoot),
1040
+ [configFile, ...loaded.dependencies]
1041
+ ),
1042
+ ...hasCompiler ? [] : [options.compiler.fallback()],
1043
+ ...adopted
1044
+ ];
1045
+ }
1046
+ function findViteConfigFile(appRoot) {
1047
+ for (const name of VITE_CONFIG_FILES) {
1048
+ const file = join(appRoot, name);
1049
+ if (existsSync(file)) return file;
1050
+ }
1051
+ return null;
1052
+ }
1053
+ var appConfigLoads = Promise.resolve();
1054
+ function loadAppConfig(configFile, appRoot) {
1055
+ const load = appConfigLoads.then(
1056
+ () => loadAppConfigFromAppFolder(configFile, appRoot)
1057
+ );
1058
+ appConfigLoads = load.catch(() => void 0);
1059
+ return load;
1060
+ }
1061
+ async function loadAppConfigFromAppFolder(configFile, appRoot) {
1062
+ const vite = await import("vite");
1063
+ const env = {
1064
+ command: "serve",
1065
+ mode: "development",
1066
+ isSsrBuild: false,
1067
+ isPreview: false
1068
+ };
1069
+ const hostCwd = process.cwd();
1070
+ process.chdir(appRoot);
1071
+ try {
1072
+ const loaded = await vite.loadConfigFromFile(
1073
+ env,
1074
+ configFile,
1075
+ appRoot,
1076
+ "silent"
1077
+ );
1078
+ if (!loaded) throw new Error(`${configFile} produced no config`);
1079
+ const plugins = await flattenPluginOption(loaded.config.plugins);
1080
+ return {
1081
+ config: loaded.config,
1082
+ plugins,
1083
+ // Relative to the working directory the bundler ran in: the app folder.
1084
+ dependencies: loaded.dependencies.map((file) => resolve(appRoot, file))
1085
+ };
1086
+ } finally {
1087
+ process.chdir(hostCwd);
1088
+ }
1089
+ }
1090
+ async function flattenPluginOption(option) {
1091
+ const value = await option;
1092
+ if (!value) return [];
1093
+ if (Array.isArray(value)) {
1094
+ const nested = await Promise.all(value.map(flattenPluginOption));
1095
+ return nested.flat();
1096
+ }
1097
+ return [value];
1098
+ }
1099
+ function droppedReason(name, exclude) {
1100
+ const matches = (prefix) => prefix !== "" && name.startsWith(prefix);
1101
+ for (const rule of DROPPED_APP_PLUGINS) {
1102
+ if (rule.names.some(matches)) return rule.reason;
1103
+ }
1104
+ if (exclude.some(matches)) return "listed in exclude";
1105
+ return null;
1106
+ }
1107
+ function createTempoOwnedModuleMatcher(hostRoot) {
1108
+ const resolvedRoot = resolve(hostRoot);
1109
+ const roots = [resolvedRoot, realPathOrSelf(resolvedRoot)];
1110
+ return (id) => {
1111
+ const file = id.split("?", 1)[0] ?? id;
1112
+ return CANVAS_MODULE.test(file) || roots.some((root) => isWithin(root, file));
1113
+ };
1114
+ }
1115
+ function realPathOrSelf(path) {
1116
+ try {
1117
+ return realpathSync(path);
1118
+ } catch {
1119
+ return path;
1120
+ }
1121
+ }
1122
+ function isWithin(directory, file) {
1123
+ const relativePath = relative(directory, file);
1124
+ return relativePath === "" || !relativePath.startsWith("..") && !isAbsolute(relativePath);
1125
+ }
1126
+ function adoptAppPlugin(plugin, scope) {
1127
+ delete plugin.transformIndexHtml;
1128
+ let disabled = false;
1129
+ const disable = (hook, error) => {
1130
+ disabled = true;
1131
+ const message = errorMessage(error);
1132
+ scope.report.disabled.push({ name: plugin.name, hook, error: message });
1133
+ console.warn(
1134
+ `[tempo] Disabled the app's Vite plugin "${plugin.name}": its ${hook} hook threw: ${message}`
1135
+ );
1136
+ };
1137
+ const hooks = plugin;
1138
+ for (const key of Object.keys(hooks)) {
1139
+ if (key === "apply") continue;
1140
+ const hook = hooks[key];
1141
+ const handler = hookHandler(hook);
1142
+ if (!handler) continue;
1143
+ const appViteRoot = ROOT_VIEW_HOOKS.has(key) ? scope.rootView : null;
1144
+ const isSetupHook = SETUP_HOOKS.has(key);
1145
+ const wrapped = function(...args) {
1146
+ if (disabled) return void 0;
1147
+ if (key === "transform" && scope.isTempoOwned(String(args[1]))) {
1148
+ return void 0;
1149
+ }
1150
+ let rootView;
1151
+ if (appViteRoot !== null) {
1152
+ rootView = withRoot(args[0], appViteRoot);
1153
+ args[0] = rootView;
1154
+ }
1155
+ const keepHostRoot = (result) => key === "config" && rootView ? withoutRoot(result, rootView) : result;
1156
+ if (!isSetupHook) return handler.apply(this, args);
1157
+ try {
1158
+ const result = handler.apply(this, args);
1159
+ if (!isPromiseLike(result)) return keepHostRoot(result);
1160
+ return Promise.resolve(result).then(
1161
+ keepHostRoot,
1162
+ (error) => disable(key, error)
1163
+ );
1164
+ } catch (error) {
1165
+ disable(key, error);
1166
+ return void 0;
1167
+ }
1168
+ };
1169
+ hooks[key] = typeof hook === "function" ? wrapped : { ...hook, handler: wrapped };
1170
+ }
1171
+ return plugin;
1172
+ }
1173
+ function hookHandler(hook) {
1174
+ if (typeof hook === "function") return hook;
1175
+ if (hook && typeof hook === "object" && "handler" in hook) {
1176
+ const { handler } = hook;
1177
+ if (typeof handler === "function") return handler;
1178
+ }
1179
+ return null;
1180
+ }
1181
+ function withRoot(config, root) {
1182
+ if (!config || typeof config !== "object") return config;
1183
+ return new Proxy(config, {
1184
+ get: (target, key) => key === "root" ? root : Reflect.get(target, key)
1185
+ });
1186
+ }
1187
+ function withoutRoot(result, rootView) {
1188
+ if (result === rootView) return void 0;
1189
+ if (!result || typeof result !== "object" || !("root" in result)) {
1190
+ return result;
1191
+ }
1192
+ const { root: _appRoot, ...rest } = result;
1193
+ return rest;
1194
+ }
1195
+ function createHostSettingsPlugin(report, settings, dependencies) {
1196
+ return {
1197
+ name: "tempo-app-vite-config",
1198
+ config: () => settings ?? void 0,
1199
+ configResolved(config) {
1200
+ for (const file of dependencies) {
1201
+ const normalized = resolve(file).replace(/\\/g, "/");
1202
+ if (!config.configFileDependencies.includes(normalized)) {
1203
+ config.configFileDependencies.push(normalized);
1204
+ }
1205
+ }
1206
+ },
1207
+ configureServer(server) {
1208
+ server.middlewares.use(TEMPO_APP_VITE_PLUGINS_ENDPOINT, (_req, res) => {
1209
+ res.statusCode = 200;
1210
+ res.setHeader("Cache-Control", "no-store");
1211
+ res.setHeader("Content-Type", "application/json; charset=utf-8");
1212
+ res.end(JSON.stringify(report));
1213
+ });
1214
+ }
1215
+ };
1216
+ }
1217
+ function hostSettingsFromAppConfig(app, appViteRoot) {
1218
+ const settings = {
1219
+ // `import.meta.env.VITE_*` from the app's `.env` files. Vite reads a
1220
+ // relative envDir from the root, which here is the app's.
1221
+ envDir: app.envDir === false ? false : resolve(appViteRoot, app.envDir ?? ".")
1222
+ };
1223
+ if (app.envPrefix) settings.envPrefix = app.envPrefix;
1224
+ if (app.define) settings.define = app.define;
1225
+ if (app.assetsInclude) settings.assetsInclude = app.assetsInclude;
1226
+ const resolveSettings = {};
1227
+ if (app.resolve?.alias) {
1228
+ resolveSettings.alias = withAbsoluteAliases(app.resolve.alias, appViteRoot);
1229
+ }
1230
+ if (app.resolve?.extensions) {
1231
+ resolveSettings.extensions = app.resolve.extensions;
1232
+ }
1233
+ if (Object.keys(resolveSettings).length > 0) {
1234
+ settings.resolve = resolveSettings;
1235
+ }
1236
+ const cssSettings = {};
1237
+ if (app.css?.preprocessorOptions) {
1238
+ cssSettings.preprocessorOptions = app.css.preprocessorOptions;
1239
+ }
1240
+ if (app.css?.modules) cssSettings.modules = app.css.modules;
1241
+ if (Object.keys(cssSettings).length > 0) settings.css = cssSettings;
1242
+ return settings;
1243
+ }
1244
+ function withAbsoluteAliases(alias, appViteRoot) {
1245
+ const absolute = (replacement) => {
1246
+ const appRelative = join(appViteRoot, replacement);
1247
+ const isRootRelative = replacement.startsWith("/") && !existsSync(replacement) && existsSync(appRelative);
1248
+ return isRootRelative ? appRelative.replace(/\\/g, "/") : replacement;
1249
+ };
1250
+ if (Array.isArray(alias)) {
1251
+ return alias.map((entry) => ({
1252
+ ...entry,
1253
+ replacement: absolute(entry.replacement)
1254
+ }));
1255
+ }
1256
+ return Object.fromEntries(
1257
+ Object.entries(alias).map(
1258
+ ([find, replacement]) => [find, absolute(replacement)]
1259
+ )
1260
+ );
1261
+ }
1262
+ function isPromiseLike(value) {
1263
+ return !!value && typeof value === "object" && typeof value.then === "function";
1264
+ }
1265
+ function errorMessage(error) {
1266
+ return error instanceof Error ? error.message : String(error);
1267
+ }
1268
+
1269
+ // vue.ts
1270
+ var VUE_MAIN_MODULE = /\.vue$/;
1271
+ function tempoVuePlugin(options = {}) {
1272
+ const root = resolve2(options.root ?? process.cwd());
1273
+ const sourceRoot = resolve2(options.sourceRoot ?? defaultSourceRoot(root));
1274
+ const enabled = options.enabled ?? Boolean(process.env.TEMPO);
1275
+ const excludedDirectories = (options.exclude ?? []).map(
1276
+ (directory) => resolve2(directory)
1277
+ );
1278
+ const isSdkFile = createSdkFileMatcher();
1279
+ const annotatedModules = /* @__PURE__ */ new Map();
1280
+ const warned = /* @__PURE__ */ new Set();
1281
+ const identityFor = (id) => {
1282
+ if (!enabled || id.startsWith("\0") || !VUE_MAIN_MODULE.test(id)) {
1283
+ return null;
1284
+ }
1285
+ const identity = resolveAnnotationIdentity(id, { root, sourceRoot });
1286
+ if (!identity || isSdkFile(identity.absoluteFilename)) return null;
1287
+ if (isUnderAny(identity.absoluteFilename, excludedDirectories)) return null;
1288
+ return identity;
1289
+ };
1290
+ return [
1291
+ {
1292
+ name: TEMPO_VUE_ANNOTATION_PLUGIN_NAME,
1293
+ enforce: "pre",
1294
+ // Read by tempoVitePlugin() to report the `vueSourceAnnotation`
1295
+ // identity capability: present and enabled means `.vue` files are
1296
+ // stamped on this server.
1297
+ api: { enabled },
1298
+ transform: {
1299
+ order: "pre",
1300
+ filter: { id: VUE_MAIN_MODULE },
1301
+ handler(code, id) {
1302
+ annotatedModules.delete(id);
1303
+ const identity = identityFor(id);
1304
+ if (!identity) return void 0;
1305
+ let raw;
1306
+ try {
1307
+ raw = readFileSync(identity.absoluteFilename, "utf8");
1308
+ } catch {
1309
+ return void 0;
1310
+ }
1311
+ const warnOnce = (reason, message) => {
1312
+ const key = `${id}\0${reason}`;
1313
+ if (warned.has(key)) return;
1314
+ warned.add(key);
1315
+ this.warn(
1316
+ `Tempo did not annotate ${identity.filepath}: ${message}`
1317
+ );
1318
+ };
1319
+ if (code !== raw) {
1320
+ warnOnce(
1321
+ "drift",
1322
+ "an earlier Vite plugin changed the source; put tempoVuePlugin() first"
1323
+ );
1324
+ return void 0;
1325
+ }
1326
+ const result = annotateVueSource({
1327
+ source: code,
1328
+ filename: id,
1329
+ filepath: identity.filepath,
1330
+ modifiedTs: readModifiedTs(identity.absoluteFilename),
1331
+ sourceVersion: sourceVersionHash(raw)
1332
+ });
1333
+ if (result.kind === "refused") {
1334
+ if (result.code !== "invalid_source") {
1335
+ warnOnce(result.code, `${result.code}: ${result.message}`);
1336
+ }
1337
+ return void 0;
1338
+ }
1339
+ annotatedModules.set(id, result.registry);
1340
+ if (result.edits.length === 0) return void 0;
1341
+ return { code: result.code, map: result.map };
1342
+ }
1343
+ }
1344
+ },
1345
+ {
1346
+ name: "tempo-vue-source-records",
1347
+ enforce: "post",
1348
+ hotUpdate: {
1349
+ order: "post",
1350
+ handler(context) {
1351
+ if (context.type !== "update" || this.environment.config.consumer !== "client" || !identityFor(context.file))
1352
+ return;
1353
+ if (!annotatedModules.has(context.file)) return;
1354
+ const modules = this.environment.moduleGraph.getModulesByFile(
1355
+ context.file
1356
+ );
1357
+ const stamped = [...modules ?? []].filter(
1358
+ (module) => module.id === context.file || module.id?.startsWith(`${context.file}?vue&type=template`)
1359
+ );
1360
+ if (stamped.length)
1361
+ return [.../* @__PURE__ */ new Set([...context.modules, ...stamped])];
1362
+ }
1363
+ },
1364
+ transform: {
1365
+ filter: { id: VUE_MAIN_MODULE },
1366
+ handler(code, id) {
1367
+ const registry = annotatedModules.get(id);
1368
+ if (!registry) return void 0;
1369
+ const withRegistry = appendVueSourceRegistryRecord(code, registry);
1370
+ return {
1371
+ code: appendModuleVersionRecord(
1372
+ withRegistry,
1373
+ registry.filepath,
1374
+ registry.modifiedTs,
1375
+ registry.sourceVersion
1376
+ ),
1377
+ // Appended after the last line: no mapping moves.
1378
+ map: null
1379
+ };
1380
+ }
1381
+ }
1382
+ }
1383
+ ];
1384
+ }
1385
+ function tempoVueAppPlugins(options) {
1386
+ return loadAppVitePlugins({
1387
+ hostRoot: options.root,
1388
+ appRoot: options.appRoot,
1389
+ compiler: { name: "vite:vue", fallback: options.vue },
1390
+ exclude: options.exclude
1391
+ });
1392
+ }
1393
+ function isUnderAny(file, directories) {
1394
+ return directories.some((directory) => {
1395
+ const relativePath = relative2(directory, file);
1396
+ return relativePath === "" || !relativePath.startsWith("..") && !isAbsolute2(relativePath);
1397
+ });
1398
+ }
1399
+ export {
1400
+ tempoVueAppPlugins,
1401
+ tempoVuePlugin
1402
+ };
1403
+ //# sourceMappingURL=vue.js.map