@editora/core 1.0.8 → 1.0.9
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 +5 -0
- package/dist/{A11yCheckerPlugin.native-BRdGYMju.mjs → A11yCheckerPlugin.native-58d12bed.mjs} +23 -12
- package/dist/{AnchorPlugin.native-BcYGEtd9.mjs → AnchorPlugin.native-289a112a.mjs} +112 -102
- package/dist/{ApprovalWorkflowPlugin.native-C3jtAYjG.mjs → ApprovalWorkflowPlugin.native-449ce66c.mjs} +79 -40
- package/dist/{BackgroundColorPlugin.native-50iAT9xU.mjs → BackgroundColorPlugin.native-8aceb5cc.mjs} +16 -9
- package/dist/{BlockquotePlugin.native-JFmOLsxN.mjs → BlockquotePlugin.native-3541c714.mjs} +3 -2
- package/dist/{BlocksLibraryPlugin.native-HMWKxWNs.mjs → BlocksLibraryPlugin.native-1cc51e63.mjs} +119 -60
- package/dist/{BoldPlugin.native-BAzzoqU5.mjs → BoldPlugin.native-f9d7f8e4.mjs} +1 -1
- package/dist/{CapitalizationPlugin.native-DOMsh5R7.mjs → CapitalizationPlugin.native-42c135dc.mjs} +3 -2
- package/dist/{ChecklistPlugin.native-nuSSEFNI.mjs → ChecklistPlugin.native-3b397ee9.mjs} +43 -22
- package/dist/{CitationsPlugin.native-BnU0qCwR.mjs → CitationsPlugin.native-169fb1e8.mjs} +137 -69
- package/dist/{ClearFormattingPlugin.native-Bq_XcTh2.mjs → ClearFormattingPlugin.native-77baa514.mjs} +11 -6
- package/dist/{CodePlugin.native-DlpTPdkd.mjs → CodePlugin.native-989cf0aa.mjs} +629 -580
- package/dist/{CodeSamplePlugin.native-CgGoH-X4.mjs → CodeSamplePlugin.native-6cc0148e.mjs} +19 -10
- package/dist/{CommentsPlugin.native-DPSqTkiv.mjs → CommentsPlugin.native-03659874.mjs} +55 -28
- package/dist/{ConditionalContentPlugin.native-CfhY46rU.mjs → ConditionalContentPlugin.native-4983143a.mjs} +108 -51
- package/dist/{ContentRulesPlugin.native-nBLQ8QFZ.mjs → ContentRulesPlugin.native-63ed405b.mjs} +100 -50
- package/dist/{DataBindingPlugin.native-jQ1JPRTp.mjs → DataBindingPlugin.native-427e9d75.mjs} +79 -40
- package/dist/{DirectionPlugin.native-CDnbdNyl.mjs → DirectionPlugin.native-4e742f42.mjs} +19 -10
- package/dist/{DocSchemaPlugin.native-CHOge18O.mjs → DocSchemaPlugin.native-8e41eda0.mjs} +115 -58
- package/dist/{DocumentManagerPlugin.native-C2cs_1w4.mjs → DocumentManagerPlugin.native-e69895ad.mjs} +4 -4
- package/dist/{EmbedIframePlugin.native-DKJx2OS7.mjs → EmbedIframePlugin.native-55209c87.mjs} +70 -70
- package/dist/{EmojisPlugin.native-CitxxlWX.mjs → EmojisPlugin.native-65c5ac47.mjs} +11 -6
- package/dist/{FontFamilyPlugin.native-j8hMTbg4.mjs → FontFamilyPlugin.native-f9bc255a.mjs} +7 -4
- package/dist/{FontSizePlugin.native-B_jCh7dY.mjs → FontSizePlugin.native-f5647872.mjs} +19 -10
- package/dist/{FootnotePlugin.native-D730OGRm.mjs → FootnotePlugin.native-494657b3.mjs} +77 -39
- package/dist/{FullscreenPlugin.native-ChXyxeNw.mjs → FullscreenPlugin.native-87ce92e9.mjs} +1 -1
- package/dist/{HeadingPlugin.native-DrLYwQnQ.mjs → HeadingPlugin.native-e38c4a16.mjs} +1 -1
- package/dist/{HistoryPlugin.native-TDnVMsEO.mjs → HistoryPlugin.native-92ed4be4.mjs} +43 -22
- package/dist/{IndentPlugin.native-BHixp8sP.mjs → IndentPlugin.native-e4ee902b.mjs} +23 -12
- package/dist/{ItalicPlugin.native-CQjjDyUL.mjs → ItalicPlugin.native-7c95cfbc.mjs} +1 -1
- package/dist/{LineHeightPlugin.native-CM7iXdQj.mjs → LineHeightPlugin.native-5668f78c.mjs} +19 -10
- package/dist/{LinkPlugin.native-DYCIcdTm.mjs → LinkPlugin.native-6df29111.mjs} +9 -5
- package/dist/{ListPlugin.native-V7EZC1lM.mjs → ListPlugin.native-fe2e115a.mjs} +9 -5
- package/dist/{MathPlugin.native-f_mDp8VL.mjs → MathPlugin.native-735bbac2.mjs} +9 -5
- package/dist/{MediaManagerPlugin.native-BiXiK8FC.mjs → MediaManagerPlugin.native-3cf48a00.mjs} +219 -207
- package/dist/{MentionPlugin.native-BMDlOqur.mjs → MentionPlugin.native-3b1e8c05.mjs} +89 -45
- package/dist/{MergeTagPlugin.native-C3eOfEgw.mjs → MergeTagPlugin.native-31cf7d48.mjs} +51 -26
- package/dist/{PIIRedactionPlugin.native-DcsjmtV1.mjs → PIIRedactionPlugin.native-7ab10b9f.mjs} +107 -54
- package/dist/{PageBreakPlugin.native-DijGuHJZ.mjs → PageBreakPlugin.native-1794c5fb.mjs} +31 -16
- package/dist/{PreviewPlugin.native-WuIwOAOR.mjs → PreviewPlugin.native-f7b67cc0.mjs} +11 -6
- package/dist/{PrintPlugin.native-7qt5v7L5.mjs → PrintPlugin.native-f6a168c2.mjs} +5 -3
- package/dist/{SlashCommandsPlugin.native-CmxvMEaE.mjs → SlashCommandsPlugin.native-8d45e511.mjs} +72 -37
- package/dist/{SmartPastePlugin.native-BOKKtF07.mjs → SmartPastePlugin.native-a6c5efec.mjs} +99 -50
- package/dist/{SpecialCharactersPlugin.native-CZDato89.mjs → SpecialCharactersPlugin.native-7f06d4ba.mjs} +17 -9
- package/dist/{SpellCheckPlugin.native-BZB9AewP.mjs → SpellCheckPlugin.native-04e20834.mjs} +41 -21
- package/dist/{StrikethroughPlugin.native-0Be7j49s.mjs → StrikethroughPlugin.native-905e9501.mjs} +9 -5
- package/dist/{TablePlugin.native-DrHX-efe.mjs → TablePlugin.native-7d5458c1.mjs} +58 -30
- package/dist/{TemplatePlugin.native-CrpfKRJ8.mjs → TemplatePlugin.native-580f0f63.mjs} +32 -17
- package/dist/{TextAlignmentPlugin.native-sM_1s00t.mjs → TextAlignmentPlugin.native-9357b3ed.mjs} +11 -6
- package/dist/{TextColorPlugin.native-Bwl_bSmc.mjs → TextColorPlugin.native-d53ed459.mjs} +26 -14
- package/dist/{TrackChangesPlugin.native-Bghu2q4a.mjs → TrackChangesPlugin.native-e96da509.mjs} +115 -58
- package/dist/{TranslationWorkflowPlugin.native-Bz6jDGvj.mjs → TranslationWorkflowPlugin.native-4e711b1e.mjs} +160 -91
- package/dist/{UnderlinePlugin.native-QpIcK4L2.mjs → UnderlinePlugin.native-8080c998.mjs} +1 -1
- package/dist/{VersionDiffPlugin.native-Bvxgy--t.mjs → VersionDiffPlugin.native-5bbeff85.mjs} +51 -26
- package/dist/_commonjsHelpers-69d58be2.mjs +31 -0
- package/dist/{anchoredPopover-Bxds0VoB.mjs → anchoredPopover-5cca53ba.mjs} +1 -1
- package/dist/documentManager-8327fb6e.mjs +9166 -0
- package/dist/{editorContainerHelpers-C7kdWnS0.mjs → editorContainerHelpers-69585c07.mjs} +3 -2
- package/dist/editora.min.js +14 -13
- package/dist/editora.umd.js +14 -13
- package/dist/{html2canvas.esm-AYkPY5LS.mjs → html2canvas.esm-c51cb3b9.mjs} +978 -894
- package/dist/index-072ef022.js +11 -0
- package/dist/index-49d31221.mjs +16860 -0
- package/dist/{index-DqC57IEH.mjs → index-7da30697.mjs} +163 -124
- package/dist/index.cjs.js +1 -1
- package/dist/index.es-b47a189f.mjs +5782 -0
- package/dist/index.esm.js +12 -7
- package/dist/{jspdf.es.min-BJGtOnRT.mjs → jspdf.es.min-780c82db.mjs} +4808 -3784
- package/dist/plugin-loader.js +67 -67
- package/dist/{purify.es-CKpwg8Tk.mjs → purify.es-3bdbcfc5.mjs} +20 -10
- package/dist/style.css +1 -0
- package/dist/webcomponent-core.js +164 -125
- package/dist/webcomponent-core.min.css +1 -1
- package/dist/webcomponent-core.min.js +18 -17
- package/dist/webcomponent.cjs.js +1 -1
- package/dist/webcomponent.esm.js +1 -1
- package/dist/webcomponent.js +226 -187
- package/dist/webcomponent.min.css +1 -1
- package/dist/webcomponent.min.js +1324 -1117
- package/package.json +11 -5
- package/LICENSE +0 -21
- package/dist/_commonjsHelpers-DOllISpa.mjs +0 -32
- package/dist/core.css +0 -1
- package/dist/documentManager-vQ1VkbUY.mjs +0 -8418
- package/dist/index-BslAFzmv.mjs +0 -16544
- package/dist/index-D1LOqg5C.js +0 -10
- package/dist/index.es-BYD2KEo6.mjs +0 -6666
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(H,N){typeof exports=="object"&&typeof module!="undefined"?N(exports):typeof define=="function"&&define.amd?define(["exports"],N):(H=typeof globalThis!="undefined"?globalThis:H||self,N(H.EditoraCore={}))})(this,(function(H){"use strict";class N{constructor(){this.loadedPlugins=new Map,this.pluginRegistry=new Map}register(e,t){this.pluginRegistry.set(e,t)}async load(e,t){if(this.loadedPlugins.has(e))return this.loadedPlugins.get(e);const n=this.pluginRegistry.get(e);if(!n)return console.warn(`Plugin not found: ${e}`),null;const i=await n();return t&&this.applyPluginConfig(i,t),this.loadedPlugins.set(e,i),i}async loadMultiple(e,t){return(await Promise.all(e.map(i=>this.load(i,t)))).filter(i=>i!==null)}async parsePluginString(e,t){const n=e.split(/\s+/).filter(Boolean);return this.loadMultiple(n,t)}applyPluginConfig(e,t){e.__pluginConfig=t}unload(e){this.loadedPlugins.delete(e)}clear(){this.loadedPlugins.clear()}getLoadedPlugins(){return Array.from(this.loadedPlugins.values())}getRegisteredPluginNames(){return Array.from(this.pluginRegistry.keys())}isLoaded(e){return this.loadedPlugins.has(e)}}class V{constructor(e,t,n){this.doc=e,this.selection=t,this.schema=n}static create(e,t){const n=t||e.node("doc",{},[e.node("paragraph")]);return new V(n,{anchor:0,head:0},e)}apply(e,t){return new V(e,t||this.selection,this.schema)}}class Ze{constructor(e,t){this.nodes=new Map(Object.entries(e)),this.marks=new Map(Object.entries(t))}node(e,t,n){return{type:e,attrs:t,content:n}}text(e,t){return{type:"text",text:e,marks:t}}}class Qe{constructor(){this.plugins=[],this.pluginConfigs=new Map}register(e,t){this.plugins.push(e),t&&this.pluginConfigs.set(e.name,t);const n=this.pluginConfigs.get(e.name)||e.config;if(e.initialize)try{e.initialize(n)}catch(i){console.error(`Failed to initialize plugin "${e.name}":`,i)}if(e.init&&e.init!==e.initialize)try{e.init(n)}catch(i){console.error(`Failed to run init hook for plugin "${e.name}":`,i)}}unregister(e){const t=this.plugins.findIndex(n=>n.name===e);if(t>-1){const n=this.plugins[t];n.destroy&&n.destroy(),this.plugins.splice(t,1),this.pluginConfigs.delete(e)}}getPlugin(e){return this.plugins.find(t=>t.name===e)}getPluginConfig(e){return this.pluginConfigs.get(e)}buildSchema(){const e={},t={};return this.plugins.forEach(n=>{n.nodes&&Object.assign(e,n.nodes),n.marks&&Object.assign(t,n.marks)}),new Ze(e,t)}getCommands(){const e={};return this.plugins.forEach(t=>{t.commands&&Object.assign(e,t.commands)}),e}getToolbarItems(){return this.plugins.flatMap(e=>e.toolbar||[])}async executePluginCommand(e,t,...n){const i=this.getPlugin(e);if(!i)throw new Error(`Plugin not found: ${e}`);const o=this.getPluginConfig(e)||i.config||{},s=o.mode||"local";try{switch(s){case"local":return i.executeLocal?i.executeLocal(t,...n):null;case"api":if(!i.executeAPI)throw new Error(`Plugin ${e} does not support API mode`);return await i.executeAPI(t,...n);case"hybrid":if(i.executeHybrid)return await i.executeHybrid(t,...n);try{if(i.executeAPI)return await i.executeAPI(t,...n)}catch(a){if(console.warn(`API execution failed for ${e}, falling back to local`,a),i.executeLocal&&o.fallbackToLocal!==!1)return i.executeLocal(t,...n);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 Xe{constructor(e={}){this.commands=new Map,Object.entries(e).forEach(([t,n])=>{this.register(t,n)})}register(e,t){this.commands.has(e)&&console.warn(`Command ${e} is being overwritten`),this.commands.set(e,t)}unregister(e){this.commands.delete(e)}get(e){return this.commands.get(e)}has(e){return this.commands.has(e)}getCommandNames(){return Array.from(this.commands.keys())}clear(){this.commands.clear()}}class Ye{constructor(e={}){this.listeners=new Map,this.isReadonly=!1,this.isDestroyed=!1,this.isReadonly=e.readonly||!1,this.pluginManager=new Qe,e.plugins&&Array.isArray(e.plugins)&&e.plugins.forEach(n=>this.pluginManager.register(n));const t=this.pluginManager.buildSchema();this.state=V.create(t),this.commandRegistry=new Xe(this.pluginManager.getCommands())}execCommand(e,t){if(this.isReadonly)return console.warn("Cannot execute commands in readonly mode"),!1;if(this.isDestroyed)return console.warn("Cannot execute commands on destroyed editor"),!1;const n=this.commandRegistry.get(e);if(!n)return console.warn(`Command not found: ${e}`),!1;let i;return t!==void 0?i=n(this.state,t):i=n(this.state),i instanceof Promise?(i.then(o=>{o&&typeof o=="object"&&"doc"in o&&"selection"in o&&(this.setState(o),this.emit("change",this.state))}).catch(o=>{console.error(`Async command failed: ${e}`,o)}),!0):i&&typeof i=="object"&&"doc"in i&&"selection"in i?(this.setState(i),this.emit("change",this.state),!0):i!==!1&&i!=null}setState(e){this.isDestroyed||(this.state=e,this.emit("stateChange",e))}getState(){return this.state}setReadonly(e){this.isReadonly=e,this.emit("readonlyChange",e)}isReadOnly(){return this.isReadonly}on(e,t){return this.listeners.has(e)||this.listeners.set(e,[]),this.listeners.get(e).push(t),()=>{const n=this.listeners.get(e);if(n){const i=n.indexOf(t);i>-1&&n.splice(i,1)}}}emit(e,...t){const n=this.listeners.get(e);n&&n.forEach(i=>{try{i(...t)}catch(o){console.error(`Error in ${e} handler:`,o)}})}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.listeners.clear(),this.emit("destroy"))}isEditorDestroyed(){return this.isDestroyed}}class Ge{setLastCommandTrigger(e,t){if(typeof window=="undefined"||!e)return;const n=t||e.getAttribute("data-command")||void 0;n&&(window.__editoraLastCommandButton=e,window.__editoraLastCommand=n)}constructor(e,t,n){this.config=e,this.plugins=t,this.pluginLoader=n}setCommandHandler(e){this.commandHandler=e}parseToolbarString(e){const t=[],n=e.split("|").map(a=>a.trim()),i=this.getAvailableToolbarItems(),o=new Map;i.forEach(a=>{a.command&&o.set(a.command,a),a.type==="group"&&a.label&&o.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",trackChanges:"toggleTrackChanges",acceptTrackChanges:"acceptAllTrackChanges",rejectTrackChanges:"rejectAllTrackChanges",anchor:"insertAnchor",code:"toggleSourceView",blockquote:"toggleBlockquote",undo:"undo",redo:"redo",textColor:"openTextColorPicker",backgroundColor:"openBackgroundColorPicker",fontSize:"fontSize",fontFamily:"setFontFamily",lineHeight:"setLineHeight",heading:"setBlockType",paragraph:"setParagraph",textAlignment:"setTextAlignment",direction:"setDirectionLTR",indent:"increaseIndent",outdent:"decreaseIndent",capitalization:"setCapitalization",math:"insertMath",specialCharacters:"insertSpecialCharacter",emojis:"openEmojiDialog",embedIframe:"openEmbedIframeDialog",fullscreen:"toggleFullscreen",preview:"togglePreview",print:"print",a11yChecker:"toggleA11yChecker",spellCheck:"toggleSpellCheck",comments:"addComment",showHideComments:"toggleComments",toggleComments:"toggleComments",footnote:"insertFootnote",mergeTags:"insertMergeTag",dataBinding:"openDataBindingDialog",dataBindingPreview:"openDataBindingDialog",contentRules:"toggleContentRulesPanel",contentRulesAudit:"runContentRulesAudit",contentRulesRealtime:"toggleContentRulesRealtime",mention:"insertMention",slash:"openSlashCommands",slashCommands:"openSlashCommands",pageBreak:"insertPageBreak",template:"insertTemplate",importWord:"importWord",exportWord:"exportWord",exportPdf:"exportPdf",insertImage:"insertImage",insertVideo:"insertVideo",codeBlock:"insertCodeBlock"};return n.forEach(a=>{const l=[];a.split(/\s+/).filter(Boolean).forEach(c=>{if(c==="direction"){const f=o.get("setDirectionLTR"),g=o.get("setDirectionRTL");f&&l.push({id:"directionLTR",label:f.label,command:f.command,icon:f.icon,type:f.type||"button",options:f.options}),g&&l.push({id:"directionRTL",label:g.label,command:g.command,icon:g.icon,type:g.type||"button",options:g.options});return}if(c==="comments"){const f=o.get("addComment"),g=o.get("toggleComments");f&&l.push({id:"addComment",label:f.label,command:f.command,icon:f.icon,type:f.type||"button",options:f.options}),g&&l.push({id:"toggleComments",label:g.label,command:g.command,icon:g.icon,type:g.type||"button",options:g.options});return}const h=s[c]||c;let u=o.get(h);u||(u=o.get(c)),u&&l.push({id:c,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(),n=this.parseToolbarString(t);n.forEach((i,o)=>{const s=document.createElement("div");if(s.className="editora-toolbar-group",i.forEach(a=>{this.appendToolbarButton(s,a)}),e.appendChild(s),o<n.length-1){const a=document.createElement("div");a.className="editora-toolbar-separator",e.appendChild(a)}})}appendToolbarButton(e,t){if(t.type==="separator"){const n=document.createElement("div");n.className="editora-toolbar-separator",e.appendChild(n)}else if(t.type==="dropdown"){const n=this.createDropdown(t);e.appendChild(n)}else if(t.type==="inline-menu"){const n=this.createInlineMenu(t);e.appendChild(n)}else if(t.type==="group"&&t.items&&t.items.length){const n=this.createGroupButton(t);e.appendChild(n)}else if(t.type==="input"){const n=this.createInput(t);e.appendChild(n)}else{const n=this.createButton(t);e.appendChild(n)}}createGroupButton(e){const t=document.createElement("div"),n=e.label.toLowerCase().replace(/\s+/g,"-");if(t.className=`editora-toolbar-group-button ${n}`,t.title=e.label,e.icon)if(e.icon.startsWith("<svg")&&e.icon.endsWith("</svg>")){const i=document.createElement("span");i.className="editora-toolbar-icon",i.innerHTML=e.icon,t.appendChild(i)}else t.innerHTML=e.icon;if(e.items&&e.items.length){const i=document.createElement("div");i.className=`editora-toolbar-group-items ${n}`,e.items.forEach(o=>{this.appendToolbarButton(i,o)}),t.appendChild(i)}return t}createInput(e){const t=document.createElement("input");return t.className=`editora-toolbar-input ${e.label.toLowerCase().replace(/\s+/g,"-")}`,t.type="text",t.title=e.label,t.placeholder=e.placeholder||"",e.command&&t.setAttribute("data-command",e.command),e.active&&t.classList.add("active"),e.disabled&&(t.disabled=!0),t.addEventListener("click",n=>{n.preventDefault(),this.setLastCommandTrigger(t,e.command),this.commandHandler&&e.command&&this.commandHandler(e.command)}),t}createButton(e){const t=document.createElement("button");if(t.className="editora-toolbar-button",t.type="button",t.title=e.label,e.command&&t.setAttribute("data-command",e.command),e.icon)if(e.icon.startsWith("<svg")&&e.icon.endsWith("</svg>")){const n=document.createElement("span");n.className="editora-toolbar-icon",n.innerHTML=e.icon,t.appendChild(n)}else t.innerHTML=e.icon;else t.textContent=e.label;return e.active&&t.classList.add("active"),e.disabled&&(t.disabled=!0),t.addEventListener("click",n=>{n.preventDefault(),this.commandHandler&&e.command&&this.commandHandler(e.command)}),t}createDropdown(e){const t=document.createElement("div");t.className="editora-toolbar-dropdown";const n=document.createElement("button");n.className="editora-toolbar-button editora-toolbar-dropdown-trigger",n.type="button",n.textContent=e.label;const i=document.createElement("div");i.className="editora-toolbar-dropdown-menu",i.style.display="none",e.options&&e.options.forEach(a=>{const l=document.createElement("button");l.className="editora-toolbar-dropdown-item",l.type="button",l.textContent=a.label,l.setAttribute("data-value",a.value),l.addEventListener("click",d=>{d.preventDefault(),this.setLastCommandTrigger(n,e.command),this.commandHandler&&e.command&&this.commandHandler(e.command,a.value),i.style.display="none"}),i.appendChild(l)}),n.addEventListener("click",a=>{a.preventDefault(),a.stopPropagation(),this.setLastCommandTrigger(n,e.command);const l=i.style.display==="block";i.style.display=l?"none":"block"});const o=a=>{t.contains(a.target)||(i.style.display="none")},s=a=>{a.key==="Escape"&&(i.style.display="none")};return document.addEventListener("mousedown",o,!0),document.addEventListener("keydown",s),t._cleanupDropdown=()=>{document.removeEventListener("mousedown",o,!0),document.removeEventListener("keydown",s)},t.appendChild(n),t.appendChild(i),t}createInlineMenu(e){const t=document.createElement("div");t.className="editora-toolbar-dropdown editora-toolbar-inline-menu";const n=document.createElement("button");if(n.className="editora-toolbar-button",n.type="button",n.title=e.label,e.icon)if(e.icon.startsWith("<svg")&&e.icon.endsWith("</svg>")){const a=document.createElement("span");a.className="editora-toolbar-icon",a.innerHTML=e.icon,n.appendChild(a)}else n.innerHTML=e.icon;else n.textContent=e.label;const i=document.createElement("div");i.className="editora-toolbar-dropdown-menu",i.style.display="none",e.options&&e.options.forEach(a=>{const l=document.createElement("button");l.className="editora-toolbar-dropdown-item",l.type="button",l.textContent=a.label,l.setAttribute("data-value",a.value),l.addEventListener("click",d=>{d.preventDefault(),d.stopPropagation(),this.setLastCommandTrigger(n,e.command),this.commandHandler&&e.command&&this.commandHandler(e.command,a.value),i.style.display="none"}),i.appendChild(l)}),n.addEventListener("click",a=>{var d;a.preventDefault(),a.stopPropagation(),this.setLastCommandTrigger(n,e.command);const l=(d=this.container)==null?void 0:d.querySelectorAll(".editora-toolbar-dropdown-menu");l==null||l.forEach(c=>{c!==i&&(c.style.display="none")}),i.style.display=i.style.display==="none"?"block":"none"});const o=a=>{t.contains(a.target)||(i.style.display="none")},s=a=>{a.key==="Escape"&&(i.style.display="none")};return document.addEventListener("mousedown",o,!0),document.addEventListener("keydown",s),t._cleanupDropdown=()=>{document.removeEventListener("mousedown",o,!0),document.removeEventListener("keydown",s)},t.appendChild(n),t.appendChild(i),t}getDefaultToolbarString(){return this.getAvailableToolbarItems().map(t=>t.command).join(" ")}updateButtonState(e,t){if(!this.container)return;const n=this.container.querySelector(`[data-command="${e}"]`);n&&(t.active!==void 0&&n.classList.toggle("active",t.active),t.disabled!==void 0&&(n.disabled=t.disabled))}destroy(){this.container&&(this.container.querySelectorAll(".editora-toolbar-dropdown").forEach(t=>{const n=t._cleanupDropdown;n&&n()}),this.container.innerHTML=""),this.commandHandler=void 0}}class Je{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 et{constructor(e={}){this.statusInfo={},this.config=e}create(e){const t=document.createElement("div");return t.className="editora-statusbar",this.config.position&&t.classList.add(`editora-statusbar-${this.config.position}`),this.container=t,e.appendChild(t),t}update(e){this.statusInfo={...this.statusInfo,...e},this.render()}render(){if(!this.container)return;this.container.innerHTML="";const e=document.createElement("div");e.className="editora-statusbar-left";const t=document.createElement("div");t.className="editora-statusbar-right";const n=[];if(this.statusInfo.selectionInfo){const o=this.statusInfo.selectionInfo;o.startLine===o.endLine&&o.startColumn===o.endColumn?n.push(`Ln ${o.startLine}, Col ${o.startColumn}`):(o.startLine===o.endLine?n.push(`Ln ${o.startLine}, Col ${o.startColumn}-${o.endColumn}`):n.push(`Ln ${o.startLine}:${o.startColumn} - ${o.endLine}:${o.endColumn}`),n.push(`${o.selectedChars} chars selected`))}else if(this.statusInfo.cursorPosition){const o=this.statusInfo.cursorPosition;n.push(`Ln ${o.line}, Col ${o.column}`)}this.statusInfo.language&&n.push(this.statusInfo.language);const i=[];this.statusInfo.wordCount!==void 0&&i.push(`${this.statusInfo.wordCount} words`),this.statusInfo.charCount!==void 0&&i.push(`${this.statusInfo.charCount} chars`),this.statusInfo.lineCount!==void 0&&i.push(`${this.statusInfo.lineCount} lines`),this.statusInfo.custom&&Object.entries(this.statusInfo.custom).forEach(([o,s])=>{i.push(`${o}: ${s}`)}),n.forEach((o,s)=>{const a=document.createElement("span");if(a.className="editora-statusbar-item",a.textContent=o,e.appendChild(a),s<n.length-1){const l=document.createElement("span");l.className="editora-statusbar-separator",l.textContent="|",e.appendChild(l)}}),i.forEach((o,s)=>{const a=document.createElement("span");if(a.className="editora-statusbar-item",a.textContent=o,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 tt(r,e){const t=r.textContent||"",n=nt(r,e.startContainer,e.startOffset),o=t.substring(0,n).split(`
|
|
1
|
+
(function(H,j){typeof exports=="object"&&typeof module!="undefined"?j(exports):typeof define=="function"&&define.amd?define(["exports"],j):(H=typeof globalThis!="undefined"?globalThis:H||self,j(H.EditoraCore={}))})(this,function(H){"use strict";const j="";class ye{constructor(){this.loadedPlugins=new Map,this.pluginRegistry=new Map}register(e,t){this.pluginRegistry.set(e,t)}async load(e,t){if(this.loadedPlugins.has(e))return this.loadedPlugins.get(e);const n=this.pluginRegistry.get(e);if(!n)return console.warn(`Plugin not found: ${e}`),null;const i=await n();return t&&this.applyPluginConfig(i,t),this.loadedPlugins.set(e,i),i}async loadMultiple(e,t){return(await Promise.all(e.map(i=>this.load(i,t)))).filter(i=>i!==null)}async parsePluginString(e,t){const n=e.split(/\s+/).filter(Boolean);return this.loadMultiple(n,t)}applyPluginConfig(e,t){e.__pluginConfig=t}unload(e){this.loadedPlugins.delete(e)}clear(){this.loadedPlugins.clear()}getLoadedPlugins(){return Array.from(this.loadedPlugins.values())}getRegisteredPluginNames(){return Array.from(this.pluginRegistry.keys())}isLoaded(e){return this.loadedPlugins.has(e)}}class V{constructor(e,t,n){this.doc=e,this.selection=t,this.schema=n}static create(e,t){const n=t||e.node("doc",{},[e.node("paragraph")]);return new V(n,{anchor:0,head:0},e)}apply(e,t){return new V(e,t||this.selection,this.schema)}}class Ze{constructor(e,t){this.nodes=new Map(Object.entries(e)),this.marks=new Map(Object.entries(t))}node(e,t,n){return{type:e,attrs:t,content:n}}text(e,t){return{type:"text",text:e,marks:t}}}class Qe{constructor(){this.plugins=[],this.pluginConfigs=new Map}register(e,t){this.plugins.push(e),t&&this.pluginConfigs.set(e.name,t);const n=this.pluginConfigs.get(e.name)||e.config;if(e.initialize)try{e.initialize(n)}catch(i){console.error(`Failed to initialize plugin "${e.name}":`,i)}if(e.init&&e.init!==e.initialize)try{e.init(n)}catch(i){console.error(`Failed to run init hook for plugin "${e.name}":`,i)}}unregister(e){const t=this.plugins.findIndex(n=>n.name===e);if(t>-1){const n=this.plugins[t];n.destroy&&n.destroy(),this.plugins.splice(t,1),this.pluginConfigs.delete(e)}}getPlugin(e){return this.plugins.find(t=>t.name===e)}getPluginConfig(e){return this.pluginConfigs.get(e)}buildSchema(){const e={},t={};return this.plugins.forEach(n=>{n.nodes&&Object.assign(e,n.nodes),n.marks&&Object.assign(t,n.marks)}),new Ze(e,t)}getCommands(){const e={};return this.plugins.forEach(t=>{t.commands&&Object.assign(e,t.commands)}),e}getToolbarItems(){return this.plugins.flatMap(e=>e.toolbar||[])}async executePluginCommand(e,t,...n){const i=this.getPlugin(e);if(!i)throw new Error(`Plugin not found: ${e}`);const o=this.getPluginConfig(e)||i.config||{},s=o.mode||"local";try{switch(s){case"local":return i.executeLocal?i.executeLocal(t,...n):null;case"api":if(!i.executeAPI)throw new Error(`Plugin ${e} does not support API mode`);return await i.executeAPI(t,...n);case"hybrid":if(i.executeHybrid)return await i.executeHybrid(t,...n);try{if(i.executeAPI)return await i.executeAPI(t,...n)}catch(a){if(console.warn(`API execution failed for ${e}, falling back to local`,a),i.executeLocal&&o.fallbackToLocal!==!1)return i.executeLocal(t,...n);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 Xe{constructor(e={}){this.commands=new Map,Object.entries(e).forEach(([t,n])=>{this.register(t,n)})}register(e,t){this.commands.has(e)&&console.warn(`Command ${e} is being overwritten`),this.commands.set(e,t)}unregister(e){this.commands.delete(e)}get(e){return this.commands.get(e)}has(e){return this.commands.has(e)}getCommandNames(){return Array.from(this.commands.keys())}clear(){this.commands.clear()}}class Ye{constructor(e={}){this.listeners=new Map,this.isReadonly=!1,this.isDestroyed=!1,this.isReadonly=e.readonly||!1,this.pluginManager=new Qe,e.plugins&&Array.isArray(e.plugins)&&e.plugins.forEach(n=>this.pluginManager.register(n));const t=this.pluginManager.buildSchema();this.state=V.create(t),this.commandRegistry=new Xe(this.pluginManager.getCommands())}execCommand(e,t){if(this.isReadonly)return console.warn("Cannot execute commands in readonly mode"),!1;if(this.isDestroyed)return console.warn("Cannot execute commands on destroyed editor"),!1;const n=this.commandRegistry.get(e);if(!n)return console.warn(`Command not found: ${e}`),!1;let i;return t!==void 0?i=n(this.state,t):i=n(this.state),i instanceof Promise?(i.then(o=>{o&&typeof o=="object"&&"doc"in o&&"selection"in o&&(this.setState(o),this.emit("change",this.state))}).catch(o=>{console.error(`Async command failed: ${e}`,o)}),!0):i&&typeof i=="object"&&"doc"in i&&"selection"in i?(this.setState(i),this.emit("change",this.state),!0):i!==!1&&i!=null}setState(e){this.isDestroyed||(this.state=e,this.emit("stateChange",e))}getState(){return this.state}setReadonly(e){this.isReadonly=e,this.emit("readonlyChange",e)}isReadOnly(){return this.isReadonly}on(e,t){return this.listeners.has(e)||this.listeners.set(e,[]),this.listeners.get(e).push(t),()=>{const n=this.listeners.get(e);if(n){const i=n.indexOf(t);i>-1&&n.splice(i,1)}}}emit(e,...t){const n=this.listeners.get(e);n&&n.forEach(i=>{try{i(...t)}catch(o){console.error(`Error in ${e} handler:`,o)}})}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.listeners.clear(),this.emit("destroy"))}isEditorDestroyed(){return this.isDestroyed}}class Ge{setLastCommandTrigger(e,t){if(typeof window=="undefined"||!e)return;const n=t||e.getAttribute("data-command")||void 0;n&&(window.__editoraLastCommandButton=e,window.__editoraLastCommand=n)}constructor(e,t,n){this.config=e,this.plugins=t,this.pluginLoader=n}setCommandHandler(e){this.commandHandler=e}parseToolbarString(e){const t=[],n=e.split("|").map(a=>a.trim()),i=this.getAvailableToolbarItems(),o=new Map;i.forEach(a=>{a.command&&o.set(a.command,a),a.type==="group"&&a.label&&o.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",trackChanges:"toggleTrackChanges",acceptTrackChanges:"acceptAllTrackChanges",rejectTrackChanges:"rejectAllTrackChanges",anchor:"insertAnchor",code:"toggleSourceView",blockquote:"toggleBlockquote",undo:"undo",redo:"redo",textColor:"openTextColorPicker",backgroundColor:"openBackgroundColorPicker",fontSize:"fontSize",fontFamily:"setFontFamily",lineHeight:"setLineHeight",heading:"setBlockType",paragraph:"setParagraph",textAlignment:"setTextAlignment",direction:"setDirectionLTR",indent:"increaseIndent",outdent:"decreaseIndent",capitalization:"setCapitalization",math:"insertMath",specialCharacters:"insertSpecialCharacter",emojis:"openEmojiDialog",embedIframe:"openEmbedIframeDialog",fullscreen:"toggleFullscreen",preview:"togglePreview",print:"print",a11yChecker:"toggleA11yChecker",spellCheck:"toggleSpellCheck",comments:"addComment",showHideComments:"toggleComments",toggleComments:"toggleComments",footnote:"insertFootnote",mergeTags:"insertMergeTag",dataBinding:"openDataBindingDialog",dataBindingPreview:"openDataBindingDialog",contentRules:"toggleContentRulesPanel",contentRulesAudit:"runContentRulesAudit",contentRulesRealtime:"toggleContentRulesRealtime",mention:"insertMention",slash:"openSlashCommands",slashCommands:"openSlashCommands",pageBreak:"insertPageBreak",template:"insertTemplate",importWord:"importWord",exportWord:"exportWord",exportPdf:"exportPdf",insertImage:"insertImage",insertVideo:"insertVideo",codeBlock:"insertCodeBlock"};return n.forEach(a=>{const l=[];a.split(/\s+/).filter(Boolean).forEach(c=>{if(c==="direction"){const p=o.get("setDirectionLTR"),g=o.get("setDirectionRTL");p&&l.push({id:"directionLTR",label:p.label,command:p.command,icon:p.icon,type:p.type||"button",options:p.options}),g&&l.push({id:"directionRTL",label:g.label,command:g.command,icon:g.icon,type:g.type||"button",options:g.options});return}if(c==="comments"){const p=o.get("addComment"),g=o.get("toggleComments");p&&l.push({id:"addComment",label:p.label,command:p.command,icon:p.icon,type:p.type||"button",options:p.options}),g&&l.push({id:"toggleComments",label:g.label,command:g.command,icon:g.icon,type:g.type||"button",options:g.options});return}const h=s[c]||c;let u=o.get(h);u||(u=o.get(c)),u&&l.push({id:c,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(),n=this.parseToolbarString(t);n.forEach((i,o)=>{const s=document.createElement("div");if(s.className="editora-toolbar-group",i.forEach(a=>{this.appendToolbarButton(s,a)}),e.appendChild(s),o<n.length-1){const a=document.createElement("div");a.className="editora-toolbar-separator",e.appendChild(a)}})}appendToolbarButton(e,t){if(t.type==="separator"){const n=document.createElement("div");n.className="editora-toolbar-separator",e.appendChild(n)}else if(t.type==="dropdown"){const n=this.createDropdown(t);e.appendChild(n)}else if(t.type==="inline-menu"){const n=this.createInlineMenu(t);e.appendChild(n)}else if(t.type==="group"&&t.items&&t.items.length){const n=this.createGroupButton(t);e.appendChild(n)}else if(t.type==="input"){const n=this.createInput(t);e.appendChild(n)}else{const n=this.createButton(t);e.appendChild(n)}}createGroupButton(e){const t=document.createElement("div"),n=e.label.toLowerCase().replace(/\s+/g,"-");if(t.className=`editora-toolbar-group-button ${n}`,t.title=e.label,e.icon)if(e.icon.startsWith("<svg")&&e.icon.endsWith("</svg>")){const i=document.createElement("span");i.className="editora-toolbar-icon",i.innerHTML=e.icon,t.appendChild(i)}else t.innerHTML=e.icon;if(e.items&&e.items.length){const i=document.createElement("div");i.className=`editora-toolbar-group-items ${n}`,e.items.forEach(o=>{this.appendToolbarButton(i,o)}),t.appendChild(i)}return t}createInput(e){const t=document.createElement("input");return t.className=`editora-toolbar-input ${e.label.toLowerCase().replace(/\s+/g,"-")}`,t.type="text",t.title=e.label,t.placeholder=e.placeholder||"",e.command&&t.setAttribute("data-command",e.command),e.active&&t.classList.add("active"),e.disabled&&(t.disabled=!0),t.addEventListener("click",n=>{n.preventDefault(),this.setLastCommandTrigger(t,e.command),this.commandHandler&&e.command&&this.commandHandler(e.command)}),t}createButton(e){const t=document.createElement("button");if(t.className="editora-toolbar-button",t.type="button",t.title=e.label,e.command&&t.setAttribute("data-command",e.command),e.icon)if(e.icon.startsWith("<svg")&&e.icon.endsWith("</svg>")){const n=document.createElement("span");n.className="editora-toolbar-icon",n.innerHTML=e.icon,t.appendChild(n)}else t.innerHTML=e.icon;else t.textContent=e.label;return e.active&&t.classList.add("active"),e.disabled&&(t.disabled=!0),t.addEventListener("click",n=>{n.preventDefault(),this.commandHandler&&e.command&&this.commandHandler(e.command)}),t}createDropdown(e){const t=document.createElement("div");t.className="editora-toolbar-dropdown";const n=document.createElement("button");n.className="editora-toolbar-button editora-toolbar-dropdown-trigger",n.type="button",n.textContent=e.label;const i=document.createElement("div");i.className="editora-toolbar-dropdown-menu",i.style.display="none",e.options&&e.options.forEach(a=>{const l=document.createElement("button");l.className="editora-toolbar-dropdown-item",l.type="button",l.textContent=a.label,l.setAttribute("data-value",a.value),l.addEventListener("click",d=>{d.preventDefault(),this.setLastCommandTrigger(n,e.command),this.commandHandler&&e.command&&this.commandHandler(e.command,a.value),i.style.display="none"}),i.appendChild(l)}),n.addEventListener("click",a=>{a.preventDefault(),a.stopPropagation(),this.setLastCommandTrigger(n,e.command);const l=i.style.display==="block";i.style.display=l?"none":"block"});const o=a=>{t.contains(a.target)||(i.style.display="none")},s=a=>{a.key==="Escape"&&(i.style.display="none")};return document.addEventListener("mousedown",o,!0),document.addEventListener("keydown",s),t._cleanupDropdown=()=>{document.removeEventListener("mousedown",o,!0),document.removeEventListener("keydown",s)},t.appendChild(n),t.appendChild(i),t}createInlineMenu(e){const t=document.createElement("div");t.className="editora-toolbar-dropdown editora-toolbar-inline-menu";const n=document.createElement("button");if(n.className="editora-toolbar-button",n.type="button",n.title=e.label,e.icon)if(e.icon.startsWith("<svg")&&e.icon.endsWith("</svg>")){const a=document.createElement("span");a.className="editora-toolbar-icon",a.innerHTML=e.icon,n.appendChild(a)}else n.innerHTML=e.icon;else n.textContent=e.label;const i=document.createElement("div");i.className="editora-toolbar-dropdown-menu",i.style.display="none",e.options&&e.options.forEach(a=>{const l=document.createElement("button");l.className="editora-toolbar-dropdown-item",l.type="button",l.textContent=a.label,l.setAttribute("data-value",a.value),l.addEventListener("click",d=>{d.preventDefault(),d.stopPropagation(),this.setLastCommandTrigger(n,e.command),this.commandHandler&&e.command&&this.commandHandler(e.command,a.value),i.style.display="none"}),i.appendChild(l)}),n.addEventListener("click",a=>{var d;a.preventDefault(),a.stopPropagation(),this.setLastCommandTrigger(n,e.command);const l=(d=this.container)==null?void 0:d.querySelectorAll(".editora-toolbar-dropdown-menu");l==null||l.forEach(c=>{c!==i&&(c.style.display="none")}),i.style.display=i.style.display==="none"?"block":"none"});const o=a=>{t.contains(a.target)||(i.style.display="none")},s=a=>{a.key==="Escape"&&(i.style.display="none")};return document.addEventListener("mousedown",o,!0),document.addEventListener("keydown",s),t._cleanupDropdown=()=>{document.removeEventListener("mousedown",o,!0),document.removeEventListener("keydown",s)},t.appendChild(n),t.appendChild(i),t}getDefaultToolbarString(){return this.getAvailableToolbarItems().map(t=>t.command).join(" ")}updateButtonState(e,t){if(!this.container)return;const n=this.container.querySelector(`[data-command="${e}"]`);n&&(t.active!==void 0&&n.classList.toggle("active",t.active),t.disabled!==void 0&&(n.disabled=t.disabled))}destroy(){this.container&&(this.container.querySelectorAll(".editora-toolbar-dropdown").forEach(t=>{const n=t._cleanupDropdown;n&&n()}),this.container.innerHTML=""),this.commandHandler=void 0}}class Je{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 et{constructor(e={}){this.statusInfo={},this.config=e}create(e){const t=document.createElement("div");return t.className="editora-statusbar",this.config.position&&t.classList.add(`editora-statusbar-${this.config.position}`),this.container=t,e.appendChild(t),t}update(e){this.statusInfo={...this.statusInfo,...e},this.render()}render(){if(!this.container)return;this.container.innerHTML="";const e=document.createElement("div");e.className="editora-statusbar-left";const t=document.createElement("div");t.className="editora-statusbar-right";const n=[];if(this.statusInfo.selectionInfo){const o=this.statusInfo.selectionInfo;o.startLine===o.endLine&&o.startColumn===o.endColumn?n.push(`Ln ${o.startLine}, Col ${o.startColumn}`):(o.startLine===o.endLine?n.push(`Ln ${o.startLine}, Col ${o.startColumn}-${o.endColumn}`):n.push(`Ln ${o.startLine}:${o.startColumn} - ${o.endLine}:${o.endColumn}`),n.push(`${o.selectedChars} chars selected`))}else if(this.statusInfo.cursorPosition){const o=this.statusInfo.cursorPosition;n.push(`Ln ${o.line}, Col ${o.column}`)}this.statusInfo.language&&n.push(this.statusInfo.language);const i=[];this.statusInfo.wordCount!==void 0&&i.push(`${this.statusInfo.wordCount} words`),this.statusInfo.charCount!==void 0&&i.push(`${this.statusInfo.charCount} chars`),this.statusInfo.lineCount!==void 0&&i.push(`${this.statusInfo.lineCount} lines`),this.statusInfo.custom&&Object.entries(this.statusInfo.custom).forEach(([o,s])=>{i.push(`${o}: ${s}`)}),n.forEach((o,s)=>{const a=document.createElement("span");if(a.className="editora-statusbar-item",a.textContent=o,e.appendChild(a),s<n.length-1){const l=document.createElement("span");l.className="editora-statusbar-separator",l.textContent="|",e.appendChild(l)}}),i.forEach((o,s)=>{const a=document.createElement("span");if(a.className="editora-statusbar-item",a.textContent=o,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 tt(r,e){const t=r.textContent||"",n=nt(r,e.startContainer,e.startOffset),o=t.substring(0,n).split(`
|
|
2
2
|
`),s=o.length,a=o[o.length-1].length+1;return{line:s,column:a}}function nt(r,e,t){var s;let n=0;const i=document.createTreeWalker(r,NodeFilter.SHOW_TEXT,null);let o=i.firstChild();for(;o;){if(o===e){n+=t;break}else o.nodeType===Node.TEXT_NODE&&(n+=((s=o.textContent)==null?void 0:s.length)||0);o=i.nextNode()}return n}function it(r){var n,i;const e=r.querySelectorAll("div, p, br, h1, h2, h3, h4, h5, h6, blockquote, li, pre");let t=1;if(e.length>0){t=e.length;const o=e[e.length-1];(o.tagName==="BR"||((n=o.innerHTML)==null?void 0:n.trim())===""||((i=o.textContent)==null?void 0:i.trim())==="")&&t++}else{const s=(r.textContent||"").split(`
|
|
3
3
|
`).length;t=Math.max(1,s)}return t}function ot(r){const e=r.trim()?r.trim().split(/\s+/).length:0,t=r.length;return{words:e,chars:t}}function rt(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 st{constructor(e){this.shortcuts=new Map,this.enabled=!0,this.isMac=typeof navigator!="undefined"&&navigator.platform.toUpperCase().indexOf("MAC")>=0,(e==null?void 0:e.enabled)===!1&&(this.enabled=!1),this.registerDefaultShortcuts(),e!=null&&e.shortcuts&&e.shortcuts.forEach(t=>this.registerShortcut(t)),e!=null&&e.customShortcuts&&Object.values(e.customShortcuts).forEach(t=>{this.registerShortcut(t)})}registerDefaultShortcuts(){this.registerShortcut({key:"b",ctrl:!this.isMac,meta:this.isMac,command:"toggleBold",description:"Bold",preventDefault:!0}),this.registerShortcut({key:"i",ctrl:!this.isMac,meta:this.isMac,command:"toggleItalic",description:"Italic",preventDefault:!0}),this.registerShortcut({key:"u",ctrl:!this.isMac,meta:this.isMac,command:"toggleUnderline",description:"Underline",preventDefault:!0}),this.registerShortcut({key:"d",ctrl:!this.isMac,meta:this.isMac,command:"toggleStrikethrough",description:"Strikethrough",preventDefault:!0}),this.registerShortcut({key:"z",ctrl:!this.isMac,meta:this.isMac,command:"undo",description:"Undo",preventDefault:!0}),this.registerShortcut({key:"z",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"redo",description:"Redo",preventDefault:!0}),this.registerShortcut({key:"y",ctrl:!this.isMac,meta:this.isMac,command:"redo",description:"Redo",preventDefault:!0});for(let e=1;e<=6;e++)this.registerShortcut({key:String(e),ctrl:!this.isMac,meta:this.isMac,alt:!0,command:"setBlockType",params:`h${e}`,description:`Heading ${e}`,preventDefault:!0});this.registerShortcut({key:"7",ctrl:!this.isMac,meta:this.isMac,alt:!0,command:"setBlockType",params:"p",description:"Paragraph",preventDefault:!0}),this.registerShortcut({key:"7",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"toggleOrderedList",description:"Numbered List",preventDefault:!0}),this.registerShortcut({key:"8",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"toggleBulletList",description:"Bullet List",preventDefault:!0}),this.registerShortcut({key:"k",ctrl:!this.isMac,meta:this.isMac,command:"openLinkDialog",description:"Insert/Edit Link",preventDefault:!0}),this.registerShortcut({key:"e",ctrl:!this.isMac,meta:this.isMac,alt:!0,command:"insertCodeBlock",description:"Code Block",preventDefault:!0}),this.registerShortcut({key:"q",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"toggleBlockquote",description:"Blockquote",preventDefault:!0}),this.registerShortcut({key:"l",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"setTextAlignment",params:"left",description:"Align Left",preventDefault:!0}),this.registerShortcut({key:"e",ctrl:!this.isMac,meta:this.isMac,shift:!0,alt:!0,command:"setTextAlignment",params:"center",description:"Align Center",preventDefault:!0}),this.registerShortcut({key:"r",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"setTextAlignment",params:"right",description:"Align Right",preventDefault:!0}),this.registerShortcut({key:"j",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"setTextAlignment",params:"justify",description:"Justify",preventDefault:!0}),this.registerShortcut({key:"\\",ctrl:!this.isMac,meta:this.isMac,command:"clearFormatting",description:"Clear Formatting",preventDefault:!0}),this.registerShortcut({key:"]",ctrl:!this.isMac,meta:this.isMac,command:"increaseIndent",description:"Indent",preventDefault:!0}),this.registerShortcut({key:"[",ctrl:!this.isMac,meta:this.isMac,command:"decreaseIndent",description:"Outdent",preventDefault:!0}),this.registerShortcut({key:"g",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"insertImage",description:"Insert Image",preventDefault:!0}),this.registerShortcut({key:"t",ctrl:!this.isMac,meta:this.isMac,shift:!0,alt:!0,command:"insertTable",description:"Insert Table",preventDefault:!0}),this.registerShortcut({key:"f11",command:"toggleFullscreen",description:"Toggle Fullscreen",preventDefault:!0}),this.registerShortcut({key:"p",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"togglePreview",description:"Preview",preventDefault:!0}),this.registerShortcut({key:"p",ctrl:!this.isMac,meta:this.isMac,command:"print",description:"Print",preventDefault:!0}),this.registerShortcut({key:"s",ctrl:!this.isMac,meta:this.isMac,shift:!0,alt:!0,command:"insertSpecialCharacter",description:"Insert Special Character",preventDefault:!0}),this.registerShortcut({key:"m",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"insertEmoji",description:"Insert Emoji",preventDefault:!0}),this.registerShortcut({key:"9",ctrl:!this.isMac,meta:this.isMac,shift:!0,command:"toggleChecklist",description:"Checklist",preventDefault:!0}),this.registerShortcut({key:"a",ctrl:!this.isMac,meta:this.isMac,shift:!0,alt:!0,command:"toggleA11yChecker",description:"Accessibility Checker",preventDefault:!0}),this.registerShortcut({key:"F7",command:"toggleSpellCheck",description:"Spell Check",preventDefault:!0}),this.registerShortcut({key:"m",ctrl:!this.isMac,meta:this.isMac,alt:!0,command:"insertMath",description:"Insert Math",preventDefault:!0}),this.registerShortcut({key:"f",ctrl:!this.isMac,meta:this.isMac,alt:!0,command:"insertFootnote",description:"Insert Footnote",preventDefault:!0})}registerShortcut(e){const t=this.getShortcutKey(e);this.shortcuts.set(t,e)}unregisterShortcut(e){const t=this.getShortcutKey(e);this.shortcuts.delete(t)}getShortcutKey(e){const t=[];return e.ctrl&&t.push("ctrl"),e.alt&&t.push("alt"),e.shift&&t.push("shift"),e.meta&&t.push("meta"),t.push(e.key.toLowerCase()),t.join("+")}getEventKey(e){const t=[];return e.ctrlKey&&t.push("ctrl"),e.altKey&&t.push("alt"),e.shiftKey&&t.push("shift"),e.metaKey&&t.push("meta"),t.push(e.key.toLowerCase()),t.join("+")}handleKeyDown(e,t){if(!this.enabled)return!1;const n=this.getEventKey(e),i=this.shortcuts.get(n);return i?(i.preventDefault!==!1&&(e.preventDefault(),e.stopPropagation()),t(i.command,i.params),!0):!1}enable(){this.enabled=!0}disable(){this.enabled=!1}isEnabled(){return this.enabled}getAllShortcuts(){return Array.from(this.shortcuts.values())}getShortcutForCommand(e){return Array.from(this.shortcuts.values()).find(t=>t.command===e)}getShortcutDescription(e){const t=[];this.isMac?(e.meta&&t.push("⌘"),e.ctrl&&t.push("⌃"),e.alt&&t.push("⌥"),e.shift&&t.push("⇧")):(e.ctrl&&t.push("Ctrl"),e.alt&&t.push("Alt"),e.shift&&t.push("Shift"));const n=e.key.length===1?e.key.toUpperCase():e.key;return t.push(n),t.join("+")}getShortcutsHelp(){const e=this.getAllShortcuts(),t=new Map;e.forEach(i=>{const o=this.getShortcutCategory(i.command);t.has(o)||t.set(o,[]),t.get(o).push(i)});let n=`# Keyboard Shortcuts
|
|
4
4
|
|
|
@@ -6,11 +6,12 @@
|
|
|
6
6
|
|
|
7
7
|
`,i.forEach(s=>{const a=this.getShortcutDescription(s);n+=`- **${a}**: ${s.description||s.command}
|
|
8
8
|
`}),n+=`
|
|
9
|
-
`}),n}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 at=["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","section","sup","sub","hr"],lt={"*":["class","style","id","data-*","role","aria-*","tabindex","contenteditable","spellcheck"],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 xe(r,e,t){if((e==null?void 0:e.sanitize)===!1)return r;const n=e!=null&&e.allowedTags&&e.allowedTags.length>0?e.allowedTags:at,o=!!(e!=null&&e.allowedAttributes)&&Object.keys(e.allowedAttributes).length>0?e.allowedAttributes:lt,s=document.createElement("div");return s.innerHTML=r,ke(s,n,o),s.innerHTML}function ke(r,e,t){const n=Array.from(r.childNodes);for(const i of n)if(i.nodeType===Node.ELEMENT_NODE){const o=i,s=o.tagName.toLowerCase();if(!e.includes(s)){for(;o.firstChild;)r.insertBefore(o.firstChild,o);r.removeChild(o);continue}ct(o,t),ke(o,e,t)}else i.nodeType!==Node.TEXT_NODE&&r.removeChild(i)}function ct(r,e){const t=r.tagName.toLowerCase(),n=Array.from(r.attributes),i=e[t]||[],o=e["*"]||[],s=[...i,...o];for(const a of n){const l=a.name.toLowerCase();let d=!1;s.includes(l)&&(d=!0);for(const c of s)if(c.endsWith("*")){const h=c.slice(0,-1);if(l.startsWith(h)){d=!0;break}}(l.startsWith("on")||l==="javascript:"||l==="href"&&a.value.trim().toLowerCase().startsWith("javascript:")||l==="src"&&a.value.trim().toLowerCase().startsWith("javascript:"))&&(d=!1),d||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 dt(r,e,t){return(t==null?void 0:t.sanitizeOnPaste)===!1?r:xe(r,e)}function ht(r,e,t){return(t==null?void 0:t.sanitizeOnInput)===!1?r:xe(r,e)}const be=class be{static resolve(e){const t={};if(Object.assign(t,this.EDITOR_DEFAULTS),e.pluginDefaults&&Object.assign(t,e.pluginDefaults),e.attributes){const n=this.parseAttributes(e.attributes);Object.assign(t,n)}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 n={enabled:!1,intervalMs:3e4,storageKey:"rte-autosave",provider:"localStorage",apiUrl:""};if(typeof t.autosave=="boolean")t.autosave={...n,enabled:t.autosave};else if(typeof t.autosave=="object"&&t.autosave){const s={...n,...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=n.intervalMs),t.autosave=s}else t.autosave=n;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 o={enabled:!1,provider:"browser",apiUrl:""};if(typeof t.spellcheck=="boolean")t.spellcheck={...o,enabled:t.spellcheck};else if(typeof t.spellcheck=="object"&&t.spellcheck){const s={...o,...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=o;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[n,i]of Object.entries(e)){const o=this.kebabToCamel(n);t[o]=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,n)=>n.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 n of e)for(const[i,o]of Object.entries(n))o!=null&&(typeof o=="object"&&!Array.isArray(o)&&t[i]?t[i]=this.merge(t[i],o):t[i]=o);return t}};be.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 G=be;const ut='.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:0px solid #ccc;border-radius:0!important}&:hover{background:#e0e0e0;border-color:#ccc}}}.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-theme-dark .editora-content,.editora-theme-dark .editora-content :is(p,span,div,li,ul,ol,td,th,h1,h2,h3,h4,h5,h6,strong,em,u,s,small,sub,sup,blockquote,code,pre,a){color:#ecf3ff}.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:#ecf3ff}.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:#ecf3ff}.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 W;const gt="__editoraCommandEditorRoot",ft="__editoraLastCommandButton",we="editora-editor, [data-editora-editor], .rte-editor, .editora-editor",Ce=".rte-content, .editora-content",J=new Set;let A=null,Ee=!1,ee=null,te=null;function Se(r){if(!(r instanceof HTMLElement))return!1;const e=r;return typeof e.execCommand=="function"&&(e.tagName.toLowerCase()==="editora-editor"||e.classList.contains("editora-editor")||e.hasAttribute("data-editora-editor"))}function pt(r){return r?r.nodeType===Node.ELEMENT_NODE?r:r.parentElement:null}function $(r){if(!r)return null;if(Se(r))return r;const e=r.matches(we)?r:r.closest(we);return!e||!Se(e)?null:e}function mt(){var i;if(typeof window=="undefined")return null;const r=window[gt];if(r instanceof HTMLElement){const o=$(r);if(o)return o;const s=r.matches(Ce)?r:r.querySelector(Ce);if(s){const a=$(s);if(a)return a}}const e=window[ft];if(e instanceof HTMLElement){const o=$(e);if(o)return o}const t=document.activeElement;if(t){const o=$(t);if(o)return o}const n=(i=window.getSelection)==null?void 0:i.call(window);if(n&&n.rangeCount>0){const o=$(pt(n.getRangeAt(0).startContainer));if(o)return o}if(A&&A.isConnected)return A;for(const o of J)if(o.isConnected)return o;return null}function bt(){if(typeof window=="undefined"||Ee)return;ee=typeof window.executeEditorCommand=="function"?window.executeEditorCommand.bind(window):null,te=typeof window.execEditorCommand=="function"?window.execEditorCommand.bind(window):null;const r=(e,t)=>{const n=mt();return n?n.execCommand(e,t):ee?ee(e,t):te?te(e,t):!1};window.executeEditorCommand=r,window.execEditorCommand=r,Ee=!0}function yt(){const r="editora-webcomponent-styles";if(!document.getElementById(r)){const e=document.createElement("style");e.id=r,e.textContent=ut,document.head.appendChild(e)}}function vt(){if(!W){const r=S.__globalPluginLoader;r?W=r:W=new N}return W}class S extends HTMLElement{constructor(){if(super(),this.pluginLoader=vt(),this.config={},this.isInitialized=!1,this.keyboardShortcutManager=new st,this.lastAutosavedContent="",this.loadedPlugins=[],this.lastBeforeInputType=null,yt(),!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(S.__globalPluginLoader){this.pluginLoader=S.__globalPluginLoader;return}return new Promise(e=>{const t=()=>{S.__globalPluginLoader?(this.pluginLoader=S.__globalPluginLoader,e()):setTimeout(t,0)};t()})}disconnectedCallback(){this.destroy()}attributeChangedCallback(e,t,n){t!==n&&(this.config=this.resolveConfig(),this.handleAttributeChange(e,n))}async setConfig(e){this.jsConfig=e,this.config=this.resolveConfig(),this.isConnected&&(this.destroy(),await this.waitForPluginLoader(),await this.initialize())}async initialize(){var n;if(this.querySelector(".editora-toolbar")||this.isInitialized)return;this.setAttribute("data-editora-editor","true"),J.add(this),A||(A=this),bt(),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(o){console.error(`[RichTextEditor] Error initializing plugin ${i.name}:`,o)}});const t=(n=this.restoreAutosavedContent())!=null?n:this.getAttribute("data-initial-content")||"";this.engine=new Ye({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(n=>n.nodeType===Node.TEXT_NODE?n.textContent:n.nodeType===Node.ELEMENT_NODE?n.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 o=this.config.plugins.split(/\s+/).filter(Boolean);i&&!o.includes("a11yChecker")&&o.push("a11yChecker");for(const s of o){const a=await this.pluginLoader.load(s,this.getPluginLoadConfig(s));a&&e.push(a)}}else if(Array.isArray(this.config.plugins)){for(const o of this.config.plugins)if(typeof o=="string"){const s=await this.pluginLoader.load(o,this.getPluginLoadConfig(o));s&&e.push(s)}else e.push(o);if(i&&!e.some(o=>(o==null?void 0:o.name)==="a11yChecker")){const o=await this.pluginLoader.load("a11yChecker",this.getPluginLoadConfig("a11yChecker"));o&&e.push(o)}}}else{const o=this.pluginLoader.getRegisteredPluginNames();for(const s of o){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 n=t.items;if(typeof n=="string")return n;if(Array.isArray(n))return n.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 n=Number((t=e.debounceInputMs)!=null?t:100);return{debounceInputMs:Number.isFinite(n)&&n>=0?n: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 o;typeof window!="undefined"&&(window.__editoraCommandEditorRoot=this);const n={editorElement:this,contentElement:this.contentElement,toolbarElement:this.toolbarElement},i=this.loadedPlugins.find(s=>s.commands&&s.commands[e]);if(i&&i.commands){const s=i.commands[e];if(typeof s=="function")try{return s(e==="toggleFullscreen"?this:t,n),!0}catch(a){return console.error(`[RichTextEditor] Error executing native command ${e}:`,a),!1}}return((o=this.engine)==null?void 0:o.execCommand(e,t))||!1}getPluginLoadConfig(e){const t=this.config.pluginConfig;if(t&&typeof t=="object"){const o=t[e];if(o&&typeof o=="object")return o}const n={spellCheck:["spellcheck","spellCheck"],trackChanges:["trackchanges","track-changes","trackChanges"],versionDiff:["versiondiff","version-diff","versionDiff"],"version-diff":["versiondiff","version-diff","versionDiff"],conditionalContent:["conditionalcontent","conditional-content","conditionalContent"],"conditional-content":["conditionalcontent","conditional-content","conditionalContent"],dataBinding:["databinding","data-binding","dataBinding"],"data-binding":["databinding","data-binding","dataBinding"],contentRules:["contentrules","content-rules","contentRules"],"content-rules":["contentrules","content-rules","contentRules"],mentions:["mention","mentions"],mention:["mention","mentions"],slashCommands:["slashcommands","slash-commands","slashCommands"],"slash-commands":["slashcommands","slash-commands","slashCommands"]},i=[e,e.toLowerCase(),...n[e]||[]];for(const o of i){const s=this.config[o];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,n;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((n=(t=e.intervalMs)!=null?t:e.interval)!=null?n: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(n){console.error("[RichTextEditor] Failed to save autosave content to localStorage:",n)}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(n=>{console.error("[RichTextEditor] Failed to save autosave content to API:",n)})}}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 n=t.getRangeAt(0);n.deleteContents();const i=document.createElement("div");i.innerHTML=e;const o=document.createDocumentFragment();for(;i.firstChild;)o.appendChild(i.firstChild);n.insertNode(o),n.collapse(!1),t.removeAllRanges(),t.addRange(n)}else this.contentElement.focus(),document.execCommand("insertHTML",!1,e)}createUI(e,t){const n=this.querySelector('[slot="toolbar"]'),i=this.querySelector('[slot="statusbar"]');this.innerHTML="",this.config.toolbar!==!1&&!n?(this.toolbarElement=document.createElement("div"),this.toolbarElement.className="editora-toolbar-container",this.appendChild(this.toolbarElement),this.toolbar=new Ge({items:this.resolveToolbarItems(),sticky:this.isToolbarStickyEnabled(),position:"top"},e,this.pluginLoader),this.toolbar.setCommandHandler((o,s)=>{var a;if(this.contentElement){this.contentElement.focus();const l=window.getSelection();if(!l||l.rangeCount===0||!this.contentElement.contains(l.anchorNode)){const d=document.createRange(),c=this.contentElement.lastChild||this.contentElement;c.nodeType===Node.TEXT_NODE?d.setStart(c,((a=c.textContent)==null?void 0:a.length)||0):c.nodeType===Node.ELEMENT_NODE?(d.selectNodeContents(c),d.collapse(!1)):d.setStart(this.contentElement,0),d.collapse(!0),l==null||l.removeAllRanges(),l==null||l.addRange(d)}}return this.executeCommand(o,s)}),this.toolbar.render(this.toolbarElement)):n&&this.appendChild(n),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(o){console.warn("defaultParagraphSeparator not supported:",o)}if(t){const o=document.createElement("div");o.innerHTML=t.trim(),!Array.from(o.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 Je({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 et({position:this.getStatusbarPosition()}),this.statusBar.create(this.statusBarElement)),this.config.autofocus&&setTimeout(()=>{var o;return(o=this.contentElement)==null?void 0:o.focus()},0)}setupEventListeners(){if(!this.contentElement||!this.engine)return;const e=this.keyboardShortcutManager;this.contentElement.addEventListener("beforeinput",n=>{this.lastBeforeInputType=n.inputType||null}),this.contentElement.addEventListener("input",()=>{if(!this.contentElement)return;let n=this.contentElement.innerHTML;const i=this.getPerformanceConfig(),o=this.getContentSanitizeConfig(),s=this.getSecurityConfig(),a=this.lastBeforeInputType;if(this.lastBeforeInputType=null,s.sanitizeOnInput!==!1&&o.sanitize!==!1&&!a){const c=ht(n,o,s);if(c!==n){const h=window.getSelection(),u=h&&h.rangeCount>0?h.getRangeAt(0):null;if(this.contentElement.innerHTML=c,u&&h)try{h.removeAllRanges(),h.addRange(u)}catch(f){}n=c}}this.contentChangeDebounceTimer&&clearTimeout(this.contentChangeDebounceTimer);const d=()=>{this.dispatchEvent(new CustomEvent("content-change",{detail:{html:n},bubbles:!0}))};i.debounceInputMs>0?this.contentChangeDebounceTimer=setTimeout(d,i.debounceInputMs):d(),this.updateStatusBar()}),this.contentElement.addEventListener("contextmenu",n=>{const i=this.config.contextMenu;(i===!1||typeof i=="object"&&i!==null&&i.enabled===!1)&&n.preventDefault()}),this.contentElement.addEventListener("paste",n=>{var c,h;if(n.__editoraSmartPasteHandled===!0||n.defaultPrevented)return;n.preventDefault();const i=this.config.paste||{};let o=((c=n.clipboardData)==null?void 0:c.getData("text/html"))||"";const s=((h=n.clipboardData)==null?void 0:h.getData("text/plain"))||"",a=this.getContentSanitizeConfig(),l=this.getSecurityConfig(),d=!!o&&/class=["'][^"']*Mso|xmlns:w=|urn:schemas-microsoft-com:office/i.test(o);if((i.clean||!i.keepFormatting)&&s){document.execCommand("insertText",!1,s);return}if(i.convertWord===!1&&d&&s){document.execCommand("insertText",!1,s);return}if(o){l.sanitizeOnPaste!==!1&&a.sanitize!==!1&&(o=dt(o,a,l)),this.insertHTMLAtSelection(o);return}s&&document.execCommand("insertText",!1,s)}),this.contentElement.addEventListener("focus",()=>{A=this,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",n=>{this.getAccessibilityConfig().keyboardNavigation&&e.handleKeyDown(n,(o,s)=>{this.executeCommand(o,s)})});const t=()=>{const n=this.getSelectionRangeInEditor(),i=document.activeElement,o=!!i&&!!this.contentElement&&(i===this.contentElement||this.contentElement.contains(i));this.getPerformanceConfig().viewportOnlyScan&&!this.isEditorInViewport()&&!o||!n&&!o||(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),n=t.commonAncestorContainer;return this.contentElement.contains(n)?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 n=Array.from(t.getClientRects()).filter(o=>o.width>0||o.height>0);return n.length===0?t.getBoundingClientRect():this.isSelectionBackward(e)?n[0]:n[n.length-1]}updateFloatingToolbar(){if(!this.floatingToolbar||!this.contentElement)return;if(this.config.readonly||this.contentElement.contentEditable==="false"||this.contentElement.getAttribute("data-readonly")==="true"||this.getAttribute("readonly")==="true"||this.getAttribute("data-readonly")==="true"){this.floatingToolbar.hide();return}const t=this.getPerformanceConfig(),n=document.activeElement===this.contentElement||!!this.contentElement&&this.contentElement.contains(document.activeElement);if(t.viewportOnlyScan&&!this.isEditorInViewport()&&!n){this.floatingToolbar.hide();return}const i=this.getSelectionRangeInEditor();if(!i){this.floatingToolbar.hide();return}if(i.collapsed){this.floatingToolbar.hide();return}const o=window.getSelection();if(!o){this.floatingToolbar.hide();return}const s=this.getSelectionAnchorRect(o,i);if(!s){this.floatingToolbar.hide();return}this.floatingToolbar.show(s.left,s.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 n=this.contentElement.textContent||"",{words:i,chars:o}=ot(n),s=it(this.contentElement);let a,l;const d=this.getSelectionRangeInEditor();d&&(a=tt(this.contentElement,d),d.collapsed||(l=rt(d,a),a=void 0)),this.statusBar.update({wordCount:i,charCount:o,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(n=>{n.startsWith("editora-theme-")&&this.classList.remove(n)}),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(n=>{console.error("[RichTextEditor] Error during attribute change re-initialization:",n)})}));break}}resolveConfig(){const e={};for(let t=0;t<this.attributes.length;t++){const n=this.attributes[t];e[n.name]=n.value}return G.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,n,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(),(n=this.floatingToolbar)==null||n.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,J.delete(this),A===this&&(A=null),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 ne=new N;S.__globalPluginLoader=ne;const xt={bold:()=>Promise.resolve().then(()=>kt).then(r=>r.BoldPlugin()),italic:()=>Promise.resolve().then(()=>Ct).then(r=>r.ItalicPlugin()),underline:()=>Promise.resolve().then(()=>Et).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(()=>$t).then(r=>r.HeadingPlugin()),blockquote:()=>Promise.resolve().then(()=>zt).then(r=>r.BlockquotePlugin()),code:()=>Promise.resolve().then(()=>en).then(r=>r.CodePlugin()),list:()=>Promise.resolve().then(()=>on).then(r=>r.ListPlugin()),history:()=>Promise.resolve().then(()=>ln).then(r=>r.HistoryPlugin())};async function Te(){return Object.entries(xt).forEach(([r,e])=>{ne.register(r,e)}),ne}typeof window!="undefined"&&Te().then(r=>{S.__globalPluginLoader=r,customElements.get("editora-editor")||customElements.define("editora-editor",S);const e=document.querySelectorAll("editora-editor:not([data-initial-content])"),t=[];e.forEach(n=>{const i=n.innerHTML.trim();i&&(t.push(i),n.setAttribute("data-initial-content",i),n.innerHTML="")}),e.forEach((n,i)=>{n instanceof S&&!n.isInitialized&&t[i]&&n.setAttribute("content",t[i])})});const kt=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"})),ie=()=>(document.execCommand("italic",!1),!0),wt=(r,e)=>{var t;typeof window!="undefined"&&((t=window.registerEditorCommand)==null||t.call(window,r,e))},Me=()=>{wt("toggleItalic",ie)};typeof window!="undefined"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",Me):Me());const Ct=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:ie},keymap:{"Mod-i":"toggleItalic","Mod-I":"toggleItalic"}}),toggleItalic:ie},Symbol.toStringTag,{value:"Module"})),Et=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"})),St=()=>({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=Tt();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 n=document.execCommand("strikeThrough",!1);return Mt(r),r.dispatchEvent(new Event("input",{bubbles:!0})),n!==!1}},keymap:{"Mod-Shift-x":"toggleStrikethrough","Mod-Shift-X":"toggleStrikethrough"}});function Tt(){const r=window.getSelection();if(r&&r.rangeCount>0){const t=r.getRangeAt(0).startContainer,n=t.nodeType===Node.ELEMENT_NODE?t:t.parentElement,i=n==null?void 0:n.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 Mt(r){r.querySelectorAll("strike, del").forEach(t=>{var i;const n=document.createElement("s");for(const o of Array.from(t.attributes))o.name!=="style"&&n.setAttribute(o.name,o.value);for(;t.firstChild;)n.appendChild(t.firstChild);(i=t.parentNode)==null||i.replaceChild(n,t)})}const Lt=Object.freeze(Object.defineProperty({__proto__:null,StrikethroughPlugin:St},Symbol.toStringTag,{value:"Module"})),At=()=>({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=Ht();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 n=t.cloneRange();return r.focus({preventScroll:!0}),document.execCommand("unlink",!1),document.execCommand("removeFormat",!1),Pt(r,n),Dt(r,n),r.dispatchEvent(new Event("input",{bubbles:!0})),!0}},keymap:{"Mod-\\":"clearFormatting"}}),It=new Set(["A","B","STRONG","I","EM","U","S","STRIKE","DEL","FONT","MARK","CODE","SUB","SUP"]),Rt=new Set(["H1","H2","H3","H4","H5","H6","BLOCKQUOTE","PRE"]),Ot=["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 Ht(){const r=window.getSelection();if(r&&r.rangeCount>0){const t=r.getRangeAt(0).startContainer,n=t.nodeType===Node.ELEMENT_NODE?t:t.parentElement,i=n==null?void 0:n.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 Le(r,e){try{if(typeof r.intersectsNode=="function")return r.intersectsNode(e)}catch(n){}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 Ae(r){let e=0,t=r;for(;t&&t.parentNode;)e+=1,t=t.parentNode;return e}function Nt(r){Ot.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 Ie(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(n=>{var o;if(!Le(e,n)||!Rt.has(n.tagName))return;const i=document.createElement("p");for(;n.firstChild;)i.appendChild(n.firstChild);(o=n.parentNode)==null||o.replaceChild(i,n)})}function Dt(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((n,i)=>Ae(i)-Ae(n)),t.forEach(n=>{if(n.isConnected&&Le(e,n)&&!(n.getAttribute("contenteditable")==="false"||n.closest('[contenteditable="false"]'))){if(Nt(n),It.has(n.tagName)){Ie(n);return}n.tagName==="SPAN"&&n.attributes.length===0&&Ie(n)}})}const Bt=Object.freeze(Object.defineProperty({__proto__:null,ClearFormattingPlugin:At},Symbol.toStringTag,{value:"Module"})),$t=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"})),zt=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 oe{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(`
|
|
9
|
+
`}),n}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 at=["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","section","sup","sub","hr"],lt={"*":["class","style","id","data-*","role","aria-*","tabindex","contenteditable","spellcheck"],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 ve(r,e,t){if((e==null?void 0:e.sanitize)===!1)return r;const n=e!=null&&e.allowedTags&&e.allowedTags.length>0?e.allowedTags:at,o=!!(e!=null&&e.allowedAttributes)&&Object.keys(e.allowedAttributes).length>0?e.allowedAttributes:lt,s=document.createElement("div");return s.innerHTML=r,xe(s,n,o),s.innerHTML}function xe(r,e,t){const n=Array.from(r.childNodes);for(const i of n)if(i.nodeType===Node.ELEMENT_NODE){const o=i,s=o.tagName.toLowerCase();if(!e.includes(s)){for(;o.firstChild;)r.insertBefore(o.firstChild,o);r.removeChild(o);continue}ct(o,t),xe(o,e,t)}else i.nodeType!==Node.TEXT_NODE&&r.removeChild(i)}function ct(r,e){const t=r.tagName.toLowerCase(),n=Array.from(r.attributes),i=e[t]||[],o=e["*"]||[],s=[...i,...o];for(const a of n){const l=a.name.toLowerCase();let d=!1;s.includes(l)&&(d=!0);for(const c of s)if(c.endsWith("*")){const h=c.slice(0,-1);if(l.startsWith(h)){d=!0;break}}(l.startsWith("on")||l==="javascript:"||l==="href"&&a.value.trim().toLowerCase().startsWith("javascript:")||l==="src"&&a.value.trim().toLowerCase().startsWith("javascript:"))&&(d=!1),d||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 dt(r,e,t){return(t==null?void 0:t.sanitizeOnPaste)===!1?r:ve(r,e)}function ht(r,e,t){return(t==null?void 0:t.sanitizeOnInput)===!1?r:ve(r,e)}class ke{static resolve(e){const t={};if(Object.assign(t,this.EDITOR_DEFAULTS),e.pluginDefaults&&Object.assign(t,e.pluginDefaults),e.attributes){const n=this.parseAttributes(e.attributes);Object.assign(t,n)}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 n={enabled:!1,intervalMs:3e4,storageKey:"rte-autosave",provider:"localStorage",apiUrl:""};if(typeof t.autosave=="boolean")t.autosave={...n,enabled:t.autosave};else if(typeof t.autosave=="object"&&t.autosave){const s={...n,...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=n.intervalMs),t.autosave=s}else t.autosave=n;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 o={enabled:!1,provider:"browser",apiUrl:""};if(typeof t.spellcheck=="boolean")t.spellcheck={...o,enabled:t.spellcheck};else if(typeof t.spellcheck=="object"&&t.spellcheck){const s={...o,...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=o;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[n,i]of Object.entries(e)){const o=this.kebabToCamel(n);t[o]=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,n)=>n.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 n of e)for(const[i,o]of Object.entries(n))o!=null&&(typeof o=="object"&&!Array.isArray(o)&&t[i]?t[i]=this.merge(t[i],o):t[i]=o);return t}}ke.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};const ut=`.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 0%,#1c2430 100%);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:white;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:0px solid #ccc;border-radius:0!important}&:hover{background:#e0e0e0;border-color:#ccc}}}.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-theme-dark .editora-content,.editora-theme-dark .editora-content :is(p,span,div,li,ul,ol,td,th,h1,h2,h3,h4,h5,h6,strong,em,u,s,small,sub,sup,blockquote,code,pre,a){color:#ecf3ff}.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:#ecf3ff}.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 0%,#1b2430 100%)!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:#ecf3ff}.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 0%,#252d37 100%);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:rgba(0,102,204,.2)}.editora-theme-dark .editora-content ::selection{background:rgba(77,184,255,.2)}.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:#ffffff;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:#ffffff;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:#ffffff;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}}
|
|
10
|
+
`;let W;const gt="__editoraCommandEditorRoot",pt="__editoraLastCommandButton",we="editora-editor, [data-editora-editor], .rte-editor, .editora-editor",Ce=".rte-content, .editora-content",G=new Set;let A=null,Ee=!1,J=null,ee=null;function Se(r){if(!(r instanceof HTMLElement))return!1;const e=r;return typeof e.execCommand=="function"&&(e.tagName.toLowerCase()==="editora-editor"||e.classList.contains("editora-editor")||e.hasAttribute("data-editora-editor"))}function ft(r){return r?r.nodeType===Node.ELEMENT_NODE?r:r.parentElement:null}function B(r){if(!r)return null;if(Se(r))return r;const e=r.matches(we)?r:r.closest(we);return!e||!Se(e)?null:e}function mt(){var i;if(typeof window=="undefined")return null;const r=window[gt];if(r instanceof HTMLElement){const o=B(r);if(o)return o;const s=r.matches(Ce)?r:r.querySelector(Ce);if(s){const a=B(s);if(a)return a}}const e=window[pt];if(e instanceof HTMLElement){const o=B(e);if(o)return o}const t=document.activeElement;if(t){const o=B(t);if(o)return o}const n=(i=window.getSelection)==null?void 0:i.call(window);if(n&&n.rangeCount>0){const o=B(ft(n.getRangeAt(0).startContainer));if(o)return o}if(A&&A.isConnected)return A;for(const o of G)if(o.isConnected)return o;return null}function bt(){if(typeof window=="undefined"||Ee)return;J=typeof window.executeEditorCommand=="function"?window.executeEditorCommand.bind(window):null,ee=typeof window.execEditorCommand=="function"?window.execEditorCommand.bind(window):null;const r=(e,t)=>{const n=mt();return n?n.execCommand(e,t):J?J(e,t):ee?ee(e,t):!1};window.executeEditorCommand=r,window.execEditorCommand=r,Ee=!0}function yt(){const r="editora-webcomponent-styles";if(!document.getElementById(r)){const e=document.createElement("style");e.id=r,e.textContent=ut,document.head.appendChild(e)}}function vt(){if(!W){const r=S.__globalPluginLoader;r?W=r:W=new ye}return W}class S extends HTMLElement{constructor(){if(super(),this.pluginLoader=vt(),this.config={},this.isInitialized=!1,this.keyboardShortcutManager=new st,this.lastAutosavedContent="",this.loadedPlugins=[],this.lastBeforeInputType=null,yt(),!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(S.__globalPluginLoader){this.pluginLoader=S.__globalPluginLoader;return}return new Promise(e=>{const t=()=>{S.__globalPluginLoader?(this.pluginLoader=S.__globalPluginLoader,e()):setTimeout(t,0)};t()})}disconnectedCallback(){this.destroy()}attributeChangedCallback(e,t,n){t!==n&&(this.config=this.resolveConfig(),this.handleAttributeChange(e,n))}async setConfig(e){this.jsConfig=e,this.config=this.resolveConfig(),this.isConnected&&(this.destroy(),await this.waitForPluginLoader(),await this.initialize())}async initialize(){var n;if(this.querySelector(".editora-toolbar")||this.isInitialized)return;this.setAttribute("data-editora-editor","true"),G.add(this),A||(A=this),bt(),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(o){console.error(`[RichTextEditor] Error initializing plugin ${i.name}:`,o)}});const t=(n=this.restoreAutosavedContent())!=null?n:this.getAttribute("data-initial-content")||"";this.engine=new Ye({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(n=>n.nodeType===Node.TEXT_NODE?n.textContent:n.nodeType===Node.ELEMENT_NODE?n.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 o=this.config.plugins.split(/\s+/).filter(Boolean);i&&!o.includes("a11yChecker")&&o.push("a11yChecker");for(const s of o){const a=await this.pluginLoader.load(s,this.getPluginLoadConfig(s));a&&e.push(a)}}else if(Array.isArray(this.config.plugins)){for(const o of this.config.plugins)if(typeof o=="string"){const s=await this.pluginLoader.load(o,this.getPluginLoadConfig(o));s&&e.push(s)}else e.push(o);if(i&&!e.some(o=>(o==null?void 0:o.name)==="a11yChecker")){const o=await this.pluginLoader.load("a11yChecker",this.getPluginLoadConfig("a11yChecker"));o&&e.push(o)}}}else{const o=this.pluginLoader.getRegisteredPluginNames();for(const s of o){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 n=t.items;if(typeof n=="string")return n;if(Array.isArray(n))return n.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 n=Number((t=e.debounceInputMs)!=null?t:100);return{debounceInputMs:Number.isFinite(n)&&n>=0?n: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 o;typeof window!="undefined"&&(window.__editoraCommandEditorRoot=this);const n={editorElement:this,contentElement:this.contentElement,toolbarElement:this.toolbarElement},i=this.loadedPlugins.find(s=>s.commands&&s.commands[e]);if(i&&i.commands){const s=i.commands[e];if(typeof s=="function")try{return s(e==="toggleFullscreen"?this:t,n),!0}catch(a){return console.error(`[RichTextEditor] Error executing native command ${e}:`,a),!1}}return((o=this.engine)==null?void 0:o.execCommand(e,t))||!1}getPluginLoadConfig(e){const t=this.config.pluginConfig;if(t&&typeof t=="object"){const o=t[e];if(o&&typeof o=="object")return o}const n={spellCheck:["spellcheck","spellCheck"],trackChanges:["trackchanges","track-changes","trackChanges"],versionDiff:["versiondiff","version-diff","versionDiff"],"version-diff":["versiondiff","version-diff","versionDiff"],conditionalContent:["conditionalcontent","conditional-content","conditionalContent"],"conditional-content":["conditionalcontent","conditional-content","conditionalContent"],dataBinding:["databinding","data-binding","dataBinding"],"data-binding":["databinding","data-binding","dataBinding"],contentRules:["contentrules","content-rules","contentRules"],"content-rules":["contentrules","content-rules","contentRules"],mentions:["mention","mentions"],mention:["mention","mentions"],slashCommands:["slashcommands","slash-commands","slashCommands"],"slash-commands":["slashcommands","slash-commands","slashCommands"]},i=[e,e.toLowerCase(),...n[e]||[]];for(const o of i){const s=this.config[o];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,n;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((n=(t=e.intervalMs)!=null?t:e.interval)!=null?n: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(n){console.error("[RichTextEditor] Failed to save autosave content to localStorage:",n)}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(n=>{console.error("[RichTextEditor] Failed to save autosave content to API:",n)})}}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 n=t.getRangeAt(0);n.deleteContents();const i=document.createElement("div");i.innerHTML=e;const o=document.createDocumentFragment();for(;i.firstChild;)o.appendChild(i.firstChild);n.insertNode(o),n.collapse(!1),t.removeAllRanges(),t.addRange(n)}else this.contentElement.focus(),document.execCommand("insertHTML",!1,e)}createUI(e,t){const n=this.querySelector('[slot="toolbar"]'),i=this.querySelector('[slot="statusbar"]');this.innerHTML="",this.config.toolbar!==!1&&!n?(this.toolbarElement=document.createElement("div"),this.toolbarElement.className="editora-toolbar-container",this.appendChild(this.toolbarElement),this.toolbar=new Ge({items:this.resolveToolbarItems(),sticky:this.isToolbarStickyEnabled(),position:"top"},e,this.pluginLoader),this.toolbar.setCommandHandler((o,s)=>{var a;if(this.contentElement){this.contentElement.focus();const l=window.getSelection();if(!l||l.rangeCount===0||!this.contentElement.contains(l.anchorNode)){const d=document.createRange(),c=this.contentElement.lastChild||this.contentElement;c.nodeType===Node.TEXT_NODE?d.setStart(c,((a=c.textContent)==null?void 0:a.length)||0):c.nodeType===Node.ELEMENT_NODE?(d.selectNodeContents(c),d.collapse(!1)):d.setStart(this.contentElement,0),d.collapse(!0),l==null||l.removeAllRanges(),l==null||l.addRange(d)}}return this.executeCommand(o,s)}),this.toolbar.render(this.toolbarElement)):n&&this.appendChild(n),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(o){console.warn("defaultParagraphSeparator not supported:",o)}if(t){const o=document.createElement("div");o.innerHTML=t.trim(),!Array.from(o.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 Je({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 et({position:this.getStatusbarPosition()}),this.statusBar.create(this.statusBarElement)),this.config.autofocus&&setTimeout(()=>{var o;return(o=this.contentElement)==null?void 0:o.focus()},0)}setupEventListeners(){if(!this.contentElement||!this.engine)return;const e=this.keyboardShortcutManager;this.contentElement.addEventListener("beforeinput",n=>{this.lastBeforeInputType=n.inputType||null}),this.contentElement.addEventListener("input",()=>{if(!this.contentElement)return;let n=this.contentElement.innerHTML;const i=this.getPerformanceConfig(),o=this.getContentSanitizeConfig(),s=this.getSecurityConfig(),a=this.lastBeforeInputType;if(this.lastBeforeInputType=null,s.sanitizeOnInput!==!1&&o.sanitize!==!1&&!a){const c=ht(n,o,s);if(c!==n){const h=window.getSelection(),u=h&&h.rangeCount>0?h.getRangeAt(0):null;if(this.contentElement.innerHTML=c,u&&h)try{h.removeAllRanges(),h.addRange(u)}catch(p){}n=c}}this.contentChangeDebounceTimer&&clearTimeout(this.contentChangeDebounceTimer);const d=()=>{this.dispatchEvent(new CustomEvent("content-change",{detail:{html:n},bubbles:!0}))};i.debounceInputMs>0?this.contentChangeDebounceTimer=setTimeout(d,i.debounceInputMs):d(),this.updateStatusBar()}),this.contentElement.addEventListener("contextmenu",n=>{const i=this.config.contextMenu;(i===!1||typeof i=="object"&&i!==null&&i.enabled===!1)&&n.preventDefault()}),this.contentElement.addEventListener("paste",n=>{var c,h;if(n.__editoraSmartPasteHandled===!0||n.defaultPrevented)return;n.preventDefault();const i=this.config.paste||{};let o=((c=n.clipboardData)==null?void 0:c.getData("text/html"))||"";const s=((h=n.clipboardData)==null?void 0:h.getData("text/plain"))||"",a=this.getContentSanitizeConfig(),l=this.getSecurityConfig(),d=!!o&&/class=["'][^"']*Mso|xmlns:w=|urn:schemas-microsoft-com:office/i.test(o);if((i.clean||!i.keepFormatting)&&s){document.execCommand("insertText",!1,s);return}if(i.convertWord===!1&&d&&s){document.execCommand("insertText",!1,s);return}if(o){l.sanitizeOnPaste!==!1&&a.sanitize!==!1&&(o=dt(o,a,l)),this.insertHTMLAtSelection(o);return}s&&document.execCommand("insertText",!1,s)}),this.contentElement.addEventListener("focus",()=>{A=this,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",n=>{this.getAccessibilityConfig().keyboardNavigation&&e.handleKeyDown(n,(o,s)=>{this.executeCommand(o,s)})});const t=()=>{const n=this.getSelectionRangeInEditor(),i=document.activeElement,o=!!i&&!!this.contentElement&&(i===this.contentElement||this.contentElement.contains(i));this.getPerformanceConfig().viewportOnlyScan&&!this.isEditorInViewport()&&!o||!n&&!o||(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),n=t.commonAncestorContainer;return this.contentElement.contains(n)?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 n=Array.from(t.getClientRects()).filter(o=>o.width>0||o.height>0);return n.length===0?t.getBoundingClientRect():this.isSelectionBackward(e)?n[0]:n[n.length-1]}updateFloatingToolbar(){if(!this.floatingToolbar||!this.contentElement)return;if(this.config.readonly||this.contentElement.contentEditable==="false"||this.contentElement.getAttribute("data-readonly")==="true"||this.getAttribute("readonly")==="true"||this.getAttribute("data-readonly")==="true"){this.floatingToolbar.hide();return}const t=this.getPerformanceConfig(),n=document.activeElement===this.contentElement||!!this.contentElement&&this.contentElement.contains(document.activeElement);if(t.viewportOnlyScan&&!this.isEditorInViewport()&&!n){this.floatingToolbar.hide();return}const i=this.getSelectionRangeInEditor();if(!i){this.floatingToolbar.hide();return}if(i.collapsed){this.floatingToolbar.hide();return}const o=window.getSelection();if(!o){this.floatingToolbar.hide();return}const s=this.getSelectionAnchorRect(o,i);if(!s){this.floatingToolbar.hide();return}this.floatingToolbar.show(s.left,s.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 n=this.contentElement.textContent||"",{words:i,chars:o}=ot(n),s=it(this.contentElement);let a,l;const d=this.getSelectionRangeInEditor();d&&(a=tt(this.contentElement,d),d.collapsed||(l=rt(d,a),a=void 0)),this.statusBar.update({wordCount:i,charCount:o,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(n=>{n.startsWith("editora-theme-")&&this.classList.remove(n)}),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(n=>{console.error("[RichTextEditor] Error during attribute change re-initialization:",n)})}));break}}resolveConfig(){const e={};for(let t=0;t<this.attributes.length;t++){const n=this.attributes[t];e[n.name]=n.value}return ke.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,n,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(),(n=this.floatingToolbar)==null||n.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,G.delete(this),A===this&&(A=null),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 te=new ye;S.__globalPluginLoader=te;const xt={bold:()=>Promise.resolve().then(()=>kt).then(r=>r.BoldPlugin()),italic:()=>Promise.resolve().then(()=>Ct).then(r=>r.ItalicPlugin()),underline:()=>Promise.resolve().then(()=>Et).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(()=>$t).then(r=>r.HeadingPlugin()),blockquote:()=>Promise.resolve().then(()=>zt).then(r=>r.BlockquotePlugin()),code:()=>Promise.resolve().then(()=>en).then(r=>r.CodePlugin()),list:()=>Promise.resolve().then(()=>on).then(r=>r.ListPlugin()),history:()=>Promise.resolve().then(()=>ln).then(r=>r.HistoryPlugin())};async function Te(){return Object.entries(xt).forEach(([r,e])=>{te.register(r,e)}),te}typeof window!="undefined"&&Te().then(r=>{S.__globalPluginLoader=r,customElements.get("editora-editor")||customElements.define("editora-editor",S);const e=document.querySelectorAll("editora-editor:not([data-initial-content])"),t=[];e.forEach(n=>{const i=n.innerHTML.trim();i&&(t.push(i),n.setAttribute("data-initial-content",i),n.innerHTML="")}),e.forEach((n,i)=>{n instanceof S&&!n.isInitialized&&t[i]&&n.setAttribute("content",t[i])})});const kt=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"})),ne=()=>(document.execCommand("italic",!1),!0),wt=(r,e)=>{var t;typeof window!="undefined"&&((t=window.registerEditorCommand)==null||t.call(window,r,e))},Me=()=>{wt("toggleItalic",ne)};typeof window!="undefined"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",Me):Me());const Ct=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:ne},keymap:{"Mod-i":"toggleItalic","Mod-I":"toggleItalic"}}),toggleItalic:ne},Symbol.toStringTag,{value:"Module"})),Et=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"})),St=()=>({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=Tt();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 n=document.execCommand("strikeThrough",!1);return Mt(r),r.dispatchEvent(new Event("input",{bubbles:!0})),n!==!1}},keymap:{"Mod-Shift-x":"toggleStrikethrough","Mod-Shift-X":"toggleStrikethrough"}});function Tt(){const r=window.getSelection();if(r&&r.rangeCount>0){const t=r.getRangeAt(0).startContainer,n=t.nodeType===Node.ELEMENT_NODE?t:t.parentElement,i=n==null?void 0:n.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 Mt(r){r.querySelectorAll("strike, del").forEach(t=>{var i;const n=document.createElement("s");for(const o of Array.from(t.attributes))o.name!=="style"&&n.setAttribute(o.name,o.value);for(;t.firstChild;)n.appendChild(t.firstChild);(i=t.parentNode)==null||i.replaceChild(n,t)})}const Lt=Object.freeze(Object.defineProperty({__proto__:null,StrikethroughPlugin:St},Symbol.toStringTag,{value:"Module"})),At=()=>({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=Ht();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 n=t.cloneRange();return r.focus({preventScroll:!0}),document.execCommand("unlink",!1),document.execCommand("removeFormat",!1),Pt(r,n),Dt(r,n),r.dispatchEvent(new Event("input",{bubbles:!0})),!0}},keymap:{"Mod-\\":"clearFormatting"}}),It=new Set(["A","B","STRONG","I","EM","U","S","STRIKE","DEL","FONT","MARK","CODE","SUB","SUP"]),Rt=new Set(["H1","H2","H3","H4","H5","H6","BLOCKQUOTE","PRE"]),Ot=["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 Ht(){const r=window.getSelection();if(r&&r.rangeCount>0){const t=r.getRangeAt(0).startContainer,n=t.nodeType===Node.ELEMENT_NODE?t:t.parentElement,i=n==null?void 0:n.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 Le(r,e){try{if(typeof r.intersectsNode=="function")return r.intersectsNode(e)}catch(n){}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 Ae(r){let e=0,t=r;for(;t&&t.parentNode;)e+=1,t=t.parentNode;return e}function Nt(r){Ot.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 Ie(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(n=>{var o;if(!Le(e,n)||!Rt.has(n.tagName))return;const i=document.createElement("p");for(;n.firstChild;)i.appendChild(n.firstChild);(o=n.parentNode)==null||o.replaceChild(i,n)})}function Dt(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((n,i)=>Ae(i)-Ae(n)),t.forEach(n=>{if(n.isConnected&&Le(e,n)&&!(n.getAttribute("contenteditable")==="false"||n.closest('[contenteditable="false"]'))){if(Nt(n),It.has(n.tagName)){Ie(n);return}n.tagName==="SPAN"&&n.attributes.length===0&&Ie(n)}})}const Bt=Object.freeze(Object.defineProperty({__proto__:null,ClearFormattingPlugin:At},Symbol.toStringTag,{value:"Module"})),$t=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"})),zt=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 ie{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(`
|
|
10
11
|
`)}setText(e){this._lines=e.split(`
|
|
11
12
|
`),this._version++}getTextInRange(e){if(e.start.line===e.end.line)return this.getLine(e.start.line).substring(e.start.column,e.end.column);const t=[];t.push(this.getLine(e.start.line).substring(e.start.column));for(let n=e.start.line+1;n<e.end.line;n++)t.push(this.getLine(n));return e.end.line<this.getLineCount()&&t.push(this.getLine(e.end.line).substring(0,e.end.column)),t.join(`
|
|
12
13
|
`)}replaceRange(e,t){const n=this.getTextInRange(e);if(e.start.line===e.end.line){const i=this.getLine(e.start.line),o=i.substring(0,e.start.column)+t+i.substring(e.end.column);this._lines[e.start.line]=o}else{const i=this.getLine(e.start.line),o=this.getLine(e.end.line),s=i.substring(0,e.start.column)+t,a=o.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:n}}insertText(e,t){const n={start:e,end:e};return this.replaceRange(n,t)}deleteRange(e){return this.replaceRange(e,"")}positionToOffset(e){let t=0;for(let n=0;n<e.line;n++)t+=this.getLine(n).length+1;return t+=e.column,t}offsetToPosition(e){let t=e;for(let n=0;n<this.getLineCount();n++){const i=this.getLine(n).length;if(t<=i)return{line:n,column:t};t-=i+1}return{line:this.getLineCount()-1,column:this.getLine(this.getLineCount()-1).length}}isValidPosition(e){return!(e.line<0||e.line>=this.getLineCount()||e.column<0||e.column>this.getLine(e.line).length)}isValidRange(e){return this.isValidPosition(e.start)&&this.isValidPosition(e.end)}getVersion(){return this._version}clone(){const e=new
|
|
14
|
+
`);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:n}}insertText(e,t){const n={start:e,end:e};return this.replaceRange(n,t)}deleteRange(e){return this.replaceRange(e,"")}positionToOffset(e){let t=0;for(let n=0;n<e.line;n++)t+=this.getLine(n).length+1;return t+=e.column,t}offsetToPosition(e){let t=e;for(let n=0;n<this.getLineCount();n++){const i=this.getLine(n).length;if(t<=i)return{line:n,column:t};t-=i+1}return{line:this.getLineCount()-1,column:this.getLine(this.getLineCount()-1).length}}isValidPosition(e){return!(e.line<0||e.line>=this.getLineCount()||e.column<0||e.column>this.getLine(e.line).length)}isValidRange(e){return this.isValidPosition(e.start)&&this.isValidPosition(e.end)}getVersion(){return this._version}clone(){const e=new ie;return e._lines=[...this._lines],e._version=this._version,e}}class Ft{constructor(e){this.gutterWidth=50,this.lineHeight=21,this.trailingNewlineMarkerAttr="data-lce-trailing-newline-marker",this.virtualMarkerRegex=/[\u200B\uE000]/,this.container=e,this.createDOM()}createDOM(){this.container.innerHTML="";const e=document.createElement("div");this.editorContainer=e,e.setAttribute("data-lce-editor-container","true"),e.style.cssText=`
|
|
14
15
|
position: relative;
|
|
15
16
|
display: flex;
|
|
16
17
|
width: 100%;
|
|
@@ -55,19 +56,19 @@
|
|
|
55
56
|
`).length;this.updateLineNumbers(t)}setHTML(e){const t=/\n$/.test(e),n=/<|>/.test(e),i=/<span\b/i.test(e),o=/<[^>]+>/.test(e);n&&i?this.contentElement.innerHTML=e:o&&!n?this.contentElement.textContent=e:this.contentElement.innerHTML=e,this.syncTrailingNewlineMarker(t);const s=(this.contentElement.textContent||"").split(`
|
|
56
57
|
`).length;this.updateLineNumbers(s)}syncTrailingNewlineMarkerForText(e){this.syncTrailingNewlineMarker(e.endsWith(`
|
|
57
58
|
`))}getCursorPosition(){const e=window.getSelection();if(!e||e.rangeCount===0)return{line:0,column:0};const t=e.getRangeAt(0),n=t.cloneRange();n.selectNodeContents(this.contentElement),n.setEnd(t.endContainer,t.endOffset);const i=n.toString().replace(/\u200B/g,"").split(`
|
|
58
|
-
`);return{line:i.length-1,column:i[i.length-1].length}}setCursorPosition(e){var
|
|
59
|
-
`),
|
|
59
|
+
`);return{line:i.length-1,column:i[i.length-1].length}}setCursorPosition(e){var t;const n=this.getText().split(`
|
|
60
|
+
`),i=Math.min(e.line,n.length-1),o=Math.min(e.column,((t=n[i])==null?void 0:t.length)||0);let s=0;for(let c=0;c<i;c++)s+=n[c].length+1;s+=o;const a=document.createRange(),l=window.getSelection(),d=this.resolveOffsetToDomPoint(s);if(d)try{a.setStart(d.node,d.offset),a.setEnd(d.node,d.offset),l==null||l.removeAllRanges(),l==null||l.addRange(a),this.ensureCaretVisible()}catch(c){console.warn("Could not set cursor position:",c)}else{const c=this.contentElement.querySelector(`[${this.trailingNewlineMarkerAttr}]`);try{c&&c.parentNode===this.contentElement?a.setStartBefore(c):(a.selectNodeContents(this.contentElement),a.collapse(!1)),a.collapse(!0),l==null||l.removeAllRanges(),l==null||l.addRange(a),this.ensureCaretVisible()}catch(h){console.warn("Could not set fallback cursor position:",h)}}}getSelectionRange(){const e=window.getSelection();if(!e||e.rangeCount===0||e.isCollapsed)return;const t=e.getRangeAt(0),n=t.cloneRange();n.selectNodeContents(this.contentElement),n.setEnd(t.startContainer,t.startOffset);const i=n.toString().replace(/\u200B/g,"").split(`
|
|
60
61
|
`),o=t.cloneRange();o.selectNodeContents(this.contentElement),o.setEnd(t.endContainer,t.endOffset);const s=o.toString().replace(/\u200B/g,"").split(`
|
|
61
62
|
`);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){const t=this.getText().split(`
|
|
62
|
-
`),n=h=>{const u=Math.max(0,Math.min(h.line,t.length-1)),
|
|
63
|
+
`),n=h=>{const u=Math.max(0,Math.min(h.line,t.length-1)),p=Math.max(0,Math.min(h.column,t[u]?t[u].length:0));let g=0;for(let f=0;f<u;f++)g+=t[f].length+1;return g+p},i=n(e.start),o=n(e.end),[s,a]=i<=o?[i,o]:[o,i],l=this.resolveOffsetToDomPoint(s),d=this.resolveOffsetToDomPoint(a);if(!l||!d)return;const c=document.createRange();try{c.setStart(l.node,l.offset),c.setEnd(d.node,d.offset);const h=window.getSelection();h==null||h.removeAllRanges(),h==null||h.addRange(c),this.ensureCaretVisible()}catch(h){console.warn("Could not set selection range:",h)}}focus(){this.contentElement.focus(),this.ensureCaretVisible()}blur(){this.contentElement.blur()}setReadOnly(e){this.contentElement.contentEditable=e?"false":"true"}applyTheme(e){Object.entries(e).forEach(([t,n])=>{this.container.style.setProperty(`--${t}`,n)})}scrollToPosition(e){const t=this.lineNumbersElement.children[e.line];t&&t.scrollIntoView({block:"center",behavior:"smooth"})}getScrollTop(){return this.editorContainer.scrollTop}getScrollElement(){return this.editorContainer}setScrollTop(e){this.editorContainer.scrollTop=e}syncTrailingNewlineMarker(e){if(this.contentElement.querySelectorAll(`[${this.trailingNewlineMarkerAttr}]`).forEach(n=>n.remove()),!e)return;const t=document.createElement("span");t.setAttribute(this.trailingNewlineMarkerAttr,"true"),t.setAttribute("aria-hidden","true"),t.contentEditable="false",t.style.cssText=`
|
|
63
64
|
display: inline-block;
|
|
64
65
|
width: 0;
|
|
65
66
|
overflow: hidden;
|
|
66
67
|
pointer-events: none;
|
|
67
68
|
user-select: none;
|
|
68
|
-
`,t.appendChild(document.createTextNode("")),this.contentElement.appendChild(t)}ensureCaretVisible(){var
|
|
69
|
-
`);c.insertNode(h),c.setStartAfter(h),c.collapse(!0),n.removeAllRanges(),n.addRange(c),this.view.ensureCaretVisible();const u=this.view.getText();this.textModel.setText(u),this.view.syncTrailingNewlineMarkerForText(u);const f=Math.min(d+1,this.textModel.getText().length);try{const g=this.textModel.offsetToPosition(f);this.setCursor(g),this.view.ensureCaretVisible()}catch(g){}this.highlightTimeout&&clearTimeout(this.highlightTimeout),this.highlightTimeout=setTimeout(()=>{this.renderTextWithHighlight(this.textModel.getText(),!1),requestAnimationFrame(()=>{try{const g=this.textModel.offsetToPosition(f);this.setCursor(g),this.view.ensureCaretVisible()}catch(g){}}),this.highlightTimeout=null},300),this.updateLineNumbers(),this.emit("change",[{range:this.getFullRange(),text:this.getValue(),oldText:""}])}}t.preventDefault(),t.stopPropagation();return}for(const n of this.extensions.values())if(n.onKeyDown&&n.onKeyDown(t)===!1){t.preventDefault(),t.stopPropagation();return}}),e.addEventListener("mousedown",t=>{this.emit("mousedown",t);for(const n of this.extensions.values())if(n.onMouseDown&&n.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 n=this.eventListeners.get(e);n&&n.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 n=this.extensions.get("syntax-highlighting");if(n&&typeof n.setTheme=="function")try{n.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 n=this.commands.get(e);n?n(this,...t):console.warn(`Command '${e}' not found`)}registerCommand(e,t){this.commands.set(e,t)}search(e,t={}){var c;if(!e)return[];const n={query:e,caseSensitive:!1,wholeWord:!1,regex:!1,...t},i=[],o=this.textModel.getText(),{normalizedText:s,normalizedToRawOffsets:a}=this.buildSearchTextAndOffsetMap(o),l=n.caseSensitive?s:s.toLowerCase(),d=n.caseSensitive?e:e.toLowerCase();if(n.regex){let h;try{h=new RegExp(e,n.caseSensitive?"g":"gi")}catch(f){return[]}let u;for(;(u=h.exec(s))!==null;){const f=(c=u[0])!=null?c:"";if(f.length===0){h.lastIndex=u.index+1;continue}const g=u.index,p=u.index+f.length;n.wholeWord&&!this.isWholeWordBoundary(s,g,p)||this.pushSearchResultFromOffsets(i,g,p,s,a)}}else{let h=0,u=l.indexOf(d,h);for(;u!==-1;){const f=u+d.length;!n.wholeWord||this.isWholeWordBoundary(s,u,f)?(this.pushSearchResultFromOffsets(i,u,f,s,a),h=f):h=u+1,u=l.indexOf(d,h)}}return i}pushSearchResultFromOffsets(e,t,n,i,o){var c,h;const s=(c=o[t])!=null?c:t,a=(h=o[n])!=null?h:s,l=this.textModel.offsetToPosition(s),d=this.textModel.offsetToPosition(a);e.push({range:{start:l,end:d},match:i.substring(t,n)})}isWholeWordBoundary(e,t,n){const i=t>0?e[t-1]:"",o=n<e.length?e[n]:"";return!this.isWordChar(i)&&!this.isWordChar(o)}isWordChar(e){return/^[A-Za-z0-9_]$/.test(e)}buildSearchTextAndOffsetMap(e){const t=[],n=[0];let i=0;for(let o=0;o<e.length;o++){const s=e[o];s===""||s===B.CURSOR_SENTINEL||(t.push(s),i+=1,n[i]=o+1)}return n[i]=e.length,{normalizedText:t.join(""),normalizedToRawOffsets:n}}replace(e,t){const n=this.getValue();if(!this.suppressHistory){const o=this.getCursor().position,s=this.textModel.positionToOffset(o),a=this.getSelection();let l,d;a&&(l=this.textModel.positionToOffset(a.start),d=this.textModel.positionToOffset(a.end)),this.undoStack.push({text:n,cursorOffset:s,anchorOffset:l,focusOffset:d}),this.undoStack.length>100&&this.undoStack.shift(),this.redoStack.length=0}const i=this.textModel.replaceRange(e,t);this.expectingProgrammaticCursor=!0,this.renderTextWithHighlight(this.getValue(),!1),this.expectingProgrammaticCursor=!1,this.emit("change",[i])}replaceAll(e,t,n={}){const i=this.search(e,n);let o=0;for(let s=i.length-1;s>=0;s--)this.replace(i[s].range,t),o++;return o}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 n=this.extensions.get("syntax-highlighting");if(n&&typeof n.highlightHTML=="function")try{const i=!t&&!this.expectingProgrammaticCursor;let o,s,a,l;if(t||i){o=this.getSelection();const u=this.getCollapsedSelectionOffsetInEditor();if(u!==void 0)s=u;else{const f=this.getCursor().position;s=this.textModel.positionToOffset(f)}o&&(a=this.textModel.positionToOffset(o.start),l=this.textModel.positionToOffset(o.end))}const d=(t||i)&&!o&&s!==void 0&&this.hasCollapsedSelectionInEditor(),c=d?this.insertSentinelAtOffset(e,s):e,h=n.highlightHTML(c);typeof this.view.setHighlightHTML=="function"?this.view.setHighlightHTML(h):this.view.setHTML(h),this.view.syncTrailingNewlineMarkerForText(e),(t||i)&&requestAnimationFrame(()=>{try{if(d&&this.restoreCursorFromSentinel()){this.view.ensureCaretVisible();return}if(o&&(a!==void 0||l!==void 0)){const u=a!==void 0?a:s,f=l!==void 0?l:s,g=Math.min(u,f),p=Math.max(u,f),m=this.textModel.offsetToPosition(g),v=this.textModel.offsetToPosition(p);this.view.setSelectionRange({start:m,end:v})}else if(s!==void 0){const u=this.textModel.offsetToPosition(s);this.view.setCursorPosition(u)}}catch(u){}});return}catch(i){console.warn("Syntax highlighting failed, falling back to plain text",i)}this.view.setText(e)}hasCollapsedSelectionInEditor(){const e=window.getSelection();if(!e||e.rangeCount===0||!e.isCollapsed)return!1;const t=e.getRangeAt(0);return this.view.getContentElement().contains(t.commonAncestorContainer)}getCollapsedSelectionOffsetInEditor(){const e=window.getSelection();if(!e||e.rangeCount===0||!e.isCollapsed)return;const t=e.getRangeAt(0),n=this.view.getContentElement();if(!n.contains(t.commonAncestorContainer))return;const i=t.cloneRange();return i.selectNodeContents(n),i.setEnd(t.endContainer,t.endOffset),this.stripVirtualMarkers(i.toString()).length}stripVirtualMarkers(e){return e.replace(/\u200B/g,"").split(B.CURSOR_SENTINEL).join("")}insertSentinelAtOffset(e,t){const n=Math.max(0,Math.min(t,e.length));return e.slice(0,n)+B.CURSOR_SENTINEL+e.slice(n)}restoreCursorFromSentinel(){var a;const e=this.view.getContentElement(),t=window.getSelection(),n=document.createTreeWalker(e,NodeFilter.SHOW_TEXT);let i=n.nextNode(),o=null,s=0;for(;i;){const l=(a=i.textContent)!=null?a:"",d=l.indexOf(B.CURSOR_SENTINEL);d!==-1&&(o||(o=i,s=d),i.textContent=l.split(B.CURSOR_SENTINEL).join("")),i=n.nextNode()}if(!o||!t)return!1;try{const l=document.createRange();return l.setStart(o,s),l.collapse(!0),t.removeAllRanges(),t.addRange(l),!0}catch(l){return!1}}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 n,i;typeof e=="string"?n=e:(n=e.text,i=e.cursorOffset),this.setValue(n),requestAnimationFrame(()=>{try{if(i!=null)if(typeof e!="string"&&(e.anchorOffset!==void 0||e.focusOffset!==void 0)){const o=e.anchorOffset!==void 0?e.anchorOffset:i,s=e.focusOffset!==void 0?e.focusOffset:i,a=Math.min(o,s),l=Math.max(o,s),d=this.textModel.offsetToPosition(a),c=this.textModel.offsetToPosition(l);this.setSelection({start:d,end:c})}else{const o=this.textModel.offsetToPosition(i);this.setCursor(o)}}catch(o){}}),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 n,i;typeof e=="string"?n=e:(n=e.text,i=e.cursorOffset),this.setValue(n),requestAnimationFrame(()=>{try{if(i!=null)if(typeof e!="string"&&(e.anchorOffset!==void 0||e.focusOffset!==void 0)){const o=e.anchorOffset!==void 0?e.anchorOffset:i,s=e.focusOffset!==void 0?e.focusOffset:i,a=Math.min(o,s),l=Math.max(o,s),d=this.textModel.offsetToPosition(a),c=this.textModel.offsetToPosition(l);this.setSelection({start:d,end:c})}else{const o=this.textModel.offsetToPosition(i);this.setCursor(o)}}catch(o){}}),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),n=" ".repeat(this.config.tabSize||2),i=this.textModel.insertText(e,n),o=this.textModel.offsetToPosition(this.textModel.positionToOffset(e)+n.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(o),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),n=this.textModel.insertText(e,`
|
|
70
|
-
`),i=this.textModel.offsetToPosition(this.textModel.positionToOffset(e)+1);if(!this.suppressHistory){const o=this.getSelection();let s,a;o&&(s=this.textModel.positionToOffset(o.start),a=this.textModel.positionToOffset(o.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",[n])}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 n=this.eventListeners.get(e);if(t){const i=n.indexOf(t);i!==-1&&n.splice(i,1)}else n.length=0}};Re.CURSOR_SENTINEL="";let _t=Re;class Ut{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:n,altKey:i,shiftKey:o,metaKey:s}=e,a=String(t).toLowerCase(),l=this.keymap[a];if(!l)return null;for(const d of l){const c=d.ctrlKey===void 0||d.ctrlKey===n,h=d.altKey===void 0||d.altKey===i,u=d.shiftKey===void 0||d.shiftKey===o,
|
|
69
|
+
`,t.appendChild(document.createTextNode("")),this.contentElement.appendChild(t)}ensureCaretVisible(){var e;const t=window.getSelection();if(!t||t.rangeCount===0)return;const n=t.getRangeAt(0).cloneRange();n.collapse(!1);let i=n.getClientRects()[0]||n.getBoundingClientRect();if((!i||i.width===0&&i.height===0)&&t.focusNode instanceof Element?i=t.focusNode.getBoundingClientRect():(!i||i.width===0&&i.height===0)&&(e=t.focusNode)!=null&&e.parentElement&&(i=t.focusNode.parentElement.getBoundingClientRect()),!i)return;const o=this.editorContainer.getBoundingClientRect(),s=12;i.bottom>o.bottom-s?this.editorContainer.scrollTop+=i.bottom-(o.bottom-s):i.top<o.top+s&&(this.editorContainer.scrollTop-=o.top+s-i.top)}destroy(){this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container),this._rafId&&(cancelAnimationFrame(this._rafId),this._rafId=void 0)}resolveOffsetToDomPoint(e){var l;var t;const n=Math.max(0,e);let i=0;const o=document.createTreeWalker(this.contentElement,NodeFilter.SHOW_TEXT,null);let s=null,a;for(;a=o.nextNode();){const d=a.parentElement;if(d!=null&&d.hasAttribute(this.trailingNewlineMarkerAttr))continue;s=a;const c=a.textContent||"",h=this.buildVisibleToDomMap(c),u=Math.max(0,h.length-1);if(i+u>=n){const p=Math.max(0,n-i),g=(l=h[p])!=null?l:c.length;return{node:a,offset:g}}i+=u}if(s){const d=((t=s.textContent)==null?void 0:t.length)||0;return{node:s,offset:d}}return null}buildVisibleToDomMap(e){const t=[0];let n=0;for(let i=0;i<e.length;i++){const o=e[i];this.virtualMarkerRegex.test(o)||(n+=1,t[n]=i+1)}return t}}const Re=class D{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.highlightTimeout=null,this.expectingProgrammaticCursor=!1,this.config={value:"",theme:"default",readOnly:!1,tabSize:2,lineWrapping:!1,lineNumbers:!0,...t},this.textModel=new ie(this.config.value),this.view=new Ft(e),this.setupEventHandlers(),this.config.extensions&&this.config.extensions.forEach(n=>this.addExtension(n)),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(),n=this.textModel.getText();if(t!==n){if(!this.suppressHistory){const i=this.getCursor().position,o=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:n,cursorOffset:o,anchorOffset:a,focusOffset:l}),this.undoStack.length>100&&this.undoStack.shift(),this.redoStack.length=0}this.textModel.setText(t),this.view.syncTrailingNewlineMarkerForText(t),this.highlightTimeout&&clearTimeout(this.highlightTimeout),this.highlightTimeout=setTimeout(()=>{const i=this.view.getText();i!==this.textModel.getText()&&this.textModel.setText(i),this.renderTextWithHighlight(this.textModel.getText(),!1),this.highlightTimeout=null},300),this.updateLineNumbers(),this.emit("change",[{range:this.getFullRange(),text:t,oldText:n}])}}),e.addEventListener("selectionchange",()=>{const t=this.getCursor(),n=this.getSelection();this.emit("cursor",t),n&&this.emit("selection",n)}),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 n=window.getSelection();if(n&&n.rangeCount>0){const i=this.getCursor().position,o=this.textModel.positionToOffset(i),s=this.getSelection();let a,l;s&&(a=this.textModel.positionToOffset(s.start),l=this.textModel.positionToOffset(s.end));const d=s&&a!==void 0&&l!==void 0?Math.min(a,l):o;this.suppressHistory||(this.undoStack.push({text:this.textModel.getText(),cursorOffset:o,anchorOffset:a,focusOffset:l}),this.undoStack.length>100&&this.undoStack.shift(),this.redoStack.length=0);const c=n.getRangeAt(0);c.deleteContents();const h=document.createTextNode(`
|
|
70
|
+
`);c.insertNode(h),c.setStartAfter(h),c.collapse(!0),n.removeAllRanges(),n.addRange(c),this.view.ensureCaretVisible();const u=this.view.getText();this.textModel.setText(u),this.view.syncTrailingNewlineMarkerForText(u);const p=Math.min(d+1,this.textModel.getText().length);try{const g=this.textModel.offsetToPosition(p);this.setCursor(g),this.view.ensureCaretVisible()}catch(g){}this.highlightTimeout&&clearTimeout(this.highlightTimeout),this.highlightTimeout=setTimeout(()=>{this.renderTextWithHighlight(this.textModel.getText(),!1),requestAnimationFrame(()=>{try{const g=this.textModel.offsetToPosition(p);this.setCursor(g),this.view.ensureCaretVisible()}catch(g){}}),this.highlightTimeout=null},300),this.updateLineNumbers(),this.emit("change",[{range:this.getFullRange(),text:this.getValue(),oldText:""}])}}t.preventDefault(),t.stopPropagation();return}for(const n of this.extensions.values())if(n.onKeyDown&&n.onKeyDown(t)===!1){t.preventDefault(),t.stopPropagation();return}}),e.addEventListener("mousedown",t=>{this.emit("mousedown",t);for(const n of this.extensions.values())if(n.onMouseDown&&n.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 n=this.eventListeners.get(e);n&&n.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 n=this.extensions.get("syntax-highlighting");if(n&&typeof n.setTheme=="function")try{n.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 n=this.commands.get(e);n?n(this,...t):console.warn(`Command '${e}' not found`)}registerCommand(e,t){this.commands.set(e,t)}search(e,t={}){var c;if(!e)return[];const n={query:e,caseSensitive:!1,wholeWord:!1,regex:!1,...t},i=[],o=this.textModel.getText(),{normalizedText:s,normalizedToRawOffsets:a}=this.buildSearchTextAndOffsetMap(o),l=n.caseSensitive?s:s.toLowerCase(),d=n.caseSensitive?e:e.toLowerCase();if(n.regex){let h;try{h=new RegExp(e,n.caseSensitive?"g":"gi")}catch(p){return[]}let u;for(;(u=h.exec(s))!==null;){const p=(c=u[0])!=null?c:"";if(p.length===0){h.lastIndex=u.index+1;continue}const g=u.index,f=u.index+p.length;n.wholeWord&&!this.isWholeWordBoundary(s,g,f)||this.pushSearchResultFromOffsets(i,g,f,s,a)}}else{let h=0,u=l.indexOf(d,h);for(;u!==-1;){const p=u+d.length;!n.wholeWord||this.isWholeWordBoundary(s,u,p)?(this.pushSearchResultFromOffsets(i,u,p,s,a),h=p):h=u+1,u=l.indexOf(d,h)}}return i}pushSearchResultFromOffsets(e,t,n,i,o){var c,h;const s=(c=o[t])!=null?c:t,a=(h=o[n])!=null?h:s,l=this.textModel.offsetToPosition(s),d=this.textModel.offsetToPosition(a);e.push({range:{start:l,end:d},match:i.substring(t,n)})}isWholeWordBoundary(e,t,n){const i=t>0?e[t-1]:"",o=n<e.length?e[n]:"";return!this.isWordChar(i)&&!this.isWordChar(o)}isWordChar(e){return/^[A-Za-z0-9_]$/.test(e)}buildSearchTextAndOffsetMap(e){const t=[],n=[0];let i=0;for(let o=0;o<e.length;o++){const s=e[o];s===""||s===D.CURSOR_SENTINEL||(t.push(s),i+=1,n[i]=o+1)}return n[i]=e.length,{normalizedText:t.join(""),normalizedToRawOffsets:n}}replace(e,t){const n=this.getValue();if(!this.suppressHistory){const o=this.getCursor().position,s=this.textModel.positionToOffset(o),a=this.getSelection();let l,d;a&&(l=this.textModel.positionToOffset(a.start),d=this.textModel.positionToOffset(a.end)),this.undoStack.push({text:n,cursorOffset:s,anchorOffset:l,focusOffset:d}),this.undoStack.length>100&&this.undoStack.shift(),this.redoStack.length=0}const i=this.textModel.replaceRange(e,t);this.expectingProgrammaticCursor=!0,this.renderTextWithHighlight(this.getValue(),!1),this.expectingProgrammaticCursor=!1,this.emit("change",[i])}replaceAll(e,t,n={}){const i=this.search(e,n);let o=0;for(let s=i.length-1;s>=0;s--)this.replace(i[s].range,t),o++;return o}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 n=this.extensions.get("syntax-highlighting");if(n&&typeof n.highlightHTML=="function")try{const i=!t&&!this.expectingProgrammaticCursor;let o,s,a,l;if(t||i){o=this.getSelection();const u=this.getCollapsedSelectionOffsetInEditor();if(u!==void 0)s=u;else{const p=this.getCursor().position;s=this.textModel.positionToOffset(p)}o&&(a=this.textModel.positionToOffset(o.start),l=this.textModel.positionToOffset(o.end))}const d=(t||i)&&!o&&s!==void 0&&this.hasCollapsedSelectionInEditor(),c=d?this.insertSentinelAtOffset(e,s):e,h=n.highlightHTML(c);typeof this.view.setHighlightHTML=="function"?this.view.setHighlightHTML(h):this.view.setHTML(h),this.view.syncTrailingNewlineMarkerForText(e),(t||i)&&requestAnimationFrame(()=>{try{if(d&&this.restoreCursorFromSentinel()){this.view.ensureCaretVisible();return}if(o&&(a!==void 0||l!==void 0)){const u=a!==void 0?a:s,p=l!==void 0?l:s,g=Math.min(u,p),f=Math.max(u,p),m=this.textModel.offsetToPosition(g),v=this.textModel.offsetToPosition(f);this.view.setSelectionRange({start:m,end:v})}else if(s!==void 0){const u=this.textModel.offsetToPosition(s);this.view.setCursorPosition(u)}}catch(u){}});return}catch(i){console.warn("Syntax highlighting failed, falling back to plain text",i)}this.view.setText(e)}hasCollapsedSelectionInEditor(){const e=window.getSelection();if(!e||e.rangeCount===0||!e.isCollapsed)return!1;const t=e.getRangeAt(0);return this.view.getContentElement().contains(t.commonAncestorContainer)}getCollapsedSelectionOffsetInEditor(){const e=window.getSelection();if(!e||e.rangeCount===0||!e.isCollapsed)return;const t=e.getRangeAt(0),n=this.view.getContentElement();if(!n.contains(t.commonAncestorContainer))return;const i=t.cloneRange();return i.selectNodeContents(n),i.setEnd(t.endContainer,t.endOffset),this.stripVirtualMarkers(i.toString()).length}stripVirtualMarkers(e){return e.replace(/\u200B/g,"").split(D.CURSOR_SENTINEL).join("")}insertSentinelAtOffset(e,t){const n=Math.max(0,Math.min(t,e.length));return e.slice(0,n)+D.CURSOR_SENTINEL+e.slice(n)}restoreCursorFromSentinel(){var a;const e=this.view.getContentElement(),t=window.getSelection(),n=document.createTreeWalker(e,NodeFilter.SHOW_TEXT);let i=n.nextNode(),o=null,s=0;for(;i;){const l=(a=i.textContent)!=null?a:"",d=l.indexOf(D.CURSOR_SENTINEL);d!==-1&&(o||(o=i,s=d),i.textContent=l.split(D.CURSOR_SENTINEL).join("")),i=n.nextNode()}if(!o||!t)return!1;try{const l=document.createRange();return l.setStart(o,s),l.collapse(!0),t.removeAllRanges(),t.addRange(l),!0}catch(l){return!1}}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 n,i;typeof e=="string"?n=e:(n=e.text,i=e.cursorOffset),this.setValue(n),requestAnimationFrame(()=>{try{if(i!=null)if(typeof e!="string"&&(e.anchorOffset!==void 0||e.focusOffset!==void 0)){const o=e.anchorOffset!==void 0?e.anchorOffset:i,s=e.focusOffset!==void 0?e.focusOffset:i,a=Math.min(o,s),l=Math.max(o,s),d=this.textModel.offsetToPosition(a),c=this.textModel.offsetToPosition(l);this.setSelection({start:d,end:c})}else{const o=this.textModel.offsetToPosition(i);this.setCursor(o)}}catch(o){}}),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 n,i;typeof e=="string"?n=e:(n=e.text,i=e.cursorOffset),this.setValue(n),requestAnimationFrame(()=>{try{if(i!=null)if(typeof e!="string"&&(e.anchorOffset!==void 0||e.focusOffset!==void 0)){const o=e.anchorOffset!==void 0?e.anchorOffset:i,s=e.focusOffset!==void 0?e.focusOffset:i,a=Math.min(o,s),l=Math.max(o,s),d=this.textModel.offsetToPosition(a),c=this.textModel.offsetToPosition(l);this.setSelection({start:d,end:c})}else{const o=this.textModel.offsetToPosition(i);this.setCursor(o)}}catch(o){}}),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),n=" ".repeat(this.config.tabSize||2),i=this.textModel.insertText(e,n),o=this.textModel.offsetToPosition(this.textModel.positionToOffset(e)+n.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(o),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),n=this.textModel.insertText(e,`
|
|
71
|
+
`),i=this.textModel.offsetToPosition(this.textModel.positionToOffset(e)+1);if(!this.suppressHistory){const o=this.getSelection();let s,a;o&&(s=this.textModel.positionToOffset(o.start),a=this.textModel.positionToOffset(o.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",[n])}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 n=this.eventListeners.get(e);if(t){const i=n.indexOf(t);i!==-1&&n.splice(i,1)}else n.length=0}};Re.CURSOR_SENTINEL="";let _t=Re;class Ut{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:n,altKey:i,shiftKey:o,metaKey:s}=e,a=String(t).toLowerCase(),l=this.keymap[a];if(!l)return null;for(const d of l){const c=d.ctrlKey===void 0||d.ctrlKey===n,h=d.altKey===void 0||d.altKey===i,u=d.shiftKey===void 0||d.shiftKey===o,p=d.metaKey===void 0||d.metaKey===s;if(c&&h&&u&&p)return d}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,n,i){const o=t.toLowerCase();e[o]||(e[o]=[]),e[o].push({key:o,command:i,...n})}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(n=>n.command!==e.command),this.keymap[t].push({...e,key:t})}removeKeyBinding(e,t){const n=e.toLowerCase();t?this.keymap[n]&&(this.keymap[n]=this.keymap[n].filter(i=>i.command!==t),this.keymap[n].length===0&&delete this.keymap[n]):delete this.keymap[n]}getKeymap(){return{...this.keymap}}getBindingsForCommand(e){const t=[];for(const n in this.keymap)for(const i of this.keymap[n])i.command===e&&t.push({...i});return t}getPlatformInfo(){return{isMac:this.isMac,platform:navigator.platform}}destroy(){this.keymap={},this.editor=null}}class jt{constructor(){this.name="transaction",this.transactions=[]}setup(e){e.on("change",t=>{const n={changes:t,selection:e.getSelection(),effects:[],annotations:[]};this.transactions.push(n)})}getTransactions(){return this.transactions}destroy(){this.transactions=[]}}class Vt{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(`
|
|
71
72
|
`).length,t=Array.from({length:Math.max(e,20)},(n,i)=>i+1);this.lineNumbersElement.innerHTML=t.map(n=>`<div style="height: 21px; line-height: 21px; padding-right: 12px;">${n}</div>`).join("")}toggle(){if(!this.editor)return;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 Wt{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 Kt{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}}let qt=0;const Oe=class b{constructor(e={}){this.name="search",this.editor=null,this.searchUI=null,this.isVisible=!1,this.currentResults=[],this.currentIndex=-1,this.searchDebounceTimer=null,this.liveRefreshTimer=null,this.statusResetTimer=null,this.statusFreezeUntil=0,this.findInput=null,this.replaceInputEl=null,this.statusDiv=null,this.modeDiv=null,this.caseSensitiveInput=null,this.wholeWordInput=null,this.regexInput=null,this.currentQuery="",this.savedCursor=null,this.editorChangeHandler=null,this.searchOptions={caseSensitive:!1,wholeWord:!1,regex:!1},this.trailingMarkerAttr="data-lce-trailing-newline-marker",this.editorContainerSelector='[data-lce-editor-container="true"]',this.highlightId=++qt,this.highlightMatchName=`editora-search-match-${this.highlightId}`,this.highlightActiveName=`editora-search-active-${this.highlightId}`,this.highlightStyleId=`editora-search-highlight-style-${this.highlightId}`,this.maxCustomHighlightRanges=2e3,this.virtualMarkerRegex=/[\u200B\uE000]/,this.hasCustomHighlightSupport=!1,this.config={replaceAndFindNext:!0,...e}}setup(e){this.editor=e,this.hasCustomHighlightSupport=this.detectCustomHighlightSupport(),this.hasCustomHighlightSupport&&this.ensureHighlightStyles(),e.registerCommand("find",()=>{this.showSearch()}),e.registerCommand("findNext",()=>{this.findNext()}),e.registerCommand("findPrev",()=>{this.findPrev()}),e.registerCommand("replace",()=>{this.showReplace()}),e.registerCommand("replaceAll",(t,n)=>{this.replaceAll(t,n)}),this.editorChangeHandler=()=>{!this.isVisible||!this.currentQuery||this.scheduleLiveRefresh(!0)},e.on("change",this.editorChangeHandler)}showSearch(){this.editor&&(this.searchUI||this.createSearchUI(),this.isVisible||this.captureSelectionState(),this.isVisible=!0,this.searchUI&&(this.searchUI.style.display="block",this.updateModeHint(!1),this.findInput&&(this.findInput.focus(),this.findInput.select())),this.currentQuery&&this.performSearch(this.currentQuery,!0,!1))}showReplace(){this.showSearch(),this.replaceInputEl&&(this.replaceInputEl.style.display="block",this.replaceInputEl.focus()),this.updateModeHint(!0),this.currentQuery&&this.performSearch(this.currentQuery,!1,!0)}hideSearch(){this.isVisible=!1,this.searchUI&&(this.searchUI.style.display="none"),this.replaceInputEl&&(this.replaceInputEl.style.display="none",this.replaceInputEl.value=""),this.updateModeHint(!1),this.clearHighlights(),this.restoreSelectionState()}createSearchUI(){if(!this.editor)return;const e=this.editor.getView().getContentElement(),t=e.closest(this.editorContainerSelector),n=e.closest(".rte-source-editor-modal")||t||e.parentElement;if(!n)return;window.getComputedStyle(n).position==="static"&&(n.style.position="relative"),this.searchUI=document.createElement("div"),this.searchUI.className=b.css.root,this.searchUI.style.display="none",this.searchUI.innerHTML=`
|
|
72
73
|
<div class="${b.css.row}">
|
|
73
74
|
<input type="text" class="${b.css.findInput} ${b.css.inputBase}" placeholder="Find..." />
|
|
@@ -94,11 +95,11 @@
|
|
|
94
95
|
<div class="${b.css.mode} ${b.css.modeLayout}" aria-live="polite"></div>
|
|
95
96
|
</div>
|
|
96
97
|
<input type="text" class="${b.css.replaceInput} ${b.css.inputBase} ${b.css.replaceInputLayout}" placeholder="Replace with..." />
|
|
97
|
-
`;const i=this.searchUI.querySelector(`.${b.css.findInput}`),o=this.searchUI.querySelector(`.${b.css.replaceInput}`),s=this.searchUI.querySelector(`.${b.css.prevButton}`),a=this.searchUI.querySelector(`.${b.css.nextButton}`),l=this.searchUI.querySelector(`.${b.css.closeButton}`),d=this.searchUI.querySelector(`.${b.css.status}`),c=this.searchUI.querySelector(`.${b.css.mode}`),h=this.searchUI.querySelector(`.${b.css.caseSensitive}`),u=this.searchUI.querySelector(`.${b.css.wholeWord}`),
|
|
98
|
+
`;const i=this.searchUI.querySelector(`.${b.css.findInput}`),o=this.searchUI.querySelector(`.${b.css.replaceInput}`),s=this.searchUI.querySelector(`.${b.css.prevButton}`),a=this.searchUI.querySelector(`.${b.css.nextButton}`),l=this.searchUI.querySelector(`.${b.css.closeButton}`),d=this.searchUI.querySelector(`.${b.css.status}`),c=this.searchUI.querySelector(`.${b.css.mode}`),h=this.searchUI.querySelector(`.${b.css.caseSensitive}`),u=this.searchUI.querySelector(`.${b.css.wholeWord}`),p=this.searchUI.querySelector(`.${b.css.regex}`);this.findInput=i,this.replaceInputEl=o,this.statusDiv=d,this.modeDiv=c,this.caseSensitiveInput=h,this.wholeWordInput=u,this.regexInput=p,h.checked=!!this.searchOptions.caseSensitive,u.checked=!!this.searchOptions.wholeWord,p.checked=!!this.searchOptions.regex,i.addEventListener("input",()=>{this.searchDebounceTimer&&clearTimeout(this.searchDebounceTimer);const f=i.value;this.searchDebounceTimer=setTimeout(()=>{this.performSearch(f,!1,!1)},120)});const g=()=>{this.searchOptions.caseSensitive=h.checked,this.searchOptions.wholeWord=u.checked,this.searchOptions.regex=p.checked;const f=i.value;f.trim()?this.performSearch(f,!1,!1):this.performSearch("",!1,!1)};h.addEventListener("change",g),u.addEventListener("change",g),p.addEventListener("change",g),i.addEventListener("keydown",f=>{f.key==="Enter"?(f.preventDefault(),f.shiftKey?this.findPrev():this.findNext()):f.key==="Escape"&&(f.preventDefault(),this.hideSearch())}),o.addEventListener("keydown",f=>{f.key==="Enter"?(f.preventDefault(),f.shiftKey?this.replaceAll(i.value,o.value):this.replaceCurrent(i.value,o.value)):f.key==="Escape"&&(f.preventDefault(),this.hideSearch())}),s.addEventListener("click",()=>this.findPrev()),a.addEventListener("click",()=>this.findNext()),l.addEventListener("click",()=>this.hideSearch()),n.appendChild(this.searchUI)}updateModeHint(e){this.modeDiv&&(this.modeDiv.textContent=e?`Replace: move next ${this.config.replaceAndFindNext?"ON":"OFF"}`:"Find mode")}performSearch(e,t,n){if(!this.editor||!e.trim()){this.currentQuery="",this.currentResults=[],this.currentIndex=-1,this.clearHighlights(),this.updateStatus("");return}if(this.searchOptions.regex&&!this.isValidRegex(e)){this.currentQuery=e,this.currentResults=[],this.currentIndex=-1,this.clearHighlights(),this.updateStatus("Invalid regular expression");return}this.currentQuery=e;const i=this.currentIndex,o=this.editor.search(e,this.searchOptions);if(this.currentResults=o,o.length===0){this.currentIndex=-1,this.clearHighlights(),this.updateStatus("No matches");return}t&&i>=0?this.currentIndex=Math.min(i,o.length-1):this.currentIndex=0,this.updateHighlights(n)}findNext(){if(this.currentResults.length===0){this.currentQuery&&this.performSearch(this.currentQuery,!0,!0);return}this.currentIndex=(this.currentIndex+1)%this.currentResults.length,this.updateHighlights(!0)}findPrev(){if(this.currentResults.length===0){this.currentQuery&&this.performSearch(this.currentQuery,!0,!0);return}this.currentIndex=this.currentIndex<=0?this.currentResults.length-1:this.currentIndex-1,this.updateHighlights(!0)}replaceCurrent(e,t){if(!this.editor||!e.trim()||((this.currentQuery!==e||this.currentResults.length===0)&&this.performSearch(e,!1,!0),this.currentIndex<0||this.currentResults.length===0))return;const n=this.currentResults[this.currentIndex];if(!n)return;const i=this.computeReplacementRange(n.range.start,t);if(this.editor.replace(n.range,t),this.config.replaceAndFindNext){this.currentQuery=e;const o=this.editor.search(e,this.searchOptions);if(this.currentResults=o,o.length===0){this.currentIndex=-1,this.clearHighlights(),this.updateStatus("Replaced current occurrence"),this.restoreReplaceInputFocus();return}this.currentIndex=this.findNextResultIndexAfter(i.end,o),this.updateHighlights(!0)}else this.scrollLogicalRangeIntoView(i,!0),this.performSearch(e,!0,!1);this.currentResults.length>0||this.showTransientStatus("Replaced current occurrence"),this.restoreReplaceInputFocus(),this.revealActiveResultAfterFocusRestore()}replaceAll(e,t){if(!this.editor||!e.trim())return;const n=this.editor.replaceAll(e,t,this.searchOptions);this.performSearch(e,!1,!1),this.showTransientStatus(`Replaced ${n} occurrence${n===1?"":"s"}`),this.restoreReplaceInputFocus(),this.revealActiveResultAfterFocusRestore()}updateHighlights(e){if(this.clearHighlights(),this.currentResults.length===0||this.currentIndex===-1||!this.editor)return;this.applyCustomHighlights();const t=this.currentResults[this.currentIndex];t&&((e||!this.hasCustomHighlightSupport)&&this.navigateToResult(t,!this.hasCustomHighlightSupport),this.updateStatus(`${this.currentResults.length} matches (showing ${this.currentIndex+1}/${this.currentResults.length})`))}navigateToResult(e,t){if(!this.editor)return;const n=document.activeElement,i=!!n&&(n===this.findInput||n===this.replaceInputEl);t?(this.editor.setSelection(e.range),this.centerCurrentSelectionInView()):this.scrollResultIntoView(e);const o=this.editor.getView();t&&typeof o.ensureCaretVisible=="function"&&o.ensureCaretVisible(),t&&i&&n&&requestAnimationFrame(()=>{this.focusWithoutScrolling(n)})}clearHighlights(){var e,t;if(this.hasCustomHighlightSupport)try{const n=CSS;(e=n.highlights)==null||e.delete(this.highlightMatchName),(t=n.highlights)==null||t.delete(this.highlightActiveName)}catch(n){}}scrollResultIntoView(e){this.scrollLogicalRangeIntoView(e.range,!0)}scrollLogicalRangeIntoView(e,t){if(!this.editor)return;const n=this.editor.getView().getContentElement(),i=this.editor.getValue(),{lineStarts:o,lines:s}=this.buildLineStarts(i),a=this.buildTextNodeIndex(n);if(a.length===0)return;const l=this.toDomRange(e,o,s,a);if(!l)return;const d=l.startContainer.nodeType===Node.TEXT_NODE?l.startContainer.parentElement:l.startContainer,c=this.resolveScrollContainer(n);if(c){const h=l.getClientRects()[0]||l.getBoundingClientRect(),u=c.getBoundingClientRect(),p=c.scrollTop+(h.top-u.top)-u.height/2+h.height/2,g=18;let f=t?p:c.scrollTop,m=c.scrollLeft;const v=c.scrollLeft+(h.left-u.left),E=v+h.width;h.right>u.right-g?m=E-u.width+g:h.left<u.left+g&&(m=Math.max(0,v-g));const x=Math.max(0,c.scrollHeight-c.clientHeight),T=Math.max(0,c.scrollWidth-c.clientWidth);if(f=Math.min(x,Math.max(0,f)),m=Math.min(T,Math.max(0,m)),x===0&&T===0){d==null||d.scrollIntoView({block:t?"center":"nearest",inline:"nearest",behavior:"smooth"});return}(f!==c.scrollTop||m!==c.scrollLeft)&&c.scrollTo({top:f,left:m,behavior:"smooth"});return}d==null||d.scrollIntoView({block:t?"center":"nearest",inline:"nearest",behavior:"smooth"})}restoreReplaceInputFocus(){const e=this.replaceInputEl;!e||e.style.display==="none"||requestAnimationFrame(()=>{this.focusWithoutScrolling(e);const t=e.value.length;try{e.setSelectionRange(t,t)}catch(n){}})}centerCurrentSelectionInView(){if(!this.editor)return;const e=this.editor.getView().getContentElement(),t=this.resolveScrollContainer(e);if(!t)return;const n=window.getSelection();if(!n||n.rangeCount===0)return;const i=n.getRangeAt(0).cloneRange(),o=i.getClientRects()[0]||i.getBoundingClientRect();if(!o)return;const s=t.getBoundingClientRect(),a=t.scrollTop+(o.top-s.top)-s.height/2+o.height/2,l=Math.max(0,t.scrollHeight-t.clientHeight),d=Math.min(l,Math.max(0,a));d!==t.scrollTop&&t.scrollTo({top:d,behavior:"smooth"})}computeReplacementRange(e,t){const n=t.replace(/\r\n?/g,`
|
|
98
99
|
`),i=n.split(`
|
|
99
|
-
`);let o;return i.length<=1?(o={start:e,end:{line:e.line,column:e.column+n.length}},this.clampRangeToDocument(o)):(o={start:e,end:{line:e.line+i.length-1,column:i[i.length-1].length}},this.clampRangeToDocument(o))}findNextResultIndexAfter(e,t){for(let n=0;n<t.length;n++)if(this.comparePositions(t[n].range.start,e)>=0)return n;return 0}comparePositions(e,t){return e.line!==t.line?e.line-t.line:e.column-t.column}clampRangeToDocument(e){var
|
|
100
|
-
`),
|
|
101
|
-
`),n=new Array(t.length);let i=0;for(let o=0;o<t.length;o++)n[o]=i,i+=t[o].length+1;return{lineStarts:n,lines:t}}positionToOffset(e,t,n){var
|
|
100
|
+
`);let o;return i.length<=1?(o={start:e,end:{line:e.line,column:e.column+n.length}},this.clampRangeToDocument(o)):(o={start:e,end:{line:e.line+i.length-1,column:i[i.length-1].length}},this.clampRangeToDocument(o))}findNextResultIndexAfter(e,t){for(let n=0;n<t.length;n++)if(this.comparePositions(t[n].range.start,e)>=0)return n;return 0}comparePositions(e,t){return e.line!==t.line?e.line-t.line:e.column-t.column}clampRangeToDocument(e){var t,n;const i=this.editor;if(!i)return e;const o=i.getValue().split(`
|
|
101
|
+
`),s=Math.max(0,o.length-1),a=Math.max(0,Math.min(e.start.line,s)),l=Math.max(0,Math.min(e.end.line,s)),d=Math.max(0,Math.min(e.start.column,((t=o[a])==null?void 0:t.length)||0)),c=Math.max(0,Math.min(e.end.column,((n=o[l])==null?void 0:n.length)||0));return{start:{line:a,column:d},end:{line:l,column:c}}}focusWithoutScrolling(e){try{e.focus({preventScroll:!0})}catch(t){const n=[];let i=e.parentElement;for(;i;)this.canScroll(i)&&n.push({el:i,top:i.scrollTop,left:i.scrollLeft}),i=i.parentElement;const o=window.scrollX,s=window.scrollY;e.focus();for(let a=0;a<n.length;a++){const l=n[a];l.el.scrollTop=l.top,l.el.scrollLeft=l.left}window.scrollTo(o,s)}}findScrollContainer(e){let t=e;for(;t;){const n=window.getComputedStyle(t).overflowY;if((n==="auto"||n==="scroll")&&t.scrollHeight>t.clientHeight)return t;t=t.parentElement}return null}resolveScrollContainer(e){var t,n;const i=(t=this.editor)==null?void 0:t.getView(),o=((n=i==null?void 0:i.getScrollElement)==null?void 0:n.call(i))||null;return o&&this.canScroll(o)?o:this.findScrollContainer(e)}canScroll(e){return e.scrollHeight>e.clientHeight||e.scrollWidth>e.clientWidth}revealActiveResultAfterFocusRestore(){!this.currentResults.length||this.currentIndex<0||requestAnimationFrame(()=>{const e=this.currentResults[this.currentIndex];e&&this.scrollResultIntoView(e)})}applyCustomHighlights(){if(!this.editor||!this.hasCustomHighlightSupport||this.currentResults.length===0)return;const e=this.editor.getView().getContentElement(),t=this.editor.getValue(),{lineStarts:n,lines:i}=this.buildLineStarts(t),o=this.buildTextNodeIndex(e);if(o.length===0)return;const s=this.buildVisibleDocumentText(o),a=[];let l=null;const d=Math.min(this.currentResults.length,this.maxCustomHighlightRanges);for(let c=0;c<d;c++){const h=this.currentResults[c],u=this.searchOptions.regex?h.match||this.currentQuery:this.currentQuery||h.match,p=this.toDomRange(h.range,n,i,o,s,u);p&&(a.push(p),c===this.currentIndex&&(l=p))}if(a.length!==0)try{const c=CSS,h=window.Highlight;if(!c.highlights||!h)return;c.highlights.set(this.highlightMatchName,new h(...a)),l&&c.highlights.set(this.highlightActiveName,new h(l))}catch(c){}}buildLineStarts(e){const t=e.split(`
|
|
102
|
+
`),n=new Array(t.length);let i=0;for(let o=0;o<t.length;o++)n[o]=i,i+=t[o].length+1;return{lineStarts:n,lines:t}}positionToOffset(e,t,n){var i;const o=Math.max(0,Math.min(e.line,n.length-1)),s=Math.max(0,Math.min(e.column,((i=n[o])==null?void 0:i.length)||0));return t[o]+s}buildTextNodeIndex(e){const t=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,null),n=[];let i=0,o;for(;o=t.nextNode();){const s=o,a=s.parentElement;if(a!=null&&a.hasAttribute(this.trailingMarkerAttr))continue;const l=s.textContent||"",d=this.buildVisibleToDomMap(l),c=Math.max(0,d.length-1);c===0&&l.length===0||(n.push({node:s,start:i,end:i+c,visibleToDom:d}),i+=c)}return n}resolveDomPoint(e,t){var a,l,d,c;var n,i;const o=Math.max(0,e);for(let h=0;h<t.length;h++){const u=t[h];if(o<=u.end){const p=Math.max(0,o-u.start),g=(l=(a=u.visibleToDom[p])!=null?a:(n=u.node.textContent)==null?void 0:n.length)!=null?l:0;return{node:u.node,offset:g}}}const s=t[t.length-1];return s?{node:s.node,offset:(c=(d=s.visibleToDom[s.visibleToDom.length-1])!=null?d:(i=s.node.textContent)==null?void 0:i.length)!=null?c:0}:null}toDomRange(e,t,n,i,o,s){const a=this.positionToOffset(e.start,t,n),l=this.positionToOffset(e.end,t,n);let d=Math.min(a,l),c=Math.max(a,l);if(o&&s){const g=s,f=o.slice(d,c);if(f.length===g.length&&f.toLowerCase()!==g.toLowerCase()){const m=this.findNearestMatchOffset(o,g,d);m!==-1&&(d=m,c=m+g.length)}}const h=this.resolveDomPoint(d,i),u=this.resolveDomPoint(c,i);if(!h||!u)return null;const p=document.createRange();try{return p.setStart(h.node,h.offset),p.setEnd(u.node,u.offset),p}catch(g){return null}}buildVisibleDocumentText(e){let t="";for(let n=0;n<e.length;n++){const i=e[n].node.textContent||"";for(let o=0;o<i.length;o++){const s=i[o];this.virtualMarkerRegex.test(s)||(t+=s)}}return t}findNearestMatchOffset(e,t,n){const i=t.toLowerCase();let o=e.toLowerCase().indexOf(i);if(o===-1)return-1;let s=o,a=Math.abs(o-n);for(;o!==-1;){const l=Math.abs(o-n);if(l<a&&(a=l,s=o),l===0)return o;o=e.toLowerCase().indexOf(i,o+1)}return s}scheduleLiveRefresh(e){this.liveRefreshTimer&&clearTimeout(this.liveRefreshTimer);const t=this.currentQuery;this.liveRefreshTimer=setTimeout(()=>{!this.isVisible||!t||this.performSearch(t,e,!1)},90)}updateStatus(e,t=!1){if(this.statusDiv){if(!t&&Date.now()<this.statusFreezeUntil)return;this.statusDiv.textContent=e}}showTransientStatus(e,t=900){this.statusFreezeUntil=Date.now()+t,this.updateStatus(e,!0),this.statusResetTimer&&clearTimeout(this.statusResetTimer),this.statusResetTimer=setTimeout(()=>{this.statusFreezeUntil=0,this.syncMatchStatus()},t)}syncMatchStatus(){if(!this.currentQuery){this.updateStatus("",!0);return}if(this.currentResults.length===0||this.currentIndex<0){this.updateStatus("No matches",!0);return}this.updateStatus(`${this.currentResults.length} matches (showing ${this.currentIndex+1}/${this.currentResults.length})`,!0)}isValidRegex(e){try{const t=this.searchOptions.caseSensitive?"g":"gi";return new RegExp(e,t),!0}catch(t){return!1}}captureSelectionState(){this.editor&&(this.savedSelection=this.editor.getSelection(),this.savedCursor=this.editor.getCursor().position)}restoreSelectionState(){this.editor&&(this.savedSelection?this.editor.setSelection(this.savedSelection):this.savedCursor&&this.editor.setCursor(this.savedCursor),this.savedSelection=void 0,this.savedCursor=null)}detectCustomHighlightSupport(){try{const e=CSS,t=window.Highlight;return!!e.highlights&&!!t}catch(e){return!1}}buildVisibleToDomMap(e){const t=[0];let n=0;for(let i=0;i<e.length;i++){const o=e[i];this.virtualMarkerRegex.test(o)||(n+=1,t[n]=i+1)}return t}ensureHighlightStyles(){if(document.getElementById(this.highlightStyleId))return;const e=document.createElement("style");e.id=this.highlightStyleId,e.textContent=`
|
|
102
103
|
::highlight(${this.highlightMatchName}) {
|
|
103
104
|
background: var(--lce-search-match-bg, rgba(255, 214, 10, 0.34));
|
|
104
105
|
border-radius: 2px;
|
|
@@ -132,7 +133,7 @@
|
|
|
132
133
|
color: var(--editor-gutter-foreground, #858585);
|
|
133
134
|
font-size: 10px;
|
|
134
135
|
user-select: none;
|
|
135
|
-
`,t.innerHTML="▶",t.title="Code folding not yet implemented - click shows fold indicators",t.addEventListener("click",()=>{}),t}foldAtCursor(){}unfoldAtCursor(){}foldAll(){}unfoldAll(){}destroy(){this.pendingUpdateRaf!==null&&(cancelAnimationFrame(this.pendingUpdateRaf),this.pendingUpdateRaf=null),this.editor&&this.changeHandler&&this.editor.off("change",this.changeHandler),this.foldingUI&&this.foldingUI.parentNode&&this.foldingUI.parentNode.removeChild(this.foldingUI),this.changeHandler=null,this.lastSnapshot="",this.foldingUI=null,this.foldIndicators=[],this.editor=null}}class Yt{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,n)=>this._highlightHTML(t,n)}),this.registerMode("javascript",{name:"javascript",highlight:(t,n)=>this._highlightJS(t,n)}),this.registerMode("typescript",{name:"typescript",highlight:(t,n)=>this._highlightJS(t,n)}),this.registerMode("php",{name:"php",highlight:(t,n)=>this._highlightPHP(t,n)})}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 n=this.getSyntaxColors(),i=(t||this.currentLanguage||"html").toLowerCase();return(this.modes.get(i)||this.modes.get("html")).highlight(e,n)}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 n=0;n<5;n++){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 n=t,i=d=>this.escapeHTML(d);let o=i(e);const s=d=>{let c=d.replace(/"/g,'"').replace(/'/g,"'");return c=c.replace(/(\/\*[\s\S]*?\*\/)/g,`<span style="color: ${n.comment};">$1</span>`),c=c.replace(/([a-zA-Z-]+)(\s*:\s*)([^;{]+)(;?)/g,(h,u,
|
|
136
|
+
`,t.innerHTML="▶",t.title="Code folding not yet implemented - click shows fold indicators",t.addEventListener("click",()=>{}),t}foldAtCursor(){}unfoldAtCursor(){}foldAll(){}unfoldAll(){}destroy(){this.pendingUpdateRaf!==null&&(cancelAnimationFrame(this.pendingUpdateRaf),this.pendingUpdateRaf=null),this.editor&&this.changeHandler&&this.editor.off("change",this.changeHandler),this.foldingUI&&this.foldingUI.parentNode&&this.foldingUI.parentNode.removeChild(this.foldingUI),this.changeHandler=null,this.lastSnapshot="",this.foldingUI=null,this.foldIndicators=[],this.editor=null}}class Yt{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,n)=>this._highlightHTML(t,n)}),this.registerMode("javascript",{name:"javascript",highlight:(t,n)=>this._highlightJS(t,n)}),this.registerMode("typescript",{name:"typescript",highlight:(t,n)=>this._highlightJS(t,n)}),this.registerMode("php",{name:"php",highlight:(t,n)=>this._highlightPHP(t,n)})}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 n=this.getSyntaxColors(),i=(t||this.currentLanguage||"html").toLowerCase();return(this.modes.get(i)||this.modes.get("html")).highlight(e,n)}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 n=0;n<5;n++){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 n=t,i=d=>this.escapeHTML(d);let o=i(e);const s=d=>{let c=d.replace(/"/g,'"').replace(/'/g,"'");return c=c.replace(/(\/\*[\s\S]*?\*\/)/g,`<span style="color: ${n.comment};">$1</span>`),c=c.replace(/([a-zA-Z-]+)(\s*:\s*)([^;{]+)(;?)/g,(h,u,p,g,f)=>{const m=String(g).trim(),v=i(m);return`<span style="color: ${n.styleProp};">${u}</span>${p}<span style="color: ${n.styleVal};">${v}</span>${f}`}),c},a=[];try{e.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi,(d,c,h)=>(a.push({attrs:String(c||""),inner:String(h||"")}),d))}catch(d){}let l=0;return o=o.replace(/(<script\b([^&>]*)>)([\s\S]*?)(<\/script>)/gi,(d,c,h,u,p)=>{var E;var g,f;const m=(E=(g=a[l++])==null?void 0:g.inner)!=null?E:this.unescapeEntitiesRepeated(u||"");(((f=a[l-1])==null?void 0:f.attrs)||h||"").toLowerCase();const v=this._highlightJS(m,n);return`${c}${v}${p}`}),o=o.replace(/(<style\b[^&]*>)([\s\S]*?)(<\/style>)/gi,(d,c,h,u)=>{const p=s(h);return`${c}${p}${u}`}),o=o.replace(/(<!--[\s\S]*?-->)/g,`<span style="color: ${n.comment};">$1</span>`),o=o.replace(/(<!DOCTYPE[\s\S]*?>)/i,`<span style="color: ${n.doctype};">$1</span>`),o=o.replace(/(<\/?\s*)([^\s&>\/]+)([\s\S]*?)(\/?>)/g,(d,c,h,u,p)=>{const g=`<span style="color: ${n.tag};">${h}</span>`;let f=u;return f=f.replace(/([\w:-]+)(\s*=\s*)(("[\s\S]*?"|'[\s\S]*?'|[^\s&>]+))/g,(m,v,E,x)=>{const T=String(v).toLowerCase(),R=`<span style="color: ${n.attrName};">${v}</span>`;let M=x,k="";x.startsWith(""")&&x.endsWith(""")?(M=x.slice(6,-6),k="""):x.startsWith("'")&&x.endsWith("'")&&(M=x.slice(5,-5),k="'");let C=x;if(T==="style"){const z=M.replace(/([\w-]+)\s*:\s*([^;]+)(;?)/g,(me,X,Y,F)=>`<span style="color: ${n.styleProp};">${X}</span>:<span style="color: ${n.styleVal};">${Y.trim()}</span>${F}`);k?C=`${k}${z}${k}`:C=z,C=`<span style="color: ${n.attrValue};">${C}</span>`}else k&&(C=`${k}${M}${k}`),C=`<span style="color: ${n.attrValue};">${C}</span>`;return`${R}${E}${C}`}),`${c}${g}${f}${p}`}),o}_highlightJS(e,t){const n=this.unescapeEntitiesRepeated(e);this.escapeHTML(n);const i=[],o=u=>{let p="",g=u;do p=String.fromCharCode(97+g%26)+p,g=Math.floor(g/26)-1;while(g>=0);return p||"a"},s=u=>`\0${o(u)}\0`,a=u=>{const p=i.length;return i.push(u),s(p)};let l;const d=/(\/\*[\s\S]*?\*\/)|(\/\/[^\n\r]*)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)/g;let c=0,h="";for(;l=d.exec(n);){const u=l.index;c<u&&(h+=this.escapeHTML(n.slice(c,u)));const p=l[0];/^\/\*/.test(p)||/^\/\//.test(p)?h+=a(`<span style="color: ${t.comment};">${this.escapeHTML(p)}</span>`):h+=a(`<span style="color: ${t.string};">${this.escapeHTML(p)}</span>`),c=d.lastIndex}return c<n.length&&(h+=this.escapeHTML(n.slice(c))),h=h.replace(/\b(0x[0-9a-fA-F]+|\d+\.?\d*|\d*\.\d+)\b/g,(u,p,g)=>{const f=h[g-1]||"",m=h[g+u.length]||"";return f==="&"||f==="#"||m===";"||m==="#"?u:`<span style="color: ${t.number};">${u}</span>`}),h=h.replace(/\b(const|let|var|function|class|if|else|return|for|while|switch|case|break|import|from|export|extends|new|try|catch|finally|throw|await|async|interface|type)\b/g,`<span style="color: ${t.keyword};">$1</span>`),h.replace(/\u0000([a-z]+)\u0000/g,(u,p)=>{let g=0;for(let f=0;f<p.length;f++)g=g*26+(p.charCodeAt(f)-97+1);return g=g-1,i[g]||""})}_highlightPHP(e,t){const n=this.unescapeEntitiesRepeated(e);let i=this.escapeHTML(n);const o=[],s=g=>{let f="",m=g;do f=String.fromCharCode(97+m%26)+f,m=Math.floor(m/26)-1;while(m>=0);return f||"a"},a=g=>{const f=o.length;return o.push(g),`\0${s(f)}\0`},l=(g,f)=>{const m=i.indexOf(g);return m===-1?!1:(i=i.slice(0,m)+f+i.slice(m+g.length),!0)};let d;const c=/\/\*[\s\S]*?\*\//g,h=/\/\/[^\n\r]*/g,u=/\#([^\n\r]*)/g,p=/("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')/g;for(;d=c.exec(n);){const g=d[0];l(this.escapeHTML(g),a(`<span style="color: ${t.comment};">${this.escapeHTML(g)}</span>`))}for(;d=h.exec(n);){const g=d[0];l(this.escapeHTML(g),a(`<span style="color: ${t.comment};">${this.escapeHTML(g)}</span>`))}for(;d=u.exec(n);){const g=d[0];l(this.escapeHTML(g),a(`<span style="color: ${t.comment};">${this.escapeHTML(g)}</span>`))}for(;d=p.exec(n);){const g=d[0];l(this.escapeHTML(g),a(`<span style="color: ${t.string};">${this.escapeHTML(g)}</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,(g,f)=>{let m=0;for(let v=0;v<f.length;v++)m=m*26+(f.charCodeAt(v)-97+1);return m=m-1,o[m]||""}),i}shouldHighlight(e){return/<\/?[\w:-]+|<!--/.test(e)}destroy(){this.editor=null,this.modes.clear()}}function Gt(r,e){const t={...e};return t.extensions||(t.extensions=[]),t.extensions.some(n=>n.name==="keymap")||t.extensions.unshift(new Ut(t.keymap)),t.extensions.some(n=>n.name==="transaction")||t.extensions.unshift(new jt),new _t(r,t)}const oe='[data-theme="dark"], .dark, .editora-theme-dark',Jt=`/* Source Editor Dialog Styles */
|
|
136
137
|
.rte-source-editor-overlay {
|
|
137
138
|
position: fixed !important;
|
|
138
139
|
top: 0 !important;
|
|
@@ -512,7 +513,7 @@
|
|
|
512
513
|
}`,en=Object.freeze(Object.defineProperty({__proto__:null,CodePlugin:()=>({name:"code",toolbar:[{label:"Source",command:"toggleSourceView",icon:'<svg width="24" height="24" focusable="false"><g fill-rule="nonzero"><path d="M9.8 15.7c.3.3.3.8 0 1-.3.4-.9.4-1.2 0l-4.4-4.1a.8.8 0 0 1 0-1.2l4.4-4.2c.3-.3.9-.3 1.2 0 .3.3.3.8 0 1.1L6 12l3.8 3.7ZM14.2 15.7c-.3.3-.3.8 0 1 .4.4.9.4 1.2 0l4.4-4.1c.3-.3.3-.9 0-1.2l-4.4-4.2a.8.8 0 0 0-1.2 0c-.3.3-.3.8 0 1.1L18 12l-3.8 3.7Z"></path></g></svg>',shortcut:"Mod-Shift-S"}],commands:{toggleSourceView:()=>{const e=(()=>{var a,l,d;const o=window.getSelection();if(o&&o.anchorNode){let c=o.anchorNode instanceof HTMLElement?o.anchorNode:o.anchorNode.parentElement;for(;c;){if((a=c.classList)!=null&&a.contains("rte-content"))return c;c=c.parentElement}}if(document.activeElement){let c=document.activeElement;if((l=c.classList)!=null&&l.contains("rte-content"))return c;for(;c&&c!==document.body;){if((d=c.classList)!=null&&d.contains("rte-content"))return c;const h=c.querySelector(".rte-content");if(h)return h;c=c.parentElement}}const s=document.querySelector("[data-editora-editor]");if(s){const c=s.querySelector(".rte-content");if(c)return c}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,n=o=>{let s="",a=0;const l=2,d=o.split(/(<\/?[a-zA-Z][^>]*>)/);for(const c of d)c.trim()&&(c.match(/^<\/[a-zA-Z]/)?(a=Math.max(0,a-1),s+=`
|
|
513
514
|
`+" ".repeat(a*l)+c):c.match(/^<[a-zA-Z]/)&&!c.match(/\/>$/)?(s+=`
|
|
514
515
|
`+" ".repeat(a*l)+c,a++):c.match(/^<[a-zA-Z].*\/>$/)?s+=`
|
|
515
|
-
`+" ".repeat(a*l)+c:s+=c.trim());return s.trim()};return(()=>{const s=n(t);let a=null,l="dark",d=!1,c=!1,h=!1,u=!1;const
|
|
516
|
+
`+" ".repeat(a*l)+c:s+=c.trim());return s.trim()};return(()=>{const s=n(t);let a=null,l="dark",d=!1,c=!1,h=!1,u=!1;const p=!!e.closest(oe)||document.body.matches(oe)||document.documentElement.matches(oe),g=document.createElement("div");g.className="rte-source-editor-overlay",p&&g.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 m=document.createElement("div");m.className="rte-source-editor-header",m.innerHTML=`
|
|
516
517
|
<h2 id="source-editor-title">Source Editor</h2>
|
|
517
518
|
<div class="rte-source-editor-header-toolbar">
|
|
518
519
|
<button class="rte-source-editor-toolbar-btn theme-toggle-btn" title="Switch theme">
|
|
@@ -556,7 +557,7 @@
|
|
|
556
557
|
<button class="rte-source-editor-btn rte-source-editor-btn-cancel">Cancel</button>
|
|
557
558
|
<button class="rte-source-editor-btn rte-source-editor-btn-save">Save</button>
|
|
558
559
|
</div>
|
|
559
|
-
`,
|
|
560
|
+
`,f.appendChild(m),f.appendChild(v),f.appendChild(R),g.appendChild(f),!document.getElementById("rte-source-editor-styles")){const y=document.createElement("style");y.id="rte-source-editor-styles",y.textContent=Jt,document.head.appendChild(y)}const M=m.querySelector(".theme-toggle-btn"),k=m.querySelector(".readonly-toggle-btn"),C=m.querySelector(".rte-source-editor-fullscreen-btn"),z=m.querySelector(".rte-source-editor-close-btn"),me=R.querySelector(".rte-source-editor-btn-cancel"),X=R.querySelector(".rte-source-editor-btn-save"),Y=R.querySelector(".unsaved-changes"),F=[],O=(y,L,be,U)=>{y.addEventListener(L,be,U),F.push(()=>y.removeEventListener(L,be,U))},qe=y=>{h!==y&&(h=y,Y&&(Y.style.display=h?"inline":"none"))},_=()=>{if(!u){for(u=!0;F.length;){const y=F.pop();y==null||y()}a&&(a.destroy(),a=null),g.isConnected&&g.remove()}},cn=()=>{l=l==="dark"?"light":"dark",a==null||a.setTheme(l),M&&(M.innerHTML=l==="light"?`
|
|
560
561
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
561
562
|
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>
|
|
562
563
|
</svg>
|
|
@@ -591,5 +592,5 @@
|
|
|
591
592
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
592
593
|
<path d="M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"/>
|
|
593
594
|
</svg>
|
|
594
|
-
`)},un=()=>{h&&!confirm("You have unsaved changes. Are you sure you want to cancel?")||U()},gn=()=>{try{const y=(a==null?void 0:a.getValue())||"",L=document.createElement("div");L.innerHTML=y,L.querySelectorAll('script, iframe[src^="javascript:"], object, embed').forEach(j=>j.remove()),e.innerHTML=L.innerHTML;try{e.dispatchEvent(new InputEvent("input",{bubbles:!0,cancelable:!1,inputType:"insertReplacementText"}))}catch(j){e.dispatchEvent(new Event("input",{bubbles:!0}))}e.dispatchEvent(new Event("change",{bubbles:!0})),qe(!1),U()}catch(y){alert("Failed to update HTML. Please check your syntax."),console.error("HTML update error:",y)}};M&&O(M,"click",cn),k&&O(k,"click",dn),C&&O(C,"click",hn),F&&O(F,"click",U),ye&&O(ye,"click",un),X&&O(X,"click",gn),O(g,"click",y=>{y.target===g&&U()}),O(document,"keydown",y=>{const L=y;L.key==="Escape"&&(L.preventDefault(),U())}),document.body.appendChild(g),requestAnimationFrame(()=>{if(!(u||!g.isConnected))try{a=Gt(T,{value:s,theme:"dark",readOnly:!1,extensions:[new Vt,new Wt,new Kt,new Qt,new Zt,new Xt,new Yt]}),a.on("change",()=>{const y=(a==null?void 0:a.getValue())||"";qe(y!==s)}),requestAnimationFrame(()=>a==null?void 0:a.focus())}catch(y){console.error("Failed to initialize code editor:",y)}})})(),!0}},keymap:{"Mod-Shift-s":"toggleSourceView","Mod-Shift-S":"toggleSourceView"}})},Symbol.toStringTag,{value:"Module"})),se=()=>He("insertUnorderedList"),ae=()=>He("insertOrderedList");function tn(){const r=window.getSelection();if(r&&r.rangeCount>0){const t=r.getRangeAt(0).startContainer,n=t.nodeType===Node.ELEMENT_NODE?t:t.parentElement,i=n==null?void 0:n.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 nn(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 o=document.createElement("li");for(;i.firstChild;)o.appendChild(i.firstChild);t.replaceChild(o,i)})})}function He(r){const e=tn();if(!e)return!1;const t=window.getSelection();if(!t||t.rangeCount===0)return!1;const n=t.getRangeAt(0);if(!e.contains(n.commonAncestorContainer))return!1;e.focus({preventScroll:!0});const i=document.execCommand(r,!1);return nn(e),e.dispatchEvent(new Event("input",{bubbles:!0})),i!==!1}const Ne=(r,e)=>{var t;typeof window!="undefined"&&((t=window.registerEditorCommand)==null||t.call(window,r,e))},Pe=()=>{Ne("toggleBulletList",se),Ne("toggleOrderedList",ae)};typeof window!="undefined"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",Pe):Pe());const on=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:se,toggleOrderedList:ae},keymap:{"Mod-Shift-8":"toggleBulletList","Mod-Shift-7":"toggleOrderedList"}}),toggleBulletList:se,toggleOrderedList:ae},Symbol.toStringTag,{value:"Module"})),De=".rte-content, .editora-content",Be=100,$e="__editoraCommandEditorRoot",P=new Map,le={};let ze=!1,w=null;function rn(r){if(!r)return null;const e=r.querySelector('[contenteditable="true"]');return e instanceof HTMLElement?e:null}function sn(){if(typeof window=="undefined")return null;const r=window[$e];if(!(r instanceof HTMLElement))return null;window[$e]=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 n=rn(e);if(n)return n;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 an(r){return r?r.nodeType===Node.ELEMENT_NODE?r:r.parentElement:null}function z(r){const e=an(r);if(!e)return null;const t=e.closest(De);if(t)return t;const n=e.closest('[contenteditable="true"]');if(!n)return null;let i=n,o=i.parentElement;for(;o;)o.getAttribute("contenteditable")==="true"&&(i=o),o=o.parentElement;return i}function K(){const r=sn();if(r&&document.contains(r))return r;const e=window.getSelection();if(e&&e.rangeCount>0){const o=z(e.getRangeAt(0).startContainer);if(o)return o}const t=document.activeElement;if(t){const o=z(t);if(o)return o}if(w!=null&&w.isConnected)return w;const n=Array.from(P.keys()).find(o=>o.isConnected);if(n)return n;const i=document.querySelector(De);return i||document.querySelector('[contenteditable="true"]')}function Fe(){for(const r of P.keys())r.isConnected||(P.delete(r),w===r&&(w=null))}function ce(r){Fe();let e=P.get(r);return e||(e={undoStack:[],redoStack:[]},P.set(r,e)),e}function D(r){r&&r.dispatchEvent(new Event("input",{bubbles:!0}))}function _e(r){return r?r.innerHTML:""}function q(r,e){if(!r)return;const t=ce(r);t.undoStack.push(e),t.redoStack.length=0,t.undoStack.length>Be&&t.undoStack.splice(0,t.undoStack.length-Be),w=r}function Ue(r,e="undo"){if(Fe(),r!=null&&r.isConnected)return r;const t=K();if(t!=null&&t.isConnected)return t;if(w!=null&&w.isConnected)return w;const n=i=>e==="undo"?i.undoStack.length>0:i.redoStack.length>0;for(const[i,o]of P.entries())if(i.isConnected&&n(o))return i;return null}function je(r){const e={};for(const i of r.getAttributeNames()){const o=r.getAttribute(i);o!==null&&(e[i]=o)}const t=r instanceof HTMLInputElement||r instanceof HTMLTextAreaElement||r instanceof HTMLSelectElement,n=r instanceof HTMLInputElement;return{attributes:e,innerHTML:r.innerHTML,value:t?r.value:null,checked:n?r.checked:null}}function Ve(r,e){const t=new Set(r.getAttributeNames());Object.keys(e.attributes).forEach(n=>t.delete(n)),t.forEach(n=>r.removeAttribute(n)),Object.entries(e.attributes).forEach(([n,i])=>{r.setAttribute(n,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 I(r,e){if(le[r]=e,typeof window=="undefined")return;const t=window.registerEditorCommand;typeof t=="function"?t(r,e):(window.registerEditorCommand=(n,i)=>{le[n]=i},window.registerEditorCommand(r,e))}const We=(r,...e)=>{const t=le[r];return t?t(...e):!1};function de(){ze||typeof window=="undefined"||(ze=!0,window.execEditorCommand||(window.execEditorCommand=We),window.executeEditorCommand||(window.executeEditorCommand=We),I("undo",he),I("redo",ue),I("setAttribute",ge),I("setText",fe),I("autoFixA11y",pe),I("recordDomTransaction",me),I("undoDom",Z),I("redoDom",Q))}function Ke(r,e){const t=e||K(),n=_e(t);t==null||t.focus({preventScroll:!0});let i=!1;try{i=!!document.execCommand(r,!1)}catch(a){i=!1}const o=_e(t),s=n!==o;return s&&D(t),{executed:i,changed:s}}const he=()=>{const r=K();return Ke("undo",r).changed?!0:Z(r!=null?r:void 0)},ue=()=>{const r=K();return Ke("redo",r).changed?!0:Q(r!=null?r:void 0)},ge=(r,e,t)=>{if(!(r instanceof HTMLElement))return;const n=z(r),i=r.hasAttribute(e),o=r.getAttribute(e);r.setAttribute(e,t),q(n,{undo:()=>{r.isConnected&&(i&&o!==null?r.setAttribute(e,o):r.removeAttribute(e))},redo:()=>{r.isConnected&&r.setAttribute(e,t)}}),D(n)},fe=(r,e)=>{var i;if(!(r instanceof HTMLElement))return;const t=z(r),n=(i=r.textContent)!=null?i:"";r.textContent=e,q(t,{undo:()=>{r.isConnected&&(r.textContent=n)},redo:()=>{r.isConnected&&(r.textContent=e)}}),D(t)},pe=r=>{var s;const e=r==null?void 0:r.element;if(!(e instanceof HTMLElement))return;const t=z(e),n=(s=window.a11yRuleRegistry)==null?void 0:s.find(a=>a.id===r.rule);if(!n||typeof n.fix!="function")return;const i=je(e);n.fix(r);const o=je(e);q(t,{undo:()=>{e.isConnected&&Ve(e,i)},redo:()=>{e.isConnected&&Ve(e,o)}}),D(t)},me=(r,e,t)=>{if(!(r instanceof HTMLElement))return!1;const n=typeof t=="string"?t:r.innerHTML;return e===n?!1:(q(r,{undo:()=>{r.isConnected&&(r.innerHTML=e)},redo:()=>{r.isConnected&&(r.innerHTML=n)}}),!0)},Z=r=>{const e=Ue(r,"undo");if(!e)return!1;const t=ce(e),n=t.undoStack.pop();return n?(n.undo(),t.redoStack.push(n),w=e,D(e),!0):!1},Q=r=>{const e=Ue(r,"redo");if(!e)return!1;const t=ce(e),n=t.redoStack.pop();return n?(n.redo(),t.undoStack.push(n),w=e,D(e),!0):!1};typeof window!="undefined"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",de,{once:!0}):de());const ln=Object.freeze(Object.defineProperty({__proto__:null,HistoryPlugin:()=>(de(),{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:he,redo:ue,setAttribute:ge,setText:fe,autoFixA11y:pe,recordDomTransaction:me,undoDom:Z,redoDom:Q},keymap:{"Mod-z":"undo","Mod-Z":"undo","Mod-y":"redo","Mod-Y":"redo","Mod-Shift-z":"redo","Mod-Shift-Z":"redo"}}),autoFixA11y:pe,recordDomTransaction:me,redo:ue,redoDom:Q,setAttribute:ge,setText:fe,undo:he,undoDom:Z},Symbol.toStringTag,{value:"Module"}));H.initWebComponent=Te,Object.defineProperty(H,Symbol.toStringTag,{value:"Module"})}));
|
|
595
|
+
`)},un=()=>{h&&!confirm("You have unsaved changes. Are you sure you want to cancel?")||_()},gn=()=>{try{const y=(a==null?void 0:a.getValue())||"",L=document.createElement("div");L.innerHTML=y,L.querySelectorAll('script, iframe[src^="javascript:"], object, embed').forEach(U=>U.remove()),e.innerHTML=L.innerHTML;try{e.dispatchEvent(new InputEvent("input",{bubbles:!0,cancelable:!1,inputType:"insertReplacementText"}))}catch(U){e.dispatchEvent(new Event("input",{bubbles:!0}))}e.dispatchEvent(new Event("change",{bubbles:!0})),qe(!1),_()}catch(y){alert("Failed to update HTML. Please check your syntax."),console.error("HTML update error:",y)}};M&&O(M,"click",cn),k&&O(k,"click",dn),C&&O(C,"click",hn),z&&O(z,"click",_),me&&O(me,"click",un),X&&O(X,"click",gn),O(g,"click",y=>{y.target===g&&_()}),O(document,"keydown",y=>{const L=y;L.key==="Escape"&&(L.preventDefault(),_())}),document.body.appendChild(g),requestAnimationFrame(()=>{if(!(u||!g.isConnected))try{a=Gt(T,{value:s,theme:"dark",readOnly:!1,extensions:[new Vt,new Wt,new Kt,new Qt,new Zt,new Xt,new Yt]}),a.on("change",()=>{const y=(a==null?void 0:a.getValue())||"";qe(y!==s)}),requestAnimationFrame(()=>a==null?void 0:a.focus())}catch(y){console.error("Failed to initialize code editor:",y)}})})(),!0}},keymap:{"Mod-Shift-s":"toggleSourceView","Mod-Shift-S":"toggleSourceView"}})},Symbol.toStringTag,{value:"Module"})),re=()=>He("insertUnorderedList"),se=()=>He("insertOrderedList");function tn(){const r=window.getSelection();if(r&&r.rangeCount>0){const t=r.getRangeAt(0).startContainer,n=t.nodeType===Node.ELEMENT_NODE?t:t.parentElement,i=n==null?void 0:n.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 nn(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 o=document.createElement("li");for(;i.firstChild;)o.appendChild(i.firstChild);t.replaceChild(o,i)})})}function He(r){const e=tn();if(!e)return!1;const t=window.getSelection();if(!t||t.rangeCount===0)return!1;const n=t.getRangeAt(0);if(!e.contains(n.commonAncestorContainer))return!1;e.focus({preventScroll:!0});const i=document.execCommand(r,!1);return nn(e),e.dispatchEvent(new Event("input",{bubbles:!0})),i!==!1}const Ne=(r,e)=>{var t;typeof window!="undefined"&&((t=window.registerEditorCommand)==null||t.call(window,r,e))},Pe=()=>{Ne("toggleBulletList",re),Ne("toggleOrderedList",se)};typeof window!="undefined"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",Pe):Pe());const on=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:re,toggleOrderedList:se},keymap:{"Mod-Shift-8":"toggleBulletList","Mod-Shift-7":"toggleOrderedList"}}),toggleBulletList:re,toggleOrderedList:se},Symbol.toStringTag,{value:"Module"})),De=".rte-content, .editora-content",Be=100,$e="__editoraCommandEditorRoot",N=new Map,ae={};let ze=!1,w=null;function rn(r){if(!r)return null;const e=r.querySelector('[contenteditable="true"]');return e instanceof HTMLElement?e:null}function sn(){if(typeof window=="undefined")return null;const r=window[$e];if(!(r instanceof HTMLElement))return null;window[$e]=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 n=rn(e);if(n)return n;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 an(r){return r?r.nodeType===Node.ELEMENT_NODE?r:r.parentElement:null}function $(r){const e=an(r);if(!e)return null;const t=e.closest(De);if(t)return t;const n=e.closest('[contenteditable="true"]');if(!n)return null;let i=n,o=i.parentElement;for(;o;)o.getAttribute("contenteditable")==="true"&&(i=o),o=o.parentElement;return i}function K(){const r=sn();if(r&&document.contains(r))return r;const e=window.getSelection();if(e&&e.rangeCount>0){const o=$(e.getRangeAt(0).startContainer);if(o)return o}const t=document.activeElement;if(t){const o=$(t);if(o)return o}if(w!=null&&w.isConnected)return w;const n=Array.from(N.keys()).find(o=>o.isConnected);if(n)return n;const i=document.querySelector(De);return i||document.querySelector('[contenteditable="true"]')}function Fe(){for(const r of N.keys())r.isConnected||(N.delete(r),w===r&&(w=null))}function le(r){Fe();let e=N.get(r);return e||(e={undoStack:[],redoStack:[]},N.set(r,e)),e}function P(r){r&&r.dispatchEvent(new Event("input",{bubbles:!0}))}function _e(r){return r?r.innerHTML:""}function q(r,e){if(!r)return;const t=le(r);t.undoStack.push(e),t.redoStack.length=0,t.undoStack.length>Be&&t.undoStack.splice(0,t.undoStack.length-Be),w=r}function Ue(r,e="undo"){if(Fe(),r!=null&&r.isConnected)return r;const t=K();if(t!=null&&t.isConnected)return t;if(w!=null&&w.isConnected)return w;const n=i=>e==="undo"?i.undoStack.length>0:i.redoStack.length>0;for(const[i,o]of N.entries())if(i.isConnected&&n(o))return i;return null}function je(r){const e={};for(const i of r.getAttributeNames()){const o=r.getAttribute(i);o!==null&&(e[i]=o)}const t=r instanceof HTMLInputElement||r instanceof HTMLTextAreaElement||r instanceof HTMLSelectElement,n=r instanceof HTMLInputElement;return{attributes:e,innerHTML:r.innerHTML,value:t?r.value:null,checked:n?r.checked:null}}function Ve(r,e){const t=new Set(r.getAttributeNames());Object.keys(e.attributes).forEach(n=>t.delete(n)),t.forEach(n=>r.removeAttribute(n)),Object.entries(e.attributes).forEach(([n,i])=>{r.setAttribute(n,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 I(r,e){if(ae[r]=e,typeof window=="undefined")return;const t=window.registerEditorCommand;typeof t=="function"?t(r,e):(window.registerEditorCommand=(n,i)=>{ae[n]=i},window.registerEditorCommand(r,e))}const We=(r,...e)=>{const t=ae[r];return t?t(...e):!1};function ce(){ze||typeof window=="undefined"||(ze=!0,window.execEditorCommand||(window.execEditorCommand=We),window.executeEditorCommand||(window.executeEditorCommand=We),I("undo",de),I("redo",he),I("setAttribute",ue),I("setText",ge),I("autoFixA11y",pe),I("recordDomTransaction",fe),I("undoDom",Z),I("redoDom",Q))}function Ke(r,e){const t=e||K(),n=_e(t);t==null||t.focus({preventScroll:!0});let i=!1;try{i=!!document.execCommand(r,!1)}catch(a){i=!1}const o=_e(t),s=n!==o;return s&&P(t),{executed:i,changed:s}}const de=()=>{const r=K();return Ke("undo",r).changed?!0:Z(r!=null?r:void 0)},he=()=>{const r=K();return Ke("redo",r).changed?!0:Q(r!=null?r:void 0)},ue=(r,e,t)=>{if(!(r instanceof HTMLElement))return;const n=$(r),i=r.hasAttribute(e),o=r.getAttribute(e);r.setAttribute(e,t),q(n,{undo:()=>{r.isConnected&&(i&&o!==null?r.setAttribute(e,o):r.removeAttribute(e))},redo:()=>{r.isConnected&&r.setAttribute(e,t)}}),P(n)},ge=(r,e)=>{var i;if(!(r instanceof HTMLElement))return;const t=$(r),n=(i=r.textContent)!=null?i:"";r.textContent=e,q(t,{undo:()=>{r.isConnected&&(r.textContent=n)},redo:()=>{r.isConnected&&(r.textContent=e)}}),P(t)},pe=r=>{var s;const e=r==null?void 0:r.element;if(!(e instanceof HTMLElement))return;const t=$(e),n=(s=window.a11yRuleRegistry)==null?void 0:s.find(a=>a.id===r.rule);if(!n||typeof n.fix!="function")return;const i=je(e);n.fix(r);const o=je(e);q(t,{undo:()=>{e.isConnected&&Ve(e,i)},redo:()=>{e.isConnected&&Ve(e,o)}}),P(t)},fe=(r,e,t)=>{if(!(r instanceof HTMLElement))return!1;const n=typeof t=="string"?t:r.innerHTML;return e===n?!1:(q(r,{undo:()=>{r.isConnected&&(r.innerHTML=e)},redo:()=>{r.isConnected&&(r.innerHTML=n)}}),!0)},Z=r=>{const e=Ue(r,"undo");if(!e)return!1;const t=le(e),n=t.undoStack.pop();return n?(n.undo(),t.redoStack.push(n),w=e,P(e),!0):!1},Q=r=>{const e=Ue(r,"redo");if(!e)return!1;const t=le(e),n=t.redoStack.pop();return n?(n.redo(),t.undoStack.push(n),w=e,P(e),!0):!1};typeof window!="undefined"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",ce,{once:!0}):ce());const ln=Object.freeze(Object.defineProperty({__proto__:null,HistoryPlugin:()=>(ce(),{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:de,redo:he,setAttribute:ue,setText:ge,autoFixA11y:pe,recordDomTransaction:fe,undoDom:Z,redoDom:Q},keymap:{"Mod-z":"undo","Mod-Z":"undo","Mod-y":"redo","Mod-Y":"redo","Mod-Shift-z":"redo","Mod-Shift-Z":"redo"}}),autoFixA11y:pe,recordDomTransaction:fe,redo:he,redoDom:Q,setAttribute:ue,setText:ge,undo:de,undoDom:Z},Symbol.toStringTag,{value:"Module"}));H.initWebComponent=Te,Object.defineProperty(H,Symbol.toStringTag,{value:"Module"})});
|
|
595
596
|
//# sourceMappingURL=webcomponent-core.min.js.map
|