@one2x/medeo-rte 0.4.0 → 0.4.1

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/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
- var Ks = Object.defineProperty;
2
- var Us = (s, t, e) => t in s ? Ks(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
- var u = (s, t, e) => Us(s, typeof t != "symbol" ? t + "" : t, e);
1
+ var Us = Object.defineProperty;
2
+ var Ks = (s, t, e) => t in s ? Us(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
+ var u = (s, t, e) => Ks(s, typeof t != "symbol" ? t + "" : t, e);
4
4
  import { e as it, E as Me, a as Tn, b as Rn, c as Bn, p as qs } from "./chunks/types-Hb-uu8xL.js";
5
- import { prepareWithSegments as Ne, measureNaturalWidth as Pn, setLocale as js, layoutNextLine as Xs } from "@chenglou/pretext";
5
+ import { prepareWithSegments as Ne, measureNaturalWidth as Ln, setLocale as js, layoutNextLine as Xs } from "@chenglou/pretext";
6
6
  const Ys = ["plain", "javascript", "typescript", "python", "json", "html", "css"], Js = 28, Zs = 18, Qs = 12;
7
7
  function ti(s, t) {
8
8
  const e = Math.max(1, (s.code ?? "").split(`
@@ -101,12 +101,12 @@ function ie(s, t) {
101
101
  }
102
102
  return 1;
103
103
  }
104
- const jt = [];
104
+ const Xt = [];
105
105
  function W(s) {
106
- for (const e of jt)
106
+ for (const e of Xt)
107
107
  if (e.spacers === s) return e.blocks;
108
108
  const t = si(s);
109
- return jt.unshift({ spacers: s, blocks: t }), jt.length > 2 && jt.pop(), t;
109
+ return Xt.unshift({ spacers: s, blocks: t }), Xt.length > 2 && Xt.pop(), t;
110
110
  }
111
111
  function si(s) {
112
112
  const t = [];
@@ -300,13 +300,13 @@ const Rt = {
300
300
  2: { fontSize: 22, bold: !0 },
301
301
  3: { fontSize: 18, bold: !0 }
302
302
  };
303
- function Ln(s) {
303
+ function Pn(s) {
304
304
  return s.bold !== void 0 || s.italic !== void 0 || s.underline !== void 0 || s.underlineStyle !== void 0 || s.strikethrough !== void 0 || s.fontSize !== void 0 || s.fontFamily !== void 0 || s.fontWeight !== void 0 || s.color !== void 0 || s.fill !== void 0;
305
305
  }
306
306
  function $n(s, t) {
307
307
  return s.bold === t.bold && s.italic === t.italic && s.underline === t.underline && s.underlineStyle === t.underlineStyle && s.strikethrough === t.strikethrough && s.fontSize === t.fontSize && s.fontFamily === t.fontFamily && s.fontWeight === t.fontWeight && s.color === t.color && s.fill === t.fill;
308
308
  }
309
- function zt(s) {
309
+ function Vt(s) {
310
310
  return s.underline === !1 ? "none" : s.underlineStyle ? s.underlineStyle : s.underline ? "single" : "none";
311
311
  }
312
312
  function X(s) {
@@ -322,10 +322,10 @@ function mi(s) {
322
322
  const t = {};
323
323
  return s.bold !== void 0 && (t.bold = s.bold), s.italic !== void 0 && (t.italic = s.italic), s.fontSize !== void 0 && (t.fontSize = s.fontSize), s.fontFamily !== void 0 && (t.fontFamily = s.fontFamily), s.fontWeight !== void 0 && (t.fontWeight = s.fontWeight), s.color !== void 0 && (t.color = s.color), t;
324
324
  }
325
- function Ae(s, t, e) {
325
+ function xe(s, t, e) {
326
326
  return e ? [...s].map((n) => n.end <= t ? I(n) : n.start >= t ? I({ ...n, start: n.start + e, end: n.end + e }) : I({ ...n, end: n.end + e })) : [...s].map(I);
327
327
  }
328
- function xe(s, t, e) {
328
+ function Ae(s, t, e) {
329
329
  const n = e - t;
330
330
  if (n <= 0) return [...s].map(I);
331
331
  const i = [];
@@ -353,7 +353,7 @@ function Ie(s, t) {
353
353
  }
354
354
  return e;
355
355
  }
356
- function xt(s, t) {
356
+ function At(s, t) {
357
357
  const e = t ?? new Map(s.map((n) => [n.id, n]));
358
358
  return [...s].sort((n, i) => {
359
359
  const r = n.end - n.start, o = i.end - i.start;
@@ -385,7 +385,7 @@ function ki(s, t, e) {
385
385
  r.parentId && !i.has(r.parentId) && (r.parentId = null);
386
386
  return n;
387
387
  }
388
- const Fn = '"PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif', wi = 1.6, re = 680, Ce = 72, Te = 56, On = 28, vi = 24, Xt = 8, nn = 36, ye = 4, Yt = /* @__PURE__ */ new Map(), Si = 2e4;
388
+ const Fn = '"PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif', wi = 1.6, re = 680, Ce = 72, Te = 56, On = 28, vi = 24, Yt = 8, nn = 36, ye = 4, Jt = /* @__PURE__ */ new Map(), Si = 2e4;
389
389
  let sn = !1;
390
390
  function ze() {
391
391
  sn || (js("zh-CN"), sn = !0);
@@ -410,27 +410,27 @@ function Kt(s) {
410
410
  function et(s, t) {
411
411
  if (!s) return 0;
412
412
  ze();
413
- const e = Kt(t), n = `${e}\0${s}`, i = Yt.get(n);
413
+ const e = Kt(t), n = `${e}\0${s}`, i = Jt.get(n);
414
414
  if (i !== void 0) return i;
415
- const r = Ne(s, e, { whiteSpace: "pre-wrap" }), o = Pn(r);
416
- return Yt.size >= Si && Yt.clear(), Yt.set(n, o), o;
417
- }
418
- const Jt = /* @__PURE__ */ new Map(), Mi = 4e3;
419
- function Ai(s, t) {
420
- return s ? Pn(Ne(s, t, { whiteSpace: "pre-wrap" })) : 0;
415
+ const r = Ne(s, e, { whiteSpace: "pre-wrap" }), o = Ln(r);
416
+ return Jt.size >= Si && Jt.clear(), Jt.set(n, o), o;
421
417
  }
418
+ const Zt = /* @__PURE__ */ new Map(), Mi = 4e3;
422
419
  function xi(s, t) {
420
+ return s ? Ln(Ne(s, t, { whiteSpace: "pre-wrap" })) : 0;
421
+ }
422
+ function Ai(s, t) {
423
423
  if (!s) return [];
424
424
  ze();
425
- const e = Kt(t), n = `${e}\0${s}`, i = Jt.get(n);
425
+ const e = Kt(t), n = `${e}\0${s}`, i = Zt.get(n);
426
426
  if (i) return i;
427
427
  const r = new Array(s.length).fill(0);
428
428
  let o = 0, a = 0;
429
429
  for (; a < s.length; ) {
430
- const l = s.codePointAt(a) ?? 0, c = a + (l > 65535 ? 2 : 1), h = c === s.length ? et(s, t) : Ai(s.slice(0, c), e);
430
+ const l = s.codePointAt(a) ?? 0, c = a + (l > 65535 ? 2 : 1), h = c === s.length ? et(s, t) : xi(s.slice(0, c), e);
431
431
  r[a] = Math.max(0, h - o), o = h, a = c;
432
432
  }
433
- return Jt.size >= Mi && Jt.clear(), Jt.set(n, r), r;
433
+ return Zt.size >= Mi && Zt.clear(), Zt.set(n, r), r;
434
434
  }
435
435
  function ce(s) {
436
436
  return Math.round((s.fontSize ?? Rt.fontSize) * wi);
@@ -470,7 +470,7 @@ function It(s, t, e) {
470
470
  };
471
471
  }
472
472
  const Nn = 120, Ti = 24;
473
- function Vt(s, t) {
473
+ function _t(s, t) {
474
474
  const e = s.kind === "hostSlot";
475
475
  let n = s.width > 0 ? s.width : e ? Nn : 0;
476
476
  const i = s.height > 0 ? s.height : e ? Ti : s.height;
@@ -479,13 +479,13 @@ function Vt(s, t) {
479
479
  function Hn(s, t) {
480
480
  return s.float ? !1 : (s.width > 0 ? s.width : s.kind === "hostSlot" ? Nn : 0) >= t - 0.5 ? !0 : s.kind === "hostSlot" ? !1 : (s.height > 0, s.height) > 36;
481
481
  }
482
- const Zt = /* @__PURE__ */ new Map(), Ri = 4e3;
482
+ const Qt = /* @__PURE__ */ new Map(), Ri = 4e3;
483
483
  function Bi(s, t) {
484
484
  ze();
485
- const e = Kt(t), n = `${e}\0${s}`, i = Zt.get(n);
485
+ const e = Kt(t), n = `${e}\0${s}`, i = Qt.get(n);
486
486
  if (i) return i;
487
487
  const r = Ne(s, e, { whiteSpace: "pre-wrap" });
488
- return Zt.size >= Ri && Zt.clear(), Zt.set(n, r), r;
488
+ return Qt.size >= Ri && Qt.clear(), Qt.set(n, r), r;
489
489
  }
490
490
  const rn = 8;
491
491
  function zn(s, t, e) {
@@ -537,7 +537,7 @@ function _n(s, t, e) {
537
537
  }
538
538
  return s.slice(0, r);
539
539
  }
540
- function Pi(s, t, e, n, i) {
540
+ function Li(s, t, e, n, i) {
541
541
  const r = Vn(s, t, e, n), o = [];
542
542
  let a = [], l = 0, c = t;
543
543
  const h = (d) => {
@@ -545,7 +545,7 @@ function Pi(s, t, e, n, i) {
545
545
  };
546
546
  for (const d of r) {
547
547
  if (d.kind === "image") {
548
- const g = Hn(d.entity, i), y = Vt(d.entity, i).width;
548
+ const g = Hn(d.entity, i), y = _t(d.entity, i).width;
549
549
  if (g) {
550
550
  a.length > 0 && h(d.index), a.push({ kind: "image", index: d.index, length: 1, entity: d.entity }), h(d.index + 1);
551
551
  continue;
@@ -578,7 +578,7 @@ function Pi(s, t, e, n, i) {
578
578
  }
579
579
  return (a.length > 0 || o.length === 0) && h(e), o;
580
580
  }
581
- function Li(s, t, e, n, i, r = 14) {
581
+ function Pi(s, t, e, n, i, r = 14) {
582
582
  let o = s, a = s + t;
583
583
  for (const l of i)
584
584
  l.y + l.h <= e + 0.5 || l.y >= e + n - 0.5 || (l.side === "left" ? o = Math.max(o, l.x + l.w + r) : a = Math.min(a, l.x - r));
@@ -610,7 +610,7 @@ function Ni(s, t) {
610
610
  const i = s.runs[s.i], r = t - n;
611
611
  if (i.kind === "image") {
612
612
  if (i.entity.float) break;
613
- const h = Hn(i.entity, t), d = Vt(i.entity, t).width;
613
+ const h = Hn(i.entity, t), d = _t(i.entity, t).width;
614
614
  if (h) {
615
615
  if (e.length > 0) break;
616
616
  e.push({ kind: "image", index: i.index, length: 1, entity: i.entity }), s.i += 1;
@@ -639,7 +639,7 @@ function Hi(s, t) {
639
639
  return s.list === "ul" ? an[(s.indent ?? 0) % an.length] : s.list === "ol" ? `${t}.` : "";
640
640
  }
641
641
  function Gn(s, t, e, n, i, r, o, a = [], l) {
642
- const c = { ...N, ...l ?? s.paragraphPropsAt(t) }, h = (c.indent ?? 0) * vi, d = Hi(c, o), f = c.list && c.list !== "none" ? On : 0, p = n + h + f, g = Math.max(80, r - h - f), y = c.align ?? "left", b = [], B = [...a], R = B.length > 0 || zi(s, t, e), L = [];
642
+ const c = { ...N, ...l ?? s.paragraphPropsAt(t) }, h = (c.indent ?? 0) * vi, d = Hi(c, o), f = c.list && c.list !== "none" ? On : 0, p = n + h + f, g = Math.max(80, r - h - f), y = c.align ?? "left", b = [], B = [...a], R = B.length > 0 || zi(s, t, e), P = [];
643
643
  let E = i;
644
644
  if (R) {
645
645
  const w = Di(s, t, e, c, !1);
@@ -647,17 +647,17 @@ function Gn(s, t, e, n, i, r, o, a = [], l) {
647
647
  do {
648
648
  const M = Fi(w);
649
649
  if ((M == null ? void 0 : M.kind) === "image" && M.entity.float) {
650
- const A = M.entity.float, x = Vt(M.entity, r), V = A === "left" ? n : n + r - x.width, H = { index: M.index, x: V, y: E, w: x.width, h: x.height, entity: M.entity };
651
- b.push(H), B.push({ x: H.x, y: H.y, w: H.w, h: H.h, side: A }), Oi(w);
650
+ const x = M.entity.float, A = _t(M.entity, r), V = x === "left" ? n : n + r - A.width, H = { index: M.index, x: V, y: E, w: A.width, h: A.height, entity: M.entity };
651
+ b.push(H), B.push({ x: H.x, y: H.y, w: H.w, h: H.h, side: x }), Oi(w);
652
652
  continue;
653
653
  }
654
- const U = Li(p, g, E, 28, B), J = on(w, t), q = oe(w) ? [] : Ni(w, U.w), v = oe(w) ? e : on(w, e), S = ln(
654
+ const K = Pi(p, g, E, 28, B), J = on(w, t), q = oe(w) ? [] : Ni(w, K.w), v = oe(w) ? e : on(w, e), S = ln(
655
655
  s,
656
656
  c,
657
657
  q,
658
- U.x,
658
+ K.x,
659
659
  E,
660
- U.w,
660
+ K.w,
661
661
  y,
662
662
  t,
663
663
  J,
@@ -665,12 +665,12 @@ function Gn(s, t, e, n, i, r, o, a = [], l) {
665
665
  d && z === 0 ? d : "",
666
666
  n + h
667
667
  );
668
- L.push(S), E += S.h, z += 1;
668
+ P.push(S), E += S.h, z += 1;
669
669
  } while (!oe(w));
670
670
  } else {
671
- const w = Pi(s, t, e, c, g);
671
+ const w = Li(s, t, e, c, g);
672
672
  for (let z = 0; z < w.length; z++) {
673
- const M = w[z], U = ln(
673
+ const M = w[z], K = ln(
674
674
  s,
675
675
  c,
676
676
  M.items,
@@ -684,7 +684,7 @@ function Gn(s, t, e, n, i, r, o, a = [], l) {
684
684
  d && z === 0 ? d : "",
685
685
  n + h
686
686
  );
687
- L.push(U), E += U.h;
687
+ P.push(K), E += K.h;
688
688
  }
689
689
  }
690
690
  return {
@@ -695,7 +695,7 @@ function Gn(s, t, e, n, i, r, o, a = [], l) {
695
695
  w: r,
696
696
  h: Math.max(0, E - i),
697
697
  props: c,
698
- lines: L,
698
+ lines: P,
699
699
  floats: b
700
700
  };
701
701
  }
@@ -718,7 +718,7 @@ function ln(s, t, e, n, i, r, o, a, l, c, h, d) {
718
718
  let f = 0, p = 20;
719
719
  for (const E of e)
720
720
  if (E.kind === "image") {
721
- const w = Vt(E.entity, r);
721
+ const w = _t(E.entity, r);
722
722
  f += w.width, p = Math.max(p, w.height);
723
723
  } else
724
724
  f += et(E.text, E.style), p = Math.max(p, ce(E.style));
@@ -732,7 +732,7 @@ function ln(s, t, e, n, i, r, o, a, l, c, h, d) {
732
732
  let R = n + g;
733
733
  for (const E of e)
734
734
  if (E.kind === "image") {
735
- const w = Vt(E.entity, r);
735
+ const w = _t(E.entity, r);
736
736
  b.push({
737
737
  index: E.index,
738
738
  x: R,
@@ -743,23 +743,23 @@ function ln(s, t, e, n, i, r, o, a, l, c, h, d) {
743
743
  }), R += w.width, B.push({ index: E.index + 1, x: R });
744
744
  } else {
745
745
  let w = R;
746
- const z = xi(E.text, E.style);
746
+ const z = Ai(E.text, E.style);
747
747
  for (let M = 0; M < E.text.length; M++) {
748
- const U = E.text[M], J = z[M];
748
+ const K = E.text[M], J = z[M];
749
749
  y.push({
750
750
  index: E.index + M,
751
751
  x: w,
752
752
  y: i,
753
753
  w: J,
754
754
  h: p,
755
- text: U,
755
+ text: K,
756
756
  style: E.style
757
757
  }), w += J, B.push({ index: E.index + M + 1, x: w });
758
758
  }
759
759
  R = w;
760
760
  }
761
761
  B[B.length - 1].index !== c && B.push({ index: c, x: R });
762
- const L = h ? {
762
+ const P = h ? {
763
763
  x: d,
764
764
  y: i,
765
765
  w: On,
@@ -779,7 +779,7 @@ function ln(s, t, e, n, i, r, o, a, l, c, h, d) {
779
779
  align: o ?? "left",
780
780
  glyphs: y,
781
781
  images: b,
782
- marker: L,
782
+ marker: P,
783
783
  caretStops: B,
784
784
  vblocks: Vi(s, l, c, i, p, y, b, !o || o === "left" ? n + r : null)
785
785
  };
@@ -787,7 +787,7 @@ function ln(s, t, e, n, i, r, o, a, l, c, h, d) {
787
787
  function Vi(s, t, e, n, i, r, o, a) {
788
788
  const l = s.virtualBlocksOverlapping(t, e);
789
789
  if (!l.length) return [];
790
- const c = xt(l, s.virtualBlocks), h = [];
790
+ const c = At(l, s.virtualBlocks), h = [];
791
791
  for (const d of c) {
792
792
  const f = [];
793
793
  for (const w of r)
@@ -795,14 +795,14 @@ function Vi(s, t, e, n, i, r, o, a) {
795
795
  for (const w of o)
796
796
  w.index >= d.start && w.index < d.end && f.push(w);
797
797
  if (!f.length) continue;
798
- const p = Math.min(...f.map((w) => w.x)), g = Math.max(...f.map((w) => w.x + w.w)), y = Math.min(...f.map((w) => w.y)), b = Math.max(...f.map((w) => w.y + w.h)), B = d.chrome.paddingX ?? 0, R = d.end > e && /[^\n]/.test(s.spacers.slice(e, d.end)), L = p - B, E = R && a != null ? Math.max(g, a) + B : g + B;
798
+ const p = Math.min(...f.map((w) => w.x)), g = Math.max(...f.map((w) => w.x + w.w)), y = Math.min(...f.map((w) => w.y)), b = Math.max(...f.map((w) => w.y + w.h)), B = d.chrome.paddingX ?? 0, R = d.end > e && /[^\n]/.test(s.spacers.slice(e, d.end)), P = p - B, E = R && a != null ? Math.max(g, a) + B : g + B;
799
799
  h.push({
800
800
  id: d.id,
801
801
  kind: d.kind,
802
802
  depth: Ie(d, s.virtualBlocks),
803
- x: L,
803
+ x: P,
804
804
  y: Math.min(y, n),
805
- w: Math.max(0, E - L),
805
+ w: Math.max(0, E - P),
806
806
  h: Math.max(i, b - y),
807
807
  chrome: { ...d.chrome },
808
808
  empty: d.empty,
@@ -824,20 +824,20 @@ function _i(s, t, e, n, i, r) {
824
824
  const g = t.rows[p], y = [];
825
825
  let b = 32, B = e;
826
826
  for (let R = 0; R < o; R++) {
827
- const L = g.cells[R], E = h[R], w = Math.max(1, E - Xt * 2), z = [];
828
- let M = f + Xt;
829
- const U = /* @__PURE__ */ new Map();
830
- if (L)
831
- for (const q of L.paragraphs) {
832
- const v = r.at(q.start, q.end), S = Gn(s, q.start, q.end, B + Xt, M, w, Wn(U, v), [], v);
827
+ const P = g.cells[R], E = h[R], w = Math.max(1, E - Yt * 2), z = [];
828
+ let M = f + Yt;
829
+ const K = /* @__PURE__ */ new Map();
830
+ if (P)
831
+ for (const q of P.paragraphs) {
832
+ const v = r.at(q.start, q.end), S = Gn(s, q.start, q.end, B + Yt, M, w, Wn(K, v), [], v);
833
833
  z.push(S), M += S.h;
834
834
  }
835
- const J = Math.max(32, M - f + Xt);
835
+ const J = Math.max(32, M - f + Yt);
836
836
  b = Math.max(b, J), y.push({
837
837
  row: p,
838
838
  col: R,
839
- start: (L == null ? void 0 : L.start) ?? t.start,
840
- end: (L == null ? void 0 : L.end) ?? t.start,
839
+ start: (P == null ? void 0 : P.start) ?? t.start,
840
+ end: (P == null ? void 0 : P.end) ?? t.start,
841
841
  x: B,
842
842
  y: f,
843
843
  w: E,
@@ -873,14 +873,14 @@ function Wi(s) {
873
873
  }
874
874
  }
875
875
  const cn = /* @__PURE__ */ new WeakMap();
876
- function Ki(s) {
876
+ function Ui(s) {
877
877
  const t = cn.get(s);
878
878
  if (t && t.spacers === s.spacers) return t.has;
879
879
  const e = s.spacers.includes(m.IMAGE);
880
880
  return cn.set(s, { spacers: s.spacers, has: e }), e;
881
881
  }
882
- function Kn(s, t, e) {
883
- if (!Ki(s)) return "";
882
+ function Un(s, t, e) {
883
+ if (!Ui(s)) return "";
884
884
  const n = [];
885
885
  for (let i = t; i < e; i++) {
886
886
  if (s.spacers[i] !== m.IMAGE) continue;
@@ -891,7 +891,7 @@ function Kn(s, t, e) {
891
891
  }
892
892
  return n.join(",");
893
893
  }
894
- class Ui {
894
+ class Ki {
895
895
  constructor(t) {
896
896
  u(this, "spans");
897
897
  /** maxEnd[i] = spans[0..i] 里最大的 end,单调不减 */
@@ -959,13 +959,13 @@ function Xi(s) {
959
959
  return JSON.stringify({ f: (t = s.textDefaults) == null ? void 0 : t.fontFamily, w: (e = s.textDefaults) == null ? void 0 : e.fontWeight, s: (n = s.textDefaults) == null ? void 0 : n.fontSize });
960
960
  }
961
961
  function Yi(s, t, e, n, i, r, o, a, l) {
962
- return `p:${i}:${r}:${o}:${a}:${s.spacers.slice(e, n)}:${t.key(e, n, qi)}:${Kn(s, e, n)}:${Ji(s, e, n)}:td:${l}`;
962
+ return `p:${i}:${r}:${o}:${a}:${s.spacers.slice(e, n)}:${t.key(e, n, qi)}:${Un(s, e, n)}:${Ji(s, e, n)}:td:${l}`;
963
963
  }
964
964
  function Ji(s, t, e) {
965
965
  return s.virtualBlocksOverlapping(t, e).map((n) => `${n.id}:${n.kind}:${n.parentId}:${n.start - t}:${n.end - t}:${n.empty ? 1 : 0}:${n.placeholder ?? ""}:${JSON.stringify(n.chrome)}`).join(";");
966
966
  }
967
967
  function Zi(s, t, e, n) {
968
- return `t:${n}:${s.spacers.slice(e.start, e.end)}:${t.key(e.start, e.end)}:${Kn(s, e.start, e.end)}`;
968
+ return `t:${n}:${s.spacers.slice(e.start, e.end)}:${t.key(e.start, e.end)}:${Un(s, e.start, e.end)}`;
969
969
  }
970
970
  function hn(s) {
971
971
  return s.flatMap((t) => t.floats ?? []);
@@ -1055,56 +1055,56 @@ function ct(s, t = re, e, n = { x: Ce, y: Te }, i = 0) {
1055
1055
  f = Math.min(f, v), p = Math.max(p, S);
1056
1056
  };
1057
1057
  (!e || e.contentWidth !== t) && g(0, 1 / 0);
1058
- const y = new Ui(s.styles), b = new ji(s), B = Xi(s), R = /* @__PURE__ */ new Map();
1058
+ const y = new Ki(s.styles), b = new ji(s), B = Xi(s), R = /* @__PURE__ */ new Map();
1059
1059
  if (e)
1060
1060
  for (const v of [...e.paragraphs, ...e.tables]) {
1061
1061
  if (!v.hash) continue;
1062
1062
  let S = R.get(v.hash);
1063
1063
  S || R.set(v.hash, S = { byY: /* @__PURE__ */ new Map(), byStart: /* @__PURE__ */ new Map(), first: v }), S.byY.set(Math.round(v.y), v), S.byStart.set(v.start, v);
1064
1064
  }
1065
- const L = !!e && !e.consumed;
1065
+ const P = !!e && !e.consumed;
1066
1066
  e && (e.consumed = !0);
1067
- const E = /* @__PURE__ */ new Set(), w = (v) => !L || E.has(v) ? !1 : (E.add(v), !0), z = (v, S, A) => {
1068
- const x = R.get(v);
1069
- if (!x) return;
1067
+ const E = /* @__PURE__ */ new Set(), w = (v) => !P || E.has(v) ? !1 : (E.add(v), !0), z = (v, S, x) => {
1068
+ const A = R.get(v);
1069
+ if (!A) return;
1070
1070
  const V = Math.round(S);
1071
- return x.byY.get(V) ?? x.byY.get(V - 1) ?? x.byY.get(V + 1) ?? x.byStart.get(A) ?? x.first;
1071
+ return A.byY.get(V) ?? A.byY.get(V - 1) ?? A.byY.get(V + 1) ?? A.byStart.get(x) ?? A.first;
1072
1072
  };
1073
1073
  for (const v of W(s.spacers))
1074
1074
  if (v.kind === "paragraph") {
1075
- const S = b.at(v.start, v.end), A = Wn(h, S);
1075
+ const S = b.at(v.start, v.end), x = Wn(h, S);
1076
1076
  d = d.filter((D) => D.y + D.h > c + 0.5);
1077
- const x = d.map((D) => `${D.side}:${Math.round(D.w)}x${Math.round(Math.max(0, D.y + D.h - c))}`).join(","), V = Yi(s, y, v.start, v.end, t, A, x, b.key(v.start, v.end), B), H = z(V, c, v.start);
1077
+ const A = d.map((D) => `${D.side}:${Math.round(D.w)}x${Math.round(Math.max(0, D.y + D.h - c))}`).join(","), V = Yi(s, y, v.start, v.end, t, x, A, b.key(v.start, v.end), B), H = z(V, c, v.start);
1078
1078
  let nt;
1079
1079
  if (H && "lines" in H && H.hash === V) {
1080
1080
  const D = H.y, Ws = ke(H);
1081
1081
  nt = Re(H, c - D, v.start - H.start, w(H)), nt.hash = V, Ft.reused++, Math.abs(D - c) > 0.5 && g(Math.min(D, c), Math.max(Ws, ke(nt)));
1082
1082
  } else
1083
- nt = Gn(s, v.start, v.end, r, c, t, A, d, S), nt.hash = V, Ft.laidOut++, g(c, ke(nt));
1083
+ nt = Gn(s, v.start, v.end, r, c, t, x, d, S), nt.hash = V, Ft.laidOut++, g(c, ke(nt));
1084
1084
  for (const D of nt.floats ?? [])
1085
1085
  D.entity.float && d.push({ x: D.x, y: D.y, w: D.w, h: D.h, side: D.entity.float });
1086
1086
  a.push(nt), c += nt.h;
1087
1087
  } else {
1088
1088
  h.clear();
1089
- const S = Zi(s, y, v, t), A = z(S, c, v.start);
1090
- let x;
1091
- if (A && "cells" in A && A.hash === S) {
1092
- const V = A.y, H = A.h;
1093
- x = tr(A, c - V, v.start - A.start, w(A)), x.hash = S, Ft.reused++, Math.abs(V - c) > 0.5 && g(Math.min(V, c), Math.max(V + H, c + x.h));
1089
+ const S = Zi(s, y, v, t), x = z(S, c, v.start);
1090
+ let A;
1091
+ if (x && "cells" in x && x.hash === S) {
1092
+ const V = x.y, H = x.h;
1093
+ A = tr(x, c - V, v.start - x.start, w(x)), A.hash = S, Ft.reused++, Math.abs(V - c) > 0.5 && g(Math.min(V, c), Math.max(V + H, c + A.h));
1094
1094
  } else
1095
- x = _i(s, v, r, c, t, b), x.hash = S, Ft.laidOut++, g(c, c + x.h);
1096
- l.push(x), c += x.h + 12;
1095
+ A = _i(s, v, r, c, t, b), A.hash = S, Ft.laidOut++, g(c, c + A.h);
1096
+ l.push(A), c += A.h + 12;
1097
1097
  }
1098
1098
  if (e) {
1099
1099
  const v = new Map(hn(a).map((S) => [S.entity.id, S]));
1100
1100
  for (const S of hn(e.paragraphs)) {
1101
- const A = v.get(S.entity.id);
1102
- (!A || A.x !== S.x || A.y !== S.y || A.w !== S.w || A.h !== S.h) && g(S.y, S.y + S.h);
1101
+ const x = v.get(S.entity.id);
1102
+ (!x || x.x !== S.x || x.y !== S.y || x.w !== S.w || x.h !== S.h) && g(S.y, S.y + S.h);
1103
1103
  }
1104
1104
  }
1105
1105
  const M = c + n.y;
1106
1106
  e && Math.abs(e.height - M) > 0.5 && g(Math.min(e.height, M), Math.max(e.height, M));
1107
- const U = f < p ? {
1107
+ const K = f < p ? {
1108
1108
  top: Math.max(0, f),
1109
1109
  bottom: Number.isFinite(p) ? p : Math.max(M, (e == null ? void 0 : e.height) ?? 0)
1110
1110
  } : { top: 0, bottom: 0 }, J = [], q = [];
@@ -1116,10 +1116,10 @@ function ct(s, t = re, e, n = { x: Ce, y: Te }, i = 0) {
1116
1116
  }
1117
1117
  for (const v of l)
1118
1118
  for (const S of v.cells)
1119
- for (const A of S.paragraphs) {
1120
- J.push(...A.lines);
1121
- for (const x of A.lines)
1122
- x.images = we(s, x.images, i), q.push(...x.images);
1119
+ for (const x of S.paragraphs) {
1120
+ J.push(...x.lines);
1121
+ for (const A of x.lines)
1122
+ A.images = we(s, A.images, i), q.push(...A.images);
1123
1123
  }
1124
1124
  return {
1125
1125
  width: t + n.x * 2,
@@ -1131,7 +1131,7 @@ function ct(s, t = re, e, n = { x: Ce, y: Te }, i = 0) {
1131
1131
  tables: l,
1132
1132
  lines: J,
1133
1133
  images: q,
1134
- dirty: U
1134
+ dirty: K
1135
1135
  };
1136
1136
  }
1137
1137
  function we(s, t, e) {
@@ -1265,10 +1265,10 @@ function pn(s, t, e) {
1265
1265
  }
1266
1266
  return null;
1267
1267
  }
1268
- function Ut(s) {
1268
+ function qt(s) {
1269
1269
  return s.fill ?? "solid";
1270
1270
  }
1271
- function Un(s) {
1271
+ function Kn(s) {
1272
1272
  return `hsl(${s * 37 % 360} 80% 46%)`;
1273
1273
  }
1274
1274
  function rr(s) {
@@ -1276,12 +1276,12 @@ function rr(s) {
1276
1276
  return t[Math.floor(e)];
1277
1277
  }
1278
1278
  function qn(s, t) {
1279
- const e = Ut(s);
1279
+ const e = qt(s);
1280
1280
  return e === "rainbow" ? `-webkit-background-clip:text;background-clip:text;color:transparent;background-image:linear-gradient(90deg,#ff4d6d,#ffd166,#06d6a0,#4cc9f0,#ff4d6d);background-size:${Math.max(120, t)}px 100%;` : e === "sunset" ? "-webkit-background-clip:text;background-clip:text;color:transparent;background-image:linear-gradient(90deg,#ff4d6d,#ff8a4c,#ffd166);" : "";
1281
1281
  }
1282
1282
  function or(s, t, e = 0) {
1283
- const n = Ut(s);
1284
- return n === "rainbow" ? Un(t) : n === "sunset" ? rr(e) : s.color ?? "#1f2329";
1283
+ const n = qt(s);
1284
+ return n === "rainbow" ? Kn(t) : n === "sunset" ? rr(e) : s.color ?? "#1f2329";
1285
1285
  }
1286
1286
  function ar(s, t, e, n, i, r, o) {
1287
1287
  if (r === "none" || n <= 0) return;
@@ -1315,7 +1315,7 @@ function cr(s) {
1315
1315
  const t = [];
1316
1316
  let e = null;
1317
1317
  for (const n of s) {
1318
- const i = zt(n.style), r = !!n.style.strikethrough, o = n.style.fontSize ?? 16, a = Ut(n.style) === "solid" ? n.style.color ?? "#1f2329" : Un(n.index), l = n.y + n.h * 0.78;
1318
+ const i = Vt(n.style), r = !!n.style.strikethrough, o = n.style.fontSize ?? 16, a = qt(n.style) === "solid" ? n.style.color ?? "#1f2329" : Kn(n.index), l = n.y + n.h * 0.78;
1319
1319
  e && e.kind === i && e.strike === r && Math.abs(e.y - l) < 1 && Math.abs(e.x + e.w - n.x) < 0.6 ? e.w += n.w : (e && t.push(e), e = { x: n.x, y: l, w: n.w, size: o, kind: i, strike: r, color: a });
1320
1320
  }
1321
1321
  return e && t.push(e), t;
@@ -1377,8 +1377,8 @@ function pr(s) {
1377
1377
  const n = () => {
1378
1378
  if (!e) return;
1379
1379
  const i = document.createElement("span");
1380
- i.className = `mini-run${Ut(e.style) !== "solid" ? " is-fill" : ""}`, i.textContent = e.text, i.style.cssText = `left:${e.x}px;top:${e.y}px;height:${e.h}px;${mr(e.style, e.w)}`, t.appendChild(i);
1381
- const r = zt(e.style);
1380
+ i.className = `mini-run${qt(e.style) !== "solid" ? " is-fill" : ""}`, i.textContent = e.text, i.style.cssText = `left:${e.x}px;top:${e.y}px;height:${e.h}px;${mr(e.style, e.w)}`, t.appendChild(i);
1381
+ const r = Vt(e.style);
1382
1382
  if (r !== "none" || e.style.strikethrough) {
1383
1383
  const o = document.createElement("span");
1384
1384
  o.className = `mini-deco mini-deco-${r}${e.style.strikethrough ? " is-strike" : ""}`, o.style.cssText = `left:${e.x}px;top:${e.y}px;width:${e.w}px;height:${e.h}px;color:${e.style.color ?? "#1f2329"};`, t.appendChild(o);
@@ -1606,7 +1606,7 @@ const Mr = {
1606
1606
  function yn(s, t) {
1607
1607
  t.entity.src && s.src !== t.entity.src && (s.src = t.entity.src);
1608
1608
  }
1609
- const Ar = {
1609
+ const xr = {
1610
1610
  kind: "video",
1611
1611
  keepAspectRatio: !0,
1612
1612
  interactive: !0,
@@ -1626,10 +1626,10 @@ const Ar = {
1626
1626
  }
1627
1627
  };
1628
1628
  let de = null;
1629
- function xr(s) {
1629
+ function Ar(s) {
1630
1630
  de = s;
1631
1631
  }
1632
- const kn = { width: 120, height: 24 }, ue = /* @__PURE__ */ new WeakMap(), qt = /* @__PURE__ */ new Map();
1632
+ const kn = { width: 120, height: 24 }, ue = /* @__PURE__ */ new WeakMap(), jt = /* @__PURE__ */ new Map();
1633
1633
  function Qn(s, t, e, n) {
1634
1634
  const i = { id: t, width: e, height: n };
1635
1635
  queueMicrotask(
@@ -1647,7 +1647,7 @@ function Ir(s, t, e) {
1647
1647
  n.observe(s), e.ro = n;
1648
1648
  }
1649
1649
  function Cr(s) {
1650
- for (const t of qt.values())
1650
+ for (const t of jt.values())
1651
1651
  Tr(t, t.box.entity.id === s);
1652
1652
  }
1653
1653
  function Tr(s, t) {
@@ -1677,7 +1677,7 @@ function wn(s, t, e) {
1677
1677
  handle: n,
1678
1678
  box: e
1679
1679
  };
1680
- ue.set(s, i), qt.set(e.entity.id, i), Ir(t, e.entity.id, i);
1680
+ ue.set(s, i), jt.set(e.entity.id, i), Ir(t, e.entity.id, i);
1681
1681
  }
1682
1682
  const Rr = {
1683
1683
  kind: "hostSlot",
@@ -1697,7 +1697,7 @@ const Rr = {
1697
1697
  update(s, t) {
1698
1698
  const e = ue.get(s);
1699
1699
  if (e)
1700
- e.box = t, e.el = s, qt.set(t.entity.id, e), e.handle.update({
1700
+ e.box = t, e.el = s, jt.set(t.entity.id, e), e.handle.update({
1701
1701
  ..._e(s, t),
1702
1702
  selected: s.classList.contains("is-selected")
1703
1703
  });
@@ -1711,12 +1711,12 @@ const Rr = {
1711
1711
  };
1712
1712
  function Br(s, t) {
1713
1713
  var e, n, i;
1714
- return ((i = (e = qt.get(s)) == null ? void 0 : (n = e.handle).activate) == null ? void 0 : i.call(n, t)) === !0;
1714
+ return ((i = (e = jt.get(s)) == null ? void 0 : (n = e.handle).activate) == null ? void 0 : i.call(n, t)) === !0;
1715
1715
  }
1716
1716
  function da(s) {
1717
1717
  var e;
1718
1718
  const t = ue.get(s);
1719
- t && ((e = t.ro) == null || e.disconnect(), t.handle.destroy(), ue.delete(s), qt.delete(t.box.entity.id));
1719
+ t && ((e = t.ro) == null || e.disconnect(), t.handle.destroy(), ue.delete(s), jt.delete(t.box.entity.id));
1720
1720
  }
1721
1721
  const fe = /* @__PURE__ */ new Map();
1722
1722
  function vn(s) {
@@ -1743,38 +1743,38 @@ function ts(s, t, e, n) {
1743
1743
  for (const [a, l] of t)
1744
1744
  i.has(a) || ((o = (r = fe.get(l.dataset.kind ?? "")) == null ? void 0 : r.destroy) == null || o.call(r, l), l.remove(), t.delete(a));
1745
1745
  }
1746
- const Pr = [
1746
+ const Lr = [
1747
1747
  ni,
1748
- Ar,
1748
+ xr,
1749
1749
  ei,
1750
1750
  Mr,
1751
1751
  gr
1752
1752
  ];
1753
1753
  function es(s, t) {
1754
- return t ? { type: "insertSpacers", insertBeforeIndex: s, spacers: t } : P;
1754
+ return t ? { type: "insertSpacers", insertBeforeIndex: s, spacers: t } : L;
1755
1755
  }
1756
1756
  function ns(s, t) {
1757
- return t >= s ? { type: "deleteSpacers", startIndex: s, endIndex: t } : P;
1757
+ return t >= s ? { type: "deleteSpacers", startIndex: s, endIndex: t } : L;
1758
1758
  }
1759
- function K(s, t, e, n) {
1760
- return e >= t ? { type: "applyStyle", styleType: s, startIndex: t, endIndex: e, props: n } : P;
1759
+ function U(s, t, e, n) {
1760
+ return e >= t ? { type: "applyStyle", styleType: s, startIndex: t, endIndex: e, props: n } : L;
1761
1761
  }
1762
1762
  function Ge(s) {
1763
1763
  return { type: "addEntity", entity: s };
1764
1764
  }
1765
- function Pe(s, t) {
1765
+ function Le(s, t) {
1766
1766
  return { type: "updateEntity", entityId: s, props: t };
1767
1767
  }
1768
1768
  function ss(s) {
1769
1769
  return { type: "deleteEntity", entityId: s };
1770
1770
  }
1771
- function Le(s) {
1771
+ function Pe(s) {
1772
1772
  return { type: "addFragment", fragment: s };
1773
1773
  }
1774
- function Lr(s) {
1774
+ function Pr(s) {
1775
1775
  return { type: "deleteFragment", fragmentId: s };
1776
1776
  }
1777
- function Nt(s) {
1777
+ function Ht(s) {
1778
1778
  return { type: "addVirtualBlock", block: s };
1779
1779
  }
1780
1780
  function is(s) {
@@ -1783,15 +1783,15 @@ function is(s) {
1783
1783
  function Et(s, t) {
1784
1784
  return { type: "updateVirtualBlock", blockId: s, block: { ...t, id: s } };
1785
1785
  }
1786
- const P = { type: "null" };
1786
+ const L = { type: "null" };
1787
1787
  function ge(s, t) {
1788
- return t.type === "null" ? P : t.type === "multi" ? mt(Z(t).map((e) => ge(s, e))) : { type: "scoped", fragmentId: s, inner: t };
1788
+ return t.type === "null" ? L : t.type === "multi" ? mt(Z(t).map((e) => ge(s, e))) : { type: "scoped", fragmentId: s, inner: t };
1789
1789
  }
1790
1790
  function mt(s) {
1791
1791
  const t = [];
1792
1792
  for (const e of s)
1793
1793
  e.type !== "null" && (e.type === "multi" ? t.push(...Z(e)) : t.push(e));
1794
- return t.length === 0 ? P : t.length === 1 ? t[0] : { type: "multi", commands: t };
1794
+ return t.length === 0 ? L : t.length === 1 ? t[0] : { type: "multi", commands: t };
1795
1795
  }
1796
1796
  function Z(s) {
1797
1797
  if (s.type === "null") return [];
@@ -1859,10 +1859,10 @@ function Q(s) {
1859
1859
  return {
1860
1860
  id: s.id,
1861
1861
  title: s.title,
1862
- slice: _t(s.slice)
1862
+ slice: Gt(s.slice)
1863
1863
  };
1864
1864
  }
1865
- function _t(s) {
1865
+ function Gt(s) {
1866
1866
  var t, e;
1867
1867
  return {
1868
1868
  text: s.text,
@@ -1895,13 +1895,13 @@ function bn(s, t, e) {
1895
1895
  const n = [];
1896
1896
  for (const i of Nr) {
1897
1897
  const r = s.styleSpansOver(i, t, e);
1898
- n.push(K(i, t, e - 1, null));
1899
- for (const o of r) n.push(K(i, o.start, o.end - 1, o.props));
1898
+ n.push(U(i, t, e - 1, null));
1899
+ for (const o of r) n.push(U(i, o.start, o.end - 1, o.props));
1900
1900
  }
1901
1901
  return n;
1902
1902
  }
1903
1903
  const Hr = {
1904
- null: () => P,
1904
+ null: () => L,
1905
1905
  multi: () => {
1906
1906
  throw new Error("组合操作要用 applyAndInvert 逐条交错求逆,不能整体求逆");
1907
1907
  },
@@ -1912,7 +1912,7 @@ const Hr = {
1912
1912
  // 只管字符与样式。落在这段里的实体由 Operation 层显式发 deleteEntity,
1913
1913
  // 它们的逆(addEntity)自然排在这条前面,不需要在这里兜底。
1914
1914
  deleteSpacers: (s, t) => {
1915
- const e = t.startIndex, n = t.endIndex + 1, i = s.virtualBlocksOverlapping(e, n).map((r) => Nt(I(r)));
1915
+ const e = t.startIndex, n = t.endIndex + 1, i = s.virtualBlocksOverlapping(e, n).map((r) => Ht(I(r)));
1916
1916
  return mt([
1917
1917
  es(e, s.spacers.slice(e, n)),
1918
1918
  ...bn(s, e, n),
@@ -1924,39 +1924,39 @@ const Hr = {
1924
1924
  (e) => e.type === "applyStyle" && e.styleType === t.styleType
1925
1925
  )
1926
1926
  ),
1927
- addEntity: (s, t) => s.entities.has(t.entity.id) ? Pe(t.entity.id, $(s.entities.get(t.entity.id))) : ss(t.entity.id),
1927
+ addEntity: (s, t) => s.entities.has(t.entity.id) ? Le(t.entity.id, $(s.entities.get(t.entity.id))) : ss(t.entity.id),
1928
1928
  updateEntity: (s, t) => {
1929
1929
  const e = s.entities.get(t.entityId);
1930
- if (!e) return P;
1930
+ if (!e) return L;
1931
1931
  const n = {};
1932
1932
  for (const i of Object.keys(t.props))
1933
1933
  n[i] = e[i];
1934
- return Pe(t.entityId, n);
1934
+ return Le(t.entityId, n);
1935
1935
  },
1936
1936
  deleteEntity: (s, t) => {
1937
1937
  const e = s.entities.get(t.entityId);
1938
- return e ? Ge($(e)) : P;
1938
+ return e ? Ge($(e)) : L;
1939
1939
  },
1940
1940
  // 覆盖已有 id 时,逆是把旧 fragment 加回来;否则逆是删掉它。
1941
1941
  addFragment: (s, t) => {
1942
1942
  const e = s.fragments.get(t.fragment.id);
1943
- return e ? Le(Q(e)) : Lr(t.fragment.id);
1943
+ return e ? Pe(Q(e)) : Pr(t.fragment.id);
1944
1944
  },
1945
1945
  deleteFragment: (s, t) => {
1946
1946
  const e = s.fragments.get(t.fragmentId);
1947
- return e ? Le(Q(e)) : P;
1947
+ return e ? Pe(Q(e)) : L;
1948
1948
  },
1949
1949
  addVirtualBlock: (s, t) => {
1950
1950
  const e = s.blockById(t.block.id);
1951
- return e ? Nt(e) : is(t.block.id);
1951
+ return e ? Ht(e) : is(t.block.id);
1952
1952
  },
1953
1953
  updateVirtualBlock: (s, t) => {
1954
1954
  const e = s.blockById(t.blockId);
1955
- return e ? Et(t.blockId, e) : P;
1955
+ return e ? Et(t.blockId, e) : L;
1956
1956
  },
1957
1957
  deleteVirtualBlock: (s, t) => {
1958
1958
  const e = s.blockById(t.blockId);
1959
- return e ? Nt(e) : P;
1959
+ return e ? Ht(e) : L;
1960
1960
  },
1961
1961
  // 在片段自己的模型上求逆,再包回同一个片段
1962
1962
  scoped: (s, t) => ge(
@@ -1976,16 +1976,16 @@ function zr(s, t) {
1976
1976
  function as(s, t) {
1977
1977
  return !s || !t ? s === t : s.min === t.min && s.max === t.max;
1978
1978
  }
1979
- function Pt(s, t, e) {
1979
+ function Lt(s, t, e) {
1980
1980
  return s >= t ? s + e : s;
1981
1981
  }
1982
1982
  function Vr(s, t, e) {
1983
- return s === t ? s : Pt(s, t, e);
1983
+ return s === t ? s : Lt(s, t, e);
1984
1984
  }
1985
1985
  function ls(s, t, e) {
1986
1986
  return s ? gt(
1987
- Pt(s.min, t, e),
1988
- Pt(s.max, t, e)
1987
+ Lt(s.min, t, e),
1988
+ Lt(s.max, t, e)
1989
1989
  ) : null;
1990
1990
  }
1991
1991
  function _r(s, t) {
@@ -2003,19 +2003,19 @@ function cs(s, t) {
2003
2003
  function Gr(s, t, e) {
2004
2004
  return t.insertBeforeIndex === s.insertBeforeIndex && e ? s : {
2005
2005
  ...s,
2006
- insertBeforeIndex: Pt(s.insertBeforeIndex, t.insertBeforeIndex, t.spacers.length)
2006
+ insertBeforeIndex: Lt(s.insertBeforeIndex, t.insertBeforeIndex, t.spacers.length)
2007
2007
  };
2008
2008
  }
2009
2009
  function Wr(s, t) {
2010
2010
  if (t.startIndex < s.insertBeforeIndex && t.endIndex >= s.insertBeforeIndex)
2011
- return P;
2011
+ return L;
2012
2012
  const e = t.endIndex - t.startIndex + 1;
2013
2013
  return {
2014
2014
  ...s,
2015
- insertBeforeIndex: Pt(s.insertBeforeIndex, t.startIndex + 1, -e)
2015
+ insertBeforeIndex: Lt(s.insertBeforeIndex, t.startIndex + 1, -e)
2016
2016
  };
2017
2017
  }
2018
- function Kr(s, t) {
2018
+ function Ur(s, t) {
2019
2019
  const e = ls(
2020
2020
  gt(s.startIndex, s.endIndex),
2021
2021
  t.insertBeforeIndex,
@@ -2023,7 +2023,7 @@ function Kr(s, t) {
2023
2023
  );
2024
2024
  return hs(s, e);
2025
2025
  }
2026
- function Ur(s, t) {
2026
+ function Kr(s, t) {
2027
2027
  const e = cs(gt(s.startIndex, s.endIndex), {
2028
2028
  min: t.startIndex,
2029
2029
  max: t.endIndex
@@ -2031,7 +2031,7 @@ function Ur(s, t) {
2031
2031
  return hs(s, e);
2032
2032
  }
2033
2033
  function hs(s, t) {
2034
- return t ? as(t, gt(s.startIndex, s.endIndex)) ? s : { ...s, startIndex: t.min, endIndex: t.max } : P;
2034
+ return t ? as(t, gt(s.startIndex, s.endIndex)) ? s : { ...s, startIndex: t.min, endIndex: t.max } : L;
2035
2035
  }
2036
2036
  function qr(s, t) {
2037
2037
  const e = ls(
@@ -2049,13 +2049,13 @@ function jr(s, t) {
2049
2049
  return ds(s, e);
2050
2050
  }
2051
2051
  function ds(s, t) {
2052
- return t ? as(t, gt(s.startIndex, s.endIndex)) ? s : { ...s, startIndex: t.min, endIndex: t.max } : P;
2052
+ return t ? as(t, gt(s.startIndex, s.endIndex)) ? s : { ...s, startIndex: t.min, endIndex: t.max } : L;
2053
2053
  }
2054
2054
  const Xr = {
2055
2055
  null: (s) => s,
2056
- multi: (s, t, e) => mt(Z(s).map((n) => Gt(n, t, e))),
2056
+ multi: (s, t, e) => mt(Z(s).map((n) => Wt(n, t, e))),
2057
2057
  insertSpacers: (s, t, e) => t.type === "insertSpacers" ? Gr(s, t, e) : t.type === "deleteSpacers" ? Wr(s, t) : s,
2058
- deleteSpacers: (s, t) => t.type === "insertSpacers" ? Kr(s, t) : t.type === "deleteSpacers" ? Ur(s, t) : s,
2058
+ deleteSpacers: (s, t) => t.type === "insertSpacers" ? Ur(s, t) : t.type === "deleteSpacers" ? Kr(s, t) : s,
2059
2059
  applyStyle: (s, t) => t.type === "insertSpacers" ? qr(s, t) : t.type === "deleteSpacers" ? jr(s, t) : s,
2060
2060
  // 实体操作按 id 寻址,不受下标变化影响
2061
2061
  addEntity: (s) => s,
@@ -2066,44 +2066,44 @@ const Xr = {
2066
2066
  deleteFragment: (s) => s,
2067
2067
  addVirtualBlock: (s, t, e) => {
2068
2068
  if (t.type === "insertSpacers") {
2069
- const [n] = Ae(
2069
+ const [n] = xe(
2070
2070
  [s.block],
2071
2071
  t.insertBeforeIndex,
2072
2072
  t.spacers.length
2073
2073
  );
2074
- return n ? { ...s, block: n } : P;
2074
+ return n ? { ...s, block: n } : L;
2075
2075
  }
2076
2076
  if (t.type === "deleteSpacers") {
2077
- const n = xe([s.block], t.startIndex, t.endIndex + 1);
2078
- return n[0] ? { ...s, block: n[0] } : P;
2077
+ const n = Ae([s.block], t.startIndex, t.endIndex + 1);
2078
+ return n[0] ? { ...s, block: n[0] } : L;
2079
2079
  }
2080
2080
  return t.type === "addVirtualBlock" && t.block.id === s.block.id ? e ? s : t : t.type === "deleteVirtualBlock" && t.blockId === s.block.id ? s : t.type === "updateVirtualBlock" && t.blockId === s.block.id ? e ? s : { type: "addVirtualBlock", block: t.block } : s;
2081
2081
  },
2082
2082
  updateVirtualBlock: (s, t, e) => {
2083
2083
  if (t.type === "insertSpacers") {
2084
- const [n] = Ae(
2084
+ const [n] = xe(
2085
2085
  [s.block],
2086
2086
  t.insertBeforeIndex,
2087
2087
  t.spacers.length
2088
2088
  );
2089
- return n ? { ...s, block: n } : P;
2089
+ return n ? { ...s, block: n } : L;
2090
2090
  }
2091
2091
  if (t.type === "deleteSpacers") {
2092
- const n = xe([s.block], t.startIndex, t.endIndex + 1);
2093
- return n[0] ? { ...s, blockId: s.blockId, block: n[0] } : P;
2092
+ const n = Ae([s.block], t.startIndex, t.endIndex + 1);
2093
+ return n[0] ? { ...s, blockId: s.blockId, block: n[0] } : L;
2094
2094
  }
2095
- return t.type === "deleteVirtualBlock" && t.blockId === s.blockId ? P : t.type === "updateVirtualBlock" && t.blockId === s.blockId ? e ? s : t : t.type === "addVirtualBlock" && t.block.id === s.blockId ? e ? s : { ...s, block: t.block } : s;
2095
+ return t.type === "deleteVirtualBlock" && t.blockId === s.blockId ? L : t.type === "updateVirtualBlock" && t.blockId === s.blockId ? e ? s : t : t.type === "addVirtualBlock" && t.block.id === s.blockId ? e ? s : { ...s, block: t.block } : s;
2096
2096
  },
2097
- deleteVirtualBlock: (s, t) => t.type === "deleteVirtualBlock" && t.blockId === s.blockId ? P : s,
2097
+ deleteVirtualBlock: (s, t) => t.type === "deleteVirtualBlock" && t.blockId === s.blockId ? L : s,
2098
2098
  // 每个片段是独立的坐标空间。同一片段就往里递归,不同片段(或主文档的操作)
2099
2099
  // 天然不冲突,原样放行 —— 这是 scoped 这个设计最省事的地方。
2100
- scoped: (s, t, e) => t.type !== "scoped" || t.fragmentId !== s.fragmentId ? s : ge(s.fragmentId, Gt(s.inner, t.inner, e))
2100
+ scoped: (s, t, e) => t.type !== "scoped" || t.fragmentId !== s.fragmentId ? s : ge(s.fragmentId, Wt(s.inner, t.inner, e))
2101
2101
  };
2102
- function Gt(s, t, e) {
2102
+ function Wt(s, t, e) {
2103
2103
  if (s.type === "null" || t.type === "null") return s;
2104
2104
  if (t.type === "multi") {
2105
2105
  let n = s;
2106
- for (const i of Z(t)) n = Gt(n, i, e);
2106
+ for (const i of Z(t)) n = Wt(n, i, e);
2107
2107
  return n;
2108
2108
  }
2109
2109
  return Xr[s.type](s, t, e);
@@ -2114,7 +2114,7 @@ function yt(s, t, e = !0) {
2114
2114
  let o = s[r];
2115
2115
  for (let a = 0; a < n.length; a++) {
2116
2116
  const l = o;
2117
- o = Gt(l, n[a], e), n[a] = Gt(n[a], l, !e);
2117
+ o = Wt(l, n[a], e), n[a] = Wt(n[a], l, !e);
2118
2118
  }
2119
2119
  i.push(o);
2120
2120
  }
@@ -2123,10 +2123,10 @@ function yt(s, t, e = !0) {
2123
2123
  function De(s, t, e = !1) {
2124
2124
  let n = s;
2125
2125
  for (const i of t)
2126
- i.type === "insertSpacers" ? n = e ? Pt(n, i.insertBeforeIndex, i.spacers.length) : Vr(n, i.insertBeforeIndex, i.spacers.length) : i.type === "deleteSpacers" ? n = $e(n, { min: i.startIndex, max: i.endIndex }) : i.type === "multi" && (n = De(n, Z(i), e));
2126
+ i.type === "insertSpacers" ? n = e ? Lt(n, i.insertBeforeIndex, i.spacers.length) : Vr(n, i.insertBeforeIndex, i.spacers.length) : i.type === "deleteSpacers" ? n = $e(n, { min: i.startIndex, max: i.endIndex }) : i.type === "multi" && (n = De(n, Z(i), e));
2127
2127
  return n;
2128
2128
  }
2129
- function Qt(s, t, e = !1) {
2129
+ function te(s, t, e = !1) {
2130
2130
  const n = t.flatMap((i) => Z(i));
2131
2131
  return {
2132
2132
  anchor: De(s.anchor, n, e),
@@ -2224,7 +2224,7 @@ function We(s, t, e) {
2224
2224
  result: i
2225
2225
  };
2226
2226
  }
2227
- function Ke(s, t) {
2227
+ function Ue(s, t) {
2228
2228
  return s.textPropsAt(t);
2229
2229
  }
2230
2230
  function St(s, t) {
@@ -2316,14 +2316,14 @@ function O(s, t, e) {
2316
2316
  return s.emit(ns(n, i - 1)), r;
2317
2317
  }
2318
2318
  function rt(s, t, e, n, i) {
2319
- n <= e || s.emit(K(t, e, n - 1, i));
2319
+ n <= e || s.emit(U(t, e, n - 1, i));
2320
2320
  }
2321
2321
  function Dt(s, t, e, n) {
2322
2322
  const i = s.doc.clamp(Math.min(t, e)), r = s.doc.clamp(Math.max(t, e));
2323
2323
  if (i >= r) return;
2324
2324
  const o = [];
2325
2325
  for (const a of ms(s.doc, i, r))
2326
- a.existing ? o.push(K("text", a.start, a.end - 1, { ...a.existing.props, ...n })) : fs(s.doc, a.start, a.end) || o.push(K("text", a.start, a.end - 1, { ...n }));
2326
+ a.existing ? o.push(U("text", a.start, a.end - 1, { ...a.existing.props, ...n })) : fs(s.doc, a.start, a.end) || o.push(U("text", a.start, a.end - 1, { ...n }));
2327
2327
  s.emit(mt(o));
2328
2328
  }
2329
2329
  function T(s) {
@@ -2343,9 +2343,9 @@ function T(s) {
2343
2343
  p.start < c && p.end > l && (p.start < l && (l = p.start, f = !0), p.end > c && (c = p.end, f = !0));
2344
2344
  if (!f) break;
2345
2345
  }
2346
- const h = [K("paragraph", l, c - 1, null)];
2346
+ const h = [U("paragraph", l, c - 1, null)];
2347
2347
  for (const d of e)
2348
- d.end <= l || d.start >= c || h.push(K("paragraph", d.start, d.end - 1, d.props));
2348
+ d.end <= l || d.start >= c || h.push(U("paragraph", d.start, d.end - 1, d.props));
2349
2349
  s.emit(mt(h));
2350
2350
  }
2351
2351
  function oo(s, t) {
@@ -2361,7 +2361,7 @@ function oo(s, t) {
2361
2361
  function ys(s, t) {
2362
2362
  t < s.doc.spacers.length || G(s, t, m.PARAGRAPH);
2363
2363
  }
2364
- function Ue(s, t, e) {
2364
+ function Ke(s, t, e) {
2365
2365
  return (n) => {
2366
2366
  Dt(n, s, t, e);
2367
2367
  };
@@ -2484,12 +2484,12 @@ class ws {
2484
2484
  applyInsertSpacers(t, e) {
2485
2485
  if (!e) return;
2486
2486
  const n = this.clamp(t);
2487
- this.spacers = this.spacers.slice(0, n) + e + this.spacers.slice(n), this.styles = go(this.styles, n, e.length), this.replaceVirtualBlocks(Ae(this.virtualBlocks.values(), n, e.length));
2487
+ this.spacers = this.spacers.slice(0, n) + e + this.spacers.slice(n), this.styles = go(this.styles, n, e.length), this.replaceVirtualBlocks(xe(this.virtualBlocks.values(), n, e.length));
2488
2488
  }
2489
2489
  /** deleteSpacers 的落地(半开区间):删字符,样式区间跟着裁剪与前挪。 */
2490
2490
  applyDeleteSpacers(t, e) {
2491
2491
  const n = this.clamp(Math.min(t, e)), i = this.clamp(Math.max(t, e));
2492
- i <= n || (this.spacers = this.spacers.slice(0, n) + this.spacers.slice(i), this.styles = yo(this.styles, n, i), this.replaceVirtualBlocks(xe(this.virtualBlocks.values(), n, i)));
2492
+ i <= n || (this.spacers = this.spacers.slice(0, n) + this.spacers.slice(i), this.styles = yo(this.styles, n, i), this.replaceVirtualBlocks(Ae(this.virtualBlocks.values(), n, i)));
2493
2493
  }
2494
2494
  /** addVirtualBlock 的落地:同 id 则整体替换。 */
2495
2495
  applyAddVirtualBlock(t) {
@@ -2644,7 +2644,7 @@ class ws {
2644
2644
  }
2645
2645
  // ---- 虚拟块 ------------------------------------------------------------
2646
2646
  listVirtualBlocks() {
2647
- return xt([...this.virtualBlocks.values()], this.virtualBlocks);
2647
+ return At([...this.virtualBlocks.values()], this.virtualBlocks);
2648
2648
  }
2649
2649
  blockById(t) {
2650
2650
  const e = this.virtualBlocks.get(t);
@@ -2653,7 +2653,7 @@ class ws {
2653
2653
  /** 覆盖下标 i 的虚拟块,外层在前。 */
2654
2654
  blocksAt(t) {
2655
2655
  const e = this.clamp(t), n = [...this.virtualBlocks.values()].filter((i) => i.start <= e && e < i.end);
2656
- return xt(n, this.virtualBlocks).map(I);
2656
+ return At(n, this.virtualBlocks).map(I);
2657
2657
  }
2658
2658
  virtualBlocksOverlapping(t, e) {
2659
2659
  const n = this.clamp(Math.min(t, e)), i = this.clamp(Math.max(t, e));
@@ -2671,7 +2671,7 @@ class ws {
2671
2671
  if (n) return n;
2672
2672
  const i = [...this.virtualBlocks.values()].filter((o) => o.kind === "virtualSlot" && o.end === e);
2673
2673
  if (!i.length) return null;
2674
- const r = xt(i, this.virtualBlocks);
2674
+ const r = At(i, this.virtualBlocks);
2675
2675
  return I(r[r.length - 1]);
2676
2676
  }
2677
2677
  replaceVirtualBlocks(t) {
@@ -2773,7 +2773,7 @@ function ko(s, t) {
2773
2773
  }
2774
2774
  return i.endsWith(m.PARAGRAPH) || (i += m.PARAGRAPH), { text: i, styles: r, entities: o };
2775
2775
  }
2776
- function Lt(s, t) {
2776
+ function Pt(s, t) {
2777
2777
  return (e) => {
2778
2778
  const n = e.doc.clamp(s), i = $({
2779
2779
  ...t,
@@ -2789,7 +2789,7 @@ function j(s, t) {
2789
2789
  const n = {};
2790
2790
  for (const [i, r] of Object.entries(t))
2791
2791
  r !== void 0 && (n[i] = r);
2792
- Object.keys(n).length && e.emit(Pe(s, n));
2792
+ Object.keys(n).length && e.emit(Le(s, n));
2793
2793
  };
2794
2794
  }
2795
2795
  function je(s) {
@@ -2836,7 +2836,7 @@ function Xe(s) {
2836
2836
  empty: l
2837
2837
  };
2838
2838
  if (Ss(e, c)) return null;
2839
- t.emit(Nt(c));
2839
+ t.emit(Ht(c));
2840
2840
  for (const d of [...e.virtualBlocks.values()])
2841
2841
  d.id === r || d.kind === "mark" || c.kind === "mark" || d.parentId === o && Bt(c, d) && d.id !== r && t.emit(Et(d.id, { ...d, parentId: r }));
2842
2842
  return r;
@@ -2865,7 +2865,7 @@ function Ms(s, t, e, n, i, r) {
2865
2865
  ...l,
2866
2866
  start: Math.min(l.start, n),
2867
2867
  end: Math.max(l.end, i)
2868
- } : c = { ...o, start: n, end: i }, l ? s.emit(Et(o.id, c)) : s.emit(Nt(c));
2868
+ } : c = { ...o, start: n, end: i }, l ? s.emit(Et(o.id, c)) : s.emit(Ht(c));
2869
2869
  }
2870
2870
  }
2871
2871
  function kt(s) {
@@ -2878,7 +2878,7 @@ function kt(s) {
2878
2878
  return O(t, i, r), G(t, i, n), Ms(t, o, s, i, i + n.length, !0), !0;
2879
2879
  };
2880
2880
  }
2881
- function Wt(s) {
2881
+ function Ut(s) {
2882
2882
  return s.replace(/\r\n/g, `
2883
2883
  `).replace(/\r/g, `
2884
2884
  `).replace(/\n+$/, "").replace(/\n+/g, " ");
@@ -2887,13 +2887,13 @@ function dt(s, t, e) {
2887
2887
  return (n) => {
2888
2888
  const i = n.doc.blockById(s);
2889
2889
  if (!i || i.kind !== "virtualSlot") return null;
2890
- const r = Wt(t), o = i.start, a = i.end, l = Dn(i, je(n.doc)), c = e ?? {
2891
- ...Ke(n.doc, o),
2890
+ const r = Ut(t), o = i.start, a = i.end, l = Dn(i, je(n.doc)), c = e ?? {
2891
+ ...Ue(n.doc, o),
2892
2892
  ...mi(i.chrome)
2893
2893
  };
2894
2894
  O(n, o, a), r && G(n, o, r);
2895
2895
  const h = o + r.length, d = r.length === 0 || r === (i.placeholder ?? "");
2896
- return Ms(n, l, s, o, h, d && !!i.placeholder), r && c && Ln(c) && Dt(n, o, h, c), h;
2896
+ return Ms(n, l, s, o, h, d && !!i.placeholder), r && c && Pn(c) && Dt(n, o, h, c), h;
2897
2897
  };
2898
2898
  }
2899
2899
  function Ye(s, t, e) {
@@ -2906,13 +2906,13 @@ function Ye(s, t, e) {
2906
2906
  const a = new Set(r);
2907
2907
  for (; o && !a.has(o); )
2908
2908
  a.add(o), r.push(o), o = ((l = n.doc.blockById(o)) == null ? void 0 : l.parentId) ?? null;
2909
- As(r, t, e)(n);
2909
+ xs(r, t, e)(n);
2910
2910
  };
2911
2911
  }
2912
- function As(s, t, e) {
2912
+ function xs(s, t, e) {
2913
2913
  return (n) => {
2914
2914
  const r = [...new Set(s)].map((o) => n.doc.blockById(o)).filter((o) => !!o);
2915
- for (const o of xt(r, je(n.doc))) {
2915
+ for (const o of At(r, je(n.doc))) {
2916
2916
  const a = {
2917
2917
  ...o,
2918
2918
  start: Math.min(o.start, t),
@@ -2938,9 +2938,9 @@ function vo(s, t, e) {
2938
2938
  end: r.end + t,
2939
2939
  chrome: { ...r.chrome }
2940
2940
  }));
2941
- return xt(i, new Map(i.map((r) => [r.id, r])));
2941
+ return At(i, new Map(i.map((r) => [r.id, r])));
2942
2942
  }
2943
- function xs(s, t) {
2943
+ function As(s, t) {
2944
2944
  return (e) => {
2945
2945
  if (!t || t.startsWith(`
2946
2946
  `)) return;
@@ -2970,9 +2970,9 @@ function bo(s, t, e) {
2970
2970
  const o = St(s.doc, r.start);
2971
2971
  s.emit(
2972
2972
  mt([
2973
- K("paragraph", r.start, r.end - 1, null),
2974
- K("paragraph", r.start, n, { ...o }),
2975
- K("paragraph", n + 1, r.end - 1, { ...o })
2973
+ U("paragraph", r.start, r.end - 1, null),
2974
+ U("paragraph", r.start, n, { ...o }),
2975
+ U("paragraph", n + 1, r.end - 1, { ...o })
2976
2976
  ])
2977
2977
  );
2978
2978
  }
@@ -2980,7 +2980,7 @@ function bo(s, t, e) {
2980
2980
  n += i.length;
2981
2981
  }
2982
2982
  }
2983
- function Ht(s, t, e) {
2983
+ function zt(s, t, e) {
2984
2984
  return (n) => {
2985
2985
  if (!t) return n.doc.clamp(s);
2986
2986
  const i = t.replace(/\r\n/g, `
@@ -2988,8 +2988,8 @@ function Ht(s, t, e) {
2988
2988
  `), r = n.doc.clamp(s), o = n.doc.slotAtCaret(r);
2989
2989
  if (o != null && o.empty)
2990
2990
  return dt(o.id, i, e)(n) ?? r;
2991
- const a = e ?? Ke(n.doc, r);
2992
- if (G(n, r, i), xs(r, i)(n), bo(n, r, i), a && Ln(a))
2991
+ const a = e ?? Ue(n.doc, r);
2992
+ if (G(n, r, i), As(r, i)(n), bo(n, r, i), a && Pn(a))
2993
2993
  for (const [l, c] of ps(i, r)) Dt(n, l, c, a);
2994
2994
  return o && Ye(o.id, r, r + i.length)(n), T(n), r + i.length;
2995
2995
  };
@@ -3009,16 +3009,16 @@ function Tt(s) {
3009
3009
  const f = { ...r }, p = { ...r }, g = r.heading ?? 0;
3010
3010
  g && !o && c && (p.heading = 0), g && !o && l && (f.heading = 0), d && (p.groupId = ""), t.emit(
3011
3011
  mt([
3012
- K("paragraph", i.start, i.end, null),
3013
- K("paragraph", i.start, e, f),
3014
- K("paragraph", e + 1, i.end, p)
3012
+ U("paragraph", i.start, i.end, null),
3013
+ U("paragraph", i.start, e, f),
3014
+ U("paragraph", e + 1, i.end, p)
3015
3015
  ])
3016
3016
  );
3017
3017
  }
3018
3018
  return T(t), e + 1;
3019
3019
  };
3020
3020
  }
3021
- function At(s, t) {
3021
+ function xt(s, t) {
3022
3022
  return (e) => {
3023
3023
  const n = di(
3024
3024
  e.doc.spacers,
@@ -3081,7 +3081,7 @@ function Rs(s) {
3081
3081
  if (r.kind === "list")
3082
3082
  return St(e, i.start).list === r.list ? n : o(r.consume, { list: r.list, heading: 0 });
3083
3083
  if (r.kind === "code-block")
3084
- return O(t, i.start, i.start + r.consume), T(t), Lt(i.start, {
3084
+ return O(t, i.start, i.start + r.consume), T(t), Pt(i.start, {
3085
3085
  kind: "code",
3086
3086
  width: 680,
3087
3087
  height: 80,
@@ -3090,7 +3090,7 @@ function Rs(s) {
3090
3090
  })(t);
3091
3091
  if (r.kind === "formula") {
3092
3092
  const l = i.start + r.matchStart;
3093
- return O(t, l, i.start + r.matchEnd), T(t), Lt(l, {
3093
+ return O(t, l, i.start + r.matchEnd), T(t), Pt(l, {
3094
3094
  kind: "formula",
3095
3095
  width: 200,
3096
3096
  height: 48,
@@ -3099,7 +3099,7 @@ function Rs(s) {
3099
3099
  })(t);
3100
3100
  }
3101
3101
  const a = i.start + r.matchStart;
3102
- return O(t, a, i.start + r.matchEnd), T(t), G(t, a, `${r.inner} `), r.inner && Ue(a, a + r.inner.length, r.style)(t), T(t), a + r.inner.length + 1;
3102
+ return O(t, a, i.start + r.matchEnd), T(t), G(t, a, `${r.inner} `), r.inner && Ke(a, a + r.inner.length, r.style)(t), T(t), a + r.inner.length + 1;
3103
3103
  };
3104
3104
  }
3105
3105
  function Je(s, t, e) {
@@ -3131,7 +3131,7 @@ function Oe(s) {
3131
3131
  return G(t, e.table.rows[e.row].end, i), T(t), !0;
3132
3132
  };
3133
3133
  }
3134
- function Ps(s) {
3134
+ function Ls(s) {
3135
3135
  return (t) => {
3136
3136
  var r;
3137
3137
  const e = Y(t.doc.spacers, s);
@@ -3148,7 +3148,7 @@ function Ps(s) {
3148
3148
  return T(t), !0;
3149
3149
  };
3150
3150
  }
3151
- function Ls(s) {
3151
+ function Ps(s) {
3152
3152
  return (t) => {
3153
3153
  const e = Y(t.doc.spacers, s);
3154
3154
  if (!e || e.table.rows.length <= 1) return !1;
@@ -3199,7 +3199,7 @@ function Mo(s) {
3199
3199
  i.index > n && t.push({ text: s.slice(n, i.index), style: {} }), i[2] !== void 0 ? t.push({ text: i[2], style: { bold: !0, italic: !0 } }) : i[3] !== void 0 ? t.push({ text: i[3], style: { bold: !0 } }) : i[4] !== void 0 ? t.push({ text: i[4], style: { italic: !0 } }) : i[5] !== void 0 ? t.push({ text: i[5], style: { strikethrough: !0 } }) : i[6] !== void 0 ? t.push({ text: i[6], style: { underline: !0 } }) : i[7] !== void 0 && t.push({ text: i[7], style: { color: He, underline: !0 }, url: i[8] }), n = i.index + i[0].length;
3200
3200
  return n < s.length && t.push({ text: s.slice(n), style: {} }), t.filter((r) => r.text.length > 0);
3201
3201
  }
3202
- function Ao(s) {
3202
+ function xo(s) {
3203
3203
  const t = s.match(/^(#{1,3})\s+(.*)$/);
3204
3204
  if (t)
3205
3205
  return { rest: t[2], para: { ...N, heading: t[1].length } };
@@ -3215,14 +3215,14 @@ function Ao(s) {
3215
3215
  }
3216
3216
  return { rest: s, para: { ...N } };
3217
3217
  }
3218
- function xo(s) {
3218
+ function Ao(s) {
3219
3219
  const e = s.replace(/\r\n/g, `
3220
3220
  `).replace(/\r/g, `
3221
3221
  `).split(`
3222
3222
  `);
3223
3223
  let n = "";
3224
3224
  const i = [], r = [], o = (c) => {
3225
- const { rest: h, para: d } = Ao(c), f = n.length, p = Mo(h);
3225
+ const { rest: h, para: d } = xo(c), f = n.length, p = Mo(h);
3226
3226
  for (const g of p) {
3227
3227
  const y = n.length;
3228
3228
  n += g.text;
@@ -3284,7 +3284,7 @@ function xo(s) {
3284
3284
  return { text: n, styles: i, entities: r };
3285
3285
  }
3286
3286
  function Io(s, t) {
3287
- if (!t.entities.some((i) => i.kind === "ref")) return _t(t);
3287
+ if (!t.entities.some((i) => i.kind === "ref")) return Gt(t);
3288
3288
  const e = new Map(s.fragments);
3289
3289
  for (const i of t.fragments ?? []) e.set(i.id, Q(i));
3290
3290
  const n = qe(t);
@@ -3294,7 +3294,7 @@ function Io(s, t) {
3294
3294
  if ((r == null ? void 0 : r.kind) !== "ref" || !r.fragmentId) continue;
3295
3295
  const o = e.get(r.fragmentId);
3296
3296
  We(n, k(i), (a) => {
3297
- O(a, i, i + 1), T(a), o && $t(i, _t(o.slice), !1)(a);
3297
+ O(a, i, i + 1), T(a), o && $t(i, Gt(o.slice), !1)(a);
3298
3298
  });
3299
3299
  }
3300
3300
  return vs(n);
@@ -3302,9 +3302,9 @@ function Io(s, t) {
3302
3302
  function $t(s, t, e = !0) {
3303
3303
  return (n) => {
3304
3304
  var d;
3305
- const i = n.doc, r = e ? Io(i, t) : _t(t), o = i.clamp(s), a = i.slotAtCaret(o), l = (((d = r.virtualBlocks) == null ? void 0 : d.length) ?? 0) > 0 || r.entities.length > 0;
3305
+ const i = n.doc, r = e ? Io(i, t) : Gt(t), o = i.clamp(s), a = i.slotAtCaret(o), l = (((d = r.virtualBlocks) == null ? void 0 : d.length) ?? 0) > 0 || r.entities.length > 0;
3306
3306
  if (a != null && a.empty && !l) {
3307
- const f = Wt(r.text);
3307
+ const f = Ut(r.text);
3308
3308
  if (f)
3309
3309
  return dt(a.id, f)(n) ?? o;
3310
3310
  }
@@ -3313,7 +3313,7 @@ function $t(s, t, e = !0) {
3313
3313
  const p = { ...$(f), id: ht() };
3314
3314
  return c.set(f.id, p.id), p;
3315
3315
  });
3316
- G(n, o, r.text), xs(o, r.text)(n);
3316
+ G(n, o, r.text), As(o, r.text)(n);
3317
3317
  for (const f of h) n.emit(Ge(f));
3318
3318
  for (const f of r.styles) {
3319
3319
  const p = f.type === "image" && c.size ? {
@@ -3344,7 +3344,7 @@ function $t(s, t, e = !0) {
3344
3344
  }
3345
3345
  function Ds(s, t) {
3346
3346
  return (e) => {
3347
- const n = e.doc, i = n.clamp(s), r = tt(n.spacers, i), o = r && n.spacers[r.end - 1] === m.PARAGRAPH ? r.end - 1 : (r == null ? void 0 : r.end) ?? i, a = r && i > r.start && i < o ? Tt(i)(e) : i, l = xo(t);
3347
+ const n = e.doc, i = n.clamp(s), r = tt(n.spacers, i), o = r && n.spacers[r.end - 1] === m.PARAGRAPH ? r.end - 1 : (r == null ? void 0 : r.end) ?? i, a = r && i > r.start && i < o ? Tt(i)(e) : i, l = Ao(t);
3348
3348
  let c = l.text, h = l.styles;
3349
3349
  if (c.endsWith(m.PARAGRAPH) && n.spacers[a] === m.PARAGRAPH) {
3350
3350
  const d = c.length - 1;
@@ -3354,7 +3354,7 @@ function Ds(s, t) {
3354
3354
  };
3355
3355
  }
3356
3356
  function Fs(s, t, e) {
3357
- return (n) => Eo(t) ? Ds(s, t)(n) : Ht(s, t, e)(n);
3357
+ return (n) => Eo(t) ? Ds(s, t)(n) : zt(s, t, e)(n);
3358
3358
  }
3359
3359
  function Os(s, t) {
3360
3360
  return (e) => {
@@ -3363,13 +3363,13 @@ function Os(s, t) {
3363
3363
  const o = n.takeSlice(i, r);
3364
3364
  if (!Or(o)) return null;
3365
3365
  const a = n.buildFragment(o);
3366
- e.emit(Le(a)), O(e, i, r), T(e);
3366
+ e.emit(Pe(a)), O(e, i, r), T(e);
3367
3367
  const l = Qe(i, a.id)(e);
3368
3368
  return { fragmentId: a.id, index: l };
3369
3369
  };
3370
3370
  }
3371
3371
  function Qe(s, t) {
3372
- return (e) => e.doc.fragments.has(t) ? Lt(s, {
3372
+ return (e) => e.doc.fragments.has(t) ? Pt(s, {
3373
3373
  kind: "ref",
3374
3374
  fragmentId: t,
3375
3375
  width: 680,
@@ -3381,7 +3381,7 @@ function Ns(s) {
3381
3381
  const e = t.doc, n = e.clamp(s), i = e.imageAt(n);
3382
3382
  if ((i == null ? void 0 : i.kind) !== "ref" || !i.fragmentId) return null;
3383
3383
  const r = e.fragments.get(i.fragmentId);
3384
- return r ? (O(t, n, n + 1), T(t), $t(n, _t(r.slice), !0)(t)) : null;
3384
+ return r ? (O(t, n, n + 1), T(t), $t(n, Gt(r.slice), !0)(t)) : null;
3385
3385
  };
3386
3386
  }
3387
3387
  const ua = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
@@ -3389,16 +3389,16 @@ const ua = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
3389
3389
  applyLink: ae,
3390
3390
  applyMarkdownShortcut: Rs,
3391
3391
  applyParagraphStyle: ft,
3392
- applyTextStyle: Ue,
3392
+ applyTextStyle: Ke,
3393
3393
  backspace: Cs,
3394
3394
  clearSlot: kt,
3395
3395
  contentRuns: ps,
3396
3396
  coverAncestorsOf: Ye,
3397
- coverVirtualBlocks: As,
3397
+ coverVirtualBlocks: xs,
3398
3398
  deleteForward: Ts,
3399
- deleteRange: At,
3399
+ deleteRange: xt,
3400
3400
  deleteTableCol: $s,
3401
- deleteTableRow: Ls,
3401
+ deleteTableRow: Ps,
3402
3402
  emitDelete: O,
3403
3403
  emitInsert: G,
3404
3404
  emitStyle: rt,
@@ -3406,15 +3406,15 @@ const ua = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
3406
3406
  ensureParagraphAfter: ys,
3407
3407
  expectedParagraphSpans: gs,
3408
3408
  fillSlot: dt,
3409
- insertImage: Lt,
3409
+ insertImage: Pt,
3410
3410
  insertMarkdown: Ds,
3411
3411
  insertParagraph: Tt,
3412
3412
  insertRef: Qe,
3413
3413
  insertSlice: $t,
3414
3414
  insertTable: Bs,
3415
- insertTableCol: Ps,
3415
+ insertTableCol: Ls,
3416
3416
  insertTableRow: Oe,
3417
- insertText: Ht,
3417
+ insertText: zt,
3418
3418
  insertVirtualBlock: Xe,
3419
3419
  normalizeParagraphs: T,
3420
3420
  pasteText: Fs,
@@ -3423,11 +3423,11 @@ const ua = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
3423
3423
  removeLink: Fe,
3424
3424
  removeVirtualBlock: bs,
3425
3425
  resolveParagraphProps: St,
3426
- resolveTextProps: Ke,
3426
+ resolveTextProps: Ue,
3427
3427
  runOperation: We,
3428
3428
  scopeContext: us,
3429
3429
  setTableColWidths: le,
3430
- slotInlineText: Wt,
3430
+ slotInlineText: Ut,
3431
3431
  spanCovering: io,
3432
3432
  textSegments: ms,
3433
3433
  unlinkRef: Ns,
@@ -3518,8 +3518,8 @@ class Ro {
3518
3518
  ...t,
3519
3519
  mutations: r.a,
3520
3520
  inverse: i.a,
3521
- selectionBefore: Qt(t.selectionBefore, n.mutations),
3522
- selectionAfter: Qt(t.selectionAfter, n.mutations)
3521
+ selectionBefore: te(t.selectionBefore, n.mutations),
3522
+ selectionAfter: te(t.selectionAfter, n.mutations)
3523
3523
  };
3524
3524
  }
3525
3525
  /** 远端操作落地后,把栈里所有本地操作变换到新坐标系。 */
@@ -3530,8 +3530,8 @@ class Ro {
3530
3530
  ...n,
3531
3531
  mutations: yt(n.mutations, t.mutations, !1).a,
3532
3532
  inverse: yt(n.inverse, t.mutations, !1).a,
3533
- selectionBefore: Qt(n.selectionBefore, t.mutations),
3534
- selectionAfter: Qt(n.selectionAfter, t.mutations)
3533
+ selectionBefore: te(n.selectionBefore, t.mutations),
3534
+ selectionAfter: te(n.selectionAfter, t.mutations)
3535
3535
  };
3536
3536
  }
3537
3537
  for (let e = 0; e < this.redos.length; e++) {
@@ -3636,14 +3636,14 @@ class Bo {
3636
3636
  const ut = (s) => ({
3637
3637
  key: s,
3638
3638
  run: (t, e) => t.moveCaret(s, e.shift)
3639
- }), te = (s) => ({
3639
+ }), ee = (s) => ({
3640
3640
  key: s,
3641
3641
  mod: !0,
3642
3642
  run: (t, e) => {
3643
3643
  const n = s === "ArrowLeft" || s === "ArrowUp" ? -1 : 1, i = s === "ArrowLeft" || s === "ArrowRight";
3644
3644
  return e.meta ? t.moveCaretBy(i ? "line" : "doc", n, e.shift) : t.moveCaretBy(i ? "word" : "paragraph", n, e.shift);
3645
3645
  }
3646
- }), ee = (s) => ({
3646
+ }), ne = (s) => ({
3647
3647
  key: s,
3648
3648
  alt: !0,
3649
3649
  run: (t, e) => {
@@ -3655,14 +3655,14 @@ const ut = (s) => ({
3655
3655
  { key: "End", mod: !0, run: (s, t) => s.moveCaretBy("doc", 1, t.shift) },
3656
3656
  { key: "Home", run: (s, t) => s.moveCaretBy("line", -1, t.shift) },
3657
3657
  { key: "End", run: (s, t) => s.moveCaretBy("line", 1, t.shift) },
3658
- te("ArrowLeft"),
3659
- te("ArrowRight"),
3660
- te("ArrowUp"),
3661
- te("ArrowDown"),
3662
3658
  ee("ArrowLeft"),
3663
3659
  ee("ArrowRight"),
3664
3660
  ee("ArrowUp"),
3665
- ee("ArrowDown")
3661
+ ee("ArrowDown"),
3662
+ ne("ArrowLeft"),
3663
+ ne("ArrowRight"),
3664
+ ne("ArrowUp"),
3665
+ ne("ArrowDown")
3666
3666
  ], Vs = [
3667
3667
  { key: "z", mod: !0, shift: !1, run: (s) => s.undo() },
3668
3668
  { key: "z", mod: !0, shift: !0, run: (s) => s.redo() },
@@ -3682,15 +3682,15 @@ const ut = (s) => ({
3682
3682
  ut("ArrowRight"),
3683
3683
  ut("ArrowUp"),
3684
3684
  ut("ArrowDown")
3685
- ], Ot = () => {
3685
+ ], Nt = () => {
3686
3686
  }, En = [
3687
3687
  { key: "z", mod: !0, shift: !1, run: (s) => s.undo() },
3688
3688
  { key: "z", mod: !0, shift: !0, run: (s) => s.redo() },
3689
3689
  { key: "y", mod: !0, run: (s) => s.redo() },
3690
- { key: "b", mod: !0, run: Ot },
3691
- { key: "i", mod: !0, run: Ot },
3692
- { key: "u", mod: !0, run: Ot },
3693
- { key: "k", mod: !0, run: Ot },
3690
+ { key: "b", mod: !0, run: Nt },
3691
+ { key: "i", mod: !0, run: Nt },
3692
+ { key: "u", mod: !0, run: Nt },
3693
+ { key: "k", mod: !0, run: Nt },
3694
3694
  { key: "a", mod: !0, run: (s) => s.selectAll() },
3695
3695
  { key: "Backspace", suppressesInput: !0, run: (s) => s.backspace() },
3696
3696
  { key: "Delete", suppressesInput: !0, run: (s) => s.deleteForward() },
@@ -3709,7 +3709,7 @@ function fa(s = "newline") {
3709
3709
  const t = s === "shift-enter";
3710
3710
  return [
3711
3711
  ...En,
3712
- { key: "Enter", shift: t, suppressesInput: !0, run: Ot },
3712
+ { key: "Enter", shift: t, suppressesInput: !0, run: Nt },
3713
3713
  {
3714
3714
  key: "Enter",
3715
3715
  shift: !t,
@@ -3718,11 +3718,11 @@ function fa(s = "newline") {
3718
3718
  }
3719
3719
  ];
3720
3720
  }
3721
- function Po(s, t) {
3721
+ function Lo(s, t) {
3722
3722
  return !((s.key.length === 1 ? t.key.toLowerCase() : t.key) !== s.key || t.mod !== (s.mod ?? !1) || s.shift !== void 0 && t.shift !== s.shift || s.alt !== void 0 && t.alt !== s.alt);
3723
3723
  }
3724
- function Lo(s, t = Vs) {
3725
- return t.find((e) => Po(e, s)) ?? null;
3724
+ function Po(s, t = Vs) {
3725
+ return t.find((e) => Lo(e, s)) ?? null;
3726
3726
  }
3727
3727
  const $o = /* @__PURE__ */ new Set(["Backspace", "Delete", "Escape"]);
3728
3728
  function Do(s) {
@@ -3738,7 +3738,7 @@ function Do(s) {
3738
3738
  function Fo(s) {
3739
3739
  const t = s.shortcuts ?? Vs, e = (n) => {
3740
3740
  if (!s.accepts(n) || n.isComposing || n.keyCode === 229 || s.composing() && !$o.has(n.key)) return;
3741
- const i = Do(n), r = Lo(i, t);
3741
+ const i = Do(n), r = Po(i, t);
3742
3742
  if (!r) return;
3743
3743
  const o = () => r.run(s.commands, i);
3744
3744
  (s.track ? s.track(o) : o()) !== !1 && (n.preventDefault(), r.suppressesInput && s.suppressInput(n));
@@ -3860,11 +3860,11 @@ class No {
3860
3860
  };
3861
3861
  }
3862
3862
  }
3863
- const Ho = 3e3, zo = 500, An = [40, 100], ne = [
3863
+ const Ho = 3e3, zo = 500, xn = [50, 100], Ot = [
3864
3864
  { key: "latency", label: "上屏延迟" },
3865
3865
  { key: "editor", label: "编辑器" },
3866
3866
  { key: "queue", label: "排队" }
3867
- ], xn = ["keydown", "beforeinput", "compositionstart", "compositionupdate", "compositionend", "paste"];
3867
+ ], An = ["keydown", "beforeinput", "compositionstart", "compositionupdate", "compositionend", "paste"];
3868
3868
  class Vo {
3869
3869
  constructor(t) {
3870
3870
  u(this, "on", !1);
@@ -3880,8 +3880,15 @@ class Vo {
3880
3880
  u(this, "channel", null);
3881
3881
  u(this, "afterPaint", null);
3882
3882
  u(this, "el", null);
3883
+ u(this, "bodyEl", null);
3884
+ u(this, "miniEl", null);
3883
3885
  u(this, "f", null);
3884
3886
  u(this, "getStats");
3887
+ u(this, "collapsed", !1);
3888
+ u(this, "left", 12);
3889
+ u(this, "top", 0);
3890
+ u(this, "placed", !1);
3891
+ u(this, "drag", null);
3885
3892
  u(this, "onEvent", (t) => {
3886
3893
  this.eventTs = t.timeStamp;
3887
3894
  });
@@ -3894,6 +3901,23 @@ class Vo {
3894
3901
  const e = t - this.fpsFrom;
3895
3902
  e >= zo && (this.fps = Math.round(this.fpsFrames * 1e3 / e), this.fpsFrames = 0, this.fpsFrom = t, this.showEnv()), this.fpsRaf = requestAnimationFrame(this.fpsTick);
3896
3903
  });
3904
+ u(this, "onDown", (t) => {
3905
+ if (t.button !== 0 || !this.el) return;
3906
+ t.preventDefault(), t.stopPropagation();
3907
+ const e = this.el.getBoundingClientRect();
3908
+ this.left = e.left, this.top = e.top, this.placed = !0, this.el.style.left = `${this.left}px`, this.el.style.top = `${this.top}px`, this.el.style.bottom = "auto", this.el.style.cursor = "grabbing", this.drag = { mx: t.clientX, my: t.clientY, left: this.left, top: this.top, moved: !1 };
3909
+ });
3910
+ u(this, "onMove", (t) => {
3911
+ const e = this.drag;
3912
+ if (!e || !this.el) return;
3913
+ const n = t.clientX - e.mx, i = t.clientY - e.my;
3914
+ !e.moved && n * n + i * i < 25 || (e.moved = !0, this.left = e.left + n, this.top = e.top + i, this.clamp());
3915
+ });
3916
+ u(this, "onUp", () => {
3917
+ const t = this.drag;
3918
+ this.drag = null, this.el && (this.el.style.cursor = "grab"), t && !t.moved && this.toggle();
3919
+ });
3920
+ u(this, "onResize", () => this.clamp());
3897
3921
  this.getStats = t;
3898
3922
  }
3899
3923
  get enabled() {
@@ -3902,7 +3926,7 @@ class Vo {
3902
3926
  enable() {
3903
3927
  if (!this.on) {
3904
3928
  this.on = !0;
3905
- for (const t of xn) document.addEventListener(t, this.onEvent, { capture: !0, passive: !0 });
3929
+ for (const t of An) document.addEventListener(t, this.onEvent, { capture: !0, passive: !0 });
3906
3930
  this.channel = new MessageChannel(), this.channel.port1.onmessage = this.onPainted, this.mount(), this.showIdle(), this.fpsFrom = performance.now(), this.fpsFrames = 0, this.fpsRaf = requestAnimationFrame(this.fpsTick);
3907
3931
  }
3908
3932
  }
@@ -3910,8 +3934,8 @@ class Vo {
3910
3934
  var t, e;
3911
3935
  if (this.on) {
3912
3936
  this.on = !1;
3913
- for (const n of xn) document.removeEventListener(n, this.onEvent, { capture: !0 });
3914
- cancelAnimationFrame(this.fpsRaf), window.clearTimeout(this.idleTimer), (t = this.channel) == null || t.port1.close(), this.channel = null, this.pending = null, this.afterPaint = null, this.flushScheduled = !1, (e = this.el) == null || e.remove(), this.el = null, this.f = null;
3937
+ for (const n of An) document.removeEventListener(n, this.onEvent, { capture: !0 });
3938
+ cancelAnimationFrame(this.fpsRaf), window.clearTimeout(this.idleTimer), (t = this.channel) == null || t.port1.close(), this.channel = null, this.pending = null, this.afterPaint = null, this.flushScheduled = !1, window.removeEventListener("mousemove", this.onMove), window.removeEventListener("mouseup", this.onUp), window.removeEventListener("resize", this.onResize), (e = this.el) == null || e.remove(), this.el = null, this.bodyEl = null, this.miniEl = null, this.f = null, this.drag = null;
3915
3939
  }
3916
3940
  }
3917
3941
  /** 包住一次输入的处理。嵌套调用只计最外层。 */
@@ -3935,35 +3959,60 @@ class Vo {
3935
3959
  }
3936
3960
  mount() {
3937
3961
  const t = document.createElement("div");
3938
- t.className = "mini-perf-panel", t.style.cssText = "position:fixed;left:12px;bottom:12px;z-index:2147483000;width:250px;padding:8px 10px;box-sizing:border-box;border-radius:8px;background:rgba(20,22,28,.86);color:#e8eaf0;pointer-events:none;user-select:none;font:12px/1.6 ui-monospace,SFMono-Regular,Menlo,monospace;contain:layout paint style;", t.innerHTML = ne.map(
3962
+ t.className = "mini-perf-panel", t.tabIndex = -1, t.style.cssText = "position:fixed;left:12px;bottom:12px;z-index:2147483000;width:250px;padding:8px 10px;box-sizing:border-box;border-radius:8px;background:rgba(20,22,28,.86);color:#e8eaf0;user-select:none;cursor:grab;font:12px/1.6 ui-monospace,SFMono-Regular,Menlo,monospace;contain:layout paint style;", t.innerHTML = '<div data-f="mini" style="display:none;align-items:center;gap:8px;cursor:grab"><span data-f="mini-fps" style="opacity:.85"></span>' + Ot.map((i) => `<span data-md="${i.key}">●</span>`).join("") + '</div><div data-f="body">' + Ot.map(
3939
3963
  (i) => `<div style="display:flex;justify-content:space-between"><span style="opacity:.65">${i.label}</span><span><span data-v="${i.key}"></span> <span data-d="${i.key}">●</span></span></div>`
3940
- ).join("") + '<div data-f="env" style="margin-top:2px;opacity:.55;white-space:nowrap;overflow:hidden;text-overflow:ellipsis"></div>';
3964
+ ).join("") + '<div data-f="env" style="margin-top:2px;opacity:.55;white-space:nowrap;overflow:hidden;text-overflow:ellipsis"></div></div>';
3941
3965
  const e = (i) => t.querySelector(i), n = {};
3942
- for (const i of ne) n[i.key] = { value: e(`[data-v="${i.key}"]`), dot: e(`[data-d="${i.key}"]`) };
3943
- this.f = { rows: n, env: e('[data-f="env"]') }, document.body.appendChild(t), this.el = t;
3966
+ for (const i of Ot) n[i.key] = { value: e(`[data-v="${i.key}"]`), dot: e(`[data-d="${i.key}"]`) };
3967
+ this.f = { rows: n, env: e('[data-f="env"]') }, this.bodyEl = e('[data-f="body"]'), this.miniEl = e('[data-f="mini"]'), t.addEventListener("mousedown", this.onDown), window.addEventListener("mousemove", this.onMove), window.addEventListener("mouseup", this.onUp), window.addEventListener("resize", this.onResize), document.body.appendChild(t), this.el = t, this.applyCollapsed(), this.clamp();
3968
+ }
3969
+ toggle() {
3970
+ this.collapsed = !this.collapsed, this.applyCollapsed(), this.clamp();
3971
+ }
3972
+ applyCollapsed() {
3973
+ const t = this.el;
3974
+ !t || !this.bodyEl || !this.miniEl || (this.bodyEl.style.display = this.collapsed ? "none" : "block", this.miniEl.style.display = this.collapsed ? "flex" : "none", t.style.width = this.collapsed ? "auto" : "250px", t.style.padding = this.collapsed ? "6px 10px" : "8px 10px", this.showEnv());
3975
+ }
3976
+ clamp() {
3977
+ const t = this.el;
3978
+ if (!t) return;
3979
+ const e = 8, n = t.offsetWidth, i = t.offsetHeight, r = Math.max(e, window.innerWidth - n - e), o = Math.max(e, window.innerHeight - i - e);
3980
+ this.placed && (this.left = Math.min(r, Math.max(e, this.left)), this.top = Math.min(o, Math.max(e, this.top)), t.style.left = `${this.left}px`, t.style.top = `${this.top}px`, t.style.bottom = "auto");
3944
3981
  }
3945
3982
  show(t, e, n) {
3983
+ var o;
3946
3984
  const i = this.f;
3947
3985
  if (!i) return;
3948
3986
  const r = { latency: t, editor: e, queue: n };
3949
- for (const o of ne) {
3950
- const a = r[o.key], l = i.rows[o.key];
3951
- l.value.textContent = `${a.toFixed(1)}ms`, l.dot.style.color = a <= An[0] ? "#3ddc84" : a <= An[1] ? "#f5c542" : "#ff5a5a";
3987
+ for (const a of Ot) {
3988
+ const l = r[a.key], c = i.rows[a.key];
3989
+ c.value.textContent = `${l.toFixed(1)}ms`;
3990
+ const h = l <= xn[0] ? "#3ddc84" : l <= xn[1] ? "#f5c542" : "#ff5a5a";
3991
+ c.dot.style.color = h;
3992
+ const d = (o = this.el) == null ? void 0 : o.querySelector(`[data-md="${a.key}"]`);
3993
+ d && (d.style.color = h);
3952
3994
  }
3953
3995
  window.clearTimeout(this.idleTimer), this.idleTimer = window.setTimeout(() => this.showIdle(), Ho);
3954
3996
  }
3955
3997
  showIdle() {
3998
+ var e;
3956
3999
  const t = this.f;
3957
4000
  if (t) {
3958
- for (const e of ne)
3959
- t.rows[e.key].value.textContent = "—", t.rows[e.key].dot.style.color = "#666";
4001
+ for (const n of Ot) {
4002
+ t.rows[n.key].value.textContent = "—", t.rows[n.key].dot.style.color = "#666";
4003
+ const i = (e = this.el) == null ? void 0 : e.querySelector(`[data-md="${n.key}"]`);
4004
+ i && (i.style.color = "#666");
4005
+ }
3960
4006
  this.showEnv();
3961
4007
  }
3962
4008
  }
3963
4009
  showEnv() {
4010
+ var i;
3964
4011
  if (!this.f) return;
3965
4012
  const t = this.getStats(), e = t.chars >= 1e4 ? `${(t.chars / 1e4).toFixed(1)}万字` : `${t.chars}字`;
3966
4013
  this.f.env.textContent = `帧率 ${this.fps || "—"}fps · ${e} · ${t.paragraphs}段`;
4014
+ const n = (i = this.el) == null ? void 0 : i.querySelector('[data-f="mini-fps"]');
4015
+ n && (n.textContent = `${this.fps || "—"}fps`);
3967
4016
  }
3968
4017
  }
3969
4018
  function _o(s) {
@@ -4001,7 +4050,7 @@ function Wo(s, t, e) {
4001
4050
  for (let i = n.length - 1; i >= 0; i--) if (n[i].start < t) return n[i].start;
4002
4051
  return 0;
4003
4052
  }
4004
- function Ko(s, t, e) {
4053
+ function Uo(s, t, e) {
4005
4054
  const n = me(s);
4006
4055
  if (e < 0) {
4007
4056
  const o = t > 0 ? s.lastIndexOf(m.PARAGRAPH, t - 1) + 1 : 0;
@@ -4013,7 +4062,7 @@ function Ko(s, t, e) {
4013
4062
  const r = s.indexOf(m.PARAGRAPH, t + 1);
4014
4063
  return r === -1 ? n : Math.min(r, n);
4015
4064
  }
4016
- function Uo(s, t) {
4065
+ function Ko(s, t) {
4017
4066
  const e = _s(s), n = e.find((i) => t >= i.start && t < i.end) ?? e.find((i) => t === i.end);
4018
4067
  return n ? { start: n.start, end: n.end } : null;
4019
4068
  }
@@ -4353,8 +4402,8 @@ function ta(s) {
4353
4402
  const n = () => {
4354
4403
  if (!e) return;
4355
4404
  const i = document.createElement("span");
4356
- i.className = `mini-run${Ut(e.style) !== "solid" ? " is-fill" : ""}`, i.textContent = e.text, i.style.cssText = `left:${e.x}px;top:${e.y}px;width:${e.w}px;height:${e.h}px;line-height:${e.h}px;${Zo(e.style, e.w)}`, t.appendChild(i);
4357
- const r = zt(e.style);
4405
+ i.className = `mini-run${qt(e.style) !== "solid" ? " is-fill" : ""}`, i.textContent = e.text, i.style.cssText = `left:${e.x}px;top:${e.y}px;width:${e.w}px;height:${e.h}px;line-height:${e.h}px;${Zo(e.style, e.w)}`, t.appendChild(i);
4406
+ const r = Vt(e.style);
4358
4407
  if (r !== "none" || e.style.strikethrough) {
4359
4408
  const o = document.createElement("span");
4360
4409
  o.className = `mini-deco mini-deco-${r}${e.style.strikethrough ? " is-strike" : ""}`, o.style.cssText = `left:${e.x}px;top:${e.y}px;width:${e.w}px;height:${e.h}px;color:${e.style.color ?? "#1f2329"};`, t.appendChild(o);
@@ -4692,8 +4741,8 @@ class pa {
4692
4741
  t.preventDefault(), this.writeClipboard(t.clipboardData), this.backspace();
4693
4742
  }
4694
4743
  });
4695
- for (const i of e.plugins ?? Pr) vn(i);
4696
- e.hostEmbed && (vn(Rr), xr(e.hostEmbed)), this.parent = t, this.widthMode = e.width ?? "fill", this.padding = e.padding ?? { x: Ce, y: Te }, this.shortcutTable = e.shortcuts, this.textDefaults = e.textDefaults ?? null, this.chrome = e.chrome ?? {}, this.doc = e.doc ?? new ws(), this.applyTextDefaults(this.doc), this.sel = k(this.doc.length - 1), this.paintMode = e.paint ?? "html", this.painter = this.createPainter(), this.perf = new No(this, () => this.painter), this.perfPanel = new Vo(() => ({
4744
+ for (const i of e.plugins ?? Lr) vn(i);
4745
+ e.hostEmbed && (vn(Rr), Ar(e.hostEmbed)), this.parent = t, this.widthMode = e.width ?? "fill", this.padding = e.padding ?? { x: Ce, y: Te }, this.shortcutTable = e.shortcuts, this.textDefaults = e.textDefaults ?? null, this.chrome = e.chrome ?? {}, this.doc = e.doc ?? new ws(), this.applyTextDefaults(this.doc), this.sel = k(this.doc.length - 1), this.paintMode = e.paint ?? "html", this.painter = this.createPainter(), this.perf = new No(this, () => this.painter), this.perfPanel = new Vo(() => ({
4697
4746
  chars: this.doc.length,
4698
4747
  paragraphs: _o(this.doc.spacers)
4699
4748
  })), this.contentWidth = this.resolveContentWidth(), this.layout = ct(this.doc, this.contentWidth, void 0, this.padding), this.root = document.createElement("div"), this.root.className = "mini-editor", this.root.dataset.paint = this.paintMode, this.applyChrome(), this.commands = {
@@ -4867,7 +4916,7 @@ class pa {
4867
4916
  var a;
4868
4917
  const i = e ?? n.selection().focus, r = (((a = t.virtualBlocks) == null ? void 0 : a.length) ?? 0) > 0 || t.entities.length > 0, o = e == null ? this.slotToFill(n) : n.doc.slotAtCaret(i);
4869
4918
  if (!r && o && (o.empty || e == null && this.selectionCoversSlot(n, o))) {
4870
- const l = Wt(t.text);
4919
+ const l = Ut(t.text);
4871
4920
  if (l) {
4872
4921
  const c = dt(o.id, l)(n);
4873
4922
  c != null && n.select(k(c));
@@ -4985,7 +5034,7 @@ class pa {
4985
5034
  if (!e.length) return 0;
4986
5035
  const n = e[e.length - 1];
4987
5036
  return this.runEdit("embed.delete", (i) => {
4988
- for (const r of e) At(r, r + 1)(i);
5037
+ for (const r of e) xt(r, r + 1)(i);
4989
5038
  i.select(k(n));
4990
5039
  }), e.length;
4991
5040
  }
@@ -5024,7 +5073,7 @@ class pa {
5024
5073
  return {
5025
5074
  bold: !!t.bold,
5026
5075
  italic: !!t.italic,
5027
- underline: zt(t) !== "none",
5076
+ underline: Vt(t) !== "none",
5028
5077
  strikethrough: !!t.strikethrough,
5029
5078
  fontSize: t.fontSize ?? 16,
5030
5079
  color: t.color ?? "#1f2329",
@@ -5221,7 +5270,7 @@ class pa {
5221
5270
  t.select(k((c == null ? void 0 : c.start) ?? n));
5222
5271
  return;
5223
5272
  }
5224
- At(n, i)(t), t.select(k(n));
5273
+ xt(n, i)(t), t.select(k(n));
5225
5274
  }
5226
5275
  clearCellGrid(t, e, n) {
5227
5276
  var p;
@@ -5266,8 +5315,8 @@ class pa {
5266
5315
  this.composeAnchor = (h == null ? void 0 : h.start) ?? n, r.select(k(c ?? n));
5267
5316
  return;
5268
5317
  }
5269
- this.composeLen > 0 && At(n, n + this.composeLen)(r);
5270
- const l = e ? Ht(n, e, i)(r) : n;
5318
+ this.composeLen > 0 && xt(n, n + this.composeLen)(r);
5319
+ const l = e ? zt(n, e, i)(r) : n;
5271
5320
  r.select(k(l));
5272
5321
  }), this.composeLen = e.length;
5273
5322
  } else if (!t && this.composeAnchor !== null) {
@@ -5280,7 +5329,7 @@ class pa {
5280
5329
  r.select(k((l == null ? void 0 : l.start) ?? o.start));
5281
5330
  return;
5282
5331
  }
5283
- i > 0 && At(n, n + i)(r), r.select(k(n));
5332
+ i > 0 && xt(n, n + i)(r), r.select(k(n));
5284
5333
  }), this.composeAnchor = null, this.composeLen = 0;
5285
5334
  }
5286
5335
  this.composeText = e, this.relayout();
@@ -5305,7 +5354,7 @@ class pa {
5305
5354
  }
5306
5355
  this.deleteSelectionIfNeeded(r);
5307
5356
  const h = this.typingStyle ?? r.doc.textPropsAt(r.selection().focus), d = r.selection().focus;
5308
- let f = Ht(d, t, h)(r);
5357
+ let f = zt(d, t, h)(r);
5309
5358
  !this.refEdit && ho(t) && (f = Rs(f)(r)), r.select(k(f));
5310
5359
  }), ((i = this.stackTop()) == null ? void 0 : i.mode) === "selected" && (e == null ? void 0 : e.kind) === "virtualSlot" && this.selectVblock(e.id, "editing"));
5311
5360
  }
@@ -5318,7 +5367,7 @@ class pa {
5318
5367
  const e = Xo(t), n = (t == null ? void 0 : t.getData("text/plain")) ?? "";
5319
5368
  if (!(!e && !n) && (this.runEdit("insert.paste", (a) => {
5320
5369
  var p;
5321
- const l = (((p = e == null ? void 0 : e.virtualBlocks) == null ? void 0 : p.length) ?? 0) > 0 || ((e == null ? void 0 : e.entities.length) ?? 0) > 0, c = Wt((e == null ? void 0 : e.text) ?? n), h = this.slotToFill(a);
5370
+ const l = (((p = e == null ? void 0 : e.virtualBlocks) == null ? void 0 : p.length) ?? 0) > 0 || ((e == null ? void 0 : e.entities.length) ?? 0) > 0, c = Ut((e == null ? void 0 : e.text) ?? n), h = this.slotToFill(a);
5322
5371
  if (h && c && !l) {
5323
5372
  const g = dt(h.id, c)(a);
5324
5373
  g != null && a.select(k(g));
@@ -5404,13 +5453,13 @@ class pa {
5404
5453
  }
5405
5454
  this.runEdit("style.text", (e) => {
5406
5455
  const n = e.selection();
5407
- Ue(F(n), _(n), t)(e);
5456
+ Ke(F(n), _(n), t)(e);
5408
5457
  });
5409
5458
  }
5410
5459
  toggleText(t) {
5411
5460
  const e = this.currentTextStyle();
5412
5461
  if (t === "underline") {
5413
- const n = zt(e) !== "none";
5462
+ const n = Vt(e) !== "none";
5414
5463
  this.applyText(n ? { underline: !1, underlineStyle: void 0 } : { underline: !0, underlineStyle: "single" });
5415
5464
  return;
5416
5465
  }
@@ -5441,7 +5490,7 @@ class pa {
5441
5490
  }
5442
5491
  this.runEdit("style.link", (l) => {
5443
5492
  if (n === i) {
5444
- const c = Ht(n, a)(l);
5493
+ const c = zt(n, a)(l);
5445
5494
  ae(n, c, a)(l), l.select({ anchor: n, focus: c });
5446
5495
  } else
5447
5496
  ae(n, i, a)(l);
@@ -5460,7 +5509,7 @@ class pa {
5460
5509
  const n = this.targetDoc(), i = { ...t, ...Ct(t.kind).measure(t, this.innerContentWidth(), n) };
5461
5510
  this.runEdit("embed.insert", (r) => {
5462
5511
  e === "cursor" ? this.deleteSelectionIfNeeded(r) : r.select(k(this.resolveInsertIndex(e, r.doc)));
5463
- const o = Lt(r.selection().focus, i)(r);
5512
+ const o = Pt(r.selection().focus, i)(r);
5464
5513
  r.select({ anchor: o - 1, focus: o });
5465
5514
  });
5466
5515
  }
@@ -5554,7 +5603,7 @@ class pa {
5554
5603
  deleteSelectedEmbed(t) {
5555
5604
  const e = this.selectedEmbedIndex(t);
5556
5605
  return e === null ? !1 : (this.runEdit("embed.delete", (n) => {
5557
- At(e, e + 1)(n), n.select(k(e));
5606
+ xt(e, e + 1)(n), n.select(k(e));
5558
5607
  }), !0);
5559
5608
  }
5560
5609
  exitRefEditAtStart() {
@@ -5595,7 +5644,7 @@ class pa {
5595
5644
  i = st(o.inner, t - (o.x + wt), e - (o.y + Mt));
5596
5645
  } else
5597
5646
  i = ot(n.spacers, st(this.layout, t, e));
5598
- const r = Uo(n.spacers, i);
5647
+ const r = Ko(n.spacers, i);
5599
5648
  if (r) {
5600
5649
  if (this.refEdit)
5601
5650
  this.fragSel = { anchor: r.start, focus: r.end };
@@ -5629,7 +5678,7 @@ class pa {
5629
5678
  };
5630
5679
  this.runEdit("embed.insert", (p) => {
5631
5680
  this.deleteSelectionIfNeeded(p);
5632
- const g = Lt(p.selection().focus, f)(p);
5681
+ const g = Pt(p.selection().focus, f)(p);
5633
5682
  p.select({ anchor: g - 1, focus: g });
5634
5683
  });
5635
5684
  };
@@ -5649,7 +5698,7 @@ class pa {
5649
5698
  tableOp(t) {
5650
5699
  this.runEdit("table.structure", (e) => {
5651
5700
  const n = e.selection().focus;
5652
- t === "row" && Oe(n)(e), t === "col" && Ps(n)(e), t === "del-row" && Ls(n)(e), t === "del-col" && $s(n)(e);
5701
+ t === "row" && Oe(n)(e), t === "col" && Ls(n)(e), t === "del-row" && Ps(n)(e), t === "del-col" && $s(n)(e);
5653
5702
  });
5654
5703
  }
5655
5704
  undo() {
@@ -5976,7 +6025,7 @@ class pa {
5976
6025
  const o = i.spacers;
5977
6026
  if (t === "doc") return e < 0 ? 0 : me(o);
5978
6027
  if (t === "word") return Wo(o, n, e);
5979
- if (t === "paragraph") return Ko(o, n, e);
6028
+ if (t === "paragraph") return Uo(o, n, e);
5980
6029
  const a = this.lineAt(r, n);
5981
6030
  return a ? e < 0 ? a.start : a.end > a.start && o[a.end - 1] === `
5982
6031
  ` ? a.end - 1 : a.end : n;
@@ -6300,7 +6349,7 @@ export {
6300
6349
  Vs as SHORTCUTS,
6301
6350
  Gs as SLICE_MIME,
6302
6351
  Br as activateHostEmbed,
6303
- Pr as builtinEmbedPlugins,
6352
+ Lr as builtinEmbedPlugins,
6304
6353
  at as caretFromIndex,
6305
6354
  ei as codePlugin,
6306
6355
  k as collapsedSel,
@@ -6325,11 +6374,11 @@ export {
6325
6374
  F as selStart,
6326
6375
  ve as selectionRects,
6327
6376
  qo as serializeSlice,
6328
- xr as setHostEmbedRenderer,
6377
+ Ar as setHostEmbedRenderer,
6329
6378
  Xo as sliceFromClipboard,
6330
6379
  vs as sliceFromDocument,
6331
6380
  Mr as slotPlugin,
6332
- zt as underlineKind,
6333
- Ar as videoPlugin
6381
+ Vt as underlineKind,
6382
+ xr as videoPlugin
6334
6383
  };
6335
6384
  //# sourceMappingURL=index.js.map