digi-mathchem-editor 1.0.25 → 1.0.26

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,4 +1,4 @@
1
- import e, { useState as T, useEffect as D, useMemo as Oe, useRef as le, useCallback as fe } from "react";
1
+ import e, { useState as T, useEffect as D, useMemo as Oe, useRef as le, useCallback as Ee } from "react";
2
2
  import { createPortal as re } from "react-dom";
3
3
  import { FontAwesomeIcon as ge } from "@fortawesome/react-fontawesome";
4
4
  import { faBold as Fe, faItalic as Ze } from "@fortawesome/free-solid-svg-icons";
@@ -302,10 +302,10 @@ const Je = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAYAAAD0eNT6AA
302
302
  function pe(l) {
303
303
  const n = l == null ? void 0 : l.shadowRoot;
304
304
  if (!n) return;
305
- const o = l.hasAttribute("read-only") || l.hasAttribute("readonly"), c = o ? "readonly" : "editable";
305
+ const s = l.hasAttribute("read-only") || l.hasAttribute("readonly"), o = s ? "readonly" : "editable";
306
306
  let a = n.querySelector(`[${He}]`);
307
- a && a.getAttribute("data-cache") === c || (a || (a = document.createElement("style"), a.setAttribute(He, "true"), n.appendChild(a)), a.setAttribute("data-cache", c), a.textContent = `
308
- ${o ? `
307
+ a && a.getAttribute("data-cache") === o || (a || (a = document.createElement("style"), a.setAttribute(He, "true"), n.appendChild(a)), a.setAttribute("data-cache", o), a.textContent = `
308
+ ${s ? `
309
309
  :host, :host * { cursor: pointer !important; }
310
310
  .ML__latex, .ML__content, .ML__container, .ML__virtual-keyboard-toggle { cursor: pointer !important; }
311
311
  ` : ""}
@@ -318,7 +318,7 @@ function st() {
318
318
  let ve = null;
319
319
  function ct() {
320
320
  ve || (st(), ve = new MutationObserver((l) => {
321
- var n, o, c;
321
+ var n, s, o;
322
322
  for (const a of l) {
323
323
  if (a.type === "attributes" && ((n = a.target.tagName) == null ? void 0 : n.toLowerCase()) === "math-field") {
324
324
  pe(a.target);
@@ -326,7 +326,7 @@ function ct() {
326
326
  }
327
327
  if (a.addedNodes)
328
328
  for (const m of a.addedNodes)
329
- m instanceof Element && (((o = m.tagName) == null ? void 0 : o.toLowerCase()) === "math-field" && requestAnimationFrame(() => pe(m)), (c = m.querySelectorAll) == null || c.call(m, "math-field").forEach((b) => requestAnimationFrame(() => pe(b))));
329
+ m instanceof Element && (((s = m.tagName) == null ? void 0 : s.toLowerCase()) === "math-field" && requestAnimationFrame(() => pe(m)), (o = m.querySelectorAll) == null || o.call(m, "math-field").forEach((b) => requestAnimationFrame(() => pe(b))));
330
330
  }
331
331
  }), ve.observe(document.body, {
332
332
  childList: !0,
@@ -347,12 +347,12 @@ const je = [
347
347
  ], ht = () => {
348
348
  const l = [];
349
349
  return je.slice(1).forEach((n) => {
350
- n.ranges.forEach((o) => {
351
- for (let c = o[0]; c <= o[1]; c++) {
352
- if (c >= 127 && c <= 159) continue;
353
- const a = String.fromCodePoint(c);
350
+ n.ranges.forEach((s) => {
351
+ for (let o = s[0]; o <= s[1]; o++) {
352
+ if (o >= 127 && o <= 159) continue;
353
+ const a = String.fromCodePoint(o);
354
354
  new RegExp("\\p{C}", "u").test(a) || l.push({
355
- code: c.toString(16).toUpperCase().padStart(4, "0"),
355
+ code: o.toString(16).toUpperCase().padStart(4, "0"),
356
356
  char: a,
357
357
  category: n.id
358
358
  });
@@ -360,37 +360,37 @@ const je = [
360
360
  });
361
361
  }), l;
362
362
  }, mt = ht();
363
- function dt({ isOpen: l, onClose: n, onInsert: o, position: c }) {
364
- const [a, m] = T(""), [b, p] = T("All");
363
+ function dt({ isOpen: l, onClose: n, onInsert: s, position: o }) {
364
+ const [a, m] = T(""), [b, d] = T("All");
365
365
  D(() => {
366
- l && (m(""), p("All"));
366
+ l && (m(""), d("All"));
367
367
  }, [l]);
368
- const y = Oe(() => {
368
+ const E = Oe(() => {
369
369
  let u = mt;
370
- if (b !== "All" && (u = u.filter((M) => M.category === b)), a.trim()) {
371
- const M = a.trim().toUpperCase();
372
- u = u.filter((x) => x.code.includes(M));
370
+ if (b !== "All" && (u = u.filter((y) => y.category === b)), a.trim()) {
371
+ const y = a.trim().toUpperCase();
372
+ u = u.filter((f) => f.code.includes(y));
373
373
  }
374
374
  return u;
375
375
  }, [b, a]), L = Oe(() => {
376
376
  if (b !== "All" && !a.trim())
377
- return { [b]: y };
377
+ return { [b]: E };
378
378
  const u = {};
379
- return y.forEach((M) => {
380
- u[M.category] || (u[M.category] = []), u[M.category].push(M);
379
+ return E.forEach((y) => {
380
+ u[y.category] || (u[y.category] = []), u[y.category].push(y);
381
381
  }), u;
382
- }, [y, b, a]), k = (u) => {
382
+ }, [E, b, a]), k = (u) => {
383
383
  u.key === "Escape" && n();
384
384
  };
385
385
  if (D(() => (l && window.addEventListener("keydown", k), () => window.removeEventListener("keydown", k)), [l]), !l) return null;
386
- let v = { top: "50%", left: "50%", transform: "translate(-50%, -50%)" };
387
- if (c) {
388
- let u = c.x - 120, M = c.y;
389
- u < 10 && (u = 10), u + 230 > window.innerWidth && (u = window.innerWidth - 240), M + 200 > window.innerHeight && (M = window.innerHeight - 210), v = { top: `${M}px`, left: `${u}px` };
386
+ let x = { top: "50%", left: "50%", transform: "translate(-50%, -50%)" };
387
+ if (o) {
388
+ let u = o.x - 120, y = o.y;
389
+ u < 10 && (u = 10), u + 230 > window.innerWidth && (u = window.innerWidth - 240), y + 200 > window.innerHeight && (y = window.innerHeight - 210), x = { top: `${y}px`, left: `${u}px` };
390
390
  }
391
391
  return /* @__PURE__ */ e.createElement("div", { className: "scm-overlay", onMouseDown: (u) => {
392
392
  u.stopPropagation(), n();
393
- } }, /* @__PURE__ */ e.createElement("div", { className: "scm-modal", style: v, onMouseDown: (u) => u.stopPropagation() }, /* @__PURE__ */ e.createElement("div", { className: "scm-toolbar" }, /* @__PURE__ */ e.createElement(
393
+ } }, /* @__PURE__ */ e.createElement("div", { className: "scm-modal", style: x, onMouseDown: (u) => u.stopPropagation() }, /* @__PURE__ */ e.createElement("div", { className: "scm-toolbar" }, /* @__PURE__ */ e.createElement(
394
394
  "input",
395
395
  {
396
396
  type: "text",
@@ -403,24 +403,24 @@ function dt({ isOpen: l, onClose: n, onInsert: o, position: c }) {
403
403
  "select",
404
404
  {
405
405
  value: b,
406
- onChange: (u) => p(u.target.value),
406
+ onChange: (u) => d(u.target.value),
407
407
  className: "scm-category-select"
408
408
  },
409
409
  je.map((u) => /* @__PURE__ */ e.createElement("option", { key: u.id, value: u.id }, u.name))
410
- )), /* @__PURE__ */ e.createElement("div", { className: "scm-body" }, /* @__PURE__ */ e.createElement("div", { className: "scm-grid-container" }, Object.entries(L).map(([u, M]) => /* @__PURE__ */ e.createElement("div", { key: u, className: "scm-category-group" }, /* @__PURE__ */ e.createElement("div", { className: "scm-char-grid" }, M.map((x) => /* @__PURE__ */ e.createElement(
410
+ )), /* @__PURE__ */ e.createElement("div", { className: "scm-body" }, /* @__PURE__ */ e.createElement("div", { className: "scm-grid-container" }, Object.entries(L).map(([u, y]) => /* @__PURE__ */ e.createElement("div", { key: u, className: "scm-category-group" }, /* @__PURE__ */ e.createElement("div", { className: "scm-char-grid" }, y.map((f) => /* @__PURE__ */ e.createElement(
411
411
  "button",
412
412
  {
413
- key: x.code,
413
+ key: f.code,
414
414
  className: "scm-char-btn",
415
415
  onClick: () => {
416
- o(x.char), n();
416
+ s(f.char), n();
417
417
  },
418
- title: `U+${x.code}`
418
+ title: `U+${f.code}`
419
419
  },
420
- x.char
421
- ))))), y.length === 0 && /* @__PURE__ */ e.createElement("div", { className: "scm-no-results" }, "No characters found.")))));
420
+ f.char
421
+ ))))), E.length === 0 && /* @__PURE__ */ e.createElement("div", { className: "scm-no-results" }, "No characters found.")))));
422
422
  }
423
- const pt = "1.0.25", bt = {
423
+ const pt = "1.0.26", bt = {
424
424
  version: pt
425
425
  };
426
426
  window.__cme_macros = {
@@ -452,66 +452,66 @@ typeof window < "u" && (window.MathfieldElement ? window.MathfieldElement.fontsD
452
452
  window.__ckMathWidgets = window.__ckMathWidgets || /* @__PURE__ */ new Map();
453
453
  window.__ckMathWidgetClickHandler = null;
454
454
  function gt(l) {
455
- var o, c, a, m, b;
455
+ var s, o, a, m, b;
456
456
  if (!l) return null;
457
457
  const n = typeof l.composedPath == "function" ? l.composedPath() : [l];
458
- for (const p of n)
459
- if (p instanceof HTMLElement && ((o = p.classList) != null && o.contains("ck-math-widget") || (c = p.dataset) != null && c.mathId || (a = p.classList) != null && a.contains("ck-widget") && ((m = p.querySelector) != null && m.call(p, ".ck-math-widget-inner"))))
460
- return p;
458
+ for (const d of n)
459
+ if (d instanceof HTMLElement && ((s = d.classList) != null && s.contains("ck-math-widget") || (o = d.dataset) != null && o.mathId || (a = d.classList) != null && a.contains("ck-widget") && ((m = d.querySelector) != null && m.call(d, ".ck-math-widget-inner"))))
460
+ return d;
461
461
  return l instanceof Element ? (b = l.closest) == null ? void 0 : b.call(l, ".ck-math-widget, [data-math-id]") : null;
462
462
  }
463
463
  function Me(l) {
464
464
  if (!l) return "";
465
- let n = "", o = 0;
466
- for (; o < l.length; ) {
467
- let c = l.indexOf("\\placeholder", o);
468
- if (c === -1) {
469
- n += l.slice(o);
465
+ let n = "", s = 0;
466
+ for (; s < l.length; ) {
467
+ let o = l.indexOf("\\placeholder", s);
468
+ if (o === -1) {
469
+ n += l.slice(s);
470
470
  break;
471
471
  }
472
- if (n += l.slice(o, c), o = c + 12, l[o] === "[") {
472
+ if (n += l.slice(s, o), s = o + 12, l[s] === "[") {
473
473
  let a = 1;
474
- for (o++; o < l.length && a > 0; )
475
- l[o] === "[" ? a++ : l[o] === "]" && a--, o++;
474
+ for (s++; s < l.length && a > 0; )
475
+ l[s] === "[" ? a++ : l[s] === "]" && a--, s++;
476
476
  }
477
- if (l[o] === "{") {
478
- let a = 1, m = o + 1;
479
- for (o++; o < l.length && a > 0; )
480
- l[o] === "{" ? a++ : l[o] === "}" && a--, o++;
481
- let b = l.slice(m, o - 1);
477
+ if (l[s] === "{") {
478
+ let a = 1, m = s + 1;
479
+ for (s++; s < l.length && a > 0; )
480
+ l[s] === "{" ? a++ : l[s] === "}" && a--, s++;
481
+ let b = l.slice(m, s - 1);
482
482
  b.trim() === "" ? n += "\\quad " : n += b;
483
483
  }
484
484
  }
485
485
  return n;
486
486
  }
487
487
  function ne(l) {
488
- let n = "", o = 0;
489
- const c = "\\text{";
490
- for (; o < l.length; ) {
491
- const a = l.indexOf(c, o);
488
+ let n = "", s = 0;
489
+ const o = "\\text{";
490
+ for (; s < l.length; ) {
491
+ const a = l.indexOf(o, s);
492
492
  if (a === -1) {
493
- n += l.slice(o);
493
+ n += l.slice(s);
494
494
  break;
495
495
  }
496
- n += l.slice(o, a);
497
- let m = 1, b = a + c.length;
496
+ n += l.slice(s, a);
497
+ let m = 1, b = a + o.length;
498
498
  for (; b < l.length && m > 0; )
499
499
  l[b] === "{" ? m++ : l[b] === "}" && m--, b++;
500
- const p = l.slice(a + c.length, b - 1);
501
- /^['"/]+$/.test(p) || p.includes("\\textquotedbl") || p.includes("\\textquotesingle") ? n += "\\text{" + p + "}" : n += p, o = b;
500
+ const d = l.slice(a + o.length, b - 1);
501
+ /^['"/]+$/.test(d) || d.includes("\\textquotedbl") || d.includes("\\textquotesingle") ? n += "\\text{" + d + "}" : n += d, s = b;
502
502
  }
503
503
  return n;
504
504
  }
505
505
  function Ue(l, n) {
506
- let o = 0, c = n - 1;
507
- for (; c >= 0 && l[c] === "\\"; )
508
- o++, c--;
509
- return o % 2 === 1;
506
+ let s = 0, o = n - 1;
507
+ for (; o >= 0 && l[o] === "\\"; )
508
+ s++, o--;
509
+ return s % 2 === 1;
510
510
  }
511
511
  function Pe(l) {
512
512
  if (!l || typeof l != "string") return l || "";
513
513
  let n = l;
514
- const o = [
514
+ const s = [
515
515
  "\\mathbfit{",
516
516
  "\\boldsymbol{",
517
517
  "\\mathbf{",
@@ -529,22 +529,22 @@ function Pe(l) {
529
529
  "\\mathsf{",
530
530
  "\\mathtt{"
531
531
  ];
532
- let c = !0, a = 0;
533
- for (; c && a < 10; ) {
534
- c = !1, a++;
535
- for (const m of o) {
532
+ let o = !0, a = 0;
533
+ for (; o && a < 10; ) {
534
+ o = !1, a++;
535
+ for (const m of s) {
536
536
  let b = 0;
537
537
  for (; b < n.length; ) {
538
- const p = n.indexOf(m, b);
539
- if (p === -1) break;
540
- let y = 1, L = p + m.length;
541
- for (; L < n.length && y > 0; )
542
- n[L] === "{" && !Ue(n, L) ? y++ : n[L] === "}" && !Ue(n, L) && y--, L++;
543
- if (y === 0) {
544
- const k = n.slice(p + m.length, L - 1);
545
- n = n.slice(0, p) + k + n.slice(L), c = !0, b = p;
538
+ const d = n.indexOf(m, b);
539
+ if (d === -1) break;
540
+ let E = 1, L = d + m.length;
541
+ for (; L < n.length && E > 0; )
542
+ n[L] === "{" && !Ue(n, L) ? E++ : n[L] === "}" && !Ue(n, L) && E--, L++;
543
+ if (E === 0) {
544
+ const k = n.slice(d + m.length, L - 1);
545
+ n = n.slice(0, d) + k + n.slice(L), o = !0, b = d;
546
546
  } else
547
- b = p + m.length;
547
+ b = d + m.length;
548
548
  }
549
549
  }
550
550
  }
@@ -589,46 +589,48 @@ function kt(l) {
589
589
  /\\alpha\b|\\beta\b|\\gamma\b|\\delta\b|\\epsilon\b|\\zeta\b|\\eta\b|\\theta\b|\\iota\b|\\kappa\b|\\lambda\b|\\mu\b|\\nu\b|\\xi\b|\\pi\b|\\rho\b|\\sigma\b|\\tau\b|\\upsilon\b|\\phi\b|\\chi\b|\\psi\b|\\omega\b/,
590
590
  /\\Gamma\b|\\Delta\b|\\Theta\b|\\Lambda\b|\\Xi\b|\\Pi\b|\\Sigma\b|\\Upsilon\b|\\Phi\b|\\Psi\b|\\Omega\b/,
591
591
  /\\pm\b|\\times\b|\\div\b|\\leq\b|\\geq\b|\\neq\b|\\approx\b|\\infty\b|\\partial\b|\\to\b|\\rightarrow\b/
592
- ].some((o) => o.test(l));
592
+ ].some((s) => s.test(l));
593
593
  }
594
594
  function ut(l, n) {
595
595
  return l ? kt(l) ? l : (n == null ? void 0 : n.fontFamily) === "sans-serif" ? `\\mathsf{${l}}` : (n == null ? void 0 : n.fontFamily) === "monospace" ? `\\mathtt{${l}}` : (n == null ? void 0 : n.fontFamily) === "roman" ? `\\mathrm{${l}}` : l : "";
596
596
  }
597
- function qe(l, n, o, c) {
597
+ function qe(l, n, s, o) {
598
598
  if (!l) return "";
599
- if (!n && !o)
600
- return ut(l, { fontFamily: c });
601
- const a = c === "sans-serif", m = c === "monospace", b = c === "roman";
602
- return n && o ? a ? `\\boldsymbol{\\mathsf{${l}}}` : m ? `\\boldsymbol{\\mathtt{${l}}}` : b ? `\\mathbfit{\\mathrm{${l}}}` : `\\mathbfit{${l}}` : n ? a ? `\\boldsymbol{\\mathsf{${l}}}` : m ? `\\boldsymbol{\\mathtt{${l}}}` : b ? `\\mathbf{\\mathrm{${l}}}` : `\\mathbf{${l}}` : o ? a ? `\\mathsf{${l}}` : m ? `\\mathtt{${l}}` : b ? `\\mathit{\\mathrm{${l}}}` : `\\mathit{${l}}` : l;
599
+ if (!n && !s)
600
+ return ut(l, { fontFamily: o });
601
+ const a = o === "sans-serif", m = o === "monospace", b = o === "roman";
602
+ return n && s ? a ? `\\boldsymbol{\\mathsf{${l}}}` : m ? `\\boldsymbol{\\mathtt{${l}}}` : b ? `\\mathbfit{\\mathrm{${l}}}` : `\\mathbfit{${l}}` : n ? a ? `\\boldsymbol{\\mathsf{${l}}}` : m ? `\\boldsymbol{\\mathtt{${l}}}` : b ? `\\mathbf{\\mathrm{${l}}}` : `\\mathbf{${l}}` : s ? a ? `\\mathsf{${l}}` : m ? `\\mathtt{${l}}` : b ? `\\mathit{\\mathrm{${l}}}` : `\\mathit{${l}}` : l;
603
603
  }
604
- function de(l, n, o, c) {
604
+ function de(l, n, s, o) {
605
605
  if (!l) return "";
606
606
  let a = l.trim();
607
607
  const m = a.match(/^\\displaylines\s*\{([\s\S]*)\}$/i);
608
608
  if (m && (a = m[1].trim()), a.match(/^\\begin\{(array|matrix|pmatrix|bmatrix|vmatrix|Vmatrix|align|aligned|gather|cases)\}([\s\S]*)\\end\{\1\}$/i))
609
609
  return a;
610
- const p = a.match(/^\\begin\{(array|gather)\}(\{[\s\S]*?\})?([\s\S]*?)\\end\{\1\}$/i);
611
- if (p && (a = p[3].trim()), /\\\\|\\cr|\\newline|\\par|\n/.test(a)) {
612
- const y = /\\\\(?:\[[^\]]*\])?|\\cr|\\newline|\\par|\n/;
613
- return `\\displaylines{${a.split(y).map((v) => {
614
- const u = v.trim();
615
- return u ? qe(u, n, o, c) : "";
616
- }).filter((v) => v.length > 0).join(" \\\\ ")}}`;
610
+ const d = a.match(/^\\begin\{(array|gather)\}(\{[\s\S]*?\})?([\s\S]*?)\\end\{\1\}$/i);
611
+ if (d && (a = d[3].trim()), /\\\\|\\cr|\\newline|\\par|\n/.test(a)) {
612
+ const E = /\\\\(?:\[[^\]]*\])?|\\cr|\\newline|\\par|\n/;
613
+ return `\\displaylines{${a.split(E).map((x) => {
614
+ const u = x.trim();
615
+ return u ? qe(u, n, s, o) : "";
616
+ }).filter((x) => x.length > 0).join(" \\\\ ")}}`;
617
617
  }
618
- return qe(a, n, o, c);
618
+ return qe(a, n, s, o);
619
619
  }
620
620
  function be(l) {
621
621
  return l.replace(/\\enclose\{([^}]*)\}\[.*?\]/g, "\\enclose{$1}");
622
622
  }
623
623
  function Se(l = "") {
624
- return typeof l != "string" ? l : l.replace(/\\textasciitilde/g, "\\text{~}").replace(/\\textasciicircum/g, "\\text{^}").replace(/\\textasteriskcentered/g, "*").replace(/\\char96/g, "`");
624
+ if (typeof l != "string") return l;
625
+ let n = l.replace(/\\textasciitilde/g, "\\text{~}").replace(/\\textasciicircum/g, "\\text{^}").replace(/\\textasteriskcentered/g, "*").replace(/\\char96/g, "`");
626
+ return n.includes("\\ce{") && (n = n.replace(/\\ce\{([\s\S]*?)\}/g, (s, o) => o.includes("\\{") || o.includes("\\}") || o.includes("\\lbrace") || o.includes("\\rbrace") ? o : `\\ce{${o.replace(/\\left\[/g, "[").replace(/\\right\]/g, "]").replace(/\\lbrack\b/g, "[").replace(/\\rbrack\b/g, "]").replace(/\\left\(/g, "(").replace(/\\right\)/g, ")").replace(/\\left\|/g, "|").replace(/\\right\|/g, "|").replace(/\\left\./g, "").replace(/\\right\./g, "")}}`)), n;
625
627
  }
626
628
  function ke(l) {
627
629
  if (!l) return "";
628
630
  const n = l.getAttribute("data-latex");
629
631
  if (n) return n;
630
- const o = l.querySelector("math-field");
631
- return o ? o.getValue ? o.getValue("latex-expanded") : o.value || "" : "";
632
+ const s = l.querySelector("math-field");
633
+ return s ? s.getValue ? s.getValue("latex-expanded") : s.value || "" : "";
632
634
  }
633
635
  function Qe(l, n) {
634
636
  if (!l || !n) return !1;
@@ -639,37 +641,37 @@ function Qe(l, n) {
639
641
  }
640
642
  }
641
643
  function wt(l, n) {
642
- var p;
644
+ var d;
643
645
  if (!l || !n) return null;
644
- const o = l.model.document.selection.getSelectedElement();
645
- if ((o == null ? void 0 : o.name) === "mathInline") return o;
646
- const c = n.getAttribute("data-math-id");
647
- if (c) {
648
- const y = window.__ckMathWidgets.get(c);
649
- if (Qe(l, y)) return y;
646
+ const s = l.model.document.selection.getSelectedElement();
647
+ if ((s == null ? void 0 : s.name) === "mathInline") return s;
648
+ const o = n.getAttribute("data-math-id");
649
+ if (o) {
650
+ const E = window.__ckMathWidgets.get(o);
651
+ if (Qe(l, E)) return E;
650
652
  }
651
653
  const a = l.editing.view.domConverter.mapDomToView(n);
652
654
  if (a) {
653
- const y = l.editing.mapper.toModelElement(a);
654
- if ((y == null ? void 0 : y.name) === "mathInline") return y;
655
+ const E = l.editing.mapper.toModelElement(a);
656
+ if ((E == null ? void 0 : E.name) === "mathInline") return E;
655
657
  }
656
658
  const m = ke(n);
657
659
  if (!m) return null;
658
660
  const b = l.model.document.getRoot();
659
- for (const { item: y } of l.model.createRangeIn(b))
660
- if ((p = y.is) != null && p.call(y, "element", "mathInline") && y.getAttribute("latex") === m)
661
- return y;
661
+ for (const { item: E } of l.model.createRangeIn(b))
662
+ if ((d = E.is) != null && d.call(E, "element", "mathInline") && E.getAttribute("latex") === m)
663
+ return E;
662
664
  return null;
663
665
  }
664
- function Xe(l, n, o, c) {
666
+ function Xe(l, n, s, o) {
665
667
  if (!l || l._mathWidgetOpening) return;
666
668
  l._mathWidgetOpening = !0, queueMicrotask(() => {
667
669
  l._mathWidgetOpening = !1;
668
670
  });
669
- const a = Qe(l, n) ? n : wt(l, c), m = (a == null ? void 0 : a.getAttribute("latex")) || o || ke(c);
671
+ const a = Qe(l, n) ? n : wt(l, o), m = (a == null ? void 0 : a.getAttribute("latex")) || s || ke(o);
670
672
  if (!m) return;
671
- a && l.model.change((p) => {
672
- p.setSelection(a, "on");
673
+ a && l.model.change((d) => {
674
+ d.setSelection(a, "on");
673
675
  });
674
676
  const b = l.mathWidgetClickHandler || window.__ckMathWidgetClickHandler;
675
677
  b && b(a, m), window.dispatchEvent(new CustomEvent("editAneesWidget", {
@@ -683,11 +685,11 @@ function Xe(l, n, o, c) {
683
685
  function xt(l, n) {
684
686
  if (!n || n._ckMathClickBound) return;
685
687
  n._ckMathClickBound = !0;
686
- const o = (c) => {
688
+ const s = (o) => {
687
689
  var a;
688
- c.button === 0 && (c.preventDefault(), c.stopPropagation(), (a = c.stopImmediatePropagation) == null || a.call(c), Xe(l, null, ke(n), n));
690
+ o.button === 0 && (o.preventDefault(), o.stopPropagation(), (a = o.stopImmediatePropagation) == null || a.call(o), Xe(l, null, ke(n), n));
689
691
  };
690
- n.addEventListener("mousedown", o, !0), n.addEventListener("click", o, !0);
692
+ n.addEventListener("mousedown", s, !0), n.addEventListener("click", s, !0);
691
693
  }
692
694
  const yt = [
693
695
  {
@@ -2125,7 +2127,7 @@ const yt = [
2125
2127
  // { type: 'sep', cols: 2, cls: 'cme-trig-subgroup' }
2126
2128
  // ]
2127
2129
  // },
2128
- ], Et = [
2130
+ ], ft = [
2129
2131
  {
2130
2132
  label: "H₂O",
2131
2133
  isChem: !0,
@@ -3732,11 +3734,14 @@ const yt = [
3732
3734
  // ]
3733
3735
  // },
3734
3736
  ];
3735
- function ft(l = "") {
3736
- if (String(l).match(/^\\ce\{([\s\S]*)\}$/) || l.includes("\\class{cme-"))
3737
- return l;
3738
- const o = l.replace(/\\text\{([^}]*)\}/g, "$1").replace(/\$/g, "").trim();
3739
- return o ? `\\ce{${o}}` : "";
3737
+ function Et(l = "") {
3738
+ let n = String(l).trim();
3739
+ const s = n.match(/^\\ce\{([\s\S]*)\}$/);
3740
+ let o = s ? s[1] : n;
3741
+ if (o.includes("\\class{cme-") || o.includes("\\xleftrightarrows") || o.includes("\\xleftrightharpoons") || o.includes("\\enclose") || o.includes("\\{") || o.includes("\\}") || o.includes("\\lbrace") || o.includes("\\rbrace"))
3742
+ return o;
3743
+ const a = o.replace(/\\left\[/g, "[").replace(/\\right\]/g, "]").replace(/\\lbrack\b/g, "[").replace(/\\rbrack\b/g, "]").replace(/\\left\(/g, "(").replace(/\\right\)/g, ")").replace(/\\left\|/g, "|").replace(/\\right\|/g, "|").replace(/\\left\./g, "").replace(/\\right\./g, "").replace(/\\text\{([^}]*)\}/g, "$1").replace(/\$/g, "").trim();
3744
+ return a ? `\\ce{${a}}` : "";
3740
3745
  }
3741
3746
  function Ae(l) {
3742
3747
  return l === "matrix" ? "\\begin{matrix} \\placeholder{} & \\placeholder{} \\\\ \\placeholder{} & \\placeholder{} \\end{matrix}" : l === "bmatrix" ? "\\begin{bmatrix} \\placeholder{} & \\placeholder{} \\\\ \\placeholder{} & \\placeholder{} \\end{bmatrix}" : l === "pmatrix" ? "\\begin{pmatrix} \\placeholder{} & \\placeholder{} \\\\ \\placeholder{} & \\placeholder{} \\end{pmatrix}" : l === "vmatrix" ? "\\begin{vmatrix} \\placeholder{} & \\placeholder{} \\\\ \\placeholder{} & \\placeholder{} \\end{vmatrix}" : l.replace(/#0|#\?/g, "\\placeholder{}");
@@ -3755,20 +3760,20 @@ class It extends it {
3755
3760
  isObject: !0,
3756
3761
  allowWhere: "$text",
3757
3762
  allowAttributes: ["latex"]
3758
- }), n.model.schema.addChildCheck((c, a) => {
3763
+ }), n.model.schema.addChildCheck((o, a) => {
3759
3764
  if (a.name === "mathInline")
3760
3765
  return !0;
3761
3766
  }), n.conversion.for("editingDowncast").elementToElement({
3762
3767
  model: "mathInline",
3763
- view: (c, { writer: a }) => {
3764
- const m = c.getAttribute("latex") || "", b = "math-" + Math.random().toString(36).substr(2, 9);
3765
- window.__ckMathWidgets.set(b, c);
3766
- const p = a.createContainerElement("span", {
3768
+ view: (o, { writer: a }) => {
3769
+ const m = o.getAttribute("latex") || "", b = "math-" + Math.random().toString(36).substr(2, 9);
3770
+ window.__ckMathWidgets.set(b, o);
3771
+ const d = a.createContainerElement("span", {
3767
3772
  class: "ck-math-widget ck-math-inline-word",
3768
3773
  contenteditable: "false",
3769
3774
  "data-math-id": b,
3770
3775
  "data-latex": m
3771
- }), y = a.createRawElement(
3776
+ }), E = a.createRawElement(
3772
3777
  "span",
3773
3778
  {
3774
3779
  class: "ck-math-widget-inner",
@@ -3777,69 +3782,69 @@ class It extends it {
3777
3782
  (L) => {
3778
3783
  const k = document.createElement("math-field");
3779
3784
  k.setAttribute("math-virtual-keyboard-policy", "manual"), k.setAttribute("tabindex", "-1"), k.style.display = "inline-block", k.style.width = "auto", k.style.maxWidth = "100%", k.style.verticalAlign = "middle", k.style.border = "none", k.style.background = "transparent", k.style.outline = "none", k.style.fontSize = "inherit", k.style.minHeight = "auto", k.style.padding = "0", k.style.margin = "0", k.style.pointerEvents = "none";
3780
- const v = () => {
3785
+ const x = () => {
3781
3786
  if (!k.isConnected) {
3782
- requestAnimationFrame(v);
3787
+ requestAnimationFrame(x);
3783
3788
  return;
3784
3789
  }
3785
3790
  window.__cme_macros && (k.macros = { ...k.macros, ...window.__cme_macros });
3786
- let M = Se(
3791
+ let y = Se(
3787
3792
  be(
3788
3793
  ne(
3789
3794
  Me(m)
3790
3795
  )
3791
3796
  )
3792
3797
  );
3793
- M.includes("\\enclose") && /^\\ce\{[\s\S]*\}$/i.test(M.trim()) && (M = M.trim().replace(/^\\ce\{([\s\S]*)\}$/i, "$1"));
3798
+ (y.includes("\\enclose") || y.includes("\\xleftrightarrows") || y.includes("\\xleftrightharpoons") || y.includes("\\class{cme-") || y.includes("\\{") || y.includes("\\}") || y.includes("\\lbrace") || y.includes("\\rbrace")) && /^\\ce\{[\s\S]*\}$/i.test(y.trim()) && (y = y.trim().replace(/^\\ce\{([\s\S]*)\}$/i, "$1"));
3794
3799
  try {
3795
- k.setValue ? k.setValue("", { silenceNotifications: !0 }) : k.value = "", k.executeCommand(["insert", M, { insertionMode: "replaceAll" }]);
3796
- } catch (x) {
3797
- console.error("[CKMathWidget] executeCommand failed, falling back to setValue:", x);
3800
+ k.setValue ? k.setValue("", { silenceNotifications: !0 }) : k.value = "", k.executeCommand(["insert", y, { insertionMode: "replaceAll" }]);
3801
+ } catch (f) {
3802
+ console.error("[CKMathWidget] executeCommand failed, falling back to setValue:", f);
3798
3803
  try {
3799
- k.setValue ? k.setValue(M, { silenceNotifications: !0 }) : k.value = M;
3804
+ k.setValue ? k.setValue(y, { silenceNotifications: !0 }) : k.value = y;
3800
3805
  } catch (A) {
3801
3806
  console.error("[CKMathWidget] setValue also failed:", A);
3802
3807
  }
3803
3808
  }
3804
3809
  k.setAttribute("read-only", "");
3805
3810
  };
3806
- customElements.get("math-field") ? requestAnimationFrame(v) : customElements.whenDefined("math-field").then(() => requestAnimationFrame(v)), L.appendChild(k);
3811
+ customElements.get("math-field") ? requestAnimationFrame(x) : customElements.whenDefined("math-field").then(() => requestAnimationFrame(x)), L.appendChild(k);
3807
3812
  const u = () => {
3808
- const M = L.parentElement;
3809
- M && xt(n, M);
3813
+ const y = L.parentElement;
3814
+ y && xt(n, y);
3810
3815
  };
3811
3816
  u(), requestAnimationFrame(u);
3812
3817
  }
3813
3818
  );
3814
- return a.insert(a.createPositionAt(p, 0), y), at(p, a, { label: "math formula" });
3819
+ return a.insert(a.createPositionAt(d, 0), E), at(d, a, { label: "math formula" });
3815
3820
  }
3816
3821
  });
3817
- const o = n.editing.view.document;
3818
- this.listenTo(o, "mousedown", (c, a) => {
3822
+ const s = n.editing.view.document;
3823
+ this.listenTo(s, "mousedown", (o, a) => {
3819
3824
  const m = gt(a.domTarget);
3820
- m && a.domEvent.button === 0 && (c.stop(), a.preventDefault(), Xe(
3825
+ m && a.domEvent.button === 0 && (o.stop(), a.preventDefault(), Xe(
3821
3826
  n,
3822
3827
  null,
3823
3828
  ke(m),
3824
3829
  m
3825
3830
  ));
3826
- }, { priority: "high" }), n.conversion.for("editingDowncast").add((c) => {
3827
- c.on("attribute:latex:mathInline", (a, m, b) => {
3831
+ }, { priority: "high" }), n.conversion.for("editingDowncast").add((o) => {
3832
+ o.on("attribute:latex:mathInline", (a, m, b) => {
3828
3833
  if (!b.consumable.consume(m.item, a.name))
3829
3834
  return;
3830
- const p = b.writer, y = b.mapper.toViewElement(m.item);
3831
- if (y) {
3832
- p.setAttribute("data-latex", m.attributeNewValue, y);
3833
- const L = n.editing.view.domConverter.mapViewToDom(y);
3835
+ const d = b.writer, E = b.mapper.toViewElement(m.item);
3836
+ if (E) {
3837
+ d.setAttribute("data-latex", m.attributeNewValue, E);
3838
+ const L = n.editing.view.domConverter.mapViewToDom(E);
3834
3839
  if (L) {
3835
3840
  const k = L.querySelector("math-field");
3836
3841
  if (k) {
3837
- let v = Se(be(ne(Me(m.attributeNewValue))));
3838
- v.includes("\\enclose") && /^\\ce\{[\s\S]*\}$/i.test(v.trim()) && (v = v.trim().replace(/^\\ce\{([\s\S]*)\}$/i, "$1")), k.removeAttribute("read-only");
3842
+ let x = Se(be(ne(Me(m.attributeNewValue))));
3843
+ (x.includes("\\enclose") || x.includes("\\xleftrightarrows") || x.includes("\\xleftrightharpoons") || x.includes("\\class{cme-") || x.includes("\\{") || x.includes("\\}") || x.includes("\\lbrace") || x.includes("\\rbrace")) && /^\\ce\{[\s\S]*\}$/i.test(x.trim()) && (x = x.trim().replace(/^\\ce\{([\s\S]*)\}$/i, "$1")), k.removeAttribute("read-only");
3839
3844
  try {
3840
- k.setValue ? k.setValue("", { silenceNotifications: !0 }) : k.value = "", k.executeCommand(["insert", v, { insertionMode: "replaceAll" }]);
3845
+ k.setValue ? k.setValue("", { silenceNotifications: !0 }) : k.value = "", k.executeCommand(["insert", x, { insertionMode: "replaceAll" }]);
3841
3846
  } catch {
3842
- k.setValue ? k.setValue(v, { silenceNotifications: !0 }) : k.value = v;
3847
+ k.setValue ? k.setValue(x, { silenceNotifications: !0 }) : k.value = x;
3843
3848
  }
3844
3849
  k.setAttribute("read-only", "");
3845
3850
  }
@@ -3849,84 +3854,84 @@ class It extends it {
3849
3854
  });
3850
3855
  }), n.conversion.for("dataDowncast").elementToElement({
3851
3856
  model: "mathInline",
3852
- view: (c, { writer: a }) => {
3853
- const m = c.getAttribute("latex") || "", b = a.createContainerElement("span", {
3857
+ view: (o, { writer: a }) => {
3858
+ const m = o.getAttribute("latex") || "", b = a.createContainerElement("span", {
3854
3859
  class: "math-tex",
3855
3860
  "data-latex": m,
3856
3861
  // Keep raw latex in data-latex for restoring
3857
3862
  style: "display:inline;"
3858
3863
  });
3859
- let p = be(
3864
+ let d = be(
3860
3865
  ne(
3861
3866
  Me(m)
3862
3867
  )
3863
3868
  );
3864
- p.includes("\\enclose") && /^\\ce\{[\s\S]*\}$/i.test(p.trim()) && (p = p.trim().replace(/^\\ce\{([\s\S]*)\}$/i, "$1"));
3865
- let y = p.replace(/\\textasciitilde/g, "~").replace(/\\textasciicircum/g, "^").replace(/\\textasteriskcentered/g, "*").replace(/\\char96/g, "`").replace(/\\sim/g, "~").replace(/\\!/g, "!").replace(/\\@/g, "@").replace(/\\#/g, "#").replace(/\\$/g, "$").replace(/\\%/g, "%").replace(/\\&/g, "&").replace(/\\_/g, "_").replace(/\\\{/g, "{").replace(/\\\}/g, "}").replace(/\\ce\{([^}]*)\}/g, "$1").trim();
3866
- return a.insert(a.createPositionAt(b, 0), a.createText(y)), b;
3869
+ (d.includes("\\enclose") || d.includes("\\xleftrightarrows") || d.includes("\\xleftrightharpoons") || d.includes("\\class{cme-") || d.includes("\\{") || d.includes("\\}") || d.includes("\\lbrace") || d.includes("\\rbrace")) && /^\\ce\{[\s\S]*\}$/i.test(d.trim()) && (d = d.trim().replace(/^\\ce\{([\s\S]*)\}$/i, "$1"));
3870
+ let E = d.replace(/\\textasciitilde/g, "~").replace(/\\textasciicircum/g, "^").replace(/\\textasteriskcentered/g, "*").replace(/\\char96/g, "`").replace(/\\sim/g, "~").replace(/\\!/g, "!").replace(/\\@/g, "@").replace(/\\#/g, "#").replace(/\\$/g, "$").replace(/\\%/g, "%").replace(/\\&/g, "&").replace(/\\_/g, "_").replace(/\\\{/g, "{").replace(/\\\}/g, "}").replace(/\\ce\{([^}]*)\}/g, "$1").trim();
3871
+ return a.insert(a.createPositionAt(b, 0), a.createText(E)), b;
3867
3872
  }
3868
3873
  }), n.conversion.for("upcast").elementToElement({
3869
3874
  view: {
3870
3875
  name: "span",
3871
3876
  classes: "math-tex"
3872
3877
  },
3873
- model: (c, { writer: a }) => {
3874
- const m = c.getAttribute("data-latex") || "";
3878
+ model: (o, { writer: a }) => {
3879
+ const m = o.getAttribute("data-latex") || "";
3875
3880
  return a.createElement("mathInline", { latex: m });
3876
3881
  }
3877
3882
  });
3878
3883
  }
3879
3884
  }
3880
- function vt({ matrixType: l, x: n, y: o, onSelect: c, onMouseEnter: a, onMouseLeave: m }) {
3881
- const [b, p] = T({ r: 2, c: 2 }), y = Math.max(10, parseInt(b.r, 10) || 0), L = Math.max(10, parseInt(b.c, 10) || 0), k = (x) => {
3882
- const A = x.target.value;
3885
+ function vt({ matrixType: l, x: n, y: s, onSelect: o, onMouseEnter: a, onMouseLeave: m }) {
3886
+ const [b, d] = T({ r: 2, c: 2 }), E = Math.max(10, parseInt(b.r, 10) || 0), L = Math.max(10, parseInt(b.c, 10) || 0), k = (f) => {
3887
+ const A = f.target.value;
3883
3888
  if (A === "") {
3884
- p((S) => ({ ...S, r: "" }));
3889
+ d((S) => ({ ...S, r: "" }));
3885
3890
  return;
3886
3891
  }
3887
3892
  const I = parseInt(A, 10);
3888
- isNaN(I) || p((S) => ({ ...S, r: Math.max(1, Math.min(10, I)) }));
3889
- }, v = () => {
3890
- (b.r === "" || isNaN(parseInt(b.r, 10))) && p((x) => ({ ...x, r: 1 }));
3891
- }, u = (x) => {
3892
- const A = x.target.value;
3893
+ isNaN(I) || d((S) => ({ ...S, r: Math.max(1, Math.min(10, I)) }));
3894
+ }, x = () => {
3895
+ (b.r === "" || isNaN(parseInt(b.r, 10))) && d((f) => ({ ...f, r: 1 }));
3896
+ }, u = (f) => {
3897
+ const A = f.target.value;
3893
3898
  if (A === "") {
3894
- p((S) => ({ ...S, c: "" }));
3899
+ d((S) => ({ ...S, c: "" }));
3895
3900
  return;
3896
3901
  }
3897
3902
  const I = parseInt(A, 10);
3898
- isNaN(I) || p((S) => ({ ...S, c: Math.max(1, Math.min(10, I)) }));
3899
- }, M = () => {
3900
- (b.c === "" || isNaN(parseInt(b.c, 10))) && p((x) => ({ ...x, c: 1 }));
3903
+ isNaN(I) || d((S) => ({ ...S, c: Math.max(1, Math.min(10, I)) }));
3904
+ }, y = () => {
3905
+ (b.c === "" || isNaN(parseInt(b.c, 10))) && d((f) => ({ ...f, c: 1 }));
3901
3906
  };
3902
3907
  return D(() => {
3903
- const x = (A) => {
3908
+ const f = (A) => {
3904
3909
  if (A.key === "Enter") {
3905
3910
  A.preventDefault(), A.stopPropagation();
3906
3911
  const I = parseInt(b.r, 10) || 1, S = parseInt(b.c, 10) || 1;
3907
- c(I, S);
3912
+ o(I, S);
3908
3913
  }
3909
3914
  };
3910
- return window.addEventListener("keydown", x, !0), () => window.removeEventListener("keydown", x, !0);
3911
- }, [b.r, b.c, c]), /* @__PURE__ */ e.createElement(
3915
+ return window.addEventListener("keydown", f, !0), () => window.removeEventListener("keydown", f, !0);
3916
+ }, [b.r, b.c, o]), /* @__PURE__ */ e.createElement(
3912
3917
  "div",
3913
3918
  {
3914
3919
  className: "cme-matrix-hover-popover ck-only",
3915
- style: { top: `${o}px`, left: `${n}px` },
3916
- onPointerDown: (x) => x.stopPropagation(),
3920
+ style: { top: `${s}px`, left: `${n}px` },
3921
+ onPointerDown: (f) => f.stopPropagation(),
3917
3922
  onMouseEnter: a,
3918
3923
  onMouseLeave: m
3919
3924
  },
3920
- /* @__PURE__ */ e.createElement("div", { className: "cme-matrix-hover-grid" }, Array.from({ length: y }).map((x, A) => /* @__PURE__ */ e.createElement("div", { key: A, className: "cme-matrix-hover-row" }, Array.from({ length: L }).map((I, S) => {
3925
+ /* @__PURE__ */ e.createElement("div", { className: "cme-matrix-hover-grid" }, Array.from({ length: E }).map((f, A) => /* @__PURE__ */ e.createElement("div", { key: A, className: "cme-matrix-hover-row" }, Array.from({ length: L }).map((I, S) => {
3921
3926
  const X = parseInt(b.r, 10) || 0, V = parseInt(b.c, 10) || 0, Y = A < X && S < V;
3922
3927
  return /* @__PURE__ */ e.createElement(
3923
3928
  "div",
3924
3929
  {
3925
3930
  key: `${A}-${S}`,
3926
3931
  className: `cme-matrix-hover-cell${Y ? " selected" : ""}`,
3927
- onMouseEnter: () => p({ r: A + 1, c: S + 1 }),
3932
+ onMouseEnter: () => d({ r: A + 1, c: S + 1 }),
3928
3933
  onClick: (Z) => {
3929
- Z.preventDefault(), Z.stopPropagation(), c(A + 1, S + 1);
3934
+ Z.preventDefault(), Z.stopPropagation(), o(A + 1, S + 1);
3930
3935
  }
3931
3936
  }
3932
3937
  );
@@ -3938,16 +3943,16 @@ function vt({ matrixType: l, x: n, y: o, onSelect: c, onMouseEnter: a, onMouseLe
3938
3943
  className: "cme-counter-val",
3939
3944
  value: b.r,
3940
3945
  onChange: k,
3941
- onBlur: v,
3946
+ onBlur: x,
3942
3947
  min: "1",
3943
3948
  max: "10"
3944
3949
  }
3945
- ), /* @__PURE__ */ e.createElement("div", { className: "cme-counter-btns" }, /* @__PURE__ */ e.createElement("button", { type: "button", onClick: () => p((x) => {
3946
- const A = parseInt(x.r, 10) || 1;
3947
- return { ...x, r: Math.min(10, A + 1) };
3948
- }) }, "▲"), /* @__PURE__ */ e.createElement("button", { type: "button", onClick: () => p((x) => {
3949
- const A = parseInt(x.r, 10) || 1;
3950
- return { ...x, r: Math.max(1, A - 1) };
3950
+ ), /* @__PURE__ */ e.createElement("div", { className: "cme-counter-btns" }, /* @__PURE__ */ e.createElement("button", { type: "button", onClick: () => d((f) => {
3951
+ const A = parseInt(f.r, 10) || 1;
3952
+ return { ...f, r: Math.min(10, A + 1) };
3953
+ }) }, "▲"), /* @__PURE__ */ e.createElement("button", { type: "button", onClick: () => d((f) => {
3954
+ const A = parseInt(f.r, 10) || 1;
3955
+ return { ...f, r: Math.max(1, A - 1) };
3951
3956
  }) }, "▼"))), /* @__PURE__ */ e.createElement("div", { className: "cme-matrix-counter" }, /* @__PURE__ */ e.createElement("span", null, "C"), /* @__PURE__ */ e.createElement(
3952
3957
  "input",
3953
3958
  {
@@ -3955,34 +3960,34 @@ function vt({ matrixType: l, x: n, y: o, onSelect: c, onMouseEnter: a, onMouseLe
3955
3960
  className: "cme-counter-val",
3956
3961
  value: b.c,
3957
3962
  onChange: u,
3958
- onBlur: M,
3963
+ onBlur: y,
3959
3964
  min: "1",
3960
3965
  max: "10"
3961
3966
  }
3962
- ), /* @__PURE__ */ e.createElement("div", { className: "cme-counter-btns" }, /* @__PURE__ */ e.createElement("button", { type: "button", onClick: () => p((x) => {
3963
- const A = parseInt(x.c, 10) || 1;
3964
- return { ...x, c: Math.min(10, A + 1) };
3965
- }) }, "▲"), /* @__PURE__ */ e.createElement("button", { type: "button", onClick: () => p((x) => {
3966
- const A = parseInt(x.c, 10) || 1;
3967
- return { ...x, c: Math.max(1, A - 1) };
3967
+ ), /* @__PURE__ */ e.createElement("div", { className: "cme-counter-btns" }, /* @__PURE__ */ e.createElement("button", { type: "button", onClick: () => d((f) => {
3968
+ const A = parseInt(f.c, 10) || 1;
3969
+ return { ...f, c: Math.min(10, A + 1) };
3970
+ }) }, "▲"), /* @__PURE__ */ e.createElement("button", { type: "button", onClick: () => d((f) => {
3971
+ const A = parseInt(f.c, 10) || 1;
3972
+ return { ...f, c: Math.max(1, A - 1) };
3968
3973
  }) }, "▼"))))
3969
3974
  );
3970
3975
  }
3971
3976
  let K = !1, Ce = null, ie = null;
3972
- function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a }) {
3973
- const m = le(null), b = le(null), [p, y] = T(null), [L, k] = T(0), [v, u] = T(null), [M, x] = T(null), [A, I] = T(null), [S, X] = T(null);
3977
+ function Mt({ mode: l, onInsert: n, onClose: s, initialLatex: o, isEditing: a }) {
3978
+ const m = le(null), b = le(null), [d, E] = T(null), [L, k] = T(0), [x, u] = T(null), [y, f] = T(null), [A, I] = T(null), [S, X] = T(null);
3974
3979
  le(null);
3975
3980
  const [V, Y] = T({ x: 0, y: 0 }), [Z, Le] = T(!1), ue = le({ x: 0, y: 0 }), [_e, Te] = T(!1), [Ke, We] = T(!1), [Ye, ae] = T(!1), we = le(null);
3976
3981
  D(() => {
3977
3982
  const t = (r) => {
3978
3983
  if (!Z) return;
3979
- const s = r.touches && r.touches.length > 0 ? r.touches[0].clientX : r.clientX, h = r.touches && r.touches.length > 0 ? r.touches[0].clientY : r.clientY;
3980
- let g = s - ue.current.x, d = h - ue.current.y;
3984
+ const c = r.touches && r.touches.length > 0 ? r.touches[0].clientX : r.clientX, h = r.touches && r.touches.length > 0 ? r.touches[0].clientY : r.clientY;
3985
+ let g = c - ue.current.x, p = h - ue.current.y;
3981
3986
  if (we.current) {
3982
- const C = we.current, f = -C.left, N = window.innerWidth - C.right, H = -C.top, R = window.innerHeight - C.bottom;
3983
- g < f && (g = f), g > N && (g = N), d < H && (d = H), d > R && (d = R);
3987
+ const C = we.current, M = -C.left, N = window.innerWidth - C.right, H = -C.top, R = window.innerHeight - C.bottom;
3988
+ g < M && (g = M), g > N && (g = N), p < H && (p = H), p > R && (p = R);
3984
3989
  }
3985
- Y({ x: g, y: d });
3990
+ Y({ x: g, y: p });
3986
3991
  }, i = () => Le(!1);
3987
3992
  return Z && (window.addEventListener("mousemove", t, { passive: !1 }), window.addEventListener("mouseup", i), window.addEventListener("touchmove", t, { passive: !1 }), window.addEventListener("touchend", i)), () => {
3988
3993
  window.removeEventListener("mousemove", t), window.removeEventListener("mouseup", i), window.removeEventListener("touchmove", t), window.removeEventListener("touchend", i);
@@ -3990,15 +3995,15 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
3990
3995
  }, [Z]), D(() => {
3991
3996
  const t = b.current;
3992
3997
  if (!t) return;
3993
- let i = 0, r = 0, s = 0;
3994
- const h = (d) => {
3995
- d.touches.length === 1 && (i = d.touches[0].clientY, r = d.touches[0].clientX, s = t.scrollTop);
3996
- }, g = (d) => {
3997
- if (d.touches.length !== 1) return;
3998
- const C = i - d.touches[0].clientY, f = r - d.touches[0].clientX;
3999
- if (Math.abs(C) < 10 || Math.abs(f) > Math.abs(C) || t.scrollHeight <= t.clientHeight) return;
4000
- const N = s + C, H = t.scrollHeight - t.clientHeight;
4001
- N > 0 && N < H && d.preventDefault(), t.scrollTop = Math.max(0, Math.min(N, H));
3998
+ let i = 0, r = 0, c = 0;
3999
+ const h = (p) => {
4000
+ p.touches.length === 1 && (i = p.touches[0].clientY, r = p.touches[0].clientX, c = t.scrollTop);
4001
+ }, g = (p) => {
4002
+ if (p.touches.length !== 1) return;
4003
+ const C = i - p.touches[0].clientY, M = r - p.touches[0].clientX;
4004
+ if (Math.abs(C) < 10 || Math.abs(M) > Math.abs(C) || t.scrollHeight <= t.clientHeight) return;
4005
+ const N = c + C, H = t.scrollHeight - t.clientHeight;
4006
+ N > 0 && N < H && p.preventDefault(), t.scrollTop = Math.max(0, Math.min(N, H));
4002
4007
  };
4003
4008
  return t.addEventListener("touchstart", h, { passive: !0 }), t.addEventListener("touchmove", g, { passive: !1 }), () => {
4004
4009
  t.removeEventListener("touchstart", h), t.removeEventListener("touchmove", g);
@@ -4012,9 +4017,9 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
4012
4017
  x: i - V.x,
4013
4018
  y: r - V.y
4014
4019
  };
4015
- const s = document.querySelector(".cme-editor-popup");
4016
- if (s) {
4017
- const h = s.getBoundingClientRect();
4020
+ const c = document.querySelector(".cme-editor-popup");
4021
+ if (c) {
4022
+ const h = c.getBoundingClientRect();
4018
4023
  we.current = {
4019
4024
  left: h.left - V.x,
4020
4025
  top: h.top - V.y,
@@ -4024,7 +4029,7 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
4024
4029
  height: h.height
4025
4030
  };
4026
4031
  }
4027
- }, oe = l === "math" ? yt : Et, [E, xe] = T({
4032
+ }, oe = l === "math" ? yt : ft, [v, xe] = T({
4028
4033
  bold: !1,
4029
4034
  italic: !1,
4030
4035
  color: "none",
@@ -4033,7 +4038,7 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
4033
4038
  });
4034
4039
  function P(t) {
4035
4040
  const i = t == null ? void 0 : t.selection;
4036
- return !i || !i.ranges || i.ranges.length === 0 ? !1 : i.ranges.some(([r, s]) => r !== s);
4041
+ return !i || !i.ranges || i.ranges.length === 0 ? !1 : i.ranges.some(([r, c]) => r !== c);
4037
4042
  }
4038
4043
  function Be(t) {
4039
4044
  if (!t) return !1;
@@ -4049,15 +4054,15 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
4049
4054
  P(t) && (r = t.getValue(t.selection) || "");
4050
4055
  } catch {
4051
4056
  }
4052
- const s = /\\mathbf\b|\\boldsymbol\b|\\mathbfit\b|\\textbf\b|\\bm\b|\\bold\b/;
4053
- if (r && s.test(r))
4057
+ const c = /\\mathbf\b|\\boldsymbol\b|\\mathbfit\b|\\textbf\b|\\bm\b|\\bold\b/;
4058
+ if (r && c.test(r))
4054
4059
  return !0;
4055
4060
  try {
4056
4061
  if (P(t)) {
4057
4062
  const h = t.getValue();
4058
- if (s.test(h)) {
4059
- const g = (f) => f.replace(/\\[a-zA-Z]+/g, "").replace(/[^a-zA-Z0-9]/g, ""), d = g(r), C = g(h);
4060
- if (d.length > 0 && d === C)
4063
+ if (c.test(h)) {
4064
+ const g = (M) => M.replace(/\\[a-zA-Z]+/g, "").replace(/[^a-zA-Z0-9]/g, ""), p = g(r), C = g(h);
4065
+ if (p.length > 0 && p === C)
4061
4066
  return !0;
4062
4067
  }
4063
4068
  }
@@ -4081,15 +4086,15 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
4081
4086
  P(t) && (r = t.getValue(t.selection) || "");
4082
4087
  } catch {
4083
4088
  }
4084
- const s = /\\mathit\b|\\mathbfit\b|\\textit\b/;
4085
- if (r && s.test(r))
4089
+ const c = /\\mathit\b|\\mathbfit\b|\\textit\b/;
4090
+ if (r && c.test(r))
4086
4091
  return !0;
4087
4092
  try {
4088
4093
  if (P(t)) {
4089
4094
  const h = t.getValue();
4090
- if (s.test(h)) {
4091
- const g = (f) => f.replace(/\\[a-zA-Z]+/g, "").replace(/[^a-zA-Z0-9]/g, ""), d = g(r), C = g(h);
4092
- if (d.length > 0 && d === C)
4095
+ if (c.test(h)) {
4096
+ const g = (M) => M.replace(/\\[a-zA-Z]+/g, "").replace(/[^a-zA-Z0-9]/g, ""), p = g(r), C = g(h);
4097
+ if (p.length > 0 && p === C)
4093
4098
  return !0;
4094
4099
  }
4095
4100
  }
@@ -4101,25 +4106,25 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
4101
4106
  }
4102
4107
  return !1;
4103
4108
  }
4104
- const q = fe(() => {
4109
+ const q = Ee(() => {
4105
4110
  if (K || window.__cmeIgnoreStyleUpdate && Date.now() < window.__cmeIgnoreStyleUpdate) return;
4106
4111
  const t = m.current;
4107
4112
  if (!(!t || typeof t.queryStyle != "function"))
4108
4113
  try {
4109
4114
  const i = P(t);
4110
- let r = Be(t), s = De(t), h = "none", g = "auto", d = "none";
4111
- const C = (f) => ["all", "some", !0].includes(f);
4115
+ let r = Be(t), c = De(t), h = "none", g = "auto", p = "none";
4116
+ const C = (M) => ["all", "some", !0].includes(M);
4112
4117
  if (i) {
4113
4118
  window.__cmeManualBold = void 0, window.__cmeManualItalic = void 0, window.__cmeManualFontFamily = void 0, window.__cmeManualFontSize = void 0;
4114
- let f = "";
4119
+ let M = "";
4115
4120
  try {
4116
- f = t.getValue(sel) || "";
4121
+ M = t.getValue(sel) || "";
4117
4122
  } catch {
4118
4123
  }
4119
4124
  const N = ["roman", "sans-serif", "monospace"].find((R) => C(t.queryStyle({ fontFamily: R }))) || "none";
4120
- N !== "none" ? h = N : /\\mathsf\b/.test(f) ? h = "sans-serif" : /\\mathtt\b/.test(f) ? h = "monospace" : /\\mathrm\b/.test(f) ? h = "roman" : h = "none";
4125
+ N !== "none" ? h = N : /\\mathsf\b/.test(M) ? h = "sans-serif" : /\\mathtt\b/.test(M) ? h = "monospace" : /\\mathrm\b/.test(M) ? h = "roman" : h = "none";
4121
4126
  const H = [5, 7, 9].find((R) => C(t.queryStyle({ fontSize: R }))) || "auto";
4122
- g = String(H), d = [
4127
+ g = String(H), p = [
4123
4128
  "black",
4124
4129
  "dimgray",
4125
4130
  "gray",
@@ -4146,11 +4151,11 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
4146
4151
  "gold"
4147
4152
  ].find((R) => C(t.queryStyle({ color: R }))) || "none";
4148
4153
  } else
4149
- window.__cmeManualBold !== void 0 && (r = window.__cmeManualBold), window.__cmeManualItalic !== void 0 && (s = window.__cmeManualItalic), console.log("CME: updateActiveStyles else-branch bold=", r, "manual=", window.__cmeManualBold), h = window.__cmeManualFontFamily !== void 0 ? window.__cmeManualFontFamily : ["roman", "sans-serif", "monospace"].find(
4150
- (f) => C(t.queryStyle({ fontFamily: f }))
4154
+ window.__cmeManualBold !== void 0 && (r = window.__cmeManualBold), window.__cmeManualItalic !== void 0 && (c = window.__cmeManualItalic), console.log("CME: updateActiveStyles else-branch bold=", r, "manual=", window.__cmeManualBold), h = window.__cmeManualFontFamily !== void 0 ? window.__cmeManualFontFamily : ["roman", "sans-serif", "monospace"].find(
4155
+ (M) => C(t.queryStyle({ fontFamily: M }))
4151
4156
  ) || "none", g = window.__cmeManualFontSize !== void 0 ? window.__cmeManualFontSize : [5, 7, 9].find(
4152
- (f) => C(t.queryStyle({ fontSize: f }))
4153
- ) || "auto", d = [
4157
+ (M) => C(t.queryStyle({ fontSize: M }))
4158
+ ) || "auto", p = [
4154
4159
  "black",
4155
4160
  "dimgray",
4156
4161
  "gray",
@@ -4176,28 +4181,28 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
4176
4181
  "violet",
4177
4182
  "gold"
4178
4183
  ].find(
4179
- (f) => C(t.queryStyle({ color: f }))
4184
+ (M) => C(t.queryStyle({ color: M }))
4180
4185
  ) || "none";
4181
4186
  xe({
4182
4187
  bold: r,
4183
- italic: s,
4188
+ italic: c,
4184
4189
  fontFamily: h,
4185
4190
  fontSize: String(g),
4186
- color: d
4191
+ color: p
4187
4192
  });
4188
4193
  } catch (i) {
4189
4194
  console.warn("Failed to query active styles:", i);
4190
4195
  }
4191
4196
  }, []);
4192
4197
  D(() => {
4193
- if (!v && !A) return;
4198
+ if (!x && !A) return;
4194
4199
  const t = (i) => {
4195
4200
  !i.target.closest(".cme-matrix-hover-popover") && !i.target.closest(".cme-matrix-btn-wrapper") && u(null), !i.target.closest(".cme-color-picker-popup") && !i.target.closest('[title="Text Color"]') && I(null);
4196
4201
  };
4197
4202
  return window.addEventListener("mousedown", t, !0), window.addEventListener("pointerdown", t, !0), () => {
4198
4203
  window.removeEventListener("mousedown", t, !0), window.removeEventListener("pointerdown", t, !0);
4199
4204
  };
4200
- }, [v, A]), D(() => {
4205
+ }, [x, A]), D(() => {
4201
4206
  if (!S) return;
4202
4207
  const t = (i) => {
4203
4208
  !i.target.closest(".cme-more-popup") && !i.target.closest(".cme-more-trigger-btn") && X(null);
@@ -4210,15 +4215,15 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
4210
4215
  return () => clearTimeout(t);
4211
4216
  }, [L]), D(() => {
4212
4217
  if (K) return;
4213
- const t = p;
4218
+ const t = d;
4214
4219
  if (!t) return;
4215
4220
  t.macros = { ...t.macros, ...window.__cme_macros || {} }, t.defaultMode = "math";
4216
4221
  const i = () => {
4217
- if (c) {
4218
- let r = Se(c);
4222
+ if (o) {
4223
+ let r = Se(o);
4219
4224
  if (l === "chem") {
4220
- const s = r.match(/^\\ce\{([\s\S]*)\}$/i);
4221
- s && (r = s[1]);
4225
+ const c = r.match(/^\\ce\{([\s\S]*)\}$/i);
4226
+ c && (r = c[1]);
4222
4227
  }
4223
4228
  r = ne(r), r = be(r), t.setValue ? t.setValue("", { silenceNotifications: !0 }) : t.value = "", t.executeCommand(["insert", r, { insertionMode: "replaceAll" }]);
4224
4229
  }
@@ -4227,67 +4232,67 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
4227
4232
  });
4228
4233
  };
4229
4234
  customElements.get("math-field") ? requestAnimationFrame(i) : customElements.whenDefined("math-field").then(() => requestAnimationFrame(i));
4230
- }, [l, c, p]), D(() => {
4231
- const t = p;
4235
+ }, [l, o, d]), D(() => {
4236
+ const t = d;
4232
4237
  if (!t) return;
4233
4238
  const i = (r) => {
4234
4239
  if (["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(r.key) ? (K = !1, clearTimeout(Ce), window.__cmeManualBold = void 0, window.__cmeManualItalic = void 0, window.__cmeManualFontFamily = void 0, window.__cmeManualFontSize = void 0) : (r.key.length === 1 || r.key === " ") && (K = !0, clearTimeout(Ce), Ce = setTimeout(() => {
4235
4240
  K = !1;
4236
4241
  }, 500)), ["`", "~", "!", "@", "#", "$", "%", "^", "&", "*", "_", '"', "'", "/", "\\", "|"].includes(r.key) && !r.ctrlKey && !r.metaKey && !r.altKey) {
4237
4242
  r.preventDefault(), r.stopPropagation();
4238
- let s = "";
4239
- r.key === "`" ? s = "\\grave{\\ }" : r.key === "~" ? s = "\\sim" : r.key === "!" ? s = "!" : r.key === "@" ? s = "@" : r.key === "#" ? s = "\\#" : r.key === "$" ? s = "\\$" : r.key === "%" ? s = "\\%" : r.key === "^" ? s = "\\wedge" : r.key === "&" ? s = "\\&" : r.key === "*" ? s = "\\ast" : r.key === "_" ? s = "\\_" : r.key === '"' ? s = '\\text{"}' : r.key === "'" ? s = "\\text{'}" : r.key === "/" ? s = "\\mathord{/}" : r.key === "\\" ? s = "\\backslash" : r.key === "|" && (s = "|"), t.executeCommand(["insert", s]);
4243
+ let c = "";
4244
+ r.key === "`" ? c = "\\grave{\\ }" : r.key === "~" ? c = "\\sim" : r.key === "!" ? c = "!" : r.key === "@" ? c = "@" : r.key === "#" ? c = "\\#" : r.key === "$" ? c = "\\$" : r.key === "%" ? c = "\\%" : r.key === "^" ? c = "\\wedge" : r.key === "&" ? c = "\\&" : r.key === "*" ? c = "\\ast" : r.key === "_" ? c = "\\_" : r.key === '"' ? c = '\\text{"}' : r.key === "'" ? c = "\\text{'}" : r.key === "/" ? c = "\\mathord{/}" : r.key === "\\" ? c = "\\backslash" : r.key === "|" && (c = "|"), t.executeCommand(["insert", c]);
4240
4245
  return;
4241
4246
  }
4242
4247
  if (r.key.length === 1 && !r.ctrlKey && !r.metaKey && !r.altKey && /[a-zA-Z0-9]/.test(r.key)) {
4243
- if (r.preventDefault(), r.stopPropagation(), !E.bold || !E.italic)
4248
+ if (r.preventDefault(), r.stopPropagation(), !v.bold || !v.italic)
4244
4249
  try {
4245
4250
  t.executeCommand("moveOutOfGroup");
4246
4251
  } catch {
4247
4252
  }
4248
- let s = de(
4253
+ let c = de(
4249
4254
  r.key,
4250
- E.bold,
4251
- E.italic,
4252
- E.fontFamily
4255
+ v.bold,
4256
+ v.italic,
4257
+ v.fontFamily
4253
4258
  );
4254
- const h = E.fontSize === "auto" ? 5 : parseInt(E.fontSize, 10);
4259
+ const h = v.fontSize === "auto" ? 5 : parseInt(v.fontSize, 10);
4255
4260
  if (h !== 5) {
4256
4261
  const g = { 1: "\\tiny", 2: "\\scriptsize", 3: "\\footnotesize", 4: "\\small", 5: "\\normalsize", 6: "\\large", 7: "\\Large", 8: "\\LARGE", 9: "\\huge", 10: "\\Huge" };
4257
- g[h] && (s = `{${g[h]} ${s}}`);
4262
+ g[h] && (c = `{${g[h]} ${c}}`);
4258
4263
  }
4259
- E.color !== "none" && (s = `\\textcolor{${E.color}}{${s}}`), t.executeCommand(["insert", s]);
4264
+ v.color !== "none" && (c = `\\textcolor{${v.color}}{${c}}`), t.executeCommand(["insert", c]);
4260
4265
  return;
4261
4266
  }
4262
4267
  r.key === " " ? (r.preventDefault(), t.executeCommand(["insert", "\\, "])) : r.key === "Enter" && (r.preventDefault(), r.stopImmediatePropagation(), t.executeCommand("addRowAfter"));
4263
4268
  };
4264
4269
  return t.addEventListener("keydown", i, !0), () => t.removeEventListener("keydown", i, !0);
4265
- }, [l, E, q, p]), D(() => {
4266
- const t = p;
4270
+ }, [l, v, q, d]), D(() => {
4271
+ const t = d;
4267
4272
  if (!t) return;
4268
4273
  const i = () => {
4269
4274
  window.__cmeIgnoreStyleUpdate && Date.now() < window.__cmeIgnoreStyleUpdate || (P(t) && (window.__cmeManualBold = void 0, window.__cmeManualItalic = void 0, window.__cmeManualFontFamily = void 0, window.__cmeManualFontSize = void 0), setTimeout(() => {
4270
4275
  const r = t.shadowRoot;
4271
4276
  if (!r) return;
4272
- const s = r.querySelector(".ML__caret") || r.querySelector('[class*="caret"]');
4273
- s && s.scrollIntoView({ behavior: "auto", block: "nearest", inline: "nearest" }), q();
4277
+ const c = r.querySelector(".ML__caret") || r.querySelector('[class*="caret"]');
4278
+ c && c.scrollIntoView({ behavior: "auto", block: "nearest", inline: "nearest" }), q();
4274
4279
  }, 0));
4275
4280
  };
4276
4281
  return t.addEventListener("selection-change", i), t.addEventListener("input", i), t.addEventListener("keydown", i), t.addEventListener("pointerup", i), t.addEventListener("click", i), setTimeout(q, 50), () => {
4277
4282
  t.removeEventListener("selection-change", i), t.removeEventListener("input", i), t.removeEventListener("keydown", i), t.removeEventListener("pointerup", i), t.removeEventListener("click", i);
4278
4283
  };
4279
- }, [q, p]), D(() => {
4280
- const t = p;
4284
+ }, [q, d]), D(() => {
4285
+ const t = d;
4281
4286
  if (!t) return;
4282
4287
  const i = () => {
4283
4288
  const r = t.shadowRoot;
4284
4289
  if (!r || r.querySelector("style[data-cme-sqrt-fix]")) return;
4285
- const s = document.createElement("style");
4286
- s.setAttribute("data-cme-sqrt-fix", "1"), s.textContent = `
4290
+ const c = document.createElement("style");
4291
+ c.setAttribute("data-cme-sqrt-fix", "1"), c.textContent = `
4287
4292
  .ML__sqrt-line {
4288
4293
  min-width: 0.6em !important;
4289
4294
  }
4290
- `, r.appendChild(s);
4295
+ `, r.appendChild(c);
4291
4296
  };
4292
4297
  if (t.shadowRoot)
4293
4298
  i();
@@ -4297,26 +4302,26 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
4297
4302
  });
4298
4303
  return r.observe(t, { childList: !0, subtree: !1 }), () => r.disconnect();
4299
4304
  }
4300
- }, [p]);
4301
- const G = fe((t) => {
4305
+ }, [d]);
4306
+ const G = Ee((t) => {
4302
4307
  const i = ie;
4303
4308
  if (!i || !t) return;
4304
4309
  i.focus();
4305
4310
  const r = de(
4306
4311
  t,
4307
- E.bold,
4308
- E.italic,
4309
- E.fontFamily
4312
+ v.bold,
4313
+ v.italic,
4314
+ v.fontFamily
4310
4315
  );
4311
4316
  i.executeCommand(["insert", r]);
4312
- }, [E]), Ge = fe((t, i, r) => {
4313
- let s = `\\begin{${t}} `;
4317
+ }, [v]), Ge = Ee((t, i, r) => {
4318
+ let c = `\\begin{${t}} `;
4314
4319
  for (let h = 0; h < i; h++) {
4315
4320
  for (let g = 0; g < r; g++)
4316
- s += "#?", g < r - 1 && (s += " & ");
4317
- h < i - 1 && (s += " \\\\ ");
4321
+ c += "#?", g < r - 1 && (c += " & ");
4322
+ h < i - 1 && (c += " \\\\ ");
4318
4323
  }
4319
- s += ` \\end{${t}}`, G(s);
4324
+ c += ` \\end{${t}}`, G(c);
4320
4325
  }, [G]), $e = (t) => {
4321
4326
  t.stopPropagation(), Te((i) => !i), We(!1), Y({ x: 0, y: 0 });
4322
4327
  }, et = (t) => {
@@ -4325,26 +4330,26 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
4325
4330
  t && t.stopPropagation();
4326
4331
  const i = ie;
4327
4332
  if (!i) {
4328
- o && o();
4333
+ s && s();
4329
4334
  return;
4330
4335
  }
4331
- const r = i.getValue ? i.getValue("latex") : i.value, s = c || "";
4332
- !r || r.trim() === "" || r === s ? o && o() : ae(!0);
4336
+ const r = i.getValue ? i.getValue("latex") : i.value, c = o || "";
4337
+ !r || r.trim() === "" || r === c ? s && s() : ae(!0);
4333
4338
  }, tt = () => {
4334
4339
  const t = ie;
4335
4340
  if (!t) return;
4336
4341
  let i = t.getValue ? t.getValue("latex") : t.value;
4337
4342
  if (!i || i.trim() === "") {
4338
- o && o();
4343
+ s && s();
4339
4344
  return;
4340
4345
  }
4341
- l === "chem" && (i = ft(i)), i = ne(i);
4346
+ l === "chem" && (i = Et(i)), i = ne(i);
4342
4347
  const r = i.match(/^\\(mathrm|mathit|mathbf|mathsf|text)\{\\displaylines\{([\s\S]*)\}\}$/);
4343
4348
  if (r) {
4344
- const s = r[1];
4345
- i = `\\displaylines{${r[2].split("\\\\").map((C) => `\\${s}{${C.trim()}}`).join(" \\\\ ")}}`;
4349
+ const c = r[1];
4350
+ i = `\\displaylines{${r[2].split("\\\\").map((C) => `\\${c}{${C.trim()}}`).join(" \\\\ ")}}`;
4346
4351
  }
4347
- i = i.replace(/[\r\n]+/g, " "), n && n(i), t.setValue ? t.setValue("") : t.value = "", o && o();
4352
+ i = i.replace(/[\r\n]+/g, " "), n && n(i), t.setValue ? t.setValue("") : t.value = "", s && s();
4348
4353
  };
4349
4354
  return re(
4350
4355
  /* @__PURE__ */ e.createElement(
@@ -4372,8 +4377,8 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
4372
4377
  key: t.isMatrix ? "matrix-tab" : t.label,
4373
4378
  className: `cme-group-tab${r ? " active" : ""}`,
4374
4379
  type: "button",
4375
- onPointerDown: (s) => {
4376
- s.preventDefault(), k(i), u(null);
4380
+ onPointerDown: (c) => {
4381
+ c.preventDefault(), k(i), u(null);
4377
4382
  }
4378
4383
  },
4379
4384
  t.mathLabel ? /* @__PURE__ */ e.createElement(
@@ -4400,8 +4405,8 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
4400
4405
  ) : t.label
4401
4406
  );
4402
4407
  })), /* @__PURE__ */ e.createElement("div", { className: "cme-toolbar-items" }, (() => {
4403
- var s;
4404
- const t = ((s = oe[L]) == null ? void 0 : s.items) || [], i = t.some((h) => h.type === "sep"), r = [];
4408
+ var c;
4409
+ const t = ((c = oe[L]) == null ? void 0 : c.items) || [], i = t.some((h) => h.type === "sep"), r = [];
4405
4410
  if (i) {
4406
4411
  let h = { cols: 2, small: !1, cls: "", items: [], moreItems: null };
4407
4412
  for (const g of t)
@@ -4428,24 +4433,24 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
4428
4433
  type: "button",
4429
4434
  className: "cme-more-trigger-btn",
4430
4435
  title: "more",
4431
- onPointerDown: (d) => {
4432
- d.preventDefault();
4436
+ onPointerDown: (p) => {
4437
+ p.preventDefault();
4433
4438
  },
4434
- onClick: (d) => {
4435
- if (d.stopPropagation(), S && S.items === h.moreItems)
4439
+ onClick: (p) => {
4440
+ if (p.stopPropagation(), S && S.items === h.moreItems)
4436
4441
  X(null);
4437
4442
  else {
4438
- const C = d.currentTarget.getBoundingClientRect(), f = oe[L] || {};
4439
- X({ cx: C.left + C.width / 2, y: C.bottom, items: h.moreItems, cols: h.moreCols, isTemplate: f.isTemplate || f.label === "√(□)" || f.isMatrix });
4443
+ const C = p.currentTarget.getBoundingClientRect(), M = oe[L] || {};
4444
+ X({ cx: C.left + C.width / 2, y: C.bottom, items: h.moreItems, cols: h.moreCols, isTemplate: M.isTemplate || M.label === "√(□)" || M.isMatrix });
4440
4445
  }
4441
4446
  }
4442
4447
  },
4443
4448
  "▶"
4444
4449
  ),
4445
- h.items.map((d, C) => {
4446
- const f = oe[L];
4447
- if (d.type === "dropdown") {
4448
- const B = d.label === "Font...", w = d.label === "Size", se = B && E.fontFamily !== "none", ce = w && E.fontSize !== "auto" && E.fontSize !== "5", he = B ? E.fontFamily === "none" ? "" : E.fontFamily : w ? E.fontSize === "auto" || E.fontSize === "5" ? "" : E.fontSize : "";
4450
+ h.items.map((p, C) => {
4451
+ const M = oe[L];
4452
+ if (p.type === "dropdown") {
4453
+ const B = p.label === "Font...", w = p.label === "Size", se = B && v.fontFamily !== "none", ce = w && v.fontSize !== "auto" && v.fontSize !== "5", he = B ? v.fontFamily === "none" ? "" : v.fontFamily : w ? v.fontSize === "auto" || v.fontSize === "5" ? "" : v.fontSize : "";
4449
4454
  return /* @__PURE__ */ e.createElement(
4450
4455
  "select",
4451
4456
  {
@@ -4453,7 +4458,7 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
4453
4458
  className: `cme-btn template${se || ce ? " active" : ""}`,
4454
4459
  value: he,
4455
4460
  style: {
4456
- width: d.width || "60px",
4461
+ width: p.width || "60px",
4457
4462
  height: "18px",
4458
4463
  minHeight: "18px",
4459
4464
  maxHeight: "18px",
@@ -4470,12 +4475,12 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
4470
4475
  !F || typeof F.applyStyle != "function" || (F.focus(), B ? F.applyStyle({ fontFamily: _ || "none" }) : w && F.applyStyle({ fontSize: _ ? parseInt(_, 10) : "auto" }), q());
4471
4476
  }
4472
4477
  },
4473
- /* @__PURE__ */ e.createElement("option", { value: "" }, d.label),
4478
+ /* @__PURE__ */ e.createElement("option", { value: "" }, p.label),
4474
4479
  B && /* @__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")),
4475
4480
  w && /* @__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"))
4476
4481
  );
4477
4482
  }
4478
- if (f.isMatrix && !d.directInsert)
4483
+ if (M.isMatrix && !p.directInsert)
4479
4484
  return /* @__PURE__ */ e.createElement(
4480
4485
  "div",
4481
4486
  {
@@ -4486,23 +4491,23 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
4486
4491
  "button",
4487
4492
  {
4488
4493
  type: "button",
4489
- className: `cme-btn template${d.cls ? ` ${d.cls}` : ""}${f.isMatrix ? " cme-matrix-btn-small" : ""}`,
4490
- title: d.title || d.label || d.insert,
4494
+ className: `cme-btn template${p.cls ? ` ${p.cls}` : ""}${M.isMatrix ? " cme-matrix-btn-small" : ""}`,
4495
+ title: p.title || p.label || p.insert,
4491
4496
  onPointerDown: (B) => {
4492
- if (B.preventDefault(), B.stopPropagation(), (v == null ? void 0 : v.type) === d.insert)
4497
+ if (B.preventDefault(), B.stopPropagation(), (x == null ? void 0 : x.type) === p.insert)
4493
4498
  u(null);
4494
4499
  else {
4495
4500
  K || (window.__cmeManualBold = void 0, window.__cmeManualItalic = void 0, window.__cmeManualFontFamily = void 0, window.__cmeManualFontSize = void 0);
4496
4501
  const w = B.currentTarget.getBoundingClientRect();
4497
4502
  u({
4498
- type: d.insert,
4503
+ type: p.insert,
4499
4504
  x: w.left + w.width / 2,
4500
4505
  y: w.bottom
4501
4506
  });
4502
4507
  }
4503
4508
  }
4504
4509
  },
4505
- typeof d.label == "object" ? d.label : /* @__PURE__ */ e.createElement(
4510
+ typeof p.label == "object" ? p.label : /* @__PURE__ */ e.createElement(
4506
4511
  "math-field",
4507
4512
  {
4508
4513
  "read-only": !0,
@@ -4521,34 +4526,34 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
4521
4526
  cursor: "pointer"
4522
4527
  }
4523
4528
  },
4524
- Ae(d.mathLabel != null ? d.mathLabel : d.insert)
4529
+ Ae(p.mathLabel != null ? p.mathLabel : p.insert)
4525
4530
  )
4526
4531
  )
4527
4532
  );
4528
- const N = d.action === "BOLD", H = d.action === "ITALIC", R = d.action === "TEXT_COLOR", lt = N && E.bold || H && E.italic || R && E.color !== "none" && E.color !== "black";
4533
+ const N = p.action === "BOLD", H = p.action === "ITALIC", R = p.action === "TEXT_COLOR", lt = N && v.bold || H && v.italic || R && v.color !== "none" && v.color !== "black";
4529
4534
  return /* @__PURE__ */ e.createElement(
4530
4535
  "button",
4531
4536
  {
4532
- key: `${f.label}-${g * 4 + C}`,
4537
+ key: `${M.label}-${g * 4 + C}`,
4533
4538
  type: "button",
4534
- className: `cme-btn${f.isTemplate ? " template" : ""}${d.cls ? ` ${d.cls}` : ""}${lt ? " active" : ""}`,
4535
- title: d.title || d.label || d.insert,
4539
+ className: `cme-btn${M.isTemplate ? " template" : ""}${p.cls ? ` ${p.cls}` : ""}${lt ? " active" : ""}`,
4540
+ title: p.title || p.label || p.insert,
4536
4541
  onPointerDown: (B) => {
4537
4542
  var se, ce, he, me, _, F, Re;
4538
4543
  B.preventDefault();
4539
4544
  const w = m.current;
4540
- if (d.action === "SPECIAL_CHARS") {
4545
+ if (p.action === "SPECIAL_CHARS") {
4541
4546
  const W = B.currentTarget.getBoundingClientRect();
4542
- x({ x: W.left, y: W.bottom + 4 });
4543
- } else if (d.action === "TEXT_COLOR") {
4547
+ f({ x: W.left, y: W.bottom + 4 });
4548
+ } else if (p.action === "TEXT_COLOR") {
4544
4549
  const W = B.currentTarget.getBoundingClientRect();
4545
4550
  I({ x: W.left, y: W.bottom + 4 });
4546
- } else if (d.action === "BOLD") {
4551
+ } else if (p.action === "BOLD") {
4547
4552
  if (w) {
4548
4553
  w.focus();
4549
- const W = P(w), U = !(W ? Be(w) : E.bold);
4554
+ const W = P(w), U = !(W ? Be(w) : v.bold);
4550
4555
  if (window.__cmeManualBold = U, window.__cmeIgnoreStyleUpdate = Date.now() + 50, W) {
4551
- const O = w.getValue(w.selection), $ = w.getValue(), ee = (Ee) => Ee.replace(/\\[a-zA-Z]+/g, "").replace(/[^a-zA-Z0-9]/g, ""), z = ee(O), te = ee($), j = z.length > 0 && z === te, ye = Pe(j ? $ : O), Q = de(ye, U, E.italic, E.fontFamily);
4556
+ const O = w.getValue(w.selection), $ = w.getValue(), ee = (fe) => fe.replace(/\\[a-zA-Z]+/g, "").replace(/[^a-zA-Z0-9]/g, ""), z = ee(O), te = ee($), j = z.length > 0 && z === te, ye = Pe(j ? $ : O), Q = de(ye, U, v.italic, v.fontFamily);
4552
4557
  console.log("[CME-BOLD] selAlnum=", z, "fullAlnum=", te, "isFullSel=", j), console.log("[CME-BOLD] formatted=", JSON.stringify(Q)), j ? (w.setValue(Q), console.log("[CME-BOLD] after setValue:", JSON.stringify(w.getValue()))) : w.executeCommand(["insert", Q]);
4553
4558
  } else if (typeof w.applyStyle == "function")
4554
4559
  if (U)
@@ -4564,12 +4569,12 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
4564
4569
  q();
4565
4570
  }, 60);
4566
4571
  }
4567
- } else if (d.action === "ITALIC") {
4572
+ } else if (p.action === "ITALIC") {
4568
4573
  if (w) {
4569
4574
  w.focus();
4570
- const W = P(w), U = !(W ? De(w) : E.italic);
4575
+ const W = P(w), U = !(W ? De(w) : v.italic);
4571
4576
  if (window.__cmeManualItalic = U, window.__cmeIgnoreStyleUpdate = Date.now() + 50, W) {
4572
- const O = w.getValue(w.selection), $ = w.getValue(), ee = (Ee) => Ee.replace(/\\[a-zA-Z]+/g, "").replace(/[^a-zA-Z0-9]/g, ""), z = ee(O), te = ee($), j = z.length > 0 && z === te, ye = Pe(j ? $ : O), Q = de(ye, E.bold, U, E.fontFamily);
4577
+ const O = w.getValue(w.selection), $ = w.getValue(), ee = (fe) => fe.replace(/\\[a-zA-Z]+/g, "").replace(/[^a-zA-Z0-9]/g, ""), z = ee(O), te = ee($), j = z.length > 0 && z === te, ye = Pe(j ? $ : O), Q = de(ye, v.bold, U, v.fontFamily);
4573
4578
  console.log("[CME-ITALIC] selAlnum=", z, "fullAlnum=", te, "isFullSel=", j), console.log("[CME-ITALIC] formatted=", JSON.stringify(Q)), j ? (w.setValue(Q), console.log("[CME-ITALIC] after setValue:", JSON.stringify(w.getValue()))) : w.executeCommand(["insert", Q]);
4574
4579
  } else if (typeof w.applyStyle == "function")
4575
4580
  if (U)
@@ -4585,16 +4590,16 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
4585
4590
  q();
4586
4591
  }, 60);
4587
4592
  }
4588
- } else d.action === "UNDO" ? (se = m.current) == null || se.executeCommand("undo") : d.action === "REDO" ? (ce = m.current) == null || ce.executeCommand("redo") : d.action === "CUT" ? ((he = m.current) == null || he.focus(), (me = m.current) == null || me.executeCommand("cutToClipboard")) : d.action === "COPY" ? ((_ = m.current) == null || _.focus(), (F = m.current) == null || F.executeCommand("copyToClipboard")) : d.action === "PASTE" ? ((Re = m.current) == null || Re.focus(), navigator.clipboard.readText().then((W) => {
4593
+ } else p.action === "UNDO" ? (se = m.current) == null || se.executeCommand("undo") : p.action === "REDO" ? (ce = m.current) == null || ce.executeCommand("redo") : p.action === "CUT" ? ((he = m.current) == null || he.focus(), (me = m.current) == null || me.executeCommand("cutToClipboard")) : p.action === "COPY" ? ((_ = m.current) == null || _.focus(), (F = m.current) == null || F.executeCommand("copyToClipboard")) : p.action === "PASTE" ? ((Re = m.current) == null || Re.focus(), navigator.clipboard.readText().then((W) => {
4589
4594
  var J;
4590
4595
  (J = m.current) == null || J.executeCommand(["insert", W]);
4591
4596
  }).catch((W) => {
4592
4597
  var J;
4593
4598
  (J = m.current) == null || J.executeCommand("pasteFromClipboard");
4594
- })) : G(d.insert);
4599
+ })) : G(p.insert);
4595
4600
  }
4596
4601
  },
4597
- (f.isTemplate || f.label === "√(□)" || f.isMatrix || d.isWidget) && d.insert && !d.action && !d.forceLabel ? /* @__PURE__ */ e.createElement(
4602
+ (M.isTemplate || M.label === "√(□)" || M.isMatrix || p.isWidget) && p.insert && !p.action && !p.forceLabel ? /* @__PURE__ */ e.createElement(
4598
4603
  "math-field",
4599
4604
  {
4600
4605
  "read-only": !0,
@@ -4613,8 +4618,8 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
4613
4618
  cursor: "pointer"
4614
4619
  }
4615
4620
  },
4616
- Ae(d.insert)
4617
- ) : d.label
4621
+ Ae(p.insert)
4622
+ ) : p.label
4618
4623
  );
4619
4624
  })
4620
4625
  ));
@@ -4625,12 +4630,12 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
4625
4630
  ref: (t) => {
4626
4631
  t && requestAnimationFrame(() => {
4627
4632
  const i = t.getBoundingClientRect(), r = document.querySelector(".cme-editor-popup");
4628
- let s = S.cx - i.width / 2, h = S.y;
4633
+ let c = S.cx - i.width / 2, h = S.y;
4629
4634
  if (r) {
4630
4635
  const g = r.getBoundingClientRect();
4631
- s + i.width > g.right - 4 && (s = g.right - i.width - 4), s < g.left + 4 && (s = g.left + 4), h + i.height > g.bottom - 4 && (h = g.bottom - i.height - 4);
4636
+ c + i.width > g.right - 4 && (c = g.right - i.width - 4), c < g.left + 4 && (c = g.left + 4), h + i.height > g.bottom - 4 && (h = g.bottom - i.height - 4);
4632
4637
  }
4633
- s + i.width > window.innerWidth - 4 && (s = window.innerWidth - i.width - 4), h + i.height > window.innerHeight - 4 && (h = window.innerHeight - i.height - 4), s < 4 && (s = 4), t.style.left = `${s}px`, t.style.top = `${h}px`, t.style.transform = "none";
4638
+ c + i.width > window.innerWidth - 4 && (c = window.innerWidth - i.width - 4), h + i.height > window.innerHeight - 4 && (h = window.innerHeight - i.height - 4), c < 4 && (c = 4), t.style.left = `${c}px`, t.style.top = `${h}px`, t.style.transform = "none";
4634
4639
  });
4635
4640
  },
4636
4641
  className: "cme-more-popup",
@@ -4691,9 +4696,9 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
4691
4696
  "math-field",
4692
4697
  {
4693
4698
  ref: (t) => {
4694
- m.current = t, ie = t, t && p !== t && (y(t), t.inlineShortcuts = Object.assign({}, t.inlineShortcuts, { "*": "*" }), window.mathVirtualKeyboard && (window.mathVirtualKeyboard.policy = "manual"), t.menuItems && (t.menuItems = t.menuItems.filter((i) => {
4695
- const r = typeof i.label == "string" ? i.label.toLowerCase() : "", s = typeof i.id == "string" ? i.id.toLowerCase() : "";
4696
- return !r.includes("matrix") && !s.includes("matrix");
4699
+ m.current = t, ie = t, t && d !== t && (E(t), t.inlineShortcuts = Object.assign({}, t.inlineShortcuts, { "*": "*" }), window.mathVirtualKeyboard && (window.mathVirtualKeyboard.policy = "manual"), t.menuItems && (t.menuItems = t.menuItems.filter((i) => {
4700
+ const r = typeof i.label == "string" ? i.label.toLowerCase() : "", c = typeof i.id == "string" ? i.id.toLowerCase() : "";
4701
+ return !r.includes("matrix") && !c.includes("matrix");
4697
4702
  })));
4698
4703
  },
4699
4704
  class: "cme-mathfield",
@@ -4707,19 +4712,19 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
4707
4712
  Ye && /* @__PURE__ */ e.createElement("div", { className: "cme-confirm-overlay", onPointerDown: (t) => {
4708
4713
  t.stopPropagation(), ae(!1);
4709
4714
  } }, /* @__PURE__ */ e.createElement("div", { className: "cme-confirm-modal", onPointerDown: (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) => {
4710
- t.stopPropagation(), ae(!1), o && o();
4715
+ t.stopPropagation(), ae(!1), s && s();
4711
4716
  } }, "Close"), /* @__PURE__ */ e.createElement("button", { type: "button", className: "cme-confirm-cancel-btn", onClick: (t) => {
4712
4717
  t.stopPropagation(), ae(!1);
4713
4718
  } }, "Cancel")))),
4714
- v && re(
4719
+ x && re(
4715
4720
  /* @__PURE__ */ e.createElement(
4716
4721
  vt,
4717
4722
  {
4718
- matrixType: v.type,
4719
- x: v.x,
4720
- y: v.y,
4723
+ matrixType: x.type,
4724
+ x: x.x,
4725
+ y: x.y,
4721
4726
  onSelect: (t, i) => {
4722
- Ge(v.type, t, i), u(null);
4727
+ Ge(x.type, t, i), u(null);
4723
4728
  },
4724
4729
  onMouseEnter: () => {
4725
4730
  },
@@ -4729,15 +4734,15 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
4729
4734
  ),
4730
4735
  document.body
4731
4736
  ),
4732
- M && re(
4737
+ y && re(
4733
4738
  /* @__PURE__ */ e.createElement(
4734
4739
  dt,
4735
4740
  {
4736
- isOpen: !!M,
4737
- position: M,
4738
- onClose: () => x(null),
4741
+ isOpen: !!y,
4742
+ position: y,
4743
+ onClose: () => f(null),
4739
4744
  onInsert: (t) => {
4740
- G(t), x(null);
4745
+ G(t), f(null);
4741
4746
  }
4742
4747
  }
4743
4748
  ),
@@ -4789,7 +4794,7 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
4789
4794
  "violet",
4790
4795
  "gold"
4791
4796
  ].map((t) => {
4792
- const i = E.color === t || t === "black" && (E.color === "none" || !E.color);
4797
+ const i = v.color === t || t === "black" && (v.color === "none" || !v.color);
4793
4798
  return /* @__PURE__ */ e.createElement(
4794
4799
  "div",
4795
4800
  {
@@ -4805,8 +4810,8 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
4805
4810
  },
4806
4811
  onPointerDown: (r) => {
4807
4812
  r.preventDefault(), r.stopPropagation();
4808
- const s = m.current;
4809
- s && typeof s.applyStyle == "function" && (s.focus(), s.applyStyle({ color: t === "black" ? "none" : t }), q()), I(null);
4813
+ const c = m.current;
4814
+ c && typeof c.applyStyle == "function" && (c.focus(), c.applyStyle({ color: t === "black" ? "none" : t }), q()), I(null);
4810
4815
  }
4811
4816
  }
4812
4817
  );
@@ -4818,14 +4823,14 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
4818
4823
  document.body
4819
4824
  );
4820
4825
  }
4821
- const Bt = ({ isOpen: l, mode: n, initialValue: o, onInsert: c, onClose: a }) => l ? /* @__PURE__ */ e.createElement(
4826
+ const Bt = ({ isOpen: l, mode: n, initialValue: s, onInsert: o, onClose: a }) => l ? /* @__PURE__ */ e.createElement(
4822
4827
  Mt,
4823
4828
  {
4824
4829
  mode: n,
4825
- onInsert: c,
4830
+ onInsert: o,
4826
4831
  onClose: a,
4827
- initialLatex: o || "",
4828
- isEditing: !!o
4832
+ initialLatex: s || "",
4833
+ isEditing: !!s
4829
4834
  }
4830
4835
  ) : null;
4831
4836
  export {