@inkandswitch/patchwork-pkg-base 0.0.7 → 0.0.8

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.
Files changed (48) hide show
  1. package/modules.json +4 -0
  2. package/package.json +1 -1
  3. package/packages/account-history/dist/assets/HistoryRecorder-HO_sxeuE.js +248 -0
  4. package/packages/account-history/dist/assets/HistoryRecorder-HO_sxeuE.js.map +1 -0
  5. package/packages/account-history/dist/assets/HistoryViewer-Ct5g7zek.js +308 -0
  6. package/packages/account-history/dist/assets/HistoryViewer-Ct5g7zek.js.map +1 -0
  7. package/packages/account-history/dist/assets/NotebookViewer-BkYJL6Jc.js +504 -0
  8. package/packages/account-history/dist/assets/NotebookViewer-BkYJL6Jc.js.map +1 -0
  9. package/packages/account-history/dist/assets/index-CFzuSuJg.js +148 -0
  10. package/packages/account-history/dist/assets/index-CFzuSuJg.js.map +1 -0
  11. package/packages/account-history/dist/assets/makeDocumentProjection-DXgEZYyv.js +706 -0
  12. package/packages/account-history/dist/assets/makeDocumentProjection-DXgEZYyv.js.map +1 -0
  13. package/packages/account-history/dist/assets/store-CRmRL4Cv.js +1079 -0
  14. package/packages/account-history/dist/assets/store-CRmRL4Cv.js.map +1 -0
  15. package/packages/account-history/dist/index.js +5 -0
  16. package/packages/account-history/dist/index.js.map +1 -0
  17. package/packages/account-history/package.json +33 -0
  18. package/packages/chat/dist/ChatRoot-BXsklgz7.js +6113 -0
  19. package/packages/chat/dist/context-tool-CenQrztX.js +107 -0
  20. package/packages/chat/dist/datatype-1niKKK-c.js +15 -0
  21. package/packages/chat/dist/index-DYFHDHZ9.js +368 -0
  22. package/packages/chat/dist/index.js +5 -0
  23. package/packages/chat/dist/tool-D9BTS5wc.js +38 -0
  24. package/packages/chat/package.json +42 -0
  25. package/packages/comments-view/dist/assets/comments-D9lwpHOh.js +50 -0
  26. package/packages/comments-view/dist/assets/comments-D9lwpHOh.js.map +1 -0
  27. package/packages/comments-view/dist/assets/datatype-C4SMwWiO.js +22 -0
  28. package/packages/comments-view/dist/assets/datatype-C4SMwWiO.js.map +1 -0
  29. package/packages/comments-view/dist/assets/main-C8GVksuY.js +2973 -0
  30. package/packages/comments-view/dist/assets/main-C8GVksuY.js.map +1 -0
  31. package/packages/comments-view/dist/index.js +115 -0
  32. package/packages/comments-view/dist/index.js.map +1 -0
  33. package/packages/comments-view/package.json +36 -0
  34. package/packages/drafts/dist/assets/DraftDatatype-Dn8VF6oC.js +14 -0
  35. package/packages/drafts/dist/assets/DraftDatatype-Dn8VF6oC.js.map +1 -0
  36. package/packages/drafts/dist/assets/DraftListProvider-DVhUGU1x.js +362 -0
  37. package/packages/drafts/dist/assets/DraftListProvider-DVhUGU1x.js.map +1 -0
  38. package/packages/drafts/dist/assets/DraftOverlayProvider-NMDqnpBV.js +123 -0
  39. package/packages/drafts/dist/assets/DraftOverlayProvider-NMDqnpBV.js.map +1 -0
  40. package/packages/drafts/dist/assets/clone-policy-D4XOfZxs.js +15 -0
  41. package/packages/drafts/dist/assets/clone-policy-D4XOfZxs.js.map +1 -0
  42. package/packages/drafts/dist/assets/index-DAqs20jZ.js +65 -0
  43. package/packages/drafts/dist/assets/index-DAqs20jZ.js.map +1 -0
  44. package/packages/drafts/dist/assets/main-Cdev7z-t.js +2366 -0
  45. package/packages/drafts/dist/assets/main-Cdev7z-t.js.map +1 -0
  46. package/packages/drafts/dist/index.js +140 -0
  47. package/packages/drafts/dist/index.js.map +1 -0
  48. package/packages/drafts/package.json +34 -0
@@ -0,0 +1,706 @@
1
+ import { o as onCleanup, a as createStore, r as reconcile, p as produce } from "./store-CRmRL4Cv.js";
2
+ function getDefaultExportFromCjs(x) {
3
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
4
+ }
5
+ var browser = { exports: {} };
6
+ var ms;
7
+ var hasRequiredMs;
8
+ function requireMs() {
9
+ if (hasRequiredMs) return ms;
10
+ hasRequiredMs = 1;
11
+ var s = 1e3;
12
+ var m = s * 60;
13
+ var h = m * 60;
14
+ var d = h * 24;
15
+ var w = d * 7;
16
+ var y = d * 365.25;
17
+ ms = function(val, options) {
18
+ options = options || {};
19
+ var type = typeof val;
20
+ if (type === "string" && val.length > 0) {
21
+ return parse(val);
22
+ } else if (type === "number" && isFinite(val)) {
23
+ return options.long ? fmtLong(val) : fmtShort(val);
24
+ }
25
+ throw new Error(
26
+ "val is not a non-empty string or a valid number. val=" + JSON.stringify(val)
27
+ );
28
+ };
29
+ function parse(str) {
30
+ str = String(str);
31
+ if (str.length > 100) {
32
+ return;
33
+ }
34
+ var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
35
+ str
36
+ );
37
+ if (!match) {
38
+ return;
39
+ }
40
+ var n = parseFloat(match[1]);
41
+ var type = (match[2] || "ms").toLowerCase();
42
+ switch (type) {
43
+ case "years":
44
+ case "year":
45
+ case "yrs":
46
+ case "yr":
47
+ case "y":
48
+ return n * y;
49
+ case "weeks":
50
+ case "week":
51
+ case "w":
52
+ return n * w;
53
+ case "days":
54
+ case "day":
55
+ case "d":
56
+ return n * d;
57
+ case "hours":
58
+ case "hour":
59
+ case "hrs":
60
+ case "hr":
61
+ case "h":
62
+ return n * h;
63
+ case "minutes":
64
+ case "minute":
65
+ case "mins":
66
+ case "min":
67
+ case "m":
68
+ return n * m;
69
+ case "seconds":
70
+ case "second":
71
+ case "secs":
72
+ case "sec":
73
+ case "s":
74
+ return n * s;
75
+ case "milliseconds":
76
+ case "millisecond":
77
+ case "msecs":
78
+ case "msec":
79
+ case "ms":
80
+ return n;
81
+ default:
82
+ return void 0;
83
+ }
84
+ }
85
+ function fmtShort(ms2) {
86
+ var msAbs = Math.abs(ms2);
87
+ if (msAbs >= d) {
88
+ return Math.round(ms2 / d) + "d";
89
+ }
90
+ if (msAbs >= h) {
91
+ return Math.round(ms2 / h) + "h";
92
+ }
93
+ if (msAbs >= m) {
94
+ return Math.round(ms2 / m) + "m";
95
+ }
96
+ if (msAbs >= s) {
97
+ return Math.round(ms2 / s) + "s";
98
+ }
99
+ return ms2 + "ms";
100
+ }
101
+ function fmtLong(ms2) {
102
+ var msAbs = Math.abs(ms2);
103
+ if (msAbs >= d) {
104
+ return plural(ms2, msAbs, d, "day");
105
+ }
106
+ if (msAbs >= h) {
107
+ return plural(ms2, msAbs, h, "hour");
108
+ }
109
+ if (msAbs >= m) {
110
+ return plural(ms2, msAbs, m, "minute");
111
+ }
112
+ if (msAbs >= s) {
113
+ return plural(ms2, msAbs, s, "second");
114
+ }
115
+ return ms2 + " ms";
116
+ }
117
+ function plural(ms2, msAbs, n, name) {
118
+ var isPlural = msAbs >= n * 1.5;
119
+ return Math.round(ms2 / n) + " " + name + (isPlural ? "s" : "");
120
+ }
121
+ return ms;
122
+ }
123
+ var common;
124
+ var hasRequiredCommon;
125
+ function requireCommon() {
126
+ if (hasRequiredCommon) return common;
127
+ hasRequiredCommon = 1;
128
+ function setup(env) {
129
+ createDebug.debug = createDebug;
130
+ createDebug.default = createDebug;
131
+ createDebug.coerce = coerce;
132
+ createDebug.disable = disable;
133
+ createDebug.enable = enable;
134
+ createDebug.enabled = enabled;
135
+ createDebug.humanize = requireMs();
136
+ createDebug.destroy = destroy;
137
+ Object.keys(env).forEach((key) => {
138
+ createDebug[key] = env[key];
139
+ });
140
+ createDebug.names = [];
141
+ createDebug.skips = [];
142
+ createDebug.formatters = {};
143
+ function selectColor(namespace) {
144
+ let hash = 0;
145
+ for (let i = 0; i < namespace.length; i++) {
146
+ hash = (hash << 5) - hash + namespace.charCodeAt(i);
147
+ hash |= 0;
148
+ }
149
+ return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
150
+ }
151
+ createDebug.selectColor = selectColor;
152
+ function createDebug(namespace) {
153
+ let prevTime;
154
+ let enableOverride = null;
155
+ let namespacesCache;
156
+ let enabledCache;
157
+ function debug2(...args) {
158
+ if (!debug2.enabled) {
159
+ return;
160
+ }
161
+ const self = debug2;
162
+ const curr = Number(/* @__PURE__ */ new Date());
163
+ const ms2 = curr - (prevTime || curr);
164
+ self.diff = ms2;
165
+ self.prev = prevTime;
166
+ self.curr = curr;
167
+ prevTime = curr;
168
+ args[0] = createDebug.coerce(args[0]);
169
+ if (typeof args[0] !== "string") {
170
+ args.unshift("%O");
171
+ }
172
+ let index = 0;
173
+ args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
174
+ if (match === "%%") {
175
+ return "%";
176
+ }
177
+ index++;
178
+ const formatter = createDebug.formatters[format];
179
+ if (typeof formatter === "function") {
180
+ const val = args[index];
181
+ match = formatter.call(self, val);
182
+ args.splice(index, 1);
183
+ index--;
184
+ }
185
+ return match;
186
+ });
187
+ createDebug.formatArgs.call(self, args);
188
+ const logFn = self.log || createDebug.log;
189
+ logFn.apply(self, args);
190
+ }
191
+ debug2.namespace = namespace;
192
+ debug2.useColors = createDebug.useColors();
193
+ debug2.color = createDebug.selectColor(namespace);
194
+ debug2.extend = extend;
195
+ debug2.destroy = createDebug.destroy;
196
+ Object.defineProperty(debug2, "enabled", {
197
+ enumerable: true,
198
+ configurable: false,
199
+ get: () => {
200
+ if (enableOverride !== null) {
201
+ return enableOverride;
202
+ }
203
+ if (namespacesCache !== createDebug.namespaces) {
204
+ namespacesCache = createDebug.namespaces;
205
+ enabledCache = createDebug.enabled(namespace);
206
+ }
207
+ return enabledCache;
208
+ },
209
+ set: (v) => {
210
+ enableOverride = v;
211
+ }
212
+ });
213
+ if (typeof createDebug.init === "function") {
214
+ createDebug.init(debug2);
215
+ }
216
+ return debug2;
217
+ }
218
+ function extend(namespace, delimiter) {
219
+ const newDebug = createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace);
220
+ newDebug.log = this.log;
221
+ return newDebug;
222
+ }
223
+ function enable(namespaces) {
224
+ createDebug.save(namespaces);
225
+ createDebug.namespaces = namespaces;
226
+ createDebug.names = [];
227
+ createDebug.skips = [];
228
+ const split = (typeof namespaces === "string" ? namespaces : "").trim().replace(/\s+/g, ",").split(",").filter(Boolean);
229
+ for (const ns of split) {
230
+ if (ns[0] === "-") {
231
+ createDebug.skips.push(ns.slice(1));
232
+ } else {
233
+ createDebug.names.push(ns);
234
+ }
235
+ }
236
+ }
237
+ function matchesTemplate(search, template) {
238
+ let searchIndex = 0;
239
+ let templateIndex = 0;
240
+ let starIndex = -1;
241
+ let matchIndex = 0;
242
+ while (searchIndex < search.length) {
243
+ if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === "*")) {
244
+ if (template[templateIndex] === "*") {
245
+ starIndex = templateIndex;
246
+ matchIndex = searchIndex;
247
+ templateIndex++;
248
+ } else {
249
+ searchIndex++;
250
+ templateIndex++;
251
+ }
252
+ } else if (starIndex !== -1) {
253
+ templateIndex = starIndex + 1;
254
+ matchIndex++;
255
+ searchIndex = matchIndex;
256
+ } else {
257
+ return false;
258
+ }
259
+ }
260
+ while (templateIndex < template.length && template[templateIndex] === "*") {
261
+ templateIndex++;
262
+ }
263
+ return templateIndex === template.length;
264
+ }
265
+ function disable() {
266
+ const namespaces = [
267
+ ...createDebug.names,
268
+ ...createDebug.skips.map((namespace) => "-" + namespace)
269
+ ].join(",");
270
+ createDebug.enable("");
271
+ return namespaces;
272
+ }
273
+ function enabled(name) {
274
+ for (const skip of createDebug.skips) {
275
+ if (matchesTemplate(name, skip)) {
276
+ return false;
277
+ }
278
+ }
279
+ for (const ns of createDebug.names) {
280
+ if (matchesTemplate(name, ns)) {
281
+ return true;
282
+ }
283
+ }
284
+ return false;
285
+ }
286
+ function coerce(val) {
287
+ if (val instanceof Error) {
288
+ return val.stack || val.message;
289
+ }
290
+ return val;
291
+ }
292
+ function destroy() {
293
+ console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
294
+ }
295
+ createDebug.enable(createDebug.load());
296
+ return createDebug;
297
+ }
298
+ common = setup;
299
+ return common;
300
+ }
301
+ var hasRequiredBrowser;
302
+ function requireBrowser() {
303
+ if (hasRequiredBrowser) return browser.exports;
304
+ hasRequiredBrowser = 1;
305
+ (function(module, exports) {
306
+ var define_process_env_default = {};
307
+ exports.formatArgs = formatArgs;
308
+ exports.save = save;
309
+ exports.load = load;
310
+ exports.useColors = useColors;
311
+ exports.storage = localstorage();
312
+ exports.destroy = /* @__PURE__ */ (() => {
313
+ let warned = false;
314
+ return () => {
315
+ if (!warned) {
316
+ warned = true;
317
+ console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
318
+ }
319
+ };
320
+ })();
321
+ exports.colors = [
322
+ "#0000CC",
323
+ "#0000FF",
324
+ "#0033CC",
325
+ "#0033FF",
326
+ "#0066CC",
327
+ "#0066FF",
328
+ "#0099CC",
329
+ "#0099FF",
330
+ "#00CC00",
331
+ "#00CC33",
332
+ "#00CC66",
333
+ "#00CC99",
334
+ "#00CCCC",
335
+ "#00CCFF",
336
+ "#3300CC",
337
+ "#3300FF",
338
+ "#3333CC",
339
+ "#3333FF",
340
+ "#3366CC",
341
+ "#3366FF",
342
+ "#3399CC",
343
+ "#3399FF",
344
+ "#33CC00",
345
+ "#33CC33",
346
+ "#33CC66",
347
+ "#33CC99",
348
+ "#33CCCC",
349
+ "#33CCFF",
350
+ "#6600CC",
351
+ "#6600FF",
352
+ "#6633CC",
353
+ "#6633FF",
354
+ "#66CC00",
355
+ "#66CC33",
356
+ "#9900CC",
357
+ "#9900FF",
358
+ "#9933CC",
359
+ "#9933FF",
360
+ "#99CC00",
361
+ "#99CC33",
362
+ "#CC0000",
363
+ "#CC0033",
364
+ "#CC0066",
365
+ "#CC0099",
366
+ "#CC00CC",
367
+ "#CC00FF",
368
+ "#CC3300",
369
+ "#CC3333",
370
+ "#CC3366",
371
+ "#CC3399",
372
+ "#CC33CC",
373
+ "#CC33FF",
374
+ "#CC6600",
375
+ "#CC6633",
376
+ "#CC9900",
377
+ "#CC9933",
378
+ "#CCCC00",
379
+ "#CCCC33",
380
+ "#FF0000",
381
+ "#FF0033",
382
+ "#FF0066",
383
+ "#FF0099",
384
+ "#FF00CC",
385
+ "#FF00FF",
386
+ "#FF3300",
387
+ "#FF3333",
388
+ "#FF3366",
389
+ "#FF3399",
390
+ "#FF33CC",
391
+ "#FF33FF",
392
+ "#FF6600",
393
+ "#FF6633",
394
+ "#FF9900",
395
+ "#FF9933",
396
+ "#FFCC00",
397
+ "#FFCC33"
398
+ ];
399
+ function useColors() {
400
+ if (typeof window !== "undefined" && window.process && (window.process.type === "renderer" || window.process.__nwjs)) {
401
+ return true;
402
+ }
403
+ if (typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
404
+ return false;
405
+ }
406
+ let m;
407
+ return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // Is firebug? http://stackoverflow.com/a/398120/376773
408
+ typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || // Is firefox >= v31?
409
+ // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
410
+ typeof navigator !== "undefined" && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31 || // Double check webkit in userAgent just in case we are in a worker
411
+ typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
412
+ }
413
+ function formatArgs(args) {
414
+ args[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + args[0] + (this.useColors ? "%c " : " ") + "+" + module.exports.humanize(this.diff);
415
+ if (!this.useColors) {
416
+ return;
417
+ }
418
+ const c = "color: " + this.color;
419
+ args.splice(1, 0, c, "color: inherit");
420
+ let index = 0;
421
+ let lastC = 0;
422
+ args[0].replace(/%[a-zA-Z%]/g, (match) => {
423
+ if (match === "%%") {
424
+ return;
425
+ }
426
+ index++;
427
+ if (match === "%c") {
428
+ lastC = index;
429
+ }
430
+ });
431
+ args.splice(lastC, 0, c);
432
+ }
433
+ exports.log = console.debug || console.log || (() => {
434
+ });
435
+ function save(namespaces) {
436
+ try {
437
+ if (namespaces) {
438
+ exports.storage.setItem("debug", namespaces);
439
+ } else {
440
+ exports.storage.removeItem("debug");
441
+ }
442
+ } catch (error) {
443
+ }
444
+ }
445
+ function load() {
446
+ let r;
447
+ try {
448
+ r = exports.storage.getItem("debug") || exports.storage.getItem("DEBUG");
449
+ } catch (error) {
450
+ }
451
+ if (!r && typeof process !== "undefined" && "env" in process) {
452
+ r = define_process_env_default.DEBUG;
453
+ }
454
+ return r;
455
+ }
456
+ function localstorage() {
457
+ try {
458
+ return localStorage;
459
+ } catch (error) {
460
+ }
461
+ }
462
+ module.exports = requireCommon()(exports);
463
+ const { formatters } = module.exports;
464
+ formatters.j = function(v) {
465
+ try {
466
+ return JSON.stringify(v);
467
+ } catch (error) {
468
+ return "[UnexpectedJSONParseError]: " + error.message;
469
+ }
470
+ };
471
+ })(browser, browser.exports);
472
+ return browser.exports;
473
+ }
474
+ var browserExports = requireBrowser();
475
+ const debug = /* @__PURE__ */ getDefaultExportFromCjs(browserExports);
476
+ var log = debug("cabbages");
477
+ function pojo(target) {
478
+ return typeof target == "object" && typeof target != null && Object.getPrototypeOf(target) == Object.prototype;
479
+ }
480
+ var BLOCK_MARKER = "";
481
+ function apply(target, ...rest) {
482
+ if (rest.length == 0) {
483
+ log("empty patch");
484
+ return;
485
+ }
486
+ const [path, range, val] = rest;
487
+ let p = [...path];
488
+ while (true) {
489
+ let key = p.shift();
490
+ if (!p.length) {
491
+ const RANGE_ARRAY = Array.isArray(range);
492
+ if (pojo(target) && RANGE_ARRAY && typeof key == "undefined" && typeof range[0] == "string") {
493
+ delete target[range[0]];
494
+ return;
495
+ }
496
+ if (RANGE_ARRAY || typeof range == "number") {
497
+ if (typeof key == "undefined") {
498
+ throw new Error("cant treat top level as a seq");
499
+ }
500
+ key = key;
501
+ let [start, end] = Array.isArray(range) ? range : [range, range + 1];
502
+ const ZERO_LENGTH = Array.isArray(range) && range.length == 0;
503
+ if (!ZERO_LENGTH && (start == null || end == null)) {
504
+ throw new RangeError("it's all or nothing, no half measures");
505
+ }
506
+ const DELETE = typeof val == "undefined";
507
+ const INSERT = start === end && !DELETE;
508
+ const APPEND = ZERO_LENGTH && !DELETE;
509
+ const REPLACE = !INSERT && !DELETE && !APPEND;
510
+ if (typeof target[key] == "undefined") {
511
+ if (typeof target == "string") {
512
+ return;
513
+ } else if (typeof val == "string") {
514
+ target[key] = "";
515
+ } else {
516
+ target[key] = [];
517
+ }
518
+ }
519
+ let seq = target[key];
520
+ if (Array.isArray(seq)) {
521
+ if (APPEND) {
522
+ Array.isArray(val) ? seq.push(...val) : seq.push(val);
523
+ return;
524
+ }
525
+ if (INSERT || REPLACE) {
526
+ Array.isArray(val) ? seq.splice(start, end - start, ...val) : seq.splice(start, end - start, val);
527
+ return;
528
+ }
529
+ if (DELETE) {
530
+ seq.splice(start, end - start);
531
+ return;
532
+ }
533
+ throw new Error("i don't know what happened");
534
+ }
535
+ if (typeof seq == "string") {
536
+ if (APPEND) {
537
+ target[key] = seq + val;
538
+ return;
539
+ }
540
+ if (REPLACE || INSERT) {
541
+ target[key] = seq.slice(0, start) + (typeof val == "string" ? val : val.map(
542
+ (n) => typeof n == "string" ? n : BLOCK_MARKER
543
+ ).join("")) + seq.slice(end);
544
+ return;
545
+ }
546
+ if (DELETE) {
547
+ target[key] = seq.slice(0, start) + seq.slice(end);
548
+ return;
549
+ }
550
+ throw new Error("i don't know what happened");
551
+ }
552
+ if (pojo(seq) && RANGE_ARRAY && typeof range[0] == "string") {
553
+ delete seq[range[0]];
554
+ return;
555
+ }
556
+ throw new Error("not implemented");
557
+ }
558
+ if (typeof key == "undefined") {
559
+ if (typeof range != "string") {
560
+ throw new Error(`can't index top-level map with ${range}`);
561
+ }
562
+ if (typeof val == "undefined") {
563
+ delete target[range];
564
+ } else {
565
+ target[range] = val;
566
+ }
567
+ return;
568
+ }
569
+ if (typeof target[key] == "undefined") {
570
+ target[key] = {};
571
+ }
572
+ if (RANGE_ARRAY) {
573
+ let [a, b] = range;
574
+ if (a != null && b != null) {
575
+ if (typeof val == "undefined" && a != null && b != null) {
576
+ delete target[key][a || b];
577
+ } else {
578
+ target[key][a || b] = val;
579
+ }
580
+ }
581
+ } else {
582
+ if (typeof val == "undefined") {
583
+ delete target[key][range];
584
+ } else if (typeof target[key] == "string") {
585
+ return;
586
+ } else {
587
+ target[key][range] = val;
588
+ }
589
+ }
590
+ return;
591
+ }
592
+ if (typeof key == "undefined") {
593
+ throw new Error("cant treat top level as a seq");
594
+ }
595
+ key = key;
596
+ let nextkey = p[0];
597
+ if (typeof target[key] == "undefined") {
598
+ if (typeof nextkey == "string") {
599
+ target[key] = {};
600
+ } else if (typeof nextkey == "number") {
601
+ target[key] = [];
602
+ } else {
603
+ throw new Error(`can't go down this road ${target}.${key}.${nextkey}`);
604
+ }
605
+ }
606
+ target = target[key];
607
+ }
608
+ }
609
+ function get(obj, key) {
610
+ for (let p = 0; p < key.length; p++) {
611
+ obj = obj ? obj[key[p]] : void 0;
612
+ }
613
+ return obj;
614
+ }
615
+ function fromAutomerge(autopatch, payload) {
616
+ const path = autopatch.path.slice(0, -1);
617
+ const key = autopatch.path[autopatch.path.length - 1];
618
+ switch (autopatch.action) {
619
+ case "mark":
620
+ case "unmark":
621
+ log(
622
+ `skipping ${autopatch.action} because it doesn't affect material reality`
623
+ );
624
+ return [];
625
+ case "inc":
626
+ if (payload) {
627
+ return [path, key, get(payload.patchInfo.after, autopatch.path)];
628
+ } else {
629
+ throw new Error(
630
+ `can't apply ${autopatch.action} without payload argument`
631
+ );
632
+ }
633
+ case "conflict":
634
+ if (payload) {
635
+ return [path, key, get(payload.patchInfo.after, autopatch.path)];
636
+ } else {
637
+ throw new Error(
638
+ `can't apply ${autopatch.action} without payload argument`
639
+ );
640
+ }
641
+ case "del": {
642
+ return typeof key == "string" ? [path, key] : [path, [key, key + (autopatch.length || 1)]];
643
+ }
644
+ case "insert": {
645
+ return [path, [key, key], autopatch.values];
646
+ }
647
+ case "splice": {
648
+ return [path, [key, key], [autopatch.value]];
649
+ }
650
+ case "put": {
651
+ return [path, key, autopatch.value];
652
+ }
653
+ }
654
+ }
655
+ function autoproduce(payload) {
656
+ return (doc) => {
657
+ for (let patch of payload.patches) {
658
+ apply(doc, ...fromAutomerge(patch, payload));
659
+ }
660
+ };
661
+ }
662
+ const cache = /* @__PURE__ */ new WeakMap();
663
+ function makeDocumentProjection(handle) {
664
+ onCleanup(() => {
665
+ const item = cache.get(handle);
666
+ if (!item) return;
667
+ if (!item.refs--) {
668
+ item.cleanup();
669
+ }
670
+ });
671
+ if (cache.has(handle)) {
672
+ const item = cache.get(handle);
673
+ item.refs++;
674
+ return item.store;
675
+ }
676
+ const [doc, set] = createStore(handle.doc());
677
+ cache.set(handle, {
678
+ refs: 0,
679
+ store: doc,
680
+ cleanup() {
681
+ handle.off("change", patch);
682
+ handle.off("delete", ondelete);
683
+ cache.delete(handle);
684
+ }
685
+ });
686
+ function patch(payload) {
687
+ if (payload.scopeReplaced) {
688
+ set(reconcile(payload.doc ?? {}));
689
+ return;
690
+ }
691
+ set(produce(autoproduce(payload)));
692
+ }
693
+ function ondelete() {
694
+ set(reconcile({}));
695
+ }
696
+ handle.on("change", patch);
697
+ handle.on("delete", ondelete);
698
+ handle.whenReady().then(() => {
699
+ set(handle.doc());
700
+ });
701
+ return doc;
702
+ }
703
+ export {
704
+ makeDocumentProjection as m
705
+ };
706
+ //# sourceMappingURL=makeDocumentProjection-DXgEZYyv.js.map