digi-mathchem-editor 1.0.8 → 1.0.11

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";
@@ -302,10 +302,10 @@ const Me = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAYAAAD0eNT6AA
302
302
  function ie(l) {
303
303
  const o = l == null ? void 0 : l.shadowRoot;
304
304
  if (!o) return;
305
- const n = l.hasAttribute("read-only") || l.hasAttribute("readonly"), s = n ? "readonly" : "editable";
306
- let i = o.querySelector(`[${ye}]`);
307
- i && i.getAttribute("data-cache") === s || (i || (i = document.createElement("style"), i.setAttribute(ye, "true"), o.appendChild(i)), i.setAttribute("data-cache", s), i.textContent = `
308
- ${n ? `
305
+ const a = l.hasAttribute("read-only") || l.hasAttribute("readonly"), s = a ? "readonly" : "editable";
306
+ let n = o.querySelector(`[${ye}]`);
307
+ n && n.getAttribute("data-cache") === s || (n || (n = document.createElement("style"), n.setAttribute(ye, "true"), o.appendChild(n)), n.setAttribute("data-cache", s), n.textContent = `
308
+ ${a ? `
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,15 +318,15 @@ function qe() {
318
318
  let me = null;
319
319
  function Fe() {
320
320
  me || (qe(), me = new MutationObserver((l) => {
321
- var o, n, s;
322
- for (const i of l) {
323
- if (i.type === "attributes" && ((o = i.target.tagName) == null ? void 0 : o.toLowerCase()) === "math-field") {
324
- ie(i.target);
321
+ var o, a, s;
322
+ for (const n of l) {
323
+ if (n.type === "attributes" && ((o = n.target.tagName) == null ? void 0 : o.toLowerCase()) === "math-field") {
324
+ ie(n.target);
325
325
  continue;
326
326
  }
327
- if (i.addedNodes)
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))));
327
+ if (n.addedNodes)
328
+ for (const c of n.addedNodes)
329
+ c instanceof Element && (((a = c.tagName) == null ? void 0 : a.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,
@@ -347,62 +347,62 @@ const Ce = [
347
347
  ], Ze = () => {
348
348
  const l = [];
349
349
  return Ce.slice(1).forEach((o) => {
350
- o.ranges.forEach((n) => {
351
- for (let s = n[0]; s <= n[1]; s++) {
350
+ o.ranges.forEach((a) => {
351
+ for (let s = a[0]; s <= a[1]; s++) {
352
352
  if (s >= 127 && s <= 159) continue;
353
- const i = String.fromCodePoint(s);
354
- new RegExp("\\p{C}", "u").test(i) || l.push({
353
+ const n = String.fromCodePoint(s);
354
+ new RegExp("\\p{C}", "u").test(n) || l.push({
355
355
  code: s.toString(16).toUpperCase().padStart(4, "0"),
356
- char: i,
356
+ char: n,
357
357
  category: o.id
358
358
  });
359
359
  }
360
360
  });
361
361
  }), l;
362
362
  }, Je = Ze();
363
- function je({ isOpen: l, onClose: o, onInsert: n, position: s }) {
364
- const [i, c] = B(""), [h, u] = B("All");
363
+ function je({ isOpen: l, onClose: o, onInsert: a, position: s }) {
364
+ const [n, 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()) {
371
- const E = i.trim().toUpperCase();
370
+ if (m !== "All" && (k = k.filter((E) => E.category === m)), n.trim()) {
371
+ const E = n.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, n]), I = xe(() => {
376
+ if (m !== "All" && !n.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, n]), 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",
397
397
  placeholder: "Code",
398
- value: i,
398
+ value: n,
399
399
  onChange: (k) => c(k.target.value),
400
400
  className: "scm-code-input"
401
401
  }
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
  },
@@ -413,7 +413,7 @@ function je({ isOpen: l, onClose: o, onInsert: n, position: s }) {
413
413
  key: b.code,
414
414
  className: "scm-char-btn",
415
415
  onClick: () => {
416
- n(b.char), o();
416
+ a(b.char), o();
417
417
  },
418
418
  title: `U+${b.code}`
419
419
  },
@@ -449,52 +449,52 @@ 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 a, s, n, 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
- 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"))))
456
+ if (u instanceof HTMLElement && ((a = u.classList) != null && a.contains("ck-math-widget") || (s = u.dataset) != null && s.mathId || (n = u.classList) != null && n.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 "";
462
- let o = "", n = 0;
463
- for (; n < l.length; ) {
464
- let s = l.indexOf("\\placeholder", n);
462
+ let o = "", a = 0;
463
+ for (; a < l.length; ) {
464
+ let s = l.indexOf("\\placeholder", a);
465
465
  if (s === -1) {
466
- o += l.slice(n);
466
+ o += l.slice(a);
467
467
  break;
468
468
  }
469
- if (o += l.slice(n, s), n = s + 12, l[n] === "[") {
470
- let i = 1;
471
- for (n++; n < l.length && i > 0; )
472
- l[n] === "[" ? i++ : l[n] === "]" && i--, n++;
469
+ if (o += l.slice(a, s), a = s + 12, l[a] === "[") {
470
+ let n = 1;
471
+ for (a++; a < l.length && n > 0; )
472
+ l[a] === "[" ? n++ : l[a] === "]" && n--, a++;
473
473
  }
474
- if (l[n] === "{") {
475
- let i = 1, c = n + 1;
476
- for (n++; n < l.length && i > 0; )
477
- l[n] === "{" ? i++ : l[n] === "}" && i--, n++;
478
- let h = l.slice(c, n - 1);
479
- h.trim() === "" ? o += "\\quad " : o += h;
474
+ if (l[a] === "{") {
475
+ let n = 1, c = a + 1;
476
+ for (a++; a < l.length && n > 0; )
477
+ l[a] === "{" ? n++ : l[a] === "}" && n--, a++;
478
+ let m = l.slice(c, a - 1);
479
+ m.trim() === "" ? o += "\\quad " : o += m;
480
480
  }
481
481
  }
482
482
  return o;
483
483
  }
484
- function X(l) {
485
- let o = "", n = 0;
484
+ function z(l) {
485
+ let o = "", a = 0;
486
486
  const s = "\\text{";
487
- for (; n < l.length; ) {
488
- const i = l.indexOf(s, n);
489
- if (i === -1) {
490
- o += l.slice(n);
487
+ for (; a < l.length; ) {
488
+ const n = l.indexOf(s, a);
489
+ if (n === -1) {
490
+ o += l.slice(a);
491
491
  break;
492
492
  }
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;
493
+ o += l.slice(a, n);
494
+ let c = 1, m = n + s.length;
495
+ for (; m < l.length && c > 0; )
496
+ l[m] === "{" ? c++ : l[m] === "}" && c--, m++;
497
+ o += l.slice(n + s.length, m - 1), a = m;
498
498
  }
499
499
  return o;
500
500
  }
@@ -505,8 +505,8 @@ function oe(l) {
505
505
  if (!l) return "";
506
506
  const o = l.getAttribute("data-latex");
507
507
  if (o) return o;
508
- const n = l.querySelector("math-field");
509
- return n ? n.getValue ? n.getValue("latex-expanded") : n.value || "" : "";
508
+ const a = l.querySelector("math-field");
509
+ return a ? a.getValue ? a.getValue("latex-expanded") : a.value || "" : "";
510
510
  }
511
511
  function Le(l, o) {
512
512
  if (!l || !o) return !1;
@@ -519,41 +519,41 @@ function Le(l, o) {
519
519
  function ze(l, o) {
520
520
  var u;
521
521
  if (!l || !o) return null;
522
- const n = l.model.document.selection.getSelectedElement();
523
- if ((n == null ? void 0 : n.name) === "mathInline") return n;
522
+ const a = l.model.document.selection.getSelectedElement();
523
+ if ((a == null ? void 0 : a.name) === "mathInline") return a;
524
524
  const s = o.getAttribute("data-math-id");
525
525
  if (s) {
526
526
  const x = window.__ckMathWidgets.get(s);
527
527
  if (Le(l, x)) return x;
528
528
  }
529
- const i = l.editing.view.domConverter.mapDomToView(o);
530
- if (i) {
531
- const x = l.editing.mapper.toModelElement(i);
529
+ const n = l.editing.view.domConverter.mapDomToView(o);
530
+ if (n) {
531
+ const x = l.editing.mapper.toModelElement(n);
532
532
  if ((x == null ? void 0 : x.name) === "mathInline") return x;
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;
541
541
  }
542
- function Se(l, o, n, s) {
542
+ function Se(l, o, a, s) {
543
543
  if (!l || l._mathWidgetOpening) return;
544
544
  l._mathWidgetOpening = !0, queueMicrotask(() => {
545
545
  l._mathWidgetOpening = !1;
546
546
  });
547
- const i = Le(l, o) ? o : ze(l, s), c = (i == null ? void 0 : i.getAttribute("latex")) || n || oe(s);
547
+ const n = Le(l, o) ? o : ze(l, s), c = (n == null ? void 0 : n.getAttribute("latex")) || a || oe(s);
548
548
  if (!c) return;
549
- i && l.model.change((u) => {
550
- u.setSelection(i, "on");
549
+ n && l.model.change((u) => {
550
+ u.setSelection(n, "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(n, c), window.dispatchEvent(new CustomEvent("editAneesWidget", {
554
554
  detail: {
555
555
  editor: l,
556
- modelElement: i,
556
+ modelElement: n,
557
557
  latex: c
558
558
  }
559
559
  }));
@@ -561,11 +561,11 @@ function Se(l, o, n, s) {
561
561
  function Xe(l, o) {
562
562
  if (!o || o._ckMathClickBound) return;
563
563
  o._ckMathClickBound = !0;
564
- const n = (s) => {
565
- var i;
566
- s.button === 0 && (s.preventDefault(), s.stopPropagation(), (i = s.stopImmediatePropagation) == null || i.call(s), Se(l, null, oe(o), o));
564
+ const a = (s) => {
565
+ var n;
566
+ s.button === 0 && (s.preventDefault(), s.stopPropagation(), (n = s.stopImmediatePropagation) == null || n.call(s), Se(l, null, oe(o), o));
567
567
  };
568
- o.addEventListener("mousedown", n, !0), o.addEventListener("click", n, !0);
568
+ o.addEventListener("mousedown", a, !0), o.addEventListener("click", a, !0);
569
569
  }
570
570
  const Ke = [
571
571
  {
@@ -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
  {
@@ -2003,7 +2003,7 @@ const Ke = [
2003
2003
  // { type: 'sep', cols: 2, cls: 'cme-trig-subgroup' }
2004
2004
  // ]
2005
2005
  // },
2006
- ], Ye = [
2006
+ ], _e = [
2007
2007
  {
2008
2008
  label: "H₂O",
2009
2009
  isChem: !0,
@@ -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
  {
@@ -3605,11 +3605,11 @@ const Ke = [
3605
3605
  // ]
3606
3606
  // },
3607
3607
  ];
3608
- function _e(l = "") {
3608
+ function Ye(l = "") {
3609
3609
  if (String(l).match(/^\\ce\{([\s\S]*)\}$/) || l.includes("\\class{cme-"))
3610
3610
  return l;
3611
- const n = l.replace(/\\text\{([^}]*)\}/g, "$1").replace(/\$/g, "").trim();
3612
- return n ? `\\ce{${n}}` : "";
3611
+ const a = l.replace(/\\text\{([^}]*)\}/g, "$1").replace(/\$/g, "").trim();
3612
+ return a ? `\\ce{${a}}` : "";
3613
3613
  }
3614
3614
  function pe(l) {
3615
3615
  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{}");
@@ -3628,20 +3628,20 @@ class at extends He {
3628
3628
  isObject: !0,
3629
3629
  allowWhere: "$text",
3630
3630
  allowAttributes: ["latex"]
3631
- }), o.model.schema.addChildCheck((s, i) => {
3632
- if (i.name === "mathInline")
3631
+ }), o.model.schema.addChildCheck((s, n) => {
3632
+ if (n.name === "mathInline")
3633
3633
  return !0;
3634
3634
  }), o.conversion.for("editingDowncast").elementToElement({
3635
3635
  model: "mathInline",
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);
3639
- const u = i.createContainerElement("span", {
3636
+ view: (s, { writer: n }) => {
3637
+ const c = s.getAttribute("latex") || "", m = "math-" + Math.random().toString(36).substr(2, 9);
3638
+ window.__ckMathWidgets.set(m, s);
3639
+ const u = n.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
- }), x = i.createRawElement(
3644
+ }), x = n.createRawElement(
3645
3645
  "span",
3646
3646
  {
3647
3647
  class: "ck-math-widget-inner",
@@ -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);
@@ -3682,35 +3682,35 @@ class at extends He {
3682
3682
  k(), requestAnimationFrame(k);
3683
3683
  }
3684
3684
  );
3685
- return i.insert(i.createPositionAt(u, 0), x), Ue(u, i, { label: "math formula" });
3685
+ return n.insert(n.createPositionAt(u, 0), x), Ue(u, n, { label: "math formula" });
3686
3686
  }
3687
3687
  });
3688
- const n = o.editing.view.document;
3689
- this.listenTo(n, "mousedown", (s, i) => {
3690
- const c = Qe(i.domTarget);
3691
- c && i.domEvent.button === 0 && (s.stop(), i.preventDefault(), Se(
3688
+ const a = o.editing.view.document;
3689
+ this.listenTo(a, "mousedown", (s, n) => {
3690
+ const c = Qe(n.domTarget);
3691
+ c && n.domEvent.button === 0 && (s.stop(), n.preventDefault(), Se(
3692
3692
  o,
3693
3693
  null,
3694
3694
  oe(c),
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", (n, c, m) => {
3699
+ if (!m.consumable.consume(c.item, n.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
  }
@@ -3720,82 +3720,82 @@ class at extends He {
3720
3720
  });
3721
3721
  }), o.conversion.for("dataDowncast").elementToElement({
3722
3722
  model: "mathInline",
3723
- view: (s, { writer: i }) => {
3724
- const c = s.getAttribute("latex") || "", h = i.createContainerElement("span", {
3723
+ view: (s, { writer: n }) => {
3724
+ const c = s.getAttribute("latex") || "", m = n.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")), n.insert(n.createPositionAt(m, 0), n.createText(u)), m;
3736
3736
  }
3737
3737
  }), o.conversion.for("upcast").elementToElement({
3738
3738
  view: {
3739
3739
  name: "span",
3740
3740
  classes: "math-tex"
3741
3741
  },
3742
- model: (s, { writer: i }) => {
3742
+ model: (s, { writer: n }) => {
3743
3743
  const c = s.getAttribute("data-latex") || "";
3744
- return i.createElement("mathInline", { latex: c });
3744
+ return n.createElement("mathInline", { latex: c });
3745
3745
  }
3746
3746
  });
3747
3747
  }
3748
3748
  }
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) => {
3749
+ function Ge({ matrixType: l, x: o, y: a, onSelect: s, onMouseEnter: n, onMouseLeave: c }) {
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",
3784
- style: { top: `${n}px`, left: `${o}px` },
3784
+ style: { top: `${a}px`, left: `${o}px` },
3785
3785
  onMouseDown: (b) => b.stopPropagation(),
3786
- onMouseEnter: i,
3786
+ onMouseEnter: n,
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;
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);
3840
+ let F = !1, be = null, V = null;
3841
+ function $e({ mode: l, onInsert: o, onClose: a, initialLatex: s, isEditing: n }) {
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, _] = B(!1), se = re(null);
3845
3845
  O(() => {
3846
- const t = (a) => {
3846
+ const t = (r) => {
3847
3847
  if (!U) return;
3848
- let d = a.clientX - J.current.x, g = a.clientY - J.current.y;
3848
+ let d = r.clientX - Z.current.x, g = r.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);
3855
- return U && (window.addEventListener("mousemove", t), window.addEventListener("mouseup", r)), () => {
3856
- window.removeEventListener("mousemove", t), window.removeEventListener("mouseup", r);
3853
+ C({ x: d, y: g });
3854
+ }, i = () => X(!1);
3855
+ return U && (window.addEventListener("mousemove", t), window.addEventListener("mouseup", i)), () => {
3856
+ window.removeEventListener("mousemove", t), window.removeEventListener("mouseup", i);
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
- const r = document.querySelector(".cme-editor-popup");
3866
- if (r) {
3867
- const a = r.getBoundingClientRect();
3865
+ const i = document.querySelector(".cme-editor-popup");
3866
+ if (i) {
3867
+ const r = i.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,
3873
- width: a.width,
3874
- height: a.height
3869
+ left: r.left - T.x,
3870
+ top: r.top - T.y,
3871
+ right: r.right - T.x,
3872
+ bottom: r.bottom - T.y,
3873
+ width: r.width,
3874
+ height: r.height
3875
3875
  };
3876
3876
  }
3877
- }, P = l === "math" ? Ke : Ye, [f, ce] = B({
3877
+ }, Y = l === "math" ? Ke : _e, [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
- 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"
3888
+ const i = window.__cmeManualBold !== void 0 ? window.__cmeManualBold : t.queryStyle({ fontSeries: "b" }) === "all" || t.queryStyle({ variantStyle: "bold" }) === "all", r = 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
+ (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,31 +3915,31 @@ 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) => ({
3921
- bold: r,
3922
- italic: a,
3920
+ ce((h) => ({
3921
+ bold: i,
3922
+ italic: r,
3923
3923
  fontFamily: d,
3924
3924
  fontSize: String(g),
3925
3925
  color: w
3926
3926
  }));
3927
- } catch (r) {
3928
- console.warn("Failed to query active styles:", r);
3927
+ } catch (i) {
3928
+ console.warn("Failed to query active styles:", i);
3929
3929
  }
3930
3930
  }, []);
3931
3931
  O(() => {
3932
3932
  if (!x && !k) return;
3933
- const t = (r) => {
3934
- !r.target.closest(".cme-matrix-hover-popover") && !r.target.closest(".cme-matrix-btn-wrapper") && I(null), !r.target.closest(".cme-color-picker-popup") && !r.target.closest('[title="Text Color"]') && E(null);
3933
+ const t = (i) => {
3934
+ !i.target.closest(".cme-matrix-hover-popover") && !i.target.closest(".cme-matrix-btn-wrapper") && I(null), !i.target.closest(".cme-color-picker-popup") && !i.target.closest('[title="Text Color"]') && E(null);
3935
3935
  };
3936
3936
  return window.addEventListener("mousedown", t, !0), window.addEventListener("pointerdown", t, !0), () => {
3937
3937
  window.removeEventListener("mousedown", t, !0), window.removeEventListener("pointerdown", t, !0);
3938
3938
  };
3939
3939
  }, [x, k]), O(() => {
3940
3940
  if (!b) return;
3941
- const t = (r) => {
3942
- !r.target.closest(".cme-more-popup") && !r.target.closest(".cme-more-trigger-btn") && y(null);
3941
+ const t = (i) => {
3942
+ !i.target.closest(".cme-more-popup") && !i.target.closest(".cme-more-trigger-btn") && y(null);
3943
3943
  };
3944
3944
  return window.addEventListener("mousedown", t, !0), window.addEventListener("pointerdown", t, !0), () => {
3945
3945
  window.removeEventListener("mousedown", t, !0), window.removeEventListener("pointerdown", t, !0);
@@ -3947,109 +3947,115 @@ 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";
3955
- const r = () => {
3955
+ const i = () => {
3956
3956
  if (typeof t.applyStyle == "function" && t.applyStyle({ variantStyle: "up" }), s) {
3957
- let a = s;
3957
+ let r = s;
3958
3958
  if (l === "chem") {
3959
- const d = a.match(/^\\ce\{([\s\S]*)\}$/i);
3960
- d && (a = d[1]);
3959
+ const d = r.match(/^\\ce\{([\s\S]*)\}$/i);
3960
+ d && (r = 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
+ r = z(r), r = ne(r), t.setValue ? t.setValue("", { silenceNotifications: !0 }) : t.value = "", t.executeCommand(["insert", r, { insertionMode: "replaceAll" }]);
3963
3963
  }
3964
3964
  requestAnimationFrame(() => t.focus());
3965
3965
  };
3966
- customElements.get("math-field") ? requestAnimationFrame(r) : customElements.whenDefined("math-field").then(() => requestAnimationFrame(r));
3966
+ customElements.get("math-field") ? requestAnimationFrame(i) : customElements.whenDefined("math-field").then(() => requestAnimationFrame(i));
3967
3967
  }, [l, s]), O(() => {
3968
3968
  const t = V;
3969
3969
  if (!t) return;
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;
3973
- }, 500)), a.key.length === 1 && !a.ctrlKey && !a.metaKey && !a.altKey && /[a-zA-Z0-9]/.test(a.key)) {
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) {
3970
+ const i = (r) => {
3971
+ if (["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(r.key) ? (F = !1, clearTimeout(be), window.__cmeManualBold = void 0, window.__cmeManualItalic = void 0, window.__cmeManualFontFamily = void 0, window.__cmeManualFontSize = void 0) : (r.key.length === 1 || r.key === " ") && (F = !0, clearTimeout(be), be = setTimeout(() => {
3972
+ F = !1;
3973
+ }, 500)), ["`", "~", "@", "^", "_", "$"].includes(r.key) && !r.ctrlKey && !r.metaKey && !r.altKey) {
3974
+ r.preventDefault(), r.stopPropagation();
3975
+ let d = "";
3976
+ r.key === "`" ? d = "\\text{\\char96}" : r.key === "~" ? d = "\\text{~}" : r.key === "@" ? d = "\\text{@}" : r.key === "^" ? d = "\\text{^}" : r.key === "_" ? d = "\\_" : r.key === "$" && (d = "\\$"), t.executeCommand(["insert", d]);
3977
+ return;
3978
+ }
3979
+ if (r.key.length === 1 && !r.ctrlKey && !r.metaKey && !r.altKey && /[a-zA-Z0-9]/.test(r.key)) {
3980
+ r.preventDefault(), r.stopPropagation();
3981
+ const d = f.fontFamily === "sans-serif", g = f.fontFamily === "monospace", w = f.bold, h = f.italic;
3982
+ let L = "\\mathrm";
3983
+ d ? L = "\\mathsf" : g ? L = "\\mathtt" : h && !w ? L = "\\mathit" : w && !h && (L = "\\mathbf");
3984
+ let M = `${L}{${r.key}}`;
3985
+ w && h ? (M = `\\mathbfit{${r.key}}`, d && (M = `\\boldsymbol{\\mathsf{${r.key}}}`), g && (M = `\\boldsymbol{\\mathtt{${r.key}}}`)) : w && (d || g) && (M = `\\boldsymbol{${M}}`);
3986
+ let R = M;
3987
+ const j = f.fontSize === "auto" ? 5 : parseInt(f.fontSize, 10);
3988
+ if (j !== 5) {
3983
3989
  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}}`);
3990
+ G[j] && (R = `{${G[j]} ${R}}`);
3985
3991
  }
3986
3992
  f.color !== "none" && (R = `\\textcolor{${f.color}}{${R}}`), t.executeCommand(["insert", R]);
3987
3993
  return;
3988
3994
  }
3989
- a.key === " " ? (a.preventDefault(), t.executeCommand(["insert", "\\, "])) : a.key === "Enter" && (a.preventDefault(), a.stopImmediatePropagation(), t.executeCommand("addRowAfter"));
3995
+ r.key === " " ? (r.preventDefault(), t.executeCommand(["insert", "\\, "])) : r.key === "Enter" && (r.preventDefault(), r.stopImmediatePropagation(), t.executeCommand("addRowAfter"));
3990
3996
  };
3991
- return t.addEventListener("keydown", r, !0), () => t.removeEventListener("keydown", r, !0);
3992
- }, [l, f, q]), O(() => {
3997
+ return t.addEventListener("keydown", i, !0), () => t.removeEventListener("keydown", i, !0);
3998
+ }, [l, f, P]), O(() => {
3993
3999
  const t = V;
3994
4000
  if (!t) return;
3995
- const r = () => {
4001
+ const i = () => {
3996
4002
  setTimeout(() => {
3997
- const a = t.shadowRoot;
3998
- if (!a) return;
3999
- const d = a.querySelector(".ML__caret") || a.querySelector('[class*="caret"]');
4000
- d && d.scrollIntoView({ behavior: "auto", block: "nearest", inline: "nearest" }), q();
4003
+ const r = t.shadowRoot;
4004
+ if (!r) return;
4005
+ const d = r.querySelector(".ML__caret") || r.querySelector('[class*="caret"]');
4006
+ d && d.scrollIntoView({ behavior: "auto", block: "nearest", inline: "nearest" }), P();
4001
4007
  }, 0);
4002
4008
  };
4003
- return t.addEventListener("selection-change", r), t.addEventListener("input", r), t.addEventListener("keydown", r), setTimeout(q, 50), () => {
4004
- t.removeEventListener("selection-change", r), t.removeEventListener("input", r), t.removeEventListener("keydown", r);
4009
+ return t.addEventListener("selection-change", i), t.addEventListener("input", i), t.addEventListener("keydown", i), setTimeout(P, 50), () => {
4010
+ t.removeEventListener("selection-change", i), t.removeEventListener("input", i), t.removeEventListener("keydown", i);
4005
4011
  };
4006
- }, [q]);
4007
- const j = he((t) => {
4008
- const r = V;
4009
- r && (r.focus(), r.executeCommand(["insert", t]));
4010
- }, []), Be = he((t, r, a) => {
4012
+ }, [P]);
4013
+ const J = he((t) => {
4014
+ const i = V;
4015
+ i && (i.focus(), i.executeCommand(["insert", t]));
4016
+ }, []), Be = he((t, i, r) => {
4011
4017
  let d = `\\begin{${t}} `;
4012
- for (let g = 0; g < r; g++) {
4013
- for (let w = 0; w < a; w++)
4014
- d += "#?", w < a - 1 && (d += " & ");
4015
- g < r - 1 && (d += " \\\\ ");
4018
+ for (let g = 0; g < i; g++) {
4019
+ for (let w = 0; w < r; w++)
4020
+ d += "#?", w < r - 1 && (d += " & ");
4021
+ g < i - 1 && (d += " \\\\ ");
4016
4022
  }
4017
- d += ` \\end{${t}}`, j(d);
4018
- }, [j]), De = (t) => {
4019
- t.stopPropagation(), ge((r) => !r), ke(!1), A({ x: 0, y: 0 });
4023
+ d += ` \\end{${t}}`, J(d);
4024
+ }, [J]), De = (t) => {
4025
+ t.stopPropagation(), ge((i) => !i), ke(!1), C({ x: 0, y: 0 });
4020
4026
  }, Ne = (t) => {
4021
- t.stopPropagation(), ke((r) => !r), ge(!1), A({ x: 0, y: 0 });
4027
+ t.stopPropagation(), ke((i) => !i), ge(!1), C({ x: 0, y: 0 });
4022
4028
  }, ue = (t) => {
4023
4029
  t && t.stopPropagation();
4024
- const r = V;
4025
- if (!r) {
4026
- n && n();
4030
+ const i = V;
4031
+ if (!i) {
4032
+ a && a();
4027
4033
  return;
4028
4034
  }
4029
- const a = r.getValue ? r.getValue("latex") : r.value, d = s || "";
4030
- !a || a.trim() === "" || a === d ? n && n() : _(!0);
4035
+ const r = i.getValue ? i.getValue("latex") : i.value, d = s || "";
4036
+ !r || r.trim() === "" || r === d ? a && a() : _(!0);
4031
4037
  }, Re = () => {
4032
4038
  const t = V;
4033
4039
  if (!t) return;
4034
- let r = t.getValue ? t.getValue("latex") : t.value;
4035
- if (!r || r.trim() === "") {
4036
- n && n();
4040
+ let i = t.getValue ? t.getValue("latex") : t.value;
4041
+ if (!i || i.trim() === "") {
4042
+ a && a();
4037
4043
  return;
4038
4044
  }
4039
- l === "chem" && (r = _e(r)), r = X(r);
4040
- const a = r.match(/^\\(mathrm|mathit|mathbf|mathsf|text)\{\\displaylines\{([\s\S]*)\}\}$/);
4041
- if (a) {
4042
- const d = a[1];
4043
- r = `\\displaylines{${a[2].split("\\\\").map((C) => `\\${d}{${C.trim()}}`).join(" \\\\ ")}}`;
4045
+ l === "chem" && (i = Ye(i)), i = z(i);
4046
+ const r = i.match(/^\\(mathrm|mathit|mathbf|mathsf|text)\{\\displaylines\{([\s\S]*)\}\}$/);
4047
+ if (r) {
4048
+ const d = r[1];
4049
+ i = `\\displaylines{${r[2].split("\\\\").map((L) => `\\${d}{${L.trim()}}`).join(" \\\\ ")}}`;
4044
4050
  }
4045
- r = r.replace(/[\r\n]+/g, " "), o && o(r), t.setValue ? t.setValue("") : t.value = "", n && n();
4051
+ i = i.replace(/[\r\n]+/g, " "), o && o(i), t.setValue ? t.setValue("") : t.value = "", a && a();
4046
4052
  };
4047
- return z(
4053
+ return Q(
4048
4054
  /* @__PURE__ */ e.createElement(
4049
4055
  "div",
4050
4056
  {
4051
- className: `cme-editor-popup ${Y ? "maximized" : ""} ${Te ? "minimized" : ""}`,
4052
- style: { transform: `translate(${S.x}px, ${S.y}px)` },
4057
+ className: `cme-editor-popup ${K ? "maximized" : ""} ${Te ? "minimized" : ""}`,
4058
+ style: { transform: `translate(${T.x}px, ${T.y}px)` },
4053
4059
  onMouseDown: (t) => t.stopPropagation()
4054
4060
  },
4055
4061
  /* @__PURE__ */ e.createElement("div", { className: "cme-popup-topbar" }, /* @__PURE__ */ e.createElement(
@@ -4059,18 +4065,18 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
4059
4065
  onMouseDown: Ie,
4060
4066
  style: { cursor: U ? "grabbing" : "grab" }
4061
4067
  },
4062
- /* @__PURE__ */ e.createElement("span", null, i ? l === "math" ? "Edit Math Formula" : "Edit Chemistry Formula" : l === "math" ? "Math Editor" : "Chemistry Editor")
4068
+ /* @__PURE__ */ e.createElement("span", null, n ? l === "math" ? "Edit Math Formula" : "Edit Chemistry Formula" : l === "math" ? "Math Editor" : "Chemistry Editor")
4063
4069
  ), /* @__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;
4070
+ /* @__PURE__ */ e.createElement("div", { className: "cme-toolbar", role: "toolbar", "aria-label": "Symbol palette" }, /* @__PURE__ */ e.createElement("div", { className: "cme-toolbar-groups" }, Y.map((t, i) => {
4071
+ const r = m === i;
4066
4072
  return /* @__PURE__ */ e.createElement(
4067
4073
  "button",
4068
4074
  {
4069
4075
  key: t.isMatrix ? "matrix-tab" : t.label,
4070
- className: `cme-group-tab${a ? " active" : ""}`,
4076
+ className: `cme-group-tab${r ? " active" : ""}`,
4071
4077
  type: "button",
4072
4078
  onMouseDown: (d) => {
4073
- d.preventDefault(), u(r), I(null);
4079
+ d.preventDefault(), u(i), I(null);
4074
4080
  }
4075
4081
  },
4076
4082
  t.mathLabel ? /* @__PURE__ */ e.createElement(
@@ -4090,7 +4096,7 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
4090
4096
  padding: "0",
4091
4097
  margin: "0",
4092
4098
  boxShadow: "none",
4093
- color: a ? "#333333" : "#ffffff"
4099
+ color: r ? "#333333" : "#ffffff"
4094
4100
  }
4095
4101
  },
4096
4102
  t.mathLabel
@@ -4098,21 +4104,21 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
4098
4104
  );
4099
4105
  })), /* @__PURE__ */ e.createElement("div", { className: "cme-toolbar-items" }, (() => {
4100
4106
  var d;
4101
- const t = ((d = P[h]) == null ? void 0 : d.items) || [], r = t.some((g) => g.type === "sep"), a = [];
4102
- if (r) {
4107
+ const t = ((d = Y[m]) == null ? void 0 : d.items) || [], i = t.some((g) => g.type === "sep"), r = [];
4108
+ if (i) {
4103
4109
  let g = { cols: 2, small: !1, cls: "", items: [], moreItems: null };
4104
4110
  for (const w of t)
4105
- w.type === "sep" ? (g.items.length > 0 && a.push(g), g = { cols: w.cols || 2, small: !!w.small, cls: w.cls || "", items: [], moreItems: w.moreItems || null, moreCols: w.moreCols || 1 }) : g.items.push(w);
4106
- g.items.length > 0 && a.push(g);
4111
+ w.type === "sep" ? (g.items.length > 0 && r.push(g), g = { cols: w.cols || 2, small: !!w.small, cls: w.cls || "", items: [], moreItems: w.moreItems || null, moreCols: w.moreCols || 1 }) : g.items.push(w);
4112
+ g.items.length > 0 && r.push(g);
4107
4113
  } else
4108
4114
  for (let w = 0; w < t.length; w += 4)
4109
- a.push({
4115
+ r.push({
4110
4116
  cols: 2,
4111
4117
  small: !1,
4112
4118
  cls: "",
4113
4119
  items: t.slice(w, w + 4)
4114
4120
  });
4115
- return a.map((g, w) => /* @__PURE__ */ e.createElement(
4121
+ return r.map((g, w) => /* @__PURE__ */ e.createElement(
4116
4122
  "div",
4117
4123
  {
4118
4124
  key: w,
@@ -4125,29 +4131,32 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
4125
4131
  type: "button",
4126
4132
  className: "cme-more-trigger-btn",
4127
4133
  title: "more",
4128
- onMouseDown: (m) => {
4129
- if (m.preventDefault(), b && b.items === g.moreItems)
4134
+ onMouseDown: (h) => {
4135
+ h.preventDefault();
4136
+ },
4137
+ onClick: (h) => {
4138
+ if (h.stopPropagation(), b && b.items === g.moreItems)
4130
4139
  y(null);
4131
4140
  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 });
4141
+ const L = h.currentTarget.getBoundingClientRect(), M = Y[m] || {};
4142
+ y({ cx: L.left + L.width / 2, y: L.bottom, items: g.moreItems, cols: g.moreCols, isTemplate: M.isTemplate || M.label === "√(□)" || M.isMatrix });
4134
4143
  }
4135
4144
  }
4136
4145
  },
4137
4146
  "▶"
4138
4147
  ),
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 : "";
4148
+ g.items.map((h, L) => {
4149
+ const M = Y[m];
4150
+ if (h.type === "dropdown") {
4151
+ 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
4152
  return /* @__PURE__ */ e.createElement(
4144
4153
  "select",
4145
4154
  {
4146
- key: C,
4155
+ key: L,
4147
4156
  className: `cme-btn template${$ || ee ? " active" : ""}`,
4148
4157
  value: te,
4149
4158
  style: {
4150
- width: m.width || "60px",
4159
+ width: h.width || "60px",
4151
4160
  height: "18px",
4152
4161
  minHeight: "18px",
4153
4162
  maxHeight: "18px",
@@ -4160,43 +4169,43 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
4160
4169
  gridColumn: g.cols === 3 || g.cols === 1 ? "span 1" : "span 2"
4161
4170
  },
4162
4171
  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());
4172
+ const q = le.target.value, H = V;
4173
+ !H || typeof H.applyStyle != "function" || (H.focus(), N ? H.applyStyle({ fontFamily: q || "none" }) : v && H.applyStyle({ fontSize: q ? parseInt(q, 10) : "auto" }), P());
4165
4174
  }
4166
4175
  },
4167
- /* @__PURE__ */ e.createElement("option", { value: "" }, m.label),
4176
+ /* @__PURE__ */ e.createElement("option", { value: "" }, h.label),
4168
4177
  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
4178
  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
4179
  );
4171
4180
  }
4172
- if (T.isMatrix && !m.directInsert)
4181
+ if (M.isMatrix && !h.directInsert)
4173
4182
  return /* @__PURE__ */ e.createElement(
4174
4183
  "div",
4175
4184
  {
4176
- key: C,
4185
+ key: L,
4177
4186
  className: "cme-matrix-btn-wrapper"
4178
4187
  },
4179
4188
  /* @__PURE__ */ e.createElement(
4180
4189
  "button",
4181
4190
  {
4182
4191
  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,
4192
+ className: `cme-btn template${h.cls ? ` ${h.cls}` : ""}${M.isMatrix ? " cme-matrix-btn-small" : ""}`,
4193
+ title: h.title || h.label || h.insert,
4185
4194
  onMouseDown: (N) => {
4186
- if (N.preventDefault(), N.stopPropagation(), (x == null ? void 0 : x.type) === m.insert)
4195
+ if (N.preventDefault(), N.stopPropagation(), (x == null ? void 0 : x.type) === h.insert)
4187
4196
  I(null);
4188
4197
  else {
4189
- Z || (window.__cmeManualBold = void 0, window.__cmeManualItalic = void 0, window.__cmeManualFontFamily = void 0, window.__cmeManualFontSize = void 0);
4198
+ F || (window.__cmeManualBold = void 0, window.__cmeManualItalic = void 0, window.__cmeManualFontFamily = void 0, window.__cmeManualFontSize = void 0);
4190
4199
  const v = N.currentTarget.getBoundingClientRect();
4191
4200
  I({
4192
- type: m.insert,
4201
+ type: h.insert,
4193
4202
  x: v.left + v.width / 2,
4194
4203
  y: v.bottom
4195
4204
  });
4196
4205
  }
4197
4206
  }
4198
4207
  },
4199
- typeof m.label == "object" ? m.label : /* @__PURE__ */ e.createElement(
4208
+ typeof h.label == "object" ? h.label : /* @__PURE__ */ e.createElement(
4200
4209
  "math-field",
4201
4210
  {
4202
4211
  "read-only": !0,
@@ -4215,62 +4224,62 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
4215
4224
  cursor: "pointer"
4216
4225
  }
4217
4226
  },
4218
- pe(m.mathLabel != null ? m.mathLabel : m.insert)
4227
+ pe(h.mathLabel != null ? h.mathLabel : h.insert)
4219
4228
  )
4220
4229
  )
4221
4230
  );
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";
4231
+ 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
4232
  return /* @__PURE__ */ e.createElement(
4224
4233
  "button",
4225
4234
  {
4226
- key: `${T.label}-${w * 4 + C}`,
4235
+ key: `${M.label}-${w * 4 + L}`,
4227
4236
  type: "button",
4228
- className: `cme-btn${T.isTemplate ? " template" : ""}${m.cls ? ` ${m.cls}` : ""}${Oe ? " active" : ""}`,
4229
- title: m.title || m.label || m.insert,
4237
+ className: `cme-btn${M.isTemplate ? " template" : ""}${h.cls ? ` ${h.cls}` : ""}${Oe ? " active" : ""}`,
4238
+ title: h.title || h.label || h.insert,
4230
4239
  onMouseDown: (N) => {
4231
- var $, ee, te, le, F, H, we;
4240
+ var $, ee, te, le, q, H, we;
4232
4241
  N.preventDefault();
4233
4242
  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") {
4243
+ if (h.action === "SPECIAL_CHARS") {
4244
+ const S = N.currentTarget.getBoundingClientRect();
4245
+ A({ x: S.left, y: S.bottom + 4 });
4246
+ } else if (h.action === "TEXT_COLOR") {
4247
+ const S = N.currentTarget.getBoundingClientRect();
4248
+ E({ x: S.left, y: S.bottom + 4 });
4249
+ } else if (h.action === "BOLD") {
4241
4250
  if (v) {
4242
4251
  v.focus();
4243
- const L = !f.bold;
4244
- window.__cmeManualBold = L;
4252
+ const S = !f.bold;
4253
+ window.__cmeManualBold = S;
4245
4254
  const D = v.selection;
4246
4255
  if (D && !D.isCollapsed) {
4247
4256
  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}}`]);
4257
+ 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
4258
  }
4250
- ce((W) => ({ ...W, bold: L }));
4259
+ ce((W) => ({ ...W, bold: S }));
4251
4260
  }
4252
- } else if (m.action === "ITALIC") {
4261
+ } else if (h.action === "ITALIC") {
4253
4262
  if (v) {
4254
4263
  v.focus();
4255
- const L = !f.italic;
4256
- window.__cmeManualItalic = L;
4264
+ const S = !f.italic;
4265
+ window.__cmeManualItalic = S;
4257
4266
  const D = v.selection;
4258
4267
  if (D && !D.isCollapsed) {
4259
4268
  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}}`]);
4269
+ 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
4270
  }
4262
- ce((W) => ({ ...W, italic: L }));
4271
+ ce((W) => ({ ...W, italic: S }));
4263
4272
  }
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) => {
4273
+ } 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
4274
  var D;
4266
- (D = c.current) == null || D.executeCommand(["insert", L]);
4267
- }).catch((L) => {
4275
+ (D = c.current) == null || D.executeCommand(["insert", S]);
4276
+ }).catch((S) => {
4268
4277
  var D;
4269
4278
  (D = c.current) == null || D.executeCommand("pasteFromClipboard");
4270
- })) : j(m.insert);
4279
+ })) : J(h.insert);
4271
4280
  }
4272
4281
  },
4273
- (T.isTemplate || T.label === "√(□)" || T.isMatrix || m.isWidget) && m.insert && !m.action && !m.forceLabel ? /* @__PURE__ */ e.createElement(
4282
+ (M.isTemplate || M.label === "√(□)" || M.isMatrix || h.isWidget) && h.insert && !h.action && !h.forceLabel ? /* @__PURE__ */ e.createElement(
4274
4283
  "math-field",
4275
4284
  {
4276
4285
  "read-only": !0,
@@ -4289,24 +4298,24 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
4289
4298
  cursor: "pointer"
4290
4299
  }
4291
4300
  },
4292
- pe(m.insert)
4293
- ) : m.label
4301
+ pe(h.insert)
4302
+ ) : h.label
4294
4303
  );
4295
4304
  })
4296
4305
  ));
4297
4306
  })())),
4298
- b && z(/* @__PURE__ */ e.createElement(
4307
+ b && Q(/* @__PURE__ */ e.createElement(
4299
4308
  "div",
4300
4309
  {
4301
4310
  ref: (t) => {
4302
4311
  t && requestAnimationFrame(() => {
4303
- const r = t.getBoundingClientRect(), a = document.querySelector(".cme-editor-popup");
4304
- let d = b.cx - r.width / 2, g = b.y;
4305
- if (a) {
4306
- const w = a.getBoundingClientRect();
4307
- 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);
4312
+ const i = t.getBoundingClientRect(), r = document.querySelector(".cme-editor-popup");
4313
+ let d = b.cx - i.width / 2, g = b.y;
4314
+ if (r) {
4315
+ const w = r.getBoundingClientRect();
4316
+ d + i.width > w.right - 4 && (d = w.right - i.width - 4), d < w.left + 4 && (d = w.left + 4), g + i.height > w.bottom - 4 && (g = w.bottom - i.height - 4);
4308
4317
  }
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";
4318
+ d + i.width > window.innerWidth - 4 && (d = window.innerWidth - i.width - 4), g + i.height > window.innerHeight - 4 && (g = window.innerHeight - i.height - 4), d < 4 && (d = 4), t.style.left = `${d}px`, t.style.top = `${g}px`, t.style.transform = "none";
4310
4319
  });
4311
4320
  },
4312
4321
  className: "cme-more-popup",
@@ -4315,20 +4324,19 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
4315
4324
  left: `${b.cx}px`,
4316
4325
  top: `${b.y}px`,
4317
4326
  transform: "translateX(-50%)",
4318
- visibility: "hidden",
4319
- zIndex: 1e5,
4327
+ zIndex: 2147483647,
4320
4328
  gridTemplateColumns: `repeat(${b.cols || 1}, auto)`
4321
4329
  }
4322
4330
  },
4323
- b.items.map((t, r) => /* @__PURE__ */ e.createElement(
4331
+ b.items.map((t, i) => /* @__PURE__ */ e.createElement(
4324
4332
  "button",
4325
4333
  {
4326
- key: r,
4334
+ key: i,
4327
4335
  type: "button",
4328
4336
  className: `cme-more-popup-btn ${t.cls || ""}`,
4329
4337
  title: t.title || t.label || t.insert,
4330
- onMouseDown: (a) => {
4331
- a.preventDefault(), j(t.insert), y(null);
4338
+ onMouseDown: (r) => {
4339
+ r.preventDefault(), J(t.insert), y(null);
4332
4340
  }
4333
4341
  },
4334
4342
  t.insert && !t.action && (t.cls === "template" || t.isWidget) ? /* @__PURE__ */ e.createElement(
@@ -4360,8 +4368,8 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
4360
4368
  className: "cme-mathfield-container",
4361
4369
  onMouseDown: (t) => {
4362
4370
  c.current && (t.target === c.current || c.current.contains(t.target)) || (t.preventDefault(), requestAnimationFrame(() => {
4363
- var r, a;
4364
- (a = (r = c.current) == null ? void 0 : r.focus) == null || a.call(r);
4371
+ var i, r;
4372
+ (r = (i = c.current) == null ? void 0 : i.focus) == null || r.call(i);
4365
4373
  }));
4366
4374
  }
4367
4375
  },
@@ -4369,7 +4377,7 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
4369
4377
  "math-field",
4370
4378
  {
4371
4379
  ref: (t) => {
4372
- c.current = t, V = t;
4380
+ c.current = t, V = t, t && (t.inlineShortcuts = Object.assign({}, t.inlineShortcuts, { "*": "*" }));
4373
4381
  },
4374
4382
  class: "cme-mathfield",
4375
4383
  tabIndex: 0,
@@ -4378,23 +4386,23 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
4378
4386
  }
4379
4387
  )
4380
4388
  ),
4381
- /* @__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")),
4389
+ /* @__PURE__ */ e.createElement("div", { className: "cme-popup-footer" }, /* @__PURE__ */ e.createElement("button", { type: "button", className: "cme-insert-btn", onClick: Re }, n ? "Update" : "Insert"), /* @__PURE__ */ e.createElement("button", { type: "button", className: "cme-cancel-btn", onClick: ue }, "Cancel"), /* @__PURE__ */ e.createElement("span", { style: { marginLeft: "auto", fontSize: "11px", color: "#888", alignSelf: "center", marginRight: "10px" } }, "v1.0.11")),
4382
4390
  We && /* @__PURE__ */ e.createElement("div", { className: "cme-confirm-overlay", onMouseDown: (t) => {
4383
4391
  t.stopPropagation(), _(!1);
4384
4392
  } }, /* @__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();
4393
+ t.stopPropagation(), _(!1), a && a();
4386
4394
  } }, "Close"), /* @__PURE__ */ e.createElement("button", { type: "button", className: "cme-confirm-cancel-btn", onClick: (t) => {
4387
4395
  t.stopPropagation(), _(!1);
4388
4396
  } }, "Cancel")))),
4389
- x && z(
4397
+ x && Q(
4390
4398
  /* @__PURE__ */ e.createElement(
4391
4399
  Ge,
4392
4400
  {
4393
4401
  matrixType: x.type,
4394
4402
  x: x.x,
4395
4403
  y: x.y,
4396
- onSelect: (t, r) => {
4397
- Be(x.type, t, r), I(null);
4404
+ onSelect: (t, i) => {
4405
+ Be(x.type, t, i), I(null);
4398
4406
  },
4399
4407
  onMouseEnter: () => {
4400
4408
  },
@@ -4404,21 +4412,21 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
4404
4412
  ),
4405
4413
  document.body
4406
4414
  ),
4407
- p && z(
4415
+ p && Q(
4408
4416
  /* @__PURE__ */ e.createElement(
4409
4417
  je,
4410
4418
  {
4411
4419
  isOpen: !!p,
4412
4420
  position: p,
4413
- onClose: () => M(null),
4421
+ onClose: () => A(null),
4414
4422
  onInsert: (t) => {
4415
- j(t), M(null);
4423
+ J(t), A(null);
4416
4424
  }
4417
4425
  }
4418
4426
  ),
4419
4427
  document.body
4420
4428
  ),
4421
- k && z(
4429
+ k && Q(
4422
4430
  /* @__PURE__ */ e.createElement(
4423
4431
  "div",
4424
4432
  {
@@ -4427,7 +4435,7 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
4427
4435
  position: "fixed",
4428
4436
  left: Math.min(k.x, window.innerWidth - 160) + "px",
4429
4437
  top: Math.min(k.y, window.innerHeight - 100) + "px",
4430
- zIndex: 1e5,
4438
+ zIndex: 2147483647,
4431
4439
  background: "#fff",
4432
4440
  border: "1px solid #ccc",
4433
4441
  padding: "6px",
@@ -4464,7 +4472,7 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
4464
4472
  "violet",
4465
4473
  "gold"
4466
4474
  ].map((t) => {
4467
- const r = f.color === t || t === "black" && (f.color === "none" || !f.color);
4475
+ const i = f.color === t || t === "black" && (f.color === "none" || !f.color);
4468
4476
  return /* @__PURE__ */ e.createElement(
4469
4477
  "div",
4470
4478
  {
@@ -4475,13 +4483,13 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
4475
4483
  height: "16px",
4476
4484
  backgroundColor: t,
4477
4485
  cursor: "pointer",
4478
- border: r ? "2px solid #e6c229" : "1px solid #000",
4486
+ border: i ? "2px solid #e6c229" : "1px solid #000",
4479
4487
  boxSizing: "border-box"
4480
4488
  },
4481
- onMouseDown: (a) => {
4482
- a.preventDefault(), a.stopPropagation();
4489
+ onMouseDown: (r) => {
4490
+ r.preventDefault(), r.stopPropagation();
4483
4491
  const d = c.current;
4484
- d && typeof d.applyStyle == "function" && (d.focus(), d.applyStyle({ color: t === "black" ? "none" : t }), q()), E(null);
4492
+ d && typeof d.applyStyle == "function" && (d.focus(), d.applyStyle({ color: t === "black" ? "none" : t }), P()), E(null);
4485
4493
  }
4486
4494
  }
4487
4495
  );
@@ -4493,14 +4501,14 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: i })
4493
4501
  document.body
4494
4502
  );
4495
4503
  }
4496
- const ot = ({ isOpen: l, mode: o, initialValue: n, onInsert: s, onClose: i }) => l ? /* @__PURE__ */ e.createElement(
4504
+ const ot = ({ isOpen: l, mode: o, initialValue: a, onInsert: s, onClose: n }) => l ? /* @__PURE__ */ e.createElement(
4497
4505
  $e,
4498
4506
  {
4499
4507
  mode: o,
4500
4508
  onInsert: s,
4501
- onClose: i,
4502
- initialLatex: n || "",
4503
- isEditing: !!n
4509
+ onClose: n,
4510
+ initialLatex: a || "",
4511
+ isEditing: !!a
4504
4512
  }
4505
4513
  ) : null;
4506
4514
  export {