@editora/core 1.0.5 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{AnchorPlugin.native-C1Rw5m04.mjs → AnchorPlugin.native-BcYGEtd9.mjs} +129 -105
- package/dist/{BackgroundColorPlugin.native-BE-p9DRd.mjs → BackgroundColorPlugin.native-50iAT9xU.mjs} +119 -122
- package/dist/CodePlugin.native-DlpTPdkd.mjs +2691 -0
- package/dist/{CommentsPlugin.native-tMnWn8a2.mjs → CommentsPlugin.native-DPSqTkiv.mjs} +153 -135
- package/dist/{DocumentManagerPlugin.native-BvZL5CSG.mjs → DocumentManagerPlugin.native-C2cs_1w4.mjs} +43 -43
- package/dist/{EmbedIframePlugin.native-CSWIB1jm.mjs → EmbedIframePlugin.native-DKJx2OS7.mjs} +61 -58
- package/dist/{EmojisPlugin.native-DxTm_DL-.mjs → EmojisPlugin.native-CitxxlWX.mjs} +135 -104
- package/dist/{LinkPlugin.native-CS2g-G18.mjs → LinkPlugin.native-DYCIcdTm.mjs} +47 -45
- package/dist/{MathPlugin.native-KUxz0o8C.mjs → MathPlugin.native-f_mDp8VL.mjs} +149 -108
- package/dist/{MediaManagerPlugin.native-CgP5iInD.mjs → MediaManagerPlugin.native-BiXiK8FC.mjs} +238 -217
- package/dist/MergeTagPlugin.native-C3eOfEgw.mjs +559 -0
- package/dist/{PageBreakPlugin.native-CGiQxXqR.mjs → PageBreakPlugin.native-CXdX5fAv.mjs} +77 -68
- package/dist/{SpecialCharactersPlugin.native-DANrbExJ.mjs → SpecialCharactersPlugin.native-CZDato89.mjs} +143 -98
- package/dist/{SpellCheckPlugin.native-C8bPvRHy.mjs → SpellCheckPlugin.native-BZB9AewP.mjs} +239 -219
- package/dist/{TemplatePlugin.native-4lKEm-WY.mjs → TemplatePlugin.native-CrpfKRJ8.mjs} +167 -143
- package/dist/{TextColorPlugin.native-Clgtb50j.mjs → TextColorPlugin.native-Bwl_bSmc.mjs} +134 -118
- package/dist/_commonjsHelpers-DOllISpa.mjs +32 -0
- package/dist/anchoredPopover-Bxds0VoB.mjs +110 -0
- package/dist/documentManager-vQ1VkbUY.mjs +8418 -0
- package/dist/editora.min.js +10 -10
- package/dist/editora.umd.js +10 -10
- package/dist/html2canvas.esm-AYkPY5LS.mjs +4803 -0
- package/dist/{index-CqWQFb3D.js → index-BpE6GFbz.js} +4 -4
- package/dist/index-BslAFzmv.mjs +16544 -0
- package/dist/{index-OwnkG39N.mjs → index-yzU4NdPT.mjs} +200 -183
- package/dist/index.cjs.js +1 -1
- package/dist/{index.es-CuicffkQ.mjs → index.es-BYD2KEo6.mjs} +5 -4
- package/dist/index.esm.js +2 -2
- package/dist/jspdf.es.min-BJGtOnRT.mjs +7890 -0
- package/dist/plugin-loader.js +15 -15
- package/dist/webcomponent-core.js +241 -224
- package/dist/webcomponent-core.min.css +1 -1
- package/dist/webcomponent-core.min.js +86 -106
- package/dist/webcomponent.cjs.js +1 -1
- package/dist/webcomponent.esm.js +1 -1
- package/dist/webcomponent.js +205 -188
- package/dist/webcomponent.min.css +1 -1
- package/dist/webcomponent.min.js +477 -402
- package/package.json +16 -10
- package/dist/CodePlugin.native-B263UI8O.mjs +0 -2173
- package/dist/MergeTagPlugin.native-DIGWhdnF.mjs +0 -419
- package/dist/colorSelectionApply-CK1My9N2.mjs +0 -67
- package/dist/documentManager-irzj9n3V.mjs +0 -37627
package/dist/editora.min.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var Editora=(function(c){"use strict";class y{constructor(e,t,o){this.doc=e,this.selection=t,this.schema=o}static create(e,t){const o=t||e.node("doc",{},[e.node("paragraph")]);return new y(o,{anchor:0,head:0},e)}apply(e,t){return new y(e,t||this.selection,this.schema)}}class L{constructor(e,t){this.nodes=new Map(Object.entries(e)),this.marks=new Map(Object.entries(t))}node(e,t,o){return{type:e,attrs:t,content:o}}text(e,t){return{type:"text",text:e,marks:t}}}class k{constructor(){this.plugins=[],this.pluginConfigs=new Map}register(e,t){this.plugins.push(e),t&&this.pluginConfigs.set(e.name,t);const o=this.pluginConfigs.get(e.name)||e.config;if(e.initialize)try{e.initialize(o)}catch(i){console.error(`Failed to initialize plugin "${e.name}":`,i)}if(e.init&&e.init!==e.initialize)try{e.init(o)}catch(i){console.error(`Failed to run init hook for plugin "${e.name}":`,i)}}unregister(e){const t=this.plugins.findIndex(o=>o.name===e);if(t>-1){const o=this.plugins[t];o.destroy&&o.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(o=>{o.nodes&&Object.assign(e,o.nodes),o.marks&&Object.assign(t,o.marks)}),new L(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,...o){const i=this.getPlugin(e);if(!i)throw new Error(`Plugin not found: ${e}`);const n=this.getPluginConfig(e)||i.config||{},a=n.mode||"local";try{switch(a){case"local":return i.executeLocal?i.executeLocal(t,...o):null;case"api":if(!i.executeAPI)throw new Error(`Plugin ${e} does not support API mode`);return await i.executeAPI(t,...o);case"hybrid":if(i.executeHybrid)return await i.executeHybrid(t,...o);try{if(i.executeAPI)return await i.executeAPI(t,...o)}catch(r){if(console.warn(`API execution failed for ${e}, falling back to local`,r),i.executeLocal&&n.fallbackToLocal!==!1)return i.executeLocal(t,...o);throw r}break;default:throw new Error(`Unknown plugin mode: ${a}`)}}catch(r){throw console.error(`Error executing command ${t} on plugin ${e}:`,r),r}}async destroyAll(){const e=this.plugins.filter(t=>t.destroy).map(t=>t.destroy());await Promise.all(e),this.plugins=[],this.pluginConfigs.clear()}}class q{constructor(e){if(this.listeners=[],e instanceof k)this.pluginManager=e;else{const o=e;this.pluginManager=new k,o.plugins&&Array.isArray(o.plugins)&&o.plugins.forEach(i=>{this.pluginManager.register(i)}),o.element&&(this.domElement=o.element,this.setupDOMElement(o))}const t=this.pluginManager.buildSchema();this.state=y.create(t),this.commands=this.pluginManager.getCommands()}setupDOMElement(e){this.domElement&&(e.enableToolbar!==!1&&e.toolbarElement?this.toolbarElement=e.toolbarElement:e.enableToolbar!==!1&&(this.toolbarElement=document.createElement("div"),this.toolbarElement.className="editora-toolbar-container",this.domElement.appendChild(this.toolbarElement)),this.contentElement=document.createElement("div"),this.contentElement.contentEditable="true",this.contentElement.className="editora-content",this.contentElement.style.minHeight="200px",this.contentElement.style.outline="none",this.contentElement.style.padding="12px",e.content&&(this.contentElement.innerHTML=e.content),this.domElement.appendChild(this.contentElement),this.contentElement.addEventListener("input",()=>{this.listeners.forEach(t=>t(this.state))}))}setupKeyboardShortcuts(e){const t={};e.forEach(o=>{o.shortcut&&(t[o.shortcut.toLowerCase()]=o.command)}),document.addEventListener("keydown",o=>{if(this.contentElement!==document.activeElement&&!(document.activeElement instanceof HTMLElement&&document.activeElement.contentEditable==="true"))return;const i=[];(o.ctrlKey||o.metaKey)&&i.push("ctrl"),o.shiftKey&&i.push("shift"),o.altKey&&i.push("alt");const n=o.key.toLowerCase(),a=i.length>0?`${i.join("+")}+${n}`:n,r=t[a];r&&(o.preventDefault(),this.execCommand(r))})}handleToolbarCommand(e,t){const i=this.pluginManager.getToolbarItems().find(n=>n.id&&n.id===e||n.command===e);i!=null&&i.command&&(t!==void 0?this.execCommand(i.command,t):this.execCommand(i.command))}setState(e){this.state=e,this.listeners.forEach(t=>t(e))}onChange(e){return this.listeners.push(e),()=>{this.listeners=this.listeners.filter(t=>t!==e)}}on(e,t){return e==="change"||e==="input"?this.onChange(t):()=>{}}getElement(){return this.contentElement||this.domElement||null}execCommand(e,t){const o=this.commands[e];if(!o)return console.warn(`Command not found: ${e}`),!1;let i;return t!==void 0?i=o(this.state,t):i=o(this.state),i instanceof Promise?(i.then(n=>{n&&typeof n=="object"&&"doc"in n&&"selection"in n&&this.setState(n)}).catch(n=>{console.error(`Async command failed: ${e}`,n)}),!0):i&&typeof i=="object"&&"doc"in i&&"selection"in i?(this.setState(i),!0):i!==!1&&i!=null}setContent(e){typeof e=="string"?this.contentElement&&(this.contentElement.innerHTML=e):this.setState(this.state.apply(e))}getContent(){return this.contentElement?this.contentElement.innerHTML:this.state.doc}destroy(){this.listeners=[],this.contentElement&&this.contentElement.removeEventListener("input",()=>{})}}class M{constructor(e){this.initialized=!1,this.plugin=e}initialize(e){var t,o;if(this.initialized)return console.warn(`Plugin "${this.plugin.name}" already initialized`),!1;try{return this.context=e,(t=this.plugin.context)!=null&&t.initialize&&this.plugin.context.initialize(),(o=this.plugin.context)!=null&&o.onEditorReady&&e.provider&&this.plugin.context.onEditorReady(e),this.initialized=!0,!0}catch(i){return console.error(`Failed to initialize plugin "${this.plugin.name}":`,i),!1}}destroy(){var e;if(!this.initialized)return!1;try{return(e=this.plugin.context)!=null&&e.destroy&&this.plugin.context.destroy(),this.initialized=!1,this.context=void 0,!0}catch(t){return console.error(`Failed to destroy plugin "${this.plugin.name}":`,t),!1}}executeCommand(e,...t){var o;if(!this.initialized)return console.warn(`Plugin "${this.plugin.name}" not initialized, cannot execute command "${e}"`),null;try{const i=(o=this.plugin.commands)==null?void 0:o[e];return i?i(...t):(console.warn(`Command "${e}" not found in plugin "${this.plugin.name}"`),null)}catch(i){return console.error(`Error executing command "${e}" in plugin "${this.plugin.name}":`,i),null}}getName(){return this.plugin.name}isInitialized(){return this.initialized}getPlugin(){return this.plugin}getContext(){return this.context}}function U(s){return new M(s)}class T{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 o=this.getEventKey(e),i=this.shortcuts.get(o);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 o=e.key.length===1?e.key.toUpperCase():e.key;return t.push(o),t.join("+")}getShortcutsHelp(){const e=this.getAllShortcuts(),t=new Map;e.forEach(i=>{const n=this.getShortcutCategory(i.command);t.has(n)||t.set(n,[]),t.get(n).push(i)});let o=`# Keyboard Shortcuts
|
|
1
|
+
var Editora=(function(d){"use strict";class y{constructor(e,t,o){this.doc=e,this.selection=t,this.schema=o}static create(e,t){const o=t||e.node("doc",{},[e.node("paragraph")]);return new y(o,{anchor:0,head:0},e)}apply(e,t){return new y(e,t||this.selection,this.schema)}}class L{constructor(e,t){this.nodes=new Map(Object.entries(e)),this.marks=new Map(Object.entries(t))}node(e,t,o){return{type:e,attrs:t,content:o}}text(e,t){return{type:"text",text:e,marks:t}}}class w{constructor(){this.plugins=[],this.pluginConfigs=new Map}register(e,t){this.plugins.push(e),t&&this.pluginConfigs.set(e.name,t);const o=this.pluginConfigs.get(e.name)||e.config;if(e.initialize)try{e.initialize(o)}catch(i){console.error(`Failed to initialize plugin "${e.name}":`,i)}if(e.init&&e.init!==e.initialize)try{e.init(o)}catch(i){console.error(`Failed to run init hook for plugin "${e.name}":`,i)}}unregister(e){const t=this.plugins.findIndex(o=>o.name===e);if(t>-1){const o=this.plugins[t];o.destroy&&o.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(o=>{o.nodes&&Object.assign(e,o.nodes),o.marks&&Object.assign(t,o.marks)}),new L(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,...o){const i=this.getPlugin(e);if(!i)throw new Error(`Plugin not found: ${e}`);const n=this.getPluginConfig(e)||i.config||{},a=n.mode||"local";try{switch(a){case"local":return i.executeLocal?i.executeLocal(t,...o):null;case"api":if(!i.executeAPI)throw new Error(`Plugin ${e} does not support API mode`);return await i.executeAPI(t,...o);case"hybrid":if(i.executeHybrid)return await i.executeHybrid(t,...o);try{if(i.executeAPI)return await i.executeAPI(t,...o)}catch(r){if(console.warn(`API execution failed for ${e}, falling back to local`,r),i.executeLocal&&n.fallbackToLocal!==!1)return i.executeLocal(t,...o);throw r}break;default:throw new Error(`Unknown plugin mode: ${a}`)}}catch(r){throw console.error(`Error executing command ${t} on plugin ${e}:`,r),r}}async destroyAll(){const e=this.plugins.filter(t=>t.destroy).map(t=>t.destroy());await Promise.all(e),this.plugins=[],this.pluginConfigs.clear()}}class q{constructor(e){if(this.listeners=[],e instanceof w)this.pluginManager=e;else{const o=e;this.pluginManager=new w,o.plugins&&Array.isArray(o.plugins)&&o.plugins.forEach(i=>{this.pluginManager.register(i)}),o.element&&(this.domElement=o.element,this.setupDOMElement(o))}const t=this.pluginManager.buildSchema();this.state=y.create(t),this.commands=this.pluginManager.getCommands()}setupDOMElement(e){this.domElement&&(e.enableToolbar!==!1&&e.toolbarElement?this.toolbarElement=e.toolbarElement:e.enableToolbar!==!1&&(this.toolbarElement=document.createElement("div"),this.toolbarElement.className="editora-toolbar-container",this.domElement.appendChild(this.toolbarElement)),this.contentElement=document.createElement("div"),this.contentElement.contentEditable="true",this.contentElement.className="editora-content",this.contentElement.style.minHeight="200px",this.contentElement.style.outline="none",this.contentElement.style.padding="12px",e.content&&(this.contentElement.innerHTML=e.content),this.domElement.appendChild(this.contentElement),this.contentElement.addEventListener("input",()=>{this.listeners.forEach(t=>t(this.state))}))}setupKeyboardShortcuts(e){const t={};e.forEach(o=>{o.shortcut&&(t[o.shortcut.toLowerCase()]=o.command)}),document.addEventListener("keydown",o=>{if(this.contentElement!==document.activeElement&&!(document.activeElement instanceof HTMLElement&&document.activeElement.contentEditable==="true"))return;const i=[];(o.ctrlKey||o.metaKey)&&i.push("ctrl"),o.shiftKey&&i.push("shift"),o.altKey&&i.push("alt");const n=o.key.toLowerCase(),a=i.length>0?`${i.join("+")}+${n}`:n,r=t[a];r&&(o.preventDefault(),this.execCommand(r))})}handleToolbarCommand(e,t){const i=this.pluginManager.getToolbarItems().find(n=>n.id&&n.id===e||n.command===e);i!=null&&i.command&&(t!==void 0?this.execCommand(i.command,t):this.execCommand(i.command))}setState(e){this.state=e,this.listeners.forEach(t=>t(e))}onChange(e){return this.listeners.push(e),()=>{this.listeners=this.listeners.filter(t=>t!==e)}}on(e,t){return e==="change"||e==="input"?this.onChange(t):()=>{}}getElement(){return this.contentElement||this.domElement||null}execCommand(e,t){const o=this.commands[e];if(!o)return console.warn(`Command not found: ${e}`),!1;let i;return t!==void 0?i=o(this.state,t):i=o(this.state),i instanceof Promise?(i.then(n=>{n&&typeof n=="object"&&"doc"in n&&"selection"in n&&this.setState(n)}).catch(n=>{console.error(`Async command failed: ${e}`,n)}),!0):i&&typeof i=="object"&&"doc"in i&&"selection"in i?(this.setState(i),!0):i!==!1&&i!=null}setContent(e){typeof e=="string"?this.contentElement&&(this.contentElement.innerHTML=e):this.setState(this.state.apply(e))}getContent(){return this.contentElement?this.contentElement.innerHTML:this.state.doc}destroy(){this.listeners=[],this.contentElement&&this.contentElement.removeEventListener("input",()=>{})}}class M{constructor(e){this.initialized=!1,this.plugin=e}initialize(e){var t,o;if(this.initialized)return console.warn(`Plugin "${this.plugin.name}" already initialized`),!1;try{return this.context=e,(t=this.plugin.context)!=null&&t.initialize&&this.plugin.context.initialize(),(o=this.plugin.context)!=null&&o.onEditorReady&&e.provider&&this.plugin.context.onEditorReady(e),this.initialized=!0,!0}catch(i){return console.error(`Failed to initialize plugin "${this.plugin.name}":`,i),!1}}destroy(){var e;if(!this.initialized)return!1;try{return(e=this.plugin.context)!=null&&e.destroy&&this.plugin.context.destroy(),this.initialized=!1,this.context=void 0,!0}catch(t){return console.error(`Failed to destroy plugin "${this.plugin.name}":`,t),!1}}executeCommand(e,...t){var o;if(!this.initialized)return console.warn(`Plugin "${this.plugin.name}" not initialized, cannot execute command "${e}"`),null;try{const i=(o=this.plugin.commands)==null?void 0:o[e];return i?i(...t):(console.warn(`Command "${e}" not found in plugin "${this.plugin.name}"`),null)}catch(i){return console.error(`Error executing command "${e}" in plugin "${this.plugin.name}":`,i),null}}getName(){return this.plugin.name}isInitialized(){return this.initialized}getPlugin(){return this.plugin}getContext(){return this.context}}function U(l){return new M(l)}class T{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 o=this.getEventKey(e),i=this.shortcuts.get(o);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 o=e.key.length===1?e.key.toUpperCase():e.key;return t.push(o),t.join("+")}getShortcutsHelp(){const e=this.getAllShortcuts(),t=new Map;e.forEach(i=>{const n=this.getShortcutCategory(i.command);t.has(n)||t.set(n,[]),t.get(n).push(i)});let o=`# Keyboard Shortcuts
|
|
2
2
|
|
|
3
3
|
`;return t.forEach((i,n)=>{o+=`## ${n}
|
|
4
4
|
|
|
5
5
|
`,i.forEach(a=>{const r=this.getShortcutDescription(a);o+=`- **${r}**: ${a.description||a.command}
|
|
6
6
|
`}),o+=`
|
|
7
|
-
`}),o}getShortcutCategory(e){return e.includes("toggle")&&(e.includes("Bold")||e.includes("Italic")||e.includes("Underline")||e.includes("Strike")||e.includes("Code")||e.includes("Super")||e.includes("Sub"))?"Text Formatting":e.includes("Heading")||e.includes("Paragraph")?"Block Formatting":e.includes("List")||e.includes("Checklist")?"Lists":e.includes("Alignment")||e.includes("Indent")?"Alignment & Indentation":e.includes("undo")||e.includes("redo")?"History":e.includes("insert")?"Insert":e.includes("find")||e.includes("replace")?"Find & Replace":e.includes("Accessibility")||e.includes("spell")?"Tools":"Other"}}function W(s={}){const{enabled:e=!1,provider:t="browser",apiUrl:o="",apiHeaders:i={},language:n="en",customDictionary:a=[],ignoreAllCaps:r=!0,ignoreNumbers:l=!0}=s;return{name:"spellcheck",context:{initialize:()=>{if(e)switch(console.log("[Spellcheck Plugin] Initialized",{provider:t,language:n}),t){case"browser":console.log("[Spellcheck] Using browser spellcheck");break;case"local":console.log("[Spellcheck] Using local dictionary (not implemented)");break;case"api":o?console.log("[Spellcheck] Using API:",o):console.warn("[Spellcheck] API provider selected but no apiUrl provided");break}},destroy:()=>{console.log("[Spellcheck Plugin] Destroyed")},onEditorReady:d=>{console.log("[Spellcheck Plugin] Editor ready")}},commands:{toggleSpellcheck:()=>(console.log("[Spellcheck] Toggle command (not implemented)"),null),addToDictionary:d=>(console.log("[Spellcheck] Add to dictionary:",d),null),checkSpelling:async()=>(console.log("[Spellcheck] Check spelling (not implemented)"),null)},toolbar:e?[{label:"Spellcheck",command:"toggleSpellcheck",icon:"Aa",type:"button"}]:[]}}function K(s={}){const{uploadUrl:e="",libraryUrl:t="",maxFileSize:o=10485760,allowedTypes:i=["image/jpeg","image/png","image/gif","image/webp"],headers:n={},withCredentials:a=!1,chunkSize:r=1048576,enableChunking:l=!0,onProgress:d,onError:u,onSuccess:f}=s;return{name:"media",context:{initialize:()=>{console.log("[Media Plugin] Initialized",{uploadUrl:e,libraryUrl:t,maxFileSize:o,allowedTypes:i}),e||console.warn("[Media] No uploadUrl provided - upload will not work")},destroy:()=>{console.log("[Media Plugin] Destroyed")},onEditorReady:h=>{console.log("[Media Plugin] Editor ready")}},commands:{insertImage:async h=>{if(console.log("[Media] Insert image command (not implemented)",h),!h)return console.log("[Media] No file provided - should open picker"),null;if(!i.includes(h.type)){const p=new Error(`File type ${h.type} not allowed`);return u==null||u(p),null}if(h.size>o){const p=new Error(`File size ${h.size} exceeds max ${o}`);return u==null||u(p),null}return null},openMediaLibrary:()=>(console.log("[Media] Open media library (not implemented)"),t||console.warn("[Media] No libraryUrl provided"),null),uploadMedia:async h=>(console.log("[Media] Upload media (not implemented)",{name:h.name,size:h.size,type:h.type}),null)},toolbar:[{label:"Image",command:"insertImage",icon:"🖼️",type:"button"},{label:"Media Library",command:"openMediaLibrary",icon:"📁",type:"button"}]}}class A{constructor(e={}){this.commands=new Map,Object.entries(e).forEach(([t,o])=>{this.register(t,o)})}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 w{constructor(e={}){this.listeners=new Map,this.isReadonly=!1,this.isDestroyed=!1,this.isReadonly=e.readonly||!1,this.pluginManager=new k,e.plugins&&Array.isArray(e.plugins)&&e.plugins.forEach(o=>this.pluginManager.register(o));const t=this.pluginManager.buildSchema();this.state=y.create(t),this.commandRegistry=new A(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 o=this.commandRegistry.get(e);if(!o)return console.warn(`Command not found: ${e}`),!1;let i;return t!==void 0?i=o(this.state,t):i=o(this.state),i instanceof Promise?(i.then(n=>{n&&typeof n=="object"&&"doc"in n&&"selection"in n&&(this.setState(n),this.emit("change",this.state))}).catch(n=>{console.error(`Async command failed: ${e}`,n)}),!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 o=this.listeners.get(e);if(o){const i=o.indexOf(t);i>-1&&o.splice(i,1)}}}emit(e,...t){const o=this.listeners.get(e);o&&o.forEach(i=>{try{i(...t)}catch(n){console.error(`Error in ${e} handler:`,n)}})}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.listeners.clear(),this.emit("destroy"))}isEditorDestroyed(){return this.isDestroyed}}class v{constructor(e,t={anchor:0,head:0}){this.doc=e,this.selection=t}getDocument(){return this.doc}setDocument(e){return new v(e,this.selection)}getSelection(){return{...this.selection}}setSelection(e){return new v(this.doc,e)}update(e,t){return new v(e||this.doc,t||this.selection)}getTextContent(){return""}isSelectionEmpty(){return this.selection.anchor===this.selection.head}}class x{constructor(e,t,o){this.config=e,this.plugins=t,this.pluginLoader=o}setCommandHandler(e){this.commandHandler=e}parseToolbarString(e){const t=[],o=e.split("|").map(r=>r.trim()),i=this.getAvailableToolbarItems(),n=new Map;i.forEach(r=>{r.command&&n.set(r.command,r),r.type==="group"&&r.label&&n.set(r.label,r)});const a={bold:"toggleBold",italic:"toggleItalic",underline:"toggleUnderline",strikethrough:"toggleStrikethrough",bullist:"toggleBulletList",numlist:"toggleOrderedList",checklist:"toggleChecklist",link:"openLinkDialog",image:"openImageDialog",table:"insertTable",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",pageBreak:"insertPageBreak",template:"insertTemplate",importWord:"importWord",exportWord:"exportWord",exportPdf:"exportPdf",insertImage:"insertImage",insertVideo:"insertVideo",codeBlock:"insertCodeBlock"};return o.forEach(r=>{const l=[];r.split(/\s+/).filter(Boolean).forEach(u=>{if(u==="direction"){const p=n.get("setDirectionLTR"),m=n.get("setDirectionRTL");p&&l.push({id:"directionLTR",label:p.label,command:p.command,icon:p.icon,type:p.type||"button",options:p.options}),m&&l.push({id:"directionRTL",label:m.label,command:m.command,icon:m.icon,type:m.type||"button",options:m.options});return}if(u==="comments"){const p=n.get("addComment"),m=n.get("toggleComments");p&&l.push({id:"addComment",label:p.label,command:p.command,icon:p.icon,type:p.type||"button",options:p.options}),m&&l.push({id:"toggleComments",label:m.label,command:m.command,icon:m.icon,type:m.type||"button",options:m.options});return}const f=a[u]||u;let h=n.get(f);h||(h=n.get(u)),h&&l.push({id:u,label:h.label,command:h.command,icon:h.icon,type:h.type==="separator"?"separator":h.type||"button",options:h.options,items:h.items})}),l.length>0&&t.push(l)}),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=this.config.items||this.getDefaultToolbarString(),o=this.parseToolbarString(t);o.forEach((i,n)=>{const a=document.createElement("div");if(a.className="editora-toolbar-group",i.forEach(r=>{this.appendToolbarButton(a,r)}),e.appendChild(a),n<o.length-1){const r=document.createElement("div");r.className="editora-toolbar-separator",e.appendChild(r)}})}appendToolbarButton(e,t){if(t.type==="separator"){const o=document.createElement("div");o.className="editora-toolbar-separator",e.appendChild(o)}else if(t.type==="dropdown"){const o=this.createDropdown(t);e.appendChild(o)}else if(t.type==="inline-menu"){const o=this.createInlineMenu(t);e.appendChild(o)}else if(t.type==="group"&&t.items&&t.items.length){const o=this.createGroupButton(t);e.appendChild(o)}else if(t.type==="input"){const o=this.createInput(t);e.appendChild(o)}else{const o=this.createButton(t);e.appendChild(o)}}createGroupButton(e){const t=document.createElement("div");if(t.className="editora-toolbar-group-button",t.title=e.label,e.icon)if(e.icon.startsWith("<svg")&&e.icon.endsWith("</svg>")){const o=document.createElement("span");o.className="editora-toolbar-icon",o.innerHTML=e.icon,t.appendChild(o)}else t.innerHTML=e.icon;if(e.items&&e.items.length){const o=document.createElement("div");o.className="editora-toolbar-group-items",e.items.forEach(i=>{this.appendToolbarButton(o,i)}),t.appendChild(o)}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",o=>{o.preventDefault(),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 o=document.createElement("span");o.className="editora-toolbar-icon",o.innerHTML=e.icon,t.appendChild(o)}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",o=>{o.preventDefault(),this.commandHandler&&e.command&&this.commandHandler(e.command)}),t}createDropdown(e){const t=document.createElement("div");t.className="editora-toolbar-dropdown";const o=document.createElement("button");o.className="editora-toolbar-button editora-toolbar-dropdown-trigger",o.type="button",o.textContent=e.label;const i=document.createElement("div");i.className="editora-toolbar-dropdown-menu",i.style.display="none",e.options&&e.options.forEach(a=>{const r=document.createElement("button");r.className="editora-toolbar-dropdown-item",r.type="button",r.textContent=a.label,r.setAttribute("data-value",a.value),r.addEventListener("click",l=>{l.preventDefault(),this.commandHandler&&e.command&&this.commandHandler(e.command,a.value),i.style.display="none"}),i.appendChild(r)}),o.addEventListener("click",a=>{a.preventDefault(),a.stopPropagation();const r=i.style.display==="block";i.style.display=r?"none":"block"});const n=a=>{t.contains(a.target)||(i.style.display="none")};return document.addEventListener("click",n),t._cleanupDropdown=()=>{document.removeEventListener("click",n)},t.appendChild(o),t.appendChild(i),t}createInlineMenu(e){const t=document.createElement("div");t.className="editora-toolbar-dropdown editora-toolbar-inline-menu";const o=document.createElement("button");if(o.className="editora-toolbar-button",o.type="button",o.title=e.label,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,o.appendChild(n)}else o.innerHTML=e.icon;else o.textContent=e.label;const i=document.createElement("div");return i.className="editora-toolbar-dropdown-menu",i.style.display="none",e.options&&e.options.forEach(n=>{const a=document.createElement("button");a.className="editora-toolbar-dropdown-item",a.type="button",a.textContent=n.label,a.setAttribute("data-value",n.value),a.addEventListener("click",r=>{r.preventDefault(),r.stopPropagation(),this.commandHandler&&e.command&&this.commandHandler(e.command,n.value),i.style.display="none"}),i.appendChild(a)}),o.addEventListener("click",n=>{var r;n.preventDefault(),n.stopPropagation();const a=(r=this.container)==null?void 0:r.querySelectorAll(".editora-toolbar-dropdown-menu");a==null||a.forEach(l=>{l!==i&&(l.style.display="none")}),i.style.display=i.style.display==="none"?"block":"none"}),document.addEventListener("click",n=>{t.contains(n.target)||(i.style.display="none")}),t.appendChild(o),t.appendChild(i),t}getDefaultToolbarString(){return this.getAvailableToolbarItems().map(t=>t.command).join(" ")}updateButtonState(e,t){if(!this.container)return;const o=this.container.querySelector(`[data-command="${e}"]`);o&&(t.active!==void 0&&o.classList.toggle("active",t.active),t.disabled!==void 0&&(o.disabled=t.disabled))}destroy(){this.container&&(this.container.querySelectorAll(".editora-toolbar-dropdown").forEach(t=>{const o=t._cleanupDropdown;o&&o()}),this.container.innerHTML=""),this.commandHandler=void 0}}class I{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 D{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 o=[];if(this.statusInfo.selectionInfo){const n=this.statusInfo.selectionInfo;n.startLine===n.endLine&&n.startColumn===n.endColumn?o.push(`Ln ${n.startLine}, Col ${n.startColumn}`):(n.startLine===n.endLine?o.push(`Ln ${n.startLine}, Col ${n.startColumn}-${n.endColumn}`):o.push(`Ln ${n.startLine}:${n.startColumn} - ${n.endLine}:${n.endColumn}`),o.push(`${n.selectedChars} chars selected`))}else if(this.statusInfo.cursorPosition){const n=this.statusInfo.cursorPosition;o.push(`Ln ${n.line}, Col ${n.column}`)}this.statusInfo.language&&o.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(([n,a])=>{i.push(`${n}: ${a}`)}),o.forEach((n,a)=>{const r=document.createElement("span");if(r.className="editora-statusbar-item",r.textContent=n,e.appendChild(r),a<o.length-1){const l=document.createElement("span");l.className="editora-statusbar-separator",l.textContent="|",e.appendChild(l)}}),i.forEach((n,a)=>{const r=document.createElement("span");if(r.className="editora-statusbar-item",r.textContent=n,t.appendChild(r),a<i.length-1){const l=document.createElement("span");l.className="editora-statusbar-separator",l.textContent="|",t.appendChild(l)}}),this.container.appendChild(e),this.container.appendChild(t)}destroy(){this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container),this.container=void 0}}class b{constructor(e){this.config={closeOnEscape:!0,closeOnBackdrop:!0,...e},this.element=this.createElement(),this.attachEventListeners()}createElement(){const e=document.createElement("dialog");e.className="editora-dialog",this.config.width&&(e.style.width=this.config.width),this.config.height&&(e.style.height=this.config.height);const t=this.config.buttons&&this.config.buttons.length>0?this.config.buttons.map((o,i)=>`<button type="button" class="editora-btn ${o.type==="danger"?"editora-btn-danger":o.type==="primary"||o.primary?"editora-btn-primary":"editora-btn-cancel"}" data-dialog-button="${i}">${o.label}</button>`).join(""):`
|
|
7
|
+
`}),o}getShortcutCategory(e){return e.includes("toggle")&&(e.includes("Bold")||e.includes("Italic")||e.includes("Underline")||e.includes("Strike")||e.includes("Code")||e.includes("Super")||e.includes("Sub"))?"Text Formatting":e.includes("Heading")||e.includes("Paragraph")?"Block Formatting":e.includes("List")||e.includes("Checklist")?"Lists":e.includes("Alignment")||e.includes("Indent")?"Alignment & Indentation":e.includes("undo")||e.includes("redo")?"History":e.includes("insert")?"Insert":e.includes("find")||e.includes("replace")?"Find & Replace":e.includes("Accessibility")||e.includes("spell")?"Tools":"Other"}}function W(l={}){const{enabled:e=!1,provider:t="browser",apiUrl:o="",apiHeaders:i={},language:n="en",customDictionary:a=[],ignoreAllCaps:r=!0,ignoreNumbers:s=!0}=l;return{name:"spellcheck",context:{initialize:()=>{if(e)switch(console.log("[Spellcheck Plugin] Initialized",{provider:t,language:n}),t){case"browser":console.log("[Spellcheck] Using browser spellcheck");break;case"local":console.log("[Spellcheck] Using local dictionary (not implemented)");break;case"api":o?console.log("[Spellcheck] Using API:",o):console.warn("[Spellcheck] API provider selected but no apiUrl provided");break}},destroy:()=>{console.log("[Spellcheck Plugin] Destroyed")},onEditorReady:c=>{console.log("[Spellcheck Plugin] Editor ready")}},commands:{toggleSpellcheck:()=>(console.log("[Spellcheck] Toggle command (not implemented)"),null),addToDictionary:c=>(console.log("[Spellcheck] Add to dictionary:",c),null),checkSpelling:async()=>(console.log("[Spellcheck] Check spelling (not implemented)"),null)},toolbar:e?[{label:"Spellcheck",command:"toggleSpellcheck",icon:"Aa",type:"button"}]:[]}}function K(l={}){const{uploadUrl:e="",libraryUrl:t="",maxFileSize:o=10485760,allowedTypes:i=["image/jpeg","image/png","image/gif","image/webp"],headers:n={},withCredentials:a=!1,chunkSize:r=1048576,enableChunking:s=!0,onProgress:c,onError:u,onSuccess:f}=l;return{name:"media",context:{initialize:()=>{console.log("[Media Plugin] Initialized",{uploadUrl:e,libraryUrl:t,maxFileSize:o,allowedTypes:i}),e||console.warn("[Media] No uploadUrl provided - upload will not work")},destroy:()=>{console.log("[Media Plugin] Destroyed")},onEditorReady:h=>{console.log("[Media Plugin] Editor ready")}},commands:{insertImage:async h=>{if(console.log("[Media] Insert image command (not implemented)",h),!h)return console.log("[Media] No file provided - should open picker"),null;if(!i.includes(h.type)){const p=new Error(`File type ${h.type} not allowed`);return u==null||u(p),null}if(h.size>o){const p=new Error(`File size ${h.size} exceeds max ${o}`);return u==null||u(p),null}return null},openMediaLibrary:()=>(console.log("[Media] Open media library (not implemented)"),t||console.warn("[Media] No libraryUrl provided"),null),uploadMedia:async h=>(console.log("[Media] Upload media (not implemented)",{name:h.name,size:h.size,type:h.type}),null)},toolbar:[{label:"Image",command:"insertImage",icon:"🖼️",type:"button"},{label:"Media Library",command:"openMediaLibrary",icon:"📁",type:"button"}]}}class A{constructor(e={}){this.commands=new Map,Object.entries(e).forEach(([t,o])=>{this.register(t,o)})}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 k{constructor(e={}){this.listeners=new Map,this.isReadonly=!1,this.isDestroyed=!1,this.isReadonly=e.readonly||!1,this.pluginManager=new w,e.plugins&&Array.isArray(e.plugins)&&e.plugins.forEach(o=>this.pluginManager.register(o));const t=this.pluginManager.buildSchema();this.state=y.create(t),this.commandRegistry=new A(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 o=this.commandRegistry.get(e);if(!o)return console.warn(`Command not found: ${e}`),!1;let i;return t!==void 0?i=o(this.state,t):i=o(this.state),i instanceof Promise?(i.then(n=>{n&&typeof n=="object"&&"doc"in n&&"selection"in n&&(this.setState(n),this.emit("change",this.state))}).catch(n=>{console.error(`Async command failed: ${e}`,n)}),!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 o=this.listeners.get(e);if(o){const i=o.indexOf(t);i>-1&&o.splice(i,1)}}}emit(e,...t){const o=this.listeners.get(e);o&&o.forEach(i=>{try{i(...t)}catch(n){console.error(`Error in ${e} handler:`,n)}})}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.listeners.clear(),this.emit("destroy"))}isEditorDestroyed(){return this.isDestroyed}}class v{constructor(e,t={anchor:0,head:0}){this.doc=e,this.selection=t}getDocument(){return this.doc}setDocument(e){return new v(e,this.selection)}getSelection(){return{...this.selection}}setSelection(e){return new v(this.doc,e)}update(e,t){return new v(e||this.doc,t||this.selection)}getTextContent(){return""}isSelectionEmpty(){return this.selection.anchor===this.selection.head}}class x{setLastCommandTrigger(e,t){if(typeof window=="undefined"||!e)return;const o=t||e.getAttribute("data-command")||void 0;o&&(window.__editoraLastCommandButton=e,window.__editoraLastCommand=o)}constructor(e,t,o){this.config=e,this.plugins=t,this.pluginLoader=o}setCommandHandler(e){this.commandHandler=e}parseToolbarString(e){const t=[],o=e.split("|").map(r=>r.trim()),i=this.getAvailableToolbarItems(),n=new Map;i.forEach(r=>{r.command&&n.set(r.command,r),r.type==="group"&&r.label&&n.set(r.label,r)});const a={bold:"toggleBold",italic:"toggleItalic",underline:"toggleUnderline",strikethrough:"toggleStrikethrough",bullist:"toggleBulletList",numlist:"toggleOrderedList",checklist:"toggleChecklist",link:"openLinkDialog",image:"openImageDialog",table:"insertTable",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",pageBreak:"insertPageBreak",template:"insertTemplate",importWord:"importWord",exportWord:"exportWord",exportPdf:"exportPdf",insertImage:"insertImage",insertVideo:"insertVideo",codeBlock:"insertCodeBlock"};return o.forEach(r=>{const s=[];r.split(/\s+/).filter(Boolean).forEach(u=>{if(u==="direction"){const p=n.get("setDirectionLTR"),m=n.get("setDirectionRTL");p&&s.push({id:"directionLTR",label:p.label,command:p.command,icon:p.icon,type:p.type||"button",options:p.options}),m&&s.push({id:"directionRTL",label:m.label,command:m.command,icon:m.icon,type:m.type||"button",options:m.options});return}if(u==="comments"){const p=n.get("addComment"),m=n.get("toggleComments");p&&s.push({id:"addComment",label:p.label,command:p.command,icon:p.icon,type:p.type||"button",options:p.options}),m&&s.push({id:"toggleComments",label:m.label,command:m.command,icon:m.icon,type:m.type||"button",options:m.options});return}const f=a[u]||u;let h=n.get(f);h||(h=n.get(u)),h&&s.push({id:u,label:h.label,command:h.command,icon:h.icon,type:h.type==="separator"?"separator":h.type||"button",options:h.options,items:h.items})}),s.length>0&&t.push(s)}),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=this.config.items||this.getDefaultToolbarString(),o=this.parseToolbarString(t);o.forEach((i,n)=>{const a=document.createElement("div");if(a.className="editora-toolbar-group",i.forEach(r=>{this.appendToolbarButton(a,r)}),e.appendChild(a),n<o.length-1){const r=document.createElement("div");r.className="editora-toolbar-separator",e.appendChild(r)}})}appendToolbarButton(e,t){if(t.type==="separator"){const o=document.createElement("div");o.className="editora-toolbar-separator",e.appendChild(o)}else if(t.type==="dropdown"){const o=this.createDropdown(t);e.appendChild(o)}else if(t.type==="inline-menu"){const o=this.createInlineMenu(t);e.appendChild(o)}else if(t.type==="group"&&t.items&&t.items.length){const o=this.createGroupButton(t);e.appendChild(o)}else if(t.type==="input"){const o=this.createInput(t);e.appendChild(o)}else{const o=this.createButton(t);e.appendChild(o)}}createGroupButton(e){const t=document.createElement("div");if(t.className="editora-toolbar-group-button",t.title=e.label,e.icon)if(e.icon.startsWith("<svg")&&e.icon.endsWith("</svg>")){const o=document.createElement("span");o.className="editora-toolbar-icon",o.innerHTML=e.icon,t.appendChild(o)}else t.innerHTML=e.icon;if(e.items&&e.items.length){const o=document.createElement("div");o.className="editora-toolbar-group-items",e.items.forEach(i=>{this.appendToolbarButton(o,i)}),t.appendChild(o)}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",o=>{o.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 o=document.createElement("span");o.className="editora-toolbar-icon",o.innerHTML=e.icon,t.appendChild(o)}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",o=>{o.preventDefault(),this.commandHandler&&e.command&&this.commandHandler(e.command)}),t}createDropdown(e){const t=document.createElement("div");t.className="editora-toolbar-dropdown";const o=document.createElement("button");o.className="editora-toolbar-button editora-toolbar-dropdown-trigger",o.type="button",o.textContent=e.label;const i=document.createElement("div");i.className="editora-toolbar-dropdown-menu",i.style.display="none",e.options&&e.options.forEach(r=>{const s=document.createElement("button");s.className="editora-toolbar-dropdown-item",s.type="button",s.textContent=r.label,s.setAttribute("data-value",r.value),s.addEventListener("click",c=>{c.preventDefault(),this.setLastCommandTrigger(o,e.command),this.commandHandler&&e.command&&this.commandHandler(e.command,r.value),i.style.display="none"}),i.appendChild(s)}),o.addEventListener("click",r=>{r.preventDefault(),r.stopPropagation(),this.setLastCommandTrigger(o,e.command);const s=i.style.display==="block";i.style.display=s?"none":"block"});const n=r=>{t.contains(r.target)||(i.style.display="none")},a=r=>{r.key==="Escape"&&(i.style.display="none")};return document.addEventListener("mousedown",n,!0),document.addEventListener("keydown",a),t._cleanupDropdown=()=>{document.removeEventListener("mousedown",n,!0),document.removeEventListener("keydown",a)},t.appendChild(o),t.appendChild(i),t}createInlineMenu(e){const t=document.createElement("div");t.className="editora-toolbar-dropdown editora-toolbar-inline-menu";const o=document.createElement("button");if(o.className="editora-toolbar-button",o.type="button",o.title=e.label,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,o.appendChild(r)}else o.innerHTML=e.icon;else o.textContent=e.label;const i=document.createElement("div");i.className="editora-toolbar-dropdown-menu",i.style.display="none",e.options&&e.options.forEach(r=>{const s=document.createElement("button");s.className="editora-toolbar-dropdown-item",s.type="button",s.textContent=r.label,s.setAttribute("data-value",r.value),s.addEventListener("click",c=>{c.preventDefault(),c.stopPropagation(),this.setLastCommandTrigger(o,e.command),this.commandHandler&&e.command&&this.commandHandler(e.command,r.value),i.style.display="none"}),i.appendChild(s)}),o.addEventListener("click",r=>{var c;r.preventDefault(),r.stopPropagation(),this.setLastCommandTrigger(o,e.command);const s=(c=this.container)==null?void 0:c.querySelectorAll(".editora-toolbar-dropdown-menu");s==null||s.forEach(u=>{u!==i&&(u.style.display="none")}),i.style.display=i.style.display==="none"?"block":"none"});const n=r=>{t.contains(r.target)||(i.style.display="none")},a=r=>{r.key==="Escape"&&(i.style.display="none")};return document.addEventListener("mousedown",n,!0),document.addEventListener("keydown",a),t._cleanupDropdown=()=>{document.removeEventListener("mousedown",n,!0),document.removeEventListener("keydown",a)},t.appendChild(o),t.appendChild(i),t}getDefaultToolbarString(){return this.getAvailableToolbarItems().map(t=>t.command).join(" ")}updateButtonState(e,t){if(!this.container)return;const o=this.container.querySelector(`[data-command="${e}"]`);o&&(t.active!==void 0&&o.classList.toggle("active",t.active),t.disabled!==void 0&&(o.disabled=t.disabled))}destroy(){this.container&&(this.container.querySelectorAll(".editora-toolbar-dropdown").forEach(t=>{const o=t._cleanupDropdown;o&&o()}),this.container.innerHTML=""),this.commandHandler=void 0}}class I{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 D{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 o=[];if(this.statusInfo.selectionInfo){const n=this.statusInfo.selectionInfo;n.startLine===n.endLine&&n.startColumn===n.endColumn?o.push(`Ln ${n.startLine}, Col ${n.startColumn}`):(n.startLine===n.endLine?o.push(`Ln ${n.startLine}, Col ${n.startColumn}-${n.endColumn}`):o.push(`Ln ${n.startLine}:${n.startColumn} - ${n.endLine}:${n.endColumn}`),o.push(`${n.selectedChars} chars selected`))}else if(this.statusInfo.cursorPosition){const n=this.statusInfo.cursorPosition;o.push(`Ln ${n.line}, Col ${n.column}`)}this.statusInfo.language&&o.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(([n,a])=>{i.push(`${n}: ${a}`)}),o.forEach((n,a)=>{const r=document.createElement("span");if(r.className="editora-statusbar-item",r.textContent=n,e.appendChild(r),a<o.length-1){const s=document.createElement("span");s.className="editora-statusbar-separator",s.textContent="|",e.appendChild(s)}}),i.forEach((n,a)=>{const r=document.createElement("span");if(r.className="editora-statusbar-item",r.textContent=n,t.appendChild(r),a<i.length-1){const s=document.createElement("span");s.className="editora-statusbar-separator",s.textContent="|",t.appendChild(s)}}),this.container.appendChild(e),this.container.appendChild(t)}destroy(){this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container),this.container=void 0}}class b{constructor(e){this.config={closeOnEscape:!0,closeOnBackdrop:!0,...e},this.element=this.createElement(),this.attachEventListeners()}createElement(){const e=document.createElement("dialog");e.className="editora-dialog",this.config.width&&(e.style.width=this.config.width),this.config.height&&(e.style.height=this.config.height);const t=this.config.buttons&&this.config.buttons.length>0?this.config.buttons.map((o,i)=>`<button type="button" class="editora-btn ${o.type==="danger"?"editora-btn-danger":o.type==="primary"||o.primary?"editora-btn-primary":"editora-btn-cancel"}" data-dialog-button="${i}">${o.label}</button>`).join(""):`
|
|
8
8
|
<button type="button" class="editora-btn editora-btn-cancel" data-dialog-default="cancel">Cancel</button>
|
|
9
9
|
<button type="button" class="editora-btn editora-btn-primary" data-dialog-default="ok">OK</button>
|
|
10
10
|
`;if(e.innerHTML=`
|
|
@@ -20,7 +20,7 @@ var Editora=(function(c){"use strict";class y{constructor(e,t,o){this.doc=e,this
|
|
|
20
20
|
${t}
|
|
21
21
|
</div>
|
|
22
22
|
</div>
|
|
23
|
-
`,typeof this.config.content!="string"){const o=e.querySelector(".editora-dialog-body");o&&(o.innerHTML="",o.appendChild(this.config.content))}return e}attachEventListeners(){const e=this.element.querySelector(".editora-dialog-close");if(e==null||e.addEventListener("click",()=>this.close()),this.config.buttons&&this.config.buttons.length>0)this.element.querySelectorAll("[data-dialog-button]").forEach(o=>{o.addEventListener("click",()=>{var a,r;const i=Number(o.getAttribute("data-dialog-button")),n=(a=this.config.buttons)==null?void 0:a[i];(r=n==null?void 0:n.onClick)==null||r.call(n)})});else{const t=this.element.querySelector('[data-dialog-default="cancel"]');t==null||t.addEventListener("click",()=>{var i,n;(n=(i=this.config).onCancel)==null||n.call(i),this.close()});const o=this.element.querySelector('[data-dialog-default="ok"]');o==null||o.addEventListener("click",()=>this.handleSubmit())}this.config.closeOnEscape&&this.element.addEventListener("cancel",t=>{t.preventDefault(),this.close()}),this.config.closeOnBackdrop&&this.element.addEventListener("click",t=>{const o=this.element.getBoundingClientRect();(t.clientX<o.left||t.clientX>o.right||t.clientY<o.top||t.clientY>o.bottom)&&this.close()})}handleSubmit(){var t,o,i,n;const e=this.element.querySelector("form");if(e){const a=new FormData(e);(o=(t=this.config).onSubmit)==null||o.call(t,a)}else{const a=this.element.querySelectorAll("input, select, textarea"),r=new FormData;a.forEach(
|
|
23
|
+
`,typeof this.config.content!="string"){const o=e.querySelector(".editora-dialog-body");o&&(o.innerHTML="",o.appendChild(this.config.content))}return e}attachEventListeners(){const e=this.element.querySelector(".editora-dialog-close");if(e==null||e.addEventListener("click",()=>this.close()),this.config.buttons&&this.config.buttons.length>0)this.element.querySelectorAll("[data-dialog-button]").forEach(o=>{o.addEventListener("click",()=>{var a,r;const i=Number(o.getAttribute("data-dialog-button")),n=(a=this.config.buttons)==null?void 0:a[i];(r=n==null?void 0:n.onClick)==null||r.call(n)})});else{const t=this.element.querySelector('[data-dialog-default="cancel"]');t==null||t.addEventListener("click",()=>{var i,n;(n=(i=this.config).onCancel)==null||n.call(i),this.close()});const o=this.element.querySelector('[data-dialog-default="ok"]');o==null||o.addEventListener("click",()=>this.handleSubmit())}this.config.closeOnEscape&&this.element.addEventListener("cancel",t=>{t.preventDefault(),this.close()}),this.config.closeOnBackdrop&&this.element.addEventListener("click",t=>{const o=this.element.getBoundingClientRect();(t.clientX<o.left||t.clientX>o.right||t.clientY<o.top||t.clientY>o.bottom)&&this.close()})}handleSubmit(){var t,o,i,n;const e=this.element.querySelector("form");if(e){const a=new FormData(e);(o=(t=this.config).onSubmit)==null||o.call(t,a)}else{const a=this.element.querySelectorAll("input, select, textarea"),r=new FormData;a.forEach(s=>{s.name&&r.append(s.name,s.value)}),(n=(i=this.config).onSubmit)==null||n.call(i,r)}this.close()}show(){document.body.appendChild(this.element),this.element.showModal()}close(){this.element.close(),this.element.remove()}destroy(){this.close()}}class _{constructor(e){this.isOpen=!1,this.config=e,this.selectedValue=e.value,this.element=this.createElement(),this.attachEventListeners()}createElement(){const e=document.createElement("div");e.className="editora-dropdown",this.config.width&&(e.style.width=this.config.width);const t=this.config.options.find(i=>i.value===this.selectedValue),o=(t==null?void 0:t.label)||this.config.placeholder||"Select...";return e.innerHTML=`
|
|
24
24
|
<button class="editora-dropdown-toggle" type="button">
|
|
25
25
|
<span class="editora-dropdown-label">${o}</span>
|
|
26
26
|
<span class="editora-dropdown-arrow">▼</span>
|
|
@@ -48,7 +48,7 @@ var Editora=(function(c){"use strict";class y{constructor(e,t,o){this.doc=e,this
|
|
|
48
48
|
></button>
|
|
49
49
|
`).join("")}
|
|
50
50
|
</div>
|
|
51
|
-
`,e}attachEventListeners(){const e=this.element.querySelector('input[type="color"]'),t=this.element.querySelector('input[type="text"]');e.addEventListener("input",i=>{var a,r;const n=i.target.value;t.value=n,this.selectedColor=n,(r=(a=this.config).onChange)==null||r.call(a,n)}),t.addEventListener("input",i=>{var a,r;const n=i.target.value;/^#[0-9A-Fa-f]{6}$/.test(n)&&(e.value=n,this.selectedColor=n,(r=(a=this.config).onChange)==null||r.call(a,n))}),this.element.querySelectorAll(".editora-color-preset").forEach(i=>{i.addEventListener("click",()=>{var a,r;const n=i.getAttribute("data-color");n&&(e.value=n,t.value=n,this.selectedColor=n,(r=(a=this.config).onChange)==null||r.call(a,n))})})}getValue(){return this.selectedColor}setValue(e){this.selectedColor=e;const t=this.element.querySelector('input[type="color"]'),o=this.element.querySelector('input[type="text"]');t&&(t.value=e),o&&(o.value=e)}getElement(){return this.element}destroy(){this.element.remove()}}class G{constructor(e){const{initialUrl:t="",initialText:o="",onSubmit:i,onCancel:n}=e;this.dialog=new b({title:"Insert/Edit Link",content:this.createFormHTML(t,o),onSubmit:a=>{const r=(a.get("url")||"").trim(),
|
|
51
|
+
`,e}attachEventListeners(){const e=this.element.querySelector('input[type="color"]'),t=this.element.querySelector('input[type="text"]');e.addEventListener("input",i=>{var a,r;const n=i.target.value;t.value=n,this.selectedColor=n,(r=(a=this.config).onChange)==null||r.call(a,n)}),t.addEventListener("input",i=>{var a,r;const n=i.target.value;/^#[0-9A-Fa-f]{6}$/.test(n)&&(e.value=n,this.selectedColor=n,(r=(a=this.config).onChange)==null||r.call(a,n))}),this.element.querySelectorAll(".editora-color-preset").forEach(i=>{i.addEventListener("click",()=>{var a,r;const n=i.getAttribute("data-color");n&&(e.value=n,t.value=n,this.selectedColor=n,(r=(a=this.config).onChange)==null||r.call(a,n))})})}getValue(){return this.selectedColor}setValue(e){this.selectedColor=e;const t=this.element.querySelector('input[type="color"]'),o=this.element.querySelector('input[type="text"]');t&&(t.value=e),o&&(o.value=e)}getElement(){return this.element}destroy(){this.element.remove()}}class G{constructor(e){const{initialUrl:t="",initialText:o="",onSubmit:i,onCancel:n}=e;this.dialog=new b({title:"Insert/Edit Link",content:this.createFormHTML(t,o),onSubmit:a=>{const r=(a.get("url")||"").trim(),s=(a.get("text")||"").trim(),c=a.get("openInNewTab")==="on";if(!r){alert("Please enter a URL");return}i({url:r,text:s,openInNewTab:c}),this.dialog.close()},onCancel:()=>{n==null||n(),this.dialog.close()},width:"500px"})}createFormHTML(e,t){return`
|
|
52
52
|
<form class="link-dialog-form">
|
|
53
53
|
<div class="form-group">
|
|
54
54
|
<label for="link-url">URL</label>
|
|
@@ -155,7 +155,7 @@ var Editora=(function(c){"use strict";class y{constructor(e,t,o){this.doc=e,this
|
|
|
155
155
|
</button>
|
|
156
156
|
</div>
|
|
157
157
|
</form>
|
|
158
|
-
`}show(){this.dialog.show(),this.attachPreviewListeners()}close(){this.dialog.close()}attachPreviewListeners(){const e=document.querySelector(".table-dialog-form");if(!e)return;const t=e.querySelector("#table-rows"),o=e.querySelector("#table-cols"),i=e.querySelector("#table-header"),n=e.querySelector("#table-preview-content"),a=()=>{const r=parseInt((t==null?void 0:t.value)||"3",10),
|
|
158
|
+
`}show(){this.dialog.show(),this.attachPreviewListeners()}close(){this.dialog.close()}attachPreviewListeners(){const e=document.querySelector(".table-dialog-form");if(!e)return;const t=e.querySelector("#table-rows"),o=e.querySelector("#table-cols"),i=e.querySelector("#table-header"),n=e.querySelector("#table-preview-content"),a=()=>{const r=parseInt((t==null?void 0:t.value)||"3",10),s=parseInt((o==null?void 0:o.value)||"3",10),c=i==null?void 0:i.checked;n&&(n.textContent=`${r} rows × ${s} columns${c?" with header":""}`)};t==null||t.addEventListener("input",a),o==null||o.addEventListener("input",a),i==null||i.addEventListener("change",a)}}class Y{constructor(e){this.config=e;const{onSubmit:t,onCancel:o}=e;this.dialog=new b({title:"Insert Image",content:this.createFormHTML(),onSubmit:i=>{const n=(i.get("src")||"").trim(),a=(i.get("alt")||"").trim(),r=(i.get("width")||"").trim(),s=(i.get("height")||"").trim();if(!n){alert("Please enter an image URL or upload an image");return}t({src:n,alt:a,width:r||void 0,height:s||void 0}),this.dialog.close()},onCancel:()=>{o==null||o(),this.dialog.close()},width:"500px"})}createFormHTML(){return`
|
|
159
159
|
<form class="image-dialog-form">
|
|
160
160
|
${this.config.allowUpload?`
|
|
161
161
|
<div class="form-group">
|
|
@@ -229,7 +229,7 @@ var Editora=(function(c){"use strict";class y{constructor(e,t,o){this.doc=e,this
|
|
|
229
229
|
</button>
|
|
230
230
|
</div>
|
|
231
231
|
</form>
|
|
232
|
-
`}show(){this.dialog.show(),this.attachImagePreview(),this.attachFileUpload()}close(){this.dialog.close()}attachImagePreview(){const e=document.querySelector(".image-dialog-form");if(!e)return;const t=e.querySelector("#image-src"),o=e.querySelector("#image-preview"),i=e.querySelector("#preview-img");t==null||t.addEventListener("input",()=>{const n=t.value.trim();n&&this.isValidImageUrl(n)?(i.src=n,o.style.display="block",i.onerror=()=>{o.style.display="none"}):o.style.display="none"})}attachFileUpload(){if(!this.config.allowUpload)return;const e=document.querySelector(".image-dialog-form");if(!e)return;const t=e.querySelector("#image-upload"),o=e.querySelector("#image-src");t==null||t.addEventListener("change",async i=>{var r;const n=(r=i.target.files)==null?void 0:r[0];if(!n)return;const a=new FileReader;a.onload=
|
|
232
|
+
`}show(){this.dialog.show(),this.attachImagePreview(),this.attachFileUpload()}close(){this.dialog.close()}attachImagePreview(){const e=document.querySelector(".image-dialog-form");if(!e)return;const t=e.querySelector("#image-src"),o=e.querySelector("#image-preview"),i=e.querySelector("#preview-img");t==null||t.addEventListener("input",()=>{const n=t.value.trim();n&&this.isValidImageUrl(n)?(i.src=n,o.style.display="block",i.onerror=()=>{o.style.display="none"}):o.style.display="none"})}attachFileUpload(){if(!this.config.allowUpload)return;const e=document.querySelector(".image-dialog-form");if(!e)return;const t=e.querySelector("#image-upload"),o=e.querySelector("#image-src");t==null||t.addEventListener("change",async i=>{var r;const n=(r=i.target.files)==null?void 0:r[0];if(!n)return;const a=new FileReader;a.onload=s=>{var u;const c=(u=s.target)==null?void 0:u.result;o.value=c,o.dispatchEvent(new Event("input"))},a.readAsDataURL(n)})}isValidImageUrl(e){try{return new URL(e),/\.(jpg|jpeg|png|gif|svg|webp|bmp)$/i.test(e)||e.startsWith("data:image/")}catch(t){return!1}}}class J{constructor(e){this.onSubmit=e.onSubmit;const t=this.createContent();this.dialog=new b({title:"Insert Math Equation",content:t,buttons:[{label:"Cancel",onClick:()=>this.dialog.close()},{label:"Insert",onClick:()=>this.handleSubmit(),primary:!0}]}),this.latexInput=t.querySelector("#math-latex"),this.previewDiv=t.querySelector("#math-preview"),this.displayTypeSelect=t.querySelector("#math-display-type"),this.latexInput.addEventListener("input",()=>this.updatePreview())}createContent(){const e=document.createElement("div");return e.className="math-dialog-content",e.style.minWidth="500px",e.innerHTML=`
|
|
233
233
|
<style>
|
|
234
234
|
.math-dialog-content {
|
|
235
235
|
display: flex;
|
|
@@ -341,7 +341,7 @@ var Editora=(function(c){"use strict";class y{constructor(e,t,o){this.doc=e,this
|
|
|
341
341
|
<option value="block">Block (centered, new line)</option>
|
|
342
342
|
</select>
|
|
343
343
|
</div>
|
|
344
|
-
`,e.querySelectorAll(".math-symbol-btn").forEach(o=>{o.addEventListener("click",i=>{i.preventDefault();const n=o.getAttribute("data-symbol");if(n&&this.latexInput){const a=this.latexInput.selectionStart,r=this.latexInput.selectionEnd,
|
|
344
|
+
`,e.querySelectorAll(".math-symbol-btn").forEach(o=>{o.addEventListener("click",i=>{i.preventDefault();const n=o.getAttribute("data-symbol");if(n&&this.latexInput){const a=this.latexInput.selectionStart,r=this.latexInput.selectionEnd,s=this.latexInput.value;this.latexInput.value=s.substring(0,a)+n+s.substring(r),this.latexInput.focus(),this.latexInput.selectionStart=this.latexInput.selectionEnd=a+n.length,this.updatePreview()}})}),e}updatePreview(){const e=this.latexInput.value.trim();if(!e){this.previewDiv.textContent="";return}let t=e.replace(/\\frac\{([^}]+)\}\{([^}]+)\}/g,"($1)/($2)").replace(/\^\{([^}]+)\}/g,"^$1").replace(/\_\{([^}]+)\}/g,"_$1").replace(/\\sqrt\{([^}]+)\}/g,"√($1)").replace(/\\sum/g,"∑").replace(/\\int/g,"∫").replace(/\\pi/g,"π").replace(/\\alpha/g,"α").replace(/\\beta/g,"β").replace(/\\gamma/g,"γ").replace(/\\theta/g,"θ").replace(/\\lambda/g,"λ").replace(/\\infty/g,"∞").replace(/\\leq/g,"≤").replace(/\\geq/g,"≥").replace(/\\neq/g,"≠");this.previewDiv.textContent=t}handleSubmit(){const e=this.latexInput.value.trim();if(!e){alert("Please enter a LaTeX expression.");return}const t=this.displayTypeSelect.value;this.onSubmit({latex:e,display:t}),this.dialog.close()}show(){this.dialog.show(),this.latexInput.value="",this.previewDiv.textContent="",this.displayTypeSelect.value="inline",setTimeout(()=>this.latexInput.focus(),100)}close(){this.dialog.close()}}class Q{constructor(e){this.characters={common:["©","®","™","§","¶","†","‡","•","‣","⁃","◦","▪","▫","◊","○","●","□","■","△","▲","▽","▼","◇","◆","★","☆"],arrows:["←","→","↑","↓","↔","↕","⇐","⇒","⇑","⇓","⇔","⇕","⟵","⟶","⟷","↖","↗","↘","↙","⇖","⇗","⇘","⇙"],currency:["$","€","£","¥","₹","₽","₩","₪","₦","฿","₴","₡","₵","₸","₫","₱","₲","₳","₭"],math:["±","×","÷","=","≠","≈","≡","≤","≥","<",">","∞","∑","∏","∫","∂","√","∛","∜","°","′","″","∠","∟","⊥","∥"],greek:["α","β","γ","δ","ε","ζ","η","θ","ι","κ","λ","μ","ν","ξ","ο","π","ρ","σ","τ","υ","φ","χ","ψ","ω","Α","Β","Γ","Δ","Ε","Ζ","Η","Θ"],punctuation:["‚","„","“","”","‘","’","«","»","‹","›","—","–","…","·","¡","¿","‰","′","″","‴"],superscript:["⁰","¹","²","³","⁴","⁵","⁶","⁷","⁸","⁹","⁺","⁻","⁼","⁽","⁾","ⁿ","ⁱ"],subscript:["₀","₁","₂","₃","₄","₅","₆","₇","₈","₉","₊","₋","₌","₍","₎"]},this.onSelect=e.onSelect;const t=this.createContent();this.dialog=new b({title:"Insert Special Character",content:t,buttons:[{label:"Close",onClick:()=>this.dialog.close()}]}),this.searchInput=t.querySelector("#char-search"),this.categorySelect=t.querySelector("#char-category"),this.charactersGrid=t.querySelector("#char-grid"),this.searchInput.addEventListener("input",()=>this.filterCharacters()),this.categorySelect.addEventListener("change",()=>this.updateGrid()),this.updateGrid()}createContent(){const e=document.createElement("div");return e.className="character-dialog-content",e.style.minWidth="500px",e.innerHTML=`
|
|
345
345
|
<style>
|
|
346
346
|
.character-dialog-content {
|
|
347
347
|
display: flex;
|
|
@@ -518,7 +518,7 @@ var Editora=(function(c){"use strict";class y{constructor(e,t,o){this.doc=e,this
|
|
|
518
518
|
<div class="emoji-info">
|
|
519
519
|
Click any emoji to insert it into your document.
|
|
520
520
|
</div>
|
|
521
|
-
`,e}updateGrid(){const e=this.categorySelect.value;this.emojisGrid.innerHTML="";let t=[];e==="all"?t=Object.values(this.emojis).flat():t=this.emojis[e]||[],t.forEach(o=>{const i=document.createElement("button");i.className="emoji-button",i.textContent=o,i.title=`Insert ${o}`,i.addEventListener("click",n=>{n.preventDefault(),this.handleSelect(o)}),this.emojisGrid.appendChild(i)})}filterEmojis(){const e=this.searchInput.value.toLowerCase();this.emojisGrid.querySelectorAll(".emoji-button").forEach(o=>{const i=o.textContent||"",n=!e||i.includes(e);o.style.display=n?"flex":"none"})}handleSelect(e){this.onSelect(e),this.dialog.close()}show(){this.dialog.show(),this.searchInput.value="",this.categorySelect.value="popular",this.updateGrid(),setTimeout(()=>this.searchInput.focus(),100)}close(){this.dialog.close()}}function P(
|
|
522
|
-
`),a=n.length,r=n[n.length-1].length+1;return{line:a,column:r}}function z(
|
|
523
|
-
`).length;t=Math.max(1,a)}return t}function N(s){const e=s.trim()?s.trim().split(/\s+/).length:0,t=s.length;return{words:e,chars:t}}function F(s,e){const t=s.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}}const S=class S{static resolve(e){const t={};if(Object.assign(t,this.EDITOR_DEFAULTS),e.pluginDefaults&&Object.assign(t,e.pluginDefaults),e.attributes){const o=this.parseAttributes(e.attributes);Object.assign(t,o)}return e.jsConfig&&Object.assign(t,e.jsConfig),this.normalizeConfig(t)}static normalizeConfig(e){const t={...e};if(t.toolbarFloating!==void 0||t.toolbarSticky!==void 0){const a=typeof t.toolbar=="object"&&t.toolbar?{...t.toolbar}:typeof t.toolbar=="string"?{items:t.toolbar}:{};t.toolbarFloating!==void 0&&(a.floating=!!t.toolbarFloating),t.toolbarSticky!==void 0&&(a.sticky=!!t.toolbarSticky),t.toolbar=a}if(t.toolbarItems!==void 0&&typeof t.toolbar=="object"&&t.toolbar&&(t.toolbar.items=t.toolbarItems),t.autosaveEnabled!==void 0||t.autosaveIntervalMs!==void 0||t.autosaveStorageKey!==void 0||t.autosaveProvider!==void 0||t.autosaveApiUrl!==void 0){const a=typeof t.autosave=="object"&&t.autosave?{...t.autosave}:{};t.autosaveEnabled!==void 0&&(a.enabled=!!t.autosaveEnabled),t.autosaveIntervalMs!==void 0&&(a.intervalMs=Number(t.autosaveIntervalMs)),t.autosaveStorageKey!==void 0&&(a.storageKey=t.autosaveStorageKey),t.autosaveProvider!==void 0&&(a.provider=t.autosaveProvider),t.autosaveApiUrl!==void 0&&(a.apiUrl=t.autosaveApiUrl),t.autosave=a}const o={enabled:!1,intervalMs:3e4,storageKey:"rte-autosave",provider:"localStorage",apiUrl:""};if(typeof t.autosave=="boolean")t.autosave={...o,enabled:t.autosave};else if(typeof t.autosave=="object"&&t.autosave){const a={...o,...t.autosave};a.intervalMs===void 0&&a.interval!==void 0&&(a.intervalMs=Number(a.interval)),a.enabled===void 0&&(a.enabled=!0),(!Number.isFinite(a.intervalMs)||a.intervalMs<=0)&&(a.intervalMs=o.intervalMs),t.autosave=a}else t.autosave=o;if(t.languageLocale!==void 0||t.languageDirection!==void 0){const a=typeof t.language=="object"&&t.language?{...t.language}:{};t.languageLocale!==void 0&&(a.locale=t.languageLocale),t.languageDirection!==void 0&&(a.direction=t.languageDirection),t.language=a}const i={locale:"en",direction:"ltr"};if(typeof t.language=="string"?t.language={locale:t.language,direction:i.direction}:typeof t.language=="object"&&t.language?t.language={...i,...t.language}:t.language=i,t.spellcheckEnabled!==void 0||t.spellcheckProvider!==void 0||t.spellcheckApiUrl!==void 0){const a=typeof t.spellcheck=="object"&&t.spellcheck?{...t.spellcheck}:{};t.spellcheckEnabled!==void 0&&(a.enabled=!!t.spellcheckEnabled),t.spellcheckProvider!==void 0&&(a.provider=t.spellcheckProvider),t.spellcheckApiUrl!==void 0&&(a.apiUrl=t.spellcheckApiUrl),t.spellcheck=a}const n={enabled:!1,provider:"browser",apiUrl:""};if(typeof t.spellcheck=="boolean")t.spellcheck={...n,enabled:t.spellcheck};else if(typeof t.spellcheck=="object"&&t.spellcheck){const a={...n,...t.spellcheck};!a.provider&&a.mode&&(a.provider=a.mode==="local"?"browser":"api"),a.enabled===void 0&&(a.enabled=!!(a.mode||a.provider||a.apiUrl)),t.spellcheck=a}else t.spellcheck=n;return t.contextMenuEnabled!==void 0&&(t.contextMenu={enabled:!!t.contextMenuEnabled}),typeof t.contextMenu=="boolean"?t.contextMenu={enabled:t.contextMenu}:typeof t.contextMenu=="object"&&t.contextMenu?t.contextMenu={enabled:t.contextMenu.enabled!==!1}:t.contextMenu={enabled:!0},(t.pasteClean!==void 0||t.pasteKeepFormatting!==void 0||t.pasteConvertWord!==void 0)&&(t.paste={...t.paste||{},...t.pasteClean!==void 0?{clean:!!t.pasteClean}:{},...t.pasteKeepFormatting!==void 0?{keepFormatting:!!t.pasteKeepFormatting}:{},...t.pasteConvertWord!==void 0?{convertWord:!!t.pasteConvertWord}:{}}),t.paste={clean:!0,keepFormatting:!1,convertWord:!0,...t.paste||{}},t.contentConfig={allowedTags:[],allowedAttributes:{},sanitize:!0,...t.contentConfig||{}},(t.securitySanitizeOnPaste!==void 0||t.securitySanitizeOnInput!==void 0)&&(t.security={...t.security||{},...t.securitySanitizeOnPaste!==void 0?{sanitizeOnPaste:!!t.securitySanitizeOnPaste}:{},...t.securitySanitizeOnInput!==void 0?{sanitizeOnInput:!!t.securitySanitizeOnInput}:{}}),t.security={sanitizeOnPaste:!0,sanitizeOnInput:!0,...t.security||{}},(t.accessibilityEnableAria!==void 0||t.accessibilityKeyboardNavigation!==void 0||t.accessibilityChecker!==void 0)&&(t.accessibility={...t.accessibility||{},...t.accessibilityEnableAria!==void 0?{enableARIA:!!t.accessibilityEnableAria}:{},...t.accessibilityKeyboardNavigation!==void 0?{keyboardNavigation:!!t.accessibilityKeyboardNavigation}:{},...t.accessibilityChecker!==void 0?{checker:!!t.accessibilityChecker}:{}}),typeof t.accessibility=="boolean"&&(t.accessibility={enableARIA:t.accessibility,keyboardNavigation:t.accessibility,checker:!1}),t.accessibility={enableARIA:!0,keyboardNavigation:!0,checker:!1,...t.accessibility||{}},(t.performanceDebounceInputMs!==void 0||t.performanceViewportOnlyScan!==void 0)&&(t.performance={...t.performance||{},...t.performanceDebounceInputMs!==void 0?{debounceInputMs:Number(t.performanceDebounceInputMs)}:{},...t.performanceViewportOnlyScan!==void 0?{viewportOnlyScan:!!t.performanceViewportOnlyScan}:{}}),typeof t.performance=="boolean"&&(t.performance={debounceInputMs:100,viewportOnlyScan:t.performance}),t.performance={debounceInputMs:100,viewportOnlyScan:!0,...t.performance||{}},(typeof t.performance.debounceInputMs!="number"||!Number.isFinite(t.performance.debounceInputMs)||t.performance.debounceInputMs<0)&&(t.performance.debounceInputMs=100),t}static parseAttributes(e){const t={};for(const[o,i]of Object.entries(e)){const n=this.kebabToCamel(o);t[n]=this.parseAttributeValue(i)}return t}static parseAttributeValue(e){if(e==="true")return!0;if(e==="false")return!1;if(/^\d+$/.test(e))return parseInt(e,10);if(/^\d+\.\d+$/.test(e))return parseFloat(e);if(e.startsWith("{")||e.startsWith("["))try{return JSON.parse(e)}catch(t){return e}return e}static kebabToCamel(e){return e.replace(/-([a-z])/g,(t,o)=>o.toUpperCase())}static validate(e){const t=[];return e.height!==void 0&&typeof e.height=="number"&&e.height<0&&t.push("height must be a positive number"),e.width!==void 0&&typeof e.width=="number"&&e.width<0&&t.push("width must be a positive number"),e.plugins!==void 0&&!Array.isArray(e.plugins)&&typeof e.plugins!="string"&&t.push("plugins must be an array or string"),e.theme!==void 0&&typeof e.theme!="string"&&t.push("theme must be a string"),{valid:t.length===0,errors:t}}static getDefaults(){return{...this.EDITOR_DEFAULTS}}static merge(...e){const t={};for(const o of e)for(const[i,n]of Object.entries(o))n!=null&&(typeof n=="object"&&!Array.isArray(n)&&t[i]?t[i]=this.merge(t[i],n):t[i]=n);return t}};S.EDITOR_DEFAULTS={height:400,width:"100%",readonly:!1,disabled:!1,menubar:!0,toolbar:!0,plugins:[],theme:"light",content:"",placeholder:"Start typing...",autofocus:!1,autosave:!1,accessibility:{enableARIA:!0,keyboardNavigation:!0,checker:!1},performance:{debounceInputMs:100,viewportOnlyScan:!0},spellcheck:{enabled:!1,provider:"browser",apiUrl:""},language:{locale:"en",direction:"ltr"},contextMenu:{enabled:!0},contentConfig:{allowedTags:[],allowedAttributes:{},sanitize:!0},paste:{clean:!0,keepFormatting:!1,convertWord:!0},security:{sanitizeOnPaste:!0,sanitizeOnInput:!0},statusbar:!1};let E=S;class H{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 o=this.pluginRegistry.get(e);if(!o)return console.warn(`Plugin not found: ${e}`),null;const i=await o();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 o=e.split(/\s+/).filter(Boolean);return this.loadMultiple(o,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 O{constructor(e={}){this.changeListeners=[],this.options=e,this.engine=new w({content:e.content,plugins:e.plugins||[],readonly:e.readonly}),e.onChange&&this.onChange(e.onChange),this.engine.on("change",()=>{const t=this.getHTML();this.changeListeners.forEach(o=>o(t))})}mount(e,t){this.contentElement=e,this.toolbarElement=t,this.contentElement.contentEditable=this.options.readonly?"false":"true",this.contentElement.className="rte-content",this.options.content&&(this.contentElement.innerHTML=this.options.content),this.options.toolbar!==!1&&this.toolbarElement&&(this.toolbar=new x({items:typeof this.options.toolbar=="string"?this.options.toolbar:void 0},this.options.plugins||[]),this.toolbar.setCommandHandler((o,i)=>{this.execCommand(o,i)}),this.toolbar.render(this.toolbarElement)),this.contentElement.addEventListener("input",()=>{const o=this.getHTML();this.changeListeners.forEach(i=>i(o))}),this.options.onInit&&this.options.onInit(this.getAPI())}getHTML(){var e;return((e=this.contentElement)==null?void 0:e.innerHTML)||""}setHTML(e){this.contentElement&&(this.contentElement.innerHTML=e)}execCommand(e,t){const o=this.engine.execCommand(e,t);return this.toolbar,o}focus(){var e;(e=this.contentElement)==null||e.focus()}blur(){var e;(e=this.contentElement)==null||e.blur()}onChange(e){return this.changeListeners.push(e),()=>{const t=this.changeListeners.indexOf(e);t>-1&&this.changeListeners.splice(t,1)}}registerCommand(e,t){if(typeof window!="undefined"){const o=window.__editorCommands||new Map;o.set(e,t),window.__editorCommands=o}}getState(){return{plugins:this.options.plugins,config:this.options,engine:this.engine.getState()}}getAPI(){var e;return{getHTML:()=>this.getHTML(),setHTML:t=>this.setHTML(t),execCommand:(t,o)=>this.execCommand(t,o),focus:()=>this.focus(),blur:()=>this.blur(),destroy:()=>this.destroy(),registerCommand:(t,o)=>this.registerCommand(t,o),onChange:t=>this.onChange(t),getState:()=>this.getState(),toolbar:{items:((e=this.options.plugins)==null?void 0:e.flatMap(t=>t.toolbar||[]))||[]}}}destroy(){var e;this.engine.destroy(),(e=this.toolbar)==null||e.destroy(),this.changeListeners=[],this.options.onDestroy&&this.options.onDestroy()}}function ee(s){return new O(s)}class ${constructor(e){this.options=e,this.containerElement=e.element;const t=this.resolvePlugins(e.plugins);this.engine=new w({content:e.content,plugins:t,readonly:e.readonly}),this.initializeDOM()}resolvePlugins(e){return e?typeof e=="string"?(console.warn("String-based plugin loading not yet implemented for VanillaAdapter"),[]):e:[]}initializeDOM(){this.containerElement.innerHTML="",this.containerElement.classList.add("editora-editor"),this.options.enableToolbar!==!1&&this.options.toolbar!==!1&&(this.toolbarElement=document.createElement("div"),this.toolbarElement.className="editora-toolbar-container",this.containerElement.appendChild(this.toolbarElement),this.toolbar=new x({items:typeof this.options.toolbar=="string"?this.options.toolbar:void 0},this.options.plugins||[]),this.toolbar.setCommandHandler((e,t)=>{this.execCommand(e,t)}),this.toolbar.render(this.toolbarElement)),this.contentElement=document.createElement("div"),this.contentElement.className="editora-content",this.contentElement.contentEditable=this.options.readonly?"false":"true",this.contentElement.style.minHeight="200px",this.contentElement.style.outline="none",this.contentElement.style.padding="12px",this.options.content&&(this.contentElement.innerHTML=this.options.content),this.containerElement.appendChild(this.contentElement),this.contentElement.addEventListener("input",()=>{this.containerElement.dispatchEvent(new CustomEvent("change",{detail:{html:this.getContent()}}))})}getContent(){var e;return((e=this.contentElement)==null?void 0:e.innerHTML)||""}setContent(e){this.contentElement&&(this.contentElement.innerHTML=e)}execCommand(e,t){return this.engine.execCommand(e,t)}focus(){var e;(e=this.contentElement)==null||e.focus()}on(e,t){const o=i=>{t(i.detail)};return this.containerElement.addEventListener(e,o),()=>{this.containerElement.removeEventListener(e,o)}}destroy(){var e;this.engine.destroy(),(e=this.toolbar)==null||e.destroy(),this.containerElement.innerHTML=""}}const te=["p","br","strong","em","u","s","strike","del","b","i","h1","h2","h3","h4","h5","h6","ul","ol","li","a","img","video","audio","table","thead","tbody","tr","th","td","blockquote","pre","code","span","div","sup","sub","hr"],oe={"*":["class","style","id","data-*"],a:["href","target","rel","title"],img:["src","alt","width","height","loading"],video:["src","controls","width","height","autoplay","loop","muted"],audio:["src","controls","autoplay","loop","muted"],table:["border","cellpadding","cellspacing"],td:["colspan","rowspan","align","valign"],th:["colspan","rowspan","align","valign"]};function R(s,e,t){if((e==null?void 0:e.sanitize)===!1)return s;const o=e!=null&&e.allowedTags&&e.allowedTags.length>0?e.allowedTags:te,n=!!(e!=null&&e.allowedAttributes)&&Object.keys(e.allowedAttributes).length>0?e.allowedAttributes:oe,a=document.createElement("div");return a.innerHTML=s,B(a,o,n),a.innerHTML}function B(s,e,t){const o=Array.from(s.childNodes);for(const i of o)if(i.nodeType===Node.ELEMENT_NODE){const n=i,a=n.tagName.toLowerCase();if(!e.includes(a)){for(;n.firstChild;)s.insertBefore(n.firstChild,n);s.removeChild(n);continue}ie(n,t),B(n,e,t)}else i.nodeType!==Node.TEXT_NODE&&s.removeChild(i)}function ie(s,e){const t=s.tagName.toLowerCase(),o=Array.from(s.attributes),i=e[t]||[],n=e["*"]||[],a=[...i,...n];for(const r of o){const l=r.name.toLowerCase();let d=!1;a.includes(l)&&(d=!0);for(const u of a)if(u.endsWith("*")){const f=u.slice(0,-1);if(l.startsWith(f)){d=!0;break}}(l.startsWith("on")||l==="javascript:"||l==="href"&&r.value.trim().toLowerCase().startsWith("javascript:")||l==="src"&&r.value.trim().toLowerCase().startsWith("javascript:"))&&(d=!1),d||s.removeAttribute(r.name)}s.hasAttribute("href")&&(s.getAttribute("href")||"").trim().toLowerCase().startsWith("javascript:")&&s.removeAttribute("href"),s.hasAttribute("src")&&(s.getAttribute("src")||"").trim().toLowerCase().startsWith("javascript:")&&s.removeAttribute("src")}function ne(s,e,t){return(t==null?void 0:t.sanitizeOnPaste)===!1?s:R(s,e)}function ae(s,e,t){return(t==null?void 0:t.sanitizeOnInput)===!1?s:R(s,e)}const re='.editora-editor{display:flex;flex-direction:column;border:1px solid #ddd;border-radius:4px;background:#fff;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,sans-serif;font-size:14px;overflow:hidden}.editora-editor *{box-sizing:border-box}.editora-theme-light{background:#fff;color:#333}.editora-theme-dark{--editora-dark-toolbar-bg-start: #353d48;--editora-dark-toolbar-bg-end: #2d3540;--editora-dark-button-bg-start: #46505f;--editora-dark-button-bg-end: #3b4553;--editora-dark-button-hover-start: #525d6d;--editora-dark-button-hover-end: #465262;--editora-dark-button-active-start: #5eaaf6;--editora-dark-button-active-end: #4a95de;--editora-dark-border: #475263;--editora-dark-border-strong: #566275;--editora-dark-text: #e1e9f5;--editora-dark-text-strong: #f3f7ff;--editora-dark-text-muted: #aeb9cc;--editora-dark-surface: #1d242d;--editora-dark-content: #1f2732;background:linear-gradient(180deg,#1b2330,#1c2430);color:var(--editora-dark-text);border-color:var(--editora-dark-border)}.editora-toolbar{display:flex;align-items:center;gap:4px;padding:8px;background:#f5f5f5;border-bottom:1px solid #ddd;flex-wrap:wrap}.editora-theme-dark .editora-toolbar{background:linear-gradient(180deg,var(--editora-dark-toolbar-bg-start) 0%,var(--editora-dark-toolbar-bg-end) 100%);border-bottom-color:var(--editora-dark-border);box-shadow:inset 0 1px #ffffff0d}.editora-toolbar-sticky{position:sticky;top:0;z-index:100;position:-webkit-sticky}.editora-toolbar-group{display:flex;align-items:center;gap:2px}.editora-toolbar-button{padding:6px 12px;border:1px solid #ccc;background:#fff;cursor:pointer;border-radius:3px;font-weight:600;font-size:14px;height:30px;display:flex;align-items:center;white-space:nowrap}.editora-toolbar-group-button{display:flex;align-items:center}.editora-toolbar-input.font-size{width:40px;padding:.25rem;text-align:center;font-size:14px;background:#fff;border:1px solid var(--rte-color-border-light);border-radius:var(--rte-radius-sm)}.editora-toolbar-group-items{display:flex;align-items:center;border:1px solid #ccc;.editora-toolbar-button{border:none;border-radius:0;&:first-child{border-right:1px solid #ccc;border-top-left-radius:3px;border-bottom-left-radius:3px}&:last-child{border-left:1px solid #ccc;border-top-right-radius:3px;border-bottom-right-radius:3px}}}.editora-theme-dark .editora-toolbar-button{background:linear-gradient(180deg,var(--editora-dark-button-bg-start) 0%,var(--editora-dark-button-bg-end) 100%);border-color:var(--editora-dark-border-strong);color:var(--editora-dark-text);box-shadow:inset 0 1px #ffffff14,0 1px 1px #00000059}.editora-theme-dark .editora-toolbar-group-items{border-color:var(--editora-dark-border-strong);background:linear-gradient(180deg,var(--editora-dark-button-bg-start) 0%,var(--editora-dark-button-bg-end) 100%)}.editora-theme-dark .editora-toolbar-group-items .editora-toolbar-button:first-child{border-right-color:#566275}.editora-theme-dark .editora-toolbar-group-items .editora-toolbar-button:last-child{border-left-color:#566275}.editora-theme-dark .editora-toolbar-input.font-size{background-color:#2e3642;color:var(--editora-dark-text-strong);border-color:var(--editora-dark-border-strong);caret-color:var(--editora-dark-text-strong)}.editora-theme-dark .editora-toolbar-input.font-size::placeholder{color:var(--editora-dark-text-strong);opacity:1}.editora-toolbar-button:hover{background:#e0e0e0;border-color:#ccc}.editora-theme-dark .editora-toolbar-button:hover{background:linear-gradient(180deg,var(--editora-dark-button-hover-start) 0%,var(--editora-dark-button-hover-end) 100%);border-color:#66748a;color:var(--editora-dark-text-strong)}.editora-toolbar-button:active,.editora-toolbar-button.active{background:#d0d0d0;border-color:#999}.editora-theme-dark .editora-toolbar-button:active,.editora-theme-dark .editora-toolbar-button.active{background:linear-gradient(180deg,var(--editora-dark-button-active-start) 0%,var(--editora-dark-button-active-end) 100%);border-color:#67adf4;color:#0f1b2a}.editora-theme-dark .editora-toolbar-button:disabled{background:#313946;border-color:#424d5e;color:#7f8ca1}.editora-theme-dark .editora-toolbar-button[data-command=insertTable],.editora-theme-dark .editora-toolbar-button[data-command=print],.editora-theme-dark .editora-toolbar-button[data-command=toggleSpellCheck],.editora-theme-dark .editora-toolbar-button[data-command=toggleA11yChecker],.editora-theme-dark .editora-toolbar-button[data-command=setDirectionLTR],.editora-theme-dark .editora-toolbar-button[data-command=setDirectionRTL]{color:#f1f6ff}.editora-toolbar-button:disabled{opacity:.5;cursor:not-allowed}.editora-toolbar-icon{display:inline-flex;align-items:center;justify-content:center;width:24px;height:24px;line-height:1}.editora-toolbar-button svg,.editora-toolbar-icon svg{width:20px;height:20px;display:block;color:currentColor;fill:currentColor}.editora-theme-dark .editora-toolbar-icon,.editora-theme-dark .editora-toolbar-icon *{color:inherit}.editora-theme-dark :is(.editora-toolbar-button,.editora-toolbar-icon) svg :is([stroke="#000" i],[stroke="#000000" i],[stroke=black i],[stroke="#0f0f0f" i],[stroke="#111111" i],[style*="stroke:#000" i],[style*="stroke: #000" i],[style*="stroke:black" i],[style*="stroke: black" i],[style*="stroke:#0f0f0f" i],[style*="stroke: #0f0f0f" i]){stroke:currentColor!important}.editora-theme-dark :is(.editora-toolbar-button,.editora-toolbar-icon) svg :is([fill="#000" i],[fill="#000000" i],[fill=black i],[fill="#0f0f0f" i],[fill="#111111" i],[style*="fill:#000" i],[style*="fill: #000" i],[style*="fill:black" i],[style*="fill: black" i],[style*="fill:#0f0f0f" i],[style*="fill: #0f0f0f" i]){fill:currentColor!important}.editora-toolbar-separator{width:1px;height:24px;background:#ddd;margin:0 4px}.editora-theme-dark .editora-toolbar-separator{background:#4d596b}.editora-toolbar-dropdown{position:relative}.editora-toolbar-dropdown-menu{position:absolute;top:100%;left:0;min-width:150px;margin-top:4px;padding:4px 0;background:#fff;border:1px solid #ddd;border-radius:4px;box-shadow:0 2px 8px #00000026;z-index:1000}.editora-theme-dark .editora-toolbar-dropdown-menu{background:#29323d;border-color:#4d596b;box-shadow:0 8px 20px #00000073}.editora-toolbar-dropdown-item{display:block;width:100%;padding:8px 12px;border:none;background:transparent;color:#333;text-align:left;cursor:pointer;font-size:13px;transition:background .15s ease}.editora-theme-dark .editora-toolbar-dropdown-item{color:#d7deea}.editora-toolbar-dropdown-item:hover{background:#f5f5f5}.editora-theme-dark .editora-toolbar-dropdown-item:hover{background:#3a4554;color:#f0f6ff}.editora-content{flex:1;min-height:200px;padding:16px;outline:none;overflow-y:auto;line-height:1.6}.editora-theme-dark .editora-content{color:#ecf3ff;background:linear-gradient(180deg,var(--editora-dark-content) 0%,#1c232e 100%)}.editora-content:empty:before{content:attr(data-placeholder);color:#999;pointer-events:none}.editora-theme-dark .editora-content:empty:before{color:#8f9bb0}.editora-content h1{font-size:2em;margin:.67em 0;font-weight:600}.editora-content h2{font-size:1.5em;margin:.75em 0;font-weight:600}.editora-content h3{font-size:1.17em;margin:.83em 0;font-weight:600}.editora-content p{margin:1em 0}.editora-content ul,.editora-content ol{margin:1em 0;padding-left:2em}.editora-content a{color:#06c;text-decoration:underline}.editora-theme-dark .editora-content a{color:#4db8ff}.editora-content code{padding:2px 4px;background:#f5f5f5;border-radius:3px;font-family:Monaco,Menlo,Consolas,monospace;font-size:.9em}.editora-theme-dark .editora-content code{background:#1e1e1e}.editora-content pre{padding:12px;background:#f5f5f5;border-radius:4px;overflow-x:auto;margin:1em 0}.editora-theme-dark .editora-content pre{background:#1e1e1e}.editora-theme-dark .rte-code-block{background:linear-gradient(180deg,#212a36,#1b2430)!important;border-color:#4f5b70!important;color:#e7effc!important}.editora-theme-dark .rte-code-block code{color:#e7effc!important}.editora-theme-dark .rte-code-block:before{background:#111927!important;color:#dce8ff!important}.editora-theme-dark .rte-code-block .rte-code-copy{background:#2b3441!important;border-color:#5a667b!important;color:#dce8ff!important}.editora-content blockquote{margin:1em 0;padding-left:1em;border-left:4px solid #ddd;color:#666}.editora-theme-dark .editora-content blockquote{border-left-color:#3c3c3c;color:#9a9a9a}.editora-floating-toolbar{position:absolute;padding:4px;background:#fff;border:1px solid #ddd;border-radius:4px;box-shadow:0 2px 8px #00000026;z-index:1000}.editora-theme-dark .editora-floating-toolbar{background:#29323d;border-color:#4d596b;box-shadow:0 8px 20px #00000073}.editora-statusbar-container{display:flex;flex-direction:column}.editora-statusbar-left{display:flex;align-items:center;gap:8px}.editora-statusbar-right{display:flex;align-items:center;gap:8px;margin-left:auto}.editora-statusbar{display:flex;align-items:center;gap:12px;padding:6px 12px;background:#f5f5f5;border-top:1px solid #ddd;font-size:12px;color:#666}.editora-theme-dark .editora-statusbar{background:linear-gradient(180deg,#2c3440,#252d37);border-top-color:#3f4a5b;color:#d7deea}.editora-statusbar-item{white-space:nowrap}.editora-statusbar-separator{color:#ddd}.editora-theme-dark .editora-statusbar-separator{color:#566275}.editora-editor[readonly] .editora-content{background:#fafafa;cursor:not-allowed}.editora-theme-dark.editora-editor[readonly] .editora-content{background:#1a1a1a}.editora-editor:focus-within{border-color:#06c;box-shadow:0 0 0 3px #0066cc1a}.editora-theme-dark.editora-editor:focus-within{border-color:#4db8ff;box-shadow:0 0 0 3px #4db8ff1a}.editora-editor[disabled]{opacity:.6;pointer-events:none}@media(max-width:768px){.editora-toolbar{padding:4px}.editora-toolbar-button{min-width:28px;min-height:28px;padding:4px 8px;font-size:12px}.editora-content{padding:12px}}.editora-content ::selection{background:#06c3}.editora-theme-dark .editora-content ::selection{background:#4db8ff33}.editora-content table{border-collapse:collapse;width:100%;margin:1em 0}.editora-content th,.editora-content td{border:1px solid #ddd;padding:8px 12px;text-align:left}.editora-theme-dark .editora-content th,.editora-theme-dark .editora-content td{border-color:#3c3c3c}.editora-content th{background:#f5f5f5;font-weight:600}.editora-theme-dark .editora-content th{background:#252526}.editora-content img{max-width:100%;height:auto;border-radius:4px;display:block}.editora-content video{max-width:100%;height:auto;border-radius:4px;display:block}.editora-editor.loading{opacity:.7;pointer-events:none}.editora-editor.loading:after{content:"";position:absolute;top:50%;left:50%;width:24px;height:24px;margin:-12px 0 0 -12px;border:3px solid #ddd;border-top-color:#06c;border-radius:50%;animation:editora-spin .8s linear infinite}@keyframes editora-spin{to{transform:rotate(360deg)}}.toolbar-container-wrapper{display:flex;align-items:center;background:#fff;border-bottom:1px solid #e0e0e0;padding:0;margin:0;width:100%;box-sizing:border-box;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,sans-serif;font-size:14px;line-height:1.5;position:relative}.toolbar-container-wrapper[data-toolbar-sticky=true]{position:sticky;top:0;z-index:999;box-shadow:0 2px 4px #0000001a}.toolbar-container-wrapper[data-toolbar-floating=true]{position:fixed;top:0;left:0;right:0;z-index:1000;box-shadow:0 4px 12px #00000026}.toolbar-container-wrapper[data-toolbar-position=bottom]{border-bottom:none;border-top:1px solid #e0e0e0}.toolbar-container-wrapper .toolbar-wrapper{display:flex;width:100%;padding:8px;gap:4px;flex-wrap:wrap;align-items:center}.toolbar-container-wrapper .toolbar{display:flex;width:100%;gap:4px;flex-wrap:wrap;align-items:center}.toolbar-container-wrapper .toolbar-container{display:flex;gap:4px;flex-wrap:wrap;align-items:center;flex:1;position:relative}.toolbar-container-wrapper .toolbar-item{display:flex;align-items:center;gap:2px}.toolbar-container-wrapper .toolbar-button{padding:6px 10px;border:1px solid #d1d5db;background:#fff;border-radius:4px;cursor:pointer;font-size:13px;display:flex;align-items:center;justify-content:center;gap:4px;transition:all .15s ease;min-height:32px;white-space:nowrap}.toolbar-container-wrapper .toolbar-button:hover{background-color:#f3f4f6;border-color:#9ca3af}.toolbar-container-wrapper .toolbar-button:active,.toolbar-container-wrapper .toolbar-button[data-active=true]{background-color:#06c;color:#fff;border-color:#0052a3;box-shadow:inset 0 1px 3px #0000001a}.toolbar-container-wrapper .toolbar-button:disabled{opacity:.5;cursor:not-allowed;background-color:#f9fafb}.toolbar-container-wrapper .toolbar-more-button{padding:6px 8px;font-size:16px;font-weight:500;line-height:1}.toolbar-container-wrapper .toolbar-separator{width:1px;height:24px;background-color:#d1d5db;margin:0 4px}.toolbar-container-wrapper .toolbar-icon{display:inline-flex;align-items:center;justify-content:center;width:18px;height:18px;flex-shrink:0}.toolbar-container-wrapper .toolbar-icon svg{width:100%;height:100%}.toolbar-container-wrapper .toolbar-dropdown{position:relative;display:flex;align-items:center}.toolbar-container-wrapper .toolbar-dropdown-arrow{font-size:10px;margin-left:2px;line-height:1}.toolbar-container-wrapper .toolbar-dropdown-menu{position:absolute;top:100%;left:0;background:#fff;border:1px solid #d1d5db;border-radius:6px;box-shadow:0 4px 12px #00000026;z-index:1000;min-width:160px;padding:4px 0;margin-top:4px;display:none}.toolbar-container-wrapper .toolbar-dropdown-menu.show{display:block}.toolbar-container-wrapper .toolbar-dropdown-item{display:block;width:100%;padding:8px 12px;border:none;background:transparent;text-align:left;cursor:pointer;font-size:13px;color:#1f2937;transition:background-color .15s ease;font-family:inherit}.toolbar-container-wrapper .toolbar-dropdown-item:hover{background-color:#f3f4f6}.toolbar-container-wrapper .toolbar-dropdown-item:active{background-color:#e5e7eb}.toolbar-container-wrapper .toolbar-input{padding:6px 8px;border:1px solid #d1d5db;border-radius:4px;font-size:13px;font-family:inherit;background-color:#fff;color:#1f2937;transition:all .15s ease}.toolbar-container-wrapper .toolbar-input:focus{outline:none;border-color:#06c;box-shadow:0 0 0 3px #0066cc1a;background-color:#fff}.toolbar-container-wrapper .toolbar-input::placeholder{color:#9ca3af}.toolbar-overflow-menu{animation:slideDown .2s ease-out}@keyframes slideDown{0%{opacity:0;transform:translateY(-8px)}to{opacity:1;transform:translateY(0)}}.toolbar-overflow-item{transition:background-color .15s ease}.floating-toolbar{user-select:none;-webkit-user-select:none;font-family:system-ui,-apple-system,sans-serif;font-size:14px;animation:fadeInUp .15s ease-out}@keyframes fadeInUp{0%{opacity:0;transform:translate(-50%) translateY(10px)}to{opacity:1;transform:translate(-50%) translateY(0)}}.floating-toolbar-btn{display:flex;align-items:center;justify-content:center;width:32px;height:32px;border:none;background:transparent;border-radius:4px;color:#495057;cursor:pointer;font-size:14px;font-weight:500;transition:all .15s ease;outline:none}.floating-toolbar-btn:hover{background:#f8f9fa;color:#212529}.floating-toolbar-btn:active{background:#e9ecef;transform:scale(.95)}.floating-toolbar-btn.floating-toolbar-toggle{color:#dc3545;font-weight:700}.floating-toolbar-btn.floating-toolbar-toggle:hover{background:#f8d7da;color:#721c24}.floating-toolbar-separator{width:1px;height:20px;background:#e1e5e9;margin:0 2px}@media(max-width:768px){.toolbar-container-wrapper .toolbar-button{padding:5px 8px;font-size:12px;min-height:28px}.toolbar-container-wrapper .toolbar-icon{width:16px;height:16px}.toolbar-container-wrapper .toolbar-dropdown-menu{min-width:140px}.toolbar-container-wrapper .toolbar-dropdown-item{padding:6px 10px;font-size:12px}.floating-toolbar{padding:4px;gap:2px}.floating-toolbar-btn{width:28px;height:28px;font-size:12px}}@media(max-width:480px){.toolbar-container-wrapper{padding:4px}.toolbar-container-wrapper .toolbar-wrapper{padding:4px;gap:2px}.toolbar-container-wrapper .toolbar-button{padding:4px 6px;font-size:11px;min-height:24px}.toolbar-container-wrapper .toolbar-icon{width:14px;height:14px}}.floating-toolbar{pointer-events:auto}.floating-toolbar{max-width:calc(100vw - 20px);overflow-x:auto}@media(prefers-color-scheme:dark){.floating-toolbar{background:#2d3748;border-color:#4a5568;color:#e2e8f0}.floating-toolbar-btn:hover{background:#4a5568;color:#f7fafc}.floating-toolbar-btn:active{background:#718096}.floating-toolbar-separator{background:#4a5568}}';let C;function se(){const s="editora-webcomponent-styles";if(!document.getElementById(s)){const e=document.createElement("style");e.id=s,e.textContent=re,document.head.appendChild(e)}}function le(){if(!C){const s=g.__globalPluginLoader;s?C=s:C=new H}return C}class g extends HTMLElement{constructor(){if(super(),this.pluginLoader=le(),this.config={},this.isInitialized=!1,this.keyboardShortcutManager=new T,this.lastAutosavedContent="",this.loadedPlugins=[],se(),!this.hasAttribute("data-initial-content")){const e=this.innerHTML.trim();e&&this.setAttribute("data-initial-content",e)}}static get observedAttributes(){return["height","width","menubar","plugins","toolbar","toolbar-items","toolbar-floating","toolbar-sticky","readonly","disabled","theme","placeholder","autofocus","autosave","autosave-enabled","autosave-interval-ms","autosave-storage-key","autosave-provider","autosave-api-url","accessibility","accessibility-enable-aria","accessibility-keyboard-navigation","accessibility-checker","performance","performance-debounce-input-ms","performance-viewport-only-scan","language","language-locale","language-direction","spellcheck","spellcheck-enabled","spellcheck-provider","context-menu","context-menu-enabled","paste","paste-clean","paste-keep-formatting","paste-convert-word","security","security-sanitize-on-paste","security-sanitize-on-input","statusbar"]}connectedCallback(){this.config=this.resolveConfig(),this.waitForPluginLoader().then(()=>{setTimeout(async()=>{await this.initialize()},0)})}async waitForPluginLoader(){if(g.__globalPluginLoader){this.pluginLoader=g.__globalPluginLoader;return}return new Promise(e=>{const t=()=>{g.__globalPluginLoader?(this.pluginLoader=g.__globalPluginLoader,e()):setTimeout(t,0)};t()})}disconnectedCallback(){this.destroy()}attributeChangedCallback(e,t,o){t!==o&&(this.config=this.resolveConfig(),this.handleAttributeChange(e,o))}async setConfig(e){this.jsConfig=e,this.config=this.resolveConfig(),this.isConnected&&(this.destroy(),await this.waitForPluginLoader(),await this.initialize())}async initialize(){var o;if(this.querySelector(".editora-toolbar")||this.isInitialized)return;this.setAttribute("data-editora-editor","true"),this.config.height&&(this.style.height=typeof this.config.height=="number"?`${this.config.height}px`:this.config.height),this.config.width&&(this.style.width=typeof this.config.width=="number"?`${this.config.width}px`:this.config.width),this.classList.add("editora-editor"),this.config.theme&&this.classList.add(`editora-theme-${this.config.theme}`);const e=await this.loadPlugins();this.loadedPlugins=e,e.forEach(i=>{if(i.init&&typeof i.init=="function")try{i.init({editorElement:this})}catch(n){console.error(`[RichTextEditor] Error initializing plugin ${i.name}:`,n)}});const t=(o=this.restoreAutosavedContent())!=null?o:this.getAttribute("data-initial-content")||"";this.engine=new w({content:t,plugins:e,readonly:this.config.readonly}),this.createUI(e,t),this.setupEventListeners(),this.startAutosave(),this.isInitialized=!0,this.dispatchEvent(new CustomEvent("editor-ready",{detail:{api:this.getAPI()},bubbles:!0}))}getInitialContent(){if(this.config.content)return this.config.content;const e=this.querySelector("[slot]");return e?e.innerHTML:this.hasChildNodes()?Array.from(this.childNodes).map(o=>o.nodeType===Node.TEXT_NODE?o.textContent:o.nodeType===Node.ELEMENT_NODE?o.outerHTML:"").join("").trim():""}async loadPlugins(){this.pluginLoader||await this.waitForPluginLoader();const e=[],t=this.config.plugins&&(typeof this.config.plugins=="string"&&this.config.plugins.length>0||Array.isArray(this.config.plugins)&&this.config.plugins.length>0),i=this.getAccessibilityConfig().checker===!0;if(t){if(typeof this.config.plugins=="string"){const n=this.config.plugins.split(/\s+/).filter(Boolean);i&&!n.includes("a11yChecker")&&n.push("a11yChecker");for(const a of n){const r=await this.pluginLoader.load(a,this.getPluginLoadConfig(a));r&&e.push(r)}}else if(Array.isArray(this.config.plugins)){for(const n of this.config.plugins)if(typeof n=="string"){const a=await this.pluginLoader.load(n,this.getPluginLoadConfig(n));a&&e.push(a)}else e.push(n);if(i&&!e.some(n=>(n==null?void 0:n.name)==="a11yChecker")){const n=await this.pluginLoader.load("a11yChecker",this.getPluginLoadConfig("a11yChecker"));n&&e.push(n)}}}else{const n=this.pluginLoader.getRegisteredPluginNames();for(const a of n){const r=await this.pluginLoader.load(a,this.getPluginLoadConfig(a));r&&e.push(r)}}return e}resolveToolbarItems(){const e=this.config.toolbarItems;if(typeof e=="string")return e;if(Array.isArray(e))return e.join(" ");const t=this.config.toolbar;if(typeof t=="string")return t;if(!t||typeof t!="object")return;const o=t.items;if(typeof o=="string")return o;if(Array.isArray(o))return o.join(" ")}isToolbarStickyEnabled(){const e=this.config.toolbar;return!e||typeof e!="object"?!1:!!e.sticky}isToolbarFloatingEnabled(){const e=this.config.toolbar;return!e||typeof e!="object"?!1:!!e.floating}isStatusbarEnabled(){const e=this.config.statusbar;return typeof e=="boolean"?e:e&&typeof e=="object"?e.enabled!==!1:!1}getStatusbarPosition(){const e=this.config.statusbar;return e&&typeof e=="object"&&e.position==="top"?"top":"bottom"}getLanguageConfig(){const e=this.config.language;return typeof e=="string"?{locale:e,direction:"ltr"}:e&&typeof e=="object"?{locale:e.locale||"en",direction:e.direction==="rtl"?"rtl":"ltr"}:{locale:"en",direction:"ltr"}}getAccessibilityConfig(){const e=this.config.accessibility;return typeof e=="boolean"?{enableARIA:e,keyboardNavigation:e,checker:!1}:e&&typeof e=="object"?{enableARIA:e.enableARIA!==!1,keyboardNavigation:e.keyboardNavigation!==!1,checker:!!e.checker}:{enableARIA:!0,keyboardNavigation:!0,checker:!1}}getPerformanceConfig(){var t;const e=this.config.performance;if(typeof e=="boolean")return{debounceInputMs:100,viewportOnlyScan:e};if(e&&typeof e=="object"){const o=Number((t=e.debounceInputMs)!=null?t:100);return{debounceInputMs:Number.isFinite(o)&&o>=0?o:100,viewportOnlyScan:e.viewportOnlyScan!==!1}}return{debounceInputMs:100,viewportOnlyScan:!0}}isEditorInViewport(){if(!this.contentElement||typeof window=="undefined")return!0;const e=this.contentElement.getBoundingClientRect();return e.bottom>=0&&e.top<=window.innerHeight}applyAccessibilitySettings(){if(!this.contentElement)return;const e=this.getAccessibilityConfig();if(e.enableARIA){this.contentElement.setAttribute("role","textbox"),this.contentElement.setAttribute("aria-multiline","true"),this.contentElement.setAttribute("aria-disabled",this.config.readonly?"true":"false");const t=typeof this.config.placeholder=="string"?this.config.placeholder.trim():"";t?this.contentElement.setAttribute("aria-label",t):this.contentElement.removeAttribute("aria-label")}else this.contentElement.removeAttribute("role"),this.contentElement.removeAttribute("aria-multiline"),this.contentElement.removeAttribute("aria-disabled"),this.contentElement.removeAttribute("aria-label");this.contentElement.tabIndex=e.keyboardNavigation?0:-1}applyLanguageSettings(){if(!this.contentElement)return;const e=this.getLanguageConfig();this.contentElement.setAttribute("lang",e.locale),this.contentElement.setAttribute("dir",e.direction)}getSpellcheckConfig(){const e=this.config.spellcheck;if(typeof e=="boolean")return{enabled:e,provider:"browser"};if(e&&typeof e=="object"){const t=e.provider||"browser";return{enabled:!!e.enabled,provider:t,mode:e.mode}}return{enabled:!1,provider:"browser"}}applySpellcheckSettings(){if(!this.contentElement)return;const e=this.getSpellcheckConfig(),t=e.enabled&&e.provider==="browser";this.contentElement.spellcheck=t,this.contentElement.setAttribute("spellcheck",t?"true":"false")}executeCommand(e,t){var i;typeof window!="undefined"&&(window.__editoraCommandEditorRoot=this);const o=this.loadedPlugins.find(n=>n.commands&&n.commands[e]);if(o&&o.commands){const n=o.commands[e];if(typeof n=="function")try{return n(e==="toggleFullscreen"?this:t),!0}catch(a){return console.error(`[RichTextEditor] Error executing native command ${e}:`,a),!1}}return((i=this.engine)==null?void 0:i.execCommand(e,t))||!1}getPluginLoadConfig(e){const t=this.config.pluginConfig;if(t&&typeof t=="object"){const n=t[e];if(n&&typeof n=="object")return n}const o={spellCheck:["spellcheck","spellCheck"]},i=[e,e.toLowerCase(),...o[e]||[]];for(const n of i){const a=this.config[n];if(a&&typeof a=="object"&&!Array.isArray(a))return a}}getContentSanitizeConfig(){const e=this.config.contentConfig;return e&&typeof e=="object"?e:{sanitize:!0}}getSecurityConfig(){const e=this.config.security;return e&&typeof e=="object"?e:{sanitizeOnPaste:!0,sanitizeOnInput:!0}}getAutosaveConfig(){var t,o;const e=this.config.autosave;if(typeof e=="boolean")return{enabled:e,intervalMs:3e4,storageKey:"rte-autosave",provider:"localStorage"};if(e&&typeof e=="object"){const i=Number((o=(t=e.intervalMs)!=null?t:e.interval)!=null?o:3e4);return{enabled:!!e.enabled,intervalMs:Number.isFinite(i)&&i>0?i:3e4,storageKey:String(e.storageKey||"rte-autosave"),provider:e.provider||"localStorage",apiUrl:e.apiUrl}}return{enabled:!1,intervalMs:3e4,storageKey:"rte-autosave",provider:"localStorage"}}persistAutosave(e){const t=this.getAutosaveConfig();if(t.enabled&&e!==this.lastAutosavedContent){if(this.lastAutosavedContent=e,t.provider==="localStorage"){try{localStorage.setItem(t.storageKey,e),localStorage.setItem(`${t.storageKey}-timestamp`,Date.now().toString())}catch(o){console.error("[RichTextEditor] Failed to save autosave content to localStorage:",o)}return}t.provider==="api"&&t.apiUrl&&fetch(t.apiUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:e,timestamp:Date.now()})}).catch(o=>{console.error("[RichTextEditor] Failed to save autosave content to API:",o)})}}restoreAutosavedContent(){const e=this.getAutosaveConfig();if(!e.enabled||e.provider!=="localStorage")return null;try{const t=localStorage.getItem(e.storageKey);if(t)return this.lastAutosavedContent=t,t}catch(t){console.error("[RichTextEditor] Failed to restore autosaved content:",t)}return null}stopAutosave(){this.autosaveTimer&&(clearInterval(this.autosaveTimer),this.autosaveTimer=void 0)}startAutosave(){this.stopAutosave();const e=this.getAutosaveConfig();!e.enabled||!this.contentElement||(this.autosaveTimer=setInterval(()=>{var t;this.persistAutosave(((t=this.contentElement)==null?void 0:t.innerHTML)||"")},e.intervalMs))}insertHTMLAtSelection(e){if(!this.contentElement)return;const t=window.getSelection();if(t&&t.rangeCount>0){const o=t.getRangeAt(0);o.deleteContents();const i=document.createElement("div");i.innerHTML=e;const n=document.createDocumentFragment();for(;i.firstChild;)n.appendChild(i.firstChild);o.insertNode(n),o.collapse(!1),t.removeAllRanges(),t.addRange(o)}else this.contentElement.focus(),document.execCommand("insertHTML",!1,e)}createUI(e,t){const o=this.querySelector('[slot="toolbar"]'),i=this.querySelector('[slot="statusbar"]');this.innerHTML="",this.config.toolbar!==!1&&!o?(this.toolbarElement=document.createElement("div"),this.toolbarElement.className="editora-toolbar-container",this.appendChild(this.toolbarElement),this.toolbar=new x({items:this.resolveToolbarItems(),sticky:this.isToolbarStickyEnabled(),position:"top"},e,this.pluginLoader),this.toolbar.setCommandHandler((n,a)=>{var r;if(this.contentElement){this.contentElement.focus();const l=window.getSelection();if(!l||l.rangeCount===0||!this.contentElement.contains(l.anchorNode)){const d=document.createRange(),u=this.contentElement.lastChild||this.contentElement;u.nodeType===Node.TEXT_NODE?d.setStart(u,((r=u.textContent)==null?void 0:r.length)||0):u.nodeType===Node.ELEMENT_NODE?(d.selectNodeContents(u),d.collapse(!1)):d.setStart(this.contentElement,0),d.collapse(!0),l==null||l.removeAllRanges(),l==null||l.addRange(d)}}return this.executeCommand(n,a)}),this.toolbar.render(this.toolbarElement)):o&&this.appendChild(o),this.contentElement=document.createElement("div"),this.contentElement.className="editora-content rte-content",this.contentElement.contentEditable=this.config.readonly?"false":"true",this.applyLanguageSettings(),this.applyAccessibilitySettings(),this.applySpellcheckSettings(),this.config.placeholder&&this.contentElement.setAttribute("data-placeholder",this.config.placeholder);try{document.execCommand("defaultParagraphSeparator",!1,"p")}catch(n){console.warn("defaultParagraphSeparator not supported:",n)}if(t){const n=document.createElement("div");n.innerHTML=t.trim(),!Array.from(n.childNodes).some(r=>{if(r.nodeType===Node.ELEMENT_NODE){const l=r.tagName;return["P","DIV","H1","H2","H3","H4","H5","H6","UL","OL","BLOCKQUOTE","PRE"].includes(l)}return!1})&&t.trim()?this.contentElement.innerHTML=`<p>${t.trim()}</p>`:this.contentElement.innerHTML=t}else this.config.placeholder?this.contentElement.innerHTML="":this.contentElement.innerHTML="<p><br></p>";this.appendChild(this.contentElement),this.isToolbarFloatingEnabled()&&(this.floatingToolbar=new I({enabled:!0}),this.floatingToolbar.create(this)),i?this.appendChild(i):this.isStatusbarEnabled()&&(this.statusBarElement=document.createElement("div"),this.statusBarElement.className="editora-statusbar-container",this.appendChild(this.statusBarElement),this.statusBar=new D({position:this.getStatusbarPosition()}),this.statusBar.create(this.statusBarElement)),this.config.autofocus&&setTimeout(()=>{var n;return(n=this.contentElement)==null?void 0:n.focus()},0)}setupEventListeners(){if(!this.contentElement||!this.engine)return;const e=this.keyboardShortcutManager;this.contentElement.addEventListener("input",()=>{if(!this.contentElement)return;let o=this.contentElement.innerHTML;const i=this.getPerformanceConfig(),n=this.getContentSanitizeConfig(),a=this.getSecurityConfig();if(a.sanitizeOnInput!==!1&&n.sanitize!==!1){const l=ae(o,n,a);if(l!==o){const d=window.getSelection(),u=d&&d.rangeCount>0?d.getRangeAt(0):null;if(this.contentElement.innerHTML=l,u&&d)try{d.removeAllRanges(),d.addRange(u)}catch(f){}o=l}}this.contentChangeDebounceTimer&&clearTimeout(this.contentChangeDebounceTimer);const r=()=>{this.dispatchEvent(new CustomEvent("content-change",{detail:{html:o},bubbles:!0}))};i.debounceInputMs>0?this.contentChangeDebounceTimer=setTimeout(r,i.debounceInputMs):r(),this.updateStatusBar()}),this.contentElement.addEventListener("contextmenu",o=>{const i=this.config.contextMenu;(i===!1||typeof i=="object"&&i!==null&&i.enabled===!1)&&o.preventDefault()}),this.contentElement.addEventListener("paste",o=>{var u,f;o.preventDefault();const i=this.config.paste||{};let n=((u=o.clipboardData)==null?void 0:u.getData("text/html"))||"";const a=((f=o.clipboardData)==null?void 0:f.getData("text/plain"))||"",r=this.getContentSanitizeConfig(),l=this.getSecurityConfig(),d=!!n&&/class=["'][^"']*Mso|xmlns:w=|urn:schemas-microsoft-com:office/i.test(n);if((i.clean||!i.keepFormatting)&&a){document.execCommand("insertText",!1,a);return}if(i.convertWord===!1&&d&&a){document.execCommand("insertText",!1,a);return}if(n){l.sanitizeOnPaste!==!1&&r.sanitize!==!1&&(n=ne(n,r,l)),this.insertHTMLAtSelection(n);return}a&&document.execCommand("insertText",!1,a)}),this.contentElement.addEventListener("focus",()=>{this.dispatchEvent(new Event("editor-focus",{bubbles:!0})),this.updateStatusBar()}),this.contentElement.addEventListener("blur",()=>{this.contentChangeDebounceTimer&&(clearTimeout(this.contentChangeDebounceTimer),this.contentChangeDebounceTimer=void 0),this.contentElement&&this.dispatchEvent(new CustomEvent("content-change",{detail:{html:this.contentElement.innerHTML},bubbles:!0})),this.dispatchEvent(new Event("editor-blur",{bubbles:!0})),this.updateFloatingToolbar(),this.updateStatusBar()}),this.contentElement.addEventListener("keydown",o=>{this.getAccessibilityConfig().keyboardNavigation&&e.handleKeyDown(o,(n,a)=>{this.executeCommand(n,a)})});const t=()=>{const o=this.getSelectionRangeInEditor(),i=document.activeElement,n=!!i&&!!this.contentElement&&(i===this.contentElement||this.contentElement.contains(i));this.getPerformanceConfig().viewportOnlyScan&&!this.isEditorInViewport()&&!n||!o&&!n||(this.updateFloatingToolbar(),this.updateStatusBar())};this.selectionChangeHandler=t,document.addEventListener("selectionchange",this.selectionChangeHandler)}getSelectionRangeInEditor(){if(!this.contentElement)return null;const e=window.getSelection();if(!e||e.rangeCount===0)return null;const t=e.getRangeAt(0),o=t.commonAncestorContainer;return this.contentElement.contains(o)?t:null}isSelectionBackward(e){if(!e.anchorNode||!e.focusNode)return!1;try{const t=document.createRange();return t.setStart(e.anchorNode,e.anchorOffset),t.setEnd(e.focusNode,e.focusOffset),t.collapsed}catch(t){return!1}}getSelectionAnchorRect(e,t){const o=Array.from(t.getClientRects()).filter(n=>n.width>0||n.height>0);return o.length===0?t.getBoundingClientRect():this.isSelectionBackward(e)?o[0]:o[o.length-1]}updateFloatingToolbar(){if(!this.floatingToolbar)return;const e=this.getPerformanceConfig(),t=document.activeElement===this.contentElement||!!this.contentElement&&this.contentElement.contains(document.activeElement);if(e.viewportOnlyScan&&!this.isEditorInViewport()&&!t){this.floatingToolbar.hide();return}const o=this.getSelectionRangeInEditor();if(!o){this.floatingToolbar.hide();return}if(o.collapsed){this.floatingToolbar.hide();return}const i=window.getSelection();if(!i){this.floatingToolbar.hide();return}const n=this.getSelectionAnchorRect(i,o);if(!n){this.floatingToolbar.hide();return}this.floatingToolbar.show(n.left,n.top-40)}updateStatusBar(){if(!this.statusBar||!this.contentElement)return;const e=this.getPerformanceConfig(),t=document.activeElement===this.contentElement||this.contentElement.contains(document.activeElement);if(e.viewportOnlyScan&&!this.isEditorInViewport()&&!t)return;const o=this.contentElement.textContent||"",{words:i,chars:n}=N(o),a=j(this.contentElement);let r,l;const d=this.getSelectionRangeInEditor();d&&(r=P(this.contentElement,d),d.collapsed||(l=F(d,r),r=void 0)),this.statusBar.update({wordCount:i,charCount:n,lineCount:a,cursorPosition:r,selectionInfo:l})}handleAttributeChange(e,t){switch(e){case"readonly":this.contentElement&&(this.contentElement.contentEditable=t==="true"?"false":"true",this.applyAccessibilitySettings()),this.engine&&this.engine.setReadonly(t==="true");break;case"theme":this.classList.forEach(o=>{o.startsWith("editora-theme-")&&this.classList.remove(o)}),t&&this.classList.add(`editora-theme-${t}`);break;case"placeholder":this.contentElement&&(this.contentElement.setAttribute("data-placeholder",t),this.applyAccessibilitySettings());break;case"accessibility":case"accessibility-enable-aria":case"accessibility-keyboard-navigation":case"accessibility-checker":this.applyAccessibilitySettings();break;case"performance":case"performance-debounce-input-ms":case"performance-viewport-only-scan":break;case"language":case"language-locale":case"language-direction":this.applyLanguageSettings();break;case"spellcheck":case"spellcheck-enabled":case"spellcheck-provider":this.applySpellcheckSettings();break;case"autosave":case"autosave-enabled":case"autosave-interval-ms":case"autosave-storage-key":case"autosave-provider":case"autosave-api-url":this.startAutosave();break;case"security":case"security-sanitize-on-paste":case"security-sanitize-on-input":case"paste":case"paste-clean":case"paste-keep-formatting":case"paste-convert-word":case"context-menu":case"context-menu-enabled":break;case"toolbar":case"toolbar-items":case"toolbar-floating":case"toolbar-sticky":case"plugins":case"statusbar":this.isConnected&&(this.destroy(),this.waitForPluginLoader().then(()=>{this.initialize().catch(o=>{console.error("[RichTextEditor] Error during attribute change re-initialization:",o)})}));break}}resolveConfig(){const e={};for(let t=0;t<this.attributes.length;t++){const o=this.attributes[t];e[o.name]=o.value}return E.resolve({jsConfig:this.jsConfig,attributes:e})}getAPI(){return{getContent:()=>{var e;return((e=this.contentElement)==null?void 0:e.innerHTML)||""},setContent:e=>{this.contentElement&&(this.contentElement.innerHTML=e)},execCommand:(e,t)=>this.executeCommand(e,t),focus:()=>{var e;(e=this.contentElement)==null||e.focus()},blur:()=>{var e;(e=this.contentElement)==null||e.blur()},destroy:()=>{this.destroy()},on:(e,t)=>(this.addEventListener(e,t),()=>this.removeEventListener(e,t)),getConfig:()=>({...this.config}),setReadonly:e=>{this.setAttribute("readonly",e.toString())}}}destroy(){var e,t,o,i;this.contentChangeDebounceTimer&&(clearTimeout(this.contentChangeDebounceTimer),this.contentChangeDebounceTimer=void 0),this.contentElement&&this.persistAutosave(this.contentElement.innerHTML||""),this.stopAutosave(),this.selectionChangeHandler&&(document.removeEventListener("selectionchange",this.selectionChangeHandler),this.selectionChangeHandler=void 0),(e=this.engine)==null||e.destroy(),(t=this.toolbar)==null||t.destroy(),(o=this.floatingToolbar)==null||o.destroy(),(i=this.statusBar)==null||i.destroy(),this.innerHTML="",this.contentElement=void 0,this.toolbarElement=void 0,this.statusBarElement=void 0,this.loadedPlugins=[],this.isInitialized=!1,this.dispatchEvent(new Event("editor-destroy",{bubbles:!0}))}getContent(){var e;return((e=this.contentElement)==null?void 0:e.innerHTML)||""}setContent(e){this.contentElement&&(this.contentElement.innerHTML=e)}execCommand(e,t){return this.executeCommand(e,t)}focus(){var e;(e=this.contentElement)==null||e.focus()}blur(){var e;(e=this.contentElement)==null||e.blur()}}function ce(s){return new $(s)}function de(){typeof window!="undefined"&&!customElements.get("editora-editor")&&customElements.define("editora-editor",g)}return c.CharacterDialog=Q,c.ColorPicker=V,c.CommandRegistry=A,c.ConfigResolver=E,c.Dialog=b,c.DocumentModel=v,c.Dropdown=_,c.Editor=q,c.EditorEngine=w,c.EditorState=y,c.EmojiDialog=Z,c.FloatingToolbar=I,c.ImageDialog=Y,c.KeyboardShortcutManager=T,c.LinkDialog=G,c.MathDialog=J,c.MediaPlugin=K,c.PluginLoader=H,c.PluginManager=k,c.PluginRuntime=M,c.ReactAdapter=O,c.RichTextEditorElement=g,c.Schema=L,c.SpellcheckPlugin=W,c.StatusBar=D,c.TableDialog=X,c.ToolbarRenderer=x,c.VanillaAdapter=$,c.calculateTextStats=N,c.countLines=j,c.createEditor=ce,c.createPluginRuntime=U,c.createReactAdapter=ee,c.getCursorPosition=P,c.getSelectionInfo=F,c.getTextOffset=z,c.initWebComponent=de,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"}),c})({});
|
|
521
|
+
`,e}updateGrid(){const e=this.categorySelect.value;this.emojisGrid.innerHTML="";let t=[];e==="all"?t=Object.values(this.emojis).flat():t=this.emojis[e]||[],t.forEach(o=>{const i=document.createElement("button");i.className="emoji-button",i.textContent=o,i.title=`Insert ${o}`,i.addEventListener("click",n=>{n.preventDefault(),this.handleSelect(o)}),this.emojisGrid.appendChild(i)})}filterEmojis(){const e=this.searchInput.value.toLowerCase();this.emojisGrid.querySelectorAll(".emoji-button").forEach(o=>{const i=o.textContent||"",n=!e||i.includes(e);o.style.display=n?"flex":"none"})}handleSelect(e){this.onSelect(e),this.dialog.close()}show(){this.dialog.show(),this.searchInput.value="",this.categorySelect.value="popular",this.updateGrid(),setTimeout(()=>this.searchInput.focus(),100)}close(){this.dialog.close()}}function P(l,e){const t=l.textContent||"",o=z(l,e.startContainer,e.startOffset),n=t.substring(0,o).split(`
|
|
522
|
+
`),a=n.length,r=n[n.length-1].length+1;return{line:a,column:r}}function z(l,e,t){var a;let o=0;const i=document.createTreeWalker(l,NodeFilter.SHOW_TEXT,null);let n=i.firstChild();for(;n;){if(n===e){o+=t;break}else n.nodeType===Node.TEXT_NODE&&(o+=((a=n.textContent)==null?void 0:a.length)||0);n=i.nextNode()}return o}function j(l){var o,i;const e=l.querySelectorAll("div, p, br, h1, h2, h3, h4, h5, h6, blockquote, li, pre");let t=1;if(e.length>0){t=e.length;const n=e[e.length-1];(n.tagName==="BR"||((o=n.innerHTML)==null?void 0:o.trim())===""||((i=n.textContent)==null?void 0:i.trim())==="")&&t++}else{const a=(l.textContent||"").split(`
|
|
523
|
+
`).length;t=Math.max(1,a)}return t}function N(l){const e=l.trim()?l.trim().split(/\s+/).length:0,t=l.length;return{words:e,chars:t}}function F(l,e){const t=l.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}}const S=class S{static resolve(e){const t={};if(Object.assign(t,this.EDITOR_DEFAULTS),e.pluginDefaults&&Object.assign(t,e.pluginDefaults),e.attributes){const o=this.parseAttributes(e.attributes);Object.assign(t,o)}return e.jsConfig&&Object.assign(t,e.jsConfig),this.normalizeConfig(t)}static normalizeConfig(e){const t={...e};if(t.toolbarFloating!==void 0||t.toolbarSticky!==void 0){const a=typeof t.toolbar=="object"&&t.toolbar?{...t.toolbar}:typeof t.toolbar=="string"?{items:t.toolbar}:{};t.toolbarFloating!==void 0&&(a.floating=!!t.toolbarFloating),t.toolbarSticky!==void 0&&(a.sticky=!!t.toolbarSticky),t.toolbar=a}if(t.toolbarItems!==void 0&&typeof t.toolbar=="object"&&t.toolbar&&(t.toolbar.items=t.toolbarItems),t.autosaveEnabled!==void 0||t.autosaveIntervalMs!==void 0||t.autosaveStorageKey!==void 0||t.autosaveProvider!==void 0||t.autosaveApiUrl!==void 0){const a=typeof t.autosave=="object"&&t.autosave?{...t.autosave}:{};t.autosaveEnabled!==void 0&&(a.enabled=!!t.autosaveEnabled),t.autosaveIntervalMs!==void 0&&(a.intervalMs=Number(t.autosaveIntervalMs)),t.autosaveStorageKey!==void 0&&(a.storageKey=t.autosaveStorageKey),t.autosaveProvider!==void 0&&(a.provider=t.autosaveProvider),t.autosaveApiUrl!==void 0&&(a.apiUrl=t.autosaveApiUrl),t.autosave=a}const o={enabled:!1,intervalMs:3e4,storageKey:"rte-autosave",provider:"localStorage",apiUrl:""};if(typeof t.autosave=="boolean")t.autosave={...o,enabled:t.autosave};else if(typeof t.autosave=="object"&&t.autosave){const a={...o,...t.autosave};a.intervalMs===void 0&&a.interval!==void 0&&(a.intervalMs=Number(a.interval)),a.enabled===void 0&&(a.enabled=!0),(!Number.isFinite(a.intervalMs)||a.intervalMs<=0)&&(a.intervalMs=o.intervalMs),t.autosave=a}else t.autosave=o;if(t.languageLocale!==void 0||t.languageDirection!==void 0){const a=typeof t.language=="object"&&t.language?{...t.language}:{};t.languageLocale!==void 0&&(a.locale=t.languageLocale),t.languageDirection!==void 0&&(a.direction=t.languageDirection),t.language=a}const i={locale:"en",direction:"ltr"};if(typeof t.language=="string"?t.language={locale:t.language,direction:i.direction}:typeof t.language=="object"&&t.language?t.language={...i,...t.language}:t.language=i,t.spellcheckEnabled!==void 0||t.spellcheckProvider!==void 0||t.spellcheckApiUrl!==void 0){const a=typeof t.spellcheck=="object"&&t.spellcheck?{...t.spellcheck}:{};t.spellcheckEnabled!==void 0&&(a.enabled=!!t.spellcheckEnabled),t.spellcheckProvider!==void 0&&(a.provider=t.spellcheckProvider),t.spellcheckApiUrl!==void 0&&(a.apiUrl=t.spellcheckApiUrl),t.spellcheck=a}const n={enabled:!1,provider:"browser",apiUrl:""};if(typeof t.spellcheck=="boolean")t.spellcheck={...n,enabled:t.spellcheck};else if(typeof t.spellcheck=="object"&&t.spellcheck){const a={...n,...t.spellcheck};!a.provider&&a.mode&&(a.provider=a.mode==="local"?"browser":"api"),a.enabled===void 0&&(a.enabled=!!(a.mode||a.provider||a.apiUrl)),t.spellcheck=a}else t.spellcheck=n;return t.contextMenuEnabled!==void 0&&(t.contextMenu={enabled:!!t.contextMenuEnabled}),typeof t.contextMenu=="boolean"?t.contextMenu={enabled:t.contextMenu}:typeof t.contextMenu=="object"&&t.contextMenu?t.contextMenu={enabled:t.contextMenu.enabled!==!1}:t.contextMenu={enabled:!0},(t.pasteClean!==void 0||t.pasteKeepFormatting!==void 0||t.pasteConvertWord!==void 0)&&(t.paste={...t.paste||{},...t.pasteClean!==void 0?{clean:!!t.pasteClean}:{},...t.pasteKeepFormatting!==void 0?{keepFormatting:!!t.pasteKeepFormatting}:{},...t.pasteConvertWord!==void 0?{convertWord:!!t.pasteConvertWord}:{}}),t.paste={clean:!0,keepFormatting:!1,convertWord:!0,...t.paste||{}},t.contentConfig={allowedTags:[],allowedAttributes:{},sanitize:!0,...t.contentConfig||{}},(t.securitySanitizeOnPaste!==void 0||t.securitySanitizeOnInput!==void 0)&&(t.security={...t.security||{},...t.securitySanitizeOnPaste!==void 0?{sanitizeOnPaste:!!t.securitySanitizeOnPaste}:{},...t.securitySanitizeOnInput!==void 0?{sanitizeOnInput:!!t.securitySanitizeOnInput}:{}}),t.security={sanitizeOnPaste:!0,sanitizeOnInput:!0,...t.security||{}},(t.accessibilityEnableAria!==void 0||t.accessibilityKeyboardNavigation!==void 0||t.accessibilityChecker!==void 0)&&(t.accessibility={...t.accessibility||{},...t.accessibilityEnableAria!==void 0?{enableARIA:!!t.accessibilityEnableAria}:{},...t.accessibilityKeyboardNavigation!==void 0?{keyboardNavigation:!!t.accessibilityKeyboardNavigation}:{},...t.accessibilityChecker!==void 0?{checker:!!t.accessibilityChecker}:{}}),typeof t.accessibility=="boolean"&&(t.accessibility={enableARIA:t.accessibility,keyboardNavigation:t.accessibility,checker:!1}),t.accessibility={enableARIA:!0,keyboardNavigation:!0,checker:!1,...t.accessibility||{}},(t.performanceDebounceInputMs!==void 0||t.performanceViewportOnlyScan!==void 0)&&(t.performance={...t.performance||{},...t.performanceDebounceInputMs!==void 0?{debounceInputMs:Number(t.performanceDebounceInputMs)}:{},...t.performanceViewportOnlyScan!==void 0?{viewportOnlyScan:!!t.performanceViewportOnlyScan}:{}}),typeof t.performance=="boolean"&&(t.performance={debounceInputMs:100,viewportOnlyScan:t.performance}),t.performance={debounceInputMs:100,viewportOnlyScan:!0,...t.performance||{}},(typeof t.performance.debounceInputMs!="number"||!Number.isFinite(t.performance.debounceInputMs)||t.performance.debounceInputMs<0)&&(t.performance.debounceInputMs=100),t}static parseAttributes(e){const t={};for(const[o,i]of Object.entries(e)){const n=this.kebabToCamel(o);t[n]=this.parseAttributeValue(i)}return t}static parseAttributeValue(e){if(e==="true")return!0;if(e==="false")return!1;if(/^\d+$/.test(e))return parseInt(e,10);if(/^\d+\.\d+$/.test(e))return parseFloat(e);if(e.startsWith("{")||e.startsWith("["))try{return JSON.parse(e)}catch(t){return e}return e}static kebabToCamel(e){return e.replace(/-([a-z])/g,(t,o)=>o.toUpperCase())}static validate(e){const t=[];return e.height!==void 0&&typeof e.height=="number"&&e.height<0&&t.push("height must be a positive number"),e.width!==void 0&&typeof e.width=="number"&&e.width<0&&t.push("width must be a positive number"),e.plugins!==void 0&&!Array.isArray(e.plugins)&&typeof e.plugins!="string"&&t.push("plugins must be an array or string"),e.theme!==void 0&&typeof e.theme!="string"&&t.push("theme must be a string"),{valid:t.length===0,errors:t}}static getDefaults(){return{...this.EDITOR_DEFAULTS}}static merge(...e){const t={};for(const o of e)for(const[i,n]of Object.entries(o))n!=null&&(typeof n=="object"&&!Array.isArray(n)&&t[i]?t[i]=this.merge(t[i],n):t[i]=n);return t}};S.EDITOR_DEFAULTS={height:400,width:"100%",readonly:!1,disabled:!1,menubar:!0,toolbar:!0,plugins:[],theme:"light",content:"",placeholder:"Start typing...",autofocus:!1,autosave:!1,accessibility:{enableARIA:!0,keyboardNavigation:!0,checker:!1},performance:{debounceInputMs:100,viewportOnlyScan:!0},spellcheck:{enabled:!1,provider:"browser",apiUrl:""},language:{locale:"en",direction:"ltr"},contextMenu:{enabled:!0},contentConfig:{allowedTags:[],allowedAttributes:{},sanitize:!0},paste:{clean:!0,keepFormatting:!1,convertWord:!0},security:{sanitizeOnPaste:!0,sanitizeOnInput:!0},statusbar:!1};let E=S;class H{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 o=this.pluginRegistry.get(e);if(!o)return console.warn(`Plugin not found: ${e}`),null;const i=await o();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 o=e.split(/\s+/).filter(Boolean);return this.loadMultiple(o,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 O{constructor(e={}){this.changeListeners=[],this.options=e,this.engine=new k({content:e.content,plugins:e.plugins||[],readonly:e.readonly}),e.onChange&&this.onChange(e.onChange),this.engine.on("change",()=>{const t=this.getHTML();this.changeListeners.forEach(o=>o(t))})}mount(e,t){this.contentElement=e,this.toolbarElement=t,this.contentElement.contentEditable=this.options.readonly?"false":"true",this.contentElement.className="rte-content",this.options.content&&(this.contentElement.innerHTML=this.options.content),this.options.toolbar!==!1&&this.toolbarElement&&(this.toolbar=new x({items:typeof this.options.toolbar=="string"?this.options.toolbar:void 0},this.options.plugins||[]),this.toolbar.setCommandHandler((o,i)=>{this.execCommand(o,i)}),this.toolbar.render(this.toolbarElement)),this.contentElement.addEventListener("input",()=>{const o=this.getHTML();this.changeListeners.forEach(i=>i(o))}),this.options.onInit&&this.options.onInit(this.getAPI())}getHTML(){var e;return((e=this.contentElement)==null?void 0:e.innerHTML)||""}setHTML(e){this.contentElement&&(this.contentElement.innerHTML=e)}execCommand(e,t){const o=this.engine.execCommand(e,t);return this.toolbar,o}focus(){var e;(e=this.contentElement)==null||e.focus()}blur(){var e;(e=this.contentElement)==null||e.blur()}onChange(e){return this.changeListeners.push(e),()=>{const t=this.changeListeners.indexOf(e);t>-1&&this.changeListeners.splice(t,1)}}registerCommand(e,t){if(typeof window!="undefined"){const o=window.__editorCommands||new Map;o.set(e,t),window.__editorCommands=o}}getState(){return{plugins:this.options.plugins,config:this.options,engine:this.engine.getState()}}getAPI(){var e;return{getHTML:()=>this.getHTML(),setHTML:t=>this.setHTML(t),execCommand:(t,o)=>this.execCommand(t,o),focus:()=>this.focus(),blur:()=>this.blur(),destroy:()=>this.destroy(),registerCommand:(t,o)=>this.registerCommand(t,o),onChange:t=>this.onChange(t),getState:()=>this.getState(),toolbar:{items:((e=this.options.plugins)==null?void 0:e.flatMap(t=>t.toolbar||[]))||[]}}}destroy(){var e;this.engine.destroy(),(e=this.toolbar)==null||e.destroy(),this.changeListeners=[],this.options.onDestroy&&this.options.onDestroy()}}function ee(l){return new O(l)}class ${constructor(e){this.options=e,this.containerElement=e.element;const t=this.resolvePlugins(e.plugins);this.engine=new k({content:e.content,plugins:t,readonly:e.readonly}),this.initializeDOM()}resolvePlugins(e){return e?typeof e=="string"?(console.warn("String-based plugin loading not yet implemented for VanillaAdapter"),[]):e:[]}initializeDOM(){this.containerElement.innerHTML="",this.containerElement.classList.add("editora-editor"),this.options.enableToolbar!==!1&&this.options.toolbar!==!1&&(this.toolbarElement=document.createElement("div"),this.toolbarElement.className="editora-toolbar-container",this.containerElement.appendChild(this.toolbarElement),this.toolbar=new x({items:typeof this.options.toolbar=="string"?this.options.toolbar:void 0},this.options.plugins||[]),this.toolbar.setCommandHandler((e,t)=>{this.execCommand(e,t)}),this.toolbar.render(this.toolbarElement)),this.contentElement=document.createElement("div"),this.contentElement.className="editora-content",this.contentElement.contentEditable=this.options.readonly?"false":"true",this.contentElement.style.minHeight="200px",this.contentElement.style.outline="none",this.contentElement.style.padding="12px",this.options.content&&(this.contentElement.innerHTML=this.options.content),this.containerElement.appendChild(this.contentElement),this.contentElement.addEventListener("input",()=>{this.containerElement.dispatchEvent(new CustomEvent("change",{detail:{html:this.getContent()}}))})}getContent(){var e;return((e=this.contentElement)==null?void 0:e.innerHTML)||""}setContent(e){this.contentElement&&(this.contentElement.innerHTML=e)}execCommand(e,t){return this.engine.execCommand(e,t)}focus(){var e;(e=this.contentElement)==null||e.focus()}on(e,t){const o=i=>{t(i.detail)};return this.containerElement.addEventListener(e,o),()=>{this.containerElement.removeEventListener(e,o)}}destroy(){var e;this.engine.destroy(),(e=this.toolbar)==null||e.destroy(),this.containerElement.innerHTML=""}}const te=["p","br","strong","em","u","s","strike","del","b","i","h1","h2","h3","h4","h5","h6","ul","ol","li","a","img","video","audio","table","thead","tbody","tr","th","td","blockquote","pre","code","span","div","sup","sub","hr"],oe={"*":["class","style","id","data-*"],a:["href","target","rel","title"],img:["src","alt","width","height","loading"],video:["src","controls","width","height","autoplay","loop","muted"],audio:["src","controls","autoplay","loop","muted"],table:["border","cellpadding","cellspacing"],td:["colspan","rowspan","align","valign"],th:["colspan","rowspan","align","valign"]};function R(l,e,t){if((e==null?void 0:e.sanitize)===!1)return l;const o=e!=null&&e.allowedTags&&e.allowedTags.length>0?e.allowedTags:te,n=!!(e!=null&&e.allowedAttributes)&&Object.keys(e.allowedAttributes).length>0?e.allowedAttributes:oe,a=document.createElement("div");return a.innerHTML=l,B(a,o,n),a.innerHTML}function B(l,e,t){const o=Array.from(l.childNodes);for(const i of o)if(i.nodeType===Node.ELEMENT_NODE){const n=i,a=n.tagName.toLowerCase();if(!e.includes(a)){for(;n.firstChild;)l.insertBefore(n.firstChild,n);l.removeChild(n);continue}ie(n,t),B(n,e,t)}else i.nodeType!==Node.TEXT_NODE&&l.removeChild(i)}function ie(l,e){const t=l.tagName.toLowerCase(),o=Array.from(l.attributes),i=e[t]||[],n=e["*"]||[],a=[...i,...n];for(const r of o){const s=r.name.toLowerCase();let c=!1;a.includes(s)&&(c=!0);for(const u of a)if(u.endsWith("*")){const f=u.slice(0,-1);if(s.startsWith(f)){c=!0;break}}(s.startsWith("on")||s==="javascript:"||s==="href"&&r.value.trim().toLowerCase().startsWith("javascript:")||s==="src"&&r.value.trim().toLowerCase().startsWith("javascript:"))&&(c=!1),c||l.removeAttribute(r.name)}l.hasAttribute("href")&&(l.getAttribute("href")||"").trim().toLowerCase().startsWith("javascript:")&&l.removeAttribute("href"),l.hasAttribute("src")&&(l.getAttribute("src")||"").trim().toLowerCase().startsWith("javascript:")&&l.removeAttribute("src")}function ne(l,e,t){return(t==null?void 0:t.sanitizeOnPaste)===!1?l:R(l,e)}function ae(l,e,t){return(t==null?void 0:t.sanitizeOnInput)===!1?l:R(l,e)}const re='.editora-editor{display:flex;flex-direction:column;border:1px solid #ddd;border-radius:4px;background:#fff;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,sans-serif;font-size:14px;overflow:hidden}.editora-editor *{box-sizing:border-box}.editora-theme-light{background:#fff;color:#333}.editora-theme-dark{--editora-dark-toolbar-bg-start: #353d48;--editora-dark-toolbar-bg-end: #2d3540;--editora-dark-button-bg-start: #46505f;--editora-dark-button-bg-end: #3b4553;--editora-dark-button-hover-start: #525d6d;--editora-dark-button-hover-end: #465262;--editora-dark-button-active-start: #5eaaf6;--editora-dark-button-active-end: #4a95de;--editora-dark-border: #475263;--editora-dark-border-strong: #566275;--editora-dark-text: #e1e9f5;--editora-dark-text-strong: #f3f7ff;--editora-dark-text-muted: #aeb9cc;--editora-dark-surface: #1d242d;--editora-dark-content: #1f2732;background:linear-gradient(180deg,#1b2330,#1c2430);color:var(--editora-dark-text);border-color:var(--editora-dark-border)}.editora-toolbar{display:flex;align-items:center;gap:4px;padding:8px;background:#f5f5f5;border-bottom:1px solid #ddd;flex-wrap:wrap}.editora-theme-dark .editora-toolbar{background:linear-gradient(180deg,var(--editora-dark-toolbar-bg-start) 0%,var(--editora-dark-toolbar-bg-end) 100%);border-bottom-color:var(--editora-dark-border);box-shadow:inset 0 1px #ffffff0d}.editora-toolbar-sticky{position:sticky;top:0;z-index:100;position:-webkit-sticky}.editora-toolbar-group{display:flex;align-items:center;gap:2px}.editora-toolbar-button{padding:6px 12px;border:1px solid #ccc;background:#fff;cursor:pointer;border-radius:3px;font-weight:600;font-size:14px;height:30px;display:flex;align-items:center;white-space:nowrap}.editora-toolbar-group-button{display:flex;align-items:center}.editora-toolbar-input.font-size{width:40px;padding:.25rem;text-align:center;font-size:14px;background:#fff;border:1px solid var(--rte-color-border-light);border-radius:var(--rte-radius-sm)}.editora-toolbar-group-items{display:flex;align-items:center;border:1px solid #ccc;.editora-toolbar-button{border:none;border-radius:0;&:first-child{border-right:1px solid #ccc;border-top-left-radius:3px;border-bottom-left-radius:3px}&:last-child{border-left:1px solid #ccc;border-top-right-radius:3px;border-bottom-right-radius:3px}}}.editora-theme-dark .editora-toolbar-button{background:linear-gradient(180deg,var(--editora-dark-button-bg-start) 0%,var(--editora-dark-button-bg-end) 100%);border-color:var(--editora-dark-border-strong);color:var(--editora-dark-text);box-shadow:inset 0 1px #ffffff14,0 1px 1px #00000059}.editora-theme-dark .editora-toolbar-group-items{border-color:var(--editora-dark-border-strong);background:linear-gradient(180deg,var(--editora-dark-button-bg-start) 0%,var(--editora-dark-button-bg-end) 100%)}.editora-theme-dark .editora-toolbar-group-items .editora-toolbar-button:first-child{border-right-color:#566275}.editora-theme-dark .editora-toolbar-group-items .editora-toolbar-button:last-child{border-left-color:#566275}.editora-theme-dark .editora-toolbar-input.font-size{background-color:#2e3642;color:var(--editora-dark-text-strong);border-color:var(--editora-dark-border-strong);caret-color:var(--editora-dark-text-strong)}.editora-theme-dark .editora-toolbar-input.font-size::placeholder{color:var(--editora-dark-text-strong);opacity:1}.editora-toolbar-button:hover{background:#e0e0e0;border-color:#ccc}.editora-theme-dark .editora-toolbar-button:hover{background:linear-gradient(180deg,var(--editora-dark-button-hover-start) 0%,var(--editora-dark-button-hover-end) 100%);border-color:#66748a;color:var(--editora-dark-text-strong)}.editora-toolbar-button:active,.editora-toolbar-button.active{background:#d0d0d0;border-color:#999}.editora-theme-dark .editora-toolbar-button:active,.editora-theme-dark .editora-toolbar-button.active{background:linear-gradient(180deg,var(--editora-dark-button-active-start) 0%,var(--editora-dark-button-active-end) 100%);border-color:#67adf4;color:#0f1b2a}.editora-theme-dark .editora-toolbar-button:disabled{background:#313946;border-color:#424d5e;color:#7f8ca1}.editora-theme-dark .editora-toolbar-button[data-command=insertTable],.editora-theme-dark .editora-toolbar-button[data-command=print],.editora-theme-dark .editora-toolbar-button[data-command=toggleSpellCheck],.editora-theme-dark .editora-toolbar-button[data-command=toggleA11yChecker],.editora-theme-dark .editora-toolbar-button[data-command=setDirectionLTR],.editora-theme-dark .editora-toolbar-button[data-command=setDirectionRTL]{color:#f1f6ff}.editora-toolbar-button:disabled{opacity:.5;cursor:not-allowed}.editora-toolbar-icon{display:inline-flex;align-items:center;justify-content:center;width:24px;height:24px;line-height:1}.editora-toolbar-button svg,.editora-toolbar-icon svg{width:20px;height:20px;display:block;color:currentColor;fill:currentColor}.editora-theme-dark .editora-toolbar-icon,.editora-theme-dark .editora-toolbar-icon *{color:inherit}.editora-theme-dark :is(.editora-toolbar-button,.editora-toolbar-icon) svg :is([stroke="#000" i],[stroke="#000000" i],[stroke=black i],[stroke="#0f0f0f" i],[stroke="#111111" i],[style*="stroke:#000" i],[style*="stroke: #000" i],[style*="stroke:black" i],[style*="stroke: black" i],[style*="stroke:#0f0f0f" i],[style*="stroke: #0f0f0f" i]){stroke:currentColor!important}.editora-theme-dark :is(.editora-toolbar-button,.editora-toolbar-icon) svg :is([fill="#000" i],[fill="#000000" i],[fill=black i],[fill="#0f0f0f" i],[fill="#111111" i],[style*="fill:#000" i],[style*="fill: #000" i],[style*="fill:black" i],[style*="fill: black" i],[style*="fill:#0f0f0f" i],[style*="fill: #0f0f0f" i]){fill:currentColor!important}.editora-toolbar-separator{width:1px;height:24px;background:#ddd;margin:0 4px}.editora-theme-dark .editora-toolbar-separator{background:#4d596b}.editora-toolbar-dropdown{position:relative}.editora-toolbar-dropdown-menu{position:absolute;top:100%;left:0;min-width:150px;margin-top:4px;padding:4px 0;background:#fff;border:1px solid #ddd;border-radius:4px;box-shadow:0 2px 8px #00000026;z-index:1000}.editora-theme-dark .editora-toolbar-dropdown-menu{background:#29323d;border-color:#4d596b;box-shadow:0 8px 20px #00000073}.editora-toolbar-dropdown-item{display:block;width:100%;padding:8px 12px;border:none;background:transparent;color:#333;text-align:left;cursor:pointer;font-size:13px;transition:background .15s ease}.editora-theme-dark .editora-toolbar-dropdown-item{color:#d7deea}.editora-toolbar-dropdown-item:hover{background:#f5f5f5}.editora-theme-dark .editora-toolbar-dropdown-item:hover{background:#3a4554;color:#f0f6ff}.editora-content{flex:1;min-height:200px;padding:16px;outline:none;overflow-y:auto;line-height:1.6}.editora-theme-dark .editora-content{color:#ecf3ff;background:linear-gradient(180deg,var(--editora-dark-content) 0%,#1c232e 100%)}.editora-content:empty:before{content:attr(data-placeholder);color:#999;pointer-events:none}.editora-theme-dark .editora-content:empty:before{color:#8f9bb0}.editora-content h1{font-size:2em;margin:.67em 0;font-weight:600}.editora-content h2{font-size:1.5em;margin:.75em 0;font-weight:600}.editora-content h3{font-size:1.17em;margin:.83em 0;font-weight:600}.editora-content p{margin:1em 0}.editora-content ul,.editora-content ol{margin:1em 0;padding-left:2em}.editora-content a{color:#06c;text-decoration:underline}.editora-theme-dark .editora-content a{color:#4db8ff}.editora-content code{padding:2px 4px;background:#f5f5f5;border-radius:3px;font-family:Monaco,Menlo,Consolas,monospace;font-size:.9em}.editora-theme-dark .editora-content code{background:#1e1e1e}.editora-content pre{padding:12px;background:#f5f5f5;border-radius:4px;overflow-x:auto;margin:1em 0}.editora-theme-dark .editora-content pre{background:#1e1e1e}.editora-theme-dark .rte-code-block{background:linear-gradient(180deg,#212a36,#1b2430)!important;border-color:#4f5b70!important;color:#e7effc!important}.editora-theme-dark .rte-code-block code{color:#e7effc!important}.editora-theme-dark .rte-code-block:before{background:#111927!important;color:#dce8ff!important}.editora-theme-dark .rte-code-block .rte-code-copy{background:#2b3441!important;border-color:#5a667b!important;color:#dce8ff!important}.editora-content blockquote{margin:1em 0;padding-left:1em;border-left:4px solid #ddd;color:#666}.editora-theme-dark .editora-content blockquote{border-left-color:#3c3c3c;color:#9a9a9a}.editora-floating-toolbar{position:absolute;padding:4px;background:#fff;border:1px solid #ddd;border-radius:4px;box-shadow:0 2px 8px #00000026;z-index:1000}.editora-theme-dark .editora-floating-toolbar{background:#29323d;border-color:#4d596b;box-shadow:0 8px 20px #00000073}.editora-statusbar-container{display:flex;flex-direction:column}.editora-statusbar-left{display:flex;align-items:center;gap:8px}.editora-statusbar-right{display:flex;align-items:center;gap:8px;margin-left:auto}.editora-statusbar{display:flex;align-items:center;gap:12px;padding:6px 12px;background:#f5f5f5;border-top:1px solid #ddd;font-size:12px;color:#666}.editora-theme-dark .editora-statusbar{background:linear-gradient(180deg,#2c3440,#252d37);border-top-color:#3f4a5b;color:#d7deea}.editora-statusbar-item{white-space:nowrap}.editora-statusbar-separator{color:#ddd}.editora-theme-dark .editora-statusbar-separator{color:#566275}.editora-editor[readonly] .editora-content{background:#fafafa;cursor:not-allowed}.editora-theme-dark.editora-editor[readonly] .editora-content{background:#1a1a1a}.editora-editor:focus-within{border-color:#06c;box-shadow:0 0 0 3px #0066cc1a}.editora-theme-dark.editora-editor:focus-within{border-color:#4db8ff;box-shadow:0 0 0 3px #4db8ff1a}.editora-editor[disabled]{opacity:.6;pointer-events:none}@media(max-width:768px){.editora-toolbar{padding:4px}.editora-toolbar-button{min-width:28px;min-height:28px;padding:4px 8px;font-size:12px}.editora-content{padding:12px}}.editora-content ::selection{background:#06c3}.editora-theme-dark .editora-content ::selection{background:#4db8ff33}.editora-content table{border-collapse:collapse;width:100%;margin:1em 0}.editora-content th,.editora-content td{border:1px solid #ddd;padding:8px 12px;text-align:left}.editora-theme-dark .editora-content th,.editora-theme-dark .editora-content td{border-color:#3c3c3c}.editora-content th{background:#f5f5f5;font-weight:600}.editora-theme-dark .editora-content th{background:#252526}.editora-content img{max-width:100%;height:auto;border-radius:4px;display:block}.editora-content video{max-width:100%;height:auto;border-radius:4px;display:block}.editora-editor.loading{opacity:.7;pointer-events:none}.editora-editor.loading:after{content:"";position:absolute;top:50%;left:50%;width:24px;height:24px;margin:-12px 0 0 -12px;border:3px solid #ddd;border-top-color:#06c;border-radius:50%;animation:editora-spin .8s linear infinite}@keyframes editora-spin{to{transform:rotate(360deg)}}.toolbar-container-wrapper{display:flex;align-items:center;background:#fff;border-bottom:1px solid #e0e0e0;padding:0;margin:0;width:100%;box-sizing:border-box;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,sans-serif;font-size:14px;line-height:1.5;position:relative}.toolbar-container-wrapper[data-toolbar-sticky=true]{position:sticky;top:0;z-index:999;box-shadow:0 2px 4px #0000001a}.toolbar-container-wrapper[data-toolbar-floating=true]{position:fixed;top:0;left:0;right:0;z-index:1000;box-shadow:0 4px 12px #00000026}.toolbar-container-wrapper[data-toolbar-position=bottom]{border-bottom:none;border-top:1px solid #e0e0e0}.toolbar-container-wrapper .toolbar-wrapper{display:flex;width:100%;padding:8px;gap:4px;flex-wrap:wrap;align-items:center}.toolbar-container-wrapper .toolbar{display:flex;width:100%;gap:4px;flex-wrap:wrap;align-items:center}.toolbar-container-wrapper .toolbar-container{display:flex;gap:4px;flex-wrap:wrap;align-items:center;flex:1;position:relative}.toolbar-container-wrapper .toolbar-item{display:flex;align-items:center;gap:2px}.toolbar-container-wrapper .toolbar-button{padding:6px 10px;border:1px solid #d1d5db;background:#fff;border-radius:4px;cursor:pointer;font-size:13px;display:flex;align-items:center;justify-content:center;gap:4px;transition:all .15s ease;min-height:32px;white-space:nowrap}.toolbar-container-wrapper .toolbar-button:hover{background-color:#f3f4f6;border-color:#9ca3af}.toolbar-container-wrapper .toolbar-button:active,.toolbar-container-wrapper .toolbar-button[data-active=true]{background-color:#06c;color:#fff;border-color:#0052a3;box-shadow:inset 0 1px 3px #0000001a}.toolbar-container-wrapper .toolbar-button:disabled{opacity:.5;cursor:not-allowed;background-color:#f9fafb}.toolbar-container-wrapper .toolbar-more-button{padding:6px 8px;font-size:16px;font-weight:500;line-height:1}.toolbar-container-wrapper .toolbar-separator{width:1px;height:24px;background-color:#d1d5db;margin:0 4px}.toolbar-container-wrapper .toolbar-icon{display:inline-flex;align-items:center;justify-content:center;width:18px;height:18px;flex-shrink:0}.toolbar-container-wrapper .toolbar-icon svg{width:100%;height:100%}.toolbar-container-wrapper .toolbar-dropdown{position:relative;display:flex;align-items:center}.toolbar-container-wrapper .toolbar-dropdown-arrow{font-size:10px;margin-left:2px;line-height:1}.toolbar-container-wrapper .toolbar-dropdown-menu{position:absolute;top:100%;left:0;background:#fff;border:1px solid #d1d5db;border-radius:6px;box-shadow:0 4px 12px #00000026;z-index:1000;min-width:160px;padding:4px 0;margin-top:4px;display:none}.toolbar-container-wrapper .toolbar-dropdown-menu.show{display:block}.toolbar-container-wrapper .toolbar-dropdown-item{display:block;width:100%;padding:8px 12px;border:none;background:transparent;text-align:left;cursor:pointer;font-size:13px;color:#1f2937;transition:background-color .15s ease;font-family:inherit}.toolbar-container-wrapper .toolbar-dropdown-item:hover{background-color:#f3f4f6}.toolbar-container-wrapper .toolbar-dropdown-item:active{background-color:#e5e7eb}.toolbar-container-wrapper .toolbar-input{padding:6px 8px;border:1px solid #d1d5db;border-radius:4px;font-size:13px;font-family:inherit;background-color:#fff;color:#1f2937;transition:all .15s ease}.toolbar-container-wrapper .toolbar-input:focus{outline:none;border-color:#06c;box-shadow:0 0 0 3px #0066cc1a;background-color:#fff}.toolbar-container-wrapper .toolbar-input::placeholder{color:#9ca3af}.toolbar-overflow-menu{animation:slideDown .2s ease-out}@keyframes slideDown{0%{opacity:0;transform:translateY(-8px)}to{opacity:1;transform:translateY(0)}}.toolbar-overflow-item{transition:background-color .15s ease}.floating-toolbar{user-select:none;-webkit-user-select:none;font-family:system-ui,-apple-system,sans-serif;font-size:14px;animation:fadeInUp .15s ease-out}@keyframes fadeInUp{0%{opacity:0;transform:translate(-50%) translateY(10px)}to{opacity:1;transform:translate(-50%) translateY(0)}}.floating-toolbar-btn{display:flex;align-items:center;justify-content:center;width:32px;height:32px;border:none;background:transparent;border-radius:4px;color:#495057;cursor:pointer;font-size:14px;font-weight:500;transition:all .15s ease;outline:none}.floating-toolbar-btn:hover{background:#f8f9fa;color:#212529}.floating-toolbar-btn:active{background:#e9ecef;transform:scale(.95)}.floating-toolbar-btn.floating-toolbar-toggle{color:#dc3545;font-weight:700}.floating-toolbar-btn.floating-toolbar-toggle:hover{background:#f8d7da;color:#721c24}.floating-toolbar-separator{width:1px;height:20px;background:#e1e5e9;margin:0 2px}@media(max-width:768px){.toolbar-container-wrapper .toolbar-button{padding:5px 8px;font-size:12px;min-height:28px}.toolbar-container-wrapper .toolbar-icon{width:16px;height:16px}.toolbar-container-wrapper .toolbar-dropdown-menu{min-width:140px}.toolbar-container-wrapper .toolbar-dropdown-item{padding:6px 10px;font-size:12px}.floating-toolbar{padding:4px;gap:2px}.floating-toolbar-btn{width:28px;height:28px;font-size:12px}}@media(max-width:480px){.toolbar-container-wrapper{padding:4px}.toolbar-container-wrapper .toolbar-wrapper{padding:4px;gap:2px}.toolbar-container-wrapper .toolbar-button{padding:4px 6px;font-size:11px;min-height:24px}.toolbar-container-wrapper .toolbar-icon{width:14px;height:14px}}.floating-toolbar{pointer-events:auto}.floating-toolbar{max-width:calc(100vw - 20px);overflow-x:auto}@media(prefers-color-scheme:dark){.floating-toolbar{background:#2d3748;border-color:#4a5568;color:#e2e8f0}.floating-toolbar-btn:hover{background:#4a5568;color:#f7fafc}.floating-toolbar-btn:active{background:#718096}.floating-toolbar-separator{background:#4a5568}}';let C;function se(){const l="editora-webcomponent-styles";if(!document.getElementById(l)){const e=document.createElement("style");e.id=l,e.textContent=re,document.head.appendChild(e)}}function le(){if(!C){const l=g.__globalPluginLoader;l?C=l:C=new H}return C}class g extends HTMLElement{constructor(){if(super(),this.pluginLoader=le(),this.config={},this.isInitialized=!1,this.keyboardShortcutManager=new T,this.lastAutosavedContent="",this.loadedPlugins=[],se(),!this.hasAttribute("data-initial-content")){const e=this.innerHTML.trim();e&&this.setAttribute("data-initial-content",e)}}static get observedAttributes(){return["height","width","menubar","plugins","toolbar","toolbar-items","toolbar-floating","toolbar-sticky","readonly","disabled","theme","placeholder","autofocus","autosave","autosave-enabled","autosave-interval-ms","autosave-storage-key","autosave-provider","autosave-api-url","accessibility","accessibility-enable-aria","accessibility-keyboard-navigation","accessibility-checker","performance","performance-debounce-input-ms","performance-viewport-only-scan","language","language-locale","language-direction","spellcheck","spellcheck-enabled","spellcheck-provider","context-menu","context-menu-enabled","paste","paste-clean","paste-keep-formatting","paste-convert-word","security","security-sanitize-on-paste","security-sanitize-on-input","statusbar"]}connectedCallback(){this.config=this.resolveConfig(),this.waitForPluginLoader().then(()=>{setTimeout(async()=>{await this.initialize()},0)})}async waitForPluginLoader(){if(g.__globalPluginLoader){this.pluginLoader=g.__globalPluginLoader;return}return new Promise(e=>{const t=()=>{g.__globalPluginLoader?(this.pluginLoader=g.__globalPluginLoader,e()):setTimeout(t,0)};t()})}disconnectedCallback(){this.destroy()}attributeChangedCallback(e,t,o){t!==o&&(this.config=this.resolveConfig(),this.handleAttributeChange(e,o))}async setConfig(e){this.jsConfig=e,this.config=this.resolveConfig(),this.isConnected&&(this.destroy(),await this.waitForPluginLoader(),await this.initialize())}async initialize(){var o;if(this.querySelector(".editora-toolbar")||this.isInitialized)return;this.setAttribute("data-editora-editor","true"),this.config.height&&(this.style.height=typeof this.config.height=="number"?`${this.config.height}px`:this.config.height),this.config.width&&(this.style.width=typeof this.config.width=="number"?`${this.config.width}px`:this.config.width),this.classList.add("editora-editor"),this.config.theme&&this.classList.add(`editora-theme-${this.config.theme}`);const e=await this.loadPlugins();this.loadedPlugins=e,e.forEach(i=>{if(i.init&&typeof i.init=="function")try{i.init({editorElement:this})}catch(n){console.error(`[RichTextEditor] Error initializing plugin ${i.name}:`,n)}});const t=(o=this.restoreAutosavedContent())!=null?o:this.getAttribute("data-initial-content")||"";this.engine=new k({content:t,plugins:e,readonly:this.config.readonly}),this.createUI(e,t),this.setupEventListeners(),this.startAutosave(),this.isInitialized=!0,this.dispatchEvent(new CustomEvent("editor-ready",{detail:{api:this.getAPI()},bubbles:!0}))}getInitialContent(){if(this.config.content)return this.config.content;const e=this.querySelector("[slot]");return e?e.innerHTML:this.hasChildNodes()?Array.from(this.childNodes).map(o=>o.nodeType===Node.TEXT_NODE?o.textContent:o.nodeType===Node.ELEMENT_NODE?o.outerHTML:"").join("").trim():""}async loadPlugins(){this.pluginLoader||await this.waitForPluginLoader();const e=[],t=this.config.plugins&&(typeof this.config.plugins=="string"&&this.config.plugins.length>0||Array.isArray(this.config.plugins)&&this.config.plugins.length>0),i=this.getAccessibilityConfig().checker===!0;if(t){if(typeof this.config.plugins=="string"){const n=this.config.plugins.split(/\s+/).filter(Boolean);i&&!n.includes("a11yChecker")&&n.push("a11yChecker");for(const a of n){const r=await this.pluginLoader.load(a,this.getPluginLoadConfig(a));r&&e.push(r)}}else if(Array.isArray(this.config.plugins)){for(const n of this.config.plugins)if(typeof n=="string"){const a=await this.pluginLoader.load(n,this.getPluginLoadConfig(n));a&&e.push(a)}else e.push(n);if(i&&!e.some(n=>(n==null?void 0:n.name)==="a11yChecker")){const n=await this.pluginLoader.load("a11yChecker",this.getPluginLoadConfig("a11yChecker"));n&&e.push(n)}}}else{const n=this.pluginLoader.getRegisteredPluginNames();for(const a of n){const r=await this.pluginLoader.load(a,this.getPluginLoadConfig(a));r&&e.push(r)}}return e}resolveToolbarItems(){const e=this.config.toolbarItems;if(typeof e=="string")return e;if(Array.isArray(e))return e.join(" ");const t=this.config.toolbar;if(typeof t=="string")return t;if(!t||typeof t!="object")return;const o=t.items;if(typeof o=="string")return o;if(Array.isArray(o))return o.join(" ")}isToolbarStickyEnabled(){const e=this.config.toolbar;return!e||typeof e!="object"?!1:!!e.sticky}isToolbarFloatingEnabled(){const e=this.config.toolbar;return!e||typeof e!="object"?!1:!!e.floating}isStatusbarEnabled(){const e=this.config.statusbar;return typeof e=="boolean"?e:e&&typeof e=="object"?e.enabled!==!1:!1}getStatusbarPosition(){const e=this.config.statusbar;return e&&typeof e=="object"&&e.position==="top"?"top":"bottom"}getLanguageConfig(){const e=this.config.language;return typeof e=="string"?{locale:e,direction:"ltr"}:e&&typeof e=="object"?{locale:e.locale||"en",direction:e.direction==="rtl"?"rtl":"ltr"}:{locale:"en",direction:"ltr"}}getAccessibilityConfig(){const e=this.config.accessibility;return typeof e=="boolean"?{enableARIA:e,keyboardNavigation:e,checker:!1}:e&&typeof e=="object"?{enableARIA:e.enableARIA!==!1,keyboardNavigation:e.keyboardNavigation!==!1,checker:!!e.checker}:{enableARIA:!0,keyboardNavigation:!0,checker:!1}}getPerformanceConfig(){var t;const e=this.config.performance;if(typeof e=="boolean")return{debounceInputMs:100,viewportOnlyScan:e};if(e&&typeof e=="object"){const o=Number((t=e.debounceInputMs)!=null?t:100);return{debounceInputMs:Number.isFinite(o)&&o>=0?o:100,viewportOnlyScan:e.viewportOnlyScan!==!1}}return{debounceInputMs:100,viewportOnlyScan:!0}}isEditorInViewport(){if(!this.contentElement||typeof window=="undefined")return!0;const e=this.contentElement.getBoundingClientRect();return e.bottom>=0&&e.top<=window.innerHeight}applyAccessibilitySettings(){if(!this.contentElement)return;const e=this.getAccessibilityConfig();if(e.enableARIA){this.contentElement.setAttribute("role","textbox"),this.contentElement.setAttribute("aria-multiline","true"),this.contentElement.setAttribute("aria-disabled",this.config.readonly?"true":"false");const t=typeof this.config.placeholder=="string"?this.config.placeholder.trim():"";t?this.contentElement.setAttribute("aria-label",t):this.contentElement.removeAttribute("aria-label")}else this.contentElement.removeAttribute("role"),this.contentElement.removeAttribute("aria-multiline"),this.contentElement.removeAttribute("aria-disabled"),this.contentElement.removeAttribute("aria-label");this.contentElement.tabIndex=e.keyboardNavigation?0:-1}applyLanguageSettings(){if(!this.contentElement)return;const e=this.getLanguageConfig();this.contentElement.setAttribute("lang",e.locale),this.contentElement.setAttribute("dir",e.direction)}getSpellcheckConfig(){const e=this.config.spellcheck;if(typeof e=="boolean")return{enabled:e,provider:"browser"};if(e&&typeof e=="object"){const t=e.provider||"browser";return{enabled:!!e.enabled,provider:t,mode:e.mode}}return{enabled:!1,provider:"browser"}}applySpellcheckSettings(){if(!this.contentElement)return;const e=this.getSpellcheckConfig(),t=e.enabled&&e.provider==="browser";this.contentElement.spellcheck=t,this.contentElement.setAttribute("spellcheck",t?"true":"false")}executeCommand(e,t){var n;typeof window!="undefined"&&(window.__editoraCommandEditorRoot=this);const o={editorElement:this,contentElement:this.contentElement,toolbarElement:this.toolbarElement},i=this.loadedPlugins.find(a=>a.commands&&a.commands[e]);if(i&&i.commands){const a=i.commands[e];if(typeof a=="function")try{return a(e==="toggleFullscreen"?this:t,o),!0}catch(r){return console.error(`[RichTextEditor] Error executing native command ${e}:`,r),!1}}return((n=this.engine)==null?void 0:n.execCommand(e,t))||!1}getPluginLoadConfig(e){const t=this.config.pluginConfig;if(t&&typeof t=="object"){const n=t[e];if(n&&typeof n=="object")return n}const o={spellCheck:["spellcheck","spellCheck"]},i=[e,e.toLowerCase(),...o[e]||[]];for(const n of i){const a=this.config[n];if(a&&typeof a=="object"&&!Array.isArray(a))return a}}getContentSanitizeConfig(){const e=this.config.contentConfig;return e&&typeof e=="object"?e:{sanitize:!0}}getSecurityConfig(){const e=this.config.security;return e&&typeof e=="object"?e:{sanitizeOnPaste:!0,sanitizeOnInput:!0}}getAutosaveConfig(){var t,o;const e=this.config.autosave;if(typeof e=="boolean")return{enabled:e,intervalMs:3e4,storageKey:"rte-autosave",provider:"localStorage"};if(e&&typeof e=="object"){const i=Number((o=(t=e.intervalMs)!=null?t:e.interval)!=null?o:3e4);return{enabled:!!e.enabled,intervalMs:Number.isFinite(i)&&i>0?i:3e4,storageKey:String(e.storageKey||"rte-autosave"),provider:e.provider||"localStorage",apiUrl:e.apiUrl}}return{enabled:!1,intervalMs:3e4,storageKey:"rte-autosave",provider:"localStorage"}}persistAutosave(e){const t=this.getAutosaveConfig();if(t.enabled&&e!==this.lastAutosavedContent){if(this.lastAutosavedContent=e,t.provider==="localStorage"){try{localStorage.setItem(t.storageKey,e),localStorage.setItem(`${t.storageKey}-timestamp`,Date.now().toString())}catch(o){console.error("[RichTextEditor] Failed to save autosave content to localStorage:",o)}return}t.provider==="api"&&t.apiUrl&&fetch(t.apiUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:e,timestamp:Date.now()})}).catch(o=>{console.error("[RichTextEditor] Failed to save autosave content to API:",o)})}}restoreAutosavedContent(){const e=this.getAutosaveConfig();if(!e.enabled||e.provider!=="localStorage")return null;try{const t=localStorage.getItem(e.storageKey);if(t)return this.lastAutosavedContent=t,t}catch(t){console.error("[RichTextEditor] Failed to restore autosaved content:",t)}return null}stopAutosave(){this.autosaveTimer&&(clearInterval(this.autosaveTimer),this.autosaveTimer=void 0)}startAutosave(){this.stopAutosave();const e=this.getAutosaveConfig();!e.enabled||!this.contentElement||(this.autosaveTimer=setInterval(()=>{var t;this.persistAutosave(((t=this.contentElement)==null?void 0:t.innerHTML)||"")},e.intervalMs))}insertHTMLAtSelection(e){if(!this.contentElement)return;const t=window.getSelection();if(t&&t.rangeCount>0){const o=t.getRangeAt(0);o.deleteContents();const i=document.createElement("div");i.innerHTML=e;const n=document.createDocumentFragment();for(;i.firstChild;)n.appendChild(i.firstChild);o.insertNode(n),o.collapse(!1),t.removeAllRanges(),t.addRange(o)}else this.contentElement.focus(),document.execCommand("insertHTML",!1,e)}createUI(e,t){const o=this.querySelector('[slot="toolbar"]'),i=this.querySelector('[slot="statusbar"]');this.innerHTML="",this.config.toolbar!==!1&&!o?(this.toolbarElement=document.createElement("div"),this.toolbarElement.className="editora-toolbar-container",this.appendChild(this.toolbarElement),this.toolbar=new x({items:this.resolveToolbarItems(),sticky:this.isToolbarStickyEnabled(),position:"top"},e,this.pluginLoader),this.toolbar.setCommandHandler((n,a)=>{var r;if(this.contentElement){this.contentElement.focus();const s=window.getSelection();if(!s||s.rangeCount===0||!this.contentElement.contains(s.anchorNode)){const c=document.createRange(),u=this.contentElement.lastChild||this.contentElement;u.nodeType===Node.TEXT_NODE?c.setStart(u,((r=u.textContent)==null?void 0:r.length)||0):u.nodeType===Node.ELEMENT_NODE?(c.selectNodeContents(u),c.collapse(!1)):c.setStart(this.contentElement,0),c.collapse(!0),s==null||s.removeAllRanges(),s==null||s.addRange(c)}}return this.executeCommand(n,a)}),this.toolbar.render(this.toolbarElement)):o&&this.appendChild(o),this.contentElement=document.createElement("div"),this.contentElement.className="editora-content rte-content",this.contentElement.contentEditable=this.config.readonly?"false":"true",this.applyLanguageSettings(),this.applyAccessibilitySettings(),this.applySpellcheckSettings(),this.config.placeholder&&this.contentElement.setAttribute("data-placeholder",this.config.placeholder);try{document.execCommand("defaultParagraphSeparator",!1,"p")}catch(n){console.warn("defaultParagraphSeparator not supported:",n)}if(t){const n=document.createElement("div");n.innerHTML=t.trim(),!Array.from(n.childNodes).some(r=>{if(r.nodeType===Node.ELEMENT_NODE){const s=r.tagName;return["P","DIV","H1","H2","H3","H4","H5","H6","UL","OL","BLOCKQUOTE","PRE"].includes(s)}return!1})&&t.trim()?this.contentElement.innerHTML=`<p>${t.trim()}</p>`:this.contentElement.innerHTML=t}else this.config.placeholder?this.contentElement.innerHTML="":this.contentElement.innerHTML="<p><br></p>";this.appendChild(this.contentElement),this.isToolbarFloatingEnabled()&&(this.floatingToolbar=new I({enabled:!0}),this.floatingToolbar.create(this)),i?this.appendChild(i):this.isStatusbarEnabled()&&(this.statusBarElement=document.createElement("div"),this.statusBarElement.className="editora-statusbar-container",this.appendChild(this.statusBarElement),this.statusBar=new D({position:this.getStatusbarPosition()}),this.statusBar.create(this.statusBarElement)),this.config.autofocus&&setTimeout(()=>{var n;return(n=this.contentElement)==null?void 0:n.focus()},0)}setupEventListeners(){if(!this.contentElement||!this.engine)return;const e=this.keyboardShortcutManager;this.contentElement.addEventListener("input",()=>{if(!this.contentElement)return;let o=this.contentElement.innerHTML;const i=this.getPerformanceConfig(),n=this.getContentSanitizeConfig(),a=this.getSecurityConfig();if(a.sanitizeOnInput!==!1&&n.sanitize!==!1){const s=ae(o,n,a);if(s!==o){const c=window.getSelection(),u=c&&c.rangeCount>0?c.getRangeAt(0):null;if(this.contentElement.innerHTML=s,u&&c)try{c.removeAllRanges(),c.addRange(u)}catch(f){}o=s}}this.contentChangeDebounceTimer&&clearTimeout(this.contentChangeDebounceTimer);const r=()=>{this.dispatchEvent(new CustomEvent("content-change",{detail:{html:o},bubbles:!0}))};i.debounceInputMs>0?this.contentChangeDebounceTimer=setTimeout(r,i.debounceInputMs):r(),this.updateStatusBar()}),this.contentElement.addEventListener("contextmenu",o=>{const i=this.config.contextMenu;(i===!1||typeof i=="object"&&i!==null&&i.enabled===!1)&&o.preventDefault()}),this.contentElement.addEventListener("paste",o=>{var u,f;o.preventDefault();const i=this.config.paste||{};let n=((u=o.clipboardData)==null?void 0:u.getData("text/html"))||"";const a=((f=o.clipboardData)==null?void 0:f.getData("text/plain"))||"",r=this.getContentSanitizeConfig(),s=this.getSecurityConfig(),c=!!n&&/class=["'][^"']*Mso|xmlns:w=|urn:schemas-microsoft-com:office/i.test(n);if((i.clean||!i.keepFormatting)&&a){document.execCommand("insertText",!1,a);return}if(i.convertWord===!1&&c&&a){document.execCommand("insertText",!1,a);return}if(n){s.sanitizeOnPaste!==!1&&r.sanitize!==!1&&(n=ne(n,r,s)),this.insertHTMLAtSelection(n);return}a&&document.execCommand("insertText",!1,a)}),this.contentElement.addEventListener("focus",()=>{this.dispatchEvent(new Event("editor-focus",{bubbles:!0})),this.updateStatusBar()}),this.contentElement.addEventListener("blur",()=>{this.contentChangeDebounceTimer&&(clearTimeout(this.contentChangeDebounceTimer),this.contentChangeDebounceTimer=void 0),this.contentElement&&this.dispatchEvent(new CustomEvent("content-change",{detail:{html:this.contentElement.innerHTML},bubbles:!0})),this.dispatchEvent(new Event("editor-blur",{bubbles:!0})),this.updateFloatingToolbar(),this.updateStatusBar()}),this.contentElement.addEventListener("keydown",o=>{this.getAccessibilityConfig().keyboardNavigation&&e.handleKeyDown(o,(n,a)=>{this.executeCommand(n,a)})});const t=()=>{const o=this.getSelectionRangeInEditor(),i=document.activeElement,n=!!i&&!!this.contentElement&&(i===this.contentElement||this.contentElement.contains(i));this.getPerformanceConfig().viewportOnlyScan&&!this.isEditorInViewport()&&!n||!o&&!n||(this.updateFloatingToolbar(),this.updateStatusBar())};this.selectionChangeHandler=t,document.addEventListener("selectionchange",this.selectionChangeHandler)}getSelectionRangeInEditor(){if(!this.contentElement)return null;const e=window.getSelection();if(!e||e.rangeCount===0)return null;const t=e.getRangeAt(0),o=t.commonAncestorContainer;return this.contentElement.contains(o)?t:null}isSelectionBackward(e){if(!e.anchorNode||!e.focusNode)return!1;try{const t=document.createRange();return t.setStart(e.anchorNode,e.anchorOffset),t.setEnd(e.focusNode,e.focusOffset),t.collapsed}catch(t){return!1}}getSelectionAnchorRect(e,t){const o=Array.from(t.getClientRects()).filter(n=>n.width>0||n.height>0);return o.length===0?t.getBoundingClientRect():this.isSelectionBackward(e)?o[0]:o[o.length-1]}updateFloatingToolbar(){if(!this.floatingToolbar)return;const e=this.getPerformanceConfig(),t=document.activeElement===this.contentElement||!!this.contentElement&&this.contentElement.contains(document.activeElement);if(e.viewportOnlyScan&&!this.isEditorInViewport()&&!t){this.floatingToolbar.hide();return}const o=this.getSelectionRangeInEditor();if(!o){this.floatingToolbar.hide();return}if(o.collapsed){this.floatingToolbar.hide();return}const i=window.getSelection();if(!i){this.floatingToolbar.hide();return}const n=this.getSelectionAnchorRect(i,o);if(!n){this.floatingToolbar.hide();return}this.floatingToolbar.show(n.left,n.top-40)}updateStatusBar(){if(!this.statusBar||!this.contentElement)return;const e=this.getPerformanceConfig(),t=document.activeElement===this.contentElement||this.contentElement.contains(document.activeElement);if(e.viewportOnlyScan&&!this.isEditorInViewport()&&!t)return;const o=this.contentElement.textContent||"",{words:i,chars:n}=N(o),a=j(this.contentElement);let r,s;const c=this.getSelectionRangeInEditor();c&&(r=P(this.contentElement,c),c.collapsed||(s=F(c,r),r=void 0)),this.statusBar.update({wordCount:i,charCount:n,lineCount:a,cursorPosition:r,selectionInfo:s})}handleAttributeChange(e,t){switch(e){case"readonly":this.contentElement&&(this.contentElement.contentEditable=t==="true"?"false":"true",this.applyAccessibilitySettings()),this.engine&&this.engine.setReadonly(t==="true");break;case"theme":this.classList.forEach(o=>{o.startsWith("editora-theme-")&&this.classList.remove(o)}),t&&this.classList.add(`editora-theme-${t}`);break;case"placeholder":this.contentElement&&(this.contentElement.setAttribute("data-placeholder",t),this.applyAccessibilitySettings());break;case"accessibility":case"accessibility-enable-aria":case"accessibility-keyboard-navigation":case"accessibility-checker":this.applyAccessibilitySettings();break;case"performance":case"performance-debounce-input-ms":case"performance-viewport-only-scan":break;case"language":case"language-locale":case"language-direction":this.applyLanguageSettings();break;case"spellcheck":case"spellcheck-enabled":case"spellcheck-provider":this.applySpellcheckSettings();break;case"autosave":case"autosave-enabled":case"autosave-interval-ms":case"autosave-storage-key":case"autosave-provider":case"autosave-api-url":this.startAutosave();break;case"security":case"security-sanitize-on-paste":case"security-sanitize-on-input":case"paste":case"paste-clean":case"paste-keep-formatting":case"paste-convert-word":case"context-menu":case"context-menu-enabled":break;case"toolbar":case"toolbar-items":case"toolbar-floating":case"toolbar-sticky":case"plugins":case"statusbar":this.isConnected&&(this.destroy(),this.waitForPluginLoader().then(()=>{this.initialize().catch(o=>{console.error("[RichTextEditor] Error during attribute change re-initialization:",o)})}));break}}resolveConfig(){const e={};for(let t=0;t<this.attributes.length;t++){const o=this.attributes[t];e[o.name]=o.value}return E.resolve({jsConfig:this.jsConfig,attributes:e})}getAPI(){return{getContent:()=>{var e;return((e=this.contentElement)==null?void 0:e.innerHTML)||""},setContent:e=>{this.contentElement&&(this.contentElement.innerHTML=e)},execCommand:(e,t)=>this.executeCommand(e,t),focus:()=>{var e;(e=this.contentElement)==null||e.focus()},blur:()=>{var e;(e=this.contentElement)==null||e.blur()},destroy:()=>{this.destroy()},on:(e,t)=>(this.addEventListener(e,t),()=>this.removeEventListener(e,t)),getConfig:()=>({...this.config}),setReadonly:e=>{this.setAttribute("readonly",e.toString())}}}destroy(){var e,t,o,i;this.contentChangeDebounceTimer&&(clearTimeout(this.contentChangeDebounceTimer),this.contentChangeDebounceTimer=void 0),this.contentElement&&this.persistAutosave(this.contentElement.innerHTML||""),this.stopAutosave(),this.selectionChangeHandler&&(document.removeEventListener("selectionchange",this.selectionChangeHandler),this.selectionChangeHandler=void 0),(e=this.engine)==null||e.destroy(),(t=this.toolbar)==null||t.destroy(),(o=this.floatingToolbar)==null||o.destroy(),(i=this.statusBar)==null||i.destroy(),this.innerHTML="",this.contentElement=void 0,this.toolbarElement=void 0,this.statusBarElement=void 0,this.loadedPlugins=[],this.isInitialized=!1,this.dispatchEvent(new Event("editor-destroy",{bubbles:!0}))}getContent(){var e;return((e=this.contentElement)==null?void 0:e.innerHTML)||""}setContent(e){this.contentElement&&(this.contentElement.innerHTML=e)}execCommand(e,t){return this.executeCommand(e,t)}focus(){var e;(e=this.contentElement)==null||e.focus()}blur(){var e;(e=this.contentElement)==null||e.blur()}}function ce(l){return new $(l)}function de(){typeof window!="undefined"&&!customElements.get("editora-editor")&&customElements.define("editora-editor",g)}return d.CharacterDialog=Q,d.ColorPicker=V,d.CommandRegistry=A,d.ConfigResolver=E,d.Dialog=b,d.DocumentModel=v,d.Dropdown=_,d.Editor=q,d.EditorEngine=k,d.EditorState=y,d.EmojiDialog=Z,d.FloatingToolbar=I,d.ImageDialog=Y,d.KeyboardShortcutManager=T,d.LinkDialog=G,d.MathDialog=J,d.MediaPlugin=K,d.PluginLoader=H,d.PluginManager=w,d.PluginRuntime=M,d.ReactAdapter=O,d.RichTextEditorElement=g,d.Schema=L,d.SpellcheckPlugin=W,d.StatusBar=D,d.TableDialog=X,d.ToolbarRenderer=x,d.VanillaAdapter=$,d.calculateTextStats=N,d.countLines=j,d.createEditor=ce,d.createPluginRuntime=U,d.createReactAdapter=ee,d.getCursorPosition=P,d.getSelectionInfo=F,d.getTextOffset=z,d.initWebComponent=de,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"}),d})({});
|
|
524
524
|
//# sourceMappingURL=editora.min.js.map
|