lody 0.62.0 → 0.63.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.
@@ -0,0 +1,311 @@
1
+ import { i as imports, g as __wbg_set_wasm, r as rawWasm, e as LoroDoc, E as EphemeralStoreWasm, U as UndoManager, h as callPendingEvents, __tla as __tla_0 } from "./loro_wasm_bg-N-tMVpou.js";
2
+ let EphemeralStore, isContainerId, isContainer, replayTurnDiffText, turnDiffReplay;
3
+ let __tla = Promise.all([
4
+ (() => {
5
+ try {
6
+ return __tla_0;
7
+ } catch {
8
+ }
9
+ })()
10
+ ]).then(async () => {
11
+ const toModuleOrExports = (wasm) => {
12
+ if (!wasm) return wasm;
13
+ if (wasm instanceof WebAssembly.Module) return wasm;
14
+ if (typeof wasm === "object" && "default" in wasm) {
15
+ return wasm.default ?? wasm;
16
+ }
17
+ return wasm;
18
+ };
19
+ const wasmModuleOrExports = toModuleOrExports(rawWasm);
20
+ const finalize = (exports$1) => {
21
+ __wbg_set_wasm(exports$1);
22
+ tryStart(imports);
23
+ };
24
+ function tryStart(imports2) {
25
+ if (typeof imports2.__wbindgen_start === "function") {
26
+ imports2.__wbindgen_start();
27
+ }
28
+ }
29
+ if (wasmModuleOrExports && wasmModuleOrExports.__wbindgen_start) {
30
+ finalize(wasmModuleOrExports);
31
+ } else if ("Bun" in globalThis) {
32
+ let instance;
33
+ if (wasmModuleOrExports instanceof WebAssembly.Module) {
34
+ ({ instance } = await WebAssembly.instantiate(wasmModuleOrExports, {
35
+ "./loro_wasm_bg.js": imports
36
+ }));
37
+ } else {
38
+ const url = Bun.pathToFileURL(wasmModuleOrExports);
39
+ ({ instance } = await WebAssembly.instantiateStreaming(fetch(url), {
40
+ "./loro_wasm_bg.js": imports
41
+ }));
42
+ }
43
+ finalize(instance.exports);
44
+ } else {
45
+ const wkmod = wasmModuleOrExports instanceof WebAssembly.Module ? wasmModuleOrExports : await import("./loro_wasm_bg-N-tMVpou.js").then(async (m) => {
46
+ await m.__tla;
47
+ return m;
48
+ }).then((n) => n.r);
49
+ const module = wkmod instanceof WebAssembly.Module ? wkmod : wkmod && wkmod.default || wkmod;
50
+ let instance;
51
+ if (module instanceof WebAssembly.Instance) {
52
+ instance = module;
53
+ } else if (module instanceof WebAssembly.Module) {
54
+ instance = await WebAssembly.instantiate(module, {
55
+ "./loro_wasm_bg.js": imports
56
+ });
57
+ } else if (module instanceof ArrayBuffer || ArrayBuffer.isView(module)) {
58
+ const { instance: inst } = await WebAssembly.instantiate(module, {
59
+ "./loro_wasm_bg.js": imports
60
+ });
61
+ instance = inst;
62
+ } else if (typeof module === "string" || module instanceof URL) {
63
+ const response = await fetch(module);
64
+ const { instance: inst } = await WebAssembly.instantiateStreaming(response, {
65
+ "./loro_wasm_bg.js": imports
66
+ });
67
+ instance = inst;
68
+ } else {
69
+ console.error("Unsupported wasm import type:", module);
70
+ throw new Error("Unsupported wasm import type: " + typeof module);
71
+ }
72
+ finalize(instance.exports ?? instance);
73
+ }
74
+ const CONTAINER_TYPES = [
75
+ "Map",
76
+ "Text",
77
+ "List",
78
+ "Tree",
79
+ "MovableList",
80
+ "Counter"
81
+ ];
82
+ isContainerId = function(s) {
83
+ return s.startsWith("cid:");
84
+ };
85
+ isContainer = function(value) {
86
+ if (typeof value !== "object" || value == null) {
87
+ return false;
88
+ }
89
+ const p = Object.getPrototypeOf(value);
90
+ if (p == null || typeof p !== "object" || typeof p["kind"] !== "function") {
91
+ return false;
92
+ }
93
+ return CONTAINER_TYPES.includes(value.kind());
94
+ };
95
+ EphemeralStore = class {
96
+ constructor(timeout = 3e4) {
97
+ this.inner = new EphemeralStoreWasm(timeout);
98
+ this.timeout = timeout;
99
+ }
100
+ apply(bytes) {
101
+ this.inner.apply(bytes);
102
+ this.startTimerIfNotEmpty();
103
+ }
104
+ set(key, value) {
105
+ this.inner.set(key, value);
106
+ this.startTimerIfNotEmpty();
107
+ }
108
+ delete(key) {
109
+ this.inner.delete(key);
110
+ }
111
+ get(key) {
112
+ return this.inner.get(key);
113
+ }
114
+ getAllStates() {
115
+ return this.inner.getAllStates();
116
+ }
117
+ encode(key) {
118
+ return this.inner.encode(key);
119
+ }
120
+ encodeAll() {
121
+ return this.inner.encodeAll();
122
+ }
123
+ keys() {
124
+ return this.inner.keys();
125
+ }
126
+ destroy() {
127
+ clearInterval(this.timer);
128
+ }
129
+ subscribe(listener) {
130
+ return this.inner.subscribe(listener);
131
+ }
132
+ subscribeLocalUpdates(listener) {
133
+ return this.inner.subscribeLocalUpdates(listener);
134
+ }
135
+ startTimerIfNotEmpty() {
136
+ if (this.inner.isEmpty() || this.timer != null) {
137
+ return;
138
+ }
139
+ this.timer = setInterval(() => {
140
+ this.inner.removeOutdated();
141
+ if (this.inner.isEmpty()) {
142
+ clearInterval(this.timer);
143
+ this.timer = void 0;
144
+ }
145
+ }, this.timeout / 2);
146
+ }
147
+ };
148
+ LoroDoc.prototype.toJsonWithReplacer = function(replacer) {
149
+ const processed = /* @__PURE__ */ new Set();
150
+ const doc = this;
151
+ const m = (key, value) => {
152
+ if (typeof value === "string") {
153
+ if (isContainerId(value) && !processed.has(value)) {
154
+ processed.add(value);
155
+ const container = doc.getContainerById(value);
156
+ if (container == null) {
157
+ throw new Error(`ContainerID not found: ${value}`);
158
+ }
159
+ const ans2 = replacer(key, container);
160
+ if (ans2 === container) {
161
+ const ans3 = container.getShallowValue();
162
+ if (typeof ans3 === "object") {
163
+ return run(ans3);
164
+ }
165
+ return ans3;
166
+ }
167
+ if (isContainer(ans2)) {
168
+ throw new Error("Using new container is not allowed in toJsonWithReplacer");
169
+ }
170
+ if (typeof ans2 === "object" && ans2 != null) {
171
+ return run(ans2);
172
+ }
173
+ return ans2;
174
+ }
175
+ }
176
+ if (typeof value === "object" && value != null) {
177
+ return run(value);
178
+ }
179
+ const ans = replacer(key, value);
180
+ if (isContainer(ans)) {
181
+ throw new Error("Using new container is not allowed in toJsonWithReplacer");
182
+ }
183
+ return ans;
184
+ };
185
+ const run = (layer2) => {
186
+ if (Array.isArray(layer2)) {
187
+ return layer2.map((item, index) => {
188
+ return m(index, item);
189
+ }).filter((item) => item !== void 0);
190
+ }
191
+ const result = {};
192
+ for (const [key, value] of Object.entries(layer2)) {
193
+ const ans = m(key, value);
194
+ if (ans !== void 0) {
195
+ result[key] = ans;
196
+ }
197
+ }
198
+ return result;
199
+ };
200
+ const layer = doc.getShallowValue();
201
+ return run(layer);
202
+ };
203
+ const CALL_PENDING_EVENTS_WRAPPED = Symbol("loro.callPendingEventsWrapped");
204
+ function decorateMethod(prototype, method) {
205
+ const descriptor = Object.getOwnPropertyDescriptor(prototype, method);
206
+ if (!descriptor || typeof descriptor.value !== "function") {
207
+ return;
208
+ }
209
+ const original = descriptor.value;
210
+ if (original[CALL_PENDING_EVENTS_WRAPPED]) {
211
+ return;
212
+ }
213
+ const wrapped = function(...args) {
214
+ let result;
215
+ try {
216
+ result = original.apply(this, args);
217
+ return result;
218
+ } finally {
219
+ if (result && typeof result.then === "function") {
220
+ result.finally(() => {
221
+ callPendingEvents();
222
+ });
223
+ } else {
224
+ callPendingEvents();
225
+ }
226
+ }
227
+ };
228
+ wrapped[CALL_PENDING_EVENTS_WRAPPED] = true;
229
+ Object.defineProperty(prototype, method, {
230
+ ...descriptor,
231
+ value: wrapped
232
+ });
233
+ }
234
+ function decorateMethods(prototype, methods) {
235
+ for (const method of methods) {
236
+ decorateMethod(prototype, method);
237
+ }
238
+ }
239
+ decorateMethods(LoroDoc.prototype, [
240
+ "setDetachedEditing",
241
+ "attach",
242
+ "detach",
243
+ "fork",
244
+ "forkAt",
245
+ "checkoutToLatest",
246
+ "checkout",
247
+ "commit",
248
+ "getCursorPos",
249
+ "revertTo",
250
+ "export",
251
+ "exportJsonUpdates",
252
+ "exportJsonInIdSpan",
253
+ "importJsonUpdates",
254
+ "import",
255
+ "importUpdateBatch",
256
+ "importBatch",
257
+ "travelChangeAncestors",
258
+ "getChangedContainersIn",
259
+ "diff",
260
+ "applyDiff",
261
+ "setPeerId"
262
+ ]);
263
+ decorateMethods(EphemeralStoreWasm.prototype, [
264
+ "set",
265
+ "delete",
266
+ "apply",
267
+ "removeOutdated"
268
+ ]);
269
+ decorateMethods(UndoManager.prototype, [
270
+ "undo",
271
+ "redo"
272
+ ]);
273
+ function textAtForkedDoc(doc) {
274
+ const present = doc.getMap("meta").get("present");
275
+ if (present !== true) {
276
+ return null;
277
+ }
278
+ return doc.getText("text").toString();
279
+ }
280
+ replayTurnDiffText = function(input) {
281
+ try {
282
+ const doc = new LoroDoc();
283
+ doc.import(input.snapshot);
284
+ const oldDoc = doc.forkAt(JSON.parse(input.oldFrontiersJson));
285
+ const newDoc = doc.forkAt(JSON.parse(input.newFrontiersJson));
286
+ return {
287
+ status: "ready",
288
+ oldText: textAtForkedDoc(oldDoc),
289
+ newText: textAtForkedDoc(newDoc)
290
+ };
291
+ } catch {
292
+ return {
293
+ status: "unavailable"
294
+ };
295
+ }
296
+ };
297
+ turnDiffReplay = Object.freeze(Object.defineProperty({
298
+ __proto__: null,
299
+ replayTurnDiffText
300
+ }, Symbol.toStringTag, {
301
+ value: "Module"
302
+ }));
303
+ });
304
+ export {
305
+ EphemeralStore as E,
306
+ __tla,
307
+ isContainerId as a,
308
+ isContainer as i,
309
+ replayTurnDiffText as r,
310
+ turnDiffReplay as t
311
+ };
@@ -0,0 +1,11 @@
1
+ import { c as computeLineCounts } from "./chunks/diff-line-counts-BLxwWP6r.js";
2
+ import "node:child_process";
3
+ import "node:fs";
4
+ import "node:os";
5
+ import "node:path";
6
+ function diffWorker(input) {
7
+ return computeLineCounts(input.oldText, input.newText);
8
+ }
9
+ export {
10
+ diffWorker as default
11
+ };