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