overtype 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/overtype.esm.js +2 -21
- package/dist/overtype.esm.js.map +2 -2
- package/dist/overtype.js +2 -21
- package/dist/overtype.js.map +2 -2
- package/dist/overtype.min.js +15 -25
- package/package.json +1 -1
- package/src/icons.js +0 -4
- package/src/styles.js +0 -7
- package/src/toolbar.js +1 -10
package/dist/overtype.min.js
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* OverType v1.0.
|
|
2
|
+
* OverType v1.0.3
|
|
3
3
|
* A lightweight markdown editor library with perfect WYSIWYG alignment
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @author Demo User
|
|
6
6
|
* https://github.com/demo/overtype
|
|
7
7
|
*/
|
|
8
|
-
var OverType=(()=>{var _=Object.defineProperty;var He=Object.getOwnPropertyDescriptor;var
|
|
9
|
-
`).map((s,a)=>o&&a===t?`<div class="raw-line">${this.escapeHtml(s)||" "}</div>`:this.parseLine(s)).join("")}};var
|
|
8
|
+
var OverType=(()=>{var _=Object.defineProperty;var He=Object.getOwnPropertyDescriptor;var Ie=Object.getOwnPropertyNames;var Me=Object.prototype.hasOwnProperty;var Oe=(n,e,t)=>e in n?_(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var je=(n,e)=>{for(var t in e)_(n,t,{get:e[t],enumerable:!0})},Ne=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Ie(e))!Me.call(n,r)&&r!==t&&_(n,r,{get:()=>e[r],enumerable:!(o=He(e,r))||o.enumerable});return n};var _e=n=>Ne(_({},"__esModule",{value:!0}),n);var I=(n,e,t)=>(Oe(n,typeof e!="symbol"?e+"":e,t),t);var Ge={};je(Ge,{OverType:()=>A,default:()=>Qe});var M=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 Pe=Object.defineProperty,X=Object.getOwnPropertySymbols,Fe=Object.prototype.hasOwnProperty,Ve=Object.prototype.propertyIsEnumerable,Y=(n,e,t)=>e in n?Pe(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,ee=(n,e)=>{for(var t in e||(e={}))Fe.call(e,t)&&Y(n,t,e[t]);if(X)for(var t of X(e))Ve.call(e,t)&&Y(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 ze(){return{prefix:"",suffix:"",blockPrefix:"",blockSuffix:"",multiline:!1,replaceNext:"",prefixSpace:!1,scanFor:"",surroundWithNewlines:!1,orderedList:!1,unorderedList:!1,trimFirst:!1}}function E(n){return ee(ee({},ze()),n)}var F=!1;function Re(){return F}function g(n,e,t){F&&(console.group(`\u{1F50D} ${n}`),console.log(e),t&&console.log("Data:",t),console.groupEnd())}function P(n,e){if(!F)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 re(n){F&&(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 $(n,{text:e,selectionStart:t,selectionEnd:o}){let r=Re();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,p=i!==s;if(C===null||C===!0){n.contentEditable="true";try{C=document.execCommand("insertText",!1,e),r&&console.log("execCommand returned:",C,"for text with",e.split(`
|
|
10
10
|
`).length,"lines")}catch(c){C=!1,r&&console.log("execCommand threw error:",c)}n.contentEditable="false"}if(r&&(console.log("canInsertText before:",C),console.log("execCommand result:",C)),C){let c=a+e+l,f=n.value;r&&(console.log("Expected length:",c.length),console.log("Actual length:",f.length)),f!==c&&r&&(console.log("execCommand changed the value but not as expected"),console.log("Expected:",JSON.stringify(c.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(c){}n.value=a+e+l;try{document.execCommand("ms-endUndoUnit")}catch(c){}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 te(n){return n.trim().split(`
|
|
11
|
-
`).length>1}function
|
|
12
|
-
`),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
|
|
11
|
+
`).length>1}function qe(n,e){let t=e;for(;n[t]&&n[t-1]!=null&&!n[t-1].match(/\s/);)t--;return t}function De(n,e,t){let o=e,r=t?/\n/:/\s/;for(;n[o]&&!n[o].match(r);)o++;return o}function ie(n){let e=n.value.split(`
|
|
12
|
+
`),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 We(n,e,t,o=!1){if(n.selectionStart===n.selectionEnd)n.selectionStart=qe(n.value,n.selectionStart),n.selectionEnd=De(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 Z(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=`
|
|
13
13
|
`.repeat(2-i)),t.match(/\S/)&&s<2&&(l=`
|
|
14
14
|
`.repeat(2-s)),{newlinesToAppend:a,newlinesToPrepend:l}}function V(n,e,t={}){let o=n.selectionStart,r=n.selectionEnd,i=o===r,s=n.value,a=o;for(;a>0&&s[a-1]!==`
|
|
15
15
|
`;)a--;if(i){let u=o;for(;u<s.length&&s[u]!==`
|
|
16
16
|
`;)u++;n.selectionStart=a,n.selectionEnd=u}else ie(n);let l=e(n);if(t.adjustSelection){let p=n.value.slice(n.selectionStart,n.selectionEnd).startsWith(t.prefix),c=t.adjustSelection(p,o,r,a);l.selectionStart=c.start,l.selectionEnd=c.end}else if(t.prefix){let p=n.value.slice(n.selectionStart,n.selectionEnd).startsWith(t.prefix);i?p?(l.selectionStart=Math.max(o-t.prefix.length,a),l.selectionEnd=l.selectionStart):(l.selectionStart=o+t.prefix.length,l.selectionEnd=l.selectionStart):p?(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 z(n,e){let t,o,{prefix:r,suffix:i,blockPrefix:s,blockSuffix:a,replaceNext:l,prefixSpace:u,scanFor:p,surroundWithNewlines:c,trimFirst:f}=e,d=n.selectionStart,v=n.selectionEnd,m=n.value.slice(n.selectionStart,n.selectionEnd),h=te(m)&&s&&s.length>0?`${s}
|
|
17
17
|
`:r,b=te(m)&&a&&a.length>0?`
|
|
18
|
-
${a}`:i;if(u){let x=n.value[n.selectionStart-1];n.selectionStart!==0&&x!=null&&!x.match(/\s/)&&(h=` ${h}`)}m=
|
|
18
|
+
${a}`:i;if(u){let x=n.value[n.selectionStart-1];n.selectionStart!==0&&x!=null&&!x.match(/\s/)&&(h=` ${h}`)}m=We(n,h,b,e.multiline);let y=n.selectionStart,w=n.selectionEnd,T=l&&l.length>0&&b.indexOf(l)>-1&&m.length>0;if(c){let x=Z(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(T)if(p&&p.length>0&&m.match(p)){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 Q=L[0]||"",G=L[1]||"";x=Q+h+m.trim()+b+G,y+=Q.length,w-=G.length}return{text:x,selectionStart:y,selectionEnd:w}}}function se(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(`
|
|
19
19
|
`);if(l.every(p=>p.startsWith(t)&&(!o||p.endsWith(o))))i=l.map(p=>{let c=p.slice(t.length);return o&&(c=c.slice(0,c.length-o.length)),c}).join(`
|
|
20
20
|
`),a=s+i.length;else if(i=l.map(p=>t+p+(o||"")).join(`
|
|
21
21
|
`),r){let{newlinesToAppend:p,newlinesToPrepend:c}=Z(n);s+=p.length,a=s+i.length,i=p+i+c}return{text:i,selectionStart:s,selectionEnd:a}}function ne(n){let e=n.split(`
|
|
22
22
|
`),t=/^\d+\.\s+/,o=e.every(i=>t.test(i)),r=e;return o&&(r=e.map(i=>i.replace(t,""))),{text:r.join(`
|
|
23
23
|
`),processed:o}}function oe(n){let e=n.split(`
|
|
24
24
|
`),t="- ",o=e.every(i=>i.startsWith(t)),r=e;return o&&(r=e.map(i=>i.slice(t.length))),{text:r.join(`
|
|
25
|
-
`),processed:o}}function O(n,e){return e?"- ":`${n+1}. `}function
|
|
25
|
+
`),processed:o}}function O(n,e){return e?"- ":`${n+1}. `}function Ke(n,e){let t,o,r;return n.orderedList?(t=ne(e),o=oe(t.text),r=o.text):(t=oe(e),o=ne(t.text),r=o.text),[t,o,r]}function Ue(n,e){let t=n.selectionStart===n.selectionEnd,o=n.selectionStart,r=n.selectionEnd;ie(n);let i=n.value.slice(n.selectionStart,n.selectionEnd),[s,a,l]=Ke(e,i),u=l.split(`
|
|
26
26
|
`).map((m,h)=>`${O(h,e.unorderedList)}${m}`),p=u.reduce((m,h,b)=>m+O(b,e.unorderedList).length,0),c=u.reduce((m,h,b)=>m+O(b,!e.unorderedList).length,0);if(s.processed)return t?(o=Math.max(o-O(0,e.unorderedList).length,0),r=o):(o=n.selectionStart,r=n.selectionEnd-p),{text:l,selectionStart:o,selectionEnd:r};let{newlinesToAppend:f,newlinesToPrepend:d}=Z(n),v=f+u.join(`
|
|
27
|
-
`)+d;return t?(o=Math.max(o+O(0,e.unorderedList).length+f.length,0),r=o):a.processed?(o=Math.max(n.selectionStart+f.length,0),r=n.selectionEnd+f.length+p-c):(o=Math.max(n.selectionStart+f.length,0),r=n.selectionEnd+f.length+p),{text:v,selectionStart:o,selectionEnd:r}}function ae(n,e){let t=V(n,o=>
|
|
27
|
+
`)+d;return t?(o=Math.max(o+O(0,e.unorderedList).length+f.length,0),r=o):a.processed?(o=Math.max(n.selectionStart+f.length,0),r=n.selectionEnd+f.length+p-c):(o=Math.max(n.selectionStart+f.length,0),r=n.selectionEnd+f.length+p),{text:v,selectionStart:o,selectionEnd:r}}function ae(n,e){let t=V(n,o=>Ue(o,e),{adjustSelection:(o,r,i,s)=>{let a=n.value.slice(s,n.selectionEnd),l=/^\d+\.\s+/,u=/^- /,p=l.test(a),c=u.test(a),f=e.orderedList&&p||e.unorderedList&&c;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(p||c){let d=a.match(p?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(p||c){let d=a.match(p?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}}}});$(n,t)}function Ze(n){if(!n)return[];let e=[],{selectionStart:t,selectionEnd:o,value:r}=n,i=r.split(`
|
|
28
28
|
`),s=0,a="";for(let c of i){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 l=Math.max(0,t-10),u=Math.min(r.length,o+10),p=r.slice(l,u);if(p.includes("**")){let c=r.slice(Math.max(0,t-100),t),f=r.slice(o,Math.min(r.length,o+100)),d=c.lastIndexOf("**"),v=f.indexOf("**");d!==-1&&v!==-1&&e.push("bold")}if(p.includes("_")){let c=r.slice(Math.max(0,t-100),t),f=r.slice(o,Math.min(r.length,o+100)),d=c.lastIndexOf("_"),v=f.indexOf("_");d!==-1&&v!==-1&&e.push("italic")}if(p.includes("`")){let c=r.slice(Math.max(0,t-100),t),f=r.slice(o,Math.min(r.length,o+100));c.includes("`")&&f.includes("`")&&e.push("code")}if(p.includes("[")&&p.includes("]")){let c=r.slice(Math.max(0,t-100),t),f=r.slice(o,Math.min(r.length,o+100)),d=c.lastIndexOf("["),v=f.indexOf("]");d!==-1&&v!==-1&&r.slice(o+v+1,o+v+10).startsWith("(")&&e.push("link")}return e}function R(n){if(!n||n.disabled||n.readOnly)return;g("toggleBold","Starting"),P(n,"Before");let e=E(S.bold),t=z(n,e);re(t),$(n,t),P(n,"After")}function q(n){if(!n||n.disabled||n.readOnly)return;let e=E(S.italic),t=z(n,e);$(n,t)}function le(n){if(!n||n.disabled||n.readOnly)return;let e=E(S.code),t=z(n,e);$(n,t)}function D(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=z(n,o);$(n,i)}function W(n){if(!n||n.disabled||n.readOnly)return;let e=E(S.bulletList);ae(n,e)}function K(n){if(!n||n.disabled||n.readOnly)return;let e=E(S.numberedList);ae(n,e)}function ce(n){if(!n||n.disabled||n.readOnly)return;g("toggleQuote","Starting"),P(n,"Initial");let e=E(S.quote),t=V(n,o=>se(o,e),{prefix:e.prefix});re(t),$(n,t),P(n,"Final")}function pe(n){if(!n||n.disabled||n.readOnly)return;let e=E(S.taskList),t=V(n,o=>se(o,e),{prefix:e.prefix});$(n,t)}function J(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]!==`
|
|
29
29
|
`;)l--;let u=a;for(;u<i.length&&i[u]!==`
|
|
30
|
-
`;)u++;let p=i.slice(l,u);g("insertHeader",`Current line (before): "${p}"`);let c=p.match(/^(#{1,6})\s*/),f=c?c[1].length:0,d=c?c[0].length:0;g("insertHeader","Existing header check:"),g("insertHeader",` - Match: ${c?`"${c[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=V(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 T=Math.max(b-d,w);return g("insertHeader",` - Removing header, adjusting by -${d}`),{start:T,end:b===y?T:Math.max(y-d,w)}}else if(d>0){let T=r.prefix.length-d;return g("insertHeader",` - Replacing header, adjusting by ${T}`),{start:b+T,end:y+T}}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 ============"),$(n,m)}function de(n){J(n,1,!0)}function ue(n){J(n,2,!0)}function he(n){J(n,3,!0)}function fe(n){return
|
|
30
|
+
`;)u++;let p=i.slice(l,u);g("insertHeader",`Current line (before): "${p}"`);let c=p.match(/^(#{1,6})\s*/),f=c?c[1].length:0,d=c?c[0].length:0;g("insertHeader","Existing header check:"),g("insertHeader",` - Match: ${c?`"${c[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=V(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 T=Math.max(b-d,w);return g("insertHeader",` - Removing header, adjusting by -${d}`),{start:T,end:b===y?T:Math.max(y-d,w)}}else if(d>0){let T=r.prefix.length-d;return g("insertHeader",` - Replacing header, adjusting by ${T}`),{start:b+T,end:y+T}}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 ============"),$(n,m)}function de(n){J(n,1,!0)}function ue(n){J(n,2,!0)}function he(n){J(n,3,!0)}function fe(n){return Ze(n)}var j=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":R(t);break;case"toggleItalic":q(t);break;case"insertLink":D(t);break;case"toggleBulletList":W(t);break;case"toggleNumberedList":K(t);break}t.dispatchEvent(new Event("input",{bubbles:!0}))}catch(o){console.error("Error in markdown action:",o)}}}destroy(){}};var B={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"}},ge={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"}},ve={solar:B,cave:ge,light:B,dark:ge};function H(n){return typeof n=="string"?{...ve[n]||ve.solar,name:n}:n}function N(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(`
|
|
31
31
|
`)}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?`
|
|
32
32
|
@media (max-width: 640px) {
|
|
33
33
|
.overtype-wrapper .overtype-input,
|
|
@@ -418,13 +418,6 @@ ${a}`:i;if(u){let x=n.value[n.selectionStart-1];n.selectionStart!==0&&x!=null&&!
|
|
|
418
418
|
height: 20px;
|
|
419
419
|
fill: currentColor;
|
|
420
420
|
}
|
|
421
|
-
|
|
422
|
-
/* Special sizing for code block icon */
|
|
423
|
-
.overtype-toolbar-button[data-action="insertCodeBlock"] svg {
|
|
424
|
-
width: 22px;
|
|
425
|
-
height: 18px;
|
|
426
|
-
fill: transparent !important;
|
|
427
|
-
}
|
|
428
421
|
|
|
429
422
|
.overtype-toolbar-button:hover {
|
|
430
423
|
background: var(--toolbar-hover, var(--bg-secondary, #e9ecef));
|
|
@@ -496,17 +489,14 @@ ${a}`:i;if(u){let x=n.value[n.selectionStart-1];n.selectionStart!==0&&x!=null&&!
|
|
|
496
489
|
<polyline stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" points="5 7 3 9 5 11"></polyline>
|
|
497
490
|
<polyline stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" points="13 7 15 9 13 11"></polyline>
|
|
498
491
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="10" x2="8" y1="5" y2="13"></line>
|
|
499
|
-
</svg>`,Ae=`<svg viewBox="0 0
|
|
500
|
-
<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>
|
|
501
|
-
<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>
|
|
502
|
-
</svg>`,Te=`<svg viewBox="0 0 18 18">
|
|
492
|
+
</svg>`,Ae=`<svg viewBox="0 0 18 18">
|
|
503
493
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="4" y2="4"></line>
|
|
504
494
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="9" y2="9"></line>
|
|
505
495
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="14" y2="14"></line>
|
|
506
496
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="3" x2="3" y1="4" y2="4"></line>
|
|
507
497
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="3" x2="3" y1="9" y2="9"></line>
|
|
508
498
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="3" x2="3" y1="14" y2="14"></line>
|
|
509
|
-
</svg
|
|
499
|
+
</svg>`,Te=`<svg viewBox="0 0 18 18">
|
|
510
500
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="15" y1="4" y2="4"></line>
|
|
511
501
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="15" y1="9" y2="9"></line>
|
|
512
502
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="15" y1="14" y2="14"></line>
|
|
@@ -514,17 +504,17 @@ ${a}`:i;if(u){let x=n.value[n.selectionStart-1];n.selectionStart!==0&&x!=null&&!
|
|
|
514
504
|
<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>
|
|
515
505
|
<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>
|
|
516
506
|
<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>
|
|
517
|
-
</svg
|
|
507
|
+
</svg>`,$e=`<svg viewBox="2 2 20 20">
|
|
518
508
|
<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>
|
|
519
509
|
<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>
|
|
520
|
-
</svg>`,
|
|
510
|
+
</svg>`,Be=`<svg viewBox="0 0 18 18">
|
|
521
511
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="16" y1="4" y2="4"></line>
|
|
522
512
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="16" y1="9" y2="9"></line>
|
|
523
513
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="16" y1="14" y2="14"></line>
|
|
524
514
|
<rect stroke="currentColor" fill="none" stroke-width="1.5" x="2" y="3" width="3" height="3" rx="0.5"></rect>
|
|
525
515
|
<rect stroke="currentColor" fill="none" stroke-width="1.5" x="2" y="13" width="3" height="3" rx="0.5"></rect>
|
|
526
516
|
<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>
|
|
527
|
-
</svg>`;var U=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:"
|
|
517
|
+
</svg>`;var U=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:"Code (Ctrl+`)",action:"toggleCode"},{separator:!0},{name:"quote",icon:$e,title:"Quote",action:"toggleQuote"},{separator:!0},{name:"bulletList",icon:Ae,title:"Bullet List",action:"toggleBulletList"},{name:"orderedList",icon:Te,title:"Numbered List",action:"toggleNumberedList"},{name:"taskList",icon:Be,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":R(t);break;case"toggleItalic":q(t);break;case"insertH1":de(t);break;case"insertH2":ue(t);break;case"insertH3":he(t);break;case"insertLink":D(t);break;case"toggleCode":le(t);break;case"toggleBulletList":W(t);break;case"toggleNumberedList":K(t);break;case"toggleQuote":ce(t);break;case"toggleTaskList":pe(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=fe(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.instanceTheme=t.theme||null,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 j(this),this.options.toolbar&&(this.toolbar=new U(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=this.instanceTheme||k.currentTheme||B,r=typeof o=="string"?o:o.name;if(r&&this.container.setAttribute("data-theme",r),this.instanceTheme){let i=typeof this.instanceTheme=="string"?H(this.instanceTheme):this.instanceTheme;if(i&&i.colors){let s=N(i.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||k.currentTheme||B,t=typeof e=="string"?e:e.name;if(t&&this.container.setAttribute("data-theme",t),this.instanceTheme){let o=typeof this.instanceTheme=="string"?H(this.instanceTheme):this.instanceTheme;if(o&&o.colors){let r=N(o.colors);this.container.style.cssText+=r}}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=M.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(`
|
|
528
518
|
`).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(`
|
|
529
519
|
`),o=e.length,r=e.split(/\s+/).filter(p=>p.length>0).length,i=this.textarea.selectionStart,a=e.substring(0,i).split(`
|
|
530
520
|
`),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=`
|
|
@@ -533,7 +523,7 @@ ${a}`:i;if(u){let x=n.value[n.selectionStart-1];n.selectionStart!==0&&x!=null&&!
|
|
|
533
523
|
<span>${o} chars, ${r} words, ${t.length} lines</span>
|
|
534
524
|
</div>
|
|
535
525
|
<div class="overtype-stat">Line ${l}, Col ${u}</div>
|
|
536
|
-
`}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||B,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"?
|
|
526
|
+
`}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||B,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"?H(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=M;A.ShortcutsManager=j;A.themes={solar:B,cave:H("cave")};A.getTheme=H;A.currentTheme=B;var Qe=A;return _e(Ge);})();
|
|
537
527
|
/**
|
|
538
528
|
* OverType - A lightweight markdown editor library with perfect WYSIWYG alignment
|
|
539
529
|
* @version 1.0.0
|
package/package.json
CHANGED
package/src/icons.js
CHANGED
|
@@ -38,10 +38,6 @@ export const codeIcon = `<svg viewBox="0 0 18 18">
|
|
|
38
38
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="10" x2="8" y1="5" y2="13"></line>
|
|
39
39
|
</svg>`;
|
|
40
40
|
|
|
41
|
-
export const codeBlockIcon = `<svg viewBox="0 0 46 33" fill="transparent" xmlns="http://www.w3.org/2000/svg">
|
|
42
|
-
<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>
|
|
43
|
-
<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>
|
|
44
|
-
</svg>`;
|
|
45
41
|
|
|
46
42
|
export const bulletListIcon = `<svg viewBox="0 0 18 18">
|
|
47
43
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="4" y2="4"></line>
|
package/src/styles.js
CHANGED
|
@@ -420,13 +420,6 @@ export function generateStyles(options = {}) {
|
|
|
420
420
|
height: 20px;
|
|
421
421
|
fill: currentColor;
|
|
422
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
423
|
|
|
431
424
|
.overtype-toolbar-button:hover {
|
|
432
425
|
background: var(--toolbar-hover, var(--bg-secondary, #e9ecef));
|
package/src/toolbar.js
CHANGED
|
@@ -33,8 +33,7 @@ export class Toolbar {
|
|
|
33
33
|
{ name: 'h3', icon: icons.h3Icon, title: 'Heading 3', action: 'insertH3' },
|
|
34
34
|
{ separator: true },
|
|
35
35
|
{ name: 'link', icon: icons.linkIcon, title: 'Insert Link (Ctrl+K)', action: 'insertLink' },
|
|
36
|
-
{ name: 'code', icon: icons.codeIcon, title: '
|
|
37
|
-
{ name: 'codeBlock', icon: icons.codeBlockIcon, title: 'Code Block', action: 'insertCodeBlock' },
|
|
36
|
+
{ name: 'code', icon: icons.codeIcon, title: 'Code (Ctrl+`)', action: 'toggleCode' },
|
|
38
37
|
{ separator: true },
|
|
39
38
|
{ name: 'quote', icon: icons.quoteIcon, title: 'Quote', action: 'toggleQuote' },
|
|
40
39
|
{ separator: true },
|
|
@@ -122,14 +121,6 @@ export class Toolbar {
|
|
|
122
121
|
case 'toggleCode':
|
|
123
122
|
markdownActions.toggleCode(textarea);
|
|
124
123
|
break;
|
|
125
|
-
case 'insertCodeBlock':
|
|
126
|
-
// For code blocks, we'll insert the markdown directly
|
|
127
|
-
const start = textarea.selectionStart;
|
|
128
|
-
const end = textarea.selectionEnd;
|
|
129
|
-
const selectedText = textarea.value.slice(start, end);
|
|
130
|
-
const codeBlock = '```\n' + selectedText + '\n```';
|
|
131
|
-
textarea.setRangeText(codeBlock, start, end, 'end');
|
|
132
|
-
break;
|
|
133
124
|
case 'toggleBulletList':
|
|
134
125
|
markdownActions.toggleBulletList(textarea);
|
|
135
126
|
break;
|