@vroomchart/core-wasm 0.3.0 → 0.5.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 +56 -1
- package/assets/vroom_core.mjs +1 -1
- package/assets/vroom_core.wasm +0 -0
- package/dist/index.d.ts +80 -16
- package/dist/index.js +44 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,2 +1,57 @@
|
|
|
1
|
-
# core-wasm
|
|
1
|
+
# @vroomchart/core-wasm
|
|
2
2
|
|
|
3
|
+
Framework-agnostic web core for the vroom chart: the C++/Skia engine compiled to
|
|
4
|
+
WebAssembly, painting a `<canvas>` through a WebGL surface. Most apps should use
|
|
5
|
+
[`@vroomchart/react`](../react) instead — this is the layer underneath it.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { loadVroom } from '@vroomchart/core-wasm';
|
|
9
|
+
|
|
10
|
+
const mod = await loadVroom();
|
|
11
|
+
const chart = mod.create(document.querySelector('canvas')!);
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
The WASM binary and axis font ship inside this package and are referenced with
|
|
15
|
+
`new URL(..., import.meta.url)`, so bundlers emit them automatically — no asset
|
|
16
|
+
hosting required.
|
|
17
|
+
|
|
18
|
+
## Bundlers & CSP
|
|
19
|
+
|
|
20
|
+
The core is loaded with a plain dynamic `import()` of an emitted asset URL. It
|
|
21
|
+
requires **no `script-src 'unsafe-eval'`** — neither this package nor the
|
|
22
|
+
emscripten module it loads calls `eval` or `new Function` (the WASM module is
|
|
23
|
+
built with `-sDYNAMIC_EXECUTION=0`, which selects embind's closure-based
|
|
24
|
+
invokers over its default runtime codegen).
|
|
25
|
+
|
|
26
|
+
A strict policy like this is sufficient:
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
script-src 'self' 'wasm-unsafe-eval';
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
`'wasm-unsafe-eval'` **is** required — it's what browsers gate
|
|
33
|
+
`WebAssembly.compile`/`instantiate` behind. It does not permit `eval`, and is
|
|
34
|
+
much narrower than `'unsafe-eval'`. Without it the module can't start at all.
|
|
35
|
+
|
|
36
|
+
### When your bundler mangles the import
|
|
37
|
+
|
|
38
|
+
The import site carries `/* webpackIgnore: true */` and `/* @vite-ignore */`, so
|
|
39
|
+
webpack, Turbopack, Vite and Rollup all leave it alone. Magic comments only take
|
|
40
|
+
effect in first-party source, though, so if some other toolchain rewrites or
|
|
41
|
+
inlines the URL, supply the import yourself:
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
<VroomChart
|
|
45
|
+
candles={candles}
|
|
46
|
+
wasm={{ importModule: (url) => import(/* webpackIgnore: true */ url) }}
|
|
47
|
+
/>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
That keeps the bundled assets — override `moduleUrl` only if you're self-hosting
|
|
51
|
+
the core, in which case `wasmUrl` and `fontUrl` become yours to provide too.
|
|
52
|
+
|
|
53
|
+
### SSR
|
|
54
|
+
|
|
55
|
+
The module touches `WebGL` and `canvas`, so it is client-only. Under Next.js,
|
|
56
|
+
render the chart from a client component and load it with
|
|
57
|
+
`dynamic(() => import('...'), { ssr: false })`.
|