@editora/core 1.0.20 → 1.0.21

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.
@@ -1,4 +1,4 @@
1
- (function(wt,xt){typeof exports=="object"&&typeof module!="undefined"?xt(exports):typeof define=="function"&&define.amd?define(["exports"],xt):(wt=typeof globalThis!="undefined"?globalThis:wt||self,xt(wt.EditoraCore={}))})(this,(function(wt){"use strict";class xt{constructor(){this.loadedPlugins=new Map,this.pluginRegistry=new Map}register(e,t){this.pluginRegistry.set(e,t)}async load(e,t){if(this.loadedPlugins.has(e))return this.loadedPlugins.get(e);const n=this.pluginRegistry.get(e);if(!n)return console.warn(`Plugin not found: ${e}`),null;const i=await n();return t&&this.applyPluginConfig(i,t),this.loadedPlugins.set(e,i),i}async loadMultiple(e,t){return(await Promise.all(e.map(i=>this.load(i,t)))).filter(i=>i!==null)}async parsePluginString(e,t){const n=e.split(/\s+/).filter(Boolean);return this.loadMultiple(n,t)}applyPluginConfig(e,t){e.__pluginConfig=t}unload(e){this.loadedPlugins.delete(e)}clear(){this.loadedPlugins.clear()}getLoadedPlugins(){return Array.from(this.loadedPlugins.values())}getRegisteredPluginNames(){return Array.from(this.pluginRegistry.keys())}isLoaded(e){return this.loadedPlugins.has(e)}}class An{constructor(e,t,n){this.doc=e,this.selection=t,this.schema=n}static create(e,t){const n=t||e.node("doc",{},[e.node("paragraph")]);return new An(n,{anchor:0,head:0},e)}apply(e,t){return new An(e,t||this.selection,this.schema)}}class wr{constructor(e,t){this.nodes=new Map(Object.entries(e)),this.marks=new Map(Object.entries(t))}node(e,t,n){return{type:e,attrs:t,content:n}}text(e,t){return{type:"text",text:e,marks:t}}}class xr{constructor(){this.plugins=[],this.pluginConfigs=new Map}register(e,t){this.plugins.push(e),t&&this.pluginConfigs.set(e.name,t);const n=this.pluginConfigs.get(e.name)||e.config;if(e.initialize)try{e.initialize(n)}catch(i){console.error(`Failed to initialize plugin "${e.name}":`,i)}if(e.init&&e.init!==e.initialize)try{e.init(n)}catch(i){console.error(`Failed to run init hook for plugin "${e.name}":`,i)}}unregister(e){const t=this.plugins.findIndex(n=>n.name===e);if(t>-1){const n=this.plugins[t];n.destroy&&n.destroy(),this.plugins.splice(t,1),this.pluginConfigs.delete(e)}}getPlugin(e){return this.plugins.find(t=>t.name===e)}getPluginConfig(e){return this.pluginConfigs.get(e)}buildSchema(){const e={},t={};return this.plugins.forEach(n=>{n.nodes&&Object.assign(e,n.nodes),n.marks&&Object.assign(t,n.marks)}),new wr(e,t)}getCommands(){const e={};return this.plugins.forEach(t=>{t.commands&&Object.assign(e,t.commands)}),e}getToolbarItems(){return this.plugins.flatMap(e=>e.toolbar||[])}async executePluginCommand(e,t,...n){const i=this.getPlugin(e);if(!i)throw new Error(`Plugin not found: ${e}`);const o=this.getPluginConfig(e)||i.config||{},s=o.mode||"local";try{switch(s){case"local":return i.executeLocal?i.executeLocal(t,...n):null;case"api":if(!i.executeAPI)throw new Error(`Plugin ${e} does not support API mode`);return await i.executeAPI(t,...n);case"hybrid":if(i.executeHybrid)return await i.executeHybrid(t,...n);try{if(i.executeAPI)return await i.executeAPI(t,...n)}catch(l){if(console.warn(`API execution failed for ${e}, falling back to local`,l),i.executeLocal&&o.fallbackToLocal!==!1)return i.executeLocal(t,...n);throw l}break;default:throw new Error(`Unknown plugin mode: ${s}`)}}catch(l){throw console.error(`Error executing command ${t} on plugin ${e}:`,l),l}}async destroyAll(){const e=this.plugins.filter(t=>t.destroy).map(t=>t.destroy());await Promise.all(e),this.plugins=[],this.pluginConfigs.clear()}}class Cr{constructor(e={}){this.commands=new Map,Object.entries(e).forEach(([t,n])=>{this.register(t,n)})}register(e,t){this.commands.has(e)&&console.warn(`Command ${e} is being overwritten`),this.commands.set(e,t)}unregister(e){this.commands.delete(e)}get(e){return this.commands.get(e)}has(e){return this.commands.has(e)}getCommandNames(){return Array.from(this.commands.keys())}clear(){this.commands.clear()}}class Ar{constructor(e={}){this.listeners=new Map,this.isReadonly=!1,this.isDestroyed=!1,this.isReadonly=e.readonly||!1,this.pluginManager=new xr,e.plugins&&Array.isArray(e.plugins)&&e.plugins.forEach(n=>this.pluginManager.register(n));const t=this.pluginManager.buildSchema();this.state=An.create(t),this.commandRegistry=new Cr(this.pluginManager.getCommands())}execCommand(e,...t){if(this.isReadonly)return console.warn("Cannot execute commands in readonly mode"),!1;if(this.isDestroyed)return console.warn("Cannot execute commands on destroyed editor"),!1;const n=this.commandRegistry.get(e);if(!n)return console.warn(`Command not found: ${e}`),!1;let i;return t.length===0?i=n(this.state):t.length===1?i=n(this.state,t[0]):i=n(this.state,...t),i instanceof Promise?(i.then(o=>{o&&typeof o=="object"&&"doc"in o&&"selection"in o&&(this.setState(o),this.emit("change",this.state))}).catch(o=>{console.error(`Async command failed: ${e}`,o)}),!0):i&&typeof i=="object"&&"doc"in i&&"selection"in i?(this.setState(i),this.emit("change",this.state),!0):i!==!1&&i!=null}setState(e){this.isDestroyed||(this.state=e,this.emit("stateChange",e))}getState(){return this.state}setReadonly(e){this.isReadonly=e,this.emit("readonlyChange",e)}isReadOnly(){return this.isReadonly}on(e,t){return this.listeners.has(e)||this.listeners.set(e,[]),this.listeners.get(e).push(t),()=>{const n=this.listeners.get(e);if(n){const i=n.indexOf(t);i>-1&&n.splice(i,1)}}}emit(e,...t){const n=this.listeners.get(e);n&&n.forEach(i=>{try{i(...t)}catch(o){console.error(`Error in ${e} handler:`,o)}})}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.listeners.clear(),this.emit("destroy"))}isEditorDestroyed(){return this.isDestroyed}}class kr{constructor(e,t,n){this.overflowUnits=[],this.overflowUnitHomes=new WeakMap,this.expandedOpen=!1,this.onDocumentPointerDownForOverflow=i=>{var s,l;if(!this.expandedOpen)return;const o=i.target;o&&((s=this.moreButton)!=null&&s.contains(o)||(l=this.expandedRow)!=null&&l.contains(o))||this.setExpandedOpen(!1)},this.config=e,this.plugins=t,this.pluginLoader=n}setLastCommandTrigger(e,t){if(typeof window=="undefined"||!e)return;const n=t||e.getAttribute("data-command")||void 0;n&&(window.__editoraLastCommandButton=e,window.__editoraLastCommand=n)}setCommandHandler(e){this.commandHandler=e}parseToolbarString(e){const t=[],n=e.split("|").map(l=>l.trim()),i=this.getAvailableToolbarItems(),o=new Map;i.forEach(l=>{l.command&&o.set(l.command,l),l.type==="group"&&l.label&&o.set(l.label,l)});const s={bold:"toggleBold",italic:"toggleItalic",underline:"toggleUnderline",strikethrough:"toggleStrikethrough",bullist:"toggleBulletList",numlist:"toggleOrderedList",checklist:"toggleChecklist",link:"openLinkDialog",image:"openImageDialog",table:"insertTable",trackChanges:"toggleTrackChanges",acceptTrackChanges:"acceptAllTrackChanges",rejectTrackChanges:"rejectAllTrackChanges",anchor:"insertAnchor",code:"toggleSourceView",blockquote:"toggleBlockquote",undo:"undo",redo:"redo",textColor:"openTextColorPicker",backgroundColor:"openBackgroundColorPicker",fontSize:"fontSize",fontFamily:"setFontFamily",lineHeight:"setLineHeight",heading:"setBlockType",paragraph:"setParagraph",textAlignment:"setTextAlignment",direction:"setDirectionLTR",indent:"increaseIndent",outdent:"decreaseIndent",capitalization:"setCapitalization",math:"insertMath",specialCharacters:"insertSpecialCharacter",emojis:"openEmojiDialog",embedIframe:"openEmbedIframeDialog",fullscreen:"toggleFullscreen",preview:"togglePreview",print:"print",a11yChecker:"toggleA11yChecker",spellCheck:"toggleSpellCheck",comments:"addComment",showHideComments:"toggleComments",toggleComments:"toggleComments",footnote:"insertFootnote",mergeTags:"insertMergeTag",dataBinding:"openDataBindingDialog",dataBindingPreview:"openDataBindingDialog",contentRules:"toggleContentRulesPanel",contentRulesAudit:"runContentRulesAudit",contentRulesRealtime:"toggleContentRulesRealtime",mention:"insertMention",slash:"openSlashCommands",slashCommands:"openSlashCommands",pageBreak:"insertPageBreak",template:"insertTemplate",importWord:"importWord",exportWord:"exportWord",exportPdf:"exportPdf",insertImage:"insertImage",insertVideo:"insertVideo",codeBlock:"insertCodeBlock"};return n.forEach(l=>{const c=[];l.split(/\s+/).filter(Boolean).forEach(u=>{if(u==="direction"){const T=o.get("setDirectionLTR"),b=o.get("setDirectionRTL");T&&c.push({id:"directionLTR",label:T.label,command:T.command,icon:T.icon,type:T.type||"button",options:T.options}),b&&c.push({id:"directionRTL",label:b.label,command:b.command,icon:b.icon,type:b.type||"button",options:b.options});return}if(u==="comments"){const T=o.get("addComment"),b=o.get("toggleComments");T&&c.push({id:"addComment",label:T.label,command:T.command,icon:T.icon,type:T.type||"button",options:T.options}),b&&c.push({id:"toggleComments",label:b.label,command:b.command,icon:b.icon,type:b.type||"button",options:b.options});return}const p=s[u]||u;let g=o.get(p);g||(g=o.get(u)),g&&c.push({id:u,label:g.label,command:g.command,icon:g.icon,type:g.type==="separator"?"separator":g.type||"button",options:g.options,items:g.items})}),c.length>0&&t.push(c)}),t}getAvailableToolbarItems(){return this.plugins.flatMap(t=>t.toolbar||[])}render(e){this.container=e,e.innerHTML="",e.className="editora-toolbar",this.config.sticky&&e.classList.add("editora-toolbar-sticky"),this.config.position&&e.classList.add(`editora-toolbar-${this.config.position}`);const t=document.createElement("div");t.className="editora-toolbar-items-container",this.itemsContainer=t,this.overflowUnits=[];const n=this.config.items||this.getDefaultToolbarString(),i=this.parseToolbarString(n);i.forEach((o,s)=>{const l=document.createElement("div");if(l.className="editora-toolbar-group",o.forEach(c=>{this.appendToolbarButton(l,c);const h=l.lastElementChild;h instanceof HTMLElement&&(this.overflowUnits.push(h),this.overflowUnitHomes.set(h,l))}),t.appendChild(l),s<i.length-1){const c=document.createElement("div");c.className="editora-toolbar-separator",t.appendChild(c)}}),e.appendChild(t),this.setupOverflow(e)}setupOverflow(e){if(!this.itemsContainer||typeof ResizeObserver=="undefined")return;const n=document.createElement("button");n.type="button",n.className="editora-toolbar-more-button",n.title="Show more options",n.setAttribute("aria-label","More toolbar options"),n.textContent="☰",n.style.display="none",n.addEventListener("click",l=>{l.preventDefault(),this.setExpandedOpen(!this.expandedOpen)}),this.moreButton=n,e.appendChild(n);const i=document.createElement("div");i.className="editora-toolbar-expanded-row",this.expandedRow=i,e.appendChild(i),document.addEventListener("mousedown",this.onDocumentPointerDownForOverflow,!0);const o=()=>{const l=this.overflowUnits;if(l.length===0)return;l.forEach(v=>{var w;v.parentElement===i&&((w=this.overflowUnitHomes.get(v))==null||w.appendChild(v))});const c=e.clientWidth,h=16,u=40,p=4,g=Math.max(0,c-h-u-p);let T=0,b=0;for(const v of l){const w=v.getBoundingClientRect().width+p;if(T+w<=g)T+=w,b++;else break}b=Math.max(1,Math.min(b,l.length));const E=b<l.length;n.style.display=E?"":"none",n.classList.toggle("active",E&&this.expandedOpen),!E&&this.expandedOpen&&this.setExpandedOpen(!1),l.forEach((v,w)=>{w>=b&&i.appendChild(v)})},s=()=>{this.overflowRafId!==void 0&&cancelAnimationFrame(this.overflowRafId),this.overflowRafId=requestAnimationFrame(o)};this.resizeObserver=new ResizeObserver(()=>s()),this.resizeObserver.observe(e),s()}setExpandedOpen(e){var t,n;this.expandedOpen=e,(t=this.expandedRow)==null||t.classList.toggle("show",e),(n=this.moreButton)==null||n.classList.toggle("active",e)}appendToolbarButton(e,t){if(t.type==="separator"){const n=document.createElement("div");n.className="editora-toolbar-separator",e.appendChild(n)}else if(t.type==="dropdown"){const n=this.createDropdown(t);e.appendChild(n)}else if(t.type==="inline-menu"){const n=this.createInlineMenu(t);e.appendChild(n)}else if(t.type==="group"&&t.items&&t.items.length){const n=this.createGroupButton(t);e.appendChild(n)}else if(t.type==="input"){const n=this.createInput(t);e.appendChild(n)}else{const n=this.createButton(t);e.appendChild(n)}}createGroupButton(e){const t=document.createElement("div"),n=e.label.toLowerCase().replace(/\s+/g,"-");if(t.className=`editora-toolbar-group-button ${n}`,t.title=e.label,e.icon)if(e.icon.startsWith("<svg")&&e.icon.endsWith("</svg>")){const i=document.createElement("span");i.className="editora-toolbar-icon",i.innerHTML=e.icon,t.appendChild(i)}else t.innerHTML=e.icon;if(e.items&&e.items.length){const i=document.createElement("div");i.className=`editora-toolbar-group-items ${n}`,e.items.forEach(o=>{this.appendToolbarButton(i,o)}),t.appendChild(i)}return t}createInput(e){const t=document.createElement("input");return t.className=`editora-toolbar-input ${e.label.toLowerCase().replace(/\s+/g,"-")}`,t.type="text",t.title=e.label,t.placeholder=e.placeholder||"",e.command&&t.setAttribute("data-command",e.command),e.active&&t.classList.add("active"),e.disabled&&(t.disabled=!0),t.addEventListener("click",n=>{n.preventDefault(),this.setLastCommandTrigger(t,e.command),this.commandHandler&&e.command&&this.commandHandler(e.command)}),t}createButton(e){const t=document.createElement("button");if(t.className="editora-toolbar-button",t.type="button",t.title=e.label,e.command&&t.setAttribute("data-command",e.command),e.icon)if(e.icon.startsWith("<svg")&&e.icon.endsWith("</svg>")){const n=document.createElement("span");n.className="editora-toolbar-icon",n.innerHTML=e.icon,t.appendChild(n)}else t.innerHTML=e.icon;else t.textContent=e.label;return e.active&&t.classList.add("active"),e.disabled&&(t.disabled=!0),t.addEventListener("click",n=>{n.preventDefault(),this.commandHandler&&e.command&&this.commandHandler(e.command)}),t}createDropdown(e){const t=document.createElement("div");t.className="editora-toolbar-dropdown";const n=document.createElement("button");n.className="editora-toolbar-button editora-toolbar-dropdown-trigger",n.type="button",n.textContent=e.label;const i=document.createElement("div");i.className="editora-toolbar-dropdown-menu",i.style.display="none",e.options&&e.options.forEach(l=>{const c=document.createElement("button");c.className="editora-toolbar-dropdown-item",c.type="button",c.textContent=l.label,c.setAttribute("data-value",l.value),c.addEventListener("click",h=>{h.preventDefault(),this.setLastCommandTrigger(n,e.command),this.commandHandler&&e.command&&this.commandHandler(e.command,l.value),i.style.display="none"}),i.appendChild(c)}),n.addEventListener("click",l=>{l.preventDefault(),l.stopPropagation(),this.setLastCommandTrigger(n,e.command);const c=i.style.display==="block";i.style.display=c?"none":"block"});const o=l=>{t.contains(l.target)||(i.style.display="none")},s=l=>{l.key==="Escape"&&(i.style.display="none")};return document.addEventListener("mousedown",o,!0),document.addEventListener("keydown",s),t._cleanupDropdown=()=>{document.removeEventListener("mousedown",o,!0),document.removeEventListener("keydown",s)},t.appendChild(n),t.appendChild(i),t}createInlineMenu(e){const t=document.createElement("div");t.className="editora-toolbar-dropdown editora-toolbar-inline-menu";const n=document.createElement("button");if(n.className="editora-toolbar-button",n.type="button",n.title=e.label,e.icon)if(e.icon.startsWith("<svg")&&e.icon.endsWith("</svg>")){const l=document.createElement("span");l.className="editora-toolbar-icon",l.innerHTML=e.icon,n.appendChild(l)}else n.innerHTML=e.icon;else n.textContent=e.label;const i=document.createElement("div");i.className="editora-toolbar-dropdown-menu",i.style.display="none",e.options&&e.options.forEach(l=>{const c=document.createElement("button");c.className="editora-toolbar-dropdown-item",c.type="button",c.textContent=l.label,c.setAttribute("data-value",l.value),c.addEventListener("click",h=>{h.preventDefault(),h.stopPropagation(),this.setLastCommandTrigger(n,e.command),this.commandHandler&&e.command&&this.commandHandler(e.command,l.value),i.style.display="none"}),i.appendChild(c)}),n.addEventListener("click",l=>{var h;l.preventDefault(),l.stopPropagation(),this.setLastCommandTrigger(n,e.command);const c=(h=this.container)==null?void 0:h.querySelectorAll(".editora-toolbar-dropdown-menu");c==null||c.forEach(u=>{u!==i&&(u.style.display="none")}),i.style.display=i.style.display==="none"?"block":"none"});const o=l=>{t.contains(l.target)||(i.style.display="none")},s=l=>{l.key==="Escape"&&(i.style.display="none")};return document.addEventListener("mousedown",o,!0),document.addEventListener("keydown",s),t._cleanupDropdown=()=>{document.removeEventListener("mousedown",o,!0),document.removeEventListener("keydown",s)},t.appendChild(n),t.appendChild(i),t}getDefaultToolbarString(){return this.getAvailableToolbarItems().map(t=>t.command).join(" ")}updateButtonState(e,t){if(!this.container)return;const n=this.container.querySelector(`[data-command="${e}"]`);n&&(t.active!==void 0&&n.classList.toggle("active",t.active),t.disabled!==void 0&&(n.disabled=t.disabled))}destroy(){var e;this.container&&(this.container.querySelectorAll(".editora-toolbar-dropdown").forEach(n=>{const i=n._cleanupDropdown;i&&i()}),this.container.innerHTML=""),(e=this.resizeObserver)==null||e.disconnect(),this.resizeObserver=void 0,this.overflowRafId!==void 0&&cancelAnimationFrame(this.overflowRafId),document.removeEventListener("mousedown",this.onDocumentPointerDownForOverflow,!0),this.itemsContainer=void 0,this.moreButton=void 0,this.expandedRow=void 0,this.commandHandler=void 0}}class Mr{constructor(e){this.visible=!1,this.config=e}create(e){const t=document.createElement("div");return t.className="editora-floating-toolbar",t.style.display="none",t.style.position="absolute",t.style.zIndex="1000",this.container=t,e.appendChild(t),t}show(e,t){this.container&&(this.container.style.display="block",this.container.style.left=`${e}px`,this.container.style.top=`${t}px`,this.visible=!0)}hide(){this.container&&(this.container.style.display="none",this.visible=!1)}updatePosition(e,t){!this.container||!this.visible||(this.container.style.left=`${e}px`,this.container.style.top=`${t}px`)}isVisible(){return this.visible}destroy(){this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container),this.container=void 0,this.visible=!1}}class Lr{constructor(e={}){this.statusInfo={},this.config=e}create(e){const t=document.createElement("div");return t.className="editora-statusbar",this.config.position&&t.classList.add(`editora-statusbar-${this.config.position}`),this.container=t,e.appendChild(t),t}update(e){this.statusInfo={...this.statusInfo,...e},this.render()}render(){if(!this.container)return;this.container.innerHTML="";const e=document.createElement("div");e.className="editora-statusbar-left";const t=document.createElement("div");t.className="editora-statusbar-right";const n=[];if(this.statusInfo.selectionInfo){const o=this.statusInfo.selectionInfo;o.startLine===o.endLine&&o.startColumn===o.endColumn?n.push(`Ln ${o.startLine}, Col ${o.startColumn}`):(o.startLine===o.endLine?n.push(`Ln ${o.startLine}, Col ${o.startColumn}-${o.endColumn}`):n.push(`Ln ${o.startLine}:${o.startColumn} - ${o.endLine}:${o.endColumn}`),n.push(`${o.selectedChars} chars selected`))}else if(this.statusInfo.cursorPosition){const o=this.statusInfo.cursorPosition;n.push(`Ln ${o.line}, Col ${o.column}`)}this.statusInfo.language&&n.push(this.statusInfo.language);const i=[];this.statusInfo.wordCount!==void 0&&i.push(`${this.statusInfo.wordCount} words`),this.statusInfo.charCount!==void 0&&i.push(`${this.statusInfo.charCount} chars`),this.statusInfo.lineCount!==void 0&&i.push(`${this.statusInfo.lineCount} lines`),this.statusInfo.custom&&Object.entries(this.statusInfo.custom).forEach(([o,s])=>{i.push(`${o}: ${s}`)}),n.forEach((o,s)=>{const l=document.createElement("span");if(l.className="editora-statusbar-item",l.textContent=o,e.appendChild(l),s<n.length-1){const c=document.createElement("span");c.className="editora-statusbar-separator",c.textContent="|",e.appendChild(c)}}),i.forEach((o,s)=>{const l=document.createElement("span");if(l.className="editora-statusbar-item",l.textContent=o,t.appendChild(l),s<i.length-1){const c=document.createElement("span");c.className="editora-statusbar-separator",c.textContent="|",t.appendChild(c)}}),this.container.appendChild(e),this.container.appendChild(t)}destroy(){this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container),this.container=void 0}}function Rr(r,e){const t=r.textContent||"",n=Or(r,e.startContainer,e.startOffset),o=t.substring(0,n).split(`
1
+ (function(wt,xt){typeof exports=="object"&&typeof module!="undefined"?xt(exports):typeof define=="function"&&define.amd?define(["exports"],xt):(wt=typeof globalThis!="undefined"?globalThis:wt||self,xt(wt.EditoraCore={}))})(this,(function(wt){"use strict";class xt{constructor(){this.loadedPlugins=new Map,this.pluginRegistry=new Map}register(e,t){this.pluginRegistry.set(e,t)}async load(e,t){if(this.loadedPlugins.has(e))return this.loadedPlugins.get(e);const n=this.pluginRegistry.get(e);if(!n)return console.warn(`Plugin not found: ${e}`),null;const i=await n();return t&&this.applyPluginConfig(i,t),this.loadedPlugins.set(e,i),i}async loadMultiple(e,t){return(await Promise.all(e.map(i=>this.load(i,t)))).filter(i=>i!==null)}async parsePluginString(e,t){const n=e.split(/\s+/).filter(Boolean);return this.loadMultiple(n,t)}applyPluginConfig(e,t){e.__pluginConfig=t}unload(e){this.loadedPlugins.delete(e)}clear(){this.loadedPlugins.clear()}getLoadedPlugins(){return Array.from(this.loadedPlugins.values())}getRegisteredPluginNames(){return Array.from(this.pluginRegistry.keys())}isLoaded(e){return this.loadedPlugins.has(e)}}class An{constructor(e,t,n){this.doc=e,this.selection=t,this.schema=n}static create(e,t){const n=t||e.node("doc",{},[e.node("paragraph")]);return new An(n,{anchor:0,head:0},e)}apply(e,t){return new An(e,t||this.selection,this.schema)}}class wr{constructor(e,t){this.nodes=new Map(Object.entries(e)),this.marks=new Map(Object.entries(t))}node(e,t,n){return{type:e,attrs:t,content:n}}text(e,t){return{type:"text",text:e,marks:t}}}class xr{constructor(){this.plugins=[],this.pluginConfigs=new Map}register(e,t){this.plugins.push(e),t&&this.pluginConfigs.set(e.name,t);const n=this.pluginConfigs.get(e.name)||e.config;if(e.initialize)try{e.initialize(n)}catch(i){console.error(`Failed to initialize plugin "${e.name}":`,i)}if(e.init&&e.init!==e.initialize)try{e.init(n)}catch(i){console.error(`Failed to run init hook for plugin "${e.name}":`,i)}}unregister(e){const t=this.plugins.findIndex(n=>n.name===e);if(t>-1){const n=this.plugins[t];n.destroy&&n.destroy(),this.plugins.splice(t,1),this.pluginConfigs.delete(e)}}getPlugin(e){return this.plugins.find(t=>t.name===e)}getPluginConfig(e){return this.pluginConfigs.get(e)}buildSchema(){const e={},t={};return this.plugins.forEach(n=>{n.nodes&&Object.assign(e,n.nodes),n.marks&&Object.assign(t,n.marks)}),new wr(e,t)}getCommands(){const e={};return this.plugins.forEach(t=>{t.commands&&Object.assign(e,t.commands)}),e}getToolbarItems(){return this.plugins.flatMap(e=>e.toolbar||[])}async executePluginCommand(e,t,...n){const i=this.getPlugin(e);if(!i)throw new Error(`Plugin not found: ${e}`);const o=this.getPluginConfig(e)||i.config||{},s=o.mode||"local";try{switch(s){case"local":return i.executeLocal?i.executeLocal(t,...n):null;case"api":if(!i.executeAPI)throw new Error(`Plugin ${e} does not support API mode`);return await i.executeAPI(t,...n);case"hybrid":if(i.executeHybrid)return await i.executeHybrid(t,...n);try{if(i.executeAPI)return await i.executeAPI(t,...n)}catch(l){if(console.warn(`API execution failed for ${e}, falling back to local`,l),i.executeLocal&&o.fallbackToLocal!==!1)return i.executeLocal(t,...n);throw l}break;default:throw new Error(`Unknown plugin mode: ${s}`)}}catch(l){throw console.error(`Error executing command ${t} on plugin ${e}:`,l),l}}async destroyAll(){const e=this.plugins.filter(t=>t.destroy).map(t=>t.destroy());await Promise.all(e),this.plugins=[],this.pluginConfigs.clear()}}class Cr{constructor(e={}){this.commands=new Map,Object.entries(e).forEach(([t,n])=>{this.register(t,n)})}register(e,t){this.commands.has(e)&&console.warn(`Command ${e} is being overwritten`),this.commands.set(e,t)}unregister(e){this.commands.delete(e)}get(e){return this.commands.get(e)}has(e){return this.commands.has(e)}getCommandNames(){return Array.from(this.commands.keys())}clear(){this.commands.clear()}}class Ar{constructor(e={}){this.listeners=new Map,this.isReadonly=!1,this.isDestroyed=!1,this.isReadonly=e.readonly||!1,this.pluginManager=new xr,e.plugins&&Array.isArray(e.plugins)&&e.plugins.forEach(n=>this.pluginManager.register(n));const t=this.pluginManager.buildSchema();this.state=An.create(t),this.commandRegistry=new Cr(this.pluginManager.getCommands())}execCommand(e,...t){if(this.isReadonly)return console.warn("Cannot execute commands in readonly mode"),!1;if(this.isDestroyed)return console.warn("Cannot execute commands on destroyed editor"),!1;const n=this.commandRegistry.get(e);if(!n)return console.warn(`Command not found: ${e}`),!1;let i;return t.length===0?i=n(this.state):t.length===1?i=n(this.state,t[0]):i=n(this.state,...t),i instanceof Promise?(i.then(o=>{o&&typeof o=="object"&&"doc"in o&&"selection"in o&&(this.setState(o),this.emit("change",this.state))}).catch(o=>{console.error(`Async command failed: ${e}`,o)}),!0):i&&typeof i=="object"&&"doc"in i&&"selection"in i?(this.setState(i),this.emit("change",this.state),!0):i!==!1&&i!=null}setState(e){this.isDestroyed||(this.state=e,this.emit("stateChange",e))}getState(){return this.state}setReadonly(e){this.isReadonly=e,this.emit("readonlyChange",e)}isReadOnly(){return this.isReadonly}on(e,t){return this.listeners.has(e)||this.listeners.set(e,[]),this.listeners.get(e).push(t),()=>{const n=this.listeners.get(e);if(n){const i=n.indexOf(t);i>-1&&n.splice(i,1)}}}emit(e,...t){const n=this.listeners.get(e);n&&n.forEach(i=>{try{i(...t)}catch(o){console.error(`Error in ${e} handler:`,o)}})}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.listeners.clear(),this.emit("destroy"))}isEditorDestroyed(){return this.isDestroyed}}class kr{constructor(e,t,n){this.overflowUnits=[],this.overflowUnitHomes=new WeakMap,this.expandedOpen=!1,this.onDocumentPointerDownForOverflow=i=>{var s,l;if(!this.expandedOpen)return;const o=i.target;o&&((s=this.moreButton)!=null&&s.contains(o)||(l=this.expandedRow)!=null&&l.contains(o))||this.setExpandedOpen(!1)},this.config=e,this.plugins=t,this.pluginLoader=n}setLastCommandTrigger(e,t){if(typeof window=="undefined"||!e)return;const n=t||e.getAttribute("data-command")||void 0;n&&(window.__editoraLastCommandButton=e,window.__editoraLastCommand=n)}setCommandHandler(e){this.commandHandler=e}parseToolbarString(e){const t=[],n=e.split("|").map(l=>l.trim()),i=this.getAvailableToolbarItems(),o=new Map;i.forEach(l=>{l.command&&o.set(l.command,l),l.type==="group"&&l.label&&o.set(l.label,l)});const s={bold:"toggleBold",italic:"toggleItalic",underline:"toggleUnderline",strikethrough:"toggleStrikethrough",bullist:"toggleBulletList",numlist:"toggleOrderedList",checklist:"toggleChecklist",link:"openLinkDialog",image:"openImageDialog",table:"insertTable",trackChanges:"toggleTrackChanges",acceptTrackChanges:"acceptAllTrackChanges",rejectTrackChanges:"rejectAllTrackChanges",anchor:"insertAnchor",code:"toggleSourceView",blockquote:"toggleBlockquote",undo:"undo",redo:"redo",textColor:"openTextColorPicker",backgroundColor:"openBackgroundColorPicker",fontSize:"fontSize",fontFamily:"setFontFamily",lineHeight:"setLineHeight",heading:"setBlockType",paragraph:"setParagraph",textAlignment:"setTextAlignment",direction:"setDirectionLTR",indent:"increaseIndent",outdent:"decreaseIndent",capitalization:"setCapitalization",math:"insertMath",specialCharacters:"insertSpecialCharacter",emojis:"openEmojiDialog",embedIframe:"openEmbedIframeDialog",fullscreen:"toggleFullscreen",preview:"togglePreview",print:"print",a11yChecker:"toggleA11yChecker",spellCheck:"toggleSpellCheck",comments:"addComment",showHideComments:"toggleComments",toggleComments:"toggleComments",footnote:"insertFootnote",mergeTags:"insertMergeTag",dataBinding:"openDataBindingDialog",dataBindingPreview:"openDataBindingDialog",contentRules:"toggleContentRulesPanel",contentRulesAudit:"runContentRulesAudit",contentRulesRealtime:"toggleContentRulesRealtime",mention:"insertMention",slash:"openSlashCommands",slashCommands:"openSlashCommands",pageBreak:"insertPageBreak",template:"insertTemplate",importWord:"importWord",exportWord:"exportWord",exportPdf:"exportPdf",insertImage:"insertImage",insertVideo:"insertVideo",codeBlock:"insertCodeBlock"};return n.forEach(l=>{const c=[];l.split(/\s+/).filter(Boolean).forEach(u=>{if(u==="direction"){const T=o.get("setDirectionLTR"),b=o.get("setDirectionRTL");T&&c.push({id:"directionLTR",label:T.label,command:T.command,icon:T.icon,type:T.type||"button",options:T.options}),b&&c.push({id:"directionRTL",label:b.label,command:b.command,icon:b.icon,type:b.type||"button",options:b.options});return}if(u==="comments"){const T=o.get("addComment"),b=o.get("toggleComments");T&&c.push({id:"addComment",label:T.label,command:T.command,icon:T.icon,type:T.type||"button",options:T.options}),b&&c.push({id:"toggleComments",label:b.label,command:b.command,icon:b.icon,type:b.type||"button",options:b.options});return}const p=s[u]||u;let g=o.get(p);g||(g=o.get(u)),g&&c.push({id:u,label:g.label,command:g.command,icon:g.icon,type:g.type==="separator"?"separator":g.type||"button",options:g.options,items:g.items})}),c.length>0&&t.push(c)}),t}getAvailableToolbarItems(){return this.plugins.flatMap(t=>t.toolbar||[])}render(e){this.container=e,e.innerHTML="",e.className="editora-toolbar",this.config.sticky&&e.classList.add("editora-toolbar-sticky"),this.config.position&&e.classList.add(`editora-toolbar-${this.config.position}`);const t=document.createElement("div");t.className="editora-toolbar-items-container",this.itemsContainer=t,this.overflowUnits=[];const n=this.config.items||this.getDefaultToolbarString(),i=this.parseToolbarString(n);i.forEach((o,s)=>{const l=document.createElement("div");if(l.className="editora-toolbar-group",o.forEach(c=>{this.appendToolbarButton(l,c);const h=l.lastElementChild;h instanceof HTMLElement&&(this.overflowUnits.push(h),this.overflowUnitHomes.set(h,l))}),t.appendChild(l),s<i.length-1){const c=document.createElement("div");c.className="editora-toolbar-separator",t.appendChild(c)}}),e.appendChild(t),this.setupOverflow(e)}setupOverflow(e){if(!this.itemsContainer||typeof ResizeObserver=="undefined")return;const n=document.createElement("button");n.type="button",n.className="editora-toolbar-more-button",n.title="Show more options",n.setAttribute("aria-label","More toolbar options"),n.textContent="☰",n.style.display="none",n.addEventListener("click",l=>{l.preventDefault(),this.setExpandedOpen(!this.expandedOpen)}),this.moreButton=n,e.appendChild(n);const i=document.createElement("div");i.className="editora-toolbar-expanded-row",this.expandedRow=i,e.appendChild(i),document.addEventListener("mousedown",this.onDocumentPointerDownForOverflow,!0);const o=()=>{const l=this.overflowUnits;if(l.length===0)return;l.forEach(v=>{var w;v.parentElement===i&&((w=this.overflowUnitHomes.get(v))==null||w.appendChild(v))});const c=e.clientWidth,h=16,u=40,p=4,g=Math.max(0,c-h-u-p);let T=0,b=0;for(const v of l){const w=v.getBoundingClientRect().width+p;if(T+w<=g)T+=w,b++;else break}b=Math.max(1,Math.min(b,l.length));const E=b<l.length;n.style.display=E?"":"none",n.classList.toggle("active",E&&this.expandedOpen),!E&&this.expandedOpen&&this.setExpandedOpen(!1),l.forEach((v,w)=>{w>=b&&i.appendChild(v)})},s=()=>{this.overflowRafId!==void 0&&cancelAnimationFrame(this.overflowRafId),this.overflowRafId=requestAnimationFrame(o)};this.resizeObserver=new ResizeObserver(()=>s()),this.resizeObserver.observe(e),s()}setExpandedOpen(e){var t,n;this.expandedOpen=e,(t=this.expandedRow)==null||t.classList.toggle("show",e),(n=this.moreButton)==null||n.classList.toggle("active",e)}appendToolbarButton(e,t){if(t.type==="separator"){const n=document.createElement("div");n.className="editora-toolbar-separator",e.appendChild(n)}else if(t.type==="dropdown"){const n=this.createDropdown(t);e.appendChild(n)}else if(t.type==="inline-menu"){const n=this.createInlineMenu(t);e.appendChild(n)}else if(t.type==="group"&&t.items&&t.items.length){const n=this.createGroupButton(t);e.appendChild(n)}else if(t.type==="input"){const n=this.createInput(t);e.appendChild(n)}else{const n=this.createButton(t);e.appendChild(n)}}createGroupButton(e){const t=document.createElement("div"),n=e.label.toLowerCase().replace(/\s+/g,"-");if(t.className=`editora-toolbar-group-button ${n}`,t.title=e.label,e.icon)if(e.icon.startsWith("<svg")&&e.icon.endsWith("</svg>")){const i=document.createElement("span");i.className="editora-toolbar-icon",i.innerHTML=e.icon,t.appendChild(i)}else t.innerHTML=e.icon;if(e.items&&e.items.length){const i=document.createElement("div");i.className=`editora-toolbar-group-items ${n}`,e.items.forEach(o=>{this.appendToolbarButton(i,o)}),t.appendChild(i)}return t}createInput(e){const t=document.createElement("input");return t.className=`editora-toolbar-input ${e.label.toLowerCase().replace(/\s+/g,"-")}`,t.type="text",t.title=e.label,t.setAttribute("aria-label",e.label),t.placeholder=e.placeholder||"",e.command&&t.setAttribute("data-command",e.command),e.active&&t.classList.add("active"),e.disabled&&(t.disabled=!0),t.addEventListener("click",n=>{n.preventDefault(),this.setLastCommandTrigger(t,e.command),this.commandHandler&&e.command&&this.commandHandler(e.command)}),t}createButton(e){const t=document.createElement("button");if(t.className="editora-toolbar-button",t.type="button",t.title=e.label,e.command&&t.setAttribute("data-command",e.command),e.icon)if(e.icon.startsWith("<svg")&&e.icon.endsWith("</svg>")){const n=document.createElement("span");n.className="editora-toolbar-icon",n.innerHTML=e.icon,t.appendChild(n)}else t.innerHTML=e.icon;else t.textContent=e.label;return e.active&&t.classList.add("active"),e.disabled&&(t.disabled=!0),t.addEventListener("click",n=>{n.preventDefault(),this.commandHandler&&e.command&&this.commandHandler(e.command)}),t}createDropdown(e){const t=document.createElement("div");t.className="editora-toolbar-dropdown";const n=document.createElement("button");n.className="editora-toolbar-button editora-toolbar-dropdown-trigger",n.type="button",n.textContent=e.label;const i=document.createElement("div");i.className="editora-toolbar-dropdown-menu",i.style.display="none",e.options&&e.options.forEach(l=>{const c=document.createElement("button");c.className="editora-toolbar-dropdown-item",c.type="button",c.textContent=l.label,c.setAttribute("data-value",l.value),c.addEventListener("click",h=>{h.preventDefault(),this.setLastCommandTrigger(n,e.command),this.commandHandler&&e.command&&this.commandHandler(e.command,l.value),i.style.display="none"}),i.appendChild(c)}),n.addEventListener("click",l=>{l.preventDefault(),l.stopPropagation(),this.setLastCommandTrigger(n,e.command);const c=i.style.display==="block";i.style.display=c?"none":"block"});const o=l=>{t.contains(l.target)||(i.style.display="none")},s=l=>{l.key==="Escape"&&(i.style.display="none")};return document.addEventListener("mousedown",o,!0),document.addEventListener("keydown",s),t._cleanupDropdown=()=>{document.removeEventListener("mousedown",o,!0),document.removeEventListener("keydown",s)},t.appendChild(n),t.appendChild(i),t}createInlineMenu(e){const t=document.createElement("div");t.className="editora-toolbar-dropdown editora-toolbar-inline-menu";const n=document.createElement("button");if(n.className="editora-toolbar-button",n.type="button",n.title=e.label,e.icon)if(e.icon.startsWith("<svg")&&e.icon.endsWith("</svg>")){const l=document.createElement("span");l.className="editora-toolbar-icon",l.innerHTML=e.icon,n.appendChild(l)}else n.innerHTML=e.icon;else n.textContent=e.label;const i=document.createElement("div");i.className="editora-toolbar-dropdown-menu",i.style.display="none",e.options&&e.options.forEach(l=>{const c=document.createElement("button");c.className="editora-toolbar-dropdown-item",c.type="button",c.textContent=l.label,c.setAttribute("data-value",l.value),c.addEventListener("click",h=>{h.preventDefault(),h.stopPropagation(),this.setLastCommandTrigger(n,e.command),this.commandHandler&&e.command&&this.commandHandler(e.command,l.value),i.style.display="none"}),i.appendChild(c)}),n.addEventListener("click",l=>{var h;l.preventDefault(),l.stopPropagation(),this.setLastCommandTrigger(n,e.command);const c=(h=this.container)==null?void 0:h.querySelectorAll(".editora-toolbar-dropdown-menu");c==null||c.forEach(u=>{u!==i&&(u.style.display="none")}),i.style.display=i.style.display==="none"?"block":"none"});const o=l=>{t.contains(l.target)||(i.style.display="none")},s=l=>{l.key==="Escape"&&(i.style.display="none")};return document.addEventListener("mousedown",o,!0),document.addEventListener("keydown",s),t._cleanupDropdown=()=>{document.removeEventListener("mousedown",o,!0),document.removeEventListener("keydown",s)},t.appendChild(n),t.appendChild(i),t}getDefaultToolbarString(){return this.getAvailableToolbarItems().map(t=>t.command).join(" ")}updateButtonState(e,t){if(!this.container)return;const n=this.container.querySelector(`[data-command="${e}"]`);n&&(t.active!==void 0&&n.classList.toggle("active",t.active),t.disabled!==void 0&&(n.disabled=t.disabled))}destroy(){var e;this.container&&(this.container.querySelectorAll(".editora-toolbar-dropdown").forEach(n=>{const i=n._cleanupDropdown;i&&i()}),this.container.innerHTML=""),(e=this.resizeObserver)==null||e.disconnect(),this.resizeObserver=void 0,this.overflowRafId!==void 0&&cancelAnimationFrame(this.overflowRafId),document.removeEventListener("mousedown",this.onDocumentPointerDownForOverflow,!0),this.itemsContainer=void 0,this.moreButton=void 0,this.expandedRow=void 0,this.commandHandler=void 0}}class Mr{constructor(e){this.visible=!1,this.config=e}create(e){const t=document.createElement("div");return t.className="editora-floating-toolbar",t.style.display="none",t.style.position="absolute",t.style.zIndex="1000",this.container=t,e.appendChild(t),t}show(e,t){this.container&&(this.container.style.display="block",this.container.style.left=`${e}px`,this.container.style.top=`${t}px`,this.visible=!0)}hide(){this.container&&(this.container.style.display="none",this.visible=!1)}updatePosition(e,t){!this.container||!this.visible||(this.container.style.left=`${e}px`,this.container.style.top=`${t}px`)}isVisible(){return this.visible}destroy(){this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container),this.container=void 0,this.visible=!1}}class Lr{constructor(e={}){this.statusInfo={},this.config=e}create(e){const t=document.createElement("div");return t.className="editora-statusbar",this.config.position&&t.classList.add(`editora-statusbar-${this.config.position}`),this.container=t,e.appendChild(t),t}update(e){this.statusInfo={...this.statusInfo,...e},this.render()}render(){if(!this.container)return;this.container.innerHTML="";const e=document.createElement("div");e.className="editora-statusbar-left";const t=document.createElement("div");t.className="editora-statusbar-right";const n=[];if(this.statusInfo.selectionInfo){const o=this.statusInfo.selectionInfo;o.startLine===o.endLine&&o.startColumn===o.endColumn?n.push(`Ln ${o.startLine}, Col ${o.startColumn}`):(o.startLine===o.endLine?n.push(`Ln ${o.startLine}, Col ${o.startColumn}-${o.endColumn}`):n.push(`Ln ${o.startLine}:${o.startColumn} - ${o.endLine}:${o.endColumn}`),n.push(`${o.selectedChars} chars selected`))}else if(this.statusInfo.cursorPosition){const o=this.statusInfo.cursorPosition;n.push(`Ln ${o.line}, Col ${o.column}`)}this.statusInfo.language&&n.push(this.statusInfo.language);const i=[];this.statusInfo.wordCount!==void 0&&i.push(`${this.statusInfo.wordCount} words`),this.statusInfo.charCount!==void 0&&i.push(`${this.statusInfo.charCount} chars`),this.statusInfo.lineCount!==void 0&&i.push(`${this.statusInfo.lineCount} lines`),this.statusInfo.custom&&Object.entries(this.statusInfo.custom).forEach(([o,s])=>{i.push(`${o}: ${s}`)}),n.forEach((o,s)=>{const l=document.createElement("span");if(l.className="editora-statusbar-item",l.textContent=o,e.appendChild(l),s<n.length-1){const c=document.createElement("span");c.className="editora-statusbar-separator",c.textContent="|",e.appendChild(c)}}),i.forEach((o,s)=>{const l=document.createElement("span");if(l.className="editora-statusbar-item",l.textContent=o,t.appendChild(l),s<i.length-1){const c=document.createElement("span");c.className="editora-statusbar-separator",c.textContent="|",t.appendChild(c)}}),this.container.appendChild(e),this.container.appendChild(t)}destroy(){this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container),this.container=void 0}}function Rr(r,e){const t=r.textContent||"",n=Or(r,e.startContainer,e.startOffset),o=t.substring(0,n).split(`
2
2
  `),s=o.length,l=o[o.length-1].length+1;return{line:s,column:l}}function Or(r,e,t){var s;let n=0;const i=document.createTreeWalker(r,NodeFilter.SHOW_TEXT,null);let o=i.firstChild();for(;o;){if(o===e){n+=t;break}else o.nodeType===Node.TEXT_NODE&&(n+=((s=o.textContent)==null?void 0:s.length)||0);o=i.nextNode()}return n}function _r(r){var n,i;const e=r.querySelectorAll("div, p, br, h1, h2, h3, h4, h5, h6, blockquote, li, pre");let t=1;if(e.length>0){t=e.length;const o=e[e.length-1];(o.tagName==="BR"||((n=o.innerHTML)==null?void 0:n.trim())===""||((i=o.textContent)==null?void 0:i.trim())==="")&&t++}else{const s=(r.textContent||"").split(`
3
3
  `).length;t=Math.max(1,s)}return t}function Ir(r){const e=r.trim()?r.trim().split(/\s+/).length:0,t=r.length;return{words:e,chars:t}}function Dr(r,e){const t=r.toString();return{startLine:e.line,startColumn:e.column,endLine:e.line,endColumn:e.column+t.length,selectedChars:t.length,selectedWords:t.trim().split(/\s+/).filter(Boolean).length}}class Nr{constructor(e){this.shortcuts=new Map,this.enabled=!0,this.isMac=typeof navigator!="undefined"&&navigator.platform.toUpperCase().indexOf("MAC")>=0,(e==null?void 0:e.enabled)===!1&&(this.enabled=!1),this.registerDefaultShortcuts(),e!=null&&e.shortcuts&&e.shortcuts.forEach(t=>this.registerShortcut(t)),e!=null&&e.customShortcuts&&Object.values(e.customShortcuts).forEach(t=>{this.registerShortcut(t)})}registerDefaultShortcuts(){this.registerShortcut({key:"b",ctrl:!this.isMac,meta:this.isMac,command:"toggleBold",description:"Bold",preventDefault:!0}),this.registerShortcut({key:"i",ctrl:!this.isMac,meta:this.isMac,command:"toggleItalic",description:"Italic",preventDefault:!0}),this.registerShortcut({key:"u",ctrl:!this.isMac,meta:this.isMac,command:"toggleUnderline",description:"Underline",preventDefault:!0}),this.registerShortcut({key:"d",ctrl:!this.isMac,meta:this.isMac,command:"toggleStrikethrough",description:"Strikethrough",preventDefault:!0}),this.registerShortcut({key:"z",ctrl:!this.isMac,meta:this.isMac,command:"undo",description:"Undo",preventDefault:!0}),this.registerShortcut({key:"z",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"redo",description:"Redo",preventDefault:!0}),this.registerShortcut({key:"y",ctrl:!this.isMac,meta:this.isMac,command:"redo",description:"Redo",preventDefault:!0});for(let e=1;e<=6;e++)this.registerShortcut({key:String(e),ctrl:!this.isMac,meta:this.isMac,alt:!0,command:"setBlockType",params:`h${e}`,description:`Heading ${e}`,preventDefault:!0});this.registerShortcut({key:"7",ctrl:!this.isMac,meta:this.isMac,alt:!0,command:"setBlockType",params:"p",description:"Paragraph",preventDefault:!0}),this.registerShortcut({key:"7",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"toggleOrderedList",description:"Numbered List",preventDefault:!0}),this.registerShortcut({key:"8",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"toggleBulletList",description:"Bullet List",preventDefault:!0}),this.registerShortcut({key:"k",ctrl:!this.isMac,meta:this.isMac,command:"openLinkDialog",description:"Insert/Edit Link",preventDefault:!0}),this.registerShortcut({key:"e",ctrl:!this.isMac,meta:this.isMac,alt:!0,command:"insertCodeBlock",description:"Code Block",preventDefault:!0}),this.registerShortcut({key:"q",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"toggleBlockquote",description:"Blockquote",preventDefault:!0}),this.registerShortcut({key:"l",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"setTextAlignment",params:"left",description:"Align Left",preventDefault:!0}),this.registerShortcut({key:"e",ctrl:!this.isMac,meta:this.isMac,shift:!0,alt:!0,command:"setTextAlignment",params:"center",description:"Align Center",preventDefault:!0}),this.registerShortcut({key:"r",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"setTextAlignment",params:"right",description:"Align Right",preventDefault:!0}),this.registerShortcut({key:"j",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"setTextAlignment",params:"justify",description:"Justify",preventDefault:!0}),this.registerShortcut({key:"\\",ctrl:!this.isMac,meta:this.isMac,command:"clearFormatting",description:"Clear Formatting",preventDefault:!0}),this.registerShortcut({key:"]",ctrl:!this.isMac,meta:this.isMac,command:"increaseIndent",description:"Indent",preventDefault:!0}),this.registerShortcut({key:"[",ctrl:!this.isMac,meta:this.isMac,command:"decreaseIndent",description:"Outdent",preventDefault:!0}),this.registerShortcut({key:"g",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"insertImage",description:"Insert Image",preventDefault:!0}),this.registerShortcut({key:"t",ctrl:!this.isMac,meta:this.isMac,shift:!0,alt:!0,command:"insertTable",description:"Insert Table",preventDefault:!0}),this.registerShortcut({key:"f11",command:"toggleFullscreen",description:"Toggle Fullscreen",preventDefault:!0}),this.registerShortcut({key:"p",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"togglePreview",description:"Preview",preventDefault:!0}),this.registerShortcut({key:"p",ctrl:!this.isMac,meta:this.isMac,command:"print",description:"Print",preventDefault:!0}),this.registerShortcut({key:"s",ctrl:!this.isMac,meta:this.isMac,shift:!0,alt:!0,command:"insertSpecialCharacter",description:"Insert Special Character",preventDefault:!0}),this.registerShortcut({key:"m",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"insertEmoji",description:"Insert Emoji",preventDefault:!0}),this.registerShortcut({key:"9",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"toggleChecklist",description:"Checklist",preventDefault:!0}),this.registerShortcut({key:"a",ctrl:!this.isMac,meta:this.isMac,shift:!0,alt:!0,command:"toggleA11yChecker",description:"Accessibility Checker",preventDefault:!0}),this.registerShortcut({key:"F7",command:"toggleSpellCheck",description:"Spell Check",preventDefault:!0}),this.registerShortcut({key:"m",ctrl:!this.isMac,meta:this.isMac,alt:!0,command:"insertMath",description:"Insert Math",preventDefault:!0}),this.registerShortcut({key:"f",ctrl:!this.isMac,meta:this.isMac,alt:!0,command:"insertFootnote",description:"Insert Footnote",preventDefault:!0})}registerShortcut(e){const t=this.getShortcutKey(e);this.shortcuts.set(t,e)}unregisterShortcut(e){const t=this.getShortcutKey(e);this.shortcuts.delete(t)}getShortcutKey(e){const t=[];return e.ctrl&&t.push("ctrl"),e.alt&&t.push("alt"),e.shift&&t.push("shift"),e.meta&&t.push("meta"),t.push(e.key.toLowerCase()),t.join("+")}getEventKey(e){const t=[];return e.ctrlKey&&t.push("ctrl"),e.altKey&&t.push("alt"),e.shiftKey&&t.push("shift"),e.metaKey&&t.push("meta"),t.push(e.key.toLowerCase()),t.join("+")}handleKeyDown(e,t){if(!this.enabled)return!1;const n=this.getEventKey(e),i=this.shortcuts.get(n);return i?(i.preventDefault!==!1&&(e.preventDefault(),e.stopPropagation()),t(i.command,i.params),!0):!1}enable(){this.enabled=!0}disable(){this.enabled=!1}isEnabled(){return this.enabled}getAllShortcuts(){return Array.from(this.shortcuts.values())}getShortcutForCommand(e){return Array.from(this.shortcuts.values()).find(t=>t.command===e)}getShortcutDescription(e){const t=[];this.isMac?(e.meta&&t.push("⌘"),e.ctrl&&t.push("⌃"),e.alt&&t.push("⌥"),e.shift&&t.push("⇧")):(e.ctrl&&t.push("Ctrl"),e.alt&&t.push("Alt"),e.shift&&t.push("Shift"));const n=e.key.length===1?e.key.toUpperCase():e.key;return t.push(n),t.join("+")}getShortcutsHelp(){const e=this.getAllShortcuts(),t=new Map;e.forEach(i=>{const o=this.getShortcutCategory(i.command);t.has(o)||t.set(o,[]),t.get(o).push(i)});let n=`# Keyboard Shortcuts
4
4
 
@@ -22,7 +22,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
22
22
  `,document.head.appendChild(r)}function Da(r){r.setAttribute("data-rte-dialog",""),Ia(),_a(r)}class oi{constructor(e=""){this._lines=[],this._version=0,this.setText(e)}getLine(e){return this._lines[e]||""}getLines(){return[...this._lines]}getLineCount(){return this._lines.length}getText(){return this._lines.join(`
23
23
  `)}setText(e){this._lines=e.split(`
24
24
  `),this._version++}getTextInRange(e){if(e.start.line===e.end.line)return this.getLine(e.start.line).substring(e.start.column,e.end.column);const t=[];t.push(this.getLine(e.start.line).substring(e.start.column));for(let n=e.start.line+1;n<e.end.line;n++)t.push(this.getLine(n));return e.end.line<this.getLineCount()&&t.push(this.getLine(e.end.line).substring(0,e.end.column)),t.join(`
25
- `)}replaceRange(e,t){const n=this.normalizeRange(e),i=this.getTextInRange(n),o=this.getText(),s=this.positionToOffset(n.start),l=this.positionToOffset(n.end),c=o.slice(0,s)+t+o.slice(l);return this.setText(c),{range:n,text:t,oldText:i}}insertText(e,t){const n={start:e,end:e};return this.replaceRange(n,t)}deleteRange(e){return this.replaceRange(e,"")}positionToOffset(e){let t=0;for(let n=0;n<e.line;n++)t+=this.getLine(n).length+1;return t+=e.column,t}offsetToPosition(e){let t=e;for(let n=0;n<this.getLineCount();n++){const i=this.getLine(n).length;if(t<=i)return{line:n,column:t};t-=i+1}return{line:this.getLineCount()-1,column:this.getLine(this.getLineCount()-1).length}}isValidPosition(e){return!(e.line<0||e.line>=this.getLineCount()||e.column<0||e.column>this.getLine(e.line).length)}isValidRange(e){return this.isValidPosition(e.start)&&this.isValidPosition(e.end)}getVersion(){return this._version}clone(){const e=new oi;return e._lines=[...this._lines],e._version=this._version,e}normalizeRange(e){return this.comparePositions(e.start,e.end)<=0?e:{start:e.end,end:e.start}}comparePositions(e,t){return e.line!==t.line?e.line-t.line:e.column-t.column}}class Na{constructor(e){this.gutterWidth=50,this.gutterFoldColumnWidth=20,this.gutterFoldColumnGap=4,this.gutterLineNumberPaddingLeft=8,this.gutterLineNumberPaddingRight=4,this.gutterDigitWidth=9,this.lineHeight=21,this.trailingNewlineMarkerAttr="data-lce-trailing-newline-marker",this.foldPlaceholderAttr="data-lce-fold-placeholder",this.virtualMarkerRegex=/[\u200B\uE000]/,this.virtualMarkerGlobalRegex=/[\u200B\uE000]/g,this.lastLineCount=0,this.lastHighlightHTML="",this.highlightOverlayActive=!1,this.lastLineDecorationSnapshot="",this.lastGutterDecorationSnapshot="",this.container=e,this.createDOM()}createDOM(){this.container.innerHTML="";const e=document.createElement("div");this.editorContainer=e,e.setAttribute("data-lce-editor-container","true"),e.style.cssText=`
25
+ `)}replaceRange(e,t){const n=this.normalizeRange(e),i=this.getTextInRange(n),o=this.getText(),s=this.positionToOffset(n.start),l=this.positionToOffset(n.end),c=o.slice(0,s)+t+o.slice(l);return this.setText(c),{range:n,text:t,oldText:i}}insertText(e,t){const n={start:e,end:e};return this.replaceRange(n,t)}deleteRange(e){return this.replaceRange(e,"")}positionToOffset(e){let t=0;for(let n=0;n<e.line;n++)t+=this.getLine(n).length+1;return t+=e.column,t}offsetToPosition(e){let t=e;for(let n=0;n<this.getLineCount();n++){const i=this.getLine(n).length;if(t<=i)return{line:n,column:t};t-=i+1}return{line:this.getLineCount()-1,column:this.getLine(this.getLineCount()-1).length}}isValidPosition(e){return!(e.line<0||e.line>=this.getLineCount()||e.column<0||e.column>this.getLine(e.line).length)}isValidRange(e){return this.isValidPosition(e.start)&&this.isValidPosition(e.end)}getVersion(){return this._version}clone(){const e=new oi;return e._lines=[...this._lines],e._version=this._version,e}normalizeRange(e){return this.comparePositions(e.start,e.end)<=0?e:{start:e.end,end:e.start}}comparePositions(e,t){return e.line!==t.line?e.line-t.line:e.column-t.column}}class Na{constructor(e){this.gutterWidth=50,this.gutterFoldColumnWidth=24,this.gutterFoldColumnGap=4,this.gutterLineNumberPaddingLeft=8,this.gutterLineNumberPaddingRight=4,this.gutterDigitWidth=9,this.lineHeight=24,this.trailingNewlineMarkerAttr="data-lce-trailing-newline-marker",this.foldPlaceholderAttr="data-lce-fold-placeholder",this.virtualMarkerRegex=/[\u200B\uE000]/,this.virtualMarkerGlobalRegex=/[\u200B\uE000]/g,this.lastLineCount=0,this.lastHighlightHTML="",this.highlightOverlayActive=!1,this.lastLineDecorationSnapshot="",this.lastGutterDecorationSnapshot="",this.container=e,this.createDOM()}createDOM(){this.container.innerHTML="";const e=document.createElement("div");this.editorContainer=e,e.setAttribute("data-lce-editor-container","true"),e.style.cssText=`
26
26
  position: relative;
27
27
  display: flex;
28
28
  width: 100%;
@@ -209,12 +209,12 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
209
209
  background-color: var(--lce-bracket-match-bg, rgba(86, 156, 214, 0.4));
210
210
  text-decoration: underline solid var(--lce-bracket-match-border, rgba(156, 220, 254, 0.95)) 2px;
211
211
  }
212
- `,document.head.appendChild(e)}getCurrentMatch(){return this.currentMatch}destroy(){var e;if(this.pendingUpdateRaf!==null&&typeof cancelAnimationFrame=="function"&&(cancelAnimationFrame(this.pendingUpdateRaf),this.pendingUpdateRaf=null),this.clearBracketHighlighting(),(e=this.observer)==null||e.disconnect(),this.observer=null,this.editor&&this.cursorHandler&&this.editor.off("cursor",this.cursorHandler),this.editor&&this.changeHandler&&this.editor.off("change",this.changeHandler),typeof document!="undefined"){const t=document.getElementById(this.highlightStyleId);t!=null&&t.parentNode&&t.parentNode.removeChild(t)}this.cursorHandler=null,this.changeHandler=null,this.editor=null}}class ja{constructor(){this.name="code-folding",this.lineHeight=21,this.voidMarkupTags=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),this.nonFoldableInlineMarkupTags=new Set(["a","abbr","b","bdi","bdo","button","cite","code","data","del","dfn","em","i","ins","kbd","label","mark","output","q","ruby","s","samp","small","span","strong","sub","sup","time","u","var"]),this.rawTextMarkupTags=new Set(["script","style","textarea","title"]),this.editor=null,this.foldingUI=null,this.pendingUpdateRaf=null,this.lastSnapshot="",this.lastParsedText=null,this.changeHandler=null,this.foldRegions=[],this.foldSnapshots=new Map,this.isDisplayingFolded=!1,this.cachedLineInfo=null}setup(e){this.editor=e,e.registerCommand("fold",()=>{this.foldAtCursor()}),e.registerCommand("unfold",()=>{this.unfoldAtCursor()}),e.registerCommand("foldAll",()=>{this.foldAll()}),e.registerCommand("unfoldAll",()=>{this.unfoldAll()}),this.changeHandler=()=>{this.syncFoldingState()},e.on("change",this.changeHandler),this.createFoldingUI(),this.syncFoldingState()}onKeyDown(e){}onMouseDown(e){}createFoldingUI(){if(!this.editor)return;const e=this.editor.getView().getLineNumbersElement();e&&(this.foldingUI=document.createElement("div"),this.foldingUI.setAttribute("data-lce-folding-ui","true"),this.foldingUI.style.cssText=`
212
+ `,document.head.appendChild(e)}getCurrentMatch(){return this.currentMatch}destroy(){var e;if(this.pendingUpdateRaf!==null&&typeof cancelAnimationFrame=="function"&&(cancelAnimationFrame(this.pendingUpdateRaf),this.pendingUpdateRaf=null),this.clearBracketHighlighting(),(e=this.observer)==null||e.disconnect(),this.observer=null,this.editor&&this.cursorHandler&&this.editor.off("cursor",this.cursorHandler),this.editor&&this.changeHandler&&this.editor.off("change",this.changeHandler),typeof document!="undefined"){const t=document.getElementById(this.highlightStyleId);t!=null&&t.parentNode&&t.parentNode.removeChild(t)}this.cursorHandler=null,this.changeHandler=null,this.editor=null}}class ja{constructor(){this.name="code-folding",this.lineHeight=24,this.voidMarkupTags=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),this.nonFoldableInlineMarkupTags=new Set(["a","abbr","b","bdi","bdo","button","cite","code","data","del","dfn","em","i","ins","kbd","label","mark","output","q","ruby","s","samp","small","span","strong","sub","sup","time","u","var"]),this.rawTextMarkupTags=new Set(["script","style","textarea","title"]),this.editor=null,this.foldingUI=null,this.pendingUpdateRaf=null,this.lastSnapshot="",this.lastParsedText=null,this.changeHandler=null,this.foldRegions=[],this.foldSnapshots=new Map,this.isDisplayingFolded=!1,this.cachedLineInfo=null}setup(e){this.editor=e,e.registerCommand("fold",()=>{this.foldAtCursor()}),e.registerCommand("unfold",()=>{this.unfoldAtCursor()}),e.registerCommand("foldAll",()=>{this.foldAll()}),e.registerCommand("unfoldAll",()=>{this.unfoldAll()}),this.changeHandler=()=>{this.syncFoldingState()},e.on("change",this.changeHandler),this.createFoldingUI(),this.syncFoldingState()}onKeyDown(e){}onMouseDown(e){}createFoldingUI(){if(!this.editor)return;const e=this.editor.getView().getLineNumbersElement();e&&(this.foldingUI=document.createElement("div"),this.foldingUI.setAttribute("data-lce-folding-ui","true"),this.foldingUI.style.cssText=`
213
213
  position: absolute;
214
214
  right: 0;
215
215
  top: 0;
216
216
  bottom: 0;
217
- width: 20px;
217
+ width: 24px;
218
218
  pointer-events: none;
219
219
  z-index: 3;
220
220
  `,e.appendChild(this.foldingUI))}syncFoldingState(){if(!this.editor)return;const e=this.editor.getValue(),t=this.foldSnapshots;e!==this.lastParsedText&&(this.foldRegions=this.buildFoldRegions(e),this.pruneInvalidFolds(e,t),this.lastParsedText=e),this.hasActiveFolds()?this.applyFoldedDisplay():this.restoreFullDisplay(),this.rememberActiveFoldSnapshots(e),this.scheduleFoldIndicatorUpdate()}scheduleFoldIndicatorUpdate(){this.pendingUpdateRaf===null&&(this.pendingUpdateRaf=requestAnimationFrame(()=>{this.pendingUpdateRaf=null,this.updateFoldIndicators()}))}updateFoldIndicators(){if(!this.editor||!this.foldingUI)return;const e=this.editor.getValue(),t=this.getActiveFolds().map(s=>this.getFoldKey(s)).join("|"),n=`${e}::${t}`;if(n===this.lastSnapshot)return;this.lastSnapshot=n,this.foldingUI.innerHTML="";const i=this.getRenderableActiveFolds(),o=document.createDocumentFragment();for(const s of this.foldRegions){const l=this.toDisplayLine(s,i);if(l===null)continue;const c=this.isFoldActive(s),h=this.createFoldIndicator(s,l,c);o.appendChild(h)}this.foldingUI.appendChild(o)}buildFoldRegions(e){const t=this.buildBracketFoldRegions(e),n=this.shouldIncludeMarkupFolds(e)?this.buildMarkupFoldRegions(e):[];return this.mergeFoldRegions([...t,...n])}buildBracketFoldRegions(e){var l;const t=e.split(`
@@ -222,7 +222,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
222
222
  position: absolute;
223
223
  left: 0;
224
224
  top: ${t*this.lineHeight}px;
225
- width: 20px;
225
+ width: 24px;
226
226
  height: ${this.lineHeight}px;
227
227
  display: flex;
228
228
  align-items: center;
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./index-Cdy6TOCy.js");exports.RichTextEditorElement=e.RichTextEditorElement;exports.initWebComponent=e.initWebComponent;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./index-Ct3Aik7_.js");exports.RichTextEditorElement=e.RichTextEditorElement;exports.initWebComponent=e.initWebComponent;
2
2
  //# sourceMappingURL=webcomponent.cjs.js.map
@@ -1,4 +1,4 @@
1
- import { R as t, o as i } from "./index-BxlbmLsp.mjs";
1
+ import { R as t, o as i } from "./index-6i4_TH66.mjs";
2
2
  export {
3
3
  t as RichTextEditorElement,
4
4
  i as initWebComponent
@@ -574,7 +574,7 @@ class pn {
574
574
  */
575
575
  createInput(t) {
576
576
  const e = document.createElement("input");
577
- return e.className = `editora-toolbar-input ${t.label.toLowerCase().replace(/\s+/g, "-")}`, e.type = "text", e.title = t.label, e.placeholder = t.placeholder || "", t.command && e.setAttribute("data-command", t.command), t.active && e.classList.add("active"), t.disabled && (e.disabled = !0), e.addEventListener("click", (n) => {
577
+ return e.className = `editora-toolbar-input ${t.label.toLowerCase().replace(/\s+/g, "-")}`, e.type = "text", e.title = t.label, e.setAttribute("aria-label", t.label), e.placeholder = t.placeholder || "", t.command && e.setAttribute("data-command", t.command), t.active && e.classList.add("active"), t.disabled && (e.disabled = !0), e.addEventListener("click", (n) => {
578
578
  n.preventDefault(), this.setLastCommandTrigger(e, t.command), this.commandHandler && t.command && this.commandHandler(t.command);
579
579
  }), e;
580
580
  }
@@ -3919,7 +3919,7 @@ const yi = {
3919
3919
  clearFormatting: () => import("./ClearFormattingPlugin.native-Pp0O-SBf.mjs").then((o) => o.ClearFormattingPlugin()),
3920
3920
  heading: () => import("./HeadingPlugin.native-DZdvubrQ.mjs").then((o) => o.HeadingPlugin()),
3921
3921
  blockquote: () => import("./BlockquotePlugin.native-D8jjGd0c.mjs").then((o) => o.BlockquotePlugin()),
3922
- code: () => import("./CodePlugin.native-BcVqm5MS.mjs").then((o) => o.CodePlugin()),
3922
+ code: () => import("./CodePlugin.native-AoJ_idGz.mjs").then((o) => o.CodePlugin()),
3923
3923
  codeSample: () => import("./CodeSamplePlugin.native-svbAFWh_.mjs").then((o) => o.CodeSamplePlugin()),
3924
3924
  list: () => import("./ListPlugin.native-Bt0LANbO.mjs").then((o) => o.ListPlugin()),
3925
3925
  checklist: () => import("./ChecklistPlugin.native-DLedNLsb.mjs").then((o) => o.ChecklistPlugin()),
@@ -1,4 +1,4 @@
1
- (function(Xa,Ya){typeof exports=="object"&&typeof module!="undefined"?Ya(exports):typeof define=="function"&&define.amd?define(["exports"],Ya):(Xa=typeof globalThis!="undefined"?globalThis:Xa||self,Ya(Xa.Editora={}))})(this,(function(Xa){"use strict";var JLe=Object.defineProperty;var eFe=(Xa,Ya,AA)=>Ya in Xa?JLe(Xa,Ya,{enumerable:!0,configurable:!0,writable:!0,value:AA}):Xa[Ya]=AA;var Gk=(Xa,Ya,AA)=>eFe(Xa,typeof Ya!="symbol"?Ya+"":Ya,AA);function Ya(t,e){for(var n=0;n<e.length;n++){const r=e[n];if(typeof r!="string"&&!Array.isArray(r)){for(const i in r)if(i!=="default"&&!(i in t)){const o=Object.getOwnPropertyDescriptor(r,i);o&&Object.defineProperty(t,i,o.get?o:{enumerable:!0,get:()=>r[i]})}}}return Object.freeze(Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}))}class AA{constructor(){this.loadedPlugins=new Map,this.pluginRegistry=new Map}register(e,n){this.pluginRegistry.set(e,n)}async load(e,n){if(this.loadedPlugins.has(e))return this.loadedPlugins.get(e);const r=this.pluginRegistry.get(e);if(!r)return console.warn(`Plugin not found: ${e}`),null;const i=await r();return n&&this.applyPluginConfig(i,n),this.loadedPlugins.set(e,i),i}async loadMultiple(e,n){return(await Promise.all(e.map(i=>this.load(i,n)))).filter(i=>i!==null)}async parsePluginString(e,n){const r=e.split(/\s+/).filter(Boolean);return this.loadMultiple(r,n)}applyPluginConfig(e,n){e.__pluginConfig=n}unload(e){this.loadedPlugins.delete(e)}clear(){this.loadedPlugins.clear()}getLoadedPlugins(){return Array.from(this.loadedPlugins.values())}getRegisteredPluginNames(){return Array.from(this.pluginRegistry.keys())}isLoaded(e){return this.loadedPlugins.has(e)}}class Uv{constructor(e,n,r){this.doc=e,this.selection=n,this.schema=r}static create(e,n){const r=n||e.node("doc",{},[e.node("paragraph")]);return new Uv(r,{anchor:0,head:0},e)}apply(e,n){return new Uv(e,n||this.selection,this.schema)}}let Sne=class{constructor(e,n){this.nodes=new Map(Object.entries(e)),this.marks=new Map(Object.entries(n))}node(e,n,r){return{type:e,attrs:n,content:r}}text(e,n){return{type:"text",text:e,marks:n}}};class _ne{constructor(){this.plugins=[],this.pluginConfigs=new Map}register(e,n){this.plugins.push(e),n&&this.pluginConfigs.set(e.name,n);const r=this.pluginConfigs.get(e.name)||e.config;if(e.initialize)try{e.initialize(r)}catch(i){console.error(`Failed to initialize plugin "${e.name}":`,i)}if(e.init&&e.init!==e.initialize)try{e.init(r)}catch(i){console.error(`Failed to run init hook for plugin "${e.name}":`,i)}}unregister(e){const n=this.plugins.findIndex(r=>r.name===e);if(n>-1){const r=this.plugins[n];r.destroy&&r.destroy(),this.plugins.splice(n,1),this.pluginConfigs.delete(e)}}getPlugin(e){return this.plugins.find(n=>n.name===e)}getPluginConfig(e){return this.pluginConfigs.get(e)}buildSchema(){const e={},n={};return this.plugins.forEach(r=>{r.nodes&&Object.assign(e,r.nodes),r.marks&&Object.assign(n,r.marks)}),new Sne(e,n)}getCommands(){const e={};return this.plugins.forEach(n=>{n.commands&&Object.assign(e,n.commands)}),e}getToolbarItems(){return this.plugins.flatMap(e=>e.toolbar||[])}async executePluginCommand(e,n,...r){const i=this.getPlugin(e);if(!i)throw new Error(`Plugin not found: ${e}`);const o=this.getPluginConfig(e)||i.config||{},a=o.mode||"local";try{switch(a){case"local":return i.executeLocal?i.executeLocal(n,...r):null;case"api":if(!i.executeAPI)throw new Error(`Plugin ${e} does not support API mode`);return await i.executeAPI(n,...r);case"hybrid":if(i.executeHybrid)return await i.executeHybrid(n,...r);try{if(i.executeAPI)return await i.executeAPI(n,...r)}catch(s){if(console.warn(`API execution failed for ${e}, falling back to local`,s),i.executeLocal&&o.fallbackToLocal!==!1)return i.executeLocal(n,...r);throw s}break;default:throw new Error(`Unknown plugin mode: ${a}`)}}catch(s){throw console.error(`Error executing command ${n} on plugin ${e}:`,s),s}}async destroyAll(){const e=this.plugins.filter(n=>n.destroy).map(n=>n.destroy());await Promise.all(e),this.plugins=[],this.pluginConfigs.clear()}}class Dne{constructor(e={}){this.commands=new Map,Object.entries(e).forEach(([n,r])=>{this.register(n,r)})}register(e,n){this.commands.has(e)&&console.warn(`Command ${e} is being overwritten`),this.commands.set(e,n)}unregister(e){this.commands.delete(e)}get(e){return this.commands.get(e)}has(e){return this.commands.has(e)}getCommandNames(){return Array.from(this.commands.keys())}clear(){this.commands.clear()}}class Lne{constructor(e={}){this.listeners=new Map,this.isReadonly=!1,this.isDestroyed=!1,this.isReadonly=e.readonly||!1,this.pluginManager=new _ne,e.plugins&&Array.isArray(e.plugins)&&e.plugins.forEach(r=>this.pluginManager.register(r));const n=this.pluginManager.buildSchema();this.state=Uv.create(n),this.commandRegistry=new Dne(this.pluginManager.getCommands())}execCommand(e,...n){if(this.isReadonly)return console.warn("Cannot execute commands in readonly mode"),!1;if(this.isDestroyed)return console.warn("Cannot execute commands on destroyed editor"),!1;const r=this.commandRegistry.get(e);if(!r)return console.warn(`Command not found: ${e}`),!1;let i;return n.length===0?i=r(this.state):n.length===1?i=r(this.state,n[0]):i=r(this.state,...n),i instanceof Promise?(i.then(o=>{o&&typeof o=="object"&&"doc"in o&&"selection"in o&&(this.setState(o),this.emit("change",this.state))}).catch(o=>{console.error(`Async command failed: ${e}`,o)}),!0):i&&typeof i=="object"&&"doc"in i&&"selection"in i?(this.setState(i),this.emit("change",this.state),!0):i!==!1&&i!=null}setState(e){this.isDestroyed||(this.state=e,this.emit("stateChange",e))}getState(){return this.state}setReadonly(e){this.isReadonly=e,this.emit("readonlyChange",e)}isReadOnly(){return this.isReadonly}on(e,n){return this.listeners.has(e)||this.listeners.set(e,[]),this.listeners.get(e).push(n),()=>{const r=this.listeners.get(e);if(r){const i=r.indexOf(n);i>-1&&r.splice(i,1)}}}emit(e,...n){const r=this.listeners.get(e);r&&r.forEach(i=>{try{i(...n)}catch(o){console.error(`Error in ${e} handler:`,o)}})}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.listeners.clear(),this.emit("destroy"))}isEditorDestroyed(){return this.isDestroyed}}class Fne{constructor(e,n,r){this.overflowUnits=[],this.overflowUnitHomes=new WeakMap,this.expandedOpen=!1,this.onDocumentPointerDownForOverflow=i=>{var a,s;if(!this.expandedOpen)return;const o=i.target;o&&((a=this.moreButton)!=null&&a.contains(o)||(s=this.expandedRow)!=null&&s.contains(o))||this.setExpandedOpen(!1)},this.config=e,this.plugins=n,this.pluginLoader=r}setLastCommandTrigger(e,n){if(typeof window=="undefined"||!e)return;const r=n||e.getAttribute("data-command")||void 0;r&&(window.__editoraLastCommandButton=e,window.__editoraLastCommand=r)}setCommandHandler(e){this.commandHandler=e}parseToolbarString(e){const n=[],r=e.split("|").map(s=>s.trim()),i=this.getAvailableToolbarItems(),o=new Map;i.forEach(s=>{s.command&&o.set(s.command,s),s.type==="group"&&s.label&&o.set(s.label,s)});const a={bold:"toggleBold",italic:"toggleItalic",underline:"toggleUnderline",strikethrough:"toggleStrikethrough",bullist:"toggleBulletList",numlist:"toggleOrderedList",checklist:"toggleChecklist",link:"openLinkDialog",image:"openImageDialog",table:"insertTable",trackChanges:"toggleTrackChanges",acceptTrackChanges:"acceptAllTrackChanges",rejectTrackChanges:"rejectAllTrackChanges",anchor:"insertAnchor",code:"toggleSourceView",blockquote:"toggleBlockquote",undo:"undo",redo:"redo",textColor:"openTextColorPicker",backgroundColor:"openBackgroundColorPicker",fontSize:"fontSize",fontFamily:"setFontFamily",lineHeight:"setLineHeight",heading:"setBlockType",paragraph:"setParagraph",textAlignment:"setTextAlignment",direction:"setDirectionLTR",indent:"increaseIndent",outdent:"decreaseIndent",capitalization:"setCapitalization",math:"insertMath",specialCharacters:"insertSpecialCharacter",emojis:"openEmojiDialog",embedIframe:"openEmbedIframeDialog",fullscreen:"toggleFullscreen",preview:"togglePreview",print:"print",a11yChecker:"toggleA11yChecker",spellCheck:"toggleSpellCheck",comments:"addComment",showHideComments:"toggleComments",toggleComments:"toggleComments",footnote:"insertFootnote",mergeTags:"insertMergeTag",dataBinding:"openDataBindingDialog",dataBindingPreview:"openDataBindingDialog",contentRules:"toggleContentRulesPanel",contentRulesAudit:"runContentRulesAudit",contentRulesRealtime:"toggleContentRulesRealtime",mention:"insertMention",slash:"openSlashCommands",slashCommands:"openSlashCommands",pageBreak:"insertPageBreak",template:"insertTemplate",importWord:"importWord",exportWord:"exportWord",exportPdf:"exportPdf",insertImage:"insertImage",insertVideo:"insertVideo",codeBlock:"insertCodeBlock"};return r.forEach(s=>{const c=[];s.split(/\s+/).filter(Boolean).forEach(u=>{if(u==="direction"){const A=o.get("setDirectionLTR"),h=o.get("setDirectionRTL");A&&c.push({id:"directionLTR",label:A.label,command:A.command,icon:A.icon,type:A.type||"button",options:A.options}),h&&c.push({id:"directionRTL",label:h.label,command:h.command,icon:h.icon,type:h.type||"button",options:h.options});return}if(u==="comments"){const A=o.get("addComment"),h=o.get("toggleComments");A&&c.push({id:"addComment",label:A.label,command:A.command,icon:A.icon,type:A.type||"button",options:A.options}),h&&c.push({id:"toggleComments",label:h.label,command:h.command,icon:h.icon,type:h.type||"button",options:h.options});return}const d=a[u]||u;let f=o.get(d);f||(f=o.get(u)),f&&c.push({id:u,label:f.label,command:f.command,icon:f.icon,type:f.type==="separator"?"separator":f.type||"button",options:f.options,items:f.items})}),c.length>0&&n.push(c)}),n}getAvailableToolbarItems(){return this.plugins.flatMap(n=>n.toolbar||[])}render(e){this.container=e,e.innerHTML="",e.className="editora-toolbar",this.config.sticky&&e.classList.add("editora-toolbar-sticky"),this.config.position&&e.classList.add(`editora-toolbar-${this.config.position}`);const n=document.createElement("div");n.className="editora-toolbar-items-container",this.itemsContainer=n,this.overflowUnits=[];const r=this.config.items||this.getDefaultToolbarString(),i=this.parseToolbarString(r);i.forEach((o,a)=>{const s=document.createElement("div");if(s.className="editora-toolbar-group",o.forEach(c=>{this.appendToolbarButton(s,c);const l=s.lastElementChild;l instanceof HTMLElement&&(this.overflowUnits.push(l),this.overflowUnitHomes.set(l,s))}),n.appendChild(s),a<i.length-1){const c=document.createElement("div");c.className="editora-toolbar-separator",n.appendChild(c)}}),e.appendChild(n),this.setupOverflow(e)}setupOverflow(e){if(!this.itemsContainer||typeof ResizeObserver=="undefined")return;const r=document.createElement("button");r.type="button",r.className="editora-toolbar-more-button",r.title="Show more options",r.setAttribute("aria-label","More toolbar options"),r.textContent="☰",r.style.display="none",r.addEventListener("click",s=>{s.preventDefault(),this.setExpandedOpen(!this.expandedOpen)}),this.moreButton=r,e.appendChild(r);const i=document.createElement("div");i.className="editora-toolbar-expanded-row",this.expandedRow=i,e.appendChild(i),document.addEventListener("mousedown",this.onDocumentPointerDownForOverflow,!0);const o=()=>{const s=this.overflowUnits;if(s.length===0)return;s.forEach(m=>{var g;m.parentElement===i&&((g=this.overflowUnitHomes.get(m))==null||g.appendChild(m))});const c=e.clientWidth,l=16,u=40,d=4,f=Math.max(0,c-l-u-d);let A=0,h=0;for(const m of s){const g=m.getBoundingClientRect().width+d;if(A+g<=f)A+=g,h++;else break}h=Math.max(1,Math.min(h,s.length));const p=h<s.length;r.style.display=p?"":"none",r.classList.toggle("active",p&&this.expandedOpen),!p&&this.expandedOpen&&this.setExpandedOpen(!1),s.forEach((m,g)=>{g>=h&&i.appendChild(m)})},a=()=>{this.overflowRafId!==void 0&&cancelAnimationFrame(this.overflowRafId),this.overflowRafId=requestAnimationFrame(o)};this.resizeObserver=new ResizeObserver(()=>a()),this.resizeObserver.observe(e),a()}setExpandedOpen(e){var n,r;this.expandedOpen=e,(n=this.expandedRow)==null||n.classList.toggle("show",e),(r=this.moreButton)==null||r.classList.toggle("active",e)}appendToolbarButton(e,n){if(n.type==="separator"){const r=document.createElement("div");r.className="editora-toolbar-separator",e.appendChild(r)}else if(n.type==="dropdown"){const r=this.createDropdown(n);e.appendChild(r)}else if(n.type==="inline-menu"){const r=this.createInlineMenu(n);e.appendChild(r)}else if(n.type==="group"&&n.items&&n.items.length){const r=this.createGroupButton(n);e.appendChild(r)}else if(n.type==="input"){const r=this.createInput(n);e.appendChild(r)}else{const r=this.createButton(n);e.appendChild(r)}}createGroupButton(e){const n=document.createElement("div"),r=e.label.toLowerCase().replace(/\s+/g,"-");if(n.className=`editora-toolbar-group-button ${r}`,n.title=e.label,e.icon)if(e.icon.startsWith("<svg")&&e.icon.endsWith("</svg>")){const i=document.createElement("span");i.className="editora-toolbar-icon",i.innerHTML=e.icon,n.appendChild(i)}else n.innerHTML=e.icon;if(e.items&&e.items.length){const i=document.createElement("div");i.className=`editora-toolbar-group-items ${r}`,e.items.forEach(o=>{this.appendToolbarButton(i,o)}),n.appendChild(i)}return n}createInput(e){const n=document.createElement("input");return n.className=`editora-toolbar-input ${e.label.toLowerCase().replace(/\s+/g,"-")}`,n.type="text",n.title=e.label,n.placeholder=e.placeholder||"",e.command&&n.setAttribute("data-command",e.command),e.active&&n.classList.add("active"),e.disabled&&(n.disabled=!0),n.addEventListener("click",r=>{r.preventDefault(),this.setLastCommandTrigger(n,e.command),this.commandHandler&&e.command&&this.commandHandler(e.command)}),n}createButton(e){const n=document.createElement("button");if(n.className="editora-toolbar-button",n.type="button",n.title=e.label,e.command&&n.setAttribute("data-command",e.command),e.icon)if(e.icon.startsWith("<svg")&&e.icon.endsWith("</svg>")){const r=document.createElement("span");r.className="editora-toolbar-icon",r.innerHTML=e.icon,n.appendChild(r)}else n.innerHTML=e.icon;else n.textContent=e.label;return e.active&&n.classList.add("active"),e.disabled&&(n.disabled=!0),n.addEventListener("click",r=>{r.preventDefault(),this.commandHandler&&e.command&&this.commandHandler(e.command)}),n}createDropdown(e){const n=document.createElement("div");n.className="editora-toolbar-dropdown";const r=document.createElement("button");r.className="editora-toolbar-button editora-toolbar-dropdown-trigger",r.type="button",r.textContent=e.label;const i=document.createElement("div");i.className="editora-toolbar-dropdown-menu",i.style.display="none",e.options&&e.options.forEach(s=>{const c=document.createElement("button");c.className="editora-toolbar-dropdown-item",c.type="button",c.textContent=s.label,c.setAttribute("data-value",s.value),c.addEventListener("click",l=>{l.preventDefault(),this.setLastCommandTrigger(r,e.command),this.commandHandler&&e.command&&this.commandHandler(e.command,s.value),i.style.display="none"}),i.appendChild(c)}),r.addEventListener("click",s=>{s.preventDefault(),s.stopPropagation(),this.setLastCommandTrigger(r,e.command);const c=i.style.display==="block";i.style.display=c?"none":"block"});const o=s=>{n.contains(s.target)||(i.style.display="none")},a=s=>{s.key==="Escape"&&(i.style.display="none")};return document.addEventListener("mousedown",o,!0),document.addEventListener("keydown",a),n._cleanupDropdown=()=>{document.removeEventListener("mousedown",o,!0),document.removeEventListener("keydown",a)},n.appendChild(r),n.appendChild(i),n}createInlineMenu(e){const n=document.createElement("div");n.className="editora-toolbar-dropdown editora-toolbar-inline-menu";const r=document.createElement("button");if(r.className="editora-toolbar-button",r.type="button",r.title=e.label,e.icon)if(e.icon.startsWith("<svg")&&e.icon.endsWith("</svg>")){const s=document.createElement("span");s.className="editora-toolbar-icon",s.innerHTML=e.icon,r.appendChild(s)}else r.innerHTML=e.icon;else r.textContent=e.label;const i=document.createElement("div");i.className="editora-toolbar-dropdown-menu",i.style.display="none",e.options&&e.options.forEach(s=>{const c=document.createElement("button");c.className="editora-toolbar-dropdown-item",c.type="button",c.textContent=s.label,c.setAttribute("data-value",s.value),c.addEventListener("click",l=>{l.preventDefault(),l.stopPropagation(),this.setLastCommandTrigger(r,e.command),this.commandHandler&&e.command&&this.commandHandler(e.command,s.value),i.style.display="none"}),i.appendChild(c)}),r.addEventListener("click",s=>{var l;s.preventDefault(),s.stopPropagation(),this.setLastCommandTrigger(r,e.command);const c=(l=this.container)==null?void 0:l.querySelectorAll(".editora-toolbar-dropdown-menu");c==null||c.forEach(u=>{u!==i&&(u.style.display="none")}),i.style.display=i.style.display==="none"?"block":"none"});const o=s=>{n.contains(s.target)||(i.style.display="none")},a=s=>{s.key==="Escape"&&(i.style.display="none")};return document.addEventListener("mousedown",o,!0),document.addEventListener("keydown",a),n._cleanupDropdown=()=>{document.removeEventListener("mousedown",o,!0),document.removeEventListener("keydown",a)},n.appendChild(r),n.appendChild(i),n}getDefaultToolbarString(){return this.getAvailableToolbarItems().map(n=>n.command).join(" ")}updateButtonState(e,n){if(!this.container)return;const r=this.container.querySelector(`[data-command="${e}"]`);r&&(n.active!==void 0&&r.classList.toggle("active",n.active),n.disabled!==void 0&&(r.disabled=n.disabled))}destroy(){var e;this.container&&(this.container.querySelectorAll(".editora-toolbar-dropdown").forEach(r=>{const i=r._cleanupDropdown;i&&i()}),this.container.innerHTML=""),(e=this.resizeObserver)==null||e.disconnect(),this.resizeObserver=void 0,this.overflowRafId!==void 0&&cancelAnimationFrame(this.overflowRafId),document.removeEventListener("mousedown",this.onDocumentPointerDownForOverflow,!0),this.itemsContainer=void 0,this.moreButton=void 0,this.expandedRow=void 0,this.commandHandler=void 0}}class Ine{constructor(e){this.visible=!1,this.config=e}create(e){const n=document.createElement("div");return n.className="editora-floating-toolbar",n.style.display="none",n.style.position="absolute",n.style.zIndex="1000",this.container=n,e.appendChild(n),n}show(e,n){this.container&&(this.container.style.display="block",this.container.style.left=`${e}px`,this.container.style.top=`${n}px`,this.visible=!0)}hide(){this.container&&(this.container.style.display="none",this.visible=!1)}updatePosition(e,n){!this.container||!this.visible||(this.container.style.left=`${e}px`,this.container.style.top=`${n}px`)}isVisible(){return this.visible}destroy(){this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container),this.container=void 0,this.visible=!1}}class Une{constructor(e={}){this.statusInfo={},this.config=e}create(e){const n=document.createElement("div");return n.className="editora-statusbar",this.config.position&&n.classList.add(`editora-statusbar-${this.config.position}`),this.container=n,e.appendChild(n),n}update(e){this.statusInfo={...this.statusInfo,...e},this.render()}render(){if(!this.container)return;this.container.innerHTML="";const e=document.createElement("div");e.className="editora-statusbar-left";const n=document.createElement("div");n.className="editora-statusbar-right";const r=[];if(this.statusInfo.selectionInfo){const o=this.statusInfo.selectionInfo;o.startLine===o.endLine&&o.startColumn===o.endColumn?r.push(`Ln ${o.startLine}, Col ${o.startColumn}`):(o.startLine===o.endLine?r.push(`Ln ${o.startLine}, Col ${o.startColumn}-${o.endColumn}`):r.push(`Ln ${o.startLine}:${o.startColumn} - ${o.endLine}:${o.endColumn}`),r.push(`${o.selectedChars} chars selected`))}else if(this.statusInfo.cursorPosition){const o=this.statusInfo.cursorPosition;r.push(`Ln ${o.line}, Col ${o.column}`)}this.statusInfo.language&&r.push(this.statusInfo.language);const i=[];this.statusInfo.wordCount!==void 0&&i.push(`${this.statusInfo.wordCount} words`),this.statusInfo.charCount!==void 0&&i.push(`${this.statusInfo.charCount} chars`),this.statusInfo.lineCount!==void 0&&i.push(`${this.statusInfo.lineCount} lines`),this.statusInfo.custom&&Object.entries(this.statusInfo.custom).forEach(([o,a])=>{i.push(`${o}: ${a}`)}),r.forEach((o,a)=>{const s=document.createElement("span");if(s.className="editora-statusbar-item",s.textContent=o,e.appendChild(s),a<r.length-1){const c=document.createElement("span");c.className="editora-statusbar-separator",c.textContent="|",e.appendChild(c)}}),i.forEach((o,a)=>{const s=document.createElement("span");if(s.className="editora-statusbar-item",s.textContent=o,n.appendChild(s),a<i.length-1){const c=document.createElement("span");c.className="editora-statusbar-separator",c.textContent="|",n.appendChild(c)}}),this.container.appendChild(e),this.container.appendChild(n)}destroy(){this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container),this.container=void 0}}function Nne(t,e){const n=t.textContent||"",r=Rne(t,e.startContainer,e.startOffset),o=n.substring(0,r).split(`
1
+ (function(Xa,Ya){typeof exports=="object"&&typeof module!="undefined"?Ya(exports):typeof define=="function"&&define.amd?define(["exports"],Ya):(Xa=typeof globalThis!="undefined"?globalThis:Xa||self,Ya(Xa.Editora={}))})(this,(function(Xa){"use strict";var JLe=Object.defineProperty;var eFe=(Xa,Ya,AA)=>Ya in Xa?JLe(Xa,Ya,{enumerable:!0,configurable:!0,writable:!0,value:AA}):Xa[Ya]=AA;var Gk=(Xa,Ya,AA)=>eFe(Xa,typeof Ya!="symbol"?Ya+"":Ya,AA);function Ya(t,e){for(var n=0;n<e.length;n++){const r=e[n];if(typeof r!="string"&&!Array.isArray(r)){for(const i in r)if(i!=="default"&&!(i in t)){const o=Object.getOwnPropertyDescriptor(r,i);o&&Object.defineProperty(t,i,o.get?o:{enumerable:!0,get:()=>r[i]})}}}return Object.freeze(Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}))}class AA{constructor(){this.loadedPlugins=new Map,this.pluginRegistry=new Map}register(e,n){this.pluginRegistry.set(e,n)}async load(e,n){if(this.loadedPlugins.has(e))return this.loadedPlugins.get(e);const r=this.pluginRegistry.get(e);if(!r)return console.warn(`Plugin not found: ${e}`),null;const i=await r();return n&&this.applyPluginConfig(i,n),this.loadedPlugins.set(e,i),i}async loadMultiple(e,n){return(await Promise.all(e.map(i=>this.load(i,n)))).filter(i=>i!==null)}async parsePluginString(e,n){const r=e.split(/\s+/).filter(Boolean);return this.loadMultiple(r,n)}applyPluginConfig(e,n){e.__pluginConfig=n}unload(e){this.loadedPlugins.delete(e)}clear(){this.loadedPlugins.clear()}getLoadedPlugins(){return Array.from(this.loadedPlugins.values())}getRegisteredPluginNames(){return Array.from(this.pluginRegistry.keys())}isLoaded(e){return this.loadedPlugins.has(e)}}class Uv{constructor(e,n,r){this.doc=e,this.selection=n,this.schema=r}static create(e,n){const r=n||e.node("doc",{},[e.node("paragraph")]);return new Uv(r,{anchor:0,head:0},e)}apply(e,n){return new Uv(e,n||this.selection,this.schema)}}let Sne=class{constructor(e,n){this.nodes=new Map(Object.entries(e)),this.marks=new Map(Object.entries(n))}node(e,n,r){return{type:e,attrs:n,content:r}}text(e,n){return{type:"text",text:e,marks:n}}};class _ne{constructor(){this.plugins=[],this.pluginConfigs=new Map}register(e,n){this.plugins.push(e),n&&this.pluginConfigs.set(e.name,n);const r=this.pluginConfigs.get(e.name)||e.config;if(e.initialize)try{e.initialize(r)}catch(i){console.error(`Failed to initialize plugin "${e.name}":`,i)}if(e.init&&e.init!==e.initialize)try{e.init(r)}catch(i){console.error(`Failed to run init hook for plugin "${e.name}":`,i)}}unregister(e){const n=this.plugins.findIndex(r=>r.name===e);if(n>-1){const r=this.plugins[n];r.destroy&&r.destroy(),this.plugins.splice(n,1),this.pluginConfigs.delete(e)}}getPlugin(e){return this.plugins.find(n=>n.name===e)}getPluginConfig(e){return this.pluginConfigs.get(e)}buildSchema(){const e={},n={};return this.plugins.forEach(r=>{r.nodes&&Object.assign(e,r.nodes),r.marks&&Object.assign(n,r.marks)}),new Sne(e,n)}getCommands(){const e={};return this.plugins.forEach(n=>{n.commands&&Object.assign(e,n.commands)}),e}getToolbarItems(){return this.plugins.flatMap(e=>e.toolbar||[])}async executePluginCommand(e,n,...r){const i=this.getPlugin(e);if(!i)throw new Error(`Plugin not found: ${e}`);const o=this.getPluginConfig(e)||i.config||{},a=o.mode||"local";try{switch(a){case"local":return i.executeLocal?i.executeLocal(n,...r):null;case"api":if(!i.executeAPI)throw new Error(`Plugin ${e} does not support API mode`);return await i.executeAPI(n,...r);case"hybrid":if(i.executeHybrid)return await i.executeHybrid(n,...r);try{if(i.executeAPI)return await i.executeAPI(n,...r)}catch(s){if(console.warn(`API execution failed for ${e}, falling back to local`,s),i.executeLocal&&o.fallbackToLocal!==!1)return i.executeLocal(n,...r);throw s}break;default:throw new Error(`Unknown plugin mode: ${a}`)}}catch(s){throw console.error(`Error executing command ${n} on plugin ${e}:`,s),s}}async destroyAll(){const e=this.plugins.filter(n=>n.destroy).map(n=>n.destroy());await Promise.all(e),this.plugins=[],this.pluginConfigs.clear()}}class Dne{constructor(e={}){this.commands=new Map,Object.entries(e).forEach(([n,r])=>{this.register(n,r)})}register(e,n){this.commands.has(e)&&console.warn(`Command ${e} is being overwritten`),this.commands.set(e,n)}unregister(e){this.commands.delete(e)}get(e){return this.commands.get(e)}has(e){return this.commands.has(e)}getCommandNames(){return Array.from(this.commands.keys())}clear(){this.commands.clear()}}class Lne{constructor(e={}){this.listeners=new Map,this.isReadonly=!1,this.isDestroyed=!1,this.isReadonly=e.readonly||!1,this.pluginManager=new _ne,e.plugins&&Array.isArray(e.plugins)&&e.plugins.forEach(r=>this.pluginManager.register(r));const n=this.pluginManager.buildSchema();this.state=Uv.create(n),this.commandRegistry=new Dne(this.pluginManager.getCommands())}execCommand(e,...n){if(this.isReadonly)return console.warn("Cannot execute commands in readonly mode"),!1;if(this.isDestroyed)return console.warn("Cannot execute commands on destroyed editor"),!1;const r=this.commandRegistry.get(e);if(!r)return console.warn(`Command not found: ${e}`),!1;let i;return n.length===0?i=r(this.state):n.length===1?i=r(this.state,n[0]):i=r(this.state,...n),i instanceof Promise?(i.then(o=>{o&&typeof o=="object"&&"doc"in o&&"selection"in o&&(this.setState(o),this.emit("change",this.state))}).catch(o=>{console.error(`Async command failed: ${e}`,o)}),!0):i&&typeof i=="object"&&"doc"in i&&"selection"in i?(this.setState(i),this.emit("change",this.state),!0):i!==!1&&i!=null}setState(e){this.isDestroyed||(this.state=e,this.emit("stateChange",e))}getState(){return this.state}setReadonly(e){this.isReadonly=e,this.emit("readonlyChange",e)}isReadOnly(){return this.isReadonly}on(e,n){return this.listeners.has(e)||this.listeners.set(e,[]),this.listeners.get(e).push(n),()=>{const r=this.listeners.get(e);if(r){const i=r.indexOf(n);i>-1&&r.splice(i,1)}}}emit(e,...n){const r=this.listeners.get(e);r&&r.forEach(i=>{try{i(...n)}catch(o){console.error(`Error in ${e} handler:`,o)}})}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.listeners.clear(),this.emit("destroy"))}isEditorDestroyed(){return this.isDestroyed}}class Fne{constructor(e,n,r){this.overflowUnits=[],this.overflowUnitHomes=new WeakMap,this.expandedOpen=!1,this.onDocumentPointerDownForOverflow=i=>{var a,s;if(!this.expandedOpen)return;const o=i.target;o&&((a=this.moreButton)!=null&&a.contains(o)||(s=this.expandedRow)!=null&&s.contains(o))||this.setExpandedOpen(!1)},this.config=e,this.plugins=n,this.pluginLoader=r}setLastCommandTrigger(e,n){if(typeof window=="undefined"||!e)return;const r=n||e.getAttribute("data-command")||void 0;r&&(window.__editoraLastCommandButton=e,window.__editoraLastCommand=r)}setCommandHandler(e){this.commandHandler=e}parseToolbarString(e){const n=[],r=e.split("|").map(s=>s.trim()),i=this.getAvailableToolbarItems(),o=new Map;i.forEach(s=>{s.command&&o.set(s.command,s),s.type==="group"&&s.label&&o.set(s.label,s)});const a={bold:"toggleBold",italic:"toggleItalic",underline:"toggleUnderline",strikethrough:"toggleStrikethrough",bullist:"toggleBulletList",numlist:"toggleOrderedList",checklist:"toggleChecklist",link:"openLinkDialog",image:"openImageDialog",table:"insertTable",trackChanges:"toggleTrackChanges",acceptTrackChanges:"acceptAllTrackChanges",rejectTrackChanges:"rejectAllTrackChanges",anchor:"insertAnchor",code:"toggleSourceView",blockquote:"toggleBlockquote",undo:"undo",redo:"redo",textColor:"openTextColorPicker",backgroundColor:"openBackgroundColorPicker",fontSize:"fontSize",fontFamily:"setFontFamily",lineHeight:"setLineHeight",heading:"setBlockType",paragraph:"setParagraph",textAlignment:"setTextAlignment",direction:"setDirectionLTR",indent:"increaseIndent",outdent:"decreaseIndent",capitalization:"setCapitalization",math:"insertMath",specialCharacters:"insertSpecialCharacter",emojis:"openEmojiDialog",embedIframe:"openEmbedIframeDialog",fullscreen:"toggleFullscreen",preview:"togglePreview",print:"print",a11yChecker:"toggleA11yChecker",spellCheck:"toggleSpellCheck",comments:"addComment",showHideComments:"toggleComments",toggleComments:"toggleComments",footnote:"insertFootnote",mergeTags:"insertMergeTag",dataBinding:"openDataBindingDialog",dataBindingPreview:"openDataBindingDialog",contentRules:"toggleContentRulesPanel",contentRulesAudit:"runContentRulesAudit",contentRulesRealtime:"toggleContentRulesRealtime",mention:"insertMention",slash:"openSlashCommands",slashCommands:"openSlashCommands",pageBreak:"insertPageBreak",template:"insertTemplate",importWord:"importWord",exportWord:"exportWord",exportPdf:"exportPdf",insertImage:"insertImage",insertVideo:"insertVideo",codeBlock:"insertCodeBlock"};return r.forEach(s=>{const c=[];s.split(/\s+/).filter(Boolean).forEach(u=>{if(u==="direction"){const A=o.get("setDirectionLTR"),h=o.get("setDirectionRTL");A&&c.push({id:"directionLTR",label:A.label,command:A.command,icon:A.icon,type:A.type||"button",options:A.options}),h&&c.push({id:"directionRTL",label:h.label,command:h.command,icon:h.icon,type:h.type||"button",options:h.options});return}if(u==="comments"){const A=o.get("addComment"),h=o.get("toggleComments");A&&c.push({id:"addComment",label:A.label,command:A.command,icon:A.icon,type:A.type||"button",options:A.options}),h&&c.push({id:"toggleComments",label:h.label,command:h.command,icon:h.icon,type:h.type||"button",options:h.options});return}const d=a[u]||u;let f=o.get(d);f||(f=o.get(u)),f&&c.push({id:u,label:f.label,command:f.command,icon:f.icon,type:f.type==="separator"?"separator":f.type||"button",options:f.options,items:f.items})}),c.length>0&&n.push(c)}),n}getAvailableToolbarItems(){return this.plugins.flatMap(n=>n.toolbar||[])}render(e){this.container=e,e.innerHTML="",e.className="editora-toolbar",this.config.sticky&&e.classList.add("editora-toolbar-sticky"),this.config.position&&e.classList.add(`editora-toolbar-${this.config.position}`);const n=document.createElement("div");n.className="editora-toolbar-items-container",this.itemsContainer=n,this.overflowUnits=[];const r=this.config.items||this.getDefaultToolbarString(),i=this.parseToolbarString(r);i.forEach((o,a)=>{const s=document.createElement("div");if(s.className="editora-toolbar-group",o.forEach(c=>{this.appendToolbarButton(s,c);const l=s.lastElementChild;l instanceof HTMLElement&&(this.overflowUnits.push(l),this.overflowUnitHomes.set(l,s))}),n.appendChild(s),a<i.length-1){const c=document.createElement("div");c.className="editora-toolbar-separator",n.appendChild(c)}}),e.appendChild(n),this.setupOverflow(e)}setupOverflow(e){if(!this.itemsContainer||typeof ResizeObserver=="undefined")return;const r=document.createElement("button");r.type="button",r.className="editora-toolbar-more-button",r.title="Show more options",r.setAttribute("aria-label","More toolbar options"),r.textContent="☰",r.style.display="none",r.addEventListener("click",s=>{s.preventDefault(),this.setExpandedOpen(!this.expandedOpen)}),this.moreButton=r,e.appendChild(r);const i=document.createElement("div");i.className="editora-toolbar-expanded-row",this.expandedRow=i,e.appendChild(i),document.addEventListener("mousedown",this.onDocumentPointerDownForOverflow,!0);const o=()=>{const s=this.overflowUnits;if(s.length===0)return;s.forEach(m=>{var g;m.parentElement===i&&((g=this.overflowUnitHomes.get(m))==null||g.appendChild(m))});const c=e.clientWidth,l=16,u=40,d=4,f=Math.max(0,c-l-u-d);let A=0,h=0;for(const m of s){const g=m.getBoundingClientRect().width+d;if(A+g<=f)A+=g,h++;else break}h=Math.max(1,Math.min(h,s.length));const p=h<s.length;r.style.display=p?"":"none",r.classList.toggle("active",p&&this.expandedOpen),!p&&this.expandedOpen&&this.setExpandedOpen(!1),s.forEach((m,g)=>{g>=h&&i.appendChild(m)})},a=()=>{this.overflowRafId!==void 0&&cancelAnimationFrame(this.overflowRafId),this.overflowRafId=requestAnimationFrame(o)};this.resizeObserver=new ResizeObserver(()=>a()),this.resizeObserver.observe(e),a()}setExpandedOpen(e){var n,r;this.expandedOpen=e,(n=this.expandedRow)==null||n.classList.toggle("show",e),(r=this.moreButton)==null||r.classList.toggle("active",e)}appendToolbarButton(e,n){if(n.type==="separator"){const r=document.createElement("div");r.className="editora-toolbar-separator",e.appendChild(r)}else if(n.type==="dropdown"){const r=this.createDropdown(n);e.appendChild(r)}else if(n.type==="inline-menu"){const r=this.createInlineMenu(n);e.appendChild(r)}else if(n.type==="group"&&n.items&&n.items.length){const r=this.createGroupButton(n);e.appendChild(r)}else if(n.type==="input"){const r=this.createInput(n);e.appendChild(r)}else{const r=this.createButton(n);e.appendChild(r)}}createGroupButton(e){const n=document.createElement("div"),r=e.label.toLowerCase().replace(/\s+/g,"-");if(n.className=`editora-toolbar-group-button ${r}`,n.title=e.label,e.icon)if(e.icon.startsWith("<svg")&&e.icon.endsWith("</svg>")){const i=document.createElement("span");i.className="editora-toolbar-icon",i.innerHTML=e.icon,n.appendChild(i)}else n.innerHTML=e.icon;if(e.items&&e.items.length){const i=document.createElement("div");i.className=`editora-toolbar-group-items ${r}`,e.items.forEach(o=>{this.appendToolbarButton(i,o)}),n.appendChild(i)}return n}createInput(e){const n=document.createElement("input");return n.className=`editora-toolbar-input ${e.label.toLowerCase().replace(/\s+/g,"-")}`,n.type="text",n.title=e.label,n.setAttribute("aria-label",e.label),n.placeholder=e.placeholder||"",e.command&&n.setAttribute("data-command",e.command),e.active&&n.classList.add("active"),e.disabled&&(n.disabled=!0),n.addEventListener("click",r=>{r.preventDefault(),this.setLastCommandTrigger(n,e.command),this.commandHandler&&e.command&&this.commandHandler(e.command)}),n}createButton(e){const n=document.createElement("button");if(n.className="editora-toolbar-button",n.type="button",n.title=e.label,e.command&&n.setAttribute("data-command",e.command),e.icon)if(e.icon.startsWith("<svg")&&e.icon.endsWith("</svg>")){const r=document.createElement("span");r.className="editora-toolbar-icon",r.innerHTML=e.icon,n.appendChild(r)}else n.innerHTML=e.icon;else n.textContent=e.label;return e.active&&n.classList.add("active"),e.disabled&&(n.disabled=!0),n.addEventListener("click",r=>{r.preventDefault(),this.commandHandler&&e.command&&this.commandHandler(e.command)}),n}createDropdown(e){const n=document.createElement("div");n.className="editora-toolbar-dropdown";const r=document.createElement("button");r.className="editora-toolbar-button editora-toolbar-dropdown-trigger",r.type="button",r.textContent=e.label;const i=document.createElement("div");i.className="editora-toolbar-dropdown-menu",i.style.display="none",e.options&&e.options.forEach(s=>{const c=document.createElement("button");c.className="editora-toolbar-dropdown-item",c.type="button",c.textContent=s.label,c.setAttribute("data-value",s.value),c.addEventListener("click",l=>{l.preventDefault(),this.setLastCommandTrigger(r,e.command),this.commandHandler&&e.command&&this.commandHandler(e.command,s.value),i.style.display="none"}),i.appendChild(c)}),r.addEventListener("click",s=>{s.preventDefault(),s.stopPropagation(),this.setLastCommandTrigger(r,e.command);const c=i.style.display==="block";i.style.display=c?"none":"block"});const o=s=>{n.contains(s.target)||(i.style.display="none")},a=s=>{s.key==="Escape"&&(i.style.display="none")};return document.addEventListener("mousedown",o,!0),document.addEventListener("keydown",a),n._cleanupDropdown=()=>{document.removeEventListener("mousedown",o,!0),document.removeEventListener("keydown",a)},n.appendChild(r),n.appendChild(i),n}createInlineMenu(e){const n=document.createElement("div");n.className="editora-toolbar-dropdown editora-toolbar-inline-menu";const r=document.createElement("button");if(r.className="editora-toolbar-button",r.type="button",r.title=e.label,e.icon)if(e.icon.startsWith("<svg")&&e.icon.endsWith("</svg>")){const s=document.createElement("span");s.className="editora-toolbar-icon",s.innerHTML=e.icon,r.appendChild(s)}else r.innerHTML=e.icon;else r.textContent=e.label;const i=document.createElement("div");i.className="editora-toolbar-dropdown-menu",i.style.display="none",e.options&&e.options.forEach(s=>{const c=document.createElement("button");c.className="editora-toolbar-dropdown-item",c.type="button",c.textContent=s.label,c.setAttribute("data-value",s.value),c.addEventListener("click",l=>{l.preventDefault(),l.stopPropagation(),this.setLastCommandTrigger(r,e.command),this.commandHandler&&e.command&&this.commandHandler(e.command,s.value),i.style.display="none"}),i.appendChild(c)}),r.addEventListener("click",s=>{var l;s.preventDefault(),s.stopPropagation(),this.setLastCommandTrigger(r,e.command);const c=(l=this.container)==null?void 0:l.querySelectorAll(".editora-toolbar-dropdown-menu");c==null||c.forEach(u=>{u!==i&&(u.style.display="none")}),i.style.display=i.style.display==="none"?"block":"none"});const o=s=>{n.contains(s.target)||(i.style.display="none")},a=s=>{s.key==="Escape"&&(i.style.display="none")};return document.addEventListener("mousedown",o,!0),document.addEventListener("keydown",a),n._cleanupDropdown=()=>{document.removeEventListener("mousedown",o,!0),document.removeEventListener("keydown",a)},n.appendChild(r),n.appendChild(i),n}getDefaultToolbarString(){return this.getAvailableToolbarItems().map(n=>n.command).join(" ")}updateButtonState(e,n){if(!this.container)return;const r=this.container.querySelector(`[data-command="${e}"]`);r&&(n.active!==void 0&&r.classList.toggle("active",n.active),n.disabled!==void 0&&(r.disabled=n.disabled))}destroy(){var e;this.container&&(this.container.querySelectorAll(".editora-toolbar-dropdown").forEach(r=>{const i=r._cleanupDropdown;i&&i()}),this.container.innerHTML=""),(e=this.resizeObserver)==null||e.disconnect(),this.resizeObserver=void 0,this.overflowRafId!==void 0&&cancelAnimationFrame(this.overflowRafId),document.removeEventListener("mousedown",this.onDocumentPointerDownForOverflow,!0),this.itemsContainer=void 0,this.moreButton=void 0,this.expandedRow=void 0,this.commandHandler=void 0}}class Ine{constructor(e){this.visible=!1,this.config=e}create(e){const n=document.createElement("div");return n.className="editora-floating-toolbar",n.style.display="none",n.style.position="absolute",n.style.zIndex="1000",this.container=n,e.appendChild(n),n}show(e,n){this.container&&(this.container.style.display="block",this.container.style.left=`${e}px`,this.container.style.top=`${n}px`,this.visible=!0)}hide(){this.container&&(this.container.style.display="none",this.visible=!1)}updatePosition(e,n){!this.container||!this.visible||(this.container.style.left=`${e}px`,this.container.style.top=`${n}px`)}isVisible(){return this.visible}destroy(){this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container),this.container=void 0,this.visible=!1}}class Une{constructor(e={}){this.statusInfo={},this.config=e}create(e){const n=document.createElement("div");return n.className="editora-statusbar",this.config.position&&n.classList.add(`editora-statusbar-${this.config.position}`),this.container=n,e.appendChild(n),n}update(e){this.statusInfo={...this.statusInfo,...e},this.render()}render(){if(!this.container)return;this.container.innerHTML="";const e=document.createElement("div");e.className="editora-statusbar-left";const n=document.createElement("div");n.className="editora-statusbar-right";const r=[];if(this.statusInfo.selectionInfo){const o=this.statusInfo.selectionInfo;o.startLine===o.endLine&&o.startColumn===o.endColumn?r.push(`Ln ${o.startLine}, Col ${o.startColumn}`):(o.startLine===o.endLine?r.push(`Ln ${o.startLine}, Col ${o.startColumn}-${o.endColumn}`):r.push(`Ln ${o.startLine}:${o.startColumn} - ${o.endLine}:${o.endColumn}`),r.push(`${o.selectedChars} chars selected`))}else if(this.statusInfo.cursorPosition){const o=this.statusInfo.cursorPosition;r.push(`Ln ${o.line}, Col ${o.column}`)}this.statusInfo.language&&r.push(this.statusInfo.language);const i=[];this.statusInfo.wordCount!==void 0&&i.push(`${this.statusInfo.wordCount} words`),this.statusInfo.charCount!==void 0&&i.push(`${this.statusInfo.charCount} chars`),this.statusInfo.lineCount!==void 0&&i.push(`${this.statusInfo.lineCount} lines`),this.statusInfo.custom&&Object.entries(this.statusInfo.custom).forEach(([o,a])=>{i.push(`${o}: ${a}`)}),r.forEach((o,a)=>{const s=document.createElement("span");if(s.className="editora-statusbar-item",s.textContent=o,e.appendChild(s),a<r.length-1){const c=document.createElement("span");c.className="editora-statusbar-separator",c.textContent="|",e.appendChild(c)}}),i.forEach((o,a)=>{const s=document.createElement("span");if(s.className="editora-statusbar-item",s.textContent=o,n.appendChild(s),a<i.length-1){const c=document.createElement("span");c.className="editora-statusbar-separator",c.textContent="|",n.appendChild(c)}}),this.container.appendChild(e),this.container.appendChild(n)}destroy(){this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container),this.container=void 0}}function Nne(t,e){const n=t.textContent||"",r=Rne(t,e.startContainer,e.startOffset),o=n.substring(0,r).split(`
2
2
  `),a=o.length,s=o[o.length-1].length+1;return{line:a,column:s}}function Rne(t,e,n){var a;let r=0;const i=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,null);let o=i.firstChild();for(;o;){if(o===e){r+=n;break}else o.nodeType===Node.TEXT_NODE&&(r+=((a=o.textContent)==null?void 0:a.length)||0);o=i.nextNode()}return r}function One(t){var r,i;const e=t.querySelectorAll("div, p, br, h1, h2, h3, h4, h5, h6, blockquote, li, pre");let n=1;if(e.length>0){n=e.length;const o=e[e.length-1];(o.tagName==="BR"||((r=o.innerHTML)==null?void 0:r.trim())===""||((i=o.textContent)==null?void 0:i.trim())==="")&&n++}else{const a=(t.textContent||"").split(`
3
3
  `).length;n=Math.max(1,a)}return n}function Mne(t){const e=t.trim()?t.trim().split(/\s+/).length:0,n=t.length;return{words:e,chars:n}}function Pne(t,e){const n=t.toString();return{startLine:e.line,startColumn:e.column,endLine:e.line,endColumn:e.column+n.length,selectedChars:n.length,selectedWords:n.trim().split(/\s+/).filter(Boolean).length}}class Hne{constructor(e){this.shortcuts=new Map,this.enabled=!0,this.isMac=typeof navigator!="undefined"&&navigator.platform.toUpperCase().indexOf("MAC")>=0,(e==null?void 0:e.enabled)===!1&&(this.enabled=!1),this.registerDefaultShortcuts(),e!=null&&e.shortcuts&&e.shortcuts.forEach(n=>this.registerShortcut(n)),e!=null&&e.customShortcuts&&Object.values(e.customShortcuts).forEach(n=>{this.registerShortcut(n)})}registerDefaultShortcuts(){this.registerShortcut({key:"b",ctrl:!this.isMac,meta:this.isMac,command:"toggleBold",description:"Bold",preventDefault:!0}),this.registerShortcut({key:"i",ctrl:!this.isMac,meta:this.isMac,command:"toggleItalic",description:"Italic",preventDefault:!0}),this.registerShortcut({key:"u",ctrl:!this.isMac,meta:this.isMac,command:"toggleUnderline",description:"Underline",preventDefault:!0}),this.registerShortcut({key:"d",ctrl:!this.isMac,meta:this.isMac,command:"toggleStrikethrough",description:"Strikethrough",preventDefault:!0}),this.registerShortcut({key:"z",ctrl:!this.isMac,meta:this.isMac,command:"undo",description:"Undo",preventDefault:!0}),this.registerShortcut({key:"z",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"redo",description:"Redo",preventDefault:!0}),this.registerShortcut({key:"y",ctrl:!this.isMac,meta:this.isMac,command:"redo",description:"Redo",preventDefault:!0});for(let e=1;e<=6;e++)this.registerShortcut({key:String(e),ctrl:!this.isMac,meta:this.isMac,alt:!0,command:"setBlockType",params:`h${e}`,description:`Heading ${e}`,preventDefault:!0});this.registerShortcut({key:"7",ctrl:!this.isMac,meta:this.isMac,alt:!0,command:"setBlockType",params:"p",description:"Paragraph",preventDefault:!0}),this.registerShortcut({key:"7",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"toggleOrderedList",description:"Numbered List",preventDefault:!0}),this.registerShortcut({key:"8",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"toggleBulletList",description:"Bullet List",preventDefault:!0}),this.registerShortcut({key:"k",ctrl:!this.isMac,meta:this.isMac,command:"openLinkDialog",description:"Insert/Edit Link",preventDefault:!0}),this.registerShortcut({key:"e",ctrl:!this.isMac,meta:this.isMac,alt:!0,command:"insertCodeBlock",description:"Code Block",preventDefault:!0}),this.registerShortcut({key:"q",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"toggleBlockquote",description:"Blockquote",preventDefault:!0}),this.registerShortcut({key:"l",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"setTextAlignment",params:"left",description:"Align Left",preventDefault:!0}),this.registerShortcut({key:"e",ctrl:!this.isMac,meta:this.isMac,shift:!0,alt:!0,command:"setTextAlignment",params:"center",description:"Align Center",preventDefault:!0}),this.registerShortcut({key:"r",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"setTextAlignment",params:"right",description:"Align Right",preventDefault:!0}),this.registerShortcut({key:"j",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"setTextAlignment",params:"justify",description:"Justify",preventDefault:!0}),this.registerShortcut({key:"\\",ctrl:!this.isMac,meta:this.isMac,command:"clearFormatting",description:"Clear Formatting",preventDefault:!0}),this.registerShortcut({key:"]",ctrl:!this.isMac,meta:this.isMac,command:"increaseIndent",description:"Indent",preventDefault:!0}),this.registerShortcut({key:"[",ctrl:!this.isMac,meta:this.isMac,command:"decreaseIndent",description:"Outdent",preventDefault:!0}),this.registerShortcut({key:"g",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"insertImage",description:"Insert Image",preventDefault:!0}),this.registerShortcut({key:"t",ctrl:!this.isMac,meta:this.isMac,shift:!0,alt:!0,command:"insertTable",description:"Insert Table",preventDefault:!0}),this.registerShortcut({key:"f11",command:"toggleFullscreen",description:"Toggle Fullscreen",preventDefault:!0}),this.registerShortcut({key:"p",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"togglePreview",description:"Preview",preventDefault:!0}),this.registerShortcut({key:"p",ctrl:!this.isMac,meta:this.isMac,command:"print",description:"Print",preventDefault:!0}),this.registerShortcut({key:"s",ctrl:!this.isMac,meta:this.isMac,shift:!0,alt:!0,command:"insertSpecialCharacter",description:"Insert Special Character",preventDefault:!0}),this.registerShortcut({key:"m",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"insertEmoji",description:"Insert Emoji",preventDefault:!0}),this.registerShortcut({key:"9",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"toggleChecklist",description:"Checklist",preventDefault:!0}),this.registerShortcut({key:"a",ctrl:!this.isMac,meta:this.isMac,shift:!0,alt:!0,command:"toggleA11yChecker",description:"Accessibility Checker",preventDefault:!0}),this.registerShortcut({key:"F7",command:"toggleSpellCheck",description:"Spell Check",preventDefault:!0}),this.registerShortcut({key:"m",ctrl:!this.isMac,meta:this.isMac,alt:!0,command:"insertMath",description:"Insert Math",preventDefault:!0}),this.registerShortcut({key:"f",ctrl:!this.isMac,meta:this.isMac,alt:!0,command:"insertFootnote",description:"Insert Footnote",preventDefault:!0})}registerShortcut(e){const n=this.getShortcutKey(e);this.shortcuts.set(n,e)}unregisterShortcut(e){const n=this.getShortcutKey(e);this.shortcuts.delete(n)}getShortcutKey(e){const n=[];return e.ctrl&&n.push("ctrl"),e.alt&&n.push("alt"),e.shift&&n.push("shift"),e.meta&&n.push("meta"),n.push(e.key.toLowerCase()),n.join("+")}getEventKey(e){const n=[];return e.ctrlKey&&n.push("ctrl"),e.altKey&&n.push("alt"),e.shiftKey&&n.push("shift"),e.metaKey&&n.push("meta"),n.push(e.key.toLowerCase()),n.join("+")}handleKeyDown(e,n){if(!this.enabled)return!1;const r=this.getEventKey(e),i=this.shortcuts.get(r);return i?(i.preventDefault!==!1&&(e.preventDefault(),e.stopPropagation()),n(i.command,i.params),!0):!1}enable(){this.enabled=!0}disable(){this.enabled=!1}isEnabled(){return this.enabled}getAllShortcuts(){return Array.from(this.shortcuts.values())}getShortcutForCommand(e){return Array.from(this.shortcuts.values()).find(n=>n.command===e)}getShortcutDescription(e){const n=[];this.isMac?(e.meta&&n.push("⌘"),e.ctrl&&n.push("⌃"),e.alt&&n.push("⌥"),e.shift&&n.push("⇧")):(e.ctrl&&n.push("Ctrl"),e.alt&&n.push("Alt"),e.shift&&n.push("Shift"));const r=e.key.length===1?e.key.toUpperCase():e.key;return n.push(r),n.join("+")}getShortcutsHelp(){const e=this.getAllShortcuts(),n=new Map;e.forEach(i=>{const o=this.getShortcutCategory(i.command);n.has(o)||n.set(o,[]),n.get(o).push(i)});let r=`# Keyboard Shortcuts
4
4
 
@@ -22,7 +22,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
22
22
  `,document.head.appendChild(t)}function Io(t){t.setAttribute("data-rte-dialog",""),Mie(),Oie(t)}class AB{constructor(e=""){this._lines=[],this._version=0,this.setText(e)}getLine(e){return this._lines[e]||""}getLines(){return[...this._lines]}getLineCount(){return this._lines.length}getText(){return this._lines.join(`
23
23
  `)}setText(e){this._lines=e.split(`
24
24
  `),this._version++}getTextInRange(e){if(e.start.line===e.end.line)return this.getLine(e.start.line).substring(e.start.column,e.end.column);const n=[];n.push(this.getLine(e.start.line).substring(e.start.column));for(let r=e.start.line+1;r<e.end.line;r++)n.push(this.getLine(r));return e.end.line<this.getLineCount()&&n.push(this.getLine(e.end.line).substring(0,e.end.column)),n.join(`
25
- `)}replaceRange(e,n){const r=this.normalizeRange(e),i=this.getTextInRange(r),o=this.getText(),a=this.positionToOffset(r.start),s=this.positionToOffset(r.end),c=o.slice(0,a)+n+o.slice(s);return this.setText(c),{range:r,text:n,oldText:i}}insertText(e,n){const r={start:e,end:e};return this.replaceRange(r,n)}deleteRange(e){return this.replaceRange(e,"")}positionToOffset(e){let n=0;for(let r=0;r<e.line;r++)n+=this.getLine(r).length+1;return n+=e.column,n}offsetToPosition(e){let n=e;for(let r=0;r<this.getLineCount();r++){const i=this.getLine(r).length;if(n<=i)return{line:r,column:n};n-=i+1}return{line:this.getLineCount()-1,column:this.getLine(this.getLineCount()-1).length}}isValidPosition(e){return!(e.line<0||e.line>=this.getLineCount()||e.column<0||e.column>this.getLine(e.line).length)}isValidRange(e){return this.isValidPosition(e.start)&&this.isValidPosition(e.end)}getVersion(){return this._version}clone(){const e=new AB;return e._lines=[...this._lines],e._version=this._version,e}normalizeRange(e){return this.comparePositions(e.start,e.end)<=0?e:{start:e.end,end:e.start}}comparePositions(e,n){return e.line!==n.line?e.line-n.line:e.column-n.column}}class Pie{constructor(e){this.gutterWidth=50,this.gutterFoldColumnWidth=20,this.gutterFoldColumnGap=4,this.gutterLineNumberPaddingLeft=8,this.gutterLineNumberPaddingRight=4,this.gutterDigitWidth=9,this.lineHeight=21,this.trailingNewlineMarkerAttr="data-lce-trailing-newline-marker",this.foldPlaceholderAttr="data-lce-fold-placeholder",this.virtualMarkerRegex=/[\u200B\uE000]/,this.virtualMarkerGlobalRegex=/[\u200B\uE000]/g,this.lastLineCount=0,this.lastHighlightHTML="",this.highlightOverlayActive=!1,this.lastLineDecorationSnapshot="",this.lastGutterDecorationSnapshot="",this.container=e,this.createDOM()}createDOM(){this.container.innerHTML="";const e=document.createElement("div");this.editorContainer=e,e.setAttribute("data-lce-editor-container","true"),e.style.cssText=`
25
+ `)}replaceRange(e,n){const r=this.normalizeRange(e),i=this.getTextInRange(r),o=this.getText(),a=this.positionToOffset(r.start),s=this.positionToOffset(r.end),c=o.slice(0,a)+n+o.slice(s);return this.setText(c),{range:r,text:n,oldText:i}}insertText(e,n){const r={start:e,end:e};return this.replaceRange(r,n)}deleteRange(e){return this.replaceRange(e,"")}positionToOffset(e){let n=0;for(let r=0;r<e.line;r++)n+=this.getLine(r).length+1;return n+=e.column,n}offsetToPosition(e){let n=e;for(let r=0;r<this.getLineCount();r++){const i=this.getLine(r).length;if(n<=i)return{line:r,column:n};n-=i+1}return{line:this.getLineCount()-1,column:this.getLine(this.getLineCount()-1).length}}isValidPosition(e){return!(e.line<0||e.line>=this.getLineCount()||e.column<0||e.column>this.getLine(e.line).length)}isValidRange(e){return this.isValidPosition(e.start)&&this.isValidPosition(e.end)}getVersion(){return this._version}clone(){const e=new AB;return e._lines=[...this._lines],e._version=this._version,e}normalizeRange(e){return this.comparePositions(e.start,e.end)<=0?e:{start:e.end,end:e.start}}comparePositions(e,n){return e.line!==n.line?e.line-n.line:e.column-n.column}}class Pie{constructor(e){this.gutterWidth=50,this.gutterFoldColumnWidth=24,this.gutterFoldColumnGap=4,this.gutterLineNumberPaddingLeft=8,this.gutterLineNumberPaddingRight=4,this.gutterDigitWidth=9,this.lineHeight=24,this.trailingNewlineMarkerAttr="data-lce-trailing-newline-marker",this.foldPlaceholderAttr="data-lce-fold-placeholder",this.virtualMarkerRegex=/[\u200B\uE000]/,this.virtualMarkerGlobalRegex=/[\u200B\uE000]/g,this.lastLineCount=0,this.lastHighlightHTML="",this.highlightOverlayActive=!1,this.lastLineDecorationSnapshot="",this.lastGutterDecorationSnapshot="",this.container=e,this.createDOM()}createDOM(){this.container.innerHTML="";const e=document.createElement("div");this.editorContainer=e,e.setAttribute("data-lce-editor-container","true"),e.style.cssText=`
26
26
  position: relative;
27
27
  display: flex;
28
28
  width: 100%;
@@ -209,12 +209,12 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
209
209
  background-color: var(--lce-bracket-match-bg, rgba(86, 156, 214, 0.4));
210
210
  text-decoration: underline solid var(--lce-bracket-match-border, rgba(156, 220, 254, 0.95)) 2px;
211
211
  }
212
- `,document.head.appendChild(e)}getCurrentMatch(){return this.currentMatch}destroy(){var e;if(this.pendingUpdateRaf!==null&&typeof cancelAnimationFrame=="function"&&(cancelAnimationFrame(this.pendingUpdateRaf),this.pendingUpdateRaf=null),this.clearBracketHighlighting(),(e=this.observer)==null||e.disconnect(),this.observer=null,this.editor&&this.cursorHandler&&this.editor.off("cursor",this.cursorHandler),this.editor&&this.changeHandler&&this.editor.off("change",this.changeHandler),typeof document!="undefined"){const n=document.getElementById(this.highlightStyleId);n!=null&&n.parentNode&&n.parentNode.removeChild(n)}this.cursorHandler=null,this.changeHandler=null,this.editor=null}}class Vie{constructor(){this.name="code-folding",this.lineHeight=21,this.voidMarkupTags=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),this.nonFoldableInlineMarkupTags=new Set(["a","abbr","b","bdi","bdo","button","cite","code","data","del","dfn","em","i","ins","kbd","label","mark","output","q","ruby","s","samp","small","span","strong","sub","sup","time","u","var"]),this.rawTextMarkupTags=new Set(["script","style","textarea","title"]),this.editor=null,this.foldingUI=null,this.pendingUpdateRaf=null,this.lastSnapshot="",this.lastParsedText=null,this.changeHandler=null,this.foldRegions=[],this.foldSnapshots=new Map,this.isDisplayingFolded=!1,this.cachedLineInfo=null}setup(e){this.editor=e,e.registerCommand("fold",()=>{this.foldAtCursor()}),e.registerCommand("unfold",()=>{this.unfoldAtCursor()}),e.registerCommand("foldAll",()=>{this.foldAll()}),e.registerCommand("unfoldAll",()=>{this.unfoldAll()}),this.changeHandler=()=>{this.syncFoldingState()},e.on("change",this.changeHandler),this.createFoldingUI(),this.syncFoldingState()}onKeyDown(e){}onMouseDown(e){}createFoldingUI(){if(!this.editor)return;const e=this.editor.getView().getLineNumbersElement();e&&(this.foldingUI=document.createElement("div"),this.foldingUI.setAttribute("data-lce-folding-ui","true"),this.foldingUI.style.cssText=`
212
+ `,document.head.appendChild(e)}getCurrentMatch(){return this.currentMatch}destroy(){var e;if(this.pendingUpdateRaf!==null&&typeof cancelAnimationFrame=="function"&&(cancelAnimationFrame(this.pendingUpdateRaf),this.pendingUpdateRaf=null),this.clearBracketHighlighting(),(e=this.observer)==null||e.disconnect(),this.observer=null,this.editor&&this.cursorHandler&&this.editor.off("cursor",this.cursorHandler),this.editor&&this.changeHandler&&this.editor.off("change",this.changeHandler),typeof document!="undefined"){const n=document.getElementById(this.highlightStyleId);n!=null&&n.parentNode&&n.parentNode.removeChild(n)}this.cursorHandler=null,this.changeHandler=null,this.editor=null}}class Vie{constructor(){this.name="code-folding",this.lineHeight=24,this.voidMarkupTags=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),this.nonFoldableInlineMarkupTags=new Set(["a","abbr","b","bdi","bdo","button","cite","code","data","del","dfn","em","i","ins","kbd","label","mark","output","q","ruby","s","samp","small","span","strong","sub","sup","time","u","var"]),this.rawTextMarkupTags=new Set(["script","style","textarea","title"]),this.editor=null,this.foldingUI=null,this.pendingUpdateRaf=null,this.lastSnapshot="",this.lastParsedText=null,this.changeHandler=null,this.foldRegions=[],this.foldSnapshots=new Map,this.isDisplayingFolded=!1,this.cachedLineInfo=null}setup(e){this.editor=e,e.registerCommand("fold",()=>{this.foldAtCursor()}),e.registerCommand("unfold",()=>{this.unfoldAtCursor()}),e.registerCommand("foldAll",()=>{this.foldAll()}),e.registerCommand("unfoldAll",()=>{this.unfoldAll()}),this.changeHandler=()=>{this.syncFoldingState()},e.on("change",this.changeHandler),this.createFoldingUI(),this.syncFoldingState()}onKeyDown(e){}onMouseDown(e){}createFoldingUI(){if(!this.editor)return;const e=this.editor.getView().getLineNumbersElement();e&&(this.foldingUI=document.createElement("div"),this.foldingUI.setAttribute("data-lce-folding-ui","true"),this.foldingUI.style.cssText=`
213
213
  position: absolute;
214
214
  right: 0;
215
215
  top: 0;
216
216
  bottom: 0;
217
- width: 20px;
217
+ width: 24px;
218
218
  pointer-events: none;
219
219
  z-index: 3;
220
220
  `,e.appendChild(this.foldingUI))}syncFoldingState(){if(!this.editor)return;const e=this.editor.getValue(),n=this.foldSnapshots;e!==this.lastParsedText&&(this.foldRegions=this.buildFoldRegions(e),this.pruneInvalidFolds(e,n),this.lastParsedText=e),this.hasActiveFolds()?this.applyFoldedDisplay():this.restoreFullDisplay(),this.rememberActiveFoldSnapshots(e),this.scheduleFoldIndicatorUpdate()}scheduleFoldIndicatorUpdate(){this.pendingUpdateRaf===null&&(this.pendingUpdateRaf=requestAnimationFrame(()=>{this.pendingUpdateRaf=null,this.updateFoldIndicators()}))}updateFoldIndicators(){if(!this.editor||!this.foldingUI)return;const e=this.editor.getValue(),n=this.getActiveFolds().map(a=>this.getFoldKey(a)).join("|"),r=`${e}::${n}`;if(r===this.lastSnapshot)return;this.lastSnapshot=r,this.foldingUI.innerHTML="";const i=this.getRenderableActiveFolds(),o=document.createDocumentFragment();for(const a of this.foldRegions){const s=this.toDisplayLine(a,i);if(s===null)continue;const c=this.isFoldActive(a),l=this.createFoldIndicator(a,s,c);o.appendChild(l)}this.foldingUI.appendChild(o)}buildFoldRegions(e){const n=this.buildBracketFoldRegions(e),r=this.shouldIncludeMarkupFolds(e)?this.buildMarkupFoldRegions(e):[];return this.mergeFoldRegions([...n,...r])}buildBracketFoldRegions(e){var s;const n=e.split(`
@@ -222,7 +222,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
222
222
  position: absolute;
223
223
  left: 0;
224
224
  top: ${n*this.lineHeight}px;
225
- width: 20px;
225
+ width: 24px;
226
226
  height: ${this.lineHeight}px;
227
227
  display: flex;
228
228
  align-items: center;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@editora/core",
3
- "version": "1.0.20",
3
+ "version": "1.0.21",
4
4
  "description": "Framework-agnostic rich text editor core for React and web apps, built for enterprise editing workflows.",
5
5
  "author": "Ajay Kumar <ajaykr089@gmail.com>",
6
6
  "license": "MIT",