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