@strategicprojects/rpic 0.5.0 → 0.6.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.
package/README.md CHANGED
@@ -9,7 +9,7 @@ import * as rpic from '@strategicprojects/rpic';
9
9
 
10
10
  await rpic.ready(); // browser: wasm fetched automatically
11
11
 
12
- const { svg, animations, diagnostics } = rpic.compile('box "A"; arrow; box "B"');
12
+ const { svg, animations, diagnostics, warnings } = rpic.compile('box "A"; arrow; box "B"');
13
13
  document.querySelector('#stage').innerHTML = svg;
14
14
 
15
15
  // animate with GSAP:
@@ -29,20 +29,52 @@ await rpic.ready(readFileSync(new URL('./node_modules/rpic/pkg/rpic_wasm_bg.wasm
29
29
  console.log(rpic.renderSvg('box "hi"'));
30
30
  ```
31
31
 
32
+ ### TeX math labels (`texlabels`)
33
+
34
+ The default wasm build is lean and renders `$…$` labels as literal text (plus
35
+ a diagnostic). To typeset them exactly like the native CLI, opt into the
36
+ math-enabled build — a second, heavier `.wasm` (RaTeX + embedded KaTeX glyph
37
+ data) that is only fetched when you ask for it:
38
+
39
+ ```js
40
+ await rpic.ready(undefined, { math: true }); // browser: fetches pkg/rpic_wasm_math_bg.wasm
41
+ rpic.renderSvg('box "$-\\\\frac{T}{2}$" fit', { texlabels: true });
42
+ ```
43
+
44
+ Apps can keep the fast path untouched and lazy-load math only when the source
45
+ contains `$…$`. The build choice is fixed by the first `ready()` call. In
46
+ Node, pass the math artifact's bytes:
47
+ `ready(readFileSync(new URL('…/pkg/rpic_wasm_math_bg.wasm', import.meta.url)), { math: true })`.
48
+
32
49
  ## API
33
50
 
34
51
  | Function | Description |
35
52
  |----------|-------------|
36
- | `ready(wasmInput?)` | Initialize WASM. Browser: no arg. Node: pass `.wasm` bytes/URL. |
37
- | `compile(src, {circuits?})` | → `{ svg, animations, diagnostics }` (throws on a pic error). |
38
- | `renderSvg(src, {circuits?})` | → SVG string. |
53
+ | `ready(wasmInput?, {math?})` | Initialize WASM. Browser: no arg. Node: pass `.wasm` bytes/URL. `math: true` loads the math-enabled build. |
54
+ | `compile(src, {circuits?, texlabels?})` | → `{ svg, animations, diagnostics, warnings }` (throws on a pic error with `errorInfo`). |
55
+ | `renderSvg(src, {circuits?, texlabels?})` | → SVG string. |
39
56
  | `animate(root, animations, gsap)` | Build/play a GSAP timeline (`draw`/`fade`/`pop`). Browser only. |
40
57
 
58
+ Compile errors keep a readable `message` and expose structured data for editors:
59
+
60
+ ```js
61
+ try {
62
+ rpic.compile('bxo');
63
+ } catch (err) {
64
+ console.log(err.errorInfo); // { message, line, col, end_col, file, kind, found, expected, hint }
65
+ }
66
+ ```
67
+
68
+ Positions are always relative to your own source — with `circuits: true` an
69
+ error on your line 1 reports `line: 1`, and a problem inside a `copy` include
70
+ carries the include's name in `file` (`null` means your own input).
71
+
41
72
  PNG/PDF are available via the CLI, the Python package, or the R package (the
42
73
  WASM core renders SVG; rasterization isn't bundled here).
43
74
 
44
75
  ## Rebuild
45
76
 
46
77
  ```sh
47
- wasm-pack build crates/wasm --target web --out-dir bindings/js/pkg
78
+ npm run build:wasm
79
+ npm test
48
80
  ```
package/index.d.ts CHANGED
@@ -8,11 +8,38 @@ export interface Anim {
8
8
  duration: number;
9
9
  }
10
10
 
11
+ export interface Diagnostic {
12
+ message: string;
13
+ line: number | null;
14
+ col: number | null;
15
+ end_col: number | null;
16
+ /**
17
+ * Which source the position refers to: `null` is your own input; a string
18
+ * names a `copy` include (as written) or a loaded library (`"circuits"`).
19
+ * Positions are always relative to that source — with `circuits: true` an
20
+ * error on your line 1 reports line 1.
21
+ */
22
+ file: string | null;
23
+ kind: string;
24
+ found: string | null;
25
+ expected: string | null;
26
+ hint: string | null;
27
+ }
28
+
11
29
  export interface Bundle {
12
30
  svg: string;
13
31
  animations: Anim[];
14
32
  /** lines emitted by pic `print` statements */
15
33
  diagnostics: string[];
34
+ /** non-fatal compiler warnings for accepted but suspicious input */
35
+ warnings: Diagnostic[];
36
+ }
37
+
38
+ export interface CompileError extends Error {
39
+ /** structured compiler error, when available */
40
+ errorInfo?: Diagnostic;
41
+ /** warnings emitted before the fatal error, currently usually empty */
42
+ warnings?: Diagnostic[];
16
43
  }
17
44
 
18
45
  export interface CompileOptions {
@@ -20,20 +47,34 @@ export interface CompileOptions {
20
47
  circuits?: boolean;
21
48
  /**
22
49
  * set `texlabels = 1`, typesetting fully `$…$`-delimited labels as TeX
23
- * math. The default wasm build ships without the math renderer (size
24
- * budget), so labels fall back to literal text plus a diagnostic; the
25
- * option exists for API parity and future math-enabled builds.
50
+ * math. Requires the math-enabled build (`ready(…, { math: true })`); the
51
+ * default lean build ships without the math renderer (size budget), so
52
+ * labels fall back to literal text plus a diagnostic.
26
53
  */
27
54
  texlabels?: boolean;
28
55
  }
29
56
 
57
+ export interface ReadyOptions {
58
+ /**
59
+ * Load the math-enabled wasm build (`pkg/rpic_wasm_math_bg.wasm`), which
60
+ * bundles the RaTeX renderer so `texlabels` sources typeset `$…$` labels.
61
+ * The heavier artifact is only fetched when requested; the choice is fixed
62
+ * by the first `ready()` call. In Node, pass the math wasm bytes as
63
+ * `wasmInput`.
64
+ */
65
+ math?: boolean;
66
+ }
67
+
30
68
  /**
31
69
  * Initialize the WebAssembly module. In the browser call with no argument; in
32
70
  * Node pass the `.wasm` bytes or a file URL.
33
71
  */
34
- export function ready(wasmInput?: BufferSource | URL | string): Promise<void>;
72
+ export function ready(
73
+ wasmInput?: BufferSource | URL | string,
74
+ opts?: ReadyOptions
75
+ ): Promise<void>;
35
76
 
36
- /** Compile pic source into `{ svg, animations, diagnostics }`. Throws on a pic error. */
77
+ /** Compile pic source into `{ svg, animations, diagnostics, warnings }`. Throws on a pic error. */
37
78
  export function compile(src: string, opts?: CompileOptions): Bundle;
38
79
 
39
80
  /** Compile and return only the SVG string. */
package/index.js CHANGED
@@ -2,51 +2,60 @@
2
2
  //
3
3
  // Browser: await ready(); // wasm fetched automatically
4
4
  // Node: await ready(fs.readFileSync(url)); // pass the .wasm bytes/URL
5
- import initWasm, {
6
- compile as wasmCompile,
7
- compile_circuits as wasmCompileCircuits,
8
- compile_with as wasmCompileWith,
9
- } from './pkg/rpic_wasm.js';
5
+ // Math: await ready(undefined, { math: true }); // texlabels typeset in-browser
6
+ import * as leanModule from './pkg/rpic_wasm.js';
10
7
 
11
8
  let initPromise = null;
12
- let initialized = false;
9
+ let wasm = null; // the initialized glue module (lean or math)
13
10
 
14
11
  /**
15
12
  * Initialize the WebAssembly module (idempotent; concurrent calls share one
16
13
  * init). In the browser, call with no argument (the .wasm is fetched relative
17
14
  * to the module). In Node, pass the wasm bytes or a file URL.
15
+ *
16
+ * Pass `{ math: true }` to load the math-enabled build instead: it bundles
17
+ * the RaTeX renderer so `texlabels` sources typeset `$…$` labels exactly like
18
+ * the native CLI. The math glue + wasm are only fetched when requested, so
19
+ * the lean fast path stays untouched. The choice is fixed by the first call;
20
+ * in Node, pass the bytes of `pkg/rpic_wasm_math_bg.wasm` along with it.
18
21
  */
19
- export function ready(wasmInput) {
22
+ export function ready(wasmInput, opts = {}) {
20
23
  if (!initPromise) {
21
- initPromise = initWasm(
22
- wasmInput === undefined ? undefined : { module_or_path: wasmInput }
23
- ).then(() => {
24
- initialized = true;
24
+ initPromise = (
25
+ opts.math ? import('./pkg/rpic_wasm_math.js') : Promise.resolve(leanModule)
26
+ ).then(async (mod) => {
27
+ await mod.default(wasmInput === undefined ? undefined : { module_or_path: wasmInput });
28
+ wasm = mod;
25
29
  });
26
30
  }
27
31
  return initPromise;
28
32
  }
29
33
 
30
34
  function ensure() {
31
- if (!initialized) {
35
+ if (!wasm) {
32
36
  throw new Error('rpic: call `await ready()` before compiling');
33
37
  }
34
38
  }
35
39
 
36
40
  /**
37
- * Compile pic source into `{ svg, animations, diagnostics }` (throws on a pic error).
41
+ * Compile pic source into `{ svg, animations, diagnostics, warnings }` (throws on a pic error).
38
42
  * @param {string} src
39
43
  * @param {{circuits?: boolean, texlabels?: boolean}} [opts]
40
44
  */
41
45
  export function compile(src, opts = {}) {
42
46
  ensure();
43
47
  const json = opts.texlabels
44
- ? wasmCompileWith(src, !!opts.circuits, true)
48
+ ? wasm.compile_with(src, !!opts.circuits, true)
45
49
  : opts.circuits
46
- ? wasmCompileCircuits(src)
47
- : wasmCompile(src);
50
+ ? wasm.compile_circuits(src)
51
+ : wasm.compile(src);
48
52
  const out = JSON.parse(json);
49
- if (out.error) throw new Error(out.error);
53
+ if (out.error) {
54
+ const err = new Error(out.error);
55
+ err.errorInfo = out.error_info;
56
+ err.warnings = out.warnings ?? [];
57
+ throw err;
58
+ }
50
59
  return out;
51
60
  }
52
61
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strategicprojects/rpic",
3
- "version": "0.5.0",
3
+ "version": "0.6.1",
4
4
  "description": "The pic graphics language compiled to SVG with animation manifests, via WebAssembly. Browser + Node.",
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -11,7 +11,8 @@
11
11
  "types": "./index.d.ts",
12
12
  "default": "./index.js"
13
13
  },
14
- "./pkg/rpic_wasm_bg.wasm": "./pkg/rpic_wasm_bg.wasm"
14
+ "./pkg/rpic_wasm_bg.wasm": "./pkg/rpic_wasm_bg.wasm",
15
+ "./pkg/rpic_wasm_math_bg.wasm": "./pkg/rpic_wasm_math_bg.wasm"
15
16
  },
16
17
  "files": [
17
18
  "index.js",
@@ -20,10 +21,18 @@
20
21
  "pkg/rpic_wasm.d.ts",
21
22
  "pkg/rpic_wasm_bg.wasm",
22
23
  "pkg/rpic_wasm_bg.wasm.d.ts",
24
+ "pkg/rpic_wasm_math.js",
25
+ "pkg/rpic_wasm_math.d.ts",
26
+ "pkg/rpic_wasm_math_bg.wasm",
27
+ "pkg/rpic_wasm_math_bg.wasm.d.ts",
23
28
  "README.md"
24
29
  ],
25
30
  "scripts": {
26
- "prepack": "wasm-pack build ../../crates/wasm --target web --out-dir ../../bindings/js/pkg"
31
+ "build:wasm:lean": "wasm-pack build ../../crates/wasm --target web --out-dir ../../bindings/js/pkg",
32
+ "build:wasm:math": "wasm-pack build ../../crates/wasm --target web --out-dir ../../bindings/js/pkg --out-name rpic_wasm_math -- --features math",
33
+ "build:wasm": "npm run build:wasm:lean && npm run build:wasm:math",
34
+ "prepack": "npm run build:wasm",
35
+ "test": "node test/smoke.mjs && node test/smoke-math.mjs"
27
36
  },
28
37
  "keywords": ["pic", "svg", "diagram", "graphics", "wasm", "gsap", "animation", "circuits"],
29
38
  "author": "André Leite <leite@de.ufpe.br>",
@@ -2,24 +2,25 @@
2
2
  /* eslint-disable */
3
3
 
4
4
  /**
5
- * Compile pic source to a JSON `{svg, animations, diagnostics}` bundle (or
6
- * `{error}`).
5
+ * Compile pic source to a JSON `{svg, animations, diagnostics, warnings}`
6
+ * bundle (or `{error, error_info}`).
7
7
  */
8
8
  export function compile(src: string): string;
9
9
 
10
10
  /**
11
- * Like [`compile`], but with the native circuit-element library prepended
12
- * (so `resistor`, `and_gate`, … are available).
11
+ * Like [`compile`], but with the native circuit-element library loaded
12
+ * (so `resistor`, `and_gate`, … are available). Loaded as an option, not
13
+ * prepended text: diagnostic positions stay relative to `src`.
13
14
  */
14
15
  export function compile_circuits(src: string): string;
15
16
 
16
17
  /**
17
- * Like [`compile`], with options: `circuits` prepends the circuit-element
18
+ * Like [`compile`], with options: `circuits` loads the circuit-element
18
19
  * library; `texlabels` sets `texlabels = 1` so `$…$` labels are typeset as
19
- * TeX math. Note: this wasm build ships without the math renderer (size
20
- * budget), so with `texlabels` the labels currently fall back to literal
21
- * text and a diagnostic — the option exists for API parity and for future
22
- * math-enabled builds.
20
+ * TeX math. Note: the default wasm build ships without the math renderer
21
+ * (size budget), so with `texlabels` the labels fall back to literal text
22
+ * and a diagnostic — use the math-enabled build (`--features math`, the
23
+ * `rpic_wasm_math` npm artifact) to typeset them.
23
24
  */
24
25
  export function compile_with(src: string, circuits: boolean, texlabels: boolean): string;
25
26
 
package/pkg/rpic_wasm.js CHANGED
@@ -1,8 +1,8 @@
1
1
  /* @ts-self-types="./rpic_wasm.d.ts" */
2
2
 
3
3
  /**
4
- * Compile pic source to a JSON `{svg, animations, diagnostics}` bundle (or
5
- * `{error}`).
4
+ * Compile pic source to a JSON `{svg, animations, diagnostics, warnings}`
5
+ * bundle (or `{error, error_info}`).
6
6
  * @param {string} src
7
7
  * @returns {string}
8
8
  */
@@ -22,8 +22,9 @@ export function compile(src) {
22
22
  }
23
23
 
24
24
  /**
25
- * Like [`compile`], but with the native circuit-element library prepended
26
- * (so `resistor`, `and_gate`, … are available).
25
+ * Like [`compile`], but with the native circuit-element library loaded
26
+ * (so `resistor`, `and_gate`, … are available). Loaded as an option, not
27
+ * prepended text: diagnostic positions stay relative to `src`.
27
28
  * @param {string} src
28
29
  * @returns {string}
29
30
  */
@@ -43,12 +44,12 @@ export function compile_circuits(src) {
43
44
  }
44
45
 
45
46
  /**
46
- * Like [`compile`], with options: `circuits` prepends the circuit-element
47
+ * Like [`compile`], with options: `circuits` loads the circuit-element
47
48
  * library; `texlabels` sets `texlabels = 1` so `$…$` labels are typeset as
48
- * TeX math. Note: this wasm build ships without the math renderer (size
49
- * budget), so with `texlabels` the labels currently fall back to literal
50
- * text and a diagnostic — the option exists for API parity and for future
51
- * math-enabled builds.
49
+ * TeX math. Note: the default wasm build ships without the math renderer
50
+ * (size budget), so with `texlabels` the labels fall back to literal text
51
+ * and a diagnostic — use the math-enabled build (`--features math`, the
52
+ * `rpic_wasm_math` npm artifact) to typeset them.
52
53
  * @param {string} src
53
54
  * @param {boolean} circuits
54
55
  * @param {boolean} texlabels
Binary file
@@ -0,0 +1,70 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Compile pic source to a JSON `{svg, animations, diagnostics, warnings}`
6
+ * bundle (or `{error, error_info}`).
7
+ */
8
+ export function compile(src: string): string;
9
+
10
+ /**
11
+ * Like [`compile`], but with the native circuit-element library loaded
12
+ * (so `resistor`, `and_gate`, … are available). Loaded as an option, not
13
+ * prepended text: diagnostic positions stay relative to `src`.
14
+ */
15
+ export function compile_circuits(src: string): string;
16
+
17
+ /**
18
+ * Like [`compile`], with options: `circuits` loads the circuit-element
19
+ * library; `texlabels` sets `texlabels = 1` so `$…$` labels are typeset as
20
+ * TeX math. Note: the default wasm build ships without the math renderer
21
+ * (size budget), so with `texlabels` the labels fall back to literal text
22
+ * and a diagnostic — use the math-enabled build (`--features math`, the
23
+ * `rpic_wasm_math` npm artifact) to typeset them.
24
+ */
25
+ export function compile_with(src: string, circuits: boolean, texlabels: boolean): string;
26
+
27
+ /**
28
+ * Math-enabled builds (`--features math`) register the RaTeX renderer once
29
+ * at module init, so `texlabels` sources typeset `$…$` labels exactly like
30
+ * the native CLI. The lean default build registers nothing and math labels
31
+ * fall back to literal text plus a diagnostic.
32
+ */
33
+ export function init_math(): void;
34
+
35
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
36
+
37
+ export interface InitOutput {
38
+ readonly memory: WebAssembly.Memory;
39
+ readonly compile: (a: number, b: number) => [number, number];
40
+ readonly compile_circuits: (a: number, b: number) => [number, number];
41
+ readonly compile_with: (a: number, b: number, c: number, d: number) => [number, number];
42
+ readonly init_math: () => void;
43
+ readonly __wbindgen_externrefs: WebAssembly.Table;
44
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
45
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
46
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
47
+ readonly __wbindgen_start: () => void;
48
+ }
49
+
50
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
51
+
52
+ /**
53
+ * Instantiates the given `module`, which can either be bytes or
54
+ * a precompiled `WebAssembly.Module`.
55
+ *
56
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
57
+ *
58
+ * @returns {InitOutput}
59
+ */
60
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
61
+
62
+ /**
63
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
64
+ * for everything else, calls `WebAssembly.instantiate` directly.
65
+ *
66
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
67
+ *
68
+ * @returns {Promise<InitOutput>}
69
+ */
70
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -0,0 +1,273 @@
1
+ /* @ts-self-types="./rpic_wasm_math.d.ts" */
2
+
3
+ /**
4
+ * Compile pic source to a JSON `{svg, animations, diagnostics, warnings}`
5
+ * bundle (or `{error, error_info}`).
6
+ * @param {string} src
7
+ * @returns {string}
8
+ */
9
+ export function compile(src) {
10
+ let deferred2_0;
11
+ let deferred2_1;
12
+ try {
13
+ const ptr0 = passStringToWasm0(src, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
14
+ const len0 = WASM_VECTOR_LEN;
15
+ const ret = wasm.compile(ptr0, len0);
16
+ deferred2_0 = ret[0];
17
+ deferred2_1 = ret[1];
18
+ return getStringFromWasm0(ret[0], ret[1]);
19
+ } finally {
20
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
21
+ }
22
+ }
23
+
24
+ /**
25
+ * Like [`compile`], but with the native circuit-element library loaded
26
+ * (so `resistor`, `and_gate`, … are available). Loaded as an option, not
27
+ * prepended text: diagnostic positions stay relative to `src`.
28
+ * @param {string} src
29
+ * @returns {string}
30
+ */
31
+ export function compile_circuits(src) {
32
+ let deferred2_0;
33
+ let deferred2_1;
34
+ try {
35
+ const ptr0 = passStringToWasm0(src, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
36
+ const len0 = WASM_VECTOR_LEN;
37
+ const ret = wasm.compile_circuits(ptr0, len0);
38
+ deferred2_0 = ret[0];
39
+ deferred2_1 = ret[1];
40
+ return getStringFromWasm0(ret[0], ret[1]);
41
+ } finally {
42
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
43
+ }
44
+ }
45
+
46
+ /**
47
+ * Like [`compile`], with options: `circuits` loads the circuit-element
48
+ * library; `texlabels` sets `texlabels = 1` so `$…$` labels are typeset as
49
+ * TeX math. Note: the default wasm build ships without the math renderer
50
+ * (size budget), so with `texlabels` the labels fall back to literal text
51
+ * and a diagnostic — use the math-enabled build (`--features math`, the
52
+ * `rpic_wasm_math` npm artifact) to typeset them.
53
+ * @param {string} src
54
+ * @param {boolean} circuits
55
+ * @param {boolean} texlabels
56
+ * @returns {string}
57
+ */
58
+ export function compile_with(src, circuits, texlabels) {
59
+ let deferred2_0;
60
+ let deferred2_1;
61
+ try {
62
+ const ptr0 = passStringToWasm0(src, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
63
+ const len0 = WASM_VECTOR_LEN;
64
+ const ret = wasm.compile_with(ptr0, len0, circuits, texlabels);
65
+ deferred2_0 = ret[0];
66
+ deferred2_1 = ret[1];
67
+ return getStringFromWasm0(ret[0], ret[1]);
68
+ } finally {
69
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
70
+ }
71
+ }
72
+
73
+ /**
74
+ * Math-enabled builds (`--features math`) register the RaTeX renderer once
75
+ * at module init, so `texlabels` sources typeset `$…$` labels exactly like
76
+ * the native CLI. The lean default build registers nothing and math labels
77
+ * fall back to literal text plus a diagnostic.
78
+ */
79
+ export function init_math() {
80
+ wasm.init_math();
81
+ }
82
+ function __wbg_get_imports() {
83
+ const import0 = {
84
+ __proto__: null,
85
+ __wbg___wbindgen_throw_344f42d3211c4765: function(arg0, arg1) {
86
+ throw new Error(getStringFromWasm0(arg0, arg1));
87
+ },
88
+ __wbindgen_init_externref_table: function() {
89
+ const table = wasm.__wbindgen_externrefs;
90
+ const offset = table.grow(4);
91
+ table.set(0, undefined);
92
+ table.set(offset + 0, undefined);
93
+ table.set(offset + 1, null);
94
+ table.set(offset + 2, true);
95
+ table.set(offset + 3, false);
96
+ },
97
+ };
98
+ return {
99
+ __proto__: null,
100
+ "./rpic_wasm_math_bg.js": import0,
101
+ };
102
+ }
103
+
104
+ function getStringFromWasm0(ptr, len) {
105
+ return decodeText(ptr >>> 0, len);
106
+ }
107
+
108
+ let cachedUint8ArrayMemory0 = null;
109
+ function getUint8ArrayMemory0() {
110
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
111
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
112
+ }
113
+ return cachedUint8ArrayMemory0;
114
+ }
115
+
116
+ function passStringToWasm0(arg, malloc, realloc) {
117
+ if (realloc === undefined) {
118
+ const buf = cachedTextEncoder.encode(arg);
119
+ const ptr = malloc(buf.length, 1) >>> 0;
120
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
121
+ WASM_VECTOR_LEN = buf.length;
122
+ return ptr;
123
+ }
124
+
125
+ let len = arg.length;
126
+ let ptr = malloc(len, 1) >>> 0;
127
+
128
+ const mem = getUint8ArrayMemory0();
129
+
130
+ let offset = 0;
131
+
132
+ for (; offset < len; offset++) {
133
+ const code = arg.charCodeAt(offset);
134
+ if (code > 0x7F) break;
135
+ mem[ptr + offset] = code;
136
+ }
137
+ if (offset !== len) {
138
+ if (offset !== 0) {
139
+ arg = arg.slice(offset);
140
+ }
141
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
142
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
143
+ const ret = cachedTextEncoder.encodeInto(arg, view);
144
+
145
+ offset += ret.written;
146
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
147
+ }
148
+
149
+ WASM_VECTOR_LEN = offset;
150
+ return ptr;
151
+ }
152
+
153
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
154
+ cachedTextDecoder.decode();
155
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
156
+ let numBytesDecoded = 0;
157
+ function decodeText(ptr, len) {
158
+ numBytesDecoded += len;
159
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
160
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
161
+ cachedTextDecoder.decode();
162
+ numBytesDecoded = len;
163
+ }
164
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
165
+ }
166
+
167
+ const cachedTextEncoder = new TextEncoder();
168
+
169
+ if (!('encodeInto' in cachedTextEncoder)) {
170
+ cachedTextEncoder.encodeInto = function (arg, view) {
171
+ const buf = cachedTextEncoder.encode(arg);
172
+ view.set(buf);
173
+ return {
174
+ read: arg.length,
175
+ written: buf.length
176
+ };
177
+ };
178
+ }
179
+
180
+ let WASM_VECTOR_LEN = 0;
181
+
182
+ let wasmModule, wasmInstance, wasm;
183
+ function __wbg_finalize_init(instance, module) {
184
+ wasmInstance = instance;
185
+ wasm = instance.exports;
186
+ wasmModule = module;
187
+ cachedUint8ArrayMemory0 = null;
188
+ wasm.__wbindgen_start();
189
+ return wasm;
190
+ }
191
+
192
+ async function __wbg_load(module, imports) {
193
+ if (typeof Response === 'function' && module instanceof Response) {
194
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
195
+ try {
196
+ return await WebAssembly.instantiateStreaming(module, imports);
197
+ } catch (e) {
198
+ const validResponse = module.ok && expectedResponseType(module.type);
199
+
200
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
201
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
202
+
203
+ } else { throw e; }
204
+ }
205
+ }
206
+
207
+ const bytes = await module.arrayBuffer();
208
+ return await WebAssembly.instantiate(bytes, imports);
209
+ } else {
210
+ const instance = await WebAssembly.instantiate(module, imports);
211
+
212
+ if (instance instanceof WebAssembly.Instance) {
213
+ return { instance, module };
214
+ } else {
215
+ return instance;
216
+ }
217
+ }
218
+
219
+ function expectedResponseType(type) {
220
+ switch (type) {
221
+ case 'basic': case 'cors': case 'default': return true;
222
+ }
223
+ return false;
224
+ }
225
+ }
226
+
227
+ function initSync(module) {
228
+ if (wasm !== undefined) return wasm;
229
+
230
+
231
+ if (module !== undefined) {
232
+ if (Object.getPrototypeOf(module) === Object.prototype) {
233
+ ({module} = module)
234
+ } else {
235
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
236
+ }
237
+ }
238
+
239
+ const imports = __wbg_get_imports();
240
+ if (!(module instanceof WebAssembly.Module)) {
241
+ module = new WebAssembly.Module(module);
242
+ }
243
+ const instance = new WebAssembly.Instance(module, imports);
244
+ return __wbg_finalize_init(instance, module);
245
+ }
246
+
247
+ async function __wbg_init(module_or_path) {
248
+ if (wasm !== undefined) return wasm;
249
+
250
+
251
+ if (module_or_path !== undefined) {
252
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
253
+ ({module_or_path} = module_or_path)
254
+ } else {
255
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
256
+ }
257
+ }
258
+
259
+ if (module_or_path === undefined) {
260
+ module_or_path = new URL('rpic_wasm_math_bg.wasm', import.meta.url);
261
+ }
262
+ const imports = __wbg_get_imports();
263
+
264
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
265
+ module_or_path = fetch(module_or_path);
266
+ }
267
+
268
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
269
+
270
+ return __wbg_finalize_init(instance, module);
271
+ }
272
+
273
+ export { initSync, __wbg_init as default };
Binary file
@@ -0,0 +1,12 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const compile: (a: number, b: number) => [number, number];
5
+ export const compile_circuits: (a: number, b: number) => [number, number];
6
+ export const compile_with: (a: number, b: number, c: number, d: number) => [number, number];
7
+ export const init_math: () => void;
8
+ export const __wbindgen_externrefs: WebAssembly.Table;
9
+ export const __wbindgen_malloc: (a: number, b: number) => number;
10
+ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
11
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
12
+ export const __wbindgen_start: () => void;