overtype 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -3
- package/dist/overtype-webcomponent.esm.js +71 -28
- package/dist/overtype-webcomponent.esm.js.map +2 -2
- package/dist/overtype-webcomponent.js +71 -28
- package/dist/overtype-webcomponent.js.map +2 -2
- package/dist/overtype-webcomponent.min.js +41 -36
- package/dist/overtype.cjs +71 -28
- package/dist/overtype.cjs.map +2 -2
- package/dist/overtype.d.ts +17 -0
- package/dist/overtype.esm.js +71 -28
- package/dist/overtype.esm.js.map +2 -2
- package/dist/overtype.js +71 -28
- package/dist/overtype.js.map +2 -2
- package/dist/overtype.min.js +32 -27
- package/package.json +1 -1
- package/src/overtype.d.ts +17 -0
- package/src/overtype.js +2 -2
- package/src/styles.js +28 -23
- package/src/themes.js +40 -3
package/dist/overtype.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* OverType v2.
|
|
2
|
+
* OverType v2.3.0
|
|
3
3
|
* A lightweight markdown editor library with perfect WYSIWYG alignment
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @author David Miranda
|
|
@@ -12,8 +12,8 @@ var OverType=(()=>{var ve=Object.defineProperty;var cn=Object.getOwnPropertyDesc
|
|
|
12
12
|
`),p=s.slice(3).trim(),h=p?` class="language-${p}"`:"",u=l,f=n||this.codeHighlighter;if(f)try{let g=l.replace(/"/g,'"').replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&"),y=f(g,p);y&&typeof y.then=="function"?console.warn("Async highlighters are not supported in Node.js (non-DOM) context. Use synchronous highlighters for server-side rendering."):y&&typeof y=="string"&&y.trim()&&(u=y)}catch(g){console.warn("Code highlighting failed:",g)}let m=`<div><span class="code-fence">${s}</span></div>`;return m+=`<pre class="code-block"><code${h}>${u}</code></pre>`,m+=`<div><span class="code-fence">${c}</span></div>`,m}),o}static getListContext(e,n){let o=e.split(`
|
|
13
13
|
`),i=0,r=0,s=0;for(let h=0;h<o.length;h++){let u=o[h].length;if(i+u>=n){r=h,s=i;break}i+=u+1}let a=o[r],c=s+a.length,d=a.match(this.LIST_PATTERNS.checkbox);if(d)return{inList:!0,listType:"checkbox",indent:d[1],marker:"-",checked:d[2]==="x",content:d[3],lineStart:s,lineEnd:c,markerEndPos:s+d[1].length+d[2].length+5};let l=a.match(this.LIST_PATTERNS.bullet);if(l)return{inList:!0,listType:"bullet",indent:l[1],marker:l[2],content:l[3],lineStart:s,lineEnd:c,markerEndPos:s+l[1].length+l[2].length+1};let p=a.match(this.LIST_PATTERNS.numbered);return p?{inList:!0,listType:"numbered",indent:p[1],marker:parseInt(p[2]),content:p[3],lineStart:s,lineEnd:c,markerEndPos:s+p[1].length+p[2].length+2}:{inList:!1,listType:null,indent:"",marker:null,content:a,lineStart:s,lineEnd:c,markerEndPos:s}}static createNewListItem(e){switch(e.listType){case"bullet":return`${e.indent}${e.marker} `;case"numbered":return`${e.indent}${e.marker+1}. `;case"checkbox":return`${e.indent}- [ ] `;default:return""}}static renumberLists(e){let n=e.split(`
|
|
14
14
|
`),o=new Map,i=!1;return n.map(s=>{let a=s.match(this.LIST_PATTERNS.numbered);if(a){let c=a[1],d=c.length,l=a[3];i||o.clear();let p=(o.get(d)||0)+1;o.set(d,p);for(let[h]of o)h>d&&o.delete(h);return i=!0,`${c}${p}. ${l}`}else return(s.trim()===""||!s.match(/^\s/))&&(i=!1,o.clear()),s}).join(`
|
|
15
|
-
`)}};C(T,"linkIndex",0),C(T,"codeHighlighter",null),C(T,"customSyntax",null),C(T,"LIST_PATTERNS",{bullet:/^(\s*)([-*+])\s+(.*)$/,numbered:/^(\s*)(\d+)\.\s+(.*)$/,checkbox:/^(\s*)-\s+\[([ x])\]\s+(.*)$/});var re=class{constructor(e){this.editor=e}handleKeydown(e){if(!(navigator.platform.toLowerCase().includes("mac")?e.metaKey:e.ctrlKey))return!1;let i=null;switch(e.key.toLowerCase()){case"b":e.shiftKey||(i="toggleBold");break;case"i":e.shiftKey||(i="toggleItalic");break;case"k":e.shiftKey||(i="insertLink");break;case"7":e.shiftKey&&(i="toggleNumberedList");break;case"8":e.shiftKey&&(i="toggleBulletList");break}return i?(e.preventDefault(),this.editor.performAction(i,e),!0):!1}destroy(){}};var B={name:"solar",colors:{bgPrimary:"#faf0ca",bgSecondary:"#ffffff",text:"#0d3b66",textPrimary:"#0d3b66",textSecondary:"#5a7a9b",h1:"#f95738",h2:"#ee964b",h3:"#3d8a51",strong:"#ee964b",em:"#f95738",del:"#ee964b",link:"#0d3b66",code:"#0d3b66",codeBg:"rgba(244, 211, 94, 0.4)",blockquote:"#5a7a9b",hr:"#5a7a9b",syntaxMarker:"rgba(13, 59, 102, 0.52)",syntax:"#999999",cursor:"#f95738",selection:"rgba(244, 211, 94, 0.4)",listMarker:"#ee964b",rawLine:"#5a7a9b",border:"#e0e0e0",hoverBg:"#f0f0f0",primary:"#0d3b66",toolbarBg:"#ffffff",toolbarIcon:"#0d3b66",toolbarHover:"#f5f5f5",toolbarActive:"#faf0ca",placeholder:"#999999"}},We={name:"cave",colors:{bgPrimary:"#141E26",bgSecondary:"#1D2D3E",text:"#c5dde8",textPrimary:"#c5dde8",textSecondary:"#9fcfec",h1:"#d4a5ff",h2:"#f6ae2d",h3:"#9fcfec",strong:"#f6ae2d",em:"#9fcfec",del:"#f6ae2d",link:"#9fcfec",code:"#c5dde8",codeBg:"#1a232b",blockquote:"#9fcfec",hr:"#c5dde8",syntaxMarker:"rgba(159, 207, 236, 0.73)",syntax:"#7a8c98",cursor:"#f26419",selection:"rgba(51, 101, 138, 0.4)",listMarker:"#f6ae2d",rawLine:"#9fcfec",border:"#2a3f52",hoverBg:"#243546",primary:"#9fcfec",toolbarBg:"#1D2D3E",toolbarIcon:"#c5dde8",toolbarHover:"#243546",toolbarActive:"#2a3f52",placeholder:"#6a7a88"}},qe={solar:B,cave:We,auto:B,light:B,dark:We};function V(t){return typeof t=="string"?{...qe[t]||qe.solar,name:t}:t}function Pe(t){if(t!=="auto")return t;let e=window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)");return e!=null&&e.matches?"cave":"solar"}function Q(t){let
|
|
16
|
-
`)}function Ke(t,e={}){return{...t,colors:{...t.colors,...e}}}function Ze(t={}){let{fontSize:e="14px",lineHeight:n=1.6,fontFamily:o='"SF Mono", SFMono-Regular, Menlo, Monaco, "Cascadia Code", Consolas, "Roboto Mono", "Noto Sans Mono", "Droid Sans Mono", "Ubuntu Mono", "DejaVu Sans Mono", "Liberation Mono", "Courier New", Courier, monospace',padding:i="20px",theme:r=null,mobile:s={}}=t,a=Object.keys(s).length>0?`
|
|
15
|
+
`)}};C(T,"linkIndex",0),C(T,"codeHighlighter",null),C(T,"customSyntax",null),C(T,"LIST_PATTERNS",{bullet:/^(\s*)([-*+])\s+(.*)$/,numbered:/^(\s*)(\d+)\.\s+(.*)$/,checkbox:/^(\s*)-\s+\[([ x])\]\s+(.*)$/});var re=class{constructor(e){this.editor=e}handleKeydown(e){if(!(navigator.platform.toLowerCase().includes("mac")?e.metaKey:e.ctrlKey))return!1;let i=null;switch(e.key.toLowerCase()){case"b":e.shiftKey||(i="toggleBold");break;case"i":e.shiftKey||(i="toggleItalic");break;case"k":e.shiftKey||(i="insertLink");break;case"7":e.shiftKey&&(i="toggleNumberedList");break;case"8":e.shiftKey&&(i="toggleBulletList");break}return i?(e.preventDefault(),this.editor.performAction(i,e),!0):!1}destroy(){}};var B={name:"solar",colors:{bgPrimary:"#faf0ca",bgSecondary:"#ffffff",text:"#0d3b66",textPrimary:"#0d3b66",textSecondary:"#5a7a9b",h1:"#f95738",h2:"#ee964b",h3:"#3d8a51",strong:"#ee964b",em:"#f95738",del:"#ee964b",link:"#0d3b66",code:"#0d3b66",codeBg:"rgba(244, 211, 94, 0.4)",blockquote:"#5a7a9b",hr:"#5a7a9b",syntaxMarker:"rgba(13, 59, 102, 0.52)",syntax:"#999999",cursor:"#f95738",selection:"rgba(244, 211, 94, 0.4)",listMarker:"#ee964b",rawLine:"#5a7a9b",border:"#e0e0e0",hoverBg:"#f0f0f0",primary:"#0d3b66",toolbarBg:"#ffffff",toolbarIcon:"#0d3b66",toolbarHover:"#f5f5f5",toolbarActive:"#faf0ca",placeholder:"#999999"},previewColors:{text:"#1a1a1a",h1:"#1a1a1a",h2:"#2a2a2a",h3:"#3a3a3a",strong:"inherit",em:"inherit",link:"#0066cc",code:"#1a1a1a",codeBg:"rgba(135, 131, 120, 0.15)",blockquote:"#555",hr:"#ddd",bg:"transparent"}},We={name:"cave",colors:{bgPrimary:"#141E26",bgSecondary:"#1D2D3E",text:"#c5dde8",textPrimary:"#c5dde8",textSecondary:"#9fcfec",h1:"#d4a5ff",h2:"#f6ae2d",h3:"#9fcfec",strong:"#f6ae2d",em:"#9fcfec",del:"#f6ae2d",link:"#9fcfec",code:"#c5dde8",codeBg:"#1a232b",blockquote:"#9fcfec",hr:"#c5dde8",syntaxMarker:"rgba(159, 207, 236, 0.73)",syntax:"#7a8c98",cursor:"#f26419",selection:"rgba(51, 101, 138, 0.4)",listMarker:"#f6ae2d",rawLine:"#9fcfec",border:"#2a3f52",hoverBg:"#243546",primary:"#9fcfec",toolbarBg:"#1D2D3E",toolbarIcon:"#c5dde8",toolbarHover:"#243546",toolbarActive:"#2a3f52",placeholder:"#6a7a88"},previewColors:{text:"#c5dde8",h1:"#e0e0e0",h2:"#d0d0d0",h3:"#c0c0c0",strong:"inherit",em:"inherit",link:"#6cb6e0",code:"#c5dde8",codeBg:"rgba(255, 255, 255, 0.08)",blockquote:"#9aa8b4",hr:"rgba(255, 255, 255, 0.15)",bg:"transparent"}},qe={solar:B,cave:We,auto:B,light:B,dark:We};function V(t){return typeof t=="string"?{...qe[t]||qe.solar,name:t}:t}function Pe(t){if(t!=="auto")return t;let e=window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)");return e!=null&&e.matches?"cave":"solar"}function Q(t,e){let n=[];for(let[o,i]of Object.entries(t)){let r=o.replace(/([A-Z])/g,"-$1").toLowerCase();n.push(`--${r}: ${i};`)}if(e)for(let[o,i]of Object.entries(e)){let r=o.replace(/([A-Z])/g,"-$1").toLowerCase();n.push(`--preview-${r}: ${i};`)}return n.join(`
|
|
16
|
+
`)}function Ke(t,e={},n={}){return{...t,colors:{...t.colors,...e},previewColors:{...t.previewColors,...n}}}function Ze(t={}){let{fontSize:e="14px",lineHeight:n=1.6,fontFamily:o='"SF Mono", SFMono-Regular, Menlo, Monaco, "Cascadia Code", Consolas, "Roboto Mono", "Noto Sans Mono", "Droid Sans Mono", "Ubuntu Mono", "DejaVu Sans Mono", "Liberation Mono", "Courier New", Courier, monospace',padding:i="20px",theme:r=null,mobile:s={}}=t,a=Object.keys(s).length>0?`
|
|
17
17
|
@media (max-width: 640px) {
|
|
18
18
|
.overtype-wrapper .overtype-input,
|
|
19
19
|
.overtype-wrapper .overtype-preview {
|
|
@@ -21,7 +21,7 @@ var OverType=(()=>{var ve=Object.defineProperty;var cn=Object.getOwnPropertyDesc
|
|
|
21
21
|
`)}
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
`:"",c=r&&r.colors?Q(r.colors):"";return`
|
|
24
|
+
`:"",c=r&&r.colors?Q(r.colors,r.previewColors):"";return`
|
|
25
25
|
/* OverType Editor Styles */
|
|
26
26
|
|
|
27
27
|
/* Middle-ground CSS Reset - Prevent parent styles from leaking in */
|
|
@@ -692,27 +692,29 @@ var OverType=(()=>{var ve=Object.defineProperty;var cn=Object.getOwnPropertyDesc
|
|
|
692
692
|
}
|
|
693
693
|
|
|
694
694
|
/* Headers - restore proper sizing in preview mode */
|
|
695
|
-
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h1,
|
|
696
|
-
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h2,
|
|
695
|
+
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h1,
|
|
696
|
+
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h2,
|
|
697
697
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h3 {
|
|
698
698
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
|
|
699
699
|
font-weight: 600 !important;
|
|
700
700
|
margin: 0 !important;
|
|
701
701
|
display: block !important;
|
|
702
|
-
|
|
703
|
-
line-height: 1 !important; /* Tight line height for headings */
|
|
702
|
+
line-height: 1 !important;
|
|
704
703
|
}
|
|
705
|
-
|
|
706
|
-
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h1 {
|
|
707
|
-
font-size: 2em !important;
|
|
704
|
+
|
|
705
|
+
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h1 {
|
|
706
|
+
font-size: 2em !important;
|
|
707
|
+
color: var(--preview-h1, #222) !important;
|
|
708
708
|
}
|
|
709
|
-
|
|
710
|
-
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h2 {
|
|
711
|
-
font-size: 1.5em !important;
|
|
709
|
+
|
|
710
|
+
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h2 {
|
|
711
|
+
font-size: 1.5em !important;
|
|
712
|
+
color: var(--preview-h2, #333) !important;
|
|
712
713
|
}
|
|
713
|
-
|
|
714
|
-
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h3 {
|
|
715
|
-
font-size: 1.17em !important;
|
|
714
|
+
|
|
715
|
+
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h3 {
|
|
716
|
+
font-size: 1.17em !important;
|
|
717
|
+
color: var(--preview-h3, #444) !important;
|
|
716
718
|
}
|
|
717
719
|
|
|
718
720
|
/* Lists - restore list styling in preview mode */
|
|
@@ -762,14 +764,14 @@ var OverType=(()=>{var ve=Object.defineProperty;var cn=Object.getOwnPropertyDesc
|
|
|
762
764
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview a {
|
|
763
765
|
pointer-events: auto !important;
|
|
764
766
|
cursor: pointer !important;
|
|
765
|
-
color: var(--link, #0066cc) !important;
|
|
767
|
+
color: var(--preview-link, #0066cc) !important;
|
|
766
768
|
text-decoration: underline !important;
|
|
767
769
|
}
|
|
768
770
|
|
|
769
771
|
/* Code blocks - proper pre/code styling in preview mode */
|
|
770
772
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview pre.code-block {
|
|
771
|
-
background: var(--code-bg, rgba(
|
|
772
|
-
color: var(--code, #
|
|
773
|
+
background: var(--preview-code-bg, rgba(135, 131, 120, 0.15)) !important;
|
|
774
|
+
color: var(--preview-code, #333) !important;
|
|
773
775
|
padding: 1.2em !important;
|
|
774
776
|
border-radius: 3px !important;
|
|
775
777
|
overflow-x: auto !important;
|
|
@@ -798,7 +800,8 @@ var OverType=(()=>{var ve=Object.defineProperty;var cn=Object.getOwnPropertyDesc
|
|
|
798
800
|
/* Blockquotes - enhanced styling in preview mode */
|
|
799
801
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview .blockquote {
|
|
800
802
|
display: block !important;
|
|
801
|
-
border-left: 4px solid var(--blockquote, #
|
|
803
|
+
border-left: 4px solid var(--preview-blockquote, #666) !important;
|
|
804
|
+
color: var(--preview-blockquote, #666) !important;
|
|
802
805
|
padding-left: 1em !important;
|
|
803
806
|
margin: 1em 0 !important;
|
|
804
807
|
font-style: italic !important;
|
|
@@ -809,14 +812,16 @@ var OverType=(()=>{var ve=Object.defineProperty;var cn=Object.getOwnPropertyDesc
|
|
|
809
812
|
font-family: Georgia, 'Times New Roman', serif !important;
|
|
810
813
|
font-size: 16px !important;
|
|
811
814
|
line-height: 1.8 !important;
|
|
812
|
-
color: var(--text, #333) !important;
|
|
815
|
+
color: var(--preview-text, #333) !important;
|
|
816
|
+
background: var(--preview-bg, transparent) !important;
|
|
813
817
|
}
|
|
814
818
|
|
|
815
819
|
/* Inline code in preview mode - keep monospace */
|
|
816
820
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview code {
|
|
817
821
|
font-family: ${o} !important;
|
|
818
822
|
font-size: 0.9em !important;
|
|
819
|
-
background: rgba(135, 131, 120, 0.15) !important;
|
|
823
|
+
background: var(--preview-code-bg, rgba(135, 131, 120, 0.15)) !important;
|
|
824
|
+
color: var(--preview-code, #333) !important;
|
|
820
825
|
padding: 0.2em 0.4em !important;
|
|
821
826
|
border-radius: 3px !important;
|
|
822
827
|
}
|
|
@@ -824,18 +829,18 @@ var OverType=(()=>{var ve=Object.defineProperty;var cn=Object.getOwnPropertyDesc
|
|
|
824
829
|
/* Strong and em elements in preview mode */
|
|
825
830
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview strong {
|
|
826
831
|
font-weight: 700 !important;
|
|
827
|
-
color: inherit !important;
|
|
832
|
+
color: var(--preview-strong, inherit) !important;
|
|
828
833
|
}
|
|
829
834
|
|
|
830
835
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview em {
|
|
831
836
|
font-style: italic !important;
|
|
832
|
-
color: inherit !important;
|
|
837
|
+
color: var(--preview-em, inherit) !important;
|
|
833
838
|
}
|
|
834
839
|
|
|
835
840
|
/* HR in preview mode */
|
|
836
841
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview .hr-marker {
|
|
837
842
|
display: block !important;
|
|
838
|
-
border-top: 2px solid var(--hr, #ddd) !important;
|
|
843
|
+
border-top: 2px solid var(--preview-hr, #ddd) !important;
|
|
839
844
|
text-indent: -9999px !important;
|
|
840
845
|
height: 2px !important;
|
|
841
846
|
}
|
|
@@ -961,7 +966,7 @@ ${a}`:r;if(d){let k=t.value[t.selectionStart-1];t.selectionStart!==0&&k!=null&&!
|
|
|
961
966
|
`+n),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}splitListItem(e,n){let o=e.content.substring(n-e.markerEndPos);this.textarea.setSelectionRange(n,e.lineEnd),document.execCommand("delete");let i=T.createNewListItem(e);document.execCommand("insertText",!1,`
|
|
962
967
|
`+i+o);let r=this.textarea.selectionStart-o.length;this.textarea.setSelectionRange(r,r),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}scheduleNumberedListUpdate(){this.numberUpdateTimeout&&clearTimeout(this.numberUpdateTimeout),this.numberUpdateTimeout=setTimeout(()=>{this.updateNumberedLists()},10)}updateNumberedLists(){let e=this.textarea.value,n=this.textarea.selectionStart,o=T.renumberLists(e);if(o!==e){let i=0,r=e.split(`
|
|
963
968
|
`),s=o.split(`
|
|
964
|
-
`),a=0;for(let d=0;d<r.length&&a<n;d++){if(r[d]!==s[d]){let l=s[d].length-r[d].length;a+r[d].length<n&&(i+=l)}a+=r[d].length+1}this.textarea.value=o;let c=n+i;this.textarea.setSelectionRange(c,c),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}}handleScroll(e){this.preview.scrollTop=this.textarea.scrollTop,this.preview.scrollLeft=this.textarea.scrollLeft}getValue(){return this.textarea.value}setValue(e){this.textarea.value=e,this.updatePreview(),this.options.autoResize&&this._updateAutoHeight()}async performAction(e,n=null){var r;let o=this.textarea;if(!o)return!1;let i=(r=this.actionsById)==null?void 0:r[e];if(!i)return console.warn(`OverType: Unknown action "${e}"`),!1;o.focus();try{return await i({editor:this,getValue:()=>this.getValue(),setValue:s=>this.setValue(s),event:n}),!0}catch(s){return console.error(`OverType: Action "${e}" error:`,s),this.wrapper.dispatchEvent(new CustomEvent("button-error",{detail:{actionId:e,error:s}})),!1}}getRenderedHTML(e={}){let n=this.getValue(),o=T.parse(n,-1,!1,this.options.codeHighlighter);return e.cleanHTML&&(o=o.replace(/<span class="syntax-marker[^"]*">.*?<\/span>/g,""),o=o.replace(/\sclass="(bullet-list|ordered-list|code-fence|hr-marker|blockquote|url-part)"/g,""),o=o.replace(/\sclass=""/g,"")),o}getPreviewHTML(){return this.preview.innerHTML}getCleanHTML(){return this.getRenderedHTML({cleanHTML:!0})}focus(){this.textarea.focus()}blur(){this.textarea.blur()}isInitialized(){return this.initialized}reinit(e={}){var i;let n=(i=this.options)==null?void 0:i.toolbarButtons;this.options=this._mergeOptions({...this.options,...e});let o=this.toolbar&&this.options.toolbar&&ro(n,this.options.toolbarButtons);this._rebuildActionsMap(),o&&(this._cleanupToolbarListeners(),this.toolbar.destroy(),this.toolbar=null,this._createToolbar()),this.fileUploadInitialized&&this._destroyFileUpload(),this.options.fileUpload&&this._initFileUpload(),this._applyOptions(),this.updatePreview()}showToolbar(){this.toolbar?this.toolbar.show():this._createToolbar()}hideToolbar(){this.toolbar&&this.toolbar.hide()}setTheme(e){if(v._autoInstances.delete(this),this.instanceTheme=e,e==="auto")v._autoInstances.add(this),v._startAutoListener(),this._applyResolvedTheme(Pe("auto"));else{let n=typeof e=="string"?V(e):e,o=typeof n=="string"?n:n.name;if(o&&this.container.setAttribute("data-theme",o),n&&n.colors){let i=Q(n.colors);this.container.style.cssText+=i}this.updatePreview()}return v._stopAutoListener(),this}_applyResolvedTheme(e){let n=V(e);this.container.setAttribute("data-theme",e),n&&n.colors&&(this.container.style.cssText=Q(n.colors)),this.updatePreview()}setCodeHighlighter(e){this.options.codeHighlighter=e,this.updatePreview()}_updateStats(){if(!this.statsBar)return;let e=this.textarea.value,n=e.split(`
|
|
969
|
+
`),a=0;for(let d=0;d<r.length&&a<n;d++){if(r[d]!==s[d]){let l=s[d].length-r[d].length;a+r[d].length<n&&(i+=l)}a+=r[d].length+1}this.textarea.value=o;let c=n+i;this.textarea.setSelectionRange(c,c),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}}handleScroll(e){this.preview.scrollTop=this.textarea.scrollTop,this.preview.scrollLeft=this.textarea.scrollLeft}getValue(){return this.textarea.value}setValue(e){this.textarea.value=e,this.updatePreview(),this.options.autoResize&&this._updateAutoHeight()}async performAction(e,n=null){var r;let o=this.textarea;if(!o)return!1;let i=(r=this.actionsById)==null?void 0:r[e];if(!i)return console.warn(`OverType: Unknown action "${e}"`),!1;o.focus();try{return await i({editor:this,getValue:()=>this.getValue(),setValue:s=>this.setValue(s),event:n}),!0}catch(s){return console.error(`OverType: Action "${e}" error:`,s),this.wrapper.dispatchEvent(new CustomEvent("button-error",{detail:{actionId:e,error:s}})),!1}}getRenderedHTML(e={}){let n=this.getValue(),o=T.parse(n,-1,!1,this.options.codeHighlighter);return e.cleanHTML&&(o=o.replace(/<span class="syntax-marker[^"]*">.*?<\/span>/g,""),o=o.replace(/\sclass="(bullet-list|ordered-list|code-fence|hr-marker|blockquote|url-part)"/g,""),o=o.replace(/\sclass=""/g,"")),o}getPreviewHTML(){return this.preview.innerHTML}getCleanHTML(){return this.getRenderedHTML({cleanHTML:!0})}focus(){this.textarea.focus()}blur(){this.textarea.blur()}isInitialized(){return this.initialized}reinit(e={}){var i;let n=(i=this.options)==null?void 0:i.toolbarButtons;this.options=this._mergeOptions({...this.options,...e});let o=this.toolbar&&this.options.toolbar&&ro(n,this.options.toolbarButtons);this._rebuildActionsMap(),o&&(this._cleanupToolbarListeners(),this.toolbar.destroy(),this.toolbar=null,this._createToolbar()),this.fileUploadInitialized&&this._destroyFileUpload(),this.options.fileUpload&&this._initFileUpload(),this._applyOptions(),this.updatePreview()}showToolbar(){this.toolbar?this.toolbar.show():this._createToolbar()}hideToolbar(){this.toolbar&&this.toolbar.hide()}setTheme(e){if(v._autoInstances.delete(this),this.instanceTheme=e,e==="auto")v._autoInstances.add(this),v._startAutoListener(),this._applyResolvedTheme(Pe("auto"));else{let n=typeof e=="string"?V(e):e,o=typeof n=="string"?n:n.name;if(o&&this.container.setAttribute("data-theme",o),n&&n.colors){let i=Q(n.colors,n.previewColors);this.container.style.cssText+=i}this.updatePreview()}return v._stopAutoListener(),this}_applyResolvedTheme(e){let n=V(e);this.container.setAttribute("data-theme",e),n&&n.colors&&(this.container.style.cssText=Q(n.colors,n.previewColors)),this.updatePreview()}setCodeHighlighter(e){this.options.codeHighlighter=e,this.updatePreview()}_updateStats(){if(!this.statsBar)return;let e=this.textarea.value,n=e.split(`
|
|
965
970
|
`),o=e.length,i=e.split(/\s+/).filter(l=>l.length>0).length,r=this.textarea.selectionStart,a=e.substring(0,r).split(`
|
|
966
971
|
`),c=a.length,d=a[a.length-1].length+1;this.options.statsFormatter?this.statsBar.innerHTML=this.options.statsFormatter({chars:o,words:i,lines:n.length,line:c,column:d}):this.statsBar.innerHTML=`
|
|
967
972
|
<div class="overtype-stat">
|
package/package.json
CHANGED
package/src/overtype.d.ts
CHANGED
|
@@ -3,6 +3,21 @@
|
|
|
3
3
|
// Definitions generated from themes.js and styles.js
|
|
4
4
|
// DO NOT EDIT MANUALLY - Run 'npm run generate:types' to regenerate
|
|
5
5
|
|
|
6
|
+
export interface PreviewColors {
|
|
7
|
+
bg?: string;
|
|
8
|
+
blockquote?: string;
|
|
9
|
+
code?: string;
|
|
10
|
+
codeBg?: string;
|
|
11
|
+
em?: string;
|
|
12
|
+
h1?: string;
|
|
13
|
+
h2?: string;
|
|
14
|
+
h3?: string;
|
|
15
|
+
hr?: string;
|
|
16
|
+
link?: string;
|
|
17
|
+
strong?: string;
|
|
18
|
+
text?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
6
21
|
export interface Theme {
|
|
7
22
|
name: string;
|
|
8
23
|
colors: {
|
|
@@ -38,6 +53,7 @@ export interface Theme {
|
|
|
38
53
|
toolbarHover?: string;
|
|
39
54
|
toolbarIcon?: string;
|
|
40
55
|
};
|
|
56
|
+
previewColors?: PreviewColors;
|
|
41
57
|
}
|
|
42
58
|
|
|
43
59
|
export interface Stats {
|
|
@@ -110,6 +126,7 @@ export interface Options {
|
|
|
110
126
|
// Theme (deprecated in favor of global theme)
|
|
111
127
|
theme?: string | Theme;
|
|
112
128
|
colors?: Partial<Theme['colors']>;
|
|
129
|
+
previewColors?: PreviewColors;
|
|
113
130
|
|
|
114
131
|
// File upload
|
|
115
132
|
fileUpload?: {
|
package/src/overtype.js
CHANGED
|
@@ -1223,7 +1223,7 @@ class OverType {
|
|
|
1223
1223
|
}
|
|
1224
1224
|
|
|
1225
1225
|
if (themeObj && themeObj.colors) {
|
|
1226
|
-
const cssVars = themeToCSSVars(themeObj.colors);
|
|
1226
|
+
const cssVars = themeToCSSVars(themeObj.colors, themeObj.previewColors);
|
|
1227
1227
|
this.container.style.cssText += cssVars;
|
|
1228
1228
|
}
|
|
1229
1229
|
|
|
@@ -1239,7 +1239,7 @@ class OverType {
|
|
|
1239
1239
|
this.container.setAttribute('data-theme', themeName);
|
|
1240
1240
|
|
|
1241
1241
|
if (themeObj && themeObj.colors) {
|
|
1242
|
-
this.container.style.cssText = themeToCSSVars(themeObj.colors);
|
|
1242
|
+
this.container.style.cssText = themeToCSSVars(themeObj.colors, themeObj.previewColors);
|
|
1243
1243
|
}
|
|
1244
1244
|
|
|
1245
1245
|
this.updatePreview();
|
package/src/styles.js
CHANGED
|
@@ -37,7 +37,7 @@ export function generateStyles(options = {}) {
|
|
|
37
37
|
` : '';
|
|
38
38
|
|
|
39
39
|
// Generate theme variables if provided
|
|
40
|
-
const themeVars = theme && theme.colors ? themeToCSSVars(theme.colors) : '';
|
|
40
|
+
const themeVars = theme && theme.colors ? themeToCSSVars(theme.colors, theme.previewColors) : '';
|
|
41
41
|
|
|
42
42
|
return `
|
|
43
43
|
/* OverType Editor Styles */
|
|
@@ -710,27 +710,29 @@ export function generateStyles(options = {}) {
|
|
|
710
710
|
}
|
|
711
711
|
|
|
712
712
|
/* Headers - restore proper sizing in preview mode */
|
|
713
|
-
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h1,
|
|
714
|
-
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h2,
|
|
713
|
+
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h1,
|
|
714
|
+
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h2,
|
|
715
715
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h3 {
|
|
716
716
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
|
|
717
717
|
font-weight: 600 !important;
|
|
718
718
|
margin: 0 !important;
|
|
719
719
|
display: block !important;
|
|
720
|
-
|
|
721
|
-
line-height: 1 !important; /* Tight line height for headings */
|
|
720
|
+
line-height: 1 !important;
|
|
722
721
|
}
|
|
723
|
-
|
|
724
|
-
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h1 {
|
|
725
|
-
font-size: 2em !important;
|
|
722
|
+
|
|
723
|
+
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h1 {
|
|
724
|
+
font-size: 2em !important;
|
|
725
|
+
color: var(--preview-h1, #222) !important;
|
|
726
726
|
}
|
|
727
|
-
|
|
728
|
-
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h2 {
|
|
729
|
-
font-size: 1.5em !important;
|
|
727
|
+
|
|
728
|
+
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h2 {
|
|
729
|
+
font-size: 1.5em !important;
|
|
730
|
+
color: var(--preview-h2, #333) !important;
|
|
730
731
|
}
|
|
731
|
-
|
|
732
|
-
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h3 {
|
|
733
|
-
font-size: 1.17em !important;
|
|
732
|
+
|
|
733
|
+
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h3 {
|
|
734
|
+
font-size: 1.17em !important;
|
|
735
|
+
color: var(--preview-h3, #444) !important;
|
|
734
736
|
}
|
|
735
737
|
|
|
736
738
|
/* Lists - restore list styling in preview mode */
|
|
@@ -780,14 +782,14 @@ export function generateStyles(options = {}) {
|
|
|
780
782
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview a {
|
|
781
783
|
pointer-events: auto !important;
|
|
782
784
|
cursor: pointer !important;
|
|
783
|
-
color: var(--link, #0066cc) !important;
|
|
785
|
+
color: var(--preview-link, #0066cc) !important;
|
|
784
786
|
text-decoration: underline !important;
|
|
785
787
|
}
|
|
786
788
|
|
|
787
789
|
/* Code blocks - proper pre/code styling in preview mode */
|
|
788
790
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview pre.code-block {
|
|
789
|
-
background: var(--code-bg, rgba(
|
|
790
|
-
color: var(--code, #
|
|
791
|
+
background: var(--preview-code-bg, rgba(135, 131, 120, 0.15)) !important;
|
|
792
|
+
color: var(--preview-code, #333) !important;
|
|
791
793
|
padding: 1.2em !important;
|
|
792
794
|
border-radius: 3px !important;
|
|
793
795
|
overflow-x: auto !important;
|
|
@@ -816,7 +818,8 @@ export function generateStyles(options = {}) {
|
|
|
816
818
|
/* Blockquotes - enhanced styling in preview mode */
|
|
817
819
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview .blockquote {
|
|
818
820
|
display: block !important;
|
|
819
|
-
border-left: 4px solid var(--blockquote, #
|
|
821
|
+
border-left: 4px solid var(--preview-blockquote, #666) !important;
|
|
822
|
+
color: var(--preview-blockquote, #666) !important;
|
|
820
823
|
padding-left: 1em !important;
|
|
821
824
|
margin: 1em 0 !important;
|
|
822
825
|
font-style: italic !important;
|
|
@@ -827,14 +830,16 @@ export function generateStyles(options = {}) {
|
|
|
827
830
|
font-family: Georgia, 'Times New Roman', serif !important;
|
|
828
831
|
font-size: 16px !important;
|
|
829
832
|
line-height: 1.8 !important;
|
|
830
|
-
color: var(--text, #333) !important;
|
|
833
|
+
color: var(--preview-text, #333) !important;
|
|
834
|
+
background: var(--preview-bg, transparent) !important;
|
|
831
835
|
}
|
|
832
836
|
|
|
833
837
|
/* Inline code in preview mode - keep monospace */
|
|
834
838
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview code {
|
|
835
839
|
font-family: ${fontFamily} !important;
|
|
836
840
|
font-size: 0.9em !important;
|
|
837
|
-
background: rgba(135, 131, 120, 0.15) !important;
|
|
841
|
+
background: var(--preview-code-bg, rgba(135, 131, 120, 0.15)) !important;
|
|
842
|
+
color: var(--preview-code, #333) !important;
|
|
838
843
|
padding: 0.2em 0.4em !important;
|
|
839
844
|
border-radius: 3px !important;
|
|
840
845
|
}
|
|
@@ -842,18 +847,18 @@ export function generateStyles(options = {}) {
|
|
|
842
847
|
/* Strong and em elements in preview mode */
|
|
843
848
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview strong {
|
|
844
849
|
font-weight: 700 !important;
|
|
845
|
-
color: inherit !important;
|
|
850
|
+
color: var(--preview-strong, inherit) !important;
|
|
846
851
|
}
|
|
847
852
|
|
|
848
853
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview em {
|
|
849
854
|
font-style: italic !important;
|
|
850
|
-
color: inherit !important;
|
|
855
|
+
color: var(--preview-em, inherit) !important;
|
|
851
856
|
}
|
|
852
857
|
|
|
853
858
|
/* HR in preview mode */
|
|
854
859
|
.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview .hr-marker {
|
|
855
860
|
display: block !important;
|
|
856
|
-
border-top: 2px solid var(--hr, #ddd) !important;
|
|
861
|
+
border-top: 2px solid var(--preview-hr, #ddd) !important;
|
|
857
862
|
text-indent: -9999px !important;
|
|
858
863
|
height: 2px !important;
|
|
859
864
|
}
|
package/src/themes.js
CHANGED
|
@@ -40,6 +40,20 @@ export const solar = {
|
|
|
40
40
|
toolbarHover: '#f5f5f5', // Light gray - hover background
|
|
41
41
|
toolbarActive: '#faf0ca', // Lemon Chiffon - active button background
|
|
42
42
|
placeholder: '#999999', // Gray - placeholder text
|
|
43
|
+
},
|
|
44
|
+
previewColors: {
|
|
45
|
+
text: '#1a1a1a',
|
|
46
|
+
h1: '#1a1a1a',
|
|
47
|
+
h2: '#2a2a2a',
|
|
48
|
+
h3: '#3a3a3a',
|
|
49
|
+
strong: 'inherit',
|
|
50
|
+
em: 'inherit',
|
|
51
|
+
link: '#0066cc',
|
|
52
|
+
code: '#1a1a1a',
|
|
53
|
+
codeBg: 'rgba(135, 131, 120, 0.15)',
|
|
54
|
+
blockquote: '#555',
|
|
55
|
+
hr: '#ddd',
|
|
56
|
+
bg: 'transparent',
|
|
43
57
|
}
|
|
44
58
|
};
|
|
45
59
|
|
|
@@ -80,6 +94,20 @@ export const cave = {
|
|
|
80
94
|
toolbarHover: '#243546', // Slightly lighter charcoal - hover background
|
|
81
95
|
toolbarActive: '#2a3f52', // Even lighter - active button background
|
|
82
96
|
placeholder: '#6a7a88', // Muted blue-gray - placeholder text
|
|
97
|
+
},
|
|
98
|
+
previewColors: {
|
|
99
|
+
text: '#c5dde8',
|
|
100
|
+
h1: '#e0e0e0',
|
|
101
|
+
h2: '#d0d0d0',
|
|
102
|
+
h3: '#c0c0c0',
|
|
103
|
+
strong: 'inherit',
|
|
104
|
+
em: 'inherit',
|
|
105
|
+
link: '#6cb6e0',
|
|
106
|
+
code: '#c5dde8',
|
|
107
|
+
codeBg: 'rgba(255, 255, 255, 0.08)',
|
|
108
|
+
blockquote: '#9aa8b4',
|
|
109
|
+
hr: 'rgba(255, 255, 255, 0.15)',
|
|
110
|
+
bg: 'transparent',
|
|
83
111
|
}
|
|
84
112
|
};
|
|
85
113
|
|
|
@@ -125,13 +153,18 @@ export function resolveAutoTheme(themeName) {
|
|
|
125
153
|
* @param {Object} colors - Theme colors object
|
|
126
154
|
* @returns {string} CSS custom properties string
|
|
127
155
|
*/
|
|
128
|
-
export function themeToCSSVars(colors) {
|
|
156
|
+
export function themeToCSSVars(colors, previewColors) {
|
|
129
157
|
const vars = [];
|
|
130
158
|
for (const [key, value] of Object.entries(colors)) {
|
|
131
|
-
// Convert camelCase to kebab-case
|
|
132
159
|
const varName = key.replace(/([A-Z])/g, '-$1').toLowerCase();
|
|
133
160
|
vars.push(`--${varName}: ${value};`);
|
|
134
161
|
}
|
|
162
|
+
if (previewColors) {
|
|
163
|
+
for (const [key, value] of Object.entries(previewColors)) {
|
|
164
|
+
const varName = key.replace(/([A-Z])/g, '-$1').toLowerCase();
|
|
165
|
+
vars.push(`--preview-${varName}: ${value};`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
135
168
|
return vars.join('\n');
|
|
136
169
|
}
|
|
137
170
|
|
|
@@ -141,12 +174,16 @@ export function themeToCSSVars(colors) {
|
|
|
141
174
|
* @param {Object} customColors - Custom color overrides
|
|
142
175
|
* @returns {Object} Merged theme object
|
|
143
176
|
*/
|
|
144
|
-
export function mergeTheme(baseTheme, customColors = {}) {
|
|
177
|
+
export function mergeTheme(baseTheme, customColors = {}, customPreviewColors = {}) {
|
|
145
178
|
return {
|
|
146
179
|
...baseTheme,
|
|
147
180
|
colors: {
|
|
148
181
|
...baseTheme.colors,
|
|
149
182
|
...customColors
|
|
183
|
+
},
|
|
184
|
+
previewColors: {
|
|
185
|
+
...baseTheme.previewColors,
|
|
186
|
+
...customPreviewColors
|
|
150
187
|
}
|
|
151
188
|
};
|
|
152
189
|
}
|