@vizhub/runtime 1.0.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/dist/index.js CHANGED
@@ -1,34 +1,33 @@
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(
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(
10
9
  "message",
11
- s
12
- ), r());
10
+ r
11
+ ), i());
13
12
  };
14
13
  e.addEventListener(
15
14
  "message",
16
- s
15
+ r
17
16
  ), e.postMessage({
18
17
  type: "invalidateVizCacheRequest",
19
18
  changedVizIds: t,
20
- requestId: n
19
+ requestId: s
21
20
  });
22
21
  });
23
- }, P = ({
22
+ }, q = ({
24
23
  worker: e,
25
24
  setBuildErrorMessage: t
26
25
  }) => ({
27
- files: n,
28
- enableSourcemap: r,
29
- vizId: s
26
+ files: s,
27
+ enableSourcemap: i,
28
+ vizId: r
30
29
  }) => {
31
- const o = L();
30
+ const o = j();
32
31
  return new Promise(
33
32
  (c) => {
34
33
  const a = (m) => {
@@ -38,49 +37,49 @@ const W = (e) => async (t) => {
38
37
  "message",
39
38
  a
40
39
  );
41
- const g = p.buildResult, v = p.error;
42
- v ? t == null || t(v) : t == null || t(null), c(g);
40
+ const w = p.buildResult, v = p.error;
41
+ v ? t == null || t(v) : t == null || t(null), c(w);
43
42
  }
44
43
  };
45
44
  e.addEventListener("message", a);
46
45
  const u = {
47
46
  type: "buildRequest",
48
- files: n,
49
- enableSourcemap: r,
47
+ files: s,
48
+ enableSourcemap: i,
50
49
  requestId: o,
51
- vizId: s
50
+ vizId: r
52
51
  };
53
52
  e.postMessage(u);
54
53
  }
55
54
  );
56
- }, S = "IDLE", b = "ENQUEUED", R = "PENDING_CLEAN", x = "PENDING_DIRTY", oe = ({
55
+ }, S = "IDLE", x = "ENQUEUED", b = "PENDING_CLEAN", C = "PENDING_DIRTY", B = ({
57
56
  iframe: e,
58
57
  worker: t,
59
- setBuildErrorMessage: n,
60
- getLatestContent: r,
61
- resolveSlugKey: s,
58
+ setBuildErrorMessage: s,
59
+ getLatestContent: i,
60
+ resolveSlugKey: r,
62
61
  writeFile: o
63
62
  }) => {
64
63
  let c = S, a = null;
65
- const u = P({
64
+ const u = q({
66
65
  worker: t,
67
- setBuildErrorMessage: n
66
+ setBuildErrorMessage: s
68
67
  }), m = ({
69
68
  data: l
70
69
  }) => {
71
- if (l.type === "contentRequest" && r) {
72
- const { vizId: i } = l;
73
- r(i).then((d) => {
70
+ if (l.type === "contentRequest" && i) {
71
+ const { vizId: n } = l;
72
+ i(n).then((d) => {
74
73
  t.postMessage({
75
74
  type: "contentResponse",
76
- vizId: i,
75
+ vizId: n,
77
76
  content: d
78
77
  });
79
78
  });
80
79
  } else if (l.type === "resolveSlugRequest") {
81
- const { slugKey: i, requestId: d } = l;
82
- if (s)
83
- s(i).then(
80
+ const { slugKey: n, requestId: d } = l;
81
+ if (r)
82
+ r(n).then(
84
83
  (f) => {
85
84
  const h = {
86
85
  type: "resolveSlugResponse",
@@ -102,43 +101,43 @@ const W = (e) => async (t) => {
102
101
  };
103
102
  t.addEventListener("message", m);
104
103
  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);
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);
107
106
  };
108
107
  window.addEventListener("message", p);
109
- const g = () => {
108
+ const w = () => {
110
109
  t.removeEventListener("message", m), window.removeEventListener("message", p);
111
110
  }, v = async ({
112
111
  files: l,
113
- enableHotReloading: i = !1,
112
+ enableHotReloading: n = !1,
114
113
  enableSourcemap: d = !1,
115
114
  vizId: f
116
115
  }) => {
117
- c = R;
116
+ c = b;
118
117
  const h = await u({
119
118
  files: l,
120
119
  enableSourcemap: d,
121
120
  vizId: f
122
121
  });
123
122
  if (h) {
124
- const { html: w, js: y, css: j } = h;
125
- if (console.clear(), i) {
126
- if (j) {
127
- const I = {
123
+ const { html: E, js: y, css: R } = h;
124
+ if (console.clear(), n) {
125
+ if (R) {
126
+ const N = {
128
127
  type: "runCSS",
129
- css: j
128
+ css: R
130
129
  };
131
130
  if (!e.contentWindow)
132
131
  throw new Error(
133
132
  "iframe.contentWindow is null - this should never happen"
134
133
  );
135
134
  e.contentWindow.postMessage(
136
- I,
135
+ N,
137
136
  window.location.origin
138
137
  );
139
138
  }
140
139
  if (y) {
141
- const I = {
140
+ const N = {
142
141
  type: "runJS",
143
142
  js: y
144
143
  };
@@ -147,112 +146,53 @@ const W = (e) => async (t) => {
147
146
  "iframe.contentWindow is null - this should never happen"
148
147
  );
149
148
  e.contentWindow.postMessage(
150
- I,
149
+ N,
151
150
  window.location.origin
152
151
  );
153
152
  }
154
153
  } else
155
- e.srcdoc = w || "";
154
+ e.srcdoc = E || "";
156
155
  }
157
- c === x ? (requestAnimationFrame(() => {
156
+ c === C ? (requestAnimationFrame(() => {
158
157
  if (!a)
159
158
  throw new Error(
160
159
  "latestFiles is not defined and state is PENDING_DIRTY - this should never happen"
161
160
  );
162
161
  v({
163
162
  files: a,
164
- enableHotReloading: i,
163
+ enableHotReloading: n,
165
164
  enableSourcemap: d,
166
165
  vizId: f
167
166
  });
168
- }), c = b) : c = S;
169
- }, E = ({
167
+ }), c = x) : c = S;
168
+ }, g = ({
170
169
  files: l,
171
- enableHotReloading: i = !1,
170
+ enableHotReloading: n = !1,
172
171
  enableSourcemap: d = !1,
173
172
  vizId: f = void 0
174
173
  }) => {
175
174
  if (a = null, c === S)
176
- c = b, v({
175
+ c = x, v({
177
176
  files: l,
178
- enableHotReloading: i,
177
+ enableHotReloading: n,
179
178
  enableSourcemap: d,
180
179
  vizId: f
181
180
  });
182
- else if (c === R)
183
- a = l, c = x;
184
- else if (c === x)
185
- a = l;
186
181
  else if (c === b)
182
+ a = l, c = C;
183
+ else if (c === C)
184
+ a = l;
185
+ else if (c === x)
187
186
  a = l;
188
187
  else
189
188
  throw new Error(`Unexpected state: ${c}`);
190
189
  };
191
190
  return {
192
- invalidateVizCache: W(t),
193
- run: E,
194
- cleanup: g
195
- };
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
191
+ invalidateVizCache: U(t),
192
+ run: g,
193
+ cleanup: w
254
194
  };
255
- }, Q = `var EOL = {},
195
+ }, J = `var EOL = {},
256
196
  EOF = {},
257
197
  QUOTE = 34,
258
198
  NEWLINE = 10,
@@ -372,84 +312,84 @@ var tsv = dsv(' ');
372
312
 
373
313
  var tsvParse = tsv.parse;
374
314
 
375
- export { csvParse, tsvParse };`, Y = (e) => (
315
+ export { csvParse, tsvParse };`, k = (e) => (
376
316
  // str.replace(/`/g, '\\`');
377
317
  e.replace(/\\/g, "\\\\").replace(/`/g, "\\`")
378
- ), Z = () => ({
318
+ ), _ = () => ({
379
319
  name: "transformDSV",
380
320
  // `id` here is of the form
381
321
  // `{vizId}/{fileName}`
382
322
  transform: async (e, t) => {
383
- const { fileName: n } = N(t), r = n.endsWith(".csv"), s = n.endsWith(".tsv");
384
- if (r || s)
323
+ const { fileName: s } = I(t), i = s.endsWith(".csv"), r = s.endsWith(".tsv");
324
+ if (i || r)
385
325
  return {
386
326
  code: `
387
- ${Q}
388
- const data = ${r ? "csvParse" : "tsvParse"}(\`${Y(e)}\`);
327
+ ${J}
328
+ const data = ${i ? "csvParse" : "tsvParse"}(\`${k(e)}\`);
389
329
  export default data;
390
330
  `,
391
331
  map: { mappings: "" }
392
332
  };
393
333
  }
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]
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]
399
339
  } : null;
400
- }, X = ({
340
+ }, Q = ({
401
341
  vizId: e,
402
342
  slugCache: t
403
343
  }) => ({
404
344
  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) {
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) {
409
349
  const {
410
350
  vizId: c,
411
351
  fileName: a
412
- } = N(r), u = a.split("/").slice(0, -1).join("/"), m = u ? `${u}/${o}` : o;
352
+ } = I(i), u = a.split("/").slice(0, -1).join("/"), m = u ? `${u}/${o}` : o;
413
353
  return `${c}/${m}`;
414
354
  }
415
355
  return e + "/" + o;
416
356
  }
417
- const s = K(n);
418
- if (s) {
357
+ const r = G(s);
358
+ if (r) {
419
359
  let o;
420
- if (F(s.idOrSlug))
421
- o = s.idOrSlug;
360
+ if (W(r.idOrSlug))
361
+ o = r.idOrSlug;
422
362
  else {
423
363
  if (!t)
424
364
  throw new Error(
425
365
  "slugCache is required to import by slug in v3 runtime"
426
366
  );
427
367
  o = await t.get(
428
- `${s.userName}/${s.idOrSlug}`
368
+ `${r.userName}/${r.idOrSlug}`
429
369
  );
430
370
  }
431
371
  return o + "/index.js";
432
372
  }
433
373
  }
434
- }), H = ({
374
+ }), M = ({
435
375
  vizCache: e,
436
376
  trackCSSImport: t,
437
- vizId: n,
438
- files: r
377
+ vizId: s,
378
+ files: i
439
379
  }) => ({
440
380
  name: "vizLoad",
441
381
  // `id` here is of the form
442
382
  // `{vizId}/{fileName}`
443
- load: async (s) => {
444
- const o = N(s), c = o.vizId, a = o.fileName;
383
+ load: async (r) => {
384
+ const o = I(r), c = o.vizId, a = o.fileName;
445
385
  if (a.endsWith(".css"))
446
- return t(s), "";
386
+ return t(r), "";
447
387
  let u = null;
448
- if (c === n && r)
449
- u = r[a] || null;
388
+ if (c === s && i)
389
+ u = i[a] || null;
450
390
  else {
451
391
  const m = await e.get(c);
452
- u = z(m, a);
392
+ u = L(m, a);
453
393
  }
454
394
  if (u === null)
455
395
  throw new Error(
@@ -457,86 +397,86 @@ export { csvParse, tsvParse };`, Y = (e) => (
457
397
  );
458
398
  return u;
459
399
  }
460
- }), B = async ({
400
+ }), Y = async ({
461
401
  files: e,
462
402
  rollup: t,
463
- enableSourcemap: n = !0,
464
- vizCache: r,
465
- vizId: s,
403
+ enableSourcemap: s = !0,
404
+ vizCache: i,
405
+ vizId: r,
466
406
  slugCache: o,
467
407
  getSvelteCompiler: c
468
408
  }) => {
469
- const a = /* @__PURE__ */ new Set(), u = (i) => {
470
- a.add(i);
409
+ const a = /* @__PURE__ */ new Set(), u = (n) => {
410
+ a.add(n);
471
411
  };
472
412
  if (!e["index.js"])
473
413
  throw new Error("Missing index.js");
474
414
  const p = {
475
415
  input: "./index.js",
476
416
  plugins: [
477
- ...s ? [X({ vizId: s, slugCache: o })] : [],
478
- Z(),
479
- A(),
480
- $({ getSvelteCompiler: c }),
481
- ...r ? [
482
- H({
483
- vizCache: r,
417
+ ...r ? [Q({ vizId: r, slugCache: o })] : [],
418
+ _(),
419
+ z(),
420
+ D({ getSvelteCompiler: c }),
421
+ ...i ? [
422
+ M({
423
+ vizCache: i,
484
424
  trackCSSImport: u,
485
- vizId: s,
425
+ vizId: r,
486
426
  files: e
487
427
  })
488
428
  ] : []
489
429
  ],
490
- onwarn(i, d) {
491
- i.code !== "UNRESOLVED_IMPORT" && d(i);
430
+ onwarn(n, d) {
431
+ n.code !== "UNRESOLVED_IMPORT" && d(n);
492
432
  }
493
- }, g = {
433
+ }, w = {
494
434
  format: "umd",
495
435
  name: "Viz",
496
- sourcemap: !!n,
436
+ sourcemap: !!s,
497
437
  compact: !0
498
- }, v = C(e);
438
+ }, v = O(e);
499
439
  if (v) {
500
- const i = M(v);
501
- i && (p.external = Object.keys(i), g.globals = i);
440
+ const n = F(v);
441
+ n && (p.external = Object.keys(n), w.globals = n);
502
442
  }
503
- const E = await t(p), { output: l } = await E.generate(g);
443
+ const g = await t(p), { output: l } = await g.generate(w);
504
444
  return {
505
445
  src: l[0].code,
506
446
  cssFiles: Array.from(a)
507
447
  };
508
448
  };
509
- function ee() {
449
+ function Z() {
510
450
  return Math.random().toString().slice(2, 7);
511
451
  }
512
- const te = ({
452
+ const K = ({
513
453
  cdn: e,
514
454
  src: t,
515
- styles: n
455
+ styles: s
516
456
  }) => {
517
- const s = `viz-container-${ee()}`;
457
+ const r = `viz-container-${Z()}`;
518
458
  return `<!DOCTYPE html>
519
459
  <html>
520
460
  <head>
521
- <meta charset="utf-8">${e}${n}
461
+ <meta charset="utf-8">${e}${s}
522
462
  <style>
523
463
  body {
524
464
  margin: 0;
525
465
  overflow: hidden;
526
466
  }
527
- #${s} {
467
+ #${r} {
528
468
  height: 100vh;
529
469
  }
530
470
  </style>
531
471
  </head>
532
472
  <body>
533
- <div id="${s}"></div>
473
+ <div id="${r}"></div>
534
474
  <script id="injected-script">${t}<\/script>
535
475
  <script>
536
476
  (() => {
537
477
  let cleanup;
538
478
  const render = () => {
539
- const container = document.getElementById('${s}');
479
+ const container = document.getElementById('${r}');
540
480
  typeof cleanup === 'function' && cleanup();
541
481
  cleanup = Viz.main(container, { state: window.state, setState, writeFile });
542
482
  };
@@ -594,49 +534,49 @@ const te = ({
594
534
  <\/script>
595
535
  </body>
596
536
  </html>`;
597
- }, ie = async ({
537
+ }, ee = async ({
598
538
  files: e,
599
539
  rollup: t,
600
- enableSourcemap: n = !0,
601
- vizCache: r,
602
- vizId: s,
540
+ enableSourcemap: s = !0,
541
+ vizCache: i,
542
+ vizId: r,
603
543
  slugCache: o,
604
544
  getSvelteCompiler: c
605
545
  }) => {
606
- const { src: a, cssFiles: u } = await B({
546
+ const { src: a, cssFiles: u } = await Y({
607
547
  files: e,
608
548
  rollup: t,
609
- enableSourcemap: n,
610
- vizCache: r,
611
- vizId: s,
549
+ enableSourcemap: s,
550
+ vizCache: i,
551
+ vizId: r,
612
552
  slugCache: o,
613
553
  getSvelteCompiler: c
614
554
  });
615
555
  let m = [];
616
556
  if (u.length > 0)
617
557
  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;
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;
622
562
  else {
623
- const y = await r.get(f);
624
- w = z(y, h);
563
+ const y = await i.get(f);
564
+ E = L(y, h);
625
565
  }
626
- w && m.push(w);
566
+ E && m.push(E);
627
567
  }
628
568
  const p = m.join(`
629
- `), g = `
569
+ `), w = `
630
570
  <style id="injected-style">${p}</style>`;
631
571
  let v = "";
632
- const E = Object.entries(
633
- J(e)
572
+ const g = Object.entries(
573
+ T(e)
634
574
  );
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 },
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 },
640
580
  l
641
581
  );
642
582
  return `${f > 0 ? " " : `
@@ -644,31 +584,31 @@ const te = ({
644
584
  }).join("");
645
585
  }
646
586
  return {
647
- html: te({ cdn: v, src: a, styles: g }),
587
+ html: K({ cdn: v, src: a, styles: w }),
648
588
  css: p,
649
589
  js: a
650
590
  };
651
- }, ce = ({
591
+ }, te = ({
652
592
  rawMessage: e,
653
593
  vizId: t
654
594
  }) => {
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),
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),
660
600
  title: t
661
601
  });
662
602
  export {
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
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
673
613
  };
674
614
  //# sourceMappingURL=index.js.map