@vizhub/runtime 4.1.0 → 4.3.0
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 +20 -3
- package/dist/build/build.d.ts.map +1 -1
- package/dist/build-BT6ouBQg.js +1216 -0
- package/dist/build-BT6ouBQg.js.map +1 -0
- package/dist/build-Dh4OViu-.cjs +317 -0
- package/dist/build-Dh4OViu-.cjs.map +1 -0
- package/dist/common/runtimeErrorHandling.d.ts +9 -0
- package/dist/common/runtimeErrorHandling.d.ts.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +111 -106
- package/dist/index.js.map +1 -1
- package/dist/orchestration/createRuntime.d.ts +2 -1
- package/dist/orchestration/createRuntime.d.ts.map +1 -1
- package/dist/orchestration/types.d.ts +4 -0
- package/dist/orchestration/types.d.ts.map +1 -1
- package/dist/orchestration/worker.d.ts.map +1 -1
- package/dist/test/extractEntryPoints.test.d.ts +2 -0
- package/dist/test/extractEntryPoints.test.d.ts.map +1 -0
- package/dist/test/extractEntryPointsEdgeCases.test.d.ts +2 -0
- package/dist/test/extractEntryPointsEdgeCases.test.d.ts.map +1 -0
- package/dist/test/fixtures/v3/basicIndexJSWithViz.d.ts +4 -0
- package/dist/test/fixtures/v3/basicIndexJSWithViz.d.ts.map +1 -0
- package/dist/test/fixtures/v3/index.d.ts +1 -0
- package/dist/test/fixtures/v3/index.d.ts.map +1 -1
- package/dist/test/fixtures/v3/svelte.d.ts.map +1 -1
- package/dist/test/fixtures/v4/index.d.ts +1 -0
- package/dist/test/fixtures/v4/index.d.ts.map +1 -1
- package/dist/test/fixtures/v4/jsInlineScriptModule.d.ts +5 -0
- package/dist/test/fixtures/v4/jsInlineScriptModule.d.ts.map +1 -0
- package/dist/test/runtimeErrorHandling.test.d.ts +2 -0
- package/dist/test/runtimeErrorHandling.test.d.ts.map +1 -0
- package/dist/test/runtimeErrorHandlingAllVersions.test.d.ts +2 -0
- package/dist/test/runtimeErrorHandlingAllVersions.test.d.ts.map +1 -0
- package/dist/test/runtimeErrorHandlingIntegration.test.d.ts +2 -0
- package/dist/test/runtimeErrorHandlingIntegration.test.d.ts.map +1 -0
- package/dist/test/updateHTML.test.d.ts +2 -0
- package/dist/test/updateHTML.test.d.ts.map +1 -0
- package/dist/test/v3BuildIntegrationViz.test.d.ts +2 -0
- package/dist/test/v3BuildIntegrationViz.test.d.ts.map +1 -0
- package/dist/test/v4Build.test.d.ts +2 -0
- package/dist/test/v4Build.test.d.ts.map +1 -0
- package/dist/test/v4BuildIntegration.test.d.ts +2 -0
- package/dist/test/v4BuildIntegration.test.d.ts.map +1 -0
- package/dist/test/v4HotReload.test.d.ts +2 -0
- package/dist/test/v4HotReload.test.d.ts.map +1 -0
- package/dist/test/v4HotReloadIntegration.test.d.ts +2 -0
- package/dist/test/v4HotReloadIntegration.test.d.ts.map +1 -0
- package/dist/test/vizExportSupport.test.d.ts +2 -0
- package/dist/test/vizExportSupport.test.d.ts.map +1 -0
- package/dist/test/vizPriorityTest.test.d.ts +2 -0
- package/dist/test/vizPriorityTest.test.d.ts.map +1 -0
- package/dist/v2/getComputedIndexHtml.d.ts.map +1 -1
- package/dist/v3/computeBundleJSV3.d.ts.map +1 -1
- package/dist/v3/htmlTemplate.d.ts.map +1 -1
- package/dist/v3/svelte5-integration.test.d.ts +2 -0
- package/dist/v3/svelte5-integration.test.d.ts.map +1 -0
- package/dist/v3/transformSvelte.d.ts +9 -2
- package/dist/v3/transformSvelte.d.ts.map +1 -1
- package/dist/v3/transformSvelte.test.d.ts +2 -0
- package/dist/v3/transformSvelte.test.d.ts.map +1 -0
- package/dist/v4/extractEntryPoints.d.ts +7 -1
- package/dist/v4/extractEntryPoints.d.ts.map +1 -1
- package/dist/v4/hotReloadScript.d.ts +6 -0
- package/dist/v4/hotReloadScript.d.ts.map +1 -0
- package/dist/v4/index.d.ts +12 -0
- package/dist/v4/index.d.ts.map +1 -1
- package/dist/v4/updateHTML.d.ts +4 -1
- package/dist/v4/updateHTML.d.ts.map +1 -1
- package/dist/worker.cjs +1 -1
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.js +1 -1
- package/dist/worker.js.map +1 -1
- package/package.json +23 -15
- package/dist/build-D8ObHgQc.js +0 -984
- package/dist/build-D8ObHgQc.js.map +0 -1
- package/dist/build-t6B4kQWS.cjs +0 -214
- package/dist/build-t6B4kQWS.cjs.map +0 -1
@@ -0,0 +1,1216 @@
|
|
1
|
+
import { magicSandbox as C } from "magic-sandbox";
|
2
|
+
import { isVizId as G, getFileText as B, generateVizId as Y, fileCollectionToVizFiles as Q, vizFilesToFileCollection as X } from "@vizhub/viz-utils";
|
3
|
+
import { transform as Z } from "sucrase";
|
4
|
+
const We = () => (Math.random() + "").slice(2);
|
5
|
+
function V(e = {}) {
|
6
|
+
return {
|
7
|
+
name: "sucrase",
|
8
|
+
transform(t, n) {
|
9
|
+
if (!n.match(/\.(?:js|[jt]sx)$/))
|
10
|
+
return null;
|
11
|
+
const s = Z(t, {
|
12
|
+
transforms: ["jsx", "typescript"],
|
13
|
+
// For source maps
|
14
|
+
filePath: n,
|
15
|
+
sourceMapOptions: {
|
16
|
+
compiledFilename: "bundle.js"
|
17
|
+
},
|
18
|
+
production: !0,
|
19
|
+
...e
|
20
|
+
});
|
21
|
+
return {
|
22
|
+
code: s.code,
|
23
|
+
map: s.sourceMap
|
24
|
+
};
|
25
|
+
}
|
26
|
+
};
|
27
|
+
}
|
28
|
+
const P = {
|
29
|
+
dependencies: {},
|
30
|
+
vizhub: {},
|
31
|
+
license: "MIT"
|
32
|
+
}, K = !1, $ = (e) => {
|
33
|
+
const t = e["package.json"];
|
34
|
+
try {
|
35
|
+
const n = t ? JSON.parse(t) : P;
|
36
|
+
return K && console.log(
|
37
|
+
"[packageJSON] pkg:",
|
38
|
+
JSON.stringify(n, null, 2)
|
39
|
+
), n;
|
40
|
+
} catch {
|
41
|
+
return P;
|
42
|
+
}
|
43
|
+
}, L = (e) => $(e).dependencies || {}, z = (e) => ($(e).vizhub || {}).libraries || {}, F = ({ name: e, version: t }, n, s = "jsdelivr") => {
|
44
|
+
const r = n[e] && n[e].path || "";
|
45
|
+
return s === "jsdelivr" ? `https://cdn.jsdelivr.net/npm/${e}@${t}${r}` : `https://unpkg.com/${e}@${t}${r}`;
|
46
|
+
}, ee = (e) => {
|
47
|
+
const t = e?.vizhub?.libraries;
|
48
|
+
return t ? Object.entries(t).reduce(
|
49
|
+
(n, [s, r]) => (r.global && (n[s] = r.global), n),
|
50
|
+
{}
|
51
|
+
) : {};
|
52
|
+
}, te = {
|
53
|
+
d3: "d3",
|
54
|
+
react: "React",
|
55
|
+
"react-dom": "ReactDOM"
|
56
|
+
}, H = (e) => {
|
57
|
+
const t = ee(e);
|
58
|
+
return {
|
59
|
+
...te,
|
60
|
+
...t
|
61
|
+
};
|
62
|
+
}, S = (e) => {
|
63
|
+
const [t, ...n] = e.split("/"), s = n.join("/");
|
64
|
+
return { vizId: t, fileName: s };
|
65
|
+
}, ne = `var EOL = {},
|
66
|
+
EOF = {},
|
67
|
+
QUOTE = 34,
|
68
|
+
NEWLINE = 10,
|
69
|
+
RETURN = 13;
|
70
|
+
|
71
|
+
function objectConverter(columns) {
|
72
|
+
return new Function(
|
73
|
+
'd',
|
74
|
+
'return {' +
|
75
|
+
columns
|
76
|
+
.map(function (name, i) {
|
77
|
+
return (
|
78
|
+
JSON.stringify(name) + ': d[' + i + '] || ""'
|
79
|
+
);
|
80
|
+
})
|
81
|
+
.join(',') +
|
82
|
+
'}',
|
83
|
+
);
|
84
|
+
}
|
85
|
+
|
86
|
+
function customConverter(columns, f) {
|
87
|
+
var object = objectConverter(columns);
|
88
|
+
return function (row, i) {
|
89
|
+
return f(object(row), i, columns);
|
90
|
+
};
|
91
|
+
}
|
92
|
+
|
93
|
+
function dsv(delimiter) {
|
94
|
+
var DELIMITER = delimiter.charCodeAt(0);
|
95
|
+
|
96
|
+
function parse(text, f) {
|
97
|
+
var convert,
|
98
|
+
columns,
|
99
|
+
rows = parseRows(text, function (row, i) {
|
100
|
+
if (convert) return convert(row, i - 1);
|
101
|
+
(columns = row),
|
102
|
+
(convert = f
|
103
|
+
? customConverter(row, f)
|
104
|
+
: objectConverter(row));
|
105
|
+
});
|
106
|
+
rows.columns = columns || [];
|
107
|
+
return rows;
|
108
|
+
}
|
109
|
+
|
110
|
+
function parseRows(text, f) {
|
111
|
+
var rows = [], // output rows
|
112
|
+
N = text.length,
|
113
|
+
I = 0, // current character index
|
114
|
+
n = 0, // current line number
|
115
|
+
t, // current token
|
116
|
+
eof = N <= 0, // current token followed by EOF?
|
117
|
+
eol = false; // current token followed by EOL?
|
118
|
+
|
119
|
+
// Strip the trailing newline.
|
120
|
+
if (text.charCodeAt(N - 1) === NEWLINE) --N;
|
121
|
+
if (text.charCodeAt(N - 1) === RETURN) --N;
|
122
|
+
|
123
|
+
function token() {
|
124
|
+
if (eof) return EOF;
|
125
|
+
if (eol) return (eol = false), EOL;
|
126
|
+
|
127
|
+
// Unescape quotes.
|
128
|
+
var i,
|
129
|
+
j = I,
|
130
|
+
c;
|
131
|
+
if (text.charCodeAt(j) === QUOTE) {
|
132
|
+
while (
|
133
|
+
(I++ < N && text.charCodeAt(I) !== QUOTE) ||
|
134
|
+
text.charCodeAt(++I) === QUOTE
|
135
|
+
);
|
136
|
+
if ((i = I) >= N) eof = true;
|
137
|
+
else if ((c = text.charCodeAt(I++)) === NEWLINE)
|
138
|
+
eol = true;
|
139
|
+
else if (c === RETURN) {
|
140
|
+
eol = true;
|
141
|
+
if (text.charCodeAt(I) === NEWLINE) ++I;
|
142
|
+
}
|
143
|
+
return text.slice(j + 1, i - 1).replace(/""/g, '"');
|
144
|
+
}
|
145
|
+
|
146
|
+
// Find next delimiter or newline.
|
147
|
+
while (I < N) {
|
148
|
+
if ((c = text.charCodeAt((i = I++))) === NEWLINE)
|
149
|
+
eol = true;
|
150
|
+
else if (c === RETURN) {
|
151
|
+
eol = true;
|
152
|
+
if (text.charCodeAt(I) === NEWLINE) ++I;
|
153
|
+
} else if (c !== DELIMITER) continue;
|
154
|
+
return text.slice(j, i);
|
155
|
+
}
|
156
|
+
|
157
|
+
// Return last token before EOF.
|
158
|
+
return (eof = true), text.slice(j, N);
|
159
|
+
}
|
160
|
+
|
161
|
+
while ((t = token()) !== EOF) {
|
162
|
+
var row = [];
|
163
|
+
while (t !== EOL && t !== EOF)
|
164
|
+
row.push(t), (t = token());
|
165
|
+
if (f && (row = f(row, n++)) == null) continue;
|
166
|
+
rows.push(row);
|
167
|
+
}
|
168
|
+
|
169
|
+
return rows;
|
170
|
+
}
|
171
|
+
|
172
|
+
return {
|
173
|
+
parse: parse,
|
174
|
+
};
|
175
|
+
}
|
176
|
+
|
177
|
+
var csv = dsv(',');
|
178
|
+
|
179
|
+
var csvParse = csv.parse;
|
180
|
+
|
181
|
+
var tsv = dsv(' ');
|
182
|
+
|
183
|
+
var tsvParse = tsv.parse;
|
184
|
+
|
185
|
+
export { csvParse, tsvParse };`, re = (e) => (
|
186
|
+
// str.replace(/`/g, '\\`');
|
187
|
+
e.replace(/\\/g, "\\\\").replace(/`/g, "\\`")
|
188
|
+
), se = () => ({
|
189
|
+
name: "transformDSV",
|
190
|
+
// `id` here is of the form
|
191
|
+
// `{vizId}/{fileName}`
|
192
|
+
transform: async (e, t) => {
|
193
|
+
const { fileName: n } = S(t), s = n.endsWith(".csv"), r = n.endsWith(".tsv");
|
194
|
+
if (s || r)
|
195
|
+
return {
|
196
|
+
code: `
|
197
|
+
${ne}
|
198
|
+
const data = ${s ? "csvParse" : "tsvParse"}(\`${re(e)}\`);
|
199
|
+
export default data;
|
200
|
+
`,
|
201
|
+
map: { mappings: "" }
|
202
|
+
};
|
203
|
+
}
|
204
|
+
}), oe = (e) => {
|
205
|
+
const t = /^@([a-zA-Z0-9_-]+)\/([a-zA-Z0-9_-]+)$/, n = e.match(t);
|
206
|
+
return n ? {
|
207
|
+
userName: n[1],
|
208
|
+
idOrSlug: n[2]
|
209
|
+
} : null;
|
210
|
+
}, ie = ({
|
211
|
+
vizId: e,
|
212
|
+
slugCache: t
|
213
|
+
}) => ({
|
214
|
+
name: "vizResolve",
|
215
|
+
resolveId: async (n, s) => {
|
216
|
+
if (n.startsWith("./") && !s?.startsWith("https://")) {
|
217
|
+
let o = n.substring(2);
|
218
|
+
if (!o.endsWith(".js") && !o.endsWith(".css") && !o.endsWith(".csv") && !o.endsWith(".svelte") && (o += ".js"), s) {
|
219
|
+
const {
|
220
|
+
vizId: c,
|
221
|
+
fileName: i
|
222
|
+
} = S(s), a = i.split("/").slice(0, -1).join("/"), u = a ? `${a}/${o}` : o;
|
223
|
+
return `${c}/${u}`;
|
224
|
+
}
|
225
|
+
return e + "/" + o;
|
226
|
+
}
|
227
|
+
const r = oe(n);
|
228
|
+
if (r) {
|
229
|
+
let o;
|
230
|
+
if (G(r.idOrSlug))
|
231
|
+
o = r.idOrSlug;
|
232
|
+
else {
|
233
|
+
if (!t)
|
234
|
+
throw new Error(
|
235
|
+
"slugCache is required to import by slug in v3 runtime"
|
236
|
+
);
|
237
|
+
o = await t.get(
|
238
|
+
`${r.userName}/${r.idOrSlug}`
|
239
|
+
);
|
240
|
+
}
|
241
|
+
return o + "/index.js";
|
242
|
+
}
|
243
|
+
}
|
244
|
+
}), ce = ({
|
245
|
+
vizCache: e,
|
246
|
+
trackCSSImport: t,
|
247
|
+
vizId: n,
|
248
|
+
files: s
|
249
|
+
}) => ({
|
250
|
+
name: "vizLoad",
|
251
|
+
// `id` here is of the form
|
252
|
+
// `{vizId}/{fileName}`
|
253
|
+
load: async (r) => {
|
254
|
+
const o = S(r), c = o.vizId, i = o.fileName;
|
255
|
+
if (i.endsWith(".css"))
|
256
|
+
return t(r), "";
|
257
|
+
let a = null;
|
258
|
+
if (c === n && s)
|
259
|
+
a = s[i] || null;
|
260
|
+
else {
|
261
|
+
const u = await e.get(c);
|
262
|
+
a = B(u, i);
|
263
|
+
}
|
264
|
+
if (a === null)
|
265
|
+
throw new Error(
|
266
|
+
`Imported file "${i}" not found.`
|
267
|
+
);
|
268
|
+
return a;
|
269
|
+
}
|
270
|
+
}), J = /* @__PURE__ */ new Map(), R = /* @__PURE__ */ new Map();
|
271
|
+
let I;
|
272
|
+
const E = "https://cdn.jsdelivr.net/npm/svelte@5.37.1", De = `${E}/compiler/index.js`;
|
273
|
+
async function W(e) {
|
274
|
+
const t = R.get(e);
|
275
|
+
if (t)
|
276
|
+
return t;
|
277
|
+
const n = [".js", "/index.js"];
|
278
|
+
for (const r of n) {
|
279
|
+
const o = `${e}${r}`;
|
280
|
+
try {
|
281
|
+
if ((await fetch(o, { method: "HEAD" })).ok)
|
282
|
+
return R.set(e, o), o;
|
283
|
+
} catch {
|
284
|
+
continue;
|
285
|
+
}
|
286
|
+
}
|
287
|
+
const s = `${e}.js`;
|
288
|
+
return R.set(e, s), s;
|
289
|
+
}
|
290
|
+
const ae = ({
|
291
|
+
getSvelteCompiler: e
|
292
|
+
}) => ({
|
293
|
+
name: "transformSvelte",
|
294
|
+
load: async (t) => {
|
295
|
+
if (t === "virtual:esm-env")
|
296
|
+
return `
|
297
|
+
export const BROWSER = true;
|
298
|
+
export const DEV = true;
|
299
|
+
export const NODE = false;
|
300
|
+
export const PROD = false;
|
301
|
+
`;
|
302
|
+
if (!t.startsWith(E))
|
303
|
+
return;
|
304
|
+
const n = J.get(t);
|
305
|
+
if (n) return n;
|
306
|
+
const s = await fetch(t).then(
|
307
|
+
(r) => r.text()
|
308
|
+
);
|
309
|
+
return J.set(t, s), s;
|
310
|
+
},
|
311
|
+
// From https://github.com/sveltejs/sites/blob/master/packages/repl/src/lib/workers/bundler/index.js#L255C2-L271C5
|
312
|
+
resolveId: async (t, n) => {
|
313
|
+
if (t === "esm-env")
|
314
|
+
return "virtual:esm-env";
|
315
|
+
if (t === "svelte")
|
316
|
+
return `${E}/src/index-client.js`;
|
317
|
+
if (t.startsWith("svelte/")) {
|
318
|
+
const s = t.slice(7), r = `${E}/src/${s}`;
|
319
|
+
return await W(r);
|
320
|
+
}
|
321
|
+
if (t.startsWith("#client/")) {
|
322
|
+
const s = t.slice(8), r = `${E}/src/internal/client/${s}`;
|
323
|
+
return await W(r);
|
324
|
+
}
|
325
|
+
if (/^https?:/.test(t)) return t;
|
326
|
+
if (t.startsWith(".") && n && n.startsWith(E)) {
|
327
|
+
const s = new URL(t, n).href;
|
328
|
+
return new URL(t, n).href, s;
|
329
|
+
}
|
330
|
+
},
|
331
|
+
transform: async (t, n) => {
|
332
|
+
const { fileName: s } = S(n);
|
333
|
+
if (s.endsWith(".svelte")) {
|
334
|
+
if (!I) {
|
335
|
+
if (!e)
|
336
|
+
throw new Error("Svelte compiler not available");
|
337
|
+
I = await e();
|
338
|
+
}
|
339
|
+
const o = I(t, {
|
340
|
+
filename: s,
|
341
|
+
generate: "client",
|
342
|
+
// Svelte 5 uses 'client' instead of 'dom'
|
343
|
+
css: "external",
|
344
|
+
// Extract CSS instead of auto-injecting
|
345
|
+
dev: !1
|
346
|
+
// Production mode
|
347
|
+
});
|
348
|
+
let c = o.js.code;
|
349
|
+
return o.css && o.css.code && (c = `
|
350
|
+
// Auto-inject CSS for Svelte component
|
351
|
+
(function() {
|
352
|
+
if (typeof document !== 'undefined') {
|
353
|
+
const style = document.createElement('style');
|
354
|
+
style.textContent = ${JSON.stringify(o.css.code)};
|
355
|
+
document.head.appendChild(style);
|
356
|
+
}
|
357
|
+
})();
|
358
|
+
` + c), c;
|
359
|
+
}
|
360
|
+
}
|
361
|
+
}), de = async ({
|
362
|
+
files: e,
|
363
|
+
rollup: t,
|
364
|
+
enableSourcemap: n = !0,
|
365
|
+
vizCache: s,
|
366
|
+
vizId: r,
|
367
|
+
slugCache: o,
|
368
|
+
getSvelteCompiler: c
|
369
|
+
}) => {
|
370
|
+
const i = /* @__PURE__ */ new Set(), a = (p) => {
|
371
|
+
i.add(p);
|
372
|
+
};
|
373
|
+
if (!e["index.js"])
|
374
|
+
throw new Error("Missing index.js");
|
375
|
+
const d = {
|
376
|
+
name: "replace",
|
377
|
+
transform(p, w) {
|
378
|
+
let y = !1, f = p;
|
379
|
+
return f.includes("process.env.NODE_ENV") && (f = f.replace(
|
380
|
+
/\bprocess\.env\.NODE_ENV\b/g,
|
381
|
+
JSON.stringify("production")
|
382
|
+
), y = !0), y ? { code: f, map: null } : null;
|
383
|
+
}
|
384
|
+
}, l = {
|
385
|
+
input: "./index.js",
|
386
|
+
plugins: [
|
387
|
+
...r ? [ie({ vizId: r, slugCache: o })] : [],
|
388
|
+
se(),
|
389
|
+
V(),
|
390
|
+
ae({ getSvelteCompiler: c }),
|
391
|
+
d,
|
392
|
+
...s ? [
|
393
|
+
ce({
|
394
|
+
vizCache: s,
|
395
|
+
trackCSSImport: a,
|
396
|
+
vizId: r,
|
397
|
+
files: e
|
398
|
+
})
|
399
|
+
] : []
|
400
|
+
],
|
401
|
+
onwarn(p, w) {
|
402
|
+
p.code !== "UNRESOLVED_IMPORT" && w(p);
|
403
|
+
}
|
404
|
+
}, m = {
|
405
|
+
format: "umd",
|
406
|
+
name: "Viz",
|
407
|
+
sourcemap: !!n,
|
408
|
+
compact: !0
|
409
|
+
}, g = $(e);
|
410
|
+
if (g) {
|
411
|
+
const p = H(g);
|
412
|
+
p && (l.external = Object.keys(p), m.globals = p);
|
413
|
+
}
|
414
|
+
l.external || (l.external = []), m.globals || (m.globals = {}), Array.isArray(l.external) && (l.external = l.external.filter(
|
415
|
+
(p) => typeof p == "string" && !p.startsWith("#client/")
|
416
|
+
));
|
417
|
+
const v = await t(l), { output: b } = await v.generate(m);
|
418
|
+
return {
|
419
|
+
src: b[0].code,
|
420
|
+
cssFiles: Array.from(i)
|
421
|
+
};
|
422
|
+
}, le = (e) => {
|
423
|
+
if (e instanceof Error) {
|
424
|
+
const t = e.stack || "", n = e.message || "Unknown error";
|
425
|
+
return `${e.name || "Error"}: ${n}
|
426
|
+
${t}`;
|
427
|
+
} else if ("error" in e && e.error instanceof Error) {
|
428
|
+
const t = e.error, n = t.stack || "", s = t.message || "Unknown error", r = "filename" in e ? e.filename : "", o = "lineno" in e ? e.lineno : "", c = "colno" in e ? e.colno : "";
|
429
|
+
let i = "";
|
430
|
+
return r && o && (i = ` at ${r}:${o}`, c && (i += `:${c}`)), `${t.name || "Error"}: ${s}${i}
|
431
|
+
${n}`;
|
432
|
+
} else if ("reason" in e) {
|
433
|
+
const t = e.reason;
|
434
|
+
if (t instanceof Error) {
|
435
|
+
const n = t.stack || "", s = t.message || "Unknown error";
|
436
|
+
return `Unhandled Promise Rejection - ${t.name || "Error"}: ${s}
|
437
|
+
${n}`;
|
438
|
+
} else
|
439
|
+
return `Unhandled Promise Rejection: ${String(t)}`;
|
440
|
+
} else
|
441
|
+
return `Unknown runtime error: ${String(e)}`;
|
442
|
+
}, j = () => `
|
443
|
+
// Global error handling for runtime errors
|
444
|
+
(() => {
|
445
|
+
const formatRuntimeError = ${le.toString()};
|
446
|
+
|
447
|
+
// Handle uncaught JavaScript errors
|
448
|
+
window.addEventListener('error', (event) => {
|
449
|
+
const formattedErrorMessage = formatRuntimeError(event);
|
450
|
+
parent.postMessage({
|
451
|
+
type: 'runtimeError',
|
452
|
+
formattedErrorMessage
|
453
|
+
}, "*");
|
454
|
+
});
|
455
|
+
|
456
|
+
// Handle unhandled promise rejections
|
457
|
+
window.addEventListener('unhandledrejection', (event) => {
|
458
|
+
const formattedErrorMessage = formatRuntimeError(event);
|
459
|
+
parent.postMessage({
|
460
|
+
type: 'runtimeError',
|
461
|
+
formattedErrorMessage
|
462
|
+
}, "*");
|
463
|
+
});
|
464
|
+
})();
|
465
|
+
`;
|
466
|
+
function ue() {
|
467
|
+
return Math.random().toString().slice(2, 7);
|
468
|
+
}
|
469
|
+
const pe = ({
|
470
|
+
cdn: e,
|
471
|
+
src: t,
|
472
|
+
styles: n
|
473
|
+
}) => {
|
474
|
+
const r = `viz-container-${ue()}`;
|
475
|
+
return `<!DOCTYPE html>
|
476
|
+
<html>
|
477
|
+
<head>
|
478
|
+
<meta charset="utf-8">${e}${n}
|
479
|
+
<style>
|
480
|
+
body {
|
481
|
+
margin: 0;
|
482
|
+
overflow: hidden;
|
483
|
+
}
|
484
|
+
#${r} {
|
485
|
+
height: 100vh;
|
486
|
+
}
|
487
|
+
</style>
|
488
|
+
</head>
|
489
|
+
<body>
|
490
|
+
<div id="${r}"></div>
|
491
|
+
<script>${j()}<\/script>
|
492
|
+
<script id="injected-script">${t}<\/script>
|
493
|
+
<script>
|
494
|
+
(() => {
|
495
|
+
let cleanup;
|
496
|
+
const render = () => {
|
497
|
+
const container = document.getElementById('${r}');
|
498
|
+
typeof cleanup === 'function' && cleanup();
|
499
|
+
cleanup = (Viz.viz || Viz.main)(container, { state: window.state, setState, writeFile });
|
500
|
+
};
|
501
|
+
const setState = (next) => {
|
502
|
+
window.state = next(window.state);
|
503
|
+
render();
|
504
|
+
};
|
505
|
+
const writeFile = (fileName, content) => {
|
506
|
+
parent.postMessage({ type: 'writeFile', fileName, content }, "*");
|
507
|
+
};
|
508
|
+
const run = () => {
|
509
|
+
try {
|
510
|
+
setState((state) => state || {});
|
511
|
+
} catch (error) {
|
512
|
+
console.error(error);
|
513
|
+
parent.postMessage({ type: 'runError', error }, "*");
|
514
|
+
}
|
515
|
+
}
|
516
|
+
run();
|
517
|
+
const runJS = (src) => {
|
518
|
+
document.getElementById('injected-script')?.remove();
|
519
|
+
const script = document.createElement('script');
|
520
|
+
script.textContent = src;
|
521
|
+
script.id = 'injected-script';
|
522
|
+
document.body.appendChild(script);
|
523
|
+
run();
|
524
|
+
};
|
525
|
+
const runCSS = (css) => {
|
526
|
+
let style = document.getElementById('injected-style');
|
527
|
+
if (!style) {
|
528
|
+
style = document.createElement('style');
|
529
|
+
style.type = 'text/css';
|
530
|
+
style.id = 'injected-style';
|
531
|
+
document.head.appendChild(style);
|
532
|
+
}
|
533
|
+
style.textContent = css;
|
534
|
+
};
|
535
|
+
onmessage = (message) => {
|
536
|
+
switch (message.data.type) {
|
537
|
+
case 'runJS':
|
538
|
+
runJS(message.data.js);
|
539
|
+
parent.postMessage({ type: 'runDone' }, "*");
|
540
|
+
break;
|
541
|
+
case 'runCSS':
|
542
|
+
runCSS(message.data.css);
|
543
|
+
break;
|
544
|
+
case 'ping':
|
545
|
+
parent.postMessage({ type: 'pong' }, "*");
|
546
|
+
break;
|
547
|
+
default:
|
548
|
+
break;
|
549
|
+
}
|
550
|
+
}
|
551
|
+
})();
|
552
|
+
<\/script>
|
553
|
+
</body>
|
554
|
+
</html>`;
|
555
|
+
}, me = async ({
|
556
|
+
files: e,
|
557
|
+
rollup: t,
|
558
|
+
enableSourcemap: n = !0,
|
559
|
+
vizCache: s,
|
560
|
+
vizId: r,
|
561
|
+
slugCache: o,
|
562
|
+
getSvelteCompiler: c
|
563
|
+
}) => {
|
564
|
+
const { src: i, cssFiles: a } = await de({
|
565
|
+
files: e,
|
566
|
+
rollup: t,
|
567
|
+
enableSourcemap: n,
|
568
|
+
vizCache: s,
|
569
|
+
vizId: r,
|
570
|
+
slugCache: o,
|
571
|
+
getSvelteCompiler: c
|
572
|
+
});
|
573
|
+
let u = [];
|
574
|
+
if (a.length > 0)
|
575
|
+
for (let v = 0; v < a.length; v++) {
|
576
|
+
const b = a[v], p = S(b), w = p.vizId, y = p.fileName;
|
577
|
+
let f = null;
|
578
|
+
if (w === r && e)
|
579
|
+
f = e[y] || null;
|
580
|
+
else {
|
581
|
+
const q = await s.get(w);
|
582
|
+
f = B(q, y);
|
583
|
+
}
|
584
|
+
f && u.push(f);
|
585
|
+
}
|
586
|
+
const d = u.join(`
|
587
|
+
`), l = `
|
588
|
+
<style id="injected-style">${d}</style>`;
|
589
|
+
let m = "";
|
590
|
+
const g = Object.entries(
|
591
|
+
L(e)
|
592
|
+
);
|
593
|
+
if (g.length > 0) {
|
594
|
+
const v = z(e);
|
595
|
+
m = g.map(([b, p], w) => {
|
596
|
+
const y = F(
|
597
|
+
{ name: b, version: p },
|
598
|
+
v
|
599
|
+
);
|
600
|
+
return `${w > 0 ? " " : `
|
601
|
+
`}<script src="${y}"><\/script>`;
|
602
|
+
}).join("");
|
603
|
+
}
|
604
|
+
return {
|
605
|
+
html: pe({ cdn: m, src: i, styles: l }),
|
606
|
+
css: d,
|
607
|
+
js: i,
|
608
|
+
runtimeVersion: "v3"
|
609
|
+
};
|
610
|
+
}, fe = ({
|
611
|
+
initialContents: e,
|
612
|
+
handleCacheMiss: t
|
613
|
+
}) => {
|
614
|
+
const n = new Map(
|
615
|
+
e.map((c) => [c.id, c])
|
616
|
+
);
|
617
|
+
return { get: async (c) => {
|
618
|
+
const i = n.get(c);
|
619
|
+
if (i !== void 0)
|
620
|
+
return i;
|
621
|
+
if (!t)
|
622
|
+
throw new Error(
|
623
|
+
`Unresolved import from vizId ${c}, cache miss handler not provided.`
|
624
|
+
);
|
625
|
+
const a = await t(c);
|
626
|
+
if (a)
|
627
|
+
return n.set(c, a), a;
|
628
|
+
throw new Error(
|
629
|
+
`Unresolved import from vizId ${c}`
|
630
|
+
);
|
631
|
+
}, set: (c) => {
|
632
|
+
n.set(c.id, c);
|
633
|
+
}, invalidate: (c) => {
|
634
|
+
n.delete(c);
|
635
|
+
} };
|
636
|
+
}, Ue = ({
|
637
|
+
initialMappings: e = {},
|
638
|
+
handleCacheMiss: t
|
639
|
+
}) => ({ get: async (o) => {
|
640
|
+
const c = e[o];
|
641
|
+
if (c !== void 0)
|
642
|
+
return c;
|
643
|
+
if (!t)
|
644
|
+
throw new Error(
|
645
|
+
`Unresolved slug ${o}, cache miss handler not provided.`
|
646
|
+
);
|
647
|
+
const i = await t(o);
|
648
|
+
if (i)
|
649
|
+
return e[o] = i, i;
|
650
|
+
throw new Error(`Unresolved slug ${o}`);
|
651
|
+
}, set: (o, c) => {
|
652
|
+
e[o] = c;
|
653
|
+
}, invalidate: (o) => {
|
654
|
+
delete e[o];
|
655
|
+
} }), he = (e, t = "Sample Content for Exporting", n = Y()) => ({
|
656
|
+
id: n,
|
657
|
+
files: Q(e),
|
658
|
+
title: t
|
659
|
+
}), ge = (e) => {
|
660
|
+
if (Object.keys(e).length === 0)
|
661
|
+
return null;
|
662
|
+
const t = "index.html" in e, n = "index.js" in e, s = "index.jsx" in e;
|
663
|
+
return t ? e["index.html"].includes('type="module"') ? "v4" : n || s ? "v2" : "v1" : !t && n ? "v3" : null;
|
664
|
+
}, O = (e, t) => new RegExp(`<${t}\\b`, "i").test(e) && new RegExp(`</${t}>`, "i").test(e), ve = (e) => {
|
665
|
+
const t = e.trim();
|
666
|
+
return O(t, "html") && O(t, "head") && O(t, "body") ? t : `<html><head></head><body>${t}</body></html>`;
|
667
|
+
}, we = (e, t) => e.replace(
|
668
|
+
new RegExp(
|
669
|
+
`<script[^>]*src=["'][^"']*${t.source}[^"']*["'][^>]*>\\s*<\/script>`,
|
670
|
+
"gi"
|
671
|
+
),
|
672
|
+
""
|
673
|
+
), N = (e, t, n) => e.replace(
|
674
|
+
new RegExp(t, "i"),
|
675
|
+
`${n}${t}`
|
676
|
+
), ye = (e, t) => {
|
677
|
+
let n = ve(e);
|
678
|
+
const s = Object.entries(L(t));
|
679
|
+
if (s.length) {
|
680
|
+
const c = z(t);
|
681
|
+
s.forEach(([a]) => {
|
682
|
+
n = we(n, new RegExp(`${a}@`));
|
683
|
+
});
|
684
|
+
const i = s.map(
|
685
|
+
([a, u]) => F({ name: a, version: u }, c)
|
686
|
+
).map((a) => `<script src="${a}"><\/script>`).join(`
|
687
|
+
`);
|
688
|
+
n = N(
|
689
|
+
n,
|
690
|
+
"</head>",
|
691
|
+
i + `
|
692
|
+
`
|
693
|
+
);
|
694
|
+
}
|
695
|
+
if (t["bundle.js"] !== void 0 || t["index.js"] !== void 0) {
|
696
|
+
const c = '<script src="bundle.js"><\/script>', i = /<script\b[^>]*\bsrc=["']bundle\.js["'][^>]*>\s*<\/script>/gi, a = [...n.matchAll(i)];
|
697
|
+
a.length === 1 && (() => {
|
698
|
+
const d = a[0].index ?? -1;
|
699
|
+
if (d === -1) return !1;
|
700
|
+
const l = n.search(/<body\b[^>]*>/i), m = n.search(/<\/body>/i);
|
701
|
+
return l !== -1 && m !== -1 && d > l && d < m;
|
702
|
+
})() || (n = n.replace(i, ""), n = N(n, "</body>", c));
|
703
|
+
}
|
704
|
+
const o = `<script>${j()}<\/script>
|
705
|
+
`;
|
706
|
+
return n = N(
|
707
|
+
n,
|
708
|
+
"</head>",
|
709
|
+
o
|
710
|
+
), /^\s*<!DOCTYPE/i.test(n) ? n : `<!DOCTYPE html>${n}`;
|
711
|
+
}, Ee = (e) => {
|
712
|
+
const t = e["index.html"];
|
713
|
+
return !t && !e["index.js"] && !e["bundle.js"] ? "" : ye(t || "<!DOCTYPE html><html><head></head><body></body></html>", e);
|
714
|
+
};
|
715
|
+
function be(e) {
|
716
|
+
return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
|
717
|
+
}
|
718
|
+
var k, D;
|
719
|
+
function xe() {
|
720
|
+
return D || (D = 1, k = {
|
721
|
+
d3: "d3",
|
722
|
+
"d3-array": "d3",
|
723
|
+
"d3-axis": "d3",
|
724
|
+
"d3-brush": "d3",
|
725
|
+
"d3-chord": "d3",
|
726
|
+
"d3-collection": "d3",
|
727
|
+
"d3-color": "d3",
|
728
|
+
"d3-contour": "d3",
|
729
|
+
"d3-dispatch": "d3",
|
730
|
+
"d3-drag": "d3",
|
731
|
+
"d3-dsv": "d3",
|
732
|
+
"d3-ease": "d3",
|
733
|
+
"d3-fetch": "d3",
|
734
|
+
"d3-force": "d3",
|
735
|
+
"d3-format": "d3",
|
736
|
+
"d3-geo": "d3",
|
737
|
+
"d3-hierarchy": "d3",
|
738
|
+
"d3-interpolate": "d3",
|
739
|
+
"d3-path": "d3",
|
740
|
+
"d3-polygon": "d3",
|
741
|
+
"d3-quadtree": "d3",
|
742
|
+
"d3-random": "d3",
|
743
|
+
"d3-scale": "d3",
|
744
|
+
"d3-scale-chromatic": "d3",
|
745
|
+
"d3-selection": "d3",
|
746
|
+
"d3-shape": "d3",
|
747
|
+
"d3-tile": "d3",
|
748
|
+
"d3-time": "d3",
|
749
|
+
"d3-time-format": "d3",
|
750
|
+
"d3-timer": "d3",
|
751
|
+
"d3-transition": "d3",
|
752
|
+
"d3-voronoi": "d3",
|
753
|
+
"d3-zoom": "d3",
|
754
|
+
react: "React",
|
755
|
+
"react-dom": "ReactDOM",
|
756
|
+
"react-dropdown-browser": "ReactDropdown",
|
757
|
+
"react-dropdown": "ReactDropdown",
|
758
|
+
three: "THREE",
|
759
|
+
vega: "vega",
|
760
|
+
"vega-embed": "vegaEmbed",
|
761
|
+
"vega-lite": "vegaLite",
|
762
|
+
"vega-lite-api": "vl",
|
763
|
+
"vega-tooltip": "vegaTooltip",
|
764
|
+
"vega-themes": "vegaThemes",
|
765
|
+
"vizhub-vega-lite-config": "vizhubVegaLiteConfig",
|
766
|
+
semiotic: "Semiotic",
|
767
|
+
"viz.js": "Viz"
|
768
|
+
}), k;
|
769
|
+
}
|
770
|
+
var Se = xe();
|
771
|
+
const $e = /* @__PURE__ */ be(Se), h = "\0virtual:", U = (e) => {
|
772
|
+
let t = e.replace(/^\.\//, "");
|
773
|
+
return t = t.replace(/\/+/g, "/"), t = t.replace(/\/$/, ""), t;
|
774
|
+
}, je = (e, t) => {
|
775
|
+
const n = e.includes("/") ? e.slice(0, e.lastIndexOf("/")) : "", s = t.split("/"), r = n ? n.split("/") : [];
|
776
|
+
for (const o of s)
|
777
|
+
o === ".." ? r.pop() : o !== "." && o !== "" && r.push(o);
|
778
|
+
return r.join("/");
|
779
|
+
}, _ = (e) => ({
|
780
|
+
name: "virtual-file-system",
|
781
|
+
resolveId(t, n) {
|
782
|
+
const s = n?.startsWith(
|
783
|
+
h
|
784
|
+
) ? n.slice(h.length) : n;
|
785
|
+
if (t.startsWith("./") || t.startsWith("../")) {
|
786
|
+
const o = U(s ? je(s, t) : t);
|
787
|
+
if (e[o])
|
788
|
+
return h + o;
|
789
|
+
const c = [".js", ".jsx", ".ts", ".tsx"];
|
790
|
+
for (const i of c) {
|
791
|
+
const a = o + i;
|
792
|
+
if (e[a])
|
793
|
+
return h + a;
|
794
|
+
}
|
795
|
+
}
|
796
|
+
if (e[t])
|
797
|
+
return h + t;
|
798
|
+
const r = [".js", ".jsx", ".ts", ".tsx"];
|
799
|
+
for (const o of r) {
|
800
|
+
const c = t + o;
|
801
|
+
if (e[c])
|
802
|
+
return h + c;
|
803
|
+
}
|
804
|
+
return null;
|
805
|
+
},
|
806
|
+
load(t) {
|
807
|
+
if (t.startsWith(h)) {
|
808
|
+
const n = t.slice(h.length);
|
809
|
+
if (e[n])
|
810
|
+
return e[n];
|
811
|
+
}
|
812
|
+
return null;
|
813
|
+
}
|
814
|
+
}), Ce = async ({
|
815
|
+
files: e,
|
816
|
+
rollup: t,
|
817
|
+
enableSourcemap: n = !0
|
818
|
+
}) => {
|
819
|
+
let s = "index.js";
|
820
|
+
if (!e[s] && (s = "index.jsx", !e[s]))
|
821
|
+
throw new Error(
|
822
|
+
"Missing entry point, can't find index.js or index.jsx"
|
823
|
+
);
|
824
|
+
const o = {
|
825
|
+
input: "./" + s,
|
826
|
+
plugins: [_(e), V()],
|
827
|
+
onwarn(d, l) {
|
828
|
+
d.code !== "UNRESOLVED_IMPORT" && l(d);
|
829
|
+
}
|
830
|
+
}, c = {
|
831
|
+
format: "iife",
|
832
|
+
sourcemap: n
|
833
|
+
}, i = $(e);
|
834
|
+
if (i) {
|
835
|
+
const d = {
|
836
|
+
// Pre-configured globals for v2 only
|
837
|
+
...$e,
|
838
|
+
// Libraries from package.json
|
839
|
+
...H(i)
|
840
|
+
};
|
841
|
+
d && (o.external = Object.keys(d), c.globals = d);
|
842
|
+
}
|
843
|
+
const a = await t(o), { output: u } = await a.generate(c);
|
844
|
+
return u[0].code;
|
845
|
+
}, Re = async ({
|
846
|
+
files: e,
|
847
|
+
rollup: t,
|
848
|
+
enableSourcemap: n
|
849
|
+
}) => ({
|
850
|
+
...e,
|
851
|
+
"bundle.js": await Ce({
|
852
|
+
files: e,
|
853
|
+
rollup: t,
|
854
|
+
enableSourcemap: n
|
855
|
+
}),
|
856
|
+
"index.html": Ee(e)
|
857
|
+
}), Ie = (e) => {
|
858
|
+
const t = [], n = [], s = /<script\b([^>]*)>([\s\S]*?)<\/script>/gi;
|
859
|
+
let r, o = 0;
|
860
|
+
for (; (r = s.exec(e)) !== null; ) {
|
861
|
+
const c = r[1], i = r[2];
|
862
|
+
if (!/\btype\s*=\s*["']module["']/i.test(c))
|
863
|
+
continue;
|
864
|
+
const a = c.match(
|
865
|
+
/\bsrc\s*=\s*["']([^"']+)["']/i
|
866
|
+
);
|
867
|
+
if (a)
|
868
|
+
t.push(a[1]);
|
869
|
+
else if (i.trim()) {
|
870
|
+
const u = `__inline_script_${o++}.js`;
|
871
|
+
n.push({
|
872
|
+
id: u,
|
873
|
+
content: i.trim()
|
874
|
+
}), t.push(u);
|
875
|
+
}
|
876
|
+
}
|
877
|
+
return { entryPoints: t, inlineScripts: n };
|
878
|
+
}, Oe = () => ({
|
879
|
+
name: "catch-all-prevent-fs",
|
880
|
+
resolveId(e, t) {
|
881
|
+
return { id: e, external: !0 };
|
882
|
+
}
|
883
|
+
}), Ne = async ({
|
884
|
+
entryPoint: e,
|
885
|
+
files: t,
|
886
|
+
rollup: n,
|
887
|
+
enableSourcemap: s = !0
|
888
|
+
}) => {
|
889
|
+
const o = {
|
890
|
+
input: e.startsWith("./") ? e : `./${e}`,
|
891
|
+
plugins: [
|
892
|
+
_(t),
|
893
|
+
V({
|
894
|
+
// Enable JSX runtime
|
895
|
+
// so we don't need to import React
|
896
|
+
// in every file that uses JSX
|
897
|
+
jsxRuntime: "automatic"
|
898
|
+
}),
|
899
|
+
Oe()
|
900
|
+
],
|
901
|
+
// external: (source: string) => {
|
902
|
+
// DEBUG && console.log("external", source);
|
903
|
+
// // Handle strings resolved by `virtualFileSystem`.
|
904
|
+
// const isVirtualFile = source.startsWith("./");
|
905
|
+
// // Handle external dependencies, e.g. from import maps.
|
906
|
+
// const isLibrary = !source.startsWith("./");
|
907
|
+
// const isExternal = !isVirtualFile || isLibrary;
|
908
|
+
// DEBUG && console.log("isExternal", isExternal);
|
909
|
+
// return isExternal;
|
910
|
+
// },
|
911
|
+
onwarn(a, u) {
|
912
|
+
}
|
913
|
+
}, c = await n(o), { output: i } = await c.generate({
|
914
|
+
format: "es",
|
915
|
+
sourcemap: s
|
916
|
+
});
|
917
|
+
return i[0].code;
|
918
|
+
}, T = (e, t) => new RegExp(`<${t}\\b`, "i").test(e) && new RegExp(`</${t}>`, "i").test(e), ke = (e) => {
|
919
|
+
const t = e.trim();
|
920
|
+
return T(t, "html") && T(t, "head") && T(t, "body") ? t : `<html><head></head><body>${t}</body></html>`;
|
921
|
+
}, A = (e) => e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), M = (e, t, n) => e.replace(
|
922
|
+
new RegExp(t, "i"),
|
923
|
+
`${n}${t}`
|
924
|
+
), Te = (e) => {
|
925
|
+
const t = L(e);
|
926
|
+
if (Object.keys(t).length === 0) return null;
|
927
|
+
const n = z(e), s = {};
|
928
|
+
for (const [r, o] of Object.entries(t))
|
929
|
+
s[r] = F(
|
930
|
+
{ name: r, version: o },
|
931
|
+
n
|
932
|
+
);
|
933
|
+
return JSON.stringify({ imports: s }, null, 2);
|
934
|
+
}, Me = () => `
|
935
|
+
// V4 Hot Reloading Support
|
936
|
+
(() => {
|
937
|
+
const runJS = (js) => {
|
938
|
+
// Remove all existing bundled module scripts
|
939
|
+
const existingScripts = document.querySelectorAll('script[type="module"]');
|
940
|
+
existingScripts.forEach(script => {
|
941
|
+
// Only remove scripts that contain bundled code (not import maps or external scripts)
|
942
|
+
if (script.textContent && script.textContent.trim()) {
|
943
|
+
script.remove();
|
944
|
+
}
|
945
|
+
});
|
946
|
+
|
947
|
+
// Create new script with updated bundled code
|
948
|
+
const script = document.createElement('script');
|
949
|
+
script.type = 'module';
|
950
|
+
script.textContent = js;
|
951
|
+
document.body.appendChild(script);
|
952
|
+
};
|
953
|
+
|
954
|
+
const runCSS = (css) => {
|
955
|
+
let style = document.getElementById('v4-injected-style');
|
956
|
+
if (!style) {
|
957
|
+
style = document.createElement('style');
|
958
|
+
style.type = 'text/css';
|
959
|
+
style.id = 'v4-injected-style';
|
960
|
+
document.head.appendChild(style);
|
961
|
+
}
|
962
|
+
style.textContent = css;
|
963
|
+
};
|
964
|
+
|
965
|
+
// Listen for hot reload messages
|
966
|
+
window.addEventListener('message', (message) => {
|
967
|
+
switch (message.data.type) {
|
968
|
+
case 'runJS':
|
969
|
+
try {
|
970
|
+
runJS(message.data.js);
|
971
|
+
parent.postMessage({ type: 'runDone' }, "*");
|
972
|
+
} catch (error) {
|
973
|
+
console.error('V4 Hot reload error:', error);
|
974
|
+
parent.postMessage({ type: 'runError', error }, "*");
|
975
|
+
}
|
976
|
+
break;
|
977
|
+
case 'runCSS':
|
978
|
+
runCSS(message.data.css);
|
979
|
+
break;
|
980
|
+
case 'ping':
|
981
|
+
parent.postMessage({ type: 'pong' }, "*");
|
982
|
+
break;
|
983
|
+
default:
|
984
|
+
break;
|
985
|
+
}
|
986
|
+
});
|
987
|
+
})();
|
988
|
+
`, Ve = (e, t, n = [], s = !1) => {
|
989
|
+
if (!e["index.html"]) return "";
|
990
|
+
let r = ke(e["index.html"]);
|
991
|
+
t.forEach((i, a) => {
|
992
|
+
if (n.some(
|
993
|
+
(d) => d.id === a
|
994
|
+
)) {
|
995
|
+
const d = n.find((g) => g.id === a)?.content || "", l = A(
|
996
|
+
d
|
997
|
+
), m = new RegExp(
|
998
|
+
`<script\\b[^>]*\\btype=["']module["'][^>]*>\\s*${l}\\s*<\/script>`,
|
999
|
+
"gi"
|
1000
|
+
);
|
1001
|
+
r = r.replace(
|
1002
|
+
m,
|
1003
|
+
`<script type="module">
|
1004
|
+
${i}
|
1005
|
+
<\/script>`
|
1006
|
+
);
|
1007
|
+
} else {
|
1008
|
+
const d = new RegExp(
|
1009
|
+
`<script\\b[^>]*\\bsrc=["']${A(a)}["'][^>]*>[^<]*<\/script>`,
|
1010
|
+
"gi"
|
1011
|
+
);
|
1012
|
+
r = r.replace(
|
1013
|
+
d,
|
1014
|
+
`<script type="module">
|
1015
|
+
${i}
|
1016
|
+
<\/script>`
|
1017
|
+
);
|
1018
|
+
}
|
1019
|
+
});
|
1020
|
+
const o = Te(e);
|
1021
|
+
if (o && !/<script\b[^>]*type=["']importmap["'][^>]*>/i.test(
|
1022
|
+
r
|
1023
|
+
)) {
|
1024
|
+
const a = `<script type="importmap">
|
1025
|
+
${o}
|
1026
|
+
<\/script>
|
1027
|
+
`;
|
1028
|
+
r = M(
|
1029
|
+
r,
|
1030
|
+
"</head>",
|
1031
|
+
a
|
1032
|
+
);
|
1033
|
+
}
|
1034
|
+
const c = `<script>${j()}<\/script>
|
1035
|
+
`;
|
1036
|
+
if (r = M(
|
1037
|
+
r,
|
1038
|
+
"</head>",
|
1039
|
+
c
|
1040
|
+
), s) {
|
1041
|
+
const i = `<script>${Me()}<\/script>
|
1042
|
+
`;
|
1043
|
+
r = M(
|
1044
|
+
r,
|
1045
|
+
"</body>",
|
1046
|
+
i
|
1047
|
+
);
|
1048
|
+
}
|
1049
|
+
return /^\s*<!DOCTYPE/i.test(r) ? r : `<!DOCTYPE html>${r}`;
|
1050
|
+
}, Le = async ({
|
1051
|
+
files: e,
|
1052
|
+
rollup: t,
|
1053
|
+
enableSourcemap: n = !0
|
1054
|
+
}) => {
|
1055
|
+
const s = e["index.html"] || "", { entryPoints: r, inlineScripts: o } = Ie(s);
|
1056
|
+
if (r.length === 0)
|
1057
|
+
return { files: e, bundledJS: "" };
|
1058
|
+
const c = { ...e };
|
1059
|
+
for (const l of o)
|
1060
|
+
c[l.id] = l.content;
|
1061
|
+
const i = /* @__PURE__ */ new Map(), a = [];
|
1062
|
+
for (const l of r) {
|
1063
|
+
const m = await Ne({
|
1064
|
+
entryPoint: l,
|
1065
|
+
files: c,
|
1066
|
+
rollup: t,
|
1067
|
+
enableSourcemap: n
|
1068
|
+
});
|
1069
|
+
i.set(l, m), a.push(m);
|
1070
|
+
}
|
1071
|
+
const u = Ve(
|
1072
|
+
c,
|
1073
|
+
i,
|
1074
|
+
o,
|
1075
|
+
!0
|
1076
|
+
), d = a.join(`
|
1077
|
+
`);
|
1078
|
+
return {
|
1079
|
+
files: {
|
1080
|
+
...e,
|
1081
|
+
"index.html": u
|
1082
|
+
},
|
1083
|
+
bundledJS: d
|
1084
|
+
};
|
1085
|
+
}, x = !1, ze = (e) => {
|
1086
|
+
const t = `<script>${j()}<\/script>`;
|
1087
|
+
return e.includes("</head>") ? e.replace(
|
1088
|
+
"</head>",
|
1089
|
+
`${t}
|
1090
|
+
</head>`
|
1091
|
+
) : e.includes("</body>") ? e.replace(
|
1092
|
+
"</body>",
|
1093
|
+
`${t}
|
1094
|
+
</body>`
|
1095
|
+
) : e + t;
|
1096
|
+
}, Ae = async ({
|
1097
|
+
files: e,
|
1098
|
+
rollup: t,
|
1099
|
+
enableSourcemap: n = !0,
|
1100
|
+
vizCache: s,
|
1101
|
+
vizId: r,
|
1102
|
+
slugCache: o,
|
1103
|
+
getSvelteCompiler: c
|
1104
|
+
}) => {
|
1105
|
+
try {
|
1106
|
+
if (x && console.log(
|
1107
|
+
"[build] files:",
|
1108
|
+
e ? JSON.stringify(e).substring(0, 100) : void 0
|
1109
|
+
), x && console.log("[build] vizCache:", s), x && console.log("[build] vizId:", r), !e && !s)
|
1110
|
+
throw new Error(
|
1111
|
+
"Either files or vizCache is required"
|
1112
|
+
);
|
1113
|
+
if (!e && s && !r)
|
1114
|
+
throw new Error(
|
1115
|
+
"vizId is required when using vizCache"
|
1116
|
+
);
|
1117
|
+
if (!e && s && r && (e = X(
|
1118
|
+
(await s.get(r))?.files
|
1119
|
+
)), !e)
|
1120
|
+
throw new Error("Upable to extract viz files");
|
1121
|
+
const i = ge(e);
|
1122
|
+
if (x && console.log("[build] version:", i), i === "v1")
|
1123
|
+
return {
|
1124
|
+
html: ze(
|
1125
|
+
C(e)
|
1126
|
+
),
|
1127
|
+
runtimeVersion: i
|
1128
|
+
};
|
1129
|
+
if (i === "v2") {
|
1130
|
+
if (!t)
|
1131
|
+
throw new Error(
|
1132
|
+
"Rollup is required for v2 runtime"
|
1133
|
+
);
|
1134
|
+
return {
|
1135
|
+
html: C(
|
1136
|
+
await Re({ files: e, rollup: t, enableSourcemap: n })
|
1137
|
+
),
|
1138
|
+
runtimeVersion: i
|
1139
|
+
};
|
1140
|
+
}
|
1141
|
+
if (i === "v3") {
|
1142
|
+
if (!t)
|
1143
|
+
throw new Error(
|
1144
|
+
"Rollup is required for v3 runtime"
|
1145
|
+
);
|
1146
|
+
if (!s && !r) {
|
1147
|
+
const a = he(e);
|
1148
|
+
r = a.id, s = fe({
|
1149
|
+
initialContents: [a],
|
1150
|
+
handleCacheMiss: async () => {
|
1151
|
+
throw new Error(
|
1152
|
+
"Cache miss handler not implemented"
|
1153
|
+
);
|
1154
|
+
}
|
1155
|
+
});
|
1156
|
+
}
|
1157
|
+
if (!s)
|
1158
|
+
throw new Error(
|
1159
|
+
"vizCache is required for v3 runtime"
|
1160
|
+
);
|
1161
|
+
if (!r)
|
1162
|
+
throw new Error(
|
1163
|
+
"vizId is required for v3 runtime if vizCache is provided"
|
1164
|
+
);
|
1165
|
+
return await me({
|
1166
|
+
files: e,
|
1167
|
+
rollup: t,
|
1168
|
+
vizCache: s,
|
1169
|
+
vizId: r,
|
1170
|
+
slugCache: o,
|
1171
|
+
getSvelteCompiler: c
|
1172
|
+
});
|
1173
|
+
}
|
1174
|
+
if (i === "v4") {
|
1175
|
+
if (!t)
|
1176
|
+
throw new Error(
|
1177
|
+
"Rollup is required for v4 runtime"
|
1178
|
+
);
|
1179
|
+
x && console.log("[build] v4Build", {
|
1180
|
+
files: e,
|
1181
|
+
rollup: t,
|
1182
|
+
enableSourcemap: n
|
1183
|
+
});
|
1184
|
+
const a = await Le({
|
1185
|
+
files: e,
|
1186
|
+
rollup: t,
|
1187
|
+
enableSourcemap: n
|
1188
|
+
});
|
1189
|
+
return {
|
1190
|
+
html: C(a.files),
|
1191
|
+
js: a.bundledJS,
|
1192
|
+
runtimeVersion: i
|
1193
|
+
};
|
1194
|
+
}
|
1195
|
+
throw new Error(
|
1196
|
+
`Unsupported runtime version: ${i}`
|
1197
|
+
);
|
1198
|
+
} catch (i) {
|
1199
|
+
throw i instanceof Error && i.message.indexOf(h) && (i.message = i.message.replace(
|
1200
|
+
h,
|
1201
|
+
""
|
1202
|
+
)), i;
|
1203
|
+
}
|
1204
|
+
};
|
1205
|
+
export {
|
1206
|
+
fe as a,
|
1207
|
+
Ae as b,
|
1208
|
+
de as c,
|
1209
|
+
ge as d,
|
1210
|
+
Ue as e,
|
1211
|
+
he as f,
|
1212
|
+
We as g,
|
1213
|
+
De as s,
|
1214
|
+
me as v
|
1215
|
+
};
|
1216
|
+
//# sourceMappingURL=build-BT6ouBQg.js.map
|