@vizhub/runtime 3.0.0 → 4.0.1
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/dist/build-C3ij8Dz4.js +918 -0
- package/dist/build-C3ij8Dz4.js.map +1 -0
- package/dist/build-Cnsq_4EK.cjs +214 -0
- package/dist/build-Cnsq_4EK.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +2 -2
- package/dist/test/fixtures/v2/index.d.ts +1 -0
- package/dist/test/fixtures/v2/index.d.ts.map +1 -1
- package/dist/test/fixtures/v2/jsxTranspileJSXExt.d.ts +5 -0
- package/dist/test/fixtures/v2/jsxTranspileJSXExt.d.ts.map +1 -0
- package/dist/v2/computeBundleJSV2.d.ts.map +1 -1
- package/dist/worker.cjs +1 -1
- package/dist/worker.js +1 -1
- package/package.json +1 -1
- package/dist/build-B2oXi2Mv.js +0 -778
- package/dist/build-B2oXi2Mv.js.map +0 -1
- package/dist/build-D837b50T.cjs +0 -209
- package/dist/build-D837b50T.cjs.map +0 -1
|
@@ -0,0 +1,918 @@
|
|
|
1
|
+
import { magicSandbox as $ } from "magic-sandbox";
|
|
2
|
+
import { isVizId as V, getFileText as L, generateVizId as D, fileCollectionToVizFiles as B, vizFilesToFileCollection as A } from "@vizhub/viz-utils";
|
|
3
|
+
import { transform as q } from "sucrase";
|
|
4
|
+
const Nt = () => (Math.random() + "").slice(2);
|
|
5
|
+
function C(t = {}) {
|
|
6
|
+
return {
|
|
7
|
+
name: "sucrase",
|
|
8
|
+
transform(e, n) {
|
|
9
|
+
if (!n.match(/\.(?:js|[jt]sx)$/))
|
|
10
|
+
return null;
|
|
11
|
+
const r = q(e, {
|
|
12
|
+
transforms: ["jsx", "typescript"],
|
|
13
|
+
// For source maps
|
|
14
|
+
filePath: n,
|
|
15
|
+
sourceMapOptions: {
|
|
16
|
+
compiledFilename: "bundle.js"
|
|
17
|
+
},
|
|
18
|
+
production: !0,
|
|
19
|
+
...t
|
|
20
|
+
});
|
|
21
|
+
return {
|
|
22
|
+
code: r.code,
|
|
23
|
+
map: r.sourceMap
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const P = {
|
|
29
|
+
dependencies: {},
|
|
30
|
+
vizhub: {},
|
|
31
|
+
license: "MIT"
|
|
32
|
+
}, _ = !1, S = (t) => {
|
|
33
|
+
const e = t["package.json"];
|
|
34
|
+
try {
|
|
35
|
+
const n = e ? JSON.parse(e) : P;
|
|
36
|
+
return _ && console.log(
|
|
37
|
+
"[packageJSON] pkg:",
|
|
38
|
+
JSON.stringify(n, null, 2)
|
|
39
|
+
), n;
|
|
40
|
+
} catch {
|
|
41
|
+
return P;
|
|
42
|
+
}
|
|
43
|
+
}, R = (t) => S(t).dependencies || {}, T = (t) => (S(t).vizhub || {}).libraries || {}, F = ({ name: t, version: e }, n, r = "jsdelivr") => {
|
|
44
|
+
const o = n[t] && n[t].path || "";
|
|
45
|
+
return r === "jsdelivr" ? `https://cdn.jsdelivr.net/npm/${t}@${e}${o}` : `https://unpkg.com/${t}@${e}${o}`;
|
|
46
|
+
}, G = (t) => {
|
|
47
|
+
var n;
|
|
48
|
+
const e = (n = t == null ? void 0 : t.vizhub) == null ? void 0 : n.libraries;
|
|
49
|
+
return e ? Object.entries(e).reduce(
|
|
50
|
+
(r, [o, s]) => (s.global && (r[o] = s.global), r),
|
|
51
|
+
{}
|
|
52
|
+
) : {};
|
|
53
|
+
}, Y = {
|
|
54
|
+
d3: "d3",
|
|
55
|
+
react: "React",
|
|
56
|
+
"react-dom": "ReactDOM"
|
|
57
|
+
}, U = (t) => {
|
|
58
|
+
const e = G(t);
|
|
59
|
+
return {
|
|
60
|
+
...Y,
|
|
61
|
+
...e
|
|
62
|
+
};
|
|
63
|
+
}, b = (t) => {
|
|
64
|
+
const [e, ...n] = t.split("/"), r = n.join("/");
|
|
65
|
+
return { vizId: e, fileName: r };
|
|
66
|
+
}, H = `var EOL = {},
|
|
67
|
+
EOF = {},
|
|
68
|
+
QUOTE = 34,
|
|
69
|
+
NEWLINE = 10,
|
|
70
|
+
RETURN = 13;
|
|
71
|
+
|
|
72
|
+
function objectConverter(columns) {
|
|
73
|
+
return new Function(
|
|
74
|
+
'd',
|
|
75
|
+
'return {' +
|
|
76
|
+
columns
|
|
77
|
+
.map(function (name, i) {
|
|
78
|
+
return (
|
|
79
|
+
JSON.stringify(name) + ': d[' + i + '] || ""'
|
|
80
|
+
);
|
|
81
|
+
})
|
|
82
|
+
.join(',') +
|
|
83
|
+
'}',
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function customConverter(columns, f) {
|
|
88
|
+
var object = objectConverter(columns);
|
|
89
|
+
return function (row, i) {
|
|
90
|
+
return f(object(row), i, columns);
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function dsv(delimiter) {
|
|
95
|
+
var DELIMITER = delimiter.charCodeAt(0);
|
|
96
|
+
|
|
97
|
+
function parse(text, f) {
|
|
98
|
+
var convert,
|
|
99
|
+
columns,
|
|
100
|
+
rows = parseRows(text, function (row, i) {
|
|
101
|
+
if (convert) return convert(row, i - 1);
|
|
102
|
+
(columns = row),
|
|
103
|
+
(convert = f
|
|
104
|
+
? customConverter(row, f)
|
|
105
|
+
: objectConverter(row));
|
|
106
|
+
});
|
|
107
|
+
rows.columns = columns || [];
|
|
108
|
+
return rows;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function parseRows(text, f) {
|
|
112
|
+
var rows = [], // output rows
|
|
113
|
+
N = text.length,
|
|
114
|
+
I = 0, // current character index
|
|
115
|
+
n = 0, // current line number
|
|
116
|
+
t, // current token
|
|
117
|
+
eof = N <= 0, // current token followed by EOF?
|
|
118
|
+
eol = false; // current token followed by EOL?
|
|
119
|
+
|
|
120
|
+
// Strip the trailing newline.
|
|
121
|
+
if (text.charCodeAt(N - 1) === NEWLINE) --N;
|
|
122
|
+
if (text.charCodeAt(N - 1) === RETURN) --N;
|
|
123
|
+
|
|
124
|
+
function token() {
|
|
125
|
+
if (eof) return EOF;
|
|
126
|
+
if (eol) return (eol = false), EOL;
|
|
127
|
+
|
|
128
|
+
// Unescape quotes.
|
|
129
|
+
var i,
|
|
130
|
+
j = I,
|
|
131
|
+
c;
|
|
132
|
+
if (text.charCodeAt(j) === QUOTE) {
|
|
133
|
+
while (
|
|
134
|
+
(I++ < N && text.charCodeAt(I) !== QUOTE) ||
|
|
135
|
+
text.charCodeAt(++I) === QUOTE
|
|
136
|
+
);
|
|
137
|
+
if ((i = I) >= N) eof = true;
|
|
138
|
+
else if ((c = text.charCodeAt(I++)) === NEWLINE)
|
|
139
|
+
eol = true;
|
|
140
|
+
else if (c === RETURN) {
|
|
141
|
+
eol = true;
|
|
142
|
+
if (text.charCodeAt(I) === NEWLINE) ++I;
|
|
143
|
+
}
|
|
144
|
+
return text.slice(j + 1, i - 1).replace(/""/g, '"');
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Find next delimiter or newline.
|
|
148
|
+
while (I < N) {
|
|
149
|
+
if ((c = text.charCodeAt((i = I++))) === NEWLINE)
|
|
150
|
+
eol = true;
|
|
151
|
+
else if (c === RETURN) {
|
|
152
|
+
eol = true;
|
|
153
|
+
if (text.charCodeAt(I) === NEWLINE) ++I;
|
|
154
|
+
} else if (c !== DELIMITER) continue;
|
|
155
|
+
return text.slice(j, i);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Return last token before EOF.
|
|
159
|
+
return (eof = true), text.slice(j, N);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
while ((t = token()) !== EOF) {
|
|
163
|
+
var row = [];
|
|
164
|
+
while (t !== EOL && t !== EOF)
|
|
165
|
+
row.push(t), (t = token());
|
|
166
|
+
if (f && (row = f(row, n++)) == null) continue;
|
|
167
|
+
rows.push(row);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return rows;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return {
|
|
174
|
+
parse: parse,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
var csv = dsv(',');
|
|
179
|
+
|
|
180
|
+
var csvParse = csv.parse;
|
|
181
|
+
|
|
182
|
+
var tsv = dsv(' ');
|
|
183
|
+
|
|
184
|
+
var tsvParse = tsv.parse;
|
|
185
|
+
|
|
186
|
+
export { csvParse, tsvParse };`, Q = (t) => (
|
|
187
|
+
// str.replace(/`/g, '\\`');
|
|
188
|
+
t.replace(/\\/g, "\\\\").replace(/`/g, "\\`")
|
|
189
|
+
), X = () => ({
|
|
190
|
+
name: "transformDSV",
|
|
191
|
+
// `id` here is of the form
|
|
192
|
+
// `{vizId}/{fileName}`
|
|
193
|
+
transform: async (t, e) => {
|
|
194
|
+
const { fileName: n } = b(e), r = n.endsWith(".csv"), o = n.endsWith(".tsv");
|
|
195
|
+
if (r || o)
|
|
196
|
+
return {
|
|
197
|
+
code: `
|
|
198
|
+
${H}
|
|
199
|
+
const data = ${r ? "csvParse" : "tsvParse"}(\`${Q(t)}\`);
|
|
200
|
+
export default data;
|
|
201
|
+
`,
|
|
202
|
+
map: { mappings: "" }
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
}), Z = (t) => {
|
|
206
|
+
const e = /^@([a-zA-Z0-9_-]+)\/([a-zA-Z0-9_-]+)$/, n = t.match(e);
|
|
207
|
+
return n ? {
|
|
208
|
+
userName: n[1],
|
|
209
|
+
idOrSlug: n[2]
|
|
210
|
+
} : null;
|
|
211
|
+
}, K = ({
|
|
212
|
+
vizId: t,
|
|
213
|
+
slugCache: e
|
|
214
|
+
}) => ({
|
|
215
|
+
name: "vizResolve",
|
|
216
|
+
resolveId: async (n, r) => {
|
|
217
|
+
if (n.startsWith("./") && !(r != null && r.startsWith("https://"))) {
|
|
218
|
+
let s = n.substring(2);
|
|
219
|
+
if (!s.endsWith(".js") && !s.endsWith(".css") && !s.endsWith(".csv") && !s.endsWith(".svelte") && (s += ".js"), r) {
|
|
220
|
+
const {
|
|
221
|
+
vizId: i,
|
|
222
|
+
fileName: c
|
|
223
|
+
} = b(r), a = c.split("/").slice(0, -1).join("/"), l = a ? `${a}/${s}` : s;
|
|
224
|
+
return `${i}/${l}`;
|
|
225
|
+
}
|
|
226
|
+
return t + "/" + s;
|
|
227
|
+
}
|
|
228
|
+
const o = Z(n);
|
|
229
|
+
if (o) {
|
|
230
|
+
let s;
|
|
231
|
+
if (V(o.idOrSlug))
|
|
232
|
+
s = o.idOrSlug;
|
|
233
|
+
else {
|
|
234
|
+
if (!e)
|
|
235
|
+
throw new Error(
|
|
236
|
+
"slugCache is required to import by slug in v3 runtime"
|
|
237
|
+
);
|
|
238
|
+
s = await e.get(
|
|
239
|
+
`${o.userName}/${o.idOrSlug}`
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
return s + "/index.js";
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}), tt = ({
|
|
246
|
+
vizCache: t,
|
|
247
|
+
trackCSSImport: e,
|
|
248
|
+
vizId: n,
|
|
249
|
+
files: r
|
|
250
|
+
}) => ({
|
|
251
|
+
name: "vizLoad",
|
|
252
|
+
// `id` here is of the form
|
|
253
|
+
// `{vizId}/{fileName}`
|
|
254
|
+
load: async (o) => {
|
|
255
|
+
const s = b(o), i = s.vizId, c = s.fileName;
|
|
256
|
+
if (c.endsWith(".css"))
|
|
257
|
+
return e(o), "";
|
|
258
|
+
let a = null;
|
|
259
|
+
if (i === n && r)
|
|
260
|
+
a = r[c] || null;
|
|
261
|
+
else {
|
|
262
|
+
const l = await t.get(i);
|
|
263
|
+
a = L(l, c);
|
|
264
|
+
}
|
|
265
|
+
if (a === null)
|
|
266
|
+
throw new Error(
|
|
267
|
+
`Imported file "${c}" not found.`
|
|
268
|
+
);
|
|
269
|
+
return a;
|
|
270
|
+
}
|
|
271
|
+
}), M = /* @__PURE__ */ new Map();
|
|
272
|
+
let I;
|
|
273
|
+
const x = "https://cdn.jsdelivr.net/npm/svelte@4.2.9", Ct = `${x}/compiler.cjs`, et = ({
|
|
274
|
+
getSvelteCompiler: t
|
|
275
|
+
}) => ({
|
|
276
|
+
name: "transformSvelte",
|
|
277
|
+
load: async (e) => {
|
|
278
|
+
if (!e.startsWith(x))
|
|
279
|
+
return;
|
|
280
|
+
const n = M.get(e);
|
|
281
|
+
if (n) return n;
|
|
282
|
+
const r = await fetch(e).then(
|
|
283
|
+
(o) => o.text()
|
|
284
|
+
);
|
|
285
|
+
return M.set(e, r), r;
|
|
286
|
+
},
|
|
287
|
+
// From https://github.com/sveltejs/sites/blob/master/packages/repl/src/lib/workers/bundler/index.js#L255C2-L271C5
|
|
288
|
+
resolveId: async (e, n) => {
|
|
289
|
+
if (e === "svelte")
|
|
290
|
+
return `${x}/src/runtime/index.js`;
|
|
291
|
+
if (e.startsWith("svelte/")) {
|
|
292
|
+
const r = e.slice(7);
|
|
293
|
+
return `${x}/src/runtime/${r}/index.js`;
|
|
294
|
+
}
|
|
295
|
+
if (/^https?:/.test(e)) return e;
|
|
296
|
+
if (e.startsWith(".") && n && n.startsWith(x)) {
|
|
297
|
+
const r = new URL(e, n).href;
|
|
298
|
+
return new URL(e, n).href, r;
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
transform: async (e, n) => {
|
|
302
|
+
const { fileName: r } = b(n);
|
|
303
|
+
if (r.endsWith(".svelte")) {
|
|
304
|
+
if (!I) {
|
|
305
|
+
if (!t)
|
|
306
|
+
throw new Error("Svelte compiler not available");
|
|
307
|
+
I = await t();
|
|
308
|
+
}
|
|
309
|
+
return I(e, {
|
|
310
|
+
filename: r,
|
|
311
|
+
hydratable: !0
|
|
312
|
+
}).js;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}), nt = async ({
|
|
316
|
+
files: t,
|
|
317
|
+
rollup: e,
|
|
318
|
+
enableSourcemap: n = !0,
|
|
319
|
+
vizCache: r,
|
|
320
|
+
vizId: o,
|
|
321
|
+
slugCache: s,
|
|
322
|
+
getSvelteCompiler: i
|
|
323
|
+
}) => {
|
|
324
|
+
const c = /* @__PURE__ */ new Set(), a = (d) => {
|
|
325
|
+
c.add(d);
|
|
326
|
+
};
|
|
327
|
+
if (!t["index.js"])
|
|
328
|
+
throw new Error("Missing index.js");
|
|
329
|
+
const u = {
|
|
330
|
+
input: "./index.js",
|
|
331
|
+
plugins: [
|
|
332
|
+
...o ? [K({ vizId: o, slugCache: s })] : [],
|
|
333
|
+
X(),
|
|
334
|
+
C(),
|
|
335
|
+
et({ getSvelteCompiler: i }),
|
|
336
|
+
...r ? [
|
|
337
|
+
tt({
|
|
338
|
+
vizCache: r,
|
|
339
|
+
trackCSSImport: a,
|
|
340
|
+
vizId: o,
|
|
341
|
+
files: t
|
|
342
|
+
})
|
|
343
|
+
] : []
|
|
344
|
+
],
|
|
345
|
+
onwarn(d, h) {
|
|
346
|
+
d.code !== "UNRESOLVED_IMPORT" && h(d);
|
|
347
|
+
}
|
|
348
|
+
}, m = {
|
|
349
|
+
format: "umd",
|
|
350
|
+
name: "Viz",
|
|
351
|
+
sourcemap: !!n,
|
|
352
|
+
compact: !0
|
|
353
|
+
}, w = S(t);
|
|
354
|
+
if (w) {
|
|
355
|
+
const d = U(w);
|
|
356
|
+
d && (u.external = Object.keys(d), m.globals = d);
|
|
357
|
+
}
|
|
358
|
+
const y = await e(u), { output: f } = await y.generate(m);
|
|
359
|
+
return {
|
|
360
|
+
src: f[0].code,
|
|
361
|
+
cssFiles: Array.from(c)
|
|
362
|
+
};
|
|
363
|
+
};
|
|
364
|
+
function rt() {
|
|
365
|
+
return Math.random().toString().slice(2, 7);
|
|
366
|
+
}
|
|
367
|
+
const st = ({
|
|
368
|
+
cdn: t,
|
|
369
|
+
src: e,
|
|
370
|
+
styles: n
|
|
371
|
+
}) => {
|
|
372
|
+
const o = `viz-container-${rt()}`;
|
|
373
|
+
return `<!DOCTYPE html>
|
|
374
|
+
<html>
|
|
375
|
+
<head>
|
|
376
|
+
<meta charset="utf-8">${t}${n}
|
|
377
|
+
<style>
|
|
378
|
+
body {
|
|
379
|
+
margin: 0;
|
|
380
|
+
overflow: hidden;
|
|
381
|
+
}
|
|
382
|
+
#${o} {
|
|
383
|
+
height: 100vh;
|
|
384
|
+
}
|
|
385
|
+
</style>
|
|
386
|
+
</head>
|
|
387
|
+
<body>
|
|
388
|
+
<div id="${o}"></div>
|
|
389
|
+
<script id="injected-script">${e}<\/script>
|
|
390
|
+
<script>
|
|
391
|
+
(() => {
|
|
392
|
+
let cleanup;
|
|
393
|
+
const render = () => {
|
|
394
|
+
const container = document.getElementById('${o}');
|
|
395
|
+
typeof cleanup === 'function' && cleanup();
|
|
396
|
+
cleanup = Viz.main(container, { state: window.state, setState, writeFile });
|
|
397
|
+
};
|
|
398
|
+
const setState = (next) => {
|
|
399
|
+
window.state = next(window.state);
|
|
400
|
+
render();
|
|
401
|
+
};
|
|
402
|
+
const writeFile = (fileName, content) => {
|
|
403
|
+
parent.postMessage({ type: 'writeFile', fileName, content }, "*");
|
|
404
|
+
};
|
|
405
|
+
const run = () => {
|
|
406
|
+
try {
|
|
407
|
+
setState((state) => state || {});
|
|
408
|
+
} catch (error) {
|
|
409
|
+
console.error(error);
|
|
410
|
+
parent.postMessage({ type: 'runError', error }, "*");
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
run();
|
|
414
|
+
const runJS = (src) => {
|
|
415
|
+
document.getElementById('injected-script')?.remove();
|
|
416
|
+
const script = document.createElement('script');
|
|
417
|
+
script.textContent = src;
|
|
418
|
+
script.id = 'injected-script';
|
|
419
|
+
document.body.appendChild(script);
|
|
420
|
+
run();
|
|
421
|
+
};
|
|
422
|
+
const runCSS = (css) => {
|
|
423
|
+
let style = document.getElementById('injected-style');
|
|
424
|
+
if (!style) {
|
|
425
|
+
style = document.createElement('style');
|
|
426
|
+
style.type = 'text/css';
|
|
427
|
+
style.id = 'injected-style';
|
|
428
|
+
document.head.appendChild(style);
|
|
429
|
+
}
|
|
430
|
+
style.textContent = css;
|
|
431
|
+
};
|
|
432
|
+
onmessage = (message) => {
|
|
433
|
+
switch (message.data.type) {
|
|
434
|
+
case 'runJS':
|
|
435
|
+
runJS(message.data.js);
|
|
436
|
+
parent.postMessage({ type: 'runDone' }, "*");
|
|
437
|
+
break;
|
|
438
|
+
case 'runCSS':
|
|
439
|
+
runCSS(message.data.css);
|
|
440
|
+
break;
|
|
441
|
+
case 'ping':
|
|
442
|
+
parent.postMessage({ type: 'pong' }, "*");
|
|
443
|
+
break;
|
|
444
|
+
default:
|
|
445
|
+
break;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
})();
|
|
449
|
+
<\/script>
|
|
450
|
+
</body>
|
|
451
|
+
</html>`;
|
|
452
|
+
}, ot = async ({
|
|
453
|
+
files: t,
|
|
454
|
+
rollup: e,
|
|
455
|
+
enableSourcemap: n = !0,
|
|
456
|
+
vizCache: r,
|
|
457
|
+
vizId: o,
|
|
458
|
+
slugCache: s,
|
|
459
|
+
getSvelteCompiler: i
|
|
460
|
+
}) => {
|
|
461
|
+
const { src: c, cssFiles: a } = await nt({
|
|
462
|
+
files: t,
|
|
463
|
+
rollup: e,
|
|
464
|
+
enableSourcemap: n,
|
|
465
|
+
vizCache: r,
|
|
466
|
+
vizId: o,
|
|
467
|
+
slugCache: s,
|
|
468
|
+
getSvelteCompiler: i
|
|
469
|
+
});
|
|
470
|
+
let l = [];
|
|
471
|
+
if (a.length > 0)
|
|
472
|
+
for (let f = 0; f < a.length; f++) {
|
|
473
|
+
const d = a[f], h = b(d), E = h.vizId, j = h.fileName;
|
|
474
|
+
let v = null;
|
|
475
|
+
if (E === o && t)
|
|
476
|
+
v = t[j] || null;
|
|
477
|
+
else {
|
|
478
|
+
const J = await r.get(E);
|
|
479
|
+
v = L(J, j);
|
|
480
|
+
}
|
|
481
|
+
v && l.push(v);
|
|
482
|
+
}
|
|
483
|
+
const u = l.join(`
|
|
484
|
+
`), m = `
|
|
485
|
+
<style id="injected-style">${u}</style>`;
|
|
486
|
+
let w = "";
|
|
487
|
+
const y = Object.entries(
|
|
488
|
+
R(t)
|
|
489
|
+
);
|
|
490
|
+
if (y.length > 0) {
|
|
491
|
+
const f = T(t);
|
|
492
|
+
w = y.map(([d, h], E) => {
|
|
493
|
+
const j = F(
|
|
494
|
+
{ name: d, version: h },
|
|
495
|
+
f
|
|
496
|
+
);
|
|
497
|
+
return `${E > 0 ? " " : `
|
|
498
|
+
`}<script src="${j}"><\/script>`;
|
|
499
|
+
}).join("");
|
|
500
|
+
}
|
|
501
|
+
return {
|
|
502
|
+
html: st({ cdn: w, src: c, styles: m }),
|
|
503
|
+
css: u,
|
|
504
|
+
js: c
|
|
505
|
+
};
|
|
506
|
+
}, it = ({
|
|
507
|
+
initialContents: t,
|
|
508
|
+
handleCacheMiss: e
|
|
509
|
+
}) => {
|
|
510
|
+
const n = new Map(
|
|
511
|
+
t.map((i) => [i.id, i])
|
|
512
|
+
);
|
|
513
|
+
return { get: async (i) => {
|
|
514
|
+
const c = n.get(i);
|
|
515
|
+
if (c !== void 0)
|
|
516
|
+
return c;
|
|
517
|
+
if (!e)
|
|
518
|
+
throw new Error(
|
|
519
|
+
`Unresolved import from vizId ${i}, cache miss handler not provided.`
|
|
520
|
+
);
|
|
521
|
+
const a = await e(i);
|
|
522
|
+
if (a)
|
|
523
|
+
return n.set(i, a), a;
|
|
524
|
+
throw new Error(
|
|
525
|
+
`Unresolved import from vizId ${i}`
|
|
526
|
+
);
|
|
527
|
+
}, set: (i) => {
|
|
528
|
+
n.set(i.id, i);
|
|
529
|
+
}, invalidate: (i) => {
|
|
530
|
+
n.delete(i);
|
|
531
|
+
} };
|
|
532
|
+
}, Rt = ({
|
|
533
|
+
initialMappings: t = {},
|
|
534
|
+
handleCacheMiss: e
|
|
535
|
+
}) => ({ get: async (s) => {
|
|
536
|
+
const i = t[s];
|
|
537
|
+
if (i !== void 0)
|
|
538
|
+
return i;
|
|
539
|
+
if (!e)
|
|
540
|
+
throw new Error(
|
|
541
|
+
`Unresolved slug ${s}, cache miss handler not provided.`
|
|
542
|
+
);
|
|
543
|
+
const c = await e(s);
|
|
544
|
+
if (c)
|
|
545
|
+
return t[s] = c, c;
|
|
546
|
+
throw new Error(`Unresolved slug ${s}`);
|
|
547
|
+
}, set: (s, i) => {
|
|
548
|
+
t[s] = i;
|
|
549
|
+
}, invalidate: (s) => {
|
|
550
|
+
delete t[s];
|
|
551
|
+
} }), ct = (t, e = "Sample Content for Exporting", n = D()) => ({
|
|
552
|
+
id: n,
|
|
553
|
+
files: B(t),
|
|
554
|
+
title: e
|
|
555
|
+
}), at = (t) => {
|
|
556
|
+
if (Object.keys(t).length === 0)
|
|
557
|
+
return null;
|
|
558
|
+
const e = "index.html" in t, n = "index.js" in t, r = "index.jsx" in t;
|
|
559
|
+
return e ? t["index.html"].includes('type="module"') ? "v4" : n || r ? "v2" : "v1" : !e && n ? "v3" : null;
|
|
560
|
+
}, O = (t, e) => new RegExp(`<${e}\\b`, "i").test(t) && new RegExp(`</${e}>`, "i").test(t), lt = (t) => {
|
|
561
|
+
const e = t.trim();
|
|
562
|
+
return O(e, "html") && O(e, "head") && O(e, "body") ? e : `<html><head></head><body>${e}</body></html>`;
|
|
563
|
+
}, ut = (t, e) => t.replace(
|
|
564
|
+
new RegExp(
|
|
565
|
+
`<script[^>]*src=["'][^"']*${e.source}[^"']*["'][^>]*>\\s*<\/script>`,
|
|
566
|
+
"gi"
|
|
567
|
+
),
|
|
568
|
+
""
|
|
569
|
+
), W = (t, e, n) => t.replace(
|
|
570
|
+
new RegExp(e, "i"),
|
|
571
|
+
`${n}${e}`
|
|
572
|
+
), dt = (t, e) => {
|
|
573
|
+
let n = lt(t);
|
|
574
|
+
const r = Object.entries(R(e));
|
|
575
|
+
if (r.length) {
|
|
576
|
+
const s = T(e);
|
|
577
|
+
r.forEach(([c]) => {
|
|
578
|
+
n = ut(n, new RegExp(`${c}@`));
|
|
579
|
+
});
|
|
580
|
+
const i = r.map(
|
|
581
|
+
([c, a]) => F({ name: c, version: a }, s)
|
|
582
|
+
).map((c) => `<script src="${c}"><\/script>`).join(`
|
|
583
|
+
`);
|
|
584
|
+
n = W(
|
|
585
|
+
n,
|
|
586
|
+
"</head>",
|
|
587
|
+
i + `
|
|
588
|
+
`
|
|
589
|
+
);
|
|
590
|
+
}
|
|
591
|
+
if (e["bundle.js"] !== void 0 || e["index.js"] !== void 0) {
|
|
592
|
+
const s = '<script src="bundle.js"><\/script>', i = /<script\b[^>]*\bsrc=["']bundle\.js["'][^>]*>\s*<\/script>/gi, c = [...n.matchAll(i)];
|
|
593
|
+
c.length === 1 && (() => {
|
|
594
|
+
const l = c[0].index ?? -1;
|
|
595
|
+
if (l === -1) return !1;
|
|
596
|
+
const u = n.search(/<body\b[^>]*>/i), m = n.search(/<\/body>/i);
|
|
597
|
+
return u !== -1 && m !== -1 && l > u && l < m;
|
|
598
|
+
})() || (n = n.replace(i, ""), n = W(n, "</body>", s));
|
|
599
|
+
}
|
|
600
|
+
return /^\s*<!DOCTYPE/i.test(n) ? n : `<!DOCTYPE html>${n}`;
|
|
601
|
+
}, pt = (t) => {
|
|
602
|
+
const e = t["index.html"];
|
|
603
|
+
return !e && !t["index.js"] && !t["bundle.js"] ? "" : dt(e || "<!DOCTYPE html><html><head></head><body></body></html>", t);
|
|
604
|
+
}, p = "\0virtual:", k = (t) => {
|
|
605
|
+
let e = t.replace(/^\.\//, "");
|
|
606
|
+
return e = e.replace(/\/+/g, "/"), e = e.replace(/\/$/, ""), e;
|
|
607
|
+
}, mt = (t, e) => {
|
|
608
|
+
const n = t.includes("/") ? t.slice(0, t.lastIndexOf("/")) : "", r = e.split("/"), o = n ? n.split("/") : [];
|
|
609
|
+
for (const s of r)
|
|
610
|
+
s === ".." ? o.pop() : s !== "." && s !== "" && o.push(s);
|
|
611
|
+
return o.join("/");
|
|
612
|
+
}, z = (t) => ({
|
|
613
|
+
name: "virtual-file-system",
|
|
614
|
+
resolveId(e, n) {
|
|
615
|
+
const r = n != null && n.startsWith(
|
|
616
|
+
p
|
|
617
|
+
) ? n.slice(p.length) : n;
|
|
618
|
+
if (e.startsWith("./") || e.startsWith("../")) {
|
|
619
|
+
const s = k(r ? mt(r, e) : e);
|
|
620
|
+
if (t[s])
|
|
621
|
+
return p + s;
|
|
622
|
+
const i = [".js", ".jsx", ".ts", ".tsx"];
|
|
623
|
+
for (const c of i) {
|
|
624
|
+
const a = s + c;
|
|
625
|
+
if (t[a])
|
|
626
|
+
return p + a;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
if (t[e])
|
|
630
|
+
return p + e;
|
|
631
|
+
const o = [".js", ".jsx", ".ts", ".tsx"];
|
|
632
|
+
for (const s of o) {
|
|
633
|
+
const i = e + s;
|
|
634
|
+
if (t[i])
|
|
635
|
+
return p + i;
|
|
636
|
+
}
|
|
637
|
+
return null;
|
|
638
|
+
},
|
|
639
|
+
load(e) {
|
|
640
|
+
if (e.startsWith(p)) {
|
|
641
|
+
const n = e.slice(p.length);
|
|
642
|
+
if (t[n])
|
|
643
|
+
return t[n];
|
|
644
|
+
}
|
|
645
|
+
return null;
|
|
646
|
+
}
|
|
647
|
+
}), ft = async ({
|
|
648
|
+
files: t,
|
|
649
|
+
rollup: e,
|
|
650
|
+
enableSourcemap: n = !0
|
|
651
|
+
}) => {
|
|
652
|
+
let r = "index.js";
|
|
653
|
+
if (!t[r] && (r = "index.jsx", !t[r]))
|
|
654
|
+
throw new Error(
|
|
655
|
+
"Missing entry point, can't find index.js or index.jsx"
|
|
656
|
+
);
|
|
657
|
+
const s = {
|
|
658
|
+
input: "./" + r,
|
|
659
|
+
plugins: [z(t), C()],
|
|
660
|
+
onwarn(u, m) {
|
|
661
|
+
u.code !== "UNRESOLVED_IMPORT" && m(u);
|
|
662
|
+
}
|
|
663
|
+
}, i = {
|
|
664
|
+
format: "iife",
|
|
665
|
+
sourcemap: n
|
|
666
|
+
}, c = S(t);
|
|
667
|
+
if (c) {
|
|
668
|
+
const u = U(c);
|
|
669
|
+
u && (s.external = Object.keys(u), i.globals = u);
|
|
670
|
+
}
|
|
671
|
+
const a = await e(s), { output: l } = await a.generate(i);
|
|
672
|
+
return l[0].code;
|
|
673
|
+
}, ht = async ({
|
|
674
|
+
files: t,
|
|
675
|
+
rollup: e,
|
|
676
|
+
enableSourcemap: n
|
|
677
|
+
}) => ({
|
|
678
|
+
...t,
|
|
679
|
+
"bundle.js": await ft({
|
|
680
|
+
files: t,
|
|
681
|
+
rollup: e,
|
|
682
|
+
enableSourcemap: n
|
|
683
|
+
}),
|
|
684
|
+
"index.html": pt(t)
|
|
685
|
+
}), wt = (t) => {
|
|
686
|
+
const e = [], n = /<script\b([^>]*)>[\s\S]*?<\/script>/gi;
|
|
687
|
+
let r;
|
|
688
|
+
for (; (r = n.exec(t)) !== null; ) {
|
|
689
|
+
const o = r[1];
|
|
690
|
+
if (!/\btype\s*=\s*["']module["']/i.test(o))
|
|
691
|
+
continue;
|
|
692
|
+
const s = o.match(
|
|
693
|
+
/\bsrc\s*=\s*["']([^"']+)["']/i
|
|
694
|
+
);
|
|
695
|
+
s && e.push(s[1]);
|
|
696
|
+
}
|
|
697
|
+
return e;
|
|
698
|
+
}, vt = () => ({
|
|
699
|
+
name: "catch-all-prevent-fs",
|
|
700
|
+
resolveId(t, e) {
|
|
701
|
+
return { id: t, external: !0 };
|
|
702
|
+
}
|
|
703
|
+
}), gt = async ({
|
|
704
|
+
entryPoint: t,
|
|
705
|
+
files: e,
|
|
706
|
+
rollup: n,
|
|
707
|
+
enableSourcemap: r = !0
|
|
708
|
+
}) => {
|
|
709
|
+
const s = {
|
|
710
|
+
input: t.startsWith("./") ? t : `./${t}`,
|
|
711
|
+
plugins: [
|
|
712
|
+
z(e),
|
|
713
|
+
C({
|
|
714
|
+
// Enable JSX runtime
|
|
715
|
+
// so we don't need to import React
|
|
716
|
+
// in every file that uses JSX
|
|
717
|
+
jsxRuntime: "automatic"
|
|
718
|
+
}),
|
|
719
|
+
vt()
|
|
720
|
+
],
|
|
721
|
+
// external: (source: string) => {
|
|
722
|
+
// DEBUG && console.log("external", source);
|
|
723
|
+
// // Handle strings resolved by `virtualFileSystem`.
|
|
724
|
+
// const isVirtualFile = source.startsWith("./");
|
|
725
|
+
// // Handle external dependencies, e.g. from import maps.
|
|
726
|
+
// const isLibrary = !source.startsWith("./");
|
|
727
|
+
// const isExternal = !isVirtualFile || isLibrary;
|
|
728
|
+
// DEBUG && console.log("isExternal", isExternal);
|
|
729
|
+
// return isExternal;
|
|
730
|
+
// },
|
|
731
|
+
onwarn(a, l) {
|
|
732
|
+
}
|
|
733
|
+
}, i = await n(s), { output: c } = await i.generate({
|
|
734
|
+
format: "es",
|
|
735
|
+
sourcemap: r
|
|
736
|
+
});
|
|
737
|
+
return c[0].code;
|
|
738
|
+
}, N = (t, e) => new RegExp(`<${e}\\b`, "i").test(t) && new RegExp(`</${e}>`, "i").test(t), xt = (t) => {
|
|
739
|
+
const e = t.trim();
|
|
740
|
+
return N(e, "html") && N(e, "head") && N(e, "body") ? e : `<html><head></head><body>${e}</body></html>`;
|
|
741
|
+
}, bt = (t) => t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), yt = (t, e, n) => t.replace(
|
|
742
|
+
new RegExp(e, "i"),
|
|
743
|
+
`${n}${e}`
|
|
744
|
+
), Et = (t) => {
|
|
745
|
+
const e = R(t);
|
|
746
|
+
if (Object.keys(e).length === 0) return null;
|
|
747
|
+
const n = T(t), r = {};
|
|
748
|
+
for (const [o, s] of Object.entries(e))
|
|
749
|
+
r[o] = F(
|
|
750
|
+
{ name: o, version: s },
|
|
751
|
+
n
|
|
752
|
+
);
|
|
753
|
+
return JSON.stringify({ imports: r }, null, 2);
|
|
754
|
+
}, jt = (t, e) => {
|
|
755
|
+
if (!t["index.html"]) return "";
|
|
756
|
+
let n = xt(t["index.html"]);
|
|
757
|
+
e.forEach((o, s) => {
|
|
758
|
+
const i = new RegExp(
|
|
759
|
+
`<script\\b[^>]*\\bsrc=["']${bt(s)}["'][^>]*>[^<]*<\/script>`,
|
|
760
|
+
"gi"
|
|
761
|
+
);
|
|
762
|
+
n = n.replace(
|
|
763
|
+
i,
|
|
764
|
+
`<script type="module">
|
|
765
|
+
${o}
|
|
766
|
+
<\/script>`
|
|
767
|
+
);
|
|
768
|
+
});
|
|
769
|
+
const r = Et(t);
|
|
770
|
+
if (r && !/<script\b[^>]*type=["']importmap["'][^>]*>/i.test(
|
|
771
|
+
n
|
|
772
|
+
)) {
|
|
773
|
+
const s = `<script type="importmap">
|
|
774
|
+
${r}
|
|
775
|
+
<\/script>
|
|
776
|
+
`;
|
|
777
|
+
n = yt(
|
|
778
|
+
n,
|
|
779
|
+
"</head>",
|
|
780
|
+
s
|
|
781
|
+
);
|
|
782
|
+
}
|
|
783
|
+
return /^\s*<!DOCTYPE/i.test(n) ? n : `<!DOCTYPE html>${n}`;
|
|
784
|
+
}, St = async ({
|
|
785
|
+
files: t,
|
|
786
|
+
rollup: e,
|
|
787
|
+
enableSourcemap: n = !0
|
|
788
|
+
}) => {
|
|
789
|
+
const r = t["index.html"] || "", o = wt(r);
|
|
790
|
+
if (o.length === 0)
|
|
791
|
+
return t;
|
|
792
|
+
const s = /* @__PURE__ */ new Map();
|
|
793
|
+
for (const c of o) {
|
|
794
|
+
const a = await gt({
|
|
795
|
+
entryPoint: c,
|
|
796
|
+
files: t,
|
|
797
|
+
rollup: e,
|
|
798
|
+
enableSourcemap: n
|
|
799
|
+
});
|
|
800
|
+
s.set(c, a);
|
|
801
|
+
}
|
|
802
|
+
const i = jt(t, s);
|
|
803
|
+
return {
|
|
804
|
+
...t,
|
|
805
|
+
"index.html": i
|
|
806
|
+
};
|
|
807
|
+
}, g = !1, Tt = async ({
|
|
808
|
+
files: t,
|
|
809
|
+
rollup: e,
|
|
810
|
+
enableSourcemap: n = !0,
|
|
811
|
+
vizCache: r,
|
|
812
|
+
vizId: o,
|
|
813
|
+
slugCache: s,
|
|
814
|
+
getSvelteCompiler: i
|
|
815
|
+
}) => {
|
|
816
|
+
var c;
|
|
817
|
+
try {
|
|
818
|
+
if (g && console.log(
|
|
819
|
+
"[build] files:",
|
|
820
|
+
t ? JSON.stringify(t).substring(0, 100) : void 0
|
|
821
|
+
), g && console.log("[build] vizCache:", r), g && console.log("[build] vizId:", o), !t && !r)
|
|
822
|
+
throw new Error(
|
|
823
|
+
"Either files or vizCache is required"
|
|
824
|
+
);
|
|
825
|
+
if (!t && r && !o)
|
|
826
|
+
throw new Error(
|
|
827
|
+
"vizId is required when using vizCache"
|
|
828
|
+
);
|
|
829
|
+
if (!t && r && o && (t = A(
|
|
830
|
+
(c = await r.get(o)) == null ? void 0 : c.files
|
|
831
|
+
)), !t)
|
|
832
|
+
throw new Error("Upable to extract viz files");
|
|
833
|
+
const a = at(t);
|
|
834
|
+
if (g && console.log("[build] version:", a), a === "v1")
|
|
835
|
+
return {
|
|
836
|
+
html: $(t)
|
|
837
|
+
};
|
|
838
|
+
if (a === "v2") {
|
|
839
|
+
if (!e)
|
|
840
|
+
throw new Error(
|
|
841
|
+
"Rollup is required for v2 runtime"
|
|
842
|
+
);
|
|
843
|
+
return {
|
|
844
|
+
html: $(
|
|
845
|
+
await ht({ files: t, rollup: e, enableSourcemap: n })
|
|
846
|
+
)
|
|
847
|
+
};
|
|
848
|
+
}
|
|
849
|
+
if (a === "v3") {
|
|
850
|
+
if (!e)
|
|
851
|
+
throw new Error(
|
|
852
|
+
"Rollup is required for v3 runtime"
|
|
853
|
+
);
|
|
854
|
+
if (!r && !o) {
|
|
855
|
+
const l = ct(t);
|
|
856
|
+
o = l.id, r = it({
|
|
857
|
+
initialContents: [l],
|
|
858
|
+
handleCacheMiss: async () => {
|
|
859
|
+
throw new Error(
|
|
860
|
+
"Cache miss handler not implemented"
|
|
861
|
+
);
|
|
862
|
+
}
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
if (!r)
|
|
866
|
+
throw new Error(
|
|
867
|
+
"vizCache is required for v3 runtime"
|
|
868
|
+
);
|
|
869
|
+
if (!o)
|
|
870
|
+
throw new Error(
|
|
871
|
+
"vizId is required for v3 runtime if vizCache is provided"
|
|
872
|
+
);
|
|
873
|
+
return await ot({
|
|
874
|
+
files: t,
|
|
875
|
+
rollup: e,
|
|
876
|
+
vizCache: r,
|
|
877
|
+
vizId: o,
|
|
878
|
+
slugCache: s,
|
|
879
|
+
getSvelteCompiler: i
|
|
880
|
+
});
|
|
881
|
+
}
|
|
882
|
+
if (a === "v4") {
|
|
883
|
+
if (!e)
|
|
884
|
+
throw new Error(
|
|
885
|
+
"Rollup is required for v4 runtime"
|
|
886
|
+
);
|
|
887
|
+
return g && console.log("[build] v4Build", {
|
|
888
|
+
files: t,
|
|
889
|
+
rollup: e,
|
|
890
|
+
enableSourcemap: n
|
|
891
|
+
}), {
|
|
892
|
+
html: $(
|
|
893
|
+
await St({ files: t, rollup: e, enableSourcemap: n })
|
|
894
|
+
)
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
throw new Error(
|
|
898
|
+
`Unsupported runtime version: ${a}`
|
|
899
|
+
);
|
|
900
|
+
} catch (a) {
|
|
901
|
+
throw a instanceof Error && a.message.indexOf(p) && (a.message = a.message.replace(
|
|
902
|
+
p,
|
|
903
|
+
""
|
|
904
|
+
)), a;
|
|
905
|
+
}
|
|
906
|
+
};
|
|
907
|
+
export {
|
|
908
|
+
it as a,
|
|
909
|
+
Tt as b,
|
|
910
|
+
nt as c,
|
|
911
|
+
at as d,
|
|
912
|
+
Rt as e,
|
|
913
|
+
ct as f,
|
|
914
|
+
Nt as g,
|
|
915
|
+
Ct as s,
|
|
916
|
+
ot as v
|
|
917
|
+
};
|
|
918
|
+
//# sourceMappingURL=build-C3ij8Dz4.js.map
|