editate 0.6.8 → 0.6.10

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