editate 0.6.27 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.cjs CHANGED
@@ -2,312 +2,393 @@ Object.defineProperty(exports, Symbol.toStringTag, {
2
2
  value: "Module"
3
3
  });
4
4
 
5
- var {min: t, max: e} = Math, {keys: n, is: r} = Object, o = t => "string" == typeof t, c = t => "function" == typeof t, s = c(queueMicrotask) ? queueMicrotask : t => {
5
+ var {min: t, max: e} = Math, {keys: n, is: r} = Object, o = t => "string" == typeof t, s = t => "function" == typeof t, c = s(queueMicrotask) ? queueMicrotask : t => {
6
6
  Promise.resolve().then(t);
7
- }, i = t => "text" in t, l = t => "children" in t, a = t => t.some(l), u = new WeakMap, f = ({children: t}, e = 0, n = t.length) => {
8
- let r = 0, o = 0;
9
- for (let c = e; c < n; c++) {
10
- const e = t[c];
11
- r += p(e), 0 !== o && l(e) && r++, o++;
7
+ }, i = t => "text" in t, l = t => "children" in t, a = t => t.some(l), f = new WeakMap, u = ({children: t}, e = 0, n = t.length) => {
8
+ let r = 0;
9
+ for (let o = e; o < n; o++) {
10
+ const n = t[o];
11
+ r += p(n), o !== e && l(n) && r++;
12
12
  }
13
13
  return r;
14
14
  }, p = t => {
15
15
  if (l(t)) {
16
- let e = u.get(t);
17
- return null == e && u.set(t, e = f(t)), e;
16
+ let e = f.get(t);
17
+ return null == e && f.set(t, e = u(t)), e;
18
18
  }
19
19
  return i(t) ? t.text.length : 1;
20
20
  }, d = ({children: t}, e, n) => {
21
21
  const r = t.length;
22
22
  for (let o = 0; o < r; o++) {
23
- const r = t[o], c = l(r);
24
- let s = p(r);
25
- const i = 0 === s;
26
- if (c && s++, s > e || s === e && !c && (n || i)) return [ r, e, o ];
27
- e -= s;
23
+ const r = t[o], s = l(r);
24
+ let c = p(r);
25
+ const i = 0 === c;
26
+ if (s && c++, c > e || c === e && !s && (n || i)) return [ r, e, o ];
27
+ e -= c;
28
28
  }
29
29
  return null;
30
- }, h = (t, e) => {
30
+ }, y = (t, e) => {
31
31
  const n = [];
32
- for (;t; ) {
33
- const r = d(t, e);
34
- if (!r) break;
35
- const o = r[0];
36
- if (!l(o)) break;
37
- e = r[1], t = o, n.push(r[2]);
38
- }
32
+ let r;
33
+ for (;(r = d(t, e)) && l(r[0]); ) e = r[1], t = r[0], n.push(r[2]);
39
34
  return [ t, e, n ];
40
- }, y = (t, e, n) => {
41
- const [r, o, c] = h(t, e), s = d(r, o, n);
42
- return s ? (c.push(s[2]), [ s[0], s[1], c ]) : null;
43
- }, x = (t, e) => {
35
+ }, x = (t, e, n) => {
36
+ const [r, o, s] = y(t, e), c = d(r, o, n);
37
+ return c ? (s.push(c[2]), [ c[0], c[1], s ]) : null;
38
+ }, h = (t, e) => {
44
39
  let n = 0, r = 0;
45
40
  for (const o of t.children) {
46
41
  const t = l(o);
47
42
  if (t && 0 !== r && n++, o === e) return n;
48
43
  if (t) {
49
- const t = x(o, e);
44
+ const t = h(o, e);
50
45
  if (null != t) return n + t;
51
46
  }
52
47
  n += p(o), r++;
53
48
  }
54
49
  return null;
55
- }, k = (t, e) => {
56
- const n = t.children, r = d(t, e);
57
- if (r) {
58
- const [e, o, c] = r;
59
- if (l(e)) {
60
- const [r, s] = k(e, o), i = n.slice(0, c), l = n.slice(c + 1);
61
- return i.push(r), l.unshift(s), [ {
62
- ...t,
63
- children: i
64
- }, {
65
- ...t,
66
- children: l
67
- } ];
68
- }
69
- {
70
- const r = n.slice(0, c), s = n.slice(c + 1);
71
- if (i(e)) {
72
- const t = e.text.slice(0, o), n = e.text.slice(o);
73
- !t && r.length || r.push({
74
- ...e,
75
- text: t
76
- }), !n && s.length || s.unshift({
77
- ...e,
78
- text: n
79
- });
80
- } else s.unshift(e);
81
- return [ {
82
- ...t,
83
- children: r
84
- }, {
85
- ...t,
86
- children: s
87
- } ];
88
- }
50
+ }, g = (t, e, n = !0) => {
51
+ const r = t.children, o = d(t, e);
52
+ if (!o) {
53
+ const e = r[r.length - 1];
54
+ return [ t, {
55
+ ...t,
56
+ children: n && i(e) ? [ {
57
+ ...e,
58
+ text: ""
59
+ } ] : []
60
+ } ];
89
61
  }
90
- const o = n[n.length - 1];
91
- return [ t, {
62
+ const [s, c, a] = o, f = r.slice(0, a), u = r.slice(a + 1);
63
+ if (l(s)) {
64
+ const [t, e] = g(s, c, n);
65
+ f.push(t), u.unshift(e);
66
+ } else if (i(s)) {
67
+ const t = s.text.slice(0, c), e = s.text.slice(c);
68
+ !t && f.length || f.push({
69
+ ...s,
70
+ text: t
71
+ }), (e || n && !u.length) && u.unshift({
72
+ ...s,
73
+ text: e
74
+ });
75
+ } else u.unshift(s);
76
+ return [ {
77
+ ...t,
78
+ children: f
79
+ }, {
92
80
  ...t,
93
- children: i(o) ? [ {
94
- ...o,
95
- text: ""
96
- } ] : []
81
+ children: u
97
82
  } ];
98
83
  }, m = (t, [e, n]) => {
99
84
  let r = 0;
100
- for (const o of e) r += f(t, 0, o), 0 !== o && r++, t = t.children[o];
85
+ for (const o of e) r += u(t, 0, o), 0 !== o && r++, t = t.children[o];
101
86
  return r + n;
102
- }, g = (t, e) => {
103
- const [, n, r] = h(t, e);
87
+ }, k = (t, e) => {
88
+ const [, n, r] = y(t, e);
104
89
  return [ r, n ];
105
- }, _ = (t, [e, n]) => [ m(t, e), m(t, n) ];
90
+ }, v = (t, [e, n]) => [ m(t, e), m(t, n) ];
106
91
 
107
- function* b(t, [e, n]) {
108
- if (e >= n) return;
109
- if (!l(t)) return;
110
- const r = d(t, e);
111
- if (r) {
112
- let o = e - r[1], c = r[2];
113
- const s = t.children, i = s.length;
114
- for (;o <= n && c < i; ) {
115
- const t = s[c];
116
- yield [ t, o ], c++, o += p(t), l(t) && o++;
92
+ function* b(n, [r, o]) {
93
+ if (r > o || !l(n)) return;
94
+ const s = d(n, r) || d(n, r, !0);
95
+ if (s) {
96
+ let c = r - s[1], i = s[2];
97
+ const a = n.children, f = a.length;
98
+ for (;c <= o && i < f; ) {
99
+ const n = a[i], s = p(n);
100
+ yield [ n, c, i, [ e(r, c) - c, t(o, c + s) - c ] ], i++, c += s, l(n) && c++;
117
101
  }
118
102
  }
119
103
  }
120
104
 
121
- function* v(t, e) {
122
- if (!l(t) || a(t.children)) for (const n of b(t, e)) {
123
- const [t, e] = n;
124
- for (const n of v(t, [ 0, p(t) ])) n[1] += e, yield n;
125
- } else yield [ t, 0 ];
105
+ function* _(t, e) {
106
+ if (!l(t) || a(t.children)) for (const [n, r, , o] of b(t, e)) for (const t of _(n, o)) t[1] += r,
107
+ yield t; else yield [ t, 0, e ];
126
108
  }
127
109
 
128
110
  function* T(t, e) {
129
- if (l(t)) for (const [n, r] of b(t, e)) for (const t of T(n, [ 0, p(n) ])) t[1] += r,
130
- yield t; else yield [ t, 0 ];
111
+ if (l(t)) for (const [n, r, , o] of b(t, e)) for (const t of T(n, o)) t[1] += r,
112
+ yield t; else yield [ t, 0, e ];
131
113
  }
132
114
 
133
- var E = (n, r = 0, o = 1 / 0, c) => {
134
- let s = "", l = r;
135
- for (const [a, u] of T(n, [ r, o ])) {
136
- for (let t = u - l; t > 0; t--) s += "\n";
137
- const n = p(a), f = u + n;
138
- if (i(a)) {
139
- const c = e(u, r) - u, i = t(f, o) - u;
140
- s += 0 === c && i === n ? a.text : a.text.slice(c, i);
141
- } else c && (s += c(a));
142
- l = f;
115
+ var w = (e, n = 0, r = 1 / 0, o) => {
116
+ let s = "", c = n;
117
+ for (const [t, l, [a, f]] of T(e, [ n, r ])) {
118
+ for (let t = l - c; t > 0; t--) s += "\n";
119
+ i(t) ? s += t.text.slice(a, f) : o && a < f && (s += o(t)), c = l + p(t);
143
120
  }
144
- for (let e = t(o, p(n)) - l; e > 0; e--) s += "\n";
121
+ for (let i = t(r, p(e)) - c; i > 0; i--) s += "\n";
145
122
  return s;
146
- }, w = (t, e, n) => e >= n ? [] : k(k(t, n)[0], e)[1].children, M = (t, e, n) => t.split("\n").map(t => ({
123
+ }, E = (t, e, n) => e >= n ? [] : g(g(t, n)[0], e)[1].children, M = ([t, e]) => t > e ? [ e, t ] : [ t, e ], S = ([t, e]) => t === e, A = ([t, e], n) => n ? t < e : t <= e, O = (t, e, n) => t.split("\n").map(t => ({
147
124
  ...n,
148
125
  children: [ {
149
126
  ...e,
150
127
  text: t
151
128
  } ]
152
- })), S = "delete", A = "insert_text", O = "insert_node", R = (t, e) => {
129
+ })), R = "delete", D = "insert_text", B = "insert_node", I = "format", L = ({type: t}) => t !== D && t !== R, P = (t, e) => {
153
130
  const o = n(t);
154
131
  return o.length === n(e).length && o.every(n => n in e && ("text" === n || r(t[n], e[n])));
155
- }, D = (t, e) => {
156
- if (e.length) {
157
- const n = t.length;
158
- if (t.push(...e), n) {
159
- const e = t[n - 1], r = t[n], o = l(e), c = l(r);
160
- o ? c && ((t, e = 0, n = t.length - 1) => {
161
- let r = e + 1;
162
- for (;r <= n; ) {
163
- const e = t[r - 1], o = t[r];
164
- t[r - 1] = B(e, o), t.splice(r, 1), n--;
165
- }
166
- })(t, n - 1, n) : o || c || ((t, e = 0, n = t.length - 1) => {
167
- let r = e + 1;
168
- for (;r <= n; ) {
169
- const e = t[r - 1], o = t[r];
170
- i(e) && i(o) && R(e, o) ? (t[r - 1] = {
171
- ...e,
172
- text: e.text + o.text
173
- }, t.splice(r, 1), n--) : r++;
174
- }
175
- for (r = e; r <= n; ) {
176
- const e = t[r];
177
- i(e) && !e.text && t.length > 1 ? (t.splice(r, 1), n--) : r++;
178
- }
179
- })(t, n - 1, n);
132
+ }, H = t => {
133
+ const e = [];
134
+ let n;
135
+ for (let r of t) i(r) && !r.text || (n && i(n) && i(r) && P(n, r) && (r = {
136
+ ...n,
137
+ text: n.text + r.text
138
+ }, e.pop()), e.push(n = r));
139
+ return e.length ? e : t.slice(-1);
140
+ }, N = (t, e) => {
141
+ const n = t.length - 1, r = t.concat(e);
142
+ if (n >= 0 && e.length) {
143
+ const e = l(r[n]);
144
+ if (e === l(r[n + 1])) {
145
+ if (!e) return t.slice(0, n).concat(H(r.slice(n)));
146
+ r.splice(n, 2, W(r.slice(n, n + 2)));
180
147
  }
181
148
  }
182
- t.length || t.push({
149
+ return r.length || r.push({
183
150
  text: ""
184
- });
185
- }, B = (...t) => ({
151
+ }), r;
152
+ }, W = t => ({
186
153
  ...t[0],
187
- children: t.reduce((t, e) => (D(t, e.children), t), [])
188
- }), I = (t, e, n, r = 0) => {
189
- if (r < e.length) {
190
- const o = e[r], c = t.children, s = c.slice();
191
- return s.splice(o, 1, I(c[o], e, n, r + 1)), {
192
- ...t,
193
- children: s
194
- };
195
- }
196
- return n;
197
- }, L = (t, e, n, r) => {
198
- const [o, c] = k(t, e), s = e < n ? k(t, n)[1] : c, i = a(t.children);
199
- a(r) ? i || (r = B(...r).children) : i && (r = [ {
154
+ children: t.reduce((t, e) => N(t, e.children), [])
155
+ }), C = (t, {range: e, depth: n = -1}, r) => {
156
+ const o = S(e), s = (t, e) => n < 0 ? !!(t & 1 << -n - 1) : n === e, c = (t, e, n, a) => {
157
+ let f = 0, u = !1, d = 0, y = 0;
158
+ const x = [];
159
+ for (const [g, m, k, v] of b(t, e)) {
160
+ x.length || (d = k);
161
+ const t = A(v, p(g)), e = a + m;
162
+ let h = g;
163
+ if (l(g)) {
164
+ let t;
165
+ [h, t] = c(g, v, n + 1, e), f |= t << 1;
166
+ } else if ((t || o) && (f |= 2), t && s(1, n + 1)) {
167
+ const [t, o] = v, s = [ e + t, e + o ];
168
+ i(g) ? (t > 0 && x.push({
169
+ ...g,
170
+ text: g.text.slice(0, t)
171
+ }), h = r({
172
+ ...g,
173
+ text: g.text.slice(t, o)
174
+ }, n + 1, s), o < g.text.length && (x.push(h), h = {
175
+ ...g,
176
+ text: g.text.slice(o)
177
+ })) : h = r(g, n + 1, s);
178
+ }
179
+ h !== g && (u = !0), x.push(h), y = k;
180
+ }
181
+ let h = t;
182
+ if (u) {
183
+ const {children: e} = t, n = e.slice(0, d).concat(x, e.slice(y + 1));
184
+ h = {
185
+ ...t,
186
+ children: H(n)
187
+ };
188
+ }
189
+ return s(f, n) && (h = r(h, n, [ a + e[0], a + e[1] ])), [ h, f ];
190
+ };
191
+ return c(t, e, 0, 0)[0];
192
+ }, F = (t, e, n, r) => {
193
+ const o = !r.length, [s, c] = g(t, e, o), i = e < n ? g(t, n, o)[1] : c, l = a(r);
194
+ return l !== a(t.children) && (r = l ? W(r).children : [ {
200
195
  children: r
201
- } ]);
202
- const l = o.children.slice();
203
- return D(l, r), D(l, s.children), {
196
+ } ]), {
204
197
  ...t,
205
- children: l
198
+ children: N(N(s.children, r), i.children)
206
199
  };
207
- }, P = (t, e) => e >= 0 && e <= p(t), H = (t, e) => e.reduce((t, e) => N(t, e), t), N = (t, e, n) => {
200
+ }, U = (t, e) => e >= 0 && e <= p(t), V = (t, e) => e.reduce((t, e) => q(t, e), t), q = (t, e, n) => {
208
201
  switch (e.type) {
209
- case S:
202
+ case R:
210
203
  {
211
204
  const [n, r] = e.range;
212
205
  if (t >= n) return r >= t ? n : t + n - r;
213
206
  break;
214
207
  }
215
208
 
216
- case A:
209
+ case D:
210
+ case B:
217
211
  {
218
- const {at: r, text: o} = e;
219
- if (n ? t > r : t >= r) return t + o.length;
212
+ const {at: r} = e;
213
+ if (n ? t > r : t >= r) return t + (e.type === D ? e.text.length : p({
214
+ children: e.fragment
215
+ }));
216
+ break;
217
+ }
218
+ }
219
+ return t;
220
+ }, z = ([t, e], n) => [ q(t, n), q(e, n) ], G = (t, [e, n]) => U(t, e) && U(t, n), J = (t, e, n) => {
221
+ switch (n.type) {
222
+ case R:
223
+ {
224
+ const [r, o] = n.range;
225
+ G(t, n.range) && r < o && (t = F(t, r, o, []), e = z(e, n));
220
226
  break;
221
227
  }
222
228
 
223
- case O:
229
+ case D:
224
230
  {
225
- const {at: r, fragment: o} = e;
226
- if (n ? t > r : t >= r) return t + p({
227
- children: o
228
- });
231
+ const {at: r, text: o} = n;
232
+ if (U(t, r) && o) {
233
+ const [s, c] = y(t, r), l = d(s, c, !0);
234
+ t = F(t, r, r, O(o, l && i(l[0]) ? l[0] : void 0, s)), e = z(e, n);
235
+ }
236
+ break;
237
+ }
238
+
239
+ case B:
240
+ {
241
+ const {at: r, fragment: o} = n;
242
+ U(t, r) && o.length && (t = F(t, r, r, o), e = z(e, n));
243
+ break;
244
+ }
245
+
246
+ case I:
247
+ {
248
+ const {range: e, key: r, value: o, depth: s} = n;
249
+ "text" !== r && ("children" !== r || 0 === s) && G(t, e) && e[0] <= e[1] && (t = C(t, n, t => {
250
+ if (void 0 !== o) return {
251
+ ...t,
252
+ [r]: o
253
+ };
254
+ const {[r]: e, ...n} = t;
255
+ return n;
256
+ }));
229
257
  break;
230
258
  }
231
259
  }
232
- return t;
233
- }, C = ([t, e], n) => [ N(t, n), N(e, n) ], W = ([t, e]) => t > e ? [ e, t ] : [ t, e ], F = ([t, e]) => t === e, U = ([t, e], [n, r]) => t < r && n < e;
260
+ return [ t, e ];
261
+ }, j = (t, e) => {
262
+ switch (e.type) {
263
+ case R:
264
+ {
265
+ const {range: n} = e;
266
+ return [ {
267
+ type: B,
268
+ at: n[0],
269
+ fragment: E(t, ...n)
270
+ } ];
271
+ }
234
272
 
235
- function* V(t, e = W(t.selection)) {
236
- if (F(e)) {
237
- const n = y(t.doc, e[0])?.[0];
273
+ case D:
274
+ case B:
275
+ {
276
+ const {at: n} = e, r = [ {
277
+ type: R,
278
+ range: [ n, q(n, e) ]
279
+ } ], [o] = y(t, n);
280
+ return p(o) || r.push({
281
+ type: B,
282
+ at: n,
283
+ fragment: o.children
284
+ }), r;
285
+ }
286
+
287
+ case I:
288
+ {
289
+ const {key: n} = e, o = [];
290
+ let s;
291
+ return C(t, e, (t, e, c) => {
292
+ const i = t[n];
293
+ return s && s.depth === e && r(s.value, i) && c[0] - s.range[1] <= 1 && (c = [ s.range[0], c[1] ],
294
+ o.pop()), s = {
295
+ type: I,
296
+ range: c,
297
+ key: n,
298
+ value: i,
299
+ depth: e
300
+ }, o.push(s), t;
301
+ }), o;
302
+ }
303
+
304
+ default:
305
+ return e;
306
+ }
307
+ };
308
+
309
+ function* X(t, e = M(t.selection)) {
310
+ if (S(e)) {
311
+ const n = x(t.doc, e[0])?.[0];
238
312
  n && (yield n);
239
- } else for (const [n, r] of T(t.doc, e)) U(e, [ r, r + p(n) ]) && (yield n);
313
+ } else for (const [n, , r] of T(t.doc, e)) A(r, p(n)) && (yield n);
240
314
  }
241
315
 
242
- function q(t, e) {
243
- t.apply({
244
- type: "patch_node",
245
- path: [],
246
- key: "children",
247
- value: e
248
- });
316
+ function* Y(t, e = M(t.selection)) {
317
+ const n = t.doc;
318
+ if (S(e)) {
319
+ const [t, r] = y(n, e[0]);
320
+ yield [ t, e[0] - r, [ r, r ] ];
321
+ } else for (const r of _(n, e)) A(r[2], p(r[0])) && (yield r);
249
322
  }
250
323
 
251
- var z = t => 1 === t.nodeType, G = t => 8 === t.nodeType, J = new Map([ [ "BR", 1 ], [ "WBR", 1 ], [ "AREA", 2 ], [ "BASE", 2 ], [ "DATALIST", 2 ], [ "HEAD", 2 ], [ "LINK", 2 ], [ "META", 2 ], [ "RP", 2 ], [ "SCRIPT", 2 ], [ "STYLE", 2 ], [ "TEMPLATE", 2 ], [ "TITLE", 2 ], [ "COLGROUP", 2 ], [ "HR", 3 ], [ "AUDIO", 3 ], [ "CANVAS", 3 ], [ "EMBED", 3 ], [ "IFRAME", 3 ], [ "IMG", 3 ], [ "OBJECT", 3 ], [ "PICTURE", 3 ], [ "VIDEO", 3 ], [ "SVG", 3 ], [ "MATH", 3 ], [ "BUTTON", 3 ], [ "INPUT", 3 ], [ "METER", 3 ], [ "PROGRESS", 3 ], [ "SELECT", 3 ], [ "TEXTAREA", 3 ] ]), X = new Set([ "DIV", "H1", "H2", "H3", "H4", "H5", "H6", "P", "PRE", "LI", "DT", "DD", "TH", "TD" ]), Y = t => X.has(t.tagName), j = (t, e) => t.compareDocumentPosition(e), Z = t => t.ownerDocument, K = t => Z(t).getSelection(), Q = (t, e) => {
324
+ function* Z(t, [e, n]) {
325
+ if (e >= n) return void (yield [ e, n ]);
326
+ let r = e;
327
+ for (const [o, s, c] of T(t.doc, [ e, n ])) !i(o) && A(c, p(o)) && (r < s && (yield [ r, s ]),
328
+ r = s + 1);
329
+ r < n && (yield [ r, n ]);
330
+ }
331
+
332
+ var K = t => 1 === t.nodeType, Q = t => 8 === t.nodeType, $ = new Map([ [ "BR", 1 ], [ "WBR", 1 ], [ "AREA", 2 ], [ "BASE", 2 ], [ "DATALIST", 2 ], [ "HEAD", 2 ], [ "LINK", 2 ], [ "META", 2 ], [ "RP", 2 ], [ "SCRIPT", 2 ], [ "STYLE", 2 ], [ "TEMPLATE", 2 ], [ "TITLE", 2 ], [ "COLGROUP", 2 ], [ "HR", 3 ], [ "AUDIO", 3 ], [ "CANVAS", 3 ], [ "EMBED", 3 ], [ "IFRAME", 3 ], [ "IMG", 3 ], [ "OBJECT", 3 ], [ "PICTURE", 3 ], [ "VIDEO", 3 ], [ "SVG", 3 ], [ "MATH", 3 ], [ "BUTTON", 3 ], [ "INPUT", 3 ], [ "METER", 3 ], [ "PROGRESS", 3 ], [ "SELECT", 3 ], [ "TEXTAREA", 3 ] ]), tt = new Set([ "DIV", "H1", "H2", "H3", "H4", "H5", "H6", "P", "PRE", "LI", "DT", "DD", "TH", "TD" ]), et = t => tt.has(t.tagName), nt = (t, e) => t.compareDocumentPosition(e), rt = t => t.ownerDocument, ot = t => rt(t).getSelection(), st = (t, e) => {
252
333
  if (t.rangeCount) {
253
334
  const n = t.getRangeAt(0);
254
335
  if (e.contains(n.commonAncestorContainer)) return n;
255
336
  }
256
- }, $ = (t, e, n, r) => {
257
- const [o, c] = ((t, [e, n]) => [ g(t, e), g(t, n) ])(n, r), s = Z(t), i = F(r), l = r[0] - r[1] > 0, a = l ? o : c, u = et(t, e, l ? c : o), f = i ? u : et(t, e, a), p = s.createRange(), [d, h] = u, [y, x] = f;
258
- return z(d) && t !== d ? h < 1 ? p.setStartBefore(d) : p.setStartAfter(d) : p.setStart(d, h),
259
- z(y) && t !== y ? x < 1 ? p.setEndBefore(y) : p.setEndAfter(y) : p.setEnd(y, x),
337
+ }, ct = (t, e, n, r) => {
338
+ const [o, s] = ((t, [e, n]) => [ k(t, e), k(t, n) ])(n, r), c = rt(t), i = S(r), l = r[0] - r[1] > 0, a = l ? o : s, f = lt(t, e, l ? s : o), u = i ? f : lt(t, e, a), p = c.createRange(), [d, y] = f, [x, h] = u;
339
+ return K(d) && t !== d ? y < 1 ? p.setStartBefore(d) : p.setStartAfter(d) : p.setStart(d, y),
340
+ K(x) && t !== x ? h < 1 ? p.setEndBefore(x) : p.setEndAfter(x) : p.setEnd(x, h),
260
341
  p;
261
- }, tt = (t, e, n, r, o) => {
262
- const c = K(t);
263
- if (o || Q(c, t)) {
264
- const o = $(t, e, n, r), s = r[0] - r[1] > 0;
265
- c.removeAllRanges(), c.addRange(o), s && (c.collapseToEnd(), c.extend(o.startContainer, o.startOffset));
342
+ }, it = (t, e, n, r, o) => {
343
+ const s = ot(t);
344
+ if (o || st(s, t)) {
345
+ const o = ct(t, e, n, r), c = r[0] - r[1] > 0;
346
+ s.removeAllRanges(), s.addRange(o), c && (s.collapseToEnd(), s.extend(o.startContainer, o.startOffset));
266
347
  }
267
- }, et = (t, e, [n, r]) => e(({t: e, o, i: c, l: s}) => {
348
+ }, lt = (t, e, [n, r]) => e(({t: e, o, i: s, l: c}) => {
268
349
  let i, l = 0;
269
350
  for (;i = e(); ) if (4 === i) {
270
351
  if (l < n.length) for (let t = n[l++]; t > 0; t--) o();
271
352
  } else {
272
- const t = s();
273
- if (r <= t) return [ c(), r ];
353
+ const t = c();
354
+ if (r <= t) return [ s(), r ];
274
355
  r -= t;
275
356
  }
276
357
  return [ t, 0 ];
277
- }, t), nt = (e, n, r, o) => {
278
- let c = !0;
358
+ }, t), at = (e, n, r, o) => {
359
+ let s = !0;
279
360
  if (e === r && !r.hasChildNodes()) return [ [], 0 ];
280
- if (z(r) && r.hasChildNodes()) {
361
+ if (K(r) && r.hasChildNodes()) {
281
362
  const e = t(o, r.childNodes.length - 1);
282
- r = r.childNodes[e], c = e === o, o = 0;
363
+ r = r.childNodes[e], s = e === o, o = 0;
283
364
  }
284
- return n(({t, u: s, p: i, h: l, i: a, l: u, k: f}) => {
285
- s(r), 4 !== f() && i();
365
+ return n(({t, u: c, p: i, h: l, i: a, l: f, m: u}) => {
366
+ c(r), 4 !== u() && i();
286
367
  const p = n(() => {
287
368
  const t = [];
288
- for (;f() && a() !== e; ) {
369
+ for (;u() && a() !== e; ) {
289
370
  let e = 0;
290
- for (;l(), f(); ) e++;
371
+ for (;l(), u(); ) e++;
291
372
  t.unshift(e), i();
292
373
  }
293
374
  return t;
294
375
  });
295
376
  let d = 0;
296
377
  for (;t(); ) {
297
- const t = j(r, a());
378
+ const t = nt(r, a());
298
379
  if (0 === t || 16 & t) {
299
- if (c) break;
380
+ if (s) break;
300
381
  } else if (4 & t) break;
301
- d += u();
382
+ d += f();
302
383
  }
303
384
  return [ p, d + o ];
304
385
  }, e);
305
- }, rt = (t, e, {startOffset: n, startContainer: r, endOffset: o, endContainer: c}) => {
306
- const s = nt(t, e, r, n);
307
- return [ s, r === c && n === o ? s : nt(t, e, c, o) ];
308
- }, ot = "undefined" != typeof navigator && /Mac|iP(hone|od|ad)/.test(navigator.platform), ct = (t, e) => {
309
- const n = t.endsWith("+"), r = (n ? t.slice(0, -2) : t).split("+"), o = n ? "+" : r.pop(), c = "Space" === o ? " " : o.toLowerCase();
310
- let s = !1, i = !1, l = !1, a = !1;
386
+ }, ft = (t, e, {startOffset: n, startContainer: r, endOffset: o, endContainer: s}) => {
387
+ const c = at(t, e, r, n);
388
+ return [ c, r === s && n === o ? c : at(t, e, s, o) ];
389
+ }, ut = "undefined" != typeof navigator && /Mac|iP(hone|od|ad)/.test(navigator.platform), pt = (t, e) => {
390
+ const n = t.endsWith("+"), r = (n ? t.slice(0, -2) : t).split("+"), o = n ? "+" : r.pop(), s = "Space" === o ? " " : o.toLowerCase();
391
+ let c = !1, i = !1, l = !1, a = !1;
311
392
  return r.forEach(t => {
312
393
  switch (t) {
313
394
  case "Ctrl":
@@ -319,7 +400,7 @@ var z = t => 1 === t.nodeType, G = t => 8 === t.nodeType, J = new Map([ [ "BR",
319
400
  break;
320
401
 
321
402
  case "Mod":
322
- ot ? l = !0 : i = !0;
403
+ ut ? l = !0 : i = !0;
323
404
  break;
324
405
 
325
406
  case "Alt":
@@ -327,251 +408,171 @@ var z = t => 1 === t.nodeType, G = t => 8 === t.nodeType, J = new Map([ [ "BR",
327
408
  break;
328
409
 
329
410
  case "Shift":
330
- s = !0;
411
+ c = !0;
331
412
  }
332
413
  }), t => {
333
- if (t.key.toLowerCase() === c && i === t.ctrlKey && l === t.metaKey && s === t.shiftKey && a === t.altKey) return !1 !== e(t);
414
+ if (t.key.toLowerCase() === s && i === t.ctrlKey && l === t.metaKey && c === t.shiftKey && a === t.altKey) return !1 !== e(t);
334
415
  };
335
416
  };
336
417
 
337
- function st(t) {
338
- let e = 0, r = 0, o = !1;
339
- const c = Date.now, s = [ [ t.doc, t.selection, [] ] ], i = () => s[e], l = () => e > 0, a = () => e < s.length - 1, u = e => {
340
- t.exec(q, e.children);
341
- const r = e, o = t.doc;
342
- for (const c of n(r)) "children" !== c && o[c] !== r[c] && t.apply({
343
- type: "patch_node",
344
- path: [],
345
- key: c,
346
- value: r[c]
347
- });
348
- for (const c of n(o)) "children" === c || c in r || t.apply({
349
- type: "patch_node",
350
- path: [],
351
- key: c,
352
- value: void 0
353
- });
354
- }, f = () => {
355
- if (l()) {
356
- const n = i()[1];
357
- e--;
358
- const r = t.doc;
359
- o = !0, u(i()[0]), o = !1, r !== t.doc && (t.selection = n);
418
+ function dt(t) {
419
+ let e = 0, n = new WeakMap;
420
+ const r = Date.now, o = [], s = [], c = ([t, e], [, n]) => [ t, n.concat(e) ], i = () => {
421
+ const e = n.get(t.doc);
422
+ return n = new WeakMap, e;
423
+ }, l = () => {
424
+ let t = i();
425
+ if (t) {
426
+ const n = r();
427
+ o.length && n - e < 500 && (t = c(o.pop(), t)), e = n, o.push(t), s.length = 0,
428
+ o.length > 100 && o.shift();
360
429
  }
361
- }, p = () => {
362
- if (a()) {
363
- e++;
364
- const [n, r, c] = i(), s = t.doc;
365
- o = !0, u(n), o = !1, s !== t.doc && (t.selection = [ H(r[0], c), H(r[1], c) ]);
430
+ }, a = (e, n) => {
431
+ if (l(), e.length) {
432
+ const [r, o] = e[e.length - 1];
433
+ t.apply(o);
434
+ const s = i();
435
+ s && (e.pop(), n.push(s), t.selection = r);
366
436
  }
437
+ }, f = () => {
438
+ a(o, s);
439
+ }, u = () => {
440
+ a(s, o);
367
441
  };
368
- t.hook("apply", (n, i) => {
369
- if (o) return;
370
- const l = t.doc, a = t.selection;
371
- i(n);
372
- const u = t.doc;
373
- if (l !== u) {
374
- const t = c();
375
- if (0 === e || t - r >= 500) {
376
- e++;
377
- const t = [ l, a, [] ];
378
- e >= s.length ? s.push(t) : s[e] = t;
379
- }
380
- r = t, s[e][0] = u, s[e][2].push(n), s.length > e + 1 && (s.length = e + 1), e > 500 && (e--,
381
- s.shift());
442
+ t.hook("apply", (e, r) => {
443
+ const o = t.doc, s = t.selection, i = r(e), l = t.doc;
444
+ if (i && o !== l) {
445
+ const t = [ s, j(o, i) ], e = n.get(o);
446
+ n.set(l, e ? c(e, t) : t);
382
447
  }
383
- }), t.hook("keyboard", ct("Mod+Z", f)), t.hook("keyboard", ct("Shift+Mod+Z", p)),
384
- t.set(st, {
448
+ }), t.on("change", l), t.hook("keyboard", pt("Mod+Z", f)), t.hook("keyboard", pt("Shift+Mod+Z", u)),
449
+ t.set(dt, {
385
450
  undo: f,
386
- redo: p,
387
- undoable: l,
388
- redoable: a,
389
- clear: () => {
390
- s.length = 0, s.push([ t.doc, t.selection, [] ]), e = 0, r = 0;
391
- }
451
+ redo: u,
452
+ stack: t => (l(), t ? s : o)
392
453
  });
393
454
  }
394
455
 
395
- var it = [], lt = () => {}, at = t => {
456
+ var yt = [], xt = () => {}, ht = t => {
396
457
  throw Error(t);
397
- }, ut = ({doc: t, readonly: e = !1, schema: n, isBlock: r = Y, onWarn: a = console.warn, onError: u = at}) => {
398
- let f = [ 0, 0 ];
399
- const p = t => {
400
- if (!n) return a("An unsafe operation was detected. We recommend using schema option."),
458
+ }, gt = ({doc: t, readonly: e = !1, schema: n, isBlock: r = et, onWarn: i = console.warn, onError: l = ht}) => {
459
+ let a = [ 0, 0 ];
460
+ const f = t => {
461
+ if (!n) return i("An unsafe operation was detected. We recommend using schema option."),
401
462
  !0;
402
463
  const e = n["~standard"].validate(t);
403
- if (e instanceof Promise) u("async validate is not supported"); else {
464
+ if (e instanceof Promise) l("async validate is not supported"); else {
404
465
  if (!e.issues) return !0;
405
- a(e.issues.map(t => t.message).join("\n"));
466
+ i(e.issues.map(t => t.message).join("\n"));
406
467
  }
407
468
  return !1;
408
469
  };
409
- n && !p(t) && u("Invalid document");
410
- const y = new Map, x = new WeakMap, k = t => y.get(t) || it, g = new Map, b = new Set, v = t => {
411
- const e = g.get(t);
412
- e && (b.size || s(() => {
413
- b.forEach(t => {
470
+ n && !f(t) && l("Invalid document");
471
+ const u = new Map, p = new WeakMap, d = t => u.get(t) || yt, y = new Map;
472
+ let x = new Set;
473
+ const h = t => {
474
+ const e = y.get(t);
475
+ e && (x.size || c(() => {
476
+ const t = x;
477
+ x = new Set, t.forEach(t => {
414
478
  t();
415
- }), b.clear();
479
+ });
416
480
  }), e.forEach(t => {
417
- b.add(t);
481
+ x.add(t);
418
482
  }));
419
- }, T = t => {
420
- if (!e) if (Array.isArray(t)) for (const e of t) E(e); else E(t);
421
- return D;
422
- }, E = e => {
423
- const n = t, r = k("apply"), o = r.length;
424
- let c = 0;
425
- const s = () => {
426
- if (c < o) {
427
- const t = c;
428
- r[c](e, u), t === c && u(e);
429
- } else if (c === o) {
430
- c++;
431
- try {
432
- const [n, r] = ((t, e, n) => {
433
- switch (n.type) {
434
- case S:
435
- {
436
- const [r, o] = n.range;
437
- P(t, r) && P(t, o) && r < o && (t = L(t, r, o, []), e = C(e, n));
438
- break;
439
- }
440
-
441
- case A:
442
- {
443
- const {at: r, text: o} = n;
444
- if (P(t, r) && o) {
445
- const [c, s] = h(t, r), l = d(c, s, !0);
446
- let a;
447
- if (l) {
448
- const t = l[0];
449
- i(t) && (a = t);
450
- }
451
- t = L(t, r, r, M(o, a, c)), e = C(e, n);
452
- }
453
- break;
454
- }
455
-
456
- case O:
457
- {
458
- const {at: r, fragment: o} = n;
459
- P(t, r) && o.length && (t = L(t, r, r, o), e = C(e, n));
460
- break;
461
- }
462
-
463
- case "format":
464
- {
465
- const {range: [e, r], key: o, value: c} = n;
466
- if (P(t, e) && P(t, r) && e <= r) if (e === r) {
467
- const [{children: n}, , r] = h(t, e);
468
- if (1 === n.length) {
469
- const e = n[0];
470
- i(e) && !e.text && (t = I(t, [ ...r, 0 ], {
471
- ...e,
472
- [o]: c
473
- }));
474
- }
475
- } else {
476
- const n = t => l(t) ? {
477
- ...t,
478
- children: t.children.map(n)
479
- } : i(t) ? {
480
- ...t,
481
- [o]: c
482
- } : t;
483
- t = L(t, e, r, w(t, e, r).map(n));
484
- }
485
- break;
486
- }
487
-
488
- case "patch_node":
489
- {
490
- const {path: e, key: r, value: o} = n, c = ((t, e) => {
491
- for (let n = 0; n < e.length; n++) t = t.children[e[n]];
492
- return t;
493
- })(t, e);
494
- c && (t = I(t, e, {
495
- ...c,
496
- [r]: o
497
- }));
498
- break;
483
+ }, g = n => {
484
+ if (!e) {
485
+ const e = d("apply"), r = e.length, o = t, s = a;
486
+ let c = !1;
487
+ try {
488
+ let o = !1;
489
+ for (let s of Array.isArray(n) ? n : [ n ]) {
490
+ let n = 0, c = null;
491
+ const l = () => {
492
+ if (n < r) {
493
+ const t = n;
494
+ e[n](s, f), t === n && f(s);
495
+ } else if (n === r) {
496
+ n++;
497
+ try {
498
+ const [e, n] = J(t, a, s);
499
+ t = e, k(n), c = s, L(s) && (o = !0);
500
+ } catch (l) {
501
+ i("rollback operation: " + l);
499
502
  }
500
503
  }
501
- return [ t, e ];
502
- })(t, f, e);
503
- (({type: t}) => t !== A && t !== S)(e) && !p(n) || (t = n, R(r));
504
- } catch (n) {
505
- a("rollback operation: " + n);
504
+ }, f = t => (null == t ? n = r + 1 : (s = t, n++, l()), c);
505
+ if (l(), !c) return b;
506
506
  }
507
+ c = !o || f(t);
508
+ } finally {
509
+ c || (t = o, a = s);
507
510
  }
508
- }, u = t => {
509
- null != t ? (e = t, c++, s()) : c = o + 1;
510
- };
511
- s(), n !== t && v("change");
512
- }, R = e => {
513
- !((t, [e, n]) => P(t, e) && P(t, n))(t, e) || f[0] === e[0] && f[1] === e[1] || (f = e,
514
- v("selectionchange"));
515
- }, D = {
511
+ t !== o && h("change");
512
+ }
513
+ return b;
514
+ }, k = e => {
515
+ !G(t, e) || a[0] === e[0] && a[1] === e[1] || (a = e, h("selectionchange"));
516
+ }, b = {
516
517
  get doc() {
517
518
  return t;
518
519
  },
519
520
  get selection() {
520
- return f;
521
+ return a;
521
522
  },
522
523
  set selection(t) {
523
- R(t);
524
+ k(t);
524
525
  },
525
526
  get readonly() {
526
527
  return e;
527
528
  },
528
529
  set readonly(t) {
529
- e = t, v("readonly");
530
+ e = t, h("readonly");
530
531
  },
531
- apply: T,
532
+ apply: g,
532
533
  on: (t, e) => {
533
- let n = g.get(t);
534
- return n || g.set(t, n = new Set), n.add(e), () => {
534
+ let n = y.get(t);
535
+ return n || y.set(t, n = new Set), n.add(e), () => {
535
536
  n.delete(e);
536
537
  };
537
538
  },
538
539
  hook: (t, e) => {
539
- let n = y.get(t);
540
- return n || y.set(t, n = []), n.push(e), () => {
540
+ let n = u.get(t);
541
+ return n || u.set(t, n = []), n.push(e), () => {
541
542
  const t = n.indexOf(e);
542
543
  -1 !== t && n.splice(t, 1);
543
544
  };
544
545
  },
545
546
  exec: (t, ...e) => {
546
- const n = t(D, ...e);
547
- return void 0 === n ? D : n;
547
+ const n = t(b, ...e);
548
+ return void 0 === n ? b : n;
548
549
  },
549
- get: t => (x.has(t) || u("No value found for key"), x.get(t)),
550
- set: (t, e) => (x.set(t, e), D),
550
+ get: t => (p.has(t) || l("No value found for key"), p.get(t)),
551
+ set: (t, e) => (p.set(t, e), b),
551
552
  input: n => {
552
- if (!window.InputEvent || !c(InputEvent.prototype.getTargetRanges)) return a("beforeinput event is not supported."),
553
- lt;
554
- const {contentEditable: s, role: i, ariaMultiLine: l, ariaReadOnly: u} = n, p = n.style.whiteSpace;
553
+ if (!window.InputEvent || !s(InputEvent.prototype.getTargetRanges)) return i("beforeinput event is not supported."),
554
+ xt;
555
+ const {contentEditable: c, role: l, ariaMultiLine: f, ariaReadOnly: u} = n, p = n.style.whiteSpace;
555
556
  n.role = "textbox", n.style.whiteSpace = "pre-wrap", n.ariaMultiLine = "true";
556
- let d = !1, h = null, y = !1, x = !1, g = !1, b = f, v = null;
557
- const E = Z(n), w = ((t, e) => {
557
+ let y = !1, x = null, h = !1, _ = !1, T = !1, w = a, E = null;
558
+ const A = rt(n), O = ((t, e) => {
558
559
  let n = null, r = null, o = null;
559
- const c = () => {
560
+ const s = () => {
560
561
  if (null != o) return o;
561
562
  if (r) if ((t => 3 === t.nodeType)(r)) {
562
563
  const t = r.data;
563
564
  if (t) return o = "\n" === t ? i() ? 3 : 5 : 1;
564
- } else if (z(r)) {
565
+ } else if (K(r)) {
565
566
  if ("false" === r.contentEditable) return o = 2;
566
567
  {
567
- const t = J.get(r.tagName);
568
+ const t = $.get(r.tagName);
568
569
  if (null != t) return o = 1 === t ? i() ? 3 : 5 : 3 === t ? 2 : 6;
569
570
  if (e(r)) return o = 4;
570
571
  }
571
572
  } else if (!(t => 11 === t.nodeType)(r)) return o = 6;
572
573
  return o = 0;
573
- }, s = () => {
574
- const t = c();
574
+ }, c = () => {
575
+ const t = s();
575
576
  if (o = null, 2 === t || 6 === t) {
576
577
  const t = r;
577
578
  if (r = n.nextSibling(), !r) for (;(r = n.nextNode()) && t.contains(r); ) ;
@@ -580,30 +581,30 @@ var it = [], lt = () => {}, at = t => {
580
581
  return r = n.nextNode();
581
582
  }, i = () => {
582
583
  const t = r.parentNode;
583
- return f(() => {
584
- for (o = 0; s(); ) {
585
- if (c()) return !0;
584
+ return u(() => {
585
+ for (o = 0; c(); ) {
586
+ if (s()) return !0;
586
587
  if (!t.contains(r)) break;
587
588
  }
588
589
  return !1;
589
590
  });
590
591
  }, l = () => {
591
- const t = c();
592
+ const t = s();
592
593
  return 0 === t || 6 === t;
593
594
  }, a = (t, e) => {
594
- for (;(o = null) || (r = t ? n.previousSibling() : n.nextSibling()); ) if (e ? 4 === c() : !l()) return !0;
595
+ for (;(o = null) || (r = t ? n.previousSibling() : n.nextSibling()); ) if (e ? 4 === s() : !l()) return !0;
595
596
  return !1;
596
- }, u = {
597
+ }, f = {
597
598
  t: () => {
598
- for (;s(); ) {
599
- const t = c();
599
+ for (;c(); ) {
600
+ const t = s();
600
601
  if (t && 6 !== t) return t;
601
602
  }
602
603
  },
603
- k: c,
604
+ m: s,
604
605
  i: () => r,
605
606
  l: () => {
606
- const t = c();
607
+ const t = s();
607
608
  return 1 === t ? r.data.length : 2 === t ? 1 : 0;
608
609
  },
609
610
  u: t => {
@@ -617,62 +618,62 @@ var it = [], lt = () => {}, at = t => {
617
618
  a(!1, !0);
618
619
  },
619
620
  p: () => {
620
- for (;(o = null) || (r = n.parentNode()); ) if (4 === c()) return;
621
+ for (;(o = null) || (r = n.parentNode()); ) if (4 === s()) return;
621
622
  }
622
- }, f = (e, c) => {
623
- const s = n, i = r, l = o;
623
+ }, u = (e, s) => {
624
+ const c = n, i = r, l = o;
624
625
  try {
625
- return n || (n = t.createTreeWalker(r = c, 5)), e(u);
626
+ return n || (n = t.createTreeWalker(r = s, 5)), e(f);
626
627
  } finally {
627
- n = s, r = i, o = l, n && i && (n.currentNode = i);
628
+ n = c, r = i, o = l, n && i && (n.currentNode = i);
628
629
  }
629
630
  };
630
- return f;
631
- })(E, r), M = () => {
631
+ return u;
632
+ })(A, r), R = () => {
632
633
  n.contentEditable = e ? "false" : "true", n.ariaReadOnly = e ? "true" : null;
633
634
  };
634
- M();
635
- const S = () => {
636
- x || n.focus({
635
+ R();
636
+ const D = () => {
637
+ _ || (it(n, O, t, a, !0), w = a, n.focus({
637
638
  preventScroll: !0
638
- });
639
- }, A = () => {
640
- v = null, f[0] === b[0] && f[1] === b[1] || (tt(n, w, t, f), b = f);
641
- }, O = () => {
642
- null != v && clearTimeout(v);
643
- }, B = D.on("change", () => {
644
- x || requestAnimationFrame(S);
645
- }), I = D.on("selectionchange", () => {
646
- f[0] === b[0] && f[1] === b[1] || (O(), v = setTimeout(A, 50));
647
- }), L = D.on("readonly", M), P = t => {
648
- for (const e of k("paste")) {
639
+ }));
640
+ }, B = () => {
641
+ E = null, a[0] === w[0] && a[1] === w[1] || (it(n, O, t, a), w = a);
642
+ }, I = () => {
643
+ null != E && clearTimeout(E);
644
+ }, L = b.on("change", () => {
645
+ _ || requestAnimationFrame(D);
646
+ }), P = b.on("selectionchange", () => {
647
+ a[0] === w[0] && a[1] === w[1] || (I(), E = setTimeout(B, 50));
648
+ }), H = b.on("readonly", R), N = t => {
649
+ for (const e of d("paste")) {
649
650
  const n = e(t);
650
651
  if (n) {
651
652
  if (!0 === n) return;
652
653
  return n;
653
654
  }
654
655
  }
655
- a("failed to serialize pasted data");
656
- }, N = ((t, e) => {
656
+ i("failed to serialize pasted data");
657
+ }, W = ((t, e) => {
657
658
  let n = !1, r = [];
658
659
  const o = t => {
659
660
  n && r.push(...t);
660
- }, c = new MutationObserver(t => {
661
+ }, s = new MutationObserver(t => {
661
662
  o(t), n || e();
662
- }), s = () => {
663
- o(c.takeRecords());
663
+ }), c = () => {
664
+ o(s.takeRecords());
664
665
  }, i = () => {
665
- s();
666
+ c();
666
667
  const t = r;
667
668
  return r = [], t;
668
669
  };
669
- return c.observe(t, {
670
+ return s.observe(t, {
670
671
  characterData: !0,
671
672
  characterDataOldValue: !0,
672
673
  childList: !0,
673
674
  subtree: !0
674
675
  }), {
675
- m: t => {
676
+ k: t => {
676
677
  let e;
677
678
  for (;e = t.pop(); ) if ("childList" === e.type) {
678
679
  const {target: t, removedNodes: n, addedNodes: r, nextSibling: o} = e;
@@ -681,80 +682,80 @@ var it = [], lt = () => {}, at = t => {
681
682
  } else e.target.data = e.oldValue;
682
683
  i();
683
684
  },
684
- _: t => {
685
- !n && t && s(), n = t;
685
+ v: t => {
686
+ !n && t && c(), n = t;
686
687
  },
687
- v: i,
688
+ _: i,
688
689
  T: () => {
689
- r.length = 0, c.disconnect();
690
+ r.length = 0, s.disconnect();
690
691
  }
691
692
  };
692
693
  })(n, () => {
693
- O(), tt(n, w, t, f);
694
+ I(), it(n, O, t, a);
694
695
  }), C = () => {
695
- R(b = _(t, ((t, e) => {
696
- const n = K(t), r = Q(n, t);
696
+ k(w = v(t, ((t, e) => {
697
+ const n = ot(t), r = st(n, t);
697
698
  if (!r) return [ [ [ 0 ], 0 ], [ [ 0 ], 0 ] ];
698
- const o = rt(t, e, r), c = j(n.anchorNode, n.focusNode);
699
- return (0 === c ? n.anchorOffset > n.focusOffset : 2 & c) ? [ o[1], o[0] ] : o;
700
- })(n, w)));
701
- }, U = () => {
702
- const e = N.v();
703
- N._(!1), e.length && (N.m(e), E.removeEventListener("selectionchange", ot), tt(n, w, t, f, !0),
704
- E.addEventListener("selectionchange", ot)), h && (R(h[1]), T(h[0]), h = null), y = !1;
705
- }, V = t => {
706
- if (!y) for (const e of k("keyboard")) if (e(t)) return t.preventDefault(), void N._(!1);
699
+ const o = ft(t, e, r), s = nt(n.anchorNode, n.focusNode);
700
+ return (0 === s ? n.anchorOffset > n.focusOffset : 2 & s) ? [ o[1], o[0] ] : o;
701
+ })(n, O)));
702
+ }, F = () => {
703
+ const e = W._();
704
+ W.v(!1), e.length && (W.k(e), A.removeEventListener("selectionchange", Y), it(n, O, t, a, !0),
705
+ A.addEventListener("selectionchange", Y)), x && (k(x[1]), g(x[0]), x = null), h = !1;
706
+ }, U = t => {
707
+ if (!h) for (const e of d("keyboard")) if (e(t)) return t.preventDefault(), void W.v(!1);
707
708
  }, q = () => {
708
- y || U();
709
- }, G = e => {
709
+ h || F();
710
+ }, z = e => {
710
711
  e.preventDefault();
711
712
  const r = e.inputType;
712
713
  if (r.startsWith("format")) return;
713
714
  if ("historyUndo" === r || "historyRedo" === r) return;
714
- y ? N._(!0) : C();
715
+ h ? W.v(!0) : C();
715
716
  const o = e.getTargetRanges()[0];
716
717
  if (o) {
717
- let c = "insertParagraph" === r || "insertLineBreak" === r ? "\n" : e.data;
718
- if (null == c) {
718
+ let s = "insertParagraph" === r || "insertLineBreak" === r ? "\n" : e.data;
719
+ if (null == s) {
719
720
  const t = e.dataTransfer;
720
- t && (c = t.getData("text/plain"));
721
+ t && (s = t.getData("text/plain"));
721
722
  }
722
- h || (h = [ [], f ]);
723
- const s = h[0], i = _(t, rt(n, w, o));
724
- F(i) || s.push({
723
+ x || (x = [ [], a ]);
724
+ const c = x[0], i = v(t, ft(n, O, o));
725
+ S(i) || c.push({
725
726
  type: "delete",
726
727
  range: i
727
- }), c && s.push({
728
+ }), s && c.push({
728
729
  type: "insert_text",
729
730
  at: i[0],
730
- text: c
731
+ text: s
731
732
  });
732
733
  }
733
- y || U();
734
+ h || F();
735
+ }, G = () => {
736
+ h || C(), h = !0;
737
+ }, J = () => {
738
+ F();
739
+ }, j = () => {
740
+ _ = !0, C();
734
741
  }, X = () => {
735
- y || C(), y = !0;
742
+ _ = !1;
736
743
  }, Y = () => {
737
- U();
738
- }, $ = () => {
739
- x = !0, C();
740
- }, et = () => {
741
- x = !1;
742
- }, ot = () => {
743
- !x || y || g || C();
744
- }, ct = t => {
745
- if (C(), !F(f)) for (const e of k("copy")) e(t);
746
- }, st = t => {
747
- t.preventDefault(), ct(t.clipboardData);
748
- }, it = t => {
749
- t.preventDefault(), e || (ct(t.clipboardData), T({
744
+ !_ || h || T || C();
745
+ }, Z = t => {
746
+ if (C(), !S(a)) for (const e of d("copy")) e(t);
747
+ }, Q = t => {
748
+ t.preventDefault(), Z(t.clipboardData);
749
+ }, tt = t => {
750
+ t.preventDefault(), e || (Z(t.clipboardData), g({
750
751
  type: "delete",
751
- range: W(f)
752
+ range: M(a)
752
753
  }));
753
- }, at = t => {
754
+ }, et = t => {
754
755
  t.preventDefault();
755
- const e = P(t.clipboardData);
756
+ const e = N(t.clipboardData);
756
757
  if (e) {
757
- const t = W(f), n = t[0], r = [ {
758
+ const t = M(a), n = t[0], r = [ {
758
759
  type: "delete",
759
760
  range: t
760
761
  } ];
@@ -766,148 +767,147 @@ var it = [], lt = () => {}, at = t => {
766
767
  type: "insert_node",
767
768
  at: n,
768
769
  fragment: e
769
- }), T(r);
770
+ }), g(r);
770
771
  }
771
- }, ut = e => {
772
+ }, ct = e => {
772
773
  e.preventDefault();
773
- const r = e.dataTransfer, c = ((t, e, {clientX: n, clientY: r}) => {
774
- const o = Z(t);
774
+ const r = e.dataTransfer, s = ((t, e, {clientX: n, clientY: r}) => {
775
+ const o = rt(t);
775
776
  if (o.caretPositionFromPoint) {
776
- const c = o.caretPositionFromPoint(n, r);
777
- if (c) return nt(t, e, c.offsetNode, c.offset);
777
+ const s = o.caretPositionFromPoint(n, r);
778
+ if (s) return at(t, e, s.offsetNode, s.offset);
778
779
  } else if (o.caretRangeFromPoint) {
779
- const c = o.caretRangeFromPoint(n, r);
780
- if (c) return nt(t, e, c.startContainer, c.startOffset);
780
+ const s = o.caretRangeFromPoint(n, r);
781
+ if (s) return at(t, e, s.startContainer, s.startOffset);
781
782
  }
782
- })(n, w, e);
783
- if (r && c) {
783
+ })(n, O, e);
784
+ if (r && s) {
784
785
  let e;
785
786
  const n = [];
786
- g && n.push({
787
+ T && n.push({
787
788
  type: "delete",
788
- range: W(f)
789
+ range: M(a)
789
790
  });
790
- const s = P(r);
791
- if (s) {
792
- const r = m(t, c), i = H(r, n);
793
- n.push(o(s) ? {
791
+ const c = N(r);
792
+ if (c) {
793
+ const r = m(t, s), i = V(r, n);
794
+ n.push(o(c) ? {
794
795
  type: "insert_text",
795
796
  at: i,
796
- text: s
797
+ text: c
797
798
  } : {
798
799
  type: "insert_node",
799
800
  at: i,
800
- fragment: s
801
- }), e = [ i, H(r, n) ];
801
+ fragment: c
802
+ }), e = [ i, V(r, n) ];
802
803
  }
803
- T(n), e && R(e);
804
+ g(n), e && k(e);
804
805
  }
805
- g = !1;
806
- }, ft = t => {
807
- g = !0, ct(t.dataTransfer);
808
- }, pt = () => {
809
- g = !1;
806
+ T = !1;
807
+ }, lt = t => {
808
+ T = !0, Z(t.dataTransfer);
809
+ }, ut = () => {
810
+ T = !1;
810
811
  };
811
- E.addEventListener("selectionchange", ot), n.addEventListener("keydown", V), n.addEventListener("input", q),
812
- n.addEventListener("beforeinput", G), n.addEventListener("compositionstart", X),
813
- n.addEventListener("compositionend", Y), n.addEventListener("focus", $), n.addEventListener("blur", et),
814
- n.addEventListener("copy", st), n.addEventListener("cut", it), n.addEventListener("paste", at),
815
- n.addEventListener("drop", ut), n.addEventListener("dragstart", ft), n.addEventListener("dragend", pt);
816
- const dt = [];
817
- return k("mount").forEach(t => {
818
- const e = t(n, w);
819
- e && dt.push(e);
812
+ A.addEventListener("selectionchange", Y), n.addEventListener("keydown", U), n.addEventListener("input", q),
813
+ n.addEventListener("beforeinput", z), n.addEventListener("compositionstart", G),
814
+ n.addEventListener("compositionend", J), n.addEventListener("focus", j), n.addEventListener("blur", X),
815
+ n.addEventListener("copy", Q), n.addEventListener("cut", tt), n.addEventListener("paste", et),
816
+ n.addEventListener("drop", ct), n.addEventListener("dragstart", lt), n.addEventListener("dragend", ut);
817
+ const pt = [];
818
+ return d("mount").forEach(t => {
819
+ const e = t(n, O);
820
+ e && pt.push(e);
820
821
  }), () => {
821
- d || (d = !0, B(), I(), L(), n.contentEditable = s, n.role = i, n.ariaMultiLine = l,
822
- n.ariaReadOnly = u, n.style.whiteSpace = p, N.T(), E.removeEventListener("selectionchange", ot),
823
- n.removeEventListener("keydown", V), n.removeEventListener("input", q), n.removeEventListener("beforeinput", G),
824
- n.removeEventListener("compositionstart", X), n.removeEventListener("compositionend", Y),
825
- n.removeEventListener("focus", $), n.removeEventListener("blur", et), n.removeEventListener("copy", st),
826
- n.removeEventListener("cut", it), n.removeEventListener("paste", at), n.removeEventListener("drop", ut),
827
- n.removeEventListener("dragstart", ft), n.removeEventListener("dragend", pt), dt.forEach(t => {
822
+ y || (y = !0, L(), P(), H(), n.contentEditable = c, n.role = l, n.ariaMultiLine = f,
823
+ n.ariaReadOnly = u, n.style.whiteSpace = p, W.T(), A.removeEventListener("selectionchange", Y),
824
+ n.removeEventListener("keydown", U), n.removeEventListener("input", q), n.removeEventListener("beforeinput", z),
825
+ n.removeEventListener("compositionstart", G), n.removeEventListener("compositionend", J),
826
+ n.removeEventListener("focus", j), n.removeEventListener("blur", X), n.removeEventListener("copy", Q),
827
+ n.removeEventListener("cut", tt), n.removeEventListener("paste", et), n.removeEventListener("drop", ct),
828
+ n.removeEventListener("dragstart", lt), n.removeEventListener("dragend", ut), pt.forEach(t => {
828
829
  t();
829
830
  }));
830
831
  };
831
832
  }
832
833
  };
833
- return D.exec(st), D;
834
+ return b.exec(dt), b;
834
835
  };
835
836
 
836
- function ft(t, e) {
837
+ function mt(t, e) {
837
838
  const n = e && e.voidToString;
838
839
  t.hook("copy", e => {
839
- e.setData("text/plain", E(t.doc, ...W(t.selection), n));
840
+ e.setData("text/plain", w(t.doc, ...M(t.selection), n));
840
841
  }), t.hook("paste", t => t.getData("text/plain"));
841
842
  }
842
843
 
843
- function pt(t, e) {
844
- const n = e.isLocked, r = e => n(h(t.doc, e)[0]), o = (e, r) => {
845
- const [o, c] = e;
846
- for (const [s, i] of v(t.doc, e)) {
847
- const t = i + p(s);
848
- if ((r ? c >= i && o <= t : c > i && o < t) && n(s)) return !0;
849
- }
844
+ function kt(t, e) {
845
+ const n = e.isLocked, r = e => {
846
+ for (const [r] of _(t.doc, e)) if (n(r)) return !0;
850
847
  return !1;
851
848
  };
852
- let c = !1;
853
- t.hook("apply", (e, i) => {
854
- const a = c;
855
- switch (c = !1, e.type) {
856
- case "delete":
857
- if (o(W(e.range), !0)) return c = !0, s(() => {
858
- c = !1;
859
- }), i(null);
860
- break;
861
-
862
- case "insert_text":
863
- case "insert_node":
864
- if (a || r(e.at)) return i(null);
865
- break;
866
-
867
- case "format":
868
- {
869
- const t = W(e.range);
870
- if (F(t) ? r(t[0]) : o(t, !1)) return i(null);
871
- break;
872
- }
873
-
874
- case "patch_node":
875
- {
876
- const r = e.path;
877
- let o = t.doc;
878
- for (let t = 0; t < r.length; t++) {
879
- const e = o.children?.[r[t]];
880
- if (!e) break;
881
- if (o = e, t < r.length - 1 && l(o) && n(o)) return i(null);
882
- }
883
- if (o !== t.doc && l(o) && n(o) && n({
884
- ...o,
885
- [e.key]: e.value
886
- })) return i(null);
887
- break;
849
+ t.hook("apply", (e, o) => {
850
+ o((e => {
851
+ if ("format" !== e.type) return r("delete" === e.type ? M(e.range) : [ e.at, e.at ]);
852
+ const o = t.doc, s = 0 === e.depth ? [ 0, p(o) ] : M(e.range), c = _(J(o, t.selection, e)[0], s);
853
+ for (const [t] of _(o, s)) {
854
+ const e = c.next().value?.[0];
855
+ if (e && t !== e && n(t) && n(e)) return !0;
888
856
  }
889
- }
890
- i(e);
891
- }), t.set(pt, {
892
- locked: t => F(t) ? r(t[0]) : o(t, !0)
857
+ return !1;
858
+ })(e) ? null : e);
859
+ }), t.set(kt, {
860
+ locked: r
893
861
  });
894
862
  }
895
863
 
896
- var dt = (t, e) => {
864
+ var vt = (t, e) => {
897
865
  const n = parseFloat(t);
898
866
  return n ? t.endsWith("%") ? n / 100 * e : n : 0;
899
- }, ht = (t, e, n, r) => [ t + dt(n, e), t + e - dt(r, e) ], yt = t => "auto" === t || "scroll" === t || "overlay" === t, xt = (t, e, [n, r]) => t < n ? t - n : e > r ? e - r : 0, kt = (t, e, n, r) => {
900
- const o = r ? -n : 0;
901
- return Math.max(o - e, Math.min(t, o + n - e));
902
- }, mt = (t, [e, n], r) => {
867
+ }, bt = (t, e, n, r) => [ t + vt(n, e), t + e - vt(r, e) ], _t = t => "auto" === t || "scroll" === t || "overlay" === t, Tt = (t, e, [n, r]) => t < n ? t - n : e > r ? e - r : 0, wt = (n, r, o, s) => {
868
+ const c = s ? -o : 0;
869
+ return e(c - r, t(n, c + o - r));
870
+ }, Et = (t, e, n) => {
903
871
  (n || e) && t.scrollBy({
904
872
  top: n,
905
873
  left: e,
906
- behavior: r
874
+ behavior: "auto"
907
875
  });
876
+ }, Mt = (t, e, n) => {
877
+ let r = e;
878
+ for (let o = e + 1; o < n; o++) p(t[o]) > p(t[r]) && (r = o);
879
+ return r;
908
880
  };
909
881
 
910
- function gt(t) {
882
+ function St(t) {
883
+ let e = 0, n = t.doc;
884
+ const r = new WeakMap, o = (t, e) => {
885
+ if (t === e) return;
886
+ let n = 0, s = t.length, c = e.length;
887
+ for (;n < s && n < c && t[n] === e[n]; ) n++;
888
+ for (;n < s && n < c && t[s - 1] === e[c - 1]; ) s--, c--;
889
+ const i = new Set(e.slice(n, c)), a = s - n, f = c - n;
890
+ for (let u = n; u < s && u < c; u++) {
891
+ const p = t[1 === f ? Mt(t, n, s) : u], d = e[1 === a ? Mt(e, n, c) : u];
892
+ if (i.has(p) || r.has(d)) continue;
893
+ const y = r.get(p);
894
+ null != y && (r.delete(p), r.set(d, y)), l(p) && l(d) && o(p.children, d.children);
895
+ }
896
+ };
897
+ t.set(St, {
898
+ id: s => {
899
+ const c = t.doc;
900
+ if (c !== n) {
901
+ const t = n;
902
+ n = c, o(t.children, c.children);
903
+ }
904
+ let i = r.get(s);
905
+ return null == i && r.set(s, i = ++e + ""), i;
906
+ }
907
+ });
908
+ }
909
+
910
+ function At(t) {
911
911
  t.hook("mount", t => {
912
912
  t.ariaMultiLine = null;
913
913
  }), t.hook("apply", (t, e) => {
@@ -918,24 +918,25 @@ function gt(t) {
918
918
  const e = t.fragment;
919
919
  t = {
920
920
  ...t,
921
- fragment: a(e) ? [ B(...e) ] : e
921
+ fragment: a(e) ? [ W(e) ] : e
922
922
  };
923
923
  }
924
924
  e(t);
925
925
  });
926
926
  }
927
927
 
928
- exports.ClearHistory = function(t) {
929
- t.get(st).clear();
930
- }, exports.Delete = function(t, e = W(t.selection)) {
928
+ exports.BlocksInRange = Y, exports.ClearHistory = function(t) {
929
+ const {stack: e} = t.get(dt);
930
+ e().length = 0, e(!0).length = 0;
931
+ }, exports.Delete = function(t, e = M(t.selection)) {
931
932
  t.apply({
932
933
  type: "delete",
933
934
  range: e
934
935
  });
935
- }, exports.Format = function(t, e, n, r = W(t.selection)) {
936
- t.apply({
936
+ }, exports.Format = function(t, e, n, r = M(t.selection)) {
937
+ for (const o of Z(t, r)) t.apply({
937
938
  type: "format",
938
- range: r,
939
+ range: o,
939
940
  key: e,
940
941
  value: n
941
942
  });
@@ -953,70 +954,88 @@ exports.ClearHistory = function(t) {
953
954
  at: n,
954
955
  text: e
955
956
  });
956
- }, exports.LeavesInRange = V, exports.LockedInRange = function(t, e = W(t.selection)) {
957
- return t.get(pt).locked(e);
957
+ }, exports.LeavesInRange = X, exports.LockedInRange = function(t, e = M(t.selection)) {
958
+ return t.get(kt).locked(e);
959
+ }, exports.NodeId = function(t, e) {
960
+ return t.get(St).id(e);
958
961
  }, exports.Redo = function(t) {
959
- t.get(st).redo();
962
+ t.get(dt).redo();
960
963
  }, exports.Redoable = function(t) {
961
- return t.get(st).redoable();
962
- }, exports.ReplaceDoc = q, exports.ReplaceText = function(t, e, n = W(t.selection)) {
964
+ return !!t.get(dt).stack(!0).length;
965
+ }, exports.ReplaceDoc = function(t, e) {
963
966
  t.apply({
967
+ type: "format",
968
+ range: [ 0, 0 ],
969
+ key: "children",
970
+ value: e,
971
+ depth: 0
972
+ });
973
+ }, exports.ReplaceText = function(t, e, n = M(t.selection)) {
974
+ t.apply([ {
964
975
  type: "delete",
965
976
  range: n
966
- }).apply({
977
+ }, {
967
978
  type: "insert_text",
968
979
  at: n[0],
969
980
  text: e
970
- });
971
- }, exports.SetBlockAttr = function(t, e, n, r = t.selection[0]) {
972
- const o = h(t.doc, r)[2];
981
+ } ]);
982
+ }, exports.SetBlockAttr = function(t, e, n, r = M(t.selection)) {
973
983
  t.apply({
974
- type: "patch_node",
975
- path: o,
984
+ type: "format",
985
+ range: r,
976
986
  key: e,
977
- value: n
987
+ value: n,
988
+ depth: -2
978
989
  });
979
990
  }, exports.SetVoidAttr = function(t, e, n, r = t.selection[0]) {
980
- const o = y(t.doc, r, !0);
981
- o && !i(o[0]) && t.apply({
982
- type: "patch_node",
983
- path: o[2],
984
- key: e,
985
- value: n
986
- });
987
- }, exports.ToggleBlockAttr = function(t, e, n, r, o = t.selection[0]) {
988
- const [c, , s] = h(t.doc, o);
991
+ const o = x(t.doc, r, !0);
992
+ if (o && !i(o[0])) {
993
+ const s = r - o[1];
994
+ t.apply({
995
+ type: "format",
996
+ range: [ s, s + 1 ],
997
+ key: e,
998
+ value: n
999
+ });
1000
+ }
1001
+ }, exports.ToggleBlockAttr = function(t, e, n, r, o = M(t.selection)) {
1002
+ let s = !1;
1003
+ for (const [c] of t.exec(Y, o)) if (c[e] !== n) {
1004
+ s = !0;
1005
+ break;
1006
+ }
989
1007
  t.apply({
990
- type: "patch_node",
991
- path: s,
1008
+ type: "format",
1009
+ range: o,
992
1010
  key: e,
993
- value: c[e] === n ? r : n
1011
+ value: s ? n : r,
1012
+ depth: -2
994
1013
  });
995
- }, exports.ToggleFormat = function(t, e, n = W(t.selection)) {
1014
+ }, exports.ToggleFormat = function(t, e, n = M(t.selection)) {
996
1015
  let r = !1, o = !1;
997
- for (const c of t.exec(V, n)) if (i(c) && (o = !0, !c[e])) {
1016
+ for (const s of t.exec(X, n)) if (i(s) && (o = !0, !s[e])) {
998
1017
  r = !0;
999
1018
  break;
1000
1019
  }
1001
- o && t.apply({
1020
+ if (o) for (const s of Z(t, n)) t.apply({
1002
1021
  type: "format",
1003
- range: n,
1022
+ range: s,
1004
1023
  key: e,
1005
1024
  value: r
1006
1025
  });
1007
1026
  }, exports.Undo = function(t) {
1008
- t.get(st).undo();
1027
+ t.get(dt).undo();
1009
1028
  }, exports.Undoable = function(t) {
1010
- return t.get(st).undoable();
1011
- }, exports.blockLockPlugin = pt, exports.createEditor = ut, exports.createPlainEditor = ({text: t, singleline: e, onChange: n, ...r}) => {
1012
- const o = ut({
1029
+ return !!t.get(dt).stack().length;
1030
+ }, exports.blockLockPlugin = kt, exports.createEditor = gt, exports.createPlainEditor = ({text: t, singleline: e, onChange: n, ...r}) => {
1031
+ const o = gt({
1013
1032
  ...r,
1014
1033
  doc: {
1015
- children: M(t)
1034
+ children: O(t)
1016
1035
  }
1017
- }).exec(ft);
1018
- return e && o.exec(gt), o.on("change", () => {
1019
- n(E(o.doc));
1036
+ }).exec(mt);
1037
+ return e && o.exec(At), o.on("change", () => {
1038
+ n(w(o.doc));
1020
1039
  }), o;
1021
1040
  }, exports.debugPlugin = function(t) {
1022
1041
  t.hook("apply", t => {
@@ -1039,13 +1058,13 @@ exports.ClearHistory = function(t) {
1039
1058
  }
1040
1059
  return null;
1041
1060
  });
1042
- }, exports.getChildAt = d, exports.getLeafAt = y, exports.getLeafBlockAt = h, exports.getNodeOffset = x,
1061
+ }, exports.getChildAt = d, exports.getLeafAt = x, exports.getLeafBlockAt = y, exports.getNodeOffset = h,
1043
1062
  exports.getNodeSize = p, exports.htmlTransferPlugin = function(t, e) {
1044
1063
  t.hook("mount", (n, r) => {
1045
1064
  const o = t.hook("copy", t => {
1046
1065
  const e = document.createElement("div");
1047
- e.appendChild(Q(K(n), n).cloneContents()), t.setData("text/html", e.innerHTML);
1048
- }), c = t.hook("paste", t => {
1066
+ e.appendChild(st(ot(n), n).cloneContents()), t.setData("text/html", e.innerHTML);
1067
+ }), s = t.hook("paste", t => {
1049
1068
  const n = t.getData("text/html");
1050
1069
  return n ? ((t, e, n) => {
1051
1070
  const r = n.text, o = t => {
@@ -1055,37 +1074,37 @@ exports.getNodeSize = p, exports.htmlTransferPlugin = function(t, e) {
1055
1074
  if (n) return n;
1056
1075
  }
1057
1076
  };
1058
- let c = (new DOMParser).parseFromString(t, "text/html").body, s = !1;
1059
- for (const i of [ ...c.childNodes ]) G(i) ? "StartFragment" === i.data ? (s = !0,
1060
- c = new DocumentFragment) : "EndFragment" === i.data && (s = !1) : s && c.appendChild(i);
1077
+ let s = (new DOMParser).parseFromString(t, "text/html").body, c = !1;
1078
+ for (const i of [ ...s.childNodes ]) Q(i) ? "StartFragment" === i.data ? (c = !0,
1079
+ s = new DocumentFragment) : "EndFragment" === i.data && (c = !1) : c && s.appendChild(i);
1061
1080
  return e(({t, i: e}) => {
1062
- let n, c = null, s = "", i = !1;
1081
+ let n, s = null, c = "", i = !1;
1063
1082
  const l = [], a = () => {
1064
- s && (c || (c = []), c.push(r(s)), s = "");
1065
- }, u = () => {
1066
- a(), !c && i && (c = []), c && l.push({
1067
- children: c
1068
- }), c = null, i = !1;
1083
+ c && (s || (s = []), s.push(r(c)), c = "");
1084
+ }, f = () => {
1085
+ a(), !s && i && (s = []), s && l.push({
1086
+ children: s
1087
+ }), s = null, i = !1;
1069
1088
  };
1070
- for (;n = t(); ) if (4 === n) u(); else if (i = !0, 1 === n) s += e().data; else if (2 === n) {
1089
+ for (;n = t(); ) if (4 === n) f(); else if (i = !0, 1 === n) c += e().data; else if (2 === n) {
1071
1090
  a();
1072
1091
  const t = o(e());
1073
- t && c.push(t);
1074
- } else 3 === n && u();
1075
- return u(), l.length || l.push({
1092
+ t && s.push(t);
1093
+ } else 3 === n && f();
1094
+ return f(), l.length || l.push({
1076
1095
  children: []
1077
1096
  }), l;
1078
- }, c);
1097
+ }, s);
1079
1098
  })(n, r, e.serializers) : null;
1080
1099
  });
1081
1100
  return () => {
1082
- o(), c();
1101
+ o(), s();
1083
1102
  };
1084
1103
  });
1085
1104
  }, exports.internalTransferPlugin = function(t, e) {
1086
1105
  const n = e && e.mime || "application/x-editate-editor";
1087
1106
  t.hook("copy", e => {
1088
- e.setData(n, JSON.stringify(w(t.doc, ...W(t.selection))));
1107
+ e.setData(n, JSON.stringify(E(t.doc, ...M(t.selection))));
1089
1108
  }), t.hook("paste", t => {
1090
1109
  try {
1091
1110
  return JSON.parse(t.getData(n));
@@ -1093,78 +1112,73 @@ exports.getNodeSize = p, exports.htmlTransferPlugin = function(t, e) {
1093
1112
  return null;
1094
1113
  }
1095
1114
  });
1096
- }, exports.iterLeafBlocks = v, exports.iterLeaves = T, exports.keymapPlugin = function(t, e) {
1115
+ }, exports.iterLeafBlocks = _, exports.iterLeaves = T, exports.keymapPlugin = function(t, e) {
1097
1116
  n(e).forEach(n => {
1098
1117
  const r = e[n];
1099
- t.hook("keyboard", ct(n, r));
1118
+ t.hook("keyboard", pt(n, r));
1100
1119
  });
1101
- }, exports.mapPosition = N, exports.plainTransferPlugin = ft, exports.scrollToSelectionPlugin = t => {
1102
- const e = "auto";
1103
- t.hook("mount", (n, r) => {
1104
- const o = Z(n), c = o.defaultView, {documentElement: s} = o, i = ((t, e, n) => {
1105
- const {body: r, documentElement: o} = e;
1106
- let c = t;
1107
- for (;c && c !== r && c !== o; ) {
1108
- const {overflowX: t, overflowY: e} = n.getComputedStyle(c);
1109
- if (yt(t) || yt(e)) return c;
1110
- c = c.parentElement;
1120
+ }, exports.mapPosition = q, exports.nodeIdPlugin = St, exports.plainTransferPlugin = mt,
1121
+ exports.scrollToSelectionPlugin = t => {
1122
+ t.hook("mount", (e, n) => {
1123
+ const r = rt(e), o = r.defaultView, {body: s, documentElement: c} = r;
1124
+ let i, l;
1125
+ for (let t = e; t && t !== s && t !== c; t = t.parentElement) {
1126
+ const e = o.getComputedStyle(t);
1127
+ if (_t(e.overflowX) || _t(e.overflowY)) {
1128
+ i = t, l = e;
1129
+ break;
1111
1130
  }
1112
- return null;
1113
- })(n, o, c), l = i && c.getComputedStyle(i), a = c.getComputedStyle(s);
1114
- let u = null;
1115
- const f = t.on("change", () => {
1116
- null == u && (u = setTimeout(() => {
1117
- u = null;
1118
- const o = $(n, r, t.doc, t.selection);
1119
- let f = o.getBoundingClientRect();
1120
- if (!f.width && !f.height) {
1121
- const t = o.startContainer, e = z(t) ? t : t.parentElement;
1122
- e && (f = e.getBoundingClientRect());
1131
+ }
1132
+ const a = o.getComputedStyle(c);
1133
+ let f = null;
1134
+ const u = t.on("change", () => {
1135
+ null == f && (f = setTimeout(() => {
1136
+ f = null;
1137
+ const r = ct(e, n, t.doc, t.selection);
1138
+ let s = r.getBoundingClientRect();
1139
+ if (!s.width && !s.height) {
1140
+ const t = r.startContainer, e = K(t) ? t : t.parentElement;
1141
+ e && (s = e.getBoundingClientRect());
1123
1142
  }
1124
- const p = i && l ? ((t, e, n) => {
1125
- const {scrollLeft: r, scrollTop: o, scrollWidth: c, scrollHeight: s, clientLeft: i, clientTop: l, clientWidth: a, clientHeight: u} = t, f = t.getBoundingClientRect(), [p, d] = (t => {
1126
- const e = "rtl" === t.direction;
1127
- switch (t.writingMode) {
1128
- case "vertical-rl":
1129
- case "sideways-rl":
1130
- return [ !0, e ];
1143
+ let u = 0, p = 0;
1144
+ if (i && l) {
1145
+ const {scrollLeft: t, scrollTop: e, scrollWidth: n, scrollHeight: r, clientLeft: o, clientTop: c, clientWidth: a, clientHeight: f} = i, d = i.getBoundingClientRect(), y = "rtl" === l.direction;
1146
+ let x = y, h = !1;
1147
+ switch (l.writingMode) {
1148
+ case "vertical-rl":
1149
+ case "sideways-rl":
1150
+ x = !0, h = y;
1151
+ break;
1131
1152
 
1132
- case "vertical-lr":
1133
- return [ !1, e ];
1153
+ case "vertical-lr":
1154
+ x = !1, h = y;
1155
+ break;
1134
1156
 
1135
- case "sideways-lr":
1136
- return [ !1, !e ];
1137
-
1138
- default:
1139
- return [ e, !1 ];
1140
- }
1141
- })(e), h = kt(xt(n.top, n.bottom, ht(f.top + l, u, e.scrollPaddingTop, e.scrollPaddingBottom)), o, s - u, d);
1142
- return [ kt(xt(n.left, n.right, ht(f.left + i, a, e.scrollPaddingLeft, e.scrollPaddingRight)), r, c - a, p), h ];
1143
- })(i, l, f) : [ 0, 0 ], d = ((t, e, n, [r, o]) => {
1144
- const {clientWidth: c, clientHeight: s} = t, i = xt(n.top - o, n.bottom - o, ht(0, s, e.scrollPaddingTop, e.scrollPaddingBottom));
1145
- return [ xt(n.left - r, n.right - r, ht(0, c, e.scrollPaddingLeft, e.scrollPaddingRight)), i ];
1146
- })(s, a, f, p);
1147
- i && mt(i, p, e), mt(c, d, e);
1157
+ case "sideways-lr":
1158
+ x = !1, h = !y;
1159
+ }
1160
+ p = wt(Tt(s.top, s.bottom, bt(d.top + c, f, l.scrollPaddingTop, l.scrollPaddingBottom)), e, r - f, h),
1161
+ u = wt(Tt(s.left, s.right, bt(d.left + o, a, l.scrollPaddingLeft, l.scrollPaddingRight)), t, n - a, x);
1162
+ }
1163
+ const {clientWidth: d, clientHeight: y} = c, x = Tt(s.top - p, s.bottom - p, bt(0, y, a.scrollPaddingTop, a.scrollPaddingBottom)), h = Tt(s.left - u, s.right - u, bt(0, d, a.scrollPaddingLeft, a.scrollPaddingRight));
1164
+ i && Et(i, u, p), Et(o, h, x);
1148
1165
  }, 50));
1149
1166
  });
1150
1167
  return () => {
1151
- null != u && clearTimeout(u), f();
1168
+ null != f && clearTimeout(f), u();
1152
1169
  };
1153
1170
  });
1154
1171
  }, exports.selectionRectPlugin = function(t, e) {
1155
1172
  t.hook("mount", (n, r) => {
1156
- let o = !0, c = !1;
1157
- const s = t.on("selectionchange", () => {
1158
- c || (c = !0, requestAnimationFrame(() => {
1159
- c = !1, o && e(() => {
1160
- const e = t.selection;
1161
- return $(n, r, t.doc, e).getBoundingClientRect();
1162
- });
1173
+ let o = !0, s = !1;
1174
+ const c = t.on("selectionchange", () => {
1175
+ s || (s = !0, requestAnimationFrame(() => {
1176
+ s = !1, o && e(() => ct(n, r, t.doc, t.selection).getBoundingClientRect());
1163
1177
  }));
1164
1178
  });
1165
1179
  return () => {
1166
- o = !1, s();
1180
+ o = !1, c();
1167
1181
  };
1168
1182
  });
1169
- }, exports.singlelinePlugin = gt, exports.sliceText = E;
1183
+ }, exports.singlelinePlugin = At, exports.sliceText = w;
1170
1184
  //# sourceMappingURL=index.cjs.map