editate 0.6.18 → 0.6.19

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