digi-mathchem-editor 1.0.32 → 1.0.33
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.
|
@@ -7389,20 +7389,20 @@ function et(o) {
|
|
|
7389
7389
|
if (!o) return "";
|
|
7390
7390
|
let t = "", e = 0;
|
|
7391
7391
|
for (; e < o.length; ) {
|
|
7392
|
-
let
|
|
7393
|
-
if (
|
|
7392
|
+
let r = o.indexOf("\\placeholder", e);
|
|
7393
|
+
if (r === -1) {
|
|
7394
7394
|
t += o.slice(e);
|
|
7395
7395
|
break;
|
|
7396
7396
|
}
|
|
7397
|
-
if (t += o.slice(e,
|
|
7398
|
-
let
|
|
7399
|
-
for (e++; e < o.length &&
|
|
7400
|
-
o[e] === "[" ?
|
|
7397
|
+
if (t += o.slice(e, r), e = r + 12, o[e] === "[") {
|
|
7398
|
+
let s = 1;
|
|
7399
|
+
for (e++; e < o.length && s > 0; )
|
|
7400
|
+
o[e] === "[" ? s++ : o[e] === "]" && s--, e++;
|
|
7401
7401
|
}
|
|
7402
7402
|
if (o[e] === "{") {
|
|
7403
|
-
let
|
|
7404
|
-
for (e++; e < o.length &&
|
|
7405
|
-
o[e] === "{" ?
|
|
7403
|
+
let s = 1, a = e + 1;
|
|
7404
|
+
for (e++; e < o.length && s > 0; )
|
|
7405
|
+
o[e] === "{" ? s++ : o[e] === "}" && s--, e++;
|
|
7406
7406
|
let l = o.slice(a, e - 1);
|
|
7407
7407
|
l.trim() === "" ? t += "\\quad " : t += l;
|
|
7408
7408
|
}
|
|
@@ -7412,26 +7412,26 @@ function et(o) {
|
|
|
7412
7412
|
function it(o) {
|
|
7413
7413
|
if (!o) return "";
|
|
7414
7414
|
let t = "", e = 0;
|
|
7415
|
-
const
|
|
7415
|
+
const r = "\\text{";
|
|
7416
7416
|
for (; e < o.length; ) {
|
|
7417
|
-
const
|
|
7418
|
-
if (
|
|
7417
|
+
const s = o.indexOf(r, e);
|
|
7418
|
+
if (s === -1) {
|
|
7419
7419
|
t += o.slice(e);
|
|
7420
7420
|
break;
|
|
7421
7421
|
}
|
|
7422
|
-
t += o.slice(e,
|
|
7423
|
-
let a = 1, l =
|
|
7422
|
+
t += o.slice(e, s);
|
|
7423
|
+
let a = 1, l = s + r.length;
|
|
7424
7424
|
for (; l < o.length && a > 0; )
|
|
7425
7425
|
o[l] === "{" ? a++ : o[l] === "}" && a--, l++;
|
|
7426
|
-
const n = o.slice(
|
|
7426
|
+
const n = o.slice(s + r.length, l - 1);
|
|
7427
7427
|
/^['"/]+$/.test(n) || n.includes("\\textquotedbl") || n.includes("\\textquotesingle") ? t += "\\text{" + n + "}" : t += n, e = l;
|
|
7428
7428
|
}
|
|
7429
7429
|
return t;
|
|
7430
7430
|
}
|
|
7431
7431
|
function P(o, t) {
|
|
7432
|
-
let e = 0,
|
|
7433
|
-
for (;
|
|
7434
|
-
e++,
|
|
7432
|
+
let e = 0, r = t - 1;
|
|
7433
|
+
for (; r >= 0 && o[r] === "\\"; )
|
|
7434
|
+
e++, r--;
|
|
7435
7435
|
return e % 2 === 1;
|
|
7436
7436
|
}
|
|
7437
7437
|
function q(o) {
|
|
@@ -7455,9 +7455,9 @@ function q(o) {
|
|
|
7455
7455
|
"\\mathsf{",
|
|
7456
7456
|
"\\mathtt{"
|
|
7457
7457
|
];
|
|
7458
|
-
let
|
|
7459
|
-
for (;
|
|
7460
|
-
|
|
7458
|
+
let r = !0, s = 0;
|
|
7459
|
+
for (; r && s < 10; ) {
|
|
7460
|
+
r = !1, s++;
|
|
7461
7461
|
for (const a of e) {
|
|
7462
7462
|
let l = 0;
|
|
7463
7463
|
for (; l < t.length; ) {
|
|
@@ -7468,7 +7468,7 @@ function q(o) {
|
|
|
7468
7468
|
t[c] === "{" && !P(t, c) ? h++ : t[c] === "}" && !P(t, c) && h--, c++;
|
|
7469
7469
|
if (h === 0) {
|
|
7470
7470
|
const d = t.slice(n + a.length, c - 1);
|
|
7471
|
-
t = t.slice(0, n) + d + t.slice(c),
|
|
7471
|
+
t = t.slice(0, n) + d + t.slice(c), r = !0, l = n;
|
|
7472
7472
|
} else
|
|
7473
7473
|
l = n + a.length;
|
|
7474
7474
|
}
|
|
@@ -7520,28 +7520,28 @@ function lt(o) {
|
|
|
7520
7520
|
function rt(o, t) {
|
|
7521
7521
|
return o ? lt(o) ? o : (t == null ? void 0 : t.fontFamily) === "sans-serif" ? `\\mathsf{${o}}` : (t == null ? void 0 : t.fontFamily) === "monospace" ? `\\mathtt{${o}}` : (t == null ? void 0 : t.fontFamily) === "roman" ? `\\mathrm{${o}}` : o : "";
|
|
7522
7522
|
}
|
|
7523
|
-
function F(o, t, e,
|
|
7523
|
+
function F(o, t, e, r) {
|
|
7524
7524
|
if (!o) return "";
|
|
7525
7525
|
if (!t && !e)
|
|
7526
|
-
return rt(o, { fontFamily:
|
|
7527
|
-
const
|
|
7528
|
-
return t && e ?
|
|
7526
|
+
return rt(o, { fontFamily: r });
|
|
7527
|
+
const s = r === "sans-serif", a = r === "monospace", l = r === "roman";
|
|
7528
|
+
return t && e ? s ? `\\boldsymbol{\\mathsf{${o}}}` : a ? `\\boldsymbol{\\mathtt{${o}}}` : l ? `\\mathbfit{\\mathrm{${o}}}` : `\\mathbfit{${o}}` : t ? s ? `\\boldsymbol{\\mathsf{${o}}}` : a ? `\\boldsymbol{\\mathtt{${o}}}` : l ? `\\mathbf{\\mathrm{${o}}}` : `\\mathbf{${o}}` : e ? s ? `\\mathsf{${o}}` : a ? `\\mathtt{${o}}` : l ? `\\mathit{\\mathrm{${o}}}` : `\\mathit{${o}}` : o;
|
|
7529
7529
|
}
|
|
7530
|
-
function B(o, t, e,
|
|
7530
|
+
function B(o, t, e, r) {
|
|
7531
7531
|
if (!o) return "";
|
|
7532
|
-
let
|
|
7533
|
-
const a =
|
|
7534
|
-
if (a && (
|
|
7535
|
-
return
|
|
7536
|
-
const n =
|
|
7537
|
-
if (n && (
|
|
7532
|
+
let s = o.trim();
|
|
7533
|
+
const a = s.match(/^\\displaylines\s*\{([\s\S]*)\}$/i);
|
|
7534
|
+
if (a && (s = a[1].trim()), s.match(/^\\begin\{(array|matrix|pmatrix|bmatrix|vmatrix|Vmatrix|align|aligned|gather|cases)\}([\s\S]*)\\end\{\1\}$/i))
|
|
7535
|
+
return s;
|
|
7536
|
+
const n = s.match(/^\\begin\{(array|gather)\}(\{[\s\S]*?\})?([\s\S]*?)\\end\{\1\}$/i);
|
|
7537
|
+
if (n && (s = n[3].trim()), /\\\\|\\cr|\\newline|\\par|\n/.test(s)) {
|
|
7538
7538
|
const h = /\\\\(?:\[[^\]]*\])?|\\cr|\\newline|\\par|\n/;
|
|
7539
|
-
return `\\displaylines{${
|
|
7539
|
+
return `\\displaylines{${s.split(h).map((w) => {
|
|
7540
7540
|
const x = w.trim();
|
|
7541
|
-
return x ? F(x, t, e,
|
|
7541
|
+
return x ? F(x, t, e, r) : "";
|
|
7542
7542
|
}).filter((w) => w.length > 0).join(" \\\\ ")}}`;
|
|
7543
7543
|
}
|
|
7544
|
-
return F(
|
|
7544
|
+
return F(s, t, e, r);
|
|
7545
7545
|
}
|
|
7546
7546
|
function st(o) {
|
|
7547
7547
|
return o ? o.replace(/\\enclose\{([^}]*)\}\s*\[.*?\]/g, "\\enclose{$1}") : "";
|
|
@@ -7549,7 +7549,7 @@ function st(o) {
|
|
|
7549
7549
|
function ot(o = "") {
|
|
7550
7550
|
if (typeof o != "string") return o;
|
|
7551
7551
|
let t = o.replace(/\\textasciitilde/g, "\\text{~}").replace(/\\textasciicircum/g, "\\text{^}").replace(/\\textasteriskcentered/g, "*").replace(/\\char96/g, "`");
|
|
7552
|
-
return t.includes("\\ce{") && (t = t.replace(/\\ce\{([\s\S]*?)\}/g, (e,
|
|
7552
|
+
return t.includes("\\ce{") && (t = t.replace(/\\ce\{([\s\S]*?)\}/g, (e, r) => r.includes("\\{") || r.includes("\\}") || r.includes("\\lbrace") || r.includes("\\rbrace") ? r : `\\ce{${r.replace(/\\left\[/g, "[").replace(/\\right\]/g, "]").replace(/\\lbrack\b/g, "[").replace(/\\rbrack\b/g, "]").replace(/\\left\(/g, "(").replace(/\\right\)/g, ")").replace(/\\left\|/g, "|").replace(/\\right\|/g, "|").replace(/\\left\./g, "").replace(/\\right\./g, "").replace(/\\enspace(?:\s|{})?/g, "~")}}`)), t;
|
|
7553
7553
|
}
|
|
7554
7554
|
const Z = "data-mathfield-shadow-styles", at = `
|
|
7555
7555
|
.ML__content, .ML__container, .ML__field-container, .ML__formula {
|
|
@@ -7882,10 +7882,10 @@ function Q(o, t = null) {
|
|
|
7882
7882
|
try {
|
|
7883
7883
|
const e = o.shadowRoot;
|
|
7884
7884
|
if (!e) return;
|
|
7885
|
-
const
|
|
7886
|
-
if (!
|
|
7887
|
-
const
|
|
7888
|
-
if (
|
|
7885
|
+
const r = e.querySelector(".ML__caret") || e.querySelector(".ML__focused") || e.querySelector(".ML__selection") || e.querySelector(".ML__selected") || e.querySelector("[class*='caret']") || e.querySelector("[class*='focused']");
|
|
7886
|
+
if (!r) return;
|
|
7887
|
+
const s = r.getBoundingClientRect();
|
|
7888
|
+
if (s.top === 0 && s.left === 0 && s.width === 0 && s.height === 0)
|
|
7889
7889
|
return;
|
|
7890
7890
|
const a = [];
|
|
7891
7891
|
t && t.isConnected && a.push(t);
|
|
@@ -7901,18 +7901,18 @@ function Q(o, t = null) {
|
|
|
7901
7901
|
const n = 40, h = 20;
|
|
7902
7902
|
for (const c of a) {
|
|
7903
7903
|
const d = c.getBoundingClientRect();
|
|
7904
|
-
if (
|
|
7905
|
-
const w =
|
|
7904
|
+
if (s.right + n > d.right) {
|
|
7905
|
+
const w = s.right + n - d.right;
|
|
7906
7906
|
c.scrollLeft += w;
|
|
7907
|
-
} else if (
|
|
7908
|
-
const w = d.left - (
|
|
7907
|
+
} else if (s.left - n < d.left) {
|
|
7908
|
+
const w = d.left - (s.left - n);
|
|
7909
7909
|
c.scrollLeft -= w;
|
|
7910
7910
|
}
|
|
7911
|
-
if (
|
|
7912
|
-
const w =
|
|
7911
|
+
if (s.bottom + h > d.bottom) {
|
|
7912
|
+
const w = s.bottom + h - d.bottom;
|
|
7913
7913
|
c.scrollTop += w;
|
|
7914
|
-
} else if (
|
|
7915
|
-
const w = d.top - (
|
|
7914
|
+
} else if (s.top - h < d.top) {
|
|
7915
|
+
const w = d.top - (s.top - h);
|
|
7916
7916
|
c.scrollTop -= w;
|
|
7917
7917
|
}
|
|
7918
7918
|
}
|
|
@@ -7929,10 +7929,10 @@ function nt(o) {
|
|
|
7929
7929
|
function L(o) {
|
|
7930
7930
|
const t = o == null ? void 0 : o.shadowRoot;
|
|
7931
7931
|
if (!t) return;
|
|
7932
|
-
const e = o.hasAttribute("read-only") || o.hasAttribute("readonly"),
|
|
7932
|
+
const e = o.hasAttribute("read-only") || o.hasAttribute("readonly"), r = e ? "readonly" : "editable";
|
|
7933
7933
|
e || nt(o);
|
|
7934
|
-
let
|
|
7935
|
-
|
|
7934
|
+
let s = t.querySelector(`[${Z}]`);
|
|
7935
|
+
s && s.getAttribute("data-cache") === r || (s || (s = document.createElement("style"), s.setAttribute(Z, "true"), t.appendChild(s)), s.setAttribute("data-cache", r), s.textContent = `
|
|
7936
7936
|
${e ? `
|
|
7937
7937
|
:host, :host * { cursor: pointer !important; }
|
|
7938
7938
|
.ML__latex, .ML__content, .ML__container, .ML__virtual-keyboard-toggle { cursor: pointer !important; }
|
|
@@ -7946,15 +7946,15 @@ function ht() {
|
|
|
7946
7946
|
let N = null;
|
|
7947
7947
|
function ct() {
|
|
7948
7948
|
N || (ht(), N = new MutationObserver((o) => {
|
|
7949
|
-
var t, e,
|
|
7950
|
-
for (const
|
|
7951
|
-
if (
|
|
7952
|
-
L(
|
|
7949
|
+
var t, e, r;
|
|
7950
|
+
for (const s of o) {
|
|
7951
|
+
if (s.type === "attributes" && ((t = s.target.tagName) == null ? void 0 : t.toLowerCase()) === "math-field") {
|
|
7952
|
+
L(s.target);
|
|
7953
7953
|
continue;
|
|
7954
7954
|
}
|
|
7955
|
-
if (
|
|
7956
|
-
for (const a of
|
|
7957
|
-
a instanceof Element && (((e = a.tagName) == null ? void 0 : e.toLowerCase()) === "math-field" && requestAnimationFrame(() => L(a)), (
|
|
7955
|
+
if (s.addedNodes)
|
|
7956
|
+
for (const a of s.addedNodes)
|
|
7957
|
+
a instanceof Element && (((e = a.tagName) == null ? void 0 : e.toLowerCase()) === "math-field" && requestAnimationFrame(() => L(a)), (r = a.querySelectorAll) == null || r.call(a, "math-field").forEach(
|
|
7958
7958
|
(l) => requestAnimationFrame(() => L(l))
|
|
7959
7959
|
));
|
|
7960
7960
|
}
|
|
@@ -7978,12 +7978,12 @@ const X = [
|
|
|
7978
7978
|
const o = [];
|
|
7979
7979
|
return X.slice(1).forEach((t) => {
|
|
7980
7980
|
t.ranges.forEach((e) => {
|
|
7981
|
-
for (let
|
|
7982
|
-
if (
|
|
7983
|
-
const
|
|
7984
|
-
new RegExp("\\p{C}", "u").test(
|
|
7985
|
-
code:
|
|
7986
|
-
char:
|
|
7981
|
+
for (let r = e[0]; r <= e[1]; r++) {
|
|
7982
|
+
if (r >= 127 && r <= 159) continue;
|
|
7983
|
+
const s = String.fromCodePoint(r);
|
|
7984
|
+
new RegExp("\\p{C}", "u").test(s) || o.push({
|
|
7985
|
+
code: r.toString(16).toUpperCase().padStart(4, "0"),
|
|
7986
|
+
char: s,
|
|
7987
7987
|
category: t.id
|
|
7988
7988
|
});
|
|
7989
7989
|
}
|
|
@@ -8009,7 +8009,7 @@ class pt {
|
|
|
8009
8009
|
let t = mt;
|
|
8010
8010
|
if (this.selectedCategory !== "All" && (t = t.filter((e) => e.category === this.selectedCategory)), this.searchCode.trim()) {
|
|
8011
8011
|
const e = this.searchCode.trim().toUpperCase();
|
|
8012
|
-
t = t.filter((
|
|
8012
|
+
t = t.filter((r) => r.code.includes(e));
|
|
8013
8013
|
}
|
|
8014
8014
|
return t;
|
|
8015
8015
|
}
|
|
@@ -8017,8 +8017,8 @@ class pt {
|
|
|
8017
8017
|
if (this.selectedCategory !== "All" && !this.searchCode.trim())
|
|
8018
8018
|
return { [this.selectedCategory]: t };
|
|
8019
8019
|
const e = {};
|
|
8020
|
-
return t.forEach((
|
|
8021
|
-
e[
|
|
8020
|
+
return t.forEach((r) => {
|
|
8021
|
+
e[r.category] || (e[r.category] = []), e[r.category].push(r);
|
|
8022
8022
|
}), e;
|
|
8023
8023
|
}
|
|
8024
8024
|
render(t) {
|
|
@@ -8031,30 +8031,30 @@ class pt {
|
|
|
8031
8031
|
this.modal.style.top = "50%", this.modal.style.left = "50%", this.modal.style.transform = "translate(-50%, -50%)";
|
|
8032
8032
|
const e = document.createElement("div");
|
|
8033
8033
|
e.className = "scm-toolbar";
|
|
8034
|
-
const
|
|
8035
|
-
|
|
8034
|
+
const r = document.createElement("input");
|
|
8035
|
+
r.type = "text", r.placeholder = "Code", r.className = "scm-code-input", r.value = this.searchCode, r.addEventListener("input", (l) => {
|
|
8036
8036
|
this.searchCode = l.target.value, this.updateGrid();
|
|
8037
8037
|
});
|
|
8038
|
-
const
|
|
8039
|
-
|
|
8038
|
+
const s = document.createElement("select");
|
|
8039
|
+
s.className = "scm-category-select", X.forEach((l) => {
|
|
8040
8040
|
const n = document.createElement("option");
|
|
8041
|
-
n.value = l.id, n.textContent = l.name,
|
|
8042
|
-
}),
|
|
8041
|
+
n.value = l.id, n.textContent = l.name, s.appendChild(n);
|
|
8042
|
+
}), s.value = this.selectedCategory, s.addEventListener("change", (l) => {
|
|
8043
8043
|
this.selectedCategory = l.target.value, this.updateGrid();
|
|
8044
|
-
}), e.appendChild(
|
|
8044
|
+
}), e.appendChild(r), e.appendChild(s), this.modal.appendChild(e);
|
|
8045
8045
|
const a = document.createElement("div");
|
|
8046
|
-
a.className = "scm-body", this.bodyContainer = document.createElement("div"), this.bodyContainer.className = "scm-grid-container", a.appendChild(this.bodyContainer), this.modal.appendChild(a), this.updateGrid(), this.overlay.appendChild(this.modal), document.body.appendChild(this.overlay), setTimeout(() =>
|
|
8046
|
+
a.className = "scm-body", this.bodyContainer = document.createElement("div"), this.bodyContainer.className = "scm-grid-container", a.appendChild(this.bodyContainer), this.modal.appendChild(a), this.updateGrid(), this.overlay.appendChild(this.modal), document.body.appendChild(this.overlay), setTimeout(() => r.focus(), 50);
|
|
8047
8047
|
}
|
|
8048
8048
|
updateGrid() {
|
|
8049
8049
|
if (!this.bodyContainer) return;
|
|
8050
8050
|
this.bodyContainer.innerHTML = "";
|
|
8051
|
-
const t = this.getFilteredCharacters(), e = this.getGroupedCharacters(t),
|
|
8052
|
-
if (
|
|
8053
|
-
const
|
|
8054
|
-
|
|
8051
|
+
const t = this.getFilteredCharacters(), e = this.getGroupedCharacters(t), r = Object.entries(e);
|
|
8052
|
+
if (r.length === 0 || t.length === 0) {
|
|
8053
|
+
const s = document.createElement("div");
|
|
8054
|
+
s.className = "scm-no-results", s.textContent = "No characters found.", this.bodyContainer.appendChild(s);
|
|
8055
8055
|
return;
|
|
8056
8056
|
}
|
|
8057
|
-
|
|
8057
|
+
r.forEach(([s, a]) => {
|
|
8058
8058
|
const l = document.createElement("div");
|
|
8059
8059
|
l.className = "scm-category-group";
|
|
8060
8060
|
const n = document.createElement("div");
|
|
@@ -8070,7 +8070,7 @@ class pt {
|
|
|
8070
8070
|
this.close();
|
|
8071
8071
|
}
|
|
8072
8072
|
}
|
|
8073
|
-
const bt = "1.0.
|
|
8073
|
+
const bt = "1.0.33", E = {
|
|
8074
8074
|
version: bt
|
|
8075
8075
|
};
|
|
8076
8076
|
typeof window < "u" && (window.MathfieldElement ? window.MathfieldElement.fontsDirectory = "https://cdn.jsdelivr.net/npm/mathlive/dist/fonts" : V && (V.fontsDirectory = "https://cdn.jsdelivr.net/npm/mathlive/dist/fonts"));
|
|
@@ -8093,15 +8093,17 @@ const D = class D {
|
|
|
8093
8093
|
if (!(!t || t === this.mode) && (this.mode = t, this.activeGroup = 0, this.explicitToggle = !1, this.closeAllPopups(), this.specCharModal && this.specCharModal.close(), this.isOpen && this.popup)) {
|
|
8094
8094
|
const e = this.popup.querySelector(".cme-popup-header span");
|
|
8095
8095
|
if (e) {
|
|
8096
|
-
const
|
|
8097
|
-
e.textContent =
|
|
8096
|
+
const r = this.title || (this.isEditing ? this.mode === "chem" ? "Edit Chemistry Formula" : "Edit Math Formula" : this.mode === "chem" ? "Chemistry Editor" : "Math Editor");
|
|
8097
|
+
e.textContent = r;
|
|
8098
8098
|
}
|
|
8099
8099
|
this.renderTabs(), this.renderToolbarItems();
|
|
8100
8100
|
}
|
|
8101
8101
|
}
|
|
8102
8102
|
open(t = "", e = null) {
|
|
8103
8103
|
if (this.isOpen) {
|
|
8104
|
-
e && e !== this.mode && this.setMode(e)
|
|
8104
|
+
e && e !== this.mode && this.setMode(e);
|
|
8105
|
+
let r = t || "";
|
|
8106
|
+
this.mode === "chem" && r.startsWith("\\ce{") && r.endsWith("}") && (r = r.slice(4, -1)), this.mode === "chem" && (r = r.replace(/~/g, "\\enspace ")), this.setValue(r), this.initialLatex = t || "", this.isEditing = !!t;
|
|
8105
8107
|
return;
|
|
8106
8108
|
}
|
|
8107
8109
|
this.isOpen = !0, this.position = { x: 0, y: 0 }, this.isDragging = !1, this.isMaximized = !1, this.isMinimized = !1, this.initialLatex = t || "", this.isEditing = !!t, e && (this.mode = e), this.activeGroup = 0, this.explicitToggle = !1, this.activeStyles = {
|
|
@@ -8151,13 +8153,13 @@ const D = class D {
|
|
|
8151
8153
|
}
|
|
8152
8154
|
handleInsert() {
|
|
8153
8155
|
let t = this.getValue();
|
|
8154
|
-
t = et(t), t = it(t), t = st(t), this.mode === "chem" && (t = t.replace(/\\enspace(?:\s|{})?/g, "
|
|
8156
|
+
t = et(t), t = it(t), t = st(t), this.mode === "chem" && (t = t.replace(/\\enspace(?:\s|{})?/g, "~"), t.includes("\\displaylines") || t.includes("\\\\") || t.includes("\\class{cme-") || t.includes("\\xleftrightarrows") || t.includes("\\xleftrightharpoons") || t.includes("\\enclose") || t.includes("\\{") || t.includes("\\}") || t.includes("\\lbrace") || t.includes("\\rbrace") ? /^\\ce\{[\s\S]*\}$/i.test(t.trim()) && (t = t.trim().replace(/^\\ce\{([\s\S]*)\}$/i, "$1")) : t.trim() && !t.trim().startsWith("\\ce{") && !t.includes("\\ce{") && (t = `\\ce{${t}}`)), this.onInsert(t), this.close();
|
|
8155
8157
|
}
|
|
8156
8158
|
insertAtCursor(t) {
|
|
8157
8159
|
if (this.closeAllPopups(), !this.mathField) return;
|
|
8158
8160
|
const e = this.mathField;
|
|
8159
8161
|
if (e.smartSuperscript = !1, e.focus(), typeof t == "string") {
|
|
8160
|
-
const
|
|
8162
|
+
const r = B(
|
|
8161
8163
|
t,
|
|
8162
8164
|
this.activeStyles.bold,
|
|
8163
8165
|
this.activeStyles.italic,
|
|
@@ -8165,11 +8167,11 @@ const D = class D {
|
|
|
8165
8167
|
);
|
|
8166
8168
|
e.executeCommand ? e.executeCommand([
|
|
8167
8169
|
"insert",
|
|
8168
|
-
|
|
8170
|
+
r,
|
|
8169
8171
|
{ selectionMode: "placeholder" }
|
|
8170
|
-
]) : e.insert(
|
|
8172
|
+
]) : e.insert(r);
|
|
8171
8173
|
} else if (t && t.insert) {
|
|
8172
|
-
const
|
|
8174
|
+
const r = t.action === "INSERT_CUSTOM" || t.directInsert ? B(
|
|
8173
8175
|
t.insert,
|
|
8174
8176
|
this.activeStyles.bold,
|
|
8175
8177
|
this.activeStyles.italic,
|
|
@@ -8177,9 +8179,9 @@ const D = class D {
|
|
|
8177
8179
|
) : t.insert;
|
|
8178
8180
|
e.executeCommand ? e.executeCommand([
|
|
8179
8181
|
"insert",
|
|
8180
|
-
|
|
8182
|
+
r,
|
|
8181
8183
|
{ selectionMode: "placeholder" }
|
|
8182
|
-
]) : e.insert(
|
|
8184
|
+
]) : e.insert(r);
|
|
8183
8185
|
}
|
|
8184
8186
|
this.scrollToCaret();
|
|
8185
8187
|
}
|
|
@@ -8190,12 +8192,12 @@ const D = class D {
|
|
|
8190
8192
|
isAllSelected(t) {
|
|
8191
8193
|
if (!t || t.selectionIsCollapsed) return !1;
|
|
8192
8194
|
try {
|
|
8193
|
-
const e = t.model,
|
|
8194
|
-
if (
|
|
8195
|
-
const
|
|
8196
|
-
if (
|
|
8195
|
+
const e = t.model, r = (e == null ? void 0 : e.selection) || t.selection;
|
|
8196
|
+
if (r) {
|
|
8197
|
+
const s = r.ranges || (Array.isArray(r) ? [r] : []);
|
|
8198
|
+
if (s.length > 0) {
|
|
8197
8199
|
let a = 1 / 0, l = -1 / 0;
|
|
8198
|
-
for (const h of
|
|
8200
|
+
for (const h of s)
|
|
8199
8201
|
Array.isArray(h) && (a = Math.min(a, h[0], h[1]), l = Math.max(l, h[0], h[1]));
|
|
8200
8202
|
const n = (e == null ? void 0 : e.lastOffset) || 1;
|
|
8201
8203
|
if (a <= 1 && l >= n)
|
|
@@ -8242,8 +8244,8 @@ const D = class D {
|
|
|
8242
8244
|
}
|
|
8243
8245
|
try {
|
|
8244
8246
|
if (typeof t.queryStyle == "function") {
|
|
8245
|
-
const e = t.queryStyle({ variantStyle: "bold" }),
|
|
8246
|
-
if (e === "all" || e === "some" ||
|
|
8247
|
+
const e = t.queryStyle({ variantStyle: "bold" }), r = t.queryStyle({ variantStyle: "bolditalic" }), s = t.queryStyle({ fontSeries: "b" });
|
|
8248
|
+
if (e === "all" || e === "some" || r === "all" || r === "some" || s === "all" || s === "some")
|
|
8247
8249
|
return !0;
|
|
8248
8250
|
}
|
|
8249
8251
|
} catch {
|
|
@@ -8251,8 +8253,8 @@ const D = class D {
|
|
|
8251
8253
|
try {
|
|
8252
8254
|
const e = t.model;
|
|
8253
8255
|
if (e && !t.selectionIsCollapsed && (e.selection || t.selection)) {
|
|
8254
|
-
const
|
|
8255
|
-
if (
|
|
8256
|
+
const r = e.selection || t.selection, s = e.getAtoms(r, { includeChildren: !0 });
|
|
8257
|
+
if (s && s.length > 0 && s.some((l) => {
|
|
8256
8258
|
if (!l || l.type === "first") return !1;
|
|
8257
8259
|
const n = l.style;
|
|
8258
8260
|
return n ? n.variantStyle === "bold" || n.variantStyle === "bolditalic" || n.fontSeries === "b" || n.variant === "bold" : !1;
|
|
@@ -8274,8 +8276,8 @@ const D = class D {
|
|
|
8274
8276
|
}
|
|
8275
8277
|
try {
|
|
8276
8278
|
if (typeof t.queryStyle == "function") {
|
|
8277
|
-
const e = t.queryStyle({ variantStyle: "italic" }),
|
|
8278
|
-
if (e === "all" || e === "some" ||
|
|
8279
|
+
const e = t.queryStyle({ variantStyle: "italic" }), r = t.queryStyle({ variantStyle: "bolditalic" }), s = t.queryStyle({ fontShape: "it" });
|
|
8280
|
+
if (e === "all" || e === "some" || r === "all" || r === "some" || s === "all" || s === "some")
|
|
8279
8281
|
return !0;
|
|
8280
8282
|
}
|
|
8281
8283
|
} catch {
|
|
@@ -8283,8 +8285,8 @@ const D = class D {
|
|
|
8283
8285
|
try {
|
|
8284
8286
|
const e = t.model;
|
|
8285
8287
|
if (e && !t.selectionIsCollapsed && (e.selection || t.selection)) {
|
|
8286
|
-
const
|
|
8287
|
-
if (
|
|
8288
|
+
const r = e.selection || t.selection, s = e.getAtoms(r, { includeChildren: !0 });
|
|
8289
|
+
if (s && s.length > 0 && s.some((l) => {
|
|
8288
8290
|
if (!l || l.type === "first") return !1;
|
|
8289
8291
|
const n = l.style;
|
|
8290
8292
|
return n ? n.variantStyle === "italic" || n.variantStyle === "bolditalic" || n.fontShape === "it" : !1;
|
|
@@ -8304,9 +8306,9 @@ const D = class D {
|
|
|
8304
8306
|
this.activeStyles.bold && (this.activeStyles.bold = !1, e = !0), this.activeStyles.italic && (this.activeStyles.italic = !1, e = !0), e && this.renderToolbarItems();
|
|
8305
8307
|
} else {
|
|
8306
8308
|
this.explicitToggle = !1;
|
|
8307
|
-
const e = this.checkSelectionBold(t),
|
|
8308
|
-
let
|
|
8309
|
-
this.activeStyles.bold !== e && (this.activeStyles.bold = e,
|
|
8309
|
+
const e = this.checkSelectionBold(t), r = this.checkSelectionItalic(t);
|
|
8310
|
+
let s = !1;
|
|
8311
|
+
this.activeStyles.bold !== e && (this.activeStyles.bold = e, s = !0), this.activeStyles.italic !== r && (this.activeStyles.italic = r, s = !0), s && this.renderToolbarItems();
|
|
8310
8312
|
}
|
|
8311
8313
|
}
|
|
8312
8314
|
render() {
|
|
@@ -8319,20 +8321,20 @@ const D = class D {
|
|
|
8319
8321
|
t.className = "cme-popup-topbar";
|
|
8320
8322
|
const e = document.createElement("div");
|
|
8321
8323
|
e.className = "cme-popup-header", e.style.cursor = "grab";
|
|
8322
|
-
const
|
|
8323
|
-
e.innerHTML = `<span>${
|
|
8324
|
-
const
|
|
8324
|
+
const r = this.title || (this.isEditing ? this.mode === "chem" ? "Edit Chemistry Formula" : "Edit Math Formula" : this.mode === "chem" ? "Chemistry Editor" : "Math Editor");
|
|
8325
|
+
e.innerHTML = `<span>${r}</span>`;
|
|
8326
|
+
const s = (i, b, g) => {
|
|
8325
8327
|
g && g.closest && g.closest(".cme-popup-btn") || (this.closeAllPopups(), this.specCharModal && this.specCharModal.close(), this.isDragging = !0, this.dragStart = {
|
|
8326
8328
|
x: i - this.position.x,
|
|
8327
8329
|
y: b - this.position.y
|
|
8328
8330
|
}, e.style.cursor = "grabbing");
|
|
8329
8331
|
};
|
|
8330
8332
|
e.addEventListener("mousedown", (i) => {
|
|
8331
|
-
|
|
8333
|
+
s(i.clientX, i.clientY, i.target);
|
|
8332
8334
|
}), e.addEventListener(
|
|
8333
8335
|
"touchstart",
|
|
8334
8336
|
(i) => {
|
|
8335
|
-
i.touches && i.touches.length > 0 &&
|
|
8337
|
+
i.touches && i.touches.length > 0 && s(i.touches[0].clientX, i.touches[0].clientY, i.target);
|
|
8336
8338
|
},
|
|
8337
8339
|
{ passive: !0 }
|
|
8338
8340
|
);
|
|
@@ -8418,14 +8420,14 @@ const D = class D {
|
|
|
8418
8420
|
} catch {
|
|
8419
8421
|
}
|
|
8420
8422
|
let i = this.initialLatex || "";
|
|
8421
|
-
this.mode === "chem" && i.startsWith("\\ce{") && i.endsWith("}") && (i = i.slice(4, -1)), this.setValue(i), this.mathField.focus(), this.scrollToCaret();
|
|
8423
|
+
this.mode === "chem" && i.startsWith("\\ce{") && i.endsWith("}") && (i = i.slice(4, -1)), this.mode === "chem" && (i = i.replace(/~/g, "\\enspace ")), this.setValue(i), this.mathField.focus(), this.scrollToCaret();
|
|
8422
8424
|
}
|
|
8423
8425
|
}, 50);
|
|
8424
8426
|
}
|
|
8425
8427
|
clampPosition(t = this.position.x, e = this.position.y) {
|
|
8426
8428
|
if (!this.popup) return { x: t, y: e };
|
|
8427
|
-
const
|
|
8428
|
-
let d = -
|
|
8429
|
+
const r = this.popup.getBoundingClientRect(), s = r.left - this.position.x, a = r.top - this.position.y, l = r.width, n = r.height, h = window.innerWidth, c = window.innerHeight;
|
|
8430
|
+
let d = -s, w = h - s - l, x = t;
|
|
8429
8431
|
d > w ? x = d : x = Math.max(d, Math.min(t, w));
|
|
8430
8432
|
let y = -a, k = c - a - n, u = e;
|
|
8431
8433
|
return y > k ? u = y : u = Math.max(y, Math.min(e, k)), { x, y: u };
|
|
@@ -8433,8 +8435,8 @@ const D = class D {
|
|
|
8433
8435
|
handleMouseMove(t) {
|
|
8434
8436
|
if (!this.isDragging || !this.popup) return;
|
|
8435
8437
|
this.closeAllPopups(), this.specCharModal && this.specCharModal.close();
|
|
8436
|
-
const e = t.clientX - this.dragStart.x,
|
|
8437
|
-
this.position = this.clampPosition(e,
|
|
8438
|
+
const e = t.clientX - this.dragStart.x, r = t.clientY - this.dragStart.y;
|
|
8439
|
+
this.position = this.clampPosition(e, r), this.popup.style.transform = `translate(${this.position.x}px, ${this.position.y}px)`;
|
|
8438
8440
|
}
|
|
8439
8441
|
handleTouchMove(t) {
|
|
8440
8442
|
!this.isDragging || !t.touches || t.touches.length === 0 || (t.cancelable && t.preventDefault(), this.handleMouseMove(t.touches[0]));
|
|
@@ -8463,22 +8465,22 @@ const D = class D {
|
|
|
8463
8465
|
}
|
|
8464
8466
|
renderTabs() {
|
|
8465
8467
|
if (!this.tabsWrapper) return;
|
|
8466
|
-
this.tabsWrapper.innerHTML = "", this.getGroups().forEach((e,
|
|
8467
|
-
const
|
|
8468
|
-
if (a.type = "button", a.className = "cme-group-tab" + (
|
|
8468
|
+
this.tabsWrapper.innerHTML = "", this.getGroups().forEach((e, r) => {
|
|
8469
|
+
const s = this.activeGroup === r, a = document.createElement("button");
|
|
8470
|
+
if (a.type = "button", a.className = "cme-group-tab" + (s ? " active" : ""), e.mathLabel) {
|
|
8469
8471
|
const l = document.createElement("math-field");
|
|
8470
|
-
l.setAttribute("read-only", "true"), l.setAttribute("tabindex", "-1"), l.style.pointerEvents = "none", l.style.background = "transparent", l.style.border = "none", l.style.outline = "none", l.style.fontSize = e.fontSize || (e.isMatrix ? "8px" : "11px"), l.style.display = "inline-block", l.style.width = "auto", l.style.padding = "0", l.style.margin = "0", l.style.boxShadow = "none", l.style.color =
|
|
8472
|
+
l.setAttribute("read-only", "true"), l.setAttribute("tabindex", "-1"), l.style.pointerEvents = "none", l.style.background = "transparent", l.style.border = "none", l.style.outline = "none", l.style.fontSize = e.fontSize || (e.isMatrix ? "8px" : "11px"), l.style.display = "inline-block", l.style.width = "auto", l.style.padding = "0", l.style.margin = "0", l.style.boxShadow = "none", l.style.color = s ? "#333333" : "#ffffff", l.textContent = e.mathLabel, a.appendChild(l);
|
|
8471
8473
|
} else typeof e.label == "string" && e.label.includes("<svg") ? a.innerHTML = e.label : a.textContent = e.label;
|
|
8472
8474
|
a.addEventListener("mousedown", (l) => {
|
|
8473
|
-
l.preventDefault(), this.activeGroup =
|
|
8475
|
+
l.preventDefault(), this.activeGroup = r, this.closeAllPopups(), this.renderTabs(), this.renderToolbarItems();
|
|
8474
8476
|
}), this.tabsWrapper.appendChild(a);
|
|
8475
8477
|
});
|
|
8476
8478
|
}
|
|
8477
8479
|
renderToolbarItems() {
|
|
8478
8480
|
if (!this.itemsWrapper) return;
|
|
8479
8481
|
this.itemsWrapper.innerHTML = "";
|
|
8480
|
-
const e = this.getGroups()[this.activeGroup] || { items: [] },
|
|
8481
|
-
if (
|
|
8482
|
+
const e = this.getGroups()[this.activeGroup] || { items: [] }, r = e.items || [], s = r.some((l) => l.type === "sep"), a = [];
|
|
8483
|
+
if (s) {
|
|
8482
8484
|
let l = {
|
|
8483
8485
|
cols: 2,
|
|
8484
8486
|
small: !1,
|
|
@@ -8487,7 +8489,7 @@ const D = class D {
|
|
|
8487
8489
|
moreItems: null,
|
|
8488
8490
|
moreCols: 1
|
|
8489
8491
|
};
|
|
8490
|
-
for (const n of
|
|
8492
|
+
for (const n of r)
|
|
8491
8493
|
n.type === "sep" ? (l.items.length > 0 && a.push(l), l = {
|
|
8492
8494
|
cols: n.cols || 2,
|
|
8493
8495
|
small: !!n.small,
|
|
@@ -8498,12 +8500,12 @@ const D = class D {
|
|
|
8498
8500
|
}) : l.items.push(n);
|
|
8499
8501
|
l.items.length > 0 && a.push(l);
|
|
8500
8502
|
} else
|
|
8501
|
-
for (let n = 0; n <
|
|
8503
|
+
for (let n = 0; n < r.length; n += 4)
|
|
8502
8504
|
a.push({
|
|
8503
8505
|
cols: 2,
|
|
8504
8506
|
small: !1,
|
|
8505
8507
|
cls: "",
|
|
8506
|
-
items:
|
|
8508
|
+
items: r.slice(n, n + 4)
|
|
8507
8509
|
});
|
|
8508
8510
|
a.forEach((l) => {
|
|
8509
8511
|
const n = document.createElement("div");
|
|
@@ -8659,8 +8661,8 @@ const D = class D {
|
|
|
8659
8661
|
}), this.itemsWrapper.appendChild(n);
|
|
8660
8662
|
});
|
|
8661
8663
|
}
|
|
8662
|
-
openDropdown(t, e,
|
|
8663
|
-
this.closeAllPopups(), this.activeDropdownBtn =
|
|
8664
|
+
openDropdown(t, e, r, s = null) {
|
|
8665
|
+
this.closeAllPopups(), this.activeDropdownBtn = s, this.activeDropdown = document.createElement("div"), this.activeDropdown.className = "cme-more-popup", this.activeDropdown.style.gridTemplateColumns = `repeat(${r}, auto)`, this.activeDropdown.style.left = `${e.left + e.width / 2}px`, this.activeDropdown.style.top = `${e.bottom + 4}px`, this.activeDropdown.style.transform = "translateX(-50%)", this.activeDropdown.addEventListener(
|
|
8664
8666
|
"mousedown",
|
|
8665
8667
|
(a) => a.stopPropagation()
|
|
8666
8668
|
), this.activeDropdown.addEventListener(
|
|
@@ -8676,16 +8678,16 @@ const D = class D {
|
|
|
8676
8678
|
closeDropdown() {
|
|
8677
8679
|
this.activeDropdown && this.activeDropdown.parentNode && this.activeDropdown.parentNode.removeChild(this.activeDropdown), this.activeDropdown = null, this.activeDropdownBtn = null;
|
|
8678
8680
|
}
|
|
8679
|
-
openMatrixGrid(t, e,
|
|
8680
|
-
this.closeAllPopups(), this.activeMatrixBtn =
|
|
8681
|
+
openMatrixGrid(t, e, r = null) {
|
|
8682
|
+
this.closeAllPopups(), this.activeMatrixBtn = r, this.activeMatrixPopup = document.createElement("div"), this.activeMatrixPopup.className = "cme-matrix-hover-popover ck-only", this.activeMatrixPopup.style.left = `${e.left + e.width / 2}px`, this.activeMatrixPopup.style.top = `${e.bottom + 6}px`, this.activeMatrixPopup.style.minHeight = "auto", this.activeMatrixPopup.addEventListener(
|
|
8681
8683
|
"mousedown",
|
|
8682
8684
|
(m) => m.stopPropagation()
|
|
8683
8685
|
), this.activeMatrixPopup.addEventListener(
|
|
8684
8686
|
"pointerdown",
|
|
8685
8687
|
(m) => m.stopPropagation()
|
|
8686
8688
|
);
|
|
8687
|
-
const
|
|
8688
|
-
|
|
8689
|
+
const s = document.createElement("div");
|
|
8690
|
+
s.className = "cme-matrix-hover-title", s.textContent = t === "matrix" ? "MATRIX" : `${t.toUpperCase()} MATRIX`;
|
|
8689
8691
|
const a = document.createElement("div");
|
|
8690
8692
|
a.className = "cme-matrix-hover-grid", a.style.flex = "none";
|
|
8691
8693
|
let l = 2, n = 2;
|
|
@@ -8748,17 +8750,17 @@ const D = class D {
|
|
|
8748
8750
|
m.preventDefault(), m.stopPropagation(), M(l, n - 1);
|
|
8749
8751
|
}), p.addEventListener("click", (m) => {
|
|
8750
8752
|
m.stopPropagation(), this.insertMatrix(t, l, n), this.closeMatrixPopup();
|
|
8751
|
-
}), this.activeMatrixPopup.appendChild(
|
|
8753
|
+
}), this.activeMatrixPopup.appendChild(s), this.activeMatrixPopup.appendChild(a), this.activeMatrixPopup.appendChild(h), document.body.appendChild(this.activeMatrixPopup);
|
|
8752
8754
|
}
|
|
8753
|
-
insertMatrix(t, e,
|
|
8754
|
-
let
|
|
8755
|
+
insertMatrix(t, e, r) {
|
|
8756
|
+
let s = [];
|
|
8755
8757
|
for (let n = 0; n < e; n++) {
|
|
8756
8758
|
let h = [];
|
|
8757
|
-
for (let c = 0; c <
|
|
8759
|
+
for (let c = 0; c < r; c++)
|
|
8758
8760
|
h.push("{#?}");
|
|
8759
|
-
|
|
8761
|
+
s.push(h.join(" & "));
|
|
8760
8762
|
}
|
|
8761
|
-
const a = t || "matrix", l = `\\begin{${a}}${
|
|
8763
|
+
const a = t || "matrix", l = `\\begin{${a}}${s.join(" \\\\ ")}\\end{${a}}`;
|
|
8762
8764
|
this.insertAtCursor(l);
|
|
8763
8765
|
}
|
|
8764
8766
|
closeMatrixPopup() {
|
|
@@ -8767,10 +8769,10 @@ const D = class D {
|
|
|
8767
8769
|
openColorPicker(t, e = null) {
|
|
8768
8770
|
this.closeAllPopups(), this.activeColorBtn = e, this.colorPickerPopup = document.createElement("div"), this.colorPickerPopup.className = "cme-more-popup", this.colorPickerPopup.style.gridTemplateColumns = "repeat(4, auto)", this.colorPickerPopup.style.left = `${t.left + t.width / 2}px`, this.colorPickerPopup.style.top = `${t.bottom + 4}px`, this.colorPickerPopup.style.transform = "translateX(-50%)", this.colorPickerPopup.addEventListener(
|
|
8769
8771
|
"mousedown",
|
|
8770
|
-
(
|
|
8772
|
+
(s) => s.stopPropagation()
|
|
8771
8773
|
), this.colorPickerPopup.addEventListener(
|
|
8772
8774
|
"pointerdown",
|
|
8773
|
-
(
|
|
8775
|
+
(s) => s.stopPropagation()
|
|
8774
8776
|
), [
|
|
8775
8777
|
"black",
|
|
8776
8778
|
"#e53935",
|
|
@@ -8780,11 +8782,11 @@ const D = class D {
|
|
|
8780
8782
|
"#8e24aa",
|
|
8781
8783
|
"#3949ab",
|
|
8782
8784
|
"#00acc1"
|
|
8783
|
-
].forEach((
|
|
8785
|
+
].forEach((s) => {
|
|
8784
8786
|
const a = document.createElement("div");
|
|
8785
|
-
a.style.width = "18px", a.style.height = "18px", a.style.borderRadius = "50%", a.style.margin = "4px", a.style.cursor = "pointer", a.style.backgroundColor =
|
|
8787
|
+
a.style.width = "18px", a.style.height = "18px", a.style.borderRadius = "50%", a.style.margin = "4px", a.style.cursor = "pointer", a.style.backgroundColor = s, a.style.border = this.activeStyles.color === s ? "2px solid #222" : "1px solid #ddd", a.addEventListener("mousedown", (l) => {
|
|
8786
8788
|
var n;
|
|
8787
|
-
l.preventDefault(), this.activeStyles.color =
|
|
8789
|
+
l.preventDefault(), this.activeStyles.color = s, (n = this.mathField) != null && n.applyStyle && this.mathField.applyStyle({ color: s === "black" ? "none" : s }), this.closeColorPicker(), this.renderToolbarItems();
|
|
8788
8790
|
}), this.colorPickerPopup.appendChild(a);
|
|
8789
8791
|
}), document.body.appendChild(this.colorPickerPopup);
|
|
8790
8792
|
}
|
|
@@ -8849,19 +8851,19 @@ if (typeof customElements < "u" && !customElements.get("digi-math-widget")) {
|
|
|
8849
8851
|
return ["latex", "editable", "mode"];
|
|
8850
8852
|
}
|
|
8851
8853
|
connectedCallback() {
|
|
8852
|
-
const e = this.getAttribute("latex") || "",
|
|
8854
|
+
const e = this.getAttribute("latex") || "", r = this.getAttribute("editable") !== "false", s = this.getAttribute("mode") || "math";
|
|
8853
8855
|
this.widget = new K({
|
|
8854
8856
|
container: this,
|
|
8855
8857
|
latex: e,
|
|
8856
|
-
editable:
|
|
8857
|
-
mode:
|
|
8858
|
+
editable: r,
|
|
8859
|
+
mode: s,
|
|
8858
8860
|
onUpdate: (a) => {
|
|
8859
8861
|
this.setAttribute("latex", a), this.dispatchEvent(new CustomEvent("latexChange", { detail: { latex: a }, bubbles: !0 }));
|
|
8860
8862
|
}
|
|
8861
8863
|
});
|
|
8862
8864
|
}
|
|
8863
|
-
attributeChangedCallback(e,
|
|
8864
|
-
|
|
8865
|
+
attributeChangedCallback(e, r, s) {
|
|
8866
|
+
r !== s && e === "latex" && this.widget && this.widget.setLatex(s);
|
|
8865
8867
|
}
|
|
8866
8868
|
disconnectedCallback() {
|
|
8867
8869
|
this.widget && this.widget.destroy();
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
<rect x="9" y="7" width="6" height="10" rx="1" stroke="#2E7D32" stroke-width="2" fill="none" />
|
|
87
87
|
<line x1="9" y1="21" x2="15" y2="3" stroke="#666" stroke-width="2" stroke-linecap="round" />
|
|
88
88
|
<line x1="9" y1="3" x2="15" y2="21" stroke="#666" stroke-width="2" stroke-linecap="round" />
|
|
89
|
-
</svg>`,insert:"\\class{cme-cross-strike}{#?}",forceLabel:!0,title:"Cross strike"}]},{label:"∑ ⋃ ",fontSize:"8px",mathLabel:"\\sum \\, \\bigcup",isTemplate:!0,items:[{type:"sep",cols:2,small:!0,cls:"cme-matrix-subgroup"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" stroke="currentColor" stroke-width="3" style="display: inline-block; vertical-align: middle; color: #2E7D32; overflow: visible"><path d="M44 16 L22 16 L34 32 L22 48 L44 48" stroke="#222" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" fill="none" /><rect x="27" y="-3" width="10" height="12" rx="1" opacity="0.45" /><rect x="27" y="56" width="10" height="12" rx="1" opacity="0.45" /></svg>',insert:"\\sum_{#?}^{#?}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Summation with limits"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" stroke="currentColor" stroke-width="3" style="display: inline-block; vertical-align: middle; color: #2E7D32; overflow: visible"><path d="M38 16 L16 16 L28 32 L16 48 L38 48" stroke="#222" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" fill="none" /><rect x="42" y="2" width="10" height="16" rx="1" opacity="0.45" /><rect x="42" y="39" width="10" height="16" rx="1" opacity="0.45" /></svg>',insert:"\\sum\\nolimits_{#?}^{#?}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Summation with side limits"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" stroke="currentColor" stroke-width="3" style="display: inline-block; vertical-align: middle; color: #2E7D32; overflow: visible"><path d="M44 16 L22 16 L34 32 L22 48 L44 48" stroke="#222" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" fill="none" /><rect x="27" y="54" width="10" height="12" rx="1" opacity="0.45" /></svg>',insert:"\\sum_{#?}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Summation with subscript"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" stroke="currentColor" stroke-width="3" style="display: inline-block; vertical-align: middle; color: #2E7D32; overflow: visible"><path d="M38 16 L16 16 L28 32 L16 48 L38 48" stroke="#222" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" fill="none" /><rect x="42" y="39" width="10" height="16" rx="1" opacity="0.45" /></svg>',insert:"\\sum\\nolimits_{#?}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Summation with side subscript"},{type:"sep",cols:2,small:!0,cls:"cme-matrix-subgroup"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" stroke="currentColor" stroke-width="3" style="display: inline-block; vertical-align: middle; color: #2E7D32; overflow: visible"><path d="M18 16 H46 M22 16 V48 M42 16 V48" stroke="#222" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" fill="none" /><rect x="27" y="-2" width="10" height="12" rx="1" opacity="0.45" /><rect x="27" y="50" width="10" height="12" rx="1" opacity="0.45" /></svg>',insert:"\\prod_{#?}^{#?}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Product with limits"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" stroke="currentColor" stroke-width="3" style="display: inline-block; vertical-align: middle; color: #2E7D32; overflow: visible"><path d="M12 16 H40 M16 16 V48 M36 16 V48" stroke="#222" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" fill="none" /><rect x="44" y="4" width="10" height="16" rx="1" opacity="0.45" /><rect x="44" y="44" width="10" height="16" rx="1" opacity="0.45" /></svg>',insert:"\\prod\\nolimits_{#?}^{#?}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Product with side limits"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" stroke="currentColor" stroke-width="3" style="display: inline-block; vertical-align: middle; color: #2E7D32; overflow: visible"><path d="M18 16 H46 M22 16 V48 M42 16 V48" stroke="#222" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" fill="none" /><rect x="27" y="50" width="10" height="12" rx="1" opacity="0.45" /></svg>',insert:"\\prod_{#?}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Product with subscript"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" stroke="currentColor" stroke-width="3" style="display: inline-block; vertical-align: middle; color: #2E7D32; overflow: visible"><path d="M12 16 H40 M16 16 V48 M36 16 V48" stroke="#222" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" fill="none" /><rect x="44" y="39" width="10" height="16" rx="1" opacity="0.45" /></svg>',insert:"\\prod\\nolimits_{#?}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Product with side subscript"},{type:"sep",cols:2,small:!0,cls:"cme-matrix-subgroup"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" stroke="currentColor" stroke-width="3" style="display: inline-block; vertical-align: middle; color: #2E7D32"><rect x="24" y="4" width="8" height="12" rx="1" opacity="0.45" /><rect x="22" y="22" width="12" height="20" rx="1" /><rect x="24" y="48" width="8" height="12" rx="1" opacity="0.45" /></svg>',insert:"\\overset{#?}{\\underset{\\raisebox{-4px}{#?}}{#?}}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Over and underscript"},{label:'<svg viewBox="0 0 24 24" width="20" height="20"><rect x="1" y="1" width="14" height="22" fill="none" stroke="currentColor" stroke-width="2" /><rect x="17" y="1" width="6" height="6" fill="none" stroke="#2E7D32" stroke-width="1.5" /><rect x="17" y="17" width="6" height="6" fill="none" stroke="#2E7D32" stroke-width="1.5" /></svg>',forceLabel:!0,insert:"{\\style{font-size:1.8em; transform: scale(0.9, 1.2); display: inline-block; padding: 0.2em 0;}{#?}}_{#?}^{\\raisebox{0.6em}{#?}}",isWidget:!0,title:"Subscript and superscript"},{label:'<svg width="26" height="26" viewBox="0 4 64 64" fill="none" stroke="currentColor" stroke-width="3" style="display: inline-block; vertical-align: middle; color: #2E7D32"><rect x="19" y="28" width="12" height="18" rx="1" /><rect x="21" y="52" width="8" height="12" rx="1" opacity="0.45" /></svg>',insert:"\\underset{\\raisebox{-4px}{#?}}{#?}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Underscript"},{label:'<svg viewBox="0 0 24 24" width="20" height="20"><rect x="1" y="1" width="14" height="22" fill="none" stroke="currentColor" stroke-width="2" /><rect x="17" y="17" width="6" height="6" fill="none" stroke="#2E7D32" stroke-width="1.5" /></svg>',forceLabel:!0,insert:"{\\style{font-size:1.8em; transform: scale(0.9, 1.2); display: inline-block; padding: 0.2em 0;}{#?}}_{#?}",isWidget:!0,title:"Subscript"},{type:"sep",cols:1,small:!0,cls:"cme-matrix-subgroup",moreCols:3,moreItems:[{label:"⨅",insert:"⨅",title:"Big square cap"},{label:"∏",insert:"∏",title:"Product"},{label:"∑",insert:"∑",title:"Summation"},{label:"⨆",insert:"⨆",title:"Big square cup"},{label:"∐",insert:"∐",title:"Coproduct"}]},{label:"⋃",insert:"\\bigcup",title:"Big union"},{label:"⋂",insert:"\\bigcap",title:"Big intersection"}]},{label:"∫ lim",fontSize:"7px",mathLabel:"\\int_{#?}^{#?} \\, \\lim",isTemplate:!0,items:[{type:"sep",cols:2,small:!0,cls:"cme-matrix-subgroup"},{label:'<svg width="24" height="26" viewBox="0 0 44 64" fill="none" style="display: inline-block; vertical-align: middle; overflow: visible"><text x="4" y="54" font-family="serif" font-size="58" fontStyle="italic" fill="#222" stroke="none" transform="rotate(10, 14, 32)">∫</text><rect x="24" y="10" width="8" height="10" rx="1" stroke="#2E7D32" stroke-width="1.5" fill="none" /><rect x="16" y="46" width="8" height="10" rx="1" stroke="#2E7D32" stroke-width="1.5" fill="none" /></svg>',insert:"\\int_{#?}^{#?}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Int"},{label:'<svg width="40" height="26" viewBox="0 0 96 64" fill="none" style="display: inline-block; vertical-align: middle; overflow: visible"><text x="4" y="54" font-family="serif" font-size="58" fontStyle="italic" fill="#222" stroke="none" transform="rotate(10, 14, 32)">∫</text><rect x="24" y="10" width="8" height="10" rx="1" stroke="#2E7D32" stroke-width="1.5" fill="none" /><rect x="16" y="46" width="8" height="10" rx="1" stroke="#2E7D32" stroke-width="1.5" fill="none" /><rect x="42" y="24" width="14" height="16" rx="2" stroke="#2E7D32" stroke-width="2" fill="none" /><text x="62" y="38" font-family="serif" fontStyle="italic" font-weight="bold" font-size="24" fill="#222" stroke="none">d</text><rect x="76" y="24" width="14" height="16" rx="2" stroke="#2E7D32" stroke-width="2" fill="none" /></svg>',insert:"\\int_{#?}^{#?} #0 \\, d#?",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Definite integral"},{label:'<svg width="24" height="26" viewBox="0 0 44 64" fill="none" style="display: inline-block; vertical-align: middle; overflow: visible"><text x="4" y="54" font-family="serif" font-size="58" fontStyle="italic" fill="#222" stroke="none" transform="rotate(10, 14, 32)">∫</text><rect x="16" y="46" width="8" height="10" rx="1" stroke="#2E7D32" stroke-width="1.5" fill="none" /></svg>',insert:"\\int_{#?}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Integral with subscript"},{label:'<svg width="40" height="26" viewBox="0 0 96 64" fill="none" style="display: inline-block; vertical-align: middle; overflow: visible"><text x="4" y="54" font-family="serif" font-size="58" fontStyle="italic" fill="#222" stroke="none" transform="rotate(10, 14, 32)">∫</text><rect x="16" y="46" width="8" height="10" rx="1" stroke="#2E7D32" stroke-width="1.5" fill="none" /><rect x="42" y="24" width="14" height="16" rx="2" stroke="#2E7D32" stroke-width="2" fill="none" /><text x="62" y="38" font-family="serif" fontStyle="italic" font-weight="bold" font-size="24" fill="#222" stroke="none">d</text><rect x="76" y="24" width="14" height="16" rx="2" stroke="#2E7D32" stroke-width="2" fill="none" /></svg>',insert:"\\int_{#?} #?\\,d#?",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Integral with subscript and differential"},{type:"sep",cols:2,small:!0,cls:"cme-matrix-subgroup"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" style="display: inline-block; vertical-align: middle; overflow: visible"><text x="32" y="42" font-family="serif" fontStyle="italic" font-weight="bold" font-size="36" fill="#222" text-anchor="middle">d</text></svg>',insert:"\\mathrm{d}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Mathrm d"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" style="display: inline-block; vertical-align: middle; overflow: visible"><line x1="8" y1="32" x2="56" y2="32" stroke="#222" stroke-width="3" /><text x="22" y="24" font-family="serif" fontStyle="italic" font-weight="bold" font-size="24" fill="#222" text-anchor="middle">d</text><rect x="32" y="8" width="14" height="16" rx="2" stroke="#2E7D32" stroke-width="2" fill="none" /><text x="22" y="54" font-family="serif" fontStyle="italic" font-weight="bold" font-size="24" fill="#222" text-anchor="middle">d</text><rect x="32" y="38" width="14" height="16" rx="2" stroke="#2E7D32" stroke-width="2" fill="none" /></svg>',insert:"\\frac{d#?}{d#?}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Derivative"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" style="display: inline-block; vertical-align: middle; overflow: visible"><text x="32" y="44" font-family="serif" fontStyle="italic" font-weight="bold" font-size="36" fill="#222" text-anchor="middle">∂</text></svg>',insert:"∂",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Partial differential"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" style="display: inline-block; vertical-align: middle; overflow: visible"><line x1="8" y1="32" x2="56" y2="32" stroke="#222" stroke-width="3" /><text x="22" y="24" font-family="serif" fontStyle="italic" font-weight="bold" font-size="24" fill="#222" text-anchor="middle">∂</text><rect x="32" y="8" width="14" height="16" rx="2" stroke="#2E7D32" stroke-width="2" fill="none" /><text x="22" y="54" font-family="serif" fontStyle="italic" font-weight="bold" font-size="24" fill="#222" text-anchor="middle">∂</text><rect x="32" y="38" width="14" height="16" rx="2" stroke="#2E7D32" stroke-width="2" fill="none" /></svg>',insert:"\\class{cme-partial-derivative}{\\frac{∂{#?}}{∂{#?}}}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Partial derivative"},{type:"sep",cols:1,small:!0,cls:"cme-matrix-subgroup"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" stroke="currentColor" stroke-width="3" style="display: inline-block; vertical-align: middle; color: #2E7D32; overflow: visible"><text x="32" y="32" fill="#222" stroke="none" font-size="24" font-family="serif" text-anchor="middle">lim</text><rect x="14" y="40" width="10" height="14" rx="1" opacity="0.45" /><text x="28" y="52" fill="#222" stroke="none" font-size="16" font-family="sans-serif">→</text><text x="44" y="52" fill="#222" stroke="none" font-size="18" font-family="serif">∞</text></svg>',insert:"\\lim_{#?\\to\\infty}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Limit to infinity"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" stroke="currentColor" stroke-width="3" style="display: inline-block; vertical-align: middle; color: #2E7D32; overflow: visible"><text x="32" y="32" fill="#222" stroke="none" font-size="24" font-family="serif" text-anchor="middle">lim</text><rect x="24" y="40" width="16" height="16" rx="1" opacity="0.45" /></svg>',insert:"\\lim_{#?}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Limit"},{type:"sep",cols:2,small:!0,cls:"cme-matrix-subgroup"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" stroke="currentColor" stroke-width="3" style="display: inline-block; vertical-align: middle; color: #2E7D32; overflow: visible"><path d="M12 24 L28 24 L20 40 Z" stroke="#222" stroke-width="3" fill="none" stroke-linejoin="round" /><path d="M34 26 L46 38 M46 26 L34 38" stroke="#222" stroke-width="3" fill="none" stroke-linecap="round" /><rect x="50" y="22" width="12" height="20" rx="1" /></svg>',insert:"\\nabla\\times #?",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Curl"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" stroke="currentColor" stroke-width="3" style="display: inline-block; vertical-align: middle; color: #2E7D32; overflow: visible"><path d="M16 24 L36 24 L26 44 Z" stroke="#222" stroke-width="4" fill="none" stroke-linejoin="round" /><rect x="44" y="24" width="16" height="20" rx="1" /></svg>',insert:"\\nabla #?",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Gradient"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" stroke="currentColor" stroke-width="3" style="display: inline-block; vertical-align: middle; color: #2E7D32; overflow: visible"><path d="M12 24 L28 24 L20 40 Z" stroke="#222" stroke-width="3" fill="none" stroke-linejoin="round" /><circle cx="38" cy="32" r="3" fill="#222" stroke="none" /><rect x="46" y="22" width="12" height="20" rx="1" /></svg>',insert:"\\nabla\\cdot #?",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Divergence"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" stroke="currentColor" stroke-width="3" style="display: inline-block; vertical-align: middle; color: #2E7D32; overflow: visible"><path d="M26 16 L12 44 L40 44 Z" stroke="#222" stroke-width="4" fill="none" stroke-linejoin="round" /><rect x="46" y="24" width="16" height="20" rx="1" /></svg>',insert:"\\Delta #?",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Laplacian"},{type:"sep",cols:2,small:!0,cls:"cme-matrix-subgroup",moreItems:[{label:"∭",insert:"\\iiint",title:"Triple integral"},{label:"∰",insert:"\\mathop{{\\style{font-size:1em;}{\\iiint}}\\mkern-28mu\\class{wider-circle}{\\bigcirc}\\mkern18mu}",title:"Closed volume integral"}]},{label:'<svg width="14" height="26" viewBox="0 0 32 64" fill="none" style="display: inline-block; vertical-align: middle; overflow: visible"><text x="22" y="54" transform="skewX(-15)" font-family="serif" font-size="58" font-weight="normal" fill="#222" stroke="none" text-anchor="middle">∫</text></svg>',forceLabel:!0,insert:"\\int",title:"Integral"},{label:'<svg width="14" height="26" viewBox="0 0 32 64" fill="none" style="display: inline-block; vertical-align: middle; overflow: visible"><text x="16" y="54" font-family="serif" font-size="58" font-weight="normal" fill="#222" stroke="none" text-anchor="middle">∬</text></svg>',forceLabel:!0,insert:"\\iint",title:"Double integral"},{label:'<svg width="14" height="26" viewBox="0 0 32 64" fill="none" style="display: inline-block; vertical-align: middle; overflow: visible"><text x="16" y="54" font-family="serif" font-size="58" font-weight="normal" fill="#222" stroke="none" text-anchor="middle">∮</text></svg>',forceLabel:!0,insert:"\\oint",title:"Contour integral"},{label:'<svg width="14" height="26" viewBox="0 0 32 64" fill="none" style="display: inline-block; vertical-align: middle; overflow: visible"><text x="16" y="54" font-family="serif" font-size="58" font-weight="normal" fill="#222" stroke="none" text-anchor="middle">∯</text></svg>',forceLabel:!0,insert:"\\mathop{{\\style{font-size:1em;}{\\iint}}\\mkern-23mu\\class{wide-circle}{\\bigcirc}\\mkern14mu}",title:"Custom surface integral"},{type:"sep",cols:3,cls:"cme-trig-subgroup",moreCols:"3",moreItems:[{label:"csc",insert:"\\csc\\left(#?\\right)",title:"Cosecant"},{label:"sec",insert:"\\sec\\left(#?\\right)",title:"Secant"},{label:"cot",insert:"\\cot\\left(#?\\right)",title:"Cotangent"},{label:"sin⁻¹",insert:"\\sin^{-1}",title:"Inverse sine"},{label:"cos⁻¹",insert:"\\cos^{-1}",title:"Inverse cosine"},{label:"tan⁻¹",insert:"\\tan^{-1}",title:"Inverse tangent"}]},{label:"sin",insert:"\\sin",title:"Sine"},{label:"cos",insert:"\\cos",title:"Cosine"},{label:"tan",insert:"\\tan",title:"Tangent"},{label:"log",insert:"\\log",title:"Logarithm"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" style="display: inline-block; vertical-align: middle; overflow: visible"><text x="2" y="42" font-family="serif" font-size="28" fill="#222" stroke="none">log</text><rect x="42" y="36" width="8" height="10" rx="1" stroke="#2E7D32" stroke-width="1.5" fill="none" /></svg>',insert:"\\log_{#?}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Logarithm with base"},{label:"ln",insert:"\\ln",title:"Natural logarithm"}]}];function et(o){if(!o)return"";let t="",e=0;for(;e<o.length;){let s=o.indexOf("\\placeholder",e);if(s===-1){t+=o.slice(e);break}if(t+=o.slice(e,s),e=s+12,o[e]==="["){let r=1;for(e++;e<o.length&&r>0;)o[e]==="["?r++:o[e]==="]"&&r--,e++}if(o[e]==="{"){let r=1,a=e+1;for(e++;e<o.length&&r>0;)o[e]==="{"?r++:o[e]==="}"&&r--,e++;let l=o.slice(a,e-1);l.trim()===""?t+="\\quad ":t+=l}}return t}function it(o){if(!o)return"";let t="",e=0;const s="\\text{";for(;e<o.length;){const r=o.indexOf(s,e);if(r===-1){t+=o.slice(e);break}t+=o.slice(e,r);let a=1,l=r+s.length;for(;l<o.length&&a>0;)o[l]==="{"?a++:o[l]==="}"&&a--,l++;const n=o.slice(r+s.length,l-1);/^['"/]+$/.test(n)||n.includes("\\textquotedbl")||n.includes("\\textquotesingle")?t+="\\text{"+n+"}":t+=n,e=l}return t}function z(o,t){let e=0,s=t-1;for(;s>=0&&o[s]==="\\";)e++,s--;return e%2===1}function j(o){if(!o||typeof o!="string")return o||"";let t=o;const e=["\\mathbfit{","\\boldsymbol{","\\mathbf{","\\mathit{","\\mathrm{","\\textbf{","\\textit{","\\textmd{","\\textnormal{","\\text{","\\mbox{","\\bm{","\\bold{","\\pmb{","\\mathsf{","\\mathtt{"];let s=!0,r=0;for(;s&&r<10;){s=!1,r++;for(const a of e){let l=0;for(;l<t.length;){const n=t.indexOf(a,l);if(n===-1)break;let h=1,c=n+a.length;for(;c<t.length&&h>0;)t[c]==="{"&&!z(t,c)?h++:t[c]==="}"&&!z(t,c)&&h--,c++;if(h===0){const d=t.slice(n+a.length,c-1);t=t.slice(0,n)+d+t.slice(c),s=!0,l=n}else l=n+a.length}}}return t}function lt(o){return!o||typeof o!="string"?!1:[/[\^_]/,/\\frac\b/,/\\tfrac\b/,/\\nicefrac\b/,/\\sqrt\b/,/\\ce\b/,/\\int\b/,/\\iint\b/,/\\iiint\b/,/\\oint\b/,/\\sum\b/,/\\prod\b/,/\\lim\b/,/\\begin\b/,/\\enclose\b/,/\\placeholder\b/,/\\over\b/,/\\vec\b/,/\\hat\b/,/\\tilde\b/,/\\bar\b/,/\\dot\b/,/\\ddot\b/,/\\underbrace\b/,/\\overbrace\b/,/\\overset\b/,/\\underset\b/,/\\raisebox\b/,/\\lowerbox\b/,/\\left\b/,/\\right\b/,/\\class\b/,/\\style\b/,/\\(LARGE|Large|large|scriptsize|tiny|small|huge|Huge|footnotesize|normalsize)\b/,/\\alpha\b|\\beta\b|\\gamma\b|\\delta\b|\\epsilon\b|\\zeta\b|\\eta\b|\\theta\b|\\iota\b|\\kappa\b|\\lambda\b|\\mu\b|\\nu\b|\\xi\b|\\pi\b|\\rho\b|\\sigma\b|\\tau\b|\\upsilon\b|\\phi\b|\\chi\b|\\psi\b|\\omega\b/,/\\Gamma\b|\\Delta\b|\\Theta\b|\\Lambda\b|\\Xi\b|\\Pi\b|\\Sigma\b|\\Upsilon\b|\\Phi\b|\\Psi\b|\\Omega\b/,/\\pm\b|\\times\b|\\div\b|\\leq\b|\\geq\b|\\neq\b|\\approx\b|\\infty\b|\\partial\b|\\to\b|\\rightarrow\b/].some(e=>e.test(o))}function rt(o,t){return o?lt(o)?o:(t==null?void 0:t.fontFamily)==="sans-serif"?`\\mathsf{${o}}`:(t==null?void 0:t.fontFamily)==="monospace"?`\\mathtt{${o}}`:(t==null?void 0:t.fontFamily)==="roman"?`\\mathrm{${o}}`:o:""}function Q(o,t,e,s){if(!o)return"";if(!t&&!e)return rt(o,{fontFamily:s});const r=s==="sans-serif",a=s==="monospace",l=s==="roman";return t&&e?r?`\\boldsymbol{\\mathsf{${o}}}`:a?`\\boldsymbol{\\mathtt{${o}}}`:l?`\\mathbfit{\\mathrm{${o}}}`:`\\mathbfit{${o}}`:t?r?`\\boldsymbol{\\mathsf{${o}}}`:a?`\\boldsymbol{\\mathtt{${o}}}`:l?`\\mathbf{\\mathrm{${o}}}`:`\\mathbf{${o}}`:e?r?`\\mathsf{${o}}`:a?`\\mathtt{${o}}`:l?`\\mathit{\\mathrm{${o}}}`:`\\mathit{${o}}`:o}function D(o,t,e,s){if(!o)return"";let r=o.trim();const a=r.match(/^\\displaylines\s*\{([\s\S]*)\}$/i);if(a&&(r=a[1].trim()),r.match(/^\\begin\{(array|matrix|pmatrix|bmatrix|vmatrix|Vmatrix|align|aligned|gather|cases)\}([\s\S]*)\\end\{\1\}$/i))return r;const n=r.match(/^\\begin\{(array|gather)\}(\{[\s\S]*?\})?([\s\S]*?)\\end\{\1\}$/i);if(n&&(r=n[3].trim()),/\\\\|\\cr|\\newline|\\par|\n/.test(r)){const h=/\\\\(?:\[[^\]]*\])?|\\cr|\\newline|\\par|\n/;return`\\displaylines{${r.split(h).map(w=>{const y=w.trim();return y?Q(y,t,e,s):""}).filter(w=>w.length>0).join(" \\\\ ")}}`}return Q(r,t,e,s)}function st(o){return o?o.replace(/\\enclose\{([^}]*)\}\s*\[.*?\]/g,"\\enclose{$1}"):""}function ot(o=""){if(typeof o!="string")return o;let t=o.replace(/\\textasciitilde/g,"\\text{~}").replace(/\\textasciicircum/g,"\\text{^}").replace(/\\textasteriskcentered/g,"*").replace(/\\char96/g,"`");return t.includes("\\ce{")&&(t=t.replace(/\\ce\{([\s\S]*?)\}/g,(e,s)=>s.includes("\\{")||s.includes("\\}")||s.includes("\\lbrace")||s.includes("\\rbrace")?s:`\\ce{${s.replace(/\\left\[/g,"[").replace(/\\right\]/g,"]").replace(/\\lbrack\b/g,"[").replace(/\\rbrack\b/g,"]").replace(/\\left\(/g,"(").replace(/\\right\)/g,")").replace(/\\left\|/g,"|").replace(/\\right\|/g,"|").replace(/\\left\./g,"").replace(/\\right\./g,"").replace(/\\enspace(?:\s|{})?/g," ")}}`)),t}const X="data-mathfield-shadow-styles",K=`
|
|
89
|
+
</svg>`,insert:"\\class{cme-cross-strike}{#?}",forceLabel:!0,title:"Cross strike"}]},{label:"∑ ⋃ ",fontSize:"8px",mathLabel:"\\sum \\, \\bigcup",isTemplate:!0,items:[{type:"sep",cols:2,small:!0,cls:"cme-matrix-subgroup"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" stroke="currentColor" stroke-width="3" style="display: inline-block; vertical-align: middle; color: #2E7D32; overflow: visible"><path d="M44 16 L22 16 L34 32 L22 48 L44 48" stroke="#222" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" fill="none" /><rect x="27" y="-3" width="10" height="12" rx="1" opacity="0.45" /><rect x="27" y="56" width="10" height="12" rx="1" opacity="0.45" /></svg>',insert:"\\sum_{#?}^{#?}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Summation with limits"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" stroke="currentColor" stroke-width="3" style="display: inline-block; vertical-align: middle; color: #2E7D32; overflow: visible"><path d="M38 16 L16 16 L28 32 L16 48 L38 48" stroke="#222" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" fill="none" /><rect x="42" y="2" width="10" height="16" rx="1" opacity="0.45" /><rect x="42" y="39" width="10" height="16" rx="1" opacity="0.45" /></svg>',insert:"\\sum\\nolimits_{#?}^{#?}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Summation with side limits"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" stroke="currentColor" stroke-width="3" style="display: inline-block; vertical-align: middle; color: #2E7D32; overflow: visible"><path d="M44 16 L22 16 L34 32 L22 48 L44 48" stroke="#222" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" fill="none" /><rect x="27" y="54" width="10" height="12" rx="1" opacity="0.45" /></svg>',insert:"\\sum_{#?}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Summation with subscript"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" stroke="currentColor" stroke-width="3" style="display: inline-block; vertical-align: middle; color: #2E7D32; overflow: visible"><path d="M38 16 L16 16 L28 32 L16 48 L38 48" stroke="#222" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" fill="none" /><rect x="42" y="39" width="10" height="16" rx="1" opacity="0.45" /></svg>',insert:"\\sum\\nolimits_{#?}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Summation with side subscript"},{type:"sep",cols:2,small:!0,cls:"cme-matrix-subgroup"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" stroke="currentColor" stroke-width="3" style="display: inline-block; vertical-align: middle; color: #2E7D32; overflow: visible"><path d="M18 16 H46 M22 16 V48 M42 16 V48" stroke="#222" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" fill="none" /><rect x="27" y="-2" width="10" height="12" rx="1" opacity="0.45" /><rect x="27" y="50" width="10" height="12" rx="1" opacity="0.45" /></svg>',insert:"\\prod_{#?}^{#?}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Product with limits"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" stroke="currentColor" stroke-width="3" style="display: inline-block; vertical-align: middle; color: #2E7D32; overflow: visible"><path d="M12 16 H40 M16 16 V48 M36 16 V48" stroke="#222" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" fill="none" /><rect x="44" y="4" width="10" height="16" rx="1" opacity="0.45" /><rect x="44" y="44" width="10" height="16" rx="1" opacity="0.45" /></svg>',insert:"\\prod\\nolimits_{#?}^{#?}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Product with side limits"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" stroke="currentColor" stroke-width="3" style="display: inline-block; vertical-align: middle; color: #2E7D32; overflow: visible"><path d="M18 16 H46 M22 16 V48 M42 16 V48" stroke="#222" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" fill="none" /><rect x="27" y="50" width="10" height="12" rx="1" opacity="0.45" /></svg>',insert:"\\prod_{#?}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Product with subscript"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" stroke="currentColor" stroke-width="3" style="display: inline-block; vertical-align: middle; color: #2E7D32; overflow: visible"><path d="M12 16 H40 M16 16 V48 M36 16 V48" stroke="#222" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" fill="none" /><rect x="44" y="39" width="10" height="16" rx="1" opacity="0.45" /></svg>',insert:"\\prod\\nolimits_{#?}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Product with side subscript"},{type:"sep",cols:2,small:!0,cls:"cme-matrix-subgroup"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" stroke="currentColor" stroke-width="3" style="display: inline-block; vertical-align: middle; color: #2E7D32"><rect x="24" y="4" width="8" height="12" rx="1" opacity="0.45" /><rect x="22" y="22" width="12" height="20" rx="1" /><rect x="24" y="48" width="8" height="12" rx="1" opacity="0.45" /></svg>',insert:"\\overset{#?}{\\underset{\\raisebox{-4px}{#?}}{#?}}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Over and underscript"},{label:'<svg viewBox="0 0 24 24" width="20" height="20"><rect x="1" y="1" width="14" height="22" fill="none" stroke="currentColor" stroke-width="2" /><rect x="17" y="1" width="6" height="6" fill="none" stroke="#2E7D32" stroke-width="1.5" /><rect x="17" y="17" width="6" height="6" fill="none" stroke="#2E7D32" stroke-width="1.5" /></svg>',forceLabel:!0,insert:"{\\style{font-size:1.8em; transform: scale(0.9, 1.2); display: inline-block; padding: 0.2em 0;}{#?}}_{#?}^{\\raisebox{0.6em}{#?}}",isWidget:!0,title:"Subscript and superscript"},{label:'<svg width="26" height="26" viewBox="0 4 64 64" fill="none" stroke="currentColor" stroke-width="3" style="display: inline-block; vertical-align: middle; color: #2E7D32"><rect x="19" y="28" width="12" height="18" rx="1" /><rect x="21" y="52" width="8" height="12" rx="1" opacity="0.45" /></svg>',insert:"\\underset{\\raisebox{-4px}{#?}}{#?}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Underscript"},{label:'<svg viewBox="0 0 24 24" width="20" height="20"><rect x="1" y="1" width="14" height="22" fill="none" stroke="currentColor" stroke-width="2" /><rect x="17" y="17" width="6" height="6" fill="none" stroke="#2E7D32" stroke-width="1.5" /></svg>',forceLabel:!0,insert:"{\\style{font-size:1.8em; transform: scale(0.9, 1.2); display: inline-block; padding: 0.2em 0;}{#?}}_{#?}",isWidget:!0,title:"Subscript"},{type:"sep",cols:1,small:!0,cls:"cme-matrix-subgroup",moreCols:3,moreItems:[{label:"⨅",insert:"⨅",title:"Big square cap"},{label:"∏",insert:"∏",title:"Product"},{label:"∑",insert:"∑",title:"Summation"},{label:"⨆",insert:"⨆",title:"Big square cup"},{label:"∐",insert:"∐",title:"Coproduct"}]},{label:"⋃",insert:"\\bigcup",title:"Big union"},{label:"⋂",insert:"\\bigcap",title:"Big intersection"}]},{label:"∫ lim",fontSize:"7px",mathLabel:"\\int_{#?}^{#?} \\, \\lim",isTemplate:!0,items:[{type:"sep",cols:2,small:!0,cls:"cme-matrix-subgroup"},{label:'<svg width="24" height="26" viewBox="0 0 44 64" fill="none" style="display: inline-block; vertical-align: middle; overflow: visible"><text x="4" y="54" font-family="serif" font-size="58" fontStyle="italic" fill="#222" stroke="none" transform="rotate(10, 14, 32)">∫</text><rect x="24" y="10" width="8" height="10" rx="1" stroke="#2E7D32" stroke-width="1.5" fill="none" /><rect x="16" y="46" width="8" height="10" rx="1" stroke="#2E7D32" stroke-width="1.5" fill="none" /></svg>',insert:"\\int_{#?}^{#?}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Int"},{label:'<svg width="40" height="26" viewBox="0 0 96 64" fill="none" style="display: inline-block; vertical-align: middle; overflow: visible"><text x="4" y="54" font-family="serif" font-size="58" fontStyle="italic" fill="#222" stroke="none" transform="rotate(10, 14, 32)">∫</text><rect x="24" y="10" width="8" height="10" rx="1" stroke="#2E7D32" stroke-width="1.5" fill="none" /><rect x="16" y="46" width="8" height="10" rx="1" stroke="#2E7D32" stroke-width="1.5" fill="none" /><rect x="42" y="24" width="14" height="16" rx="2" stroke="#2E7D32" stroke-width="2" fill="none" /><text x="62" y="38" font-family="serif" fontStyle="italic" font-weight="bold" font-size="24" fill="#222" stroke="none">d</text><rect x="76" y="24" width="14" height="16" rx="2" stroke="#2E7D32" stroke-width="2" fill="none" /></svg>',insert:"\\int_{#?}^{#?} #0 \\, d#?",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Definite integral"},{label:'<svg width="24" height="26" viewBox="0 0 44 64" fill="none" style="display: inline-block; vertical-align: middle; overflow: visible"><text x="4" y="54" font-family="serif" font-size="58" fontStyle="italic" fill="#222" stroke="none" transform="rotate(10, 14, 32)">∫</text><rect x="16" y="46" width="8" height="10" rx="1" stroke="#2E7D32" stroke-width="1.5" fill="none" /></svg>',insert:"\\int_{#?}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Integral with subscript"},{label:'<svg width="40" height="26" viewBox="0 0 96 64" fill="none" style="display: inline-block; vertical-align: middle; overflow: visible"><text x="4" y="54" font-family="serif" font-size="58" fontStyle="italic" fill="#222" stroke="none" transform="rotate(10, 14, 32)">∫</text><rect x="16" y="46" width="8" height="10" rx="1" stroke="#2E7D32" stroke-width="1.5" fill="none" /><rect x="42" y="24" width="14" height="16" rx="2" stroke="#2E7D32" stroke-width="2" fill="none" /><text x="62" y="38" font-family="serif" fontStyle="italic" font-weight="bold" font-size="24" fill="#222" stroke="none">d</text><rect x="76" y="24" width="14" height="16" rx="2" stroke="#2E7D32" stroke-width="2" fill="none" /></svg>',insert:"\\int_{#?} #?\\,d#?",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Integral with subscript and differential"},{type:"sep",cols:2,small:!0,cls:"cme-matrix-subgroup"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" style="display: inline-block; vertical-align: middle; overflow: visible"><text x="32" y="42" font-family="serif" fontStyle="italic" font-weight="bold" font-size="36" fill="#222" text-anchor="middle">d</text></svg>',insert:"\\mathrm{d}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Mathrm d"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" style="display: inline-block; vertical-align: middle; overflow: visible"><line x1="8" y1="32" x2="56" y2="32" stroke="#222" stroke-width="3" /><text x="22" y="24" font-family="serif" fontStyle="italic" font-weight="bold" font-size="24" fill="#222" text-anchor="middle">d</text><rect x="32" y="8" width="14" height="16" rx="2" stroke="#2E7D32" stroke-width="2" fill="none" /><text x="22" y="54" font-family="serif" fontStyle="italic" font-weight="bold" font-size="24" fill="#222" text-anchor="middle">d</text><rect x="32" y="38" width="14" height="16" rx="2" stroke="#2E7D32" stroke-width="2" fill="none" /></svg>',insert:"\\frac{d#?}{d#?}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Derivative"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" style="display: inline-block; vertical-align: middle; overflow: visible"><text x="32" y="44" font-family="serif" fontStyle="italic" font-weight="bold" font-size="36" fill="#222" text-anchor="middle">∂</text></svg>',insert:"∂",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Partial differential"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" style="display: inline-block; vertical-align: middle; overflow: visible"><line x1="8" y1="32" x2="56" y2="32" stroke="#222" stroke-width="3" /><text x="22" y="24" font-family="serif" fontStyle="italic" font-weight="bold" font-size="24" fill="#222" text-anchor="middle">∂</text><rect x="32" y="8" width="14" height="16" rx="2" stroke="#2E7D32" stroke-width="2" fill="none" /><text x="22" y="54" font-family="serif" fontStyle="italic" font-weight="bold" font-size="24" fill="#222" text-anchor="middle">∂</text><rect x="32" y="38" width="14" height="16" rx="2" stroke="#2E7D32" stroke-width="2" fill="none" /></svg>',insert:"\\class{cme-partial-derivative}{\\frac{∂{#?}}{∂{#?}}}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Partial derivative"},{type:"sep",cols:1,small:!0,cls:"cme-matrix-subgroup"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" stroke="currentColor" stroke-width="3" style="display: inline-block; vertical-align: middle; color: #2E7D32; overflow: visible"><text x="32" y="32" fill="#222" stroke="none" font-size="24" font-family="serif" text-anchor="middle">lim</text><rect x="14" y="40" width="10" height="14" rx="1" opacity="0.45" /><text x="28" y="52" fill="#222" stroke="none" font-size="16" font-family="sans-serif">→</text><text x="44" y="52" fill="#222" stroke="none" font-size="18" font-family="serif">∞</text></svg>',insert:"\\lim_{#?\\to\\infty}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Limit to infinity"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" stroke="currentColor" stroke-width="3" style="display: inline-block; vertical-align: middle; color: #2E7D32; overflow: visible"><text x="32" y="32" fill="#222" stroke="none" font-size="24" font-family="serif" text-anchor="middle">lim</text><rect x="24" y="40" width="16" height="16" rx="1" opacity="0.45" /></svg>',insert:"\\lim_{#?}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Limit"},{type:"sep",cols:2,small:!0,cls:"cme-matrix-subgroup"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" stroke="currentColor" stroke-width="3" style="display: inline-block; vertical-align: middle; color: #2E7D32; overflow: visible"><path d="M12 24 L28 24 L20 40 Z" stroke="#222" stroke-width="3" fill="none" stroke-linejoin="round" /><path d="M34 26 L46 38 M46 26 L34 38" stroke="#222" stroke-width="3" fill="none" stroke-linecap="round" /><rect x="50" y="22" width="12" height="20" rx="1" /></svg>',insert:"\\nabla\\times #?",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Curl"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" stroke="currentColor" stroke-width="3" style="display: inline-block; vertical-align: middle; color: #2E7D32; overflow: visible"><path d="M16 24 L36 24 L26 44 Z" stroke="#222" stroke-width="4" fill="none" stroke-linejoin="round" /><rect x="44" y="24" width="16" height="20" rx="1" /></svg>',insert:"\\nabla #?",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Gradient"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" stroke="currentColor" stroke-width="3" style="display: inline-block; vertical-align: middle; color: #2E7D32; overflow: visible"><path d="M12 24 L28 24 L20 40 Z" stroke="#222" stroke-width="3" fill="none" stroke-linejoin="round" /><circle cx="38" cy="32" r="3" fill="#222" stroke="none" /><rect x="46" y="22" width="12" height="20" rx="1" /></svg>',insert:"\\nabla\\cdot #?",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Divergence"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" stroke="currentColor" stroke-width="3" style="display: inline-block; vertical-align: middle; color: #2E7D32; overflow: visible"><path d="M26 16 L12 44 L40 44 Z" stroke="#222" stroke-width="4" fill="none" stroke-linejoin="round" /><rect x="46" y="24" width="16" height="20" rx="1" /></svg>',insert:"\\Delta #?",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Laplacian"},{type:"sep",cols:2,small:!0,cls:"cme-matrix-subgroup",moreItems:[{label:"∭",insert:"\\iiint",title:"Triple integral"},{label:"∰",insert:"\\mathop{{\\style{font-size:1em;}{\\iiint}}\\mkern-28mu\\class{wider-circle}{\\bigcirc}\\mkern18mu}",title:"Closed volume integral"}]},{label:'<svg width="14" height="26" viewBox="0 0 32 64" fill="none" style="display: inline-block; vertical-align: middle; overflow: visible"><text x="22" y="54" transform="skewX(-15)" font-family="serif" font-size="58" font-weight="normal" fill="#222" stroke="none" text-anchor="middle">∫</text></svg>',forceLabel:!0,insert:"\\int",title:"Integral"},{label:'<svg width="14" height="26" viewBox="0 0 32 64" fill="none" style="display: inline-block; vertical-align: middle; overflow: visible"><text x="16" y="54" font-family="serif" font-size="58" font-weight="normal" fill="#222" stroke="none" text-anchor="middle">∬</text></svg>',forceLabel:!0,insert:"\\iint",title:"Double integral"},{label:'<svg width="14" height="26" viewBox="0 0 32 64" fill="none" style="display: inline-block; vertical-align: middle; overflow: visible"><text x="16" y="54" font-family="serif" font-size="58" font-weight="normal" fill="#222" stroke="none" text-anchor="middle">∮</text></svg>',forceLabel:!0,insert:"\\oint",title:"Contour integral"},{label:'<svg width="14" height="26" viewBox="0 0 32 64" fill="none" style="display: inline-block; vertical-align: middle; overflow: visible"><text x="16" y="54" font-family="serif" font-size="58" font-weight="normal" fill="#222" stroke="none" text-anchor="middle">∯</text></svg>',forceLabel:!0,insert:"\\mathop{{\\style{font-size:1em;}{\\iint}}\\mkern-23mu\\class{wide-circle}{\\bigcirc}\\mkern14mu}",title:"Custom surface integral"},{type:"sep",cols:3,cls:"cme-trig-subgroup",moreCols:"3",moreItems:[{label:"csc",insert:"\\csc\\left(#?\\right)",title:"Cosecant"},{label:"sec",insert:"\\sec\\left(#?\\right)",title:"Secant"},{label:"cot",insert:"\\cot\\left(#?\\right)",title:"Cotangent"},{label:"sin⁻¹",insert:"\\sin^{-1}",title:"Inverse sine"},{label:"cos⁻¹",insert:"\\cos^{-1}",title:"Inverse cosine"},{label:"tan⁻¹",insert:"\\tan^{-1}",title:"Inverse tangent"}]},{label:"sin",insert:"\\sin",title:"Sine"},{label:"cos",insert:"\\cos",title:"Cosine"},{label:"tan",insert:"\\tan",title:"Tangent"},{label:"log",insert:"\\log",title:"Logarithm"},{label:'<svg width="26" height="26" viewBox="0 0 64 64" fill="none" style="display: inline-block; vertical-align: middle; overflow: visible"><text x="2" y="42" font-family="serif" font-size="28" fill="#222" stroke="none">log</text><rect x="42" y="36" width="8" height="10" rx="1" stroke="#2E7D32" stroke-width="1.5" fill="none" /></svg>',insert:"\\log_{#?}",cls:"template",directInsert:!0,action:"INSERT_CUSTOM",title:"Logarithm with base"},{label:"ln",insert:"\\ln",title:"Natural logarithm"}]}];function et(o){if(!o)return"";let t="",e=0;for(;e<o.length;){let r=o.indexOf("\\placeholder",e);if(r===-1){t+=o.slice(e);break}if(t+=o.slice(e,r),e=r+12,o[e]==="["){let s=1;for(e++;e<o.length&&s>0;)o[e]==="["?s++:o[e]==="]"&&s--,e++}if(o[e]==="{"){let s=1,a=e+1;for(e++;e<o.length&&s>0;)o[e]==="{"?s++:o[e]==="}"&&s--,e++;let l=o.slice(a,e-1);l.trim()===""?t+="\\quad ":t+=l}}return t}function it(o){if(!o)return"";let t="",e=0;const r="\\text{";for(;e<o.length;){const s=o.indexOf(r,e);if(s===-1){t+=o.slice(e);break}t+=o.slice(e,s);let a=1,l=s+r.length;for(;l<o.length&&a>0;)o[l]==="{"?a++:o[l]==="}"&&a--,l++;const n=o.slice(s+r.length,l-1);/^['"/]+$/.test(n)||n.includes("\\textquotedbl")||n.includes("\\textquotesingle")?t+="\\text{"+n+"}":t+=n,e=l}return t}function z(o,t){let e=0,r=t-1;for(;r>=0&&o[r]==="\\";)e++,r--;return e%2===1}function j(o){if(!o||typeof o!="string")return o||"";let t=o;const e=["\\mathbfit{","\\boldsymbol{","\\mathbf{","\\mathit{","\\mathrm{","\\textbf{","\\textit{","\\textmd{","\\textnormal{","\\text{","\\mbox{","\\bm{","\\bold{","\\pmb{","\\mathsf{","\\mathtt{"];let r=!0,s=0;for(;r&&s<10;){r=!1,s++;for(const a of e){let l=0;for(;l<t.length;){const n=t.indexOf(a,l);if(n===-1)break;let h=1,c=n+a.length;for(;c<t.length&&h>0;)t[c]==="{"&&!z(t,c)?h++:t[c]==="}"&&!z(t,c)&&h--,c++;if(h===0){const d=t.slice(n+a.length,c-1);t=t.slice(0,n)+d+t.slice(c),r=!0,l=n}else l=n+a.length}}}return t}function lt(o){return!o||typeof o!="string"?!1:[/[\^_]/,/\\frac\b/,/\\tfrac\b/,/\\nicefrac\b/,/\\sqrt\b/,/\\ce\b/,/\\int\b/,/\\iint\b/,/\\iiint\b/,/\\oint\b/,/\\sum\b/,/\\prod\b/,/\\lim\b/,/\\begin\b/,/\\enclose\b/,/\\placeholder\b/,/\\over\b/,/\\vec\b/,/\\hat\b/,/\\tilde\b/,/\\bar\b/,/\\dot\b/,/\\ddot\b/,/\\underbrace\b/,/\\overbrace\b/,/\\overset\b/,/\\underset\b/,/\\raisebox\b/,/\\lowerbox\b/,/\\left\b/,/\\right\b/,/\\class\b/,/\\style\b/,/\\(LARGE|Large|large|scriptsize|tiny|small|huge|Huge|footnotesize|normalsize)\b/,/\\alpha\b|\\beta\b|\\gamma\b|\\delta\b|\\epsilon\b|\\zeta\b|\\eta\b|\\theta\b|\\iota\b|\\kappa\b|\\lambda\b|\\mu\b|\\nu\b|\\xi\b|\\pi\b|\\rho\b|\\sigma\b|\\tau\b|\\upsilon\b|\\phi\b|\\chi\b|\\psi\b|\\omega\b/,/\\Gamma\b|\\Delta\b|\\Theta\b|\\Lambda\b|\\Xi\b|\\Pi\b|\\Sigma\b|\\Upsilon\b|\\Phi\b|\\Psi\b|\\Omega\b/,/\\pm\b|\\times\b|\\div\b|\\leq\b|\\geq\b|\\neq\b|\\approx\b|\\infty\b|\\partial\b|\\to\b|\\rightarrow\b/].some(e=>e.test(o))}function rt(o,t){return o?lt(o)?o:(t==null?void 0:t.fontFamily)==="sans-serif"?`\\mathsf{${o}}`:(t==null?void 0:t.fontFamily)==="monospace"?`\\mathtt{${o}}`:(t==null?void 0:t.fontFamily)==="roman"?`\\mathrm{${o}}`:o:""}function Q(o,t,e,r){if(!o)return"";if(!t&&!e)return rt(o,{fontFamily:r});const s=r==="sans-serif",a=r==="monospace",l=r==="roman";return t&&e?s?`\\boldsymbol{\\mathsf{${o}}}`:a?`\\boldsymbol{\\mathtt{${o}}}`:l?`\\mathbfit{\\mathrm{${o}}}`:`\\mathbfit{${o}}`:t?s?`\\boldsymbol{\\mathsf{${o}}}`:a?`\\boldsymbol{\\mathtt{${o}}}`:l?`\\mathbf{\\mathrm{${o}}}`:`\\mathbf{${o}}`:e?s?`\\mathsf{${o}}`:a?`\\mathtt{${o}}`:l?`\\mathit{\\mathrm{${o}}}`:`\\mathit{${o}}`:o}function D(o,t,e,r){if(!o)return"";let s=o.trim();const a=s.match(/^\\displaylines\s*\{([\s\S]*)\}$/i);if(a&&(s=a[1].trim()),s.match(/^\\begin\{(array|matrix|pmatrix|bmatrix|vmatrix|Vmatrix|align|aligned|gather|cases)\}([\s\S]*)\\end\{\1\}$/i))return s;const n=s.match(/^\\begin\{(array|gather)\}(\{[\s\S]*?\})?([\s\S]*?)\\end\{\1\}$/i);if(n&&(s=n[3].trim()),/\\\\|\\cr|\\newline|\\par|\n/.test(s)){const h=/\\\\(?:\[[^\]]*\])?|\\cr|\\newline|\\par|\n/;return`\\displaylines{${s.split(h).map(w=>{const y=w.trim();return y?Q(y,t,e,r):""}).filter(w=>w.length>0).join(" \\\\ ")}}`}return Q(s,t,e,r)}function st(o){return o?o.replace(/\\enclose\{([^}]*)\}\s*\[.*?\]/g,"\\enclose{$1}"):""}function ot(o=""){if(typeof o!="string")return o;let t=o.replace(/\\textasciitilde/g,"\\text{~}").replace(/\\textasciicircum/g,"\\text{^}").replace(/\\textasteriskcentered/g,"*").replace(/\\char96/g,"`");return t.includes("\\ce{")&&(t=t.replace(/\\ce\{([\s\S]*?)\}/g,(e,r)=>r.includes("\\{")||r.includes("\\}")||r.includes("\\lbrace")||r.includes("\\rbrace")?r:`\\ce{${r.replace(/\\left\[/g,"[").replace(/\\right\]/g,"]").replace(/\\lbrack\b/g,"[").replace(/\\rbrack\b/g,"]").replace(/\\left\(/g,"(").replace(/\\right\)/g,")").replace(/\\left\|/g,"|").replace(/\\right\|/g,"|").replace(/\\left\./g,"").replace(/\\right\./g,"").replace(/\\enspace(?:\s|{})?/g,"~")}}`)),t}const X="data-mathfield-shadow-styles",K=`
|
|
90
90
|
.ML__content, .ML__container, .ML__field-container, .ML__formula {
|
|
91
91
|
overflow: visible !important;
|
|
92
92
|
contain: none !important;
|
|
@@ -411,10 +411,10 @@
|
|
|
411
411
|
text-align: right;
|
|
412
412
|
padding-top: 0.1em;
|
|
413
413
|
}
|
|
414
|
-
`;function U(o,t=null){o&&requestAnimationFrame(()=>{try{const e=o.shadowRoot;if(!e)return;const
|
|
414
|
+
`;function U(o,t=null){o&&requestAnimationFrame(()=>{try{const e=o.shadowRoot;if(!e)return;const r=e.querySelector(".ML__caret")||e.querySelector(".ML__focused")||e.querySelector(".ML__selection")||e.querySelector(".ML__selected")||e.querySelector("[class*='caret']")||e.querySelector("[class*='focused']");if(!r)return;const s=r.getBoundingClientRect();if(s.top===0&&s.left===0&&s.width===0&&s.height===0)return;const a=[];t&&t.isConnected&&a.push(t);let l=o;for(;l&&l!==document.body&&l!==document.documentElement;){if(!a.includes(l)){const c=window.getComputedStyle(l);(c.overflow==="auto"||c.overflow==="scroll"||c.overflowX==="auto"||c.overflowX==="scroll"||c.overflowY==="auto"||c.overflowY==="scroll")&&a.push(l)}l=l.parentElement}a.length===0&&o.parentElement&&a.push(o.parentElement);const n=40,h=20;for(const c of a){const d=c.getBoundingClientRect();if(s.right+n>d.right){const w=s.right+n-d.right;c.scrollLeft+=w}else if(s.left-n<d.left){const w=d.left-(s.left-n);c.scrollLeft-=w}if(s.bottom+h>d.bottom){const w=s.bottom+h-d.bottom;c.scrollTop+=w}else if(s.top-h<d.top){const w=d.top-(s.top-h);c.scrollTop-=w}}}catch{}})}function at(o){if(!o||o._cmeCaretTrackingAttached||o.hasAttribute("read-only")||o.hasAttribute("readonly"))return;o._cmeCaretTrackingAttached=!0;const e=()=>U(o);o.addEventListener("input",e),o.addEventListener("selection-change",e),o.addEventListener("keyup",e),o.addEventListener("keydown",e),o.addEventListener("focus",e),o.addEventListener("pointerup",e)}function N(o){const t=o==null?void 0:o.shadowRoot;if(!t)return;const e=o.hasAttribute("read-only")||o.hasAttribute("readonly"),r=e?"readonly":"editable";e||at(o);let s=t.querySelector(`[${X}]`);s&&s.getAttribute("data-cache")===r||(s||(s=document.createElement("style"),s.setAttribute(X,"true"),t.appendChild(s)),s.setAttribute("data-cache",r),s.textContent=`
|
|
415
415
|
${e?`
|
|
416
416
|
:host, :host * { cursor: pointer !important; }
|
|
417
417
|
.ML__latex, .ML__content, .ML__container, .ML__virtual-keyboard-toggle { cursor: pointer !important; }
|
|
418
418
|
`:""}
|
|
419
419
|
${K}
|
|
420
|
-
`)}function nt(){document.querySelectorAll("math-field").forEach(N)}let V=null;function W(){V||(nt(),V=new MutationObserver(o=>{var t,e,s;for(const r of o){if(r.type==="attributes"&&((t=r.target.tagName)==null?void 0:t.toLowerCase())==="math-field"){N(r.target);continue}if(r.addedNodes)for(const a of r.addedNodes)a instanceof Element&&(((e=a.tagName)==null?void 0:e.toLowerCase())==="math-field"&&requestAnimationFrame(()=>N(a)),(s=a.querySelectorAll)==null||s.call(a,"math-field").forEach(l=>requestAnimationFrame(()=>N(l))))}}),V.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["read-only","readonly"]}))}const G=[{id:"All",name:"All"},{id:"Symbol",name:"Symbol",ranges:[[8704,8959],[9728,9983],[8592,8703],[9984,10175]]},{id:"Punctuation",name:"Punctuation",ranges:[[33,47],[58,64],[91,96],[123,126],[161,161],[171,171],[187,187],[191,191],[8208,8231],[8240,8286],[10088,10101],[10214,10223],[10627,10648],[11776,11903],[12288,12351],[65104,65135],[65281,65295],[65306,65312],[65339,65344],[65371,65381]]},{id:"Letter",name:"Letter",ranges:[[65,90],[97,122],[880,1023],[1024,1279]]},{id:"Mark",name:"Mark",ranges:[[169,169],[174,174],[8224,8231],[8240,8286],[8471,8471],[8482,8482],[9744,9746],[10003,10008],[10013,10017],[10018,10059],[10067,10074],[10081,10087],[10132,10174],[128500,128505]]},{id:"Number",name:"Number",ranges:[[48,57],[8304,8351],[8528,8591],[9312,9471],[10102,10131],[65296,65305],[120782,120831]]},{id:"Phonetic",name:"Phonetic",ranges:[[592,687],[688,767],[7424,7551],[7552,7615],[43824,43887]]},{id:"Other",name:"Other",ranges:[[8352,8399],[8448,8527],[8960,9215],[9472,9599],[9600,9631],[9632,9727],[10240,10495],[11008,11263]]}],ht=(()=>{const o=[];return G.slice(1).forEach(t=>{t.ranges.forEach(e=>{for(let s=e[0];s<=e[1];s++){if(s>=127&&s<=159)continue;const r=String.fromCodePoint(s);new RegExp("\\p{C}","u").test(r)||o.push({code:s.toString(16).toUpperCase().padStart(4,"0"),char:r,category:t.id})}})}),o})();class Y{constructor(t={}){this.onInsert=t.onInsert||(()=>{}),this.onClose=t.onClose||(()=>{}),this.isOpen=!1,this.searchCode="",this.selectedCategory="All",this.overlay=null,this.modal=null,this.bodyContainer=null,this.boundKeyDown=this.handleKeyDown.bind(this)}open(t=null){this.isOpen||(this.isOpen=!0,this.searchCode="",this.selectedCategory="All",this.render(t),window.addEventListener("keydown",this.boundKeyDown))}close(){this.isOpen&&(this.isOpen=!1,window.removeEventListener("keydown",this.boundKeyDown),this.overlay&&this.overlay.parentNode&&this.overlay.parentNode.removeChild(this.overlay),this.overlay=null,this.onClose())}handleKeyDown(t){t.key==="Escape"&&this.close()}getFilteredCharacters(){let t=ht;if(this.selectedCategory!=="All"&&(t=t.filter(e=>e.category===this.selectedCategory)),this.searchCode.trim()){const e=this.searchCode.trim().toUpperCase();t=t.filter(s=>s.code.includes(e))}return t}getGroupedCharacters(t){if(this.selectedCategory!=="All"&&!this.searchCode.trim())return{[this.selectedCategory]:t};const e={};return t.forEach(s=>{e[s.category]||(e[s.category]=[]),e[s.category].push(s)}),e}render(t){if(this.overlay&&this.overlay.parentNode&&this.overlay.parentNode.removeChild(this.overlay),this.overlay=document.createElement("div"),this.overlay.className="scm-overlay",this.overlay.addEventListener("mousedown",l=>{l.stopPropagation(),this.close()}),this.modal=document.createElement("div"),this.modal.className="scm-modal",this.modal.addEventListener("mousedown",l=>l.stopPropagation()),t){let l=t.x-120,n=t.y;l<10&&(l=10),l+230>window.innerWidth&&(l=window.innerWidth-240),n+200>window.innerHeight&&(n=window.innerHeight-210),this.modal.style.top=`${n}px`,this.modal.style.left=`${l}px`,this.modal.style.transform="none"}else this.modal.style.top="50%",this.modal.style.left="50%",this.modal.style.transform="translate(-50%, -50%)";const e=document.createElement("div");e.className="scm-toolbar";const s=document.createElement("input");s.type="text",s.placeholder="Code",s.className="scm-code-input",s.value=this.searchCode,s.addEventListener("input",l=>{this.searchCode=l.target.value,this.updateGrid()});const r=document.createElement("select");r.className="scm-category-select",G.forEach(l=>{const n=document.createElement("option");n.value=l.id,n.textContent=l.name,r.appendChild(n)}),r.value=this.selectedCategory,r.addEventListener("change",l=>{this.selectedCategory=l.target.value,this.updateGrid()}),e.appendChild(s),e.appendChild(r),this.modal.appendChild(e);const a=document.createElement("div");a.className="scm-body",this.bodyContainer=document.createElement("div"),this.bodyContainer.className="scm-grid-container",a.appendChild(this.bodyContainer),this.modal.appendChild(a),this.updateGrid(),this.overlay.appendChild(this.modal),document.body.appendChild(this.overlay),setTimeout(()=>s.focus(),50)}updateGrid(){if(!this.bodyContainer)return;this.bodyContainer.innerHTML="";const t=this.getFilteredCharacters(),e=this.getGroupedCharacters(t),s=Object.entries(e);if(s.length===0||t.length===0){const r=document.createElement("div");r.className="scm-no-results",r.textContent="No characters found.",this.bodyContainer.appendChild(r);return}s.forEach(([r,a])=>{const l=document.createElement("div");l.className="scm-category-group";const n=document.createElement("div");n.className="scm-char-grid",a.forEach(h=>{const c=document.createElement("button");c.type="button",c.className="scm-char-btn",c.title=`U+${h.code}`,c.textContent=h.char,c.addEventListener("click",d=>{d.preventDefault(),this.onInsert(h.char),this.close()}),n.appendChild(c)}),l.appendChild(n),this.bodyContainer.appendChild(l)})}destroy(){this.close()}}const A={version:"1.0.32"};typeof window<"u"&&(window.MathfieldElement?window.MathfieldElement.fontsDirectory="https://cdn.jsdelivr.net/npm/mathlive/dist/fonts":v.MathfieldElement&&(v.MathfieldElement.fontsDirectory="https://cdn.jsdelivr.net/npm/mathlive/dist/fonts"));const O=class O{constructor(t={}){this.version=O.VERSION,this.options=t,this.onInsert=t.onInsert||(()=>{}),this.onClose=t.onClose||(()=>{}),this.mode=t.mode||"math",this.title=t.title||null,this.isOpen=!1,this.isEditing=!1,this.initialLatex="",this.activeGroup=0,this.explicitToggle=!1,this.activeStyles={bold:!1,italic:!1,fontFamily:"none",fontSize:"auto",color:"none"},this.isMaximized=!1,this.isMinimized=!1,this.position={x:0,y:0},this.isDragging=!1,this.dragStart={x:0,y:0},this.popup=null,this.mathField=null,this.mathFieldContainer=null,this.tabsWrapper=null,this.itemsWrapper=null,this.activeDropdown=null,this.activeDropdownBtn=null,this.activeMatrixPopup=null,this.activeMatrixBtn=null,this.colorPickerPopup=null,this.activeColorBtn=null,this.specCharModal=null,this.boundKeyDown=this.handleGlobalKeyDown.bind(this),this.boundDocClick=this.handleDocumentClick.bind(this),this.boundMouseMove=this.handleMouseMove.bind(this),this.boundMouseUp=this.handleMouseUp.bind(this),this.boundTouchMove=this.handleTouchMove.bind(this),this.boundTouchEnd=this.handleMouseUp.bind(this),this.boundResize=this.handleWindowResize.bind(this)}getGroups(){return this.mode==="chem"?tt:$}setMode(t){if(!(!t||t===this.mode)&&(this.mode=t,this.activeGroup=0,this.explicitToggle=!1,this.closeAllPopups(),this.specCharModal&&this.specCharModal.close(),this.isOpen&&this.popup)){const e=this.popup.querySelector(".cme-popup-header span");if(e){const s=this.title||(this.isEditing?this.mode==="chem"?"Edit Chemistry Formula":"Edit Math Formula":this.mode==="chem"?"Chemistry Editor":"Math Editor");e.textContent=s}this.renderTabs(),this.renderToolbarItems()}}open(t="",e=null){if(this.isOpen){e&&e!==this.mode&&this.setMode(e),this.setValue(t||""),this.initialLatex=t||"",this.isEditing=!!t;return}this.isOpen=!0,this.position={x:0,y:0},this.isDragging=!1,this.isMaximized=!1,this.isMinimized=!1,this.initialLatex=t||"",this.isEditing=!!t,e&&(this.mode=e),this.activeGroup=0,this.explicitToggle=!1,this.activeStyles={bold:!1,italic:!1,fontFamily:"none",fontSize:"auto",color:"none"},this.render(),window.addEventListener("keydown",this.boundKeyDown),document.addEventListener("mousedown",this.boundDocClick,!0),document.addEventListener("pointerdown",this.boundDocClick,!0),window.addEventListener("mousemove",this.boundMouseMove),window.addEventListener("mouseup",this.boundMouseUp),window.addEventListener("touchmove",this.boundTouchMove,{passive:!1}),window.addEventListener("touchend",this.boundTouchEnd),window.addEventListener("resize",this.boundResize)}close(){this.isOpen&&(this.isOpen=!1,window.removeEventListener("keydown",this.boundKeyDown),document.removeEventListener("mousedown",this.boundDocClick,!0),document.removeEventListener("pointerdown",this.boundDocClick,!0),window.removeEventListener("mousemove",this.boundMouseMove),window.removeEventListener("mouseup",this.boundMouseUp),window.removeEventListener("touchmove",this.boundTouchMove),window.removeEventListener("touchend",this.boundTouchEnd),window.removeEventListener("resize",this.boundResize),this.closeAllPopups(),this.specCharModal&&this.specCharModal.close(),this.popup&&this.popup.parentNode&&this.popup.parentNode.removeChild(this.popup),this.popup=null,this.mathField=null,this.mathFieldContainer=null,this.onClose())}scrollToCaret(){this.mathField&&U(this.mathField,this.mathFieldContainer)}getValue(){if(!this.mathField)return"";const t=this.mathField.getValue?this.mathField.getValue("latex"):this.mathField.value||"";return ot(t)}setValue(t){if(!this.mathField)return;const e=t||"";try{typeof this.mathField.setValue=="function"?this.mathField.setValue(e):this.mathField.textContent=e}catch{this.mathField.textContent=e}this.scrollToCaret()}handleGlobalKeyDown(t){if(t.key==="Escape"){if(this.activeDropdown||this.activeMatrixPopup||this.colorPickerPopup){this.closeAllPopups();return}this.close();return}t.key==="Enter"&&(t.ctrlKey||t.metaKey)&&(t.preventDefault(),this.handleInsert())}handleDocumentClick(t){if(!this.popup)return;const e=t.composedPath?t.composedPath():[];this.activeDropdown&&(this.activeDropdown===t.target||this.activeDropdown.contains(t.target)||e.includes(this.activeDropdown)||this.activeDropdownBtn&&(this.activeDropdownBtn===t.target||this.activeDropdownBtn.contains(t.target)||e.includes(this.activeDropdownBtn))||this.closeDropdown()),this.activeMatrixPopup&&(this.activeMatrixPopup===t.target||this.activeMatrixPopup.contains(t.target)||e.includes(this.activeMatrixPopup)||this.activeMatrixBtn&&(this.activeMatrixBtn===t.target||this.activeMatrixBtn.contains(t.target)||e.includes(this.activeMatrixBtn))||this.closeMatrixPopup()),this.colorPickerPopup&&(this.colorPickerPopup===t.target||this.colorPickerPopup.contains(t.target)||e.includes(this.colorPickerPopup)||this.activeColorBtn&&(this.activeColorBtn===t.target||this.activeColorBtn.contains(t.target)||e.includes(this.activeColorBtn))||this.closeColorPicker())}handleInsert(){let t=this.getValue();t=et(t),t=it(t),t=st(t),this.mode==="chem"&&(t=t.replace(/\\enspace(?:\s|{})?/g," "),t.includes("\\displaylines")||t.includes("\\\\")||t.includes("\\class{cme-")||t.includes("\\xleftrightarrows")||t.includes("\\xleftrightharpoons")||t.includes("\\enclose")||t.includes("\\{")||t.includes("\\}")||t.includes("\\lbrace")||t.includes("\\rbrace")?/^\\ce\{[\s\S]*\}$/i.test(t.trim())&&(t=t.trim().replace(/^\\ce\{([\s\S]*)\}$/i,"$1")):t.trim()&&!t.trim().startsWith("\\ce{")&&!t.includes("\\ce{")&&(t=`\\ce{${t}}`)),this.onInsert(t),this.close()}insertAtCursor(t){if(this.closeAllPopups(),!this.mathField)return;const e=this.mathField;if(e.smartSuperscript=!1,e.focus(),typeof t=="string"){const s=D(t,this.activeStyles.bold,this.activeStyles.italic,this.activeStyles.fontFamily);e.executeCommand?e.executeCommand(["insert",s,{selectionMode:"placeholder"}]):e.insert(s)}else if(t&&t.insert){const s=t.action==="INSERT_CUSTOM"||t.directInsert?D(t.insert,this.activeStyles.bold,this.activeStyles.italic,this.activeStyles.fontFamily):t.insert;e.executeCommand?e.executeCommand(["insert",s,{selectionMode:"placeholder"}]):e.insert(s)}this.scrollToCaret()}getInsertStyle(){const t={};return this.activeStyles.bold&&this.activeStyles.italic?(t.variant="main",t.variantStyle="bolditalic"):this.activeStyles.bold?(t.variant="normal",t.variantStyle="bold"):this.activeStyles.italic&&(t.variant="main",t.variantStyle="italic"),this.activeStyles.fontFamily&&this.activeStyles.fontFamily!=="none"&&(t.fontFamily=this.activeStyles.fontFamily),this.activeStyles.color&&this.activeStyles.color!=="none"&&(t.color=this.activeStyles.color),t}isAllSelected(t){if(!t||t.selectionIsCollapsed)return!1;try{const e=t.model,s=(e==null?void 0:e.selection)||t.selection;if(s){const r=s.ranges||(Array.isArray(s)?[s]:[]);if(r.length>0){let a=1/0,l=-1/0;for(const h of r)Array.isArray(h)&&(a=Math.min(a,h[0],h[1]),l=Math.max(l,h[0],h[1]));const n=(e==null?void 0:e.lastOffset)||1;if(a<=1&&l>=n)return!0}}}catch{}return!1}getSelectionLatex(t){if(!t)return"";try{if(this.isAllSelected(t))return t.getValue()||t.value||"";if(t.selection){const e=t.getValue(t.selection);if(typeof e=="string")return e}}catch{}try{if(t.model&&t.model.selection){const e=t.getValue(t.model.selection);if(typeof e=="string")return e}}catch{}try{const e=t.getValue("latex-selection");if(typeof e=="string")return e}catch{}return""}checkSelectionBold(t){if(!t)return!1;if(!t.selectionIsCollapsed){const e=this.getSelectionLatex(t);if(e&&e.trim()&&/\\mathbfit\{|\\mathbf\{|\\boldsymbol\{|\\textbf\{|\\bold\{|\\bm\{|\\pmb\{/.test(e.trim()))return!0}try{if(typeof t.queryStyle=="function"){const e=t.queryStyle({variantStyle:"bold"}),s=t.queryStyle({variantStyle:"bolditalic"}),r=t.queryStyle({fontSeries:"b"});if(e==="all"||e==="some"||s==="all"||s==="some"||r==="all"||r==="some")return!0}}catch{}try{const e=t.model;if(e&&!t.selectionIsCollapsed&&(e.selection||t.selection)){const s=e.selection||t.selection,r=e.getAtoms(s,{includeChildren:!0});if(r&&r.length>0&&r.some(l=>{if(!l||l.type==="first")return!1;const n=l.style;return n?n.variantStyle==="bold"||n.variantStyle==="bolditalic"||n.fontSeries==="b"||n.variant==="bold":!1}))return!0}}catch{}return!1}checkSelectionItalic(t){if(!t)return!1;if(!t.selectionIsCollapsed){const e=this.getSelectionLatex(t);if(e&&e.trim()&&/\\mathbfit\{|\\mathit\{|\\textit\{|\\textsl\{|\\slshape\{/.test(e.trim()))return!0}try{if(typeof t.queryStyle=="function"){const e=t.queryStyle({variantStyle:"italic"}),s=t.queryStyle({variantStyle:"bolditalic"}),r=t.queryStyle({fontShape:"it"});if(e==="all"||e==="some"||s==="all"||s==="some"||r==="all"||r==="some")return!0}}catch{}try{const e=t.model;if(e&&!t.selectionIsCollapsed&&(e.selection||t.selection)){const s=e.selection||t.selection,r=e.getAtoms(s,{includeChildren:!0});if(r&&r.length>0&&r.some(l=>{if(!l||l.type==="first")return!1;const n=l.style;return n?n.variantStyle==="italic"||n.variantStyle==="bolditalic"||n.fontShape==="it":!1}))return!0}}catch{}return!1}updateStylesFromSelection(){const t=this.mathField;if(t)if(t.selectionIsCollapsed){if(this.explicitToggle)return;let e=!1;this.activeStyles.bold&&(this.activeStyles.bold=!1,e=!0),this.activeStyles.italic&&(this.activeStyles.italic=!1,e=!0),e&&this.renderToolbarItems()}else{this.explicitToggle=!1;const e=this.checkSelectionBold(t),s=this.checkSelectionItalic(t);let r=!1;this.activeStyles.bold!==e&&(this.activeStyles.bold=e,r=!0),this.activeStyles.italic!==s&&(this.activeStyles.italic=s,r=!0),r&&this.renderToolbarItems()}}render(){this.popup=document.createElement("div"),this.popup.className="cme-editor-popup"+(this.isMaximized?" maximized":"")+(this.isMinimized?" minimized":""),this.popup.addEventListener("mousedown",i=>{this.handleDocumentClick(i),i.stopPropagation()}),this.popup.addEventListener("pointerdown",i=>{this.handleDocumentClick(i)});const t=document.createElement("div");t.className="cme-popup-topbar";const e=document.createElement("div");e.className="cme-popup-header",e.style.cursor="grab";const s=this.title||(this.isEditing?this.mode==="chem"?"Edit Chemistry Formula":"Edit Math Formula":this.mode==="chem"?"Chemistry Editor":"Math Editor");e.innerHTML=`<span>${s}</span>`;const r=(i,b,g)=>{g&&g.closest&&g.closest(".cme-popup-btn")||(this.closeAllPopups(),this.specCharModal&&this.specCharModal.close(),this.isDragging=!0,this.dragStart={x:i-this.position.x,y:b-this.position.y},e.style.cursor="grabbing")};e.addEventListener("mousedown",i=>{r(i.clientX,i.clientY,i.target)}),e.addEventListener("touchstart",i=>{i.touches&&i.touches.length>0&&r(i.touches[0].clientX,i.touches[0].clientY,i.target)},{passive:!0});const a=document.createElement("div");a.className="cme-popup-controls";const l=document.createElement("button");l.type="button",l.className="cme-popup-btn",l.textContent="—",l.title="Minimize",l.addEventListener("click",()=>this.toggleMinimize());const n=document.createElement("button");n.type="button",n.className="cme-popup-btn",n.textContent="⤢",n.title="Maximize",n.addEventListener("click",()=>this.toggleMaximize()),this.minBtn=l,this.maxBtn=n;const h=document.createElement("button");h.type="button",h.className="cme-popup-btn",h.textContent="✕",h.title="Close",h.addEventListener("click",()=>this.close()),a.appendChild(l),a.appendChild(n),a.appendChild(h),t.appendChild(e),t.appendChild(a),this.popup.appendChild(t);const c=document.createElement("div");c.className="cme-toolbar",c.setAttribute("role","toolbar"),c.setAttribute("aria-label","Symbol palette"),this.tabsWrapper=document.createElement("div"),this.tabsWrapper.className="cme-toolbar-groups",this.renderTabs(),c.appendChild(this.tabsWrapper),this.itemsWrapper=document.createElement("div"),this.itemsWrapper.className="cme-toolbar-items",this.renderToolbarItems(),c.appendChild(this.itemsWrapper),this.popup.appendChild(c);const d=document.createElement("div");d.className="cme-mathfield-container",this.mathFieldContainer=d,d.addEventListener("mousedown",i=>{var b,g;this.explicitToggle=!1,this.closeAllPopups(),!(this.mathField&&(i.target===this.mathField||this.mathField.contains(i.target)))&&(i.preventDefault(),(g=(b=this.mathField)==null?void 0:b.focus)==null||g.call(b))}),this.mathField=document.createElement("math-field"),this.mathField.className="cme-mathfield",this.mathField.setAttribute("tabindex","0"),this.mathField.setAttribute("math-virtual-keyboard-policy","manual"),this.mathField.setAttribute("smart-superscript","false"),this.mathField.smartSuperscript=!1,this.mathField.setAttribute("math-mode-space","\\enspace"),this.mathField.mathModeSpace="\\enspace",this.mathField.onInsertStyle=()=>this.getInsertStyle(),this.mathField.addEventListener("keydown",i=>{if(i.key==="Enter"&&!i.ctrlKey&&!i.metaKey&&!i.altKey){i.preventDefault(),i.stopPropagation(),i.stopImmediatePropagation(),this.activeStyles.bold||this.activeStyles.italic||this.activeStyles.fontFamily&&this.activeStyles.fontFamily!=="none"?this.explicitToggle=!0:this.explicitToggle=!1;const p=this.mathField;p!=null&&p.executeCommand&&p.executeCommand("addRowAfter"),this.scrollToCaret();return}if(i.key===" "||i.code==="Space"){i.preventDefault(),i.stopPropagation(),i.stopImmediatePropagation();const p=this.mathField;p.executeCommand?p.executeCommand(["insert","\\enspace ",{selectionMode:"after"}]):p.insert&&p.insert("\\enspace "),this.scrollToCaret();return}if(i.key==="ArrowLeft"||i.key==="ArrowRight"||i.key==="ArrowUp"||i.key==="ArrowDown"||i.key==="Home"||i.key==="End"){this.explicitToggle=!1,this.scrollToCaret();return}if(!this.activeStyles.bold&&!this.activeStyles.italic&&this.activeStyles.fontFamily==="none"||i.key.length!==1||i.ctrlKey||i.metaKey||i.altKey)return;i.preventDefault(),i.stopPropagation(),i.stopImmediatePropagation();const b=D(i.key,this.activeStyles.bold,this.activeStyles.italic,this.activeStyles.fontFamily),g=this.mathField;g.executeCommand?g.executeCommand(["insert",b,{selectionMode:"after"}]):g.insert&&g.insert(b),this.scrollToCaret()},{capture:!0});const w=()=>{this.updateStylesFromSelection(),this.scrollToCaret()};this.mathField.addEventListener("input",()=>this.scrollToCaret()),this.mathField.addEventListener("selection-change",w),this.mathField.addEventListener("pointerup",w),this.mathField.addEventListener("keyup",w),this.mathField.addEventListener("pointerdown",()=>{this.explicitToggle=!1,this.closeAllPopups()}),this.mathField.addEventListener("focus",()=>{this.closeAllPopups(),this.scrollToCaret()}),d.appendChild(this.mathField),this.popup.appendChild(d);const y=document.createElement("div");y.className="cme-popup-footer";const f=document.createElement("button");f.type="button",f.className="cme-insert-btn",f.textContent=this.isEditing?"Update":"Insert",f.addEventListener("click",()=>this.handleInsert());const k=document.createElement("button");k.type="button",k.className="cme-cancel-btn",k.textContent="Cancel",k.addEventListener("click",()=>this.close()),y.appendChild(f),y.appendChild(k);const u=`v${A.version}`;if(u){const i=document.createElement("span");i.className="cme-popup-version",i.textContent=u,i.title=`Version ${A.version}`,y.appendChild(i)}this.popup.appendChild(y),document.body.appendChild(this.popup),setTimeout(()=>{if(this.mathField){W();try{this.mathField.smartSuperscript=!1,this.mathField.inlineShortcuts=Object.assign({},this.mathField.inlineShortcuts||{},{"*":"*"}),typeof this.mathField.setOptions=="function"&&this.mathField.setOptions({smartSuperscript:!1,mathModeSpace:"\\enspace",onInsertStyle:()=>this.getInsertStyle(),macros:{...window.__cme_macros||{},...B}}),this.mathField.menuItems&&Array.isArray(this.mathField.menuItems)&&(this.mathField.menuItems=this.mathField.menuItems.filter(b=>b&&b.id!=="insert-matrix"&&b.submenuClass!=="insert-matrix-submenu"))}catch{}let i=this.initialLatex||"";this.mode==="chem"&&i.startsWith("\\ce{")&&i.endsWith("}")&&(i=i.slice(4,-1)),this.setValue(i),this.mathField.focus(),this.scrollToCaret()}},50)}clampPosition(t=this.position.x,e=this.position.y){if(!this.popup)return{x:t,y:e};const s=this.popup.getBoundingClientRect(),r=s.left-this.position.x,a=s.top-this.position.y,l=s.width,n=s.height,h=window.innerWidth,c=window.innerHeight;let d=-r,w=h-r-l,y=t;d>w?y=d:y=Math.max(d,Math.min(t,w));let f=-a,k=c-a-n,u=e;return f>k?u=f:u=Math.max(f,Math.min(e,k)),{x:y,y:u}}handleMouseMove(t){if(!this.isDragging||!this.popup)return;this.closeAllPopups(),this.specCharModal&&this.specCharModal.close();const e=t.clientX-this.dragStart.x,s=t.clientY-this.dragStart.y;this.position=this.clampPosition(e,s),this.popup.style.transform=`translate(${this.position.x}px, ${this.position.y}px)`}handleTouchMove(t){!this.isDragging||!t.touches||t.touches.length===0||(t.cancelable&&t.preventDefault(),this.handleMouseMove(t.touches[0]))}handleWindowResize(){if(!this.popup)return;const t=this.clampPosition(this.position.x,this.position.y);(t.x!==this.position.x||t.y!==this.position.y)&&(this.position=t,this.popup.style.transform=`translate(${this.position.x}px, ${this.position.y}px)`)}handleMouseUp(){var e;this.isDragging=!1;const t=(e=this.popup)==null?void 0:e.querySelector(".cme-popup-header");t&&(t.style.cursor="grab")}updateControlButtons(){this.maxBtn&&(this.maxBtn.textContent=this.isMaximized?"⤡":"⤢",this.maxBtn.title=this.isMaximized?"Restore":"Maximize"),this.minBtn&&(this.minBtn.title=this.isMinimized?"Restore":"Minimize")}toggleMaximize(){var t,e;this.isMaximized=!this.isMaximized,this.isMaximized&&(this.isMinimized=!1,(t=this.popup)==null||t.classList.remove("minimized")),(e=this.popup)==null||e.classList.toggle("maximized",this.isMaximized),this.position={x:0,y:0},this.popup&&(this.popup.style.transform="translate(0px, 0px)"),this.updateControlButtons()}toggleMinimize(){var t,e;this.isMinimized=!this.isMinimized,this.isMinimized&&(this.isMaximized=!1,(t=this.popup)==null||t.classList.remove("maximized")),(e=this.popup)==null||e.classList.toggle("minimized",this.isMinimized),this.position={x:0,y:0},this.popup&&(this.popup.style.transform="translate(0px, 0px)"),this.updateControlButtons()}renderTabs(){if(!this.tabsWrapper)return;this.tabsWrapper.innerHTML="",this.getGroups().forEach((e,s)=>{const r=this.activeGroup===s,a=document.createElement("button");if(a.type="button",a.className="cme-group-tab"+(r?" active":""),e.mathLabel){const l=document.createElement("math-field");l.setAttribute("read-only","true"),l.setAttribute("tabindex","-1"),l.style.pointerEvents="none",l.style.background="transparent",l.style.border="none",l.style.outline="none",l.style.fontSize=e.fontSize||(e.isMatrix?"8px":"11px"),l.style.display="inline-block",l.style.width="auto",l.style.padding="0",l.style.margin="0",l.style.boxShadow="none",l.style.color=r?"#333333":"#ffffff",l.textContent=e.mathLabel,a.appendChild(l)}else typeof e.label=="string"&&e.label.includes("<svg")?a.innerHTML=e.label:a.textContent=e.label;a.addEventListener("mousedown",l=>{l.preventDefault(),this.activeGroup=s,this.closeAllPopups(),this.renderTabs(),this.renderToolbarItems()}),this.tabsWrapper.appendChild(a)})}renderToolbarItems(){if(!this.itemsWrapper)return;this.itemsWrapper.innerHTML="";const e=this.getGroups()[this.activeGroup]||{items:[]},s=e.items||[],r=s.some(l=>l.type==="sep"),a=[];if(r){let l={cols:2,small:!1,cls:"",items:[],moreItems:null,moreCols:1};for(const n of s)n.type==="sep"?(l.items.length>0&&a.push(l),l={cols:n.cols||2,small:!!n.small,cls:n.cls||"",items:[],moreItems:n.moreItems||null,moreCols:n.moreCols||1}):l.items.push(n);l.items.length>0&&a.push(l)}else for(let n=0;n<s.length;n+=4)a.push({cols:2,small:!1,cls:"",items:s.slice(n,n+4)});a.forEach(l=>{const n=document.createElement("div");if(n.className="cme-symbol-subgroup"+(l.small?" cme-symbol-subgroup--small":"")+(l.cls?` ${l.cls}`:"")+(l.moreItems?" cme-subgroup-has-more":""),n.style.gridTemplateColumns=`repeat(${l.cols}, auto)`,n.style.position="relative",l.moreItems){const h=document.createElement("button");h.type="button",h.className="cme-more-trigger-btn",h.title="More",h.textContent="▶",h.addEventListener("mousedown",c=>c.preventDefault()),h.addEventListener("click",c=>{if(c.stopPropagation(),this.activeDropdown&&this.activeDropdownBtn===h)this.closeDropdown();else{const d=h.getBoundingClientRect();this.openDropdown(l.moreItems,d,l.moreCols||4,h)}}),n.appendChild(h)}l.items.forEach(h=>{if(h.type==="dropdown"){const u=h.label==="Font...",i=h.label==="Size",b=document.createElement("select");b.className="cme-select"+(u?" cme-select-font":"")+(i?" cme-select-size":"")+(u&&this.activeStyles.fontFamily!=="none"||i&&this.activeStyles.fontSize!=="auto"?" active":""),u?([{id:"none",label:"Font..."},{id:"roman",label:"Roman"},{id:"sans-serif",label:"Sans-Serif"},{id:"monospace",label:"Monospace"}].forEach(g=>{const p=document.createElement("option");p.value=g.id,p.textContent=g.label,b.appendChild(p)}),b.value=this.activeStyles.fontFamily,b.addEventListener("change",g=>{var p;this.activeStyles.fontFamily=g.target.value,(p=this.mathField)!=null&&p.applyStyle&&this.mathField.applyStyle({fontFamily:this.activeStyles.fontFamily==="none"?"none":this.activeStyles.fontFamily}),this.renderToolbarItems()})):i&&([{id:"auto",label:"Size"},{id:"1",label:"Tiny"},{id:"3",label:"Small"},{id:"5",label:"Normal"},{id:"7",label:"Large"},{id:"9",label:"Huge"}].forEach(g=>{const p=document.createElement("option");p.value=g.id,p.textContent=g.label,b.appendChild(p)}),b.value=this.activeStyles.fontSize,b.addEventListener("change",g=>{var p;if(this.activeStyles.fontSize=g.target.value,(p=this.mathField)!=null&&p.applyStyle){const S=this.activeStyles.fontSize==="auto"?"none":parseInt(this.activeStyles.fontSize,10);this.mathField.applyStyle({fontSize:S})}this.renderToolbarItems()})),n.appendChild(b);return}const c=h.action==="BOLD",d=h.action==="ITALIC",w=h.action==="TEXT_COLOR",y=h.action==="SPECIAL_CHARS",f=c&&this.activeStyles.bold||d&&this.activeStyles.italic||w&&this.activeStyles.color!=="none",k=document.createElement("button");k.type="button",k.className="cme-btn"+(e.isTemplate?" template":"")+(h.cls?` ${h.cls}`:"")+(f?" active":""),k.title=h.title||h.label||h.insert||"",typeof h.label=="string"&&(h.label.includes("<svg")||h.label.includes("<img")||h.label.includes("<strong")||h.label.includes("<em"))?k.innerHTML=h.label:typeof h.label=="string"&&(k.textContent=h.label),k.addEventListener("mousedown",u=>{var b,g,p,S,m,T,E,M,L,H;u.preventDefault();const i=this.mathField;if(y){this.closeAllPopups();const C=k.getBoundingClientRect();this.openSpecialCharacters(C)}else if(w)if(this.colorPickerPopup&&this.activeColorBtn===k)this.closeColorPicker();else{const C=k.getBoundingClientRect();this.openColorPicker(C,k)}else if(c){if(this.closeAllPopups(),this.explicitToggle=!0,this.activeStyles.bold=!this.activeStyles.bold,i){if(i.selectionIsCollapsed)this.activeStyles.bold||(i.styleBias="none",i.defaultStyle&&(delete i.defaultStyle.variantStyle,delete i.defaultStyle.fontSeries));else{const C=this.getSelectionLatex(i);if(C&&C.trim()){const q=j(C.trim()),I=D(q,this.activeStyles.bold,this.activeStyles.italic,this.activeStyles.fontFamily);if(this.activeStyles.bold||(i.styleBias="none",i.defaultStyle&&(delete i.defaultStyle.variantStyle,delete i.defaultStyle.fontSeries)),this.isAllSelected(i)?(i.setValue(I),i.executeCommand?i.executeCommand("selectAll"):(b=i.model)!=null&&b.setSelection&&i.model.setSelection(0,i.model.lastOffset)):i.executeCommand?i.executeCommand(["insert",I,{selectionMode:"item"}]):i.insert&&i.insert(I,{selectionMode:"item"}),!this.activeStyles.bold&&i.applyStyle)try{i.applyStyle({variantStyle:this.activeStyles.italic?"italic":"",fontSeries:"auto"},{operation:"set"})}catch{}}}i.focus()}this.renderToolbarItems()}else if(d){if(this.closeAllPopups(),this.explicitToggle=!0,this.activeStyles.italic=!this.activeStyles.italic,i){if(i.selectionIsCollapsed)this.activeStyles.italic||(i.styleBias="none",i.defaultStyle&&(delete i.defaultStyle.variantStyle,delete i.defaultStyle.fontShape));else{const C=this.getSelectionLatex(i);if(C&&C.trim()){const q=j(C.trim()),I=D(q,this.activeStyles.bold,this.activeStyles.italic,this.activeStyles.fontFamily);if(this.activeStyles.italic||(i.styleBias="none",i.defaultStyle&&(delete i.defaultStyle.variantStyle,delete i.defaultStyle.fontShape)),this.isAllSelected(i)?(i.setValue(I),i.executeCommand?i.executeCommand("selectAll"):(g=i.model)!=null&&g.setSelection&&i.model.setSelection(0,i.model.lastOffset)):i.executeCommand?i.executeCommand(["insert",I,{selectionMode:"item"}]):i.insert&&i.insert(I,{selectionMode:"item"}),!this.activeStyles.italic&&i.applyStyle)try{i.applyStyle({variantStyle:this.activeStyles.bold?"bold":"",fontShape:"auto"},{operation:"set"})}catch{}}}i.focus()}this.renderToolbarItems()}else if(h.action==="UNDO")this.closeAllPopups(),(p=i==null?void 0:i.executeCommand)==null||p.call(i,"undo");else if(h.action==="REDO")this.closeAllPopups(),(S=i==null?void 0:i.executeCommand)==null||S.call(i,"redo");else if(h.action==="CUT")this.closeAllPopups(),(m=i==null?void 0:i.focus)==null||m.call(i),(T=i==null?void 0:i.executeCommand)==null||T.call(i,"cutToClipboard");else if(h.action==="COPY")this.closeAllPopups(),(E=i==null?void 0:i.focus)==null||E.call(i),(M=i==null?void 0:i.executeCommand)==null||M.call(i,"copyToClipboard");else if(h.action==="PASTE")this.closeAllPopups(),(L=i==null?void 0:i.focus)==null||L.call(i),(H=i==null?void 0:i.executeCommand)==null||H.call(i,"pasteFromClipboard");else if(h.action==="MATRIX_HOVER")if(this.activeMatrixPopup&&this.activeMatrixBtn===k)this.closeMatrixPopup();else{const C=k.getBoundingClientRect();this.openMatrixGrid(h.matrixType||"matrix",C,k)}else this.insertAtCursor(h)}),n.appendChild(k)}),this.itemsWrapper.appendChild(n)})}openDropdown(t,e,s,r=null){this.closeAllPopups(),this.activeDropdownBtn=r,this.activeDropdown=document.createElement("div"),this.activeDropdown.className="cme-more-popup",this.activeDropdown.style.gridTemplateColumns=`repeat(${s}, auto)`,this.activeDropdown.style.left=`${e.left+e.width/2}px`,this.activeDropdown.style.top=`${e.bottom+4}px`,this.activeDropdown.style.transform="translateX(-50%)",this.activeDropdown.addEventListener("mousedown",a=>a.stopPropagation()),this.activeDropdown.addEventListener("pointerdown",a=>a.stopPropagation()),t.forEach(a=>{const l=document.createElement("button");l.type="button",l.className="cme-more-popup-btn "+(a.cls||""),l.title=a.title||a.label||a.insert||"",typeof a.label=="string"&&(a.label.includes("<svg")||a.label.includes("<img"))?l.innerHTML=a.label:l.textContent=a.label,l.addEventListener("mousedown",n=>{n.preventDefault(),this.insertAtCursor(a.insert||a),this.closeDropdown()}),this.activeDropdown.appendChild(l)}),document.body.appendChild(this.activeDropdown)}closeDropdown(){this.activeDropdown&&this.activeDropdown.parentNode&&this.activeDropdown.parentNode.removeChild(this.activeDropdown),this.activeDropdown=null,this.activeDropdownBtn=null}openMatrixGrid(t,e,s=null){this.closeAllPopups(),this.activeMatrixBtn=s,this.activeMatrixPopup=document.createElement("div"),this.activeMatrixPopup.className="cme-matrix-hover-popover ck-only",this.activeMatrixPopup.style.left=`${e.left+e.width/2}px`,this.activeMatrixPopup.style.top=`${e.bottom+6}px`,this.activeMatrixPopup.style.minHeight="auto",this.activeMatrixPopup.addEventListener("mousedown",m=>m.stopPropagation()),this.activeMatrixPopup.addEventListener("pointerdown",m=>m.stopPropagation());const r=document.createElement("div");r.className="cme-matrix-hover-title",r.textContent=t==="matrix"?"MATRIX":`${t.toUpperCase()} MATRIX`;const a=document.createElement("div");a.className="cme-matrix-hover-grid",a.style.flex="none";let l=2,n=2;const h=document.createElement("div");h.className="cme-matrix-hover-footer";const c=document.createElement("div");c.className="cme-matrix-counter";const d=document.createElement("input");d.type="number",d.className="cme-counter-val",d.min="1",d.max="10",d.value=l;const w=document.createElement("div");w.className="cme-counter-btns";const y=document.createElement("button");y.type="button",y.textContent="▲";const f=document.createElement("button");f.type="button",f.textContent="▼",w.appendChild(y),w.appendChild(f);const k=document.createElement("span");k.textContent="×";const u=document.createElement("input");u.type="number",u.className="cme-counter-val",u.min="1",u.max="10",u.value=n;const i=document.createElement("div");i.className="cme-counter-btns";const b=document.createElement("button");b.type="button",b.textContent="▲";const g=document.createElement("button");g.type="button",g.textContent="▼",i.appendChild(b),i.appendChild(g),c.appendChild(d),c.appendChild(w),c.appendChild(k),c.appendChild(u),c.appendChild(i);const p=document.createElement("button");p.type="button",p.className="cme-matrix-insert-btn",p.textContent="INSERT",h.appendChild(c),h.appendChild(p);const S=(m,T)=>{l=Math.max(1,Math.min(10,m)),n=Math.max(1,Math.min(10,T)),d.value=l,u.value=n,a.querySelectorAll(".cme-matrix-hover-cell").forEach(M=>{const L=parseInt(M.dataset.row,10),H=parseInt(M.dataset.col,10);L<=l&&H<=n?M.classList.add("selected"):M.classList.remove("selected")})};for(let m=1;m<=5;m++){const T=document.createElement("div");T.className="cme-matrix-hover-row";for(let E=1;E<=10;E++){const M=document.createElement("div");M.className="cme-matrix-hover-cell"+(m<=l&&E<=n?" selected":""),M.dataset.row=m,M.dataset.col=E,M.addEventListener("mouseenter",()=>{S(m,E)}),M.addEventListener("click",L=>{L.stopPropagation(),this.insertMatrix(t,m,E),this.closeMatrixPopup()}),T.appendChild(M)}a.appendChild(T)}d.addEventListener("input",()=>{const m=parseInt(d.value,10)||1;S(m,n)}),u.addEventListener("input",()=>{const m=parseInt(u.value,10)||1;S(l,m)}),y.addEventListener("click",m=>{m.preventDefault(),m.stopPropagation(),S(l+1,n)}),f.addEventListener("click",m=>{m.preventDefault(),m.stopPropagation(),S(l-1,n)}),b.addEventListener("click",m=>{m.preventDefault(),m.stopPropagation(),S(l,n+1)}),g.addEventListener("click",m=>{m.preventDefault(),m.stopPropagation(),S(l,n-1)}),p.addEventListener("click",m=>{m.stopPropagation(),this.insertMatrix(t,l,n),this.closeMatrixPopup()}),this.activeMatrixPopup.appendChild(r),this.activeMatrixPopup.appendChild(a),this.activeMatrixPopup.appendChild(h),document.body.appendChild(this.activeMatrixPopup)}insertMatrix(t,e,s){let r=[];for(let n=0;n<e;n++){let h=[];for(let c=0;c<s;c++)h.push("{#?}");r.push(h.join(" & "))}const a=t||"matrix",l=`\\begin{${a}}${r.join(" \\\\ ")}\\end{${a}}`;this.insertAtCursor(l)}closeMatrixPopup(){this.activeMatrixPopup&&this.activeMatrixPopup.parentNode&&this.activeMatrixPopup.parentNode.removeChild(this.activeMatrixPopup),this.activeMatrixPopup=null,this.activeMatrixBtn=null}openColorPicker(t,e=null){this.closeAllPopups(),this.activeColorBtn=e,this.colorPickerPopup=document.createElement("div"),this.colorPickerPopup.className="cme-more-popup",this.colorPickerPopup.style.gridTemplateColumns="repeat(4, auto)",this.colorPickerPopup.style.left=`${t.left+t.width/2}px`,this.colorPickerPopup.style.top=`${t.bottom+4}px`,this.colorPickerPopup.style.transform="translateX(-50%)",this.colorPickerPopup.addEventListener("mousedown",r=>r.stopPropagation()),this.colorPickerPopup.addEventListener("pointerdown",r=>r.stopPropagation()),["black","#e53935","#1e88e5","#43a047","#fb8c00","#8e24aa","#3949ab","#00acc1"].forEach(r=>{const a=document.createElement("div");a.style.width="18px",a.style.height="18px",a.style.borderRadius="50%",a.style.margin="4px",a.style.cursor="pointer",a.style.backgroundColor=r,a.style.border=this.activeStyles.color===r?"2px solid #222":"1px solid #ddd",a.addEventListener("mousedown",l=>{var n;l.preventDefault(),this.activeStyles.color=r,(n=this.mathField)!=null&&n.applyStyle&&this.mathField.applyStyle({color:r==="black"?"none":r}),this.closeColorPicker(),this.renderToolbarItems()}),this.colorPickerPopup.appendChild(a)}),document.body.appendChild(this.colorPickerPopup)}closeColorPicker(){this.colorPickerPopup&&this.colorPickerPopup.parentNode&&this.colorPickerPopup.parentNode.removeChild(this.colorPickerPopup),this.colorPickerPopup=null,this.activeColorBtn=null}openSpecialCharacters(t){this.specCharModal||(this.specCharModal=new Y({onInsert:e=>{this.insertAtCursor(e)}})),this.specCharModal.open({x:t.left,y:t.bottom+6})}closeAllPopups(){this.closeDropdown(),this.closeMatrixPopup(),this.closeColorPicker()}destroy(){this.close()}};_(O,"VERSION",A==null?void 0:A.version);let R=O,P=null;function ct(){return P||(P=new R),P}class F{constructor(t={}){this.container=t.container||null,this.latex=t.latex||"",this.editable=t.editable!==!1,this.mode=t.mode||"math",this.onUpdate=t.onUpdate||(()=>{}),this.editor=t.editor||ct(),this.element=null,this.mathField=null,this.container&&this.mount(this.container)}mount(t){this.container=t,this.element=document.createElement("span"),this.element.className="digi-math-widget"+(this.editable?"":" readonly"),this.element.setAttribute("data-latex",this.latex),this.element.title=this.editable?"Click to edit formula":"",this.mathField=document.createElement("math-field"),this.mathField.setAttribute("read-only","true"),this.mathField.textContent=this.latex,this.element.appendChild(this.mathField),this.editable&&this.element.addEventListener("click",e=>{e.preventDefault(),e.stopPropagation(),this.openEditor()}),this.container.appendChild(this.element)}openEditor(){this.editor.open(this.latex,this.mode),this.editor.onInsert=t=>{this.setLatex(t),this.onUpdate(t)}}setLatex(t){if(this.latex=t||"",this.element&&this.element.setAttribute("data-latex",this.latex),this.mathField)try{typeof this.mathField.setValue=="function"?this.mathField.setValue(this.latex):this.mathField.textContent=this.latex}catch{this.mathField.textContent=this.latex}}getLatex(){return this.latex}destroy(){this.element&&this.element.parentNode&&this.element.parentNode.removeChild(this.element)}}function dt(o){return new F(o)}if(typeof customElements<"u"&&!customElements.get("digi-math-widget")){class o extends HTMLElement{static get observedAttributes(){return["latex","editable","mode"]}connectedCallback(){const e=this.getAttribute("latex")||"",s=this.getAttribute("editable")!=="false",r=this.getAttribute("mode")||"math";this.widget=new F({container:this,latex:e,editable:s,mode:r,onUpdate:a=>{this.setAttribute("latex",a),this.dispatchEvent(new CustomEvent("latexChange",{detail:{latex:a},bubbles:!0}))}})}attributeChangedCallback(e,s,r){s!==r&&e==="latex"&&this.widget&&this.widget.setLatex(r)}disconnectedCallback(){this.widget&&this.widget.destroy()}}customElements.define("digi-math-widget",o)}const mt=A==null?void 0:A.version;x.CME_SHADOW_DOM_CSS=K,x.DigiMathChemEditor=R,x.DigiMathWidget=F,x.SpecialCharacterModal=Y,x.VERSION=mt,x.createMathWidget=dt,x.default=R,x.initMathFieldCursorFix=W,x.scrollMathFieldCaretIntoView=U,Object.defineProperties(x,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
420
|
+
`)}function nt(){document.querySelectorAll("math-field").forEach(N)}let V=null;function W(){V||(nt(),V=new MutationObserver(o=>{var t,e,r;for(const s of o){if(s.type==="attributes"&&((t=s.target.tagName)==null?void 0:t.toLowerCase())==="math-field"){N(s.target);continue}if(s.addedNodes)for(const a of s.addedNodes)a instanceof Element&&(((e=a.tagName)==null?void 0:e.toLowerCase())==="math-field"&&requestAnimationFrame(()=>N(a)),(r=a.querySelectorAll)==null||r.call(a,"math-field").forEach(l=>requestAnimationFrame(()=>N(l))))}}),V.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["read-only","readonly"]}))}const G=[{id:"All",name:"All"},{id:"Symbol",name:"Symbol",ranges:[[8704,8959],[9728,9983],[8592,8703],[9984,10175]]},{id:"Punctuation",name:"Punctuation",ranges:[[33,47],[58,64],[91,96],[123,126],[161,161],[171,171],[187,187],[191,191],[8208,8231],[8240,8286],[10088,10101],[10214,10223],[10627,10648],[11776,11903],[12288,12351],[65104,65135],[65281,65295],[65306,65312],[65339,65344],[65371,65381]]},{id:"Letter",name:"Letter",ranges:[[65,90],[97,122],[880,1023],[1024,1279]]},{id:"Mark",name:"Mark",ranges:[[169,169],[174,174],[8224,8231],[8240,8286],[8471,8471],[8482,8482],[9744,9746],[10003,10008],[10013,10017],[10018,10059],[10067,10074],[10081,10087],[10132,10174],[128500,128505]]},{id:"Number",name:"Number",ranges:[[48,57],[8304,8351],[8528,8591],[9312,9471],[10102,10131],[65296,65305],[120782,120831]]},{id:"Phonetic",name:"Phonetic",ranges:[[592,687],[688,767],[7424,7551],[7552,7615],[43824,43887]]},{id:"Other",name:"Other",ranges:[[8352,8399],[8448,8527],[8960,9215],[9472,9599],[9600,9631],[9632,9727],[10240,10495],[11008,11263]]}],ht=(()=>{const o=[];return G.slice(1).forEach(t=>{t.ranges.forEach(e=>{for(let r=e[0];r<=e[1];r++){if(r>=127&&r<=159)continue;const s=String.fromCodePoint(r);new RegExp("\\p{C}","u").test(s)||o.push({code:r.toString(16).toUpperCase().padStart(4,"0"),char:s,category:t.id})}})}),o})();class Y{constructor(t={}){this.onInsert=t.onInsert||(()=>{}),this.onClose=t.onClose||(()=>{}),this.isOpen=!1,this.searchCode="",this.selectedCategory="All",this.overlay=null,this.modal=null,this.bodyContainer=null,this.boundKeyDown=this.handleKeyDown.bind(this)}open(t=null){this.isOpen||(this.isOpen=!0,this.searchCode="",this.selectedCategory="All",this.render(t),window.addEventListener("keydown",this.boundKeyDown))}close(){this.isOpen&&(this.isOpen=!1,window.removeEventListener("keydown",this.boundKeyDown),this.overlay&&this.overlay.parentNode&&this.overlay.parentNode.removeChild(this.overlay),this.overlay=null,this.onClose())}handleKeyDown(t){t.key==="Escape"&&this.close()}getFilteredCharacters(){let t=ht;if(this.selectedCategory!=="All"&&(t=t.filter(e=>e.category===this.selectedCategory)),this.searchCode.trim()){const e=this.searchCode.trim().toUpperCase();t=t.filter(r=>r.code.includes(e))}return t}getGroupedCharacters(t){if(this.selectedCategory!=="All"&&!this.searchCode.trim())return{[this.selectedCategory]:t};const e={};return t.forEach(r=>{e[r.category]||(e[r.category]=[]),e[r.category].push(r)}),e}render(t){if(this.overlay&&this.overlay.parentNode&&this.overlay.parentNode.removeChild(this.overlay),this.overlay=document.createElement("div"),this.overlay.className="scm-overlay",this.overlay.addEventListener("mousedown",l=>{l.stopPropagation(),this.close()}),this.modal=document.createElement("div"),this.modal.className="scm-modal",this.modal.addEventListener("mousedown",l=>l.stopPropagation()),t){let l=t.x-120,n=t.y;l<10&&(l=10),l+230>window.innerWidth&&(l=window.innerWidth-240),n+200>window.innerHeight&&(n=window.innerHeight-210),this.modal.style.top=`${n}px`,this.modal.style.left=`${l}px`,this.modal.style.transform="none"}else this.modal.style.top="50%",this.modal.style.left="50%",this.modal.style.transform="translate(-50%, -50%)";const e=document.createElement("div");e.className="scm-toolbar";const r=document.createElement("input");r.type="text",r.placeholder="Code",r.className="scm-code-input",r.value=this.searchCode,r.addEventListener("input",l=>{this.searchCode=l.target.value,this.updateGrid()});const s=document.createElement("select");s.className="scm-category-select",G.forEach(l=>{const n=document.createElement("option");n.value=l.id,n.textContent=l.name,s.appendChild(n)}),s.value=this.selectedCategory,s.addEventListener("change",l=>{this.selectedCategory=l.target.value,this.updateGrid()}),e.appendChild(r),e.appendChild(s),this.modal.appendChild(e);const a=document.createElement("div");a.className="scm-body",this.bodyContainer=document.createElement("div"),this.bodyContainer.className="scm-grid-container",a.appendChild(this.bodyContainer),this.modal.appendChild(a),this.updateGrid(),this.overlay.appendChild(this.modal),document.body.appendChild(this.overlay),setTimeout(()=>r.focus(),50)}updateGrid(){if(!this.bodyContainer)return;this.bodyContainer.innerHTML="";const t=this.getFilteredCharacters(),e=this.getGroupedCharacters(t),r=Object.entries(e);if(r.length===0||t.length===0){const s=document.createElement("div");s.className="scm-no-results",s.textContent="No characters found.",this.bodyContainer.appendChild(s);return}r.forEach(([s,a])=>{const l=document.createElement("div");l.className="scm-category-group";const n=document.createElement("div");n.className="scm-char-grid",a.forEach(h=>{const c=document.createElement("button");c.type="button",c.className="scm-char-btn",c.title=`U+${h.code}`,c.textContent=h.char,c.addEventListener("click",d=>{d.preventDefault(),this.onInsert(h.char),this.close()}),n.appendChild(c)}),l.appendChild(n),this.bodyContainer.appendChild(l)})}destroy(){this.close()}}const A={version:"1.0.33"};typeof window<"u"&&(window.MathfieldElement?window.MathfieldElement.fontsDirectory="https://cdn.jsdelivr.net/npm/mathlive/dist/fonts":v.MathfieldElement&&(v.MathfieldElement.fontsDirectory="https://cdn.jsdelivr.net/npm/mathlive/dist/fonts"));const O=class O{constructor(t={}){this.version=O.VERSION,this.options=t,this.onInsert=t.onInsert||(()=>{}),this.onClose=t.onClose||(()=>{}),this.mode=t.mode||"math",this.title=t.title||null,this.isOpen=!1,this.isEditing=!1,this.initialLatex="",this.activeGroup=0,this.explicitToggle=!1,this.activeStyles={bold:!1,italic:!1,fontFamily:"none",fontSize:"auto",color:"none"},this.isMaximized=!1,this.isMinimized=!1,this.position={x:0,y:0},this.isDragging=!1,this.dragStart={x:0,y:0},this.popup=null,this.mathField=null,this.mathFieldContainer=null,this.tabsWrapper=null,this.itemsWrapper=null,this.activeDropdown=null,this.activeDropdownBtn=null,this.activeMatrixPopup=null,this.activeMatrixBtn=null,this.colorPickerPopup=null,this.activeColorBtn=null,this.specCharModal=null,this.boundKeyDown=this.handleGlobalKeyDown.bind(this),this.boundDocClick=this.handleDocumentClick.bind(this),this.boundMouseMove=this.handleMouseMove.bind(this),this.boundMouseUp=this.handleMouseUp.bind(this),this.boundTouchMove=this.handleTouchMove.bind(this),this.boundTouchEnd=this.handleMouseUp.bind(this),this.boundResize=this.handleWindowResize.bind(this)}getGroups(){return this.mode==="chem"?tt:$}setMode(t){if(!(!t||t===this.mode)&&(this.mode=t,this.activeGroup=0,this.explicitToggle=!1,this.closeAllPopups(),this.specCharModal&&this.specCharModal.close(),this.isOpen&&this.popup)){const e=this.popup.querySelector(".cme-popup-header span");if(e){const r=this.title||(this.isEditing?this.mode==="chem"?"Edit Chemistry Formula":"Edit Math Formula":this.mode==="chem"?"Chemistry Editor":"Math Editor");e.textContent=r}this.renderTabs(),this.renderToolbarItems()}}open(t="",e=null){if(this.isOpen){e&&e!==this.mode&&this.setMode(e);let r=t||"";this.mode==="chem"&&r.startsWith("\\ce{")&&r.endsWith("}")&&(r=r.slice(4,-1)),this.mode==="chem"&&(r=r.replace(/~/g,"\\enspace ")),this.setValue(r),this.initialLatex=t||"",this.isEditing=!!t;return}this.isOpen=!0,this.position={x:0,y:0},this.isDragging=!1,this.isMaximized=!1,this.isMinimized=!1,this.initialLatex=t||"",this.isEditing=!!t,e&&(this.mode=e),this.activeGroup=0,this.explicitToggle=!1,this.activeStyles={bold:!1,italic:!1,fontFamily:"none",fontSize:"auto",color:"none"},this.render(),window.addEventListener("keydown",this.boundKeyDown),document.addEventListener("mousedown",this.boundDocClick,!0),document.addEventListener("pointerdown",this.boundDocClick,!0),window.addEventListener("mousemove",this.boundMouseMove),window.addEventListener("mouseup",this.boundMouseUp),window.addEventListener("touchmove",this.boundTouchMove,{passive:!1}),window.addEventListener("touchend",this.boundTouchEnd),window.addEventListener("resize",this.boundResize)}close(){this.isOpen&&(this.isOpen=!1,window.removeEventListener("keydown",this.boundKeyDown),document.removeEventListener("mousedown",this.boundDocClick,!0),document.removeEventListener("pointerdown",this.boundDocClick,!0),window.removeEventListener("mousemove",this.boundMouseMove),window.removeEventListener("mouseup",this.boundMouseUp),window.removeEventListener("touchmove",this.boundTouchMove),window.removeEventListener("touchend",this.boundTouchEnd),window.removeEventListener("resize",this.boundResize),this.closeAllPopups(),this.specCharModal&&this.specCharModal.close(),this.popup&&this.popup.parentNode&&this.popup.parentNode.removeChild(this.popup),this.popup=null,this.mathField=null,this.mathFieldContainer=null,this.onClose())}scrollToCaret(){this.mathField&&U(this.mathField,this.mathFieldContainer)}getValue(){if(!this.mathField)return"";const t=this.mathField.getValue?this.mathField.getValue("latex"):this.mathField.value||"";return ot(t)}setValue(t){if(!this.mathField)return;const e=t||"";try{typeof this.mathField.setValue=="function"?this.mathField.setValue(e):this.mathField.textContent=e}catch{this.mathField.textContent=e}this.scrollToCaret()}handleGlobalKeyDown(t){if(t.key==="Escape"){if(this.activeDropdown||this.activeMatrixPopup||this.colorPickerPopup){this.closeAllPopups();return}this.close();return}t.key==="Enter"&&(t.ctrlKey||t.metaKey)&&(t.preventDefault(),this.handleInsert())}handleDocumentClick(t){if(!this.popup)return;const e=t.composedPath?t.composedPath():[];this.activeDropdown&&(this.activeDropdown===t.target||this.activeDropdown.contains(t.target)||e.includes(this.activeDropdown)||this.activeDropdownBtn&&(this.activeDropdownBtn===t.target||this.activeDropdownBtn.contains(t.target)||e.includes(this.activeDropdownBtn))||this.closeDropdown()),this.activeMatrixPopup&&(this.activeMatrixPopup===t.target||this.activeMatrixPopup.contains(t.target)||e.includes(this.activeMatrixPopup)||this.activeMatrixBtn&&(this.activeMatrixBtn===t.target||this.activeMatrixBtn.contains(t.target)||e.includes(this.activeMatrixBtn))||this.closeMatrixPopup()),this.colorPickerPopup&&(this.colorPickerPopup===t.target||this.colorPickerPopup.contains(t.target)||e.includes(this.colorPickerPopup)||this.activeColorBtn&&(this.activeColorBtn===t.target||this.activeColorBtn.contains(t.target)||e.includes(this.activeColorBtn))||this.closeColorPicker())}handleInsert(){let t=this.getValue();t=et(t),t=it(t),t=st(t),this.mode==="chem"&&(t=t.replace(/\\enspace(?:\s|{})?/g,"~"),t.includes("\\displaylines")||t.includes("\\\\")||t.includes("\\class{cme-")||t.includes("\\xleftrightarrows")||t.includes("\\xleftrightharpoons")||t.includes("\\enclose")||t.includes("\\{")||t.includes("\\}")||t.includes("\\lbrace")||t.includes("\\rbrace")?/^\\ce\{[\s\S]*\}$/i.test(t.trim())&&(t=t.trim().replace(/^\\ce\{([\s\S]*)\}$/i,"$1")):t.trim()&&!t.trim().startsWith("\\ce{")&&!t.includes("\\ce{")&&(t=`\\ce{${t}}`)),this.onInsert(t),this.close()}insertAtCursor(t){if(this.closeAllPopups(),!this.mathField)return;const e=this.mathField;if(e.smartSuperscript=!1,e.focus(),typeof t=="string"){const r=D(t,this.activeStyles.bold,this.activeStyles.italic,this.activeStyles.fontFamily);e.executeCommand?e.executeCommand(["insert",r,{selectionMode:"placeholder"}]):e.insert(r)}else if(t&&t.insert){const r=t.action==="INSERT_CUSTOM"||t.directInsert?D(t.insert,this.activeStyles.bold,this.activeStyles.italic,this.activeStyles.fontFamily):t.insert;e.executeCommand?e.executeCommand(["insert",r,{selectionMode:"placeholder"}]):e.insert(r)}this.scrollToCaret()}getInsertStyle(){const t={};return this.activeStyles.bold&&this.activeStyles.italic?(t.variant="main",t.variantStyle="bolditalic"):this.activeStyles.bold?(t.variant="normal",t.variantStyle="bold"):this.activeStyles.italic&&(t.variant="main",t.variantStyle="italic"),this.activeStyles.fontFamily&&this.activeStyles.fontFamily!=="none"&&(t.fontFamily=this.activeStyles.fontFamily),this.activeStyles.color&&this.activeStyles.color!=="none"&&(t.color=this.activeStyles.color),t}isAllSelected(t){if(!t||t.selectionIsCollapsed)return!1;try{const e=t.model,r=(e==null?void 0:e.selection)||t.selection;if(r){const s=r.ranges||(Array.isArray(r)?[r]:[]);if(s.length>0){let a=1/0,l=-1/0;for(const h of s)Array.isArray(h)&&(a=Math.min(a,h[0],h[1]),l=Math.max(l,h[0],h[1]));const n=(e==null?void 0:e.lastOffset)||1;if(a<=1&&l>=n)return!0}}}catch{}return!1}getSelectionLatex(t){if(!t)return"";try{if(this.isAllSelected(t))return t.getValue()||t.value||"";if(t.selection){const e=t.getValue(t.selection);if(typeof e=="string")return e}}catch{}try{if(t.model&&t.model.selection){const e=t.getValue(t.model.selection);if(typeof e=="string")return e}}catch{}try{const e=t.getValue("latex-selection");if(typeof e=="string")return e}catch{}return""}checkSelectionBold(t){if(!t)return!1;if(!t.selectionIsCollapsed){const e=this.getSelectionLatex(t);if(e&&e.trim()&&/\\mathbfit\{|\\mathbf\{|\\boldsymbol\{|\\textbf\{|\\bold\{|\\bm\{|\\pmb\{/.test(e.trim()))return!0}try{if(typeof t.queryStyle=="function"){const e=t.queryStyle({variantStyle:"bold"}),r=t.queryStyle({variantStyle:"bolditalic"}),s=t.queryStyle({fontSeries:"b"});if(e==="all"||e==="some"||r==="all"||r==="some"||s==="all"||s==="some")return!0}}catch{}try{const e=t.model;if(e&&!t.selectionIsCollapsed&&(e.selection||t.selection)){const r=e.selection||t.selection,s=e.getAtoms(r,{includeChildren:!0});if(s&&s.length>0&&s.some(l=>{if(!l||l.type==="first")return!1;const n=l.style;return n?n.variantStyle==="bold"||n.variantStyle==="bolditalic"||n.fontSeries==="b"||n.variant==="bold":!1}))return!0}}catch{}return!1}checkSelectionItalic(t){if(!t)return!1;if(!t.selectionIsCollapsed){const e=this.getSelectionLatex(t);if(e&&e.trim()&&/\\mathbfit\{|\\mathit\{|\\textit\{|\\textsl\{|\\slshape\{/.test(e.trim()))return!0}try{if(typeof t.queryStyle=="function"){const e=t.queryStyle({variantStyle:"italic"}),r=t.queryStyle({variantStyle:"bolditalic"}),s=t.queryStyle({fontShape:"it"});if(e==="all"||e==="some"||r==="all"||r==="some"||s==="all"||s==="some")return!0}}catch{}try{const e=t.model;if(e&&!t.selectionIsCollapsed&&(e.selection||t.selection)){const r=e.selection||t.selection,s=e.getAtoms(r,{includeChildren:!0});if(s&&s.length>0&&s.some(l=>{if(!l||l.type==="first")return!1;const n=l.style;return n?n.variantStyle==="italic"||n.variantStyle==="bolditalic"||n.fontShape==="it":!1}))return!0}}catch{}return!1}updateStylesFromSelection(){const t=this.mathField;if(t)if(t.selectionIsCollapsed){if(this.explicitToggle)return;let e=!1;this.activeStyles.bold&&(this.activeStyles.bold=!1,e=!0),this.activeStyles.italic&&(this.activeStyles.italic=!1,e=!0),e&&this.renderToolbarItems()}else{this.explicitToggle=!1;const e=this.checkSelectionBold(t),r=this.checkSelectionItalic(t);let s=!1;this.activeStyles.bold!==e&&(this.activeStyles.bold=e,s=!0),this.activeStyles.italic!==r&&(this.activeStyles.italic=r,s=!0),s&&this.renderToolbarItems()}}render(){this.popup=document.createElement("div"),this.popup.className="cme-editor-popup"+(this.isMaximized?" maximized":"")+(this.isMinimized?" minimized":""),this.popup.addEventListener("mousedown",i=>{this.handleDocumentClick(i),i.stopPropagation()}),this.popup.addEventListener("pointerdown",i=>{this.handleDocumentClick(i)});const t=document.createElement("div");t.className="cme-popup-topbar";const e=document.createElement("div");e.className="cme-popup-header",e.style.cursor="grab";const r=this.title||(this.isEditing?this.mode==="chem"?"Edit Chemistry Formula":"Edit Math Formula":this.mode==="chem"?"Chemistry Editor":"Math Editor");e.innerHTML=`<span>${r}</span>`;const s=(i,b,g)=>{g&&g.closest&&g.closest(".cme-popup-btn")||(this.closeAllPopups(),this.specCharModal&&this.specCharModal.close(),this.isDragging=!0,this.dragStart={x:i-this.position.x,y:b-this.position.y},e.style.cursor="grabbing")};e.addEventListener("mousedown",i=>{s(i.clientX,i.clientY,i.target)}),e.addEventListener("touchstart",i=>{i.touches&&i.touches.length>0&&s(i.touches[0].clientX,i.touches[0].clientY,i.target)},{passive:!0});const a=document.createElement("div");a.className="cme-popup-controls";const l=document.createElement("button");l.type="button",l.className="cme-popup-btn",l.textContent="—",l.title="Minimize",l.addEventListener("click",()=>this.toggleMinimize());const n=document.createElement("button");n.type="button",n.className="cme-popup-btn",n.textContent="⤢",n.title="Maximize",n.addEventListener("click",()=>this.toggleMaximize()),this.minBtn=l,this.maxBtn=n;const h=document.createElement("button");h.type="button",h.className="cme-popup-btn",h.textContent="✕",h.title="Close",h.addEventListener("click",()=>this.close()),a.appendChild(l),a.appendChild(n),a.appendChild(h),t.appendChild(e),t.appendChild(a),this.popup.appendChild(t);const c=document.createElement("div");c.className="cme-toolbar",c.setAttribute("role","toolbar"),c.setAttribute("aria-label","Symbol palette"),this.tabsWrapper=document.createElement("div"),this.tabsWrapper.className="cme-toolbar-groups",this.renderTabs(),c.appendChild(this.tabsWrapper),this.itemsWrapper=document.createElement("div"),this.itemsWrapper.className="cme-toolbar-items",this.renderToolbarItems(),c.appendChild(this.itemsWrapper),this.popup.appendChild(c);const d=document.createElement("div");d.className="cme-mathfield-container",this.mathFieldContainer=d,d.addEventListener("mousedown",i=>{var b,g;this.explicitToggle=!1,this.closeAllPopups(),!(this.mathField&&(i.target===this.mathField||this.mathField.contains(i.target)))&&(i.preventDefault(),(g=(b=this.mathField)==null?void 0:b.focus)==null||g.call(b))}),this.mathField=document.createElement("math-field"),this.mathField.className="cme-mathfield",this.mathField.setAttribute("tabindex","0"),this.mathField.setAttribute("math-virtual-keyboard-policy","manual"),this.mathField.setAttribute("smart-superscript","false"),this.mathField.smartSuperscript=!1,this.mathField.setAttribute("math-mode-space","\\enspace"),this.mathField.mathModeSpace="\\enspace",this.mathField.onInsertStyle=()=>this.getInsertStyle(),this.mathField.addEventListener("keydown",i=>{if(i.key==="Enter"&&!i.ctrlKey&&!i.metaKey&&!i.altKey){i.preventDefault(),i.stopPropagation(),i.stopImmediatePropagation(),this.activeStyles.bold||this.activeStyles.italic||this.activeStyles.fontFamily&&this.activeStyles.fontFamily!=="none"?this.explicitToggle=!0:this.explicitToggle=!1;const p=this.mathField;p!=null&&p.executeCommand&&p.executeCommand("addRowAfter"),this.scrollToCaret();return}if(i.key===" "||i.code==="Space"){i.preventDefault(),i.stopPropagation(),i.stopImmediatePropagation();const p=this.mathField;p.executeCommand?p.executeCommand(["insert","\\enspace ",{selectionMode:"after"}]):p.insert&&p.insert("\\enspace "),this.scrollToCaret();return}if(i.key==="ArrowLeft"||i.key==="ArrowRight"||i.key==="ArrowUp"||i.key==="ArrowDown"||i.key==="Home"||i.key==="End"){this.explicitToggle=!1,this.scrollToCaret();return}if(!this.activeStyles.bold&&!this.activeStyles.italic&&this.activeStyles.fontFamily==="none"||i.key.length!==1||i.ctrlKey||i.metaKey||i.altKey)return;i.preventDefault(),i.stopPropagation(),i.stopImmediatePropagation();const b=D(i.key,this.activeStyles.bold,this.activeStyles.italic,this.activeStyles.fontFamily),g=this.mathField;g.executeCommand?g.executeCommand(["insert",b,{selectionMode:"after"}]):g.insert&&g.insert(b),this.scrollToCaret()},{capture:!0});const w=()=>{this.updateStylesFromSelection(),this.scrollToCaret()};this.mathField.addEventListener("input",()=>this.scrollToCaret()),this.mathField.addEventListener("selection-change",w),this.mathField.addEventListener("pointerup",w),this.mathField.addEventListener("keyup",w),this.mathField.addEventListener("pointerdown",()=>{this.explicitToggle=!1,this.closeAllPopups()}),this.mathField.addEventListener("focus",()=>{this.closeAllPopups(),this.scrollToCaret()}),d.appendChild(this.mathField),this.popup.appendChild(d);const y=document.createElement("div");y.className="cme-popup-footer";const f=document.createElement("button");f.type="button",f.className="cme-insert-btn",f.textContent=this.isEditing?"Update":"Insert",f.addEventListener("click",()=>this.handleInsert());const k=document.createElement("button");k.type="button",k.className="cme-cancel-btn",k.textContent="Cancel",k.addEventListener("click",()=>this.close()),y.appendChild(f),y.appendChild(k);const u=`v${A.version}`;if(u){const i=document.createElement("span");i.className="cme-popup-version",i.textContent=u,i.title=`Version ${A.version}`,y.appendChild(i)}this.popup.appendChild(y),document.body.appendChild(this.popup),setTimeout(()=>{if(this.mathField){W();try{this.mathField.smartSuperscript=!1,this.mathField.inlineShortcuts=Object.assign({},this.mathField.inlineShortcuts||{},{"*":"*"}),typeof this.mathField.setOptions=="function"&&this.mathField.setOptions({smartSuperscript:!1,mathModeSpace:"\\enspace",onInsertStyle:()=>this.getInsertStyle(),macros:{...window.__cme_macros||{},...B}}),this.mathField.menuItems&&Array.isArray(this.mathField.menuItems)&&(this.mathField.menuItems=this.mathField.menuItems.filter(b=>b&&b.id!=="insert-matrix"&&b.submenuClass!=="insert-matrix-submenu"))}catch{}let i=this.initialLatex||"";this.mode==="chem"&&i.startsWith("\\ce{")&&i.endsWith("}")&&(i=i.slice(4,-1)),this.mode==="chem"&&(i=i.replace(/~/g,"\\enspace ")),this.setValue(i),this.mathField.focus(),this.scrollToCaret()}},50)}clampPosition(t=this.position.x,e=this.position.y){if(!this.popup)return{x:t,y:e};const r=this.popup.getBoundingClientRect(),s=r.left-this.position.x,a=r.top-this.position.y,l=r.width,n=r.height,h=window.innerWidth,c=window.innerHeight;let d=-s,w=h-s-l,y=t;d>w?y=d:y=Math.max(d,Math.min(t,w));let f=-a,k=c-a-n,u=e;return f>k?u=f:u=Math.max(f,Math.min(e,k)),{x:y,y:u}}handleMouseMove(t){if(!this.isDragging||!this.popup)return;this.closeAllPopups(),this.specCharModal&&this.specCharModal.close();const e=t.clientX-this.dragStart.x,r=t.clientY-this.dragStart.y;this.position=this.clampPosition(e,r),this.popup.style.transform=`translate(${this.position.x}px, ${this.position.y}px)`}handleTouchMove(t){!this.isDragging||!t.touches||t.touches.length===0||(t.cancelable&&t.preventDefault(),this.handleMouseMove(t.touches[0]))}handleWindowResize(){if(!this.popup)return;const t=this.clampPosition(this.position.x,this.position.y);(t.x!==this.position.x||t.y!==this.position.y)&&(this.position=t,this.popup.style.transform=`translate(${this.position.x}px, ${this.position.y}px)`)}handleMouseUp(){var e;this.isDragging=!1;const t=(e=this.popup)==null?void 0:e.querySelector(".cme-popup-header");t&&(t.style.cursor="grab")}updateControlButtons(){this.maxBtn&&(this.maxBtn.textContent=this.isMaximized?"⤡":"⤢",this.maxBtn.title=this.isMaximized?"Restore":"Maximize"),this.minBtn&&(this.minBtn.title=this.isMinimized?"Restore":"Minimize")}toggleMaximize(){var t,e;this.isMaximized=!this.isMaximized,this.isMaximized&&(this.isMinimized=!1,(t=this.popup)==null||t.classList.remove("minimized")),(e=this.popup)==null||e.classList.toggle("maximized",this.isMaximized),this.position={x:0,y:0},this.popup&&(this.popup.style.transform="translate(0px, 0px)"),this.updateControlButtons()}toggleMinimize(){var t,e;this.isMinimized=!this.isMinimized,this.isMinimized&&(this.isMaximized=!1,(t=this.popup)==null||t.classList.remove("maximized")),(e=this.popup)==null||e.classList.toggle("minimized",this.isMinimized),this.position={x:0,y:0},this.popup&&(this.popup.style.transform="translate(0px, 0px)"),this.updateControlButtons()}renderTabs(){if(!this.tabsWrapper)return;this.tabsWrapper.innerHTML="",this.getGroups().forEach((e,r)=>{const s=this.activeGroup===r,a=document.createElement("button");if(a.type="button",a.className="cme-group-tab"+(s?" active":""),e.mathLabel){const l=document.createElement("math-field");l.setAttribute("read-only","true"),l.setAttribute("tabindex","-1"),l.style.pointerEvents="none",l.style.background="transparent",l.style.border="none",l.style.outline="none",l.style.fontSize=e.fontSize||(e.isMatrix?"8px":"11px"),l.style.display="inline-block",l.style.width="auto",l.style.padding="0",l.style.margin="0",l.style.boxShadow="none",l.style.color=s?"#333333":"#ffffff",l.textContent=e.mathLabel,a.appendChild(l)}else typeof e.label=="string"&&e.label.includes("<svg")?a.innerHTML=e.label:a.textContent=e.label;a.addEventListener("mousedown",l=>{l.preventDefault(),this.activeGroup=r,this.closeAllPopups(),this.renderTabs(),this.renderToolbarItems()}),this.tabsWrapper.appendChild(a)})}renderToolbarItems(){if(!this.itemsWrapper)return;this.itemsWrapper.innerHTML="";const e=this.getGroups()[this.activeGroup]||{items:[]},r=e.items||[],s=r.some(l=>l.type==="sep"),a=[];if(s){let l={cols:2,small:!1,cls:"",items:[],moreItems:null,moreCols:1};for(const n of r)n.type==="sep"?(l.items.length>0&&a.push(l),l={cols:n.cols||2,small:!!n.small,cls:n.cls||"",items:[],moreItems:n.moreItems||null,moreCols:n.moreCols||1}):l.items.push(n);l.items.length>0&&a.push(l)}else for(let n=0;n<r.length;n+=4)a.push({cols:2,small:!1,cls:"",items:r.slice(n,n+4)});a.forEach(l=>{const n=document.createElement("div");if(n.className="cme-symbol-subgroup"+(l.small?" cme-symbol-subgroup--small":"")+(l.cls?` ${l.cls}`:"")+(l.moreItems?" cme-subgroup-has-more":""),n.style.gridTemplateColumns=`repeat(${l.cols}, auto)`,n.style.position="relative",l.moreItems){const h=document.createElement("button");h.type="button",h.className="cme-more-trigger-btn",h.title="More",h.textContent="▶",h.addEventListener("mousedown",c=>c.preventDefault()),h.addEventListener("click",c=>{if(c.stopPropagation(),this.activeDropdown&&this.activeDropdownBtn===h)this.closeDropdown();else{const d=h.getBoundingClientRect();this.openDropdown(l.moreItems,d,l.moreCols||4,h)}}),n.appendChild(h)}l.items.forEach(h=>{if(h.type==="dropdown"){const u=h.label==="Font...",i=h.label==="Size",b=document.createElement("select");b.className="cme-select"+(u?" cme-select-font":"")+(i?" cme-select-size":"")+(u&&this.activeStyles.fontFamily!=="none"||i&&this.activeStyles.fontSize!=="auto"?" active":""),u?([{id:"none",label:"Font..."},{id:"roman",label:"Roman"},{id:"sans-serif",label:"Sans-Serif"},{id:"monospace",label:"Monospace"}].forEach(g=>{const p=document.createElement("option");p.value=g.id,p.textContent=g.label,b.appendChild(p)}),b.value=this.activeStyles.fontFamily,b.addEventListener("change",g=>{var p;this.activeStyles.fontFamily=g.target.value,(p=this.mathField)!=null&&p.applyStyle&&this.mathField.applyStyle({fontFamily:this.activeStyles.fontFamily==="none"?"none":this.activeStyles.fontFamily}),this.renderToolbarItems()})):i&&([{id:"auto",label:"Size"},{id:"1",label:"Tiny"},{id:"3",label:"Small"},{id:"5",label:"Normal"},{id:"7",label:"Large"},{id:"9",label:"Huge"}].forEach(g=>{const p=document.createElement("option");p.value=g.id,p.textContent=g.label,b.appendChild(p)}),b.value=this.activeStyles.fontSize,b.addEventListener("change",g=>{var p;if(this.activeStyles.fontSize=g.target.value,(p=this.mathField)!=null&&p.applyStyle){const S=this.activeStyles.fontSize==="auto"?"none":parseInt(this.activeStyles.fontSize,10);this.mathField.applyStyle({fontSize:S})}this.renderToolbarItems()})),n.appendChild(b);return}const c=h.action==="BOLD",d=h.action==="ITALIC",w=h.action==="TEXT_COLOR",y=h.action==="SPECIAL_CHARS",f=c&&this.activeStyles.bold||d&&this.activeStyles.italic||w&&this.activeStyles.color!=="none",k=document.createElement("button");k.type="button",k.className="cme-btn"+(e.isTemplate?" template":"")+(h.cls?` ${h.cls}`:"")+(f?" active":""),k.title=h.title||h.label||h.insert||"",typeof h.label=="string"&&(h.label.includes("<svg")||h.label.includes("<img")||h.label.includes("<strong")||h.label.includes("<em"))?k.innerHTML=h.label:typeof h.label=="string"&&(k.textContent=h.label),k.addEventListener("mousedown",u=>{var b,g,p,S,m,T,E,M,L,H;u.preventDefault();const i=this.mathField;if(y){this.closeAllPopups();const C=k.getBoundingClientRect();this.openSpecialCharacters(C)}else if(w)if(this.colorPickerPopup&&this.activeColorBtn===k)this.closeColorPicker();else{const C=k.getBoundingClientRect();this.openColorPicker(C,k)}else if(c){if(this.closeAllPopups(),this.explicitToggle=!0,this.activeStyles.bold=!this.activeStyles.bold,i){if(i.selectionIsCollapsed)this.activeStyles.bold||(i.styleBias="none",i.defaultStyle&&(delete i.defaultStyle.variantStyle,delete i.defaultStyle.fontSeries));else{const C=this.getSelectionLatex(i);if(C&&C.trim()){const q=j(C.trim()),I=D(q,this.activeStyles.bold,this.activeStyles.italic,this.activeStyles.fontFamily);if(this.activeStyles.bold||(i.styleBias="none",i.defaultStyle&&(delete i.defaultStyle.variantStyle,delete i.defaultStyle.fontSeries)),this.isAllSelected(i)?(i.setValue(I),i.executeCommand?i.executeCommand("selectAll"):(b=i.model)!=null&&b.setSelection&&i.model.setSelection(0,i.model.lastOffset)):i.executeCommand?i.executeCommand(["insert",I,{selectionMode:"item"}]):i.insert&&i.insert(I,{selectionMode:"item"}),!this.activeStyles.bold&&i.applyStyle)try{i.applyStyle({variantStyle:this.activeStyles.italic?"italic":"",fontSeries:"auto"},{operation:"set"})}catch{}}}i.focus()}this.renderToolbarItems()}else if(d){if(this.closeAllPopups(),this.explicitToggle=!0,this.activeStyles.italic=!this.activeStyles.italic,i){if(i.selectionIsCollapsed)this.activeStyles.italic||(i.styleBias="none",i.defaultStyle&&(delete i.defaultStyle.variantStyle,delete i.defaultStyle.fontShape));else{const C=this.getSelectionLatex(i);if(C&&C.trim()){const q=j(C.trim()),I=D(q,this.activeStyles.bold,this.activeStyles.italic,this.activeStyles.fontFamily);if(this.activeStyles.italic||(i.styleBias="none",i.defaultStyle&&(delete i.defaultStyle.variantStyle,delete i.defaultStyle.fontShape)),this.isAllSelected(i)?(i.setValue(I),i.executeCommand?i.executeCommand("selectAll"):(g=i.model)!=null&&g.setSelection&&i.model.setSelection(0,i.model.lastOffset)):i.executeCommand?i.executeCommand(["insert",I,{selectionMode:"item"}]):i.insert&&i.insert(I,{selectionMode:"item"}),!this.activeStyles.italic&&i.applyStyle)try{i.applyStyle({variantStyle:this.activeStyles.bold?"bold":"",fontShape:"auto"},{operation:"set"})}catch{}}}i.focus()}this.renderToolbarItems()}else if(h.action==="UNDO")this.closeAllPopups(),(p=i==null?void 0:i.executeCommand)==null||p.call(i,"undo");else if(h.action==="REDO")this.closeAllPopups(),(S=i==null?void 0:i.executeCommand)==null||S.call(i,"redo");else if(h.action==="CUT")this.closeAllPopups(),(m=i==null?void 0:i.focus)==null||m.call(i),(T=i==null?void 0:i.executeCommand)==null||T.call(i,"cutToClipboard");else if(h.action==="COPY")this.closeAllPopups(),(E=i==null?void 0:i.focus)==null||E.call(i),(M=i==null?void 0:i.executeCommand)==null||M.call(i,"copyToClipboard");else if(h.action==="PASTE")this.closeAllPopups(),(L=i==null?void 0:i.focus)==null||L.call(i),(H=i==null?void 0:i.executeCommand)==null||H.call(i,"pasteFromClipboard");else if(h.action==="MATRIX_HOVER")if(this.activeMatrixPopup&&this.activeMatrixBtn===k)this.closeMatrixPopup();else{const C=k.getBoundingClientRect();this.openMatrixGrid(h.matrixType||"matrix",C,k)}else this.insertAtCursor(h)}),n.appendChild(k)}),this.itemsWrapper.appendChild(n)})}openDropdown(t,e,r,s=null){this.closeAllPopups(),this.activeDropdownBtn=s,this.activeDropdown=document.createElement("div"),this.activeDropdown.className="cme-more-popup",this.activeDropdown.style.gridTemplateColumns=`repeat(${r}, auto)`,this.activeDropdown.style.left=`${e.left+e.width/2}px`,this.activeDropdown.style.top=`${e.bottom+4}px`,this.activeDropdown.style.transform="translateX(-50%)",this.activeDropdown.addEventListener("mousedown",a=>a.stopPropagation()),this.activeDropdown.addEventListener("pointerdown",a=>a.stopPropagation()),t.forEach(a=>{const l=document.createElement("button");l.type="button",l.className="cme-more-popup-btn "+(a.cls||""),l.title=a.title||a.label||a.insert||"",typeof a.label=="string"&&(a.label.includes("<svg")||a.label.includes("<img"))?l.innerHTML=a.label:l.textContent=a.label,l.addEventListener("mousedown",n=>{n.preventDefault(),this.insertAtCursor(a.insert||a),this.closeDropdown()}),this.activeDropdown.appendChild(l)}),document.body.appendChild(this.activeDropdown)}closeDropdown(){this.activeDropdown&&this.activeDropdown.parentNode&&this.activeDropdown.parentNode.removeChild(this.activeDropdown),this.activeDropdown=null,this.activeDropdownBtn=null}openMatrixGrid(t,e,r=null){this.closeAllPopups(),this.activeMatrixBtn=r,this.activeMatrixPopup=document.createElement("div"),this.activeMatrixPopup.className="cme-matrix-hover-popover ck-only",this.activeMatrixPopup.style.left=`${e.left+e.width/2}px`,this.activeMatrixPopup.style.top=`${e.bottom+6}px`,this.activeMatrixPopup.style.minHeight="auto",this.activeMatrixPopup.addEventListener("mousedown",m=>m.stopPropagation()),this.activeMatrixPopup.addEventListener("pointerdown",m=>m.stopPropagation());const s=document.createElement("div");s.className="cme-matrix-hover-title",s.textContent=t==="matrix"?"MATRIX":`${t.toUpperCase()} MATRIX`;const a=document.createElement("div");a.className="cme-matrix-hover-grid",a.style.flex="none";let l=2,n=2;const h=document.createElement("div");h.className="cme-matrix-hover-footer";const c=document.createElement("div");c.className="cme-matrix-counter";const d=document.createElement("input");d.type="number",d.className="cme-counter-val",d.min="1",d.max="10",d.value=l;const w=document.createElement("div");w.className="cme-counter-btns";const y=document.createElement("button");y.type="button",y.textContent="▲";const f=document.createElement("button");f.type="button",f.textContent="▼",w.appendChild(y),w.appendChild(f);const k=document.createElement("span");k.textContent="×";const u=document.createElement("input");u.type="number",u.className="cme-counter-val",u.min="1",u.max="10",u.value=n;const i=document.createElement("div");i.className="cme-counter-btns";const b=document.createElement("button");b.type="button",b.textContent="▲";const g=document.createElement("button");g.type="button",g.textContent="▼",i.appendChild(b),i.appendChild(g),c.appendChild(d),c.appendChild(w),c.appendChild(k),c.appendChild(u),c.appendChild(i);const p=document.createElement("button");p.type="button",p.className="cme-matrix-insert-btn",p.textContent="INSERT",h.appendChild(c),h.appendChild(p);const S=(m,T)=>{l=Math.max(1,Math.min(10,m)),n=Math.max(1,Math.min(10,T)),d.value=l,u.value=n,a.querySelectorAll(".cme-matrix-hover-cell").forEach(M=>{const L=parseInt(M.dataset.row,10),H=parseInt(M.dataset.col,10);L<=l&&H<=n?M.classList.add("selected"):M.classList.remove("selected")})};for(let m=1;m<=5;m++){const T=document.createElement("div");T.className="cme-matrix-hover-row";for(let E=1;E<=10;E++){const M=document.createElement("div");M.className="cme-matrix-hover-cell"+(m<=l&&E<=n?" selected":""),M.dataset.row=m,M.dataset.col=E,M.addEventListener("mouseenter",()=>{S(m,E)}),M.addEventListener("click",L=>{L.stopPropagation(),this.insertMatrix(t,m,E),this.closeMatrixPopup()}),T.appendChild(M)}a.appendChild(T)}d.addEventListener("input",()=>{const m=parseInt(d.value,10)||1;S(m,n)}),u.addEventListener("input",()=>{const m=parseInt(u.value,10)||1;S(l,m)}),y.addEventListener("click",m=>{m.preventDefault(),m.stopPropagation(),S(l+1,n)}),f.addEventListener("click",m=>{m.preventDefault(),m.stopPropagation(),S(l-1,n)}),b.addEventListener("click",m=>{m.preventDefault(),m.stopPropagation(),S(l,n+1)}),g.addEventListener("click",m=>{m.preventDefault(),m.stopPropagation(),S(l,n-1)}),p.addEventListener("click",m=>{m.stopPropagation(),this.insertMatrix(t,l,n),this.closeMatrixPopup()}),this.activeMatrixPopup.appendChild(s),this.activeMatrixPopup.appendChild(a),this.activeMatrixPopup.appendChild(h),document.body.appendChild(this.activeMatrixPopup)}insertMatrix(t,e,r){let s=[];for(let n=0;n<e;n++){let h=[];for(let c=0;c<r;c++)h.push("{#?}");s.push(h.join(" & "))}const a=t||"matrix",l=`\\begin{${a}}${s.join(" \\\\ ")}\\end{${a}}`;this.insertAtCursor(l)}closeMatrixPopup(){this.activeMatrixPopup&&this.activeMatrixPopup.parentNode&&this.activeMatrixPopup.parentNode.removeChild(this.activeMatrixPopup),this.activeMatrixPopup=null,this.activeMatrixBtn=null}openColorPicker(t,e=null){this.closeAllPopups(),this.activeColorBtn=e,this.colorPickerPopup=document.createElement("div"),this.colorPickerPopup.className="cme-more-popup",this.colorPickerPopup.style.gridTemplateColumns="repeat(4, auto)",this.colorPickerPopup.style.left=`${t.left+t.width/2}px`,this.colorPickerPopup.style.top=`${t.bottom+4}px`,this.colorPickerPopup.style.transform="translateX(-50%)",this.colorPickerPopup.addEventListener("mousedown",s=>s.stopPropagation()),this.colorPickerPopup.addEventListener("pointerdown",s=>s.stopPropagation()),["black","#e53935","#1e88e5","#43a047","#fb8c00","#8e24aa","#3949ab","#00acc1"].forEach(s=>{const a=document.createElement("div");a.style.width="18px",a.style.height="18px",a.style.borderRadius="50%",a.style.margin="4px",a.style.cursor="pointer",a.style.backgroundColor=s,a.style.border=this.activeStyles.color===s?"2px solid #222":"1px solid #ddd",a.addEventListener("mousedown",l=>{var n;l.preventDefault(),this.activeStyles.color=s,(n=this.mathField)!=null&&n.applyStyle&&this.mathField.applyStyle({color:s==="black"?"none":s}),this.closeColorPicker(),this.renderToolbarItems()}),this.colorPickerPopup.appendChild(a)}),document.body.appendChild(this.colorPickerPopup)}closeColorPicker(){this.colorPickerPopup&&this.colorPickerPopup.parentNode&&this.colorPickerPopup.parentNode.removeChild(this.colorPickerPopup),this.colorPickerPopup=null,this.activeColorBtn=null}openSpecialCharacters(t){this.specCharModal||(this.specCharModal=new Y({onInsert:e=>{this.insertAtCursor(e)}})),this.specCharModal.open({x:t.left,y:t.bottom+6})}closeAllPopups(){this.closeDropdown(),this.closeMatrixPopup(),this.closeColorPicker()}destroy(){this.close()}};_(O,"VERSION",A==null?void 0:A.version);let R=O,P=null;function ct(){return P||(P=new R),P}class F{constructor(t={}){this.container=t.container||null,this.latex=t.latex||"",this.editable=t.editable!==!1,this.mode=t.mode||"math",this.onUpdate=t.onUpdate||(()=>{}),this.editor=t.editor||ct(),this.element=null,this.mathField=null,this.container&&this.mount(this.container)}mount(t){this.container=t,this.element=document.createElement("span"),this.element.className="digi-math-widget"+(this.editable?"":" readonly"),this.element.setAttribute("data-latex",this.latex),this.element.title=this.editable?"Click to edit formula":"",this.mathField=document.createElement("math-field"),this.mathField.setAttribute("read-only","true"),this.mathField.textContent=this.latex,this.element.appendChild(this.mathField),this.editable&&this.element.addEventListener("click",e=>{e.preventDefault(),e.stopPropagation(),this.openEditor()}),this.container.appendChild(this.element)}openEditor(){this.editor.open(this.latex,this.mode),this.editor.onInsert=t=>{this.setLatex(t),this.onUpdate(t)}}setLatex(t){if(this.latex=t||"",this.element&&this.element.setAttribute("data-latex",this.latex),this.mathField)try{typeof this.mathField.setValue=="function"?this.mathField.setValue(this.latex):this.mathField.textContent=this.latex}catch{this.mathField.textContent=this.latex}}getLatex(){return this.latex}destroy(){this.element&&this.element.parentNode&&this.element.parentNode.removeChild(this.element)}}function dt(o){return new F(o)}if(typeof customElements<"u"&&!customElements.get("digi-math-widget")){class o extends HTMLElement{static get observedAttributes(){return["latex","editable","mode"]}connectedCallback(){const e=this.getAttribute("latex")||"",r=this.getAttribute("editable")!=="false",s=this.getAttribute("mode")||"math";this.widget=new F({container:this,latex:e,editable:r,mode:s,onUpdate:a=>{this.setAttribute("latex",a),this.dispatchEvent(new CustomEvent("latexChange",{detail:{latex:a},bubbles:!0}))}})}attributeChangedCallback(e,r,s){r!==s&&e==="latex"&&this.widget&&this.widget.setLatex(s)}disconnectedCallback(){this.widget&&this.widget.destroy()}}customElements.define("digi-math-widget",o)}const mt=A==null?void 0:A.version;x.CME_SHADOW_DOM_CSS=K,x.DigiMathChemEditor=R,x.DigiMathWidget=F,x.SpecialCharacterModal=Y,x.VERSION=mt,x.createMathWidget=dt,x.default=R,x.initMathFieldCursorFix=W,x.scrollMathFieldCaretIntoView=U,Object.defineProperties(x,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|