editate 0.6.22 → 0.6.24

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
@@ -41,11 +41,23 @@ var {min: t, max: e} = Math, {keys: n, is: r} = Object, o = t => "string" == typ
41
41
  const [r, o, c] = h(t, e), s = d(r, o, n);
42
42
  return s ? (c.push(s[2]), [ s[0], s[1], c ]) : null;
43
43
  }, x = (t, e) => {
44
+ let n = 0, r = 0;
45
+ for (const o of t.children) {
46
+ const t = l(o);
47
+ if (t && 0 !== r && n++, o === e) return n;
48
+ if (t) {
49
+ const t = x(o, e);
50
+ if (null != t) return n + t;
51
+ }
52
+ n += p(o), r++;
53
+ }
54
+ return null;
55
+ }, k = (t, e) => {
44
56
  const n = t.children, r = d(t, e);
45
57
  if (r) {
46
58
  const [e, o, c] = r;
47
59
  if (l(e)) {
48
- const [r, s] = x(e, o), i = n.slice(0, c), l = n.slice(c + 1);
60
+ const [r, s] = k(e, o), i = n.slice(0, c), l = n.slice(c + 1);
49
61
  return i.push(r), l.unshift(s), [ {
50
62
  ...t,
51
63
  children: i
@@ -83,16 +95,16 @@ var {min: t, max: e} = Math, {keys: n, is: r} = Object, o = t => "string" == typ
83
95
  text: ""
84
96
  } ] : []
85
97
  } ];
86
- }, k = (t, [e, n]) => {
98
+ }, m = (t, [e, n]) => {
87
99
  let r = 0;
88
100
  for (const o of e) r += f(t, 0, o), 0 !== o && r++, t = t.children[o];
89
101
  return r + n;
90
- }, m = (t, e) => {
102
+ }, g = (t, e) => {
91
103
  const [, n, r] = h(t, e);
92
104
  return [ r, n ];
93
- }, g = (t, [e, n]) => [ k(t, e), k(t, n) ];
105
+ }, _ = (t, [e, n]) => [ m(t, e), m(t, n) ];
94
106
 
95
- function* _(t, [e, n]) {
107
+ function* b(t, [e, n]) {
96
108
  if (e >= n) return;
97
109
  if (!l(t)) return;
98
110
  const r = d(t, e);
@@ -106,21 +118,21 @@ function* _(t, [e, n]) {
106
118
  }
107
119
  }
108
120
 
109
- function* b(t, e) {
110
- if (!l(t) || a(t.children)) for (const n of _(t, e)) {
121
+ function* v(t, e) {
122
+ if (!l(t) || a(t.children)) for (const n of b(t, e)) {
111
123
  const [t, e] = n;
112
- for (const n of b(t, [ 0, p(t) ])) n[1] += e, yield n;
124
+ for (const n of v(t, [ 0, p(t) ])) n[1] += e, yield n;
113
125
  } else yield [ t, 0 ];
114
126
  }
115
127
 
116
- function* v(t, e) {
117
- if (l(t)) for (const [n, r] of _(t, e)) for (const t of v(n, [ 0, p(n) ])) t[1] += r,
128
+ 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,
118
130
  yield t; else yield [ t, 0 ];
119
131
  }
120
132
 
121
- var T = (n, r = 0, o = 1 / 0, c) => {
133
+ var E = (n, r = 0, o = 1 / 0, c) => {
122
134
  let s = "", l = r;
123
- for (const [a, u] of v(n, [ r, o ])) {
135
+ for (const [a, u] of T(n, [ r, o ])) {
124
136
  for (let t = u - l; t > 0; t--) s += "\n";
125
137
  const n = p(a), f = u + n;
126
138
  if (i(a)) {
@@ -131,16 +143,16 @@ var T = (n, r = 0, o = 1 / 0, c) => {
131
143
  }
132
144
  for (let e = t(o, p(n)) - l; e > 0; e--) s += "\n";
133
145
  return s;
134
- }, E = (t, e, n) => e >= n ? [] : x(x(t, n)[0], e)[1].children, M = (t, e, n) => t.split("\n").map(t => ({
146
+ }, w = (t, e, n) => e >= n ? [] : k(k(t, n)[0], e)[1].children, M = (t, e, n) => t.split("\n").map(t => ({
135
147
  ...n,
136
148
  children: [ {
137
149
  ...e,
138
150
  text: t
139
151
  } ]
140
- })), S = "delete", w = "insert_text", A = "insert_node", O = (t, e) => {
152
+ })), S = "delete", A = "insert_text", O = "insert_node", R = (t, e) => {
141
153
  const o = n(t);
142
154
  return o.length === n(e).length && o.every(n => n in e && ("text" === n || r(t[n], e[n])));
143
- }, R = (t, e) => {
155
+ }, D = (t, e) => {
144
156
  if (e.length) {
145
157
  const n = t.length;
146
158
  if (t.push(...e), n) {
@@ -149,13 +161,13 @@ var T = (n, r = 0, o = 1 / 0, c) => {
149
161
  let r = e + 1;
150
162
  for (;r <= n; ) {
151
163
  const e = t[r - 1], o = t[r];
152
- t[r - 1] = D(e, o), t.splice(r, 1), n--;
164
+ t[r - 1] = B(e, o), t.splice(r, 1), n--;
153
165
  }
154
166
  })(t, n - 1, n) : o || c || ((t, e = 0, n = t.length - 1) => {
155
167
  let r = e + 1;
156
168
  for (;r <= n; ) {
157
169
  const e = t[r - 1], o = t[r];
158
- i(e) && i(o) && O(e, o) ? (t[r - 1] = {
170
+ i(e) && i(o) && R(e, o) ? (t[r - 1] = {
159
171
  ...e,
160
172
  text: e.text + o.text
161
173
  }, t.splice(r, 1), n--) : r++;
@@ -170,29 +182,29 @@ var T = (n, r = 0, o = 1 / 0, c) => {
170
182
  t.length || t.push({
171
183
  text: ""
172
184
  });
173
- }, D = (...t) => ({
185
+ }, B = (...t) => ({
174
186
  ...t[0],
175
- children: t.reduce((t, e) => (R(t, e.children), t), [])
176
- }), B = (t, e, n, r = 0) => {
187
+ children: t.reduce((t, e) => (D(t, e.children), t), [])
188
+ }), I = (t, e, n, r = 0) => {
177
189
  if (r < e.length) {
178
190
  const o = e[r], c = t.children, s = c.slice();
179
- return s.splice(o, 1, B(c[o], e, n, r + 1)), {
191
+ return s.splice(o, 1, I(c[o], e, n, r + 1)), {
180
192
  ...t,
181
193
  children: s
182
194
  };
183
195
  }
184
196
  return n;
185
- }, I = (t, e, n, r) => {
186
- const [o, c] = x(t, e), s = e < n ? x(t, n)[1] : c, i = a(t.children);
187
- a(r) ? i || (r = D(...r).children) : i && (r = [ {
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 = [ {
188
200
  children: r
189
201
  } ]);
190
202
  const l = o.children.slice();
191
- return R(l, r), R(l, s.children), {
203
+ return D(l, r), D(l, s.children), {
192
204
  ...t,
193
205
  children: l
194
206
  };
195
- }, L = (t, e) => e >= 0 && e <= p(t), P = (t, e) => e.reduce((t, e) => H(t, e), t), H = (t, e, n) => {
207
+ }, P = (t, e) => e >= 0 && e <= p(t), H = (t, e) => e.reduce((t, e) => N(t, e), t), N = (t, e, n) => {
196
208
  switch (e.type) {
197
209
  case S:
198
210
  {
@@ -201,14 +213,14 @@ var T = (n, r = 0, o = 1 / 0, c) => {
201
213
  break;
202
214
  }
203
215
 
204
- case w:
216
+ case A:
205
217
  {
206
218
  const {at: r, text: o} = e;
207
219
  if (n ? t > r : t >= r) return t + o.length;
208
220
  break;
209
221
  }
210
222
 
211
- case A:
223
+ case O:
212
224
  {
213
225
  const {at: r, fragment: o} = e;
214
226
  if (n ? t > r : t >= r) return t + p({
@@ -218,16 +230,16 @@ var T = (n, r = 0, o = 1 / 0, c) => {
218
230
  }
219
231
  }
220
232
  return t;
221
- }, N = ([t, e], n) => [ H(t, n), H(e, n) ], C = ([t, e]) => t > e ? [ e, t ] : [ t, e ], W = ([t, e]) => t === e, F = ([t, e], [n, r]) => t < r && n < e;
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;
222
234
 
223
- function* U(t, e = C(t.selection)) {
224
- if (W(e)) {
235
+ function* V(t, e = W(t.selection)) {
236
+ if (F(e)) {
225
237
  const n = y(t.doc, e[0])?.[0];
226
238
  n && (yield n);
227
- } else for (const [n, r] of v(t.doc, e)) F(e, [ r, r + p(n) ]) && (yield n);
239
+ } else for (const [n, r] of T(t.doc, e)) U(e, [ r, r + p(n) ]) && (yield n);
228
240
  }
229
241
 
230
- function V(t, e) {
242
+ function q(t, e) {
231
243
  t.apply({
232
244
  type: "patch_node",
233
245
  path: [],
@@ -236,23 +248,23 @@ function V(t, e) {
236
248
  });
237
249
  }
238
250
 
239
- var q = t => 1 === t.nodeType, z = t => 8 === t.nodeType, G = 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 ] ]), J = new Set([ "DIV", "H1", "H2", "H3", "H4", "H5", "H6", "P", "PRE", "LI", "DT", "DD", "TH", "TD" ]), Y = t => J.has(t.tagName), j = (t, e) => t.compareDocumentPosition(e), X = t => t.ownerDocument, Z = t => X(t).getSelection(), K = (t, e) => {
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) => {
240
252
  if (t.rangeCount) {
241
253
  const n = t.getRangeAt(0);
242
254
  if (e.contains(n.commonAncestorContainer)) return n;
243
255
  }
244
- }, Q = (t, e, n, r) => {
245
- const [o, c] = ((t, [e, n]) => [ m(t, e), m(t, n) ])(n, r), s = X(t), i = W(r), l = r[0] - r[1] > 0, a = l ? o : c, u = tt(t, e, l ? c : o), f = i ? u : tt(t, e, a), p = s.createRange(), [d, h] = u, [y, x] = f;
246
- return q(d) && t !== d ? h < 1 ? p.setStartBefore(d) : p.setStartAfter(d) : p.setStart(d, h),
247
- q(y) && t !== y ? x < 1 ? p.setEndBefore(y) : p.setEndAfter(y) : p.setEnd(y, x),
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),
248
260
  p;
249
- }, $ = (t, e, n, r, o) => {
250
- const c = Z(t);
251
- if (o || K(c, t)) {
252
- const o = Q(t, e, n, r), s = r[0] - r[1] > 0;
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;
253
265
  c.removeAllRanges(), c.addRange(o), s && (c.collapseToEnd(), c.extend(o.startContainer, o.startOffset));
254
266
  }
255
- }, tt = (t, e, [n, r]) => e(({t: e, o, i: c, l: s}) => {
267
+ }, et = (t, e, [n, r]) => e(({t: e, o, i: c, l: s}) => {
256
268
  let i, l = 0;
257
269
  for (;i = e(); ) if (4 === i) {
258
270
  if (l < n.length) for (let t = n[l++]; t > 0; t--) o();
@@ -262,10 +274,10 @@ var q = t => 1 === t.nodeType, z = t => 8 === t.nodeType, G = new Map([ [ "BR",
262
274
  r -= t;
263
275
  }
264
276
  return [ t, 0 ];
265
- }, t), et = (e, n, r, o) => {
277
+ }, t), nt = (e, n, r, o) => {
266
278
  let c = !0;
267
279
  if (e === r && !r.hasChildNodes()) return [ [], 0 ];
268
- if (q(r) && r.hasChildNodes()) {
280
+ if (z(r) && r.hasChildNodes()) {
269
281
  const e = t(o, r.childNodes.length - 1);
270
282
  r = r.childNodes[e], c = e === o, o = 0;
271
283
  }
@@ -290,10 +302,10 @@ var q = t => 1 === t.nodeType, z = t => 8 === t.nodeType, G = new Map([ [ "BR",
290
302
  }
291
303
  return [ p, d + o ];
292
304
  }, e);
293
- }, nt = (t, e, {startOffset: n, startContainer: r, endOffset: o, endContainer: c}) => {
294
- const s = et(t, e, r, n);
295
- return [ s, r === c && n === o ? s : et(t, e, c, o) ];
296
- }, rt = "undefined" != typeof navigator && /Mac|iP(hone|od|ad)/.test(navigator.platform), ot = (t, 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) => {
297
309
  const n = t.endsWith("+"), r = (n ? t.slice(0, -2) : t).split("+"), o = n ? "+" : r.pop(), c = "Space" === o ? " " : o.toLowerCase();
298
310
  let s = !1, i = !1, l = !1, a = !1;
299
311
  return r.forEach(t => {
@@ -307,7 +319,7 @@ var q = t => 1 === t.nodeType, z = t => 8 === t.nodeType, G = new Map([ [ "BR",
307
319
  break;
308
320
 
309
321
  case "Mod":
310
- rt ? l = !0 : i = !0;
322
+ ot ? l = !0 : i = !0;
311
323
  break;
312
324
 
313
325
  case "Alt":
@@ -322,10 +334,10 @@ var q = t => 1 === t.nodeType, z = t => 8 === t.nodeType, G = new Map([ [ "BR",
322
334
  };
323
335
  };
324
336
 
325
- function ct(t) {
337
+ function st(t) {
326
338
  let e = 0, r = 0, o = !1;
327
339
  const c = Date.now, s = [ [ t.doc, t.selection, [] ] ], i = () => s[e], l = () => e > 0, a = () => e < s.length - 1, u = e => {
328
- t.exec(V, e.children);
340
+ t.exec(q, e.children);
329
341
  const r = e, o = t.doc;
330
342
  for (const c of n(r)) "children" !== c && o[c] !== r[c] && t.apply({
331
343
  type: "patch_node",
@@ -350,7 +362,7 @@ function ct(t) {
350
362
  if (a()) {
351
363
  e++;
352
364
  const [n, r, c] = i(), s = t.doc;
353
- o = !0, u(n), o = !1, s !== t.doc && (t.selection = [ P(r[0], c), P(r[1], c) ]);
365
+ o = !0, u(n), o = !1, s !== t.doc && (t.selection = [ H(r[0], c), H(r[1], c) ]);
354
366
  }
355
367
  };
356
368
  t.hook("apply", (n, i) => {
@@ -368,18 +380,21 @@ function ct(t) {
368
380
  r = t, s[e][0] = u, s[e][2].push(n), s.length > e + 1 && (s.length = e + 1), e > 500 && (e--,
369
381
  s.shift());
370
382
  }
371
- }), t.hook("keyboard", ot("Mod+Z", f)), t.hook("keyboard", ot("Shift+Mod+Z", p)),
372
- t.set(ct, {
383
+ }), t.hook("keyboard", ct("Mod+Z", f)), t.hook("keyboard", ct("Shift+Mod+Z", p)),
384
+ t.set(st, {
373
385
  undo: f,
374
386
  redo: p,
375
387
  undoable: l,
376
- redoable: a
388
+ redoable: a,
389
+ clear: () => {
390
+ s.length = 0, s.push([ t.doc, t.selection, [] ]), e = 0, r = 0;
391
+ }
377
392
  });
378
393
  }
379
394
 
380
- var st = [], it = () => {}, lt = t => {
395
+ var it = [], lt = () => {}, at = t => {
381
396
  throw Error(t);
382
- }, at = ({doc: t, readonly: e = !1, schema: n, isBlock: r = Y, onWarn: a = console.warn, onError: u = lt}) => {
397
+ }, ut = ({doc: t, readonly: e = !1, schema: n, isBlock: r = Y, onWarn: a = console.warn, onError: u = at}) => {
383
398
  let f = [ 0, 0 ];
384
399
  const p = t => {
385
400
  if (!n) return a("An unsafe operation was detected. We recommend using schema option."),
@@ -392,8 +407,8 @@ var st = [], it = () => {}, lt = t => {
392
407
  return !1;
393
408
  };
394
409
  n && !p(t) && u("Invalid document");
395
- const y = new Map, x = new WeakMap, m = t => y.get(t) || st, _ = new Map, b = new Set, v = t => {
396
- const e = _.get(t);
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);
397
412
  e && (b.size || s(() => {
398
413
  b.forEach(t => {
399
414
  t();
@@ -402,10 +417,10 @@ var st = [], it = () => {}, lt = t => {
402
417
  b.add(t);
403
418
  }));
404
419
  }, T = t => {
405
- if (!e) if (Array.isArray(t)) for (const e of t) O(e); else O(t);
420
+ if (!e) if (Array.isArray(t)) for (const e of t) E(e); else E(t);
406
421
  return D;
407
- }, O = e => {
408
- const n = t, r = m("apply"), o = r.length;
422
+ }, E = e => {
423
+ const n = t, r = k("apply"), o = r.length;
409
424
  let c = 0;
410
425
  const s = () => {
411
426
  if (c < o) {
@@ -419,40 +434,40 @@ var st = [], it = () => {}, lt = t => {
419
434
  case S:
420
435
  {
421
436
  const [r, o] = n.range;
422
- L(t, r) && L(t, o) && r < o && (t = I(t, r, o, []), e = N(e, n));
437
+ P(t, r) && P(t, o) && r < o && (t = L(t, r, o, []), e = C(e, n));
423
438
  break;
424
439
  }
425
440
 
426
- case w:
441
+ case A:
427
442
  {
428
443
  const {at: r, text: o} = n;
429
- if (L(t, r) && o) {
444
+ if (P(t, r) && o) {
430
445
  const [c, s] = h(t, r), l = d(c, s, !0);
431
446
  let a;
432
447
  if (l) {
433
448
  const t = l[0];
434
449
  i(t) && (a = t);
435
450
  }
436
- t = I(t, r, r, M(o, a, c)), e = N(e, n);
451
+ t = L(t, r, r, M(o, a, c)), e = C(e, n);
437
452
  }
438
453
  break;
439
454
  }
440
455
 
441
- case A:
456
+ case O:
442
457
  {
443
458
  const {at: r, fragment: o} = n;
444
- L(t, r) && o.length && (t = I(t, r, r, o), e = N(e, n));
459
+ P(t, r) && o.length && (t = L(t, r, r, o), e = C(e, n));
445
460
  break;
446
461
  }
447
462
 
448
463
  case "format":
449
464
  {
450
465
  const {range: [e, r], key: o, value: c} = n;
451
- if (L(t, e) && L(t, r) && e <= r) if (e === r) {
466
+ if (P(t, e) && P(t, r) && e <= r) if (e === r) {
452
467
  const [{children: n}, , r] = h(t, e);
453
468
  if (1 === n.length) {
454
469
  const e = n[0];
455
- i(e) && !e.text && (t = B(t, [ ...r, 0 ], {
470
+ i(e) && !e.text && (t = I(t, [ ...r, 0 ], {
456
471
  ...e,
457
472
  [o]: c
458
473
  }));
@@ -465,7 +480,7 @@ var st = [], it = () => {}, lt = t => {
465
480
  ...t,
466
481
  [o]: c
467
482
  } : t;
468
- t = I(t, e, r, E(t, e, r).map(n));
483
+ t = L(t, e, r, w(t, e, r).map(n));
469
484
  }
470
485
  break;
471
486
  }
@@ -476,7 +491,7 @@ var st = [], it = () => {}, lt = t => {
476
491
  for (let n = 0; n < e.length; n++) t = t.children[e[n]];
477
492
  return t;
478
493
  })(t, e);
479
- c && (t = B(t, e, {
494
+ c && (t = I(t, e, {
480
495
  ...c,
481
496
  [r]: o
482
497
  }));
@@ -485,7 +500,7 @@ var st = [], it = () => {}, lt = t => {
485
500
  }
486
501
  return [ t, e ];
487
502
  })(t, f, e);
488
- (({type: t}) => t !== w && t !== S)(e) && !p(n) || (t = n, R(r));
503
+ (({type: t}) => t !== A && t !== S)(e) && !p(n) || (t = n, R(r));
489
504
  } catch (n) {
490
505
  a("rollback operation: " + n);
491
506
  }
@@ -495,7 +510,7 @@ var st = [], it = () => {}, lt = t => {
495
510
  };
496
511
  s(), n !== t && v("change");
497
512
  }, R = e => {
498
- !((t, [e, n]) => L(t, e) && L(t, n))(t, e) || f[0] === e[0] && f[1] === e[1] || (f = e,
513
+ !((t, [e, n]) => P(t, e) && P(t, n))(t, e) || f[0] === e[0] && f[1] === e[1] || (f = e,
499
514
  v("selectionchange"));
500
515
  }, D = {
501
516
  get doc() {
@@ -515,8 +530,8 @@ var st = [], it = () => {}, lt = t => {
515
530
  },
516
531
  apply: T,
517
532
  on: (t, e) => {
518
- let n = _.get(t);
519
- return n || _.set(t, n = new Set), n.add(e), () => {
533
+ let n = g.get(t);
534
+ return n || g.set(t, n = new Set), n.add(e), () => {
520
535
  n.delete(e);
521
536
  };
522
537
  },
@@ -535,21 +550,21 @@ var st = [], it = () => {}, lt = t => {
535
550
  set: (t, e) => (x.set(t, e), D),
536
551
  input: n => {
537
552
  if (!window.InputEvent || !c(InputEvent.prototype.getTargetRanges)) return a("beforeinput event is not supported."),
538
- it;
553
+ lt;
539
554
  const {contentEditable: s, role: i, ariaMultiLine: l, ariaReadOnly: u} = n, p = n.style.whiteSpace;
540
555
  n.role = "textbox", n.style.whiteSpace = "pre-wrap", n.ariaMultiLine = "true";
541
- let d = !1, h = null, y = !1, x = !1, _ = !1, b = f, v = null;
542
- const E = X(n), M = ((t, e) => {
556
+ let d = !1, h = null, y = !1, x = !1, g = !1, b = f, v = null;
557
+ const E = Z(n), w = ((t, e) => {
543
558
  let n = null, r = null, o = null;
544
559
  const c = () => {
545
560
  if (null != o) return o;
546
561
  if (r) if ((t => 3 === t.nodeType)(r)) {
547
562
  const t = r.data;
548
563
  if (t) return o = "\n" === t ? i() ? 3 : 5 : 1;
549
- } else if (q(r)) {
564
+ } else if (z(r)) {
550
565
  if ("false" === r.contentEditable) return o = 2;
551
566
  {
552
- const t = G.get(r.tagName);
567
+ const t = J.get(r.tagName);
553
568
  if (null != t) return o = 1 === t ? i() ? 3 : 5 : 3 === t ? 2 : 6;
554
569
  if (e(r)) return o = 4;
555
570
  }
@@ -606,26 +621,29 @@ var st = [], it = () => {}, lt = t => {
606
621
  }
607
622
  };
608
623
  return a;
609
- })(E, r), S = () => {
624
+ })(E, r), M = () => {
610
625
  n.contentEditable = e ? "false" : "true", n.ariaReadOnly = e ? "true" : null;
611
626
  };
612
- S();
613
- const w = () => {
627
+ M();
628
+ const S = () => {
614
629
  x || n.focus({
615
630
  preventScroll: !0
616
631
  });
617
632
  }, A = () => {
618
- v = null, f[0] === b[0] && f[1] === b[1] || ($(n, M, t, f), b = f);
633
+ v = null, f[0] === b[0] && f[1] === b[1] || (tt(n, w, t, f), b = f);
619
634
  }, O = () => {
620
635
  null != v && clearTimeout(v);
621
636
  }, B = D.on("change", () => {
622
- x || requestAnimationFrame(w);
637
+ x || requestAnimationFrame(S);
623
638
  }), I = D.on("selectionchange", () => {
624
639
  f[0] === b[0] && f[1] === b[1] || (O(), v = setTimeout(A, 50));
625
- }), L = D.on("readonly", S), H = t => {
626
- for (const e of m("paste")) {
640
+ }), L = D.on("readonly", M), P = t => {
641
+ for (const e of k("paste")) {
627
642
  const n = e(t);
628
- if (n) return n;
643
+ if (n) {
644
+ if (!0 === n) return;
645
+ return n;
646
+ }
629
647
  }
630
648
  a("failed to serialize pasted data");
631
649
  }, N = ((t, e) => {
@@ -665,28 +683,28 @@ var st = [], it = () => {}, lt = t => {
665
683
  }
666
684
  };
667
685
  })(n, () => {
668
- O(), $(n, M, t, f);
669
- }), F = () => {
670
- R(b = g(t, ((t, e) => {
671
- const n = Z(t), r = K(n, t);
686
+ O(), tt(n, w, t, f);
687
+ }), C = () => {
688
+ R(b = _(t, ((t, e) => {
689
+ const n = K(t), r = Q(n, t);
672
690
  if (!r) return [ [ [ 0 ], 0 ], [ [ 0 ], 0 ] ];
673
- const o = nt(t, e, r), c = j(n.anchorNode, n.focusNode);
691
+ const o = rt(t, e, r), c = j(n.anchorNode, n.focusNode);
674
692
  return (0 === c ? n.anchorOffset > n.focusOffset : 2 & c) ? [ o[1], o[0] ] : o;
675
- })(n, M)));
693
+ })(n, w)));
676
694
  }, U = () => {
677
695
  const e = N.v();
678
- N._(!1), e.length && (N.m(e), E.removeEventListener("selectionchange", ot), $(n, M, t, f, !0),
696
+ N._(!1), e.length && (N.m(e), E.removeEventListener("selectionchange", ot), tt(n, w, t, f, !0),
679
697
  E.addEventListener("selectionchange", ot)), h && (R(h[1]), T(h[0]), h = null), y = !1;
680
698
  }, V = t => {
681
- if (!y) for (const e of m("keyboard")) if (e(t)) return t.preventDefault(), void N._(!1);
682
- }, z = () => {
699
+ if (!y) for (const e of k("keyboard")) if (e(t)) return t.preventDefault(), void N._(!1);
700
+ }, q = () => {
683
701
  y || U();
684
- }, J = e => {
702
+ }, G = e => {
685
703
  e.preventDefault();
686
704
  const r = e.inputType;
687
705
  if (r.startsWith("format")) return;
688
706
  if ("historyUndo" === r || "historyRedo" === r) return;
689
- y ? N._(!0) : F();
707
+ y ? N._(!0) : C();
690
708
  const o = e.getTargetRanges()[0];
691
709
  if (o) {
692
710
  let c = "insertParagraph" === r || "insertLineBreak" === r ? "\n" : e.data;
@@ -695,8 +713,8 @@ var st = [], it = () => {}, lt = t => {
695
713
  t && (c = t.getData("text/plain"));
696
714
  }
697
715
  h || (h = [ [], f ]);
698
- const s = h[0], i = g(t, nt(n, M, o));
699
- W(i) || s.push({
716
+ const s = h[0], i = _(t, rt(n, w, o));
717
+ F(i) || s.push({
700
718
  type: "delete",
701
719
  range: i
702
720
  }), c && s.push({
@@ -706,30 +724,30 @@ var st = [], it = () => {}, lt = t => {
706
724
  });
707
725
  }
708
726
  y || U();
727
+ }, X = () => {
728
+ y || C(), y = !0;
709
729
  }, Y = () => {
710
- y || F(), y = !0;
711
- }, Q = () => {
712
730
  U();
713
- }, tt = () => {
714
- x = !0, F();
715
- }, rt = () => {
731
+ }, $ = () => {
732
+ x = !0, C();
733
+ }, et = () => {
716
734
  x = !1;
717
735
  }, ot = () => {
718
- !x || y || _ || F();
736
+ !x || y || g || C();
719
737
  }, ct = t => {
720
- if (F(), !W(f)) for (const e of m("copy")) e(t);
738
+ if (C(), !F(f)) for (const e of k("copy")) e(t);
721
739
  }, st = t => {
722
740
  t.preventDefault(), ct(t.clipboardData);
723
- }, lt = t => {
741
+ }, it = t => {
724
742
  t.preventDefault(), e || (ct(t.clipboardData), T({
725
743
  type: "delete",
726
- range: C(f)
744
+ range: W(f)
727
745
  }));
728
746
  }, at = t => {
729
747
  t.preventDefault();
730
- const e = H(t.clipboardData);
748
+ const e = P(t.clipboardData);
731
749
  if (e) {
732
- const t = C(f), n = t[0], r = [ {
750
+ const t = W(f), n = t[0], r = [ {
733
751
  type: "delete",
734
752
  range: t
735
753
  } ];
@@ -746,25 +764,25 @@ var st = [], it = () => {}, lt = t => {
746
764
  }, ut = e => {
747
765
  e.preventDefault();
748
766
  const r = e.dataTransfer, c = ((t, e, {clientX: n, clientY: r}) => {
749
- const o = X(t);
767
+ const o = Z(t);
750
768
  if (o.caretPositionFromPoint) {
751
769
  const c = o.caretPositionFromPoint(n, r);
752
- if (c) return et(t, e, c.offsetNode, c.offset);
770
+ if (c) return nt(t, e, c.offsetNode, c.offset);
753
771
  } else if (o.caretRangeFromPoint) {
754
772
  const c = o.caretRangeFromPoint(n, r);
755
- if (c) return et(t, e, c.startContainer, c.startOffset);
773
+ if (c) return nt(t, e, c.startContainer, c.startOffset);
756
774
  }
757
- })(n, M, e);
775
+ })(n, w, e);
758
776
  if (r && c) {
759
777
  let e;
760
778
  const n = [];
761
- _ && n.push({
779
+ g && n.push({
762
780
  type: "delete",
763
- range: C(f)
781
+ range: W(f)
764
782
  });
765
- const s = H(r);
783
+ const s = P(r);
766
784
  if (s) {
767
- const r = k(t, c), i = P(r, n);
785
+ const r = m(t, c), i = H(r, n);
768
786
  n.push(o(s) ? {
769
787
  type: "insert_text",
770
788
  at: i,
@@ -773,54 +791,54 @@ var st = [], it = () => {}, lt = t => {
773
791
  type: "insert_node",
774
792
  at: i,
775
793
  fragment: s
776
- }), e = [ i, P(r, n) ];
794
+ }), e = [ i, H(r, n) ];
777
795
  }
778
796
  T(n), e && R(e);
779
797
  }
780
- _ = !1;
798
+ g = !1;
781
799
  }, ft = t => {
782
- _ = !0, ct(t.dataTransfer);
800
+ g = !0, ct(t.dataTransfer);
783
801
  }, pt = () => {
784
- _ = !1;
802
+ g = !1;
785
803
  };
786
- E.addEventListener("selectionchange", ot), n.addEventListener("keydown", V), n.addEventListener("input", z),
787
- n.addEventListener("beforeinput", J), n.addEventListener("compositionstart", Y),
788
- n.addEventListener("compositionend", Q), n.addEventListener("focus", tt), n.addEventListener("blur", rt),
789
- n.addEventListener("copy", st), n.addEventListener("cut", lt), n.addEventListener("paste", at),
804
+ E.addEventListener("selectionchange", ot), n.addEventListener("keydown", V), n.addEventListener("input", q),
805
+ n.addEventListener("beforeinput", G), n.addEventListener("compositionstart", X),
806
+ n.addEventListener("compositionend", Y), n.addEventListener("focus", $), n.addEventListener("blur", et),
807
+ n.addEventListener("copy", st), n.addEventListener("cut", it), n.addEventListener("paste", at),
790
808
  n.addEventListener("drop", ut), n.addEventListener("dragstart", ft), n.addEventListener("dragend", pt);
791
809
  const dt = [];
792
- return m("mount").forEach(t => {
793
- const e = t(n, M);
810
+ return k("mount").forEach(t => {
811
+ const e = t(n, w);
794
812
  e && dt.push(e);
795
813
  }), () => {
796
814
  d || (d = !0, B(), I(), L(), n.contentEditable = s, n.role = i, n.ariaMultiLine = l,
797
815
  n.ariaReadOnly = u, n.style.whiteSpace = p, N.T(), E.removeEventListener("selectionchange", ot),
798
- n.removeEventListener("keydown", V), n.removeEventListener("input", z), n.removeEventListener("beforeinput", J),
799
- n.removeEventListener("compositionstart", Y), n.removeEventListener("compositionend", Q),
800
- n.removeEventListener("focus", tt), n.removeEventListener("blur", rt), n.removeEventListener("copy", st),
801
- n.removeEventListener("cut", lt), n.removeEventListener("paste", at), n.removeEventListener("drop", ut),
816
+ n.removeEventListener("keydown", V), n.removeEventListener("input", q), n.removeEventListener("beforeinput", G),
817
+ n.removeEventListener("compositionstart", X), n.removeEventListener("compositionend", Y),
818
+ n.removeEventListener("focus", $), n.removeEventListener("blur", et), n.removeEventListener("copy", st),
819
+ n.removeEventListener("cut", it), n.removeEventListener("paste", at), n.removeEventListener("drop", ut),
802
820
  n.removeEventListener("dragstart", ft), n.removeEventListener("dragend", pt), dt.forEach(t => {
803
821
  t();
804
822
  }));
805
823
  };
806
824
  }
807
825
  };
808
- return D.exec(ct), D;
826
+ return D.exec(st), D;
809
827
  };
810
828
 
811
- function ut(t, e) {
829
+ function ft(t, e) {
812
830
  const n = e && e.voidToString;
813
831
  t.hook("copy", e => {
814
- e.setData("text/plain", T(t.doc, ...C(t.selection), n));
832
+ e.setData("text/plain", E(t.doc, ...W(t.selection), n));
815
833
  }), t.hook("paste", t => t.getData("text/plain"));
816
834
  }
817
835
 
818
- var ft = "application/x-editate-editor";
836
+ var pt = "application/x-editate-editor";
819
837
 
820
- function pt(t, e) {
838
+ function dt(t, e) {
821
839
  const n = e.isLocked, r = e => n(h(t.doc, e)[0]), o = (e, r) => {
822
840
  const [o, c] = e;
823
- for (const [s, i] of b(t.doc, e)) {
841
+ for (const [s, i] of v(t.doc, e)) {
824
842
  const t = i + p(s);
825
843
  if ((r ? c >= i && o <= t : c > i && o < t) && n(s)) return !0;
826
844
  }
@@ -831,7 +849,7 @@ function pt(t, e) {
831
849
  const a = c;
832
850
  switch (c = !1, e.type) {
833
851
  case "delete":
834
- if (o(C(e.range), !0)) return c = !0, s(() => {
852
+ if (o(W(e.range), !0)) return c = !0, s(() => {
835
853
  c = !1;
836
854
  }), i(null);
837
855
  break;
@@ -843,8 +861,8 @@ function pt(t, e) {
843
861
 
844
862
  case "format":
845
863
  {
846
- const t = C(e.range);
847
- if (W(t) ? r(t[0]) : o(t, !1)) return i(null);
864
+ const t = W(e.range);
865
+ if (F(t) ? r(t[0]) : o(t, !1)) return i(null);
848
866
  break;
849
867
  }
850
868
 
@@ -865,17 +883,26 @@ function pt(t, e) {
865
883
  }
866
884
  }
867
885
  i(e);
868
- }), t.set(pt, {
869
- locked: t => W(t) ? r(t[0]) : o(t, !0)
886
+ }), t.set(dt, {
887
+ locked: t => F(t) ? r(t[0]) : o(t, !0)
870
888
  });
871
889
  }
872
890
 
873
- var dt = (t, e) => {
891
+ var ht = (t, e) => {
874
892
  const n = parseFloat(t);
875
893
  return n ? t.endsWith("%") ? n / 100 * e : n : 0;
876
- }, ht = (t, e, n, r) => [ t + dt(n, e), t + e - dt(r, e) ], yt = (t, e, [n, r]) => t < n ? t - n : e > r ? e - r : 0, xt = (t, e, n) => Math.max(-e, Math.min(t, n - e));
894
+ }, yt = (t, e, n, r) => [ t + ht(n, e), t + e - ht(r, e) ], xt = t => "auto" === t || "scroll" === t || "overlay" === t, kt = (t, e, [n, r]) => t < n ? t - n : e > r ? e - r : 0, mt = (t, e, n, r) => {
895
+ const o = r ? -n : 0;
896
+ return Math.max(o - e, Math.min(t, o + n - e));
897
+ }, gt = (t, [e, n], r) => {
898
+ (n || e) && t.scrollBy({
899
+ top: n,
900
+ left: e,
901
+ behavior: r
902
+ });
903
+ };
877
904
 
878
- function kt(t) {
905
+ function _t(t) {
879
906
  t.hook("mount", t => {
880
907
  t.ariaMultiLine = null;
881
908
  }), t.hook("apply", (t, e) => {
@@ -886,19 +913,21 @@ function kt(t) {
886
913
  const e = t.fragment;
887
914
  t = {
888
915
  ...t,
889
- fragment: a(e) ? [ D(...e) ] : e
916
+ fragment: a(e) ? [ B(...e) ] : e
890
917
  };
891
918
  }
892
919
  e(t);
893
920
  });
894
921
  }
895
922
 
896
- exports.Delete = function(t, e = C(t.selection)) {
923
+ exports.ClearHistory = function(t) {
924
+ t.get(st).clear();
925
+ }, exports.Delete = function(t, e = W(t.selection)) {
897
926
  t.apply({
898
927
  type: "delete",
899
928
  range: e
900
929
  });
901
- }, exports.Format = function(t, e, n, r = C(t.selection)) {
930
+ }, exports.Format = function(t, e, n, r = W(t.selection)) {
902
931
  t.apply({
903
932
  type: "format",
904
933
  range: r,
@@ -919,13 +948,13 @@ exports.Delete = function(t, e = C(t.selection)) {
919
948
  at: n,
920
949
  text: e
921
950
  });
922
- }, exports.LeavesInRange = U, exports.LockedInRange = function(t, e = C(t.selection)) {
923
- return t.get(pt).locked(e);
951
+ }, exports.LeavesInRange = V, exports.LockedInRange = function(t, e = W(t.selection)) {
952
+ return t.get(dt).locked(e);
924
953
  }, exports.Redo = function(t) {
925
- t.get(ct).redo();
954
+ t.get(st).redo();
926
955
  }, exports.Redoable = function(t) {
927
- return t.get(ct).redoable();
928
- }, exports.ReplaceDoc = V, exports.ReplaceText = function(t, e, n = C(t.selection)) {
956
+ return t.get(st).redoable();
957
+ }, exports.ReplaceDoc = q, exports.ReplaceText = function(t, e, n = W(t.selection)) {
929
958
  t.apply({
930
959
  type: "delete",
931
960
  range: n
@@ -958,9 +987,9 @@ exports.Delete = function(t, e = C(t.selection)) {
958
987
  key: e,
959
988
  value: c[e] === n ? r : n
960
989
  });
961
- }, exports.ToggleFormat = function(t, e, n = C(t.selection)) {
990
+ }, exports.ToggleFormat = function(t, e, n = W(t.selection)) {
962
991
  let r = !1, o = !1;
963
- for (const c of t.exec(U, n)) if (i(c) && (o = !0, !c[e])) {
992
+ for (const c of t.exec(V, n)) if (i(c) && (o = !0, !c[e])) {
964
993
  r = !0;
965
994
  break;
966
995
  }
@@ -971,18 +1000,18 @@ exports.Delete = function(t, e = C(t.selection)) {
971
1000
  value: r
972
1001
  });
973
1002
  }, exports.Undo = function(t) {
974
- t.get(ct).undo();
1003
+ t.get(st).undo();
975
1004
  }, exports.Undoable = function(t) {
976
- return t.get(ct).undoable();
977
- }, exports.blockLockPlugin = pt, exports.createEditor = at, exports.createPlainEditor = ({text: t, singleline: e, onChange: n, ...r}) => {
978
- const o = at({
1005
+ return t.get(st).undoable();
1006
+ }, exports.blockLockPlugin = dt, exports.createEditor = ut, exports.createPlainEditor = ({text: t, singleline: e, onChange: n, ...r}) => {
1007
+ const o = ut({
979
1008
  ...r,
980
1009
  doc: {
981
1010
  children: M(t)
982
1011
  }
983
- }).exec(ut);
984
- return e && o.exec(kt), o.on("change", () => {
985
- n(T(o.doc));
1012
+ }).exec(ft);
1013
+ return e && o.exec(_t), o.on("change", () => {
1014
+ n(E(o.doc));
986
1015
  }), o;
987
1016
  }, exports.debugPlugin = function(t) {
988
1017
  t.hook("apply", t => {
@@ -1005,12 +1034,12 @@ exports.Delete = function(t, e = C(t.selection)) {
1005
1034
  }
1006
1035
  return null;
1007
1036
  });
1008
- }, exports.getChildAt = d, exports.getLeafAt = y, exports.getLeafBlockAt = h, exports.getNodeSize = p,
1009
- exports.htmlTransferPlugin = function(t, e) {
1037
+ }, exports.getChildAt = d, exports.getLeafAt = y, exports.getLeafBlockAt = h, exports.getNodeOffset = x,
1038
+ exports.getNodeSize = p, exports.htmlTransferPlugin = function(t, e) {
1010
1039
  t.hook("mount", (n, r) => {
1011
1040
  const o = t.hook("copy", t => {
1012
1041
  const e = document.createElement("div");
1013
- e.appendChild(K(Z(n), n).cloneContents()), t.setData("text/html", e.innerHTML);
1042
+ e.appendChild(Q(K(n), n).cloneContents()), t.setData("text/html", e.innerHTML);
1014
1043
  }), c = t.hook("paste", t => {
1015
1044
  const n = t.getData("text/html");
1016
1045
  return n ? ((t, e, n) => {
@@ -1022,7 +1051,7 @@ exports.htmlTransferPlugin = function(t, e) {
1022
1051
  }
1023
1052
  };
1024
1053
  let c = (new DOMParser).parseFromString(t, "text/html").body, s = !1;
1025
- for (const i of [ ...c.childNodes ]) z(i) ? "StartFragment" === i.data ? (s = !0,
1054
+ for (const i of [ ...c.childNodes ]) G(i) ? "StartFragment" === i.data ? (s = !0,
1026
1055
  c = new DocumentFragment) : "EndFragment" === i.data && (s = !1) : s && c.appendChild(i);
1027
1056
  return e(({t, i: e}) => {
1028
1057
  let n, c = null, s = "", i = !1;
@@ -1048,64 +1077,72 @@ exports.htmlTransferPlugin = function(t, e) {
1048
1077
  o(), c();
1049
1078
  };
1050
1079
  });
1051
- }, exports.internalTranferPlugin = function(t) {
1080
+ }, exports.internalTransferPlugin = function(t) {
1052
1081
  t.hook("copy", e => {
1053
- e.setData(ft, JSON.stringify(E(t.doc, ...C(t.selection))));
1082
+ e.setData(pt, JSON.stringify(w(t.doc, ...W(t.selection))));
1054
1083
  }), t.hook("paste", t => {
1055
1084
  try {
1056
- return JSON.parse(t.getData(ft));
1085
+ return JSON.parse(t.getData(pt));
1057
1086
  } catch (e) {
1058
1087
  return null;
1059
1088
  }
1060
1089
  });
1061
- }, exports.iterLeafBlocks = b, exports.iterLeaves = v, exports.keymapPlugin = function(t, e) {
1090
+ }, exports.iterLeafBlocks = v, exports.iterLeaves = T, exports.keymapPlugin = function(t, e) {
1062
1091
  n(e).forEach(n => {
1063
1092
  const r = e[n];
1064
- t.hook("keyboard", ot(n, r));
1093
+ t.hook("keyboard", ct(n, r));
1065
1094
  });
1066
- }, exports.mapPosition = H, exports.plainTransferPlugin = ut, exports.scrollToSelectionPlugin = t => {
1095
+ }, exports.mapPosition = N, exports.plainTransferPlugin = ft, exports.scrollToSelectionPlugin = t => {
1067
1096
  const e = "auto";
1068
1097
  t.hook("mount", (n, r) => {
1069
- const o = X(n), c = o.defaultView, s = ((t, e, n) => {
1098
+ const o = Z(n), c = o.defaultView, {documentElement: s} = o, i = ((t, e, n) => {
1070
1099
  const {body: r, documentElement: o} = e;
1071
1100
  let c = t;
1072
1101
  for (;c && c !== r && c !== o; ) {
1073
- const {overflowY: t} = n.getComputedStyle(c);
1074
- if ("auto" === t || "scroll" === t || "overlay" === t) return c;
1102
+ const {overflowX: t, overflowY: e} = n.getComputedStyle(c);
1103
+ if (xt(t) || xt(e)) return c;
1075
1104
  c = c.parentElement;
1076
1105
  }
1077
1106
  return null;
1078
- })(n, o, c);
1079
- let i = null;
1080
- const l = t.on("change", () => {
1081
- null == i && (i = setTimeout(() => {
1082
- i = null;
1083
- const o = Q(n, r, t.doc, t.selection);
1084
- let l = o.getBoundingClientRect();
1085
- if (!l.height) {
1086
- const t = o.startContainer, e = q(t) ? t : t.parentElement;
1087
- e && (l = e.getBoundingClientRect());
1107
+ })(n, o, c), l = i && c.getComputedStyle(i), a = c.getComputedStyle(s);
1108
+ let u = null;
1109
+ const f = t.on("change", () => {
1110
+ null == u && (u = setTimeout(() => {
1111
+ u = null;
1112
+ const o = $(n, r, t.doc, t.selection);
1113
+ let f = o.getBoundingClientRect();
1114
+ if (!f.width && !f.height) {
1115
+ const t = o.startContainer, e = z(t) ? t : t.parentElement;
1116
+ e && (f = e.getBoundingClientRect());
1088
1117
  }
1089
- const a = s ? ((t, e, n, r) => {
1090
- const {scrollLeft: o, scrollTop: c, scrollWidth: s, scrollHeight: i, clientLeft: l, clientTop: a, clientWidth: u, clientHeight: f} = e, p = e.getBoundingClientRect(), d = t.getComputedStyle(e), h = xt(yt(n.top, n.bottom, ht(p.top + a, f, d.scrollPaddingTop, d.scrollPaddingBottom)), c, i - f), y = xt(yt(n.left, n.right, ht(p.left + l, u, d.scrollPaddingLeft, d.scrollPaddingRight)), o, s - u);
1091
- return (h || y) && e.scrollBy({
1092
- top: h,
1093
- left: y,
1094
- behavior: r
1095
- }), [ y, h ];
1096
- })(c, s, l, e) : [ 0, 0 ];
1097
- ((t, e, [n, r], o) => {
1098
- const {documentElement: c} = t.document, {clientWidth: s, clientHeight: i} = c, l = t.getComputedStyle(c), a = yt(e.top - r, e.bottom - r, ht(0, i, l.scrollPaddingTop, l.scrollPaddingBottom)), u = yt(e.left - n, e.right - n, ht(0, s, l.scrollPaddingLeft, l.scrollPaddingRight));
1099
- (a || u) && t.scrollBy({
1100
- top: a,
1101
- left: u,
1102
- behavior: o
1103
- });
1104
- })(c, l, a, e);
1118
+ const p = i && l ? ((t, e, n) => {
1119
+ const {scrollLeft: r, scrollTop: o, scrollWidth: c, scrollHeight: s, clientLeft: i, clientTop: l, clientWidth: a, clientHeight: u} = t, f = t.getBoundingClientRect(), [p, d] = (t => {
1120
+ const e = "rtl" === t.direction;
1121
+ switch (t.writingMode) {
1122
+ case "vertical-rl":
1123
+ case "sideways-rl":
1124
+ return [ !0, e ];
1125
+
1126
+ case "vertical-lr":
1127
+ return [ !1, e ];
1128
+
1129
+ case "sideways-lr":
1130
+ return [ !1, !e ];
1131
+
1132
+ default:
1133
+ return [ e, !1 ];
1134
+ }
1135
+ })(e), h = mt(kt(n.top, n.bottom, yt(f.top + l, u, e.scrollPaddingTop, e.scrollPaddingBottom)), o, s - u, d);
1136
+ return [ mt(kt(n.left, n.right, yt(f.left + i, a, e.scrollPaddingLeft, e.scrollPaddingRight)), r, c - a, p), h ];
1137
+ })(i, l, f) : [ 0, 0 ], d = ((t, e, n, [r, o]) => {
1138
+ const {clientWidth: c, clientHeight: s} = t, i = kt(n.top - o, n.bottom - o, yt(0, s, e.scrollPaddingTop, e.scrollPaddingBottom));
1139
+ return [ kt(n.left - r, n.right - r, yt(0, c, e.scrollPaddingLeft, e.scrollPaddingRight)), i ];
1140
+ })(s, a, f, p);
1141
+ i && gt(i, p, e), gt(c, d, e);
1105
1142
  }, 50));
1106
1143
  });
1107
1144
  return () => {
1108
- null != i && clearTimeout(i), l();
1145
+ null != u && clearTimeout(u), f();
1109
1146
  };
1110
1147
  });
1111
1148
  }, exports.selectionRectPlugin = function(t, e) {
@@ -1115,7 +1152,7 @@ exports.htmlTransferPlugin = function(t, e) {
1115
1152
  c || (c = !0, requestAnimationFrame(() => {
1116
1153
  c = !1, o && e(() => {
1117
1154
  const e = t.selection;
1118
- return Q(n, r, t.doc, e).getBoundingClientRect();
1155
+ return $(n, r, t.doc, e).getBoundingClientRect();
1119
1156
  });
1120
1157
  }));
1121
1158
  });
@@ -1123,5 +1160,5 @@ exports.htmlTransferPlugin = function(t, e) {
1123
1160
  o = !1, s();
1124
1161
  };
1125
1162
  });
1126
- }, exports.singlelinePlugin = kt, exports.sliceText = T;
1163
+ }, exports.singlelinePlugin = _t, exports.sliceText = E;
1127
1164
  //# sourceMappingURL=index.cjs.map