digi-mathchem-editor 1.0.23 → 1.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/digi-mathchem-editor.es.js +128 -107
- package/dist/digi-mathchem-editor.umd.js +5 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import e, { useState as T, useEffect as
|
|
1
|
+
import e, { useState as T, useEffect as D, useMemo as Oe, useRef as le, useCallback as fe } 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";
|
|
@@ -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((
|
|
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))));
|
|
330
330
|
}
|
|
331
331
|
}), ve.observe(document.body, {
|
|
332
332
|
childList: !0,
|
|
@@ -361,28 +361,28 @@ const je = [
|
|
|
361
361
|
}), l;
|
|
362
362
|
}, mt = ht();
|
|
363
363
|
function dt({ isOpen: l, onClose: n, onInsert: o, position: c }) {
|
|
364
|
-
const [a, m] = T(""), [
|
|
365
|
-
|
|
366
|
-
l && (m(""),
|
|
364
|
+
const [a, m] = T(""), [b, p] = T("All");
|
|
365
|
+
D(() => {
|
|
366
|
+
l && (m(""), p("All"));
|
|
367
367
|
}, [l]);
|
|
368
368
|
const y = Oe(() => {
|
|
369
369
|
let u = mt;
|
|
370
|
-
if (
|
|
370
|
+
if (b !== "All" && (u = u.filter((M) => M.category === b)), a.trim()) {
|
|
371
371
|
const M = a.trim().toUpperCase();
|
|
372
372
|
u = u.filter((x) => x.code.includes(M));
|
|
373
373
|
}
|
|
374
374
|
return u;
|
|
375
|
-
}, [
|
|
376
|
-
if (
|
|
377
|
-
return { [
|
|
375
|
+
}, [b, a]), L = Oe(() => {
|
|
376
|
+
if (b !== "All" && !a.trim())
|
|
377
|
+
return { [b]: y };
|
|
378
378
|
const u = {};
|
|
379
379
|
return y.forEach((M) => {
|
|
380
380
|
u[M.category] || (u[M.category] = []), u[M.category].push(M);
|
|
381
381
|
}), u;
|
|
382
|
-
}, [y,
|
|
382
|
+
}, [y, b, a]), k = (u) => {
|
|
383
383
|
u.key === "Escape" && n();
|
|
384
384
|
};
|
|
385
|
-
if (
|
|
385
|
+
if (D(() => (l && window.addEventListener("keydown", k), () => window.removeEventListener("keydown", k)), [l]), !l) return null;
|
|
386
386
|
let v = { top: "50%", left: "50%", transform: "translate(-50%, -50%)" };
|
|
387
387
|
if (c) {
|
|
388
388
|
let u = c.x - 120, M = c.y;
|
|
@@ -402,8 +402,8 @@ function dt({ isOpen: l, onClose: n, onInsert: o, position: c }) {
|
|
|
402
402
|
), /* @__PURE__ */ e.createElement(
|
|
403
403
|
"select",
|
|
404
404
|
{
|
|
405
|
-
value:
|
|
406
|
-
onChange: (u) =>
|
|
405
|
+
value: b,
|
|
406
|
+
onChange: (u) => p(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))
|
|
@@ -420,7 +420,7 @@ function dt({ isOpen: l, onClose: n, onInsert: o, position: c }) {
|
|
|
420
420
|
x.char
|
|
421
421
|
))))), y.length === 0 && /* @__PURE__ */ e.createElement("div", { className: "scm-no-results" }, "No characters found.")))));
|
|
422
422
|
}
|
|
423
|
-
const pt = "1.0.
|
|
423
|
+
const pt = "1.0.24", bt = {
|
|
424
424
|
version: pt
|
|
425
425
|
};
|
|
426
426
|
window.__cme_macros = {
|
|
@@ -452,13 +452,13 @@ 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,
|
|
455
|
+
var o, c, a, m, b;
|
|
456
456
|
if (!l) return null;
|
|
457
457
|
const n = typeof l.composedPath == "function" ? l.composedPath() : [l];
|
|
458
|
-
for (const
|
|
459
|
-
if (
|
|
460
|
-
return
|
|
461
|
-
return l instanceof Element ? (
|
|
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;
|
|
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 "";
|
|
@@ -478,8 +478,8 @@ function Me(l) {
|
|
|
478
478
|
let a = 1, m = o + 1;
|
|
479
479
|
for (o++; o < l.length && a > 0; )
|
|
480
480
|
l[o] === "{" ? a++ : l[o] === "}" && a--, o++;
|
|
481
|
-
let
|
|
482
|
-
|
|
481
|
+
let b = l.slice(m, o - 1);
|
|
482
|
+
b.trim() === "" ? n += "\\quad " : n += b;
|
|
483
483
|
}
|
|
484
484
|
}
|
|
485
485
|
return n;
|
|
@@ -494,11 +494,11 @@ function ne(l) {
|
|
|
494
494
|
break;
|
|
495
495
|
}
|
|
496
496
|
n += l.slice(o, a);
|
|
497
|
-
let m = 1,
|
|
498
|
-
for (;
|
|
499
|
-
l[
|
|
500
|
-
const
|
|
501
|
-
/^['"/]+$/.test(
|
|
497
|
+
let m = 1, b = a + c.length;
|
|
498
|
+
for (; b < l.length && m > 0; )
|
|
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;
|
|
502
502
|
}
|
|
503
503
|
return n;
|
|
504
504
|
}
|
|
@@ -533,18 +533,18 @@ function Pe(l) {
|
|
|
533
533
|
for (; c && a < 10; ) {
|
|
534
534
|
c = !1, a++;
|
|
535
535
|
for (const m of o) {
|
|
536
|
-
let
|
|
537
|
-
for (;
|
|
538
|
-
const
|
|
539
|
-
if (
|
|
540
|
-
let y = 1, L =
|
|
536
|
+
let b = 0;
|
|
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
541
|
for (; L < n.length && y > 0; )
|
|
542
542
|
n[L] === "{" && !Ue(n, L) ? y++ : n[L] === "}" && !Ue(n, L) && y--, L++;
|
|
543
543
|
if (y === 0) {
|
|
544
|
-
const k = n.slice(
|
|
545
|
-
n = n.slice(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;
|
|
546
546
|
} else
|
|
547
|
-
|
|
547
|
+
b = p + m.length;
|
|
548
548
|
}
|
|
549
549
|
}
|
|
550
550
|
}
|
|
@@ -598,8 +598,8 @@ function qe(l, n, o, c) {
|
|
|
598
598
|
if (!l) return "";
|
|
599
599
|
if (!n && !o)
|
|
600
600
|
return ut(l, { fontFamily: c });
|
|
601
|
-
const a = c === "sans-serif", m = c === "monospace",
|
|
602
|
-
return n && o ? a ? `\\boldsymbol{\\mathsf{${l}}}` : m ? `\\boldsymbol{\\mathtt{${l}}}` :
|
|
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;
|
|
603
603
|
}
|
|
604
604
|
function de(l, n, o, c) {
|
|
605
605
|
if (!l) return "";
|
|
@@ -607,8 +607,8 @@ function de(l, n, o, c) {
|
|
|
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
|
|
611
|
-
if (
|
|
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
612
|
const y = /\\\\(?:\[[^\]]*\])?|\\cr|\\newline|\\par|\n/;
|
|
613
613
|
return `\\displaylines{${a.split(y).map((v) => {
|
|
614
614
|
const u = v.trim();
|
|
@@ -639,7 +639,7 @@ function Qe(l, n) {
|
|
|
639
639
|
}
|
|
640
640
|
}
|
|
641
641
|
function wt(l, n) {
|
|
642
|
-
var
|
|
642
|
+
var p;
|
|
643
643
|
if (!l || !n) return null;
|
|
644
644
|
const o = l.model.document.selection.getSelectedElement();
|
|
645
645
|
if ((o == null ? void 0 : o.name) === "mathInline") return o;
|
|
@@ -655,9 +655,9 @@ function wt(l, n) {
|
|
|
655
655
|
}
|
|
656
656
|
const m = ke(n);
|
|
657
657
|
if (!m) return null;
|
|
658
|
-
const
|
|
659
|
-
for (const { item: y } of l.model.createRangeIn(
|
|
660
|
-
if ((
|
|
658
|
+
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
661
|
return y;
|
|
662
662
|
return null;
|
|
663
663
|
}
|
|
@@ -668,11 +668,11 @@ function Xe(l, n, o, c) {
|
|
|
668
668
|
});
|
|
669
669
|
const a = Qe(l, n) ? n : wt(l, c), m = (a == null ? void 0 : a.getAttribute("latex")) || o || ke(c);
|
|
670
670
|
if (!m) return;
|
|
671
|
-
a && l.model.change((
|
|
672
|
-
|
|
671
|
+
a && l.model.change((p) => {
|
|
672
|
+
p.setSelection(a, "on");
|
|
673
673
|
});
|
|
674
|
-
const
|
|
675
|
-
|
|
674
|
+
const b = l.mathWidgetClickHandler || window.__ckMathWidgetClickHandler;
|
|
675
|
+
b && b(a, m), window.dispatchEvent(new CustomEvent("editAneesWidget", {
|
|
676
676
|
detail: {
|
|
677
677
|
editor: l,
|
|
678
678
|
modelElement: a,
|
|
@@ -3761,12 +3761,12 @@ class It extends it {
|
|
|
3761
3761
|
}), n.conversion.for("editingDowncast").elementToElement({
|
|
3762
3762
|
model: "mathInline",
|
|
3763
3763
|
view: (c, { writer: a }) => {
|
|
3764
|
-
const m = c.getAttribute("latex") || "",
|
|
3765
|
-
window.__ckMathWidgets.set(
|
|
3766
|
-
const
|
|
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", {
|
|
3767
3767
|
class: "ck-math-widget ck-math-inline-word",
|
|
3768
3768
|
contenteditable: "false",
|
|
3769
|
-
"data-math-id":
|
|
3769
|
+
"data-math-id": b,
|
|
3770
3770
|
"data-latex": m
|
|
3771
3771
|
}), y = a.createRawElement(
|
|
3772
3772
|
"span",
|
|
@@ -3811,7 +3811,7 @@ class It extends it {
|
|
|
3811
3811
|
u(), requestAnimationFrame(u);
|
|
3812
3812
|
}
|
|
3813
3813
|
);
|
|
3814
|
-
return a.insert(a.createPositionAt(
|
|
3814
|
+
return a.insert(a.createPositionAt(p, 0), y), at(p, a, { label: "math formula" });
|
|
3815
3815
|
}
|
|
3816
3816
|
});
|
|
3817
3817
|
const o = n.editing.view.document;
|
|
@@ -3824,12 +3824,12 @@ class It extends it {
|
|
|
3824
3824
|
m
|
|
3825
3825
|
));
|
|
3826
3826
|
}, { priority: "high" }), n.conversion.for("editingDowncast").add((c) => {
|
|
3827
|
-
c.on("attribute:latex:mathInline", (a, m,
|
|
3828
|
-
if (!
|
|
3827
|
+
c.on("attribute:latex:mathInline", (a, m, b) => {
|
|
3828
|
+
if (!b.consumable.consume(m.item, a.name))
|
|
3829
3829
|
return;
|
|
3830
|
-
const
|
|
3830
|
+
const p = b.writer, y = b.mapper.toViewElement(m.item);
|
|
3831
3831
|
if (y) {
|
|
3832
|
-
|
|
3832
|
+
p.setAttribute("data-latex", m.attributeNewValue, y);
|
|
3833
3833
|
const L = n.editing.view.domConverter.mapViewToDom(y);
|
|
3834
3834
|
if (L) {
|
|
3835
3835
|
const k = L.querySelector("math-field");
|
|
@@ -3850,20 +3850,20 @@ class It extends it {
|
|
|
3850
3850
|
}), n.conversion.for("dataDowncast").elementToElement({
|
|
3851
3851
|
model: "mathInline",
|
|
3852
3852
|
view: (c, { writer: a }) => {
|
|
3853
|
-
const m = c.getAttribute("latex") || "",
|
|
3853
|
+
const m = c.getAttribute("latex") || "", b = a.createContainerElement("span", {
|
|
3854
3854
|
class: "math-tex",
|
|
3855
3855
|
"data-latex": m,
|
|
3856
3856
|
// Keep raw latex in data-latex for restoring
|
|
3857
3857
|
style: "display:inline;"
|
|
3858
3858
|
});
|
|
3859
|
-
let
|
|
3859
|
+
let p = be(
|
|
3860
3860
|
ne(
|
|
3861
3861
|
Me(m)
|
|
3862
3862
|
)
|
|
3863
3863
|
);
|
|
3864
|
-
|
|
3865
|
-
let y =
|
|
3866
|
-
return a.insert(a.createPositionAt(
|
|
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;
|
|
3867
3867
|
}
|
|
3868
3868
|
}), n.conversion.for("upcast").elementToElement({
|
|
3869
3869
|
view: {
|
|
@@ -3878,37 +3878,37 @@ class It extends it {
|
|
|
3878
3878
|
}
|
|
3879
3879
|
}
|
|
3880
3880
|
function vt({ matrixType: l, x: n, y: o, onSelect: c, onMouseEnter: a, onMouseLeave: m }) {
|
|
3881
|
-
const [
|
|
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
3882
|
const A = x.target.value;
|
|
3883
3883
|
if (A === "") {
|
|
3884
|
-
|
|
3884
|
+
p((S) => ({ ...S, r: "" }));
|
|
3885
3885
|
return;
|
|
3886
3886
|
}
|
|
3887
3887
|
const I = parseInt(A, 10);
|
|
3888
|
-
isNaN(I) ||
|
|
3888
|
+
isNaN(I) || p((S) => ({ ...S, r: Math.max(1, Math.min(10, I)) }));
|
|
3889
3889
|
}, v = () => {
|
|
3890
|
-
(
|
|
3890
|
+
(b.r === "" || isNaN(parseInt(b.r, 10))) && p((x) => ({ ...x, r: 1 }));
|
|
3891
3891
|
}, u = (x) => {
|
|
3892
3892
|
const A = x.target.value;
|
|
3893
3893
|
if (A === "") {
|
|
3894
|
-
|
|
3894
|
+
p((S) => ({ ...S, c: "" }));
|
|
3895
3895
|
return;
|
|
3896
3896
|
}
|
|
3897
3897
|
const I = parseInt(A, 10);
|
|
3898
|
-
isNaN(I) ||
|
|
3898
|
+
isNaN(I) || p((S) => ({ ...S, c: Math.max(1, Math.min(10, I)) }));
|
|
3899
3899
|
}, M = () => {
|
|
3900
|
-
(
|
|
3900
|
+
(b.c === "" || isNaN(parseInt(b.c, 10))) && p((x) => ({ ...x, c: 1 }));
|
|
3901
3901
|
};
|
|
3902
|
-
return
|
|
3902
|
+
return D(() => {
|
|
3903
3903
|
const x = (A) => {
|
|
3904
3904
|
if (A.key === "Enter") {
|
|
3905
3905
|
A.preventDefault(), A.stopPropagation();
|
|
3906
|
-
const I = parseInt(
|
|
3906
|
+
const I = parseInt(b.r, 10) || 1, S = parseInt(b.c, 10) || 1;
|
|
3907
3907
|
c(I, S);
|
|
3908
3908
|
}
|
|
3909
3909
|
};
|
|
3910
3910
|
return window.addEventListener("keydown", x, !0), () => window.removeEventListener("keydown", x, !0);
|
|
3911
|
-
}, [
|
|
3911
|
+
}, [b.r, b.c, c]), /* @__PURE__ */ e.createElement(
|
|
3912
3912
|
"div",
|
|
3913
3913
|
{
|
|
3914
3914
|
className: "cme-matrix-hover-popover ck-only",
|
|
@@ -3918,13 +3918,13 @@ function vt({ matrixType: l, x: n, y: o, onSelect: c, onMouseEnter: a, onMouseLe
|
|
|
3918
3918
|
onMouseLeave: m
|
|
3919
3919
|
},
|
|
3920
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) => {
|
|
3921
|
-
const X = parseInt(
|
|
3921
|
+
const X = parseInt(b.r, 10) || 0, V = parseInt(b.c, 10) || 0, Y = A < X && S < V;
|
|
3922
3922
|
return /* @__PURE__ */ e.createElement(
|
|
3923
3923
|
"div",
|
|
3924
3924
|
{
|
|
3925
3925
|
key: `${A}-${S}`,
|
|
3926
3926
|
className: `cme-matrix-hover-cell${Y ? " selected" : ""}`,
|
|
3927
|
-
onMouseEnter: () =>
|
|
3927
|
+
onMouseEnter: () => p({ r: A + 1, c: S + 1 }),
|
|
3928
3928
|
onClick: (Z) => {
|
|
3929
3929
|
Z.preventDefault(), Z.stopPropagation(), c(A + 1, S + 1);
|
|
3930
3930
|
}
|
|
@@ -3936,16 +3936,16 @@ function vt({ matrixType: l, x: n, y: o, onSelect: c, onMouseEnter: a, onMouseLe
|
|
|
3936
3936
|
{
|
|
3937
3937
|
type: "number",
|
|
3938
3938
|
className: "cme-counter-val",
|
|
3939
|
-
value:
|
|
3939
|
+
value: b.r,
|
|
3940
3940
|
onChange: k,
|
|
3941
3941
|
onBlur: v,
|
|
3942
3942
|
min: "1",
|
|
3943
3943
|
max: "10"
|
|
3944
3944
|
}
|
|
3945
|
-
), /* @__PURE__ */ e.createElement("div", { className: "cme-counter-btns" }, /* @__PURE__ */ e.createElement("button", { type: "button", onClick: () =>
|
|
3945
|
+
), /* @__PURE__ */ e.createElement("div", { className: "cme-counter-btns" }, /* @__PURE__ */ e.createElement("button", { type: "button", onClick: () => p((x) => {
|
|
3946
3946
|
const A = parseInt(x.r, 10) || 1;
|
|
3947
3947
|
return { ...x, r: Math.min(10, A + 1) };
|
|
3948
|
-
}) }, "▲"), /* @__PURE__ */ e.createElement("button", { type: "button", onClick: () =>
|
|
3948
|
+
}) }, "▲"), /* @__PURE__ */ e.createElement("button", { type: "button", onClick: () => p((x) => {
|
|
3949
3949
|
const A = parseInt(x.r, 10) || 1;
|
|
3950
3950
|
return { ...x, r: Math.max(1, A - 1) };
|
|
3951
3951
|
}) }, "▼"))), /* @__PURE__ */ e.createElement("div", { className: "cme-matrix-counter" }, /* @__PURE__ */ e.createElement("span", null, "C"), /* @__PURE__ */ e.createElement(
|
|
@@ -3953,16 +3953,16 @@ function vt({ matrixType: l, x: n, y: o, onSelect: c, onMouseEnter: a, onMouseLe
|
|
|
3953
3953
|
{
|
|
3954
3954
|
type: "number",
|
|
3955
3955
|
className: "cme-counter-val",
|
|
3956
|
-
value:
|
|
3956
|
+
value: b.c,
|
|
3957
3957
|
onChange: u,
|
|
3958
3958
|
onBlur: M,
|
|
3959
3959
|
min: "1",
|
|
3960
3960
|
max: "10"
|
|
3961
3961
|
}
|
|
3962
|
-
), /* @__PURE__ */ e.createElement("div", { className: "cme-counter-btns" }, /* @__PURE__ */ e.createElement("button", { type: "button", onClick: () =>
|
|
3962
|
+
), /* @__PURE__ */ e.createElement("div", { className: "cme-counter-btns" }, /* @__PURE__ */ e.createElement("button", { type: "button", onClick: () => p((x) => {
|
|
3963
3963
|
const A = parseInt(x.c, 10) || 1;
|
|
3964
3964
|
return { ...x, c: Math.min(10, A + 1) };
|
|
3965
|
-
}) }, "▲"), /* @__PURE__ */ e.createElement("button", { type: "button", onClick: () =>
|
|
3965
|
+
}) }, "▲"), /* @__PURE__ */ e.createElement("button", { type: "button", onClick: () => p((x) => {
|
|
3966
3966
|
const A = parseInt(x.c, 10) || 1;
|
|
3967
3967
|
return { ...x, c: Math.max(1, A - 1) };
|
|
3968
3968
|
}) }, "▼"))))
|
|
@@ -3970,25 +3970,25 @@ function vt({ matrixType: l, x: n, y: o, onSelect: c, onMouseEnter: a, onMouseLe
|
|
|
3970
3970
|
}
|
|
3971
3971
|
let K = !1, Ce = null, ie = null;
|
|
3972
3972
|
function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a }) {
|
|
3973
|
-
const m = le(null),
|
|
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);
|
|
3974
3974
|
le(null);
|
|
3975
3975
|
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
|
-
|
|
3976
|
+
D(() => {
|
|
3977
3977
|
const t = (r) => {
|
|
3978
3978
|
if (!Z) return;
|
|
3979
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
3980
|
let g = s - ue.current.x, d = h - ue.current.y;
|
|
3981
3981
|
if (we.current) {
|
|
3982
|
-
const C = we.current, f = -C.left,
|
|
3983
|
-
g < f && (g = f), g >
|
|
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);
|
|
3984
3984
|
}
|
|
3985
3985
|
Y({ x: g, y: d });
|
|
3986
3986
|
}, i = () => Le(!1);
|
|
3987
3987
|
return Z && (window.addEventListener("mousemove", t, { passive: !1 }), window.addEventListener("mouseup", i), window.addEventListener("touchmove", t, { passive: !1 }), window.addEventListener("touchend", i)), () => {
|
|
3988
3988
|
window.removeEventListener("mousemove", t), window.removeEventListener("mouseup", i), window.removeEventListener("touchmove", t), window.removeEventListener("touchend", i);
|
|
3989
3989
|
};
|
|
3990
|
-
}, [Z]),
|
|
3991
|
-
const t =
|
|
3990
|
+
}, [Z]), D(() => {
|
|
3991
|
+
const t = b.current;
|
|
3992
3992
|
if (!t) return;
|
|
3993
3993
|
let i = 0, r = 0, s = 0;
|
|
3994
3994
|
const h = (d) => {
|
|
@@ -3997,8 +3997,8 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
|
|
|
3997
3997
|
if (d.touches.length !== 1) return;
|
|
3998
3998
|
const C = i - d.touches[0].clientY, f = r - d.touches[0].clientX;
|
|
3999
3999
|
if (Math.abs(C) < 10 || Math.abs(f) > Math.abs(C) || t.scrollHeight <= t.clientHeight) return;
|
|
4000
|
-
const
|
|
4001
|
-
|
|
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));
|
|
4002
4002
|
};
|
|
4003
4003
|
return t.addEventListener("touchstart", h, { passive: !0 }), t.addEventListener("touchmove", g, { passive: !1 }), () => {
|
|
4004
4004
|
t.removeEventListener("touchstart", h), t.removeEventListener("touchmove", g);
|
|
@@ -4116,9 +4116,9 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
|
|
|
4116
4116
|
f = t.getValue(sel) || "";
|
|
4117
4117
|
} catch {
|
|
4118
4118
|
}
|
|
4119
|
-
const
|
|
4120
|
-
|
|
4121
|
-
const H = [5, 7, 9].find((
|
|
4119
|
+
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";
|
|
4121
|
+
const H = [5, 7, 9].find((R) => C(t.queryStyle({ fontSize: R }))) || "auto";
|
|
4122
4122
|
g = String(H), d = [
|
|
4123
4123
|
"black",
|
|
4124
4124
|
"dimgray",
|
|
@@ -4144,7 +4144,7 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
|
|
|
4144
4144
|
"indigo",
|
|
4145
4145
|
"violet",
|
|
4146
4146
|
"gold"
|
|
4147
|
-
].find((
|
|
4147
|
+
].find((R) => C(t.queryStyle({ color: R }))) || "none";
|
|
4148
4148
|
} else
|
|
4149
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
4150
|
(f) => C(t.queryStyle({ fontFamily: f }))
|
|
@@ -4189,7 +4189,7 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
|
|
|
4189
4189
|
console.warn("Failed to query active styles:", i);
|
|
4190
4190
|
}
|
|
4191
4191
|
}, []);
|
|
4192
|
-
|
|
4192
|
+
D(() => {
|
|
4193
4193
|
if (!v && !A) return;
|
|
4194
4194
|
const t = (i) => {
|
|
4195
4195
|
!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);
|
|
@@ -4197,7 +4197,7 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
|
|
|
4197
4197
|
return window.addEventListener("mousedown", t, !0), window.addEventListener("pointerdown", t, !0), () => {
|
|
4198
4198
|
window.removeEventListener("mousedown", t, !0), window.removeEventListener("pointerdown", t, !0);
|
|
4199
4199
|
};
|
|
4200
|
-
}, [v, A]),
|
|
4200
|
+
}, [v, A]), D(() => {
|
|
4201
4201
|
if (!S) return;
|
|
4202
4202
|
const t = (i) => {
|
|
4203
4203
|
!i.target.closest(".cme-more-popup") && !i.target.closest(".cme-more-trigger-btn") && X(null);
|
|
@@ -4205,12 +4205,12 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
|
|
|
4205
4205
|
return window.addEventListener("mousedown", t, !0), window.addEventListener("pointerdown", t, !0), () => {
|
|
4206
4206
|
window.removeEventListener("mousedown", t, !0), window.removeEventListener("pointerdown", t, !0);
|
|
4207
4207
|
};
|
|
4208
|
-
}, [S]),
|
|
4208
|
+
}, [S]), D(() => {
|
|
4209
4209
|
const t = setTimeout(() => ct(), 50);
|
|
4210
4210
|
return () => clearTimeout(t);
|
|
4211
|
-
}, [L]),
|
|
4211
|
+
}, [L]), D(() => {
|
|
4212
4212
|
if (K) return;
|
|
4213
|
-
const t =
|
|
4213
|
+
const t = p;
|
|
4214
4214
|
if (!t) return;
|
|
4215
4215
|
t.macros = { ...t.macros, ...window.__cme_macros || {} }, t.defaultMode = "math";
|
|
4216
4216
|
const i = () => {
|
|
@@ -4227,8 +4227,8 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
|
|
|
4227
4227
|
});
|
|
4228
4228
|
};
|
|
4229
4229
|
customElements.get("math-field") ? requestAnimationFrame(i) : customElements.whenDefined("math-field").then(() => requestAnimationFrame(i));
|
|
4230
|
-
}, [l, c,
|
|
4231
|
-
const t =
|
|
4230
|
+
}, [l, c, p]), D(() => {
|
|
4231
|
+
const t = p;
|
|
4232
4232
|
if (!t) return;
|
|
4233
4233
|
const i = (r) => {
|
|
4234
4234
|
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(() => {
|
|
@@ -4262,8 +4262,8 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
|
|
|
4262
4262
|
r.key === " " ? (r.preventDefault(), t.executeCommand(["insert", "\\, "])) : r.key === "Enter" && (r.preventDefault(), r.stopImmediatePropagation(), t.executeCommand("addRowAfter"));
|
|
4263
4263
|
};
|
|
4264
4264
|
return t.addEventListener("keydown", i, !0), () => t.removeEventListener("keydown", i, !0);
|
|
4265
|
-
}, [l, E, q,
|
|
4266
|
-
const t =
|
|
4265
|
+
}, [l, E, q, p]), D(() => {
|
|
4266
|
+
const t = p;
|
|
4267
4267
|
if (!t) return;
|
|
4268
4268
|
const i = () => {
|
|
4269
4269
|
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(() => {
|
|
@@ -4276,7 +4276,28 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
|
|
|
4276
4276
|
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
4277
|
t.removeEventListener("selection-change", i), t.removeEventListener("input", i), t.removeEventListener("keydown", i), t.removeEventListener("pointerup", i), t.removeEventListener("click", i);
|
|
4278
4278
|
};
|
|
4279
|
-
}, [q,
|
|
4279
|
+
}, [q, p]), D(() => {
|
|
4280
|
+
const t = p;
|
|
4281
|
+
if (!t) return;
|
|
4282
|
+
const i = () => {
|
|
4283
|
+
const r = t.shadowRoot;
|
|
4284
|
+
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 = `
|
|
4287
|
+
.ML__sqrt-line {
|
|
4288
|
+
min-width: 0.6em !important;
|
|
4289
|
+
}
|
|
4290
|
+
`, r.appendChild(s);
|
|
4291
|
+
};
|
|
4292
|
+
if (t.shadowRoot)
|
|
4293
|
+
i();
|
|
4294
|
+
else {
|
|
4295
|
+
const r = new MutationObserver(() => {
|
|
4296
|
+
t.shadowRoot && (r.disconnect(), i());
|
|
4297
|
+
});
|
|
4298
|
+
return r.observe(t, { childList: !0, subtree: !1 }), () => r.disconnect();
|
|
4299
|
+
}
|
|
4300
|
+
}, [p]);
|
|
4280
4301
|
const G = fe((t) => {
|
|
4281
4302
|
const i = ie;
|
|
4282
4303
|
if (!i || !t) return;
|
|
@@ -4504,7 +4525,7 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
|
|
|
4504
4525
|
)
|
|
4505
4526
|
)
|
|
4506
4527
|
);
|
|
4507
|
-
const
|
|
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";
|
|
4508
4529
|
return /* @__PURE__ */ e.createElement(
|
|
4509
4530
|
"button",
|
|
4510
4531
|
{
|
|
@@ -4527,7 +4548,7 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
|
|
|
4527
4548
|
w.focus();
|
|
4528
4549
|
const W = P(w), U = !(W ? Be(w) : E.bold);
|
|
4529
4550
|
if (window.__cmeManualBold = U, window.__cmeIgnoreStyleUpdate = Date.now() + 50, W) {
|
|
4530
|
-
const
|
|
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);
|
|
4531
4552
|
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]);
|
|
4532
4553
|
} else if (typeof w.applyStyle == "function")
|
|
4533
4554
|
if (U)
|
|
@@ -4539,7 +4560,7 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
|
|
|
4539
4560
|
}
|
|
4540
4561
|
w.applyStyle({ fontSeries: "auto" }), w.applyStyle({ fontSeries: "m" });
|
|
4541
4562
|
}
|
|
4542
|
-
xe((
|
|
4563
|
+
xe((O) => ({ ...O, bold: U })), setTimeout(() => {
|
|
4543
4564
|
q();
|
|
4544
4565
|
}, 60);
|
|
4545
4566
|
}
|
|
@@ -4548,7 +4569,7 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
|
|
|
4548
4569
|
w.focus();
|
|
4549
4570
|
const W = P(w), U = !(W ? De(w) : E.italic);
|
|
4550
4571
|
if (window.__cmeManualItalic = U, window.__cmeIgnoreStyleUpdate = Date.now() + 50, W) {
|
|
4551
|
-
const
|
|
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);
|
|
4552
4573
|
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]);
|
|
4553
4574
|
} else if (typeof w.applyStyle == "function")
|
|
4554
4575
|
if (U)
|
|
@@ -4560,7 +4581,7 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
|
|
|
4560
4581
|
}
|
|
4561
4582
|
w.applyStyle({ shape: "auto" }), w.applyStyle({ shape: "n" });
|
|
4562
4583
|
}
|
|
4563
|
-
xe((
|
|
4584
|
+
xe((O) => ({ ...O, italic: U })), setTimeout(() => {
|
|
4564
4585
|
q();
|
|
4565
4586
|
}, 60);
|
|
4566
4587
|
}
|
|
@@ -4659,7 +4680,7 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
|
|
|
4659
4680
|
/* @__PURE__ */ e.createElement(
|
|
4660
4681
|
"div",
|
|
4661
4682
|
{
|
|
4662
|
-
ref:
|
|
4683
|
+
ref: b,
|
|
4663
4684
|
className: "cme-mathfield-container",
|
|
4664
4685
|
onPointerDown: (t) => {
|
|
4665
4686
|
var i, r;
|
|
@@ -4670,7 +4691,7 @@ function Mt({ mode: l, onInsert: n, onClose: o, initialLatex: c, isEditing: a })
|
|
|
4670
4691
|
"math-field",
|
|
4671
4692
|
{
|
|
4672
4693
|
ref: (t) => {
|
|
4673
|
-
m.current = t, ie = t, 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) => {
|
|
4674
4695
|
const r = typeof i.label == "string" ? i.label.toLowerCase() : "", s = typeof i.id == "string" ? i.id.toLowerCase() : "";
|
|
4675
4696
|
return !r.includes("matrix") && !s.includes("matrix");
|
|
4676
4697
|
})));
|