@pluv/crdt-loro 0.18.0 → 0.20.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/dist/index.js CHANGED
@@ -44,498 +44,68 @@ module.exports = __toCommonJS(src_exports);
44
44
  // src/loro.ts
45
45
  var loro_exports = {};
46
46
  __export(loro_exports, {
47
- CrdtLoroArray: () => CrdtLoroArray,
48
47
  CrdtLoroDoc: () => CrdtLoroDoc,
49
- CrdtLoroMap: () => CrdtLoroMap,
50
- CrdtLoroObject: () => CrdtLoroObject,
51
- CrdtLoroText: () => CrdtLoroText,
52
- array: () => array,
53
48
  doc: () => doc,
49
+ list: () => list,
54
50
  map: () => map,
55
51
  object: () => object,
56
52
  text: () => text
57
53
  });
58
54
 
59
- // src/array/CrdtLoroArray.ts
60
- var import_crdt5 = require("@pluv/crdt");
61
- var import_loro_crdt4 = require("loro-crdt");
62
-
63
- // src/shared/cloneType.ts
64
- var import_crdt4 = require("@pluv/crdt");
65
-
66
- // src/map/CrdtLoroMap.ts
67
- var import_crdt = require("@pluv/crdt");
68
- var import_loro_crdt = require("loro-crdt");
69
- var CrdtLoroMap = class extends import_crdt.AbstractCrdtType {
70
- constructor(value = []) {
71
- super();
72
- this._doc = null;
73
- this._initialized = false;
74
- this._value = new import_loro_crdt.LoroMap();
75
- this.initialValue = value.map(([k, v]) => [k, v]);
76
- }
77
- set doc(doc2) {
78
- if (this._doc)
79
- throw new Error("Cannot overwrite array doc");
80
- this._doc = doc2;
81
- }
82
- get size() {
83
- return this.value.size;
84
- }
85
- get value() {
86
- return this._value;
87
- }
88
- set value(value) {
89
- if (this._initialized)
90
- throw new Error("Cannot re-assign map");
91
- this._initialized = true;
92
- this._value = value;
93
- cloneType({ source: this, target: this.value });
94
- }
95
- delete(prop) {
96
- var _a;
97
- this._guardInitialized();
98
- this.value.delete(prop);
99
- (_a = this._doc) == null ? void 0 : _a.value.commit();
100
- return this;
101
- }
102
- set(prop, value) {
103
- var _a, _b;
104
- this._guardInitialized();
105
- if (!(value instanceof import_crdt.AbstractCrdtType)) {
106
- this.value.set(prop, value);
107
- (_a = this._doc) == null ? void 0 : _a.value.commit();
108
- return this;
109
- }
110
- if (!isWrapper(value)) {
111
- throw new Error("This type is not yet supported");
112
- }
113
- const containerType = getLoroContainerType(value);
114
- const container = this.value.setContainer(prop, containerType);
115
- cloneType({ source: value, target: container });
116
- if (this._doc)
117
- value.doc = this._doc;
118
- (_b = this._doc) == null ? void 0 : _b.value.commit();
119
- return this;
120
- }
121
- toJson() {
122
- return this.value.toJson();
123
- }
124
- _guardInitialized() {
125
- if (!this._initialized)
126
- throw new Error("Array is not yet initialized");
127
- }
128
- };
129
-
130
- // src/map/map.ts
131
- var map = (value = []) => {
132
- return new CrdtLoroMap(value);
133
- };
134
-
135
- // src/object/CrdtLoroObject.ts
136
- var import_crdt2 = require("@pluv/crdt");
137
- var import_loro_crdt2 = require("loro-crdt");
138
- var CrdtLoroObject = class extends import_crdt2.AbstractCrdtType {
139
- constructor(value) {
140
- super();
141
- this._doc = null;
142
- this._initialized = false;
143
- this._value = new import_loro_crdt2.LoroMap();
144
- this.initialValue = Object.entries(value).map(([k, v]) => [k, v]);
145
- }
146
- set doc(doc2) {
147
- if (this._doc)
148
- throw new Error("Cannot overwrite array doc");
149
- this._doc = doc2;
150
- }
151
- get size() {
152
- return this.value.size;
153
- }
154
- get value() {
155
- return this._value;
156
- }
157
- set value(value) {
158
- if (this._initialized)
159
- throw new Error("Cannot re-assign map");
160
- this._initialized = true;
161
- this._value = value;
162
- cloneType({ source: this, target: this.value });
163
- }
164
- set(prop, value) {
165
- var _a, _b;
166
- this._guardInitialized();
167
- if (!(value instanceof import_crdt2.AbstractCrdtType)) {
168
- this.value.set(prop, value);
169
- (_a = this._doc) == null ? void 0 : _a.value.commit();
170
- return this;
171
- }
172
- if (!isWrapper(value)) {
173
- throw new Error("This type is not yet supported");
174
- }
175
- const containerType = getLoroContainerType(value);
176
- const container = this.value.setContainer(prop, containerType);
177
- cloneType({ source: value, target: container });
178
- if (this._doc)
179
- value.doc = this._doc;
180
- (_b = this._doc) == null ? void 0 : _b.value.commit();
181
- return this;
182
- }
183
- toJson() {
184
- return this.value.toJson();
185
- }
186
- _guardInitialized() {
187
- if (!this._initialized)
188
- throw new Error("Array is not yet initialized");
189
- }
190
- };
191
-
192
- // src/object/object.ts
193
- var object = (value) => {
194
- return new CrdtLoroObject(value);
195
- };
196
-
197
- // src/text/CrdtLoroText.ts
198
- var import_crdt3 = require("@pluv/crdt");
199
- var import_loro_crdt3 = require("loro-crdt");
200
- var CrdtLoroText = class extends import_crdt3.AbstractCrdtType {
201
- constructor(value = "") {
202
- super();
203
- this._doc = null;
204
- this._initialized = false;
205
- this._value = new import_loro_crdt3.LoroText();
206
- this.initalValue = value;
207
- this.value = new import_loro_crdt3.LoroText();
208
- }
209
- set doc(doc2) {
210
- if (this._doc)
211
- throw new Error("Cannot overwrite array doc");
212
- this._doc = doc2;
213
- }
214
- get length() {
215
- return this.value.length;
216
- }
217
- get value() {
218
- return this._value;
219
- }
220
- set value(value) {
221
- if (this._initialized)
222
- throw new Error("Cannot re-assign text");
223
- this._initialized = true;
224
- this._value = value;
225
- cloneType({ source: this, target: this.value });
226
- }
227
- delete(index, length = 1) {
228
- var _a;
229
- this._guardInitialized();
230
- this.value.delete(index, length);
231
- (_a = this._doc) == null ? void 0 : _a.value.commit();
232
- return this;
233
- }
234
- insert(index, text2) {
235
- var _a;
236
- this._guardInitialized();
237
- this.value.insert(index, text2);
238
- (_a = this._doc) == null ? void 0 : _a.value.commit();
239
- return this;
240
- }
241
- toJson() {
242
- return this.value.toString();
243
- }
244
- _guardInitialized() {
245
- if (!this._initialized)
246
- throw new Error("Array is not yet initialized");
247
- }
248
- };
249
-
250
- // src/text/text.ts
251
- var text = (value = "") => {
252
- return new CrdtLoroText(value);
253
- };
254
-
255
- // src/shared/cloneType.ts
256
- function cloneArray(params) {
257
- const { source, target } = params;
258
- const items = source.initialValue;
259
- items.forEach((item, i) => {
260
- if (!(item instanceof import_crdt4.AbstractCrdtType)) {
261
- target.insert(i, item);
262
- return;
263
- }
264
- if (item instanceof CrdtLoroArray) {
265
- const list = target.insertContainer(i, "List");
266
- item.value = list;
267
- cloneArray({ source: item, target: list });
268
- return;
269
- }
270
- if (item instanceof CrdtLoroMap) {
271
- const map2 = target.insertContainer(i, "Map");
272
- item.value = map2;
273
- cloneMap({ source: item, target: map2 });
274
- return;
275
- }
276
- if (item instanceof CrdtLoroObject) {
277
- const map2 = target.insertContainer(i, "Map");
278
- item.value = map2;
279
- cloneObject({ source: item, target: map2 });
280
- return;
281
- }
282
- if (item instanceof CrdtLoroText) {
283
- const text2 = target.insertContainer(i, "Text");
284
- item.value = text2;
285
- cloneText({ source: item, target: text2 });
286
- return;
287
- }
288
- throw new Error("This type is not yet supported");
289
- });
290
- }
291
- function cloneMap(params) {
292
- const { source, target } = params;
293
- const items = source.initialValue;
294
- items.forEach(([key, item]) => {
295
- if (!(item instanceof import_crdt4.AbstractCrdtType)) {
296
- target.set(key, item);
297
- return;
298
- }
299
- if (item instanceof CrdtLoroArray) {
300
- const list = target.setContainer(key, "List");
301
- item.value = list;
302
- cloneArray({ source: item, target: list });
303
- return;
304
- }
305
- if (item instanceof CrdtLoroMap) {
306
- const map2 = target.setContainer(key, "Map");
307
- item.value = map2;
308
- cloneMap({ source: item, target: map2 });
309
- return;
310
- }
311
- if (item instanceof CrdtLoroObject) {
312
- const map2 = target.setContainer(key, "Map");
313
- item.value = map2;
314
- cloneObject({ source: item, target: map2 });
315
- return;
316
- }
317
- if (item instanceof CrdtLoroText) {
318
- const text2 = target.setContainer(key, "Text");
319
- item.value = text2;
320
- cloneText({ source: item, target: text2 });
321
- return;
322
- }
323
- throw new Error("This type is not yet supported");
324
- });
325
- }
326
- function cloneObject(params) {
327
- const { source, target } = params;
328
- const items = source.initialValue;
329
- items.forEach(([key, item]) => {
330
- if (!(item instanceof import_crdt4.AbstractCrdtType)) {
331
- target.set(key, item);
332
- return;
333
- }
334
- if (item instanceof CrdtLoroArray) {
335
- const list = target.setContainer(key, "List");
336
- item.value = list;
337
- cloneArray({ source: item, target: list });
338
- return;
339
- }
340
- if (item instanceof CrdtLoroMap) {
341
- const map2 = target.setContainer(key, "Map");
342
- item.value = map2;
343
- cloneMap({ source: item, target: map2 });
344
- return;
345
- }
346
- if (item instanceof CrdtLoroObject) {
347
- const map2 = target.setContainer(key, "Map");
348
- item.value = map2;
349
- cloneObject({ source: item, target: map2 });
350
- return;
351
- }
352
- if (item instanceof CrdtLoroText) {
353
- const text2 = target.setContainer(key, "Text");
354
- item.value = text2;
355
- cloneText({ source: item, target: text2 });
356
- return;
357
- }
358
- throw new Error("This type is not yet supported");
359
- });
360
- }
361
- function cloneText(params) {
362
- const { source, target } = params;
363
- source.value = target;
364
- source.insert(0, source.initalValue);
365
- }
366
- var cloneType = (params) => {
367
- const { source, target } = params;
368
- if (source instanceof CrdtLoroArray) {
369
- cloneArray({ source, target });
370
- return;
371
- }
372
- if (source instanceof CrdtLoroMap) {
373
- cloneMap({ source, target });
374
- return;
375
- }
376
- if (source instanceof CrdtLoroObject) {
377
- cloneObject({ source, target });
378
- return;
379
- }
380
- if (source instanceof CrdtLoroText) {
381
- cloneText({ source, target });
382
- return;
383
- }
384
- throw new Error("This type is not yet supported");
385
- };
386
-
387
- // src/shared/getLoroContainerType.ts
388
- var getLoroContainerType = (value) => {
389
- if (value instanceof CrdtLoroArray)
390
- return "List";
391
- if (value instanceof CrdtLoroMap)
392
- return "Map";
393
- if (value instanceof CrdtLoroObject)
394
- return "Map";
395
- if (value instanceof CrdtLoroText)
396
- return "Text";
397
- throw new Error("This type is not yet supported");
398
- };
399
-
400
- // src/shared/isWrapper.ts
401
- var isWrapper = (item) => {
402
- return item instanceof CrdtLoroArray || item instanceof CrdtLoroMap || item instanceof CrdtLoroObject || item instanceof CrdtLoroText;
403
- };
404
-
405
- // src/array/CrdtLoroArray.ts
406
- var CrdtLoroArray = class extends import_crdt5.AbstractCrdtType {
407
- constructor(value = []) {
408
- super();
409
- this._doc = null;
410
- this._initialized = false;
411
- this._value = new import_loro_crdt4.LoroList();
412
- this.initialValue = value.slice();
413
- }
414
- set doc(doc2) {
415
- if (this._doc)
416
- throw new Error("Cannot overwrite array doc");
417
- this._doc = doc2;
418
- }
419
- get length() {
420
- return this.value.length;
421
- }
422
- get value() {
423
- return this._value;
424
- }
425
- set value(value) {
426
- if (this._initialized)
427
- throw new Error("Cannot re-assign array");
428
- this._initialized = true;
429
- this._value = value;
430
- cloneType({ source: this, target: this.value });
431
- }
432
- delete(index, length = 1) {
433
- var _a;
434
- this._guardInitialized();
435
- this.value.delete(index, length);
436
- (_a = this._doc) == null ? void 0 : _a.value.commit();
437
- return this;
438
- }
439
- insert(index, ...items) {
440
- var _a;
441
- this._guardInitialized();
442
- items.forEach((item, i) => {
443
- var _a2;
444
- if (!(item instanceof import_crdt5.AbstractCrdtType)) {
445
- this.value.insert(index + i, item);
446
- (_a2 = this._doc) == null ? void 0 : _a2.value.commit();
447
- return this;
448
- }
449
- if (!isWrapper(item)) {
450
- throw new Error("This type is not yet supported");
451
- }
452
- const containerType = getLoroContainerType(item);
453
- const container = this.value.insertContainer(index + i, containerType);
454
- cloneType({ source: item, target: container });
455
- if (this._doc)
456
- item.doc = this._doc;
457
- return this;
458
- });
459
- (_a = this._doc) == null ? void 0 : _a.value.commit();
460
- return this;
461
- }
462
- push(...items) {
463
- return this.insert(this.length, ...items);
464
- }
465
- unshift(...items) {
466
- return this.insert(0, ...items);
467
- }
468
- toJson() {
469
- return this.value.toJson();
470
- }
471
- _guardInitialized() {
472
- if (!this._initialized)
473
- throw new Error("Array is not yet initialized");
474
- }
475
- };
476
-
477
- // src/array/array.ts
478
- var array = (value = []) => {
479
- return new CrdtLoroArray(value);
480
- };
481
-
482
55
  // src/doc/CrdtLoroDoc.ts
483
- var import_crdt6 = require("@pluv/crdt");
56
+ var import_crdt = require("@pluv/crdt");
484
57
  var import_js_base64 = require("js-base64");
485
- var import_loro_crdt5 = require("loro-crdt");
486
- var CrdtLoroDoc = class extends import_crdt6.AbstractCrdtDoc {
58
+ var import_loro_crdt = require("loro-crdt");
59
+ var CrdtLoroDoc = class extends import_crdt.AbstractCrdtDoc {
487
60
  constructor(value = {}) {
488
61
  super();
489
- this.value = new import_loro_crdt5.Loro();
62
+ this.value = new import_loro_crdt.Loro();
490
63
  this._storage = Object.entries(value).reduce((acc, [key, node]) => {
491
- if (node instanceof CrdtLoroArray) {
492
- const loroList = this.value.getList(key);
493
- node.value = loroList;
494
- node.doc = this;
495
- return __spreadProps(__spreadValues({}, acc), { [key]: node });
64
+ if (node instanceof import_loro_crdt.LoroList) {
65
+ const container = this.value.getList(key);
66
+ node.toArray().forEach((item, i) => {
67
+ (0, import_loro_crdt.isContainer)(item) ? container.insertContainer(i, item) : container.insert(i, item);
68
+ });
69
+ return __spreadProps(__spreadValues({}, acc), { [key]: container });
496
70
  }
497
- if (node instanceof CrdtLoroMap || node instanceof CrdtLoroObject) {
498
- const loroMap = this.value.getMap(key);
499
- node.value = loroMap;
500
- node.doc = this;
501
- return __spreadProps(__spreadValues({}, acc), { [key]: node });
71
+ if (node instanceof import_loro_crdt.LoroMap) {
72
+ const container = this.value.getMap(key);
73
+ container.entries().forEach(([key2, item]) => {
74
+ (0, import_loro_crdt.isContainer)(item) ? container.setContainer(key2, item) : container.set(key2, item);
75
+ });
76
+ return __spreadProps(__spreadValues({}, acc), { [key]: container });
502
77
  }
503
- if (node instanceof CrdtLoroText) {
504
- const loroText = this.value.getText(key);
505
- node.value = loroText;
506
- node.doc = this;
507
- return __spreadProps(__spreadValues({}, acc), { [key]: loroText });
78
+ if (node instanceof import_loro_crdt.LoroText) {
79
+ const container = this.value.getText(key);
80
+ container.insert(0, node.toString());
81
+ return __spreadProps(__spreadValues({}, acc), { [key]: container });
508
82
  }
509
83
  return acc;
510
84
  }, {});
511
85
  }
512
86
  applyEncodedState(params) {
513
87
  const update = typeof params.update === "string" ? (0, import_js_base64.toUint8Array)(params.update) : params.update;
514
- if (!update)
515
- return this;
88
+ if (!update) return this;
516
89
  this.value.import(update);
517
90
  return this;
518
91
  }
519
92
  batchApplyEncodedState(updates) {
520
93
  var _a;
521
94
  const _updates = updates.reduce((acc, item) => {
522
- if (!item)
523
- return acc;
95
+ if (!item) return acc;
524
96
  if (typeof item === "string") {
525
97
  acc.push((0, import_js_base64.toUint8Array)(item));
526
98
  return acc;
527
99
  }
528
100
  if (typeof item === "object") {
529
101
  const update = typeof item.update === "string" ? (0, import_js_base64.toUint8Array)(item.update) : item.update;
530
- if (!update)
531
- return acc;
102
+ if (!update) return acc;
532
103
  acc.push(update);
533
104
  return acc;
534
105
  }
535
106
  return acc;
536
107
  }, []);
537
- if (!_updates.length)
538
- return this;
108
+ if (!_updates.length) return this;
539
109
  if (_updates.length === 1) {
540
110
  const update = (_a = _updates[0]) != null ? _a : null;
541
111
  update && this.value.import(update);
@@ -562,21 +132,26 @@ var CrdtLoroDoc = class extends import_crdt6.AbstractCrdtDoc {
562
132
  return;
563
133
  }
564
134
  get(key) {
565
- if (typeof key === "undefined")
566
- return this._storage;
135
+ if (typeof key === "undefined") return this._storage;
567
136
  return this._storage[key];
568
137
  }
569
138
  getEncodedState() {
570
139
  return (0, import_js_base64.fromUint8Array)(this.value.exportSnapshot());
571
140
  }
572
- toJson() {
141
+ toJson(type) {
142
+ if (typeof type === "string") {
143
+ const container = this._storage[type];
144
+ return container instanceof import_loro_crdt.LoroText ? container.toString() : container.toJSON();
145
+ }
573
146
  return Object.entries(this._storage).reduce(
574
- (acc, [key, value]) => __spreadProps(__spreadValues({}, acc), { [key]: value.toJson() }),
147
+ (acc, [key, value]) => __spreadProps(__spreadValues({}, acc), {
148
+ [key]: value instanceof import_loro_crdt.LoroText ? value.toString() : value.toJSON()
149
+ }),
575
150
  {}
576
151
  );
577
152
  }
578
153
  isEmpty() {
579
- const serialized = this.value.toJson();
154
+ const serialized = this.value.toJSON();
580
155
  return !serialized || !Object.keys(serialized).length;
581
156
  }
582
157
  /**
@@ -591,24 +166,24 @@ var CrdtLoroDoc = class extends import_crdt6.AbstractCrdtDoc {
591
166
  const update = (0, import_js_base64.fromUint8Array)(this.value.exportFrom());
592
167
  listener({
593
168
  doc: this,
594
- local: event.local,
169
+ local: event.by === "local",
595
170
  origin: event.origin ? String(event.origin) : null,
596
171
  update
597
172
  });
598
173
  };
599
174
  const subscriptionIds = Object.entries(this._storage).reduce((map2, [key, crdtType]) => {
600
- const container = crdtType.value;
601
- const subscriptionId = container.subscribe(this.value, fn);
175
+ const container = crdtType;
176
+ const subscriptionId = container.subscribe(fn);
602
177
  return map2.set(key, subscriptionId);
603
178
  }, /* @__PURE__ */ new Map());
604
179
  return () => {
605
180
  Array.from(subscriptionIds.entries()).forEach(([key, subscriptionId]) => {
606
- var _a, _b;
607
- const container = (_b = (_a = this._storage[key]) == null ? void 0 : _a.value) != null ? _b : null;
181
+ var _a;
182
+ const container = (_a = this._storage[key]) != null ? _a : null;
608
183
  if (!container) {
609
184
  throw new Error("Storage could not be found");
610
185
  }
611
- container.unsubscribe(this.value, subscriptionId);
186
+ container.unsubscribe(subscriptionId);
612
187
  });
613
188
  };
614
189
  }
@@ -625,6 +200,7 @@ var CrdtLoroDoc = class extends import_crdt6.AbstractCrdtDoc {
625
200
  */
626
201
  transact(fn) {
627
202
  fn();
203
+ this.value.commit();
628
204
  return this;
629
205
  }
630
206
  /**
@@ -637,8 +213,9 @@ var CrdtLoroDoc = class extends import_crdt6.AbstractCrdtDoc {
637
213
  };
638
214
 
639
215
  // src/doc/CrdtLoroDocFactory.ts
640
- var import_crdt7 = require("@pluv/crdt");
641
- var CrdtLoroDocFactory = class _CrdtLoroDocFactory extends import_crdt7.AbstractCrdtDocFactory {
216
+ var import_crdt2 = require("@pluv/crdt");
217
+ var import_loro_crdt2 = require("loro-crdt");
218
+ var CrdtLoroDocFactory = class _CrdtLoroDocFactory extends import_crdt2.AbstractCrdtDocFactory {
642
219
  constructor(initialStorage = () => ({})) {
643
220
  super();
644
221
  this._initialStorage = initialStorage;
@@ -653,17 +230,14 @@ var CrdtLoroDocFactory = class _CrdtLoroDocFactory extends import_crdt7.Abstract
653
230
  const storage = this._initialStorage();
654
231
  return new CrdtLoroDoc(
655
232
  Object.entries(storage).reduce((acc, [key, node]) => {
656
- if (node instanceof CrdtLoroArray) {
657
- return __spreadProps(__spreadValues({}, acc), { [key]: new CrdtLoroArray([]) });
233
+ if (node instanceof import_loro_crdt2.LoroList) {
234
+ return __spreadProps(__spreadValues({}, acc), { [key]: new import_loro_crdt2.LoroList() });
658
235
  }
659
- if (node instanceof CrdtLoroMap) {
660
- return __spreadProps(__spreadValues({}, acc), { [key]: new CrdtLoroMap([]) });
236
+ if (node instanceof import_loro_crdt2.LoroMap) {
237
+ return __spreadProps(__spreadValues({}, acc), { [key]: new import_loro_crdt2.LoroMap() });
661
238
  }
662
- if (node instanceof CrdtLoroObject) {
663
- return __spreadProps(__spreadValues({}, acc), { [key]: new CrdtLoroObject({}) });
664
- }
665
- if (node instanceof CrdtLoroText) {
666
- return __spreadProps(__spreadValues({}, acc), { [key]: new CrdtLoroText("") });
239
+ if (node instanceof import_loro_crdt2.LoroText) {
240
+ return __spreadProps(__spreadValues({}, acc), { [key]: new import_loro_crdt2.LoroText() });
667
241
  }
668
242
  return acc;
669
243
  }, {})
@@ -679,6 +253,44 @@ var CrdtLoroDocFactory = class _CrdtLoroDocFactory extends import_crdt7.Abstract
679
253
  var doc = (value = () => ({})) => {
680
254
  return new CrdtLoroDocFactory(value);
681
255
  };
256
+
257
+ // src/list.ts
258
+ var import_loro_crdt3 = require("loro-crdt");
259
+ var list = (value = []) => {
260
+ const container = new import_loro_crdt3.LoroList();
261
+ value.forEach((item, i) => {
262
+ (0, import_loro_crdt3.isContainer)(item) ? container.insertContainer(i, item) : container.insert(i, item);
263
+ });
264
+ return container;
265
+ };
266
+
267
+ // src/map.ts
268
+ var import_loro_crdt4 = require("loro-crdt");
269
+ var map = (value = []) => {
270
+ const container = new import_loro_crdt4.LoroMap();
271
+ value.forEach(([key, item]) => {
272
+ (0, import_loro_crdt4.isContainer)(item) ? container.setContainer(key, item) : container.set(key, item);
273
+ });
274
+ return container;
275
+ };
276
+
277
+ // src/object.ts
278
+ var import_loro_crdt5 = require("loro-crdt");
279
+ var object = (value) => {
280
+ const container = new import_loro_crdt5.LoroMap();
281
+ Object.entries(value).forEach(([key, item]) => {
282
+ (0, import_loro_crdt5.isContainer)(item) ? container.setContainer(key, item) : container.set(key, item);
283
+ });
284
+ return container;
285
+ };
286
+
287
+ // src/text.ts
288
+ var import_loro_crdt6 = require("loro-crdt");
289
+ var text = (value = "") => {
290
+ const container = new import_loro_crdt6.LoroText();
291
+ container.insert(0, value);
292
+ return container;
293
+ };
682
294
  // Annotate the CommonJS export names for ESM import in node:
683
295
  0 && (module.exports = {
684
296
  loro