@editora/math 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +62 -0
- package/dist/index.esm.js +492 -0
- package/package.json +1 -1
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function K(e){return String(e??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function G(e){let t=!1;e.addEventListener("pointerdown",r=>{t=r.target!==e},!0),e.addEventListener("click",r=>{r.target===e&&t&&r.stopImmediatePropagation(),t=!1},!0)}const H="rte-dialog-base-styles";function W(){if(typeof document>"u"||document.getElementById(H))return;const e=document.createElement("style");e.id=H,e.textContent=`
|
|
2
|
+
[data-rte-dialog] {
|
|
3
|
+
font-family: var(--rte-font-family-base, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/* Form controls ignore inherited fonts (browsers default them to Arial /
|
|
7
|
+
system-ui). :where() keeps this at zero specificity so any control a plugin
|
|
8
|
+
styles explicitly - e.g. a monospace formula field - keeps its own font. */
|
|
9
|
+
:where([data-rte-dialog]) :where(button, input, select, textarea) {
|
|
10
|
+
font-family: inherit;
|
|
11
|
+
}
|
|
12
|
+
`,document.head.appendChild(e)}function X(e){e.setAttribute("data-rte-dialog",""),W(),G(e)}const Z={latex:[{name:"Fraction",formula:"\\frac{a}{b}",description:"Simple fraction"},{name:"Square Root",formula:"\\sqrt{x}",description:"Square root"},{name:"Power",formula:"x^{2}",description:"Exponent/power"},{name:"Subscript",formula:"x_{sub}",description:"Subscript"},{name:"Integral",formula:"\\int_{a}^{b} f(x) \\, dx",description:"Definite integral"},{name:"Summation",formula:"\\sum_{i=1}^{n} x_{i}",description:"Summation"},{name:"Limit",formula:"\\lim_{x \\to 0} f(x)",description:"Limit"},{name:"Derivative",formula:"\\frac{d}{dx} f(x)",description:"Derivative"},{name:"Matrix 2x2",formula:"\\begin{pmatrix} a & b \\\\ c & d \\end{pmatrix}",description:"2x2 matrix"},{name:"System",formula:"\\begin{cases} x + y = 1 \\\\ 2x - y = 0 \\end{cases}",description:"System of equations"}],mathml:[{name:"Fraction",formula:"<mfrac><mi>a</mi><mi>b</mi></mfrac>",description:"Simple fraction"},{name:"Square Root",formula:"<msqrt><mi>x</mi></msqrt>",description:"Square root"},{name:"Power",formula:"<msup><mi>x</mi><mn>2</mn></msup>",description:"Exponent/power"},{name:"Subscript",formula:"<msub><mi>x</mi><mi>sub</mi></msub>",description:"Subscript"},{name:"Parentheses",formula:'<mfenced open="(" close=")"><mi>a</mi><mo>+</mo><mi>b</mi></mfenced>',description:"Grouped expression"}]};let S=null,$=null,_=!1,y=null,m=null;const k='[data-theme="dark"], .dark, .editora-theme-dark',Q=new Set(["math","mrow","mi","mn","mo","ms","mtext","mspace","msup","msub","msubsup","mfrac","msqrt","mroot","mfenced","mstyle","mpadded","mphantom","menclose","mtable","mtr","mtd","mlabeledtr","munder","mover","munderover","mmultiscripts","mprescripts","none","semantics","annotation"]),Y=new Set(["display","displaystyle","mathvariant","mathsize","mathcolor","mathbackground","scriptlevel","fence","separator","stretchy","symmetric","lspace","rspace","largeop","movablelimits","accent","accentunder","open","close","separators","linethickness","columnalign","rowalign","columnspacing","rowspacing","columnlines","rowlines","frame","notation","width","height","depth","voffset","minsize","maxsize","form","encoding","xmlns","dir","class","id"]),L=e=>{const t=new DOMParser().parseFromString(`<body>${e}</body>`,"text/html"),r=l=>{Array.from(l.childNodes).forEach(a=>{if(a.nodeType===Node.ELEMENT_NODE){const n=a;if(!Q.has(n.localName.toLowerCase())){n.remove();return}Array.from(n.attributes).forEach(c=>{Y.has(c.name.toLowerCase())||n.removeAttribute(c.name)}),r(n)}else a.nodeType!==Node.TEXT_NODE&&a.parentNode?.removeChild(a)})};return r(t.body),t.body.innerHTML},J=()=>new Promise((e,t)=>{if(window.katex){e(window.katex);return}if(_){const a=setInterval(()=>{window.katex&&(clearInterval(a),e(window.katex))},100);return}_=!0;const r=document.createElement("link");r.rel="stylesheet",r.href="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css",document.head.appendChild(r);const l=document.createElement("script");l.src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.js",l.onload=()=>e(window.katex),l.onerror=t,document.head.appendChild(l)}),I=()=>{const e=window.getSelection();if(!e||e.rangeCount===0)return null;const t=e.getRangeAt(0).startContainer;return(t.nodeType===Node.ELEMENT_NODE?t:t.parentElement)?.closest(".rte-content, .editora-content")||null},V=e=>e?e.nodeType===Node.ELEMENT_NODE?e:e.parentElement:null,z=e=>V(e)?.closest('.rte-content, .editora-content, [contenteditable="true"]')||null,ee=(e,t,r)=>{if(t!==r){if(typeof window.execEditorCommand=="function"){window.execEditorCommand("recordDomTransaction",e,t,r);return}if(typeof window.executeEditorCommand=="function")try{window.executeEditorCommand("recordDomTransaction",{editor:e,beforeHTML:t,afterHTML:r})}catch{}}},te=e=>{if(!(e instanceof Element))return null;const t=e.closest(".math-formula, .math-block");return t instanceof HTMLElement?t:null},h=()=>{m&&(m.classList.remove("math-object-selected"),m.removeAttribute("data-rte-selected-object"),m=null)},ne=e=>{if(m===e)return;h(),m=e,e.classList.add("math-object-selected"),e.setAttribute("data-rte-selected-object","true");const t=window.getSelection();if(!t)return;const r=document.createRange();r.selectNode(e),t.removeAllRanges(),t.addRange(r)},oe=(e,t)=>{const r=window.getSelection();if(!r)return;const l=document.createRange();t&&t.parentNode===e?l.setStartBefore(t):(l.selectNodeContents(e),l.collapse(!1)),l.collapse(!0),r.removeAllRanges(),r.addRange(l)},re=e=>{if(e.childNodes.length>0)return;const t=document.createElement("p");t.appendChild(document.createElement("br")),e.appendChild(t)},ae=()=>{if(!m||!m.isConnected)return h(),!1;const e=m,t=z(e);if(!t)return h(),!1;const r=t.innerHTML,l=e.nextSibling;e.remove(),re(t),h(),oe(t,l);const a=t.innerHTML;return ee(t,r,a),t.dispatchEvent(new window.Event("input",{bubbles:!0})),r!==a},ie=()=>{if(document.getElementById("math-object-selection-styles"))return;const e=document.createElement("style");e.id="math-object-selection-styles",e.textContent=`
|
|
13
|
+
.math-object-selected {
|
|
14
|
+
outline: 2px solid #2563eb !important;
|
|
15
|
+
outline-offset: 2px;
|
|
16
|
+
box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.18);
|
|
17
|
+
}
|
|
18
|
+
`,document.head.appendChild(e)},le=()=>{typeof window>"u"||window.__mathPluginObjectSelectionInitialized||(window.__mathPluginObjectSelectionInitialized=!0,ie(),document.addEventListener("pointerdown",e=>{const t=te(e.target);if(!t){e.target?.closest?.(".math-dialog-overlay")||h();return}e.preventDefault(),z(t)?.focus(),ne(t)},!0),document.addEventListener("keydown",e=>{if(m){if(e.key==="Escape"){h();return}e.key!=="Backspace"&&e.key!=="Delete"||(e.preventDefault(),e.stopPropagation(),ae())}},!0))},se=e=>{if((e||I())?.closest(k))return!0;const r=window.getSelection();if(r&&r.rangeCount>0){const a=r.getRangeAt(0).startContainer;if((a.nodeType===Node.ELEMENT_NODE?a:a.parentElement)?.closest(k))return!0}return document.activeElement?.closest(k)?!0:document.body.matches(k)||document.documentElement.matches(k)},R=async(e,t)=>{document.querySelectorAll(".math-dialog-overlay").forEach(o=>o.remove());const r=t||$?.closest(".rte-content, .editora-content")||I()||y;y=r||null;const l=window.getSelection();if(l&&l.rangeCount>0){const o=l.getRangeAt(0);S=r&&r.contains(o.commonAncestorContainer)?o.cloneRange():null}await J();const a=se(r),n=a?{overlay:"rgba(0, 0, 0, 0.62)",dialogBg:"#1f2937",border:"#3b4657",panelBg:"#222d3a",fieldBg:"#111827",fieldBorder:"#4b5563",text:"#e2e8f0",muted:"#94a3b8",templateBtnBg:"#273244",templateBtnHover:"#334155",templateBtnText:"#dbe7f7",templateSubText:"#9fb0c6",previewBg:"#111827",previewText:"#cbd5e1",cancelBg:"#334155",cancelText:"#e2e8f0",cancelBorder:"#4b5563",insertBg:"#3b82f6",insertHover:"#2563eb",invalid:"#f87171"}:{overlay:"rgba(0, 0, 0, 0.5)",dialogBg:"#ffffff",border:"#e1e5e9",panelBg:"#f8f9fa",fieldBg:"#ffffff",fieldBorder:"#ced4da",text:"#1f2937",muted:"#6c757d",templateBtnBg:"#ffffff",templateBtnHover:"#f8f9fa",templateBtnText:"#1f2937",templateSubText:"#6c757d",previewBg:"#f8f9fa",previewText:"#6c757d",cancelBg:"#ffffff",cancelText:"#1f2937",cancelBorder:"#ced4da",insertBg:"#007bff",insertHover:"#0069d9",invalid:"#cc0000"},c=document.createElement("div");X(c),c.className="math-dialog-overlay",c.style.cssText=`position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: ${n.overlay}; display: flex; align-items: center; justify-content: center; z-index: 99999;`;const d=document.createElement("div");d.style.cssText=`background: ${n.dialogBg}; border: 1px solid ${n.border}; border-radius: 8px; width: 90%; max-width: 600px; max-height: 90vh; overflow: hidden; display: flex; flex-direction: column; box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2); color: ${n.text};`;let u=e?.format||"latex",B=e?.formula||"";const j=e?.inline!==!1;let b=null,C="";d.innerHTML=`
|
|
19
|
+
<div style="display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid ${n.border}; background: ${n.panelBg};">
|
|
20
|
+
<h2 style="margin: 0; font-size: 18px; font-weight: 600; color: ${n.text};">${e?"Edit":"Insert"} Math Formula</h2>
|
|
21
|
+
<button class="close-btn" style="background: none; border: none; font-size: 28px; cursor: pointer; color: ${n.muted}; padding: 0; width: 30px; height: 30px; line-height: 1;">×</button>
|
|
22
|
+
</div>
|
|
23
|
+
|
|
24
|
+
<div style="padding: 20px; overflow-y: auto; flex: 1;">
|
|
25
|
+
<div style="margin-bottom: 20px;">
|
|
26
|
+
<label style="display: block; font-weight: 600; margin-bottom: 8px; font-size: 14px; color: ${n.text};">Format:</label>
|
|
27
|
+
<div style="display: flex; gap: 16px;">
|
|
28
|
+
<label style="cursor: pointer; color: ${n.text};"><input type="radio" name="format" value="latex" ${u==="latex"?"checked":""} style="margin-right: 6px;"> LaTeX</label>
|
|
29
|
+
<label style="cursor: pointer; color: ${n.text};"><input type="radio" name="format" value="mathml" ${u==="mathml"?"checked":""} style="margin-right: 6px;"> MathML</label>
|
|
30
|
+
</div>
|
|
31
|
+
</div>
|
|
32
|
+
|
|
33
|
+
<div style="margin-bottom: 20px;">
|
|
34
|
+
<label style="display: block; font-weight: 600; margin-bottom: 8px; font-size: 14px; color: ${n.text};">Quick Templates:</label>
|
|
35
|
+
<div id="templates-grid" style="display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; max-height: 200px; overflow-y: auto;"></div>
|
|
36
|
+
</div>
|
|
37
|
+
|
|
38
|
+
<div style="margin-bottom: 20px;">
|
|
39
|
+
<label style="cursor: pointer; color: ${n.text};"><input type="checkbox" id="inline-cb" ${j?"checked":""} style="margin-right: 8px;"> Inline math</label>
|
|
40
|
+
</div>
|
|
41
|
+
|
|
42
|
+
<div style="margin-bottom: 20px;">
|
|
43
|
+
<label style="display: block; font-weight: 600; margin-bottom: 8px; font-size: 14px; color: ${n.text};">Formula:</label>
|
|
44
|
+
<textarea id="formula-input" rows="4" style="width: 100%; min-height: 112px; padding: 10px 12px; border: 1px solid ${n.fieldBorder}; border-radius: 6px; font-family: 'Courier New', monospace; font-size: 14px; line-height: 1.45; background: ${n.fieldBg}; color: ${n.text}; box-sizing: border-box; overflow-x: hidden; overflow-y: auto; resize: vertical;">${K(B)}</textarea>
|
|
45
|
+
</div>
|
|
46
|
+
|
|
47
|
+
<div style="margin-bottom: 20px;">
|
|
48
|
+
<label style="display: block; font-weight: 600; margin-bottom: 8px; font-size: 14px; color: ${n.text};">Preview:</label>
|
|
49
|
+
<div id="preview-area" style="min-height: 60px; padding: 15px; border: 1px solid ${n.fieldBorder}; border-radius: 4px; background: ${n.previewBg}; display: flex; align-items: center; justify-content: center; color: ${n.previewText};"></div>
|
|
50
|
+
</div>
|
|
51
|
+
</div>
|
|
52
|
+
|
|
53
|
+
<div style="display: flex; justify-content: flex-end; gap: 10px; padding: 16px 20px; border-top: 1px solid ${n.border}; background: ${n.panelBg};">
|
|
54
|
+
<button class="cancel-btn" style="padding: 10px 20px; background: ${n.cancelBg}; color: ${n.cancelText}; border: 1px solid ${n.cancelBorder}; border-radius: 4px; cursor: pointer; font-size: 14px;">Cancel</button>
|
|
55
|
+
<button id="insert-btn" style="padding: 10px 20px; background: ${n.insertBg}; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 14px;" disabled>${e?"Update":"Insert"}</button>
|
|
56
|
+
</div>
|
|
57
|
+
`,c.appendChild(d),document.body.appendChild(c);const p=d.querySelector("#formula-input"),v=d.querySelector("#preview-area"),T=d.querySelector("#templates-grid"),P=d.querySelectorAll('input[name="format"]'),q=d.querySelector("#inline-cb"),f=d.querySelector("#insert-btn"),g=d.querySelector(".close-btn"),w=d.querySelector(".cancel-btn"),F=o=>encodeURIComponent(o),O=o=>{try{return decodeURIComponent(o)}catch{return o}},A=()=>{const o=Z[u];T.innerHTML=o.map(s=>`
|
|
58
|
+
<button type="button" data-formula="${F(s.formula)}" title="${s.description}" style="padding: 8px; border: 1px solid ${n.fieldBorder}; border-radius: 4px; background: ${n.templateBtnBg}; cursor: pointer; text-align: left; transition: background-color 0.16s ease;">
|
|
59
|
+
<div style="font-weight: 600; font-size: 12px; color: ${n.templateBtnText};">${s.name}</div>
|
|
60
|
+
<div style="font-size: 10px; color: ${n.templateSubText}; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">${s.formula.substring(0,20)}...</div>
|
|
61
|
+
</button>
|
|
62
|
+
`).join("")},U=()=>{const o=p.value.trim(),s=`${u}:${o}`;if(s!==C){if(C=s,!o){v.innerHTML=`<span style="color: ${n.previewText};">Enter a formula to see preview</span>`,f.disabled=!0;return}f.disabled=!1;try{if(u==="latex"){const i=window.katex;v.innerHTML=i.renderToString(o,{displayMode:!1,throwOnError:!1})}else o.trim().startsWith("<math")?v.innerHTML=L(o):v.innerHTML=L(`<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline">${o}</math>`)}catch{v.innerHTML=`<span style="color: ${n.invalid};">Invalid formula</span>`}}},M=()=>{b!==null&&cancelAnimationFrame(b),b=requestAnimationFrame(()=>{b=null,U()})},D=o=>{o.key==="Escape"&&(o.preventDefault(),o.stopPropagation(),E())},E=()=>{document.removeEventListener("keydown",D,!0),b!==null&&(cancelAnimationFrame(b),b=null),c.parentNode&&c.parentNode.removeChild(c)};g.onmouseover=()=>{g.style.color="#f8fafc",g.style.background=a?"#334155":"#e5e7eb",g.style.borderRadius="4px"},g.onmouseout=()=>{g.style.color=n.muted,g.style.background="none"},w.onmouseover=()=>{w.style.background=a?"#475569":"#f3f4f6"},w.onmouseout=()=>{w.style.background=n.cancelBg},f.onmouseover=()=>{f.disabled||(f.style.background=n.insertHover)},f.onmouseout=()=>{f.style.background=n.insertBg},T.addEventListener("mouseover",o=>{const i=o.target.closest("button[data-formula]");i&&(i.style.background=n.templateBtnHover)}),T.addEventListener("mouseout",o=>{const i=o.target.closest("button[data-formula]");i&&(i.style.background=n.templateBtnBg)}),T.addEventListener("click",o=>{const i=o.target.closest("button[data-formula]");i&&(p.value=O(i.getAttribute("data-formula")||""),B=p.value,M())});const N=()=>{const o=p.value.trim();if(!o)return;const s={formula:o,format:u,inline:q.checked},i=s.inline?document.createElement("span"):document.createElement("div");if(i.className=s.inline?"math-formula":"math-block",i.setAttribute("data-math-formula",o),i.setAttribute("data-math-format",u),i.contentEditable="false",i.style.cssText=s.inline?"background: #f0f8ff; border: 1px solid #b8daff; border-radius: 4px; padding: 2px 6px; margin: 0 2px; color: #004085; display: inline-block; cursor: pointer;":"background: #f8f9fa; border: 1px solid #dee2e6; border-radius: 4px; padding: 12px; margin: 8px 0; text-align: center; display: block; cursor: pointer;",u==="latex"){const x=window.katex;try{i.innerHTML=x.renderToString(o,{displayMode:!s.inline,throwOnError:!1})}catch{i.textContent=s.inline?`$${o}$`:`$$${o}$$`}}else if(o.trim().startsWith("<math"))i.innerHTML=L(o);else{const x=`<math xmlns="http://www.w3.org/1998/Math/MathML" display="${s.inline?"inline":"block"}">${o}</math>`;i.innerHTML=L(x)}if($)$.replaceWith(i);else if(S)S.deleteContents(),S.insertNode(i);else if(y&&y.isConnected){const x=document.createRange();x.selectNodeContents(y),x.collapse(!1),x.insertNode(i)}(i.closest(".rte-content, .editora-content")||y)?.dispatchEvent(new Event("input",{bubbles:!0})),E()};g.addEventListener("click",E),w.addEventListener("click",E),f.addEventListener("click",N),c.addEventListener("click",o=>{o.target===c&&E()}),document.addEventListener("keydown",D,!0),P.forEach(o=>{o.addEventListener("change",s=>{u=s.target.value,C="",A(),M()})}),p.addEventListener("input",()=>{B=p.value,M()}),p.addEventListener("keydown",o=>{(o.ctrlKey||o.metaKey)&&o.key==="Enter"&&(o.preventDefault(),N())}),A(),M(),p.focus()};if(typeof window<"u"&&!window.__mathPluginDoubleClickInitialized){window.__mathPluginDoubleClickInitialized=!0;const e=r=>{const a=r.target.closest(".math-formula, .math-block");if(a){r.preventDefault(),r.stopPropagation(),r.stopImmediatePropagation(),h(),$=a;const n=a.getAttribute("data-math-formula")||"",c=a.getAttribute("data-math-format")||"latex",d=a.classList.contains("math-formula");R({formula:n,format:c,inline:d})}},t=()=>{document.addEventListener("dblclick",e,{capture:!0})};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",t):setTimeout(t,100)}const ce=()=>({name:"math",init:le,toolbar:[{label:"Insert Math",command:"insertMath",icon:'<svg width="24" height="24" focusable="false"><path fill-rule="evenodd" clip-rule="evenodd" d="M9 4.8c.1-.5.5-.8 1-.8h10a1 1 0 1 1 0 2h-9.2L8.3 19.2a1 1 0 0 1-1.7.4l-3.4-4.2a1 1 0 0 1 1.6-1.2l2 2.5L9 4.8Zm9.7 5.5c.4.4.4 1 0 1.4L17 13.5l1.8 1.8a1 1 0 0 1-1.4 1.4L15.5 15l-1.8 1.8a1 1 0 0 1-1.4-1.4l1.8-1.8-1.8-1.8a1 1 0 0 1 1.4-1.4l1.8 1.8 1.8-1.8a1 1 0 0 1 1.4 0Z"></path></svg>'}],commands:{insertMath:(e,t)=>{const r=t?.contentElement instanceof HTMLElement?t.contentElement:null;return R(void 0,r),!0}},keymap:{"Mod-Shift-m":"insertMath"}});exports.MathPlugin=ce;
|
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
function K(e) {
|
|
2
|
+
return String(e ?? "").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
3
|
+
}
|
|
4
|
+
function G(e) {
|
|
5
|
+
let t = !1;
|
|
6
|
+
e.addEventListener(
|
|
7
|
+
"pointerdown",
|
|
8
|
+
(r) => {
|
|
9
|
+
t = r.target !== e;
|
|
10
|
+
},
|
|
11
|
+
!0
|
|
12
|
+
), e.addEventListener(
|
|
13
|
+
"click",
|
|
14
|
+
(r) => {
|
|
15
|
+
r.target === e && t && r.stopImmediatePropagation(), t = !1;
|
|
16
|
+
},
|
|
17
|
+
!0
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
const H = "rte-dialog-base-styles";
|
|
21
|
+
function W() {
|
|
22
|
+
if (typeof document > "u" || document.getElementById(H)) return;
|
|
23
|
+
const e = document.createElement("style");
|
|
24
|
+
e.id = H, e.textContent = `
|
|
25
|
+
[data-rte-dialog] {
|
|
26
|
+
font-family: var(--rte-font-family-base, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/* Form controls ignore inherited fonts (browsers default them to Arial /
|
|
30
|
+
system-ui). :where() keeps this at zero specificity so any control a plugin
|
|
31
|
+
styles explicitly - e.g. a monospace formula field - keeps its own font. */
|
|
32
|
+
:where([data-rte-dialog]) :where(button, input, select, textarea) {
|
|
33
|
+
font-family: inherit;
|
|
34
|
+
}
|
|
35
|
+
`, document.head.appendChild(e);
|
|
36
|
+
}
|
|
37
|
+
function X(e) {
|
|
38
|
+
e.setAttribute("data-rte-dialog", ""), W(), G(e);
|
|
39
|
+
}
|
|
40
|
+
const Z = {
|
|
41
|
+
latex: [
|
|
42
|
+
{ name: "Fraction", formula: "\\frac{a}{b}", description: "Simple fraction" },
|
|
43
|
+
{ name: "Square Root", formula: "\\sqrt{x}", description: "Square root" },
|
|
44
|
+
{ name: "Power", formula: "x^{2}", description: "Exponent/power" },
|
|
45
|
+
{ name: "Subscript", formula: "x_{sub}", description: "Subscript" },
|
|
46
|
+
{ name: "Integral", formula: "\\int_{a}^{b} f(x) \\, dx", description: "Definite integral" },
|
|
47
|
+
{ name: "Summation", formula: "\\sum_{i=1}^{n} x_{i}", description: "Summation" },
|
|
48
|
+
{ name: "Limit", formula: "\\lim_{x \\to 0} f(x)", description: "Limit" },
|
|
49
|
+
{ name: "Derivative", formula: "\\frac{d}{dx} f(x)", description: "Derivative" },
|
|
50
|
+
{ name: "Matrix 2x2", formula: "\\begin{pmatrix} a & b \\\\ c & d \\end{pmatrix}", description: "2x2 matrix" },
|
|
51
|
+
{ name: "System", formula: "\\begin{cases} x + y = 1 \\\\ 2x - y = 0 \\end{cases}", description: "System of equations" }
|
|
52
|
+
],
|
|
53
|
+
mathml: [
|
|
54
|
+
{ name: "Fraction", formula: "<mfrac><mi>a</mi><mi>b</mi></mfrac>", description: "Simple fraction" },
|
|
55
|
+
{ name: "Square Root", formula: "<msqrt><mi>x</mi></msqrt>", description: "Square root" },
|
|
56
|
+
{ name: "Power", formula: "<msup><mi>x</mi><mn>2</mn></msup>", description: "Exponent/power" },
|
|
57
|
+
{ name: "Subscript", formula: "<msub><mi>x</mi><mi>sub</mi></msub>", description: "Subscript" },
|
|
58
|
+
{ name: "Parentheses", formula: '<mfenced open="(" close=")"><mi>a</mi><mo>+</mo><mi>b</mi></mfenced>', description: "Grouped expression" }
|
|
59
|
+
]
|
|
60
|
+
};
|
|
61
|
+
let S = null, $ = null, _ = !1, y = null, m = null;
|
|
62
|
+
const k = '[data-theme="dark"], .dark, .editora-theme-dark', Q = /* @__PURE__ */ new Set([
|
|
63
|
+
"math",
|
|
64
|
+
"mrow",
|
|
65
|
+
"mi",
|
|
66
|
+
"mn",
|
|
67
|
+
"mo",
|
|
68
|
+
"ms",
|
|
69
|
+
"mtext",
|
|
70
|
+
"mspace",
|
|
71
|
+
"msup",
|
|
72
|
+
"msub",
|
|
73
|
+
"msubsup",
|
|
74
|
+
"mfrac",
|
|
75
|
+
"msqrt",
|
|
76
|
+
"mroot",
|
|
77
|
+
"mfenced",
|
|
78
|
+
"mstyle",
|
|
79
|
+
"mpadded",
|
|
80
|
+
"mphantom",
|
|
81
|
+
"menclose",
|
|
82
|
+
"mtable",
|
|
83
|
+
"mtr",
|
|
84
|
+
"mtd",
|
|
85
|
+
"mlabeledtr",
|
|
86
|
+
"munder",
|
|
87
|
+
"mover",
|
|
88
|
+
"munderover",
|
|
89
|
+
"mmultiscripts",
|
|
90
|
+
"mprescripts",
|
|
91
|
+
"none",
|
|
92
|
+
"semantics",
|
|
93
|
+
"annotation"
|
|
94
|
+
]), Y = /* @__PURE__ */ new Set([
|
|
95
|
+
"display",
|
|
96
|
+
"displaystyle",
|
|
97
|
+
"mathvariant",
|
|
98
|
+
"mathsize",
|
|
99
|
+
"mathcolor",
|
|
100
|
+
"mathbackground",
|
|
101
|
+
"scriptlevel",
|
|
102
|
+
"fence",
|
|
103
|
+
"separator",
|
|
104
|
+
"stretchy",
|
|
105
|
+
"symmetric",
|
|
106
|
+
"lspace",
|
|
107
|
+
"rspace",
|
|
108
|
+
"largeop",
|
|
109
|
+
"movablelimits",
|
|
110
|
+
"accent",
|
|
111
|
+
"accentunder",
|
|
112
|
+
"open",
|
|
113
|
+
"close",
|
|
114
|
+
"separators",
|
|
115
|
+
"linethickness",
|
|
116
|
+
"columnalign",
|
|
117
|
+
"rowalign",
|
|
118
|
+
"columnspacing",
|
|
119
|
+
"rowspacing",
|
|
120
|
+
"columnlines",
|
|
121
|
+
"rowlines",
|
|
122
|
+
"frame",
|
|
123
|
+
"notation",
|
|
124
|
+
"width",
|
|
125
|
+
"height",
|
|
126
|
+
"depth",
|
|
127
|
+
"voffset",
|
|
128
|
+
"minsize",
|
|
129
|
+
"maxsize",
|
|
130
|
+
"form",
|
|
131
|
+
"encoding",
|
|
132
|
+
"xmlns",
|
|
133
|
+
"dir",
|
|
134
|
+
"class",
|
|
135
|
+
"id"
|
|
136
|
+
]), L = (e) => {
|
|
137
|
+
const t = new DOMParser().parseFromString(`<body>${e}</body>`, "text/html"), r = (l) => {
|
|
138
|
+
Array.from(l.childNodes).forEach((a) => {
|
|
139
|
+
if (a.nodeType === Node.ELEMENT_NODE) {
|
|
140
|
+
const n = a;
|
|
141
|
+
if (!Q.has(n.localName.toLowerCase())) {
|
|
142
|
+
n.remove();
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
Array.from(n.attributes).forEach((c) => {
|
|
146
|
+
Y.has(c.name.toLowerCase()) || n.removeAttribute(c.name);
|
|
147
|
+
}), r(n);
|
|
148
|
+
} else a.nodeType !== Node.TEXT_NODE && a.parentNode?.removeChild(a);
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
return r(t.body), t.body.innerHTML;
|
|
152
|
+
}, J = () => new Promise((e, t) => {
|
|
153
|
+
if (window.katex) {
|
|
154
|
+
e(window.katex);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (_) {
|
|
158
|
+
const a = setInterval(() => {
|
|
159
|
+
window.katex && (clearInterval(a), e(window.katex));
|
|
160
|
+
}, 100);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
_ = !0;
|
|
164
|
+
const r = document.createElement("link");
|
|
165
|
+
r.rel = "stylesheet", r.href = "https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css", document.head.appendChild(r);
|
|
166
|
+
const l = document.createElement("script");
|
|
167
|
+
l.src = "https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.js", l.onload = () => e(window.katex), l.onerror = t, document.head.appendChild(l);
|
|
168
|
+
}), I = () => {
|
|
169
|
+
const e = window.getSelection();
|
|
170
|
+
if (!e || e.rangeCount === 0) return null;
|
|
171
|
+
const t = e.getRangeAt(0).startContainer;
|
|
172
|
+
return (t.nodeType === Node.ELEMENT_NODE ? t : t.parentElement)?.closest(".rte-content, .editora-content") || null;
|
|
173
|
+
}, V = (e) => e ? e.nodeType === Node.ELEMENT_NODE ? e : e.parentElement : null, z = (e) => V(e)?.closest('.rte-content, .editora-content, [contenteditable="true"]') || null, ee = (e, t, r) => {
|
|
174
|
+
if (t !== r) {
|
|
175
|
+
if (typeof window.execEditorCommand == "function") {
|
|
176
|
+
window.execEditorCommand("recordDomTransaction", e, t, r);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (typeof window.executeEditorCommand == "function")
|
|
180
|
+
try {
|
|
181
|
+
window.executeEditorCommand("recordDomTransaction", { editor: e, beforeHTML: t, afterHTML: r });
|
|
182
|
+
} catch {
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}, te = (e) => {
|
|
186
|
+
if (!(e instanceof Element)) return null;
|
|
187
|
+
const t = e.closest(".math-formula, .math-block");
|
|
188
|
+
return t instanceof HTMLElement ? t : null;
|
|
189
|
+
}, h = () => {
|
|
190
|
+
m && (m.classList.remove("math-object-selected"), m.removeAttribute("data-rte-selected-object"), m = null);
|
|
191
|
+
}, ne = (e) => {
|
|
192
|
+
if (m === e) return;
|
|
193
|
+
h(), m = e, e.classList.add("math-object-selected"), e.setAttribute("data-rte-selected-object", "true");
|
|
194
|
+
const t = window.getSelection();
|
|
195
|
+
if (!t) return;
|
|
196
|
+
const r = document.createRange();
|
|
197
|
+
r.selectNode(e), t.removeAllRanges(), t.addRange(r);
|
|
198
|
+
}, oe = (e, t) => {
|
|
199
|
+
const r = window.getSelection();
|
|
200
|
+
if (!r) return;
|
|
201
|
+
const l = document.createRange();
|
|
202
|
+
t && t.parentNode === e ? l.setStartBefore(t) : (l.selectNodeContents(e), l.collapse(!1)), l.collapse(!0), r.removeAllRanges(), r.addRange(l);
|
|
203
|
+
}, re = (e) => {
|
|
204
|
+
if (e.childNodes.length > 0) return;
|
|
205
|
+
const t = document.createElement("p");
|
|
206
|
+
t.appendChild(document.createElement("br")), e.appendChild(t);
|
|
207
|
+
}, ae = () => {
|
|
208
|
+
if (!m || !m.isConnected)
|
|
209
|
+
return h(), !1;
|
|
210
|
+
const e = m, t = z(e);
|
|
211
|
+
if (!t)
|
|
212
|
+
return h(), !1;
|
|
213
|
+
const r = t.innerHTML, l = e.nextSibling;
|
|
214
|
+
e.remove(), re(t), h(), oe(t, l);
|
|
215
|
+
const a = t.innerHTML;
|
|
216
|
+
return ee(t, r, a), t.dispatchEvent(new window.Event("input", { bubbles: !0 })), r !== a;
|
|
217
|
+
}, ie = () => {
|
|
218
|
+
if (document.getElementById("math-object-selection-styles")) return;
|
|
219
|
+
const e = document.createElement("style");
|
|
220
|
+
e.id = "math-object-selection-styles", e.textContent = `
|
|
221
|
+
.math-object-selected {
|
|
222
|
+
outline: 2px solid #2563eb !important;
|
|
223
|
+
outline-offset: 2px;
|
|
224
|
+
box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.18);
|
|
225
|
+
}
|
|
226
|
+
`, document.head.appendChild(e);
|
|
227
|
+
}, le = () => {
|
|
228
|
+
typeof window > "u" || window.__mathPluginObjectSelectionInitialized || (window.__mathPluginObjectSelectionInitialized = !0, ie(), document.addEventListener("pointerdown", (e) => {
|
|
229
|
+
const t = te(e.target);
|
|
230
|
+
if (!t) {
|
|
231
|
+
e.target?.closest?.(".math-dialog-overlay") || h();
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
e.preventDefault(), z(t)?.focus(), ne(t);
|
|
235
|
+
}, !0), document.addEventListener("keydown", (e) => {
|
|
236
|
+
if (m) {
|
|
237
|
+
if (e.key === "Escape") {
|
|
238
|
+
h();
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
e.key !== "Backspace" && e.key !== "Delete" || (e.preventDefault(), e.stopPropagation(), ae());
|
|
242
|
+
}
|
|
243
|
+
}, !0));
|
|
244
|
+
}, se = (e) => {
|
|
245
|
+
if ((e || I())?.closest(k)) return !0;
|
|
246
|
+
const r = window.getSelection();
|
|
247
|
+
if (r && r.rangeCount > 0) {
|
|
248
|
+
const a = r.getRangeAt(0).startContainer;
|
|
249
|
+
if ((a.nodeType === Node.ELEMENT_NODE ? a : a.parentElement)?.closest(k)) return !0;
|
|
250
|
+
}
|
|
251
|
+
return document.activeElement?.closest(k) ? !0 : document.body.matches(k) || document.documentElement.matches(k);
|
|
252
|
+
}, R = async (e, t) => {
|
|
253
|
+
document.querySelectorAll(".math-dialog-overlay").forEach((o) => o.remove());
|
|
254
|
+
const r = t || $?.closest(".rte-content, .editora-content") || I() || y;
|
|
255
|
+
y = r || null;
|
|
256
|
+
const l = window.getSelection();
|
|
257
|
+
if (l && l.rangeCount > 0) {
|
|
258
|
+
const o = l.getRangeAt(0);
|
|
259
|
+
S = r && r.contains(o.commonAncestorContainer) ? o.cloneRange() : null;
|
|
260
|
+
}
|
|
261
|
+
await J();
|
|
262
|
+
const a = se(r), n = a ? {
|
|
263
|
+
overlay: "rgba(0, 0, 0, 0.62)",
|
|
264
|
+
dialogBg: "#1f2937",
|
|
265
|
+
border: "#3b4657",
|
|
266
|
+
panelBg: "#222d3a",
|
|
267
|
+
fieldBg: "#111827",
|
|
268
|
+
fieldBorder: "#4b5563",
|
|
269
|
+
text: "#e2e8f0",
|
|
270
|
+
muted: "#94a3b8",
|
|
271
|
+
templateBtnBg: "#273244",
|
|
272
|
+
templateBtnHover: "#334155",
|
|
273
|
+
templateBtnText: "#dbe7f7",
|
|
274
|
+
templateSubText: "#9fb0c6",
|
|
275
|
+
previewBg: "#111827",
|
|
276
|
+
previewText: "#cbd5e1",
|
|
277
|
+
cancelBg: "#334155",
|
|
278
|
+
cancelText: "#e2e8f0",
|
|
279
|
+
cancelBorder: "#4b5563",
|
|
280
|
+
insertBg: "#3b82f6",
|
|
281
|
+
insertHover: "#2563eb",
|
|
282
|
+
invalid: "#f87171"
|
|
283
|
+
} : {
|
|
284
|
+
overlay: "rgba(0, 0, 0, 0.5)",
|
|
285
|
+
dialogBg: "#ffffff",
|
|
286
|
+
border: "#e1e5e9",
|
|
287
|
+
panelBg: "#f8f9fa",
|
|
288
|
+
fieldBg: "#ffffff",
|
|
289
|
+
fieldBorder: "#ced4da",
|
|
290
|
+
text: "#1f2937",
|
|
291
|
+
muted: "#6c757d",
|
|
292
|
+
templateBtnBg: "#ffffff",
|
|
293
|
+
templateBtnHover: "#f8f9fa",
|
|
294
|
+
templateBtnText: "#1f2937",
|
|
295
|
+
templateSubText: "#6c757d",
|
|
296
|
+
previewBg: "#f8f9fa",
|
|
297
|
+
previewText: "#6c757d",
|
|
298
|
+
cancelBg: "#ffffff",
|
|
299
|
+
cancelText: "#1f2937",
|
|
300
|
+
cancelBorder: "#ced4da",
|
|
301
|
+
insertBg: "#007bff",
|
|
302
|
+
insertHover: "#0069d9",
|
|
303
|
+
invalid: "#cc0000"
|
|
304
|
+
}, c = document.createElement("div");
|
|
305
|
+
X(c), c.className = "math-dialog-overlay", c.style.cssText = `position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: ${n.overlay}; display: flex; align-items: center; justify-content: center; z-index: 99999;`;
|
|
306
|
+
const d = document.createElement("div");
|
|
307
|
+
d.style.cssText = `background: ${n.dialogBg}; border: 1px solid ${n.border}; border-radius: 8px; width: 90%; max-width: 600px; max-height: 90vh; overflow: hidden; display: flex; flex-direction: column; box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2); color: ${n.text};`;
|
|
308
|
+
let u = e?.format || "latex", B = e?.formula || "";
|
|
309
|
+
const j = e?.inline !== !1;
|
|
310
|
+
let b = null, C = "";
|
|
311
|
+
d.innerHTML = `
|
|
312
|
+
<div style="display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid ${n.border}; background: ${n.panelBg};">
|
|
313
|
+
<h2 style="margin: 0; font-size: 18px; font-weight: 600; color: ${n.text};">${e ? "Edit" : "Insert"} Math Formula</h2>
|
|
314
|
+
<button class="close-btn" style="background: none; border: none; font-size: 28px; cursor: pointer; color: ${n.muted}; padding: 0; width: 30px; height: 30px; line-height: 1;">×</button>
|
|
315
|
+
</div>
|
|
316
|
+
|
|
317
|
+
<div style="padding: 20px; overflow-y: auto; flex: 1;">
|
|
318
|
+
<div style="margin-bottom: 20px;">
|
|
319
|
+
<label style="display: block; font-weight: 600; margin-bottom: 8px; font-size: 14px; color: ${n.text};">Format:</label>
|
|
320
|
+
<div style="display: flex; gap: 16px;">
|
|
321
|
+
<label style="cursor: pointer; color: ${n.text};"><input type="radio" name="format" value="latex" ${u === "latex" ? "checked" : ""} style="margin-right: 6px;"> LaTeX</label>
|
|
322
|
+
<label style="cursor: pointer; color: ${n.text};"><input type="radio" name="format" value="mathml" ${u === "mathml" ? "checked" : ""} style="margin-right: 6px;"> MathML</label>
|
|
323
|
+
</div>
|
|
324
|
+
</div>
|
|
325
|
+
|
|
326
|
+
<div style="margin-bottom: 20px;">
|
|
327
|
+
<label style="display: block; font-weight: 600; margin-bottom: 8px; font-size: 14px; color: ${n.text};">Quick Templates:</label>
|
|
328
|
+
<div id="templates-grid" style="display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; max-height: 200px; overflow-y: auto;"></div>
|
|
329
|
+
</div>
|
|
330
|
+
|
|
331
|
+
<div style="margin-bottom: 20px;">
|
|
332
|
+
<label style="cursor: pointer; color: ${n.text};"><input type="checkbox" id="inline-cb" ${j ? "checked" : ""} style="margin-right: 8px;"> Inline math</label>
|
|
333
|
+
</div>
|
|
334
|
+
|
|
335
|
+
<div style="margin-bottom: 20px;">
|
|
336
|
+
<label style="display: block; font-weight: 600; margin-bottom: 8px; font-size: 14px; color: ${n.text};">Formula:</label>
|
|
337
|
+
<textarea id="formula-input" rows="4" style="width: 100%; min-height: 112px; padding: 10px 12px; border: 1px solid ${n.fieldBorder}; border-radius: 6px; font-family: 'Courier New', monospace; font-size: 14px; line-height: 1.45; background: ${n.fieldBg}; color: ${n.text}; box-sizing: border-box; overflow-x: hidden; overflow-y: auto; resize: vertical;">${K(B)}</textarea>
|
|
338
|
+
</div>
|
|
339
|
+
|
|
340
|
+
<div style="margin-bottom: 20px;">
|
|
341
|
+
<label style="display: block; font-weight: 600; margin-bottom: 8px; font-size: 14px; color: ${n.text};">Preview:</label>
|
|
342
|
+
<div id="preview-area" style="min-height: 60px; padding: 15px; border: 1px solid ${n.fieldBorder}; border-radius: 4px; background: ${n.previewBg}; display: flex; align-items: center; justify-content: center; color: ${n.previewText};"></div>
|
|
343
|
+
</div>
|
|
344
|
+
</div>
|
|
345
|
+
|
|
346
|
+
<div style="display: flex; justify-content: flex-end; gap: 10px; padding: 16px 20px; border-top: 1px solid ${n.border}; background: ${n.panelBg};">
|
|
347
|
+
<button class="cancel-btn" style="padding: 10px 20px; background: ${n.cancelBg}; color: ${n.cancelText}; border: 1px solid ${n.cancelBorder}; border-radius: 4px; cursor: pointer; font-size: 14px;">Cancel</button>
|
|
348
|
+
<button id="insert-btn" style="padding: 10px 20px; background: ${n.insertBg}; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 14px;" disabled>${e ? "Update" : "Insert"}</button>
|
|
349
|
+
</div>
|
|
350
|
+
`, c.appendChild(d), document.body.appendChild(c);
|
|
351
|
+
const p = d.querySelector("#formula-input"), v = d.querySelector("#preview-area"), T = d.querySelector("#templates-grid"), q = d.querySelectorAll('input[name="format"]'), P = d.querySelector("#inline-cb"), f = d.querySelector("#insert-btn"), g = d.querySelector(".close-btn"), w = d.querySelector(".cancel-btn"), F = (o) => encodeURIComponent(o), O = (o) => {
|
|
352
|
+
try {
|
|
353
|
+
return decodeURIComponent(o);
|
|
354
|
+
} catch {
|
|
355
|
+
return o;
|
|
356
|
+
}
|
|
357
|
+
}, A = () => {
|
|
358
|
+
const o = Z[u];
|
|
359
|
+
T.innerHTML = o.map((s) => `
|
|
360
|
+
<button type="button" data-formula="${F(s.formula)}" title="${s.description}" style="padding: 8px; border: 1px solid ${n.fieldBorder}; border-radius: 4px; background: ${n.templateBtnBg}; cursor: pointer; text-align: left; transition: background-color 0.16s ease;">
|
|
361
|
+
<div style="font-weight: 600; font-size: 12px; color: ${n.templateBtnText};">${s.name}</div>
|
|
362
|
+
<div style="font-size: 10px; color: ${n.templateSubText}; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">${s.formula.substring(0, 20)}...</div>
|
|
363
|
+
</button>
|
|
364
|
+
`).join("");
|
|
365
|
+
}, U = () => {
|
|
366
|
+
const o = p.value.trim(), s = `${u}:${o}`;
|
|
367
|
+
if (s !== C) {
|
|
368
|
+
if (C = s, !o) {
|
|
369
|
+
v.innerHTML = `<span style="color: ${n.previewText};">Enter a formula to see preview</span>`, f.disabled = !0;
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
f.disabled = !1;
|
|
373
|
+
try {
|
|
374
|
+
if (u === "latex") {
|
|
375
|
+
const i = window.katex;
|
|
376
|
+
v.innerHTML = i.renderToString(o, { displayMode: !1, throwOnError: !1 });
|
|
377
|
+
} else
|
|
378
|
+
o.trim().startsWith("<math") ? v.innerHTML = L(o) : v.innerHTML = L(`<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline">${o}</math>`);
|
|
379
|
+
} catch {
|
|
380
|
+
v.innerHTML = `<span style="color: ${n.invalid};">Invalid formula</span>`;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}, M = () => {
|
|
384
|
+
b !== null && cancelAnimationFrame(b), b = requestAnimationFrame(() => {
|
|
385
|
+
b = null, U();
|
|
386
|
+
});
|
|
387
|
+
}, D = (o) => {
|
|
388
|
+
o.key === "Escape" && (o.preventDefault(), o.stopPropagation(), E());
|
|
389
|
+
}, E = () => {
|
|
390
|
+
document.removeEventListener("keydown", D, !0), b !== null && (cancelAnimationFrame(b), b = null), c.parentNode && c.parentNode.removeChild(c);
|
|
391
|
+
};
|
|
392
|
+
g.onmouseover = () => {
|
|
393
|
+
g.style.color = "#f8fafc", g.style.background = a ? "#334155" : "#e5e7eb", g.style.borderRadius = "4px";
|
|
394
|
+
}, g.onmouseout = () => {
|
|
395
|
+
g.style.color = n.muted, g.style.background = "none";
|
|
396
|
+
}, w.onmouseover = () => {
|
|
397
|
+
w.style.background = a ? "#475569" : "#f3f4f6";
|
|
398
|
+
}, w.onmouseout = () => {
|
|
399
|
+
w.style.background = n.cancelBg;
|
|
400
|
+
}, f.onmouseover = () => {
|
|
401
|
+
f.disabled || (f.style.background = n.insertHover);
|
|
402
|
+
}, f.onmouseout = () => {
|
|
403
|
+
f.style.background = n.insertBg;
|
|
404
|
+
}, T.addEventListener("mouseover", (o) => {
|
|
405
|
+
const i = o.target.closest("button[data-formula]");
|
|
406
|
+
i && (i.style.background = n.templateBtnHover);
|
|
407
|
+
}), T.addEventListener("mouseout", (o) => {
|
|
408
|
+
const i = o.target.closest("button[data-formula]");
|
|
409
|
+
i && (i.style.background = n.templateBtnBg);
|
|
410
|
+
}), T.addEventListener("click", (o) => {
|
|
411
|
+
const i = o.target.closest("button[data-formula]");
|
|
412
|
+
i && (p.value = O(i.getAttribute("data-formula") || ""), B = p.value, M());
|
|
413
|
+
});
|
|
414
|
+
const N = () => {
|
|
415
|
+
const o = p.value.trim();
|
|
416
|
+
if (!o) return;
|
|
417
|
+
const s = { formula: o, format: u, inline: P.checked }, i = s.inline ? document.createElement("span") : document.createElement("div");
|
|
418
|
+
if (i.className = s.inline ? "math-formula" : "math-block", i.setAttribute("data-math-formula", o), i.setAttribute("data-math-format", u), i.contentEditable = "false", i.style.cssText = s.inline ? "background: #f0f8ff; border: 1px solid #b8daff; border-radius: 4px; padding: 2px 6px; margin: 0 2px; color: #004085; display: inline-block; cursor: pointer;" : "background: #f8f9fa; border: 1px solid #dee2e6; border-radius: 4px; padding: 12px; margin: 8px 0; text-align: center; display: block; cursor: pointer;", u === "latex") {
|
|
419
|
+
const x = window.katex;
|
|
420
|
+
try {
|
|
421
|
+
i.innerHTML = x.renderToString(o, {
|
|
422
|
+
displayMode: !s.inline,
|
|
423
|
+
throwOnError: !1
|
|
424
|
+
});
|
|
425
|
+
} catch {
|
|
426
|
+
i.textContent = s.inline ? `$${o}$` : `$$${o}$$`;
|
|
427
|
+
}
|
|
428
|
+
} else if (o.trim().startsWith("<math"))
|
|
429
|
+
i.innerHTML = L(o);
|
|
430
|
+
else {
|
|
431
|
+
const x = `<math xmlns="http://www.w3.org/1998/Math/MathML" display="${s.inline ? "inline" : "block"}">${o}</math>`;
|
|
432
|
+
i.innerHTML = L(x);
|
|
433
|
+
}
|
|
434
|
+
if ($)
|
|
435
|
+
$.replaceWith(i);
|
|
436
|
+
else if (S)
|
|
437
|
+
S.deleteContents(), S.insertNode(i);
|
|
438
|
+
else if (y && y.isConnected) {
|
|
439
|
+
const x = document.createRange();
|
|
440
|
+
x.selectNodeContents(y), x.collapse(!1), x.insertNode(i);
|
|
441
|
+
}
|
|
442
|
+
(i.closest(".rte-content, .editora-content") || y)?.dispatchEvent(new Event("input", { bubbles: !0 })), E();
|
|
443
|
+
};
|
|
444
|
+
g.addEventListener("click", E), w.addEventListener("click", E), f.addEventListener("click", N), c.addEventListener("click", (o) => {
|
|
445
|
+
o.target === c && E();
|
|
446
|
+
}), document.addEventListener("keydown", D, !0), q.forEach((o) => {
|
|
447
|
+
o.addEventListener("change", (s) => {
|
|
448
|
+
u = s.target.value, C = "", A(), M();
|
|
449
|
+
});
|
|
450
|
+
}), p.addEventListener("input", () => {
|
|
451
|
+
B = p.value, M();
|
|
452
|
+
}), p.addEventListener("keydown", (o) => {
|
|
453
|
+
(o.ctrlKey || o.metaKey) && o.key === "Enter" && (o.preventDefault(), N());
|
|
454
|
+
}), A(), M(), p.focus();
|
|
455
|
+
};
|
|
456
|
+
if (typeof window < "u" && !window.__mathPluginDoubleClickInitialized) {
|
|
457
|
+
window.__mathPluginDoubleClickInitialized = !0;
|
|
458
|
+
const e = (r) => {
|
|
459
|
+
const a = r.target.closest(".math-formula, .math-block");
|
|
460
|
+
if (a) {
|
|
461
|
+
r.preventDefault(), r.stopPropagation(), r.stopImmediatePropagation(), h(), $ = a;
|
|
462
|
+
const n = a.getAttribute("data-math-formula") || "", c = a.getAttribute("data-math-format") || "latex", d = a.classList.contains("math-formula");
|
|
463
|
+
R({ formula: n, format: c, inline: d });
|
|
464
|
+
}
|
|
465
|
+
}, t = () => {
|
|
466
|
+
document.addEventListener("dblclick", e, { capture: !0 });
|
|
467
|
+
};
|
|
468
|
+
document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", t) : setTimeout(t, 100);
|
|
469
|
+
}
|
|
470
|
+
const de = () => ({
|
|
471
|
+
name: "math",
|
|
472
|
+
init: le,
|
|
473
|
+
toolbar: [
|
|
474
|
+
{
|
|
475
|
+
label: "Insert Math",
|
|
476
|
+
command: "insertMath",
|
|
477
|
+
icon: '<svg width="24" height="24" focusable="false"><path fill-rule="evenodd" clip-rule="evenodd" d="M9 4.8c.1-.5.5-.8 1-.8h10a1 1 0 1 1 0 2h-9.2L8.3 19.2a1 1 0 0 1-1.7.4l-3.4-4.2a1 1 0 0 1 1.6-1.2l2 2.5L9 4.8Zm9.7 5.5c.4.4.4 1 0 1.4L17 13.5l1.8 1.8a1 1 0 0 1-1.4 1.4L15.5 15l-1.8 1.8a1 1 0 0 1-1.4-1.4l1.8-1.8-1.8-1.8a1 1 0 0 1 1.4-1.4l1.8 1.8 1.8-1.8a1 1 0 0 1 1.4 0Z"></path></svg>'
|
|
478
|
+
}
|
|
479
|
+
],
|
|
480
|
+
commands: {
|
|
481
|
+
insertMath: (e, t) => {
|
|
482
|
+
const r = t?.contentElement instanceof HTMLElement ? t.contentElement : null;
|
|
483
|
+
return R(void 0, r), !0;
|
|
484
|
+
}
|
|
485
|
+
},
|
|
486
|
+
keymap: {
|
|
487
|
+
"Mod-Shift-m": "insertMath"
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
export {
|
|
491
|
+
de as MathPlugin
|
|
492
|
+
};
|