@ifc-lite/wasm 10.4.0 → 10.6.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/retained.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ /* This Source Code Form is subject to the terms of the Mozilla Public
2
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
+
5
+ /** The retained engine: the default engine API plus the opt-in executor. */
6
+ export type RetainedEngine = typeof import('./pkg-retained/ifc-lite.js');
7
+
8
+ /**
9
+ * Import and initialize the separate retained engine bundle. Nothing is
10
+ * fetched until this is called; the executor's SMLib bundle at /smlib/ is
11
+ * fetched only when a `RetainedBrowserExecutor` is constructed.
12
+ */
13
+ export function loadRetainedEngine(options?: {
14
+ moduleUrl?: string | URL;
15
+ wasm?: RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
16
+ }): Promise<RetainedEngine>;
package/retained.js ADDED
@@ -0,0 +1,33 @@
1
+ /* This Source Code Form is subject to the terms of the Mozilla Public
2
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
+
5
+ // Opt-in loader for the retained-geometry engine bundle (#7955). Importing
6
+ // this module fetches nothing: the separate `pkg-retained` engine (built with
7
+ // `BUILD_RETAINED=1 scripts/build-wasm.sh` and deployed by the application;
8
+ // the published package ships only its types) is imported and instantiated
9
+ // only when `loadRetainedEngine()` is called, and its RetainedBrowserExecutor loads
10
+ // the SMLib bundle from /smlib/ only when constructed. The default engine
11
+ // (`@ifc-lite/wasm`) never contains the executor.
12
+
13
+ const DEFAULT_MODULE = new URL('./pkg-retained/ifc-lite.js', import.meta.url);
14
+
15
+ /**
16
+ * Import and initialize the retained engine module. `moduleUrl` points at a
17
+ * deployed copy of `pkg-retained/ifc-lite.js`; `wasm` is forwarded to its
18
+ * initializer (default: the sibling `ifc-lite_bg.wasm`). Memoized per URL.
19
+ */
20
+ const loaded = new Map();
21
+ export function loadRetainedEngine({ moduleUrl = DEFAULT_MODULE, wasm } = {}) {
22
+ const key = String(moduleUrl);
23
+ if (!loaded.has(key)) {
24
+ const pending = import(/* @vite-ignore */ key).then(async (engine) => {
25
+ await engine.default(wasm === undefined ? undefined : { module_or_path: wasm });
26
+ return engine;
27
+ });
28
+ // A failed load is not cached: the caller may deploy the bundle and retry.
29
+ pending.catch(() => loaded.delete(key));
30
+ loaded.set(key, pending);
31
+ }
32
+ return loaded.get(key);
33
+ }