overtype 1.0.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/LICENSE +21 -0
- package/README.md +441 -0
- package/dist/overtype.esm.js +2576 -0
- package/dist/overtype.esm.js.map +7 -0
- package/dist/overtype.js +2599 -0
- package/dist/overtype.js.map +7 -0
- package/dist/overtype.min.js +546 -0
- package/package.json +50 -0
- package/src/icons.js +77 -0
- package/src/index.js +4 -0
- package/src/overtype.js +781 -0
- package/src/parser.js +222 -0
- package/src/shortcuts.js +125 -0
- package/src/styles.js +486 -0
- package/src/themes.js +124 -0
- package/src/toolbar.js +221 -0
|
@@ -0,0 +1,546 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OverType v1.0.0
|
|
3
|
+
* A lightweight markdown editor library with perfect WYSIWYG alignment
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @author Demo User
|
|
6
|
+
* https://github.com/demo/overtype
|
|
7
|
+
*/
|
|
8
|
+
var OverType=(()=>{var j=Object.defineProperty;var He=Object.getOwnPropertyDescriptor;var Me=Object.getOwnPropertyNames;var Oe=Object.prototype.hasOwnProperty;var je=(n,e,t)=>e in n?j(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var Ne=(n,e)=>{for(var t in e)j(n,t,{get:e[t],enumerable:!0})},_e=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Me(e))!Oe.call(n,r)&&r!==t&&j(n,r,{get:()=>e[r],enumerable:!(o=He(e,r))||o.enumerable});return n};var Pe=n=>_e(j({},"__esModule",{value:!0}),n);var I=(n,e,t)=>(je(n,typeof e!="symbol"?e+"":e,t),t);var Xe={};Ne(Xe,{OverType:()=>A,default:()=>Ge});var H=class{static escapeHtml(e){let t={"&":"&","<":"<",">":">",'"':""","'":"'"};return e.replace(/[&<>"']/g,o=>t[o])}static preserveIndentation(e,t){let r=t.match(/^(\s*)/)[1].replace(/ /g," ");return e.replace(/^\s*/,r)}static parseHeader(e){return e.replace(/^(#{1,3})\s(.+)$/,(t,o,r)=>{let i=o.length;return`<span class="header ${["h1","h2","h3"][i-1]}"><span class="syntax-marker">${o}</span> ${r}</span>`})}static parseHorizontalRule(e){return e.match(/^(-{3,}|\*{3,}|_{3,})$/)?`<div><span class="hr-marker">${e}</span></div>`:null}static parseBlockquote(e){return e.replace(/^> (.+)$/,(t,o)=>`<span class="blockquote"><span class="syntax-marker">></span> ${o}</span>`)}static parseBulletList(e){return e.replace(/^((?: )*)([-*])\s(.+)$/,(t,o,r,i)=>`${o}<span class="syntax-marker">${r}</span> ${i}`)}static parseNumberedList(e){return e.replace(/^((?: )*)(\d+\.)\s(.+)$/,(t,o,r,i)=>`${o}<span class="syntax-marker">${r}</span> ${i}`)}static parseCodeBlock(e){return e.startsWith("```")?`<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("(?<!_)_(?!_)(.+?)(?<!_)_(?!_)","g"),'<em><span class="syntax-marker">_</span>$1<span class="syntax-marker">_</span></em>'),e}static parseInlineCode(e){return e.replace(/`(.+?)`/g,'<code><span class="syntax-marker">`</span>$1<span class="syntax-marker">`</span></code>')}static parseLinks(e){return e.replace(/\[(.+?)\]\((.+?)\)/g,'<a href="$2"><span class="syntax-marker">[</span>$1<span class="syntax-marker">](</span><span class="syntax-marker">$2</span><span class="syntax-marker">)</span></a>')}static parseInlineElements(e){let t=e;return t=this.parseInlineCode(t),t=this.parseLinks(t),t=this.parseBold(t),t=this.parseItalic(t),t}static parseLine(e){let t=this.escapeHtml(e);t=this.preserveIndentation(t,e);let o=this.parseHorizontalRule(t);if(o)return o;let r=this.parseCodeBlock(t);return r||(t=this.parseHeader(t),t=this.parseBlockquote(t),t=this.parseBulletList(t),t=this.parseNumberedList(t),t=this.parseInlineElements(t),t.trim()===""?"<div> </div>":`<div>${t}</div>`)}static parse(e,t=-1,o=!1){return e.split(`
|
|
9
|
+
`).map((s,a)=>o&&a===t?`<div class="raw-line">${this.escapeHtml(s)||" "}</div>`:this.parseLine(s)).join("")}};var Fe=Object.defineProperty,G=Object.getOwnPropertySymbols,ze=Object.prototype.hasOwnProperty,Ve=Object.prototype.propertyIsEnumerable,X=(n,e,t)=>e in n?Fe(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,Y=(n,e)=>{for(var t in e||(e={}))ze.call(e,t)&&X(n,t,e[t]);if(G)for(var t of G(e))Ve.call(e,t)&&X(n,t,e[t]);return n},S={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 Re(){return{prefix:"",suffix:"",blockPrefix:"",blockSuffix:"",multiline:!1,replaceNext:"",prefixSpace:!1,scanFor:"",surroundWithNewlines:!1,orderedList:!1,unorderedList:!1,trimFirst:!1}}function E(n){return Y(Y({},Re()),n)}var _=!1;function qe(){return _}function g(n,e,t){_&&(console.group(`\u{1F50D} ${n}`),console.log(e),t&&console.log("Data:",t),console.groupEnd())}function N(n,e){if(!_)return;let t=n.value.slice(n.selectionStart,n.selectionEnd);console.group(`\u{1F4CD} Selection: ${e}`),console.log("Position:",`${n.selectionStart}-${n.selectionEnd}`),console.log("Selected text:",JSON.stringify(t)),console.log("Length:",t.length);let o=n.value.slice(Math.max(0,n.selectionStart-10),n.selectionStart),r=n.value.slice(n.selectionEnd,Math.min(n.value.length,n.selectionEnd+10));console.log("Context:",JSON.stringify(o)+"[SELECTION]"+JSON.stringify(r)),console.groupEnd()}function oe(n){_&&(console.group("\u{1F4DD} Result"),console.log("Text to insert:",JSON.stringify(n.text)),console.log("New selection:",`${n.selectionStart}-${n.selectionEnd}`),console.groupEnd())}var C=null;function B(n,{text:e,selectionStart:t,selectionEnd:o}){let r=qe();r&&(console.group("\u{1F527} insertText"),console.log("Current selection:",`${n.selectionStart}-${n.selectionEnd}`),console.log("Text to insert:",JSON.stringify(e)),console.log("New selection to set:",t,"-",o)),n.focus();let i=n.selectionStart,s=n.selectionEnd,a=n.value.slice(0,i),l=n.value.slice(s);r&&(console.log("Before text (last 20):",JSON.stringify(a.slice(-20))),console.log("After text (first 20):",JSON.stringify(l.slice(0,20))),console.log("Selected text being replaced:",JSON.stringify(n.value.slice(i,s))));let u=n.value,c=i!==s;if(!c&&(C===null||C===!0)){n.contentEditable="true";try{C=document.execCommand("insertText",!1,e)}catch(p){C=!1}n.contentEditable="false"}else c&&(r&&console.log("Has selection, skipping execCommand and using manual mode"),C=!1);if(r&&(console.log("canInsertText before:",C),console.log("execCommand result:",C)),C){let p=a+e+l,f=n.value;r&&(console.log("Expected length:",p.length),console.log("Actual length:",f.length)),f!==p&&r&&(console.log("execCommand changed the value but not as expected"),console.log("Expected:",JSON.stringify(p.slice(0,100))),console.log("Actual:",JSON.stringify(f.slice(0,100))))}if(!C)if(r&&console.log("Using manual insertion"),n.value===u){r&&console.log("Value unchanged, doing manual replacement");try{document.execCommand("ms-beginUndoUnit")}catch(p){}n.value=a+e+l;try{document.execCommand("ms-endUndoUnit")}catch(p){}n.dispatchEvent(new CustomEvent("input",{bubbles:!0,cancelable:!0}))}else r&&console.log("Value was changed by execCommand, skipping manual insertion");r&&console.log("Setting selection range:",t,o),t!=null&&o!=null?n.setSelectionRange(t,o):n.setSelectionRange(i,n.selectionEnd),r&&(console.log("Final value length:",n.value.length),console.groupEnd())}function ee(n){return n.trim().split(`
|
|
10
|
+
`).length>1}function De(n,e){let t=e;for(;n[t]&&n[t-1]!=null&&!n[t-1].match(/\s/);)t--;return t}function We(n,e,t){let o=e,r=t?/\n/:/\s/;for(;n[o]&&!n[o].match(r);)o++;return o}function re(n){let e=n.value.split(`
|
|
11
|
+
`),t=0;for(let o=0;o<e.length;o++){let r=e[o].length+1;n.selectionStart>=t&&n.selectionStart<t+r&&(n.selectionStart=t),n.selectionEnd>=t&&n.selectionEnd<t+r&&(o===e.length-1?n.selectionEnd=Math.min(t+e[o].length,n.value.length):n.selectionEnd=t+r-1),t+=r}}function Ke(n,e,t,o=!1){if(n.selectionStart===n.selectionEnd)n.selectionStart=De(n.value,n.selectionStart),n.selectionEnd=We(n.value,n.selectionEnd,o);else{let r=n.selectionStart-e.length,i=n.selectionEnd+t.length,s=n.value.slice(r,n.selectionStart)===e,a=n.value.slice(n.selectionEnd,i)===t;s&&a&&(n.selectionStart=r,n.selectionEnd=i)}return n.value.slice(n.selectionStart,n.selectionEnd)}function U(n){let e=n.value.slice(0,n.selectionStart),t=n.value.slice(n.selectionEnd),o=e.match(/\n*$/),r=t.match(/^\n*/),i=o?o[0].length:0,s=r?r[0].length:0,a="",l="";return e.match(/\S/)&&i<2&&(a=`
|
|
12
|
+
`.repeat(2-i)),t.match(/\S/)&&s<2&&(l=`
|
|
13
|
+
`.repeat(2-s)),{newlinesToAppend:a,newlinesToPrepend:l}}function P(n,e,t={}){let o=n.selectionStart,r=n.selectionEnd,i=o===r,s=n.value,a=o;for(;a>0&&s[a-1]!==`
|
|
14
|
+
`;)a--;if(i){let u=o;for(;u<s.length&&s[u]!==`
|
|
15
|
+
`;)u++;n.selectionStart=a,n.selectionEnd=u}else re(n);let l=e(n);if(t.adjustSelection){let c=n.value.slice(n.selectionStart,n.selectionEnd).startsWith(t.prefix),p=t.adjustSelection(c,o,r,a);l.selectionStart=p.start,l.selectionEnd=p.end}else if(t.prefix){let c=n.value.slice(n.selectionStart,n.selectionEnd).startsWith(t.prefix);i?c?(l.selectionStart=Math.max(o-t.prefix.length,a),l.selectionEnd=l.selectionStart):(l.selectionStart=o+t.prefix.length,l.selectionEnd=l.selectionStart):c?(l.selectionStart=Math.max(o-t.prefix.length,a),l.selectionEnd=Math.max(r-t.prefix.length,a)):(l.selectionStart=o+t.prefix.length,l.selectionEnd=r+t.prefix.length)}return l}function F(n,e){let t,o,{prefix:r,suffix:i,blockPrefix:s,blockSuffix:a,replaceNext:l,prefixSpace:u,scanFor:c,surroundWithNewlines:p,trimFirst:f}=e,d=n.selectionStart,v=n.selectionEnd,m=n.value.slice(n.selectionStart,n.selectionEnd),h=ee(m)&&s&&s.length>0?`${s}
|
|
16
|
+
`:r,b=ee(m)&&a&&a.length>0?`
|
|
17
|
+
${a}`:i;if(u){let x=n.value[n.selectionStart-1];n.selectionStart!==0&&x!=null&&!x.match(/\s/)&&(h=` ${h}`)}m=Ke(n,h,b,e.multiline);let y=n.selectionStart,w=n.selectionEnd,$=l&&l.length>0&&b.indexOf(l)>-1&&m.length>0;if(p){let x=U(n);t=x.newlinesToAppend,o=x.newlinesToPrepend,h=t+r,b+=o}if(m.startsWith(h)&&m.endsWith(b)){let x=m.slice(h.length,m.length-b.length);if(d===v){let L=d-h.length;L=Math.max(L,y),L=Math.min(L,y+x.length),y=w=L}else w=y+x.length;return{text:x,selectionStart:y,selectionEnd:w}}else if($)if(c&&c.length>0&&m.match(c)){b=b.replace(l,m);let x=h+b;return y=w=y+h.length,{text:x,selectionStart:y,selectionEnd:w}}else{let x=h+m+b;return y=y+h.length+m.length+b.indexOf(l),w=y+l.length,{text:x,selectionStart:y,selectionEnd:w}}else{let x=h+m+b;y=d+h.length,w=v+h.length;let L=m.match(/^\s*|\s*$/g);if(f&&L){let J=L[0]||"",Q=L[1]||"";x=J+h+m.trim()+b+Q,y+=J.length,w-=Q.length}return{text:x,selectionStart:y,selectionEnd:w}}}function ie(n,e){let{prefix:t,suffix:o,surroundWithNewlines:r}=e,i=n.value.slice(n.selectionStart,n.selectionEnd),s=n.selectionStart,a=n.selectionEnd,l=i.split(`
|
|
18
|
+
`);if(l.every(c=>c.startsWith(t)&&(!o||c.endsWith(o))))i=l.map(c=>{let p=c.slice(t.length);return o&&(p=p.slice(0,p.length-o.length)),p}).join(`
|
|
19
|
+
`),a=s+i.length;else if(i=l.map(c=>t+c+(o||"")).join(`
|
|
20
|
+
`),r){let{newlinesToAppend:c,newlinesToPrepend:p}=U(n);s+=c.length,a=s+i.length,i=c+i+p}return{text:i,selectionStart:s,selectionEnd:a}}function te(n){let e=n.split(`
|
|
21
|
+
`),t=/^\d+\.\s+/,o=e.every(i=>t.test(i)),r=e;return o&&(r=e.map(i=>i.replace(t,""))),{text:r.join(`
|
|
22
|
+
`),processed:o}}function ne(n){let e=n.split(`
|
|
23
|
+
`),t="- ",o=e.every(i=>i.startsWith(t)),r=e;return o&&(r=e.map(i=>i.slice(t.length))),{text:r.join(`
|
|
24
|
+
`),processed:o}}function M(n,e){return e?"- ":`${n+1}. `}function Ue(n,e){let t,o,r;return n.orderedList?(t=te(e),o=ne(t.text),r=o.text):(t=ne(e),o=te(t.text),r=o.text),[t,o,r]}function Ze(n,e){let t=n.selectionStart===n.selectionEnd,o=n.selectionStart,r=n.selectionEnd;re(n);let i=n.value.slice(n.selectionStart,n.selectionEnd),[s,a,l]=Ue(e,i),u=l.split(`
|
|
25
|
+
`).map((m,h)=>`${M(h,e.unorderedList)}${m}`),c=u.reduce((m,h,b)=>m+M(b,e.unorderedList).length,0),p=u.reduce((m,h,b)=>m+M(b,!e.unorderedList).length,0);if(s.processed)return t?(o=Math.max(o-M(0,e.unorderedList).length,0),r=o):(o=n.selectionStart,r=n.selectionEnd-c),{text:l,selectionStart:o,selectionEnd:r};let{newlinesToAppend:f,newlinesToPrepend:d}=U(n),v=f+u.join(`
|
|
26
|
+
`)+d;return t?(o=Math.max(o+M(0,e.unorderedList).length+f.length,0),r=o):a.processed?(o=Math.max(n.selectionStart+f.length,0),r=n.selectionEnd+f.length+c-p):(o=Math.max(n.selectionStart+f.length,0),r=n.selectionEnd+f.length+c),{text:v,selectionStart:o,selectionEnd:r}}function se(n,e){let t=P(n,o=>Ze(o,e),{adjustSelection:(o,r,i,s)=>{let a=n.value.slice(s,n.selectionEnd),l=/^\d+\.\s+/,u=/^- /,c=l.test(a),p=u.test(a),f=e.orderedList&&c||e.unorderedList&&p;if(r===i)if(f){let d=a.match(e.orderedList?l:u),v=d?d[0].length:0;return{start:Math.max(r-v,s),end:Math.max(r-v,s)}}else if(c||p){let d=a.match(c?l:u),v=d?d[0].length:0,h=(e.unorderedList?2:3)-v;return{start:r+h,end:r+h}}else{let d=e.unorderedList?2:3;return{start:r+d,end:r+d}}else if(f){let d=a.match(e.orderedList?l:u),v=d?d[0].length:0;return{start:Math.max(r-v,s),end:Math.max(i-v,s)}}else if(c||p){let d=a.match(c?l:u),v=d?d[0].length:0,h=(e.unorderedList?2:3)-v;return{start:r+h,end:i+h}}else{let d=e.unorderedList?2:3;return{start:r+d,end:i+d}}}});B(n,t)}function Je(n){if(!n)return[];let e=[],{selectionStart:t,selectionEnd:o,value:r}=n,i=r.split(`
|
|
27
|
+
`),s=0,a="";for(let p of i){if(t>=s&&t<=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 l=Math.max(0,t-10),u=Math.min(r.length,o+10),c=r.slice(l,u);if(c.includes("**")){let p=r.slice(Math.max(0,t-100),t),f=r.slice(o,Math.min(r.length,o+100)),d=p.lastIndexOf("**"),v=f.indexOf("**");d!==-1&&v!==-1&&e.push("bold")}if(c.includes("_")){let p=r.slice(Math.max(0,t-100),t),f=r.slice(o,Math.min(r.length,o+100)),d=p.lastIndexOf("_"),v=f.indexOf("_");d!==-1&&v!==-1&&e.push("italic")}if(c.includes("`")){let p=r.slice(Math.max(0,t-100),t),f=r.slice(o,Math.min(r.length,o+100));p.includes("`")&&f.includes("`")&&e.push("code")}if(c.includes("[")&&c.includes("]")){let p=r.slice(Math.max(0,t-100),t),f=r.slice(o,Math.min(r.length,o+100)),d=p.lastIndexOf("["),v=f.indexOf("]");d!==-1&&v!==-1&&r.slice(o+v+1,o+v+10).startsWith("(")&&e.push("link")}return e}function z(n){if(!n||n.disabled||n.readOnly)return;g("toggleBold","Starting"),N(n,"Before");let e=E(S.bold),t=F(n,e);oe(t),B(n,t),N(n,"After")}function V(n){if(!n||n.disabled||n.readOnly)return;let e=E(S.italic),t=F(n,e);B(n,t)}function ae(n){if(!n||n.disabled||n.readOnly)return;let e=E(S.code),t=F(n,e);B(n,t)}function R(n,e={}){if(!n||n.disabled||n.readOnly)return;let t=n.value.slice(n.selectionStart,n.selectionEnd),o=E(S.link);if(t&&t.match(/^https?:\/\//)&&!e.url?(o.suffix=`](${t})`,o.replaceNext=""):e.url&&(o.suffix=`](${e.url})`,o.replaceNext=""),e.text&&!t){let s=n.selectionStart;n.value=n.value.slice(0,s)+e.text+n.value.slice(s),n.selectionStart=s,n.selectionEnd=s+e.text.length}let i=F(n,o);B(n,i)}function q(n){if(!n||n.disabled||n.readOnly)return;let e=E(S.bulletList);se(n,e)}function D(n){if(!n||n.disabled||n.readOnly)return;let e=E(S.numberedList);se(n,e)}function le(n){if(!n||n.disabled||n.readOnly)return;g("toggleQuote","Starting"),N(n,"Initial");let e=E(S.quote),t=P(n,o=>ie(o,e),{prefix:e.prefix});oe(t),B(n,t),N(n,"Final")}function ce(n){if(!n||n.disabled||n.readOnly)return;let e=E(S.taskList),t=P(n,o=>ie(o,e),{prefix:e.prefix});B(n,t)}function Z(n,e=1,t=!1){if(!n||n.disabled||n.readOnly)return;(e<1||e>6)&&(e=1),g("insertHeader","============ START ============"),g("insertHeader",`Level: ${e}, Toggle: ${t}`),g("insertHeader",`Initial cursor: ${n.selectionStart}-${n.selectionEnd}`);let o=`header${e===1?"1":e}`,r=E(S[o]||S.header1);g("insertHeader",`Style prefix: "${r.prefix}"`);let i=n.value,s=n.selectionStart,a=n.selectionEnd,l=s;for(;l>0&&i[l-1]!==`
|
|
28
|
+
`;)l--;let u=a;for(;u<i.length&&i[u]!==`
|
|
29
|
+
`;)u++;let c=i.slice(l,u);g("insertHeader",`Current line (before): "${c}"`);let p=c.match(/^(#{1,6})\s*/),f=p?p[1].length:0,d=p?p[0].length:0;g("insertHeader","Existing header check:"),g("insertHeader",` - Match: ${p?`"${p[0]}"`:"none"}`),g("insertHeader",` - Existing level: ${f}`),g("insertHeader",` - Existing prefix length: ${d}`),g("insertHeader",` - Target level: ${e}`);let v=t&&f===e;g("insertHeader",`Should toggle OFF: ${v} (toggle=${t}, existingLevel=${f}, level=${e})`);let m=P(n,h=>{let b=h.value.slice(h.selectionStart,h.selectionEnd);g("insertHeader",`Line in operation: "${b}"`);let y=b.replace(/^#{1,6}\s*/,"");g("insertHeader",`Cleaned line: "${y}"`);let w;return v?(g("insertHeader","ACTION: Toggling OFF - removing header"),w=y):f>0?(g("insertHeader",`ACTION: Replacing H${f} with H${e}`),w=r.prefix+y):(g("insertHeader","ACTION: Adding new header"),w=r.prefix+y),g("insertHeader",`New line: "${w}"`),{text:w,selectionStart:h.selectionStart,selectionEnd:h.selectionEnd}},{prefix:r.prefix,adjustSelection:(h,b,y,w)=>{if(g("insertHeader","Adjusting selection:"),g("insertHeader",` - isRemoving param: ${h}`),g("insertHeader",` - shouldToggleOff: ${v}`),g("insertHeader",` - selStart: ${b}, selEnd: ${y}`),g("insertHeader",` - lineStartPos: ${w}`),v){let $=Math.max(b-d,w);return g("insertHeader",` - Removing header, adjusting by -${d}`),{start:$,end:b===y?$:Math.max(y-d,w)}}else if(d>0){let $=r.prefix.length-d;return g("insertHeader",` - Replacing header, adjusting by ${$}`),{start:b+$,end:y+$}}else return g("insertHeader",` - Adding header, adjusting by +${r.prefix.length}`),{start:b+r.prefix.length,end:y+r.prefix.length}}});g("insertHeader",`Final result: text="${m.text}", cursor=${m.selectionStart}-${m.selectionEnd}`),g("insertHeader","============ END ============"),B(n,m)}function pe(n){Z(n,1,!0)}function de(n){Z(n,2,!0)}function ue(n){Z(n,3,!0)}function he(n){return Je(n)}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 r=null;switch(e.key.toLowerCase()){case"b":e.shiftKey||(r="toggleBold");break;case"i":e.shiftKey||(r="toggleItalic");break;case"k":e.shiftKey||(r="insertLink");break;case"7":e.shiftKey&&(r="toggleNumberedList");break;case"8":e.shiftKey&&(r="toggleBulletList");break}return r?(e.preventDefault(),this.editor.toolbar?this.editor.toolbar.handleAction(r):this.handleAction(r),!0):!1}async handleAction(e){let t=this.textarea;if(t){t.focus();try{switch(e){case"toggleBold":z(t);break;case"toggleItalic":V(t);break;case"insertLink":R(t);break;case"toggleBulletList":q(t);break;case"toggleNumberedList":D(t);break}t.dispatchEvent(new Event("input",{bubbles:!0}))}catch(o){console.error("Error in markdown action:",o)}}}destroy(){}};var T={name:"solar",colors:{bgPrimary:"#faf0ca",bgSecondary:"#ffffff",text:"#0d3b66",h1:"#f95738",h2:"#ee964b",h3:"#3d8a51",strong:"#ee964b",em:"#f95738",link:"#0d3b66",code:"#0d3b66",codeBg:"rgba(244, 211, 94, 0.4)",blockquote:"#5a7a9b",hr:"#5a7a9b",syntaxMarker:"rgba(13, 59, 102, 0.52)",cursor:"#f95738",selection:"rgba(244, 211, 94, 0.4)",listMarker:"#ee964b",toolbarBg:"#ffffff",toolbarBorder:"rgba(13, 59, 102, 0.15)",toolbarIcon:"#0d3b66",toolbarHover:"#f5f5f5",toolbarActive:"#faf0ca"}},me={name:"cave",colors:{bgPrimary:"#141E26",bgSecondary:"#1D2D3E",text:"#c5dde8",h1:"#d4a5ff",h2:"#f6ae2d",h3:"#9fcfec",strong:"#f6ae2d",em:"#9fcfec",link:"#9fcfec",code:"#c5dde8",codeBg:"#1a232b",blockquote:"#9fcfec",hr:"#c5dde8",syntaxMarker:"rgba(159, 207, 236, 0.73)",cursor:"#f26419",selection:"rgba(51, 101, 138, 0.4)",listMarker:"#f6ae2d",toolbarBg:"#1D2D3E",toolbarBorder:"rgba(197, 221, 232, 0.1)",toolbarIcon:"#c5dde8",toolbarHover:"#243546",toolbarActive:"#2a3f52"}},ge={solar:T,cave:me,light:T,dark:me};function W(n){return typeof n=="string"?{...ge[n]||ge.solar,name:n}:n}function ve(n){let e=[];for(let[t,o]of Object.entries(n)){let r=t.replace(/([A-Z])/g,"-$1").toLowerCase();e.push(`--${r}: ${o};`)}return e.join(`
|
|
30
|
+
`)}function ye(n,e={}){return{...n,colors:{...n.colors,...e}}}function be(n={}){let{fontSize:e="14px",lineHeight:t=1.6,fontFamily:o="'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace",padding:r="20px",theme:i=null,mobile:s={}}=n,a=Object.keys(s).length>0?`
|
|
31
|
+
@media (max-width: 640px) {
|
|
32
|
+
.overtype-wrapper .overtype-input,
|
|
33
|
+
.overtype-wrapper .overtype-preview {
|
|
34
|
+
${Object.entries(s).map(([u,c])=>`${u.replace(/([A-Z])/g,"-$1").toLowerCase()}: ${c} !important;`).join(`
|
|
35
|
+
`)}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
`:"",l=i&&i.colors?ve(i.colors):"";return`
|
|
39
|
+
/* OverType Editor Styles */
|
|
40
|
+
.overtype-container {
|
|
41
|
+
position: relative !important;
|
|
42
|
+
width: 100% !important;
|
|
43
|
+
height: 100% !important;
|
|
44
|
+
${l?`
|
|
45
|
+
/* Theme Variables */
|
|
46
|
+
${l}`:""}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.overtype-wrapper {
|
|
50
|
+
position: relative !important;
|
|
51
|
+
width: 100% !important;
|
|
52
|
+
height: 100% !important;
|
|
53
|
+
overflow: hidden !important;
|
|
54
|
+
background: var(--bg-secondary, #ffffff) !important;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/* Critical alignment styles - must be identical for both layers */
|
|
58
|
+
.overtype-wrapper .overtype-input,
|
|
59
|
+
.overtype-wrapper .overtype-preview {
|
|
60
|
+
/* Positioning - must be identical */
|
|
61
|
+
position: absolute !important;
|
|
62
|
+
top: 0 !important;
|
|
63
|
+
left: 0 !important;
|
|
64
|
+
width: 100% !important;
|
|
65
|
+
height: 100% !important;
|
|
66
|
+
|
|
67
|
+
/* Font properties - any difference breaks alignment */
|
|
68
|
+
font-family: ${o} !important;
|
|
69
|
+
font-size: var(--instance-font-size, ${e}) !important;
|
|
70
|
+
line-height: var(--instance-line-height, ${t}) !important;
|
|
71
|
+
font-weight: normal !important;
|
|
72
|
+
font-style: normal !important;
|
|
73
|
+
font-variant: normal !important;
|
|
74
|
+
font-stretch: normal !important;
|
|
75
|
+
font-kerning: none !important;
|
|
76
|
+
font-feature-settings: normal !important;
|
|
77
|
+
|
|
78
|
+
/* Box model - must match exactly */
|
|
79
|
+
padding: var(--instance-padding, ${r}) !important;
|
|
80
|
+
margin: 0 !important;
|
|
81
|
+
border: none !important;
|
|
82
|
+
outline: none !important;
|
|
83
|
+
box-sizing: border-box !important;
|
|
84
|
+
|
|
85
|
+
/* Text layout - critical for character positioning */
|
|
86
|
+
white-space: pre-wrap !important;
|
|
87
|
+
word-wrap: break-word !important;
|
|
88
|
+
word-break: normal !important;
|
|
89
|
+
overflow-wrap: break-word !important;
|
|
90
|
+
tab-size: 2 !important;
|
|
91
|
+
-moz-tab-size: 2 !important;
|
|
92
|
+
text-align: left !important;
|
|
93
|
+
text-indent: 0 !important;
|
|
94
|
+
letter-spacing: normal !important;
|
|
95
|
+
word-spacing: normal !important;
|
|
96
|
+
|
|
97
|
+
/* Text rendering */
|
|
98
|
+
text-transform: none !important;
|
|
99
|
+
text-rendering: auto !important;
|
|
100
|
+
-webkit-font-smoothing: auto !important;
|
|
101
|
+
-webkit-text-size-adjust: 100% !important;
|
|
102
|
+
|
|
103
|
+
/* Direction and writing */
|
|
104
|
+
direction: ltr !important;
|
|
105
|
+
writing-mode: horizontal-tb !important;
|
|
106
|
+
unicode-bidi: normal !important;
|
|
107
|
+
text-orientation: mixed !important;
|
|
108
|
+
|
|
109
|
+
/* Visual effects that could shift perception */
|
|
110
|
+
text-shadow: none !important;
|
|
111
|
+
filter: none !important;
|
|
112
|
+
transform: none !important;
|
|
113
|
+
zoom: 1 !important;
|
|
114
|
+
|
|
115
|
+
/* Vertical alignment */
|
|
116
|
+
vertical-align: baseline !important;
|
|
117
|
+
|
|
118
|
+
/* Size constraints */
|
|
119
|
+
min-width: 0 !important;
|
|
120
|
+
min-height: 0 !important;
|
|
121
|
+
max-width: none !important;
|
|
122
|
+
max-height: none !important;
|
|
123
|
+
|
|
124
|
+
/* Overflow */
|
|
125
|
+
overflow-y: auto !important;
|
|
126
|
+
overflow-x: auto !important;
|
|
127
|
+
scrollbar-width: auto !important;
|
|
128
|
+
scrollbar-gutter: auto !important;
|
|
129
|
+
|
|
130
|
+
/* Animation/transition - disabled to prevent movement */
|
|
131
|
+
animation: none !important;
|
|
132
|
+
transition: none !important;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/* Input layer styles */
|
|
136
|
+
.overtype-wrapper .overtype-input {
|
|
137
|
+
/* Layer positioning */
|
|
138
|
+
z-index: 1 !important;
|
|
139
|
+
|
|
140
|
+
/* Text visibility */
|
|
141
|
+
color: transparent !important;
|
|
142
|
+
caret-color: var(--cursor, #f95738) !important;
|
|
143
|
+
background-color: transparent !important;
|
|
144
|
+
|
|
145
|
+
/* Textarea-specific */
|
|
146
|
+
resize: none !important;
|
|
147
|
+
appearance: none !important;
|
|
148
|
+
-webkit-appearance: none !important;
|
|
149
|
+
-moz-appearance: none !important;
|
|
150
|
+
|
|
151
|
+
/* Prevent mobile zoom on focus */
|
|
152
|
+
touch-action: manipulation !important;
|
|
153
|
+
|
|
154
|
+
/* Disable autofill and spellcheck */
|
|
155
|
+
autocomplete: off !important;
|
|
156
|
+
autocorrect: off !important;
|
|
157
|
+
autocapitalize: off !important;
|
|
158
|
+
spellcheck: false !important;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.overtype-wrapper .overtype-input::selection {
|
|
162
|
+
background-color: var(--selection, rgba(244, 211, 94, 0.4));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/* Preview layer styles */
|
|
166
|
+
.overtype-wrapper .overtype-preview {
|
|
167
|
+
/* Layer positioning */
|
|
168
|
+
z-index: 0 !important;
|
|
169
|
+
pointer-events: none !important;
|
|
170
|
+
color: var(--text, #0d3b66) !important;
|
|
171
|
+
background-color: transparent !important;
|
|
172
|
+
|
|
173
|
+
/* Prevent text selection */
|
|
174
|
+
user-select: none !important;
|
|
175
|
+
-webkit-user-select: none !important;
|
|
176
|
+
-moz-user-select: none !important;
|
|
177
|
+
-ms-user-select: none !important;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/* Defensive styles for preview child divs */
|
|
181
|
+
.overtype-wrapper .overtype-preview div {
|
|
182
|
+
/* Reset any inherited styles */
|
|
183
|
+
margin: 0 !important;
|
|
184
|
+
padding: 0 !important;
|
|
185
|
+
border: none !important;
|
|
186
|
+
text-align: left !important;
|
|
187
|
+
text-indent: 0 !important;
|
|
188
|
+
display: block !important;
|
|
189
|
+
position: static !important;
|
|
190
|
+
transform: none !important;
|
|
191
|
+
min-height: 0 !important;
|
|
192
|
+
max-height: none !important;
|
|
193
|
+
line-height: inherit !important;
|
|
194
|
+
font-size: inherit !important;
|
|
195
|
+
font-family: inherit !important;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/* Markdown element styling - NO SIZE CHANGES */
|
|
199
|
+
.overtype-wrapper .overtype-preview .header {
|
|
200
|
+
font-weight: bold !important;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/* Header colors */
|
|
204
|
+
.overtype-wrapper .overtype-preview .h1 {
|
|
205
|
+
color: var(--h1, #f95738) !important;
|
|
206
|
+
}
|
|
207
|
+
.overtype-wrapper .overtype-preview .h2 {
|
|
208
|
+
color: var(--h2, #ee964b) !important;
|
|
209
|
+
}
|
|
210
|
+
.overtype-wrapper .overtype-preview .h3 {
|
|
211
|
+
color: var(--h3, #3d8a51) !important;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/* Bold text */
|
|
215
|
+
.overtype-wrapper .overtype-preview strong {
|
|
216
|
+
color: var(--strong, #ee964b) !important;
|
|
217
|
+
font-weight: bold !important;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/* Italic text */
|
|
221
|
+
.overtype-wrapper .overtype-preview em {
|
|
222
|
+
color: var(--em, #f95738) !important;
|
|
223
|
+
text-decoration-color: var(--em, #f95738) !important;
|
|
224
|
+
text-decoration-thickness: 1px !important;
|
|
225
|
+
font-style: italic !important;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/* Inline code */
|
|
229
|
+
.overtype-wrapper .overtype-preview code {
|
|
230
|
+
background: var(--code-bg, rgba(244, 211, 94, 0.4)) !important;
|
|
231
|
+
color: var(--code, #0d3b66) !important;
|
|
232
|
+
padding: 0 !important;
|
|
233
|
+
border-radius: 2px !important;
|
|
234
|
+
font-family: inherit !important;
|
|
235
|
+
font-weight: normal !important;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/* Code blocks */
|
|
239
|
+
.overtype-wrapper .overtype-preview pre {
|
|
240
|
+
background: #1e1e1e !important;
|
|
241
|
+
padding: 0 !important;
|
|
242
|
+
margin: 0 !important;
|
|
243
|
+
border-radius: 4px !important;
|
|
244
|
+
overflow-x: auto !important;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
.overtype-wrapper .overtype-preview pre code {
|
|
248
|
+
background: none !important;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/* Blockquotes */
|
|
252
|
+
.overtype-wrapper .overtype-preview .blockquote {
|
|
253
|
+
color: var(--blockquote, #5a7a9b) !important;
|
|
254
|
+
padding: 0 !important;
|
|
255
|
+
margin: 0 !important;
|
|
256
|
+
border: none !important;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/* Links */
|
|
260
|
+
.overtype-wrapper .overtype-preview a {
|
|
261
|
+
color: var(--link, #0d3b66) !important;
|
|
262
|
+
text-decoration: underline !important;
|
|
263
|
+
font-weight: normal !important;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
.overtype-wrapper .overtype-preview a:hover {
|
|
267
|
+
text-decoration: underline !important;
|
|
268
|
+
color: var(--link, #0d3b66) !important;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/* Lists - no list styling */
|
|
272
|
+
.overtype-wrapper .overtype-preview ul,
|
|
273
|
+
.overtype-wrapper .overtype-preview ol {
|
|
274
|
+
list-style: none !important;
|
|
275
|
+
margin: 0 !important;
|
|
276
|
+
padding: 0 !important;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
.overtype-wrapper .overtype-preview li {
|
|
280
|
+
margin: 0 !important;
|
|
281
|
+
padding: 0 !important;
|
|
282
|
+
list-style: none !important;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/* Horizontal rules */
|
|
286
|
+
.overtype-wrapper .overtype-preview hr {
|
|
287
|
+
border: none !important;
|
|
288
|
+
color: var(--hr, #5a7a9b) !important;
|
|
289
|
+
margin: 0 !important;
|
|
290
|
+
padding: 0 !important;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
.overtype-wrapper .overtype-preview .hr-marker {
|
|
294
|
+
color: var(--hr, #5a7a9b) !important;
|
|
295
|
+
opacity: 0.6 !important;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/* Code fence markers - with background when not in code block */
|
|
299
|
+
.overtype-wrapper .overtype-preview .code-fence {
|
|
300
|
+
color: var(--code, #0d3b66) !important;
|
|
301
|
+
background: var(--code-bg, rgba(244, 211, 94, 0.4)) !important;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/* Code block lines - background for entire code block */
|
|
305
|
+
.overtype-wrapper .overtype-preview .code-block-line {
|
|
306
|
+
background: var(--code-bg, rgba(244, 211, 94, 0.4)) !important;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/* Remove background from code fence when inside code block line */
|
|
310
|
+
.overtype-wrapper .overtype-preview .code-block-line .code-fence {
|
|
311
|
+
background: transparent !important;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/* Raw markdown line */
|
|
315
|
+
.overtype-wrapper .overtype-preview .raw-line {
|
|
316
|
+
color: var(--raw-line, #5a7a9b) !important;
|
|
317
|
+
font-style: normal !important;
|
|
318
|
+
font-weight: normal !important;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/* Syntax markers */
|
|
322
|
+
.overtype-wrapper .overtype-preview .syntax-marker {
|
|
323
|
+
color: var(--syntax-marker, rgba(13, 59, 102, 0.52)) !important;
|
|
324
|
+
opacity: 0.7 !important;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/* List markers */
|
|
328
|
+
.overtype-wrapper .overtype-preview .list-marker {
|
|
329
|
+
color: var(--list-marker, #ee964b) !important;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/* Stats bar */
|
|
333
|
+
.overtype-wrapper.with-stats {
|
|
334
|
+
padding-bottom: 40px !important;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
.overtype-wrapper .overtype-stats {
|
|
338
|
+
position: absolute !important;
|
|
339
|
+
bottom: 0 !important;
|
|
340
|
+
left: 0 !important;
|
|
341
|
+
right: 0 !important;
|
|
342
|
+
height: 40px !important;
|
|
343
|
+
padding: 0 20px !important;
|
|
344
|
+
background: #f8f9fa !important;
|
|
345
|
+
border-top: 1px solid #e0e0e0 !important;
|
|
346
|
+
display: flex !important;
|
|
347
|
+
justify-content: space-between !important;
|
|
348
|
+
align-items: center !important;
|
|
349
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
|
|
350
|
+
font-size: 0.85rem !important;
|
|
351
|
+
color: #666 !important;
|
|
352
|
+
z-index: 2 !important;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/* Dark theme stats bar */
|
|
356
|
+
.overtype-wrapper[data-theme="cave"] .overtype-stats {
|
|
357
|
+
background: var(--bg-secondary, #1D2D3E) !important;
|
|
358
|
+
border-top: 1px solid rgba(197, 221, 232, 0.1) !important;
|
|
359
|
+
color: var(--text, #c5dde8) !important;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
.overtype-wrapper .overtype-stats .overtype-stat {
|
|
363
|
+
display: flex !important;
|
|
364
|
+
align-items: center !important;
|
|
365
|
+
gap: 5px !important;
|
|
366
|
+
white-space: nowrap !important;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
.overtype-wrapper .overtype-stats .live-dot {
|
|
370
|
+
width: 8px !important;
|
|
371
|
+
height: 8px !important;
|
|
372
|
+
background: #4caf50 !important;
|
|
373
|
+
border-radius: 50% !important;
|
|
374
|
+
animation: pulse 2s infinite !important;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
@keyframes pulse {
|
|
378
|
+
0%, 100% { opacity: 1; transform: scale(1); }
|
|
379
|
+
50% { opacity: 0.6; transform: scale(1.2); }
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/* Adjust textarea and preview for stats bar */
|
|
383
|
+
.overtype-wrapper.with-stats .overtype-input,
|
|
384
|
+
.overtype-wrapper.with-stats .overtype-preview {
|
|
385
|
+
height: calc(100% - 40px) !important;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/* Toolbar Styles */
|
|
389
|
+
.overtype-toolbar {
|
|
390
|
+
display: flex;
|
|
391
|
+
align-items: center;
|
|
392
|
+
gap: 4px;
|
|
393
|
+
padding: 8px;
|
|
394
|
+
background: var(--toolbar-bg, var(--bg-primary, #f8f9fa));
|
|
395
|
+
border: 1px solid var(--toolbar-border, var(--border, #e0e0e0));
|
|
396
|
+
border-bottom: none;
|
|
397
|
+
border-radius: 8px 8px 0 0;
|
|
398
|
+
overflow-x: auto;
|
|
399
|
+
-webkit-overflow-scrolling: touch;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
.overtype-toolbar-button {
|
|
403
|
+
display: flex;
|
|
404
|
+
align-items: center;
|
|
405
|
+
justify-content: center;
|
|
406
|
+
width: 32px;
|
|
407
|
+
height: 32px;
|
|
408
|
+
padding: 0;
|
|
409
|
+
border: none;
|
|
410
|
+
border-radius: 6px;
|
|
411
|
+
background: transparent;
|
|
412
|
+
color: var(--toolbar-icon, var(--text-secondary, #666));
|
|
413
|
+
cursor: pointer;
|
|
414
|
+
transition: all 0.2s ease;
|
|
415
|
+
flex-shrink: 0;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
.overtype-toolbar-button svg {
|
|
419
|
+
width: 20px;
|
|
420
|
+
height: 20px;
|
|
421
|
+
fill: currentColor;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/* Special sizing for code block icon */
|
|
425
|
+
.overtype-toolbar-button[data-action="insertCodeBlock"] svg {
|
|
426
|
+
width: 22px;
|
|
427
|
+
height: 18px;
|
|
428
|
+
fill: transparent !important;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
.overtype-toolbar-button:hover {
|
|
432
|
+
background: var(--toolbar-hover, var(--bg-secondary, #e9ecef));
|
|
433
|
+
color: var(--toolbar-icon, var(--text-primary, #333));
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
.overtype-toolbar-button:active {
|
|
437
|
+
transform: scale(0.95);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
.overtype-toolbar-button.active {
|
|
441
|
+
background: var(--toolbar-active, var(--primary, #007bff));
|
|
442
|
+
color: var(--toolbar-icon, var(--text-primary, #333));
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
.overtype-toolbar-button:disabled {
|
|
446
|
+
opacity: 0.5;
|
|
447
|
+
cursor: not-allowed;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
.overtype-toolbar-separator {
|
|
451
|
+
width: 1px;
|
|
452
|
+
height: 24px;
|
|
453
|
+
background: var(--border, #e0e0e0);
|
|
454
|
+
margin: 0 4px;
|
|
455
|
+
flex-shrink: 0;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/* Adjust wrapper when toolbar is present */
|
|
459
|
+
.overtype-container .overtype-toolbar + .overtype-wrapper {
|
|
460
|
+
border-radius: 0 0 8px 8px;
|
|
461
|
+
border-top: none;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/* Mobile toolbar adjustments */
|
|
465
|
+
@media (max-width: 640px) {
|
|
466
|
+
.overtype-toolbar {
|
|
467
|
+
padding: 6px;
|
|
468
|
+
gap: 2px;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
.overtype-toolbar-button {
|
|
472
|
+
width: 36px;
|
|
473
|
+
height: 36px;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
.overtype-toolbar-separator {
|
|
477
|
+
margin: 0 2px;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
${a}
|
|
482
|
+
`}var ke=`<svg viewBox="0 0 18 18">
|
|
483
|
+
<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>
|
|
484
|
+
<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>
|
|
485
|
+
</svg>`,we=`<svg viewBox="0 0 18 18">
|
|
486
|
+
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="13" y1="4" y2="4"></line>
|
|
487
|
+
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="5" x2="11" y1="14" y2="14"></line>
|
|
488
|
+
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="10" y1="14" y2="4"></line>
|
|
489
|
+
</svg>`,xe=`<svg viewBox="0 0 18 18">
|
|
490
|
+
<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>
|
|
491
|
+
</svg>`,Se=`<svg viewBox="0 0 18 18">
|
|
492
|
+
<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>
|
|
493
|
+
</svg>`,Le=`<svg viewBox="0 0 18 18">
|
|
494
|
+
<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>
|
|
495
|
+
</svg>`,Ce=`<svg viewBox="0 0 18 18">
|
|
496
|
+
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="11" y1="7" y2="11"></line>
|
|
497
|
+
<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>
|
|
498
|
+
<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>
|
|
499
|
+
</svg>`,Ee=`<svg viewBox="0 0 18 18">
|
|
500
|
+
<polyline stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" points="5 7 3 9 5 11"></polyline>
|
|
501
|
+
<polyline stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" points="13 7 15 9 13 11"></polyline>
|
|
502
|
+
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="10" x2="8" y1="5" y2="13"></line>
|
|
503
|
+
</svg>`,Ae=`<svg viewBox="0 0 46 33" fill="transparent" xmlns="http://www.w3.org/2000/svg">
|
|
504
|
+
<path d="M35 8h3a5 5 0 0 1 5 5v12a5 5 0 0 1-5 5H18a5 5 0 0 1-5-5v-2" stroke="currentColor" stroke-width="4" stroke-linecap="round"></path>
|
|
505
|
+
<path d="m9 2.5-6 6L9 14M20 2.5l6 6-6 5.5" stroke="currentColor" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"></path>
|
|
506
|
+
</svg>`,$e=`<svg viewBox="0 0 18 18">
|
|
507
|
+
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="4" y2="4"></line>
|
|
508
|
+
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="9" y2="9"></line>
|
|
509
|
+
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="14" y2="14"></line>
|
|
510
|
+
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="3" x2="3" y1="4" y2="4"></line>
|
|
511
|
+
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="3" x2="3" y1="9" y2="9"></line>
|
|
512
|
+
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="3" x2="3" y1="14" y2="14"></line>
|
|
513
|
+
</svg>`,Be=`<svg viewBox="0 0 18 18">
|
|
514
|
+
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="15" y1="4" y2="4"></line>
|
|
515
|
+
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="15" y1="9" y2="9"></line>
|
|
516
|
+
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="15" y1="14" y2="14"></line>
|
|
517
|
+
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="1" x1="2.5" x2="4.5" y1="5.5" y2="5.5"></line>
|
|
518
|
+
<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>
|
|
519
|
+
<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>
|
|
520
|
+
<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>
|
|
521
|
+
</svg>`,Te=`<svg viewBox="2 2 20 20">
|
|
522
|
+
<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>
|
|
523
|
+
<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>
|
|
524
|
+
</svg>`,Ie=`<svg viewBox="0 0 18 18">
|
|
525
|
+
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="16" y1="4" y2="4"></line>
|
|
526
|
+
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="16" y1="9" y2="9"></line>
|
|
527
|
+
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="16" y1="14" y2="14"></line>
|
|
528
|
+
<rect stroke="currentColor" fill="none" stroke-width="1.5" x="2" y="3" width="3" height="3" rx="0.5"></rect>
|
|
529
|
+
<rect stroke="currentColor" fill="none" stroke-width="1.5" x="2" y="13" width="3" height="3" rx="0.5"></rect>
|
|
530
|
+
<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>
|
|
531
|
+
</svg>`;var K=class{constructor(e){this.editor=e,this.container=null,this.buttons={}}create(){this.container=document.createElement("div"),this.container.className="overtype-toolbar",this.container.setAttribute("role","toolbar"),this.container.setAttribute("aria-label","Text formatting"),[{name:"bold",icon:ke,title:"Bold (Ctrl+B)",action:"toggleBold"},{name:"italic",icon:we,title:"Italic (Ctrl+I)",action:"toggleItalic"},{separator:!0},{name:"h1",icon:xe,title:"Heading 1",action:"insertH1"},{name:"h2",icon:Se,title:"Heading 2",action:"insertH2"},{name:"h3",icon:Le,title:"Heading 3",action:"insertH3"},{separator:!0},{name:"link",icon:Ce,title:"Insert Link (Ctrl+K)",action:"insertLink"},{name:"code",icon:Ee,title:"Inline Code",action:"toggleCode"},{name:"codeBlock",icon:Ae,title:"Code Block",action:"insertCodeBlock"},{separator:!0},{name:"quote",icon:Te,title:"Quote",action:"toggleQuote"},{separator:!0},{name:"bulletList",icon:$e,title:"Bullet List",action:"toggleBulletList"},{name:"orderedList",icon:Be,title:"Numbered List",action:"toggleNumberedList"},{name:"taskList",icon:Ie,title:"Task List",action:"toggleTaskList"}].forEach(r=>{if(r.separator){let i=document.createElement("div");i.className="overtype-toolbar-separator",i.setAttribute("role","separator"),this.container.appendChild(i)}else{let i=this.createButton(r);this.buttons[r.name]=i,this.container.appendChild(i)}});let t=this.editor.element.querySelector(".overtype-container"),o=this.editor.element.querySelector(".overtype-wrapper");return t&&o&&t.insertBefore(this.container,o),this.container}createButton(e){let t=document.createElement("button");return t.className="overtype-toolbar-button",t.type="button",t.title=e.title,t.setAttribute("aria-label",e.title),t.setAttribute("data-action",e.action),t.innerHTML=e.icon,t.addEventListener("click",o=>{o.preventDefault(),this.handleAction(e.action)}),t}async handleAction(e){let t=this.editor.textarea;if(t){t.focus();try{switch(e){case"toggleBold":z(t);break;case"toggleItalic":V(t);break;case"insertH1":pe(t);break;case"insertH2":de(t);break;case"insertH3":ue(t);break;case"insertLink":R(t);break;case"toggleCode":ae(t);break;case"insertCodeBlock":let o=t.selectionStart,r=t.selectionEnd,s="```\n"+t.value.slice(o,r)+"\n```";t.setRangeText(s,o,r,"end");break;case"toggleBulletList":q(t);break;case"toggleNumberedList":D(t);break;case"toggleQuote":le(t);break;case"toggleTaskList":ce(t);break}t.dispatchEvent(new Event("input",{bubbles:!0}))}catch(o){console.error("Error loading markdown-actions:",o)}}}async updateButtonStates(){let e=this.editor.textarea;if(e)try{let t=he(e);Object.entries(this.buttons).forEach(([o,r])=>{let i=!1;switch(o){case"bold":i=t.includes("bold");break;case"italic":i=t.includes("italic");break;case"code":i=!1;break;case"bulletList":i=t.includes("bullet-list");break;case"orderedList":i=t.includes("numbered-list");break;case"quote":i=t.includes("quote");break;case"taskList":i=t.includes("task-list");break;case"h1":i=t.includes("header");break;case"h2":i=t.includes("header-2");break;case"h3":i=t.includes("header-3");break}r.classList.toggle("active",i),r.setAttribute("aria-pressed",i.toString())})}catch(t){}}destroy(){this.container&&(this.container.remove(),this.container=null,this.buttons={})}};var k=class k{constructor(e,t={}){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(i=>{if(i.overTypeInstance)return i.overTypeInstance.reinit(t),i.overTypeInstance;let s=Object.create(k.prototype);return s._init(i,t),i.overTypeInstance=s,k.instances.set(i,s),s})}_init(e,t={}){this.element=e,this.options=this._mergeOptions(t),this.instanceId=++k.instanceCount,this.initialized=!1,k.injectStyles(),k.initGlobalListeners();let o=e.querySelector(".overtype-container"),r=e.querySelector(".overtype-wrapper");o||r?this._recoverFromDOM(o,r):this._buildFromScratch(),this.shortcuts=new O(this),this.options.toolbar&&(this.toolbar=new K(this),this.toolbar.create(),this.textarea.addEventListener("selectionchange",()=>{this.toolbar.updateButtonStates()}),this.textarea.addEventListener("input",()=>{this.toolbar.updateButtonStates()})),this.initialized=!0,this.options.onChange&&this.options.onChange(this.getValue(),this)}_mergeOptions(e){let t={fontSize:"14px",lineHeight:1.6,fontFamily:"'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace",padding:"16px",mobile:{fontSize:"16px",padding:"12px",lineHeight:1.5},autofocus:!1,placeholder:"Start typing...",value:"",onChange:null,onKeydown:null,showActiveLineRaw:!1,showStats:!1,toolbar:!1,statsFormatter:null},{theme:o,colors:r,...i}=e;return{...t,...i}}_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 o=k.currentTheme||T,r=typeof o=="string"?o:o.name;r&&this.container.setAttribute("data-theme",r),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=k.currentTheme||T,t=typeof e=="string"?e:e.name;t&&this.container.setAttribute("data-theme",t),this.wrapper=document.createElement("div"),this.wrapper.className="overtype-wrapper",this.options.showStats&&this.wrapper.classList.add("with-stats"),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.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.options.showStats&&(this.statsBar=document.createElement("div"),this.statsBar.className="overtype-stats",this.wrapper.appendChild(this.statsBar),this._updateStats()),this.container.appendChild(this.wrapper),this.element.appendChild(this.container)}_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")}_applyOptions(){this.options.autofocus&&this.textarea.focus(),this.updatePreview()}updatePreview(){let e=this.textarea.value,t=this.textarea.selectionStart,o=this._getCurrentLine(e,t),r=H.parse(e,o,this.options.showActiveLineRaw);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 o=e[t],r=e[t+1],i=o.parentElement,s=r.parentElement;if(!i||!s)continue;o.style.display="block",r.style.display="block",i.classList.add("code-block-line"),s.classList.add("code-block-line");let a=i.nextElementSibling;for(;a&&a!==s&&(a.tagName==="DIV"&&a.classList.add("code-block-line"),a=a.nextElementSibling,!!a););}}_getCurrentLine(e,t){return e.substring(0,t).split(`
|
|
532
|
+
`).length-1}handleInput(e){this.updatePreview()}handleKeydown(e){!this.shortcuts.handleKeydown(e)&&this.options.onKeydown&&this.options.onKeydown(e,this)}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()}focus(){this.textarea.focus()}blur(){this.textarea.blur()}isInitialized(){return this.initialized}reinit(e={}){this.options=this._mergeOptions({...this.options,...e}),this._applyOptions(),this.updatePreview()}_updateStats(){if(!this.statsBar)return;let e=this.textarea.value,t=e.split(`
|
|
533
|
+
`),o=e.length,r=e.split(/\s+/).filter(c=>c.length>0).length,i=this.textarea.selectionStart,a=e.substring(0,i).split(`
|
|
534
|
+
`),l=a.length,u=a[a.length-1].length+1;this.options.statsFormatter?this.statsBar.innerHTML=this.options.statsFormatter({chars:o,words:r,lines:t.length,line:l,column:u}):this.statsBar.innerHTML=`
|
|
535
|
+
<div class="overtype-stat">
|
|
536
|
+
<span class="live-dot"></span>
|
|
537
|
+
<span>${o} chars, ${r} words, ${t.length} lines</span>
|
|
538
|
+
</div>
|
|
539
|
+
<div class="overtype-stat">Line ${l}, Col ${u}</div>
|
|
540
|
+
`}showStats(e){this.options.showStats=e,e&&!this.statsBar?(this.statsBar=document.createElement("div"),this.statsBar.className="overtype-stats",this.wrapper.appendChild(this.statsBar),this.wrapper.classList.add("with-stats"),this._updateStats()):!e&&this.statsBar&&(this.statsBar.remove(),this.statsBar=null,this.wrapper.classList.remove("with-stats"))}destroy(){if(this.element.overTypeInstance=null,k.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,t={}){return new k(e,t)}static getInstance(e){return e.overTypeInstance||k.instances.get(e)||null}static destroyAll(){document.querySelectorAll("[data-overtype-instance]").forEach(t=>{let o=k.getInstance(t);o&&o.destroy()})}static injectStyles(e=!1){if(k.stylesInjected&&!e)return;let t=document.querySelector("style.overtype-styles");t&&t.remove();let o=k.currentTheme||T,r=be({theme:o}),i=document.createElement("style");i.className="overtype-styles",i.textContent=r,document.head.appendChild(i),k.stylesInjected=!0}static setTheme(e,t=null){let o=typeof e=="string"?W(e):e;t&&(o=ye(o,t)),k.currentTheme=o,k.injectStyles(!0),document.querySelectorAll(".overtype-container").forEach(r=>{let i=typeof o=="string"?o:o.name;i&&r.setAttribute("data-theme",i)}),document.querySelectorAll(".overtype-wrapper").forEach(r=>{if(!r.closest(".overtype-container")){let s=typeof o=="string"?o:o.name;s&&r.setAttribute("data-theme",s)}let i=r._instance;i&&i.updatePreview()})}static initGlobalListeners(){k.globalListenersInitialized||(document.addEventListener("input",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let t=e.target.closest(".overtype-wrapper"),o=t==null?void 0:t._instance;o&&o.handleInput(e)}}),document.addEventListener("keydown",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let t=e.target.closest(".overtype-wrapper"),o=t==null?void 0:t._instance;o&&o.handleKeydown(e)}}),document.addEventListener("scroll",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let t=e.target.closest(".overtype-wrapper"),o=t==null?void 0:t._instance;o&&o.handleScroll(e)}},!0),document.addEventListener("selectionchange",e=>{let t=document.activeElement;if(t&&t.classList.contains("overtype-input")){let o=t.closest(".overtype-wrapper"),r=o==null?void 0:o._instance;r&&(r.options.showStats&&r.statsBar&&r._updateStats(),clearTimeout(r._selectionTimeout),r._selectionTimeout=setTimeout(()=>{r.updatePreview()},50))}}),k.globalListenersInitialized=!0)}};I(k,"instances",new WeakMap),I(k,"stylesInjected",!1),I(k,"globalListenersInitialized",!1),I(k,"instanceCount",0);var A=k;A.MarkdownParser=H;A.ShortcutsManager=O;A.themes={solar:T,cave:W("cave")};A.getTheme=W;A.currentTheme=T;var Ge=A;return Pe(Xe);})();
|
|
541
|
+
/**
|
|
542
|
+
* OverType - A lightweight markdown editor library with perfect WYSIWYG alignment
|
|
543
|
+
* @version 1.0.0
|
|
544
|
+
* @license MIT
|
|
545
|
+
*/
|
|
546
|
+
window.OverType = OverType.OverType || OverType.default || OverType;
|