@editora/core 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
- (function(y,C){typeof exports=="object"&&typeof module!="undefined"?C(exports):typeof define=="function"&&define.amd?define(["exports"],C):(y=typeof globalThis!="undefined"?globalThis:y||self,C(y.EditoraCore={}))})(this,(function(y){"use strict";class C{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 n=await o();return t&&this.applyPluginConfig(n,t),this.loadedPlugins.set(e,n),n}async loadMultiple(e,t){return(await Promise.all(e.map(n=>this.load(n,t)))).filter(n=>n!==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 T{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 T(o,{anchor:0,head:0},e)}apply(e,t){return new T(e,t||this.selection,this.schema)}}class oe{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 ne{constructor(){this.plugins=[],this.pluginConfigs=new Map}register(e,t){if(this.plugins.push(e),t&&this.pluginConfigs.set(e.name,t),e.initialize){const o=this.pluginConfigs.get(e.name)||e.config;e.initialize(o)}}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 oe(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 n=this.getPlugin(e);if(!n)throw new Error(`Plugin not found: ${e}`);const i=this.getPluginConfig(e)||n.config||{},r=i.mode||"local";try{switch(r){case"local":return n.executeLocal?n.executeLocal(t,...o):null;case"api":if(!n.executeAPI)throw new Error(`Plugin ${e} does not support API mode`);return await n.executeAPI(t,...o);case"hybrid":if(n.executeHybrid)return await n.executeHybrid(t,...o);try{if(n.executeAPI)return await n.executeAPI(t,...o)}catch(a){if(console.warn(`API execution failed for ${e}, falling back to local`,a),n.executeLocal&&i.fallbackToLocal!==!1)return n.executeLocal(t,...o);throw a}break;default:throw new Error(`Unknown plugin mode: ${r}`)}}catch(a){throw console.error(`Error executing command ${t} on plugin ${e}:`,a),a}}async destroyAll(){const e=this.plugins.filter(t=>t.destroy).map(t=>t.destroy());await Promise.all(e),this.plugins=[],this.pluginConfigs.clear()}}class ie{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 re{constructor(e={}){this.listeners=new Map,this.isReadonly=!1,this.isDestroyed=!1,this.isReadonly=e.readonly||!1,this.pluginManager=new ne,e.plugins&&Array.isArray(e.plugins)&&e.plugins.forEach(o=>this.pluginManager.register(o));const t=this.pluginManager.buildSchema();this.state=T.create(t),this.commandRegistry=new ie(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 n;return t!==void 0?n=o(this.state,t):n=o(this.state),n?(this.setState(n),this.emit("change",this.state),!0):!1}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 n=o.indexOf(t);n>-1&&o.splice(n,1)}}}emit(e,...t){const o=this.listeners.get(e);o&&o.forEach(n=>{try{n(...t)}catch(i){console.error(`Error in ${e} handler:`,i)}})}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.listeners.clear(),this.emit("destroy"))}isEditorDestroyed(){return this.isDestroyed}}class se{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(a=>a.trim()),n=this.getAvailableToolbarItems(),i=new Map;n.forEach(a=>{a.command&&i.set(a.command,a),a.type==="group"&&a.label&&i.set(a.label,a)});const r={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(a=>{const l=[];a.split(/\s+/).filter(Boolean).forEach(d=>{if(d==="direction"){const g=i.get("setDirectionLTR"),m=i.get("setDirectionRTL");g&&l.push({id:"directionLTR",label:g.label,command:g.command,icon:g.icon,type:g.type||"button",options:g.options}),m&&l.push({id:"directionRTL",label:m.label,command:m.command,icon:m.icon,type:m.type||"button",options:m.options});return}if(d==="comments"){const g=i.get("addComment"),m=i.get("toggleComments");g&&l.push({id:"addComment",label:g.label,command:g.command,icon:g.icon,type:g.type||"button",options:g.options}),m&&l.push({id:"toggleComments",label:m.label,command:m.command,icon:m.icon,type:m.type||"button",options:m.options});return}const c=r[d]||d;let u=i.get(c);u||(u=i.get(d)),u&&l.push({id:d,label:u.label,command:u.command,icon:u.icon,type:u.type==="separator"?"separator":u.type||"button",options:u.options,items:u.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((n,i)=>{const r=document.createElement("div");if(r.className="editora-toolbar-group",n.forEach(a=>{this.appendToolbarButton(r,a)}),e.appendChild(r),i<o.length-1){const a=document.createElement("div");a.className="editora-toolbar-separator",e.appendChild(a)}})}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(n=>{this.appendToolbarButton(o,n)}),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||"",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&&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,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&&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 n=document.createElement("div");n.className="editora-toolbar-dropdown-menu",n.style.display="none",e.options&&e.options.forEach(r=>{const a=document.createElement("button");a.className="editora-toolbar-dropdown-item",a.type="button",a.textContent=r.label,a.setAttribute("data-value",r.value),a.addEventListener("click",l=>{l.preventDefault(),this.commandHandler&&this.commandHandler(e.command,r.value),n.style.display="none"}),n.appendChild(a)}),o.addEventListener("click",r=>{r.preventDefault(),r.stopPropagation();const a=n.style.display==="block";n.style.display=a?"none":"block"});const i=r=>{t.contains(r.target)||(n.style.display="none")};return document.addEventListener("click",i),t._cleanupDropdown=()=>{document.removeEventListener("click",i)},t.appendChild(o),t.appendChild(n),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 i=document.createElement("span");i.className="editora-toolbar-icon",i.innerHTML=e.icon,o.appendChild(i)}else o.innerHTML=e.icon;else o.textContent=e.label;const n=document.createElement("div");return n.className="editora-toolbar-dropdown-menu",n.style.display="none",e.options&&e.options.forEach(i=>{const r=document.createElement("button");r.className="editora-toolbar-dropdown-item",r.type="button",r.textContent=i.label,r.setAttribute("data-value",i.value),r.addEventListener("click",a=>{a.preventDefault(),a.stopPropagation(),this.commandHandler&&this.commandHandler(e.command,i.value),n.style.display="none"}),n.appendChild(r)}),o.addEventListener("click",i=>{var a;i.preventDefault(),i.stopPropagation();const r=(a=this.container)==null?void 0:a.querySelectorAll(".editora-toolbar-dropdown-menu");r==null||r.forEach(l=>{l!==n&&(l.style.display="none")}),n.style.display=n.style.display==="none"?"block":"none"}),document.addEventListener("click",i=>{t.contains(i.target)||(n.style.display="none")}),t.appendChild(o),t.appendChild(n),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 ae{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 le{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 i=this.statusInfo.selectionInfo;i.startLine===i.endLine&&i.startColumn===i.endColumn?o.push(`Ln ${i.startLine}, Col ${i.startColumn}`):(i.startLine===i.endLine?o.push(`Ln ${i.startLine}, Col ${i.startColumn}-${i.endColumn}`):o.push(`Ln ${i.startLine}:${i.startColumn} - ${i.endLine}:${i.endColumn}`),o.push(`${i.selectedChars} chars selected`))}else if(this.statusInfo.cursorPosition){const i=this.statusInfo.cursorPosition;o.push(`Ln ${i.line}, Col ${i.column}`)}this.statusInfo.language&&o.push(this.statusInfo.language);const n=[];this.statusInfo.wordCount!==void 0&&n.push(`${this.statusInfo.wordCount} words`),this.statusInfo.charCount!==void 0&&n.push(`${this.statusInfo.charCount} chars`),this.statusInfo.lineCount!==void 0&&n.push(`${this.statusInfo.lineCount} lines`),this.statusInfo.custom&&Object.entries(this.statusInfo.custom).forEach(([i,r])=>{n.push(`${i}: ${r}`)}),o.forEach((i,r)=>{const a=document.createElement("span");if(a.className="editora-statusbar-item",a.textContent=i,e.appendChild(a),r<o.length-1){const l=document.createElement("span");l.className="editora-statusbar-separator",l.textContent="|",e.appendChild(l)}}),n.forEach((i,r)=>{const a=document.createElement("span");if(a.className="editora-statusbar-item",a.textContent=i,t.appendChild(a),r<n.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}}function de(s,e){const t=s.textContent||"",o=ce(s,e.startContainer,e.startOffset),i=t.substring(0,o).split(`
2
- `),r=i.length,a=i[i.length-1].length+1;return{line:r,column:a}}function ce(s,e,t){var r;let o=0;const n=document.createTreeWalker(s,NodeFilter.SHOW_TEXT,null);let i=n.firstChild();for(;i;){if(i===e){o+=t;break}else i.nodeType===Node.TEXT_NODE&&(o+=((r=i.textContent)==null?void 0:r.length)||0);i=n.nextNode()}return o}function he(s){var o,n;const e=s.querySelectorAll("div, p, br, h1, h2, h3, h4, h5, h6, blockquote, li, pre");let t=1;if(e.length>0){t=e.length;const i=e[e.length-1];(i.tagName==="BR"||((o=i.innerHTML)==null?void 0:o.trim())===""||((n=i.textContent)==null?void 0:n.trim())==="")&&t++}else{const r=(s.textContent||"").split(`
3
- `).length;t=Math.max(1,r)}return t}function ue(s){const e=s.trim()?s.trim().split(/\s+/).length:0,t=s.length;return{words:e,chars:t}}function ge(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 j=class j{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),t}static parseAttributes(e){const t={};for(const[o,n]of Object.entries(e)){const i=this.kebabToCamel(o);t[i]=this.parseAttributeValue(n)}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[n,i]of Object.entries(o))i!=null&&(typeof i=="object"&&!Array.isArray(i)&&t[n]?t[n]=this.merge(t[n],i):t[n]=i);return t}};j.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,spellcheck:!1,language:"en"};let P=j;const pe='.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{background:#1e1e1e;color:#d4d4d4;border-color:#3c3c3c}.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:#252526;border-bottom-color:#3c3c3c}.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-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{color:#d4d4d4}.editora-toolbar-button:hover{background:#e0e0e0;border-color:#ccc}.editora-theme-dark .editora-toolbar-button:hover{background:#37373d;border-color:#555}.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:#2a2d2e;border-color:#666}.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:24px;height:24px;display:block}.editora-toolbar-separator{width:1px;height:24px;background:#ddd;margin:0 4px}.editora-theme-dark .editora-toolbar-separator{background:#3c3c3c}.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:#252526;border-color:#3c3c3c;box-shadow:0 2px 8px #00000080}.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:#d4d4d4}.editora-toolbar-dropdown-item:hover{background:#f5f5f5}.editora-theme-dark .editora-toolbar-dropdown-item:hover{background:#37373d}.editora-content{flex:1;min-height:200px;padding:16px;outline:none;overflow-y:auto;line-height:1.6}.editora-content:empty:before{content:attr(data-placeholder);color:#999;pointer-events:none}.editora-theme-dark .editora-content:empty:before{color:#6a6a6a}.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-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:#252526;border-color:#3c3c3c;box-shadow:0 2px 8px #00000080}.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:#252526;border-top-color:#3c3c3c;color:#9a9a9a}.editora-statusbar-item{white-space:nowrap}.editora-statusbar-separator{color:#ddd}.editora-theme-dark .editora-statusbar-separator{color:#3c3c3c}.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}}';function me(){const s="editora-webcomponent-styles";if(!document.getElementById(s)){const e=document.createElement("style");e.id=s,e.textContent=pe,document.head.appendChild(e)}}class b extends HTMLElement{constructor(){if(super(),this.config={},this.isInitialized=!1,me(),!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","readonly","disabled","theme","placeholder","autofocus","language","spellcheck","statusbar"]}connectedCallback(){this.config=this.resolveConfig(),this.waitForPluginLoader().then(()=>{setTimeout(async()=>{await this.initialize()},0)})}async waitForPluginLoader(){if(b.__globalPluginLoader){this.pluginLoader=b.__globalPluginLoader;return}return new Promise(e=>{const t=()=>{b.__globalPluginLoader?(this.pluginLoader=b.__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(){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();e.forEach(o=>{if(o.init&&typeof o.init=="function")try{o.init({editorElement:this})}catch(n){console.error(`[RichTextEditor] Error initializing plugin ${o.name}:`,n)}});const t=this.getAttribute("data-initial-content")||"";this.engine=new re({content:t,plugins:e,readonly:this.config.readonly}),this.createUI(e,t),this.setupEventListeners(),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=[];if(this.config.plugins&&(typeof this.config.plugins=="string"&&this.config.plugins.length>0||Array.isArray(this.config.plugins)&&this.config.plugins.length>0)){if(typeof this.config.plugins=="string"){const o=await this.pluginLoader.parsePluginString(this.config.plugins);e.push(...o)}else if(Array.isArray(this.config.plugins))for(const o of this.config.plugins)if(typeof o=="string"){const n=await this.pluginLoader.load(o);n&&e.push(n)}else e.push(o)}else{const o=this.pluginLoader.getRegisteredPluginNames(),n=await this.pluginLoader.loadMultiple(o);e.push(...n)}return e}createUI(e,t){const o=this.querySelector('[slot="toolbar"]'),n=this.querySelector('[slot="statusbar"]');if(this.innerHTML="",this.config.toolbar!==!1&&!o){this.toolbarElement=document.createElement("div"),this.toolbarElement.className="editora-toolbar-container",this.appendChild(this.toolbarElement);const i=this.config.toolbarItems||this.config.toolbar;this.toolbar=new se({items:typeof i=="string"?i:void 0,sticky:this.config.toolbar&&typeof this.config.toolbar=="object"?this.config.toolbar.sticky:!1,position:"top"},e,this.pluginLoader),this.toolbar.setCommandHandler((r,a)=>{var h,d;if(this.contentElement){this.contentElement.focus();const c=window.getSelection();if(!c||c.rangeCount===0||!this.contentElement.contains(c.anchorNode)){const u=document.createRange(),g=this.contentElement.lastChild||this.contentElement;g.nodeType===Node.TEXT_NODE?u.setStart(g,((h=g.textContent)==null?void 0:h.length)||0):g.nodeType===Node.ELEMENT_NODE?(u.selectNodeContents(g),u.collapse(!1)):u.setStart(this.contentElement,0),u.collapse(!0),c==null||c.removeAllRanges(),c==null||c.addRange(u)}}const l=e.find(c=>c.commands&&c.commands[r]);if(l&&l.commands){const c=l.commands[r];if(typeof c=="function")try{return c(r==="toggleFullscreen"?this:a)}catch(u){return console.error(`[RichTextEditor] Error executing native command ${r}:`,u),!1}}return((d=this.engine)==null?void 0:d.execCommand(r,a))||!1}),this.toolbar.render(this.toolbarElement)}else 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.contentElement.setAttribute("role","textbox"),this.contentElement.setAttribute("aria-multiline","true"),this.config.placeholder&&this.contentElement.setAttribute("data-placeholder",this.config.placeholder);try{document.execCommand("defaultParagraphSeparator",!1,"p")}catch(i){console.warn("defaultParagraphSeparator not supported:",i)}if(t){const i=document.createElement("div");i.innerHTML=t.trim(),!Array.from(i.childNodes).some(a=>{if(a.nodeType===Node.ELEMENT_NODE){const l=a.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.config.toolbar&&typeof this.config.toolbar=="object"&&this.config.toolbar.floating&&(this.floatingToolbar=new ae({enabled:!0}),this.floatingToolbar.create(this)),n?this.appendChild(n):this.config.statusbar&&(this.statusBarElement=document.createElement("div"),this.statusBarElement.className="editora-statusbar-container",this.appendChild(this.statusBarElement),this.statusBar=new le({position:"bottom"}),this.statusBar.create(this.statusBarElement)),this.config.autofocus&&setTimeout(()=>{var i;return(i=this.contentElement)==null?void 0:i.focus()},0)}setupEventListeners(){if(!this.contentElement||!this.engine)return;this.contentElement.addEventListener("input",()=>{const t=this.contentElement.innerHTML;this.dispatchEvent(new CustomEvent("content-change",{detail:{html:t},bubbles:!0})),this.updateStatusBar()}),this.contentElement.addEventListener("focus",()=>{this.dispatchEvent(new Event("editor-focus",{bubbles:!0}))}),this.contentElement.addEventListener("blur",()=>{this.dispatchEvent(new Event("editor-blur",{bubbles:!0}))});const e=()=>{this.updateFloatingToolbar(),this.updateStatusBar()};document.addEventListener("selectionchange",e)}updateFloatingToolbar(){if(!this.floatingToolbar)return;const e=window.getSelection();if(!e||e.rangeCount===0){this.floatingToolbar.hide();return}const t=e.getRangeAt(0);if(t.collapsed){this.floatingToolbar.hide();return}const o=t.getBoundingClientRect();this.floatingToolbar.show(o.left,o.top-40)}updateStatusBar(){if(!this.statusBar||!this.contentElement)return;const e=this.contentElement.textContent||"",{words:t,chars:o}=ue(e),n=he(this.contentElement),i=window.getSelection();let r,a;if(i&&i.rangeCount>0){const l=i.getRangeAt(0);r=de(this.contentElement,l),l.collapsed||(a=ge(l,r),r=void 0)}this.statusBar.update({wordCount:t,charCount:o,lineCount:n,cursorPosition:r,selectionInfo:a})}handleAttributeChange(e,t){switch(e){case"readonly":this.contentElement&&(this.contentElement.contentEditable=t==="true"?"false":"true"),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);break;case"toolbar":case"plugins":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 P.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)=>{var o;return((o=this.engine)==null?void 0:o.execCommand(e,t))||!1},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,n;(e=this.engine)==null||e.destroy(),(t=this.toolbar)==null||t.destroy(),(o=this.floatingToolbar)==null||o.destroy(),(n=this.statusBar)==null||n.destroy(),this.innerHTML="",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){var o;return((o=this.engine)==null?void 0:o.execCommand(e,t))||!1}focus(){var e;(e=this.contentElement)==null||e.focus()}blur(){var e;(e=this.contentElement)==null||e.blur()}}const I=new C;b.__globalPluginLoader=I;const fe={bold:()=>Promise.resolve().then(()=>be).then(s=>s.BoldPlugin()),italic:()=>Promise.resolve().then(()=>ye).then(s=>s.ItalicPlugin()),underline:()=>Promise.resolve().then(()=>ve).then(s=>s.UnderlinePlugin()),strikethrough:()=>Promise.resolve().then(()=>we).then(s=>s.StrikethroughPlugin()),clearFormatting:()=>Promise.resolve().then(()=>ke).then(s=>s.ClearFormattingPlugin()),heading:()=>Promise.resolve().then(()=>Ce).then(s=>s.HeadingPlugin()),blockquote:()=>Promise.resolve().then(()=>Ee).then(s=>s.BlockquotePlugin()),code:()=>Promise.resolve().then(()=>Re).then(s=>s.CodePlugin()),list:()=>Promise.resolve().then(()=>De).then(s=>s.ListPlugin()),history:()=>Promise.resolve().then(()=>Ue).then(s=>s.HistoryPlugin())};async function q(){return Object.entries(fe).forEach(([s,e])=>{I.register(s,e)}),I}typeof window!="undefined"&&q().then(s=>{b.__globalPluginLoader=s,customElements.get("editora-editor")||customElements.define("editora-editor",b);const e=document.querySelectorAll("editora-editor:not([data-initial-content])"),t=[];e.forEach(o=>{const n=o.innerHTML.trim();n&&(t.push(n),o.setAttribute("data-initial-content",n),o.innerHTML="")}),e.forEach((o,n)=>{o instanceof b&&!o.isInitialized&&t[n]&&o.setAttribute("content",t[n])})});const be=Object.freeze(Object.defineProperty({__proto__:null,BoldPlugin:()=>({name:"bold",marks:{bold:{parseDOM:[{tag:"strong"},{tag:"b"},{style:"font-weight",getAttrs:s=>{const e=typeof s=="string"?s:s.style.fontWeight;return/^(bold(er)?|[5-9]\d{2,})$/.test(e)&&null}}],toDOM:()=>["strong",0]}},toolbar:[{label:"Bold",command:"toggleBold",icon:'<svg width="24" height="24" focusable="false"><path d="M7.8 19c-.3 0-.5 0-.6-.2l-.2-.5V5.7c0-.2 0-.4.2-.5l.6-.2h5c1.5 0 2.7.3 3.5 1 .7.6 1.1 1.4 1.1 2.5a3 3 0 0 1-.6 1.9c-.4.6-1 1-1.6 1.2.4.1.9.3 1.3.6s.8.7 1 1.2c.4.4.5 1 .5 1.6 0 1.3-.4 2.3-1.3 3-.8.7-2.1 1-3.8 1H7.8Zm5-8.3c.6 0 1.2-.1 1.6-.5.4-.3.6-.7.6-1.3 0-1.1-.8-1.7-2.3-1.7H9.3v3.5h3.4Zm.5 6c.7 0 1.3-.1 1.7-.4.4-.4.6-.9.6-1.5s-.2-1-.7-1.4c-.4-.3-1-.4-2-.4H9.4v3.8h4Z" fill-rule="evenodd"></path></svg>',shortcut:"Mod-b"}],commands:{toggleBold:()=>(document.execCommand("bold",!1),!0)},keymap:{"Mod-b":"toggleBold","Mod-B":"toggleBold"}})},Symbol.toStringTag,{value:"Module"})),H=()=>(document.execCommand("italic",!1),!0),xe=(s,e)=>{var t;typeof window!="undefined"&&((t=window.registerEditorCommand)==null||t.call(window,s,e))},K=()=>{xe("toggleItalic",H)};typeof window!="undefined"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",K):K());const ye=Object.freeze(Object.defineProperty({__proto__:null,ItalicPlugin:()=>({name:"italic",marks:{italic:{parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style=italic"}],toDOM:()=>["em",0]}},toolbar:[{label:"Italic",command:"toggleItalic",type:"button",icon:'<svg width="24" height="24" focusable="false"><path d="M16.7 4.7l-.1.9h-.3c-.6 0-1 0-1.4.3-.3.3-.4.6-.5 1.1l-2.1 9.8v.6c0 .5.4.8 1.4.8h.2l-.2.8H8l.2-.8h.2c1.1 0 1.8-.5 2-1.5l2-9.8.1-.5c0-.6-.4-.8-1.4-.8h-.3l.2-.9h5.8Z" fill-rule="evenodd"></path></svg>',shortcut:"Mod-i"}],commands:{toggleItalic:H},keymap:{"Mod-i":"toggleItalic","Mod-I":"toggleItalic"}}),toggleItalic:H},Symbol.toStringTag,{value:"Module"})),ve=Object.freeze(Object.defineProperty({__proto__:null,UnderlinePlugin:()=>({name:"underline",marks:{underline:{parseDOM:[{tag:"u"}],toDOM:()=>["u",{},0]}},toolbar:[{label:"Underline",command:"toggleUnderline",icon:'<svg width="24" height="24" focusable="false"><path d="M16 5c.6 0 1 .4 1 1v7c0 2.8-2.2 5-5 5s-5-2.2-5-5V6c0-.6.4-1 1-1s1 .4 1 1v7c0 1.7 1.3 3 3 3s3-1.3 3-3V6c0-.6.4-1 1-1ZM4 17h16c.6 0 1 .4 1 1s-.4 1-1 1H4a1 1 0 1 1 0-2Z" fill-rule="evenodd"></path></svg>',shortcut:"Mod-u"}],commands:{toggleUnderline:()=>(document.execCommand("underline",!1),!0)},keymap:{"Mod-u":"toggleUnderline","Mod-U":"toggleUnderline"}})},Symbol.toStringTag,{value:"Module"})),we=Object.freeze(Object.defineProperty({__proto__:null,StrikethroughPlugin:()=>({name:"strikethrough",marks:{strikethrough:{parseDOM:[{tag:"s"},{tag:"strike"},{tag:"del"},{style:"text-decoration",getAttrs:s=>(typeof s=="string"?s:s.style.textDecoration)==="line-through"&&null}],toDOM:()=>["s",0]}},toolbar:[{label:"Strikethrough",command:"toggleStrikethrough",icon:'<svg width="24" height="24" focusable="false"><g fill-rule="evenodd"><path d="M15.6 8.5c-.5-.7-1-1.1-1.3-1.3-.6-.4-1.3-.6-2-.6-2.7 0-2.8 1.7-2.8 2.1 0 1.6 1.8 2 3.2 2.3 4.4.9 4.6 2.8 4.6 3.9 0 1.4-.7 4.1-5 4.1A6.2 6.2 0 0 1 7 16.4l1.5-1.1c.4.6 1.6 2 3.7 2 1.6 0 2.5-.4 3-1.2.4-.8.3-2-.8-2.6-.7-.4-1.6-.7-2.9-1-1-.2-3.9-.8-3.9-3.6C7.6 6 10.3 5 12.4 5c2.9 0 4.2 1.6 4.7 2.4l-1.5 1.1Z"></path><path d="M5 11h14a1 1 0 0 1 0 2H5a1 1 0 0 1 0-2Z" fill-rule="nonzero"></path></g></svg>',shortcut:"Mod-Shift-x"}],commands:{toggleStrikethrough:()=>(document.execCommand("strikeThrough",!1),!0)},keymap:{"Mod-Shift-x":"toggleStrikethrough","Mod-Shift-X":"toggleStrikethrough"}})},Symbol.toStringTag,{value:"Module"})),ke=Object.freeze(Object.defineProperty({__proto__:null,ClearFormattingPlugin:()=>({name:"clearFormatting",toolbar:[{label:"Clear Formatting",command:"clearFormatting",icon:'<svg width="24" height="24" focusable="false"><path d="M13.2 6a1 1 0 0 1 0 .2l-2.6 10a1 1 0 0 1-1 .8h-.2a.8.8 0 0 1-.8-1l2.6-10H8a1 1 0 1 1 0-2h9a1 1 0 0 1 0 2h-3.8ZM5 18h7a1 1 0 0 1 0 2H5a1 1 0 0 1 0-2Zm13 1.5L16.5 18 15 19.5a.7.7 0 0 1-1-1l1.5-1.5-1.5-1.5a.7.7 0 0 1 1-1l1.5 1.5 1.5-1.5a.7.7 0 0 1 1 1L17.5 17l1.5 1.5a.7.7 0 0 1-1 1Z" fill-rule="evenodd"></path></svg>',shortcut:"Mod-\\"}],commands:{clearFormatting:()=>(document.execCommand("removeFormat",!1),!0)},keymap:{"Mod-\\":"clearFormatting"}})},Symbol.toStringTag,{value:"Module"})),Ce=Object.freeze(Object.defineProperty({__proto__:null,HeadingPlugin:()=>{const s=e=>{try{return document.execCommand("formatBlock",!1,e),!0}catch(t){return console.error(`Failed to set block type to ${e}:`,t),!1}};return{name:"heading",toolbar:[{label:"Heading",command:"setBlockType",type:"dropdown",options:[{value:"p",label:"Paragraph"},{value:"h1",label:"Heading 1"},{value:"h2",label:"Heading 2"},{value:"h3",label:"Heading 3"},{value:"h4",label:"Heading 4"},{value:"h5",label:"Heading 5"},{value:"h6",label:"Heading 6"}],icon:'<svg width="24" height="24" focusable="false"><path d="M16.1 8.6 14.2 4l-1.4.5 2.8 7.4c.1.4.5.6.9.6h.1c.4-.1.6-.5.6-.9l1.8-4.8-1.4-.5-1.5 2.3ZM4 11.5h6V10H4v1.5ZM18.5 3v1L17 7l.9.9L20.7 3h-2.2ZM5.5 12h1v7h1v-7h1v-.5h-3V12Zm4 0h1v7h1v-7h1v-.5h-3V12Zm10 1.5a2 2 0 0 0-2-2h-1v7.5h1v-2.7h1a2 2 0 0 0 2-2v-.8Zm-2 1.3h-1v-2.3h1a.8.8 0 1 1 0 1.6v.7Z" fill-rule="evenodd"></path></svg>'}],commands:{setBlockType:e=>e?s(e):!1,setHeading1:()=>s("h1"),setHeading2:()=>s("h2"),setHeading3:()=>s("h3"),setParagraph:()=>s("p")},keymap:{"Mod-Alt-1":"setHeading1","Mod-Alt-2":"setHeading2","Mod-Alt-3":"setHeading3","Mod-Alt-0":"setParagraph"}}}},Symbol.toStringTag,{value:"Module"})),Ee=Object.freeze(Object.defineProperty({__proto__:null,BlockquotePlugin:()=>({name:"blockquote",nodes:{blockquote:{content:"block+",group:"block",parseDOM:[{tag:"blockquote"}],toDOM:()=>["blockquote",0]}},toolbar:[{label:"Quote",command:"toggleBlockquote",icon:'<svg fill="#000000" height="24px" width="24px" version="1.1" id="Icons" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 32 32" xml:space="preserve"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <g> <path d="M13,11c0.6,0,1-0.4,1-1s-0.4-1-1-1c-5,0-9,4-9,9c0,2.8,2.2,5,5,5s5-2.2,5-5s-2.2-5-5-5c-0.3,0-0.7,0-1,0.1 C9.3,11.8,11,11,13,11z"></path> <path d="M23,13c-0.3,0-0.7,0-1,0.1c1.3-1.3,3-2.1,5-2.1c0.6,0,1-0.4,1-1s-0.4-1-1-1c-5,0-9,4-9,9c0,2.8,2.2,5,5,5s5-2.2,5-5 S25.8,13,23,13z"></path> </g> </g></svg>',shortcut:"Mod-Shift-9"}],commands:{toggleBlockquote:()=>{const s=window.getSelection();if(!s||s.rangeCount===0)return!1;let e=s.anchorNode,t=!1;for(;e&&e!==document.body;){if(e.nodeName==="BLOCKQUOTE"){t=!0;break}e=e.parentNode}return t?document.execCommand("formatBlock",!1,"p"):document.execCommand("formatBlock",!1,"blockquote"),!0}},keymap:{"Mod-Shift-9":"toggleBlockquote"}})},Symbol.toStringTag,{value:"Module"}));class O{constructor(e=""){this._lines=[],this._version=0,this.setText(e)}getLine(e){return this._lines[e]||""}getLines(){return[...this._lines]}getLineCount(){return this._lines.length}getText(){return this._lines.join(`
1
+ (function(E,S){typeof exports=="object"&&typeof module!="undefined"?S(exports):typeof define=="function"&&define.amd?define(["exports"],S):(E=typeof globalThis!="undefined"?globalThis:E||self,S(E.EditoraCore={}))})(this,(function(E){"use strict";class S{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 B{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 B(o,{anchor:0,head:0},e)}apply(e,t){return new B(e,t||this.selection,this.schema)}}class ae{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 le{constructor(){this.plugins=[],this.pluginConfigs=new Map}register(e,t){if(this.plugins.push(e),t&&this.pluginConfigs.set(e.name,t),e.initialize){const o=this.pluginConfigs.get(e.name)||e.config;e.initialize(o)}}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 ae(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||{},r=n.mode||"local";try{switch(r){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(s){if(console.warn(`API execution failed for ${e}, falling back to local`,s),i.executeLocal&&n.fallbackToLocal!==!1)return i.executeLocal(t,...o);throw s}break;default:throw new Error(`Unknown plugin mode: ${r}`)}}catch(s){throw console.error(`Error executing command ${t} on plugin ${e}:`,s),s}}async destroyAll(){const e=this.plugins.filter(t=>t.destroy).map(t=>t.destroy());await Promise.all(e),this.plugins=[],this.pluginConfigs.clear()}}class de{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 ce{constructor(e={}){this.listeners=new Map,this.isReadonly=!1,this.isDestroyed=!1,this.isReadonly=e.readonly||!1,this.pluginManager=new le,e.plugins&&Array.isArray(e.plugins)&&e.plugins.forEach(o=>this.pluginManager.register(o));const t=this.pluginManager.buildSchema();this.state=B.create(t),this.commandRegistry=new de(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?(this.setState(i),this.emit("change",this.state),!0):!1}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 he{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(s=>s.trim()),i=this.getAvailableToolbarItems(),n=new Map;i.forEach(s=>{s.command&&n.set(s.command,s),s.type==="group"&&s.label&&n.set(s.label,s)});const r={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(s=>{const a=[];s.split(/\s+/).filter(Boolean).forEach(d=>{if(d==="direction"){const g=n.get("setDirectionLTR"),p=n.get("setDirectionRTL");g&&a.push({id:"directionLTR",label:g.label,command:g.command,icon:g.icon,type:g.type||"button",options:g.options}),p&&a.push({id:"directionRTL",label:p.label,command:p.command,icon:p.icon,type:p.type||"button",options:p.options});return}if(d==="comments"){const g=n.get("addComment"),p=n.get("toggleComments");g&&a.push({id:"addComment",label:g.label,command:g.command,icon:g.icon,type:g.type||"button",options:g.options}),p&&a.push({id:"toggleComments",label:p.label,command:p.command,icon:p.icon,type:p.type||"button",options:p.options});return}const h=r[d]||d;let u=n.get(h);u||(u=n.get(d)),u&&a.push({id:d,label:u.label,command:u.command,icon:u.icon,type:u.type==="separator"?"separator":u.type||"button",options:u.options,items:u.items})}),a.length>0&&t.push(a)}),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 r=document.createElement("div");if(r.className="editora-toolbar-group",i.forEach(s=>{this.appendToolbarButton(r,s)}),e.appendChild(r),n<o.length-1){const s=document.createElement("div");s.className="editora-toolbar-separator",e.appendChild(s)}})}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||"",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&&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,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&&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",a=>{a.preventDefault(),this.commandHandler&&this.commandHandler(e.command,r.value),i.style.display="none"}),i.appendChild(s)}),o.addEventListener("click",r=>{r.preventDefault(),r.stopPropagation();const s=i.style.display==="block";i.style.display=s?"none":"block"});const n=r=>{t.contains(r.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 r=document.createElement("button");r.className="editora-toolbar-dropdown-item",r.type="button",r.textContent=n.label,r.setAttribute("data-value",n.value),r.addEventListener("click",s=>{s.preventDefault(),s.stopPropagation(),this.commandHandler&&this.commandHandler(e.command,n.value),i.style.display="none"}),i.appendChild(r)}),o.addEventListener("click",n=>{var s;n.preventDefault(),n.stopPropagation();const r=(s=this.container)==null?void 0:s.querySelectorAll(".editora-toolbar-dropdown-menu");r==null||r.forEach(a=>{a!==i&&(a.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 ue{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 ge{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,r])=>{i.push(`${n}: ${r}`)}),o.forEach((n,r)=>{const s=document.createElement("span");if(s.className="editora-statusbar-item",s.textContent=n,e.appendChild(s),r<o.length-1){const a=document.createElement("span");a.className="editora-statusbar-separator",a.textContent="|",e.appendChild(a)}}),i.forEach((n,r)=>{const s=document.createElement("span");if(s.className="editora-statusbar-item",s.textContent=n,t.appendChild(s),r<i.length-1){const a=document.createElement("span");a.className="editora-statusbar-separator",a.textContent="|",t.appendChild(a)}}),this.container.appendChild(e),this.container.appendChild(t)}destroy(){this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container),this.container=void 0}}function pe(l,e){const t=l.textContent||"",o=fe(l,e.startContainer,e.startOffset),n=t.substring(0,o).split(`
2
+ `),r=n.length,s=n[n.length-1].length+1;return{line:r,column:s}}function fe(l,e,t){var r;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+=((r=n.textContent)==null?void 0:r.length)||0);n=i.nextNode()}return o}function me(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 r=(l.textContent||"").split(`
3
+ `).length;t=Math.max(1,r)}return t}function be(l){const e=l.trim()?l.trim().split(/\s+/).length:0,t=l.length;return{words:e,chars:t}}function xe(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 J=class J{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),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}};J.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,spellcheck:!1,language:"en"};let _=J;const ye='.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{background:#1e1e1e;color:#d4d4d4;border-color:#3c3c3c}.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:#252526;border-bottom-color:#3c3c3c}.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-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{color:#d4d4d4}.editora-toolbar-button:hover{background:#e0e0e0;border-color:#ccc}.editora-theme-dark .editora-toolbar-button:hover{background:#37373d;border-color:#555}.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:#2a2d2e;border-color:#666}.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:24px;height:24px;display:block}.editora-toolbar-separator{width:1px;height:24px;background:#ddd;margin:0 4px}.editora-theme-dark .editora-toolbar-separator{background:#3c3c3c}.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:#252526;border-color:#3c3c3c;box-shadow:0 2px 8px #00000080}.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:#d4d4d4}.editora-toolbar-dropdown-item:hover{background:#f5f5f5}.editora-theme-dark .editora-toolbar-dropdown-item:hover{background:#37373d}.editora-content{flex:1;min-height:200px;padding:16px;outline:none;overflow-y:auto;line-height:1.6}.editora-content:empty:before{content:attr(data-placeholder);color:#999;pointer-events:none}.editora-theme-dark .editora-content:empty:before{color:#6a6a6a}.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-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:#252526;border-color:#3c3c3c;box-shadow:0 2px 8px #00000080}.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:#252526;border-top-color:#3c3c3c;color:#9a9a9a}.editora-statusbar-item{white-space:nowrap}.editora-statusbar-separator{color:#ddd}.editora-theme-dark .editora-statusbar-separator{color:#3c3c3c}.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}}';function ve(){const l="editora-webcomponent-styles";if(!document.getElementById(l)){const e=document.createElement("style");e.id=l,e.textContent=ye,document.head.appendChild(e)}}class M extends HTMLElement{constructor(){if(super(),this.config={},this.isInitialized=!1,ve(),!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","readonly","disabled","theme","placeholder","autofocus","language","spellcheck","statusbar"]}connectedCallback(){this.config=this.resolveConfig(),this.waitForPluginLoader().then(()=>{setTimeout(async()=>{await this.initialize()},0)})}async waitForPluginLoader(){if(M.__globalPluginLoader){this.pluginLoader=M.__globalPluginLoader;return}return new Promise(e=>{const t=()=>{M.__globalPluginLoader?(this.pluginLoader=M.__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(){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();e.forEach(o=>{if(o.init&&typeof o.init=="function")try{o.init({editorElement:this})}catch(i){console.error(`[RichTextEditor] Error initializing plugin ${o.name}:`,i)}});const t=this.getAttribute("data-initial-content")||"";this.engine=new ce({content:t,plugins:e,readonly:this.config.readonly}),this.createUI(e,t),this.setupEventListeners(),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=[];if(this.config.plugins&&(typeof this.config.plugins=="string"&&this.config.plugins.length>0||Array.isArray(this.config.plugins)&&this.config.plugins.length>0)){if(typeof this.config.plugins=="string"){const o=await this.pluginLoader.parsePluginString(this.config.plugins);e.push(...o)}else if(Array.isArray(this.config.plugins))for(const o of this.config.plugins)if(typeof o=="string"){const i=await this.pluginLoader.load(o);i&&e.push(i)}else e.push(o)}else{const o=this.pluginLoader.getRegisteredPluginNames(),i=await this.pluginLoader.loadMultiple(o);e.push(...i)}return e}createUI(e,t){const o=this.querySelector('[slot="toolbar"]'),i=this.querySelector('[slot="statusbar"]');if(this.innerHTML="",this.config.toolbar!==!1&&!o){this.toolbarElement=document.createElement("div"),this.toolbarElement.className="editora-toolbar-container",this.appendChild(this.toolbarElement);const n=this.config.toolbarItems||this.config.toolbar;this.toolbar=new he({items:typeof n=="string"?n:void 0,sticky:this.config.toolbar&&typeof this.config.toolbar=="object"?this.config.toolbar.sticky:!1,position:"top"},e,this.pluginLoader),this.toolbar.setCommandHandler((r,s)=>{var c,d;if(this.contentElement){this.contentElement.focus();const h=window.getSelection();if(!h||h.rangeCount===0||!this.contentElement.contains(h.anchorNode)){const u=document.createRange(),g=this.contentElement.lastChild||this.contentElement;g.nodeType===Node.TEXT_NODE?u.setStart(g,((c=g.textContent)==null?void 0:c.length)||0):g.nodeType===Node.ELEMENT_NODE?(u.selectNodeContents(g),u.collapse(!1)):u.setStart(this.contentElement,0),u.collapse(!0),h==null||h.removeAllRanges(),h==null||h.addRange(u)}}const a=e.find(h=>h.commands&&h.commands[r]);if(a&&a.commands){const h=a.commands[r];if(typeof h=="function")try{return h(r==="toggleFullscreen"?this:s)}catch(u){return console.error(`[RichTextEditor] Error executing native command ${r}:`,u),!1}}return((d=this.engine)==null?void 0:d.execCommand(r,s))||!1}),this.toolbar.render(this.toolbarElement)}else 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.contentElement.setAttribute("role","textbox"),this.contentElement.setAttribute("aria-multiline","true"),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(s=>{if(s.nodeType===Node.ELEMENT_NODE){const a=s.tagName;return["P","DIV","H1","H2","H3","H4","H5","H6","UL","OL","BLOCKQUOTE","PRE"].includes(a)}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.config.toolbar&&typeof this.config.toolbar=="object"&&this.config.toolbar.floating&&(this.floatingToolbar=new ue({enabled:!0}),this.floatingToolbar.create(this)),i?this.appendChild(i):this.config.statusbar&&(this.statusBarElement=document.createElement("div"),this.statusBarElement.className="editora-statusbar-container",this.appendChild(this.statusBarElement),this.statusBar=new ge({position:"bottom"}),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;this.contentElement.addEventListener("input",()=>{const t=this.contentElement.innerHTML;this.dispatchEvent(new CustomEvent("content-change",{detail:{html:t},bubbles:!0})),this.updateStatusBar()}),this.contentElement.addEventListener("focus",()=>{this.dispatchEvent(new Event("editor-focus",{bubbles:!0}))}),this.contentElement.addEventListener("blur",()=>{this.dispatchEvent(new Event("editor-blur",{bubbles:!0}))});const e=()=>{this.updateFloatingToolbar(),this.updateStatusBar()};document.addEventListener("selectionchange",e)}updateFloatingToolbar(){if(!this.floatingToolbar)return;const e=window.getSelection();if(!e||e.rangeCount===0){this.floatingToolbar.hide();return}const t=e.getRangeAt(0);if(t.collapsed){this.floatingToolbar.hide();return}const o=t.getBoundingClientRect();this.floatingToolbar.show(o.left,o.top-40)}updateStatusBar(){if(!this.statusBar||!this.contentElement)return;const e=this.contentElement.textContent||"",{words:t,chars:o}=be(e),i=me(this.contentElement),n=window.getSelection();let r,s;if(n&&n.rangeCount>0){const a=n.getRangeAt(0);r=pe(this.contentElement,a),a.collapsed||(s=xe(a,r),r=void 0)}this.statusBar.update({wordCount:t,charCount:o,lineCount:i,cursorPosition:r,selectionInfo:s})}handleAttributeChange(e,t){switch(e){case"readonly":this.contentElement&&(this.contentElement.contentEditable=t==="true"?"false":"true"),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);break;case"toolbar":case"plugins":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 _.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)=>{var o;return((o=this.engine)==null?void 0:o.execCommand(e,t))||!1},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;(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.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){var o;return((o=this.engine)==null?void 0:o.execCommand(e,t))||!1}focus(){var e;(e=this.contentElement)==null||e.focus()}blur(){var e;(e=this.contentElement)==null||e.blur()}}const D=new S;M.__globalPluginLoader=D;const we={bold:()=>Promise.resolve().then(()=>ke).then(l=>l.BoldPlugin()),italic:()=>Promise.resolve().then(()=>Me).then(l=>l.ItalicPlugin()),underline:()=>Promise.resolve().then(()=>Te).then(l=>l.UnderlinePlugin()),strikethrough:()=>Promise.resolve().then(()=>Ee).then(l=>l.StrikethroughPlugin()),clearFormatting:()=>Promise.resolve().then(()=>Le).then(l=>l.ClearFormattingPlugin()),heading:()=>Promise.resolve().then(()=>Se).then(l=>l.HeadingPlugin()),blockquote:()=>Promise.resolve().then(()=>Pe).then(l=>l.BlockquotePlugin()),code:()=>Promise.resolve().then(()=>Fe).then(l=>l.CodePlugin()),list:()=>Promise.resolve().then(()=>Ve).then(l=>l.ListPlugin()),history:()=>Promise.resolve().then(()=>Ke).then(l=>l.HistoryPlugin())};async function ee(){return Object.entries(we).forEach(([l,e])=>{D.register(l,e)}),D}typeof window!="undefined"&&ee().then(l=>{M.__globalPluginLoader=l,customElements.get("editora-editor")||customElements.define("editora-editor",M);const e=document.querySelectorAll("editora-editor:not([data-initial-content])"),t=[];e.forEach(o=>{const i=o.innerHTML.trim();i&&(t.push(i),o.setAttribute("data-initial-content",i),o.innerHTML="")}),e.forEach((o,i)=>{o instanceof M&&!o.isInitialized&&t[i]&&o.setAttribute("content",t[i])})});const ke=Object.freeze(Object.defineProperty({__proto__:null,BoldPlugin:()=>({name:"bold",marks:{bold:{parseDOM:[{tag:"strong"},{tag:"b"},{style:"font-weight",getAttrs:l=>{const e=typeof l=="string"?l:l.style.fontWeight;return/^(bold(er)?|[5-9]\d{2,})$/.test(e)&&null}}],toDOM:()=>["strong",0]}},toolbar:[{label:"Bold",command:"toggleBold",icon:'<svg width="24" height="24" focusable="false"><path d="M7.8 19c-.3 0-.5 0-.6-.2l-.2-.5V5.7c0-.2 0-.4.2-.5l.6-.2h5c1.5 0 2.7.3 3.5 1 .7.6 1.1 1.4 1.1 2.5a3 3 0 0 1-.6 1.9c-.4.6-1 1-1.6 1.2.4.1.9.3 1.3.6s.8.7 1 1.2c.4.4.5 1 .5 1.6 0 1.3-.4 2.3-1.3 3-.8.7-2.1 1-3.8 1H7.8Zm5-8.3c.6 0 1.2-.1 1.6-.5.4-.3.6-.7.6-1.3 0-1.1-.8-1.7-2.3-1.7H9.3v3.5h3.4Zm.5 6c.7 0 1.3-.1 1.7-.4.4-.4.6-.9.6-1.5s-.2-1-.7-1.4c-.4-.3-1-.4-2-.4H9.4v3.8h4Z" fill-rule="evenodd"></path></svg>',shortcut:"Mod-b"}],commands:{toggleBold:()=>(document.execCommand("bold",!1),!0)},keymap:{"Mod-b":"toggleBold","Mod-B":"toggleBold"}})},Symbol.toStringTag,{value:"Module"})),U=()=>(document.execCommand("italic",!1),!0),Ce=(l,e)=>{var t;typeof window!="undefined"&&((t=window.registerEditorCommand)==null||t.call(window,l,e))},te=()=>{Ce("toggleItalic",U)};typeof window!="undefined"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",te):te());const Me=Object.freeze(Object.defineProperty({__proto__:null,ItalicPlugin:()=>({name:"italic",marks:{italic:{parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style=italic"}],toDOM:()=>["em",0]}},toolbar:[{label:"Italic",command:"toggleItalic",type:"button",icon:'<svg width="24" height="24" focusable="false"><path d="M16.7 4.7l-.1.9h-.3c-.6 0-1 0-1.4.3-.3.3-.4.6-.5 1.1l-2.1 9.8v.6c0 .5.4.8 1.4.8h.2l-.2.8H8l.2-.8h.2c1.1 0 1.8-.5 2-1.5l2-9.8.1-.5c0-.6-.4-.8-1.4-.8h-.3l.2-.9h5.8Z" fill-rule="evenodd"></path></svg>',shortcut:"Mod-i"}],commands:{toggleItalic:U},keymap:{"Mod-i":"toggleItalic","Mod-I":"toggleItalic"}}),toggleItalic:U},Symbol.toStringTag,{value:"Module"})),Te=Object.freeze(Object.defineProperty({__proto__:null,UnderlinePlugin:()=>({name:"underline",marks:{underline:{parseDOM:[{tag:"u"}],toDOM:()=>["u",{},0]}},toolbar:[{label:"Underline",command:"toggleUnderline",icon:'<svg width="24" height="24" focusable="false"><path d="M16 5c.6 0 1 .4 1 1v7c0 2.8-2.2 5-5 5s-5-2.2-5-5V6c0-.6.4-1 1-1s1 .4 1 1v7c0 1.7 1.3 3 3 3s3-1.3 3-3V6c0-.6.4-1 1-1ZM4 17h16c.6 0 1 .4 1 1s-.4 1-1 1H4a1 1 0 1 1 0-2Z" fill-rule="evenodd"></path></svg>',shortcut:"Mod-u"}],commands:{toggleUnderline:()=>(document.execCommand("underline",!1),!0)},keymap:{"Mod-u":"toggleUnderline","Mod-U":"toggleUnderline"}})},Symbol.toStringTag,{value:"Module"})),Ee=Object.freeze(Object.defineProperty({__proto__:null,StrikethroughPlugin:()=>({name:"strikethrough",marks:{strikethrough:{parseDOM:[{tag:"s"},{tag:"strike"},{tag:"del"},{style:"text-decoration",getAttrs:l=>(typeof l=="string"?l:l.style.textDecoration)==="line-through"&&null}],toDOM:()=>["s",0]}},toolbar:[{label:"Strikethrough",command:"toggleStrikethrough",icon:'<svg width="24" height="24" focusable="false"><g fill-rule="evenodd"><path d="M15.6 8.5c-.5-.7-1-1.1-1.3-1.3-.6-.4-1.3-.6-2-.6-2.7 0-2.8 1.7-2.8 2.1 0 1.6 1.8 2 3.2 2.3 4.4.9 4.6 2.8 4.6 3.9 0 1.4-.7 4.1-5 4.1A6.2 6.2 0 0 1 7 16.4l1.5-1.1c.4.6 1.6 2 3.7 2 1.6 0 2.5-.4 3-1.2.4-.8.3-2-.8-2.6-.7-.4-1.6-.7-2.9-1-1-.2-3.9-.8-3.9-3.6C7.6 6 10.3 5 12.4 5c2.9 0 4.2 1.6 4.7 2.4l-1.5 1.1Z"></path><path d="M5 11h14a1 1 0 0 1 0 2H5a1 1 0 0 1 0-2Z" fill-rule="nonzero"></path></g></svg>',shortcut:"Mod-Shift-x"}],commands:{toggleStrikethrough:()=>(document.execCommand("strikeThrough",!1),!0)},keymap:{"Mod-Shift-x":"toggleStrikethrough","Mod-Shift-X":"toggleStrikethrough"}})},Symbol.toStringTag,{value:"Module"})),Le=Object.freeze(Object.defineProperty({__proto__:null,ClearFormattingPlugin:()=>({name:"clearFormatting",toolbar:[{label:"Clear Formatting",command:"clearFormatting",icon:'<svg width="24" height="24" focusable="false"><path d="M13.2 6a1 1 0 0 1 0 .2l-2.6 10a1 1 0 0 1-1 .8h-.2a.8.8 0 0 1-.8-1l2.6-10H8a1 1 0 1 1 0-2h9a1 1 0 0 1 0 2h-3.8ZM5 18h7a1 1 0 0 1 0 2H5a1 1 0 0 1 0-2Zm13 1.5L16.5 18 15 19.5a.7.7 0 0 1-1-1l1.5-1.5-1.5-1.5a.7.7 0 0 1 1-1l1.5 1.5 1.5-1.5a.7.7 0 0 1 1 1L17.5 17l1.5 1.5a.7.7 0 0 1-1 1Z" fill-rule="evenodd"></path></svg>',shortcut:"Mod-\\"}],commands:{clearFormatting:()=>(document.execCommand("removeFormat",!1),!0)},keymap:{"Mod-\\":"clearFormatting"}})},Symbol.toStringTag,{value:"Module"})),Se=Object.freeze(Object.defineProperty({__proto__:null,HeadingPlugin:()=>{const l=e=>{try{return document.execCommand("formatBlock",!1,e),!0}catch(t){return console.error(`Failed to set block type to ${e}:`,t),!1}};return{name:"heading",toolbar:[{label:"Heading",command:"setBlockType",type:"dropdown",options:[{value:"p",label:"Paragraph"},{value:"h1",label:"Heading 1"},{value:"h2",label:"Heading 2"},{value:"h3",label:"Heading 3"},{value:"h4",label:"Heading 4"},{value:"h5",label:"Heading 5"},{value:"h6",label:"Heading 6"}],icon:'<svg width="24" height="24" focusable="false"><path d="M16.1 8.6 14.2 4l-1.4.5 2.8 7.4c.1.4.5.6.9.6h.1c.4-.1.6-.5.6-.9l1.8-4.8-1.4-.5-1.5 2.3ZM4 11.5h6V10H4v1.5ZM18.5 3v1L17 7l.9.9L20.7 3h-2.2ZM5.5 12h1v7h1v-7h1v-.5h-3V12Zm4 0h1v7h1v-7h1v-.5h-3V12Zm10 1.5a2 2 0 0 0-2-2h-1v7.5h1v-2.7h1a2 2 0 0 0 2-2v-.8Zm-2 1.3h-1v-2.3h1a.8.8 0 1 1 0 1.6v.7Z" fill-rule="evenodd"></path></svg>'}],commands:{setBlockType:e=>e?l(e):!1,setHeading1:()=>l("h1"),setHeading2:()=>l("h2"),setHeading3:()=>l("h3"),setParagraph:()=>l("p")},keymap:{"Mod-Alt-1":"setHeading1","Mod-Alt-2":"setHeading2","Mod-Alt-3":"setHeading3","Mod-Alt-0":"setParagraph"}}}},Symbol.toStringTag,{value:"Module"})),Pe=Object.freeze(Object.defineProperty({__proto__:null,BlockquotePlugin:()=>({name:"blockquote",nodes:{blockquote:{content:"block+",group:"block",parseDOM:[{tag:"blockquote"}],toDOM:()=>["blockquote",0]}},toolbar:[{label:"Quote",command:"toggleBlockquote",icon:'<svg fill="#000000" height="24px" width="24px" version="1.1" id="Icons" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 32 32" xml:space="preserve"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <g> <path d="M13,11c0.6,0,1-0.4,1-1s-0.4-1-1-1c-5,0-9,4-9,9c0,2.8,2.2,5,5,5s5-2.2,5-5s-2.2-5-5-5c-0.3,0-0.7,0-1,0.1 C9.3,11.8,11,11,13,11z"></path> <path d="M23,13c-0.3,0-0.7,0-1,0.1c1.3-1.3,3-2.1,5-2.1c0.6,0,1-0.4,1-1s-0.4-1-1-1c-5,0-9,4-9,9c0,2.8,2.2,5,5,5s5-2.2,5-5 S25.8,13,23,13z"></path> </g> </g></svg>',shortcut:"Mod-Shift-9"}],commands:{toggleBlockquote:()=>{const l=window.getSelection();if(!l||l.rangeCount===0)return!1;let e=l.anchorNode,t=!1;for(;e&&e!==document.body;){if(e.nodeName==="BLOCKQUOTE"){t=!0;break}e=e.parentNode}return t?document.execCommand("formatBlock",!1,"p"):document.execCommand("formatBlock",!1,"blockquote"),!0}},keymap:{"Mod-Shift-9":"toggleBlockquote"}})},Symbol.toStringTag,{value:"Module"}));class j{constructor(e=""){this._lines=[],this._version=0,this.setText(e)}getLine(e){return this._lines[e]||""}getLines(){return[...this._lines]}getLineCount(){return this._lines.length}getText(){return this._lines.join(`
4
4
  `)}setText(e){this._lines=e.split(`
5
5
  `),this._version++}getTextInRange(e){if(e.start.line===e.end.line)return this.getLine(e.start.line).substring(e.start.column,e.end.column);const t=[];t.push(this.getLine(e.start.line).substring(e.start.column));for(let o=e.start.line+1;o<e.end.line;o++)t.push(this.getLine(o));return e.end.line<this.getLineCount()&&t.push(this.getLine(e.end.line).substring(0,e.end.column)),t.join(`
6
- `)}replaceRange(e,t){const o=this.getTextInRange(e);if(e.start.line===e.end.line){const n=this.getLine(e.start.line),i=n.substring(0,e.start.column)+t+n.substring(e.end.column);this._lines[e.start.line]=i}else{const n=this.getLine(e.start.line),i=this.getLine(e.end.line),r=n.substring(0,e.start.column)+t,a=i.substring(e.end.column),l=t.split(`
7
- `);l[0]=r+l[0],l[l.length-1]=l[l.length-1]+a,this._lines.splice(e.start.line,e.end.line-e.start.line+1,...l)}return this._version++,{range:e,text:t,oldText:o}}insertText(e,t){const o={start:e,end:e};return this.replaceRange(o,t)}deleteRange(e){return this.replaceRange(e,"")}positionToOffset(e){let t=0;for(let o=0;o<e.line;o++)t+=this.getLine(o).length+1;return t+=e.column,t}offsetToPosition(e){let t=e;for(let o=0;o<this.getLineCount();o++){const n=this.getLine(o).length;if(t<=n)return{line:o,column:t};t-=n+1}return{line:this.getLineCount()-1,column:this.getLine(this.getLineCount()-1).length}}isValidPosition(e){return!(e.line<0||e.line>=this.getLineCount()||e.column<0||e.column>this.getLine(e.line).length)}isValidRange(e){return this.isValidPosition(e.start)&&this.isValidPosition(e.end)}getVersion(){return this._version}clone(){const e=new O;return e._lines=[...this._lines],e._version=this._version,e}}class Le{constructor(e){this.gutterWidth=50,this.lineHeight=21,this.container=e,this.createDOM()}createDOM(){this.container.innerHTML="";const e=document.createElement("div");e.style.cssText=`
6
+ `)}replaceRange(e,t){const o=this.getTextInRange(e);if(e.start.line===e.end.line){const i=this.getLine(e.start.line),n=i.substring(0,e.start.column)+t+i.substring(e.end.column);this._lines[e.start.line]=n}else{const i=this.getLine(e.start.line),n=this.getLine(e.end.line),r=i.substring(0,e.start.column)+t,s=n.substring(e.end.column),a=t.split(`
7
+ `);a[0]=r+a[0],a[a.length-1]=a[a.length-1]+s,this._lines.splice(e.start.line,e.end.line-e.start.line+1,...a)}return this._version++,{range:e,text:t,oldText:o}}insertText(e,t){const o={start:e,end:e};return this.replaceRange(o,t)}deleteRange(e){return this.replaceRange(e,"")}positionToOffset(e){let t=0;for(let o=0;o<e.line;o++)t+=this.getLine(o).length+1;return t+=e.column,t}offsetToPosition(e){let t=e;for(let o=0;o<this.getLineCount();o++){const i=this.getLine(o).length;if(t<=i)return{line:o,column:t};t-=i+1}return{line:this.getLineCount()-1,column:this.getLine(this.getLineCount()-1).length}}isValidPosition(e){return!(e.line<0||e.line>=this.getLineCount()||e.column<0||e.column>this.getLine(e.line).length)}isValidRange(e){return this.isValidPosition(e.start)&&this.isValidPosition(e.end)}getVersion(){return this._version}clone(){const e=new j;return e._lines=[...this._lines],e._version=this._version,e}}class Oe{constructor(e){this.gutterWidth=50,this.lineHeight=21,this.container=e,this.createDOM()}createDOM(){this.container.innerHTML="";const e=document.createElement("div");this.editorContainer=e,e.style.cssText=`
8
8
  position: relative;
9
9
  display: flex;
10
10
  width: 100%;
@@ -14,29 +14,29 @@
14
14
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
15
15
  font-size: 14px;
16
16
  line-height: ${this.lineHeight}px;
17
- overflow: hidden;
18
- `,this.lineNumbersElement=document.createElement("div"),this.lineNumbersElement.style.cssText=`
19
- position: sticky;
20
- left: 0;
21
- top: 0;
17
+ /* make the outer container the single scrollable element so gutter and content scroll together */
18
+ overflow: auto;
19
+ `,this.lineNumbersElement=document.createElement("div"),this.lineNumbersElement.setAttribute("data-editor-gutter","true"),this.lineNumbersElement.style.cssText=`
20
+ display: table-cell;
21
+ vertical-align: top;
22
22
  width: ${this.gutterWidth}px;
23
23
  background: var(--editor-gutter-background, #252526);
24
24
  color: var(--editor-gutter-foreground, #858585);
25
- padding: 0;
25
+ padding: 0 8px 0 0;
26
26
  text-align: right;
27
27
  border-right: 1px solid var(--editor-gutter-border, #3e3e42);
28
28
  user-select: none;
29
- overflow: hidden;
30
29
  z-index: 1;
31
30
  `,this.contentElement=document.createElement("div"),this.contentElement.style.cssText=`
32
- flex: 1;
33
- padding: 0;
31
+ display: table-cell;
32
+ vertical-align: top;
33
+ padding: 0 12px;
34
34
  background: transparent;
35
35
  border: none;
36
36
  outline: none;
37
37
  white-space: pre;
38
38
  overflow-x: auto;
39
- overflow-y: auto;
39
+ overflow-y: visible;
40
40
  min-height: 400px;
41
41
  font-family: inherit;
42
42
  font-size: inherit;
@@ -44,32 +44,17 @@
44
44
  color: inherit;
45
45
  tab-size: 2;
46
46
  -moz-tab-size: 2;
47
- `,this.contentElement.contentEditable="true",this.contentElement.spellcheck=!1,e.appendChild(this.lineNumbersElement),e.appendChild(this.contentElement),this.container.appendChild(e),this.updateLineNumbers(1)}updateLineNumbers(e){const t=Math.max(e,20),o=Array.from({length:t},(n,i)=>i+1);this.lineNumbersElement.innerHTML=o.map(n=>`<div style="height: ${this.lineHeight}px; line-height: ${this.lineHeight}px; padding-right: 12px;">${n}</div>`).join("")}getContentElement(){return this.contentElement}getLineNumbersElement(){return this.lineNumbersElement}getText(){return this.contentElement.textContent||""}setText(e){this.contentElement.textContent=e;const t=e.split(`
48
- `).length;this.updateLineNumbers(t)}getCursorPosition(){const e=window.getSelection();if(!e||e.rangeCount===0)return{line:0,column:0};const t=e.getRangeAt(0),o=t.cloneRange();o.selectNodeContents(this.contentElement),o.setEnd(t.endContainer,t.endOffset);const n=o.toString().split(`
49
- `);return{line:n.length-1,column:n[n.length-1].length}}setCursorPosition(e){var g,m;const t=this.getText().split(`
50
- `),o=Math.min(e.line,t.length-1),n=Math.min(e.column,((g=t[o])==null?void 0:g.length)||0);let i=0;for(let f=0;f<o;f++)i+=t[f].length+1;i+=n;const r=document.createRange(),a=window.getSelection();let l=0,h=null,d=0;const c=document.createTreeWalker(this.contentElement,NodeFilter.SHOW_TEXT,null);let u;for(;u=c.nextNode();){const f=((m=u.textContent)==null?void 0:m.length)||0;if(l+f>=i){h=u,d=i-l;break}l+=f}if(h)try{r.setStart(h,d),r.setEnd(h,d),a==null||a.removeAllRanges(),a==null||a.addRange(r)}catch(f){console.warn("Could not set cursor position:",f)}}getSelectionRange(){const e=window.getSelection();if(!e||e.rangeCount===0||e.isCollapsed)return;const t=e.getRangeAt(0),o=t.cloneRange();o.selectNodeContents(this.contentElement),o.setEnd(t.startContainer,t.startOffset);const n=o.toString().split(`
51
- `),i=t.cloneRange();i.selectNodeContents(this.contentElement),i.setEnd(t.endContainer,t.endOffset);const r=i.toString().split(`
52
- `);return{start:{line:n.length-1,column:n[n.length-1].length},end:{line:r.length-1,column:r[r.length-1].length}}}setSelectionRange(e){this.setCursorPosition(e.start)}focus(){this.contentElement.focus()}blur(){this.contentElement.blur()}setReadOnly(e){this.contentElement.contentEditable=e?"false":"true"}applyTheme(e){Object.entries(e).forEach(([t,o])=>{this.container.style.setProperty(`--${t}`,o)})}scrollToPosition(e){const t=this.lineNumbersElement.children[e.line];t&&t.scrollIntoView({block:"center",behavior:"smooth"})}getScrollTop(){return this.contentElement.scrollTop}setScrollTop(e){this.contentElement.scrollTop=e,this.lineNumbersElement.scrollTop=e}destroy(){this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container)}}class Me{constructor(e,t={}){this.extensions=new Map,this.commands=new Map,this.eventListeners=new Map,this.folds=[],this.currentTheme="default",this.isDestroyed=!1,this.config={value:"",theme:"default",readOnly:!1,tabSize:2,lineWrapping:!1,lineNumbers:!0,...t},this.textModel=new O(this.config.value),this.view=new Le(e),this.view.setText(this.textModel.getText()),this.view.setReadOnly(this.config.readOnly||!1),this.setupEventHandlers(),this.config.extensions&&this.config.extensions.forEach(o=>this.addExtension(o)),this.setTheme(this.config.theme)}getTextModel(){return this.textModel}getView(){return this.view}getConfig(){return{...this.config}}getKeymapExtension(){return this.extensions.get("keymap")}setupEventHandlers(){const e=this.view.getContentElement();e.addEventListener("input",()=>{const t=this.view.getText(),o=this.textModel.getText();t!==o&&(this.textModel.setText(t),this.emit("change",[{range:this.getFullRange(),text:t,oldText:o}]),this.updateLineNumbers())}),e.addEventListener("selectionchange",()=>{const t=this.getCursor(),o=this.getSelection();this.emit("cursor",t),o&&this.emit("selection",o)}),e.addEventListener("keydown",t=>{this.emit("keydown",t);for(const o of this.extensions.values())if(o.onKeyDown&&o.onKeyDown(t)===!1){t.preventDefault(),t.stopPropagation();return}}),e.addEventListener("mousedown",t=>{this.emit("mousedown",t);for(const o of this.extensions.values())if(o.onMouseDown&&o.onMouseDown(t)===!1){t.preventDefault(),t.stopPropagation();return}}),e.addEventListener("focus",()=>{this.emit("focus")}),e.addEventListener("blur",()=>{this.emit("blur")})}updateLineNumbers(){const e=this.textModel.getLineCount();this.view.updateLineNumbers(e)}getFullRange(){return{start:{line:0,column:0},end:{line:this.textModel.getLineCount()-1,column:this.textModel.getLine(this.textModel.getLineCount()-1).length}}}emit(e,...t){const o=this.eventListeners.get(e);o&&o.forEach(n=>n(...t))}getValue(){return this.textModel.getText()}setValue(e){this.textModel.setText(e),this.view.setText(e),this.updateLineNumbers(),this.emit("change",[{range:this.getFullRange(),text:e,oldText:this.getValue()}])}getState(){return{text:this.getValue(),cursor:this.getCursor(),selection:this.getSelection(),readOnly:this.config.readOnly||!1,theme:this.currentTheme}}getCursor(){const e=this.view.getCursorPosition();return{position:e,anchor:e}}setCursor(e){this.view.setCursorPosition(e),this.emit("cursor",this.getCursor())}getSelection(){return this.view.getSelectionRange()}setSelection(e){this.view.setSelectionRange(e),this.emit("selection",e)}setTheme(e){this.currentTheme=e;const t={"editor-background":e==="dark"?"#1e1e1e":"#ffffff","editor-foreground":e==="dark"?"#f8f9fa":"#1a1a1a","editor-gutter-background":e==="dark"?"#252526":"#f8f9fa","editor-gutter-foreground":e==="dark"?"#858585":"#666666","editor-gutter-border":e==="dark"?"#3e3e42":"#e1e5e9"};this.view.applyTheme(t)}setReadOnly(e){this.config.readOnly=e,this.view.setReadOnly(e)}addExtension(e){if(this.extensions.has(e.name))throw new Error(`Extension '${e.name}' already exists`);this.extensions.set(e.name,e),e.setup(this)}removeExtension(e){const t=this.extensions.get(e);t&&t.destroy&&t.destroy(),this.extensions.delete(e)}executeCommand(e,...t){const o=this.commands.get(e);o?o(this,...t):console.warn(`Command '${e}' not found`)}registerCommand(e,t){this.commands.set(e,t)}search(e,t={}){const o={caseSensitive:!1,regex:!1,...t},n=[],i=this.getValue();i.split(`
53
- `);let r=o.caseSensitive?i:i.toLowerCase(),a=o.caseSensitive?e:e.toLowerCase();if(o.regex){const l=new RegExp(a,o.caseSensitive?"g":"gi");let h;for(;(h=l.exec(r))!==null;){const d=this.textModel.offsetToPosition(h.index),c=this.textModel.offsetToPosition(h.index+h[0].length);n.push({range:{start:d,end:c},match:h[0]})}}else{let l=0,h=r.indexOf(a,l);for(;h!==-1;){const d=h+e.length,c=this.textModel.offsetToPosition(h),u=this.textModel.offsetToPosition(d);n.push({range:{start:c,end:u},match:i.substring(h,d)}),l=d,h=r.indexOf(a,l)}}return n}replace(e,t){const o=this.textModel.replaceRange(e,t);this.view.setText(this.getValue()),this.emit("change",[o])}replaceAll(e,t,o={}){const n=this.search(e,o);let i=0;for(let r=n.length-1;r>=0;r--)this.replace(n[r].range,t),i++;return i}fold(e){const t={start:e.start,end:e.end,collapsed:!0,level:0};this.folds.push(t)}unfold(e){this.folds=this.folds.filter(t=>!(t.start.line===e.start.line&&t.end.line===e.end.line))}getFolds(){return[...this.folds]}focus(){this.view.focus()}blur(){this.view.blur()}destroy(){if(!this.isDestroyed){this.isDestroyed=!0;for(const e of this.extensions.values())e.destroy&&e.destroy();this.extensions.clear(),this.view.destroy(),this.commands.clear(),this.eventListeners.clear()}}on(e,t){this.eventListeners.has(e)||this.eventListeners.set(e,[]),this.eventListeners.get(e).push(t)}off(e,t){if(!this.eventListeners.has(e))return;const o=this.eventListeners.get(e);if(t){const n=o.indexOf(t);n!==-1&&o.splice(n,1)}else o.length=0}}class Te{constructor(e){this.name="keymap",this.editor=null,this.keymap={},this.isMac=navigator.platform.toUpperCase().indexOf("MAC")>=0,this.keymap=e||this.getDefaultKeymap()}setup(e){this.editor=e,e.on("keydown",t=>this.handleKeyDown(t))}handleKeyDown(e){if(!this.editor)return;const t=this.findMatchingBinding(e);if(t)return this.editor.executeCommand(t.command),e.preventDefault(),e.stopPropagation(),!1}findMatchingBinding(e){const{key:t,ctrlKey:o,altKey:n,shiftKey:i,metaKey:r}=e,a=t.toLowerCase(),l=this.keymap[a];if(!l)return null;for(const h of l)if((h.ctrlKey===o||!h.ctrlKey&&!o)&&(h.altKey===n||!h.altKey&&!n)&&(h.shiftKey===i||!h.shiftKey&&!i)&&(h.metaKey===r||!h.metaKey&&!r))return h;return null}getDefaultKeymap(){const e={};return this.addBinding(e,"f",{ctrlKey:!this.isMac,metaKey:this.isMac},"find"),this.addBinding(e,"h",{ctrlKey:!this.isMac,metaKey:this.isMac},"replace"),this.addBinding(e,"f3",{},"findNext"),this.addBinding(e,"f3",{shiftKey:!0},"findPrev"),this.addBinding(e,"g",{ctrlKey:!this.isMac,metaKey:this.isMac},"findNext"),this.addBinding(e,"[",{ctrlKey:!this.isMac,metaKey:this.isMac,shiftKey:!0},"fold"),this.addBinding(e,"]",{ctrlKey:!this.isMac,metaKey:this.isMac,shiftKey:!0},"unfold"),this.addBinding(e,"s",{ctrlKey:!this.isMac,metaKey:this.isMac},"save"),this.addBinding(e,"z",{ctrlKey:!this.isMac,metaKey:this.isMac},"undo"),this.addBinding(e,"y",{ctrlKey:!this.isMac,metaKey:this.isMac},"redo"),this.addBinding(e,"z",{ctrlKey:!this.isMac,metaKey:this.isMac,shiftKey:!0},"redo"),this.addBinding(e,"t",{ctrlKey:!this.isMac,metaKey:this.isMac,shiftKey:!0},"toggleTheme"),e}addBinding(e,t,o,n){const i=t.toLowerCase();e[i]||(e[i]=[]),e[i].push({key:i,command:n,...o})}setKeymap(e){this.keymap={...e}}addKeyBinding(e){const t=e.key.toLowerCase();this.keymap[t]||(this.keymap[t]=[]),this.keymap[t]=this.keymap[t].filter(o=>o.command!==e.command),this.keymap[t].push({...e,key:t})}removeKeyBinding(e,t){const o=e.toLowerCase();t?this.keymap[o]&&(this.keymap[o]=this.keymap[o].filter(n=>n.command!==t),this.keymap[o].length===0&&delete this.keymap[o]):delete this.keymap[o]}getKeymap(){return{...this.keymap}}getBindingsForCommand(e){const t=[];for(const o in this.keymap)for(const n of this.keymap[o])n.command===e&&t.push({...n});return t}getPlatformInfo(){return{isMac:this.isMac,platform:navigator.platform}}destroy(){this.keymap={},this.editor=null}}class Se{constructor(){this.name="line-numbers",this.editor=null,this.lineNumbersElement=null,this.isEnabled=!0}setup(e){this.editor=e,this.createLineNumbers(),e.registerCommand("toggleLineNumbers",()=>{this.toggle()}),e.on("change",()=>{this.updateLineNumbers()}),this.updateLineNumbers()}createLineNumbers(){if(!this.editor)return;const e=this.editor.getView();if(!e.container)return;this.lineNumbersElement=document.createElement("div"),this.lineNumbersElement.style.cssText=`
54
- position: absolute;
55
- left: 0;
56
- top: 0;
57
- bottom: 0;
58
- width: 50px;
59
- background: var(--editor-gutter-background, #252526);
60
- color: var(--editor-gutter-foreground, #858585);
61
- font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
62
- font-size: 14px;
63
- line-height: 21px;
64
- padding: 0;
65
- text-align: right;
66
- border-right: 1px solid var(--editor-gutter-border, #3e3e42);
67
- user-select: none;
68
- overflow: hidden;
69
- z-index: 1;
70
- pointer-events: none;
71
- `;const t=e.getContentElement();t&&t.parentNode&&(t.parentNode.insertBefore(this.lineNumbersElement,t),t.style.marginLeft="60px")}updateLineNumbers(){if(!this.lineNumbersElement||!this.editor||!this.isEnabled)return;const e=this.editor.getValue().split(`
72
- `).length,t=Array.from({length:Math.max(e,20)},(o,n)=>n+1);this.lineNumbersElement.innerHTML=t.map(o=>`<div style="height: 21px; line-height: 21px; padding-right: 12px;">${o}</div>`).join("")}toggle(){this.isEnabled=!this.isEnabled,this.lineNumbersElement&&(this.lineNumbersElement.style.display=this.isEnabled?"block":"none");const e=this.editor.getView().getContentElement();e&&(e.style.marginLeft=this.isEnabled?"60px":"0"),this.updateLineNumbers()}destroy(){this.lineNumbersElement&&this.lineNumbersElement.parentNode&&this.lineNumbersElement.parentNode.removeChild(this.lineNumbersElement),this.lineNumbersElement=null,this.editor=null}}class Pe{constructor(){this.name="theme",this.editor=null,this.currentTheme="dark"}setup(e){this.editor=e,e.registerCommand("setTheme",t=>{this.setTheme(t)}),e.registerCommand("toggleTheme",()=>{this.toggleTheme()}),this.setTheme(this.currentTheme)}setTheme(e){this.editor&&(this.currentTheme=e,this.editor.setTheme(e))}toggleTheme(){const e=this.currentTheme==="dark"?"light":"dark";this.setTheme(e)}getCurrentTheme(){return this.currentTheme}destroy(){this.editor=null}}class Ie{constructor(){this.name="read-only",this.editor=null,this.isReadOnly=!1}setup(e){this.editor=e,e.registerCommand("setReadOnly",t=>{this.setReadOnly(t)}),e.registerCommand("toggleReadOnly",()=>{this.toggleReadOnly()}),e.on("keydown",t=>{if(t.ctrlKey&&t.key==="r")return t.preventDefault(),this.toggleReadOnly(),!1})}setReadOnly(e){this.editor&&(this.isReadOnly=e,this.editor.setReadOnly(e))}toggleReadOnly(){this.setReadOnly(!this.isReadOnly)}isCurrentlyReadOnly(){return this.isReadOnly}destroy(){this.editor=null}}class He{constructor(){this.name="search",this.editor=null,this.searchUI=null,this.isVisible=!1,this.currentResults=[],this.currentIndex=-1}setup(e){this.editor=e,e.registerCommand("find",()=>{this.showSearch()}),e.registerCommand("findNext",()=>{this.findNext()}),e.registerCommand("findPrev",()=>{this.findPrev()}),e.registerCommand("replace",()=>{this.showReplace()}),e.registerCommand("replaceAll",(t,o)=>{this.replaceAll(t,o)})}showSearch(){if(this.editor&&(this.searchUI||this.createSearchUI(),this.isVisible=!0,this.searchUI)){this.searchUI.style.display="block";const e=this.searchUI.querySelector("input");e&&(e.focus(),e.select())}}showReplace(){var o,n;this.showSearch();const e=(o=this.searchUI)==null?void 0:o.querySelector(".search-replace-input");e&&(e.style.display="block",e.focus());const t=(n=this.searchUI)==null?void 0:n.querySelector(".search-status");t&&(t.textContent="Replace mode - Enter to replace, Shift+Enter to replace all")}hideSearch(){this.isVisible=!1,this.searchUI&&(this.searchUI.style.display="none"),this.clearHighlights()}createSearchUI(){if(!this.editor)return;const e=document.querySelector(".rte-source-editor-modal");if(!e)return;this.searchUI=document.createElement("div"),this.searchUI.style.cssText=`
47
+ `,this.contentElement.contentEditable="true",this.contentElement.spellcheck=!1;const t=document.createElement("div");t.setAttribute("data-editora-editor","true"),t.style.cssText="display: table; table-layout: fixed; width: 100%; height: 100%;",t.appendChild(this.lineNumbersElement),t.appendChild(this.contentElement),e.appendChild(t),this.container.appendChild(e),this.updateLineNumbers(1)}updateLineNumbers(e){const t=Math.max(e,20),o=Array.from({length:t},(i,n)=>n+1);this.lineNumbersElement.innerHTML=o.map(i=>`<div style="height: ${this.lineHeight}px; line-height: ${this.lineHeight}px; padding-right: 12px;">${i}</div>`).join("")}getContentElement(){return this.contentElement}getLineNumbersElement(){return this.lineNumbersElement}getText(){return this.contentElement.textContent||""}setText(e){this.contentElement.textContent=e;const t=e.split(`
48
+ `).length;this.updateLineNumbers(t)}setHTML(e){const t=/&lt;|&gt;/.test(e),o=/<span\b/i.test(e),i=/<[^>]+>/.test(e);t&&o?this.contentElement.innerHTML=e:i&&!t?this.contentElement.textContent=e:this.contentElement.innerHTML=e;const n=(this.contentElement.textContent||"").split(`
49
+ `).length;this.updateLineNumbers(n)}getCursorPosition(){const e=window.getSelection();if(!e||e.rangeCount===0)return{line:0,column:0};const t=e.getRangeAt(0),o=t.cloneRange();o.selectNodeContents(this.contentElement),o.setEnd(t.endContainer,t.endOffset);const i=o.toString().split(`
50
+ `);return{line:i.length-1,column:i[i.length-1].length}}setCursorPosition(e){var g,p;const t=this.getText().split(`
51
+ `),o=Math.min(e.line,t.length-1),i=Math.min(e.column,((g=t[o])==null?void 0:g.length)||0);let n=0;for(let f=0;f<o;f++)n+=t[f].length+1;n+=i;const r=document.createRange(),s=window.getSelection();let a=0,c=null,d=0;const h=document.createTreeWalker(this.contentElement,NodeFilter.SHOW_TEXT,null);let u;for(;u=h.nextNode();){const f=((p=u.textContent)==null?void 0:p.length)||0;if(a+f>=n){c=u,d=n-a;break}a+=f}if(c)try{r.setStart(c,d),r.setEnd(c,d),s==null||s.removeAllRanges(),s==null||s.addRange(r)}catch(f){console.warn("Could not set cursor position:",f)}}getSelectionRange(){const e=window.getSelection();if(!e||e.rangeCount===0||e.isCollapsed)return;const t=e.getRangeAt(0),o=t.cloneRange();o.selectNodeContents(this.contentElement),o.setEnd(t.startContainer,t.startOffset);const i=o.toString().split(`
52
+ `),n=t.cloneRange();n.selectNodeContents(this.contentElement),n.setEnd(t.endContainer,t.endOffset);const r=n.toString().split(`
53
+ `);return{start:{line:i.length-1,column:i[i.length-1].length},end:{line:r.length-1,column:r[r.length-1].length}}}setSelectionRange(e){this.setCursorPosition(e.start)}focus(){this.contentElement.focus()}blur(){this.contentElement.blur()}setReadOnly(e){this.contentElement.contentEditable=e?"false":"true"}applyTheme(e){Object.entries(e).forEach(([t,o])=>{this.container.style.setProperty(`--${t}`,o)})}scrollToPosition(e){const t=this.lineNumbersElement.children[e.line];t&&t.scrollIntoView({block:"center",behavior:"smooth"})}getScrollTop(){return this.editorContainer.scrollTop}setScrollTop(e){this.editorContainer.scrollTop=e}destroy(){this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container),this._rafId&&(cancelAnimationFrame(this._rafId),this._rafId=void 0)}}class He{constructor(e,t={}){this.extensions=new Map,this.commands=new Map,this.eventListeners=new Map,this.folds=[],this.currentTheme="default",this.isDestroyed=!1,this.undoStack=[],this.redoStack=[],this.suppressHistory=!1,this.expectingProgrammaticCursor=!1,this.config={value:"",theme:"default",readOnly:!1,tabSize:2,lineWrapping:!1,lineNumbers:!0,...t},this.textModel=new j(this.config.value),this.view=new Oe(e),this.setupEventHandlers(),this.config.extensions&&this.config.extensions.forEach(o=>this.addExtension(o)),this.setTheme(this.config.theme),this.view.setReadOnly(this.config.readOnly||!1),this.renderTextWithHighlight(this.textModel.getText()),this.registerBuiltInCommands()}getTextModel(){return this.textModel}getView(){return this.view}getConfig(){return{...this.config}}registerBuiltInCommands(){this.registerCommand("undo",()=>this.undo()),this.registerCommand("redo",()=>this.redo()),this.registerCommand("insertTab",()=>this.insertTab()),this.registerCommand("save",()=>{this.emit("save")})}getKeymapExtension(){return this.extensions.get("keymap")}setupEventHandlers(){const e=this.view.getContentElement();e.addEventListener("input",()=>{const t=this.view.getText(),o=this.textModel.getText();if(t!==o){if(!this.suppressHistory){const i=this.getCursor().position,n=this.textModel.positionToOffset(i),r=this.getSelection();let s,a;r&&(s=this.textModel.positionToOffset(r.start),a=this.textModel.positionToOffset(r.end)),this.undoStack.push({text:o,cursorOffset:n,anchorOffset:s,focusOffset:a}),this.undoStack.length>100&&this.undoStack.shift(),this.redoStack.length=0}this.textModel.setText(t),this.highlightTimeout&&clearTimeout(this.highlightTimeout),this.highlightTimeout=setTimeout(()=>{this.renderTextWithHighlight(this.textModel.getText(),!1),this.highlightTimeout=null},300),this.updateLineNumbers(),this.emit("change",[{range:this.getFullRange(),text:t,oldText:o}])}}),e.addEventListener("selectionchange",()=>{const t=this.getCursor(),o=this.getSelection();this.emit("cursor",t),o&&this.emit("selection",o)}),e.addEventListener("keydown",t=>{if(this.emit("keydown",t),t.key==="Tab"){this.config.readOnly||this.insertTab(),t.preventDefault(),t.stopPropagation();return}if(t.key==="Enter"){if(!this.config.readOnly){const o=window.getSelection();if(o&&o.rangeCount>0){const i=this.getCursor().position,n=this.textModel.positionToOffset(i),r=this.getSelection();let s,a;r&&(s=this.textModel.positionToOffset(r.start),a=this.textModel.positionToOffset(r.end)),this.suppressHistory||(this.undoStack.push({text:this.textModel.getText(),cursorOffset:n,anchorOffset:s,focusOffset:a}),this.undoStack.length>100&&this.undoStack.shift(),this.redoStack.length=0);const c=o.getRangeAt(0);c.deleteContents();const d=document.createTextNode(`
54
+ `);c.insertNode(d),c.setStartAfter(d),c.collapse(!0),o.removeAllRanges(),o.addRange(c);const h=this.getCursor().position,u=this.textModel.positionToOffset(h),g=this.getSelection();let p,f;g&&(p=this.textModel.positionToOffset(g.start),f=this.textModel.positionToOffset(g.end));const m=this.view.getText();this.textModel.setText(m),this.highlightTimeout&&clearTimeout(this.highlightTimeout),this.highlightTimeout=setTimeout(()=>{this.renderTextWithHighlight(this.textModel.getText(),!1),requestAnimationFrame(()=>{try{if(g&&(p!==void 0||f!==void 0)){const x=p!==void 0?p:u,y=f!==void 0?f:u,v=Math.min(x,y),H=Math.max(x,y),I=this.textModel.offsetToPosition(v),w=this.textModel.offsetToPosition(H);this.setSelection({start:I,end:w})}else{const x=this.textModel.offsetToPosition(u);this.setCursor(x)}}catch(x){}}),this.highlightTimeout=null},300),this.updateLineNumbers(),this.emit("change",[{range:this.getFullRange(),text:this.getValue(),oldText:""}])}}t.preventDefault(),t.stopPropagation();return}for(const o of this.extensions.values())if(o.onKeyDown&&o.onKeyDown(t)===!1){t.preventDefault(),t.stopPropagation();return}}),e.addEventListener("mousedown",t=>{this.emit("mousedown",t);for(const o of this.extensions.values())if(o.onMouseDown&&o.onMouseDown(t)===!1){t.preventDefault(),t.stopPropagation();return}}),e.addEventListener("focus",()=>{this.emit("focus")}),e.addEventListener("blur",()=>{this.emit("blur")})}updateLineNumbers(){const e=this.textModel.getLineCount();this.view.updateLineNumbers(e)}getFullRange(){return{start:{line:0,column:0},end:{line:this.textModel.getLineCount()-1,column:this.textModel.getLine(this.textModel.getLineCount()-1).length}}}emit(e,...t){const o=this.eventListeners.get(e);o&&o.forEach(i=>i(...t))}getValue(){return this.textModel.getText()}setValue(e){const t=this.textModel.getText();this.textModel.setText(e),this.renderTextWithHighlight(e,!1),this.updateLineNumbers(),this.emit("change",[{range:this.getFullRange(),text:e,oldText:t}])}getState(){return{text:this.getValue(),cursor:this.getCursor(),selection:this.getSelection(),readOnly:this.config.readOnly||!1,theme:this.currentTheme}}getCursor(){const e=this.view.getCursorPosition();return{position:e,anchor:e}}setCursor(e){this.view.setCursorPosition(e),this.emit("cursor",this.getCursor())}getSelection(){return this.view.getSelectionRange()}setSelection(e){this.view.setSelectionRange(e),this.emit("selection",e)}setTheme(e){this.currentTheme=e;const t={"editor-background":e==="dark"?"#1e1e1e":"#ffffff","editor-foreground":e==="dark"?"#f8f9fa":"#1a1a1a","editor-gutter-background":e==="dark"?"#252526":"#f8f9fa","editor-gutter-foreground":e==="dark"?"#858585":"#666666","editor-gutter-border":e==="dark"?"#3e3e42":"#e1e5e9"};this.view.applyTheme(t);const o=this.extensions.get("syntax-highlighting");if(o&&typeof o.setTheme=="function")try{o.setTheme(e==="dark"?"dark":"light"),this.renderTextWithHighlight(this.textModel.getText())}catch(i){console.warn("Error applying theme to syntax-highlighting extension",i)}}setReadOnly(e){this.config.readOnly=e,this.view.setReadOnly(e)}addExtension(e){if(this.extensions.has(e.name))throw new Error(`Extension '${e.name}' already exists`);this.extensions.set(e.name,e),e.setup(this),e.name==="syntax-highlighting"&&typeof e.highlightHTML=="function"&&this.renderTextWithHighlight(this.textModel.getText())}removeExtension(e){const t=this.extensions.get(e);t&&t.destroy&&t.destroy(),this.extensions.delete(e)}executeCommand(e,...t){const o=this.commands.get(e);o?o(this,...t):console.warn(`Command '${e}' not found`)}registerCommand(e,t){this.commands.set(e,t)}search(e,t={}){const o={caseSensitive:!1,regex:!1,...t},i=[],n=this.getValue();n.split(`
55
+ `);let r=o.caseSensitive?n:n.toLowerCase(),s=o.caseSensitive?e:e.toLowerCase();if(o.regex){const a=new RegExp(s,o.caseSensitive?"g":"gi");let c;for(;(c=a.exec(r))!==null;){const d=this.textModel.offsetToPosition(c.index),h=this.textModel.offsetToPosition(c.index+c[0].length);i.push({range:{start:d,end:h},match:c[0]})}}else{let a=0,c=r.indexOf(s,a);for(;c!==-1;){const d=c+e.length,h=this.textModel.offsetToPosition(c),u=this.textModel.offsetToPosition(d);i.push({range:{start:h,end:u},match:n.substring(c,d)}),a=d,c=r.indexOf(s,a)}}return i}replace(e,t){const o=this.getValue();if(!this.suppressHistory){const n=this.getCursor().position,r=this.textModel.positionToOffset(n),s=this.getSelection();let a,c;s&&(a=this.textModel.positionToOffset(s.start),c=this.textModel.positionToOffset(s.end)),this.undoStack.push({text:o,cursorOffset:r,anchorOffset:a,focusOffset:c}),this.undoStack.length>100&&this.undoStack.shift(),this.redoStack.length=0}const i=this.textModel.replaceRange(e,t);this.renderTextWithHighlight(this.getValue(),!1),this.emit("change",[i])}replaceAll(e,t,o={}){const i=this.search(e,o);let n=0;for(let r=i.length-1;r>=0;r--)this.replace(i[r].range,t),n++;return n}fold(e){const t={start:e.start,end:e.end,collapsed:!0,level:0};this.folds.push(t)}unfold(e){this.folds=this.folds.filter(t=>!(t.start.line===e.start.line&&t.end.line===e.end.line))}getFolds(){return[...this.folds]}focus(){this.view.focus()}blur(){this.view.blur()}renderTextWithHighlight(e,t=!0){const o=this.extensions.get("syntax-highlighting");if(o&&typeof o.highlightHTML=="function")try{const i=!t&&!this.expectingProgrammaticCursor;let n,r,s,a;if(t||i){n=this.getSelection();const d=this.getCursor().position;r=this.textModel.positionToOffset(d),n&&(s=this.textModel.positionToOffset(n.start),a=this.textModel.positionToOffset(n.end))}const c=o.highlightHTML(e);typeof this.view.setHighlightHTML=="function"?this.view.setHighlightHTML(c):this.view.setHTML(c),(t||i)&&requestAnimationFrame(()=>{try{if(n&&(s!==void 0||a!==void 0)){const d=s!==void 0?s:r,h=a!==void 0?a:r,u=Math.min(d,h),g=Math.max(d,h),p=this.textModel.offsetToPosition(u),f=this.textModel.offsetToPosition(g);this.view.setSelectionRange({start:p,end:f})}else if(r!==void 0){const d=this.textModel.offsetToPosition(r);this.view.setCursorPosition(d)}}catch(d){}});return}catch(i){console.warn("Syntax highlighting failed, falling back to plain text",i)}this.view.setText(e)}destroy(){if(!this.isDestroyed){this.isDestroyed=!0;for(const e of this.extensions.values())e.destroy&&e.destroy();this.extensions.clear(),this.view.destroy(),this.commands.clear(),this.eventListeners.clear()}}undo(){if(this.undoStack.length===0)return;const e=this.undoStack.pop(),t={text:this.getValue(),cursorOffset:this.textModel.positionToOffset(this.getCursor().position)};this.redoStack.push(t);try{this.suppressHistory=!0,this.expectingProgrammaticCursor=!0;let o,i;typeof e=="string"?o=e:(o=e.text,i=e.cursorOffset),this.setValue(o),requestAnimationFrame(()=>{try{if(i!=null)if(typeof e!="string"&&(e.anchorOffset!==void 0||e.focusOffset!==void 0)){const n=e.anchorOffset!==void 0?e.anchorOffset:i,r=e.focusOffset!==void 0?e.focusOffset:i,s=Math.min(n,r),a=Math.max(n,r),c=this.textModel.offsetToPosition(s),d=this.textModel.offsetToPosition(a);this.setSelection({start:c,end:d})}else{const n=this.textModel.offsetToPosition(i);this.setCursor(n)}}catch(n){}}),setTimeout(()=>{this.expectingProgrammaticCursor=!1},30)}finally{this.suppressHistory=!1}}redo(){if(this.redoStack.length===0)return;const e=this.redoStack.pop(),t={text:this.getValue(),cursorOffset:this.textModel.positionToOffset(this.getCursor().position)};this.undoStack.push(t);try{this.suppressHistory=!0,this.expectingProgrammaticCursor=!0;let o,i;typeof e=="string"?o=e:(o=e.text,i=e.cursorOffset),this.setValue(o),requestAnimationFrame(()=>{try{if(i!=null)if(typeof e!="string"&&(e.anchorOffset!==void 0||e.focusOffset!==void 0)){const n=e.anchorOffset!==void 0?e.anchorOffset:i,r=e.focusOffset!==void 0?e.focusOffset:i,s=Math.min(n,r),a=Math.max(n,r),c=this.textModel.offsetToPosition(s),d=this.textModel.offsetToPosition(a);this.setSelection({start:c,end:d})}else{const n=this.textModel.offsetToPosition(i);this.setCursor(n)}}catch(n){}}),setTimeout(()=>{this.expectingProgrammaticCursor=!1},30)}finally{this.suppressHistory=!1}}insertTab(){if(this.config.readOnly)return;const e=this.getCursor().position,t=this.textModel.positionToOffset(e),o=" ".repeat(this.config.tabSize||2),i=this.textModel.insertText(e,o),n=this.textModel.offsetToPosition(this.textModel.positionToOffset(e)+o.length);if(!this.suppressHistory){const r=this.getSelection();let s,a;r&&(s=this.textModel.positionToOffset(r.start),a=this.textModel.positionToOffset(r.end)),this.undoStack.push({text:this.getValue(),cursorOffset:t,anchorOffset:s,focusOffset:a}),this.redoStack.length=0}this.expectingProgrammaticCursor=!0,this.renderTextWithHighlight(this.getValue(),!1),this.setCursor(n),setTimeout(()=>{this.expectingProgrammaticCursor=!1},20),this.emit("change",[i])}insertNewLine(){if(this.config.readOnly)return;const e=this.getCursor().position,t=this.textModel.positionToOffset(e),o=this.textModel.insertText(e,`
56
+ `),i=this.textModel.offsetToPosition(this.textModel.positionToOffset(e)+1);if(!this.suppressHistory){const n=this.getSelection();let r,s;n&&(r=this.textModel.positionToOffset(n.start),s=this.textModel.positionToOffset(n.end)),this.undoStack.push({text:this.getValue(),cursorOffset:t,anchorOffset:r,focusOffset:s}),this.redoStack.length=0}this.expectingProgrammaticCursor=!0,this.renderTextWithHighlight(this.getValue(),!1),this.setCursor(i),setTimeout(()=>{this.expectingProgrammaticCursor=!1},20),this.emit("change",[o])}on(e,t){this.eventListeners.has(e)||this.eventListeners.set(e,[]),this.eventListeners.get(e).push(t)}off(e,t){if(!this.eventListeners.has(e))return;const o=this.eventListeners.get(e);if(t){const i=o.indexOf(t);i!==-1&&o.splice(i,1)}else o.length=0}}class Ie{constructor(e){this.name="keymap",this.editor=null,this.keymap={},this.isMac=navigator.platform.toUpperCase().indexOf("MAC")>=0,this.keymap=e||this.getDefaultKeymap()}setup(e){this.editor=e}handleKeyDown(e){if(!this.editor)return;const t=this.findMatchingBinding(e);if(t)return this.editor.executeCommand(t.command),e.preventDefault(),e.stopPropagation(),!1}findMatchingBinding(e){const{key:t,ctrlKey:o,altKey:i,shiftKey:n,metaKey:r}=e,s=String(t).toLowerCase(),a=this.keymap[s];if(!a)return null;for(const c of a){const d=c.ctrlKey===void 0||c.ctrlKey===o,h=c.altKey===void 0||c.altKey===i,u=c.shiftKey===void 0||c.shiftKey===n,g=c.metaKey===void 0||c.metaKey===r;if(d&&h&&u&&g)return c}return null}onKeyDown(e){return this.handleKeyDown(e)}getDefaultKeymap(){const e={};return this.addBinding(e,"f",{ctrlKey:!this.isMac,metaKey:this.isMac},"find"),this.addBinding(e,"h",{ctrlKey:!this.isMac,metaKey:this.isMac},"replace"),this.addBinding(e,"f3",{},"findNext"),this.addBinding(e,"f3",{shiftKey:!0},"findPrev"),this.addBinding(e,"g",{ctrlKey:!this.isMac,metaKey:this.isMac},"findNext"),this.addBinding(e,"[",{ctrlKey:!this.isMac,metaKey:this.isMac,shiftKey:!0},"fold"),this.addBinding(e,"]",{ctrlKey:!this.isMac,metaKey:this.isMac,shiftKey:!0},"unfold"),this.addBinding(e,"s",{ctrlKey:!0},"save"),this.addBinding(e,"s",{metaKey:!0},"save"),this.addBinding(e,"z",{ctrlKey:!0},"undo"),this.addBinding(e,"z",{metaKey:!0},"undo"),this.addBinding(e,"y",{ctrlKey:!0},"redo"),this.addBinding(e,"y",{metaKey:!0},"redo"),this.addBinding(e,"z",{ctrlKey:!0,shiftKey:!0},"redo"),this.addBinding(e,"z",{metaKey:!0,shiftKey:!0},"redo"),this.addBinding(e,"tab",{},"insertTab"),this.addBinding(e,"t",{ctrlKey:!this.isMac,metaKey:this.isMac,shiftKey:!0},"toggleTheme"),e}addBinding(e,t,o,i){const n=t.toLowerCase();e[n]||(e[n]=[]),e[n].push({key:n,command:i,...o})}setKeymap(e){this.keymap={...e}}addKeyBinding(e){const t=e.key.toLowerCase();this.keymap[t]||(this.keymap[t]=[]),this.keymap[t]=this.keymap[t].filter(o=>o.command!==e.command),this.keymap[t].push({...e,key:t})}removeKeyBinding(e,t){const o=e.toLowerCase();t?this.keymap[o]&&(this.keymap[o]=this.keymap[o].filter(i=>i.command!==t),this.keymap[o].length===0&&delete this.keymap[o]):delete this.keymap[o]}getKeymap(){return{...this.keymap}}getBindingsForCommand(e){const t=[];for(const o in this.keymap)for(const i of this.keymap[o])i.command===e&&t.push({...i});return t}getPlatformInfo(){return{isMac:this.isMac,platform:navigator.platform}}destroy(){this.keymap={},this.editor=null}}class Ae{constructor(){this.name="transaction",this.transactions=[]}setup(e){e.on("change",t=>{const o={changes:[t],selection:e.getSelection(),effects:[],annotations:[]};this.transactions.push(o)})}getTransactions(){return this.transactions}destroy(){this.transactions=[]}}class Be{constructor(){this.name="line-numbers",this.editor=null,this.lineNumbersElement=null,this.isEnabled=!0}setup(e){this.editor=e,this.createLineNumbers(),e.registerCommand("toggleLineNumbers",()=>{this.toggle()}),e.on("change",()=>{this.updateLineNumbers()}),this.updateLineNumbers()}createLineNumbers(){if(!this.editor)return;const e=this.editor.getView().getLineNumbersElement();e&&(this.lineNumbersElement=e)}updateLineNumbers(){if(!this.lineNumbersElement||!this.editor||!this.isEnabled)return;const e=this.editor.getValue().split(`
57
+ `).length,t=Array.from({length:Math.max(e,20)},(o,i)=>i+1);this.lineNumbersElement.innerHTML=t.map(o=>`<div style="height: 21px; line-height: 21px; padding-right: 12px;">${o}</div>`).join("")}toggle(){this.isEnabled=!this.isEnabled,this.lineNumbersElement&&(this.lineNumbersElement.style.display=this.isEnabled?"block":"none");const e=this.editor.getView().getContentElement();e&&(e.style.marginLeft=this.isEnabled?"60px":"0"),this.updateLineNumbers()}destroy(){this.lineNumbersElement=null,this.editor=null}}class Ne{constructor(){this.name="theme",this.editor=null,this.currentTheme="dark"}setup(e){this.editor=e,e.registerCommand("setTheme",t=>{this.setTheme(t)}),e.registerCommand("toggleTheme",()=>{this.toggleTheme()}),this.setTheme(this.currentTheme)}setTheme(e){this.editor&&(this.currentTheme=e,this.editor.setTheme(e))}toggleTheme(){const e=this.currentTheme==="dark"?"light":"dark";this.setTheme(e)}getCurrentTheme(){return this.currentTheme}destroy(){this.editor=null}}class $e{constructor(){this.name="read-only",this.editor=null,this.isReadOnly=!1}setup(e){this.editor=e,e.registerCommand("setReadOnly",t=>{this.setReadOnly(t)}),e.registerCommand("toggleReadOnly",()=>{this.toggleReadOnly()}),e.on("keydown",t=>{if(t.ctrlKey&&t.key==="r")return t.preventDefault(),this.toggleReadOnly(),!1})}setReadOnly(e){this.editor&&(this.isReadOnly=e,this.editor.setReadOnly(e))}toggleReadOnly(){this.setReadOnly(!this.isReadOnly)}isCurrentlyReadOnly(){return this.isReadOnly}destroy(){this.editor=null}}class Re{constructor(){this.name="search",this.editor=null,this.searchUI=null,this.isVisible=!1,this.currentResults=[],this.currentIndex=-1}setup(e){this.editor=e,e.registerCommand("find",()=>{this.showSearch()}),e.registerCommand("findNext",()=>{this.findNext()}),e.registerCommand("findPrev",()=>{this.findPrev()}),e.registerCommand("replace",()=>{this.showReplace()}),e.registerCommand("replaceAll",(t,o)=>{this.replaceAll(t,o)})}showSearch(){if(this.editor&&(this.searchUI||this.createSearchUI(),this.isVisible=!0,this.searchUI)){this.searchUI.style.display="block";const e=this.searchUI.querySelector("input");e&&(e.focus(),e.select())}}showReplace(){var o,i;this.showSearch();const e=(o=this.searchUI)==null?void 0:o.querySelector(".search-replace-input");e&&(e.style.display="block",e.focus());const t=(i=this.searchUI)==null?void 0:i.querySelector(".search-status");t&&(t.textContent="Replace mode - Enter to replace, Shift+Enter to replace all")}hideSearch(){this.isVisible=!1,this.searchUI&&(this.searchUI.style.display="none"),this.clearHighlights()}createSearchUI(){if(!this.editor)return;const e=document.querySelector(".rte-source-editor-modal");if(!e)return;this.searchUI=document.createElement("div"),this.searchUI.style.cssText=`
73
58
  position: absolute;
74
59
  top: 10px;
75
60
  right: 10px;
@@ -138,11 +123,11 @@
138
123
  display: none;
139
124
  margin-top: 4px;
140
125
  " />
141
- `;const t=this.searchUI.querySelector("input"),o=this.searchUI.querySelector(".search-replace-input"),n=this.searchUI.querySelector(".search-prev"),i=this.searchUI.querySelector(".search-next"),r=this.searchUI.querySelector(".search-close");t.addEventListener("input",()=>{this.performSearch(t.value)}),t.addEventListener("keydown",a=>{a.key==="Enter"&&(a.preventDefault(),a.shiftKey?this.findPrev():this.findNext())}),o.addEventListener("keydown",a=>{a.key==="Enter"&&(a.preventDefault(),a.shiftKey?this.replaceAll(t.value,o.value):this.replaceCurrent(t.value,o.value))}),n.addEventListener("click",()=>this.findPrev()),i.addEventListener("click",()=>this.findNext()),r.addEventListener("click",()=>this.hideSearch()),e.appendChild(this.searchUI)}performSearch(e){if(!this.editor||!e.trim()){this.clearHighlights(),this.updateStatus("");return}const t=this.editor.getValue(),o=[];let n=t.toLowerCase().indexOf(e.toLowerCase());for(;n!==-1;){const i=this.getPositionFromOffset(t,n),r=this.getPositionFromOffset(t,n+e.length);o.push({range:{start:i,end:r},match:t.substring(n,n+e.length)}),n=t.toLowerCase().indexOf(e.toLowerCase(),n+1)}this.currentResults=o,this.currentIndex=this.currentResults.length>0?0:-1,this.updateHighlights(),this.updateStatus(`${this.currentResults.length} matches`)}getPositionFromOffset(e,t){const o=e.substring(0,t).split(`
142
- `),n=o.length-1,i=o[o.length-1].length;return{line:n,column:i}}findNext(){this.currentResults.length!==0&&(this.currentIndex=(this.currentIndex+1)%this.currentResults.length,this.updateHighlights())}findPrev(){this.currentResults.length!==0&&(this.currentIndex=this.currentIndex<=0?this.currentResults.length-1:this.currentIndex-1,this.updateHighlights())}replaceCurrent(e,t){if(!this.editor||!e.trim()||this.currentIndex===-1)return;const o=this.currentResults[this.currentIndex];if(!o)return;const n=this.editor.getValue(),i=this.getOffsetFromPosition(n,o.range.start),r=n.substring(0,i),a=n.substring(i+e.length),l=r+t+a;this.editor.setValue(l),this.performSearch(e),this.updateStatus("Replaced current occurrence")}replaceAll(e,t){if(!this.editor||!e.trim())return;let o=this.editor.getValue(),n=0,i=o.toLowerCase().indexOf(e.toLowerCase());for(;i!==-1;)o=o.substring(0,i)+t+o.substring(i+e.length),n++,i=o.toLowerCase().indexOf(e.toLowerCase(),i+t.length);n>0&&(this.editor.setValue(o),this.updateStatus(`Replaced ${n} occurrences`))}getOffsetFromPosition(e,t){const o=e.split(`
143
- `);let n=0;for(let i=0;i<t.line;i++)n+=o[i].length+1;return n+=t.column,n}updateHighlights(){this.clearHighlights(),!(this.currentResults.length===0||this.currentIndex===-1)&&(this.currentResults[this.currentIndex],this.updateStatus(`${this.currentResults.length} matches (showing ${this.currentIndex+1}/${this.currentResults.length})`))}clearHighlights(){}updateStatus(e){var o;const t=(o=this.searchUI)==null?void 0:o.querySelector(".search-status");t&&(t.textContent=e)}destroy(){this.searchUI&&this.searchUI.parentNode&&this.searchUI.parentNode.removeChild(this.searchUI),this.searchUI=null,this.editor=null}}class Oe{constructor(){this.name="bracket-matching",this.editor=null,this.bracketPairs={"(":")","[":"]","{":"}","<":">"},this.reverseBracketPairs={")":"(","]":"[","}":"{",">":"<"},this.currentMatch=null}setup(e){this.editor=e,e.on("cursor",()=>{this.updateBracketMatching()}),e.on("change",()=>{this.updateBracketMatching()})}updateBracketMatching(){if(!this.editor)return;const e=this.editor.getCursor(),t=this.editor.getValue();this.clearBracketHighlighting();const o=this.getBracketAtPosition(t,e.position);if(!o)return;const n=this.findMatchingBracket(t,o);n&&(this.currentMatch=n,this.highlightBrackets(n))}getBracketAtPosition(e,t){const o=e.split(`
144
- `);if(t.line>=o.length)return null;const n=o[t.line];if(t.column>=n.length)return null;const i=n[t.column];return this.bracketPairs[i]||this.reverseBracketPairs[i]?{char:i,position:t}:null}findMatchingBracket(e,t){const o=e.split(`
145
- `),n=t.position.line,i=t.position.column,r=t.char;return this.bracketPairs[r]?this.findClosingBracket(e,o,n,i,r):this.reverseBracketPairs[r]?this.findOpeningBracket(e,o,n,i,r):null}findClosingBracket(e,t,o,n,i){const r=this.bracketPairs[i];let a=0;for(let l=o;l<t.length;l++){const h=t[l],d=l===o?n:0;for(let c=d;c<h.length;c++){const u=h[c];if(u===i)a++;else if(u===r&&(a--,a===0))return{open:{start:{line:o,column:n},end:{line:o,column:n+1}},close:{start:{line:l,column:c},end:{line:l,column:c+1}},type:i}}}return null}findOpeningBracket(e,t,o,n,i){const r=this.reverseBracketPairs[i];let a=0;for(let l=o;l>=0;l--){const h=t[l],d=l===o?n:h.length-1;for(let c=d;c>=0;c--){const u=h[c];if(u===i)a++;else if(u===r&&(a--,a===0))return{open:{start:{line:l,column:c},end:{line:l,column:c+1}},close:{start:{line:o,column:n},end:{line:o,column:n+1}},type:r}}}return null}highlightBrackets(e){console.log("Bracket match found:",e)}clearBracketHighlighting(){this.currentMatch=null}getCurrentMatch(){return this.currentMatch}destroy(){this.clearBracketHighlighting(),this.editor=null}}class Ne{constructor(){this.name="code-folding",this.editor=null,this.foldIndicators=[],this.foldingUI=null}setup(e){this.editor=e,e.registerCommand("fold",()=>{console.log("Fold command executed - folding not yet implemented"),this.foldAtCursor()}),e.registerCommand("unfold",()=>{console.log("Unfold command executed - unfolding not yet implemented"),this.unfoldAtCursor()}),e.registerCommand("foldAll",()=>{console.log("Fold all command executed - folding not yet implemented"),this.foldAll()}),e.registerCommand("unfoldAll",()=>{console.log("Unfold all command executed - unfolding not yet implemented"),this.unfoldAll()}),e.on("change",()=>{this.updateFoldIndicators()}),this.createFoldingUI(),this.updateFoldIndicators()}createFoldingUI(){if(!this.editor)return;const e=document.querySelector(".rte-source-editor-modal");e&&(this.foldingUI=document.createElement("div"),this.foldingUI.style.cssText=`
126
+ `;const t=this.searchUI.querySelector("input"),o=this.searchUI.querySelector(".search-replace-input"),i=this.searchUI.querySelector(".search-prev"),n=this.searchUI.querySelector(".search-next"),r=this.searchUI.querySelector(".search-close");t.addEventListener("input",()=>{this.performSearch(t.value)}),t.addEventListener("keydown",s=>{s.key==="Enter"&&(s.preventDefault(),s.shiftKey?this.findPrev():this.findNext())}),o.addEventListener("keydown",s=>{s.key==="Enter"&&(s.preventDefault(),s.shiftKey?this.replaceAll(t.value,o.value):this.replaceCurrent(t.value,o.value))}),i.addEventListener("click",()=>this.findPrev()),n.addEventListener("click",()=>this.findNext()),r.addEventListener("click",()=>this.hideSearch()),e.appendChild(this.searchUI)}performSearch(e){if(!this.editor||!e.trim()){this.clearHighlights(),this.updateStatus("");return}const t=this.editor.getValue(),o=[];let i=t.toLowerCase().indexOf(e.toLowerCase());for(;i!==-1;){const n=this.getPositionFromOffset(t,i),r=this.getPositionFromOffset(t,i+e.length);o.push({range:{start:n,end:r},match:t.substring(i,i+e.length)}),i=t.toLowerCase().indexOf(e.toLowerCase(),i+1)}this.currentResults=o,this.currentIndex=this.currentResults.length>0?0:-1,this.updateHighlights(),this.updateStatus(`${this.currentResults.length} matches`)}getPositionFromOffset(e,t){const o=e.substring(0,t).split(`
127
+ `),i=o.length-1,n=o[o.length-1].length;return{line:i,column:n}}findNext(){this.currentResults.length!==0&&(this.currentIndex=(this.currentIndex+1)%this.currentResults.length,this.updateHighlights())}findPrev(){this.currentResults.length!==0&&(this.currentIndex=this.currentIndex<=0?this.currentResults.length-1:this.currentIndex-1,this.updateHighlights())}replaceCurrent(e,t){if(!this.editor||!e.trim()||this.currentIndex===-1)return;const o=this.currentResults[this.currentIndex];if(!o)return;const i=this.editor.getValue(),n=this.getOffsetFromPosition(i,o.range.start),r=i.substring(0,n),s=i.substring(n+e.length),a=r+t+s;this.editor.setValue(a),this.performSearch(e),this.updateStatus("Replaced current occurrence")}replaceAll(e,t){if(!this.editor||!e.trim())return;let o=this.editor.getValue(),i=0,n=o.toLowerCase().indexOf(e.toLowerCase());for(;n!==-1;)o=o.substring(0,n)+t+o.substring(n+e.length),i++,n=o.toLowerCase().indexOf(e.toLowerCase(),n+t.length);i>0&&(this.editor.setValue(o),this.updateStatus(`Replaced ${i} occurrences`))}getOffsetFromPosition(e,t){const o=e.split(`
128
+ `);let i=0;for(let n=0;n<t.line;n++)i+=o[n].length+1;return i+=t.column,i}updateHighlights(){this.clearHighlights(),!(this.currentResults.length===0||this.currentIndex===-1)&&(this.currentResults[this.currentIndex],this.updateStatus(`${this.currentResults.length} matches (showing ${this.currentIndex+1}/${this.currentResults.length})`))}clearHighlights(){}updateStatus(e){var o;const t=(o=this.searchUI)==null?void 0:o.querySelector(".search-status");t&&(t.textContent=e)}destroy(){this.searchUI&&this.searchUI.parentNode&&this.searchUI.parentNode.removeChild(this.searchUI),this.searchUI=null,this.editor=null}}class ze{constructor(){this.name="bracket-matching",this.editor=null,this.bracketPairs={"(":")","[":"]","{":"}","<":">"},this.reverseBracketPairs={")":"(","]":"[","}":"{",">":"<"},this.currentMatch=null}setup(e){this.editor=e,e.on("cursor",()=>{this.updateBracketMatching()}),e.on("change",()=>{this.updateBracketMatching()})}updateBracketMatching(){if(!this.editor)return;const e=this.editor.getCursor(),t=this.editor.getValue();this.clearBracketHighlighting();const o=this.getBracketAtPosition(t,e.position);if(!o)return;const i=this.findMatchingBracket(t,o);i&&(this.currentMatch=i,this.highlightBrackets(i))}getBracketAtPosition(e,t){const o=e.split(`
129
+ `);if(t.line>=o.length)return null;const i=o[t.line];if(t.column>=i.length)return null;const n=i[t.column];return this.bracketPairs[n]||this.reverseBracketPairs[n]?{char:n,position:t}:null}findMatchingBracket(e,t){const o=e.split(`
130
+ `),i=t.position.line,n=t.position.column,r=t.char;return this.bracketPairs[r]?this.findClosingBracket(e,o,i,n,r):this.reverseBracketPairs[r]?this.findOpeningBracket(e,o,i,n,r):null}findClosingBracket(e,t,o,i,n){const r=this.bracketPairs[n];let s=0;for(let a=o;a<t.length;a++){const c=t[a],d=a===o?i:0;for(let h=d;h<c.length;h++){const u=c[h];if(u===n)s++;else if(u===r&&(s--,s===0))return{open:{start:{line:o,column:i},end:{line:o,column:i+1}},close:{start:{line:a,column:h},end:{line:a,column:h+1}},type:n}}}return null}findOpeningBracket(e,t,o,i,n){const r=this.reverseBracketPairs[n];let s=0;for(let a=o;a>=0;a--){const c=t[a],d=a===o?i:c.length-1;for(let h=d;h>=0;h--){const u=c[h];if(u===n)s++;else if(u===r&&(s--,s===0))return{open:{start:{line:a,column:h},end:{line:a,column:h+1}},close:{start:{line:o,column:i},end:{line:o,column:i+1}},type:r}}}return null}highlightBrackets(e){}clearBracketHighlighting(){this.currentMatch=null}getCurrentMatch(){return this.currentMatch}destroy(){this.clearBracketHighlighting(),this.editor=null}}class _e{constructor(){this.name="code-folding",this.editor=null,this.foldIndicators=[],this.foldingUI=null}setup(e){this.editor=e,e.registerCommand("fold",()=>{this.foldAtCursor()}),e.registerCommand("unfold",()=>{this.unfoldAtCursor()}),e.registerCommand("foldAll",()=>{this.foldAll()}),e.registerCommand("unfoldAll",()=>{this.unfoldAll()}),e.on("change",()=>{this.updateFoldIndicators()}),this.createFoldingUI(),this.updateFoldIndicators()}createFoldingUI(){if(!this.editor)return;const e=document.querySelector(".rte-source-editor-modal");e&&(this.foldingUI=document.createElement("div"),this.foldingUI.style.cssText=`
146
131
  position: absolute;
147
132
  left: 40px;
148
133
  top: 0;
@@ -151,7 +136,7 @@
151
136
  pointer-events: none;
152
137
  z-index: 2;
153
138
  `,e.appendChild(this.foldingUI))}updateFoldIndicators(){if(!this.editor||!this.foldingUI)return;this.foldingUI.innerHTML="",this.foldIndicators=[];const e=this.editor.getValue().split(`
154
- `);this.findFoldableLines(e).forEach(t=>{this.createFoldIndicator(t)})}findFoldableLines(e){const t=[];for(let o=0;o<e.length;o++){const n=e[o].trim();(n.startsWith("{")||n.startsWith("function")||n.startsWith("class")||n.startsWith("if")||n.includes("=>")||n.startsWith("for")||n.startsWith("while")||n.startsWith("try"))&&t.push(o)}return t}createFoldIndicator(e){if(!this.foldingUI)return;const t=document.createElement("div");t.style.cssText=`
139
+ `);this.findFoldableLines(e).forEach(t=>{this.createFoldIndicator(t)})}findFoldableLines(e){const t=[];for(let o=0;o<e.length;o++){const i=e[o].trim();(i.startsWith("{")||i.startsWith("function")||i.startsWith("class")||i.startsWith("if")||i.includes("=>")||i.startsWith("for")||i.startsWith("while")||i.startsWith("try"))&&t.push(o)}return t}createFoldIndicator(e){if(!this.foldingUI)return;const t=document.createElement("div");t.style.cssText=`
155
140
  position: absolute;
156
141
  left: 0;
157
142
  top: ${e*21}px;
@@ -165,7 +150,7 @@
165
150
  color: var(--editor-gutter-foreground, #858585);
166
151
  font-size: 10px;
167
152
  user-select: none;
168
- `,t.innerHTML="▶",t.title="Code folding not yet implemented - click shows fold indicators",t.addEventListener("click",()=>{console.log(`Fold toggle clicked at line ${e} - implementation pending`)}),this.foldingUI.appendChild(t),this.foldIndicators.push(t)}foldAtCursor(){console.log("foldAtCursor called - implementation pending")}unfoldAtCursor(){console.log("unfoldAtCursor called - implementation pending")}foldAll(){console.log("foldAll called - implementation pending")}unfoldAll(){console.log("unfoldAll called - implementation pending")}destroy(){this.foldingUI&&this.foldingUI.parentNode&&this.foldingUI.parentNode.removeChild(this.foldingUI),this.foldingUI=null,this.foldIndicators=[],this.editor=null}}class Be{constructor(){this.name="syntax-highlighting",this.editor=null,this.currentTheme="dark"}setup(e){this.editor=e,console.log("SyntaxHighlightingExtension: Isolated extension loaded - ready for use")}setTheme(e){this.currentTheme=e,console.log(`SyntaxHighlightingExtension: Theme changed to ${e}`)}getSyntaxColors(){return this.currentTheme==="dark"?{tag:"#569cd6",comment:"#6a9955",attrValue:"#ce9178",text:"#d4d4d4"}:{tag:"#0000ff",comment:"#008000",attrValue:"#a31515",text:"#000000"}}highlightHTML(e){const t=this.getSyntaxColors();let o=e;return o=o.replace(/(<\/?[\w:-]+(?:\s[^>]*?)?\/?>)/g,`<span style="color: ${t.tag};">$1</span>`),o=o.replace(/(<!--[\s\S]*?-->)/g,`<span style="color: ${t.comment};">$1</span>`),o=o.replace(/("[^"]*"|'[^']*')/g,`<span style="color: ${t.attrValue};">$1</span>`),o}shouldHighlight(e){return/<\/?[\w:-]+|<!--/.test(e)}destroy(){this.editor=null,console.log("SyntaxHighlightingExtension: Extension destroyed")}}function Ae(s,e){const t={...e};return t.extensions||(t.extensions=[]),t.extensions.some(o=>o.name==="keymap")||t.extensions.unshift(new Te(t.keymap)),new Me(s,t)}const ze=`/* Source Editor Dialog Styles */
153
+ `,t.innerHTML="▶",t.title="Code folding not yet implemented - click shows fold indicators",t.addEventListener("click",()=>{}),this.foldingUI.appendChild(t),this.foldIndicators.push(t)}foldAtCursor(){}unfoldAtCursor(){}foldAll(){}unfoldAll(){}destroy(){this.foldingUI&&this.foldingUI.parentNode&&this.foldingUI.parentNode.removeChild(this.foldingUI),this.foldingUI=null,this.foldIndicators=[],this.editor=null}}class De{constructor(){this.name="syntax-highlighting",this.editor=null,this.currentTheme="dark",this.currentLanguage=null,this.modes=new Map}setup(e){this.editor=e,this.registerMode("html",{name:"html",highlight:(t,o)=>this._highlightHTML(t,o)}),this.registerMode("javascript",{name:"javascript",highlight:(t,o)=>this._highlightJS(t,o)}),this.registerMode("typescript",{name:"typescript",highlight:(t,o)=>this._highlightJS(t,o)}),this.registerMode("php",{name:"php",highlight:(t,o)=>this._highlightPHP(t,o)})}setTheme(e){this.currentTheme=e}setLanguage(e){this.currentLanguage=e}registerMode(e,t){this.modes.set(e.toLowerCase(),t)}getSyntaxColors(){return this.currentTheme==="dark"?{tag:"#569cd6",comment:"#6a9955",attrName:"#9cdcfe",attrValue:"#ce9178",styleProp:"#c586c0",styleVal:"#dcdcaa",doctype:"#808080",text:"#d4d4d4",keyword:"#c586c0",string:"#ce9178",number:"#b5cea8",variable:"#9cdcfe"}:{tag:"#0000ff",comment:"#008000",attrName:"#001080",attrValue:"#a31515",styleProp:"#6a00a8",styleVal:"#804000",doctype:"#444444",text:"#000000",keyword:"#000080",string:"#a31515",number:"#0086b3",variable:"#001080"}}highlight(e,t){const o=this.getSyntaxColors(),i=(t||this.currentLanguage||"html").toLowerCase();return(this.modes.get(i)||this.modes.get("html")).highlight(e,o)}highlightHTML(e){return this.highlight(e,"html")}escapeHTML(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\"/g,"&quot;").replace(/'/g,"&#39;")}unescapeEntitiesRepeated(e){let t=e||"";for(let o=0;o<5;o++){const i=t;if(t=t.replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#39;/g,"'"),t===i)break}return t}_highlightHTML(e,t){const o=t,i=c=>this.escapeHTML(c);let n=i(e);const r=c=>{let d=c.replace(/&quot;/g,'"').replace(/&#39;/g,"'");return d=d.replace(/(\/\*[\s\S]*?\*\/)/g,`<span style="color: ${o.comment};">$1</span>`),d=d.replace(/([a-zA-Z-]+)(\s*:\s*)([^;{]+)(;?)/g,(h,u,g,p,f)=>{const m=String(p).trim(),x=i(m);return`<span style="color: ${o.styleProp};">${u}</span>${g}<span style="color: ${o.styleVal};">${x}</span>${f}`}),d},s=[];try{e.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi,(c,d,h)=>(s.push({attrs:String(d||""),inner:String(h||"")}),c))}catch(c){}let a=0;return n=n.replace(/(&lt;script\b([^&>]*)&gt;)([\s\S]*?)(&lt;\/script&gt;)/gi,(c,d,h,u,g)=>{var m,x,y;const p=(x=(m=s[a++])==null?void 0:m.inner)!=null?x:this.unescapeEntitiesRepeated(u||"");(((y=s[a-1])==null?void 0:y.attrs)||h||"").toLowerCase();const f=this._highlightJS(p,o);return`${d}${f}${g}`}),n=n.replace(/(&lt;style\b[^&]*&gt;)([\s\S]*?)(&lt;\/style&gt;)/gi,(c,d,h,u)=>{const g=r(h);return`${d}${g}${u}`}),n=n.replace(/(&lt;!--[\s\S]*?--&gt;)/g,`<span style="color: ${o.comment};">$1</span>`),n=n.replace(/(&lt;!DOCTYPE[\s\S]*?&gt;)/i,`<span style="color: ${o.doctype};">$1</span>`),n=n.replace(/(&lt;\/?\s*)([^\s&>\/]+)([\s\S]*?)(\/?&gt;)/g,(c,d,h,u,g)=>{const p=`<span style="color: ${o.tag};">${h}</span>`;let f=u;return f=f.replace(/([\w:-]+)(\s*=\s*)((&quot;[\s\S]*?&quot;|&#39;[\s\S]*?&#39;|[^\s&>]+))/g,(m,x,y,v)=>{const H=String(x).toLowerCase(),I=`<span style="color: ${o.attrName};">${x}</span>`;let w=v,k="";v.startsWith("&quot;")&&v.endsWith("&quot;")?(w=v.slice(6,-6),k="&quot;"):v.startsWith("&#39;")&&v.endsWith("&#39;")&&(w=v.slice(5,-5),k="&#39;");let C=v;if(H==="style"){const A=w.replace(/([\w-]+)\s*:\s*([^;]+)(;?)/g,(Q,$,R,z)=>`<span style="color: ${o.styleProp};">${$}</span>:<span style="color: ${o.styleVal};">${R.trim()}</span>${z}`);k?C=`${k}${A}${k}`:C=A,C=`<span style="color: ${o.attrValue};">${C}</span>`}else k&&(C=`${k}${w}${k}`),C=`<span style="color: ${o.attrValue};">${C}</span>`;return`${I}${y}${C}`}),`${d}${p}${f}${g}`}),n}_highlightJS(e,t){const o=this.unescapeEntitiesRepeated(e);this.escapeHTML(o);const i=[],n=u=>{let g="",p=u;do g=String.fromCharCode(97+p%26)+g,p=Math.floor(p/26)-1;while(p>=0);return g||"a"},r=u=>`\0${n(u)}\0`,s=u=>{const g=i.length;return i.push(u),r(g)};let a;const c=/(\/\*[\s\S]*?\*\/)|(\/\/[^\n\r]*)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)/g;let d=0,h="";for(;a=c.exec(o);){const u=a.index;d<u&&(h+=this.escapeHTML(o.slice(d,u)));const g=a[0];/^\/\*/.test(g)||/^\/\//.test(g)?h+=s(`<span style="color: ${t.comment};">${this.escapeHTML(g)}</span>`):h+=s(`<span style="color: ${t.string};">${this.escapeHTML(g)}</span>`),d=c.lastIndex}return d<o.length&&(h+=this.escapeHTML(o.slice(d))),h=h.replace(/\b(0x[0-9a-fA-F]+|\d+\.?\d*|\d*\.\d+)\b/g,(u,g,p)=>{const f=h[p-1]||"",m=h[p+u.length]||"";return f==="&"||f==="#"||m===";"||m==="#"?u:`<span style="color: ${t.number};">${u}</span>`}),h=h.replace(/\b(const|let|var|function|class|if|else|return|for|while|switch|case|break|import|from|export|extends|new|try|catch|finally|throw|await|async|interface|type)\b/g,`<span style="color: ${t.keyword};">$1</span>`),h.replace(/\u0000([a-z]+)\u0000/g,(u,g)=>{let p=0;for(let f=0;f<g.length;f++)p=p*26+(g.charCodeAt(f)-97+1);return p=p-1,i[p]||""})}_highlightPHP(e,t){const o=this.unescapeEntitiesRepeated(e);let i=this.escapeHTML(o);const n=[],r=p=>{let f="",m=p;do f=String.fromCharCode(97+m%26)+f,m=Math.floor(m/26)-1;while(m>=0);return f||"a"},s=p=>{const f=n.length;return n.push(p),`\0${r(f)}\0`},a=(p,f)=>{const m=i.indexOf(p);return m===-1?!1:(i=i.slice(0,m)+f+i.slice(m+p.length),!0)};let c;const d=/\/\*[\s\S]*?\*\//g,h=/\/\/[^\n\r]*/g,u=/\#([^\n\r]*)/g,g=/("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')/g;for(;c=d.exec(o);){const p=c[0];a(this.escapeHTML(p),s(`<span style="color: ${t.comment};">${this.escapeHTML(p)}</span>`))}for(;c=h.exec(o);){const p=c[0];a(this.escapeHTML(p),s(`<span style="color: ${t.comment};">${this.escapeHTML(p)}</span>`))}for(;c=u.exec(o);){const p=c[0];a(this.escapeHTML(p),s(`<span style="color: ${t.comment};">${this.escapeHTML(p)}</span>`))}for(;c=g.exec(o);){const p=c[0];a(this.escapeHTML(p),s(`<span style="color: ${t.string};">${this.escapeHTML(p)}</span>`))}return i=i.replace(/(\$[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*)/g,`<span style="color: ${t.variable};">$1</span>`),i=i.replace(/\b(echo|print|function|class|if|else|elseif|foreach|as|return|namespace|use|new|extends|public|protected|private|static)\b/g,`<span style="color: ${t.keyword};">$1</span>`),i=i.replace(/\u0000([a-z]+)\u0000/g,(p,f)=>{let m=0;for(let x=0;x<f.length;x++)m=m*26+(f.charCodeAt(x)-97+1);return m=m-1,n[m]||""}),i}shouldHighlight(e){return/<\/?[\w:-]+|<!--/.test(e)}destroy(){this.editor=null,this.modes.clear()}}function Ue(l,e){const t={...e};return t.extensions||(t.extensions=[]),t.extensions.some(o=>o.name==="keymap")||t.extensions.unshift(new Ie(t.keymap)),t.extensions.some(o=>o.name==="transaction")||t.extensions.unshift(new Ae),new He(l,t)}const je=`/* Source Editor Dialog Styles */
169
154
  .rte-source-editor-overlay {
170
155
  position: fixed !important;
171
156
  top: 0 !important;
@@ -523,10 +508,10 @@
523
508
  flex: 1;
524
509
  text-align: center;
525
510
  }
526
- }`,Re=Object.freeze(Object.defineProperty({__proto__:null,CodePlugin:()=>({name:"code",toolbar:[{label:"Source",command:"toggleSourceView",type:"button",icon:"<>",shortcut:"Mod-Shift-S"}],commands:{toggleSourceView:()=>{const e=(()=>{var a,l,h;const i=window.getSelection();if(i&&i.anchorNode){let d=i.anchorNode instanceof HTMLElement?i.anchorNode:i.anchorNode.parentElement;for(;d;){if((a=d.classList)!=null&&a.contains("rte-content"))return d;d=d.parentElement}}if(document.activeElement){let d=document.activeElement;if((l=d.classList)!=null&&l.contains("rte-content"))return d;for(;d&&d!==document.body;){if((h=d.classList)!=null&&h.contains("rte-content"))return d;const c=d.querySelector(".rte-content");if(c)return c;d=d.parentElement}}const r=document.querySelector("[data-editora-editor]");if(r){const d=r.querySelector(".rte-content");if(d)return d}return document.querySelector(".rte-content")})();if(!e)return console.error("[CodePlugin] Editor content area not found"),alert("Editor content area not found. Please click inside the editor first."),!1;const t=e.innerHTML,o=i=>{let r="",a=0;const l=2,h=i.split(/(<\/?[a-zA-Z][^>]*>)/);for(const d of h)d.trim()&&(d.match(/^<\/[a-zA-Z]/)?(a=Math.max(0,a-1),r+=`
527
- `+" ".repeat(a*l)+d):d.match(/^<[a-zA-Z]/)&&!d.match(/\/>$/)?(r+=`
528
- `+" ".repeat(a*l)+d,a++):d.match(/^<[a-zA-Z].*\/>$/)?r+=`
529
- `+" ".repeat(a*l)+d:r+=d.trim());return r.trim()};return(()=>{var X,Y,Q,J,ee,te;let i=null,r="dark",a=!1,l=!1,h=!1;const d=t,c=document.createElement("div");c.className="rte-source-editor-overlay";const u=document.createElement("div");u.className="rte-source-editor-modal",u.setAttribute("role","dialog"),u.setAttribute("aria-modal","true"),u.setAttribute("aria-labelledby","source-editor-title");const g=document.createElement("div");g.className="rte-source-editor-header",g.innerHTML=`
511
+ }`,Fe=Object.freeze(Object.defineProperty({__proto__:null,CodePlugin:()=>({name:"code",toolbar:[{label:"Source",command:"toggleSourceView",type:"button",icon:"<>",shortcut:"Mod-Shift-S"}],commands:{toggleSourceView:()=>{const e=(()=>{var s,a,c;const n=window.getSelection();if(n&&n.anchorNode){let d=n.anchorNode instanceof HTMLElement?n.anchorNode:n.anchorNode.parentElement;for(;d;){if((s=d.classList)!=null&&s.contains("rte-content"))return d;d=d.parentElement}}if(document.activeElement){let d=document.activeElement;if((a=d.classList)!=null&&a.contains("rte-content"))return d;for(;d&&d!==document.body;){if((c=d.classList)!=null&&c.contains("rte-content"))return d;const h=d.querySelector(".rte-content");if(h)return h;d=d.parentElement}}const r=document.querySelector("[data-editora-editor]");if(r){const d=r.querySelector(".rte-content");if(d)return d}return document.querySelector(".rte-content")})();if(!e)return console.error("[CodePlugin] Editor content area not found"),alert("Editor content area not found. Please click inside the editor first."),!1;const t=e.innerHTML,o=n=>{let r="",s=0;const a=2,c=n.split(/(<\/?[a-zA-Z][^>]*>)/);for(const d of c)d.trim()&&(d.match(/^<\/[a-zA-Z]/)?(s=Math.max(0,s-1),r+=`
512
+ `+" ".repeat(s*a)+d):d.match(/^<[a-zA-Z]/)&&!d.match(/\/>$/)?(r+=`
513
+ `+" ".repeat(s*a)+d,s++):d.match(/^<[a-zA-Z].*\/>$/)?r+=`
514
+ `+" ".repeat(s*a)+d:r+=d.trim());return r.trim()};return(()=>{var Q,$,R,z,re,se;let n=null,r="dark",s=!1,a=!1,c=!1;const d=t,h=document.createElement("div");h.className="rte-source-editor-overlay";const u=document.createElement("div");u.className="rte-source-editor-modal",u.setAttribute("role","dialog"),u.setAttribute("aria-modal","true"),u.setAttribute("aria-labelledby","source-editor-title");const g=document.createElement("div");g.className="rte-source-editor-header",g.innerHTML=`
530
515
  <h2 id="source-editor-title">Source Editor</h2>
531
516
  <div class="rte-source-editor-header-toolbar">
532
517
  <button class="rte-source-editor-toolbar-btn theme-toggle-btn" title="Switch theme">
@@ -562,7 +547,7 @@
562
547
  </svg>
563
548
  </button>
564
549
  </div>
565
- `;const m=document.createElement("div");m.className="rte-source-editor-body";const f=document.createElement("div");f.className="rte-source-editor-content";const F=document.createElement("div");F.className="rte-source-editor-warning",F.textContent="⚠️ Advanced users only. Invalid HTML may break the editor.";const v=document.createElement("div");v.className="rte-source-editor-light-editor",v.style.height="400px",f.appendChild(F),f.appendChild(v),m.appendChild(f);const w=document.createElement("div");if(w.className="rte-source-editor-footer",w.innerHTML=`
550
+ `;const p=document.createElement("div");p.className="rte-source-editor-body";const f=document.createElement("div");f.className="rte-source-editor-content";const m=document.createElement("div");m.className="rte-source-editor-warning",m.textContent="⚠️ Advanced users only. Invalid HTML may break the editor.";const x=document.createElement("div");x.className="rte-source-editor-light-editor",x.style.height="400px",f.appendChild(m),f.appendChild(x),p.appendChild(f);const y=document.createElement("div");if(y.className="rte-source-editor-footer",y.innerHTML=`
566
551
  <div class="rte-source-editor-footer-info">
567
552
  <span class="unsaved-changes" style="display: none;">• Unsaved changes</span>
568
553
  </div>
@@ -570,22 +555,22 @@
570
555
  <button class="rte-source-editor-btn rte-source-editor-btn-cancel">Cancel</button>
571
556
  <button class="rte-source-editor-btn rte-source-editor-btn-save">Save</button>
572
557
  </div>
573
- `,u.appendChild(g),u.appendChild(m),u.appendChild(w),c.appendChild(u),!document.getElementById("rte-source-editor-styles")){const p=document.createElement("style");p.id="rte-source-editor-styles",p.textContent=ze,document.head.appendChild(p)}document.body.appendChild(c);try{i=Ae(v,{value:o(t),theme:"dark",readOnly:!1,extensions:[new Se,new Pe,new Ie,new Oe,new He,new Ne,new Be]}),i.on("change",()=>{h=((i==null?void 0:i.getValue())||"")!==o(d);const k=w.querySelector(".unsaved-changes");k&&(k.style.display=h?"inline":"none")}),setTimeout(()=>i==null?void 0:i.focus(),100)}catch(p){console.error("Failed to initialize code editor:",p)}const $e=()=>{r=r==="dark"?"light":"dark",i==null||i.setTheme(r);const p=g.querySelector(".theme-toggle-btn");p&&r==="light"&&(p.innerHTML=`
558
+ `,u.appendChild(g),u.appendChild(p),u.appendChild(y),h.appendChild(u),!document.getElementById("rte-source-editor-styles")){const b=document.createElement("style");b.id="rte-source-editor-styles",b.textContent=je,document.head.appendChild(b)}document.body.appendChild(h);try{n=Ue(x,{value:o(t),theme:"dark",readOnly:!1,extensions:[new Be,new Ne,new $e,new ze,new Re,new _e,new De]}),n.on("change",()=>{c=((n==null?void 0:n.getValue())||"")!==o(d);const L=y.querySelector(".unsaved-changes");L&&(L.style.display=c?"inline":"none")}),setTimeout(()=>n==null?void 0:n.focus(),100)}catch(b){console.error("Failed to initialize code editor:",b)}const v=()=>{r=r==="dark"?"light":"dark",n==null||n.setTheme(r);const b=g.querySelector(".theme-toggle-btn");b&&r==="light"&&(b.innerHTML=`
574
559
  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
575
560
  <path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>
576
561
  </svg>
577
- `)},je=()=>{a=!a,i==null||i.setReadOnly(a);const p=g.querySelector(".readonly-toggle-btn");p&&(a?(p.classList.add("active"),p.innerHTML=`
562
+ `)},H=()=>{s=!s,n==null||n.setReadOnly(s);const b=g.querySelector(".readonly-toggle-btn");b&&(s?(b.classList.add("active"),b.innerHTML=`
578
563
  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
579
564
  <rect x="3" y="11" width="18" height="11" rx="2" ry="2"/>
580
565
  <circle cx="12" cy="16" r="1"/>
581
566
  <path d="M7 11V7a5 5 0 0 1 10 0v4"/>
582
567
  </svg>
583
- `):(p.classList.remove("active"),p.innerHTML=`
568
+ `):(b.classList.remove("active"),b.innerHTML=`
584
569
  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
585
570
  <path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/>
586
571
  <path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>
587
572
  </svg>
588
- `))},Fe=()=>{l=!l,l?(c.classList.add("fullscreen"),v.style.height="calc(100vh - 200px)"):(c.classList.remove("fullscreen"),v.style.height="400px");const p=g.querySelector(".rte-source-editor-fullscreen-btn");p&&(p.innerHTML=l?`
573
+ `))},I=()=>{a=!a,a?(h.classList.add("fullscreen"),x.style.height="calc(100vh - 200px)"):(h.classList.remove("fullscreen"),x.style.height="400px");const b=g.querySelector(".rte-source-editor-fullscreen-btn");b&&(b.innerHTML=a?`
589
574
  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
590
575
  <path d="M8 3v3a2 2 0 0 1-2 2H3m18 0h-3a2 2 0 0 1-2-2V3m0 18v-3a2 2 0 0 0 2-2h3M3 16h3a2 2 0 0 0 2 2v3"/>
591
576
  </svg>
@@ -593,5 +578,5 @@
593
578
  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
594
579
  <path d="M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"/>
595
580
  </svg>
596
- `)},M=()=>{i&&(i.destroy(),i=null),document.body.removeChild(c)},qe=()=>{h&&!confirm("You have unsaved changes. Are you sure you want to cancel?")||M()},Ke=()=>{try{const p=(i==null?void 0:i.getValue())||"",k=document.createElement("div");k.innerHTML=p,k.querySelectorAll('script, iframe[src^="javascript:"], object, embed').forEach(Ve=>Ve.remove()),e.innerHTML=k.innerHTML,h=!1,M()}catch(p){alert("Failed to update HTML. Please check your syntax."),console.error("HTML update error:",p)}};(X=g.querySelector(".theme-toggle-btn"))==null||X.addEventListener("click",$e),(Y=g.querySelector(".readonly-toggle-btn"))==null||Y.addEventListener("click",je),(Q=g.querySelector(".rte-source-editor-fullscreen-btn"))==null||Q.addEventListener("click",Fe),(J=g.querySelector(".rte-source-editor-close-btn"))==null||J.addEventListener("click",M),(ee=w.querySelector(".rte-source-editor-btn-cancel"))==null||ee.addEventListener("click",qe),(te=w.querySelector(".rte-source-editor-btn-save"))==null||te.addEventListener("click",Ke),c.addEventListener("click",p=>{p.target===c&&M()});const G=p=>{p.key==="Escape"&&(M(),document.removeEventListener("keydown",G))};document.addEventListener("keydown",G)})(),!0}},keymap:{"Mod-Shift-s":"toggleSourceView","Mod-Shift-S":"toggleSourceView"}})},Symbol.toStringTag,{value:"Module"})),N=()=>(document.execCommand("insertUnorderedList",!1),!0),B=()=>(document.execCommand("insertOrderedList",!1),!0),V=(s,e)=>{var t;typeof window!="undefined"&&((t=window.registerEditorCommand)==null||t.call(window,s,e))},Z=()=>{V("toggleBulletList",N),V("toggleOrderedList",B)};typeof window!="undefined"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",Z):Z());const De=Object.freeze(Object.defineProperty({__proto__:null,ListPlugin:()=>({name:"list",nodes:{bulletList:{content:"listItem+",group:"block",parseDOM:[{tag:"ul"}],toDOM:()=>["ul",0]},orderedList:{content:"listItem+",group:"block",parseDOM:[{tag:"ol"}],toDOM:()=>["ol",0]},listItem:{content:"paragraph",parseDOM:[{tag:"li"}],toDOM:()=>["li",0]}},toolbar:[{label:"Bullet List",command:"toggleBulletList",type:"button",icon:'<svg width="24" height="24" focusable="false"><path d="M11 5h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2Zm0 6h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2Zm0 6h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2ZM4.5 6c0 .4.1.8.4 1 .3.4.7.5 1.1.5.4 0 .8-.1 1-.4.4-.3.5-.7.5-1.1 0-.4-.1-.8-.4-1-.3-.4-.7-.5-1.1-.5-.4 0-.8.1-1 .4-.4.3-.5.7-.5 1.1Zm0 6c0 .4.1.8.4 1 .3.4.7.5 1.1.5.4 0 .8-.1 1-.4.4-.3.5-.7.5-1.1 0-.4-.1-.8-.4-1-.3-.4-.7-.5-1.1-.5-.4 0-.8.1-1 .4-.4.3-.5.7-.5 1.1Zm0 6c0 .4.1.8.4 1 .3.4.7.5 1.1.5.4 0 .8-.1 1-.4.4-.3.5-.7.5-1.1 0-.4-.1-.8-.4-1-.3-.4-.7-.5-1.1-.5-.4 0-.8.1-1 .4-.4.3-.5.7-.5 1.1Z" fill-rule="evenodd"></path></svg>',shortcut:"Mod-Shift-8"},{label:"Numbered List",command:"toggleOrderedList",type:"button",icon:'<svg width="24" height="24" focusable="false"><path d="M10 17h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2Zm0-6h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2Zm0-6h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 1 1 0-2ZM6 4v3.5c0 .3-.2.5-.5.5a.5.5 0 0 1-.5-.5V5h-.5a.5.5 0 0 1 0-1H6Zm-1 8.8l.2.2h1.3c.3 0 .5.2.5.5s-.2.5-.5.5H4.9a1 1 0 0 1-.9-1V13c0-.4.3-.8.6-1l1.2-.4.2-.3a.2.2 0 0 0 0-.2l-.7.3a.5.5 0 0 1-.7-.3.5.5 0 0 1 .3-.6l.7-.4c.5-.2 1.1 0 1.4.4.3.5.3 1.1-.1 1.5l-1.2.7Zm0 3.7v.5c0 .3.2.5.5.5h1c.3 0 .5.2.5.5s-.2.5-.5.5h-1a1.5 1.5 0 0 1-1.5-1.5v-.5c0-.3.1-.6.3-.8l1.3-1.4c.3-.4.1-.9-.2-1-.1 0-.2 0-.3.2l-.4.5a.5.5 0 0 1-.7.1.5.5 0 0 1-.1-.7l.4-.5c.5-.5 1.2-.6 1.8-.4.6.3 1 .9 1 1.6 0 .4-.2.8-.5 1.1l-1.3 1.4-.3.4Z" fill-rule="evenodd"></path></svg>',shortcut:"Mod-Shift-7"}],commands:{toggleBulletList:N,toggleOrderedList:B},keymap:{"Mod-Shift-8":"toggleBulletList","Mod-Shift-7":"toggleOrderedList"}}),toggleBulletList:N,toggleOrderedList:B},Symbol.toStringTag,{value:"Module"})),E=[],L=[],S={},x=(s,e)=>{S[s]=e,typeof window!="undefined"&&(window.registerEditorCommand||(window.registerEditorCommand=(t,o)=>{S[t]=o}),window.registerEditorCommand(s,e))},_e=(s,...e)=>{S[s]&&S[s](...e)},A=()=>(document.execCommand("undo",!1),!0),z=()=>(document.execCommand("redo",!1),!0),R=(s,e,t)=>{const o=s.getAttribute(e);s.setAttribute(e,t),E.push(()=>{o==null?s.removeAttribute(e):s.setAttribute(e,o)}),L.length=0},D=(s,e)=>{const t=s.textContent;s.textContent=e,E.push(()=>{s.textContent=t!=null?t:""}),L.length=0},_=s=>{var n;const e=s.element;if(!e)return;const t=(n=window.a11yRuleRegistry)==null?void 0:n.find(i=>i.id===s.rule);let o=null;if(t&&t.fix){const i={};for(const r of e.getAttributeNames())i[r]=e.getAttribute(r);t.fix(s),o=()=>{for(const r of Object.keys(i))i[r]==null?e.removeAttribute(r):e.setAttribute(r,i[r])}}o&&E.push(o),L.length=0},U=()=>{const s=E.pop();s&&(s(),L.push(s))},$=()=>{const s=L.pop();s&&(s(),E.push(s))},W=()=>{typeof window!="undefined"&&(window.execEditorCommand||(window.execEditorCommand=_e),x("undo",A),x("redo",z),x("setAttribute",R),x("setText",D),x("autoFixA11y",_),x("undoDom",U),x("redoDom",$))};typeof window!="undefined"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",W):W());const Ue=Object.freeze(Object.defineProperty({__proto__:null,HistoryPlugin:()=>({name:"history",toolbar:[{label:"Undo",command:"undo",type:"button",icon:'<svg width="24" height="24" focusable="false"><path d="M6.4 8H12c3.7 0 6.2 2 6.8 5.1.6 2.7-.4 5.6-2.3 6.8a1 1 0 0 1-1-1.8c1.1-.6 1.8-2.7 1.4-4.6-.5-2.1-2.1-3.5-4.9-3.5H6.4l3.3 3.3a1 1 0 1 1-1.4 1.4l-5-5a1 1 0 0 1 0-1.4l5-5a1 1 0 0 1 1.4 1.4L6.4 8Z" fill-rule="nonzero"></path></svg>',shortcut:"Mod-z"},{label:"Redo",command:"redo",type:"button",icon:'<svg width="24" height="24" focusable="false"><path d="M17.6 10H12c-2.8 0-4.4 1.4-4.9 3.5-.4 2 .3 4 1.4 4.6a1 1 0 1 1-1 1.8c-2-1.2-2.9-4.1-2.3-6.8.6-3 3-5.1 6.8-5.1h5.6l-3.3-3.3a1 1 0 1 1 1.4-1.4l5 5a1 1 0 0 1 0 1.4l-5 5a1 1 0 0 1-1.4-1.4l3.3-3.3Z" fill-rule="nonzero"></path></svg>',shortcut:"Mod-y"}],commands:{undo:A,redo:z,setAttribute:R,setText:D,autoFixA11y:_,undoDom:U,redoDom:$},keymap:{"Mod-z":"undo","Mod-Z":"undo","Mod-y":"redo","Mod-Y":"redo","Mod-Shift-z":"redo","Mod-Shift-Z":"redo"}}),autoFixA11y:_,redo:z,redoDom:$,setAttribute:R,setText:D,undo:A,undoDom:U},Symbol.toStringTag,{value:"Module"}));y.initWebComponent=q,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})}));
581
+ `)},w=()=>{n&&(n.destroy(),n=null),document.body.removeChild(h)},k=()=>{c&&!confirm("You have unsaved changes. Are you sure you want to cancel?")||w()},C=()=>{try{const b=(n==null?void 0:n.getValue())||"",L=document.createElement("div");L.innerHTML=b,L.querySelectorAll('script, iframe[src^="javascript:"], object, embed').forEach(We=>We.remove()),e.innerHTML=L.innerHTML,c=!1,w()}catch(b){alert("Failed to update HTML. Please check your syntax."),console.error("HTML update error:",b)}};(Q=g.querySelector(".theme-toggle-btn"))==null||Q.addEventListener("click",v),($=g.querySelector(".readonly-toggle-btn"))==null||$.addEventListener("click",H),(R=g.querySelector(".rte-source-editor-fullscreen-btn"))==null||R.addEventListener("click",I),(z=g.querySelector(".rte-source-editor-close-btn"))==null||z.addEventListener("click",w),(re=y.querySelector(".rte-source-editor-btn-cancel"))==null||re.addEventListener("click",k),(se=y.querySelector(".rte-source-editor-btn-save"))==null||se.addEventListener("click",C),h.addEventListener("click",b=>{b.target===h&&w()});const A=b=>{b.key==="Escape"&&(w(),document.removeEventListener("keydown",A))};document.addEventListener("keydown",A)})(),!0}},keymap:{"Mod-Shift-s":"toggleSourceView","Mod-Shift-S":"toggleSourceView"}})},Symbol.toStringTag,{value:"Module"})),F=()=>(document.execCommand("insertUnorderedList",!1),!0),V=()=>(document.execCommand("insertOrderedList",!1),!0),oe=(l,e)=>{var t;typeof window!="undefined"&&((t=window.registerEditorCommand)==null||t.call(window,l,e))},ie=()=>{oe("toggleBulletList",F),oe("toggleOrderedList",V)};typeof window!="undefined"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",ie):ie());const Ve=Object.freeze(Object.defineProperty({__proto__:null,ListPlugin:()=>({name:"list",nodes:{bulletList:{content:"listItem+",group:"block",parseDOM:[{tag:"ul"}],toDOM:()=>["ul",0]},orderedList:{content:"listItem+",group:"block",parseDOM:[{tag:"ol"}],toDOM:()=>["ol",0]},listItem:{content:"paragraph",parseDOM:[{tag:"li"}],toDOM:()=>["li",0]}},toolbar:[{label:"Bullet List",command:"toggleBulletList",type:"button",icon:'<svg width="24" height="24" focusable="false"><path d="M11 5h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2Zm0 6h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2Zm0 6h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2ZM4.5 6c0 .4.1.8.4 1 .3.4.7.5 1.1.5.4 0 .8-.1 1-.4.4-.3.5-.7.5-1.1 0-.4-.1-.8-.4-1-.3-.4-.7-.5-1.1-.5-.4 0-.8.1-1 .4-.4.3-.5.7-.5 1.1Zm0 6c0 .4.1.8.4 1 .3.4.7.5 1.1.5.4 0 .8-.1 1-.4.4-.3.5-.7.5-1.1 0-.4-.1-.8-.4-1-.3-.4-.7-.5-1.1-.5-.4 0-.8.1-1 .4-.4.3-.5.7-.5 1.1Zm0 6c0 .4.1.8.4 1 .3.4.7.5 1.1.5.4 0 .8-.1 1-.4.4-.3.5-.7.5-1.1 0-.4-.1-.8-.4-1-.3-.4-.7-.5-1.1-.5-.4 0-.8.1-1 .4-.4.3-.5.7-.5 1.1Z" fill-rule="evenodd"></path></svg>',shortcut:"Mod-Shift-8"},{label:"Numbered List",command:"toggleOrderedList",type:"button",icon:'<svg width="24" height="24" focusable="false"><path d="M10 17h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2Zm0-6h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2Zm0-6h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 1 1 0-2ZM6 4v3.5c0 .3-.2.5-.5.5a.5.5 0 0 1-.5-.5V5h-.5a.5.5 0 0 1 0-1H6Zm-1 8.8l.2.2h1.3c.3 0 .5.2.5.5s-.2.5-.5.5H4.9a1 1 0 0 1-.9-1V13c0-.4.3-.8.6-1l1.2-.4.2-.3a.2.2 0 0 0 0-.2l-.7.3a.5.5 0 0 1-.7-.3.5.5 0 0 1 .3-.6l.7-.4c.5-.2 1.1 0 1.4.4.3.5.3 1.1-.1 1.5l-1.2.7Zm0 3.7v.5c0 .3.2.5.5.5h1c.3 0 .5.2.5.5s-.2.5-.5.5h-1a1.5 1.5 0 0 1-1.5-1.5v-.5c0-.3.1-.6.3-.8l1.3-1.4c.3-.4.1-.9-.2-1-.1 0-.2 0-.3.2l-.4.5a.5.5 0 0 1-.7.1.5.5 0 0 1-.1-.7l.4-.5c.5-.5 1.2-.6 1.8-.4.6.3 1 .9 1 1.6 0 .4-.2.8-.5 1.1l-1.3 1.4-.3.4Z" fill-rule="evenodd"></path></svg>',shortcut:"Mod-Shift-7"}],commands:{toggleBulletList:F,toggleOrderedList:V},keymap:{"Mod-Shift-8":"toggleBulletList","Mod-Shift-7":"toggleOrderedList"}}),toggleBulletList:F,toggleOrderedList:V},Symbol.toStringTag,{value:"Module"})),P=[],O=[],N={},T=(l,e)=>{N[l]=e,typeof window!="undefined"&&(window.registerEditorCommand||(window.registerEditorCommand=(t,o)=>{N[t]=o}),window.registerEditorCommand(l,e))},qe=(l,...e)=>{N[l]&&N[l](...e)},q=()=>(document.execCommand("undo",!1),!0),K=()=>(document.execCommand("redo",!1),!0),W=(l,e,t)=>{const o=l.getAttribute(e);l.setAttribute(e,t),P.push(()=>{o==null?l.removeAttribute(e):l.setAttribute(e,o)}),O.length=0},Z=(l,e)=>{const t=l.textContent;l.textContent=e,P.push(()=>{l.textContent=t!=null?t:""}),O.length=0},Y=l=>{var i;const e=l.element;if(!e)return;const t=(i=window.a11yRuleRegistry)==null?void 0:i.find(n=>n.id===l.rule);let o=null;if(t&&t.fix){const n={};for(const r of e.getAttributeNames())n[r]=e.getAttribute(r);t.fix(l),o=()=>{for(const r of Object.keys(n))n[r]==null?e.removeAttribute(r):e.setAttribute(r,n[r])}}o&&P.push(o),O.length=0},G=()=>{const l=P.pop();l&&(l(),O.push(l))},X=()=>{const l=O.pop();l&&(l(),P.push(l))},ne=()=>{typeof window!="undefined"&&(window.execEditorCommand||(window.execEditorCommand=qe),T("undo",q),T("redo",K),T("setAttribute",W),T("setText",Z),T("autoFixA11y",Y),T("undoDom",G),T("redoDom",X))};typeof window!="undefined"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",ne):ne());const Ke=Object.freeze(Object.defineProperty({__proto__:null,HistoryPlugin:()=>({name:"history",toolbar:[{label:"Undo",command:"undo",type:"button",icon:'<svg width="24" height="24" focusable="false"><path d="M6.4 8H12c3.7 0 6.2 2 6.8 5.1.6 2.7-.4 5.6-2.3 6.8a1 1 0 0 1-1-1.8c1.1-.6 1.8-2.7 1.4-4.6-.5-2.1-2.1-3.5-4.9-3.5H6.4l3.3 3.3a1 1 0 1 1-1.4 1.4l-5-5a1 1 0 0 1 0-1.4l5-5a1 1 0 0 1 1.4 1.4L6.4 8Z" fill-rule="nonzero"></path></svg>',shortcut:"Mod-z"},{label:"Redo",command:"redo",type:"button",icon:'<svg width="24" height="24" focusable="false"><path d="M17.6 10H12c-2.8 0-4.4 1.4-4.9 3.5-.4 2 .3 4 1.4 4.6a1 1 0 1 1-1 1.8c-2-1.2-2.9-4.1-2.3-6.8.6-3 3-5.1 6.8-5.1h5.6l-3.3-3.3a1 1 0 1 1 1.4-1.4l5 5a1 1 0 0 1 0 1.4l-5 5a1 1 0 0 1-1.4-1.4l3.3-3.3Z" fill-rule="nonzero"></path></svg>',shortcut:"Mod-y"}],commands:{undo:q,redo:K,setAttribute:W,setText:Z,autoFixA11y:Y,undoDom:G,redoDom:X},keymap:{"Mod-z":"undo","Mod-Z":"undo","Mod-y":"redo","Mod-Y":"redo","Mod-Shift-z":"redo","Mod-Shift-Z":"redo"}}),autoFixA11y:Y,redo:K,redoDom:X,setAttribute:W,setText:Z,undo:q,undoDom:G},Symbol.toStringTag,{value:"Module"}));E.initWebComponent=ee,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})}));
597
582
  //# sourceMappingURL=webcomponent-core.min.js.map