@vizhub/runtime 4.2.0 → 4.4.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 +20 -3
- package/dist/build/build.d.ts.map +1 -1
- package/dist/build-4ni0mWxG.cjs +317 -0
- package/dist/build-4ni0mWxG.cjs.map +1 -0
- package/dist/{build-DnPT2Qew.js → build-B7w6NcTo.js} +510 -299
- package/dist/build-B7w6NcTo.js.map +1 -0
- package/dist/common/imageSupport.d.ts +23 -0
- package/dist/common/imageSupport.d.ts.map +1 -0
- package/dist/common/imageSupport.test.d.ts +2 -0
- package/dist/common/imageSupport.test.d.ts.map +1 -0
- package/dist/common/runtimeErrorHandling.d.ts.map +1 -1
- package/dist/common/virtualFileSystem.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +55 -51
- package/dist/index.js.map +1 -1
- package/dist/orchestration/createRuntime.d.ts.map +1 -1
- package/dist/orchestration/types.d.ts +1 -0
- package/dist/orchestration/types.d.ts.map +1 -1
- package/dist/orchestration/worker.d.ts.map +1 -1
- package/dist/test/fixtures/v1/imageSupport.d.ts +18 -0
- package/dist/test/fixtures/v1/imageSupport.d.ts.map +1 -0
- package/dist/test/fixtures/v1/index.d.ts +1 -0
- package/dist/test/fixtures/v1/index.d.ts.map +1 -1
- package/dist/test/fixtures/v2/imageSupport.d.ts +13 -0
- package/dist/test/fixtures/v2/imageSupport.d.ts.map +1 -0
- 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/v3/basicIndexJSWithViz.d.ts +4 -0
- package/dist/test/fixtures/v3/basicIndexJSWithViz.d.ts.map +1 -0
- package/dist/test/fixtures/v3/index.d.ts +1 -0
- package/dist/test/fixtures/v3/index.d.ts.map +1 -1
- package/dist/test/imageSupport.test.d.ts +2 -0
- package/dist/test/imageSupport.test.d.ts.map +1 -0
- package/dist/test/v3BuildIntegrationViz.test.d.ts +2 -0
- package/dist/test/v3BuildIntegrationViz.test.d.ts.map +1 -0
- package/dist/test/v4HotReload.test.d.ts +2 -0
- package/dist/test/v4HotReload.test.d.ts.map +1 -0
- package/dist/test/v4HotReloadIntegration.test.d.ts +2 -0
- package/dist/test/v4HotReloadIntegration.test.d.ts.map +1 -0
- package/dist/test/vizExportSupport.test.d.ts +2 -0
- package/dist/test/vizExportSupport.test.d.ts.map +1 -0
- package/dist/test/vizPriorityTest.test.d.ts +2 -0
- package/dist/test/vizPriorityTest.test.d.ts.map +1 -0
- package/dist/v2/getComputedIndexHtml.d.ts.map +1 -1
- package/dist/v3/computeBundleJSV3.d.ts.map +1 -1
- package/dist/v3/transformSvelte.d.ts +1 -1
- package/dist/v3/transformSvelte.d.ts.map +1 -1
- package/dist/v3/vizLoad.d.ts.map +1 -1
- package/dist/v3/vizResolve.d.ts.map +1 -1
- package/dist/v4/extractEntryPoints.d.ts.map +1 -1
- package/dist/v4/hotReloadScript.d.ts +6 -0
- package/dist/v4/hotReloadScript.d.ts.map +1 -0
- package/dist/v4/index.d.ts +12 -0
- package/dist/v4/index.d.ts.map +1 -1
- package/dist/v4/updateHTML.d.ts +1 -1
- package/dist/v4/updateHTML.d.ts.map +1 -1
- package/dist/worker.cjs +1 -1
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.js +1 -1
- package/dist/worker.js.map +1 -1
- package/package.json +10 -10
- package/dist/build-BXOhZlRS.cjs +0 -256
- package/dist/build-BXOhZlRS.cjs.map +0 -1
- package/dist/build-DnPT2Qew.js.map +0 -1
package/README.md
CHANGED
@@ -28,7 +28,7 @@ The library automatically detects which runtime version to use based on the file
|
|
28
28
|
| **React JSX** | ⬜️ | ✅ | ⬜️ | ✅ |
|
29
29
|
| **Svelte** | ⬜️ | ⬜️ | ✅ | ⬜️ |
|
30
30
|
| **Cross-Viz Imports** | ⬜️ | ⬜️ | ✅ | ⬜️ |
|
31
|
-
| **Hot Reloading** | ⬜️ | ⬜️ | ✅ |
|
31
|
+
| **Hot Reloading** | ⬜️ | ⬜️ | ✅ | ✅ |
|
32
32
|
| **State Management** | ⬜️ | ⬜️ | ✅ | ⬜️ |
|
33
33
|
| **Import from CSV** | ⬜️ | ⬜️ | ✅ | ⬜️ |
|
34
34
|
| **TypeScript** | ⬜️ | ⬜️ | ⬜️ | ✅ |
|
@@ -304,18 +304,35 @@ V4 is ideal for modern browsers with native ES module support, TypeScript develo
|
|
304
304
|
- Import maps for direct CDN dependencies
|
305
305
|
- Native ES modules without bundling
|
306
306
|
- Local module imports with relative paths
|
307
|
+
- Hot reloading for fast development iteration
|
308
|
+
|
309
|
+
### V4 Hot Reloading
|
310
|
+
|
311
|
+
V4 runtime supports hot reloading similar to V3, allowing for rapid development cycles without full page refreshes. When `enableHotReloading` is set to `true`, the V4 runtime:
|
312
|
+
|
313
|
+
- Monitors code changes and re-bundles ES modules
|
314
|
+
- Sends updated JavaScript to the iframe via `runJS` messages
|
315
|
+
- Replaces existing module script tags with updated bundled code
|
316
|
+
- Preserves the current browser state where possible
|
317
|
+
|
318
|
+
The hot reloading system works by:
|
319
|
+
|
320
|
+
1. Bundling ES modules using Rollup (similar to V3)
|
321
|
+
2. Injecting a hot reload script that listens for update messages
|
322
|
+
3. Replacing module scripts dynamically when code changes
|
323
|
+
4. Re-executing the updated modules in the current context
|
324
|
+
|
325
|
+
Unlike V3's built-in state management, V4 hot reloading relies on the application's own state management (e.g., React state, DOM state) to preserve state between updates.
|
307
326
|
|
308
327
|
## Key Features
|
309
328
|
|
310
329
|
- **Multi-Version Runtime Support**
|
311
|
-
|
312
330
|
- **v1**: Simple HTML execution with fetch proxying
|
313
331
|
- **v2**: JavaScript bundling with Rollup, JSX support, and CDN-based dependency resolution
|
314
332
|
- **v3**: Advanced module bundling with Svelte support and cross-viz imports
|
315
333
|
- **v4**: Modern ES Modules with import maps for direct browser execution
|
316
334
|
|
317
335
|
- **Comprehensive Tooling**
|
318
|
-
|
319
336
|
- **Bundling**: Seamless integration with Rollup for module bundling
|
320
337
|
- **Transpilation**: Support for JSX (v2) and Svelte components (v3)
|
321
338
|
- **Dependency Management**: Automatic resolution via CDNs (jsDelivr/unpkg)
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/build/build.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACzD,OAAO,EAGL,SAAS,EACT,cAAc,EAEd,QAAQ,EACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AA+
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/build/build.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACzD,OAAO,EAGL,SAAS,EACT,cAAc,EAEd,QAAQ,EACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AA+DtC,eAAO,MAAM,KAAK,GAAU,oFAQzB;IAGD,KAAK,CAAC,EAAE,cAAc,CAAC;IAGvB,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;IAQ1D,eAAe,CAAC,EAAE,OAAO,CAAC;IAI1B,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAGpB,KAAK,CAAC,EAAE,MAAM,CAAC;IAGf,SAAS,CAAC,EAAE,SAAS,CAAC;IAGtB,iBAAiB,CAAC,EAAE,MAAM,OAAO,CAAC,cAAc,CAAC,CAAC;CACnD,KAAG,OAAO,CAAC,WAAW,CA0JtB,CAAC"}
|
@@ -0,0 +1,317 @@
|
|
1
|
+
"use strict";const R=require("magic-sandbox"),x=require("@vizhub/viz-utils"),ne=require("sucrase"),re=()=>(Math.random()+"").slice(2);function F(e={}){return{name:"sucrase",transform(t,n){if(!n.match(/\.(?:js|[jt]sx)$/))return null;const r=ne.transform(t,{transforms:["jsx","typescript"],filePath:n,sourceMapOptions:{compiledFilename:"bundle.js"},production:!0,...e});return{code:r.code,map:r.sourceMap}}}}const D={dependencies:{},vizhub:{},license:"MIT"},se=!1,j=e=>{const t=e["package.json"];try{const n=t?JSON.parse(t):D;return se&&console.log("[packageJSON] pkg:",JSON.stringify(n,null,2)),n}catch{return D}},U=e=>j(e).dependencies||{},W=e=>(j(e).vizhub||{}).libraries||{},z=({name:e,version:t},n,r="jsdelivr")=>{const s=n[e]&&n[e].path||"";return r==="jsdelivr"?`https://cdn.jsdelivr.net/npm/${e}@${t}${s}`:`https://unpkg.com/${e}@${t}${s}`},oe=e=>{const t=e?.vizhub?.libraries;return t?Object.entries(t).reduce((n,[r,s])=>(s.global&&(n[r]=s.global),n),{}):{}},ie={d3:"d3",react:"React","react-dom":"ReactDOM"},G=e=>{const t=oe(e);return{...ie,...t}},$=e=>{const[t,...n]=e.split("/"),r=n.join("/");return{vizId:t,fileName:r}},ce=`var EOL = {},
|
2
|
+
EOF = {},
|
3
|
+
QUOTE = 34,
|
4
|
+
NEWLINE = 10,
|
5
|
+
RETURN = 13;
|
6
|
+
|
7
|
+
function objectConverter(columns) {
|
8
|
+
return new Function(
|
9
|
+
'd',
|
10
|
+
'return {' +
|
11
|
+
columns
|
12
|
+
.map(function (name, i) {
|
13
|
+
return (
|
14
|
+
JSON.stringify(name) + ': d[' + i + '] || ""'
|
15
|
+
);
|
16
|
+
})
|
17
|
+
.join(',') +
|
18
|
+
'}',
|
19
|
+
);
|
20
|
+
}
|
21
|
+
|
22
|
+
function customConverter(columns, f) {
|
23
|
+
var object = objectConverter(columns);
|
24
|
+
return function (row, i) {
|
25
|
+
return f(object(row), i, columns);
|
26
|
+
};
|
27
|
+
}
|
28
|
+
|
29
|
+
function dsv(delimiter) {
|
30
|
+
var DELIMITER = delimiter.charCodeAt(0);
|
31
|
+
|
32
|
+
function parse(text, f) {
|
33
|
+
var convert,
|
34
|
+
columns,
|
35
|
+
rows = parseRows(text, function (row, i) {
|
36
|
+
if (convert) return convert(row, i - 1);
|
37
|
+
(columns = row),
|
38
|
+
(convert = f
|
39
|
+
? customConverter(row, f)
|
40
|
+
: objectConverter(row));
|
41
|
+
});
|
42
|
+
rows.columns = columns || [];
|
43
|
+
return rows;
|
44
|
+
}
|
45
|
+
|
46
|
+
function parseRows(text, f) {
|
47
|
+
var rows = [], // output rows
|
48
|
+
N = text.length,
|
49
|
+
I = 0, // current character index
|
50
|
+
n = 0, // current line number
|
51
|
+
t, // current token
|
52
|
+
eof = N <= 0, // current token followed by EOF?
|
53
|
+
eol = false; // current token followed by EOL?
|
54
|
+
|
55
|
+
// Strip the trailing newline.
|
56
|
+
if (text.charCodeAt(N - 1) === NEWLINE) --N;
|
57
|
+
if (text.charCodeAt(N - 1) === RETURN) --N;
|
58
|
+
|
59
|
+
function token() {
|
60
|
+
if (eof) return EOF;
|
61
|
+
if (eol) return (eol = false), EOL;
|
62
|
+
|
63
|
+
// Unescape quotes.
|
64
|
+
var i,
|
65
|
+
j = I,
|
66
|
+
c;
|
67
|
+
if (text.charCodeAt(j) === QUOTE) {
|
68
|
+
while (
|
69
|
+
(I++ < N && text.charCodeAt(I) !== QUOTE) ||
|
70
|
+
text.charCodeAt(++I) === QUOTE
|
71
|
+
);
|
72
|
+
if ((i = I) >= N) eof = true;
|
73
|
+
else if ((c = text.charCodeAt(I++)) === NEWLINE)
|
74
|
+
eol = true;
|
75
|
+
else if (c === RETURN) {
|
76
|
+
eol = true;
|
77
|
+
if (text.charCodeAt(I) === NEWLINE) ++I;
|
78
|
+
}
|
79
|
+
return text.slice(j + 1, i - 1).replace(/""/g, '"');
|
80
|
+
}
|
81
|
+
|
82
|
+
// Find next delimiter or newline.
|
83
|
+
while (I < N) {
|
84
|
+
if ((c = text.charCodeAt((i = I++))) === NEWLINE)
|
85
|
+
eol = true;
|
86
|
+
else if (c === RETURN) {
|
87
|
+
eol = true;
|
88
|
+
if (text.charCodeAt(I) === NEWLINE) ++I;
|
89
|
+
} else if (c !== DELIMITER) continue;
|
90
|
+
return text.slice(j, i);
|
91
|
+
}
|
92
|
+
|
93
|
+
// Return last token before EOF.
|
94
|
+
return (eof = true), text.slice(j, N);
|
95
|
+
}
|
96
|
+
|
97
|
+
while ((t = token()) !== EOF) {
|
98
|
+
var row = [];
|
99
|
+
while (t !== EOL && t !== EOF)
|
100
|
+
row.push(t), (t = token());
|
101
|
+
if (f && (row = f(row, n++)) == null) continue;
|
102
|
+
rows.push(row);
|
103
|
+
}
|
104
|
+
|
105
|
+
return rows;
|
106
|
+
}
|
107
|
+
|
108
|
+
return {
|
109
|
+
parse: parse,
|
110
|
+
};
|
111
|
+
}
|
112
|
+
|
113
|
+
var csv = dsv(',');
|
114
|
+
|
115
|
+
var csvParse = csv.parse;
|
116
|
+
|
117
|
+
var tsv = dsv(' ');
|
118
|
+
|
119
|
+
var tsvParse = tsv.parse;
|
120
|
+
|
121
|
+
export { csvParse, tsvParse };`,ae=e=>e.replace(/\\/g,"\\\\").replace(/`/g,"\\`"),de=()=>({name:"transformDSV",transform:async(e,t)=>{const{fileName:n}=$(t),r=n.endsWith(".csv"),s=n.endsWith(".tsv");if(r||s)return{code:`
|
122
|
+
${ce}
|
123
|
+
const data = ${r?"csvParse":"tsvParse"}(\`${ae(e)}\`);
|
124
|
+
export default data;
|
125
|
+
`,map:{mappings:""}}}}),le=e=>{const t=/^@([a-zA-Z0-9_-]+)\/([a-zA-Z0-9_-]+)$/,n=e.match(t);return n?{userName:n[1],idOrSlug:n[2]}:null},ue=({vizId:e,slugCache:t})=>({name:"vizResolve",resolveId:async(n,r)=>{if(n.startsWith("./")&&!r?.startsWith("https://")){let o=n.substring(2);if(!o.endsWith(".js")&&!o.endsWith(".css")&&!o.endsWith(".csv")&&!o.endsWith(".svelte")&&!o.endsWith(".png")&&!o.endsWith(".jpg")&&!o.endsWith(".jpeg")&&!o.endsWith(".gif")&&!o.endsWith(".svg")&&!o.endsWith(".webp")&&!o.endsWith(".bmp")&&(o+=".js"),r){const{vizId:c,fileName:i}=$(r),a=i.split("/").slice(0,-1).join("/"),d=a?`${a}/${o}`:o;return`${c}/${d}`}return e+"/"+o}const s=le(n);if(s){let o;if(x.isVizId(s.idOrSlug))o=s.idOrSlug;else{if(!t)throw new Error("slugCache is required to import by slug in v3 runtime");o=await t.get(`${s.userName}/${s.idOrSlug}`)}return o+"/index.js"}}}),pe=[".jpg",".jpeg",".png",".gif",".svg",".webp",".bmp"],J=e=>{const t=e.toLowerCase().split(".").pop();return t?pe.includes(`.${t}`):!1},me=e=>{switch(e.toLowerCase().split(".").pop()){case"jpg":case"jpeg":return"image/jpeg";case"png":return"image/png";case"gif":return"image/gif";case"svg":return"image/svg+xml";case"webp":return"image/webp";case"bmp":return"image/bmp";default:return"image/png"}},fe=e=>{const t=e.replace(/\s/g,"");return/^[A-Za-z0-9+/]*={0,2}$/.test(t)},P=(e,t)=>{const n=me(e);return e.toLowerCase().split(".").pop()==="svg"&&!fe(t)?`data:${n};utf8,${encodeURIComponent(t)}`:`data:${n};base64,${t}`},he=(e,t)=>e.replace(/<img([^>]*)\s+src=["']([^"']+)["']([^>]*)>/gi,(n,r,s,o)=>{if(t[s]!==void 0&&J(s)){const c=P(s,t[s]);return`<img${r} src="${c}"${o}>`}return n}),ge=({vizCache:e,trackCSSImport:t,vizId:n,files:r})=>({name:"vizLoad",load:async s=>{const o=$(s),c=o.vizId,i=o.fileName;if(i.endsWith(".css"))return t(s),"";let a=null;if(c===n&&r)a=r[i]||null;else{const d=await e.get(c);a=x.getFileText(d,i)}if(a===null)throw new Error(`Imported file "${i}" not found.`);return J(i)?`export default "${P(i,a)}";`:a}}),A=new Map,I=new Map;let O;const y="https://cdn.jsdelivr.net/npm/svelte@5.37.1",ve=`${y}/compiler/index.js`;async function B(e){const t=I.get(e);if(t)return t;const n=[".js","/index.js"];for(const s of n){const o=`${e}${s}`;try{if((await fetch(o,{method:"HEAD"})).ok)return I.set(e,o),o}catch{continue}}const r=`${e}.js`;return I.set(e,r),r}const we=({getSvelteCompiler:e})=>({name:"transformSvelte",load:async t=>{if(t==="virtual:esm-env")return`
|
126
|
+
export const BROWSER = true;
|
127
|
+
export const DEV = true;
|
128
|
+
export const NODE = false;
|
129
|
+
export const PROD = false;
|
130
|
+
`;if(!t.startsWith(y))return;const n=A.get(t);if(n)return n;const r=await fetch(t).then(s=>s.text());return A.set(t,r),r},resolveId:async(t,n)=>{if(t==="esm-env")return"virtual:esm-env";if(t==="svelte")return`${y}/src/index-client.js`;if(t.startsWith("svelte/")){const r=t.slice(7),s=`${y}/src/${r}`;return await B(s)}if(t.startsWith("#client/")){const r=t.slice(8),s=`${y}/src/internal/client/${r}`;return await B(s)}if(/^https?:/.test(t))return t;if(t.startsWith(".")&&n&&n.startsWith(y)){const r=new URL(t,n).href;return new URL(t,n).href,r}},transform:async(t,n)=>{const{fileName:r}=$(n);if(r.endsWith(".svelte")){if(!O){if(!e)throw new Error("Svelte compiler not available");O=await e()}const o=O(t,{filename:r,generate:"client",css:"external",dev:!1});let c=o.js.code;return o.css&&o.css.code&&(c=`
|
131
|
+
// Auto-inject CSS for Svelte component
|
132
|
+
(function() {
|
133
|
+
if (typeof document !== 'undefined') {
|
134
|
+
const style = document.createElement('style');
|
135
|
+
style.textContent = ${JSON.stringify(o.css.code)};
|
136
|
+
document.head.appendChild(style);
|
137
|
+
}
|
138
|
+
})();
|
139
|
+
`+c),c}}}),Y=async({files:e,rollup:t,enableSourcemap:n=!0,vizCache:r,vizId:s,slugCache:o,getSvelteCompiler:c})=>{const i=new Set,a=p=>{i.add(p)};if(!e["index.js"])throw new Error("Missing index.js");const l={name:"replace",transform(p,w){let b=!1,f=p;return f.includes("process.env.NODE_ENV")&&(f=f.replace(/\bprocess\.env\.NODE_ENV\b/g,JSON.stringify("production")),b=!0),b?{code:f,map:null}:null}},u={input:"./index.js",plugins:[...s?[ue({vizId:s,slugCache:o})]:[],de(),F(),we({getSvelteCompiler:c}),l,...r?[ge({vizCache:r,trackCSSImport:a,vizId:s,files:e})]:[]],onwarn(p,w){p.code!=="UNRESOLVED_IMPORT"&&w(p)}},m={format:"umd",name:"Viz",sourcemap:!!n,compact:!0},g=j(e);if(g){const p=G(g);p&&(u.external=Object.keys(p),m.globals=p)}u.external||(u.external=[]),m.globals||(m.globals={}),Array.isArray(u.external)&&(u.external=u.external.filter(p=>typeof p=="string"&&!p.startsWith("#client/")));const v=await t(u),{output:E}=await v.generate(m);return{src:E[0].code,cssFiles:Array.from(i)}},be=e=>{if(e instanceof Error){const t=e.stack||"",n=e.message||"Unknown error";return`${e.name||"Error"}: ${n}
|
140
|
+
${t}`}else if("error"in e&&e.error instanceof Error){const t=e.error,n=t.stack||"",r=t.message||"Unknown error",s="filename"in e?e.filename:"",o="lineno"in e?e.lineno:"",c="colno"in e?e.colno:"";let i="";return s&&o&&(i=` at ${s}:${o}`,c&&(i+=`:${c}`)),`${t.name||"Error"}: ${r}${i}
|
141
|
+
${n}`}else if("reason"in e){const t=e.reason;if(t instanceof Error){const n=t.stack||"",r=t.message||"Unknown error";return`Unhandled Promise Rejection - ${t.name||"Error"}: ${r}
|
142
|
+
${n}`}else return`Unhandled Promise Rejection: ${String(t)}`}else return`Unknown runtime error: ${String(e)}`},C=()=>`
|
143
|
+
// Global error handling for runtime errors
|
144
|
+
(() => {
|
145
|
+
const formatRuntimeError = ${be.toString()};
|
146
|
+
|
147
|
+
// Handle uncaught JavaScript errors
|
148
|
+
window.addEventListener('error', (event) => {
|
149
|
+
const formattedErrorMessage = formatRuntimeError(event);
|
150
|
+
parent.postMessage({
|
151
|
+
type: 'runtimeError',
|
152
|
+
formattedErrorMessage
|
153
|
+
}, "*");
|
154
|
+
});
|
155
|
+
|
156
|
+
// Handle unhandled promise rejections
|
157
|
+
window.addEventListener('unhandledrejection', (event) => {
|
158
|
+
const formattedErrorMessage = formatRuntimeError(event);
|
159
|
+
parent.postMessage({
|
160
|
+
type: 'runtimeError',
|
161
|
+
formattedErrorMessage
|
162
|
+
}, "*");
|
163
|
+
});
|
164
|
+
})();
|
165
|
+
`;function ye(){return Math.random().toString().slice(2,7)}const xe=({cdn:e,src:t,styles:n})=>{const s=`viz-container-${ye()}`;return`<!DOCTYPE html>
|
166
|
+
<html>
|
167
|
+
<head>
|
168
|
+
<meta charset="utf-8">${e}${n}
|
169
|
+
<style>
|
170
|
+
body {
|
171
|
+
margin: 0;
|
172
|
+
overflow: hidden;
|
173
|
+
}
|
174
|
+
#${s} {
|
175
|
+
height: 100vh;
|
176
|
+
}
|
177
|
+
</style>
|
178
|
+
</head>
|
179
|
+
<body>
|
180
|
+
<div id="${s}"></div>
|
181
|
+
<script>${C()}<\/script>
|
182
|
+
<script id="injected-script">${t}<\/script>
|
183
|
+
<script>
|
184
|
+
(() => {
|
185
|
+
let cleanup;
|
186
|
+
const render = () => {
|
187
|
+
const container = document.getElementById('${s}');
|
188
|
+
typeof cleanup === 'function' && cleanup();
|
189
|
+
cleanup = (Viz.viz || Viz.main)(container, { state: window.state, setState, writeFile });
|
190
|
+
};
|
191
|
+
const setState = (next) => {
|
192
|
+
window.state = next(window.state);
|
193
|
+
render();
|
194
|
+
};
|
195
|
+
const writeFile = (fileName, content) => {
|
196
|
+
parent.postMessage({ type: 'writeFile', fileName, content }, "*");
|
197
|
+
};
|
198
|
+
const run = () => {
|
199
|
+
try {
|
200
|
+
setState((state) => state || {});
|
201
|
+
} catch (error) {
|
202
|
+
console.error(error);
|
203
|
+
parent.postMessage({ type: 'runError', error }, "*");
|
204
|
+
}
|
205
|
+
}
|
206
|
+
run();
|
207
|
+
const runJS = (src) => {
|
208
|
+
document.getElementById('injected-script')?.remove();
|
209
|
+
const script = document.createElement('script');
|
210
|
+
script.textContent = src;
|
211
|
+
script.id = 'injected-script';
|
212
|
+
document.body.appendChild(script);
|
213
|
+
run();
|
214
|
+
};
|
215
|
+
const runCSS = (css) => {
|
216
|
+
let style = document.getElementById('injected-style');
|
217
|
+
if (!style) {
|
218
|
+
style = document.createElement('style');
|
219
|
+
style.type = 'text/css';
|
220
|
+
style.id = 'injected-style';
|
221
|
+
document.head.appendChild(style);
|
222
|
+
}
|
223
|
+
style.textContent = css;
|
224
|
+
};
|
225
|
+
onmessage = (message) => {
|
226
|
+
switch (message.data.type) {
|
227
|
+
case 'runJS':
|
228
|
+
runJS(message.data.js);
|
229
|
+
parent.postMessage({ type: 'runDone' }, "*");
|
230
|
+
break;
|
231
|
+
case 'runCSS':
|
232
|
+
runCSS(message.data.css);
|
233
|
+
break;
|
234
|
+
case 'ping':
|
235
|
+
parent.postMessage({ type: 'pong' }, "*");
|
236
|
+
break;
|
237
|
+
default:
|
238
|
+
break;
|
239
|
+
}
|
240
|
+
}
|
241
|
+
})();
|
242
|
+
<\/script>
|
243
|
+
</body>
|
244
|
+
</html>`},Q=async({files:e,rollup:t,enableSourcemap:n=!0,vizCache:r,vizId:s,slugCache:o,getSvelteCompiler:c})=>{const{src:i,cssFiles:a}=await Y({files:e,rollup:t,enableSourcemap:n,vizCache:r,vizId:s,slugCache:o,getSvelteCompiler:c});let d=[];if(a.length>0)for(let v=0;v<a.length;v++){const E=a[v],p=$(E),w=p.vizId,b=p.fileName;let f=null;if(w===s&&e)f=e[b]||null;else{const te=await r.get(w);f=x.getFileText(te,b)}f&&d.push(f)}const l=d.join(`
|
245
|
+
`),u=`
|
246
|
+
<style id="injected-style">${l}</style>`;let m="";const g=Object.entries(U(e));if(g.length>0){const v=W(e);m=g.map(([E,p],w)=>{const b=z({name:E,version:p},v);return`${w>0?" ":`
|
247
|
+
`}<script src="${b}"><\/script>`}).join("")}return{html:xe({cdn:m,src:i,styles:u}),css:l,js:i,runtimeVersion:"v3"}},X=({initialContents:e,handleCacheMiss:t})=>{const n=new Map(e.map(c=>[c.id,c]));return{get:async c=>{const i=n.get(c);if(i!==void 0)return i;if(!t)throw new Error(`Unresolved import from vizId ${c}, cache miss handler not provided.`);const a=await t(c);if(a)return n.set(c,a),a;throw new Error(`Unresolved import from vizId ${c}`)},set:c=>{n.set(c.id,c)},invalidate:c=>{n.delete(c)}}},Ee=({initialMappings:e={},handleCacheMiss:t})=>({get:async o=>{const c=e[o];if(c!==void 0)return c;if(!t)throw new Error(`Unresolved slug ${o}, cache miss handler not provided.`);const i=await t(o);if(i)return e[o]=i,i;throw new Error(`Unresolved slug ${o}`)},set:(o,c)=>{e[o]=c},invalidate:o=>{delete e[o]}}),Z=(e,t="Sample Content for Exporting",n=x.generateVizId())=>({id:n,files:x.fileCollectionToVizFiles(e),title:t}),K=e=>{if(Object.keys(e).length===0)return null;const t="index.html"in e,n="index.js"in e,r="index.jsx"in e;return t?e["index.html"].includes('type="module"')?"v4":n||r?"v2":"v1":!t&&n?"v3":null},N=(e,t)=>new RegExp(`<${t}\\b`,"i").test(e)&&new RegExp(`</${t}>`,"i").test(e),Se=e=>{const t=e.trim();return N(t,"html")&&N(t,"head")&&N(t,"body")?t:`<html><head></head><body>${t}</body></html>`},$e=(e,t)=>e.replace(new RegExp(`<script[^>]*src=["'][^"']*${t.source}[^"']*["'][^>]*>\\s*<\/script>`,"gi"),""),T=(e,t,n)=>e.replace(new RegExp(t,"i"),`${n}${t}`),je=(e,t)=>{let n=Se(e);const r=Object.entries(U(t));if(r.length){const c=W(t);r.forEach(([a])=>{n=$e(n,new RegExp(`${a}@`))});const i=r.map(([a,d])=>z({name:a,version:d},c)).map(a=>`<script src="${a}"><\/script>`).join(`
|
248
|
+
`);n=T(n,"</head>",i+`
|
249
|
+
`)}if(t["bundle.js"]!==void 0||t["index.js"]!==void 0){const c='<script src="bundle.js"><\/script>',i=/<script\b[^>]*\bsrc=["']bundle\.js["'][^>]*>\s*<\/script>/gi,a=[...n.matchAll(i)];a.length===1&&(()=>{const l=a[0].index??-1;if(l===-1)return!1;const u=n.search(/<body\b[^>]*>/i),m=n.search(/<\/body>/i);return u!==-1&&m!==-1&&l>u&&l<m})()||(n=n.replace(i,""),n=T(n,"</body>",c))}const o=`<script>${C()}<\/script>
|
250
|
+
`;return n=T(n,"</head>",o),/^\s*<!DOCTYPE/i.test(n)?n:`<!DOCTYPE html>${n}`},Ce=e=>{const t=e["index.html"];return!t&&!e["index.js"]&&!e["bundle.js"]?"":je(t||"<!DOCTYPE html><html><head></head><body></body></html>",e)};function Re(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var k,q;function Ie(){return q||(q=1,k={d3:"d3","d3-array":"d3","d3-axis":"d3","d3-brush":"d3","d3-chord":"d3","d3-collection":"d3","d3-color":"d3","d3-contour":"d3","d3-dispatch":"d3","d3-drag":"d3","d3-dsv":"d3","d3-ease":"d3","d3-fetch":"d3","d3-force":"d3","d3-format":"d3","d3-geo":"d3","d3-hierarchy":"d3","d3-interpolate":"d3","d3-path":"d3","d3-polygon":"d3","d3-quadtree":"d3","d3-random":"d3","d3-scale":"d3","d3-scale-chromatic":"d3","d3-selection":"d3","d3-shape":"d3","d3-tile":"d3","d3-time":"d3","d3-time-format":"d3","d3-timer":"d3","d3-transition":"d3","d3-voronoi":"d3","d3-zoom":"d3",react:"React","react-dom":"ReactDOM","react-dropdown-browser":"ReactDropdown","react-dropdown":"ReactDropdown",three:"THREE",vega:"vega","vega-embed":"vegaEmbed","vega-lite":"vegaLite","vega-lite-api":"vl","vega-tooltip":"vegaTooltip","vega-themes":"vegaThemes","vizhub-vega-lite-config":"vizhubVegaLiteConfig",semiotic:"Semiotic","viz.js":"Viz"}),k}var Oe=Ie();const Ne=Re(Oe),h="\0virtual:",H=e=>{let t=e.replace(/^\.\//,"");return t=t.replace(/\/+/g,"/"),t=t.replace(/\/$/,""),t},Te=(e,t)=>{const n=e.includes("/")?e.slice(0,e.lastIndexOf("/")):"",r=t.split("/"),s=n?n.split("/"):[];for(const o of r)o===".."?s.pop():o!=="."&&o!==""&&s.push(o);return s.join("/")},ee=e=>({name:"virtual-file-system",resolveId(t,n){const r=n?.startsWith(h)?n.slice(h.length):n;if(t.startsWith("./")||t.startsWith("../")){const o=H(r?Te(r,t):t);if(e[o])return h+o;const c=[".js",".jsx",".ts",".tsx"];for(const i of c){const a=o+i;if(e[a])return h+a}}if(e[t])return h+t;const s=[".js",".jsx",".ts",".tsx"];for(const o of s){const c=t+o;if(e[c])return h+c}return null},load(t){if(t.startsWith(h)){const n=t.slice(h.length);if(e[n])return J(n)?`export default "${P(n,e[n])}";`:e[n]}return null}}),ke=async({files:e,rollup:t,enableSourcemap:n=!0})=>{let r="index.js";if(!e[r]&&(r="index.jsx",!e[r]))throw new Error("Missing entry point, can't find index.js or index.jsx");const o={input:"./"+r,plugins:[ee(e),F()],onwarn(l,u){l.code!=="UNRESOLVED_IMPORT"&&u(l)}},c={format:"iife",sourcemap:n},i=j(e);if(i){const l={...Ne,...G(i)};l&&(o.external=Object.keys(l),c.globals=l)}const a=await t(o),{output:d}=await a.generate(c);return d[0].code},Le=async({files:e,rollup:t,enableSourcemap:n})=>({...e,"bundle.js":await ke({files:e,rollup:t,enableSourcemap:n}),"index.html":Ce(e)}),Me=e=>{const t=[],n=[],r=/<script\b([^>]*)>([\s\S]*?)<\/script>/gi;let s,o=0;for(;(s=r.exec(e))!==null;){const c=s[1],i=s[2];if(!/\btype\s*=\s*["']module["']/i.test(c))continue;const a=c.match(/\bsrc\s*=\s*["']([^"']+)["']/i);if(a)t.push(a[1]);else if(i.trim()){const d=`__inline_script_${o++}.js`;n.push({id:d,content:i.trim()}),t.push(d)}}return{entryPoints:t,inlineScripts:n}},Ve=()=>({name:"catch-all-prevent-fs",resolveId(e,t){return{id:e,external:!0}}}),Fe=async({entryPoint:e,files:t,rollup:n,enableSourcemap:r=!0})=>{const o={input:e.startsWith("./")?e:`./${e}`,plugins:[ee(t),F({jsxRuntime:"automatic"}),Ve()],onwarn(a,d){}},c=await n(o),{output:i}=await c.generate({format:"es",sourcemap:r});return i[0].code},L=(e,t)=>new RegExp(`<${t}\\b`,"i").test(e)&&new RegExp(`</${t}>`,"i").test(e),Ue=e=>{const t=e.trim();return L(t,"html")&&L(t,"head")&&L(t,"body")?t:`<html><head></head><body>${t}</body></html>`},_=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),M=(e,t,n)=>e.replace(new RegExp(t,"i"),`${n}${t}`),We=e=>{const t=U(e);if(Object.keys(t).length===0)return null;const n=W(e),r={};for(const[s,o]of Object.entries(t))r[s]=z({name:s,version:o},n);return JSON.stringify({imports:r},null,2)},ze=()=>`
|
251
|
+
// V4 Hot Reloading Support
|
252
|
+
(() => {
|
253
|
+
const runJS = (js) => {
|
254
|
+
// Remove all existing bundled module scripts
|
255
|
+
const existingScripts = document.querySelectorAll('script[type="module"]');
|
256
|
+
existingScripts.forEach(script => {
|
257
|
+
// Only remove scripts that contain bundled code (not import maps or external scripts)
|
258
|
+
if (script.textContent && script.textContent.trim()) {
|
259
|
+
script.remove();
|
260
|
+
}
|
261
|
+
});
|
262
|
+
|
263
|
+
// Create new script with updated bundled code
|
264
|
+
const script = document.createElement('script');
|
265
|
+
script.type = 'module';
|
266
|
+
script.textContent = js;
|
267
|
+
document.body.appendChild(script);
|
268
|
+
};
|
269
|
+
|
270
|
+
const runCSS = (css) => {
|
271
|
+
let style = document.getElementById('v4-injected-style');
|
272
|
+
if (!style) {
|
273
|
+
style = document.createElement('style');
|
274
|
+
style.type = 'text/css';
|
275
|
+
style.id = 'v4-injected-style';
|
276
|
+
document.head.appendChild(style);
|
277
|
+
}
|
278
|
+
style.textContent = css;
|
279
|
+
};
|
280
|
+
|
281
|
+
// Listen for hot reload messages
|
282
|
+
window.addEventListener('message', (message) => {
|
283
|
+
switch (message.data.type) {
|
284
|
+
case 'runJS':
|
285
|
+
try {
|
286
|
+
runJS(message.data.js);
|
287
|
+
parent.postMessage({ type: 'runDone' }, "*");
|
288
|
+
} catch (error) {
|
289
|
+
console.error('V4 Hot reload error:', error);
|
290
|
+
parent.postMessage({ type: 'runError', error }, "*");
|
291
|
+
}
|
292
|
+
break;
|
293
|
+
case 'runCSS':
|
294
|
+
runCSS(message.data.css);
|
295
|
+
break;
|
296
|
+
case 'ping':
|
297
|
+
parent.postMessage({ type: 'pong' }, "*");
|
298
|
+
break;
|
299
|
+
default:
|
300
|
+
break;
|
301
|
+
}
|
302
|
+
});
|
303
|
+
})();
|
304
|
+
`,Je=(e,t,n=[],r=!1)=>{if(!e["index.html"])return"";let s=Ue(e["index.html"]);t.forEach((i,a)=>{if(n.some(l=>l.id===a)){const l=n.find(g=>g.id===a)?.content||"",u=_(l),m=new RegExp(`<script\\b[^>]*\\btype=["']module["'][^>]*>\\s*${u}\\s*<\/script>`,"gi");s=s.replace(m,`<script type="module">
|
305
|
+
${i}
|
306
|
+
<\/script>`)}else{const l=new RegExp(`<script\\b[^>]*\\bsrc=["']${_(a)}["'][^>]*>[^<]*<\/script>`,"gi");s=s.replace(l,`<script type="module">
|
307
|
+
${i}
|
308
|
+
<\/script>`)}});const o=We(e);if(o&&!/<script\b[^>]*type=["']importmap["'][^>]*>/i.test(s)){const a=`<script type="importmap">
|
309
|
+
${o}
|
310
|
+
<\/script>
|
311
|
+
`;s=M(s,"</head>",a)}const c=`<script>${C()}<\/script>
|
312
|
+
`;if(s=M(s,"</head>",c),r){const i=`<script>${ze()}<\/script>
|
313
|
+
`;s=M(s,"</body>",i)}return/^\s*<!DOCTYPE/i.test(s)?s:`<!DOCTYPE html>${s}`},Pe=async({files:e,rollup:t,enableSourcemap:n=!0})=>{const r=e["index.html"]||"",{entryPoints:s,inlineScripts:o}=Me(r);if(s.length===0)return{files:e,bundledJS:""};const c={...e};for(const u of o)c[u.id]=u.content;const i=new Map,a=[];for(const u of s){const m=await Fe({entryPoint:u,files:c,rollup:t,enableSourcemap:n});i.set(u,m),a.push(m)}const d=Je(c,i,o,!0),l=a.join(`
|
314
|
+
`);return{files:{...e,"index.html":d},bundledJS:l}},S=!1,De=e=>{const t=`<script>${C()}<\/script>`;return e.includes("</head>")?e.replace("</head>",`${t}
|
315
|
+
</head>`):e.includes("</body>")?e.replace("</body>",`${t}
|
316
|
+
</body>`):e+t},V=e=>{const t={...e};for(const[n,r]of Object.entries(t))n.toLowerCase().endsWith(".html")&&(t[n]=he(r,e));return t},Ae=async({files:e,rollup:t,enableSourcemap:n=!0,vizCache:r,vizId:s,slugCache:o,getSvelteCompiler:c})=>{try{if(S&&console.log("[build] files:",e?JSON.stringify(e).substring(0,100):void 0),S&&console.log("[build] vizCache:",r),S&&console.log("[build] vizId:",s),!e&&!r)throw new Error("Either files or vizCache is required");if(!e&&r&&!s)throw new Error("vizId is required when using vizCache");if(!e&&r&&s&&(e=x.vizFilesToFileCollection((await r.get(s))?.files)),!e)throw new Error("Upable to extract viz files");const i=K(e);if(S&&console.log("[build] version:",i),i==="v1"){const a=V(e);return{html:De(R.magicSandbox(a)),runtimeVersion:i}}if(i==="v2"){if(!t)throw new Error("Rollup is required for v2 runtime");const a=await Le({files:e,rollup:t,enableSourcemap:n}),d=V(a);return{html:R.magicSandbox(d),runtimeVersion:i}}if(i==="v3"){if(!t)throw new Error("Rollup is required for v3 runtime");if(!r&&!s){const a=Z(e);s=a.id,r=X({initialContents:[a],handleCacheMiss:async()=>{throw new Error("Cache miss handler not implemented")}})}if(!r)throw new Error("vizCache is required for v3 runtime");if(!s)throw new Error("vizId is required for v3 runtime if vizCache is provided");return await Q({files:e,rollup:t,vizCache:r,vizId:s,slugCache:o,getSvelteCompiler:c})}if(i==="v4"){if(!t)throw new Error("Rollup is required for v4 runtime");S&&console.log("[build] v4Build",{files:e,rollup:t,enableSourcemap:n});const a=await Pe({files:e,rollup:t,enableSourcemap:n}),d=V(a.files);return{html:R.magicSandbox(d),js:a.bundledJS,runtimeVersion:i}}throw new Error(`Unsupported runtime version: ${i}`)}catch(i){throw i instanceof Error&&i.message.indexOf(h)&&(i.message=i.message.replace(h,"")),i}};exports.build=Ae;exports.computeBundleJSV3=Y;exports.createSlugCache=Ee;exports.createVizCache=X;exports.createVizContent=Z;exports.determineRuntimeVersion=K;exports.generateRequestId=re;exports.svelteCompilerUrl=ve;exports.v3Build=Q;
|
317
|
+
//# sourceMappingURL=build-4ni0mWxG.cjs.map
|