@editora/core 1.0.1 → 1.0.2
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 +9 -0
- package/dist/A11yCheckerPlugin.native-CZKpi3uF.mjs +475 -0
- package/dist/A11yCheckerPlugin.native-CZKpi3uF.mjs.map +1 -0
- package/dist/AnchorPlugin.native-7es9PVZ9.mjs +340 -0
- package/dist/AnchorPlugin.native-7es9PVZ9.mjs.map +1 -0
- package/dist/BackgroundColorPlugin.native-Dip5uqTg.mjs +449 -0
- package/dist/BackgroundColorPlugin.native-Dip5uqTg.mjs.map +1 -0
- package/dist/BlockquotePlugin.native-JFmOLsxN.mjs +48 -0
- package/dist/BlockquotePlugin.native-JFmOLsxN.mjs.map +1 -0
- package/dist/BoldPlugin.native-BAzzoqU5.mjs +45 -0
- package/dist/BoldPlugin.native-BAzzoqU5.mjs.map +1 -0
- package/dist/CapitalizationPlugin.native-DOMsh5R7.mjs +79 -0
- package/dist/CapitalizationPlugin.native-DOMsh5R7.mjs.map +1 -0
- package/dist/ChecklistPlugin.native-Dccs3nLe.mjs +153 -0
- package/dist/ChecklistPlugin.native-Dccs3nLe.mjs.map +1 -0
- package/dist/ClearFormattingPlugin.native-BZPDHswo.mjs +27 -0
- package/dist/ClearFormattingPlugin.native-BZPDHswo.mjs.map +1 -0
- package/dist/CodePlugin.native-DD9xFIid.mjs +1679 -0
- package/dist/CodePlugin.native-DD9xFIid.mjs.map +1 -0
- package/dist/CodeSamplePlugin.native-DMbEdO9j.mjs +326 -0
- package/dist/CodeSamplePlugin.native-DMbEdO9j.mjs.map +1 -0
- package/dist/CommentsPlugin.native-2zQV8Ia4.mjs +473 -0
- package/dist/CommentsPlugin.native-2zQV8Ia4.mjs.map +1 -0
- package/dist/DirectionPlugin.native-Be7wCzkI.mjs +59 -0
- package/dist/DirectionPlugin.native-Be7wCzkI.mjs.map +1 -0
- package/dist/DocumentManagerPlugin.native-BvZL5CSG.mjs +116 -0
- package/dist/DocumentManagerPlugin.native-BvZL5CSG.mjs.map +1 -0
- package/dist/EmbedIframePlugin.native-ifr9KLdN.mjs +461 -0
- package/dist/EmbedIframePlugin.native-ifr9KLdN.mjs.map +1 -0
- package/dist/EmojisPlugin.native-D6mJSnSR.mjs +1033 -0
- package/dist/EmojisPlugin.native-D6mJSnSR.mjs.map +1 -0
- package/dist/FontFamilyPlugin.native-BzS_9qbM.mjs +106 -0
- package/dist/FontFamilyPlugin.native-BzS_9qbM.mjs.map +1 -0
- package/dist/FontSizePlugin.native-DkLMLPue.mjs +186 -0
- package/dist/FontSizePlugin.native-DkLMLPue.mjs.map +1 -0
- package/dist/FootnotePlugin.native-BciVc9W6.mjs +128 -0
- package/dist/FootnotePlugin.native-BciVc9W6.mjs.map +1 -0
- package/dist/FullscreenPlugin.native-ChXyxeNw.mjs +77 -0
- package/dist/FullscreenPlugin.native-ChXyxeNw.mjs.map +1 -0
- package/dist/HeadingPlugin.native-DrLYwQnQ.mjs +64 -0
- package/dist/HeadingPlugin.native-DrLYwQnQ.mjs.map +1 -0
- package/dist/HistoryPlugin.native-DoDRifCf.mjs +89 -0
- package/dist/HistoryPlugin.native-DoDRifCf.mjs.map +1 -0
- package/dist/IndentPlugin.native-CbFugPoi.mjs +133 -0
- package/dist/IndentPlugin.native-CbFugPoi.mjs.map +1 -0
- package/dist/ItalicPlugin.native-CQjjDyUL.mjs +43 -0
- package/dist/ItalicPlugin.native-CQjjDyUL.mjs.map +1 -0
- package/dist/LineHeightPlugin.native-CWQT2FIa.mjs +73 -0
- package/dist/LineHeightPlugin.native-CWQT2FIa.mjs.map +1 -0
- package/dist/LinkPlugin.native-BdAOV-iu.mjs +206 -0
- package/dist/LinkPlugin.native-BdAOV-iu.mjs.map +1 -0
- package/dist/ListPlugin.native-CLFU5AUQ.mjs +59 -0
- package/dist/ListPlugin.native-CLFU5AUQ.mjs.map +1 -0
- package/dist/MathPlugin.native-DE_ii-LA.mjs +182 -0
- package/dist/MathPlugin.native-DE_ii-LA.mjs.map +1 -0
- package/dist/MediaManagerPlugin.native-DaYFDzNM.mjs +533 -0
- package/dist/MediaManagerPlugin.native-DaYFDzNM.mjs.map +1 -0
- package/dist/MergeTagPlugin.native-CrxyThyn.mjs +178 -0
- package/dist/MergeTagPlugin.native-CrxyThyn.mjs.map +1 -0
- package/dist/PageBreakPlugin.native-DDjcDyRW.mjs +172 -0
- package/dist/PageBreakPlugin.native-DDjcDyRW.mjs.map +1 -0
- package/dist/PreviewPlugin.native-DBvfpmIv.mjs +322 -0
- package/dist/PreviewPlugin.native-DBvfpmIv.mjs.map +1 -0
- package/dist/PrintPlugin.native-BUpm52VJ.mjs +311 -0
- package/dist/PrintPlugin.native-BUpm52VJ.mjs.map +1 -0
- package/dist/SpecialCharactersPlugin.native-x7a2SWXc.mjs +731 -0
- package/dist/SpecialCharactersPlugin.native-x7a2SWXc.mjs.map +1 -0
- package/dist/SpellCheckPlugin.native-B7yTh0iE.mjs +465 -0
- package/dist/SpellCheckPlugin.native-B7yTh0iE.mjs.map +1 -0
- package/dist/StrikethroughPlugin.native-ChaZLaXw.mjs +43 -0
- package/dist/StrikethroughPlugin.native-ChaZLaXw.mjs.map +1 -0
- package/dist/TablePlugin.native-EEWXn1-s.mjs +491 -0
- package/dist/TablePlugin.native-EEWXn1-s.mjs.map +1 -0
- package/dist/TemplatePlugin.native-BlSn1c9h.mjs +564 -0
- package/dist/TemplatePlugin.native-BlSn1c9h.mjs.map +1 -0
- package/dist/TextAlignmentPlugin.native-CQIs1m7R.mjs +97 -0
- package/dist/TextAlignmentPlugin.native-CQIs1m7R.mjs.map +1 -0
- package/dist/TextColorPlugin.native-D6SmTglm.mjs +432 -0
- package/dist/TextColorPlugin.native-D6SmTglm.mjs.map +1 -0
- package/dist/UnderlinePlugin.native-QpIcK4L2.mjs +35 -0
- package/dist/UnderlinePlugin.native-QpIcK4L2.mjs.map +1 -0
- package/dist/documentManager-irzj9n3V.mjs +37627 -0
- package/dist/documentManager-irzj9n3V.mjs.map +1 -0
- package/dist/editorContainerHelpers-C7kdWnS0.mjs +27 -0
- package/dist/editorContainerHelpers-C7kdWnS0.mjs.map +1 -0
- package/dist/editora.min.js +14 -12
- package/dist/editora.min.js.map +1 -1
- package/dist/editora.umd.js +14 -12
- package/dist/editora.umd.js.map +1 -1
- package/dist/index-BF5RBhL9.js +4 -0
- package/dist/index-BF5RBhL9.js.map +1 -0
- package/dist/{index-BS4zT-KN.mjs → index-BPsf460l.mjs} +286 -162
- package/dist/index-BPsf460l.mjs.map +1 -0
- package/dist/index.cjs.js +3 -3
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es-CuicffkQ.mjs +6665 -0
- package/dist/index.es-CuicffkQ.mjs.map +1 -0
- package/dist/index.esm.js +117 -112
- package/dist/index.esm.js.map +1 -1
- package/dist/plugin-loader.js +55 -0
- package/dist/plugin-loader.js.map +1 -0
- package/dist/purify.es-CKpwg8Tk.mjs +471 -0
- package/dist/purify.es-CKpwg8Tk.mjs.map +1 -0
- package/dist/webcomponent-core.js +1243 -0
- package/dist/webcomponent-core.js.map +1 -0
- package/dist/webcomponent-core.min.css +1 -0
- package/dist/webcomponent-core.min.js +597 -0
- package/dist/webcomponent-core.min.js.map +1 -0
- package/dist/webcomponent.cjs.js +1 -1
- package/dist/webcomponent.esm.js +3 -3
- package/dist/webcomponent.js +1286 -0
- package/dist/webcomponent.js.map +1 -0
- package/dist/webcomponent.min.css +1 -0
- package/dist/webcomponent.min.js +337 -334
- package/dist/webcomponent.min.js.map +1 -1
- package/package.json +16 -4
- package/dist/index-BK2lHfHK.js +0 -2
- package/dist/index-BK2lHfHK.js.map +0 -1
- package/dist/index-BS4zT-KN.mjs.map +0 -1
- package/dist/webcomponent.umd.js +0 -4073
- package/dist/webcomponent.umd.js.map +0 -1
|
@@ -0,0 +1,597 @@
|
|
|
1
|
+
(function(y,C){typeof exports=="object"&&typeof module!="undefined"?C(exports):typeof define=="function"&&define.amd?define(["exports"],C):(y=typeof globalThis!="undefined"?globalThis:y||self,C(y.EditoraCore={}))})(this,(function(y){"use strict";class C{constructor(){this.loadedPlugins=new Map,this.pluginRegistry=new Map}register(e,t){this.pluginRegistry.set(e,t)}async load(e,t){if(this.loadedPlugins.has(e))return this.loadedPlugins.get(e);const o=this.pluginRegistry.get(e);if(!o)return console.warn(`Plugin not found: ${e}`),null;const n=await o();return t&&this.applyPluginConfig(n,t),this.loadedPlugins.set(e,n),n}async loadMultiple(e,t){return(await Promise.all(e.map(n=>this.load(n,t)))).filter(n=>n!==null)}async parsePluginString(e,t){const o=e.split(/\s+/).filter(Boolean);return this.loadMultiple(o,t)}applyPluginConfig(e,t){e.__pluginConfig=t}unload(e){this.loadedPlugins.delete(e)}clear(){this.loadedPlugins.clear()}getLoadedPlugins(){return Array.from(this.loadedPlugins.values())}getRegisteredPluginNames(){return Array.from(this.pluginRegistry.keys())}isLoaded(e){return this.loadedPlugins.has(e)}}class T{constructor(e,t,o){this.doc=e,this.selection=t,this.schema=o}static create(e,t){const o=t||e.node("doc",{},[e.node("paragraph")]);return new T(o,{anchor:0,head:0},e)}apply(e,t){return new T(e,t||this.selection,this.schema)}}class oe{constructor(e,t){this.nodes=new Map(Object.entries(e)),this.marks=new Map(Object.entries(t))}node(e,t,o){return{type:e,attrs:t,content:o}}text(e,t){return{type:"text",text:e,marks:t}}}class ne{constructor(){this.plugins=[],this.pluginConfigs=new Map}register(e,t){if(this.plugins.push(e),t&&this.pluginConfigs.set(e.name,t),e.initialize){const o=this.pluginConfigs.get(e.name)||e.config;e.initialize(o)}}unregister(e){const t=this.plugins.findIndex(o=>o.name===e);if(t>-1){const o=this.plugins[t];o.destroy&&o.destroy(),this.plugins.splice(t,1),this.pluginConfigs.delete(e)}}getPlugin(e){return this.plugins.find(t=>t.name===e)}getPluginConfig(e){return this.pluginConfigs.get(e)}buildSchema(){const e={},t={};return this.plugins.forEach(o=>{o.nodes&&Object.assign(e,o.nodes),o.marks&&Object.assign(t,o.marks)}),new oe(e,t)}getCommands(){const e={};return this.plugins.forEach(t=>{t.commands&&Object.assign(e,t.commands)}),e}getToolbarItems(){return this.plugins.flatMap(e=>e.toolbar||[])}async executePluginCommand(e,t,...o){const n=this.getPlugin(e);if(!n)throw new Error(`Plugin not found: ${e}`);const i=this.getPluginConfig(e)||n.config||{},r=i.mode||"local";try{switch(r){case"local":return n.executeLocal?n.executeLocal(t,...o):null;case"api":if(!n.executeAPI)throw new Error(`Plugin ${e} does not support API mode`);return await n.executeAPI(t,...o);case"hybrid":if(n.executeHybrid)return await n.executeHybrid(t,...o);try{if(n.executeAPI)return await n.executeAPI(t,...o)}catch(a){if(console.warn(`API execution failed for ${e}, falling back to local`,a),n.executeLocal&&i.fallbackToLocal!==!1)return n.executeLocal(t,...o);throw a}break;default:throw new Error(`Unknown plugin mode: ${r}`)}}catch(a){throw console.error(`Error executing command ${t} on plugin ${e}:`,a),a}}async destroyAll(){const e=this.plugins.filter(t=>t.destroy).map(t=>t.destroy());await Promise.all(e),this.plugins=[],this.pluginConfigs.clear()}}class ie{constructor(e={}){this.commands=new Map,Object.entries(e).forEach(([t,o])=>{this.register(t,o)})}register(e,t){this.commands.has(e)&&console.warn(`Command ${e} is being overwritten`),this.commands.set(e,t)}unregister(e){this.commands.delete(e)}get(e){return this.commands.get(e)}has(e){return this.commands.has(e)}getCommandNames(){return Array.from(this.commands.keys())}clear(){this.commands.clear()}}class re{constructor(e={}){this.listeners=new Map,this.isReadonly=!1,this.isDestroyed=!1,this.isReadonly=e.readonly||!1,this.pluginManager=new ne,e.plugins&&Array.isArray(e.plugins)&&e.plugins.forEach(o=>this.pluginManager.register(o));const t=this.pluginManager.buildSchema();this.state=T.create(t),this.commandRegistry=new ie(this.pluginManager.getCommands())}execCommand(e,t){if(this.isReadonly)return console.warn("Cannot execute commands in readonly mode"),!1;if(this.isDestroyed)return console.warn("Cannot execute commands on destroyed editor"),!1;const o=this.commandRegistry.get(e);if(!o)return console.warn(`Command not found: ${e}`),!1;let n;return t!==void 0?n=o(this.state,t):n=o(this.state),n?(this.setState(n),this.emit("change",this.state),!0):!1}setState(e){this.isDestroyed||(this.state=e,this.emit("stateChange",e))}getState(){return this.state}setReadonly(e){this.isReadonly=e,this.emit("readonlyChange",e)}isReadOnly(){return this.isReadonly}on(e,t){return this.listeners.has(e)||this.listeners.set(e,[]),this.listeners.get(e).push(t),()=>{const o=this.listeners.get(e);if(o){const n=o.indexOf(t);n>-1&&o.splice(n,1)}}}emit(e,...t){const o=this.listeners.get(e);o&&o.forEach(n=>{try{n(...t)}catch(i){console.error(`Error in ${e} handler:`,i)}})}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.listeners.clear(),this.emit("destroy"))}isEditorDestroyed(){return this.isDestroyed}}class se{constructor(e,t,o){this.config=e,this.plugins=t,this.pluginLoader=o}setCommandHandler(e){this.commandHandler=e}parseToolbarString(e){const t=[],o=e.split("|").map(a=>a.trim()),n=this.getAvailableToolbarItems(),i=new Map;n.forEach(a=>{a.command&&i.set(a.command,a),a.type==="group"&&a.label&&i.set(a.label,a)});const r={bold:"toggleBold",italic:"toggleItalic",underline:"toggleUnderline",strikethrough:"toggleStrikethrough",bullist:"toggleBulletList",numlist:"toggleOrderedList",checklist:"toggleChecklist",link:"openLinkDialog",image:"openImageDialog",table:"insertTable",anchor:"insertAnchor",code:"toggleSourceView",blockquote:"toggleBlockquote",undo:"undo",redo:"redo",textColor:"openTextColorPicker",backgroundColor:"openBackgroundColorPicker",fontSize:"fontSize",fontFamily:"setFontFamily",lineHeight:"setLineHeight",heading:"setBlockType",paragraph:"setParagraph",textAlignment:"setTextAlignment",direction:"setDirectionLTR",indent:"increaseIndent",outdent:"decreaseIndent",capitalization:"setCapitalization",math:"insertMath",specialCharacters:"insertSpecialCharacter",emojis:"openEmojiDialog",embedIframe:"openEmbedIframeDialog",fullscreen:"toggleFullscreen",preview:"togglePreview",print:"print",a11yChecker:"toggleA11yChecker",spellCheck:"toggleSpellCheck",comments:"addComment",showHideComments:"toggleComments",toggleComments:"toggleComments",footnote:"insertFootnote",mergeTags:"insertMergeTag",pageBreak:"insertPageBreak",template:"insertTemplate",importWord:"importWord",exportWord:"exportWord",exportPdf:"exportPdf",insertImage:"insertImage",insertVideo:"insertVideo",codeBlock:"insertCodeBlock"};return o.forEach(a=>{const l=[];a.split(/\s+/).filter(Boolean).forEach(d=>{if(d==="direction"){const g=i.get("setDirectionLTR"),m=i.get("setDirectionRTL");g&&l.push({id:"directionLTR",label:g.label,command:g.command,icon:g.icon,type:g.type||"button",options:g.options}),m&&l.push({id:"directionRTL",label:m.label,command:m.command,icon:m.icon,type:m.type||"button",options:m.options});return}if(d==="comments"){const g=i.get("addComment"),m=i.get("toggleComments");g&&l.push({id:"addComment",label:g.label,command:g.command,icon:g.icon,type:g.type||"button",options:g.options}),m&&l.push({id:"toggleComments",label:m.label,command:m.command,icon:m.icon,type:m.type||"button",options:m.options});return}const c=r[d]||d;let u=i.get(c);u||(u=i.get(d)),u&&l.push({id:d,label:u.label,command:u.command,icon:u.icon,type:u.type==="separator"?"separator":u.type||"button",options:u.options,items:u.items})}),l.length>0&&t.push(l)}),t}getAvailableToolbarItems(){return this.plugins.flatMap(t=>t.toolbar||[])}render(e){this.container=e,e.innerHTML="",e.className="editora-toolbar",this.config.sticky&&e.classList.add("editora-toolbar-sticky"),this.config.position&&e.classList.add(`editora-toolbar-${this.config.position}`);const t=this.config.items||this.getDefaultToolbarString(),o=this.parseToolbarString(t);o.forEach((n,i)=>{const r=document.createElement("div");if(r.className="editora-toolbar-group",n.forEach(a=>{this.appendToolbarButton(r,a)}),e.appendChild(r),i<o.length-1){const a=document.createElement("div");a.className="editora-toolbar-separator",e.appendChild(a)}})}appendToolbarButton(e,t){if(t.type==="separator"){const o=document.createElement("div");o.className="editora-toolbar-separator",e.appendChild(o)}else if(t.type==="dropdown"){const o=this.createDropdown(t);e.appendChild(o)}else if(t.type==="inline-menu"){const o=this.createInlineMenu(t);e.appendChild(o)}else if(t.type==="group"&&t.items&&t.items.length){const o=this.createGroupButton(t);e.appendChild(o)}else if(t.type==="input"){const o=this.createInput(t);e.appendChild(o)}else{const o=this.createButton(t);e.appendChild(o)}}createGroupButton(e){const t=document.createElement("div");if(t.className="editora-toolbar-group-button",t.title=e.label,e.icon)if(e.icon.startsWith("<svg")&&e.icon.endsWith("</svg>")){const o=document.createElement("span");o.className="editora-toolbar-icon",o.innerHTML=e.icon,t.appendChild(o)}else t.innerHTML=e.icon;if(e.items&&e.items.length){const o=document.createElement("div");o.className="editora-toolbar-group-items",e.items.forEach(n=>{this.appendToolbarButton(o,n)}),t.appendChild(o)}return t}createInput(e){const t=document.createElement("input");return t.className=`editora-toolbar-input ${e.label.toLowerCase().replace(/\s+/g,"-")}`,t.type="text",t.title=e.label,t.placeholder=e.placeholder||"",t.setAttribute("data-command",e.command),e.active&&t.classList.add("active"),e.disabled&&(t.disabled=!0),t.addEventListener("click",o=>{o.preventDefault(),this.commandHandler&&this.commandHandler(e.command)}),t}createButton(e){const t=document.createElement("button");if(t.className="editora-toolbar-button",t.type="button",t.title=e.label,t.setAttribute("data-command",e.command),e.icon)if(e.icon.startsWith("<svg")&&e.icon.endsWith("</svg>")){const o=document.createElement("span");o.className="editora-toolbar-icon",o.innerHTML=e.icon,t.appendChild(o)}else t.innerHTML=e.icon;else t.textContent=e.label;return e.active&&t.classList.add("active"),e.disabled&&(t.disabled=!0),t.addEventListener("click",o=>{o.preventDefault(),this.commandHandler&&this.commandHandler(e.command)}),t}createDropdown(e){const t=document.createElement("div");t.className="editora-toolbar-dropdown";const o=document.createElement("button");o.className="editora-toolbar-button editora-toolbar-dropdown-trigger",o.type="button",o.textContent=e.label;const n=document.createElement("div");n.className="editora-toolbar-dropdown-menu",n.style.display="none",e.options&&e.options.forEach(r=>{const a=document.createElement("button");a.className="editora-toolbar-dropdown-item",a.type="button",a.textContent=r.label,a.setAttribute("data-value",r.value),a.addEventListener("click",l=>{l.preventDefault(),this.commandHandler&&this.commandHandler(e.command,r.value),n.style.display="none"}),n.appendChild(a)}),o.addEventListener("click",r=>{r.preventDefault(),r.stopPropagation();const a=n.style.display==="block";n.style.display=a?"none":"block"});const i=r=>{t.contains(r.target)||(n.style.display="none")};return document.addEventListener("click",i),t._cleanupDropdown=()=>{document.removeEventListener("click",i)},t.appendChild(o),t.appendChild(n),t}createInlineMenu(e){const t=document.createElement("div");t.className="editora-toolbar-dropdown editora-toolbar-inline-menu";const o=document.createElement("button");if(o.className="editora-toolbar-button",o.type="button",o.title=e.label,e.icon)if(e.icon.startsWith("<svg")&&e.icon.endsWith("</svg>")){const i=document.createElement("span");i.className="editora-toolbar-icon",i.innerHTML=e.icon,o.appendChild(i)}else o.innerHTML=e.icon;else o.textContent=e.label;const n=document.createElement("div");return n.className="editora-toolbar-dropdown-menu",n.style.display="none",e.options&&e.options.forEach(i=>{const r=document.createElement("button");r.className="editora-toolbar-dropdown-item",r.type="button",r.textContent=i.label,r.setAttribute("data-value",i.value),r.addEventListener("click",a=>{a.preventDefault(),a.stopPropagation(),this.commandHandler&&this.commandHandler(e.command,i.value),n.style.display="none"}),n.appendChild(r)}),o.addEventListener("click",i=>{var a;i.preventDefault(),i.stopPropagation();const r=(a=this.container)==null?void 0:a.querySelectorAll(".editora-toolbar-dropdown-menu");r==null||r.forEach(l=>{l!==n&&(l.style.display="none")}),n.style.display=n.style.display==="none"?"block":"none"}),document.addEventListener("click",i=>{t.contains(i.target)||(n.style.display="none")}),t.appendChild(o),t.appendChild(n),t}getDefaultToolbarString(){return this.getAvailableToolbarItems().map(t=>t.command).join(" ")}updateButtonState(e,t){if(!this.container)return;const o=this.container.querySelector(`[data-command="${e}"]`);o&&(t.active!==void 0&&o.classList.toggle("active",t.active),t.disabled!==void 0&&(o.disabled=t.disabled))}destroy(){this.container&&(this.container.querySelectorAll(".editora-toolbar-dropdown").forEach(t=>{const o=t._cleanupDropdown;o&&o()}),this.container.innerHTML=""),this.commandHandler=void 0}}class ae{constructor(e){this.visible=!1,this.config=e}create(e){const t=document.createElement("div");return t.className="editora-floating-toolbar",t.style.display="none",t.style.position="absolute",t.style.zIndex="1000",this.container=t,e.appendChild(t),t}show(e,t){this.container&&(this.container.style.display="block",this.container.style.left=`${e}px`,this.container.style.top=`${t}px`,this.visible=!0)}hide(){this.container&&(this.container.style.display="none",this.visible=!1)}updatePosition(e,t){!this.container||!this.visible||(this.container.style.left=`${e}px`,this.container.style.top=`${t}px`)}isVisible(){return this.visible}destroy(){this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container),this.container=void 0,this.visible=!1}}class le{constructor(e={}){this.statusInfo={},this.config=e}create(e){const t=document.createElement("div");return t.className="editora-statusbar",this.config.position&&t.classList.add(`editora-statusbar-${this.config.position}`),this.container=t,e.appendChild(t),t}update(e){this.statusInfo={...this.statusInfo,...e},this.render()}render(){if(!this.container)return;this.container.innerHTML="";const e=document.createElement("div");e.className="editora-statusbar-left";const t=document.createElement("div");t.className="editora-statusbar-right";const o=[];if(this.statusInfo.selectionInfo){const i=this.statusInfo.selectionInfo;i.startLine===i.endLine&&i.startColumn===i.endColumn?o.push(`Ln ${i.startLine}, Col ${i.startColumn}`):(i.startLine===i.endLine?o.push(`Ln ${i.startLine}, Col ${i.startColumn}-${i.endColumn}`):o.push(`Ln ${i.startLine}:${i.startColumn} - ${i.endLine}:${i.endColumn}`),o.push(`${i.selectedChars} chars selected`))}else if(this.statusInfo.cursorPosition){const i=this.statusInfo.cursorPosition;o.push(`Ln ${i.line}, Col ${i.column}`)}this.statusInfo.language&&o.push(this.statusInfo.language);const n=[];this.statusInfo.wordCount!==void 0&&n.push(`${this.statusInfo.wordCount} words`),this.statusInfo.charCount!==void 0&&n.push(`${this.statusInfo.charCount} chars`),this.statusInfo.lineCount!==void 0&&n.push(`${this.statusInfo.lineCount} lines`),this.statusInfo.custom&&Object.entries(this.statusInfo.custom).forEach(([i,r])=>{n.push(`${i}: ${r}`)}),o.forEach((i,r)=>{const a=document.createElement("span");if(a.className="editora-statusbar-item",a.textContent=i,e.appendChild(a),r<o.length-1){const l=document.createElement("span");l.className="editora-statusbar-separator",l.textContent="|",e.appendChild(l)}}),n.forEach((i,r)=>{const a=document.createElement("span");if(a.className="editora-statusbar-item",a.textContent=i,t.appendChild(a),r<n.length-1){const l=document.createElement("span");l.className="editora-statusbar-separator",l.textContent="|",t.appendChild(l)}}),this.container.appendChild(e),this.container.appendChild(t)}destroy(){this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container),this.container=void 0}}function de(s,e){const t=s.textContent||"",o=ce(s,e.startContainer,e.startOffset),i=t.substring(0,o).split(`
|
|
2
|
+
`),r=i.length,a=i[i.length-1].length+1;return{line:r,column:a}}function ce(s,e,t){var r;let o=0;const n=document.createTreeWalker(s,NodeFilter.SHOW_TEXT,null);let i=n.firstChild();for(;i;){if(i===e){o+=t;break}else i.nodeType===Node.TEXT_NODE&&(o+=((r=i.textContent)==null?void 0:r.length)||0);i=n.nextNode()}return o}function he(s){var o,n;const e=s.querySelectorAll("div, p, br, h1, h2, h3, h4, h5, h6, blockquote, li, pre");let t=1;if(e.length>0){t=e.length;const i=e[e.length-1];(i.tagName==="BR"||((o=i.innerHTML)==null?void 0:o.trim())===""||((n=i.textContent)==null?void 0:n.trim())==="")&&t++}else{const r=(s.textContent||"").split(`
|
|
3
|
+
`).length;t=Math.max(1,r)}return t}function ue(s){const e=s.trim()?s.trim().split(/\s+/).length:0,t=s.length;return{words:e,chars:t}}function ge(s,e){const t=s.toString();return{startLine:e.line,startColumn:e.column,endLine:e.line,endColumn:e.column+t.length,selectedChars:t.length,selectedWords:t.trim().split(/\s+/).filter(Boolean).length}}const j=class j{static resolve(e){const t={};if(Object.assign(t,this.EDITOR_DEFAULTS),e.pluginDefaults&&Object.assign(t,e.pluginDefaults),e.attributes){const o=this.parseAttributes(e.attributes);Object.assign(t,o)}return e.jsConfig&&Object.assign(t,e.jsConfig),t}static parseAttributes(e){const t={};for(const[o,n]of Object.entries(e)){const i=this.kebabToCamel(o);t[i]=this.parseAttributeValue(n)}return t}static parseAttributeValue(e){if(e==="true")return!0;if(e==="false")return!1;if(/^\d+$/.test(e))return parseInt(e,10);if(/^\d+\.\d+$/.test(e))return parseFloat(e);if(e.startsWith("{")||e.startsWith("["))try{return JSON.parse(e)}catch(t){return e}return e}static kebabToCamel(e){return e.replace(/-([a-z])/g,(t,o)=>o.toUpperCase())}static validate(e){const t=[];return e.height!==void 0&&typeof e.height=="number"&&e.height<0&&t.push("height must be a positive number"),e.width!==void 0&&typeof e.width=="number"&&e.width<0&&t.push("width must be a positive number"),e.plugins!==void 0&&!Array.isArray(e.plugins)&&typeof e.plugins!="string"&&t.push("plugins must be an array or string"),e.theme!==void 0&&typeof e.theme!="string"&&t.push("theme must be a string"),{valid:t.length===0,errors:t}}static getDefaults(){return{...this.EDITOR_DEFAULTS}}static merge(...e){const t={};for(const o of e)for(const[n,i]of Object.entries(o))i!=null&&(typeof i=="object"&&!Array.isArray(i)&&t[n]?t[n]=this.merge(t[n],i):t[n]=i);return t}};j.EDITOR_DEFAULTS={height:400,width:"100%",readonly:!1,disabled:!1,menubar:!0,toolbar:!0,plugins:[],theme:"light",content:"",placeholder:"Start typing...",autofocus:!1,autosave:!1,spellcheck:!1,language:"en"};let P=j;const pe='.editora-editor{display:flex;flex-direction:column;border:1px solid #ddd;border-radius:4px;background:#fff;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,sans-serif;font-size:14px;overflow:hidden}.editora-editor *{box-sizing:border-box}.editora-theme-light{background:#fff;color:#333}.editora-theme-dark{background:#1e1e1e;color:#d4d4d4;border-color:#3c3c3c}.editora-toolbar{display:flex;align-items:center;gap:4px;padding:8px;background:#f5f5f5;border-bottom:1px solid #ddd;flex-wrap:wrap}.editora-theme-dark .editora-toolbar{background:#252526;border-bottom-color:#3c3c3c}.editora-toolbar-sticky{position:sticky;top:0;z-index:100;position:-webkit-sticky}.editora-toolbar-group{display:flex;align-items:center;gap:2px}.editora-toolbar-button{padding:6px 12px;border:1px solid #ccc;background:#fff;cursor:pointer;border-radius:3px;font-weight:600;font-size:14px;height:30px;display:flex;align-items:center;white-space:nowrap}.editora-toolbar-input.font-size{width:40px;padding:.25rem;text-align:center;font-size:14px;background:#fff;border:1px solid var(--rte-color-border-light);border-radius:var(--rte-radius-sm)}.editora-toolbar-group-items{display:flex;align-items:center;border:1px solid #ccc;.editora-toolbar-button{border:none;border-radius:0;&:first-child{border-right:1px solid #ccc;border-top-left-radius:3px;border-bottom-left-radius:3px}&:last-child{border-left:1px solid #ccc;border-top-right-radius:3px;border-bottom-right-radius:3px}}}.editora-theme-dark .editora-toolbar-button{color:#d4d4d4}.editora-toolbar-button:hover{background:#e0e0e0;border-color:#ccc}.editora-theme-dark .editora-toolbar-button:hover{background:#37373d;border-color:#555}.editora-toolbar-button:active,.editora-toolbar-button.active{background:#d0d0d0;border-color:#999}.editora-theme-dark .editora-toolbar-button:active,.editora-theme-dark .editora-toolbar-button.active{background:#2a2d2e;border-color:#666}.editora-toolbar-button:disabled{opacity:.5;cursor:not-allowed}.editora-toolbar-icon{display:inline-flex;align-items:center;justify-content:center;width:24px;height:24px;line-height:1}.editora-toolbar-button svg,.editora-toolbar-icon svg{width:24px;height:24px;display:block}.editora-toolbar-separator{width:1px;height:24px;background:#ddd;margin:0 4px}.editora-theme-dark .editora-toolbar-separator{background:#3c3c3c}.editora-toolbar-dropdown{position:relative}.editora-toolbar-dropdown-menu{position:absolute;top:100%;left:0;min-width:150px;margin-top:4px;padding:4px 0;background:#fff;border:1px solid #ddd;border-radius:4px;box-shadow:0 2px 8px #00000026;z-index:1000}.editora-theme-dark .editora-toolbar-dropdown-menu{background:#252526;border-color:#3c3c3c;box-shadow:0 2px 8px #00000080}.editora-toolbar-dropdown-item{display:block;width:100%;padding:8px 12px;border:none;background:transparent;color:#333;text-align:left;cursor:pointer;font-size:13px;transition:background .15s ease}.editora-theme-dark .editora-toolbar-dropdown-item{color:#d4d4d4}.editora-toolbar-dropdown-item:hover{background:#f5f5f5}.editora-theme-dark .editora-toolbar-dropdown-item:hover{background:#37373d}.editora-content{flex:1;min-height:200px;padding:16px;outline:none;overflow-y:auto;line-height:1.6}.editora-content:empty:before{content:attr(data-placeholder);color:#999;pointer-events:none}.editora-theme-dark .editora-content:empty:before{color:#6a6a6a}.editora-content h1{font-size:2em;margin:.67em 0;font-weight:600}.editora-content h2{font-size:1.5em;margin:.75em 0;font-weight:600}.editora-content h3{font-size:1.17em;margin:.83em 0;font-weight:600}.editora-content p{margin:1em 0}.editora-content ul,.editora-content ol{margin:1em 0;padding-left:2em}.editora-content a{color:#06c;text-decoration:underline}.editora-theme-dark .editora-content a{color:#4db8ff}.editora-content code{padding:2px 4px;background:#f5f5f5;border-radius:3px;font-family:Monaco,Menlo,Consolas,monospace;font-size:.9em}.editora-theme-dark .editora-content code{background:#1e1e1e}.editora-content pre{padding:12px;background:#f5f5f5;border-radius:4px;overflow-x:auto;margin:1em 0}.editora-theme-dark .editora-content pre{background:#1e1e1e}.editora-content blockquote{margin:1em 0;padding-left:1em;border-left:4px solid #ddd;color:#666}.editora-theme-dark .editora-content blockquote{border-left-color:#3c3c3c;color:#9a9a9a}.editora-floating-toolbar{position:absolute;padding:4px;background:#fff;border:1px solid #ddd;border-radius:4px;box-shadow:0 2px 8px #00000026;z-index:1000}.editora-theme-dark .editora-floating-toolbar{background:#252526;border-color:#3c3c3c;box-shadow:0 2px 8px #00000080}.editora-statusbar-container{display:flex;flex-direction:column}.editora-statusbar-left{display:flex;align-items:center;gap:8px}.editora-statusbar-right{display:flex;align-items:center;gap:8px;margin-left:auto}.editora-statusbar{display:flex;align-items:center;gap:12px;padding:6px 12px;background:#f5f5f5;border-top:1px solid #ddd;font-size:12px;color:#666}.editora-theme-dark .editora-statusbar{background:#252526;border-top-color:#3c3c3c;color:#9a9a9a}.editora-statusbar-item{white-space:nowrap}.editora-statusbar-separator{color:#ddd}.editora-theme-dark .editora-statusbar-separator{color:#3c3c3c}.editora-editor[readonly] .editora-content{background:#fafafa;cursor:not-allowed}.editora-theme-dark.editora-editor[readonly] .editora-content{background:#1a1a1a}.editora-editor:focus-within{border-color:#06c;box-shadow:0 0 0 3px #0066cc1a}.editora-theme-dark.editora-editor:focus-within{border-color:#4db8ff;box-shadow:0 0 0 3px #4db8ff1a}.editora-editor[disabled]{opacity:.6;pointer-events:none}@media(max-width:768px){.editora-toolbar{padding:4px}.editora-toolbar-button{min-width:28px;min-height:28px;padding:4px 8px;font-size:12px}.editora-content{padding:12px}}.editora-content ::selection{background:#06c3}.editora-theme-dark .editora-content ::selection{background:#4db8ff33}.editora-content table{border-collapse:collapse;width:100%;margin:1em 0}.editora-content th,.editora-content td{border:1px solid #ddd;padding:8px 12px;text-align:left}.editora-theme-dark .editora-content th,.editora-theme-dark .editora-content td{border-color:#3c3c3c}.editora-content th{background:#f5f5f5;font-weight:600}.editora-theme-dark .editora-content th{background:#252526}.editora-content img{max-width:100%;height:auto;border-radius:4px;display:block}.editora-content video{max-width:100%;height:auto;border-radius:4px;display:block}.editora-editor.loading{opacity:.7;pointer-events:none}.editora-editor.loading:after{content:"";position:absolute;top:50%;left:50%;width:24px;height:24px;margin:-12px 0 0 -12px;border:3px solid #ddd;border-top-color:#06c;border-radius:50%;animation:editora-spin .8s linear infinite}@keyframes editora-spin{to{transform:rotate(360deg)}}.toolbar-container-wrapper{display:flex;align-items:center;background:#fff;border-bottom:1px solid #e0e0e0;padding:0;margin:0;width:100%;box-sizing:border-box;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,sans-serif;font-size:14px;line-height:1.5;position:relative}.toolbar-container-wrapper[data-toolbar-sticky=true]{position:sticky;top:0;z-index:999;box-shadow:0 2px 4px #0000001a}.toolbar-container-wrapper[data-toolbar-floating=true]{position:fixed;top:0;left:0;right:0;z-index:1000;box-shadow:0 4px 12px #00000026}.toolbar-container-wrapper[data-toolbar-position=bottom]{border-bottom:none;border-top:1px solid #e0e0e0}.toolbar-container-wrapper .toolbar-wrapper{display:flex;width:100%;padding:8px;gap:4px;flex-wrap:wrap;align-items:center}.toolbar-container-wrapper .toolbar{display:flex;width:100%;gap:4px;flex-wrap:wrap;align-items:center}.toolbar-container-wrapper .toolbar-container{display:flex;gap:4px;flex-wrap:wrap;align-items:center;flex:1;position:relative}.toolbar-container-wrapper .toolbar-item{display:flex;align-items:center;gap:2px}.toolbar-container-wrapper .toolbar-button{padding:6px 10px;border:1px solid #d1d5db;background:#fff;border-radius:4px;cursor:pointer;font-size:13px;display:flex;align-items:center;justify-content:center;gap:4px;transition:all .15s ease;min-height:32px;white-space:nowrap}.toolbar-container-wrapper .toolbar-button:hover{background-color:#f3f4f6;border-color:#9ca3af}.toolbar-container-wrapper .toolbar-button:active,.toolbar-container-wrapper .toolbar-button[data-active=true]{background-color:#06c;color:#fff;border-color:#0052a3;box-shadow:inset 0 1px 3px #0000001a}.toolbar-container-wrapper .toolbar-button:disabled{opacity:.5;cursor:not-allowed;background-color:#f9fafb}.toolbar-container-wrapper .toolbar-more-button{padding:6px 8px;font-size:16px;font-weight:500;line-height:1}.toolbar-container-wrapper .toolbar-separator{width:1px;height:24px;background-color:#d1d5db;margin:0 4px}.toolbar-container-wrapper .toolbar-icon{display:inline-flex;align-items:center;justify-content:center;width:18px;height:18px;flex-shrink:0}.toolbar-container-wrapper .toolbar-icon svg{width:100%;height:100%}.toolbar-container-wrapper .toolbar-dropdown{position:relative;display:flex;align-items:center}.toolbar-container-wrapper .toolbar-dropdown-arrow{font-size:10px;margin-left:2px;line-height:1}.toolbar-container-wrapper .toolbar-dropdown-menu{position:absolute;top:100%;left:0;background:#fff;border:1px solid #d1d5db;border-radius:6px;box-shadow:0 4px 12px #00000026;z-index:1000;min-width:160px;padding:4px 0;margin-top:4px;display:none}.toolbar-container-wrapper .toolbar-dropdown-menu.show{display:block}.toolbar-container-wrapper .toolbar-dropdown-item{display:block;width:100%;padding:8px 12px;border:none;background:transparent;text-align:left;cursor:pointer;font-size:13px;color:#1f2937;transition:background-color .15s ease;font-family:inherit}.toolbar-container-wrapper .toolbar-dropdown-item:hover{background-color:#f3f4f6}.toolbar-container-wrapper .toolbar-dropdown-item:active{background-color:#e5e7eb}.toolbar-container-wrapper .toolbar-input{padding:6px 8px;border:1px solid #d1d5db;border-radius:4px;font-size:13px;font-family:inherit;background-color:#fff;color:#1f2937;transition:all .15s ease}.toolbar-container-wrapper .toolbar-input:focus{outline:none;border-color:#06c;box-shadow:0 0 0 3px #0066cc1a;background-color:#fff}.toolbar-container-wrapper .toolbar-input::placeholder{color:#9ca3af}.toolbar-overflow-menu{animation:slideDown .2s ease-out}@keyframes slideDown{0%{opacity:0;transform:translateY(-8px)}to{opacity:1;transform:translateY(0)}}.toolbar-overflow-item{transition:background-color .15s ease}.floating-toolbar{user-select:none;-webkit-user-select:none;font-family:system-ui,-apple-system,sans-serif;font-size:14px;animation:fadeInUp .15s ease-out}@keyframes fadeInUp{0%{opacity:0;transform:translate(-50%) translateY(10px)}to{opacity:1;transform:translate(-50%) translateY(0)}}.floating-toolbar-btn{display:flex;align-items:center;justify-content:center;width:32px;height:32px;border:none;background:transparent;border-radius:4px;color:#495057;cursor:pointer;font-size:14px;font-weight:500;transition:all .15s ease;outline:none}.floating-toolbar-btn:hover{background:#f8f9fa;color:#212529}.floating-toolbar-btn:active{background:#e9ecef;transform:scale(.95)}.floating-toolbar-btn.floating-toolbar-toggle{color:#dc3545;font-weight:700}.floating-toolbar-btn.floating-toolbar-toggle:hover{background:#f8d7da;color:#721c24}.floating-toolbar-separator{width:1px;height:20px;background:#e1e5e9;margin:0 2px}@media(max-width:768px){.toolbar-container-wrapper .toolbar-button{padding:5px 8px;font-size:12px;min-height:28px}.toolbar-container-wrapper .toolbar-icon{width:16px;height:16px}.toolbar-container-wrapper .toolbar-dropdown-menu{min-width:140px}.toolbar-container-wrapper .toolbar-dropdown-item{padding:6px 10px;font-size:12px}.floating-toolbar{padding:4px;gap:2px}.floating-toolbar-btn{width:28px;height:28px;font-size:12px}}@media(max-width:480px){.toolbar-container-wrapper{padding:4px}.toolbar-container-wrapper .toolbar-wrapper{padding:4px;gap:2px}.toolbar-container-wrapper .toolbar-button{padding:4px 6px;font-size:11px;min-height:24px}.toolbar-container-wrapper .toolbar-icon{width:14px;height:14px}}.floating-toolbar{pointer-events:auto}.floating-toolbar{max-width:calc(100vw - 20px);overflow-x:auto}@media(prefers-color-scheme:dark){.floating-toolbar{background:#2d3748;border-color:#4a5568;color:#e2e8f0}.floating-toolbar-btn:hover{background:#4a5568;color:#f7fafc}.floating-toolbar-btn:active{background:#718096}.floating-toolbar-separator{background:#4a5568}}';function me(){const s="editora-webcomponent-styles";if(!document.getElementById(s)){const e=document.createElement("style");e.id=s,e.textContent=pe,document.head.appendChild(e)}}class b extends HTMLElement{constructor(){if(super(),this.config={},this.isInitialized=!1,me(),!this.hasAttribute("data-initial-content")){const e=this.innerHTML.trim();e&&this.setAttribute("data-initial-content",e)}}static get observedAttributes(){return["height","width","menubar","plugins","toolbar","toolbar-items","readonly","disabled","theme","placeholder","autofocus","language","spellcheck","statusbar"]}connectedCallback(){this.config=this.resolveConfig(),this.waitForPluginLoader().then(()=>{setTimeout(async()=>{await this.initialize()},0)})}async waitForPluginLoader(){if(b.__globalPluginLoader){this.pluginLoader=b.__globalPluginLoader;return}return new Promise(e=>{const t=()=>{b.__globalPluginLoader?(this.pluginLoader=b.__globalPluginLoader,e()):setTimeout(t,0)};t()})}disconnectedCallback(){this.destroy()}attributeChangedCallback(e,t,o){t!==o&&(this.config=this.resolveConfig(),this.handleAttributeChange(e,o))}async setConfig(e){this.jsConfig=e,this.config=this.resolveConfig(),this.isConnected&&(this.destroy(),await this.waitForPluginLoader(),await this.initialize())}async initialize(){if(this.querySelector(".editora-toolbar")||this.isInitialized)return;this.setAttribute("data-editora-editor","true"),this.config.height&&(this.style.height=typeof this.config.height=="number"?`${this.config.height}px`:this.config.height),this.config.width&&(this.style.width=typeof this.config.width=="number"?`${this.config.width}px`:this.config.width),this.classList.add("editora-editor"),this.config.theme&&this.classList.add(`editora-theme-${this.config.theme}`);const e=await this.loadPlugins();e.forEach(o=>{if(o.init&&typeof o.init=="function")try{o.init({editorElement:this})}catch(n){console.error(`[RichTextEditor] Error initializing plugin ${o.name}:`,n)}});const t=this.getAttribute("data-initial-content")||"";this.engine=new re({content:t,plugins:e,readonly:this.config.readonly}),this.createUI(e,t),this.setupEventListeners(),this.isInitialized=!0,this.dispatchEvent(new CustomEvent("editor-ready",{detail:{api:this.getAPI()},bubbles:!0}))}getInitialContent(){if(this.config.content)return this.config.content;const e=this.querySelector("[slot]");return e?e.innerHTML:this.hasChildNodes()?Array.from(this.childNodes).map(o=>o.nodeType===Node.TEXT_NODE?o.textContent:o.nodeType===Node.ELEMENT_NODE?o.outerHTML:"").join("").trim():""}async loadPlugins(){this.pluginLoader||await this.waitForPluginLoader();const e=[];if(this.config.plugins&&(typeof this.config.plugins=="string"&&this.config.plugins.length>0||Array.isArray(this.config.plugins)&&this.config.plugins.length>0)){if(typeof this.config.plugins=="string"){const o=await this.pluginLoader.parsePluginString(this.config.plugins);e.push(...o)}else if(Array.isArray(this.config.plugins))for(const o of this.config.plugins)if(typeof o=="string"){const n=await this.pluginLoader.load(o);n&&e.push(n)}else e.push(o)}else{const o=this.pluginLoader.getRegisteredPluginNames(),n=await this.pluginLoader.loadMultiple(o);e.push(...n)}return e}createUI(e,t){const o=this.querySelector('[slot="toolbar"]'),n=this.querySelector('[slot="statusbar"]');if(this.innerHTML="",this.config.toolbar!==!1&&!o){this.toolbarElement=document.createElement("div"),this.toolbarElement.className="editora-toolbar-container",this.appendChild(this.toolbarElement);const i=this.config.toolbarItems||this.config.toolbar;this.toolbar=new se({items:typeof i=="string"?i:void 0,sticky:this.config.toolbar&&typeof this.config.toolbar=="object"?this.config.toolbar.sticky:!1,position:"top"},e,this.pluginLoader),this.toolbar.setCommandHandler((r,a)=>{var h,d;if(this.contentElement){this.contentElement.focus();const c=window.getSelection();if(!c||c.rangeCount===0||!this.contentElement.contains(c.anchorNode)){const u=document.createRange(),g=this.contentElement.lastChild||this.contentElement;g.nodeType===Node.TEXT_NODE?u.setStart(g,((h=g.textContent)==null?void 0:h.length)||0):g.nodeType===Node.ELEMENT_NODE?(u.selectNodeContents(g),u.collapse(!1)):u.setStart(this.contentElement,0),u.collapse(!0),c==null||c.removeAllRanges(),c==null||c.addRange(u)}}const l=e.find(c=>c.commands&&c.commands[r]);if(l&&l.commands){const c=l.commands[r];if(typeof c=="function")try{return c(r==="toggleFullscreen"?this:a)}catch(u){return console.error(`[RichTextEditor] Error executing native command ${r}:`,u),!1}}return((d=this.engine)==null?void 0:d.execCommand(r,a))||!1}),this.toolbar.render(this.toolbarElement)}else o&&this.appendChild(o);this.contentElement=document.createElement("div"),this.contentElement.className="editora-content rte-content",this.contentElement.contentEditable=this.config.readonly?"false":"true",this.contentElement.setAttribute("role","textbox"),this.contentElement.setAttribute("aria-multiline","true"),this.config.placeholder&&this.contentElement.setAttribute("data-placeholder",this.config.placeholder);try{document.execCommand("defaultParagraphSeparator",!1,"p")}catch(i){console.warn("defaultParagraphSeparator not supported:",i)}if(t){const i=document.createElement("div");i.innerHTML=t.trim(),!Array.from(i.childNodes).some(a=>{if(a.nodeType===Node.ELEMENT_NODE){const l=a.tagName;return["P","DIV","H1","H2","H3","H4","H5","H6","UL","OL","BLOCKQUOTE","PRE"].includes(l)}return!1})&&t.trim()?this.contentElement.innerHTML=`<p>${t.trim()}</p>`:this.contentElement.innerHTML=t}else this.config.placeholder?this.contentElement.innerHTML="":this.contentElement.innerHTML="<p><br></p>";this.appendChild(this.contentElement),this.config.toolbar&&typeof this.config.toolbar=="object"&&this.config.toolbar.floating&&(this.floatingToolbar=new ae({enabled:!0}),this.floatingToolbar.create(this)),n?this.appendChild(n):this.config.statusbar&&(this.statusBarElement=document.createElement("div"),this.statusBarElement.className="editora-statusbar-container",this.appendChild(this.statusBarElement),this.statusBar=new le({position:"bottom"}),this.statusBar.create(this.statusBarElement)),this.config.autofocus&&setTimeout(()=>{var i;return(i=this.contentElement)==null?void 0:i.focus()},0)}setupEventListeners(){if(!this.contentElement||!this.engine)return;this.contentElement.addEventListener("input",()=>{const t=this.contentElement.innerHTML;this.dispatchEvent(new CustomEvent("content-change",{detail:{html:t},bubbles:!0})),this.updateStatusBar()}),this.contentElement.addEventListener("focus",()=>{this.dispatchEvent(new Event("editor-focus",{bubbles:!0}))}),this.contentElement.addEventListener("blur",()=>{this.dispatchEvent(new Event("editor-blur",{bubbles:!0}))});const e=()=>{this.updateFloatingToolbar(),this.updateStatusBar()};document.addEventListener("selectionchange",e)}updateFloatingToolbar(){if(!this.floatingToolbar)return;const e=window.getSelection();if(!e||e.rangeCount===0){this.floatingToolbar.hide();return}const t=e.getRangeAt(0);if(t.collapsed){this.floatingToolbar.hide();return}const o=t.getBoundingClientRect();this.floatingToolbar.show(o.left,o.top-40)}updateStatusBar(){if(!this.statusBar||!this.contentElement)return;const e=this.contentElement.textContent||"",{words:t,chars:o}=ue(e),n=he(this.contentElement),i=window.getSelection();let r,a;if(i&&i.rangeCount>0){const l=i.getRangeAt(0);r=de(this.contentElement,l),l.collapsed||(a=ge(l,r),r=void 0)}this.statusBar.update({wordCount:t,charCount:o,lineCount:n,cursorPosition:r,selectionInfo:a})}handleAttributeChange(e,t){switch(e){case"readonly":this.contentElement&&(this.contentElement.contentEditable=t==="true"?"false":"true"),this.engine&&this.engine.setReadonly(t==="true");break;case"theme":this.classList.forEach(o=>{o.startsWith("editora-theme-")&&this.classList.remove(o)}),t&&this.classList.add(`editora-theme-${t}`);break;case"placeholder":this.contentElement&&this.contentElement.setAttribute("data-placeholder",t);break;case"toolbar":case"plugins":this.isConnected&&(this.destroy(),this.waitForPluginLoader().then(()=>{this.initialize().catch(o=>{console.error("[RichTextEditor] Error during attribute change re-initialization:",o)})}));break}}resolveConfig(){const e={};for(let t=0;t<this.attributes.length;t++){const o=this.attributes[t];e[o.name]=o.value}return P.resolve({jsConfig:this.jsConfig,attributes:e})}getAPI(){return{getContent:()=>{var e;return((e=this.contentElement)==null?void 0:e.innerHTML)||""},setContent:e=>{this.contentElement&&(this.contentElement.innerHTML=e)},execCommand:(e,t)=>{var o;return((o=this.engine)==null?void 0:o.execCommand(e,t))||!1},focus:()=>{var e;(e=this.contentElement)==null||e.focus()},blur:()=>{var e;(e=this.contentElement)==null||e.blur()},destroy:()=>{this.destroy()},on:(e,t)=>(this.addEventListener(e,t),()=>this.removeEventListener(e,t)),getConfig:()=>({...this.config}),setReadonly:e=>{this.setAttribute("readonly",e.toString())}}}destroy(){var e,t,o,n;(e=this.engine)==null||e.destroy(),(t=this.toolbar)==null||t.destroy(),(o=this.floatingToolbar)==null||o.destroy(),(n=this.statusBar)==null||n.destroy(),this.innerHTML="",this.isInitialized=!1,this.dispatchEvent(new Event("editor-destroy",{bubbles:!0}))}getContent(){var e;return((e=this.contentElement)==null?void 0:e.innerHTML)||""}setContent(e){this.contentElement&&(this.contentElement.innerHTML=e)}execCommand(e,t){var o;return((o=this.engine)==null?void 0:o.execCommand(e,t))||!1}focus(){var e;(e=this.contentElement)==null||e.focus()}blur(){var e;(e=this.contentElement)==null||e.blur()}}const I=new C;b.__globalPluginLoader=I;const fe={bold:()=>Promise.resolve().then(()=>be).then(s=>s.BoldPlugin()),italic:()=>Promise.resolve().then(()=>ye).then(s=>s.ItalicPlugin()),underline:()=>Promise.resolve().then(()=>ve).then(s=>s.UnderlinePlugin()),strikethrough:()=>Promise.resolve().then(()=>we).then(s=>s.StrikethroughPlugin()),clearFormatting:()=>Promise.resolve().then(()=>ke).then(s=>s.ClearFormattingPlugin()),heading:()=>Promise.resolve().then(()=>Ce).then(s=>s.HeadingPlugin()),blockquote:()=>Promise.resolve().then(()=>Ee).then(s=>s.BlockquotePlugin()),code:()=>Promise.resolve().then(()=>Re).then(s=>s.CodePlugin()),list:()=>Promise.resolve().then(()=>De).then(s=>s.ListPlugin()),history:()=>Promise.resolve().then(()=>Ue).then(s=>s.HistoryPlugin())};async function q(){return Object.entries(fe).forEach(([s,e])=>{I.register(s,e)}),I}typeof window!="undefined"&&q().then(s=>{b.__globalPluginLoader=s,customElements.get("editora-editor")||customElements.define("editora-editor",b);const e=document.querySelectorAll("editora-editor:not([data-initial-content])"),t=[];e.forEach(o=>{const n=o.innerHTML.trim();n&&(t.push(n),o.setAttribute("data-initial-content",n),o.innerHTML="")}),e.forEach((o,n)=>{o instanceof b&&!o.isInitialized&&t[n]&&o.setAttribute("content",t[n])})});const be=Object.freeze(Object.defineProperty({__proto__:null,BoldPlugin:()=>({name:"bold",marks:{bold:{parseDOM:[{tag:"strong"},{tag:"b"},{style:"font-weight",getAttrs:s=>{const e=typeof s=="string"?s:s.style.fontWeight;return/^(bold(er)?|[5-9]\d{2,})$/.test(e)&&null}}],toDOM:()=>["strong",0]}},toolbar:[{label:"Bold",command:"toggleBold",icon:'<svg width="24" height="24" focusable="false"><path d="M7.8 19c-.3 0-.5 0-.6-.2l-.2-.5V5.7c0-.2 0-.4.2-.5l.6-.2h5c1.5 0 2.7.3 3.5 1 .7.6 1.1 1.4 1.1 2.5a3 3 0 0 1-.6 1.9c-.4.6-1 1-1.6 1.2.4.1.9.3 1.3.6s.8.7 1 1.2c.4.4.5 1 .5 1.6 0 1.3-.4 2.3-1.3 3-.8.7-2.1 1-3.8 1H7.8Zm5-8.3c.6 0 1.2-.1 1.6-.5.4-.3.6-.7.6-1.3 0-1.1-.8-1.7-2.3-1.7H9.3v3.5h3.4Zm.5 6c.7 0 1.3-.1 1.7-.4.4-.4.6-.9.6-1.5s-.2-1-.7-1.4c-.4-.3-1-.4-2-.4H9.4v3.8h4Z" fill-rule="evenodd"></path></svg>',shortcut:"Mod-b"}],commands:{toggleBold:()=>(document.execCommand("bold",!1),!0)},keymap:{"Mod-b":"toggleBold","Mod-B":"toggleBold"}})},Symbol.toStringTag,{value:"Module"})),H=()=>(document.execCommand("italic",!1),!0),xe=(s,e)=>{var t;typeof window!="undefined"&&((t=window.registerEditorCommand)==null||t.call(window,s,e))},K=()=>{xe("toggleItalic",H)};typeof window!="undefined"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",K):K());const ye=Object.freeze(Object.defineProperty({__proto__:null,ItalicPlugin:()=>({name:"italic",marks:{italic:{parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style=italic"}],toDOM:()=>["em",0]}},toolbar:[{label:"Italic",command:"toggleItalic",type:"button",icon:'<svg width="24" height="24" focusable="false"><path d="M16.7 4.7l-.1.9h-.3c-.6 0-1 0-1.4.3-.3.3-.4.6-.5 1.1l-2.1 9.8v.6c0 .5.4.8 1.4.8h.2l-.2.8H8l.2-.8h.2c1.1 0 1.8-.5 2-1.5l2-9.8.1-.5c0-.6-.4-.8-1.4-.8h-.3l.2-.9h5.8Z" fill-rule="evenodd"></path></svg>',shortcut:"Mod-i"}],commands:{toggleItalic:H},keymap:{"Mod-i":"toggleItalic","Mod-I":"toggleItalic"}}),toggleItalic:H},Symbol.toStringTag,{value:"Module"})),ve=Object.freeze(Object.defineProperty({__proto__:null,UnderlinePlugin:()=>({name:"underline",marks:{underline:{parseDOM:[{tag:"u"}],toDOM:()=>["u",{},0]}},toolbar:[{label:"Underline",command:"toggleUnderline",icon:'<svg width="24" height="24" focusable="false"><path d="M16 5c.6 0 1 .4 1 1v7c0 2.8-2.2 5-5 5s-5-2.2-5-5V6c0-.6.4-1 1-1s1 .4 1 1v7c0 1.7 1.3 3 3 3s3-1.3 3-3V6c0-.6.4-1 1-1ZM4 17h16c.6 0 1 .4 1 1s-.4 1-1 1H4a1 1 0 1 1 0-2Z" fill-rule="evenodd"></path></svg>',shortcut:"Mod-u"}],commands:{toggleUnderline:()=>(document.execCommand("underline",!1),!0)},keymap:{"Mod-u":"toggleUnderline","Mod-U":"toggleUnderline"}})},Symbol.toStringTag,{value:"Module"})),we=Object.freeze(Object.defineProperty({__proto__:null,StrikethroughPlugin:()=>({name:"strikethrough",marks:{strikethrough:{parseDOM:[{tag:"s"},{tag:"strike"},{tag:"del"},{style:"text-decoration",getAttrs:s=>(typeof s=="string"?s:s.style.textDecoration)==="line-through"&&null}],toDOM:()=>["s",0]}},toolbar:[{label:"Strikethrough",command:"toggleStrikethrough",icon:'<svg width="24" height="24" focusable="false"><g fill-rule="evenodd"><path d="M15.6 8.5c-.5-.7-1-1.1-1.3-1.3-.6-.4-1.3-.6-2-.6-2.7 0-2.8 1.7-2.8 2.1 0 1.6 1.8 2 3.2 2.3 4.4.9 4.6 2.8 4.6 3.9 0 1.4-.7 4.1-5 4.1A6.2 6.2 0 0 1 7 16.4l1.5-1.1c.4.6 1.6 2 3.7 2 1.6 0 2.5-.4 3-1.2.4-.8.3-2-.8-2.6-.7-.4-1.6-.7-2.9-1-1-.2-3.9-.8-3.9-3.6C7.6 6 10.3 5 12.4 5c2.9 0 4.2 1.6 4.7 2.4l-1.5 1.1Z"></path><path d="M5 11h14a1 1 0 0 1 0 2H5a1 1 0 0 1 0-2Z" fill-rule="nonzero"></path></g></svg>',shortcut:"Mod-Shift-x"}],commands:{toggleStrikethrough:()=>(document.execCommand("strikeThrough",!1),!0)},keymap:{"Mod-Shift-x":"toggleStrikethrough","Mod-Shift-X":"toggleStrikethrough"}})},Symbol.toStringTag,{value:"Module"})),ke=Object.freeze(Object.defineProperty({__proto__:null,ClearFormattingPlugin:()=>({name:"clearFormatting",toolbar:[{label:"Clear Formatting",command:"clearFormatting",icon:'<svg width="24" height="24" focusable="false"><path d="M13.2 6a1 1 0 0 1 0 .2l-2.6 10a1 1 0 0 1-1 .8h-.2a.8.8 0 0 1-.8-1l2.6-10H8a1 1 0 1 1 0-2h9a1 1 0 0 1 0 2h-3.8ZM5 18h7a1 1 0 0 1 0 2H5a1 1 0 0 1 0-2Zm13 1.5L16.5 18 15 19.5a.7.7 0 0 1-1-1l1.5-1.5-1.5-1.5a.7.7 0 0 1 1-1l1.5 1.5 1.5-1.5a.7.7 0 0 1 1 1L17.5 17l1.5 1.5a.7.7 0 0 1-1 1Z" fill-rule="evenodd"></path></svg>',shortcut:"Mod-\\"}],commands:{clearFormatting:()=>(document.execCommand("removeFormat",!1),!0)},keymap:{"Mod-\\":"clearFormatting"}})},Symbol.toStringTag,{value:"Module"})),Ce=Object.freeze(Object.defineProperty({__proto__:null,HeadingPlugin:()=>{const s=e=>{try{return document.execCommand("formatBlock",!1,e),!0}catch(t){return console.error(`Failed to set block type to ${e}:`,t),!1}};return{name:"heading",toolbar:[{label:"Heading",command:"setBlockType",type:"dropdown",options:[{value:"p",label:"Paragraph"},{value:"h1",label:"Heading 1"},{value:"h2",label:"Heading 2"},{value:"h3",label:"Heading 3"},{value:"h4",label:"Heading 4"},{value:"h5",label:"Heading 5"},{value:"h6",label:"Heading 6"}],icon:'<svg width="24" height="24" focusable="false"><path d="M16.1 8.6 14.2 4l-1.4.5 2.8 7.4c.1.4.5.6.9.6h.1c.4-.1.6-.5.6-.9l1.8-4.8-1.4-.5-1.5 2.3ZM4 11.5h6V10H4v1.5ZM18.5 3v1L17 7l.9.9L20.7 3h-2.2ZM5.5 12h1v7h1v-7h1v-.5h-3V12Zm4 0h1v7h1v-7h1v-.5h-3V12Zm10 1.5a2 2 0 0 0-2-2h-1v7.5h1v-2.7h1a2 2 0 0 0 2-2v-.8Zm-2 1.3h-1v-2.3h1a.8.8 0 1 1 0 1.6v.7Z" fill-rule="evenodd"></path></svg>'}],commands:{setBlockType:e=>e?s(e):!1,setHeading1:()=>s("h1"),setHeading2:()=>s("h2"),setHeading3:()=>s("h3"),setParagraph:()=>s("p")},keymap:{"Mod-Alt-1":"setHeading1","Mod-Alt-2":"setHeading2","Mod-Alt-3":"setHeading3","Mod-Alt-0":"setParagraph"}}}},Symbol.toStringTag,{value:"Module"})),Ee=Object.freeze(Object.defineProperty({__proto__:null,BlockquotePlugin:()=>({name:"blockquote",nodes:{blockquote:{content:"block+",group:"block",parseDOM:[{tag:"blockquote"}],toDOM:()=>["blockquote",0]}},toolbar:[{label:"Quote",command:"toggleBlockquote",icon:'<svg fill="#000000" height="24px" width="24px" version="1.1" id="Icons" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 32 32" xml:space="preserve"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <g> <path d="M13,11c0.6,0,1-0.4,1-1s-0.4-1-1-1c-5,0-9,4-9,9c0,2.8,2.2,5,5,5s5-2.2,5-5s-2.2-5-5-5c-0.3,0-0.7,0-1,0.1 C9.3,11.8,11,11,13,11z"></path> <path d="M23,13c-0.3,0-0.7,0-1,0.1c1.3-1.3,3-2.1,5-2.1c0.6,0,1-0.4,1-1s-0.4-1-1-1c-5,0-9,4-9,9c0,2.8,2.2,5,5,5s5-2.2,5-5 S25.8,13,23,13z"></path> </g> </g></svg>',shortcut:"Mod-Shift-9"}],commands:{toggleBlockquote:()=>{const s=window.getSelection();if(!s||s.rangeCount===0)return!1;let e=s.anchorNode,t=!1;for(;e&&e!==document.body;){if(e.nodeName==="BLOCKQUOTE"){t=!0;break}e=e.parentNode}return t?document.execCommand("formatBlock",!1,"p"):document.execCommand("formatBlock",!1,"blockquote"),!0}},keymap:{"Mod-Shift-9":"toggleBlockquote"}})},Symbol.toStringTag,{value:"Module"}));class O{constructor(e=""){this._lines=[],this._version=0,this.setText(e)}getLine(e){return this._lines[e]||""}getLines(){return[...this._lines]}getLineCount(){return this._lines.length}getText(){return this._lines.join(`
|
|
4
|
+
`)}setText(e){this._lines=e.split(`
|
|
5
|
+
`),this._version++}getTextInRange(e){if(e.start.line===e.end.line)return this.getLine(e.start.line).substring(e.start.column,e.end.column);const t=[];t.push(this.getLine(e.start.line).substring(e.start.column));for(let o=e.start.line+1;o<e.end.line;o++)t.push(this.getLine(o));return e.end.line<this.getLineCount()&&t.push(this.getLine(e.end.line).substring(0,e.end.column)),t.join(`
|
|
6
|
+
`)}replaceRange(e,t){const o=this.getTextInRange(e);if(e.start.line===e.end.line){const n=this.getLine(e.start.line),i=n.substring(0,e.start.column)+t+n.substring(e.end.column);this._lines[e.start.line]=i}else{const n=this.getLine(e.start.line),i=this.getLine(e.end.line),r=n.substring(0,e.start.column)+t,a=i.substring(e.end.column),l=t.split(`
|
|
7
|
+
`);l[0]=r+l[0],l[l.length-1]=l[l.length-1]+a,this._lines.splice(e.start.line,e.end.line-e.start.line+1,...l)}return this._version++,{range:e,text:t,oldText:o}}insertText(e,t){const o={start:e,end:e};return this.replaceRange(o,t)}deleteRange(e){return this.replaceRange(e,"")}positionToOffset(e){let t=0;for(let o=0;o<e.line;o++)t+=this.getLine(o).length+1;return t+=e.column,t}offsetToPosition(e){let t=e;for(let o=0;o<this.getLineCount();o++){const n=this.getLine(o).length;if(t<=n)return{line:o,column:t};t-=n+1}return{line:this.getLineCount()-1,column:this.getLine(this.getLineCount()-1).length}}isValidPosition(e){return!(e.line<0||e.line>=this.getLineCount()||e.column<0||e.column>this.getLine(e.line).length)}isValidRange(e){return this.isValidPosition(e.start)&&this.isValidPosition(e.end)}getVersion(){return this._version}clone(){const e=new O;return e._lines=[...this._lines],e._version=this._version,e}}class Le{constructor(e){this.gutterWidth=50,this.lineHeight=21,this.container=e,this.createDOM()}createDOM(){this.container.innerHTML="";const e=document.createElement("div");e.style.cssText=`
|
|
8
|
+
position: relative;
|
|
9
|
+
display: flex;
|
|
10
|
+
width: 100%;
|
|
11
|
+
height: 100%;
|
|
12
|
+
background: var(--editor-background, #1e1e1e);
|
|
13
|
+
color: var(--editor-foreground, #f8f9fa);
|
|
14
|
+
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
|
|
15
|
+
font-size: 14px;
|
|
16
|
+
line-height: ${this.lineHeight}px;
|
|
17
|
+
overflow: hidden;
|
|
18
|
+
`,this.lineNumbersElement=document.createElement("div"),this.lineNumbersElement.style.cssText=`
|
|
19
|
+
position: sticky;
|
|
20
|
+
left: 0;
|
|
21
|
+
top: 0;
|
|
22
|
+
width: ${this.gutterWidth}px;
|
|
23
|
+
background: var(--editor-gutter-background, #252526);
|
|
24
|
+
color: var(--editor-gutter-foreground, #858585);
|
|
25
|
+
padding: 0;
|
|
26
|
+
text-align: right;
|
|
27
|
+
border-right: 1px solid var(--editor-gutter-border, #3e3e42);
|
|
28
|
+
user-select: none;
|
|
29
|
+
overflow: hidden;
|
|
30
|
+
z-index: 1;
|
|
31
|
+
`,this.contentElement=document.createElement("div"),this.contentElement.style.cssText=`
|
|
32
|
+
flex: 1;
|
|
33
|
+
padding: 0;
|
|
34
|
+
background: transparent;
|
|
35
|
+
border: none;
|
|
36
|
+
outline: none;
|
|
37
|
+
white-space: pre;
|
|
38
|
+
overflow-x: auto;
|
|
39
|
+
overflow-y: auto;
|
|
40
|
+
min-height: 400px;
|
|
41
|
+
font-family: inherit;
|
|
42
|
+
font-size: inherit;
|
|
43
|
+
line-height: inherit;
|
|
44
|
+
color: inherit;
|
|
45
|
+
tab-size: 2;
|
|
46
|
+
-moz-tab-size: 2;
|
|
47
|
+
`,this.contentElement.contentEditable="true",this.contentElement.spellcheck=!1,e.appendChild(this.lineNumbersElement),e.appendChild(this.contentElement),this.container.appendChild(e),this.updateLineNumbers(1)}updateLineNumbers(e){const t=Math.max(e,20),o=Array.from({length:t},(n,i)=>i+1);this.lineNumbersElement.innerHTML=o.map(n=>`<div style="height: ${this.lineHeight}px; line-height: ${this.lineHeight}px; padding-right: 12px;">${n}</div>`).join("")}getContentElement(){return this.contentElement}getLineNumbersElement(){return this.lineNumbersElement}getText(){return this.contentElement.textContent||""}setText(e){this.contentElement.textContent=e;const t=e.split(`
|
|
48
|
+
`).length;this.updateLineNumbers(t)}getCursorPosition(){const e=window.getSelection();if(!e||e.rangeCount===0)return{line:0,column:0};const t=e.getRangeAt(0),o=t.cloneRange();o.selectNodeContents(this.contentElement),o.setEnd(t.endContainer,t.endOffset);const n=o.toString().split(`
|
|
49
|
+
`);return{line:n.length-1,column:n[n.length-1].length}}setCursorPosition(e){var g,m;const t=this.getText().split(`
|
|
50
|
+
`),o=Math.min(e.line,t.length-1),n=Math.min(e.column,((g=t[o])==null?void 0:g.length)||0);let i=0;for(let f=0;f<o;f++)i+=t[f].length+1;i+=n;const r=document.createRange(),a=window.getSelection();let l=0,h=null,d=0;const c=document.createTreeWalker(this.contentElement,NodeFilter.SHOW_TEXT,null);let u;for(;u=c.nextNode();){const f=((m=u.textContent)==null?void 0:m.length)||0;if(l+f>=i){h=u,d=i-l;break}l+=f}if(h)try{r.setStart(h,d),r.setEnd(h,d),a==null||a.removeAllRanges(),a==null||a.addRange(r)}catch(f){console.warn("Could not set cursor position:",f)}}getSelectionRange(){const e=window.getSelection();if(!e||e.rangeCount===0||e.isCollapsed)return;const t=e.getRangeAt(0),o=t.cloneRange();o.selectNodeContents(this.contentElement),o.setEnd(t.startContainer,t.startOffset);const n=o.toString().split(`
|
|
51
|
+
`),i=t.cloneRange();i.selectNodeContents(this.contentElement),i.setEnd(t.endContainer,t.endOffset);const r=i.toString().split(`
|
|
52
|
+
`);return{start:{line:n.length-1,column:n[n.length-1].length},end:{line:r.length-1,column:r[r.length-1].length}}}setSelectionRange(e){this.setCursorPosition(e.start)}focus(){this.contentElement.focus()}blur(){this.contentElement.blur()}setReadOnly(e){this.contentElement.contentEditable=e?"false":"true"}applyTheme(e){Object.entries(e).forEach(([t,o])=>{this.container.style.setProperty(`--${t}`,o)})}scrollToPosition(e){const t=this.lineNumbersElement.children[e.line];t&&t.scrollIntoView({block:"center",behavior:"smooth"})}getScrollTop(){return this.contentElement.scrollTop}setScrollTop(e){this.contentElement.scrollTop=e,this.lineNumbersElement.scrollTop=e}destroy(){this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container)}}class Me{constructor(e,t={}){this.extensions=new Map,this.commands=new Map,this.eventListeners=new Map,this.folds=[],this.currentTheme="default",this.isDestroyed=!1,this.config={value:"",theme:"default",readOnly:!1,tabSize:2,lineWrapping:!1,lineNumbers:!0,...t},this.textModel=new O(this.config.value),this.view=new Le(e),this.view.setText(this.textModel.getText()),this.view.setReadOnly(this.config.readOnly||!1),this.setupEventHandlers(),this.config.extensions&&this.config.extensions.forEach(o=>this.addExtension(o)),this.setTheme(this.config.theme)}getTextModel(){return this.textModel}getView(){return this.view}getConfig(){return{...this.config}}getKeymapExtension(){return this.extensions.get("keymap")}setupEventHandlers(){const e=this.view.getContentElement();e.addEventListener("input",()=>{const t=this.view.getText(),o=this.textModel.getText();t!==o&&(this.textModel.setText(t),this.emit("change",[{range:this.getFullRange(),text:t,oldText:o}]),this.updateLineNumbers())}),e.addEventListener("selectionchange",()=>{const t=this.getCursor(),o=this.getSelection();this.emit("cursor",t),o&&this.emit("selection",o)}),e.addEventListener("keydown",t=>{this.emit("keydown",t);for(const o of this.extensions.values())if(o.onKeyDown&&o.onKeyDown(t)===!1){t.preventDefault(),t.stopPropagation();return}}),e.addEventListener("mousedown",t=>{this.emit("mousedown",t);for(const o of this.extensions.values())if(o.onMouseDown&&o.onMouseDown(t)===!1){t.preventDefault(),t.stopPropagation();return}}),e.addEventListener("focus",()=>{this.emit("focus")}),e.addEventListener("blur",()=>{this.emit("blur")})}updateLineNumbers(){const e=this.textModel.getLineCount();this.view.updateLineNumbers(e)}getFullRange(){return{start:{line:0,column:0},end:{line:this.textModel.getLineCount()-1,column:this.textModel.getLine(this.textModel.getLineCount()-1).length}}}emit(e,...t){const o=this.eventListeners.get(e);o&&o.forEach(n=>n(...t))}getValue(){return this.textModel.getText()}setValue(e){this.textModel.setText(e),this.view.setText(e),this.updateLineNumbers(),this.emit("change",[{range:this.getFullRange(),text:e,oldText:this.getValue()}])}getState(){return{text:this.getValue(),cursor:this.getCursor(),selection:this.getSelection(),readOnly:this.config.readOnly||!1,theme:this.currentTheme}}getCursor(){const e=this.view.getCursorPosition();return{position:e,anchor:e}}setCursor(e){this.view.setCursorPosition(e),this.emit("cursor",this.getCursor())}getSelection(){return this.view.getSelectionRange()}setSelection(e){this.view.setSelectionRange(e),this.emit("selection",e)}setTheme(e){this.currentTheme=e;const t={"editor-background":e==="dark"?"#1e1e1e":"#ffffff","editor-foreground":e==="dark"?"#f8f9fa":"#1a1a1a","editor-gutter-background":e==="dark"?"#252526":"#f8f9fa","editor-gutter-foreground":e==="dark"?"#858585":"#666666","editor-gutter-border":e==="dark"?"#3e3e42":"#e1e5e9"};this.view.applyTheme(t)}setReadOnly(e){this.config.readOnly=e,this.view.setReadOnly(e)}addExtension(e){if(this.extensions.has(e.name))throw new Error(`Extension '${e.name}' already exists`);this.extensions.set(e.name,e),e.setup(this)}removeExtension(e){const t=this.extensions.get(e);t&&t.destroy&&t.destroy(),this.extensions.delete(e)}executeCommand(e,...t){const o=this.commands.get(e);o?o(this,...t):console.warn(`Command '${e}' not found`)}registerCommand(e,t){this.commands.set(e,t)}search(e,t={}){const o={caseSensitive:!1,regex:!1,...t},n=[],i=this.getValue();i.split(`
|
|
53
|
+
`);let r=o.caseSensitive?i:i.toLowerCase(),a=o.caseSensitive?e:e.toLowerCase();if(o.regex){const l=new RegExp(a,o.caseSensitive?"g":"gi");let h;for(;(h=l.exec(r))!==null;){const d=this.textModel.offsetToPosition(h.index),c=this.textModel.offsetToPosition(h.index+h[0].length);n.push({range:{start:d,end:c},match:h[0]})}}else{let l=0,h=r.indexOf(a,l);for(;h!==-1;){const d=h+e.length,c=this.textModel.offsetToPosition(h),u=this.textModel.offsetToPosition(d);n.push({range:{start:c,end:u},match:i.substring(h,d)}),l=d,h=r.indexOf(a,l)}}return n}replace(e,t){const o=this.textModel.replaceRange(e,t);this.view.setText(this.getValue()),this.emit("change",[o])}replaceAll(e,t,o={}){const n=this.search(e,o);let i=0;for(let r=n.length-1;r>=0;r--)this.replace(n[r].range,t),i++;return i}fold(e){const t={start:e.start,end:e.end,collapsed:!0,level:0};this.folds.push(t)}unfold(e){this.folds=this.folds.filter(t=>!(t.start.line===e.start.line&&t.end.line===e.end.line))}getFolds(){return[...this.folds]}focus(){this.view.focus()}blur(){this.view.blur()}destroy(){if(!this.isDestroyed){this.isDestroyed=!0;for(const e of this.extensions.values())e.destroy&&e.destroy();this.extensions.clear(),this.view.destroy(),this.commands.clear(),this.eventListeners.clear()}}on(e,t){this.eventListeners.has(e)||this.eventListeners.set(e,[]),this.eventListeners.get(e).push(t)}off(e,t){if(!this.eventListeners.has(e))return;const o=this.eventListeners.get(e);if(t){const n=o.indexOf(t);n!==-1&&o.splice(n,1)}else o.length=0}}class Te{constructor(e){this.name="keymap",this.editor=null,this.keymap={},this.isMac=navigator.platform.toUpperCase().indexOf("MAC")>=0,this.keymap=e||this.getDefaultKeymap()}setup(e){this.editor=e,e.on("keydown",t=>this.handleKeyDown(t))}handleKeyDown(e){if(!this.editor)return;const t=this.findMatchingBinding(e);if(t)return this.editor.executeCommand(t.command),e.preventDefault(),e.stopPropagation(),!1}findMatchingBinding(e){const{key:t,ctrlKey:o,altKey:n,shiftKey:i,metaKey:r}=e,a=t.toLowerCase(),l=this.keymap[a];if(!l)return null;for(const h of l)if((h.ctrlKey===o||!h.ctrlKey&&!o)&&(h.altKey===n||!h.altKey&&!n)&&(h.shiftKey===i||!h.shiftKey&&!i)&&(h.metaKey===r||!h.metaKey&&!r))return h;return null}getDefaultKeymap(){const e={};return this.addBinding(e,"f",{ctrlKey:!this.isMac,metaKey:this.isMac},"find"),this.addBinding(e,"h",{ctrlKey:!this.isMac,metaKey:this.isMac},"replace"),this.addBinding(e,"f3",{},"findNext"),this.addBinding(e,"f3",{shiftKey:!0},"findPrev"),this.addBinding(e,"g",{ctrlKey:!this.isMac,metaKey:this.isMac},"findNext"),this.addBinding(e,"[",{ctrlKey:!this.isMac,metaKey:this.isMac,shiftKey:!0},"fold"),this.addBinding(e,"]",{ctrlKey:!this.isMac,metaKey:this.isMac,shiftKey:!0},"unfold"),this.addBinding(e,"s",{ctrlKey:!this.isMac,metaKey:this.isMac},"save"),this.addBinding(e,"z",{ctrlKey:!this.isMac,metaKey:this.isMac},"undo"),this.addBinding(e,"y",{ctrlKey:!this.isMac,metaKey:this.isMac},"redo"),this.addBinding(e,"z",{ctrlKey:!this.isMac,metaKey:this.isMac,shiftKey:!0},"redo"),this.addBinding(e,"t",{ctrlKey:!this.isMac,metaKey:this.isMac,shiftKey:!0},"toggleTheme"),e}addBinding(e,t,o,n){const i=t.toLowerCase();e[i]||(e[i]=[]),e[i].push({key:i,command:n,...o})}setKeymap(e){this.keymap={...e}}addKeyBinding(e){const t=e.key.toLowerCase();this.keymap[t]||(this.keymap[t]=[]),this.keymap[t]=this.keymap[t].filter(o=>o.command!==e.command),this.keymap[t].push({...e,key:t})}removeKeyBinding(e,t){const o=e.toLowerCase();t?this.keymap[o]&&(this.keymap[o]=this.keymap[o].filter(n=>n.command!==t),this.keymap[o].length===0&&delete this.keymap[o]):delete this.keymap[o]}getKeymap(){return{...this.keymap}}getBindingsForCommand(e){const t=[];for(const o in this.keymap)for(const n of this.keymap[o])n.command===e&&t.push({...n});return t}getPlatformInfo(){return{isMac:this.isMac,platform:navigator.platform}}destroy(){this.keymap={},this.editor=null}}class Se{constructor(){this.name="line-numbers",this.editor=null,this.lineNumbersElement=null,this.isEnabled=!0}setup(e){this.editor=e,this.createLineNumbers(),e.registerCommand("toggleLineNumbers",()=>{this.toggle()}),e.on("change",()=>{this.updateLineNumbers()}),this.updateLineNumbers()}createLineNumbers(){if(!this.editor)return;const e=this.editor.getView();if(!e.container)return;this.lineNumbersElement=document.createElement("div"),this.lineNumbersElement.style.cssText=`
|
|
54
|
+
position: absolute;
|
|
55
|
+
left: 0;
|
|
56
|
+
top: 0;
|
|
57
|
+
bottom: 0;
|
|
58
|
+
width: 50px;
|
|
59
|
+
background: var(--editor-gutter-background, #252526);
|
|
60
|
+
color: var(--editor-gutter-foreground, #858585);
|
|
61
|
+
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
|
|
62
|
+
font-size: 14px;
|
|
63
|
+
line-height: 21px;
|
|
64
|
+
padding: 0;
|
|
65
|
+
text-align: right;
|
|
66
|
+
border-right: 1px solid var(--editor-gutter-border, #3e3e42);
|
|
67
|
+
user-select: none;
|
|
68
|
+
overflow: hidden;
|
|
69
|
+
z-index: 1;
|
|
70
|
+
pointer-events: none;
|
|
71
|
+
`;const t=e.getContentElement();t&&t.parentNode&&(t.parentNode.insertBefore(this.lineNumbersElement,t),t.style.marginLeft="60px")}updateLineNumbers(){if(!this.lineNumbersElement||!this.editor||!this.isEnabled)return;const e=this.editor.getValue().split(`
|
|
72
|
+
`).length,t=Array.from({length:Math.max(e,20)},(o,n)=>n+1);this.lineNumbersElement.innerHTML=t.map(o=>`<div style="height: 21px; line-height: 21px; padding-right: 12px;">${o}</div>`).join("")}toggle(){this.isEnabled=!this.isEnabled,this.lineNumbersElement&&(this.lineNumbersElement.style.display=this.isEnabled?"block":"none");const e=this.editor.getView().getContentElement();e&&(e.style.marginLeft=this.isEnabled?"60px":"0"),this.updateLineNumbers()}destroy(){this.lineNumbersElement&&this.lineNumbersElement.parentNode&&this.lineNumbersElement.parentNode.removeChild(this.lineNumbersElement),this.lineNumbersElement=null,this.editor=null}}class Pe{constructor(){this.name="theme",this.editor=null,this.currentTheme="dark"}setup(e){this.editor=e,e.registerCommand("setTheme",t=>{this.setTheme(t)}),e.registerCommand("toggleTheme",()=>{this.toggleTheme()}),this.setTheme(this.currentTheme)}setTheme(e){this.editor&&(this.currentTheme=e,this.editor.setTheme(e))}toggleTheme(){const e=this.currentTheme==="dark"?"light":"dark";this.setTheme(e)}getCurrentTheme(){return this.currentTheme}destroy(){this.editor=null}}class Ie{constructor(){this.name="read-only",this.editor=null,this.isReadOnly=!1}setup(e){this.editor=e,e.registerCommand("setReadOnly",t=>{this.setReadOnly(t)}),e.registerCommand("toggleReadOnly",()=>{this.toggleReadOnly()}),e.on("keydown",t=>{if(t.ctrlKey&&t.key==="r")return t.preventDefault(),this.toggleReadOnly(),!1})}setReadOnly(e){this.editor&&(this.isReadOnly=e,this.editor.setReadOnly(e))}toggleReadOnly(){this.setReadOnly(!this.isReadOnly)}isCurrentlyReadOnly(){return this.isReadOnly}destroy(){this.editor=null}}class He{constructor(){this.name="search",this.editor=null,this.searchUI=null,this.isVisible=!1,this.currentResults=[],this.currentIndex=-1}setup(e){this.editor=e,e.registerCommand("find",()=>{this.showSearch()}),e.registerCommand("findNext",()=>{this.findNext()}),e.registerCommand("findPrev",()=>{this.findPrev()}),e.registerCommand("replace",()=>{this.showReplace()}),e.registerCommand("replaceAll",(t,o)=>{this.replaceAll(t,o)})}showSearch(){if(this.editor&&(this.searchUI||this.createSearchUI(),this.isVisible=!0,this.searchUI)){this.searchUI.style.display="block";const e=this.searchUI.querySelector("input");e&&(e.focus(),e.select())}}showReplace(){var o,n;this.showSearch();const e=(o=this.searchUI)==null?void 0:o.querySelector(".search-replace-input");e&&(e.style.display="block",e.focus());const t=(n=this.searchUI)==null?void 0:n.querySelector(".search-status");t&&(t.textContent="Replace mode - Enter to replace, Shift+Enter to replace all")}hideSearch(){this.isVisible=!1,this.searchUI&&(this.searchUI.style.display="none"),this.clearHighlights()}createSearchUI(){if(!this.editor)return;const e=document.querySelector(".rte-source-editor-modal");if(!e)return;this.searchUI=document.createElement("div"),this.searchUI.style.cssText=`
|
|
73
|
+
position: absolute;
|
|
74
|
+
top: 10px;
|
|
75
|
+
right: 10px;
|
|
76
|
+
background: var(--editor-background, #1e1e1e);
|
|
77
|
+
border: 1px solid var(--editor-gutter-border, #3e3e42);
|
|
78
|
+
border-radius: 4px;
|
|
79
|
+
padding: 8px;
|
|
80
|
+
z-index: 1000;
|
|
81
|
+
display: none;
|
|
82
|
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
|
|
83
|
+
min-width: 250px;
|
|
84
|
+
`,this.searchUI.innerHTML=`
|
|
85
|
+
<div style="display: flex; align-items: center; gap: 4px; margin-bottom: 4px;">
|
|
86
|
+
<input type="text" placeholder="Find..." style="
|
|
87
|
+
flex: 1;
|
|
88
|
+
padding: 4px 8px;
|
|
89
|
+
background: var(--editor-gutter-background, #252526);
|
|
90
|
+
color: var(--editor-foreground, #f8f9fa);
|
|
91
|
+
border: 1px solid var(--editor-gutter-border, #3e3e42);
|
|
92
|
+
border-radius: 3px;
|
|
93
|
+
font-size: 12px;
|
|
94
|
+
outline: none;
|
|
95
|
+
" />
|
|
96
|
+
<button class="search-prev" style="
|
|
97
|
+
padding: 2px 6px;
|
|
98
|
+
background: var(--editor-gutter-background, #252526);
|
|
99
|
+
color: var(--editor-gutter-foreground, #858585);
|
|
100
|
+
border: 1px solid var(--editor-gutter-border, #3e3e42);
|
|
101
|
+
border-radius: 3px;
|
|
102
|
+
cursor: pointer;
|
|
103
|
+
font-size: 11px;
|
|
104
|
+
">↑</button>
|
|
105
|
+
<button class="search-next" style="
|
|
106
|
+
padding: 2px 6px;
|
|
107
|
+
background: var(--editor-gutter-background, #252526);
|
|
108
|
+
color: var(--editor-gutter-foreground, #858585);
|
|
109
|
+
border: 1px solid var(--editor-gutter-border, #3e3e42);
|
|
110
|
+
border-radius: 3px;
|
|
111
|
+
cursor: pointer;
|
|
112
|
+
font-size: 11px;
|
|
113
|
+
">↓</button>
|
|
114
|
+
<button class="search-close" style="
|
|
115
|
+
padding: 2px 6px;
|
|
116
|
+
background: var(--editor-gutter-background, #252526);
|
|
117
|
+
color: var(--editor-gutter-foreground, #858585);
|
|
118
|
+
border: 1px solid var(--editor-gutter-border, #3e3e42);
|
|
119
|
+
border-radius: 3px;
|
|
120
|
+
cursor: pointer;
|
|
121
|
+
font-size: 11px;
|
|
122
|
+
">×</button>
|
|
123
|
+
</div>
|
|
124
|
+
<div class="search-status" style="
|
|
125
|
+
font-size: 11px;
|
|
126
|
+
color: var(--editor-gutter-foreground, #858585);
|
|
127
|
+
text-align: center;
|
|
128
|
+
"></div>
|
|
129
|
+
<input type="text" class="search-replace-input" placeholder="Replace with..." style="
|
|
130
|
+
width: 100%;
|
|
131
|
+
padding: 4px 8px;
|
|
132
|
+
background: var(--editor-gutter-background, #252526);
|
|
133
|
+
color: var(--editor-foreground, #f8f9fa);
|
|
134
|
+
border: 1px solid var(--editor-gutter-border, #3e3e42);
|
|
135
|
+
border-radius: 3px;
|
|
136
|
+
font-size: 12px;
|
|
137
|
+
outline: none;
|
|
138
|
+
display: none;
|
|
139
|
+
margin-top: 4px;
|
|
140
|
+
" />
|
|
141
|
+
`;const t=this.searchUI.querySelector("input"),o=this.searchUI.querySelector(".search-replace-input"),n=this.searchUI.querySelector(".search-prev"),i=this.searchUI.querySelector(".search-next"),r=this.searchUI.querySelector(".search-close");t.addEventListener("input",()=>{this.performSearch(t.value)}),t.addEventListener("keydown",a=>{a.key==="Enter"&&(a.preventDefault(),a.shiftKey?this.findPrev():this.findNext())}),o.addEventListener("keydown",a=>{a.key==="Enter"&&(a.preventDefault(),a.shiftKey?this.replaceAll(t.value,o.value):this.replaceCurrent(t.value,o.value))}),n.addEventListener("click",()=>this.findPrev()),i.addEventListener("click",()=>this.findNext()),r.addEventListener("click",()=>this.hideSearch()),e.appendChild(this.searchUI)}performSearch(e){if(!this.editor||!e.trim()){this.clearHighlights(),this.updateStatus("");return}const t=this.editor.getValue(),o=[];let n=t.toLowerCase().indexOf(e.toLowerCase());for(;n!==-1;){const i=this.getPositionFromOffset(t,n),r=this.getPositionFromOffset(t,n+e.length);o.push({range:{start:i,end:r},match:t.substring(n,n+e.length)}),n=t.toLowerCase().indexOf(e.toLowerCase(),n+1)}this.currentResults=o,this.currentIndex=this.currentResults.length>0?0:-1,this.updateHighlights(),this.updateStatus(`${this.currentResults.length} matches`)}getPositionFromOffset(e,t){const o=e.substring(0,t).split(`
|
|
142
|
+
`),n=o.length-1,i=o[o.length-1].length;return{line:n,column:i}}findNext(){this.currentResults.length!==0&&(this.currentIndex=(this.currentIndex+1)%this.currentResults.length,this.updateHighlights())}findPrev(){this.currentResults.length!==0&&(this.currentIndex=this.currentIndex<=0?this.currentResults.length-1:this.currentIndex-1,this.updateHighlights())}replaceCurrent(e,t){if(!this.editor||!e.trim()||this.currentIndex===-1)return;const o=this.currentResults[this.currentIndex];if(!o)return;const n=this.editor.getValue(),i=this.getOffsetFromPosition(n,o.range.start),r=n.substring(0,i),a=n.substring(i+e.length),l=r+t+a;this.editor.setValue(l),this.performSearch(e),this.updateStatus("Replaced current occurrence")}replaceAll(e,t){if(!this.editor||!e.trim())return;let o=this.editor.getValue(),n=0,i=o.toLowerCase().indexOf(e.toLowerCase());for(;i!==-1;)o=o.substring(0,i)+t+o.substring(i+e.length),n++,i=o.toLowerCase().indexOf(e.toLowerCase(),i+t.length);n>0&&(this.editor.setValue(o),this.updateStatus(`Replaced ${n} occurrences`))}getOffsetFromPosition(e,t){const o=e.split(`
|
|
143
|
+
`);let n=0;for(let i=0;i<t.line;i++)n+=o[i].length+1;return n+=t.column,n}updateHighlights(){this.clearHighlights(),!(this.currentResults.length===0||this.currentIndex===-1)&&(this.currentResults[this.currentIndex],this.updateStatus(`${this.currentResults.length} matches (showing ${this.currentIndex+1}/${this.currentResults.length})`))}clearHighlights(){}updateStatus(e){var o;const t=(o=this.searchUI)==null?void 0:o.querySelector(".search-status");t&&(t.textContent=e)}destroy(){this.searchUI&&this.searchUI.parentNode&&this.searchUI.parentNode.removeChild(this.searchUI),this.searchUI=null,this.editor=null}}class Oe{constructor(){this.name="bracket-matching",this.editor=null,this.bracketPairs={"(":")","[":"]","{":"}","<":">"},this.reverseBracketPairs={")":"(","]":"[","}":"{",">":"<"},this.currentMatch=null}setup(e){this.editor=e,e.on("cursor",()=>{this.updateBracketMatching()}),e.on("change",()=>{this.updateBracketMatching()})}updateBracketMatching(){if(!this.editor)return;const e=this.editor.getCursor(),t=this.editor.getValue();this.clearBracketHighlighting();const o=this.getBracketAtPosition(t,e.position);if(!o)return;const n=this.findMatchingBracket(t,o);n&&(this.currentMatch=n,this.highlightBrackets(n))}getBracketAtPosition(e,t){const o=e.split(`
|
|
144
|
+
`);if(t.line>=o.length)return null;const n=o[t.line];if(t.column>=n.length)return null;const i=n[t.column];return this.bracketPairs[i]||this.reverseBracketPairs[i]?{char:i,position:t}:null}findMatchingBracket(e,t){const o=e.split(`
|
|
145
|
+
`),n=t.position.line,i=t.position.column,r=t.char;return this.bracketPairs[r]?this.findClosingBracket(e,o,n,i,r):this.reverseBracketPairs[r]?this.findOpeningBracket(e,o,n,i,r):null}findClosingBracket(e,t,o,n,i){const r=this.bracketPairs[i];let a=0;for(let l=o;l<t.length;l++){const h=t[l],d=l===o?n:0;for(let c=d;c<h.length;c++){const u=h[c];if(u===i)a++;else if(u===r&&(a--,a===0))return{open:{start:{line:o,column:n},end:{line:o,column:n+1}},close:{start:{line:l,column:c},end:{line:l,column:c+1}},type:i}}}return null}findOpeningBracket(e,t,o,n,i){const r=this.reverseBracketPairs[i];let a=0;for(let l=o;l>=0;l--){const h=t[l],d=l===o?n:h.length-1;for(let c=d;c>=0;c--){const u=h[c];if(u===i)a++;else if(u===r&&(a--,a===0))return{open:{start:{line:l,column:c},end:{line:l,column:c+1}},close:{start:{line:o,column:n},end:{line:o,column:n+1}},type:r}}}return null}highlightBrackets(e){console.log("Bracket match found:",e)}clearBracketHighlighting(){this.currentMatch=null}getCurrentMatch(){return this.currentMatch}destroy(){this.clearBracketHighlighting(),this.editor=null}}class Ne{constructor(){this.name="code-folding",this.editor=null,this.foldIndicators=[],this.foldingUI=null}setup(e){this.editor=e,e.registerCommand("fold",()=>{console.log("Fold command executed - folding not yet implemented"),this.foldAtCursor()}),e.registerCommand("unfold",()=>{console.log("Unfold command executed - unfolding not yet implemented"),this.unfoldAtCursor()}),e.registerCommand("foldAll",()=>{console.log("Fold all command executed - folding not yet implemented"),this.foldAll()}),e.registerCommand("unfoldAll",()=>{console.log("Unfold all command executed - unfolding not yet implemented"),this.unfoldAll()}),e.on("change",()=>{this.updateFoldIndicators()}),this.createFoldingUI(),this.updateFoldIndicators()}createFoldingUI(){if(!this.editor)return;const e=document.querySelector(".rte-source-editor-modal");e&&(this.foldingUI=document.createElement("div"),this.foldingUI.style.cssText=`
|
|
146
|
+
position: absolute;
|
|
147
|
+
left: 40px;
|
|
148
|
+
top: 0;
|
|
149
|
+
bottom: 0;
|
|
150
|
+
width: 20px;
|
|
151
|
+
pointer-events: none;
|
|
152
|
+
z-index: 2;
|
|
153
|
+
`,e.appendChild(this.foldingUI))}updateFoldIndicators(){if(!this.editor||!this.foldingUI)return;this.foldingUI.innerHTML="",this.foldIndicators=[];const e=this.editor.getValue().split(`
|
|
154
|
+
`);this.findFoldableLines(e).forEach(t=>{this.createFoldIndicator(t)})}findFoldableLines(e){const t=[];for(let o=0;o<e.length;o++){const n=e[o].trim();(n.startsWith("{")||n.startsWith("function")||n.startsWith("class")||n.startsWith("if")||n.includes("=>")||n.startsWith("for")||n.startsWith("while")||n.startsWith("try"))&&t.push(o)}return t}createFoldIndicator(e){if(!this.foldingUI)return;const t=document.createElement("div");t.style.cssText=`
|
|
155
|
+
position: absolute;
|
|
156
|
+
left: 0;
|
|
157
|
+
top: ${e*21}px;
|
|
158
|
+
width: 20px;
|
|
159
|
+
height: 21px;
|
|
160
|
+
display: flex;
|
|
161
|
+
align-items: center;
|
|
162
|
+
justify-content: center;
|
|
163
|
+
cursor: pointer;
|
|
164
|
+
pointer-events: auto;
|
|
165
|
+
color: var(--editor-gutter-foreground, #858585);
|
|
166
|
+
font-size: 10px;
|
|
167
|
+
user-select: none;
|
|
168
|
+
`,t.innerHTML="▶",t.title="Code folding not yet implemented - click shows fold indicators",t.addEventListener("click",()=>{console.log(`Fold toggle clicked at line ${e} - implementation pending`)}),this.foldingUI.appendChild(t),this.foldIndicators.push(t)}foldAtCursor(){console.log("foldAtCursor called - implementation pending")}unfoldAtCursor(){console.log("unfoldAtCursor called - implementation pending")}foldAll(){console.log("foldAll called - implementation pending")}unfoldAll(){console.log("unfoldAll called - implementation pending")}destroy(){this.foldingUI&&this.foldingUI.parentNode&&this.foldingUI.parentNode.removeChild(this.foldingUI),this.foldingUI=null,this.foldIndicators=[],this.editor=null}}class Be{constructor(){this.name="syntax-highlighting",this.editor=null,this.currentTheme="dark"}setup(e){this.editor=e,console.log("SyntaxHighlightingExtension: Isolated extension loaded - ready for use")}setTheme(e){this.currentTheme=e,console.log(`SyntaxHighlightingExtension: Theme changed to ${e}`)}getSyntaxColors(){return this.currentTheme==="dark"?{tag:"#569cd6",comment:"#6a9955",attrValue:"#ce9178",text:"#d4d4d4"}:{tag:"#0000ff",comment:"#008000",attrValue:"#a31515",text:"#000000"}}highlightHTML(e){const t=this.getSyntaxColors();let o=e;return o=o.replace(/(<\/?[\w:-]+(?:\s[^>]*?)?\/?>)/g,`<span style="color: ${t.tag};">$1</span>`),o=o.replace(/(<!--[\s\S]*?-->)/g,`<span style="color: ${t.comment};">$1</span>`),o=o.replace(/("[^"]*"|'[^']*')/g,`<span style="color: ${t.attrValue};">$1</span>`),o}shouldHighlight(e){return/<\/?[\w:-]+|<!--/.test(e)}destroy(){this.editor=null,console.log("SyntaxHighlightingExtension: Extension destroyed")}}function Ae(s,e){const t={...e};return t.extensions||(t.extensions=[]),t.extensions.some(o=>o.name==="keymap")||t.extensions.unshift(new Te(t.keymap)),new Me(s,t)}const ze=`/* Source Editor Dialog Styles */
|
|
169
|
+
.rte-source-editor-overlay {
|
|
170
|
+
position: fixed !important;
|
|
171
|
+
top: 0 !important;
|
|
172
|
+
left: 0 !important;
|
|
173
|
+
right: 0 !important;
|
|
174
|
+
bottom: 0 !important;
|
|
175
|
+
width: 100vw !important;
|
|
176
|
+
height: 100vh !important;
|
|
177
|
+
background-color: rgba(0, 0, 0, 0.6) !important;
|
|
178
|
+
display: flex !important;
|
|
179
|
+
align-items: center !important;
|
|
180
|
+
justify-content: center !important;
|
|
181
|
+
z-index: 10000 !important;
|
|
182
|
+
padding: 20px !important;
|
|
183
|
+
box-sizing: border-box !important;
|
|
184
|
+
margin: 0 !important;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.rte-source-editor-overlay.fullscreen {
|
|
188
|
+
padding: 0 !important;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
.rte-source-editor-modal {
|
|
192
|
+
background: white;
|
|
193
|
+
border-radius: 8px;
|
|
194
|
+
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
|
195
|
+
width: 100%;
|
|
196
|
+
max-width: 1200px;
|
|
197
|
+
max-height: 90vh;
|
|
198
|
+
display: flex;
|
|
199
|
+
flex-direction: column;
|
|
200
|
+
overflow: hidden;
|
|
201
|
+
position: relative;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
.rte-source-editor-overlay.fullscreen .rte-source-editor-modal {
|
|
205
|
+
border-radius: 0;
|
|
206
|
+
max-width: 100%;
|
|
207
|
+
max-height: 100vh;
|
|
208
|
+
width: 100%;
|
|
209
|
+
height: 100vh;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
.rte-source-editor-header {
|
|
213
|
+
display: flex;
|
|
214
|
+
align-items: center;
|
|
215
|
+
justify-content: space-between;
|
|
216
|
+
padding: 16px 20px;
|
|
217
|
+
border-bottom: 1px solid #e1e5e9;
|
|
218
|
+
background: #f8f9fa;
|
|
219
|
+
border-radius: 8px 8px 0 0;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
.rte-source-editor-overlay.fullscreen .rte-source-editor-header {
|
|
223
|
+
border-radius: 0;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
.rte-source-editor-header h2 {
|
|
227
|
+
margin: 0;
|
|
228
|
+
font-size: 18px;
|
|
229
|
+
font-weight: 600;
|
|
230
|
+
color: #1a1a1a;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
.rte-source-editor-header-toolbar {
|
|
234
|
+
display: flex;
|
|
235
|
+
gap: 8px;
|
|
236
|
+
margin-left: auto;
|
|
237
|
+
margin-right: 16px;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
.rte-source-editor-toolbar-btn {
|
|
241
|
+
background: none;
|
|
242
|
+
border: none;
|
|
243
|
+
cursor: pointer;
|
|
244
|
+
padding: 6px;
|
|
245
|
+
border-radius: 4px;
|
|
246
|
+
font-size: 16px;
|
|
247
|
+
line-height: 1;
|
|
248
|
+
transition: all 0.2s ease;
|
|
249
|
+
color: #666;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
.rte-source-editor-toolbar-btn:hover:not(:disabled) {
|
|
253
|
+
background: #e1e5e9;
|
|
254
|
+
color: #1a1a1a;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
.rte-source-editor-toolbar-btn:disabled {
|
|
258
|
+
opacity: 0.5;
|
|
259
|
+
cursor: not-allowed;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
.rte-source-editor-toolbar-btn.active {
|
|
263
|
+
background: #007acc;
|
|
264
|
+
color: white;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
.rte-source-editor-toolbar-btn.active:hover {
|
|
268
|
+
background: #0056b3;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
.rte-source-editor-header-actions {
|
|
272
|
+
display: flex;
|
|
273
|
+
gap: 8px;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
.rte-source-editor-fullscreen-btn,
|
|
277
|
+
.rte-source-editor-close-btn {
|
|
278
|
+
background: none;
|
|
279
|
+
border: none;
|
|
280
|
+
cursor: pointer;
|
|
281
|
+
padding: 4px;
|
|
282
|
+
border-radius: 4px;
|
|
283
|
+
color: #666;
|
|
284
|
+
font-size: 16px;
|
|
285
|
+
line-height: 1;
|
|
286
|
+
transition: all 0.2s ease;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
.rte-source-editor-fullscreen-btn:hover,
|
|
290
|
+
.rte-source-editor-close-btn:hover {
|
|
291
|
+
background: #e1e5e9;
|
|
292
|
+
color: #1a1a1a;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
.rte-source-editor-body {
|
|
296
|
+
flex: 1;
|
|
297
|
+
overflow: hidden;
|
|
298
|
+
display: flex;
|
|
299
|
+
flex-direction: column;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
.rte-source-editor-loading {
|
|
303
|
+
display: flex;
|
|
304
|
+
flex-direction: column;
|
|
305
|
+
align-items: center;
|
|
306
|
+
justify-content: center;
|
|
307
|
+
padding: 40px;
|
|
308
|
+
color: #666;
|
|
309
|
+
position: absolute;
|
|
310
|
+
z-index: 9;
|
|
311
|
+
margin: 0 auto;
|
|
312
|
+
width: 100%;
|
|
313
|
+
top: 44%;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
.rte-source-editor-spinner {
|
|
317
|
+
width: 32px;
|
|
318
|
+
height: 32px;
|
|
319
|
+
border: 3px solid #e1e5e9;
|
|
320
|
+
border-top: 3px solid #007acc;
|
|
321
|
+
border-radius: 50%;
|
|
322
|
+
animation: spin 1s linear infinite;
|
|
323
|
+
margin-bottom: 16px;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
@keyframes spin {
|
|
327
|
+
0% { transform: rotate(0deg); }
|
|
328
|
+
100% { transform: rotate(360deg); }
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
.rte-source-editor-error {
|
|
332
|
+
background: #fee;
|
|
333
|
+
color: #c53030;
|
|
334
|
+
padding: 12px 16px;
|
|
335
|
+
border-left: 4px solid #c53030;
|
|
336
|
+
margin: 16px;
|
|
337
|
+
border-radius: 4px;
|
|
338
|
+
font-size: 14px;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
.rte-source-editor-content {
|
|
342
|
+
flex: 1;
|
|
343
|
+
display: flex;
|
|
344
|
+
flex-direction: column;
|
|
345
|
+
overflow: hidden;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
.rte-source-editor-warning {
|
|
349
|
+
background: #fefcbf;
|
|
350
|
+
color: #744210;
|
|
351
|
+
padding: 8px 16px;
|
|
352
|
+
font-size: 12px;
|
|
353
|
+
font-weight: 500;
|
|
354
|
+
border-bottom: 1px solid #f6e05e;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
.rte-source-editor-codemirror {
|
|
358
|
+
flex: 1;
|
|
359
|
+
overflow: auto;
|
|
360
|
+
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
|
|
361
|
+
font-size: 14px;
|
|
362
|
+
line-height: 1.5;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
.rte-source-editor-codemirror .cm-editor {
|
|
366
|
+
height: 100%;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
.rte-source-editor-codemirror .cm-focused {
|
|
370
|
+
outline: none;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
.rte-source-editor-footer {
|
|
374
|
+
display: flex;
|
|
375
|
+
align-items: center;
|
|
376
|
+
justify-content: space-between;
|
|
377
|
+
padding: 16px 20px;
|
|
378
|
+
border-top: 1px solid #e1e5e9;
|
|
379
|
+
background: #f8f9fa;
|
|
380
|
+
border-radius: 0 0 8px 8px;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
.rte-source-editor-overlay.fullscreen .rte-source-editor-footer {
|
|
384
|
+
border-radius: 0;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
.rte-source-editor-footer-info {
|
|
388
|
+
font-size: 12px;
|
|
389
|
+
color: #666;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
.unsaved-changes {
|
|
393
|
+
color: #d69e2e;
|
|
394
|
+
font-weight: 500;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
.rte-source-editor-footer-actions {
|
|
398
|
+
display: flex;
|
|
399
|
+
gap: 12px;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
.rte-source-editor-btn {
|
|
403
|
+
padding: 8px 16px;
|
|
404
|
+
border-radius: 4px;
|
|
405
|
+
font-size: 14px;
|
|
406
|
+
font-weight: 500;
|
|
407
|
+
cursor: pointer;
|
|
408
|
+
border: 1px solid transparent;
|
|
409
|
+
transition: all 0.2s ease;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
.rte-source-editor-btn:disabled {
|
|
413
|
+
opacity: 0.6;
|
|
414
|
+
cursor: not-allowed;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
.rte-source-editor-btn-cancel {
|
|
418
|
+
background: white;
|
|
419
|
+
border-color: #d1d5db;
|
|
420
|
+
color: #374151;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
.rte-source-editor-btn-cancel:hover:not(:disabled) {
|
|
424
|
+
background: #f9fafb;
|
|
425
|
+
border-color: #9ca3af;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
.rte-source-editor-btn-save {
|
|
429
|
+
background: #007acc;
|
|
430
|
+
color: white;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
.rte-source-editor-btn-save:hover:not(:disabled) {
|
|
434
|
+
background: #0056b3;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/* Dark theme support */
|
|
438
|
+
@media (prefers-color-scheme: dark) {
|
|
439
|
+
.rte-source-editor-modal {
|
|
440
|
+
background: #1e1e1e;
|
|
441
|
+
color: #f8f9fa;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
.rte-source-editor-header {
|
|
445
|
+
background: #2d2d2d;
|
|
446
|
+
border-color: #404040;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
.rte-source-editor-header h2 {
|
|
450
|
+
color: #f8f9fa;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
.rte-source-editor-fullscreen-btn,
|
|
454
|
+
.rte-source-editor-close-btn {
|
|
455
|
+
color: #ccc;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
.rte-source-editor-fullscreen-btn:hover,
|
|
459
|
+
.rte-source-editor-close-btn:hover {
|
|
460
|
+
background: #404040;
|
|
461
|
+
color: #f8f9fa;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
.rte-source-editor-error {
|
|
465
|
+
background: #2d1b1b;
|
|
466
|
+
color: #fca5a5;
|
|
467
|
+
border-color: #dc2626;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
.rte-source-editor-warning {
|
|
471
|
+
background: #2d2a1b;
|
|
472
|
+
color: #fcd34d;
|
|
473
|
+
border-color: #d97706;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
.rte-source-editor-footer {
|
|
477
|
+
background: #2d2d2d;
|
|
478
|
+
border-color: #404040;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
.rte-source-editor-footer-info {
|
|
482
|
+
color: #ccc;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
.rte-source-editor-btn-cancel {
|
|
486
|
+
background: #374151;
|
|
487
|
+
border-color: #4b5563;
|
|
488
|
+
color: #f9fafb;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
.rte-source-editor-btn-cancel:hover:not(:disabled) {
|
|
492
|
+
background: #4b5563;
|
|
493
|
+
border-color: #6b7280;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/* Responsive design */
|
|
498
|
+
@media (max-width: 768px) {
|
|
499
|
+
.rte-source-editor-overlay {
|
|
500
|
+
padding: 10px;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
.rte-source-editor-modal {
|
|
504
|
+
max-height: 95vh;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
.rte-source-editor-header {
|
|
508
|
+
padding: 12px 16px;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
.rte-source-editor-footer {
|
|
512
|
+
padding: 12px 16px;
|
|
513
|
+
flex-direction: column;
|
|
514
|
+
gap: 12px;
|
|
515
|
+
align-items: stretch;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
.rte-source-editor-footer-actions {
|
|
519
|
+
justify-content: stretch;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
.rte-source-editor-btn {
|
|
523
|
+
flex: 1;
|
|
524
|
+
text-align: center;
|
|
525
|
+
}
|
|
526
|
+
}`,Re=Object.freeze(Object.defineProperty({__proto__:null,CodePlugin:()=>({name:"code",toolbar:[{label:"Source",command:"toggleSourceView",type:"button",icon:"<>",shortcut:"Mod-Shift-S"}],commands:{toggleSourceView:()=>{const e=(()=>{var a,l,h;const i=window.getSelection();if(i&&i.anchorNode){let d=i.anchorNode instanceof HTMLElement?i.anchorNode:i.anchorNode.parentElement;for(;d;){if((a=d.classList)!=null&&a.contains("rte-content"))return d;d=d.parentElement}}if(document.activeElement){let d=document.activeElement;if((l=d.classList)!=null&&l.contains("rte-content"))return d;for(;d&&d!==document.body;){if((h=d.classList)!=null&&h.contains("rte-content"))return d;const c=d.querySelector(".rte-content");if(c)return c;d=d.parentElement}}const r=document.querySelector("[data-editora-editor]");if(r){const d=r.querySelector(".rte-content");if(d)return d}return document.querySelector(".rte-content")})();if(!e)return console.error("[CodePlugin] Editor content area not found"),alert("Editor content area not found. Please click inside the editor first."),!1;const t=e.innerHTML,o=i=>{let r="",a=0;const l=2,h=i.split(/(<\/?[a-zA-Z][^>]*>)/);for(const d of h)d.trim()&&(d.match(/^<\/[a-zA-Z]/)?(a=Math.max(0,a-1),r+=`
|
|
527
|
+
`+" ".repeat(a*l)+d):d.match(/^<[a-zA-Z]/)&&!d.match(/\/>$/)?(r+=`
|
|
528
|
+
`+" ".repeat(a*l)+d,a++):d.match(/^<[a-zA-Z].*\/>$/)?r+=`
|
|
529
|
+
`+" ".repeat(a*l)+d:r+=d.trim());return r.trim()};return(()=>{var X,Y,Q,J,ee,te;let i=null,r="dark",a=!1,l=!1,h=!1;const d=t,c=document.createElement("div");c.className="rte-source-editor-overlay";const u=document.createElement("div");u.className="rte-source-editor-modal",u.setAttribute("role","dialog"),u.setAttribute("aria-modal","true"),u.setAttribute("aria-labelledby","source-editor-title");const g=document.createElement("div");g.className="rte-source-editor-header",g.innerHTML=`
|
|
530
|
+
<h2 id="source-editor-title">Source Editor</h2>
|
|
531
|
+
<div class="rte-source-editor-header-toolbar">
|
|
532
|
+
<button class="rte-source-editor-toolbar-btn theme-toggle-btn" title="Switch theme">
|
|
533
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
534
|
+
<circle cx="12" cy="12" r="5"/>
|
|
535
|
+
<line x1="12" y1="1" x2="12" y2="3"/>
|
|
536
|
+
<line x1="12" y1="21" x2="12" y2="23"/>
|
|
537
|
+
<line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/>
|
|
538
|
+
<line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/>
|
|
539
|
+
<line x1="1" y1="12" x2="3" y2="12"/>
|
|
540
|
+
<line x1="21" y1="12" x2="23" y2="12"/>
|
|
541
|
+
<line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/>
|
|
542
|
+
<line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/>
|
|
543
|
+
</svg>
|
|
544
|
+
</button>
|
|
545
|
+
<button class="rte-source-editor-toolbar-btn readonly-toggle-btn" title="Toggle read-only">
|
|
546
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
547
|
+
<path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/>
|
|
548
|
+
<path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>
|
|
549
|
+
</svg>
|
|
550
|
+
</button>
|
|
551
|
+
</div>
|
|
552
|
+
<div class="rte-source-editor-header-actions">
|
|
553
|
+
<button class="rte-source-editor-fullscreen-btn" title="Toggle fullscreen">
|
|
554
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
555
|
+
<path d="M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"/>
|
|
556
|
+
</svg>
|
|
557
|
+
</button>
|
|
558
|
+
<button class="rte-source-editor-close-btn" aria-label="Close source editor">
|
|
559
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
560
|
+
<line x1="18" y1="6" x2="6" y2="18"/>
|
|
561
|
+
<line x1="6" y1="6" x2="18" y2="18"/>
|
|
562
|
+
</svg>
|
|
563
|
+
</button>
|
|
564
|
+
</div>
|
|
565
|
+
`;const m=document.createElement("div");m.className="rte-source-editor-body";const f=document.createElement("div");f.className="rte-source-editor-content";const F=document.createElement("div");F.className="rte-source-editor-warning",F.textContent="⚠️ Advanced users only. Invalid HTML may break the editor.";const v=document.createElement("div");v.className="rte-source-editor-light-editor",v.style.height="400px",f.appendChild(F),f.appendChild(v),m.appendChild(f);const w=document.createElement("div");if(w.className="rte-source-editor-footer",w.innerHTML=`
|
|
566
|
+
<div class="rte-source-editor-footer-info">
|
|
567
|
+
<span class="unsaved-changes" style="display: none;">• Unsaved changes</span>
|
|
568
|
+
</div>
|
|
569
|
+
<div class="rte-source-editor-footer-actions">
|
|
570
|
+
<button class="rte-source-editor-btn rte-source-editor-btn-cancel">Cancel</button>
|
|
571
|
+
<button class="rte-source-editor-btn rte-source-editor-btn-save">Save</button>
|
|
572
|
+
</div>
|
|
573
|
+
`,u.appendChild(g),u.appendChild(m),u.appendChild(w),c.appendChild(u),!document.getElementById("rte-source-editor-styles")){const p=document.createElement("style");p.id="rte-source-editor-styles",p.textContent=ze,document.head.appendChild(p)}document.body.appendChild(c);try{i=Ae(v,{value:o(t),theme:"dark",readOnly:!1,extensions:[new Se,new Pe,new Ie,new Oe,new He,new Ne,new Be]}),i.on("change",()=>{h=((i==null?void 0:i.getValue())||"")!==o(d);const k=w.querySelector(".unsaved-changes");k&&(k.style.display=h?"inline":"none")}),setTimeout(()=>i==null?void 0:i.focus(),100)}catch(p){console.error("Failed to initialize code editor:",p)}const $e=()=>{r=r==="dark"?"light":"dark",i==null||i.setTheme(r);const p=g.querySelector(".theme-toggle-btn");p&&r==="light"&&(p.innerHTML=`
|
|
574
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
575
|
+
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>
|
|
576
|
+
</svg>
|
|
577
|
+
`)},je=()=>{a=!a,i==null||i.setReadOnly(a);const p=g.querySelector(".readonly-toggle-btn");p&&(a?(p.classList.add("active"),p.innerHTML=`
|
|
578
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
579
|
+
<rect x="3" y="11" width="18" height="11" rx="2" ry="2"/>
|
|
580
|
+
<circle cx="12" cy="16" r="1"/>
|
|
581
|
+
<path d="M7 11V7a5 5 0 0 1 10 0v4"/>
|
|
582
|
+
</svg>
|
|
583
|
+
`):(p.classList.remove("active"),p.innerHTML=`
|
|
584
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
585
|
+
<path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/>
|
|
586
|
+
<path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>
|
|
587
|
+
</svg>
|
|
588
|
+
`))},Fe=()=>{l=!l,l?(c.classList.add("fullscreen"),v.style.height="calc(100vh - 200px)"):(c.classList.remove("fullscreen"),v.style.height="400px");const p=g.querySelector(".rte-source-editor-fullscreen-btn");p&&(p.innerHTML=l?`
|
|
589
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
590
|
+
<path d="M8 3v3a2 2 0 0 1-2 2H3m18 0h-3a2 2 0 0 1-2-2V3m0 18v-3a2 2 0 0 0 2-2h3M3 16h3a2 2 0 0 0 2 2v3"/>
|
|
591
|
+
</svg>
|
|
592
|
+
`:`
|
|
593
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
594
|
+
<path d="M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"/>
|
|
595
|
+
</svg>
|
|
596
|
+
`)},M=()=>{i&&(i.destroy(),i=null),document.body.removeChild(c)},qe=()=>{h&&!confirm("You have unsaved changes. Are you sure you want to cancel?")||M()},Ke=()=>{try{const p=(i==null?void 0:i.getValue())||"",k=document.createElement("div");k.innerHTML=p,k.querySelectorAll('script, iframe[src^="javascript:"], object, embed').forEach(Ve=>Ve.remove()),e.innerHTML=k.innerHTML,h=!1,M()}catch(p){alert("Failed to update HTML. Please check your syntax."),console.error("HTML update error:",p)}};(X=g.querySelector(".theme-toggle-btn"))==null||X.addEventListener("click",$e),(Y=g.querySelector(".readonly-toggle-btn"))==null||Y.addEventListener("click",je),(Q=g.querySelector(".rte-source-editor-fullscreen-btn"))==null||Q.addEventListener("click",Fe),(J=g.querySelector(".rte-source-editor-close-btn"))==null||J.addEventListener("click",M),(ee=w.querySelector(".rte-source-editor-btn-cancel"))==null||ee.addEventListener("click",qe),(te=w.querySelector(".rte-source-editor-btn-save"))==null||te.addEventListener("click",Ke),c.addEventListener("click",p=>{p.target===c&&M()});const G=p=>{p.key==="Escape"&&(M(),document.removeEventListener("keydown",G))};document.addEventListener("keydown",G)})(),!0}},keymap:{"Mod-Shift-s":"toggleSourceView","Mod-Shift-S":"toggleSourceView"}})},Symbol.toStringTag,{value:"Module"})),N=()=>(document.execCommand("insertUnorderedList",!1),!0),B=()=>(document.execCommand("insertOrderedList",!1),!0),V=(s,e)=>{var t;typeof window!="undefined"&&((t=window.registerEditorCommand)==null||t.call(window,s,e))},Z=()=>{V("toggleBulletList",N),V("toggleOrderedList",B)};typeof window!="undefined"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",Z):Z());const De=Object.freeze(Object.defineProperty({__proto__:null,ListPlugin:()=>({name:"list",nodes:{bulletList:{content:"listItem+",group:"block",parseDOM:[{tag:"ul"}],toDOM:()=>["ul",0]},orderedList:{content:"listItem+",group:"block",parseDOM:[{tag:"ol"}],toDOM:()=>["ol",0]},listItem:{content:"paragraph",parseDOM:[{tag:"li"}],toDOM:()=>["li",0]}},toolbar:[{label:"Bullet List",command:"toggleBulletList",type:"button",icon:'<svg width="24" height="24" focusable="false"><path d="M11 5h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2Zm0 6h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2Zm0 6h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2ZM4.5 6c0 .4.1.8.4 1 .3.4.7.5 1.1.5.4 0 .8-.1 1-.4.4-.3.5-.7.5-1.1 0-.4-.1-.8-.4-1-.3-.4-.7-.5-1.1-.5-.4 0-.8.1-1 .4-.4.3-.5.7-.5 1.1Zm0 6c0 .4.1.8.4 1 .3.4.7.5 1.1.5.4 0 .8-.1 1-.4.4-.3.5-.7.5-1.1 0-.4-.1-.8-.4-1-.3-.4-.7-.5-1.1-.5-.4 0-.8.1-1 .4-.4.3-.5.7-.5 1.1Zm0 6c0 .4.1.8.4 1 .3.4.7.5 1.1.5.4 0 .8-.1 1-.4.4-.3.5-.7.5-1.1 0-.4-.1-.8-.4-1-.3-.4-.7-.5-1.1-.5-.4 0-.8.1-1 .4-.4.3-.5.7-.5 1.1Z" fill-rule="evenodd"></path></svg>',shortcut:"Mod-Shift-8"},{label:"Numbered List",command:"toggleOrderedList",type:"button",icon:'<svg width="24" height="24" focusable="false"><path d="M10 17h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2Zm0-6h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2Zm0-6h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 1 1 0-2ZM6 4v3.5c0 .3-.2.5-.5.5a.5.5 0 0 1-.5-.5V5h-.5a.5.5 0 0 1 0-1H6Zm-1 8.8l.2.2h1.3c.3 0 .5.2.5.5s-.2.5-.5.5H4.9a1 1 0 0 1-.9-1V13c0-.4.3-.8.6-1l1.2-.4.2-.3a.2.2 0 0 0 0-.2l-.7.3a.5.5 0 0 1-.7-.3.5.5 0 0 1 .3-.6l.7-.4c.5-.2 1.1 0 1.4.4.3.5.3 1.1-.1 1.5l-1.2.7Zm0 3.7v.5c0 .3.2.5.5.5h1c.3 0 .5.2.5.5s-.2.5-.5.5h-1a1.5 1.5 0 0 1-1.5-1.5v-.5c0-.3.1-.6.3-.8l1.3-1.4c.3-.4.1-.9-.2-1-.1 0-.2 0-.3.2l-.4.5a.5.5 0 0 1-.7.1.5.5 0 0 1-.1-.7l.4-.5c.5-.5 1.2-.6 1.8-.4.6.3 1 .9 1 1.6 0 .4-.2.8-.5 1.1l-1.3 1.4-.3.4Z" fill-rule="evenodd"></path></svg>',shortcut:"Mod-Shift-7"}],commands:{toggleBulletList:N,toggleOrderedList:B},keymap:{"Mod-Shift-8":"toggleBulletList","Mod-Shift-7":"toggleOrderedList"}}),toggleBulletList:N,toggleOrderedList:B},Symbol.toStringTag,{value:"Module"})),E=[],L=[],S={},x=(s,e)=>{S[s]=e,typeof window!="undefined"&&(window.registerEditorCommand||(window.registerEditorCommand=(t,o)=>{S[t]=o}),window.registerEditorCommand(s,e))},_e=(s,...e)=>{S[s]&&S[s](...e)},A=()=>(document.execCommand("undo",!1),!0),z=()=>(document.execCommand("redo",!1),!0),R=(s,e,t)=>{const o=s.getAttribute(e);s.setAttribute(e,t),E.push(()=>{o==null?s.removeAttribute(e):s.setAttribute(e,o)}),L.length=0},D=(s,e)=>{const t=s.textContent;s.textContent=e,E.push(()=>{s.textContent=t!=null?t:""}),L.length=0},_=s=>{var n;const e=s.element;if(!e)return;const t=(n=window.a11yRuleRegistry)==null?void 0:n.find(i=>i.id===s.rule);let o=null;if(t&&t.fix){const i={};for(const r of e.getAttributeNames())i[r]=e.getAttribute(r);t.fix(s),o=()=>{for(const r of Object.keys(i))i[r]==null?e.removeAttribute(r):e.setAttribute(r,i[r])}}o&&E.push(o),L.length=0},U=()=>{const s=E.pop();s&&(s(),L.push(s))},$=()=>{const s=L.pop();s&&(s(),E.push(s))},W=()=>{typeof window!="undefined"&&(window.execEditorCommand||(window.execEditorCommand=_e),x("undo",A),x("redo",z),x("setAttribute",R),x("setText",D),x("autoFixA11y",_),x("undoDom",U),x("redoDom",$))};typeof window!="undefined"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",W):W());const Ue=Object.freeze(Object.defineProperty({__proto__:null,HistoryPlugin:()=>({name:"history",toolbar:[{label:"Undo",command:"undo",type:"button",icon:'<svg width="24" height="24" focusable="false"><path d="M6.4 8H12c3.7 0 6.2 2 6.8 5.1.6 2.7-.4 5.6-2.3 6.8a1 1 0 0 1-1-1.8c1.1-.6 1.8-2.7 1.4-4.6-.5-2.1-2.1-3.5-4.9-3.5H6.4l3.3 3.3a1 1 0 1 1-1.4 1.4l-5-5a1 1 0 0 1 0-1.4l5-5a1 1 0 0 1 1.4 1.4L6.4 8Z" fill-rule="nonzero"></path></svg>',shortcut:"Mod-z"},{label:"Redo",command:"redo",type:"button",icon:'<svg width="24" height="24" focusable="false"><path d="M17.6 10H12c-2.8 0-4.4 1.4-4.9 3.5-.4 2 .3 4 1.4 4.6a1 1 0 1 1-1 1.8c-2-1.2-2.9-4.1-2.3-6.8.6-3 3-5.1 6.8-5.1h5.6l-3.3-3.3a1 1 0 1 1 1.4-1.4l5 5a1 1 0 0 1 0 1.4l-5 5a1 1 0 0 1-1.4-1.4l3.3-3.3Z" fill-rule="nonzero"></path></svg>',shortcut:"Mod-y"}],commands:{undo:A,redo:z,setAttribute:R,setText:D,autoFixA11y:_,undoDom:U,redoDom:$},keymap:{"Mod-z":"undo","Mod-Z":"undo","Mod-y":"redo","Mod-Y":"redo","Mod-Shift-z":"redo","Mod-Shift-Z":"redo"}}),autoFixA11y:_,redo:z,redoDom:$,setAttribute:R,setText:D,undo:A,undoDom:U},Symbol.toStringTag,{value:"Module"}));y.initWebComponent=q,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})}));
|
|
597
|
+
//# sourceMappingURL=webcomponent-core.min.js.map
|