@wangeditor-next/yjs 0.1.32-beta.0 → 0.1.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.js +2 -1442
  2. package/dist/index.mjs +2 -1407
  3. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -1,1442 +1,2 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('yjs'), require('slate')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'yjs', 'slate'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.WangEditorYjsModule = {}, global.Y, global.slate));
5
- })(this, (function (exports, Y, slate) { 'use strict';
6
-
7
- function _interopNamespaceDefault(e) {
8
- var n = Object.create(null);
9
- if (e) {
10
- Object.keys(e).forEach(function (k) {
11
- if (k !== 'default') {
12
- var d = Object.getOwnPropertyDescriptor(e, k);
13
- Object.defineProperty(n, k, d.get ? d : {
14
- enumerable: true,
15
- get: function () { return e[k]; }
16
- });
17
- }
18
- });
19
- }
20
- n.default = e;
21
- return Object.freeze(n);
22
- }
23
-
24
- var Y__namespace = /*#__PURE__*/_interopNamespaceDefault(Y);
25
-
26
- /******************************************************************************
27
- Copyright (c) Microsoft Corporation.
28
-
29
- Permission to use, copy, modify, and/or distribute this software for any
30
- purpose with or without fee is hereby granted.
31
-
32
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
33
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
34
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
35
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
36
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
37
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
38
- PERFORMANCE OF THIS SOFTWARE.
39
- ***************************************************************************** */
40
- /* global Reflect, Promise, SuppressedError, Symbol */
41
-
42
-
43
- var __assign = function() {
44
- __assign = Object.assign || function __assign(t) {
45
- for (var s, i = 1, n = arguments.length; i < n; i++) {
46
- s = arguments[i];
47
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
48
- }
49
- return t;
50
- };
51
- return __assign.apply(this, arguments);
52
- };
53
-
54
- function __rest(s, e) {
55
- var t = {};
56
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
57
- t[p] = s[p];
58
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
59
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
60
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
61
- t[p[i]] = s[p[i]];
62
- }
63
- return t;
64
- }
65
-
66
- function __values(o) {
67
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
68
- if (m) return m.call(o);
69
- if (o && typeof o.length === "number") return {
70
- next: function () {
71
- if (o && i >= o.length) o = void 0;
72
- return { value: o && o[i++], done: !o };
73
- }
74
- };
75
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
76
- }
77
-
78
- function __read(o, n) {
79
- var m = typeof Symbol === "function" && o[Symbol.iterator];
80
- if (!m) return o;
81
- var i = m.call(o), r, ar = [], e;
82
- try {
83
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
84
- }
85
- catch (error) { e = { error: error }; }
86
- finally {
87
- try {
88
- if (r && !r.done && (m = i["return"])) m.call(i);
89
- }
90
- finally { if (e) throw e.error; }
91
- }
92
- return ar;
93
- }
94
-
95
- function __spreadArray(to, from, pack) {
96
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
97
- if (ar || !(i in from)) {
98
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
99
- ar[i] = from[i];
100
- }
101
- }
102
- return to.concat(ar || Array.prototype.slice.call(from));
103
- }
104
-
105
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
106
- var e = new Error(message);
107
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
108
- };
109
-
110
- function isObject(o) {
111
- return Object.prototype.toString.call(o) === '[object Object]';
112
- }
113
- function isPlainObject(o) {
114
- if (!isObject(o)) {
115
- return false;
116
- }
117
- // If has modified constructor
118
- var ctor = o.constructor;
119
- if (ctor === undefined) {
120
- return true;
121
- }
122
- // If has modified prototype
123
- var prot = ctor.prototype;
124
- if (isObject(prot) === false) {
125
- return false;
126
- }
127
- // If constructor does not have an Object-specific method
128
- if (Object.prototype.hasOwnProperty.call(prot, 'isPrototypeOfOf')) {
129
- return false;
130
- }
131
- // Most likely a plain Object
132
- return true;
133
- }
134
- // Slates deep equality function: https://github.com/ianstormtaylor/slate/blob/68aff89e892fe15a16314398ff052ade6068900b/packages/slate/src/utils/deep-equal.ts#L13
135
- // We have to match slates deepEquals behavior to merge insert deltas in the same way slate does.
136
- function deepEquals(node, another) {
137
- // eslint-disable-next-line guard-for-in
138
- for (var key in node) {
139
- var a = node[key];
140
- var b = another[key];
141
- if (isPlainObject(a) && isPlainObject(b)) {
142
- if (!deepEquals(a, b)) {
143
- return false;
144
- }
145
- }
146
- else if (Array.isArray(a) && Array.isArray(b)) {
147
- if (a.length !== b.length) {
148
- return false;
149
- }
150
- for (var i = 0; i < a.length; i += 1) {
151
- if (a[i] !== b[i]) {
152
- return false;
153
- }
154
- }
155
- }
156
- else if (a !== b) {
157
- return false;
158
- }
159
- }
160
- for (var key in another) {
161
- if (node[key] === undefined && another[key] !== undefined) {
162
- return false;
163
- }
164
- }
165
- return true;
166
- }
167
- function pick(obj) {
168
- var keys = [];
169
- for (var _i = 1; _i < arguments.length; _i++) {
170
- keys[_i - 1] = arguments[_i];
171
- }
172
- return Object.fromEntries(Object.entries(obj).filter(function (_a) {
173
- var _b = __read(_a, 1), key = _b[0];
174
- return keys.includes(key);
175
- }));
176
- }
177
- function omit(obj) {
178
- var keys = [];
179
- for (var _i = 1; _i < arguments.length; _i++) {
180
- keys[_i - 1] = arguments[_i];
181
- }
182
- return Object.fromEntries(Object.entries(obj).filter(function (_a) {
183
- var _b = __read(_a, 1), key = _b[0];
184
- return !keys.includes(key);
185
- }));
186
- }
187
- function omitNullEntries(obj) {
188
- return Object.fromEntries(Object.entries(obj).filter(function (_a) {
189
- var _b = __read(_a, 2), value = _b[1];
190
- return value !== null;
191
- }));
192
- }
193
-
194
- function normalizeInsertDelta(delta) {
195
- var e_1, _a;
196
- var _b, _c;
197
- var normalized = [];
198
- try {
199
- for (var delta_1 = __values(delta), delta_1_1 = delta_1.next(); !delta_1_1.done; delta_1_1 = delta_1.next()) {
200
- var element = delta_1_1.value;
201
- if (typeof element.insert === 'string' && element.insert.length === 0) {
202
- continue;
203
- }
204
- var prev = normalized[normalized.length - 1];
205
- if (!prev || typeof prev.insert !== 'string' || typeof element.insert !== 'string') {
206
- normalized.push(element);
207
- continue;
208
- }
209
- var merge = prev.attributes === element.attributes
210
- || (!prev.attributes === !element.attributes
211
- && deepEquals((_b = prev.attributes) !== null && _b !== void 0 ? _b : {}, (_c = element.attributes) !== null && _c !== void 0 ? _c : {}));
212
- if (merge) {
213
- prev.insert += element.insert;
214
- continue;
215
- }
216
- normalized.push(element);
217
- }
218
- }
219
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
220
- finally {
221
- try {
222
- if (delta_1_1 && !delta_1_1.done && (_a = delta_1.return)) _a.call(delta_1);
223
- }
224
- finally { if (e_1) throw e_1.error; }
225
- }
226
- return normalized;
227
- }
228
- function yTextToInsertDelta(yText) {
229
- return normalizeInsertDelta(yText.toDelta());
230
- }
231
- function getInsertLength(_a) {
232
- var insert = _a.insert;
233
- return typeof insert === 'string' ? insert.length : 1;
234
- }
235
- function getInsertDeltaLength(delta) {
236
- return delta.reduce(function (curr, element) { return curr + getInsertLength(element); }, 0);
237
- }
238
- function sliceInsertDelta(delta, start, length) {
239
- if (length < 1) {
240
- return [];
241
- }
242
- var currentOffset = 0;
243
- var sliced = [];
244
- var end = start + length;
245
- for (var i = 0; i < delta.length; i += 1) {
246
- if (currentOffset >= end) {
247
- break;
248
- }
249
- var element = delta[i];
250
- var elementLength = getInsertLength(element);
251
- if (currentOffset + elementLength <= start) {
252
- currentOffset += elementLength;
253
- continue;
254
- }
255
- if (typeof element.insert !== 'string') {
256
- currentOffset += elementLength;
257
- sliced.push(element);
258
- continue;
259
- }
260
- var startOffset = Math.max(0, start - currentOffset);
261
- var endOffset = Math.min(elementLength, elementLength - (currentOffset + elementLength - end));
262
- sliced.push(__assign(__assign({}, element), { insert: element.insert.slice(startOffset, endOffset) }));
263
- currentOffset += elementLength;
264
- }
265
- return sliced;
266
- }
267
-
268
- function getSlateNodeYLength(node) {
269
- if (!node) {
270
- return 0;
271
- }
272
- return slate.Text.isText(node) ? node.text.length : 1;
273
- }
274
- function slatePathOffsetToYOffset(element, pathOffset) {
275
- return element.children
276
- .slice(0, pathOffset)
277
- .reduce(function (yOffset, node) { return yOffset + getSlateNodeYLength(node); }, 0);
278
- }
279
- function getYTarget(yRoot, slateRoot, path) {
280
- var _a;
281
- if (path.length === 0) {
282
- throw new Error('Path has to a have a length >= 1');
283
- }
284
- if (slate.Text.isText(slateRoot)) {
285
- throw new Error('Cannot descent into slate text');
286
- }
287
- var _b = __read(path), pathOffset = _b[0], childPath = _b.slice(1);
288
- var yOffset = slatePathOffsetToYOffset(slateRoot, pathOffset);
289
- var targetNode = slateRoot.children[pathOffset];
290
- var delta = yTextToInsertDelta(yRoot);
291
- var targetLength = getSlateNodeYLength(targetNode);
292
- var targetDelta = sliceInsertDelta(delta, yOffset, targetLength);
293
- if (targetDelta.length > 1) {
294
- throw new Error("Path doesn't match yText, yTarget spans multiple nodes");
295
- }
296
- var yTarget = (_a = targetDelta[0]) === null || _a === void 0 ? void 0 : _a.insert;
297
- if (childPath.length > 0) {
298
- if (!(yTarget instanceof Y__namespace.XmlText)) {
299
- throw new Error("Path doesn't match yText, cannot descent into non-yText");
300
- }
301
- return getYTarget(yTarget, targetNode, childPath);
302
- }
303
- return {
304
- yParent: yRoot,
305
- textRange: { start: yOffset, end: yOffset + targetLength },
306
- yTarget: yTarget instanceof Y__namespace.XmlText ? yTarget : undefined,
307
- slateParent: slateRoot,
308
- slateTarget: targetNode,
309
- targetDelta: targetDelta,
310
- };
311
- }
312
- function yOffsetToSlateOffsets(parent, yOffset, opts) {
313
- if (opts === void 0) { opts = {}; }
314
- var _a = opts.assoc, assoc = _a === void 0 ? 0 : _a, _b = opts.insert, insert = _b === void 0 ? false : _b;
315
- var currentOffset = 0;
316
- var lastNonEmptyPathOffset = 0;
317
- for (var pathOffset = 0; pathOffset < parent.children.length; pathOffset += 1) {
318
- var child_1 = parent.children[pathOffset];
319
- var nodeLength = slate.Text.isText(child_1) ? child_1.text.length : 1;
320
- if (nodeLength > 0) {
321
- lastNonEmptyPathOffset = pathOffset;
322
- }
323
- var endOffset = currentOffset + nodeLength;
324
- if (nodeLength > 0 && (assoc >= 0 ? endOffset > yOffset : endOffset >= yOffset)) {
325
- return [pathOffset, yOffset - currentOffset];
326
- }
327
- currentOffset += nodeLength;
328
- }
329
- if (yOffset > currentOffset + (insert ? 1 : 0)) {
330
- throw new Error('yOffset out of bounds');
331
- }
332
- if (insert) {
333
- return [parent.children.length, 0];
334
- }
335
- var child = parent.children[lastNonEmptyPathOffset];
336
- var textOffset = slate.Text.isText(child) ? child.text.length : 1;
337
- return [lastNonEmptyPathOffset, textOffset];
338
- }
339
- function getSlatePath(sharedRoot, slateRoot, yText) {
340
- var yNodePath = [yText];
341
- while (yNodePath[0] !== sharedRoot) {
342
- var yParent = yNodePath[0].parent;
343
- if (!yParent) {
344
- throw new Error("yText isn't a descendant of root element");
345
- }
346
- if (!(yParent instanceof Y__namespace.XmlText)) {
347
- throw new Error('Unexpected y parent type');
348
- }
349
- yNodePath.unshift(yParent);
350
- }
351
- if (yNodePath.length < 2) {
352
- return [];
353
- }
354
- var slateParent = slateRoot;
355
- return yNodePath.reduce(function (path, yParent, idx) {
356
- var e_1, _a;
357
- var yChild = yNodePath[idx + 1];
358
- if (!yChild) {
359
- return path;
360
- }
361
- var yOffset = 0;
362
- var currentDelta = yTextToInsertDelta(yParent);
363
- try {
364
- for (var currentDelta_1 = __values(currentDelta), currentDelta_1_1 = currentDelta_1.next(); !currentDelta_1_1.done; currentDelta_1_1 = currentDelta_1.next()) {
365
- var element = currentDelta_1_1.value;
366
- if (element.insert === yChild) {
367
- break;
368
- }
369
- yOffset += typeof element.insert === 'string' ? element.insert.length : 1;
370
- }
371
- }
372
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
373
- finally {
374
- try {
375
- if (currentDelta_1_1 && !currentDelta_1_1.done && (_a = currentDelta_1.return)) _a.call(currentDelta_1);
376
- }
377
- finally { if (e_1) throw e_1.error; }
378
- }
379
- if (slate.Text.isText(slateParent)) {
380
- throw new Error('Cannot descent into slate text');
381
- }
382
- var _b = __read(yOffsetToSlateOffsets(slateParent, yOffset), 1), pathOffset = _b[0];
383
- slateParent = slateParent.children[pathOffset];
384
- return path.concat(pathOffset);
385
- }, []);
386
- }
387
-
388
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
389
- function assertDocumentAttachment(sharedType) {
390
- if (!sharedType.doc) {
391
- throw new Error("shared type isn't attached to a document");
392
- }
393
- }
394
-
395
- var STORED_POSITION_PREFIX = '__slateYjsStoredPosition_';
396
- function slatePointToRelativePosition(sharedRoot, slateRoot, point) {
397
- var _a = getYTarget(sharedRoot, slateRoot, point.path), yTarget = _a.yTarget, yParent = _a.yParent, textRange = _a.textRange;
398
- if (yTarget) {
399
- throw new Error('Slate point points to a non-text element inside sharedRoot');
400
- }
401
- var index = textRange.start + point.offset;
402
- return Y__namespace.createRelativePositionFromTypeIndex(yParent, index, index === textRange.end ? -1 : 0);
403
- }
404
- function absolutePositionToSlatePoint(sharedRoot, slateRoot, _a) {
405
- var type = _a.type, index = _a.index, assoc = _a.assoc;
406
- if (!(type instanceof Y__namespace.XmlText)) {
407
- throw new Error('Absolute position points to a non-XMLText');
408
- }
409
- var parentPath = getSlatePath(sharedRoot, slateRoot, type);
410
- var parent = slate.Node.get(slateRoot, parentPath);
411
- if (slate.Text.isText(parent) || !slate.Element.isElement(parent)) {
412
- throw new Error("Absolute position doesn't match slateRoot, cannot descent into text and EditorRoot");
413
- }
414
- var _b = __read(yOffsetToSlateOffsets(parent, index, {
415
- assoc: assoc,
416
- }), 2), pathOffset = _b[0], textOffset = _b[1];
417
- var target = parent.children[pathOffset];
418
- if (!slate.Text.isText(target)) {
419
- return null;
420
- }
421
- return { path: __spreadArray(__spreadArray([], __read(parentPath), false), [pathOffset], false), offset: textOffset };
422
- }
423
- function relativePositionToSlatePoint(sharedRoot, slateRoot, pos) {
424
- if (!sharedRoot.doc) {
425
- throw new Error("sharedRoot isn't attach to a yDoc");
426
- }
427
- var absPos = Y__namespace.createAbsolutePositionFromRelativePosition(pos, sharedRoot.doc);
428
- return absPos && absolutePositionToSlatePoint(sharedRoot, slateRoot, absPos);
429
- }
430
- function getStoredPosition(sharedRoot, key) {
431
- var rawPosition = sharedRoot.getAttribute(STORED_POSITION_PREFIX + key);
432
- if (!rawPosition) {
433
- return null;
434
- }
435
- return Y__namespace.decodeRelativePosition(rawPosition);
436
- }
437
- function getStoredPositions(sharedRoot) {
438
- return Object.fromEntries(Object.entries(sharedRoot.getAttributes())
439
- .filter(function (_a) {
440
- var _b = __read(_a, 1), key = _b[0];
441
- return key.startsWith(STORED_POSITION_PREFIX);
442
- })
443
- .map(function (_a) {
444
- var _b = __read(_a, 2), key = _b[0], position = _b[1];
445
- return [
446
- key.slice(STORED_POSITION_PREFIX.length),
447
- Y__namespace.createRelativePositionFromJSON(position),
448
- ];
449
- }));
450
- }
451
- function getStoredPositionsAbsolute(sharedRoot) {
452
- assertDocumentAttachment(sharedRoot);
453
- return Object.fromEntries(Object.entries(sharedRoot.getAttributes())
454
- .filter(function (_a) {
455
- var _b = __read(_a, 1), key = _b[0];
456
- return key.startsWith(STORED_POSITION_PREFIX);
457
- })
458
- .map(function (_a) {
459
- var _b = __read(_a, 2), key = _b[0], position = _b[1];
460
- return [
461
- key.slice(STORED_POSITION_PREFIX.length),
462
- Y__namespace.createAbsolutePositionFromRelativePosition(Y__namespace.decodeRelativePosition(position), sharedRoot.doc),
463
- ];
464
- })
465
- .filter(function (_a) {
466
- var _b = __read(_a, 2), position = _b[1];
467
- return position;
468
- }));
469
- }
470
- function removeStoredPosition(sharedRoot, key) {
471
- sharedRoot.removeAttribute(STORED_POSITION_PREFIX + key);
472
- }
473
- function setStoredPosition(sharedRoot, key, position) {
474
- sharedRoot.setAttribute(STORED_POSITION_PREFIX + key, Y__namespace.encodeRelativePosition(position));
475
- }
476
- function getAbsolutePositionsInTextRange(absolutePositions, yTarget, textRange) {
477
- return Object.fromEntries(Object.entries(absolutePositions).filter(function (_a) {
478
- var _b = __read(_a, 2), position = _b[1];
479
- if (position.type !== yTarget) {
480
- return false;
481
- }
482
- if (!textRange) {
483
- return true;
484
- }
485
- return position.assoc >= 0
486
- ? position.index >= textRange.start && position.index < textRange.end
487
- : position.index > textRange.start && position.index >= textRange.end;
488
- }));
489
- }
490
- function getAbsolutePositionsInYText(absolutePositions, yText, parentPath) {
491
- var _a;
492
- if (parentPath === void 0) { parentPath = ''; }
493
- var positions = (_a = {},
494
- _a[parentPath] = getAbsolutePositionsInTextRange(absolutePositions, yText),
495
- _a);
496
- var insertDelta = yTextToInsertDelta(yText);
497
- insertDelta.forEach(function (_a, i) {
498
- var insert = _a.insert;
499
- if (insert instanceof Y__namespace.XmlText) {
500
- Object.assign(positions, getAbsolutePositionsInYText(absolutePositions, insert, parentPath ? "".concat(parentPath, ".").concat(i) : i.toString()));
501
- }
502
- });
503
- return positions;
504
- }
505
- function getStoredPositionsInDeltaAbsolute(sharedRoot, yText, delta, deltaOffset) {
506
- if (deltaOffset === void 0) { deltaOffset = 0; }
507
- var absolutePositions = getStoredPositionsAbsolute(sharedRoot);
508
- var positions = {
509
- '': getAbsolutePositionsInTextRange(absolutePositions, yText, {
510
- start: deltaOffset,
511
- end: deltaOffset + getInsertDeltaLength(delta),
512
- }),
513
- };
514
- delta.forEach(function (_a, i) {
515
- var insert = _a.insert;
516
- if (insert instanceof Y__namespace.XmlText) {
517
- Object.assign(positions, getAbsolutePositionsInYText(absolutePositions, insert, i.toString()));
518
- }
519
- });
520
- return positions;
521
- }
522
- function restoreStoredPositionsWithDeltaAbsolute(sharedRoot, yText, absolutePositions, delta, newDeltaOffset, previousDeltaOffset, path) {
523
- if (newDeltaOffset === void 0) { newDeltaOffset = 0; }
524
- if (previousDeltaOffset === void 0) { previousDeltaOffset = 0; }
525
- if (path === void 0) { path = ''; }
526
- var toRestore = absolutePositions[path];
527
- if (toRestore) {
528
- Object.entries(toRestore).forEach(function (_a) {
529
- var _b = __read(_a, 2), key = _b[0], position = _b[1];
530
- setStoredPosition(sharedRoot, key, Y__namespace.createRelativePositionFromTypeIndex(yText, position.index - previousDeltaOffset + newDeltaOffset, position.assoc));
531
- });
532
- }
533
- delta.forEach(function (_a, i) {
534
- var insert = _a.insert;
535
- if (insert instanceof Y__namespace.XmlText) {
536
- restoreStoredPositionsWithDeltaAbsolute(sharedRoot, insert, absolutePositions, yTextToInsertDelta(insert), 0, 0, path ? "".concat(path, ".").concat(i) : i.toString());
537
- }
538
- });
539
- }
540
- function slateRangeToRelativeRange(sharedRoot, slateRoot, range) {
541
- return {
542
- anchor: slatePointToRelativePosition(sharedRoot, slateRoot, range.anchor),
543
- focus: slatePointToRelativePosition(sharedRoot, slateRoot, range.focus),
544
- };
545
- }
546
- function relativeRangeToSlateRange(sharedRoot, slateRoot, range) {
547
- var anchor = relativePositionToSlatePoint(sharedRoot, slateRoot, range.anchor);
548
- if (!anchor) {
549
- return null;
550
- }
551
- var focus = relativePositionToSlatePoint(sharedRoot, slateRoot, range.focus);
552
- if (!focus) {
553
- return null;
554
- }
555
- return { anchor: anchor, focus: focus };
556
- }
557
-
558
- function getProperties(node) {
559
- return omit(node, (slate.Text.isText(node) ? 'text' : 'children'));
560
- }
561
-
562
- function yTextToSlateElement(yText) {
563
- var delta = yTextToInsertDelta(yText);
564
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
565
- var children = delta.length > 0 ? delta.map(deltaInsertToSlateNode) : [{ text: '' }];
566
- // @ts-ignore
567
- return __assign(__assign({}, yText.getAttributes()), { children: children });
568
- }
569
- function deltaInsertToSlateNode(insert) {
570
- if (typeof insert.insert === 'string') {
571
- return __assign(__assign({}, insert.attributes), { text: insert.insert });
572
- }
573
- return yTextToSlateElement(insert.insert);
574
- }
575
- function slateNodesToInsertDelta(nodes) {
576
- return nodes.map(function (node) {
577
- if (slate.Text.isText(node)) {
578
- return { insert: node.text, attributes: getProperties(node) };
579
- }
580
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
581
- return { insert: slateElementToYText(node) };
582
- });
583
- }
584
- function slateElementToYText(_a) {
585
- var children = _a.children, attributes = __rest(_a, ["children"]);
586
- var yElement = new Y__namespace.XmlText();
587
- Object.entries(attributes).forEach(function (_a) {
588
- var _b = __read(_a, 2), key = _b[0], value = _b[1];
589
- yElement.setAttribute(key, value);
590
- });
591
- yElement.applyDelta(slateNodesToInsertDelta(children), { sanitize: false });
592
- return yElement;
593
- }
594
-
595
- function applyDelta(node, slatePath, delta) {
596
- var ops = [];
597
- var yOffset = delta.reduce(function (length, change) {
598
- if ('retain' in change) {
599
- return length + change.retain;
600
- }
601
- if ('delete' in change) {
602
- return length + change.delete;
603
- }
604
- return length;
605
- }, 0);
606
- // Apply changes in reverse order to avoid path changes.
607
- delta.reverse().forEach(function (change) {
608
- var _a;
609
- if ('attributes' in change && 'retain' in change) {
610
- var _b = __read(yOffsetToSlateOffsets(node, yOffset - change.retain), 2), startPathOffset = _b[0], startTextOffset = _b[1];
611
- var _c = __read(yOffsetToSlateOffsets(node, yOffset, { assoc: -1 }), 2), endPathOffset = _c[0], endTextOffset = _c[1];
612
- for (var pathOffset = endPathOffset; pathOffset >= startPathOffset; pathOffset -= 1) {
613
- var child = node.children[pathOffset];
614
- var childPath = __spreadArray(__spreadArray([], __read(slatePath), false), [pathOffset], false);
615
- if (!slate.Text.isText(child)) {
616
- // Ignore attribute updates on non-text nodes (which are backed by Y.XmlText)
617
- // to be consistent with deltaInsertToSlateNode. Y.XmlText attributes don't show
618
- // up in deltas but in key changes (YEvent.changes.keys).
619
- continue;
620
- }
621
- var newProperties = change.attributes;
622
- var properties = pick.apply(void 0, __spreadArray([node], __read(Object.keys(change.attributes)), false));
623
- if (pathOffset === startPathOffset || pathOffset === endPathOffset) {
624
- var start = pathOffset === startPathOffset ? startTextOffset : 0;
625
- var end = pathOffset === endPathOffset ? endTextOffset : child.text.length;
626
- if (end !== child.text.length) {
627
- ops.push({
628
- type: 'split_node',
629
- path: childPath,
630
- position: end,
631
- properties: getProperties(child),
632
- });
633
- }
634
- if (start !== 0) {
635
- ops.push({
636
- type: 'split_node',
637
- path: childPath,
638
- position: start,
639
- properties: omitNullEntries(__assign(__assign({}, getProperties(child)), newProperties)),
640
- });
641
- continue;
642
- }
643
- }
644
- ops.push({
645
- type: 'set_node',
646
- newProperties: newProperties,
647
- path: childPath,
648
- properties: properties,
649
- });
650
- }
651
- }
652
- if ('retain' in change) {
653
- yOffset -= change.retain;
654
- }
655
- if ('delete' in change) {
656
- var _d = __read(yOffsetToSlateOffsets(node, yOffset - change.delete), 2), startPathOffset = _d[0], startTextOffset = _d[1];
657
- var _e = __read(yOffsetToSlateOffsets(node, yOffset, { assoc: -1 }), 2), endPathOffset = _e[0], endTextOffset = _e[1];
658
- for (var pathOffset = endTextOffset === 0 ? endPathOffset - 1 : endPathOffset; pathOffset >= startPathOffset; pathOffset -= 1) {
659
- var child = node.children[pathOffset];
660
- var childPath = __spreadArray(__spreadArray([], __read(slatePath), false), [pathOffset], false);
661
- if (slate.Text.isText(child)
662
- && (pathOffset === startPathOffset || pathOffset === endPathOffset)) {
663
- var start = pathOffset === startPathOffset ? startTextOffset : 0;
664
- var end = pathOffset === endPathOffset ? endTextOffset : child.text.length;
665
- ops.push({
666
- type: 'remove_text',
667
- offset: start,
668
- text: child.text.slice(start, end),
669
- path: childPath,
670
- });
671
- yOffset -= end - start;
672
- continue;
673
- }
674
- ops.push({
675
- type: 'remove_node',
676
- node: child,
677
- path: childPath,
678
- });
679
- yOffset -= getSlateNodeYLength(child);
680
- }
681
- return;
682
- }
683
- if ('insert' in change) {
684
- var _f = __read(yOffsetToSlateOffsets(node, yOffset, {
685
- insert: true,
686
- }), 2), pathOffset = _f[0], textOffset = _f[1];
687
- var child = node.children[pathOffset];
688
- var childPath = __spreadArray(__spreadArray([], __read(slatePath), false), [pathOffset], false);
689
- if (slate.Text.isText(child)) {
690
- var lastOp = ops[ops.length - 1];
691
- /**
692
- * The props that exist at the current path
693
- * Since we're not actually using slate to update the node
694
- * this is a simulation
695
- */
696
- var currentProps = lastOp != null && lastOp.type === 'insert_node' ? lastOp.node : getProperties(child);
697
- var lastPath = [];
698
- if (lastOp != null
699
- && (lastOp.type === 'insert_node'
700
- || lastOp.type === 'insert_text'
701
- || lastOp.type === 'split_node'
702
- || lastOp.type === 'set_node')) {
703
- lastPath = lastOp.path;
704
- }
705
- /**
706
- * If the insert is a string and the attributes are the same as the
707
- * props at the current path, we can just insert a text node
708
- */
709
- if (typeof change.insert === 'string'
710
- && deepEquals((_a = change.attributes) !== null && _a !== void 0 ? _a : {}, currentProps)
711
- && slate.Path.equals(childPath, lastPath)) {
712
- return ops.push({
713
- type: 'insert_text',
714
- offset: textOffset,
715
- text: change.insert,
716
- path: childPath,
717
- });
718
- }
719
- var toInsert = deltaInsertToSlateNode(change);
720
- if (textOffset === 0) {
721
- return ops.push({
722
- type: 'insert_node',
723
- path: childPath,
724
- node: toInsert,
725
- });
726
- }
727
- return ops.push({
728
- type: 'insert_node',
729
- path: slate.Path.next(childPath),
730
- node: toInsert,
731
- });
732
- }
733
- return ops.push({
734
- type: 'insert_node',
735
- path: childPath,
736
- node: deltaInsertToSlateNode(change),
737
- });
738
- }
739
- });
740
- return ops;
741
- }
742
- function translateYTextEvent(sharedRoot, editor, event) {
743
- var target = event.target, changes = event.changes;
744
- var delta = event.delta;
745
- if (!(target instanceof Y__namespace.XmlText)) {
746
- throw new Error('Unexpected target node type');
747
- }
748
- var ops = [];
749
- var slatePath = getSlatePath(sharedRoot, editor, target);
750
- var targetElement = slate.Node.get(editor, slatePath);
751
- if (slate.Text.isText(targetElement)) {
752
- throw new Error('Cannot apply yTextEvent to text node');
753
- }
754
- var keyChanges = Array.from(changes.keys.entries());
755
- if (slatePath.length > 0 && keyChanges.length > 0) {
756
- var newProperties = Object.fromEntries(keyChanges.map(function (_a) {
757
- var _b = __read(_a, 2), key = _b[0], info = _b[1];
758
- return [
759
- key,
760
- info.action === 'delete' ? null : target.getAttribute(key),
761
- ];
762
- }));
763
- var properties = Object.fromEntries(keyChanges.map(function (_a) {
764
- var _b = __read(_a, 1), key = _b[0];
765
- return [key, targetElement[key]];
766
- }));
767
- ops.push({
768
- type: 'set_node',
769
- newProperties: newProperties,
770
- properties: properties,
771
- path: slatePath,
772
- });
773
- }
774
- if (delta.length > 0) {
775
- ops.push.apply(ops, __spreadArray([], __read(applyDelta(targetElement, slatePath, delta)), false));
776
- }
777
- return ops;
778
- }
779
-
780
- /**
781
- * Translate a yjs event into slate operations. The editor state has to match the
782
- * yText state before the event occurred.
783
- *
784
- * @param sharedType
785
- * @param op
786
- */
787
- function translateYjsEvent(sharedRoot, editor, event) {
788
- if (event instanceof Y__namespace.YTextEvent) {
789
- return translateYTextEvent(sharedRoot, editor, event);
790
- }
791
- throw new Error('Unexpected Y event type');
792
- }
793
- /**
794
- * Translates yjs events into slate operations and applies them to the editor. The
795
- * editor state has to match the yText state before the events occurred.
796
- *
797
- * @param sharedRoot
798
- * @param editor
799
- * @param events
800
- */
801
- function applyYjsEvents(sharedRoot, editor, events) {
802
- slate.Editor.withoutNormalizing(editor, function () {
803
- events.forEach(function (event) {
804
- translateYjsEvent(sharedRoot, editor, event).forEach(function (op) {
805
- editor.apply(op);
806
- });
807
- });
808
- });
809
- }
810
-
811
- function insertNode(sharedRoot, slateRoot, op) {
812
- var _a = getYTarget(sharedRoot, slateRoot, op.path), yParent = _a.yParent, textRange = _a.textRange;
813
- if (slate.Text.isText(op.node)) {
814
- return yParent.insert(textRange.start, op.node.text, getProperties(op.node));
815
- }
816
- yParent.insertEmbed(textRange.start, slateElementToYText(op.node));
817
- }
818
-
819
- function cloneInsertDeltaDeep(delta) {
820
- return delta.map(function (element) {
821
- if (typeof element.insert === 'string') {
822
- return element;
823
- }
824
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
825
- return __assign(__assign({}, element), { insert: cloneDeep(element.insert) });
826
- });
827
- }
828
- function cloneDeep(yText) {
829
- var clone = new Y__namespace.XmlText();
830
- var attributes = yText.getAttributes();
831
- Object.entries(attributes).forEach(function (_a) {
832
- var _b = __read(_a, 2), key = _b[0], value = _b[1];
833
- clone.setAttribute(key, value);
834
- });
835
- clone.applyDelta(cloneInsertDeltaDeep(yTextToInsertDelta(yText)), {
836
- sanitize: false,
837
- });
838
- return clone;
839
- }
840
-
841
- function mergeNode(sharedRoot, slateRoot, op) {
842
- var target = getYTarget(sharedRoot, slateRoot, op.path);
843
- var prev = getYTarget(target.yParent, target.slateParent, slate.Path.previous(op.path.slice(-1)));
844
- if (!target.yTarget !== !prev.yTarget) {
845
- throw new Error('Cannot merge y text with y element');
846
- }
847
- if (!prev.yTarget || !target.yTarget) {
848
- var parent_1 = target.yParent, textRange = target.textRange, slateTarget = target.slateTarget;
849
- if (!slateTarget) {
850
- throw new Error('Expected Slate target node for merge op.');
851
- }
852
- var prevSibling = slate.Node.get(slateRoot, slate.Path.previous(op.path));
853
- if (!slate.Text.isText(prevSibling)) {
854
- throw new Error('Path points to Y.Text but not a Slate text node.');
855
- }
856
- var targetProps = getProperties(slateTarget);
857
- var prevSiblingProps_1 = getProperties(prevSibling);
858
- var unsetProps = Object.keys(targetProps).reduce(function (acc, key) {
859
- var _a;
860
- var prevSiblingHasProp = key in prevSiblingProps_1;
861
- return prevSiblingHasProp ? acc : __assign(__assign({}, acc), (_a = {}, _a[key] = null, _a));
862
- }, {});
863
- return parent_1.format(textRange.start, textRange.end - textRange.start, __assign(__assign({}, unsetProps), prevSiblingProps_1));
864
- }
865
- var deltaApplyYOffset = prev.yTarget.length;
866
- var targetDelta = yTextToInsertDelta(target.yTarget);
867
- var clonedDelta = cloneInsertDeltaDeep(targetDelta);
868
- var storedPositions = getStoredPositionsInDeltaAbsolute(sharedRoot, target.yTarget, targetDelta, deltaApplyYOffset);
869
- var applyDelta = __spreadArray([{ retain: deltaApplyYOffset }], __read(clonedDelta), false);
870
- prev.yTarget.applyDelta(applyDelta, {
871
- sanitize: false,
872
- });
873
- target.yParent.delete(target.textRange.start, target.textRange.end - target.textRange.start);
874
- restoreStoredPositionsWithDeltaAbsolute(sharedRoot, prev.yTarget, storedPositions, clonedDelta, deltaApplyYOffset);
875
- }
876
-
877
- function moveNode(sharedRoot, slateRoot, op) {
878
- var newParentPath = slate.Path.parent(op.newPath);
879
- var newPathOffset = op.newPath[op.newPath.length - 1];
880
- var parent = slate.Node.get(slateRoot, newParentPath);
881
- if (slate.Text.isText(parent)) {
882
- throw new Error('Cannot move slate node into text element');
883
- }
884
- var normalizedNewPath = __spreadArray(__spreadArray([], __read(newParentPath), false), [Math.min(newPathOffset, parent.children.length)], false);
885
- var origin = getYTarget(sharedRoot, slateRoot, op.path);
886
- var target = getYTarget(sharedRoot, slateRoot, normalizedNewPath);
887
- var insertDelta = cloneInsertDeltaDeep(origin.targetDelta);
888
- var storedPositions = getStoredPositionsInDeltaAbsolute(sharedRoot, origin.yParent, origin.targetDelta);
889
- origin.yParent.delete(origin.textRange.start, origin.textRange.end - origin.textRange.start);
890
- var targetLength = getInsertDeltaLength(yTextToInsertDelta(target.yParent));
891
- var deltaApplyYOffset = Math.min(target.textRange.start, targetLength);
892
- var applyDelta = __spreadArray([{ retain: deltaApplyYOffset }], __read(insertDelta), false);
893
- target.yParent.applyDelta(applyDelta, { sanitize: false });
894
- restoreStoredPositionsWithDeltaAbsolute(sharedRoot, target.yParent, storedPositions, insertDelta, deltaApplyYOffset, origin.textRange.start);
895
- }
896
-
897
- function removeNode(sharedRoot, slateRoot, op) {
898
- var _a = getYTarget(sharedRoot, slateRoot, op.path), parent = _a.yParent, textRange = _a.textRange;
899
- parent.delete(textRange.start, textRange.end - textRange.start);
900
- }
901
-
902
- function setNode(sharedRoot, slateRoot, op) {
903
- var _a = getYTarget(sharedRoot, slateRoot, op.path), yTarget = _a.yTarget, textRange = _a.textRange, yParent = _a.yParent;
904
- if (yTarget) {
905
- Object.entries(op.newProperties).forEach(function (_a) {
906
- var _b = __read(_a, 2), key = _b[0], value = _b[1];
907
- if (value === null) {
908
- return yTarget.removeAttribute(key);
909
- }
910
- yTarget.setAttribute(key, value);
911
- });
912
- return Object.entries(op.properties).forEach(function (_a) {
913
- var _b = __read(_a, 1), key = _b[0];
914
- if (!Object.prototype.hasOwnProperty.call(op.newProperties, key)) {
915
- yTarget.removeAttribute(key);
916
- }
917
- });
918
- }
919
- var unset = Object.fromEntries(Object.keys(op.properties).map(function (key) { return [key, null]; }));
920
- var newProperties = __assign(__assign({}, unset), op.newProperties);
921
- yParent.format(textRange.start, textRange.end - textRange.start, newProperties);
922
- }
923
-
924
- function splitNode(sharedRoot, slateRoot, op) {
925
- var target = getYTarget(sharedRoot, slateRoot, op.path);
926
- if (!target.slateTarget) {
927
- throw new Error('Y target without corresponding slate node');
928
- }
929
- if (!target.yTarget) {
930
- if (!slate.Text.isText(target.slateTarget)) {
931
- throw new Error('Mismatch node type between y target and slate node');
932
- }
933
- var unset_1 = {};
934
- target.targetDelta.forEach(function (element) {
935
- if (element.attributes) {
936
- Object.keys(element.attributes).forEach(function (key) {
937
- unset_1[key] = null;
938
- });
939
- }
940
- });
941
- return target.yParent.format(target.textRange.start, target.textRange.end - target.textRange.start, __assign(__assign({}, unset_1), op.properties));
942
- }
943
- if (slate.Text.isText(target.slateTarget)) {
944
- throw new Error('Mismatch node type between y target and slate node');
945
- }
946
- var splitTarget = getYTarget(target.yTarget, target.slateTarget, [op.position]);
947
- var ySplitOffset = target.slateTarget.children
948
- .slice(0, op.position)
949
- .reduce(function (length, child) { return length + getSlateNodeYLength(child); }, 0);
950
- // @ts-ignore
951
- var length = target.slateTarget.children.reduce(function (current, child) { return current + getSlateNodeYLength(child); }, 0);
952
- var splitDelta = sliceInsertDelta(yTextToInsertDelta(target.yTarget), ySplitOffset, length - ySplitOffset);
953
- var clonedDelta = cloneInsertDeltaDeep(splitDelta);
954
- var storedPositions = getStoredPositionsInDeltaAbsolute(sharedRoot, target.yTarget, splitDelta, ySplitOffset);
955
- var toInsert = new Y__namespace.XmlText();
956
- toInsert.applyDelta(clonedDelta, {
957
- sanitize: false,
958
- });
959
- Object.entries(op.properties).forEach(function (_a) {
960
- var _b = __read(_a, 2), key = _b[0], value = _b[1];
961
- toInsert.setAttribute(key, value);
962
- });
963
- target.yTarget.delete(splitTarget.textRange.start, target.yTarget.length - splitTarget.textRange.start);
964
- target.yParent.insertEmbed(target.textRange.end, toInsert);
965
- restoreStoredPositionsWithDeltaAbsolute(sharedRoot, toInsert, storedPositions, clonedDelta, 0, ySplitOffset);
966
- }
967
-
968
- var NODE_MAPPER = {
969
- insert_node: insertNode,
970
- remove_node: removeNode,
971
- set_node: setNode,
972
- merge_node: mergeNode,
973
- move_node: moveNode,
974
- split_node: splitNode,
975
- };
976
-
977
- function insertText(sharedRoot, slateRoot, op) {
978
- var _a = getYTarget(sharedRoot, slateRoot, op.path), target = _a.yParent, textRange = _a.textRange;
979
- var targetNode = slate.Node.get(slateRoot, op.path);
980
- if (!slate.Text.isText(targetNode)) {
981
- throw new Error('Cannot insert text into non-text node');
982
- }
983
- target.insert(textRange.start + op.offset, op.text, getProperties(targetNode));
984
- }
985
-
986
- function removeText(sharedRoot, slateRoot, op) {
987
- var _a = getYTarget(sharedRoot, slateRoot, op.path), target = _a.yParent, textRange = _a.textRange;
988
- target.delete(textRange.start + op.offset, op.text.length);
989
- }
990
-
991
- var TEXT_MAPPER = {
992
- insert_text: insertText,
993
- remove_text: removeText,
994
- };
995
-
996
- // eslint-disable-next-line @typescript-eslint/no-empty-function
997
- var NOOP = function () { };
998
- var opMappers = __assign(__assign(__assign({}, TEXT_MAPPER), NODE_MAPPER), { set_selection: NOOP });
999
- function applySlateOp(sharedRoot, slateRoot, op) {
1000
- var apply = opMappers[op.type];
1001
- if (!apply) {
1002
- throw new Error("Unknown operation: ".concat(op.type));
1003
- }
1004
- apply(sharedRoot, slateRoot, op);
1005
- }
1006
-
1007
- var DEFAULT_LOCAL_ORIGIN = Symbol('slate-yjs-operation');
1008
- var DEFAULT_POSITION_STORAGE_ORIGIN = Symbol('slate-yjs-position-storage');
1009
- var ORIGIN = new WeakMap();
1010
- var LOCAL_CHANGES = new WeakMap();
1011
- var CONNECTED = new WeakSet();
1012
- // eslint-disable-next-line @typescript-eslint/no-redeclare
1013
- var YjsEditor = {
1014
- isYjsEditor: function (value) {
1015
- return (slate.Editor.isEditor(value)
1016
- && value.sharedRoot instanceof Y__namespace.XmlText
1017
- && 'localOrigin' in value
1018
- && 'positionStorageOrigin' in value
1019
- && typeof value.applyRemoteEvents === 'function'
1020
- && typeof value.storeLocalChange === 'function'
1021
- && typeof value.flushLocalChanges === 'function'
1022
- && typeof value.isLocalOrigin === 'function'
1023
- && typeof value.connect === 'function'
1024
- && typeof value.disconnect === 'function');
1025
- },
1026
- localChanges: function (editor) {
1027
- var _a;
1028
- return (_a = LOCAL_CHANGES.get(editor)) !== null && _a !== void 0 ? _a : [];
1029
- },
1030
- applyRemoteEvents: function (editor, events, origin) {
1031
- editor.applyRemoteEvents(events, origin);
1032
- },
1033
- storeLocalChange: function (editor, op) {
1034
- editor.storeLocalChange(op);
1035
- },
1036
- flushLocalChanges: function (editor) {
1037
- editor.flushLocalChanges();
1038
- },
1039
- connected: function (editor) {
1040
- return CONNECTED.has(editor);
1041
- },
1042
- connect: function (editor) {
1043
- editor.connect();
1044
- },
1045
- disconnect: function (editor) {
1046
- editor.disconnect();
1047
- },
1048
- isLocal: function (editor) {
1049
- return editor.isLocalOrigin(YjsEditor.origin(editor));
1050
- },
1051
- origin: function (editor) {
1052
- var origin = ORIGIN.get(editor);
1053
- return origin !== undefined ? origin : editor.localOrigin;
1054
- },
1055
- withOrigin: function (editor, origin, fn) {
1056
- var prev = YjsEditor.origin(editor);
1057
- ORIGIN.set(editor, origin);
1058
- fn();
1059
- ORIGIN.set(editor, prev);
1060
- },
1061
- storePosition: function (editor, key, point) {
1062
- var sharedRoot = editor.sharedRoot, locationStorageOrigin = editor.positionStorageOrigin;
1063
- assertDocumentAttachment(sharedRoot);
1064
- var position = slatePointToRelativePosition(sharedRoot, editor, point);
1065
- sharedRoot.doc.transact(function () {
1066
- setStoredPosition(sharedRoot, key, position);
1067
- }, locationStorageOrigin);
1068
- },
1069
- removeStoredPosition: function (editor, key) {
1070
- var sharedRoot = editor.sharedRoot, locationStorageOrigin = editor.positionStorageOrigin;
1071
- assertDocumentAttachment(sharedRoot);
1072
- sharedRoot.doc.transact(function () {
1073
- removeStoredPosition(sharedRoot, key);
1074
- }, locationStorageOrigin);
1075
- },
1076
- position: function (editor, key) {
1077
- var position = getStoredPosition(editor.sharedRoot, key);
1078
- if (!position) {
1079
- return undefined;
1080
- }
1081
- return relativePositionToSlatePoint(editor.sharedRoot, editor, position);
1082
- },
1083
- storedPositionsRelative: function (editor) {
1084
- return getStoredPositions(editor.sharedRoot);
1085
- },
1086
- };
1087
- function withYjs(sharedRoot, options) {
1088
- if (options === void 0) { options = {}; }
1089
- return function (editor) {
1090
- var _a, _b;
1091
- var e = editor;
1092
- e.sharedRoot = sharedRoot;
1093
- e.localOrigin = (_a = options.localOrigin) !== null && _a !== void 0 ? _a : DEFAULT_LOCAL_ORIGIN;
1094
- e.positionStorageOrigin = (_b = options.positionStorageOrigin) !== null && _b !== void 0 ? _b : DEFAULT_POSITION_STORAGE_ORIGIN;
1095
- e.applyRemoteEvents = function (events, origin) {
1096
- YjsEditor.flushLocalChanges(e);
1097
- slate.Editor.withoutNormalizing(e, function () {
1098
- YjsEditor.withOrigin(e, origin, function () {
1099
- applyYjsEvents(e.sharedRoot, e, events);
1100
- });
1101
- });
1102
- };
1103
- e.isLocalOrigin = function (origin) { return origin === e.localOrigin; };
1104
- var handleYEvents = function (events, transaction) {
1105
- if (e.isLocalOrigin(transaction.origin)) {
1106
- return;
1107
- }
1108
- YjsEditor.applyRemoteEvents(e, events, transaction.origin);
1109
- };
1110
- var autoConnectTimeoutId = null;
1111
- if (options.autoConnect) {
1112
- autoConnectTimeoutId = setTimeout(function () {
1113
- autoConnectTimeoutId = null;
1114
- YjsEditor.connect(e);
1115
- });
1116
- }
1117
- e.connect = function () {
1118
- if (YjsEditor.connected(e)) {
1119
- throw new Error('already connected');
1120
- }
1121
- e.sharedRoot.observeDeep(handleYEvents);
1122
- var content = yTextToSlateElement(e.sharedRoot);
1123
- e.children = content.children;
1124
- CONNECTED.add(e);
1125
- slate.Editor.normalize(editor, { force: true });
1126
- if (!editor.operations.length) {
1127
- editor.onChange();
1128
- }
1129
- };
1130
- e.disconnect = function () {
1131
- if (autoConnectTimeoutId) {
1132
- clearTimeout(autoConnectTimeoutId);
1133
- }
1134
- YjsEditor.flushLocalChanges(e);
1135
- e.sharedRoot.unobserveDeep(handleYEvents);
1136
- CONNECTED.delete(e);
1137
- };
1138
- e.storeLocalChange = function (op) {
1139
- LOCAL_CHANGES.set(e, __spreadArray(__spreadArray([], __read(YjsEditor.localChanges(e)), false), [
1140
- { op: op, doc: editor.children, origin: YjsEditor.origin(e) },
1141
- ], false));
1142
- };
1143
- e.flushLocalChanges = function () {
1144
- assertDocumentAttachment(e.sharedRoot);
1145
- var localChanges = YjsEditor.localChanges(e);
1146
- LOCAL_CHANGES.delete(e);
1147
- var txGroups = [];
1148
- localChanges.forEach(function (change) {
1149
- var currentGroup = txGroups[txGroups.length - 1];
1150
- if (currentGroup && currentGroup[0].origin === change.origin) {
1151
- return currentGroup.push(change);
1152
- }
1153
- txGroups.push([change]);
1154
- });
1155
- txGroups.forEach(function (txGroup) {
1156
- assertDocumentAttachment(e.sharedRoot);
1157
- e.sharedRoot.doc.transact(function () {
1158
- txGroup.forEach(function (change) {
1159
- assertDocumentAttachment(e.sharedRoot);
1160
- // @ts-ignore
1161
- applySlateOp(e.sharedRoot, { children: change.doc }, change.op);
1162
- });
1163
- }, txGroup[0].origin);
1164
- });
1165
- };
1166
- var apply = e.apply, onChange = e.onChange;
1167
- e.apply = function (op) {
1168
- if (YjsEditor.connected(e) && YjsEditor.isLocal(e)) {
1169
- YjsEditor.storeLocalChange(e, op);
1170
- }
1171
- apply(op);
1172
- };
1173
- e.onChange = function () {
1174
- if (YjsEditor.connected(e)) {
1175
- YjsEditor.flushLocalChanges(e);
1176
- }
1177
- onChange();
1178
- };
1179
- return e;
1180
- };
1181
- }
1182
-
1183
- var CURSOR_CHANGE_EVENT_LISTENERS = new WeakMap();
1184
- // eslint-disable-next-line @typescript-eslint/no-redeclare
1185
- var CursorEditor = {
1186
- isCursorEditor: function (value) {
1187
- return (YjsEditor.isYjsEditor(value)
1188
- && value.awareness
1189
- && typeof value.cursorDataField === 'string'
1190
- && typeof value.selectionStateField === 'string'
1191
- && typeof value.sendCursorPosition === 'function'
1192
- && typeof value.sendCursorData === 'function');
1193
- },
1194
- sendCursorPosition: function (editor, range) {
1195
- if (range === void 0) { range = editor.selection; }
1196
- editor.sendCursorPosition(range);
1197
- },
1198
- sendCursorData: function (editor, data) {
1199
- editor.sendCursorData(data);
1200
- },
1201
- on: function (editor, event, handler) {
1202
- var _a;
1203
- if (event !== 'change') {
1204
- return;
1205
- }
1206
- var listeners = (_a = CURSOR_CHANGE_EVENT_LISTENERS.get(editor)) !== null && _a !== void 0 ? _a : new Set();
1207
- listeners.add(handler);
1208
- if (editor) {
1209
- CURSOR_CHANGE_EVENT_LISTENERS.set(editor, listeners);
1210
- }
1211
- },
1212
- off: function (editor, event, listener) {
1213
- if (event !== 'change') {
1214
- return;
1215
- }
1216
- var listeners = CURSOR_CHANGE_EVENT_LISTENERS.get(editor);
1217
- if (listeners) {
1218
- listeners.delete(listener);
1219
- }
1220
- },
1221
- cursorState: function (editor, clientId) {
1222
- var _a;
1223
- if (clientId === editor.awareness.clientID || !YjsEditor.connected(editor)) {
1224
- return null;
1225
- }
1226
- var state = editor.awareness.getStates().get(clientId);
1227
- if (!state) {
1228
- return null;
1229
- }
1230
- return {
1231
- relativeSelection: (_a = state[editor.selectionStateField]) !== null && _a !== void 0 ? _a : null,
1232
- data: state[editor.cursorDataField],
1233
- clientId: clientId,
1234
- };
1235
- },
1236
- cursorStates: function (editor) {
1237
- if (!YjsEditor.connected(editor)) {
1238
- return {};
1239
- }
1240
- return Object.fromEntries(Array.from(editor.awareness.getStates().entries(), function (_a) {
1241
- var _b = __read(_a, 2), id = _b[0], state = _b[1];
1242
- // Ignore own state
1243
- if (id === editor.awareness.clientID || !state) {
1244
- return null;
1245
- }
1246
- return [
1247
- id,
1248
- {
1249
- relativeSelection: state[editor.selectionStateField],
1250
- data: state[editor.cursorDataField],
1251
- },
1252
- ];
1253
- }).filter(Array.isArray));
1254
- },
1255
- };
1256
- function withCursors(awareness, options) {
1257
- if (options === void 0) { options = {}; }
1258
- return function (editor) {
1259
- var _a = options.cursorStateField, selectionStateField = _a === void 0 ? 'selection' : _a, _b = options.cursorDataField, cursorDataField = _b === void 0 ? 'data' : _b, _c = options.autoSend, autoSend = _c === void 0 ? true : _c, data = options.data;
1260
- var e = editor;
1261
- e.awareness = awareness;
1262
- e.cursorDataField = cursorDataField;
1263
- e.selectionStateField = selectionStateField;
1264
- e.sendCursorData = function (cursorData) {
1265
- e.awareness.setLocalStateField(e.cursorDataField, cursorData);
1266
- };
1267
- e.sendCursorPosition = function (range) {
1268
- var localState = e.awareness.getLocalState();
1269
- var currentRange = localState === null || localState === void 0 ? void 0 : localState[selectionStateField];
1270
- if (!range) {
1271
- if (currentRange) {
1272
- e.awareness.setLocalStateField(e.selectionStateField, null);
1273
- }
1274
- return;
1275
- }
1276
- var _a = slateRangeToRelativeRange(e.sharedRoot, e, range), anchor = _a.anchor, focus = _a.focus;
1277
- if (!currentRange
1278
- || !Y__namespace.compareRelativePositions(anchor, currentRange)
1279
- || !Y__namespace.compareRelativePositions(focus, currentRange)) {
1280
- e.awareness.setLocalStateField(e.selectionStateField, { anchor: anchor, focus: focus });
1281
- }
1282
- };
1283
- var awarenessChangeListener = function (yEvent) {
1284
- var listeners = CURSOR_CHANGE_EVENT_LISTENERS.get(e);
1285
- if (!listeners) {
1286
- return;
1287
- }
1288
- var localId = e.awareness.clientID;
1289
- var event = {
1290
- added: yEvent.added.filter(function (id) { return id !== localId; }),
1291
- removed: yEvent.removed.filter(function (id) { return id !== localId; }),
1292
- updated: yEvent.updated.filter(function (id) { return id !== localId; }),
1293
- };
1294
- if (event.added.length > 0 || event.removed.length > 0 || event.updated.length > 0) {
1295
- listeners.forEach(function (listener) { return listener(event); });
1296
- }
1297
- };
1298
- var connect = e.connect, disconnect = e.disconnect;
1299
- e.connect = function () {
1300
- connect();
1301
- e.awareness.on('change', awarenessChangeListener);
1302
- awarenessChangeListener({
1303
- removed: [],
1304
- added: Array.from(e.awareness.getStates().keys()),
1305
- updated: [],
1306
- });
1307
- if (autoSend) {
1308
- if (data) {
1309
- CursorEditor.sendCursorData(e, data);
1310
- }
1311
- var onChange_1 = e.onChange;
1312
- e.onChange = function () {
1313
- onChange_1();
1314
- if (YjsEditor.connected(e)) {
1315
- CursorEditor.sendCursorPosition(e);
1316
- }
1317
- };
1318
- }
1319
- };
1320
- e.disconnect = function () {
1321
- e.awareness.off('change', awarenessChangeListener);
1322
- awarenessChangeListener({
1323
- removed: Array.from(e.awareness.getStates().keys()),
1324
- added: [],
1325
- updated: [],
1326
- });
1327
- disconnect();
1328
- };
1329
- return e;
1330
- };
1331
- }
1332
-
1333
- var LAST_SELECTION = new WeakMap();
1334
- var DEFAULT_WITHOUT_SAVING_ORIGIN = Symbol('slate-yjs-history-without-saving');
1335
- // eslint-disable-next-line @typescript-eslint/no-redeclare
1336
- var YHistoryEditor = {
1337
- isYHistoryEditor: function (value) {
1338
- return (YjsEditor.isYjsEditor(value)
1339
- && value.undoManager instanceof Y__namespace.UndoManager
1340
- && typeof value.undo === 'function'
1341
- && typeof value.redo === 'function'
1342
- && 'withoutSavingOrigin' in value);
1343
- },
1344
- canUndo: function (editor) {
1345
- return editor.undoManager.undoStack.length > 0;
1346
- },
1347
- canRedo: function (editor) {
1348
- return editor.undoManager.redoStack.length > 0;
1349
- },
1350
- isSaving: function (editor) {
1351
- return editor.undoManager.trackedOrigins.has(YjsEditor.origin(editor));
1352
- },
1353
- withoutSaving: function (editor, fn) {
1354
- YjsEditor.withOrigin(editor, editor.withoutSavingOrigin, fn);
1355
- },
1356
- };
1357
- function withYHistory(options) {
1358
- if (options === void 0) { options = {}; }
1359
- return function (editor) {
1360
- var e = editor;
1361
- // 将 trackedOrigins 的初始化放到 editor 被传入之后
1362
- var _a = options.withoutSavingOrigin, withoutSavingOrigin = _a === void 0 ? DEFAULT_WITHOUT_SAVING_ORIGIN : _a, _b = options.trackedOrigins, trackedOrigins = _b === void 0 ? new Set([e.localOrigin]) : _b, restOptions = __rest(options, ["withoutSavingOrigin", "trackedOrigins"]);
1363
- var undoManager = new Y__namespace.UndoManager(e.sharedRoot, __assign({ trackedOrigins: trackedOrigins }, restOptions));
1364
- e.undoManager = undoManager;
1365
- e.withoutSavingOrigin = withoutSavingOrigin;
1366
- var onChange = e.onChange, isLocalOrigin = e.isLocalOrigin;
1367
- e.onChange = function () {
1368
- onChange();
1369
- LAST_SELECTION.set(e, e.selection && slateRangeToRelativeRange(e.sharedRoot, e, e.selection));
1370
- };
1371
- e.isLocalOrigin = function (origin) { return origin === e.withoutSavingOrigin || isLocalOrigin(origin); };
1372
- var handleStackItemAdded = function (_a) {
1373
- var stackItem = _a.stackItem;
1374
- stackItem.meta.set('selection', e.selection && slateRangeToRelativeRange(e.sharedRoot, e, e.selection));
1375
- stackItem.meta.set('selectionBefore', LAST_SELECTION.get(e));
1376
- };
1377
- var handleStackItemUpdated = function (_a) {
1378
- var stackItem = _a.stackItem;
1379
- stackItem.meta.set('selection', e.selection && slateRangeToRelativeRange(e.sharedRoot, e, e.selection));
1380
- };
1381
- var handleStackItemPopped = function (_a) {
1382
- var stackItem = _a.stackItem, type = _a.type;
1383
- // TODO: Change once https://github.com/yjs/yjs/issues/353 is resolved
1384
- var inverseStack = type === 'undo' ? e.undoManager.redoStack : e.undoManager.undoStack;
1385
- var inverseItem = inverseStack[inverseStack.length - 1];
1386
- if (inverseItem) {
1387
- inverseItem.meta.set('selection', stackItem.meta.get('selectionBefore'));
1388
- inverseItem.meta.set('selectionBefore', stackItem.meta.get('selection'));
1389
- }
1390
- var relativeSelection = stackItem.meta.get('selectionBefore');
1391
- if (!relativeSelection) {
1392
- return;
1393
- }
1394
- var selection = relativeRangeToSlateRange(e.sharedRoot, e, relativeSelection);
1395
- if (!selection) {
1396
- return;
1397
- }
1398
- slate.Transforms.select(e, selection);
1399
- };
1400
- var connect = e.connect, disconnect = e.disconnect;
1401
- e.connect = function () {
1402
- connect();
1403
- e.undoManager.on('stack-item-added', handleStackItemAdded);
1404
- e.undoManager.on('stack-item-popped', handleStackItemPopped);
1405
- e.undoManager.on('stack-item-updated', handleStackItemUpdated);
1406
- };
1407
- e.disconnect = function () {
1408
- e.undoManager.off('stack-item-added', handleStackItemAdded);
1409
- e.undoManager.off('stack-item-popped', handleStackItemPopped);
1410
- e.undoManager.off('stack-item-updated', handleStackItemUpdated);
1411
- disconnect();
1412
- };
1413
- e.undo = function () {
1414
- if (YjsEditor.connected(e)) {
1415
- YjsEditor.flushLocalChanges(e);
1416
- e.undoManager.undo();
1417
- }
1418
- };
1419
- e.redo = function () {
1420
- if (YjsEditor.connected(e)) {
1421
- YjsEditor.flushLocalChanges(e);
1422
- e.undoManager.redo();
1423
- }
1424
- };
1425
- return e;
1426
- };
1427
- }
1428
-
1429
- exports.CursorEditor = CursorEditor;
1430
- exports.YHistoryEditor = YHistoryEditor;
1431
- exports.YjsEditor = YjsEditor;
1432
- exports.relativePositionToSlatePoint = relativePositionToSlatePoint;
1433
- exports.relativeRangeToSlateRange = relativeRangeToSlateRange;
1434
- exports.slateNodesToInsertDelta = slateNodesToInsertDelta;
1435
- exports.slatePointToRelativePosition = slatePointToRelativePosition;
1436
- exports.slateRangeToRelativeRange = slateRangeToRelativeRange;
1437
- exports.withCursors = withCursors;
1438
- exports.withYHistory = withYHistory;
1439
- exports.withYjs = withYjs;
1440
- exports.yTextToSlateElement = yTextToSlateElement;
1441
-
1442
- }));
1
+ !function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("yjs"),require("slate")):"function"==typeof define&&define.amd?define(["exports","yjs","slate"],r):r((t="undefined"!=typeof globalThis?globalThis:t||self).WangEditorYjsModule={},t.Y,t.slate)}(this,(function(t,r,n){"use strict";function e(t){var r=Object.create(null);return t&&Object.keys(t).forEach((function(n){if("default"!==n){var e=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(r,n,e.get?e:{enumerable:!0,get:function(){return t[n]}})}})),r.default=t,Object.freeze(r)}var i,o,u=e(r),a="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},c={};function f(){if(o)return i;o=1;var t=function(t){return t&&t.Math===Math&&t};return i=t("object"==typeof globalThis&&globalThis)||t("object"==typeof window&&window)||t("object"==typeof self&&self)||t("object"==typeof a&&a)||t("object"==typeof i&&i)||function(){return this}()||Function("return this")()}var s,l,v,d,h,p,g,y,b={};function m(){return l?s:(l=1,s=function(t){try{return!!t()}catch(t){return!0}})}function w(){if(d)return v;d=1;var t=m();return v=!t((function(){return 7!==Object.defineProperty({},1,{get:function(){return 7}})[1]}))}function x(){if(p)return h;p=1;var t=m();return h=!t((function(){var t=function(){}.bind();return"function"!=typeof t||t.hasOwnProperty("prototype")}))}function O(){if(y)return g;y=1;var t=x(),r=Function.prototype.call;return g=t?r.bind(r):function(){return r.apply(r,arguments)},g}var S,E,T,j,P,R,A,C,k,L,F,_,D,M,I,z,N,W,Y,X,G,B,U,V,q,H,$,J,K,Q,Z,tt,rt,nt,et,it,ot,ut,at,ct,ft,st={};function lt(){if(S)return st;S=1;var t={}.propertyIsEnumerable,r=Object.getOwnPropertyDescriptor,n=r&&!t.call({1:2},1);return st.f=n?function(t){var n=r(this,t);return!!n&&n.enumerable}:t,st}function vt(){return T?E:(T=1,E=function(t,r){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:r}})}function dt(){if(P)return j;P=1;var t=x(),r=Function.prototype,n=r.call,e=t&&r.bind.bind(n,n);return j=t?e:function(t){return function(){return n.apply(t,arguments)}},j}function ht(){if(A)return R;A=1;var t=dt(),r=t({}.toString),n=t("".slice);return R=function(t){return n(r(t),8,-1)}}function pt(){if(k)return C;k=1;var t=dt(),r=m(),n=ht(),e=Object,i=t("".split);return C=r((function(){return!e("z").propertyIsEnumerable(0)}))?function(t){return"String"===n(t)?i(t,""):e(t)}:e}function gt(){return F?L:(F=1,L=function(t){return null==t})}function yt(){if(D)return _;D=1;var t=gt(),r=TypeError;return _=function(n){if(t(n))throw new r("Can't call method on "+n);return n}}function bt(){if(I)return M;I=1;var t=pt(),r=yt();return M=function(n){return t(r(n))}}function mt(){if(N)return z;N=1;var t="object"==typeof document&&document.all;return z=void 0===t&&void 0!==t?function(r){return"function"==typeof r||r===t}:function(t){return"function"==typeof t}}function wt(){if(Y)return W;Y=1;var t=mt();return W=function(r){return"object"==typeof r?null!==r:t(r)}}function xt(){if(G)return X;G=1;var t=f(),r=mt();return X=function(n,e){return arguments.length<2?(i=t[n],r(i)?i:void 0):t[n]&&t[n][e];var i},X}function Ot(){if(U)return B;U=1;var t=dt();return B=t({}.isPrototypeOf)}function St(){if($)return H;$=1;var t,r,n=f(),e=function(){if(q)return V;q=1;var t=f().navigator,r=t&&t.userAgent;return V=r?String(r):""}(),i=n.process,o=n.Deno,u=i&&i.versions||o&&o.version,a=u&&u.v8;return a&&(r=(t=a.split("."))[0]>0&&t[0]<4?1:+(t[0]+t[1])),!r&&e&&(!(t=e.match(/Edge\/(\d+)/))||t[1]>=74)&&(t=e.match(/Chrome\/(\d+)/))&&(r=+t[1]),H=r}function Et(){if(K)return J;K=1;var t=St(),r=m(),n=f().String;return J=!!Object.getOwnPropertySymbols&&!r((function(){var r=Symbol("symbol detection");return!n(r)||!(Object(r)instanceof Symbol)||!Symbol.sham&&t&&t<41}))}function Tt(){if(Z)return Q;Z=1;var t=Et();return Q=t&&!Symbol.sham&&"symbol"==typeof Symbol.iterator}function jt(){if(rt)return tt;rt=1;var t=xt(),r=mt(),n=Ot(),e=Tt(),i=Object;return tt=e?function(t){return"symbol"==typeof t}:function(e){var o=t("Symbol");return r(o)&&n(o.prototype,i(e))}}function Pt(){if(et)return nt;et=1;var t=String;return nt=function(r){try{return t(r)}catch(t){return"Object"}}}function Rt(){if(ot)return it;ot=1;var t=mt(),r=Pt(),n=TypeError;return it=function(e){if(t(e))return e;throw new n(r(e)+" is not a function")}}function At(){if(at)return ut;at=1;var t=Rt(),r=gt();return ut=function(n,e){var i=n[e];return r(i)?void 0:t(i)}}function Ct(){if(ft)return ct;ft=1;var t=O(),r=mt(),n=wt(),e=TypeError;return ct=function(i,o){var u,a;if("string"===o&&r(u=i.toString)&&!n(a=t(u,i)))return a;if(r(u=i.valueOf)&&!n(a=t(u,i)))return a;if("string"!==o&&r(u=i.toString)&&!n(a=t(u,i)))return a;throw new e("Can't convert object to primitive value")}}var kt,Lt,Ft,_t,Dt,Mt,It,zt,Nt,Wt,Yt,Xt,Gt,Bt,Ut,Vt,qt,Ht,$t,Jt,Kt,Qt,Zt,tr,rr={exports:{}};function nr(){return Lt?kt:(Lt=1,kt=!1)}function er(){if(_t)return Ft;_t=1;var t=f(),r=Object.defineProperty;return Ft=function(n,e){try{r(t,n,{value:e,configurable:!0,writable:!0})}catch(r){t[n]=e}return e}}function ir(){if(Dt)return rr.exports;Dt=1;var t=nr(),r=f(),n=er(),e="__core-js_shared__",i=rr.exports=r[e]||n(e,{});return(i.versions||(i.versions=[])).push({version:"3.38.1",mode:t?"pure":"global",copyright:"© 2014-2024 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.38.1/LICENSE",source:"https://github.com/zloirock/core-js"}),rr.exports}function or(){if(It)return Mt;It=1;var t=ir();return Mt=function(r,n){return t[r]||(t[r]=n||{})}}function ur(){if(Nt)return zt;Nt=1;var t=yt(),r=Object;return zt=function(n){return r(t(n))}}function ar(){if(Yt)return Wt;Yt=1;var t=dt(),r=ur(),n=t({}.hasOwnProperty);return Wt=Object.hasOwn||function(t,e){return n(r(t),e)}}function cr(){if(Gt)return Xt;Gt=1;var t=dt(),r=0,n=Math.random(),e=t(1..toString);return Xt=function(t){return"Symbol("+(void 0===t?"":t)+")_"+e(++r+n,36)}}function fr(){if(Ut)return Bt;Ut=1;var t=f(),r=or(),n=ar(),e=cr(),i=Et(),o=Tt(),u=t.Symbol,a=r("wks"),c=o?u.for||u:u&&u.withoutSetter||e;return Bt=function(t){return n(a,t)||(a[t]=i&&n(u,t)?u[t]:c("Symbol."+t)),a[t]}}function sr(){if(qt)return Vt;qt=1;var t=O(),r=wt(),n=jt(),e=At(),i=Ct(),o=fr(),u=TypeError,a=o("toPrimitive");return Vt=function(o,c){if(!r(o)||n(o))return o;var f,s=e(o,a);if(s){if(void 0===c&&(c="default"),f=t(s,o,c),!r(f)||n(f))return f;throw new u("Can't convert object to primitive value")}return void 0===c&&(c="number"),i(o,c)}}function lr(){if($t)return Ht;$t=1;var t=sr(),r=jt();return Ht=function(n){var e=t(n,"string");return r(e)?e:e+""}}function vr(){if(Kt)return Jt;Kt=1;var t=f(),r=wt(),n=t.document,e=r(n)&&r(n.createElement);return Jt=function(t){return e?n.createElement(t):{}}}function dr(){if(Zt)return Qt;Zt=1;var t=w(),r=m(),n=vr();return Qt=!t&&!r((function(){return 7!==Object.defineProperty(n("div"),"a",{get:function(){return 7}}).a}))}function hr(){if(tr)return b;tr=1;var t=w(),r=O(),n=lt(),e=vt(),i=bt(),o=lr(),u=ar(),a=dr(),c=Object.getOwnPropertyDescriptor;return b.f=t?c:function(t,f){if(t=i(t),f=o(f),a)try{return c(t,f)}catch(t){}if(u(t,f))return e(!r(n.f,t,f),t[f])},b}var pr,gr,yr,br,mr,wr,xr,Or={};function Sr(){if(gr)return pr;gr=1;var t=w(),r=m();return pr=t&&r((function(){return 42!==Object.defineProperty((function(){}),"prototype",{value:42,writable:!1}).prototype}))}function Er(){if(br)return yr;br=1;var t=wt(),r=String,n=TypeError;return yr=function(e){if(t(e))return e;throw new n(r(e)+" is not an object")}}function Tr(){if(mr)return Or;mr=1;var t=w(),r=dr(),n=Sr(),e=Er(),i=lr(),o=TypeError,u=Object.defineProperty,a=Object.getOwnPropertyDescriptor,c="enumerable",f="configurable",s="writable";return Or.f=t?n?function(t,r,n){if(e(t),r=i(r),e(n),"function"==typeof t&&"prototype"===r&&"value"in n&&s in n&&!n[s]){var o=a(t,r);o&&o[s]&&(t[r]=n.value,n={configurable:f in n?n[f]:o[f],enumerable:c in n?n[c]:o[c],writable:!1})}return u(t,r,n)}:u:function(t,n,a){if(e(t),n=i(n),e(a),r)try{return u(t,n,a)}catch(t){}if("get"in a||"set"in a)throw new o("Accessors not supported");return"value"in a&&(t[n]=a.value),t},Or}function jr(){if(xr)return wr;xr=1;var t=w(),r=Tr(),n=vt();return wr=t?function(t,e,i){return r.f(t,e,n(1,i))}:function(t,r,n){return t[r]=n,t}}var Pr,Rr,Ar,Cr,kr,Lr,Fr,_r,Dr,Mr,Ir,zr,Nr,Wr,Yr,Xr={exports:{}};function Gr(){if(Rr)return Pr;Rr=1;var t=w(),r=ar(),n=Function.prototype,e=t&&Object.getOwnPropertyDescriptor,i=r(n,"name"),o=i&&"something"===function(){}.name,u=i&&(!t||t&&e(n,"name").configurable);return Pr={EXISTS:i,PROPER:o,CONFIGURABLE:u}}function Br(){if(Cr)return Ar;Cr=1;var t=dt(),r=mt(),n=ir(),e=t(Function.toString);return r(n.inspectSource)||(n.inspectSource=function(t){return e(t)}),Ar=n.inspectSource}function Ur(){if(Lr)return kr;Lr=1;var t=f(),r=mt(),n=t.WeakMap;return kr=r(n)&&/native code/.test(String(n))}function Vr(){if(_r)return Fr;_r=1;var t=or(),r=cr(),n=t("keys");return Fr=function(t){return n[t]||(n[t]=r(t))}}function qr(){return Mr?Dr:(Mr=1,Dr={})}function Hr(){if(zr)return Ir;zr=1;var t,r,n,e=Ur(),i=f(),o=wt(),u=jr(),a=ar(),c=ir(),s=Vr(),l=qr(),v="Object already initialized",d=i.TypeError,h=i.WeakMap;if(e||c.state){var p=c.state||(c.state=new h);p.get=p.get,p.has=p.has,p.set=p.set,t=function(t,r){if(p.has(t))throw new d(v);return r.facade=t,p.set(t,r),r},r=function(t){return p.get(t)||{}},n=function(t){return p.has(t)}}else{var g=s("state");l[g]=!0,t=function(t,r){if(a(t,g))throw new d(v);return r.facade=t,u(t,g,r),r},r=function(t){return a(t,g)?t[g]:{}},n=function(t){return a(t,g)}}return Ir={set:t,get:r,has:n,enforce:function(e){return n(e)?r(e):t(e,{})},getterFor:function(t){return function(n){var e;if(!o(n)||(e=r(n)).type!==t)throw new d("Incompatible receiver, "+t+" required");return e}}}}function $r(){if(Nr)return Xr.exports;Nr=1;var t=dt(),r=m(),n=mt(),e=ar(),i=w(),o=Gr().CONFIGURABLE,u=Br(),a=Hr(),c=a.enforce,f=a.get,s=String,l=Object.defineProperty,v=t("".slice),d=t("".replace),h=t([].join),p=i&&!r((function(){return 8!==l((function(){}),"length",{value:8}).length})),g=String(String).split("String"),y=Xr.exports=function(t,r,n){"Symbol("===v(s(r),0,7)&&(r="["+d(s(r),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),n&&n.getter&&(r="get "+r),n&&n.setter&&(r="set "+r),(!e(t,"name")||o&&t.name!==r)&&(i?l(t,"name",{value:r,configurable:!0}):t.name=r),p&&n&&e(n,"arity")&&t.length!==n.arity&&l(t,"length",{value:n.arity});try{n&&e(n,"constructor")&&n.constructor?i&&l(t,"prototype",{writable:!1}):t.prototype&&(t.prototype=void 0)}catch(t){}var u=c(t);return e(u,"source")||(u.source=h(g,"string"==typeof r?r:"")),t};return Function.prototype.toString=y((function(){return n(this)&&f(this).source||u(this)}),"toString"),Xr.exports}function Jr(){if(Yr)return Wr;Yr=1;var t=mt(),r=Tr(),n=$r(),e=er();return Wr=function(i,o,u,a){a||(a={});var c=a.enumerable,f=void 0!==a.name?a.name:o;if(t(u)&&n(u,f,a),a.global)c?i[o]=u:e(o,u);else{try{a.unsafe?i[o]&&(c=!0):delete i[o]}catch(t){}c?i[o]=u:r.f(i,o,{value:u,enumerable:!1,configurable:!a.nonConfigurable,writable:!a.nonWritable})}return i}}var Kr,Qr,Zr,tn,rn,nn,en,on,un,an,cn,fn,sn,ln,vn,dn,hn,pn={};function gn(){if(tn)return Zr;tn=1;var t=function(){if(Qr)return Kr;Qr=1;var t=Math.ceil,r=Math.floor;return Kr=Math.trunc||function(n){var e=+n;return(e>0?r:t)(e)}}();return Zr=function(r){var n=+r;return n!=n||0===n?0:t(n)}}function yn(){if(nn)return rn;nn=1;var t=gn(),r=Math.max,n=Math.min;return rn=function(e,i){var o=t(e);return o<0?r(o+i,0):n(o,i)}}function bn(){if(on)return en;on=1;var t=gn(),r=Math.min;return en=function(n){var e=t(n);return e>0?r(e,9007199254740991):0}}function mn(){if(an)return un;an=1;var t=bn();return un=function(r){return t(r.length)}}function wn(){if(fn)return cn;fn=1;var t=bt(),r=yn(),n=mn(),e=function(e){return function(i,o,u){var a=t(i),c=n(a);if(0===c)return!e&&-1;var f,s=r(u,c);if(e&&o!=o){for(;c>s;)if((f=a[s++])!=f)return!0}else for(;c>s;s++)if((e||s in a)&&a[s]===o)return e||s||0;return!e&&-1}};return cn={includes:e(!0),indexOf:e(!1)}}function xn(){if(ln)return sn;ln=1;var t=dt(),r=ar(),n=bt(),e=wn().indexOf,i=qr(),o=t([].push);return sn=function(t,u){var a,c=n(t),f=0,s=[];for(a in c)!r(i,a)&&r(c,a)&&o(s,a);for(;u.length>f;)r(c,a=u[f++])&&(~e(s,a)||o(s,a));return s}}function On(){return dn?vn:(dn=1,vn=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"])}function Sn(){if(hn)return pn;hn=1;var t=xn(),r=On().concat("length","prototype");return pn.f=Object.getOwnPropertyNames||function(n){return t(n,r)},pn}var En,Tn,jn,Pn,Rn,An,Cn,kn,Ln,Fn,_n,Dn,Mn,In,zn,Nn,Wn,Yn,Xn,Gn,Bn,Un,Vn,qn,Hn,$n,Jn,Kn,Qn,Zn,te={};function re(){return En||(En=1,te.f=Object.getOwnPropertySymbols),te}function ne(){if(jn)return Tn;jn=1;var t=xt(),r=dt(),n=Sn(),e=re(),i=Er(),o=r([].concat);return Tn=t("Reflect","ownKeys")||function(t){var r=n.f(i(t)),u=e.f;return u?o(r,u(t)):r}}function ee(){if(Rn)return Pn;Rn=1;var t=ar(),r=ne(),n=hr(),e=Tr();return Pn=function(i,o,u){for(var a=r(o),c=e.f,f=n.f,s=0;s<a.length;s++){var l=a[s];t(i,l)||u&&t(u,l)||c(i,l,f(o,l))}}}function ie(){if(Cn)return An;Cn=1;var t=m(),r=mt(),n=/#|\.prototype\./,e=function(n,e){var c=o[i(n)];return c===a||c!==u&&(r(e)?t(e):!!e)},i=e.normalize=function(t){return String(t).replace(n,".").toLowerCase()},o=e.data={},u=e.NATIVE="N",a=e.POLYFILL="P";return An=e}function oe(){if(Ln)return kn;Ln=1;var t=f(),r=hr().f,n=jr(),e=Jr(),i=er(),o=ee(),u=ie();return kn=function(a,c){var f,s,l,v,d,h=a.target,p=a.global,g=a.stat;if(f=p?t:g?t[h]||i(h,{}):t[h]&&t[h].prototype)for(s in c){if(v=c[s],l=a.dontCallGetSet?(d=r(f,s))&&d.value:f[s],!u(p?s:h+(g?".":"#")+s,a.forced)&&void 0!==l){if(typeof v==typeof l)continue;o(v,l)}(a.sham||l&&l.sham)&&n(v,"sham",!0),e(f,s,v,a)}}}function ue(){if(_n)return Fn;_n=1;var t=ht(),r=dt();return Fn=function(n){if("Function"===t(n))return r(n)}}function ae(){if(Mn)return Dn;Mn=1;var t=ue(),r=Rt(),n=x(),e=t(t.bind);return Dn=function(t,i){return r(t),void 0===i?t:n?e(t,i):function(){return t.apply(i,arguments)}},Dn}function ce(){if(zn)return In;zn=1;var t=ht();return In=Array.isArray||function(r){return"Array"===t(r)}}function fe(){if(Wn)return Nn;Wn=1;var t={};return t[fr()("toStringTag")]="z",Nn="[object z]"===String(t)}function se(){if(Xn)return Yn;Xn=1;var t=fe(),r=mt(),n=ht(),e=fr()("toStringTag"),i=Object,o="Arguments"===n(function(){return arguments}());return Yn=t?n:function(t){var u,a,c;return void 0===t?"Undefined":null===t?"Null":"string"==typeof(a=function(t,r){try{return t[r]}catch(t){}}(u=i(t),e))?a:o?n(u):"Object"===(c=n(u))&&r(u.callee)?"Arguments":c}}function le(){if(Bn)return Gn;Bn=1;var t=dt(),r=m(),n=mt(),e=se(),i=xt(),o=Br(),u=function(){},a=i("Reflect","construct"),c=/^\s*(?:class|function)\b/,f=t(c.exec),s=!c.test(u),l=function(t){if(!n(t))return!1;try{return a(u,[],t),!0}catch(t){return!1}},v=function(t){if(!n(t))return!1;switch(e(t)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return s||!!f(c,o(t))}catch(t){return!0}};return v.sham=!0,Gn=!a||r((function(){var t;return l(l.call)||!l(Object)||!l((function(){t=!0}))||t}))?v:l}function ve(){if(Vn)return Un;Vn=1;var t=ce(),r=le(),n=wt(),e=fr()("species"),i=Array;return Un=function(o){var u;return t(o)&&(u=o.constructor,(r(u)&&(u===i||t(u.prototype))||n(u)&&null===(u=u[e]))&&(u=void 0)),void 0===u?i:u}}function de(){if(Hn)return qn;Hn=1;var t=ve();return qn=function(r,n){return new(t(r))(0===n?0:n)}}function he(){if(Jn)return $n;Jn=1;var t=ae(),r=dt(),n=pt(),e=ur(),i=mn(),o=de(),u=r([].push),a=function(r){var a=1===r,c=2===r,f=3===r,s=4===r,l=6===r,v=7===r,d=5===r||l;return function(h,p,g,y){for(var b,m,w=e(h),x=n(w),O=i(x),S=t(p,g),E=0,T=y||o,j=a?T(h,O):c||v?T(h,0):void 0;O>E;E++)if((d||E in x)&&(m=S(b=x[E],E,w),r))if(a)j[E]=m;else if(m)switch(r){case 3:return!0;case 5:return b;case 6:return E;case 2:u(j,b)}else switch(r){case 4:return!1;case 7:u(j,b)}return l?-1:f||s?s:j}};return $n={forEach:a(0),map:a(1),filter:a(2),some:a(3),every:a(4),find:a(5),findIndex:a(6),filterReject:a(7)}}function pe(){if(Qn)return Kn;Qn=1;var t=m(),r=fr(),n=St(),e=r("species");return Kn=function(r){return n>=51||!t((function(){var t=[];return(t.constructor={})[e]=function(){return{foo:1}},1!==t[r](Boolean).foo}))}}!function(){if(Zn)return c;Zn=1;var t=oe(),r=he().filter;t({target:"Array",proto:!0,forced:!pe()("filter")},{filter:function(t){return r(this,t,arguments.length>1?arguments[1]:void 0)}})}();var ge,ye,be,me,we,xe,Oe,Se,Ee,Te,je,Pe,Re,Ae,Ce,ke,Le,Fe,_e,De={};function Me(){if(ye)return ge;ye=1;var t=O(),r=Er(),n=At();return ge=function(e,i,o){var u,a;r(e);try{if(!(u=n(e,"return"))){if("throw"===i)throw o;return o}u=t(u,e)}catch(t){a=!0,u=t}if("throw"===i)throw o;if(a)throw u;return r(u),o}}function Ie(){if(me)return be;me=1;var t=Er(),r=Me();return be=function(n,e,i,o){try{return o?e(t(i)[0],i[1]):e(i)}catch(t){r(n,"throw",t)}}}function ze(){return xe?we:(xe=1,we={})}function Ne(){if(Se)return Oe;Se=1;var t=fr(),r=ze(),n=t("iterator"),e=Array.prototype;return Oe=function(t){return void 0!==t&&(r.Array===t||e[n]===t)}}function We(){if(Te)return Ee;Te=1;var t=w(),r=Tr(),n=vt();return Ee=function(e,i,o){t?r.f(e,i,n(0,o)):e[i]=o}}function Ye(){if(Pe)return je;Pe=1;var t=se(),r=At(),n=gt(),e=ze(),i=fr()("iterator");return je=function(o){if(!n(o))return r(o,i)||r(o,"@@iterator")||e[t(o)]}}function Xe(){if(Ae)return Re;Ae=1;var t=O(),r=Rt(),n=Er(),e=Pt(),i=Ye(),o=TypeError;return Re=function(u,a){var c=arguments.length<2?i(u):a;if(r(c))return n(t(c,u));throw new o(e(u)+" is not iterable")},Re}function Ge(){if(Fe)return Le;Fe=1;var t=fr()("iterator"),r=!1;try{var n=0,e={next:function(){return{done:!!n++}},return:function(){r=!0}};e[t]=function(){return this},Array.from(e,(function(){throw 2}))}catch(t){}return Le=function(n,e){try{if(!e&&!r)return!1}catch(t){return!1}var i=!1;try{var o={};o[t]=function(){return{next:function(){return{done:i=!0}}}},n(o)}catch(t){}return i}}!function(){if(_e)return De;_e=1;var t=oe(),r=function(){if(ke)return Ce;ke=1;var t=ae(),r=O(),n=ur(),e=Ie(),i=Ne(),o=le(),u=mn(),a=We(),c=Xe(),f=Ye(),s=Array;return Ce=function(l){var v=n(l),d=o(this),h=arguments.length,p=h>1?arguments[1]:void 0,g=void 0!==p;g&&(p=t(p,h>2?arguments[2]:void 0));var y,b,m,w,x,O,S=f(v),E=0;if(!S||this===s&&i(S))for(y=u(v),b=d?new this(y):s(y);y>E;E++)O=g?p(v[E],E):v[E],a(b,E,O);else for(b=d?new this:[],x=(w=c(v,S)).next;!(m=r(x,w)).done;E++)O=g?e(w,p,[m.value,E],!0):m.value,a(b,E,O);return b.length=E,b},Ce}();t({target:"Array",stat:!0,forced:!Ge()((function(t){Array.from(t)}))},{from:r})}();var Be,Ue,Ve,qe,He,$e,Je,Ke,Qe,Ze,ti,ri,ni,ei,ii,oi,ui,ai,ci,fi,si,li,vi,di,hi,pi,gi,yi,bi,mi,wi,xi,Oi,Si={};function Ei(){if(Ue)return Be;Ue=1;var t=xn(),r=On();return Be=Object.keys||function(n){return t(n,r)}}function Ti(){if(Ve)return Si;Ve=1;var t=w(),r=Sr(),n=Tr(),e=Er(),i=bt(),o=Ei();return Si.f=t&&!r?Object.defineProperties:function(t,r){e(t);for(var u,a=i(r),c=o(r),f=c.length,s=0;f>s;)n.f(t,u=c[s++],a[u]);return t},Si}function ji(){if(He)return qe;He=1;var t=xt();return qe=t("document","documentElement")}function Pi(){if(Je)return $e;Je=1;var t,r=Er(),n=Ti(),e=On(),i=qr(),o=ji(),u=vr(),a=Vr(),c="prototype",f="script",s=a("IE_PROTO"),l=function(){},v=function(t){return"<"+f+">"+t+"</"+f+">"},d=function(t){t.write(v("")),t.close();var r=t.parentWindow.Object;return t=null,r},h=function(){try{t=new ActiveXObject("htmlfile")}catch(t){}var r,n,i;h="undefined"!=typeof document?document.domain&&t?d(t):(n=u("iframe"),i="java"+f+":",n.style.display="none",o.appendChild(n),n.src=String(i),(r=n.contentWindow.document).open(),r.write(v("document.F=Object")),r.close(),r.F):d(t);for(var a=e.length;a--;)delete h[c][e[a]];return h()};return i[s]=!0,$e=Object.create||function(t,e){var i;return null!==t?(l[c]=r(t),i=new l,l[c]=null,i[s]=t):i=h(),void 0===e?i:n.f(i,e)}}function Ri(){if(Qe)return Ke;Qe=1;var t=fr(),r=Pi(),n=Tr().f,e=t("unscopables"),i=Array.prototype;return void 0===i[e]&&n(i,e,{configurable:!0,value:r(null)}),Ke=function(t){i[e][t]=!0}}function Ai(){if(ni)return ri;ni=1;var t=ar(),r=mt(),n=ur(),e=Vr(),i=function(){if(ti)return Ze;ti=1;var t=m();return Ze=!t((function(){function t(){}return t.prototype.constructor=null,Object.getPrototypeOf(new t)!==t.prototype}))}(),o=e("IE_PROTO"),u=Object,a=u.prototype;return ri=i?u.getPrototypeOf:function(e){var i=n(e);if(t(i,o))return i[o];var c=i.constructor;return r(c)&&i instanceof c?c.prototype:i instanceof u?a:null}}function Ci(){if(ii)return ei;ii=1;var t,r,n,e=m(),i=mt(),o=wt(),u=Pi(),a=Ai(),c=Jr(),f=fr(),s=nr(),l=f("iterator"),v=!1;return[].keys&&("next"in(n=[].keys())?(r=a(a(n)))!==Object.prototype&&(t=r):v=!0),!o(t)||e((function(){var r={};return t[l].call(r)!==r}))?t={}:s&&(t=u(t)),i(t[l])||c(t,l,(function(){return this})),ei={IteratorPrototype:t,BUGGY_SAFARI_ITERATORS:v}}function ki(){if(ui)return oi;ui=1;var t=Tr().f,r=ar(),n=fr()("toStringTag");return oi=function(e,i,o){e&&!o&&(e=e.prototype),e&&!r(e,n)&&t(e,n,{configurable:!0,value:i})}}function Li(){if(vi)return li;vi=1;var t=wt();return li=function(r){return t(r)||null===r}}function Fi(){if(hi)return di;hi=1;var t=Li(),r=String,n=TypeError;return di=function(e){if(t(e))return e;throw new n("Can't set "+r(e)+" as a prototype")}}function _i(){if(gi)return pi;gi=1;var t=function(){if(si)return fi;si=1;var t=dt(),r=Rt();return fi=function(n,e,i){try{return t(r(Object.getOwnPropertyDescriptor(n,e)[i]))}catch(t){}}}(),r=wt(),n=yt(),e=Fi();return pi=Object.setPrototypeOf||("__proto__"in{}?function(){var i,o=!1,u={};try{(i=t(Object.prototype,"__proto__","set"))(u,[]),o=u instanceof Array}catch(t){}return function(t,u){return n(t),e(u),r(t)?(o?i(t,u):t.__proto__=u,t):t}}():void 0)}function Di(){if(bi)return yi;bi=1;var t=oe(),r=O(),n=nr(),e=Gr(),i=mt(),o=function(){if(ci)return ai;ci=1;var t=Ci().IteratorPrototype,r=Pi(),n=vt(),e=ki(),i=ze(),o=function(){return this};return ai=function(u,a,c,f){var s=a+" Iterator";return u.prototype=r(t,{next:n(+!f,c)}),e(u,s,!1,!0),i[s]=o,u}}(),u=Ai(),a=_i(),c=ki(),f=jr(),s=Jr(),l=fr(),v=ze(),d=Ci(),h=e.PROPER,p=e.CONFIGURABLE,g=d.IteratorPrototype,y=d.BUGGY_SAFARI_ITERATORS,b=l("iterator"),m="keys",w="values",x="entries",S=function(){return this};return yi=function(e,l,d,O,E,T,j){o(d,l,O);var P,R,A,C=function(t){if(t===E&&D)return D;if(!y&&t&&t in F)return F[t];switch(t){case m:case w:case x:return function(){return new d(this,t)}}return function(){return new d(this)}},k=l+" Iterator",L=!1,F=e.prototype,_=F[b]||F["@@iterator"]||E&&F[E],D=!y&&_||C(E),M="Array"===l&&F.entries||_;if(M&&(P=u(M.call(new e)))!==Object.prototype&&P.next&&(n||u(P)===g||(a?a(P,g):i(P[b])||s(P,b,S)),c(P,k,!0,!0),n&&(v[k]=S)),h&&E===w&&_&&_.name!==w&&(!n&&p?f(F,"name",w):(L=!0,D=function(){return r(_,this)})),E)if(R={values:C(w),keys:T?D:C(m),entries:C(x)},j)for(A in R)(y||L||!(A in F))&&s(F,A,R[A]);else t({target:l,proto:!0,forced:y||L},R);return n&&!j||F[b]===D||s(F,b,D,{name:E}),v[l]=D,R}}function Mi(){return wi?mi:(wi=1,mi=function(t,r){return{value:t,done:r}})}function Ii(){if(Oi)return xi;Oi=1;var t=bt(),r=Ri(),n=ze(),e=Hr(),i=Tr().f,o=Di(),u=Mi(),a=nr(),c=w(),f="Array Iterator",s=e.set,l=e.getterFor(f);xi=o(Array,"Array",(function(r,n){s(this,{type:f,target:t(r),index:0,kind:n})}),(function(){var t=l(this),r=t.target,n=t.index++;if(!r||n>=r.length)return t.target=null,u(void 0,!0);switch(t.kind){case"keys":return u(n,!1);case"values":return u(r[n],!1)}return u([n,r[n]],!1)}),"values");var v=n.Arguments=n.Array;if(r("keys"),r("values"),r("entries"),!a&&c&&"values"!==v.name)try{i(v,"name",{value:"values"})}catch(t){}return xi}Ii();var zi,Ni,Wi,Yi={};function Xi(){if(Ni)return zi;Ni=1;var t=ae(),r=O(),n=Er(),e=Pt(),i=Ne(),o=mn(),u=Ot(),a=Xe(),c=Ye(),f=Me(),s=TypeError,l=function(t,r){this.stopped=t,this.result=r},v=l.prototype;return zi=function(d,h,p){var g,y,b,m,w,x,O,S=p&&p.that,E=!(!p||!p.AS_ENTRIES),T=!(!p||!p.IS_RECORD),j=!(!p||!p.IS_ITERATOR),P=!(!p||!p.INTERRUPTED),R=t(h,S),A=function(t){return g&&f(g,"normal",t),new l(!0,t)},C=function(t){return E?(n(t),P?R(t[0],t[1],A):R(t[0],t[1])):P?R(t,A):R(t)};if(T)g=d.iterator;else if(j)g=d;else{if(!(y=c(d)))throw new s(e(d)+" is not iterable");if(i(y)){for(b=0,m=o(d);m>b;b++)if((w=C(d[b]))&&u(v,w))return w;return new l(!1)}g=a(d,y)}for(x=T?d.next:g.next;!(O=r(x,g)).done;){try{w=C(O.value)}catch(t){f(g,"throw",t)}if("object"==typeof w&&w&&u(v,w))return w}return new l(!1)}}!function(){if(Wi)return Yi;Wi=1;var t=oe(),r=Xi(),n=We();t({target:"Object",stat:!0},{fromEntries:function(t){var e={};return r(t,(function(t,r){n(e,t,r)}),{AS_ENTRIES:!0}),e}})}();var Gi,Bi,Ui,Vi={};!function(){if(Ui)return Vi;Ui=1;var t=fe(),r=Jr(),n=function(){if(Bi)return Gi;Bi=1;var t=fe(),r=se();return Gi=t?{}.toString:function(){return"[object "+r(this)+"]"}}();t||r(Object.prototype,"toString",n,{unsafe:!0})}();var qi,Hi,$i,Ji,Ki,Qi,Zi,to,ro,no,eo,io,oo,uo,ao,co,fo,so,lo,vo,ho,po,go,yo,bo,mo,wo={exports:{}},xo={};function Oo(){if(Hi)return qi;Hi=1;var t=dt();return qi=t([].slice)}function So(){if($i)return xo;$i=1;var t=ht(),r=bt(),n=Sn().f,e=Oo(),i="object"==typeof window&&window&&Object.getOwnPropertyNames?Object.getOwnPropertyNames(window):[];return xo.f=function(o){return i&&"Window"===t(o)?function(t){try{return n(t)}catch(t){return e(i)}}(o):n(r(o))},xo}function Eo(){if(Zi)return Qi;Zi=1;var t=m(),r=wt(),n=ht(),e=function(){if(Ki)return Ji;Ki=1;var t=m();return Ji=t((function(){if("function"==typeof ArrayBuffer){var t=new ArrayBuffer(8);Object.isExtensible(t)&&Object.defineProperty(t,"a",{value:8})}}))}(),i=Object.isExtensible,o=t((function(){}));return Qi=o||e?function(t){return!!r(t)&&((!e||"ArrayBuffer"!==n(t))&&(!i||i(t)))}:i}function To(){if(ro)return to;ro=1;var t=m();return to=!t((function(){return Object.isExtensible(Object.preventExtensions({}))}))}function jo(){if(no)return wo.exports;no=1;var t=oe(),r=dt(),n=qr(),e=wt(),i=ar(),o=Tr().f,u=Sn(),a=So(),c=Eo(),f=cr(),s=To(),l=!1,v=f("meta"),d=0,h=function(t){o(t,v,{value:{objectID:"O"+d++,weakData:{}}})},p=wo.exports={enable:function(){p.enable=function(){},l=!0;var n=u.f,e=r([].splice),i={};i[v]=1,n(i).length&&(u.f=function(t){for(var r=n(t),i=0,o=r.length;i<o;i++)if(r[i]===v){e(r,i,1);break}return r},t({target:"Object",stat:!0,forced:!0},{getOwnPropertyNames:a.f}))},fastKey:function(t,r){if(!e(t))return"symbol"==typeof t?t:("string"==typeof t?"S":"P")+t;if(!i(t,v)){if(!c(t))return"F";if(!r)return"E";h(t)}return t[v].objectID},getWeakData:function(t,r){if(!i(t,v)){if(!c(t))return!0;if(!r)return!1;h(t)}return t[v].weakData},onFreeze:function(t){return s&&l&&c(t)&&!i(t,v)&&h(t),t}};return n[v]=!0,wo.exports}function Po(){if(io)return eo;io=1;var t=Ot(),r=TypeError;return eo=function(n,e){if(t(e,n))return n;throw new r("Incorrect invocation")}}function Ro(){if(uo)return oo;uo=1;var t=mt(),r=wt(),n=_i();return oo=function(e,i,o){var u,a;return n&&t(u=i.constructor)&&u!==o&&r(a=u.prototype)&&a!==o.prototype&&n(e,a),e}}function Ao(){if(co)return ao;co=1;var t=oe(),r=f(),n=dt(),e=ie(),i=Jr(),o=jo(),u=Xi(),a=Po(),c=mt(),s=gt(),l=wt(),v=m(),d=Ge(),h=ki(),p=Ro();return ao=function(f,g,y){var b=-1!==f.indexOf("Map"),m=-1!==f.indexOf("Weak"),w=b?"set":"add",x=r[f],O=x&&x.prototype,S=x,E={},T=function(t){var r=n(O[t]);i(O,t,"add"===t?function(t){return r(this,0===t?0:t),this}:"delete"===t?function(t){return!(m&&!l(t))&&r(this,0===t?0:t)}:"get"===t?function(t){return m&&!l(t)?void 0:r(this,0===t?0:t)}:"has"===t?function(t){return!(m&&!l(t))&&r(this,0===t?0:t)}:function(t,n){return r(this,0===t?0:t,n),this})};if(e(f,!c(x)||!(m||O.forEach&&!v((function(){(new x).entries().next()})))))S=y.getConstructor(g,f,b,w),o.enable();else if(e(f,!0)){var j=new S,P=j[w](m?{}:-0,1)!==j,R=v((function(){j.has(1)})),A=d((function(t){new x(t)})),C=!m&&v((function(){for(var t=new x,r=5;r--;)t[w](r,r);return!t.has(-0)}));A||((S=g((function(t,r){a(t,O);var n=p(new x,t,S);return s(r)||u(r,n[w],{that:n,AS_ENTRIES:b}),n}))).prototype=O,O.constructor=S),(R||C)&&(T("delete"),T("has"),b&&T("get")),(C||P)&&T(w),m&&O.clear&&delete O.clear}return E[f]=S,t({global:!0,constructor:!0,forced:S!==x},E),h(S,f),m||y.setStrong(S,f,b),S}}function Co(){if(so)return fo;so=1;var t=$r(),r=Tr();return fo=function(n,e,i){return i.get&&t(i.get,e,{getter:!0}),i.set&&t(i.set,e,{setter:!0}),r.f(n,e,i)}}function ko(){if(vo)return lo;vo=1;var t=Jr();return lo=function(r,n,e){for(var i in n)t(r,i,n[i],e);return r}}function Lo(){if(po)return ho;po=1;var t=xt(),r=Co(),n=fr(),e=w(),i=n("species");return ho=function(n){var o=t(n);e&&o&&!o[i]&&r(o,i,{configurable:!0,get:function(){return this}})}}mo||(mo=1,bo||(bo=1,Ao()("Set",(function(t){return function(){return t(this,arguments.length?arguments[0]:void 0)}}),function(){if(yo)return go;yo=1;var t=Pi(),r=Co(),n=ko(),e=ae(),i=Po(),o=gt(),u=Xi(),a=Di(),c=Mi(),f=Lo(),s=w(),l=jo().fastKey,v=Hr(),d=v.set,h=v.getterFor;return go={getConstructor:function(a,c,f,v){var p=a((function(r,n){i(r,g),d(r,{type:c,index:t(null),first:null,last:null,size:0}),s||(r.size=0),o(n)||u(n,r[v],{that:r,AS_ENTRIES:f})})),g=p.prototype,y=h(c),b=function(t,r,n){var e,i,o=y(t),u=m(t,r);return u?u.value=n:(o.last=u={index:i=l(r,!0),key:r,value:n,previous:e=o.last,next:null,removed:!1},o.first||(o.first=u),e&&(e.next=u),s?o.size++:t.size++,"F"!==i&&(o.index[i]=u)),t},m=function(t,r){var n,e=y(t),i=l(r);if("F"!==i)return e.index[i];for(n=e.first;n;n=n.next)if(n.key===r)return n};return n(g,{clear:function(){for(var r=y(this),n=r.first;n;)n.removed=!0,n.previous&&(n.previous=n.previous.next=null),n=n.next;r.first=r.last=null,r.index=t(null),s?r.size=0:this.size=0},delete:function(t){var r=this,n=y(r),e=m(r,t);if(e){var i=e.next,o=e.previous;delete n.index[e.index],e.removed=!0,o&&(o.next=i),i&&(i.previous=o),n.first===e&&(n.first=i),n.last===e&&(n.last=o),s?n.size--:r.size--}return!!e},forEach:function(t){for(var r,n=y(this),i=e(t,arguments.length>1?arguments[1]:void 0);r=r?r.next:n.first;)for(i(r.value,r.key,this);r&&r.removed;)r=r.previous},has:function(t){return!!m(this,t)}}),n(g,f?{get:function(t){var r=m(this,t);return r&&r.value},set:function(t,r){return b(this,0===t?0:t,r)}}:{add:function(t){return b(this,t=0===t?0:t,t)}}),s&&r(g,"size",{configurable:!0,get:function(){return y(this).size}}),p},setStrong:function(t,r,n){var e=r+" Iterator",i=h(r),o=h(e);a(t,r,(function(t,r){d(this,{type:e,target:t,state:i(t),kind:r,last:null})}),(function(){for(var t=o(this),r=t.kind,n=t.last;n&&n.removed;)n=n.previous;return t.target&&(t.last=n=n?n.next:t.state.first)?c("keys"===r?n.key:"values"===r?n.value:[n.key,n.value],!1):(t.target=null,c(void 0,!0))}),n?"entries":"values",!n,!0),f(r)}},go}())));var Fo,_o,Do,Mo,Io,zo={};function No(){if(_o)return Fo;_o=1;var t=se(),r=String;return Fo=function(n){if("Symbol"===t(n))throw new TypeError("Cannot convert a Symbol value to a string");return r(n)}}!function(){if(Io)return zo;Io=1;var t=function(){if(Mo)return Do;Mo=1;var t=dt(),r=gn(),n=No(),e=yt(),i=t("".charAt),o=t("".charCodeAt),u=t("".slice),a=function(t){return function(a,c){var f,s,l=n(e(a)),v=r(c),d=l.length;return v<0||v>=d?t?"":void 0:(f=o(l,v))<55296||f>56319||v+1===d||(s=o(l,v+1))<56320||s>57343?t?i(l,v):f:t?u(l,v,v+2):s-56320+(f-55296<<10)+65536}};return Do={codeAt:a(!1),charAt:a(!0)}}().charAt,r=No(),n=Hr(),e=Di(),i=Mi(),o="String Iterator",u=n.set,a=n.getterFor(o);e(String,"String",(function(t){u(this,{type:o,string:r(t),index:0})}),(function(){var r,n=a(this),e=n.string,o=n.index;return o>=e.length?i(void 0,!0):(r=t(e,o),n.index+=r.length,i(r,!1))}))}();var Wo,Yo,Xo,Go,Bo,Uo={};!function(){if(Bo)return Uo;Bo=1;var t=oe(),r=function(){if(Yo)return Wo;Yo=1;var t=dt(),r=yt(),n=No(),e=/"/g,i=t("".replace);return Wo=function(t,o,u,a){var c=n(r(t)),f="<"+o;return""!==u&&(f+=" "+u+'="'+i(n(a),e,"&quot;")+'"'),f+">"+c+"</"+o+">"}}(),n=function(){if(Go)return Xo;Go=1;var t=m();return Xo=function(r){return t((function(){var t=""[r]('"');return t!==t.toLowerCase()||t.split('"').length>3}))}}();t({target:"String",proto:!0,forced:n("anchor")},{anchor:function(t){return r(this,"a","name",t)}})}();var Vo,qo,Ho,$o,Jo={};function Ko(){if(qo)return Vo;qo=1;var t=dt(),r=ko(),n=jo().getWeakData,e=Po(),i=Er(),o=gt(),u=wt(),a=Xi(),c=he(),f=ar(),s=Hr(),l=s.set,v=s.getterFor,d=c.find,h=c.findIndex,p=t([].splice),g=0,y=function(t){return t.frozen||(t.frozen=new b)},b=function(){this.entries=[]},m=function(t,r){return d(t.entries,(function(t){return t[0]===r}))};return b.prototype={get:function(t){var r=m(this,t);if(r)return r[1]},has:function(t){return!!m(this,t)},set:function(t,r){var n=m(this,t);n?n[1]=r:this.entries.push([t,r])},delete:function(t){var r=h(this.entries,(function(r){return r[0]===t}));return~r&&p(this.entries,r,1),!!~r}},Vo={getConstructor:function(t,c,s,d){var h=t((function(t,r){e(t,p),l(t,{type:c,id:g++,frozen:null}),o(r)||a(r,t[d],{that:t,AS_ENTRIES:s})})),p=h.prototype,b=v(c),m=function(t,r,e){var o=b(t),u=n(i(r),!0);return!0===u?y(o).set(r,e):u[o.id]=e,t};return r(p,{delete:function(t){var r=b(this);if(!u(t))return!1;var e=n(t);return!0===e?y(r).delete(t):e&&f(e,r.id)&&delete e[r.id]},has:function(t){var r=b(this);if(!u(t))return!1;var e=n(t);return!0===e?y(r).has(t):e&&f(e,r.id)}}),r(p,s?{get:function(t){var r=b(this);if(u(t)){var e=n(t);if(!0===e)return y(r).get(t);if(e)return e[r.id]}},set:function(t,r){return m(this,t,r)}}:{add:function(t){return m(this,t,!0)}}),h}}}$o||($o=1,function(){if(Ho)return Jo;Ho=1;var t,r=To(),n=f(),e=dt(),i=ko(),o=jo(),u=Ao(),a=Ko(),c=wt(),s=Hr().enforce,l=m(),v=Ur(),d=Object,h=Array.isArray,p=d.isExtensible,g=d.isFrozen,y=d.isSealed,b=d.freeze,w=d.seal,x=!n.ActiveXObject&&"ActiveXObject"in n,O=function(t){return function(){return t(this,arguments.length?arguments[0]:void 0)}},S=u("WeakMap",O,a),E=S.prototype,T=e(E.set);if(v)if(x){t=a.getConstructor(O,"WeakMap",!0),o.enable();var j=e(E.delete),P=e(E.has),R=e(E.get);i(E,{delete:function(r){if(c(r)&&!p(r)){var n=s(this);return n.frozen||(n.frozen=new t),j(this,r)||n.frozen.delete(r)}return j(this,r)},has:function(r){if(c(r)&&!p(r)){var n=s(this);return n.frozen||(n.frozen=new t),P(this,r)||n.frozen.has(r)}return P(this,r)},get:function(r){if(c(r)&&!p(r)){var n=s(this);return n.frozen||(n.frozen=new t),P(this,r)?R(this,r):n.frozen.get(r)}return R(this,r)},set:function(r,n){if(c(r)&&!p(r)){var e=s(this);e.frozen||(e.frozen=new t),P(this,r)?T(this,r,n):e.frozen.set(r,n)}else T(this,r,n);return this}})}else r&&l((function(){var t=b([]);return T(new S,t,1),!g(t)}))&&i(E,{set:function(t,r){var n;return h(t)&&(g(t)?n=b:y(t)&&(n=w)),T(this,t,r),n&&n(t),this}})}());var Qo,Zo,tu,ru,nu,eu,iu,ou,uu,au={};function cu(){return Zo?Qo:(Zo=1,Qo={CSSRuleList:0,CSSStyleDeclaration:0,CSSValueList:0,ClientRectList:0,DOMRectList:0,DOMStringList:0,DOMTokenList:1,DataTransferItemList:0,FileList:0,HTMLAllCollection:0,HTMLCollection:0,HTMLFormElement:0,HTMLSelectElement:0,MediaList:0,MimeTypeArray:0,NamedNodeMap:0,NodeList:1,PaintRequestList:0,Plugin:0,PluginArray:0,SVGLengthList:0,SVGNumberList:0,SVGPathSegList:0,SVGPointList:0,SVGStringList:0,SVGTransformList:0,SourceBufferList:0,StyleSheetList:0,TextTrackCueList:0,TextTrackList:0,TouchList:0})}function fu(){if(ru)return tu;ru=1;var t=vr()("span").classList,r=t&&t.constructor&&t.constructor.prototype;return tu=r===Object.prototype?void 0:r}!function(){if(uu)return au;uu=1;var t=f(),r=cu(),n=fu(),e=function(){if(ou)return iu;ou=1;var t=he().forEach,r=function(){if(eu)return nu;eu=1;var t=m();return nu=function(r,n){var e=[][r];return!!e&&t((function(){e.call(null,n||function(){return 1},1)}))}}()("forEach");return iu=r?[].forEach:function(r){return t(this,r,arguments.length>1?arguments[1]:void 0)},iu}(),i=jr(),o=function(t){if(t&&t.forEach!==e)try{i(t,"forEach",e)}catch(r){t.forEach=e}};for(var u in r)r[u]&&o(t[u]&&t[u].prototype);o(n)}();var su,lu={};!function(){if(su)return lu;su=1;var t=f(),r=cu(),n=fu(),e=Ii(),i=jr(),o=ki(),u=fr()("iterator"),a=e.values,c=function(t,n){if(t){if(t[u]!==a)try{i(t,u,a)}catch(r){t[u]=a}if(o(t,n,!0),r[n])for(var c in e)if(t[c]!==e[c])try{i(t,c,e[c])}catch(r){t[c]=e[c]}}};for(var s in r)c(t[s]&&t[s].prototype,s);c(n,"DOMTokenList")}();var vu=function(){return vu=Object.assign||function(t){for(var r,n=1,e=arguments.length;n<e;n++)for(var i in r=arguments[n])Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i]);return t},vu.apply(this,arguments)};function du(t,r){var n={};for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&r.indexOf(e)<0&&(n[e]=t[e]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(e=Object.getOwnPropertySymbols(t);i<e.length;i++)r.indexOf(e[i])<0&&Object.prototype.propertyIsEnumerable.call(t,e[i])&&(n[e[i]]=t[e[i]])}return n}function hu(t){var r="function"==typeof Symbol&&Symbol.iterator,n=r&&t[r],e=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&e>=t.length&&(t=void 0),{value:t&&t[e++],done:!t}}};throw new TypeError(r?"Object is not iterable.":"Symbol.iterator is not defined.")}function pu(t,r){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var e,i,o=n.call(t),u=[];try{for(;(void 0===r||r-- >0)&&!(e=o.next()).done;)u.push(e.value)}catch(t){i={error:t}}finally{try{e&&!e.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return u}function gu(t,r,n){if(n||2===arguments.length)for(var e,i=0,o=r.length;i<o;i++)!e&&i in r||(e||(e=Array.prototype.slice.call(r,0,i)),e[i]=r[i]);return t.concat(e||Array.prototype.slice.call(r))}"function"==typeof SuppressedError&&SuppressedError;var yu,bu,mu,wu={};function xu(){if(bu)return yu;bu=1;var t=TypeError;return yu=function(r){if(r>9007199254740991)throw t("Maximum allowed index exceeded");return r}}!function(){if(mu)return wu;mu=1;var t=oe(),r=m(),n=ce(),e=wt(),i=ur(),o=mn(),u=xu(),a=We(),c=de(),f=pe(),s=fr(),l=St(),v=s("isConcatSpreadable"),d=l>=51||!r((function(){var t=[];return t[v]=!1,t.concat()[0]!==t})),h=function(t){if(!e(t))return!1;var r=t[v];return void 0!==r?!!r:n(t)};t({target:"Array",proto:!0,arity:1,forced:!d||!f("concat")},{concat:function(t){var r,n,e,f,s,l=i(this),v=c(l,0),d=0;for(r=-1,e=arguments.length;r<e;r++)if(h(s=-1===r?l:arguments[r]))for(f=o(s),u(d+f),n=0;n<f;n++,d++)n in s&&a(v,d,s[n]);else u(d+1),a(v,d++,s);return v.length=d,v}})}();var Ou,Su={};!function(){if(Ou)return Su;Ou=1;var t=oe(),r=he().map;t({target:"Array",proto:!0,forced:!pe()("map")},{map:function(t){return r(this,t,arguments.length>1?arguments[1]:void 0)}})}();var Eu,Tu={};!function(){if(Eu)return Tu;Eu=1;var t=oe(),r=ce(),n=le(),e=wt(),i=yn(),o=mn(),u=bt(),a=We(),c=fr(),f=pe(),s=Oo(),l=f("slice"),v=c("species"),d=Array,h=Math.max;t({target:"Array",proto:!0,forced:!l},{slice:function(t,c){var f,l,p,g=u(this),y=o(g),b=i(t,y),m=i(void 0===c?y:c,y);if(r(g)&&(f=g.constructor,(n(f)&&(f===d||r(f.prototype))||e(f)&&null===(f=f[v]))&&(f=void 0),f===d||void 0===f))return s(g,b,m);for(l=new(void 0===f?d:f)(h(m-b,0)),p=0;b<m;b++,p++)b in g&&a(l,p,g[b]);return l.length=p,l}})}();var ju,Pu,Ru,Au={};!function(){if(Ru)return Au;Ru=1;var t=oe(),r=function(){if(Pu)return ju;Pu=1;var t=w(),r=dt(),n=O(),e=m(),i=Ei(),o=re(),u=lt(),a=ur(),c=pt(),f=Object.assign,s=Object.defineProperty,l=r([].concat);return ju=!f||e((function(){if(t&&1!==f({b:1},f(s({},"a",{enumerable:!0,get:function(){s(this,"b",{value:3,enumerable:!1})}}),{b:2})).b)return!0;var r={},n={},e=Symbol("assign detection"),o="abcdefghijklmnopqrst";return r[e]=7,o.split("").forEach((function(t){n[t]=t})),7!==f({},r)[e]||i(f({},n)).join("")!==o}))?function(r,e){for(var f=a(r),s=arguments.length,v=1,d=o.f,h=u.f;s>v;)for(var p,g=c(arguments[v++]),y=d?l(i(g),d(g)):i(g),b=y.length,m=0;b>m;)p=y[m++],t&&!n(h,g,p)||(f[p]=g[p]);return f}:f,ju}();t({target:"Object",stat:!0,arity:2,forced:Object.assign!==r},{assign:r})}();var Cu,ku,Lu,Fu={};!function(){if(Lu)return Fu;Lu=1;var t=oe(),r=function(){if(ku)return Cu;ku=1;var t=w(),r=m(),n=dt(),e=Ai(),i=Ei(),o=bt(),u=n(lt().f),a=n([].push),c=t&&r((function(){var t=Object.create(null);return t[2]=2,!u(t,2)})),f=function(r){return function(n){for(var f,s=o(n),l=i(s),v=c&&null===e(s),d=l.length,h=0,p=[];d>h;)f=l[h++],t&&!(v?f in s:u(s,f))||a(p,r?[f,s[f]]:s[f]);return p}};return Cu={entries:f(!0),values:f(!1)}}().entries;t({target:"Object",stat:!0},{entries:function(t){return r(t)}})}();var _u,Du,Mu,Iu,zu,Nu={};function Wu(){if(Iu)return Mu;Iu=1;var t=O(),r=ar(),n=Ot(),e=function(){if(Du)return _u;Du=1;var t=Er();return _u=function(){var r=t(this),n="";return r.hasIndices&&(n+="d"),r.global&&(n+="g"),r.ignoreCase&&(n+="i"),r.multiline&&(n+="m"),r.dotAll&&(n+="s"),r.unicode&&(n+="u"),r.unicodeSets&&(n+="v"),r.sticky&&(n+="y"),n}}(),i=RegExp.prototype;return Mu=function(o){var u=o.flags;return void 0!==u||"flags"in i||r(o,"flags")||!n(i,o)?u:t(e,o)}}!function(){if(zu)return Nu;zu=1;var t=Gr().PROPER,r=Jr(),n=Er(),e=No(),i=m(),o=Wu(),u="toString",a=RegExp.prototype,c=a[u],f=i((function(){return"/a/b"!==c.call({source:"a",flags:"b"})})),s=t&&c.name!==u;(f||s)&&r(a,u,(function(){var t=n(this);return"/"+e(t.source)+"/"+e(o(t))}),{unsafe:!0})}();var Yu,Xu,Gu,Bu,Uu,Vu,qu,Hu={};function $u(){if(Bu)return Gu;Bu=1;var t=function(){if(Xu)return Yu;Xu=1;var t=wt(),r=ht(),n=fr()("match");return Yu=function(e){var i;return t(e)&&(void 0!==(i=e[n])?!!i:"RegExp"===r(e))}}(),r=TypeError;return Gu=function(n){if(t(n))throw new r("The method doesn't accept regular expressions");return n}}!function(){if(qu)return Hu;qu=1;var t,r=oe(),n=ue(),e=hr().f,i=bn(),o=No(),u=$u(),a=yt(),c=function(){if(Vu)return Uu;Vu=1;var t=fr()("match");return Uu=function(r){var n=/./;try{"/./"[r](n)}catch(e){try{return n[t]=!1,"/./"[r](n)}catch(t){}}return!1}}(),f=nr(),s=n("".slice),l=Math.min,v=c("startsWith");r({target:"String",proto:!0,forced:!!(f||v||(t=e(String.prototype,"startsWith"),!t||t.writable))&&!v},{startsWith:function(t){var r=o(a(this));u(t);var n=i(l(arguments.length>1?arguments[1]:void 0,r.length)),e=o(t);return s(r,n,n+e.length)===e}})}();var Ju,Ku={};function Qu(t){return"[object Object]"===Object.prototype.toString.call(t)}function Zu(t){if(!Qu(t))return!1;var r=t.constructor;if(void 0===r)return!0;var n=r.prototype;return!1!==Qu(n)&&!Object.prototype.hasOwnProperty.call(n,"isPrototypeOfOf")}function ta(t,r){for(var n in t){var e=t[n],i=r[n];if(Zu(e)&&Zu(i)){if(!ta(e,i))return!1}else if(Array.isArray(e)&&Array.isArray(i)){if(e.length!==i.length)return!1;for(var o=0;o<e.length;o+=1)if(e[o]!==i[o])return!1}else if(e!==i)return!1}for(var n in r)if(void 0===t[n]&&void 0!==r[n])return!1;return!0}function ra(t){for(var r=[],n=1;n<arguments.length;n++)r[n-1]=arguments[n];return Object.fromEntries(Object.entries(t).filter((function(t){var n=pu(t,1)[0];return r.includes(n)})))}function na(t){return function(t){var r,n,e,i,o=[];try{for(var u=hu(t),a=u.next();!a.done;a=u.next()){var c=a.value;if("string"!=typeof c.insert||0!==c.insert.length){var f=o[o.length-1];f&&"string"==typeof f.insert&&"string"==typeof c.insert&&(f.attributes===c.attributes||!f.attributes==!c.attributes&&ta(null!==(e=f.attributes)&&void 0!==e?e:{},null!==(i=c.attributes)&&void 0!==i?i:{}))?f.insert+=c.insert:o.push(c)}}}catch(t){r={error:t}}finally{try{a&&!a.done&&(n=u.return)&&n.call(u)}finally{if(r)throw r.error}}return o}(t.toDelta())}function ea(t){var r=t.insert;return"string"==typeof r?r.length:1}function ia(t){return t.reduce((function(t,r){return t+ea(r)}),0)}function oa(t,r,n){if(n<1)return[];for(var e=0,i=[],o=r+n,u=0;u<t.length&&!(e>=o);u+=1){var a=t[u],c=ea(a);if(e+c<=r)e+=c;else if("string"==typeof a.insert){var f=Math.max(0,r-e),s=Math.min(c,c-(e+c-o));i.push(vu(vu({},a),{insert:a.insert.slice(f,s)})),e+=c}else e+=c,i.push(a)}return i}function ua(t){return t?n.Text.isText(t)?t.text.length:1:0}function aa(t,r,e){var i;if(0===e.length)throw new Error("Path has to a have a length >= 1");if(n.Text.isText(r))throw new Error("Cannot descent into slate text");var o=pu(e),a=o[0],c=o.slice(1),f=function(t,r){return t.children.slice(0,r).reduce((function(t,r){return t+ua(r)}),0)}(r,a),s=r.children[a],l=na(t),v=ua(s),d=oa(l,f,v);if(d.length>1)throw new Error("Path doesn't match yText, yTarget spans multiple nodes");var h=null===(i=d[0])||void 0===i?void 0:i.insert;if(c.length>0){if(!(h instanceof u.XmlText))throw new Error("Path doesn't match yText, cannot descent into non-yText");return aa(h,s,c)}return{yParent:t,textRange:{start:f,end:f+v},yTarget:h instanceof u.XmlText?h:void 0,slateParent:r,slateTarget:s,targetDelta:d}}function ca(t,r,e){void 0===e&&(e={});for(var i=e.assoc,o=void 0===i?0:i,u=e.insert,a=void 0!==u&&u,c=0,f=0,s=0;s<t.children.length;s+=1){var l=t.children[s],v=n.Text.isText(l)?l.text.length:1;v>0&&(f=s);var d=c+v;if(v>0&&(o>=0?d>r:d>=r))return[s,r-c];c+=v}if(r>c+(a?1:0))throw new Error("yOffset out of bounds");if(a)return[t.children.length,0];var h=t.children[f];return[f,n.Text.isText(h)?h.text.length:1]}function fa(t,r,e){for(var i=[e];i[0]!==t;){var o=i[0].parent;if(!o)throw new Error("yText isn't a descendant of root element");if(!(o instanceof u.XmlText))throw new Error("Unexpected y parent type");i.unshift(o)}if(i.length<2)return[];var a=r;return i.reduce((function(t,r,e){var o,u,c=i[e+1];if(!c)return t;var f=0,s=na(r);try{for(var l=hu(s),v=l.next();!v.done;v=l.next()){var d=v.value;if(d.insert===c)break;f+="string"==typeof d.insert?d.insert.length:1}}catch(t){o={error:t}}finally{try{v&&!v.done&&(u=l.return)&&u.call(l)}finally{if(o)throw o.error}}if(n.Text.isText(a))throw new Error("Cannot descent into slate text");var h=pu(ca(a,f),1)[0];return a=a.children[h],t.concat(h)}),[])}function sa(t){if(!t.doc)throw new Error("shared type isn't attached to a document")}!function(){if(Ju)return Ku;Ju=1;var t=oe(),r=wn().includes,n=m(),e=Ri();t({target:"Array",proto:!0,forced:n((function(){return!Array(1).includes()}))},{includes:function(t){return r(this,t,arguments.length>1?arguments[1]:void 0)}}),e("includes")}();var la="__slateYjsStoredPosition_";function va(t,r,n){var e=aa(t,r,n.path),i=e.yTarget,o=e.yParent,a=e.textRange;if(i)throw new Error("Slate point points to a non-text element inside sharedRoot");var c=a.start+n.offset;return u.createRelativePositionFromTypeIndex(o,c,c===a.end?-1:0)}function da(t,r,e){if(!t.doc)throw new Error("sharedRoot isn't attach to a yDoc");var i=u.createAbsolutePositionFromRelativePosition(e,t.doc);return i&&function(t,r,e){var i=e.type,o=e.index,a=e.assoc;if(!(i instanceof u.XmlText))throw new Error("Absolute position points to a non-XMLText");var c=fa(t,r,i),f=n.Node.get(r,c);if(n.Text.isText(f)||!n.Element.isElement(f))throw new Error("Absolute position doesn't match slateRoot, cannot descent into text and EditorRoot");var s=pu(ca(f,o,{assoc:a}),2),l=s[0],v=s[1],d=f.children[l];return n.Text.isText(d)?{path:gu(gu([],pu(c),!1),[l],!1),offset:v}:null}(t,r,i)}function ha(t,r,n){t.setAttribute(la+r,u.encodeRelativePosition(n))}function pa(t,r,n){return Object.fromEntries(Object.entries(t).filter((function(t){var e=pu(t,2)[1];return e.type===r&&(!n||(e.assoc>=0?e.index>=n.start&&e.index<n.end:e.index>n.start&&e.index>=n.end))})))}function ga(t,r,n){var e;void 0===n&&(n="");var i=((e={})[n]=pa(t,r),e);return na(r).forEach((function(r,e){var o=r.insert;o instanceof u.XmlText&&Object.assign(i,ga(t,o,n?"".concat(n,".").concat(e):e.toString()))})),i}function ya(t,r,n,e){void 0===e&&(e=0);var i=function(t){return sa(t),Object.fromEntries(Object.entries(t.getAttributes()).filter((function(t){return pu(t,1)[0].startsWith(la)})).map((function(r){var n=pu(r,2),e=n[0],i=n[1];return[e.slice(la.length),u.createAbsolutePositionFromRelativePosition(u.decodeRelativePosition(i),t.doc)]})).filter((function(t){return pu(t,2)[1]})))}(t),o={"":pa(i,r,{start:e,end:e+ia(n)})};return n.forEach((function(t,r){var n=t.insert;n instanceof u.XmlText&&Object.assign(o,ga(i,n,r.toString()))})),o}function ba(t,r,n,e,i,o,a){void 0===i&&(i=0),void 0===o&&(o=0),void 0===a&&(a="");var c=n[a];c&&Object.entries(c).forEach((function(n){var e=pu(n,2),a=e[0],c=e[1];ha(t,a,u.createRelativePositionFromTypeIndex(r,c.index-o+i,c.assoc))})),e.forEach((function(r,e){var i=r.insert;i instanceof u.XmlText&&ba(t,i,n,na(i),0,0,a?"".concat(a,".").concat(e):e.toString())}))}function ma(t,r,n){return{anchor:va(t,r,n.anchor),focus:va(t,r,n.focus)}}function wa(t,r,n){var e=da(t,r,n.anchor);if(!e)return null;var i=da(t,r,n.focus);return i?{anchor:e,focus:i}:null}var xa,Oa,Sa,Ea,Ta,ja,Pa,Ra,Aa={},Ca={};function ka(){if(xa)return Ca;xa=1;var t=fr();return Ca.f=t,Ca}function La(){if(Sa)return Oa;Sa=1;var t=f();return Oa=t}function Fa(){if(Ra)return Aa;Ra=1;var t=oe(),r=f(),n=O(),e=dt(),i=nr(),o=w(),u=Et(),a=m(),c=ar(),s=Ot(),l=Er(),v=bt(),d=lr(),h=No(),p=vt(),g=Pi(),y=Ei(),b=Sn(),x=So(),S=re(),E=hr(),T=Tr(),j=Ti(),P=lt(),R=Jr(),A=Co(),C=or(),k=Vr(),L=qr(),F=cr(),_=fr(),D=ka(),M=function(){if(Ta)return Ea;Ta=1;var t=La(),r=ar(),n=ka(),e=Tr().f;return Ea=function(i){var o=t.Symbol||(t.Symbol={});r(o,i)||e(o,i,{value:n.f(i)})}}(),I=function(){if(Pa)return ja;Pa=1;var t=O(),r=xt(),n=fr(),e=Jr();return ja=function(){var i=r("Symbol"),o=i&&i.prototype,u=o&&o.valueOf,a=n("toPrimitive");o&&!o[a]&&e(o,a,(function(r){return t(u,this)}),{arity:1})}}(),z=ki(),N=Hr(),W=he().forEach,Y=k("hidden"),X="Symbol",G="prototype",B=N.set,U=N.getterFor(X),V=Object[G],q=r.Symbol,H=q&&q[G],$=r.RangeError,J=r.TypeError,K=r.QObject,Q=E.f,Z=T.f,tt=x.f,rt=P.f,nt=e([].push),et=C("symbols"),it=C("op-symbols"),ot=C("wks"),ut=!K||!K[G]||!K[G].findChild,at=function(t,r,n){var e=Q(V,r);e&&delete V[r],Z(t,r,n),e&&t!==V&&Z(V,r,e)},ct=o&&a((function(){return 7!==g(Z({},"a",{get:function(){return Z(this,"a",{value:7}).a}})).a}))?at:Z,ft=function(t,r){var n=et[t]=g(H);return B(n,{type:X,tag:t,description:r}),o||(n.description=r),n},st=function(t,r,n){t===V&&st(it,r,n),l(t);var e=d(r);return l(n),c(et,e)?(n.enumerable?(c(t,Y)&&t[Y][e]&&(t[Y][e]=!1),n=g(n,{enumerable:p(0,!1)})):(c(t,Y)||Z(t,Y,p(1,g(null))),t[Y][e]=!0),ct(t,e,n)):Z(t,e,n)},ht=function(t,r){l(t);var e=v(r),i=y(e).concat(mt(e));return W(i,(function(r){o&&!n(pt,e,r)||st(t,r,e[r])})),t},pt=function(t){var r=d(t),e=n(rt,this,r);return!(this===V&&c(et,r)&&!c(it,r))&&(!(e||!c(this,r)||!c(et,r)||c(this,Y)&&this[Y][r])||e)},gt=function(t,r){var n=v(t),e=d(r);if(n!==V||!c(et,e)||c(it,e)){var i=Q(n,e);return!i||!c(et,e)||c(n,Y)&&n[Y][e]||(i.enumerable=!0),i}},yt=function(t){var r=tt(v(t)),n=[];return W(r,(function(t){c(et,t)||c(L,t)||nt(n,t)})),n},mt=function(t){var r=t===V,n=tt(r?it:v(t)),e=[];return W(n,(function(t){!c(et,t)||r&&!c(V,t)||nt(e,et[t])})),e};return u||(q=function(){if(s(H,this))throw new J("Symbol is not a constructor");var t=arguments.length&&void 0!==arguments[0]?h(arguments[0]):void 0,e=F(t),i=function(t){var o=void 0===this?r:this;o===V&&n(i,it,t),c(o,Y)&&c(o[Y],e)&&(o[Y][e]=!1);var u=p(1,t);try{ct(o,e,u)}catch(t){if(!(t instanceof $))throw t;at(o,e,u)}};return o&&ut&&ct(V,e,{configurable:!0,set:i}),ft(e,t)},R(H=q[G],"toString",(function(){return U(this).tag})),R(q,"withoutSetter",(function(t){return ft(F(t),t)})),P.f=pt,T.f=st,j.f=ht,E.f=gt,b.f=x.f=yt,S.f=mt,D.f=function(t){return ft(_(t),t)},o&&(A(H,"description",{configurable:!0,get:function(){return U(this).description}}),i||R(V,"propertyIsEnumerable",pt,{unsafe:!0}))),t({global:!0,constructor:!0,wrap:!0,forced:!u,sham:!u},{Symbol:q}),W(y(ot),(function(t){M(t)})),t({target:X,stat:!0,forced:!u},{useSetter:function(){ut=!0},useSimple:function(){ut=!1}}),t({target:"Object",stat:!0,forced:!u,sham:!o},{create:function(t,r){return void 0===r?g(t):ht(g(t),r)},defineProperty:st,defineProperties:ht,getOwnPropertyDescriptor:gt}),t({target:"Object",stat:!0,forced:!u},{getOwnPropertyNames:yt}),I(),z(q,X),L[Y]=!0,Aa}var _a,Da,Ma,Ia={};function za(){if(Da)return _a;Da=1;var t=Et();return _a=t&&!!Symbol.for&&!!Symbol.keyFor}var Na,Wa={};var Ya,Xa,Ga,Ba,Ua,Va={};function qa(){if(Ua)return Va;Ua=1;var t=oe(),r=xt(),n=function(){if(Xa)return Ya;Xa=1;var t=x(),r=Function.prototype,n=r.apply,e=r.call;return Ya="object"==typeof Reflect&&Reflect.apply||(t?e.bind(n):function(){return e.apply(n,arguments)}),Ya}(),e=O(),i=dt(),o=m(),u=mt(),a=jt(),c=Oo(),f=function(){if(Ba)return Ga;Ba=1;var t=dt(),r=ce(),n=mt(),e=ht(),i=No(),o=t([].push);return Ga=function(t){if(n(t))return t;if(r(t)){for(var u=t.length,a=[],c=0;c<u;c++){var f=t[c];"string"==typeof f?o(a,f):"number"!=typeof f&&"Number"!==e(f)&&"String"!==e(f)||o(a,i(f))}var s=a.length,l=!0;return function(t,n){if(l)return l=!1,n;if(r(this))return n;for(var e=0;e<s;e++)if(a[e]===t)return n}}}}(),s=Et(),l=String,v=r("JSON","stringify"),d=i(/./.exec),h=i("".charAt),p=i("".charCodeAt),g=i("".replace),y=i(1..toString),b=/[\uD800-\uDFFF]/g,w=/^[\uD800-\uDBFF]$/,S=/^[\uDC00-\uDFFF]$/,E=!s||o((function(){var t=r("Symbol")("stringify detection");return"[null]"!==v([t])||"{}"!==v({a:t})||"{}"!==v(Object(t))})),T=o((function(){return'"\\udf06\\ud834"'!==v("\udf06\ud834")||'"\\udead"'!==v("\udead")})),j=function(t,r){var i=c(arguments),o=f(r);if(u(o)||void 0!==t&&!a(t))return i[1]=function(t,r){if(u(o)&&(r=e(o,this,l(t),r)),!a(r))return r},n(v,null,i)},P=function(t,r,n){var e=h(n,r-1),i=h(n,r+1);return d(w,t)&&!d(S,i)||d(S,t)&&!d(w,e)?"\\u"+y(p(t,0),16):t};return v&&t({target:"JSON",stat:!0,arity:3,forced:E||T},{stringify:function(t,r,e){var i=c(arguments),o=n(E?j:v,null,i);return T&&"string"==typeof o?g(o,b,P):o}}),Va}var Ha,$a,Ja={};$a||($a=1,Fa(),function(){if(Ma)return Ia;Ma=1;var t=oe(),r=xt(),n=ar(),e=No(),i=or(),o=za(),u=i("string-to-symbol-registry"),a=i("symbol-to-string-registry");t({target:"Symbol",stat:!0,forced:!o},{for:function(t){var i=e(t);if(n(u,i))return u[i];var o=r("Symbol")(i);return u[i]=o,a[o]=i,o}})}(),function(){if(Na)return Wa;Na=1;var t=oe(),r=ar(),n=jt(),e=Pt(),i=or(),o=za(),u=i("symbol-to-string-registry");t({target:"Symbol",stat:!0,forced:!o},{keyFor:function(t){if(!n(t))throw new TypeError(e(t)+" is not a symbol");if(r(u,t))return u[t]}})}(),qa(),function(){if(Ha)return Ja;Ha=1;var t=oe(),r=Et(),n=m(),e=re(),i=ur();t({target:"Object",stat:!0,forced:!r||n((function(){e.f(1)}))},{getOwnPropertySymbols:function(t){var r=e.f;return r?r(i(t)):[]}})}());var Ka,Qa={};!function(){if(Ka)return Qa;Ka=1;var t=oe(),r=w(),n=f(),e=dt(),i=ar(),o=mt(),u=Ot(),a=No(),c=Co(),s=ee(),l=n.Symbol,v=l&&l.prototype;if(r&&o(l)&&(!("description"in v)||void 0!==l().description)){var d={},h=function(){var t=arguments.length<1||void 0===arguments[0]?void 0:a(arguments[0]),r=u(v,this)?new l(t):void 0===t?l():l(t);return""===t&&(d[r]=!0),r};s(h,l),h.prototype=v,v.constructor=h;var p="Symbol(description detection)"===String(l("description detection")),g=e(v.valueOf),y=e(v.toString),b=/^Symbol\((.*)\)[^)]+$/,m=e("".replace),x=e("".slice);c(v,"description",{configurable:!0,get:function(){var t=g(this);if(i(d,t))return"";var r=y(t),n=p?x(r,7,-1):m(r,b,"$1");return""===n?void 0:n}}),t({global:!0,constructor:!0,forced:!0},{Symbol:h})}}();var Za,tc;tc||(tc=1,Za||(Za=1,Ao()("WeakSet",(function(t){return function(){return t(this,arguments.length?arguments[0]:void 0)}}),Ko())));var rc,nc={};function ec(t){return function(t){for(var r=[],n=1;n<arguments.length;n++)r[n-1]=arguments[n];return Object.fromEntries(Object.entries(t).filter((function(t){var n=pu(t,1)[0];return!r.includes(n)})))}(t,n.Text.isText(t)?"text":"children")}function ic(t){var r=na(t),n=r.length>0?r.map(oc):[{text:""}];return vu(vu({},t.getAttributes()),{children:n})}function oc(t){return"string"==typeof t.insert?vu(vu({},t.attributes),{text:t.insert}):ic(t.insert)}function uc(t){return t.map((function(t){return n.Text.isText(t)?{insert:t.text,attributes:ec(t)}:{insert:ac(t)}}))}function ac(t){var r=t.children,n=du(t,["children"]),e=new u.XmlText;return Object.entries(n).forEach((function(t){var r=pu(t,2),n=r[0],i=r[1];e.setAttribute(n,i)})),e.applyDelta(uc(r),{sanitize:!1}),e}function cc(t,r,e){var i=e.target,o=e.changes,a=e.delta;if(!(i instanceof u.XmlText))throw new Error("Unexpected target node type");var c=[],f=fa(t,r,i),s=n.Node.get(r,f);if(n.Text.isText(s))throw new Error("Cannot apply yTextEvent to text node");var l=Array.from(o.keys.entries());if(f.length>0&&l.length>0){var v=Object.fromEntries(l.map((function(t){var r=pu(t,2),n=r[0];return[n,"delete"===r[1].action?null:i.getAttribute(n)]}))),d=Object.fromEntries(l.map((function(t){var r=pu(t,1)[0];return[r,s[r]]})));c.push({type:"set_node",newProperties:v,properties:d,path:f})}return a.length>0&&c.push.apply(c,gu([],pu(function(t,r,e){var i=[],o=e.reduce((function(t,r){return"retain"in r?t+r.retain:"delete"in r?t+r.delete:t}),0);return e.reverse().forEach((function(e){var u,a;if("attributes"in e&&"retain"in e)for(var c=pu(ca(t,o-e.retain),2),f=c[0],s=c[1],l=pu(ca(t,o,{assoc:-1}),2),v=l[0],d=l[1],h=v;h>=f;h-=1){var p=t.children[h],g=gu(gu([],pu(r),!1),[h],!1);if(n.Text.isText(p)){var y=e.attributes,b=ra.apply(void 0,gu([t],pu(Object.keys(e.attributes)),!1));if(h===f||h===v){var m=h===f?s:0;if((O=h===v?d:p.text.length)!==p.text.length&&i.push({type:"split_node",path:g,position:O,properties:ec(p)}),0!==m){i.push({type:"split_node",path:g,position:m,properties:(a=vu(vu({},ec(p)),y),Object.fromEntries(Object.entries(a).filter((function(t){return null!==pu(t,2)[1]}))))});continue}}i.push({type:"set_node",newProperties:y,path:g,properties:b})}}if("retain"in e&&(o-=e.retain),"delete"in e){var w=pu(ca(t,o-e.delete),2),x=(f=w[0],s=w[1],pu(ca(t,o,{assoc:-1}),2));for(v=x[0],h=0===(d=x[1])?v-1:v;h>=f;h-=1)if(p=t.children[h],g=gu(gu([],pu(r),!1),[h],!1),!n.Text.isText(p)||h!==f&&h!==v)i.push({type:"remove_node",node:p,path:g}),o-=ua(p);else{m=h===f?s:0;var O=h===v?d:p.text.length;i.push({type:"remove_text",offset:m,text:p.text.slice(m,O),path:g}),o-=O-m}}else if("insert"in e){var S=pu(ca(t,o,{insert:!0}),2),E=(h=S[0],S[1]);if(p=t.children[h],g=gu(gu([],pu(r),!1),[h],!1),n.Text.isText(p)){var T=i[i.length-1],j=null!=T&&"insert_node"===T.type?T.node:ec(p),P=[];if(null==T||"insert_node"!==T.type&&"insert_text"!==T.type&&"split_node"!==T.type&&"set_node"!==T.type||(P=T.path),"string"==typeof e.insert&&ta(null!==(u=e.attributes)&&void 0!==u?u:{},j)&&n.Path.equals(g,P))return i.push({type:"insert_text",offset:E,text:e.insert,path:g});var R=oc(e);return 0===E?i.push({type:"insert_node",path:g,node:R}):(E<p.text.length&&i.push({type:"split_node",path:g,position:E,properties:ec(p)}),i.push({type:"insert_node",path:n.Path.next(g),node:R}))}return i.push({type:"insert_node",path:g,node:oc(e)})}})),i}(s,f,a)),!1)),c}function fc(t,r,e){n.Editor.withoutNormalizing(r,(function(){e.forEach((function(n){(function(t,r,n){if(n instanceof u.YTextEvent)return cc(t,r,n);throw new Error("Unexpected Y event type")})(t,r,n).forEach((function(t){r.apply(t)}))}))}))}function sc(t){return t.map((function(t){return"string"==typeof t.insert?t:vu(vu({},t),{insert:lc(t.insert)})}))}function lc(t){var r=new u.XmlText,n=t.getAttributes();return Object.entries(n).forEach((function(t){var n=pu(t,2),e=n[0],i=n[1];r.setAttribute(e,i)})),r.applyDelta(sc(na(t)),{sanitize:!1}),r}!function(){if(rc)return nc;rc=1;var t=oe(),r=ur(),n=Ei();t({target:"Object",stat:!0,forced:m()((function(){n(1)}))},{keys:function(t){return n(r(t))}})}();var vc={insert_node:function(t,r,e){var i=aa(t,r,e.path),o=i.yParent,u=i.textRange;if(n.Text.isText(e.node))return o.insert(u.start,e.node.text,ec(e.node));o.insertEmbed(u.start,ac(e.node))},remove_node:function(t,r,n){var e=aa(t,r,n.path),i=e.yParent,o=e.textRange;i.delete(o.start,o.end-o.start)},set_node:function(t,r,n){var e=aa(t,r,n.path),i=e.yTarget,o=e.textRange,u=e.yParent;if(i)return Object.entries(n.newProperties).forEach((function(t){var r=pu(t,2),n=r[0],e=r[1];if(null===e)return i.removeAttribute(n);i.setAttribute(n,e)})),Object.entries(n.properties).forEach((function(t){var r=pu(t,1)[0];Object.prototype.hasOwnProperty.call(n.newProperties,r)||i.removeAttribute(r)}));var a=Object.fromEntries(Object.keys(n.properties).map((function(t){return[t,null]}))),c=vu(vu({},a),n.newProperties);u.format(o.start,o.end-o.start,c)},merge_node:function(t,r,e){var i=aa(t,r,e.path),o=aa(i.yParent,i.slateParent,n.Path.previous(e.path.slice(-1)));if(!i.yTarget!=!o.yTarget)throw new Error("Cannot merge y text with y element");if(!o.yTarget||!i.yTarget){var u=i.yParent,a=i.textRange,c=i.slateTarget;if(!c)throw new Error("Expected Slate target node for merge op.");var f=n.Node.get(r,n.Path.previous(e.path));if(!n.Text.isText(f))throw new Error("Path points to Y.Text but not a Slate text node.");var s=ec(c),l=ec(f),v=Object.keys(s).reduce((function(t,r){var n;return r in l?t:vu(vu({},t),((n={})[r]=null,n))}),{});return u.format(a.start,a.end-a.start,vu(vu({},v),l))}var d=o.yTarget.length,h=na(i.yTarget),p=sc(h),g=ya(t,i.yTarget,h,d),y=gu([{retain:d}],pu(p),!1);o.yTarget.applyDelta(y,{sanitize:!1}),i.yParent.delete(i.textRange.start,i.textRange.end-i.textRange.start),ba(t,o.yTarget,g,p,d)},move_node:function(t,r,e){var i=n.Path.parent(e.newPath),o=e.newPath[e.newPath.length-1],u=n.Node.get(r,i);if(n.Text.isText(u))throw new Error("Cannot move slate node into text element");var a=gu(gu([],pu(i),!1),[Math.min(o,u.children.length)],!1),c=aa(t,r,e.path),f=aa(t,r,a),s=sc(c.targetDelta),l=ya(t,c.yParent,c.targetDelta);c.yParent.delete(c.textRange.start,c.textRange.end-c.textRange.start);var v=ia(na(f.yParent)),d=Math.min(f.textRange.start,v),h=gu([{retain:d}],pu(s),!1);f.yParent.applyDelta(h,{sanitize:!1}),ba(t,f.yParent,l,s,d,c.textRange.start)},split_node:function(t,r,e){var i=aa(t,r,e.path);if(!i.slateTarget)throw new Error("Y target without corresponding slate node");if(!i.yTarget){if(!n.Text.isText(i.slateTarget))throw new Error("Mismatch node type between y target and slate node");var o={};return i.targetDelta.forEach((function(t){t.attributes&&Object.keys(t.attributes).forEach((function(t){o[t]=null}))})),i.yParent.format(i.textRange.start,i.textRange.end-i.textRange.start,vu(vu({},o),e.properties))}if(n.Text.isText(i.slateTarget))throw new Error("Mismatch node type between y target and slate node");var a=aa(i.yTarget,i.slateTarget,[e.position]),c=i.slateTarget.children.slice(0,e.position).reduce((function(t,r){return t+ua(r)}),0),f=i.slateTarget.children.reduce((function(t,r){return t+ua(r)}),0),s=oa(na(i.yTarget),c,f-c),l=sc(s),v=ya(t,i.yTarget,s,c),d=new u.XmlText;d.applyDelta(l,{sanitize:!1}),Object.entries(e.properties).forEach((function(t){var r=pu(t,2),n=r[0],e=r[1];d.setAttribute(n,e)})),i.yTarget.delete(a.textRange.start,i.yTarget.length-a.textRange.start),i.yParent.insertEmbed(i.textRange.end,d),ba(t,d,v,l,0,c)}};var dc=vu(vu(vu({},{insert_text:function(t,r,e){var i=aa(t,r,e.path),o=i.yParent,u=i.textRange,a=n.Node.get(r,e.path);if(!n.Text.isText(a))throw new Error("Cannot insert text into non-text node");o.insert(u.start+e.offset,e.text,ec(a))},remove_text:function(t,r,n){var e=aa(t,r,n.path),i=e.yParent,o=e.textRange;i.delete(o.start+n.offset,n.text.length)}}),vc),{set_selection:function(){}});var hc=Symbol("slate-yjs-operation"),pc=Symbol("slate-yjs-position-storage"),gc=new WeakMap,yc=new WeakMap,bc=new WeakSet,mc={isYjsEditor:function(t){return n.Editor.isEditor(t)&&t.sharedRoot instanceof u.XmlText&&"localOrigin"in t&&"positionStorageOrigin"in t&&"function"==typeof t.applyRemoteEvents&&"function"==typeof t.storeLocalChange&&"function"==typeof t.flushLocalChanges&&"function"==typeof t.isLocalOrigin&&"function"==typeof t.connect&&"function"==typeof t.disconnect},localChanges:function(t){var r;return null!==(r=yc.get(t))&&void 0!==r?r:[]},applyRemoteEvents:function(t,r,n){t.applyRemoteEvents(r,n)},storeLocalChange:function(t,r){t.storeLocalChange(r)},flushLocalChanges:function(t){t.flushLocalChanges()},connected:function(t){return bc.has(t)},connect:function(t){t.connect()},disconnect:function(t){t.disconnect()},isLocal:function(t){return t.isLocalOrigin(mc.origin(t))},origin:function(t){var r=gc.get(t);return void 0!==r?r:t.localOrigin},withOrigin:function(t,r,n){var e=mc.origin(t);gc.set(t,r),n(),gc.set(t,e)},storePosition:function(t,r,n){var e=t.sharedRoot,i=t.positionStorageOrigin;sa(e);var o=va(e,t,n);e.doc.transact((function(){ha(e,r,o)}),i)},removeStoredPosition:function(t,r){var n=t.sharedRoot,e=t.positionStorageOrigin;sa(n),n.doc.transact((function(){!function(t,r){t.removeAttribute(la+r)}(n,r)}),e)},position:function(t,r){var n=function(t,r){var n=t.getAttribute(la+r);return n?u.decodeRelativePosition(n):null}(t.sharedRoot,r);if(n)return da(t.sharedRoot,t,n)},storedPositionsRelative:function(t){return r=t.sharedRoot,Object.fromEntries(Object.entries(r.getAttributes()).filter((function(t){return pu(t,1)[0].startsWith(la)})).map((function(t){var r=pu(t,2),n=r[0],e=r[1];return[n.slice(la.length),u.createRelativePositionFromJSON(e)]})));var r}};var wc=new WeakMap,xc={isCursorEditor:function(t){return mc.isYjsEditor(t)&&t.awareness&&"string"==typeof t.cursorDataField&&"string"==typeof t.selectionStateField&&"function"==typeof t.sendCursorPosition&&"function"==typeof t.sendCursorData},sendCursorPosition:function(t,r){void 0===r&&(r=t.selection),t.sendCursorPosition(r)},sendCursorData:function(t,r){t.sendCursorData(r)},on:function(t,r,n){var e;if("change"===r){var i=null!==(e=wc.get(t))&&void 0!==e?e:new Set;i.add(n),t&&wc.set(t,i)}},off:function(t,r,n){if("change"===r){var e=wc.get(t);e&&e.delete(n)}},cursorState:function(t,r){var n;if(r===t.awareness.clientID||!mc.connected(t))return null;var e=t.awareness.getStates().get(r);return e?{relativeSelection:null!==(n=e[t.selectionStateField])&&void 0!==n?n:null,data:e[t.cursorDataField],clientId:r}:null},cursorStates:function(t){return mc.connected(t)?Object.fromEntries(Array.from(t.awareness.getStates().entries(),(function(r){var n=pu(r,2),e=n[0],i=n[1];return e!==t.awareness.clientID&&i?[e,{relativeSelection:i[t.selectionStateField],data:i[t.cursorDataField]}]:null})).filter(Array.isArray)):{}}};var Oc=new WeakMap,Sc=Symbol("slate-yjs-history-without-saving"),Ec={isYHistoryEditor:function(t){return mc.isYjsEditor(t)&&t.undoManager instanceof u.UndoManager&&"function"==typeof t.undo&&"function"==typeof t.redo&&"withoutSavingOrigin"in t},canUndo:function(t){return t.undoManager.undoStack.length>0},canRedo:function(t){return t.undoManager.redoStack.length>0},isSaving:function(t){return t.undoManager.trackedOrigins.has(mc.origin(t))},withoutSaving:function(t,r){mc.withOrigin(t,t.withoutSavingOrigin,r)}};t.CursorEditor=xc,t.YHistoryEditor=Ec,t.YjsEditor=mc,t.relativePositionToSlatePoint=da,t.relativeRangeToSlateRange=wa,t.slateNodesToInsertDelta=uc,t.slatePointToRelativePosition=va,t.slateRangeToRelativeRange=ma,t.withCursors=function(t,r){return void 0===r&&(r={}),function(n){var e=r.cursorStateField,i=void 0===e?"selection":e,o=r.cursorDataField,a=void 0===o?"data":o,c=r.autoSend,f=void 0===c||c,s=r.data,l=n;l.awareness=t,l.cursorDataField=a,l.selectionStateField=i,l.sendCursorData=function(t){l.awareness.setLocalStateField(l.cursorDataField,t)},l.sendCursorPosition=function(t){var r=l.awareness.getLocalState(),n=null==r?void 0:r[i];if(t){var e=ma(l.sharedRoot,l,t),o=e.anchor,a=e.focus;n&&u.compareRelativePositions(o,n)&&u.compareRelativePositions(a,n)||l.awareness.setLocalStateField(l.selectionStateField,{anchor:o,focus:a})}else n&&l.awareness.setLocalStateField(l.selectionStateField,null)};var v=function(t){var r=wc.get(l);if(r){var n=l.awareness.clientID,e={added:t.added.filter((function(t){return t!==n})),removed:t.removed.filter((function(t){return t!==n})),updated:t.updated.filter((function(t){return t!==n}))};(e.added.length>0||e.removed.length>0||e.updated.length>0)&&r.forEach((function(t){return t(e)}))}},d=l.connect,h=l.disconnect;return l.connect=function(){if(d(),l.awareness.on("change",v),v({removed:[],added:Array.from(l.awareness.getStates().keys()),updated:[]}),f){s&&xc.sendCursorData(l,s);var t=l.onChange;l.onChange=function(){t(),mc.connected(l)&&xc.sendCursorPosition(l)}}},l.disconnect=function(){l.awareness.off("change",v),v({removed:Array.from(l.awareness.getStates().keys()),added:[],updated:[]}),h()},l}},t.withYHistory=function(t){return void 0===t&&(t={}),function(r){var e=r,i=t.withoutSavingOrigin,o=void 0===i?Sc:i,a=t.trackedOrigins,c=void 0===a?new Set([e.localOrigin]):a,f=du(t,["withoutSavingOrigin","trackedOrigins"]),s=new u.UndoManager(e.sharedRoot,vu({trackedOrigins:c},f));e.undoManager=s,e.withoutSavingOrigin=o;var l=e.onChange,v=e.isLocalOrigin;e.onChange=function(){l(),Oc.set(e,e.selection&&ma(e.sharedRoot,e,e.selection))},e.isLocalOrigin=function(t){return t===e.withoutSavingOrigin||v(t)};var d=function(t){var r=t.stackItem;r.meta.set("selection",e.selection&&ma(e.sharedRoot,e,e.selection)),r.meta.set("selectionBefore",Oc.get(e))},h=function(t){t.stackItem.meta.set("selection",e.selection&&ma(e.sharedRoot,e,e.selection))},p=function(t){var r=t.stackItem,i="undo"===t.type?e.undoManager.redoStack:e.undoManager.undoStack,o=i[i.length-1];o&&(o.meta.set("selection",r.meta.get("selectionBefore")),o.meta.set("selectionBefore",r.meta.get("selection")));var u=r.meta.get("selectionBefore");if(u){var a=wa(e.sharedRoot,e,u);a&&n.Transforms.select(e,a)}},g=e.connect,y=e.disconnect;return e.connect=function(){g(),e.undoManager.on("stack-item-added",d),e.undoManager.on("stack-item-popped",p),e.undoManager.on("stack-item-updated",h)},e.disconnect=function(){e.undoManager.off("stack-item-added",d),e.undoManager.off("stack-item-popped",p),e.undoManager.off("stack-item-updated",h),y()},e.undo=function(){mc.connected(e)&&(mc.flushLocalChanges(e),e.undoManager.undo())},e.redo=function(){mc.connected(e)&&(mc.flushLocalChanges(e),e.undoManager.redo())},e}},t.withYjs=function(t,r){return void 0===r&&(r={}),function(e){var i,o,u=e;u.sharedRoot=t,u.localOrigin=null!==(i=r.localOrigin)&&void 0!==i?i:hc,u.positionStorageOrigin=null!==(o=r.positionStorageOrigin)&&void 0!==o?o:pc,u.applyRemoteEvents=function(t,r){mc.flushLocalChanges(u),n.Editor.withoutNormalizing(u,(function(){mc.withOrigin(u,r,(function(){fc(u.sharedRoot,u,t)}))}))},u.isLocalOrigin=function(t){return t===u.localOrigin};var a=function(t,r){u.isLocalOrigin(r.origin)||mc.applyRemoteEvents(u,t,r.origin)},c=null;r.autoConnect&&(c=setTimeout((function(){c=null,mc.connect(u)}))),u.connect=function(){if(mc.connected(u))throw new Error("already connected");u.sharedRoot.observeDeep(a);var t=ic(u.sharedRoot);u.children=t.children,bc.add(u),n.Editor.normalize(e,{force:!0}),e.operations.length||e.onChange()},u.disconnect=function(){c&&clearTimeout(c),mc.flushLocalChanges(u),u.sharedRoot.unobserveDeep(a),bc.delete(u)},u.storeLocalChange=function(t){yc.set(u,gu(gu([],pu(mc.localChanges(u)),!1),[{op:t,doc:e.children,origin:mc.origin(u)}],!1))},u.flushLocalChanges=function(){sa(u.sharedRoot);var t=mc.localChanges(u);yc.delete(u);var r=[];t.forEach((function(t){var n=r[r.length-1];if(n&&n[0].origin===t.origin)return n.push(t);r.push([t])})),r.forEach((function(t){sa(u.sharedRoot),u.sharedRoot.doc.transact((function(){t.forEach((function(t){sa(u.sharedRoot),function(t,r,n){var e=dc[n.type];if(!e)throw new Error("Unknown operation: ".concat(n.type));e(t,r,n)}(u.sharedRoot,{children:t.doc},t.op)}))}),t[0].origin)}))};var f=u.apply,s=u.onChange;return u.apply=function(t){mc.connected(u)&&mc.isLocal(u)&&mc.storeLocalChange(u,t),f(t)},u.onChange=function(){mc.connected(u)&&mc.flushLocalChanges(u),s()},u}},t.yTextToSlateElement=ic}));
2
+ //# sourceMappingURL=index.js.map