overtype 1.0.0 → 1.0.2
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/diagram.png +0 -0
- package/dist/overtype.esm.js +25 -15
- package/dist/overtype.esm.js.map +2 -2
- package/dist/overtype.js +25 -15
- package/dist/overtype.js.map +2 -2
- package/dist/overtype.min.js +27 -31
- package/package.json +8 -7
- package/src/overtype.js +29 -6
- package/src/styles.js +0 -5
package/dist/overtype.min.js
CHANGED
|
@@ -1,41 +1,42 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* OverType v1.0.
|
|
2
|
+
* OverType v1.0.1
|
|
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
|
|
9
|
-
`).map((s,a)=>o&&a===t?`<div class="raw-line">${this.escapeHtml(s)||" "}</div>`:this.parseLine(s)).join("")}};var Fe=Object.defineProperty,
|
|
10
|
-
`).length
|
|
11
|
-
`),
|
|
8
|
+
var OverType=(()=>{var _=Object.defineProperty;var He=Object.getOwnPropertyDescriptor;var Me=Object.getOwnPropertyNames;var Oe=Object.prototype.hasOwnProperty;var je=(n,e,t)=>e in n?_(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var Ne=(n,e)=>{for(var t in e)_(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&&_(n,r,{get:()=>e[r],enumerable:!(o=He(e,r))||o.enumerable});return n};var Pe=n=>_e(_({},"__esModule",{value:!0}),n);var H=(n,e,t)=>(je(n,typeof e!="symbol"?e+"":e,t),t);var Xe={};Ne(Xe,{OverType:()=>A,default:()=>Ge});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 Fe=Object.defineProperty,X=Object.getOwnPropertySymbols,Ve=Object.prototype.hasOwnProperty,ze=Object.prototype.propertyIsEnumerable,Y=(n,e,t)=>e in n?Fe(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,ee=(n,e)=>{for(var t in e||(e={}))Ve.call(e,t)&&Y(n,t,e[t]);if(X)for(var t of X(e))ze.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 Re(){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({},Re()),n)}var F=!1;function qe(){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=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,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
|
+
`).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 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 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 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 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=`
|
|
12
13
|
`.repeat(2-i)),t.match(/\S/)&&s<2&&(l=`
|
|
13
|
-
`.repeat(2-s)),{newlinesToAppend:a,newlinesToPrepend:l}}function
|
|
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]!==`
|
|
14
15
|
`;)a--;if(i){let u=o;for(;u<s.length&&s[u]!==`
|
|
15
|
-
`;)u++;n.selectionStart=a,n.selectionEnd=u}else
|
|
16
|
-
`:r,b=
|
|
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
|
|
18
|
-
`);if(l.every(
|
|
19
|
-
`),a=s+i.length;else if(i=l.map(
|
|
20
|
-
`),r){let{newlinesToAppend:
|
|
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
|
+
`: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=Ke(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
|
+
`);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
|
+
`),a=s+i.length;else if(i=l.map(p=>t+p+(o||"")).join(`
|
|
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(`
|
|
21
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(`
|
|
22
|
-
`),processed:o}}function
|
|
23
|
+
`),processed:o}}function oe(n){let e=n.split(`
|
|
23
24
|
`),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
|
|
25
|
-
`).map((m,h)=>`${
|
|
26
|
-
`)+d;return t?(o=Math.max(o+
|
|
27
|
-
`),s=0,a="";for(let
|
|
25
|
+
`),processed:o}}function O(n,e){return e?"- ":`${n+1}. `}function Ue(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 Ze(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]=Ue(e,i),u=l.split(`
|
|
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=>Ze(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 Je(n){if(!n)return[];let e=[],{selectionStart:t,selectionEnd:o,value:r}=n,i=r.split(`
|
|
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]!==`
|
|
28
29
|
`;)l--;let u=a;for(;u<i.length&&i[u]!==`
|
|
29
|
-
`;)u++;let
|
|
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 Je(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 I(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(`
|
|
30
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?`
|
|
31
32
|
@media (max-width: 640px) {
|
|
32
33
|
.overtype-wrapper .overtype-input,
|
|
33
34
|
.overtype-wrapper .overtype-preview {
|
|
34
|
-
${Object.entries(s).map(([u,
|
|
35
|
+
${Object.entries(s).map(([u,p])=>`${u.replace(/([A-Z])/g,"-$1").toLowerCase()}: ${p} !important;`).join(`
|
|
35
36
|
`)}
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
|
-
`:"",l=i&&i.colors?
|
|
39
|
+
`:"",l=i&&i.colors?N(i.colors):"";return`
|
|
39
40
|
/* OverType Editor Styles */
|
|
40
41
|
.overtype-container {
|
|
41
42
|
position: relative !important;
|
|
@@ -392,9 +393,6 @@ ${a}`:i;if(u){let x=n.value[n.selectionStart-1];n.selectionStart!==0&&x!=null&&!
|
|
|
392
393
|
gap: 4px;
|
|
393
394
|
padding: 8px;
|
|
394
395
|
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
396
|
overflow-x: auto;
|
|
399
397
|
-webkit-overflow-scrolling: touch;
|
|
400
398
|
}
|
|
@@ -457,8 +455,6 @@ ${a}`:i;if(u){let x=n.value[n.selectionStart-1];n.selectionStart!==0&&x!=null&&!
|
|
|
457
455
|
|
|
458
456
|
/* Adjust wrapper when toolbar is present */
|
|
459
457
|
.overtype-container .overtype-toolbar + .overtype-wrapper {
|
|
460
|
-
border-radius: 0 0 8px 8px;
|
|
461
|
-
border-top: none;
|
|
462
458
|
}
|
|
463
459
|
|
|
464
460
|
/* Mobile toolbar adjustments */
|
|
@@ -503,14 +499,14 @@ ${a}`:i;if(u){let x=n.value[n.selectionStart-1];n.selectionStart!==0&&x!=null&&!
|
|
|
503
499
|
</svg>`,Ae=`<svg viewBox="0 0 46 33" fill="transparent" xmlns="http://www.w3.org/2000/svg">
|
|
504
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>
|
|
505
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>
|
|
506
|
-
</svg
|
|
502
|
+
</svg>`,Te=`<svg viewBox="0 0 18 18">
|
|
507
503
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="4" y2="4"></line>
|
|
508
504
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="9" y2="9"></line>
|
|
509
505
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="14" y2="14"></line>
|
|
510
506
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="3" x2="3" y1="4" y2="4"></line>
|
|
511
507
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="3" x2="3" y1="9" y2="9"></line>
|
|
512
508
|
<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
|
|
509
|
+
</svg>`,$e=`<svg viewBox="0 0 18 18">
|
|
514
510
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="15" y1="4" y2="4"></line>
|
|
515
511
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="15" y1="9" y2="9"></line>
|
|
516
512
|
<line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="15" y1="14" y2="14"></line>
|
|
@@ -518,7 +514,7 @@ ${a}`:i;if(u){let x=n.value[n.selectionStart-1];n.selectionStart!==0&&x!=null&&!
|
|
|
518
514
|
<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
515
|
<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
516
|
<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>`,
|
|
517
|
+
</svg>`,Be=`<svg viewBox="2 2 20 20">
|
|
522
518
|
<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
519
|
<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
520
|
</svg>`,Ie=`<svg viewBox="0 0 18 18">
|
|
@@ -528,16 +524,16 @@ ${a}`:i;if(u){let x=n.value[n.selectionStart-1];n.selectionStart!==0&&x!=null&&!
|
|
|
528
524
|
<rect stroke="currentColor" fill="none" stroke-width="1.5" x="2" y="3" width="3" height="3" rx="0.5"></rect>
|
|
529
525
|
<rect stroke="currentColor" fill="none" stroke-width="1.5" x="2" y="13" width="3" height="3" rx="0.5"></rect>
|
|
530
526
|
<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
|
|
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:"Inline Code",action:"toggleCode"},{name:"codeBlock",icon:Ae,title:"Code Block",action:"insertCodeBlock"},{separator:!0},{name:"quote",icon:Be,title:"Quote",action:"toggleQuote"},{separator:!0},{name:"bulletList",icon:Te,title:"Bullet List",action:"toggleBulletList"},{name:"orderedList",icon:$e,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":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"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":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"?I(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"?I(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(`
|
|
532
528
|
`).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(
|
|
529
|
+
`),o=e.length,r=e.split(/\s+/).filter(p=>p.length>0).length,i=this.textarea.selectionStart,a=e.substring(0,i).split(`
|
|
534
530
|
`),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
531
|
<div class="overtype-stat">
|
|
536
532
|
<span class="live-dot"></span>
|
|
537
533
|
<span>${o} chars, ${r} words, ${t.length} lines</span>
|
|
538
534
|
</div>
|
|
539
535
|
<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||
|
|
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"?I(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)}};H(k,"instances",new WeakMap),H(k,"stylesInjected",!1),H(k,"globalListenersInitialized",!1),H(k,"instanceCount",0);var A=k;A.MarkdownParser=M;A.ShortcutsManager=j;A.themes={solar:B,cave:I("cave")};A.getTheme=I;A.currentTheme=B;var Ge=A;return Pe(Xe);})();
|
|
541
537
|
/**
|
|
542
538
|
* OverType - A lightweight markdown editor library with perfect WYSIWYG alignment
|
|
543
539
|
* @version 1.0.0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "overtype",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "A lightweight markdown editor library with perfect WYSIWYG alignment using an invisible textarea overlay",
|
|
5
5
|
"main": "dist/overtype.js",
|
|
6
6
|
"module": "dist/overtype.esm.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"textarea",
|
|
24
24
|
"markdown-editor"
|
|
25
25
|
],
|
|
26
|
-
"author": "
|
|
26
|
+
"author": "David Miranda",
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"esbuild": "^0.19.0",
|
|
@@ -34,17 +34,18 @@
|
|
|
34
34
|
"dist",
|
|
35
35
|
"src",
|
|
36
36
|
"README.md",
|
|
37
|
-
"LICENSE"
|
|
37
|
+
"LICENSE",
|
|
38
|
+
"diagram.png"
|
|
38
39
|
],
|
|
39
40
|
"repository": {
|
|
40
41
|
"type": "git",
|
|
41
|
-
"url": "https://github.com/
|
|
42
|
+
"url": "https://github.com/panphora/overtype.git"
|
|
42
43
|
},
|
|
43
44
|
"bugs": {
|
|
44
|
-
"url": "https://github.com/
|
|
45
|
+
"url": "https://github.com/panphora/overtype/issues"
|
|
45
46
|
},
|
|
46
|
-
"homepage": "https://github.com/
|
|
47
|
+
"homepage": "https://github.com/panphora/overtype#readme",
|
|
47
48
|
"dependencies": {
|
|
48
|
-
"markdown-actions": "^1.1.
|
|
49
|
+
"markdown-actions": "^1.1.2"
|
|
49
50
|
}
|
|
50
51
|
}
|
package/src/overtype.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import { MarkdownParser } from './parser.js';
|
|
8
8
|
import { ShortcutsManager } from './shortcuts.js';
|
|
9
9
|
import { generateStyles } from './styles.js';
|
|
10
|
-
import { getTheme, mergeTheme, solar } from './themes.js';
|
|
10
|
+
import { getTheme, mergeTheme, solar, themeToCSSVars } from './themes.js';
|
|
11
11
|
import { Toolbar } from './toolbar.js';
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -72,6 +72,10 @@ class OverType {
|
|
|
72
72
|
*/
|
|
73
73
|
_init(element, options = {}) {
|
|
74
74
|
this.element = element;
|
|
75
|
+
|
|
76
|
+
// Store the original theme option before merging
|
|
77
|
+
this.instanceTheme = options.theme || null;
|
|
78
|
+
|
|
75
79
|
this.options = this._mergeOptions(options);
|
|
76
80
|
this.instanceId = ++OverType.instanceCount;
|
|
77
81
|
this.initialized = false;
|
|
@@ -176,11 +180,21 @@ class OverType {
|
|
|
176
180
|
// Wrap it in a container for consistency
|
|
177
181
|
this.container = document.createElement('div');
|
|
178
182
|
this.container.className = 'overtype-container';
|
|
179
|
-
|
|
180
|
-
const
|
|
183
|
+
// Use instance theme if provided, otherwise use global theme
|
|
184
|
+
const themeToUse = this.instanceTheme || OverType.currentTheme || solar;
|
|
185
|
+
const themeName = typeof themeToUse === 'string' ? themeToUse : themeToUse.name;
|
|
181
186
|
if (themeName) {
|
|
182
187
|
this.container.setAttribute('data-theme', themeName);
|
|
183
188
|
}
|
|
189
|
+
|
|
190
|
+
// If using instance theme, apply CSS variables to container
|
|
191
|
+
if (this.instanceTheme) {
|
|
192
|
+
const themeObj = typeof this.instanceTheme === 'string' ? getTheme(this.instanceTheme) : this.instanceTheme;
|
|
193
|
+
if (themeObj && themeObj.colors) {
|
|
194
|
+
const cssVars = themeToCSSVars(themeObj.colors);
|
|
195
|
+
this.container.style.cssText += cssVars;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
184
198
|
wrapper.parentNode.insertBefore(this.container, wrapper);
|
|
185
199
|
this.container.appendChild(wrapper);
|
|
186
200
|
}
|
|
@@ -269,13 +283,22 @@ class OverType {
|
|
|
269
283
|
this.container = document.createElement('div');
|
|
270
284
|
this.container.className = 'overtype-container';
|
|
271
285
|
|
|
272
|
-
// Set
|
|
273
|
-
const
|
|
274
|
-
const themeName = typeof
|
|
286
|
+
// Set theme on container - use instance theme if provided
|
|
287
|
+
const themeToUse = this.instanceTheme || OverType.currentTheme || solar;
|
|
288
|
+
const themeName = typeof themeToUse === 'string' ? themeToUse : themeToUse.name;
|
|
275
289
|
if (themeName) {
|
|
276
290
|
this.container.setAttribute('data-theme', themeName);
|
|
277
291
|
}
|
|
278
292
|
|
|
293
|
+
// If using instance theme, apply CSS variables to container
|
|
294
|
+
if (this.instanceTheme) {
|
|
295
|
+
const themeObj = typeof this.instanceTheme === 'string' ? getTheme(this.instanceTheme) : this.instanceTheme;
|
|
296
|
+
if (themeObj && themeObj.colors) {
|
|
297
|
+
const cssVars = themeToCSSVars(themeObj.colors);
|
|
298
|
+
this.container.style.cssText += cssVars;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
279
302
|
// Create wrapper for editor
|
|
280
303
|
this.wrapper = document.createElement('div');
|
|
281
304
|
this.wrapper.className = 'overtype-wrapper';
|
package/src/styles.js
CHANGED
|
@@ -395,9 +395,6 @@ export function generateStyles(options = {}) {
|
|
|
395
395
|
gap: 4px;
|
|
396
396
|
padding: 8px;
|
|
397
397
|
background: var(--toolbar-bg, var(--bg-primary, #f8f9fa));
|
|
398
|
-
border: 1px solid var(--toolbar-border, var(--border, #e0e0e0));
|
|
399
|
-
border-bottom: none;
|
|
400
|
-
border-radius: 8px 8px 0 0;
|
|
401
398
|
overflow-x: auto;
|
|
402
399
|
-webkit-overflow-scrolling: touch;
|
|
403
400
|
}
|
|
@@ -460,8 +457,6 @@ export function generateStyles(options = {}) {
|
|
|
460
457
|
|
|
461
458
|
/* Adjust wrapper when toolbar is present */
|
|
462
459
|
.overtype-container .overtype-toolbar + .overtype-wrapper {
|
|
463
|
-
border-radius: 0 0 8px 8px;
|
|
464
|
-
border-top: none;
|
|
465
460
|
}
|
|
466
461
|
|
|
467
462
|
/* Mobile toolbar adjustments */
|