digi-mathchem-editor 1.0.8 → 1.0.9

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.
@@ -1,5 +1,5 @@
1
1
  import e, { useState as B, useEffect as O, useMemo as xe, useRef as re, useCallback as he } from "react";
2
- import { createPortal as z } from "react-dom";
2
+ import { createPortal as Q } from "react-dom";
3
3
  import { FontAwesomeIcon as ae } from "@fortawesome/react-fontawesome";
4
4
  import { faBold as fe, faItalic as ve } from "@fortawesome/free-solid-svg-icons";
5
5
  import { MathfieldElement as Ee } from "mathlive";
@@ -326,7 +326,7 @@ function Fe() {
326
326
  }
327
327
  if (i.addedNodes)
328
328
  for (const c of i.addedNodes)
329
- c instanceof Element && (((n = c.tagName) == null ? void 0 : n.toLowerCase()) === "math-field" && requestAnimationFrame(() => ie(c)), (s = c.querySelectorAll) == null || s.call(c, "math-field").forEach((h) => requestAnimationFrame(() => ie(h))));
329
+ c instanceof Element && (((n = c.tagName) == null ? void 0 : n.toLowerCase()) === "math-field" && requestAnimationFrame(() => ie(c)), (s = c.querySelectorAll) == null || s.call(c, "math-field").forEach((m) => requestAnimationFrame(() => ie(m))));
330
330
  }
331
331
  }), me.observe(document.body, {
332
332
  childList: !0,
@@ -361,36 +361,36 @@ const Ce = [
361
361
  }), l;
362
362
  }, Je = Ze();
363
363
  function je({ isOpen: l, onClose: o, onInsert: n, position: s }) {
364
- const [i, c] = B(""), [h, u] = B("All");
364
+ const [i, c] = B(""), [m, u] = B("All");
365
365
  O(() => {
366
366
  l && (c(""), u("All"));
367
367
  }, [l]);
368
368
  const x = xe(() => {
369
369
  let k = Je;
370
- if (h !== "All" && (k = k.filter((E) => E.category === h)), i.trim()) {
370
+ if (m !== "All" && (k = k.filter((E) => E.category === m)), i.trim()) {
371
371
  const E = i.trim().toUpperCase();
372
372
  k = k.filter((b) => b.code.includes(E));
373
373
  }
374
374
  return k;
375
- }, [h, i]), I = xe(() => {
376
- if (h !== "All" && !i.trim())
377
- return { [h]: x };
375
+ }, [m, i]), I = xe(() => {
376
+ if (m !== "All" && !i.trim())
377
+ return { [m]: x };
378
378
  const k = {};
379
379
  return x.forEach((E) => {
380
380
  k[E.category] || (k[E.category] = []), k[E.category].push(E);
381
381
  }), k;
382
- }, [x, h, i]), p = (k) => {
382
+ }, [x, m, i]), p = (k) => {
383
383
  k.key === "Escape" && o();
384
384
  };
385
385
  if (O(() => (l && window.addEventListener("keydown", p), () => window.removeEventListener("keydown", p)), [l]), !l) return null;
386
- let M = { top: "50%", left: "50%", transform: "translate(-50%, -50%)" };
386
+ let A = { top: "50%", left: "50%", transform: "translate(-50%, -50%)" };
387
387
  if (s) {
388
388
  let k = s.x - 120, E = s.y;
389
- k < 10 && (k = 10), k + 230 > window.innerWidth && (k = window.innerWidth - 240), E + 200 > window.innerHeight && (E = window.innerHeight - 210), M = { top: `${E}px`, left: `${k}px` };
389
+ k < 10 && (k = 10), k + 230 > window.innerWidth && (k = window.innerWidth - 240), E + 200 > window.innerHeight && (E = window.innerHeight - 210), A = { top: `${E}px`, left: `${k}px` };
390
390
  }
391
391
  return /* @__PURE__ */ e.createElement("div", { className: "scm-overlay", onMouseDown: (k) => {
392
392
  k.stopPropagation(), o();
393
- } }, /* @__PURE__ */ e.createElement("div", { className: "scm-modal", style: M, onMouseDown: (k) => k.stopPropagation() }, /* @__PURE__ */ e.createElement("div", { className: "scm-toolbar" }, /* @__PURE__ */ e.createElement(
393
+ } }, /* @__PURE__ */ e.createElement("div", { className: "scm-modal", style: A, onMouseDown: (k) => k.stopPropagation() }, /* @__PURE__ */ e.createElement("div", { className: "scm-toolbar" }, /* @__PURE__ */ e.createElement(
394
394
  "input",
395
395
  {
396
396
  type: "text",
@@ -402,7 +402,7 @@ function je({ isOpen: l, onClose: o, onInsert: n, position: s }) {
402
402
  ), /* @__PURE__ */ e.createElement(
403
403
  "select",
404
404
  {
405
- value: h,
405
+ value: m,
406
406
  onChange: (k) => u(k.target.value),
407
407
  className: "scm-category-select"
408
408
  },
@@ -449,13 +449,13 @@ typeof window < "u" && (window.MathfieldElement ? window.MathfieldElement.fontsD
449
449
  window.__ckMathWidgets = window.__ckMathWidgets || /* @__PURE__ */ new Map();
450
450
  window.__ckMathWidgetClickHandler = null;
451
451
  function Qe(l) {
452
- var n, s, i, c, h;
452
+ var n, s, i, c, m;
453
453
  if (!l) return null;
454
454
  const o = typeof l.composedPath == "function" ? l.composedPath() : [l];
455
455
  for (const u of o)
456
456
  if (u instanceof HTMLElement && ((n = u.classList) != null && n.contains("ck-math-widget") || (s = u.dataset) != null && s.mathId || (i = u.classList) != null && i.contains("ck-widget") && ((c = u.querySelector) != null && c.call(u, ".ck-math-widget-inner"))))
457
457
  return u;
458
- return l instanceof Element ? (h = l.closest) == null ? void 0 : h.call(l, ".ck-math-widget, [data-math-id]") : null;
458
+ return l instanceof Element ? (m = l.closest) == null ? void 0 : m.call(l, ".ck-math-widget, [data-math-id]") : null;
459
459
  }
460
460
  function de(l) {
461
461
  if (!l) return "";
@@ -475,13 +475,13 @@ function de(l) {
475
475
  let i = 1, c = n + 1;
476
476
  for (n++; n < l.length && i > 0; )
477
477
  l[n] === "{" ? i++ : l[n] === "}" && i--, n++;
478
- let h = l.slice(c, n - 1);
479
- h.trim() === "" ? o += "\\quad " : o += h;
478
+ let m = l.slice(c, n - 1);
479
+ m.trim() === "" ? o += "\\quad " : o += m;
480
480
  }
481
481
  }
482
482
  return o;
483
483
  }
484
- function X(l) {
484
+ function z(l) {
485
485
  let o = "", n = 0;
486
486
  const s = "\\text{";
487
487
  for (; n < l.length; ) {
@@ -491,10 +491,10 @@ function X(l) {
491
491
  break;
492
492
  }
493
493
  o += l.slice(n, i);
494
- let c = 1, h = i + s.length;
495
- for (; h < l.length && c > 0; )
496
- l[h] === "{" ? c++ : l[h] === "}" && c--, h++;
497
- o += l.slice(i + s.length, h - 1), n = h;
494
+ let c = 1, m = i + s.length;
495
+ for (; m < l.length && c > 0; )
496
+ l[m] === "{" ? c++ : l[m] === "}" && c--, m++;
497
+ o += l.slice(i + s.length, m - 1), n = m;
498
498
  }
499
499
  return o;
500
500
  }
@@ -533,8 +533,8 @@ function ze(l, o) {
533
533
  }
534
534
  const c = oe(o);
535
535
  if (!c) return null;
536
- const h = l.model.document.getRoot();
537
- for (const { item: x } of l.model.createRangeIn(h))
536
+ const m = l.model.document.getRoot();
537
+ for (const { item: x } of l.model.createRangeIn(m))
538
538
  if ((u = x.is) != null && u.call(x, "element", "mathInline") && x.getAttribute("latex") === c)
539
539
  return x;
540
540
  return null;
@@ -549,8 +549,8 @@ function Se(l, o, n, s) {
549
549
  i && l.model.change((u) => {
550
550
  u.setSelection(i, "on");
551
551
  });
552
- const h = l.mathWidgetClickHandler || window.__ckMathWidgetClickHandler;
553
- h && h(i, c), window.dispatchEvent(new CustomEvent("editAneesWidget", {
552
+ const m = l.mathWidgetClickHandler || window.__ckMathWidgetClickHandler;
553
+ m && m(i, c), window.dispatchEvent(new CustomEvent("editAneesWidget", {
554
554
  detail: {
555
555
  editor: l,
556
556
  modelElement: i,
@@ -687,7 +687,7 @@ const Ke = [
687
687
  { label: "÷", insert: "\\div", title: "Divide sign" },
688
688
  { label: "/", insert: "/", title: "Slash" },
689
689
  { label: "±", insert: "\\pm", title: "Plus-minus" },
690
- { label: "*", insert: "\\ast", title: "Asterisk" },
690
+ { label: "*", insert: "*", title: "Asterisk" },
691
691
  { label: "○", insert: "\\circ", title: "Circle" },
692
692
  // Group 3 – Constants & Symbols (3 cols × 3 rows)
693
693
  {
@@ -2288,7 +2288,7 @@ const Ke = [
2288
2288
  { label: "÷", insert: "\\div", title: "Divide sign" },
2289
2289
  { label: "/", insert: "/", title: "Slash" },
2290
2290
  { label: "±", insert: "\\pm", title: "Plus-minus" },
2291
- { label: "*", insert: "\\ast", title: "Asterisk" },
2291
+ { label: "*", insert: "*", title: "Asterisk" },
2292
2292
  { label: "○", insert: "\\circ", title: "Circle" },
2293
2293
  // Group 3 – Constants & Symbols (3 cols × 3 rows)
2294
2294
  {
@@ -3634,12 +3634,12 @@ class at extends He {
3634
3634
  }), o.conversion.for("editingDowncast").elementToElement({
3635
3635
  model: "mathInline",
3636
3636
  view: (s, { writer: i }) => {
3637
- const c = s.getAttribute("latex") || "", h = "math-" + Math.random().toString(36).substr(2, 9);
3638
- window.__ckMathWidgets.set(h, s);
3637
+ const c = s.getAttribute("latex") || "", m = "math-" + Math.random().toString(36).substr(2, 9);
3638
+ window.__ckMathWidgets.set(m, s);
3639
3639
  const u = i.createContainerElement("span", {
3640
3640
  class: "ck-math-widget ck-math-inline-word",
3641
3641
  contenteditable: "false",
3642
- "data-math-id": h,
3642
+ "data-math-id": m,
3643
3643
  "data-latex": c
3644
3644
  }), x = i.createRawElement(
3645
3645
  "span",
@@ -3650,14 +3650,14 @@ class at extends He {
3650
3650
  (I) => {
3651
3651
  const p = document.createElement("math-field");
3652
3652
  p.setAttribute("math-virtual-keyboard-policy", "manual"), p.setAttribute("tabindex", "-1"), p.style.display = "inline-block", p.style.width = "auto", p.style.maxWidth = "100%", p.style.verticalAlign = "middle", p.style.border = "none", p.style.background = "transparent", p.style.outline = "none", p.style.fontSize = "inherit", p.style.minHeight = "auto", p.style.padding = "0 2px", p.style.margin = "0", p.style.pointerEvents = "none";
3653
- const M = () => {
3653
+ const A = () => {
3654
3654
  if (!p.isConnected) {
3655
- requestAnimationFrame(M);
3655
+ requestAnimationFrame(A);
3656
3656
  return;
3657
3657
  }
3658
3658
  window.__cme_macros && (p.macros = { ...p.macros, ...window.__cme_macros });
3659
3659
  let E = ne(
3660
- X(
3660
+ z(
3661
3661
  de(c)
3662
3662
  )
3663
3663
  );
@@ -3674,7 +3674,7 @@ class at extends He {
3674
3674
  }
3675
3675
  p.setAttribute("read-only", "");
3676
3676
  };
3677
- customElements.get("math-field") ? requestAnimationFrame(M) : customElements.whenDefined("math-field").then(() => requestAnimationFrame(M)), I.appendChild(p);
3677
+ customElements.get("math-field") ? requestAnimationFrame(A) : customElements.whenDefined("math-field").then(() => requestAnimationFrame(A)), I.appendChild(p);
3678
3678
  const k = () => {
3679
3679
  const E = I.parentElement;
3680
3680
  E && Xe(o, E);
@@ -3695,22 +3695,22 @@ class at extends He {
3695
3695
  c
3696
3696
  ));
3697
3697
  }, { priority: "high" }), o.conversion.for("editingDowncast").add((s) => {
3698
- s.on("attribute:latex:mathInline", (i, c, h) => {
3699
- if (!h.consumable.consume(c.item, i.name))
3698
+ s.on("attribute:latex:mathInline", (i, c, m) => {
3699
+ if (!m.consumable.consume(c.item, i.name))
3700
3700
  return;
3701
- const u = h.writer, x = h.mapper.toViewElement(c.item);
3701
+ const u = m.writer, x = m.mapper.toViewElement(c.item);
3702
3702
  if (x) {
3703
3703
  u.setAttribute("data-latex", c.attributeNewValue, x);
3704
3704
  const I = o.editing.view.domConverter.mapViewToDom(x);
3705
3705
  if (I) {
3706
3706
  const p = I.querySelector("math-field");
3707
3707
  if (p) {
3708
- let M = ne(X(de(c.attributeNewValue)));
3709
- M.includes("\\enclose") && /^\\ce\{[\s\S]*\}$/i.test(M.trim()) && (M = M.trim().replace(/^\\ce\{([\s\S]*)\}$/i, "$1")), p.removeAttribute("read-only");
3708
+ let A = ne(z(de(c.attributeNewValue)));
3709
+ A.includes("\\enclose") && /^\\ce\{[\s\S]*\}$/i.test(A.trim()) && (A = A.trim().replace(/^\\ce\{([\s\S]*)\}$/i, "$1")), p.removeAttribute("read-only");
3710
3710
  try {
3711
- p.setValue ? p.setValue("", { silenceNotifications: !0 }) : p.value = "", p.executeCommand(["insert", M, { insertionMode: "replaceAll" }]);
3711
+ p.setValue ? p.setValue("", { silenceNotifications: !0 }) : p.value = "", p.executeCommand(["insert", A, { insertionMode: "replaceAll" }]);
3712
3712
  } catch {
3713
- p.setValue ? p.setValue(M, { silenceNotifications: !0 }) : p.value = M;
3713
+ p.setValue ? p.setValue(A, { silenceNotifications: !0 }) : p.value = A;
3714
3714
  }
3715
3715
  p.setAttribute("read-only", "");
3716
3716
  }
@@ -3721,18 +3721,18 @@ class at extends He {
3721
3721
  }), o.conversion.for("dataDowncast").elementToElement({
3722
3722
  model: "mathInline",
3723
3723
  view: (s, { writer: i }) => {
3724
- const c = s.getAttribute("latex") || "", h = i.createContainerElement("span", {
3724
+ const c = s.getAttribute("latex") || "", m = i.createContainerElement("span", {
3725
3725
  class: "math-tex",
3726
3726
  "data-latex": c,
3727
3727
  // Keep raw latex in data-latex for restoring
3728
3728
  style: "display:inline;"
3729
3729
  });
3730
3730
  let u = ne(
3731
- X(
3731
+ z(
3732
3732
  de(c)
3733
3733
  )
3734
3734
  );
3735
- return u.includes("\\enclose") && /^\\ce\{[\s\S]*\}$/i.test(u.trim()) && (u = u.trim().replace(/^\\ce\{([\s\S]*)\}$/i, "$1")), i.insert(i.createPositionAt(h, 0), i.createText(u)), h;
3735
+ return u.includes("\\enclose") && /^\\ce\{[\s\S]*\}$/i.test(u.trim()) && (u = u.trim().replace(/^\\ce\{([\s\S]*)\}$/i, "$1")), i.insert(i.createPositionAt(m, 0), i.createText(u)), m;
3736
3736
  }
3737
3737
  }), o.conversion.for("upcast").elementToElement({
3738
3738
  view: {
@@ -3747,37 +3747,37 @@ class at extends He {
3747
3747
  }
3748
3748
  }
3749
3749
  function Ge({ matrixType: l, x: o, y: n, onSelect: s, onMouseEnter: i, onMouseLeave: c }) {
3750
- const [h, u] = B({ r: 2, c: 2 }), x = Math.max(10, parseInt(h.r, 10) || 0), I = Math.max(10, parseInt(h.c, 10) || 0), p = (b) => {
3750
+ const [m, u] = B({ r: 2, c: 2 }), x = Math.max(10, parseInt(m.r, 10) || 0), I = Math.max(10, parseInt(m.c, 10) || 0), p = (b) => {
3751
3751
  const y = b.target.value;
3752
3752
  if (y === "") {
3753
- u((A) => ({ ...A, r: "" }));
3753
+ u((C) => ({ ...C, r: "" }));
3754
3754
  return;
3755
3755
  }
3756
- const S = parseInt(y, 10);
3757
- isNaN(S) || u((A) => ({ ...A, r: Math.max(1, Math.min(10, S)) }));
3758
- }, M = () => {
3759
- (h.r === "" || isNaN(parseInt(h.r, 10))) && u((b) => ({ ...b, r: 1 }));
3756
+ const T = parseInt(y, 10);
3757
+ isNaN(T) || u((C) => ({ ...C, r: Math.max(1, Math.min(10, T)) }));
3758
+ }, A = () => {
3759
+ (m.r === "" || isNaN(parseInt(m.r, 10))) && u((b) => ({ ...b, r: 1 }));
3760
3760
  }, k = (b) => {
3761
3761
  const y = b.target.value;
3762
3762
  if (y === "") {
3763
- u((A) => ({ ...A, c: "" }));
3763
+ u((C) => ({ ...C, c: "" }));
3764
3764
  return;
3765
3765
  }
3766
- const S = parseInt(y, 10);
3767
- isNaN(S) || u((A) => ({ ...A, c: Math.max(1, Math.min(10, S)) }));
3766
+ const T = parseInt(y, 10);
3767
+ isNaN(T) || u((C) => ({ ...C, c: Math.max(1, Math.min(10, T)) }));
3768
3768
  }, E = () => {
3769
- (h.c === "" || isNaN(parseInt(h.c, 10))) && u((b) => ({ ...b, c: 1 }));
3769
+ (m.c === "" || isNaN(parseInt(m.c, 10))) && u((b) => ({ ...b, c: 1 }));
3770
3770
  };
3771
3771
  return O(() => {
3772
3772
  const b = (y) => {
3773
3773
  if (y.key === "Enter") {
3774
3774
  y.preventDefault(), y.stopPropagation();
3775
- const S = parseInt(h.r, 10) || 1, A = parseInt(h.c, 10) || 1;
3776
- s(S, A);
3775
+ const T = parseInt(m.r, 10) || 1, C = parseInt(m.c, 10) || 1;
3776
+ s(T, C);
3777
3777
  }
3778
3778
  };
3779
3779
  return window.addEventListener("keydown", b, !0), () => window.removeEventListener("keydown", b, !0);
3780
- }, [h.r, h.c, s]), /* @__PURE__ */ e.createElement(
3780
+ }, [m.r, m.c, s]), /* @__PURE__ */ e.createElement(
3781
3781
  "div",
3782
3782
  {
3783
3783
  className: "cme-matrix-hover-popover ck-only",
@@ -3786,16 +3786,16 @@ function Ge({ matrixType: l, x: o, y: n, onSelect: s, onMouseEnter: i, onMouseLe
3786
3786
  onMouseEnter: i,
3787
3787
  onMouseLeave: c
3788
3788
  },
3789
- /* @__PURE__ */ e.createElement("div", { className: "cme-matrix-hover-grid" }, Array.from({ length: x }).map((b, y) => /* @__PURE__ */ e.createElement("div", { key: y, className: "cme-matrix-hover-row" }, Array.from({ length: I }).map((S, A) => {
3790
- const U = parseInt(h.r, 10) || 0, K = parseInt(h.c, 10) || 0, J = y < U && A < K;
3789
+ /* @__PURE__ */ e.createElement("div", { className: "cme-matrix-hover-grid" }, Array.from({ length: x }).map((b, y) => /* @__PURE__ */ e.createElement("div", { key: y, className: "cme-matrix-hover-row" }, Array.from({ length: I }).map((T, C) => {
3790
+ const U = parseInt(m.r, 10) || 0, X = parseInt(m.c, 10) || 0, Z = y < U && C < X;
3791
3791
  return /* @__PURE__ */ e.createElement(
3792
3792
  "div",
3793
3793
  {
3794
- key: `${y}-${A}`,
3795
- className: `cme-matrix-hover-cell${J ? " selected" : ""}`,
3796
- onMouseEnter: () => u({ r: y + 1, c: A + 1 }),
3797
- onClick: (Y) => {
3798
- Y.preventDefault(), Y.stopPropagation(), s(y + 1, A + 1);
3794
+ key: `${y}-${C}`,
3795
+ className: `cme-matrix-hover-cell${Z ? " selected" : ""}`,
3796
+ onMouseEnter: () => u({ r: y + 1, c: C + 1 }),
3797
+ onClick: (K) => {
3798
+ K.preventDefault(), K.stopPropagation(), s(y + 1, C + 1);
3799
3799
  }
3800
3800
  }
3801
3801
  );
@@ -3805,9 +3805,9 @@ function Ge({ matrixType: l, x: o, y: n, onSelect: s, onMouseEnter: i, onMouseLe
3805
3805
  {
3806
3806
  type: "number",
3807
3807
  className: "cme-counter-val",
3808
- value: h.r,
3808
+ value: m.r,
3809
3809
  onChange: p,
3810
- onBlur: M,
3810
+ onBlur: A,
3811
3811
  min: "1",
3812
3812
  max: "10"
3813
3813
  }
@@ -3822,7 +3822,7 @@ function Ge({ matrixType: l, x: o, y: n, onSelect: s, onMouseEnter: i, onMouseLe
3822
3822
  {
3823
3823
  type: "number",
3824
3824
  className: "cme-counter-val",
3825
- value: h.c,
3825
+ value: m.c,
3826
3826
  onChange: k,
3827
3827
  onBlur: E,
3828
3828
  min: "1",
@@ -3837,58 +3837,58 @@ function Ge({ matrixType: l, x: o, y: n, onSelect: s, onMouseEnter: i, onMouseLe
3837
3837
  }) }, "▼"))))
3838
3838
  );
3839
3839
  }
3840
- let Z = !1, be = null, V = null;
3840
+ let F = !1, be = null, V = null;
3841
3841
  function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i }) {
3842
- const c = re(null), [h, u] = B(0), [x, I] = B(null), [p, M] = B(null), [k, E] = B(null), [b, y] = B(null);
3842
+ const c = re(null), [m, u] = B(0), [x, I] = B(null), [p, A] = B(null), [k, E] = B(null), [b, y] = B(null);
3843
3843
  re(null);
3844
- const [S, A] = B({ x: 0, y: 0 }), [U, K] = B(!1), J = re({ x: 0, y: 0 }), [Y, ge] = B(!1), [Te, ke] = B(!1), [We, _] = B(!1), se = re(null);
3844
+ const [T, C] = B({ x: 0, y: 0 }), [U, X] = B(!1), Z = re({ x: 0, y: 0 }), [K, ge] = B(!1), [Te, ke] = B(!1), [We, Y] = B(!1), se = re(null);
3845
3845
  O(() => {
3846
3846
  const t = (a) => {
3847
3847
  if (!U) return;
3848
- let d = a.clientX - J.current.x, g = a.clientY - J.current.y;
3848
+ let d = a.clientX - Z.current.x, g = a.clientY - Z.current.y;
3849
3849
  if (se.current) {
3850
- const w = se.current, m = -w.left, C = window.innerWidth - w.right, T = -w.top, R = window.innerHeight - w.bottom;
3851
- d < m && (d = m), d > C && (d = C), g < T && (g = T), g > R && (g = R);
3850
+ const w = se.current, h = -w.left, L = window.innerWidth - w.right, M = -w.top, R = window.innerHeight - w.bottom;
3851
+ d < h && (d = h), d > L && (d = L), g < M && (g = M), g > R && (g = R);
3852
3852
  }
3853
- A({ x: d, y: g });
3854
- }, r = () => K(!1);
3853
+ C({ x: d, y: g });
3854
+ }, r = () => X(!1);
3855
3855
  return U && (window.addEventListener("mousemove", t), window.addEventListener("mouseup", r)), () => {
3856
3856
  window.removeEventListener("mousemove", t), window.removeEventListener("mouseup", r);
3857
3857
  };
3858
3858
  }, [U]);
3859
3859
  const Ie = (t) => {
3860
3860
  if (t.target.closest(".cme-popup-controls")) return;
3861
- K(!0), J.current = {
3862
- x: t.clientX - S.x,
3863
- y: t.clientY - S.y
3861
+ X(!0), Z.current = {
3862
+ x: t.clientX - T.x,
3863
+ y: t.clientY - T.y
3864
3864
  };
3865
3865
  const r = document.querySelector(".cme-editor-popup");
3866
3866
  if (r) {
3867
3867
  const a = r.getBoundingClientRect();
3868
3868
  se.current = {
3869
- left: a.left - S.x,
3870
- top: a.top - S.y,
3871
- right: a.right - S.x,
3872
- bottom: a.bottom - S.y,
3869
+ left: a.left - T.x,
3870
+ top: a.top - T.y,
3871
+ right: a.right - T.x,
3872
+ bottom: a.bottom - T.y,
3873
3873
  width: a.width,
3874
3874
  height: a.height
3875
3875
  };
3876
3876
  }
3877
- }, P = l === "math" ? Ke : Ye, [f, ce] = B({
3877
+ }, _ = l === "math" ? Ke : Ye, [f, ce] = B({
3878
3878
  bold: !1,
3879
3879
  italic: !1,
3880
3880
  color: "none",
3881
3881
  fontFamily: "none",
3882
3882
  fontSize: "auto"
3883
- }), q = he(() => {
3884
- if (Z || window.__cmeIgnoreStyleUpdate && Date.now() - window.__cmeIgnoreStyleUpdate < 150) return;
3883
+ }), P = he(() => {
3884
+ if (F || window.__cmeIgnoreStyleUpdate && Date.now() - window.__cmeIgnoreStyleUpdate < 150) return;
3885
3885
  const t = c.current;
3886
3886
  if (!(!t || typeof t.queryStyle != "function"))
3887
3887
  try {
3888
3888
  const r = window.__cmeManualBold !== void 0 ? window.__cmeManualBold : t.queryStyle({ fontSeries: "b" }) === "all" || t.queryStyle({ variantStyle: "bold" }) === "all", a = window.__cmeManualItalic !== void 0 ? window.__cmeManualItalic : t.queryStyle({ variantStyle: "italic" }) === "all" || t.queryStyle({ shape: "it" }) === "all", d = window.__cmeManualFontFamily !== void 0 ? window.__cmeManualFontFamily : ["roman", "sans-serif", "monospace"].find(
3889
- (m) => t.queryStyle({ fontFamily: m }) === "all"
3889
+ (h) => t.queryStyle({ fontFamily: h }) === "all"
3890
3890
  ) || "none", g = window.__cmeManualFontSize !== void 0 ? window.__cmeManualFontSize : [5, 7, 9].find(
3891
- (m) => t.queryStyle({ fontSize: m }) === "all"
3891
+ (h) => t.queryStyle({ fontSize: h }) === "all"
3892
3892
  ) || "auto", w = [
3893
3893
  "black",
3894
3894
  "dimgray",
@@ -3915,9 +3915,9 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
3915
3915
  "violet",
3916
3916
  "gold"
3917
3917
  ].find(
3918
- (m) => t.queryStyle({ color: m }) === "all"
3918
+ (h) => t.queryStyle({ color: h }) === "all"
3919
3919
  ) || "none";
3920
- ce((m) => ({
3920
+ ce((h) => ({
3921
3921
  bold: r,
3922
3922
  italic: a,
3923
3923
  fontFamily: d,
@@ -3947,8 +3947,8 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
3947
3947
  }, [b]), O(() => {
3948
3948
  const t = setTimeout(() => Fe(), 50);
3949
3949
  return () => clearTimeout(t);
3950
- }, [h]), O(() => {
3951
- if (Z) return;
3950
+ }, [m]), O(() => {
3951
+ if (F) return;
3952
3952
  const t = V;
3953
3953
  if (!t) return;
3954
3954
  t.macros = { ...t.macros, ...window.__cme_macros || {} }, t.defaultMode = "math";
@@ -3959,7 +3959,7 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
3959
3959
  const d = a.match(/^\\ce\{([\s\S]*)\}$/i);
3960
3960
  d && (a = d[1]);
3961
3961
  }
3962
- a = X(a), a = ne(a), t.setValue ? t.setValue("", { silenceNotifications: !0 }) : t.value = "", t.executeCommand(["insert", a, { insertionMode: "replaceAll" }]);
3962
+ a = z(a), a = ne(a), t.setValue ? t.setValue("", { silenceNotifications: !0 }) : t.value = "", t.executeCommand(["insert", a, { insertionMode: "replaceAll" }]);
3963
3963
  }
3964
3964
  requestAnimationFrame(() => t.focus());
3965
3965
  };
@@ -3968,20 +3968,20 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
3968
3968
  const t = V;
3969
3969
  if (!t) return;
3970
3970
  const r = (a) => {
3971
- if (["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(a.key) ? (Z = !1, clearTimeout(be), window.__cmeManualBold = void 0, window.__cmeManualItalic = void 0, window.__cmeManualFontFamily = void 0, window.__cmeManualFontSize = void 0) : (a.key.length === 1 || a.key === " ") && (Z = !0, clearTimeout(be), be = setTimeout(() => {
3972
- Z = !1;
3971
+ if (["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(a.key) ? (F = !1, clearTimeout(be), window.__cmeManualBold = void 0, window.__cmeManualItalic = void 0, window.__cmeManualFontFamily = void 0, window.__cmeManualFontSize = void 0) : (a.key.length === 1 || a.key === " ") && (F = !0, clearTimeout(be), be = setTimeout(() => {
3972
+ F = !1;
3973
3973
  }, 500)), a.key.length === 1 && !a.ctrlKey && !a.metaKey && !a.altKey && /[a-zA-Z0-9]/.test(a.key)) {
3974
3974
  a.preventDefault(), a.stopPropagation();
3975
- const d = f.fontFamily === "sans-serif", g = f.fontFamily === "monospace", w = f.bold, m = f.italic;
3976
- let C = "\\mathrm";
3977
- d ? C = "\\mathsf" : g ? C = "\\mathtt" : m && !w ? C = "\\mathit" : w && !m && (C = "\\mathbf");
3978
- let T = `${C}{${a.key}}`;
3979
- w && m ? (T = `\\mathbfit{${a.key}}`, d && (T = `\\boldsymbol{\\mathsf{${a.key}}}`), g && (T = `\\boldsymbol{\\mathtt{${a.key}}}`)) : w && (d || g) && (T = `\\boldsymbol{${T}}`);
3980
- let R = T;
3981
- const Q = f.fontSize === "auto" ? 5 : parseInt(f.fontSize, 10);
3982
- if (Q !== 5) {
3975
+ const d = f.fontFamily === "sans-serif", g = f.fontFamily === "monospace", w = f.bold, h = f.italic;
3976
+ let L = "\\mathrm";
3977
+ d ? L = "\\mathsf" : g ? L = "\\mathtt" : h && !w ? L = "\\mathit" : w && !h && (L = "\\mathbf");
3978
+ let M = `${L}{${a.key}}`;
3979
+ w && h ? (M = `\\mathbfit{${a.key}}`, d && (M = `\\boldsymbol{\\mathsf{${a.key}}}`), g && (M = `\\boldsymbol{\\mathtt{${a.key}}}`)) : w && (d || g) && (M = `\\boldsymbol{${M}}`);
3980
+ let R = M;
3981
+ const j = f.fontSize === "auto" ? 5 : parseInt(f.fontSize, 10);
3982
+ if (j !== 5) {
3983
3983
  const G = { 1: "\\tiny", 2: "\\scriptsize", 3: "\\footnotesize", 4: "\\small", 5: "\\normalsize", 6: "\\large", 7: "\\Large", 8: "\\LARGE", 9: "\\huge", 10: "\\Huge" };
3984
- G[Q] && (R = `{${G[Q]} ${R}}`);
3984
+ G[j] && (R = `{${G[j]} ${R}}`);
3985
3985
  }
3986
3986
  f.color !== "none" && (R = `\\textcolor{${f.color}}{${R}}`), t.executeCommand(["insert", R]);
3987
3987
  return;
@@ -3989,7 +3989,7 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
3989
3989
  a.key === " " ? (a.preventDefault(), t.executeCommand(["insert", "\\, "])) : a.key === "Enter" && (a.preventDefault(), a.stopImmediatePropagation(), t.executeCommand("addRowAfter"));
3990
3990
  };
3991
3991
  return t.addEventListener("keydown", r, !0), () => t.removeEventListener("keydown", r, !0);
3992
- }, [l, f, q]), O(() => {
3992
+ }, [l, f, P]), O(() => {
3993
3993
  const t = V;
3994
3994
  if (!t) return;
3995
3995
  const r = () => {
@@ -3997,14 +3997,14 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
3997
3997
  const a = t.shadowRoot;
3998
3998
  if (!a) return;
3999
3999
  const d = a.querySelector(".ML__caret") || a.querySelector('[class*="caret"]');
4000
- d && d.scrollIntoView({ behavior: "auto", block: "nearest", inline: "nearest" }), q();
4000
+ d && d.scrollIntoView({ behavior: "auto", block: "nearest", inline: "nearest" }), P();
4001
4001
  }, 0);
4002
4002
  };
4003
- return t.addEventListener("selection-change", r), t.addEventListener("input", r), t.addEventListener("keydown", r), setTimeout(q, 50), () => {
4003
+ return t.addEventListener("selection-change", r), t.addEventListener("input", r), t.addEventListener("keydown", r), setTimeout(P, 50), () => {
4004
4004
  t.removeEventListener("selection-change", r), t.removeEventListener("input", r), t.removeEventListener("keydown", r);
4005
4005
  };
4006
- }, [q]);
4007
- const j = he((t) => {
4006
+ }, [P]);
4007
+ const J = he((t) => {
4008
4008
  const r = V;
4009
4009
  r && (r.focus(), r.executeCommand(["insert", t]));
4010
4010
  }, []), Be = he((t, r, a) => {
@@ -4014,11 +4014,11 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
4014
4014
  d += "#?", w < a - 1 && (d += " & ");
4015
4015
  g < r - 1 && (d += " \\\\ ");
4016
4016
  }
4017
- d += ` \\end{${t}}`, j(d);
4018
- }, [j]), De = (t) => {
4019
- t.stopPropagation(), ge((r) => !r), ke(!1), A({ x: 0, y: 0 });
4017
+ d += ` \\end{${t}}`, J(d);
4018
+ }, [J]), De = (t) => {
4019
+ t.stopPropagation(), ge((r) => !r), ke(!1), C({ x: 0, y: 0 });
4020
4020
  }, Ne = (t) => {
4021
- t.stopPropagation(), ke((r) => !r), ge(!1), A({ x: 0, y: 0 });
4021
+ t.stopPropagation(), ke((r) => !r), ge(!1), C({ x: 0, y: 0 });
4022
4022
  }, ue = (t) => {
4023
4023
  t && t.stopPropagation();
4024
4024
  const r = V;
@@ -4027,7 +4027,7 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
4027
4027
  return;
4028
4028
  }
4029
4029
  const a = r.getValue ? r.getValue("latex") : r.value, d = s || "";
4030
- !a || a.trim() === "" || a === d ? n && n() : _(!0);
4030
+ !a || a.trim() === "" || a === d ? n && n() : Y(!0);
4031
4031
  }, Re = () => {
4032
4032
  const t = V;
4033
4033
  if (!t) return;
@@ -4036,20 +4036,20 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
4036
4036
  n && n();
4037
4037
  return;
4038
4038
  }
4039
- l === "chem" && (r = _e(r)), r = X(r);
4039
+ l === "chem" && (r = _e(r)), r = z(r);
4040
4040
  const a = r.match(/^\\(mathrm|mathit|mathbf|mathsf|text)\{\\displaylines\{([\s\S]*)\}\}$/);
4041
4041
  if (a) {
4042
4042
  const d = a[1];
4043
- r = `\\displaylines{${a[2].split("\\\\").map((C) => `\\${d}{${C.trim()}}`).join(" \\\\ ")}}`;
4043
+ r = `\\displaylines{${a[2].split("\\\\").map((L) => `\\${d}{${L.trim()}}`).join(" \\\\ ")}}`;
4044
4044
  }
4045
4045
  r = r.replace(/[\r\n]+/g, " "), o && o(r), t.setValue ? t.setValue("") : t.value = "", n && n();
4046
4046
  };
4047
- return z(
4047
+ return Q(
4048
4048
  /* @__PURE__ */ e.createElement(
4049
4049
  "div",
4050
4050
  {
4051
- className: `cme-editor-popup ${Y ? "maximized" : ""} ${Te ? "minimized" : ""}`,
4052
- style: { transform: `translate(${S.x}px, ${S.y}px)` },
4051
+ className: `cme-editor-popup ${K ? "maximized" : ""} ${Te ? "minimized" : ""}`,
4052
+ style: { transform: `translate(${T.x}px, ${T.y}px)` },
4053
4053
  onMouseDown: (t) => t.stopPropagation()
4054
4054
  },
4055
4055
  /* @__PURE__ */ e.createElement("div", { className: "cme-popup-topbar" }, /* @__PURE__ */ e.createElement(
@@ -4061,8 +4061,8 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
4061
4061
  },
4062
4062
  /* @__PURE__ */ e.createElement("span", null, i ? l === "math" ? "Edit Math Formula" : "Edit Chemistry Formula" : l === "math" ? "Math Editor" : "Chemistry Editor")
4063
4063
  ), /* @__PURE__ */ e.createElement("div", { className: "cme-popup-controls" }, /* @__PURE__ */ e.createElement("button", { type: "button", className: "cme-popup-btn", onClick: Ne, title: "Minimize" }, "—"), /* @__PURE__ */ e.createElement("button", { type: "button", className: "cme-popup-btn", onClick: De, title: "Maximize" }, "⤢"), /* @__PURE__ */ e.createElement("button", { type: "button", className: "cme-popup-btn", onClick: ue, title: "Close" }, "✕"))),
4064
- /* @__PURE__ */ e.createElement("div", { className: "cme-toolbar", role: "toolbar", "aria-label": "Symbol palette" }, /* @__PURE__ */ e.createElement("div", { className: "cme-toolbar-groups" }, P.map((t, r) => {
4065
- const a = h === r;
4064
+ /* @__PURE__ */ e.createElement("div", { className: "cme-toolbar", role: "toolbar", "aria-label": "Symbol palette" }, /* @__PURE__ */ e.createElement("div", { className: "cme-toolbar-groups" }, _.map((t, r) => {
4065
+ const a = m === r;
4066
4066
  return /* @__PURE__ */ e.createElement(
4067
4067
  "button",
4068
4068
  {
@@ -4098,7 +4098,7 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
4098
4098
  );
4099
4099
  })), /* @__PURE__ */ e.createElement("div", { className: "cme-toolbar-items" }, (() => {
4100
4100
  var d;
4101
- const t = ((d = P[h]) == null ? void 0 : d.items) || [], r = t.some((g) => g.type === "sep"), a = [];
4101
+ const t = ((d = _[m]) == null ? void 0 : d.items) || [], r = t.some((g) => g.type === "sep"), a = [];
4102
4102
  if (r) {
4103
4103
  let g = { cols: 2, small: !1, cls: "", items: [], moreItems: null };
4104
4104
  for (const w of t)
@@ -4125,29 +4125,32 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
4125
4125
  type: "button",
4126
4126
  className: "cme-more-trigger-btn",
4127
4127
  title: "more",
4128
- onMouseDown: (m) => {
4129
- if (m.preventDefault(), b && b.items === g.moreItems)
4128
+ onMouseDown: (h) => {
4129
+ h.preventDefault();
4130
+ },
4131
+ onClick: (h) => {
4132
+ if (h.stopPropagation(), b && b.items === g.moreItems)
4130
4133
  y(null);
4131
4134
  else {
4132
- const C = m.currentTarget.getBoundingClientRect();
4133
- y({ cx: C.left + C.width / 2, y: C.bottom, items: g.moreItems, cols: g.moreCols, isTemplate: P[h].isTemplate || P[h].label === "√(□)" || P[h].isMatrix });
4135
+ const L = h.currentTarget.getBoundingClientRect(), M = _[m] || {};
4136
+ y({ cx: L.left + L.width / 2, y: L.bottom, items: g.moreItems, cols: g.moreCols, isTemplate: M.isTemplate || M.label === "√(□)" || M.isMatrix });
4134
4137
  }
4135
4138
  }
4136
4139
  },
4137
4140
  "▶"
4138
4141
  ),
4139
- g.items.map((m, C) => {
4140
- const T = P[h];
4141
- if (m.type === "dropdown") {
4142
- const N = m.label === "Font...", v = m.label === "Size", $ = N && f.fontFamily !== "none", ee = v && f.fontSize !== "auto" && f.fontSize !== "5", te = N ? f.fontFamily === "none" ? "" : f.fontFamily : v ? f.fontSize === "auto" || f.fontSize === "5" ? "" : f.fontSize : "";
4142
+ g.items.map((h, L) => {
4143
+ const M = _[m];
4144
+ if (h.type === "dropdown") {
4145
+ const N = h.label === "Font...", v = h.label === "Size", $ = N && f.fontFamily !== "none", ee = v && f.fontSize !== "auto" && f.fontSize !== "5", te = N ? f.fontFamily === "none" ? "" : f.fontFamily : v ? f.fontSize === "auto" || f.fontSize === "5" ? "" : f.fontSize : "";
4143
4146
  return /* @__PURE__ */ e.createElement(
4144
4147
  "select",
4145
4148
  {
4146
- key: C,
4149
+ key: L,
4147
4150
  className: `cme-btn template${$ || ee ? " active" : ""}`,
4148
4151
  value: te,
4149
4152
  style: {
4150
- width: m.width || "60px",
4153
+ width: h.width || "60px",
4151
4154
  height: "18px",
4152
4155
  minHeight: "18px",
4153
4156
  maxHeight: "18px",
@@ -4160,43 +4163,43 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
4160
4163
  gridColumn: g.cols === 3 || g.cols === 1 ? "span 1" : "span 2"
4161
4164
  },
4162
4165
  onChange: (le) => {
4163
- const F = le.target.value, H = V;
4164
- !H || typeof H.applyStyle != "function" || (H.focus(), N ? H.applyStyle({ fontFamily: F || "none" }) : v && H.applyStyle({ fontSize: F ? parseInt(F, 10) : "auto" }), q());
4166
+ const q = le.target.value, H = V;
4167
+ !H || typeof H.applyStyle != "function" || (H.focus(), N ? H.applyStyle({ fontFamily: q || "none" }) : v && H.applyStyle({ fontSize: q ? parseInt(q, 10) : "auto" }), P());
4165
4168
  }
4166
4169
  },
4167
- /* @__PURE__ */ e.createElement("option", { value: "" }, m.label),
4170
+ /* @__PURE__ */ e.createElement("option", { value: "" }, h.label),
4168
4171
  N && /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement("option", { value: "roman" }, "Times"), /* @__PURE__ */ e.createElement("option", { value: "sans-serif" }, "Helvetica"), /* @__PURE__ */ e.createElement("option", { value: "monospace" }, "Courier")),
4169
4172
  v && /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement("option", { value: "5" }, "12px"), /* @__PURE__ */ e.createElement("option", { value: "7" }, "16px"), /* @__PURE__ */ e.createElement("option", { value: "9" }, "20px"))
4170
4173
  );
4171
4174
  }
4172
- if (T.isMatrix && !m.directInsert)
4175
+ if (M.isMatrix && !h.directInsert)
4173
4176
  return /* @__PURE__ */ e.createElement(
4174
4177
  "div",
4175
4178
  {
4176
- key: C,
4179
+ key: L,
4177
4180
  className: "cme-matrix-btn-wrapper"
4178
4181
  },
4179
4182
  /* @__PURE__ */ e.createElement(
4180
4183
  "button",
4181
4184
  {
4182
4185
  type: "button",
4183
- className: `cme-btn template${m.cls ? ` ${m.cls}` : ""}${T.isMatrix ? " cme-matrix-btn-small" : ""}`,
4184
- title: m.title || m.label || m.insert,
4186
+ className: `cme-btn template${h.cls ? ` ${h.cls}` : ""}${M.isMatrix ? " cme-matrix-btn-small" : ""}`,
4187
+ title: h.title || h.label || h.insert,
4185
4188
  onMouseDown: (N) => {
4186
- if (N.preventDefault(), N.stopPropagation(), (x == null ? void 0 : x.type) === m.insert)
4189
+ if (N.preventDefault(), N.stopPropagation(), (x == null ? void 0 : x.type) === h.insert)
4187
4190
  I(null);
4188
4191
  else {
4189
- Z || (window.__cmeManualBold = void 0, window.__cmeManualItalic = void 0, window.__cmeManualFontFamily = void 0, window.__cmeManualFontSize = void 0);
4192
+ F || (window.__cmeManualBold = void 0, window.__cmeManualItalic = void 0, window.__cmeManualFontFamily = void 0, window.__cmeManualFontSize = void 0);
4190
4193
  const v = N.currentTarget.getBoundingClientRect();
4191
4194
  I({
4192
- type: m.insert,
4195
+ type: h.insert,
4193
4196
  x: v.left + v.width / 2,
4194
4197
  y: v.bottom
4195
4198
  });
4196
4199
  }
4197
4200
  }
4198
4201
  },
4199
- typeof m.label == "object" ? m.label : /* @__PURE__ */ e.createElement(
4202
+ typeof h.label == "object" ? h.label : /* @__PURE__ */ e.createElement(
4200
4203
  "math-field",
4201
4204
  {
4202
4205
  "read-only": !0,
@@ -4215,62 +4218,62 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
4215
4218
  cursor: "pointer"
4216
4219
  }
4217
4220
  },
4218
- pe(m.mathLabel != null ? m.mathLabel : m.insert)
4221
+ pe(h.mathLabel != null ? h.mathLabel : h.insert)
4219
4222
  )
4220
4223
  )
4221
4224
  );
4222
- const R = m.action === "BOLD", Q = m.action === "ITALIC", G = m.action === "TEXT_COLOR", Oe = R && f.bold || Q && f.italic || G && f.color !== "none" && f.color !== "black";
4225
+ const R = h.action === "BOLD", j = h.action === "ITALIC", G = h.action === "TEXT_COLOR", Oe = R && f.bold || j && f.italic || G && f.color !== "none" && f.color !== "black";
4223
4226
  return /* @__PURE__ */ e.createElement(
4224
4227
  "button",
4225
4228
  {
4226
- key: `${T.label}-${w * 4 + C}`,
4229
+ key: `${M.label}-${w * 4 + L}`,
4227
4230
  type: "button",
4228
- className: `cme-btn${T.isTemplate ? " template" : ""}${m.cls ? ` ${m.cls}` : ""}${Oe ? " active" : ""}`,
4229
- title: m.title || m.label || m.insert,
4231
+ className: `cme-btn${M.isTemplate ? " template" : ""}${h.cls ? ` ${h.cls}` : ""}${Oe ? " active" : ""}`,
4232
+ title: h.title || h.label || h.insert,
4230
4233
  onMouseDown: (N) => {
4231
- var $, ee, te, le, F, H, we;
4234
+ var $, ee, te, le, q, H, we;
4232
4235
  N.preventDefault();
4233
4236
  const v = c.current;
4234
- if (m.action === "SPECIAL_CHARS") {
4235
- const L = N.currentTarget.getBoundingClientRect();
4236
- M({ x: L.left, y: L.bottom + 4 });
4237
- } else if (m.action === "TEXT_COLOR") {
4238
- const L = N.currentTarget.getBoundingClientRect();
4239
- E({ x: L.left, y: L.bottom + 4 });
4240
- } else if (m.action === "BOLD") {
4237
+ if (h.action === "SPECIAL_CHARS") {
4238
+ const S = N.currentTarget.getBoundingClientRect();
4239
+ A({ x: S.left, y: S.bottom + 4 });
4240
+ } else if (h.action === "TEXT_COLOR") {
4241
+ const S = N.currentTarget.getBoundingClientRect();
4242
+ E({ x: S.left, y: S.bottom + 4 });
4243
+ } else if (h.action === "BOLD") {
4241
4244
  if (v) {
4242
4245
  v.focus();
4243
- const L = !f.bold;
4244
- window.__cmeManualBold = L;
4246
+ const S = !f.bold;
4247
+ window.__cmeManualBold = S;
4245
4248
  const D = v.selection;
4246
4249
  if (D && !D.isCollapsed) {
4247
4250
  let W = v.getValue(D);
4248
- W = W.replace(/\\mathrm{([^}]*)}/g, "$1").replace(/\\mathbf{([^}]*)}/g, "$1").replace(/\\mathit{([^}]*)}/g, "$1").replace(/\\mathbfit{([^}]*)}/g, "$1"), L && f.italic ? v.executeCommand(["insert", `\\mathbfit{${W}}`]) : L ? v.executeCommand(["insert", `\\mathbf{${W}}`]) : f.italic ? v.executeCommand(["insert", `\\mathit{${W}}`]) : v.executeCommand(["insert", `\\mathrm{${W}}`]);
4251
+ W = W.replace(/\\mathrm{([^}]*)}/g, "$1").replace(/\\mathbf{([^}]*)}/g, "$1").replace(/\\mathit{([^}]*)}/g, "$1").replace(/\\mathbfit{([^}]*)}/g, "$1"), S && f.italic ? v.executeCommand(["insert", `\\mathbfit{${W}}`]) : S ? v.executeCommand(["insert", `\\mathbf{${W}}`]) : f.italic ? v.executeCommand(["insert", `\\mathit{${W}}`]) : v.executeCommand(["insert", `\\mathrm{${W}}`]);
4249
4252
  }
4250
- ce((W) => ({ ...W, bold: L }));
4253
+ ce((W) => ({ ...W, bold: S }));
4251
4254
  }
4252
- } else if (m.action === "ITALIC") {
4255
+ } else if (h.action === "ITALIC") {
4253
4256
  if (v) {
4254
4257
  v.focus();
4255
- const L = !f.italic;
4256
- window.__cmeManualItalic = L;
4258
+ const S = !f.italic;
4259
+ window.__cmeManualItalic = S;
4257
4260
  const D = v.selection;
4258
4261
  if (D && !D.isCollapsed) {
4259
4262
  let W = v.getValue(D);
4260
- W = W.replace(/\\mathrm{([^}]*)}/g, "$1").replace(/\\mathbf{([^}]*)}/g, "$1").replace(/\\mathit{([^}]*)}/g, "$1").replace(/\\mathbfit{([^}]*)}/g, "$1"), f.bold && L ? v.executeCommand(["insert", `\\mathbfit{${W}}`]) : f.bold ? v.executeCommand(["insert", `\\mathbf{${W}}`]) : L ? v.executeCommand(["insert", `\\mathit{${W}}`]) : v.executeCommand(["insert", `\\mathrm{${W}}`]);
4263
+ W = W.replace(/\\mathrm{([^}]*)}/g, "$1").replace(/\\mathbf{([^}]*)}/g, "$1").replace(/\\mathit{([^}]*)}/g, "$1").replace(/\\mathbfit{([^}]*)}/g, "$1"), f.bold && S ? v.executeCommand(["insert", `\\mathbfit{${W}}`]) : f.bold ? v.executeCommand(["insert", `\\mathbf{${W}}`]) : S ? v.executeCommand(["insert", `\\mathit{${W}}`]) : v.executeCommand(["insert", `\\mathrm{${W}}`]);
4261
4264
  }
4262
- ce((W) => ({ ...W, italic: L }));
4265
+ ce((W) => ({ ...W, italic: S }));
4263
4266
  }
4264
- } else m.action === "UNDO" ? ($ = c.current) == null || $.executeCommand("undo") : m.action === "REDO" ? (ee = c.current) == null || ee.executeCommand("redo") : m.action === "CUT" ? ((te = c.current) == null || te.focus(), (le = c.current) == null || le.executeCommand("cutToClipboard")) : m.action === "COPY" ? ((F = c.current) == null || F.focus(), (H = c.current) == null || H.executeCommand("copyToClipboard")) : m.action === "PASTE" ? ((we = c.current) == null || we.focus(), navigator.clipboard.readText().then((L) => {
4267
+ } else h.action === "UNDO" ? ($ = c.current) == null || $.executeCommand("undo") : h.action === "REDO" ? (ee = c.current) == null || ee.executeCommand("redo") : h.action === "CUT" ? ((te = c.current) == null || te.focus(), (le = c.current) == null || le.executeCommand("cutToClipboard")) : h.action === "COPY" ? ((q = c.current) == null || q.focus(), (H = c.current) == null || H.executeCommand("copyToClipboard")) : h.action === "PASTE" ? ((we = c.current) == null || we.focus(), navigator.clipboard.readText().then((S) => {
4265
4268
  var D;
4266
- (D = c.current) == null || D.executeCommand(["insert", L]);
4267
- }).catch((L) => {
4269
+ (D = c.current) == null || D.executeCommand(["insert", S]);
4270
+ }).catch((S) => {
4268
4271
  var D;
4269
4272
  (D = c.current) == null || D.executeCommand("pasteFromClipboard");
4270
- })) : j(m.insert);
4273
+ })) : J(h.insert);
4271
4274
  }
4272
4275
  },
4273
- (T.isTemplate || T.label === "√(□)" || T.isMatrix || m.isWidget) && m.insert && !m.action && !m.forceLabel ? /* @__PURE__ */ e.createElement(
4276
+ (M.isTemplate || M.label === "√(□)" || M.isMatrix || h.isWidget) && h.insert && !h.action && !h.forceLabel ? /* @__PURE__ */ e.createElement(
4274
4277
  "math-field",
4275
4278
  {
4276
4279
  "read-only": !0,
@@ -4289,13 +4292,13 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
4289
4292
  cursor: "pointer"
4290
4293
  }
4291
4294
  },
4292
- pe(m.insert)
4293
- ) : m.label
4295
+ pe(h.insert)
4296
+ ) : h.label
4294
4297
  );
4295
4298
  })
4296
4299
  ));
4297
4300
  })())),
4298
- b && z(/* @__PURE__ */ e.createElement(
4301
+ b && Q(/* @__PURE__ */ e.createElement(
4299
4302
  "div",
4300
4303
  {
4301
4304
  ref: (t) => {
@@ -4306,7 +4309,7 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
4306
4309
  const w = a.getBoundingClientRect();
4307
4310
  d + r.width > w.right - 4 && (d = w.right - r.width - 4), d < w.left + 4 && (d = w.left + 4), g + r.height > w.bottom - 4 && (g = w.bottom - r.height - 4);
4308
4311
  }
4309
- d + r.width > window.innerWidth - 4 && (d = window.innerWidth - r.width - 4), g + r.height > window.innerHeight - 4 && (g = window.innerHeight - r.height - 4), d < 4 && (d = 4), t.style.left = `${d}px`, t.style.top = `${g}px`, t.style.transform = "none", t.style.visibility = "visible";
4312
+ d + r.width > window.innerWidth - 4 && (d = window.innerWidth - r.width - 4), g + r.height > window.innerHeight - 4 && (g = window.innerHeight - r.height - 4), d < 4 && (d = 4), t.style.left = `${d}px`, t.style.top = `${g}px`, t.style.transform = "none";
4310
4313
  });
4311
4314
  },
4312
4315
  className: "cme-more-popup",
@@ -4315,8 +4318,7 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
4315
4318
  left: `${b.cx}px`,
4316
4319
  top: `${b.y}px`,
4317
4320
  transform: "translateX(-50%)",
4318
- visibility: "hidden",
4319
- zIndex: 1e5,
4321
+ zIndex: 2147483647,
4320
4322
  gridTemplateColumns: `repeat(${b.cols || 1}, auto)`
4321
4323
  }
4322
4324
  },
@@ -4328,7 +4330,7 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
4328
4330
  className: `cme-more-popup-btn ${t.cls || ""}`,
4329
4331
  title: t.title || t.label || t.insert,
4330
4332
  onMouseDown: (a) => {
4331
- a.preventDefault(), j(t.insert), y(null);
4333
+ a.preventDefault(), J(t.insert), y(null);
4332
4334
  }
4333
4335
  },
4334
4336
  t.insert && !t.action && (t.cls === "template" || t.isWidget) ? /* @__PURE__ */ e.createElement(
@@ -4369,7 +4371,7 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
4369
4371
  "math-field",
4370
4372
  {
4371
4373
  ref: (t) => {
4372
- c.current = t, V = t;
4374
+ c.current = t, V = t, t && (t.inlineShortcuts = Object.assign({}, t.inlineShortcuts, { "*": "*" }));
4373
4375
  },
4374
4376
  class: "cme-mathfield",
4375
4377
  tabIndex: 0,
@@ -4380,13 +4382,13 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
4380
4382
  ),
4381
4383
  /* @__PURE__ */ e.createElement("div", { className: "cme-popup-footer" }, /* @__PURE__ */ e.createElement("button", { type: "button", className: "cme-insert-btn", onClick: Re }, i ? "Update" : "Insert"), /* @__PURE__ */ e.createElement("button", { type: "button", className: "cme-cancel-btn", onClick: ue }, "Cancel")),
4382
4384
  We && /* @__PURE__ */ e.createElement("div", { className: "cme-confirm-overlay", onMouseDown: (t) => {
4383
- t.stopPropagation(), _(!1);
4385
+ t.stopPropagation(), Y(!1);
4384
4386
  } }, /* @__PURE__ */ e.createElement("div", { className: "cme-confirm-modal", onMouseDown: (t) => t.stopPropagation() }, /* @__PURE__ */ e.createElement("p", null, "Are you sure you want to leave? The changes you made will be lost."), /* @__PURE__ */ e.createElement("div", { className: "cme-confirm-actions" }, /* @__PURE__ */ e.createElement("button", { type: "button", className: "cme-confirm-close-btn", onClick: (t) => {
4385
- t.stopPropagation(), _(!1), n && n();
4387
+ t.stopPropagation(), Y(!1), n && n();
4386
4388
  } }, "Close"), /* @__PURE__ */ e.createElement("button", { type: "button", className: "cme-confirm-cancel-btn", onClick: (t) => {
4387
- t.stopPropagation(), _(!1);
4389
+ t.stopPropagation(), Y(!1);
4388
4390
  } }, "Cancel")))),
4389
- x && z(
4391
+ x && Q(
4390
4392
  /* @__PURE__ */ e.createElement(
4391
4393
  Ge,
4392
4394
  {
@@ -4404,21 +4406,21 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
4404
4406
  ),
4405
4407
  document.body
4406
4408
  ),
4407
- p && z(
4409
+ p && Q(
4408
4410
  /* @__PURE__ */ e.createElement(
4409
4411
  je,
4410
4412
  {
4411
4413
  isOpen: !!p,
4412
4414
  position: p,
4413
- onClose: () => M(null),
4415
+ onClose: () => A(null),
4414
4416
  onInsert: (t) => {
4415
- j(t), M(null);
4417
+ J(t), A(null);
4416
4418
  }
4417
4419
  }
4418
4420
  ),
4419
4421
  document.body
4420
4422
  ),
4421
- k && z(
4423
+ k && Q(
4422
4424
  /* @__PURE__ */ e.createElement(
4423
4425
  "div",
4424
4426
  {
@@ -4427,7 +4429,7 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
4427
4429
  position: "fixed",
4428
4430
  left: Math.min(k.x, window.innerWidth - 160) + "px",
4429
4431
  top: Math.min(k.y, window.innerHeight - 100) + "px",
4430
- zIndex: 1e5,
4432
+ zIndex: 2147483647,
4431
4433
  background: "#fff",
4432
4434
  border: "1px solid #ccc",
4433
4435
  padding: "6px",
@@ -4481,7 +4483,7 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
4481
4483
  onMouseDown: (a) => {
4482
4484
  a.preventDefault(), a.stopPropagation();
4483
4485
  const d = c.current;
4484
- d && typeof d.applyStyle == "function" && (d.focus(), d.applyStyle({ color: t === "black" ? "none" : t }), q()), E(null);
4486
+ d && typeof d.applyStyle == "function" && (d.focus(), d.applyStyle({ color: t === "black" ? "none" : t }), P()), E(null);
4485
4487
  }
4486
4488
  }
4487
4489
  );