overtype 2.1.0 → 2.2.0
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 +26 -18
- package/dist/overtype-webcomponent.esm.js +3672 -2122
- package/dist/overtype-webcomponent.esm.js.map +4 -4
- package/dist/overtype-webcomponent.js +3667 -2117
- package/dist/overtype-webcomponent.js.map +4 -4
- package/dist/overtype-webcomponent.min.js +106 -93
- package/dist/overtype.cjs +3644 -2121
- package/dist/overtype.cjs.map +4 -4
- package/dist/overtype.d.ts +16 -0
- package/dist/overtype.esm.js +3644 -2121
- package/dist/overtype.esm.js.map +4 -4
- package/dist/overtype.js +3621 -2098
- package/dist/overtype.js.map +4 -4
- package/dist/overtype.min.js +107 -94
- package/package.json +4 -4
- package/src/icons.js +6 -0
- package/src/link-tooltip.js +40 -71
- package/src/overtype-webcomponent.js +32 -3
- package/src/overtype.d.ts +16 -0
- package/src/overtype.js +403 -38
- package/src/parser.js +9 -3
- package/src/shortcuts.js +11 -76
- package/src/styles.js +36 -28
- package/src/themes.js +14 -0
- package/src/toolbar-buttons.js +48 -12
- package/src/toolbar.js +39 -48
package/dist/overtype.min.js
CHANGED
|
@@ -1,40 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* OverType v2.0
|
|
2
|
+
* OverType v2.2.0
|
|
3
3
|
* A lightweight markdown editor library with perfect WYSIWYG alignment
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @author David Miranda
|
|
6
6
|
* https://github.com/panphora/overtype
|
|
7
7
|
*/
|
|
8
|
-
var OverType=(()=>{var
|
|
9
|
-
`),a=!1,d=s.map((l,
|
|
8
|
+
var OverType=(()=>{var ve=Object.defineProperty;var cn=Object.getOwnPropertyDescriptor;var pn=Object.getOwnPropertyNames;var dn=Object.prototype.hasOwnProperty;var un=(t,e,n)=>e in t?ve(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var hn=(t,e)=>{for(var n in e)ve(t,n,{get:e[n],enumerable:!0})},fn=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of pn(e))!dn.call(t,i)&&i!==n&&ve(t,i,{get:()=>e[i],enumerable:!(o=cn(e,i))||o.enumerable});return t};var mn=t=>fn(ve({},"__esModule",{value:!0}),t);var C=(t,e,n)=>(un(t,typeof e!="symbol"?e+"":e,n),n);var ao={};hn(ao,{OverType:()=>z,default:()=>so,defaultToolbarButtons:()=>oe,toolbarButtons:()=>S});var T=class{static resetLinkIndex(){this.linkIndex=0}static setCodeHighlighter(e){this.codeHighlighter=e}static setCustomSyntax(e){this.customSyntax=e}static applyCustomSyntax(e){return this.customSyntax?this.customSyntax(e):e}static escapeHtml(e){let n={"&":"&","<":"<",">":">",'"':""","'":"'"};return e.replace(/[&<>"']/g,o=>n[o])}static preserveIndentation(e,n){let i=n.match(/^(\s*)/)[1].replace(/ /g," ");return e.replace(/^\s*/,i)}static parseHeader(e){return e.replace(/^(#{1,3})\s(.+)$/,(n,o,i)=>{let r=o.length;return i=this.parseInlineElements(i),`<h${r}><span class="syntax-marker">${o} </span>${i}</h${r}>`})}static parseHorizontalRule(e){return e.match(/^(-{3,}|\*{3,}|_{3,})$/)?`<div><span class="hr-marker">${e}</span></div>`:null}static parseBlockquote(e){return e.replace(/^> (.+)$/,(n,o)=>`<span class="blockquote"><span class="syntax-marker">></span> ${o}</span>`)}static parseBulletList(e){return e.replace(/^((?: )*)([-*+])\s(.+)$/,(n,o,i,r)=>(r=this.parseInlineElements(r),`${o}<li class="bullet-list"><span class="syntax-marker">${i} </span>${r}</li>`))}static parseTaskList(e,n=!1){return e.replace(/^((?: )*)-\s+\[([ xX])\]\s+(.+)$/,(o,i,r,s)=>{if(s=this.parseInlineElements(s),n){let a=r.toLowerCase()==="x";return`${i}<li class="task-list"><input type="checkbox" ${a?"checked":""}> ${s}</li>`}else return`${i}<li class="task-list"><span class="syntax-marker">- [${r}] </span>${s}</li>`})}static parseNumberedList(e){return e.replace(/^((?: )*)(\d+\.)\s(.+)$/,(n,o,i,r)=>(r=this.parseInlineElements(r),`${o}<li class="ordered-list"><span class="syntax-marker">${i} </span>${r}</li>`))}static parseCodeBlock(e){return/^`{3}[^`]*$/.test(e)?`<div><span class="code-fence">${e}</span></div>`:null}static parseBold(e){return e=e.replace(/\*\*(.+?)\*\*/g,'<strong><span class="syntax-marker">**</span>$1<span class="syntax-marker">**</span></strong>'),e=e.replace(/__(.+?)__/g,'<strong><span class="syntax-marker">__</span>$1<span class="syntax-marker">__</span></strong>'),e}static parseItalic(e){return e=e.replace(new RegExp("(?<![\\*>])\\*(?!\\*)(.+?)(?<!\\*)\\*(?!\\*)","g"),'<em><span class="syntax-marker">*</span>$1<span class="syntax-marker">*</span></em>'),e=e.replace(new RegExp("(?<=^|\\s)_(?!_)(.+?)(?<!_)_(?!_)(?=\\s|$)","g"),'<em><span class="syntax-marker">_</span>$1<span class="syntax-marker">_</span></em>'),e}static parseStrikethrough(e){return e=e.replace(new RegExp("(?<!~)~~(?!~)(.+?)(?<!~)~~(?!~)","g"),'<del><span class="syntax-marker">~~</span>$1<span class="syntax-marker">~~</span></del>'),e=e.replace(new RegExp("(?<!~)~(?!~)(.+?)(?<!~)~(?!~)","g"),'<del><span class="syntax-marker">~</span>$1<span class="syntax-marker">~</span></del>'),e}static parseInlineCode(e){return e.replace(new RegExp("(?<!`)(`+)(?!`)((?:(?!\\1).)+?)(\\1)(?!`)","g"),'<code><span class="syntax-marker">$1</span>$2<span class="syntax-marker">$3</span></code>')}static sanitizeUrl(e){let n=e.trim(),o=n.toLowerCase(),r=["http://","https://","mailto:","ftp://","ftps://"].some(a=>o.startsWith(a)),s=n.startsWith("/")||n.startsWith("#")||n.startsWith("?")||n.startsWith(".")||!n.includes(":")&&!n.includes("//");return r||s?e:"#"}static parseLinks(e){return e.replace(/\[(.+?)\]\((.+?)\)/g,(n,o,i)=>{let r=`--link-${this.linkIndex++}`;return`<a href="${this.sanitizeUrl(i)}" style="anchor-name: ${r}"><span class="syntax-marker">[</span>${o}<span class="syntax-marker url-part">](${i})</span></a>`})}static identifyAndProtectSanctuaries(e){let n=new Map,o=0,i=e,r=[],s=/\[([^\]]+)\]\(([^)]+)\)/g,a;for(;(a=s.exec(e))!==null;){let h=a.index+a[0].indexOf("](")+2,u=h+a[2].length;r.push({start:h,end:u})}let c=new RegExp("(?<!`)(`+)(?!`)((?:(?!\\1).)+?)(\\1)(?!`)","g"),d,l=[];for(;(d=c.exec(e))!==null;){let p=d.index,h=d.index+d[0].length;r.some(f=>p>=f.start&&h<=f.end)||l.push({match:d[0],index:d.index,openTicks:d[1],content:d[2],closeTicks:d[3]})}return l.sort((p,h)=>h.index-p.index),l.forEach(p=>{let h=`\uE000${o++}\uE001`;n.set(h,{type:"code",original:p.match,openTicks:p.openTicks,content:p.content,closeTicks:p.closeTicks}),i=i.substring(0,p.index)+h+i.substring(p.index+p.match.length)}),i=i.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(p,h,u)=>{let f=`\uE000${o++}\uE001`;return n.set(f,{type:"link",original:p,linkText:h,url:u}),f}),{protectedText:i,sanctuaries:n}}static restoreAndTransformSanctuaries(e,n){return Array.from(n.keys()).sort((i,r)=>{let s=e.indexOf(i),a=e.indexOf(r);return s-a}).forEach(i=>{let r=n.get(i),s;if(r.type==="code")s=`<code><span class="syntax-marker">${r.openTicks}</span>${r.content}<span class="syntax-marker">${r.closeTicks}</span></code>`;else if(r.type==="link"){let a=r.linkText;n.forEach((l,p)=>{if(a.includes(p)&&l.type==="code"){let h=`<code><span class="syntax-marker">${l.openTicks}</span>${l.content}<span class="syntax-marker">${l.closeTicks}</span></code>`;a=a.replace(p,h)}}),a=this.parseStrikethrough(a),a=this.parseBold(a),a=this.parseItalic(a);let c=`--link-${this.linkIndex++}`;s=`<a href="${this.sanitizeUrl(r.url)}" style="anchor-name: ${c}"><span class="syntax-marker">[</span>${a}<span class="syntax-marker url-part">](${r.url})</span></a>`}e=e.replace(i,s)}),e}static parseInlineElements(e){let{protectedText:n,sanctuaries:o}=this.identifyAndProtectSanctuaries(e),i=n;return i=this.parseStrikethrough(i),i=this.parseBold(i),i=this.parseItalic(i),i=this.restoreAndTransformSanctuaries(i,o),i}static parseLine(e,n=!1){let o=this.escapeHtml(e);o=this.preserveIndentation(o,e);let i=this.parseHorizontalRule(o);if(i)return i;let r=this.parseCodeBlock(o);return r||(o=this.parseHeader(o),o=this.parseBlockquote(o),o=this.parseTaskList(o,n),o=this.parseBulletList(o),o=this.parseNumberedList(o),!o.includes("<li")&&!o.includes("<h")&&(o=this.parseInlineElements(o)),o.trim()===""?"<div> </div>":`<div>${o}</div>`)}static parse(e,n=-1,o=!1,i,r=!1){this.resetLinkIndex();let s=e.split(`
|
|
9
|
+
`),a=!1,d=s.map((l,p)=>{if(o&&p===n)return`<div class="raw-line">${this.escapeHtml(l)||" "}</div>`;if(/^```[^`]*$/.test(l))return a=!a,this.applyCustomSyntax(this.parseLine(l,r));if(a){let u=this.escapeHtml(l);return`<div>${this.preserveIndentation(u,l)||" "}</div>`}return this.applyCustomSyntax(this.parseLine(l,r))}).join("");return this.postProcessHTML(d,i)}static postProcessHTML(e,n){if(typeof document>"u"||!document)return this.postProcessHTMLManual(e,n);let o=document.createElement("div");o.innerHTML=e;let i=null,r=null,s=null,a=!1,c=Array.from(o.children);for(let d=0;d<c.length;d++){let l=c[d];if(!l.parentNode)continue;let p=l.querySelector(".code-fence");if(p){let u=p.textContent;if(u.startsWith("```"))if(a){let f=n||this.codeHighlighter;if(s&&f&&s._codeContent)try{let m=f(s._codeContent,s._language||"");m&&typeof m.then=="function"?console.warn("Async highlighters are not supported in parse() because it returns an HTML string. The caller creates new DOM elements from that string, breaking references to the elements we would update. Use synchronous highlighters only."):m&&typeof m=="string"&&m.trim()&&(s._codeElement.innerHTML=m)}catch(m){console.warn("Code highlighting failed:",m)}a=!1,s=null;continue}else{a=!0,s=document.createElement("pre");let f=document.createElement("code");s.appendChild(f),s.className="code-block";let m=u.slice(3).trim();m&&(f.className=`language-${m}`),o.insertBefore(s,l.nextSibling),s._codeElement=f,s._language=m,s._codeContent="";continue}}if(a&&s&&l.tagName==="DIV"&&!l.querySelector(".code-fence")){let u=s._codeElement||s.querySelector("code");s._codeContent.length>0&&(s._codeContent+=`
|
|
10
10
|
`);let f=l.textContent.replace(/\u00A0/g," ");s._codeContent+=f,u.textContent.length>0&&(u.textContent+=`
|
|
11
|
-
`),u.textContent+=f,l.remove();continue}let h=null;if(l.tagName==="DIV"&&(h=l.querySelector("li")),h){let u=h.classList.contains("bullet-list"),f=h.classList.contains("ordered-list");if(!u&&!f){i=null,r=null;continue}let m=u?"ul":"ol";(!i||r!==m)&&(i=document.createElement(m),
|
|
12
|
-
`),
|
|
13
|
-
`),i=0,r=0,s=0;for(let h=0;h<
|
|
14
|
-
`),
|
|
15
|
-
`)}};
|
|
16
|
-
`)
|
|
17
|
-
`).length>1}function Ke(o,e){let t=e;for(;o[t]&&o[t-1]!=null&&!o[t-1].match(/\s/);)t--;return t}function Ze(o,e,t){let n=e,i=t?/\n/:/\s/;for(;o[n]&&!o[n].match(i);)n++;return n}function pe(o){let e=o.value.split(`
|
|
18
|
-
`),t=0;for(let n=0;n<e.length;n++){let i=e[n].length+1;o.selectionStart>=t&&o.selectionStart<t+i&&(o.selectionStart=t),o.selectionEnd>=t&&o.selectionEnd<t+i&&(n===e.length-1?o.selectionEnd=Math.min(t+e[n].length,o.value.length):o.selectionEnd=t+i-1),t+=i}}function Je(o,e,t,n=!1){if(o.selectionStart===o.selectionEnd)o.selectionStart=Ke(o.value,o.selectionStart),o.selectionEnd=Ze(o.value,o.selectionEnd,n);else{let i=o.selectionStart-e.length,r=o.selectionEnd+t.length,s=o.value.slice(i,o.selectionStart)===e,a=o.value.slice(o.selectionEnd,r)===t;s&&a&&(o.selectionStart=i,o.selectionEnd=r)}return o.value.slice(o.selectionStart,o.selectionEnd)}function Q(o){let e=o.value.slice(0,o.selectionStart),t=o.value.slice(o.selectionEnd),n=e.match(/\n*$/),i=t.match(/^\n*/),r=n?n[0].length:0,s=i?i[0].length:0,a="",p="";return e.match(/\S/)&&r<2&&(a=`
|
|
19
|
-
`.repeat(2-r)),t.match(/\S/)&&s<2&&(p=`
|
|
20
|
-
`.repeat(2-s)),{newlinesToAppend:a,newlinesToPrepend:p}}function R(o,e,t={}){let n=o.selectionStart,i=o.selectionEnd,r=n===i,s=o.value,a=n;for(;a>0&&s[a-1]!==`
|
|
21
|
-
`;)a--;if(r){let d=n;for(;d<s.length&&s[d]!==`
|
|
22
|
-
`;)d++;o.selectionStart=a,o.selectionEnd=d}else pe(o);let p=e(o);if(t.adjustSelection){let l=o.value.slice(o.selectionStart,o.selectionEnd).startsWith(t.prefix),c=t.adjustSelection(l,n,i,a);p.selectionStart=c.start,p.selectionEnd=c.end}else if(t.prefix){let l=o.value.slice(o.selectionStart,o.selectionEnd).startsWith(t.prefix);r?l?(p.selectionStart=Math.max(n-t.prefix.length,a),p.selectionEnd=p.selectionStart):(p.selectionStart=n+t.prefix.length,p.selectionEnd=p.selectionStart):l?(p.selectionStart=Math.max(n-t.prefix.length,a),p.selectionEnd=Math.max(i-t.prefix.length,a)):(p.selectionStart=n+t.prefix.length,p.selectionEnd=i+t.prefix.length)}return p}function V(o,e){let t,n,{prefix:i,suffix:r,blockPrefix:s,blockSuffix:a,replaceNext:p,prefixSpace:d,scanFor:l,surroundWithNewlines:c,trimFirst:h}=e,u=o.selectionStart,f=o.selectionEnd,m=o.value.slice(o.selectionStart,o.selectionEnd),g=se(m)&&s&&s.length>0?`${s}
|
|
23
|
-
`:i,v=se(m)&&a&&a.length>0?`
|
|
24
|
-
${a}`:r;if(d){let L=o.value[o.selectionStart-1];o.selectionStart!==0&&L!=null&&!L.match(/\s/)&&(g=` ${g}`)}m=Je(o,g,v,e.multiline);let b=o.selectionStart,x=o.selectionEnd,M=p&&p.length>0&&v.indexOf(p)>-1&&m.length>0;if(c){let L=Q(o);t=L.newlinesToAppend,n=L.newlinesToPrepend,g=t+i,v+=n}if(m.startsWith(g)&&m.endsWith(v)){let L=m.slice(g.length,m.length-v.length);if(u===f){let T=u-g.length;T=Math.max(T,b),T=Math.min(T,b+L.length),b=x=T}else x=b+L.length;return{text:L,selectionStart:b,selectionEnd:x}}else if(M)if(l&&l.length>0&&m.match(l)){v=v.replace(p,m);let L=g+v;return b=x=b+g.length,{text:L,selectionStart:b,selectionEnd:x}}else{let L=g+m+v;return b=b+g.length+m.length+v.indexOf(p),x=b+p.length,{text:L,selectionStart:b,selectionEnd:x}}else{let L=g+m+v;b=u+g.length,x=f+g.length;let T=m.match(/^\s*|\s*$/g);if(h&&T){let te=T[0]||"",ne=T[1]||"";L=te+g+m.trim()+v+ne,b+=te.length,x-=ne.length}return{text:L,selectionStart:b,selectionEnd:x}}}function de(o,e){let{prefix:t,suffix:n,surroundWithNewlines:i}=e,r=o.value.slice(o.selectionStart,o.selectionEnd),s=o.selectionStart,a=o.selectionEnd,p=r.split(`
|
|
25
|
-
`);if(p.every(l=>l.startsWith(t)&&(!n||l.endsWith(n))))r=p.map(l=>{let c=l.slice(t.length);return n&&(c=c.slice(0,c.length-n.length)),c}).join(`
|
|
26
|
-
`),a=s+r.length;else if(r=p.map(l=>t+l+(n||"")).join(`
|
|
27
|
-
`),i){let{newlinesToAppend:l,newlinesToPrepend:c}=Q(o);s+=l.length,a=s+r.length,r=l+r+c}return{text:r,selectionStart:s,selectionEnd:a}}function ae(o){let e=o.split(`
|
|
28
|
-
`),t=/^\d+\.\s+/,n=e.every(r=>t.test(r)),i=e;return n&&(i=e.map(r=>r.replace(t,""))),{text:i.join(`
|
|
29
|
-
`),processed:n}}function le(o){let e=o.split(`
|
|
30
|
-
`),t="- ",n=e.every(r=>r.startsWith(t)),i=e;return n&&(i=e.map(r=>r.slice(t.length))),{text:i.join(`
|
|
31
|
-
`),processed:n}}function _(o,e){return e?"- ":`${o+1}. `}function Ge(o,e){let t,n,i;return o.orderedList?(t=ae(e),n=le(t.text),i=n.text):(t=le(e),n=ae(t.text),i=n.text),[t,n,i]}function Qe(o,e){let t=o.selectionStart===o.selectionEnd,n=o.selectionStart,i=o.selectionEnd;pe(o);let r=o.value.slice(o.selectionStart,o.selectionEnd),[s,a,p]=Ge(e,r),d=p.split(`
|
|
32
|
-
`).map((m,g)=>`${_(g,e.unorderedList)}${m}`),l=d.reduce((m,g,v)=>m+_(v,e.unorderedList).length,0),c=d.reduce((m,g,v)=>m+_(v,!e.unorderedList).length,0);if(s.processed)return t?(n=Math.max(n-_(0,e.unorderedList).length,0),i=n):(n=o.selectionStart,i=o.selectionEnd-l),{text:p,selectionStart:n,selectionEnd:i};let{newlinesToAppend:h,newlinesToPrepend:u}=Q(o),f=h+d.join(`
|
|
33
|
-
`)+u;return t?(n=Math.max(n+_(0,e.unorderedList).length+h.length,0),i=n):a.processed?(n=Math.max(o.selectionStart+h.length,0),i=o.selectionEnd+h.length+l-c):(n=Math.max(o.selectionStart+h.length,0),i=o.selectionEnd+h.length+l),{text:f,selectionStart:n,selectionEnd:i}}function he(o,e){let t=R(o,n=>Qe(n,e),{adjustSelection:(n,i,r,s)=>{let a=o.value.slice(s,o.selectionEnd),p=/^\d+\.\s+/,d=/^- /,l=p.test(a),c=d.test(a),h=e.orderedList&&l||e.unorderedList&&c;if(i===r)if(h){let u=a.match(e.orderedList?p:d),f=u?u[0].length:0;return{start:Math.max(i-f,s),end:Math.max(i-f,s)}}else if(l||c){let u=a.match(l?p:d),f=u?u[0].length:0,g=(e.unorderedList?2:3)-f;return{start:i+g,end:i+g}}else{let u=e.unorderedList?2:3;return{start:i+u,end:i+u}}else if(h){let u=a.match(e.orderedList?p:d),f=u?u[0].length:0;return{start:Math.max(i-f,s),end:Math.max(r-f,s)}}else if(l||c){let u=a.match(l?p:d),f=u?u[0].length:0,g=(e.unorderedList?2:3)-f;return{start:i+g,end:r+g}}else{let u=e.unorderedList?2:3;return{start:i+u,end:r+u}}}});I(o,t)}function Xe(o){if(!o)return[];let e=[],{selectionStart:t,selectionEnd:n,value:i}=o,r=i.split(`
|
|
34
|
-
`),s=0,a="";for(let c of r){if(t>=s&&t<=s+c.length){a=c;break}s+=c.length+1}a.startsWith("- ")&&(a.startsWith("- [ ] ")||a.startsWith("- [x] ")?e.push("task-list"):e.push("bullet-list")),/^\d+\.\s/.test(a)&&e.push("numbered-list"),a.startsWith("> ")&&e.push("quote"),a.startsWith("# ")&&e.push("header"),a.startsWith("## ")&&e.push("header-2"),a.startsWith("### ")&&e.push("header-3");let p=Math.max(0,t-10),d=Math.min(i.length,n+10),l=i.slice(p,d);if(l.includes("**")){let c=i.slice(Math.max(0,t-100),t),h=i.slice(n,Math.min(i.length,n+100)),u=c.lastIndexOf("**"),f=h.indexOf("**");u!==-1&&f!==-1&&e.push("bold")}if(l.includes("_")){let c=i.slice(Math.max(0,t-100),t),h=i.slice(n,Math.min(i.length,n+100)),u=c.lastIndexOf("_"),f=h.indexOf("_");u!==-1&&f!==-1&&e.push("italic")}if(l.includes("`")){let c=i.slice(Math.max(0,t-100),t),h=i.slice(n,Math.min(i.length,n+100));c.includes("`")&&h.includes("`")&&e.push("code")}if(l.includes("[")&&l.includes("]")){let c=i.slice(Math.max(0,t-100),t),h=i.slice(n,Math.min(i.length,n+100)),u=c.lastIndexOf("["),f=h.indexOf("]");u!==-1&&f!==-1&&i.slice(n+f+1,n+f+10).startsWith("(")&&e.push("link")}return e}function U(o){if(!o||o.disabled||o.readOnly)return;y("toggleBold","Starting"),j(o,"Before");let e=$(C.bold),t=V(o,e);ce(t),I(o,t),j(o,"After")}function D(o){if(!o||o.disabled||o.readOnly)return;let e=$(C.italic),t=V(o,e);I(o,t)}function ue(o){if(!o||o.disabled||o.readOnly)return;let e=$(C.code),t=V(o,e);I(o,t)}function q(o,e={}){if(!o||o.disabled||o.readOnly)return;let t=o.value.slice(o.selectionStart,o.selectionEnd),n=$(C.link);if(t&&t.match(/^https?:\/\//)&&!e.url?(n.suffix=`](${t})`,n.replaceNext=""):e.url&&(n.suffix=`](${e.url})`,n.replaceNext=""),e.text&&!t){let s=o.selectionStart;o.value=o.value.slice(0,s)+e.text+o.value.slice(s),o.selectionStart=s,o.selectionEnd=s+e.text.length}let r=V(o,n);I(o,r)}function W(o){if(!o||o.disabled||o.readOnly)return;let e=$(C.bulletList);he(o,e)}function K(o){if(!o||o.disabled||o.readOnly)return;let e=$(C.numberedList);he(o,e)}function me(o){if(!o||o.disabled||o.readOnly)return;y("toggleQuote","Starting"),j(o,"Initial");let e=$(C.quote),t=R(o,n=>de(n,e),{prefix:e.prefix});ce(t),I(o,t),j(o,"Final")}function X(o){if(!o||o.disabled||o.readOnly)return;let e=$(C.taskList),t=R(o,n=>de(n,e),{prefix:e.prefix});I(o,t)}function Y(o,e=1,t=!1){if(!o||o.disabled||o.readOnly)return;(e<1||e>6)&&(e=1),y("insertHeader","============ START ============"),y("insertHeader",`Level: ${e}, Toggle: ${t}`),y("insertHeader",`Initial cursor: ${o.selectionStart}-${o.selectionEnd}`);let n=`header${e===1?"1":e}`,i=$(C[n]||C.header1);y("insertHeader",`Style prefix: "${i.prefix}"`);let r=o.value,s=o.selectionStart,a=o.selectionEnd,p=s;for(;p>0&&r[p-1]!==`
|
|
35
|
-
`;)p--;let d=a;for(;d<r.length&&r[d]!==`
|
|
36
|
-
`;)d++;let l=r.slice(p,d);y("insertHeader",`Current line (before): "${l}"`);let c=l.match(/^(#{1,6})\s*/),h=c?c[1].length:0,u=c?c[0].length:0;y("insertHeader","Existing header check:"),y("insertHeader",` - Match: ${c?`"${c[0]}"`:"none"}`),y("insertHeader",` - Existing level: ${h}`),y("insertHeader",` - Existing prefix length: ${u}`),y("insertHeader",` - Target level: ${e}`);let f=t&&h===e;y("insertHeader",`Should toggle OFF: ${f} (toggle=${t}, existingLevel=${h}, level=${e})`);let m=R(o,g=>{let v=g.value.slice(g.selectionStart,g.selectionEnd);y("insertHeader",`Line in operation: "${v}"`);let b=v.replace(/^#{1,6}\s*/,"");y("insertHeader",`Cleaned line: "${b}"`);let x;return f?(y("insertHeader","ACTION: Toggling OFF - removing header"),x=b):h>0?(y("insertHeader",`ACTION: Replacing H${h} with H${e}`),x=i.prefix+b):(y("insertHeader","ACTION: Adding new header"),x=i.prefix+b),y("insertHeader",`New line: "${x}"`),{text:x,selectionStart:g.selectionStart,selectionEnd:g.selectionEnd}},{prefix:i.prefix,adjustSelection:(g,v,b,x)=>{if(y("insertHeader","Adjusting selection:"),y("insertHeader",` - isRemoving param: ${g}`),y("insertHeader",` - shouldToggleOff: ${f}`),y("insertHeader",` - selStart: ${v}, selEnd: ${b}`),y("insertHeader",` - lineStartPos: ${x}`),f){let M=Math.max(v-u,x);return y("insertHeader",` - Removing header, adjusting by -${u}`),{start:M,end:v===b?M:Math.max(b-u,x)}}else if(u>0){let M=i.prefix.length-u;return y("insertHeader",` - Replacing header, adjusting by ${M}`),{start:v+M,end:b+M}}else return y("insertHeader",` - Adding header, adjusting by +${i.prefix.length}`),{start:v+i.prefix.length,end:b+i.prefix.length}}});y("insertHeader",`Final result: text="${m.text}", cursor=${m.selectionStart}-${m.selectionEnd}`),y("insertHeader","============ END ============"),I(o,m)}function fe(o){Y(o,1,!0)}function ge(o){Y(o,2,!0)}function ve(o){Y(o,3,!0)}function ye(o){return Xe(o)}var O=class{constructor(e){this.editor=e,this.textarea=e.textarea}handleKeydown(e){if(!(navigator.platform.toLowerCase().includes("mac")?e.metaKey:e.ctrlKey))return!1;let i=null;switch(e.key.toLowerCase()){case"b":e.shiftKey||(i="toggleBold");break;case"i":e.shiftKey||(i="toggleItalic");break;case"k":e.shiftKey||(i="insertLink");break;case"7":e.shiftKey&&(i="toggleNumberedList");break;case"8":e.shiftKey&&(i="toggleBulletList");break}return i?(e.preventDefault(),this.editor.toolbar?this.editor.toolbar.handleAction(i):this.handleAction(i),!0):!1}async handleAction(e){let t=this.textarea;if(t){t.focus();try{switch(e){case"toggleBold":U(t);break;case"toggleItalic":D(t);break;case"insertLink":q(t);break;case"toggleBulletList":W(t);break;case"toggleNumberedList":K(t);break}t.dispatchEvent(new Event("input",{bubbles:!0}))}catch(n){console.error("Error in markdown action:",n)}}}destroy(){}};var P={name:"solar",colors:{bgPrimary:"#faf0ca",bgSecondary:"#ffffff",text:"#0d3b66",textPrimary:"#0d3b66",textSecondary:"#5a7a9b",h1:"#f95738",h2:"#ee964b",h3:"#3d8a51",strong:"#ee964b",em:"#f95738",del:"#ee964b",link:"#0d3b66",code:"#0d3b66",codeBg:"rgba(244, 211, 94, 0.4)",blockquote:"#5a7a9b",hr:"#5a7a9b",syntaxMarker:"rgba(13, 59, 102, 0.52)",syntax:"#999999",cursor:"#f95738",selection:"rgba(244, 211, 94, 0.4)",listMarker:"#ee964b",rawLine:"#5a7a9b",border:"#e0e0e0",hoverBg:"#f0f0f0",primary:"#0d3b66",toolbarBg:"#ffffff",toolbarIcon:"#0d3b66",toolbarHover:"#f5f5f5",toolbarActive:"#faf0ca"}},be={name:"cave",colors:{bgPrimary:"#141E26",bgSecondary:"#1D2D3E",text:"#c5dde8",textPrimary:"#c5dde8",textSecondary:"#9fcfec",h1:"#d4a5ff",h2:"#f6ae2d",h3:"#9fcfec",strong:"#f6ae2d",em:"#9fcfec",del:"#f6ae2d",link:"#9fcfec",code:"#c5dde8",codeBg:"#1a232b",blockquote:"#9fcfec",hr:"#c5dde8",syntaxMarker:"rgba(159, 207, 236, 0.73)",syntax:"#7a8c98",cursor:"#f26419",selection:"rgba(51, 101, 138, 0.4)",listMarker:"#f6ae2d",rawLine:"#9fcfec",border:"#2a3f52",hoverBg:"#243546",primary:"#9fcfec",toolbarBg:"#1D2D3E",toolbarIcon:"#c5dde8",toolbarHover:"#243546",toolbarActive:"#2a3f52"}},we={solar:P,cave:be,light:P,dark:be};function B(o){return typeof o=="string"?{...we[o]||we.solar,name:o}:o}function N(o){let e=[];for(let[t,n]of Object.entries(o)){let i=t.replace(/([A-Z])/g,"-$1").toLowerCase();e.push(`--${i}: ${n};`)}return e.join(`
|
|
37
|
-
`)}function xe(o,e={}){return{...o,colors:{...o.colors,...e}}}function ke(o={}){let{fontSize:e="14px",lineHeight:t=1.6,fontFamily:n='"SF Mono", SFMono-Regular, Menlo, Monaco, "Cascadia Code", Consolas, "Roboto Mono", "Noto Sans Mono", "Droid Sans Mono", "Ubuntu Mono", "DejaVu Sans Mono", "Liberation Mono", "Courier New", Courier, monospace',padding:i="20px",theme:r=null,mobile:s={}}=o,a=Object.keys(s).length>0?`
|
|
11
|
+
`),u.textContent+=f,l.remove();continue}let h=null;if(l.tagName==="DIV"&&(h=l.querySelector("li")),h){let u=h.classList.contains("bullet-list"),f=h.classList.contains("ordered-list");if(!u&&!f){i=null,r=null;continue}let m=u?"ul":"ol";(!i||r!==m)&&(i=document.createElement(m),o.insertBefore(i,l),r=m);let g=[];for(let y of l.childNodes)if(y.nodeType===3&&y.textContent.match(/^\u00A0+$/))g.push(y.cloneNode(!0));else if(y===h)break;g.forEach(y=>{h.insertBefore(y,h.firstChild)}),i.appendChild(h),l.remove()}else i=null,r=null}return o.innerHTML}static postProcessHTMLManual(e,n){let o=e;o=o.replace(/((?:<div>(?: )*<li class="bullet-list">.*?<\/li><\/div>\s*)+)/gs,r=>{let s=r.match(/<div>(?: )*<li class="bullet-list">.*?<\/li><\/div>/gs)||[];return s.length>0?"<ul>"+s.map(c=>{let d=c.match(/<div>((?: )*)<li/),l=c.match(/<li class="bullet-list">.*?<\/li>/);if(d&&l){let p=d[1];return l[0].replace(/<li class="bullet-list">/,`<li class="bullet-list">${p}`)}return l?l[0]:""}).filter(Boolean).join("")+"</ul>":r}),o=o.replace(/((?:<div>(?: )*<li class="ordered-list">.*?<\/li><\/div>\s*)+)/gs,r=>{let s=r.match(/<div>(?: )*<li class="ordered-list">.*?<\/li><\/div>/gs)||[];return s.length>0?"<ol>"+s.map(c=>{let d=c.match(/<div>((?: )*)<li/),l=c.match(/<li class="ordered-list">.*?<\/li>/);if(d&&l){let p=d[1];return l[0].replace(/<li class="ordered-list">/,`<li class="ordered-list">${p}`)}return l?l[0]:""}).filter(Boolean).join("")+"</ol>":r});let i=/<div><span class="code-fence">(```[^<]*)<\/span><\/div>(.*?)<div><span class="code-fence">(```)<\/span><\/div>/gs;return o=o.replace(i,(r,s,a,c)=>{let l=(a.match(/<div>(.*?)<\/div>/gs)||[]).map(g=>g.replace(/<div>(.*?)<\/div>/s,"$1").replace(/ /g," ")).join(`
|
|
12
|
+
`),p=s.slice(3).trim(),h=p?` class="language-${p}"`:"",u=l,f=n||this.codeHighlighter;if(f)try{let g=l.replace(/"/g,'"').replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&"),y=f(g,p);y&&typeof y.then=="function"?console.warn("Async highlighters are not supported in Node.js (non-DOM) context. Use synchronous highlighters for server-side rendering."):y&&typeof y=="string"&&y.trim()&&(u=y)}catch(g){console.warn("Code highlighting failed:",g)}let m=`<div><span class="code-fence">${s}</span></div>`;return m+=`<pre class="code-block"><code${h}>${u}</code></pre>`,m+=`<div><span class="code-fence">${c}</span></div>`,m}),o}static getListContext(e,n){let o=e.split(`
|
|
13
|
+
`),i=0,r=0,s=0;for(let h=0;h<o.length;h++){let u=o[h].length;if(i+u>=n){r=h,s=i;break}i+=u+1}let a=o[r],c=s+a.length,d=a.match(this.LIST_PATTERNS.checkbox);if(d)return{inList:!0,listType:"checkbox",indent:d[1],marker:"-",checked:d[2]==="x",content:d[3],lineStart:s,lineEnd:c,markerEndPos:s+d[1].length+d[2].length+5};let l=a.match(this.LIST_PATTERNS.bullet);if(l)return{inList:!0,listType:"bullet",indent:l[1],marker:l[2],content:l[3],lineStart:s,lineEnd:c,markerEndPos:s+l[1].length+l[2].length+1};let p=a.match(this.LIST_PATTERNS.numbered);return p?{inList:!0,listType:"numbered",indent:p[1],marker:parseInt(p[2]),content:p[3],lineStart:s,lineEnd:c,markerEndPos:s+p[1].length+p[2].length+2}:{inList:!1,listType:null,indent:"",marker:null,content:a,lineStart:s,lineEnd:c,markerEndPos:s}}static createNewListItem(e){switch(e.listType){case"bullet":return`${e.indent}${e.marker} `;case"numbered":return`${e.indent}${e.marker+1}. `;case"checkbox":return`${e.indent}- [ ] `;default:return""}}static renumberLists(e){let n=e.split(`
|
|
14
|
+
`),o=new Map,i=!1;return n.map(s=>{let a=s.match(this.LIST_PATTERNS.numbered);if(a){let c=a[1],d=c.length,l=a[3];i||o.clear();let p=(o.get(d)||0)+1;o.set(d,p);for(let[h]of o)h>d&&o.delete(h);return i=!0,`${c}${p}. ${l}`}else return(s.trim()===""||!s.match(/^\s/))&&(i=!1,o.clear()),s}).join(`
|
|
15
|
+
`)}};C(T,"linkIndex",0),C(T,"codeHighlighter",null),C(T,"customSyntax",null),C(T,"LIST_PATTERNS",{bullet:/^(\s*)([-*+])\s+(.*)$/,numbered:/^(\s*)(\d+)\.\s+(.*)$/,checkbox:/^(\s*)-\s+\[([ x])\]\s+(.*)$/});var re=class{constructor(e){this.editor=e}handleKeydown(e){if(!(navigator.platform.toLowerCase().includes("mac")?e.metaKey:e.ctrlKey))return!1;let i=null;switch(e.key.toLowerCase()){case"b":e.shiftKey||(i="toggleBold");break;case"i":e.shiftKey||(i="toggleItalic");break;case"k":e.shiftKey||(i="insertLink");break;case"7":e.shiftKey&&(i="toggleNumberedList");break;case"8":e.shiftKey&&(i="toggleBulletList");break}return i?(e.preventDefault(),this.editor.performAction(i,e),!0):!1}destroy(){}};var B={name:"solar",colors:{bgPrimary:"#faf0ca",bgSecondary:"#ffffff",text:"#0d3b66",textPrimary:"#0d3b66",textSecondary:"#5a7a9b",h1:"#f95738",h2:"#ee964b",h3:"#3d8a51",strong:"#ee964b",em:"#f95738",del:"#ee964b",link:"#0d3b66",code:"#0d3b66",codeBg:"rgba(244, 211, 94, 0.4)",blockquote:"#5a7a9b",hr:"#5a7a9b",syntaxMarker:"rgba(13, 59, 102, 0.52)",syntax:"#999999",cursor:"#f95738",selection:"rgba(244, 211, 94, 0.4)",listMarker:"#ee964b",rawLine:"#5a7a9b",border:"#e0e0e0",hoverBg:"#f0f0f0",primary:"#0d3b66",toolbarBg:"#ffffff",toolbarIcon:"#0d3b66",toolbarHover:"#f5f5f5",toolbarActive:"#faf0ca",placeholder:"#999999"}},We={name:"cave",colors:{bgPrimary:"#141E26",bgSecondary:"#1D2D3E",text:"#c5dde8",textPrimary:"#c5dde8",textSecondary:"#9fcfec",h1:"#d4a5ff",h2:"#f6ae2d",h3:"#9fcfec",strong:"#f6ae2d",em:"#9fcfec",del:"#f6ae2d",link:"#9fcfec",code:"#c5dde8",codeBg:"#1a232b",blockquote:"#9fcfec",hr:"#c5dde8",syntaxMarker:"rgba(159, 207, 236, 0.73)",syntax:"#7a8c98",cursor:"#f26419",selection:"rgba(51, 101, 138, 0.4)",listMarker:"#f6ae2d",rawLine:"#9fcfec",border:"#2a3f52",hoverBg:"#243546",primary:"#9fcfec",toolbarBg:"#1D2D3E",toolbarIcon:"#c5dde8",toolbarHover:"#243546",toolbarActive:"#2a3f52",placeholder:"#6a7a88"}},qe={solar:B,cave:We,auto:B,light:B,dark:We};function V(t){return typeof t=="string"?{...qe[t]||qe.solar,name:t}:t}function Pe(t){if(t!=="auto")return t;let e=window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)");return e!=null&&e.matches?"cave":"solar"}function Q(t){let e=[];for(let[n,o]of Object.entries(t)){let i=n.replace(/([A-Z])/g,"-$1").toLowerCase();e.push(`--${i}: ${o};`)}return e.join(`
|
|
16
|
+
`)}function Ke(t,e={}){return{...t,colors:{...t.colors,...e}}}function Ze(t={}){let{fontSize:e="14px",lineHeight:n=1.6,fontFamily:o='"SF Mono", SFMono-Regular, Menlo, Monaco, "Cascadia Code", Consolas, "Roboto Mono", "Noto Sans Mono", "Droid Sans Mono", "Ubuntu Mono", "DejaVu Sans Mono", "Liberation Mono", "Courier New", Courier, monospace',padding:i="20px",theme:r=null,mobile:s={}}=t,a=Object.keys(s).length>0?`
|
|
38
17
|
@media (max-width: 640px) {
|
|
39
18
|
.overtype-wrapper .overtype-input,
|
|
40
19
|
.overtype-wrapper .overtype-preview {
|
|
@@ -42,7 +21,7 @@ ${a}`:r;if(d){let L=o.value[o.selectionStart-1];o.selectionStart!==0&&L!=null&&!
|
|
|
42
21
|
`)}
|
|
43
22
|
}
|
|
44
23
|
}
|
|
45
|
-
`:"",
|
|
24
|
+
`:"",c=r&&r.colors?Q(r.colors):"";return`
|
|
46
25
|
/* OverType Editor Styles */
|
|
47
26
|
|
|
48
27
|
/* Middle-ground CSS Reset - Prevent parent styles from leaking in */
|
|
@@ -83,9 +62,9 @@ ${a}`:r;if(d){let L=o.value[o.selectionStart-1];o.selectionStart!==0&&L!=null&&!
|
|
|
83
62
|
overflow: visible !important; /* Allow dropdown to overflow container */
|
|
84
63
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
|
|
85
64
|
text-align: left !important;
|
|
86
|
-
${
|
|
65
|
+
${c?`
|
|
87
66
|
/* Theme Variables */
|
|
88
|
-
${
|
|
67
|
+
${c}`:""}
|
|
89
68
|
}
|
|
90
69
|
|
|
91
70
|
/* Force left alignment for all elements in the editor */
|
|
@@ -126,10 +105,10 @@ ${a}`:r;if(d){let L=o.value[o.selectionStart-1];o.selectionStart!==0&&L!=null&&!
|
|
|
126
105
|
height: 100% !important;
|
|
127
106
|
|
|
128
107
|
/* Font properties - any difference breaks alignment */
|
|
129
|
-
font-family: ${
|
|
108
|
+
font-family: ${o} !important;
|
|
130
109
|
font-variant-ligatures: none !important; /* keep metrics stable for code */
|
|
131
110
|
font-size: var(--instance-font-size, ${e}) !important;
|
|
132
|
-
line-height: var(--instance-line-height, ${
|
|
111
|
+
line-height: var(--instance-line-height, ${n}) !important;
|
|
133
112
|
font-weight: normal !important;
|
|
134
113
|
font-style: normal !important;
|
|
135
114
|
font-variant: normal !important;
|
|
@@ -214,17 +193,36 @@ ${a}`:r;if(d){let L=o.value[o.selectionStart-1];o.selectionStart!==0&&L!=null&&!
|
|
|
214
193
|
/* Prevent mobile zoom on focus */
|
|
215
194
|
touch-action: manipulation !important;
|
|
216
195
|
|
|
217
|
-
/* Disable autofill
|
|
196
|
+
/* Disable autofill */
|
|
218
197
|
autocomplete: off !important;
|
|
219
198
|
autocorrect: off !important;
|
|
220
199
|
autocapitalize: off !important;
|
|
221
|
-
spellcheck: false !important;
|
|
222
200
|
}
|
|
223
201
|
|
|
224
202
|
.overtype-wrapper .overtype-input::selection {
|
|
225
203
|
background-color: var(--selection, rgba(244, 211, 94, 0.4));
|
|
226
204
|
}
|
|
227
205
|
|
|
206
|
+
/* Placeholder shim - visible when textarea is empty */
|
|
207
|
+
.overtype-wrapper .overtype-placeholder {
|
|
208
|
+
position: absolute !important;
|
|
209
|
+
top: 0 !important;
|
|
210
|
+
left: 0 !important;
|
|
211
|
+
width: 100% !important;
|
|
212
|
+
z-index: 0 !important;
|
|
213
|
+
pointer-events: none !important;
|
|
214
|
+
user-select: none !important;
|
|
215
|
+
font-family: ${o} !important;
|
|
216
|
+
font-size: var(--instance-font-size, ${e}) !important;
|
|
217
|
+
line-height: var(--instance-line-height, ${n}) !important;
|
|
218
|
+
padding: var(--instance-padding, ${i}) !important;
|
|
219
|
+
box-sizing: border-box !important;
|
|
220
|
+
color: var(--placeholder, #999) !important;
|
|
221
|
+
overflow: hidden !important;
|
|
222
|
+
white-space: nowrap !important;
|
|
223
|
+
text-overflow: ellipsis !important;
|
|
224
|
+
}
|
|
225
|
+
|
|
228
226
|
/* Preview layer styles */
|
|
229
227
|
.overtype-wrapper .overtype-preview {
|
|
230
228
|
/* Layer positioning */
|
|
@@ -365,7 +363,7 @@ ${a}`:r;if(d){let L=o.value[o.selectionStart-1];o.selectionStart!==0&&L!=null&&!
|
|
|
365
363
|
.overtype-wrapper .overtype-preview pre code {
|
|
366
364
|
background: transparent !important;
|
|
367
365
|
color: var(--code, #0d3b66) !important;
|
|
368
|
-
font-family: ${
|
|
366
|
+
font-family: ${o} !important; /* Match textarea font exactly for alignment */
|
|
369
367
|
}
|
|
370
368
|
|
|
371
369
|
/* Blockquotes */
|
|
@@ -492,6 +490,10 @@ ${a}`:r;if(d){let L=o.value[o.selectionStart-1];o.selectionStart!==0&&L!=null&&!
|
|
|
492
490
|
|
|
493
491
|
|
|
494
492
|
/* Toolbar Styles */
|
|
493
|
+
.overtype-toolbar.overtype-toolbar-hidden {
|
|
494
|
+
display: none !important;
|
|
495
|
+
}
|
|
496
|
+
|
|
495
497
|
.overtype-toolbar {
|
|
496
498
|
display: flex !important;
|
|
497
499
|
align-items: center !important;
|
|
@@ -766,25 +768,20 @@ ${a}`:r;if(d){let L=o.value[o.selectionStart-1];o.selectionStart!==0&&L!=null&&!
|
|
|
766
768
|
|
|
767
769
|
/* Code blocks - proper pre/code styling in preview mode */
|
|
768
770
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview pre.code-block {
|
|
769
|
-
background:
|
|
770
|
-
color: #
|
|
771
|
+
background: var(--code-bg, rgba(244, 211, 94, 0.4)) !important;
|
|
772
|
+
color: var(--code, #0d3b66) !important;
|
|
771
773
|
padding: 1.2em !important;
|
|
772
774
|
border-radius: 3px !important;
|
|
773
775
|
overflow-x: auto !important;
|
|
774
776
|
margin: 0 !important;
|
|
775
777
|
display: block !important;
|
|
776
778
|
}
|
|
777
|
-
|
|
778
|
-
/* Cave theme code block background in preview mode */
|
|
779
|
-
.overtype-container[data-theme="cave"][data-mode="preview"] .overtype-wrapper .overtype-preview pre.code-block {
|
|
780
|
-
background: #11171F !important;
|
|
781
|
-
}
|
|
782
779
|
|
|
783
780
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview pre.code-block code {
|
|
784
781
|
background: transparent !important;
|
|
785
782
|
color: inherit !important;
|
|
786
783
|
padding: 0 !important;
|
|
787
|
-
font-family: ${
|
|
784
|
+
font-family: ${o} !important;
|
|
788
785
|
font-size: 0.9em !important;
|
|
789
786
|
line-height: 1.4 !important;
|
|
790
787
|
}
|
|
@@ -817,7 +814,7 @@ ${a}`:r;if(d){let L=o.value[o.selectionStart-1];o.selectionStart!==0&&L!=null&&!
|
|
|
817
814
|
|
|
818
815
|
/* Inline code in preview mode - keep monospace */
|
|
819
816
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview code {
|
|
820
|
-
font-family: ${
|
|
817
|
+
font-family: ${o} !important;
|
|
821
818
|
font-size: 0.9em !important;
|
|
822
819
|
background: rgba(135, 131, 120, 0.15) !important;
|
|
823
820
|
padding: 0.2em 0.4em !important;
|
|
@@ -843,16 +840,17 @@ ${a}`:r;if(d){let L=o.value[o.selectionStart-1];o.selectionStart!==0&&L!=null&&!
|
|
|
843
840
|
height: 2px !important;
|
|
844
841
|
}
|
|
845
842
|
|
|
846
|
-
/* Link Tooltip
|
|
843
|
+
/* Link Tooltip */
|
|
847
844
|
.overtype-link-tooltip {
|
|
848
|
-
/* Visual styles that work for both positioning methods */
|
|
849
845
|
background: #333 !important;
|
|
850
846
|
color: white !important;
|
|
851
847
|
padding: 6px 10px !important;
|
|
852
848
|
border-radius: 16px !important;
|
|
853
849
|
font-size: 12px !important;
|
|
854
850
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif !important;
|
|
855
|
-
display:
|
|
851
|
+
display: flex !important;
|
|
852
|
+
visibility: hidden !important;
|
|
853
|
+
pointer-events: none !important;
|
|
856
854
|
z-index: 10000 !important;
|
|
857
855
|
cursor: pointer !important;
|
|
858
856
|
box-shadow: 0 2px 8px rgba(0,0,0,0.3) !important;
|
|
@@ -860,29 +858,39 @@ ${a}`:r;if(d){let L=o.value[o.selectionStart-1];o.selectionStart!==0&&L!=null&&!
|
|
|
860
858
|
white-space: nowrap !important;
|
|
861
859
|
overflow: hidden !important;
|
|
862
860
|
text-overflow: ellipsis !important;
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
861
|
+
position: fixed;
|
|
862
|
+
top: 0;
|
|
863
|
+
left: 0;
|
|
866
864
|
}
|
|
867
865
|
|
|
868
866
|
.overtype-link-tooltip.visible {
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
/* CSS Anchor Positioning (modern browsers only) */
|
|
873
|
-
@supports (position-anchor: --x) and (position-area: center) {
|
|
874
|
-
.overtype-link-tooltip {
|
|
875
|
-
/* Only anchor positioning specific properties */
|
|
876
|
-
position-anchor: var(--target-anchor, --link-0);
|
|
877
|
-
position-area: block-end center;
|
|
878
|
-
margin-top: 8px !important;
|
|
879
|
-
position-try: most-width block-end inline-end, flip-inline, block-start center;
|
|
880
|
-
position-visibility: anchors-visible;
|
|
881
|
-
}
|
|
867
|
+
visibility: visible !important;
|
|
868
|
+
pointer-events: auto !important;
|
|
882
869
|
}
|
|
883
870
|
|
|
884
871
|
${a}
|
|
885
|
-
`}var
|
|
872
|
+
`}var gn=Object.defineProperty,Qe=Object.getOwnPropertySymbols,vn=Object.prototype.hasOwnProperty,yn=Object.prototype.propertyIsEnumerable,Ge=(t,e,n)=>e in t?gn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Je=(t,e)=>{for(var n in e||(e={}))vn.call(e,n)&&Ge(t,n,e[n]);if(Qe)for(var n of Qe(e))yn.call(e,n)&&Ge(t,n,e[n]);return t},I={bold:{prefix:"**",suffix:"**",trimFirst:!0},italic:{prefix:"_",suffix:"_",trimFirst:!0},code:{prefix:"`",suffix:"`",blockPrefix:"```",blockSuffix:"```"},link:{prefix:"[",suffix:"](url)",replaceNext:"url",scanFor:"https?://"},bulletList:{prefix:"- ",multiline:!0,unorderedList:!0},numberedList:{prefix:"1. ",multiline:!0,orderedList:!0},quote:{prefix:"> ",multiline:!0,surroundWithNewlines:!0},taskList:{prefix:"- [ ] ",multiline:!0,surroundWithNewlines:!0},header1:{prefix:"# "},header2:{prefix:"## "},header3:{prefix:"### "},header4:{prefix:"#### "},header5:{prefix:"##### "},header6:{prefix:"###### "}};function wn(){return{prefix:"",suffix:"",blockPrefix:"",blockSuffix:"",multiline:!1,replaceNext:"",prefixSpace:!1,scanFor:"",surroundWithNewlines:!1,orderedList:!1,unorderedList:!1,trimFirst:!1}}function F(t){return Je(Je({},wn()),t)}var we=!1;function bn(){return we}function x(t,e,n){we&&(console.group(`\u{1F50D} ${t}`),console.log(e),n&&console.log("Data:",n),console.groupEnd())}function ye(t,e){if(!we)return;let n=t.value.slice(t.selectionStart,t.selectionEnd);console.group(`\u{1F4CD} Selection: ${e}`),console.log("Position:",`${t.selectionStart}-${t.selectionEnd}`),console.log("Selected text:",JSON.stringify(n)),console.log("Length:",n.length);let o=t.value.slice(Math.max(0,t.selectionStart-10),t.selectionStart),i=t.value.slice(t.selectionEnd,Math.min(t.value.length,t.selectionEnd+10));console.log("Context:",JSON.stringify(o)+"[SELECTION]"+JSON.stringify(i)),console.groupEnd()}function tt(t){we&&(console.group("\u{1F4DD} Result"),console.log("Text to insert:",JSON.stringify(t.text)),console.log("New selection:",`${t.selectionStart}-${t.selectionEnd}`),console.groupEnd())}var _=null;function U(t,{text:e,selectionStart:n,selectionEnd:o}){let i=bn();i&&(console.group("\u{1F527} insertText"),console.log("Current selection:",`${t.selectionStart}-${t.selectionEnd}`),console.log("Text to insert:",JSON.stringify(e)),console.log("New selection to set:",n,"-",o)),t.focus();let r=t.selectionStart,s=t.selectionEnd,a=t.value.slice(0,r),c=t.value.slice(s);i&&(console.log("Before text (last 20):",JSON.stringify(a.slice(-20))),console.log("After text (first 20):",JSON.stringify(c.slice(0,20))),console.log("Selected text being replaced:",JSON.stringify(t.value.slice(r,s))));let d=t.value,l=r!==s;if(_===null||_===!0){t.contentEditable="true";try{_=document.execCommand("insertText",!1,e),i&&console.log("execCommand returned:",_,"for text with",e.split(`
|
|
873
|
+
`).length,"lines")}catch(p){_=!1,i&&console.log("execCommand threw error:",p)}t.contentEditable="false"}if(i&&(console.log("canInsertText before:",_),console.log("execCommand result:",_)),_){let p=a+e+c,h=t.value;i&&(console.log("Expected length:",p.length),console.log("Actual length:",h.length)),h!==p&&i&&(console.log("execCommand changed the value but not as expected"),console.log("Expected:",JSON.stringify(p.slice(0,100))),console.log("Actual:",JSON.stringify(h.slice(0,100))))}if(!_)if(i&&console.log("Using manual insertion"),t.value===d){i&&console.log("Value unchanged, doing manual replacement");try{document.execCommand("ms-beginUndoUnit")}catch(p){}t.value=a+e+c;try{document.execCommand("ms-endUndoUnit")}catch(p){}t.dispatchEvent(new CustomEvent("input",{bubbles:!0,cancelable:!0}))}else i&&console.log("Value was changed by execCommand, skipping manual insertion");i&&console.log("Setting selection range:",n,o),n!=null&&o!=null?t.setSelectionRange(n,o):t.setSelectionRange(r,t.selectionEnd),i&&(console.log("Final value length:",t.value.length),console.groupEnd())}function Xe(t){return t.trim().split(`
|
|
874
|
+
`).length>1}function xn(t,e){let n=e;for(;t[n]&&t[n-1]!=null&&!t[n-1].match(/\s/);)n--;return n}function kn(t,e,n){let o=e,i=n?/\n/:/\s/;for(;t[o]&&!t[o].match(i);)o++;return o}function nt(t){let e=t.value.split(`
|
|
875
|
+
`),n=0;for(let o=0;o<e.length;o++){let i=e[o].length+1;t.selectionStart>=n&&t.selectionStart<n+i&&(t.selectionStart=n),t.selectionEnd>=n&&t.selectionEnd<n+i&&(o===e.length-1?t.selectionEnd=Math.min(n+e[o].length,t.value.length):t.selectionEnd=n+i-1),n+=i}}function Ln(t,e,n,o=!1){if(t.selectionStart===t.selectionEnd)t.selectionStart=xn(t.value,t.selectionStart),t.selectionEnd=kn(t.value,t.selectionEnd,o);else{let i=t.selectionStart-e.length,r=t.selectionEnd+n.length,s=t.value.slice(i,t.selectionStart)===e,a=t.value.slice(t.selectionEnd,r)===n;s&&a&&(t.selectionStart=i,t.selectionEnd=r)}return t.value.slice(t.selectionStart,t.selectionEnd)}function $e(t){let e=t.value.slice(0,t.selectionStart),n=t.value.slice(t.selectionEnd),o=e.match(/\n*$/),i=n.match(/^\n*/),r=o?o[0].length:0,s=i?i[0].length:0,a="",c="";return e.match(/\S/)&&r<2&&(a=`
|
|
876
|
+
`.repeat(2-r)),n.match(/\S/)&&s<2&&(c=`
|
|
877
|
+
`.repeat(2-s)),{newlinesToAppend:a,newlinesToPrepend:c}}function be(t,e,n={}){let o=t.selectionStart,i=t.selectionEnd,r=o===i,s=t.value,a=o;for(;a>0&&s[a-1]!==`
|
|
878
|
+
`;)a--;if(r){let d=o;for(;d<s.length&&s[d]!==`
|
|
879
|
+
`;)d++;t.selectionStart=a,t.selectionEnd=d}else nt(t);let c=e(t);if(n.adjustSelection){let l=t.value.slice(t.selectionStart,t.selectionEnd).startsWith(n.prefix),p=n.adjustSelection(l,o,i,a);c.selectionStart=p.start,c.selectionEnd=p.end}else if(n.prefix){let l=t.value.slice(t.selectionStart,t.selectionEnd).startsWith(n.prefix);r?l?(c.selectionStart=Math.max(o-n.prefix.length,a),c.selectionEnd=c.selectionStart):(c.selectionStart=o+n.prefix.length,c.selectionEnd=c.selectionStart):l?(c.selectionStart=Math.max(o-n.prefix.length,a),c.selectionEnd=Math.max(i-n.prefix.length,a)):(c.selectionStart=o+n.prefix.length,c.selectionEnd=i+n.prefix.length)}return c}function xe(t,e){let n,o,{prefix:i,suffix:r,blockPrefix:s,blockSuffix:a,replaceNext:c,prefixSpace:d,scanFor:l,surroundWithNewlines:p,trimFirst:h}=e,u=t.selectionStart,f=t.selectionEnd,m=t.value.slice(t.selectionStart,t.selectionEnd),g=Xe(m)&&s&&s.length>0?`${s}
|
|
880
|
+
`:i,y=Xe(m)&&a&&a.length>0?`
|
|
881
|
+
${a}`:r;if(d){let k=t.value[t.selectionStart-1];t.selectionStart!==0&&k!=null&&!k.match(/\s/)&&(g=` ${g}`)}m=Ln(t,g,y,e.multiline);let w=t.selectionStart,b=t.selectionEnd,L=c&&c.length>0&&y.indexOf(c)>-1&&m.length>0;if(p){let k=$e(t);n=k.newlinesToAppend,o=k.newlinesToPrepend,g=n+i,y+=o}if(m.startsWith(g)&&m.endsWith(y)){let k=m.slice(g.length,m.length-y.length);if(u===f){let E=u-g.length;E=Math.max(E,w),E=Math.min(E,w+k.length),w=b=E}else b=w+k.length;return{text:k,selectionStart:w,selectionEnd:b}}else if(L)if(l&&l.length>0&&m.match(l)){y=y.replace(c,m);let k=g+y;return w=b=w+g.length,{text:k,selectionStart:w,selectionEnd:b}}else{let k=g+m+y;return w=w+g.length+m.length+y.indexOf(c),b=w+c.length,{text:k,selectionStart:w,selectionEnd:b}}else{let k=g+m+y;w=u+g.length,b=f+g.length;let E=m.match(/^\s*|\s*$/g);if(h&&E){let me=E[0]||"",Y=E[1]||"";k=me+g+m.trim()+y+Y,w+=me.length,b-=Y.length}return{text:k,selectionStart:w,selectionEnd:b}}}function ot(t,e){let{prefix:n,suffix:o,surroundWithNewlines:i}=e,r=t.value.slice(t.selectionStart,t.selectionEnd),s=t.selectionStart,a=t.selectionEnd,c=r.split(`
|
|
882
|
+
`);if(c.every(l=>l.startsWith(n)&&(!o||l.endsWith(o))))r=c.map(l=>{let p=l.slice(n.length);return o&&(p=p.slice(0,p.length-o.length)),p}).join(`
|
|
883
|
+
`),a=s+r.length;else if(r=c.map(l=>n+l+(o||"")).join(`
|
|
884
|
+
`),i){let{newlinesToAppend:l,newlinesToPrepend:p}=$e(t);s+=l.length,a=s+r.length,r=l+r+p}return{text:r,selectionStart:s,selectionEnd:a}}function Ye(t){let e=t.split(`
|
|
885
|
+
`),n=/^\d+\.\s+/,o=e.every(r=>n.test(r)),i=e;return o&&(i=e.map(r=>r.replace(n,""))),{text:i.join(`
|
|
886
|
+
`),processed:o}}function et(t){let e=t.split(`
|
|
887
|
+
`),n="- ",o=e.every(r=>r.startsWith(n)),i=e;return o&&(i=e.map(r=>r.slice(n.length))),{text:i.join(`
|
|
888
|
+
`),processed:o}}function se(t,e){return e?"- ":`${t+1}. `}function Sn(t,e){let n,o,i;return t.orderedList?(n=Ye(e),o=et(n.text),i=o.text):(n=et(e),o=Ye(n.text),i=o.text),[n,o,i]}function En(t,e){let n=t.selectionStart===t.selectionEnd,o=t.selectionStart,i=t.selectionEnd;nt(t);let r=t.value.slice(t.selectionStart,t.selectionEnd),[s,a,c]=Sn(e,r),d=c.split(`
|
|
889
|
+
`).map((m,g)=>`${se(g,e.unorderedList)}${m}`),l=d.reduce((m,g,y)=>m+se(y,e.unorderedList).length,0),p=d.reduce((m,g,y)=>m+se(y,!e.unorderedList).length,0);if(s.processed)return n?(o=Math.max(o-se(0,e.unorderedList).length,0),i=o):(o=t.selectionStart,i=t.selectionEnd-l),{text:c,selectionStart:o,selectionEnd:i};let{newlinesToAppend:h,newlinesToPrepend:u}=$e(t),f=h+d.join(`
|
|
890
|
+
`)+u;return n?(o=Math.max(o+se(0,e.unorderedList).length+h.length,0),i=o):a.processed?(o=Math.max(t.selectionStart+h.length,0),i=t.selectionEnd+h.length+l-p):(o=Math.max(t.selectionStart+h.length,0),i=t.selectionEnd+h.length+l),{text:f,selectionStart:o,selectionEnd:i}}function it(t,e){let n=be(t,o=>En(o,e),{adjustSelection:(o,i,r,s)=>{let a=t.value.slice(s,t.selectionEnd),c=/^\d+\.\s+/,d=/^- /,l=c.test(a),p=d.test(a),h=e.orderedList&&l||e.unorderedList&&p;if(i===r)if(h){let u=a.match(e.orderedList?c:d),f=u?u[0].length:0;return{start:Math.max(i-f,s),end:Math.max(i-f,s)}}else if(l||p){let u=a.match(l?c:d),f=u?u[0].length:0,g=(e.unorderedList?2:3)-f;return{start:i+g,end:i+g}}else{let u=e.unorderedList?2:3;return{start:i+u,end:i+u}}else if(h){let u=a.match(e.orderedList?c:d),f=u?u[0].length:0;return{start:Math.max(i-f,s),end:Math.max(r-f,s)}}else if(l||p){let u=a.match(l?c:d),f=u?u[0].length:0,g=(e.unorderedList?2:3)-f;return{start:i+g,end:r+g}}else{let u=e.unorderedList?2:3;return{start:i+u,end:r+u}}}});U(t,n)}function Tn(t){if(!t)return[];let e=[],{selectionStart:n,selectionEnd:o,value:i}=t,r=i.split(`
|
|
891
|
+
`),s=0,a="";for(let p of r){if(n>=s&&n<=s+p.length){a=p;break}s+=p.length+1}a.startsWith("- ")&&(a.startsWith("- [ ] ")||a.startsWith("- [x] ")?e.push("task-list"):e.push("bullet-list")),/^\d+\.\s/.test(a)&&e.push("numbered-list"),a.startsWith("> ")&&e.push("quote"),a.startsWith("# ")&&e.push("header"),a.startsWith("## ")&&e.push("header-2"),a.startsWith("### ")&&e.push("header-3");let c=Math.max(0,n-10),d=Math.min(i.length,o+10),l=i.slice(c,d);if(l.includes("**")){let p=i.slice(Math.max(0,n-100),n),h=i.slice(o,Math.min(i.length,o+100)),u=p.lastIndexOf("**"),f=h.indexOf("**");u!==-1&&f!==-1&&e.push("bold")}if(l.includes("_")){let p=i.slice(Math.max(0,n-100),n),h=i.slice(o,Math.min(i.length,o+100)),u=p.lastIndexOf("_"),f=h.indexOf("_");u!==-1&&f!==-1&&e.push("italic")}if(l.includes("`")){let p=i.slice(Math.max(0,n-100),n),h=i.slice(o,Math.min(i.length,o+100));p.includes("`")&&h.includes("`")&&e.push("code")}if(l.includes("[")&&l.includes("]")){let p=i.slice(Math.max(0,n-100),n),h=i.slice(o,Math.min(i.length,o+100)),u=p.lastIndexOf("["),f=h.indexOf("]");u!==-1&&f!==-1&&i.slice(o+f+1,o+f+10).startsWith("(")&&e.push("link")}return e}function rt(t){if(!t||t.disabled||t.readOnly)return;x("toggleBold","Starting"),ye(t,"Before");let e=F(I.bold),n=xe(t,e);tt(n),U(t,n),ye(t,"After")}function st(t){if(!t||t.disabled||t.readOnly)return;let e=F(I.italic),n=xe(t,e);U(t,n)}function at(t){if(!t||t.disabled||t.readOnly)return;let e=F(I.code),n=xe(t,e);U(t,n)}function lt(t,e={}){if(!t||t.disabled||t.readOnly)return;let n=t.value.slice(t.selectionStart,t.selectionEnd),o=F(I.link);if(n&&n.match(/^https?:\/\//)&&!e.url?(o.suffix=`](${n})`,o.replaceNext=""):e.url&&(o.suffix=`](${e.url})`,o.replaceNext=""),e.text&&!n){let s=t.selectionStart;t.value=t.value.slice(0,s)+e.text+t.value.slice(s),t.selectionStart=s,t.selectionEnd=s+e.text.length}let r=xe(t,o);U(t,r)}function ct(t){if(!t||t.disabled||t.readOnly)return;let e=F(I.bulletList);it(t,e)}function pt(t){if(!t||t.disabled||t.readOnly)return;let e=F(I.numberedList);it(t,e)}function dt(t){if(!t||t.disabled||t.readOnly)return;x("toggleQuote","Starting"),ye(t,"Initial");let e=F(I.quote),n=be(t,o=>ot(o,e),{prefix:e.prefix});tt(n),U(t,n),ye(t,"Final")}function Ie(t){if(!t||t.disabled||t.readOnly)return;let e=F(I.taskList),n=be(t,o=>ot(o,e),{prefix:e.prefix});U(t,n)}function Re(t,e=1,n=!1){if(!t||t.disabled||t.readOnly)return;(e<1||e>6)&&(e=1),x("insertHeader","============ START ============"),x("insertHeader",`Level: ${e}, Toggle: ${n}`),x("insertHeader",`Initial cursor: ${t.selectionStart}-${t.selectionEnd}`);let o=`header${e===1?"1":e}`,i=F(I[o]||I.header1);x("insertHeader",`Style prefix: "${i.prefix}"`);let r=t.value,s=t.selectionStart,a=t.selectionEnd,c=s;for(;c>0&&r[c-1]!==`
|
|
892
|
+
`;)c--;let d=a;for(;d<r.length&&r[d]!==`
|
|
893
|
+
`;)d++;let l=r.slice(c,d);x("insertHeader",`Current line (before): "${l}"`);let p=l.match(/^(#{1,6})\s*/),h=p?p[1].length:0,u=p?p[0].length:0;x("insertHeader","Existing header check:"),x("insertHeader",` - Match: ${p?`"${p[0]}"`:"none"}`),x("insertHeader",` - Existing level: ${h}`),x("insertHeader",` - Existing prefix length: ${u}`),x("insertHeader",` - Target level: ${e}`);let f=n&&h===e;x("insertHeader",`Should toggle OFF: ${f} (toggle=${n}, existingLevel=${h}, level=${e})`);let m=be(t,g=>{let y=g.value.slice(g.selectionStart,g.selectionEnd);x("insertHeader",`Line in operation: "${y}"`);let w=y.replace(/^#{1,6}\s*/,"");x("insertHeader",`Cleaned line: "${w}"`);let b;return f?(x("insertHeader","ACTION: Toggling OFF - removing header"),b=w):h>0?(x("insertHeader",`ACTION: Replacing H${h} with H${e}`),b=i.prefix+w):(x("insertHeader","ACTION: Adding new header"),b=i.prefix+w),x("insertHeader",`New line: "${b}"`),{text:b,selectionStart:g.selectionStart,selectionEnd:g.selectionEnd}},{prefix:i.prefix,adjustSelection:(g,y,w,b)=>{if(x("insertHeader","Adjusting selection:"),x("insertHeader",` - isRemoving param: ${g}`),x("insertHeader",` - shouldToggleOff: ${f}`),x("insertHeader",` - selStart: ${y}, selEnd: ${w}`),x("insertHeader",` - lineStartPos: ${b}`),f){let L=Math.max(y-u,b);return x("insertHeader",` - Removing header, adjusting by -${u}`),{start:L,end:y===w?L:Math.max(w-u,b)}}else if(u>0){let L=i.prefix.length-u;return x("insertHeader",` - Replacing header, adjusting by ${L}`),{start:y+L,end:w+L}}else return x("insertHeader",` - Adding header, adjusting by +${i.prefix.length}`),{start:y+i.prefix.length,end:w+i.prefix.length}}});x("insertHeader",`Final result: text="${m.text}", cursor=${m.selectionStart}-${m.selectionEnd}`),x("insertHeader","============ END ============"),U(t,m)}function ut(t){Re(t,1,!0)}function ht(t){Re(t,2,!0)}function ft(t){Re(t,3,!0)}function mt(t){return Tn(t)}var ke=class{constructor(e,n={}){this.editor=e,this.container=null,this.buttons={},this.toolbarButtons=n.toolbarButtons||[]}create(){this.container=document.createElement("div"),this.container.className="overtype-toolbar",this.container.setAttribute("role","toolbar"),this.container.setAttribute("aria-label","Formatting toolbar"),this.toolbarButtons.forEach(e=>{if(e.name==="separator"){let n=this.createSeparator();this.container.appendChild(n)}else{let n=this.createButton(e);this.buttons[e.name]=n,this.container.appendChild(n)}}),this.editor.container.insertBefore(this.container,this.editor.wrapper)}createSeparator(){let e=document.createElement("div");return e.className="overtype-toolbar-separator",e.setAttribute("role","separator"),e}createButton(e){let n=document.createElement("button");return n.className="overtype-toolbar-button",n.type="button",n.setAttribute("data-button",e.name),n.title=e.title||"",n.setAttribute("aria-label",e.title||e.name),n.innerHTML=this.sanitizeSVG(e.icon||""),e.name==="viewMode"?(n.classList.add("has-dropdown"),n.dataset.dropdown="true",n.addEventListener("click",o=>{o.preventDefault(),this.toggleViewModeDropdown(n)}),n):(n._clickHandler=o=>{o.preventDefault();let i=e.actionId||e.name;this.editor.performAction(i,o)},n.addEventListener("click",n._clickHandler),n)}async handleAction(e){if(e&&typeof e=="object"&&typeof e.action=="function"){this.editor.textarea.focus();try{return await e.action({editor:this.editor,getValue:()=>this.editor.getValue(),setValue:n=>this.editor.setValue(n),event:null}),!0}catch(n){return console.error(`Action "${e.name}" error:`,n),this.editor.wrapper.dispatchEvent(new CustomEvent("button-error",{detail:{buttonName:e.name,error:n}})),!1}}return typeof e=="string"?this.editor.performAction(e,null):!1}sanitizeSVG(e){return typeof e!="string"?"":e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/\son\w+\s*=\s*["'][^"']*["']/gi,"").replace(/\son\w+\s*=\s*[^\s>]*/gi,"")}toggleViewModeDropdown(e){let n=document.querySelector(".overtype-dropdown-menu");if(n){n.remove(),e.classList.remove("dropdown-active");return}e.classList.add("dropdown-active");let o=this.createViewModeDropdown(e),i=e.getBoundingClientRect();o.style.position="absolute",o.style.top=`${i.bottom+5}px`,o.style.left=`${i.left}px`,document.body.appendChild(o),this.handleDocumentClick=r=>{!o.contains(r.target)&&!e.contains(r.target)&&(o.remove(),e.classList.remove("dropdown-active"),document.removeEventListener("click",this.handleDocumentClick))},setTimeout(()=>{document.addEventListener("click",this.handleDocumentClick)},0)}createViewModeDropdown(e){let n=document.createElement("div");n.className="overtype-dropdown-menu";let o=[{id:"normal",label:"Normal Edit",icon:"\u2713"},{id:"plain",label:"Plain Textarea",icon:"\u2713"},{id:"preview",label:"Preview Mode",icon:"\u2713"}],i=this.editor.container.dataset.mode||"normal";return o.forEach(r=>{let s=document.createElement("button");if(s.className="overtype-dropdown-item",s.type="button",s.textContent=r.label,r.id===i){s.classList.add("active"),s.setAttribute("aria-current","true");let a=document.createElement("span");a.className="overtype-dropdown-icon",a.textContent=r.icon,s.prepend(a)}s.addEventListener("click",a=>{switch(a.preventDefault(),r.id){case"plain":this.editor.showPlainTextarea();break;case"preview":this.editor.showPreviewMode();break;case"normal":default:this.editor.showNormalEditMode();break}n.remove(),e.classList.remove("dropdown-active"),document.removeEventListener("click",this.handleDocumentClick)}),n.appendChild(s)}),n}updateButtonStates(){var e;try{let n=((e=mt)==null?void 0:e(this.editor.textarea,this.editor.textarea.selectionStart))||[];Object.entries(this.buttons).forEach(([o,i])=>{if(o==="viewMode")return;let r=!1;switch(o){case"bold":r=n.includes("bold");break;case"italic":r=n.includes("italic");break;case"code":r=!1;break;case"bulletList":r=n.includes("bullet-list");break;case"orderedList":r=n.includes("numbered-list");break;case"taskList":r=n.includes("task-list");break;case"quote":r=n.includes("quote");break;case"h1":r=n.includes("header");break;case"h2":r=n.includes("header-2");break;case"h3":r=n.includes("header-3");break}i.classList.toggle("active",r),i.setAttribute("aria-pressed",r.toString())})}catch(n){}}show(){this.container&&this.container.classList.remove("overtype-toolbar-hidden")}hide(){this.container&&this.container.classList.add("overtype-toolbar-hidden")}destroy(){this.container&&(this.handleDocumentClick&&document.removeEventListener("click",this.handleDocumentClick),Object.values(this.buttons).forEach(e=>{e._clickHandler&&(e.removeEventListener("click",e._clickHandler),delete e._clickHandler)}),this.container.remove(),this.container=null,this.buttons={})}};var le=Math.min,W=Math.max,ce=Math.round;var P=t=>({x:t,y:t}),Cn={left:"right",right:"left",bottom:"top",top:"bottom"},An={start:"end",end:"start"};function Be(t,e,n){return W(t,le(e,n))}function pe(t,e){return typeof t=="function"?t(e):t}function q(t){return t.split("-")[0]}function de(t){return t.split("-")[1]}function _e(t){return t==="x"?"y":"x"}function Fe(t){return t==="y"?"height":"width"}var Mn=new Set(["top","bottom"]);function N(t){return Mn.has(q(t))?"y":"x"}function Ne(t){return _e(N(t))}function wt(t,e,n){n===void 0&&(n=!1);let o=de(t),i=Ne(t),r=Fe(i),s=i==="x"?o===(n?"end":"start")?"right":"left":o==="start"?"bottom":"top";return e.reference[r]>e.floating[r]&&(s=ae(s)),[s,ae(s)]}function bt(t){let e=ae(t);return[Le(t),e,Le(e)]}function Le(t){return t.replace(/start|end/g,e=>An[e])}var vt=["left","right"],yt=["right","left"],Hn=["top","bottom"],On=["bottom","top"];function Pn(t,e,n){switch(t){case"top":case"bottom":return n?e?yt:vt:e?vt:yt;case"left":case"right":return e?Hn:On;default:return[]}}function xt(t,e,n,o){let i=de(t),r=Pn(q(t),n==="start",o);return i&&(r=r.map(s=>s+"-"+i),e&&(r=r.concat(r.map(Le)))),r}function ae(t){return t.replace(/left|right|bottom|top/g,e=>Cn[e])}function $n(t){return{top:0,right:0,bottom:0,left:0,...t}}function kt(t){return typeof t!="number"?$n(t):{top:t,right:t,bottom:t,left:t}}function G(t){let{x:e,y:n,width:o,height:i}=t;return{width:o,height:i,top:n,left:e,right:e+o,bottom:n+i,x:e,y:n}}function Lt(t,e,n){let{reference:o,floating:i}=t,r=N(e),s=Ne(e),a=Fe(s),c=q(e),d=r==="y",l=o.x+o.width/2-i.width/2,p=o.y+o.height/2-i.height/2,h=o[a]/2-i[a]/2,u;switch(c){case"top":u={x:l,y:o.y-i.height};break;case"bottom":u={x:l,y:o.y+o.height};break;case"right":u={x:o.x+o.width,y:p};break;case"left":u={x:o.x-i.width,y:p};break;default:u={x:o.x,y:o.y}}switch(de(e)){case"start":u[s]-=h*(n&&d?-1:1);break;case"end":u[s]+=h*(n&&d?-1:1);break}return u}async function St(t,e){var n;e===void 0&&(e={});let{x:o,y:i,platform:r,rects:s,elements:a,strategy:c}=t,{boundary:d="clippingAncestors",rootBoundary:l="viewport",elementContext:p="floating",altBoundary:h=!1,padding:u=0}=pe(e,t),f=kt(u),g=a[h?p==="floating"?"reference":"floating":p],y=G(await r.getClippingRect({element:(n=await(r.isElement==null?void 0:r.isElement(g)))==null||n?g:g.contextElement||await(r.getDocumentElement==null?void 0:r.getDocumentElement(a.floating)),boundary:d,rootBoundary:l,strategy:c})),w=p==="floating"?{x:o,y:i,width:s.floating.width,height:s.floating.height}:s.reference,b=await(r.getOffsetParent==null?void 0:r.getOffsetParent(a.floating)),L=await(r.isElement==null?void 0:r.isElement(b))?await(r.getScale==null?void 0:r.getScale(b))||{x:1,y:1}:{x:1,y:1},k=G(r.convertOffsetParentRelativeRectToViewportRelativeRect?await r.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:w,offsetParent:b,strategy:c}):w);return{top:(y.top-k.top+f.top)/L.y,bottom:(k.bottom-y.bottom+f.bottom)/L.y,left:(y.left-k.left+f.left)/L.x,right:(k.right-y.right+f.right)/L.x}}var Et=async(t,e,n)=>{let{placement:o="bottom",strategy:i="absolute",middleware:r=[],platform:s}=n,a=r.filter(Boolean),c=await(s.isRTL==null?void 0:s.isRTL(e)),d=await s.getElementRects({reference:t,floating:e,strategy:i}),{x:l,y:p}=Lt(d,o,c),h=o,u={},f=0;for(let g=0;g<a.length;g++){var m;let{name:y,fn:w}=a[g],{x:b,y:L,data:k,reset:E}=await w({x:l,y:p,initialPlacement:o,placement:h,strategy:i,middlewareData:u,rects:d,platform:{...s,detectOverflow:(m=s.detectOverflow)!=null?m:St},elements:{reference:t,floating:e}});l=b!=null?b:l,p=L!=null?L:p,u={...u,[y]:{...u[y],...k}},E&&f<=50&&(f++,typeof E=="object"&&(E.placement&&(h=E.placement),E.rects&&(d=E.rects===!0?await s.getElementRects({reference:t,floating:e,strategy:i}):E.rects),{x:l,y:p}=Lt(d,h,c)),g=-1)}return{x:l,y:p,placement:h,strategy:i,middlewareData:u}};var Tt=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(e){var n,o;let{placement:i,middlewareData:r,rects:s,initialPlacement:a,platform:c,elements:d}=e,{mainAxis:l=!0,crossAxis:p=!0,fallbackPlacements:h,fallbackStrategy:u="bestFit",fallbackAxisSideDirection:f="none",flipAlignment:m=!0,...g}=pe(t,e);if((n=r.arrow)!=null&&n.alignmentOffset)return{};let y=q(i),w=N(a),b=q(a)===a,L=await(c.isRTL==null?void 0:c.isRTL(d.floating)),k=h||(b||!m?[ae(a)]:bt(a)),E=f!=="none";!h&&E&&k.push(...xt(a,m,f,L));let me=[a,...k],Y=await c.detectOverflow(e,g),ge=[],ee=((o=r.flip)==null?void 0:o.overflows)||[];if(l&&ge.push(Y[y]),p){let K=wt(i,s,L);ge.push(Y[K[0]],Y[K[1]])}if(ee=[...ee,{placement:i,overflows:ge}],!ge.every(K=>K<=0)){var je,Ve;let K=(((je=r.flip)==null?void 0:je.index)||0)+1,Oe=me[K];if(Oe&&(!(p==="alignment"?w!==N(Oe):!1)||ee.every(O=>N(O.placement)===w?O.overflows[0]>0:!0)))return{data:{index:K,overflows:ee},reset:{placement:Oe}};let ie=(Ve=ee.filter(Z=>Z.overflows[0]<=0).sort((Z,O)=>Z.overflows[1]-O.overflows[1])[0])==null?void 0:Ve.placement;if(!ie)switch(u){case"bestFit":{var Ue;let Z=(Ue=ee.filter(O=>{if(E){let j=N(O.placement);return j===w||j==="y"}return!0}).map(O=>[O.placement,O.overflows.filter(j=>j>0).reduce((j,ln)=>j+ln,0)]).sort((O,j)=>O[1]-j[1])[0])==null?void 0:Ue[0];Z&&(ie=Z);break}case"initialPlacement":ie=a;break}if(i!==ie)return{reset:{placement:ie}}}return{}}}};var In=new Set(["left","top"]);async function Rn(t,e){let{placement:n,platform:o,elements:i}=t,r=await(o.isRTL==null?void 0:o.isRTL(i.floating)),s=q(n),a=de(n),c=N(n)==="y",d=In.has(s)?-1:1,l=r&&c?-1:1,p=pe(e,t),{mainAxis:h,crossAxis:u,alignmentAxis:f}=typeof p=="number"?{mainAxis:p,crossAxis:0,alignmentAxis:null}:{mainAxis:p.mainAxis||0,crossAxis:p.crossAxis||0,alignmentAxis:p.alignmentAxis};return a&&typeof f=="number"&&(u=a==="end"?f*-1:f),c?{x:u*l,y:h*d}:{x:h*d,y:u*l}}var Ct=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(e){var n,o;let{x:i,y:r,placement:s,middlewareData:a}=e,c=await Rn(e,t);return s===((n=a.offset)==null?void 0:n.placement)&&(o=a.arrow)!=null&&o.alignmentOffset?{}:{x:i+c.x,y:r+c.y,data:{...c,placement:s}}}}},At=function(t){return t===void 0&&(t={}),{name:"shift",options:t,async fn(e){let{x:n,y:o,placement:i,platform:r}=e,{mainAxis:s=!0,crossAxis:a=!1,limiter:c={fn:y=>{let{x:w,y:b}=y;return{x:w,y:b}}},...d}=pe(t,e),l={x:n,y:o},p=await r.detectOverflow(e,d),h=N(q(i)),u=_e(h),f=l[u],m=l[h];if(s){let y=u==="y"?"top":"left",w=u==="y"?"bottom":"right",b=f+p[y],L=f-p[w];f=Be(b,f,L)}if(a){let y=h==="y"?"top":"left",w=h==="y"?"bottom":"right",b=m+p[y],L=m-p[w];m=Be(b,m,L)}let g=c.fn({...e,[u]:f,[h]:m});return{...g,data:{x:g.x-n,y:g.y-o,enabled:{[u]:s,[h]:a}}}}}};function Ee(){return typeof window<"u"}function J(t){return Ht(t)?(t.nodeName||"").toLowerCase():"#document"}function A(t){var e;return(t==null||(e=t.ownerDocument)==null?void 0:e.defaultView)||window}function R(t){var e;return(e=(Ht(t)?t.ownerDocument:t.document)||window.document)==null?void 0:e.documentElement}function Ht(t){return Ee()?t instanceof Node||t instanceof A(t).Node:!1}function M(t){return Ee()?t instanceof Element||t instanceof A(t).Element:!1}function $(t){return Ee()?t instanceof HTMLElement||t instanceof A(t).HTMLElement:!1}function Mt(t){return!Ee()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof A(t).ShadowRoot}var Bn=new Set(["inline","contents"]);function te(t){let{overflow:e,overflowX:n,overflowY:o,display:i}=H(t);return/auto|scroll|overlay|hidden|clip/.test(e+o+n)&&!Bn.has(i)}var _n=new Set(["table","td","th"]);function Ot(t){return _n.has(J(t))}var Fn=[":popover-open",":modal"];function ue(t){return Fn.some(e=>{try{return t.matches(e)}catch(n){return!1}})}var Nn=["transform","translate","scale","rotate","perspective"],Dn=["transform","translate","scale","rotate","perspective","filter"],zn=["paint","layout","strict","content"];function Te(t){let e=Ce(),n=M(t)?H(t):t;return Nn.some(o=>n[o]?n[o]!=="none":!1)||(n.containerType?n.containerType!=="normal":!1)||!e&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!e&&(n.filter?n.filter!=="none":!1)||Dn.some(o=>(n.willChange||"").includes(o))||zn.some(o=>(n.contain||"").includes(o))}function Pt(t){let e=D(t);for(;$(e)&&!X(e);){if(Te(e))return e;if(ue(e))return null;e=D(e)}return null}function Ce(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}var jn=new Set(["html","body","#document"]);function X(t){return jn.has(J(t))}function H(t){return A(t).getComputedStyle(t)}function he(t){return M(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function D(t){if(J(t)==="html")return t;let e=t.assignedSlot||t.parentNode||Mt(t)&&t.host||R(t);return Mt(e)?e.host:e}function $t(t){let e=D(t);return X(e)?t.ownerDocument?t.ownerDocument.body:t.body:$(e)&&te(e)?e:$t(e)}function Se(t,e,n){var o;e===void 0&&(e=[]),n===void 0&&(n=!0);let i=$t(t),r=i===((o=t.ownerDocument)==null?void 0:o.body),s=A(i);if(r){let a=Ae(s);return e.concat(s,s.visualViewport||[],te(i)?i:[],a&&n?Se(a):[])}return e.concat(i,Se(i,[],n))}function Ae(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function _t(t){let e=H(t),n=parseFloat(e.width)||0,o=parseFloat(e.height)||0,i=$(t),r=i?t.offsetWidth:n,s=i?t.offsetHeight:o,a=ce(n)!==r||ce(o)!==s;return a&&(n=r,o=s),{width:n,height:o,$:a}}function Ft(t){return M(t)?t:t.contextElement}function ne(t){let e=Ft(t);if(!$(e))return P(1);let n=e.getBoundingClientRect(),{width:o,height:i,$:r}=_t(e),s=(r?ce(n.width):n.width)/o,a=(r?ce(n.height):n.height)/i;return(!s||!Number.isFinite(s))&&(s=1),(!a||!Number.isFinite(a))&&(a=1),{x:s,y:a}}var Vn=P(0);function Nt(t){let e=A(t);return!Ce()||!e.visualViewport?Vn:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function Un(t,e,n){return e===void 0&&(e=!1),!n||e&&n!==A(t)?!1:e}function fe(t,e,n,o){e===void 0&&(e=!1),n===void 0&&(n=!1);let i=t.getBoundingClientRect(),r=Ft(t),s=P(1);e&&(o?M(o)&&(s=ne(o)):s=ne(t));let a=Un(r,n,o)?Nt(r):P(0),c=(i.left+a.x)/s.x,d=(i.top+a.y)/s.y,l=i.width/s.x,p=i.height/s.y;if(r){let h=A(r),u=o&&M(o)?A(o):o,f=h,m=Ae(f);for(;m&&o&&u!==f;){let g=ne(m),y=m.getBoundingClientRect(),w=H(m),b=y.left+(m.clientLeft+parseFloat(w.paddingLeft))*g.x,L=y.top+(m.clientTop+parseFloat(w.paddingTop))*g.y;c*=g.x,d*=g.y,l*=g.x,p*=g.y,c+=b,d+=L,f=A(m),m=Ae(f)}}return G({width:l,height:p,x:c,y:d})}function Me(t,e){let n=he(t).scrollLeft;return e?e.left+n:fe(R(t)).left+n}function Dt(t,e){let n=t.getBoundingClientRect(),o=n.left+e.scrollLeft-Me(t,n),i=n.top+e.scrollTop;return{x:o,y:i}}function Wn(t){let{elements:e,rect:n,offsetParent:o,strategy:i}=t,r=i==="fixed",s=R(o),a=e?ue(e.floating):!1;if(o===s||a&&r)return n;let c={scrollLeft:0,scrollTop:0},d=P(1),l=P(0),p=$(o);if((p||!p&&!r)&&((J(o)!=="body"||te(s))&&(c=he(o)),$(o))){let u=fe(o);d=ne(o),l.x=u.x+o.clientLeft,l.y=u.y+o.clientTop}let h=s&&!p&&!r?Dt(s,c):P(0);return{width:n.width*d.x,height:n.height*d.y,x:n.x*d.x-c.scrollLeft*d.x+l.x+h.x,y:n.y*d.y-c.scrollTop*d.y+l.y+h.y}}function qn(t){return Array.from(t.getClientRects())}function Kn(t){let e=R(t),n=he(t),o=t.ownerDocument.body,i=W(e.scrollWidth,e.clientWidth,o.scrollWidth,o.clientWidth),r=W(e.scrollHeight,e.clientHeight,o.scrollHeight,o.clientHeight),s=-n.scrollLeft+Me(t),a=-n.scrollTop;return H(o).direction==="rtl"&&(s+=W(e.clientWidth,o.clientWidth)-i),{width:i,height:r,x:s,y:a}}var It=25;function Zn(t,e){let n=A(t),o=R(t),i=n.visualViewport,r=o.clientWidth,s=o.clientHeight,a=0,c=0;if(i){r=i.width,s=i.height;let l=Ce();(!l||l&&e==="fixed")&&(a=i.offsetLeft,c=i.offsetTop)}let d=Me(o);if(d<=0){let l=o.ownerDocument,p=l.body,h=getComputedStyle(p),u=l.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,f=Math.abs(o.clientWidth-p.clientWidth-u);f<=It&&(r-=f)}else d<=It&&(r+=d);return{width:r,height:s,x:a,y:c}}var Qn=new Set(["absolute","fixed"]);function Gn(t,e){let n=fe(t,!0,e==="fixed"),o=n.top+t.clientTop,i=n.left+t.clientLeft,r=$(t)?ne(t):P(1),s=t.clientWidth*r.x,a=t.clientHeight*r.y,c=i*r.x,d=o*r.y;return{width:s,height:a,x:c,y:d}}function Rt(t,e,n){let o;if(e==="viewport")o=Zn(t,n);else if(e==="document")o=Kn(R(t));else if(M(e))o=Gn(e,n);else{let i=Nt(t);o={x:e.x-i.x,y:e.y-i.y,width:e.width,height:e.height}}return G(o)}function zt(t,e){let n=D(t);return n===e||!M(n)||X(n)?!1:H(n).position==="fixed"||zt(n,e)}function Jn(t,e){let n=e.get(t);if(n)return n;let o=Se(t,[],!1).filter(a=>M(a)&&J(a)!=="body"),i=null,r=H(t).position==="fixed",s=r?D(t):t;for(;M(s)&&!X(s);){let a=H(s),c=Te(s);!c&&a.position==="fixed"&&(i=null),(r?!c&&!i:!c&&a.position==="static"&&!!i&&Qn.has(i.position)||te(s)&&!c&&zt(t,s))?o=o.filter(l=>l!==s):i=a,s=D(s)}return e.set(t,o),o}function Xn(t){let{element:e,boundary:n,rootBoundary:o,strategy:i}=t,s=[...n==="clippingAncestors"?ue(e)?[]:Jn(e,this._c):[].concat(n),o],a=s[0],c=s.reduce((d,l)=>{let p=Rt(e,l,i);return d.top=W(p.top,d.top),d.right=le(p.right,d.right),d.bottom=le(p.bottom,d.bottom),d.left=W(p.left,d.left),d},Rt(e,a,i));return{width:c.right-c.left,height:c.bottom-c.top,x:c.left,y:c.top}}function Yn(t){let{width:e,height:n}=_t(t);return{width:e,height:n}}function eo(t,e,n){let o=$(e),i=R(e),r=n==="fixed",s=fe(t,!0,r,e),a={scrollLeft:0,scrollTop:0},c=P(0);function d(){c.x=Me(i)}if(o||!o&&!r)if((J(e)!=="body"||te(i))&&(a=he(e)),o){let u=fe(e,!0,r,e);c.x=u.x+e.clientLeft,c.y=u.y+e.clientTop}else i&&d();r&&!o&&i&&d();let l=i&&!o&&!r?Dt(i,a):P(0),p=s.left+a.scrollLeft-c.x-l.x,h=s.top+a.scrollTop-c.y-l.y;return{x:p,y:h,width:s.width,height:s.height}}function De(t){return H(t).position==="static"}function Bt(t,e){if(!$(t)||H(t).position==="fixed")return null;if(e)return e(t);let n=t.offsetParent;return R(t)===n&&(n=n.ownerDocument.body),n}function jt(t,e){let n=A(t);if(ue(t))return n;if(!$(t)){let i=D(t);for(;i&&!X(i);){if(M(i)&&!De(i))return i;i=D(i)}return n}let o=Bt(t,e);for(;o&&Ot(o)&&De(o);)o=Bt(o,e);return o&&X(o)&&De(o)&&!Te(o)?n:o||Pt(t)||n}var to=async function(t){let e=this.getOffsetParent||jt,n=this.getDimensions,o=await n(t.floating);return{reference:eo(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:o.width,height:o.height}}};function no(t){return H(t).direction==="rtl"}var oo={convertOffsetParentRelativeRectToViewportRelativeRect:Wn,getDocumentElement:R,getClippingRect:Xn,getOffsetParent:jt,getElementRects:to,getClientRects:qn,getDimensions:Yn,getScale:ne,isElement:M,isRTL:no};var Vt=Ct;var Ut=At,Wt=Tt;var qt=(t,e,n)=>{let o=new Map,i={platform:oo,...n},r={...i.platform,_c:o};return Et(t,e,{...i,platform:r})};var He=class{constructor(e){this.editor=e,this.tooltip=null,this.currentLink=null,this.hideTimeout=null,this.visibilityChangeHandler=null,this.isTooltipHovered=!1,this.init()}init(){this.createTooltip(),this.editor.textarea.addEventListener("selectionchange",()=>this.checkCursorPosition()),this.editor.textarea.addEventListener("keyup",e=>{(e.key.includes("Arrow")||e.key==="Home"||e.key==="End")&&this.checkCursorPosition()}),this.editor.textarea.addEventListener("input",()=>this.hide()),this.editor.textarea.addEventListener("scroll",()=>{this.currentLink&&this.positionTooltip(this.currentLink)}),this.editor.textarea.addEventListener("blur",()=>{this.isTooltipHovered||this.hide()}),this.visibilityChangeHandler=()=>{document.hidden&&this.hide()},document.addEventListener("visibilitychange",this.visibilityChangeHandler),this.tooltip.addEventListener("mouseenter",()=>{this.isTooltipHovered=!0,this.cancelHide()}),this.tooltip.addEventListener("mouseleave",()=>{this.isTooltipHovered=!1,this.scheduleHide()})}createTooltip(){this.tooltip=document.createElement("div"),this.tooltip.className="overtype-link-tooltip",this.tooltip.innerHTML=`
|
|
886
894
|
<span style="display: flex; align-items: center; gap: 6px;">
|
|
887
895
|
<svg width="12" height="12" viewBox="0 0 20 20" fill="currentColor" style="flex-shrink: 0;">
|
|
888
896
|
<path d="M11 3a1 1 0 100 2h2.586l-6.293 6.293a1 1 0 101.414 1.414L15 6.414V9a1 1 0 102 0V4a1 1 0 00-1-1h-5z"></path>
|
|
@@ -890,35 +898,35 @@ ${a}`:r;if(d){let L=o.value[o.selectionStart-1];o.selectionStart!==0&&L!=null&&!
|
|
|
890
898
|
</svg>
|
|
891
899
|
<span class="overtype-link-tooltip-url"></span>
|
|
892
900
|
</span>
|
|
893
|
-
`,this.tooltip.addEventListener("click",e=>{e.preventDefault(),e.stopPropagation(),this.currentLink&&(window.open(this.currentLink.url,"_blank"),this.hide())}),this.editor.container.appendChild(this.tooltip)}checkCursorPosition(){let e=this.editor.textarea.selectionStart,
|
|
901
|
+
`,this.tooltip.addEventListener("click",e=>{e.preventDefault(),e.stopPropagation(),this.currentLink&&(window.open(this.currentLink.url,"_blank"),this.hide())}),this.editor.container.appendChild(this.tooltip)}checkCursorPosition(){let e=this.editor.textarea.selectionStart,n=this.editor.textarea.value,o=this.findLinkAtPosition(n,e);o?(!this.currentLink||this.currentLink.url!==o.url||this.currentLink.index!==o.index)&&this.show(o):this.scheduleHide()}findLinkAtPosition(e,n){let o=/\[([^\]]+)\]\(([^)]+)\)/g,i,r=0;for(;(i=o.exec(e))!==null;){let s=i.index,a=i.index+i[0].length;if(n>=s&&n<=a)return{text:i[1],url:i[2],index:r,start:s,end:a};r++}return null}async show(e){this.currentLink=e,this.cancelHide();let n=this.tooltip.querySelector(".overtype-link-tooltip-url");n.textContent=e.url,await this.positionTooltip(e),this.currentLink===e&&this.tooltip.classList.add("visible")}async positionTooltip(e){let n=this.findAnchorElement(e.index);if(!n)return;let o=n.getBoundingClientRect();if(!(o.width===0||o.height===0))try{let{x:i,y:r}=await qt(n,this.tooltip,{strategy:"fixed",placement:"bottom",middleware:[Vt(8),Ut({padding:8}),Wt()]});Object.assign(this.tooltip.style,{left:`${i}px`,top:`${r}px`,position:"fixed"})}catch(i){console.warn("Floating UI positioning failed:",i)}}findAnchorElement(e){return this.editor.preview.querySelector(`a[style*="--link-${e}"]`)}hide(){this.tooltip.classList.remove("visible"),this.currentLink=null,this.isTooltipHovered=!1}scheduleHide(){this.cancelHide(),this.hideTimeout=setTimeout(()=>this.hide(),300)}cancelHide(){this.hideTimeout&&(clearTimeout(this.hideTimeout),this.hideTimeout=null)}destroy(){this.cancelHide(),this.visibilityChangeHandler&&(document.removeEventListener("visibilitychange",this.visibilityChangeHandler),this.visibilityChangeHandler=null),this.tooltip&&this.tooltip.parentNode&&this.tooltip.parentNode.removeChild(this.tooltip),this.tooltip=null,this.currentLink=null,this.isTooltipHovered=!1}};var Kt=`<svg viewBox="0 0 18 18">
|
|
894
902
|
<path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5,4H9.5A2.5,2.5,0,0,1,12,6.5v0A2.5,2.5,0,0,1,9.5,9H5A0,0,0,0,1,5,9V4A0,0,0,0,1,5,4Z"></path>
|
|
895
903
|
<path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5,9h5.5A2.5,2.5,0,0,1,13,11.5v0A2.5,2.5,0,0,1,10.5,14H5a0,0,0,0,1,0,0V9A0,0,0,0,1,5,9Z"></path>
|
|
896
|
-
</svg>`,
|
|
904
|
+
</svg>`,Zt=`<svg viewBox="0 0 18 18">
|
|
897
905
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="13" y1="4" y2="4"></line>
|
|
898
906
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="5" x2="11" y1="14" y2="14"></line>
|
|
899
907
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="10" y1="14" y2="4"></line>
|
|
900
|
-
</svg>`,
|
|
908
|
+
</svg>`,Qt=`<svg viewBox="0 0 18 18">
|
|
901
909
|
<path fill="currentColor" d="M10,4V14a1,1,0,0,1-2,0V10H3v4a1,1,0,0,1-2,0V4A1,1,0,0,1,3,4V8H8V4a1,1,0,0,1,2,0Zm6.06787,9.209H14.98975V7.59863a.54085.54085,0,0,0-.605-.60547h-.62744a1.01119,1.01119,0,0,0-.748.29688L11.645,8.56641a.5435.5435,0,0,0-.022.8584l.28613.30762a.53861.53861,0,0,0,.84717.0332l.09912-.08789a1.2137,1.2137,0,0,0,.2417-.35254h.02246s-.01123.30859-.01123.60547V13.209H12.041a.54085.54085,0,0,0-.605.60547v.43945a.54085.54085,0,0,0,.605.60547h4.02686a.54085.54085,0,0,0,.605-.60547v-.43945A.54085.54085,0,0,0,16.06787,13.209Z"></path>
|
|
902
|
-
</svg>`,
|
|
910
|
+
</svg>`,Gt=`<svg viewBox="0 0 18 18">
|
|
903
911
|
<path fill="currentColor" d="M16.73975,13.81445v.43945a.54085.54085,0,0,1-.605.60547H11.855a.58392.58392,0,0,1-.64893-.60547V14.0127c0-2.90527,3.39941-3.42187,3.39941-4.55469a.77675.77675,0,0,0-.84717-.78125,1.17684,1.17684,0,0,0-.83594.38477c-.2749.26367-.561.374-.85791.13184l-.4292-.34082c-.30811-.24219-.38525-.51758-.1543-.81445a2.97155,2.97155,0,0,1,2.45361-1.17676,2.45393,2.45393,0,0,1,2.68408,2.40918c0,2.45312-3.1792,2.92676-3.27832,3.93848h2.79443A.54085.54085,0,0,1,16.73975,13.81445ZM9,3A.99974.99974,0,0,0,8,4V8H3V4A1,1,0,0,0,1,4V14a1,1,0,0,0,2,0V10H8v4a1,1,0,0,0,2,0V4A.99974.99974,0,0,0,9,3Z"></path>
|
|
904
|
-
</svg>`,
|
|
912
|
+
</svg>`,Jt=`<svg viewBox="0 0 18 18">
|
|
905
913
|
<path fill="currentColor" d="M16.65186,12.30664a2.6742,2.6742,0,0,1-2.915,2.68457,3.96592,3.96592,0,0,1-2.25537-.6709.56007.56007,0,0,1-.13232-.83594L11.64648,13c.209-.34082.48389-.36328.82471-.1543a2.32654,2.32654,0,0,0,1.12256.33008c.71484,0,1.12207-.35156,1.12207-.78125,0-.61523-.61621-.86816-1.46338-.86816H13.2085a.65159.65159,0,0,1-.68213-.41895l-.05518-.10937a.67114.67114,0,0,1,.14307-.78125l.71533-.86914a8.55289,8.55289,0,0,1,.68213-.7373V8.58887a3.93913,3.93913,0,0,1-.748.05469H11.9873a.54085.54085,0,0,1-.605-.60547V7.59863a.54085.54085,0,0,1,.605-.60547h3.75146a.53773.53773,0,0,1,.60547.59375v.17676a1.03723,1.03723,0,0,1-.27539.748L14.74854,10.0293A2.31132,2.31132,0,0,1,16.65186,12.30664ZM9,3A.99974.99974,0,0,0,8,4V8H3V4A1,1,0,0,0,1,4V14a1,1,0,0,0,2,0V10H8v4a1,1,0,0,0,2,0V4A.99974.99974,0,0,0,9,3Z"></path>
|
|
906
|
-
</svg>`,
|
|
914
|
+
</svg>`,Xt=`<svg viewBox="0 0 18 18">
|
|
907
915
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="11" y1="7" y2="11"></line>
|
|
908
916
|
<path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8.9,4.577a3.476,3.476,0,0,1,.36,4.679A3.476,3.476,0,0,1,4.577,8.9C3.185,7.5,2.035,6.4,4.217,4.217S7.5,3.185,8.9,4.577Z"></path>
|
|
909
917
|
<path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13.423,9.1a3.476,3.476,0,0,0-4.679-.36,3.476,3.476,0,0,0,.36,4.679c1.392,1.392,2.5,2.542,4.679.36S14.815,10.5,13.423,9.1Z"></path>
|
|
910
|
-
</svg
|
|
918
|
+
</svg>`,Yt=`<svg viewBox="0 0 18 18">
|
|
911
919
|
<polyline stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" points="5 7 3 9 5 11"></polyline>
|
|
912
920
|
<polyline stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" points="13 7 15 9 13 11"></polyline>
|
|
913
921
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="10" x2="8" y1="5" y2="13"></line>
|
|
914
|
-
</svg>`,
|
|
922
|
+
</svg>`,en=`<svg viewBox="0 0 18 18">
|
|
915
923
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="4" y2="4"></line>
|
|
916
924
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="9" y2="9"></line>
|
|
917
925
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="14" y2="14"></line>
|
|
918
926
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="3" x2="3" y1="4" y2="4"></line>
|
|
919
927
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="3" x2="3" y1="9" y2="9"></line>
|
|
920
928
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="3" x2="3" y1="14" y2="14"></line>
|
|
921
|
-
</svg>`,
|
|
929
|
+
</svg>`,tn=`<svg viewBox="0 0 18 18">
|
|
922
930
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="15" y1="4" y2="4"></line>
|
|
923
931
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="15" y1="9" y2="9"></line>
|
|
924
932
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="15" y1="14" y2="14"></line>
|
|
@@ -926,37 +934,42 @@ ${a}`:r;if(d){let L=o.value[o.selectionStart-1];o.selectionStart!==0&&L!=null&&!
|
|
|
926
934
|
<path fill="currentColor" d="M3.5,6A0.5,0.5,0,0,1,3,5.5V3.085l-0.276.138A0.5,0.5,0,0,1,2.053,3c-0.124-.247-0.023-0.324.224-0.447l1-.5A0.5,0.5,0,0,1,4,2.5v3A0.5,0.5,0,0,1,3.5,6Z"></path>
|
|
927
935
|
<path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="1" d="M4.5,10.5h-2c0-.234,1.85-1.076,1.85-2.234A0.959,0.959,0,0,0,2.5,8.156"></path>
|
|
928
936
|
<path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="1" d="M2.5,14.846a0.959,0.959,0,0,0,1.85-.109A0.7,0.7,0,0,0,3.75,14a0.688,0.688,0,0,0,.6-0.736,0.959,0.959,0,0,0-1.85-.109"></path>
|
|
929
|
-
</svg>`,
|
|
937
|
+
</svg>`,nn=`<svg viewBox="2 2 20 20">
|
|
930
938
|
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 10.8182L9 10.8182C8.80222 10.8182 8.60888 10.7649 8.44443 10.665C8.27998 10.5651 8.15181 10.4231 8.07612 10.257C8.00043 10.0909 7.98063 9.90808 8.01922 9.73174C8.0578 9.55539 8.15304 9.39341 8.29289 9.26627C8.43275 9.13913 8.61093 9.05255 8.80491 9.01747C8.99889 8.98239 9.19996 9.00039 9.38268 9.0692C9.56541 9.13801 9.72159 9.25453 9.83147 9.40403C9.94135 9.55353 10 9.72929 10 9.90909L10 12.1818C10 12.664 9.78929 13.1265 9.41421 13.4675C9.03914 13.8084 8.53043 14 8 14"></path>
|
|
931
939
|
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 10.8182L15 10.8182C14.8022 10.8182 14.6089 10.7649 14.4444 10.665C14.28 10.5651 14.1518 10.4231 14.0761 10.257C14.0004 10.0909 13.9806 9.90808 14.0192 9.73174C14.0578 9.55539 14.153 9.39341 14.2929 9.26627C14.4327 9.13913 14.6109 9.05255 14.8049 9.01747C14.9989 8.98239 15.2 9.00039 15.3827 9.0692C15.5654 9.13801 15.7216 9.25453 15.8315 9.40403C15.9414 9.55353 16 9.72929 16 9.90909L16 12.1818C16 12.664 15.7893 13.1265 15.4142 13.4675C15.0391 13.8084 14.5304 14 14 14"></path>
|
|
932
|
-
</svg>`,
|
|
940
|
+
</svg>`,on=`<svg viewBox="0 0 18 18">
|
|
933
941
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="16" y1="4" y2="4"></line>
|
|
934
942
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="16" y1="9" y2="9"></line>
|
|
935
943
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="16" y1="14" y2="14"></line>
|
|
936
944
|
<rect stroke="currentColor" fill="none" stroke-width="1.5" x="2" y="3" width="3" height="3" rx="0.5"></rect>
|
|
937
945
|
<rect stroke="currentColor" fill="none" stroke-width="1.5" x="2" y="13" width="3" height="3" rx="0.5"></rect>
|
|
938
946
|
<polyline stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" points="2.65 9.5 3.5 10.5 5 8.5"></polyline>
|
|
939
|
-
</svg>`,
|
|
947
|
+
</svg>`,rn=`<svg viewBox="0 0 18 18">
|
|
948
|
+
<path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.25 12.375v1.688A1.688 1.688 0 0 0 3.938 15.75h10.124a1.688 1.688 0 0 0 1.688-1.688V12.375"></path>
|
|
949
|
+
<path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5.063 6.188L9 2.25l3.938 3.938"></path>
|
|
950
|
+
<path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 2.25v10.125"></path>
|
|
951
|
+
</svg>`,sn=`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
940
952
|
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" fill="none"></path>
|
|
941
953
|
<circle cx="12" cy="12" r="3" fill="none"></circle>
|
|
942
|
-
</svg>`;var k={bold:{name:"bold",icon:Le,title:"Bold (Ctrl+B)",action:({editor:o,event:e})=>{U(o.textarea),o.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},italic:{name:"italic",icon:Se,title:"Italic (Ctrl+I)",action:({editor:o,event:e})=>{D(o.textarea),o.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},code:{name:"code",icon:$e,title:"Inline Code",action:({editor:o,event:e})=>{ue(o.textarea),o.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},separator:{name:"separator"},link:{name:"link",icon:Ae,title:"Insert Link",action:({editor:o,event:e})=>{q(o.textarea),o.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h1:{name:"h1",icon:Ee,title:"Heading 1",action:({editor:o,event:e})=>{fe(o.textarea),o.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h2:{name:"h2",icon:Ce,title:"Heading 2",action:({editor:o,event:e})=>{ge(o.textarea),o.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h3:{name:"h3",icon:Te,title:"Heading 3",action:({editor:o,event:e})=>{ve(o.textarea),o.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},bulletList:{name:"bulletList",icon:He,title:"Bullet List",action:({editor:o,event:e})=>{W(o.textarea),o.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},orderedList:{name:"orderedList",icon:Me,title:"Numbered List",action:({editor:o,event:e})=>{K(o.textarea),o.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},taskList:{name:"taskList",icon:Pe,title:"Task List",action:({editor:o,event:e})=>{X&&(X(o.textarea),o.textarea.dispatchEvent(new Event("input",{bubbles:!0})))}},quote:{name:"quote",icon:Ie,title:"Quote",action:({editor:o,event:e})=>{me(o.textarea),o.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},viewMode:{name:"viewMode",icon:Be,title:"View mode"}},G=[k.bold,k.italic,k.code,k.separator,k.link,k.separator,k.h1,k.h2,k.h3,k.separator,k.bulletList,k.orderedList,k.taskList,k.separator,k.quote,k.separator,k.viewMode];var w=class w{constructor(e,t={}){let n;if(typeof e=="string"){if(n=document.querySelectorAll(e),n.length===0)throw new Error(`No elements found for selector: ${e}`);n=Array.from(n)}else if(e instanceof Element)n=[e];else if(e instanceof NodeList)n=Array.from(e);else if(Array.isArray(e))n=e;else throw new Error("Invalid target: must be selector string, Element, NodeList, or Array");return n.map(r=>{if(r.overTypeInstance)return r.overTypeInstance.reinit(t),r.overTypeInstance;let s=Object.create(w.prototype);return s._init(r,t),r.overTypeInstance=s,w.instances.set(r,s),s})}_init(e,t={}){this.element=e,this.instanceTheme=t.theme||null,this.options=this._mergeOptions(t),this.instanceId=++w.instanceCount,this.initialized=!1,w.injectStyles(),w.initGlobalListeners();let n=e.querySelector(".overtype-container"),i=e.querySelector(".overtype-wrapper");n||i?this._recoverFromDOM(n,i):this._buildFromScratch(),this.shortcuts=new O(this),this.linkTooltip=new J(this),requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.textarea.scrollTop=this.preview.scrollTop,this.textarea.scrollLeft=this.preview.scrollLeft})}),this.initialized=!0,this.options.onChange&&this.options.onChange(this.getValue(),this)}_mergeOptions(e){let t={fontSize:"14px",lineHeight:1.6,fontFamily:'"SF Mono", SFMono-Regular, Menlo, Monaco, "Cascadia Code", Consolas, "Roboto Mono", "Noto Sans Mono", "Droid Sans Mono", "Ubuntu Mono", "DejaVu Sans Mono", "Liberation Mono", "Courier New", Courier, monospace',padding:"16px",mobile:{fontSize:"16px",padding:"12px",lineHeight:1.5},textareaProps:{},autofocus:!1,autoResize:!1,minHeight:"100px",maxHeight:null,placeholder:"Start typing...",value:"",onChange:null,onKeydown:null,showActiveLineRaw:!1,showStats:!1,toolbar:!1,toolbarButtons:null,statsFormatter:null,smartLists:!0,codeHighlighter:null},{theme:n,colors:i,...r}=e;return{...t,...r}}_recoverFromDOM(e,t){if(e&&e.classList.contains("overtype-container"))this.container=e,this.wrapper=e.querySelector(".overtype-wrapper");else if(t){this.wrapper=t,this.container=document.createElement("div"),this.container.className="overtype-container";let n=this.instanceTheme||w.currentTheme||P,i=typeof n=="string"?n:n.name;if(i&&this.container.setAttribute("data-theme",i),this.instanceTheme){let r=typeof this.instanceTheme=="string"?B(this.instanceTheme):this.instanceTheme;if(r&&r.colors){let s=N(r.colors);this.container.style.cssText+=s}}t.parentNode.insertBefore(this.container,t),this.container.appendChild(t)}if(!this.wrapper){e&&e.remove(),t&&t.remove(),this._buildFromScratch();return}if(this.textarea=this.wrapper.querySelector(".overtype-input"),this.preview=this.wrapper.querySelector(".overtype-preview"),!this.textarea||!this.preview){this.container.remove(),this._buildFromScratch();return}this.wrapper._instance=this,this.options.fontSize&&this.wrapper.style.setProperty("--instance-font-size",this.options.fontSize),this.options.lineHeight&&this.wrapper.style.setProperty("--instance-line-height",String(this.options.lineHeight)),this.options.padding&&this.wrapper.style.setProperty("--instance-padding",this.options.padding),this._configureTextarea(),this._applyOptions()}_buildFromScratch(){let e=this._extractContent();this.element.innerHTML="",this._createDOM(),(e||this.options.value)&&this.setValue(e||this.options.value),this._applyOptions()}_extractContent(){let e=this.element.querySelector(".overtype-input");return e?e.value:this.element.textContent||""}_createDOM(){this.container=document.createElement("div"),this.container.className="overtype-container";let e=this.instanceTheme||w.currentTheme||P,t=typeof e=="string"?e:e.name;if(t&&this.container.setAttribute("data-theme",t),this.instanceTheme){let n=typeof this.instanceTheme=="string"?B(this.instanceTheme):this.instanceTheme;if(n&&n.colors){let i=N(n.colors);this.container.style.cssText+=i}}this.wrapper=document.createElement("div"),this.wrapper.className="overtype-wrapper",this.options.fontSize&&this.wrapper.style.setProperty("--instance-font-size",this.options.fontSize),this.options.lineHeight&&this.wrapper.style.setProperty("--instance-line-height",String(this.options.lineHeight)),this.options.padding&&this.wrapper.style.setProperty("--instance-padding",this.options.padding),this.wrapper._instance=this,this.textarea=document.createElement("textarea"),this.textarea.className="overtype-input",this.textarea.placeholder=this.options.placeholder,this._configureTextarea(),this.options.textareaProps&&Object.entries(this.options.textareaProps).forEach(([n,i])=>{n==="className"||n==="class"?this.textarea.className+=" "+i:n==="style"&&typeof i=="object"?Object.assign(this.textarea.style,i):this.textarea.setAttribute(n,i)}),this.preview=document.createElement("div"),this.preview.className="overtype-preview",this.preview.setAttribute("aria-hidden","true"),this.wrapper.appendChild(this.textarea),this.wrapper.appendChild(this.preview),this.container.appendChild(this.wrapper),this.options.showStats&&(this.statsBar=document.createElement("div"),this.statsBar.className="overtype-stats",this.container.appendChild(this.statsBar),this._updateStats()),this.element.appendChild(this.container),this.options.autoResize?this._setupAutoResize():this.container.classList.remove("overtype-auto-resize")}_configureTextarea(){this.textarea.setAttribute("autocomplete","off"),this.textarea.setAttribute("autocorrect","off"),this.textarea.setAttribute("autocapitalize","off"),this.textarea.setAttribute("spellcheck","false"),this.textarea.setAttribute("data-gramm","false"),this.textarea.setAttribute("data-gramm_editor","false"),this.textarea.setAttribute("data-enable-grammarly","false")}_createToolbar(){let e=this.options.toolbarButtons||G;this.toolbar=new Z(this,{toolbarButtons:e}),this.toolbar.create(),this._toolbarSelectionListener=()=>{this.toolbar&&this.toolbar.updateButtonStates()},this._toolbarInputListener=()=>{this.toolbar&&this.toolbar.updateButtonStates()},this.textarea.addEventListener("selectionchange",this._toolbarSelectionListener),this.textarea.addEventListener("input",this._toolbarInputListener)}_cleanupToolbarListeners(){this._toolbarSelectionListener&&(this.textarea.removeEventListener("selectionchange",this._toolbarSelectionListener),this._toolbarSelectionListener=null),this._toolbarInputListener&&(this.textarea.removeEventListener("input",this._toolbarInputListener),this._toolbarInputListener=null)}_applyOptions(){this.options.autofocus&&this.textarea.focus(),this.options.autoResize?this.container.classList.contains("overtype-auto-resize")||this._setupAutoResize():this.container.classList.remove("overtype-auto-resize"),this.options.toolbar&&!this.toolbar?this._createToolbar():!this.options.toolbar&&this.toolbar&&(this._cleanupToolbarListeners(),this.toolbar.destroy(),this.toolbar=null),this.updatePreview()}updatePreview(){let e=this.textarea.value,t=this.textarea.selectionStart,n=this._getCurrentLine(e,t),i=this.container.dataset.mode==="preview",r=S.parse(e,n,this.options.showActiveLineRaw,this.options.codeHighlighter,i);this.preview.innerHTML=r||'<span style="color: #808080;">Start typing...</span>',this._applyCodeBlockBackgrounds(),this.options.showStats&&this.statsBar&&this._updateStats(),this.options.onChange&&this.initialized&&this.options.onChange(e,this)}_applyCodeBlockBackgrounds(){let e=this.preview.querySelectorAll(".code-fence");for(let t=0;t<e.length-1;t+=2){let n=e[t],i=e[t+1],r=n.parentElement,s=i.parentElement;!r||!s||(n.style.display="block",i.style.display="block",r.classList.add("code-block-line"),s.classList.add("code-block-line"))}}_getCurrentLine(e,t){return e.substring(0,t).split(`
|
|
943
|
-
`).length
|
|
944
|
-
`).
|
|
945
|
-
`)
|
|
946
|
-
`).
|
|
947
|
-
`)
|
|
948
|
-
|
|
949
|
-
`+
|
|
950
|
-
|
|
951
|
-
`),
|
|
952
|
-
`),n=
|
|
953
|
-
`),
|
|
954
|
+
</svg>`;var S={bold:{name:"bold",actionId:"toggleBold",icon:Kt,title:"Bold (Ctrl+B)",action:({editor:t})=>{rt(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},italic:{name:"italic",actionId:"toggleItalic",icon:Zt,title:"Italic (Ctrl+I)",action:({editor:t})=>{st(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},code:{name:"code",actionId:"toggleCode",icon:Yt,title:"Inline Code",action:({editor:t})=>{at(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},separator:{name:"separator"},link:{name:"link",actionId:"insertLink",icon:Xt,title:"Insert Link",action:({editor:t})=>{lt(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h1:{name:"h1",actionId:"toggleH1",icon:Qt,title:"Heading 1",action:({editor:t})=>{ut(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h2:{name:"h2",actionId:"toggleH2",icon:Gt,title:"Heading 2",action:({editor:t})=>{ht(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h3:{name:"h3",actionId:"toggleH3",icon:Jt,title:"Heading 3",action:({editor:t})=>{ft(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},bulletList:{name:"bulletList",actionId:"toggleBulletList",icon:en,title:"Bullet List",action:({editor:t})=>{ct(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},orderedList:{name:"orderedList",actionId:"toggleNumberedList",icon:tn,title:"Numbered List",action:({editor:t})=>{pt(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},taskList:{name:"taskList",actionId:"toggleTaskList",icon:on,title:"Task List",action:({editor:t})=>{Ie&&(Ie(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0})))}},quote:{name:"quote",actionId:"toggleQuote",icon:nn,title:"Quote",action:({editor:t})=>{dt(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},upload:{name:"upload",actionId:"uploadFile",icon:rn,title:"Upload File",action:({editor:t})=>{var n,o;if(!((n=t.options.fileUpload)!=null&&n.enabled))return;let e=document.createElement("input");e.type="file",e.multiple=!0,((o=t.options.fileUpload.mimeTypes)==null?void 0:o.length)>0&&(e.accept=t.options.fileUpload.mimeTypes.join(",")),e.onchange=()=>{var r;if(!((r=e.files)!=null&&r.length))return;let i=new DataTransfer;for(let s of e.files)i.items.add(s);t._handleDataTransfer(i)},e.click()}},viewMode:{name:"viewMode",icon:sn,title:"View mode"}},oe=[S.bold,S.italic,S.code,S.separator,S.link,S.separator,S.h1,S.h2,S.h3,S.separator,S.bulletList,S.orderedList,S.taskList,S.separator,S.quote,S.separator,S.viewMode];function ze(t){let e={};return(t||[]).forEach(n=>{if(!n||n.name==="separator")return;let o=n.actionId||n.name;n.action&&(e[o]=n.action)}),e}function an(t){let e=t||oe;return Array.isArray(e)?e.map(n=>({name:(n==null?void 0:n.name)||null,actionId:(n==null?void 0:n.actionId)||(n==null?void 0:n.name)||null,icon:(n==null?void 0:n.icon)||null,title:(n==null?void 0:n.title)||null})):null}function ro(t,e){let n=an(t),o=an(e);if(n===null||o===null)return n!==o;if(n.length!==o.length)return!0;for(let i=0;i<n.length;i++){let r=n[i],s=o[i];if(r.name!==s.name||r.actionId!==s.actionId||r.icon!==s.icon||r.title!==s.title)return!0}return!1}var v=class v{constructor(e,n={}){let o;if(typeof e=="string"){if(o=document.querySelectorAll(e),o.length===0)throw new Error(`No elements found for selector: ${e}`);o=Array.from(o)}else if(e instanceof Element)o=[e];else if(e instanceof NodeList)o=Array.from(e);else if(Array.isArray(e))o=e;else throw new Error("Invalid target: must be selector string, Element, NodeList, or Array");return o.map(r=>{if(r.overTypeInstance)return r.overTypeInstance.reinit(n),r.overTypeInstance;let s=Object.create(v.prototype);return s._init(r,n),r.overTypeInstance=s,v.instances.set(r,s),s})}_init(e,n={}){this.element=e,this.instanceTheme=n.theme||null,this.options=this._mergeOptions(n),this.instanceId=++v.instanceCount,this.initialized=!1,v.injectStyles(),v.initGlobalListeners();let o=e.querySelector(".overtype-container"),i=e.querySelector(".overtype-wrapper");o||i?this._recoverFromDOM(o,i):this._buildFromScratch(),this.instanceTheme==="auto"&&this.setTheme("auto"),this.shortcuts=new re(this),this._rebuildActionsMap(),this.linkTooltip=new He(this),requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.textarea.scrollTop=this.preview.scrollTop,this.textarea.scrollLeft=this.preview.scrollLeft})}),this.initialized=!0,this.options.onChange&&this.options.onChange(this.getValue(),this)}_mergeOptions(e){let n={fontSize:"14px",lineHeight:1.6,fontFamily:'"SF Mono", SFMono-Regular, Menlo, Monaco, "Cascadia Code", Consolas, "Roboto Mono", "Noto Sans Mono", "Droid Sans Mono", "Ubuntu Mono", "DejaVu Sans Mono", "Liberation Mono", "Courier New", Courier, monospace',padding:"16px",mobile:{fontSize:"16px",padding:"12px",lineHeight:1.5},textareaProps:{},autofocus:!1,autoResize:!1,minHeight:"100px",maxHeight:null,placeholder:"Start typing...",value:"",onChange:null,onKeydown:null,showActiveLineRaw:!1,showStats:!1,toolbar:!1,toolbarButtons:null,statsFormatter:null,smartLists:!0,codeHighlighter:null,spellcheck:!1},{theme:o,colors:i,...r}=e;return{...n,...r}}_recoverFromDOM(e,n){if(e&&e.classList.contains("overtype-container"))this.container=e,this.wrapper=e.querySelector(".overtype-wrapper");else if(n){this.wrapper=n,this.container=document.createElement("div"),this.container.className="overtype-container";let o=this.instanceTheme||v.currentTheme||B,i=typeof o=="string"?o:o.name;if(i&&this.container.setAttribute("data-theme",i),this.instanceTheme){let r=typeof this.instanceTheme=="string"?V(this.instanceTheme):this.instanceTheme;if(r&&r.colors){let s=Q(r.colors);this.container.style.cssText+=s}}n.parentNode.insertBefore(this.container,n),this.container.appendChild(n)}if(!this.wrapper){e&&e.remove(),n&&n.remove(),this._buildFromScratch();return}if(this.textarea=this.wrapper.querySelector(".overtype-input"),this.preview=this.wrapper.querySelector(".overtype-preview"),!this.textarea||!this.preview){this.container.remove(),this._buildFromScratch();return}this.wrapper._instance=this,this.options.fontSize&&this.wrapper.style.setProperty("--instance-font-size",this.options.fontSize),this.options.lineHeight&&this.wrapper.style.setProperty("--instance-line-height",String(this.options.lineHeight)),this.options.padding&&this.wrapper.style.setProperty("--instance-padding",this.options.padding),this._configureTextarea(),this._applyOptions()}_buildFromScratch(){let e=this._extractContent();this.element.innerHTML="",this._createDOM(),(e||this.options.value)&&this.setValue(e||this.options.value),this._applyOptions()}_extractContent(){let e=this.element.querySelector(".overtype-input");return e?e.value:this.element.textContent||""}_createDOM(){this.container=document.createElement("div"),this.container.className="overtype-container";let e=this.instanceTheme||v.currentTheme||B,n=typeof e=="string"?e:e.name;if(n&&this.container.setAttribute("data-theme",n),this.instanceTheme){let o=typeof this.instanceTheme=="string"?V(this.instanceTheme):this.instanceTheme;if(o&&o.colors){let i=Q(o.colors);this.container.style.cssText+=i}}this.wrapper=document.createElement("div"),this.wrapper.className="overtype-wrapper",this.options.fontSize&&this.wrapper.style.setProperty("--instance-font-size",this.options.fontSize),this.options.lineHeight&&this.wrapper.style.setProperty("--instance-line-height",String(this.options.lineHeight)),this.options.padding&&this.wrapper.style.setProperty("--instance-padding",this.options.padding),this.wrapper._instance=this,this.textarea=document.createElement("textarea"),this.textarea.className="overtype-input",this.textarea.placeholder=this.options.placeholder,this._configureTextarea(),this.options.textareaProps&&Object.entries(this.options.textareaProps).forEach(([o,i])=>{o==="className"||o==="class"?this.textarea.className+=" "+i:o==="style"&&typeof i=="object"?Object.assign(this.textarea.style,i):this.textarea.setAttribute(o,i)}),this.preview=document.createElement("div"),this.preview.className="overtype-preview",this.preview.setAttribute("aria-hidden","true"),this.placeholderEl=document.createElement("div"),this.placeholderEl.className="overtype-placeholder",this.placeholderEl.setAttribute("aria-hidden","true"),this.placeholderEl.textContent=this.options.placeholder,this.wrapper.appendChild(this.textarea),this.wrapper.appendChild(this.preview),this.wrapper.appendChild(this.placeholderEl),this.container.appendChild(this.wrapper),this.options.showStats&&(this.statsBar=document.createElement("div"),this.statsBar.className="overtype-stats",this.container.appendChild(this.statsBar),this._updateStats()),this.element.appendChild(this.container),this.options.autoResize?this._setupAutoResize():this.container.classList.remove("overtype-auto-resize")}_configureTextarea(){this.textarea.setAttribute("autocomplete","off"),this.textarea.setAttribute("autocorrect","off"),this.textarea.setAttribute("autocapitalize","off"),this.textarea.setAttribute("spellcheck",String(this.options.spellcheck)),this.textarea.setAttribute("data-gramm","false"),this.textarea.setAttribute("data-gramm_editor","false"),this.textarea.setAttribute("data-enable-grammarly","false")}_createToolbar(){var n;let e=this.options.toolbarButtons||oe;if((n=this.options.fileUpload)!=null&&n.enabled&&!e.some(o=>(o==null?void 0:o.name)==="upload")){let o=e.findIndex(i=>(i==null?void 0:i.name)==="viewMode");o!==-1?(e=[...e],e.splice(o,0,S.separator,S.upload)):e=[...e,S.separator,S.upload]}this.toolbar=new ke(this,{toolbarButtons:e}),this.toolbar.create(),this._toolbarSelectionListener=()=>{this.toolbar&&this.toolbar.updateButtonStates()},this._toolbarInputListener=()=>{this.toolbar&&this.toolbar.updateButtonStates()},this.textarea.addEventListener("selectionchange",this._toolbarSelectionListener),this.textarea.addEventListener("input",this._toolbarInputListener)}_cleanupToolbarListeners(){this._toolbarSelectionListener&&(this.textarea.removeEventListener("selectionchange",this._toolbarSelectionListener),this._toolbarSelectionListener=null),this._toolbarInputListener&&(this.textarea.removeEventListener("input",this._toolbarInputListener),this._toolbarInputListener=null)}_rebuildActionsMap(){var e;this.actionsById=ze(oe),this.options.toolbarButtons&&Object.assign(this.actionsById,ze(this.options.toolbarButtons)),(e=this.options.fileUpload)!=null&&e.enabled&&Object.assign(this.actionsById,ze([S.upload]))}_applyOptions(){this.options.autofocus&&this.textarea.focus(),this.options.autoResize?this.container.classList.contains("overtype-auto-resize")?this._updateAutoHeight():this._setupAutoResize():this.container.classList.remove("overtype-auto-resize"),this.options.toolbar&&!this.toolbar?this._createToolbar():!this.options.toolbar&&this.toolbar&&(this._cleanupToolbarListeners(),this.toolbar.destroy(),this.toolbar=null),this.placeholderEl&&(this.placeholderEl.textContent=this.options.placeholder),this.options.fileUpload&&!this.fileUploadInitialized?this._initFileUpload():!this.options.fileUpload&&this.fileUploadInitialized&&this._destroyFileUpload(),this.updatePreview()}_initFileUpload(){let e=this.options.fileUpload;if(!(!e||!e.enabled)){if(e.maxSize=e.maxSize||10*1024*1024,e.mimeTypes=e.mimeTypes||[],e.batch=e.batch||!1,!e.onInsertFile||typeof e.onInsertFile!="function"){console.warn("OverType: fileUpload.onInsertFile callback is required for file uploads.");return}this._fileUploadCounter=0,this._boundHandleFilePaste=this._handleFilePaste.bind(this),this._boundHandleFileDrop=this._handleFileDrop.bind(this),this._boundHandleDragOver=this._handleDragOver.bind(this),this.textarea.addEventListener("paste",this._boundHandleFilePaste),this.textarea.addEventListener("drop",this._boundHandleFileDrop),this.textarea.addEventListener("dragover",this._boundHandleDragOver),this.fileUploadInitialized=!0}}_handleFilePaste(e){var n,o;(o=(n=e==null?void 0:e.clipboardData)==null?void 0:n.files)!=null&&o.length&&(e.preventDefault(),this._handleDataTransfer(e.clipboardData))}_handleFileDrop(e){var n,o;(o=(n=e==null?void 0:e.dataTransfer)==null?void 0:n.files)!=null&&o.length&&(e.preventDefault(),this._handleDataTransfer(e.dataTransfer))}_handleDataTransfer(e){let n=[];for(let o of e.files){if(o.size>this.options.fileUpload.maxSize||this.options.fileUpload.mimeTypes.length>0&&!this.options.fileUpload.mimeTypes.includes(o.type))continue;let i=++this._fileUploadCounter,s=`${o.type.startsWith("image/")?"!":""}[Uploading ${o.name} (#${i})...]()`;if(this.insertAtCursor(`${s}
|
|
955
|
+
`),this.options.fileUpload.batch){n.push({file:o,placeholder:s});continue}this.options.fileUpload.onInsertFile(o).then(a=>{this.textarea.value=this.textarea.value.replace(s,a),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))},a=>{console.error("OverType: File upload failed",a),this.textarea.value=this.textarea.value.replace(s,"[Upload failed]()"),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))})}this.options.fileUpload.batch&&n.length>0&&this.options.fileUpload.onInsertFile(n.map(o=>o.file)).then(o=>{(Array.isArray(o)?o:[o]).forEach((r,s)=>{this.textarea.value=this.textarea.value.replace(n[s].placeholder,r)}),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))},o=>{console.error("OverType: File upload failed",o),n.forEach(({placeholder:i})=>{this.textarea.value=this.textarea.value.replace(i,"[Upload failed]()")}),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))})}_handleDragOver(e){e.preventDefault()}_destroyFileUpload(){this.textarea.removeEventListener("paste",this._boundHandleFilePaste),this.textarea.removeEventListener("drop",this._boundHandleFileDrop),this.textarea.removeEventListener("dragover",this._boundHandleDragOver),this._boundHandleFilePaste=null,this._boundHandleFileDrop=null,this._boundHandleDragOver=null,this.fileUploadInitialized=!1}insertAtCursor(e){let n=this.textarea.selectionStart,o=this.textarea.selectionEnd,i=!1;try{i=document.execCommand("insertText",!1,e)}catch(r){}if(!i){let r=this.textarea.value.slice(0,n),s=this.textarea.value.slice(o);this.textarea.value=r+e+s,this.textarea.setSelectionRange(n+e.length,n+e.length)}this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}updatePreview(){let e=this.textarea.value,n=this.textarea.selectionStart,o=this._getCurrentLine(e,n),i=this.container.dataset.mode==="preview",r=T.parse(e,o,this.options.showActiveLineRaw,this.options.codeHighlighter,i);this.preview.innerHTML=r,this.placeholderEl&&(this.placeholderEl.style.display=e?"none":""),this._applyCodeBlockBackgrounds(),this.options.showStats&&this.statsBar&&this._updateStats(),this.options.onChange&&this.initialized&&this.options.onChange(e,this)}_applyCodeBlockBackgrounds(){let e=this.preview.querySelectorAll(".code-fence");for(let n=0;n<e.length-1;n+=2){let o=e[n],i=e[n+1],r=o.parentElement,s=i.parentElement;!r||!s||(o.style.display="block",i.style.display="block",r.classList.add("code-block-line"),s.classList.add("code-block-line"))}}_getCurrentLine(e,n){return e.substring(0,n).split(`
|
|
956
|
+
`).length-1}handleInput(e){this.updatePreview()}handleKeydown(e){if(e.key==="Tab"){let o=this.textarea.selectionStart,i=this.textarea.selectionEnd,r=this.textarea.value;if(e.shiftKey&&o===i)return;if(e.preventDefault(),o!==i&&e.shiftKey){let s=r.substring(0,o),a=r.substring(o,i),c=r.substring(i),l=a.split(`
|
|
957
|
+
`).map(p=>p.replace(/^ /,"")).join(`
|
|
958
|
+
`);document.execCommand?(this.textarea.setSelectionRange(o,i),document.execCommand("insertText",!1,l)):(this.textarea.value=s+l+c,this.textarea.selectionStart=o,this.textarea.selectionEnd=o+l.length)}else if(o!==i){let s=r.substring(0,o),a=r.substring(o,i),c=r.substring(i),l=a.split(`
|
|
959
|
+
`).map(p=>" "+p).join(`
|
|
960
|
+
`);document.execCommand?(this.textarea.setSelectionRange(o,i),document.execCommand("insertText",!1,l)):(this.textarea.value=s+l+c,this.textarea.selectionStart=o,this.textarea.selectionEnd=o+l.length)}else document.execCommand?document.execCommand("insertText",!1," "):(this.textarea.value=r.substring(0,o)+" "+r.substring(i),this.textarea.selectionStart=this.textarea.selectionEnd=o+2);this.textarea.dispatchEvent(new Event("input",{bubbles:!0}));return}if(e.key==="Enter"&&!e.shiftKey&&!e.metaKey&&!e.ctrlKey&&this.options.smartLists&&this.handleSmartListContinuation()){e.preventDefault();return}!this.shortcuts.handleKeydown(e)&&this.options.onKeydown&&this.options.onKeydown(e,this)}handleSmartListContinuation(){let e=this.textarea,n=e.selectionStart,o=T.getListContext(e.value,n);return!o||!o.inList?!1:o.content.trim()===""&&n>=o.markerEndPos?(this.deleteListMarker(o),!0):(n>o.markerEndPos&&n<o.lineEnd?this.splitListItem(o,n):this.insertNewListItem(o),o.listType==="numbered"&&this.scheduleNumberedListUpdate(),!0)}deleteListMarker(e){this.textarea.setSelectionRange(e.lineStart,e.markerEndPos),document.execCommand("delete"),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}insertNewListItem(e){let n=T.createNewListItem(e);document.execCommand("insertText",!1,`
|
|
961
|
+
`+n),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}splitListItem(e,n){let o=e.content.substring(n-e.markerEndPos);this.textarea.setSelectionRange(n,e.lineEnd),document.execCommand("delete");let i=T.createNewListItem(e);document.execCommand("insertText",!1,`
|
|
962
|
+
`+i+o);let r=this.textarea.selectionStart-o.length;this.textarea.setSelectionRange(r,r),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}scheduleNumberedListUpdate(){this.numberUpdateTimeout&&clearTimeout(this.numberUpdateTimeout),this.numberUpdateTimeout=setTimeout(()=>{this.updateNumberedLists()},10)}updateNumberedLists(){let e=this.textarea.value,n=this.textarea.selectionStart,o=T.renumberLists(e);if(o!==e){let i=0,r=e.split(`
|
|
963
|
+
`),s=o.split(`
|
|
964
|
+
`),a=0;for(let d=0;d<r.length&&a<n;d++){if(r[d]!==s[d]){let l=s[d].length-r[d].length;a+r[d].length<n&&(i+=l)}a+=r[d].length+1}this.textarea.value=o;let c=n+i;this.textarea.setSelectionRange(c,c),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}}handleScroll(e){this.preview.scrollTop=this.textarea.scrollTop,this.preview.scrollLeft=this.textarea.scrollLeft}getValue(){return this.textarea.value}setValue(e){this.textarea.value=e,this.updatePreview(),this.options.autoResize&&this._updateAutoHeight()}async performAction(e,n=null){var r;let o=this.textarea;if(!o)return!1;let i=(r=this.actionsById)==null?void 0:r[e];if(!i)return console.warn(`OverType: Unknown action "${e}"`),!1;o.focus();try{return await i({editor:this,getValue:()=>this.getValue(),setValue:s=>this.setValue(s),event:n}),!0}catch(s){return console.error(`OverType: Action "${e}" error:`,s),this.wrapper.dispatchEvent(new CustomEvent("button-error",{detail:{actionId:e,error:s}})),!1}}getRenderedHTML(e={}){let n=this.getValue(),o=T.parse(n,-1,!1,this.options.codeHighlighter);return e.cleanHTML&&(o=o.replace(/<span class="syntax-marker[^"]*">.*?<\/span>/g,""),o=o.replace(/\sclass="(bullet-list|ordered-list|code-fence|hr-marker|blockquote|url-part)"/g,""),o=o.replace(/\sclass=""/g,"")),o}getPreviewHTML(){return this.preview.innerHTML}getCleanHTML(){return this.getRenderedHTML({cleanHTML:!0})}focus(){this.textarea.focus()}blur(){this.textarea.blur()}isInitialized(){return this.initialized}reinit(e={}){var i;let n=(i=this.options)==null?void 0:i.toolbarButtons;this.options=this._mergeOptions({...this.options,...e});let o=this.toolbar&&this.options.toolbar&&ro(n,this.options.toolbarButtons);this._rebuildActionsMap(),o&&(this._cleanupToolbarListeners(),this.toolbar.destroy(),this.toolbar=null,this._createToolbar()),this.fileUploadInitialized&&this._destroyFileUpload(),this.options.fileUpload&&this._initFileUpload(),this._applyOptions(),this.updatePreview()}showToolbar(){this.toolbar?this.toolbar.show():this._createToolbar()}hideToolbar(){this.toolbar&&this.toolbar.hide()}setTheme(e){if(v._autoInstances.delete(this),this.instanceTheme=e,e==="auto")v._autoInstances.add(this),v._startAutoListener(),this._applyResolvedTheme(Pe("auto"));else{let n=typeof e=="string"?V(e):e,o=typeof n=="string"?n:n.name;if(o&&this.container.setAttribute("data-theme",o),n&&n.colors){let i=Q(n.colors);this.container.style.cssText+=i}this.updatePreview()}return v._stopAutoListener(),this}_applyResolvedTheme(e){let n=V(e);this.container.setAttribute("data-theme",e),n&&n.colors&&(this.container.style.cssText=Q(n.colors)),this.updatePreview()}setCodeHighlighter(e){this.options.codeHighlighter=e,this.updatePreview()}_updateStats(){if(!this.statsBar)return;let e=this.textarea.value,n=e.split(`
|
|
965
|
+
`),o=e.length,i=e.split(/\s+/).filter(l=>l.length>0).length,r=this.textarea.selectionStart,a=e.substring(0,r).split(`
|
|
966
|
+
`),c=a.length,d=a[a.length-1].length+1;this.options.statsFormatter?this.statsBar.innerHTML=this.options.statsFormatter({chars:o,words:i,lines:n.length,line:c,column:d}):this.statsBar.innerHTML=`
|
|
954
967
|
<div class="overtype-stat">
|
|
955
968
|
<span class="live-dot"></span>
|
|
956
|
-
<span>${
|
|
969
|
+
<span>${o} chars, ${i} words, ${n.length} lines</span>
|
|
957
970
|
</div>
|
|
958
|
-
<div class="overtype-stat">Line ${
|
|
959
|
-
`}_setupAutoResize(){this.container.classList.add("overtype-auto-resize"),this.previousHeight=null,this._updateAutoHeight(),this.textarea.addEventListener("input",()=>this._updateAutoHeight()),window.addEventListener("resize",()=>this._updateAutoHeight())}_updateAutoHeight(){if(!this.options.autoResize)return;let e=this.textarea,
|
|
971
|
+
<div class="overtype-stat">Line ${c}, Col ${d}</div>
|
|
972
|
+
`}_setupAutoResize(){this.container.classList.add("overtype-auto-resize"),this.previousHeight=null,this._updateAutoHeight(),this.textarea.addEventListener("input",()=>this._updateAutoHeight()),window.addEventListener("resize",()=>this._updateAutoHeight())}_updateAutoHeight(){if(!this.options.autoResize)return;let e=this.textarea,n=this.preview,o=this.wrapper,i=window.getComputedStyle(e),r=parseFloat(i.paddingTop),s=parseFloat(i.paddingBottom),a=e.scrollTop;e.style.setProperty("height","auto","important");let c=e.scrollHeight;if(this.options.minHeight){let p=parseInt(this.options.minHeight);c=Math.max(c,p)}let d="hidden";if(this.options.maxHeight){let p=parseInt(this.options.maxHeight);c>p&&(c=p,d="auto")}let l=c+"px";e.style.setProperty("height",l,"important"),e.style.setProperty("overflow-y",d,"important"),n.style.setProperty("height",l,"important"),n.style.setProperty("overflow-y",d,"important"),o.style.setProperty("height",l,"important"),e.scrollTop=a,n.scrollTop=a,this.previousHeight!==c&&(this.previousHeight=c)}showStats(e){this.options.showStats=e,e&&!this.statsBar?(this.statsBar=document.createElement("div"),this.statsBar.className="overtype-stats",this.container.appendChild(this.statsBar),this._updateStats()):e&&this.statsBar?this._updateStats():!e&&this.statsBar&&(this.statsBar.remove(),this.statsBar=null)}showNormalEditMode(){return this.container.dataset.mode="normal",this.updatePreview(),requestAnimationFrame(()=>{this.textarea.scrollTop=this.preview.scrollTop,this.textarea.scrollLeft=this.preview.scrollLeft}),this}showPlainTextarea(){if(this.container.dataset.mode="plain",this.toolbar){let e=this.container.querySelector('[data-action="toggle-plain"]');e&&(e.classList.remove("active"),e.title="Show markdown preview")}return this}showPreviewMode(){return this.container.dataset.mode="preview",this.updatePreview(),this}destroy(){if(v._autoInstances.delete(this),v._stopAutoListener(),this.fileUploadInitialized&&this._destroyFileUpload(),this.element.overTypeInstance=null,v.instances.delete(this.element),this.shortcuts&&this.shortcuts.destroy(),this.wrapper){let e=this.getValue();this.wrapper.remove(),this.element.textContent=e}this.initialized=!1}static init(e,n={}){return new v(e,n)}static initFromData(e,n={}){let o=document.querySelectorAll(e);return Array.from(o).map(i=>{let r={...n};for(let s of i.attributes)if(s.name.startsWith("data-ot-")){let c=s.name.slice(8).replace(/-([a-z])/g,(d,l)=>l.toUpperCase());r[c]=v._parseDataValue(s.value)}return new v(i,r)[0]})}static _parseDataValue(e){return e==="true"?!0:e==="false"?!1:e==="null"?null:e!==""&&!isNaN(Number(e))?Number(e):e}static getInstance(e){return e.overTypeInstance||v.instances.get(e)||null}static destroyAll(){document.querySelectorAll("[data-overtype-instance]").forEach(n=>{let o=v.getInstance(n);o&&o.destroy()})}static injectStyles(e=!1){if(v.stylesInjected&&!e)return;let n=document.querySelector("style.overtype-styles");n&&n.remove();let o=v.currentTheme||B,i=Ze({theme:o}),r=document.createElement("style");r.className="overtype-styles",r.textContent=i,document.head.appendChild(r),v.stylesInjected=!0}static setTheme(e,n=null){if(v._globalAutoTheme=!1,v._globalAutoCustomColors=null,e==="auto"){v._globalAutoTheme=!0,v._globalAutoCustomColors=n,v._startAutoListener(),v._applyGlobalTheme(Pe("auto"),n);return}v._stopAutoListener(),v._applyGlobalTheme(e,n)}static _applyGlobalTheme(e,n=null){let o=typeof e=="string"?V(e):e;n&&(o=Ke(o,n)),v.currentTheme=o,v.injectStyles(!0);let i=typeof o=="string"?o:o.name;document.querySelectorAll(".overtype-container").forEach(r=>{i&&r.setAttribute("data-theme",i)}),document.querySelectorAll(".overtype-wrapper").forEach(r=>{r.closest(".overtype-container")||i&&r.setAttribute("data-theme",i);let s=r._instance;s&&s.updatePreview()}),document.querySelectorAll("overtype-editor").forEach(r=>{i&&typeof r.setAttribute=="function"&&r.setAttribute("theme",i),typeof r.refreshTheme=="function"&&r.refreshTheme()})}static _startAutoListener(){v._autoMediaQuery||window.matchMedia&&(v._autoMediaQuery=window.matchMedia("(prefers-color-scheme: dark)"),v._autoMediaListener=e=>{let n=e.matches?"cave":"solar";v._globalAutoTheme&&v._applyGlobalTheme(n,v._globalAutoCustomColors),v._autoInstances.forEach(o=>o._applyResolvedTheme(n))},v._autoMediaQuery.addEventListener("change",v._autoMediaListener))}static _stopAutoListener(){v._autoInstances.size>0||v._globalAutoTheme||v._autoMediaQuery&&(v._autoMediaQuery.removeEventListener("change",v._autoMediaListener),v._autoMediaQuery=null,v._autoMediaListener=null)}static setCodeHighlighter(e){T.setCodeHighlighter(e),document.querySelectorAll(".overtype-wrapper").forEach(n=>{let o=n._instance;o&&o.updatePreview&&o.updatePreview()}),document.querySelectorAll("overtype-editor").forEach(n=>{if(typeof n.getEditor=="function"){let o=n.getEditor();o&&o.updatePreview&&o.updatePreview()}})}static setCustomSyntax(e){T.setCustomSyntax(e),document.querySelectorAll(".overtype-wrapper").forEach(n=>{let o=n._instance;o&&o.updatePreview&&o.updatePreview()}),document.querySelectorAll("overtype-editor").forEach(n=>{if(typeof n.getEditor=="function"){let o=n.getEditor();o&&o.updatePreview&&o.updatePreview()}})}static initGlobalListeners(){v.globalListenersInitialized||(document.addEventListener("input",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let n=e.target.closest(".overtype-wrapper"),o=n==null?void 0:n._instance;o&&o.handleInput(e)}}),document.addEventListener("keydown",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let n=e.target.closest(".overtype-wrapper"),o=n==null?void 0:n._instance;o&&o.handleKeydown(e)}}),document.addEventListener("scroll",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let n=e.target.closest(".overtype-wrapper"),o=n==null?void 0:n._instance;o&&o.handleScroll(e)}},!0),document.addEventListener("selectionchange",e=>{let n=document.activeElement;if(n&&n.classList.contains("overtype-input")){let o=n.closest(".overtype-wrapper"),i=o==null?void 0:o._instance;i&&(i.options.showStats&&i.statsBar&&i._updateStats(),clearTimeout(i._selectionTimeout),i._selectionTimeout=setTimeout(()=>{i.updatePreview()},50))}}),v.globalListenersInitialized=!0)}};C(v,"instances",new WeakMap),C(v,"stylesInjected",!1),C(v,"globalListenersInitialized",!1),C(v,"instanceCount",0),C(v,"_autoMediaQuery",null),C(v,"_autoMediaListener",null),C(v,"_autoInstances",new Set),C(v,"_globalAutoTheme",!1),C(v,"_globalAutoCustomColors",null);var z=v;z.MarkdownParser=T;z.ShortcutsManager=re;z.themes={solar:B,cave:V("cave")};z.getTheme=V;z.currentTheme=B;var so=z;return mn(ao);})();
|
|
960
973
|
/**
|
|
961
974
|
* OverType - A lightweight markdown editor library with perfect WYSIWYG alignment
|
|
962
975
|
* @version 1.0.0
|