editate 0.6.19 → 0.6.21

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