@univerjs/drawing 0.5.0 → 0.5.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.
package/lib/es/index.js CHANGED
@@ -1,318 +1,329 @@
1
- var Ut = Object.defineProperty;
2
- var Mt = (n, e, t) => e in n ? Ut(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
- var V = (n, e, t) => Mt(n, typeof e != "symbol" ? e + "" : e, t);
4
- import { sortRules as Nt, sortRulesByDesc as Rt, createIdentifier as Ct, Tools as kt, Inject as St, Injector as jt, Plugin as Tt, mergeOverrideWithDependencies as $t, IConfigService as Wt } from "@univerjs/core";
5
- import { Subject as we } from "rxjs";
6
- const an = 500, cn = 500, un = 10, Gt = 5 * 1024 * 1024, Bt = ["image/png", "image/jpeg", "image/jpg", "image/gif", "image/bmp"];
7
- var Ce = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, F = {}, Et = {}, ct = {};
8
- Object.defineProperty(ct, "__esModule", { value: !0 });
9
- function xt(n, e) {
10
- if (Array.isArray(e))
11
- return !1;
12
- for (let t in n)
13
- if (!ut(n[t], e[t]))
1
+ var jt = Object.defineProperty;
2
+ var $t = (a, e, n) => e in a ? jt(a, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : a[e] = n;
3
+ var F = (a, e, n) => $t(a, typeof e != "symbol" ? e + "" : e, n);
4
+ import { sortRules as Nt, sortRulesByDesc as Rt, createIdentifier as xt, ImageSourceType as at, ImageUploadStatusType as et, Tools as Bt, Inject as Wt, Injector as Gt, Plugin as Lt, mergeOverrideWithDependencies as qt, IConfigService as Kt, IImageIoService as Ft } from "@univerjs/core";
5
+ import { IImageIoService as wn, ImageSourceType as bn, ImageUploadStatusType as Cn } from "@univerjs/core";
6
+ import { Subject as be } from "rxjs";
7
+ const pn = 500, gn = 500, yn = 10, Vt = 5 * 1024 * 1024, Ht = ["image/png", "image/jpeg", "image/jpg", "image/gif", "image/bmp"];
8
+ var Ve = {}, Ze = {}, tt = {}, _t;
9
+ function zt() {
10
+ if (_t) return tt;
11
+ _t = 1, Object.defineProperty(tt, "__esModule", { value: !0 });
12
+ function a(t, r) {
13
+ if (Array.isArray(r))
14
14
  return !1;
15
- for (let t in e)
16
- if (n[t] === void 0)
17
- return !1;
18
- return !0;
19
- }
20
- function Lt(n, e) {
21
- if (!Array.isArray(e) || n.length !== e.length)
22
- return !1;
23
- for (let t = 0; t < n.length; t++)
24
- if (!ut(n[t], e[t]))
15
+ for (let u in t)
16
+ if (!n(t[u], r[u]))
17
+ return !1;
18
+ for (let u in r)
19
+ if (t[u] === void 0)
20
+ return !1;
21
+ return !0;
22
+ }
23
+ function e(t, r) {
24
+ if (!Array.isArray(r) || t.length !== r.length)
25
25
  return !1;
26
- return !0;
27
- }
28
- function ut(n, e) {
29
- return n === e ? !0 : n === null || e === null || typeof n != "object" || typeof e != "object" ? !1 : Array.isArray(n) ? Lt(n, e) : xt(n, e);
30
- }
31
- ct.default = ut;
32
- var dt = {};
33
- Object.defineProperty(dt, "__esModule", { value: !0 });
34
- function lt(n) {
35
- if (n === null)
36
- return null;
37
- if (Array.isArray(n))
38
- return n.map(lt);
39
- if (typeof n == "object") {
40
- const e = {};
41
- for (let t in n)
42
- e[t] = lt(n[t]);
43
- return e;
44
- } else
45
- return n;
46
- }
47
- dt.default = lt;
48
- var ft = {};
49
- (function(n) {
50
- Object.defineProperty(n, "__esModule", { value: !0 }), n.eachChildOf = n.advancer = n.readCursor = n.writeCursor = n.WriteCursor = n.ReadCursor = n.isValidPathItem = void 0;
51
- function e(O, o) {
52
- if (!O)
53
- throw new Error(o);
54
- }
55
- const t = (O) => O != null && typeof O == "object" && !Array.isArray(O), i = (O, o) => (
56
- // All the numbers, then all the letters. Just as the gods of ascii intended.
57
- typeof O == typeof o ? O > o : typeof O == "string" && typeof o == "number"
58
- );
59
- function s(O, o) {
60
- for (let c in O) {
61
- const h = c;
62
- o.write(h, O[h]);
63
- }
26
+ for (let u = 0; u < t.length; u++)
27
+ if (!n(t[u], r[u]))
28
+ return !1;
29
+ return !0;
64
30
  }
65
- n.isValidPathItem = (O) => typeof O == "number" || typeof O == "string" && O !== "__proto__";
66
- class d {
67
- constructor(o = null) {
68
- this.parents = [], this.indexes = [], this.lcIdx = -1, this.idx = -1, this.container = o;
69
- }
70
- ascend() {
71
- e(this.parents.length === this.indexes.length / 2), this.idx === 0 ? this.parents.length ? (this.lcIdx = this.indexes.pop(), this.container = this.parents.pop(), this.idx = this.indexes.pop()) : (this.lcIdx = 0, this.idx = -1) : (e(this.idx > 0), this.idx--, t(this.container[this.idx]) && this.idx--);
72
- }
73
- getPath() {
74
- const o = [];
75
- let c = this.container, h = this.parents.length - 1, k = this.idx;
76
- for (; k >= 0; )
77
- o.unshift(c[k]), k === 0 ? (k = this.indexes[h * 2], c = this.parents[h--]) : k -= t(c[k - 1]) ? 2 : 1;
78
- return o;
79
- }
31
+ function n(t, r) {
32
+ return t === r ? !0 : t === null || r === null || typeof t != "object" || typeof r != "object" ? !1 : Array.isArray(t) ? e(t, r) : a(t, r);
80
33
  }
81
- class l extends d {
82
- get() {
83
- return this.container ? this.container.slice(this.idx + 1) : null;
84
- }
85
- // Its only valid to call this after descending into a child.
86
- getKey() {
87
- return e(this.container != null, "Invalid call to getKey before cursor descended"), this.container[this.idx];
88
- }
89
- getComponent() {
90
- let o;
91
- return this.container && this.container.length > this.idx + 1 && t(o = this.container[this.idx + 1]) ? o : null;
92
- }
93
- descendFirst() {
94
- let o = this.idx + 1;
95
- if (!this.container || o >= this.container.length || t(this.container[o]) && o + 1 >= this.container.length)
96
- return !1;
97
- t(this.container[o]) && o++;
98
- const c = this.container[o];
99
- return Array.isArray(c) ? (this.indexes.push(this.idx), this.parents.push(this.container), this.indexes.push(o), this.idx = 0, this.container = c) : this.idx = o, !0;
100
- }
101
- nextSibling() {
102
- if (e(this.parents.length === this.indexes.length / 2), this.idx > 0 || this.parents.length === 0)
103
- return !1;
104
- const o = this.indexes[this.indexes.length - 1] + 1, c = this.parents[this.parents.length - 1];
105
- return o >= c.length ? !1 : (e(!isNaN(o)), this.indexes[this.indexes.length - 1] = o, this.container = c[o], !0);
106
- }
107
- _init(o, c, h, k) {
108
- this.container = o, this.idx = c, this.parents = h.slice(), this.indexes = k.slice();
109
- }
110
- clone() {
111
- const o = new l();
112
- return o._init(this.container, this.idx, this.parents, this.indexes), o;
34
+ return tt.default = n, tt;
35
+ }
36
+ var nt = {}, vt;
37
+ function Xt() {
38
+ if (vt) return nt;
39
+ vt = 1, Object.defineProperty(nt, "__esModule", { value: !0 });
40
+ function a(e) {
41
+ if (e === null)
42
+ return null;
43
+ if (Array.isArray(e))
44
+ return e.map(a);
45
+ if (typeof e == "object") {
46
+ const n = {};
47
+ for (let t in e)
48
+ n[t] = a(e[t]);
49
+ return n;
50
+ } else
51
+ return e;
52
+ }
53
+ return nt.default = a, nt;
54
+ }
55
+ var lt = {}, mt;
56
+ function At() {
57
+ return mt || (mt = 1, function(a) {
58
+ Object.defineProperty(a, "__esModule", { value: !0 }), a.eachChildOf = a.advancer = a.readCursor = a.writeCursor = a.WriteCursor = a.ReadCursor = a.isValidPathItem = void 0;
59
+ function e(_, s) {
60
+ if (!_)
61
+ throw new Error(s);
113
62
  }
114
- *[Symbol.iterator]() {
115
- if (this.descendFirst()) {
116
- do
117
- yield this.getKey();
118
- while (this.nextSibling());
119
- this.ascend();
63
+ const n = (_) => _ != null && typeof _ == "object" && !Array.isArray(_), t = (_, s) => (
64
+ // All the numbers, then all the letters. Just as the gods of ascii intended.
65
+ typeof _ == typeof s ? _ > s : typeof _ == "string" && typeof s == "number"
66
+ );
67
+ function r(_, s) {
68
+ for (let c in _) {
69
+ const h = c;
70
+ s.write(h, _[h]);
120
71
  }
121
72
  }
122
- // TODO(cleanup): Consider moving these functions out of cursor, since
123
- // they're really just helper methods.
124
- // It'd be really nice to do this using generators.
125
- traverse(o, c) {
126
- const h = this.getComponent();
127
- h && c(h, o);
128
- for (const k of this)
129
- o && o.descend(k), this.traverse(o, c), o && o.ascend();
130
- }
131
- eachPick(o, c) {
132
- this.traverse(o, (h, k) => {
133
- h.p != null && c(h.p, k);
134
- });
135
- }
136
- eachDrop(o, c) {
137
- this.traverse(o, (h, k) => {
138
- h.d != null && c(h.d, k);
139
- });
73
+ a.isValidPathItem = (_) => typeof _ == "number" || typeof _ == "string" && _ !== "__proto__";
74
+ class u {
75
+ constructor(s = null) {
76
+ this.parents = [], this.indexes = [], this.lcIdx = -1, this.idx = -1, this.container = s;
77
+ }
78
+ ascend() {
79
+ e(this.parents.length === this.indexes.length / 2), this.idx === 0 ? this.parents.length ? (this.lcIdx = this.indexes.pop(), this.container = this.parents.pop(), this.idx = this.indexes.pop()) : (this.lcIdx = 0, this.idx = -1) : (e(this.idx > 0), this.idx--, n(this.container[this.idx]) && this.idx--);
80
+ }
81
+ getPath() {
82
+ const s = [];
83
+ let c = this.container, h = this.parents.length - 1, S = this.idx;
84
+ for (; S >= 0; )
85
+ s.unshift(c[S]), S === 0 ? (S = this.indexes[h * 2], c = this.parents[h--]) : S -= n(c[S - 1]) ? 2 : 1;
86
+ return s;
87
+ }
140
88
  }
141
- }
142
- n.ReadCursor = l;
143
- class a extends d {
144
- constructor(o = null) {
145
- super(o), this.pendingDescent = [], this._op = o;
89
+ class o extends u {
90
+ get() {
91
+ return this.container ? this.container.slice(this.idx + 1) : null;
92
+ }
93
+ // Its only valid to call this after descending into a child.
94
+ getKey() {
95
+ return e(this.container != null, "Invalid call to getKey before cursor descended"), this.container[this.idx];
96
+ }
97
+ getComponent() {
98
+ let s;
99
+ return this.container && this.container.length > this.idx + 1 && n(s = this.container[this.idx + 1]) ? s : null;
100
+ }
101
+ descendFirst() {
102
+ let s = this.idx + 1;
103
+ if (!this.container || s >= this.container.length || n(this.container[s]) && s + 1 >= this.container.length)
104
+ return !1;
105
+ n(this.container[s]) && s++;
106
+ const c = this.container[s];
107
+ return Array.isArray(c) ? (this.indexes.push(this.idx), this.parents.push(this.container), this.indexes.push(s), this.idx = 0, this.container = c) : this.idx = s, !0;
108
+ }
109
+ nextSibling() {
110
+ if (e(this.parents.length === this.indexes.length / 2), this.idx > 0 || this.parents.length === 0)
111
+ return !1;
112
+ const s = this.indexes[this.indexes.length - 1] + 1, c = this.parents[this.parents.length - 1];
113
+ return s >= c.length ? !1 : (e(!isNaN(s)), this.indexes[this.indexes.length - 1] = s, this.container = c[s], !0);
114
+ }
115
+ _init(s, c, h, S) {
116
+ this.container = s, this.idx = c, this.parents = h.slice(), this.indexes = S.slice();
117
+ }
118
+ clone() {
119
+ const s = new o();
120
+ return s._init(this.container, this.idx, this.parents, this.indexes), s;
121
+ }
122
+ *[Symbol.iterator]() {
123
+ if (this.descendFirst()) {
124
+ do
125
+ yield this.getKey();
126
+ while (this.nextSibling());
127
+ this.ascend();
128
+ }
129
+ }
130
+ // TODO(cleanup): Consider moving these functions out of cursor, since
131
+ // they're really just helper methods.
132
+ // It'd be really nice to do this using generators.
133
+ traverse(s, c) {
134
+ const h = this.getComponent();
135
+ h && c(h, s);
136
+ for (const S of this)
137
+ s && s.descend(S), this.traverse(s, c), s && s.ascend();
138
+ }
139
+ eachPick(s, c) {
140
+ this.traverse(s, (h, S) => {
141
+ h.p != null && c(h.p, S);
142
+ });
143
+ }
144
+ eachDrop(s, c) {
145
+ this.traverse(s, (h, S) => {
146
+ h.d != null && c(h.d, S);
147
+ });
148
+ }
146
149
  }
147
- flushDescent() {
148
- e(this.parents.length === this.indexes.length / 2), this.container === null && (this._op = this.container = []);
149
- for (let o = 0; o < this.pendingDescent.length; o++) {
150
- const c = this.pendingDescent[o];
151
- let h = this.idx + 1;
152
- if (h < this.container.length && t(this.container[h]) && h++, e(h === this.container.length || !t(this.container[h])), h === this.container.length)
153
- this.container.push(c), this.idx = h;
154
- else if (this.container[h] === c)
155
- this.idx = h;
156
- else {
157
- if (!Array.isArray(this.container[h])) {
158
- const k = this.container.splice(h, this.container.length - h);
159
- this.container.push(k), this.lcIdx > -1 && (this.lcIdx = h);
160
- }
161
- for (this.indexes.push(this.idx), this.parents.push(this.container), this.lcIdx !== -1 && (e(i(c, this.container[this.lcIdx][0])), h = this.lcIdx + 1, this.lcIdx = -1); h < this.container.length && i(c, this.container[h][0]); )
162
- h++;
163
- if (this.indexes.push(h), this.idx = 0, h < this.container.length && this.container[h][0] === c)
164
- this.container = this.container[h];
150
+ a.ReadCursor = o;
151
+ class l extends u {
152
+ constructor(s = null) {
153
+ super(s), this.pendingDescent = [], this._op = s;
154
+ }
155
+ flushDescent() {
156
+ e(this.parents.length === this.indexes.length / 2), this.container === null && (this._op = this.container = []);
157
+ for (let s = 0; s < this.pendingDescent.length; s++) {
158
+ const c = this.pendingDescent[s];
159
+ let h = this.idx + 1;
160
+ if (h < this.container.length && n(this.container[h]) && h++, e(h === this.container.length || !n(this.container[h])), h === this.container.length)
161
+ this.container.push(c), this.idx = h;
162
+ else if (this.container[h] === c)
163
+ this.idx = h;
165
164
  else {
166
- const k = [c];
167
- this.container.splice(h, 0, k), this.container = k;
165
+ if (!Array.isArray(this.container[h])) {
166
+ const S = this.container.splice(h, this.container.length - h);
167
+ this.container.push(S), this.lcIdx > -1 && (this.lcIdx = h);
168
+ }
169
+ for (this.indexes.push(this.idx), this.parents.push(this.container), this.lcIdx !== -1 && (e(t(c, this.container[this.lcIdx][0])), h = this.lcIdx + 1, this.lcIdx = -1); h < this.container.length && t(c, this.container[h][0]); )
170
+ h++;
171
+ if (this.indexes.push(h), this.idx = 0, h < this.container.length && this.container[h][0] === c)
172
+ this.container = this.container[h];
173
+ else {
174
+ const S = [c];
175
+ this.container.splice(h, 0, S), this.container = S;
176
+ }
168
177
  }
169
178
  }
179
+ this.pendingDescent.length = 0;
170
180
  }
171
- this.pendingDescent.length = 0;
172
- }
173
- reset() {
174
- this.lcIdx = -1;
175
- }
176
- // Creates and returns a component, creating one if need be. You should
177
- // probably write to it immediately - ops are not valid with empty
178
- // components.
179
- getComponent() {
180
- this.flushDescent();
181
- const o = this.idx + 1;
182
- if (o < this.container.length && t(this.container[o]))
183
- return this.container[o];
184
- {
185
- const c = {};
186
- return this.container.splice(o, 0, c), c;
181
+ reset() {
182
+ this.lcIdx = -1;
187
183
  }
188
- }
189
- write(o, c) {
190
- const h = this.getComponent();
191
- e(h[o] == null || h[o] === c, "Internal consistency error: Overwritten component. File a bug"), h[o] = c;
192
- }
193
- get() {
194
- return this._op;
195
- }
196
- descend(o) {
197
- if (!n.isValidPathItem(o))
198
- throw Error("Invalid JSON key");
199
- this.pendingDescent.push(o);
200
- }
201
- descendPath(o) {
202
- return this.pendingDescent.push(...o), this;
203
- }
204
- ascend() {
205
- this.pendingDescent.length ? this.pendingDescent.pop() : super.ascend();
206
- }
207
- mergeTree(o, c = s) {
208
- if (o === null)
209
- return;
210
- if (e(Array.isArray(o)), o === this._op)
211
- throw Error("Cannot merge into my own tree");
212
- const h = this.lcIdx, k = this.parents.length;
213
- let Z = 0;
214
- for (let pe = 0; pe < o.length; pe++) {
215
- const J = o[pe];
216
- typeof J == "string" || typeof J == "number" ? (Z++, this.descend(J)) : Array.isArray(J) ? this.mergeTree(J, c) : typeof J == "object" && c(J, this);
184
+ // Creates and returns a component, creating one if need be. You should
185
+ // probably write to it immediately - ops are not valid with empty
186
+ // components.
187
+ getComponent() {
188
+ this.flushDescent();
189
+ const s = this.idx + 1;
190
+ if (s < this.container.length && n(this.container[s]))
191
+ return this.container[s];
192
+ {
193
+ const c = {};
194
+ return this.container.splice(s, 0, c), c;
195
+ }
196
+ }
197
+ write(s, c) {
198
+ const h = this.getComponent();
199
+ e(h[s] == null || h[s] === c, "Internal consistency error: Overwritten component. File a bug"), h[s] = c;
200
+ }
201
+ get() {
202
+ return this._op;
203
+ }
204
+ descend(s) {
205
+ if (!a.isValidPathItem(s))
206
+ throw Error("Invalid JSON key");
207
+ this.pendingDescent.push(s);
208
+ }
209
+ descendPath(s) {
210
+ return this.pendingDescent.push(...s), this;
211
+ }
212
+ ascend() {
213
+ this.pendingDescent.length ? this.pendingDescent.pop() : super.ascend();
214
+ }
215
+ mergeTree(s, c = r) {
216
+ if (s === null)
217
+ return;
218
+ if (e(Array.isArray(s)), s === this._op)
219
+ throw Error("Cannot merge into my own tree");
220
+ const h = this.lcIdx, S = this.parents.length;
221
+ let Y = 0;
222
+ for (let pe = 0; pe < s.length; pe++) {
223
+ const Z = s[pe];
224
+ typeof Z == "string" || typeof Z == "number" ? (Y++, this.descend(Z)) : Array.isArray(Z) ? this.mergeTree(Z, c) : typeof Z == "object" && c(Z, this);
225
+ }
226
+ for (; Y--; )
227
+ this.ascend();
228
+ this.lcIdx = this.parents.length === S ? h : -1;
229
+ }
230
+ at(s, c) {
231
+ this.descendPath(s), c(this);
232
+ for (let h = 0; h < s.length; h++)
233
+ this.ascend();
234
+ return this;
235
+ }
236
+ // This is used by helpers, so the strict ordering guarantees are
237
+ // relaxed.
238
+ writeAtPath(s, c, h) {
239
+ return this.at(s, () => this.write(c, h)), this.reset(), this;
240
+ }
241
+ writeMove(s, c, h = 0) {
242
+ return this.writeAtPath(s, "p", h).writeAtPath(c, "d", h);
243
+ }
244
+ getPath() {
245
+ const s = super.getPath();
246
+ return s.push(...this.pendingDescent), s;
217
247
  }
218
- for (; Z--; )
219
- this.ascend();
220
- this.lcIdx = this.parents.length === k ? h : -1;
221
- }
222
- at(o, c) {
223
- this.descendPath(o), c(this);
224
- for (let h = 0; h < o.length; h++)
225
- this.ascend();
226
- return this;
227
- }
228
- // This is used by helpers, so the strict ordering guarantees are
229
- // relaxed.
230
- writeAtPath(o, c, h) {
231
- return this.at(o, () => this.write(c, h)), this.reset(), this;
232
- }
233
- writeMove(o, c, h = 0) {
234
- return this.writeAtPath(o, "p", h).writeAtPath(c, "d", h);
235
- }
236
- getPath() {
237
- const o = super.getPath();
238
- return o.push(...this.pendingDescent), o;
239
248
  }
240
- }
241
- n.WriteCursor = a, n.writeCursor = () => new a(), n.readCursor = (O) => new l(O);
242
- function E(O, o, c) {
243
- let h, k;
244
- k = h = O ? O.descendFirst() : !1;
245
- function Z(pe) {
246
- let J;
247
- for (; k; ) {
248
- const Ie = J = O.getKey();
249
- if (pe != null) {
250
- let xe = !1;
251
- if (o && typeof Ie == "number" && (J = o(Ie, O.getComponent()), J < 0 && (J = ~J, xe = !0)), i(J, pe))
252
- return null;
253
- if (J === pe && !xe)
254
- return O;
249
+ a.WriteCursor = l, a.writeCursor = () => new l(), a.readCursor = (_) => new o(_);
250
+ function E(_, s, c) {
251
+ let h, S;
252
+ S = h = _ ? _.descendFirst() : !1;
253
+ function Y(pe) {
254
+ let Z;
255
+ for (; S; ) {
256
+ const Ce = Z = _.getKey();
257
+ if (pe != null) {
258
+ let Ge = !1;
259
+ if (s && typeof Ce == "number" && (Z = s(Ce, _.getComponent()), Z < 0 && (Z = ~Z, Ge = !0)), t(Z, pe))
260
+ return null;
261
+ if (Z === pe && !Ge)
262
+ return _;
263
+ }
264
+ c && typeof Z == "number" && c(Z, _.getComponent()), S = _.nextSibling();
255
265
  }
256
- c && typeof J == "number" && c(J, O.getComponent()), k = O.nextSibling();
266
+ return null;
257
267
  }
258
- return null;
268
+ return Y.end = () => {
269
+ h && _.ascend();
270
+ }, Y;
259
271
  }
260
- return Z.end = () => {
261
- h && O.ascend();
262
- }, Z;
263
- }
264
- n.advancer = E;
265
- function W(O, o, c) {
266
- let h, k, Z, pe;
267
- for (h = k = O && O.descendFirst(), Z = pe = o && o.descendFirst(); h || Z; ) {
268
- let J = h ? O.getKey() : null, Ie = Z ? o.getKey() : null;
269
- J !== null && Ie !== null && (i(Ie, J) ? Ie = null : J !== Ie && (J = null)), c(J == null ? Ie : J, J != null ? O : null, Ie != null ? o : null), J != null && h && (h = O.nextSibling()), Ie != null && Z && (Z = o.nextSibling());
272
+ a.advancer = E;
273
+ function x(_, s, c) {
274
+ let h, S, Y, pe;
275
+ for (h = S = _ && _.descendFirst(), Y = pe = s && s.descendFirst(); h || Y; ) {
276
+ let Z = h ? _.getKey() : null, Ce = Y ? s.getKey() : null;
277
+ Z !== null && Ce !== null && (t(Ce, Z) ? Ce = null : Z !== Ce && (Z = null)), c(Z == null ? Ce : Z, Z != null ? _ : null, Ce != null ? s : null), Z != null && h && (h = _.nextSibling()), Ce != null && Y && (Y = s.nextSibling());
278
+ }
279
+ S && _.ascend(), pe && s.ascend();
270
280
  }
271
- k && O.ascend(), pe && o.ascend();
272
- }
273
- n.eachChildOf = W;
274
- })(ft);
275
- var ht = {};
276
- (function(n) {
277
- Object.defineProperty(n, "__esModule", { value: !0 }), n.ConflictType = void 0, function(e) {
278
- e[e.RM_UNEXPECTED_CONTENT = 1] = "RM_UNEXPECTED_CONTENT", e[e.DROP_COLLISION = 2] = "DROP_COLLISION", e[e.BLACKHOLE = 3] = "BLACKHOLE";
279
- }(n.ConflictType || (n.ConflictType = {}));
280
- })(ht);
281
- var it = {}, Fe = {}, vt;
282
- function pt() {
283
- return vt || (vt = 1, Object.defineProperty(Fe, "__esModule", { value: !0 }), Fe.uniToStrPos = Fe.strPosToUni = void 0, Fe.strPosToUni = (n, e = n.length) => {
284
- let t = 0, i = 0;
285
- for (; i < e; i++) {
286
- const s = n.charCodeAt(i);
287
- s >= 55296 && s <= 57343 && (t++, i++);
281
+ a.eachChildOf = x;
282
+ }(lt)), lt;
283
+ }
284
+ var ut = {}, Ot;
285
+ function Mt() {
286
+ return Ot || (Ot = 1, function(a) {
287
+ Object.defineProperty(a, "__esModule", { value: !0 }), a.ConflictType = void 0, function(e) {
288
+ e[e.RM_UNEXPECTED_CONTENT = 1] = "RM_UNEXPECTED_CONTENT", e[e.DROP_COLLISION = 2] = "DROP_COLLISION", e[e.BLACKHOLE = 3] = "BLACKHOLE";
289
+ }(a.ConflictType || (a.ConflictType = {}));
290
+ }(ut)), ut;
291
+ }
292
+ var Se = {}, He = {}, wt;
293
+ function ht() {
294
+ return wt || (wt = 1, Object.defineProperty(He, "__esModule", { value: !0 }), He.uniToStrPos = He.strPosToUni = void 0, He.strPosToUni = (a, e = a.length) => {
295
+ let n = 0, t = 0;
296
+ for (; t < e; t++) {
297
+ const r = a.charCodeAt(t);
298
+ r >= 55296 && r <= 57343 && (n++, t++);
288
299
  }
289
- if (i !== e)
300
+ if (t !== e)
290
301
  throw Error("Invalid offset - splits unicode bytes");
291
- return i - t;
292
- }, Fe.uniToStrPos = (n, e) => {
293
- let t = 0;
302
+ return t - n;
303
+ }, He.uniToStrPos = (a, e) => {
304
+ let n = 0;
294
305
  for (; e > 0; e--) {
295
- const i = n.charCodeAt(t);
296
- t += i >= 55296 && i <= 57343 ? 2 : 1;
306
+ const t = a.charCodeAt(n);
307
+ n += t >= 55296 && t <= 57343 ? 2 : 1;
297
308
  }
298
- return t;
299
- }), Fe;
309
+ return n;
310
+ }), He;
300
311
  }
301
- var st = {}, yt;
302
- function at() {
303
- return yt || (yt = 1, function(n) {
304
- Object.defineProperty(n, "__esModule", { value: !0 }), n.uniSlice = n.dlen = n.eachOp = void 0;
305
- const e = pt(), t = (f) => {
312
+ var ct = {}, bt;
313
+ function ft() {
314
+ return bt || (bt = 1, function(a) {
315
+ Object.defineProperty(a, "__esModule", { value: !0 }), a.uniSlice = a.dlen = a.eachOp = void 0;
316
+ const e = ht(), n = (f) => {
306
317
  if (!Array.isArray(f))
307
318
  throw Error("Op must be an array of components");
308
- let _ = null;
309
- for (let w = 0; w < f.length; w++) {
310
- const L = f[w];
319
+ let y = null;
320
+ for (let b = 0; b < f.length; b++) {
321
+ const L = f[b];
311
322
  switch (typeof L) {
312
323
  case "object":
313
324
  if (typeof L.d != "number" && typeof L.d != "string")
314
325
  throw Error("Delete must be number or string");
315
- if (n.dlen(L.d) <= 0)
326
+ if (a.dlen(L.d) <= 0)
316
327
  throw Error("Deletes must not be empty");
317
328
  break;
318
329
  case "string":
@@ -322,234 +333,236 @@ function at() {
322
333
  case "number":
323
334
  if (!(L > 0))
324
335
  throw Error("Skip components must be >0");
325
- if (typeof _ == "number")
336
+ if (typeof y == "number")
326
337
  throw Error("Adjacent skip components should be combined");
327
338
  break;
328
339
  }
329
- _ = L;
340
+ y = L;
330
341
  }
331
- if (typeof _ == "number")
342
+ if (typeof y == "number")
332
343
  throw Error("Op has a trailing skip");
333
344
  };
334
- function i(f, _) {
335
- let w = 0, L = 0;
345
+ function t(f, y) {
346
+ let b = 0, L = 0;
336
347
  for (let z = 0; z < f.length; z++) {
337
- const H = f[z];
338
- switch (_(H, w, L), typeof H) {
348
+ const q = f[z];
349
+ switch (y(q, b, L), typeof q) {
339
350
  case "object":
340
- w += n.dlen(H.d);
351
+ b += a.dlen(q.d);
341
352
  break;
342
353
  case "string":
343
- L += e.strPosToUni(H);
354
+ L += e.strPosToUni(q);
344
355
  break;
345
356
  case "number":
346
- w += H, L += H;
357
+ b += q, L += q;
347
358
  break;
348
359
  }
349
360
  }
350
361
  }
351
- n.eachOp = i;
352
- function s(f, _) {
353
- const w = [], L = a(w);
354
- return i(f, (z, H, De) => {
355
- L(_(z, H, De));
356
- }), o(w);
362
+ a.eachOp = t;
363
+ function r(f, y) {
364
+ const b = [], L = l(b);
365
+ return t(f, (z, q, Ee) => {
366
+ L(y(z, q, Ee));
367
+ }), s(b);
357
368
  }
358
- const d = (f) => f, l = (f) => s(f, d);
359
- n.dlen = (f) => typeof f == "number" ? f : e.strPosToUni(f);
360
- const a = (f) => (_) => {
361
- if (!(!_ || _.d === 0 || _.d === "")) if (f.length === 0)
362
- f.push(_);
363
- else if (typeof _ == typeof f[f.length - 1])
364
- if (typeof _ == "object") {
365
- const w = f[f.length - 1];
366
- w.d = typeof w.d == "string" && typeof _.d == "string" ? w.d + _.d : n.dlen(w.d) + n.dlen(_.d);
369
+ const u = (f) => f, o = (f) => r(f, u);
370
+ a.dlen = (f) => typeof f == "number" ? f : e.strPosToUni(f);
371
+ const l = (f) => (y) => {
372
+ if (!(!y || y.d === 0 || y.d === "")) if (f.length === 0)
373
+ f.push(y);
374
+ else if (typeof y == typeof f[f.length - 1])
375
+ if (typeof y == "object") {
376
+ const b = f[f.length - 1];
377
+ b.d = typeof b.d == "string" && typeof y.d == "string" ? b.d + y.d : a.dlen(b.d) + a.dlen(y.d);
367
378
  } else
368
- f[f.length - 1] += _;
379
+ f[f.length - 1] += y;
369
380
  else
370
- f.push(_);
381
+ f.push(y);
371
382
  }, E = (f) => typeof f == "number" ? f : typeof f == "string" ? e.strPosToUni(f) : typeof f.d == "number" ? f.d : e.strPosToUni(f.d);
372
- n.uniSlice = (f, _, w) => {
373
- const L = e.uniToStrPos(f, _), z = w == null ? 1 / 0 : e.uniToStrPos(f, w);
383
+ a.uniSlice = (f, y, b) => {
384
+ const L = e.uniToStrPos(f, y), z = b == null ? 1 / 0 : e.uniToStrPos(f, b);
374
385
  return f.slice(L, z);
375
386
  };
376
- const W = (f, _, w) => typeof f == "number" ? w == null ? f - _ : Math.min(f, w) - _ : n.uniSlice(f, _, w), O = (f) => {
377
- let _ = 0, w = 0;
378
- return { take: (H, De) => {
379
- if (_ === f.length)
380
- return H === -1 ? null : H;
381
- const ue = f[_];
387
+ const x = (f, y, b) => typeof f == "number" ? b == null ? f - y : Math.min(f, b) - y : a.uniSlice(f, y, b), _ = (f) => {
388
+ let y = 0, b = 0;
389
+ return { take: (q, Ee) => {
390
+ if (y === f.length)
391
+ return q === -1 ? null : q;
392
+ const ce = f[y];
382
393
  let ne;
383
- if (typeof ue == "number")
384
- return H === -1 || ue - w <= H ? (ne = ue - w, ++_, w = 0, ne) : (w += H, H);
385
- if (typeof ue == "string") {
386
- if (H === -1 || De === "i" || e.strPosToUni(ue.slice(w)) <= H)
387
- return ne = ue.slice(w), ++_, w = 0, ne;
394
+ if (typeof ce == "number")
395
+ return q === -1 || ce - b <= q ? (ne = ce - b, ++y, b = 0, ne) : (b += q, q);
396
+ if (typeof ce == "string") {
397
+ if (q === -1 || Ee === "i" || e.strPosToUni(ce.slice(b)) <= q)
398
+ return ne = ce.slice(b), ++y, b = 0, ne;
388
399
  {
389
- const ae = w + e.uniToStrPos(ue.slice(w), H);
390
- return ne = ue.slice(w, ae), w = ae, ne;
400
+ const le = b + e.uniToStrPos(ce.slice(b), q);
401
+ return ne = ce.slice(b, le), b = le, ne;
391
402
  }
392
403
  } else {
393
- if (H === -1 || De === "d" || n.dlen(ue.d) - w <= H)
394
- return ne = { d: W(ue.d, w) }, ++_, w = 0, ne;
404
+ if (q === -1 || Ee === "d" || a.dlen(ce.d) - b <= q)
405
+ return ne = { d: x(ce.d, b) }, ++y, b = 0, ne;
395
406
  {
396
- let ae = W(ue.d, w, w + H);
397
- return w += H, { d: ae };
407
+ let le = x(ce.d, b, b + q);
408
+ return b += q, { d: le };
398
409
  }
399
410
  }
400
- }, peek: () => f[_] };
401
- }, o = (f) => (f.length > 0 && typeof f[f.length - 1] == "number" && f.pop(), f);
402
- function c(f, _, w) {
403
- if (w !== "left" && w !== "right")
404
- throw Error("side (" + w + ") must be 'left' or 'right'");
405
- t(f), t(_);
406
- const L = [], z = a(L), { take: H, peek: De } = O(f);
407
- for (let ne = 0; ne < _.length; ne++) {
408
- const ae = _[ne];
409
- let ge, Ae;
410
- switch (typeof ae) {
411
+ }, peek: () => f[y] };
412
+ }, s = (f) => (f.length > 0 && typeof f[f.length - 1] == "number" && f.pop(), f);
413
+ function c(f, y, b) {
414
+ if (b !== "left" && b !== "right")
415
+ throw Error("side (" + b + ") must be 'left' or 'right'");
416
+ n(f), n(y);
417
+ const L = [], z = l(L), { take: q, peek: Ee } = _(f);
418
+ for (let ne = 0; ne < y.length; ne++) {
419
+ const le = y[ne];
420
+ let ge, De;
421
+ switch (typeof le) {
411
422
  case "number":
412
- for (ge = ae; ge > 0; )
413
- Ae = H(ge, "i"), z(Ae), typeof Ae != "string" && (ge -= E(Ae));
423
+ for (ge = le; ge > 0; )
424
+ De = q(ge, "i"), z(De), typeof De != "string" && (ge -= E(De));
414
425
  break;
415
426
  case "string":
416
- w === "left" && typeof De() == "string" && z(H(-1)), z(e.strPosToUni(ae));
427
+ b === "left" && typeof Ee() == "string" && z(q(-1)), z(e.strPosToUni(le));
417
428
  break;
418
429
  case "object":
419
- for (ge = n.dlen(ae.d); ge > 0; )
420
- switch (Ae = H(ge, "i"), typeof Ae) {
430
+ for (ge = a.dlen(le.d); ge > 0; )
431
+ switch (De = q(ge, "i"), typeof De) {
421
432
  case "number":
422
- ge -= Ae;
433
+ ge -= De;
423
434
  break;
424
435
  case "string":
425
- z(Ae);
436
+ z(De);
426
437
  break;
427
438
  case "object":
428
- ge -= n.dlen(Ae.d);
439
+ ge -= a.dlen(De.d);
429
440
  }
430
441
  break;
431
442
  }
432
443
  }
433
- let ue;
434
- for (; ue = H(-1); )
435
- z(ue);
436
- return o(L);
444
+ let ce;
445
+ for (; ce = q(-1); )
446
+ z(ce);
447
+ return s(L);
437
448
  }
438
- function h(f, _) {
439
- t(f), t(_);
440
- const w = [], L = a(w), { take: z } = O(f);
441
- for (let De = 0; De < _.length; De++) {
442
- const ue = _[De];
443
- let ne, ae;
444
- switch (typeof ue) {
449
+ function h(f, y) {
450
+ n(f), n(y);
451
+ const b = [], L = l(b), { take: z } = _(f);
452
+ for (let Ee = 0; Ee < y.length; Ee++) {
453
+ const ce = y[Ee];
454
+ let ne, le;
455
+ switch (typeof ce) {
445
456
  case "number":
446
- for (ne = ue; ne > 0; )
447
- ae = z(ne, "d"), L(ae), typeof ae != "object" && (ne -= E(ae));
457
+ for (ne = ce; ne > 0; )
458
+ le = z(ne, "d"), L(le), typeof le != "object" && (ne -= E(le));
448
459
  break;
449
460
  case "string":
450
- L(ue);
461
+ L(ce);
451
462
  break;
452
463
  case "object":
453
- ne = n.dlen(ue.d);
464
+ ne = a.dlen(ce.d);
454
465
  let ge = 0;
455
466
  for (; ge < ne; )
456
- switch (ae = z(ne - ge, "d"), typeof ae) {
467
+ switch (le = z(ne - ge, "d"), typeof le) {
457
468
  case "number":
458
- L({ d: W(ue.d, ge, ge + ae) }), ge += ae;
469
+ L({ d: x(ce.d, ge, ge + le) }), ge += le;
459
470
  break;
460
471
  case "string":
461
- ge += e.strPosToUni(ae);
472
+ ge += e.strPosToUni(le);
462
473
  break;
463
474
  case "object":
464
- L(ae);
475
+ L(le);
465
476
  }
466
477
  break;
467
478
  }
468
479
  }
469
- let H;
470
- for (; H = z(-1); )
471
- L(H);
472
- return o(w);
480
+ let q;
481
+ for (; q = z(-1); )
482
+ L(q);
483
+ return s(b);
473
484
  }
474
- const k = (f, _) => {
475
- let w = 0;
476
- for (let L = 0; L < _.length && f > w; L++) {
477
- const z = _[L];
485
+ const S = (f, y) => {
486
+ let b = 0;
487
+ for (let L = 0; L < y.length && f > b; L++) {
488
+ const z = y[L];
478
489
  switch (typeof z) {
479
490
  case "number": {
480
- w += z;
491
+ b += z;
481
492
  break;
482
493
  }
483
494
  case "string":
484
- const H = e.strPosToUni(z);
485
- w += H, f += H;
495
+ const q = e.strPosToUni(z);
496
+ b += q, f += q;
486
497
  break;
487
498
  case "object":
488
- f -= Math.min(n.dlen(z.d), f - w);
499
+ f -= Math.min(a.dlen(z.d), f - b);
489
500
  break;
490
501
  }
491
502
  }
492
503
  return f;
493
- }, Z = (f, _) => typeof f == "number" ? k(f, _) : f.map((w) => k(w, _));
494
- function pe(f, _, w) {
495
- return s(f, (L, z) => typeof L == "object" && typeof L.d == "number" ? { d: w.slice(_, z, z + L.d) } : L);
504
+ }, Y = (f, y) => typeof f == "number" ? S(f, y) : f.map((b) => S(b, y));
505
+ function pe(f, y, b) {
506
+ return r(f, (L, z) => typeof L == "object" && typeof L.d == "number" ? { d: b.slice(y, z, z + L.d) } : L);
496
507
  }
497
- function J(f) {
498
- return s(f, (_) => {
499
- switch (typeof _) {
508
+ function Z(f) {
509
+ return r(f, (y) => {
510
+ switch (typeof y) {
500
511
  case "object":
501
- if (typeof _.d == "number")
512
+ if (typeof y.d == "number")
502
513
  throw Error("Cannot invert text op: Deleted characters missing from operation. makeInvertible must be called first.");
503
- return _.d;
514
+ return y.d;
515
+ // delete -> insert
504
516
  case "string":
505
- return { d: _ };
517
+ return { d: y };
518
+ // Insert -> delete
506
519
  case "number":
507
- return _;
520
+ return y;
508
521
  }
509
522
  });
510
523
  }
511
- function Ie(f) {
512
- return s(f, (_) => typeof _ == "object" && typeof _.d == "string" ? { d: e.strPosToUni(_.d) } : _);
524
+ function Ce(f) {
525
+ return r(f, (y) => typeof y == "object" && typeof y.d == "string" ? { d: e.strPosToUni(y.d) } : y);
513
526
  }
514
- function xe(f) {
515
- let _ = !0;
516
- return i(f, (w) => {
517
- typeof w == "object" && typeof w.d == "number" && (_ = !1);
518
- }), _;
527
+ function Ge(f) {
528
+ let y = !0;
529
+ return t(f, (b) => {
530
+ typeof b == "object" && typeof b.d == "number" && (y = !1);
531
+ }), y;
519
532
  }
520
533
  function ve(f) {
521
534
  return {
522
535
  name: "text-unicode",
523
536
  uri: "http://sharejs.org/types/text-unicode",
524
- trim: o,
525
- normalize: l,
526
- checkOp: t,
537
+ trim: s,
538
+ normalize: o,
539
+ checkOp: n,
527
540
  /** Create a new text snapshot.
528
541
  *
529
542
  * @param {string} initial - initial snapshot data. Optional. Defaults to ''.
530
543
  * @returns {Snap} Initial document snapshot object
531
544
  */
532
- create(_ = "") {
533
- if (typeof _ != "string")
545
+ create(y = "") {
546
+ if (typeof y != "string")
534
547
  throw Error("Initial data must be a string");
535
- return f.create(_);
548
+ return f.create(y);
536
549
  },
537
550
  /** Apply an operation to a document snapshot
538
551
  */
539
- apply(_, w) {
540
- t(w);
541
- const L = f.builder(_);
542
- for (let z = 0; z < w.length; z++) {
543
- const H = w[z];
544
- switch (typeof H) {
552
+ apply(y, b) {
553
+ n(b);
554
+ const L = f.builder(y);
555
+ for (let z = 0; z < b.length; z++) {
556
+ const q = b[z];
557
+ switch (typeof q) {
545
558
  case "number":
546
- L.skip(H);
559
+ L.skip(q);
547
560
  break;
548
561
  case "string":
549
- L.append(H);
562
+ L.append(q);
550
563
  break;
551
564
  case "object":
552
- L.del(n.dlen(H.d));
565
+ L.del(a.dlen(q.d));
553
566
  break;
554
567
  }
555
568
  }
@@ -557,58 +570,58 @@ function at() {
557
570
  },
558
571
  transform: c,
559
572
  compose: h,
560
- transformPosition: k,
561
- transformSelection: Z,
562
- isInvertible: xe,
563
- makeInvertible(_, w) {
564
- return pe(_, w, f);
573
+ transformPosition: S,
574
+ transformSelection: Y,
575
+ isInvertible: Ge,
576
+ makeInvertible(y, b) {
577
+ return pe(y, b, f);
565
578
  },
566
- stripInvertible: Ie,
567
- invert: J,
568
- invertWithDoc(_, w) {
569
- return J(pe(_, w, f));
579
+ stripInvertible: Ce,
580
+ invert: Z,
581
+ invertWithDoc(y, b) {
582
+ return Z(pe(y, b, f));
570
583
  },
571
- isNoop: (_) => _.length === 0
584
+ isNoop: (y) => y.length === 0
572
585
  };
573
586
  }
574
- n.default = ve;
575
- }(st)), st;
587
+ a.default = ve;
588
+ }(ct)), ct;
576
589
  }
577
- var Qe = {}, mt;
578
- function Ht() {
579
- if (mt) return Qe;
580
- mt = 1, Object.defineProperty(Qe, "__esModule", { value: !0 });
581
- const n = at(), e = pt();
582
- function t(i, s) {
590
+ var rt = {}, Ct;
591
+ function Jt() {
592
+ if (Ct) return rt;
593
+ Ct = 1, Object.defineProperty(rt, "__esModule", { value: !0 });
594
+ const a = ft(), e = ht();
595
+ function n(t, r) {
583
596
  return {
584
597
  // Returns the text content of the document
585
- get: i,
598
+ get: t,
586
599
  // Returns the number of characters in the string
587
600
  getLength() {
588
- return i().length;
601
+ return t().length;
589
602
  },
590
603
  // Insert the specified text at the given position in the document
591
- insert(d, l, a) {
592
- const E = e.strPosToUni(i(), d);
593
- return s([E, l], a);
604
+ insert(u, o, l) {
605
+ const E = e.strPosToUni(t(), u);
606
+ return r([E, o], l);
594
607
  },
595
- remove(d, l, a) {
596
- const E = e.strPosToUni(i(), d);
597
- return s([E, { d: l }], a);
608
+ remove(u, o, l) {
609
+ const E = e.strPosToUni(t(), u);
610
+ return r([E, { d: o }], l);
598
611
  },
599
612
  // When you use this API, you should implement these two methods
600
613
  // in your editing context.
601
614
  //onInsert: function(pos, text) {},
602
615
  //onRemove: function(pos, removedLength) {},
603
- _onOp(d) {
604
- n.eachOp(d, (l, a, E) => {
605
- switch (typeof l) {
616
+ _onOp(u) {
617
+ a.eachOp(u, (o, l, E) => {
618
+ switch (typeof o) {
606
619
  case "string":
607
- this.onInsert && this.onInsert(E, l);
620
+ this.onInsert && this.onInsert(E, o);
608
621
  break;
609
622
  case "object":
610
- const W = n.dlen(l.d);
611
- this.onRemove && this.onRemove(E, W);
623
+ const x = a.dlen(o.d);
624
+ this.onRemove && this.onRemove(E, x);
612
625
  }
613
626
  });
614
627
  },
@@ -616,31 +629,31 @@ function Ht() {
616
629
  onRemove: null
617
630
  };
618
631
  }
619
- return Qe.default = t, t.provides = { text: !0 }, Qe;
632
+ return rt.default = n, n.provides = { text: !0 }, rt;
620
633
  }
621
- var bt;
622
- function Kt() {
623
- return bt || (bt = 1, function(n) {
624
- var e = Ce && Ce.__createBinding || (Object.create ? function(c, h, k, Z) {
625
- Z === void 0 && (Z = k), Object.defineProperty(c, Z, { enumerable: !0, get: function() {
626
- return h[k];
634
+ var It;
635
+ function Yt() {
636
+ return It || (It = 1, function(a) {
637
+ var e = Se && Se.__createBinding || (Object.create ? function(c, h, S, Y) {
638
+ Y === void 0 && (Y = S), Object.defineProperty(c, Y, { enumerable: !0, get: function() {
639
+ return h[S];
627
640
  } });
628
- } : function(c, h, k, Z) {
629
- Z === void 0 && (Z = k), c[Z] = h[k];
630
- }), t = Ce && Ce.__setModuleDefault || (Object.create ? function(c, h) {
641
+ } : function(c, h, S, Y) {
642
+ Y === void 0 && (Y = S), c[Y] = h[S];
643
+ }), n = Se && Se.__setModuleDefault || (Object.create ? function(c, h) {
631
644
  Object.defineProperty(c, "default", { enumerable: !0, value: h });
632
645
  } : function(c, h) {
633
646
  c.default = h;
634
- }), i = Ce && Ce.__importStar || function(c) {
647
+ }), t = Se && Se.__importStar || function(c) {
635
648
  if (c && c.__esModule) return c;
636
649
  var h = {};
637
- if (c != null) for (var k in c) Object.hasOwnProperty.call(c, k) && e(h, c, k);
638
- return t(h, c), h;
639
- }, s = Ce && Ce.__importDefault || function(c) {
650
+ if (c != null) for (var S in c) Object.hasOwnProperty.call(c, S) && e(h, c, S);
651
+ return n(h, c), h;
652
+ }, r = Se && Se.__importDefault || function(c) {
640
653
  return c && c.__esModule ? c : { default: c };
641
654
  };
642
- Object.defineProperty(n, "__esModule", { value: !0 }), n.type = n.remove = n.insert = void 0;
643
- const d = pt(), l = i(at()), a = s(Ht()), E = {
655
+ Object.defineProperty(a, "__esModule", { value: !0 }), a.type = a.remove = a.insert = void 0;
656
+ const u = ht(), o = t(ft()), l = r(Jt()), E = {
644
657
  create(c) {
645
658
  return c;
646
659
  },
@@ -652,854 +665,861 @@ function Kt() {
652
665
  throw Error("Invalid document snapshot: " + c);
653
666
  const h = [];
654
667
  return {
655
- skip(k) {
656
- let Z = d.uniToStrPos(c, k);
657
- if (Z > c.length)
668
+ skip(S) {
669
+ let Y = u.uniToStrPos(c, S);
670
+ if (Y > c.length)
658
671
  throw Error("The op is too long for this document");
659
- h.push(c.slice(0, Z)), c = c.slice(Z);
672
+ h.push(c.slice(0, Y)), c = c.slice(Y);
660
673
  },
661
- append(k) {
662
- h.push(k);
674
+ append(S) {
675
+ h.push(S);
663
676
  },
664
- del(k) {
665
- c = c.slice(d.uniToStrPos(c, k));
677
+ del(S) {
678
+ c = c.slice(u.uniToStrPos(c, S));
666
679
  },
667
680
  build() {
668
681
  return h.join("") + c;
669
682
  }
670
683
  };
671
684
  },
672
- slice: l.uniSlice
673
- }, W = l.default(E), O = Object.assign(Object.assign({}, W), { api: a.default });
674
- n.type = O, n.insert = (c, h) => h.length === 0 ? [] : c === 0 ? [h] : [c, h], n.remove = (c, h) => l.dlen(h) === 0 ? [] : c === 0 ? [{ d: h }] : [c, { d: h }];
675
- var o = at();
676
- Object.defineProperty(n, "makeType", { enumerable: !0, get: function() {
677
- return o.default;
685
+ slice: o.uniSlice
686
+ }, x = o.default(E), _ = Object.assign(Object.assign({}, x), { api: l.default });
687
+ a.type = _, a.insert = (c, h) => h.length === 0 ? [] : c === 0 ? [h] : [c, h], a.remove = (c, h) => o.dlen(h) === 0 ? [] : c === 0 ? [{ d: h }] : [c, { d: h }];
688
+ var s = ft();
689
+ Object.defineProperty(a, "makeType", { enumerable: !0, get: function() {
690
+ return s.default;
678
691
  } });
679
- }(it)), it;
692
+ }(Se)), Se;
680
693
  }
681
- (function(n) {
682
- var e = Ce && Ce.__importDefault || function(r) {
683
- return r && r.__esModule ? r : {
684
- default: r
694
+ var Et;
695
+ function Zt() {
696
+ return Et || (Et = 1, function(a) {
697
+ var e = Ze && Ze.__importDefault || function(i) {
698
+ return i && i.__esModule ? i : {
699
+ default: i
700
+ };
685
701
  };
686
- };
687
- Object.defineProperty(n, "__esModule", {
688
- value: !0
689
- }), n.editOp = n.replaceOp = n.insertOp = n.moveOp = n.removeOp = n.type = void 0;
690
- const t = e(ct), i = e(dt), s = ft, d = ht;
691
- function l(r, u) {
692
- if (!r) throw new Error(u);
693
- }
694
- n.type = {
695
- name: "json1",
696
- uri: "http://sharejs.org/types/JSONv1",
697
- readCursor: s.readCursor,
698
- writeCursor: s.writeCursor,
699
- create: (r) => r,
700
- isNoop: (r) => r == null,
701
- setDebug(r) {
702
- },
703
- registerSubtype: J,
704
- checkValidOp: z,
705
- normalize: H,
706
- apply: De,
707
- transformPosition: ue,
708
- compose: ne,
709
- tryTransform: nt,
710
- transform: At,
711
- makeInvertible: Ae,
712
- invert: ae,
713
- invertWithDoc: Dt,
714
- RM_UNEXPECTED_CONTENT: d.ConflictType.RM_UNEXPECTED_CONTENT,
715
- DROP_COLLISION: d.ConflictType.DROP_COLLISION,
716
- BLACKHOLE: d.ConflictType.BLACKHOLE,
717
- transformNoConflict: (r, u, y) => _t(() => !0, r, u, y),
718
- typeAllowingConflictsPred: (r) => Object.assign(Object.assign({}, n.type), {
719
- transform: (u, y, D) => _t(r, u, y, D)
720
- })
721
- };
722
- const a = (r) => r ? r.getComponent() : null;
723
- function E(r) {
724
- return r && typeof r == "object" && !Array.isArray(r);
725
- }
726
- const W = (r) => Array.isArray(r) ? r.slice() : r !== null && typeof r == "object" ? Object.assign({}, r) : r, O = (r) => r && (r.p != null || r.r !== void 0), o = (r) => r && (r.d != null || r.i !== void 0);
727
- function c(r, u) {
728
- return l(r != null), typeof u == "number" ? (l(Array.isArray(r), "Invalid key - child is not an array"), (r = r.slice()).splice(u, 1)) : (l(E(r), "Invalid key - child is not an object"), delete (r = Object.assign({}, r))[u]), r;
729
- }
730
- function h(r, u, y) {
731
- return typeof u == "number" ? (l(r != null, "Container is missing for key"), l(Array.isArray(r), "Cannot use numerical key for object container"), l(r.length >= u, "Cannot insert into out of bounds index"), r.splice(u, 0, y)) : (l(E(r), "Cannot insert into missing item"), l(r[u] === void 0, "Trying to overwrite value at key. Your op needs to remove it first"), r[u] = y), y;
732
- }
733
- n.removeOp = (r, u = !0) => s.writeCursor().writeAtPath(r, "r", u).get(), n.moveOp = (r, u) => s.writeCursor().writeMove(r, u).get(), n.insertOp = (r, u) => s.writeCursor().writeAtPath(r, "i", u).get(), n.replaceOp = (r, u, y) => s.writeCursor().at(r, (D) => {
734
- D.write("r", u), D.write("i", y);
735
- }).get(), n.editOp = (r, u, y, D = !1) => s.writeCursor().at(r, (m) => _(m, u, y, D)).get();
736
- const k = (r, u) => r != null && (typeof u == "number" ? Array.isArray(r) : typeof r == "object"), Z = (r, u) => k(r, u) ? r[u] : void 0, pe = {};
737
- function J(r) {
738
- let u = r.type ? r.type : r;
739
- u.name && (pe[u.name] = u), u.uri && (pe[u.uri] = u);
740
- }
741
- const Ie = (r) => {
742
- const u = pe[r];
743
- if (u) return u;
744
- throw Error("Missing type: " + r);
745
- };
746
- J(Kt());
747
- const xe = (r, u) => r + u;
748
- J({
749
- name: "number",
750
- apply: xe,
751
- compose: xe,
752
- invert: (r) => -r,
753
- transform: (r) => r
754
- });
755
- const ve = (r) => r == null ? null : r.et ? Ie(r.et) : r.es ? pe["text-unicode"] : r.ena != null ? pe.number : null, f = (r) => r.es ? r.es : r.ena != null ? r.ena : r.e, _ = (r, u, y, D = !1) => {
756
- const [m, C] = typeof u == "string" ? [Ie(u), u] : [u, u.name];
757
- !D && m.isNoop && m.isNoop(y) || (C === "number" ? r.write("ena", y) : C === "text-unicode" ? r.write("es", y) : (r.write("et", C), r.write("e", y)));
758
- };
759
- function w(r) {
760
- l(typeof r == "number"), l(r >= 0), l(r === (0 | r));
761
- }
762
- function L(r) {
763
- typeof r == "number" ? w(r) : l(typeof r == "string");
764
- }
765
- function z(r) {
766
- if (r === null) return;
767
- const u = /* @__PURE__ */ new Set(), y = /* @__PURE__ */ new Set(), D = (C) => {
768
- let $ = !0, j = !1;
769
- for (let p in C) {
770
- const v = C[p];
771
- if ($ = !1, l(p === "p" || p === "r" || p === "d" || p === "i" || p === "e" || p === "es" || p === "ena" || p === "et", "Invalid component item '" + p + "'"), p === "p") w(v), l(!u.has(v)), u.add(v), l(C.r === void 0);
772
- else if (p === "d") w(v), l(!y.has(v)), y.add(v), l(C.i === void 0);
773
- else if (p === "e" || p === "es" || p === "ena") {
774
- l(!j), j = !0;
775
- const b = ve(C);
776
- l(b, "Missing type in edit"), b.checkValidOp && b.checkValidOp(f(C));
702
+ Object.defineProperty(a, "__esModule", {
703
+ value: !0
704
+ }), a.editOp = a.replaceOp = a.insertOp = a.moveOp = a.removeOp = a.type = void 0;
705
+ const n = e(zt()), t = e(Xt()), r = At(), u = Mt();
706
+ function o(i, d) {
707
+ if (!i) throw new Error(d);
708
+ }
709
+ a.type = {
710
+ name: "json1",
711
+ uri: "http://sharejs.org/types/JSONv1",
712
+ readCursor: r.readCursor,
713
+ writeCursor: r.writeCursor,
714
+ create: (i) => i,
715
+ isNoop: (i) => i == null,
716
+ setDebug(i) {
717
+ },
718
+ registerSubtype: Z,
719
+ checkValidOp: z,
720
+ normalize: q,
721
+ apply: Ee,
722
+ transformPosition: ce,
723
+ compose: ne,
724
+ tryTransform: st,
725
+ transform: kt,
726
+ makeInvertible: De,
727
+ invert: le,
728
+ invertWithDoc: Ut,
729
+ RM_UNEXPECTED_CONTENT: u.ConflictType.RM_UNEXPECTED_CONTENT,
730
+ DROP_COLLISION: u.ConflictType.DROP_COLLISION,
731
+ BLACKHOLE: u.ConflictType.BLACKHOLE,
732
+ transformNoConflict: (i, d, m) => gt(() => !0, i, d, m),
733
+ typeAllowingConflictsPred: (i) => Object.assign(Object.assign({}, a.type), {
734
+ transform: (d, m, D) => gt(i, d, m, D)
735
+ })
736
+ };
737
+ const l = (i) => i ? i.getComponent() : null;
738
+ function E(i) {
739
+ return i && typeof i == "object" && !Array.isArray(i);
740
+ }
741
+ const x = (i) => Array.isArray(i) ? i.slice() : i !== null && typeof i == "object" ? Object.assign({}, i) : i, _ = (i) => i && (i.p != null || i.r !== void 0), s = (i) => i && (i.d != null || i.i !== void 0);
742
+ function c(i, d) {
743
+ return o(i != null), typeof d == "number" ? (o(Array.isArray(i), "Invalid key - child is not an array"), (i = i.slice()).splice(d, 1)) : (o(E(i), "Invalid key - child is not an object"), delete (i = Object.assign({}, i))[d]), i;
744
+ }
745
+ function h(i, d, m) {
746
+ return typeof d == "number" ? (o(i != null, "Container is missing for key"), o(Array.isArray(i), "Cannot use numerical key for object container"), o(i.length >= d, "Cannot insert into out of bounds index"), i.splice(d, 0, m)) : (o(E(i), "Cannot insert into missing item"), o(i[d] === void 0, "Trying to overwrite value at key. Your op needs to remove it first"), i[d] = m), m;
747
+ }
748
+ a.removeOp = (i, d = !0) => r.writeCursor().writeAtPath(i, "r", d).get(), a.moveOp = (i, d) => r.writeCursor().writeMove(i, d).get(), a.insertOp = (i, d) => r.writeCursor().writeAtPath(i, "i", d).get(), a.replaceOp = (i, d, m) => r.writeCursor().at(i, (D) => {
749
+ D.write("r", d), D.write("i", m);
750
+ }).get(), a.editOp = (i, d, m, D = !1) => r.writeCursor().at(i, (O) => y(O, d, m, D)).get();
751
+ const S = (i, d) => i != null && (typeof d == "number" ? Array.isArray(i) : typeof i == "object"), Y = (i, d) => S(i, d) ? i[d] : void 0, pe = {};
752
+ function Z(i) {
753
+ let d = i.type ? i.type : i;
754
+ d.name && (pe[d.name] = d), d.uri && (pe[d.uri] = d);
755
+ }
756
+ const Ce = (i) => {
757
+ const d = pe[i];
758
+ if (d) return d;
759
+ throw Error("Missing type: " + i);
760
+ };
761
+ Z(Yt());
762
+ const Ge = (i, d) => i + d;
763
+ Z({
764
+ name: "number",
765
+ apply: Ge,
766
+ compose: Ge,
767
+ invert: (i) => -i,
768
+ transform: (i) => i
769
+ });
770
+ const ve = (i) => i == null ? null : i.et ? Ce(i.et) : i.es ? pe["text-unicode"] : i.ena != null ? pe.number : null, f = (i) => i.es ? i.es : i.ena != null ? i.ena : i.e, y = (i, d, m, D = !1) => {
771
+ const [O, I] = typeof d == "string" ? [Ce(d), d] : [d, d.name];
772
+ !D && O.isNoop && O.isNoop(m) || (I === "number" ? i.write("ena", m) : I === "text-unicode" ? i.write("es", m) : (i.write("et", I), i.write("e", m)));
773
+ };
774
+ function b(i) {
775
+ o(typeof i == "number"), o(i >= 0), o(i === (0 | i));
776
+ }
777
+ function L(i) {
778
+ typeof i == "number" ? b(i) : o(typeof i == "string");
779
+ }
780
+ function z(i) {
781
+ if (i === null) return;
782
+ const d = /* @__PURE__ */ new Set(), m = /* @__PURE__ */ new Set(), D = (I) => {
783
+ let R = !0, $ = !1;
784
+ for (let p in I) {
785
+ const v = I[p];
786
+ if (R = !1, o(p === "p" || p === "r" || p === "d" || p === "i" || p === "e" || p === "es" || p === "ena" || p === "et", "Invalid component item '" + p + "'"), p === "p") b(v), o(!d.has(v)), d.add(v), o(I.r === void 0);
787
+ else if (p === "d") b(v), o(!m.has(v)), m.add(v), o(I.i === void 0);
788
+ else if (p === "e" || p === "es" || p === "ena") {
789
+ o(!$), $ = !0;
790
+ const w = ve(I);
791
+ o(w, "Missing type in edit"), w.checkValidOp && w.checkValidOp(f(I));
792
+ }
777
793
  }
778
- }
779
- l(!$);
780
- }, m = (C, $, j) => {
781
- if (!Array.isArray(C)) throw Error("Op must be null or a list");
782
- if (C.length === 0) throw Error("Empty descent");
783
- $ || L(C[0]);
784
- let p = 1, v = 0, b = 0;
785
- for (let I = 0; I < C.length; I++) {
786
- const T = C[I];
787
- if (l(T != null), Array.isArray(T)) {
788
- const G = m(T, !1);
789
- if (v) {
790
- const g = typeof b, N = typeof G;
791
- g === N ? l(b < G, "descent keys are not in order") : l(g === "number" && N === "string");
794
+ o(!R);
795
+ }, O = (I, R, $) => {
796
+ if (!Array.isArray(I)) throw Error("Op must be null or a list");
797
+ if (I.length === 0) throw Error("Empty descent");
798
+ R || L(I[0]);
799
+ let p = 1, v = 0, w = 0;
800
+ for (let C = 0; C < I.length; C++) {
801
+ const N = I[C];
802
+ if (o(N != null), Array.isArray(N)) {
803
+ const B = O(N, !1);
804
+ if (v) {
805
+ const g = typeof w, U = typeof B;
806
+ g === U ? o(w < B, "descent keys are not in order") : o(g === "number" && U === "string");
807
+ }
808
+ w = B, v++, p = 3;
809
+ } else typeof N == "object" ? (o(p === 1, `Prev not scalar - instead ${p}`), D(N), p = 2) : (o(p !== 3), L(N), o(r.isValidPathItem(N), "Invalid path key"), p = 1);
810
+ }
811
+ return o(v !== 1, "Operation makes multiple descents. Remove some []"), o(p === 2 || p === 3), I[0];
812
+ };
813
+ O(i, !0), o(d.size === m.size, "Mismatched picks and drops in op");
814
+ for (let I = 0; I < d.size; I++) o(d.has(I)), o(m.has(I));
815
+ }
816
+ function q(i) {
817
+ let d = 0, m = [];
818
+ const D = r.writeCursor();
819
+ return D.mergeTree(i, (O, I) => {
820
+ const R = ve(O);
821
+ if (R) {
822
+ const p = f(O);
823
+ y(I, R, R.normalize ? R.normalize(p) : p);
824
+ }
825
+ for (const p of ["r", "p", "i", "d"]) if (O[p] !== void 0) {
826
+ const v = p === "p" || p === "d" ? ($ = O[p], m[$] == null && (m[$] = d++), m[$]) : O[p];
827
+ I.write(p, v);
828
+ }
829
+ var $;
830
+ }), D.get();
831
+ }
832
+ function Ee(i, d) {
833
+ if (z(d), d === null) return i;
834
+ const m = [];
835
+ return function D(O, I) {
836
+ let R = O, $ = 0, p = {
837
+ root: O
838
+ }, v = 0, w = p, C = "root";
839
+ function N() {
840
+ for (; v < $; v++) {
841
+ let B = I[v];
842
+ typeof B != "object" && (o(S(w, C)), w = w[C] = x(w[C]), C = B);
792
843
  }
793
- b = G, v++, p = 3;
794
- } else typeof T == "object" ? (l(p === 1, `Prev not scalar - instead ${p}`), D(T), p = 2) : (l(p !== 3), L(T), l(s.isValidPathItem(T), "Invalid path key"), p = 1);
795
- }
796
- return l(v !== 1, "Operation makes multiple descents. Remove some []"), l(p === 2 || p === 3), C[0];
797
- };
798
- m(r, !0), l(u.size === y.size, "Mismatched picks and drops in op");
799
- for (let C = 0; C < u.size; C++) l(u.has(C)), l(y.has(C));
800
- }
801
- function H(r) {
802
- let u = 0, y = [];
803
- const D = s.writeCursor();
804
- return D.mergeTree(r, (m, C) => {
805
- const $ = ve(m);
806
- if ($) {
807
- const p = f(m);
808
- _(C, $, $.normalize ? $.normalize(p) : p);
809
- }
810
- for (const p of ["r", "p", "i", "d"]) if (m[p] !== void 0) {
811
- const v = p === "p" || p === "d" ? (j = m[p], y[j] == null && (y[j] = u++), y[j]) : m[p];
812
- C.write(p, v);
813
- }
814
- var j;
815
- }), D.get();
816
- }
817
- function De(r, u) {
818
- if (z(u), u === null) return r;
819
- const y = [];
820
- return function D(m, C) {
821
- let $ = m, j = 0, p = {
822
- root: m
823
- }, v = 0, b = p, I = "root";
824
- function T() {
825
- for (; v < j; v++) {
826
- let G = C[v];
827
- typeof G != "object" && (l(k(b, I)), b = b[I] = W(b[I]), I = G);
828
844
  }
829
- }
830
- for (; j < C.length; j++) {
831
- const G = C[j];
832
- if (Array.isArray(G)) {
833
- const g = D($, G);
834
- g !== $ && g !== void 0 && (T(), $ = b[I] = g);
835
- } else if (typeof G == "object") {
836
- G.d != null ? (T(), $ = h(b, I, y[G.d])) : G.i !== void 0 && (T(), $ = h(b, I, G.i));
837
- const g = ve(G);
838
- if (g) T(), $ = b[I] = g.apply($, f(G));
839
- else if (G.e !== void 0) throw Error("Subtype " + G.et + " undefined");
840
- } else $ = Z($, G);
841
- }
842
- return p.root;
843
- }(r = function D(m, C) {
844
- const $ = [];
845
- let j = 0;
846
- for (; j < C.length; j++) {
847
- const I = C[j];
848
- if (Array.isArray(I)) break;
849
- typeof I != "object" && ($.push(m), m = Z(m, I));
850
- }
851
- for (let I = C.length - 1; I >= j; I--) m = D(m, C[I]);
852
- for (--j; j >= 0; j--) {
853
- const I = C[j];
854
- if (typeof I != "object") {
855
- const T = $.pop();
856
- m = m === Z(T, I) ? T : m === void 0 ? c(T, I) : (v = I, b = m, (p = W(p = T))[v] = b, p);
857
- } else O(I) && (l(m !== void 0, "Cannot pick up or remove undefined"), I.p != null && (y[I.p] = m), m = void 0);
858
- }
859
- var p, v, b;
860
- return m;
861
- }(r, u), u);
862
- }
863
- function ue(r, u) {
864
- r = r.slice(), z(u);
865
- const y = s.readCursor(u);
866
- let D, m, C = !1;
867
- const $ = [];
868
- for (let p = 0; ; p++) {
869
- const v = r[p], b = y.getComponent();
870
- if (b && (b.r !== void 0 ? C = !0 : b.p != null && (C = !1, D = b.p, m = p)), p >= r.length) break;
871
- let I = 0;
872
- const T = s.advancer(y, void 0, (g, N) => {
873
- O(N) && I++;
874
- });
875
- $.unshift(T);
876
- const G = T(v);
877
- if (typeof v == "number" && (r[p] -= I), !G) break;
845
+ for (; $ < I.length; $++) {
846
+ const B = I[$];
847
+ if (Array.isArray(B)) {
848
+ const g = D(R, B);
849
+ g !== R && g !== void 0 && (N(), R = w[C] = g);
850
+ } else if (typeof B == "object") {
851
+ B.d != null ? (N(), R = h(w, C, m[B.d])) : B.i !== void 0 && (N(), R = h(w, C, B.i));
852
+ const g = ve(B);
853
+ if (g) N(), R = w[C] = g.apply(R, f(B));
854
+ else if (B.e !== void 0) throw Error("Subtype " + B.et + " undefined");
855
+ } else R = Y(R, B);
856
+ }
857
+ return p.root;
858
+ }(i = function D(O, I) {
859
+ const R = [];
860
+ let $ = 0;
861
+ for (; $ < I.length; $++) {
862
+ const C = I[$];
863
+ if (Array.isArray(C)) break;
864
+ typeof C != "object" && (R.push(O), O = Y(O, C));
865
+ }
866
+ for (let C = I.length - 1; C >= $; C--) O = D(O, I[C]);
867
+ for (--$; $ >= 0; $--) {
868
+ const C = I[$];
869
+ if (typeof C != "object") {
870
+ const N = R.pop();
871
+ O = O === Y(N, C) ? N : O === void 0 ? c(N, C) : (v = C, w = O, (p = x(p = N))[v] = w, p);
872
+ } else _(C) && (o(O !== void 0, "Cannot pick up or remove undefined"), C.p != null && (m[C.p] = O), O = void 0);
873
+ }
874
+ var p, v, w;
875
+ return O;
876
+ }(i, d), d);
878
877
  }
879
- if ($.forEach((p) => p.end()), C) return null;
880
- const j = () => {
881
- let p = 0;
882
- if (D != null) {
883
- const v = y.getPath();
884
- p = v.length, r = v.concat(r.slice(m));
878
+ function ce(i, d) {
879
+ i = i.slice(), z(d);
880
+ const m = r.readCursor(d);
881
+ let D, O, I = !1;
882
+ const R = [];
883
+ for (let p = 0; ; p++) {
884
+ const v = i[p], w = m.getComponent();
885
+ if (w && (w.r !== void 0 ? I = !0 : w.p != null && (I = !1, D = w.p, O = p)), p >= i.length) break;
886
+ let C = 0;
887
+ const N = r.advancer(m, void 0, (g, U) => {
888
+ _(U) && C++;
889
+ });
890
+ R.unshift(N);
891
+ const B = N(v);
892
+ if (typeof v == "number" && (i[p] -= C), !B) break;
885
893
  }
886
- for (; p < r.length; p++) {
887
- const v = r[p], b = a(y), I = ve(b);
888
- if (I) {
889
- const g = f(b);
890
- I.transformPosition && (r[p] = I.transformPosition(r[p], g));
891
- break;
894
+ if (R.forEach((p) => p.end()), I) return null;
895
+ const $ = () => {
896
+ let p = 0;
897
+ if (D != null) {
898
+ const v = m.getPath();
899
+ p = v.length, i = v.concat(i.slice(O));
892
900
  }
893
- let T = 0;
894
- const G = s.advancer(y, (g, N) => o(N) ? ~(g - T) : g - T, (g, N) => {
895
- o(N) && T++;
896
- })(v);
897
- if (typeof v == "number" && (r[p] += T), !G) break;
898
- }
899
- };
900
- return D != null ? y.eachDrop(null, (p) => {
901
- p === D && j();
902
- }) : j(), r;
903
- }
904
- function ne(r, u) {
905
- if (z(r), z(u), r == null) return u;
906
- if (u == null) return r;
907
- let y = 0;
908
- const D = s.readCursor(r), m = s.readCursor(u), C = s.writeCursor(), $ = [], j = [], p = [], v = [], b = [], I = [], T = /* @__PURE__ */ new Set();
909
- D.traverse(null, (g) => {
910
- g.p != null && (p[g.p] = D.clone());
911
- }), m.traverse(null, (g) => {
912
- g.d != null && (v[g.d] = m.clone());
913
- });
914
- const G = s.writeCursor();
915
- return function g(N, re, te, K, se, Te, me, _e) {
916
- l(re || te);
917
- const oe = a(re), Pe = a(te), Me = !!Pe && Pe.r !== void 0, Le = !!oe && oe.i !== void 0, Ue = oe ? oe.d : null, Ee = Pe ? Pe.p : null, $e = (Te || Me) && Ee == null;
918
- if (Ee != null) K = v[Ee], me = j[Ee] = new s.WriteCursor();
919
- else if (Pe && Pe.r !== void 0) K = null;
920
- else {
921
- const P = a(K);
922
- P && P.d != null && (K = null);
923
- }
924
- const Q = a(K);
925
- if (Ue != null) if (N = p[Ue], _e = $[Ue] = new s.WriteCursor(), $e) Te && !Me && _e.write("r", !0);
926
- else {
927
- const P = b[Ue] = y++;
928
- me.write("d", P);
929
- }
930
- else if (oe && oe.i !== void 0) N = null;
931
- else {
932
- const P = a(N);
933
- P && P.p != null && (N = null);
934
- }
935
- let U;
936
- Le ? (l(se === void 0), U = oe.i) : U = se;
937
- const B = (Ee == null ? !Le || Te || Me : U === void 0) ? null : me.getComponent();
938
- if (Ee != null) {
939
- if (!(se !== void 0 || Le)) {
940
- const P = Ue != null ? b[Ue] : y++;
941
- I[Ee] = P, _e.write("p", P);
901
+ for (; p < i.length; p++) {
902
+ const v = i[p], w = l(m), C = ve(w);
903
+ if (C) {
904
+ const g = f(w);
905
+ C.transformPosition && (i[p] = C.transformPosition(i[p], g));
906
+ break;
907
+ }
908
+ let N = 0;
909
+ const B = r.advancer(m, (g, U) => s(U) ? ~(g - N) : g - N, (g, U) => {
910
+ s(U) && N++;
911
+ })(v);
912
+ if (typeof v == "number" && (i[p] += N), !B) break;
942
913
  }
943
- } else Me && (Le || se !== void 0 || (Pe.r, _e.write("r", Pe.r)));
944
- const M = $e ? null : ve(oe), A = ve(Q);
945
- if ((M || A) && (M && M.name, A && A.name), M && A) {
946
- l(M === A);
947
- const P = f(oe), x = f(Q), he = M.compose(P, x);
948
- _(me, M, he), T.add(Q);
949
- } else M ? _(me, M, f(oe)) : A && (_(me, A, f(Q)), T.add(Q));
950
- const R = typeof U == "object" && U != null;
951
- let X = !1, Y = 0, ee = 0, fe = 0, de = 0, le = 0;
952
- const ye = s.advancer(K, (P, x) => o(x) ? de - P - 1 : P - de, (P, x) => {
953
- o(x) && de++;
954
- }), q = s.advancer(N, (P, x) => O(x) ? Y - P - 1 : P - Y, (P, x) => {
955
- O(x) && Y++;
914
+ };
915
+ return D != null ? m.eachDrop(null, (p) => {
916
+ p === D && $();
917
+ }) : $(), i;
918
+ }
919
+ function ne(i, d) {
920
+ if (z(i), z(d), i == null) return d;
921
+ if (d == null) return i;
922
+ let m = 0;
923
+ const D = r.readCursor(i), O = r.readCursor(d), I = r.writeCursor(), R = [], $ = [], p = [], v = [], w = [], C = [], N = /* @__PURE__ */ new Set();
924
+ D.traverse(null, (g) => {
925
+ g.p != null && (p[g.p] = D.clone());
926
+ }), O.traverse(null, (g) => {
927
+ g.d != null && (v[g.d] = O.clone());
956
928
  });
957
- if (s.eachChildOf(re, te, (P, x, he) => {
958
- let be, We, He = P, Ne = P, Ye = P;
959
- if (typeof P == "number") {
960
- let Oe = P + fe;
961
- We = ye(Oe), Ne = Oe + de;
962
- let ce = P + ee;
963
- be = q(ce), o(a(We)) && (be = null), He = ce + Y, Ye = P + le, l(He >= 0, "p1PickKey is negative"), l(Ne >= 0, "p2DropKey is negative");
964
- const Re = o(a(x)), Ge = O(a(he));
965
- (Re || Ge && !$e) && le--, Re && ee--, Ge && fe--;
966
- } else be = q(P), We = ye(P);
967
- _e.descend(He), me.descend(Ne);
968
- const ze = R && !o(a(x)) ? U[Ye] : void 0, Se = g(be, x, he, We, ze, $e, me, _e);
969
- var je, S, ie;
970
- R && !$e ? ze !== Se && (X || (U = Array.isArray(U) ? U.slice() : Object.assign({}, U), X = !0), je = U, ie = Se, typeof (S = Ye) == "number" ? (l(Array.isArray(je)), l(S < je.length)) : (l(!Array.isArray(je)), l(je[S] !== void 0)), ie === void 0 ? typeof S == "number" ? je.splice(S, 1) : delete je[S] : je[S] = ie) : l(Se === void 0), me.ascend(), _e.ascend();
971
- }), q.end(), ye.end(), B != null) B.i = U;
972
- else if (!Te && !Me && Ee == null) return U;
973
- }(D, D.clone(), m, m.clone(), void 0, !1, C, G), C.reset(), C.mergeTree(G.get()), C.reset(), C.get(), $.map((g) => g.get()), j.map((g) => g.get()), D.traverse(C, (g, N) => {
974
- const re = g.p;
975
- if (re != null) {
976
- const te = b[re];
977
- te != null && N.write("p", te);
978
- const K = $[re];
979
- K && K.get(), K && N.mergeTree(K.get());
980
- } else g.r !== void 0 && N.write("r", g.r);
981
- }), C.reset(), C.get(), m.traverse(C, (g, N) => {
982
- const re = g.d;
983
- if (re != null) {
984
- const K = I[re];
985
- K != null && N.write("d", K);
986
- const se = j[re];
987
- se && N.mergeTree(se.get());
988
- } else g.i !== void 0 && N.write("i", g.i);
989
- const te = ve(g);
990
- te && !T.has(g) && _(N, te, f(g));
991
- }), C.get();
992
- }
993
- function ae(r) {
994
- if (r == null) return null;
995
- const u = new s.ReadCursor(r), y = new s.WriteCursor();
996
- let D;
997
- const m = [], C = [];
998
- return function $(j, p, v) {
999
- const b = j.getComponent();
1000
- let I, T = !1;
1001
- if (b) {
1002
- b.p != null && (p.write("d", b.p), m[b.p] = j.clone()), b.r !== void 0 && p.write("i", b.r), b.d != null && (p.write("p", b.d), v = void 0), b.i !== void 0 && (v = I = b.i);
1003
- const g = ve(b);
1004
- g && (v === void 0 ? (D || (D = /* @__PURE__ */ new Set()), D.add(b)) : (f(b), v = g.apply(v, f(b)), T = !0));
1005
- }
1006
- let G = 0;
1007
- for (const g of j) {
1008
- p.descend(g);
1009
- const N = typeof g == "number" ? g - G : g, re = Z(v, N);
1010
- o(j.getComponent()) && G++;
1011
- const te = $(j, p, re);
1012
- if (v !== void 0 && te !== void 0) {
1013
- if (T || (T = !0, v = W(v)), !k(v, N)) throw Error("Cannot modify child - invalid operation");
1014
- v[N] = te;
929
+ const B = r.writeCursor();
930
+ return function g(U, re, te, K, se, Ne, Oe, ye) {
931
+ o(re || te);
932
+ const oe = l(re), Pe = l(te), Ae = !!Pe && Pe.r !== void 0, Le = !!oe && oe.i !== void 0, Te = oe ? oe.d : null, Ie = Pe ? Pe.p : null, Re = (Ne || Ae) && Ie == null;
933
+ if (Ie != null) K = v[Ie], Oe = $[Ie] = new r.WriteCursor();
934
+ else if (Pe && Pe.r !== void 0) K = null;
935
+ else {
936
+ const T = l(K);
937
+ T && T.d != null && (K = null);
1015
938
  }
1016
- p.ascend();
1017
- }
1018
- if (I === void 0) return T ? v : void 0;
1019
- p.write("r", v);
1020
- }(u, y, void 0), D && (y.reset(), function $(j, p, v) {
1021
- const b = p.getComponent();
1022
- if (b) {
1023
- const g = b.d;
1024
- if (g != null && (j = m[g], v = C[g] = s.writeCursor()), D.has(b)) {
1025
- const N = ve(b);
1026
- if (!N.invert) throw Error(`Cannot invert subtype ${N.name}`);
1027
- _(v, N, N.invert(f(b)));
939
+ const Q = l(K);
940
+ if (Te != null) if (U = p[Te], ye = R[Te] = new r.WriteCursor(), Re) Ne && !Ae && ye.write("r", !0);
941
+ else {
942
+ const T = w[Te] = m++;
943
+ Oe.write("d", T);
1028
944
  }
1029
- }
1030
- let I = 0, T = 0;
1031
- const G = s.advancer(j, (g, N) => O(N) ? I - g - 1 : g - I, (g, N) => {
1032
- O(N) && I++;
1033
- });
1034
- for (const g of p) if (typeof g == "number") {
1035
- const N = g - T, re = G(N), te = N + I;
1036
- v.descend(te), $(re, p, v), o(p.getComponent()) && T++, v.ascend();
1037
- } else v.descend(g), $(G(g), p, v), v.ascend();
1038
- G.end();
1039
- }(u.clone(), u, y), C.length && (y.reset(), u.traverse(y, ($, j) => {
1040
- const p = $.p;
1041
- if (p != null) {
1042
- const v = C[p];
1043
- v && v.get(), v && j.mergeTree(v.get());
1044
- }
1045
- }))), y.get();
1046
- }
1047
- const ge = (r, u) => r.some((y) => typeof y == "object" && (Array.isArray(y) ? ge(y, u) : u(y)));
1048
- function Ae(r, u) {
1049
- if (r == null || !ge(r, (p) => {
1050
- var v;
1051
- return p.r !== void 0 || ((v = ve(p)) === null || v === void 0 ? void 0 : v.makeInvertible) != null;
1052
- })) return r;
1053
- const y = new s.ReadCursor(r), D = new s.WriteCursor();
1054
- let m = !1;
1055
- const C = [], $ = [], j = (p, v, b) => {
1056
- const I = p.getComponent();
1057
- let T = !1;
1058
- if (I) {
1059
- I.d != null && v.write("d", I.d), I.i !== void 0 && v.write("i", I.i);
1060
- const g = I.p;
1061
- if (g != null && (C[g] = p.clone(), l(b !== void 0, "Operation picks up at an invalid key"), $[g] = b, v.write("p", I.p)), I.r !== void 0 && b === void 0) throw Error("Invalid doc / op in makeInvertible: removed item missing from doc");
1062
- const N = ve(I);
1063
- N && (N.makeInvertible ? m = !0 : _(v, N, f(I), !0));
1064
- }
1065
- let G = 0;
1066
- for (const g of p) {
1067
- v.descend(g);
1068
- const N = typeof g == "number" ? g - G : g, re = Z(b, N), te = j(p, v, re);
1069
- re !== te && (T || (T = !0, b = W(b)), te === void 0 ? (b = c(b, N), typeof g == "number" && G++) : b[N] = te), v.ascend();
1070
- }
1071
- return I && (I.r !== void 0 ? (v.write("r", i.default(b)), b = void 0) : I.p != null && (b = void 0)), b;
1072
- };
1073
- return j(y, D, u), D.get(), m && (D.reset(), function p(v, b, I, T, G) {
1074
- const g = b.getComponent();
1075
- if (g) {
1076
- g.i !== void 0 ? (T = g.i, G = !0) : g.d != null && (T = $[g.d], v = C[g.d], G = !1, g.d);
1077
- let K = ve(g);
1078
- if (K && K.makeInvertible) {
1079
- const se = f(g);
1080
- _(I, K, K.makeInvertible(se, T), !0);
945
+ else if (oe && oe.i !== void 0) U = null;
946
+ else {
947
+ const T = l(U);
948
+ T && T.p != null && (U = null);
1081
949
  }
1082
- }
1083
- let N = 0, re = 0;
1084
- const te = s.advancer(v, (K, se) => O(se) ? N - K - 1 : K - N, (K, se) => {
1085
- O(se) && N++;
1086
- });
1087
- for (const K of b) if (typeof K == "number") {
1088
- const se = K - re, Te = te(se), me = se + N, _e = Z(T, G ? se : me);
1089
- I.descend(K), p(Te, b, I, _e, G), o(b.getComponent()) && re++, I.ascend();
1090
- } else {
1091
- const se = Z(T, K);
1092
- I.descend(K), p(te(K), b, I, se, G), I.ascend();
1093
- }
1094
- te.end();
1095
- }(y.clone(), y, D, u, !1)), D.get();
1096
- }
1097
- function Dt(r, u) {
1098
- return ae(Ae(r, u));
1099
- }
1100
- const tt = (r) => {
1101
- if (r == null) return null;
1102
- const u = r.slice();
1103
- for (let y = 0; y < r.length; y++) {
1104
- const D = u[y];
1105
- Array.isArray(D) && (u[y] = tt(D));
950
+ let A;
951
+ Le ? (o(se === void 0), A = oe.i) : A = se;
952
+ const W = (Ie == null ? !Le || Ne || Ae : A === void 0) ? null : Oe.getComponent();
953
+ if (Ie != null) {
954
+ if (!(se !== void 0 || Le)) {
955
+ const T = Te != null ? w[Te] : m++;
956
+ C[Ie] = T, ye.write("p", T);
957
+ }
958
+ } else Ae && (Le || se !== void 0 || (Pe.r, ye.write("r", Pe.r)));
959
+ const M = Re ? null : ve(oe), P = ve(Q);
960
+ if ((M || P) && (M && M.name, P && P.name), M && P) {
961
+ o(M === P);
962
+ const T = f(oe), G = f(Q), he = M.compose(T, G);
963
+ y(Oe, M, he), N.add(Q);
964
+ } else M ? y(Oe, M, f(oe)) : P && (y(Oe, P, f(Q)), N.add(Q));
965
+ const k = typeof A == "object" && A != null;
966
+ let X = !1, J = 0, ee = 0, fe = 0, de = 0, ae = 0;
967
+ const me = r.advancer(K, (T, G) => s(G) ? de - T - 1 : T - de, (T, G) => {
968
+ s(G) && de++;
969
+ }), H = r.advancer(U, (T, G) => _(G) ? J - T - 1 : T - J, (T, G) => {
970
+ _(G) && J++;
971
+ });
972
+ if (r.eachChildOf(re, te, (T, G, he) => {
973
+ let we, xe, qe = T, Me = T, Ye = T;
974
+ if (typeof T == "number") {
975
+ let _e = T + fe;
976
+ xe = me(_e), Me = _e + de;
977
+ let ue = T + ee;
978
+ we = H(ue), s(l(xe)) && (we = null), qe = ue + J, Ye = T + ae, o(qe >= 0, "p1PickKey is negative"), o(Me >= 0, "p2DropKey is negative");
979
+ const Ue = s(l(G)), Be = _(l(he));
980
+ (Ue || Be && !Re) && ae--, Ue && ee--, Be && fe--;
981
+ } else we = H(T), xe = me(T);
982
+ ye.descend(qe), Oe.descend(Me);
983
+ const Xe = k && !s(l(G)) ? A[Ye] : void 0, je = g(we, G, he, xe, Xe, Re, Oe, ye);
984
+ var $e, j, ie;
985
+ k && !Re ? Xe !== je && (X || (A = Array.isArray(A) ? A.slice() : Object.assign({}, A), X = !0), $e = A, ie = je, typeof (j = Ye) == "number" ? (o(Array.isArray($e)), o(j < $e.length)) : (o(!Array.isArray($e)), o($e[j] !== void 0)), ie === void 0 ? typeof j == "number" ? $e.splice(j, 1) : delete $e[j] : $e[j] = ie) : o(je === void 0), Oe.ascend(), ye.ascend();
986
+ }), H.end(), me.end(), W != null) W.i = A;
987
+ else if (!Ne && !Ae && Ie == null) return A;
988
+ }(D, D.clone(), O, O.clone(), void 0, !1, I, B), I.reset(), I.mergeTree(B.get()), I.reset(), I.get(), R.map((g) => g.get()), $.map((g) => g.get()), D.traverse(I, (g, U) => {
989
+ const re = g.p;
990
+ if (re != null) {
991
+ const te = w[re];
992
+ te != null && U.write("p", te);
993
+ const K = R[re];
994
+ K && K.get(), K && U.mergeTree(K.get());
995
+ } else g.r !== void 0 && U.write("r", g.r);
996
+ }), I.reset(), I.get(), O.traverse(I, (g, U) => {
997
+ const re = g.d;
998
+ if (re != null) {
999
+ const K = C[re];
1000
+ K != null && U.write("d", K);
1001
+ const se = $[re];
1002
+ se && U.mergeTree(se.get());
1003
+ } else g.i !== void 0 && U.write("i", g.i);
1004
+ const te = ve(g);
1005
+ te && !N.has(g) && y(U, te, f(g));
1006
+ }), I.get();
1106
1007
  }
1107
- return u;
1108
- };
1109
- function nt(r, u, y) {
1110
- l(y === "left" || y === "right", "Direction must be left or right");
1111
- const D = y === "left" ? 0 : 1;
1112
- if (u == null) return {
1113
- ok: !0,
1114
- result: r
1115
- };
1116
- z(r), z(u);
1117
- let m = null;
1118
- const C = [], $ = [], j = [], p = [], v = [], b = [], I = [], T = [], G = [], g = [], N = [], re = [], te = [], K = [], se = [];
1119
- let Te = 0;
1120
- const me = s.readCursor(r), _e = s.readCursor(u), oe = s.writeCursor();
1121
- if (function Q(U, B = null, M) {
1122
- const A = a(B);
1123
- A && (A.r !== void 0 ? M = B.clone() : A.p != null && (M = null, b[A.p] = U.clone()));
1124
- const R = U.getComponent();
1125
- let X;
1126
- R && (X = R.p) != null && (v[X] = B ? B.clone() : null, j[X] = U.clone(), M && (g[X] = !0, G[X] = M), A && A.p != null && (K[X] = A.p));
1127
- const Y = s.advancer(B);
1128
- for (const ee of U) Q(U, Y(ee), M);
1129
- Y.end();
1130
- }(_e, me, null), function Q(U, B, M, A, R) {
1131
- const X = M.getComponent();
1132
- let Y, ee = !1;
1133
- X && ((Y = X.d) != null ? (p[Y] = M.clone(), A != null && (se[A] == null && (se[A] = []), se[A].push(Y)), U = v[Y] || null, B = j[Y] || null, g[Y] ? (R && (N[Y] = !0), R = G[Y] || null) : !R || D !== 1 && K[Y] != null || m == null && (m = {
1134
- type: d.ConflictType.RM_UNEXPECTED_CONTENT,
1135
- op1: n.removeOp(R.getPath()),
1136
- op2: n.moveOp(B.getPath(), M.getPath())
1137
- }), ee = !0) : X.i !== void 0 && (U = B = null, ee = !0, R && m == null && (m = {
1138
- type: d.ConflictType.RM_UNEXPECTED_CONTENT,
1139
- op1: n.removeOp(R.getPath()),
1140
- op2: n.insertOp(M.getPath(), X.i)
1141
- })));
1142
- const fe = a(U);
1143
- fe && (fe.r !== void 0 ? R = U.clone() : fe.p != null && (fe.p, A = fe.p, R = null));
1144
- const de = ve(X);
1145
- de && R && m == null && (m = {
1146
- type: d.ConflictType.RM_UNEXPECTED_CONTENT,
1147
- op1: n.removeOp(R.getPath()),
1148
- op2: n.editOp(M.getPath(), de, f(X), !0)
1149
- });
1150
- let le = 0, ye = 0;
1151
- const q = s.advancer(B, (x, he) => O(he) ? le - x - 1 : x - le, (x, he) => {
1152
- O(he) && le++;
1153
- }), P = s.advancer(U);
1154
- for (const x of M) if (typeof x == "number") {
1155
- const he = x - ye, be = q(he);
1156
- ye += +Q(P(he + le), be, M, A, R);
1157
- } else {
1158
- const he = q(x);
1159
- Q(P(x), he, M, A, R);
1008
+ function le(i) {
1009
+ if (i == null) return null;
1010
+ const d = new r.ReadCursor(i), m = new r.WriteCursor();
1011
+ let D;
1012
+ const O = [], I = [];
1013
+ return function R($, p, v) {
1014
+ const w = $.getComponent();
1015
+ let C, N = !1;
1016
+ if (w) {
1017
+ w.p != null && (p.write("d", w.p), O[w.p] = $.clone()), w.r !== void 0 && p.write("i", w.r), w.d != null && (p.write("p", w.d), v = void 0), w.i !== void 0 && (v = C = w.i);
1018
+ const g = ve(w);
1019
+ g && (v === void 0 ? (D || (D = /* @__PURE__ */ new Set()), D.add(w)) : (f(w), v = g.apply(v, f(w)), N = !0));
1020
+ }
1021
+ let B = 0;
1022
+ for (const g of $) {
1023
+ p.descend(g);
1024
+ const U = typeof g == "number" ? g - B : g, re = Y(v, U);
1025
+ s($.getComponent()) && B++;
1026
+ const te = R($, p, re);
1027
+ if (v !== void 0 && te !== void 0) {
1028
+ if (N || (N = !0, v = x(v)), !S(v, U)) throw Error("Cannot modify child - invalid operation");
1029
+ v[U] = te;
1030
+ }
1031
+ p.ascend();
1032
+ }
1033
+ if (C === void 0) return N ? v : void 0;
1034
+ p.write("r", v);
1035
+ }(d, m, void 0), D && (m.reset(), function R($, p, v) {
1036
+ const w = p.getComponent();
1037
+ if (w) {
1038
+ const g = w.d;
1039
+ if (g != null && ($ = O[g], v = I[g] = r.writeCursor()), D.has(w)) {
1040
+ const U = ve(w);
1041
+ if (!U.invert) throw Error(`Cannot invert subtype ${U.name}`);
1042
+ y(v, U, U.invert(f(w)));
1043
+ }
1044
+ }
1045
+ let C = 0, N = 0;
1046
+ const B = r.advancer($, (g, U) => _(U) ? C - g - 1 : g - C, (g, U) => {
1047
+ _(U) && C++;
1048
+ });
1049
+ for (const g of p) if (typeof g == "number") {
1050
+ const U = g - N, re = B(U), te = U + C;
1051
+ v.descend(te), R(re, p, v), s(p.getComponent()) && N++, v.ascend();
1052
+ } else v.descend(g), R(B(g), p, v), v.ascend();
1053
+ B.end();
1054
+ }(d.clone(), d, m), I.length && (m.reset(), d.traverse(m, (R, $) => {
1055
+ const p = R.p;
1056
+ if (p != null) {
1057
+ const v = I[p];
1058
+ v && v.get(), v && $.mergeTree(v.get());
1059
+ }
1060
+ }))), m.get();
1061
+ }
1062
+ const ge = (i, d) => i.some((m) => typeof m == "object" && (Array.isArray(m) ? ge(m, d) : d(m)));
1063
+ function De(i, d) {
1064
+ if (i == null || !ge(i, (p) => {
1065
+ var v;
1066
+ return p.r !== void 0 || ((v = ve(p)) === null || v === void 0 ? void 0 : v.makeInvertible) != null;
1067
+ })) return i;
1068
+ const m = new r.ReadCursor(i), D = new r.WriteCursor();
1069
+ let O = !1;
1070
+ const I = [], R = [], $ = (p, v, w) => {
1071
+ const C = p.getComponent();
1072
+ let N = !1;
1073
+ if (C) {
1074
+ C.d != null && v.write("d", C.d), C.i !== void 0 && v.write("i", C.i);
1075
+ const g = C.p;
1076
+ if (g != null && (I[g] = p.clone(), o(w !== void 0, "Operation picks up at an invalid key"), R[g] = w, v.write("p", C.p)), C.r !== void 0 && w === void 0) throw Error("Invalid doc / op in makeInvertible: removed item missing from doc");
1077
+ const U = ve(C);
1078
+ U && (U.makeInvertible ? O = !0 : y(v, U, f(C), !0));
1079
+ }
1080
+ let B = 0;
1081
+ for (const g of p) {
1082
+ v.descend(g);
1083
+ const U = typeof g == "number" ? g - B : g, re = Y(w, U), te = $(p, v, re);
1084
+ re !== te && (N || (N = !0, w = x(w)), te === void 0 ? (w = c(w, U), typeof g == "number" && B++) : w[U] = te), v.ascend();
1085
+ }
1086
+ return C && (C.r !== void 0 ? (v.write("r", t.default(w)), w = void 0) : C.p != null && (w = void 0)), w;
1087
+ };
1088
+ return $(m, D, d), D.get(), O && (D.reset(), function p(v, w, C, N, B) {
1089
+ const g = w.getComponent();
1090
+ if (g) {
1091
+ g.i !== void 0 ? (N = g.i, B = !0) : g.d != null && (N = R[g.d], v = I[g.d], B = !1, g.d);
1092
+ let K = ve(g);
1093
+ if (K && K.makeInvertible) {
1094
+ const se = f(g);
1095
+ y(C, K, K.makeInvertible(se, N), !0);
1096
+ }
1097
+ }
1098
+ let U = 0, re = 0;
1099
+ const te = r.advancer(v, (K, se) => _(se) ? U - K - 1 : K - U, (K, se) => {
1100
+ _(se) && U++;
1101
+ });
1102
+ for (const K of w) if (typeof K == "number") {
1103
+ const se = K - re, Ne = te(se), Oe = se + U, ye = Y(N, B ? se : Oe);
1104
+ C.descend(K), p(Ne, w, C, ye, B), s(w.getComponent()) && re++, C.ascend();
1105
+ } else {
1106
+ const se = Y(N, K);
1107
+ C.descend(K), p(te(K), w, C, se, B), C.ascend();
1108
+ }
1109
+ te.end();
1110
+ }(m.clone(), m, D, d, !1)), D.get();
1111
+ }
1112
+ function Ut(i, d) {
1113
+ return le(De(i, d));
1114
+ }
1115
+ const it = (i) => {
1116
+ if (i == null) return null;
1117
+ const d = i.slice();
1118
+ for (let m = 0; m < i.length; m++) {
1119
+ const D = d[m];
1120
+ Array.isArray(D) && (d[m] = it(D));
1160
1121
  }
1161
- return q.end(), P.end(), ee;
1162
- }(me, _e, _e.clone(), null, null), p.map((Q) => Q && Q.get()), m) return {
1163
- ok: !1,
1164
- conflict: m
1122
+ return d;
1165
1123
  };
1166
- N.map((Q) => !!Q);
1167
- const Pe = [];
1168
- let Me = null;
1169
- (function Q(U, B, M, A, R) {
1170
- let X = !1;
1171
- const Y = a(B);
1172
- if (O(Y)) {
1173
- const q = Y.p;
1174
- q != null ? (M = p[q], A = re[q] = s.writeCursor(), X = !0, R = null) : (M = null, R = B.clone());
1175
- } else o(a(M)) && (M = null);
1176
- const ee = U.getComponent();
1177
- if (ee) {
1178
- const q = ee.p;
1179
- q != null ? (R && (T[q] = R), Pe[q] = R || D === 1 && X ? null : A.getComponent(), C[q] = U.clone(), M && (I[q] = M.clone())) : ee.r !== void 0 && (R || A.write("r", !0), (R || X) && (Me == null && (Me = /* @__PURE__ */ new Set()), Me.add(ee)));
1180
- }
1181
- let fe = 0, de = 0;
1182
- const le = s.advancer(B, void 0, (q, P) => {
1183
- O(P) && fe++;
1184
- }), ye = s.advancer(M, (q, P) => o(P) ? ~(q - de) : q - de, (q, P) => {
1185
- o(P) && de++;
1186
- });
1187
- if (U) for (const q of U) if (typeof q == "string") {
1188
- const P = le(q), x = ye(q);
1189
- A.descend(q), Q(U, P, x, A, R), A.ascend();
1190
- } else {
1191
- const P = le(q), x = q - fe, he = O(a(P)) ? null : ye(x), be = x + de;
1192
- l(be >= 0), A.descend(be), Q(U, P, he, A, R), A.ascend();
1193
- }
1194
- le.end(), ye.end();
1195
- })(me, _e, _e.clone(), oe, null), oe.reset();
1196
- let Le = [];
1197
- if (function Q(U, B, M, A, R, X) {
1198
- l(B);
1199
- const Y = B.getComponent();
1200
- let ee = a(A), fe = !1;
1201
- const de = (S, ie, Oe) => S ? n.moveOp(S.getPath(), ie.getPath()) : n.insertOp(ie.getPath(), Oe.i);
1202
- if (o(Y)) {
1203
- const S = Y.d;
1204
- S != null && ($[S] = B.clone());
1205
- const ie = S != null ? Pe[S] : null;
1206
- let Oe = !1;
1207
- if (Y.i !== void 0 || S != null && ie) {
1208
- let ce;
1209
- ee && (ee.i !== void 0 || (ce = ee.d) != null && !g[ce]) && (Oe = ce != null ? S != null && S === K[ce] : t.default(ee.i, Y.i), Oe || ce != null && D !== 1 && K[ce] != null || m == null && (m = {
1210
- type: d.ConflictType.DROP_COLLISION,
1211
- op1: de(S != null ? C[S] : null, B, Y),
1212
- op2: de(ce != null ? j[ce] : null, A, ee)
1213
- })), Oe || (X ? m == null && (m = {
1214
- type: d.ConflictType.RM_UNEXPECTED_CONTENT,
1215
- op1: de(S != null ? C[S] : null, B, Y),
1216
- op2: n.removeOp(X.getPath())
1217
- }) : (S != null ? (Le[Te] = S, R.write("d", ie.p = Te++)) : R.write("i", i.default(Y.i)), fe = !0));
1218
- } else if (S != null && !ie) {
1219
- const ce = T[S];
1220
- ce && (X = ce.clone());
1124
+ function st(i, d, m) {
1125
+ o(m === "left" || m === "right", "Direction must be left or right");
1126
+ const D = m === "left" ? 0 : 1;
1127
+ if (d == null) return {
1128
+ ok: !0,
1129
+ result: i
1130
+ };
1131
+ z(i), z(d);
1132
+ let O = null;
1133
+ const I = [], R = [], $ = [], p = [], v = [], w = [], C = [], N = [], B = [], g = [], U = [], re = [], te = [], K = [], se = [];
1134
+ let Ne = 0;
1135
+ const Oe = r.readCursor(i), ye = r.readCursor(d), oe = r.writeCursor();
1136
+ if (function Q(A, W = null, M) {
1137
+ const P = l(W);
1138
+ P && (P.r !== void 0 ? M = W.clone() : P.p != null && (M = null, w[P.p] = A.clone()));
1139
+ const k = A.getComponent();
1140
+ let X;
1141
+ k && (X = k.p) != null && (v[X] = W ? W.clone() : null, $[X] = A.clone(), M && (g[X] = !0, B[X] = M), P && P.p != null && (K[X] = P.p));
1142
+ const J = r.advancer(W);
1143
+ for (const ee of A) Q(A, J(ee), M);
1144
+ J.end();
1145
+ }(ye, Oe, null), function Q(A, W, M, P, k) {
1146
+ const X = M.getComponent();
1147
+ let J, ee = !1;
1148
+ X && ((J = X.d) != null ? (p[J] = M.clone(), P != null && (se[P] == null && (se[P] = []), se[P].push(J)), A = v[J] || null, W = $[J] || null, g[J] ? (k && (U[J] = !0), k = B[J] || null) : !k || D !== 1 && K[J] != null || O == null && (O = {
1149
+ type: u.ConflictType.RM_UNEXPECTED_CONTENT,
1150
+ op1: a.removeOp(k.getPath()),
1151
+ op2: a.moveOp(W.getPath(), M.getPath())
1152
+ }), ee = !0) : X.i !== void 0 && (A = W = null, ee = !0, k && O == null && (O = {
1153
+ type: u.ConflictType.RM_UNEXPECTED_CONTENT,
1154
+ op1: a.removeOp(k.getPath()),
1155
+ op2: a.insertOp(M.getPath(), X.i)
1156
+ })));
1157
+ const fe = l(A);
1158
+ fe && (fe.r !== void 0 ? k = A.clone() : fe.p != null && (fe.p, P = fe.p, k = null));
1159
+ const de = ve(X);
1160
+ de && k && O == null && (O = {
1161
+ type: u.ConflictType.RM_UNEXPECTED_CONTENT,
1162
+ op1: a.removeOp(k.getPath()),
1163
+ op2: a.editOp(M.getPath(), de, f(X), !0)
1164
+ });
1165
+ let ae = 0, me = 0;
1166
+ const H = r.advancer(W, (G, he) => _(he) ? ae - G - 1 : G - ae, (G, he) => {
1167
+ _(he) && ae++;
1168
+ }), T = r.advancer(A);
1169
+ for (const G of M) if (typeof G == "number") {
1170
+ const he = G - me, we = H(he);
1171
+ me += +Q(T(he + ae), we, M, P, k);
1172
+ } else {
1173
+ const he = H(G);
1174
+ Q(T(G), he, M, P, k);
1175
+ }
1176
+ return H.end(), T.end(), ee;
1177
+ }(Oe, ye, ye.clone(), null, null), p.map((Q) => Q && Q.get()), O) return {
1178
+ ok: !1,
1179
+ conflict: O
1180
+ };
1181
+ U.map((Q) => !!Q);
1182
+ const Pe = [];
1183
+ let Ae = null;
1184
+ (function Q(A, W, M, P, k) {
1185
+ let X = !1;
1186
+ const J = l(W);
1187
+ if (_(J)) {
1188
+ const H = J.p;
1189
+ H != null ? (M = p[H], P = re[H] = r.writeCursor(), X = !0, k = null) : (M = null, k = W.clone());
1190
+ } else s(l(M)) && (M = null);
1191
+ const ee = A.getComponent();
1192
+ if (ee) {
1193
+ const H = ee.p;
1194
+ H != null ? (k && (N[H] = k), Pe[H] = k || D === 1 && X ? null : P.getComponent(), I[H] = A.clone(), M && (C[H] = M.clone())) : ee.r !== void 0 && (k || P.write("r", !0), (k || X) && (Ae == null && (Ae = /* @__PURE__ */ new Set()), Ae.add(ee)));
1221
1195
  }
1222
- S != null ? (U = C[S], M = b[S], A = I[S]) : Y.i !== void 0 && (U = M = null, Oe || (A = null));
1223
- } else O(a(U)) && (U = M = A = null);
1224
- const le = a(U), ye = a(M);
1225
- if (O(ye)) {
1226
- const S = ye.p;
1227
- ye.r !== void 0 && (!le || le.r === void 0) || g[S] ? (A = null, X = M.clone()) : S != null && (A = p[S], D !== 1 && K[S] != null || ((R = te[S]) || (R = te[S] = s.writeCursor()), R.reset(), X = null));
1228
- } else !o(Y) && o(ee) && (A = null);
1229
- ee = A != null ? A.getComponent() : null;
1230
- const q = ve(Y);
1231
- if (q) {
1232
- const S = f(Y);
1233
- if (X) m == null && (m = {
1234
- type: d.ConflictType.RM_UNEXPECTED_CONTENT,
1235
- op1: n.editOp(B.getPath(), q, S, !0),
1236
- op2: n.removeOp(X.getPath())
1196
+ let fe = 0, de = 0;
1197
+ const ae = r.advancer(W, void 0, (H, T) => {
1198
+ _(T) && fe++;
1199
+ }), me = r.advancer(M, (H, T) => s(T) ? ~(H - de) : H - de, (H, T) => {
1200
+ s(T) && de++;
1237
1201
  });
1238
- else {
1239
- const ie = ve(ee);
1240
- let Oe;
1241
- if (ie) {
1242
- if (q !== ie) throw Error("Transforming incompatible types");
1243
- const ce = f(ee);
1244
- Oe = q.transform(S, ce, y);
1245
- } else Oe = i.default(S);
1246
- _(R, q, Oe);
1202
+ if (A) for (const H of A) if (typeof H == "string") {
1203
+ const T = ae(H), G = me(H);
1204
+ P.descend(H), Q(A, T, G, P, k), P.ascend();
1205
+ } else {
1206
+ const T = ae(H), G = H - fe, he = _(l(T)) ? null : me(G), we = G + de;
1207
+ o(we >= 0), P.descend(we), Q(A, T, he, P, k), P.ascend();
1247
1208
  }
1248
- }
1249
- let P = 0, x = 0, he = 0, be = 0, We = 0, He = 0, Ne = U != null && U.descendFirst(), Ye = Ne;
1250
- const ze = s.advancer(M, void 0, (S, ie) => {
1251
- O(ie) && he++;
1252
- });
1253
- let Se = A != null && A.descendFirst(), je = Se;
1254
- for (const S of B) if (typeof S == "number") {
1255
- let ie;
1256
- const Oe = o(B.getComponent()), ce = S - x;
1257
- {
1258
- let Be;
1259
- for (; Ne && typeof (Be = U.getKey()) == "number"; ) {
1260
- Be += P;
1261
- const ke = U.getComponent(), Xe = O(ke);
1262
- if (Be > ce || Be === ce && (!Xe || D === 0 && Oe)) break;
1263
- if (Xe) {
1264
- P--;
1265
- const Ke = ke.p;
1266
- K.includes(Ke), ke.d, a(te[ke.d]), O(a(te[ke.d])), (ke.r === void 0 || Me && Me.has(ke)) && (Ke == null || !Pe[Ke] || D !== 1 && K.includes(Ke)) || We--;
1267
- }
1268
- Ne = U.nextSibling();
1209
+ ae.end(), me.end();
1210
+ })(Oe, ye, ye.clone(), oe, null), oe.reset();
1211
+ let Le = [];
1212
+ if (function Q(A, W, M, P, k, X) {
1213
+ o(W);
1214
+ const J = W.getComponent();
1215
+ let ee = l(P), fe = !1;
1216
+ const de = (j, ie, _e) => j ? a.moveOp(j.getPath(), ie.getPath()) : a.insertOp(ie.getPath(), _e.i);
1217
+ if (s(J)) {
1218
+ const j = J.d;
1219
+ j != null && (R[j] = W.clone());
1220
+ const ie = j != null ? Pe[j] : null;
1221
+ let _e = !1;
1222
+ if (J.i !== void 0 || j != null && ie) {
1223
+ let ue;
1224
+ ee && (ee.i !== void 0 || (ue = ee.d) != null && !g[ue]) && (_e = ue != null ? j != null && j === K[ue] : n.default(ee.i, J.i), _e || ue != null && D !== 1 && K[ue] != null || O == null && (O = {
1225
+ type: u.ConflictType.DROP_COLLISION,
1226
+ op1: de(j != null ? I[j] : null, W, J),
1227
+ op2: de(ue != null ? $[ue] : null, P, ee)
1228
+ })), _e || (X ? O == null && (O = {
1229
+ type: u.ConflictType.RM_UNEXPECTED_CONTENT,
1230
+ op1: de(j != null ? I[j] : null, W, J),
1231
+ op2: a.removeOp(X.getPath())
1232
+ }) : (j != null ? (Le[Ne] = j, k.write("d", ie.p = Ne++)) : k.write("i", t.default(J.i)), fe = !0));
1233
+ } else if (j != null && !ie) {
1234
+ const ue = N[j];
1235
+ ue && (X = ue.clone());
1236
+ }
1237
+ j != null ? (A = I[j], M = w[j], P = C[j]) : J.i !== void 0 && (A = M = null, _e || (P = null));
1238
+ } else _(l(A)) && (A = M = P = null);
1239
+ const ae = l(A), me = l(M);
1240
+ if (_(me)) {
1241
+ const j = me.p;
1242
+ me.r !== void 0 && (!ae || ae.r === void 0) || g[j] ? (P = null, X = M.clone()) : j != null && (P = p[j], D !== 1 && K[j] != null || ((k = te[j]) || (k = te[j] = r.writeCursor()), k.reset(), X = null));
1243
+ } else !s(J) && s(ee) && (P = null);
1244
+ ee = P != null ? P.getComponent() : null;
1245
+ const H = ve(J);
1246
+ if (H) {
1247
+ const j = f(J);
1248
+ if (X) O == null && (O = {
1249
+ type: u.ConflictType.RM_UNEXPECTED_CONTENT,
1250
+ op1: a.editOp(W.getPath(), H, j, !0),
1251
+ op2: a.removeOp(X.getPath())
1252
+ });
1253
+ else {
1254
+ const ie = ve(ee);
1255
+ let _e;
1256
+ if (ie) {
1257
+ if (H !== ie) throw Error("Transforming incompatible types");
1258
+ const ue = f(ee);
1259
+ _e = H.transform(j, ue, m);
1260
+ } else _e = t.default(j);
1261
+ y(k, H, _e);
1269
1262
  }
1270
- ie = Ne && Be === ce ? U : null;
1271
1263
  }
1272
- const Re = ce - P;
1273
- let Ge = ze(Re);
1274
- const rt = Re - he;
1275
- let Je = null;
1276
- {
1277
- let Be, ke;
1278
- for (; Se && typeof (Be = A.getKey()) == "number"; ) {
1279
- ke = Be - be;
1280
- const Xe = A.getComponent(), Ke = o(Xe);
1281
- if (ke > rt) break;
1282
- if (ke === rt) {
1283
- if (!Ke) {
1284
- Je = A;
1285
- break;
1264
+ let T = 0, G = 0, he = 0, we = 0, xe = 0, qe = 0, Me = A != null && A.descendFirst(), Ye = Me;
1265
+ const Xe = r.advancer(M, void 0, (j, ie) => {
1266
+ _(ie) && he++;
1267
+ });
1268
+ let je = P != null && P.descendFirst(), $e = je;
1269
+ for (const j of W) if (typeof j == "number") {
1270
+ let ie;
1271
+ const _e = s(W.getComponent()), ue = j - G;
1272
+ {
1273
+ let We;
1274
+ for (; Me && typeof (We = A.getKey()) == "number"; ) {
1275
+ We += T;
1276
+ const ke = A.getComponent(), Je = _(ke);
1277
+ if (We > ue || We === ue && (!Je || D === 0 && _e)) break;
1278
+ if (Je) {
1279
+ T--;
1280
+ const Ke = ke.p;
1281
+ K.includes(Ke), ke.d, l(te[ke.d]), _(l(te[ke.d])), (ke.r === void 0 || Ae && Ae.has(ke)) && (Ke == null || !Pe[Ke] || D !== 1 && K.includes(Ke)) || xe--;
1286
1282
  }
1287
- {
1288
- if (D === 0 && Oe) {
1289
- Je = A;
1283
+ Me = A.nextSibling();
1284
+ }
1285
+ ie = Me && We === ue ? A : null;
1286
+ }
1287
+ const Ue = ue - T;
1288
+ let Be = Xe(Ue);
1289
+ const ot = Ue - he;
1290
+ let Qe = null;
1291
+ {
1292
+ let We, ke;
1293
+ for (; je && typeof (We = P.getKey()) == "number"; ) {
1294
+ ke = We - we;
1295
+ const Je = P.getComponent(), Ke = s(Je);
1296
+ if (ke > ot) break;
1297
+ if (ke === ot) {
1298
+ if (!Ke) {
1299
+ Qe = P;
1290
1300
  break;
1291
1301
  }
1292
- const Ve = Ge && O(Ge.getComponent());
1293
- if (D === 0 && Ve) break;
1302
+ {
1303
+ if (D === 0 && _e) {
1304
+ Qe = P;
1305
+ break;
1306
+ }
1307
+ const Fe = Be && _(Be.getComponent());
1308
+ if (D === 0 && Fe) break;
1309
+ }
1294
1310
  }
1311
+ if (Ke) {
1312
+ const Fe = Je.d;
1313
+ K[Fe], Je.i === void 0 && (g[Fe] || K[Fe] != null && D !== 1) ? (g[Fe] || K[Fe] != null && D === 0) && (we++, qe--) : we++;
1314
+ }
1315
+ je = P.nextSibling();
1295
1316
  }
1296
- if (Ke) {
1297
- const Ve = Xe.d;
1298
- K[Ve], Xe.i === void 0 && (g[Ve] || K[Ve] != null && D !== 1) ? (g[Ve] || K[Ve] != null && D === 0) && (be++, He--) : be++;
1299
- }
1300
- Se = A.nextSibling();
1301
- }
1302
- }
1303
- const Ot = rt + be + We + He;
1304
- l(Ot >= 0, "trying to descend to a negative index"), R.descend(Ot), Oe && (ie = Ge = Je = null, x++), Q(ie, B, Ge, Je, R, X) && He++, R.ascend();
1305
- } else {
1306
- let ie;
1307
- for (; Ne && (ie = U.getKey(), typeof ie != "string" || !(ie > S || ie === S)); ) Ne = U.nextSibling();
1308
- const Oe = Ne && ie === S ? U : null, ce = ze(S);
1309
- let Re;
1310
- for (; Se && (Re = A.getKey(), typeof Re != "string" || !(Re > S || Re === S)); ) Se = A.nextSibling();
1311
- const Ge = Se && Re === S ? A : null;
1312
- R.descend(S), Q(Oe, B, ce, Ge, R, X), R.ascend();
1313
- }
1314
- return ze.end(), Ye && U.ascend(), je && A.ascend(), fe;
1315
- }(me, me.clone(), _e, _e.clone(), oe, null), m) return {
1316
- ok: !1,
1317
- conflict: m
1318
- };
1319
- oe.reset();
1320
- const Ue = (Q, U, B) => Q.traverse(U, (M, A) => {
1321
- M.d != null && B(M.d, Q, A);
1322
- });
1323
- (g.length || re.length) && (Ue(_e, oe, (Q, U, B) => {
1324
- g[Q] && !N[Q] && B.write("r", !0), re[Q] && B.mergeTree(re[Q].get());
1325
- }), oe.reset());
1326
- const Ee = [], $e = [];
1327
- if ((te.length || g.length) && !m) {
1328
- const Q = s.readCursor(tt(oe.get()));
1329
- if (Ue(Q, null, (U, B) => {
1330
- Ee[U] = B.clone();
1331
- }), te.forEach((U) => {
1332
- U && Ue(s.readCursor(U.get()), null, (B, M) => {
1333
- Ee[B] = M.clone();
1334
- });
1335
- }), function U(B, M, A, R, X, Y) {
1336
- const ee = a(M);
1337
- if (ee && O(ee)) if (ee.p != null) {
1338
- const P = ee.p;
1339
- Ee[P].getPath(), A = Ee[P], R = $e[P] = s.writeCursor();
1340
- } else ee.r !== void 0 && (A = null);
1341
- else o(a(A)) && (A = null);
1342
- const fe = B.getComponent();
1343
- if (fe) {
1344
- let P;
1345
- if ((P = fe.d) != null) {
1346
- const x = te[P];
1347
- x && (x.get(), R.mergeTree(x.get()), A = s.readCursor(x.get()));
1348
1317
  }
1318
+ const yt = ot + we + xe + qe;
1319
+ o(yt >= 0, "trying to descend to a negative index"), k.descend(yt), _e && (ie = Be = Qe = null, G++), Q(ie, W, Be, Qe, k, X) && qe++, k.ascend();
1320
+ } else {
1321
+ let ie;
1322
+ for (; Me && (ie = A.getKey(), typeof ie != "string" || !(ie > j || ie === j)); ) Me = A.nextSibling();
1323
+ const _e = Me && ie === j ? A : null, ue = Xe(j);
1324
+ let Ue;
1325
+ for (; je && (Ue = P.getKey(), typeof Ue != "string" || !(Ue > j || Ue === j)); ) je = P.nextSibling();
1326
+ const Be = je && Ue === j ? P : null;
1327
+ k.descend(j), Q(_e, W, ue, Be, k, X), k.ascend();
1349
1328
  }
1350
- let de = 0, le = 0;
1351
- const ye = s.advancer(M, void 0, (P, x) => {
1352
- O(x) && de--;
1353
- }), q = s.advancer(A, (P, x) => o(x) ? -(P - le) - 1 : P - le, (P, x) => {
1354
- o(x) && le++;
1355
- });
1356
- for (const P of B) if (typeof P == "number") {
1357
- const x = ye(P), he = P + de, be = q(he), We = he + le;
1358
- R.descend(We), U(B, x, be, R), R.ascend();
1359
- } else R.descend(P), U(B, ye(P), q(P), R), R.ascend();
1360
- ye.end(), q.end();
1361
- }(_e, Q, Q.clone(), oe), oe.reset(), m) return {
1329
+ return Xe.end(), Ye && A.ascend(), $e && P.ascend(), fe;
1330
+ }(Oe, Oe.clone(), ye, ye.clone(), oe, null), O) return {
1362
1331
  ok: !1,
1363
- conflict: m
1332
+ conflict: O
1364
1333
  };
1365
- if (oe.get(), $e.length) {
1366
- const U = $e.map((M) => M ? M.get() : null), B = s.readCursor(tt(oe.get()));
1367
- if (Ue(B, oe, (M, A, R) => {
1368
- const X = U[M];
1369
- X && (R.mergeTree(X), U[M] = null);
1370
- }), U.find((M) => M)) {
1371
- const M = s.writeCursor(), A = s.writeCursor();
1372
- let R = 0, X = 0;
1373
- U.forEach((Y) => {
1374
- Y != null && Ue(s.readCursor(Y), null, (ee) => {
1375
- const fe = Le[ee];
1376
- M.writeMove(C[fe].getPath(), $[fe].getPath(), R++);
1377
- const de = se[fe];
1378
- de && de.forEach((le) => {
1379
- g[le] || D !== 1 && K[le] != null || A.writeMove(j[le].getPath(), p[le].getPath(), X++);
1334
+ oe.reset();
1335
+ const Te = (Q, A, W) => Q.traverse(A, (M, P) => {
1336
+ M.d != null && W(M.d, Q, P);
1337
+ });
1338
+ (g.length || re.length) && (Te(ye, oe, (Q, A, W) => {
1339
+ g[Q] && !U[Q] && W.write("r", !0), re[Q] && W.mergeTree(re[Q].get());
1340
+ }), oe.reset());
1341
+ const Ie = [], Re = [];
1342
+ if ((te.length || g.length) && !O) {
1343
+ const Q = r.readCursor(it(oe.get()));
1344
+ if (Te(Q, null, (A, W) => {
1345
+ Ie[A] = W.clone();
1346
+ }), te.forEach((A) => {
1347
+ A && Te(r.readCursor(A.get()), null, (W, M) => {
1348
+ Ie[W] = M.clone();
1349
+ });
1350
+ }), function A(W, M, P, k, X, J) {
1351
+ const ee = l(M);
1352
+ if (ee && _(ee)) if (ee.p != null) {
1353
+ const T = ee.p;
1354
+ Ie[T].getPath(), P = Ie[T], k = Re[T] = r.writeCursor();
1355
+ } else ee.r !== void 0 && (P = null);
1356
+ else s(l(P)) && (P = null);
1357
+ const fe = W.getComponent();
1358
+ if (fe) {
1359
+ let T;
1360
+ if ((T = fe.d) != null) {
1361
+ const G = te[T];
1362
+ G && (G.get(), k.mergeTree(G.get()), P = r.readCursor(G.get()));
1363
+ }
1364
+ }
1365
+ let de = 0, ae = 0;
1366
+ const me = r.advancer(M, void 0, (T, G) => {
1367
+ _(G) && de--;
1368
+ }), H = r.advancer(P, (T, G) => s(G) ? -(T - ae) - 1 : T - ae, (T, G) => {
1369
+ s(G) && ae++;
1370
+ });
1371
+ for (const T of W) if (typeof T == "number") {
1372
+ const G = me(T), he = T + de, we = H(he), xe = he + ae;
1373
+ k.descend(xe), A(W, G, we, k), k.ascend();
1374
+ } else k.descend(T), A(W, me(T), H(T), k), k.ascend();
1375
+ me.end(), H.end();
1376
+ }(ye, Q, Q.clone(), oe), oe.reset(), O) return {
1377
+ ok: !1,
1378
+ conflict: O
1379
+ };
1380
+ if (oe.get(), Re.length) {
1381
+ const A = Re.map((M) => M ? M.get() : null), W = r.readCursor(it(oe.get()));
1382
+ if (Te(W, oe, (M, P, k) => {
1383
+ const X = A[M];
1384
+ X && (k.mergeTree(X), A[M] = null);
1385
+ }), A.find((M) => M)) {
1386
+ const M = r.writeCursor(), P = r.writeCursor();
1387
+ let k = 0, X = 0;
1388
+ A.forEach((J) => {
1389
+ J != null && Te(r.readCursor(J), null, (ee) => {
1390
+ const fe = Le[ee];
1391
+ M.writeMove(I[fe].getPath(), R[fe].getPath(), k++);
1392
+ const de = se[fe];
1393
+ de && de.forEach((ae) => {
1394
+ g[ae] || D !== 1 && K[ae] != null || P.writeMove($[ae].getPath(), p[ae].getPath(), X++);
1395
+ });
1380
1396
  });
1381
- });
1382
- }), m = {
1383
- type: d.ConflictType.BLACKHOLE,
1384
- op1: M.get(),
1385
- op2: A.get()
1386
- };
1397
+ }), O = {
1398
+ type: u.ConflictType.BLACKHOLE,
1399
+ op1: M.get(),
1400
+ op2: P.get()
1401
+ };
1402
+ }
1387
1403
  }
1388
1404
  }
1405
+ return O ? {
1406
+ ok: !1,
1407
+ conflict: O
1408
+ } : {
1409
+ ok: !0,
1410
+ result: oe.get()
1411
+ };
1389
1412
  }
1390
- return m ? {
1391
- ok: !1,
1392
- conflict: m
1393
- } : {
1394
- ok: !0,
1395
- result: oe.get()
1413
+ const pt = (i) => {
1414
+ const d = new Error("Transform detected write conflict");
1415
+ throw d.conflict = i, d.type = d.name = "writeConflict", d;
1396
1416
  };
1397
- }
1398
- const gt = (r) => {
1399
- const u = new Error("Transform detected write conflict");
1400
- throw u.conflict = r, u.type = u.name = "writeConflict", u;
1401
- };
1402
- function At(r, u, y) {
1403
- const D = nt(r, u, y);
1404
- if (D.ok) return D.result;
1405
- gt(D.conflict);
1406
- }
1407
- const qe = (r) => {
1408
- const u = s.writeCursor();
1409
- return s.readCursor(r).traverse(u, (y, D) => {
1410
- (o(y) || ve(y)) && D.write("r", !0);
1411
- }), u.get();
1412
- }, Pt = (r, u) => {
1413
- const { type: y, op1: D, op2: m } = r;
1414
- switch (y) {
1415
- case d.ConflictType.DROP_COLLISION:
1416
- return u === "left" ? [null, qe(m)] : [qe(D), null];
1417
- case d.ConflictType.RM_UNEXPECTED_CONTENT:
1418
- let C = !1;
1419
- return s.readCursor(D).traverse(null, ($) => {
1420
- $.r !== void 0 && (C = !0);
1421
- }), C ? [null, qe(m)] : [qe(D), null];
1422
- case d.ConflictType.BLACKHOLE:
1423
- return [qe(D), qe(m)];
1424
- default:
1425
- throw Error("Unrecognised conflict: " + y);
1417
+ function kt(i, d, m) {
1418
+ const D = st(i, d, m);
1419
+ if (D.ok) return D.result;
1420
+ pt(D.conflict);
1426
1421
  }
1427
- };
1428
- function _t(r, u, y, D) {
1429
- let m = null;
1430
- for (; ; ) {
1431
- const C = nt(u, y, D);
1432
- if (C.ok) return ne(m, C.result);
1433
- {
1434
- const { conflict: $ } = C;
1435
- r($) || gt($);
1436
- const [j, p] = Pt($, D);
1437
- u = ne(H(u), j), y = ne(H(y), p), m = ne(m, p);
1422
+ const ze = (i) => {
1423
+ const d = r.writeCursor();
1424
+ return r.readCursor(i).traverse(d, (m, D) => {
1425
+ (s(m) || ve(m)) && D.write("r", !0);
1426
+ }), d.get();
1427
+ }, St = (i, d) => {
1428
+ const { type: m, op1: D, op2: O } = i;
1429
+ switch (m) {
1430
+ case u.ConflictType.DROP_COLLISION:
1431
+ return d === "left" ? [null, ze(O)] : [ze(D), null];
1432
+ case u.ConflictType.RM_UNEXPECTED_CONTENT:
1433
+ let I = !1;
1434
+ return r.readCursor(D).traverse(null, (R) => {
1435
+ R.r !== void 0 && (I = !0);
1436
+ }), I ? [null, ze(O)] : [ze(D), null];
1437
+ case u.ConflictType.BLACKHOLE:
1438
+ return [ze(D), ze(O)];
1439
+ default:
1440
+ throw Error("Unrecognised conflict: " + m);
1441
+ }
1442
+ };
1443
+ function gt(i, d, m, D) {
1444
+ let O = null;
1445
+ for (; ; ) {
1446
+ const I = st(d, m, D);
1447
+ if (I.ok) return ne(O, I.result);
1448
+ {
1449
+ const { conflict: R } = I;
1450
+ i(R) || pt(R);
1451
+ const [$, p] = St(R, D);
1452
+ d = ne(q(d), $), m = ne(q(m), p), O = ne(O, p);
1453
+ }
1438
1454
  }
1439
1455
  }
1440
- }
1441
- })(Et);
1442
- (function(n) {
1443
- var e = Ce && Ce.__createBinding || (Object.create ? function(d, l, a, E) {
1444
- E === void 0 && (E = a), Object.defineProperty(d, E, { enumerable: !0, get: function() {
1445
- return l[a];
1456
+ }(Ze)), Ze;
1457
+ }
1458
+ var Dt;
1459
+ function Qt() {
1460
+ return Dt || (Dt = 1, function(a) {
1461
+ var e = Ve && Ve.__createBinding || (Object.create ? function(u, o, l, E) {
1462
+ E === void 0 && (E = l), Object.defineProperty(u, E, { enumerable: !0, get: function() {
1463
+ return o[l];
1464
+ } });
1465
+ } : function(u, o, l, E) {
1466
+ E === void 0 && (E = l), u[E] = o[l];
1467
+ }), n = Ve && Ve.__exportStar || function(u, o) {
1468
+ for (var l in u) l !== "default" && !o.hasOwnProperty(l) && e(o, u, l);
1469
+ };
1470
+ Object.defineProperty(a, "__esModule", { value: !0 }), n(Zt(), a);
1471
+ var t = At();
1472
+ Object.defineProperty(a, "ReadCursor", { enumerable: !0, get: function() {
1473
+ return t.ReadCursor;
1474
+ } }), Object.defineProperty(a, "WriteCursor", { enumerable: !0, get: function() {
1475
+ return t.WriteCursor;
1446
1476
  } });
1447
- } : function(d, l, a, E) {
1448
- E === void 0 && (E = a), d[E] = l[a];
1449
- }), t = Ce && Ce.__exportStar || function(d, l) {
1450
- for (var a in d) a !== "default" && !l.hasOwnProperty(a) && e(l, d, a);
1451
- };
1452
- Object.defineProperty(n, "__esModule", { value: !0 }), t(Et, n);
1453
- var i = ft;
1454
- Object.defineProperty(n, "ReadCursor", { enumerable: !0, get: function() {
1455
- return i.ReadCursor;
1456
- } }), Object.defineProperty(n, "WriteCursor", { enumerable: !0, get: function() {
1457
- return i.WriteCursor;
1458
- } });
1459
- var s = ht;
1460
- Object.defineProperty(n, "ConflictType", { enumerable: !0, get: function() {
1461
- return s.ConflictType;
1462
- } });
1463
- })(F);
1464
- class Vt {
1477
+ var r = Mt();
1478
+ Object.defineProperty(a, "ConflictType", { enumerable: !0, get: function() {
1479
+ return r.ConflictType;
1480
+ } });
1481
+ }(Ve)), Ve;
1482
+ }
1483
+ var V = Qt();
1484
+ class en {
1465
1485
  constructor() {
1466
- V(this, "drawingManagerData", {});
1467
- V(this, "_oldDrawingManagerData", {});
1468
- V(this, "_focusDrawings", []);
1469
- V(this, "_remove$", new we());
1470
- V(this, "remove$", this._remove$.asObservable());
1471
- V(this, "_add$", new we());
1472
- V(this, "add$", this._add$.asObservable());
1473
- V(this, "_update$", new we());
1474
- V(this, "update$", this._update$.asObservable());
1475
- V(this, "_order$", new we());
1476
- V(this, "order$", this._order$.asObservable());
1477
- V(this, "_group$", new we());
1478
- V(this, "group$", this._group$.asObservable());
1479
- V(this, "_ungroup$", new we());
1480
- V(this, "ungroup$", this._ungroup$.asObservable());
1481
- V(this, "_refreshTransform$", new we());
1482
- V(this, "refreshTransform$", this._refreshTransform$.asObservable());
1483
- V(this, "_visible$", new we());
1484
- V(this, "visible$", this._visible$.asObservable());
1486
+ F(this, "drawingManagerData", {});
1487
+ F(this, "_oldDrawingManagerData", {});
1488
+ F(this, "_focusDrawings", []);
1489
+ F(this, "_remove$", new be());
1490
+ F(this, "remove$", this._remove$.asObservable());
1491
+ F(this, "_add$", new be());
1492
+ F(this, "add$", this._add$.asObservable());
1493
+ F(this, "_update$", new be());
1494
+ F(this, "update$", this._update$.asObservable());
1495
+ F(this, "_order$", new be());
1496
+ F(this, "order$", this._order$.asObservable());
1497
+ F(this, "_group$", new be());
1498
+ F(this, "group$", this._group$.asObservable());
1499
+ F(this, "_ungroup$", new be());
1500
+ F(this, "ungroup$", this._ungroup$.asObservable());
1501
+ F(this, "_refreshTransform$", new be());
1502
+ F(this, "refreshTransform$", this._refreshTransform$.asObservable());
1503
+ F(this, "_visible$", new be());
1504
+ F(this, "visible$", this._visible$.asObservable());
1485
1505
  // private readonly _externalUpdate$ = new Subject<T[]>();
1486
1506
  // readonly externalUpdate$ = this._externalUpdate$.asObservable();
1487
- V(this, "_focus$", new we());
1488
- V(this, "focus$", this._focus$.asObservable());
1489
- V(this, "_featurePluginUpdate$", new we());
1490
- V(this, "featurePluginUpdate$", this._featurePluginUpdate$.asObservable());
1491
- V(this, "_featurePluginAdd$", new we());
1492
- V(this, "featurePluginAdd$", this._featurePluginAdd$.asObservable());
1493
- V(this, "_featurePluginRemove$", new we());
1494
- V(this, "featurePluginRemove$", this._featurePluginRemove$.asObservable());
1495
- V(this, "_featurePluginOrderUpdate$", new we());
1496
- V(this, "featurePluginOrderUpdate$", this._featurePluginOrderUpdate$.asObservable());
1497
- V(this, "_featurePluginGroupUpdate$", new we());
1498
- V(this, "featurePluginGroupUpdate$", this._featurePluginGroupUpdate$.asObservable());
1499
- V(this, "_featurePluginUngroupUpdate$", new we());
1500
- V(this, "featurePluginUngroupUpdate$", this._featurePluginUngroupUpdate$.asObservable());
1501
- V(this, "_visible", !0);
1502
- V(this, "_editable", !0);
1507
+ F(this, "_focus$", new be());
1508
+ F(this, "focus$", this._focus$.asObservable());
1509
+ F(this, "_featurePluginUpdate$", new be());
1510
+ F(this, "featurePluginUpdate$", this._featurePluginUpdate$.asObservable());
1511
+ F(this, "_featurePluginAdd$", new be());
1512
+ F(this, "featurePluginAdd$", this._featurePluginAdd$.asObservable());
1513
+ F(this, "_featurePluginRemove$", new be());
1514
+ F(this, "featurePluginRemove$", this._featurePluginRemove$.asObservable());
1515
+ F(this, "_featurePluginOrderUpdate$", new be());
1516
+ F(this, "featurePluginOrderUpdate$", this._featurePluginOrderUpdate$.asObservable());
1517
+ F(this, "_featurePluginGroupUpdate$", new be());
1518
+ F(this, "featurePluginGroupUpdate$", this._featurePluginGroupUpdate$.asObservable());
1519
+ F(this, "_featurePluginUngroupUpdate$", new be());
1520
+ F(this, "featurePluginUngroupUpdate$", this._featurePluginUngroupUpdate$.asObservable());
1521
+ F(this, "_visible", !0);
1522
+ F(this, "_editable", !0);
1503
1523
  }
1504
1524
  dispose() {
1505
1525
  this._remove$.complete(), this._add$.complete(), this._update$.complete(), this._order$.complete(), this._focus$.complete(), this._featurePluginUpdate$.complete(), this._featurePluginAdd$.complete(), this._featurePluginRemove$.complete(), this._featurePluginOrderUpdate$.complete(), this.drawingManagerData = {}, this._oldDrawingManagerData = {};
@@ -1508,74 +1528,74 @@ class Vt {
1508
1528
  this._visible$.next(e);
1509
1529
  }
1510
1530
  refreshTransform(e) {
1511
- e.forEach((t) => {
1512
- const i = this._getCurrentBySearch(t);
1513
- i != null && (i.transform = t.transform, i.transforms = t.transforms, i.isMultiTransform = t.isMultiTransform);
1531
+ e.forEach((n) => {
1532
+ const t = this._getCurrentBySearch(n);
1533
+ t != null && (t.transform = n.transform, t.transforms = n.transforms, t.isMultiTransform = n.isMultiTransform);
1514
1534
  }), this.refreshTransformNotification(e);
1515
1535
  }
1516
1536
  getDrawingDataForUnit(e) {
1517
1537
  return this.drawingManagerData[e] || {};
1518
1538
  }
1519
1539
  removeDrawingDataForUnit(e) {
1520
- const t = this.drawingManagerData[e];
1521
- if (t == null)
1540
+ const n = this.drawingManagerData[e];
1541
+ if (n == null)
1522
1542
  return;
1523
1543
  delete this.drawingManagerData[e];
1524
- const i = [];
1525
- Object.keys(t).forEach((s) => {
1526
- const d = t[s];
1527
- (d == null ? void 0 : d.data) != null && Object.keys(d.data).forEach((l) => {
1528
- i.push({ unitId: e, subUnitId: s, drawingId: l });
1544
+ const t = [];
1545
+ Object.keys(n).forEach((r) => {
1546
+ const u = n[r];
1547
+ (u == null ? void 0 : u.data) != null && Object.keys(u.data).forEach((o) => {
1548
+ t.push({ unitId: e, subUnitId: r, drawingId: o });
1529
1549
  });
1530
- }), i.length > 0 && this.removeNotification(i);
1550
+ }), t.length > 0 && this.removeNotification(t);
1531
1551
  }
1532
- registerDrawingData(e, t) {
1533
- this.drawingManagerData[e] = t;
1552
+ registerDrawingData(e, n) {
1553
+ this.drawingManagerData[e] = n;
1534
1554
  }
1535
1555
  initializeNotification(e) {
1536
- const t = [], i = this.drawingManagerData[e];
1537
- i != null && (Object.keys(i).forEach((s) => {
1538
- this._establishDrawingMap(e, s);
1539
- const d = i[s];
1540
- Object.keys(d.data).forEach((l) => {
1541
- const a = d.data[l];
1542
- a.unitId = e, a.subUnitId = s, t.push(a);
1556
+ const n = [], t = this.drawingManagerData[e];
1557
+ t != null && (Object.keys(t).forEach((r) => {
1558
+ this._establishDrawingMap(e, r);
1559
+ const u = t[r];
1560
+ Object.keys(u.data).forEach((o) => {
1561
+ const l = u.data[o];
1562
+ l.unitId = e, l.subUnitId = r, n.push(l);
1543
1563
  });
1544
- }), t.length > 0 && this.addNotification(t));
1564
+ }), n.length > 0 && this.addNotification(n));
1545
1565
  }
1546
- getDrawingData(e, t) {
1547
- return this._getDrawingData(e, t);
1566
+ getDrawingData(e, n) {
1567
+ return this._getDrawingData(e, n);
1548
1568
  }
1549
1569
  // Use in doc only.
1550
- setDrawingData(e, t, i) {
1551
- this.drawingManagerData[e][t].data = i;
1570
+ setDrawingData(e, n, t) {
1571
+ this.drawingManagerData[e][n].data = t;
1552
1572
  }
1553
1573
  getBatchAddOp(e) {
1554
- const t = [], i = [], s = [];
1555
- e.forEach((W) => {
1556
- const { op: O, invertOp: o } = this._addByParam(W);
1557
- t.push({ unitId: W.unitId, subUnitId: W.subUnitId, drawingId: W.drawingId }), i.push(O), s.push(o);
1574
+ const n = [], t = [], r = [];
1575
+ e.forEach((x) => {
1576
+ const { op: _, invertOp: s } = this._addByParam(x);
1577
+ n.push({ unitId: x.unitId, subUnitId: x.subUnitId, drawingId: x.drawingId }), t.push(_), r.push(s);
1558
1578
  });
1559
- const d = i.reduce(F.type.compose, null), l = s.reduce(F.type.compose, null), { unitId: a, subUnitId: E } = e[0];
1560
- return { undo: l, redo: d, unitId: a, subUnitId: E, objects: t };
1579
+ const u = t.reduce(V.type.compose, null), o = r.reduce(V.type.compose, null), { unitId: l, subUnitId: E } = e[0];
1580
+ return { undo: o, redo: u, unitId: l, subUnitId: E, objects: n };
1561
1581
  }
1562
1582
  getBatchRemoveOp(e) {
1563
- const t = [], i = [];
1583
+ const n = [], t = [];
1564
1584
  e.forEach((E) => {
1565
- const { op: W, invertOp: O } = this._removeByParam(E);
1566
- t.unshift(W), i.push(O);
1585
+ const { op: x, invertOp: _ } = this._removeByParam(E);
1586
+ n.unshift(x), t.push(_);
1567
1587
  });
1568
- const s = t.reduce(F.type.compose, null), d = i.reduce(F.type.compose, null), { unitId: l, subUnitId: a } = e[0];
1569
- return { undo: d, redo: s, unitId: l, subUnitId: a, objects: e };
1588
+ const r = n.reduce(V.type.compose, null), u = t.reduce(V.type.compose, null), { unitId: o, subUnitId: l } = e[0];
1589
+ return { undo: u, redo: r, unitId: o, subUnitId: l, objects: e };
1570
1590
  }
1571
1591
  getBatchUpdateOp(e) {
1572
- const t = [], i = [], s = [];
1573
- e.forEach((W) => {
1574
- const { op: O, invertOp: o } = this._updateByParam(W);
1575
- t.push({ unitId: W.unitId, subUnitId: W.subUnitId, drawingId: W.drawingId }), i.push(O), s.push(o);
1592
+ const n = [], t = [], r = [];
1593
+ e.forEach((x) => {
1594
+ const { op: _, invertOp: s } = this._updateByParam(x);
1595
+ n.push({ unitId: x.unitId, subUnitId: x.subUnitId, drawingId: x.drawingId }), t.push(_), r.push(s);
1576
1596
  });
1577
- const d = i.reduce(F.type.compose, null), l = s.reduce(F.type.compose, null), { unitId: a, subUnitId: E } = e[0];
1578
- return { undo: l, redo: d, unitId: a, subUnitId: E, objects: t };
1597
+ const u = t.reduce(V.type.compose, null), o = r.reduce(V.type.compose, null), { unitId: l, subUnitId: E } = e[0];
1598
+ return { undo: o, redo: u, unitId: l, subUnitId: E, objects: n };
1579
1599
  }
1580
1600
  removeNotification(e) {
1581
1601
  this._remove$.next(e);
@@ -1599,61 +1619,61 @@ class Vt {
1599
1619
  this._refreshTransform$.next(e);
1600
1620
  }
1601
1621
  getGroupDrawingOp(e) {
1602
- const t = [], { unitId: i, subUnitId: s } = e[0].parent;
1603
- e.forEach((a) => {
1604
- t.push(this._getGroupDrawingOp(a));
1622
+ const n = [], { unitId: t, subUnitId: r } = e[0].parent;
1623
+ e.forEach((l) => {
1624
+ n.push(this._getGroupDrawingOp(l));
1605
1625
  });
1606
- const d = t.reduce(F.type.compose, null);
1607
- return { undo: F.type.invertWithDoc(d, this.drawingManagerData), redo: d, unitId: i, subUnitId: s, objects: e };
1626
+ const u = n.reduce(V.type.compose, null);
1627
+ return { undo: V.type.invertWithDoc(u, this.drawingManagerData), redo: u, unitId: t, subUnitId: r, objects: e };
1608
1628
  }
1609
1629
  getUngroupDrawingOp(e) {
1610
- const t = [], { unitId: i, subUnitId: s } = e[0].parent;
1611
- e.forEach((a) => {
1612
- t.push(this._getUngroupDrawingOp(a));
1630
+ const n = [], { unitId: t, subUnitId: r } = e[0].parent;
1631
+ e.forEach((l) => {
1632
+ n.push(this._getUngroupDrawingOp(l));
1613
1633
  });
1614
- const d = t.reduce(F.type.compose, null);
1615
- return { undo: F.type.invertWithDoc(d, this.drawingManagerData), redo: d, unitId: i, subUnitId: s, objects: e };
1634
+ const u = n.reduce(V.type.compose, null);
1635
+ return { undo: V.type.invertWithDoc(u, this.drawingManagerData), redo: u, unitId: t, subUnitId: r, objects: e };
1616
1636
  }
1617
1637
  getDrawingsByGroup(e) {
1618
- const { unitId: t, subUnitId: i, drawingId: s } = e;
1619
- if (this.getDrawingByParam({ unitId: t, subUnitId: i, drawingId: s }) == null)
1638
+ const { unitId: n, subUnitId: t, drawingId: r } = e;
1639
+ if (this.getDrawingByParam({ unitId: n, subUnitId: t, drawingId: r }) == null)
1620
1640
  return [];
1621
- const l = this._getDrawingData(t, i), a = [];
1622
- return Object.keys(l).forEach((E) => {
1623
- const W = l[E];
1624
- W.groupId === s && a.push(W);
1625
- }), a;
1641
+ const o = this._getDrawingData(n, t), l = [];
1642
+ return Object.keys(o).forEach((E) => {
1643
+ const x = o[E];
1644
+ x.groupId === r && l.push(x);
1645
+ }), l;
1626
1646
  }
1627
1647
  _getGroupDrawingOp(e) {
1628
- const { parent: t, children: i } = e, { unitId: s, subUnitId: d, drawingId: l } = t, a = [];
1629
- a.push(
1630
- F.insertOp([s, d, "data", l], t)
1648
+ const { parent: n, children: t } = e, { unitId: r, subUnitId: u, drawingId: o } = n, l = [];
1649
+ l.push(
1650
+ V.insertOp([r, u, "data", o], n)
1631
1651
  );
1632
1652
  let E = Number.NEGATIVE_INFINITY;
1633
- return i.forEach((W) => {
1634
- const { unitId: O, subUnitId: o, drawingId: c } = W, h = this._hasDrawingOrder({ unitId: O, subUnitId: o, drawingId: c });
1635
- E = Math.max(E, h), a.push(
1636
- ...this._getUpdateParamCompareOp(W, this.getDrawingByParam({ unitId: O, subUnitId: o, drawingId: c }))
1653
+ return t.forEach((x) => {
1654
+ const { unitId: _, subUnitId: s, drawingId: c } = x, h = this._hasDrawingOrder({ unitId: _, subUnitId: s, drawingId: c });
1655
+ E = Math.max(E, h), l.push(
1656
+ ...this._getUpdateParamCompareOp(x, this.getDrawingByParam({ unitId: _, subUnitId: s, drawingId: c }))
1637
1657
  );
1638
- }), E === Number.NEGATIVE_INFINITY && (E = this._getDrawingOrder(s, d).length), a.push(
1639
- F.insertOp([s, d, "order", E], l)
1640
- ), a.reduce(F.type.compose, null);
1658
+ }), E === Number.NEGATIVE_INFINITY && (E = this._getDrawingOrder(r, u).length), l.push(
1659
+ V.insertOp([r, u, "order", E], o)
1660
+ ), l.reduce(V.type.compose, null);
1641
1661
  }
1642
1662
  _getUngroupDrawingOp(e) {
1643
- const { parent: t, children: i } = e, { unitId: s, subUnitId: d, drawingId: l } = t, a = [];
1644
- return i.forEach((E) => {
1645
- const { unitId: W, subUnitId: O, drawingId: o } = E;
1646
- a.push(
1647
- ...this._getUpdateParamCompareOp(E, this.getDrawingByParam({ unitId: W, subUnitId: O, drawingId: o }))
1663
+ const { parent: n, children: t } = e, { unitId: r, subUnitId: u, drawingId: o } = n, l = [];
1664
+ return t.forEach((E) => {
1665
+ const { unitId: x, subUnitId: _, drawingId: s } = E;
1666
+ l.push(
1667
+ ...this._getUpdateParamCompareOp(E, this.getDrawingByParam({ unitId: x, subUnitId: _, drawingId: s }))
1648
1668
  );
1649
- }), a.push(
1650
- F.removeOp([s, d, "data", l], !0)
1651
- ), a.push(
1652
- F.removeOp([s, d, "order", this._getDrawingOrder(s, d).indexOf(l)], !0)
1653
- ), a.reduce(F.type.compose, null);
1669
+ }), l.push(
1670
+ V.removeOp([r, u, "data", o], !0)
1671
+ ), l.push(
1672
+ V.removeOp([r, u, "order", this._getDrawingOrder(r, u).indexOf(o)], !0)
1673
+ ), l.reduce(V.type.compose, null);
1654
1674
  }
1655
- applyJson1(e, t, i) {
1656
- this._establishDrawingMap(e, t), this._oldDrawingManagerData = { ...this.drawingManagerData }, this.drawingManagerData = F.type.apply(this.drawingManagerData, i);
1675
+ applyJson1(e, n, t) {
1676
+ this._establishDrawingMap(e, n), this._oldDrawingManagerData = { ...this.drawingManagerData }, this.drawingManagerData = V.type.apply(this.drawingManagerData, t);
1657
1677
  }
1658
1678
  // private _fillMissingFields(jsonOp: JSONOp) {
1659
1679
  // if (jsonOp == null) {
@@ -1700,138 +1720,138 @@ class Vt {
1700
1720
  return this._getOldBySearch(e);
1701
1721
  }
1702
1722
  getDrawingOKey(e) {
1703
- const [t, i, s] = e.split("#-#");
1704
- return this._getCurrentBySearch({ unitId: t, subUnitId: i, drawingId: s });
1723
+ const [n, t, r] = e.split("#-#");
1724
+ return this._getCurrentBySearch({ unitId: n, subUnitId: t, drawingId: r });
1705
1725
  }
1706
1726
  focusDrawing(e) {
1707
1727
  if (e == null) {
1708
1728
  this._focusDrawings = [], this._focus$.next([]);
1709
1729
  return;
1710
1730
  }
1711
- const t = [];
1712
- e.forEach((i) => {
1731
+ const n = [];
1732
+ e.forEach((t) => {
1713
1733
  var E;
1714
- const { unitId: s, subUnitId: d, drawingId: l } = i, a = (E = this._getDrawingData(s, d)) == null ? void 0 : E[l];
1715
- a != null && t.push(a);
1716
- }), t.length > 0 && (this._focusDrawings = t, this._focus$.next(t));
1734
+ const { unitId: r, subUnitId: u, drawingId: o } = t, l = (E = this._getDrawingData(r, u)) == null ? void 0 : E[o];
1735
+ l != null && n.push(l);
1736
+ }), n.length > 0 && (this._focusDrawings = n, this._focus$.next(n));
1717
1737
  }
1718
1738
  getFocusDrawings() {
1719
1739
  const e = [];
1720
- return this._focusDrawings.forEach((t) => {
1721
- var a;
1722
- const { unitId: i, subUnitId: s, drawingId: d } = t, l = (a = this._getDrawingData(i, s)) == null ? void 0 : a[d];
1723
- l != null && e.push(l);
1740
+ return this._focusDrawings.forEach((n) => {
1741
+ var l;
1742
+ const { unitId: t, subUnitId: r, drawingId: u } = n, o = (l = this._getDrawingData(t, r)) == null ? void 0 : l[u];
1743
+ o != null && e.push(o);
1724
1744
  }), e;
1725
1745
  }
1726
- getDrawingOrder(e, t) {
1727
- return this._getDrawingOrder(e, t);
1746
+ getDrawingOrder(e, n) {
1747
+ return this._getDrawingOrder(e, n);
1728
1748
  }
1729
1749
  // Use in doc only.
1730
- setDrawingOrder(e, t, i) {
1731
- this.drawingManagerData[e][t].order = i;
1750
+ setDrawingOrder(e, n, t) {
1751
+ this.drawingManagerData[e][n].order = t;
1732
1752
  }
1733
1753
  orderUpdateNotification(e) {
1734
1754
  this._order$.next(e);
1735
1755
  }
1736
1756
  getForwardDrawingsOp(e) {
1737
- const { unitId: t, subUnitId: i, drawingIds: s } = e, d = [], l = this.getDrawingOrder(t, i), a = [...s];
1738
- s.forEach((O) => {
1739
- const o = this._hasDrawingOrder({ unitId: t, subUnitId: i, drawingId: O });
1740
- if (o === -1 || o === l.length - 1)
1757
+ const { unitId: n, subUnitId: t, drawingIds: r } = e, u = [], o = this.getDrawingOrder(n, t), l = [...r];
1758
+ r.forEach((_) => {
1759
+ const s = this._hasDrawingOrder({ unitId: n, subUnitId: t, drawingId: _ });
1760
+ if (s === -1 || s === o.length - 1)
1741
1761
  return;
1742
- const c = F.moveOp([t, i, "order", o], [t, i, "order", o + 1]);
1743
- d.push(c), a.includes(l[o + 1]) || a.push(l[o + 1]);
1762
+ const c = V.moveOp([n, t, "order", s], [n, t, "order", s + 1]);
1763
+ u.push(c), l.includes(o[s + 1]) || l.push(o[s + 1]);
1744
1764
  });
1745
- const E = d.reduce(F.type.compose, null);
1746
- return { undo: F.type.invertWithDoc(E, this.drawingManagerData), redo: E, unitId: t, subUnitId: i, objects: { ...e, drawingIds: a } };
1765
+ const E = u.reduce(V.type.compose, null);
1766
+ return { undo: V.type.invertWithDoc(E, this.drawingManagerData), redo: E, unitId: n, subUnitId: t, objects: { ...e, drawingIds: l } };
1747
1767
  }
1748
1768
  getBackwardDrawingOp(e) {
1749
- const { unitId: t, subUnitId: i, drawingIds: s } = e, d = [], l = this.getDrawingOrder(t, i), a = [...s];
1750
- s.forEach((O) => {
1751
- const o = this._hasDrawingOrder({ unitId: t, subUnitId: i, drawingId: O });
1752
- if (o === -1 || o === 0)
1769
+ const { unitId: n, subUnitId: t, drawingIds: r } = e, u = [], o = this.getDrawingOrder(n, t), l = [...r];
1770
+ r.forEach((_) => {
1771
+ const s = this._hasDrawingOrder({ unitId: n, subUnitId: t, drawingId: _ });
1772
+ if (s === -1 || s === 0)
1753
1773
  return;
1754
- const c = F.moveOp([t, i, "order", o], [t, i, "order", o - 1]);
1755
- d.push(c), a.includes(l[o - 1]) || a.push(l[o - 1]);
1774
+ const c = V.moveOp([n, t, "order", s], [n, t, "order", s - 1]);
1775
+ u.push(c), l.includes(o[s - 1]) || l.push(o[s - 1]);
1756
1776
  });
1757
- const E = d.reduce(F.type.compose, null);
1758
- return { undo: F.type.invertWithDoc(E, this.drawingManagerData), redo: E, unitId: t, subUnitId: i, objects: { ...e, drawingIds: a } };
1777
+ const E = u.reduce(V.type.compose, null);
1778
+ return { undo: V.type.invertWithDoc(E, this.drawingManagerData), redo: E, unitId: n, subUnitId: t, objects: { ...e, drawingIds: l } };
1759
1779
  }
1760
1780
  getFrontDrawingsOp(e) {
1761
- const { unitId: t, subUnitId: i, drawingIds: s } = e, d = this._getOrderFromSearchParams(t, i, s), l = [...s], a = this.getDrawingOrder(t, i), E = [];
1762
- d.forEach((o) => {
1763
- const { drawingId: c } = o, h = this._getDrawingCount(t, i) - 1, k = F.moveOp([t, i, "order", this._getDrawingOrder(t, i).indexOf(c)], [t, i, "order", h]);
1764
- E.push(k), l.includes(a[h]) || l.push(a[h]);
1781
+ const { unitId: n, subUnitId: t, drawingIds: r } = e, u = this._getOrderFromSearchParams(n, t, r), o = [...r], l = this.getDrawingOrder(n, t), E = [];
1782
+ u.forEach((s) => {
1783
+ const { drawingId: c } = s, h = this._getDrawingCount(n, t) - 1, S = V.moveOp([n, t, "order", this._getDrawingOrder(n, t).indexOf(c)], [n, t, "order", h]);
1784
+ E.push(S), o.includes(l[h]) || o.push(l[h]);
1765
1785
  });
1766
- const W = E.reduce(F.type.compose, null);
1767
- return { undo: F.type.invertWithDoc(W, this.drawingManagerData), redo: W, unitId: t, subUnitId: i, objects: { ...e, drawingIds: l } };
1786
+ const x = E.reduce(V.type.compose, null);
1787
+ return { undo: V.type.invertWithDoc(x, this.drawingManagerData), redo: x, unitId: n, subUnitId: t, objects: { ...e, drawingIds: o } };
1768
1788
  }
1769
1789
  getBackDrawingsOp(e) {
1770
- const { unitId: t, subUnitId: i, drawingIds: s } = e, d = this._getOrderFromSearchParams(t, i, s, !0), l = [...s], a = this.getDrawingOrder(t, i), E = [];
1771
- d.forEach((o) => {
1772
- const { drawingId: c } = o, h = F.moveOp([t, i, "order", this._getDrawingOrder(t, i).indexOf(c)], [t, i, "order", 0]);
1773
- E.push(h), l.includes(a[0]) || l.push(a[0]);
1790
+ const { unitId: n, subUnitId: t, drawingIds: r } = e, u = this._getOrderFromSearchParams(n, t, r, !0), o = [...r], l = this.getDrawingOrder(n, t), E = [];
1791
+ u.forEach((s) => {
1792
+ const { drawingId: c } = s, h = V.moveOp([n, t, "order", this._getDrawingOrder(n, t).indexOf(c)], [n, t, "order", 0]);
1793
+ E.push(h), o.includes(l[0]) || o.push(l[0]);
1774
1794
  });
1775
- const W = E.reduce(F.type.compose, null);
1776
- return { undo: F.type.invertWithDoc(W, this.drawingManagerData), redo: W, unitId: t, subUnitId: i, objects: { ...e, drawingIds: l } };
1795
+ const x = E.reduce(V.type.compose, null);
1796
+ return { undo: V.type.invertWithDoc(x, this.drawingManagerData), redo: x, unitId: n, subUnitId: t, objects: { ...e, drawingIds: o } };
1777
1797
  }
1778
- _getDrawingCount(e, t) {
1779
- return this.getDrawingOrder(e, t).length || 0;
1798
+ _getDrawingCount(e, n) {
1799
+ return this.getDrawingOrder(e, n).length || 0;
1780
1800
  }
1781
- _getOrderFromSearchParams(e, t, i, s = !1) {
1782
- return i.map((d) => {
1783
- const l = this._hasDrawingOrder({ unitId: e, subUnitId: t, drawingId: d });
1784
- return { drawingId: d, zIndex: l };
1785
- }).sort(s === !1 ? Nt : Rt);
1801
+ _getOrderFromSearchParams(e, n, t, r = !1) {
1802
+ return t.map((u) => {
1803
+ const o = this._hasDrawingOrder({ unitId: e, subUnitId: n, drawingId: u });
1804
+ return { drawingId: u, zIndex: o };
1805
+ }).sort(r === !1 ? Nt : Rt);
1786
1806
  }
1787
1807
  _hasDrawingOrder(e) {
1788
1808
  if (e == null)
1789
1809
  return -1;
1790
- const { unitId: t, subUnitId: i, drawingId: s } = e;
1791
- return this._establishDrawingMap(t, i), this._getDrawingOrder(t, i).indexOf(s);
1810
+ const { unitId: n, subUnitId: t, drawingId: r } = e;
1811
+ return this._establishDrawingMap(n, t), this._getDrawingOrder(n, t).indexOf(r);
1792
1812
  }
1793
1813
  _getCurrentBySearch(e) {
1794
- var d, l, a;
1814
+ var u, o, l;
1795
1815
  if (e == null)
1796
1816
  return;
1797
- const { unitId: t, subUnitId: i, drawingId: s } = e;
1798
- return (a = (l = (d = this.drawingManagerData[t]) == null ? void 0 : d[i]) == null ? void 0 : l.data) == null ? void 0 : a[s];
1817
+ const { unitId: n, subUnitId: t, drawingId: r } = e;
1818
+ return (l = (o = (u = this.drawingManagerData[n]) == null ? void 0 : u[t]) == null ? void 0 : o.data) == null ? void 0 : l[r];
1799
1819
  }
1800
1820
  _getOldBySearch(e) {
1801
- var d, l, a;
1821
+ var u, o, l;
1802
1822
  if (e == null)
1803
1823
  return;
1804
- const { unitId: t, subUnitId: i, drawingId: s } = e;
1805
- return (a = (l = (d = this._oldDrawingManagerData[t]) == null ? void 0 : d[i]) == null ? void 0 : l.data) == null ? void 0 : a[s];
1824
+ const { unitId: n, subUnitId: t, drawingId: r } = e;
1825
+ return (l = (o = (u = this._oldDrawingManagerData[n]) == null ? void 0 : u[t]) == null ? void 0 : o.data) == null ? void 0 : l[r];
1806
1826
  }
1807
- _establishDrawingMap(e, t, i) {
1808
- var s;
1809
- return this.drawingManagerData[e] || (this.drawingManagerData[e] = {}), this.drawingManagerData[e][t] || (this.drawingManagerData[e][t] = {
1827
+ _establishDrawingMap(e, n, t) {
1828
+ var r;
1829
+ return this.drawingManagerData[e] || (this.drawingManagerData[e] = {}), this.drawingManagerData[e][n] || (this.drawingManagerData[e][n] = {
1810
1830
  data: {},
1811
1831
  order: []
1812
- }), i == null ? null : (s = this.drawingManagerData[e][t].data) == null ? void 0 : s[i];
1832
+ }), t == null ? null : (r = this.drawingManagerData[e][n].data) == null ? void 0 : r[t];
1813
1833
  }
1814
1834
  _addByParam(e) {
1815
- const { unitId: t, subUnitId: i, drawingId: s } = e;
1816
- this._establishDrawingMap(t, i, s);
1817
- const d = F.insertOp([t, i, "data", s], e), l = F.insertOp([t, i, "order", this._getDrawingOrder(t, i).length], s), a = [d, l].reduce(F.type.compose, null), E = F.type.invertWithDoc(a, this.drawingManagerData);
1818
- return { op: a, invertOp: E };
1835
+ const { unitId: n, subUnitId: t, drawingId: r } = e;
1836
+ this._establishDrawingMap(n, t, r);
1837
+ const u = V.insertOp([n, t, "data", r], e), o = V.insertOp([n, t, "order", this._getDrawingOrder(n, t).length], r), l = [u, o].reduce(V.type.compose, null), E = V.type.invertWithDoc(l, this.drawingManagerData);
1838
+ return { op: l, invertOp: E };
1819
1839
  }
1820
1840
  _removeByParam(e) {
1821
1841
  if (e == null)
1822
1842
  return { op: [], invertOp: [] };
1823
- const { unitId: t, subUnitId: i, drawingId: s } = e;
1824
- if (this._establishDrawingMap(t, i, s) == null)
1843
+ const { unitId: n, subUnitId: t, drawingId: r } = e;
1844
+ if (this._establishDrawingMap(n, t, r) == null)
1825
1845
  return { op: [], invertOp: [] };
1826
- const l = F.removeOp([t, i, "data", s], !0), a = F.removeOp([t, i, "order", this._getDrawingOrder(t, i).indexOf(s)], !0), E = [l, a].reduce(F.type.compose, null), W = F.type.invertWithDoc(E, this.drawingManagerData);
1827
- return { op: E, invertOp: W };
1846
+ const o = V.removeOp([n, t, "data", r], !0), l = V.removeOp([n, t, "order", this._getDrawingOrder(n, t).indexOf(r)], !0), E = [o, l].reduce(V.type.compose, null), x = V.type.invertWithDoc(E, this.drawingManagerData);
1847
+ return { op: E, invertOp: x };
1828
1848
  }
1829
1849
  _updateByParam(e) {
1830
- const { unitId: t, subUnitId: i, drawingId: s } = e, d = this._establishDrawingMap(t, i, s);
1831
- if (d == null)
1850
+ const { unitId: n, subUnitId: t, drawingId: r } = e, u = this._establishDrawingMap(n, t, r);
1851
+ if (u == null)
1832
1852
  return { op: [], invertOp: [] };
1833
- const a = this._getUpdateParamCompareOp(e, d).reduce(F.type.compose, null), E = F.type.invertWithDoc(a, this.drawingManagerData);
1834
- return { op: a, invertOp: E };
1853
+ const l = this._getUpdateParamCompareOp(e, u).reduce(V.type.compose, null), E = V.type.invertWithDoc(l, this.drawingManagerData);
1854
+ return { op: l, invertOp: E };
1835
1855
  }
1836
1856
  // private _initializeDrawingData(updateParam: T, oldParam: T) {
1837
1857
  // Object.keys(updateParam).forEach((key) => {
@@ -1840,22 +1860,22 @@ class Vt {
1840
1860
  // }
1841
1861
  // });
1842
1862
  // }
1843
- _getUpdateParamCompareOp(e, t) {
1844
- const { unitId: i, subUnitId: s, drawingId: d } = e, l = [];
1845
- return Object.keys(e).forEach((a) => {
1846
- const E = e[a], W = t[a];
1847
- W !== E && l.push(
1848
- F.replaceOp([i, s, "data", d, a], W, E)
1863
+ _getUpdateParamCompareOp(e, n) {
1864
+ const { unitId: t, subUnitId: r, drawingId: u } = e, o = [];
1865
+ return Object.keys(e).forEach((l) => {
1866
+ const E = e[l], x = n[l];
1867
+ x !== E && o.push(
1868
+ V.replaceOp([t, r, "data", u, l], x, E)
1849
1869
  );
1850
- }), l;
1870
+ }), o;
1851
1871
  }
1852
- _getDrawingData(e, t) {
1853
- var i, s;
1854
- return ((s = (i = this.drawingManagerData[e]) == null ? void 0 : i[t]) == null ? void 0 : s.data) || {};
1872
+ _getDrawingData(e, n) {
1873
+ var t, r;
1874
+ return ((r = (t = this.drawingManagerData[e]) == null ? void 0 : t[n]) == null ? void 0 : r.data) || {};
1855
1875
  }
1856
- _getDrawingOrder(e, t) {
1857
- var i, s;
1858
- return ((s = (i = this.drawingManagerData[e]) == null ? void 0 : i[t]) == null ? void 0 : s.order) || [];
1876
+ _getDrawingOrder(e, n) {
1877
+ var t, r;
1878
+ return ((r = (t = this.drawingManagerData[e]) == null ? void 0 : t[n]) == null ? void 0 : r.order) || [];
1859
1879
  }
1860
1880
  getDrawingVisible() {
1861
1881
  return this._visible;
@@ -1870,73 +1890,71 @@ class Vt {
1870
1890
  this._editable = e;
1871
1891
  }
1872
1892
  }
1873
- class Ft extends Vt {
1893
+ class tn extends en {
1874
1894
  }
1875
- function dn({ unitId: n, subUnitId: e, drawingId: t }, i) {
1876
- return typeof i == "number" ? `${n}#-#${e}#-#${t}#-#${i}` : `${n}#-#${e}#-#${t}`;
1895
+ function _n({ unitId: a, subUnitId: e, drawingId: n }, t) {
1896
+ return typeof t == "number" ? `${a}#-#${e}#-#${n}#-#${t}` : `${a}#-#${e}#-#${n}`;
1877
1897
  }
1878
- const fn = async (n) => new Promise((e, t) => {
1879
- const i = new Image();
1880
- i.src = n, i.onload = () => {
1898
+ const vn = async (a) => new Promise((e, n) => {
1899
+ const t = new Image();
1900
+ t.src = a, t.onload = () => {
1881
1901
  e({
1882
- width: i.width,
1883
- height: i.height,
1884
- image: i
1902
+ width: t.width,
1903
+ height: t.height,
1904
+ image: t
1885
1905
  });
1886
- }, i.onerror = (s) => {
1887
- t(s);
1906
+ }, t.onerror = (r) => {
1907
+ n(r);
1888
1908
  };
1889
- });
1890
- var et = /* @__PURE__ */ ((n) => (n.URL = "URL", n.UUID = "UUID", n.BASE64 = "BASE64", n))(et || {}), Ze = /* @__PURE__ */ ((n) => (n.SUCCUSS = "0", n.ERROR_EXCEED_SIZE = "1", n.ERROR_IMAGE_TYPE = "2", n.ERROR_UPLOAD_COUNT_LIMIT = "3", n.ERROR_IMAGE = "4", n))(Ze || {});
1891
- const qt = Ct("core.image-io.service");
1892
- class zt {
1909
+ }), nn = "drawing.config", rn = {}, sn = xt("univer.drawing-manager.service");
1910
+ class on {
1893
1911
  constructor() {
1894
- V(this, "_waitCount", 0);
1895
- V(this, "_change$", new we());
1896
- V(this, "change$", this._change$);
1897
- V(this, "_imageSourceCache", /* @__PURE__ */ new Map());
1912
+ F(this, "_waitCount", 0);
1913
+ F(this, "_change$", new be());
1914
+ F(this, "change$", this._change$);
1915
+ F(this, "_imageSourceCache", /* @__PURE__ */ new Map());
1898
1916
  }
1899
1917
  setWaitCount(e) {
1900
1918
  this._waitCount = e, this._change$.next(e);
1901
1919
  }
1902
- getImageSourceCache(e, t) {
1903
- if (t === et.BASE64) {
1904
- const i = new Image();
1905
- return i.src = e, i;
1920
+ getImageSourceCache(e, n) {
1921
+ if (n === at.BASE64) {
1922
+ const t = new Image();
1923
+ return t.src = e, t;
1906
1924
  }
1907
1925
  return this._imageSourceCache.get(e);
1908
1926
  }
1909
- addImageSourceCache(e, t, i) {
1910
- t === et.BASE64 || i == null || this._imageSourceCache.set(e, i);
1927
+ addImageSourceCache(e, n, t) {
1928
+ n === at.BASE64 || t == null || this._imageSourceCache.set(e, t);
1911
1929
  }
1912
1930
  async getImage(e) {
1913
1931
  return Promise.resolve(e);
1914
1932
  }
1915
1933
  async saveImage(e) {
1916
- return new Promise((t, i) => {
1917
- if (!Bt.includes(e.type)) {
1918
- i(new Error(Ze.ERROR_IMAGE_TYPE)), this._decreaseWaiting();
1934
+ return new Promise((n, t) => {
1935
+ if (!Ht.includes(e.type)) {
1936
+ t(new Error(et.ERROR_IMAGE_TYPE)), this._decreaseWaiting();
1919
1937
  return;
1920
1938
  }
1921
- if (e.size > Gt) {
1922
- i(new Error(Ze.ERROR_EXCEED_SIZE)), this._decreaseWaiting();
1939
+ if (e.size > Vt) {
1940
+ t(new Error(et.ERROR_EXCEED_SIZE)), this._decreaseWaiting();
1923
1941
  return;
1924
1942
  }
1925
- const s = new FileReader();
1926
- s.readAsDataURL(e), s.onload = (d) => {
1943
+ const r = new FileReader();
1944
+ r.readAsDataURL(e), r.onload = (u) => {
1927
1945
  var E;
1928
- const l = (E = d.target) == null ? void 0 : E.result;
1929
- if (l == null) {
1930
- i(new Error(Ze.ERROR_IMAGE)), this._decreaseWaiting();
1946
+ const o = (E = u.target) == null ? void 0 : E.result;
1947
+ if (o == null) {
1948
+ t(new Error(et.ERROR_IMAGE)), this._decreaseWaiting();
1931
1949
  return;
1932
1950
  }
1933
- const a = kt.generateRandomId(6);
1934
- t({
1935
- imageId: a,
1936
- imageSourceType: et.BASE64,
1937
- source: l,
1938
- base64Cache: l,
1939
- status: Ze.SUCCUSS
1951
+ const l = Bt.generateRandomId(6);
1952
+ n({
1953
+ imageId: l,
1954
+ imageSourceType: at.BASE64,
1955
+ source: o,
1956
+ base64Cache: o,
1957
+ status: et.SUCCUSS
1940
1958
  }), this._decreaseWaiting();
1941
1959
  };
1942
1960
  });
@@ -1945,54 +1963,48 @@ class zt {
1945
1963
  this._waitCount -= 1, this._change$.next(this._waitCount);
1946
1964
  }
1947
1965
  }
1948
- const hn = "__default_document_sub_component_id20231101__";
1949
- var Xt = /* @__PURE__ */ ((n) => (n[n.forward = 0] = "forward", n[n.backward = 1] = "backward", n[n.front = 2] = "front", n[n.back = 3] = "back", n))(Xt || {}), Yt = /* @__PURE__ */ ((n) => (n[n.UNRECOGNIZED = -1] = "UNRECOGNIZED", n[n.DRAWING_IMAGE = 0] = "DRAWING_IMAGE", n[n.DRAWING_SHAPE = 1] = "DRAWING_SHAPE", n[n.DRAWING_CHART = 2] = "DRAWING_CHART", n[n.DRAWING_TABLE = 3] = "DRAWING_TABLE", n[n.DRAWING_SMART_ART = 4] = "DRAWING_SMART_ART", n[n.DRAWING_VIDEO = 5] = "DRAWING_VIDEO", n[n.DRAWING_GROUP = 6] = "DRAWING_GROUP", n[n.DRAWING_UNIT = 7] = "DRAWING_UNIT", n[n.DRAWING_DOM = 8] = "DRAWING_DOM", n))(Yt || {});
1950
- const Zt = Ct("univer.drawing-manager.service"), Jt = "drawing.config", Qt = {};
1951
- var en = Object.defineProperty, tn = Object.getOwnPropertyDescriptor, nn = (n, e, t, i) => {
1952
- for (var s = i > 1 ? void 0 : i ? tn(e, t) : e, d = n.length - 1, l; d >= 0; d--)
1953
- (l = n[d]) && (s = (i ? l(e, t, s) : l(s)) || s);
1954
- return i && s && en(e, t, s), s;
1955
- }, wt = (n, e) => (t, i) => e(t, i, n);
1956
- const rn = "UNIVER_DRAWING_PLUGIN";
1957
- var ot;
1958
- let It = (ot = class extends Tt {
1959
- constructor(n = Qt, e, t) {
1960
- super(), this._config = n, this._injector = e, this._configService = t;
1961
- const { ...i } = this._config;
1962
- this._configService.setConfig(Jt, i);
1966
+ var an = Object.defineProperty, ln = Object.getOwnPropertyDescriptor, un = (a, e, n, t) => {
1967
+ for (var r = t > 1 ? void 0 : t ? ln(e, n) : e, u = a.length - 1, o; u >= 0; u--)
1968
+ (o = a[u]) && (r = (t ? o(e, n, r) : o(r)) || r);
1969
+ return t && r && an(e, n, r), r;
1970
+ }, Pt = (a, e) => (n, t) => e(n, t, a);
1971
+ const cn = "UNIVER_DRAWING_PLUGIN";
1972
+ var dt;
1973
+ let Tt = (dt = class extends Lt {
1974
+ constructor(a = rn, e, n) {
1975
+ super(), this._config = a, this._injector = e, this._configService = n;
1976
+ const { ...t } = this._config;
1977
+ this._configService.setConfig(nn, t);
1963
1978
  }
1964
1979
  onStarting() {
1965
1980
  this._initDependencies();
1966
1981
  }
1967
1982
  _initDependencies() {
1968
- var t;
1969
- $t([
1970
- [qt, { useClass: zt }],
1971
- [Zt, { useClass: Ft }]
1972
- ], (t = this._config) == null ? void 0 : t.override).forEach((i) => this._injector.add(i));
1973
- }
1974
- }, V(ot, "pluginName", rn), ot);
1975
- It = nn([
1976
- wt(1, St(jt)),
1977
- wt(2, Wt)
1978
- ], It);
1983
+ var n;
1984
+ qt([
1985
+ [Ft, { useClass: on }],
1986
+ [sn, { useClass: tn }]
1987
+ ], (n = this._config) == null ? void 0 : n.override).forEach((t) => this._injector.add(t));
1988
+ }
1989
+ }, F(dt, "pluginName", cn), dt);
1990
+ Tt = un([
1991
+ Pt(1, Wt(Gt)),
1992
+ Pt(2, Kt)
1993
+ ], Tt);
1979
1994
  export {
1980
- Xt as ArrangeTypeEnum,
1981
- hn as DEFAULT_DOCUMENT_SUB_COMPONENT_ID,
1982
- Bt as DRAWING_IMAGE_ALLOW_IMAGE_LIST,
1983
- Gt as DRAWING_IMAGE_ALLOW_SIZE,
1984
- un as DRAWING_IMAGE_COUNT_LIMIT,
1985
- cn as DRAWING_IMAGE_HEIGHT_LIMIT,
1986
- an as DRAWING_IMAGE_WIDTH_LIMIT,
1987
- Ft as DrawingManagerService,
1988
- Yt as DrawingTypeEnum,
1989
- Zt as IDrawingManagerService,
1990
- qt as IImageIoService,
1991
- zt as ImageIoService,
1992
- et as ImageSourceType,
1993
- Ze as ImageUploadStatusType,
1994
- Vt as UnitDrawingService,
1995
- It as UniverDrawingPlugin,
1996
- dn as getDrawingShapeKeyByDrawingSearch,
1997
- fn as getImageSize
1995
+ Ht as DRAWING_IMAGE_ALLOW_IMAGE_LIST,
1996
+ Vt as DRAWING_IMAGE_ALLOW_SIZE,
1997
+ yn as DRAWING_IMAGE_COUNT_LIMIT,
1998
+ gn as DRAWING_IMAGE_HEIGHT_LIMIT,
1999
+ pn as DRAWING_IMAGE_WIDTH_LIMIT,
2000
+ tn as DrawingManagerService,
2001
+ sn as IDrawingManagerService,
2002
+ wn as IImageIoService,
2003
+ on as ImageIoService,
2004
+ bn as ImageSourceType,
2005
+ Cn as ImageUploadStatusType,
2006
+ en as UnitDrawingService,
2007
+ Tt as UniverDrawingPlugin,
2008
+ _n as getDrawingShapeKeyByDrawingSearch,
2009
+ vn as getImageSize
1998
2010
  };