@vizhub/runtime 0.7.0 → 2.0.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 +71 -21
- package/dist/build/build.d.ts.map +1 -1
- package/dist/build/determineRuntimeVersion.d.ts.map +1 -1
- package/dist/build/index.d.ts +1 -0
- package/dist/build/index.d.ts.map +1 -1
- package/dist/common/sucrasePlugin.d.ts +1 -1
- package/dist/common/sucrasePlugin.d.ts.map +1 -1
- package/dist/common/virtualFileSystem.d.ts +2 -1
- package/dist/common/virtualFileSystem.d.ts.map +1 -1
- package/dist/index.cjs +206 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +540 -138
- package/dist/index.js.map +1 -1
- package/dist/orchestration/createRuntime.d.ts.map +1 -1
- package/dist/orchestration/types.d.ts.map +1 -1
- package/dist/slugCache-DqUp8B5A.js +350 -0
- package/dist/slugCache-DqUp8B5A.js.map +1 -0
- package/dist/slugCache-mB6V-shn.cjs +4 -0
- package/dist/slugCache-mB6V-shn.cjs.map +1 -0
- package/dist/test/fixtures/v4/index.d.ts +2 -0
- package/dist/test/fixtures/v4/index.d.ts.map +1 -1
- package/dist/test/fixtures/v4/jsScriptTagTypeModulesRelative.d.ts +6 -0
- package/dist/test/fixtures/v4/jsScriptTagTypeModulesRelative.d.ts.map +1 -0
- package/dist/test/fixtures/v4/reactJsx.d.ts +0 -1
- package/dist/test/fixtures/v4/reactJsx.d.ts.map +1 -1
- package/dist/test/fixtures/v4/reactJsxWithoutImport.d.ts +6 -0
- package/dist/test/fixtures/v4/reactJsxWithoutImport.d.ts.map +1 -0
- package/dist/test/testInBrowser.d.ts +1 -1
- package/dist/test/testInBrowser.d.ts.map +1 -1
- package/dist/v3/slugCache.d.ts.map +1 -1
- package/dist/v4/bundleModule.d.ts.map +1 -1
- package/dist/v4/catchAll.d.ts +8 -0
- package/dist/v4/catchAll.d.ts.map +1 -0
- package/dist/worker.cjs +1 -1
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.js +7 -7
- package/package.json +3 -3
- package/dist/build-BAZMN_vU.cjs +0 -214
- package/dist/build-BAZMN_vU.cjs.map +0 -1
- package/dist/build-NWFvyYnC.js +0 -866
- package/dist/build-NWFvyYnC.js.map +0 -1
package/dist/index.js
CHANGED
@@ -1,212 +1,614 @@
|
|
1
|
-
import { g as D } from "./
|
2
|
-
import {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
import { g as j, p as I, a as O, b as F, s as z, t as D, d as T, c as V, e as $ } from "./slugCache-DqUp8B5A.js";
|
2
|
+
import { f as oe, j as ie, i as ce, h as ae, k as le } from "./slugCache-DqUp8B5A.js";
|
3
|
+
import { isVizId as W, getFileText as L, generateVizId as A, fileCollectionToVizFiles as P } from "@vizhub/viz-utils";
|
4
|
+
const U = (e) => async (t) => {
|
5
|
+
const s = j();
|
6
|
+
return new Promise((i) => {
|
7
|
+
const r = (o) => {
|
8
|
+
o.data.type === "invalidateVizCacheResponse" && o.data.requestId === s && (e.removeEventListener(
|
8
9
|
"message",
|
9
|
-
|
10
|
-
),
|
10
|
+
r
|
11
|
+
), i());
|
11
12
|
};
|
12
|
-
|
13
|
+
e.addEventListener(
|
13
14
|
"message",
|
14
|
-
|
15
|
-
),
|
15
|
+
r
|
16
|
+
), e.postMessage({
|
16
17
|
type: "invalidateVizCacheRequest",
|
17
18
|
changedVizIds: t,
|
18
|
-
requestId:
|
19
|
+
requestId: s
|
19
20
|
});
|
20
21
|
});
|
21
|
-
},
|
22
|
-
worker:
|
22
|
+
}, q = ({
|
23
|
+
worker: e,
|
23
24
|
setBuildErrorMessage: t
|
24
25
|
}) => ({
|
25
|
-
files:
|
26
|
-
enableSourcemap:
|
27
|
-
vizId:
|
26
|
+
files: s,
|
27
|
+
enableSourcemap: i,
|
28
|
+
vizId: r
|
28
29
|
}) => {
|
29
|
-
const
|
30
|
+
const o = j();
|
30
31
|
return new Promise(
|
31
|
-
(
|
32
|
-
const
|
33
|
-
const
|
34
|
-
if (
|
35
|
-
|
32
|
+
(c) => {
|
33
|
+
const a = (m) => {
|
34
|
+
const p = m.data;
|
35
|
+
if (p.type === "buildResponse" && p.requestId === o) {
|
36
|
+
e.removeEventListener(
|
36
37
|
"message",
|
37
|
-
|
38
|
+
a
|
38
39
|
);
|
39
|
-
const
|
40
|
-
|
40
|
+
const w = p.buildResult, v = p.error;
|
41
|
+
v ? t == null || t(v) : t == null || t(null), c(w);
|
41
42
|
}
|
42
43
|
};
|
43
|
-
|
44
|
-
const
|
44
|
+
e.addEventListener("message", a);
|
45
|
+
const u = {
|
45
46
|
type: "buildRequest",
|
46
|
-
files:
|
47
|
-
enableSourcemap:
|
48
|
-
requestId:
|
49
|
-
vizId:
|
47
|
+
files: s,
|
48
|
+
enableSourcemap: i,
|
49
|
+
requestId: o,
|
50
|
+
vizId: r
|
50
51
|
};
|
51
|
-
|
52
|
+
e.postMessage(u);
|
52
53
|
}
|
53
54
|
);
|
54
|
-
},
|
55
|
-
iframe:
|
55
|
+
}, S = "IDLE", x = "ENQUEUED", b = "PENDING_CLEAN", C = "PENDING_DIRTY", B = ({
|
56
|
+
iframe: e,
|
56
57
|
worker: t,
|
57
|
-
setBuildErrorMessage:
|
58
|
-
getLatestContent:
|
59
|
-
resolveSlugKey:
|
60
|
-
writeFile:
|
58
|
+
setBuildErrorMessage: s,
|
59
|
+
getLatestContent: i,
|
60
|
+
resolveSlugKey: r,
|
61
|
+
writeFile: o
|
61
62
|
}) => {
|
62
|
-
let
|
63
|
-
const
|
63
|
+
let c = S, a = null;
|
64
|
+
const u = q({
|
64
65
|
worker: t,
|
65
|
-
setBuildErrorMessage:
|
66
|
-
}),
|
67
|
-
data:
|
66
|
+
setBuildErrorMessage: s
|
67
|
+
}), m = ({
|
68
|
+
data: l
|
68
69
|
}) => {
|
69
|
-
if (
|
70
|
-
const { vizId:
|
71
|
-
|
70
|
+
if (l.type === "contentRequest" && i) {
|
71
|
+
const { vizId: n } = l;
|
72
|
+
i(n).then((d) => {
|
72
73
|
t.postMessage({
|
73
74
|
type: "contentResponse",
|
74
|
-
vizId:
|
75
|
-
content:
|
75
|
+
vizId: n,
|
76
|
+
content: d
|
76
77
|
});
|
77
78
|
});
|
78
|
-
} else if (
|
79
|
-
const { slugKey:
|
80
|
-
if (
|
81
|
-
|
82
|
-
(
|
83
|
-
const
|
79
|
+
} else if (l.type === "resolveSlugRequest") {
|
80
|
+
const { slugKey: n, requestId: d } = l;
|
81
|
+
if (r)
|
82
|
+
r(n).then(
|
83
|
+
(f) => {
|
84
|
+
const h = {
|
84
85
|
type: "resolveSlugResponse",
|
85
|
-
vizId:
|
86
|
-
requestId:
|
86
|
+
vizId: f,
|
87
|
+
requestId: d
|
87
88
|
};
|
88
|
-
t.postMessage(
|
89
|
+
t.postMessage(h);
|
89
90
|
}
|
90
91
|
);
|
91
92
|
else {
|
92
|
-
const
|
93
|
+
const f = {
|
93
94
|
type: "resolveSlugResponse",
|
94
95
|
vizId: null,
|
95
|
-
requestId:
|
96
|
+
requestId: d
|
96
97
|
};
|
97
|
-
t.postMessage(
|
98
|
+
t.postMessage(f);
|
98
99
|
}
|
99
100
|
}
|
100
101
|
};
|
101
|
-
t.addEventListener("message",
|
102
|
-
const
|
103
|
-
const
|
104
|
-
(
|
102
|
+
t.addEventListener("message", m);
|
103
|
+
const p = (l) => {
|
104
|
+
const n = l.data;
|
105
|
+
(n.type === "runDone" || n.type === "runError") && n.type === "runError" && s && s(n.error.message), n.type === "writeFile" && o && n.fileName && n.content && o(n.fileName, n.content);
|
105
106
|
};
|
106
|
-
window.addEventListener("message",
|
107
|
-
const
|
108
|
-
t.removeEventListener("message",
|
109
|
-
},
|
110
|
-
files:
|
111
|
-
enableHotReloading:
|
112
|
-
enableSourcemap:
|
113
|
-
vizId:
|
107
|
+
window.addEventListener("message", p);
|
108
|
+
const w = () => {
|
109
|
+
t.removeEventListener("message", m), window.removeEventListener("message", p);
|
110
|
+
}, v = async ({
|
111
|
+
files: l,
|
112
|
+
enableHotReloading: n = !1,
|
113
|
+
enableSourcemap: d = !1,
|
114
|
+
vizId: f
|
114
115
|
}) => {
|
115
|
-
|
116
|
-
const
|
117
|
-
files:
|
118
|
-
enableSourcemap:
|
119
|
-
vizId:
|
116
|
+
c = b;
|
117
|
+
const h = await u({
|
118
|
+
files: l,
|
119
|
+
enableSourcemap: d,
|
120
|
+
vizId: f
|
120
121
|
});
|
121
|
-
if (
|
122
|
-
const { html:
|
123
|
-
if (console.clear(),
|
124
|
-
if (
|
125
|
-
const
|
122
|
+
if (h) {
|
123
|
+
const { html: E, js: y, css: R } = h;
|
124
|
+
if (console.clear(), n) {
|
125
|
+
if (R) {
|
126
|
+
const N = {
|
126
127
|
type: "runCSS",
|
127
|
-
css:
|
128
|
+
css: R
|
128
129
|
};
|
129
|
-
if (!
|
130
|
+
if (!e.contentWindow)
|
130
131
|
throw new Error(
|
131
132
|
"iframe.contentWindow is null - this should never happen"
|
132
133
|
);
|
133
|
-
|
134
|
-
|
134
|
+
e.contentWindow.postMessage(
|
135
|
+
N,
|
135
136
|
window.location.origin
|
136
137
|
);
|
137
138
|
}
|
138
|
-
if (
|
139
|
-
const
|
139
|
+
if (y) {
|
140
|
+
const N = {
|
140
141
|
type: "runJS",
|
141
|
-
js:
|
142
|
+
js: y
|
142
143
|
};
|
143
|
-
if (!
|
144
|
+
if (!e.contentWindow)
|
144
145
|
throw new Error(
|
145
146
|
"iframe.contentWindow is null - this should never happen"
|
146
147
|
);
|
147
|
-
|
148
|
-
|
148
|
+
e.contentWindow.postMessage(
|
149
|
+
N,
|
149
150
|
window.location.origin
|
150
151
|
);
|
151
152
|
}
|
152
153
|
} else
|
153
|
-
|
154
|
+
e.srcdoc = E || "";
|
154
155
|
}
|
155
|
-
|
156
|
-
if (!
|
156
|
+
c === C ? (requestAnimationFrame(() => {
|
157
|
+
if (!a)
|
157
158
|
throw new Error(
|
158
159
|
"latestFiles is not defined and state is PENDING_DIRTY - this should never happen"
|
159
160
|
);
|
160
|
-
|
161
|
-
files:
|
162
|
-
enableHotReloading:
|
163
|
-
enableSourcemap:
|
164
|
-
vizId:
|
161
|
+
v({
|
162
|
+
files: a,
|
163
|
+
enableHotReloading: n,
|
164
|
+
enableSourcemap: d,
|
165
|
+
vizId: f
|
165
166
|
});
|
166
|
-
}),
|
167
|
-
},
|
168
|
-
files:
|
169
|
-
enableHotReloading:
|
170
|
-
enableSourcemap:
|
171
|
-
vizId:
|
167
|
+
}), c = x) : c = S;
|
168
|
+
}, g = ({
|
169
|
+
files: l,
|
170
|
+
enableHotReloading: n = !1,
|
171
|
+
enableSourcemap: d = !1,
|
172
|
+
vizId: f = void 0
|
172
173
|
}) => {
|
173
|
-
if (
|
174
|
-
|
175
|
-
files:
|
176
|
-
enableHotReloading:
|
177
|
-
enableSourcemap:
|
178
|
-
vizId:
|
174
|
+
if (a = null, c === S)
|
175
|
+
c = x, v({
|
176
|
+
files: l,
|
177
|
+
enableHotReloading: n,
|
178
|
+
enableSourcemap: d,
|
179
|
+
vizId: f
|
179
180
|
});
|
180
|
-
else if (
|
181
|
-
|
182
|
-
else if (
|
183
|
-
|
184
|
-
else if (
|
185
|
-
|
181
|
+
else if (c === b)
|
182
|
+
a = l, c = C;
|
183
|
+
else if (c === C)
|
184
|
+
a = l;
|
185
|
+
else if (c === x)
|
186
|
+
a = l;
|
186
187
|
else
|
187
|
-
throw new Error(`Unexpected state: ${
|
188
|
+
throw new Error(`Unexpected state: ${c}`);
|
188
189
|
};
|
189
190
|
return {
|
190
|
-
invalidateVizCache:
|
191
|
-
run:
|
192
|
-
cleanup:
|
191
|
+
invalidateVizCache: U(t),
|
192
|
+
run: g,
|
193
|
+
cleanup: w
|
193
194
|
};
|
194
|
-
},
|
195
|
-
|
196
|
-
|
195
|
+
}, J = `var EOL = {},
|
196
|
+
EOF = {},
|
197
|
+
QUOTE = 34,
|
198
|
+
NEWLINE = 10,
|
199
|
+
RETURN = 13;
|
200
|
+
|
201
|
+
function objectConverter(columns) {
|
202
|
+
return new Function(
|
203
|
+
'd',
|
204
|
+
'return {' +
|
205
|
+
columns
|
206
|
+
.map(function (name, i) {
|
207
|
+
return (
|
208
|
+
JSON.stringify(name) + ': d[' + i + '] || ""'
|
209
|
+
);
|
210
|
+
})
|
211
|
+
.join(',') +
|
212
|
+
'}',
|
213
|
+
);
|
214
|
+
}
|
215
|
+
|
216
|
+
function customConverter(columns, f) {
|
217
|
+
var object = objectConverter(columns);
|
218
|
+
return function (row, i) {
|
219
|
+
return f(object(row), i, columns);
|
220
|
+
};
|
221
|
+
}
|
222
|
+
|
223
|
+
function dsv(delimiter) {
|
224
|
+
var DELIMITER = delimiter.charCodeAt(0);
|
225
|
+
|
226
|
+
function parse(text, f) {
|
227
|
+
var convert,
|
228
|
+
columns,
|
229
|
+
rows = parseRows(text, function (row, i) {
|
230
|
+
if (convert) return convert(row, i - 1);
|
231
|
+
(columns = row),
|
232
|
+
(convert = f
|
233
|
+
? customConverter(row, f)
|
234
|
+
: objectConverter(row));
|
235
|
+
});
|
236
|
+
rows.columns = columns || [];
|
237
|
+
return rows;
|
238
|
+
}
|
239
|
+
|
240
|
+
function parseRows(text, f) {
|
241
|
+
var rows = [], // output rows
|
242
|
+
N = text.length,
|
243
|
+
I = 0, // current character index
|
244
|
+
n = 0, // current line number
|
245
|
+
t, // current token
|
246
|
+
eof = N <= 0, // current token followed by EOF?
|
247
|
+
eol = false; // current token followed by EOL?
|
248
|
+
|
249
|
+
// Strip the trailing newline.
|
250
|
+
if (text.charCodeAt(N - 1) === NEWLINE) --N;
|
251
|
+
if (text.charCodeAt(N - 1) === RETURN) --N;
|
252
|
+
|
253
|
+
function token() {
|
254
|
+
if (eof) return EOF;
|
255
|
+
if (eol) return (eol = false), EOL;
|
256
|
+
|
257
|
+
// Unescape quotes.
|
258
|
+
var i,
|
259
|
+
j = I,
|
260
|
+
c;
|
261
|
+
if (text.charCodeAt(j) === QUOTE) {
|
262
|
+
while (
|
263
|
+
(I++ < N && text.charCodeAt(I) !== QUOTE) ||
|
264
|
+
text.charCodeAt(++I) === QUOTE
|
265
|
+
);
|
266
|
+
if ((i = I) >= N) eof = true;
|
267
|
+
else if ((c = text.charCodeAt(I++)) === NEWLINE)
|
268
|
+
eol = true;
|
269
|
+
else if (c === RETURN) {
|
270
|
+
eol = true;
|
271
|
+
if (text.charCodeAt(I) === NEWLINE) ++I;
|
272
|
+
}
|
273
|
+
return text.slice(j + 1, i - 1).replace(/""/g, '"');
|
274
|
+
}
|
275
|
+
|
276
|
+
// Find next delimiter or newline.
|
277
|
+
while (I < N) {
|
278
|
+
if ((c = text.charCodeAt((i = I++))) === NEWLINE)
|
279
|
+
eol = true;
|
280
|
+
else if (c === RETURN) {
|
281
|
+
eol = true;
|
282
|
+
if (text.charCodeAt(I) === NEWLINE) ++I;
|
283
|
+
} else if (c !== DELIMITER) continue;
|
284
|
+
return text.slice(j, i);
|
285
|
+
}
|
286
|
+
|
287
|
+
// Return last token before EOF.
|
288
|
+
return (eof = true), text.slice(j, N);
|
289
|
+
}
|
290
|
+
|
291
|
+
while ((t = token()) !== EOF) {
|
292
|
+
var row = [];
|
293
|
+
while (t !== EOL && t !== EOF)
|
294
|
+
row.push(t), (t = token());
|
295
|
+
if (f && (row = f(row, n++)) == null) continue;
|
296
|
+
rows.push(row);
|
297
|
+
}
|
298
|
+
|
299
|
+
return rows;
|
300
|
+
}
|
301
|
+
|
302
|
+
return {
|
303
|
+
parse: parse,
|
304
|
+
};
|
305
|
+
}
|
306
|
+
|
307
|
+
var csv = dsv(',');
|
308
|
+
|
309
|
+
var csvParse = csv.parse;
|
310
|
+
|
311
|
+
var tsv = dsv(' ');
|
312
|
+
|
313
|
+
var tsvParse = tsv.parse;
|
314
|
+
|
315
|
+
export { csvParse, tsvParse };`, k = (e) => (
|
316
|
+
// str.replace(/`/g, '\\`');
|
317
|
+
e.replace(/\\/g, "\\\\").replace(/`/g, "\\`")
|
318
|
+
), _ = () => ({
|
319
|
+
name: "transformDSV",
|
320
|
+
// `id` here is of the form
|
321
|
+
// `{vizId}/{fileName}`
|
322
|
+
transform: async (e, t) => {
|
323
|
+
const { fileName: s } = I(t), i = s.endsWith(".csv"), r = s.endsWith(".tsv");
|
324
|
+
if (i || r)
|
325
|
+
return {
|
326
|
+
code: `
|
327
|
+
${J}
|
328
|
+
const data = ${i ? "csvParse" : "tsvParse"}(\`${k(e)}\`);
|
329
|
+
export default data;
|
330
|
+
`,
|
331
|
+
map: { mappings: "" }
|
332
|
+
};
|
333
|
+
}
|
334
|
+
}), G = (e) => {
|
335
|
+
const t = /^@([a-zA-Z0-9_-]+)\/([a-zA-Z0-9_-]+)$/, s = e.match(t);
|
336
|
+
return s ? {
|
337
|
+
userName: s[1],
|
338
|
+
idOrSlug: s[2]
|
339
|
+
} : null;
|
340
|
+
}, Q = ({
|
341
|
+
vizId: e,
|
342
|
+
slugCache: t
|
343
|
+
}) => ({
|
344
|
+
name: "vizResolve",
|
345
|
+
resolveId: async (s, i) => {
|
346
|
+
if (s.startsWith("./") && !(i != null && i.startsWith("https://"))) {
|
347
|
+
let o = s.substring(2);
|
348
|
+
if (!o.endsWith(".js") && !o.endsWith(".css") && !o.endsWith(".csv") && !o.endsWith(".svelte") && (o += ".js"), i) {
|
349
|
+
const {
|
350
|
+
vizId: c,
|
351
|
+
fileName: a
|
352
|
+
} = I(i), u = a.split("/").slice(0, -1).join("/"), m = u ? `${u}/${o}` : o;
|
353
|
+
return `${c}/${m}`;
|
354
|
+
}
|
355
|
+
return e + "/" + o;
|
356
|
+
}
|
357
|
+
const r = G(s);
|
358
|
+
if (r) {
|
359
|
+
let o;
|
360
|
+
if (W(r.idOrSlug))
|
361
|
+
o = r.idOrSlug;
|
362
|
+
else {
|
363
|
+
if (!t)
|
364
|
+
throw new Error(
|
365
|
+
"slugCache is required to import by slug in v3 runtime"
|
366
|
+
);
|
367
|
+
o = await t.get(
|
368
|
+
`${r.userName}/${r.idOrSlug}`
|
369
|
+
);
|
370
|
+
}
|
371
|
+
return o + "/index.js";
|
372
|
+
}
|
373
|
+
}
|
374
|
+
}), M = ({
|
375
|
+
vizCache: e,
|
376
|
+
trackCSSImport: t,
|
377
|
+
vizId: s,
|
378
|
+
files: i
|
379
|
+
}) => ({
|
380
|
+
name: "vizLoad",
|
381
|
+
// `id` here is of the form
|
382
|
+
// `{vizId}/{fileName}`
|
383
|
+
load: async (r) => {
|
384
|
+
const o = I(r), c = o.vizId, a = o.fileName;
|
385
|
+
if (a.endsWith(".css"))
|
386
|
+
return t(r), "";
|
387
|
+
let u = null;
|
388
|
+
if (c === s && i)
|
389
|
+
u = i[a] || null;
|
390
|
+
else {
|
391
|
+
const m = await e.get(c);
|
392
|
+
u = L(m, a);
|
393
|
+
}
|
394
|
+
if (u === null)
|
395
|
+
throw new Error(
|
396
|
+
`Imported file "${a}" not found.`
|
397
|
+
);
|
398
|
+
return u;
|
399
|
+
}
|
400
|
+
}), Y = async ({
|
401
|
+
files: e,
|
402
|
+
rollup: t,
|
403
|
+
enableSourcemap: s = !0,
|
404
|
+
vizCache: i,
|
405
|
+
vizId: r,
|
406
|
+
slugCache: o,
|
407
|
+
getSvelteCompiler: c
|
197
408
|
}) => {
|
198
|
-
const
|
199
|
-
|
409
|
+
const a = /* @__PURE__ */ new Set(), u = (n) => {
|
410
|
+
a.add(n);
|
411
|
+
};
|
412
|
+
if (!e["index.js"])
|
413
|
+
throw new Error("Missing index.js");
|
414
|
+
const p = {
|
415
|
+
input: "./index.js",
|
416
|
+
plugins: [
|
417
|
+
...r ? [Q({ vizId: r, slugCache: o })] : [],
|
418
|
+
_(),
|
419
|
+
z(),
|
420
|
+
D({ getSvelteCompiler: c }),
|
421
|
+
...i ? [
|
422
|
+
M({
|
423
|
+
vizCache: i,
|
424
|
+
trackCSSImport: u,
|
425
|
+
vizId: r,
|
426
|
+
files: e
|
427
|
+
})
|
428
|
+
] : []
|
429
|
+
],
|
430
|
+
onwarn(n, d) {
|
431
|
+
n.code !== "UNRESOLVED_IMPORT" && d(n);
|
432
|
+
}
|
433
|
+
}, w = {
|
434
|
+
format: "umd",
|
435
|
+
name: "Viz",
|
436
|
+
sourcemap: !!s,
|
437
|
+
compact: !0
|
438
|
+
}, v = O(e);
|
439
|
+
if (v) {
|
440
|
+
const n = F(v);
|
441
|
+
n && (p.external = Object.keys(n), w.globals = n);
|
442
|
+
}
|
443
|
+
const g = await t(p), { output: l } = await g.generate(w);
|
444
|
+
return {
|
445
|
+
src: l[0].code,
|
446
|
+
cssFiles: Array.from(a)
|
447
|
+
};
|
200
448
|
};
|
449
|
+
function Z() {
|
450
|
+
return Math.random().toString().slice(2, 7);
|
451
|
+
}
|
452
|
+
const K = ({
|
453
|
+
cdn: e,
|
454
|
+
src: t,
|
455
|
+
styles: s
|
456
|
+
}) => {
|
457
|
+
const r = `viz-container-${Z()}`;
|
458
|
+
return `<!DOCTYPE html>
|
459
|
+
<html>
|
460
|
+
<head>
|
461
|
+
<meta charset="utf-8">${e}${s}
|
462
|
+
<style>
|
463
|
+
body {
|
464
|
+
margin: 0;
|
465
|
+
overflow: hidden;
|
466
|
+
}
|
467
|
+
#${r} {
|
468
|
+
height: 100vh;
|
469
|
+
}
|
470
|
+
</style>
|
471
|
+
</head>
|
472
|
+
<body>
|
473
|
+
<div id="${r}"></div>
|
474
|
+
<script id="injected-script">${t}<\/script>
|
475
|
+
<script>
|
476
|
+
(() => {
|
477
|
+
let cleanup;
|
478
|
+
const render = () => {
|
479
|
+
const container = document.getElementById('${r}');
|
480
|
+
typeof cleanup === 'function' && cleanup();
|
481
|
+
cleanup = Viz.main(container, { state: window.state, setState, writeFile });
|
482
|
+
};
|
483
|
+
const setState = (next) => {
|
484
|
+
window.state = next(window.state);
|
485
|
+
render();
|
486
|
+
};
|
487
|
+
const writeFile = (fileName, content) => {
|
488
|
+
parent.postMessage({ type: 'writeFile', fileName, content }, "*");
|
489
|
+
};
|
490
|
+
const run = () => {
|
491
|
+
try {
|
492
|
+
setState((state) => state || {});
|
493
|
+
} catch (error) {
|
494
|
+
console.error(error);
|
495
|
+
parent.postMessage({ type: 'runError', error }, "*");
|
496
|
+
}
|
497
|
+
}
|
498
|
+
run();
|
499
|
+
const runJS = (src) => {
|
500
|
+
document.getElementById('injected-script')?.remove();
|
501
|
+
const script = document.createElement('script');
|
502
|
+
script.textContent = src;
|
503
|
+
script.id = 'injected-script';
|
504
|
+
document.body.appendChild(script);
|
505
|
+
run();
|
506
|
+
};
|
507
|
+
const runCSS = (css) => {
|
508
|
+
let style = document.getElementById('injected-style');
|
509
|
+
if (!style) {
|
510
|
+
style = document.createElement('style');
|
511
|
+
style.type = 'text/css';
|
512
|
+
style.id = 'injected-style';
|
513
|
+
document.head.appendChild(style);
|
514
|
+
}
|
515
|
+
style.textContent = css;
|
516
|
+
};
|
517
|
+
onmessage = (message) => {
|
518
|
+
switch (message.data.type) {
|
519
|
+
case 'runJS':
|
520
|
+
runJS(message.data.js);
|
521
|
+
parent.postMessage({ type: 'runDone' }, "*");
|
522
|
+
break;
|
523
|
+
case 'runCSS':
|
524
|
+
runCSS(message.data.css);
|
525
|
+
break;
|
526
|
+
case 'ping':
|
527
|
+
parent.postMessage({ type: 'pong' }, "*");
|
528
|
+
break;
|
529
|
+
default:
|
530
|
+
break;
|
531
|
+
}
|
532
|
+
}
|
533
|
+
})();
|
534
|
+
<\/script>
|
535
|
+
</body>
|
536
|
+
</html>`;
|
537
|
+
}, ee = async ({
|
538
|
+
files: e,
|
539
|
+
rollup: t,
|
540
|
+
enableSourcemap: s = !0,
|
541
|
+
vizCache: i,
|
542
|
+
vizId: r,
|
543
|
+
slugCache: o,
|
544
|
+
getSvelteCompiler: c
|
545
|
+
}) => {
|
546
|
+
const { src: a, cssFiles: u } = await Y({
|
547
|
+
files: e,
|
548
|
+
rollup: t,
|
549
|
+
enableSourcemap: s,
|
550
|
+
vizCache: i,
|
551
|
+
vizId: r,
|
552
|
+
slugCache: o,
|
553
|
+
getSvelteCompiler: c
|
554
|
+
});
|
555
|
+
let m = [];
|
556
|
+
if (u.length > 0)
|
557
|
+
for (let l = 0; l < u.length; l++) {
|
558
|
+
const n = u[l], d = I(n), f = d.vizId, h = d.fileName;
|
559
|
+
let E = null;
|
560
|
+
if (f === r && e)
|
561
|
+
E = e[h] || null;
|
562
|
+
else {
|
563
|
+
const y = await i.get(f);
|
564
|
+
E = L(y, h);
|
565
|
+
}
|
566
|
+
E && m.push(E);
|
567
|
+
}
|
568
|
+
const p = m.join(`
|
569
|
+
`), w = `
|
570
|
+
<style id="injected-style">${p}</style>`;
|
571
|
+
let v = "";
|
572
|
+
const g = Object.entries(
|
573
|
+
T(e)
|
574
|
+
);
|
575
|
+
if (g.length > 0) {
|
576
|
+
const l = V(e);
|
577
|
+
v = g.map(([n, d], f) => {
|
578
|
+
const h = $(
|
579
|
+
{ name: n, version: d },
|
580
|
+
l
|
581
|
+
);
|
582
|
+
return `${f > 0 ? " " : `
|
583
|
+
`}<script src="${h}"><\/script>`;
|
584
|
+
}).join("");
|
585
|
+
}
|
586
|
+
return {
|
587
|
+
html: K({ cdn: v, src: a, styles: w }),
|
588
|
+
css: p,
|
589
|
+
js: a
|
590
|
+
};
|
591
|
+
}, te = ({
|
592
|
+
rawMessage: e,
|
593
|
+
vizId: t
|
594
|
+
}) => {
|
595
|
+
const s = new RegExp(t, "g");
|
596
|
+
return e == null ? void 0 : e.replace(s, ".");
|
597
|
+
}, ne = (e, t = "Sample Content for Exporting", s = A()) => ({
|
598
|
+
id: s,
|
599
|
+
files: P(e),
|
600
|
+
title: t
|
601
|
+
});
|
201
602
|
export {
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
603
|
+
oe as build,
|
604
|
+
te as cleanRollupErrorMessage,
|
605
|
+
Y as computeBundleJSV3,
|
606
|
+
B as createRuntime,
|
607
|
+
ie as createSlugCache,
|
608
|
+
ce as createVizCache,
|
609
|
+
ne as createVizContent,
|
610
|
+
ae as determineRuntimeVersion,
|
611
|
+
le as svelteCompilerUrl,
|
612
|
+
ee as v3Build
|
211
613
|
};
|
212
614
|
//# sourceMappingURL=index.js.map
|