@vizhub/runtime 4.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.
@@ -1,5 +1,5 @@
1
1
  import { magicSandbox as $ } from "magic-sandbox";
2
- import { isVizId as J, getFileText as L, generateVizId as D, fileCollectionToVizFiles as B, vizFilesToFileCollection as A } from "@vizhub/viz-utils";
2
+ import { isVizId as V, getFileText as L, generateVizId as D, fileCollectionToVizFiles as B, vizFilesToFileCollection as A } from "@vizhub/viz-utils";
3
3
  import { transform as q } from "sucrase";
4
4
  const Nt = () => (Math.random() + "").slice(2);
5
5
  function C(t = {}) {
@@ -25,20 +25,20 @@ function C(t = {}) {
25
25
  }
26
26
  };
27
27
  }
28
- const M = {
28
+ const P = {
29
29
  dependencies: {},
30
30
  vizhub: {},
31
31
  license: "MIT"
32
32
  }, _ = !1, S = (t) => {
33
33
  const e = t["package.json"];
34
34
  try {
35
- const n = e ? JSON.parse(e) : M;
35
+ const n = e ? JSON.parse(e) : P;
36
36
  return _ && console.log(
37
37
  "[packageJSON] pkg:",
38
38
  JSON.stringify(n, null, 2)
39
39
  ), n;
40
40
  } catch {
41
- return M;
41
+ return P;
42
42
  }
43
43
  }, R = (t) => S(t).dependencies || {}, T = (t) => (S(t).vizhub || {}).libraries || {}, F = ({ name: t, version: e }, n, r = "jsdelivr") => {
44
44
  const o = n[t] && n[t].path || "";
@@ -219,8 +219,8 @@ export { csvParse, tsvParse };`, Q = (t) => (
219
219
  if (!s.endsWith(".js") && !s.endsWith(".css") && !s.endsWith(".csv") && !s.endsWith(".svelte") && (s += ".js"), r) {
220
220
  const {
221
221
  vizId: i,
222
- fileName: a
223
- } = b(r), c = a.split("/").slice(0, -1).join("/"), l = c ? `${c}/${s}` : s;
222
+ fileName: c
223
+ } = b(r), a = c.split("/").slice(0, -1).join("/"), l = a ? `${a}/${s}` : s;
224
224
  return `${i}/${l}`;
225
225
  }
226
226
  return t + "/" + s;
@@ -228,7 +228,7 @@ export { csvParse, tsvParse };`, Q = (t) => (
228
228
  const o = Z(n);
229
229
  if (o) {
230
230
  let s;
231
- if (J(o.idOrSlug))
231
+ if (V(o.idOrSlug))
232
232
  s = o.idOrSlug;
233
233
  else {
234
234
  if (!e)
@@ -252,23 +252,23 @@ export { csvParse, tsvParse };`, Q = (t) => (
252
252
  // `id` here is of the form
253
253
  // `{vizId}/{fileName}`
254
254
  load: async (o) => {
255
- const s = b(o), i = s.vizId, a = s.fileName;
256
- if (a.endsWith(".css"))
255
+ const s = b(o), i = s.vizId, c = s.fileName;
256
+ if (c.endsWith(".css"))
257
257
  return e(o), "";
258
- let c = null;
258
+ let a = null;
259
259
  if (i === n && r)
260
- c = r[a] || null;
260
+ a = r[c] || null;
261
261
  else {
262
262
  const l = await t.get(i);
263
- c = L(l, a);
263
+ a = L(l, c);
264
264
  }
265
- if (c === null)
265
+ if (a === null)
266
266
  throw new Error(
267
- `Imported file "${a}" not found.`
267
+ `Imported file "${c}" not found.`
268
268
  );
269
- return c;
269
+ return a;
270
270
  }
271
- }), P = /* @__PURE__ */ new Map();
271
+ }), M = /* @__PURE__ */ new Map();
272
272
  let I;
273
273
  const x = "https://cdn.jsdelivr.net/npm/svelte@4.2.9", Ct = `${x}/compiler.cjs`, et = ({
274
274
  getSvelteCompiler: t
@@ -277,12 +277,12 @@ const x = "https://cdn.jsdelivr.net/npm/svelte@4.2.9", Ct = `${x}/compiler.cjs`,
277
277
  load: async (e) => {
278
278
  if (!e.startsWith(x))
279
279
  return;
280
- const n = P.get(e);
280
+ const n = M.get(e);
281
281
  if (n) return n;
282
282
  const r = await fetch(e).then(
283
283
  (o) => o.text()
284
284
  );
285
- return P.set(e, r), r;
285
+ return M.set(e, r), r;
286
286
  },
287
287
  // From https://github.com/sveltejs/sites/blob/master/packages/repl/src/lib/workers/bundler/index.js#L255C2-L271C5
288
288
  resolveId: async (e, n) => {
@@ -321,12 +321,12 @@ const x = "https://cdn.jsdelivr.net/npm/svelte@4.2.9", Ct = `${x}/compiler.cjs`,
321
321
  slugCache: s,
322
322
  getSvelteCompiler: i
323
323
  }) => {
324
- const a = /* @__PURE__ */ new Set(), c = (u) => {
325
- a.add(u);
324
+ const c = /* @__PURE__ */ new Set(), a = (d) => {
325
+ c.add(d);
326
326
  };
327
327
  if (!t["index.js"])
328
328
  throw new Error("Missing index.js");
329
- const d = {
329
+ const u = {
330
330
  input: "./index.js",
331
331
  plugins: [
332
332
  ...o ? [K({ vizId: o, slugCache: s })] : [],
@@ -336,14 +336,14 @@ const x = "https://cdn.jsdelivr.net/npm/svelte@4.2.9", Ct = `${x}/compiler.cjs`,
336
336
  ...r ? [
337
337
  tt({
338
338
  vizCache: r,
339
- trackCSSImport: c,
339
+ trackCSSImport: a,
340
340
  vizId: o,
341
341
  files: t
342
342
  })
343
343
  ] : []
344
344
  ],
345
- onwarn(u, f) {
346
- u.code !== "UNRESOLVED_IMPORT" && f(u);
345
+ onwarn(d, h) {
346
+ d.code !== "UNRESOLVED_IMPORT" && h(d);
347
347
  }
348
348
  }, m = {
349
349
  format: "umd",
@@ -352,13 +352,13 @@ const x = "https://cdn.jsdelivr.net/npm/svelte@4.2.9", Ct = `${x}/compiler.cjs`,
352
352
  compact: !0
353
353
  }, w = S(t);
354
354
  if (w) {
355
- const u = U(w);
356
- u && (d.external = Object.keys(u), m.globals = u);
355
+ const d = U(w);
356
+ d && (u.external = Object.keys(d), m.globals = d);
357
357
  }
358
- const y = await e(d), { output: h } = await y.generate(m);
358
+ const y = await e(u), { output: f } = await y.generate(m);
359
359
  return {
360
- src: h[0].code,
361
- cssFiles: Array.from(a)
360
+ src: f[0].code,
361
+ cssFiles: Array.from(c)
362
362
  };
363
363
  };
364
364
  function rt() {
@@ -458,7 +458,7 @@ const st = ({
458
458
  slugCache: s,
459
459
  getSvelteCompiler: i
460
460
  }) => {
461
- const { src: a, cssFiles: c } = await nt({
461
+ const { src: c, cssFiles: a } = await nt({
462
462
  files: t,
463
463
  rollup: e,
464
464
  enableSourcemap: n,
@@ -468,40 +468,40 @@ const st = ({
468
468
  getSvelteCompiler: i
469
469
  });
470
470
  let l = [];
471
- if (c.length > 0)
472
- for (let h = 0; h < c.length; h++) {
473
- const u = c[h], f = b(u), E = f.vizId, j = f.fileName;
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
474
  let v = null;
475
475
  if (E === o && t)
476
476
  v = t[j] || null;
477
477
  else {
478
- const V = await r.get(E);
479
- v = L(V, j);
478
+ const J = await r.get(E);
479
+ v = L(J, j);
480
480
  }
481
481
  v && l.push(v);
482
482
  }
483
- const d = l.join(`
483
+ const u = l.join(`
484
484
  `), m = `
485
- <style id="injected-style">${d}</style>`;
485
+ <style id="injected-style">${u}</style>`;
486
486
  let w = "";
487
487
  const y = Object.entries(
488
488
  R(t)
489
489
  );
490
490
  if (y.length > 0) {
491
- const h = T(t);
492
- w = y.map(([u, f], E) => {
491
+ const f = T(t);
492
+ w = y.map(([d, h], E) => {
493
493
  const j = F(
494
- { name: u, version: f },
495
- h
494
+ { name: d, version: h },
495
+ f
496
496
  );
497
497
  return `${E > 0 ? " " : `
498
498
  `}<script src="${j}"><\/script>`;
499
499
  }).join("");
500
500
  }
501
501
  return {
502
- html: st({ cdn: w, src: a, styles: m }),
503
- css: d,
504
- js: a
502
+ html: st({ cdn: w, src: c, styles: m }),
503
+ css: u,
504
+ js: c
505
505
  };
506
506
  }, it = ({
507
507
  initialContents: t,
@@ -511,16 +511,16 @@ const st = ({
511
511
  t.map((i) => [i.id, i])
512
512
  );
513
513
  return { get: async (i) => {
514
- const a = n.get(i);
515
- if (a !== void 0)
516
- return a;
514
+ const c = n.get(i);
515
+ if (c !== void 0)
516
+ return c;
517
517
  if (!e)
518
518
  throw new Error(
519
519
  `Unresolved import from vizId ${i}, cache miss handler not provided.`
520
520
  );
521
- const c = await e(i);
522
- if (c)
523
- return n.set(i, c), c;
521
+ const a = await e(i);
522
+ if (a)
523
+ return n.set(i, a), a;
524
524
  throw new Error(
525
525
  `Unresolved import from vizId ${i}`
526
526
  );
@@ -540,9 +540,9 @@ const st = ({
540
540
  throw new Error(
541
541
  `Unresolved slug ${s}, cache miss handler not provided.`
542
542
  );
543
- const a = await e(s);
544
- if (a)
545
- return t[s] = a, a;
543
+ const c = await e(s);
544
+ if (c)
545
+ return t[s] = c, c;
546
546
  throw new Error(`Unresolved slug ${s}`);
547
547
  }, set: (s, i) => {
548
548
  t[s] = i;
@@ -574,12 +574,12 @@ const st = ({
574
574
  const r = Object.entries(R(e));
575
575
  if (r.length) {
576
576
  const s = T(e);
577
- r.forEach(([a]) => {
578
- n = ut(n, new RegExp(`${a}@`));
577
+ r.forEach(([c]) => {
578
+ n = ut(n, new RegExp(`${c}@`));
579
579
  });
580
580
  const i = r.map(
581
- ([a, c]) => F({ name: a, version: c }, s)
582
- ).map((a) => `<script src="${a}"><\/script>`).join(`
581
+ ([c, a]) => F({ name: c, version: a }, s)
582
+ ).map((c) => `<script src="${c}"><\/script>`).join(`
583
583
  `);
584
584
  n = W(
585
585
  n,
@@ -589,12 +589,12 @@ const st = ({
589
589
  );
590
590
  }
591
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, a = [...n.matchAll(i)];
593
- a.length === 1 && (() => {
594
- const l = a[0].index ?? -1;
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
595
  if (l === -1) return !1;
596
- const d = n.search(/<body\b[^>]*>/i), m = n.search(/<\/body>/i);
597
- return d !== -1 && m !== -1 && l > d && l < m;
596
+ const u = n.search(/<body\b[^>]*>/i), m = n.search(/<\/body>/i);
597
+ return u !== -1 && m !== -1 && l > u && l < m;
598
598
  })() || (n = n.replace(i, ""), n = W(n, "</body>", s));
599
599
  }
600
600
  return /^\s*<!DOCTYPE/i.test(n) ? n : `<!DOCTYPE html>${n}`;
@@ -620,10 +620,10 @@ const st = ({
620
620
  if (t[s])
621
621
  return p + s;
622
622
  const i = [".js", ".jsx", ".ts", ".tsx"];
623
- for (const a of i) {
624
- const c = s + a;
625
- if (t[c])
626
- return p + c;
623
+ for (const c of i) {
624
+ const a = s + c;
625
+ if (t[a])
626
+ return p + a;
627
627
  }
628
628
  }
629
629
  if (t[e])
@@ -644,36 +644,39 @@ const st = ({
644
644
  }
645
645
  return null;
646
646
  }
647
- }), ht = async ({
647
+ }), ft = async ({
648
648
  files: t,
649
649
  rollup: e,
650
650
  enableSourcemap: n = !0
651
651
  }) => {
652
- if (!t["index.js"])
653
- throw new Error("Missing index.js");
654
- const o = {
655
- input: "./index.js",
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,
656
659
  plugins: [z(t), C()],
657
- onwarn(l, d) {
658
- l.code !== "UNRESOLVED_IMPORT" && d(l);
660
+ onwarn(u, m) {
661
+ u.code !== "UNRESOLVED_IMPORT" && m(u);
659
662
  }
660
- }, s = {
663
+ }, i = {
661
664
  format: "iife",
662
665
  sourcemap: n
663
- }, i = S(t);
664
- if (i) {
665
- const l = U(i);
666
- l && (o.external = Object.keys(l), s.globals = l);
666
+ }, c = S(t);
667
+ if (c) {
668
+ const u = U(c);
669
+ u && (s.external = Object.keys(u), i.globals = u);
667
670
  }
668
- const a = await e(o), { output: c } = await a.generate(s);
669
- return c[0].code;
670
- }, ft = async ({
671
+ const a = await e(s), { output: l } = await a.generate(i);
672
+ return l[0].code;
673
+ }, ht = async ({
671
674
  files: t,
672
675
  rollup: e,
673
676
  enableSourcemap: n
674
677
  }) => ({
675
678
  ...t,
676
- "bundle.js": await ht({
679
+ "bundle.js": await ft({
677
680
  files: t,
678
681
  rollup: e,
679
682
  enableSourcemap: n
@@ -725,13 +728,13 @@ const st = ({
725
728
  // DEBUG && console.log("isExternal", isExternal);
726
729
  // return isExternal;
727
730
  // },
728
- onwarn(c, l) {
731
+ onwarn(a, l) {
729
732
  }
730
- }, i = await n(s), { output: a } = await i.generate({
733
+ }, i = await n(s), { output: c } = await i.generate({
731
734
  format: "es",
732
735
  sourcemap: r
733
736
  });
734
- return a[0].code;
737
+ return c[0].code;
735
738
  }, N = (t, e) => new RegExp(`<${e}\\b`, "i").test(t) && new RegExp(`</${e}>`, "i").test(t), xt = (t) => {
736
739
  const e = t.trim();
737
740
  return N(e, "html") && N(e, "head") && N(e, "body") ? e : `<html><head></head><body>${e}</body></html>`;
@@ -787,14 +790,14 @@ ${r}
787
790
  if (o.length === 0)
788
791
  return t;
789
792
  const s = /* @__PURE__ */ new Map();
790
- for (const a of o) {
791
- const c = await gt({
792
- entryPoint: a,
793
+ for (const c of o) {
794
+ const a = await gt({
795
+ entryPoint: c,
793
796
  files: t,
794
797
  rollup: e,
795
798
  enableSourcemap: n
796
799
  });
797
- s.set(a, c);
800
+ s.set(c, a);
798
801
  }
799
802
  const i = jt(t, s);
800
803
  return {
@@ -810,7 +813,7 @@ ${r}
810
813
  slugCache: s,
811
814
  getSvelteCompiler: i
812
815
  }) => {
813
- var a;
816
+ var c;
814
817
  try {
815
818
  if (g && console.log(
816
819
  "[build] files:",
@@ -824,26 +827,26 @@ ${r}
824
827
  "vizId is required when using vizCache"
825
828
  );
826
829
  if (!t && r && o && (t = A(
827
- (a = await r.get(o)) == null ? void 0 : a.files
830
+ (c = await r.get(o)) == null ? void 0 : c.files
828
831
  )), !t)
829
832
  throw new Error("Upable to extract viz files");
830
- const c = at(t);
831
- if (g && console.log("[build] version:", c), c === "v1")
833
+ const a = at(t);
834
+ if (g && console.log("[build] version:", a), a === "v1")
832
835
  return {
833
836
  html: $(t)
834
837
  };
835
- if (c === "v2") {
838
+ if (a === "v2") {
836
839
  if (!e)
837
840
  throw new Error(
838
841
  "Rollup is required for v2 runtime"
839
842
  );
840
843
  return {
841
844
  html: $(
842
- await ft({ files: t, rollup: e, enableSourcemap: n })
845
+ await ht({ files: t, rollup: e, enableSourcemap: n })
843
846
  )
844
847
  };
845
848
  }
846
- if (c === "v3") {
849
+ if (a === "v3") {
847
850
  if (!e)
848
851
  throw new Error(
849
852
  "Rollup is required for v3 runtime"
@@ -876,7 +879,7 @@ ${r}
876
879
  getSvelteCompiler: i
877
880
  });
878
881
  }
879
- if (c === "v4") {
882
+ if (a === "v4") {
880
883
  if (!e)
881
884
  throw new Error(
882
885
  "Rollup is required for v4 runtime"
@@ -892,13 +895,13 @@ ${r}
892
895
  };
893
896
  }
894
897
  throw new Error(
895
- `Unsupported runtime version: ${c}`
898
+ `Unsupported runtime version: ${a}`
896
899
  );
897
- } catch (c) {
898
- throw c instanceof Error && c.message.indexOf(p) && (c.message = c.message.replace(
900
+ } catch (a) {
901
+ throw a instanceof Error && a.message.indexOf(p) && (a.message = a.message.replace(
899
902
  p,
900
903
  ""
901
- )), c;
904
+ )), a;
902
905
  }
903
906
  };
904
907
  export {
@@ -912,4 +915,4 @@ export {
912
915
  Ct as s,
913
916
  ot as v
914
917
  };
915
- //# sourceMappingURL=build-H5Rfq113.js.map
918
+ //# sourceMappingURL=build-C3ij8Dz4.js.map