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