overtype 2.3.0 → 2.3.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 +3 -3
- package/dist/overtype-webcomponent.esm.js +34 -33
- package/dist/overtype-webcomponent.esm.js.map +2 -2
- package/dist/overtype-webcomponent.js +34 -33
- package/dist/overtype-webcomponent.js.map +2 -2
- package/dist/overtype-webcomponent.min.js +18 -18
- package/dist/overtype.cjs +34 -33
- package/dist/overtype.cjs.map +2 -2
- package/dist/overtype.esm.js +34 -33
- package/dist/overtype.esm.js.map +2 -2
- package/dist/overtype.js +34 -33
- package/dist/overtype.js.map +2 -2
- package/dist/overtype.min.js +20 -20
- package/package.json +1 -1
- package/src/overtype.js +4 -2
- package/src/styles.js +15 -15
- package/src/themes.js +17 -17
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* OverType v2.3.
|
|
2
|
+
* OverType v2.3.2
|
|
3
3
|
* A lightweight markdown editor library with perfect WYSIWYG alignment
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @author David Miranda
|
|
@@ -12,7 +12,7 @@ var OverTypeEditor=(()=>{var ve=Object.defineProperty;var di=Object.getOwnProper
|
|
|
12
12
|
`),p=s.slice(3).trim(),u=p?` class="language-${p}"`:"",h=l,f=t||this.codeHighlighter;if(f)try{let g=l.replace(/"/g,'"').replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&"),y=f(g,p);y&&typeof y.then=="function"?console.warn("Async highlighters are not supported in Node.js (non-DOM) context. Use synchronous highlighters for server-side rendering."):y&&typeof y=="string"&&y.trim()&&(h=y)}catch(g){console.warn("Code highlighting failed:",g)}let m=`<div><span class="code-fence">${s}</span></div>`;return m+=`<pre class="code-block"><code${u}>${h}</code></pre>`,m+=`<div><span class="code-fence">${c}</span></div>`,m}),n}static getListContext(e,t){let n=e.split(`
|
|
13
13
|
`),o=0,r=0,s=0;for(let u=0;u<n.length;u++){let h=n[u].length;if(o+h>=t){r=u,s=o;break}o+=h+1}let a=n[r],c=s+a.length,d=a.match(this.LIST_PATTERNS.checkbox);if(d)return{inList:!0,listType:"checkbox",indent:d[1],marker:"-",checked:d[2]==="x",content:d[3],lineStart:s,lineEnd:c,markerEndPos:s+d[1].length+d[2].length+5};let l=a.match(this.LIST_PATTERNS.bullet);if(l)return{inList:!0,listType:"bullet",indent:l[1],marker:l[2],content:l[3],lineStart:s,lineEnd:c,markerEndPos:s+l[1].length+l[2].length+1};let p=a.match(this.LIST_PATTERNS.numbered);return p?{inList:!0,listType:"numbered",indent:p[1],marker:parseInt(p[2]),content:p[3],lineStart:s,lineEnd:c,markerEndPos:s+p[1].length+p[2].length+2}:{inList:!1,listType:null,indent:"",marker:null,content:a,lineStart:s,lineEnd:c,markerEndPos:s}}static createNewListItem(e){switch(e.listType){case"bullet":return`${e.indent}${e.marker} `;case"numbered":return`${e.indent}${e.marker+1}. `;case"checkbox":return`${e.indent}- [ ] `;default:return""}}static renumberLists(e){let t=e.split(`
|
|
14
14
|
`),n=new Map,o=!1;return t.map(s=>{let a=s.match(this.LIST_PATTERNS.numbered);if(a){let c=a[1],d=c.length,l=a[3];o||n.clear();let p=(n.get(d)||0)+1;n.set(d,p);for(let[u]of n)u>d&&n.delete(u);return o=!0,`${c}${p}. ${l}`}else return(s.trim()===""||!s.match(/^\s/))&&(o=!1,n.clear()),s}).join(`
|
|
15
|
-
`)}};T(C,"linkIndex",0),T(C,"codeHighlighter",null),T(C,"customSyntax",null),T(C,"LIST_PATTERNS",{bullet:/^(\s*)([-*+])\s+(.*)$/,numbered:/^(\s*)(\d+)\.\s+(.*)$/,checkbox:/^(\s*)-\s+\[([ x])\]\s+(.*)$/});var oe=class{constructor(e){this.editor=e}handleKeydown(e){if(!(navigator.platform.toLowerCase().includes("mac")?e.metaKey:e.ctrlKey))return!1;let o=null;switch(e.key.toLowerCase()){case"b":e.shiftKey||(o="toggleBold");break;case"i":e.shiftKey||(o="toggleItalic");break;case"k":e.shiftKey||(o="insertLink");break;case"7":e.shiftKey&&(o="toggleNumberedList");break;case"8":e.shiftKey&&(o="toggleBulletList");break}return o?(e.preventDefault(),this.editor.performAction(o,e),!0):!1}destroy(){}};var B={name:"solar",colors:{bgPrimary:"#faf0ca",bgSecondary:"#ffffff",text:"#0d3b66",textPrimary:"#0d3b66",textSecondary:"#5a7a9b",h1:"#f95738",h2:"#ee964b",h3:"#3d8a51",strong:"#ee964b",em:"#f95738",del:"#ee964b",link:"#0d3b66",code:"#0d3b66",codeBg:"rgba(244, 211, 94, 0.4)",blockquote:"#5a7a9b",hr:"#5a7a9b",syntaxMarker:"rgba(13, 59, 102, 0.52)",syntax:"#999999",cursor:"#f95738",selection:"rgba(244, 211, 94, 0.4)",listMarker:"#ee964b",rawLine:"#5a7a9b",border:"#e0e0e0",hoverBg:"#f0f0f0",primary:"#0d3b66",toolbarBg:"#ffffff",toolbarIcon:"#0d3b66",toolbarHover:"#f5f5f5",toolbarActive:"#faf0ca",placeholder:"#999999"},previewColors:{text:"#
|
|
15
|
+
`)}};T(C,"linkIndex",0),T(C,"codeHighlighter",null),T(C,"customSyntax",null),T(C,"LIST_PATTERNS",{bullet:/^(\s*)([-*+])\s+(.*)$/,numbered:/^(\s*)(\d+)\.\s+(.*)$/,checkbox:/^(\s*)-\s+\[([ x])\]\s+(.*)$/});var oe=class{constructor(e){this.editor=e}handleKeydown(e){if(!(navigator.platform.toLowerCase().includes("mac")?e.metaKey:e.ctrlKey))return!1;let o=null;switch(e.key.toLowerCase()){case"b":e.shiftKey||(o="toggleBold");break;case"i":e.shiftKey||(o="toggleItalic");break;case"k":e.shiftKey||(o="insertLink");break;case"7":e.shiftKey&&(o="toggleNumberedList");break;case"8":e.shiftKey&&(o="toggleBulletList");break}return o?(e.preventDefault(),this.editor.performAction(o,e),!0):!1}destroy(){}};var B={name:"solar",colors:{bgPrimary:"#faf0ca",bgSecondary:"#ffffff",text:"#0d3b66",textPrimary:"#0d3b66",textSecondary:"#5a7a9b",h1:"#f95738",h2:"#ee964b",h3:"#3d8a51",strong:"#ee964b",em:"#f95738",del:"#ee964b",link:"#0d3b66",code:"#0d3b66",codeBg:"rgba(244, 211, 94, 0.4)",blockquote:"#5a7a9b",hr:"#5a7a9b",syntaxMarker:"rgba(13, 59, 102, 0.52)",syntax:"#999999",cursor:"#f95738",selection:"rgba(244, 211, 94, 0.4)",listMarker:"#ee964b",rawLine:"#5a7a9b",border:"#e0e0e0",hoverBg:"#f0f0f0",primary:"#0d3b66",toolbarBg:"#ffffff",toolbarIcon:"#0d3b66",toolbarHover:"#f5f5f5",toolbarActive:"#faf0ca",placeholder:"#999999"},previewColors:{text:"#0d3b66",h1:"inherit",h2:"inherit",h3:"inherit",strong:"inherit",em:"inherit",link:"#0d3b66",code:"#0d3b66",codeBg:"rgba(244, 211, 94, 0.4)",blockquote:"#5a7a9b",hr:"#5a7a9b",bg:"transparent"}},Ke={name:"cave",colors:{bgPrimary:"#141E26",bgSecondary:"#1D2D3E",text:"#c5dde8",textPrimary:"#c5dde8",textSecondary:"#9fcfec",h1:"#d4a5ff",h2:"#f6ae2d",h3:"#9fcfec",strong:"#f6ae2d",em:"#9fcfec",del:"#f6ae2d",link:"#9fcfec",code:"#c5dde8",codeBg:"#1a232b",blockquote:"#9fcfec",hr:"#c5dde8",syntaxMarker:"rgba(159, 207, 236, 0.73)",syntax:"#7a8c98",cursor:"#f26419",selection:"rgba(51, 101, 138, 0.4)",listMarker:"#f6ae2d",rawLine:"#9fcfec",border:"#2a3f52",hoverBg:"#243546",primary:"#9fcfec",toolbarBg:"#1D2D3E",toolbarIcon:"#c5dde8",toolbarHover:"#243546",toolbarActive:"#2a3f52",placeholder:"#6a7a88"},previewColors:{text:"#c5dde8",h1:"inherit",h2:"inherit",h3:"inherit",strong:"inherit",em:"inherit",link:"#9fcfec",code:"#c5dde8",codeBg:"#1a232b",blockquote:"#9fcfec",hr:"#c5dde8",bg:"transparent"}},Ze={solar:B,cave:Ke,auto:B,light:B,dark:Ke};function $(i){return typeof i=="string"?{...Ze[i]||Ze.solar,name:i}:i}function $e(i){if(i!=="auto")return i;let e=window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)");return e!=null&&e.matches?"cave":"solar"}function Q(i,e){let t=[];for(let[n,o]of Object.entries(i)){let r=n.replace(/([A-Z])/g,"-$1").toLowerCase();t.push(`--${r}: ${o};`)}if(e)for(let[n,o]of Object.entries(e)){let r=n.replace(/([A-Z])/g,"-$1").toLowerCase();t.push(`--preview-${r}-default: ${o};`)}return t.join(`
|
|
16
16
|
`)}function Qe(i,e={},t={}){return{...i,colors:{...i.colors,...e},previewColors:{...i.previewColors,...t}}}function ye(i={}){let{fontSize:e="14px",lineHeight:t=1.6,fontFamily:n='"SF Mono", SFMono-Regular, Menlo, Monaco, "Cascadia Code", Consolas, "Roboto Mono", "Noto Sans Mono", "Droid Sans Mono", "Ubuntu Mono", "DejaVu Sans Mono", "Liberation Mono", "Courier New", Courier, monospace',padding:o="20px",theme:r=null,mobile:s={}}=i,a=Object.keys(s).length>0?`
|
|
17
17
|
@media (max-width: 640px) {
|
|
18
18
|
.overtype-wrapper .overtype-input,
|
|
@@ -704,17 +704,17 @@ var OverTypeEditor=(()=>{var ve=Object.defineProperty;var di=Object.getOwnProper
|
|
|
704
704
|
|
|
705
705
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h1 {
|
|
706
706
|
font-size: 2em !important;
|
|
707
|
-
color: var(--preview-h1,
|
|
707
|
+
color: var(--preview-h1, var(--preview-h1-default)) !important;
|
|
708
708
|
}
|
|
709
709
|
|
|
710
710
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h2 {
|
|
711
711
|
font-size: 1.5em !important;
|
|
712
|
-
color: var(--preview-h2,
|
|
712
|
+
color: var(--preview-h2, var(--preview-h2-default)) !important;
|
|
713
713
|
}
|
|
714
714
|
|
|
715
715
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h3 {
|
|
716
716
|
font-size: 1.17em !important;
|
|
717
|
-
color: var(--preview-h3,
|
|
717
|
+
color: var(--preview-h3, var(--preview-h3-default)) !important;
|
|
718
718
|
}
|
|
719
719
|
|
|
720
720
|
/* Lists - restore list styling in preview mode */
|
|
@@ -764,14 +764,14 @@ var OverTypeEditor=(()=>{var ve=Object.defineProperty;var di=Object.getOwnProper
|
|
|
764
764
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview a {
|
|
765
765
|
pointer-events: auto !important;
|
|
766
766
|
cursor: pointer !important;
|
|
767
|
-
color: var(--preview-link,
|
|
767
|
+
color: var(--preview-link, var(--preview-link-default)) !important;
|
|
768
768
|
text-decoration: underline !important;
|
|
769
769
|
}
|
|
770
770
|
|
|
771
771
|
/* Code blocks - proper pre/code styling in preview mode */
|
|
772
772
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview pre.code-block {
|
|
773
|
-
background: var(--preview-code-bg,
|
|
774
|
-
color: var(--preview-code,
|
|
773
|
+
background: var(--preview-code-bg, var(--preview-code-bg-default)) !important;
|
|
774
|
+
color: var(--preview-code, var(--preview-code-default)) !important;
|
|
775
775
|
padding: 1.2em !important;
|
|
776
776
|
border-radius: 3px !important;
|
|
777
777
|
overflow-x: auto !important;
|
|
@@ -800,8 +800,8 @@ var OverTypeEditor=(()=>{var ve=Object.defineProperty;var di=Object.getOwnProper
|
|
|
800
800
|
/* Blockquotes - enhanced styling in preview mode */
|
|
801
801
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview .blockquote {
|
|
802
802
|
display: block !important;
|
|
803
|
-
border-left: 4px solid var(--preview-blockquote,
|
|
804
|
-
color: var(--preview-blockquote,
|
|
803
|
+
border-left: 4px solid var(--preview-blockquote, var(--preview-blockquote-default)) !important;
|
|
804
|
+
color: var(--preview-blockquote, var(--preview-blockquote-default)) !important;
|
|
805
805
|
padding-left: 1em !important;
|
|
806
806
|
margin: 1em 0 !important;
|
|
807
807
|
font-style: italic !important;
|
|
@@ -812,16 +812,16 @@ var OverTypeEditor=(()=>{var ve=Object.defineProperty;var di=Object.getOwnProper
|
|
|
812
812
|
font-family: Georgia, 'Times New Roman', serif !important;
|
|
813
813
|
font-size: 16px !important;
|
|
814
814
|
line-height: 1.8 !important;
|
|
815
|
-
color: var(--preview-text,
|
|
816
|
-
background: var(--preview-bg,
|
|
815
|
+
color: var(--preview-text, var(--preview-text-default)) !important;
|
|
816
|
+
background: var(--preview-bg, var(--preview-bg-default)) !important;
|
|
817
817
|
}
|
|
818
818
|
|
|
819
819
|
/* Inline code in preview mode - keep monospace */
|
|
820
820
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview code {
|
|
821
821
|
font-family: ${n} !important;
|
|
822
822
|
font-size: 0.9em !important;
|
|
823
|
-
background: var(--preview-code-bg,
|
|
824
|
-
color: var(--preview-code,
|
|
823
|
+
background: var(--preview-code-bg, var(--preview-code-bg-default)) !important;
|
|
824
|
+
color: var(--preview-code, var(--preview-code-default)) !important;
|
|
825
825
|
padding: 0.2em 0.4em !important;
|
|
826
826
|
border-radius: 3px !important;
|
|
827
827
|
}
|
|
@@ -829,18 +829,18 @@ var OverTypeEditor=(()=>{var ve=Object.defineProperty;var di=Object.getOwnProper
|
|
|
829
829
|
/* Strong and em elements in preview mode */
|
|
830
830
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview strong {
|
|
831
831
|
font-weight: 700 !important;
|
|
832
|
-
color: var(--preview-strong,
|
|
832
|
+
color: var(--preview-strong, var(--preview-strong-default)) !important;
|
|
833
833
|
}
|
|
834
834
|
|
|
835
835
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview em {
|
|
836
836
|
font-style: italic !important;
|
|
837
|
-
color: var(--preview-em,
|
|
837
|
+
color: var(--preview-em, var(--preview-em-default)) !important;
|
|
838
838
|
}
|
|
839
839
|
|
|
840
840
|
/* HR in preview mode */
|
|
841
841
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview .hr-marker {
|
|
842
842
|
display: block !important;
|
|
843
|
-
border-top: 2px solid var(--preview-hr,
|
|
843
|
+
border-top: 2px solid var(--preview-hr, var(--preview-hr-default)) !important;
|
|
844
844
|
text-indent: -9999px !important;
|
|
845
845
|
height: 2px !important;
|
|
846
846
|
}
|
|
@@ -974,7 +974,7 @@ ${a}`:r;if(d){let k=i.value[i.selectionStart-1];i.selectionStart!==0&&k!=null&&!
|
|
|
974
974
|
<span>${n} chars, ${o} words, ${t.length} lines</span>
|
|
975
975
|
</div>
|
|
976
976
|
<div class="overtype-stat">Line ${c}, Col ${d}</div>
|
|
977
|
-
`}_setupAutoResize(){this.container.classList.add("overtype-auto-resize"),this.previousHeight=null,this._updateAutoHeight(),this.textarea.addEventListener("input",()=>this._updateAutoHeight()),window.addEventListener("resize",()=>this._updateAutoHeight())}_updateAutoHeight(){if(!this.options.autoResize)return;let e=this.textarea,t=this.preview,n=this.wrapper,o=window.getComputedStyle(e),r=parseFloat(o.paddingTop),s=parseFloat(o.paddingBottom),a=e.scrollTop;e.style.setProperty("height","auto","important");let c=e.scrollHeight;if(this.options.minHeight){let p=parseInt(this.options.minHeight);c=Math.max(c,p)}let d="hidden";if(this.options.maxHeight){let p=parseInt(this.options.maxHeight);c>p&&(c=p,d="auto")}let l=c+"px";e.style.setProperty("height",l,"important"),e.style.setProperty("overflow-y",d,"important"),t.style.setProperty("height",l,"important"),t.style.setProperty("overflow-y",d,"important"),n.style.setProperty("height",l,"important"),e.scrollTop=a,t.scrollTop=a,this.previousHeight!==c&&(this.previousHeight=c)}showStats(e){this.options.showStats=e,e&&!this.statsBar?(this.statsBar=document.createElement("div"),this.statsBar.className="overtype-stats",this.container.appendChild(this.statsBar),this._updateStats()):e&&this.statsBar?this._updateStats():!e&&this.statsBar&&(this.statsBar.remove(),this.statsBar=null)}showNormalEditMode(){return this.container.dataset.mode="normal",this.updatePreview(),requestAnimationFrame(()=>{this.textarea.scrollTop=this.preview.scrollTop,this.textarea.scrollLeft=this.preview.scrollLeft}),this}showPlainTextarea(){if(this.container.dataset.mode="plain",this.toolbar){let e=this.container.querySelector('[data-action="toggle-plain"]');e&&(e.classList.remove("active"),e.title="Show markdown preview")}return this}showPreviewMode(){return this.container.dataset.mode="preview",this.updatePreview(),this}destroy(){if(v._autoInstances.delete(this),v._stopAutoListener(),this.fileUploadInitialized&&this._destroyFileUpload(),this.element.overTypeInstance=null,v.instances.delete(this.element),this.shortcuts&&this.shortcuts.destroy(),this.wrapper){let e=this.getValue();this.wrapper.remove(),this.element.textContent=e}this.initialized=!1}static init(e,t={}){return new v(e,t)}static initFromData(e,t={}){let n=document.querySelectorAll(e);return Array.from(n).map(o=>{let r={...t};for(let s of o.attributes)if(s.name.startsWith("data-ot-")){let c=s.name.slice(8).replace(/-([a-z])/g,(d,l)=>l.toUpperCase());r[c]=v._parseDataValue(s.value)}return new v(o,r)[0]})}static _parseDataValue(e){return e==="true"?!0:e==="false"?!1:e==="null"?null:e!==""&&!isNaN(Number(e))?Number(e):e}static getInstance(e){return e.overTypeInstance||v.instances.get(e)||null}static destroyAll(){document.querySelectorAll("[data-overtype-instance]").forEach(t=>{let n=v.getInstance(t);n&&n.destroy()})}static injectStyles(e=!1){if(v.stylesInjected&&!e)return;let t=document.querySelector("style.overtype-styles");t&&t.remove();let n=v.currentTheme||B,o=ye({theme:n}),r=document.createElement("style");r.className="overtype-styles",r.textContent=o,document.head.appendChild(r),v.stylesInjected=!0}static setTheme(e,t=null){if(v._globalAutoTheme=!1,v._globalAutoCustomColors=null,e==="auto"){v._globalAutoTheme=!0,v._globalAutoCustomColors=t,v._startAutoListener(),v._applyGlobalTheme($e("auto"),t);return}v._stopAutoListener(),v._applyGlobalTheme(e,t)}static _applyGlobalTheme(e,t=null){let n=typeof e=="string"?$(e):e;t&&(n=Qe(n,t)),v.currentTheme=n,v.injectStyles(!0);let o=typeof n=="string"?n:n.name;document.querySelectorAll(".overtype-container").forEach(r=>{o&&r.setAttribute("data-theme",o)}),document.querySelectorAll(".overtype-wrapper").forEach(r=>{r.closest(".overtype-container")||o&&r.setAttribute("data-theme",o);let s=r._instance;s&&s.updatePreview()}),document.querySelectorAll("overtype-editor").forEach(r=>{o&&typeof r.setAttribute=="function"&&r.setAttribute("theme",o),typeof r.refreshTheme=="function"&&r.refreshTheme()})}static _startAutoListener(){v._autoMediaQuery||window.matchMedia&&(v._autoMediaQuery=window.matchMedia("(prefers-color-scheme: dark)"),v._autoMediaListener=e=>{let t=e.matches?"cave":"solar";v._globalAutoTheme&&v._applyGlobalTheme(t,v._globalAutoCustomColors),v._autoInstances.forEach(n=>n._applyResolvedTheme(t))},v._autoMediaQuery.addEventListener("change",v._autoMediaListener))}static _stopAutoListener(){v._autoInstances.size>0||v._globalAutoTheme||v._autoMediaQuery&&(v._autoMediaQuery.removeEventListener("change",v._autoMediaListener),v._autoMediaQuery=null,v._autoMediaListener=null)}static setCodeHighlighter(e){C.setCodeHighlighter(e),document.querySelectorAll(".overtype-wrapper").forEach(t=>{let n=t._instance;n&&n.updatePreview&&n.updatePreview()}),document.querySelectorAll("overtype-editor").forEach(t=>{if(typeof t.getEditor=="function"){let n=t.getEditor();n&&n.updatePreview&&n.updatePreview()}})}static setCustomSyntax(e){C.setCustomSyntax(e),document.querySelectorAll(".overtype-wrapper").forEach(t=>{let n=t._instance;n&&n.updatePreview&&n.updatePreview()}),document.querySelectorAll("overtype-editor").forEach(t=>{if(typeof t.getEditor=="function"){let n=t.getEditor();n&&n.updatePreview&&n.updatePreview()}})}static initGlobalListeners(){v.globalListenersInitialized||(document.addEventListener("input",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let t=e.target.closest(".overtype-wrapper"),n=t==null?void 0:t._instance;n&&n.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"),n=t==null?void 0:t._instance;n&&n.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"),n=t==null?void 0:t._instance;n&&n.handleScroll(e)}},!0),document.addEventListener("selectionchange",e=>{let t=document.activeElement;if(t&&t.classList.contains("overtype-input")){let n=t.closest(".overtype-wrapper"),o=n==null?void 0:n._instance;o&&(o.options.showStats&&o.statsBar&&o._updateStats(),clearTimeout(o._selectionTimeout),o._selectionTimeout=setTimeout(()=>{o.updatePreview()},50))}}),v.globalListenersInitialized=!0)}};T(v,"instances",new WeakMap),T(v,"stylesInjected",!1),T(v,"globalListenersInitialized",!1),T(v,"instanceCount",0),T(v,"_autoMediaQuery",null),T(v,"_autoMediaListener",null),T(v,"_autoInstances",new Set),T(v,"_globalAutoTheme",!1),T(v,"_globalAutoCustomColors",null);var q=v;q.MarkdownParser=C;q.ShortcutsManager=oe;q.themes={solar:B,cave:$("cave")};q.getTheme=$;q.currentTheme=B;var li=q;var ci="overtype-webcomponent-container",cn="Start typing...",pn=["value","theme","toolbar","height","min-height","max-height","placeholder","font-size","line-height","padding","auto-resize","autofocus","show-stats","smart-lists","readonly","spellcheck"],Oe=class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}),this._editor=null,this._initialized=!1,this._pendingOptions={},this._styleVersion=0,this._baseStyleElement=null,this._selectionChangeHandler=null,this._isConnected=!1,this._handleChange=this._handleChange.bind(this),this._handleKeydown=this._handleKeydown.bind(this)}_decodeValue(e){return typeof e!="string"?"":e.replace(/\\r/g,"\r").replace(/\\n/g,`
|
|
977
|
+
`}_setupAutoResize(){this.container.classList.add("overtype-auto-resize"),this.previousHeight=null,this._updateAutoHeight(),this.textarea.addEventListener("input",()=>this._updateAutoHeight()),window.addEventListener("resize",()=>this._updateAutoHeight())}_updateAutoHeight(){if(!this.options.autoResize)return;let e=this.textarea,t=this.preview,n=this.wrapper,o=window.getComputedStyle(e),r=parseFloat(o.paddingTop),s=parseFloat(o.paddingBottom),a=e.scrollTop;n.style.setProperty("height","auto","important"),e.style.setProperty("height","auto","important");let c=e.scrollHeight;if(this.options.minHeight){let p=parseInt(this.options.minHeight);c=Math.max(c,p)}let d="hidden";if(this.options.maxHeight){let p=parseInt(this.options.maxHeight);c>p&&(c=p,d="auto")}let l=c+"px";e.style.setProperty("height",l,"important"),e.style.setProperty("overflow-y",d,"important"),t.style.setProperty("height",l,"important"),t.style.setProperty("overflow-y",d,"important"),n.style.setProperty("height",l,"important"),e.scrollTop=a,t.scrollTop=a,this.previousHeight!==c&&(this.previousHeight=c)}showStats(e){this.options.showStats=e,e&&!this.statsBar?(this.statsBar=document.createElement("div"),this.statsBar.className="overtype-stats",this.container.appendChild(this.statsBar),this._updateStats()):e&&this.statsBar?this._updateStats():!e&&this.statsBar&&(this.statsBar.remove(),this.statsBar=null)}showNormalEditMode(){return this.container.dataset.mode="normal",this.updatePreview(),requestAnimationFrame(()=>{this.textarea.scrollTop=this.preview.scrollTop,this.textarea.scrollLeft=this.preview.scrollLeft}),this}showPlainTextarea(){if(this.container.dataset.mode="plain",this.toolbar){let e=this.container.querySelector('[data-action="toggle-plain"]');e&&(e.classList.remove("active"),e.title="Show markdown preview")}return this}showPreviewMode(){return this.container.dataset.mode="preview",this.updatePreview(),this}destroy(){if(v._autoInstances.delete(this),v._stopAutoListener(),this.fileUploadInitialized&&this._destroyFileUpload(),this.element.overTypeInstance=null,v.instances.delete(this.element),this.shortcuts&&this.shortcuts.destroy(),this.wrapper){let e=this.getValue();this.wrapper.remove(),this.element.textContent=e}this.initialized=!1}static init(e,t={}){return new v(e,t)}static initFromData(e,t={}){let n=document.querySelectorAll(e);return Array.from(n).map(o=>{let r={...t};for(let s of o.attributes)if(s.name.startsWith("data-ot-")){let c=s.name.slice(8).replace(/-([a-z])/g,(d,l)=>l.toUpperCase());r[c]=v._parseDataValue(s.value)}return new v(o,r)[0]})}static _parseDataValue(e){return e==="true"?!0:e==="false"?!1:e==="null"?null:e!==""&&!isNaN(Number(e))?Number(e):e}static getInstance(e){return e.overTypeInstance||v.instances.get(e)||null}static destroyAll(){document.querySelectorAll("[data-overtype-instance]").forEach(t=>{let n=v.getInstance(t);n&&n.destroy()})}static injectStyles(e=!1){if(v.stylesInjected&&!e)return;let t=document.querySelector("style.overtype-styles");t&&t.remove();let n=v.currentTheme||B,o=ye({theme:n}),r=document.createElement("style");r.className="overtype-styles",r.textContent=o,document.head.appendChild(r),v.stylesInjected=!0}static setTheme(e,t=null){if(v._globalAutoTheme=!1,v._globalAutoCustomColors=null,e==="auto"){v._globalAutoTheme=!0,v._globalAutoCustomColors=t,v._startAutoListener(),v._applyGlobalTheme($e("auto"),t);return}v._stopAutoListener(),v._applyGlobalTheme(e,t)}static _applyGlobalTheme(e,t=null){let n=typeof e=="string"?$(e):e;t&&(n=Qe(n,t)),v.currentTheme=n,v.injectStyles(!0);let o=typeof n=="string"?n:n.name;document.querySelectorAll(".overtype-container").forEach(r=>{o&&r.setAttribute("data-theme",o)}),document.querySelectorAll(".overtype-wrapper").forEach(r=>{r.closest(".overtype-container")||o&&r.setAttribute("data-theme",o);let s=r._instance;s&&s.updatePreview()}),document.querySelectorAll("overtype-editor").forEach(r=>{o&&typeof r.setAttribute=="function"&&r.setAttribute("theme",o),typeof r.refreshTheme=="function"&&r.refreshTheme()})}static _startAutoListener(){v._autoMediaQuery||window.matchMedia&&(v._autoMediaQuery=window.matchMedia("(prefers-color-scheme: dark)"),v._autoMediaListener=e=>{let t=e.matches?"cave":"solar";v._globalAutoTheme&&v._applyGlobalTheme(t,v._globalAutoCustomColors),v._autoInstances.forEach(n=>n._applyResolvedTheme(t))},v._autoMediaQuery.addEventListener("change",v._autoMediaListener))}static _stopAutoListener(){v._autoInstances.size>0||v._globalAutoTheme||v._autoMediaQuery&&(v._autoMediaQuery.removeEventListener("change",v._autoMediaListener),v._autoMediaQuery=null,v._autoMediaListener=null)}static setCodeHighlighter(e){C.setCodeHighlighter(e),document.querySelectorAll(".overtype-wrapper").forEach(t=>{let n=t._instance;n&&n.updatePreview&&n.updatePreview()}),document.querySelectorAll("overtype-editor").forEach(t=>{if(typeof t.getEditor=="function"){let n=t.getEditor();n&&n.updatePreview&&n.updatePreview()}})}static setCustomSyntax(e){C.setCustomSyntax(e),document.querySelectorAll(".overtype-wrapper").forEach(t=>{let n=t._instance;n&&n.updatePreview&&n.updatePreview()}),document.querySelectorAll("overtype-editor").forEach(t=>{if(typeof t.getEditor=="function"){let n=t.getEditor();n&&n.updatePreview&&n.updatePreview()}})}static initGlobalListeners(){v.globalListenersInitialized||(document.addEventListener("input",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let t=e.target.closest(".overtype-wrapper"),n=t==null?void 0:t._instance;n&&n.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"),n=t==null?void 0:t._instance;n&&n.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"),n=t==null?void 0:t._instance;n&&n.handleScroll(e)}},!0),document.addEventListener("selectionchange",e=>{let t=document.activeElement;if(t&&t.classList.contains("overtype-input")){let n=t.closest(".overtype-wrapper"),o=n==null?void 0:n._instance;o&&(o.options.showStats&&o.statsBar&&o._updateStats(),clearTimeout(o._selectionTimeout),o._selectionTimeout=setTimeout(()=>{o.updatePreview()},50))}}),v.globalListenersInitialized=!0)}};T(v,"instances",new WeakMap),T(v,"stylesInjected",!1),T(v,"globalListenersInitialized",!1),T(v,"instanceCount",0),T(v,"_autoMediaQuery",null),T(v,"_autoMediaListener",null),T(v,"_autoInstances",new Set),T(v,"_globalAutoTheme",!1),T(v,"_globalAutoCustomColors",null);var q=v;q.MarkdownParser=C;q.ShortcutsManager=oe;q.themes={solar:B,cave:$("cave")};q.getTheme=$;q.currentTheme=B;var li=q;var ci="overtype-webcomponent-container",cn="Start typing...",pn=["value","theme","toolbar","height","min-height","max-height","placeholder","font-size","line-height","padding","auto-resize","autofocus","show-stats","smart-lists","readonly","spellcheck"],Oe=class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}),this._editor=null,this._initialized=!1,this._pendingOptions={},this._styleVersion=0,this._baseStyleElement=null,this._selectionChangeHandler=null,this._isConnected=!1,this._handleChange=this._handleChange.bind(this),this._handleKeydown=this._handleKeydown.bind(this)}_decodeValue(e){return typeof e!="string"?"":e.replace(/\\r/g,"\r").replace(/\\n/g,`
|
|
978
978
|
`).replace(/\\t/g," ")}static get observedAttributes(){return pn}connectedCallback(){this._isConnected=!0,this._initializeEditor()}disconnectedCallback(){this._isConnected=!1,this._cleanup()}attributeChangedCallback(e,t,n){if(t!==n&&!this._silentUpdate){if(!this._initialized){this._pendingOptions[e]=n;return}this._updateOption(e,n)}}_initializeEditor(){if(!(this._initialized||!this._isConnected))try{let e=document.createElement("div");e.className=ci;let t=this.getAttribute("height"),n=this.getAttribute("min-height"),o=this.getAttribute("max-height");t&&(e.style.height=t),n&&(e.style.minHeight=n),o&&(e.style.maxHeight=o),this._injectStyles(),this.shadowRoot.appendChild(e);let r=this._getOptionsFromAttributes(),s=new li(e,r);this._editor=s[0],this._initialized=!0,this._editor&&this._editor.textarea&&(this._editor.textarea.addEventListener("scroll",()=>{this._editor&&this._editor.preview&&this._editor.textarea&&(this._editor.preview.scrollTop=this._editor.textarea.scrollTop,this._editor.preview.scrollLeft=this._editor.textarea.scrollLeft)}),this._editor.textarea.addEventListener("input",a=>{this._editor&&this._editor.handleInput&&this._editor.handleInput(a)}),this._editor.textarea.addEventListener("keydown",a=>{this._editor&&this._editor.handleKeydown&&this._editor.handleKeydown(a)}),this._selectionChangeHandler=()=>{if(document.activeElement===this){let a=this.shadowRoot.activeElement;a&&a===this._editor.textarea&&(this._editor.options.showStats&&this._editor.statsBar&&this._editor._updateStats(),this._editor.linkTooltip&&this._editor.linkTooltip.checkCursorPosition&&this._editor.linkTooltip.checkCursorPosition())}},document.addEventListener("selectionchange",this._selectionChangeHandler)),this._applyPendingOptions(),this._dispatchEvent("ready",{editor:this._editor})}catch(e){let t=e&&e.message?e.message:String(e);console.warn("OverType Web Component initialization failed:",t),this._dispatchEvent("error",{error:{message:t}})}}_injectStyles(){let e=document.createElement("style"),t=this.getAttribute("theme")||"solar",n=$(t),o=this._getOptionsFromAttributes(),r=ye({...o,theme:n}),s=`
|
|
979
979
|
/* Web Component Host Styles */
|
|
980
980
|
:host {
|
package/dist/overtype.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* OverType v2.3.
|
|
2
|
+
* OverType v2.3.2
|
|
3
3
|
* A lightweight markdown editor library with perfect WYSIWYG alignment
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @author David Miranda
|
|
@@ -884,17 +884,17 @@ var solar = {
|
|
|
884
884
|
// Gray - placeholder text
|
|
885
885
|
},
|
|
886
886
|
previewColors: {
|
|
887
|
-
text: "#
|
|
888
|
-
h1: "
|
|
889
|
-
h2: "
|
|
890
|
-
h3: "
|
|
887
|
+
text: "#0d3b66",
|
|
888
|
+
h1: "inherit",
|
|
889
|
+
h2: "inherit",
|
|
890
|
+
h3: "inherit",
|
|
891
891
|
strong: "inherit",
|
|
892
892
|
em: "inherit",
|
|
893
|
-
link: "#
|
|
894
|
-
code: "#
|
|
895
|
-
codeBg: "rgba(
|
|
896
|
-
blockquote: "#
|
|
897
|
-
hr: "#
|
|
893
|
+
link: "#0d3b66",
|
|
894
|
+
code: "#0d3b66",
|
|
895
|
+
codeBg: "rgba(244, 211, 94, 0.4)",
|
|
896
|
+
blockquote: "#5a7a9b",
|
|
897
|
+
hr: "#5a7a9b",
|
|
898
898
|
bg: "transparent"
|
|
899
899
|
}
|
|
900
900
|
};
|
|
@@ -965,16 +965,16 @@ var cave = {
|
|
|
965
965
|
},
|
|
966
966
|
previewColors: {
|
|
967
967
|
text: "#c5dde8",
|
|
968
|
-
h1: "
|
|
969
|
-
h2: "
|
|
970
|
-
h3: "
|
|
968
|
+
h1: "inherit",
|
|
969
|
+
h2: "inherit",
|
|
970
|
+
h3: "inherit",
|
|
971
971
|
strong: "inherit",
|
|
972
972
|
em: "inherit",
|
|
973
|
-
link: "#
|
|
973
|
+
link: "#9fcfec",
|
|
974
974
|
code: "#c5dde8",
|
|
975
|
-
codeBg: "
|
|
976
|
-
blockquote: "#
|
|
977
|
-
hr: "
|
|
975
|
+
codeBg: "#1a232b",
|
|
976
|
+
blockquote: "#9fcfec",
|
|
977
|
+
hr: "#c5dde8",
|
|
978
978
|
bg: "transparent"
|
|
979
979
|
}
|
|
980
980
|
};
|
|
@@ -1008,7 +1008,7 @@ function themeToCSSVars(colors, previewColors) {
|
|
|
1008
1008
|
if (previewColors) {
|
|
1009
1009
|
for (const [key, value] of Object.entries(previewColors)) {
|
|
1010
1010
|
const varName = key.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
1011
|
-
vars.push(`--preview-${varName}: ${value};`);
|
|
1011
|
+
vars.push(`--preview-${varName}-default: ${value};`);
|
|
1012
1012
|
}
|
|
1013
1013
|
}
|
|
1014
1014
|
return vars.join("\n");
|
|
@@ -1733,17 +1733,17 @@ function generateStyles(options = {}) {
|
|
|
1733
1733
|
|
|
1734
1734
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h1 {
|
|
1735
1735
|
font-size: 2em !important;
|
|
1736
|
-
color: var(--preview-h1,
|
|
1736
|
+
color: var(--preview-h1, var(--preview-h1-default)) !important;
|
|
1737
1737
|
}
|
|
1738
1738
|
|
|
1739
1739
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h2 {
|
|
1740
1740
|
font-size: 1.5em !important;
|
|
1741
|
-
color: var(--preview-h2,
|
|
1741
|
+
color: var(--preview-h2, var(--preview-h2-default)) !important;
|
|
1742
1742
|
}
|
|
1743
1743
|
|
|
1744
1744
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h3 {
|
|
1745
1745
|
font-size: 1.17em !important;
|
|
1746
|
-
color: var(--preview-h3,
|
|
1746
|
+
color: var(--preview-h3, var(--preview-h3-default)) !important;
|
|
1747
1747
|
}
|
|
1748
1748
|
|
|
1749
1749
|
/* Lists - restore list styling in preview mode */
|
|
@@ -1793,14 +1793,14 @@ function generateStyles(options = {}) {
|
|
|
1793
1793
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview a {
|
|
1794
1794
|
pointer-events: auto !important;
|
|
1795
1795
|
cursor: pointer !important;
|
|
1796
|
-
color: var(--preview-link,
|
|
1796
|
+
color: var(--preview-link, var(--preview-link-default)) !important;
|
|
1797
1797
|
text-decoration: underline !important;
|
|
1798
1798
|
}
|
|
1799
1799
|
|
|
1800
1800
|
/* Code blocks - proper pre/code styling in preview mode */
|
|
1801
1801
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview pre.code-block {
|
|
1802
|
-
background: var(--preview-code-bg,
|
|
1803
|
-
color: var(--preview-code,
|
|
1802
|
+
background: var(--preview-code-bg, var(--preview-code-bg-default)) !important;
|
|
1803
|
+
color: var(--preview-code, var(--preview-code-default)) !important;
|
|
1804
1804
|
padding: 1.2em !important;
|
|
1805
1805
|
border-radius: 3px !important;
|
|
1806
1806
|
overflow-x: auto !important;
|
|
@@ -1829,8 +1829,8 @@ function generateStyles(options = {}) {
|
|
|
1829
1829
|
/* Blockquotes - enhanced styling in preview mode */
|
|
1830
1830
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview .blockquote {
|
|
1831
1831
|
display: block !important;
|
|
1832
|
-
border-left: 4px solid var(--preview-blockquote,
|
|
1833
|
-
color: var(--preview-blockquote,
|
|
1832
|
+
border-left: 4px solid var(--preview-blockquote, var(--preview-blockquote-default)) !important;
|
|
1833
|
+
color: var(--preview-blockquote, var(--preview-blockquote-default)) !important;
|
|
1834
1834
|
padding-left: 1em !important;
|
|
1835
1835
|
margin: 1em 0 !important;
|
|
1836
1836
|
font-style: italic !important;
|
|
@@ -1841,16 +1841,16 @@ function generateStyles(options = {}) {
|
|
|
1841
1841
|
font-family: Georgia, 'Times New Roman', serif !important;
|
|
1842
1842
|
font-size: 16px !important;
|
|
1843
1843
|
line-height: 1.8 !important;
|
|
1844
|
-
color: var(--preview-text,
|
|
1845
|
-
background: var(--preview-bg,
|
|
1844
|
+
color: var(--preview-text, var(--preview-text-default)) !important;
|
|
1845
|
+
background: var(--preview-bg, var(--preview-bg-default)) !important;
|
|
1846
1846
|
}
|
|
1847
1847
|
|
|
1848
1848
|
/* Inline code in preview mode - keep monospace */
|
|
1849
1849
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview code {
|
|
1850
1850
|
font-family: ${fontFamily} !important;
|
|
1851
1851
|
font-size: 0.9em !important;
|
|
1852
|
-
background: var(--preview-code-bg,
|
|
1853
|
-
color: var(--preview-code,
|
|
1852
|
+
background: var(--preview-code-bg, var(--preview-code-bg-default)) !important;
|
|
1853
|
+
color: var(--preview-code, var(--preview-code-default)) !important;
|
|
1854
1854
|
padding: 0.2em 0.4em !important;
|
|
1855
1855
|
border-radius: 3px !important;
|
|
1856
1856
|
}
|
|
@@ -1858,18 +1858,18 @@ function generateStyles(options = {}) {
|
|
|
1858
1858
|
/* Strong and em elements in preview mode */
|
|
1859
1859
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview strong {
|
|
1860
1860
|
font-weight: 700 !important;
|
|
1861
|
-
color: var(--preview-strong,
|
|
1861
|
+
color: var(--preview-strong, var(--preview-strong-default)) !important;
|
|
1862
1862
|
}
|
|
1863
1863
|
|
|
1864
1864
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview em {
|
|
1865
1865
|
font-style: italic !important;
|
|
1866
|
-
color: var(--preview-em,
|
|
1866
|
+
color: var(--preview-em, var(--preview-em-default)) !important;
|
|
1867
1867
|
}
|
|
1868
1868
|
|
|
1869
1869
|
/* HR in preview mode */
|
|
1870
1870
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview .hr-marker {
|
|
1871
1871
|
display: block !important;
|
|
1872
|
-
border-top: 2px solid var(--preview-hr,
|
|
1872
|
+
border-top: 2px solid var(--preview-hr, var(--preview-hr-default)) !important;
|
|
1873
1873
|
text-indent: -9999px !important;
|
|
1874
1874
|
height: 2px !important;
|
|
1875
1875
|
}
|
|
@@ -5614,6 +5614,7 @@ var _OverType = class _OverType {
|
|
|
5614
5614
|
const paddingTop = parseFloat(computed.paddingTop);
|
|
5615
5615
|
const paddingBottom = parseFloat(computed.paddingBottom);
|
|
5616
5616
|
const scrollTop = textarea.scrollTop;
|
|
5617
|
+
wrapper.style.setProperty("height", "auto", "important");
|
|
5617
5618
|
textarea.style.setProperty("height", "auto", "important");
|
|
5618
5619
|
let newHeight = textarea.scrollHeight;
|
|
5619
5620
|
if (this.options.minHeight) {
|