loro-crdt 1.8.9 → 1.9.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/CHANGELOG.md +188 -0
- package/base64/index.js +2948 -2917
- package/base64/loro_wasm.d.ts +1161 -1189
- package/bundler/loro_wasm.d.ts +1161 -1189
- package/bundler/loro_wasm.js +85 -23
- package/bundler/loro_wasm_bg.js +2852 -2896
- package/bundler/loro_wasm_bg.wasm +0 -0
- package/bundler/loro_wasm_bg.wasm.d.ts +250 -252
- package/nodejs/loro_wasm.d.ts +1161 -1189
- package/nodejs/loro_wasm.js +2885 -2929
- package/nodejs/loro_wasm_bg.wasm +0 -0
- package/nodejs/loro_wasm_bg.wasm.d.ts +250 -252
- package/package.json +1 -2
- package/web/loro_wasm.d.ts +1440 -1470
- package/web/loro_wasm.js +2836 -2880
- package/web/loro_wasm_bg.wasm +0 -0
- package/web/loro_wasm_bg.wasm.d.ts +250 -252
package/bundler/loro_wasm.js
CHANGED
|
@@ -1,34 +1,96 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import * as wasm from "./loro_wasm_bg.wasm";
|
|
4
|
-
import * as imports from "./loro_wasm_bg.js";
|
|
1
|
+
import * as rawWasm from './loro_wasm_bg.wasm';
|
|
2
|
+
import * as imports from './loro_wasm_bg.js';
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
wasm
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
4
|
+
// Normalize how bundlers expose the wasm module/exports.
|
|
5
|
+
const toModuleOrExports = (wasm) => {
|
|
6
|
+
if (!wasm) return wasm;
|
|
7
|
+
if (wasm instanceof WebAssembly.Module) return wasm;
|
|
8
|
+
if (typeof wasm === 'object' && 'default' in wasm) {
|
|
9
|
+
return wasm.default ?? wasm;
|
|
10
|
+
}
|
|
11
|
+
// rsbuild doesn't provide a default export when importing wasm.
|
|
12
|
+
return wasm;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const wasmModuleOrExports = toModuleOrExports(rawWasm);
|
|
16
|
+
|
|
17
|
+
// Helper: ensure we end up with exports + optionally run externref init.
|
|
18
|
+
const finalize = (exports) => {
|
|
19
|
+
imports.__wbg_set_wasm(exports);
|
|
20
|
+
if (typeof imports.__wbindgen_init_externref_table === 'function') {
|
|
21
|
+
imports.__wbindgen_init_externref_table();
|
|
22
|
+
}
|
|
23
|
+
tryStart(imports);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
function tryStart(imports) {
|
|
27
|
+
if (typeof imports.__wbindgen_start === 'function') {
|
|
28
|
+
// Some bundlers require explicit start invocation.
|
|
29
|
+
imports.__wbindgen_start();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
17
32
|
|
|
33
|
+
if (wasmModuleOrExports && wasmModuleOrExports.__wbindgen_start) {
|
|
34
|
+
// See https://github.com/loro-dev/loro/issues/440
|
|
35
|
+
// Without this patch, Cloudflare Worker would raise issue like: "Uncaught TypeError: wasm2.__wbindgen_start is not a function"
|
|
36
|
+
// Already the initialized exports object (Cloudflare Workers path).
|
|
37
|
+
finalize(wasmModuleOrExports);
|
|
38
|
+
} else if ('Bun' in globalThis) {
|
|
18
39
|
// Bun's wasm runtime (1.3.0 as of Oct 2025) sometimes reads externref slot 1
|
|
19
40
|
// (reserved for booleans by wasm-bindgen) as the global object, causing APIs
|
|
20
41
|
// like `LoroText.toDelta()` to return cyclic structures. Re-running the
|
|
21
42
|
// wasm-bindgen externref table initializer after instantiation resets the
|
|
22
43
|
// table so booleans stay primitives and avoids the infinite recursion seen in
|
|
23
44
|
// Bun tests during `pnpm release-wasm`.
|
|
24
|
-
|
|
25
|
-
|
|
45
|
+
let instance;
|
|
46
|
+
if (wasmModuleOrExports instanceof WebAssembly.Module) {
|
|
47
|
+
({ instance } = await WebAssembly.instantiate(wasmModuleOrExports, {
|
|
48
|
+
'./loro_wasm_bg.js': imports,
|
|
49
|
+
}));
|
|
50
|
+
} else {
|
|
51
|
+
const url = Bun.pathToFileURL(wasmModuleOrExports);
|
|
52
|
+
({ instance } = await WebAssembly.instantiateStreaming(fetch(url), {
|
|
53
|
+
'./loro_wasm_bg.js': imports,
|
|
54
|
+
}));
|
|
26
55
|
}
|
|
56
|
+
finalize(instance.exports);
|
|
27
57
|
} else {
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
58
|
+
// Browser/node-like bundlers: either we already have exports, or a Module/URL.
|
|
59
|
+
const wkmod =
|
|
60
|
+
wasmModuleOrExports instanceof WebAssembly.Module
|
|
61
|
+
? wasmModuleOrExports
|
|
62
|
+
: await import('./loro_wasm_bg.wasm');
|
|
63
|
+
const module =
|
|
64
|
+
wkmod instanceof WebAssembly.Module
|
|
65
|
+
? wkmod
|
|
66
|
+
: (wkmod && wkmod.default) || wkmod;
|
|
67
|
+
let instance;
|
|
68
|
+
if (module instanceof WebAssembly.Instance) {
|
|
69
|
+
instance = module;
|
|
70
|
+
} else if (module instanceof WebAssembly.Module) {
|
|
71
|
+
instance = await WebAssembly.instantiate(module, {
|
|
72
|
+
'./loro_wasm_bg.js': imports,
|
|
73
|
+
});
|
|
74
|
+
} else if (module instanceof ArrayBuffer || ArrayBuffer.isView(module)) {
|
|
75
|
+
const { instance: inst } = await WebAssembly.instantiate(module, {
|
|
76
|
+
'./loro_wasm_bg.js': imports,
|
|
77
|
+
});
|
|
78
|
+
instance = inst;
|
|
79
|
+
} else if (typeof module === 'string' || module instanceof URL) {
|
|
80
|
+
const response = await fetch(module);
|
|
81
|
+
const { instance: inst } = await WebAssembly.instantiateStreaming(
|
|
82
|
+
response,
|
|
83
|
+
{
|
|
84
|
+
'./loro_wasm_bg.js': imports,
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
instance = inst;
|
|
88
|
+
} else {
|
|
89
|
+
console.error('Unsupported wasm import type:', module);
|
|
90
|
+
throw new Error('Unsupported wasm import type: ' + typeof module);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
finalize(instance.exports ?? instance);
|
|
33
94
|
}
|
|
34
|
-
|
|
95
|
+
|
|
96
|
+
export * from './loro_wasm_bg.js';
|