@editora/plugins 1.0.2 → 1.0.4
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/README.md +30 -5
- package/dist/a11y-checker.cjs.js +109 -0
- package/dist/a11y-checker.esm.js +509 -0
- package/dist/anchor.cjs.js +176 -0
- package/dist/anchor.esm.js +400 -0
- package/dist/background-color.cjs.js +218 -0
- package/dist/background-color.esm.js +482 -0
- package/dist/blockquote.cjs.js +1 -0
- package/dist/blockquote.esm.js +47 -0
- package/dist/bold.cjs.js +1 -0
- package/dist/bold.esm.js +44 -0
- package/dist/capitalization.cjs.js +1 -0
- package/dist/capitalization.esm.js +78 -0
- package/dist/checklist.cjs.js +1 -0
- package/dist/checklist.esm.js +305 -0
- package/dist/clear-formatting.cjs.js +1 -0
- package/dist/clear-formatting.esm.js +138 -0
- package/dist/code-sample.cjs.js +161 -0
- package/dist/code-sample.esm.js +381 -0
- package/dist/code.cjs.js +598 -0
- package/dist/code.esm.js +2034 -0
- package/dist/colorSelectionApply-C0iOfMWb.js +1 -0
- package/dist/colorSelectionApply-D8r_gV32.mjs +63 -0
- package/dist/comments.cjs.js +354 -0
- package/dist/comments.esm.js +692 -0
- package/dist/direction.cjs.js +1 -0
- package/dist/direction.esm.js +129 -0
- package/dist/document-manager.cjs.js +1 -0
- package/dist/document-manager.esm.js +6 -0
- package/dist/{documentManager-CYC9totK.mjs → documentManager-DRUc1-Cs.mjs} +3 -3
- package/dist/{documentManager-BGlu3WRB.js → documentManager-_tQQfQi9.js} +3 -3
- package/dist/editorContainerHelpers-C7kdWnS0.mjs +26 -0
- package/dist/editorContainerHelpers-CFbfiOJI.js +1 -0
- package/dist/embed-iframe.cjs.js +361 -0
- package/dist/embed-iframe.esm.js +556 -0
- package/dist/emojis.cjs.js +284 -0
- package/dist/emojis.esm.js +1080 -0
- package/dist/font-family.cjs.js +1 -0
- package/dist/font-family.esm.js +152 -0
- package/dist/font-size.cjs.js +1 -0
- package/dist/font-size.esm.js +278 -0
- package/dist/footnote.cjs.js +85 -0
- package/dist/footnote.esm.js +397 -0
- package/dist/fullscreen.cjs.js +1 -0
- package/dist/fullscreen.esm.js +73 -0
- package/dist/heading.cjs.js +1 -0
- package/dist/heading.esm.js +63 -0
- package/dist/history.cjs.js +1 -0
- package/dist/history.esm.js +246 -0
- package/dist/indent.cjs.js +1 -0
- package/dist/indent.esm.js +146 -0
- package/dist/index-Bskk414V.mjs +145 -0
- package/dist/index-D3pJyAsj.js +1 -0
- package/dist/index.cjs.js +1 -1
- package/dist/{index.es-B-to-4j4.js → index.es-Cz1qItab.js} +1 -1
- package/dist/{index.es-BbXJ7tyO.mjs → index.es-DEcRmSTY.mjs} +1 -1
- package/dist/index.esm.js +89 -49
- package/dist/italic.cjs.js +1 -0
- package/dist/italic.esm.js +40 -0
- package/dist/line-height.cjs.js +1 -0
- package/dist/line-height.esm.js +145 -0
- package/dist/link.cjs.js +138 -0
- package/dist/link.esm.js +276 -0
- package/dist/list.cjs.js +1 -0
- package/dist/list.esm.js +102 -0
- package/dist/lite.cjs.js +1 -0
- package/dist/lite.esm.js +61 -0
- package/dist/math.cjs.js +45 -0
- package/dist/math.esm.js +249 -0
- package/dist/media-manager.cjs.js +619 -0
- package/dist/media-manager.esm.js +994 -0
- package/dist/merge-tag.cjs.js +93 -0
- package/dist/merge-tag.esm.js +412 -0
- package/dist/page-break.cjs.js +72 -0
- package/dist/page-break.esm.js +295 -0
- package/dist/plugins.css +1 -1
- package/dist/preview.cjs.js +230 -0
- package/dist/preview.esm.js +321 -0
- package/dist/print.cjs.js +254 -0
- package/dist/print.esm.js +309 -0
- package/dist/purify.es-DHhaBdbu.mjs +470 -0
- package/dist/purify.es-T2a3nLiC.js +3 -0
- package/dist/shared-config.cjs.js +1 -0
- package/dist/shared-config.esm.js +30 -0
- package/dist/special-characters.cjs.js +257 -0
- package/dist/special-characters.esm.js +772 -0
- package/dist/spell-check.cjs.js +512 -0
- package/dist/spell-check.esm.js +1013 -0
- package/dist/strikethrough.cjs.js +1 -0
- package/dist/strikethrough.esm.js +71 -0
- package/dist/table.cjs.js +35 -0
- package/dist/table.esm.js +477 -0
- package/dist/template.cjs.js +356 -0
- package/dist/template.esm.js +560 -0
- package/dist/text-alignment.cjs.js +1 -0
- package/dist/text-alignment.esm.js +105 -0
- package/dist/text-color.cjs.js +300 -0
- package/dist/text-color.esm.js +507 -0
- package/dist/underline.cjs.js +1 -0
- package/dist/underline.esm.js +34 -0
- package/index.d.ts +62 -0
- package/package.json +218 -6
- package/LICENSE +0 -21
- package/dist/index-BbORIHoM.mjs +0 -11763
- package/dist/index-C-OCBS_6.js +0 -3753
package/dist/math.cjs.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C={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 h=null,w=null,E=!1;const y='[data-theme="dark"], .dark, .editora-theme-dark',q=()=>new Promise((a,s)=>{if(window.katex){a(window.katex);return}if(E){const i=setInterval(()=>{window.katex&&(clearInterval(i),a(window.katex))},100);return}E=!0;const o=document.createElement("link");o.rel="stylesheet",o.href="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css",document.head.appendChild(o);const e=document.createElement("script");e.src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.js",e.onload=()=>a(window.katex),e.onerror=s,document.head.appendChild(e)}),H=()=>{const a=window.getSelection();if(a&&a.rangeCount>0){const o=a.getRangeAt(0).startContainer;if((o.nodeType===Node.ELEMENT_NODE?o:o.parentElement)?.closest(y))return!0}return document.activeElement?.closest(y)?!0:document.body.matches(y)||document.documentElement.matches(y)},T=async a=>{const s=window.getSelection();s&&s.rangeCount>0&&(h=s.getRangeAt(0).cloneRange()),await q();const o=H(),e=o?{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"},i=document.createElement("div");i.style.cssText=`position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: ${e.overlay}; display: flex; align-items: center; justify-content: center; z-index: 99999;`;const l=document.createElement("div");l.style.cssText=`background: ${e.dialogBg}; border: 1px solid ${e.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: ${e.text};`;let d=a?.format||"latex",u=a?.formula||"",M=a?.inline!==!1;l.innerHTML=`
|
|
2
|
+
<div style="display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid ${e.border}; background: ${e.panelBg};">
|
|
3
|
+
<h2 style="margin: 0; font-size: 18px; font-weight: 600; color: ${e.text};">${a?"Edit":"Insert"} Math Formula</h2>
|
|
4
|
+
<button class="close-btn" style="background: none; border: none; font-size: 28px; cursor: pointer; color: ${e.muted}; padding: 0; width: 30px; height: 30px; line-height: 1;">×</button>
|
|
5
|
+
</div>
|
|
6
|
+
|
|
7
|
+
<div style="padding: 20px; overflow-y: auto; flex: 1;">
|
|
8
|
+
<div style="margin-bottom: 20px;">
|
|
9
|
+
<label style="display: block; font-weight: 600; margin-bottom: 8px; font-size: 14px; color: ${e.text};">Format:</label>
|
|
10
|
+
<div style="display: flex; gap: 16px;">
|
|
11
|
+
<label style="cursor: pointer; color: ${e.text};"><input type="radio" name="format" value="latex" ${d==="latex"?"checked":""} style="margin-right: 6px;"> LaTeX</label>
|
|
12
|
+
<label style="cursor: pointer; color: ${e.text};"><input type="radio" name="format" value="mathml" ${d==="mathml"?"checked":""} style="margin-right: 6px;"> MathML</label>
|
|
13
|
+
</div>
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
<div style="margin-bottom: 20px;">
|
|
17
|
+
<label style="display: block; font-weight: 600; margin-bottom: 8px; font-size: 14px; color: ${e.text};">Quick Templates:</label>
|
|
18
|
+
<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>
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
<div style="margin-bottom: 20px;">
|
|
22
|
+
<label style="cursor: pointer; color: ${e.text};"><input type="checkbox" id="inline-cb" ${M?"checked":""} style="margin-right: 8px;"> Inline math</label>
|
|
23
|
+
</div>
|
|
24
|
+
|
|
25
|
+
<div style="margin-bottom: 20px;">
|
|
26
|
+
<label style="display: block; font-weight: 600; margin-bottom: 8px; font-size: 14px; color: ${e.text};">Formula:</label>
|
|
27
|
+
<textarea id="formula-input" rows="4" style="width: 100%; padding: 10px; border: 1px solid ${e.fieldBorder}; border-radius: 4px; font-family: 'Courier New', monospace; font-size: 14px; background: ${e.fieldBg}; color: ${e.text};">${u}</textarea>
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
<div style="margin-bottom: 20px;">
|
|
31
|
+
<label style="display: block; font-weight: 600; margin-bottom: 8px; font-size: 14px; color: ${e.text};">Preview:</label>
|
|
32
|
+
<div id="preview-area" style="min-height: 60px; padding: 15px; border: 1px solid ${e.fieldBorder}; border-radius: 4px; background: ${e.previewBg}; display: flex; align-items: center; justify-content: center; color: ${e.previewText};"></div>
|
|
33
|
+
</div>
|
|
34
|
+
</div>
|
|
35
|
+
|
|
36
|
+
<div style="display: flex; justify-content: flex-end; gap: 10px; padding: 16px 20px; border-top: 1px solid ${e.border}; background: ${e.panelBg};">
|
|
37
|
+
<button class="cancel-btn" style="padding: 10px 20px; background: ${e.cancelBg}; color: ${e.cancelText}; border: 1px solid ${e.cancelBorder}; border-radius: 4px; cursor: pointer; font-size: 14px;">Cancel</button>
|
|
38
|
+
<button id="insert-btn" style="padding: 10px 20px; background: ${e.insertBg}; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 14px;" disabled>${a?"Update":"Insert"}</button>
|
|
39
|
+
</div>
|
|
40
|
+
`,i.appendChild(l),document.body.appendChild(i);const c=l.querySelector("#formula-input"),f=l.querySelector("#preview-area"),k=l.querySelector("#templates-grid"),S=l.querySelectorAll('input[name="format"]'),L=l.querySelector("#inline-cb"),m=l.querySelector("#insert-btn"),p=l.querySelector(".close-btn"),x=l.querySelector(".cancel-btn"),$=()=>{const t=C[d];k.innerHTML=t.map(n=>`
|
|
41
|
+
<button type="button" data-formula="${n.formula.replace(/"/g,""")}" title="${n.description}" style="padding: 8px; border: 1px solid ${e.fieldBorder}; border-radius: 4px; background: ${e.templateBtnBg}; cursor: pointer; text-align: left;">
|
|
42
|
+
<div style="font-weight: 600; font-size: 12px; color: ${e.templateBtnText};">${n.name}</div>
|
|
43
|
+
<div style="font-size: 10px; color: ${e.templateSubText}; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">${n.formula.substring(0,20)}...</div>
|
|
44
|
+
</button>
|
|
45
|
+
`).join(""),k.querySelectorAll("button").forEach(n=>{const r=n;r.onmouseover=()=>{r.style.background=e.templateBtnHover},r.onmouseout=()=>{r.style.background=e.templateBtnBg},n.addEventListener("click",()=>{c.value=n.getAttribute("data-formula")||"",u=c.value,b()})})},b=()=>{const t=c.value.trim();if(!t){f.innerHTML=`<span style="color: ${e.previewText};">Enter a formula to see preview</span>`,m.disabled=!0;return}m.disabled=!1;try{if(d==="latex"){const n=window.katex;f.innerHTML=n.renderToString(t,{displayMode:!1,throwOnError:!1})}else t.trim().startsWith("<math")?f.innerHTML=t:f.innerHTML=`<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline">${t}</math>`}catch{f.innerHTML=`<span style="color: ${e.invalid};">Invalid formula</span>`}},g=()=>document.body.removeChild(i);p.onmouseover=()=>{p.style.color="#f8fafc",p.style.background=o?"#334155":"#e5e7eb",p.style.borderRadius="4px"},p.onmouseout=()=>{p.style.color=e.muted,p.style.background="none"},x.onmouseover=()=>{x.style.background=o?"#475569":"#f3f4f6"},x.onmouseout=()=>{x.style.background=e.cancelBg},m.onmouseover=()=>{m.disabled||(m.style.background=e.insertHover)},m.onmouseout=()=>{m.style.background=e.insertBg};const B=()=>{const t=c.value.trim();if(!t)return;const n={formula:t,format:d,inline:L.checked},r=n.inline?document.createElement("span"):document.createElement("div");if(r.className=n.inline?"math-formula":"math-block",r.setAttribute("data-math-formula",t),r.setAttribute("data-math-format",d),r.contentEditable="false",r.style.cssText=n.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;",d==="latex"){const v=window.katex;try{r.innerHTML=v.renderToString(t,{displayMode:!n.inline,throwOnError:!1})}catch{r.textContent=n.inline?`$${t}$`:`$$${t}$$`}}else if(t.trim().startsWith("<math"))r.innerHTML=t;else{const v=`<math xmlns="http://www.w3.org/1998/Math/MathML" display="${n.inline?"inline":"block"}">${t}</math>`;r.innerHTML=v}w?w.replaceWith(r):h&&(h.deleteContents(),h.insertNode(r)),g()};p.addEventListener("click",g),x.addEventListener("click",g),m.addEventListener("click",B),i.addEventListener("click",t=>{t.target===i&&g()}),S.forEach(t=>{t.addEventListener("change",n=>{d=n.target.value,$(),b()})}),c.addEventListener("input",()=>{u=c.value,b()}),c.addEventListener("keydown",t=>{(t.ctrlKey||t.metaKey)&&t.key==="Enter"&&(t.preventDefault(),B())}),$(),b(),c.focus()};if(typeof window<"u"&&!window.__mathPluginDoubleClickInitialized){window.__mathPluginDoubleClickInitialized=!0;const a=o=>{const i=o.target.closest(".math-formula, .math-block");if(i){o.preventDefault(),o.stopPropagation(),o.stopImmediatePropagation(),w=i;const l=i.getAttribute("data-math-formula")||"",d=i.getAttribute("data-math-format")||"latex",u=i.classList.contains("math-formula");T({formula:l,format:d,inline:u})}},s=()=>{document.addEventListener("dblclick",a,{capture:!0})};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",s):setTimeout(s,100)}const z=()=>({name:"math",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:()=>(T(),!0)},keymap:{"Mod-Shift-m":"insertMath"}});exports.MathPlugin=z;
|
package/dist/math.esm.js
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
const C = {
|
|
2
|
+
latex: [
|
|
3
|
+
{ name: "Fraction", formula: "\\frac{a}{b}", description: "Simple fraction" },
|
|
4
|
+
{ name: "Square Root", formula: "\\sqrt{x}", description: "Square root" },
|
|
5
|
+
{ name: "Power", formula: "x^{2}", description: "Exponent/power" },
|
|
6
|
+
{ name: "Subscript", formula: "x_{sub}", description: "Subscript" },
|
|
7
|
+
{ name: "Integral", formula: "\\int_{a}^{b} f(x) \\, dx", description: "Definite integral" },
|
|
8
|
+
{ name: "Summation", formula: "\\sum_{i=1}^{n} x_{i}", description: "Summation" },
|
|
9
|
+
{ name: "Limit", formula: "\\lim_{x \\to 0} f(x)", description: "Limit" },
|
|
10
|
+
{ name: "Derivative", formula: "\\frac{d}{dx} f(x)", description: "Derivative" },
|
|
11
|
+
{ name: "Matrix 2x2", formula: "\\begin{pmatrix} a & b \\\\ c & d \\end{pmatrix}", description: "2x2 matrix" },
|
|
12
|
+
{ name: "System", formula: "\\begin{cases} x + y = 1 \\\\ 2x - y = 0 \\end{cases}", description: "System of equations" }
|
|
13
|
+
],
|
|
14
|
+
mathml: [
|
|
15
|
+
{ name: "Fraction", formula: "<mfrac><mi>a</mi><mi>b</mi></mfrac>", description: "Simple fraction" },
|
|
16
|
+
{ name: "Square Root", formula: "<msqrt><mi>x</mi></msqrt>", description: "Square root" },
|
|
17
|
+
{ name: "Power", formula: "<msup><mi>x</mi><mn>2</mn></msup>", description: "Exponent/power" },
|
|
18
|
+
{ name: "Subscript", formula: "<msub><mi>x</mi><mi>sub</mi></msub>", description: "Subscript" },
|
|
19
|
+
{ name: "Parentheses", formula: '<mfenced open="(" close=")"><mi>a</mi><mo>+</mo><mi>b</mi></mfenced>', description: "Grouped expression" }
|
|
20
|
+
]
|
|
21
|
+
};
|
|
22
|
+
let h = null, w = null, E = !1;
|
|
23
|
+
const y = '[data-theme="dark"], .dark, .editora-theme-dark', q = () => new Promise((a, s) => {
|
|
24
|
+
if (window.katex) {
|
|
25
|
+
a(window.katex);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (E) {
|
|
29
|
+
const i = setInterval(() => {
|
|
30
|
+
window.katex && (clearInterval(i), a(window.katex));
|
|
31
|
+
}, 100);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
E = !0;
|
|
35
|
+
const o = document.createElement("link");
|
|
36
|
+
o.rel = "stylesheet", o.href = "https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css", document.head.appendChild(o);
|
|
37
|
+
const e = document.createElement("script");
|
|
38
|
+
e.src = "https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.js", e.onload = () => a(window.katex), e.onerror = s, document.head.appendChild(e);
|
|
39
|
+
}), H = () => {
|
|
40
|
+
const a = window.getSelection();
|
|
41
|
+
if (a && a.rangeCount > 0) {
|
|
42
|
+
const o = a.getRangeAt(0).startContainer;
|
|
43
|
+
if ((o.nodeType === Node.ELEMENT_NODE ? o : o.parentElement)?.closest(y)) return !0;
|
|
44
|
+
}
|
|
45
|
+
return document.activeElement?.closest(y) ? !0 : document.body.matches(y) || document.documentElement.matches(y);
|
|
46
|
+
}, T = async (a) => {
|
|
47
|
+
const s = window.getSelection();
|
|
48
|
+
s && s.rangeCount > 0 && (h = s.getRangeAt(0).cloneRange()), await q();
|
|
49
|
+
const o = H(), e = o ? {
|
|
50
|
+
overlay: "rgba(0, 0, 0, 0.62)",
|
|
51
|
+
dialogBg: "#1f2937",
|
|
52
|
+
border: "#3b4657",
|
|
53
|
+
panelBg: "#222d3a",
|
|
54
|
+
fieldBg: "#111827",
|
|
55
|
+
fieldBorder: "#4b5563",
|
|
56
|
+
text: "#e2e8f0",
|
|
57
|
+
muted: "#94a3b8",
|
|
58
|
+
templateBtnBg: "#273244",
|
|
59
|
+
templateBtnHover: "#334155",
|
|
60
|
+
templateBtnText: "#dbe7f7",
|
|
61
|
+
templateSubText: "#9fb0c6",
|
|
62
|
+
previewBg: "#111827",
|
|
63
|
+
previewText: "#cbd5e1",
|
|
64
|
+
cancelBg: "#334155",
|
|
65
|
+
cancelText: "#e2e8f0",
|
|
66
|
+
cancelBorder: "#4b5563",
|
|
67
|
+
insertBg: "#3b82f6",
|
|
68
|
+
insertHover: "#2563eb",
|
|
69
|
+
invalid: "#f87171"
|
|
70
|
+
} : {
|
|
71
|
+
overlay: "rgba(0, 0, 0, 0.5)",
|
|
72
|
+
dialogBg: "#ffffff",
|
|
73
|
+
border: "#e1e5e9",
|
|
74
|
+
panelBg: "#f8f9fa",
|
|
75
|
+
fieldBg: "#ffffff",
|
|
76
|
+
fieldBorder: "#ced4da",
|
|
77
|
+
text: "#1f2937",
|
|
78
|
+
muted: "#6c757d",
|
|
79
|
+
templateBtnBg: "#ffffff",
|
|
80
|
+
templateBtnHover: "#f8f9fa",
|
|
81
|
+
templateBtnText: "#1f2937",
|
|
82
|
+
templateSubText: "#6c757d",
|
|
83
|
+
previewBg: "#f8f9fa",
|
|
84
|
+
previewText: "#6c757d",
|
|
85
|
+
cancelBg: "#ffffff",
|
|
86
|
+
cancelText: "#1f2937",
|
|
87
|
+
cancelBorder: "#ced4da",
|
|
88
|
+
insertBg: "#007bff",
|
|
89
|
+
insertHover: "#0069d9",
|
|
90
|
+
invalid: "#cc0000"
|
|
91
|
+
}, i = document.createElement("div");
|
|
92
|
+
i.style.cssText = `position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: ${e.overlay}; display: flex; align-items: center; justify-content: center; z-index: 99999;`;
|
|
93
|
+
const l = document.createElement("div");
|
|
94
|
+
l.style.cssText = `background: ${e.dialogBg}; border: 1px solid ${e.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: ${e.text};`;
|
|
95
|
+
let d = a?.format || "latex", u = a?.formula || "", M = a?.inline !== !1;
|
|
96
|
+
l.innerHTML = `
|
|
97
|
+
<div style="display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid ${e.border}; background: ${e.panelBg};">
|
|
98
|
+
<h2 style="margin: 0; font-size: 18px; font-weight: 600; color: ${e.text};">${a ? "Edit" : "Insert"} Math Formula</h2>
|
|
99
|
+
<button class="close-btn" style="background: none; border: none; font-size: 28px; cursor: pointer; color: ${e.muted}; padding: 0; width: 30px; height: 30px; line-height: 1;">×</button>
|
|
100
|
+
</div>
|
|
101
|
+
|
|
102
|
+
<div style="padding: 20px; overflow-y: auto; flex: 1;">
|
|
103
|
+
<div style="margin-bottom: 20px;">
|
|
104
|
+
<label style="display: block; font-weight: 600; margin-bottom: 8px; font-size: 14px; color: ${e.text};">Format:</label>
|
|
105
|
+
<div style="display: flex; gap: 16px;">
|
|
106
|
+
<label style="cursor: pointer; color: ${e.text};"><input type="radio" name="format" value="latex" ${d === "latex" ? "checked" : ""} style="margin-right: 6px;"> LaTeX</label>
|
|
107
|
+
<label style="cursor: pointer; color: ${e.text};"><input type="radio" name="format" value="mathml" ${d === "mathml" ? "checked" : ""} style="margin-right: 6px;"> MathML</label>
|
|
108
|
+
</div>
|
|
109
|
+
</div>
|
|
110
|
+
|
|
111
|
+
<div style="margin-bottom: 20px;">
|
|
112
|
+
<label style="display: block; font-weight: 600; margin-bottom: 8px; font-size: 14px; color: ${e.text};">Quick Templates:</label>
|
|
113
|
+
<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>
|
|
114
|
+
</div>
|
|
115
|
+
|
|
116
|
+
<div style="margin-bottom: 20px;">
|
|
117
|
+
<label style="cursor: pointer; color: ${e.text};"><input type="checkbox" id="inline-cb" ${M ? "checked" : ""} style="margin-right: 8px;"> Inline math</label>
|
|
118
|
+
</div>
|
|
119
|
+
|
|
120
|
+
<div style="margin-bottom: 20px;">
|
|
121
|
+
<label style="display: block; font-weight: 600; margin-bottom: 8px; font-size: 14px; color: ${e.text};">Formula:</label>
|
|
122
|
+
<textarea id="formula-input" rows="4" style="width: 100%; padding: 10px; border: 1px solid ${e.fieldBorder}; border-radius: 4px; font-family: 'Courier New', monospace; font-size: 14px; background: ${e.fieldBg}; color: ${e.text};">${u}</textarea>
|
|
123
|
+
</div>
|
|
124
|
+
|
|
125
|
+
<div style="margin-bottom: 20px;">
|
|
126
|
+
<label style="display: block; font-weight: 600; margin-bottom: 8px; font-size: 14px; color: ${e.text};">Preview:</label>
|
|
127
|
+
<div id="preview-area" style="min-height: 60px; padding: 15px; border: 1px solid ${e.fieldBorder}; border-radius: 4px; background: ${e.previewBg}; display: flex; align-items: center; justify-content: center; color: ${e.previewText};"></div>
|
|
128
|
+
</div>
|
|
129
|
+
</div>
|
|
130
|
+
|
|
131
|
+
<div style="display: flex; justify-content: flex-end; gap: 10px; padding: 16px 20px; border-top: 1px solid ${e.border}; background: ${e.panelBg};">
|
|
132
|
+
<button class="cancel-btn" style="padding: 10px 20px; background: ${e.cancelBg}; color: ${e.cancelText}; border: 1px solid ${e.cancelBorder}; border-radius: 4px; cursor: pointer; font-size: 14px;">Cancel</button>
|
|
133
|
+
<button id="insert-btn" style="padding: 10px 20px; background: ${e.insertBg}; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 14px;" disabled>${a ? "Update" : "Insert"}</button>
|
|
134
|
+
</div>
|
|
135
|
+
`, i.appendChild(l), document.body.appendChild(i);
|
|
136
|
+
const c = l.querySelector("#formula-input"), f = l.querySelector("#preview-area"), k = l.querySelector("#templates-grid"), L = l.querySelectorAll('input[name="format"]'), S = l.querySelector("#inline-cb"), m = l.querySelector("#insert-btn"), p = l.querySelector(".close-btn"), x = l.querySelector(".cancel-btn"), $ = () => {
|
|
137
|
+
const t = C[d];
|
|
138
|
+
k.innerHTML = t.map((n) => `
|
|
139
|
+
<button type="button" data-formula="${n.formula.replace(/"/g, """)}" title="${n.description}" style="padding: 8px; border: 1px solid ${e.fieldBorder}; border-radius: 4px; background: ${e.templateBtnBg}; cursor: pointer; text-align: left;">
|
|
140
|
+
<div style="font-weight: 600; font-size: 12px; color: ${e.templateBtnText};">${n.name}</div>
|
|
141
|
+
<div style="font-size: 10px; color: ${e.templateSubText}; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">${n.formula.substring(0, 20)}...</div>
|
|
142
|
+
</button>
|
|
143
|
+
`).join(""), k.querySelectorAll("button").forEach((n) => {
|
|
144
|
+
const r = n;
|
|
145
|
+
r.onmouseover = () => {
|
|
146
|
+
r.style.background = e.templateBtnHover;
|
|
147
|
+
}, r.onmouseout = () => {
|
|
148
|
+
r.style.background = e.templateBtnBg;
|
|
149
|
+
}, n.addEventListener("click", () => {
|
|
150
|
+
c.value = n.getAttribute("data-formula") || "", u = c.value, b();
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
}, b = () => {
|
|
154
|
+
const t = c.value.trim();
|
|
155
|
+
if (!t) {
|
|
156
|
+
f.innerHTML = `<span style="color: ${e.previewText};">Enter a formula to see preview</span>`, m.disabled = !0;
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
m.disabled = !1;
|
|
160
|
+
try {
|
|
161
|
+
if (d === "latex") {
|
|
162
|
+
const n = window.katex;
|
|
163
|
+
f.innerHTML = n.renderToString(t, { displayMode: !1, throwOnError: !1 });
|
|
164
|
+
} else
|
|
165
|
+
t.trim().startsWith("<math") ? f.innerHTML = t : f.innerHTML = `<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline">${t}</math>`;
|
|
166
|
+
} catch {
|
|
167
|
+
f.innerHTML = `<span style="color: ${e.invalid};">Invalid formula</span>`;
|
|
168
|
+
}
|
|
169
|
+
}, g = () => document.body.removeChild(i);
|
|
170
|
+
p.onmouseover = () => {
|
|
171
|
+
p.style.color = "#f8fafc", p.style.background = o ? "#334155" : "#e5e7eb", p.style.borderRadius = "4px";
|
|
172
|
+
}, p.onmouseout = () => {
|
|
173
|
+
p.style.color = e.muted, p.style.background = "none";
|
|
174
|
+
}, x.onmouseover = () => {
|
|
175
|
+
x.style.background = o ? "#475569" : "#f3f4f6";
|
|
176
|
+
}, x.onmouseout = () => {
|
|
177
|
+
x.style.background = e.cancelBg;
|
|
178
|
+
}, m.onmouseover = () => {
|
|
179
|
+
m.disabled || (m.style.background = e.insertHover);
|
|
180
|
+
}, m.onmouseout = () => {
|
|
181
|
+
m.style.background = e.insertBg;
|
|
182
|
+
};
|
|
183
|
+
const B = () => {
|
|
184
|
+
const t = c.value.trim();
|
|
185
|
+
if (!t) return;
|
|
186
|
+
const n = { formula: t, format: d, inline: S.checked }, r = n.inline ? document.createElement("span") : document.createElement("div");
|
|
187
|
+
if (r.className = n.inline ? "math-formula" : "math-block", r.setAttribute("data-math-formula", t), r.setAttribute("data-math-format", d), r.contentEditable = "false", r.style.cssText = n.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;", d === "latex") {
|
|
188
|
+
const v = window.katex;
|
|
189
|
+
try {
|
|
190
|
+
r.innerHTML = v.renderToString(t, {
|
|
191
|
+
displayMode: !n.inline,
|
|
192
|
+
throwOnError: !1
|
|
193
|
+
});
|
|
194
|
+
} catch {
|
|
195
|
+
r.textContent = n.inline ? `$${t}$` : `$$${t}$$`;
|
|
196
|
+
}
|
|
197
|
+
} else if (t.trim().startsWith("<math"))
|
|
198
|
+
r.innerHTML = t;
|
|
199
|
+
else {
|
|
200
|
+
const v = `<math xmlns="http://www.w3.org/1998/Math/MathML" display="${n.inline ? "inline" : "block"}">${t}</math>`;
|
|
201
|
+
r.innerHTML = v;
|
|
202
|
+
}
|
|
203
|
+
w ? w.replaceWith(r) : h && (h.deleteContents(), h.insertNode(r)), g();
|
|
204
|
+
};
|
|
205
|
+
p.addEventListener("click", g), x.addEventListener("click", g), m.addEventListener("click", B), i.addEventListener("click", (t) => {
|
|
206
|
+
t.target === i && g();
|
|
207
|
+
}), L.forEach((t) => {
|
|
208
|
+
t.addEventListener("change", (n) => {
|
|
209
|
+
d = n.target.value, $(), b();
|
|
210
|
+
});
|
|
211
|
+
}), c.addEventListener("input", () => {
|
|
212
|
+
u = c.value, b();
|
|
213
|
+
}), c.addEventListener("keydown", (t) => {
|
|
214
|
+
(t.ctrlKey || t.metaKey) && t.key === "Enter" && (t.preventDefault(), B());
|
|
215
|
+
}), $(), b(), c.focus();
|
|
216
|
+
};
|
|
217
|
+
if (typeof window < "u" && !window.__mathPluginDoubleClickInitialized) {
|
|
218
|
+
window.__mathPluginDoubleClickInitialized = !0;
|
|
219
|
+
const a = (o) => {
|
|
220
|
+
const i = o.target.closest(".math-formula, .math-block");
|
|
221
|
+
if (i) {
|
|
222
|
+
o.preventDefault(), o.stopPropagation(), o.stopImmediatePropagation(), w = i;
|
|
223
|
+
const l = i.getAttribute("data-math-formula") || "", d = i.getAttribute("data-math-format") || "latex", u = i.classList.contains("math-formula");
|
|
224
|
+
T({ formula: l, format: d, inline: u });
|
|
225
|
+
}
|
|
226
|
+
}, s = () => {
|
|
227
|
+
document.addEventListener("dblclick", a, { capture: !0 });
|
|
228
|
+
};
|
|
229
|
+
document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", s) : setTimeout(s, 100);
|
|
230
|
+
}
|
|
231
|
+
const z = () => ({
|
|
232
|
+
name: "math",
|
|
233
|
+
toolbar: [
|
|
234
|
+
{
|
|
235
|
+
label: "Insert Math",
|
|
236
|
+
command: "insertMath",
|
|
237
|
+
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>'
|
|
238
|
+
}
|
|
239
|
+
],
|
|
240
|
+
commands: {
|
|
241
|
+
insertMath: () => (T(), !0)
|
|
242
|
+
},
|
|
243
|
+
keymap: {
|
|
244
|
+
"Mod-Shift-m": "insertMath"
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
export {
|
|
248
|
+
z as MathPlugin
|
|
249
|
+
};
|