editate 0.7.0 → 0.7.2

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,50 +1,49 @@
1
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
2
  Promise.resolve().then(t);
3
- }, i = t => "text" in t, l = t => "children" in t, a = t => t.some(l), f = /* @__PURE__ */ new WeakMap, u = ({children: t}, e = 0, n = t.length) => {
4
- let r = 0;
5
- for (let o = e; o < n; o++) {
6
- const n = t[o];
7
- r += d(n), o !== e && l(n) && r++;
8
- }
9
- return r;
10
- }, d = t => {
3
+ }, i = t => "text" in t, l = t => "children" in t, a = t => t.some(l), f = /* @__PURE__ */ new WeakMap, u = t => {
11
4
  if (l(t)) {
12
5
  let e = f.get(t);
13
- return null == e && f.set(t, e = u(t)), e;
6
+ if (null == e) {
7
+ const {children: n} = t;
8
+ e = 0;
9
+ for (let t = 0; t < n.length; t++) {
10
+ const r = n[t];
11
+ e += u(r), 0 !== t && l(r) && e++;
12
+ }
13
+ f.set(t, e);
14
+ }
15
+ return e;
14
16
  }
15
17
  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 = l(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;
18
+ }, d = ({children: t}, e, n) => {
19
+ for (let r = 0; r < t.length; r++) {
20
+ const o = t[r], c = l(o), s = u(o);
21
+ if (e < s || e === s && (c || n || !s)) return [ o, e, r ];
22
+ e -= s, c && e--;
24
23
  }
25
24
  return null;
26
- }, y = (t, e) => {
25
+ }, p = (t, e) => {
27
26
  const n = [];
28
27
  let r;
29
- for (;(r = p(t, e)) && l(r[0]); ) e = r[1], t = r[0], n.push(r[2]);
28
+ for (;(r = d(t, e)) && l(r[0]); ) e = r[1], t = r[0], n.push(r[2]);
30
29
  return [ t, e, n ];
31
- }, h = (t, e, n) => {
32
- const [r, o, c] = y(t, e), s = p(r, o, n);
30
+ }, y = (t, e, n) => {
31
+ const [r, o, c] = p(t, e), s = d(r, o, n);
33
32
  return s ? (c.push(s[2]), [ s[0], s[1], c ]) : null;
34
- }, g = (t, e) => {
35
- let n = 0, r = 0;
36
- for (const o of t.children) {
37
- const t = l(o);
38
- if (t && 0 !== r && n++, o === e) return n;
39
- if (t) {
40
- const t = g(o, e);
33
+ }, h = (t, e) => {
34
+ let n = 0;
35
+ for (const r of t.children) {
36
+ if (r === e) return n;
37
+ if (l(r)) {
38
+ const t = h(r, e);
41
39
  if (null != t) return n + t;
40
+ n++;
42
41
  }
43
- n += d(o), r++;
42
+ n += u(r);
44
43
  }
45
44
  return null;
46
- }, m = (t, e, n = !0) => {
47
- const r = t.children, o = p(t, e);
45
+ }, g = (t, e, n = !0) => {
46
+ const r = t.children, o = d(t, e);
48
47
  if (!o) {
49
48
  const e = r[r.length - 1];
50
49
  return [ t, {
@@ -57,7 +56,7 @@ var {min: t, max: e} = Math, {keys: n, is: r} = Object, o = t => "string" == typ
57
56
  }
58
57
  const [c, s, a] = o, f = r.slice(0, a), u = r.slice(a + 1);
59
58
  if (l(c)) {
60
- const [t, e] = m(c, s, n);
59
+ const [t, e] = g(c, s, n);
61
60
  f.push(t), u.unshift(e);
62
61
  } else if (i(c)) {
63
62
  const t = c.text.slice(0, s), e = c.text.slice(s);
@@ -76,91 +75,99 @@ var {min: t, max: e} = Math, {keys: n, is: r} = Object, o = t => "string" == typ
76
75
  ...t,
77
76
  children: u
78
77
  } ];
79
- }, k = (t, [e, n]) => {
80
- let r = 0;
81
- for (const o of e) r += u(t, 0, o), 0 !== o && r++, t = t.children[o];
82
- return r + n;
83
- }, x = (t, e) => {
84
- const [, n, r] = y(t, e);
78
+ }, m = (t, [e, n]) => {
79
+ for (const r of e) {
80
+ for (let e = 0; e < r; e++) n += u(t.children[e]) + 1;
81
+ t = t.children[r];
82
+ }
83
+ return n;
84
+ }, k = (t, e) => {
85
+ const [, n, r] = p(t, e);
85
86
  return [ r, n ];
86
- }, v = (t, [e, n]) => [ k(t, e), k(t, n) ];
87
+ }, x = (t, [e, n]) => [ m(t, e), m(t, n) ];
87
88
 
88
- function* _(n, [r, o]) {
89
+ function* v(n, [r, o]) {
89
90
  if (r > o || !l(n)) return;
90
- const c = p(n, r) || p(n, r, !0);
91
+ const c = d(n, r) || d(n, r, !0);
91
92
  if (c) {
92
93
  let s = r - c[1], i = c[2];
93
94
  const a = n.children, f = a.length;
94
95
  for (;s <= o && i < f; ) {
95
- const n = a[i], c = d(n);
96
- yield [ n, s, i, [ e(r, s) - s, t(o, s + c) - s ] ], i++, s += c, l(n) && s++;
96
+ const n = a[i], c = u(n);
97
+ yield [ n, s, i, [ e(r - s, 0), t(o - s, c) ] ], i++, s += c, l(n) && s++;
97
98
  }
98
99
  }
99
100
  }
100
101
 
101
- function* b(t, e) {
102
- if (!l(t) || a(t.children)) for (const [n, r, , o] of _(t, e)) for (const t of b(n, o)) t[1] += r,
102
+ function* _(t, e) {
103
+ if (!l(t) || a(t.children)) for (const [n, r, , o] of v(t, e)) for (const t of _(n, o)) t[1] += r,
103
104
  yield t; else yield [ t, 0, e ];
104
105
  }
105
106
 
106
- function* T(t, e) {
107
- if (l(t)) for (const [n, r, , o] of _(t, e)) for (const t of T(n, o)) t[1] += r,
107
+ function* b(t, e) {
108
+ if (l(t)) for (const [n, r, , o] of v(t, e)) for (const t of b(n, o)) t[1] += r,
108
109
  yield t; else yield [ t, 0, e ];
109
110
  }
110
111
 
111
112
  var w = (e, n = 0, r = 1 / 0, o) => {
112
113
  let c = "", s = n;
113
- for (const [t, l, [a, f]] of T(e, [ n, r ])) {
114
+ for (const [t, l, [a, f]] of b(e, [ n, r ])) {
114
115
  for (let t = l - s; t > 0; t--) c += "\n";
115
- i(t) ? c += t.text.slice(a, f) : o && a < f && (c += o(t)), s = l + d(t);
116
+ i(t) ? c += t.text.slice(a, f) : o && a < f && (c += o(t)), s = l + u(t);
116
117
  }
117
- for (let i = t(r, d(e)) - s; i > 0; i--) c += "\n";
118
+ for (let i = t(r, u(e)) - s; i > 0; i--) c += "\n";
118
119
  return c;
119
- }, E = (t, e, n) => e >= n ? [] : m(m(t, n)[0], e)[1].children, M = ([t, e]) => t > e ? [ e, t ] : [ t, e ], S = ([t, e]) => t === e, A = ([t, e], n) => n ? t < e : t <= e, O = (t, e, n) => t.split("\n").map(t => ({
120
+ }, T = (t, e, n) => e >= n ? [] : g(g(t, n)[0], e)[1].children, E = ([t, e]) => t > e ? [ e, t ] : [ t, e ], M = ([t, e]) => t === e, S = ([t, e], n) => n ? t < e : t <= e, A = (t, e, n) => t.split("\n").map(t => ({
120
121
  ...n,
121
122
  children: [ {
122
123
  ...e,
123
124
  text: t
124
125
  } ]
125
- })), R = "delete", D = "insert_text", B = "insert_node", I = "format", L = ({type: t}) => t !== D && t !== R, P = (t, e) => {
126
+ })), O = "delete", R = "insert_text", L = "insert_node", B = "format", D = ({type: t}) => t !== R && t !== O, I = (t, e) => {
126
127
  const o = n(t);
127
128
  return o.length === n(e).length && o.every(n => n in e && ("text" === n || r(t[n], e[n])));
128
- }, H = t => {
129
+ }, P = t => {
129
130
  const e = [];
130
131
  let n;
131
- for (let r of t) i(r) && !r.text || (n && i(n) && i(r) && P(n, r) && (r = {
132
- ...n,
133
- text: n.text + r.text
134
- }, e.pop()), e.push(n = r));
132
+ for (let r of t) {
133
+ if (i(r)) {
134
+ if (!r.text) continue;
135
+ n && i(n) && I(n, r) && (r = {
136
+ ...n,
137
+ text: n.text + r.text
138
+ }, e.pop());
139
+ }
140
+ e.push(n = r);
141
+ }
135
142
  return e.length ? e : t.slice(-1);
136
- }, N = (t, e) => {
143
+ }, H = (t, e) => {
137
144
  const n = t.length - 1, r = t.concat(e);
138
145
  if (n >= 0 && e.length) {
139
146
  const e = l(r[n]);
140
147
  if (e === l(r[n + 1])) {
141
- if (!e) return t.slice(0, n).concat(H(r.slice(n)));
142
- r.splice(n, 2, W(r.slice(n, n + 2)));
148
+ if (!e) return t.slice(0, n).concat(P(r.slice(n)));
149
+ r.splice(n, 2, N(r.slice(n, n + 2)));
143
150
  }
144
151
  }
145
152
  return r.length || r.push({
146
153
  text: ""
147
154
  }), r;
148
- }, W = t => ({
155
+ }, N = t => ({
149
156
  ...t[0],
150
- children: t.reduce((t, e) => N(t, e.children), [])
151
- }), C = (t, {range: e, depth: n = -1}, r) => {
152
- const o = S(e), c = (t, e) => n < 0 ? !!(t & 1 << -n - 1) : n === e, s = (t, e, n, a) => {
153
- let f = 0, u = !1, p = 0, y = 0;
157
+ children: t.reduce((t, e) => H(t, e.children), [])
158
+ }), W = (t, {range: e, depth: n = -1}, r) => {
159
+ const o = M(e), c = (t, e) => n < 0 ? !!(t & 1 << -n - 1) : n === e, s = (t, e, n, a) => {
160
+ let f = 0, d = !1, p = 0, y = 0;
154
161
  const h = [];
155
- for (const [m, k, x, v] of _(t, e)) {
162
+ for (const [m, k, x, _] of v(t, e)) {
156
163
  h.length || (p = x);
157
- const t = A(v, d(m)), e = a + k;
164
+ const t = S(_, u(m)), e = a + k;
158
165
  let g = m;
159
166
  if (l(m)) {
160
167
  let t;
161
- [g, t] = s(m, v, n + 1, e), f |= t << 1;
168
+ [g, t] = s(m, _, n + 1, e), f |= t << 1;
162
169
  } else if ((t || o) && (f |= 2), t && c(1, n + 1)) {
163
- const [t, o] = v, c = [ e + t, e + o ];
170
+ const [t, o] = _, c = [ e + t, e + o ];
164
171
  i(m) ? (t > 0 && h.push({
165
172
  ...m,
166
173
  text: m.text.slice(0, t)
@@ -172,77 +179,77 @@ var w = (e, n = 0, r = 1 / 0, o) => {
172
179
  text: m.text.slice(o)
173
180
  })) : g = r(m, n + 1, c);
174
181
  }
175
- g !== m && (u = !0), h.push(g), y = x;
182
+ g !== m && (d = !0), h.push(g), y = x;
176
183
  }
177
184
  let g = t;
178
- if (u) {
185
+ if (d) {
179
186
  const {children: e} = t, n = e.slice(0, p).concat(h, e.slice(y + 1));
180
187
  g = {
181
188
  ...t,
182
- children: H(n)
189
+ children: P(n)
183
190
  };
184
191
  }
185
192
  return c(f, n) && (g = r(g, n, [ a + e[0], a + e[1] ])), [ g, f ];
186
193
  };
187
194
  return s(t, e, 0, 0)[0];
188
- }, F = (t, e, n, r) => {
189
- const o = !r.length, [c, s] = m(t, e, o), i = e < n ? m(t, n, o)[1] : s, l = a(r);
190
- return l !== a(t.children) && (r = l ? W(r).children : [ {
195
+ }, C = (t, e, n, r) => {
196
+ const o = !r.length, [c, s] = g(t, e, o), i = e < n ? g(t, n, o)[1] : s, l = a(r);
197
+ return l !== a(t.children) && (r = l ? N(r).children : [ {
191
198
  children: r
192
199
  } ]), {
193
200
  ...t,
194
- children: N(N(c.children, r), i.children)
201
+ children: H(H(c.children, r), i.children)
195
202
  };
196
- }, U = (t, e) => e >= 0 && e <= d(t), V = (t, e) => e.reduce((t, e) => q(t, e), t), q = (t, e, n) => {
203
+ }, F = (t, e) => e >= 0 && e <= u(t), U = (t, e) => e.reduce((t, e) => q(t, e), t), q = (t, e, n) => {
197
204
  switch (e.type) {
198
- case R:
205
+ case O:
199
206
  {
200
207
  const [n, r] = e.range;
201
208
  if (t >= n) return r >= t ? n : t + n - r;
202
209
  break;
203
210
  }
204
211
 
205
- case D:
206
- case B:
212
+ case R:
213
+ case L:
207
214
  {
208
215
  const {at: r} = e;
209
- if (n ? t > r : t >= r) return t + (e.type === D ? e.text.length : d({
216
+ if (n ? t > r : t >= r) return t + (e.type === R ? e.text.length : u({
210
217
  children: e.fragment
211
218
  }));
212
219
  break;
213
220
  }
214
221
  }
215
222
  return t;
216
- }, z = ([t, e], n) => [ q(t, n), q(e, n) ], G = (t, [e, n]) => U(t, e) && U(t, n), J = (t, e, n) => {
223
+ }, z = ([t, e], n) => [ q(t, n), q(e, n) ], V = (t, [e, n]) => F(t, e) && F(t, n), G = (t, e, n) => {
217
224
  switch (n.type) {
218
- case R:
225
+ case O:
219
226
  {
220
227
  const [r, o] = n.range;
221
- G(t, n.range) && r < o && (t = F(t, r, o, []), e = z(e, n));
228
+ V(t, n.range) && r < o && (t = C(t, r, o, []), e = z(e, n));
222
229
  break;
223
230
  }
224
231
 
225
- case D:
232
+ case R:
226
233
  {
227
234
  const {at: r, text: o} = n;
228
- if (U(t, r) && o) {
229
- const [c, s] = y(t, r), l = p(c, s, !0);
230
- t = F(t, r, r, O(o, l && i(l[0]) ? l[0] : void 0, c)), e = z(e, n);
235
+ if (F(t, r) && o) {
236
+ const [c, s] = p(t, r), l = d(c, s, !0);
237
+ t = C(t, r, r, A(o, l && i(l[0]) ? l[0] : void 0, c)), e = z(e, n);
231
238
  }
232
239
  break;
233
240
  }
234
241
 
235
- case B:
242
+ case L:
236
243
  {
237
244
  const {at: r, fragment: o} = n;
238
- U(t, r) && o.length && (t = F(t, r, r, o), e = z(e, n));
245
+ F(t, r) && o.length && (t = C(t, r, r, o), e = z(e, n));
239
246
  break;
240
247
  }
241
248
 
242
- case I:
249
+ case B:
243
250
  {
244
251
  const {range: e, key: r, value: o, depth: c} = n;
245
- "text" !== r && ("children" !== r || 0 === c) && G(t, e) && e[0] <= e[1] && (t = C(t, n, t => {
252
+ "text" !== r && ("children" !== r || 0 === c) && V(t, e) && e[0] <= e[1] && (t = W(t, n, t => {
246
253
  if (void 0 !== o) return {
247
254
  ...t,
248
255
  [r]: o
@@ -254,41 +261,41 @@ var w = (e, n = 0, r = 1 / 0, o) => {
254
261
  }
255
262
  }
256
263
  return [ t, e ];
257
- }, X = (t, e) => {
264
+ }, J = (t, e) => {
258
265
  switch (e.type) {
259
- case R:
266
+ case O:
260
267
  {
261
268
  const {range: n} = e;
262
269
  return [ {
263
- type: B,
270
+ type: L,
264
271
  at: n[0],
265
- fragment: E(t, ...n)
272
+ fragment: T(t, ...n)
266
273
  } ];
267
274
  }
268
275
 
269
- case D:
270
- case B:
276
+ case R:
277
+ case L:
271
278
  {
272
279
  const {at: n} = e, r = [ {
273
- type: R,
280
+ type: O,
274
281
  range: [ n, q(n, e) ]
275
- } ], [o] = y(t, n);
276
- return d(o) || r.push({
277
- type: B,
282
+ } ], [o] = p(t, n);
283
+ return u(o) || r.push({
284
+ type: L,
278
285
  at: n,
279
286
  fragment: o.children
280
287
  }), r;
281
288
  }
282
289
 
283
- case I:
290
+ case B:
284
291
  {
285
292
  const {key: n} = e, o = [];
286
293
  let c;
287
- return C(t, e, (t, e, s) => {
294
+ return W(t, e, (t, e, s) => {
288
295
  const i = t[n];
289
296
  return c && c.depth === e && r(c.value, i) && s[0] - c.range[1] <= 1 && (s = [ c.range[0], s[1] ],
290
297
  o.pop()), c = {
291
- type: I,
298
+ type: B,
292
299
  range: s,
293
300
  key: n,
294
301
  value: i,
@@ -302,29 +309,29 @@ var w = (e, n = 0, r = 1 / 0, o) => {
302
309
  }
303
310
  };
304
311
 
305
- function* Y(t, e = M(t.selection)) {
306
- if (S(e)) {
307
- const n = h(t.doc, e[0])?.[0];
312
+ function* X(t, e = E(t.selection)) {
313
+ if (M(e)) {
314
+ const n = y(t.doc, e[0])?.[0];
308
315
  n && (yield n);
309
- } else for (const [n, , r] of T(t.doc, e)) A(r, d(n)) && (yield n);
316
+ } else for (const [n, , r] of b(t.doc, e)) S(r, u(n)) && (yield n);
310
317
  }
311
318
 
312
- function* Z(t, e = M(t.selection)) {
319
+ function* Y(t, e = E(t.selection)) {
313
320
  const n = t.doc;
314
- if (S(e)) {
315
- const [t, r] = y(n, e[0]);
321
+ if (M(e)) {
322
+ const [t, r] = p(n, e[0]);
316
323
  yield [ t, e[0] - r, [ r, r ] ];
317
- } else for (const r of b(n, e)) A(r[2], d(r[0])) && (yield r);
324
+ } else for (const r of _(n, e)) S(r[2], u(r[0])) && (yield r);
318
325
  }
319
326
 
320
- function j(t, e = M(t.selection)) {
327
+ function Z(t, e = E(t.selection)) {
321
328
  t.apply({
322
329
  type: "delete",
323
330
  range: e
324
331
  });
325
332
  }
326
333
 
327
- function K(t, e, n = t.selection[0]) {
334
+ function j(t, e, n = t.selection[0]) {
328
335
  t.apply({
329
336
  type: "insert_text",
330
337
  at: n,
@@ -332,7 +339,7 @@ function K(t, e, n = t.selection[0]) {
332
339
  });
333
340
  }
334
341
 
335
- function Q(t, e, n = t.selection[0]) {
342
+ function K(t, e, n = t.selection[0]) {
336
343
  t.apply({
337
344
  type: "insert_node",
338
345
  at: n,
@@ -342,7 +349,7 @@ function Q(t, e, n = t.selection[0]) {
342
349
  });
343
350
  }
344
351
 
345
- function $(t, e, n = M(t.selection)) {
352
+ function Q(t, e, n = E(t.selection)) {
346
353
  t.apply([ {
347
354
  type: "delete",
348
355
  range: n
@@ -353,7 +360,7 @@ function $(t, e, n = M(t.selection)) {
353
360
  } ]);
354
361
  }
355
362
 
356
- function tt(t, e) {
363
+ function $(t, e) {
357
364
  t.apply({
358
365
  type: "format",
359
366
  range: [ 0, 0 ],
@@ -363,16 +370,16 @@ function tt(t, e) {
363
370
  });
364
371
  }
365
372
 
366
- function* et(t, [e, n]) {
373
+ function* tt(t, [e, n]) {
367
374
  if (e >= n) return void (yield [ e, n ]);
368
375
  let r = e;
369
- for (const [o, c, s] of T(t.doc, [ e, n ])) !i(o) && A(s, d(o)) && (r < c && (yield [ r, c ]),
376
+ for (const [o, c, s] of b(t.doc, [ e, n ])) !i(o) && S(s, u(o)) && (r < c && (yield [ r, c ]),
370
377
  r = c + 1);
371
378
  r < n && (yield [ r, n ]);
372
379
  }
373
380
 
374
- function nt(t, e, n, r = M(t.selection)) {
375
- for (const o of et(t, r)) t.apply({
381
+ function et(t, e, n, r = E(t.selection)) {
382
+ for (const o of tt(t, r)) t.apply({
376
383
  type: "format",
377
384
  range: o,
378
385
  key: e,
@@ -380,13 +387,13 @@ function nt(t, e, n, r = M(t.selection)) {
380
387
  });
381
388
  }
382
389
 
383
- function rt(t, e, n = M(t.selection)) {
390
+ function nt(t, e, n = E(t.selection)) {
384
391
  let r = !1, o = !1;
385
- for (const c of t.exec(Y, n)) if (i(c) && (o = !0, !c[e])) {
392
+ for (const c of t.exec(X, n)) if (i(c) && (o = !0, !c[e])) {
386
393
  r = !0;
387
394
  break;
388
395
  }
389
- if (o) for (const c of et(t, n)) t.apply({
396
+ if (o) for (const c of tt(t, n)) t.apply({
390
397
  type: "format",
391
398
  range: c,
392
399
  key: e,
@@ -394,7 +401,7 @@ function rt(t, e, n = M(t.selection)) {
394
401
  });
395
402
  }
396
403
 
397
- function ot(t, e, n, r = M(t.selection)) {
404
+ function rt(t, e, n, r = E(t.selection)) {
398
405
  t.apply({
399
406
  type: "format",
400
407
  range: r,
@@ -404,9 +411,9 @@ function ot(t, e, n, r = M(t.selection)) {
404
411
  });
405
412
  }
406
413
 
407
- function ct(t, e, n, r, o = M(t.selection)) {
414
+ function ot(t, e, n, r, o = E(t.selection)) {
408
415
  let c = !1;
409
- for (const [s] of t.exec(Z, o)) if (s[e] !== n) {
416
+ for (const [s] of t.exec(Y, o)) if (s[e] !== n) {
410
417
  c = !0;
411
418
  break;
412
419
  }
@@ -419,8 +426,8 @@ function ct(t, e, n, r, o = M(t.selection)) {
419
426
  });
420
427
  }
421
428
 
422
- function st(t, e, n, r = t.selection[0]) {
423
- const o = h(t.doc, r, !0);
429
+ function ct(t, e, n, r = t.selection[0]) {
430
+ const o = y(t.doc, r, !0);
424
431
  if (o && !i(o[0])) {
425
432
  const c = r - o[1];
426
433
  t.apply({
@@ -432,23 +439,23 @@ function st(t, e, n, r = t.selection[0]) {
432
439
  }
433
440
  }
434
441
 
435
- var it = t => 1 === t.nodeType, lt = t => 8 === t.nodeType, at = /* @__PURE__ */ 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 ] ]), ft = /* @__PURE__ */ new Set([ "DIV", "H1", "H2", "H3", "H4", "H5", "H6", "P", "PRE", "LI", "DT", "DD", "TH", "TD" ]), ut = t => ft.has(t.tagName), dt = (t, e) => t.compareDocumentPosition(e), pt = t => t.ownerDocument, yt = t => pt(t).getSelection(), ht = (t, e) => {
442
+ var st = t => 1 === t.nodeType, it = t => 8 === t.nodeType, lt = /* @__PURE__ */ 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 ] ]), at = /* @__PURE__ */ new Set([ "DIV", "H1", "H2", "H3", "H4", "H5", "H6", "P", "PRE", "LI", "DT", "DD", "TH", "TD" ]), ft = t => at.has(t.tagName), ut = (t, e) => t.compareDocumentPosition(e), dt = t => t.ownerDocument, pt = t => dt(t).getSelection(), yt = (t, e) => {
436
443
  if (t.rangeCount) {
437
444
  const n = t.getRangeAt(0);
438
445
  if (e.contains(n.commonAncestorContainer)) return n;
439
446
  }
440
- }, gt = (t, e, n, r) => {
441
- const [o, c] = ((t, [e, n]) => [ x(t, e), x(t, n) ])(n, r), s = pt(t), i = S(r), l = r[0] - r[1] > 0, a = l ? o : c, f = kt(t, e, l ? c : o), u = i ? f : kt(t, e, a), d = s.createRange(), [p, y] = f, [h, g] = u;
442
- return it(p) && t !== p ? y < 1 ? d.setStartBefore(p) : d.setStartAfter(p) : d.setStart(p, y),
443
- it(h) && t !== h ? g < 1 ? d.setEndBefore(h) : d.setEndAfter(h) : d.setEnd(h, g),
447
+ }, ht = (t, e, n, r) => {
448
+ const [o, c] = ((t, [e, n]) => [ k(t, e), k(t, n) ])(n, r), s = dt(t), i = M(r), l = r[0] - r[1] > 0, a = l ? o : c, f = mt(t, e, l ? c : o), u = i ? f : mt(t, e, a), d = s.createRange(), [p, y] = f, [h, g] = u;
449
+ return st(p) && t !== p ? y < 1 ? d.setStartBefore(p) : d.setStartAfter(p) : d.setStart(p, y),
450
+ st(h) && t !== h ? g < 1 ? d.setEndBefore(h) : d.setEndAfter(h) : d.setEnd(h, g),
444
451
  d;
445
- }, mt = (t, e, n, r, o) => {
446
- const c = yt(t);
447
- if (o || ht(c, t)) {
448
- const o = gt(t, e, n, r), s = r[0] - r[1] > 0;
452
+ }, gt = (t, e, n, r, o) => {
453
+ const c = pt(t);
454
+ if (o || yt(c, t)) {
455
+ const o = ht(t, e, n, r), s = r[0] - r[1] > 0;
449
456
  c.removeAllRanges(), c.addRange(o), s && (c.collapseToEnd(), c.extend(o.startContainer, o.startOffset));
450
457
  }
451
- }, kt = (t, e, [n, r]) => e(({t: e, o, i: c, l: s}) => {
458
+ }, mt = (t, e, [n, r]) => e(({t: e, o, i: c, l: s}) => {
452
459
  let i, l = 0;
453
460
  for (;i = e(); ) if (4 === i) {
454
461
  if (l < n.length) for (let t = n[l++]; t > 0; t--) o();
@@ -458,10 +465,10 @@ var it = t => 1 === t.nodeType, lt = t => 8 === t.nodeType, at = /* @__PURE__ */
458
465
  r -= t;
459
466
  }
460
467
  return [ t, 0 ];
461
- }, t), xt = (e, n, r, o) => {
468
+ }, t), kt = (e, n, r, o) => {
462
469
  let c = !0;
463
470
  if (e === r && !r.hasChildNodes()) return [ [], 0 ];
464
- if (it(r) && r.hasChildNodes()) {
471
+ if (st(r) && r.hasChildNodes()) {
465
472
  const e = t(o, r.childNodes.length - 1);
466
473
  r = r.childNodes[e], c = e === o, o = 0;
467
474
  }
@@ -478,7 +485,7 @@ var it = t => 1 === t.nodeType, lt = t => 8 === t.nodeType, at = /* @__PURE__ */
478
485
  });
479
486
  let p = 0;
480
487
  for (;t(); ) {
481
- const t = dt(r, a());
488
+ const t = ut(r, a());
482
489
  if (0 === t || 16 & t) {
483
490
  if (c) break;
484
491
  } else if (4 & t) break;
@@ -486,10 +493,10 @@ var it = t => 1 === t.nodeType, lt = t => 8 === t.nodeType, at = /* @__PURE__ */
486
493
  }
487
494
  return [ d, p + o ];
488
495
  }, e);
489
- }, vt = (t, e, {startOffset: n, startContainer: r, endOffset: o, endContainer: c}) => {
490
- const s = xt(t, e, r, n);
491
- return [ s, r === c && n === o ? s : xt(t, e, c, o) ];
492
- }, _t = "undefined" != typeof navigator && /Mac|iP(hone|od|ad)/.test(navigator.platform), bt = (t, e) => {
496
+ }, xt = (t, e, {startOffset: n, startContainer: r, endOffset: o, endContainer: c}) => {
497
+ const s = kt(t, e, r, n);
498
+ return [ s, r === c && n === o ? s : kt(t, e, c, o) ];
499
+ }, vt = "undefined" != typeof navigator && /Mac|iP(hone|od|ad)/.test(navigator.platform), _t = (t, e) => {
493
500
  const n = t.endsWith("+"), r = (n ? t.slice(0, -2) : t).split("+"), o = n ? "+" : r.pop(), c = "Space" === o ? " " : o.toLowerCase();
494
501
  let s = !1, i = !1, l = !1, a = !1;
495
502
  return r.forEach(t => {
@@ -503,7 +510,7 @@ var it = t => 1 === t.nodeType, lt = t => 8 === t.nodeType, at = /* @__PURE__ */
503
510
  break;
504
511
 
505
512
  case "Mod":
506
- _t ? l = !0 : i = !0;
513
+ vt ? l = !0 : i = !0;
507
514
  break;
508
515
 
509
516
  case "Alt":
@@ -518,7 +525,7 @@ var it = t => 1 === t.nodeType, lt = t => 8 === t.nodeType, at = /* @__PURE__ */
518
525
  };
519
526
  };
520
527
 
521
- function Tt(t) {
528
+ function bt(t) {
522
529
  let e = 0, n = /* @__PURE__ */ new WeakMap;
523
530
  const r = Date.now, o = [], c = [], s = ([t, e], [, n]) => [ t, n.concat(e) ], i = () => {
524
531
  const e = n.get(t.doc);
@@ -545,11 +552,11 @@ function Tt(t) {
545
552
  t.hook("apply", (e, r) => {
546
553
  const o = t.doc, c = t.selection, i = r(e), l = t.doc;
547
554
  if (i && o !== l) {
548
- const t = [ c, X(o, i) ], e = n.get(o);
555
+ const t = [ c, J(o, i) ], e = n.get(o);
549
556
  n.set(l, e ? s(e, t) : t);
550
557
  }
551
- }), t.on("change", l), t.hook("keyboard", bt("Mod+Z", f)), t.hook("keyboard", bt("Shift+Mod+Z", u)),
552
- t.set(Tt, {
558
+ }), t.on("change", l), t.hook("keyboard", _t("Mod+Z", f)), t.hook("keyboard", _t("Shift+Mod+Z", u)),
559
+ t.set(bt, {
553
560
  undo: f,
554
561
  redo: u,
555
562
  stack: t => (l(), t ? c : o)
@@ -557,29 +564,29 @@ function Tt(t) {
557
564
  }
558
565
 
559
566
  function wt(t) {
560
- t.get(Tt).undo();
567
+ t.get(bt).undo();
568
+ }
569
+
570
+ function Tt(t) {
571
+ t.get(bt).redo();
561
572
  }
562
573
 
563
574
  function Et(t) {
564
- t.get(Tt).redo();
575
+ return !!t.get(bt).stack().length;
565
576
  }
566
577
 
567
578
  function Mt(t) {
568
- return !!t.get(Tt).stack().length;
579
+ return !!t.get(bt).stack(!0).length;
569
580
  }
570
581
 
571
582
  function St(t) {
572
- return !!t.get(Tt).stack(!0).length;
573
- }
574
-
575
- function At(t) {
576
- const {stack: e} = t.get(Tt);
583
+ const {stack: e} = t.get(bt);
577
584
  e().length = 0, e(!0).length = 0;
578
585
  }
579
586
 
580
- var Ot = [], Rt = () => {}, Dt = t => {
587
+ var At, Ot = [], Rt = () => {}, Lt = t => {
581
588
  throw Error(t);
582
- }, Bt = ({doc: t, readonly: e = !1, schema: n, isBlock: r = ut, onWarn: i = console.warn, onError: l = Dt}) => {
589
+ }, Bt = ({doc: t, readonly: e = !1, schema: n, isBlock: r = ft, onWarn: i = console.warn, onError: l = Lt}) => {
583
590
  let a = [ 0, 0 ];
584
591
  const f = t => {
585
592
  if (!n) return i("An unsafe operation was detected. We recommend using schema option."),
@@ -604,7 +611,7 @@ var Ot = [], Rt = () => {}, Dt = t => {
604
611
  }), e.forEach(t => {
605
612
  h.add(t);
606
613
  }));
607
- }, m = n => {
614
+ }, k = n => {
608
615
  if (!e) {
609
616
  const e = p("apply"), r = e.length, o = t, c = a;
610
617
  let s = !1;
@@ -619,8 +626,8 @@ var Ot = [], Rt = () => {}, Dt = t => {
619
626
  } else if (n === r) {
620
627
  n++;
621
628
  try {
622
- const [e, n] = J(t, a, c);
623
- t = e, x(n), s = c, L(c) && (o = !0);
629
+ const [e, n] = G(t, a, c);
630
+ t = e, v(n), s = c, D(c) && (o = !0);
624
631
  } catch (l) {
625
632
  i("rollback operation: " + l);
626
633
  }
@@ -635,8 +642,8 @@ var Ot = [], Rt = () => {}, Dt = t => {
635
642
  t !== o && g("change");
636
643
  }
637
644
  return _;
638
- }, x = e => {
639
- !G(t, e) || a[0] === e[0] && a[1] === e[1] || (a = e, g("selectionchange"));
645
+ }, v = e => {
646
+ !V(t, e) || a[0] === e[0] && a[1] === e[1] || (a = e, g("selectionchange"));
640
647
  }, _ = {
641
648
  get doc() {
642
649
  return t;
@@ -645,7 +652,7 @@ var Ot = [], Rt = () => {}, Dt = t => {
645
652
  return a;
646
653
  },
647
654
  set selection(t) {
648
- x(t);
655
+ v(t);
649
656
  },
650
657
  get readonly() {
651
658
  return e;
@@ -653,7 +660,7 @@ var Ot = [], Rt = () => {}, Dt = t => {
653
660
  set readonly(t) {
654
661
  e = t, g("readonly");
655
662
  },
656
- apply: m,
663
+ apply: k,
657
664
  on: (t, e) => {
658
665
  let n = y.get(t);
659
666
  return n || y.set(t, n = /* @__PURE__ */ new Set), n.add(e), () => {
@@ -678,18 +685,18 @@ var Ot = [], Rt = () => {}, Dt = t => {
678
685
  Rt;
679
686
  const {contentEditable: s, role: l, ariaMultiLine: f, ariaReadOnly: u} = n, d = n.style.whiteSpace;
680
687
  n.role = "textbox", n.style.whiteSpace = "pre-wrap", n.ariaMultiLine = "true";
681
- let y = !1, h = null, g = !1, b = !1, T = !1, w = a, E = null;
682
- const A = pt(n), O = ((t, e) => {
688
+ let y = !1, h = null, g = !1, b = !1, w = !1, T = a, S = null;
689
+ const A = dt(n), O = ((t, e) => {
683
690
  let n = null, r = null, o = null;
684
691
  const c = () => {
685
692
  if (null != o) return o;
686
693
  if (r) if ((t => 3 === t.nodeType)(r)) {
687
694
  const t = r.data;
688
695
  if (t) return o = "\n" === t ? i() ? 3 : 5 : 1;
689
- } else if (it(r)) {
696
+ } else if (st(r)) {
690
697
  if ("false" === r.contentEditable) return o = 2;
691
698
  {
692
- const t = at.get(r.tagName);
699
+ const t = lt.get(r.tagName);
693
700
  if (null != t) return o = 1 === t ? i() ? 3 : 5 : 3 === t ? 2 : 6;
694
701
  if (e(r)) return o = 4;
695
702
  }
@@ -757,18 +764,18 @@ var Ot = [], Rt = () => {}, Dt = t => {
757
764
  n.contentEditable = e ? "false" : "true", n.ariaReadOnly = e ? "true" : null;
758
765
  };
759
766
  R();
760
- const D = () => {
761
- b || (mt(n, O, t, a, !0), w = a, n.focus({
767
+ const L = () => {
768
+ b || (gt(n, O, t, a, !0), T = a, n.focus({
762
769
  preventScroll: !0
763
770
  }));
764
771
  }, B = () => {
765
- E = null, a[0] === w[0] && a[1] === w[1] || (mt(n, O, t, a), w = a);
766
- }, I = () => {
767
- null != E && clearTimeout(E);
768
- }, L = _.on("change", () => {
769
- b || requestAnimationFrame(D);
772
+ S = null, a[0] === T[0] && a[1] === T[1] || (gt(n, O, t, a), T = a);
773
+ }, D = () => {
774
+ null != S && clearTimeout(S);
775
+ }, I = _.on("change", () => {
776
+ b || requestAnimationFrame(L);
770
777
  }), P = _.on("selectionchange", () => {
771
- a[0] === w[0] && a[1] === w[1] || (I(), E = setTimeout(B, 50));
778
+ a[0] === T[0] && a[1] === T[1] || (D(), S = setTimeout(B, 50));
772
779
  }), H = _.on("readonly", R), N = t => {
773
780
  for (const e of p("paste")) {
774
781
  const n = e(t);
@@ -815,23 +822,23 @@ var Ot = [], Rt = () => {}, Dt = t => {
815
822
  }
816
823
  };
817
824
  })(n, () => {
818
- I(), mt(n, O, t, a);
825
+ D(), gt(n, O, t, a);
819
826
  }), C = () => {
820
- x(w = v(t, ((t, e) => {
821
- const n = yt(t), r = ht(n, t);
827
+ v(T = x(t, ((t, e) => {
828
+ const n = pt(t), r = yt(n, t);
822
829
  if (!r) return [ [ [ 0 ], 0 ], [ [ 0 ], 0 ] ];
823
- const o = vt(t, e, r), c = dt(n.anchorNode, n.focusNode);
830
+ const o = xt(t, e, r), c = ut(n.anchorNode, n.focusNode);
824
831
  return (0 === c ? n.anchorOffset > n.focusOffset : 2 & c) ? [ o[1], o[0] ] : o;
825
832
  })(n, O)));
826
833
  }, F = () => {
827
834
  const e = W._();
828
- W.v(!1), e.length && (W.k(e), A.removeEventListener("selectionchange", Z), mt(n, O, t, a, !0),
829
- A.addEventListener("selectionchange", Z)), h && (x(h[1]), m(h[0]), h = null), g = !1;
830
- }, U = t => {
835
+ W.v(!1), e.length && (W.k(e), A.removeEventListener("selectionchange", Z), gt(n, O, t, a, !0),
836
+ A.addEventListener("selectionchange", Z)), h && (v(h[1]), k(h[0]), h = null), g = !1;
837
+ }, q = t => {
831
838
  if (!g) for (const e of p("keyboard")) if (e(t)) return t.preventDefault(), void W.v(!1);
832
- }, q = () => {
839
+ }, z = () => {
833
840
  g || F();
834
- }, z = e => {
841
+ }, V = e => {
835
842
  e.preventDefault();
836
843
  const r = e.inputType;
837
844
  if (r.startsWith("format")) return;
@@ -845,8 +852,8 @@ var Ot = [], Rt = () => {}, Dt = t => {
845
852
  t && (c = t.getData("text/plain"));
846
853
  }
847
854
  h || (h = [ [], a ]);
848
- const s = h[0], i = v(t, vt(n, O, o));
849
- S(i) || s.push({
855
+ const s = h[0], i = x(t, xt(n, O, o));
856
+ M(i) || s.push({
850
857
  type: "delete",
851
858
  range: i
852
859
  }), c && s.push({
@@ -865,21 +872,21 @@ var Ot = [], Rt = () => {}, Dt = t => {
865
872
  }, Y = () => {
866
873
  b = !1;
867
874
  }, Z = () => {
868
- !b || g || T || C();
875
+ !b || g || w || C();
869
876
  }, j = t => {
870
- if (C(), !S(a)) for (const e of p("copy")) e(t);
877
+ if (C(), !M(a)) for (const e of p("copy")) e(t);
871
878
  }, K = t => {
872
879
  t.preventDefault(), j(t.clipboardData);
873
880
  }, Q = t => {
874
- t.preventDefault(), e || (j(t.clipboardData), m({
881
+ t.preventDefault(), e || (j(t.clipboardData), k({
875
882
  type: "delete",
876
- range: M(a)
883
+ range: E(a)
877
884
  }));
878
885
  }, $ = t => {
879
886
  t.preventDefault();
880
887
  const e = N(t.clipboardData);
881
888
  if (e) {
882
- const t = M(a), n = t[0], r = [ {
889
+ const t = E(a), n = t[0], r = [ {
883
890
  type: "delete",
884
891
  range: t
885
892
  } ];
@@ -891,30 +898,30 @@ var Ot = [], Rt = () => {}, Dt = t => {
891
898
  type: "insert_node",
892
899
  at: n,
893
900
  fragment: e
894
- }), m(r);
901
+ }), k(r);
895
902
  }
896
903
  }, tt = e => {
897
904
  e.preventDefault();
898
905
  const r = e.dataTransfer, c = ((t, e, {clientX: n, clientY: r}) => {
899
- const o = pt(t);
906
+ const o = dt(t);
900
907
  if (o.caretPositionFromPoint) {
901
908
  const c = o.caretPositionFromPoint(n, r);
902
- if (c) return xt(t, e, c.offsetNode, c.offset);
909
+ if (c) return kt(t, e, c.offsetNode, c.offset);
903
910
  } else if (o.caretRangeFromPoint) {
904
911
  const c = o.caretRangeFromPoint(n, r);
905
- if (c) return xt(t, e, c.startContainer, c.startOffset);
912
+ if (c) return kt(t, e, c.startContainer, c.startOffset);
906
913
  }
907
914
  })(n, O, e);
908
915
  if (r && c) {
909
916
  let e;
910
917
  const n = [];
911
- T && n.push({
918
+ w && n.push({
912
919
  type: "delete",
913
- range: M(a)
920
+ range: E(a)
914
921
  });
915
922
  const s = N(r);
916
923
  if (s) {
917
- const r = k(t, c), i = V(r, n);
924
+ const r = m(t, c), i = U(r, n);
918
925
  n.push(o(s) ? {
919
926
  type: "insert_text",
920
927
  at: i,
@@ -923,18 +930,18 @@ var Ot = [], Rt = () => {}, Dt = t => {
923
930
  type: "insert_node",
924
931
  at: i,
925
932
  fragment: s
926
- }), e = [ i, V(r, n) ];
933
+ }), e = [ i, U(r, n) ];
927
934
  }
928
- m(n), e && x(e);
935
+ k(n), e && v(e);
929
936
  }
930
- T = !1;
937
+ w = !1;
931
938
  }, et = t => {
932
- T = !0, j(t.dataTransfer);
939
+ w = !0, j(t.dataTransfer);
933
940
  }, nt = () => {
934
- T = !1;
941
+ w = !1;
935
942
  };
936
- A.addEventListener("selectionchange", Z), n.addEventListener("keydown", U), n.addEventListener("input", q),
937
- n.addEventListener("beforeinput", z), n.addEventListener("compositionstart", G),
943
+ A.addEventListener("selectionchange", Z), n.addEventListener("keydown", q), n.addEventListener("input", z),
944
+ n.addEventListener("beforeinput", V), n.addEventListener("compositionstart", G),
938
945
  n.addEventListener("compositionend", J), n.addEventListener("focus", X), n.addEventListener("blur", Y),
939
946
  n.addEventListener("copy", K), n.addEventListener("cut", Q), n.addEventListener("paste", $),
940
947
  n.addEventListener("drop", tt), n.addEventListener("dragstart", et), n.addEventListener("dragend", nt);
@@ -943,9 +950,9 @@ var Ot = [], Rt = () => {}, Dt = t => {
943
950
  const e = t(n, O);
944
951
  e && rt.push(e);
945
952
  }), () => {
946
- y || (y = !0, L(), P(), H(), n.contentEditable = s, n.role = l, n.ariaMultiLine = f,
953
+ y || (y = !0, I(), P(), H(), n.contentEditable = s, n.role = l, n.ariaMultiLine = f,
947
954
  n.ariaReadOnly = u, n.style.whiteSpace = d, W.T(), A.removeEventListener("selectionchange", Z),
948
- n.removeEventListener("keydown", U), n.removeEventListener("input", q), n.removeEventListener("beforeinput", z),
955
+ n.removeEventListener("keydown", q), n.removeEventListener("input", z), n.removeEventListener("beforeinput", V),
949
956
  n.removeEventListener("compositionstart", G), n.removeEventListener("compositionend", J),
950
957
  n.removeEventListener("focus", X), n.removeEventListener("blur", Y), n.removeEventListener("copy", K),
951
958
  n.removeEventListener("cut", Q), n.removeEventListener("paste", $), n.removeEventListener("drop", tt),
@@ -955,77 +962,87 @@ var Ot = [], Rt = () => {}, Dt = t => {
955
962
  };
956
963
  }
957
964
  };
958
- return _.exec(Tt), _;
959
- }, It = (t, e) => {
965
+ return _.exec(bt), _;
966
+ }, Dt = (t, e) => {
960
967
  t.hook("paste", t => {
961
- for (const n of t.items) if ("file" === n.kind) {
962
- const t = e[n.type];
968
+ const n = [];
969
+ for (const r of t.items) if ("file" === r.kind) {
970
+ const t = e[r.type];
963
971
  if (t) {
964
- const e = n.getAsFile();
965
- if (e) return [ {
966
- children: [ t(e) ]
967
- } ];
972
+ const e = r.getAsFile();
973
+ e && n.push(t(e));
968
974
  }
969
975
  }
970
- return null;
976
+ return n.length ? n : null;
971
977
  });
972
978
  };
973
979
 
974
- function Lt(t, e) {
980
+ function It(t, e) {
975
981
  const n = e && e.voidToString;
976
982
  t.hook("copy", e => {
977
- e.setData("text/plain", w(t.doc, ...M(t.selection), n));
983
+ e.setData("text/plain", w(t.doc, ...E(t.selection), n));
978
984
  }), t.hook("paste", t => t.getData("text/plain"));
979
985
  }
980
986
 
981
987
  function Pt(t, e) {
982
- t.hook("mount", (n, r) => {
983
- const o = t.hook("copy", t => {
984
- const e = document.createElement("div");
985
- e.appendChild(ht(yt(n), n).cloneContents()), t.setData("text/html", e.innerHTML);
986
- }), c = t.hook("paste", t => {
987
- const n = t.getData("text/html");
988
- return n ? ((t, e, n) => {
989
- const r = n.text, o = t => {
990
- const e = n[t.tagName.toLowerCase()];
991
- if (e) {
992
- const n = e(t);
993
- if (n) return n;
994
- }
988
+ let n;
989
+ t.hook("mount", (t, e) => (n = [ t, e ], () => {
990
+ n = void 0;
991
+ })), t.hook("copy", t => {
992
+ if (n) {
993
+ const e = n[0], r = document.createElement("div");
994
+ r.appendChild(yt(pt(e), e).cloneContents()), t.setData("text/html", r.innerHTML);
995
+ }
996
+ }), t.hook("paste", t => {
997
+ const r = t.getData("text/html");
998
+ return n && r ? ((t, e, n) => {
999
+ const r = n.text, o = t => {
1000
+ const e = n[t.tagName.toLowerCase()];
1001
+ if (e) {
1002
+ const n = e(t);
1003
+ if (n) return n;
1004
+ }
1005
+ };
1006
+ if (!At) {
1007
+ const t = {
1008
+ createHTML: t => t
995
1009
  };
996
- let c = (new DOMParser).parseFromString(t, "text/html").body, s = !1;
997
- for (const i of [ ...c.childNodes ]) lt(i) ? "StartFragment" === i.data ? (s = !0,
998
- c = new DocumentFragment) : "EndFragment" === i.data && (s = !1) : s && c.appendChild(i);
999
- return e(({t, i: e}) => {
1000
- let n, c = null, s = "", i = !1;
1001
- const l = [], a = () => {
1002
- s && (c || (c = []), c.push(r(s)), s = "");
1003
- }, f = () => {
1004
- a(), !c && i && (c = []), c && l.push({
1005
- children: c
1006
- }), c = null, i = !1;
1007
- };
1008
- for (;n = t(); ) if (4 === n) f(); else if (i = !0, 1 === n) s += e().data; else if (2 === n) {
1009
- a();
1010
- const t = o(e());
1011
- t && c.push(t);
1012
- } else 3 === n && f();
1013
- return f(), l.length || l.push({
1014
- children: []
1015
- }), l;
1016
- }, c);
1017
- })(n, r, e.serializers) : null;
1018
- });
1019
- return () => {
1020
- o(), c();
1021
- };
1010
+ At = t;
1011
+ try {
1012
+ const e = window.trustedTypes;
1013
+ e && (At = e.createPolicy("editate", t));
1014
+ } catch {}
1015
+ }
1016
+ const c = (new DOMParser).parseFromString(At.createHTML(t), "text/html");
1017
+ let s = c.body, i = !1;
1018
+ for (const l of [ ...s.childNodes ]) it(l) ? "StartFragment" === l.data ? (i = !0,
1019
+ s = c.createDocumentFragment()) : "EndFragment" === l.data && (i = !1) : i && s.appendChild(l);
1020
+ return e(({t, i: e}) => {
1021
+ let n, c = null, s = "", i = !1;
1022
+ const l = [], a = () => {
1023
+ s && (c || (c = []), c.push(r(s)), s = "");
1024
+ }, f = () => {
1025
+ a(), !c && i && (c = []), c && l.push({
1026
+ children: c
1027
+ }), c = null, i = !1;
1028
+ };
1029
+ for (;n = t(); ) if (4 === n) f(); else if (i = !0, 1 === n) s += e().data; else if (2 === n) {
1030
+ a();
1031
+ const t = o(e());
1032
+ t && c.push(t);
1033
+ } else 3 === n && f();
1034
+ return f(), l.length || l.push({
1035
+ children: []
1036
+ }), l;
1037
+ }, s);
1038
+ })(r, n[1], e.serializers) : null;
1022
1039
  });
1023
1040
  }
1024
1041
 
1025
1042
  function Ht(t, e) {
1026
1043
  const n = e && e.mime || "application/x-editate-editor";
1027
1044
  t.hook("copy", e => {
1028
- e.setData(n, JSON.stringify(E(t.doc, ...M(t.selection))));
1045
+ e.setData(n, JSON.stringify(T(t.doc, ...E(t.selection))));
1029
1046
  }), t.hook("paste", t => {
1030
1047
  try {
1031
1048
  return JSON.parse(t.getData(n));
@@ -1037,14 +1054,14 @@ function Ht(t, e) {
1037
1054
 
1038
1055
  function Nt(t, e) {
1039
1056
  const n = e.isLocked, r = e => {
1040
- for (const [r] of b(t.doc, e)) if (n(r)) return !0;
1057
+ for (const [r] of _(t.doc, e)) if (n(r)) return !0;
1041
1058
  return !1;
1042
1059
  };
1043
1060
  t.hook("apply", (e, o) => {
1044
1061
  o((e => {
1045
- if ("format" !== e.type) return r("delete" === e.type ? M(e.range) : [ e.at, e.at ]);
1046
- const o = t.doc, c = 0 === e.depth ? [ 0, d(o) ] : M(e.range), s = b(J(o, t.selection, e)[0], c);
1047
- for (const [t] of b(o, c)) {
1062
+ if ("format" !== e.type) return r("delete" === e.type ? E(e.range) : [ e.at, e.at ]);
1063
+ const o = t.doc, c = 0 === e.depth ? [ 0, u(o) ] : E(e.range), s = _(G(o, t.selection, e)[0], c);
1064
+ for (const [t] of _(o, c)) {
1048
1065
  const e = s.next().value?.[0];
1049
1066
  if (e && t !== e && n(t) && n(e)) return !0;
1050
1067
  }
@@ -1055,15 +1072,17 @@ function Nt(t, e) {
1055
1072
  });
1056
1073
  }
1057
1074
 
1058
- function Wt(t, e = M(t.selection)) {
1075
+ function Wt(t, e = E(t.selection)) {
1059
1076
  return t.get(Nt).locked(e);
1060
1077
  }
1061
1078
 
1062
1079
  function Ct(t) {
1063
- t.hook("apply", t => {
1064
- console.log("apply", t);
1080
+ let e = /* @__PURE__ */ new WeakMap;
1081
+ t.hook("apply", (n, r) => {
1082
+ const o = t.doc, c = r(n);
1083
+ c && o !== t.doc && e.set(t.doc, (e.get(o) || []).concat(c));
1065
1084
  }), t.on("change", () => {
1066
- console.log("change", t.doc);
1085
+ console.log("apply", e.get(t.doc)), e = /* @__PURE__ */ new WeakMap, console.log("change", t.doc);
1067
1086
  }), t.on("selectionchange", () => {
1068
1087
  console.log("selectionchange", t.selection);
1069
1088
  });
@@ -1072,29 +1091,48 @@ function Ct(t) {
1072
1091
  function Ft(t, e) {
1073
1092
  n(e).forEach(n => {
1074
1093
  const r = e[n];
1075
- t.hook("keyboard", bt(n, r));
1094
+ t.hook("keyboard", _t(n, r));
1076
1095
  });
1077
1096
  }
1078
1097
 
1079
- var Ut = (t, e) => {
1098
+ function Ut(t) {
1099
+ t.hook("mount", (e, n) => {
1100
+ let r = !1, o = 0, c = 0;
1101
+ const s = () => {
1102
+ r = !e.matches(":focus");
1103
+ }, i = () => {
1104
+ o = e.scrollTop, c = e.scrollLeft;
1105
+ }, l = () => {
1106
+ r || (gt(e, n, t.doc, t.selection, !0), e.scrollTop || e.scrollLeft || (e.scrollTop = o,
1107
+ e.scrollLeft = c)), r = !1;
1108
+ };
1109
+ return e.addEventListener("mousedown", s, !0), e.addEventListener("focus", l, !0),
1110
+ e.addEventListener("scroll", i), () => {
1111
+ e.removeEventListener("mousedown", s, !0), e.removeEventListener("focus", l, !0),
1112
+ e.removeEventListener("scroll", i);
1113
+ };
1114
+ });
1115
+ }
1116
+
1117
+ var qt = (t, e) => {
1080
1118
  const n = parseFloat(t);
1081
1119
  return n ? t.endsWith("%") ? n / 100 * e : n : 0;
1082
- }, Vt = (t, e, n, r) => [ t + Ut(n, e), t + e - Ut(r, e) ], qt = t => "auto" === t || "scroll" === t || "overlay" === t, zt = (t, e, [n, r]) => t < n ? t - n : e > r ? e - r : 0, Gt = (n, r, o, c) => {
1120
+ }, zt = (t, e, n, r) => [ t + qt(n, e), t + e - qt(r, e) ], Vt = t => "auto" === t || "scroll" === t || "overlay" === t, Gt = (t, e, [n, r]) => t < n ? t - n : e > r ? e - r : 0, Jt = (n, r, o, c) => {
1083
1121
  const s = c ? -o : 0;
1084
1122
  return e(s - r, t(n, s + o - r));
1085
- }, Jt = (t, e, n) => {
1123
+ }, Xt = (t, e, n) => {
1086
1124
  (n || e) && t.scrollBy({
1087
1125
  top: n,
1088
1126
  left: e,
1089
1127
  behavior: "auto"
1090
1128
  });
1091
- }, Xt = t => {
1129
+ }, Yt = t => {
1092
1130
  t.hook("mount", (e, n) => {
1093
- const r = pt(e), o = r.defaultView, {body: c, documentElement: s} = r;
1131
+ const r = dt(e), o = r.defaultView, {body: c, documentElement: s} = r;
1094
1132
  let i, l;
1095
1133
  for (let t = e; t && t !== c && t !== s; t = t.parentElement) {
1096
1134
  const e = o.getComputedStyle(t);
1097
- if (qt(e.overflowX) || qt(e.overflowY)) {
1135
+ if (Vt(e.overflowX) || Vt(e.overflowY)) {
1098
1136
  i = t, l = e;
1099
1137
  break;
1100
1138
  }
@@ -1104,10 +1142,10 @@ var Ut = (t, e) => {
1104
1142
  const u = t.on("change", () => {
1105
1143
  null == f && (f = setTimeout(() => {
1106
1144
  f = null;
1107
- const r = gt(e, n, t.doc, t.selection);
1145
+ const r = ht(e, n, t.doc, t.selection);
1108
1146
  let c = r.getBoundingClientRect();
1109
1147
  if (!c.width && !c.height) {
1110
- const t = r.startContainer, e = it(t) ? t : t.parentElement;
1148
+ const t = r.startContainer, e = st(t) ? t : t.parentElement;
1111
1149
  e && (c = e.getBoundingClientRect());
1112
1150
  }
1113
1151
  let u = 0, d = 0;
@@ -1127,24 +1165,24 @@ var Ut = (t, e) => {
1127
1165
  case "sideways-lr":
1128
1166
  h = !1, g = !y;
1129
1167
  }
1130
- d = Gt(zt(c.top, c.bottom, Vt(p.top + s, f, l.scrollPaddingTop, l.scrollPaddingBottom)), e, r - f, g),
1131
- u = Gt(zt(c.left, c.right, Vt(p.left + o, a, l.scrollPaddingLeft, l.scrollPaddingRight)), t, n - a, h);
1168
+ d = Jt(Gt(c.top, c.bottom, zt(p.top + s, f, l.scrollPaddingTop, l.scrollPaddingBottom)), e, r - f, g),
1169
+ u = Jt(Gt(c.left, c.right, zt(p.left + o, a, l.scrollPaddingLeft, l.scrollPaddingRight)), t, n - a, h);
1132
1170
  }
1133
- const {clientWidth: p, clientHeight: y} = s, h = zt(c.top - d, c.bottom - d, Vt(0, y, a.scrollPaddingTop, a.scrollPaddingBottom)), g = zt(c.left - u, c.right - u, Vt(0, p, a.scrollPaddingLeft, a.scrollPaddingRight));
1134
- i && Jt(i, u, d), Jt(o, g, h);
1171
+ const {clientWidth: p, clientHeight: y} = s, h = Gt(c.top - d, c.bottom - d, zt(0, y, a.scrollPaddingTop, a.scrollPaddingBottom)), g = Gt(c.left - u, c.right - u, zt(0, p, a.scrollPaddingLeft, a.scrollPaddingRight));
1172
+ i && Xt(i, u, d), Xt(o, g, h);
1135
1173
  }, 50));
1136
1174
  });
1137
1175
  return () => {
1138
1176
  null != f && clearTimeout(f), u();
1139
1177
  };
1140
1178
  });
1141
- }, Yt = (t, e, n) => {
1179
+ }, Zt = (t, e, n) => {
1142
1180
  let r = e;
1143
- for (let o = e + 1; o < n; o++) d(t[o]) > d(t[r]) && (r = o);
1181
+ for (let o = e + 1; o < n; o++) u(t[o]) > u(t[r]) && (r = o);
1144
1182
  return r;
1145
1183
  };
1146
1184
 
1147
- function Zt(t) {
1185
+ function jt(t) {
1148
1186
  let e = 0, n = t.doc;
1149
1187
  const r = /* @__PURE__ */ new WeakMap, o = (t, e) => {
1150
1188
  if (t === e) return;
@@ -1153,13 +1191,13 @@ function Zt(t) {
1153
1191
  for (;n < c && n < s && t[c - 1] === e[s - 1]; ) c--, s--;
1154
1192
  const i = new Set(e.slice(n, s)), a = c - n, f = s - n;
1155
1193
  for (let u = n; u < c && u < s; u++) {
1156
- const d = t[1 === f ? Yt(t, n, c) : u], p = e[1 === a ? Yt(e, n, s) : u];
1194
+ const d = t[1 === f ? Zt(t, n, c) : u], p = e[1 === a ? Zt(e, n, s) : u];
1157
1195
  if (i.has(d) || r.has(p)) continue;
1158
1196
  const y = r.get(d);
1159
1197
  null != y && (r.delete(d), r.set(p, y)), l(d) && l(p) && o(d.children, p.children);
1160
1198
  }
1161
1199
  };
1162
- t.set(Zt, {
1200
+ t.set(jt, {
1163
1201
  id: c => {
1164
1202
  const s = t.doc;
1165
1203
  if (s !== n) {
@@ -1172,16 +1210,16 @@ function Zt(t) {
1172
1210
  });
1173
1211
  }
1174
1212
 
1175
- function jt(t, e) {
1176
- return t.get(Zt).id(e);
1213
+ function Kt(t, e) {
1214
+ return t.get(jt).id(e);
1177
1215
  }
1178
1216
 
1179
- function Kt(t, e) {
1217
+ function Qt(t, e) {
1180
1218
  t.hook("mount", (n, r) => {
1181
1219
  let o = !0, c = !1;
1182
1220
  const s = t.on("selectionchange", () => {
1183
1221
  c || (c = !0, requestAnimationFrame(() => {
1184
- c = !1, o && e(() => gt(n, r, t.doc, t.selection).getBoundingClientRect());
1222
+ c = !1, o && e(() => ht(n, r, t.doc, t.selection).getBoundingClientRect());
1185
1223
  }));
1186
1224
  });
1187
1225
  return () => {
@@ -1190,7 +1228,7 @@ function Kt(t, e) {
1190
1228
  });
1191
1229
  }
1192
1230
 
1193
- function Qt(t) {
1231
+ function $t(t) {
1194
1232
  t.hook("mount", t => {
1195
1233
  t.ariaMultiLine = null;
1196
1234
  }), t.hook("apply", (t, e) => {
@@ -1201,24 +1239,24 @@ function Qt(t) {
1201
1239
  const e = t.fragment;
1202
1240
  t = {
1203
1241
  ...t,
1204
- fragment: a(e) ? [ W(e) ] : e
1242
+ fragment: a(e) ? [ N(e) ] : e
1205
1243
  };
1206
1244
  }
1207
1245
  e(t);
1208
1246
  });
1209
1247
  }
1210
1248
 
1211
- var $t = ({text: t, singleline: e, onChange: n, ...r}) => {
1249
+ var te = ({text: t, singleline: e, onChange: n, ...r}) => {
1212
1250
  const o = Bt({
1213
1251
  ...r,
1214
1252
  doc: {
1215
- children: O(t)
1253
+ children: A(t)
1216
1254
  }
1217
- }).exec(Lt);
1218
- return e && o.exec(Qt), o.on("change", () => {
1255
+ }).exec(It);
1256
+ return e && o.exec($t), o.on("change", () => {
1219
1257
  n(w(o.doc));
1220
1258
  }), o;
1221
1259
  };
1222
1260
 
1223
- export { Z as BlocksInRange, At as ClearHistory, j as Delete, nt as Format, Q as InsertNode, K as InsertText, Y as LeavesInRange, Wt as LockedInRange, jt as NodeId, Et as Redo, St as Redoable, tt as ReplaceDoc, $ as ReplaceText, ot as SetBlockAttr, st as SetVoidAttr, ct as ToggleBlockAttr, rt as ToggleFormat, wt as Undo, Mt as Undoable, Nt as blockLockPlugin, Bt as createEditor, $t as createPlainEditor, Ct as debugPlugin, It as fileTransferPlugin, p as getChildAt, h as getLeafAt, y as getLeafBlockAt, g as getNodeOffset, d as getNodeSize, Pt as htmlTransferPlugin, Ht as internalTransferPlugin, b as iterLeafBlocks, T as iterLeaves, Ft as keymapPlugin, q as mapPosition, Zt as nodeIdPlugin, Lt as plainTransferPlugin, Xt as scrollToSelectionPlugin, Kt as selectionRectPlugin, Qt as singlelinePlugin, w as sliceText };
1261
+ export { Y as BlocksInRange, St as ClearHistory, Z as Delete, et as Format, K as InsertNode, j as InsertText, X as LeavesInRange, Wt as LockedInRange, Kt as NodeId, Tt as Redo, Mt as Redoable, $ as ReplaceDoc, Q as ReplaceText, rt as SetBlockAttr, ct as SetVoidAttr, ot as ToggleBlockAttr, nt as ToggleFormat, wt as Undo, Et as Undoable, Nt as blockLockPlugin, Bt as createEditor, te as createPlainEditor, Ct as debugPlugin, Dt as fileTransferPlugin, d as getChildAt, y as getLeafAt, p as getLeafBlockAt, h as getNodeOffset, u as getNodeSize, Pt as htmlTransferPlugin, Ht as internalTransferPlugin, _ as iterLeafBlocks, b as iterLeaves, Ft as keymapPlugin, q as mapPosition, jt as nodeIdPlugin, It as plainTransferPlugin, Ut as restoreSelectionPlugin, Yt as scrollToSelectionPlugin, Qt as selectionRectPlugin, $t as singlelinePlugin, w as sliceText };
1224
1262
  //# sourceMappingURL=index.js.map