@univerjs/drawing 0.16.1 → 0.17.0-insiders.20260318-5bef180

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