@p10node/office-engine 0.2.2 → 0.2.3

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.
@@ -46,16 +46,16 @@ function p(e, t) {
46
46
  function ee(e, t) {
47
47
  for (let n of c.get(e)?.localFns ?? []) n(t);
48
48
  }
49
- function te(e, t) {
49
+ function m(e, t) {
50
50
  let n = l(e);
51
51
  return n.localFns.add(t), () => n.localFns.delete(t);
52
52
  }
53
53
  // src/react/edit/rich.ts
54
- var m = (e) => e.t === "text" ? e.text.length : 1, h = (e) => e.reduce((e, t) => e + m(t), 0), g = (e) => e.a.pa === e.f.pa && e.a.o === e.f.o, _ = (e, t) => e.replace(/(\d+)$/, (e) => String(Number(e) + t));
55
- function v(e) {
54
+ var h = (e) => e.t === "text" ? e.text.length : 1, g = (e) => e.reduce((e, t) => e + h(t), 0), _ = (e) => e.a.pa === e.f.pa && e.a.o === e.f.o, v = (e, t) => e.replace(/(\d+)$/, (e) => String(Number(e) + t));
55
+ function y(e) {
56
56
  return e.map((e) => e.t === "text" ? e.text : "").join("");
57
57
  }
58
- function y(e, t) {
58
+ function b(e, t) {
59
59
  if (e === t) return !0;
60
60
  if (!e || !t) return !e && !t;
61
61
  let n = Object.keys(e);
@@ -63,23 +63,23 @@ function y(e, t) {
63
63
  for (let r of n) if (e[r] !== t[r]) return !1;
64
64
  return !0;
65
65
  }
66
- var ne = (e, t) => e.t === "text" && t.t === "text" && e.href === t.href && e.lk === t.lk && y(e.s, t.s) && y(e.d, t.d);
67
- function b(e) {
66
+ var te = (e, t) => e.t === "text" && t.t === "text" && e.href === t.href && e.lk === t.lk && b(e.s, t.s) && b(e.d, t.d);
67
+ function x(e) {
68
68
  let t = [];
69
69
  for (let n of e) {
70
70
  if (n.t === "text" && !n.text) continue;
71
71
  let e = t[t.length - 1];
72
- e && ne(e, n) ? t[t.length - 1] = {
72
+ e && te(e, n) ? t[t.length - 1] = {
73
73
  ...e,
74
74
  text: e.text + n.text
75
75
  } : t.push(n);
76
76
  }
77
77
  return t;
78
78
  }
79
- function x(e, t) {
79
+ function S(e, t) {
80
80
  let n = [], r = [], i = 0;
81
81
  for (let a of e) {
82
- let e = m(a);
82
+ let e = h(a);
83
83
  if (i + e <= t) n.push(a);
84
84
  else if (i >= t) r.push(a);
85
85
  else {
@@ -96,14 +96,14 @@ function x(e, t) {
96
96
  }
97
97
  return [n, r];
98
98
  }
99
- function S(e, t) {
100
- let [n, r] = x(e, t);
99
+ function C(e, t) {
100
+ let [n, r] = S(e, t);
101
101
  for (let e = n.length - 1; e >= 0; e--) if (n[e].t === "text") return n[e];
102
102
  return r.find((e) => e.t === "text");
103
103
  }
104
- function re(e, t, n, r, i) {
104
+ function ne(e, t, n, r, i) {
105
105
  if (!n) return e;
106
- let [a, o] = x(e, t), s = S(e, t), c = {
106
+ let [a, o] = S(e, t), s = C(e, t), c = {
107
107
  t: "text",
108
108
  ...s ?? i ?? {},
109
109
  ...r ?? {},
@@ -115,17 +115,17 @@ function re(e, t, n, r, i) {
115
115
  }), (r?.d || s?.d) && (c.d = {
116
116
  ...s?.d ?? {},
117
117
  ...r?.d ?? {}
118
- }), c.d && !Object.keys(c.d).length && delete c.d, b([
118
+ }), c.d && !Object.keys(c.d).length && delete c.d, x([
119
119
  ...a,
120
120
  c,
121
121
  ...o
122
122
  ]);
123
123
  }
124
- function C(e, t, n) {
125
- return n <= t ? e : b([...x(e, t)[0], ...x(e, n)[1]]);
124
+ function w(e, t, n) {
125
+ return n <= t ? e : x([...S(e, t)[0], ...S(e, n)[1]]);
126
126
  }
127
- function ie(e, t, n, r, i) {
128
- let [a, o] = x(e, t), [s, c] = x(o, n - t), l = s.map((e) => e.t === "text" ? {
127
+ function re(e, t, n, r, i) {
128
+ let [a, o] = S(e, t), [s, c] = S(o, n - t), l = s.map((e) => e.t === "text" ? {
129
129
  ...e,
130
130
  s: {
131
131
  ...e.s ?? {},
@@ -136,13 +136,13 @@ function ie(e, t, n, r, i) {
136
136
  ...i
137
137
  }
138
138
  } : e);
139
- return b([
139
+ return x([
140
140
  ...a,
141
141
  ...l,
142
142
  ...c
143
143
  ]);
144
144
  }
145
- function ae(e, t) {
145
+ function ie(e, t) {
146
146
  if (t <= 0) return 0;
147
147
  let n = Intl.Segmenter;
148
148
  if (n) {
@@ -153,7 +153,7 @@ function ae(e, t) {
153
153
  let r = e.charCodeAt(t - 1);
154
154
  return r >= 56320 && r <= 57343 && t >= 2 ? t - 2 : t - 1;
155
155
  }
156
- function oe(e, t) {
156
+ function ae(e, t) {
157
157
  if (t >= e.length) return e.length;
158
158
  let n = Intl.Segmenter;
159
159
  if (n) for (let r of new n(void 0, { granularity: "grapheme" }).segment(e.slice(t))) return t + r.segment.length;
@@ -161,39 +161,47 @@ function oe(e, t) {
161
161
  return r >= 55296 && r <= 56319 ? t + 2 : t + 1;
162
162
  }
163
163
  // src/react/edit/input.ts
164
- function w(e, t) {
164
+ function T(e, t) {
165
165
  let n = e.cmp(t.a.pa, t.f.pa);
166
166
  return n < 0 || n === 0 && t.a.o <= t.f.o ? [t.a, t.f] : [t.f, t.a];
167
167
  }
168
- var T = (e) => ({
168
+ var E = (e) => ({
169
169
  a: e,
170
170
  f: e
171
- });
172
- function E(e, t) {
173
- let [n, r] = w(e, t);
171
+ }), oe = (e, t) => e.a.pa === t.a.pa && e.a.o === t.a.o && e.f.pa === t.f.pa && e.f.o === t.f.o;
172
+ function D(e, t) {
173
+ let [n, r] = T(e, t);
174
174
  if (n.pa === r.pa) {
175
175
  let t = e.para(n.pa);
176
176
  return t ? {
177
177
  pas: [n.pa],
178
- paras: [e.withRuns(t, C(t.runs, n.o, r.o))],
178
+ paras: [e.withRuns(t, w(t.runs, n.o, r.o))],
179
179
  at: n
180
180
  } : null;
181
181
  }
182
182
  let i = e.span(n.pa, r.pa);
183
- if (!i) return null;
184
- let a = e.para(i[0]), o = e.para(i[i.length - 1]), s = b([...x(a.runs, n.o)[0], ...x(o.runs, r.o)[1]]);
183
+ if (!i) {
184
+ let t = e.deleteAcross?.(n, r), i = t && e.para(t.pa);
185
+ return t && i ? {
186
+ pas: [t.pa],
187
+ paras: [i],
188
+ at: t,
189
+ applied: !0
190
+ } : null;
191
+ }
192
+ let a = e.para(i[0]), o = e.para(i[i.length - 1]), s = x([...S(a.runs, n.o)[0], ...S(o.runs, r.o)[1]]);
185
193
  return {
186
194
  pas: i,
187
195
  paras: [e.join(a, o, s)],
188
196
  at: n
189
197
  };
190
198
  }
191
- function D(e, t, n) {
192
- let r = E(e, t);
193
- r && e.replace(r.pas, r.paras, T(r.at), n);
199
+ function O(e, t, n) {
200
+ let r = D(e, t);
201
+ r && !r.applied && e.replace(r.pas, r.paras, E(r.at), n);
194
202
  }
195
- function O(e, t) {
196
- if (!g(t)) return E(e, t);
203
+ function k(e, t) {
204
+ if (!_(t)) return D(e, t);
197
205
  let n = e.para(t.a.pa);
198
206
  return n ? {
199
207
  pas: [t.a.pa],
@@ -201,53 +209,53 @@ function O(e, t) {
201
209
  at: t.a
202
210
  } : null;
203
211
  }
204
- function k(e, t, n, r = {}, i) {
205
- let a = O(e, t);
212
+ function A(e, t, n, r = {}, i) {
213
+ let a = k(e, t);
206
214
  if (!a) return;
207
- let o = a.paras[0], s = a.at.o, [c, l] = x(o.runs, s), u = S(o.runs, s) ?? e.defaultRun?.(o), d = (e) => e.map((e) => e.t === "text" && !e.s && u ? {
215
+ let o = a.paras[0], s = a.at.o, [c, l] = S(o.runs, s), u = C(o.runs, s) ?? e.defaultRun?.(o), d = (e) => e.map((e) => e.t === "text" && !e.s && u ? {
208
216
  ...u,
209
217
  ...e,
210
218
  s: u.s,
211
219
  src: u.src
212
220
  } : e);
213
221
  if (n.length === 1) {
214
- let t = d(n[0]), i = b([
222
+ let t = d(n[0]), i = x([
215
223
  ...c,
216
224
  ...t,
217
225
  ...l
218
226
  ]);
219
- e.replace(a.pas, [e.withRuns(o, i)], T({
227
+ e.replace(a.pas, [e.withRuns(o, i)], E({
220
228
  pa: a.at.pa,
221
- o: s + h(t)
229
+ o: s + g(t)
222
230
  }), {
223
231
  label: "paste",
224
232
  ...r
225
233
  });
226
234
  return;
227
235
  }
228
- let f = [], p = e.withRuns(o, b([...c, ...d(n[0])]));
236
+ let f = [], p = e.withRuns(o, x([...c, ...d(n[0])]));
229
237
  i?.[0] && (p = i[0](p));
230
238
  for (let t = 1; t < n.length; t++) {
231
- let r = t === n.length - 1, a = d(n[t]), [o, s] = e.split(p, p.runs, b([...a, ...r ? l : []]), !r);
239
+ let r = t === n.length - 1, a = d(n[t]), [o, s] = e.split(p, p.runs, x([...a, ...r ? l : []]), !r);
232
240
  f.push(o), p = i?.[t] ? i[t](s) : s;
233
241
  }
234
- f.push(p), e.replace(a.pas, f, T({
235
- pa: _(a.at.pa, f.length - 1),
236
- o: h(d(n[n.length - 1]))
242
+ f.push(p), e.replace(a.pas, f, E({
243
+ pa: v(a.at.pa, f.length - 1),
244
+ o: g(d(n[n.length - 1]))
237
245
  }), {
238
246
  label: "paste",
239
247
  ...r
240
248
  });
241
249
  }
242
- function A(e, t, n, r) {
243
- let i = O(e, t);
250
+ function j(e, t, n, r) {
251
+ let i = k(e, t);
244
252
  if (!i) return;
245
253
  let a = e.pendingStyle?.();
246
254
  e.clearPending?.();
247
255
  let o = i.paras[0], s = i.at.o, c = n.replace(/\r\n?/g, "\n").split("\n");
248
256
  if (c.length === 1 || r?.label === "linebreak") {
249
- let t = re(o.runs, s, n, a, e.defaultRun?.(o));
250
- e.replace(i.pas, [e.withRuns(o, t)], T({
257
+ let t = ne(o.runs, s, n, a, e.defaultRun?.(o));
258
+ e.replace(i.pas, [e.withRuns(o, t)], E({
251
259
  pa: i.at.pa,
252
260
  o: s + n.length
253
261
  }), {
@@ -257,42 +265,42 @@ function A(e, t, n, r) {
257
265
  return;
258
266
  }
259
267
  let l = a ? {
260
- ...S(o.runs, s) ?? e.defaultRun?.(o) ?? {},
268
+ ...C(o.runs, s) ?? e.defaultRun?.(o) ?? {},
261
269
  ...a
262
270
  } : void 0;
263
- k(e, t, c.map((e) => e ? [{
271
+ A(e, t, c.map((e) => e ? [{
264
272
  ...l ?? {},
265
273
  t: "text",
266
274
  text: e
267
275
  }] : []), r);
268
276
  }
269
277
  function se(e, t) {
270
- let n = g(t) ? (() => {
278
+ let n = _(t) ? (() => {
271
279
  let n = e.para(t.a.pa);
272
280
  return n ? {
273
281
  pas: [t.a.pa],
274
282
  paras: [n],
275
283
  at: t.a
276
284
  } : null;
277
- })() : E(e, t);
285
+ })() : D(e, t);
278
286
  if (!n) return;
279
- let r = n.paras[0], [i, a] = x(r.runs, n.at.o), [o, s] = e.split(r, i, a, n.at.o >= h(r.runs));
280
- e.replace(n.pas, [o, s], T({
281
- pa: _(n.at.pa, 1),
287
+ let r = n.paras[0], [i, a] = S(r.runs, n.at.o), [o, s] = e.split(r, i, a, n.at.o >= g(r.runs));
288
+ e.replace(n.pas, [o, s], E({
289
+ pa: v(n.at.pa, 1),
282
290
  o: 0
283
291
  }), { label: "enter" });
284
292
  }
285
- function j(e, t, n = !1) {
286
- if (!g(t)) return D(e, t);
293
+ function M(e, t, n = !1) {
294
+ if (!_(t)) return O(e, t);
287
295
  let { pa: r, o: i } = t.a, a = e.para(r);
288
296
  if (!a) return;
289
297
  if (i > 0) {
290
- let t = v(a.runs), o = ae(t, i);
298
+ let t = y(a.runs), o = ie(t, i);
291
299
  if (n) {
292
300
  let e = /(\S+\s*|\s+)$/.exec(t.slice(0, i));
293
301
  e && (o = i - e[0].length);
294
302
  }
295
- e.replace([r], [e.withRuns(a, C(a.runs, o, i))], T({
303
+ e.replace([r], [e.withRuns(a, w(a.runs, o, i))], E({
296
304
  pa: r,
297
305
  o
298
306
  }), { label: "delete" });
@@ -301,23 +309,23 @@ function j(e, t, n = !1) {
301
309
  if (e.backspaceAtStart?.(r, a)) return;
302
310
  let o = e.prev(r), s = o ? e.para(o) : void 0;
303
311
  if (!o || !s) return;
304
- let c = e.join(s, a, b([...s.runs, ...a.runs]));
305
- e.replace([o, r], [c], T({
312
+ let c = e.join(s, a, x([...s.runs, ...a.runs]));
313
+ e.replace([o, r], [c], E({
306
314
  pa: o,
307
- o: h(s.runs)
315
+ o: g(s.runs)
308
316
  }), { label: "merge" });
309
317
  }
310
- function M(e, t, n = !1) {
311
- if (!g(t)) return D(e, t);
318
+ function ce(e, t, n = !1) {
319
+ if (!_(t)) return O(e, t);
312
320
  let { pa: r, o: i } = t.a, a = e.para(r);
313
321
  if (!a) return;
314
- if (i < h(a.runs)) {
315
- let t = v(a.runs), o = oe(t, i);
322
+ if (i < g(a.runs)) {
323
+ let t = y(a.runs), o = ae(t, i);
316
324
  if (n) {
317
325
  let e = /^(\s*\S+|\s+)/.exec(t.slice(i));
318
326
  e && (o = i + e[0].length);
319
327
  }
320
- e.replace([r], [e.withRuns(a, C(a.runs, i, o))], T({
328
+ e.replace([r], [e.withRuns(a, w(a.runs, i, o))], E({
321
329
  pa: r,
322
330
  o: i
323
331
  }), { label: "delete" });
@@ -325,36 +333,36 @@ function M(e, t, n = !1) {
325
333
  }
326
334
  let o = e.next(r), s = o ? e.para(o) : void 0;
327
335
  if (!o || !s) return;
328
- let c = e.join(a, s, b([...a.runs, ...s.runs]));
329
- e.replace([r, o], [c], T({
336
+ let c = e.join(a, s, x([...a.runs, ...s.runs]));
337
+ e.replace([r, o], [c], E({
330
338
  pa: r,
331
339
  o: i
332
340
  }), { label: "merge" });
333
341
  }
334
- function N(e, t) {
342
+ function le(e, t) {
335
343
  let n = (e && (e.nodeType === 1 ? e : e.parentElement))?.closest("[data-o]");
336
344
  return n && t.contains(n) ? n : null;
337
345
  }
338
- function P(e) {
346
+ function N(e) {
339
347
  let t = Number(e.dataset.o);
340
348
  return e.hasAttribute("data-obj") ? t + 1 : e.hasAttribute("data-empty") ? t : t + (e.textContent?.length ?? 0);
341
349
  }
342
- function F(e, t, n) {
350
+ function P(e, t, n) {
343
351
  let r = (t.nodeType === 1 ? t : t.parentElement)?.closest("[data-pa]");
344
352
  if (!r || !e.contains(r)) return null;
345
353
  let i = r.dataset.pa;
346
- if (!N(t, r)) {
354
+ if (!le(t, r)) {
347
355
  let e = document.createRange();
348
356
  e.setStart(t, n), e.collapse(!0);
349
357
  let a = 0;
350
- for (let t of Array.from(r.querySelectorAll("[data-o]"))) if (e.comparePoint(t, t.childNodes.length) < 0) a = P(t);
358
+ for (let t of Array.from(r.querySelectorAll("[data-o]"))) if (e.comparePoint(t, t.childNodes.length) < 0) a = N(t);
351
359
  else break;
352
360
  return {
353
361
  pa: i,
354
362
  o: a
355
363
  };
356
364
  }
357
- let a = N(t, r), o = Number(a.dataset.o);
365
+ let a = le(t, r), o = Number(a.dataset.o);
358
366
  if (a.hasAttribute("data-empty")) return {
359
367
  pa: i,
360
368
  o
@@ -384,14 +392,14 @@ function F(e, t, n) {
384
392
  o: o + s
385
393
  };
386
394
  }
387
- function I(e, t) {
395
+ function F(e, t) {
388
396
  let n = e.querySelector(`[data-pa="${t.pa}"]`);
389
397
  if (!n) return null;
390
398
  let r = Array.from(n.querySelectorAll("[data-o]"));
391
399
  if (!r.length) return [n, n.childNodes.length];
392
400
  let i;
393
401
  for (let e of r) {
394
- let n = Number(e.dataset.o), r = P(e);
402
+ let n = Number(e.dataset.o), r = N(e);
395
403
  if (t.o >= n && t.o <= r && (i = e, t.o < r || !e.hasAttribute("data-obj"))) break;
396
404
  }
397
405
  i ??= r[r.length - 1];
@@ -412,12 +420,12 @@ function I(e, t) {
412
420
  }
413
421
  return c ? [c, c.textContent?.length ?? 0] : [i, 0];
414
422
  }
415
- function L(e) {
423
+ function I(e) {
416
424
  let t = e.getRootNode();
417
425
  return typeof ShadowRoot < "u" && t instanceof ShadowRoot && typeof t.getSelection == "function" ? t.getSelection() : (e.ownerDocument ?? document).getSelection();
418
426
  }
419
- function ce(e) {
420
- let t = e.getRootNode(), n = L(e);
427
+ function ue(e) {
428
+ let t = e.getRootNode(), n = I(e);
421
429
  if (!n) return null;
422
430
  if (typeof ShadowRoot < "u" && t instanceof ShadowRoot && n.anchorNode && !e.contains(n.anchorNode)) {
423
431
  let e = n.getComposedRanges?.call(n, { shadowRoots: [t] })[0];
@@ -430,13 +438,14 @@ function ce(e) {
430
438
  }
431
439
  return n;
432
440
  }
433
- var le = class {
441
+ var de = class {
434
442
  host;
435
443
  root = null;
436
444
  composing = null;
437
445
  justComposed = "";
438
446
  raf = 0;
439
447
  lastSel = null;
448
+ override = null;
440
449
  constructor(e) {
441
450
  this.host = e;
442
451
  }
@@ -445,31 +454,53 @@ var le = class {
445
454
  }
446
455
  detach() {
447
456
  let e = this.root;
448
- e && (e.removeEventListener("beforeinput", this.onBeforeInput), e.removeEventListener("compositionstart", this.onCompStart), e.removeEventListener("compositionend", this.onCompEnd), e.removeEventListener("keydown", this.onKeyDown), document.removeEventListener("selectionchange", this.onSelChange), cancelAnimationFrame(this.raf), this.root = null);
457
+ e && (e.removeEventListener("beforeinput", this.onBeforeInput), e.removeEventListener("compositionstart", this.onCompStart), e.removeEventListener("compositionend", this.onCompEnd), e.removeEventListener("keydown", this.onKeyDown), document.removeEventListener("selectionchange", this.onSelChange), cancelAnimationFrame(this.raf), this.root = null, this.override = null);
449
458
  }
450
459
  get isComposing() {
451
460
  return !!this.composing;
452
461
  }
453
462
  readSel() {
454
- let e = this.root, t = e ? ce(e) : null;
463
+ let e = this.root, t = e ? ue(e) : null;
455
464
  if (!e || !t || !t.anchorNode || !t.focusNode || !e.contains(t.anchorNode) || !e.contains(t.focusNode)) return null;
456
- let n = F(e, t.anchorNode, t.anchorOffset), r = F(e, t.focusNode, t.focusOffset);
465
+ let n = P(e, t.anchorNode, t.anchorOffset), r = P(e, t.focusNode, t.focusOffset);
457
466
  return n && r ? {
458
467
  a: n,
459
468
  f: r
460
469
  } : null;
461
470
  }
462
471
  sel() {
463
- return this.readSel() ?? this.lastSel;
472
+ return this.override?.model ?? this.readSel() ?? this.lastSel;
473
+ }
474
+ selectAll() {
475
+ let e = this.root, t = this.host.all?.();
476
+ if (!e || !t) return !1;
477
+ let n = Array.from(e.querySelectorAll("[data-pa]")).filter((t) => {
478
+ let n = t.closest("[contenteditable=\"false\"]");
479
+ return this.host.para(t.dataset.pa) && !(n && e.contains(n));
480
+ }), r = n[0], i = n[n.length - 1], a = r && i ? {
481
+ a: {
482
+ pa: r.dataset.pa,
483
+ o: 0
484
+ },
485
+ f: {
486
+ pa: i.dataset.pa,
487
+ o: g(this.host.para(i.dataset.pa).runs)
488
+ }
489
+ } : t;
490
+ return this.restore(a), this.override = {
491
+ model: t,
492
+ dom: this.readSel() ?? a
493
+ }, this.host.onSelection?.(t), !0;
464
494
  }
465
495
  restore(e, t = !0) {
466
496
  let n = this.root;
467
497
  if (!n || !e) return !1;
468
- let r = I(n, e.a), i = I(n, e.f);
498
+ this.override = null;
499
+ let r = F(n, e.a), i = F(n, e.f);
469
500
  if (!r || !i) return this.lastSel = e, !1;
470
501
  let a = n.getRootNode().activeElement;
471
502
  t && a !== n && !n.contains(a) && n.focus({ preventScroll: !0 });
472
- let o = L(n);
503
+ let o = I(n);
473
504
  try {
474
505
  o?.setBaseAndExtent(r[0], r[1], i[0], i[1]);
475
506
  } catch {}
@@ -477,7 +508,7 @@ var le = class {
477
508
  }
478
509
  rangeSel(e) {
479
510
  if (!e || !this.root) return null;
480
- let t = F(this.root, e.startContainer, e.startOffset), n = F(this.root, e.endContainer, e.endOffset);
511
+ let t = P(this.root, e.startContainer, e.startOffset), n = P(this.root, e.endContainer, e.endOffset);
481
512
  return t && n ? {
482
513
  a: t,
483
514
  f: n
@@ -489,47 +520,47 @@ var le = class {
489
520
  if (t === "deleteCompositionText" || t === "insertFromComposition") {
490
521
  if (e.cancelable && e.preventDefault(), t === "insertFromComposition" && e.data && e.data !== this.justComposed) {
491
522
  let t = this.sel();
492
- t && A(this.host, t, e.data, { remount: !0 });
523
+ t && j(this.host, t, e.data, { remount: !0 });
493
524
  }
494
525
  this.justComposed = "";
495
526
  return;
496
527
  }
497
528
  e.preventDefault();
498
- let n = this.rangeSel(e.getTargetRanges?.()[0]), r = this.readSel() ?? this.lastSel;
529
+ let n = this.rangeSel(e.getTargetRanges?.()[0]), r = this.sel();
499
530
  if (!r) return;
500
531
  let i = this.host;
501
532
  switch (t) {
502
533
  case "insertText":
503
534
  case "insertReplacementText": {
504
535
  let a = e.data ?? e.dataTransfer?.getData("text/plain") ?? "";
505
- A(i, t === "insertReplacementText" && n ? n : r, a);
536
+ j(i, t === "insertReplacementText" && n ? n : r, a);
506
537
  break;
507
538
  }
508
539
  case "insertParagraph":
509
540
  se(i, r);
510
541
  break;
511
542
  case "insertLineBreak":
512
- A(i, r, "\n", { label: "linebreak" });
543
+ j(i, r, "\n", { label: "linebreak" });
513
544
  break;
514
545
  case "insertFromPaste":
515
546
  case "insertFromDrop":
516
547
  case "insertFromYank": {
517
548
  if (e.dataTransfer && i.pasteRich?.(t === "insertFromDrop" && n ? n : r, e.dataTransfer)) break;
518
549
  let a = e.dataTransfer?.getData("text/plain") ?? e.data ?? "";
519
- a && A(i, r, a);
550
+ a && j(i, r, a);
520
551
  break;
521
552
  }
522
553
  case "deleteContentBackward":
523
- j(i, r);
554
+ M(i, r);
524
555
  break;
525
556
  case "deleteWordBackward":
526
- j(i, r, !0);
557
+ M(i, r, !0);
527
558
  break;
528
559
  case "deleteContentForward":
529
- M(i, r);
560
+ ce(i, r);
530
561
  break;
531
562
  case "deleteWordForward":
532
- M(i, r, !0);
563
+ ce(i, r, !0);
533
564
  break;
534
565
  case "deleteSoftLineBackward":
535
566
  case "deleteHardLineBackward":
@@ -539,7 +570,7 @@ var le = class {
539
570
  case "deleteByDrag":
540
571
  case "deleteContent":
541
572
  case "deleteEntireSoftLine":
542
- g(r) ? n && !g(n) && D(i, n) : D(i, r);
573
+ _(r) ? n && !_(n) && O(i, n) : O(i, r);
543
574
  break;
544
575
  case "historyUndo":
545
576
  i.undo();
@@ -557,11 +588,11 @@ var le = class {
557
588
  }
558
589
  };
559
590
  onCompStart = () => {
560
- this.composing = this.readSel() ?? this.lastSel;
591
+ this.composing = this.sel();
561
592
  };
562
593
  onCompEnd = (e) => {
563
594
  let t = this.composing;
564
- this.composing = null, t && (this.justComposed = e.data ?? "", e.data ? A(this.host, t, e.data, { remount: !0 }) : A(this.host, t, "", { remount: !0 }), setTimeout(() => this.justComposed = "", 0));
595
+ this.composing = null, t && (this.justComposed = e.data ?? "", e.data ? j(this.host, t, e.data, { remount: !0 }) : j(this.host, t, "", { remount: !0 }), setTimeout(() => this.justComposed = "", 0));
565
596
  };
566
597
  onKeyDown = (e) => {
567
598
  if (e.isComposing || this.composing) return;
@@ -577,6 +608,10 @@ var le = class {
577
608
  e.preventDefault(), this.host.redo();
578
609
  return;
579
610
  }
611
+ if (n === "a" && !e.shiftKey) {
612
+ this.selectAll() && e.preventDefault();
613
+ return;
614
+ }
580
615
  if (n === "b" || n === "i" || n === "u") {
581
616
  e.preventDefault(), this.host.toggle?.(n);
582
617
  return;
@@ -586,46 +621,51 @@ var le = class {
586
621
  e.preventDefault();
587
622
  let t = this.sel();
588
623
  if (!t) return;
589
- !this.host.tab?.(t, e.shiftKey) && !e.shiftKey && A(this.host, t, " ");
624
+ !this.host.tab?.(t, e.shiftKey) && !e.shiftKey && j(this.host, t, " ");
590
625
  }
591
626
  }
592
627
  };
593
628
  onSelChange = () => {
594
629
  this.raf ||= requestAnimationFrame(() => {
595
630
  this.raf = 0;
596
- let e = this.readSel();
631
+ let e = this.readSel(), t = this.override;
632
+ if (t && e && !oe(e, t.dom)) this.override = null;
633
+ else if (t) {
634
+ this.host.onSelection?.(t.model);
635
+ return;
636
+ }
597
637
  e && (this.lastSel = e), this.host.onSelection?.(e);
598
638
  });
599
639
  };
600
- }, ue = /* @__PURE__ */ new Set([
640
+ }, fe = /* @__PURE__ */ new Set([
601
641
  "open",
602
642
  "part",
603
643
  "docx.start",
604
644
  "save",
605
645
  "dirty"
606
- ]), R = (e) => e.t === "p" ? e.pid === void 0 ? null : { p: e.pid } : e.t === "tbl" ? {
646
+ ]), L = (e) => e.t === "p" ? e.pid === void 0 ? null : { p: e.pid } : e.t === "tbl" ? {
607
647
  tid: e.tid,
608
648
  item: e.item
609
649
  } : null;
610
- function z(e, t) {
650
+ function R(e, t) {
611
651
  return e ? "p" in t ? e.t === "p" && e.pid === t.p : e.t === "tbl" && (t.tid !== void 0 && e.tid === t.tid || t.item !== void 0 && e.item === t.item) : !1;
612
652
  }
613
- var de = (e) => [...new Set(e)];
614
- function B(e, t = []) {
653
+ var pe = (e) => [...new Set(e)];
654
+ function z(e, t = []) {
615
655
  for (let n of e) if (n.t === "p" && n.pid !== void 0) t.push(n.pid);
616
- else if (n.t === "tbl") for (let e of n.rows) for (let n of e.cells) B(n.blocks, t);
656
+ else if (n.t === "tbl") for (let e of n.rows) for (let n of e.cells) z(n.blocks, t);
617
657
  return t;
618
658
  }
619
- function fe(e) {
659
+ function me(e) {
620
660
  if (e.t !== "text") return JSON.stringify(e);
621
661
  let { text: t, ...n } = e;
622
662
  return JSON.stringify(n);
623
663
  }
624
- function pe(e, t) {
664
+ function he(e, t) {
625
665
  let n = (e) => {
626
666
  let t = [];
627
667
  for (let n of e) {
628
- let e = fe(n);
668
+ let e = me(n);
629
669
  if (n.t === "text") for (let r = 0; r < n.text.length; r++) t.push(e + "\0" + n.text[r]);
630
670
  else t.push(e);
631
671
  }
@@ -635,25 +675,25 @@ function pe(e, t) {
635
675
  let o = 0;
636
676
  for (; o < r.length - a && o < i.length - a && r[r.length - 1 - o] === i[i.length - 1 - o];) o++;
637
677
  if (a === r.length && a === i.length) return null;
638
- let [, s] = x(t, a), [c] = x(s, i.length - a - o);
678
+ let [, s] = S(t, a), [c] = S(s, i.length - a - o);
639
679
  return {
640
680
  at: a,
641
681
  del: r.length - a - o,
642
682
  ins: c
643
683
  };
644
684
  }
645
- function me(e, t, n, r) {
646
- let i = h(e), a = Math.max(0, Math.min(t, i)), o = Math.max(0, Math.min(n, i - a)), [s, c] = x(e, a), [, l] = x(c, o);
685
+ function ge(e, t, n, r) {
686
+ let i = g(e), a = Math.max(0, Math.min(t, i)), o = Math.max(0, Math.min(n, i - a)), [s, c] = S(e, a), [, l] = S(c, o);
647
687
  return [
648
688
  ...s,
649
689
  ...r,
650
690
  ...l
651
691
  ];
652
692
  }
653
- function V(e, t, n, r, i) {
693
+ function B(e, t, n, r, i) {
654
694
  return e < t || e === t && (n > 0 || i) ? e : e >= t + n ? e - n + r : t + r;
655
695
  }
656
- function he(e, t, n) {
696
+ function _e(e, t, n) {
657
697
  if (t === n) return e;
658
698
  let r = 0;
659
699
  for (; r < t.length && r < n.length && t[r] === n[r];) r++;
@@ -661,7 +701,7 @@ function he(e, t, n) {
661
701
  for (; i < t.length - r && i < n.length - r && t[t.length - 1 - i] === n[n.length - 1 - i];) i++;
662
702
  return e <= r ? e : e >= t.length - i ? n.length - (t.length - e) : n.length - i;
663
703
  }
664
- var ge = (e, t) => e.pid === t.pid && e.from === t.from && e.sid === t.sid && !!e.pb == !!t.pb && e.keepSect === t.keepSect && JSON.stringify(e.pd ?? null) === JSON.stringify(t.pd ?? null) && JSON.stringify(e.ps) === JSON.stringify(t.ps) && JSON.stringify(e.orig ?? null) === JSON.stringify(t.orig ?? null), _e = class {
704
+ var ve = (e, t) => e.pid === t.pid && e.from === t.from && e.sid === t.sid && !!e.pb == !!t.pb && e.keepSect === t.keepSect && JSON.stringify(e.pd ?? null) === JSON.stringify(t.pd ?? null) && JSON.stringify(e.ps) === JSON.stringify(t.ps) && JSON.stringify(e.orig ?? null) === JSON.stringify(t.orig ?? null), ye = class {
665
705
  client;
666
706
  host;
667
707
  suppress = 0;
@@ -701,7 +741,7 @@ var ge = (e, t) => e.pid === t.pid && e.from === t.from && e.sid === t.sid && !!
701
741
  this.offHost?.(), this.host && (this.host.editor.onCommit = void 0), typeof document < "u" && document.removeEventListener("selectionchange", this.onSel), this.raf && cancelAnimationFrame(this.raf);
702
742
  }
703
743
  captures(e) {
704
- return !this.suppress && !ue.has(e) && e !== "docx.edit" && e !== "docx.table" && e.startsWith("docx.");
744
+ return !this.suppress && !fe.has(e) && e !== "docx.edit" && e !== "docx.table" && e.startsWith("docx.");
705
745
  }
706
746
  intercept(e, t) {
707
747
  if (this.submit && this.captures(e)) {
@@ -756,7 +796,7 @@ var ge = (e, t) => e.pid === t.pid && e.from === t.from && e.sid === t.sid && !!
756
796
  }), t;
757
797
  }
758
798
  topIndex(e) {
759
- return this.st.blocks.findIndex((t) => z(t, e));
799
+ return this.st.blocks.findIndex((t) => R(t, e));
760
800
  }
761
801
  region(e) {
762
802
  let t = new Set(e);
@@ -841,8 +881,8 @@ var ge = (e, t) => e.pid === t.pid && e.from === t.from && e.sid === t.sid && !!
841
881
  if (this.suppress || !this.push) return;
842
882
  if (e.kind === "paras") {
843
883
  let t = e.before, n = e.next;
844
- if (t.length === 1 && n.length === 1 && t[0].pid !== void 0 && ge(t[0], n[0]) && this.locate(t[0].pid).length === 1) {
845
- let e = pe(t[0].runs, n[0].runs);
884
+ if (t.length === 1 && n.length === 1 && t[0].pid !== void 0 && ve(t[0], n[0]) && this.locate(t[0].pid).length === 1) {
885
+ let e = he(t[0].runs, n[0].runs);
846
886
  if (!e) return;
847
887
  this.push({
848
888
  t: "text",
@@ -868,10 +908,10 @@ var ge = (e, t) => e.pid === t.pid && e.from === t.from && e.sid === t.sid && !!
868
908
  }]);
869
909
  return;
870
910
  }
871
- let t = e.bi > 0 ? R(this.st.blocks[e.bi - 1]) : null;
911
+ let t = e.bi > 0 ? L(this.st.blocks[e.bi - 1]) : null;
872
912
  this.push({
873
913
  t: "blocks",
874
- before: e.before.map(R).filter((e) => !!e),
914
+ before: e.before.map(L).filter((e) => !!e),
875
915
  prev: t,
876
916
  next: e.next.map((e) => this.tag(e))
877
917
  }, [{
@@ -884,14 +924,14 @@ var ge = (e, t) => e.pid === t.pid && e.from === t.from && e.sid === t.sid && !!
884
924
  transform(e, t) {
885
925
  if (e.t !== "text") return e;
886
926
  if (t.t === "text" && t.pid === e.pid) {
887
- let n = h(t.ins), r = V(e.at, t.at, t.del, n, !1), i = e.del ? Math.max(r, V(e.at + e.del, t.at, t.del, n, !0)) : r;
927
+ let n = g(t.ins), r = B(e.at, t.at, t.del, n, !1), i = e.del ? Math.max(r, B(e.at + e.del, t.at, t.del, n, !0)) : r;
888
928
  return r === e.at && i - r === e.del ? e : {
889
929
  ...e,
890
930
  at: r,
891
931
  del: i - r
892
932
  };
893
933
  }
894
- return t.t === "paras" && (t.before.includes(e.pid) || t.next.some((t) => t.pid === e.pid)) ? t.next.some((t) => t.pid === e.pid) ? e : null : t.t === "blocks" && t.before.some((t) => "p" in t && t.p === e.pid) && !B(t.next).includes(e.pid) ? null : e;
934
+ return t.t === "paras" && (t.before.includes(e.pid) || t.next.some((t) => t.pid === e.pid)) ? t.next.some((t) => t.pid === e.pid) ? e : null : t.t === "blocks" && t.before.some((t) => "p" in t && t.p === e.pid) && !z(t.next).includes(e.pid) ? null : e;
895
935
  }
896
936
  touched(e) {
897
937
  switch (e.t) {
@@ -901,9 +941,9 @@ var ge = (e, t) => e.pid === t.pid && e.from === t.from && e.sid === t.sid && !!
901
941
  let t = [
902
942
  ...e.before,
903
943
  ...e.prev ? [e.prev] : [],
904
- ...e.next.map(R).filter((e) => !!e)
944
+ ...e.next.map(L).filter((e) => !!e)
905
945
  ].map((e) => "p" in e ? "p" + e.p : "t" + (e.item ?? "n" + e.tid));
906
- for (let n of B(e.next)) t.push("p" + n);
946
+ for (let n of z(e.next)) t.push("p" + n);
907
947
  return t;
908
948
  }
909
949
  default: return [];
@@ -950,7 +990,7 @@ var ge = (e, t) => e.pid === t.pid && e.from === t.from && e.sid === t.sid && !!
950
990
  if (n.length !== 1 || !t.para(n[0].pa)) return null;
951
991
  let r = n[0].p, i = {
952
992
  ...r,
953
- runs: me(r.runs, e.at, e.del, e.ins.map((e) => this.remap(e))),
993
+ runs: ge(r.runs, e.at, e.del, e.ins.map((e) => this.remap(e))),
954
994
  edited: !0
955
995
  };
956
996
  return t.replace([n[0].pa], [i], this.sel(), {
@@ -966,7 +1006,7 @@ var ge = (e, t) => e.pid === t.pid && e.from === t.from && e.sid === t.sid && !!
966
1006
  let n = e.next.map((e) => this.remap(e)), r = new Set(n.map((e) => e.pid)), i = this.region(e.before);
967
1007
  if (!i || !i.length) return null;
968
1008
  let a = [], o = new Set(i.map((e) => t.para(e)?.pid ?? -1));
969
- for (let n of de([...e.before, ...r])) if (!o.has(n)) for (let e of this.locate(n).reverse()) {
1009
+ for (let n of pe([...e.before, ...r])) if (!o.has(n)) for (let e of this.locate(n).reverse()) {
970
1010
  if (!t.para(e.pa)) continue;
971
1011
  let n = (t) => {
972
1012
  let n = e.list[t];
@@ -1006,14 +1046,14 @@ var ge = (e, t) => e.pid === t.pid && e.from === t.from && e.sid === t.sid && !!
1006
1046
  if (!t) return null;
1007
1047
  r = this.topIndex(t);
1008
1048
  }
1009
- for (; r + i < this.st.blocks.length && e.before.some((e) => z(this.st.blocks[r + i], e));) i++;
1049
+ for (; r + i < this.st.blocks.length && e.before.some((e) => R(this.st.blocks[r + i], e));) i++;
1010
1050
  } else if (r = e.prev ? this.topIndex(e.prev) + 1 : 0, e.prev && r === 0) return null;
1011
1051
  let a = this.st.blocks.slice(r, r + i), o = new Map(a.flatMap((e) => e.t === "p" && e.pid !== void 0 ? [[e.pid, e]] : []));
1012
1052
  return n = n.map((e) => e.t === "p" && e.pid !== void 0 && o.has(e.pid) ? o.get(e.pid) : e), t.replaceBlocks(r, i, n, null, !1), [{
1013
1053
  t: "blocks",
1014
1054
  before: a,
1015
1055
  next: n,
1016
- prev: r > 0 ? R(this.st.blocks[r - 1]) : null
1056
+ prev: r > 0 ? L(this.st.blocks[r - 1]) : null
1017
1057
  }];
1018
1058
  }
1019
1059
  return null;
@@ -1055,7 +1095,7 @@ var ge = (e, t) => e.pid === t.pid && e.from === t.from && e.sid === t.sid && !!
1055
1095
  });
1056
1096
  return;
1057
1097
  }
1058
- let n = e.next.length ? R(e.next[0]) : null, r = n ? this.topIndex(n) : e.prev ? this.topIndex(e.prev) + 1 : 0;
1098
+ let n = e.next.length ? L(e.next[0]) : null, r = n ? this.topIndex(n) : e.prev ? this.topIndex(e.prev) + 1 : 0;
1059
1099
  if (r < 0) return;
1060
1100
  let i = new Map(this.st.blocks.slice(r, r + e.next.length).flatMap((e) => e.t === "p" && e.pid !== void 0 ? [[e.pid, e]] : []));
1061
1101
  t.replaceBlocks(r, e.next.length, e.before.map((e) => e.t === "p" && e.pid !== void 0 && i.has(e.pid) ? i.get(e.pid) : e), null, !1);
@@ -1074,7 +1114,7 @@ var ge = (e, t) => e.pid === t.pid && e.from === t.from && e.sid === t.sid && !!
1074
1114
  let t = this.locate(e.pid), n = t[Math.min(e.k, t.length - 1)];
1075
1115
  return n ? {
1076
1116
  pa: n.pa,
1077
- o: Math.min(e.o, h(n.p.runs))
1117
+ o: Math.min(e.o, g(n.p.runs))
1078
1118
  } : null;
1079
1119
  }
1080
1120
  capture() {
@@ -1084,7 +1124,7 @@ var ge = (e, t) => e.pid === t.pid && e.from === t.from && e.sid === t.sid && !!
1084
1124
  let i = /* @__PURE__ */ new Map();
1085
1125
  for (let e of [n, r]) {
1086
1126
  let t = this.locate(e.pid)[e.k];
1087
- t && i.set(`${e.pid}:${e.k}`, v(t.p.runs));
1127
+ t && i.set(`${e.pid}:${e.k}`, y(t.p.runs));
1088
1128
  }
1089
1129
  this.snap = {
1090
1130
  a: n,
@@ -1105,10 +1145,10 @@ var ge = (e, t) => e.pid === t.pid && e.from === t.from && e.sid === t.sid && !!
1105
1145
  let n = (n) => {
1106
1146
  let r = this.locate(n.pid)[n.k] ?? this.locate(n.pid)[0];
1107
1147
  if (!r) return this.ed.input.lastSel?.f ?? t;
1108
- let i = e.text.get(`${n.pid}:${n.k}`), a = v(r.p.runs);
1148
+ let i = e.text.get(`${n.pid}:${n.k}`), a = y(r.p.runs);
1109
1149
  return {
1110
1150
  pa: r.pa,
1111
- o: i === void 0 ? Math.min(n.o, a.length) : he(n.o, i, a)
1151
+ o: i === void 0 ? Math.min(n.o, a.length) : _e(n.o, i, a)
1112
1152
  };
1113
1153
  };
1114
1154
  return {
@@ -1151,7 +1191,7 @@ var ge = (e, t) => e.pid === t.pid && e.from === t.from && e.sid === t.sid && !!
1151
1191
  caret: null,
1152
1192
  sel: []
1153
1193
  };
1154
- let a = I(n, i), o = null;
1194
+ let a = F(n, i), o = null;
1155
1195
  if (a) {
1156
1196
  let e = document.createRange();
1157
1197
  try {
@@ -1160,7 +1200,7 @@ var ge = (e, t) => e.pid === t.pid && e.from === t.from && e.sid === t.sid && !!
1160
1200
  o = null;
1161
1201
  }
1162
1202
  }
1163
- let s = [], c = I(n, r);
1203
+ let s = [], c = F(n, r);
1164
1204
  if (c && a && (r.pa !== i.pa || r.o !== i.o)) {
1165
1205
  let e = document.createRange();
1166
1206
  try {
@@ -1173,7 +1213,7 @@ var ge = (e, t) => e.pid === t.pid && e.from === t.from && e.sid === t.sid && !!
1173
1213
  sel: s
1174
1214
  };
1175
1215
  }
1176
- }, H = (e) => e !== null, U = class {
1216
+ }, V = (e) => e !== null, H = class {
1177
1217
  transport;
1178
1218
  adapter;
1179
1219
  opts;
@@ -1297,7 +1337,7 @@ var ge = (e, t) => e.pid === t.pid && e.from === t.from && e.sid === t.sid && !!
1297
1337
  t: "ops",
1298
1338
  id: this.inflight.id,
1299
1339
  base: this.rev,
1300
- ops: this.inflight.items.map((e) => e.op).filter(H)
1340
+ ops: this.inflight.items.map((e) => e.op).filter(V)
1301
1341
  })), this.flush(), this.presence !== void 0 && this.transport.send({
1302
1342
  t: "presence",
1303
1343
  data: this.presence
@@ -1343,7 +1383,7 @@ var ge = (e, t) => e.pid === t.pid && e.from === t.from && e.sid === t.sid && !!
1343
1383
  let t = e.ops.map((e) => e);
1344
1384
  if (e.base < e.seq - 1 && (this.log[0]?.seq ?? Infinity) > e.base + 1 && this.rev > e.base) return this.fail("Operation is too old to merge; reopen the document"), null;
1345
1385
  for (let n of this.log) if (!(n.seq <= e.base || n.site === e.site)) for (let e of n.ops) t = t.map((t) => t === null ? null : this.adapter.transform(t, e));
1346
- return t.filter(H);
1386
+ return t.filter(V);
1347
1387
  }
1348
1388
  async revertAll(e) {
1349
1389
  for (let t = e.length - 1; t >= 0; t--) {
@@ -1402,7 +1442,7 @@ var ge = (e, t) => e.pid === t.pid && e.from === t.from && e.sid === t.sid && !!
1402
1442
  this.log.push({
1403
1443
  seq: e.seq,
1404
1444
  site: e.site,
1405
- ops: t.map((e) => e.op).filter(H)
1445
+ ops: t.map((e) => e.op).filter(V)
1406
1446
  });
1407
1447
  }
1408
1448
  flush() {
@@ -1418,28 +1458,28 @@ var ge = (e, t) => e.pid === t.pid && e.from === t.from && e.sid === t.sid && !!
1418
1458
  t: "ops",
1419
1459
  id: t,
1420
1460
  base: this.rev,
1421
- ops: e.map((e) => e.op).filter(H)
1461
+ ops: e.map((e) => e.op).filter(V)
1422
1462
  });
1423
1463
  }
1424
- }, W = "$b64";
1425
- function ve(e) {
1464
+ }, U = "$b64";
1465
+ function W(e) {
1426
1466
  let t = "";
1427
1467
  for (let n = 0; n < e.length; n += 32768) t += String.fromCharCode(...e.subarray(n, n + 32768));
1428
1468
  return btoa(t);
1429
1469
  }
1430
- function ye(e) {
1470
+ function be(e) {
1431
1471
  let t = atob(e), n = new Uint8Array(t.length);
1432
1472
  for (let e = 0; e < t.length; e++) n[e] = t.charCodeAt(e);
1433
1473
  return n;
1434
1474
  }
1435
1475
  function G(e) {
1436
- return JSON.stringify(e, (e, t) => t instanceof Uint8Array ? { [W]: ve(t) } : t instanceof ArrayBuffer ? { [W]: ve(new Uint8Array(t)) } : t);
1476
+ return JSON.stringify(e, (e, t) => t instanceof Uint8Array ? { [U]: W(t) } : t instanceof ArrayBuffer ? { [U]: W(new Uint8Array(t)) } : t);
1437
1477
  }
1438
1478
  function K(e) {
1439
- return JSON.parse(e, (e, t) => t && typeof t == "object" && typeof t[W] == "string" && Object.keys(t).length === 1 ? ye(t[W]) : t);
1479
+ return JSON.parse(e, (e, t) => t && typeof t == "object" && typeof t[U] == "string" && Object.keys(t).length === 1 ? be(t[U]) : t);
1440
1480
  }
1441
1481
  // src/collab/transport.ts
1442
- var be = class {
1482
+ var q = class {
1443
1483
  url;
1444
1484
  protocols;
1445
1485
  onMessage;
@@ -1534,7 +1574,7 @@ var be = class {
1534
1574
  redoStack = [];
1535
1575
  offLocal;
1536
1576
  constructor(e) {
1537
- this.client = e, this.offLocal = te(e, (e) => {
1577
+ this.client = e, this.offLocal = m(e, (e) => {
1538
1578
  let t = e, n = this.path(t.sheet);
1539
1579
  n && this.onPresence?.({
1540
1580
  k: "xlsx",
@@ -1709,7 +1749,7 @@ var Ee = /* @__PURE__ */ new Set([
1709
1749
  ridKey = /* @__PURE__ */ new Map();
1710
1750
  offLocal;
1711
1751
  constructor(e) {
1712
- this.client = e, this.offLocal = te(e, (e) => {
1752
+ this.client = e, this.offLocal = m(e, (e) => {
1713
1753
  let t = e, n = this.path(t.slide);
1714
1754
  n && this.onPresence?.({
1715
1755
  k: "pptx",
@@ -1846,7 +1886,7 @@ var Ee = /* @__PURE__ */ new Set([
1846
1886
  async revert(e) {
1847
1887
  typeof e == "number" && this.client.notify("collab:pptx", await this.client.direct("collab.pptx.revert", e));
1848
1888
  }
1849
- }, q = [
1889
+ }, J = [
1850
1890
  "#1a73e8",
1851
1891
  "#e8710a",
1852
1892
  "#188038",
@@ -1904,7 +1944,7 @@ var Ee = /* @__PURE__ */ new Set([
1904
1944
  if (t) for (let [r, i] of t.peers) r !== n && i.send(e);
1905
1945
  }, o = (r, i) => {
1906
1946
  t = r, n = i.site && i.site < r.nextSite && !r.peers.has(i.site) ? i.site : r.nextSite++;
1907
- let o = new Set([...r.peers.values()].map((e) => e.info.color)), s = i.user.color || q.find((e) => !o.has(e)) || q[n % q.length], c = {
1947
+ let o = new Set([...r.peers.values()].map((e) => e.info.color)), s = i.user.color || J.find((e) => !o.has(e)) || J[n % J.length], c = {
1908
1948
  ...i.user,
1909
1949
  site: n,
1910
1950
  color: s
@@ -2028,7 +2068,7 @@ async function je(e, t) {
2028
2068
  r.forEach((e, t) => {
2029
2069
  if (e.seq !== n.seq + t + 1) throw Error(`compact: batch ${n.seq + t + 1} is missing`);
2030
2070
  });
2031
- let i = n.seq + r.length, a = $(e, {
2071
+ let i = n.seq + r.length, a = Pe(e, {
2032
2072
  transport: new Ae({
2033
2073
  t: "welcome",
2034
2074
  site: 0,
@@ -2072,7 +2112,7 @@ var Me = class {
2072
2112
  async delete(e) {
2073
2113
  this.data.delete(e);
2074
2114
  }
2075
- }, J = (e) => String(e).padStart(12, "0"), Y = new TextEncoder(), X = new TextDecoder(), Z = (e) => Y.encode(JSON.stringify(e)), Q = (e) => e ? JSON.parse(X.decode(e)) : null, Ne = class {
2115
+ }, Y = (e) => String(e).padStart(12, "0"), X = new TextEncoder(), Z = new TextDecoder(), Q = (e) => X.encode(JSON.stringify(e)), $ = (e) => e ? JSON.parse(Z.decode(e)) : null, Ne = class {
2076
2116
  blobs;
2077
2117
  opts;
2078
2118
  heads = /* @__PURE__ */ new Map();
@@ -2093,7 +2133,7 @@ var Me = class {
2093
2133
  }
2094
2134
  async readHead(e) {
2095
2135
  if (this.heads.has(e)) return this.heads.get(e);
2096
- let t = Q(await this.blobs.get(this.dir(e) + "head.json"));
2136
+ let t = $(await this.blobs.get(this.dir(e) + "head.json"));
2097
2137
  return this.heads.set(e, t), t;
2098
2138
  }
2099
2139
  create(e, t, n) {
@@ -2106,11 +2146,11 @@ var Me = class {
2106
2146
  time: Date.now(),
2107
2147
  ...n
2108
2148
  }, a = this.epochDir(e, i.epoch);
2109
- if (await this.blobs.put(`${a}snap/${J(0)}.bin`, t), await this.blobs.put(`${a}snap/${J(0)}.json`, Z({
2149
+ if (await this.blobs.put(`${a}snap/${Y(0)}.bin`, t), await this.blobs.put(`${a}snap/${Y(0)}.json`, Q({
2110
2150
  seq: 0,
2111
2151
  size: t.length,
2112
2152
  time: i.time
2113
- })), await this.blobs.put(this.dir(e) + "head.json", Z(i)), this.heads.set(e, i), r) for (let t of await this.blobs.list(this.epochDir(e, r.epoch))) await this.blobs.delete(t);
2153
+ })), await this.blobs.put(this.dir(e) + "head.json", Q(i)), this.heads.set(e, i), r) for (let t of await this.blobs.list(this.epochDir(e, r.epoch))) await this.blobs.delete(t);
2114
2154
  return i;
2115
2155
  });
2116
2156
  }
@@ -2118,23 +2158,23 @@ var Me = class {
2118
2158
  return this.run(e, () => this.readHead(e));
2119
2159
  }
2120
2160
  async file(e, t, n) {
2121
- return n ??= (await this.head(e))?.epoch, n ? this.blobs.get(`${this.epochDir(e, n)}snap/${J(t)}.bin`) : null;
2161
+ return n ??= (await this.head(e))?.epoch, n ? this.blobs.get(`${this.epochDir(e, n)}snap/${Y(t)}.bin`) : null;
2122
2162
  }
2123
2163
  async snapshot(e, t, n) {
2124
2164
  if (n ??= (await this.head(e))?.epoch, !n) return null;
2125
- let r = `${this.epochDir(e, n)}snap/${J(t)}`, i = Q(await this.blobs.get(r + ".json"));
2165
+ let r = `${this.epochDir(e, n)}snap/${Y(t)}`, i = $(await this.blobs.get(r + ".json"));
2126
2166
  if (!i) return null;
2127
2167
  let a = await this.blobs.get(r + ".ctx");
2128
2168
  return {
2129
2169
  ...i,
2130
- ctx: a ? K(X.decode(a)) : []
2170
+ ctx: a ? K(Z.decode(a)) : []
2131
2171
  };
2132
2172
  }
2133
2173
  async versions(e, t) {
2134
2174
  if (t ??= (await this.head(e))?.epoch, !t) return [];
2135
2175
  let n = `${this.epochDir(e, t)}snap/`, r = (await this.blobs.list(n)).filter((e) => e.endsWith(".json")).sort(), i = [];
2136
2176
  for (let e of r) {
2137
- let t = Q(await this.blobs.get(e));
2177
+ let t = $(await this.blobs.get(e));
2138
2178
  t && i.push({
2139
2179
  seq: t.seq,
2140
2180
  size: t.size,
@@ -2154,7 +2194,7 @@ var Me = class {
2154
2194
  } : null;
2155
2195
  }).filter((e) => e !== null && e.last > t && e.first <= n).sort((e, t) => e.first - t.first), a = /* @__PURE__ */ new Set(), o = [];
2156
2196
  for (let e of i) {
2157
- let r = X.decode(await this.blobs.get(e.k) ?? /* @__PURE__ */ new Uint8Array());
2197
+ let r = Z.decode(await this.blobs.get(e.k) ?? /* @__PURE__ */ new Uint8Array());
2158
2198
  for (let e of r.split("\n")) {
2159
2199
  if (!e) continue;
2160
2200
  let r = K(e);
@@ -2183,9 +2223,9 @@ var Me = class {
2183
2223
  t.batches = [];
2184
2224
  let r = await this.readHead(e);
2185
2225
  if (!r) return;
2186
- let i = `${this.epochDir(e, r.epoch)}ops/${J(n[0].seq)}-${J(n[n.length - 1].seq)}.jsonl`;
2226
+ let i = `${this.epochDir(e, r.epoch)}ops/${Y(n[0].seq)}-${Y(n[n.length - 1].seq)}.jsonl`;
2187
2227
  try {
2188
- await this.blobs.put(i, Y.encode(n.map((e) => G(e)).join("\n") + "\n")), t.retry = 0;
2228
+ await this.blobs.put(i, X.encode(n.map((e) => G(e)).join("\n") + "\n")), t.retry = 0;
2189
2229
  } catch (r) {
2190
2230
  if (this.opts.onError?.(r, e), this.buffers.get(e) !== t) return;
2191
2231
  t.batches.unshift(...n), t.timer ||= setTimeout(() => void this.flushRoom(e), Math.min(3e4, 500 * 2 ** t.retry++));
@@ -2213,9 +2253,9 @@ var Me = class {
2213
2253
  if (!i || i.epoch !== t.epoch || n.seq <= i.seq) return null;
2214
2254
  let a = this.epochDir(e, i.epoch), o = Date.now();
2215
2255
  await Promise.all([
2216
- this.blobs.put(`${a}snap/${J(n.seq)}.bin`, r),
2217
- this.blobs.put(`${a}snap/${J(n.seq)}.ctx`, Y.encode(G(n.ctx))),
2218
- this.blobs.put(`${a}snap/${J(n.seq)}.json`, Z({
2256
+ this.blobs.put(`${a}snap/${Y(n.seq)}.bin`, r),
2257
+ this.blobs.put(`${a}snap/${Y(n.seq)}.ctx`, X.encode(G(n.ctx))),
2258
+ this.blobs.put(`${a}snap/${Y(n.seq)}.json`, Q({
2219
2259
  seq: n.seq,
2220
2260
  size: r.length,
2221
2261
  time: o,
@@ -2228,7 +2268,7 @@ var Me = class {
2228
2268
  size: r.length,
2229
2269
  time: o
2230
2270
  };
2231
- return await this.blobs.put(this.dir(e) + "head.json", Z(s)), this.heads.set(e, s), this.opts.keep && await this.prune(e, s), s;
2271
+ return await this.blobs.put(this.dir(e) + "head.json", Q(s)), this.heads.set(e, s), this.opts.keep && await this.prune(e, s), s;
2232
2272
  });
2233
2273
  }
2234
2274
  async prune(e, t) {
@@ -2237,14 +2277,14 @@ var Me = class {
2237
2277
  "bin",
2238
2278
  "json",
2239
2279
  "ctx"
2240
- ]) await this.blobs.delete(`${n}${J(e)}.${t}`);
2280
+ ]) await this.blobs.delete(`${n}${Y(e)}.${t}`);
2241
2281
  let a = r[i.length], o = Math.min(a, t.seq - (this.opts.retain ?? 1e3));
2242
2282
  for (let n of await this.blobs.list(`${this.epochDir(e, t.epoch)}ops/`)) Number(/-(\d+)\.jsonl$/.exec(n)?.[1]) <= o && await this.blobs.delete(n);
2243
2283
  }
2244
2284
  };
2245
2285
  // src/collab/index.ts
2246
- function $(e, t) {
2247
- let n = typeof t.transport == "string" ? new be(t.transport) : t.transport, r = e.kind === "docx" ? new _e(e) : void 0, i = r ?? (e.kind === "xlsx" ? new Ce(e) : new De(e)), a = new U(n, i, {
2286
+ function Pe(e, t) {
2287
+ let n = typeof t.transport == "string" ? new q(t.transport) : t.transport, r = e.kind === "docx" ? new ye(e) : void 0, i = r ?? (e.kind === "xlsx" ? new Ce(e) : new De(e)), a = new H(n, i, {
2248
2288
  room: t.room,
2249
2289
  user: t.user,
2250
2290
  base: t.base
@@ -2276,6 +2316,6 @@ function $(e, t) {
2276
2316
  }
2277
2317
  };
2278
2318
  }
2279
- export { v as C, ee as D, f as E, a as O, S, x as T, F as _, Oe as a, b, K as c, le as d, I as f, w as g, k as h, je as i, p as k, G as l, A as m, Me as n, xe as o, L as p, Ne as r, be as s, $ as t, U as u, g as v, _ as w, h as x, ie as y };
2319
+ export { y as C, ee as D, f as E, a as O, C as S, S as T, P as _, Oe as a, x as b, K as c, de as d, F as f, T as g, A as h, je as i, p as k, G as l, j as m, Me as n, xe as o, I as p, Ne as r, q as s, Pe as t, H as u, _ as v, v as w, g as x, re as y };
2280
2320
 
2281
- //# sourceMappingURL=collab-BvjXvfJ9.js.map
2321
+ //# sourceMappingURL=collab-Dx00zqXR.js.map