@editora/core 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -0
- package/dist/{A11yCheckerPlugin.native-CZKpi3uF.mjs → A11yCheckerPlugin.native-BRdGYMju.mjs} +225 -173
- package/dist/AnchorPlugin.native-C1Rw5m04.mjs +404 -0
- package/dist/BackgroundColorPlugin.native-BE-p9DRd.mjs +489 -0
- package/dist/ChecklistPlugin.native-nuSSEFNI.mjs +309 -0
- package/dist/ClearFormattingPlugin.native-Bq_XcTh2.mjs +140 -0
- package/dist/{CodePlugin.native-CK9d8rmt.mjs → CodePlugin.native-0Zari_zp.mjs} +329 -310
- package/dist/CodeSamplePlugin.native-B-KS1pOl.mjs +384 -0
- package/dist/CommentsPlugin.native-tMnWn8a2.mjs +723 -0
- package/dist/DirectionPlugin.native-CDnbdNyl.mjs +130 -0
- package/dist/{EmbedIframePlugin.native-ifr9KLdN.mjs → EmbedIframePlugin.native-CSWIB1jm.mjs} +154 -50
- package/dist/{EmojisPlugin.native-D6mJSnSR.mjs → EmojisPlugin.native-DxTm_DL-.mjs} +156 -103
- package/dist/FontFamilyPlugin.native-j8hMTbg4.mjs +158 -0
- package/dist/FontSizePlugin.native-B_jCh7dY.mjs +286 -0
- package/dist/FootnotePlugin.native-D730OGRm.mjs +425 -0
- package/dist/HistoryPlugin.native-DCrPdeSW.mjs +257 -0
- package/dist/IndentPlugin.native-BHixp8sP.mjs +150 -0
- package/dist/LineHeightPlugin.native-CM7iXdQj.mjs +151 -0
- package/dist/{LinkPlugin.native-BdAOV-iu.mjs → LinkPlugin.native-CS2g-G18.mjs} +128 -53
- package/dist/{ListPlugin.native-CLFU5AUQ.mjs → ListPlugin.native-V7EZC1lM.mjs} +59 -12
- package/dist/MathPlugin.native-KUxz0o8C.mjs +251 -0
- package/dist/MediaManagerPlugin.native-CgP5iInD.mjs +970 -0
- package/dist/MergeTagPlugin.native-CU9LtsfD.mjs +416 -0
- package/dist/PageBreakPlugin.native-CGiQxXqR.mjs +297 -0
- package/dist/{PrintPlugin.native-BUpm52VJ.mjs → PrintPlugin.native-7qt5v7L5.mjs} +10 -10
- package/dist/{SpecialCharactersPlugin.native-x7a2SWXc.mjs → SpecialCharactersPlugin.native-DANrbExJ.mjs} +143 -97
- package/dist/SpellCheckPlugin.native-C8bPvRHy.mjs +1019 -0
- package/dist/StrikethroughPlugin.native-0Be7j49s.mjs +73 -0
- package/dist/{TablePlugin.native-EEWXn1-s.mjs → TablePlugin.native-DrHX-efe.mjs} +149 -145
- package/dist/TemplatePlugin.native-4lKEm-WY.mjs +578 -0
- package/dist/TextAlignmentPlugin.native-sM_1s00t.mjs +108 -0
- package/dist/{TextColorPlugin.native-D6SmTglm.mjs → TextColorPlugin.native-Clgtb50j.mjs} +173 -92
- package/dist/colorSelectionApply-CK1My9N2.mjs +67 -0
- package/dist/core.css +1 -1
- package/dist/editora.min.js +31 -29
- package/dist/editora.umd.js +31 -29
- package/dist/index-CqWQFb3D.js +10 -0
- package/dist/index-OwnkG39N.mjs +2227 -0
- package/dist/index.cjs.js +14 -18
- package/dist/index.esm.js +204 -521
- package/dist/plugin-loader.js +26 -26
- package/dist/webcomponent-core.js +1286 -295
- package/dist/webcomponent-core.min.css +1 -1
- package/dist/webcomponent-core.min.js +100 -75
- package/dist/webcomponent.cjs.js +1 -1
- package/dist/webcomponent.esm.js +1 -1
- package/dist/webcomponent.js +1252 -261
- package/dist/webcomponent.min.css +1 -1
- package/dist/webcomponent.min.js +3616 -2109
- package/index.d.ts +355 -0
- package/package.json +19 -17
- package/dist/A11yCheckerPlugin.native-CZKpi3uF.mjs.map +0 -1
- package/dist/AnchorPlugin.native-7es9PVZ9.mjs +0 -340
- package/dist/AnchorPlugin.native-7es9PVZ9.mjs.map +0 -1
- package/dist/BackgroundColorPlugin.native-Dip5uqTg.mjs +0 -449
- package/dist/BackgroundColorPlugin.native-Dip5uqTg.mjs.map +0 -1
- package/dist/BlockquotePlugin.native-JFmOLsxN.mjs.map +0 -1
- package/dist/BoldPlugin.native-BAzzoqU5.mjs.map +0 -1
- package/dist/CapitalizationPlugin.native-DOMsh5R7.mjs.map +0 -1
- package/dist/ChecklistPlugin.native-Dccs3nLe.mjs +0 -153
- package/dist/ChecklistPlugin.native-Dccs3nLe.mjs.map +0 -1
- package/dist/ClearFormattingPlugin.native-BZPDHswo.mjs +0 -27
- package/dist/ClearFormattingPlugin.native-BZPDHswo.mjs.map +0 -1
- package/dist/CodePlugin.native-CK9d8rmt.mjs.map +0 -1
- package/dist/CodeSamplePlugin.native-DMbEdO9j.mjs +0 -326
- package/dist/CodeSamplePlugin.native-DMbEdO9j.mjs.map +0 -1
- package/dist/CommentsPlugin.native-2zQV8Ia4.mjs +0 -473
- package/dist/CommentsPlugin.native-2zQV8Ia4.mjs.map +0 -1
- package/dist/DirectionPlugin.native-Be7wCzkI.mjs +0 -59
- package/dist/DirectionPlugin.native-Be7wCzkI.mjs.map +0 -1
- package/dist/DocumentManagerPlugin.native-BvZL5CSG.mjs.map +0 -1
- package/dist/EmbedIframePlugin.native-ifr9KLdN.mjs.map +0 -1
- package/dist/EmojisPlugin.native-D6mJSnSR.mjs.map +0 -1
- package/dist/FontFamilyPlugin.native-BzS_9qbM.mjs +0 -106
- package/dist/FontFamilyPlugin.native-BzS_9qbM.mjs.map +0 -1
- package/dist/FontSizePlugin.native-DkLMLPue.mjs +0 -186
- package/dist/FontSizePlugin.native-DkLMLPue.mjs.map +0 -1
- package/dist/FootnotePlugin.native-BciVc9W6.mjs +0 -128
- package/dist/FootnotePlugin.native-BciVc9W6.mjs.map +0 -1
- package/dist/FullscreenPlugin.native-ChXyxeNw.mjs.map +0 -1
- package/dist/HeadingPlugin.native-DrLYwQnQ.mjs.map +0 -1
- package/dist/HistoryPlugin.native-DoDRifCf.mjs +0 -89
- package/dist/HistoryPlugin.native-DoDRifCf.mjs.map +0 -1
- package/dist/IndentPlugin.native-CbFugPoi.mjs +0 -133
- package/dist/IndentPlugin.native-CbFugPoi.mjs.map +0 -1
- package/dist/ItalicPlugin.native-CQjjDyUL.mjs.map +0 -1
- package/dist/LineHeightPlugin.native-CWQT2FIa.mjs +0 -73
- package/dist/LineHeightPlugin.native-CWQT2FIa.mjs.map +0 -1
- package/dist/LinkPlugin.native-BdAOV-iu.mjs.map +0 -1
- package/dist/ListPlugin.native-CLFU5AUQ.mjs.map +0 -1
- package/dist/MathPlugin.native-DE_ii-LA.mjs +0 -182
- package/dist/MathPlugin.native-DE_ii-LA.mjs.map +0 -1
- package/dist/MediaManagerPlugin.native-DaYFDzNM.mjs +0 -533
- package/dist/MediaManagerPlugin.native-DaYFDzNM.mjs.map +0 -1
- package/dist/MergeTagPlugin.native-CrxyThyn.mjs +0 -178
- package/dist/MergeTagPlugin.native-CrxyThyn.mjs.map +0 -1
- package/dist/PageBreakPlugin.native-DDjcDyRW.mjs +0 -172
- package/dist/PageBreakPlugin.native-DDjcDyRW.mjs.map +0 -1
- package/dist/PreviewPlugin.native-DBvfpmIv.mjs.map +0 -1
- package/dist/PrintPlugin.native-BUpm52VJ.mjs.map +0 -1
- package/dist/SpecialCharactersPlugin.native-x7a2SWXc.mjs.map +0 -1
- package/dist/SpellCheckPlugin.native-B7yTh0iE.mjs +0 -465
- package/dist/SpellCheckPlugin.native-B7yTh0iE.mjs.map +0 -1
- package/dist/StrikethroughPlugin.native-ChaZLaXw.mjs +0 -43
- package/dist/StrikethroughPlugin.native-ChaZLaXw.mjs.map +0 -1
- package/dist/TablePlugin.native-EEWXn1-s.mjs.map +0 -1
- package/dist/TemplatePlugin.native-BlSn1c9h.mjs +0 -564
- package/dist/TemplatePlugin.native-BlSn1c9h.mjs.map +0 -1
- package/dist/TextAlignmentPlugin.native-CQIs1m7R.mjs +0 -97
- package/dist/TextAlignmentPlugin.native-CQIs1m7R.mjs.map +0 -1
- package/dist/TextColorPlugin.native-D6SmTglm.mjs.map +0 -1
- package/dist/UnderlinePlugin.native-QpIcK4L2.mjs.map +0 -1
- package/dist/documentManager-irzj9n3V.mjs.map +0 -1
- package/dist/editorContainerHelpers-C7kdWnS0.mjs.map +0 -1
- package/dist/editora.min.js.map +0 -1
- package/dist/editora.umd.js.map +0 -1
- package/dist/index-BF5RBhL9.js +0 -4
- package/dist/index-BF5RBhL9.js.map +0 -1
- package/dist/index-BPsf460l.mjs +0 -1243
- package/dist/index-BPsf460l.mjs.map +0 -1
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.es-CuicffkQ.mjs.map +0 -1
- package/dist/index.esm.js.map +0 -1
- package/dist/plugin-loader.js.map +0 -1
- package/dist/purify.es-CKpwg8Tk.mjs.map +0 -1
- package/dist/webcomponent-core.js.map +0 -1
- package/dist/webcomponent-core.min.js.map +0 -1
- package/dist/webcomponent.cjs.js.map +0 -1
- package/dist/webcomponent.esm.js.map +0 -1
- package/dist/webcomponent.js.map +0 -1
- package/dist/webcomponent.min.js.map +0 -1
|
@@ -1,10 +1,16 @@
|
|
|
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
|
-
`),
|
|
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(`
|
|
1
|
+
(function(T,L){typeof exports=="object"&&typeof module!="undefined"?L(exports):typeof define=="function"&&define.amd?define(["exports"],L):(T=typeof globalThis!="undefined"?globalThis:T||self,L(T.EditoraCore={}))})(this,(function(T){"use strict";class L{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 D{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 D(o,{anchor:0,head:0},e)}apply(e,t){return new D(e,t||this.selection,this.schema)}}class He{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){this.plugins.push(e),t&&this.pluginConfigs.set(e.name,t);const o=this.pluginConfigs.get(e.name)||e.config;if(e.initialize)try{e.initialize(o)}catch(i){console.error(`Failed to initialize plugin "${e.name}":`,i)}if(e.init&&e.init!==e.initialize)try{e.init(o)}catch(i){console.error(`Failed to run init hook for plugin "${e.name}":`,i)}}unregister(e){const t=this.plugins.findIndex(o=>o.name===e);if(t>-1){const o=this.plugins[t];o.destroy&&o.destroy(),this.plugins.splice(t,1),this.pluginConfigs.delete(e)}}getPlugin(e){return this.plugins.find(t=>t.name===e)}getPluginConfig(e){return this.pluginConfigs.get(e)}buildSchema(){const e={},t={};return this.plugins.forEach(o=>{o.nodes&&Object.assign(e,o.nodes),o.marks&&Object.assign(t,o.marks)}),new He(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||{},s=n.mode||"local";try{switch(s){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(a){if(console.warn(`API execution failed for ${e}, falling back to local`,a),i.executeLocal&&n.fallbackToLocal!==!1)return i.executeLocal(t,...o);throw a}break;default:throw new Error(`Unknown plugin mode: ${s}`)}}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 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 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=D.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 instanceof Promise?(i.then(n=>{n&&typeof n=="object"&&"doc"in n&&"selection"in n&&(this.setState(n),this.emit("change",this.state))}).catch(n=>{console.error(`Async command failed: ${e}`,n)}),!0):i&&typeof i=="object"&&"doc"in i&&"selection"in i?(this.setState(i),this.emit("change",this.state),!0):i!==!1&&i!=null}setState(e){this.isDestroyed||(this.state=e,this.emit("stateChange",e))}getState(){return this.state}setReadonly(e){this.isReadonly=e,this.emit("readonlyChange",e)}isReadOnly(){return this.isReadonly}on(e,t){return this.listeners.has(e)||this.listeners.set(e,[]),this.listeners.get(e).push(t),()=>{const o=this.listeners.get(e);if(o){const i=o.indexOf(t);i>-1&&o.splice(i,1)}}}emit(e,...t){const o=this.listeners.get(e);o&&o.forEach(i=>{try{i(...t)}catch(n){console.error(`Error in ${e} handler:`,n)}})}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.listeners.clear(),this.emit("destroy"))}isEditorDestroyed(){return this.isDestroyed}}class Be{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()),i=this.getAvailableToolbarItems(),n=new Map;i.forEach(a=>{a.command&&n.set(a.command,a),a.type==="group"&&a.label&&n.set(a.label,a)});const s={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 f=n.get("setDirectionLTR"),h=n.get("setDirectionRTL");f&&l.push({id:"directionLTR",label:f.label,command:f.command,icon:f.icon,type:f.type||"button",options:f.options}),h&&l.push({id:"directionRTL",label:h.label,command:h.command,icon:h.icon,type:h.type||"button",options:h.options});return}if(d==="comments"){const f=n.get("addComment"),h=n.get("toggleComments");f&&l.push({id:"addComment",label:f.label,command:f.command,icon:f.icon,type:f.type||"button",options:f.options}),h&&l.push({id:"toggleComments",label:h.label,command:h.command,icon:h.icon,type:h.type||"button",options:h.options});return}const g=s[d]||d;let u=n.get(g);u||(u=n.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((i,n)=>{const s=document.createElement("div");if(s.className="editora-toolbar-group",i.forEach(a=>{this.appendToolbarButton(s,a)}),e.appendChild(s),n<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(i=>{this.appendToolbarButton(o,i)}),t.appendChild(o)}return t}createInput(e){const t=document.createElement("input");return t.className=`editora-toolbar-input ${e.label.toLowerCase().replace(/\s+/g,"-")}`,t.type="text",t.title=e.label,t.placeholder=e.placeholder||"",e.command&&t.setAttribute("data-command",e.command),e.active&&t.classList.add("active"),e.disabled&&(t.disabled=!0),t.addEventListener("click",o=>{o.preventDefault(),this.commandHandler&&e.command&&this.commandHandler(e.command)}),t}createButton(e){const t=document.createElement("button");if(t.className="editora-toolbar-button",t.type="button",t.title=e.label,e.command&&t.setAttribute("data-command",e.command),e.icon)if(e.icon.startsWith("<svg")&&e.icon.endsWith("</svg>")){const o=document.createElement("span");o.className="editora-toolbar-icon",o.innerHTML=e.icon,t.appendChild(o)}else t.innerHTML=e.icon;else t.textContent=e.label;return e.active&&t.classList.add("active"),e.disabled&&(t.disabled=!0),t.addEventListener("click",o=>{o.preventDefault(),this.commandHandler&&e.command&&this.commandHandler(e.command)}),t}createDropdown(e){const t=document.createElement("div");t.className="editora-toolbar-dropdown";const o=document.createElement("button");o.className="editora-toolbar-button editora-toolbar-dropdown-trigger",o.type="button",o.textContent=e.label;const i=document.createElement("div");i.className="editora-toolbar-dropdown-menu",i.style.display="none",e.options&&e.options.forEach(s=>{const a=document.createElement("button");a.className="editora-toolbar-dropdown-item",a.type="button",a.textContent=s.label,a.setAttribute("data-value",s.value),a.addEventListener("click",l=>{l.preventDefault(),this.commandHandler&&e.command&&this.commandHandler(e.command,s.value),i.style.display="none"}),i.appendChild(a)}),o.addEventListener("click",s=>{s.preventDefault(),s.stopPropagation();const a=i.style.display==="block";i.style.display=a?"none":"block"});const n=s=>{t.contains(s.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 s=document.createElement("button");s.className="editora-toolbar-dropdown-item",s.type="button",s.textContent=n.label,s.setAttribute("data-value",n.value),s.addEventListener("click",a=>{a.preventDefault(),a.stopPropagation(),this.commandHandler&&e.command&&this.commandHandler(e.command,n.value),i.style.display="none"}),i.appendChild(s)}),o.addEventListener("click",n=>{var a;n.preventDefault(),n.stopPropagation();const s=(a=this.container)==null?void 0:a.querySelectorAll(".editora-toolbar-dropdown-menu");s==null||s.forEach(l=>{l!==i&&(l.style.display="none")}),i.style.display=i.style.display==="none"?"block":"none"}),document.addEventListener("click",n=>{t.contains(n.target)||(i.style.display="none")}),t.appendChild(o),t.appendChild(i),t}getDefaultToolbarString(){return this.getAvailableToolbarItems().map(t=>t.command).join(" ")}updateButtonState(e,t){if(!this.container)return;const o=this.container.querySelector(`[data-command="${e}"]`);o&&(t.active!==void 0&&o.classList.toggle("active",t.active),t.disabled!==void 0&&(o.disabled=t.disabled))}destroy(){this.container&&(this.container.querySelectorAll(".editora-toolbar-dropdown").forEach(t=>{const o=t._cleanupDropdown;o&&o()}),this.container.innerHTML=""),this.commandHandler=void 0}}class ze{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 $e{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,s])=>{i.push(`${n}: ${s}`)}),o.forEach((n,s)=>{const a=document.createElement("span");if(a.className="editora-statusbar-item",a.textContent=n,e.appendChild(a),s<o.length-1){const l=document.createElement("span");l.className="editora-statusbar-separator",l.textContent="|",e.appendChild(l)}}),i.forEach((n,s)=>{const a=document.createElement("span");if(a.className="editora-statusbar-item",a.textContent=n,t.appendChild(a),s<i.length-1){const l=document.createElement("span");l.className="editora-statusbar-separator",l.textContent="|",t.appendChild(l)}}),this.container.appendChild(e),this.container.appendChild(t)}destroy(){this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container),this.container=void 0}}function _e(r,e){const t=r.textContent||"",o=je(r,e.startContainer,e.startOffset),n=t.substring(0,o).split(`
|
|
2
|
+
`),s=n.length,a=n[n.length-1].length+1;return{line:s,column:a}}function je(r,e,t){var s;let o=0;const i=document.createTreeWalker(r,NodeFilter.SHOW_TEXT,null);let n=i.firstChild();for(;n;){if(n===e){o+=t;break}else n.nodeType===Node.TEXT_NODE&&(o+=((s=n.textContent)==null?void 0:s.length)||0);n=i.nextNode()}return o}function Fe(r){var o,i;const e=r.querySelectorAll("div, p, br, h1, h2, h3, h4, h5, h6, blockquote, li, pre");let t=1;if(e.length>0){t=e.length;const 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 s=(r.textContent||"").split(`
|
|
3
|
+
`).length;t=Math.max(1,s)}return t}function Ue(r){const e=r.trim()?r.trim().split(/\s+/).length:0,t=r.length;return{words:e,chars:t}}function Ke(r,e){const t=r.toString();return{startLine:e.line,startColumn:e.column,endLine:e.line,endColumn:e.column+t.length,selectedChars:t.length,selectedWords:t.trim().split(/\s+/).filter(Boolean).length}}class qe{constructor(e){this.shortcuts=new Map,this.enabled=!0,this.isMac=typeof navigator!="undefined"&&navigator.platform.toUpperCase().indexOf("MAC")>=0,(e==null?void 0:e.enabled)===!1&&(this.enabled=!1),this.registerDefaultShortcuts(),e!=null&&e.shortcuts&&e.shortcuts.forEach(t=>this.registerShortcut(t)),e!=null&&e.customShortcuts&&Object.values(e.customShortcuts).forEach(t=>{this.registerShortcut(t)})}registerDefaultShortcuts(){this.registerShortcut({key:"b",ctrl:!this.isMac,meta:this.isMac,command:"toggleBold",description:"Bold",preventDefault:!0}),this.registerShortcut({key:"i",ctrl:!this.isMac,meta:this.isMac,command:"toggleItalic",description:"Italic",preventDefault:!0}),this.registerShortcut({key:"u",ctrl:!this.isMac,meta:this.isMac,command:"toggleUnderline",description:"Underline",preventDefault:!0}),this.registerShortcut({key:"d",ctrl:!this.isMac,meta:this.isMac,command:"toggleStrikethrough",description:"Strikethrough",preventDefault:!0}),this.registerShortcut({key:"z",ctrl:!this.isMac,meta:this.isMac,command:"undo",description:"Undo",preventDefault:!0}),this.registerShortcut({key:"z",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"redo",description:"Redo",preventDefault:!0}),this.registerShortcut({key:"y",ctrl:!this.isMac,meta:this.isMac,command:"redo",description:"Redo",preventDefault:!0});for(let e=1;e<=6;e++)this.registerShortcut({key:String(e),ctrl:!this.isMac,meta:this.isMac,alt:!0,command:"setBlockType",params:`h${e}`,description:`Heading ${e}`,preventDefault:!0});this.registerShortcut({key:"7",ctrl:!this.isMac,meta:this.isMac,alt:!0,command:"setBlockType",params:"p",description:"Paragraph",preventDefault:!0}),this.registerShortcut({key:"7",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"toggleOrderedList",description:"Numbered List",preventDefault:!0}),this.registerShortcut({key:"8",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"toggleBulletList",description:"Bullet List",preventDefault:!0}),this.registerShortcut({key:"k",ctrl:!this.isMac,meta:this.isMac,command:"openLinkDialog",description:"Insert/Edit Link",preventDefault:!0}),this.registerShortcut({key:"e",ctrl:!this.isMac,meta:this.isMac,alt:!0,command:"insertCodeBlock",description:"Code Block",preventDefault:!0}),this.registerShortcut({key:"q",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"toggleBlockquote",description:"Blockquote",preventDefault:!0}),this.registerShortcut({key:"l",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"setTextAlignment",params:"left",description:"Align Left",preventDefault:!0}),this.registerShortcut({key:"e",ctrl:!this.isMac,meta:this.isMac,shift:!0,alt:!0,command:"setTextAlignment",params:"center",description:"Align Center",preventDefault:!0}),this.registerShortcut({key:"r",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"setTextAlignment",params:"right",description:"Align Right",preventDefault:!0}),this.registerShortcut({key:"j",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"setTextAlignment",params:"justify",description:"Justify",preventDefault:!0}),this.registerShortcut({key:"\\",ctrl:!this.isMac,meta:this.isMac,command:"clearFormatting",description:"Clear Formatting",preventDefault:!0}),this.registerShortcut({key:"]",ctrl:!this.isMac,meta:this.isMac,command:"increaseIndent",description:"Indent",preventDefault:!0}),this.registerShortcut({key:"[",ctrl:!this.isMac,meta:this.isMac,command:"decreaseIndent",description:"Outdent",preventDefault:!0}),this.registerShortcut({key:"g",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"insertImage",description:"Insert Image",preventDefault:!0}),this.registerShortcut({key:"t",ctrl:!this.isMac,meta:this.isMac,shift:!0,alt:!0,command:"insertTable",description:"Insert Table",preventDefault:!0}),this.registerShortcut({key:"f11",command:"toggleFullscreen",description:"Toggle Fullscreen",preventDefault:!0}),this.registerShortcut({key:"p",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"togglePreview",description:"Preview",preventDefault:!0}),this.registerShortcut({key:"p",ctrl:!this.isMac,meta:this.isMac,command:"print",description:"Print",preventDefault:!0}),this.registerShortcut({key:"s",ctrl:!this.isMac,meta:this.isMac,shift:!0,alt:!0,command:"insertSpecialCharacter",description:"Insert Special Character",preventDefault:!0}),this.registerShortcut({key:"m",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"insertEmoji",description:"Insert Emoji",preventDefault:!0}),this.registerShortcut({key:"9",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"toggleChecklist",description:"Checklist",preventDefault:!0}),this.registerShortcut({key:"a",ctrl:!this.isMac,meta:this.isMac,shift:!0,alt:!0,command:"toggleA11yChecker",description:"Accessibility Checker",preventDefault:!0}),this.registerShortcut({key:"F7",command:"toggleSpellCheck",description:"Spell Check",preventDefault:!0}),this.registerShortcut({key:"m",ctrl:!this.isMac,meta:this.isMac,alt:!0,command:"insertMath",description:"Insert Math",preventDefault:!0}),this.registerShortcut({key:"f",ctrl:!this.isMac,meta:this.isMac,alt:!0,command:"insertFootnote",description:"Insert Footnote",preventDefault:!0})}registerShortcut(e){const t=this.getShortcutKey(e);this.shortcuts.set(t,e)}unregisterShortcut(e){const t=this.getShortcutKey(e);this.shortcuts.delete(t)}getShortcutKey(e){const t=[];return e.ctrl&&t.push("ctrl"),e.alt&&t.push("alt"),e.shift&&t.push("shift"),e.meta&&t.push("meta"),t.push(e.key.toLowerCase()),t.join("+")}getEventKey(e){const t=[];return e.ctrlKey&&t.push("ctrl"),e.altKey&&t.push("alt"),e.shiftKey&&t.push("shift"),e.metaKey&&t.push("meta"),t.push(e.key.toLowerCase()),t.join("+")}handleKeyDown(e,t){if(!this.enabled)return!1;const o=this.getEventKey(e),i=this.shortcuts.get(o);return i?(i.preventDefault!==!1&&(e.preventDefault(),e.stopPropagation()),t(i.command,i.params),!0):!1}enable(){this.enabled=!0}disable(){this.enabled=!1}isEnabled(){return this.enabled}getAllShortcuts(){return Array.from(this.shortcuts.values())}getShortcutForCommand(e){return Array.from(this.shortcuts.values()).find(t=>t.command===e)}getShortcutDescription(e){const t=[];this.isMac?(e.meta&&t.push("⌘"),e.ctrl&&t.push("⌃"),e.alt&&t.push("⌥"),e.shift&&t.push("⇧")):(e.ctrl&&t.push("Ctrl"),e.alt&&t.push("Alt"),e.shift&&t.push("Shift"));const o=e.key.length===1?e.key.toUpperCase():e.key;return t.push(o),t.join("+")}getShortcutsHelp(){const e=this.getAllShortcuts(),t=new Map;e.forEach(i=>{const n=this.getShortcutCategory(i.command);t.has(n)||t.set(n,[]),t.get(n).push(i)});let o=`# Keyboard Shortcuts
|
|
4
|
+
|
|
5
|
+
`;return t.forEach((i,n)=>{o+=`## ${n}
|
|
6
|
+
|
|
7
|
+
`,i.forEach(s=>{const a=this.getShortcutDescription(s);o+=`- **${a}**: ${s.description||s.command}
|
|
8
|
+
`}),o+=`
|
|
9
|
+
`}),o}getShortcutCategory(e){return e.includes("toggle")&&(e.includes("Bold")||e.includes("Italic")||e.includes("Underline")||e.includes("Strike")||e.includes("Code")||e.includes("Super")||e.includes("Sub"))?"Text Formatting":e.includes("Heading")||e.includes("Paragraph")?"Block Formatting":e.includes("List")||e.includes("Checklist")?"Lists":e.includes("Alignment")||e.includes("Indent")?"Alignment & Indentation":e.includes("undo")||e.includes("redo")?"History":e.includes("insert")?"Insert":e.includes("find")||e.includes("replace")?"Find & Replace":e.includes("Accessibility")||e.includes("spell")?"Tools":"Other"}}const Ve=["p","br","strong","em","u","s","strike","del","b","i","h1","h2","h3","h4","h5","h6","ul","ol","li","a","img","video","audio","table","thead","tbody","tr","th","td","blockquote","pre","code","span","div","sup","sub","hr"],We={"*":["class","style","id","data-*"],a:["href","target","rel","title"],img:["src","alt","width","height","loading"],video:["src","controls","width","height","autoplay","loop","muted"],audio:["src","controls","autoplay","loop","muted"],table:["border","cellpadding","cellspacing"],td:["colspan","rowspan","align","valign"],th:["colspan","rowspan","align","valign"]};function ce(r,e,t){if((e==null?void 0:e.sanitize)===!1)return r;const o=e!=null&&e.allowedTags&&e.allowedTags.length>0?e.allowedTags:Ve,n=!!(e!=null&&e.allowedAttributes)&&Object.keys(e.allowedAttributes).length>0?e.allowedAttributes:We,s=document.createElement("div");return s.innerHTML=r,de(s,o,n),s.innerHTML}function de(r,e,t){const o=Array.from(r.childNodes);for(const i of o)if(i.nodeType===Node.ELEMENT_NODE){const n=i,s=n.tagName.toLowerCase();if(!e.includes(s)){for(;n.firstChild;)r.insertBefore(n.firstChild,n);r.removeChild(n);continue}Ze(n,t),de(n,e,t)}else i.nodeType!==Node.TEXT_NODE&&r.removeChild(i)}function Ze(r,e){const t=r.tagName.toLowerCase(),o=Array.from(r.attributes),i=e[t]||[],n=e["*"]||[],s=[...i,...n];for(const a of o){const l=a.name.toLowerCase();let c=!1;s.includes(l)&&(c=!0);for(const d of s)if(d.endsWith("*")){const g=d.slice(0,-1);if(l.startsWith(g)){c=!0;break}}(l.startsWith("on")||l==="javascript:"||l==="href"&&a.value.trim().toLowerCase().startsWith("javascript:")||l==="src"&&a.value.trim().toLowerCase().startsWith("javascript:"))&&(c=!1),c||r.removeAttribute(a.name)}r.hasAttribute("href")&&(r.getAttribute("href")||"").trim().toLowerCase().startsWith("javascript:")&&r.removeAttribute("href"),r.hasAttribute("src")&&(r.getAttribute("src")||"").trim().toLowerCase().startsWith("javascript:")&&r.removeAttribute("src")}function Ge(r,e,t){return(t==null?void 0:t.sanitizeOnPaste)===!1?r:ce(r,e)}function Xe(r,e,t){return(t==null?void 0:t.sanitizeOnInput)===!1?r:ce(r,e)}const ae=class ae{static resolve(e){const t={};if(Object.assign(t,this.EDITOR_DEFAULTS),e.pluginDefaults&&Object.assign(t,e.pluginDefaults),e.attributes){const o=this.parseAttributes(e.attributes);Object.assign(t,o)}return e.jsConfig&&Object.assign(t,e.jsConfig),this.normalizeConfig(t)}static normalizeConfig(e){const t={...e};if(t.toolbarFloating!==void 0||t.toolbarSticky!==void 0){const s=typeof t.toolbar=="object"&&t.toolbar?{...t.toolbar}:typeof t.toolbar=="string"?{items:t.toolbar}:{};t.toolbarFloating!==void 0&&(s.floating=!!t.toolbarFloating),t.toolbarSticky!==void 0&&(s.sticky=!!t.toolbarSticky),t.toolbar=s}if(t.toolbarItems!==void 0&&typeof t.toolbar=="object"&&t.toolbar&&(t.toolbar.items=t.toolbarItems),t.autosaveEnabled!==void 0||t.autosaveIntervalMs!==void 0||t.autosaveStorageKey!==void 0||t.autosaveProvider!==void 0||t.autosaveApiUrl!==void 0){const s=typeof t.autosave=="object"&&t.autosave?{...t.autosave}:{};t.autosaveEnabled!==void 0&&(s.enabled=!!t.autosaveEnabled),t.autosaveIntervalMs!==void 0&&(s.intervalMs=Number(t.autosaveIntervalMs)),t.autosaveStorageKey!==void 0&&(s.storageKey=t.autosaveStorageKey),t.autosaveProvider!==void 0&&(s.provider=t.autosaveProvider),t.autosaveApiUrl!==void 0&&(s.apiUrl=t.autosaveApiUrl),t.autosave=s}const o={enabled:!1,intervalMs:3e4,storageKey:"rte-autosave",provider:"localStorage",apiUrl:""};if(typeof t.autosave=="boolean")t.autosave={...o,enabled:t.autosave};else if(typeof t.autosave=="object"&&t.autosave){const s={...o,...t.autosave};s.intervalMs===void 0&&s.interval!==void 0&&(s.intervalMs=Number(s.interval)),s.enabled===void 0&&(s.enabled=!0),(!Number.isFinite(s.intervalMs)||s.intervalMs<=0)&&(s.intervalMs=o.intervalMs),t.autosave=s}else t.autosave=o;if(t.languageLocale!==void 0||t.languageDirection!==void 0){const s=typeof t.language=="object"&&t.language?{...t.language}:{};t.languageLocale!==void 0&&(s.locale=t.languageLocale),t.languageDirection!==void 0&&(s.direction=t.languageDirection),t.language=s}const i={locale:"en",direction:"ltr"};if(typeof t.language=="string"?t.language={locale:t.language,direction:i.direction}:typeof t.language=="object"&&t.language?t.language={...i,...t.language}:t.language=i,t.spellcheckEnabled!==void 0||t.spellcheckProvider!==void 0||t.spellcheckApiUrl!==void 0){const s=typeof t.spellcheck=="object"&&t.spellcheck?{...t.spellcheck}:{};t.spellcheckEnabled!==void 0&&(s.enabled=!!t.spellcheckEnabled),t.spellcheckProvider!==void 0&&(s.provider=t.spellcheckProvider),t.spellcheckApiUrl!==void 0&&(s.apiUrl=t.spellcheckApiUrl),t.spellcheck=s}const n={enabled:!1,provider:"browser",apiUrl:""};if(typeof t.spellcheck=="boolean")t.spellcheck={...n,enabled:t.spellcheck};else if(typeof t.spellcheck=="object"&&t.spellcheck){const s={...n,...t.spellcheck};!s.provider&&s.mode&&(s.provider=s.mode==="local"?"browser":"api"),s.enabled===void 0&&(s.enabled=!!(s.mode||s.provider||s.apiUrl)),t.spellcheck=s}else t.spellcheck=n;return t.contextMenuEnabled!==void 0&&(t.contextMenu={enabled:!!t.contextMenuEnabled}),typeof t.contextMenu=="boolean"?t.contextMenu={enabled:t.contextMenu}:typeof t.contextMenu=="object"&&t.contextMenu?t.contextMenu={enabled:t.contextMenu.enabled!==!1}:t.contextMenu={enabled:!0},(t.pasteClean!==void 0||t.pasteKeepFormatting!==void 0||t.pasteConvertWord!==void 0)&&(t.paste={...t.paste||{},...t.pasteClean!==void 0?{clean:!!t.pasteClean}:{},...t.pasteKeepFormatting!==void 0?{keepFormatting:!!t.pasteKeepFormatting}:{},...t.pasteConvertWord!==void 0?{convertWord:!!t.pasteConvertWord}:{}}),t.paste={clean:!0,keepFormatting:!1,convertWord:!0,...t.paste||{}},t.contentConfig={allowedTags:[],allowedAttributes:{},sanitize:!0,...t.contentConfig||{}},(t.securitySanitizeOnPaste!==void 0||t.securitySanitizeOnInput!==void 0)&&(t.security={...t.security||{},...t.securitySanitizeOnPaste!==void 0?{sanitizeOnPaste:!!t.securitySanitizeOnPaste}:{},...t.securitySanitizeOnInput!==void 0?{sanitizeOnInput:!!t.securitySanitizeOnInput}:{}}),t.security={sanitizeOnPaste:!0,sanitizeOnInput:!0,...t.security||{}},(t.accessibilityEnableAria!==void 0||t.accessibilityKeyboardNavigation!==void 0||t.accessibilityChecker!==void 0)&&(t.accessibility={...t.accessibility||{},...t.accessibilityEnableAria!==void 0?{enableARIA:!!t.accessibilityEnableAria}:{},...t.accessibilityKeyboardNavigation!==void 0?{keyboardNavigation:!!t.accessibilityKeyboardNavigation}:{},...t.accessibilityChecker!==void 0?{checker:!!t.accessibilityChecker}:{}}),typeof t.accessibility=="boolean"&&(t.accessibility={enableARIA:t.accessibility,keyboardNavigation:t.accessibility,checker:!1}),t.accessibility={enableARIA:!0,keyboardNavigation:!0,checker:!1,...t.accessibility||{}},(t.performanceDebounceInputMs!==void 0||t.performanceViewportOnlyScan!==void 0)&&(t.performance={...t.performance||{},...t.performanceDebounceInputMs!==void 0?{debounceInputMs:Number(t.performanceDebounceInputMs)}:{},...t.performanceViewportOnlyScan!==void 0?{viewportOnlyScan:!!t.performanceViewportOnlyScan}:{}}),typeof t.performance=="boolean"&&(t.performance={debounceInputMs:100,viewportOnlyScan:t.performance}),t.performance={debounceInputMs:100,viewportOnlyScan:!0,...t.performance||{}},(typeof t.performance.debounceInputMs!="number"||!Number.isFinite(t.performance.debounceInputMs)||t.performance.debounceInputMs<0)&&(t.performance.debounceInputMs=100),t}static parseAttributes(e){const t={};for(const[o,i]of Object.entries(e)){const n=this.kebabToCamel(o);t[n]=this.parseAttributeValue(i)}return t}static parseAttributeValue(e){if(e==="true")return!0;if(e==="false")return!1;if(/^\d+$/.test(e))return parseInt(e,10);if(/^\d+\.\d+$/.test(e))return parseFloat(e);if(e.startsWith("{")||e.startsWith("["))try{return JSON.parse(e)}catch(t){return e}return e}static kebabToCamel(e){return e.replace(/-([a-z])/g,(t,o)=>o.toUpperCase())}static validate(e){const t=[];return e.height!==void 0&&typeof e.height=="number"&&e.height<0&&t.push("height must be a positive number"),e.width!==void 0&&typeof e.width=="number"&&e.width<0&&t.push("width must be a positive number"),e.plugins!==void 0&&!Array.isArray(e.plugins)&&typeof e.plugins!="string"&&t.push("plugins must be an array or string"),e.theme!==void 0&&typeof e.theme!="string"&&t.push("theme must be a string"),{valid:t.length===0,errors:t}}static getDefaults(){return{...this.EDITOR_DEFAULTS}}static merge(...e){const t={};for(const o of e)for(const[i,n]of Object.entries(o))n!=null&&(typeof n=="object"&&!Array.isArray(n)&&t[i]?t[i]=this.merge(t[i],n):t[i]=n);return t}};ae.EDITOR_DEFAULTS={height:400,width:"100%",readonly:!1,disabled:!1,menubar:!0,toolbar:!0,plugins:[],theme:"light",content:"",placeholder:"Start typing...",autofocus:!1,autosave:!1,accessibility:{enableARIA:!0,keyboardNavigation:!0,checker:!1},performance:{debounceInputMs:100,viewportOnlyScan:!0},spellcheck:{enabled:!1,provider:"browser",apiUrl:""},language:{locale:"en",direction:"ltr"},contextMenu:{enabled:!0},contentConfig:{allowedTags:[],allowedAttributes:{},sanitize:!0},paste:{clean:!0,keepFormatting:!1,convertWord:!0},security:{sanitizeOnPaste:!0,sanitizeOnInput:!0},statusbar:!1};let q=ae;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{--editora-dark-toolbar-bg-start: #353d48;--editora-dark-toolbar-bg-end: #2d3540;--editora-dark-button-bg-start: #46505f;--editora-dark-button-bg-end: #3b4553;--editora-dark-button-hover-start: #525d6d;--editora-dark-button-hover-end: #465262;--editora-dark-button-active-start: #5eaaf6;--editora-dark-button-active-end: #4a95de;--editora-dark-border: #475263;--editora-dark-border-strong: #566275;--editora-dark-text: #e1e9f5;--editora-dark-text-strong: #f3f7ff;--editora-dark-text-muted: #aeb9cc;--editora-dark-surface: #1d242d;--editora-dark-content: #1f2732;background:linear-gradient(180deg,#1b2330,#1c2430);color:var(--editora-dark-text);border-color:var(--editora-dark-border)}.editora-toolbar{display:flex;align-items:center;gap:4px;padding:8px;background:#f5f5f5;border-bottom:1px solid #ddd;flex-wrap:wrap}.editora-theme-dark .editora-toolbar{background:linear-gradient(180deg,var(--editora-dark-toolbar-bg-start) 0%,var(--editora-dark-toolbar-bg-end) 100%);border-bottom-color:var(--editora-dark-border);box-shadow:inset 0 1px #ffffff0d}.editora-toolbar-sticky{position:sticky;top:0;z-index:100;position:-webkit-sticky}.editora-toolbar-group{display:flex;align-items:center;gap:2px}.editora-toolbar-button{padding:6px 12px;border:1px solid #ccc;background:#fff;cursor:pointer;border-radius:3px;font-weight:600;font-size:14px;height:30px;display:flex;align-items:center;white-space:nowrap}.editora-toolbar-group-button{display:flex;align-items:center}.editora-toolbar-input.font-size{width:40px;padding:.25rem;text-align:center;font-size:14px;background:#fff;border:1px solid var(--rte-color-border-light);border-radius:var(--rte-radius-sm)}.editora-toolbar-group-items{display:flex;align-items:center;border:1px solid #ccc;.editora-toolbar-button{border:none;border-radius:0;&:first-child{border-right:1px solid #ccc;border-top-left-radius:3px;border-bottom-left-radius:3px}&:last-child{border-left:1px solid #ccc;border-top-right-radius:3px;border-bottom-right-radius:3px}}}.editora-theme-dark .editora-toolbar-button{background:linear-gradient(180deg,var(--editora-dark-button-bg-start) 0%,var(--editora-dark-button-bg-end) 100%);border-color:var(--editora-dark-border-strong);color:var(--editora-dark-text);box-shadow:inset 0 1px #ffffff14,0 1px 1px #00000059}.editora-theme-dark .editora-toolbar-group-items{border-color:var(--editora-dark-border-strong);background:linear-gradient(180deg,var(--editora-dark-button-bg-start) 0%,var(--editora-dark-button-bg-end) 100%)}.editora-theme-dark .editora-toolbar-group-items .editora-toolbar-button:first-child{border-right-color:#566275}.editora-theme-dark .editora-toolbar-group-items .editora-toolbar-button:last-child{border-left-color:#566275}.editora-theme-dark .editora-toolbar-input.font-size{background-color:#2e3642;color:var(--editora-dark-text-strong);border-color:var(--editora-dark-border-strong);caret-color:var(--editora-dark-text-strong)}.editora-theme-dark .editora-toolbar-input.font-size::placeholder{color:var(--editora-dark-text-strong);opacity:1}.editora-toolbar-button:hover{background:#e0e0e0;border-color:#ccc}.editora-theme-dark .editora-toolbar-button:hover{background:linear-gradient(180deg,var(--editora-dark-button-hover-start) 0%,var(--editora-dark-button-hover-end) 100%);border-color:#66748a;color:var(--editora-dark-text-strong)}.editora-toolbar-button:active,.editora-toolbar-button.active{background:#d0d0d0;border-color:#999}.editora-theme-dark .editora-toolbar-button:active,.editora-theme-dark .editora-toolbar-button.active{background:linear-gradient(180deg,var(--editora-dark-button-active-start) 0%,var(--editora-dark-button-active-end) 100%);border-color:#67adf4;color:#0f1b2a}.editora-theme-dark .editora-toolbar-button:disabled{background:#313946;border-color:#424d5e;color:#7f8ca1}.editora-theme-dark .editora-toolbar-button[data-command=insertTable],.editora-theme-dark .editora-toolbar-button[data-command=print],.editora-theme-dark .editora-toolbar-button[data-command=toggleSpellCheck],.editora-theme-dark .editora-toolbar-button[data-command=toggleA11yChecker],.editora-theme-dark .editora-toolbar-button[data-command=setDirectionLTR],.editora-theme-dark .editora-toolbar-button[data-command=setDirectionRTL]{color:#f1f6ff}.editora-toolbar-button:disabled{opacity:.5;cursor:not-allowed}.editora-toolbar-icon{display:inline-flex;align-items:center;justify-content:center;width:24px;height:24px;line-height:1}.editora-toolbar-button svg,.editora-toolbar-icon svg{width:20px;height:20px;display:block;color:currentColor;fill:currentColor}.editora-theme-dark .editora-toolbar-icon,.editora-theme-dark .editora-toolbar-icon *{color:inherit}.editora-theme-dark :is(.editora-toolbar-button,.editora-toolbar-icon) svg :is([stroke="#000" i],[stroke="#000000" i],[stroke=black i],[stroke="#0f0f0f" i],[stroke="#111111" i],[style*="stroke:#000" i],[style*="stroke: #000" i],[style*="stroke:black" i],[style*="stroke: black" i],[style*="stroke:#0f0f0f" i],[style*="stroke: #0f0f0f" i]){stroke:currentColor!important}.editora-theme-dark :is(.editora-toolbar-button,.editora-toolbar-icon) svg :is([fill="#000" i],[fill="#000000" i],[fill=black i],[fill="#0f0f0f" i],[fill="#111111" i],[style*="fill:#000" i],[style*="fill: #000" i],[style*="fill:black" i],[style*="fill: black" i],[style*="fill:#0f0f0f" i],[style*="fill: #0f0f0f" i]){fill:currentColor!important}.editora-toolbar-separator{width:1px;height:24px;background:#ddd;margin:0 4px}.editora-theme-dark .editora-toolbar-separator{background:#4d596b}.editora-toolbar-dropdown{position:relative}.editora-toolbar-dropdown-menu{position:absolute;top:100%;left:0;min-width:150px;margin-top:4px;padding:4px 0;background:#fff;border:1px solid #ddd;border-radius:4px;box-shadow:0 2px 8px #00000026;z-index:1000}.editora-theme-dark .editora-toolbar-dropdown-menu{background:#29323d;border-color:#4d596b;box-shadow:0 8px 20px #00000073}.editora-toolbar-dropdown-item{display:block;width:100%;padding:8px 12px;border:none;background:transparent;color:#333;text-align:left;cursor:pointer;font-size:13px;transition:background .15s ease}.editora-theme-dark .editora-toolbar-dropdown-item{color:#d7deea}.editora-toolbar-dropdown-item:hover{background:#f5f5f5}.editora-theme-dark .editora-toolbar-dropdown-item:hover{background:#3a4554;color:#f0f6ff}.editora-content{flex:1;min-height:200px;padding:16px;outline:none;overflow-y:auto;line-height:1.6}.editora-theme-dark .editora-content{color:#ecf3ff;background:linear-gradient(180deg,var(--editora-dark-content) 0%,#1c232e 100%)}.editora-content:empty:before{content:attr(data-placeholder);color:#999;pointer-events:none}.editora-theme-dark .editora-content:empty:before{color:#8f9bb0}.editora-content h1{font-size:2em;margin:.67em 0;font-weight:600}.editora-content h2{font-size:1.5em;margin:.75em 0;font-weight:600}.editora-content h3{font-size:1.17em;margin:.83em 0;font-weight:600}.editora-content p{margin:1em 0}.editora-content ul,.editora-content ol{margin:1em 0;padding-left:2em}.editora-content a{color:#06c;text-decoration:underline}.editora-theme-dark .editora-content a{color:#4db8ff}.editora-content code{padding:2px 4px;background:#f5f5f5;border-radius:3px;font-family:Monaco,Menlo,Consolas,monospace;font-size:.9em}.editora-theme-dark .editora-content code{background:#1e1e1e}.editora-content pre{padding:12px;background:#f5f5f5;border-radius:4px;overflow-x:auto;margin:1em 0}.editora-theme-dark .editora-content pre{background:#1e1e1e}.editora-theme-dark .rte-code-block{background:linear-gradient(180deg,#212a36,#1b2430)!important;border-color:#4f5b70!important;color:#e7effc!important}.editora-theme-dark .rte-code-block code{color:#e7effc!important}.editora-theme-dark .rte-code-block:before{background:#111927!important;color:#dce8ff!important}.editora-theme-dark .rte-code-block .rte-code-copy{background:#2b3441!important;border-color:#5a667b!important;color:#dce8ff!important}.editora-content blockquote{margin:1em 0;padding-left:1em;border-left:4px solid #ddd;color:#666}.editora-theme-dark .editora-content blockquote{border-left-color:#3c3c3c;color:#9a9a9a}.editora-floating-toolbar{position:absolute;padding:4px;background:#fff;border:1px solid #ddd;border-radius:4px;box-shadow:0 2px 8px #00000026;z-index:1000}.editora-theme-dark .editora-floating-toolbar{background:#29323d;border-color:#4d596b;box-shadow:0 8px 20px #00000073}.editora-statusbar-container{display:flex;flex-direction:column}.editora-statusbar-left{display:flex;align-items:center;gap:8px}.editora-statusbar-right{display:flex;align-items:center;gap:8px;margin-left:auto}.editora-statusbar{display:flex;align-items:center;gap:12px;padding:6px 12px;background:#f5f5f5;border-top:1px solid #ddd;font-size:12px;color:#666}.editora-theme-dark .editora-statusbar{background:linear-gradient(180deg,#2c3440,#252d37);border-top-color:#3f4a5b;color:#d7deea}.editora-statusbar-item{white-space:nowrap}.editora-statusbar-separator{color:#ddd}.editora-theme-dark .editora-statusbar-separator{color:#566275}.editora-editor[readonly] .editora-content{background:#fafafa;cursor:not-allowed}.editora-theme-dark.editora-editor[readonly] .editora-content{background:#1a1a1a}.editora-editor:focus-within{border-color:#06c;box-shadow:0 0 0 3px #0066cc1a}.editora-theme-dark.editora-editor:focus-within{border-color:#4db8ff;box-shadow:0 0 0 3px #4db8ff1a}.editora-editor[disabled]{opacity:.6;pointer-events:none}@media(max-width:768px){.editora-toolbar{padding:4px}.editora-toolbar-button{min-width:28px;min-height:28px;padding:4px 8px;font-size:12px}.editora-content{padding:12px}}.editora-content ::selection{background:#06c3}.editora-theme-dark .editora-content ::selection{background:#4db8ff33}.editora-content table{border-collapse:collapse;width:100%;margin:1em 0}.editora-content th,.editora-content td{border:1px solid #ddd;padding:8px 12px;text-align:left}.editora-theme-dark .editora-content th,.editora-theme-dark .editora-content td{border-color:#3c3c3c}.editora-content th{background:#f5f5f5;font-weight:600}.editora-theme-dark .editora-content th{background:#252526}.editora-content img{max-width:100%;height:auto;border-radius:4px;display:block}.editora-content video{max-width:100%;height:auto;border-radius:4px;display:block}.editora-editor.loading{opacity:.7;pointer-events:none}.editora-editor.loading:after{content:"";position:absolute;top:50%;left:50%;width:24px;height:24px;margin:-12px 0 0 -12px;border:3px solid #ddd;border-top-color:#06c;border-radius:50%;animation:editora-spin .8s linear infinite}@keyframes editora-spin{to{transform:rotate(360deg)}}.toolbar-container-wrapper{display:flex;align-items:center;background:#fff;border-bottom:1px solid #e0e0e0;padding:0;margin:0;width:100%;box-sizing:border-box;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,sans-serif;font-size:14px;line-height:1.5;position:relative}.toolbar-container-wrapper[data-toolbar-sticky=true]{position:sticky;top:0;z-index:999;box-shadow:0 2px 4px #0000001a}.toolbar-container-wrapper[data-toolbar-floating=true]{position:fixed;top:0;left:0;right:0;z-index:1000;box-shadow:0 4px 12px #00000026}.toolbar-container-wrapper[data-toolbar-position=bottom]{border-bottom:none;border-top:1px solid #e0e0e0}.toolbar-container-wrapper .toolbar-wrapper{display:flex;width:100%;padding:8px;gap:4px;flex-wrap:wrap;align-items:center}.toolbar-container-wrapper .toolbar{display:flex;width:100%;gap:4px;flex-wrap:wrap;align-items:center}.toolbar-container-wrapper .toolbar-container{display:flex;gap:4px;flex-wrap:wrap;align-items:center;flex:1;position:relative}.toolbar-container-wrapper .toolbar-item{display:flex;align-items:center;gap:2px}.toolbar-container-wrapper .toolbar-button{padding:6px 10px;border:1px solid #d1d5db;background:#fff;border-radius:4px;cursor:pointer;font-size:13px;display:flex;align-items:center;justify-content:center;gap:4px;transition:all .15s ease;min-height:32px;white-space:nowrap}.toolbar-container-wrapper .toolbar-button:hover{background-color:#f3f4f6;border-color:#9ca3af}.toolbar-container-wrapper .toolbar-button:active,.toolbar-container-wrapper .toolbar-button[data-active=true]{background-color:#06c;color:#fff;border-color:#0052a3;box-shadow:inset 0 1px 3px #0000001a}.toolbar-container-wrapper .toolbar-button:disabled{opacity:.5;cursor:not-allowed;background-color:#f9fafb}.toolbar-container-wrapper .toolbar-more-button{padding:6px 8px;font-size:16px;font-weight:500;line-height:1}.toolbar-container-wrapper .toolbar-separator{width:1px;height:24px;background-color:#d1d5db;margin:0 4px}.toolbar-container-wrapper .toolbar-icon{display:inline-flex;align-items:center;justify-content:center;width:18px;height:18px;flex-shrink:0}.toolbar-container-wrapper .toolbar-icon svg{width:100%;height:100%}.toolbar-container-wrapper .toolbar-dropdown{position:relative;display:flex;align-items:center}.toolbar-container-wrapper .toolbar-dropdown-arrow{font-size:10px;margin-left:2px;line-height:1}.toolbar-container-wrapper .toolbar-dropdown-menu{position:absolute;top:100%;left:0;background:#fff;border:1px solid #d1d5db;border-radius:6px;box-shadow:0 4px 12px #00000026;z-index:1000;min-width:160px;padding:4px 0;margin-top:4px;display:none}.toolbar-container-wrapper .toolbar-dropdown-menu.show{display:block}.toolbar-container-wrapper .toolbar-dropdown-item{display:block;width:100%;padding:8px 12px;border:none;background:transparent;text-align:left;cursor:pointer;font-size:13px;color:#1f2937;transition:background-color .15s ease;font-family:inherit}.toolbar-container-wrapper .toolbar-dropdown-item:hover{background-color:#f3f4f6}.toolbar-container-wrapper .toolbar-dropdown-item:active{background-color:#e5e7eb}.toolbar-container-wrapper .toolbar-input{padding:6px 8px;border:1px solid #d1d5db;border-radius:4px;font-size:13px;font-family:inherit;background-color:#fff;color:#1f2937;transition:all .15s ease}.toolbar-container-wrapper .toolbar-input:focus{outline:none;border-color:#06c;box-shadow:0 0 0 3px #0066cc1a;background-color:#fff}.toolbar-container-wrapper .toolbar-input::placeholder{color:#9ca3af}.toolbar-overflow-menu{animation:slideDown .2s ease-out}@keyframes slideDown{0%{opacity:0;transform:translateY(-8px)}to{opacity:1;transform:translateY(0)}}.toolbar-overflow-item{transition:background-color .15s ease}.floating-toolbar{user-select:none;-webkit-user-select:none;font-family:system-ui,-apple-system,sans-serif;font-size:14px;animation:fadeInUp .15s ease-out}@keyframes fadeInUp{0%{opacity:0;transform:translate(-50%) translateY(10px)}to{opacity:1;transform:translate(-50%) translateY(0)}}.floating-toolbar-btn{display:flex;align-items:center;justify-content:center;width:32px;height:32px;border:none;background:transparent;border-radius:4px;color:#495057;cursor:pointer;font-size:14px;font-weight:500;transition:all .15s ease;outline:none}.floating-toolbar-btn:hover{background:#f8f9fa;color:#212529}.floating-toolbar-btn:active{background:#e9ecef;transform:scale(.95)}.floating-toolbar-btn.floating-toolbar-toggle{color:#dc3545;font-weight:700}.floating-toolbar-btn.floating-toolbar-toggle:hover{background:#f8d7da;color:#721c24}.floating-toolbar-separator{width:1px;height:20px;background:#e1e5e9;margin:0 2px}@media(max-width:768px){.toolbar-container-wrapper .toolbar-button{padding:5px 8px;font-size:12px;min-height:28px}.toolbar-container-wrapper .toolbar-icon{width:16px;height:16px}.toolbar-container-wrapper .toolbar-dropdown-menu{min-width:140px}.toolbar-container-wrapper .toolbar-dropdown-item{padding:6px 10px;font-size:12px}.floating-toolbar{padding:4px;gap:2px}.floating-toolbar-btn{width:28px;height:28px;font-size:12px}}@media(max-width:480px){.toolbar-container-wrapper{padding:4px}.toolbar-container-wrapper .toolbar-wrapper{padding:4px;gap:2px}.toolbar-container-wrapper .toolbar-button{padding:4px 6px;font-size:11px;min-height:24px}.toolbar-container-wrapper .toolbar-icon{width:14px;height:14px}}.floating-toolbar{pointer-events:auto}.floating-toolbar{max-width:calc(100vw - 20px);overflow-x:auto}@media(prefers-color-scheme:dark){.floating-toolbar{background:#2d3748;border-color:#4a5568;color:#e2e8f0}.floating-toolbar-btn:hover{background:#4a5568;color:#f7fafc}.floating-toolbar-btn:active{background:#718096}.floating-toolbar-separator{background:#4a5568}}';let R;function Je(){const r="editora-webcomponent-styles";if(!document.getElementById(r)){const e=document.createElement("style");e.id=r,e.textContent=Ye,document.head.appendChild(e)}}function Qe(){if(!R){const r=C.__globalPluginLoader;r?R=r:R=new L}return R}class C extends HTMLElement{constructor(){if(super(),this.pluginLoader=Qe(),this.config={},this.isInitialized=!1,this.keyboardShortcutManager=new qe,this.lastAutosavedContent="",this.loadedPlugins=[],Je(),!this.hasAttribute("data-initial-content")){const e=this.innerHTML.trim();e&&this.setAttribute("data-initial-content",e)}}static get observedAttributes(){return["height","width","menubar","plugins","toolbar","toolbar-items","toolbar-floating","toolbar-sticky","readonly","disabled","theme","placeholder","autofocus","autosave","autosave-enabled","autosave-interval-ms","autosave-storage-key","autosave-provider","autosave-api-url","accessibility","accessibility-enable-aria","accessibility-keyboard-navigation","accessibility-checker","performance","performance-debounce-input-ms","performance-viewport-only-scan","language","language-locale","language-direction","spellcheck","spellcheck-enabled","spellcheck-provider","context-menu","context-menu-enabled","paste","paste-clean","paste-keep-formatting","paste-convert-word","security","security-sanitize-on-paste","security-sanitize-on-input","statusbar"]}connectedCallback(){this.config=this.resolveConfig(),this.waitForPluginLoader().then(()=>{setTimeout(async()=>{await this.initialize()},0)})}async waitForPluginLoader(){if(C.__globalPluginLoader){this.pluginLoader=C.__globalPluginLoader;return}return new Promise(e=>{const t=()=>{C.__globalPluginLoader?(this.pluginLoader=C.__globalPluginLoader,e()):setTimeout(t,0)};t()})}disconnectedCallback(){this.destroy()}attributeChangedCallback(e,t,o){t!==o&&(this.config=this.resolveConfig(),this.handleAttributeChange(e,o))}async setConfig(e){this.jsConfig=e,this.config=this.resolveConfig(),this.isConnected&&(this.destroy(),await this.waitForPluginLoader(),await this.initialize())}async initialize(){var o;if(this.querySelector(".editora-toolbar")||this.isInitialized)return;this.setAttribute("data-editora-editor","true"),this.config.height&&(this.style.height=typeof this.config.height=="number"?`${this.config.height}px`:this.config.height),this.config.width&&(this.style.width=typeof this.config.width=="number"?`${this.config.width}px`:this.config.width),this.classList.add("editora-editor"),this.config.theme&&this.classList.add(`editora-theme-${this.config.theme}`);const e=await this.loadPlugins();this.loadedPlugins=e,e.forEach(i=>{if(i.init&&typeof i.init=="function")try{i.init({editorElement:this})}catch(n){console.error(`[RichTextEditor] Error initializing plugin ${i.name}:`,n)}});const t=(o=this.restoreAutosavedContent())!=null?o:this.getAttribute("data-initial-content")||"";this.engine=new Re({content:t,plugins:e,readonly:this.config.readonly}),this.createUI(e,t),this.setupEventListeners(),this.startAutosave(),this.isInitialized=!0,this.dispatchEvent(new CustomEvent("editor-ready",{detail:{api:this.getAPI()},bubbles:!0}))}getInitialContent(){if(this.config.content)return this.config.content;const e=this.querySelector("[slot]");return e?e.innerHTML:this.hasChildNodes()?Array.from(this.childNodes).map(o=>o.nodeType===Node.TEXT_NODE?o.textContent:o.nodeType===Node.ELEMENT_NODE?o.outerHTML:"").join("").trim():""}async loadPlugins(){this.pluginLoader||await this.waitForPluginLoader();const e=[],t=this.config.plugins&&(typeof this.config.plugins=="string"&&this.config.plugins.length>0||Array.isArray(this.config.plugins)&&this.config.plugins.length>0),i=this.getAccessibilityConfig().checker===!0;if(t){if(typeof this.config.plugins=="string"){const n=this.config.plugins.split(/\s+/).filter(Boolean);i&&!n.includes("a11yChecker")&&n.push("a11yChecker");for(const s of n){const a=await this.pluginLoader.load(s,this.getPluginLoadConfig(s));a&&e.push(a)}}else if(Array.isArray(this.config.plugins)){for(const n of this.config.plugins)if(typeof n=="string"){const s=await this.pluginLoader.load(n,this.getPluginLoadConfig(n));s&&e.push(s)}else e.push(n);if(i&&!e.some(n=>(n==null?void 0:n.name)==="a11yChecker")){const n=await this.pluginLoader.load("a11yChecker",this.getPluginLoadConfig("a11yChecker"));n&&e.push(n)}}}else{const n=this.pluginLoader.getRegisteredPluginNames();for(const s of n){const a=await this.pluginLoader.load(s,this.getPluginLoadConfig(s));a&&e.push(a)}}return e}resolveToolbarItems(){const e=this.config.toolbarItems;if(typeof e=="string")return e;if(Array.isArray(e))return e.join(" ");const t=this.config.toolbar;if(typeof t=="string")return t;if(!t||typeof t!="object")return;const o=t.items;if(typeof o=="string")return o;if(Array.isArray(o))return o.join(" ")}isToolbarStickyEnabled(){const e=this.config.toolbar;return!e||typeof e!="object"?!1:!!e.sticky}isToolbarFloatingEnabled(){const e=this.config.toolbar;return!e||typeof e!="object"?!1:!!e.floating}isStatusbarEnabled(){const e=this.config.statusbar;return typeof e=="boolean"?e:e&&typeof e=="object"?e.enabled!==!1:!1}getStatusbarPosition(){const e=this.config.statusbar;return e&&typeof e=="object"&&e.position==="top"?"top":"bottom"}getLanguageConfig(){const e=this.config.language;return typeof e=="string"?{locale:e,direction:"ltr"}:e&&typeof e=="object"?{locale:e.locale||"en",direction:e.direction==="rtl"?"rtl":"ltr"}:{locale:"en",direction:"ltr"}}getAccessibilityConfig(){const e=this.config.accessibility;return typeof e=="boolean"?{enableARIA:e,keyboardNavigation:e,checker:!1}:e&&typeof e=="object"?{enableARIA:e.enableARIA!==!1,keyboardNavigation:e.keyboardNavigation!==!1,checker:!!e.checker}:{enableARIA:!0,keyboardNavigation:!0,checker:!1}}getPerformanceConfig(){var t;const e=this.config.performance;if(typeof e=="boolean")return{debounceInputMs:100,viewportOnlyScan:e};if(e&&typeof e=="object"){const o=Number((t=e.debounceInputMs)!=null?t:100);return{debounceInputMs:Number.isFinite(o)&&o>=0?o:100,viewportOnlyScan:e.viewportOnlyScan!==!1}}return{debounceInputMs:100,viewportOnlyScan:!0}}isEditorInViewport(){if(!this.contentElement||typeof window=="undefined")return!0;const e=this.contentElement.getBoundingClientRect();return e.bottom>=0&&e.top<=window.innerHeight}applyAccessibilitySettings(){if(!this.contentElement)return;const e=this.getAccessibilityConfig();if(e.enableARIA){this.contentElement.setAttribute("role","textbox"),this.contentElement.setAttribute("aria-multiline","true"),this.contentElement.setAttribute("aria-disabled",this.config.readonly?"true":"false");const t=typeof this.config.placeholder=="string"?this.config.placeholder.trim():"";t?this.contentElement.setAttribute("aria-label",t):this.contentElement.removeAttribute("aria-label")}else this.contentElement.removeAttribute("role"),this.contentElement.removeAttribute("aria-multiline"),this.contentElement.removeAttribute("aria-disabled"),this.contentElement.removeAttribute("aria-label");this.contentElement.tabIndex=e.keyboardNavigation?0:-1}applyLanguageSettings(){if(!this.contentElement)return;const e=this.getLanguageConfig();this.contentElement.setAttribute("lang",e.locale),this.contentElement.setAttribute("dir",e.direction)}getSpellcheckConfig(){const e=this.config.spellcheck;if(typeof e=="boolean")return{enabled:e,provider:"browser"};if(e&&typeof e=="object"){const t=e.provider||"browser";return{enabled:!!e.enabled,provider:t,mode:e.mode}}return{enabled:!1,provider:"browser"}}applySpellcheckSettings(){if(!this.contentElement)return;const e=this.getSpellcheckConfig(),t=e.enabled&&e.provider==="browser";this.contentElement.spellcheck=t,this.contentElement.setAttribute("spellcheck",t?"true":"false")}executeCommand(e,t){var i;typeof window!="undefined"&&(window.__editoraCommandEditorRoot=this);const o=this.loadedPlugins.find(n=>n.commands&&n.commands[e]);if(o&&o.commands){const n=o.commands[e];if(typeof n=="function")try{return n(e==="toggleFullscreen"?this:t),!0}catch(s){return console.error(`[RichTextEditor] Error executing native command ${e}:`,s),!1}}return((i=this.engine)==null?void 0:i.execCommand(e,t))||!1}getPluginLoadConfig(e){const t=this.config.pluginConfig;if(t&&typeof t=="object"){const n=t[e];if(n&&typeof n=="object")return n}const o={spellCheck:["spellcheck","spellCheck"]},i=[e,e.toLowerCase(),...o[e]||[]];for(const n of i){const s=this.config[n];if(s&&typeof s=="object"&&!Array.isArray(s))return s}}getContentSanitizeConfig(){const e=this.config.contentConfig;return e&&typeof e=="object"?e:{sanitize:!0}}getSecurityConfig(){const e=this.config.security;return e&&typeof e=="object"?e:{sanitizeOnPaste:!0,sanitizeOnInput:!0}}getAutosaveConfig(){var t,o;const e=this.config.autosave;if(typeof e=="boolean")return{enabled:e,intervalMs:3e4,storageKey:"rte-autosave",provider:"localStorage"};if(e&&typeof e=="object"){const i=Number((o=(t=e.intervalMs)!=null?t:e.interval)!=null?o:3e4);return{enabled:!!e.enabled,intervalMs:Number.isFinite(i)&&i>0?i:3e4,storageKey:String(e.storageKey||"rte-autosave"),provider:e.provider||"localStorage",apiUrl:e.apiUrl}}return{enabled:!1,intervalMs:3e4,storageKey:"rte-autosave",provider:"localStorage"}}persistAutosave(e){const t=this.getAutosaveConfig();if(t.enabled&&e!==this.lastAutosavedContent){if(this.lastAutosavedContent=e,t.provider==="localStorage"){try{localStorage.setItem(t.storageKey,e),localStorage.setItem(`${t.storageKey}-timestamp`,Date.now().toString())}catch(o){console.error("[RichTextEditor] Failed to save autosave content to localStorage:",o)}return}t.provider==="api"&&t.apiUrl&&fetch(t.apiUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:e,timestamp:Date.now()})}).catch(o=>{console.error("[RichTextEditor] Failed to save autosave content to API:",o)})}}restoreAutosavedContent(){const e=this.getAutosaveConfig();if(!e.enabled||e.provider!=="localStorage")return null;try{const t=localStorage.getItem(e.storageKey);if(t)return this.lastAutosavedContent=t,t}catch(t){console.error("[RichTextEditor] Failed to restore autosaved content:",t)}return null}stopAutosave(){this.autosaveTimer&&(clearInterval(this.autosaveTimer),this.autosaveTimer=void 0)}startAutosave(){this.stopAutosave();const e=this.getAutosaveConfig();!e.enabled||!this.contentElement||(this.autosaveTimer=setInterval(()=>{var t;this.persistAutosave(((t=this.contentElement)==null?void 0:t.innerHTML)||"")},e.intervalMs))}insertHTMLAtSelection(e){if(!this.contentElement)return;const t=window.getSelection();if(t&&t.rangeCount>0){const o=t.getRangeAt(0);o.deleteContents();const i=document.createElement("div");i.innerHTML=e;const n=document.createDocumentFragment();for(;i.firstChild;)n.appendChild(i.firstChild);o.insertNode(n),o.collapse(!1),t.removeAllRanges(),t.addRange(o)}else this.contentElement.focus(),document.execCommand("insertHTML",!1,e)}createUI(e,t){const o=this.querySelector('[slot="toolbar"]'),i=this.querySelector('[slot="statusbar"]');this.innerHTML="",this.config.toolbar!==!1&&!o?(this.toolbarElement=document.createElement("div"),this.toolbarElement.className="editora-toolbar-container",this.appendChild(this.toolbarElement),this.toolbar=new Be({items:this.resolveToolbarItems(),sticky:this.isToolbarStickyEnabled(),position:"top"},e,this.pluginLoader),this.toolbar.setCommandHandler((n,s)=>{var a;if(this.contentElement){this.contentElement.focus();const l=window.getSelection();if(!l||l.rangeCount===0||!this.contentElement.contains(l.anchorNode)){const c=document.createRange(),d=this.contentElement.lastChild||this.contentElement;d.nodeType===Node.TEXT_NODE?c.setStart(d,((a=d.textContent)==null?void 0:a.length)||0):d.nodeType===Node.ELEMENT_NODE?(c.selectNodeContents(d),c.collapse(!1)):c.setStart(this.contentElement,0),c.collapse(!0),l==null||l.removeAllRanges(),l==null||l.addRange(c)}}return this.executeCommand(n,s)}),this.toolbar.render(this.toolbarElement)):o&&this.appendChild(o),this.contentElement=document.createElement("div"),this.contentElement.className="editora-content rte-content",this.contentElement.contentEditable=this.config.readonly?"false":"true",this.applyLanguageSettings(),this.applyAccessibilitySettings(),this.applySpellcheckSettings(),this.config.placeholder&&this.contentElement.setAttribute("data-placeholder",this.config.placeholder);try{document.execCommand("defaultParagraphSeparator",!1,"p")}catch(n){console.warn("defaultParagraphSeparator not supported:",n)}if(t){const n=document.createElement("div");n.innerHTML=t.trim(),!Array.from(n.childNodes).some(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.isToolbarFloatingEnabled()&&(this.floatingToolbar=new ze({enabled:!0}),this.floatingToolbar.create(this)),i?this.appendChild(i):this.isStatusbarEnabled()&&(this.statusBarElement=document.createElement("div"),this.statusBarElement.className="editora-statusbar-container",this.appendChild(this.statusBarElement),this.statusBar=new $e({position:this.getStatusbarPosition()}),this.statusBar.create(this.statusBarElement)),this.config.autofocus&&setTimeout(()=>{var n;return(n=this.contentElement)==null?void 0:n.focus()},0)}setupEventListeners(){if(!this.contentElement||!this.engine)return;const e=this.keyboardShortcutManager;this.contentElement.addEventListener("input",()=>{if(!this.contentElement)return;let o=this.contentElement.innerHTML;const i=this.getPerformanceConfig(),n=this.getContentSanitizeConfig(),s=this.getSecurityConfig();if(s.sanitizeOnInput!==!1&&n.sanitize!==!1){const l=Xe(o,n,s);if(l!==o){const c=window.getSelection(),d=c&&c.rangeCount>0?c.getRangeAt(0):null;if(this.contentElement.innerHTML=l,d&&c)try{c.removeAllRanges(),c.addRange(d)}catch(g){}o=l}}this.contentChangeDebounceTimer&&clearTimeout(this.contentChangeDebounceTimer);const a=()=>{this.dispatchEvent(new CustomEvent("content-change",{detail:{html:o},bubbles:!0}))};i.debounceInputMs>0?this.contentChangeDebounceTimer=setTimeout(a,i.debounceInputMs):a(),this.updateStatusBar()}),this.contentElement.addEventListener("contextmenu",o=>{const i=this.config.contextMenu;(i===!1||typeof i=="object"&&i!==null&&i.enabled===!1)&&o.preventDefault()}),this.contentElement.addEventListener("paste",o=>{var d,g;o.preventDefault();const i=this.config.paste||{};let n=((d=o.clipboardData)==null?void 0:d.getData("text/html"))||"";const s=((g=o.clipboardData)==null?void 0:g.getData("text/plain"))||"",a=this.getContentSanitizeConfig(),l=this.getSecurityConfig(),c=!!n&&/class=["'][^"']*Mso|xmlns:w=|urn:schemas-microsoft-com:office/i.test(n);if((i.clean||!i.keepFormatting)&&s){document.execCommand("insertText",!1,s);return}if(i.convertWord===!1&&c&&s){document.execCommand("insertText",!1,s);return}if(n){l.sanitizeOnPaste!==!1&&a.sanitize!==!1&&(n=Ge(n,a,l)),this.insertHTMLAtSelection(n);return}s&&document.execCommand("insertText",!1,s)}),this.contentElement.addEventListener("focus",()=>{this.dispatchEvent(new Event("editor-focus",{bubbles:!0})),this.updateStatusBar()}),this.contentElement.addEventListener("blur",()=>{this.contentChangeDebounceTimer&&(clearTimeout(this.contentChangeDebounceTimer),this.contentChangeDebounceTimer=void 0),this.contentElement&&this.dispatchEvent(new CustomEvent("content-change",{detail:{html:this.contentElement.innerHTML},bubbles:!0})),this.dispatchEvent(new Event("editor-blur",{bubbles:!0})),this.updateFloatingToolbar(),this.updateStatusBar()}),this.contentElement.addEventListener("keydown",o=>{this.getAccessibilityConfig().keyboardNavigation&&e.handleKeyDown(o,(n,s)=>{this.executeCommand(n,s)})});const t=()=>{const o=this.getSelectionRangeInEditor(),i=document.activeElement,n=!!i&&!!this.contentElement&&(i===this.contentElement||this.contentElement.contains(i));this.getPerformanceConfig().viewportOnlyScan&&!this.isEditorInViewport()&&!n||!o&&!n||(this.updateFloatingToolbar(),this.updateStatusBar())};this.selectionChangeHandler=t,document.addEventListener("selectionchange",this.selectionChangeHandler)}getSelectionRangeInEditor(){if(!this.contentElement)return null;const e=window.getSelection();if(!e||e.rangeCount===0)return null;const t=e.getRangeAt(0),o=t.commonAncestorContainer;return this.contentElement.contains(o)?t:null}isSelectionBackward(e){if(!e.anchorNode||!e.focusNode)return!1;try{const t=document.createRange();return t.setStart(e.anchorNode,e.anchorOffset),t.setEnd(e.focusNode,e.focusOffset),t.collapsed}catch(t){return!1}}getSelectionAnchorRect(e,t){const o=Array.from(t.getClientRects()).filter(n=>n.width>0||n.height>0);return o.length===0?t.getBoundingClientRect():this.isSelectionBackward(e)?o[0]:o[o.length-1]}updateFloatingToolbar(){if(!this.floatingToolbar)return;const e=this.getPerformanceConfig(),t=document.activeElement===this.contentElement||!!this.contentElement&&this.contentElement.contains(document.activeElement);if(e.viewportOnlyScan&&!this.isEditorInViewport()&&!t){this.floatingToolbar.hide();return}const o=this.getSelectionRangeInEditor();if(!o){this.floatingToolbar.hide();return}if(o.collapsed){this.floatingToolbar.hide();return}const i=window.getSelection();if(!i){this.floatingToolbar.hide();return}const n=this.getSelectionAnchorRect(i,o);if(!n){this.floatingToolbar.hide();return}this.floatingToolbar.show(n.left,n.top-40)}updateStatusBar(){if(!this.statusBar||!this.contentElement)return;const e=this.getPerformanceConfig(),t=document.activeElement===this.contentElement||this.contentElement.contains(document.activeElement);if(e.viewportOnlyScan&&!this.isEditorInViewport()&&!t)return;const o=this.contentElement.textContent||"",{words:i,chars:n}=Ue(o),s=Fe(this.contentElement);let a,l;const c=this.getSelectionRangeInEditor();c&&(a=_e(this.contentElement,c),c.collapsed||(l=Ke(c,a),a=void 0)),this.statusBar.update({wordCount:i,charCount:n,lineCount:s,cursorPosition:a,selectionInfo:l})}handleAttributeChange(e,t){switch(e){case"readonly":this.contentElement&&(this.contentElement.contentEditable=t==="true"?"false":"true",this.applyAccessibilitySettings()),this.engine&&this.engine.setReadonly(t==="true");break;case"theme":this.classList.forEach(o=>{o.startsWith("editora-theme-")&&this.classList.remove(o)}),t&&this.classList.add(`editora-theme-${t}`);break;case"placeholder":this.contentElement&&(this.contentElement.setAttribute("data-placeholder",t),this.applyAccessibilitySettings());break;case"accessibility":case"accessibility-enable-aria":case"accessibility-keyboard-navigation":case"accessibility-checker":this.applyAccessibilitySettings();break;case"performance":case"performance-debounce-input-ms":case"performance-viewport-only-scan":break;case"language":case"language-locale":case"language-direction":this.applyLanguageSettings();break;case"spellcheck":case"spellcheck-enabled":case"spellcheck-provider":this.applySpellcheckSettings();break;case"autosave":case"autosave-enabled":case"autosave-interval-ms":case"autosave-storage-key":case"autosave-provider":case"autosave-api-url":this.startAutosave();break;case"security":case"security-sanitize-on-paste":case"security-sanitize-on-input":case"paste":case"paste-clean":case"paste-keep-formatting":case"paste-convert-word":case"context-menu":case"context-menu-enabled":break;case"toolbar":case"toolbar-items":case"toolbar-floating":case"toolbar-sticky":case"plugins":case"statusbar":this.isConnected&&(this.destroy(),this.waitForPluginLoader().then(()=>{this.initialize().catch(o=>{console.error("[RichTextEditor] Error during attribute change re-initialization:",o)})}));break}}resolveConfig(){const e={};for(let t=0;t<this.attributes.length;t++){const o=this.attributes[t];e[o.name]=o.value}return q.resolve({jsConfig:this.jsConfig,attributes:e})}getAPI(){return{getContent:()=>{var e;return((e=this.contentElement)==null?void 0:e.innerHTML)||""},setContent:e=>{this.contentElement&&(this.contentElement.innerHTML=e)},execCommand:(e,t)=>this.executeCommand(e,t),focus:()=>{var e;(e=this.contentElement)==null||e.focus()},blur:()=>{var e;(e=this.contentElement)==null||e.blur()},destroy:()=>{this.destroy()},on:(e,t)=>(this.addEventListener(e,t),()=>this.removeEventListener(e,t)),getConfig:()=>({...this.config}),setReadonly:e=>{this.setAttribute("readonly",e.toString())}}}destroy(){var e,t,o,i;this.contentChangeDebounceTimer&&(clearTimeout(this.contentChangeDebounceTimer),this.contentChangeDebounceTimer=void 0),this.contentElement&&this.persistAutosave(this.contentElement.innerHTML||""),this.stopAutosave(),this.selectionChangeHandler&&(document.removeEventListener("selectionchange",this.selectionChangeHandler),this.selectionChangeHandler=void 0),(e=this.engine)==null||e.destroy(),(t=this.toolbar)==null||t.destroy(),(o=this.floatingToolbar)==null||o.destroy(),(i=this.statusBar)==null||i.destroy(),this.innerHTML="",this.contentElement=void 0,this.toolbarElement=void 0,this.statusBarElement=void 0,this.loadedPlugins=[],this.isInitialized=!1,this.dispatchEvent(new Event("editor-destroy",{bubbles:!0}))}getContent(){var e;return((e=this.contentElement)==null?void 0:e.innerHTML)||""}setContent(e){this.contentElement&&(this.contentElement.innerHTML=e)}execCommand(e,t){return this.executeCommand(e,t)}focus(){var e;(e=this.contentElement)==null||e.focus()}blur(){var e;(e=this.contentElement)==null||e.blur()}}const V=new L;C.__globalPluginLoader=V;const et={bold:()=>Promise.resolve().then(()=>tt).then(r=>r.BoldPlugin()),italic:()=>Promise.resolve().then(()=>it).then(r=>r.ItalicPlugin()),underline:()=>Promise.resolve().then(()=>nt).then(r=>r.UnderlinePlugin()),strikethrough:()=>Promise.resolve().then(()=>lt).then(r=>r.StrikethroughPlugin()),clearFormatting:()=>Promise.resolve().then(()=>bt).then(r=>r.ClearFormattingPlugin()),heading:()=>Promise.resolve().then(()=>yt).then(r=>r.HeadingPlugin()),blockquote:()=>Promise.resolve().then(()=>vt).then(r=>r.BlockquotePlugin()),code:()=>Promise.resolve().then(()=>Ht).then(r=>r.CodePlugin()),list:()=>Promise.resolve().then(()=>Rt).then(r=>r.ListPlugin()),history:()=>Promise.resolve().then(()=>_t).then(r=>r.HistoryPlugin())};async function he(){return Object.entries(et).forEach(([r,e])=>{V.register(r,e)}),V}typeof window!="undefined"&&he().then(r=>{C.__globalPluginLoader=r,customElements.get("editora-editor")||customElements.define("editora-editor",C);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 C&&!o.isInitialized&&t[i]&&o.setAttribute("content",t[i])})});const tt=Object.freeze(Object.defineProperty({__proto__:null,BoldPlugin:()=>({name:"bold",marks:{bold:{parseDOM:[{tag:"strong"},{tag:"b"},{style:"font-weight",getAttrs:r=>{const e=typeof r=="string"?r:r.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"})),W=()=>(document.execCommand("italic",!1),!0),ot=(r,e)=>{var t;typeof window!="undefined"&&((t=window.registerEditorCommand)==null||t.call(window,r,e))},ue=()=>{ot("toggleItalic",W)};typeof window!="undefined"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",ue):ue());const it=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:W},keymap:{"Mod-i":"toggleItalic","Mod-I":"toggleItalic"}}),toggleItalic:W},Symbol.toStringTag,{value:"Module"})),nt=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"})),rt=()=>({name:"strikethrough",marks:{strikethrough:{parseDOM:[{tag:"s"},{tag:"strike"},{tag:"del"},{style:"text-decoration",getAttrs:r=>(typeof r=="string"?r:r.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:()=>{const r=st();if(!r)return!1;const e=window.getSelection();if(!e||e.rangeCount===0)return!1;const t=e.getRangeAt(0);if(!r.contains(t.commonAncestorContainer))return!1;r.focus({preventScroll:!0});const o=document.execCommand("strikeThrough",!1);return at(r),r.dispatchEvent(new Event("input",{bubbles:!0})),o!==!1}},keymap:{"Mod-Shift-x":"toggleStrikethrough","Mod-Shift-X":"toggleStrikethrough"}});function st(){const r=window.getSelection();if(r&&r.rangeCount>0){const t=r.getRangeAt(0).startContainer,o=t.nodeType===Node.ELEMENT_NODE?t:t.parentElement,i=o==null?void 0:o.closest('[contenteditable="true"], .rte-content, .editora-content');if(i)return i}const e=document.activeElement;return e?e.getAttribute("contenteditable")==="true"?e:e.closest('[contenteditable="true"], .rte-content, .editora-content'):null}function at(r){r.querySelectorAll("strike, del").forEach(t=>{var i;const o=document.createElement("s");for(const n of Array.from(t.attributes))n.name!=="style"&&o.setAttribute(n.name,n.value);for(;t.firstChild;)o.appendChild(t.firstChild);(i=t.parentNode)==null||i.replaceChild(o,t)})}const lt=Object.freeze(Object.defineProperty({__proto__:null,StrikethroughPlugin:rt},Symbol.toStringTag,{value:"Module"})),ct=()=>({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:()=>{const r=gt();if(!r)return!1;const e=window.getSelection();if(!e||e.rangeCount===0)return!1;const t=e.getRangeAt(0);if(!r.contains(t.commonAncestorContainer))return!1;const o=t.cloneRange();return r.focus({preventScroll:!0}),document.execCommand("unlink",!1),document.execCommand("removeFormat",!1),pt(r,o),mt(r,o),r.dispatchEvent(new Event("input",{bubbles:!0})),!0}},keymap:{"Mod-\\":"clearFormatting"}}),dt=new Set(["A","B","STRONG","I","EM","U","S","STRIKE","DEL","FONT","MARK","CODE","SUB","SUP"]),ht=new Set(["H1","H2","H3","H4","H5","H6","BLOCKQUOTE","PRE"]),ut=["color","background-color","font-size","font-family","font-weight","font-style","text-decoration","text-transform","line-height","letter-spacing","word-spacing","vertical-align","text-align","padding-left"];function gt(){const r=window.getSelection();if(r&&r.rangeCount>0){const t=r.getRangeAt(0).startContainer,o=t.nodeType===Node.ELEMENT_NODE?t:t.parentElement,i=o==null?void 0:o.closest('[contenteditable="true"], .rte-content, .editora-content');if(i)return i}const e=document.activeElement;return e?e.getAttribute("contenteditable")==="true"?e:e.closest('[contenteditable="true"], .rte-content, .editora-content'):null}function ge(r,e){try{if(typeof r.intersectsNode=="function")return r.intersectsNode(e)}catch(o){}const t=document.createRange();return e.nodeType===Node.ELEMENT_NODE?t.selectNodeContents(e):t.selectNode(e),r.compareBoundaryPoints(Range.END_TO_START,t)>0&&r.compareBoundaryPoints(Range.START_TO_END,t)<0}function fe(r){let e=0,t=r;for(;t&&t.parentNode;)e+=1,t=t.parentNode;return e}function ft(r){ut.forEach(e=>{r.style.removeProperty(e)}),(!r.getAttribute("style")||r.style.length===0)&&r.removeAttribute("style"),r.classList.contains("rte-text-color")&&r.classList.remove("rte-text-color"),r.classList.contains("rte-bg-color")&&r.classList.remove("rte-bg-color"),r.classList.length===0&&r.removeAttribute("class")}function pe(r){const e=r.parentNode;if(e){for(;r.firstChild;)e.insertBefore(r.firstChild,r);e.removeChild(r)}}function pt(r,e){Array.from(r.querySelectorAll("h1,h2,h3,h4,h5,h6,blockquote,pre")).forEach(o=>{var n;if(!ge(e,o)||!ht.has(o.tagName))return;const i=document.createElement("p");for(;o.firstChild;)i.appendChild(o.firstChild);(n=o.parentNode)==null||n.replaceChild(i,o)})}function mt(r,e){const t=Array.from(r.querySelectorAll("a,b,strong,i,em,u,s,strike,del,font,mark,code,sub,sup,span,[style],[class]"));t.sort((o,i)=>fe(i)-fe(o)),t.forEach(o=>{if(o.isConnected&&ge(e,o)&&!(o.getAttribute("contenteditable")==="false"||o.closest('[contenteditable="false"]'))){if(ft(o),dt.has(o.tagName)){pe(o);return}o.tagName==="SPAN"&&o.attributes.length===0&&pe(o)}})}const bt=Object.freeze(Object.defineProperty({__proto__:null,ClearFormattingPlugin:ct},Symbol.toStringTag,{value:"Module"})),yt=Object.freeze(Object.defineProperty({__proto__:null,HeadingPlugin:()=>{const r=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?r(e):!1,setHeading1:()=>r("h1"),setHeading2:()=>r("h2"),setHeading3:()=>r("h3"),setParagraph:()=>r("p")},keymap:{"Mod-Alt-1":"setHeading1","Mod-Alt-2":"setHeading2","Mod-Alt-3":"setHeading3","Mod-Alt-0":"setParagraph"}}}},Symbol.toStringTag,{value:"Module"})),vt=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 r=window.getSelection();if(!r||r.rangeCount===0)return!1;let e=r.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 Z{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
10
|
`)}setText(e){this._lines=e.split(`
|
|
5
11
|
`),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 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),
|
|
7
|
-
`);
|
|
12
|
+
`)}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),s=i.substring(0,e.start.column)+t,a=n.substring(e.end.column),l=t.split(`
|
|
13
|
+
`);l[0]=s+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 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 Z;return e._lines=[...this._lines],e._version=this._version,e}}class xt{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
14
|
position: relative;
|
|
9
15
|
display: flex;
|
|
10
16
|
width: 100%;
|
|
@@ -47,14 +53,14 @@
|
|
|
47
53
|
`,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
54
|
`).length;this.updateLineNumbers(t)}setHTML(e){const t=/<|>/.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
55
|
`).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
|
|
51
|
-
`),o=Math.min(e.line,t.length-1),i=Math.min(e.column,((
|
|
52
|
-
`),n=t.cloneRange();n.selectNodeContents(this.contentElement),n.setEnd(t.endContainer,t.endOffset);const
|
|
53
|
-
`);return{start:{line:i.length-1,column:i[i.length-1].length},end:{line:
|
|
54
|
-
`);c.insertNode(d),c.setStartAfter(d),c.collapse(!0),o.removeAllRanges(),o.addRange(c);const
|
|
55
|
-
`);let
|
|
56
|
-
`),i=this.textModel.offsetToPosition(this.textModel.positionToOffset(e)+1);if(!this.suppressHistory){const n=this.getSelection();let
|
|
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
|
|
56
|
+
`);return{line:i.length-1,column:i[i.length-1].length}}setCursorPosition(e){var f,h;const t=this.getText().split(`
|
|
57
|
+
`),o=Math.min(e.line,t.length-1),i=Math.min(e.column,((f=t[o])==null?void 0:f.length)||0);let n=0;for(let p=0;p<o;p++)n+=t[p].length+1;n+=i;const s=document.createRange(),a=window.getSelection();let l=0,c=null,d=0;const g=document.createTreeWalker(this.contentElement,NodeFilter.SHOW_TEXT,null);let u;for(;u=g.nextNode();){const p=((h=u.textContent)==null?void 0:h.length)||0;if(l+p>=n){c=u,d=n-l;break}l+=p}if(c)try{s.setStart(c,d),s.setEnd(c,d),a==null||a.removeAllRanges(),a==null||a.addRange(s)}catch(p){console.warn("Could not set cursor position:",p)}}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(`
|
|
58
|
+
`),n=t.cloneRange();n.selectNodeContents(this.contentElement),n.setEnd(t.endContainer,t.endOffset);const s=n.toString().split(`
|
|
59
|
+
`);return{start:{line:i.length-1,column:i[i.length-1].length},end:{line:s.length-1,column:s[s.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 kt{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 Z(this.config.value),this.view=new xt(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),s=this.getSelection();let a,l;s&&(a=this.textModel.positionToOffset(s.start),l=this.textModel.positionToOffset(s.end)),this.undoStack.push({text:o,cursorOffset:n,anchorOffset:a,focusOffset:l}),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),s=this.getSelection();let a,l;s&&(a=this.textModel.positionToOffset(s.start),l=this.textModel.positionToOffset(s.end)),this.suppressHistory||(this.undoStack.push({text:this.textModel.getText(),cursorOffset:n,anchorOffset:a,focusOffset:l}),this.undoStack.length>100&&this.undoStack.shift(),this.redoStack.length=0);const c=o.getRangeAt(0);c.deleteContents();const d=document.createTextNode(`
|
|
60
|
+
`);c.insertNode(d),c.setStartAfter(d),c.collapse(!0),o.removeAllRanges(),o.addRange(c);const g=this.getCursor().position,u=this.textModel.positionToOffset(g),f=this.getSelection();let h,p;f&&(h=this.textModel.positionToOffset(f.start),p=this.textModel.positionToOffset(f.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(f&&(h!==void 0||p!==void 0)){const y=h!==void 0?h:u,x=p!==void 0?p:u,v=Math.min(y,x),H=Math.max(y,x),N=this.textModel.offsetToPosition(v),S=this.textModel.offsetToPosition(H);this.setSelection({start:N,end:S})}else{const y=this.textModel.offsetToPosition(u);this.setCursor(y)}}catch(y){}}),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(`
|
|
61
|
+
`);let s=o.caseSensitive?n:n.toLowerCase(),a=o.caseSensitive?e:e.toLowerCase();if(o.regex){const l=new RegExp(a,o.caseSensitive?"g":"gi");let c;for(;(c=l.exec(s))!==null;){const d=this.textModel.offsetToPosition(c.index),g=this.textModel.offsetToPosition(c.index+c[0].length);i.push({range:{start:d,end:g},match:c[0]})}}else{let l=0,c=s.indexOf(a,l);for(;c!==-1;){const d=c+e.length,g=this.textModel.offsetToPosition(c),u=this.textModel.offsetToPosition(d);i.push({range:{start:g,end:u},match:n.substring(c,d)}),l=d,c=s.indexOf(a,l)}}return i}replace(e,t){const o=this.getValue();if(!this.suppressHistory){const n=this.getCursor().position,s=this.textModel.positionToOffset(n),a=this.getSelection();let l,c;a&&(l=this.textModel.positionToOffset(a.start),c=this.textModel.positionToOffset(a.end)),this.undoStack.push({text:o,cursorOffset:s,anchorOffset:l,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 s=i.length-1;s>=0;s--)this.replace(i[s].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,s,a,l;if(t||i){n=this.getSelection();const d=this.getCursor().position;s=this.textModel.positionToOffset(d),n&&(a=this.textModel.positionToOffset(n.start),l=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&&(a!==void 0||l!==void 0)){const d=a!==void 0?a:s,g=l!==void 0?l:s,u=Math.min(d,g),f=Math.max(d,g),h=this.textModel.offsetToPosition(u),p=this.textModel.offsetToPosition(f);this.view.setSelectionRange({start:h,end:p})}else if(s!==void 0){const d=this.textModel.offsetToPosition(s);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,s=e.focusOffset!==void 0?e.focusOffset:i,a=Math.min(n,s),l=Math.max(n,s),c=this.textModel.offsetToPosition(a),d=this.textModel.offsetToPosition(l);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,s=e.focusOffset!==void 0?e.focusOffset:i,a=Math.min(n,s),l=Math.max(n,s),c=this.textModel.offsetToPosition(a),d=this.textModel.offsetToPosition(l);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 s=this.getSelection();let a,l;s&&(a=this.textModel.positionToOffset(s.start),l=this.textModel.positionToOffset(s.end)),this.undoStack.push({text:this.getValue(),cursorOffset:t,anchorOffset:a,focusOffset:l}),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,`
|
|
62
|
+
`),i=this.textModel.offsetToPosition(this.textModel.positionToOffset(e)+1);if(!this.suppressHistory){const n=this.getSelection();let s,a;n&&(s=this.textModel.positionToOffset(n.start),a=this.textModel.positionToOffset(n.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(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 wt{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:s}=e,a=String(t).toLowerCase(),l=this.keymap[a];if(!l)return null;for(const c of l){const d=c.ctrlKey===void 0||c.ctrlKey===o,g=c.altKey===void 0||c.altKey===i,u=c.shiftKey===void 0||c.shiftKey===n,f=c.metaKey===void 0||c.metaKey===s;if(d&&g&&u&&f)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 Ct{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 Et{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(`
|
|
63
|
+
`).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 Mt{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 St{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 Tt{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=`
|
|
58
64
|
position: absolute;
|
|
59
65
|
top: 10px;
|
|
60
66
|
right: 10px;
|
|
@@ -123,11 +129,11 @@
|
|
|
123
129
|
display: none;
|
|
124
130
|
margin-top: 4px;
|
|
125
131
|
" />
|
|
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"),
|
|
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),
|
|
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
|
|
132
|
+
`;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"),s=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))}),i.addEventListener("click",()=>this.findPrev()),n.addEventListener("click",()=>this.findNext()),s.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),s=this.getPositionFromOffset(t,i+e.length);o.push({range:{start:n,end:s},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(`
|
|
133
|
+
`),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),s=i.substring(0,n),a=i.substring(n+e.length),l=s+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(),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(`
|
|
134
|
+
`);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 Lt{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
135
|
`);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,
|
|
136
|
+
`),i=t.position.line,n=t.position.column,s=t.char;return this.bracketPairs[s]?this.findClosingBracket(e,o,i,n,s):this.reverseBracketPairs[s]?this.findOpeningBracket(e,o,i,n,s):null}findClosingBracket(e,t,o,i,n){const s=this.bracketPairs[n];let a=0;for(let l=o;l<t.length;l++){const c=t[l],d=l===o?i:0;for(let g=d;g<c.length;g++){const u=c[g];if(u===n)a++;else if(u===s&&(a--,a===0))return{open:{start:{line:o,column:i},end:{line:o,column:i+1}},close:{start:{line:l,column:g},end:{line:l,column:g+1}},type:n}}}return null}findOpeningBracket(e,t,o,i,n){const s=this.reverseBracketPairs[n];let a=0;for(let l=o;l>=0;l--){const c=t[l],d=l===o?i:c.length-1;for(let g=d;g>=0;g--){const u=c[g];if(u===n)a++;else if(u===s&&(a--,a===0))return{open:{start:{line:l,column:g},end:{line:l,column:g+1}},close:{start:{line:o,column:i},end:{line:o,column:i+1}},type:s}}}return null}highlightBrackets(e){}clearBracketHighlighting(){this.currentMatch=null}getCurrentMatch(){return this.currentMatch}destroy(){this.clearBracketHighlighting(),this.editor=null}}class At{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=`
|
|
131
137
|
position: absolute;
|
|
132
138
|
left: 40px;
|
|
133
139
|
top: 0;
|
|
@@ -150,7 +156,7 @@
|
|
|
150
156
|
color: var(--editor-gutter-foreground, #858585);
|
|
151
157
|
font-size: 10px;
|
|
152
158
|
user-select: none;
|
|
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
|
|
159
|
+
`,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 Ot{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,"&").replace(/</g,"<").replace(/>/g,">").replace(/\"/g,""").replace(/'/g,"'")}unescapeEntitiesRepeated(e){let t=e||"";for(let o=0;o<5;o++){const i=t;if(t=t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/'/g,"'"),t===i)break}return t}_highlightHTML(e,t){const o=t,i=c=>this.escapeHTML(c);let n=i(e);const s=c=>{let d=c.replace(/"/g,'"').replace(/'/g,"'");return d=d.replace(/(\/\*[\s\S]*?\*\/)/g,`<span style="color: ${o.comment};">$1</span>`),d=d.replace(/([a-zA-Z-]+)(\s*:\s*)([^;{]+)(;?)/g,(g,u,f,h,p)=>{const m=String(h).trim(),y=i(m);return`<span style="color: ${o.styleProp};">${u}</span>${f}<span style="color: ${o.styleVal};">${y}</span>${p}`}),d},a=[];try{e.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi,(c,d,g)=>(a.push({attrs:String(d||""),inner:String(g||"")}),c))}catch(c){}let l=0;return n=n.replace(/(<script\b([^&>]*)>)([\s\S]*?)(<\/script>)/gi,(c,d,g,u,f)=>{var m,y,x;const h=(y=(m=a[l++])==null?void 0:m.inner)!=null?y:this.unescapeEntitiesRepeated(u||"");(((x=a[l-1])==null?void 0:x.attrs)||g||"").toLowerCase();const p=this._highlightJS(h,o);return`${d}${p}${f}`}),n=n.replace(/(<style\b[^&]*>)([\s\S]*?)(<\/style>)/gi,(c,d,g,u)=>{const f=s(g);return`${d}${f}${u}`}),n=n.replace(/(<!--[\s\S]*?-->)/g,`<span style="color: ${o.comment};">$1</span>`),n=n.replace(/(<!DOCTYPE[\s\S]*?>)/i,`<span style="color: ${o.doctype};">$1</span>`),n=n.replace(/(<\/?\s*)([^\s&>\/]+)([\s\S]*?)(\/?>)/g,(c,d,g,u,f)=>{const h=`<span style="color: ${o.tag};">${g}</span>`;let p=u;return p=p.replace(/([\w:-]+)(\s*=\s*)(("[\s\S]*?"|'[\s\S]*?'|[^\s&>]+))/g,(m,y,x,v)=>{const H=String(y).toLowerCase(),N=`<span style="color: ${o.attrName};">${y}</span>`;let S=v,k="";v.startsWith(""")&&v.endsWith(""")?(S=v.slice(6,-6),k="""):v.startsWith("'")&&v.endsWith("'")&&(S=v.slice(5,-5),k="'");let E=v;if(H==="style"){const j=S.replace(/([\w-]+)\s*:\s*([^;]+)(;?)/g,(le,F,U,K)=>`<span style="color: ${o.styleProp};">${F}</span>:<span style="color: ${o.styleVal};">${U.trim()}</span>${K}`);k?E=`${k}${j}${k}`:E=j,E=`<span style="color: ${o.attrValue};">${E}</span>`}else k&&(E=`${k}${S}${k}`),E=`<span style="color: ${o.attrValue};">${E}</span>`;return`${N}${x}${E}`}),`${d}${h}${p}${f}`}),n}_highlightJS(e,t){const o=this.unescapeEntitiesRepeated(e);this.escapeHTML(o);const i=[],n=u=>{let f="",h=u;do f=String.fromCharCode(97+h%26)+f,h=Math.floor(h/26)-1;while(h>=0);return f||"a"},s=u=>`\0${n(u)}\0`,a=u=>{const f=i.length;return i.push(u),s(f)};let l;const c=/(\/\*[\s\S]*?\*\/)|(\/\/[^\n\r]*)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)/g;let d=0,g="";for(;l=c.exec(o);){const u=l.index;d<u&&(g+=this.escapeHTML(o.slice(d,u)));const f=l[0];/^\/\*/.test(f)||/^\/\//.test(f)?g+=a(`<span style="color: ${t.comment};">${this.escapeHTML(f)}</span>`):g+=a(`<span style="color: ${t.string};">${this.escapeHTML(f)}</span>`),d=c.lastIndex}return d<o.length&&(g+=this.escapeHTML(o.slice(d))),g=g.replace(/\b(0x[0-9a-fA-F]+|\d+\.?\d*|\d*\.\d+)\b/g,(u,f,h)=>{const p=g[h-1]||"",m=g[h+u.length]||"";return p==="&"||p==="#"||m===";"||m==="#"?u:`<span style="color: ${t.number};">${u}</span>`}),g=g.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>`),g.replace(/\u0000([a-z]+)\u0000/g,(u,f)=>{let h=0;for(let p=0;p<f.length;p++)h=h*26+(f.charCodeAt(p)-97+1);return h=h-1,i[h]||""})}_highlightPHP(e,t){const o=this.unescapeEntitiesRepeated(e);let i=this.escapeHTML(o);const n=[],s=h=>{let p="",m=h;do p=String.fromCharCode(97+m%26)+p,m=Math.floor(m/26)-1;while(m>=0);return p||"a"},a=h=>{const p=n.length;return n.push(h),`\0${s(p)}\0`},l=(h,p)=>{const m=i.indexOf(h);return m===-1?!1:(i=i.slice(0,m)+p+i.slice(m+h.length),!0)};let c;const d=/\/\*[\s\S]*?\*\//g,g=/\/\/[^\n\r]*/g,u=/\#([^\n\r]*)/g,f=/("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')/g;for(;c=d.exec(o);){const h=c[0];l(this.escapeHTML(h),a(`<span style="color: ${t.comment};">${this.escapeHTML(h)}</span>`))}for(;c=g.exec(o);){const h=c[0];l(this.escapeHTML(h),a(`<span style="color: ${t.comment};">${this.escapeHTML(h)}</span>`))}for(;c=u.exec(o);){const h=c[0];l(this.escapeHTML(h),a(`<span style="color: ${t.comment};">${this.escapeHTML(h)}</span>`))}for(;c=f.exec(o);){const h=c[0];l(this.escapeHTML(h),a(`<span style="color: ${t.string};">${this.escapeHTML(h)}</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,(h,p)=>{let m=0;for(let y=0;y<p.length;y++)m=m*26+(p.charCodeAt(y)-97+1);return m=m-1,n[m]||""}),i}shouldHighlight(e){return/<\/?[\w:-]+|<!--/.test(e)}destroy(){this.editor=null,this.modes.clear()}}function Pt(r,e){const t={...e};return t.extensions||(t.extensions=[]),t.extensions.some(o=>o.name==="keymap")||t.extensions.unshift(new wt(t.keymap)),t.extensions.some(o=>o.name==="transaction")||t.extensions.unshift(new Ct),new kt(r,t)}const G='[data-theme="dark"], .dark, .editora-theme-dark',It=`/* Source Editor Dialog Styles */
|
|
154
160
|
.rte-source-editor-overlay {
|
|
155
161
|
position: fixed !important;
|
|
156
162
|
top: 0 !important;
|
|
@@ -419,64 +425,83 @@
|
|
|
419
425
|
background: #0056b3;
|
|
420
426
|
}
|
|
421
427
|
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
}
|
|
428
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-modal {
|
|
429
|
+
background: #1e1e1e;
|
|
430
|
+
color: #f8f9fa;
|
|
431
|
+
border: 1px solid #434d5f;
|
|
432
|
+
}
|
|
428
433
|
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
434
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-header,
|
|
435
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-footer {
|
|
436
|
+
background: #2a3442;
|
|
437
|
+
border-color: #434d5f;
|
|
438
|
+
}
|
|
433
439
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
440
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-header h2 {
|
|
441
|
+
color: #f8f9fa;
|
|
442
|
+
}
|
|
437
443
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
444
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-toolbar-btn,
|
|
445
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-fullscreen-btn,
|
|
446
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-close-btn {
|
|
447
|
+
color: #c1cede;
|
|
448
|
+
}
|
|
442
449
|
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
450
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-toolbar-btn:hover:not(:disabled),
|
|
451
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-fullscreen-btn:hover,
|
|
452
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-close-btn:hover {
|
|
453
|
+
background: #404a5a;
|
|
454
|
+
color: #f8fafc;
|
|
455
|
+
}
|
|
448
456
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
}
|
|
457
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-toolbar-btn.active {
|
|
458
|
+
background: #3b82f6;
|
|
459
|
+
color: #ffffff;
|
|
460
|
+
}
|
|
454
461
|
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
border-color: #d97706;
|
|
459
|
-
}
|
|
462
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-toolbar-btn.active:hover {
|
|
463
|
+
background: #2563eb;
|
|
464
|
+
}
|
|
460
465
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
466
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-loading,
|
|
467
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-footer-info {
|
|
468
|
+
color: #cbd5e1;
|
|
469
|
+
}
|
|
465
470
|
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
471
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-spinner {
|
|
472
|
+
border-color: #3f4b60;
|
|
473
|
+
border-top-color: #58a6ff;
|
|
474
|
+
}
|
|
469
475
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
476
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-error {
|
|
477
|
+
background: #3f2124;
|
|
478
|
+
color: #fecaca;
|
|
479
|
+
border-color: #ef4444;
|
|
480
|
+
}
|
|
475
481
|
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
482
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-warning {
|
|
483
|
+
background: #3b3220;
|
|
484
|
+
color: #fde68a;
|
|
485
|
+
border-color: #f59e0b;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-btn-cancel {
|
|
489
|
+
background: #334155;
|
|
490
|
+
border-color: #475569;
|
|
491
|
+
color: #f1f5f9;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-btn-cancel:hover:not(:disabled) {
|
|
495
|
+
background: #475569;
|
|
496
|
+
border-color: #64748b;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-btn-save {
|
|
500
|
+
background: #3b82f6;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-btn-save:hover:not(:disabled) {
|
|
504
|
+
background: #2563eb;
|
|
480
505
|
}
|
|
481
506
|
|
|
482
507
|
/* Responsive design */
|
|
@@ -508,10 +533,10 @@
|
|
|
508
533
|
flex: 1;
|
|
509
534
|
text-align: center;
|
|
510
535
|
}
|
|
511
|
-
}`,
|
|
512
|
-
`+" ".repeat(
|
|
513
|
-
`+" ".repeat(
|
|
514
|
-
`+" ".repeat(
|
|
536
|
+
}`,Ht=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,c;const n=window.getSelection();if(n&&n.anchorNode){let d=n.anchorNode instanceof HTMLElement?n.anchorNode:n.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((c=d.classList)!=null&&c.contains("rte-content"))return d;const g=d.querySelector(".rte-content");if(g)return g;d=d.parentElement}}const s=document.querySelector("[data-editora-editor]");if(s){const d=s.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 s="",a=0;const l=2,c=n.split(/(<\/?[a-zA-Z][^>]*>)/);for(const d of c)d.trim()&&(d.match(/^<\/[a-zA-Z]/)?(a=Math.max(0,a-1),s+=`
|
|
537
|
+
`+" ".repeat(a*l)+d):d.match(/^<[a-zA-Z]/)&&!d.match(/\/>$/)?(s+=`
|
|
538
|
+
`+" ".repeat(a*l)+d,a++):d.match(/^<[a-zA-Z].*\/>$/)?s+=`
|
|
539
|
+
`+" ".repeat(a*l)+d:s+=d.trim());return s.trim()};return(()=>{var F,U,K,Oe,Pe,Ie;let n=null,s="dark",a=!1,l=!1,c=!1;const d=t,g=!!e.closest(G)||document.body.matches(G)||document.documentElement.matches(G),u=document.createElement("div");u.className="rte-source-editor-overlay",g&&u.classList.add("rte-theme-dark");const f=document.createElement("div");f.className="rte-source-editor-modal",f.setAttribute("role","dialog"),f.setAttribute("aria-modal","true"),f.setAttribute("aria-labelledby","source-editor-title");const h=document.createElement("div");h.className="rte-source-editor-header",h.innerHTML=`
|
|
515
540
|
<h2 id="source-editor-title">Source Editor</h2>
|
|
516
541
|
<div class="rte-source-editor-header-toolbar">
|
|
517
542
|
<button class="rte-source-editor-toolbar-btn theme-toggle-btn" title="Switch theme">
|
|
@@ -547,7 +572,7 @@
|
|
|
547
572
|
</svg>
|
|
548
573
|
</button>
|
|
549
574
|
</div>
|
|
550
|
-
`;const p=document.createElement("div");p.className="rte-source-editor-body";const
|
|
575
|
+
`;const p=document.createElement("div");p.className="rte-source-editor-body";const m=document.createElement("div");m.className="rte-source-editor-content";const y=document.createElement("div");y.className="rte-source-editor-warning",y.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",m.appendChild(y),m.appendChild(x),p.appendChild(m);const v=document.createElement("div");if(v.className="rte-source-editor-footer",v.innerHTML=`
|
|
551
576
|
<div class="rte-source-editor-footer-info">
|
|
552
577
|
<span class="unsaved-changes" style="display: none;">• Unsaved changes</span>
|
|
553
578
|
</div>
|
|
@@ -555,11 +580,11 @@
|
|
|
555
580
|
<button class="rte-source-editor-btn rte-source-editor-btn-cancel">Cancel</button>
|
|
556
581
|
<button class="rte-source-editor-btn rte-source-editor-btn-save">Save</button>
|
|
557
582
|
</div>
|
|
558
|
-
`,
|
|
583
|
+
`,f.appendChild(h),f.appendChild(p),f.appendChild(v),u.appendChild(f),!document.getElementById("rte-source-editor-styles")){const b=document.createElement("style");b.id="rte-source-editor-styles",b.textContent=It,document.head.appendChild(b)}document.body.appendChild(u);try{n=Pt(x,{value:o(t),theme:"dark",readOnly:!1,extensions:[new Et,new Mt,new St,new Lt,new Tt,new At,new Ot]}),n.on("change",()=>{c=((n==null?void 0:n.getValue())||"")!==o(d);const P=v.querySelector(".unsaved-changes");P&&(P.style.display=c?"inline":"none")}),setTimeout(()=>n==null?void 0:n.focus(),100)}catch(b){console.error("Failed to initialize code editor:",b)}const H=()=>{s=s==="dark"?"light":"dark",n==null||n.setTheme(s);const b=h.querySelector(".theme-toggle-btn");b&&s==="light"&&(b.innerHTML=`
|
|
559
584
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
560
585
|
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>
|
|
561
586
|
</svg>
|
|
562
|
-
`)},
|
|
587
|
+
`)},N=()=>{a=!a,n==null||n.setReadOnly(a);const b=h.querySelector(".readonly-toggle-btn");b&&(a?(b.classList.add("active"),b.innerHTML=`
|
|
563
588
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
564
589
|
<rect x="3" y="11" width="18" height="11" rx="2" ry="2"/>
|
|
565
590
|
<circle cx="12" cy="16" r="1"/>
|
|
@@ -570,7 +595,7 @@
|
|
|
570
595
|
<path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/>
|
|
571
596
|
<path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>
|
|
572
597
|
</svg>
|
|
573
|
-
`))},
|
|
598
|
+
`))},S=()=>{l=!l,l?(u.classList.add("fullscreen"),x.style.height="calc(100vh - 200px)"):(u.classList.remove("fullscreen"),x.style.height="400px");const b=h.querySelector(".rte-source-editor-fullscreen-btn");b&&(b.innerHTML=l?`
|
|
574
599
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
575
600
|
<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"/>
|
|
576
601
|
</svg>
|
|
@@ -578,5 +603,5 @@
|
|
|
578
603
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
579
604
|
<path d="M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"/>
|
|
580
605
|
</svg>
|
|
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"})}));
|
|
606
|
+
`)},k=()=>{n&&(n.destroy(),n=null),document.body.removeChild(u)},E=()=>{c&&!confirm("You have unsaved changes. Are you sure you want to cancel?")||k()},j=()=>{try{const b=(n==null?void 0:n.getValue())||"",P=document.createElement("div");P.innerHTML=b,P.querySelectorAll('script, iframe[src^="javascript:"], object, embed').forEach(jt=>jt.remove()),e.innerHTML=P.innerHTML,c=!1,k()}catch(b){alert("Failed to update HTML. Please check your syntax."),console.error("HTML update error:",b)}};(F=h.querySelector(".theme-toggle-btn"))==null||F.addEventListener("click",H),(U=h.querySelector(".readonly-toggle-btn"))==null||U.addEventListener("click",N),(K=h.querySelector(".rte-source-editor-fullscreen-btn"))==null||K.addEventListener("click",S),(Oe=h.querySelector(".rte-source-editor-close-btn"))==null||Oe.addEventListener("click",k),(Pe=v.querySelector(".rte-source-editor-btn-cancel"))==null||Pe.addEventListener("click",E),(Ie=v.querySelector(".rte-source-editor-btn-save"))==null||Ie.addEventListener("click",j),u.addEventListener("click",b=>{b.target===u&&k()});const le=b=>{b.key==="Escape"&&(k(),document.removeEventListener("keydown",le))};document.addEventListener("keydown",le)})(),!0}},keymap:{"Mod-Shift-s":"toggleSourceView","Mod-Shift-S":"toggleSourceView"}})},Symbol.toStringTag,{value:"Module"})),X=()=>me("insertUnorderedList"),Y=()=>me("insertOrderedList");function Nt(){const r=window.getSelection();if(r&&r.rangeCount>0){const t=r.getRangeAt(0).startContainer,o=t.nodeType===Node.ELEMENT_NODE?t:t.parentElement,i=o==null?void 0:o.closest('[contenteditable="true"], .rte-content, .editora-content');if(i)return i}const e=document.activeElement;return e?e.getAttribute("contenteditable")==="true"?e:e.closest('[contenteditable="true"], .rte-content, .editora-content'):null}function Dt(r){r.querySelectorAll('ul:not([data-type="checklist"]), ol').forEach(t=>{Array.from(t.childNodes).forEach(i=>{if(i.nodeType===Node.TEXT_NODE){const s=(i.textContent||"").trim();if(!s){t.removeChild(i);return}const a=document.createElement("li");a.textContent=s,t.replaceChild(a,i);return}if(!(i instanceof HTMLElement)){t.removeChild(i);return}if(i.tagName==="LI")return;const n=document.createElement("li");for(;i.firstChild;)n.appendChild(i.firstChild);t.replaceChild(n,i)})})}function me(r){const e=Nt();if(!e)return!1;const t=window.getSelection();if(!t||t.rangeCount===0)return!1;const o=t.getRangeAt(0);if(!e.contains(o.commonAncestorContainer))return!1;e.focus({preventScroll:!0});const i=document.execCommand(r,!1);return Dt(e),e.dispatchEvent(new Event("input",{bubbles:!0})),i!==!1}const be=(r,e)=>{var t;typeof window!="undefined"&&((t=window.registerEditorCommand)==null||t.call(window,r,e))},ye=()=>{be("toggleBulletList",X),be("toggleOrderedList",Y)};typeof window!="undefined"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",ye):ye());const Rt=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:X,toggleOrderedList:Y},keymap:{"Mod-Shift-8":"toggleBulletList","Mod-Shift-7":"toggleOrderedList"}}),toggleBulletList:X,toggleOrderedList:Y},Symbol.toStringTag,{value:"Module"})),ve=".rte-content, .editora-content",xe=100,ke="__editoraCommandEditorRoot",A=new Map,J={};let we=!1,w=null;function Bt(r){if(!r)return null;const e=r.querySelector('[contenteditable="true"]');return e instanceof HTMLElement?e:null}function zt(){if(typeof window=="undefined")return null;const r=window[ke];if(!(r instanceof HTMLElement))return null;window[ke]=null;const e=r.closest("[data-editora-editor], .rte-editor, .editora-editor, editora-editor")||(r.matches("[data-editora-editor], .rte-editor, .editora-editor, editora-editor")?r:null);if(e){const o=Bt(e);if(o)return o;if(e.getAttribute("contenteditable")==="true")return e}if(r.getAttribute("contenteditable")==="true")return r;const t=r.closest('[contenteditable="true"]');return t instanceof HTMLElement?t:null}function $t(r){return r?r.nodeType===Node.ELEMENT_NODE?r:r.parentElement:null}function I(r){const e=$t(r);if(!e)return null;const t=e.closest(ve);if(t)return t;const o=e.closest('[contenteditable="true"]');if(!o)return null;let i=o,n=i.parentElement;for(;n;)n.getAttribute("contenteditable")==="true"&&(i=n),n=n.parentElement;return i}function B(){const r=zt();if(r&&document.contains(r))return r;const e=window.getSelection();if(e&&e.rangeCount>0){const n=I(e.getRangeAt(0).startContainer);if(n)return n}const t=document.activeElement;if(t){const n=I(t);if(n)return n}if(w!=null&&w.isConnected)return w;const o=Array.from(A.keys()).find(n=>n.isConnected);if(o)return o;const i=document.querySelector(ve);return i||document.querySelector('[contenteditable="true"]')}function Ce(){for(const r of A.keys())r.isConnected||(A.delete(r),w===r&&(w=null))}function Q(r){Ce();let e=A.get(r);return e||(e={undoStack:[],redoStack:[]},A.set(r,e)),e}function O(r){r&&r.dispatchEvent(new Event("input",{bubbles:!0}))}function Ee(r){return r?r.innerHTML:""}function z(r,e){if(!r)return;const t=Q(r);t.undoStack.push(e),t.redoStack.length=0,t.undoStack.length>xe&&t.undoStack.splice(0,t.undoStack.length-xe),w=r}function Me(r,e="undo"){if(Ce(),r!=null&&r.isConnected)return r;const t=B();if(t!=null&&t.isConnected)return t;if(w!=null&&w.isConnected)return w;const o=i=>e==="undo"?i.undoStack.length>0:i.redoStack.length>0;for(const[i,n]of A.entries())if(i.isConnected&&o(n))return i;return null}function Se(r){const e={};for(const i of r.getAttributeNames()){const n=r.getAttribute(i);n!==null&&(e[i]=n)}const t=r instanceof HTMLInputElement||r instanceof HTMLTextAreaElement||r instanceof HTMLSelectElement,o=r instanceof HTMLInputElement;return{attributes:e,innerHTML:r.innerHTML,value:t?r.value:null,checked:o?r.checked:null}}function Te(r,e){const t=new Set(r.getAttributeNames());Object.keys(e.attributes).forEach(o=>t.delete(o)),t.forEach(o=>r.removeAttribute(o)),Object.entries(e.attributes).forEach(([o,i])=>{r.setAttribute(o,i)}),r.innerHTML!==e.innerHTML&&(r.innerHTML=e.innerHTML),e.value!==null&&(r instanceof HTMLInputElement||r instanceof HTMLTextAreaElement||r instanceof HTMLSelectElement)&&(r.value=e.value),e.checked!==null&&r instanceof HTMLInputElement&&(r.checked=e.checked)}function M(r,e){if(J[r]=e,typeof window=="undefined")return;const t=window.registerEditorCommand;typeof t=="function"?t(r,e):(window.registerEditorCommand=(o,i)=>{J[o]=i},window.registerEditorCommand(r,e))}const Le=(r,...e)=>{const t=J[r];return t?t(...e):!1};function ee(){we||typeof window=="undefined"||(we=!0,window.execEditorCommand||(window.execEditorCommand=Le),window.executeEditorCommand||(window.executeEditorCommand=Le),M("undo",te),M("redo",oe),M("setAttribute",ie),M("setText",ne),M("autoFixA11y",re),M("recordDomTransaction",se),M("undoDom",$),M("redoDom",_))}function Ae(r,e){const t=e||B(),o=Ee(t);t==null||t.focus({preventScroll:!0});let i=!1;try{i=!!document.execCommand(r,!1)}catch(a){i=!1}const n=Ee(t),s=o!==n;return s&&O(t),{executed:i,changed:s}}const te=()=>{const r=B();return Ae("undo",r).changed?!0:$(r)},oe=()=>{const r=B();return Ae("redo",r).changed?!0:_(r)},ie=(r,e,t)=>{if(!(r instanceof HTMLElement))return;const o=I(r),i=r.hasAttribute(e),n=r.getAttribute(e);r.setAttribute(e,t),z(o,{undo:()=>{r.isConnected&&(i&&n!==null?r.setAttribute(e,n):r.removeAttribute(e))},redo:()=>{r.isConnected&&r.setAttribute(e,t)}}),O(o)},ne=(r,e)=>{var i;if(!(r instanceof HTMLElement))return;const t=I(r),o=(i=r.textContent)!=null?i:"";r.textContent=e,z(t,{undo:()=>{r.isConnected&&(r.textContent=o)},redo:()=>{r.isConnected&&(r.textContent=e)}}),O(t)},re=r=>{var s;const e=r==null?void 0:r.element;if(!(e instanceof HTMLElement))return;const t=I(e),o=(s=window.a11yRuleRegistry)==null?void 0:s.find(a=>a.id===r.rule);if(!o||typeof o.fix!="function")return;const i=Se(e);o.fix(r);const n=Se(e);z(t,{undo:()=>{e.isConnected&&Te(e,i)},redo:()=>{e.isConnected&&Te(e,n)}}),O(t)},se=(r,e,t)=>{if(!(r instanceof HTMLElement))return!1;const o=typeof t=="string"?t:r.innerHTML;return e===o?!1:(z(r,{undo:()=>{r.isConnected&&(r.innerHTML=e)},redo:()=>{r.isConnected&&(r.innerHTML=o)}}),!0)},$=r=>{const e=Me(r,"undo");if(!e)return!1;const t=Q(e),o=t.undoStack.pop();return o?(o.undo(),t.redoStack.push(o),w=e,O(e),!0):!1},_=r=>{const e=Me(r,"redo");if(!e)return!1;const t=Q(e),o=t.redoStack.pop();return o?(o.redo(),t.undoStack.push(o),w=e,O(e),!0):!1};typeof window!="undefined"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",ee,{once:!0}):ee());const _t=Object.freeze(Object.defineProperty({__proto__:null,HistoryPlugin:()=>(ee(),{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:te,redo:oe,setAttribute:ie,setText:ne,autoFixA11y:re,recordDomTransaction:se,undoDom:$,redoDom:_},keymap:{"Mod-z":"undo","Mod-Z":"undo","Mod-y":"redo","Mod-Y":"redo","Mod-Shift-z":"redo","Mod-Shift-Z":"redo"}}),autoFixA11y:re,recordDomTransaction:se,redo:oe,redoDom:_,setAttribute:ie,setText:ne,undo:te,undoDom:$},Symbol.toStringTag,{value:"Module"}));T.initWebComponent=he,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})}));
|
|
582
607
|
//# sourceMappingURL=webcomponent-core.min.js.map
|