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.
- package/README.md +3 -403
- package/dist/assets/editor.d.ts +43 -65
- package/dist/assets/editor.js +1 -573
- package/dist/assets/index.d.ts +11 -61
- package/dist/assets/index.js +1 -338
- package/dist/assets/parser.d.ts +68 -78
- package/dist/assets/parser.js +1 -33
- package/dist/astro/asset-preview-client.d.ts +3 -2
- package/dist/astro/asset-preview-client.js +1 -93
- package/dist/astro/controls.d.ts +1 -3
- package/dist/astro/controls.js +1 -7
- package/dist/astro/document-client.d.ts +5 -6
- package/dist/astro/document-client.js +1 -78
- package/dist/astro/runtime.d.ts +23 -11
- package/dist/astro/runtime.js +1 -86
- package/dist/astro.d.ts +19 -13
- package/dist/astro.js +1 -818
- package/dist/canvas/astro-contract.d.ts +0 -3
- package/dist/canvas/astro-contract.js +1 -9
- package/dist/canvas/astro.d.ts +3 -4
- package/dist/canvas/astro.js +1 -42
- package/dist/canvas/editor.d.ts +187 -183
- package/dist/canvas/editor.js +1 -1094
- package/dist/canvas/flutter-preview.d.ts +0 -1
- package/dist/canvas/flutter-preview.js +1 -9
- package/dist/canvas/index.d.ts +46 -100
- package/dist/canvas/index.js +1 -3926
- package/dist/canvas/interact-projection.d.ts +7 -5
- package/dist/canvas/interact-projection.js +1 -12
- package/dist/canvas/parser.d.ts +10 -303
- package/dist/canvas/parser.js +1 -30
- package/dist/canvas/svelte.d.ts +6 -7
- package/dist/canvas/svelte.js +1 -91
- package/dist/canvas/vue.d.ts +9 -49
- package/dist/canvas/vue.js +1 -264
- package/dist/chunk-CXCUJCXD.js +1 -0
- package/dist/chunk-FH6TMWFA.js +1 -0
- package/dist/chunk-FL7FSJSL.js +1 -0
- package/dist/chunk-GQIOB5SV.js +1 -0
- package/dist/chunk-HBQ7FFH7.js +1 -0
- package/dist/chunk-JRJOWLCN.js +1 -0
- package/dist/chunk-LJCBFTMP.js +1 -0
- package/dist/chunk-M3GN2KUH.js +1 -0
- package/dist/chunk-MPIHFFML.js +1 -0
- package/dist/chunk-T5TY3U2H.js +1 -0
- package/dist/chunk-XO2BSHWM.js +1 -0
- package/dist/chunk-XUSV3KOD.js +1 -0
- package/dist/chunk-ZXBMP6RV.js +1 -0
- package/dist/{controls-uCaQ3CNX.d.ts → controls-DKslABtM.d.ts} +0 -3
- package/dist/expo/plugin.cjs +1 -1928
- package/dist/expo/plugin.js +1 -8
- package/dist/expo-babel-plugin.cjs +1 -1928
- package/dist/expo-babel-plugin.d.cts +46 -40
- package/dist/expo-babel-plugin.d.ts +46 -40
- package/dist/expo-babel-plugin.js +1 -8
- package/dist/flutter-preview-path.d.ts +23 -7
- package/dist/flutter-preview-path.js +1 -16
- package/dist/index.d.ts +33 -45
- package/dist/index.js +1 -20
- package/dist/nextjs/plugin.cjs +1 -413
- package/dist/nextjs/plugin.js +1 -7
- package/dist/nextjs-loader.cjs +1 -2277
- package/dist/nextjs.cjs +1 -484
- package/dist/nextjs.d.cts +2 -58
- package/dist/nextjs.d.ts +2 -58
- package/dist/nextjs.js +1 -17
- package/dist/nuxt/runtime/identity.d.ts +2 -4
- package/dist/nuxt/runtime/identity.js +1 -18
- package/dist/nuxt.d.ts +31 -92
- package/dist/nuxt.js +1 -5854
- package/dist/{page-DwLnOM5d.d.ts → page-Bc8PekIX.d.ts} +1 -5
- package/dist/parser.d-MO5ciJ5n.d.ts +236 -0
- package/dist/{storyboard-CMJVBSXn.d.ts → storyboard.contract.d-UQ4MUYN5.d.ts} +3 -25
- package/dist/svelte.d.ts +8 -18
- package/dist/svelte.js +1 -917
- package/dist/types-CfUgM2w4.d.ts +57 -0
- package/dist/v1-client-compat-n0E0XxuX.d.ts +5 -0
- package/dist/vue.d.ts +17 -58
- package/dist/vue.js +1 -1501
- package/package.json +12 -62
- package/dist/assets/editor.js.map +0 -1
- package/dist/assets/index.js.map +0 -1
- package/dist/assets/parser.js.map +0 -1
- package/dist/astro/asset-preview-client.js.map +0 -1
- package/dist/astro/controls.js.map +0 -1
- package/dist/astro/document-client.js.map +0 -1
- package/dist/astro/runtime.js.map +0 -1
- package/dist/astro.js.map +0 -1
- package/dist/canvas/astro-contract.js.map +0 -1
- package/dist/canvas/astro.js.map +0 -1
- package/dist/canvas/editor.js.map +0 -1
- package/dist/canvas/flutter-preview.js.map +0 -1
- package/dist/canvas/index.js.map +0 -1
- package/dist/canvas/interact-projection.js.map +0 -1
- package/dist/canvas/parser.js.map +0 -1
- package/dist/canvas/svelte.js.map +0 -1
- package/dist/canvas/vue.js.map +0 -1
- package/dist/chunk-27WT3XUG.js +0 -455
- package/dist/chunk-27WT3XUG.js.map +0 -1
- package/dist/chunk-5HIIF354.js +0 -67
- package/dist/chunk-5HIIF354.js.map +0 -1
- package/dist/chunk-65B52AR7.js +0 -11
- package/dist/chunk-65B52AR7.js.map +0 -1
- package/dist/chunk-6HYKKP5N.js +0 -2658
- package/dist/chunk-6HYKKP5N.js.map +0 -1
- package/dist/chunk-6SOP4XU6.js +0 -1891
- package/dist/chunk-6SOP4XU6.js.map +0 -1
- package/dist/chunk-AFXE462X.js +0 -1253
- package/dist/chunk-AFXE462X.js.map +0 -1
- package/dist/chunk-BQPKOVI5.js +0 -115
- package/dist/chunk-BQPKOVI5.js.map +0 -1
- package/dist/chunk-CYDF4LYJ.js +0 -342
- package/dist/chunk-CYDF4LYJ.js.map +0 -1
- package/dist/chunk-CYQE3TLC.js +0 -37
- package/dist/chunk-CYQE3TLC.js.map +0 -1
- package/dist/chunk-DI2ZFAWL.js +0 -14
- package/dist/chunk-DI2ZFAWL.js.map +0 -1
- package/dist/chunk-EGRHWZRV.js +0 -1
- package/dist/chunk-EGRHWZRV.js.map +0 -1
- package/dist/chunk-FGWGY3G3.js +0 -157
- package/dist/chunk-FGWGY3G3.js.map +0 -1
- package/dist/chunk-HOBTDB6G.js +0 -112
- package/dist/chunk-HOBTDB6G.js.map +0 -1
- package/dist/chunk-I7VF4ZOV.js +0 -630
- package/dist/chunk-I7VF4ZOV.js.map +0 -1
- package/dist/chunk-JVVHU3A7.js +0 -1077
- package/dist/chunk-JVVHU3A7.js.map +0 -1
- package/dist/chunk-MIXQVPDH.js +0 -8606
- package/dist/chunk-MIXQVPDH.js.map +0 -1
- package/dist/chunk-MU7S7NU7.js +0 -183
- package/dist/chunk-MU7S7NU7.js.map +0 -1
- package/dist/chunk-OX2YKYSL.js +0 -13
- package/dist/chunk-OX2YKYSL.js.map +0 -1
- package/dist/chunk-PYAJHLXO.js +0 -903
- package/dist/chunk-PYAJHLXO.js.map +0 -1
- package/dist/chunk-SGN7BDRE.js +0 -16
- package/dist/chunk-SGN7BDRE.js.map +0 -1
- package/dist/chunk-SGTGDLOX.js +0 -285
- package/dist/chunk-SGTGDLOX.js.map +0 -1
- package/dist/chunk-T364NBR3.js +0 -1440
- package/dist/chunk-T364NBR3.js.map +0 -1
- package/dist/chunk-U66QI3EN.js +0 -1524
- package/dist/chunk-U66QI3EN.js.map +0 -1
- package/dist/chunk-WTXOWQ7N.js +0 -47
- package/dist/chunk-WTXOWQ7N.js.map +0 -1
- package/dist/chunk-X5DJKVBT.js +0 -1308
- package/dist/chunk-X5DJKVBT.js.map +0 -1
- package/dist/chunk-ZT7HJ6YU.js +0 -38
- package/dist/chunk-ZT7HJ6YU.js.map +0 -1
- package/dist/chunk-ZW26VZHX.js +0 -3169
- package/dist/chunk-ZW26VZHX.js.map +0 -1
- package/dist/controls-reader-5MFHYBZZ.js +0 -192
- package/dist/controls-reader-5MFHYBZZ.js.map +0 -1
- package/dist/expo/plugin.cjs.map +0 -1
- package/dist/expo/plugin.js.map +0 -1
- package/dist/expo-babel-plugin.cjs.map +0 -1
- package/dist/expo-babel-plugin.js.map +0 -1
- package/dist/flutter-preview-path.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/nextjs/plugin.cjs.map +0 -1
- package/dist/nextjs/plugin.js.map +0 -1
- package/dist/nextjs-loader.cjs.map +0 -1
- package/dist/nextjs.cjs.map +0 -1
- package/dist/nextjs.js.map +0 -1
- package/dist/nuxt/runtime/identity.js.map +0 -1
- package/dist/nuxt.js.map +0 -1
- package/dist/svelte.js.map +0 -1
- package/dist/types-C8OIU-kc.d.ts +0 -106
- package/dist/v1-client-compat-qxaXEDm_.d.ts +0 -23
- package/dist/vue.js.map +0 -1
package/dist/chunk-AFXE462X.js
DELETED
|
@@ -1,1253 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
parseFlutterPreview
|
|
3
|
-
} from "./chunk-CYQE3TLC.js";
|
|
4
|
-
|
|
5
|
-
// canvas/parser.ts
|
|
6
|
-
import { parseSync } from "oxc-parser";
|
|
7
|
-
|
|
8
|
-
// canvas/storyboard-components.ts
|
|
9
|
-
var STORYBOARD_SDK_COMPONENT_ROWS = {
|
|
10
|
-
Storyboard: {
|
|
11
|
-
importSource: "tempo-sdk/canvas",
|
|
12
|
-
kind: "component",
|
|
13
|
-
requiresComponentProp: true,
|
|
14
|
-
allowsVrt: true,
|
|
15
|
-
componentFileExtension: ".tsx"
|
|
16
|
-
},
|
|
17
|
-
SvelteStoryboard: {
|
|
18
|
-
importSource: "tempo-sdk/canvas/svelte",
|
|
19
|
-
kind: "component",
|
|
20
|
-
uiFramework: "svelte",
|
|
21
|
-
requiresComponentProp: true,
|
|
22
|
-
allowsVrt: true,
|
|
23
|
-
componentFileExtension: ".svelte"
|
|
24
|
-
},
|
|
25
|
-
VueStoryboard: {
|
|
26
|
-
importSource: "tempo-sdk/canvas/vue",
|
|
27
|
-
kind: "component",
|
|
28
|
-
uiFramework: "vue",
|
|
29
|
-
requiresComponentProp: true,
|
|
30
|
-
allowsVrt: true,
|
|
31
|
-
componentFileExtension: ".vue"
|
|
32
|
-
},
|
|
33
|
-
AstroStoryboard: {
|
|
34
|
-
importSource: "tempo-sdk/canvas/astro",
|
|
35
|
-
kind: "component",
|
|
36
|
-
uiFramework: "astro",
|
|
37
|
-
requiresComponentProp: true,
|
|
38
|
-
allowsVrt: true,
|
|
39
|
-
componentFileExtension: ".astro",
|
|
40
|
-
componentImportQuery: "?tempo-component"
|
|
41
|
-
},
|
|
42
|
-
FlutterStoryboard: {
|
|
43
|
-
importSource: "tempo-sdk/canvas",
|
|
44
|
-
kind: "component",
|
|
45
|
-
requiresComponentProp: false,
|
|
46
|
-
allowsVrt: true
|
|
47
|
-
},
|
|
48
|
-
RouteStoryboard: {
|
|
49
|
-
importSource: "tempo-sdk/canvas",
|
|
50
|
-
kind: "route",
|
|
51
|
-
requiresComponentProp: false,
|
|
52
|
-
allowsVrt: false
|
|
53
|
-
},
|
|
54
|
-
HtmlStoryboard: {
|
|
55
|
-
importSource: "tempo-sdk/canvas",
|
|
56
|
-
kind: "html",
|
|
57
|
-
requiresComponentProp: false,
|
|
58
|
-
allowsVrt: true
|
|
59
|
-
},
|
|
60
|
-
LegacyStoryboardV1: {
|
|
61
|
-
importSource: "tempo-sdk/canvas",
|
|
62
|
-
kind: "component",
|
|
63
|
-
requiresComponentProp: false,
|
|
64
|
-
allowsVrt: false
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
var STORYBOARD_SDK_COMPONENTS = STORYBOARD_SDK_COMPONENT_ROWS;
|
|
68
|
-
var STORYBOARD_SDK_COMPONENT_NAMES = Object.keys(
|
|
69
|
-
STORYBOARD_SDK_COMPONENTS
|
|
70
|
-
);
|
|
71
|
-
function storyboardComponentForFramework(uiFramework) {
|
|
72
|
-
if (uiFramework === void 0 || uiFramework === "react") {
|
|
73
|
-
return "Storyboard";
|
|
74
|
-
}
|
|
75
|
-
const component = STORYBOARD_SDK_COMPONENT_NAMES.find(
|
|
76
|
-
(name) => STORYBOARD_SDK_COMPONENTS[name].uiFramework === uiFramework
|
|
77
|
-
);
|
|
78
|
-
if (!component) {
|
|
79
|
-
throw new Error(`No storyboard component renders "${uiFramework}"`);
|
|
80
|
-
}
|
|
81
|
-
return component;
|
|
82
|
-
}
|
|
83
|
-
function componentFileExtensionForFramework(uiFramework) {
|
|
84
|
-
const component = storyboardComponentForFramework(uiFramework);
|
|
85
|
-
const extension = STORYBOARD_SDK_COMPONENTS[component].componentFileExtension;
|
|
86
|
-
if (!extension) {
|
|
87
|
-
throw new Error(`<${component}> declares no component file extension`);
|
|
88
|
-
}
|
|
89
|
-
return extension;
|
|
90
|
-
}
|
|
91
|
-
function componentImportSpecifier(source) {
|
|
92
|
-
for (const spec of Object.values(STORYBOARD_SDK_COMPONENTS)) {
|
|
93
|
-
const query = spec.componentImportQuery;
|
|
94
|
-
const extension = spec.componentFileExtension;
|
|
95
|
-
if (!query || !extension) continue;
|
|
96
|
-
if (source.endsWith(extension)) return source + query;
|
|
97
|
-
}
|
|
98
|
-
return source;
|
|
99
|
-
}
|
|
100
|
-
function componentImportPath(source) {
|
|
101
|
-
for (const spec of Object.values(STORYBOARD_SDK_COMPONENTS)) {
|
|
102
|
-
const query = spec.componentImportQuery;
|
|
103
|
-
if (query && source.endsWith(query)) {
|
|
104
|
-
return source.slice(0, -query.length);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
return source;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// canvas/parser.ts
|
|
111
|
-
function componentFrameworkForStoryboard(storyboard) {
|
|
112
|
-
return storyboard.componentFramework ?? storyboard.runtimeFramework ?? storyboard.uiFramework;
|
|
113
|
-
}
|
|
114
|
-
var SDK_IMPORT_SOURCES = /* @__PURE__ */ new Set([
|
|
115
|
-
"tempo-sdk/canvas",
|
|
116
|
-
...STORYBOARD_SDK_COMPONENT_NAMES.map(
|
|
117
|
-
(component) => STORYBOARD_SDK_COMPONENTS[component].importSource
|
|
118
|
-
)
|
|
119
|
-
]);
|
|
120
|
-
var SDK_COMPONENTS = /* @__PURE__ */ new Set([
|
|
121
|
-
"Canvas",
|
|
122
|
-
...STORYBOARD_SDK_COMPONENT_NAMES
|
|
123
|
-
]);
|
|
124
|
-
var CANVAS_CHILDREN_ERROR = `<Canvas> children must be ${formatAlternatives(
|
|
125
|
-
STORYBOARD_SDK_COMPONENT_NAMES.map((component) => `<${component}>`)
|
|
126
|
-
)} declarations`;
|
|
127
|
-
var SDK_CANVAS_VALUE_EXPORTS = /* @__PURE__ */ new Set([
|
|
128
|
-
"Canvas",
|
|
129
|
-
"CanvasContext",
|
|
130
|
-
"getCanvasStoryboardRenderId",
|
|
131
|
-
"CanvasHost",
|
|
132
|
-
"buildRenderContentFiberSelector",
|
|
133
|
-
"buildRenderContentSelector",
|
|
134
|
-
"buildRenderSelector",
|
|
135
|
-
"captureStoryboardCombined",
|
|
136
|
-
"captureStoryboardHtml",
|
|
137
|
-
"captureStoryboardImage",
|
|
138
|
-
"stripRenderContentWrapperAttributes",
|
|
139
|
-
"stripRenderContentWrapperFromCombinedCapture",
|
|
140
|
-
"watchStoryboardCombined",
|
|
141
|
-
"getCanvasHostRuntime",
|
|
142
|
-
"getOptionalCanvasHostRuntime",
|
|
143
|
-
"useActiveState",
|
|
144
|
-
"FlutterStoryboard",
|
|
145
|
-
"HtmlStoryboard",
|
|
146
|
-
"LegacyStoryboardV1",
|
|
147
|
-
"RouteStoryboard",
|
|
148
|
-
"Storyboard",
|
|
149
|
-
"StoryboardSlot"
|
|
150
|
-
]);
|
|
151
|
-
var DEFAULT_LAYOUT = {
|
|
152
|
-
x: 0,
|
|
153
|
-
y: 0
|
|
154
|
-
};
|
|
155
|
-
var DEFAULT_VIEWPORT_LAYOUT = {
|
|
156
|
-
...DEFAULT_LAYOUT,
|
|
157
|
-
width: 600,
|
|
158
|
-
height: 400
|
|
159
|
-
};
|
|
160
|
-
var NO_CANVAS_DECLARATION_ERROR = "No <Canvas> declaration found in canvas file";
|
|
161
|
-
function parseCanvasFile(filePath, source) {
|
|
162
|
-
const errors = [];
|
|
163
|
-
let program;
|
|
164
|
-
try {
|
|
165
|
-
const result = parseSync(filePath, source);
|
|
166
|
-
program = result.program;
|
|
167
|
-
for (const error of result.errors ?? []) {
|
|
168
|
-
errors.push({
|
|
169
|
-
message: error.message ?? "Unable to parse canvas source",
|
|
170
|
-
span: toSpan(error) ?? toSpan(error?.labels?.[0]),
|
|
171
|
-
kind: "structural"
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
} catch (error) {
|
|
175
|
-
return {
|
|
176
|
-
filePath,
|
|
177
|
-
pageName: fallbackPageName(filePath),
|
|
178
|
-
imports: [],
|
|
179
|
-
misimportedSdkCanvasImports: [],
|
|
180
|
-
storyboards: [],
|
|
181
|
-
errors: [
|
|
182
|
-
{
|
|
183
|
-
message: error instanceof Error ? error.message : "Unable to parse canvas source",
|
|
184
|
-
kind: "structural"
|
|
185
|
-
}
|
|
186
|
-
]
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
const imports = readImports(program);
|
|
190
|
-
const misimportedSdkCanvasImports = readMisimportedSdkCanvasImports(program);
|
|
191
|
-
const { legacyObjects, stringBindings: objectStringBindings } = readObjectExpressionBindings(program, imports, source);
|
|
192
|
-
let canvasElement = null;
|
|
193
|
-
const allStoryboardElements = [];
|
|
194
|
-
walk(program, (node) => {
|
|
195
|
-
if (node.type !== "JSXElement") return;
|
|
196
|
-
const component = resolveSdkComponent(node.openingElement?.name, imports);
|
|
197
|
-
const namespaceMisimport = resolveMisimportedNamespaceSdkComponent(
|
|
198
|
-
node.openingElement?.name,
|
|
199
|
-
imports,
|
|
200
|
-
misimportedSdkCanvasImports
|
|
201
|
-
);
|
|
202
|
-
if (namespaceMisimport) {
|
|
203
|
-
misimportedSdkCanvasImports.add(namespaceMisimport);
|
|
204
|
-
}
|
|
205
|
-
if (component === "Canvas") {
|
|
206
|
-
if (!canvasElement) {
|
|
207
|
-
canvasElement = node;
|
|
208
|
-
} else {
|
|
209
|
-
errors.push({
|
|
210
|
-
message: "Canvas file must declare exactly one <Canvas> element",
|
|
211
|
-
span: toSpan(node),
|
|
212
|
-
kind: "structural"
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
if (isStoryboardSdkComponent(component)) {
|
|
218
|
-
allStoryboardElements.push({ element: node, component });
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
const directStoryboardElements = canvasElement ? readDirectCanvasStoryboardElements(canvasElement, imports) : [];
|
|
222
|
-
const directStoryboardElementSet = new Set(
|
|
223
|
-
directStoryboardElements.map((item) => item.element)
|
|
224
|
-
);
|
|
225
|
-
const storyboards = directStoryboardElements.map(
|
|
226
|
-
(item) => readStoryboard(
|
|
227
|
-
item.element,
|
|
228
|
-
item.component,
|
|
229
|
-
imports,
|
|
230
|
-
legacyObjects,
|
|
231
|
-
source,
|
|
232
|
-
errors
|
|
233
|
-
)
|
|
234
|
-
);
|
|
235
|
-
for (const item of allStoryboardElements) {
|
|
236
|
-
if (directStoryboardElementSet.has(item.element)) continue;
|
|
237
|
-
errors.push({
|
|
238
|
-
message: `<${item.component}> declarations must be direct children of the <Canvas> element`,
|
|
239
|
-
span: toSpan(item.element),
|
|
240
|
-
kind: "structural"
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
reportDuplicateStoryboardIds(storyboards, errors);
|
|
244
|
-
if (!canvasElement) {
|
|
245
|
-
if (misimportedSdkCanvasImports.all.length > 0) {
|
|
246
|
-
for (const entry of misimportedSdkCanvasImports.all) {
|
|
247
|
-
errors.push({
|
|
248
|
-
message: misimportedSdkCanvasImportMessage(entry),
|
|
249
|
-
span: entry.sourceSpan,
|
|
250
|
-
kind: "structural"
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
} else {
|
|
254
|
-
errors.push({
|
|
255
|
-
message: NO_CANVAS_DECLARATION_ERROR,
|
|
256
|
-
kind: "structural"
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
} else {
|
|
260
|
-
errors.push(...validateCanvasChildren(canvasElement, imports));
|
|
261
|
-
}
|
|
262
|
-
const openingElement = canvasElement?.openingElement;
|
|
263
|
-
const name = readResolvableStringAttribute(
|
|
264
|
-
openingElement,
|
|
265
|
-
"name",
|
|
266
|
-
objectStringBindings
|
|
267
|
-
);
|
|
268
|
-
const path = readStringAttribute(openingElement, "path");
|
|
269
|
-
const backgroundColor = readResolvableStringAttribute(
|
|
270
|
-
openingElement,
|
|
271
|
-
"backgroundColor",
|
|
272
|
-
objectStringBindings
|
|
273
|
-
) ?? readResolvableStringAttribute(
|
|
274
|
-
openingElement,
|
|
275
|
-
"background",
|
|
276
|
-
objectStringBindings
|
|
277
|
-
);
|
|
278
|
-
if (openingElement && !name) {
|
|
279
|
-
errors.push({
|
|
280
|
-
message: '<Canvas> must include a literal "name" prop',
|
|
281
|
-
span: toSpan(openingElement),
|
|
282
|
-
kind: "degraded"
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
return {
|
|
286
|
-
filePath,
|
|
287
|
-
canvasPath: path?.value,
|
|
288
|
-
pageName: name?.value ?? fallbackPageName(filePath),
|
|
289
|
-
backgroundColor: backgroundColor?.value,
|
|
290
|
-
canvasElementSpan: toSpan(canvasElement),
|
|
291
|
-
canvasOpeningElementSpan: toSpan(openingElement),
|
|
292
|
-
canvasChildrenInsertionOffset: typeof canvasElement?.closingElement?.start === "number" ? canvasElement.closingElement.start : void 0,
|
|
293
|
-
nameSpan: name?.valueSpan,
|
|
294
|
-
nameAttributeSpan: name?.attributeSpan,
|
|
295
|
-
pathSpan: path?.valueSpan,
|
|
296
|
-
pathAttributeSpan: path?.attributeSpan,
|
|
297
|
-
backgroundColorSpan: backgroundColor?.valueSpan,
|
|
298
|
-
backgroundColorAttributeSpan: backgroundColor?.attributeSpan,
|
|
299
|
-
imports: imports.all,
|
|
300
|
-
misimportedSdkCanvasImports: misimportedSdkCanvasImports.all,
|
|
301
|
-
storyboards,
|
|
302
|
-
errors
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
function misimportedSdkCanvasImportMessage(entry) {
|
|
306
|
-
return `Tempo canvas components must be imported from "tempo-sdk/canvas" \u2014 found import of ${entry.importedNames.join(", ")} from "${entry.source}"`;
|
|
307
|
-
}
|
|
308
|
-
function readMisimportedSdkCanvasImports(program) {
|
|
309
|
-
const all = [];
|
|
310
|
-
const byDeclarationKey = /* @__PURE__ */ new Map();
|
|
311
|
-
const namespaceCandidatesByLocalName = /* @__PURE__ */ new Map();
|
|
312
|
-
const add = (entry) => {
|
|
313
|
-
const key = spanKey(entry.sourceSpan);
|
|
314
|
-
if (byDeclarationKey.has(key)) return;
|
|
315
|
-
byDeclarationKey.set(key, entry);
|
|
316
|
-
all.push(entry);
|
|
317
|
-
};
|
|
318
|
-
for (const statement of program?.body ?? []) {
|
|
319
|
-
if (statement?.type !== "ImportDeclaration" || typeof statement.source?.value !== "string" || !isWrongTempoSdkCanvasImportSource(statement.source.value) || statement.importKind === "type") {
|
|
320
|
-
continue;
|
|
321
|
-
}
|
|
322
|
-
const source = statement.source.value;
|
|
323
|
-
const sourceSpan = toSpan(statement.source);
|
|
324
|
-
if (!sourceSpan) continue;
|
|
325
|
-
const valueSpecifiers = (statement.specifiers ?? []).filter(
|
|
326
|
-
(specifier) => specifier?.importKind !== "type"
|
|
327
|
-
);
|
|
328
|
-
const importedNames = valueSpecifiers.map(readImportedName);
|
|
329
|
-
const entry = {
|
|
330
|
-
source,
|
|
331
|
-
sourceSpan,
|
|
332
|
-
importedNames,
|
|
333
|
-
rewritable: valueSpecifiers.length > 0 && valueSpecifiers.every(
|
|
334
|
-
(specifier) => specifier?.type === "ImportSpecifier" && SDK_CANVAS_VALUE_EXPORTS.has(readImportedName(specifier))
|
|
335
|
-
)
|
|
336
|
-
};
|
|
337
|
-
const hasMisimportedNamedSdkComponent = valueSpecifiers.some(
|
|
338
|
-
(specifier) => specifier?.type === "ImportSpecifier" && SDK_COMPONENTS.has(readImportedName(specifier))
|
|
339
|
-
);
|
|
340
|
-
if (hasMisimportedNamedSdkComponent) {
|
|
341
|
-
add(entry);
|
|
342
|
-
}
|
|
343
|
-
for (const specifier of valueSpecifiers) {
|
|
344
|
-
if (specifier?.type !== "ImportNamespaceSpecifier") continue;
|
|
345
|
-
const localName = specifier.local?.name;
|
|
346
|
-
if (typeof localName === "string") {
|
|
347
|
-
namespaceCandidatesByLocalName.set(localName, entry);
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
return { all, byDeclarationKey, namespaceCandidatesByLocalName, add };
|
|
352
|
-
}
|
|
353
|
-
function readImports(program) {
|
|
354
|
-
const all = [];
|
|
355
|
-
const byLocalName = /* @__PURE__ */ new Map();
|
|
356
|
-
const sdkLocalNames = /* @__PURE__ */ new Map();
|
|
357
|
-
const sdkNamespaces = /* @__PURE__ */ new Set();
|
|
358
|
-
for (const statement of program?.body ?? []) {
|
|
359
|
-
if (statement?.type !== "ImportDeclaration" || typeof statement.source?.value !== "string") {
|
|
360
|
-
continue;
|
|
361
|
-
}
|
|
362
|
-
const source = statement.source.value;
|
|
363
|
-
const isSdkImport = isSdkImportSource(source);
|
|
364
|
-
for (const specifier of statement.specifiers ?? []) {
|
|
365
|
-
const localName = specifier.local?.name;
|
|
366
|
-
if (typeof localName !== "string") continue;
|
|
367
|
-
const importedName = readImportedName(specifier);
|
|
368
|
-
const imported = {
|
|
369
|
-
localName,
|
|
370
|
-
source,
|
|
371
|
-
importedName,
|
|
372
|
-
kind: readImportKind(specifier),
|
|
373
|
-
importKind: specifier.importKind === "type" ? "type" : "value",
|
|
374
|
-
span: toSpan(specifier) ?? toSpan(statement) ?? { start: 0, end: 0 },
|
|
375
|
-
declarationSpan: toSpan(statement) ?? { start: 0, end: 0 },
|
|
376
|
-
specifierCount: statement.specifiers?.length ?? 0,
|
|
377
|
-
namedSpecifierCount: (statement.specifiers ?? []).filter(
|
|
378
|
-
(item) => item?.type === "ImportSpecifier"
|
|
379
|
-
).length,
|
|
380
|
-
hasDefaultSpecifier: (statement.specifiers ?? []).some(
|
|
381
|
-
(item) => item?.type === "ImportDefaultSpecifier"
|
|
382
|
-
),
|
|
383
|
-
hasNamespaceSpecifier: (statement.specifiers ?? []).some(
|
|
384
|
-
(item) => item?.type === "ImportNamespaceSpecifier"
|
|
385
|
-
)
|
|
386
|
-
};
|
|
387
|
-
all.push(imported);
|
|
388
|
-
byLocalName.set(localName, imported);
|
|
389
|
-
if (!isSdkImport) continue;
|
|
390
|
-
if (specifier.type === "ImportNamespaceSpecifier") {
|
|
391
|
-
sdkNamespaces.add(localName);
|
|
392
|
-
continue;
|
|
393
|
-
}
|
|
394
|
-
if (SDK_COMPONENTS.has(importedName)) {
|
|
395
|
-
sdkLocalNames.set(localName, importedName);
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
return { all, byLocalName, sdkLocalNames, sdkNamespaces };
|
|
400
|
-
}
|
|
401
|
-
function readObjectExpressionBindings(program, imports, source) {
|
|
402
|
-
const legacyObjects = /* @__PURE__ */ new Map();
|
|
403
|
-
const stringBindings = /* @__PURE__ */ new Map();
|
|
404
|
-
for (const node of readTopLevelVariableDeclarators(program)) {
|
|
405
|
-
if (node.id?.type !== "Identifier") {
|
|
406
|
-
continue;
|
|
407
|
-
}
|
|
408
|
-
const objectExpression = unwrapTsExpression(node.init);
|
|
409
|
-
if (objectExpression?.type !== "ObjectExpression") continue;
|
|
410
|
-
const bindingName = node.id.name;
|
|
411
|
-
legacyObjects.set(
|
|
412
|
-
bindingName,
|
|
413
|
-
readLegacyStoryboardObject(
|
|
414
|
-
bindingName,
|
|
415
|
-
objectExpression,
|
|
416
|
-
imports,
|
|
417
|
-
source
|
|
418
|
-
)
|
|
419
|
-
);
|
|
420
|
-
const stringProperties = readObjectStringProperties(objectExpression);
|
|
421
|
-
if (stringProperties.size > 0) {
|
|
422
|
-
stringBindings.set(bindingName, stringProperties);
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
return { legacyObjects, stringBindings };
|
|
426
|
-
}
|
|
427
|
-
function readTopLevelVariableDeclarators(program) {
|
|
428
|
-
const declarators = [];
|
|
429
|
-
for (const statement of program?.body ?? []) {
|
|
430
|
-
const declaration = statement?.type === "VariableDeclaration" ? statement : statement?.type === "ExportNamedDeclaration" && statement.declaration?.type === "VariableDeclaration" ? statement.declaration : null;
|
|
431
|
-
if (!declaration) continue;
|
|
432
|
-
declarators.push(...declaration.declarations ?? []);
|
|
433
|
-
}
|
|
434
|
-
return declarators;
|
|
435
|
-
}
|
|
436
|
-
function readLegacyStoryboardObject(bindingName, objectExpression, imports, source) {
|
|
437
|
-
const errors = [];
|
|
438
|
-
const nameProperty = getObjectProperty(objectExpression, "name");
|
|
439
|
-
const name = nameProperty ? readStringLiteralValue(nameProperty.value) : null;
|
|
440
|
-
const layoutProperty = getObjectProperty(objectExpression, "layout");
|
|
441
|
-
const layout = layoutProperty ? readLayoutExpression(layoutProperty.value, "LegacyStoryboardV1") : {
|
|
442
|
-
value: DEFAULT_LAYOUT,
|
|
443
|
-
errors: [
|
|
444
|
-
{
|
|
445
|
-
message: '<LegacyStoryboardV1> storyboard object must include a literal "layout" object',
|
|
446
|
-
span: toSpan(objectExpression),
|
|
447
|
-
kind: "degraded"
|
|
448
|
-
}
|
|
449
|
-
]
|
|
450
|
-
};
|
|
451
|
-
const renderProperty = getObjectProperty(objectExpression, "render");
|
|
452
|
-
const component = readRenderComponentReference(
|
|
453
|
-
renderProperty?.value,
|
|
454
|
-
imports,
|
|
455
|
-
source
|
|
456
|
-
);
|
|
457
|
-
if (nameProperty && !name) {
|
|
458
|
-
errors.push({
|
|
459
|
-
message: "<LegacyStoryboardV1> storyboard.name must be a string literal when set",
|
|
460
|
-
span: toSpan(nameProperty),
|
|
461
|
-
kind: "degraded"
|
|
462
|
-
});
|
|
463
|
-
}
|
|
464
|
-
errors.push(...layout.errors);
|
|
465
|
-
return {
|
|
466
|
-
bindingName,
|
|
467
|
-
displayName: name?.value,
|
|
468
|
-
component: component ?? void 0,
|
|
469
|
-
objectSpan: toSpan(objectExpression),
|
|
470
|
-
objectClose: readLayoutClose(objectExpression),
|
|
471
|
-
nameSpan: name?.span,
|
|
472
|
-
namePropertySpan: toSpan(nameProperty),
|
|
473
|
-
layoutPropertySpan: toSpan(layoutProperty),
|
|
474
|
-
layout: layout.value,
|
|
475
|
-
layoutSpans: layout.spans,
|
|
476
|
-
errors
|
|
477
|
-
};
|
|
478
|
-
}
|
|
479
|
-
function readObjectStringProperties(objectExpression) {
|
|
480
|
-
const properties = /* @__PURE__ */ new Map();
|
|
481
|
-
for (const property of objectExpression.properties ?? []) {
|
|
482
|
-
if (property?.type !== "Property" || property.computed) continue;
|
|
483
|
-
const propertyName = readPropertyKeyName(property.key);
|
|
484
|
-
const value = readStringLiteralValue(property.value);
|
|
485
|
-
if (!propertyName || !value) continue;
|
|
486
|
-
properties.set(propertyName, value);
|
|
487
|
-
}
|
|
488
|
-
return properties;
|
|
489
|
-
}
|
|
490
|
-
function readStoryboard(element, component, imports, legacyObjects, source, globalErrors) {
|
|
491
|
-
const openingElement = element.openingElement;
|
|
492
|
-
const errors = [];
|
|
493
|
-
const id = readStringAttribute(openingElement, "id");
|
|
494
|
-
const name = readStringAttribute(openingElement, "name");
|
|
495
|
-
const legacyReference = component === "LegacyStoryboardV1" ? readExpressionReference(openingElement, "storyboard", source) : void 0;
|
|
496
|
-
const legacyObject = legacyReference?.expression && isIdentifierExpression(legacyReference.expression) ? legacyObjects.get(legacyReference.expression) : void 0;
|
|
497
|
-
const layout = component === "LegacyStoryboardV1" ? {
|
|
498
|
-
value: legacyObject?.layout ?? DEFAULT_LAYOUT,
|
|
499
|
-
spans: legacyObject?.layoutSpans,
|
|
500
|
-
attributeSpan: void 0,
|
|
501
|
-
errors: legacyObject?.errors ?? (legacyReference ? [
|
|
502
|
-
{
|
|
503
|
-
message: "<LegacyStoryboardV1> storyboard prop must reference a same-file object literal",
|
|
504
|
-
span: legacyReference.span,
|
|
505
|
-
kind: "degraded"
|
|
506
|
-
}
|
|
507
|
-
] : [
|
|
508
|
-
{
|
|
509
|
-
message: '<LegacyStoryboardV1> must include a "storyboard" expression prop',
|
|
510
|
-
span: toSpan(openingElement),
|
|
511
|
-
kind: "degraded"
|
|
512
|
-
}
|
|
513
|
-
])
|
|
514
|
-
} : readLayout(openingElement, component);
|
|
515
|
-
const spec = STORYBOARD_SDK_COMPONENTS[component];
|
|
516
|
-
if (!id) {
|
|
517
|
-
errors.push({
|
|
518
|
-
message: `<${component}> must include a literal "id" prop`,
|
|
519
|
-
span: toSpan(openingElement),
|
|
520
|
-
kind: "structural"
|
|
521
|
-
});
|
|
522
|
-
}
|
|
523
|
-
if (layout.errors.length > 0) {
|
|
524
|
-
errors.push(...layout.errors);
|
|
525
|
-
}
|
|
526
|
-
const storyboard = {
|
|
527
|
-
storyboardKey: id?.value ?? "",
|
|
528
|
-
displayName: name?.value ?? legacyObject?.displayName,
|
|
529
|
-
kind: spec.kind,
|
|
530
|
-
...spec.uiFramework ? { componentFramework: spec.uiFramework } : {},
|
|
531
|
-
...spec.uiFramework === "svelte" ? { uiFramework: spec.uiFramework } : spec.uiFramework === "astro" ? { runtimeFramework: spec.uiFramework } : {},
|
|
532
|
-
layout: layout.value,
|
|
533
|
-
editable: Boolean(id) && layout.errors.length === 0,
|
|
534
|
-
jsxElementSpan: toSpan(element) ?? { start: 0, end: 0 },
|
|
535
|
-
openingElementSpan: toSpan(openingElement),
|
|
536
|
-
idSpan: id?.valueSpan,
|
|
537
|
-
idAttributeSpan: id?.attributeSpan,
|
|
538
|
-
nameSpan: name?.valueSpan ?? legacyObject?.nameSpan,
|
|
539
|
-
nameAttributeSpan: name?.attributeSpan ?? legacyObject?.namePropertySpan,
|
|
540
|
-
layoutAttributeSpan: layout.attributeSpan,
|
|
541
|
-
layoutSpans: layout.spans,
|
|
542
|
-
props: readExpressionReference(openingElement, "props", source),
|
|
543
|
-
component: legacyObject?.component,
|
|
544
|
-
legacyV1: legacyReference ? {
|
|
545
|
-
storyboard: legacyReference,
|
|
546
|
-
objectName: legacyObject?.bindingName,
|
|
547
|
-
objectSpan: legacyObject?.objectSpan,
|
|
548
|
-
objectClose: legacyObject?.objectClose,
|
|
549
|
-
namePropertySpan: legacyObject?.namePropertySpan,
|
|
550
|
-
layoutPropertySpan: legacyObject?.layoutPropertySpan
|
|
551
|
-
} : void 0,
|
|
552
|
-
errors
|
|
553
|
-
};
|
|
554
|
-
if (spec.requiresComponentProp) {
|
|
555
|
-
const componentReference = readComponentReference(
|
|
556
|
-
openingElement,
|
|
557
|
-
imports,
|
|
558
|
-
source
|
|
559
|
-
);
|
|
560
|
-
if (componentReference) {
|
|
561
|
-
storyboard.component = componentReference;
|
|
562
|
-
} else {
|
|
563
|
-
errors.push({
|
|
564
|
-
message: `<${component}> must include a "component" expression prop`,
|
|
565
|
-
span: toSpan(openingElement),
|
|
566
|
-
kind: "degraded"
|
|
567
|
-
});
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
if (spec.allowsVrt) {
|
|
571
|
-
const vrt = readVrt(openingElement, errors);
|
|
572
|
-
if (vrt) {
|
|
573
|
-
if (vrt.value) {
|
|
574
|
-
storyboard.vrt = vrt.value;
|
|
575
|
-
}
|
|
576
|
-
storyboard.vrtAttributeSpan = vrt.attributeSpan;
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
if (component === "RouteStoryboard") {
|
|
580
|
-
const route = readStringAttribute(openingElement, "route");
|
|
581
|
-
if (route) {
|
|
582
|
-
storyboard.route = route.value;
|
|
583
|
-
storyboard.routeSpan = route.valueSpan;
|
|
584
|
-
storyboard.routeAttributeSpan = route.attributeSpan;
|
|
585
|
-
} else {
|
|
586
|
-
errors.push({
|
|
587
|
-
message: '<RouteStoryboard> must include a literal "route" prop',
|
|
588
|
-
span: toSpan(openingElement),
|
|
589
|
-
kind: "degraded"
|
|
590
|
-
});
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
if (component === "HtmlStoryboard") {
|
|
594
|
-
const filepath = readStringAttribute(openingElement, "filepath");
|
|
595
|
-
const src = readStringAttribute(openingElement, "src");
|
|
596
|
-
storyboard.filepath = filepath?.value.trim() ? filepath.value : void 0;
|
|
597
|
-
storyboard.filepathSpan = filepath?.valueSpan;
|
|
598
|
-
storyboard.filepathAttributeSpan = filepath?.attributeSpan;
|
|
599
|
-
storyboard.src = src?.value;
|
|
600
|
-
storyboard.srcSpan = src?.valueSpan;
|
|
601
|
-
storyboard.srcAttributeSpan = src?.attributeSpan;
|
|
602
|
-
if (!filepath?.value.trim() && !src?.value.trim()) {
|
|
603
|
-
errors.push({
|
|
604
|
-
message: '<HtmlStoryboard> must include a literal "filepath" or "src" prop',
|
|
605
|
-
span: toSpan(openingElement),
|
|
606
|
-
kind: "degraded"
|
|
607
|
-
});
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
if (component === "FlutterStoryboard") {
|
|
611
|
-
const preview = readStringAttribute(openingElement, "preview");
|
|
612
|
-
if (preview?.value.trim()) {
|
|
613
|
-
storyboard.preview = preview.value;
|
|
614
|
-
storyboard.previewSpan = preview.valueSpan;
|
|
615
|
-
storyboard.previewAttributeSpan = preview.attributeSpan;
|
|
616
|
-
const parsedPreview = parseFlutterPreview(preview.value);
|
|
617
|
-
if ("error" in parsedPreview)
|
|
618
|
-
errors.push({
|
|
619
|
-
message: `flutter_preview_invalid: ${parsedPreview.error}`,
|
|
620
|
-
span: preview.valueSpan,
|
|
621
|
-
kind: "structural"
|
|
622
|
-
});
|
|
623
|
-
} else {
|
|
624
|
-
errors.push({
|
|
625
|
-
message: '<FlutterStoryboard> must include a literal "preview" prop naming a Flutter @Preview function, e.g. preview="../../lib/cards.dart#productCard"',
|
|
626
|
-
span: toSpan(getAttribute(openingElement, "preview") ?? openingElement),
|
|
627
|
-
kind: "structural"
|
|
628
|
-
});
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
globalErrors.push(...errors);
|
|
632
|
-
return storyboard;
|
|
633
|
-
}
|
|
634
|
-
function readDirectCanvasStoryboardElements(canvasElement, imports) {
|
|
635
|
-
const elements = [];
|
|
636
|
-
for (const child of canvasElement.children ?? []) {
|
|
637
|
-
if (child?.type !== "JSXElement") continue;
|
|
638
|
-
const component = resolveSdkComponent(child.openingElement?.name, imports);
|
|
639
|
-
if (isStoryboardSdkComponent(component)) {
|
|
640
|
-
elements.push({ element: child, component });
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
return elements;
|
|
644
|
-
}
|
|
645
|
-
function reportDuplicateStoryboardIds(storyboards, errors) {
|
|
646
|
-
const byId = /* @__PURE__ */ new Map();
|
|
647
|
-
for (const storyboard of storyboards) {
|
|
648
|
-
if (!storyboard.storyboardKey) continue;
|
|
649
|
-
const matching = byId.get(storyboard.storyboardKey);
|
|
650
|
-
if (matching) {
|
|
651
|
-
matching.push(storyboard);
|
|
652
|
-
} else {
|
|
653
|
-
byId.set(storyboard.storyboardKey, [storyboard]);
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
for (const [storyboardKey, matching] of byId) {
|
|
657
|
-
if (matching.length < 2) continue;
|
|
658
|
-
errors.push({
|
|
659
|
-
message: `Duplicate storyboard id "${storyboardKey}" (${matching.length} declarations) \u2014 storyboard ids must be unique`,
|
|
660
|
-
span: matching[1]?.jsxElementSpan,
|
|
661
|
-
kind: "structural"
|
|
662
|
-
});
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
function validateCanvasChildren(canvasElement, imports) {
|
|
666
|
-
const errors = [];
|
|
667
|
-
for (const child of canvasElement.children ?? []) {
|
|
668
|
-
if (!child) continue;
|
|
669
|
-
if (child.type === "JSXText") {
|
|
670
|
-
if (typeof child.value === "string" && child.value.trim() === "") {
|
|
671
|
-
continue;
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
if (child.type === "JSXExpressionContainer") {
|
|
675
|
-
if (child.expression?.type === "JSXEmptyExpression") {
|
|
676
|
-
continue;
|
|
677
|
-
}
|
|
678
|
-
errors.push({
|
|
679
|
-
message: "<Canvas> children must be static storyboard declarations, not expressions",
|
|
680
|
-
span: toSpan(child),
|
|
681
|
-
kind: "structural"
|
|
682
|
-
});
|
|
683
|
-
continue;
|
|
684
|
-
}
|
|
685
|
-
if (child.type === "JSXElement") {
|
|
686
|
-
const component = resolveSdkComponent(
|
|
687
|
-
child.openingElement?.name,
|
|
688
|
-
imports
|
|
689
|
-
);
|
|
690
|
-
if (isStoryboardSdkComponent(component)) continue;
|
|
691
|
-
const newerComponent = resolveNewerSdkStoryboardComponent(
|
|
692
|
-
child.openingElement?.name,
|
|
693
|
-
imports
|
|
694
|
-
);
|
|
695
|
-
if (newerComponent) {
|
|
696
|
-
errors.push(newerSdkStoryboardError(child, newerComponent));
|
|
697
|
-
continue;
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
errors.push({
|
|
701
|
-
message: CANVAS_CHILDREN_ERROR,
|
|
702
|
-
span: toSpan(child),
|
|
703
|
-
kind: "structural"
|
|
704
|
-
});
|
|
705
|
-
}
|
|
706
|
-
return errors;
|
|
707
|
-
}
|
|
708
|
-
var SDK_CANVAS_SUBPATH = /(^|\/)tempo-sdk\/canvas(\/[^/]+)?$/;
|
|
709
|
-
function resolveNewerSdkStoryboardComponent(nameNode, imports) {
|
|
710
|
-
let importedName;
|
|
711
|
-
let source;
|
|
712
|
-
if (nameNode?.type === "JSXIdentifier") {
|
|
713
|
-
const imported = imports.byLocalName.get(nameNode.name);
|
|
714
|
-
if (imported?.kind !== "named") return null;
|
|
715
|
-
importedName = imported.importedName;
|
|
716
|
-
source = imported.source;
|
|
717
|
-
} else if (nameNode?.type === "JSXMemberExpression" && nameNode.object?.type === "JSXIdentifier" && nameNode.property?.type === "JSXIdentifier") {
|
|
718
|
-
const imported = imports.byLocalName.get(nameNode.object.name);
|
|
719
|
-
if (imported?.kind !== "namespace") return null;
|
|
720
|
-
importedName = nameNode.property.name;
|
|
721
|
-
source = imported.source;
|
|
722
|
-
} else {
|
|
723
|
-
return null;
|
|
724
|
-
}
|
|
725
|
-
const fromSdkCanvas = SDK_CANVAS_SUBPATH.test(source);
|
|
726
|
-
const namesStoryboard = importedName.endsWith("Storyboard");
|
|
727
|
-
return fromSdkCanvas && namesStoryboard ? importedName : null;
|
|
728
|
-
}
|
|
729
|
-
function newerSdkStoryboardError(element, component) {
|
|
730
|
-
const openingElement = element.openingElement;
|
|
731
|
-
const storyboardKey = readStringAttribute(openingElement, "id")?.value;
|
|
732
|
-
const vrt = readVrt(openingElement, [])?.value != null;
|
|
733
|
-
const named = storyboardKey ? ` id="${storyboardKey}"` : "";
|
|
734
|
-
return {
|
|
735
|
-
message: `<${component}${named}> is a storyboard from a newer tempo-sdk than this reader supports`,
|
|
736
|
-
span: toSpan(element),
|
|
737
|
-
kind: "structural",
|
|
738
|
-
newerSdkStoryboard: {
|
|
739
|
-
component,
|
|
740
|
-
...storyboardKey ? { storyboardKey } : {},
|
|
741
|
-
vrt
|
|
742
|
-
}
|
|
743
|
-
};
|
|
744
|
-
}
|
|
745
|
-
function readVrt(openingElement, errors) {
|
|
746
|
-
const attribute = getAttribute(openingElement, "vrt");
|
|
747
|
-
if (!attribute) return null;
|
|
748
|
-
const attributeSpan = toSpan(attribute);
|
|
749
|
-
if (attribute.value == null) {
|
|
750
|
-
return { value: {}, attributeSpan };
|
|
751
|
-
}
|
|
752
|
-
const expression = unwrapTsExpression(
|
|
753
|
-
unwrapAttributeExpression(attribute.value)
|
|
754
|
-
);
|
|
755
|
-
if (expression?.type === "Literal" && expression.value === true) {
|
|
756
|
-
return { value: {}, attributeSpan };
|
|
757
|
-
}
|
|
758
|
-
if (expression?.type === "Literal" && expression.value === false) {
|
|
759
|
-
return { value: null, attributeSpan };
|
|
760
|
-
}
|
|
761
|
-
if (expression?.type !== "ObjectExpression") {
|
|
762
|
-
errors.push({
|
|
763
|
-
message: "<Storyboard> vrt must be a boolean literal or an object literal ({ threshold?, skip?, ignore? })",
|
|
764
|
-
span: toSpan(expression) ?? attributeSpan,
|
|
765
|
-
kind: "degraded"
|
|
766
|
-
});
|
|
767
|
-
return { value: null, attributeSpan };
|
|
768
|
-
}
|
|
769
|
-
const value = {};
|
|
770
|
-
for (const property of expression.properties ?? []) {
|
|
771
|
-
if (property?.type !== "Property" || property.computed) {
|
|
772
|
-
errors.push({
|
|
773
|
-
message: "<Storyboard> vrt must contain only literal properties",
|
|
774
|
-
span: toSpan(property ?? expression),
|
|
775
|
-
kind: "degraded"
|
|
776
|
-
});
|
|
777
|
-
continue;
|
|
778
|
-
}
|
|
779
|
-
const key = readPropertyKeyName(property.key);
|
|
780
|
-
if (key === "threshold") {
|
|
781
|
-
const threshold = readNumberLiteral(property.value);
|
|
782
|
-
if (threshold && threshold.value >= 0 && threshold.value <= 0.5) {
|
|
783
|
-
value.threshold = threshold.value;
|
|
784
|
-
} else {
|
|
785
|
-
errors.push({
|
|
786
|
-
message: "<Storyboard> vrt.threshold must be a number literal between 0 and 0.5",
|
|
787
|
-
span: toSpan(property),
|
|
788
|
-
kind: "degraded"
|
|
789
|
-
});
|
|
790
|
-
}
|
|
791
|
-
continue;
|
|
792
|
-
}
|
|
793
|
-
if (key === "skip") {
|
|
794
|
-
if (property.value?.type === "Literal" && typeof property.value.value === "boolean") {
|
|
795
|
-
if (property.value.value) value.skip = true;
|
|
796
|
-
} else {
|
|
797
|
-
errors.push({
|
|
798
|
-
message: "<Storyboard> vrt.skip must be a boolean literal",
|
|
799
|
-
span: toSpan(property),
|
|
800
|
-
kind: "degraded"
|
|
801
|
-
});
|
|
802
|
-
}
|
|
803
|
-
continue;
|
|
804
|
-
}
|
|
805
|
-
if (key === "ignore") {
|
|
806
|
-
const regions = readVrtIgnoreRegions(property.value, errors);
|
|
807
|
-
if (regions) value.ignore = regions;
|
|
808
|
-
continue;
|
|
809
|
-
}
|
|
810
|
-
errors.push({
|
|
811
|
-
message: `<Storyboard> vrt has unknown property "${key ?? "?"}" \u2014 expected threshold, skip, or ignore`,
|
|
812
|
-
span: toSpan(property),
|
|
813
|
-
kind: "degraded"
|
|
814
|
-
});
|
|
815
|
-
}
|
|
816
|
-
return { value, attributeSpan };
|
|
817
|
-
}
|
|
818
|
-
function readVrtIgnoreRegions(node, errors) {
|
|
819
|
-
if (node?.type !== "ArrayExpression") {
|
|
820
|
-
errors.push({
|
|
821
|
-
message: "<Storyboard> vrt.ignore must be an array of { x, y, w, h } literals",
|
|
822
|
-
span: toSpan(node),
|
|
823
|
-
kind: "degraded"
|
|
824
|
-
});
|
|
825
|
-
return null;
|
|
826
|
-
}
|
|
827
|
-
const regions = [];
|
|
828
|
-
for (const element of node.elements ?? []) {
|
|
829
|
-
const region = {};
|
|
830
|
-
for (const key of ["x", "y", "w", "h"]) {
|
|
831
|
-
const property = getObjectProperty(element, key);
|
|
832
|
-
const number = property ? readNumberLiteral(property.value) : null;
|
|
833
|
-
if (number) region[key] = number.value;
|
|
834
|
-
}
|
|
835
|
-
if (region.x === void 0 || region.y === void 0 || region.w === void 0 || region.h === void 0) {
|
|
836
|
-
errors.push({
|
|
837
|
-
message: "<Storyboard> vrt.ignore regions must be { x, y, w, h } number literals",
|
|
838
|
-
span: toSpan(element) ?? toSpan(node),
|
|
839
|
-
kind: "degraded"
|
|
840
|
-
});
|
|
841
|
-
return null;
|
|
842
|
-
}
|
|
843
|
-
regions.push(region);
|
|
844
|
-
}
|
|
845
|
-
return regions;
|
|
846
|
-
}
|
|
847
|
-
function readComponentReference(openingElement, imports, source) {
|
|
848
|
-
const attribute = getAttribute(openingElement, "component");
|
|
849
|
-
const expression = unwrapAttributeExpression(attribute?.value);
|
|
850
|
-
const span = toSpan(expression);
|
|
851
|
-
if (!expression || !span) return null;
|
|
852
|
-
const localName = expression.type === "Identifier" ? expression.name : expression.type === "MemberExpression" && expression.object?.type === "Identifier" ? expression.object.name : void 0;
|
|
853
|
-
return {
|
|
854
|
-
expression: source.slice(span.start, span.end),
|
|
855
|
-
span,
|
|
856
|
-
attributeSpan: toSpan(attribute),
|
|
857
|
-
localName,
|
|
858
|
-
import: localName ? imports.byLocalName.get(localName) : void 0
|
|
859
|
-
};
|
|
860
|
-
}
|
|
861
|
-
function readRenderComponentReference(renderValue, imports, source) {
|
|
862
|
-
if (renderValue?.type !== "ArrowFunctionExpression") return null;
|
|
863
|
-
const body = unwrapTsExpression(renderValue.body);
|
|
864
|
-
if (body?.type !== "JSXElement") return null;
|
|
865
|
-
const name = body.openingElement?.name;
|
|
866
|
-
if (name?.type !== "JSXIdentifier") return null;
|
|
867
|
-
const span = toSpan(name);
|
|
868
|
-
if (!span || typeof name.name !== "string") return null;
|
|
869
|
-
return {
|
|
870
|
-
expression: source.slice(span.start, span.end),
|
|
871
|
-
span,
|
|
872
|
-
localName: name.name,
|
|
873
|
-
import: imports.byLocalName.get(name.name)
|
|
874
|
-
};
|
|
875
|
-
}
|
|
876
|
-
function readExpressionReference(openingElement, name, source) {
|
|
877
|
-
const attribute = getAttribute(openingElement, name);
|
|
878
|
-
const expression = unwrapAttributeExpression(attribute?.value);
|
|
879
|
-
const span = toSpan(expression);
|
|
880
|
-
if (!expression || !span) return void 0;
|
|
881
|
-
return {
|
|
882
|
-
expression: source.slice(span.start, span.end),
|
|
883
|
-
span,
|
|
884
|
-
attributeSpan: toSpan(attribute)
|
|
885
|
-
};
|
|
886
|
-
}
|
|
887
|
-
function isIdentifierExpression(expression) {
|
|
888
|
-
return /^[A-Za-z_$][\w$]*$/.test(expression);
|
|
889
|
-
}
|
|
890
|
-
function readLayout(openingElement, componentName) {
|
|
891
|
-
const isViewport = requiresFixedLayoutSize(componentName);
|
|
892
|
-
const attribute = getAttribute(openingElement, "layout");
|
|
893
|
-
const expression = unwrapAttributeExpression(attribute?.value);
|
|
894
|
-
if (!expression) {
|
|
895
|
-
return {
|
|
896
|
-
value: isViewport ? DEFAULT_VIEWPORT_LAYOUT : DEFAULT_LAYOUT,
|
|
897
|
-
attributeSpan: toSpan(attribute),
|
|
898
|
-
errors: [
|
|
899
|
-
{
|
|
900
|
-
message: `<${componentName}> must include a literal "layout" object prop`,
|
|
901
|
-
span: toSpan(openingElement),
|
|
902
|
-
kind: "degraded"
|
|
903
|
-
}
|
|
904
|
-
]
|
|
905
|
-
};
|
|
906
|
-
}
|
|
907
|
-
const layout = readLayoutExpression(expression, componentName);
|
|
908
|
-
return {
|
|
909
|
-
...layout,
|
|
910
|
-
attributeSpan: toSpan(attribute)
|
|
911
|
-
};
|
|
912
|
-
}
|
|
913
|
-
function readLayoutExpression(expression, componentName) {
|
|
914
|
-
const errors = [];
|
|
915
|
-
const isViewport = requiresFixedLayoutSize(componentName);
|
|
916
|
-
if (expression.type !== "ObjectExpression") {
|
|
917
|
-
return {
|
|
918
|
-
value: isViewport ? DEFAULT_VIEWPORT_LAYOUT : DEFAULT_LAYOUT,
|
|
919
|
-
spans: { layoutClose: readLayoutClose(expression) },
|
|
920
|
-
errors: [
|
|
921
|
-
{
|
|
922
|
-
message: `<${componentName}> layout must be an object literal`,
|
|
923
|
-
span: toSpan(expression),
|
|
924
|
-
kind: "degraded"
|
|
925
|
-
}
|
|
926
|
-
]
|
|
927
|
-
};
|
|
928
|
-
}
|
|
929
|
-
const spans = {
|
|
930
|
-
layoutClose: readLayoutClose(expression)
|
|
931
|
-
};
|
|
932
|
-
const layout = { ...DEFAULT_LAYOUT };
|
|
933
|
-
const width = getObjectProperty(expression, "width");
|
|
934
|
-
const height = getObjectProperty(expression, "height");
|
|
935
|
-
const legacySizing = getObjectProperty(expression, "intrinsicSizing");
|
|
936
|
-
const legacyResponsiveFlag = legacySizing?.value?.value === "root-element";
|
|
937
|
-
const hasBothSizes = Boolean(width && height);
|
|
938
|
-
const readSize = isViewport || hasBothSizes && !legacyResponsiveFlag;
|
|
939
|
-
const incompleteSize = !isViewport && Boolean(width) !== Boolean(height);
|
|
940
|
-
if (incompleteSize) {
|
|
941
|
-
errors.push({
|
|
942
|
-
message: "layout.width and layout.height must be set together",
|
|
943
|
-
span: toSpan(expression),
|
|
944
|
-
kind: "degraded"
|
|
945
|
-
});
|
|
946
|
-
}
|
|
947
|
-
const size = readSize ? {
|
|
948
|
-
width: width ? readNumberLiteral(width.value) : null,
|
|
949
|
-
height: height ? readNumberLiteral(height.value) : null
|
|
950
|
-
} : null;
|
|
951
|
-
const keys = readSize ? ["x", "y", "width", "height"] : ["x", "y"];
|
|
952
|
-
for (const key of keys) {
|
|
953
|
-
const property = key === "width" ? width : key === "height" ? height : getObjectProperty(expression, key);
|
|
954
|
-
const value = key === "width" || key === "height" ? size?.[key] : property ? readNumberLiteral(property.value) : null;
|
|
955
|
-
const keepValue = key === "x" || key === "y" || isViewport || Boolean(size?.width && size.height);
|
|
956
|
-
if (!value) {
|
|
957
|
-
errors.push({
|
|
958
|
-
message: `<${componentName}> layout.${key} must be a number literal`,
|
|
959
|
-
span: toSpan(property ?? expression),
|
|
960
|
-
kind: "degraded"
|
|
961
|
-
});
|
|
962
|
-
continue;
|
|
963
|
-
}
|
|
964
|
-
if (!keepValue) continue;
|
|
965
|
-
layout[key] = value.value;
|
|
966
|
-
spans[key] = value.span;
|
|
967
|
-
}
|
|
968
|
-
const zIndex = getObjectProperty(expression, "zIndex");
|
|
969
|
-
if (zIndex) {
|
|
970
|
-
const value = readNumberLiteral(zIndex.value);
|
|
971
|
-
if (value) {
|
|
972
|
-
layout.zIndex = value.value;
|
|
973
|
-
spans.zIndex = value.span;
|
|
974
|
-
} else {
|
|
975
|
-
errors.push({
|
|
976
|
-
message: `<${componentName}> layout.zIndex must be a number literal`,
|
|
977
|
-
span: toSpan(zIndex),
|
|
978
|
-
kind: "degraded"
|
|
979
|
-
});
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
const invalidLegacyFlag = legacySizing && (legacySizing.value?.type !== "Literal" || !legacyResponsiveFlag);
|
|
983
|
-
if (invalidLegacyFlag) {
|
|
984
|
-
errors.push({
|
|
985
|
-
message: `<${componentName}> layout.intrinsicSizing must be "root-element" when set`,
|
|
986
|
-
span: toSpan(legacySizing),
|
|
987
|
-
kind: "degraded"
|
|
988
|
-
});
|
|
989
|
-
}
|
|
990
|
-
return { value: layout, spans, errors };
|
|
991
|
-
}
|
|
992
|
-
function readStringLiteralValue(node) {
|
|
993
|
-
return node?.type === "Literal" && typeof node.value === "string" ? { value: node.value, span: toSpan(node) ?? { start: 0, end: 0 } } : null;
|
|
994
|
-
}
|
|
995
|
-
function unwrapTsExpression(node) {
|
|
996
|
-
let current = node;
|
|
997
|
-
while (current?.type === "TSSatisfiesExpression" || current?.type === "TSAsExpression" || current?.type === "TSNonNullExpression" || current?.type === "ParenthesizedExpression") {
|
|
998
|
-
current = current.expression;
|
|
999
|
-
}
|
|
1000
|
-
return current;
|
|
1001
|
-
}
|
|
1002
|
-
function readResolvableStringAttribute(openingElement, name, bindings) {
|
|
1003
|
-
const literal = readStringAttribute(openingElement, name);
|
|
1004
|
-
if (literal) return literal;
|
|
1005
|
-
const attribute = getAttribute(openingElement, name);
|
|
1006
|
-
const expression = unwrapAttributeExpression(attribute?.value);
|
|
1007
|
-
const expressionSpan = toSpan(expression);
|
|
1008
|
-
const attributeSpan = toSpan(attribute);
|
|
1009
|
-
if (!expression || !expressionSpan || !attributeSpan) return null;
|
|
1010
|
-
const resolved = resolveStringMemberExpression(expression, bindings);
|
|
1011
|
-
return resolved ? {
|
|
1012
|
-
value: resolved.value,
|
|
1013
|
-
valueSpan: expressionSpan,
|
|
1014
|
-
attributeSpan
|
|
1015
|
-
} : null;
|
|
1016
|
-
}
|
|
1017
|
-
function resolveStringMemberExpression(expression, bindings) {
|
|
1018
|
-
if (expression?.type !== "MemberExpression") return null;
|
|
1019
|
-
if (expression.object?.type !== "Identifier") return null;
|
|
1020
|
-
const propertyName = readPropertyKeyName(expression.property);
|
|
1021
|
-
if (!propertyName) return null;
|
|
1022
|
-
return bindings.get(expression.object.name)?.get(propertyName) ?? null;
|
|
1023
|
-
}
|
|
1024
|
-
function readStringAttribute(openingElement, name) {
|
|
1025
|
-
const attribute = getAttribute(openingElement, name);
|
|
1026
|
-
if (!attribute) return null;
|
|
1027
|
-
const value = attribute.value;
|
|
1028
|
-
if (value?.type === "Literal" && typeof value.value === "string") {
|
|
1029
|
-
return {
|
|
1030
|
-
value: value.value,
|
|
1031
|
-
valueSpan: toSpan(value) ?? toSpan(attribute) ?? { start: 0, end: 0 },
|
|
1032
|
-
attributeSpan: toSpan(attribute) ?? { start: 0, end: 0 }
|
|
1033
|
-
};
|
|
1034
|
-
}
|
|
1035
|
-
const expression = unwrapTsExpression(unwrapAttributeExpression(value));
|
|
1036
|
-
const fixed = expression?.type === "Literal" && typeof expression.value === "string" ? expression.value : expression?.type === "TemplateLiteral" && (expression.expressions?.length ?? 0) === 0 && expression.quasis?.length === 1 && typeof expression.quasis[0]?.value?.cooked === "string" ? expression.quasis[0].value.cooked : null;
|
|
1037
|
-
if (fixed !== null) {
|
|
1038
|
-
return {
|
|
1039
|
-
value: fixed,
|
|
1040
|
-
valueSpan: toSpan(expression) ?? toSpan(attribute) ?? { start: 0, end: 0 },
|
|
1041
|
-
attributeSpan: toSpan(attribute) ?? { start: 0, end: 0 }
|
|
1042
|
-
};
|
|
1043
|
-
}
|
|
1044
|
-
return null;
|
|
1045
|
-
}
|
|
1046
|
-
function getAttribute(openingElement, name) {
|
|
1047
|
-
for (const attribute of openingElement?.attributes ?? []) {
|
|
1048
|
-
if (attribute?.type === "JSXAttribute" && attribute.name?.type === "JSXIdentifier" && attribute.name.name === name) {
|
|
1049
|
-
return attribute;
|
|
1050
|
-
}
|
|
1051
|
-
}
|
|
1052
|
-
return null;
|
|
1053
|
-
}
|
|
1054
|
-
function unwrapAttributeExpression(value) {
|
|
1055
|
-
if (!value) return null;
|
|
1056
|
-
if (value.type === "JSXExpressionContainer") {
|
|
1057
|
-
return value.expression;
|
|
1058
|
-
}
|
|
1059
|
-
return value;
|
|
1060
|
-
}
|
|
1061
|
-
function readPropertyKeyName(key) {
|
|
1062
|
-
if (key?.type === "Identifier") return key.name;
|
|
1063
|
-
if (key?.type === "Literal" && typeof key.value === "string") {
|
|
1064
|
-
return key.value;
|
|
1065
|
-
}
|
|
1066
|
-
return null;
|
|
1067
|
-
}
|
|
1068
|
-
function getObjectProperty(objectExpression, name) {
|
|
1069
|
-
if (objectExpression?.type !== "ObjectExpression") return null;
|
|
1070
|
-
for (const property of objectExpression.properties ?? []) {
|
|
1071
|
-
if (property?.type !== "Property" || property.computed) continue;
|
|
1072
|
-
const propertyName = readPropertyKeyName(property.key);
|
|
1073
|
-
if (propertyName === name) return property;
|
|
1074
|
-
}
|
|
1075
|
-
return null;
|
|
1076
|
-
}
|
|
1077
|
-
function readNumberLiteral(node) {
|
|
1078
|
-
if (node?.type === "Literal" && typeof node.value === "number" && Number.isFinite(node.value)) {
|
|
1079
|
-
return { value: node.value, span: toSpan(node) ?? { start: 0, end: 0 } };
|
|
1080
|
-
}
|
|
1081
|
-
if (node?.type === "UnaryExpression" && node.operator === "-" && node.argument?.type === "Literal" && typeof node.argument.value === "number" && Number.isFinite(node.argument.value)) {
|
|
1082
|
-
return {
|
|
1083
|
-
value: -node.argument.value,
|
|
1084
|
-
span: toSpan(node) ?? { start: 0, end: 0 }
|
|
1085
|
-
};
|
|
1086
|
-
}
|
|
1087
|
-
return null;
|
|
1088
|
-
}
|
|
1089
|
-
function resolveSdkComponent(nameNode, imports) {
|
|
1090
|
-
if (nameNode?.type === "JSXIdentifier") {
|
|
1091
|
-
return imports.sdkLocalNames.get(nameNode.name) ?? null;
|
|
1092
|
-
}
|
|
1093
|
-
if (nameNode?.type === "JSXMemberExpression" && nameNode.object?.type === "JSXIdentifier" && nameNode.property?.type === "JSXIdentifier" && imports.sdkNamespaces.has(nameNode.object.name) && SDK_COMPONENTS.has(nameNode.property.name)) {
|
|
1094
|
-
return nameNode.property.name;
|
|
1095
|
-
}
|
|
1096
|
-
return null;
|
|
1097
|
-
}
|
|
1098
|
-
function resolveMisimportedNamespaceSdkComponent(nameNode, imports, misimportedSdkCanvasImports) {
|
|
1099
|
-
if (nameNode?.type !== "JSXMemberExpression" || nameNode.object?.type !== "JSXIdentifier" || nameNode.property?.type !== "JSXIdentifier" || !SDK_COMPONENTS.has(nameNode.property.name)) {
|
|
1100
|
-
return null;
|
|
1101
|
-
}
|
|
1102
|
-
const imported = imports.byLocalName.get(nameNode.object.name);
|
|
1103
|
-
if (imported?.kind !== "namespace" || !isWrongTempoSdkCanvasImportSource(imported.source)) {
|
|
1104
|
-
return null;
|
|
1105
|
-
}
|
|
1106
|
-
return misimportedSdkCanvasImports.namespaceCandidatesByLocalName.get(
|
|
1107
|
-
nameNode.object.name
|
|
1108
|
-
) ?? null;
|
|
1109
|
-
}
|
|
1110
|
-
function isStoryboardSdkComponent(component) {
|
|
1111
|
-
return component !== null && component !== "Canvas";
|
|
1112
|
-
}
|
|
1113
|
-
function formatAlternatives(items) {
|
|
1114
|
-
if (items.length <= 1) return items.join("");
|
|
1115
|
-
return `${items.slice(0, -1).join(", ")}, or ${items[items.length - 1]}`;
|
|
1116
|
-
}
|
|
1117
|
-
function requiresFixedLayoutSize(componentName) {
|
|
1118
|
-
return componentName === "RouteStoryboard" || componentName === "HtmlStoryboard" || componentName === "FlutterStoryboard";
|
|
1119
|
-
}
|
|
1120
|
-
function readImportedName(specifier) {
|
|
1121
|
-
if (specifier.type === "ImportDefaultSpecifier") return "default";
|
|
1122
|
-
if (specifier.type === "ImportNamespaceSpecifier") return "*";
|
|
1123
|
-
return specifier.imported?.name ?? specifier.local?.name ?? "unknown";
|
|
1124
|
-
}
|
|
1125
|
-
function readImportKind(specifier) {
|
|
1126
|
-
if (specifier.type === "ImportDefaultSpecifier") return "default";
|
|
1127
|
-
if (specifier.type === "ImportNamespaceSpecifier") return "namespace";
|
|
1128
|
-
return "named";
|
|
1129
|
-
}
|
|
1130
|
-
function isSdkImportSource(source) {
|
|
1131
|
-
for (const sdkSource of SDK_IMPORT_SOURCES) {
|
|
1132
|
-
if (source === sdkSource || source.endsWith(`/${sdkSource}`)) return true;
|
|
1133
|
-
}
|
|
1134
|
-
return false;
|
|
1135
|
-
}
|
|
1136
|
-
function isWrongTempoSdkCanvasImportSource(source) {
|
|
1137
|
-
return (source === "tempo-sdk" || source.startsWith("tempo-sdk/")) && !isSdkImportSource(source);
|
|
1138
|
-
}
|
|
1139
|
-
function spanKey(span) {
|
|
1140
|
-
return `${span.start}:${span.end}`;
|
|
1141
|
-
}
|
|
1142
|
-
function readLayoutClose(node) {
|
|
1143
|
-
return typeof node?.end === "number" && Number.isFinite(node.end) ? node.end - 1 : void 0;
|
|
1144
|
-
}
|
|
1145
|
-
function fallbackPageName(filePath) {
|
|
1146
|
-
const normalized = filePath.replace(/\\/g, "/");
|
|
1147
|
-
const segments = normalized.split("/").filter(Boolean);
|
|
1148
|
-
const fileName = segments.length > 0 ? segments[segments.length - 1] : filePath;
|
|
1149
|
-
const parentName = segments.length > 1 ? segments[segments.length - 2] : fileName;
|
|
1150
|
-
const baseName = /^index\.canvas\.[tj]sx?$/.test(fileName) ? parentName : fileName.replace(/\.canvas\.[tj]sx?$/, "");
|
|
1151
|
-
return baseName.split(/[-_\s]+/).filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
|
|
1152
|
-
}
|
|
1153
|
-
function toSpan(node) {
|
|
1154
|
-
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;
|
|
1155
|
-
}
|
|
1156
|
-
function walk(node, visitor, seen = /* @__PURE__ */ new Set()) {
|
|
1157
|
-
if (!node || typeof node !== "object" || seen.has(node)) return;
|
|
1158
|
-
seen.add(node);
|
|
1159
|
-
visitor(node);
|
|
1160
|
-
for (const value of Object.values(node)) {
|
|
1161
|
-
if (!value) continue;
|
|
1162
|
-
if (Array.isArray(value)) {
|
|
1163
|
-
for (const item of value) {
|
|
1164
|
-
walk(item, visitor, seen);
|
|
1165
|
-
}
|
|
1166
|
-
} else if (typeof value === "object") {
|
|
1167
|
-
walk(value, visitor, seen);
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
}
|
|
1171
|
-
function parseComponentRoot(filePath, source, exportName) {
|
|
1172
|
-
const result = parseSync(filePath, source);
|
|
1173
|
-
if (result.errors.length > 0) {
|
|
1174
|
-
throw new Error(result.errors.map((error) => error.message).join("; "));
|
|
1175
|
-
}
|
|
1176
|
-
const declarations = /* @__PURE__ */ new Map();
|
|
1177
|
-
let component;
|
|
1178
|
-
let localName = exportName;
|
|
1179
|
-
let exported = false;
|
|
1180
|
-
for (const statement of result.program.body) {
|
|
1181
|
-
const declaration = statement.declaration ?? statement;
|
|
1182
|
-
if (declaration.type === "FunctionDeclaration" && declaration.id) {
|
|
1183
|
-
declarations.set(declaration.id.name, declaration);
|
|
1184
|
-
}
|
|
1185
|
-
if (declaration.type === "VariableDeclaration") {
|
|
1186
|
-
for (const entry of declaration.declarations) {
|
|
1187
|
-
if (entry.id.type === "Identifier") {
|
|
1188
|
-
declarations.set(entry.id.name, unwrapTsExpression(entry.init));
|
|
1189
|
-
}
|
|
1190
|
-
}
|
|
1191
|
-
}
|
|
1192
|
-
if (statement.type === "ExportDefaultDeclaration" && exportName === "default") {
|
|
1193
|
-
exported = true;
|
|
1194
|
-
if (declaration.type === "Identifier") localName = declaration.name;
|
|
1195
|
-
else component = declaration;
|
|
1196
|
-
}
|
|
1197
|
-
if (statement.type !== "ExportNamedDeclaration") continue;
|
|
1198
|
-
for (const specifier of statement.specifiers ?? []) {
|
|
1199
|
-
if (!statement.source && (specifier.exported.name ?? specifier.exported.value) === exportName) {
|
|
1200
|
-
exported = true;
|
|
1201
|
-
localName = specifier.local.name;
|
|
1202
|
-
}
|
|
1203
|
-
}
|
|
1204
|
-
if (declaration.id?.name === exportName) {
|
|
1205
|
-
exported = true;
|
|
1206
|
-
component = declaration;
|
|
1207
|
-
}
|
|
1208
|
-
if (declaration.type === "VariableDeclaration" && declaration.declarations.some(
|
|
1209
|
-
(entry) => entry.id.name === exportName
|
|
1210
|
-
)) {
|
|
1211
|
-
exported = true;
|
|
1212
|
-
}
|
|
1213
|
-
}
|
|
1214
|
-
if (!exported) return null;
|
|
1215
|
-
component = unwrapTsExpression(component ?? declarations.get(localName));
|
|
1216
|
-
const isFunction = component?.type === "FunctionDeclaration" || component?.type === "FunctionExpression" || component?.type === "ArrowFunctionExpression";
|
|
1217
|
-
if (!isFunction) return null;
|
|
1218
|
-
const name = component.id?.name ?? localName;
|
|
1219
|
-
let root = unwrapTsExpression(component.body);
|
|
1220
|
-
if (root?.type === "BlockStatement") {
|
|
1221
|
-
const returns = root.body.filter(
|
|
1222
|
-
(statement) => statement.type === "ReturnStatement"
|
|
1223
|
-
);
|
|
1224
|
-
const hasControlFlow = root.body.some(
|
|
1225
|
-
(statement) => ![
|
|
1226
|
-
"ReturnStatement",
|
|
1227
|
-
"VariableDeclaration",
|
|
1228
|
-
"ExpressionStatement",
|
|
1229
|
-
"FunctionDeclaration",
|
|
1230
|
-
"EmptyStatement"
|
|
1231
|
-
].includes(statement.type)
|
|
1232
|
-
);
|
|
1233
|
-
if (returns.length !== 1 || hasControlFlow) return null;
|
|
1234
|
-
root = unwrapTsExpression(returns[0].argument);
|
|
1235
|
-
}
|
|
1236
|
-
return root?.type === "JSXElement" ? { name, root } : null;
|
|
1237
|
-
}
|
|
1238
|
-
|
|
1239
|
-
export {
|
|
1240
|
-
STORYBOARD_SDK_COMPONENTS,
|
|
1241
|
-
storyboardComponentForFramework,
|
|
1242
|
-
componentFileExtensionForFramework,
|
|
1243
|
-
componentImportSpecifier,
|
|
1244
|
-
componentImportPath,
|
|
1245
|
-
componentFrameworkForStoryboard,
|
|
1246
|
-
NO_CANVAS_DECLARATION_ERROR,
|
|
1247
|
-
parseCanvasFile,
|
|
1248
|
-
misimportedSdkCanvasImportMessage,
|
|
1249
|
-
unwrapTsExpression,
|
|
1250
|
-
fallbackPageName,
|
|
1251
|
-
parseComponentRoot
|
|
1252
|
-
};
|
|
1253
|
-
//# sourceMappingURL=chunk-AFXE462X.js.map
|