@taulabs/openrscad-engine 0.11.0-beta.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/LICENSE-APACHE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 The OpenRSCAD Authors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/LICENSE-MIT ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 The OpenRSCAD Authors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,194 @@
1
+ # @taulabs/openrscad-engine
2
+
3
+ > **A fork.** This is [Tau](https://tau.new)'s build of
4
+ > [OpenRSCAD](https://github.com/matthova/openrscad) by Matt Hova, published
5
+ > under the `@taulabs` scope while our additions are prepared for contribution
6
+ > back upstream. It tracks upstream and keeps its `Apache-2.0 OR MIT` licensing
7
+ > and attribution unchanged. For the original, install `openrscad-engine`.
8
+ >
9
+ > What this fork adds on top of upstream: a structured export path that
10
+ > preserves the authored scene — user-module hierarchy, per-owner materials and
11
+ > source provenance — through GLB and 3MF, plus optional source-derived feature
12
+ > edges. Fork sources live at
13
+ > [taucad/openrscad](https://github.com/taucad/openrscad).
14
+
15
+ The [OpenRSCAD](https://github.com/matthova/openrscad) geometry engine, compiled
16
+ to WebAssembly. Parse OpenSCAD-compatible `.scad` source and render solid 3D
17
+ meshes — the same Rust core that powers the
18
+ [playground](https://matthova.github.io/openrscad) — in your own browser app
19
+ or Node tool.
20
+
21
+ - **Oracle-checked.** Representative output is compared with stock OpenSCAD by
22
+ geometry metrics; the wasm build uses the pure-Rust Manifold geometry kernel.
23
+ - **Fast, incremental.** A persistent geometry cache makes warm edits
24
+ single-digit-millisecond.
25
+ - **Self-contained.** No native dependencies, no threads, no `SharedArrayBuffer`
26
+ — so **no COOP/COEP headers are needed**, even from a CDN.
27
+
28
+ > **Heads up — this is a 0.x release.**
29
+ > - The JS API may change between minor versions. **Pin a version** (`"@taulabs/openrscad-engine": "~0.1.0"`, not `^0.1.0`) if you depend on it.
30
+ > - The `.wasm` binary is a few MB. Load it in a **Web Worker** (see below) so a
31
+ > render never blocks your UI, and let your CDN serve it gzip/brotli-compressed.
32
+
33
+ ## Install
34
+
35
+ ```sh
36
+ npm install @taulabs/openrscad-engine
37
+ ```
38
+
39
+ ## Quickstart (browser / bundler)
40
+
41
+ The default export is a small, safe wrapper: pass plain objects, get a plain
42
+ result back, and never manage wasm memory yourself.
43
+
44
+ ```js
45
+ import { render } from "@taulabs/openrscad-engine";
46
+
47
+ // The first call fetches + instantiates the wasm (resolving openrscad_bg.wasm
48
+ // next to the module). Call ensureReady() yourself to preload it earlier.
49
+ const r = await render("difference() { cube(20, center=true); sphere(12); }");
50
+
51
+ if (r.ok) {
52
+ console.log(r.triangleCount, "triangles, volume", r.volume);
53
+ // r.positions / r.normals: non-indexed triangle soup, 9 f32 per triangle.
54
+ } else {
55
+ console.error(r.error, r.diagnostics);
56
+ }
57
+ ```
58
+
59
+ Works out of the box in Vite, webpack 5, and any ES-module bundler.
60
+
61
+ ### Native 3D files
62
+
63
+ ```js
64
+ import { exportShape3D } from "@taulabs/openrscad-engine";
65
+
66
+ const result = await exportShape3D(
67
+ 'color("red") { cube(10); translate([0, 0, 20]) cube(10); }',
68
+ "glb",
69
+ { includeEdges: true },
70
+ );
71
+ if (!result.ok) throw new Error(result.error);
72
+ // One owned Uint8Array. Authored module calls become nested named glTF nodes;
73
+ // geometry outside a user module uses deterministic hexadecimal color names.
74
+ console.log(result.bytes);
75
+ ```
76
+
77
+ `exportShape3D` supports `stl`, `off`, `obj`, `3mf`, `amf`, and `glb`. GLB and
78
+ 3MF share one exact attributed boundary. GLB preserves authored user-module
79
+ hierarchy and uses materials for color; anonymous top-level geometry falls back
80
+ to deterministic color/connectivity parts. 3MF keeps each spatial solid
81
+ manifold, assigns materials per triangle, and derives object names and
82
+ namespaced source metadata without changing that physical partition.
83
+ `includeEdges` is GLB-only, defaults to false, and emits owner-local mesh
84
+ feature lines rather than analytic/BRep curves.
85
+
86
+ Use `renderToGlb(source, { includeEdges })` for interactive preview semantics
87
+ (`$preview=true`, including factual highlight/background display modes). File
88
+ exports always evaluate with `$preview=false`.
89
+
90
+ ### Customizer params and include/use files
91
+
92
+ ```js
93
+ await render("width = 10; cube([width, 10, 10]);", {
94
+ params: { width: 40 }, // numbers/booleans are stringified;
95
+ files: { "lib.scad": "function f() = 3;" },// strings must be quoted: '"hi"'
96
+ });
97
+ ```
98
+
99
+ ## No-install: import straight from a CDN
100
+
101
+ Because the package publishes the browser (`web`) target, you can import it with
102
+ no build step at all. **Use the raw file path** (not `/+esm` or `esm.run`, which
103
+ mangle wasm glue) and **pin the version**:
104
+
105
+ ```js
106
+ import init, { render_with_files } from
107
+ "https://cdn.jsdelivr.net/npm/openrscad-engine@0.1.0/pkg/web/openrscad.js";
108
+
109
+ await init(); // resolves the sibling openrscad_bg.wasm
110
+ const r = render_with_files("cube(10);", [], [], [], []);
111
+ try {
112
+ console.log(r.triangle_count);
113
+ } finally {
114
+ r.free(); // raw exports are wasm-owned — free them
115
+ }
116
+ ```
117
+
118
+ The CDN path exposes the **raw** wasm-bindgen exports (below); for the friendlier
119
+ wrapper, install the package instead.
120
+
121
+ ## Run it in a Web Worker (recommended)
122
+
123
+ See [`examples/worker.js`](./examples/worker.js) for a ready-made module worker.
124
+ In short:
125
+
126
+ ```js
127
+ // worker.js
128
+ import { render } from "@taulabs/openrscad-engine";
129
+ self.onmessage = async (e) => {
130
+ const result = await render(e.data.source);
131
+ self.postMessage({ result }, [result.positions.buffer, result.normals.buffer]);
132
+ };
133
+ ```
134
+
135
+ ```js
136
+ // app.js
137
+ const worker = new Worker(new URL("./worker.js", import.meta.url), { type: "module" });
138
+ worker.onmessage = (e) => draw(e.data.result);
139
+ worker.postMessage({ source: "cube(10);" });
140
+ ```
141
+
142
+ ## Node
143
+
144
+ ```js
145
+ import { render, version } from "@taulabs/openrscad-engine"; // ESM
146
+ console.log(await version());
147
+ const r = await render("sphere(8);");
148
+ ```
149
+
150
+ The wasm instantiates on import in Node — no init step. CommonJS `require()`
151
+ consumers get the raw wasm-bindgen exports (call `.free()` on results). A full
152
+ example is in [`examples/node-render.mjs`](./examples/node-render.mjs).
153
+
154
+ ## API
155
+
156
+ The wrapper (default export) — all methods are async and initialize the engine
157
+ on first use:
158
+
159
+ | method | returns | notes |
160
+ |---|---|---|
161
+ | `render(source, opts?)` | `Promise<RenderOutput>` | full pipeline → mesh + diagnostics |
162
+ | `renderToGlb(source, opts?)` | `Promise<ExportShape3DOutput>` | preview-semantics GLB for interactive viewers |
163
+ | `exportShape2D(source, "dxf" \| "svg", opts?)` | `Promise<string>` | 2D models only |
164
+ | `exportShape3D(source, format, opts?)` | `Promise<ExportShape3DOutput>` | native STL/OFF/OBJ/3MF/AMF/GLB |
165
+ | `parameters(source)` | `Promise<string>` | customizer schema JSON |
166
+ | `version()` | `Promise<string>` | engine version |
167
+ | `clearCache()` | `Promise<void>` | drop the persistent geometry cache |
168
+ | `ensureReady(wasmUrl?)` | `Promise<void>` | preload / point at a custom `.wasm` |
169
+
170
+ All render/export options accept customizer `params`, text `files`, binary
171
+ `binaryFiles`, and `fontFiles`. GLB export additionally accepts `includeEdges`,
172
+ `sourceUnitToMeters`, and `coordinateSystem` (`"y-up"` by default). Other 3D
173
+ formats expose only the common request options. `renderToGlb` accepts
174
+ `includeEdges` and owns fixed viewer units/coordinates.
175
+
176
+ `RenderOutput` includes `ok`, `error`, `positions`/`normals` (Float32Array
177
+ triangle soup, 9 f32 per triangle, flat per-face normals — parallel arrays you
178
+ own), `is2d`, `triangleCount`, `vertexCount`, `volume`, `area`, `echo`,
179
+ `warnings`, `diagnostics` (parsed `[{severity,message,start,end}]`, with byte
180
+ offsets), plus `preview` and `provenance` channels for color and editor↔preview
181
+ linking. Full types ship with the package.
182
+
183
+ ### Subpath entry points (advanced)
184
+
185
+ - `@taulabs/openrscad-engine/web` — the raw `--target web` wasm-bindgen module (call `init()`, then the exports; `.free()` results).
186
+ - `@taulabs/openrscad-engine/node` — the raw `--target nodejs` module (auto-init).
187
+ - `@taulabs/openrscad-engine/openrscad_bg.wasm` — the wasm binary URL, for `init({ module_or_path })` with a custom loader.
188
+
189
+ Prefer the default wrapper unless you specifically need the raw surface — it
190
+ copies mesh data into values you own and frees the wasm object for you.
191
+
192
+ ## License
193
+
194
+ Apache-2.0 OR MIT, at your option.
@@ -0,0 +1,16 @@
1
+ /** Initialize the wasm module (idempotent — safe to call repeatedly). Pass a
2
+ * URL/Request/etc. to load the `.wasm` from a custom location; omit it to
3
+ * resolve `openrscad_bg.wasm` beside the glue module. */
4
+ export declare function ensureReady(wasmUrl?: string | URL | Request): Promise<void>;
5
+ export declare const render: (source: string, opts?: import("./core.js").RenderOptions) => Promise<import("./core.js").RenderOutput>;
6
+ export declare const renderToGlb: (source: string, opts?: import("./core.js").RenderToGlbOptions) => Promise<import("./core.js").ExportShape3DOutput>;
7
+ export declare const exportShape2D: (source: string, format: "dxf" | "svg", opts?: import("./core.js").RenderOptions) => Promise<string>;
8
+ export declare const exportShape3D: {
9
+ (source: string, format: "glb", opts?: import("./core.js").ExportGlbOptions): Promise<import("./core.js").ExportShape3DOutput>;
10
+ (source: string, format: Exclude<import("./core.js").ExportShape3DFormat, "glb">, opts?: import("./core.js").RenderOptions): Promise<import("./core.js").ExportShape3DOutput>;
11
+ };
12
+ export declare const parameters: (source: string) => Promise<string>;
13
+ export declare const version: () => Promise<string>;
14
+ export declare const clearCache: () => Promise<void>;
15
+ export type { Diagnostic, ExportGlbOptions, ExportShape3DFormat, ExportShape3DOutput, RenderOptions, RenderOutput, RenderToGlbOptions, } from "./core.js";
16
+ //# sourceMappingURL=browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAmBA;;0DAE0D;AAC1D,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,GAAG,GAAG,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAE3E;AAcD,eAAO,MAAM,MAAM,yGAAa,CAAC;AACjC,eAAO,MAAM,WAAW,qHAAkB,CAAC;AAC3C,eAAO,MAAM,aAAa,sGAAoB,CAAC;AAC/C,eAAO,MAAM,aAAa;;;CAAoB,CAAC;AAC/C,eAAO,MAAM,UAAU,qCAAiB,CAAC;AACzC,eAAO,MAAM,OAAO,uBAAc,CAAC;AACnC,eAAO,MAAM,UAAU,qBAAiB,CAAC;AAEzC,YAAY,EACV,UAAU,EACV,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,aAAa,EACb,YAAY,EACZ,kBAAkB,GACnB,MAAM,WAAW,CAAC"}
@@ -0,0 +1,33 @@
1
+ // Browser / bundler entry (the default `.` export for web and CDN consumers).
2
+ //
3
+ // The wasm module is fetched and instantiated on first use via `init()`. Call
4
+ // `ensureReady(wasmUrl?)` up front to control when — and from where — the
5
+ // `.wasm` loads (preload it, or point at a custom/CDN URL); otherwise the first
6
+ // `render()` initializes it, resolving `openrscad_bg.wasm` next to the glue module.
7
+ import init, { render_with_files as rawRenderWithFiles, export_2d as rawExport2d, export_3d as rawExport3d, render_to_glb as rawRenderToGlb, parameters as rawParameters, version as rawVersion, clear_cache as rawClearCache, } from "../pkg/web/openrscad.js";
8
+ import { makeApi } from "./core.js";
9
+ let ready = null;
10
+ /** Initialize the wasm module (idempotent — safe to call repeatedly). Pass a
11
+ * URL/Request/etc. to load the `.wasm` from a custom location; omit it to
12
+ * resolve `openrscad_bg.wasm` beside the glue module. */
13
+ export function ensureReady(wasmUrl) {
14
+ return (ready ??= init(wasmUrl ? { module_or_path: wasmUrl } : undefined).then(() => undefined));
15
+ }
16
+ const engine = {
17
+ render_with_files: rawRenderWithFiles,
18
+ export_2d: rawExport2d,
19
+ export_3d: rawExport3d,
20
+ render_to_glb: rawRenderToGlb,
21
+ parameters: rawParameters,
22
+ version: rawVersion,
23
+ clear_cache: rawClearCache,
24
+ };
25
+ const api = makeApi(engine, ensureReady);
26
+ export const render = api.render;
27
+ export const renderToGlb = api.renderToGlb;
28
+ export const exportShape2D = api.exportShape2D;
29
+ export const exportShape3D = api.exportShape3D;
30
+ export const parameters = api.parameters;
31
+ export const version = api.version;
32
+ export const clearCache = api.clearCache;
33
+ //# sourceMappingURL=browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.js","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,EAAE;AACF,8EAA8E;AAC9E,0EAA0E;AAC1E,gFAAgF;AAChF,oFAAoF;AACpF,OAAO,IAAI,EAAE,EACX,iBAAiB,IAAI,kBAAkB,EACvC,SAAS,IAAI,WAAW,EACxB,SAAS,IAAI,WAAW,EACxB,aAAa,IAAI,cAAc,EAC/B,UAAU,IAAI,aAAa,EAC3B,OAAO,IAAI,UAAU,EACrB,WAAW,IAAI,aAAa,GAC7B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,OAAO,EAAkB,MAAM,WAAW,CAAC;AAEpD,IAAI,KAAK,GAAyB,IAAI,CAAC;AAEvC;;0DAE0D;AAC1D,MAAM,UAAU,WAAW,CAAC,OAAgC;IAC1D,OAAO,CAAC,KAAK,KAAK,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;AACnG,CAAC;AAED,MAAM,MAAM,GAAG;IACb,iBAAiB,EAAE,kBAAkB;IACrC,SAAS,EAAE,WAAW;IACtB,SAAS,EAAE,WAAW;IACtB,aAAa,EAAE,cAAc;IAC7B,UAAU,EAAE,aAAa;IACzB,OAAO,EAAE,UAAU;IACnB,WAAW,EAAE,aAAa;CACH,CAAC;AAE1B,MAAM,GAAG,GAAG,OAAO,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;AAEzC,MAAM,CAAC,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;AACjC,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,CAAC,WAAW,CAAC;AAC3C,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,CAAC,aAAa,CAAC;AAC/C,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,CAAC,aAAa,CAAC;AAC/C,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,CAAC,UAAU,CAAC;AACzC,MAAM,CAAC,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC;AACnC,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,CAAC,UAAU,CAAC"}
package/dist/core.d.ts ADDED
@@ -0,0 +1,158 @@
1
+ /** A structured diagnostic. `start`/`end` are UTF-8 byte offsets into the
2
+ * source (or -1 when unknown) — note JS strings are UTF-16, so map offsets if
3
+ * you place them in an editor. */
4
+ export interface Diagnostic {
5
+ severity: "error" | "warning";
6
+ message: string;
7
+ start: number;
8
+ end: number;
9
+ }
10
+ /** A parsed render. Mesh data is a non-indexed triangle soup: `positions` and
11
+ * `normals` both hold 9 f32 per triangle (flat, per-face normals), and are
12
+ * independent copies you own (safe to transfer to another worker/thread). */
13
+ export interface RenderOutput {
14
+ ok: boolean;
15
+ /** Error message, or "" when `ok`. */
16
+ error: string;
17
+ positions: Float32Array;
18
+ normals: Float32Array;
19
+ /** True for 2D models (exportable to DXF/SVG via `exportShape2D`). */
20
+ is2d: boolean;
21
+ triangleCount: number;
22
+ vertexCount: number;
23
+ volume: number;
24
+ area: number;
25
+ /** Newline-joined `ECHO:` output. */
26
+ echo: string;
27
+ /** Newline-joined warnings. */
28
+ warnings: string;
29
+ /** Recoverable geometry errors. A mesh may still be present when non-empty. */
30
+ geomErrors: string;
31
+ diagnostics: Diagnostic[];
32
+ /** Per-color preview channel (a concatenated triangle soup + a JSON array of
33
+ * `{start,count,color,mode}`). Empty unless the model uses `color`/`#`/`%`
34
+ * (the viewer then uses `positions`). */
35
+ preview: {
36
+ positions: Float32Array;
37
+ normals: Float32Array;
38
+ groups: string;
39
+ };
40
+ /** Editor↔preview provenance channel (a per-leaf triangle soup + a JSON array
41
+ * of `{start,count,spans}` byte-offset stacks). Empty for models with no
42
+ * geometry. */
43
+ provenance: {
44
+ positions: Float32Array;
45
+ normals: Float32Array;
46
+ groups: string;
47
+ };
48
+ /** `$vp*` viewport variables as JSON, or "" when the source has no `$vp`. */
49
+ viewport: string;
50
+ }
51
+ export interface RenderOptions {
52
+ /** Customizer overrides. Values are OpenSCAD literals as strings — numbers and
53
+ * booleans are stringified for you, but strings must be quoted (`'"hi"'`) and
54
+ * vectors bracketed (`"[1,2,3]"`), matching the language. */
55
+ params?: Record<string, string | number | boolean>;
56
+ /** In-memory files for `include`/`use` resolution, keyed by path:
57
+ * `{ "lib.scad": "function f() = 1;" }`. */
58
+ files?: Record<string, string>;
59
+ /** Binary files for `import()`, keyed by path. */
60
+ binaryFiles?: Record<string, Uint8Array>;
61
+ /** Font files made available to `text()` for this request. */
62
+ fontFiles?: readonly Uint8Array[];
63
+ }
64
+ export type ExportShape3DFormat = "stl" | "off" | "obj" | "3mf" | "amf" | "glb";
65
+ export interface ExportGlbOptions extends RenderOptions {
66
+ /** Add native owner-local mesh feature lines to GLB output. */
67
+ includeEdges?: boolean;
68
+ /** Scale from source coordinates to metres in GLB. Defaults to millimetres. */
69
+ sourceUnitToMeters?: number;
70
+ /** GLB coordinate convention. Standard glTF Y-up is the default. */
71
+ coordinateSystem?: "y-up" | "z-up";
72
+ }
73
+ export interface RenderToGlbOptions extends RenderOptions {
74
+ /** Add native owner-local feature lines. */
75
+ includeEdges?: boolean;
76
+ }
77
+ export interface ExportShape3DOutput {
78
+ ok: boolean;
79
+ error: string;
80
+ bytes: Uint8Array<ArrayBuffer>;
81
+ format: ExportShape3DFormat;
82
+ is2d: boolean;
83
+ triangleCount: number;
84
+ vertexCount: number;
85
+ volume: number;
86
+ area: number;
87
+ echo: string;
88
+ warnings: string;
89
+ geomErrors: string;
90
+ diagnostics: Diagnostic[];
91
+ viewport: string;
92
+ }
93
+ /** The subset of the wasm `RenderResult` this facade reads. */
94
+ interface RawResult {
95
+ ok: boolean;
96
+ error: string;
97
+ positions: Float32Array;
98
+ normals: Float32Array;
99
+ is_2d: boolean;
100
+ triangle_count: number;
101
+ vertex_count: number;
102
+ volume: number;
103
+ area: number;
104
+ echo: string;
105
+ warnings: string;
106
+ geom_errors: string;
107
+ diagnostics: string;
108
+ preview_positions: Float32Array;
109
+ preview_normals: Float32Array;
110
+ groups: string;
111
+ provenance_positions: Float32Array;
112
+ provenance_normals: Float32Array;
113
+ provenance: string;
114
+ viewport: string;
115
+ free(): void;
116
+ }
117
+ interface RawExportResult {
118
+ ok: boolean;
119
+ error: string;
120
+ format: string;
121
+ is_2d: boolean;
122
+ triangle_count: number;
123
+ vertex_count: number;
124
+ volume: number;
125
+ area: number;
126
+ echo: string;
127
+ warnings: string;
128
+ geom_errors: string;
129
+ diagnostics: string;
130
+ viewport: string;
131
+ take_bytes(): Uint8Array<ArrayBuffer>;
132
+ free(): void;
133
+ }
134
+ /** The generated wasm-bindgen exports this facade wraps. */
135
+ export interface RawEngine {
136
+ render_with_files(source: string, names: string[], values: string[], fileNames: string[], fileContents: string[], binNames: string[], binData: string[], fontBlobs: string[]): RawResult;
137
+ export_2d(source: string, names: string[], values: string[], fileNames: string[], fileContents: string[], binNames: string[], binData: string[], fontBlobs: string[], format: string): string;
138
+ export_3d(source: string, names: string[], values: string[], fileNames: string[], fileContents: string[], binNames: string[], binData: string[], fontBlobs: string[], format: string, includeEdges: boolean, sourceUnitToMeters: number, coordinateSystem: string): RawExportResult;
139
+ render_to_glb(source: string, names: string[], values: string[], fileNames: string[], fileContents: string[], binNames: string[], binData: string[], fontBlobs: string[], includeEdges: boolean): RawExportResult;
140
+ parameters(source: string): string;
141
+ version(): string;
142
+ clear_cache(): void;
143
+ }
144
+ /** Build the public API from the raw engine bindings and an init hook. */
145
+ export declare function makeApi(engine: RawEngine, ensureReady: () => Promise<void>): {
146
+ render: (source: string, opts?: RenderOptions) => Promise<RenderOutput>;
147
+ renderToGlb: (source: string, opts?: RenderToGlbOptions) => Promise<ExportShape3DOutput>;
148
+ exportShape2D: (source: string, format: "dxf" | "svg", opts?: RenderOptions) => Promise<string>;
149
+ exportShape3D: {
150
+ (source: string, format: "glb", opts?: ExportGlbOptions): Promise<ExportShape3DOutput>;
151
+ (source: string, format: Exclude<ExportShape3DFormat, "glb">, opts?: RenderOptions): Promise<ExportShape3DOutput>;
152
+ };
153
+ parameters: (source: string) => Promise<string>;
154
+ version: () => Promise<string>;
155
+ clearCache: () => Promise<void>;
156
+ };
157
+ export {};
158
+ //# sourceMappingURL=core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AASA;;mCAEmC;AACnC,MAAM,WAAW,UAA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