@oix1987/yjd 2.1.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).yjd=e()}(this,function(){"use strict";const t=new class{constructor(){this.modules=new Map,this.formats=new Map,this.themes=new Map,this.ui=new Map}register(t,e,i=!1){if("object"==typeof t)return void Object.entries(t).forEach(([t,e])=>{this.register(t,e,i)});const[o,n]=t.split("/");if(!i){this.get(t)}switch(o){case"modules":this.modules.set(n,e);break;case"formats":this.formats.set(n,e);break;case"themes":this.themes.set(n,e);break;case"ui":this.ui.set(n,e)}}get(t){const[e,i]=t.split("/");switch(e){case"modules":return this.modules.get(i);case"formats":return this.formats.get(i);case"themes":return this.themes.get(i);case"ui":return this.ui.get(i);default:return null}}has(t){return null!==this.get(t)&&void 0!==this.get(t)}getAll(t){switch(t){case"modules":return new Map(this.modules);case"formats":return new Map(this.formats);case"themes":return new Map(this.themes);case"ui":return new Map(this.ui);default:return new Map}}unregister(t){const[e,i]=t.split("/");switch(e){case"modules":this.modules.delete(i);break;case"formats":this.formats.delete(i);break;case"themes":this.themes.delete(i);break;case"ui":this.ui.delete(i)}}clear(){this.modules.clear(),this.formats.clear(),this.themes.clear(),this.ui.clear()}getAllItems(){const t={};return t.modules=Array.from(this.modules.keys()),t.formats=Array.from(this.formats.keys()),t.themes=Array.from(this.themes.keys()),t.ui=Array.from(this.ui.keys()),t}};class e{static DEFAULTS={};constructor(t,e={}){this.editor=t,this.options={...this.constructor.DEFAULTS,...e},this.events=new Map}on(t,e){this.events.has(t)||this.events.set(t,[]),this.events.get(t).push(e)}off(t,e){if(this.events.has(t)){const i=this.events.get(t),o=i.indexOf(e);o>-1&&i.splice(o,1)}}emit(t,e){this.events.has(t)&&this.events.get(t).forEach(t=>{try{t(e)}catch(t){}})}destroy(){this.events.clear()}onContentChange(){}onSelectionChange(t){}}function i(t,e=null){try{return null==e?document.execCommand(t,!1):document.execCommand(t,!1,e)}catch(t){return!1}}function o(t=!0){return i("styleWithCSS",t)}function n(t){try{return document.queryCommandState(t)}catch(t){return!1}}const r=["http:","https:","mailto:","tel:","ftp:"],s=["https://www.youtube.com/embed/","https://www.youtube-nocookie.com/embed/","https://player.vimeo.com/video/"];function a(t,{allowDataImage:e=!1}={}){if("string"!=typeof t)return!1;const i=t.trim();if(""===i)return!1;const o=i.replace(/[\u0000-\u0020\u007F-\u009F]/g,""),n=o.match(/^([a-z][a-z0-9+.-]*):/i);if(!n)return!0;const s=n[1].toLowerCase()+":";return"data:"===s?!!e&&(/^data:image\//i.test(o)&&!/^data:image\/svg/i.test(o)):r.includes(s)}const l=new Set(["SCRIPT","STYLE","OBJECT","EMBED","LINK","META","BASE","FORM","INPUT","BUTTON","TEXTAREA","SELECT","OPTION","NOSCRIPT"]);function c(t){const e=Array.from(t.attributes);for(const i of e){const e=i.name.toLowerCase(),o=i.value;if(e.startsWith("on"))t.removeAttribute(i.name);else{if("href"===e||"src"===e||"xlink:href"===e){a(o,{allowDataImage:"IMG"===t.tagName})||t.removeAttribute(i.name);continue}"style"===e&&/expression\s*\(|javascript:/i.test(o)&&t.removeAttribute(i.name)}}}function d(t){if("string"!=typeof t||""===t)return"";const e=(new DOMParser).parseFromString(t,"text/html"),i=Array.from(e.body.querySelectorAll("*"));for(const t of i){const e=t.tagName;if(l.has(e))t.remove();else{if("IFRAME"===e){const e=t.getAttribute("src")||"";if(!s.some(t=>e.startsWith(t))){t.remove();continue}}c(t)}}return e.body.innerHTML}function h(t){const e=document.createElement("div");return e.innerHTML=t||"",p(e,0).replace(/\n{3,}/g,"\n\n").trim()+"\n"}function p(t,e){let i="";return t.childNodes.forEach(t=>{i+=function(t,e){if(3===t.nodeType){const e=t.textContent.replace(/\s+/g," ");return e.trim()?e+"\n\n":""}if(1!==t.nodeType)return"";const i=t.tagName;switch(i){case"H1":case"H2":case"H3":case"H4":case"H5":case"H6":return"#".repeat(+i[1])+" "+g(t)+"\n\n";case"P":case"DIV":{const e=g(t);return e.trim()?e+"\n\n":""}case"BLOCKQUOTE":return g(t).split("\n").map(t=>"> "+t).join("\n")+"\n\n";case"PRE":return"```\n"+t.textContent.replace(/\n$/,"")+"\n```\n\n";case"UL":return u(t,e,!1)+"\n";case"OL":return u(t,e,!0)+"\n";case"HR":return"---\n\n";case"TABLE":return function(t){const e=[...t.querySelectorAll("tr")];if(!e.length)return"";const i=t=>[...t.children].map(t=>g(t).replace(/\|/g,"\\|").trim()),o=i(e[0]);let n="| "+o.join(" | ")+" |\n| "+o.map(()=>"---").join(" | ")+" |\n";return e.slice(1).forEach(t=>{n+="| "+i(t).join(" | ")+" |\n"}),n}(t)+"\n";case"FIGURE":return p(t,e);case"IMG":return m(t)+"\n\n";case"BR":return"\n";default:return g(t)+"\n\n"}}(t,e)}),i}function u(t,e,i){let o="",n=1;return t.childNodes.forEach(t=>{if(1!==t.nodeType||"LI"!==t.tagName)return;const r=i?n+++". ":"- ",s=" ".repeat(e);let a="",l="";t.childNodes.forEach(t=>{1!==t.nodeType||"UL"!==t.tagName&&"OL"!==t.tagName?a+=f(t):l+=u(t,e+1,"OL"===t.tagName)}),o+=s+r+a.trim()+"\n"+l}),o}function m(t){return`![${t.getAttribute("alt")||""}](${t.getAttribute("src")||""})`}function g(t){let e="";return t.childNodes.forEach(t=>{e+=f(t)}),e}function f(t){if(3===t.nodeType)return t.textContent;if(1!==t.nodeType)return"";const e=t.tagName;if(t.classList&&t.classList.contains("mention")){const e=t.getAttribute("data-id")||"",i=(t.textContent||"").replace(/^[@#]/,"");return`${(t.textContent||"@")[0]}[${i}](${e})`}switch(e){case"B":case"STRONG":return"**"+g(t)+"**";case"I":case"EM":return"*"+g(t)+"*";case"S":case"STRIKE":case"DEL":return"~~"+g(t)+"~~";case"U":return"<u>"+g(t)+"</u>";case"CODE":return"`"+t.textContent+"`";case"A":return"["+g(t)+"]("+(t.getAttribute("href")||"")+")";case"IMG":return m(t);case"BR":return" \n";default:return g(t)}}function y(t){const e=(t||"").replace(/\r\n/g,"\n").split("\n");let i="",o=0;const n=t=>/^\s*([-*+]|\d+\.)\s+/.test(t);for(;o<e.length;){const t=e[o];if(/^\s*$/.test(t)){o++;continue}if(/^---+$/.test(t.trim())){i+="<hr>",o++;continue}const r=t.match(/^(#{1,6})\s+(.*)$/);if(r){i+=`<h${r[1].length}>${C(r[2])}</h${r[1].length}>`,o++;continue}if(/^```/.test(t)){o++;let t="";for(;o<e.length&&!/^```/.test(e[o]);)t+=e[o]+"\n",o++;o++,i+="<pre>"+w(t.replace(/\n$/,""))+"</pre>";continue}if(/^>\s?/.test(t)){const t=[];for(;o<e.length&&/^>\s?/.test(e[o]);)t.push(e[o].replace(/^>\s?/,"")),o++;i+="<blockquote>"+C(t.join(" "))+"</blockquote>";continue}if(/^\|.*\|\s*$/.test(t)&&o+1<e.length&&/^\|[\s:|-]+\|\s*$/.test(e[o+1])){const t=x(e,o);i+=t.html,o=t.next;continue}if(n(t)){const t=v(e,o,0);i+=t.html,o=t.next;continue}const s=[t];for(o++;o<e.length&&!/^\s*$/.test(e[o])&&!/^(#{1,6}\s|>|```)/.test(e[o])&&!/^---+$/.test(e[o].trim())&&!n(e[o]);)s.push(e[o]),o++;i+="<p>"+C(s.join("\n").trim())+"</p>"}return i}function b(t){return(t.match(/^(\s*)/)[1]||"").length}function v(t,e,i){const o=/^\s*\d+\./.test(t[e]);let n=e,r="<"+(o?"ol":"ul")+">";for(;n<t.length;){const e=t[n];if(/^\s*$/.test(e)){n++;continue}const o=b(e),s=e.match(/^\s*([-*+]|\d+\.)\s+(.*)$/);if(!s||o<i)break;if(o>i){const e=v(t,n,o);r=r.replace(/<\/li>$/,e.html+"</li>"),n=e.next;continue}r+="<li>"+C(s[2])+"</li>",n++}return{html:r+"</"+(o?"ol":"ul")+">",next:n}}function x(t,e){const i=t=>t.trim().replace(/^\||\|$/g,"").split("|").map(t=>t.trim()),o=i(t[e]);let n=e+2,r="";for(;n<t.length&&/^\|.*\|\s*$/.test(t[n]);)r+="<tr>"+i(t[n]).map(t=>`<td>${C(t)}</td>`).join("")+"</tr>",n++;return{html:`<table class="rich-editor-table"><tbody>${"<tr>"+o.map(t=>`<td><b>${C(t)}</b></td>`).join("")+"</tr>"}${r}</tbody></table>`,next:n}}function C(t){return t.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,(t,e,i)=>`<img class="inserted-image" src="${E(i)}" alt="${E(e)}" style="max-width:100%;height:auto">`).replace(/([@#])\[([^\]]+)\]\(([^)]+)\)/g,(t,e,i,o)=>`<span class="mention" data-id="${E(o)}">${e}${w(i)}</span>`).replace(/\[([^\]]+)\]\(([^)]+)\)/g,(t,e,i)=>`<a href="${E(i)}" target="_blank" rel="noopener noreferrer">${w(e)}</a>`).replace(/\*\*([^*]+)\*\*/g,"<b>$1</b>").replace(/(^|[^*])\*([^*]+)\*/g,"$1<i>$2</i>").replace(/~~([^~]+)~~/g,"<s>$1</s>").replace(/`([^`]+)`/g,(t,e)=>"<code>"+w(e)+"</code>").replace(/\n/g,"<br>")}function w(t){return String(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function E(t){return String(t).replace(/"/g,"&quot;").replace(/</g,"&lt;")}function k(t){const e=document.createElement("div");return e.innerHTML=t||"",{type:"doc",content:[...e.childNodes].map(j).filter(Boolean)}}function j(t){if(3===t.nodeType){const e=t.textContent;return e?{text:e}:null}if(1!==t.nodeType)return null;const e={tag:t.tagName.toLowerCase()};if(t.attributes.length){e.attrs={};for(const i of t.attributes)e.attrs[i.name]=i.value}const i=[...t.childNodes].map(j).filter(Boolean);return i.length&&(e.content=i),e}function T(t){return(t&&t.content?t.content:Array.isArray(t)?t:[]).map(I).join("")}function I(t){if(null==t)return"";if(null!=t.text)return w(t.text);if(!t.tag)return"";const e=t.attrs?Object.entries(t.attrs).map(([t,e])=>` ${t}="${E(e)}"`).join(""):"",i=(t.content||[]).map(I).join("");return new Set(["img","hr","br","input"]).has(t.tag)?`<${t.tag}${e}>`:`<${t.tag}${e}>${i}</${t.tag}>`}class S{static DEFAULTS={placeholder:"Start typing...",theme:"light",height:400,width:800,maxWidth:1200,maxHeight:800,content:null,features:{emoji:!0,image:!0,table:!0,wordCount:!0,breadcrumb:!0}};static currentInstance=null;static instances=new Map;constructor(e,i={}){this.options={...S.DEFAULTS,...i,features:{...S.DEFAULTS.features,...i.features||{}}},this.root="string"==typeof e?document.querySelector(e):e,this.modules=new Map,this.formats=new Map,this.registry=t,this.events=new Map,this.toolbarBtns={},this.statusbarEls={},this.dropdownMenus={},this.popupInstances=new Map,S.currentInstance=this;const o=this.generateInstanceId();this.instanceId=o,S.instances.set(o,this),this.init()}generateInstanceId(){return"editor_"+Date.now()+"_"+Math.random().toString(36).substr(2,9)}init(){this.createStructure(),this.loadModules(),this.loadFormats(),this.setupEventListeners(),this.updateStatusbar()}createStructure(){this.wrapper=document.createElement("div"),this.wrapper.className="yjd-rich-editor";const t=t=>"number"==typeof t?t+"px":t;this.wrapper.style.width=t(this.options.width),this.wrapper.style.maxWidth=t(this.options.maxWidth),this.wrapper.style.minHeight=t(this.options.height),this.wrapper.style.maxHeight=t(this.options.maxHeight),this.wrapper.style.position="relative",this.editor=document.createElement("div"),this.editor.className="rich-editor-area",this.editor.contentEditable=!0,this.editor.setAttribute("data-placeholder",this.options.placeholder),this.editor.setAttribute("role","textbox"),this.editor.setAttribute("aria-multiline","true"),this.editor.setAttribute("aria-label",this.options.ariaLabel||this.options.placeholder||"Rich text editor"),this.options.direction&&this.editor.setAttribute("dir","rtl"===this.options.direction?"rtl":"ltr"),i("defaultParagraphSeparator","p"),this.editor.innerHTML=this.getDefaultContent(),this.wrapper.appendChild(this.editor),this.popupContainer=document.createElement("div"),this.popupContainer.className="rich-editor-popup-container",this.popupContainer.style.position="absolute",this.popupContainer.style.top="0",this.popupContainer.style.left="0",this.popupContainer.style.width="100%",this.popupContainer.style.height="100%",this.popupContainer.style.pointerEvents="none",this.popupContainer.style.zIndex="1000",this.wrapper.appendChild(this.popupContainer),(this.options.features.wordCount||this.options.features.breadcrumb)&&this.createStatusbar(),this.root.appendChild(this.wrapper),this.updatePlaceholderVisibility()}isHtmlContent(t){if(!t||"string"!=typeof t)return!1;const e=t.trim();return[/<[^>]+>/,/&[a-zA-Z]+;/,/&#\d+;/].some(t=>t.test(e))}wrapTextInParagraph(t){if(!t||"string"!=typeof t)return"<p><br></p>";const e=t.trim();return this.isHtmlContent(e)?e:""===e?"<p><br></p>":`<p>${e}</p>`}getDefaultContent(){if(this.options.content)return this.wrapTextInParagraph(this.options.content);const t=this._getAutosaved();return null!=t&&""!==t?t:""}createStatusbar(){this.statusbar=document.createElement("div"),this.statusbar.className="rich-editor-statusbar",this.statusbarEls.breadcrumb=document.createElement("span"),this.statusbarEls.breadcrumb.className="rich-editor-breadcrumb",this.statusbarEls.wordcount=document.createElement("span"),this.statusbarEls.wordcount.className="wordcount",this.statusbar.appendChild(this.statusbarEls.breadcrumb),this.statusbar.appendChild(this.statusbarEls.wordcount),this.wrapper.appendChild(this.statusbar)}loadModules(){let t;t=this.options.toolbar||this.options.toolbar1||this.options.toolbar2?this.options.modules||["toolbar","history"]:this.options.modules||["toolbar","history","block-toolbar","table-toolbar","code-view","theme-switcher","resize-handles","find-replace","slash-menu","mention"],this.options.mention&&!t.includes("mention")&&t.push("mention"),t.forEach(t=>{const e=this.registry.get(`modules/${t}`);if(e){const i=new e(this,"toolbar"===t?this.options:this.options[t]||this.options);if(this.modules.set(t,i),"toolbar"===t&&i.getContainer){const t=i.getContainer();this.wrapper.insertBefore(t,this.editor),i.on("toolbar-click",t=>{this.handleToolbarClick(t)})}}})}loadFormats(){let t;t=this.options.toolbar||this.options.toolbar1||this.options.toolbar2?this.options.formats||["bold","italic","underline","strike"]:this.options.formats||["bold","italic","underline","strike","subscript","superscript","color","background","text-align","text-size","link","code","h1","h2","h3","h4","h5","h6","paragraph","pre"],t.forEach(t=>{const e=this.registry.get(`formats/${t}`);e&&this.formats.set(t,e)})}setupEventListeners(){this._markActive=()=>{S.currentInstance=this},this.wrapper.addEventListener("pointerdown",this._markActive,!0),this.wrapper.addEventListener("focusin",this._markActive,!0),this.editor.addEventListener("input",()=>{this.updatePlaceholderVisibility(),this.onContentChange()}),this._onDocSelectionChange=()=>{(document.activeElement===this.editor||this.editor.contains(document.activeElement))&&this._scheduleSelectionUpdate()},document.addEventListener("selectionchange",this._onDocSelectionChange),this.editor.addEventListener("mouseup",()=>this._scheduleSelectionUpdate()),this.editor.addEventListener("click",()=>{this.ensureEditorHasContent()}),this.editor.addEventListener("contextmenu",t=>{}),this.editor.addEventListener("keydown",t=>{if(!t.ctrlKey&&!t.metaKey||t.altKey)return;const e={b:"bold",i:"italic",u:"underline",k:"link"}[t.key.toLowerCase()];e&&(t.shiftKey||(t.preventDefault(),this.toggleFormat(e)))}),this.editor.addEventListener("keydown",t=>{"Delete"!==t.key&&"Backspace"!==t.key||setTimeout(()=>{this.ensureEditorHasContent(),this.updatePlaceholderVisibility()},0)}),this.editor.addEventListener("paste",t=>{this.handlePaste(t)}),this.editor.addEventListener("dragover",t=>{t.dataTransfer&&Array.from(t.dataTransfer.types||[]).includes("Files")&&t.preventDefault()}),this.editor.addEventListener("drop",t=>{const e=t.dataTransfer,i=(e&&e.files?Array.from(e.files):[]).find(t=>t.type&&t.type.startsWith("image/"));if(i)return t.preventDefault(),this.placeCaretAtPoint(t.clientX,t.clientY),void this.insertImageFile(i);setTimeout(()=>{this.ensureEditorHasContent(),this.updatePlaceholderVisibility()},0)}),this.options.maxLength&&this.editor.addEventListener("beforeinput",t=>{if(!t.inputType||!t.inputType.startsWith("insert"))return;if("insertFromPaste"===t.inputType)return;const e=t.data?t.data.length:1;this._remainingChars()<e&&t.preventDefault()}),!1!==this.options.markdown&&this.editor.addEventListener("keydown",t=>{" "!==t.key||t.ctrlKey||t.metaKey||t.altKey||this.handleMarkdownShortcut(t)}),this.editor.addEventListener("cut",()=>{setTimeout(()=>{this.ensureEditorHasContent(),this.updatePlaceholderVisibility()},0)}),setTimeout(()=>{this.ensureEditorHasContent(),this.updatePlaceholderVisibility(),this.updateHistoryButtons(),this.focus()},100),this.editor.addEventListener("focus",()=>{setTimeout(()=>{this.ensureEditorHasContent(),this.updatePlaceholderVisibility()},0)})}onContentChange(){this.ensureEditorHasContent(),this._emitChange()}_emitChange(){this.modules.forEach(t=>{"function"==typeof t.onContentChange&&t.onContentChange()}),this.updateStatusbar();const t=this.getContent();this.options.onChange&&"function"==typeof this.options.onChange&&this.options.onChange(t),this._scheduleAutosave(t),this.emit("change",t),this.emit("text-change",t)}ensureEditorHasContent(){if(!this.isEditorEmpty())return;const t=this.isSelectionInEditableArea(window.getSelection());if("<p><br></p>"!==this.editor.innerHTML){const t=document.createElement("p");t.innerHTML="<br>",this.editor.innerHTML="",this.editor.appendChild(t),this.setCursorToElement(t),this.editor.focus()}(t||document.activeElement===this.editor)&&this._clearStickyInlineFormats(),this.updateToolbarButtonStates(),this.updateStatusbar()}_clearStickyInlineFormats(){["bold","italic","underline","strikeThrough"].forEach(t=>{n(t)&&i(t)})}ensureParagraphForEditing(){const t=this.editor.children;if(0===t.length){const t=document.createElement("p");return t.innerHTML="<br>",this.editor.appendChild(t),void this.setCursorToElement(t)}const e=t[t.length-1];if(!["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","PRE","ARTICLE","SECTION","MAIN","ASIDE"].includes(e.tagName)){const t=document.createElement("p");t.innerHTML="<br>",this.editor.appendChild(t)}}isEditorEmpty(){const t=this.editor.textContent;return(!t||""===t.replace(/\u200B/g,"").trim())&&!this.editor.querySelector("img, table, hr, video, iframe, audio, figure")}setCursorToElement(t){const e=document.createRange(),i=window.getSelection();t.firstChild&&t.firstChild.nodeType===Node.TEXT_NODE?e.setStart(t.firstChild,0):e.setStart(t,0),e.collapse(!0),i.removeAllRanges(),i.addRange(e)}_scheduleSelectionUpdate(){this._selUpdateQueued||(this._selUpdateQueued=!0,requestAnimationFrame(()=>{this._selUpdateQueued=!1,this.onSelectionChange()}))}onSelectionChange(){const t=window.getSelection(),e=t.rangeCount>0?t.getRangeAt(0):null,i=this.isSelectionInEditableArea(t);i&&(S.currentInstance=this,e&&!e.collapsed&&(this._lastRange=e.cloneRange())),this.modules.forEach(t=>{"function"==typeof t.onSelectionChange&&t.onSelectionChange(e,i)}),this.updateToolbarButtonStates(),this.updateToolbarAccessibility(i),this.updateStatusbar()}isSelectionInEditableArea(t){if(!t||0===t.rangeCount)return!1;const e=t.getRangeAt(0),i=e.startContainer,o=e.endContainer,n=this.isNodeInEditableArea(i),r=this.isNodeInEditableArea(o);return n&&r}isNodeInEditableArea(t){if(!t)return!1;let e=t.nodeType===Node.TEXT_NODE?t.parentNode:t;for(;e&&e!==document.body;){if(e===this.editor||e.classList&&e.classList.contains("rich-editor-area"))return!0;e=e.parentNode}return!1}updateToolbarAccessibility(t){const e=this.getModule("toolbar");if(!e)return;["bold","italic","underline","strike","subscript","superscript","color","background","link","table","heading","font-family","line-height","capitalization","text-align","list","indent-increase","indent-decrease","text-size"].forEach(i=>{e.setButtonDisabled(i,!t)});["more","undo","redo","code-view","theme"].forEach(t=>{e.setButtonDisabled(t,!1)})}updateStatusbar(){if(!this.statusbar)return;const t=window.getSelection();if(t){if(this.statusbarEls.breadcrumb&&this.options.features.breadcrumb){const e=t.anchorNode;if(e&&this.editor.contains(e)){const t=[];let i=3===e?.nodeType?e.parentElement:e;for(;i&&i!==this.editor&&i!==document.body;){if(i.tagName){let e=i.tagName.toLowerCase();if(i.className&&"string"==typeof i.className){const t=i.className.trim();t&&(e+="."+t.split(" ").join("."))}i.id&&(e+="#"+i.id),t.unshift(e)}i=i.parentElement}this.statusbarEls.breadcrumb.textContent=t.length>0?t.join(" > "):"editor"}else this.statusbarEls.breadcrumb.textContent="editor"}if(this.statusbarEls.wordcount&&this.options.features.wordCount){let t;const e=this.getModule("code-view");if(e&&"function"==typeof e.isInCodeView&&e.isInCodeView()){const i=document.createElement("div");i.innerHTML=e.getCurrentContent?e.getCurrentContent():"",t=i.textContent||""}else t=this.editor.textContent||"";const i=t.trim()?t.trim().split(/\s+/).length:0,o=t.length;let n=`${i} words, ${o} chars (${t.replace(/\s/g,"").length} no spaces)`;this.options.maxLength&&(n+=` • ${Math.max(0,this.options.maxLength-o)} left`),this.statusbarEls.wordcount.textContent=n}}}focus(){this.editor&&this.editor.focus()}getContent(){return this.editor.innerHTML}setContent(t){const e=this.wrapTextInParagraph(t);this.editor.innerHTML=e,this.onContentChange()}getHTML(){return this.getContent()}setHTML(t){this.setContent(d(t||""))}getJSON(){return k(this.getContent())}setJSON(t){this.setContent(d(T(t)))}getMarkdown(){return h(this.getContent())}setMarkdown(t){this.setContent(d(y(t||"")))}getText(){return this.editor.textContent||""}isEmpty(){return this.isEditorEmpty()}clear(){this.editor.innerHTML="<p><br></p>",this.onContentChange(),this.updatePlaceholderVisibility()}insertText(t){"string"==typeof t&&(this.focus(),i("insertText",t),this.onContentChange())}insertHTML(t){"string"==typeof t&&(this.focus(),i("insertHTML",d(t)),this.onContentChange())}handlePaste(t){const e=t.clipboardData||window.clipboardData;if(!e)return;const o=(e.items?Array.from(e.items):[]).find(t=>"file"===t.kind&&t.type&&t.type.startsWith("image/"));if(o){const e=o.getAsFile();if(e)return t.preventDefault(),void this.insertImageFile(e)}let n=e.getData("text/html"),r=e.getData("text/plain");if(n||r){if(t.preventDefault(),this.options.maxLength){const t=this._remainingChars();if(t<=0)return;i("insertText",(r||"").slice(0,t))}else!this.options.pasteAsPlainText&&n?i("insertHTML",d(n)):r&&i("insertText",r);setTimeout(()=>{this.ensureEditorHasContent(),this.updatePlaceholderVisibility(),this.onContentChange()},0)}}_remainingChars(){if(!this.options.maxLength)return 1/0;const t=window.getSelection(),e=t&&!t.isCollapsed?t.toString().length:0;return this.options.maxLength-(this.getText().length-e)}insertImageFile(t){if(!t||!t.type||!t.type.startsWith("image/"))return;const e=this.options.image||{};if(e.accept&&"image/*"!==e.accept){if(!e.accept.split(",").some(e=>(e=e.trim()).endsWith("/*")?t.type.startsWith(e.slice(0,-1)):t.type===e))return void this.emit("image:error",{file:t,reason:"type"})}if(e.maxSize&&t.size>e.maxSize)return void this.emit("image:error",{file:t,reason:"size"});const o=(t,e="")=>{const i=this.registry.get("formats/image");if(i&&"function"==typeof i.create){const o=i.create(t);return o?(e&&o.setAttribute("data-state",e),o):null}return null};if("function"!=typeof e.upload){const e=new FileReader;return e.onload=t=>{const e=(o(t.target.result)||{}).outerHTML||`<img src="${t.target.result}" class="inserted-image" style="max-width:100%" contenteditable="false">`;this.focus(),i("insertHTML",e),this.onContentChange()},void e.readAsDataURL(t)}const n="rte-up-"+Math.round(performance.now())+"-"+(this._upCounter=(this._upCounter||0)+1),r=o("data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 width=%27120%27 height=%2790%27%3E%3Crect width=%27100%25%27 height=%27100%25%27 fill=%27%23efedff%27/%3E%3C/svg%3E","uploading");r&&(r.id=n,r.style.opacity="0.6",this.focus(),i("insertHTML",r.outerHTML),this.emit("image:upload",{file:t}),Promise.resolve(e.upload(t)).then(e=>{const i=this.editor.querySelector("#"+n);i&&(e?(i.src=e,i.style.opacity="",i.removeAttribute("data-state"),i.removeAttribute("id"),this.emit("image:uploaded",{file:t,url:e})):i.remove(),this.onContentChange())}).catch(e=>{const i=this.editor.querySelector("#"+n);i&&i.remove(),this.emit("image:error",{file:t,reason:"upload",error:e}),this.onContentChange()}))}placeCaretAtPoint(t,e){let i=null;if(document.caretRangeFromPoint)i=document.caretRangeFromPoint(t,e);else if(document.caretPositionFromPoint){const o=document.caretPositionFromPoint(t,e);o&&(i=document.createRange(),i.setStart(o.offsetNode,o.offset))}if(i){i.collapse(!0);const t=window.getSelection();t.removeAllRanges(),t.addRange(i)}}handleMarkdownShortcut(t){const e=window.getSelection();if(!e||!e.isCollapsed||!e.rangeCount)return;const o=e.getRangeAt(0);let n=o.startContainer;for(n=n.nodeType===Node.TEXT_NODE?n.parentElement:n;n&&n!==this.editor&&"P"!==n.tagName&&"DIV"!==n.tagName;)n=n.parentElement;if(!n||n===this.editor)return;const r=document.createRange();r.selectNodeContents(n),r.setEnd(o.startContainer,o.startOffset);const s=r.toString(),a={"#":"h1","##":"h2","###":"h3","####":"h4","#####":"h5","######":"h6",">":"blockquote"}[s],l="-"===s||"*"===s?"ul":/^\d+\.$/.test(s)?"ol":null;if(!a&&!l)return;t.preventDefault();const c=this.getModule("history");if(c&&"function"==typeof c.saveBeforeFormat&&c.saveBeforeFormat(),r.deleteContents(),a){const t=document.createElement(a);for(;n.firstChild;)t.appendChild(n.firstChild);""!==t.textContent||t.querySelector("*")||(t.innerHTML="<br>"),n.replaceWith(t);const i=document.createRange();i.selectNodeContents(t),i.collapse(!0),e.removeAllRanges(),e.addRange(i)}else{const t=document.createRange();t.selectNodeContents(n),t.collapse(!0),e.removeAllRanges(),e.addRange(t),i("ul"===l?"insertUnorderedList":"insertOrderedList")}this._emitChange(),this.updatePlaceholderVisibility()}setDirection(t){const e="rtl"===t?"rtl":"ltr";this.editor.setAttribute("dir",e);const i=this.getModule("toolbar");i&&i.setButtonActive("text-direction","rtl"===e)}getDirection(){return"rtl"===this.editor.getAttribute("dir")?"rtl":"ltr"}toggleDirection(){this.setDirection("rtl"===this.getDirection()?"ltr":"rtl")}_autosaveCfg(){if(void 0!==this._autosaveMemo)return this._autosaveMemo;const t=this.options.autosave;return t?(this._autosaveMemo={key:"object"==typeof t&&t.key?t.key:"yjd-autosave",debounce:"object"==typeof t&&t.debounce?t.debounce:1e3},this._autosaveMemo):(this._autosaveMemo=null,null)}_getAutosaved(){const t=this._autosaveCfg();if(!t)return null;try{return localStorage.getItem(t.key)}catch(t){return null}}_scheduleAutosave(t){const e=this._autosaveCfg();e&&(clearTimeout(this._autosaveTimer),this._autosaveTimer=setTimeout(()=>{try{localStorage.setItem(e.key,t)}catch(t){}},e.debounce))}clearAutosave(){const t=this._autosaveCfg();if(t)try{localStorage.removeItem(t.key)}catch(t){}}clearFormatting(){const t=this.getModule("history");t&&"function"==typeof t.saveBeforeFormat&&t.saveBeforeFormat(),this.focus(),i("removeFormat"),i("unlink"),this.onContentChange(),this.updateToolbarButtonStates()}setBlockType(t){const e=window.getSelection();if(!e||!e.rangeCount)return;let o=e.getRangeAt(0).startContainer;o=o.nodeType===Node.TEXT_NODE?o.parentElement:o;const n=/^(P|DIV|H[1-6]|BLOCKQUOTE|PRE|LI)$/;for(;o&&o!==this.editor&&!n.test(o.tagName);)o=o.parentElement;if(!o||o===this.editor)return;const r=this.getModule("history");if(r&&"function"==typeof r.saveBeforeFormat&&r.saveBeforeFormat(),"ul"===t||"ol"===t){const n=document.createRange();n.selectNodeContents(o),n.collapse(!0),e.removeAllRanges(),e.addRange(n),i("ul"===t?"insertUnorderedList":"insertOrderedList")}else{const i=document.createElement(t);for(;o.firstChild;)i.appendChild(o.firstChild);""!==i.textContent||i.querySelector("*")||(i.innerHTML="<br>"),o.replaceWith(i);const n=document.createRange();n.selectNodeContents(i),n.collapse(!1),e.removeAllRanges(),e.addRange(n)}this._emitChange(),this.updatePlaceholderVisibility()}insertHorizontalRule(){const t=this.getModule("history");t&&"function"==typeof t.saveBeforeFormat&&t.saveBeforeFormat(),this.focus(),i("insertHorizontalRule"),this.onContentChange()}_isBlockEmpty(t){return!t||(!t.querySelector||!t.querySelector("img, table, hr, video, iframe, audio, figure"))&&""===(t.textContent||"").replace(/\u200B/g,"").trim()}insertBlock(t){const e=window.getSelection();let i=null;if(e&&e.rangeCount){const t=e.getRangeAt(0);t.collapsed||t.deleteContents();let o=t.startContainer;for(o=o.nodeType===Node.TEXT_NODE?o.parentNode:o;o&&o!==this.editor&&o.parentNode!==this.editor;)o=o.parentNode;o&&o.parentNode===this.editor&&(i=o)}if(i){const e=this._isBlockEmpty(i);i.nextSibling?this.editor.insertBefore(t,i.nextSibling):this.editor.appendChild(t),e&&i.remove()}else this.editor.appendChild(t);if(!t.nextSibling){const t=document.createElement("p");t.innerHTML="<br>",this.editor.appendChild(t)}}setReadOnly(t){this._readOnly=!!t,this.editor.contentEditable=this._readOnly?"false":"true",this.editor.setAttribute("aria-readonly",this._readOnly?"true":"false"),this.wrapper.classList.toggle("read-only",this._readOnly);const e=this.getModule("toolbar");e&&e.buttons&&e.buttons.forEach((t,i)=>{e.setButtonDisabled(i,this._readOnly)})}isReadOnly(){return!!this._readOnly}getModule(t){return this.modules.get(t)}getFormat(t){return this.formats.get(t)}register(t,e,i=!1){this.registry.register(t,e,i)}handleToolbarClick(t){const{command:e,button:i,value:o}=t;S.currentInstance,S.currentInstance=this,this.emit("toolbar-click",t);if(["more","undo","redo","code-view","theme","text-direction","find"].includes(e))switch(e){case"more":case"code-view":case"find":return;case"undo":return void this.undo();case"redo":return void this.redo();case"text-direction":return void this.toggleDirection()}const n=window.getSelection();if(this.isSelectionInEditableArea(n))switch(e){case"bold":case"italic":case"underline":case"strike":case"subscript":case"superscript":case"color":case"background":case"link":case"table":case"heading":case"font-family":case"line-height":case"capitalization":case"text-align":case"text-size":case"list":case"indent-increase":case"indent-decrease":case"emoji":case"image":case"video":case"tag":case"import":this.toggleFormat(e);break;case"clear-format":this.clearFormatting();break;case"horizontal-rule":this.insertHorizontalRule()}}toggleFormat(t){const e=this.getModule("history");e&&"function"==typeof e.saveBeforeFormat&&e.saveBeforeFormat();const i={bold:"bold",italic:"italic",underline:"underline",strike:"strike",subscript:"subscript",superscript:"superscript",color:"color",background:"background",link:"link",table:"table",heading:"heading","font-family":"font-family","line-height":"line-height",capitalization:"capitalization","text-align":"text-align","text-size":"text-size",list:"list","indent-increase":"indent-increase","indent-decrease":"indent-decrease",emoji:"emoji",image:"image",video:"video",tag:"tag",import:"import"}[t];if(!i)return;const o=this.registry.get(`formats/${i}`);if(!o)return;(new o).toggle(),this.updateToolbarButtonStates();["bold","italic","underline","strike","subscript","superscript"].includes(t)&&setTimeout(()=>{this.onContentChange()},0)}_getFormatInstance(t){if(this._fmtCache||(this._fmtCache=new Map),this._fmtCache.has(t))return this._fmtCache.get(t);const e=this.registry.get(`formats/${t}`);if(!e)return null;let i;if(e.createForEditor)i=e.createForEditor(this.instanceId);else{const t=S.currentInstance;S.currentInstance=this,i=new e,S.currentInstance=t}return this._fmtCache.set(t,i),i}updateToolbarButtonStates(){const t=this.getModule("toolbar");if(!t)return;const e=window.getSelection();if(!e||!e.rangeCount)return;const i=this.isSelectionInEditableArea(e);if(["heading","font-family","line-height","capitalization","text-align","list","indent-increase","indent-decrease","bold","italic","underline","strike","subscript","superscript","color","background","link","table","text-size"].forEach(e=>{if(i){const i=this._getFormatInstance(e);i&&(t.setButtonActive(e,i.isActive()),"line-height"===e&&"function"==typeof i.updateButtonText&&i.updateButtonText())}else t.setButtonActive(e,!1)}),i){const t=this.registry.get("formats/text-size");t&&"function"==typeof t.updateButtonTextStatic&&t.updateButtonTextStatic(this.instanceId)}this.updateColorSwatches(),this.updateHistoryButtons()}updateHistoryButtons(){const t=this.getModule("toolbar");if(!t||"function"!=typeof t.getButton)return;const e=this.getModule("history"),i=!(!e||"function"!=typeof e.canUndo||!e.canUndo()),o=!(!e||"function"!=typeof e.canRedo||!e.canRedo()),n=(t,e)=>{t&&(t.classList.remove("rte-hidden"),t.disabled=!e,t.classList.toggle("is-disabled",!e))};n(t.getButton("undo"),i),n(t.getButton("redo"),o)}updateColorSwatches(){const t=this.getModule("toolbar");if(!t||"function"!=typeof t.getButton)return;const e=(e,i)=>{const o=t.getButton(e);if(!o)return;const n=o.querySelector(".rte-swatch");n&&(i?(n.style.background=i,o.classList.add("has-color")):(n.style.removeProperty("background"),o.classList.remove("has-color")))},i=this.registry.get("formats/color");i&&"function"==typeof i.getCurrentColor&&e("color",i.getCurrentColor());const o=this.registry.get("formats/background");o&&"function"==typeof o.getCurrentColor&&e("background",o.getCurrentColor())}undo(){const t=this.getModule("history");t&&"function"==typeof t.undo?t.undo():i("undo")}redo(){const t=this.getModule("history");t&&"function"==typeof t.redo?t.redo():i("redo")}on(t,e){this.events.has(t)||this.events.set(t,[]),this.events.get(t).push(e)}off(t,e){if(this.events.has(t)){const i=this.events.get(t),o=i.indexOf(e);o>-1&&i.splice(o,1)}}emit(t,e){this.events.has(t)&&this.events.get(t).forEach(t=>{try{t(e)}catch(t){}})}preventFocusLoss(t,e="button, input, select, textarea, [contenteditable]"){t&&t.addEventListener("mousedown",t=>{t.target.closest(e)||(t.preventDefault(),setTimeout(()=>{this.focus()},0))})}static getCurrentInstance(){return S.currentInstance}static maintainFocus(t,e=null){"function"==typeof t&&t();const i=e||S.getCurrentInstance();i&&setTimeout(()=>i.focus(),0)}getPopupContainer(){return this.popupContainer}static getPopupContainer(){const t=S.getCurrentInstance();return t?t.getPopupContainer():null}getPopupInstance(t){return this.popupInstances.get(t)}setPopupInstance(t,e){this.popupInstances.set(t,e)}static getPopupInstanceById(t,e){const i=S.instances.get(t);return i?i.getPopupInstance(e):null}static getInstanceById(t){return S.instances.get(t)}static getAllInstances(){return S.instances}destroyPopupInstances(){this.popupInstances.forEach((t,e)=>{t&&"function"==typeof t.destroy&&t.destroy()}),this.popupInstances.clear()}updatePlaceholderVisibility(){this.isEditorEmpty()?this.editor.classList.add("placeholder-visible"):this.editor.classList.remove("placeholder-visible")}destroy(){this._markActive&&(this.wrapper.removeEventListener("pointerdown",this._markActive,!0),this.wrapper.removeEventListener("focusin",this._markActive,!0),this._markActive=null),this._onDocSelectionChange&&(document.removeEventListener("selectionchange",this._onDocSelectionChange),this._onDocSelectionChange=null),this._fmtCache&&this._fmtCache.clear(),clearTimeout(this._autosaveTimer),this.modules.forEach(t=>{"function"==typeof t.destroy&&t.destroy()}),this.destroyPopupInstances(),this.wrapper&&this.wrapper.parentNode&&this.wrapper.parentNode.removeChild(this.wrapper),this.modules.clear(),this.formats.clear(),this.events.clear(),S.instances.delete(this.instanceId),S.currentInstance===this&&(S.currentInstance=null)}}class N{static formatName="";static tagName="";static className="";constructor(t){this.domNode=t}static create(t){const e=document.createElement(this.tagName);return this.className&&(e.className=this.className),e}getOffsetWithin(t,e){let i=0;const o=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,null);let n;for(;n=o.nextNode();){if(n===e.startContainer)return i+e.startOffset;i+=n.textContent.length}return i}}class L extends N{static create(t){return super.create(t)}apply(t){const e=window.getSelection();if(!e||!e.rangeCount)return;const i=e.getRangeAt(0);if(i.collapsed){const o=this.constructor.create(t);o.appendChild(document.createTextNode("​")),i.insertNode(o);const n=document.createRange();n.setStart(o.firstChild,1),n.collapse(!0),e.removeAllRanges(),e.addRange(n)}else{const o=i.extractContents(),n=this.constructor.create(t);n.appendChild(o),i.insertNode(n);const r=document.createRange();r.selectNodeContents(n),e.removeAllRanges(),e.addRange(r)}}remove(){const t=window.getSelection();if(!t||!t.rangeCount)return;const e=t.getRangeAt(0);e.collapsed?this.removeAtCursor(e,t):this.removeFromSelection(e,t)}removeAtCursor(t,e){const i=t.startContainer,o=this.findFormatNode(i);if(!o||!o.parentNode)return;const n=o.textContent,r=this.getOffsetWithin(o,t),s=n.slice(0,r),a=n.slice(r),l=document.createDocumentFragment();if(s){const t=o.cloneNode(!1);t.textContent=s,l.appendChild(t)}const c=document.createTextNode("​");if(l.appendChild(c),a){const t=o.cloneNode(!1);t.textContent=a,l.appendChild(t)}o.replaceWith(l);const d=document.createRange();d.setStartAfter(c),d.collapse(!0),e.removeAllRanges(),e.addRange(d)}removeFromSelection(t,e){const o=this.constructor.formatName;i(o),"strike"===o&&i("strikeThrough")}findFormatNode(t){for(;t&&t!==document.body;){if(t.nodeType===Node.ELEMENT_NODE&&t.tagName===this.constructor.tagName)return t;t=t.parentNode}return null}findFormatNodesInRange(t){const e=[],i=document.createTreeWalker(t.commonAncestorContainer,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>e.tagName===this.constructor.tagName&&t.intersectsNode(e)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP});let o;for(;o=i.nextNode();)e.push(o);return e}isActive(){const t=window.getSelection();if(!t||!t.rangeCount)return!1;let e=t.getRangeAt(0).startContainer;const i=this.constructor.tagName,o=this.constructor.alternativeTagNames||[],r=this.constructor.formatName;if(["bold","italic","underline"].includes(r?.toLowerCase()))return n(r);for(;e&&e!==document.body;){if(e.nodeType===Node.ELEMENT_NODE&&(e.tagName===i||o.includes(e.tagName)))return!0;e=e.parentNode}return!1}}class A extends N{static create(t){return super.create(t)}apply(t){const e=window.getSelection();if(!e||!e.rangeCount)return;const i=e.getRangeAt(0),o=this.getBlockElements(i);0===o.length?this.createBlockAtCursor(i,t):o.forEach(e=>{this.convertBlock(e,t)})}remove(){const t=window.getSelection();if(!t||!t.rangeCount)return;const e=t.getRangeAt(0);this.getBlockElements(e).forEach(t=>{this.removeBlockFormat(t)})}createBlockAtCursor(t,e){const i=this.constructor.create(e),o=this.getBlockElement(t.startContainer);if(o&&o.style&&o.style.cssText&&(i.style.cssText=o.style.cssText),t.collapsed){i.appendChild(document.createTextNode("")),t.insertNode(i);const e=document.createRange();e.setStart(i,0),e.collapse(!0);const o=window.getSelection();o.removeAllRanges(),o.addRange(e)}else{const e=t.extractContents();i.appendChild(e),t.insertNode(i);const o=document.createRange();o.selectNodeContents(i);const n=window.getSelection();n.removeAllRanges(),n.addRange(o)}}convertBlock(t,e){const i=this.constructor.create(e);for(;t.firstChild;)i.appendChild(t.firstChild);t.className&&this.shouldPreserveClass(t.className)&&(i.className=t.className),t.style&&t.style.cssText&&(i.style.cssText=t.style.cssText),t.parentNode.replaceChild(i,t)}removeBlockFormat(t){const e=document.createElement("P");for(;t.firstChild;)e.appendChild(t.firstChild);t.style&&t.style.cssText&&(e.style.cssText=t.style.cssText),t.parentNode.replaceChild(e,t)}getBlockElements(t){const e=[];let i=this.getBlockElement(t.startContainer),o=this.getBlockElement(t.endContainer);if(i&&o&&i.nextElementSibling===o){t.endContainer===o&&0===t.endOffset&&(o=i)}if(i===o)i&&e.push(i);else{let t=i;for(;t&&t!==o;)this.isBlockElement(t)&&e.push(t),t=this.getNextBlockElement(t);o&&this.isBlockElement(o)&&e.push(o)}return e.filter((t,e,i)=>i.indexOf(t)===e)}getBlockElement(t){for(;t&&t.nodeType!==Node.ELEMENT_NODE;)t=t.parentNode;for(;t&&t!==document.body;){if(this.isBlockElement(t))return t;t=t.parentNode}return null}isBlockElement(t){if(!t||t.nodeType!==Node.ELEMENT_NODE)return!1;return["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","PRE","UL","OL","LI","SECTION","ARTICLE"].includes(t.tagName.toUpperCase())}getNextBlockElement(t){let e=t.nextElementSibling;for(;e;){if(this.isBlockElement(e))return e;e=e.nextElementSibling}return null}isActive(t=null){const e=window.getSelection();if(!e||!e.rangeCount)return!1;const i=e.getRangeAt(0),o=this.getBlockElement(i.startContainer);return!!o&&(o.tagName===this.constructor.tagName&&(!t||this.hasValue(o,t)))}hasValue(t,e){return!0}shouldPreserveClass(t){return!1}}function B(){const t=S.getCurrentInstance();if(t){const e=t.getModule("history");e&&"function"==typeof e.saveBeforeFormat&&e.saveBeforeFormat()}}class R extends L{static formatName="bold";static tagName="B";static alternativeTagNames=["STRONG"];apply(){B(),i("bold")}remove(){i("bold")}toggle(){B(),i("bold")}isActive(){return n("bold")}}class H extends L{static formatName="italic";static tagName="I";static alternativeTagNames=["EM"];toggle(){B(),this.isActive()?this.remove():this.apply()}}class z extends L{static formatName="underline";static tagName="U";static alternativeTagNames=["SPAN"];toggle(){B(),this.isActive()?this.remove():this.apply()}}class M extends L{static formatName="strike";static tagName="S";static alternativeTagNames=["STRIKE","DEL"];toggle(){B(),this.isActive()?this.remove():this.apply()}}class O extends L{static formatName="subscript";static tagName="SUB";removeSuperscriptBeforeApply(){const e=t.get("formats/superscript");if(!e)return;const i=new e;i.isActive()&&i.remove()}toggle(){B(),this.isActive()?this.remove():(this.removeSuperscriptBeforeApply(),this.apply())}}class P extends L{static formatName="superscript";static tagName="SUP";removeSubscriptBeforeApply(){const e=t.get("formats/subscript");if(!e)return;const i=new e;i.isActive()&&i.remove()}toggle(){B(),this.isActive()?this.remove():(this.removeSubscriptBeforeApply(),this.apply())}}const _=t=>`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">${t}</svg>`,D={bold:_('<path d="M6 4h8a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"/><path d="M6 12h9a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"/>'),italic:_('<line x1="19" x2="10" y1="4" y2="4"/><line x1="14" x2="5" y1="20" y2="20"/><line x1="15" x2="9" y1="4" y2="20"/>'),underline:_('<path d="M6 4v6a6 6 0 0 0 12 0V4"/><line x1="4" x2="20" y1="20" y2="20"/>'),strike:_('<path d="M16 4H9a3 3 0 0 0-2.83 4"/><path d="M14 12a4 4 0 0 1 0 8H6"/><line x1="4" x2="20" y1="12" y2="12"/>'),subscript:_('<path d="m4 5 8 8"/><path d="m12 5-8 8"/><path d="M20 19h-4c0-1.5.44-2 1.5-2.5S20 15.33 20 14c0-.47-.17-.93-.48-1.29a2.11 2.11 0 0 0-2.62-.44c-.42.24-.74.62-.9 1.07"/>'),superscript:_('<path d="m4 19 8-8"/><path d="m12 19-8-8"/><path d="M20 12h-4c0-1.5.44-2 1.5-2.5S20 8.33 20 7c0-.47-.17-.93-.48-1.29a2.11 2.11 0 0 0-2.62-.44c-.42.24-.74.62-.9 1.07"/>'),"align-left":_('<line x1="21" x2="3" y1="6" y2="6"/><line x1="15" x2="3" y1="12" y2="12"/><line x1="17" x2="3" y1="18" y2="18"/>'),"align-center":_('<line x1="21" x2="3" y1="6" y2="6"/><line x1="17" x2="7" y1="12" y2="12"/><line x1="19" x2="5" y1="18" y2="18"/>'),"align-right":_('<line x1="21" x2="3" y1="6" y2="6"/><line x1="21" x2="9" y1="12" y2="12"/><line x1="21" x2="7" y1="18" y2="18"/>'),"align-justify":_('<line x1="3" x2="21" y1="6" y2="6"/><line x1="3" x2="21" y1="12" y2="12"/><line x1="3" x2="21" y1="18" y2="18"/>'),"list-bullet":_('<line x1="8" x2="21" y1="6" y2="6"/><line x1="8" x2="21" y1="12" y2="12"/><line x1="8" x2="21" y1="18" y2="18"/><circle cx="3.5" cy="6" r="1" fill="currentColor" stroke="none"/><circle cx="3.5" cy="12" r="1" fill="currentColor" stroke="none"/><circle cx="3.5" cy="18" r="1" fill="currentColor" stroke="none"/>'),"list-ordered":_('<line x1="10" x2="21" y1="6" y2="6"/><line x1="10" x2="21" y1="12" y2="12"/><line x1="10" x2="21" y1="18" y2="18"/><path d="M4 6h1v4"/><path d="M4 10h2"/><path d="M6 18H4c0-1 2-2 2-3s-1-1.5-2-1"/>'),"list-alpha":_('<line x1="10" x2="21" y1="6" y2="6"/><line x1="10" x2="21" y1="12" y2="12"/><line x1="10" x2="21" y1="18" y2="18"/><path d="M4 10V8a1 1 0 0 1 2 0v2"/><path d="M4 9h2"/><path d="M4 14h1.5a1 1 0 0 1 0 2H4l2-2"/>'),"list-roman":_('<line x1="10" x2="21" y1="6" y2="6"/><line x1="10" x2="21" y1="12" y2="12"/><line x1="10" x2="21" y1="18" y2="18"/><path d="M5 7v3"/><path d="M4 14h2l-1 4"/>'),list:_('<line x1="8" x2="21" y1="6" y2="6"/><line x1="8" x2="21" y1="12" y2="12"/><line x1="8" x2="21" y1="18" y2="18"/><circle cx="3.5" cy="6" r="1" fill="currentColor" stroke="none"/><circle cx="3.5" cy="12" r="1" fill="currentColor" stroke="none"/><circle cx="3.5" cy="18" r="1" fill="currentColor" stroke="none"/>'),"indent-increase":_('<polyline points="3 8 7 12 3 16"/><line x1="21" x2="11" y1="6" y2="6"/><line x1="21" x2="11" y1="12" y2="12"/><line x1="21" x2="11" y1="18" y2="18"/>'),"indent-decrease":_('<polyline points="7 8 3 12 7 16"/><line x1="21" x2="11" y1="6" y2="6"/><line x1="21" x2="11" y1="12" y2="12"/><line x1="21" x2="11" y1="18" y2="18"/>'),image:_('<rect width="18" height="18" x="3" y="3" rx="2" ry="2"/><circle cx="9" cy="9" r="2"/><path d="m21 15-3.1-3.1a2 2 0 0 0-2.8 0L6 21"/>'),video:_('<path d="m22 8-6 4 6 4V8Z"/><rect width="14" height="12" x="2" y="6" rx="2" ry="2"/>'),table:_('<path d="M12 3v18"/><rect width="18" height="18" x="3" y="3" rx="2"/><path d="M3 9h18"/><path d="M3 15h18"/>'),"table-profile":_('<path d="M15 3v18"/><rect width="18" height="18" x="3" y="3" rx="2"/><path d="M21 9H3"/><path d="M21 15H3"/>'),"add-row-above":_('<rect x="3" y="13" width="18" height="8" rx="2"/><line x1="12" x2="12" y1="3" y2="9"/><line x1="9" x2="15" y1="6" y2="6"/>'),"add-row-below":_('<rect x="3" y="3" width="18" height="8" rx="2"/><line x1="12" x2="12" y1="15" y2="21"/><line x1="9" x2="15" y1="18" y2="18"/>'),"add-col-left":_('<rect x="13" y="3" width="8" height="18" rx="2"/><line x1="3" x2="9" y1="12" y2="12"/><line x1="6" x2="6" y1="9" y2="15"/>'),"add-col-right":_('<rect x="3" y="3" width="8" height="18" rx="2"/><line x1="15" x2="21" y1="12" y2="12"/><line x1="18" x2="18" y1="9" y2="15"/>'),"delete-row":_('<rect x="3" y="9" width="18" height="6" rx="2"/><line x1="9" x2="15" y1="12" y2="12"/>'),"delete-col":_('<rect x="9" y="3" width="6" height="18" rx="2"/><line x1="12" x2="12" y1="9" y2="15"/>'),"delete-table":_('<path d="M3 6h18"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"/><path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/><line x1="10" x2="10" y1="11" y2="17"/><line x1="14" x2="14" y1="11" y2="17"/>'),color:_('<path d="M5.5 19 12 5l6.5 14"/><path d="M8 14h8"/>'),background:_('<path d="m9 11-6 6v3h9l3-3"/><path d="m22 12-4.6 4.6a2 2 0 0 1-2.8 0l-5.2-5.2a2 2 0 0 1 0-2.8L14 4"/>'),"no-color":_('<circle cx="12" cy="12" r="9"/><line x1="5.6" x2="18.4" y1="5.6" y2="18.4"/>'),"custom-color":_('<path d="M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10c.93 0 1.65-.75 1.65-1.69 0-.43-.18-.83-.44-1.12-.29-.29-.44-.65-.44-1.13a1.64 1.64 0 0 1 1.67-1.67h2c3.05 0 5.55-2.5 5.55-5.55C22 6 17.5 2 12 2z"/><circle cx="8.5" cy="7.5" r="1" fill="currentColor" stroke="none"/><circle cx="6.5" cy="12.5" r="1" fill="currentColor" stroke="none"/><circle cx="13.5" cy="6.5" r="1" fill="currentColor" stroke="none"/><circle cx="17.5" cy="10.5" r="1" fill="currentColor" stroke="none"/>'),undo:_('<path d="M9 14 4 9l5-5"/><path d="M4 9h10.5a5.5 5.5 0 0 1 0 11H11"/>'),redo:_('<path d="m15 14 5-5-5-5"/><path d="M20 9H9.5a5.5 5.5 0 0 0 0 11H13"/>'),link:_('<path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/>'),emoji:_('<circle cx="12" cy="12" r="10"/><path d="M8 14s1.5 2 4 2 4-2 4-2"/><line x1="9" x2="9.01" y1="9" y2="9"/><line x1="15" x2="15.01" y1="9" y2="9"/>'),tag:_('<path d="M12.6 2.6A2 2 0 0 0 11.2 2H4a2 2 0 0 0-2 2v7.2a2 2 0 0 0 .6 1.4l8.7 8.7a2.4 2.4 0 0 0 3.4 0l6.6-6.6a2.4 2.4 0 0 0 0-3.4z"/><circle cx="7.5" cy="7.5" r="1" fill="currentColor" stroke="none"/>'),import:_('<path d="M12 3v12"/><path d="m8 11 4 4 4-4"/><path d="M8 5H4a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-4"/>'),code:_('<polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/>'),"code-view":_('<path d="m18 16 4-4-4-4"/><path d="m6 8-4 4 4 4"/><path d="m14.5 4-5 16"/>'),"clear-format":_('<path d="M4 7V4h16v3"/><path d="M5 20h6"/><path d="M13 4 8 20"/><path d="m15 15 5 5"/><path d="m20 15-5 5"/>'),"horizontal-rule":_('<path d="M5 12h14"/>'),find:_('<circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/>'),"chevron-up":_('<path d="m18 15-6-6-6 6"/>'),"chevron-down":_('<path d="m6 9 6 6 6-6"/>'),close:_('<path d="M18 6 6 18"/><path d="m6 6 12 12"/>'),"text-direction":_('<path d="M8 3 4 7l4 4"/><path d="M4 7h16"/><path d="m16 21 4-4-4-4"/><path d="M20 17H4"/>'),check:_('<polyline points="20 6 9 17 4 12"/>'),dropdown:_('<path d="m6 9 6 6 6-6"/>'),more:_('<circle cx="12" cy="12" r="1.4" fill="currentColor" stroke="none"/><circle cx="19" cy="12" r="1.4" fill="currentColor" stroke="none"/><circle cx="5" cy="12" r="1.4" fill="currentColor" stroke="none"/>'),theme:_('<circle cx="12" cy="12" r="4"/><path d="M12 2v2"/><path d="M12 20v2"/><path d="m4.9 4.9 1.4 1.4"/><path d="m17.7 17.7 1.4 1.4"/><path d="M2 12h2"/><path d="M20 12h2"/><path d="m6.3 17.7-1.4 1.4"/><path d="m19.1 4.9-1.4 1.4"/>'),heading:_('<path d="M4 12h8"/><path d="M4 18V6"/><path d="M12 18V6"/><path d="m17 12 3-2v8"/>'),"font-family":_('<polyline points="4 7 4 4 20 4 20 7"/><line x1="9" x2="15" y1="20" y2="20"/><line x1="12" x2="12" y1="4" y2="20"/>'),"line-height":_('<path d="M3 5h12"/><path d="M3 12h12"/><path d="M3 19h12"/><path d="M19 5v14"/><path d="m16.5 7.5 2.5-2.5 2.5 2.5"/><path d="m16.5 16.5 2.5 2.5 2.5-2.5"/>'),capitalization:_('<path d="M4 18 8 8l4 10"/><path d="M5.5 14h5"/><path d="M16 18a3 3 0 1 0 0-6 3 3 0 0 0-3 3v3"/><path d="M19 12v6"/>'),"text-size":_('<path d="M21 14h-5"/><path d="M16 16v-3.5a2.5 2.5 0 0 1 5 0V16"/><path d="M4.5 13h6"/><path d="m3 16 4.5-9 4.5 9"/>')};class F{static getIcon(t){return D[t]||""}static createIconElement(t,e={}){const i=document.createElement("span");return i.className=`icon icon-${t}`,i.style.display="inline-flex",i.style.alignItems="center",i.style.justifyContent="center",i.style.width=e.width||"16px",i.style.height=e.height||"16px",i.style.verticalAlign="middle",i.innerHTML=this.getIcon(t),i}static hasIcon(t){return t in D}static getIconNames(){return Object.keys(D)}}function V(t=null){let e;return e=t?S.getInstanceById(t):S.getCurrentInstance(),e?e.getPopupContainer():document.body}function U(t,e=null){const i=V(e);t.parentNode&&t.parentNode.removeChild(t),i.appendChild(t)}function q(t){if(!t)return{width:300,height:200};const e=t.getBoundingClientRect();if(e.width>0&&e.height>0)return{width:e.width,height:e.height};if(t.offsetWidth>0&&t.offsetHeight>0)return{width:t.offsetWidth,height:t.offsetHeight};const i=window.getComputedStyle(t);if("none"===i.display||"hidden"===i.visibility){const e=t.style.display,i=t.style.visibility,o=t.style.position,n=t.style.top,r=t.style.left,s=t.style.zIndex;t.style.display="block",t.style.visibility="visible",t.style.position="absolute",t.style.top="-9999px",t.style.left="-9999px",t.style.zIndex="-1",t.offsetHeight;const a=t.getBoundingClientRect(),l=a.width>0?a.width:300,c=a.height>0?a.height:200;return t.style.display=e,t.style.visibility=i,t.style.position=o,t.style.top=n,t.style.left=r,t.style.zIndex=s,{width:l,height:c}}const o=parseInt(i.width),n=parseInt(i.height);return{width:o>0?o:300,height:n>0?n:200}}function W(t,e,i={}){const{offsetX:o=0,offsetY:n=5,preferTop:r=!1,preferLeft:s=!1}=i,a=t.getBoundingClientRect(),l=V();let c,d;if(l.classList.contains("rich-editor-popup-container")){const t=l.getBoundingClientRect();c=a.top-t.top+a.height+n,d=a.left-t.left+o;const{width:i,height:h}=q(e);if(c+h>t.height&&!r){const e=a.top-t.top-h-n;c=e>=0?e:Math.max(n,(t.height-h)/2)}d+i+5>t.width&&!s&&(d=t.width-i-o-15),d<0&&(d=o),c<0&&(c=n)}else{c=a.bottom+window.scrollY+n,d=a.left+window.scrollX+o;const{width:t,height:i}=q(e);if(d+t>window.innerWidth&&!s&&(d=window.innerWidth-t-o),c+i>window.innerHeight+window.scrollY&&!r){const t=a.top+window.scrollY-i-n;c=t>=window.scrollY?t:Math.max(window.scrollY+n,window.scrollY+(window.innerHeight-i)/2)}d<0&&(d=o),c<0&&(c=n)}return{top:c,left:d}}function $(t,e){t.style.position="absolute",t.style.top=`${e.top}px`,t.style.left=`${e.left}px`,t.style.zIndex="1000"}class X{constructor(t={}){this.options={colors:["#000000","#333333","#666666","#999999","#cccccc","#eeeeee","#ff0000","#ff6600","#ffcc00","#ffff00","#99ff00","#00ff00","#00ffcc","#00ccff","#0066ff","#0000ff","#6600ff","#cc00ff","#ff00cc","#ff0066","#800000","#ff8000","#808000","#008000","#008080","#0080ff","#004080","#800080","#804080","#ff0080"],customColorEnabled:!0,onColorSelect:null,editor:null,...t},this.popup=null,this.isVisible=!1,this.currentColor="#000000",this.clickOutsideHandler=null,this.createColorPicker()}createColorPicker(){this.popup=document.createElement("div"),this.popup.className="color-picker-popup",this.createColorGrid(),this.options.customColorEnabled&&this.createCustomColorInput(),U(this.popup),this.options.editor&&"function"==typeof this.options.editor.preventFocusLoss&&this.options.editor.preventFocusLoss(this.popup)}createColorGrid(){const t=document.createElement("div");t.className="color-grid",this.options.colors.forEach(e=>{const i=document.createElement("button");i.type="button",i.className="color-button",i.style.backgroundColor=e,i.dataset.color=e,i.title=e,i.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),this.selectColor(e),this.options.editor&&setTimeout(()=>this.options.editor.focus(),0)}),t.appendChild(i)}),this.popup.appendChild(t)}createCustomColorInput(){const t=document.createElement("div");t.className="custom-color-container";const e=document.createElement("button");e.type="button",e.className="color-button no-color-button",e.title="No Color",e.style.backgroundColor="transparent";const i=F.createIconElement("no-color",{width:"24",height:"24"});e.appendChild(i),e.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),this.selectColor("transparent"),this.options.editor&&setTimeout(()=>this.options.editor.focus(),0)});const o=document.createElement("button");o.type="button",o.className="color-button white-button",o.style.backgroundColor="#ffffff",o.style.border="1px solid #ccc",o.title="White",o.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),this.selectColor("#ffffff"),this.options.editor&&setTimeout(()=>this.options.editor.focus(),0)});const n=document.createElement("button");n.type="button",n.className="color-button black-button",n.style.backgroundColor="#000000",n.title="Black",n.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),this.selectColor("#000000"),this.options.editor&&setTimeout(()=>this.options.editor.focus(),0)});const r=document.createElement("button");r.type="button",r.className="color-button custom-color-button",r.title="Custom Color",r.style.backgroundColor="transparent",r.style.border="1px solid #ccc",r.style.font="none !important";const s=F.createIconElement("custom-color",{width:"16px",height:"16px"});r.appendChild(s);const a=document.createElement("input");a.type="color",a.className="custom-color-input",a.value=this.currentColor,a.style.visibility="hidden",a.style.pointerEvents="none",a.style.opacity="0",r.addEventListener("click",t=>{a.style.visibility="visible",a.style.pointerEvents="auto",a.style.opacity="1",t.preventDefault(),t.stopPropagation(),a.click()}),a.addEventListener("change",t=>{a.style.visibility="hidden",a.style.pointerEvents="none",a.style.opacity="0",this.selectColor(t.target.value),this.options.editor&&setTimeout(()=>this.options.editor.focus(),0)}),t.appendChild(e),t.appendChild(o),t.appendChild(n),t.appendChild(r),t.appendChild(a),this.popup.appendChild(t)}setupClickOutside(){this.clickOutsideHandler&&document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=t=>{this.popup.contains(t.target)||this.hide()},setTimeout(()=>{document.addEventListener("click",this.clickOutsideHandler)},100)}removeClickOutside(){this.clickOutsideHandler&&(document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=null)}show(t){if(!t)return;document.body.contains(this.popup)||U(this.popup);const e=W(t,this.popup,{offsetY:5,offsetX:0});$(this.popup,e),this.popup.classList.add("visible"),this.isVisible=!0,this.setupClickOutside()}hide(){this.popup.classList.remove("visible"),this.isVisible=!1,this.removeClickOutside()}selectColor(t){this.currentColor=t,this.options.onColorSelect&&this.options.onColorSelect(t),this.hide()}destroy(){this.removeClickOutside(),this.popup&&this.popup.parentNode&&this.popup.parentNode.removeChild(this.popup)}}class K extends L{static formatName="color";static tagName="SPAN";static attribute="color";static savedRanges=new Map;constructor(){super();const t=S.getCurrentInstance();if(!t)return;this.editorId=t.instanceId;let e=t.getPopupInstance("color");if(!e){const i=this.editorId;e=new X({onColorSelect:t=>{K.applyColorToCurrentSelection(t,i)},editor:S.getCurrentInstance()}),t.setPopupInstance("color",e)}this.colorPicker=e}static applyColorToCurrentSelection(t,e=null){const n=window.getSelection(),r=null!=e?K.savedRanges.get(e):null;r&&(n.removeAllRanges(),n.addRange(r)),null!=e&&K.savedRanges.delete(e),n&&n.rangeCount&&!n.isCollapsed&&(B(),o(!0),i("foreColor","transparent"===t?"inherit":t),setTimeout(()=>{const t=S.getCurrentInstance();t&&("function"==typeof t.updateToolbarButtonStates&&t.updateToolbarButtonStates(),"function"==typeof t.onContentChange&&t.onContentChange())},0))}toggle(){this.colorPicker.isVisible?this.colorPicker.hide():this.showColorPicker()}showColorPicker(){const t=S.getInstanceById(this.editorId);if(!t)return;const e=window.getSelection();e&&e.rangeCount&&!e.isCollapsed?K.savedRanges.set(this.editorId,e.getRangeAt(0).cloneRange()):t._lastRange&&K.savedRanges.set(this.editorId,t._lastRange.cloneRange());const i=t.getModule("toolbar");let o=null;if(i&&(o=i.getButton("color")),!o){const t=i?.getContainer();t&&(o=t.querySelector(".rich-editor-toolbar-btn.color-btn"))}o||(o=t.wrapper.querySelector(".rich-editor-toolbar-btn.color-btn")),o&&this.colorPicker.show(o)}isActive(){return!!K.getCurrentColor()}static getCurrentColor(){const t=window.getSelection();if(!t||!t.rangeCount)return null;let e=t.getRangeAt(0).startContainer;for(e.nodeType===Node.TEXT_NODE&&(e=e.parentNode);e&&e.nodeType===Node.ELEMENT_NODE&&(!e.classList||!e.classList.contains("rich-editor-area"));){if(e.style&&e.style.color&&"inherit"!==e.style.color)return e.style.color;if("FONT"===e.tagName&&e.getAttribute("color"))return e.getAttribute("color");e=e.parentNode}return null}}class G extends L{static formatName="background";static tagName="SPAN";static attribute="background-color";static savedRanges=new Map;constructor(){super();const t=S.getCurrentInstance();if(!t)return;this.editorId=t.instanceId;let e=t.getPopupInstance("background");e||(e=new X({onColorSelect:t=>{G.applyBackgroundToCurrentSelection(t,this.editorId)},editor:t,editorId:this.editorId}),t.setPopupInstance("background",e)),this.colorPicker=e}static createForEditor(t){const e=S.getInstanceById(t);if(!e)return null;const i=S.currentInstance;S.currentInstance=e;const o=new G;return S.currentInstance=i,o}static applyBackgroundToCurrentSelection(t,e=null){let n=null;if(n=e?S.getInstanceById(e):S.getCurrentInstance(),!n)return;const r=window.getSelection(),s=null!=e?G.savedRanges.get(e):null;s&&(r.removeAllRanges(),r.addRange(s)),null!=e&&G.savedRanges.delete(e),r&&r.rangeCount&&!r.isCollapsed&&(B(),o(!0),i("backColor","transparent"===t?"inherit":t),setTimeout(()=>{n&&("function"==typeof n.updateToolbarButtonStates&&n.updateToolbarButtonStates(),"function"==typeof n.onContentChange&&n.onContentChange())},0))}toggle(){this.colorPicker.isVisible?this.colorPicker.hide():this.showColorPicker()}showColorPicker(){const t=S.getInstanceById(this.editorId);if(!t)return;const e=window.getSelection();e&&e.rangeCount&&!e.isCollapsed?G.savedRanges.set(this.editorId,e.getRangeAt(0).cloneRange()):t._lastRange&&G.savedRanges.set(this.editorId,t._lastRange.cloneRange());const i=t.getModule("toolbar");let o=null;if(i&&(o=i.getButton("background")),!o){const t=i?.getContainer();t&&(o=t.querySelector(".rich-editor-toolbar-btn.background-btn"))}o||(o=t.wrapper.querySelector(".rich-editor-toolbar-btn.background-btn")),o&&this.colorPicker.show(o)}isActive(){return!!G.getCurrentColor()}static getCurrentColor(){const t=window.getSelection();if(!t||!t.rangeCount)return null;let e=t.getRangeAt(0).startContainer;for(e.nodeType===Node.TEXT_NODE&&(e=e.parentNode);e&&e.nodeType===Node.ELEMENT_NODE&&(!e.classList||!e.classList.contains("rich-editor-area"));){if(e.style&&e.style.backgroundColor&&"inherit"!==e.style.backgroundColor)return e.style.backgroundColor;e=e.parentNode}return null}}class Y{constructor(t={}){this.options={onLinkSelect:null,editor:null,...t},this.popup=null,this.isVisible=!1,this.urlInput=null,this.textInput=null,this.createPopup()}createPopup(){this.popup=document.createElement("div"),this.popup.className="link-popup link-popup--inline";const t=document.createElement("div");t.className="link-popup-content",this.textGroup=document.createElement("div"),this.textGroup.className="link-popup-row",this.textInput=document.createElement("input"),this.textInput.type="text",this.textInput.className="yjd-input",this.textInput.placeholder="Text to display",this.textGroup.appendChild(this.textInput);const e=document.createElement("div");e.className="link-popup-row",this.urlInput=document.createElement("input"),this.urlInput.type="text",this.urlInput.className="yjd-input",this.urlInput.placeholder="Paste or type a link…",this.applyBtn=document.createElement("button"),this.applyBtn.type="button",this.applyBtn.className="yjd-button-confirm link-popup-apply",this.applyBtn.textContent="Apply",this.applyBtn.onclick=()=>{this.handleOk(),this._refocusEditor()},e.appendChild(this.urlInput),e.appendChild(this.applyBtn),t.appendChild(this.textGroup),t.appendChild(e),this.popup.appendChild(t);const i=t=>{"Enter"===t.key&&(t.preventDefault(),this.handleOk(),this._refocusEditor()),"Escape"===t.key&&(this.hide(),this._refocusEditor())};this.urlInput.onkeydown=i,this.textInput.onkeydown=i,U(this.popup),this.options.editor&&"function"==typeof this.options.editor.preventFocusLoss&&this.options.editor.preventFocusLoss(this.popup)}_refocusEditor(){this.options.editor&&setTimeout(()=>this.options.editor.focus(),0)}handleOk(){const t=this.urlInput.value.trim();if(!t)return void this.urlInput.focus();let e=t;/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(e)||e.startsWith("/")||e.startsWith("#")||(e="https://"+e);const i=this.textInput.value.trim();this.options.onLinkSelect&&this.options.onLinkSelect({url:e,text:i}),this.hide()}show(t,e=null,i=""){if(!t)return;const o=!!i;this.urlInput.value=e?e.url:"",this.textInput.value=i||(e?e.text:""),this.textGroup.style.display=o?"none":"";const n=W(t,this.popup,{offsetY:8,offsetX:0});$(this.popup,n),this.popup.classList.add("visible"),this.isVisible=!0,setTimeout(()=>this.urlInput.focus(),60),setTimeout(()=>{document.addEventListener("click",this.closeOnClickOutside)},100)}hide(){this.popup.classList.remove("visible"),this.isVisible=!1,document.removeEventListener("click",this.closeOnClickOutside)}closeOnClickOutside=t=>{this.popup.contains(t.target)||this.hide()};destroy(){document.removeEventListener("click",this.closeOnClickOutside),this.popup&&this.popup.parentNode&&this.popup.parentNode.removeChild(this.popup)}}class Q extends L{static formatName="link";static tagName="A";static savedRanges=new Map;constructor(){super();const t=S.getCurrentInstance();if(!t)return;this.editorId=t.instanceId;let e=t.getPopupInstance("link");e||(e=new Y({onLinkSelect:t=>{Q.insertLink(t,this.editorId)},editor:t,editorId:this.editorId}),t.setPopupInstance("link",e)),this.linkPopup=e}static createForEditor(t){const e=S.getInstanceById(t);if(!e)return null;const i=S.currentInstance;S.currentInstance=e;const o=new Q;return S.currentInstance=i,o}static insertLink(t,e=null){let i=null;if(i=e?S.getInstanceById(e):S.getCurrentInstance(),!i)return;if(!a(t.url))return;const o=Q.savedRanges.get(e);if(!o)return;const n=window.getSelection();n.removeAllRanges(),n.addRange(o);const r=n.getRangeAt(0);if(r.collapsed){const e=document.createElement("A");e.href=t.url,e.target="_blank",e.rel="noopener noreferrer",e.textContent=t.text||t.url,r.insertNode(e)}else{const e=r.extractContents(),i=document.createElement("A");for(i.href=t.url,i.target="_blank",i.rel="noopener noreferrer";e.firstChild;)i.appendChild(e.firstChild);r.insertNode(i)}const s=document.createRange();s.setStartAfter(r.endContainer),s.collapse(!0),n.removeAllRanges(),n.addRange(s),setTimeout(()=>{i&&"function"==typeof i.onContentChange&&i.onContentChange()},0),Q.savedRanges.delete(e),i&&"function"==typeof i.onContentChange&&i.onContentChange()}toggle(){this.linkPopup.isVisible?this.linkPopup.hide():this.showPopup()}showPopup(){const t=S.getInstanceById(this.editorId);if(!t)return;const e=window.getSelection();let i=null;if(e&&e.rangeCount>0){const t=e.getRangeAt(0).cloneRange();if(Q.savedRanges.set(this.editorId,t),i=t.getBoundingClientRect(),!i||0===i.width&&0===i.height){const e=t.startContainer.nodeType===Node.TEXT_NODE?t.startContainer.parentElement:t.startContainer;e&&e.getBoundingClientRect&&(i=e.getBoundingClientRect())}}const o=this.getCurrentLink();let n="";e&&!e.isCollapsed&&(n=e.toString().trim());let r=null;if(i&&(i.width||i.height))r={getBoundingClientRect:()=>i};else{const e=t.getModule("toolbar");r=e&&(e.getButton("link")||t.wrapper.querySelector('.rich-editor-toolbar-btn[data-command="link"]'))}r&&this.linkPopup.show(r,o,n)}getCurrentLink(){const t=window.getSelection();if(!t||!t.rangeCount)return null;let e=t.getRangeAt(0).startContainer;for(;e&&e!==document.body;){if(e.nodeType===Node.ELEMENT_NODE&&"A"===e.tagName)return{url:e.href||"",text:e.textContent||""};e=e.parentNode}return null}isActive(){return null!==this.getCurrentLink()}}class Z{constructor(t={}){this.options={maxRows:8,maxCols:8,onTableSelect:null,...t},this.popup=null,this.isVisible=!1,this.selectedRows=1,this.selectedCols=1,this.grid=null,this.sizeDisplay=null,this.createPopup()}createPopup(){this.popup=document.createElement("div"),this.popup.className="table-popup";const t=document.createElement("div");t.className="table-popup-content",this.createSizeDisplay(),this.createGridSelector(),t.appendChild(this.grid),t.appendChild(this.sizeDisplay),this.popup.appendChild(t),U(this.popup)}createSizeDisplay(){this.sizeDisplay=document.createElement("div"),this.sizeDisplay.className="table-size-display"}createGridSelector(){this.grid=document.createElement("div"),this.grid.className="table-grid-selector";for(let t=1;t<=this.options.maxRows;t++)for(let e=1;e<=this.options.maxCols;e++){const i=document.createElement("div");i.className="table-grid-cell",i.dataset.row=t,i.dataset.col=e,i.addEventListener("mouseenter",()=>{this.highlightGrid(t,e)}),i.addEventListener("click",()=>{this.selectSize(t,e),this.handleInsert()}),this.grid.appendChild(i)}this.grid.addEventListener("mouseleave",()=>{this.highlightGrid(1,1)})}highlightGrid(t,e){this.selectedRows=t,this.selectedCols=e,this.updateSizeDisplay(t,e);this.grid.querySelectorAll(".table-grid-cell").forEach(i=>{const o=parseInt(i.dataset.row),n=parseInt(i.dataset.col);o<=t&&n<=e?i.classList.add("highlighted"):i.classList.remove("highlighted")})}updateSizeDisplay(t,e){this.sizeDisplay&&(this.sizeDisplay.textContent=`${t}x${e}`)}selectSize(t,e){this.selectedRows=t,this.selectedCols=e,this.updateSizeDisplay(t,e)}handleInsert(){this.options.onTableSelect&&this.options.onTableSelect({rows:this.selectedRows,cols:this.selectedCols}),this.hide()}show(t){if(!t)return;this.selectedRows=1,this.selectedCols=1,this.highlightGrid(1,1);const e=W(t,this.popup,{offsetY:5,offsetX:0});$(this.popup,e),this.popup.classList.add("visible"),this.isVisible=!0,setTimeout(()=>{document.addEventListener("click",this.closeOnClickOutside)},100)}hide(){this.popup.classList.remove("visible"),this.isVisible=!1,document.removeEventListener("click",this.closeOnClickOutside)}closeOnClickOutside=t=>{this.popup.contains(t.target)||this.hide()};destroy(){document.removeEventListener("click",this.closeOnClickOutside),this.popup&&this.popup.parentNode&&this.popup.parentNode.removeChild(this.popup)}}class J extends A{static formatName="table";static tagName="TABLE";static savedRanges=new Map;constructor(){super();const t=S.getCurrentInstance();if(!t)return;this.editorId=t.instanceId;let e=t.getPopupInstance("table");e||(e=new Z({onTableSelect:t=>{J.insertTable(t,this.editorId)},editor:t,editorId:this.editorId}),t.setPopupInstance("table",e)),this.tablePopup=e}static createForEditor(t){const e=S.getInstanceById(t);if(!e)return null;const i=S.currentInstance;S.currentInstance=e;const o=new J;return S.currentInstance=i,o}static insertTable(t,e=null){let i=null;if(i=e?S.getInstanceById(e):S.getCurrentInstance(),!i)return;const o=J.savedRanges.get(e);if(!o)return;const n=window.getSelection();n.removeAllRanges(),n.addRange(o);const r=n.getRangeAt(0),s=J.createTableElement(t.rows,t.cols);r.collapsed||r.deleteContents(),"function"==typeof i.insertBlock?i.insertBlock(s):r.insertNode(s);const a=s.querySelector("td");if(a){const t=document.createRange();t.setStart(a,0),t.collapse(!0),n.removeAllRanges(),n.addRange(t)}J.savedRanges.delete(e),i&&"function"==typeof i.onContentChange&&i.onContentChange()}static createTableElement(t,e){const i=document.createElement("table");i.className="rich-editor-table",i.cellSpacing="0",i.cellPadding="0",i.border="1";const o=document.createElement("tbody");for(let i=0;i<t;i++){const t=document.createElement("tr");for(let i=0;i<e;i++){const e=document.createElement("td");e.innerHTML="<br>",e.style.minWidth="50px",e.style.minHeight="24px",e.style.padding="4px 8px",e.style.border="1px solid #ddd",e.style.verticalAlign="top",e.contentEditable="true",t.appendChild(e)}o.appendChild(t)}return i.appendChild(o),i.style.borderCollapse="collapse",i.style.width="100%",i.style.margin="10px 0",i}toggle(){this.tablePopup.isVisible?this.tablePopup.hide():this.showPopup()}showPopup(){const t=window.getSelection();t&&t.rangeCount>0&&J.savedRanges.set(this.editorId,t.getRangeAt(0).cloneRange());const e=S.getInstanceById(this.editorId);if(!e)return;const i=e.getModule("toolbar");let o=null;if(i&&(o=i.getButton("table")),!o){const t=i?.getContainer();t&&(o=t.querySelector(".rich-editor-toolbar-btn.table-btn"))}o||(o=e.wrapper.querySelector(".rich-editor-toolbar-btn.table-btn")),o&&this.tablePopup.show(o)}isActive(){const t=window.getSelection();if(!t||!t.rangeCount)return!1;let e=t.getRangeAt(0).startContainer;for(;e&&e!==document.body;){if(e.nodeType===Node.ELEMENT_NODE&&"TABLE"===e.tagName)return!0;e=e.parentNode}return!1}getCurrentTable(){const t=window.getSelection();if(!t||!t.rangeCount)return null;let e=t.getRangeAt(0).startContainer;for(;e&&e!==document.body;){if(e.nodeType===Node.ELEMENT_NODE&&"TABLE"===e.tagName)return e;e=e.parentNode}return null}apply(){this.showPopup()}remove(){const t=this.getCurrentTable();t&&(window.richEditor&&window.richEditor.resizeHandles&&window.richEditor.resizeHandles.hideHandles(),t.parentNode.removeChild(t))}}class tt{constructor(t={}){this.options={items:[],onItemSelect:null,displayProperty:"label",valueProperty:"value",className:"custom-select",title:"",width:200,height:280,...t},this.popup=null,this.isVisible=!1,this.currentValue=null,this.clickOutsideHandler=null,this.initialized=!1,this.createSelect()}createSelect(){if(this.popup=document.createElement("div"),this.popup.className=`${this.options.className}-popup`,this.options.title){const t=document.createElement("div");t.className="custom-select-header",t.textContent=this.options.title,this.popup.appendChild(t)}U(this.popup),this.init()}async init(){await this.createItemList(),this.initialized=!0}async createItemList(){const t=document.createElement("div");t.className="item-list";const e=F.getIcon("check");this.options.items.forEach(i=>{const o=document.createElement("button");o.type="button",o.className="custom-select-item-button",o.dataset.value=this.getItemValue(i);const n=document.createElement("div");n.className="item-text",n.innerHTML=this.getItemDisplay(i);const r=document.createElement("span");r.className="item-checkmark",r.innerHTML=e||"",o.appendChild(n),o.appendChild(r),o.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),this.selectItem(i)}),t.appendChild(o)}),this.popup.appendChild(t)}getItemDisplay(t){return t[this.options.displayProperty]||t.toString()}getItemValue(t){return t[this.options.valueProperty]||t[this.options.displayProperty]||t}async updateItems(t){this.options.items=t;const e=this.popup.querySelector(".item-list");e&&e.remove(),await this.createItemList()}setupClickOutside(){this.clickOutsideHandler&&document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=t=>{t.target.closest(".block-toolbar")||this.popup.contains(t.target)||this.hide()},setTimeout(()=>{document.addEventListener("click",this.clickOutsideHandler)},100)}removeClickOutside(){this.clickOutsideHandler&&(document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=null)}setupScrollHandler(){this.scrollHandler&&window.removeEventListener("scroll",this.scrollHandler),this.scrollHandler=()=>{this.isVisible&&this.updatePosition()},window.addEventListener("scroll",this.scrollHandler)}removeScrollHandler(){this.scrollHandler&&(window.removeEventListener("scroll",this.scrollHandler),this.scrollHandler=null)}async show(t){if(!t)return;const e=window.getSelection(),i=S.getCurrentInstance&&S.getCurrentInstance(),o=i&&i.editor;e&&e.rangeCount&&o&&o.contains(e.anchorNode)?this._savedRange=e.getRangeAt(0).cloneRange():this._savedRange=i&&i._lastRange?i._lastRange.cloneRange():null,this.initialized||await new Promise(t=>{const e=()=>{this.initialized?t():setTimeout(e,10)};e()}),document.body.contains(this.popup)||U(this.popup),this.highlightCurrentItem(this.currentValue);const n=W(t,this.popup,{offsetY:5,offsetX:0});$(this.popup,n),this.popup.classList.add("visible"),this.isVisible=!0,this.setupClickOutside(),this.setupScrollHandler(),this.currentAnchor=t}hide(){this.popup.classList.remove("visible"),this.isVisible=!1,this.removeClickOutside(),this.currentAnchor=null}updatePosition(){if(this.isVisible&&this.currentAnchor){const t=W(this.currentAnchor,this.popup,{offsetY:5,offsetX:0});$(this.popup,t)}}setCurrentValue(t){this.currentValue=t,this.highlightCurrentItem(t)}highlightCurrentItem(t){if(this.popup.querySelectorAll(".custom-select-item-button.current").forEach(t=>{t.classList.remove("current")}),null!=t){const e=this.popup.querySelectorAll(".custom-select-item-button");for(const i of e)if(i.dataset.value===t.toString()){i.classList.add("current");break}}}selectItem(t){const e=this.getItemValue(t);if(this.currentValue=e,this._savedRange){const t=window.getSelection();t.removeAllRanges(),t.addRange(this._savedRange)}this.options.onItemSelect&&this.options.onItemSelect(e,t),this.hide()}getCurrentValue(){return this.currentValue}destroy(){this.removeClickOutside(),this.popup&&this.popup.parentNode&&this.popup.parentNode.removeChild(this.popup)}}class et extends A{static formatName="heading";static tagName="H1";constructor(){super();const t=S.getCurrentInstance();if(!t)return;this.editorId=t.instanceId;let e=t.getPopupInstance("heading");if(!e){const i=et.getTagMap(),o=Object.values(i).map(t=>({value:t.tag,label:t.element,title:t.title}));e=new tt({items:o,displayProperty:"label",valueProperty:"value",className:"heading-select",onItemSelect:(t,e)=>{et.applyTagToCurrentSelection(t,this.editorId)},editor:t,editorId:this.editorId}),t.setPopupInstance("heading",e)}this.customSelect=e}static createForEditor(t){const e=S.getInstanceById(t);if(!e)return null;const i=S.currentInstance;S.currentInstance=e;const o=new et;return S.currentInstance=i,o}static getTagMap(){return{H1:{tag:"H1",element:'<h1 style="margin:0">Heading 1</h1>',title:"Heading 1"},H2:{tag:"H2",element:'<h2 style="margin:0">Heading 2</h2>',title:"Heading 2"},H3:{tag:"H3",element:'<h3 style="margin:0">Heading 3</h3>',title:"Heading 3"},H4:{tag:"H4",element:'<h4 style="margin:0">Heading 4</h4>',title:"Heading 4"},H5:{tag:"H5",element:'<h5 style="margin:0">Heading 5</h5>',title:"Heading 5"},H6:{tag:"H6",element:'<h6 style="margin:0">Heading 6</h6>',title:"Heading 6"},P:{tag:"P",element:'<p style="margin:0">Paragraph</p>',title:"Paragraph"},PRE:{tag:"PRE",element:'<pre style="margin:0">Code</pre>',title:"Preformatted"},BLOCKQUOTE:{tag:"BLOCKQUOTE",element:'<blockquote style="margin:0">Quote</blockquote>',title:"Quote"}}}static getTagDisplayName(t){const e=this.getTagMap();return e[t]?.title||"Paragraph"}updateButtonText(){const t=this.getCurrentTag(),e=et.getTagDisplayName(t||"P"),i=S.getInstanceById(this.editorId);if(!i)return;const o=i.getModule("toolbar");let n=null;if(o&&(n=o.getButton("heading")),!n){const t=o?.getContainer();t&&(n=t.querySelector(".rich-editor-toolbar-btn.heading-btn"))}n||(n=i.wrapper.querySelector(".rich-editor-toolbar-btn.heading-btn")),n&&n.updateText?n.updateText(e):n&&(n.textContent=e)}static create(t="P"){return document.createElement(t.toUpperCase())}static applyTagToCurrentSelection(t,e=null){let i=null;if(i=e?S.getInstanceById(e):S.getCurrentInstance(),!i)return;const o=window.getSelection();if(!o||!o.rangeCount)return;B(),o.getRangeAt(0);const n=et.createForEditor(e);n&&(n.apply(t),n.updateButtonText()),setTimeout(()=>{i&&"function"==typeof i.onContentChange&&i.onContentChange()},0)}apply(t="P"){const e=window.getSelection();if(!e||!e.rangeCount)return;const i=e.getRangeAt(0);i.collapsed;const o=this.getBlockElements(i);if(0===o.length){const n=this.createBlockAtCursor(i,t),r=document.createRange();r.setStart(n,0),r.collapse(!0),e.removeAllRanges(),e.addRange(r)}else{const s=window.getSelection();if(!s.rangeCount)return;const a=s.getRangeAt(0),l=a.collapsed,c=Array.from(o);function d(t,e){for(;t&&9!==t.nodeType;){const i=e.indexOf(t);if(-1!==i)return i;t=t.parentNode}return-1}function h(t,e,i){const o=document.createRange();return o.setStart(t,0),o.setEnd(e,i),o.toString().length}const p=d(a.startContainer,c),u=d(a.endContainer,c);let m=0,g=0;-1!==p&&(m=h(c[p],a.startContainer,a.startOffset)),l||-1===u||(g=h(c[u],a.endContainer,a.endOffset));const f=c.map(e=>this.convertBlock(e,t)||e);function y(t,e){const i=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,null,!1);let o,n=e;for(;o=i.nextNode();){const t=o.nodeValue.length;if(n<=t)return{node:o,offset:n};n-=t}return{node:t,offset:t.childNodes.length}}const b=document.createRange();if(l){const v=y(f[-1!==p?p:0],m);v.node.nodeType===Node.TEXT_NODE?b.setStart(v.node,v.offset):b.setStart(v.node,Math.max(0,v.offset)),b.collapse(!0)}else{if(-1===p||-1===u)return s.removeAllRanges(),void s.addRange(a);const x=y(f[p],m),C=y(f[u],g);x.node.nodeType===Node.TEXT_NODE?b.setStart(x.node,x.offset):b.setStart(x.node,Math.min(x.offset,x.node.childNodes.length)),C.node.nodeType===Node.TEXT_NODE?b.setEnd(C.node,C.offset):b.setEnd(C.node,Math.min(C.offset,C.node.childNodes.length))}s.removeAllRanges(),s.addRange(b)}}createBlockAtCursor(t,e){const i=this.constructor.create(e),o=this.getBlockElement(t.startContainer);if(o&&o.style&&o.style.cssText&&(i.style.cssText=o.style.cssText),t.collapsed){i.appendChild(document.createTextNode("")),t.insertNode(i);const e=document.createRange();e.setStart(i,0),e.collapse(!0);const o=window.getSelection();o.removeAllRanges(),o.addRange(e)}else{const e=t.extractContents();i.appendChild(e),t.insertNode(i);const o=document.createRange();o.selectNodeContents(i);const n=window.getSelection();n.removeAllRanges(),n.addRange(o)}}convertBlock(t,e){const i=this.constructor.create(e);for(;t.firstChild;)i.appendChild(t.firstChild);return t.className&&this.shouldPreserveClass(t.className)&&(i.className=t.className),t.style&&t.style.cssText&&(i.style.cssText=t.style.cssText),t.parentNode.replaceChild(i,t),i}setCursorAtStartOfBlock(t){const e=window.getSelection(),i=document.createRange(),o=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,null,!1).nextNode();o?(i.setStart(o,0),i.collapse(!0)):(i.setStart(t,0),i.collapse(!0)),e.removeAllRanges(),e.addRange(i)}async toggle(){this.customSelect.isVisible?this.customSelect.hide():await this.showTagPicker()}async showTagPicker(){const t=S.getInstanceById(this.editorId);if(!t)return;const e=t.getModule("toolbar");let i=null;if(e&&(i=e.getButton("heading")),!i){const t=e?.getContainer();t&&(i=t.querySelector(".rich-editor-toolbar-btn.heading-btn"))}if(i||(i=t.wrapper.querySelector(".rich-editor-toolbar-btn.heading-btn")),!i)return;const o=this.getCurrentTag();o&&this.customSelect.setCurrentValue(o),await this.customSelect.show(i)}isActive(t=null){return this.updateButtonText(),!1}getCurrentTag(){const t=window.getSelection();if(!t||!t.rangeCount)return null;const e=t.getRangeAt(0),i=this.getBlockElement(e.startContainer);if(!i)return null;return["H1","H2","H3","H4","H5","H6","P","PRE","BLOCKQUOTE"].includes(i.tagName)?i.tagName:null}}class it extends L{static formatName="fontFamily";static tagName="SPAN";constructor(){super();const t=S.getCurrentInstance();if(!t)return;this.editorId=t.instanceId;let e=t.getPopupInstance("font-family");if(!e){const i=it.getFontMap(),o=Object.values(i).map(t=>({value:t.font,label:t.element,title:t.title}));e=new tt({items:o,displayProperty:"label",valueProperty:"value",className:"font-family-select",onItemSelect:(t,e)=>{it.applyFontFamilyToCurrentSelection(t,this.editorId)},editor:t,editorId:this.editorId}),t.setPopupInstance("font-family",e)}this.customSelect=e,this.setupSelectionListener()}static createForEditor(t){const e=S.getInstanceById(t);if(!e)return null;const i=S.currentInstance;S.currentInstance=e;const o=new it;return S.currentInstance=i,o}setupSelectionListener(){let t;const e=()=>{clearTimeout(t),t=setTimeout(()=>{const t=window.getSelection();if(t&&t.rangeCount>0){const e=t.getRangeAt(0),i=S.getInstanceById(this.editorId);i&&(i.editor.contains(e.startContainer)||i.editor.isSameNode(e.startContainer))&&this.updateButtonText()}},50)};document.addEventListener("selectionchange",e),document.addEventListener("mouseup",e),document.addEventListener("keyup",e),this.selectionListener=e}static getFontMap(){return{Arial:{font:"Arial, sans-serif",element:'<span style="font-family: Arial, sans-serif">Arial</span>',title:"Arial"},Helvetica:{font:"Helvetica, Arial, sans-serif",element:'<span style="font-family: Helvetica, Arial, sans-serif">Helvetica</span>',title:"Helvetica"},"Times New Roman":{font:'"Times New Roman", Times, serif',element:"<span style=\"font-family: 'Times New Roman', Times, serif\">Times New Roman</span>",title:"Times New Roman"},Georgia:{font:"Georgia, serif",element:'<span style="font-family: Georgia, serif">Georgia</span>',title:"Georgia"},Verdana:{font:"Verdana, Geneva, sans-serif",element:'<span style="font-family: Verdana, Geneva, sans-serif">Verdana</span>',title:"Verdana"},"Courier New":{font:'"Courier New", Courier, monospace',element:"<span style=\"font-family: 'Courier New', Courier, monospace\">Courier New</span>",title:"Courier New"},"Trebuchet MS":{font:'"Trebuchet MS", Helvetica, sans-serif',element:"<span style=\"font-family: 'Trebuchet MS', Helvetica, sans-serif\">Trebuchet MS</span>",title:"Trebuchet MS"},"Comic Sans MS":{font:'"Comic Sans MS", cursive',element:"<span style=\"font-family: 'Comic Sans MS', cursive\">Comic Sans MS</span>",title:"Comic Sans MS"},Impact:{font:"Impact, Charcoal, sans-serif",element:'<span style="font-family: Impact, Charcoal, sans-serif">Impact</span>',title:"Impact"},"Lucida Console":{font:'"Lucida Console", Monaco, monospace',element:"<span style=\"font-family: 'Lucida Console', Monaco, monospace\">Lucida Console</span>",title:"Lucida Console"}}}static getFontDisplayName(t){const e=this.getFontMap();for(const[i,o]of Object.entries(e))if(o.font===t||i===t)return o.title;return"Arial"}updateButtonText(){const t=this.getCurrentFont(),e=it.getFontDisplayName(t||"Arial, sans-serif"),i=S.getInstanceById(this.editorId);if(!i)return;const o=i.getModule("toolbar");let n=null;if(o&&(n=o.getButton("font-family")),!n){const t=o?.getContainer();t&&(n=t.querySelector(".rich-editor-toolbar-btn.font-family-btn"))}n||(n=i.wrapper.querySelector(".rich-editor-toolbar-btn.font-family-btn")),n&&n.updateText?n.updateText(e):n&&(n.textContent=e)}static create(t="Arial, sans-serif"){const e=document.createElement("span");return e.style.fontFamily=t,e}static applyFontFamilyToCurrentSelection(t,e=null){let i=null;if(i=e?S.getInstanceById(e):S.getCurrentInstance(),!i)return;const o=window.getSelection();if(!o||!o.rangeCount)return;B(),o.getRangeAt(0);const n=it.createForEditor(e);n&&(n.apply(t),n.updateButtonText()),setTimeout(()=>{i&&"function"==typeof i.onContentChange&&i.onContentChange()},0)}apply(t="Arial, sans-serif"){const e=window.getSelection();if(!e||!e.rangeCount)return;const o=e.getRangeAt(0);function n(t){const e=window.getSelection(),i=document.createRange(),o=t.firstChild;i.setStart(o,o.length),i.collapse(!0),e.removeAllRanges(),e.addRange(i)}if(o.collapsed){if(function(t,e){if(!t.rangeCount)return!1;let i=t.getRangeAt(0).startContainer;i.nodeType===Node.TEXT_NODE&&(i=i.parentNode);const o=e.split(",")[0].trim().toLowerCase();for(;i&&i.nodeType===Node.ELEMENT_NODE;){if("SPAN"===i.tagName){const t=i.style.fontFamily;if(t&&t.split(",")[0].trim().toLowerCase()===o)return 1===i.childNodes.length&&i.firstChild.nodeType===Node.TEXT_NODE&&i.firstChild.textContent,!0}i=i.parentNode}return!1}(e,t))return;let i=o.startContainer;o.startOffset,i.nodeType===Node.TEXT_NODE&&(i=i.parentNode);const r=i.closest&&i.closest("span");if(r&&"​"===r.textContent)return void(r.style.fontFamily=t);if(r&&r.firstChild&&r.firstChild.nodeType===Node.TEXT_NODE){const e=r.firstChild,i=o.startOffset,s=e.data.slice(0,i),a=e.data.slice(i),l=r.parentNode;if(0===i){const e=document.createElement("span");e.style.fontFamily=t,e.appendChild(document.createTextNode("​")),l.insertBefore(e,r),n(e)}else if(i===e.data.length){const e=document.createElement("span");e.style.fontFamily=t,e.appendChild(document.createTextNode("​")),l.insertBefore(e,r.nextSibling),n(e)}else{const e=document.createElement("span");e.style.fontFamily=r.style.fontFamily,e.appendChild(document.createTextNode(s));const i=document.createElement("span");i.style.fontFamily=t,i.appendChild(document.createTextNode("​"));const o=document.createElement("span");o.style.fontFamily=r.style.fontFamily,o.appendChild(document.createTextNode(a)),l.insertBefore(e,r),l.insertBefore(i,r),l.insertBefore(o,r),l.removeChild(r),n(i)}return}const s=document.createElement("span");s.style.fontFamily=t,s.appendChild(document.createTextNode("​")),o.insertNode(s),n(s)}else i("fontName",t)}async toggle(t=null){this.customSelect.isVisible?this.customSelect.hide():await this.showFontPicker(t)}async showFontPicker(t=null){let e=t;if(!e){const t=S.getInstanceById(this.editorId);if(!t)return;const i=t.getModule("toolbar");if(i&&(e=i.getButton("font-family")),!e){const t=i?.getContainer();t&&(e=t.querySelector(".rich-editor-toolbar-btn.font-family-btn"))}e||(e=t.wrapper.querySelector(".rich-editor-toolbar-btn.font-family-btn"))}if(!e)return;const i=this.getCurrentFont();i&&this.customSelect.setCurrentValue(i),await this.customSelect.show(e)}isActive(t=null){return this.updateButtonText(),!1}getCurrentFont(){const t=window.getSelection();if(!t||!t.rangeCount)return null;let e=t.getRangeAt(0).startContainer;e.nodeType===Node.TEXT_NODE&&(e=e.parentElement);const i=S.getInstanceById(this.editorId);if(!i)return"Arial, sans-serif";if(!i.editor.contains(e)&&!i.editor.isSameNode(e))return"Arial, sans-serif";for(;e&&e!==document.body;){if(e.nodeType===Node.ELEMENT_NODE){const t=e;if(t.style.fontFamily)return t.style.fontFamily;const i=window.getComputedStyle(t).fontFamily;if(i&&"initial"!==i&&"inherit"!==i)return i}e=e.parentElement}return"Arial, sans-serif"}setCurrentFont(t){this.currentFont=t}}class ot extends L{static formatName="lineHeight";static tagName="SPAN";constructor(){super();const t=S.getCurrentInstance();if(!t)return;this.editorId=t.instanceId;let e=t.getPopupInstance("line-height");if(!e){const i=ot.getHeightMap(),o=Object.values(i).map(t=>({value:t.height,label:t.element,title:t.title}));e=new tt({items:o,displayProperty:"label",valueProperty:"value",className:"line-height-select",onItemSelect:(t,e)=>{ot.applyLineHeightToCurrentSelection(t,this.editorId)},editor:t,editorId:this.editorId}),t.setPopupInstance("line-height",e)}this.customSelect=e,this.setupSelectionListener()}static createForEditor(t){const e=S.getInstanceById(t);if(!e)return null;const i=S.currentInstance;S.currentInstance=e;const o=new ot;return S.currentInstance=i,o}setupSelectionListener(){let t;const e=()=>{clearTimeout(t),t=setTimeout(()=>{const t=window.getSelection();if(t&&t.rangeCount>0){const e=t.getRangeAt(0),i=S.getInstanceById(this.editorId);i&&(i.editor.contains(e.startContainer)||i.editor.isSameNode(e.startContainer))&&this.updateButtonText()}},50)};document.addEventListener("selectionchange",e),document.addEventListener("mouseup",e),document.addEventListener("keyup",e),this.selectionListener=e}static getHeightMap(){return{"1.0":{height:"1",element:"<span>1.0</span>",title:"1.0"},1.2:{height:"1.2",element:"<span>1.2</span>",title:"1.2"},1.5:{height:"1.5",element:"<span>1.5</span>",title:"1.5"},1.8:{height:"1.8",element:"<span>1.8</span>",title:"1.8"},"2.0":{height:"2",element:"<span>2.0</span>",title:"2.0"},2.5:{height:"2.5",element:"<span>2.5</span>",title:"2.5"},"3.0":{height:"3",element:"<span>3.0</span>",title:"3.0"}}}static getHeightDisplayName(t){const e=this.getHeightMap();if(e[t]?.title)return e[t].title;const i=parseFloat(t);return isNaN(i)?"Normal":String(i)}updateButtonText(){const t=this.getCurrentHeight(),e=ot.getHeightDisplayName(t||"1.15"),i=S.getInstanceById(this.editorId);if(!i)return;const o=i.getModule("toolbar");let n=null;if(o&&(n=o.getButton("line-height")),!n){const t=o?.getContainer();t&&(n=t.querySelector(".rich-editor-toolbar-btn.line-height-btn"))}n||(n=i.wrapper.querySelector(".rich-editor-toolbar-btn.line-height-btn")),n&&n.updateText?n.updateText(e):n&&(n.textContent=e)}static create(t="1.15"){const e=document.createElement("span");return e.style.lineHeight=t,e}static applyLineHeightToCurrentSelection(t,e=null){let i=null;if(i=e?S.getInstanceById(e):S.getCurrentInstance(),!i)return;const o=window.getSelection();if(!o||!o.rangeCount)return;B(),o.getRangeAt(0);const n=ot.createForEditor(e);n&&(n.apply(t),n.updateButtonText()),setTimeout(()=>{i&&"function"==typeof i.onContentChange&&i.onContentChange()},0)}apply(t="1.15"){const e=window.getSelection();if(!e||!e.rangeCount)return;B();const i=e.getRangeAt(0);if(i.collapsed){let e=i.startContainer;e.nodeType===Node.TEXT_NODE&&(e=e.parentNode);const o=e.closest("div, p, li, section, article")||e;return o.style.lineHeight=t,void function(t){const e=window.getSelection(),i=document.createRange(),o=t.firstChild;i.setStart(o,o.length),i.collapse(!0),e.removeAllRanges(),e.addRange(i)}(o)}const o=this.getBlockElementsInRange(i);if(o.length>0)o.forEach(e=>{e.style.lineHeight=t});else{const o=this.constructor.create(t);try{const t=i.extractContents();o.appendChild(t),i.insertNode(o);const n=document.createRange();n.selectNodeContents(o),e.removeAllRanges(),e.addRange(n)}catch(t){}}}getBlockElementsInRange(t){const e=[],i=["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","PRE","UL","OL","LI"],o=t.cloneContents(),n=document.createTreeWalker(o,NodeFilter.SHOW_ELEMENT,{acceptNode:t=>i.includes(t.tagName)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP});let r=n.nextNode();for(;r;){const i=t.commonAncestorContainer.querySelector(`${r.tagName.toLowerCase()}:not([data-processed])`);i&&t.intersectsNode(i)&&(e.push(i),i.setAttribute("data-processed","true")),r=n.nextNode()}if(e.forEach(t=>t.removeAttribute("data-processed")),0===e.length){let o=t.startContainer;for(o.nodeType===Node.TEXT_NODE&&(o=o.parentElement);o&&o!==document.body;){if(o.nodeType===Node.ELEMENT_NODE&&i.includes(o.tagName)){e.push(o);break}o=o.parentElement}}return e}async toggle(){this.customSelect.isVisible?this.customSelect.hide():await this.showHeightPicker()}async showHeightPicker(){const t=S.getInstanceById(this.editorId);if(!t)return;const e=t.getModule("toolbar");let i=null;if(e&&(i=e.getButton("line-height")),!i){const t=e?.getContainer();t&&(i=t.querySelector(".rich-editor-toolbar-btn.line-height-btn"))}if(i||(i=t.wrapper.querySelector(".rich-editor-toolbar-btn.line-height-btn")),!i)return;const o=this.getCurrentHeight();o&&this.customSelect.setCurrentValue(o),await this.customSelect.show(i)}isActive(t=null){return this.updateButtonText(),!1}getCurrentHeight(){const t=window.getSelection();if(!t||!t.rangeCount)return null;let e=t.getRangeAt(0).startContainer;e.nodeType===Node.TEXT_NODE&&(e=e.parentElement);const i=S.getInstanceById(this.editorId);if(!i)return"1.15";if(!i.editor.contains(e)&&!i.editor.isSameNode(e))return"1.15";for(;e&&e!==document.body;){if(e.nodeType===Node.ELEMENT_NODE){const t=e;if(t.style.lineHeight){const e=t.style.lineHeight;return this.normalizeHeightValue(e)}const i=window.getComputedStyle(t),o=i.lineHeight;if(o&&"normal"!==o&&"initial"!==o&&"inherit"!==o){if(o.endsWith("px")){const t=parseFloat(i.fontSize),e=parseFloat(o);if(t>0){const i=(e/t).toFixed(2);return this.normalizeHeightValue(i)}}return this.normalizeHeightValue(o)}}e=e.parentElement}return"1.15"}normalizeHeightValue(t){if(!t)return"1.15";const e=parseFloat(t);if(isNaN(e))return"1.15";const i=e.toFixed(1);return this.constructor.getHeightMap()[i]?i:t}destroy(){this.selectionListener&&(document.removeEventListener("selectionchange",this.selectionListener),document.removeEventListener("mouseup",this.selectionListener),document.removeEventListener("keyup",this.selectionListener),this.selectionListener=null)}}class nt extends L{static formatName="capitalization";static tagName="SPAN";constructor(){super();const t=S.getCurrentInstance();if(!t)return;this.editorId=t.instanceId;let e=t.getPopupInstance("capitalization");if(!e){const i=nt.getCapitalizationMap(),o=Object.values(i).map(t=>({value:t.style,label:t.element,title:t.title}));e=new tt({items:o,displayProperty:"label",valueProperty:"value",className:"capitalization-select",onItemSelect:(t,e)=>{nt.applyCapitalizationToCurrentSelection(t,this.editorId)},editor:t,editorId:this.editorId}),t.setPopupInstance("capitalization",e)}this.customSelect=e}static createForEditor(t){const e=S.getInstanceById(t);if(!e)return null;const i=S.currentInstance;S.currentInstance=e;const o=new nt;return S.currentInstance=i,o}static getCapitalizationMap(){return{capitalize:{style:"capitalize",element:"<span>Capitalize</span>",title:"Capitalize"},uppercase:{style:"uppercase",element:"<span>UPPERCASE</span>",title:"UPPERCASE"},lowercase:{style:"lowercase",element:"<span>lowercase</span>",title:"lowercase"},"small-caps":{style:"small-caps",element:"<span>Small Caps</span>",title:"Small Caps"}}}static getCapitalizationDisplayName(t){const e=this.getCapitalizationMap();return e[t]?.title||"Capitalization"}updateButtonText(){const t=this.getCurrentCapitalization(),e=nt.getCapitalizationDisplayName(t||"none"),i=S.getInstanceById(this.editorId);if(!i)return;const o=i.getModule("toolbar");let n=null;if(o&&(n=o.getButton("capitalization")),!n){const t=o?.getContainer();t&&(n=t.querySelector(".rich-editor-toolbar-btn.capitalization-btn"))}n||(n=i.wrapper.querySelector(".rich-editor-toolbar-btn.capitalization-btn")),n&&n.updateText?n.updateText(e):n&&(n.textContent=e)}static create(t="none"){const e=document.createElement("span");return"small-caps"===t?e.style.fontVariant="small-caps":e.style.textTransform=t,e}static applyCapitalizationToCurrentSelection(t,e=null){let i=null;if(i=e?S.getInstanceById(e):S.getCurrentInstance(),!i)return;const o=window.getSelection();if(!o||!o.rangeCount)return;B(),o.getRangeAt(0);const n=nt.createForEditor(e);n&&(n.apply(t),n.updateButtonText()),setTimeout(()=>{i&&"function"==typeof i.onContentChange&&i.onContentChange()},0)}hasCapitalizationStyling(t){if(!t||t.nodeType!==Node.ELEMENT_NODE)return!1;if("small-caps"===t.style.fontVariant)return!0;if(t.style.textTransform&&"none"!==t.style.textTransform)return!0;const e=window.getComputedStyle(t);return"small-caps"===e.fontVariant||!(!e.textTransform||"none"===e.textTransform)}isCapitalizationElement(t){return!(!t||t.nodeType!==Node.ELEMENT_NODE)&&("small-caps"===t.style.fontVariant||!(!t.style.textTransform||"none"===t.style.textTransform))}findAncestorCapitalizationElement(t){let e=t;if(!e)return null;for(e.nodeType===Node.TEXT_NODE&&(e=e.parentElement);e&&e!==document.body;){if(this.isCapitalizationElement(e))return e;e=e.parentElement}return null}setElementCapitalizationStyle(t,e){t&&("small-caps"===e?(t.style.fontVariant="small-caps",t.style.textTransform=""):"none"===e?(t.style.fontVariant="",t.style.textTransform=""):(t.style.fontVariant="",t.style.textTransform=e))}apply(t="none"){const e=window.getSelection();if(!e||!e.rangeCount)return;B();const i=e.getRangeAt(0);if(i.collapsed)return;if("small-caps"===t){const t=i.extractContents(),o=document.createElement("span");o.style.fontVariant="small-caps",o.appendChild(t),i.insertNode(o);const n=document.createRange();return n.selectNodeContents(o),e.removeAllRanges(),void e.addRange(n)}function o(t,e){switch(e){case"uppercase":return t.toUpperCase();case"lowercase":return t.toLowerCase();case"capitalize":return(t=t.toLowerCase()).replace(/\b\w/g,t=>t.toUpperCase());default:return t}}const n=i.extractContents(),r=document.createTreeWalker(n,NodeFilter.SHOW_TEXT,null);for(;r.nextNode();){const e=r.currentNode;e.textContent=o(e.textContent,t)}i.deleteContents(),i.insertNode(n),function(t){if(!t)return;const e=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,null),i=[];for(;e.nextNode();){const t=e.currentNode;t.textContent.trim()||0!==t.childElementCount||i.push(t)}i.forEach(t=>t.remove())}(i.commonAncestorContainer),e.removeAllRanges(),e.addRange(i)}removeExistingCapitalization(t){const e=t.commonAncestorContainer,i=new Set,o=e=>{e&&e.nodeType===Node.ELEMENT_NODE&&this.hasCapitalizationStyling(e)&&t.intersectsNode(e)&&i.add(e)};e&&e.nodeType===Node.ELEMENT_NODE&&o(e);const n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>t.intersectsNode(e)&&this.hasCapitalizationStyling(e)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP});let r;for(;r=n.nextNode();)i.add(r);const s=t=>{let e=t.nodeType===Node.TEXT_NODE?t.parentElement:t;for(;e&&e!==document.body;)o(e),e=e.parentElement};s(t.startContainer),s(t.endContainer),Array.from(i).forEach(t=>{t.style.textTransform="",t.style.fontVariant="",t.style.cssText.trim()||t.className||this.unwrapElement(t)})}unwrapElement(t){const e=t.parentNode;if(e){for(;t.firstChild;)e.insertBefore(t.firstChild,t);e.removeChild(t)}}async toggle(){this.customSelect.isVisible?this.customSelect.hide():await this.showCapitalizationPicker()}async showCapitalizationPicker(){const t=S.getInstanceById(this.editorId);if(!t)return;const e=t.getModule("toolbar");let i=null;if(e&&(i=e.getButton("capitalization")),!i){const t=e?.getContainer();t&&(i=t.querySelector(".rich-editor-toolbar-btn.capitalization-btn"))}if(i||(i=t.wrapper.querySelector(".rich-editor-toolbar-btn.capitalization-btn")),!i)return;const o=this.getCurrentCapitalization();o&&this.customSelect.setCurrentValue(o),await this.customSelect.show(i)}isActive(t=null){return this.updateButtonText(),!1}getCurrentCapitalization(){const t=window.getSelection();if(!t||!t.rangeCount)return null;let e=t.getRangeAt(0).startContainer;for(e.nodeType===Node.TEXT_NODE&&(e=e.parentElement);e&&e!==document.body;){if(e.nodeType===Node.ELEMENT_NODE){const t=e;if("small-caps"===t.style.fontVariant)return"small-caps";if(t.style.textTransform&&"none"!==t.style.textTransform)return t.style.textTransform;const i=window.getComputedStyle(t);if("small-caps"===i.fontVariant)return"small-caps";if(i.textTransform&&"none"!==i.textTransform)return i.textTransform}e=e.parentElement}return"none"}setCurrentCapitalization(t){this.currentCapitalization=t}static toggleUppercase(){const t="uppercase"===(new nt).getCurrentCapitalization()?"none":"uppercase";nt.applyCapitalizationToCurrentSelection(t)}static toggleLowercase(){const t="lowercase"===(new nt).getCurrentCapitalization()?"none":"lowercase";nt.applyCapitalizationToCurrentSelection(t)}static toggleCapitalize(){const t="capitalize"===(new nt).getCurrentCapitalization()?"none":"capitalize";nt.applyCapitalizationToCurrentSelection(t)}static toggleSmallCaps(){const t="small-caps"===(new nt).getCurrentCapitalization()?"none":"small-caps";nt.applyCapitalizationToCurrentSelection(t)}}class rt{constructor(t={}){this.options={alignments:[{value:"left",label:"Align Left",icon:"align-left"},{value:"center",label:"Align Center",icon:"align-center"},{value:"right",label:"Align Right",icon:"align-right"},{value:"justify",label:"Justify",icon:"align-justify"}],onAlignSelect:null,...t},this.popup=null,this.isVisible=!1,this.currentAlignment="left",this.clickOutsideHandler=null,this.createAlignPicker()}createAlignPicker(){this.popup=document.createElement("div"),this.popup.className="text-align-picker-popup",this.createAlignmentButtons(),U(this.popup)}async createAlignmentButtons(){const t=document.createElement("div");t.className="align-button-container";for(const e of this.options.alignments){const i=document.createElement("button");i.type="button",i.className="align-button",i.dataset.alignment=e.value,i.title=e.label;const o=F.getIcon(e.icon);o?i.innerHTML=`<span class="icon-wrapper">${o}</span>`:i.textContent=e.label.charAt(0),i.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),this.selectAlignment(e.value)}),t.appendChild(i)}this.popup.appendChild(t)}setupClickOutside(){this.clickOutsideHandler&&document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=t=>{this.popup.contains(t.target)||this.hide()},setTimeout(()=>{document.addEventListener("click",this.clickOutsideHandler)},100)}removeClickOutside(){this.clickOutsideHandler&&(document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=null)}show(t){if(!t)return;document.body.contains(this.popup)||U(this.popup),this.updateCurrentAlignment();const e=W(t,this.popup,{offsetY:5,offsetX:0});$(this.popup,e),this.popup.classList.add("visible"),this.isVisible=!0,this.setupClickOutside()}hide(){this.popup.classList.remove("visible"),this.isVisible=!1,this.removeClickOutside()}selectAlignment(t){this.currentAlignment=t,this.options.onAlignSelect&&this.options.onAlignSelect(t),this.hide()}updateCurrentAlignment(){const t=window.getSelection();if(t&&t.rangeCount)try{const e=t.getRangeAt(0),i=this.getSelectedBlockElements(e),o=i.length>0?i[0]:this.getBlockElement(e.commonAncestorContainer);if(o){const t=window.getComputedStyle(o).textAlign;this.currentAlignment="left"!==t&&"start"!==t&&t?t:"left"}else this.currentAlignment="left";this.popup.querySelectorAll(".align-button").forEach(t=>{t.dataset.alignment===this.currentAlignment?t.classList.add("active"):t.classList.remove("active")}),this.updateToolbarButtonIcon(this.currentAlignment)}catch(t){}}getSelectedBlockElements(t){const e=[],i=this.getBlockElement(t.startContainer),o=this.getBlockElement(t.endContainer);if(i&&e.push(i),i&&o&&i!==o){let t=i;for(;t&&t!==o;)t=t.nextElementSibling,t&&this.getBlockElement(t)&&!e.includes(t)&&e.push(t);o&&!e.includes(o)&&e.push(o)}return e}updateToolbarButtonIcon(t){Promise.resolve().then(function(){return at}).then(e=>{e.default.updateToolbarButtonIcon(t)}).catch(t=>{})}getBlockElement(t){if(!t)return null;let e=t;for(;e&&e!==document.body;){if(e.nodeType===Node.ELEMENT_NODE){const t=e.tagName;if(["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","LI"].includes(t))return e}e=e.parentNode}return null}destroy(){this.removeClickOutside(),this.popup&&this.popup.parentNode&&this.popup.parentNode.removeChild(this.popup)}}class st extends A{static formatName="text-align";static tagName="P";static attribute="style";constructor(){super();const t=S.getCurrentInstance();if(!t)return;this.editorId=t.instanceId;let e=t.getPopupInstance("text-align");e||(e=new rt({onAlignSelect:t=>{st.applyAlignToCurrentSelection(t,this.editorId)},editor:t,editorId:this.editorId}),t.setPopupInstance("text-align",e)),this.alignPicker=e}static createForEditor(t){const e=S.getInstanceById(t);if(!e)return null;const i=S.currentInstance;S.currentInstance=e;const o=new st;return S.currentInstance=i,o}static create(t){const e=document.createElement(this.tagName);return t&&"left"!==t&&(e.style.textAlign=t),e}static applyAlignToCurrentSelection(t,e=null){let o=null;if(o=e?S.getInstanceById(e):S.getCurrentInstance(),!o)return;const n=window.getSelection();if(!n||!n.rangeCount)return;B();const r=n.getRangeAt(0),s=r.endContainer,a=r.endOffset;try{const o=n.getRangeAt(0),r=st.getSelectedBlockElements(o);if(0===r.length){i("formatBlock","p");const e=n.getRangeAt(0);st.getSelectedBlockElements(e).forEach(e=>{st.applyAlignmentToBlock(e,t)})}else r.forEach(e=>{st.applyAlignmentToBlock(e,t)});st.updateToolbarButtonIcon(t,e),n.removeAllRanges();const l=document.createRange();l.setStart(s,a),l.collapse(!0),n.addRange(l)}catch(t){}setTimeout(()=>{o&&"function"==typeof o.onContentChange&&o.onContentChange()},0)}static applyAlignmentToBlock(t,e){t.style.textAlign="left"===e?"":e}static getIconNameForAlignment(t){return{left:"align-left",center:"align-center",right:"align-right",justify:"align-justify"}[t]||"align-center"}static updateToolbarButtonIcon(t,e=null){let i=null;if(i=e?S.getInstanceById(e):S.getCurrentInstance(),!i)return;const o=i.getModule("toolbar");let n=null;if(o&&(n=o.getButton("text-align")),!n){const t=o?.getContainer();t&&(n=t.querySelector(".rich-editor-toolbar-btn.text-align-btn"))}if(n||(n=i.wrapper.querySelector(".rich-editor-toolbar-btn.text-align-btn")),!n)return;const r=st.getIconNameForAlignment(t);n.title={left:"Align Left",center:"Align Center",right:"Align Right",justify:"Justify"}[t]||"Text Alignment";const s=F.getIcon(r);if(s){const t=n.querySelector(".icon");t?t.innerHTML=s:n.innerHTML=`<span class="icon">${s}</span>`}}static getSelectedBlockElements(t){const e=[],i=st.getBlockElement(t.startContainer),o=st.getBlockElement(t.endContainer);if(!i||!o)return e;if(i===o)return e.push(i),e;let n=i;for(;n;){const i=document.createRange();if(i.selectNodeContents(n),t.compareBoundaryPoints(Range.END_TO_START,i)<0&&t.compareBoundaryPoints(Range.START_TO_END,i)>0&&e.push(n),n===o)break;n=st.getNextBlockElement(n)}return e}static getBlockElement(t){if(!t)return null;let e=t;for(;e&&e!==document.body;){if(e.nodeType===Node.ELEMENT_NODE){const t=e.tagName;if(["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","LI"].includes(t))return e}e=e.parentNode}return null}static getNextBlockElement(t){let e=t.nextSibling;for(;e;){if(e.nodeType===Node.ELEMENT_NODE){const t=e.tagName;if(["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","LI"].includes(t))return e}e=e.nextSibling}return null}apply(t="left"){st.applyAlignToCurrentSelection(t,this.editorId)}remove(){st.applyAlignToCurrentSelection("left",this.editorId)}toggle(){this.alignPicker.isVisible?this.alignPicker.hide():this.showAlignPicker()}showAlignPicker(){const t=S.getInstanceById(this.editorId);if(!t)return;const e=t.getModule("toolbar");let i=null;if(e&&(i=e.getButton("text-align")),!i){const t=e?.getContainer();t&&(i=t.querySelector(".rich-editor-toolbar-btn.text-align-btn"))}i||(i=t.wrapper.querySelector(".rich-editor-toolbar-btn.text-align-btn")),i&&this.alignPicker.show(i)}isActive(t=null){const e=st.getCurrentAlignment();return st.updateToolbarButtonIcon(e,this.editorId),!!e&&"left"!==e&&"start"!==e}static getCurrentAlignment(){const t=window.getSelection();if(!t||!t.rangeCount)return"left";try{const e=t.getRangeAt(0),i=st.getSelectedBlockElements(e),o=i.length>0?i[0]:st.getBlockElement(e.commonAncestorContainer);if(!o)return"left";const n=window.getComputedStyle(o).textAlign;return"left"!==n&&"start"!==n&&n?n:"left"}catch(t){return"left"}}}var at=Object.freeze({__proto__:null,default:st});class lt{constructor(t={}){this.options={listTypes:[{value:"bullet",label:"Bullet List",icon:"list-bullet"},{value:"ordered",label:"Numbered List",icon:"list-ordered"},{value:"roman",label:"Roman Numerals List",icon:"list-roman"},{value:"alpha",label:"Alphabetical List",icon:"list-alpha"}],onListSelect:null,...t},this.popup=null,this.isVisible=!1,this.currentListType=null,this.clickOutsideHandler=null,this.createListPicker()}createListPicker(){this.popup=document.createElement("div"),this.popup.className="list-picker-popup",this.createListTypeButtons(),U(this.popup)}async createListTypeButtons(){const t=document.createElement("div");t.className="list-button-container";for(const e of this.options.listTypes){const i=document.createElement("button");i.type="button",i.className="list-button",i.dataset.listType=e.value,i.title=e.label;const o=F.getIcon(e.icon);o?i.innerHTML=o:i.textContent=e.label.charAt(0),i.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),this.selectListType(e.value)}),t.appendChild(i)}this.popup.appendChild(t)}setupClickOutside(){this.clickOutsideHandler&&document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=t=>{this.popup.contains(t.target)||this.hide()},setTimeout(()=>{document.addEventListener("click",this.clickOutsideHandler)},100)}removeClickOutside(){this.clickOutsideHandler&&(document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=null)}show(t){if(!t)return;document.body.contains(this.popup)||U(this.popup),this.updateCurrentListType();const e=W(t,this.popup,{offsetY:5,offsetX:0});$(this.popup,e),this.popup.classList.add("visible"),this.isVisible=!0,this.setupClickOutside()}hide(){this.popup.classList.remove("visible"),this.isVisible=!1,this.removeClickOutside()}selectListType(t){this.currentListType=t,this.options.onListSelect&&this.options.onListSelect(t),this.hide()}updateCurrentListType(){try{const t=this.getCurrentListType();this.currentListType=t,this.updateButtonStates(t)}catch(t){}}updateButtonStates(t){this.popup.querySelectorAll(".list-button").forEach(e=>{e.classList.remove("active"),t&&e.dataset.listType===t&&e.classList.add("active")})}updateToolbarButtonIcon(t){const e=document.querySelector(".rich-editor-toolbar-btn.list-btn");if(!e)return;const i={bullet:"list-bullet",ordered:"list-ordered",roman:"list-roman",alpha:"list-alpha"}[t]||"list-bullet";e.title={bullet:"Bullet List",ordered:"Numbered List",roman:"Roman Numerals List",alpha:"Alphabetical List"}[t]||"List";const o=F.getIcon(i);if(o){const t=e.querySelector(".icon");t?t.innerHTML=o:e.innerHTML=`<span class="icon">${o}</span>`}}getParentList(t){let e=t;for(;e&&e!==document.body;){if("UL"===e.tagName||"OL"===e.tagName)return e;e=e.parentElement}return null}getListType(t){if("OL"===t.tagName){const e=t.style.listStyleType;return"upper-roman"===e?"roman":"lower-alpha"===e?"alpha":"ordered"}return"bullet"}getBlockElement(t){if(!t)return null;let e=t;for(;e&&e!==document.body;){if(e.nodeType===Node.ELEMENT_NODE){const t=e.tagName;if(["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","LI","UL","OL"].includes(t))return e}e=e.parentNode}return null}getCurrentListType(){const t=window.getSelection();if(!t||!t.rangeCount)return null;const e=t.getRangeAt(0),i=this.getParentList(e.commonAncestorContainer);return i?this.getListType(i):null}destroy(){this.removeClickOutside(),this.popup&&this.popup.parentNode&&this.popup.parentNode.removeChild(this.popup),this.popup=null,this.isVisible=!1,this.currentListType=null}}class ct extends A{static formatName="list";static tagName="UL";static attribute="class";constructor(){super();const t=S.getCurrentInstance();if(!t)return;this.editorId=t.instanceId;let e=t.getPopupInstance("list");e||(e=new lt({onListSelect:t=>{ct.applyListToCurrentSelection(t,this.editorId)},editor:t,editorId:this.editorId}),t.setPopupInstance("list",e)),this.listPicker=e}static createForEditor(t){const e=S.getInstanceById(t);if(!e)return null;const i=S.currentInstance;S.currentInstance=e;const o=new ct;return S.currentInstance=i,o}static create(t){let e;switch(t){case"ordered":e=document.createElement("OL"),e.style.listStyleType="decimal";break;case"roman":e=document.createElement("OL"),e.style.listStyleType="upper-roman";break;case"alpha":e=document.createElement("OL"),e.style.listStyleType="lower-alpha";break;default:e=document.createElement("UL"),e.style.listStyleType="disc"}return e}static applyListToCurrentSelection(t,e=null){let i=null;if(i=e?S.getInstanceById(e):S.getCurrentInstance(),!i)return;const o=window.getSelection();if(o&&o.rangeCount){B();try{const i=o.getRangeAt(0),n=ct.getSelectedBlockElements(i);0===n.length?ct.createListFromSelection(t):ct.convertBlocksToList(n,t),ct.updateToolbarButtonIcon(t,e)}catch(t){}setTimeout(()=>{i&&"function"==typeof i.onContentChange&&i.onContentChange()},0)}}static createListFromSelection(t){const e=window.getSelection();if(!e||!e.rangeCount)return;const i=e.getRangeAt(0),o=i.toString()||"List item",n=ct.create(t),r=document.createElement("LI");if(i.toString()===i.cloneContents().textContent)r.textContent=o;else{const t=i.cloneContents();r.appendChild(t)}const s=ct.getBlockElement(i.startContainer);s&&s.style&&s.style.cssText&&(r.style.cssText=s.style.cssText),n.appendChild(r),i.deleteContents(),i.insertNode(n);const a=document.createRange();a.selectNodeContents(r),a.collapse(!1),e.removeAllRanges(),e.addRange(a)}static convertBlocksToList(t,e){if(0===t.length)return;const i=ct.getParentList(t[0]);if(i)return void ct.toggleOrChangeListType(i,e);const o=ct.create(e),n=t[0];n.parentNode.insertBefore(o,n);let r=null;if(t.forEach((t,e)=>{const i=document.createElement("LI");i.innerHTML=t.innerHTML||t.textContent||"",t.style&&t.style.cssText&&(i.style.cssText=t.style.cssText),o.appendChild(i),t.remove(),0===e&&(r=i)}),r){const t=document.createRange(),e=window.getSelection();t.selectNodeContents(r),t.collapse(!1),e.removeAllRanges(),e.addRange(t)}}static toggleOrChangeListType(t,e){ct.getListType(t)===e?ct.removeListFormatting(t):ct.changeListType(t,e)}static getListType(t){if("OL"===t.tagName){const e=t.style.listStyleType;return"upper-roman"===e?"roman":"lower-alpha"===e?"alpha":"ordered"}return"bullet"}static changeListType(t,e){const i=ct.create(e);if(Array.from(t.children).forEach(t=>{const e=document.createElement("LI");e.innerHTML=t.innerHTML||t.textContent||"",t.style&&t.style.cssText&&(e.style.cssText=t.style.cssText),i.appendChild(e)}),t.parentNode.replaceChild(i,t),i.firstElementChild){const t=document.createRange(),e=window.getSelection();t.selectNodeContents(i.firstElementChild),t.collapse(!1),e.removeAllRanges(),e.addRange(t)}}static removeListFormatting(t){const e=t.parentNode;let i=null;if(Array.from(t.children).forEach((o,n)=>{const r=document.createElement("P");r.innerHTML=o.innerHTML||o.textContent||"",o.style&&o.style.cssText&&(r.style.cssText=o.style.cssText),e.insertBefore(r,t),0===n&&(i=r)}),t.remove(),i){const t=document.createRange(),e=window.getSelection();t.selectNodeContents(i),t.collapse(!1),e.removeAllRanges(),e.addRange(t)}}static getParentList(t){let e=t;for(;e&&e!==document.body;){if("UL"===e.tagName||"OL"===e.tagName)return e;e=e.parentElement}return null}static getIconNameForListType(t){return{bullet:"list-bullet",ordered:"list-ordered",roman:"list-roman",alpha:"list-alpha"}[t]||"list-bullet"}static updateToolbarButtonIcon(t,e=null){let i=null;if(i=e?S.getInstanceById(e):S.getCurrentInstance(),!i)return;const o=i.getModule("toolbar");let n=null;if(o&&(n=o.getButton("list")),!n){const t=o?.getContainer();t&&(n=t.querySelector(".rich-editor-toolbar-btn.list-btn"))}if(n||(n=i.wrapper.querySelector(".rich-editor-toolbar-btn.list-btn")),!n)return;const r=ct.getIconNameForListType(t);n.title={bullet:"Bullet List",ordered:"Numbered List",roman:"Roman Numerals List",alpha:"Alphabetical List"}[t]||"List";const s=F.getIcon(r);if(s){const t=n.querySelector(".icon");t?t.innerHTML=s:n.innerHTML=`<span class="icon">${s}</span>`}}static getSelectedBlockElements(t){const e=[],i=t.startContainer,o=t.endContainer,n=ct.getBlockElement(i);if(n&&e.push(n),i!==o){let t=n;for(;t&&t!==o;){const i=ct.getNextBlockElement(t);if(!i||e.includes(i))break;e.push(i),t=i}const i=ct.getBlockElement(o);i&&!e.includes(i)&&e.push(i)}return e}static getBlockElement(t){if(!t)return null;let e=t;for(;e&&e!==document.body;){if(e.nodeType===Node.ELEMENT_NODE){const t=e.tagName;if(["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","LI"].includes(t))return e}e=e.parentNode}return null}static getNextBlockElement(t){let e=t.nextSibling;for(;e;){if(e.nodeType===Node.ELEMENT_NODE){const t=e.tagName;if(["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","LI"].includes(t))return e}e=e.nextSibling}return null}apply(t="bullet"){ct.applyListToCurrentSelection(t,this.editorId)}remove(){const t=window.getSelection();if(!t||!t.rangeCount)return;const e=t.getRangeAt(0),i=ct.getParentList(e.commonAncestorContainer);i&&ct.removeListFormatting(i)}toggle(){this.listPicker.isVisible?this.listPicker.hide():this.showListPicker()}showListPicker(){const t=S.getInstanceById(this.editorId);if(!t)return;const e=t.getModule("toolbar");let i=null;if(e&&(i=e.getButton("list")),!i){const t=e?.getContainer();t&&(i=t.querySelector(".rich-editor-toolbar-btn.list-btn"))}i||(i=t.wrapper.querySelector(".rich-editor-toolbar-btn.list-btn")),i&&this.listPicker.show(i)}isActive(t=null){const e=ct.getCurrentListType();return e?ct.updateToolbarButtonIcon(e,this.editorId):ct.updateToolbarButtonIcon("bullet",this.editorId),!!e}static getCurrentListType(){const t=window.getSelection();if(!t||!t.rangeCount)return null;const e=t.getRangeAt(0),i=ct.getParentList(e.commonAncestorContainer);return i?ct.getListType(i):null}getCurrentListType(){return ct.getCurrentListType()}}class dt extends A{static formatName="indent";static tagName="DIV";static attribute="style";constructor(){super()}static create(t){const e=document.createElement("DIV");return t&&(e.style.paddingLeft=t),e}static applyIndentToCurrentSelection(t){const e=window.getSelection();if(e&&e.rangeCount){B();try{const i=e.getRangeAt(0),o=dt.getSelectedBlockElements(i);if(0===o.length){const o=document.createElement("DIV");o.style.paddingLeft="increase"===t?"20px":"0px";const n=i.toString()||"";n?(o.textContent=n,i.deleteContents(),i.insertNode(o)):(i.insertNode(o),o.innerHTML="<br>");const r=document.createRange();r.selectNodeContents(o),r.collapse(!1),e.removeAllRanges(),e.addRange(r)}else o.forEach(e=>{dt.applyIndentToBlock(e,t)})}catch(t){}setTimeout(()=>{const t=S.getCurrentInstance();t&&"function"==typeof t.onContentChange&&t.onContentChange()},0)}}static applyIndentToBlock(t,e){if(!t||!t.style)return;const i=parseInt(t.style.paddingLeft)||0;let o;o="increase"===e?i+20:Math.max(0,i-20),t.style.paddingLeft=0===o?"":o+"px"}static getSelectedBlockElements(t){const e=[],i=t.startContainer,o=t.endContainer,n=dt.getBlockElement(i);if(n&&e.push(n),i!==o){let t=n;for(;t&&t!==o;){const i=dt.getNextBlockElement(t);if(!i||e.includes(i))break;e.push(i),t=i}const i=dt.getBlockElement(o);i&&!e.includes(i)&&e.push(i)}return e}static getBlockElement(t){if(!t)return null;let e=t;for(;e&&e!==document.body;){if(e.nodeType===Node.ELEMENT_NODE){const t=e.tagName;if(["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","LI"].includes(t))return e}e=e.parentNode}return null}static getNextBlockElement(t){let e=t.nextSibling;for(;e;){if(e.nodeType===Node.ELEMENT_NODE){const t=e.tagName;if(["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","LI"].includes(t))return e}e=e.nextSibling}return null}apply(t="increase"){dt.applyIndentToCurrentSelection(t)}remove(){dt.applyIndentToCurrentSelection("remove")}isActive(){const t=window.getSelection();if(!t||!t.rangeCount)return!1;const e=t.getRangeAt(0),i=dt.getBlockElement(e.commonAncestorContainer);if(!i)return!1;return(parseInt(i.style.paddingLeft)||0)>0}static getCurrentIndentLevel(){const t=window.getSelection();if(!t||!t.rangeCount)return 0;const e=t.getRangeAt(0),i=dt.getBlockElement(e.commonAncestorContainer);return i&&parseInt(i.style.paddingLeft)||0}getCurrentIndentLevel(){return dt.getCurrentIndentLevel()}}class ht extends dt{static formatName="indent-increase";apply(){dt.applyIndentToCurrentSelection("increase")}toggle(){this.apply()}isActive(){return!1}}class pt extends dt{static formatName="indent-decrease";apply(){dt.applyIndentToCurrentSelection("decrease")}toggle(){this.apply()}isActive(){return!1}}class ut{constructor(t={}){this.options={emojis:["😀","😁","😂","🤣","😃","😄","😅","😆","😉","😊","😋","😎","😍","🥰","😘","😗","😙","😚","🙂","🤗","😳","🥺","😦","😧","😨","😰","😥","😢","😭","😱","🤬","😈","👿","💀","☠️","💩","🤡","👹","👺","👻"],onEmojiSelect:null,...t},this.popup=null,this.isVisible=!1,this.clickOutsideHandler=null,this.createEmojiPicker()}detectOS(){const t=navigator.platform.toLowerCase();return t.includes("mac")?"mac":(t.includes("win"),"windows")}getEmojiShortcutMessage(){return"mac"===this.detectOS()?'<div style="color: rgb(113, 120, 124); font-style: normal; font-weight: 400; line-height: normal; text-align: center;">Get more emojis with <span style="border-radius: 2.2px; background: #EEE; padding: 2px 4px;">⌘</span> <span style="color: #000;">+</span> <span style="border-radius: 2.2px; background: #EEE; padding: 2px 4px;">CTRL</span> <span style="color: #000;">+</span> <span style="border-radius: 2.2px; background: #EEE; padding: 2px 4px;">SPACE</span></div>':'<div style="color: rgb(113, 120, 124); font-style: normal; font-weight: 400; line-height: normal; text-align: center;">Get more emojis with <span style="border-radius: 2.2px; background: #EEE; padding: 2px 4px;">WIN</span> <span style="color: #000;">+</span> <span style="border-radius: 2.2px; background: #EEE; padding: 2px 4px;">.</span></div>'}createEmojiPicker(){this.popup=document.createElement("div"),this.popup.className="emoji-picker-popup",this.createEmojiGrid();const t=document.createElement("div");t.className="emoji-text-message",t.innerHTML=this.getEmojiShortcutMessage(),this.popup.appendChild(t),U(this.popup)}createEmojiGrid(){const t=document.createElement("div");t.className="emoji-grid",this.options.emojis.forEach(e=>{const i=document.createElement("button");i.type="button",i.className="emoji-button",i.textContent=e,i.title=e,i.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),this.selectEmoji(e)}),t.appendChild(i)}),this.popup.appendChild(t)}setupClickOutside(){this.clickOutsideHandler&&document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=t=>{this.popup.contains(t.target)||this.hide()},setTimeout(()=>{document.addEventListener("click",this.clickOutsideHandler)},100)}removeClickOutside(){this.clickOutsideHandler&&(document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=null)}show(t){if(!t)return;document.body.contains(this.popup)||U(this.popup);const e=W(t,this.popup,{offsetY:5,offsetX:0});$(this.popup,e),this.popup.classList.add("visible"),this.isVisible=!0,this.setupClickOutside()}hide(){this.popup.classList.remove("visible"),this.isVisible=!1,this.removeClickOutside()}selectEmoji(t){this.options.onEmojiSelect&&this.options.onEmojiSelect(t),this.hide()}destroy(){this.removeClickOutside(),this.popup&&this.popup.parentNode&&this.popup.parentNode.removeChild(this.popup),this.popup=null,this.isVisible=!1}}class mt extends L{static formatName="emoji";static tagName="SPAN";static className="emoji";constructor(){super();const t=S.getCurrentInstance();if(!t)return;this.editorId=t.instanceId;let e=t.getPopupInstance("emoji");e||(e=new ut({onEmojiSelect:t=>{mt.insertEmojiAtCurrentPosition(t,this.editorId)},editor:t,editorId:this.editorId}),t.setPopupInstance("emoji",e)),this.emojiPicker=e}static createForEditor(t){const e=S.getInstanceById(t);if(!e)return null;const i=S.currentInstance;S.currentInstance=e;const o=new mt;return S.currentInstance=i,o}static create(t){const e=document.createElement("SPAN");return e.className="emoji",e.textContent=t,e.setAttribute("data-emoji",t),e}static insertEmojiAtCurrentPosition(t,e=null){let i=null;if(i=e?S.getInstanceById(e):S.getCurrentInstance(),!i)return;const o=window.getSelection();if(o&&o.rangeCount)try{const e=o.getRangeAt(0);let n=e.startContainer,r=null;for(n.nodeType===Node.TEXT_NODE&&(n=n.parentNode);n&&n!==i.element;){if(n.classList&&n.classList.contains("emoji")){r=n;break}n=n.parentNode}r&&(e.setStartAfter(r),e.collapse(!0),o.removeAllRanges(),o.addRange(e));const s=mt.create(t);e.deleteContents(),e.insertNode(s);const a=document.createTextNode("​");e.setStartAfter(s),e.insertNode(a),e.setStartAfter(a),e.collapse(!0),o.removeAllRanges(),o.addRange(e),i&&"function"==typeof i.onContentChange&&i.onContentChange()}catch(t){}}apply(t){t?mt.insertEmojiAtCurrentPosition(t,this.editorId):this.showEmojiPicker()}remove(){const t=window.getSelection();if(!t||!t.rangeCount)return;const e=t.getRangeAt(0),i=this.getEmojiElement(e);if(i){const t=document.createTextNode(i.textContent);i.parentNode.replaceChild(t,i)}}toggle(){this.emojiPicker.isVisible?this.emojiPicker.hide():this.showEmojiPicker()}showEmojiPicker(){const t=S.getInstanceById(this.editorId);if(!t)return;const e=t.getModule("toolbar");let i=null;if(e&&(i=e.getButton("emoji")),!i){const t=e?.getContainer();t&&(i=t.querySelector(".rich-editor-toolbar-btn.emoji-btn"))}i||(i=t.wrapper.querySelector(".rich-editor-toolbar-btn.emoji-btn")),i&&this.emojiPicker.show(i)}isActive(){const t=window.getSelection();if(!t||!t.rangeCount)return!1;const e=t.getRangeAt(0);return null!==this.getEmojiElement(e)}getEmojiElement(t){let e=t.commonAncestorContainer;if(e.nodeType===Node.TEXT_NODE&&(e=e.parentNode),e.classList&&e.classList.contains("emoji"))return e;const i=t.cloneContents().querySelector(".emoji");return i||null}}class gt extends L{static formatName="image";static tagName="IMG";static className="inserted-image";constructor(){super();const t=S.getCurrentInstance();t&&(this.editorId=t.instanceId)}static createForEditor(t){const e=S.getInstanceById(t);if(!e)return null;const i=S.currentInstance;S.currentInstance=e;const o=new gt;return S.currentInstance=i,o}static create(t,e=""){if(!a(t,{allowDataImage:!0}))return null;const i=document.createElement("IMG");return i.src=t,i.alt=e||"Inserted image",i.className="inserted-image",i.style.maxWidth="100%",i.style.height="auto",i.setAttribute("contenteditable","false"),i}static insertImageAtCurrentPosition(t,e="",i=null){let o=null;if(o=i?S.getInstanceById(i):S.getCurrentInstance(),!o)return;const n=window.getSelection();if(n){if(!n.rangeCount||!o.editor.contains(n.anchorNode)){const t=document.createRange();t.selectNodeContents(o.editor),t.collapse(!1),n.removeAllRanges(),n.addRange(t)}try{const i=n.getRangeAt(0),r=gt.create(t,e);if(!r)return;i.deleteContents(),i.insertNode(r);const s=document.createTextNode(" ");i.setStartAfter(r),i.insertNode(s),i.setStartAfter(s),i.collapse(!0),n.removeAllRanges(),n.addRange(i),o&&"function"==typeof o.onContentChange&&o.onContentChange()}catch(t){}setTimeout(()=>{const t=S.getCurrentInstance();t&&"function"==typeof t.onContentChange&&t.onContentChange()},0)}}apply(t,e){t?gt.insertImageAtCurrentPosition(t,e,this.editorId):this.openFilePicker()}openFilePicker(){const t=S.getInstanceById(this.editorId);if(!t)return;const e=window.getSelection(),i=e&&e.rangeCount?e.getRangeAt(0).cloneRange():null,o=document.createElement("input");o.type="file",o.accept=t.options.image&&t.options.image.accept||"image/*",o.style.display="none",o.addEventListener("change",()=>{const e=o.files&&o.files[0];if(e){t.focus();const o=window.getSelection();if(i)o.removeAllRanges(),o.addRange(i);else if(!o.rangeCount||!t.editor.contains(o.anchorNode)){const e=document.createRange();e.selectNodeContents(t.editor),e.collapse(!1),o.removeAllRanges(),o.addRange(e)}t.insertImageFile(e)}o.remove()}),document.body.appendChild(o),o.click()}remove(){const t=window.getSelection();if(!t||!t.rangeCount)return;const e=t.getRangeAt(0),i=this.getImageElement(e);i&&i.remove()}toggle(){this.openFilePicker()}isActive(){const t=window.getSelection();if(!t||!t.rangeCount)return!1;const e=t.getRangeAt(0);return null!==this.getImageElement(e)}getImageElement(t){let e=t.commonAncestorContainer;if(e.nodeType===Node.TEXT_NODE&&(e=e.parentNode),"IMG"===e.tagName&&e.classList&&e.classList.contains("inserted-image"))return e;const i=t.cloneContents().querySelector(".inserted-image");return i||null}static async handleFileUpload(t){return new Promise((e,i)=>{if(!t||!t.type.startsWith("image/"))return void i(new Error("Please select a valid image file"));const o=new FileReader;o.onload=t=>{e(t.target.result)},o.onerror=()=>{i(new Error("Failed to read file"))},o.readAsDataURL(t)})}static validateImageUrl(t){return new Promise(e=>{const i=["jpg","jpeg","png","gif","bmp","webp","svg"].some(e=>t.toLowerCase().includes(`.${e}`));if(t.startsWith("data:image/"))return void e(!0);if(!/^https?:\/\//.test(t))return void e(!1);if(i)return void e(!0);const o=new gt;o.onload=()=>{e(!0)},o.onerror=()=>{t.includes("imgur.com")||t.includes("drive.google.com")||i?e(!0):e(!1)},setTimeout(()=>{i||t.includes("imgur.com")||t.includes("drive.google.com")?e(!0):e(!1)},5e3),o.src=t})}}var ft=Object.freeze({__proto__:null,default:gt});class yt{constructor(t={}){this.options={onVideoInsert:null,editor:null,...t},this.popup=null,this.isVisible=!1,this.clickOutsideHandler=null,this.selectedVideoSrc=null,this.savedSelection=null,this.createVideoPopup()}createVideoPopup(){this.popup=document.createElement("div"),this.popup.className="video-popup";const t=document.createElement("div");t.className="video-popup-content";const e=document.createElement("h3");e.textContent="Insert video",e.className="yjd-input-title",t.appendChild(e);const i=document.createElement("div");i.className="video-input-container";const o=document.createElement("p");o.textContent="Your video url",o.className="yjd-input-label";const n=document.createElement("div");n.className="yjd-input-upload-group",this.inputGroup=n,this.urlInput=document.createElement("input"),this.urlInput.type="url",this.urlInput.className="yjd-input",this.urlInput.placeholder="Please enter your video URL",this.urlInput.addEventListener("input",()=>{this.updateInsertButton();const t=this.urlInput.value.trim();t&&this.isValidVideoUrl(t)?this.showPreview(t):this.removePreview(),this.urlInput.value.trim()?this.customButton.style.display="none":this.customButton.style.display="block"}),this.fileInput=document.createElement("input"),this.fileInput.type="file",this.fileInput.accept="video/*",this.fileInput.className="image-input-hidden",this.fileInput.addEventListener("change",t=>this.handleFileSelect(t));const r=document.createElement("button");r.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" x2="12" y1="3" y2="15"/></svg>',r.className="yjd-custom-upload-button",this.customButton=r,r.addEventListener("click",()=>this.fileInput.click()),this.createPreviewContainer(),n.appendChild(this.urlInput),n.appendChild(this.fileInput),n.appendChild(r),i.appendChild(o),i.appendChild(n),i.appendChild(this.previewContainer),t.appendChild(i);const s=document.createElement("div");s.className="yjd-button-container";const a=document.createElement("button");a.type="button",a.className="image-button yjd-button-cancel",a.textContent="Cancel",a.addEventListener("click",()=>{this.hide(),this.options.editor&&setTimeout(()=>this.options.editor.focus(),0)}),this.insertButton=document.createElement("button"),this.insertButton.type="button",this.insertButton.className="image-button yjd-button-confirm button-disable",this.insertButton.textContent="Add video",this.insertButton.disabled=!0,this.insertButton.addEventListener("click",()=>{this.insertVideo(),this.options.editor&&setTimeout(()=>this.options.editor.focus(),0)}),s.appendChild(a),s.appendChild(this.insertButton),t.appendChild(s),this.popup.appendChild(t),U(this.popup),this.options.editor&&"function"==typeof this.options.editor.preventFocusLoss&&this.options.editor.preventFocusLoss(this.popup)}async handleFileSelect(t){const e=t.target.files[0];if(e)try{const{default:t}=await Promise.resolve().then(function(){return vt});this.selectedVideoSrc=await t.handleFileUpload(e),this.urlInput.value="",this.showPreview(this.selectedVideoSrc),this.updateInsertButton()}catch(t){alert(t.message)}}updateInsertButton(){const t=this.selectedVideoSrc||this.urlInput.value.trim();this.insertButton.disabled=!t,this.insertButton.classList.toggle("button-disable",!t)}showPreview(t){t&&(this.videoPreview.src=t,this.previewContainer.style.display="block",this.selectedVideoSrc=t,this.toggleInputGroup(!1),this.recalculatePosition())}removePreview(){this.selectedVideoSrc=null,this.previewContainer.style.display="none",this.videoPreview.src="",this.toggleInputGroup(!0),this.fileInput&&(this.fileInput.value=""),this.updateInsertButton(),this.recalculatePosition()}toggleInputGroup(t){this.inputGroup&&(t?(this.inputGroup.style.display="flex",this.inputGroup.style.visibility="visible",this.customButton&&(this.customButton.style.pointerEvents="auto")):(this.inputGroup.style.display="none",this.inputGroup.style.visibility="hidden"))}createPreviewContainer(){this.previewContainer=document.createElement("div"),this.previewContainer.className="video-preview-container",this.previewContainer.style.cssText="display: none; position: relative;",this.videoPreview=document.createElement("video"),this.videoPreview.className="video-preview",this.videoPreview.style.cssText="max-width: 100%; max-height: 200px; border-radius: 8px; object-fit: contain;",this.videoPreview.controls=!0,this.videoPreview.muted=!0,this.removeButton=document.createElement("button"),this.removeButton.className="video-remove-button",this.removeButton.innerHTML="×",this.removeButton.style.cssText="\n position: absolute; top: 5px; right: 5px; background: rgba(0,0,0,0.7);\n color: white; border: none; border-radius: 50%; width: 24px; height: 24px;\n cursor: pointer; font-size: 16px; font-weight: bold;\n ",this.removeButton.addEventListener("click",()=>this.removePreview()),this.previewContainer.appendChild(this.videoPreview),this.previewContainer.appendChild(this.removeButton)}isValidVideoUrl(t){try{const e=new URL(t),i=[".mp4",".webm",".ogg",".mov",".avi",".mkv"],o=["youtube.com","youtu.be","vimeo.com","dailymotion.com"],n=e.pathname.toLowerCase(),r=i.some(t=>n.endsWith(t)),s=o.some(t=>e.hostname.includes(t));return r||s}catch{return!1}}async insertVideo(){let t=this.selectedVideoSrc||this.urlInput.value.trim();if(t){try{const{default:e}=await Promise.resolve().then(function(){return vt});if(!await e.validateVideoUrl(t))return void alert("Invalid video URL. Please check the URL and try again.")}catch(t){return void alert("Error validating video URL.")}this.restoreSelection(),this.options.onVideoInsert&&this.options.onVideoInsert(t),this.hide(),this.reset()}}reset(){this.fileInput.value="",this.urlInput.value="",this.selectedVideoSrc=null,this.previewContainer.style.display="none",this.videoPreview.src="",this.toggleInputGroup(!0),this.updateInsertButton(),this.customButton.style.display="block"}saveSelection(){const t=window.getSelection();t&&t.rangeCount>0&&(this.savedSelection=t.getRangeAt(0).cloneRange())}restoreSelection(){if(this.savedSelection){const t=window.getSelection();t.removeAllRanges(),t.addRange(this.savedSelection)}}setupClickOutside(){this.clickOutsideHandler&&document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=t=>{this.popup.contains(t.target)||this.hide()},setTimeout(()=>{document.addEventListener("click",this.clickOutsideHandler)},100)}removeClickOutside(){this.clickOutsideHandler&&(document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=null)}show(t){if(!t)return;this.saveSelection(),this.reset(),this.currentAnchor=t;const e=W(t,this.popup,{offsetY:5,offsetX:0});$(this.popup,e),this.popup.classList.add("visible"),this.isVisible=!0,this.setupClickOutside()}recalculatePosition(){this.currentAnchor&&this.isVisible&&setTimeout(()=>{const t=W(this.currentAnchor,this.popup,{offsetY:5,offsetX:0});$(this.popup,t)},10)}hide(){this.popup.classList.remove("visible"),this.isVisible=!1,this.removeClickOutside(),this.savedSelection=null}destroy(){this.removeClickOutside(),this.popup&&this.popup.parentNode&&this.popup.parentNode.removeChild(this.popup),this.popup=null,this.isVisible=!1}}class bt extends L{static formatName="video";static tagName="VIDEO";static className="inserted-video";constructor(){super();const t=S.getCurrentInstance();if(!t)return;this.editorId=t.instanceId;let e=t.getPopupInstance("video");e||(e=new yt({onVideoInsert:t=>{bt.insertVideoAtCurrentPosition(t,this.editorId)},editor:t,editorId:this.editorId}),t.setPopupInstance("video",e)),this.videoPopup=e}static createForEditor(t){const e=S.getInstanceById(t);if(!e)return null;const i=S.currentInstance;S.currentInstance=e;const o=new bt;return S.currentInstance=i,o}static create(t){if(bt.isYouTubeUrl(t))return bt.createYouTubeEmbed(t);if(!a(t))return null;const e=document.createElement("VIDEO");return e.src=t,e.className="inserted-video",e.controls=!0,e.style.maxWidth="100%",e.style.height="auto",e.setAttribute("contenteditable","false"),e}static createYouTubeEmbed(t){const e=bt.getYouTubeVideoId(t);if(!e)throw new Error("Invalid YouTube URL");const i=document.createElement("IFRAME");return i.src=`https://www.youtube.com/embed/${e}`,i.className="inserted-video youtube-video",i.width="560",i.height="315",i.style.maxWidth="100%",i.style.width="560px",i.style.height="315px",i.style.position="relative",i.style.display="block",i.setAttribute("frameborder","0"),i.setAttribute("allowfullscreen",""),i.setAttribute("contenteditable","false"),i}static insertVideoAtCurrentPosition(t,e=null){let i=null;if(i=e?S.getInstanceById(e):S.getCurrentInstance(),!i)return;const o=window.getSelection();if(o&&o.rangeCount)try{const e=o.getRangeAt(0),n=bt.create(t);if(!n)return;e.deleteContents(),e.insertNode(n);const r=document.createTextNode(" ");e.setStartAfter(n),e.insertNode(r),e.setStartAfter(r),e.collapse(!0),o.removeAllRanges(),o.addRange(e),i&&"function"==typeof i.onContentChange&&i.onContentChange()}catch(t){}}apply(t){t?bt.insertVideoAtCurrentPosition(t,this.editorId):this.showVideoPopup()}remove(){const t=window.getSelection();if(!t||!t.rangeCount)return;const e=t.getRangeAt(0),i=this.getVideoElement(e);i&&i.remove()}toggle(){this.videoPopup.isVisible?this.videoPopup.hide():this.showVideoPopup()}showVideoPopup(){const t=S.getInstanceById(this.editorId);if(!t)return;const e=t.getModule("toolbar");let i=null;if(e&&(i=e.getButton("video")),!i){const t=e?.getContainer();t&&(i=t.querySelector(".rich-editor-toolbar-btn.video-btn"))}i||(i=t.wrapper.querySelector(".rich-editor-toolbar-btn.video-btn")),i&&this.videoPopup.show(i)}isActive(){const t=window.getSelection();if(!t||!t.rangeCount)return!1;const e=t.getRangeAt(0);return null!==this.getVideoElement(e)}getVideoElement(t){let e=t.commonAncestorContainer;if(e.nodeType===Node.TEXT_NODE&&(e=e.parentNode),("VIDEO"===e.tagName||"IFRAME"===e.tagName)&&e.classList&&e.classList.contains("inserted-video"))return e;const i=t.cloneContents().querySelector(".inserted-video");return i||null}static async handleFileUpload(t){return new Promise((e,i)=>{if(!t||!t.type.startsWith("video/"))return void i(new Error("Please select a valid video file"));const o=new FileReader;o.onload=t=>{e(t.target.result)},o.onerror=()=>{i(new Error("Failed to read file"))},o.readAsDataURL(t)})}static validateVideoUrl(t){return new Promise(e=>{if(bt.isYouTubeUrl(t))return void e(!0);if(["mp4","webm","ogg","mov","avi","mkv"].some(e=>t.toLowerCase().includes(`.${e}`)))return void e(!0);const i=document.createElement("video");i.onloadedmetadata=()=>{e(!0)},i.onerror=()=>{e(!1)},setTimeout(()=>{e(!1)},5e3),i.src=t})}static isYouTubeUrl(t){return/(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/embed\/)([a-zA-Z0-9_-]{11})/.test(t)}static getYouTubeVideoId(t){const e=t.match(/(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/embed\/)([a-zA-Z0-9_-]{11})/);return e?e[1]:null}}var vt=Object.freeze({__proto__:null,default:bt});class xt{constructor(t={}){this.options={onTagInsert:null,editor:null,...t},this.popup=null,this.isVisible=!1,this.clickOutsideHandler=null,this.selectedTagType="mention",this.createTagPopup()}createTagPopup(){this.popup=document.createElement("div"),this.popup.className="tag-popup";const t=document.createElement("div");t.className="tag-popup-content";const e=document.createElement("h3");e.textContent="Insert tags",e.className="yjd-input-title",t.appendChild(e);const i=document.createElement("div");i.className="yjd-input-group";const o=document.createElement("label");o.textContent="Type",o.className="yjd-input-label",this.typeSelect=document.createElement("select"),this.typeSelect.className="yjd-select-input",this.typeSelect.innerHTML='\n <option value="mention">Mention</option>\n <option value="hashtag">Hashtag</option>\n <option value="custom">Custom</option>\n ',this.typeSelect.addEventListener("change",()=>this.updateSuggestions()),i.appendChild(o),i.appendChild(this.typeSelect),t.appendChild(i);const n=document.createElement("div");n.className="yjd-input-group";const r=document.createElement("label");r.textContent="Content",r.className="yjd-input-label",this.contentInput=document.createElement("input"),this.contentInput.type="text",this.contentInput.className="yjd-input",this.contentInput.placeholder="Please enter tag content",this.contentInput.addEventListener("input",()=>this.updateInsertButton()),this.contentInput.addEventListener("keydown",t=>{"Enter"===t.key&&(t.preventDefault(),this.insertTag())}),n.appendChild(r),n.appendChild(this.contentInput),t.appendChild(n);const s=document.createElement("div");s.className="yjd-input-group",this.suggestionsContainer=document.createElement("div"),this.suggestionsContainer.className="tag-suggestions-container";const a=document.createElement("label");a.textContent="Suggestions",a.className="yjd-input-label",this.suggestionsList=document.createElement("div"),this.suggestionsList.className="yjd-suggestions-list",this.suggestionsContainer.appendChild(this.suggestionsList),s.appendChild(a),s.appendChild(this.suggestionsContainer),t.appendChild(s);const l=document.createElement("div");l.className="yjd-button-container";const c=document.createElement("button");c.type="button",c.className="yjd-button-cancel",c.textContent="Cancel",c.addEventListener("click",()=>this.hide()),this.insertButton=document.createElement("button"),this.insertButton.type="button",this.insertButton.className="yjd-button-confirm",this.insertButton.textContent="Insert Tag",this.insertButton.disabled=!0,this.insertButton.addEventListener("click",()=>this.insertTag()),l.appendChild(c),l.appendChild(this.insertButton),t.appendChild(l),this.popup.appendChild(t),U(this.popup),this.options.editor&&"function"==typeof this.options.editor.preventFocusLoss&&this.options.editor.preventFocusLoss(this.popup),this.updateSuggestions()}updateSuggestions(){this.selectedTagType=this.typeSelect.value,this.suggestionsList.innerHTML="";this.getSuggestions(this.selectedTagType).forEach(t=>{const e=document.createElement("button");e.type="button",e.className="yjd-suggestion-button",e.textContent=t,e.addEventListener("click",()=>{this.contentInput.value=t,this.updateInsertButton(),this.contentInput.focus()}),this.suggestionsList.appendChild(e)})}getSuggestions(t){return{mention:["john","admin","team","support"],hashtag:["urgent","done","important"],custom:["warning","info","success"]}[t]||[]}updateInsertButton(){const t=this.contentInput.value.trim();this.insertButton.disabled=!t}insertTag(){const t=this.contentInput.value.trim();t&&(this.options.onTagInsert&&this.options.onTagInsert(this.selectedTagType,t),this.hide(),this.reset())}reset(){this.contentInput.value="",this.typeSelect.value="mention",this.selectedTagType="mention",this.updateInsertButton(),this.updateSuggestions()}setupClickOutside(){this.clickOutsideHandler&&document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=t=>{this.popup.contains(t.target)||this.hide()},setTimeout(()=>{document.addEventListener("click",this.clickOutsideHandler)},100)}removeClickOutside(){this.clickOutsideHandler&&(document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=null)}show(t){if(!t)return;const e=W(t,this.popup,{offsetY:5,offsetX:0});$(this.popup,e),this.popup.classList.add("visible"),this.isVisible=!0,this.setupClickOutside(),setTimeout(()=>{this.contentInput.focus()},100)}hide(){this.popup.classList.remove("visible"),this.isVisible=!1,this.removeClickOutside()}destroy(){this.removeClickOutside(),this.popup&&this.popup.parentNode&&this.popup.parentNode.removeChild(this.popup),this.popup=null,this.isVisible=!1}}class Ct extends L{static formatName="tag";static tagName="SPAN";static className="custom-tag";static savedRanges=new Map;constructor(){super();const t=S.getCurrentInstance();if(!t)return;this.editorId=t.instanceId;let e=t.getPopupInstance("tag");e||(e=new xt({onTagInsert:(t,e)=>{Ct.insertTagAtCurrentPosition(t,e,this.editorId)},editor:t,editorId:this.editorId}),t.setPopupInstance("tag",e)),this.tagPopup=e}static createForEditor(t){const e=S.getInstanceById(t);if(!e)return null;const i=S.currentInstance;S.currentInstance=e;const o=new Ct;return S.currentInstance=i,o}static create(t,e){const i=document.createElement("SPAN");i.className=`custom-tag tag-${t}`;let o=e;return"mention"===t?o=`@${e}`:"hashtag"===t?o=`#${e}`:"custom"===t&&(o=`<${e}>`),i.textContent=o,i.setAttribute("data-tag-type",t),i.setAttribute("data-tag-content",e),i.setAttribute("contenteditable","false"),i}static insertTagAtCurrentPosition(t,e,i=null){let o=null;if(o=i?S.getInstanceById(i):S.getCurrentInstance(),!o)return;const n=window.getSelection();if(n)try{const r=Ct.savedRanges.get(i);if(r)n.removeAllRanges(),n.addRange(r),Ct.savedRanges.delete(i);else if(!n.rangeCount)return;const s=n.getRangeAt(0),a=Ct.create(t,e);s.deleteContents(),s.insertNode(a);const l=document.createTextNode(" ");s.setStartAfter(a),s.insertNode(l),s.setStartAfter(l),s.collapse(!0),n.removeAllRanges(),n.addRange(s),o&&o.element&&o.element.focus(),o&&"function"==typeof o.onContentChange&&o.onContentChange()}catch(t){}}apply(t,e){if(t&&e)Ct.insertTagAtCurrentPosition(t,e,this.editorId);else{const t=window.getSelection();t&&t.rangeCount>0&&Ct.savedRanges.set(this.editorId,t.getRangeAt(0).cloneRange()),this.showTagPopup()}}remove(){const t=window.getSelection();if(!t||!t.rangeCount)return;const e=t.getRangeAt(0),i=this.getTagElement(e);if(i){const t=document.createTextNode(i.textContent);i.parentNode.replaceChild(t,i)}}toggle(){if(this.tagPopup.isVisible)this.tagPopup.hide();else{const t=window.getSelection();t&&t.rangeCount>0&&Ct.savedRanges.set(this.editorId,t.getRangeAt(0).cloneRange()),this.showTagPopup()}}showTagPopup(){const t=S.getInstanceById(this.editorId);if(!t)return;const e=t.getModule("toolbar");let i=null;if(e&&(i=e.getButton("tag")),!i){const t=e?.getContainer();t&&(i=t.querySelector(".rich-editor-toolbar-btn.tag-btn"))}i||(i=t.wrapper.querySelector(".rich-editor-toolbar-btn.tag-btn")),i&&this.tagPopup.show(i)}isActive(){const t=window.getSelection();if(!t||!t.rangeCount)return!1;const e=t.getRangeAt(0);return null!==this.getTagElement(e)}getTagElement(t){let e=t.commonAncestorContainer;if(e.nodeType===Node.TEXT_NODE&&(e=e.parentNode),e.classList&&e.classList.contains("custom-tag"))return e;return t.cloneContents().querySelector(".custom-tag")||null}static getSuggestions(t){return{mention:["john","sarah","admin","team","support"],hashtag:["urgent","todo","done","review","important"],custom:["note","warning","tip","info","success"]}[t]||[]}}class wt extends L{static formatName="textSize";static tagName="SPAN";constructor(){super();const t=S.getCurrentInstance();if(!t)return;this.editorId=t.instanceId;let e=t.getPopupInstance("text-size");if(!e){const i=wt.getSizeMap(),o=Object.values(i).map(t=>({value:t.size,label:t.element,title:t.title}));e=new tt({items:o,displayProperty:"label",valueProperty:"value",className:"text-size-select",onItemSelect:t=>{wt.applyTextSizeToCurrentSelection(t,this.editorId)},editor:t,editorId:this.editorId}),t.setPopupInstance("text-size",e)}this.customSelect=e}static createForEditor(t){const e=S.getInstanceById(t);if(!e)return null;const i=S.currentInstance;S.currentInstance=e;const o=new wt;return S.currentInstance=i,o}static getSizeMap(){return{1:{size:"1",element:"<span >XX-Small</span>",title:"XX-Small"},2:{size:"2",element:"<span >X-Small</span>",title:"X-Small"},3:{size:"3",element:"<span >Small</span>",title:"Small"},4:{size:"4",element:"<span >Medium</span>",title:"Medium"},5:{size:"5",element:"<span >Large</span>",title:"Large"},6:{size:"6",element:"<span >X-Large</span>",title:"X-Large"},7:{size:"7",element:"<span >XX-Large</span>",title:"XX-Large"}}}static getSizeDisplayName(t){const e=this.getSizeMap();return e[t]?.title||"Medium"}updateButtonText(){const t=this.getCurrentSize(),e=wt.getSizeDisplayName(t||"4"),i=S.getInstanceById(this.editorId);if(!i)return;const o=i.getModule("toolbar");let n=null;if(o&&(n=o.getButton("text-size")),!n){const t=o?.getContainer();t&&(n=t.querySelector(".rich-editor-toolbar-btn.text-size-btn"))}n||(n=i.wrapper.querySelector(".rich-editor-toolbar-btn.text-size-btn")),n&&n.updateText?n.updateText(e):n&&(n.textContent=e)}static updateButtonTextStatic(t=null){let e=null;if(e=t?S.getInstanceById(t):S.getCurrentInstance(),!e)return;const i=wt.getCurrentSizeStatic(),o=wt.getSizeDisplayName(i||"4"),n=e.getModule("toolbar");let r=null;if(n&&(r=n.getButton("text-size")),!r){const t=n?.getContainer();t&&(r=t.querySelector(".rich-editor-toolbar-btn.text-size-btn"))}r||(r=e.wrapper.querySelector(".rich-editor-toolbar-btn.text-size-btn")),r&&r.updateText?r.updateText(o):r&&(r.textContent=o)}static create(t="4"){const e=document.createElement("span");return e.style.fontSize=wt.sizeToCss(t),e}static applyTextSizeToCurrentSelection(t,e=null){let i=null;if(i=e?S.getInstanceById(e):S.getCurrentInstance(),!i)return;const o=window.getSelection();if(!o||!o.rangeCount)return;B();const n=wt.createForEditor(e);n&&(n.apply(t),n.updateButtonText()),setTimeout(()=>{i&&"function"==typeof i.onContentChange&&i.onContentChange()},0)}static sizeToCss(t){return{1:"10px",2:"12px",3:"14px",4:"16px",5:"20px",6:"28px",7:"36px"}[String(t)]||"16px"}apply(t="4"){const e=window.getSelection();if(!e||!e.rangeCount)return;B();const o=e.getRangeAt(0);if(!o.collapsed){i("fontSize",String(t));const e=window.getSelection();if(e.rangeCount>0){const t=e.getRangeAt(0).commonAncestorContainer;t.nodeType===Node.TEXT_NODE?t.parentNode.normalize():t.normalize()}return}let n=o.startContainer;o.startOffset,n.nodeType===Node.TEXT_NODE&&(n=n.parentNode);const r=n.closest&&n.closest("font");if(r&&"​"===r.textContent)return void r.setAttribute("size",String(t));if(r&&r.firstChild&&r.firstChild.nodeType===Node.TEXT_NODE){const e=r.firstChild,i=o.startOffset,n=e.data.slice(0,i),s=e.data.slice(i),a=r.parentNode;if(0===i){const e=document.createElement("font");e.setAttribute("size",String(t)),e.appendChild(document.createTextNode("​")),a.insertBefore(e,r),l(e)}else if(i===e.data.length){const e=document.createElement("font");e.setAttribute("size",String(t)),e.appendChild(document.createTextNode("​")),a.insertBefore(e,r.nextSibling),l(e)}else{const e=document.createElement("font");e.setAttribute("size",r.getAttribute("size")),e.appendChild(document.createTextNode(n));const i=document.createElement("font");i.setAttribute("size",String(t)),i.appendChild(document.createTextNode("​"));const o=document.createElement("font");o.setAttribute("size",r.getAttribute("size")),o.appendChild(document.createTextNode(s)),a.insertBefore(e,r),a.insertBefore(i,r),a.insertBefore(o,r),a.removeChild(r),l(i)}return}const s=document.createElement("font");s.setAttribute("size",String(t));const a=document.createTextNode("​");function l(t){const e=window.getSelection(),i=document.createRange(),o=t.firstChild;i.setStart(o,o.length),i.collapse(!0),e.removeAllRanges(),e.addRange(i)}s.appendChild(a),o.insertNode(s),l(s)}async toggle(){this.customSelect.isVisible?this.customSelect.hide():await this.showSizePicker()}async showSizePicker(){const t=S.getInstanceById(this.editorId);if(!t)return;const e=t.getModule("toolbar");let i=null;if(e&&(i=e.getButton("text-size")),!i){const t=e?.getContainer();t&&(i=t.querySelector(".rich-editor-toolbar-btn.text-size-btn"))}if(i||(i=t.wrapper.querySelector(".rich-editor-toolbar-btn.text-size-btn")),!i)return;const o=this.getCurrentSize();o&&this.customSelect.setCurrentValue(o),await this.customSelect.show(i)}isActive(t=null){return this.updateButtonText(),!1}getCurrentSize(){return wt.getCurrentSizeStatic()}static getCurrentSizeStatic(){const t=window.getSelection();if(!t||!t.rangeCount)return"4";try{const t=function(t){try{return document.queryCommandValue(t)||""}catch(t){return""}}("fontSize"),e=parseInt(t,10);if(!isNaN(e)&&e>=1&&e<=7)return String(e)}catch(t){}let e=t.getRangeAt(0).startContainer;for(e.nodeType===Node.TEXT_NODE&&(e=e.parentElement);e&&e!==document.body;){if(e.nodeType===Node.ELEMENT_NODE){const t=e,i=t.style?.fontSize;if(i)return this.normalizeCssSizeToExecSize(i);const o=window.getComputedStyle(t).fontSize;if(o)return this.normalizeCssSizeToExecSize(o)}e=e.parentElement}return"4"}normalizeCssSizeToExecSize(t){const e=parseFloat(t);if(isNaN(e))return"4";const i=[10,12,14,16,20,28,36];let o=3,n=1/0;for(let t=0;t<i.length;t++){const r=Math.abs(e-i[t]);r<n&&(n=r,o=t)}return String(o+1)}}class Et{constructor(t={}){this.options={onImport:null,...t},this.popup=null,this.isVisible=!1,this.clickOutsideHandler=null,this.selectedFile=null,this.fileType=null,this.createImportPopup()}createImportPopup(){this.popup=document.createElement("div"),this.popup.className="import-popup";const t=document.createElement("div");t.className="import-popup-content";const e=document.createElement("h3");e.textContent="Import File",e.className="import-popup-title",t.appendChild(e);const i=document.createElement("div");i.className="import-type-container";const o=document.createElement("label");o.textContent="File Type:",o.className="import-input-label",this.typeSelect=document.createElement("select"),this.typeSelect.className="import-type-select",this.typeSelect.innerHTML='\n <option value="">Select file type...</option>\n <option value="html">HTML (.html, .htm)</option>\n <option value="excel">Excel/CSV (.csv, .xlsx, .xls)</option>\n <option value="pdf">PDF (.pdf)</option>\n <option value="word">Word (.doc, .docx)</option>\n ',this.typeSelect.addEventListener("change",()=>this.updateFileInput()),i.appendChild(o),i.appendChild(this.typeSelect),t.appendChild(i),this.fileInput=document.createElement("input"),this.fileInput.type="file",this.fileInput.className="import-file-input",this.fileInput.disabled=!0,this.fileInput.addEventListener("change",t=>this.handleFileSelect(t)),t.appendChild(this.fileInput),this.fileInfo=document.createElement("div"),this.fileInfo.className="import-file-info",this.fileInfo.style.display="none",t.appendChild(this.fileInfo);const n=document.createElement("div");n.className="import-button-container";const r=document.createElement("button");r.type="button",r.className="import-button cancel-button",r.textContent="Cancel",r.addEventListener("click",()=>this.hide()),this.importButton=document.createElement("button"),this.importButton.type="button",this.importButton.className="import-button import-button-main",this.importButton.textContent="Import",this.importButton.disabled=!0,this.importButton.addEventListener("click",()=>this.processImport()),n.appendChild(r),n.appendChild(this.importButton),t.appendChild(n),this.popup.appendChild(t),U(this.popup)}updateFileInput(){const t=this.typeSelect.value;if(t){this.fileType=t,this.fileInput.disabled=!1;const e=this.getAcceptTypes(t);this.fileInput.accept=e}else this.fileType=null,this.fileInput.disabled=!0,this.fileInput.accept="";this.updateImportButton()}getAcceptTypes(t){return{html:".html,.htm,text/html",excel:".csv,.xlsx,.xls,text/csv",pdf:".pdf,application/pdf",word:".doc,.docx"}[t]||""}handleFileSelect(t){const e=t.target.files[0];e&&this.setSelectedFile(e)}setSelectedFile(t){this.selectedFile=t,this.fileInfo.style.display="block",this.fileInfo.innerHTML=`\n <div><strong>Name:</strong> ${t.name}</div>\n <div><strong>Size:</strong> ${this.formatFileSize(t.size)}</div>\n <div><strong>Type:</strong> ${t.type||"Unknown"}</div>\n `,this.updateImportButton()}formatFileSize(t){if(0===t)return"0 Bytes";const e=Math.floor(Math.log(t)/Math.log(1024));return parseFloat((t/Math.pow(1024,e)).toFixed(2))+" "+["Bytes","KB","MB","GB"][e]}updateImportButton(){this.importButton.disabled=!this.selectedFile||!this.fileType}async processImport(){if(this.selectedFile&&this.fileType)try{let t;if("html"===this.fileType)t=await this.readAsText(this.selectedFile);else if("excel"===this.fileType){if(!this.selectedFile.name.toLowerCase().endsWith(".csv"))return void alert("Excel files (.xlsx/.xls) require additional libraries. Please use CSV format.");{const e=await this.readAsText(this.selectedFile);t=this.parseCSV(e)}}else{if("pdf"===this.fileType)return void alert("PDF import requires additional libraries. Feature coming soon.");if("word"===this.fileType)return void alert("Word document import requires additional libraries. Feature coming soon.")}this.options.onImport&&this.options.onImport(t,this.fileType),this.hide(),this.reset()}catch(t){alert("Error importing file: "+t.message)}}parseCSV(t){const e=t.split("\n"),i=[];return e.forEach(t=>{if(t.trim()){const e=t.split(",").map(t=>t.trim().replace(/^["']|["']$/g,""));i.push(e)}}),i}readAsText(t){return new Promise((e,i)=>{const o=new FileReader;o.onload=t=>e(t.target.result),o.onerror=()=>i(new Error("Failed to read file")),o.readAsText(t)})}reset(){this.selectedFile=null,this.fileType=null,this.typeSelect.value="",this.fileInput.value="",this.fileInput.disabled=!0,this.fileInfo.style.display="none",this.updateImportButton()}setupClickOutside(){this.clickOutsideHandler&&document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=t=>{this.popup.contains(t.target)||this.hide()},setTimeout(()=>{document.addEventListener("click",this.clickOutsideHandler)},100)}removeClickOutside(){this.clickOutsideHandler&&(document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=null)}show(t){if(!t)return;const e=W(t,this.popup,{offsetY:5,offsetX:0});$(this.popup,e),this.popup.classList.add("visible"),this.isVisible=!0,this.setupClickOutside()}hide(){this.popup.classList.remove("visible"),this.isVisible=!1,this.removeClickOutside()}destroy(){this.removeClickOutside(),this.popup&&this.popup.parentNode&&this.popup.parentNode.removeChild(this.popup),this.popup=null,this.isVisible=!1}}class kt extends L{static formatName="import";static tagName="DIV";static className="imported-content";constructor(){super();const t=S.getCurrentInstance();if(!t)return;this.editorId=t.instanceId;let e=t.getPopupInstance("import");e||(e=new Et({onImport:(t,e)=>{kt.insertImportedContent(t,e,this.editorId)},editor:t,editorId:this.editorId}),t.setPopupInstance("import",e)),this.importPopup=e}static createForEditor(t){const e=S.getInstanceById(t);if(!e)return null;const i=S.currentInstance;S.currentInstance=e;const o=new kt;return S.currentInstance=i,o}static insertImportedContent(t,e,i=null){let o=null;if(o=i?S.getInstanceById(i):S.getCurrentInstance(),!o)return;const n=window.getSelection();if(n&&n.rangeCount)try{const i=n.getRangeAt(0);let r;r="html"===e?kt.processHtmlContent(t):"excel"===e?kt.processExcelContent(t):kt.processTextContent(t),i.deleteContents(),i.insertNode(r),i.setStartAfter(r),i.collapse(!0),n.removeAllRanges(),n.addRange(i),o&&"function"==typeof o.onContentChange&&o.onContentChange()}catch(t){}}static processHtmlContent(t){const e=document.createElement("div");return e.className="imported-content html-content",e.innerHTML=d(t),kt.cleanHtmlContent(e),e}static processExcelContent(t){const e=document.createElement("div");if(e.className="imported-content excel-content",!Array.isArray(t)||0===t.length)return e.textContent="No data to import",e;const i=document.createElement("table");if(i.className="imported-table",t.length>0){const e=document.createElement("thead"),o=document.createElement("tr");t[0].forEach(t=>{const e=document.createElement("th");e.textContent=t||"",o.appendChild(e)}),e.appendChild(o),i.appendChild(e)}if(t.length>1){const e=document.createElement("tbody");for(let i=1;i<t.length;i++){const o=document.createElement("tr");t[i].forEach(t=>{const e=document.createElement("td");e.textContent=t||"",o.appendChild(e)}),e.appendChild(o)}i.appendChild(e)}return e.appendChild(i),e}static processTextContent(t){const e=document.createElement("div");e.className="imported-content text-content";return t.split(/\n\s*\n/).forEach(t=>{if(t.trim()){const i=document.createElement("p");i.textContent=t.trim(),e.appendChild(i)}}),e}static cleanHtmlContent(t){const e=["p","div","span","h1","h2","h3","h4","h5","h6","strong","b","em","i","u","ul","ol","li","br","table","thead","tbody","tr","th","td"],i=["class","style"],o=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,null,!1),n=[];for(;o.nextNode();){const t=o.currentNode;if(!e.includes(t.tagName.toLowerCase())){n.push(t);continue}Array.from(t.attributes).forEach(e=>{i.includes(e.name.toLowerCase())||t.removeAttribute(e.name)})}n.forEach(t=>{t.parentNode&&t.parentNode.removeChild(t)})}static parseCSV(t){const e=t.split("\n"),i=[];return e.forEach(t=>{if(t.trim()){const e=t.split(",").map(t=>t.trim().replace(/^["']|["']$/g,""));i.push(e)}}),i}apply(){this.showImportPopup()}toggle(){this.importPopup.isVisible?this.importPopup.hide():this.showImportPopup()}showImportPopup(){const t=S.getInstanceById(this.editorId);if(!t)return;const e=t.getModule("toolbar");let i=null;if(e&&(i=e.getButton("import")),!i){const t=e?.getContainer();t&&(i=t.querySelector(".rich-editor-toolbar-btn.import-btn"))}i||(i=t.wrapper.querySelector(".rich-editor-toolbar-btn.import-btn")),i&&this.importPopup.show(i)}isActive(){return!1}static getSupportedTypes(){return{html:{extensions:[".html",".htm"],mimeTypes:["text/html"],name:"HTML Files"},excel:{extensions:[".csv",".xlsx",".xls"],mimeTypes:["text/csv","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],name:"Excel Files"},pdf:{extensions:[".pdf"],mimeTypes:["application/pdf"],name:"PDF Files"},word:{extensions:[".doc",".docx"],mimeTypes:["application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document"],name:"Word Documents"}}}}function jt(t="Button",e={}){const{width:i="auto",icon:o=null}=e,n=document.createElement("button");if(n.type="button",n.className="custom-select-button",o){const t=F.createIconElement(o);t.className="select-lead-icon",n.appendChild(t)}const r=document.createElement("span");r.textContent=t,r.className="button-text";const s=F.createIconElement("dropdown");return s.className="dropdown-icon",n.appendChild(r),n.appendChild(s),n.style.width=i,n.style.padding="0px 5px 0px 8px",n.style.setProperty("height","32px","important"),n.style.setProperty("borderRadius","6px","important"),n.style.setProperty("alignItems","center","important"),n.style.fontSize="14px",n.style.fontWeight="400",n.style.color="#374151",n.style.background="#FFFFFF",n.style.cursor="pointer",n.style.border="1px solid #d1d5db",n.style.display="flex",n.style.justifyContent="space-between",n.style.alignItems="center",r.style.flex="1",r.style.textAlign="left",n.updateText=function(t){r.textContent=t},n}class Tt extends e{static DEFAULTS={container:null,toolbar1:[{group:"text-format",items:["bold","italic","underline","strike"]},{group:"paragraph",items:["heading"]},{group:"colors",items:["color","background"]},{group:"link",items:["link"]},{group:"paragraph-ops",items:["list","indent-increase","indent-decrease","text-align"]},{group:"insert",items:["image","table"]},{group:"history",items:["undo","redo"]},{group:"more",items:["more"]}],toolbar2:[{group:"font",items:["font-family","text-size","line-height"]},{group:"script",items:["subscript","superscript","capitalization"]},{group:"media",items:["emoji","video","tag","horizontal-rule"]},{group:"tools",items:["clear-format","text-direction","find","code-view"]}]};constructor(t,e={}){super(t,e),this.buttons=new Map,this.toolbar2Visible=!1,this.events=new Map,Array.isArray(e.toolbar)?this.options={container:null,toolbar1:[{group:"text-format",items:e.toolbar}],toolbar2:[]}:e.toolbar1||e.toolbar2?this.options={container:null,toolbar1:e.toolbar1||[],toolbar2:e.toolbar2||[]}:this.options={...Tt.DEFAULTS,...e},this.init(),this.preloadIcons()}init(){this.container=this.createToolbarContainer()}async preloadIcons(){}createToolbarContainer(){const t=document.createElement("div");t.className="rich-editor-toolbar-container",t.setAttribute("role","toolbar"),t.setAttribute("aria-label","Text formatting"),this.editor.preventFocusLoss(t),t.addEventListener("pointerdown",t=>{t.target.closest("button")&&t.preventDefault()}),this.toolbar1=document.createElement("div"),this.toolbar1.className="rich-editor-toolbar-1",this.toolbar2=document.createElement("div"),this.toolbar2.className="rich-editor-toolbar-2",this.toolbar2.style.display="none",this.flowGroups=[];return[...this.options.toolbar1||[],...this.options.toolbar2||[]].forEach(t=>{if(!t||!t.group||!Array.isArray(t.items))return;if(1===t.items.length&&"more"===t.items[0])return;const e=document.createElement("div");e.className=`toolbar-group toolbar-group-${t.group}`,t.items.forEach(t=>{"string"==typeof t&&this.addButton(e,t)}),this.toolbar1.appendChild(e),this.flowGroups.push(e)}),this.addMoreButton(this.toolbar1),this.moreBtn=this.buttons.get("more"),this.moreBtn&&this.moreBtn.classList.add("more-btn"),t.appendChild(this.toolbar1),t.appendChild(this.toolbar2),"undefined"!=typeof ResizeObserver&&(this._ro=new ResizeObserver(()=>this._scheduleReflow()),this._ro.observe(t)),requestAnimationFrame(()=>this.reflow()),this._setupKeyboardNav(t),t}_focusableButtons(){return Array.from(this.container.querySelectorAll(".rich-editor-toolbar-btn, .custom-select-button")).filter(t=>!t.disabled&&null!==t.offsetParent)}_updateRoving(){this._focusableButtons().forEach((t,e)=>{t.tabIndex=0===e?0:-1})}_setupKeyboardNav(t){t.addEventListener("keydown",t=>{if(!["ArrowLeft","ArrowRight","Home","End"].includes(t.key))return;const e=this._focusableButtons();if(!e.length)return;const i=e.indexOf(document.activeElement);let o;o="Home"===t.key?0:"End"===t.key?e.length-1:-1===i?0:"ArrowRight"===t.key?(i+1)%e.length:(i-1+e.length)%e.length,t.preventDefault(),e.forEach(t=>{t.tabIndex=-1}),e[o].tabIndex=0,e[o].focus()})}_scheduleReflow(){this._reflowQueued||(this._reflowQueued=!0,requestAnimationFrame(()=>{this._reflowQueued=!1,this.reflow()}))}reflow(){if(!this.toolbar1||!this.flowGroups||!this.moreBtn)return;if(this.flowGroups.forEach(t=>this.toolbar1.insertBefore(t,this.moreBtn)),"undefined"!=typeof window&&window.matchMedia&&window.matchMedia("(max-width: 640px)").matches)return this.moreBtn.style.display="none",this.toolbar2.style.display="none",this.toolbar2Visible=!1,this._syncMoreButton(),void this._updateRoving();const t=getComputedStyle(this.toolbar1),e=this.toolbar1.clientWidth-(parseFloat(t.paddingLeft)||0)-(parseFloat(t.paddingRight)||0);if(e<=0)return;let i=0;if(this.flowGroups.forEach((t,e)=>{i+=t.offsetWidth+(e>0?12:0)}),i<=e)return this.moreBtn.style.display="none",this.toolbar2.style.display="none",this.toolbar2Visible=!1,this._syncMoreButton(),void this._updateRoving();const o=e-((this.moreBtn.offsetWidth||32)+12);let n=0,r=this.flowGroups.length;for(let t=0;t<this.flowGroups.length;t++){const e=this.flowGroups[t].offsetWidth+(t>0?12:0);if(n+e>o){r=t;break}n+=e}r<1&&(r=1);for(let t=r;t<this.flowGroups.length;t++)this.toolbar2.appendChild(this.flowGroups[t]);this.moreBtn.style.display="",this.toolbar2.style.display=this.toolbar2Visible?"flex":"none",this._syncMoreButton(),this._updateRoving()}_syncMoreButton(){const t=this.moreBtn;t&&(t.setAttribute("aria-expanded",this.toolbar2Visible?"true":"false"),this.toolbar2Visible?(t.classList.add("active"),t.title="Hide more options"):(t.classList.remove("active"),t.title="More options"))}createToolbar(t,e){const i=document.createElement("div");return i.className=t,Array.isArray(e)&&e.forEach(t=>{if(t&&t.group&&Array.isArray(t.items)){const e=document.createElement("div");e.className=`toolbar-group toolbar-group-${t.group}`,t.items.forEach(t=>{"string"==typeof t&&this.addButton(e,t)}),i.appendChild(e)}}),i}addButton(t,e){if("more"===e)return this.addMoreButton(t);const i={heading:{text:"Paragraph",width:"124px",title:"Paragraph style",icon:"heading"},"font-family":{text:"Font Family",width:"156px",title:"Font",icon:"font-family"},"line-height":{text:"Line Height",width:"116px",title:"Line spacing",icon:"line-height"},capitalization:{text:"Capitalization",width:"146px",title:"Letter case",icon:"capitalization"},"text-size":{text:"Text Size",width:"116px",title:"Font size",icon:"text-size"}};if(i[e]){const o=i[e],n=jt(o.text,{width:o.width,icon:o.icon});return n.dataset.command=e,n.classList.add("rich-editor-toolbar-btn",`${e}-btn`),n.title=o.title,n.setAttribute("aria-label",o.title),n.setAttribute("aria-haspopup","true"),n.addEventListener("click",t=>{t.preventDefault(),this.emit("toolbar-click",{command:e,button:n}),setTimeout(()=>{this.editor.focus()},0)}),this.buttons.set(e,n),t.appendChild(n),n}const o={"text-align":{icon:"align-left",title:"Align Left"},list:{icon:"list",title:"List"}};if(o[e]){const i=o[e],n=document.createElement("button");n.type="button",n.className=`rich-editor-toolbar-btn ${e}-btn`,n.dataset.command=e,n.title=i.title,n.setAttribute("aria-label",i.title);const r=F.getIcon(i.icon);return r?n.innerHTML=`<span class="icon">${r}</span>`:n.textContent="text-align"===e?"≡":"•",n.addEventListener("click",t=>{t.preventDefault(),this.emit("toolbar-click",{command:e,button:n}),setTimeout(()=>{this.editor.focus()},0)}),this.buttons.set(e,n),t.appendChild(n),n}const n=document.createElement("button");n.type="button",n.className=`rich-editor-toolbar-btn ${e}-btn`,n.dataset.command=e;const r=F.createIconElement(e,{width:"16px",height:"16px"});n.appendChild(r);if(n.title={bold:"Bold (Ctrl+B)",italic:"Italic (Ctrl+I)",underline:"Underline (Ctrl+U)",strike:"Strikethrough",subscript:"Subscript",superscript:"Superscript",color:"Text Color",background:"Background Color",link:"Insert/Edit Link",table:"Insert Table",undo:"Undo (Ctrl+Z)",redo:"Redo (Ctrl+Y)","indent-increase":"Increase Indent","indent-decrease":"Decrease Indent",emoji:"Insert Emoji",image:"Insert Image",video:"Insert Video",tag:"Insert Tag","horizontal-rule":"Insert Horizontal Rule","clear-format":"Clear Formatting","text-direction":"Toggle Text Direction (LTR/RTL)",find:"Find & Replace (Ctrl+F)",import:"Import Files","code-view":"Switch to HTML Editor"}[e]||e,n.setAttribute("aria-label",n.title),"color"===e||"background"===e){const t=document.createElement("span");t.className="rte-swatch",n.appendChild(t)}return"code-view"===e&&setTimeout(()=>{r.innerHTML.trim()||(r.innerHTML="&lt;/&gt;",r.style.fontSize="12px",r.style.fontWeight="bold")},1e3),n.addEventListener("click",t=>{t.preventDefault(),this.emit("toolbar-click",{command:e,button:n}),setTimeout(()=>{this.editor.focus()},0)}),this.buttons.set(e,n),t.appendChild(n),n}addMoreButton(t){const e=document.createElement("button");e.type="button",e.className="rich-editor-toolbar-btn more-btn",e.dataset.command="more";const i=F.createIconElement("more",{width:"16px",height:"16px"});return e.appendChild(i),e.title="More Options",e.setAttribute("aria-label","More Options"),e.setAttribute("aria-expanded","false"),e.addEventListener("click",t=>{t.preventDefault(),this.toggleToolbar2(),setTimeout(()=>{this.editor.focus()},0)}),this.buttons.set("more",e),t.appendChild(e),e}toggleToolbar2(){this.moreBtn&&"none"===this.moreBtn.style.display||(this.toolbar2Visible=!this.toolbar2Visible,this.toolbar2.style.display=this.toolbar2Visible?"flex":"none",this._syncMoreButton(),this._updateRoving())}getContainer(){return this.container}getButton(t){return this.buttons.get(t)}setButtonActive(t,e){const i=this.buttons.get(t);i&&i.classList&&(e?i.classList.add("active"):i.classList.remove("active"),i.setAttribute("aria-pressed",e?"true":"false"))}setButtonDisabled(t,e){const i=this.buttons.get(t);i&&(i.disabled=e,i.style.opacity=e?"0.5":"1",i.style.cursor=e?"not-allowed":"pointer")}setButtonTitle(t,e){const i=this.buttons.get(t);i&&(i.title=e)}isToolbar2Visible(){return this.toolbar2Visible}on(t,e){this.events.has(t)||this.events.set(t,[]),this.events.get(t).push(e)}emit(t,e){const i=this.events.get(t);i&&i.forEach(t=>{try{t(e)}catch(t){}})}destroy(){this._ro&&(this._ro.disconnect(),this._ro=null),this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container),this.buttons.clear(),this.events.clear()}}class It extends e{static DEFAULTS={delay:1e3,maxStack:100,userOnly:!1};constructor(t,e={}){super(t,e),this.stack=[],this.index=-1,this.lastSave=0,this.savedSelection=null,this.init()}init(){this.setupEventListeners(),this.saveState()}setupEventListeners(){this._onInput=()=>{this.handleInput()},this._onKeydownSave=t=>{"Enter"!==t.key&&"Backspace"!==t.key&&"Delete"!==t.key||this.saveState()},this._onToolbarClick=t=>{t.target.closest(".rich-editor-toolbar-btn")&&setTimeout(()=>{this.saveState()},0)},this._onUndoRedo=t=>{!t.ctrlKey&&!t.metaKey||t.shiftKey||"z"!==t.key?((t.ctrlKey||t.metaKey)&&t.shiftKey&&"z"===t.key||(t.ctrlKey||t.metaKey)&&"y"===t.key)&&(t.preventDefault(),this.redo()):(t.preventDefault(),this.undo())},this.editor.editor.addEventListener("input",this._onInput),this.editor.editor.addEventListener("keydown",this._onKeydownSave),this.editor.wrapper.addEventListener("click",this._onToolbarClick),this.editor.editor.addEventListener("keydown",this._onUndoRedo),this.setupMutationObserver()}setupMutationObserver(){this.mutationObserver=new MutationObserver(t=>{let e=!1;for(const i of t)if("childList"===i.type||"attributes"===i.type&&(i.target.nodeType===Node.TEXT_NODE||["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","PRE","UL","OL","LI","SPAN","STRONG","EM","U","S","SUB","SUP","A","IMG","VIDEO","TABLE","TR","TD","TH"].includes(i.target.tagName))){e=!0;break}e&&(clearTimeout(this.mutationTimeout),this.mutationTimeout=setTimeout(()=>{this.saveState()},100))}),this.mutationObserver.observe(this.editor.editor,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style","class","href","src","alt","title"]})}handleInput(){const t=Date.now();t-this.lastSave>this.options.delay&&(this.saveState(),this.lastSave=t)}saveState(){const t=this.editor.getContent(),e=this.saveSelection();if(this.stack.length>0&&this.stack[this.index]?.content===t)return;const i=Date.now();this.lastSave&&i-this.lastSave<50||(this.index<this.stack.length-1&&this.stack.splice(this.index+1),this.stack.push({content:t,selection:e,timestamp:i}),this.stack.length>this.options.maxStack?this.stack.shift():this.index++,this.lastSave=i)}undo(){if(!this.canUndo())return!1;this.index--;const t=this.stack[this.index];return this.restoreState(t),this.onHistoryChange("undo"),!0}redo(){if(!this.canRedo())return!1;this.index++;const t=this.stack[this.index];return this.restoreState(t),this.onHistoryChange("redo"),!0}canUndo(){return this.index>0}canRedo(){return this.index<this.stack.length-1}restoreState(t){t&&(this.editor.setContent(t.content),t.selection&&setTimeout(()=>{this.restoreSelection(t.selection)},10))}saveSelection(){const t=window.getSelection();if(!t||!t.rangeCount)return null;const e=t.getRangeAt(0),i=this.editor.editor;return{startOffset:this.getOffsetInEditor(e.startContainer,e.startOffset,i),endOffset:this.getOffsetInEditor(e.endContainer,e.endOffset,i),collapsed:e.collapsed}}restoreSelection(t){if(!t)return;const e=this.editor.editor,i=document.createRange(),o=window.getSelection();try{const n=this.getNodeAtOffset(e,t.startOffset),r=this.getNodeAtOffset(e,t.endOffset);n&&r&&(i.setStart(n.node,n.offset),i.setEnd(r.node,r.offset),o.removeAllRanges(),o.addRange(i))}catch(t){this.editor.focus()}}getOffsetInEditor(t,e,i){let o=0;const n=document.createTreeWalker(i,NodeFilter.SHOW_TEXT,null,!1);let r;for(;r=n.nextNode();){if(r===t)return o+e;o+=r.textContent.length}return o}getNodeAtOffset(t,e){let i=0;const o=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,null,!1);let n;for(;n=o.nextNode();){const t=n.textContent.length;if(i+t>=e)return{node:n,offset:e-i};i+=t}return{node:t.lastChild||t,offset:0}}clear(){this.stack=[],this.index=-1,this.saveState()}getState(){return{canUndo:this.canUndo(),canRedo:this.canRedo(),stackLength:this.stack.length,currentIndex:this.index}}onHistoryChange(t){this.editor.modules.forEach(e=>{e!==this&&"function"==typeof e.onHistoryChange&&e.onHistoryChange(t,this.getState())});const e=new CustomEvent("historychange",{detail:{action:t,state:this.getState()}});this.editor.editor.dispatchEvent(e)}forceSave(){const t=this.lastSave;this.lastSave=0,this.saveState(),this.lastSave=t}saveBeforeFormat(){this.forceSave()}destroy(){this._onInput&&(this.editor.editor.removeEventListener("input",this._onInput),this.editor.editor.removeEventListener("keydown",this._onKeydownSave),this.editor.editor.removeEventListener("keydown",this._onUndoRedo),this.editor.wrapper.removeEventListener("click",this._onToolbarClick),this._onInput=this._onKeydownSave=this._onUndoRedo=this._onToolbarClick=null),this.mutationObserver&&(this.mutationObserver.disconnect(),this.mutationObserver=null),this.mutationTimeout&&(clearTimeout(this.mutationTimeout),this.mutationTimeout=null),this.stack=[],this.index=-1,this.savedSelection=null}}class St extends e{static DEFAULTS={showOnSelection:!0,showOnEnter:!0,buttons:["bold","italic","underline","strike","code"]};constructor(t,e={}){super(t,e),this.blockToolbar=null,this.isVisible=!1,this.currentSelection=null,this.currentCursorPosition=null,this.originalTags=new Map,this.init()}init(){this.preloadIcons(),this.createBlockToolbar(),this.setupEventListeners()}async preloadIcons(){}createBlockToolbar(){this.blockToolbar=document.createElement("div"),this.blockToolbar.className="block-toolbar";const t=document.createElement("div");t.className="block-toolbar-container";const e={bold:{icon:"bold",title:"Bold (Ctrl+B)"},italic:{icon:"italic",title:"Italic (Ctrl+I)"},underline:{icon:"underline",title:"Underline (Ctrl+U)"},strike:{icon:"strike",title:"Strikethrough"},code:{icon:"code",title:"Code"},"font-family":{icon:"font-family",title:"Font Family"},link:{icon:"link",title:"Insert link"},color:{icon:"color",title:"Text color"},background:{icon:"background",title:"Background color"}};(Array.isArray(this.options.buttons)&&this.options.buttons.length?this.options.buttons:["bold","italic","underline","strike","code","font-family"]).map(t=>({cmd:t,icon:e[t]&&e[t].icon||t,title:e[t]&&e[t].title||t})).forEach(({cmd:e,icon:i,title:o})=>{const n=document.createElement("button");n.className="block-toolbar-btn",n.title=o,n.dataset.command=e;const r=F.createIconElement(i,{width:"16px",height:"16px"});n.appendChild(r),n.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),this.handleCommand(e,n)}),t.appendChild(n)});const i=document.createElement("div");i.className="block-toolbar-arrow",this.blockToolbar.appendChild(t),this.blockToolbar.appendChild(i),this.editor.wrapper.appendChild(this.blockToolbar)}setupEventListeners(){this._onEditorMouseup=()=>{setTimeout(()=>this.handleSelectionChange(),0)},this._onEditorKeydown=t=>{"Enter"!==t.key||t.shiftKey||requestAnimationFrame(()=>{setTimeout(()=>this.showAtCursorAfterEnter(),10)})},this._onDocMousedown=t=>{t.target.closest(".font-family-select-popup")||t.target.closest(".custom-select-popup")||t.target.closest(".block-toolbar")||t.target.closest(".rich-editor-area")||this.hide()},this._onWindowScroll=()=>{this.isVisible&&this.updateToolbarPosition()},this._onEditorScroll=()=>{this.isVisible&&this.updateToolbarPosition()},this._onEditorKeyup=t=>{"Enter"===t.key&&t.shiftKey?this.hide():this.isVisible?this.updateButtonStates():this.handleSelectionChange()},this.options.showOnSelection&&this.editor.editor.addEventListener("mouseup",this._onEditorMouseup),this.options.showOnEnter&&this.editor.editor.addEventListener("keydown",this._onEditorKeydown),document.addEventListener("mousedown",this._onDocMousedown),window.addEventListener("scroll",this._onWindowScroll),this.editor.editor.addEventListener("scroll",this._onEditorScroll),this.editor.editor.addEventListener("keyup",this._onEditorKeyup)}handleSelectionChange(){const t=window.getSelection();if(!t||0===t.rangeCount)return this.hide();const e=t.getRangeAt(0);if(!(this.editor.isSelectionInEditableArea?this.editor.isSelectionInEditableArea(t):this.editor.editor.contains(e.commonAncestorContainer)))return this.hide();!e.collapsed&&t.toString().trim().length>0?this.showAtSelection(t):this.hide()}showAtSelection(t){if(!t||0===t.rangeCount)return;this.currentSelection=t,this.currentCursorPosition=null;const e=t.getRangeAt(0).getBoundingClientRect(),i=this.editor.wrapper.getBoundingClientRect(),o=window.pageYOffset||document.documentElement.scrollTop,n=window.pageXOffset||document.documentElement.scrollLeft;this.showAt(e.left+e.width/2-i.left+n,e.top-i.top+o-10)}showAtCursorAfterEnter(){this.editor.focus();const t=window.getSelection();if(!t||0===t.rangeCount)return;const e=t.getRangeAt(0);if(!(this.editor.isSelectionInEditableArea?this.editor.isSelectionInEditableArea(t):this.editor.editor.contains(e.commonAncestorContainer)))return;this.ensureCursorAtEndOfLine(e),this.currentSelection=t,this.currentCursorPosition=this.getCursorPositionAfterEnter();const i=this.currentCursorPosition;if(!i)return;const o=this.editor.wrapper.getBoundingClientRect(),n=window.pageYOffset||document.documentElement.scrollTop,r=window.pageXOffset||document.documentElement.scrollLeft;this.showAt(i.left-o.left+r,i.top-o.top+n-10)}ensureCursorAtEndOfLine(t){if(!t.collapsed)return;const e=window.getSelection(),i=t.startContainer;if(i.nodeType===Node.TEXT_NODE){const o=i.textContent.length;t.startOffset<o&&(t.setStart(i,o),t.setEnd(i,o),e.removeAllRanges(),e.addRange(t))}else if(i.nodeType===Node.ELEMENT_NODE){const o=document.createTreeWalker(i,NodeFilter.SHOW_TEXT,null,!1);let n,r=null;for(;n=o.nextNode();)r=n;if(r){const i=r.textContent.length;t.setStart(r,i),t.setEnd(r,i),e.removeAllRanges(),e.addRange(t)}}}getCursorPositionAfterEnter(){const t=window.getSelection();if(!t||0===t.rangeCount)return null;const e=t.getRangeAt(0),i=document.createElement("span");i.innerHTML="&#8203;",i.style.position="absolute",i.style.visibility="hidden",i.style.pointerEvents="none",e.insertNode(i);const o=i.getBoundingClientRect();i.parentNode&&i.parentNode.removeChild(i);const n=document.createRange();return n.setStart(e.startContainer,e.startOffset),n.collapse(!0),t.removeAllRanges(),t.addRange(n),o}showAtCursor(){const t=window.getSelection();if(!t||0===t.rangeCount)return;const e=t.getRangeAt(0);if(!(this.editor.isSelectionInEditableArea?this.editor.isSelectionInEditableArea(t):this.editor.editor.contains(e.commonAncestorContainer)))return;let i;if(e.collapsed){const o=document.createElement("span");o.innerHTML="&#8203;",o.style.position="absolute",o.style.visibility="hidden",o.style.pointerEvents="none",e.insertNode(o),i=o.getBoundingClientRect(),o.parentNode&&o.parentNode.removeChild(o);const n=document.createRange();n.setStart(e.startContainer,e.startOffset),n.collapse(!0),t.removeAllRanges(),t.addRange(n)}else i=e.getBoundingClientRect();const o=this.editor.wrapper.getBoundingClientRect(),n=window.pageYOffset||document.documentElement.scrollTop,r=window.pageXOffset||document.documentElement.scrollLeft;this.showAt(i.left-o.left+r,i.top-o.top+n-10)}showAt(t,e){this.blockToolbar&&(this.blockToolbar.classList.add("visible"),this.isVisible=!0,this.ensureToolbarInViewport(t,e),this.updateButtonStates())}ensureToolbarInViewport(t,e){if(!this.blockToolbar)return;const i=this.editor.editor,o=i.getBoundingClientRect();this.blockToolbar.getBoundingClientRect();const n=this.editor.wrapper.querySelector(".rich-editor-toolbar-container"),r=n?n.getBoundingClientRect():null;let s=t-this.blockToolbar.offsetWidth/2,a=o.y+e-r.height-i.scrollTop-(o.y+window.scrollY)+n.offsetHeight-49,l="50%",c="down";if(s<0&&(s=t-.1*this.blockToolbar.offsetWidth,s<0&&(s=0),l="10%"),s+this.blockToolbar.offsetWidth>this.editor.wrapper.offsetWidth-2&&(s=t-.9*this.blockToolbar.offsetWidth,l="90%"),a<r.height&&(a=o.y+e-r.height-i.scrollTop+100-(o.y+window.scrollY)+n.offsetHeight-49,c="up",a<r.height))return void this.hide();if(a>o.height)return void this.hide();const d=this.blockToolbar.querySelector(".block-toolbar-arrow");d&&(d.style.left=l,"up"===c?(d.style.bottom="auto",d.style.top="-8px",d.style.borderTop="none",d.style.borderBottom="8px solid #fff",d.style.borderLeft="6px solid transparent",d.style.borderRight="6px solid transparent"):(d.style.top="auto",d.style.bottom="-8px",d.style.borderBottom="none",d.style.borderTop="8px solid #fff",d.style.borderLeft="6px solid transparent",d.style.borderRight="6px solid transparent")),this.blockToolbar.style.left=s+"px",this.blockToolbar.style.top=a+"px"}updateToolbarPosition(){if(!this.isVisible)return;const t=window.getSelection();if(!t||0===t.rangeCount)return void this.hide();const e=t.getRangeAt(0);if(!(this.editor.isSelectionInEditableArea?this.editor.isSelectionInEditableArea(t):this.editor.editor.contains(e.commonAncestorContainer)))return void this.hide();let i;if(e.collapsed){const o=document.createElement("span");o.innerHTML="&#8203;",o.style.position="absolute",o.style.visibility="hidden",o.style.pointerEvents="none";try{e.insertNode(o),i=o.getBoundingClientRect(),o.parentNode&&o.parentNode.removeChild(o);const n=document.createRange();n.setStart(e.startContainer,e.startOffset),n.collapse(!0),t.removeAllRanges(),t.addRange(n)}catch(t){return void this.hide()}}else i=e.getBoundingClientRect();const o=this.editor.wrapper.getBoundingClientRect(),n=window.pageYOffset||document.documentElement.scrollTop,r=window.pageXOffset||document.documentElement.scrollLeft;let s,a;e.collapsed?(s=i.left-o.left+r,a=i.top-o.top+n-10):(s=i.left+i.width/2-o.left+r,a=i.top-o.top+n-10),this.updateToolbarAt(s,a);const l=this.editor.registry.get("formats/font-family");l&&l.selectInstance&&l.selectInstance.isVisible&&l.selectInstance.updatePosition()}updateToolbarAt(t,e){this.blockToolbar&&(this.ensureToolbarInViewport(t,e),this.updateButtonStates())}hide(){if(!this.blockToolbar||!this.isVisible)return;this.blockToolbar.classList.remove("visible"),this.isVisible=!1,this.currentSelection=null,this.currentCursorPosition=null;const t=this.editor.registry.get("formats/font-family");t&&t.selectInstance&&t.selectInstance.hide()}handleCommand(t,e){const o=window.getSelection();if(!(!this.editor.isSelectionInEditableArea||this.editor.isSelectionInEditableArea(o)))return void this.hide();if("font-family"===t){const i=this.editor.registry.get("formats/font-family");if(i){return(new i).toggle(e),this.updateButtonState(t,e),void this.editor.focus()}}if("code"===t){const i=this.editor.registry.get("formats/heading");if(i){const o=new i,n=o.getCurrentTag();if("PRE"===n){const t=window.getSelection();if(t&&t.rangeCount){const e=t.getRangeAt(0),i=this.getBlockElement(e.startContainer);if(i){const t=this.originalTags.get(i)||"P";o.apply(t),this.originalTags.delete(i)}else o.apply("P")}else o.apply("P")}else{const t=window.getSelection();if(t&&t.rangeCount){const e=t.getRangeAt(0),i=this.getBlockElement(e.startContainer);i&&this.originalTags.set(i,n||"P")}o.apply("PRE")}return this.updateButtonState(t,e),void this.editor.focus()}}const n=this.editor.registry.get(`formats/${t}`);if(n){const t=new n;"function"==typeof t.toggle?t.toggle():"function"==typeof t.apply&&t.apply()}else i(t);this.updateButtonState(t,e),this.editor.focus()}updateButtonStates(){if(!this.blockToolbar)return;this.blockToolbar.querySelectorAll(".block-toolbar-btn").forEach(t=>{const e=t.dataset.command;this.updateButtonState(e,t)})}updateButtonState(t,e){if(!e)return;let i=!1;if("font-family"===t){const t=this.editor.registry.get("formats/font-family");if(t){i=(new t).isActive()}}else if("code"===t){const t=this.editor.registry.get("formats/heading");if(t){i="PRE"===(new t).getCurrentTag()}}else if("strike"===t){const e=this.editor.registry.get(`formats/${t}`);if(e){i=(new e).isActive()}}else i=n(t);i?e.classList.add("active"):e.classList.remove("active")}getBlockElement(t){if(!t)return null;if(t.nodeType===Node.ELEMENT_NODE){if(["H1","H2","H3","H4","H5","H6","P","PRE","BLOCKQUOTE","DIV"].includes(t.tagName))return t}let e=t;for(;e&&e!==this.editor.editor;){if(e.nodeType===Node.ELEMENT_NODE){if(["H1","H2","H3","H4","H5","H6","P","PRE","BLOCKQUOTE","DIV"].includes(e.tagName))return e}e=e.parentNode}return null}destroy(){this._onDocMousedown&&(document.removeEventListener("mousedown",this._onDocMousedown),window.removeEventListener("scroll",this._onWindowScroll),this.editor.editor.removeEventListener("mouseup",this._onEditorMouseup),this.editor.editor.removeEventListener("keydown",this._onEditorKeydown),this.editor.editor.removeEventListener("scroll",this._onEditorScroll),this.editor.editor.removeEventListener("keyup",this._onEditorKeyup),this._onDocMousedown=this._onWindowScroll=this._onEditorMouseup=null,this._onEditorKeydown=this._onEditorScroll=this._onEditorKeyup=null),this.blockToolbar&&this.blockToolbar.parentNode&&this.blockToolbar.parentNode.removeChild(this.blockToolbar),this.blockToolbar=null,this.isVisible=!1,this.originalTags.clear()}}class Nt extends e{static DEFAULTS={fadeDelay:3e3,buttons:["tableProfile","deleteTable","insertRowAbove","insertRowBelow","deleteRow","insertColRight","insertColLeft","deleteCol"]};constructor(t,e={}){super(t,e),this.tableToolbar=null,this.currentTable=null,this.currentCell=null,this.hideTimeout=null,this.isVisible=!1,this.init()}async init(){await this.createTableToolbar(),this.setupEventListeners()}async createTableToolbar(){this.tableToolbar=document.createElement("div"),this.tableToolbar.className="table-toolbar";const t=document.createElement("div");t.className="table-toolbar-container";const e=[{name:"table-actions",buttons:[{cmd:"tableProfile",icon:"icon-table-profile",title:"Table Profile"},{cmd:"deleteTable",icon:"icon-delete-table",title:"Delete Table"}]},{name:"row-actions",buttons:[{cmd:"insertRowAbove",icon:"icon-add-row-above",title:"Add Row Above"},{cmd:"insertRowBelow",icon:"icon-add-row-below",title:"Add Row Below"},{cmd:"deleteRow",icon:"icon-delete-row",title:"Delete Selected Row"}]},{name:"col-actions",buttons:[{cmd:"insertColRight",icon:"icon-add-col-right",title:"Add Column Right"},{cmd:"insertColLeft",icon:"icon-add-col-left",title:"Add Column Left"},{cmd:"deleteCol",icon:"icon-delete-col",title:"Delete Selected Column"}]}];for(const i of e){const e=document.createElement("div");e.className=`table-toolbar-group ${i.name}`;for(const{cmd:t,icon:o,title:n}of i.buttons){const i=document.createElement("button");i.className="table-toolbar-btn",i.title=n,i.dataset.command=t;const r=F.getIcon(o.replace("icon-",""));r&&(i.innerHTML=r),i.addEventListener("click",e=>{e.preventDefault(),e.stopPropagation(),this.handleCommand(t,i)}),e.appendChild(i)}t.appendChild(e)}const i=document.createElement("div");i.className="table-toolbar-arrow",this.tableToolbar.appendChild(t),this.tableToolbar.appendChild(i),this.editor.wrapper.appendChild(this.tableToolbar)}setupEventListeners(){this._onEditorClick=t=>{const e=t.target.closest("td, th"),i=t.target.closest("table");if(i&&e){if(!(!this.editor.isNodeInEditableArea||this.editor.isNodeInEditableArea(i)))return void this.hide();this.currentTable=i,this.currentCell=e,this.showAtTable(i)}else this.hide()},this._onDocMousedown=t=>{t.target.closest(".table-toolbar")||t.target.closest("table")||this.hide()},this._onWindowScroll=()=>{this.isVisible&&this.currentTable&&this.updateToolbarPosition()},this._onEditorScroll=()=>{this.isVisible&&this.currentTable&&this.updateToolbarPosition()},this.editor.editor.addEventListener("click",this._onEditorClick),document.addEventListener("mousedown",this._onDocMousedown),window.addEventListener("scroll",this._onWindowScroll),this.editor.editor.addEventListener("scroll",this._onEditorScroll),this._onEditorKeyup=t=>{if(this.isVisible&&this.currentTable){const t=window.getSelection();if(t&&t.rangeCount>0){const e=t.getRangeAt(0).startContainer,i=e.nodeType===Node.TEXT_NODE?e.parentElement.closest("td, th"):e.closest("td, th");if(i&&i!==this.currentCell){if(!(!this.editor.isNodeInEditableArea||this.editor.isNodeInEditableArea(i)))return void this.hide();this.currentCell=i}}}},this.editor.editor.addEventListener("keyup",this._onEditorKeyup)}updateToolbarPosition(){if(!this.isVisible||!this.currentTable)return;if(!document.body.contains(this.currentTable))return void this.hide();if(!(!this.editor.isNodeInEditableArea||this.editor.isNodeInEditableArea(this.currentTable)))return void this.hide();const t=this.currentTable.getBoundingClientRect(),e=this.editor.wrapper.getBoundingClientRect(),i=window.pageYOffset||document.documentElement.scrollTop,o=window.pageXOffset||document.documentElement.scrollLeft;this.updateToolbarAt(t.left-e.left+o,t.top-e.top+i,t.width,t.height)}updateToolbarAt(t,e,i,o){this.tableToolbar&&this.ensureToolbarInViewport(t,e,i,o)}showAtTable(t){if(!t||!this.tableToolbar)return;const e=t.getBoundingClientRect(),i=this.editor.wrapper.getBoundingClientRect(),o=window.pageYOffset||document.documentElement.scrollTop,n=window.pageXOffset||document.documentElement.scrollLeft;this.showAt(e.left-i.left+n,e.top-i.top+o,e.width,e.height)}showAt(t,e,i,o){this.tableToolbar&&(this.tableToolbar.classList.add("visible"),this.isVisible=!0,this.ensureToolbarInViewport(t,e,i,o),this.clearHideTimeout())}ensureToolbarInViewport(t,e,i,o){if(!this.tableToolbar)return;const n=this.editor.editor.getBoundingClientRect();this.tableToolbar.getBoundingClientRect();const r=this.editor.wrapper.querySelector(".rich-editor-toolbar-container"),s=r?r.getBoundingClientRect():null;let a=t+i/2-this.tableToolbar.offsetWidth/2,l=e-60-document.documentElement.scrollTop,c="50%",d="down";if(a<0&&(a=t-.1*this.tableToolbar.offsetWidth,a<0&&(a=0),c="10%"),a+this.tableToolbar.offsetWidth>this.editor.wrapper.offsetWidth-2&&(a=t-.9*this.tableToolbar.offsetWidth,c="90%"),l<(s?s.height:48)&&(l=e+o+10-document.documentElement.scrollTop,d="up",l<(s?s.height:48)))return void this.hide();if(l>n.height)return void this.hide();const h=this.tableToolbar.querySelector(".table-toolbar-arrow");h&&(h.style.left=c,"up"===d?(h.style.bottom="auto",h.style.top="-8px",h.style.borderTop="none",h.style.borderBottom="8px solid #fff",h.style.borderLeft="6px solid transparent",h.style.borderRight="6px solid transparent"):(h.style.top="auto",h.style.bottom="-8px",h.style.borderBottom="none",h.style.borderTop="8px solid #fff",h.style.borderLeft="6px solid transparent",h.style.borderRight="6px solid transparent")),this.tableToolbar.style.left=a+"px",this.tableToolbar.style.top=l+"px"}hide(){this.tableToolbar&&this.isVisible&&(this.tableToolbar.classList.remove("visible"),this.isVisible=!1,this.currentTable=null,this.currentCell=null,this.clearHideTimeout())}clearHideTimeout(){this.hideTimeout&&(clearTimeout(this.hideTimeout),this.hideTimeout=null)}handleCommand(t,e){if(!this.currentTable||!this.currentCell)return;if(!this.editor.isNodeInEditableArea||this.editor.isNodeInEditableArea(this.currentTable)){switch(t){case"tableProfile":this.showTableProfile();break;case"deleteTable":this.deleteTable();break;case"insertRowAbove":this.insertRowAbove();break;case"insertRowBelow":this.insertRowBelow();break;case"deleteRow":this.deleteRow();break;case"insertColRight":this.insertColumnRight();break;case"insertColLeft":this.insertColumnLeft();break;case"deleteCol":this.deleteColumn()}this.editor.focus()}else this.hide()}insertRowAbove(){const t=this.currentCell.parentElement,e=this.createNewRow(t.cells.length);t.parentElement.insertBefore(e,t),this.editor.resizeHandles&&this.editor.resizeHandles.checkAndUpdateHandles()}insertRowBelow(){const t=this.currentCell.parentElement,e=this.createNewRow(t.cells.length);t.nextElementSibling?t.parentElement.insertBefore(e,t.nextElementSibling):t.parentElement.appendChild(e),this.editor.resizeHandles&&this.editor.resizeHandles.checkAndUpdateHandles()}insertColumnLeft(){const t=Array.from(this.currentCell.parentElement.children).indexOf(this.currentCell);(this.currentTable.querySelector("tbody")||this.currentTable).querySelectorAll("tr").forEach(e=>{const i=this.createNewCell(),o=e.children[t];o?e.insertBefore(i,o):e.appendChild(i)}),this.editor.resizeHandles&&this.editor.resizeHandles.checkAndUpdateHandles()}insertColumnRight(){const t=Array.from(this.currentCell.parentElement.children).indexOf(this.currentCell);(this.currentTable.querySelector("tbody")||this.currentTable).querySelectorAll("tr").forEach(e=>{const i=this.createNewCell(),o=e.children[t+1];o?e.insertBefore(i,o):e.appendChild(i)}),this.editor.resizeHandles&&this.editor.resizeHandles.checkAndUpdateHandles()}deleteRow(){const t=this.currentCell.parentElement;t.parentElement.children.length<=1||(t.remove(),this.editor.resizeHandles&&this.editor.resizeHandles.checkAndUpdateHandles(),this.hide())}deleteColumn(){const t=Array.from(this.currentCell.parentElement.children).indexOf(this.currentCell),e=(this.currentTable.querySelector("tbody")||this.currentTable).querySelectorAll("tr");this.currentCell.parentElement.children.length<=1||(e.forEach(e=>{e.children[t]&&e.children[t].remove()}),this.editor.resizeHandles&&this.editor.resizeHandles.checkAndUpdateHandles(),this.hide())}showTableProfile(){if(!this.currentTable)return;const t=this.currentTable.querySelectorAll("tr").length,e=this.currentTable.querySelector("tr")?this.currentTable.querySelector("tr").querySelectorAll("td, th").length:0,i=t,o=e,n=t*e,r=this.currentTable.offsetWidth,s=this.currentTable.offsetHeight;alert(`Table Profile:\nRows: ${i}\nColumns: ${o}\nTotal Cells: ${n}\nWidth: ${r}px\nHeight: ${s}px`)}deleteTable(){this.editor.resizeHandles&&this.editor.resizeHandles.hideHandles(),this.currentTable.remove(),this.hide()}createNewRow(t){const e=document.createElement("tr");for(let i=0;i<t;i++)e.appendChild(this.createNewCell());return e}createNewCell(){const t=document.createElement("td");return t.innerHTML="&nbsp;",t.style.minWidth="50px",t.style.minHeight="24px",t.style.padding="4px 8px",t.style.border="1px solid #ddd",t.style.verticalAlign="top",t.contentEditable="true",t}destroy(){this._onDocMousedown&&(document.removeEventListener("mousedown",this._onDocMousedown),window.removeEventListener("scroll",this._onWindowScroll),this.editor.editor.removeEventListener("click",this._onEditorClick),this.editor.editor.removeEventListener("scroll",this._onEditorScroll),this.editor.editor.removeEventListener("keyup",this._onEditorKeyup),this._onDocMousedown=this._onWindowScroll=this._onEditorClick=null,this._onEditorScroll=this._onEditorKeyup=null),this.tableToolbar&&this.tableToolbar.parentNode&&this.tableToolbar.parentNode.removeChild(this.tableToolbar),this.clearHideTimeout(),this.tableToolbar=null,this.currentTable=null,this.currentCell=null,this.isVisible=!1}}class Lt extends e{constructor(t,e={}){super(t,e),this.isCodeView=!1,this.originalContent="",this.codeTextarea=null,this.disabledModules=new Set,this.init()}init(){this.editor.on("toolbar-click",t=>{"code-view"===t.command&&this.toggleCodeView()})}toggleCodeView(){this.isCodeView?this.showNormalView():this.showCodeView(),this.updateToolbarButton()}showCodeView(){const t=this.editor.editor;if(!t)return;this.originalContent=t.innerHTML,this.codeTextarea=document.createElement("textarea"),this.codeTextarea.className="code-view-textarea",this.codeTextarea.value=this.formatHTML(this.originalContent),t.style.display="none",t.parentNode.insertBefore(this.codeTextarea,t);const e=this.editor.wrapper;e&&e.classList.add("code-view-active"),this.codeTextarea.focus(),this.isCodeView=!0,"function"==typeof this.editor.updateStatusbar&&this.editor.updateStatusbar(),this.disableOtherFeatures(),this.codeTextarea.addEventListener("input",()=>{this.updateOriginalContent()})}showNormalView(){const t=this.editor.editor;if(!t||!this.codeTextarea)return;const e=this.codeTextarea.value;this.codeTextarea.parentNode.removeChild(this.codeTextarea),this.codeTextarea=null;const i=this.editor.wrapper;i&&i.classList.remove("code-view-active"),t.style.display="",t.innerHTML=d(e),t.focus(),this.isCodeView=!1,this.enableOtherFeatures(),this.editor.onContentChange()}disableOtherFeatures(){const t=this.editor.getModule("toolbar");if(t){["bold","italic","underline","strike","subscript","superscript","color","background","link","table","heading","font-family","line-height","capitalization","text-align","list","indent-increase","indent-decrease","text-size","emoji","image","video","tag","import","undo","redo","clear-format","horizontal-rule","text-direction","find","more"].forEach(e=>{t.setButtonDisabled(e,!0)}),t.setButtonDisabled("code-view",!1),t.setButtonDisabled("theme",!1)}this.disableEditorEvents(),this.disableOtherModules(),this.hideAllPopups()}enableOtherFeatures(){const t=this.editor.getModule("toolbar");if(t){["bold","italic","underline","strike","subscript","superscript","color","background","link","table","heading","font-family","line-height","capitalization","text-align","list","indent-increase","indent-decrease","text-size","emoji","image","video","tag","import","undo","redo","clear-format","horizontal-rule","text-direction","find","more"].forEach(e=>{t.setButtonDisabled(e,!1)})}this.enableEditorEvents(),this.enableOtherModules()}disableEditorEvents(){const t=this.editor.editor;t&&(t.contentEditable=!1,t.style.opacity="0.5",t.style.pointerEvents="none",t.style.cursor="not-allowed",t.title='Editor is disabled in code view mode. Click "Switch to Visual Editor" to return to normal editing.')}enableEditorEvents(){const t=this.editor.editor;t&&(t.contentEditable=!0,t.style.opacity="",t.style.pointerEvents="",t.style.cursor="",t.title="")}disableOtherModules(){["history","block-toolbar","table-toolbar","resize-handles"].forEach(t=>{const e=this.editor.getModule(t);if(e)if("function"==typeof e.disable)e.disable(),this.disabledModules.add(t);else if(e.getContainer&&"function"==typeof e.getContainer){const i=e.getContainer();i&&(i.style.display="none",this.disabledModules.add(t))}})}enableOtherModules(){this.disabledModules.forEach(t=>{const e=this.editor.getModule(t);if(e)if("function"==typeof e.enable)e.enable();else if(e.getContainer&&"function"==typeof e.getContainer){const t=e.getContainer();t&&(t.style.display="")}}),this.disabledModules.clear()}updateOriginalContent(){if(this.codeTextarea){this.originalContent=this.codeTextarea.value;const t=this.codeTextarea.value;this.editor.options.onChange&&"function"==typeof this.editor.options.onChange&&this.editor.options.onChange(t),this.editor.emit("text-change",t),"function"==typeof this.editor.updateStatusbar&&this.editor.updateStatusbar()}}formatHTML(t){let e=t;e=e.replace(/></g,">\n<"),e=e.replace(/>([^<>\s][^<]*)</g,">\n$1\n<");const i=e.split("\n"),o=[],n=[];for(let t of i){const e=t.trim();if(!e)continue;if(/^<\/(\w+)/.test(e)){const t=e.match(/^<\/(\w+)/);if(t){const e=t[1];for(let t=n.length-1;t>=0;t--)if(n[t]===e){n.splice(t,1);break}}}let i=n.length;e.startsWith("<")||(i=n.length),o.push(" ".repeat(4*i)+e);const r=e.match(/^<(\w+)/);if(r&&!e.startsWith("</")&&!e.endsWith("/>")&&!["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"].includes(r[1].toLowerCase())){const t=r[1];n.push(t)}}return o.join("\n")}updateToolbarButton(){const t=this.editor.getModule("toolbar");if(t){t.setButtonActive("code-view",this.isCodeView);const e=this.isCodeView?"Switch to Visual Editor":"Switch to HTML Editor";t.setButtonTitle("code-view",e)}}isInCodeView(){return this.isCodeView}getCurrentContent(){return this.isCodeView&&this.codeTextarea?this.codeTextarea.value:this.editor.editor.innerHTML}setContent(t){this.isCodeView&&this.codeTextarea?(this.codeTextarea.value=this.formatHTML(t),this.updateOriginalContent()):this.editor.editor.innerHTML=t}hideAllPopups(){document.querySelectorAll(".rich-editor-popup, .color-picker-popup, .emoji-picker-popup, .link-popup, .image-popup, .video-popup, .table-popup, .tag-popup, .import-popup").forEach(t=>{t.parentNode&&t.parentNode.removeChild(t)}),this.editor.popupInstances&&this.editor.popupInstances.clear()}destroy(){this.isCodeView&&this.showNormalView(),this.codeTextarea&&this.codeTextarea.parentNode&&this.codeTextarea.parentNode.removeChild(this.codeTextarea),this.codeTextarea=null,this.originalContent="",this.isCodeView=!1,this.disabledModules.clear()}}class At extends e{constructor(t,e={}){super(t,e),this.hits=[],this.activeIndex=-1,this.caseSensitive=!1,this.isOpen=!1,this.buildPanel(),this.bindEvents()}buildPanel(){const t=document.createElement("div");t.className="yjd-find-replace";const e=(t,e)=>{const i=document.createElement("input");return i.type="text",i.placeholder=t,i.className=`yjd-find-input ${e}`,i.setAttribute("aria-label",t),i},i=(t,e,i="",o=null)=>{const n=document.createElement("button");if(n.type="button",o){const e=F.getIcon(o);n.innerHTML=e?`<span class="icon">${e}</span>`:t}else n.textContent=t;return n.title=e,n.setAttribute("aria-label",e),n.className=`yjd-find-btn ${i}`.trim(),n},o=document.createElement("div");o.className="yjd-find-row";const n=document.createElement("div");n.className="yjd-find-row",this.findInput=e("Find","yjd-find-field"),this.replaceInput=e("Replace with","yjd-find-field"),this.countEl=document.createElement("span"),this.countEl.className="yjd-find-count",this.countEl.textContent="0/0",this.prevBtn=i("","Previous match","yjd-find-icon","chevron-up"),this.nextBtn=i("","Next match","yjd-find-icon","chevron-down"),this.caseBtn=i("Aa","Match case","yjd-find-icon yjd-find-toggle"),this.closeBtn=i("","Close (Esc)","yjd-find-icon yjd-find-close","close"),this.replaceBtn=i("Replace","Replace current"),this.replaceAllBtn=i("Replace all","Replace all matches"),o.append(this.findInput,this.countEl,this.prevBtn,this.nextBtn,this.caseBtn,this.closeBtn),n.append(this.replaceInput,this.replaceBtn,this.replaceAllBtn),t.append(o,n),this.panel=t,this.editor.wrapper.appendChild(t)}bindEvents(){this._onKeydown=t=>{!t.ctrlKey&&!t.metaKey||t.shiftKey||t.altKey||"f"!==t.key.toLowerCase()||(t.preventDefault(),this.open())},this.editor.editor.addEventListener("keydown",this._onKeydown),this._onToolbarClick=t=>{t&&"find"===t.command&&this.open()},this.editor.on("toolbar-click",this._onToolbarClick),this.findInput.addEventListener("input",()=>this.runSearch()),this.findInput.addEventListener("keydown",t=>{"Enter"===t.key?(t.preventDefault(),this.navigate(t.shiftKey?-1:1)):"Escape"===t.key&&(t.preventDefault(),this.close())}),this.replaceInput.addEventListener("keydown",t=>{"Enter"===t.key?(t.preventDefault(),this.replaceCurrent()):"Escape"===t.key&&(t.preventDefault(),this.close())}),this.prevBtn.addEventListener("click",()=>this.navigate(-1)),this.nextBtn.addEventListener("click",()=>this.navigate(1)),this.replaceBtn.addEventListener("click",()=>this.replaceCurrent()),this.replaceAllBtn.addEventListener("click",()=>this.replaceAll()),this.caseBtn.addEventListener("click",()=>{this.caseSensitive=!this.caseSensitive,this.caseBtn.classList.toggle("active",this.caseSensitive),this.caseBtn.setAttribute("aria-pressed",this.caseSensitive?"true":"false"),this.runSearch()}),this.closeBtn.addEventListener("click",()=>this.close())}open(){this.isOpen=!0,this.panel.classList.add("open");const t=this.editor.wrapper.querySelector(".rich-editor-toolbar-container");t&&(this.panel.style.top=t.offsetHeight+6+"px");const e=window.getSelection(),i=e&&!e.isCollapsed?e.toString():"";i&&!i.includes("\n")&&(this.findInput.value=i),this.findInput.focus(),this.findInput.select(),this.runSearch()}close(){this.isOpen=!1,this.panel.classList.remove("open"),this.clearHighlights(),this.hits=[],this.activeIndex=-1,this.editor.focus()}escapeRegex(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}clearHighlights(){this.editor.editor.querySelectorAll("mark.yjd-find-hit").forEach(t=>{const e=t.parentNode;if(e){for(;t.firstChild;)e.insertBefore(t.firstChild,t);e.removeChild(t),e.normalize()}})}runSearch(){this.clearHighlights(),this.hits=[],this.activeIndex=-1;const t=this.findInput.value;if(!t)return void this.updateCount();let e;try{e=new RegExp(this.escapeRegex(t),this.caseSensitive?"g":"gi")}catch(t){return void this.updateCount()}const i=this.editor.editor,o=document.createTreeWalker(i,NodeFilter.SHOW_TEXT,null),n=[];let r;for(;r=o.nextNode();)r.nodeValue&&r.nodeValue.length&&n.push(r);n.forEach(t=>{const i=t.nodeValue,o=[];let n;for(e.lastIndex=0;null!==(n=e.exec(i));)0!==n[0].length?o.push([n.index,n.index+n[0].length]):e.lastIndex++;for(let e=o.length-1;e>=0;e--){const i=document.createRange();i.setStart(t,o[e][0]),i.setEnd(t,o[e][1]);const n=document.createElement("mark");n.className="yjd-find-hit";try{i.surroundContents(n)}catch(t){}}}),this.hits=Array.from(i.querySelectorAll("mark.yjd-find-hit")),this.hits.length&&(this.activeIndex=0,this.highlightActive(!0)),this.updateCount()}highlightActive(t){this.hits.forEach((t,e)=>{t.classList.toggle("active",e===this.activeIndex)}),t&&this.activeIndex>=0&&this.hits[this.activeIndex]&&this.hits[this.activeIndex].scrollIntoView({block:"nearest",inline:"nearest"})}navigate(t){this.hits.length&&(this.activeIndex=(this.activeIndex+t+this.hits.length)%this.hits.length,this.highlightActive(!0),this.updateCount())}updateCount(){const t=this.hits.length,e=t?this.activeIndex+1:0;this.countEl.textContent=`${e}/${t}`}replaceCurrent(){if(this.activeIndex<0||!this.hits[this.activeIndex])return;const t=this.editor.getModule("history");t&&"function"==typeof t.saveBeforeFormat&&t.saveBeforeFormat();const e=this.hits[this.activeIndex],i=this.activeIndex,o=e.parentNode;o.replaceChild(document.createTextNode(this.replaceInput.value),e),o.normalize(),this.editor.onContentChange(),this.runSearch(),this.hits.length&&(this.activeIndex=Math.min(i,this.hits.length-1),this.highlightActive(!0),this.updateCount())}replaceAll(){if(!this.hits.length)return;const t=this.editor.getModule("history");t&&"function"==typeof t.saveBeforeFormat&&t.saveBeforeFormat();const e=this.replaceInput.value;this.hits.forEach(t=>{const i=t.parentNode;i&&i.replaceChild(document.createTextNode(e),t)}),this.editor.editor.normalize(),this.editor.onContentChange(),this.runSearch()}destroy(){this.editor.editor.removeEventListener("keydown",this._onKeydown),this.editor.off("toolbar-click",this._onToolbarClick),this.clearHighlights(),this.panel&&this.panel.parentNode&&this.panel.parentNode.removeChild(this.panel),super.destroy()}}class Bt extends e{constructor(t,e={}){super(t,e),this.isOpen=!1,this.activeIndex=0,this.query="",this.filtered=[],this.commands=this.buildCommands(),this.buildMenu(),this.bindEvents()}buildCommands(){const t=this.editor;return[{id:"h1",label:"Heading 1",hint:"Big section heading",icon:"heading",run:()=>t.setBlockType("h1")},{id:"h2",label:"Heading 2",hint:"Medium heading",icon:"heading",run:()=>t.setBlockType("h2")},{id:"h3",label:"Heading 3",hint:"Small heading",icon:"heading",run:()=>t.setBlockType("h3")},{id:"ul",label:"Bullet list",hint:"Unordered list",icon:"list-bullet",run:()=>t.setBlockType("ul")},{id:"ol",label:"Numbered list",hint:"Ordered list",icon:"list-ordered",run:()=>t.setBlockType("ol")},{id:"quote",label:"Quote",hint:"Blockquote",icon:"code",run:()=>t.setBlockType("blockquote")},{id:"code",label:"Code block",hint:"Preformatted code",icon:"code-view",run:()=>t.setBlockType("pre")},{id:"hr",label:"Divider",hint:"Horizontal rule",icon:"horizontal-rule",run:()=>t.insertHorizontalRule()},{id:"table",label:"Table",hint:"3×3 table",icon:"table",run:()=>this.insertTable()},{id:"p",label:"Text",hint:"Plain paragraph",icon:"font-family",run:()=>t.setBlockType("p")}]}insertTable(){const t=this.editor.registry.get("formats/table");t&&"function"==typeof t.createTableElement&&"function"==typeof this.editor.insertBlock&&this.editor.insertBlock(t.createTableElement(3,3))}buildMenu(){const t=document.createElement("div");t.className="yjd-slash-menu",t.setAttribute("role","listbox"),t.style.display="none",this.menu=t,document.body.appendChild(t)}bindEvents(){this._onInput=()=>this.handleInput(),this.editor.editor.addEventListener("input",this._onInput),this._onKeydown=t=>{this.isOpen&&("ArrowDown"===t.key?(t.preventDefault(),this.move(1)):"ArrowUp"===t.key?(t.preventDefault(),this.move(-1)):"Enter"===t.key?(t.preventDefault(),this.choose(this.activeIndex)):"Escape"===t.key&&(t.preventDefault(),this.close()))},this.editor.editor.addEventListener("keydown",this._onKeydown,!0),this._onDocPointer=t=>{this.isOpen&&!this.menu.contains(t.target)&&this.close()},document.addEventListener("pointerdown",this._onDocPointer,!0)}handleInput(){const t=window.getSelection();if(!t||!t.isCollapsed||!t.rangeCount)return this.close();const e=t.getRangeAt(0),i=e.startContainer;if(i.nodeType!==Node.TEXT_NODE)return this.close();const o=i.textContent.slice(0,e.startOffset).match(/(?:^|\s)\/([^\s/]*)$/);if(!o)return this.close();this.query=o[1],this.slashNode=i,this.slashStart=e.startOffset-this.query.length-1;const n=this.query.toLowerCase();if(this.filtered=this.commands.filter(t=>t.label.toLowerCase().includes(n)||t.id.toLowerCase().includes(n)||(t.hint||"").toLowerCase().includes(n)),!this.filtered.length)return this.close();this.activeIndex=0,this.render(),this.open(e)}open(t){this.isOpen=!0,this.menu.style.display="block";const e=t.getBoundingClientRect(),i=e.left||(t.startContainer.parentElement||this.editor.editor).getBoundingClientRect().left,o=e.bottom||e.top;this.menu.style.left=`${Math.round(i+window.scrollX)}px`,this.menu.style.top=`${Math.round(o+window.scrollY+6)}px`;const n=this.menu.offsetHeight;e.bottom+n+8>window.innerHeight&&(this.menu.style.top=`${Math.round(e.top+window.scrollY-n-6)}px`)}close(){this.isOpen&&(this.isOpen=!1,this.menu.style.display="none")}move(t){this.activeIndex=(this.activeIndex+t+this.filtered.length)%this.filtered.length,this.render()}render(){this.menu.innerHTML="",this.filtered.forEach((t,e)=>{const i=document.createElement("button");i.type="button",i.className="yjd-slash-item"+(e===this.activeIndex?" active":""),i.setAttribute("role","option"),i.setAttribute("aria-selected",e===this.activeIndex?"true":"false");const o=document.createElement("span");o.className="yjd-slash-icon",o.innerHTML=F.getIcon(t.icon)||"";const n=document.createElement("span");n.className="yjd-slash-text",n.innerHTML=`<span class="yjd-slash-label">${t.label}</span><span class="yjd-slash-hint">${t.hint}</span>`,i.append(o,n),i.addEventListener("pointerdown",t=>{t.preventDefault(),this.choose(e)}),this.menu.appendChild(i)})}choose(t){const e=this.filtered[t];if(!e)return this.close();try{const t=this.slashNode,e=window.getSelection(),i=document.createRange();i.setStart(t,this.slashStart),i.setEnd(t,this.slashStart+this.query.length+1),i.deleteContents();const o=document.createRange();o.setStart(t,this.slashStart),o.collapse(!0),e.removeAllRanges(),e.addRange(o)}catch(t){}this.close(),this.editor.focus(),e.run(this.editor)}destroy(){this.editor.editor.removeEventListener("input",this._onInput),this.editor.editor.removeEventListener("keydown",this._onKeydown,!0),document.removeEventListener("pointerdown",this._onDocPointer,!0),this.menu&&this.menu.parentNode&&this.menu.parentNode.removeChild(this.menu),super.destroy()}}class Rt extends e{constructor(t,e={}){super(t,e),this.isOpen=!1,this.activeIndex=0,this.items=[],this.sources=this._buildSources(),this.buildMenu(),this.bindEvents()}_buildSources(){const t=this.editor.options.mention||this.options||{},e={},i=t.renderItem;return"function"==typeof t.source&&(e[t.trigger||"@"]={source:t.source,renderItem:t.renderItem||i}),(t.triggers||[]).forEach(t=>{t&&t.char&&"function"==typeof t.source&&(e[t.char]={source:t.source,renderItem:t.renderItem||i})}),e}get enabled(){return Object.keys(this.sources).length>0}buildMenu(){const t=document.createElement("div");t.className="yjd-mention-menu",t.setAttribute("role","listbox"),t.style.display="none",this.menu=t,document.body.appendChild(t)}bindEvents(){this.enabled&&(this._onInput=()=>this.handleInput(),this.editor.editor.addEventListener("input",this._onInput),this._onKeydown=t=>{this.isOpen&&("ArrowDown"===t.key?(t.preventDefault(),this.move(1)):"ArrowUp"===t.key?(t.preventDefault(),this.move(-1)):"Enter"===t.key||"Tab"===t.key?(t.preventDefault(),this.choose(this.activeIndex)):"Escape"===t.key&&(t.preventDefault(),this.close()))},this.editor.editor.addEventListener("keydown",this._onKeydown,!0),this._onDocPointer=t=>{this.isOpen&&!this.menu.contains(t.target)&&this.close()},document.addEventListener("pointerdown",this._onDocPointer,!0))}handleInput(){const t=window.getSelection();if(!t||!t.isCollapsed||!t.rangeCount)return this.close();const e=t.getRangeAt(0),i=e.startContainer;if(i.nodeType!==Node.TEXT_NODE)return this.close();const o=Object.keys(this.sources).map(t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join(""),n=i.textContent.slice(0,e.startOffset).match(new RegExp(`(?:^|\\s)([${o}])([^\\s${o}]*)$`));if(!n)return this.close();this.char=n[1],this.query=n[2],this.node=i,this.start=e.startOffset-this.query.length-1,this._loadFor(e)}_loadFor(t){const e=this.sources[this.char];if(!e)return this.close();clearTimeout(this._t);const i=this.query,o=this.char;this._t=setTimeout(()=>{Promise.resolve(e.source(i)).then(n=>{if(this.char===o&&this.query===i){if(this.items=Array.isArray(n)?n:[],!this.items.length)return this.close();this.activeIndex=0,this.render(e.renderItem),this.open(t)}}).catch(()=>this.close())},120)}open(t){this.isOpen=!0,this.menu.style.display="block";const e=t.getBoundingClientRect(),i=e.left||(t.startContainer.parentElement||this.editor.editor).getBoundingClientRect().left,o=e.bottom||e.top;this.menu.style.left=`${Math.round(i+window.scrollX)}px`,this.menu.style.top=`${Math.round(o+window.scrollY+6)}px`;const n=this.menu.offsetHeight;e.bottom+n+8>window.innerHeight&&(this.menu.style.top=`${Math.round(e.top+window.scrollY-n-6)}px`)}close(){this.isOpen&&(this.isOpen=!1,this.menu.style.display="none")}move(t){this.activeIndex=(this.activeIndex+t+this.items.length)%this.items.length,[...this.menu.children].forEach((t,e)=>{t.classList.toggle("active",e===this.activeIndex),t.setAttribute("aria-selected",e===this.activeIndex?"true":"false")})}render(t){this.menu.innerHTML="",this.items.forEach((e,i)=>{const o=document.createElement("button");o.type="button",o.className="yjd-mention-item"+(i===this.activeIndex?" active":""),o.setAttribute("role","option"),o.setAttribute("aria-selected",i===this.activeIndex?"true":"false");const n=e.name||e.label||e.id||"";o.innerHTML="function"==typeof t?t(e):`${e.avatar_url?`<img class="yjd-mention-avatar" src="${e.avatar_url}" alt="">`:""}<span class="yjd-mention-name">${this.char}${n}</span>`,o.addEventListener("pointerdown",t=>{t.preventDefault(),this.choose(i)}),this.menu.appendChild(o)})}choose(t){const e=this.items[t];if(!e)return this.close();const i=e.name||e.label||e.id||"";try{const t=this.node,o=window.getSelection(),n=document.createRange();n.setStart(t,this.start),n.setEnd(t,this.start+this.query.length+1),n.deleteContents();const r=document.createElement("span");r.className="mention",r.setAttribute("data-id",String(null!=e.id?e.id:"")),r.setAttribute("data-trigger",this.char),r.setAttribute("contenteditable","false"),r.textContent=this.char+i,n.insertNode(r);const s=document.createTextNode(" ");r.after(s);const a=document.createRange();a.setStart(s,1),a.collapse(!0),o.removeAllRanges(),o.addRange(a)}catch(t){}this.close(),this.editor.focus(),"function"==typeof this.editor.onContentChange&&this.editor.onContentChange(),this.editor.emit("mention:select",e)}destroy(){this._onInput&&this.editor.editor.removeEventListener("input",this._onInput),this._onKeydown&&this.editor.editor.removeEventListener("keydown",this._onKeydown,!0),this._onDocPointer&&document.removeEventListener("pointerdown",this._onDocPointer,!0),this.menu&&this.menu.parentNode&&this.menu.parentNode.removeChild(this.menu),super.destroy()}}class Ht extends e{static DEFAULTS={minWidth:50,minHeight:50,maxWidth:800,maxHeight:600,maintainAspectRatio:!0,snapToGrid:!1,gridSize:10};constructor(t,e={}){super(t,e),this.activeElement=null,this.handles=[],this.isResizing=!1,this.startX=0,this.startY=0,this.startWidth=0,this.startHeight=0,this.currentHandle=null,this.aspectRatio=1,this.init()}init(){this.createHandles(),this.setupEventListeners()}createHandles(){this.handlesContainer=document.createElement("div"),this.handlesContainer.className="resize-handles-container",this.handlesContainer.style.position="absolute",this.handlesContainer.style.pointerEvents="none",this.handlesContainer.style.zIndex="997",this.handlesContainer.style.display="none";[{name:"nw",cursor:"nw-resize",position:{top:-4,left:-4}},{name:"ne",cursor:"ne-resize",position:{top:-4,right:-4}},{name:"sw",cursor:"sw-resize",position:{bottom:-4,left:-4}},{name:"se",cursor:"se-resize",position:{bottom:-4,right:-4}}].forEach(t=>{const e=this.createHandle(t);this.handles.push(e),this.handlesContainer.appendChild(e)}),this.editor.wrapper.appendChild(this.handlesContainer)}createHandle(t){const e=document.createElement("div");return e.className=`resize-handle resize-handle-${t.name}`,e.style.position="absolute",e.style.width="8px",e.style.height="8px",e.style.backgroundColor="#3b82f6",e.style.border="1px solid #fff",e.style.borderRadius="50%",e.style.cursor=t.cursor,e.style.pointerEvents="auto",e.style.boxShadow="0 2px 4px rgba(0,0,0,0.2)",e.style.zIndex="999",e.dataset.handle=t.name,Object.entries(t.position).forEach(([t,i])=>{e.style[t]=i+"px"}),e.addEventListener("mousedown",e=>this.handleMouseDown(e,t.name)),e}setupEventListeners(){this._onEditorClick=t=>this.handleElementClick(t),this._onDocClick=t=>{this.isClickOnResizableElement(t)||this.isClickOnHandle(t)||this.hideHandles()},this._onDocMousemove=t=>this.handleMouseMove(t),this._onDocMouseup=t=>this.handleMouseUp(t),this._onWindowScroll=()=>{this.activeElement&&this.updateHandlePosition()},this._onEditorScroll=()=>{this.activeElement&&this.updateHandlePosition()},this.editor.editor.addEventListener("click",this._onEditorClick),document.addEventListener("click",this._onDocClick),document.addEventListener("mousemove",this._onDocMousemove),document.addEventListener("mouseup",this._onDocMouseup),window.addEventListener("scroll",this._onWindowScroll),this.editor.editor.addEventListener("scroll",this._onEditorScroll),this.setupMutationObserver()}handleElementClick(t){const e=t.target;let i=this.findResizableElement(e);i&&(t.preventDefault(),t.stopPropagation(),this.showHandles(i))}findResizableElement(t){if(this.isResizableElement(t))return t;if("TD"===t.tagName||"TH"===t.tagName||"TR"===t.tagName||"TBODY"===t.tagName){let e=t.parentElement;for(;e&&"TABLE"!==e.tagName;)e=e.parentElement;if(e&&this.isResizableElement(e))return e}let e=t.parentElement;for(;e&&e!==this.editor.wrapper;){if(this.isResizableElement(e))return e;e=e.parentElement}return null}isResizableElement(t){const e=t.classList.contains("inserted-image"),i=t.classList.contains("inserted-video"),o=t.classList.contains("rich-editor-table");return e||i||o}isClickOnResizableElement(t){return this.isResizableElement(t.target)}isClickOnHandle(t){return t.target.classList.contains("resize-handle")}showHandles(t){this.activeElement=t,this.updateHandlePosition(),this.handlesContainer.style.display="block",(t.classList.contains("inserted-image")||t.classList.contains("inserted-video"))&&(this.aspectRatio=t.offsetWidth/t.offsetHeight),t.classList.contains("rich-editor-table")&&(t.style.position="relative",t.style.display="table",this.lastTableWidth=t.offsetWidth,this.lastTableHeight=t.offsetHeight,this.setupTableSizeMonitoring(t))}hideHandles(){this.tableSizeInterval&&(clearInterval(this.tableSizeInterval),this.tableSizeInterval=null),this.activeElement=null,this.handlesContainer.style.display="none"}updateHandlePosition(){if(!this.activeElement)return;if(!document.body.contains(this.activeElement))return void this.hideHandles();const t=this.activeElement.getBoundingClientRect(),e=this.editor.wrapper.getBoundingClientRect(),i=this.editor.wrapper.scrollTop||0,o=this.editor.wrapper.scrollLeft||0,n=t.top-e.top+i,r=t.left-e.left+o,s=t.width,a=t.height,l=n+a;this.handlesContainer.style.top=n+"px",this.handlesContainer.style.left=r+"px",this.handlesContainer.style.width=s+"px",this.handlesContainer.style.height=a+"px",(l<0||n>e.height)&&this.hideHandles()}handleMouseDown(t,e){t.preventDefault(),t.stopPropagation(),this.isResizing=!0,this.currentHandle=e,this.startX=t.clientX,this.startY=t.clientY,this.startWidth=this.activeElement.offsetWidth,this.startHeight=this.activeElement.offsetHeight;const i=this.activeElement.getBoundingClientRect();this.startLeft=i.left,this.startTop=i.top,this.activeElement.classList.add("resizing"),document.body.style.cursor=t.target.style.cursor,document.body.style.userSelect="none"}handleMouseMove(t){if(!this.isResizing||!this.activeElement)return;const e=t.clientX-this.startX,i=t.clientY-this.startY;let o=this.startWidth,n=this.startHeight;switch(this.currentHandle){case"nw":o=this.startWidth-e,n=this.startHeight-i;break;case"ne":o=this.startWidth+e,n=this.startHeight-i;break;case"sw":o=this.startWidth-e,n=this.startHeight+i;break;case"se":o=this.startWidth+e,n=this.startHeight+i}let r=this.options.maxWidth;const s=this.editor&&this.editor.editor;if(s){const t=getComputedStyle(s),e=s.clientWidth-(parseFloat(t.paddingLeft)||0)-(parseFloat(t.paddingRight)||0);e>0&&(r=Math.min(r,e))}if(o=Math.max(this.options.minWidth,Math.min(r,o)),n=Math.max(this.options.minHeight,Math.min(this.options.maxHeight,n)),(this.activeElement.classList.contains("inserted-image")||this.activeElement.classList.contains("inserted-video"))&&this.options.maintainAspectRatio){const t=o/this.aspectRatio,e=n*this.aspectRatio;Math.abs(o-e)<Math.abs(n-t)?o=e:n=t,o>r&&(o=r,n=o/this.aspectRatio)}this.options.snapToGrid&&(o=Math.round(o/this.options.gridSize)*this.options.gridSize,n=Math.round(n/this.options.gridSize)*this.options.gridSize),this.applyDimensions(o,n),this.updateHandlePosition(),this.emit("element-resize",{element:this.activeElement,width:o,height:n,handle:this.currentHandle})}handleMouseUp(t){this.isResizing&&(this.isResizing=!1,this.currentHandle=null,this.activeElement&&this.activeElement.classList.remove("resizing"),document.body.style.cursor="",document.body.style.userSelect="",this.emit("element-resize-complete",{element:this.activeElement,width:this.activeElement.offsetWidth,height:this.activeElement.offsetHeight}))}applyDimensions(t,e){if(this.activeElement)if(this.activeElement.classList.contains("rich-editor-table")){this.activeElement.style.width=t+"px",this.activeElement.style.minWidth=t+"px",this.activeElement.style.height=e+"px",this.activeElement.style.minHeight=e+"px";const i=this.activeElement.querySelectorAll("tr"),o=i.length>0?i[0].querySelectorAll("td, th").length:0;if(i.length>0&&o>0){const n=Math.floor(t/o),r=Math.floor(e/i.length);this.activeElement.querySelectorAll("td, th").forEach(t=>{t.style.minWidth=n+"px",t.style.minHeight=r+"px",t.style.height=r+"px"})}}else this.activeElement.style.width=t+"px",this.activeElement.style.height=e+"px","IFRAME"===this.activeElement.tagName&&(this.activeElement.width=t,this.activeElement.height=e)}getActiveElement(){return this.activeElement}setActiveElement(t){this.isResizableElement(t)&&this.showHandles(t)}checkAndUpdateHandles(){if(this.activeElement){if(!document.body.contains(this.activeElement)||!this.isResizableElement(this.activeElement))return void this.hideHandles();this.updateHandlePosition(),this.activeElement.classList.contains("rich-editor-table")&&this.checkTableSizeChange()}}refreshHandles(){this.activeElement&&document.body.contains(this.activeElement)&&this.updateHandlePosition()}setupTableSizeMonitoring(t){this.tableSizeInterval&&clearInterval(this.tableSizeInterval),this.tableSizeInterval=setInterval(()=>{this.activeElement&&this.activeElement.classList.contains("rich-editor-table")?this.checkTableSizeChange():(clearInterval(this.tableSizeInterval),this.tableSizeInterval=null)},100)}checkTableSizeChange(){if(!this.activeElement||!this.activeElement.classList.contains("rich-editor-table"))return;const t=this.activeElement.offsetWidth,e=this.activeElement.offsetHeight;(Math.abs(t-this.lastTableWidth)>1||Math.abs(e-this.lastTableHeight)>1)&&(this.lastTableWidth=t,this.lastTableHeight=e,this.updateHandlePosition(),this.emit("table-size-changed",{element:this.activeElement,width:t,height:e,previousWidth:this.lastTableWidth,previousHeight:this.lastTableHeight}))}setupMutationObserver(){"undefined"!=typeof MutationObserver&&(this.mutationObserver=new MutationObserver(t=>{let e=!1;t.forEach(t=>{if(this.activeElement){if("childList"===t.type){if(t.removedNodes)for(let i of t.removedNodes)if(i===this.activeElement||i.contains(this.activeElement)){e=!0;break}(t.target===this.activeElement||t.target.nodeType===Node.ELEMENT_NODE&&this.activeElement.contains(t.target))&&(e=!0)}if("characterData"===t.type&&this.activeElement.classList.contains("rich-editor-table")){let i=t.target;for(;i&&i!==this.activeElement;)i=i.parentNode;i===this.activeElement&&(e=!0)}if("attributes"===t.type&&this.activeElement.classList.contains("rich-editor-table")){const i=t.attributeName;"style"!==i&&"class"!==i||(e=!0)}}}),e&&setTimeout(()=>{this.checkAndUpdateHandles()},0)}),this.mutationObserver.observe(this.editor.editor,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style","class"],characterData:!0,characterDataOldValue:!0}))}setMaintainAspectRatio(t){this.options.maintainAspectRatio=t}setConstraints(t,e,i,o){this.options.minWidth=t||this.options.minWidth,this.options.minHeight=e||this.options.minHeight,this.options.maxWidth=i||this.options.maxWidth,this.options.maxHeight=o||this.options.maxHeight}destroy(){this.hideHandles(),this._onDocClick&&(this.editor.editor.removeEventListener("click",this._onEditorClick),document.removeEventListener("click",this._onDocClick),document.removeEventListener("mousemove",this._onDocMousemove),document.removeEventListener("mouseup",this._onDocMouseup),window.removeEventListener("scroll",this._onWindowScroll),this.editor.editor.removeEventListener("scroll",this._onEditorScroll),this._onEditorClick=this._onDocClick=this._onDocMousemove=null,this._onDocMouseup=this._onWindowScroll=this._onEditorScroll=null),this.handlesContainer&&this.handlesContainer.remove(),this.tableSizeInterval&&(clearInterval(this.tableSizeInterval),this.tableSizeInterval=null),this.mutationObserver&&(this.mutationObserver.disconnect(),this.mutationObserver=null),super.destroy()}}class zt{constructor(t={}){this.options={onImageInsert:null,editor:null,...t},this.popup=null,this.isVisible=!1,this.clickOutsideHandler=null,this.selectedImageSrc=null,this.savedSelection=null,this.resizeHandler=null,this.createImagePopup()}createImagePopup(){this.popup=document.createElement("div"),this.popup.className="image-popup";const t=document.createElement("div");t.className="image-popup-content";const e=document.createElement("h3");e.textContent="Insert image",e.className="yjd-input-title",t.appendChild(e);const i=document.createElement("div");i.className="image-input-container";const o=document.createElement("p");o.textContent="Your image url",o.className="yjd-input-label";const n=document.createElement("div");n.className="yjd-input-upload-group",this.inputGroup=n,this.urlInput=document.createElement("input"),this.urlInput.type="url",this.urlInput.className="yjd-input",this.urlInput.placeholder="Please enter your image URL",this.fileInput=document.createElement("input"),this.fileInput.type="file",this.fileInput.accept="image/*",this.fileInput.className="image-input-hidden",this.fileInput.addEventListener("change",t=>this.handleFileSelect(t));const r=document.createElement("button");r.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" x2="12" y1="3" y2="15"/></svg>',r.className="yjd-custom-upload-button",this.customButton=r,r.addEventListener("click",()=>this.fileInput.click()),this.createPreviewContainer(),n.appendChild(this.urlInput),n.appendChild(this.fileInput),n.appendChild(r),i.appendChild(o),i.appendChild(n),i.appendChild(this.previewContainer),t.appendChild(i),this.urlInput.addEventListener("input",()=>{this.updateInsertButton();const t=this.urlInput.value.trim();t&&this.isValidImageUrl(t)?this.showPreview(t):this.removePreview(),this.urlInput.value.trim()?this.customButton.style.display="none":this.customButton.style.display="flex"});const s=document.createElement("div");s.className="yjd-button-container";const a=document.createElement("button");a.type="button",a.className="image-button yjd-button-cancel",a.textContent="Cancel",a.addEventListener("click",()=>{this.hide(),this.options.editor&&setTimeout(()=>this.options.editor.focus(),0)}),this.insertButton=document.createElement("button"),this.insertButton.type="button",this.insertButton.className="image-button yjd-button-confirm button-disable",this.insertButton.textContent="Add image",this.insertButton.disabled=!0,this.insertButton.addEventListener("click",()=>{this.insertImage(),this.options.editor&&setTimeout(()=>this.options.editor.focus(),0)}),s.appendChild(a),s.appendChild(this.insertButton),t.appendChild(s),this.popup.appendChild(t),U(this.popup),this.options.editor&&"function"==typeof this.options.editor.preventFocusLoss&&this.options.editor.preventFocusLoss(this.popup)}async handleFileSelect(t){const e=t.target.files[0];if(e)try{const{default:t}=await Promise.resolve().then(function(){return ft});this.selectedImageSrc=await t.handleFileUpload(e),this.urlInput.value="",this.showPreview(this.selectedImageSrc),this.updateInsertButton()}catch(t){alert(t.message)}}updateInsertButton(){const t=this.selectedImageSrc||this.urlInput.value.trim();this.insertButton.disabled=!t,this.insertButton.classList.toggle("button-disable",!t)}showPreview(t){t&&(this.imagePreview.src=t,this.previewContainer.style.display="block",this.selectedImageSrc=t,this.toggleInputGroup(!1),this.recalculatePosition())}removePreview(){this.selectedImageSrc=null,this.previewContainer.style.display="none",this.imagePreview.src="",this.toggleInputGroup(!0),this.fileInput&&(this.fileInput.value=""),this.updateInsertButton(),this.recalculatePosition()}toggleInputGroup(t){this.inputGroup&&(t?(this.inputGroup.style.display="flex",this.inputGroup.style.visibility="visible",this.customButton&&(this.customButton.style.pointerEvents="auto")):(this.inputGroup.style.display="none",this.inputGroup.style.visibility="hidden"))}createPreviewContainer(){this.previewContainer=document.createElement("div"),this.previewContainer.className="image-preview-container",this.previewContainer.style.cssText="display: none; position: relative;",this.imagePreview=document.createElement("img"),this.imagePreview.className="image-preview",this.imagePreview.style.cssText="max-width: 100%; max-height: 200px; border-radius: 8px; object-fit: contain;",this.removeButton=document.createElement("button"),this.removeButton.className="image-remove-button",this.removeButton.innerHTML="×",this.removeButton.style.cssText="\n position: absolute; top: 5px; right: 5px; background: rgba(0,0,0,0.7);\n color: white; border: none; border-radius: 50%; width: 24px; height: 24px;\n cursor: pointer; font-size: 16px; font-weight: bold;\n ",this.removeButton.addEventListener("click",()=>this.removePreview()),this.previewContainer.appendChild(this.imagePreview),this.previewContainer.appendChild(this.removeButton)}isValidImageUrl(t){try{const e=new URL(t),i=[".jpg",".jpeg",".png",".gif",".webp",".svg",".bmp"],o=["imgur.com","images.unsplash.com","picsum.photos","via.placeholder.com"],n=e.pathname.toLowerCase(),r=i.some(t=>n.endsWith(t)),s=o.some(t=>e.hostname.includes(t));return r||s}catch{return!1}}async insertImage(){let t=this.selectedImageSrc||this.urlInput.value.trim();if(t){try{const{default:e}=await Promise.resolve().then(function(){return ft});if(!await e.validateImageUrl(t))return void alert("Invalid image URL. Please check the URL and try again.")}catch(t){return void alert("Error validating image URL.")}this.restoreSelection(),this.options.onImageInsert&&this.options.onImageInsert(t,""),this.hide(),this.reset()}}reset(){this.fileInput.value="",this.urlInput.value="",this.selectedImageSrc=null,this.previewContainer.style.display="none",this.imagePreview.src="",this.toggleInputGroup(!0),this.updateInsertButton(),this.customButton.style.display="block"}saveSelection(){const t=window.getSelection();t&&t.rangeCount>0&&(this.savedSelection=t.getRangeAt(0).cloneRange())}restoreSelection(){if(this.savedSelection){const t=window.getSelection();t.removeAllRanges(),t.addRange(this.savedSelection)}}setupClickOutside(){this.clickOutsideHandler&&document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=t=>{this.popup.contains(t.target)||this.hide()},setTimeout(()=>{document.addEventListener("click",this.clickOutsideHandler)},100)}setupResizeHandler(){this.resizeHandler&&window.removeEventListener("resize",this.resizeHandler),this.resizeHandler=()=>{this.isVisible&&this.recalculatePosition()},window.addEventListener("resize",this.resizeHandler)}removeResizeHandler(){this.resizeHandler&&(window.removeEventListener("resize",this.resizeHandler),this.resizeHandler=null)}removeClickOutside(){this.clickOutsideHandler&&(document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=null)}show(t){if(!t)return;this.saveSelection(),this.reset(),this.currentAnchor=t;const e=W(t,this.popup,{offsetY:5,offsetX:0});$(this.popup,e),this.popup.classList.add("visible"),this.isVisible=!0,this.setupClickOutside()}recalculatePosition(){this.currentAnchor&&this.isVisible&&setTimeout(()=>{const t=W(this.currentAnchor,this.popup,{offsetY:5,offsetX:0});$(this.popup,t)},10)}hide(){this.popup.classList.remove("visible"),this.isVisible=!1,this.removeClickOutside(),this.savedSelection=null}destroy(){this.removeClickOutside(),this.popup&&this.popup.parentNode&&this.popup.parentNode.removeChild(this.popup),this.popup=null,this.isVisible=!1}}t.register("formats/bold",R,!0),t.register("formats/italic",H,!0),t.register("formats/underline",z,!0),t.register("formats/strike",M,!0),t.register("formats/subscript",O,!0),t.register("formats/superscript",P,!0),t.register("formats/color",K,!0),t.register("formats/background",G,!0),t.register("formats/link",Q,!0),t.register("formats/table",J,!0),t.register("formats/heading",et,!0),t.register("formats/font-family",it,!0),t.register("formats/line-height",ot,!0),t.register("formats/capitalization",nt,!0),t.register("formats/text-align",st,!0),t.register("formats/list",ct,!0),t.register("formats/indent",dt,!0),t.register("formats/indent-increase",ht,!0),t.register("formats/indent-decrease",pt,!0),t.register("formats/emoji",mt,!0),t.register("formats/image",gt,!0),t.register("formats/video",bt,!0),t.register("formats/tag",Ct,!0),t.register("formats/text-size",wt,!0),t.register("formats/import",kt,!0),t.register("modules/toolbar",Tt,!0),t.register("modules/history",It,!0),t.register("modules/block-toolbar",St,!0),t.register("modules/table-toolbar",Nt,!0),t.register("modules/code-view",Lt,!0),t.register("modules/find-replace",At,!0),t.register("modules/slash-menu",Bt,!0),t.register("modules/mention",Rt,!0),t.register("modules/resize-handles",Ht,!0),t.register("ui/color-picker",X,!0),t.register("ui/text-align-picker",rt,!0),t.register("ui/list-picker",lt,!0),t.register("ui/emoji-picker",ut,!0),t.register("ui/image-popup",zt,!0),t.register("ui/video-popup",yt,!0),t.register("ui/tag-popup",xt,!0),t.register("ui/custom-button",jt,!0),class{static loaded=!1;static styleElement=null;static loadStyles(){if(this.loaded)return Promise.resolve();try{this.styleElement=document.createElement("style"),this.styleElement.id="rich-editor-styles",this.styleElement.textContent='@keyframes rte-pop-in{0%{opacity:0;transform:translateY(-2px)}to{opacity:1;transform:none}}@keyframes yjd-slash-in{0%{opacity:0;transform:translateY(-2px)}to{opacity:1;transform:none}}.yjd-rich-editor,.yjd-rich-editor .rich-editor-area{background:#fff;position:relative;box-sizing:border-box}.yjd-rich-editor{border:1px solid #d1d5db;border-radius:8px;overflow:hidden;margin:0 auto;display:flex;flex-direction:column}@layer base{.yjd-rich-editor .toolbar-container ::file-selector-button,.yjd-rich-editor .toolbar-container button,.yjd-rich-editor .toolbar-container input,.yjd-rich-editor .toolbar-container optgroup,.yjd-rich-editor .toolbar-container select,.yjd-rich-editor .toolbar-container textarea{font:500 14px/1.4"Inter",Arial,sans-serif!important;letter-spacing:normal!important;font-feature-settings:normal!important;font-variation-settings:normal!important}.yjd-rich-editor .emoji-picker-popup .emoji-button,.yjd-rich-editor .emoji-picker-popup button.emoji-button{font-size:20px!important}}@layer base{.yjd-rich-editor .rich-editor-popup-container ::file-selector-button,.yjd-rich-editor .rich-editor-popup-container button,.yjd-rich-editor .rich-editor-popup-container input,.yjd-rich-editor .rich-editor-popup-container optgroup,.yjd-rich-editor .rich-editor-popup-container select,.yjd-rich-editor .rich-editor-popup-container textarea{font:500 14px/1.4"Inter",Arial,sans-serif!important;letter-spacing:normal!important;font-feature-settings:normal!important;font-variation-settings:normal!important}.yjd-rich-editor .emoji-picker-popup .emoji-button,.yjd-rich-editor .emoji-picker-popup button.emoji-button{font-size:20px!important}}.yjd-rich-editor .rich-editor-area{flex:1 1 auto;min-height:40px;outline:0;overflow-y:auto;border:0;text-align:left;font-family:inherit;color:#2c3e50}.yjd-rich-editor .rich-editor-area[data-placeholder]:before{content:attr(data-placeholder);color:#9ca3af;pointer-events:none;position:absolute;top:0;left:0;right:0;padding:inherit;box-sizing:border-box;font:inherit;font-style:italic;line-height:inherit;display:none;z-index:1}.yjd-rich-editor .custom-select-item-button.current .item-checkmark,.yjd-rich-editor .rich-editor-area div,.yjd-rich-editor .rich-editor-area[data-placeholder].placeholder-visible:before{display:block}.yjd-rich-editor .rich-editor-area b,.yjd-rich-editor .rich-editor-area strong{font-weight:700}.yjd-rich-editor .rich-editor-area em,.yjd-rich-editor .rich-editor-area i{font-style:italic}.yjd-rich-editor .rich-editor-area u{text-decoration:underline}.yjd-rich-editor .rich-editor-area a{color:#2563eb;text-decoration:underline;cursor:pointer;color:var(--rte-accent-ink);text-decoration-color:var(--rte-accent-ring);text-underline-offset:2px}.yjd-content p,.yjd-rich-editor .rich-editor-area p{margin:0 0 1em}.yjd-content h1,.yjd-rich-editor .rich-editor-area h1{font-size:2em;font-weight:700;margin:.67em 0}.yjd-content h2,.yjd-rich-editor .rich-editor-area h2{font-size:1.5em;font-weight:700;margin:.75em 0}.yjd-content h3,.yjd-rich-editor .rich-editor-area h3{font-size:1.25em;font-weight:700;margin:.83em 0}.yjd-content h4,.yjd-rich-editor .rich-editor-area h4{font-size:1.1em;font-weight:700;margin:1em 0}.yjd-content h5,.yjd-rich-editor .rich-editor-area h5{font-size:1em;font-weight:700;margin:1.25em 0}.yjd-content h6,.yjd-rich-editor .rich-editor-area h6{font-size:.875em;font-weight:700;margin:1.5em 0;color:#555}.yjd-content ol,.yjd-content ul{margin:0 0 1em 2em;padding:0}.yjd-rich-editor .rich-editor-area ol,.yjd-rich-editor .rich-editor-area ul{padding:0}.yjd-rich-editor .rich-editor-area li{margin:.25em 0 4px;line-height:1.6}.yjd-rich-editor .rich-editor-area code,.yjd-rich-editor .rich-editor-area pre{font-family:Consolas,Menlo,Monaco,"Courier New",monospace;background:#f1f2f3;overflow-x:auto}.yjd-rich-editor .rich-editor-area pre{border-radius:4px;display:block;margin:1em 0;background-color:#f1f2f3;width:96%;white-space:pre;word-wrap:normal;background:#20242f;color:#ececf5;border-radius:var(--rte-radius-md);padding:14px 16px;border:0}.yjd-rich-editor .rich-editor-area code{display:inline;background:var(--rte-chrome-2);border-radius:6px;padding:2px 6px;font-size:.9em}.yjd-content blockquote{margin:1em 0;padding:4px 12px}.yjd-content blockquote,.yjd-rich-editor .rich-editor-area blockquote{border-left:4px solid #d1d5db;color:#555;font-style:italic;background:#f9fafb}.yjd-rich-editor .rich-editor-area sub{font-size:.75em;vertical-align:sub;line-height:1}.yjd-rich-editor .rich-editor-area sup{font-size:.75em;vertical-align:super;line-height:1}.yjd-rich-editor .rich-editor-area:empty::before{content:"";display:block}.yjd-rich-editor .rich-editor-statusbar{position:relative;z-index:1000;border-top:1px solid #d1d5db;background:#f9fafb;font-size:13px;color:#6b7280;font-family:inherit;min-height:32px;box-sizing:border-box}.yjd-rich-editor .rich-editor-toolbar-container{border-bottom:1px solid #d1d5db;position:relative;z-index:1000}.yjd-rich-editor .rich-editor-toolbar-1,.yjd-rich-editor .rich-editor-toolbar-2{gap:20px;background:#fcfcfc;min-height:48px;box-sizing:border-box;width:100%;z-index:1000;position:relative}.yjd-rich-editor .rich-editor-toolbar-2{display:none;overflow:hidden}.yjd-rich-editor .rich-editor-toolbar-2.visible{display:flex}.yjd-rich-editor .rich-editor-toolbar-btn{width:22px;border-radius:4px;font-size:14px;font-weight:500}.yjd-rich-editor .custom-select-button span{justify-content:left!important}.yjd-rich-editor .custom-select-button:focus{outline:0;border-color:#3b82f6;box-shadow:0 0 0 1px rgba(59,130,246,.1)}.yjd-rich-editor .rich-editor-toolbar-btn span{display:flex!important;align-items:center;justify-content:center}.yjd-rich-editor .rich-editor-toolbar-btn:hover{background:#eee!important;cursor:pointer}.yjd-rich-editor .block-toolbar-btn{border-radius:4px;padding:4px;cursor:pointer;font-size:14px;font-weight:500;align-items:center;justify-content:center;display:inline-flex}.yjd-rich-editor .block-toolbar-btn:hover{background:#eee}.yjd-rich-editor .block-toolbar-btn.active{background:#ccc;color:#136fdf!important}.yjd-rich-editor .block-toolbar-btn.active svg,.yjd-rich-editor .block-toolbar-btn.active svg path{fill:#136fdf!important}.yjd-rich-editor .block-toolbar-container{display:flex;align-items:center;background:#fff;border-radius:6.9px;box-shadow:0 4px 24px rgba(0,0,0,.13)}.yjd-rich-editor .block-toolbar-arrow{position:absolute;bottom:-6px;left:50%;transform:translateX(-50%);width:0;height:0;border-left:6px solid transparent;border-right:6px solid transparent;border-top:6px solid #fff;filter:drop-shadow(0 2px 4px rgba(0,0,0,.1))}.yjd-rich-editor .table-toolbar-container{display:flex;align-items:center;background:#fff;border-radius:6px;box-shadow:0 4px 24px rgba(0,0,0,.13)}.yjd-rich-editor .table-toolbar-arrow{position:absolute;bottom:-6px;left:50%;transform:translateX(-50%);width:0;height:0;border-left:6px solid transparent;border-right:6px solid transparent;border-top:6px solid #fff;filter:drop-shadow(0 2px 4px rgba(0,0,0,.1))}.yjd-rich-editor .block-toolbar{display:none;position:absolute;z-index:1001;background:0 0;border:0;border-radius:6.9px;box-sizing:border-box;padding:0;gap:0;flex-direction:column;align-items:center}.yjd-rich-editor .block-toolbar.visible{display:flex}.yjd-rich-editor .color-picker-popup{position:absolute;background:#fff;display:none;border-radius:6.9px;padding:8px;z-index:1000;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.yjd-rich-editor .capitalization-select-popup.visible,.yjd-rich-editor .color-picker-popup.visible,.yjd-rich-editor .custom-select-popup.visible,.yjd-rich-editor .font-family-select-popup.visible,.yjd-rich-editor .heading-select-popup.visible,.yjd-rich-editor .line-height-select-popup.visible,.yjd-rich-editor .text-size-select-popup.visible{display:block!important}.yjd-rich-editor .capitalization-select-popup,.yjd-rich-editor .custom-select-popup,.yjd-rich-editor .font-family-select-popup,.yjd-rich-editor .heading-select-popup,.yjd-rich-editor .line-height-select-popup,.yjd-rich-editor .text-size-select-popup{position:absolute;background:#fff;display:none;border:1px solid #d1d5db;border-radius:6.9px;z-index:1002;max-height:200px;overflow-y:auto;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.yjd-rich-editor .image-popup,.yjd-rich-editor .link-popup,.yjd-rich-editor .tag-popup,.yjd-rich-editor .video-popup{width:299px}.yjd-rich-editor .item-list{display:flex;flex-direction:column;gap:2px}.yjd-rich-editor .heading-select-popup{width:190px;max-width:100vw}.yjd-rich-editor .capitalization-select-popup{width:150px;max-width:100vw}.yjd-rich-editor .font-family-select-popup{width:190px;max-width:100vw}.yjd-rich-editor .line-height-select-popup{width:80px;max-width:100vw}.yjd-rich-editor .text-size-select-popup{width:150px;max-width:100vw}.yjd-rich-editor .custom-select-item-button{width:100%;border:0;background:0 0;border-radius:6px;cursor:pointer;text-align:left;transition:all .2s ease;font-size:14px;line-height:1.4;color:#111827;display:flex;align-items:center;justify-content:space-between;pointer-events:auto}.yjd-rich-editor .custom-select-item-button:hover{background:#eee}.yjd-rich-editor .custom-select-item-button.current{background:#eee!important}.yjd-rich-editor .custom-select-item-button .item-checkmark{display:none}.yjd-rich-editor .item-text{flex:1}.yjd-rich-editor .dropdown-icon{display:inline-flex!important;align-items:center;justify-content:center;width:16px;height:16px;flex:0 0 auto}.yjd-rich-editor .dropdown-icon svg{width:16px;height:16px;display:block;stroke:currentColor;fill:none}.yjd-rich-editor .color-grid{display:grid;grid-template-columns:repeat(6,1fr);gap:6px 4px;margin-bottom:12px}.yjd-rich-editor .color-button{width:24px;height:24px;border:0;border-radius:50%;cursor:pointer;transition:all .2s ease;padding:0;margin:0;pointer-events:auto}.yjd-rich-editor .color-button:hover{transform:scale(1.1);border-color:#374151;box-shadow:0 2px 4px rgba(0,0,0,.1)}.yjd-rich-editor .custom-color-container{position:relative;padding-top:8px;display:flex;align-items:center;gap:8px;z-index:0}.yjd-rich-editor .custom-color-container::before{content:"";position:absolute;top:0;left:-8px;width:calc(100% + 16px);height:0;border-top:1px solid #e5e7eb;z-index:-1}.yjd-rich-editor .custom-color-label{font-size:12px;color:#6b7280;margin:0}.yjd-rich-editor .yjd-input-label,.yjd-rich-editor .yjd-input-title{margin:0;color:#252424;font-size:16px;font-style:normal;line-height:normal}.yjd-rich-editor .yjd-input-label{font-size:14px;font-weight:700}.yjd-rich-editor .yjd-input-group{display:flex;flex-direction:column;gap:8px}.yjd-rich-editor .yjd-input{flex:1 1 auto;min-width:0;max-width:100%;max-height:37px;border-radius:10px;border:1px solid #e1e1e1;color:#252424!important}.yjd-rich-editor .yjd-input:focus{border-color:#3b82f6;box-shadow:0 0 0 1px rgba(59,130,246,.1)}.yjd-rich-editor .yjd-button-container{display:flex;justify-content:flex-end;gap:4px}.yjd-rich-editor .yjd-button-cancel,.yjd-rich-editor .yjd-button-confirm{border-radius:6px;align-items:center;box-shadow:0 1px 3.3px 0 rgba(0,0,0,.04);font-style:normal;line-height:normal;cursor:pointer}.yjd-rich-editor .yjd-button-confirm{background:#181616}.yjd-rich-editor .yjd-button-cancel{border:1px solid #e0e0e0;background:#fff;color:#2a2727}.yjd-rich-editor .button-disable{cursor:not-allowed}.yjd-rich-editor .link-popup{position:absolute;background:#fff;font-family:"Lato",sans-serif;display:none;border:0;border-radius:10px;z-index:1000;margin:0;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.yjd-rich-editor .link-popup.visible{display:block!important}.yjd-rich-editor .link-popup-content{display:flex;flex-direction:column;gap:16px;padding:16px}.yjd-rich-editor .yjd-input-upload-group{display:flex;align-items:center;gap:4px}.yjd-rich-editor .yjd-custom-upload-button{display:flex!important;align-items:center;justify-content:center;padding:0;border:1px solid #e1e1e1;background:#fff;width:34px;height:34px;border-radius:10px;cursor:pointer}.yjd-rich-editor .yjd-suggestions-list{display:flex;flex-wrap:wrap;gap:8px;flex:1 1 auto;min-width:0;max-width:100%}.yjd-rich-editor .yjd-suggestion-button{border:0;display:flex;padding:4px 10px;justify-content:center;align-items:center;border-radius:30px;background:#f5f5f5;cursor:pointer;font-size:14px;color:#252424!important}.yjd-rich-editor .yjd-select-input{border-radius:10px;border:1px solid #e1e1e1;max-height:37px;align-items:center;color:#252424!important}.yjd-rich-editor .yjd-select-input:focus{border-color:#3b82f6;box-shadow:0 0 0 1px rgba(59,130,246,.1)}.yjd-rich-editor .table-popup{position:absolute;background:#fff;font-family:"Lato",sans-serif;display:none;border:1px solid #d1d5db;border-radius:6.9px;z-index:1000;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.yjd-rich-editor .table-popup.visible{display:block!important}.yjd-rich-editor .table-popup-content{padding:8px;display:flex;flex-direction:column;align-items:center;gap:12px;position:relative}.yjd-rich-editor .table-popup-content>*{position:relative;width:100%}.yjd-rich-editor .table-popup-content>:not(:last-child)::after{content:"";position:absolute;bottom:-8px;left:-8px;right:-8px;height:1px;background-color:#e5e7eb}.yjd-rich-editor .table-grid-selector{display:grid;grid-template-columns:repeat(8,1fr);gap:1px;border-bottom:1px solid #eee}.yjd-rich-editor .table-size-display{display:flex;align-items:center;justify-content:center;font-family:"Lato",sans-serif;color:#252424!important;font-size:12px;font-style:normal;font-weight:400;line-height:normal}.yjd-rich-editor .table-grid-cell{width:20px;height:20px;background:#fff;border:1px solid #eee;cursor:pointer;transition:background-color .1s ease;border-radius:2px}.yjd-rich-editor .table-grid-cell.highlighted,.yjd-rich-editor .table-grid-cell:hover{background:#eee}.yjd-rich-editor .rich-editor-table{border-collapse:collapse;width:100%;max-width:100%;box-sizing:border-box;margin:16px 0;font-size:14px;line-height:1.5;position:relative;display:table;table-layout:fixed}.yjd-rich-editor .rich-editor-table td{box-sizing:border-box;border:1px solid #d1d5db;padding:8px 12px;min-height:28px;vertical-align:top;background:#fff;overflow-wrap:break-word}.yjd-rich-editor .rich-editor-table td:focus{outline-offset:-2px;background:#fefefe}.yjd-rich-editor .table-toolbar{position:absolute;display:none;z-index:1002;background:0 0;border:0;border-radius:6.9px;opacity:0;pointer-events:none}.yjd-rich-editor .table-toolbar-group{display:flex;gap:8px;align-items:center}.yjd-rich-editor .table-toolbar.visible{display:block;opacity:1;pointer-events:auto;transform:translateY(0)}.yjd-rich-editor .table-toolbar-btn{padding:4px;display:inline-flex;align-items:center;justify-content:center;border-radius:4px;font-size:12px;font-weight:500;cursor:pointer;transition:all .15s ease;white-space:nowrap}.yjd-rich-editor .table-toolbar-btn:hover{background:#f3f4f6;color:#111827}.yjd-rich-editor .table-toolbar-btn:active{background:#e5e7eb;border-color:#9ca3af;color:#136fdf!important}@media (max-width:768px){.yjd-rich-editor .table-toolbar-container{flex-wrap:wrap;max-width:200px;gap:2px}.yjd-rich-editor .table-toolbar-btn{height:24px;min-width:24px;font-size:10px;padding:2px 4px}}.yjd-rich-editor .text-align-picker-popup{position:absolute;background:#fff;display:none;border:1px solid #d1d5db;border-radius:6.9px;z-index:1000;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.yjd-rich-editor .text-align-picker-popup.visible{display:block!important}.yjd-rich-editor .align-button-container{display:flex}.yjd-rich-editor .align-button .icon-wrapper{display:flex;margin-left:8px;align-items:center;justify-content:center}.yjd-rich-editor .align-button .label-text{color:#252424;font-size:12px;font-style:normal;font-weight:400;line-height:normal}.yjd-rich-editor .align-button{border-radius:3.456px;background:#fff;border:0;align-items:center;display:flex;cursor:pointer;pointer-events:auto}.yjd-rich-editor .align-button:hover{background:#f3f4f6}.yjd-rich-editor .align-button.active{background:#e5e7eb}.yjd-rich-editor .align-button.active svg{color:#1f2937}.yjd-rich-editor .list-picker-popup{position:absolute;background:#fff;display:none;border-radius:6.9px;box-shadow:0 4px 16px rgba(0,0,0,.1);z-index:1000;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.yjd-rich-editor .list-picker-popup.visible{display:block!important}.yjd-rich-editor .list-button-container{display:grid;grid-template-columns:repeat(3,1fr)}.yjd-rich-editor .list-button{border-radius:3.46px;display:flex}.yjd-rich-editor .list-button:hover{background:#f3f4f6}.yjd-rich-editor .list-button.active{background:#eee}.yjd-rich-editor .list-button svg{color:#374151}.yjd-rich-editor .list-button.active svg{color:#fff}.yjd-rich-editor .rich-editor-area ul.checklist{list-style:none;padding-left:0}.yjd-rich-editor .rich-editor-area ul.checklist li{position:relative;padding-left:25px;margin-bottom:4px}.yjd-rich-editor .rich-editor-area ul.checklist li input[type=checkbox]{position:absolute;left:0;top:2px;margin:0;cursor:pointer}.yjd-rich-editor .rich-editor-area ol,.yjd-rich-editor .rich-editor-area ul{margin:12px 0;padding-left:20px}.yjd-rich-editor .rich-editor-area .indented,.yjd-rich-editor .rich-editor-area [style*=padding-left]{transition:padding-left .2s ease}.yjd-rich-editor .indent-decrease-btn svg,.yjd-rich-editor .indent-increase-btn svg{width:16px;height:16px;fill:#454545}.yjd-rich-editor .indent-decrease-btn:hover svg,.yjd-rich-editor .indent-increase-btn:hover svg{fill:#454545}.yjd-rich-editor .indent-decrease-btn:disabled,.yjd-rich-editor .indent-increase-btn:disabled{opacity:.5;cursor:not-allowed}.yjd-rich-editor .indent-decrease-btn:disabled svg,.yjd-rich-editor .indent-increase-btn:disabled svg{fill:#9ca3af}.yjd-rich-editor .emoji-picker-popup{position:absolute;z-index:10000;background:#fff;border-radius:8px;padding:8px;display:none;overflow-y:auto;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.yjd-rich-editor .emoji-picker-popup.visible{display:block}.yjd-rich-editor .emoji-grid{display:grid;grid-template-columns:repeat(10,1fr);gap:4px;max-height:240px;overflow-y:auto}.yjd-rich-editor .emoji-text-message{margin-top:4px;color:#71787c;text-align:center;font-family:"Segoe UI",Arial,sans-serif;font-size:12px;font-style:normal;font-weight:400;line-height:normal}.yjd-rich-editor .emoji-button{width:28px;height:28px;border:0;background:0 0;padding:0;border-radius:4px;cursor:pointer;font-size:20px!important;display:flex;align-items:center;justify-content:center;transition:background-color .2s ease;pointer-events:auto}.yjd-rich-editor .emoji-button:hover{background-color:#f3f4f6}.yjd-rich-editor .emoji{font-size:1.1em;line-height:1}.yjd-rich-editor .image-popup{position:absolute;z-index:10000;background:#fff;font-family:"Lato",sans-serif;border-radius:10px;display:none;margin:0;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.yjd-rich-editor .image-popup.visible,.yjd-rich-editor .tag-popup.visible,.yjd-rich-editor .video-popup.visible{display:block}.yjd-rich-editor .image-popup-content{display:flex;flex-direction:column;gap:16px;padding:16px}.yjd-rich-editor .image-input-container{gap:8px;display:flex;flex-direction:column}.yjd-rich-editor .image-input-hidden{display:none}.yjd-rich-editor .video-popup{position:absolute;z-index:10000;background:#fff;font-family:"Lato",sans-serif;border-radius:10px;display:none;margin:0;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.yjd-rich-editor .video-popup-content{display:flex;flex-direction:column;gap:16px;padding:16px}.yjd-rich-editor .video-input-container{gap:8px;display:flex;flex-direction:column}.yjd-rich-editor .inserted-image,.yjd-rich-editor .inserted-video{max-width:100%;height:auto;margin:4px 0;border-radius:4px;display:block}.yjd-rich-editor .inserted-video{background:#000}.yjd-rich-editor .tag-popup{position:absolute;z-index:10000;background:#fff;font-family:"Lato",sans-serif;border-radius:10px;display:none;margin:0;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.tag-popup{max-height:80vh;overflow-y:auto}.tag-suggestions-container{max-height:200px;overflow-y:auto}.yjd-rich-editor .tag-popup-content{display:flex;flex-direction:column;gap:16px;padding:16px}.yjd-rich-editor .tag-type-container{gap:8px;display:flex;flex-direction:column}.yjd-rich-editor .custom-tag{display:inline-block;padding:2px 6px;border-radius:12px;font-size:.85em;font-weight:500;cursor:pointer;margin:0 2px}.yjd-rich-editor .custom-tag.tag-mention{background:#dbeafe;color:#1d4ed8}.yjd-rich-editor .custom-tag.tag-hashtag{background:#dcfce7;color:#166534}.yjd-rich-editor .custom-tag.tag-custom{background:#fef3c7;color:#92400e}.yjd-rich-editor .custom-tag:hover{opacity:.8}.yjd-rich-editor .import-popup{position:absolute;z-index:10000;background:#fff;border:1px solid #d1d5db;border-radius:8px;display:none;width:400px;max-width:90vw;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.yjd-rich-editor .import-popup.visible{display:block}.yjd-rich-editor .import-popup-content{padding:20px}.yjd-rich-editor .import-popup-title{margin:0 0 20px;font-size:18px;font-weight:600;color:#1f2937}.yjd-rich-editor .import-type-container{margin-bottom:20px}.yjd-rich-editor .import-input-label{display:block;margin-bottom:8px;font-size:14px;font-weight:500;color:#374151}.yjd-rich-editor .import-type-select{border:1px solid #d1d5db;border-radius:6px;font-size:14px;background:#fff;color:#374151}.yjd-rich-editor .import-type-select:focus{border-color:#3b82f6;box-shadow:0 0 0 1px rgba(59,130,246,.1)}.yjd-rich-editor .import-file-input{width:100%;padding:10px 12px;border:1px solid #d1d5db;border-radius:6px;font-size:14px;background:#fff;color:#374151;margin-bottom:16px;cursor:pointer;box-sizing:border-box}.yjd-rich-editor .import-file-input:disabled{background-color:#f3f4f6;cursor:not-allowed;opacity:.5}.yjd-rich-editor .import-file-input:focus{outline:0;border-color:#3b82f6;box-shadow:0 0 0 1px rgba(59,130,246,.1)}.yjd-rich-editor .import-file-info{padding:12px;background-color:#f9fafb;border:1px solid #e5e7eb;border-radius:6px;margin-bottom:16px;font-size:14px;color:#374151}.yjd-rich-editor .import-file-info div{margin-bottom:4px}.yjd-rich-editor .import-file-info div:last-child{margin-bottom:0}.yjd-rich-editor .import-button-container{display:flex;justify-content:flex-end;gap:10px;margin-top:20px}.yjd-rich-editor .import-button{padding:10px 20px;border:1px solid #d1d5db;border-radius:6px;font-size:14px;font-weight:500;cursor:pointer;transition:all .2s}.yjd-rich-editor .import-button:hover{background-color:#f3f4f6}.yjd-rich-editor .import-button.import-button-main{background-color:#3b82f6;color:#fff;border-color:#3b82f6}.yjd-rich-editor .import-button.import-button-main:hover{background-color:#2563eb}.yjd-rich-editor .import-button.import-button-main:disabled{background-color:#9ca3af;border-color:#9ca3af;cursor:not-allowed}.yjd-rich-editor .import-button.cancel-button{background-color:#fff;color:#6b7280}.yjd-rich-editor .import-button.cancel-button:hover,.yjd-rich-editor .imported-table tr:hover{background-color:#f9fafb}.yjd-rich-editor .imported-content{margin:16px 0;padding:16px;border:1px dashed #d1d5db;border-radius:6px;background-color:#f9fafb}.yjd-rich-editor .imported-content.html-content{border-color:#3b82f6;background-color:#eff6ff}.yjd-rich-editor .imported-content.excel-content{border-color:#10b981;background-color:#f0fdf4}.yjd-rich-editor .imported-content.text-content{border-color:#f59e0b;background-color:#fffbeb}.yjd-rich-editor .imported-table{width:100%;border-collapse:collapse;font-size:14px;background:#fff;border-radius:4px;overflow:hidden;box-shadow:0 1px 3px rgba(0,0,0,.1)}.yjd-rich-editor .imported-table td,.yjd-rich-editor .imported-table th{padding:12px;text-align:left;border-bottom:1px solid #e5e7eb}.yjd-rich-editor .imported-table th{background-color:#f3f4f6;font-weight:600;color:#374151}.yjd-rich-editor .imported-content p{margin:8px 0;line-height:1.6;color:#374151}.yjd-rich-editor .imported-content p:first-child{margin-top:0}.yjd-rich-editor .imported-content p:last-child{margin-bottom:0}.yjd-rich-editor .code-view-textarea{width:100%;height:500px;font-family:"Consolas","Monaco","Courier New",monospace;font-size:14px;line-height:1.5;padding:16px;background-color:#f8fafc;color:#374151;resize:vertical;border:0;outline:0;white-space:pre;word-wrap:break-word;tab-size:2;box-sizing:border-box}@media (max-width:768px){.yjd-rich-editor .code-view-textarea{font-size:13px;padding:12px}.yjd-rich-editor.code-view-active::after{top:5px;right:5px;font-size:11px;padding:3px 6px}}.yjd-rich-editor .resize-handles-container{position:absolute;pointer-events:none;z-index:997;display:none}.yjd-rich-editor .resize-handles-container.active{display:block}.yjd-rich-editor .resize-handle{position:absolute;width:8px;height:8px;background-color:#3b82f6;pointer-events:auto;box-shadow:0 2px 4px rgba(0,0,0,.2);transition:all .2s ease;z-index:999}.yjd-rich-editor .resize-handle:hover{background-color:#2563eb;transform:scale(1.2);box-shadow:0 2px 6px rgba(0,0,0,.3)}.yjd-rich-editor .resize-handle-nw{top:-4px;left:-4px;cursor:nw-resize}.yjd-rich-editor .resize-handle-ne{top:-4px;right:-4px;cursor:ne-resize}.yjd-rich-editor .resize-handle-sw{bottom:-4px;left:-4px;cursor:sw-resize}.yjd-rich-editor .resize-handle-se{bottom:-4px;right:-4px;cursor:se-resize}.yjd-rich-editor .inserted-image.resizing,.yjd-rich-editor .inserted-video.resizing,.yjd-rich-editor .rich-editor-table.resizing{outline:2px solid #3b82f6;outline-offset:2px;opacity:.8}.yjd-rich-editor .inserted-image.resizing,.yjd-rich-editor .inserted-video.resizing{-webkit-user-select:none;user-select:none;pointer-events:none}.yjd-rich-editor .rich-editor-table.resizing{-webkit-user-select:none;user-select:none}.yjd-rich-editor .rich-editor-table.resizing td{pointer-events:none}.yjd-rich-editor .inserted-image:hover,.yjd-rich-editor .inserted-video:hover,.yjd-rich-editor .rich-editor-table:hover{outline:1px solid #3b82f6;outline-offset:1px;cursor:pointer}@media (max-width:768px){.yjd-rich-editor .resize-handle{width:12px;height:12px}.yjd-rich-editor .resize-handle-nw{top:-6px;left:-6px}.yjd-rich-editor .resize-handle-ne{top:-6px;right:-6px}.yjd-rich-editor .resize-handle-sw{bottom:-6px;left:-6px}.yjd-rich-editor .resize-handle-se{bottom:-6px;right:-6px}}@media (max-width:849px){.yjd-rich-editor{margin:0;width:100%!important;max-width:100%!important}.yjd-rich-editor .rich-editor-area{padding:12px;min-height:150px;font-size:14px;line-height:1.4}.yjd-rich-editor .rich-editor-statusbar{padding:6px 8px;font-size:11px;flex-wrap:wrap;gap:8px}.yjd-rich-editor .editor-dropdown,.yjd-rich-editor .editor-popup{position:fixed!important;top:50%!important;left:50%!important;transform:translate(-50%,-50%)!important;width:90%!important;max-width:320px!important;max-height:80vh!important;overflow-y:auto;z-index:10000}.yjd-rich-editor .editor-popup::before{content:"";position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,.5);z-index:-1}.yjd-rich-editor .color-picker{width:100%!important;max-width:280px!important}.yjd-rich-editor .color-picker-grid{grid-template-columns:repeat(6,1fr)!important;gap:8px!important}.yjd-rich-editor .color-picker-item{width:32px!important;height:32px!important}.yjd-rich-editor .table-popup{max-width:300px!important}.yjd-rich-editor .table-size-grid{grid-template-columns:repeat(8,1fr)!important;gap:2px!important}.yjd-rich-editor .table-size-cell{width:24px!important;height:24px!important}.yjd-rich-editor .list-picker{width:100%!important;max-width:250px!important}.yjd-rich-editor .list-picker-btn{padding:12px!important;font-size:14px!important}.yjd-rich-editor .text-align-picker{width:100%!important;max-width:200px!important}.yjd-rich-editor .image-popup,.yjd-rich-editor .import-popup,.yjd-rich-editor .link-popup,.yjd-rich-editor .video-popup{width:90%!important;max-width:350px!important}.yjd-rich-editor .media-upload-area{min-height:100px!important;padding:20px!important}.yjd-rich-editor .tag-popup{width:90%!important;max-width:320px!important}.yjd-rich-editor .emoji-picker{width:100%!important;max-width:300px!important;max-height:350px!important}.yjd-rich-editor .emoji-grid{grid-template-columns:repeat(8,1fr)!important;gap:4px!important}.yjd-rich-editor .emoji-item{width:32px!important;height:32px!important;font-size:18px!important}.yjd-rich-editor .code-view-textarea{font-size:12px!important;padding:8px!important;line-height:1.3!important}.yjd-rich-editor .rich-editor-area h1{font-size:1.5em!important;margin:.5em 0!important}.yjd-rich-editor .rich-editor-area h2{font-size:1.3em!important;margin:.5em 0!important}.yjd-rich-editor .rich-editor-area h3{font-size:1.1em!important;margin:.5em 0!important}.yjd-rich-editor .rich-editor-area p{margin:.8em 0!important}.yjd-rich-editor .rich-editor-area ol,.yjd-rich-editor .rich-editor-area ul{padding-left:20px!important;margin:.8em 0!important}.yjd-rich-editor .rich-editor-area blockquote{padding-left:12px!important;margin:.8em 0!important;font-size:14px!important}.yjd-rich-editor .rich-editor-area table{font-size:13px!important;overflow-x:auto!important;display:block!important;white-space:nowrap!important}.yjd-rich-editor .rich-editor-area td,.yjd-rich-editor .rich-editor-area th{padding:6px 8px!important;min-width:60px!important}}@media (max-width:290px){.yjd-rich-editor .emoji-picker{max-width:calc(100vw - 20px)!important}.yjd-rich-editor .emoji-grid{grid-template-columns:repeat(auto-fit,minmax(30px,1fr))!important}}@media print{.yjd-rich-editor .rich-editor-statusbar,.yjd-rich-editor .rich-editor-toolbar-1,.yjd-rich-editor .rich-editor-toolbar-2{display:none!important}.yjd-rich-editor{border:0!important;box-shadow:none!important}.yjd-rich-editor .rich-editor-area{padding:0!important;background:#fff!important;color:#000!important}}.yjd-rich-editor .rich-editor-popup-container{position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none;z-index:1005;overflow:visible;max-height:90%;overflow-y:auto}.yjd-rich-editor .capitalization-select-popup button,.yjd-rich-editor .color-picker-popup button,.yjd-rich-editor .custom-color-input,.yjd-rich-editor .custom-select-popup button,.yjd-rich-editor .custom-tag,.yjd-rich-editor .emoji-picker-popup button,.yjd-rich-editor .font-family-select-popup button,.yjd-rich-editor .heading-select-popup button,.yjd-rich-editor .image-input-hidden,.yjd-rich-editor .image-popup button,.yjd-rich-editor .image-popup input,.yjd-rich-editor .image-popup select,.yjd-rich-editor .import-csv-input,.yjd-rich-editor .import-file-input,.yjd-rich-editor .import-html-input,.yjd-rich-editor .import-input,.yjd-rich-editor .import-json-input,.yjd-rich-editor .import-markdown-input,.yjd-rich-editor .import-popup button,.yjd-rich-editor .import-popup input,.yjd-rich-editor .import-popup select,.yjd-rich-editor .import-text-input,.yjd-rich-editor .import-toml-input,.yjd-rich-editor .import-type-select,.yjd-rich-editor .import-url-input,.yjd-rich-editor .import-xml-input,.yjd-rich-editor .import-yaml-input,.yjd-rich-editor .line-height-select-popup button,.yjd-rich-editor .link-popup button,.yjd-rich-editor .link-popup input,.yjd-rich-editor .link-popup select,.yjd-rich-editor .list-button,.yjd-rich-editor .list-picker-popup button,.yjd-rich-editor .table-popup button,.yjd-rich-editor .table-popup input,.yjd-rich-editor .table-toolbar-btn,.yjd-rich-editor .tag-popup button,.yjd-rich-editor .tag-popup input,.yjd-rich-editor .tag-popup select,.yjd-rich-editor .tag-type-select,.yjd-rich-editor .tag-value-input,.yjd-rich-editor .text-align-picker-popup button,.yjd-rich-editor .text-size-select-popup button,.yjd-rich-editor .video-input-hidden,.yjd-rich-editor .video-popup button,.yjd-rich-editor .video-popup input,.yjd-rich-editor .video-popup select,.yjd-rich-editor .yjd-button-cancel,.yjd-rich-editor .yjd-button-confirm,.yjd-rich-editor .yjd-custom-upload-button,.yjd-rich-editor .yjd-input,.yjd-rich-editor .yjd-select-input,.yjd-rich-editor .yjd-suggestion-button{pointer-events:auto!important}.yjd-rich-editor .rich-editor-popup-container>*{pointer-events:auto}.yjd-rich-editor .rich-editor-popup-container .color-picker-popup,.yjd-rich-editor .rich-editor-popup-container .custom-select-popup,.yjd-rich-editor .rich-editor-popup-container .emoji-picker-popup,.yjd-rich-editor .rich-editor-popup-container .image-popup,.yjd-rich-editor .rich-editor-popup-container .import-popup,.yjd-rich-editor .rich-editor-popup-container .link-popup,.yjd-rich-editor .rich-editor-popup-container .list-picker-popup,.yjd-rich-editor .rich-editor-popup-container .table-popup,.yjd-rich-editor .rich-editor-popup-container .tag-popup,.yjd-rich-editor .rich-editor-popup-container .text-align-picker-popup,.yjd-rich-editor .rich-editor-popup-container .video-popup{position:absolute!important;z-index:1001!important}.yjd-rich-editor{--rte-bg:#ffffff;--rte-chrome:#fbfbfd;--rte-chrome-2:#f2f2f7;--rte-border:#e9e9f1;--rte-border-strong:#dadae6;--rte-ink:#20242f;--rte-muted:#767c8e;--rte-accent:#6d5efc;--rte-accent-ink:#5a48ee;--rte-accent-weak:#efedff;--rte-accent-ring:rgba(109, 94, 252, 0.28);--rte-danger:#e5484d;--rte-radius:14px;--rte-radius-md:11px;--rte-radius-sm:8px;--rte-shadow-sm:0 1px 2px rgba(20, 24, 46, 0.06);--rte-shadow:0 12px 32px -8px rgba(20, 24, 46, 0.20), 0 4px 10px -4px rgba(20, 24, 46, 0.10);--rte-t:140ms cubic-bezier(0.4, 0, 0.2, 1);border:1px solid var(--rte-border)!important;border-radius:var(--rte-radius)!important;background:var(--rte-bg);color:var(--rte-ink);box-shadow:var(--rte-shadow-sm);font-family:system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif}.yjd-rich-editor .rich-editor-popup-container button,.yjd-rich-editor .rich-editor-popup-container input,.yjd-rich-editor .rich-editor-popup-container select,.yjd-rich-editor .rich-editor-popup-container textarea,.yjd-rich-editor .toolbar-container button,.yjd-rich-editor .toolbar-container input,.yjd-rich-editor .toolbar-container select,.yjd-rich-editor .toolbar-container textarea{font-family:system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif!important}.yjd-rich-editor .rich-editor-toolbar-container{background:var(--rte-chrome);border-bottom:1px solid var(--rte-border)}.yjd-rich-editor .rich-editor-toolbar-1,.yjd-rich-editor .rich-editor-toolbar-2{display:flex;align-items:center;column-gap:0;row-gap:4px;padding:8px 12px}.yjd-rich-editor .rich-editor-toolbar-2{justify-content:flex-start}.yjd-rich-editor .rich-editor-toolbar-2.visible{border-top:1px solid var(--rte-border)}.yjd-rich-editor .toolbar-group{display:flex;align-items:center;gap:2px;border-right:none;margin:0;padding:0}.yjd-rich-editor .toolbar-group+.toolbar-group{margin-left:12px}.yjd-rich-editor .rich-editor-toolbar-btn{color:var(--rte-ink)}.yjd-rich-editor .custom-select-button,.yjd-rich-editor .rich-editor-toolbar-btn{display:inline-flex;align-items:center;justify-content:center;gap:6px;min-width:32px;height:32px;padding:0 8px;border:1px solid transparent;border-radius:var(--rte-radius-sm);background:0 0;cursor:pointer;transition:background var(--rte-t),color var(--rte-t),box-shadow var(--rte-t),border-color var(--rte-t)}.yjd-rich-editor .rich-editor-toolbar-btn:hover{background:var(--rte-chrome-2)}.yjd-rich-editor .custom-select-button:hover{background:var(--rte-chrome-2);color:var(--rte-ink)}.yjd-rich-editor .rich-editor-toolbar-btn.active{background:var(--rte-accent-weak);border-color:transparent}.yjd-rich-editor .rich-editor-toolbar-btn:disabled,.yjd-rich-editor .rich-editor-toolbar-btn[disabled]{opacity:.38!important;cursor:not-allowed!important}.yjd-rich-editor .custom-select-button:focus-visible,.yjd-rich-editor .rich-editor-toolbar-btn:focus-visible{outline:0;border-color:var(--rte-accent);box-shadow:0 0 0 3px var(--rte-accent-ring)}.yjd-rich-editor .rich-editor-statusbar{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:7px 14px;background:var(--rte-chrome);border-top:1px solid var(--rte-border)}.yjd-rich-editor .rich-editor-breadcrumb,.yjd-rich-editor .wordcount{color:var(--rte-muted);font-size:12px;letter-spacing:.01em}.yjd-rich-editor .rich-editor-area{color:var(--rte-ink);font-size:16px;line-height:1.75;padding:22px 24px}.yjd-rich-editor .rich-editor-area[data-placeholder].placeholder-visible:before{color:var(--rte-muted);opacity:.55}.yjd-rich-editor .rich-editor-area blockquote{border-left:3px solid var(--rte-accent);background:var(--rte-accent-weak);border-radius:0 var(--rte-radius-sm) var(--rte-radius-sm)0;padding:8px 16px;color:var(--rte-ink);margin:12px 0}.yjd-rich-editor .rich-editor-area pre code{background:0 0;color:inherit;padding:0}.yjd-rich-editor .capitalization-select-popup,.yjd-rich-editor .color-picker-popup,.yjd-rich-editor .custom-select-popup,.yjd-rich-editor .emoji-picker-popup,.yjd-rich-editor .font-family-select-popup,.yjd-rich-editor .heading-select-popup,.yjd-rich-editor .image-popup,.yjd-rich-editor .import-popup,.yjd-rich-editor .line-height-select-popup,.yjd-rich-editor .link-popup,.yjd-rich-editor .table-popup,.yjd-rich-editor .tag-popup,.yjd-rich-editor .text-align-picker-popup,.yjd-rich-editor .text-size-select-popup,.yjd-rich-editor .video-popup{background:var(--rte-bg);border:1px solid var(--rte-border);box-shadow:var(--rte-shadow)}.yjd-rich-editor .custom-select-item-button{color:var(--rte-ink);transition:background var(--rte-t),color var(--rte-t)}.yjd-rich-editor .custom-select-item-button:hover{background:var(--rte-chrome-2)}.yjd-rich-editor .custom-select-item-button.current .item-checkmark{color:var(--rte-accent-ink)}.yjd-rich-editor .yjd-input{transition:border-color var(--rte-t),box-shadow var(--rte-t)}.yjd-rich-editor .yjd-input:focus{outline:0}.yjd-rich-editor .yjd-input-title{color:var(--rte-ink);font-weight:600}.yjd-rich-editor .yjd-input-label{color:var(--rte-muted)}.yjd-rich-editor .yjd-button-confirm{border:0}.yjd-rich-editor .yjd-button-cancel{background:var(--rte-chrome-2)}.yjd-rich-editor .yjd-button-cancel:hover{background:#e9e9f2}.yjd-rich-editor .yjd-custom-upload-button{border-radius:var(--rte-radius-sm);border:1px dashed var(--rte-border-strong);color:var(--rte-accent-ink);background:var(--rte-accent-weak);transition:background var(--rte-t),border-color var(--rte-t)}.yjd-rich-editor .yjd-custom-upload-button:hover{border-color:var(--rte-accent)}.yjd-rich-editor .block-toolbar-container,.yjd-rich-editor .table-toolbar-container{background:var(--rte-bg);border:1px solid var(--rte-border);border-radius:var(--rte-radius-md);box-shadow:var(--rte-shadow);padding:4px;gap:2px}.yjd-rich-editor .block-toolbar-btn,.yjd-rich-editor .table-toolbar-btn{border:1px solid transparent;border-radius:var(--rte-radius-sm);background:0 0;color:var(--rte-ink);transition:background var(--rte-t),color var(--rte-t)}.yjd-rich-editor .block-toolbar-btn:hover,.yjd-rich-editor .table-toolbar-btn:hover{background:var(--rte-chrome-2)}.yjd-rich-editor .block-toolbar-btn.active{background:var(--rte-accent-weak);color:var(--rte-accent-ink)}.yjd-rich-editor .block-toolbar-btn.active .icon svg,.yjd-rich-editor .block-toolbar-btn.active .icon svg path{fill:var(--rte-accent-ink)}.yjd-rich-editor .rich-editor-table td{border:1px solid var(--rte-border-strong)!important}.yjd-rich-editor .rich-editor-table td:focus{outline:0;box-shadow:inset 0 0 0 2px var(--rte-accent);background:var(--rte-accent-weak)}.yjd-rich-editor .table-grid-cell.highlighted{background:var(--rte-accent);border-color:var(--rte-accent)}.yjd-rich-editor .resize-handle{background:var(--rte-accent)!important;border:2px solid #fff!important;border-radius:50%!important;box-shadow:var(--rte-shadow-sm)!important}.yjd-rich-editor .yjd-find-replace{position:absolute;top:10px;right:10px;z-index:1100;display:none;flex-direction:column;gap:8px;padding:10px;background:var(--rte-bg);border:1px solid var(--rte-border);border-radius:var(--rte-radius-md);box-shadow:var(--rte-shadow);font:13px/1.4 system-ui,-apple-system,sans-serif;max-width:calc(100% - 20px)}.yjd-rich-editor .yjd-find-replace.open{display:flex}.yjd-rich-editor .yjd-find-row{display:flex;align-items:center;gap:6px}.yjd-rich-editor .yjd-find-input{flex:1 1 auto;min-width:150px;transition:border-color var(--rte-t),box-shadow var(--rte-t)}.yjd-rich-editor .yjd-find-input:focus{outline:0}.yjd-rich-editor .yjd-find-count{min-width:46px;text-align:center;color:var(--rte-muted);font-variant-numeric:tabular-nums}.yjd-rich-editor .yjd-find-btn{border:1px solid var(--rte-border);background:var(--rte-chrome);color:var(--rte-ink);cursor:pointer}.yjd-rich-editor .yjd-find-btn:hover{background:var(--rte-chrome-2)}.yjd-rich-editor .yjd-find-btn:focus-visible{outline:0;border-color:var(--rte-accent);box-shadow:0 0 0 3px var(--rte-accent-ring)}.yjd-rich-editor .yjd-find-icon{width:30px;padding:0;font-size:15px;line-height:1}.yjd-rich-editor .yjd-find-toggle.active{background:var(--rte-accent-weak);color:var(--rte-accent-ink);border-color:transparent}.yjd-rich-editor .yjd-find-replace .yjd-find-btn.yjd-find-close:hover{background:#fdecec;color:var(--rte-danger);border-color:#f6caca}.yjd-rich-editor .yjd-find-replace-input{flex:1 1 auto}.yjd-rich-editor .yjd-find-row .yjd-find-btn:not(.yjd-find-icon){flex:0 0 auto}.yjd-rich-editor mark.yjd-find-hit{background:#fff1b8;color:inherit;border-radius:3px}.yjd-rich-editor mark.yjd-find-hit.active{background:var(--rte-accent);color:#fff}@media (prefers-reduced-motion:reduce){.yjd-rich-editor *{transition-duration:.01ms!important;animation-duration:.01ms!important}}.yjd-rich-editor .block-toolbar-btn svg [fill="#454545"],.yjd-rich-editor .icon svg [fill="#010101"],.yjd-rich-editor .icon svg [fill="#231F20"],.yjd-rich-editor .icon svg [fill="#454545"],.yjd-rich-editor .icon svg[fill="#454545"],.yjd-rich-editor .table-toolbar-btn svg [fill="#454545"]{fill:currentColor}.yjd-rich-editor .block-toolbar-btn .icon,.yjd-rich-editor .rich-editor-toolbar-btn .icon,.yjd-rich-editor .table-toolbar-btn .icon{display:inline-flex;align-items:center;justify-content:center;width:18px;height:18px;color:inherit}.yjd-rich-editor .block-toolbar-btn .icon svg,.yjd-rich-editor .rich-editor-toolbar-btn .icon svg,.yjd-rich-editor .table-toolbar-btn .icon svg{width:auto!important;height:16px!important;max-width:18px;display:block}.yjd-rich-editor .rich-editor-toolbar-btn .icon svg,.yjd-rich-editor .rich-editor-toolbar-btn .icon svg path{fill:currentColor}.yjd-rich-editor .rich-editor-toolbar-btn{color:#4b5060}.yjd-rich-editor .rich-editor-toolbar-btn:hover{color:var(--rte-ink)}.yjd-rich-editor .rich-editor-toolbar-btn.active,.yjd-rich-editor .rich-editor-toolbar-btn.active .icon svg [fill]{color:var(--rte-accent-ink)!important;fill:var(--rte-accent-ink)!important}.yjd-rich-editor .rich-editor-toolbar-btn.active .icon svg,.yjd-rich-editor .rich-editor-toolbar-btn.active .icon svg path{fill:var(--rte-accent-ink)!important}.yjd-rich-editor .custom-select-button,.yjd-rich-editor .rich-editor-toolbar-btn{box-shadow:none}.yjd-rich-editor .custom-select-button{border-color:var(--rte-border);background:var(--rte-bg);color:var(--rte-ink);font-weight:500}.yjd-rich-editor .custom-select-button:hover{border-color:var(--rte-border-strong);background:var(--rte-bg)}.yjd-rich-editor .dropdown-icon{color:var(--rte-muted)}.yjd-rich-editor .capitalization-select-popup,.yjd-rich-editor .color-picker-popup,.yjd-rich-editor .custom-select-popup,.yjd-rich-editor .font-family-select-popup,.yjd-rich-editor .heading-select-popup,.yjd-rich-editor .image-popup,.yjd-rich-editor .import-popup,.yjd-rich-editor .line-height-select-popup,.yjd-rich-editor .link-popup,.yjd-rich-editor .table-popup,.yjd-rich-editor .tag-popup,.yjd-rich-editor .text-size-select-popup,.yjd-rich-editor .video-popup{border-color:var(--rte-border);border-radius:var(--rte-radius-md);box-shadow:0 10px 30px -10px rgba(20,24,46,.18),0 2px 6px -2px rgba(20,24,46,.08)}.yjd-rich-editor .emoji-picker-popup,.yjd-rich-editor .text-align-picker-popup{border-color:var(--rte-border);box-shadow:0 10px 30px -10px rgba(20,24,46,.18),0 2px 6px -2px rgba(20,24,46,.08)}.yjd-rich-editor .emoji-picker-popup{border-radius:var(--rte-radius-md)}.yjd-rich-editor .capitalization-select-popup,.yjd-rich-editor .custom-select-popup,.yjd-rich-editor .font-family-select-popup,.yjd-rich-editor .heading-select-popup,.yjd-rich-editor .line-height-select-popup,.yjd-rich-editor .text-size-select-popup{padding:6px}.yjd-rich-editor .capitalization-select-popup.visible,.yjd-rich-editor .color-picker-popup.visible,.yjd-rich-editor .custom-select-popup.visible,.yjd-rich-editor .font-family-select-popup.visible,.yjd-rich-editor .heading-select-popup.visible,.yjd-rich-editor .image-popup.visible,.yjd-rich-editor .line-height-select-popup.visible,.yjd-rich-editor .link-popup.visible,.yjd-rich-editor .table-popup.visible,.yjd-rich-editor .tag-popup.visible,.yjd-rich-editor .text-align-picker-popup.visible,.yjd-rich-editor .text-size-select-popup.visible,.yjd-rich-editor .video-popup.visible,.yjd-rich-editor .yjd-find-replace.open{animation:rte-pop-in 90ms ease-out}.yjd-rich-editor .yjd-input{height:36px;border:1px solid var(--rte-border);border-radius:var(--rte-radius-sm);background:var(--rte-bg);color:var(--rte-ink)}.yjd-rich-editor .yjd-select-input{height:36px;background:var(--rte-bg);font-size:14px}.yjd-rich-editor .yjd-find-input{height:36px;border:1px solid var(--rte-border);border-radius:var(--rte-radius-sm);background:var(--rte-bg);color:var(--rte-ink)}.yjd-rich-editor .yjd-find-input::placeholder,.yjd-rich-editor .yjd-input::placeholder,.yjd-rich-editor .yjd-select-input::placeholder{color:var(--rte-muted);opacity:.7}.yjd-rich-editor .yjd-find-input:focus,.yjd-rich-editor .yjd-input:focus{border-color:var(--rte-accent);box-shadow:0 0 0 3px var(--rte-accent-ring)}.yjd-rich-editor .yjd-button-cancel,.yjd-rich-editor .yjd-button-confirm,.yjd-rich-editor .yjd-find-btn{height:36px;padding:0 16px;font-size:14px;font-weight:500;border-radius:var(--rte-radius-sm);box-shadow:none;transition:background var(--rte-t),color var(--rte-t),border-color var(--rte-t)}.yjd-rich-editor .yjd-button-confirm{background:var(--rte-accent);border:1px solid var(--rte-accent);color:#fff}.yjd-rich-editor .yjd-button-confirm:hover{background:var(--rte-accent-ink);border-color:var(--rte-accent-ink)}.yjd-rich-editor .yjd-button-cancel{background:0 0;border:1px solid var(--rte-border);color:var(--rte-muted)}.yjd-rich-editor .yjd-button-cancel:hover{background:var(--rte-chrome-2);color:var(--rte-ink)}.yjd-rich-editor .yjd-find-btn:not(.yjd-find-icon){background:0 0;border:1px solid var(--rte-border);color:var(--rte-ink)}.yjd-rich-editor .yjd-find-btn:not(.yjd-find-icon):hover{background:var(--rte-chrome-2)}.yjd-rich-editor .yjd-find-btn.yjd-find-icon{height:32px;width:32px;color:var(--rte-muted);background:0 0;border:1px solid transparent}.yjd-rich-editor .yjd-find-btn.yjd-find-icon:hover{background:var(--rte-chrome-2);color:var(--rte-ink)}@media (prefers-reduced-motion:reduce){.yjd-rich-editor .color-picker-popup.visible,.yjd-rich-editor .yjd-find-replace.open,.yjd-rich-editor [class$=-popup].visible,.yjd-rich-editor [class*=select-popup].visible{animation:none!important}}.yjd-rich-editor .icon svg{display:block;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;overflow:visible}.yjd-rich-editor .icon svg line,.yjd-rich-editor .icon svg path,.yjd-rich-editor .icon svg polyline,.yjd-rich-editor .icon svg rect{fill:none!important;stroke:currentColor}.yjd-rich-editor .icon svg [fill=currentColor],.yjd-rich-editor .list-button svg [fill=currentColor],.yjd-rich-editor .table-toolbar-btn svg [fill=currentColor]{fill:currentColor!important;stroke:none!important}.yjd-rich-editor .rich-editor-toolbar-btn .icon svg{color:#565b6b}.yjd-rich-editor .rich-editor-toolbar-btn:hover .icon svg{color:var(--rte-ink)}.yjd-rich-editor .rich-editor-toolbar-btn.active .icon svg,.yjd-rich-editor .rich-editor-toolbar-btn.active .icon svg line,.yjd-rich-editor .rich-editor-toolbar-btn.active .icon svg path,.yjd-rich-editor .rich-editor-toolbar-btn.active .icon svg polyline,.yjd-rich-editor .rich-editor-toolbar-btn.active .icon svg rect{color:var(--rte-accent-ink)!important;stroke:var(--rte-accent-ink)!important;fill:none!important}.yjd-rich-editor .rich-editor-toolbar-btn.active .icon svg [fill=currentColor]{fill:var(--rte-accent-ink)!important;stroke:none!important}.yjd-rich-editor .block-toolbar-btn.active .icon svg,.yjd-rich-editor .block-toolbar-btn.active .icon svg path{stroke:var(--rte-accent-ink)!important;fill:none!important}.yjd-rich-editor .list-picker-popup{background:var(--rte-bg);border:1px solid var(--rte-border);border-radius:var(--rte-radius-md);box-shadow:var(--rte-shadow);padding:6px}.yjd-rich-editor .list-picker-popup.visible{animation:rte-pop-in 90ms ease-out}.yjd-rich-editor .list-button-container{display:flex;align-items:center;gap:2px}.yjd-rich-editor .list-button{display:inline-flex;align-items:center;justify-content:center;width:34px;height:32px;padding:0;border:1px solid transparent;border-radius:var(--rte-radius-sm);background:0 0;color:#565b6b;cursor:pointer;transition:background var(--rte-t),color var(--rte-t)}.yjd-rich-editor .list-button:hover{background:var(--rte-chrome-2);color:var(--rte-ink)}.yjd-rich-editor .list-button.active{background:var(--rte-accent-weak);color:var(--rte-accent-ink)}.yjd-rich-editor .icon svg,.yjd-rich-editor .list-button svg,.yjd-rich-editor .table-toolbar-btn svg{width:auto!important;height:16px!important;max-width:20px;fill:none!important}.yjd-rich-editor .list-button svg{stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}.yjd-rich-editor .table-toolbar-btn svg{display:block}.yjd-rich-editor .table-toolbar-btn{color:#565b6b}.yjd-rich-editor .table-toolbar-btn:hover{color:var(--rte-ink)}.yjd-rich-editor .align-button{border-radius:var(--rte-radius-sm);background:0 0;color:var(--rte-ink);transition:background var(--rte-t),color var(--rte-t)}.yjd-rich-editor .align-button:hover{background:var(--rte-chrome-2);border-color:transparent}.yjd-rich-editor .align-button.active{background:var(--rte-accent-weak);color:var(--rte-accent-ink);border-color:transparent}.yjd-rich-editor .align-button svg,.yjd-rich-editor .table-toolbar-btn svg,.yjd-slash-icon svg{stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}.yjd-rich-editor .align-button svg{width:auto!important;height:16px!important;color:inherit;fill:none!important}.yjd-rich-editor .align-button.active svg{color:var(--rte-accent-ink)}.yjd-rich-editor .yjd-custom-upload-button svg{width:17px;height:17px;fill:none;stroke:var(--rte-accent-ink)}.yjd-rich-editor .text-align-picker-popup{min-width:168px}.yjd-rich-editor .align-button,.yjd-rich-editor .align-button .label-text{white-space:nowrap}.yjd-rich-editor .rich-editor-toolbar-1{flex-wrap:nowrap!important;overflow:hidden}.yjd-rich-editor .rich-editor-toolbar-2{border-top:1px solid var(--rte-border)}.yjd-rich-editor .custom-select-button,.yjd-rich-editor .rich-editor-toolbar-btn,.yjd-rich-editor .toolbar-group{flex:0 0 auto}.yjd-rich-editor .block-toolbar-arrow,.yjd-rich-editor .table-toolbar-arrow{display:none!important}.yjd-slash-menu{position:absolute;z-index:2000;min-width:264px;max-width:320px;max-height:320px;overflow-y:auto;padding:6px;background:#fff;border:1px solid #e9e9f1;border-radius:12px;box-shadow:0 12px 32px -8px rgba(20,24,46,.2),0 4px 10px -4px rgba(20,24,46,.1);font:14px/1.4 system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;animation:yjd-slash-in 90ms ease-out}.yjd-slash-item{display:flex;align-items:center;gap:10px;width:100%;padding:8px 10px;border:0;background:0 0;border-radius:8px;cursor:pointer;text-align:left;color:#20242f}.yjd-slash-item.active,.yjd-slash-item:hover{background:#efedff;color:#5a48ee}.yjd-slash-icon{display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;flex:0 0 auto;border-radius:7px;background:#f2f2f7;color:inherit}.yjd-slash-item.active .yjd-slash-icon{background:#fff}.yjd-slash-icon svg{width:auto;height:16px;fill:none}.yjd-slash-icon svg [fill=currentColor]{fill:currentColor;stroke:none}.yjd-slash-text{display:flex;flex-direction:column;line-height:1.25;min-width:0}.yjd-slash-label{font-weight:500}.yjd-slash-hint{font-size:12px;color:#767c8e}.yjd-slash-item.active .yjd-slash-hint{color:#8b7ff0}@media (prefers-reduced-motion:reduce){.yjd-slash-menu{animation:none}}.yjd-rich-editor .rich-editor-toolbar-btn.background-btn,.yjd-rich-editor .rich-editor-toolbar-btn.color-btn{position:relative}.yjd-rich-editor .rich-editor-toolbar-btn .rte-swatch{position:absolute;left:50%;bottom:5px;transform:translateX(-50%);width:16px;height:3px;border-radius:2px;background:var(--rte-ink, #20242f);pointer-events:none;box-shadow:0 0 0 1px rgba(0,0,0,.06)}.yjd-rich-editor .rich-editor-toolbar-btn.background-btn .rte-swatch{background:0 0;box-shadow:inset 0 0 0 1px var(--rte-border, #e9e9f1)}.yjd-rich-editor .rich-editor-toolbar-btn.background-btn.has-color .rte-swatch{box-shadow:0 0 0 1px rgba(0,0,0,.06)}.yjd-rich-editor .rich-editor-toolbar-btn.background-btn .icon,.yjd-rich-editor .rich-editor-toolbar-btn.color-btn .icon{transform:translateY(-1px)}.yjd-rich-editor .link-popup.link-popup--inline{width:auto;min-width:320px;max-width:min(92vw,420px);padding:10px}.yjd-rich-editor .link-popup--inline .link-popup-content{display:flex;flex-direction:column;gap:8px}.yjd-rich-editor .link-popup--inline .link-popup-row{display:flex;align-items:center;gap:8px}.yjd-rich-editor .link-popup--inline .link-popup-row .yjd-input{flex:1;min-width:0;margin:0}.yjd-rich-editor .link-popup--inline .link-popup-apply{flex:0 0 auto;white-space:nowrap;padding:8px 16px;margin:0}.yjd-rich-editor .custom-select-item-button{min-height:34px;padding:6px 10px!important;gap:10px;border-radius:var(--rte-radius-sm)!important}.yjd-rich-editor .custom-select-item-button.current,.yjd-rich-editor .custom-select-item-button:hover{background:var(--rte-accent-weak)!important;color:var(--rte-accent-ink)!important}.yjd-rich-editor .custom-select-item-button.current{font-weight:600}.yjd-rich-editor .font-family-select-popup .custom-select-item-button,.yjd-rich-editor .heading-select-popup .custom-select-item-button,.yjd-rich-editor .text-size-select-popup .custom-select-item-button{line-height:1.15}.yjd-rich-editor .import-type-select,.yjd-rich-editor .tag-type-select,.yjd-rich-editor .yjd-select-input,.yjd-rich-editor select{-webkit-appearance:none;-moz-appearance:none;appearance:none;width:100%;box-sizing:border-box;padding:10px 36px 10px 12px;font:500 14px/1.4 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;color:var(--rte-ink);background-color:var(--rte-bg);background-image:url("data:image/svg+xml,%3Csvg%20xmlns=\'http://www.w3.org/2000/svg\'%20width=\'16\'%20height=\'16\'%20viewBox=\'0%200%2024%2024\'%20fill=\'none\'%20stroke=\'%23767c8e\'%20stroke-width=\'2\'%20stroke-linecap=\'round\'%20stroke-linejoin=\'round\'%3E%3Cpath%20d=\'m6%209%206%206%206-6\'/%3E%3C/svg%3E");background-repeat:no-repeat;background-position:right 12px center;background-size:16px;border:1px solid var(--rte-border-strong);border-radius:var(--rte-radius-sm);cursor:pointer;transition:border-color var(--rte-t),box-shadow var(--rte-t)}.yjd-rich-editor .import-type-select:hover,.yjd-rich-editor .tag-type-select:hover,.yjd-rich-editor .yjd-select-input:hover,.yjd-rich-editor select:hover{border-color:var(--rte-accent)}.yjd-rich-editor .import-type-select:focus,.yjd-rich-editor .tag-type-select:focus,.yjd-rich-editor .yjd-select-input:focus,.yjd-rich-editor select:focus{outline:0;border-color:var(--rte-accent);box-shadow:0 0 0 3px var(--rte-accent-ring)}.yjd-rich-editor .yjd-find-input,.yjd-rich-editor .yjd-input{box-sizing:border-box;padding:10px 12px;font-size:14px;line-height:1.4}.yjd-rich-editor .table-grid-cell:hover{background:var(--rte-accent-weak)!important;border-color:var(--rte-accent)!important}.yjd-rich-editor .rich-editor-toolbar-1{justify-content:flex-start!important}.yjd-rich-editor .rich-editor-toolbar-1 .more-btn{margin-left:auto!important}@media (max-width:640px){.yjd-rich-editor .rich-editor-toolbar-1{flex-wrap:nowrap!important;overflow-x:auto!important;overflow-y:hidden;-webkit-overflow-scrolling:touch;scrollbar-width:none;justify-content:flex-start!important;padding:6px 8px;scroll-padding:8px}.yjd-rich-editor .rich-editor-toolbar-1::-webkit-scrollbar{display:none}.yjd-rich-editor .rich-editor-toolbar-1 .more-btn,.yjd-rich-editor .rich-editor-toolbar-2{display:none!important}.yjd-rich-editor .toolbar-group{flex:0 0 auto}.yjd-rich-editor .toolbar-group+.toolbar-group{margin-left:8px}.yjd-rich-editor .custom-select-button,.yjd-rich-editor .rich-editor-toolbar-btn{min-width:32px;height:32px;padding:0 8px;flex:0 0 auto}.yjd-rich-editor .custom-select-button{max-width:none}}.yjd-rich-editor .rich-editor-toolbar-btn.rte-hidden{display:none!important}.yjd-rich-editor .rich-editor-area>:first-child{margin-top:0!important}.yjd-rich-editor .rich-editor-area>:last-child{margin-bottom:0!important}.yjd-rich-editor .align-button-container{flex-direction:row!important;width:auto!important;height:auto!important;gap:4px}.yjd-rich-editor .align-button{width:34px!important;min-height:34px!important;height:34px!important;padding:0!important;gap:0!important;justify-content:center!important}.yjd-rich-editor .text-align-picker-popup{width:auto!important}.yjd-rich-editor .rich-editor-toolbar-2{flex-wrap:nowrap!important;overflow-x:auto;overflow-y:hidden;-webkit-overflow-scrolling:touch;scrollbar-width:none}.yjd-rich-editor .rich-editor-toolbar-2::-webkit-scrollbar{display:none}.yjd-rich-editor .rich-editor-toolbar-2 .toolbar-group{flex:0 0 auto}.yjd-rich-editor .custom-select-header{padding:8px 12px 6px;font-size:11px;font-weight:600;letter-spacing:.05em;text-transform:uppercase;color:var(--rte-muted);border-bottom:1px solid var(--rte-border);margin-bottom:4px;white-space:nowrap}.yjd-rich-editor .custom-select-button .select-lead-icon{width:16px;height:16px;display:inline-flex;align-items:center;justify-content:center;color:var(--rte-muted);margin-right:4px}.yjd-rich-editor .custom-select-button .select-lead-icon svg{width:16px;height:16px;display:block;stroke:currentColor;fill:none}.yjd-rich-editor .custom-select-button{white-space:nowrap;overflow:hidden}.yjd-rich-editor .custom-select-button .button-text{flex:1 1 auto;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.yjd-rich-editor .custom-select-button .dropdown-icon,.yjd-rich-editor .custom-select-button .select-lead-icon{flex:0 0 auto}.yjd-rich-editor .text-align-picker-popup{padding:6px!important;border-radius:var(--rte-radius-md)!important}.yjd-rich-editor .align-button-container{padding:0!important}.yjd-rich-editor .rich-editor-breadcrumb,.yjd-rich-editor .wordcount{color:#5b6373}.yjd-rich-editor .yjd-find-btn{display:inline-flex;align-items:center;justify-content:center}.yjd-rich-editor .yjd-find-icon .icon,.yjd-rich-editor .yjd-find-icon .icon svg{width:16px;height:16px;display:block}.yjd-rich-editor .yjd-find-icon .icon svg{stroke:currentColor;fill:none}.mention{display:inline;padding:0 2px;border-radius:4px;background:#efedff;color:#5a48ee;font-weight:500;text-decoration:none;white-space:nowrap}.mention[data-trigger="#"]{background:#e8f3ff;color:#1f6feb}.yjd-mention-menu{position:absolute;z-index:2000;min-width:220px;max-width:320px;max-height:280px;overflow-y:auto;padding:6px;background:#fff;border:1px solid #e9e9f1;border-radius:12px;box-shadow:0 12px 32px -8px rgba(20,24,46,.2),0 4px 10px -4px rgba(20,24,46,.1);font:14px/1.4 system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;animation:yjd-slash-in 90ms ease-out}.yjd-mention-item{display:flex;align-items:center;gap:10px;width:100%;padding:7px 10px;border:0;background:0 0;border-radius:8px;cursor:pointer;text-align:left;color:#20242f}.yjd-mention-item.active,.yjd-mention-item:hover{background:#efedff;color:#5a48ee}.yjd-mention-avatar{width:26px;height:26px;border-radius:50%;object-fit:cover;flex:0 0 auto;background:#f2f2f7}.yjd-mention-name{font-weight:500;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}@media (prefers-reduced-motion:reduce){.yjd-mention-menu{animation:none}}.yjd-content{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;font-size:16px;line-height:1.6;color:#20242f;word-wrap:break-word}.yjd-content>:first-child{margin-top:0}.yjd-content>:last-child{margin-bottom:0}.yjd-content li{margin:.25em 0}.yjd-content a{color:#2563eb;text-decoration:underline}.yjd-content code,.yjd-content pre{font-family:Consolas,Menlo,Monaco,"Courier New",monospace;background:#f1f2f3;padding:2px 6px;border-radius:4px}.yjd-content pre{padding:12px 14px;border-radius:6px;margin:1em 0;overflow-x:auto;white-space:pre}.yjd-content pre code{background:0 0;padding:0}.yjd-content img{max-width:100%;height:auto;border-radius:4px}.yjd-content hr{border:0;border-top:1px solid #d1d5db;margin:1.5em 0}.yjd-content table{border-collapse:collapse;width:100%;margin:1em 0}.yjd-content table td,.yjd-content table th{border:1px solid #d1d5db;padding:8px 10px;text-align:left}',document.head.appendChild(this.styleElement),this.loaded=!0}catch(t){this.loadFallbackStyles()}return Promise.resolve()}static loadFallbackStyles(){this.styleElement=document.createElement("style"),this.styleElement.id="rich-editor-styles-fallback",this.styleElement.textContent="\n .yjd-rich-editor { \n position: relative; \n background: #fff; \n border: 1px solid #ddd; \n border-radius: 4px; \n display: flex; \n flex-direction: column; \n font-family: system-ui, sans-serif; \n }\n .yjd-rich-editor .rich-editor-area { \n flex: 1; \n padding: 20px; \n outline: none; \n min-height: 100px; \n }\n .yjd-rich-editor .rich-editor-toolbar { \n display: flex; \n gap: 4px; \n padding: 8px; \n border-bottom: 1px solid #ddd; \n background: #f9f9f9; \n }\n .yjd-rich-editor .rich-editor-toolbar-btn { \n padding: 4px 8px; \n border: 1px solid #ccc; \n border-radius: 3px; \n background: #fff; \n cursor: pointer; \n }\n .yjd-rich-editor .table-grid-selector { \n position: absolute; \n background: white; \n border: 1px solid #ccc; \n border-radius: 4px; \n padding: 10px; \n box-shadow: 0 2px 8px rgba(0,0,0,0.15); \n z-index: 1000; \n display: none; \n }\n .yjd-rich-editor .table-grid-cell { \n width: 20px; \n height: 20px; \n border: 1px solid #ddd; \n cursor: pointer; \n background: white; \n }\n ",document.head.appendChild(this.styleElement),this.loaded=!0}static unloadStyles(){this.styleElement&&this.styleElement.parentNode&&(this.styleElement.parentNode.removeChild(this.styleElement),this.styleElement=null,this.loaded=!1)}static isLoaded(){return this.loaded}static async reloadStyles(){this.unloadStyles(),await this.loadStyles()}static addCustomCSS(t,e="rich-editor-custom"){const i=document.getElementById(e);i&&i.remove();const o=document.createElement("style");o.id=e,o.textContent=t,document.head.appendChild(o)}}.loadStyles().catch(t=>{});class Mt extends S{static register(e,i,o=!1){t.register(e,i,o)}static get(e){return t.get(e)}static create(t,e={}){return new Mt(t,e)}static fromTextarea(t,e={}){const i="string"==typeof t?document.querySelector(t):t;if(!i)throw new Error("RichEditor.fromTextarea: textarea not found");const o="markdown"===e.format?"markdown":"html",n=document.createElement("div");i.after(n),i.style.display="none",i.setAttribute("aria-hidden","true");const r=i.value||"",s=new Mt(n,{width:"100%",...e,content:null!=e.content?e.content:"markdown"===o?y(r):r}),a=()=>{const t=(e=s,"markdown"===o?e.getMarkdown():e.getContent());var e;i.value!==t&&(i.value=t,i.dispatchEvent(new Event("input",{bubbles:!0})),i.dispatchEvent(new Event("change",{bubbles:!0})))};return s.on("change",a),a(),s.textarea=i,s}}var Ot=Object.freeze({__proto__:null,Background:G,BlockFormat:A,BlockToolbar:St,Bold:R,Capitalization:nt,CodeView:Lt,Color:K,ColorPicker:X,Editor:S,Emoji:mt,EmojiPicker:ut,FindReplace:At,FontFamily:it,Format:N,Heading:et,History:It,IconUtils:F,Image:gt,ImagePopup:zt,Import:kt,Indent:dt,IndentDecrease:pt,IndentIncrease:ht,InlineFormat:L,Italic:H,LineHeight:ot,Link:Q,LinkPopup:Y,List:ct,ListPicker:lt,Mention:Rt,Module:e,ResizeHandles:Ht,RichEditor:Mt,SlashMenu:Bt,Strike:M,Subscript:O,Superscript:P,Table:J,TablePopup:Z,TableToolbar:Nt,Tag:Ct,TagPopup:xt,TextAlign:st,TextAlignPicker:rt,TextSize:wt,Toolbar:Tt,Underline:z,Video:bt,VideoPopup:yt,createCustomButton:jt,createEditor:function(t,e={}){return new Mt(t,e)},default:Mt,domToJson:k,htmlToMarkdown:h,jsonToHtml:T,markdownToHtml:y,registry:t,renderStatic:function(t,e){const i=d(t||""),o=e||document.createElement("div");return o.classList.add("yjd-content"),o.innerHTML=i,o},yjd:Mt});for(const[t,e]of Object.entries(Ot))"default"===t||t in Mt||(Mt[t]=e);return Mt}),"undefined"!=typeof window&&(window.RichEditor=window.RichEditor||window.yjd);
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).yjd=e()}(this,function(){"use strict";const t=new class{constructor(){this.modules=new Map,this.formats=new Map,this.themes=new Map,this.ui=new Map}register(t,e,i=!1){if("object"==typeof t)return void Object.entries(t).forEach(([t,e])=>{this.register(t,e,i)});const[o,n]=t.split("/");if(!i){this.get(t)}switch(o){case"modules":this.modules.set(n,e);break;case"formats":this.formats.set(n,e);break;case"themes":this.themes.set(n,e);break;case"ui":this.ui.set(n,e)}}get(t){const[e,i]=t.split("/");switch(e){case"modules":return this.modules.get(i);case"formats":return this.formats.get(i);case"themes":return this.themes.get(i);case"ui":return this.ui.get(i);default:return null}}has(t){return null!==this.get(t)&&void 0!==this.get(t)}getAll(t){switch(t){case"modules":return new Map(this.modules);case"formats":return new Map(this.formats);case"themes":return new Map(this.themes);case"ui":return new Map(this.ui);default:return new Map}}unregister(t){const[e,i]=t.split("/");switch(e){case"modules":this.modules.delete(i);break;case"formats":this.formats.delete(i);break;case"themes":this.themes.delete(i);break;case"ui":this.ui.delete(i)}}clear(){this.modules.clear(),this.formats.clear(),this.themes.clear(),this.ui.clear()}getAllItems(){const t={};return t.modules=Array.from(this.modules.keys()),t.formats=Array.from(this.formats.keys()),t.themes=Array.from(this.themes.keys()),t.ui=Array.from(this.ui.keys()),t}};class e{static DEFAULTS={};constructor(t,e={}){this.editor=t,this.options={...this.constructor.DEFAULTS,...e},this.events=new Map}on(t,e){this.events.has(t)||this.events.set(t,[]),this.events.get(t).push(e)}off(t,e){if(this.events.has(t)){const i=this.events.get(t),o=i.indexOf(e);o>-1&&i.splice(o,1)}}emit(t,e){this.events.has(t)&&this.events.get(t).forEach(t=>{try{t(e)}catch(t){}})}destroy(){this.events.clear()}onContentChange(){}onSelectionChange(t){}}function i(t,e=null){try{return null==e?document.execCommand(t,!1):document.execCommand(t,!1,e)}catch(t){return!1}}function o(t=!0){return i("styleWithCSS",t)}function n(t){try{return document.queryCommandState(t)}catch(t){return!1}}const r=["http:","https:","mailto:","tel:","ftp:"],s=["https://www.youtube.com/embed/","https://www.youtube-nocookie.com/embed/","https://player.vimeo.com/video/"];function a(t,{allowDataImage:e=!1}={}){if("string"!=typeof t)return!1;const i=t.trim();if(""===i)return!1;const o=i.replace(/[\u0000-\u0020\u007F-\u009F]/g,""),n=o.match(/^([a-z][a-z0-9+.-]*):/i);if(!n)return!0;const s=n[1].toLowerCase()+":";return"data:"===s?!!e&&(/^data:image\//i.test(o)&&!/^data:image\/svg/i.test(o)):r.includes(s)}const l=new Set(["SCRIPT","STYLE","OBJECT","EMBED","LINK","META","BASE","FORM","INPUT","BUTTON","TEXTAREA","SELECT","OPTION","NOSCRIPT"]);function c(t){const e=Array.from(t.attributes);for(const i of e){const e=i.name.toLowerCase(),o=i.value;if(e.startsWith("on"))t.removeAttribute(i.name);else{if("href"===e||"src"===e||"xlink:href"===e){a(o,{allowDataImage:"IMG"===t.tagName})||t.removeAttribute(i.name);continue}"style"===e&&/expression\s*\(|javascript:/i.test(o)&&t.removeAttribute(i.name)}}}function d(t){if("string"!=typeof t||""===t)return"";const e=(new DOMParser).parseFromString(t,"text/html"),i=Array.from(e.body.querySelectorAll("*"));for(const t of i){const e=t.tagName;if(l.has(e))t.remove();else{if("IFRAME"===e){const e=t.getAttribute("src")||"";if(!s.some(t=>e.startsWith(t))){t.remove();continue}}c(t)}}return e.body.innerHTML}function p(t){const e=document.createElement("div");return e.innerHTML=t||"",h(e,0).replace(/\n{3,}/g,"\n\n").trim()+"\n"}function h(t,e){let i="";return t.childNodes.forEach(t=>{i+=function(t,e){if(3===t.nodeType){const e=t.textContent.replace(/\s+/g," ");return e.trim()?e+"\n\n":""}if(1!==t.nodeType)return"";const i=t.tagName;switch(i){case"H1":case"H2":case"H3":case"H4":case"H5":case"H6":return"#".repeat(+i[1])+" "+g(t)+"\n\n";case"P":case"DIV":{const e=g(t);return e.trim()?e+"\n\n":""}case"BLOCKQUOTE":return g(t).split("\n").map(t=>"> "+t).join("\n")+"\n\n";case"PRE":return"```\n"+t.textContent.replace(/\n$/,"")+"\n```\n\n";case"UL":return u(t,e,!1)+"\n";case"OL":return u(t,e,!0)+"\n";case"HR":return"---\n\n";case"TABLE":return function(t){const e=[...t.querySelectorAll("tr")];if(!e.length)return"";const i=t=>[...t.children].map(t=>g(t).replace(/\|/g,"\\|").trim()),o=i(e[0]);let n="| "+o.join(" | ")+" |\n| "+o.map(()=>"---").join(" | ")+" |\n";return e.slice(1).forEach(t=>{n+="| "+i(t).join(" | ")+" |\n"}),n}(t)+"\n";case"FIGURE":return h(t,e);case"IMG":return m(t)+"\n\n";case"BR":return"\n";default:return g(t)+"\n\n"}}(t,e)}),i}function u(t,e,i){let o="",n=1;return t.childNodes.forEach(t=>{if(1!==t.nodeType||"LI"!==t.tagName)return;const r=i?n+++". ":"- ",s=" ".repeat(e);let a="",l="";t.childNodes.forEach(t=>{1!==t.nodeType||"UL"!==t.tagName&&"OL"!==t.tagName?a+=f(t):l+=u(t,e+1,"OL"===t.tagName)}),o+=s+r+a.trim()+"\n"+l}),o}function m(t){return`![${t.getAttribute("alt")||""}](${t.getAttribute("src")||""})`}function g(t){let e="";return t.childNodes.forEach(t=>{e+=f(t)}),e}function f(t){if(3===t.nodeType)return t.textContent;if(1!==t.nodeType)return"";const e=t.tagName;if(t.classList&&t.classList.contains("mention")){const e=t.getAttribute("data-id")||"",i=(t.textContent||"").replace(/^[@#]/,"");return`${(t.textContent||"@")[0]}[${i}](${e})`}if(t.classList&&t.classList.contains("yjd-file-chip")){const e=t.getAttribute("href")||"",i=t.querySelector?t.querySelector(".yjd-file-name"):null,o=t.getAttribute("data-name")||i&&i.textContent||"file",n=t.getAttribute("data-size")||"";return`[${n?`${o} (${n})`:o}](${e})`}switch(e){case"B":case"STRONG":return"**"+g(t)+"**";case"I":case"EM":return"*"+g(t)+"*";case"S":case"STRIKE":case"DEL":return"~~"+g(t)+"~~";case"U":return"<u>"+g(t)+"</u>";case"CODE":return"`"+t.textContent+"`";case"A":return"["+g(t)+"]("+(t.getAttribute("href")||"")+")";case"IMG":return m(t);case"BR":return" \n";default:return g(t)}}function y(t){const e=(t||"").replace(/\r\n/g,"\n").split("\n");let i="",o=0;const n=t=>/^\s*([-*+]|\d+\.)\s+/.test(t);for(;o<e.length;){const t=e[o];if(/^\s*$/.test(t)){o++;continue}if(/^---+$/.test(t.trim())){i+="<hr>",o++;continue}const r=t.match(/^(#{1,6})\s+(.*)$/);if(r){i+=`<h${r[1].length}>${w(r[2])}</h${r[1].length}>`,o++;continue}if(/^```/.test(t)){o++;let t="";for(;o<e.length&&!/^```/.test(e[o]);)t+=e[o]+"\n",o++;o++,i+="<pre>"+C(t.replace(/\n$/,""))+"</pre>";continue}if(/^>\s?/.test(t)){const t=[];for(;o<e.length&&/^>\s?/.test(e[o]);)t.push(e[o].replace(/^>\s?/,"")),o++;i+="<blockquote>"+w(t.join(" "))+"</blockquote>";continue}if(/^\|.*\|\s*$/.test(t)&&o+1<e.length&&/^\|[\s:|-]+\|\s*$/.test(e[o+1])){const t=x(e,o);i+=t.html,o=t.next;continue}if(n(t)){const t=v(e,o,0);i+=t.html,o=t.next;continue}const s=[t];for(o++;o<e.length&&!/^\s*$/.test(e[o])&&!/^(#{1,6}\s|>|```)/.test(e[o])&&!/^---+$/.test(e[o].trim())&&!n(e[o]);)s.push(e[o]),o++;i+="<p>"+w(s.join("\n").trim())+"</p>"}return i}function b(t){return(t.match(/^(\s*)/)[1]||"").length}function v(t,e,i){const o=/^\s*\d+\./.test(t[e]);let n=e,r="<"+(o?"ol":"ul")+">";for(;n<t.length;){const e=t[n];if(/^\s*$/.test(e)){n++;continue}const o=b(e),s=e.match(/^\s*([-*+]|\d+\.)\s+(.*)$/);if(!s||o<i)break;if(o>i){const e=v(t,n,o);r=r.replace(/<\/li>$/,e.html+"</li>"),n=e.next;continue}r+="<li>"+w(s[2])+"</li>",n++}return{html:r+"</"+(o?"ol":"ul")+">",next:n}}function x(t,e){const i=t=>t.trim().replace(/^\||\|$/g,"").split("|").map(t=>t.trim()),o=i(t[e]);let n=e+2,r="";for(;n<t.length&&/^\|.*\|\s*$/.test(t[n]);)r+="<tr>"+i(t[n]).map(t=>`<td>${w(t)}</td>`).join("")+"</tr>",n++;return{html:`<table class="rich-editor-table"><tbody>${"<tr>"+o.map(t=>`<td><b>${w(t)}</b></td>`).join("")+"</tr>"}${r}</tbody></table>`,next:n}}function w(t){return t.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,(t,e,i)=>`<img class="inserted-image" src="${E(i)}" alt="${E(e)}" style="max-width:100%;height:auto">`).replace(/([@#])\[([^\]]+)\]\(([^)]+)\)/g,(t,e,i,o)=>`<span class="mention" data-id="${E(o)}">${e}${C(i)}</span>`).replace(/\[([^\]]+)\]\(([^)]+)\)/g,(t,e,i)=>`<a href="${E(i)}" target="_blank" rel="noopener noreferrer">${C(e)}</a>`).replace(/\*\*([^*]+)\*\*/g,"<b>$1</b>").replace(/(^|[^*])\*([^*]+)\*/g,"$1<i>$2</i>").replace(/~~([^~]+)~~/g,"<s>$1</s>").replace(/`([^`]+)`/g,(t,e)=>"<code>"+C(e)+"</code>").replace(/\n/g,"<br>")}function C(t){return String(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function E(t){return String(t).replace(/"/g,"&quot;").replace(/</g,"&lt;")}function k(t){const e=document.createElement("div");return e.innerHTML=t||"",{type:"doc",content:[...e.childNodes].map(j).filter(Boolean)}}function j(t){if(3===t.nodeType){const e=t.textContent;return e?{text:e}:null}if(1!==t.nodeType)return null;const e={tag:t.tagName.toLowerCase()};if(t.attributes.length){e.attrs={};for(const i of t.attributes)e.attrs[i.name]=i.value}const i=[...t.childNodes].map(j).filter(Boolean);return i.length&&(e.content=i),e}function T(t){return(t&&t.content?t.content:Array.isArray(t)?t:[]).map(I).join("")}function I(t){if(null==t)return"";if(null!=t.text)return C(t.text);if(!t.tag)return"";const e=t.attrs?Object.entries(t.attrs).map(([t,e])=>` ${t}="${E(e)}"`).join(""):"",i=(t.content||[]).map(I).join("");return new Set(["img","hr","br","input"]).has(t.tag)?`<${t.tag}${e}>`:`<${t.tag}${e}>${i}</${t.tag}>`}const S=t=>`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">${t}</svg>`,N={bold:S('<path d="M6 4h8a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"/><path d="M6 12h9a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"/>'),italic:S('<line x1="19" x2="10" y1="4" y2="4"/><line x1="14" x2="5" y1="20" y2="20"/><line x1="15" x2="9" y1="4" y2="20"/>'),underline:S('<path d="M6 4v6a6 6 0 0 0 12 0V4"/><line x1="4" x2="20" y1="20" y2="20"/>'),strike:S('<path d="M16 4H9a3 3 0 0 0-2.83 4"/><path d="M14 12a4 4 0 0 1 0 8H6"/><line x1="4" x2="20" y1="12" y2="12"/>'),subscript:S('<path d="m4 5 8 8"/><path d="m12 5-8 8"/><path d="M20 19h-4c0-1.5.44-2 1.5-2.5S20 15.33 20 14c0-.47-.17-.93-.48-1.29a2.11 2.11 0 0 0-2.62-.44c-.42.24-.74.62-.9 1.07"/>'),superscript:S('<path d="m4 19 8-8"/><path d="m12 19-8-8"/><path d="M20 12h-4c0-1.5.44-2 1.5-2.5S20 8.33 20 7c0-.47-.17-.93-.48-1.29a2.11 2.11 0 0 0-2.62-.44c-.42.24-.74.62-.9 1.07"/>'),"align-left":S('<line x1="21" x2="3" y1="6" y2="6"/><line x1="15" x2="3" y1="12" y2="12"/><line x1="17" x2="3" y1="18" y2="18"/>'),"align-center":S('<line x1="21" x2="3" y1="6" y2="6"/><line x1="17" x2="7" y1="12" y2="12"/><line x1="19" x2="5" y1="18" y2="18"/>'),"align-right":S('<line x1="21" x2="3" y1="6" y2="6"/><line x1="21" x2="9" y1="12" y2="12"/><line x1="21" x2="7" y1="18" y2="18"/>'),"align-justify":S('<line x1="3" x2="21" y1="6" y2="6"/><line x1="3" x2="21" y1="12" y2="12"/><line x1="3" x2="21" y1="18" y2="18"/>'),"list-bullet":S('<line x1="8" x2="21" y1="6" y2="6"/><line x1="8" x2="21" y1="12" y2="12"/><line x1="8" x2="21" y1="18" y2="18"/><circle cx="3.5" cy="6" r="1" fill="currentColor" stroke="none"/><circle cx="3.5" cy="12" r="1" fill="currentColor" stroke="none"/><circle cx="3.5" cy="18" r="1" fill="currentColor" stroke="none"/>'),"list-ordered":S('<line x1="10" x2="21" y1="6" y2="6"/><line x1="10" x2="21" y1="12" y2="12"/><line x1="10" x2="21" y1="18" y2="18"/><path d="M4 6h1v4"/><path d="M4 10h2"/><path d="M6 18H4c0-1 2-2 2-3s-1-1.5-2-1"/>'),"list-alpha":S('<line x1="10" x2="21" y1="6" y2="6"/><line x1="10" x2="21" y1="12" y2="12"/><line x1="10" x2="21" y1="18" y2="18"/><path d="M4 10V8a1 1 0 0 1 2 0v2"/><path d="M4 9h2"/><path d="M4 14h1.5a1 1 0 0 1 0 2H4l2-2"/>'),"list-roman":S('<line x1="10" x2="21" y1="6" y2="6"/><line x1="10" x2="21" y1="12" y2="12"/><line x1="10" x2="21" y1="18" y2="18"/><path d="M5 7v3"/><path d="M4 14h2l-1 4"/>'),list:S('<line x1="8" x2="21" y1="6" y2="6"/><line x1="8" x2="21" y1="12" y2="12"/><line x1="8" x2="21" y1="18" y2="18"/><circle cx="3.5" cy="6" r="1" fill="currentColor" stroke="none"/><circle cx="3.5" cy="12" r="1" fill="currentColor" stroke="none"/><circle cx="3.5" cy="18" r="1" fill="currentColor" stroke="none"/>'),"indent-increase":S('<polyline points="3 8 7 12 3 16"/><line x1="21" x2="11" y1="6" y2="6"/><line x1="21" x2="11" y1="12" y2="12"/><line x1="21" x2="11" y1="18" y2="18"/>'),"indent-decrease":S('<polyline points="7 8 3 12 7 16"/><line x1="21" x2="11" y1="6" y2="6"/><line x1="21" x2="11" y1="12" y2="12"/><line x1="21" x2="11" y1="18" y2="18"/>'),image:S('<rect width="18" height="18" x="3" y="3" rx="2" ry="2"/><circle cx="9" cy="9" r="2"/><path d="m21 15-3.1-3.1a2 2 0 0 0-2.8 0L6 21"/>'),video:S('<path d="m22 8-6 4 6 4V8Z"/><rect width="14" height="12" x="2" y="6" rx="2" ry="2"/>'),file:S('<path d="m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48"/>'),table:S('<path d="M12 3v18"/><rect width="18" height="18" x="3" y="3" rx="2"/><path d="M3 9h18"/><path d="M3 15h18"/>'),"table-profile":S('<path d="M15 3v18"/><rect width="18" height="18" x="3" y="3" rx="2"/><path d="M21 9H3"/><path d="M21 15H3"/>'),"add-row-above":S('<rect x="3" y="13" width="18" height="8" rx="2"/><line x1="12" x2="12" y1="3" y2="9"/><line x1="9" x2="15" y1="6" y2="6"/>'),"add-row-below":S('<rect x="3" y="3" width="18" height="8" rx="2"/><line x1="12" x2="12" y1="15" y2="21"/><line x1="9" x2="15" y1="18" y2="18"/>'),"add-col-left":S('<rect x="13" y="3" width="8" height="18" rx="2"/><line x1="3" x2="9" y1="12" y2="12"/><line x1="6" x2="6" y1="9" y2="15"/>'),"add-col-right":S('<rect x="3" y="3" width="8" height="18" rx="2"/><line x1="15" x2="21" y1="12" y2="12"/><line x1="18" x2="18" y1="9" y2="15"/>'),"delete-row":S('<rect x="3" y="9" width="18" height="6" rx="2"/><line x1="9" x2="15" y1="12" y2="12"/>'),"delete-col":S('<rect x="9" y="3" width="6" height="18" rx="2"/><line x1="12" x2="12" y1="9" y2="15"/>'),"delete-table":S('<path d="M3 6h18"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"/><path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/><line x1="10" x2="10" y1="11" y2="17"/><line x1="14" x2="14" y1="11" y2="17"/>'),color:S('<path d="M5.5 19 12 5l6.5 14"/><path d="M8 14h8"/>'),background:S('<path d="m9 11-6 6v3h9l3-3"/><path d="m22 12-4.6 4.6a2 2 0 0 1-2.8 0l-5.2-5.2a2 2 0 0 1 0-2.8L14 4"/>'),"no-color":S('<circle cx="12" cy="12" r="9"/><line x1="5.6" x2="18.4" y1="5.6" y2="18.4"/>'),"custom-color":S('<path d="M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10c.93 0 1.65-.75 1.65-1.69 0-.43-.18-.83-.44-1.12-.29-.29-.44-.65-.44-1.13a1.64 1.64 0 0 1 1.67-1.67h2c3.05 0 5.55-2.5 5.55-5.55C22 6 17.5 2 12 2z"/><circle cx="8.5" cy="7.5" r="1" fill="currentColor" stroke="none"/><circle cx="6.5" cy="12.5" r="1" fill="currentColor" stroke="none"/><circle cx="13.5" cy="6.5" r="1" fill="currentColor" stroke="none"/><circle cx="17.5" cy="10.5" r="1" fill="currentColor" stroke="none"/>'),undo:S('<path d="M9 14 4 9l5-5"/><path d="M4 9h10.5a5.5 5.5 0 0 1 0 11H11"/>'),redo:S('<path d="m15 14 5-5-5-5"/><path d="M20 9H9.5a5.5 5.5 0 0 0 0 11H13"/>'),link:S('<path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/>'),emoji:S('<circle cx="12" cy="12" r="10"/><path d="M8 14s1.5 2 4 2 4-2 4-2"/><line x1="9" x2="9.01" y1="9" y2="9"/><line x1="15" x2="15.01" y1="9" y2="9"/>'),tag:S('<path d="M12.6 2.6A2 2 0 0 0 11.2 2H4a2 2 0 0 0-2 2v7.2a2 2 0 0 0 .6 1.4l8.7 8.7a2.4 2.4 0 0 0 3.4 0l6.6-6.6a2.4 2.4 0 0 0 0-3.4z"/><circle cx="7.5" cy="7.5" r="1" fill="currentColor" stroke="none"/>'),import:S('<path d="M12 3v12"/><path d="m8 11 4 4 4-4"/><path d="M8 5H4a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-4"/>'),code:S('<polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/>'),"code-view":S('<path d="m18 16 4-4-4-4"/><path d="m6 8-4 4 4 4"/><path d="m14.5 4-5 16"/>'),"clear-format":S('<path d="M4 7V4h16v3"/><path d="M5 20h6"/><path d="M13 4 8 20"/><path d="m15 15 5 5"/><path d="m20 15-5 5"/>'),"horizontal-rule":S('<path d="M5 12h14"/>'),find:S('<circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/>'),"chevron-up":S('<path d="m18 15-6-6-6 6"/>'),"chevron-down":S('<path d="m6 9 6 6 6-6"/>'),close:S('<path d="M18 6 6 18"/><path d="m6 6 12 12"/>'),"text-direction":S('<path d="M8 3 4 7l4 4"/><path d="M4 7h16"/><path d="m16 21 4-4-4-4"/><path d="M20 17H4"/>'),check:S('<polyline points="20 6 9 17 4 12"/>'),dropdown:S('<path d="m6 9 6 6 6-6"/>'),more:S('<circle cx="12" cy="12" r="1.4" fill="currentColor" stroke="none"/><circle cx="19" cy="12" r="1.4" fill="currentColor" stroke="none"/><circle cx="5" cy="12" r="1.4" fill="currentColor" stroke="none"/>'),theme:S('<circle cx="12" cy="12" r="4"/><path d="M12 2v2"/><path d="M12 20v2"/><path d="m4.9 4.9 1.4 1.4"/><path d="m17.7 17.7 1.4 1.4"/><path d="M2 12h2"/><path d="M20 12h2"/><path d="m6.3 17.7-1.4 1.4"/><path d="m19.1 4.9-1.4 1.4"/>'),heading:S('<path d="M4 12h8"/><path d="M4 18V6"/><path d="M12 18V6"/><path d="m17 12 3-2v8"/>'),"font-family":S('<polyline points="4 7 4 4 20 4 20 7"/><line x1="9" x2="15" y1="20" y2="20"/><line x1="12" x2="12" y1="4" y2="20"/>'),"line-height":S('<path d="M3 5h12"/><path d="M3 12h12"/><path d="M3 19h12"/><path d="M19 5v14"/><path d="m16.5 7.5 2.5-2.5 2.5 2.5"/><path d="m16.5 16.5 2.5 2.5 2.5-2.5"/>'),capitalization:S('<path d="M4 18 8 8l4 10"/><path d="M5.5 14h5"/><path d="M16 18a3 3 0 1 0 0-6 3 3 0 0 0-3 3v3"/><path d="M19 12v6"/>'),"text-size":S('<path d="M21 14h-5"/><path d="M16 16v-3.5a2.5 2.5 0 0 1 5 0V16"/><path d="M4.5 13h6"/><path d="m3 16 4.5-9 4.5 9"/>')};class L{static getIcon(t){return N[t]||""}static createIconElement(t,e={}){const i=document.createElement("span");return i.className=`icon icon-${t}`,i.style.display="inline-flex",i.style.alignItems="center",i.style.justifyContent="center",i.style.width=e.width||"16px",i.style.height=e.height||"16px",i.style.verticalAlign="middle",i.innerHTML=this.getIcon(t),i}static hasIcon(t){return t in N}static getIconNames(){return Object.keys(N)}}class A{static DEFAULTS={placeholder:"Start typing...",theme:"light",height:400,width:800,maxWidth:1200,maxHeight:800,content:null,features:{emoji:!0,image:!0,table:!0,wordCount:!0,breadcrumb:!0}};static currentInstance=null;static instances=new Map;constructor(e,i={}){this.options={...A.DEFAULTS,...i,features:{...A.DEFAULTS.features,...i.features||{}}},this.root="string"==typeof e?document.querySelector(e):e,this.modules=new Map,this.formats=new Map,this.registry=t,this.events=new Map,this.toolbarBtns={},this.statusbarEls={},this.dropdownMenus={},this.popupInstances=new Map,A.currentInstance=this;const o=this.generateInstanceId();this.instanceId=o,A.instances.set(o,this),this.init()}generateInstanceId(){return"editor_"+Date.now()+"_"+Math.random().toString(36).substr(2,9)}init(){this.createStructure(),this.loadModules(),this.loadFormats(),this.setupEventListeners(),this.updateStatusbar()}createStructure(){this.wrapper=document.createElement("div"),this.wrapper.className="yjd-rich-editor";const t=t=>"number"==typeof t?t+"px":t;this.wrapper.style.width=t(this.options.width),this.wrapper.style.maxWidth=t(this.options.maxWidth),this.wrapper.style.minHeight=t(this.options.height),this.wrapper.style.maxHeight=t(this.options.maxHeight),this.wrapper.style.position="relative",this.editor=document.createElement("div"),this.editor.className="rich-editor-area",this.editor.contentEditable=!0,this.editor.setAttribute("data-placeholder",this.options.placeholder),this.editor.setAttribute("role","textbox"),this.editor.setAttribute("aria-multiline","true"),this.editor.setAttribute("aria-label",this.options.ariaLabel||this.options.placeholder||"Rich text editor"),this.options.direction&&this.editor.setAttribute("dir","rtl"===this.options.direction?"rtl":"ltr"),i("defaultParagraphSeparator","p"),this.editor.innerHTML=this.getDefaultContent(),this.wrapper.appendChild(this.editor),this.popupContainer=document.createElement("div"),this.popupContainer.className="rich-editor-popup-container",this.popupContainer.style.position="absolute",this.popupContainer.style.top="0",this.popupContainer.style.left="0",this.popupContainer.style.width="100%",this.popupContainer.style.height="100%",this.popupContainer.style.pointerEvents="none",this.popupContainer.style.zIndex="1000",this.wrapper.appendChild(this.popupContainer),(this.options.features.wordCount||this.options.features.breadcrumb)&&this.createStatusbar(),this.root.appendChild(this.wrapper),this.updatePlaceholderVisibility()}isHtmlContent(t){if(!t||"string"!=typeof t)return!1;const e=t.trim();return[/<[^>]+>/,/&[a-zA-Z]+;/,/&#\d+;/].some(t=>t.test(e))}wrapTextInParagraph(t){if(!t||"string"!=typeof t)return"<p><br></p>";const e=t.trim();return this.isHtmlContent(e)?e:""===e?"<p><br></p>":`<p>${e}</p>`}getDefaultContent(){if(this.options.content)return this.wrapTextInParagraph(this.options.content);const t=this._getAutosaved();return null!=t&&""!==t?t:""}createStatusbar(){this.statusbar=document.createElement("div"),this.statusbar.className="rich-editor-statusbar",this.statusbarEls.breadcrumb=document.createElement("span"),this.statusbarEls.breadcrumb.className="rich-editor-breadcrumb",this.statusbarEls.wordcount=document.createElement("span"),this.statusbarEls.wordcount.className="wordcount",this.statusbar.appendChild(this.statusbarEls.breadcrumb),this.statusbar.appendChild(this.statusbarEls.wordcount),this.wrapper.appendChild(this.statusbar)}loadModules(){let t;t=this.options.toolbar||this.options.toolbar1||this.options.toolbar2?this.options.modules||["toolbar","history"]:this.options.modules||["toolbar","history","block-toolbar","table-toolbar","code-view","theme-switcher","resize-handles","find-replace","slash-menu","mention"],this.options.mention&&!t.includes("mention")&&t.push("mention"),t.forEach(t=>{const e=this.registry.get(`modules/${t}`);if(e){const i=new e(this,"toolbar"===t?this.options:this.options[t]||this.options);if(this.modules.set(t,i),"toolbar"===t&&i.getContainer){const t=i.getContainer();this.wrapper.insertBefore(t,this.editor),i.on("toolbar-click",t=>{this.handleToolbarClick(t)})}}})}loadFormats(){let t;t=this.options.toolbar||this.options.toolbar1||this.options.toolbar2?this.options.formats||["bold","italic","underline","strike"]:this.options.formats||["bold","italic","underline","strike","subscript","superscript","color","background","text-align","text-size","link","code","h1","h2","h3","h4","h5","h6","paragraph","pre"],t.forEach(t=>{const e=this.registry.get(`formats/${t}`);e&&this.formats.set(t,e)})}setupEventListeners(){if(this._markActive=()=>{A.currentInstance=this},this.wrapper.addEventListener("pointerdown",this._markActive,!0),this.wrapper.addEventListener("focusin",this._markActive,!0),this.editor.addEventListener("input",()=>{this.updatePlaceholderVisibility(),this.onContentChange()}),this._onDocSelectionChange=()=>{(document.activeElement===this.editor||this.editor.contains(document.activeElement))&&this._scheduleSelectionUpdate()},document.addEventListener("selectionchange",this._onDocSelectionChange),this.editor.addEventListener("mouseup",()=>this._scheduleSelectionUpdate()),this.editor.addEventListener("click",()=>{this.ensureEditorHasContent()}),this.editor.addEventListener("contextmenu",t=>{}),this.editor.addEventListener("keydown",t=>{if(!t.ctrlKey&&!t.metaKey||t.altKey)return;const e={b:"bold",i:"italic",u:"underline",k:"link"}[t.key.toLowerCase()];e&&(t.shiftKey||(t.preventDefault(),this.toggleFormat(e)))}),this.editor.addEventListener("keydown",t=>{"Delete"!==t.key&&"Backspace"!==t.key||setTimeout(()=>{this.ensureEditorHasContent(),this.updatePlaceholderVisibility()},0)}),this.editor.addEventListener("paste",t=>{this.handlePaste(t)}),this.editor.addEventListener("dragover",t=>{t.dataTransfer&&Array.from(t.dataTransfer.types||[]).includes("Files")&&(t.preventDefault(),this.editor.classList.add("yjd-drag-over"))}),this.editor.addEventListener("dragleave",t=>{t.relatedTarget&&this.editor.contains(t.relatedTarget)||this.editor.classList.remove("yjd-drag-over")}),this.editor.addEventListener("drop",t=>{this.editor.classList.remove("yjd-drag-over");const e=t.dataTransfer,i=e&&e.files?Array.from(e.files):[],o=i.find(t=>t.type&&t.type.startsWith("image/"));if(o)return t.preventDefault(),this.placeCaretAtPoint(t.clientX,t.clientY),void this.insertImageFile(o);const n=i.find(t=>t&&t.name);if(n&&this.options.file)return t.preventDefault(),this.placeCaretAtPoint(t.clientX,t.clientY),void this.insertFileAttachment(n);setTimeout(()=>{this.ensureEditorHasContent(),this.updatePlaceholderVisibility()},0)}),this.options.maxLength&&this.editor.addEventListener("beforeinput",t=>{if(!t.inputType||!t.inputType.startsWith("insert"))return;if("insertFromPaste"===t.inputType)return;const e=t.data?t.data.length:1;this._remainingChars()<e&&t.preventDefault()}),!1!==this.options.markdown&&this.editor.addEventListener("keydown",t=>{" "!==t.key||t.ctrlKey||t.metaKey||t.altKey||this.handleMarkdownShortcut(t)}),this.options.submit&&"function"==typeof this.options.submit.onEnter){const t=this.options.submit;this.editor.addEventListener("keydown",e=>{"Enter"!==e.key||e.isComposing||e.shiftKey||this.isMenuOpen()||(e.preventDefault(),t.onEnter(this.getContent(),this))})}this.editor.addEventListener("cut",()=>{setTimeout(()=>{this.ensureEditorHasContent(),this.updatePlaceholderVisibility()},0)}),setTimeout(()=>{this.ensureEditorHasContent(),this.updatePlaceholderVisibility(),this.updateHistoryButtons(),this.focus()},100),this.editor.addEventListener("focus",()=>{setTimeout(()=>{this.ensureEditorHasContent(),this.updatePlaceholderVisibility()},0)})}onContentChange(){this.ensureEditorHasContent(),this._emitChange()}_emitChange(){this.modules.forEach(t=>{"function"==typeof t.onContentChange&&t.onContentChange()}),this.updateStatusbar();const t=this.getContent();if(this.options.onChange&&"function"==typeof this.options.onChange&&this.options.onChange(t),this._scheduleAutosave(t),this.options.maxContentSize){const e=t.length,i=e>this.options.maxContentSize;i&&!this._overflowed?(this._overflowed=!0,this.emit("content:overflow",{size:e,max:this.options.maxContentSize})):i||(this._overflowed=!1)}this.emit("change",t),this.emit("text-change",t)}ensureEditorHasContent(){if(!this.isEditorEmpty())return;const t=this.isSelectionInEditableArea(window.getSelection());if("<p><br></p>"!==this.editor.innerHTML){const t=document.createElement("p");t.innerHTML="<br>",this.editor.innerHTML="",this.editor.appendChild(t),this.setCursorToElement(t),this.editor.focus()}(t||document.activeElement===this.editor)&&this._clearStickyInlineFormats(),this.updateToolbarButtonStates(),this.updateStatusbar()}_clearStickyInlineFormats(){["bold","italic","underline","strikeThrough"].forEach(t=>{n(t)&&i(t)})}ensureParagraphForEditing(){const t=this.editor.children;if(0===t.length){const t=document.createElement("p");return t.innerHTML="<br>",this.editor.appendChild(t),void this.setCursorToElement(t)}const e=t[t.length-1];if(!["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","PRE","ARTICLE","SECTION","MAIN","ASIDE"].includes(e.tagName)){const t=document.createElement("p");t.innerHTML="<br>",this.editor.appendChild(t)}}isEditorEmpty(){const t=this.editor.textContent;return(!t||""===t.replace(/\u200B/g,"").trim())&&!this.editor.querySelector("img, table, hr, video, iframe, audio, figure")}setCursorToElement(t){const e=document.createRange(),i=window.getSelection();t.firstChild&&t.firstChild.nodeType===Node.TEXT_NODE?e.setStart(t.firstChild,0):e.setStart(t,0),e.collapse(!0),i.removeAllRanges(),i.addRange(e)}_scheduleSelectionUpdate(){this._selUpdateQueued||(this._selUpdateQueued=!0,requestAnimationFrame(()=>{this._selUpdateQueued=!1,this.onSelectionChange()}))}onSelectionChange(){const t=window.getSelection(),e=t.rangeCount>0?t.getRangeAt(0):null,i=this.isSelectionInEditableArea(t);i&&(A.currentInstance=this,e&&!e.collapsed&&(this._lastRange=e.cloneRange())),this.modules.forEach(t=>{"function"==typeof t.onSelectionChange&&t.onSelectionChange(e,i)}),this.updateToolbarButtonStates(),this.updateToolbarAccessibility(i),this.updateStatusbar()}isSelectionInEditableArea(t){if(!t||0===t.rangeCount)return!1;const e=t.getRangeAt(0),i=e.startContainer,o=e.endContainer,n=this.isNodeInEditableArea(i),r=this.isNodeInEditableArea(o);return n&&r}isNodeInEditableArea(t){if(!t)return!1;let e=t.nodeType===Node.TEXT_NODE?t.parentNode:t;for(;e&&e!==document.body;){if(e===this.editor||e.classList&&e.classList.contains("rich-editor-area"))return!0;e=e.parentNode}return!1}updateToolbarAccessibility(t){const e=this.getModule("toolbar");if(!e)return;["bold","italic","underline","strike","subscript","superscript","color","background","link","table","heading","font-family","line-height","capitalization","text-align","list","indent-increase","indent-decrease","text-size"].forEach(i=>{e.setButtonDisabled(i,!t)});["more","undo","redo","code-view","theme"].forEach(t=>{e.setButtonDisabled(t,!1)})}updateStatusbar(){if(!this.statusbar)return;const t=window.getSelection();if(t){if(this.statusbarEls.breadcrumb&&this.options.features.breadcrumb){const e=t.anchorNode;if(e&&this.editor.contains(e)){const t=[];let i=3===e?.nodeType?e.parentElement:e;for(;i&&i!==this.editor&&i!==document.body;){if(i.tagName){let e=i.tagName.toLowerCase();if(i.className&&"string"==typeof i.className){const t=i.className.trim();t&&(e+="."+t.split(" ").join("."))}i.id&&(e+="#"+i.id),t.unshift(e)}i=i.parentElement}this.statusbarEls.breadcrumb.textContent=t.length>0?t.join(" > "):"editor"}else this.statusbarEls.breadcrumb.textContent="editor"}if(this.statusbarEls.wordcount&&this.options.features.wordCount){let t;const e=this.getModule("code-view");if(e&&"function"==typeof e.isInCodeView&&e.isInCodeView()){const i=document.createElement("div");i.innerHTML=e.getCurrentContent?e.getCurrentContent():"",t=i.textContent||""}else t=this.editor.textContent||"";const i=t.trim()?t.trim().split(/\s+/).length:0,o=t.length;let n=`${i} words, ${o} chars (${t.replace(/\s/g,"").length} no spaces)`;this.options.maxLength&&(n+=` • ${Math.max(0,this.options.maxLength-o)} left`),this.statusbarEls.wordcount.textContent=n}}}focus(){this.editor&&this.editor.focus()}getContent(){return this.editor.innerHTML}setContent(t){const e=this.wrapTextInParagraph(t);this.editor.innerHTML=e,this.onContentChange()}getHTML(){return this.getContent()}setHTML(t){this.setContent(d(t||""))}getJSON(){return k(this.getContent())}setJSON(t){this.setContent(d(T(t)))}getMarkdown(){return p(this.getContent())}setMarkdown(t){this.setContent(d(y(t||"")))}getText(){return this.editor.textContent||""}isEmpty(){return this.isEditorEmpty()}clear(){this.editor.innerHTML="<p><br></p>",this.onContentChange(),this.updatePlaceholderVisibility()}insertText(t){"string"==typeof t&&(this.focus(),i("insertText",t),this.onContentChange())}insertHTML(t){"string"==typeof t&&(this.focus(),i("insertHTML",d(t)),this.onContentChange())}handlePaste(t){const e=t.clipboardData||window.clipboardData;if(!e)return;const o=(e.items?Array.from(e.items):[]).find(t=>"file"===t.kind&&t.type&&t.type.startsWith("image/"));if(o){const e=o.getAsFile();if(e)return t.preventDefault(),void this.insertImageFile(e)}let n=e.getData("text/html"),r=e.getData("text/plain");if(n||r){if(t.preventDefault(),this.options.maxLength){const t=this._remainingChars();if(t<=0)return;i("insertText",(r||"").slice(0,t))}else!this.options.pasteAsPlainText&&n?i("insertHTML",d(n)):r&&i("insertText",r);setTimeout(()=>{this.ensureEditorHasContent(),this.updatePlaceholderVisibility(),this.onContentChange()},0)}}_remainingChars(){if(!this.options.maxLength)return 1/0;const t=window.getSelection(),e=t&&!t.isCollapsed?t.toString().length:0;return this.options.maxLength-(this.getText().length-e)}insertImageFile(t){if(!t||!t.type||!t.type.startsWith("image/"))return;const e=this.options.image||{};if(e.accept&&"image/*"!==e.accept){if(!e.accept.split(",").some(e=>(e=e.trim()).endsWith("/*")?t.type.startsWith(e.slice(0,-1)):t.type===e))return void this.emit("image:error",{file:t,reason:"type"})}if(e.maxSize&&t.size>e.maxSize)return void this.emit("image:error",{file:t,reason:"size"});const o=(t,e="")=>{const i=this.registry.get("formats/image");if(i&&"function"==typeof i.create){const o=i.create(t);return o?(e&&o.setAttribute("data-state",e),o):null}return null};if("function"!=typeof e.upload){const e=new FileReader;return e.onload=t=>{const e=(o(t.target.result)||{}).outerHTML||`<img src="${t.target.result}" class="inserted-image" style="max-width:100%" contenteditable="false">`;this.focus(),i("insertHTML",e),this.onContentChange()},void e.readAsDataURL(t)}const n="rte-up-"+Math.round(performance.now())+"-"+(this._upCounter=(this._upCounter||0)+1),r=(t.name||"image").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),s=`<span class="yjd-upload" id="${n}" contenteditable="false" data-state="uploading"><span class="yjd-spinner" aria-hidden="true"></span><span class="yjd-upload-label">${r}</span></span>`;this.focus(),i("insertHTML",s),this.emit("image:upload",{file:t}),Promise.resolve(e.upload(t)).then(e=>{const i=this.editor.querySelector("#"+n);if(i){if(e){const n=o(e);n?i.replaceWith(n):i.remove(),this.emit("image:uploaded",{file:t,url:e})}else i.remove();this.onContentChange()}}).catch(e=>{const i=this.editor.querySelector("#"+n);i&&i.remove(),this.emit("image:error",{file:t,reason:"upload",error:e}),this.onContentChange()})}static formatBytes(t){if(!t&&0!==t)return"";const e=["B","KB","MB","GB"];let i=0,o=t;for(;o>=1024&&i<e.length-1;)o/=1024,i++;return`${o>=10||0===i?Math.round(o):o.toFixed(1)} ${e[i]}`}openFileAttachmentPicker(){const t=this.options.file||{},e=window.getSelection(),i=e&&e.rangeCount?e.getRangeAt(0).cloneRange():null,o=document.createElement("input");o.type="file",o.accept=t.accept||"*/*",o.style.display="none",o.addEventListener("change",()=>{const t=o.files&&o.files[0];if(t){this.focus();const e=window.getSelection();if(i)e.removeAllRanges(),e.addRange(i);else if(!e.rangeCount||!this.editor.contains(e.anchorNode)){const t=document.createRange();t.selectNodeContents(this.editor),t.collapse(!1),e.removeAllRanges(),e.addRange(t)}this.insertFileAttachment(t)}o.remove()}),document.body.appendChild(o),o.click()}insertFileAttachment(t){if(!t)return;const e=this.options.file||{};if(e.accept&&"*/*"!==e.accept){const i=(t.name||"").toLowerCase();if(!e.accept.split(",").some(e=>!!(e=e.trim().toLowerCase())&&(e.startsWith(".")?i.endsWith(e):e.endsWith("/*")?(t.type||"").startsWith(e.slice(0,-1)):t.type===e)))return void this.emit("file:error",{file:t,reason:"type"})}if(e.maxSize&&t.size>e.maxSize)return void this.emit("file:error",{file:t,reason:"size"});const o=L&&"function"==typeof L.getIcon&&L.getIcon("file")||"",n=t=>String(null==t?"":t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),r=(e,i={},r="")=>{const s=i.name||t.name||"file",a=null!=i.size?i.size:A.formatBytes(t.size),l=document.createElement("a");l.className="yjd-file-chip",l.setAttribute("contenteditable","false"),l.setAttribute("href",e||"#"),l.setAttribute("target","_blank"),l.setAttribute("rel","noopener noreferrer"),l.setAttribute("data-name",s),a&&l.setAttribute("data-size",a),r&&l.setAttribute("data-state",r);const c="uploading"===r?'<span class="yjd-spinner" aria-hidden="true"></span>':o;return l.innerHTML=`<span class="yjd-file-ico" contenteditable="false">${c}</span><span class="yjd-file-name">${n(s)}</span>`+(a?`<span class="yjd-file-size">${n(a)}</span>`:""),l},s=t=>{this.focus(),i("insertHTML",t+"&nbsp;"),this.onContentChange()};if("function"!=typeof e.upload){const e=new FileReader;return e.onload=t=>s(r(t.target.result).outerHTML),e.onerror=()=>this.emit("file:error",{file:t,reason:"read"}),void e.readAsDataURL(t)}const a="rte-file-"+Math.round(performance.now())+"-"+(this._fileCounter=(this._fileCounter||0)+1),l=r("#",{},"uploading");l.id=a,l.style.opacity="0.6",s(l.outerHTML),this.emit("file:upload",{file:t}),Promise.resolve(e.upload(t)).then(e=>{const i=this.editor.querySelector("#"+a);if(!i)return;const n="string"==typeof e?e:e&&e.url;if(!n)return i.remove(),void this.onContentChange();const r=e&&e.name||i.getAttribute("data-name"),s=e&&e.size||i.getAttribute("data-size");i.setAttribute("href",n),i.setAttribute("data-name",r),s&&i.setAttribute("data-size",s),i.style.opacity="",i.removeAttribute("data-state"),i.removeAttribute("id");const l=i.querySelector(".yjd-file-ico");l&&(l.innerHTML=o);const c=i.querySelector(".yjd-file-name"),d=i.querySelector(".yjd-file-size");c&&(c.textContent=r),d&&s&&(d.textContent=s),this.emit("file:uploaded",{file:t,url:n,name:r,size:s}),this.onContentChange()}).catch(e=>{const i=this.editor.querySelector("#"+a);i&&i.remove(),this.emit("file:error",{file:t,reason:"upload",error:e}),this.onContentChange()})}placeCaretAtPoint(t,e){let i=null;if(document.caretRangeFromPoint)i=document.caretRangeFromPoint(t,e);else if(document.caretPositionFromPoint){const o=document.caretPositionFromPoint(t,e);o&&(i=document.createRange(),i.setStart(o.offsetNode,o.offset))}if(i){i.collapse(!0);const t=window.getSelection();t.removeAllRanges(),t.addRange(i)}}handleMarkdownShortcut(t){const e=window.getSelection();if(!e||!e.isCollapsed||!e.rangeCount)return;const o=e.getRangeAt(0);let n=o.startContainer;for(n=n.nodeType===Node.TEXT_NODE?n.parentElement:n;n&&n!==this.editor&&"P"!==n.tagName&&"DIV"!==n.tagName;)n=n.parentElement;if(!n||n===this.editor)return;const r=document.createRange();r.selectNodeContents(n),r.setEnd(o.startContainer,o.startOffset);const s=r.toString(),a={"#":"h1","##":"h2","###":"h3","####":"h4","#####":"h5","######":"h6",">":"blockquote"}[s],l="-"===s||"*"===s?"ul":/^\d+\.$/.test(s)?"ol":null;if(!a&&!l)return;t.preventDefault();const c=this.getModule("history");if(c&&"function"==typeof c.saveBeforeFormat&&c.saveBeforeFormat(),r.deleteContents(),a){const t=document.createElement(a);for(;n.firstChild;)t.appendChild(n.firstChild);""!==t.textContent||t.querySelector("*")||(t.innerHTML="<br>"),n.replaceWith(t);const i=document.createRange();i.selectNodeContents(t),i.collapse(!0),e.removeAllRanges(),e.addRange(i)}else{const t=document.createRange();t.selectNodeContents(n),t.collapse(!0),e.removeAllRanges(),e.addRange(t),i("ul"===l?"insertUnorderedList":"insertOrderedList")}this._emitChange(),this.updatePlaceholderVisibility()}setDirection(t){const e="rtl"===t?"rtl":"ltr";this.editor.setAttribute("dir",e);const i=this.getModule("toolbar");i&&i.setButtonActive("text-direction","rtl"===e)}getDirection(){return"rtl"===this.editor.getAttribute("dir")?"rtl":"ltr"}toggleDirection(){this.setDirection("rtl"===this.getDirection()?"ltr":"rtl")}_autosaveCfg(){if(void 0!==this._autosaveMemo)return this._autosaveMemo;const t=this.options.autosave;return t?(this._autosaveMemo={key:"object"==typeof t&&t.key?t.key:"yjd-autosave",debounce:"object"==typeof t&&t.debounce?t.debounce:1e3},this._autosaveMemo):(this._autosaveMemo=null,null)}_getAutosaved(){const t=this._autosaveCfg();if(!t)return null;try{return localStorage.getItem(t.key)}catch(t){return null}}_scheduleAutosave(t){const e=this._autosaveCfg();e&&(clearTimeout(this._autosaveTimer),this._autosaveTimer=setTimeout(()=>{try{localStorage.setItem(e.key,t)}catch(t){}},e.debounce))}clearAutosave(){const t=this._autosaveCfg();if(t)try{localStorage.removeItem(t.key)}catch(t){}}isMenuOpen(){const t=this.modules.get("mention");if(t&&t.isOpen)return!0;const e=this.modules.get("slash-menu");if(e&&e.isOpen)return!0;return[...document.querySelectorAll(".yjd-mention-menu, .yjd-slash-menu, .emoji-picker-popup.visible, .link-popup, .image-popup, .video-popup, .tag-popup")].some(t=>!(!t.offsetParent&&"fixed"!==getComputedStyle(t).position)&&"none"!==getComputedStyle(t).display)}clearFormatting(){const t=this.getModule("history");t&&"function"==typeof t.saveBeforeFormat&&t.saveBeforeFormat(),this.focus(),i("removeFormat"),i("unlink"),this.onContentChange(),this.updateToolbarButtonStates()}setBlockType(t){const e=window.getSelection();if(!e||!e.rangeCount)return;let o=e.getRangeAt(0).startContainer;o=o.nodeType===Node.TEXT_NODE?o.parentElement:o;const n=/^(P|DIV|H[1-6]|BLOCKQUOTE|PRE|LI)$/;for(;o&&o!==this.editor&&!n.test(o.tagName);)o=o.parentElement;if(!o||o===this.editor)return;const r=this.getModule("history");if(r&&"function"==typeof r.saveBeforeFormat&&r.saveBeforeFormat(),"ul"===t||"ol"===t){const n=document.createRange();n.selectNodeContents(o),n.collapse(!0),e.removeAllRanges(),e.addRange(n),i("ul"===t?"insertUnorderedList":"insertOrderedList")}else{const i=document.createElement(t);for(;o.firstChild;)i.appendChild(o.firstChild);""!==i.textContent||i.querySelector("*")||(i.innerHTML="<br>"),o.replaceWith(i);const n=document.createRange();n.selectNodeContents(i),n.collapse(!1),e.removeAllRanges(),e.addRange(n)}this._emitChange(),this.updatePlaceholderVisibility()}insertHorizontalRule(){const t=this.getModule("history");t&&"function"==typeof t.saveBeforeFormat&&t.saveBeforeFormat(),this.focus(),i("insertHorizontalRule"),this.onContentChange()}_isBlockEmpty(t){return!t||(!t.querySelector||!t.querySelector("img, table, hr, video, iframe, audio, figure"))&&""===(t.textContent||"").replace(/\u200B/g,"").trim()}insertBlock(t){const e=window.getSelection();let i=null;if(e&&e.rangeCount){const t=e.getRangeAt(0);t.collapsed||t.deleteContents();let o=t.startContainer;for(o=o.nodeType===Node.TEXT_NODE?o.parentNode:o;o&&o!==this.editor&&o.parentNode!==this.editor;)o=o.parentNode;o&&o.parentNode===this.editor&&(i=o)}if(i){const e=this._isBlockEmpty(i);i.nextSibling?this.editor.insertBefore(t,i.nextSibling):this.editor.appendChild(t),e&&i.remove()}else this.editor.appendChild(t);if(!t.nextSibling){const t=document.createElement("p");t.innerHTML="<br>",this.editor.appendChild(t)}}setReadOnly(t){this._readOnly=!!t,this.editor.contentEditable=this._readOnly?"false":"true",this.editor.setAttribute("aria-readonly",this._readOnly?"true":"false"),this.wrapper.classList.toggle("read-only",this._readOnly);const e=this.getModule("toolbar");e&&e.buttons&&e.buttons.forEach((t,i)=>{e.setButtonDisabled(i,this._readOnly)})}isReadOnly(){return!!this._readOnly}getModule(t){return this.modules.get(t)}getFormat(t){return this.formats.get(t)}register(t,e,i=!1){this.registry.register(t,e,i)}handleToolbarClick(t){const{command:e,button:i,value:o}=t;A.currentInstance,A.currentInstance=this,this.emit("toolbar-click",t);if(["more","undo","redo","code-view","theme","text-direction","find"].includes(e))switch(e){case"more":case"code-view":case"find":return;case"undo":return void this.undo();case"redo":return void this.redo();case"text-direction":return void this.toggleDirection()}const n=window.getSelection();if(this.isSelectionInEditableArea(n))switch(e){case"bold":case"italic":case"underline":case"strike":case"subscript":case"superscript":case"color":case"background":case"link":case"table":case"heading":case"font-family":case"line-height":case"capitalization":case"text-align":case"text-size":case"list":case"indent-increase":case"indent-decrease":case"emoji":case"image":case"video":case"tag":case"import":this.toggleFormat(e);break;case"file":this.openFileAttachmentPicker();break;case"clear-format":this.clearFormatting();break;case"horizontal-rule":this.insertHorizontalRule()}}toggleFormat(t){const e=this.getModule("history");e&&"function"==typeof e.saveBeforeFormat&&e.saveBeforeFormat();const i={bold:"bold",italic:"italic",underline:"underline",strike:"strike",subscript:"subscript",superscript:"superscript",color:"color",background:"background",link:"link",table:"table",heading:"heading","font-family":"font-family","line-height":"line-height",capitalization:"capitalization","text-align":"text-align","text-size":"text-size",list:"list","indent-increase":"indent-increase","indent-decrease":"indent-decrease",emoji:"emoji",image:"image",video:"video",tag:"tag",import:"import"}[t];if(!i)return;const o=this.registry.get(`formats/${i}`);if(!o)return;(new o).toggle(),this.updateToolbarButtonStates();["bold","italic","underline","strike","subscript","superscript"].includes(t)&&setTimeout(()=>{this.onContentChange()},0)}_getFormatInstance(t){if(this._fmtCache||(this._fmtCache=new Map),this._fmtCache.has(t))return this._fmtCache.get(t);const e=this.registry.get(`formats/${t}`);if(!e)return null;let i;if(e.createForEditor)i=e.createForEditor(this.instanceId);else{const t=A.currentInstance;A.currentInstance=this,i=new e,A.currentInstance=t}return this._fmtCache.set(t,i),i}updateToolbarButtonStates(){const t=this.getModule("toolbar");if(!t)return;const e=window.getSelection();if(!e||!e.rangeCount)return;const i=this.isSelectionInEditableArea(e);if(["heading","font-family","line-height","capitalization","text-align","list","indent-increase","indent-decrease","bold","italic","underline","strike","subscript","superscript","color","background","link","table","text-size"].forEach(e=>{if(i){const i=this._getFormatInstance(e);i&&(t.setButtonActive(e,i.isActive()),"line-height"===e&&"function"==typeof i.updateButtonText&&i.updateButtonText())}else t.setButtonActive(e,!1)}),i){const t=this.registry.get("formats/text-size");t&&"function"==typeof t.updateButtonTextStatic&&t.updateButtonTextStatic(this.instanceId)}this.updateColorSwatches(),this.updateHistoryButtons()}updateHistoryButtons(){const t=this.getModule("toolbar");if(!t||"function"!=typeof t.getButton)return;const e=this.getModule("history"),i=!(!e||"function"!=typeof e.canUndo||!e.canUndo()),o=!(!e||"function"!=typeof e.canRedo||!e.canRedo()),n=(t,e)=>{t&&(t.classList.remove("rte-hidden"),t.disabled=!e,t.classList.toggle("is-disabled",!e))};n(t.getButton("undo"),i),n(t.getButton("redo"),o)}updateColorSwatches(){const t=this.getModule("toolbar");if(!t||"function"!=typeof t.getButton)return;const e=(e,i)=>{const o=t.getButton(e);if(!o)return;const n=o.querySelector(".rte-swatch");n&&(i?(n.style.background=i,o.classList.add("has-color")):(n.style.removeProperty("background"),o.classList.remove("has-color")))},i=this.registry.get("formats/color");i&&"function"==typeof i.getCurrentColor&&e("color",i.getCurrentColor());const o=this.registry.get("formats/background");o&&"function"==typeof o.getCurrentColor&&e("background",o.getCurrentColor())}undo(){const t=this.getModule("history");t&&"function"==typeof t.undo?t.undo():i("undo")}redo(){const t=this.getModule("history");t&&"function"==typeof t.redo?t.redo():i("redo")}on(t,e){this.events.has(t)||this.events.set(t,[]),this.events.get(t).push(e)}off(t,e){if(this.events.has(t)){const i=this.events.get(t),o=i.indexOf(e);o>-1&&i.splice(o,1)}}emit(t,e){this.events.has(t)&&this.events.get(t).forEach(t=>{try{t(e)}catch(t){}})}preventFocusLoss(t,e="button, input, select, textarea, [contenteditable]"){t&&t.addEventListener("mousedown",t=>{t.target.closest(e)||(t.preventDefault(),setTimeout(()=>{this.focus()},0))})}static getCurrentInstance(){return A.currentInstance}static maintainFocus(t,e=null){"function"==typeof t&&t();const i=e||A.getCurrentInstance();i&&setTimeout(()=>i.focus(),0)}getPopupContainer(){return this.popupContainer}static getPopupContainer(){const t=A.getCurrentInstance();return t?t.getPopupContainer():null}getPopupInstance(t){return this.popupInstances.get(t)}setPopupInstance(t,e){this.popupInstances.set(t,e)}static getPopupInstanceById(t,e){const i=A.instances.get(t);return i?i.getPopupInstance(e):null}static getInstanceById(t){return A.instances.get(t)}static getAllInstances(){return A.instances}destroyPopupInstances(){this.popupInstances.forEach((t,e)=>{t&&"function"==typeof t.destroy&&t.destroy()}),this.popupInstances.clear()}updatePlaceholderVisibility(){this.isEditorEmpty()?this.editor.classList.add("placeholder-visible"):this.editor.classList.remove("placeholder-visible")}destroy(){this._markActive&&(this.wrapper.removeEventListener("pointerdown",this._markActive,!0),this.wrapper.removeEventListener("focusin",this._markActive,!0),this._markActive=null),this._onDocSelectionChange&&(document.removeEventListener("selectionchange",this._onDocSelectionChange),this._onDocSelectionChange=null),this._fmtCache&&this._fmtCache.clear(),clearTimeout(this._autosaveTimer),this.modules.forEach(t=>{"function"==typeof t.destroy&&t.destroy()}),this.destroyPopupInstances(),this.wrapper&&this.wrapper.parentNode&&this.wrapper.parentNode.removeChild(this.wrapper),this.modules.clear(),this.formats.clear(),this.events.clear(),A.instances.delete(this.instanceId),A.currentInstance===this&&(A.currentInstance=null)}}class B{static formatName="";static tagName="";static className="";constructor(t){this.domNode=t}static create(t){const e=document.createElement(this.tagName);return this.className&&(e.className=this.className),e}getOffsetWithin(t,e){let i=0;const o=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,null);let n;for(;n=o.nextNode();){if(n===e.startContainer)return i+e.startOffset;i+=n.textContent.length}return i}}class R extends B{static create(t){return super.create(t)}apply(t){const e=window.getSelection();if(!e||!e.rangeCount)return;const i=e.getRangeAt(0);if(i.collapsed){const o=this.constructor.create(t);o.appendChild(document.createTextNode("​")),i.insertNode(o);const n=document.createRange();n.setStart(o.firstChild,1),n.collapse(!0),e.removeAllRanges(),e.addRange(n)}else{const o=i.extractContents(),n=this.constructor.create(t);n.appendChild(o),i.insertNode(n);const r=document.createRange();r.selectNodeContents(n),e.removeAllRanges(),e.addRange(r)}}remove(){const t=window.getSelection();if(!t||!t.rangeCount)return;const e=t.getRangeAt(0);e.collapsed?this.removeAtCursor(e,t):this.removeFromSelection(e,t)}removeAtCursor(t,e){const i=t.startContainer,o=this.findFormatNode(i);if(!o||!o.parentNode)return;const n=o.textContent,r=this.getOffsetWithin(o,t),s=n.slice(0,r),a=n.slice(r),l=document.createDocumentFragment();if(s){const t=o.cloneNode(!1);t.textContent=s,l.appendChild(t)}const c=document.createTextNode("​");if(l.appendChild(c),a){const t=o.cloneNode(!1);t.textContent=a,l.appendChild(t)}o.replaceWith(l);const d=document.createRange();d.setStartAfter(c),d.collapse(!0),e.removeAllRanges(),e.addRange(d)}removeFromSelection(t,e){const o=this.constructor.formatName;i(o),"strike"===o&&i("strikeThrough")}findFormatNode(t){for(;t&&t!==document.body;){if(t.nodeType===Node.ELEMENT_NODE&&t.tagName===this.constructor.tagName)return t;t=t.parentNode}return null}findFormatNodesInRange(t){const e=[],i=document.createTreeWalker(t.commonAncestorContainer,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>e.tagName===this.constructor.tagName&&t.intersectsNode(e)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP});let o;for(;o=i.nextNode();)e.push(o);return e}isActive(){const t=window.getSelection();if(!t||!t.rangeCount)return!1;let e=t.getRangeAt(0).startContainer;const i=this.constructor.tagName,o=this.constructor.alternativeTagNames||[],r=this.constructor.formatName;if(["bold","italic","underline"].includes(r?.toLowerCase()))return n(r);for(;e&&e!==document.body;){if(e.nodeType===Node.ELEMENT_NODE&&(e.tagName===i||o.includes(e.tagName)))return!0;e=e.parentNode}return!1}}class H extends B{static create(t){return super.create(t)}apply(t){const e=window.getSelection();if(!e||!e.rangeCount)return;const i=e.getRangeAt(0),o=this.getBlockElements(i);0===o.length?this.createBlockAtCursor(i,t):o.forEach(e=>{this.convertBlock(e,t)})}remove(){const t=window.getSelection();if(!t||!t.rangeCount)return;const e=t.getRangeAt(0);this.getBlockElements(e).forEach(t=>{this.removeBlockFormat(t)})}createBlockAtCursor(t,e){const i=this.constructor.create(e),o=this.getBlockElement(t.startContainer);if(o&&o.style&&o.style.cssText&&(i.style.cssText=o.style.cssText),t.collapsed){i.appendChild(document.createTextNode("")),t.insertNode(i);const e=document.createRange();e.setStart(i,0),e.collapse(!0);const o=window.getSelection();o.removeAllRanges(),o.addRange(e)}else{const e=t.extractContents();i.appendChild(e),t.insertNode(i);const o=document.createRange();o.selectNodeContents(i);const n=window.getSelection();n.removeAllRanges(),n.addRange(o)}}convertBlock(t,e){const i=this.constructor.create(e);for(;t.firstChild;)i.appendChild(t.firstChild);t.className&&this.shouldPreserveClass(t.className)&&(i.className=t.className),t.style&&t.style.cssText&&(i.style.cssText=t.style.cssText),t.parentNode.replaceChild(i,t)}removeBlockFormat(t){const e=document.createElement("P");for(;t.firstChild;)e.appendChild(t.firstChild);t.style&&t.style.cssText&&(e.style.cssText=t.style.cssText),t.parentNode.replaceChild(e,t)}getBlockElements(t){const e=[];let i=this.getBlockElement(t.startContainer),o=this.getBlockElement(t.endContainer);if(i&&o&&i.nextElementSibling===o){t.endContainer===o&&0===t.endOffset&&(o=i)}if(i===o)i&&e.push(i);else{let t=i;for(;t&&t!==o;)this.isBlockElement(t)&&e.push(t),t=this.getNextBlockElement(t);o&&this.isBlockElement(o)&&e.push(o)}return e.filter((t,e,i)=>i.indexOf(t)===e)}getBlockElement(t){for(;t&&t.nodeType!==Node.ELEMENT_NODE;)t=t.parentNode;for(;t&&t!==document.body;){if(this.isBlockElement(t))return t;t=t.parentNode}return null}isBlockElement(t){if(!t||t.nodeType!==Node.ELEMENT_NODE)return!1;return["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","PRE","UL","OL","LI","SECTION","ARTICLE"].includes(t.tagName.toUpperCase())}getNextBlockElement(t){let e=t.nextElementSibling;for(;e;){if(this.isBlockElement(e))return e;e=e.nextElementSibling}return null}isActive(t=null){const e=window.getSelection();if(!e||!e.rangeCount)return!1;const i=e.getRangeAt(0),o=this.getBlockElement(i.startContainer);return!!o&&(o.tagName===this.constructor.tagName&&(!t||this.hasValue(o,t)))}hasValue(t,e){return!0}shouldPreserveClass(t){return!1}}function z(){const t=A.getCurrentInstance();if(t){const e=t.getModule("history");e&&"function"==typeof e.saveBeforeFormat&&e.saveBeforeFormat()}}class M extends R{static formatName="bold";static tagName="B";static alternativeTagNames=["STRONG"];apply(){z(),i("bold")}remove(){i("bold")}toggle(){z(),i("bold")}isActive(){return n("bold")}}class O extends R{static formatName="italic";static tagName="I";static alternativeTagNames=["EM"];toggle(){z(),this.isActive()?this.remove():this.apply()}}class P extends R{static formatName="underline";static tagName="U";static alternativeTagNames=["SPAN"];toggle(){z(),this.isActive()?this.remove():this.apply()}}class _ extends R{static formatName="strike";static tagName="S";static alternativeTagNames=["STRIKE","DEL"];toggle(){z(),this.isActive()?this.remove():this.apply()}}class F extends R{static formatName="subscript";static tagName="SUB";removeSuperscriptBeforeApply(){const e=t.get("formats/superscript");if(!e)return;const i=new e;i.isActive()&&i.remove()}toggle(){z(),this.isActive()?this.remove():(this.removeSuperscriptBeforeApply(),this.apply())}}class D extends R{static formatName="superscript";static tagName="SUP";removeSubscriptBeforeApply(){const e=t.get("formats/subscript");if(!e)return;const i=new e;i.isActive()&&i.remove()}toggle(){z(),this.isActive()?this.remove():(this.removeSubscriptBeforeApply(),this.apply())}}function V(t=null){let e;return e=t?A.getInstanceById(t):A.getCurrentInstance(),e?e.getPopupContainer():document.body}function q(t,e=null){const i=V(e);t.parentNode&&t.parentNode.removeChild(t),i.appendChild(t)}function U(t){if(!t)return{width:300,height:200};const e=t.getBoundingClientRect();if(e.width>0&&e.height>0)return{width:e.width,height:e.height};if(t.offsetWidth>0&&t.offsetHeight>0)return{width:t.offsetWidth,height:t.offsetHeight};const i=window.getComputedStyle(t);if("none"===i.display||"hidden"===i.visibility){const e=t.style.display,i=t.style.visibility,o=t.style.position,n=t.style.top,r=t.style.left,s=t.style.zIndex;t.style.display="block",t.style.visibility="visible",t.style.position="absolute",t.style.top="-9999px",t.style.left="-9999px",t.style.zIndex="-1",t.offsetHeight;const a=t.getBoundingClientRect(),l=a.width>0?a.width:300,c=a.height>0?a.height:200;return t.style.display=e,t.style.visibility=i,t.style.position=o,t.style.top=n,t.style.left=r,t.style.zIndex=s,{width:l,height:c}}const o=parseInt(i.width),n=parseInt(i.height);return{width:o>0?o:300,height:n>0?n:200}}function $(t,e,i={}){const{offsetX:o=0,offsetY:n=5,preferTop:r=!1,preferLeft:s=!1}=i,a=t.getBoundingClientRect(),l=V();let c,d;if(l.classList.contains("rich-editor-popup-container")){const t=l.getBoundingClientRect();c=a.top-t.top+a.height+n,d=a.left-t.left+o;const{width:i,height:p}=U(e);if(c+p>t.height&&!r){const e=a.top-t.top-p-n;c=e>=0?e:Math.max(n,(t.height-p)/2)}d+i+5>t.width&&!s&&(d=t.width-i-o-15),d<0&&(d=o),c<0&&(c=n)}else{c=a.bottom+window.scrollY+n,d=a.left+window.scrollX+o;const{width:t,height:i}=U(e);if(d+t>window.innerWidth&&!s&&(d=window.innerWidth-t-o),c+i>window.innerHeight+window.scrollY&&!r){const t=a.top+window.scrollY-i-n;c=t>=window.scrollY?t:Math.max(window.scrollY+n,window.scrollY+(window.innerHeight-i)/2)}d<0&&(d=o),c<0&&(c=n)}return{top:c,left:d}}function W(t,e){t.style.position="absolute",t.style.top=`${e.top}px`,t.style.left=`${e.left}px`,t.style.zIndex="1000"}class X{constructor(t={}){this.options={colors:["#000000","#333333","#666666","#999999","#cccccc","#eeeeee","#ff0000","#ff6600","#ffcc00","#ffff00","#99ff00","#00ff00","#00ffcc","#00ccff","#0066ff","#0000ff","#6600ff","#cc00ff","#ff00cc","#ff0066","#800000","#ff8000","#808000","#008000","#008080","#0080ff","#004080","#800080","#804080","#ff0080"],customColorEnabled:!0,onColorSelect:null,editor:null,...t},this.popup=null,this.isVisible=!1,this.currentColor="#000000",this.clickOutsideHandler=null,this.createColorPicker()}createColorPicker(){this.popup=document.createElement("div"),this.popup.className="color-picker-popup",this.createColorGrid(),this.options.customColorEnabled&&this.createCustomColorInput(),q(this.popup),this.options.editor&&"function"==typeof this.options.editor.preventFocusLoss&&this.options.editor.preventFocusLoss(this.popup)}createColorGrid(){const t=document.createElement("div");t.className="color-grid",this.options.colors.forEach(e=>{const i=document.createElement("button");i.type="button",i.className="color-button",i.style.backgroundColor=e,i.dataset.color=e,i.title=e,i.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),this.selectColor(e),this.options.editor&&setTimeout(()=>this.options.editor.focus(),0)}),t.appendChild(i)}),this.popup.appendChild(t)}createCustomColorInput(){const t=document.createElement("div");t.className="custom-color-container";const e=document.createElement("button");e.type="button",e.className="color-button no-color-button",e.title="No Color",e.style.backgroundColor="transparent";const i=L.createIconElement("no-color",{width:"24",height:"24"});e.appendChild(i),e.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),this.selectColor("transparent"),this.options.editor&&setTimeout(()=>this.options.editor.focus(),0)});const o=document.createElement("button");o.type="button",o.className="color-button white-button",o.style.backgroundColor="#ffffff",o.style.border="1px solid #ccc",o.title="White",o.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),this.selectColor("#ffffff"),this.options.editor&&setTimeout(()=>this.options.editor.focus(),0)});const n=document.createElement("button");n.type="button",n.className="color-button black-button",n.style.backgroundColor="#000000",n.title="Black",n.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),this.selectColor("#000000"),this.options.editor&&setTimeout(()=>this.options.editor.focus(),0)});const r=document.createElement("button");r.type="button",r.className="color-button custom-color-button",r.title="Custom Color",r.style.backgroundColor="transparent",r.style.border="1px solid #ccc",r.style.font="none !important";const s=L.createIconElement("custom-color",{width:"16px",height:"16px"});r.appendChild(s);const a=document.createElement("input");a.type="color",a.className="custom-color-input",a.value=this.currentColor,a.style.visibility="hidden",a.style.pointerEvents="none",a.style.opacity="0",r.addEventListener("click",t=>{a.style.visibility="visible",a.style.pointerEvents="auto",a.style.opacity="1",t.preventDefault(),t.stopPropagation(),a.click()}),a.addEventListener("change",t=>{a.style.visibility="hidden",a.style.pointerEvents="none",a.style.opacity="0",this.selectColor(t.target.value),this.options.editor&&setTimeout(()=>this.options.editor.focus(),0)}),t.appendChild(e),t.appendChild(o),t.appendChild(n),t.appendChild(r),t.appendChild(a),this.popup.appendChild(t)}setupClickOutside(){this.clickOutsideHandler&&document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=t=>{this.popup.contains(t.target)||this.hide()},setTimeout(()=>{document.addEventListener("click",this.clickOutsideHandler)},100)}removeClickOutside(){this.clickOutsideHandler&&(document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=null)}show(t){if(!t)return;document.body.contains(this.popup)||q(this.popup);const e=$(t,this.popup,{offsetY:5,offsetX:0});W(this.popup,e),this.popup.classList.add("visible"),this.isVisible=!0,this.setupClickOutside()}hide(){this.popup.classList.remove("visible"),this.isVisible=!1,this.removeClickOutside()}selectColor(t){this.currentColor=t,this.options.onColorSelect&&this.options.onColorSelect(t),this.hide()}destroy(){this.removeClickOutside(),this.popup&&this.popup.parentNode&&this.popup.parentNode.removeChild(this.popup)}}class K extends R{static formatName="color";static tagName="SPAN";static attribute="color";static savedRanges=new Map;constructor(){super();const t=A.getCurrentInstance();if(!t)return;this.editorId=t.instanceId;let e=t.getPopupInstance("color");if(!e){const i=this.editorId;e=new X({onColorSelect:t=>{K.applyColorToCurrentSelection(t,i)},editor:A.getCurrentInstance()}),t.setPopupInstance("color",e)}this.colorPicker=e}static applyColorToCurrentSelection(t,e=null){const n=window.getSelection(),r=null!=e?K.savedRanges.get(e):null;r&&(n.removeAllRanges(),n.addRange(r)),null!=e&&K.savedRanges.delete(e),n&&n.rangeCount&&!n.isCollapsed&&(z(),o(!0),i("foreColor","transparent"===t?"inherit":t),setTimeout(()=>{const t=A.getCurrentInstance();t&&("function"==typeof t.updateToolbarButtonStates&&t.updateToolbarButtonStates(),"function"==typeof t.onContentChange&&t.onContentChange())},0))}toggle(){this.colorPicker.isVisible?this.colorPicker.hide():this.showColorPicker()}showColorPicker(){const t=A.getInstanceById(this.editorId);if(!t)return;const e=window.getSelection();e&&e.rangeCount&&!e.isCollapsed?K.savedRanges.set(this.editorId,e.getRangeAt(0).cloneRange()):t._lastRange&&K.savedRanges.set(this.editorId,t._lastRange.cloneRange());const i=t.getModule("toolbar");let o=null;if(i&&(o=i.getButton("color")),!o){const t=i?.getContainer();t&&(o=t.querySelector(".rich-editor-toolbar-btn.color-btn"))}o||(o=t.wrapper.querySelector(".rich-editor-toolbar-btn.color-btn")),o&&this.colorPicker.show(o)}isActive(){return!!K.getCurrentColor()}static getCurrentColor(){const t=window.getSelection();if(!t||!t.rangeCount)return null;let e=t.getRangeAt(0).startContainer;for(e.nodeType===Node.TEXT_NODE&&(e=e.parentNode);e&&e.nodeType===Node.ELEMENT_NODE&&(!e.classList||!e.classList.contains("rich-editor-area"));){if(e.style&&e.style.color&&"inherit"!==e.style.color)return e.style.color;if("FONT"===e.tagName&&e.getAttribute("color"))return e.getAttribute("color");e=e.parentNode}return null}}class G extends R{static formatName="background";static tagName="SPAN";static attribute="background-color";static savedRanges=new Map;constructor(){super();const t=A.getCurrentInstance();if(!t)return;this.editorId=t.instanceId;let e=t.getPopupInstance("background");e||(e=new X({onColorSelect:t=>{G.applyBackgroundToCurrentSelection(t,this.editorId)},editor:t,editorId:this.editorId}),t.setPopupInstance("background",e)),this.colorPicker=e}static createForEditor(t){const e=A.getInstanceById(t);if(!e)return null;const i=A.currentInstance;A.currentInstance=e;const o=new G;return A.currentInstance=i,o}static applyBackgroundToCurrentSelection(t,e=null){let n=null;if(n=e?A.getInstanceById(e):A.getCurrentInstance(),!n)return;const r=window.getSelection(),s=null!=e?G.savedRanges.get(e):null;s&&(r.removeAllRanges(),r.addRange(s)),null!=e&&G.savedRanges.delete(e),r&&r.rangeCount&&!r.isCollapsed&&(z(),o(!0),i("backColor","transparent"===t?"inherit":t),setTimeout(()=>{n&&("function"==typeof n.updateToolbarButtonStates&&n.updateToolbarButtonStates(),"function"==typeof n.onContentChange&&n.onContentChange())},0))}toggle(){this.colorPicker.isVisible?this.colorPicker.hide():this.showColorPicker()}showColorPicker(){const t=A.getInstanceById(this.editorId);if(!t)return;const e=window.getSelection();e&&e.rangeCount&&!e.isCollapsed?G.savedRanges.set(this.editorId,e.getRangeAt(0).cloneRange()):t._lastRange&&G.savedRanges.set(this.editorId,t._lastRange.cloneRange());const i=t.getModule("toolbar");let o=null;if(i&&(o=i.getButton("background")),!o){const t=i?.getContainer();t&&(o=t.querySelector(".rich-editor-toolbar-btn.background-btn"))}o||(o=t.wrapper.querySelector(".rich-editor-toolbar-btn.background-btn")),o&&this.colorPicker.show(o)}isActive(){return!!G.getCurrentColor()}static getCurrentColor(){const t=window.getSelection();if(!t||!t.rangeCount)return null;let e=t.getRangeAt(0).startContainer;for(e.nodeType===Node.TEXT_NODE&&(e=e.parentNode);e&&e.nodeType===Node.ELEMENT_NODE&&(!e.classList||!e.classList.contains("rich-editor-area"));){if(e.style&&e.style.backgroundColor&&"inherit"!==e.style.backgroundColor)return e.style.backgroundColor;e=e.parentNode}return null}}class Y{constructor(t={}){this.options={onLinkSelect:null,editor:null,...t},this.popup=null,this.isVisible=!1,this.urlInput=null,this.textInput=null,this.createPopup()}createPopup(){this.popup=document.createElement("div"),this.popup.className="link-popup link-popup--inline";const t=document.createElement("div");t.className="link-popup-content",this.textGroup=document.createElement("div"),this.textGroup.className="link-popup-row",this.textInput=document.createElement("input"),this.textInput.type="text",this.textInput.className="yjd-input",this.textInput.placeholder="Text to display",this.textGroup.appendChild(this.textInput);const e=document.createElement("div");e.className="link-popup-row",this.urlInput=document.createElement("input"),this.urlInput.type="text",this.urlInput.className="yjd-input",this.urlInput.placeholder="Paste or type a link…",this.applyBtn=document.createElement("button"),this.applyBtn.type="button",this.applyBtn.className="yjd-button-confirm link-popup-apply",this.applyBtn.textContent="Apply",this.applyBtn.onclick=()=>{this.handleOk(),this._refocusEditor()},e.appendChild(this.urlInput),e.appendChild(this.applyBtn),t.appendChild(this.textGroup),t.appendChild(e),this.popup.appendChild(t);const i=t=>{"Enter"===t.key&&(t.preventDefault(),this.handleOk(),this._refocusEditor()),"Escape"===t.key&&(this.hide(),this._refocusEditor())};this.urlInput.onkeydown=i,this.textInput.onkeydown=i,q(this.popup),this.options.editor&&"function"==typeof this.options.editor.preventFocusLoss&&this.options.editor.preventFocusLoss(this.popup)}_refocusEditor(){this.options.editor&&setTimeout(()=>this.options.editor.focus(),0)}handleOk(){const t=this.urlInput.value.trim();if(!t)return void this.urlInput.focus();let e=t;/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(e)||e.startsWith("/")||e.startsWith("#")||(e="https://"+e);const i=this.textInput.value.trim();this.options.onLinkSelect&&this.options.onLinkSelect({url:e,text:i}),this.hide()}show(t,e=null,i=""){if(!t)return;const o=!!i;this.urlInput.value=e?e.url:"",this.textInput.value=i||(e?e.text:""),this.textGroup.style.display=o?"none":"";const n=$(t,this.popup,{offsetY:8,offsetX:0});W(this.popup,n),this.popup.classList.add("visible"),this.isVisible=!0,setTimeout(()=>this.urlInput.focus(),60),setTimeout(()=>{document.addEventListener("click",this.closeOnClickOutside)},100)}hide(){this.popup.classList.remove("visible"),this.isVisible=!1,document.removeEventListener("click",this.closeOnClickOutside)}closeOnClickOutside=t=>{this.popup.contains(t.target)||this.hide()};destroy(){document.removeEventListener("click",this.closeOnClickOutside),this.popup&&this.popup.parentNode&&this.popup.parentNode.removeChild(this.popup)}}class Q extends R{static formatName="link";static tagName="A";static savedRanges=new Map;constructor(){super();const t=A.getCurrentInstance();if(!t)return;this.editorId=t.instanceId;let e=t.getPopupInstance("link");e||(e=new Y({onLinkSelect:t=>{Q.insertLink(t,this.editorId)},editor:t,editorId:this.editorId}),t.setPopupInstance("link",e)),this.linkPopup=e}static createForEditor(t){const e=A.getInstanceById(t);if(!e)return null;const i=A.currentInstance;A.currentInstance=e;const o=new Q;return A.currentInstance=i,o}static insertLink(t,e=null){let i=null;if(i=e?A.getInstanceById(e):A.getCurrentInstance(),!i)return;if(!a(t.url))return;const o=Q.savedRanges.get(e);if(!o)return;const n=window.getSelection();n.removeAllRanges(),n.addRange(o);const r=n.getRangeAt(0);if(r.collapsed){const e=document.createElement("A");e.href=t.url,e.target="_blank",e.rel="noopener noreferrer",e.textContent=t.text||t.url,r.insertNode(e)}else{const e=r.extractContents(),i=document.createElement("A");for(i.href=t.url,i.target="_blank",i.rel="noopener noreferrer";e.firstChild;)i.appendChild(e.firstChild);r.insertNode(i)}const s=document.createRange();s.setStartAfter(r.endContainer),s.collapse(!0),n.removeAllRanges(),n.addRange(s),setTimeout(()=>{i&&"function"==typeof i.onContentChange&&i.onContentChange()},0),Q.savedRanges.delete(e),i&&"function"==typeof i.onContentChange&&i.onContentChange()}toggle(){this.linkPopup.isVisible?this.linkPopup.hide():this.showPopup()}showPopup(){const t=A.getInstanceById(this.editorId);if(!t)return;const e=window.getSelection();let i=null;if(e&&e.rangeCount>0){const t=e.getRangeAt(0).cloneRange();if(Q.savedRanges.set(this.editorId,t),i=t.getBoundingClientRect(),!i||0===i.width&&0===i.height){const e=t.startContainer.nodeType===Node.TEXT_NODE?t.startContainer.parentElement:t.startContainer;e&&e.getBoundingClientRect&&(i=e.getBoundingClientRect())}}const o=this.getCurrentLink();let n="";e&&!e.isCollapsed&&(n=e.toString().trim());let r=null;if(i&&(i.width||i.height))r={getBoundingClientRect:()=>i};else{const e=t.getModule("toolbar");r=e&&(e.getButton("link")||t.wrapper.querySelector('.rich-editor-toolbar-btn[data-command="link"]'))}r&&this.linkPopup.show(r,o,n)}getCurrentLink(){const t=window.getSelection();if(!t||!t.rangeCount)return null;let e=t.getRangeAt(0).startContainer;for(;e&&e!==document.body;){if(e.nodeType===Node.ELEMENT_NODE&&"A"===e.tagName)return{url:e.href||"",text:e.textContent||""};e=e.parentNode}return null}isActive(){return null!==this.getCurrentLink()}}class Z{constructor(t={}){this.options={maxRows:8,maxCols:8,onTableSelect:null,...t},this.popup=null,this.isVisible=!1,this.selectedRows=1,this.selectedCols=1,this.grid=null,this.sizeDisplay=null,this.createPopup()}createPopup(){this.popup=document.createElement("div"),this.popup.className="table-popup";const t=document.createElement("div");t.className="table-popup-content",this.createSizeDisplay(),this.createGridSelector(),t.appendChild(this.grid),t.appendChild(this.sizeDisplay),this.popup.appendChild(t),q(this.popup)}createSizeDisplay(){this.sizeDisplay=document.createElement("div"),this.sizeDisplay.className="table-size-display"}createGridSelector(){this.grid=document.createElement("div"),this.grid.className="table-grid-selector";for(let t=1;t<=this.options.maxRows;t++)for(let e=1;e<=this.options.maxCols;e++){const i=document.createElement("div");i.className="table-grid-cell",i.dataset.row=t,i.dataset.col=e,i.addEventListener("mouseenter",()=>{this.highlightGrid(t,e)}),i.addEventListener("click",()=>{this.selectSize(t,e),this.handleInsert()}),this.grid.appendChild(i)}this.grid.addEventListener("mouseleave",()=>{this.highlightGrid(1,1)})}highlightGrid(t,e){this.selectedRows=t,this.selectedCols=e,this.updateSizeDisplay(t,e);this.grid.querySelectorAll(".table-grid-cell").forEach(i=>{const o=parseInt(i.dataset.row),n=parseInt(i.dataset.col);o<=t&&n<=e?i.classList.add("highlighted"):i.classList.remove("highlighted")})}updateSizeDisplay(t,e){this.sizeDisplay&&(this.sizeDisplay.textContent=`${t}x${e}`)}selectSize(t,e){this.selectedRows=t,this.selectedCols=e,this.updateSizeDisplay(t,e)}handleInsert(){this.options.onTableSelect&&this.options.onTableSelect({rows:this.selectedRows,cols:this.selectedCols}),this.hide()}show(t){if(!t)return;this.selectedRows=1,this.selectedCols=1,this.highlightGrid(1,1);const e=$(t,this.popup,{offsetY:5,offsetX:0});W(this.popup,e),this.popup.classList.add("visible"),this.isVisible=!0,setTimeout(()=>{document.addEventListener("click",this.closeOnClickOutside)},100)}hide(){this.popup.classList.remove("visible"),this.isVisible=!1,document.removeEventListener("click",this.closeOnClickOutside)}closeOnClickOutside=t=>{this.popup.contains(t.target)||this.hide()};destroy(){document.removeEventListener("click",this.closeOnClickOutside),this.popup&&this.popup.parentNode&&this.popup.parentNode.removeChild(this.popup)}}class J extends H{static formatName="table";static tagName="TABLE";static savedRanges=new Map;constructor(){super();const t=A.getCurrentInstance();if(!t)return;this.editorId=t.instanceId;let e=t.getPopupInstance("table");e||(e=new Z({onTableSelect:t=>{J.insertTable(t,this.editorId)},editor:t,editorId:this.editorId}),t.setPopupInstance("table",e)),this.tablePopup=e}static createForEditor(t){const e=A.getInstanceById(t);if(!e)return null;const i=A.currentInstance;A.currentInstance=e;const o=new J;return A.currentInstance=i,o}static insertTable(t,e=null){let i=null;if(i=e?A.getInstanceById(e):A.getCurrentInstance(),!i)return;const o=J.savedRanges.get(e);if(!o)return;const n=window.getSelection();n.removeAllRanges(),n.addRange(o);const r=n.getRangeAt(0),s=J.createTableElement(t.rows,t.cols);r.collapsed||r.deleteContents(),"function"==typeof i.insertBlock?i.insertBlock(s):r.insertNode(s);const a=s.querySelector("td");if(a){const t=document.createRange();t.setStart(a,0),t.collapse(!0),n.removeAllRanges(),n.addRange(t)}J.savedRanges.delete(e),i&&"function"==typeof i.onContentChange&&i.onContentChange()}static createTableElement(t,e){const i=document.createElement("table");i.className="rich-editor-table",i.cellSpacing="0",i.cellPadding="0",i.border="1";const o=document.createElement("tbody");for(let i=0;i<t;i++){const t=document.createElement("tr");for(let i=0;i<e;i++){const e=document.createElement("td");e.innerHTML="<br>",e.style.minWidth="50px",e.style.minHeight="24px",e.style.padding="4px 8px",e.style.border="1px solid #ddd",e.style.verticalAlign="top",e.contentEditable="true",t.appendChild(e)}o.appendChild(t)}return i.appendChild(o),i.style.borderCollapse="collapse",i.style.width="100%",i.style.margin="10px 0",i}toggle(){this.tablePopup.isVisible?this.tablePopup.hide():this.showPopup()}showPopup(){const t=window.getSelection();t&&t.rangeCount>0&&J.savedRanges.set(this.editorId,t.getRangeAt(0).cloneRange());const e=A.getInstanceById(this.editorId);if(!e)return;const i=e.getModule("toolbar");let o=null;if(i&&(o=i.getButton("table")),!o){const t=i?.getContainer();t&&(o=t.querySelector(".rich-editor-toolbar-btn.table-btn"))}o||(o=e.wrapper.querySelector(".rich-editor-toolbar-btn.table-btn")),o&&this.tablePopup.show(o)}isActive(){const t=window.getSelection();if(!t||!t.rangeCount)return!1;let e=t.getRangeAt(0).startContainer;for(;e&&e!==document.body;){if(e.nodeType===Node.ELEMENT_NODE&&"TABLE"===e.tagName)return!0;e=e.parentNode}return!1}getCurrentTable(){const t=window.getSelection();if(!t||!t.rangeCount)return null;let e=t.getRangeAt(0).startContainer;for(;e&&e!==document.body;){if(e.nodeType===Node.ELEMENT_NODE&&"TABLE"===e.tagName)return e;e=e.parentNode}return null}apply(){this.showPopup()}remove(){const t=this.getCurrentTable();t&&(window.richEditor&&window.richEditor.resizeHandles&&window.richEditor.resizeHandles.hideHandles(),t.parentNode.removeChild(t))}}class tt{constructor(t={}){this.options={items:[],onItemSelect:null,displayProperty:"label",valueProperty:"value",className:"custom-select",title:"",width:200,height:280,...t},this.popup=null,this.isVisible=!1,this.currentValue=null,this.clickOutsideHandler=null,this.initialized=!1,this.createSelect()}createSelect(){if(this.popup=document.createElement("div"),this.popup.className=`${this.options.className}-popup`,this.options.title){const t=document.createElement("div");t.className="custom-select-header",t.textContent=this.options.title,this.popup.appendChild(t)}q(this.popup),this.init()}async init(){await this.createItemList(),this.initialized=!0}async createItemList(){const t=document.createElement("div");t.className="item-list";const e=L.getIcon("check");this.options.items.forEach(i=>{const o=document.createElement("button");o.type="button",o.className="custom-select-item-button",o.dataset.value=this.getItemValue(i);const n=document.createElement("div");n.className="item-text",n.innerHTML=this.getItemDisplay(i);const r=document.createElement("span");r.className="item-checkmark",r.innerHTML=e||"",o.appendChild(n),o.appendChild(r),o.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),this.selectItem(i)}),t.appendChild(o)}),this.popup.appendChild(t)}getItemDisplay(t){return t[this.options.displayProperty]||t.toString()}getItemValue(t){return t[this.options.valueProperty]||t[this.options.displayProperty]||t}async updateItems(t){this.options.items=t;const e=this.popup.querySelector(".item-list");e&&e.remove(),await this.createItemList()}setupClickOutside(){this.clickOutsideHandler&&document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=t=>{t.target.closest(".block-toolbar")||this.popup.contains(t.target)||this.hide()},setTimeout(()=>{document.addEventListener("click",this.clickOutsideHandler)},100)}removeClickOutside(){this.clickOutsideHandler&&(document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=null)}setupScrollHandler(){this.scrollHandler&&window.removeEventListener("scroll",this.scrollHandler),this.scrollHandler=()=>{this.isVisible&&this.updatePosition()},window.addEventListener("scroll",this.scrollHandler)}removeScrollHandler(){this.scrollHandler&&(window.removeEventListener("scroll",this.scrollHandler),this.scrollHandler=null)}async show(t){if(!t)return;const e=window.getSelection(),i=A.getCurrentInstance&&A.getCurrentInstance(),o=i&&i.editor;e&&e.rangeCount&&o&&o.contains(e.anchorNode)?this._savedRange=e.getRangeAt(0).cloneRange():this._savedRange=i&&i._lastRange?i._lastRange.cloneRange():null,this.initialized||await new Promise(t=>{const e=()=>{this.initialized?t():setTimeout(e,10)};e()}),document.body.contains(this.popup)||q(this.popup),this.highlightCurrentItem(this.currentValue);const n=$(t,this.popup,{offsetY:5,offsetX:0});W(this.popup,n),this.popup.classList.add("visible"),this.isVisible=!0,this.setupClickOutside(),this.setupScrollHandler(),this.currentAnchor=t}hide(){this.popup.classList.remove("visible"),this.isVisible=!1,this.removeClickOutside(),this.currentAnchor=null}updatePosition(){if(this.isVisible&&this.currentAnchor){const t=$(this.currentAnchor,this.popup,{offsetY:5,offsetX:0});W(this.popup,t)}}setCurrentValue(t){this.currentValue=t,this.highlightCurrentItem(t)}highlightCurrentItem(t){if(this.popup.querySelectorAll(".custom-select-item-button.current").forEach(t=>{t.classList.remove("current")}),null!=t){const e=this.popup.querySelectorAll(".custom-select-item-button");for(const i of e)if(i.dataset.value===t.toString()){i.classList.add("current");break}}}selectItem(t){const e=this.getItemValue(t);if(this.currentValue=e,this._savedRange){const t=window.getSelection();t.removeAllRanges(),t.addRange(this._savedRange)}this.options.onItemSelect&&this.options.onItemSelect(e,t),this.hide()}getCurrentValue(){return this.currentValue}destroy(){this.removeClickOutside(),this.popup&&this.popup.parentNode&&this.popup.parentNode.removeChild(this.popup)}}class et extends H{static formatName="heading";static tagName="H1";constructor(){super();const t=A.getCurrentInstance();if(!t)return;this.editorId=t.instanceId;let e=t.getPopupInstance("heading");if(!e){const i=et.getTagMap(),o=Object.values(i).map(t=>({value:t.tag,label:t.element,title:t.title}));e=new tt({items:o,displayProperty:"label",valueProperty:"value",className:"heading-select",onItemSelect:(t,e)=>{et.applyTagToCurrentSelection(t,this.editorId)},editor:t,editorId:this.editorId}),t.setPopupInstance("heading",e)}this.customSelect=e}static createForEditor(t){const e=A.getInstanceById(t);if(!e)return null;const i=A.currentInstance;A.currentInstance=e;const o=new et;return A.currentInstance=i,o}static getTagMap(){return{H1:{tag:"H1",element:'<h1 style="margin:0">Heading 1</h1>',title:"Heading 1"},H2:{tag:"H2",element:'<h2 style="margin:0">Heading 2</h2>',title:"Heading 2"},H3:{tag:"H3",element:'<h3 style="margin:0">Heading 3</h3>',title:"Heading 3"},H4:{tag:"H4",element:'<h4 style="margin:0">Heading 4</h4>',title:"Heading 4"},H5:{tag:"H5",element:'<h5 style="margin:0">Heading 5</h5>',title:"Heading 5"},H6:{tag:"H6",element:'<h6 style="margin:0">Heading 6</h6>',title:"Heading 6"},P:{tag:"P",element:'<p style="margin:0">Paragraph</p>',title:"Paragraph"},PRE:{tag:"PRE",element:'<pre style="margin:0">Code</pre>',title:"Preformatted"},BLOCKQUOTE:{tag:"BLOCKQUOTE",element:'<blockquote style="margin:0">Quote</blockquote>',title:"Quote"}}}static getTagDisplayName(t){const e=this.getTagMap();return e[t]?.title||"Paragraph"}updateButtonText(){const t=this.getCurrentTag(),e=et.getTagDisplayName(t||"P"),i=A.getInstanceById(this.editorId);if(!i)return;const o=i.getModule("toolbar");let n=null;if(o&&(n=o.getButton("heading")),!n){const t=o?.getContainer();t&&(n=t.querySelector(".rich-editor-toolbar-btn.heading-btn"))}n||(n=i.wrapper.querySelector(".rich-editor-toolbar-btn.heading-btn")),n&&n.updateText?n.updateText(e):n&&(n.textContent=e)}static create(t="P"){return document.createElement(t.toUpperCase())}static applyTagToCurrentSelection(t,e=null){let i=null;if(i=e?A.getInstanceById(e):A.getCurrentInstance(),!i)return;const o=window.getSelection();if(!o||!o.rangeCount)return;z(),o.getRangeAt(0);const n=et.createForEditor(e);n&&(n.apply(t),n.updateButtonText()),setTimeout(()=>{i&&"function"==typeof i.onContentChange&&i.onContentChange()},0)}apply(t="P"){const e=window.getSelection();if(!e||!e.rangeCount)return;const i=e.getRangeAt(0);i.collapsed;const o=this.getBlockElements(i);if(0===o.length){const n=this.createBlockAtCursor(i,t),r=document.createRange();r.setStart(n,0),r.collapse(!0),e.removeAllRanges(),e.addRange(r)}else{const s=window.getSelection();if(!s.rangeCount)return;const a=s.getRangeAt(0),l=a.collapsed,c=Array.from(o);function d(t,e){for(;t&&9!==t.nodeType;){const i=e.indexOf(t);if(-1!==i)return i;t=t.parentNode}return-1}function p(t,e,i){const o=document.createRange();return o.setStart(t,0),o.setEnd(e,i),o.toString().length}const h=d(a.startContainer,c),u=d(a.endContainer,c);let m=0,g=0;-1!==h&&(m=p(c[h],a.startContainer,a.startOffset)),l||-1===u||(g=p(c[u],a.endContainer,a.endOffset));const f=c.map(e=>this.convertBlock(e,t)||e);function y(t,e){const i=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,null,!1);let o,n=e;for(;o=i.nextNode();){const t=o.nodeValue.length;if(n<=t)return{node:o,offset:n};n-=t}return{node:t,offset:t.childNodes.length}}const b=document.createRange();if(l){const v=y(f[-1!==h?h:0],m);v.node.nodeType===Node.TEXT_NODE?b.setStart(v.node,v.offset):b.setStart(v.node,Math.max(0,v.offset)),b.collapse(!0)}else{if(-1===h||-1===u)return s.removeAllRanges(),void s.addRange(a);const x=y(f[h],m),w=y(f[u],g);x.node.nodeType===Node.TEXT_NODE?b.setStart(x.node,x.offset):b.setStart(x.node,Math.min(x.offset,x.node.childNodes.length)),w.node.nodeType===Node.TEXT_NODE?b.setEnd(w.node,w.offset):b.setEnd(w.node,Math.min(w.offset,w.node.childNodes.length))}s.removeAllRanges(),s.addRange(b)}}createBlockAtCursor(t,e){const i=this.constructor.create(e),o=this.getBlockElement(t.startContainer);if(o&&o.style&&o.style.cssText&&(i.style.cssText=o.style.cssText),t.collapsed){i.appendChild(document.createTextNode("")),t.insertNode(i);const e=document.createRange();e.setStart(i,0),e.collapse(!0);const o=window.getSelection();o.removeAllRanges(),o.addRange(e)}else{const e=t.extractContents();i.appendChild(e),t.insertNode(i);const o=document.createRange();o.selectNodeContents(i);const n=window.getSelection();n.removeAllRanges(),n.addRange(o)}}convertBlock(t,e){const i=this.constructor.create(e);for(;t.firstChild;)i.appendChild(t.firstChild);return t.className&&this.shouldPreserveClass(t.className)&&(i.className=t.className),t.style&&t.style.cssText&&(i.style.cssText=t.style.cssText),t.parentNode.replaceChild(i,t),i}setCursorAtStartOfBlock(t){const e=window.getSelection(),i=document.createRange(),o=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,null,!1).nextNode();o?(i.setStart(o,0),i.collapse(!0)):(i.setStart(t,0),i.collapse(!0)),e.removeAllRanges(),e.addRange(i)}async toggle(){this.customSelect.isVisible?this.customSelect.hide():await this.showTagPicker()}async showTagPicker(){const t=A.getInstanceById(this.editorId);if(!t)return;const e=t.getModule("toolbar");let i=null;if(e&&(i=e.getButton("heading")),!i){const t=e?.getContainer();t&&(i=t.querySelector(".rich-editor-toolbar-btn.heading-btn"))}if(i||(i=t.wrapper.querySelector(".rich-editor-toolbar-btn.heading-btn")),!i)return;const o=this.getCurrentTag();o&&this.customSelect.setCurrentValue(o),await this.customSelect.show(i)}isActive(t=null){return this.updateButtonText(),!1}getCurrentTag(){const t=window.getSelection();if(!t||!t.rangeCount)return null;const e=t.getRangeAt(0),i=this.getBlockElement(e.startContainer);if(!i)return null;return["H1","H2","H3","H4","H5","H6","P","PRE","BLOCKQUOTE"].includes(i.tagName)?i.tagName:null}}class it extends R{static formatName="fontFamily";static tagName="SPAN";constructor(){super();const t=A.getCurrentInstance();if(!t)return;this.editorId=t.instanceId;let e=t.getPopupInstance("font-family");if(!e){const i=it.getFontMap(),o=Object.values(i).map(t=>({value:t.font,label:t.element,title:t.title}));e=new tt({items:o,displayProperty:"label",valueProperty:"value",className:"font-family-select",onItemSelect:(t,e)=>{it.applyFontFamilyToCurrentSelection(t,this.editorId)},editor:t,editorId:this.editorId}),t.setPopupInstance("font-family",e)}this.customSelect=e,this.setupSelectionListener()}static createForEditor(t){const e=A.getInstanceById(t);if(!e)return null;const i=A.currentInstance;A.currentInstance=e;const o=new it;return A.currentInstance=i,o}setupSelectionListener(){let t;const e=()=>{clearTimeout(t),t=setTimeout(()=>{const t=window.getSelection();if(t&&t.rangeCount>0){const e=t.getRangeAt(0),i=A.getInstanceById(this.editorId);i&&(i.editor.contains(e.startContainer)||i.editor.isSameNode(e.startContainer))&&this.updateButtonText()}},50)};document.addEventListener("selectionchange",e),document.addEventListener("mouseup",e),document.addEventListener("keyup",e),this.selectionListener=e}static getFontMap(){return{Arial:{font:"Arial, sans-serif",element:'<span style="font-family: Arial, sans-serif">Arial</span>',title:"Arial"},Helvetica:{font:"Helvetica, Arial, sans-serif",element:'<span style="font-family: Helvetica, Arial, sans-serif">Helvetica</span>',title:"Helvetica"},"Times New Roman":{font:'"Times New Roman", Times, serif',element:"<span style=\"font-family: 'Times New Roman', Times, serif\">Times New Roman</span>",title:"Times New Roman"},Georgia:{font:"Georgia, serif",element:'<span style="font-family: Georgia, serif">Georgia</span>',title:"Georgia"},Verdana:{font:"Verdana, Geneva, sans-serif",element:'<span style="font-family: Verdana, Geneva, sans-serif">Verdana</span>',title:"Verdana"},"Courier New":{font:'"Courier New", Courier, monospace',element:"<span style=\"font-family: 'Courier New', Courier, monospace\">Courier New</span>",title:"Courier New"},"Trebuchet MS":{font:'"Trebuchet MS", Helvetica, sans-serif',element:"<span style=\"font-family: 'Trebuchet MS', Helvetica, sans-serif\">Trebuchet MS</span>",title:"Trebuchet MS"},"Comic Sans MS":{font:'"Comic Sans MS", cursive',element:"<span style=\"font-family: 'Comic Sans MS', cursive\">Comic Sans MS</span>",title:"Comic Sans MS"},Impact:{font:"Impact, Charcoal, sans-serif",element:'<span style="font-family: Impact, Charcoal, sans-serif">Impact</span>',title:"Impact"},"Lucida Console":{font:'"Lucida Console", Monaco, monospace',element:"<span style=\"font-family: 'Lucida Console', Monaco, monospace\">Lucida Console</span>",title:"Lucida Console"}}}static getFontDisplayName(t){const e=this.getFontMap();for(const[i,o]of Object.entries(e))if(o.font===t||i===t)return o.title;return"Arial"}updateButtonText(){const t=this.getCurrentFont(),e=it.getFontDisplayName(t||"Arial, sans-serif"),i=A.getInstanceById(this.editorId);if(!i)return;const o=i.getModule("toolbar");let n=null;if(o&&(n=o.getButton("font-family")),!n){const t=o?.getContainer();t&&(n=t.querySelector(".rich-editor-toolbar-btn.font-family-btn"))}n||(n=i.wrapper.querySelector(".rich-editor-toolbar-btn.font-family-btn")),n&&n.updateText?n.updateText(e):n&&(n.textContent=e)}static create(t="Arial, sans-serif"){const e=document.createElement("span");return e.style.fontFamily=t,e}static applyFontFamilyToCurrentSelection(t,e=null){let i=null;if(i=e?A.getInstanceById(e):A.getCurrentInstance(),!i)return;const o=window.getSelection();if(!o||!o.rangeCount)return;z(),o.getRangeAt(0);const n=it.createForEditor(e);n&&(n.apply(t),n.updateButtonText()),setTimeout(()=>{i&&"function"==typeof i.onContentChange&&i.onContentChange()},0)}apply(t="Arial, sans-serif"){const e=window.getSelection();if(!e||!e.rangeCount)return;const o=e.getRangeAt(0);function n(t){const e=window.getSelection(),i=document.createRange(),o=t.firstChild;i.setStart(o,o.length),i.collapse(!0),e.removeAllRanges(),e.addRange(i)}if(o.collapsed){if(function(t,e){if(!t.rangeCount)return!1;let i=t.getRangeAt(0).startContainer;i.nodeType===Node.TEXT_NODE&&(i=i.parentNode);const o=e.split(",")[0].trim().toLowerCase();for(;i&&i.nodeType===Node.ELEMENT_NODE;){if("SPAN"===i.tagName){const t=i.style.fontFamily;if(t&&t.split(",")[0].trim().toLowerCase()===o)return 1===i.childNodes.length&&i.firstChild.nodeType===Node.TEXT_NODE&&i.firstChild.textContent,!0}i=i.parentNode}return!1}(e,t))return;let i=o.startContainer;o.startOffset,i.nodeType===Node.TEXT_NODE&&(i=i.parentNode);const r=i.closest&&i.closest("span");if(r&&"​"===r.textContent)return void(r.style.fontFamily=t);if(r&&r.firstChild&&r.firstChild.nodeType===Node.TEXT_NODE){const e=r.firstChild,i=o.startOffset,s=e.data.slice(0,i),a=e.data.slice(i),l=r.parentNode;if(0===i){const e=document.createElement("span");e.style.fontFamily=t,e.appendChild(document.createTextNode("​")),l.insertBefore(e,r),n(e)}else if(i===e.data.length){const e=document.createElement("span");e.style.fontFamily=t,e.appendChild(document.createTextNode("​")),l.insertBefore(e,r.nextSibling),n(e)}else{const e=document.createElement("span");e.style.fontFamily=r.style.fontFamily,e.appendChild(document.createTextNode(s));const i=document.createElement("span");i.style.fontFamily=t,i.appendChild(document.createTextNode("​"));const o=document.createElement("span");o.style.fontFamily=r.style.fontFamily,o.appendChild(document.createTextNode(a)),l.insertBefore(e,r),l.insertBefore(i,r),l.insertBefore(o,r),l.removeChild(r),n(i)}return}const s=document.createElement("span");s.style.fontFamily=t,s.appendChild(document.createTextNode("​")),o.insertNode(s),n(s)}else i("fontName",t)}async toggle(t=null){this.customSelect.isVisible?this.customSelect.hide():await this.showFontPicker(t)}async showFontPicker(t=null){let e=t;if(!e){const t=A.getInstanceById(this.editorId);if(!t)return;const i=t.getModule("toolbar");if(i&&(e=i.getButton("font-family")),!e){const t=i?.getContainer();t&&(e=t.querySelector(".rich-editor-toolbar-btn.font-family-btn"))}e||(e=t.wrapper.querySelector(".rich-editor-toolbar-btn.font-family-btn"))}if(!e)return;const i=this.getCurrentFont();i&&this.customSelect.setCurrentValue(i),await this.customSelect.show(e)}isActive(t=null){return this.updateButtonText(),!1}getCurrentFont(){const t=window.getSelection();if(!t||!t.rangeCount)return null;let e=t.getRangeAt(0).startContainer;e.nodeType===Node.TEXT_NODE&&(e=e.parentElement);const i=A.getInstanceById(this.editorId);if(!i)return"Arial, sans-serif";if(!i.editor.contains(e)&&!i.editor.isSameNode(e))return"Arial, sans-serif";for(;e&&e!==document.body;){if(e.nodeType===Node.ELEMENT_NODE){const t=e;if(t.style.fontFamily)return t.style.fontFamily;const i=window.getComputedStyle(t).fontFamily;if(i&&"initial"!==i&&"inherit"!==i)return i}e=e.parentElement}return"Arial, sans-serif"}setCurrentFont(t){this.currentFont=t}}class ot extends R{static formatName="lineHeight";static tagName="SPAN";constructor(){super();const t=A.getCurrentInstance();if(!t)return;this.editorId=t.instanceId;let e=t.getPopupInstance("line-height");if(!e){const i=ot.getHeightMap(),o=Object.values(i).map(t=>({value:t.height,label:t.element,title:t.title}));e=new tt({items:o,displayProperty:"label",valueProperty:"value",className:"line-height-select",onItemSelect:(t,e)=>{ot.applyLineHeightToCurrentSelection(t,this.editorId)},editor:t,editorId:this.editorId}),t.setPopupInstance("line-height",e)}this.customSelect=e,this.setupSelectionListener()}static createForEditor(t){const e=A.getInstanceById(t);if(!e)return null;const i=A.currentInstance;A.currentInstance=e;const o=new ot;return A.currentInstance=i,o}setupSelectionListener(){let t;const e=()=>{clearTimeout(t),t=setTimeout(()=>{const t=window.getSelection();if(t&&t.rangeCount>0){const e=t.getRangeAt(0),i=A.getInstanceById(this.editorId);i&&(i.editor.contains(e.startContainer)||i.editor.isSameNode(e.startContainer))&&this.updateButtonText()}},50)};document.addEventListener("selectionchange",e),document.addEventListener("mouseup",e),document.addEventListener("keyup",e),this.selectionListener=e}static getHeightMap(){return{"1.0":{height:"1",element:"<span>1.0</span>",title:"1.0"},1.2:{height:"1.2",element:"<span>1.2</span>",title:"1.2"},1.5:{height:"1.5",element:"<span>1.5</span>",title:"1.5"},1.8:{height:"1.8",element:"<span>1.8</span>",title:"1.8"},"2.0":{height:"2",element:"<span>2.0</span>",title:"2.0"},2.5:{height:"2.5",element:"<span>2.5</span>",title:"2.5"},"3.0":{height:"3",element:"<span>3.0</span>",title:"3.0"}}}static getHeightDisplayName(t){const e=this.getHeightMap();if(e[t]?.title)return e[t].title;const i=parseFloat(t);return isNaN(i)?"Normal":String(i)}updateButtonText(){const t=this.getCurrentHeight(),e=ot.getHeightDisplayName(t||"1.15"),i=A.getInstanceById(this.editorId);if(!i)return;const o=i.getModule("toolbar");let n=null;if(o&&(n=o.getButton("line-height")),!n){const t=o?.getContainer();t&&(n=t.querySelector(".rich-editor-toolbar-btn.line-height-btn"))}n||(n=i.wrapper.querySelector(".rich-editor-toolbar-btn.line-height-btn")),n&&n.updateText?n.updateText(e):n&&(n.textContent=e)}static create(t="1.15"){const e=document.createElement("span");return e.style.lineHeight=t,e}static applyLineHeightToCurrentSelection(t,e=null){let i=null;if(i=e?A.getInstanceById(e):A.getCurrentInstance(),!i)return;const o=window.getSelection();if(!o||!o.rangeCount)return;z(),o.getRangeAt(0);const n=ot.createForEditor(e);n&&(n.apply(t),n.updateButtonText()),setTimeout(()=>{i&&"function"==typeof i.onContentChange&&i.onContentChange()},0)}apply(t="1.15"){const e=window.getSelection();if(!e||!e.rangeCount)return;z();const i=e.getRangeAt(0);if(i.collapsed){let e=i.startContainer;e.nodeType===Node.TEXT_NODE&&(e=e.parentNode);const o=e.closest("div, p, li, section, article")||e;return o.style.lineHeight=t,void function(t){const e=window.getSelection(),i=document.createRange(),o=t.firstChild;i.setStart(o,o.length),i.collapse(!0),e.removeAllRanges(),e.addRange(i)}(o)}const o=this.getBlockElementsInRange(i);if(o.length>0)o.forEach(e=>{e.style.lineHeight=t});else{const o=this.constructor.create(t);try{const t=i.extractContents();o.appendChild(t),i.insertNode(o);const n=document.createRange();n.selectNodeContents(o),e.removeAllRanges(),e.addRange(n)}catch(t){}}}getBlockElementsInRange(t){const e=[],i=["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","PRE","UL","OL","LI"],o=t.cloneContents(),n=document.createTreeWalker(o,NodeFilter.SHOW_ELEMENT,{acceptNode:t=>i.includes(t.tagName)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP});let r=n.nextNode();for(;r;){const i=t.commonAncestorContainer.querySelector(`${r.tagName.toLowerCase()}:not([data-processed])`);i&&t.intersectsNode(i)&&(e.push(i),i.setAttribute("data-processed","true")),r=n.nextNode()}if(e.forEach(t=>t.removeAttribute("data-processed")),0===e.length){let o=t.startContainer;for(o.nodeType===Node.TEXT_NODE&&(o=o.parentElement);o&&o!==document.body;){if(o.nodeType===Node.ELEMENT_NODE&&i.includes(o.tagName)){e.push(o);break}o=o.parentElement}}return e}async toggle(){this.customSelect.isVisible?this.customSelect.hide():await this.showHeightPicker()}async showHeightPicker(){const t=A.getInstanceById(this.editorId);if(!t)return;const e=t.getModule("toolbar");let i=null;if(e&&(i=e.getButton("line-height")),!i){const t=e?.getContainer();t&&(i=t.querySelector(".rich-editor-toolbar-btn.line-height-btn"))}if(i||(i=t.wrapper.querySelector(".rich-editor-toolbar-btn.line-height-btn")),!i)return;const o=this.getCurrentHeight();o&&this.customSelect.setCurrentValue(o),await this.customSelect.show(i)}isActive(t=null){return this.updateButtonText(),!1}getCurrentHeight(){const t=window.getSelection();if(!t||!t.rangeCount)return null;let e=t.getRangeAt(0).startContainer;e.nodeType===Node.TEXT_NODE&&(e=e.parentElement);const i=A.getInstanceById(this.editorId);if(!i)return"1.15";if(!i.editor.contains(e)&&!i.editor.isSameNode(e))return"1.15";for(;e&&e!==document.body;){if(e.nodeType===Node.ELEMENT_NODE){const t=e;if(t.style.lineHeight){const e=t.style.lineHeight;return this.normalizeHeightValue(e)}const i=window.getComputedStyle(t),o=i.lineHeight;if(o&&"normal"!==o&&"initial"!==o&&"inherit"!==o){if(o.endsWith("px")){const t=parseFloat(i.fontSize),e=parseFloat(o);if(t>0){const i=(e/t).toFixed(2);return this.normalizeHeightValue(i)}}return this.normalizeHeightValue(o)}}e=e.parentElement}return"1.15"}normalizeHeightValue(t){if(!t)return"1.15";const e=parseFloat(t);if(isNaN(e))return"1.15";const i=e.toFixed(1);return this.constructor.getHeightMap()[i]?i:t}destroy(){this.selectionListener&&(document.removeEventListener("selectionchange",this.selectionListener),document.removeEventListener("mouseup",this.selectionListener),document.removeEventListener("keyup",this.selectionListener),this.selectionListener=null)}}class nt extends R{static formatName="capitalization";static tagName="SPAN";constructor(){super();const t=A.getCurrentInstance();if(!t)return;this.editorId=t.instanceId;let e=t.getPopupInstance("capitalization");if(!e){const i=nt.getCapitalizationMap(),o=Object.values(i).map(t=>({value:t.style,label:t.element,title:t.title}));e=new tt({items:o,displayProperty:"label",valueProperty:"value",className:"capitalization-select",onItemSelect:(t,e)=>{nt.applyCapitalizationToCurrentSelection(t,this.editorId)},editor:t,editorId:this.editorId}),t.setPopupInstance("capitalization",e)}this.customSelect=e}static createForEditor(t){const e=A.getInstanceById(t);if(!e)return null;const i=A.currentInstance;A.currentInstance=e;const o=new nt;return A.currentInstance=i,o}static getCapitalizationMap(){return{capitalize:{style:"capitalize",element:"<span>Capitalize</span>",title:"Capitalize"},uppercase:{style:"uppercase",element:"<span>UPPERCASE</span>",title:"UPPERCASE"},lowercase:{style:"lowercase",element:"<span>lowercase</span>",title:"lowercase"},"small-caps":{style:"small-caps",element:"<span>Small Caps</span>",title:"Small Caps"}}}static getCapitalizationDisplayName(t){const e=this.getCapitalizationMap();return e[t]?.title||"Capitalization"}updateButtonText(){const t=this.getCurrentCapitalization(),e=nt.getCapitalizationDisplayName(t||"none"),i=A.getInstanceById(this.editorId);if(!i)return;const o=i.getModule("toolbar");let n=null;if(o&&(n=o.getButton("capitalization")),!n){const t=o?.getContainer();t&&(n=t.querySelector(".rich-editor-toolbar-btn.capitalization-btn"))}n||(n=i.wrapper.querySelector(".rich-editor-toolbar-btn.capitalization-btn")),n&&n.updateText?n.updateText(e):n&&(n.textContent=e)}static create(t="none"){const e=document.createElement("span");return"small-caps"===t?e.style.fontVariant="small-caps":e.style.textTransform=t,e}static applyCapitalizationToCurrentSelection(t,e=null){let i=null;if(i=e?A.getInstanceById(e):A.getCurrentInstance(),!i)return;const o=window.getSelection();if(!o||!o.rangeCount)return;z(),o.getRangeAt(0);const n=nt.createForEditor(e);n&&(n.apply(t),n.updateButtonText()),setTimeout(()=>{i&&"function"==typeof i.onContentChange&&i.onContentChange()},0)}hasCapitalizationStyling(t){if(!t||t.nodeType!==Node.ELEMENT_NODE)return!1;if("small-caps"===t.style.fontVariant)return!0;if(t.style.textTransform&&"none"!==t.style.textTransform)return!0;const e=window.getComputedStyle(t);return"small-caps"===e.fontVariant||!(!e.textTransform||"none"===e.textTransform)}isCapitalizationElement(t){return!(!t||t.nodeType!==Node.ELEMENT_NODE)&&("small-caps"===t.style.fontVariant||!(!t.style.textTransform||"none"===t.style.textTransform))}findAncestorCapitalizationElement(t){let e=t;if(!e)return null;for(e.nodeType===Node.TEXT_NODE&&(e=e.parentElement);e&&e!==document.body;){if(this.isCapitalizationElement(e))return e;e=e.parentElement}return null}setElementCapitalizationStyle(t,e){t&&("small-caps"===e?(t.style.fontVariant="small-caps",t.style.textTransform=""):"none"===e?(t.style.fontVariant="",t.style.textTransform=""):(t.style.fontVariant="",t.style.textTransform=e))}apply(t="none"){const e=window.getSelection();if(!e||!e.rangeCount)return;z();const i=e.getRangeAt(0);if(i.collapsed)return;if("small-caps"===t){const t=i.extractContents(),o=document.createElement("span");o.style.fontVariant="small-caps",o.appendChild(t),i.insertNode(o);const n=document.createRange();return n.selectNodeContents(o),e.removeAllRanges(),void e.addRange(n)}function o(t,e){switch(e){case"uppercase":return t.toUpperCase();case"lowercase":return t.toLowerCase();case"capitalize":return(t=t.toLowerCase()).replace(/\b\w/g,t=>t.toUpperCase());default:return t}}const n=i.extractContents(),r=document.createTreeWalker(n,NodeFilter.SHOW_TEXT,null);for(;r.nextNode();){const e=r.currentNode;e.textContent=o(e.textContent,t)}i.deleteContents(),i.insertNode(n),function(t){if(!t)return;const e=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,null),i=[];for(;e.nextNode();){const t=e.currentNode;t.textContent.trim()||0!==t.childElementCount||i.push(t)}i.forEach(t=>t.remove())}(i.commonAncestorContainer),e.removeAllRanges(),e.addRange(i)}removeExistingCapitalization(t){const e=t.commonAncestorContainer,i=new Set,o=e=>{e&&e.nodeType===Node.ELEMENT_NODE&&this.hasCapitalizationStyling(e)&&t.intersectsNode(e)&&i.add(e)};e&&e.nodeType===Node.ELEMENT_NODE&&o(e);const n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>t.intersectsNode(e)&&this.hasCapitalizationStyling(e)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP});let r;for(;r=n.nextNode();)i.add(r);const s=t=>{let e=t.nodeType===Node.TEXT_NODE?t.parentElement:t;for(;e&&e!==document.body;)o(e),e=e.parentElement};s(t.startContainer),s(t.endContainer),Array.from(i).forEach(t=>{t.style.textTransform="",t.style.fontVariant="",t.style.cssText.trim()||t.className||this.unwrapElement(t)})}unwrapElement(t){const e=t.parentNode;if(e){for(;t.firstChild;)e.insertBefore(t.firstChild,t);e.removeChild(t)}}async toggle(){this.customSelect.isVisible?this.customSelect.hide():await this.showCapitalizationPicker()}async showCapitalizationPicker(){const t=A.getInstanceById(this.editorId);if(!t)return;const e=t.getModule("toolbar");let i=null;if(e&&(i=e.getButton("capitalization")),!i){const t=e?.getContainer();t&&(i=t.querySelector(".rich-editor-toolbar-btn.capitalization-btn"))}if(i||(i=t.wrapper.querySelector(".rich-editor-toolbar-btn.capitalization-btn")),!i)return;const o=this.getCurrentCapitalization();o&&this.customSelect.setCurrentValue(o),await this.customSelect.show(i)}isActive(t=null){return this.updateButtonText(),!1}getCurrentCapitalization(){const t=window.getSelection();if(!t||!t.rangeCount)return null;let e=t.getRangeAt(0).startContainer;for(e.nodeType===Node.TEXT_NODE&&(e=e.parentElement);e&&e!==document.body;){if(e.nodeType===Node.ELEMENT_NODE){const t=e;if("small-caps"===t.style.fontVariant)return"small-caps";if(t.style.textTransform&&"none"!==t.style.textTransform)return t.style.textTransform;const i=window.getComputedStyle(t);if("small-caps"===i.fontVariant)return"small-caps";if(i.textTransform&&"none"!==i.textTransform)return i.textTransform}e=e.parentElement}return"none"}setCurrentCapitalization(t){this.currentCapitalization=t}static toggleUppercase(){const t="uppercase"===(new nt).getCurrentCapitalization()?"none":"uppercase";nt.applyCapitalizationToCurrentSelection(t)}static toggleLowercase(){const t="lowercase"===(new nt).getCurrentCapitalization()?"none":"lowercase";nt.applyCapitalizationToCurrentSelection(t)}static toggleCapitalize(){const t="capitalize"===(new nt).getCurrentCapitalization()?"none":"capitalize";nt.applyCapitalizationToCurrentSelection(t)}static toggleSmallCaps(){const t="small-caps"===(new nt).getCurrentCapitalization()?"none":"small-caps";nt.applyCapitalizationToCurrentSelection(t)}}class rt{constructor(t={}){this.options={alignments:[{value:"left",label:"Align Left",icon:"align-left"},{value:"center",label:"Align Center",icon:"align-center"},{value:"right",label:"Align Right",icon:"align-right"},{value:"justify",label:"Justify",icon:"align-justify"}],onAlignSelect:null,...t},this.popup=null,this.isVisible=!1,this.currentAlignment="left",this.clickOutsideHandler=null,this.createAlignPicker()}createAlignPicker(){this.popup=document.createElement("div"),this.popup.className="text-align-picker-popup",this.createAlignmentButtons(),q(this.popup)}async createAlignmentButtons(){const t=document.createElement("div");t.className="align-button-container";for(const e of this.options.alignments){const i=document.createElement("button");i.type="button",i.className="align-button",i.dataset.alignment=e.value,i.title=e.label;const o=L.getIcon(e.icon);o?i.innerHTML=`<span class="icon-wrapper">${o}</span>`:i.textContent=e.label.charAt(0),i.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),this.selectAlignment(e.value)}),t.appendChild(i)}this.popup.appendChild(t)}setupClickOutside(){this.clickOutsideHandler&&document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=t=>{this.popup.contains(t.target)||this.hide()},setTimeout(()=>{document.addEventListener("click",this.clickOutsideHandler)},100)}removeClickOutside(){this.clickOutsideHandler&&(document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=null)}show(t){if(!t)return;document.body.contains(this.popup)||q(this.popup),this.updateCurrentAlignment();const e=$(t,this.popup,{offsetY:5,offsetX:0});W(this.popup,e),this.popup.classList.add("visible"),this.isVisible=!0,this.setupClickOutside()}hide(){this.popup.classList.remove("visible"),this.isVisible=!1,this.removeClickOutside()}selectAlignment(t){this.currentAlignment=t,this.options.onAlignSelect&&this.options.onAlignSelect(t),this.hide()}updateCurrentAlignment(){const t=window.getSelection();if(t&&t.rangeCount)try{const e=t.getRangeAt(0),i=this.getSelectedBlockElements(e),o=i.length>0?i[0]:this.getBlockElement(e.commonAncestorContainer);if(o){const t=window.getComputedStyle(o).textAlign;this.currentAlignment="left"!==t&&"start"!==t&&t?t:"left"}else this.currentAlignment="left";this.popup.querySelectorAll(".align-button").forEach(t=>{t.dataset.alignment===this.currentAlignment?t.classList.add("active"):t.classList.remove("active")}),this.updateToolbarButtonIcon(this.currentAlignment)}catch(t){}}getSelectedBlockElements(t){const e=[],i=this.getBlockElement(t.startContainer),o=this.getBlockElement(t.endContainer);if(i&&e.push(i),i&&o&&i!==o){let t=i;for(;t&&t!==o;)t=t.nextElementSibling,t&&this.getBlockElement(t)&&!e.includes(t)&&e.push(t);o&&!e.includes(o)&&e.push(o)}return e}updateToolbarButtonIcon(t){Promise.resolve().then(function(){return at}).then(e=>{e.default.updateToolbarButtonIcon(t)}).catch(t=>{})}getBlockElement(t){if(!t)return null;let e=t;for(;e&&e!==document.body;){if(e.nodeType===Node.ELEMENT_NODE){const t=e.tagName;if(["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","LI"].includes(t))return e}e=e.parentNode}return null}destroy(){this.removeClickOutside(),this.popup&&this.popup.parentNode&&this.popup.parentNode.removeChild(this.popup)}}class st extends H{static formatName="text-align";static tagName="P";static attribute="style";constructor(){super();const t=A.getCurrentInstance();if(!t)return;this.editorId=t.instanceId;let e=t.getPopupInstance("text-align");e||(e=new rt({onAlignSelect:t=>{st.applyAlignToCurrentSelection(t,this.editorId)},editor:t,editorId:this.editorId}),t.setPopupInstance("text-align",e)),this.alignPicker=e}static createForEditor(t){const e=A.getInstanceById(t);if(!e)return null;const i=A.currentInstance;A.currentInstance=e;const o=new st;return A.currentInstance=i,o}static create(t){const e=document.createElement(this.tagName);return t&&"left"!==t&&(e.style.textAlign=t),e}static applyAlignToCurrentSelection(t,e=null){let o=null;if(o=e?A.getInstanceById(e):A.getCurrentInstance(),!o)return;const n=window.getSelection();if(!n||!n.rangeCount)return;z();const r=n.getRangeAt(0),s=r.endContainer,a=r.endOffset;try{const o=n.getRangeAt(0),r=st.getSelectedBlockElements(o);if(0===r.length){i("formatBlock","p");const e=n.getRangeAt(0);st.getSelectedBlockElements(e).forEach(e=>{st.applyAlignmentToBlock(e,t)})}else r.forEach(e=>{st.applyAlignmentToBlock(e,t)});st.updateToolbarButtonIcon(t,e),n.removeAllRanges();const l=document.createRange();l.setStart(s,a),l.collapse(!0),n.addRange(l)}catch(t){}setTimeout(()=>{o&&"function"==typeof o.onContentChange&&o.onContentChange()},0)}static applyAlignmentToBlock(t,e){t.style.textAlign="left"===e?"":e}static getIconNameForAlignment(t){return{left:"align-left",center:"align-center",right:"align-right",justify:"align-justify"}[t]||"align-center"}static updateToolbarButtonIcon(t,e=null){let i=null;if(i=e?A.getInstanceById(e):A.getCurrentInstance(),!i)return;const o=i.getModule("toolbar");let n=null;if(o&&(n=o.getButton("text-align")),!n){const t=o?.getContainer();t&&(n=t.querySelector(".rich-editor-toolbar-btn.text-align-btn"))}if(n||(n=i.wrapper.querySelector(".rich-editor-toolbar-btn.text-align-btn")),!n)return;const r=st.getIconNameForAlignment(t);n.title={left:"Align Left",center:"Align Center",right:"Align Right",justify:"Justify"}[t]||"Text Alignment";const s=L.getIcon(r);if(s){const t=n.querySelector(".icon");t?t.innerHTML=s:n.innerHTML=`<span class="icon">${s}</span>`}}static getSelectedBlockElements(t){const e=[],i=st.getBlockElement(t.startContainer),o=st.getBlockElement(t.endContainer);if(!i||!o)return e;if(i===o)return e.push(i),e;let n=i;for(;n;){const i=document.createRange();if(i.selectNodeContents(n),t.compareBoundaryPoints(Range.END_TO_START,i)<0&&t.compareBoundaryPoints(Range.START_TO_END,i)>0&&e.push(n),n===o)break;n=st.getNextBlockElement(n)}return e}static getBlockElement(t){if(!t)return null;let e=t;for(;e&&e!==document.body;){if(e.nodeType===Node.ELEMENT_NODE){const t=e.tagName;if(["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","LI"].includes(t))return e}e=e.parentNode}return null}static getNextBlockElement(t){let e=t.nextSibling;for(;e;){if(e.nodeType===Node.ELEMENT_NODE){const t=e.tagName;if(["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","LI"].includes(t))return e}e=e.nextSibling}return null}apply(t="left"){st.applyAlignToCurrentSelection(t,this.editorId)}remove(){st.applyAlignToCurrentSelection("left",this.editorId)}toggle(){this.alignPicker.isVisible?this.alignPicker.hide():this.showAlignPicker()}showAlignPicker(){const t=A.getInstanceById(this.editorId);if(!t)return;const e=t.getModule("toolbar");let i=null;if(e&&(i=e.getButton("text-align")),!i){const t=e?.getContainer();t&&(i=t.querySelector(".rich-editor-toolbar-btn.text-align-btn"))}i||(i=t.wrapper.querySelector(".rich-editor-toolbar-btn.text-align-btn")),i&&this.alignPicker.show(i)}isActive(t=null){const e=st.getCurrentAlignment();return st.updateToolbarButtonIcon(e,this.editorId),!!e&&"left"!==e&&"start"!==e}static getCurrentAlignment(){const t=window.getSelection();if(!t||!t.rangeCount)return"left";try{const e=t.getRangeAt(0),i=st.getSelectedBlockElements(e),o=i.length>0?i[0]:st.getBlockElement(e.commonAncestorContainer);if(!o)return"left";const n=window.getComputedStyle(o).textAlign;return"left"!==n&&"start"!==n&&n?n:"left"}catch(t){return"left"}}}var at=Object.freeze({__proto__:null,default:st});class lt{constructor(t={}){this.options={listTypes:[{value:"bullet",label:"Bullet List",icon:"list-bullet"},{value:"ordered",label:"Numbered List",icon:"list-ordered"},{value:"roman",label:"Roman Numerals List",icon:"list-roman"},{value:"alpha",label:"Alphabetical List",icon:"list-alpha"}],onListSelect:null,...t},this.popup=null,this.isVisible=!1,this.currentListType=null,this.clickOutsideHandler=null,this.createListPicker()}createListPicker(){this.popup=document.createElement("div"),this.popup.className="list-picker-popup",this.createListTypeButtons(),q(this.popup)}async createListTypeButtons(){const t=document.createElement("div");t.className="list-button-container";for(const e of this.options.listTypes){const i=document.createElement("button");i.type="button",i.className="list-button",i.dataset.listType=e.value,i.title=e.label;const o=L.getIcon(e.icon);o?i.innerHTML=o:i.textContent=e.label.charAt(0),i.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),this.selectListType(e.value)}),t.appendChild(i)}this.popup.appendChild(t)}setupClickOutside(){this.clickOutsideHandler&&document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=t=>{this.popup.contains(t.target)||this.hide()},setTimeout(()=>{document.addEventListener("click",this.clickOutsideHandler)},100)}removeClickOutside(){this.clickOutsideHandler&&(document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=null)}show(t){if(!t)return;document.body.contains(this.popup)||q(this.popup),this.updateCurrentListType();const e=$(t,this.popup,{offsetY:5,offsetX:0});W(this.popup,e),this.popup.classList.add("visible"),this.isVisible=!0,this.setupClickOutside()}hide(){this.popup.classList.remove("visible"),this.isVisible=!1,this.removeClickOutside()}selectListType(t){this.currentListType=t,this.options.onListSelect&&this.options.onListSelect(t),this.hide()}updateCurrentListType(){try{const t=this.getCurrentListType();this.currentListType=t,this.updateButtonStates(t)}catch(t){}}updateButtonStates(t){this.popup.querySelectorAll(".list-button").forEach(e=>{e.classList.remove("active"),t&&e.dataset.listType===t&&e.classList.add("active")})}updateToolbarButtonIcon(t){const e=document.querySelector(".rich-editor-toolbar-btn.list-btn");if(!e)return;const i={bullet:"list-bullet",ordered:"list-ordered",roman:"list-roman",alpha:"list-alpha"}[t]||"list-bullet";e.title={bullet:"Bullet List",ordered:"Numbered List",roman:"Roman Numerals List",alpha:"Alphabetical List"}[t]||"List";const o=L.getIcon(i);if(o){const t=e.querySelector(".icon");t?t.innerHTML=o:e.innerHTML=`<span class="icon">${o}</span>`}}getParentList(t){let e=t;for(;e&&e!==document.body;){if("UL"===e.tagName||"OL"===e.tagName)return e;e=e.parentElement}return null}getListType(t){if("OL"===t.tagName){const e=t.style.listStyleType;return"upper-roman"===e?"roman":"lower-alpha"===e?"alpha":"ordered"}return"bullet"}getBlockElement(t){if(!t)return null;let e=t;for(;e&&e!==document.body;){if(e.nodeType===Node.ELEMENT_NODE){const t=e.tagName;if(["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","LI","UL","OL"].includes(t))return e}e=e.parentNode}return null}getCurrentListType(){const t=window.getSelection();if(!t||!t.rangeCount)return null;const e=t.getRangeAt(0),i=this.getParentList(e.commonAncestorContainer);return i?this.getListType(i):null}destroy(){this.removeClickOutside(),this.popup&&this.popup.parentNode&&this.popup.parentNode.removeChild(this.popup),this.popup=null,this.isVisible=!1,this.currentListType=null}}class ct extends H{static formatName="list";static tagName="UL";static attribute="class";constructor(){super();const t=A.getCurrentInstance();if(!t)return;this.editorId=t.instanceId;let e=t.getPopupInstance("list");e||(e=new lt({onListSelect:t=>{ct.applyListToCurrentSelection(t,this.editorId)},editor:t,editorId:this.editorId}),t.setPopupInstance("list",e)),this.listPicker=e}static createForEditor(t){const e=A.getInstanceById(t);if(!e)return null;const i=A.currentInstance;A.currentInstance=e;const o=new ct;return A.currentInstance=i,o}static create(t){let e;switch(t){case"ordered":e=document.createElement("OL"),e.style.listStyleType="decimal";break;case"roman":e=document.createElement("OL"),e.style.listStyleType="upper-roman";break;case"alpha":e=document.createElement("OL"),e.style.listStyleType="lower-alpha";break;default:e=document.createElement("UL"),e.style.listStyleType="disc"}return e}static applyListToCurrentSelection(t,e=null){let i=null;if(i=e?A.getInstanceById(e):A.getCurrentInstance(),!i)return;const o=window.getSelection();if(o&&o.rangeCount){z();try{const i=o.getRangeAt(0),n=ct.getSelectedBlockElements(i);0===n.length?ct.createListFromSelection(t):ct.convertBlocksToList(n,t),ct.updateToolbarButtonIcon(t,e)}catch(t){}setTimeout(()=>{i&&"function"==typeof i.onContentChange&&i.onContentChange()},0)}}static createListFromSelection(t){const e=window.getSelection();if(!e||!e.rangeCount)return;const i=e.getRangeAt(0),o=i.toString()||"List item",n=ct.create(t),r=document.createElement("LI");if(i.toString()===i.cloneContents().textContent)r.textContent=o;else{const t=i.cloneContents();r.appendChild(t)}const s=ct.getBlockElement(i.startContainer);s&&s.style&&s.style.cssText&&(r.style.cssText=s.style.cssText),n.appendChild(r),i.deleteContents(),i.insertNode(n);const a=document.createRange();a.selectNodeContents(r),a.collapse(!1),e.removeAllRanges(),e.addRange(a)}static convertBlocksToList(t,e){if(0===t.length)return;const i=ct.getParentList(t[0]);if(i)return void ct.toggleOrChangeListType(i,e);const o=ct.create(e),n=t[0];n.parentNode.insertBefore(o,n);let r=null;if(t.forEach((t,e)=>{const i=document.createElement("LI");i.innerHTML=t.innerHTML||t.textContent||"",t.style&&t.style.cssText&&(i.style.cssText=t.style.cssText),o.appendChild(i),t.remove(),0===e&&(r=i)}),r){const t=document.createRange(),e=window.getSelection();t.selectNodeContents(r),t.collapse(!1),e.removeAllRanges(),e.addRange(t)}}static toggleOrChangeListType(t,e){ct.getListType(t)===e?ct.removeListFormatting(t):ct.changeListType(t,e)}static getListType(t){if("OL"===t.tagName){const e=t.style.listStyleType;return"upper-roman"===e?"roman":"lower-alpha"===e?"alpha":"ordered"}return"bullet"}static changeListType(t,e){const i=ct.create(e);if(Array.from(t.children).forEach(t=>{const e=document.createElement("LI");e.innerHTML=t.innerHTML||t.textContent||"",t.style&&t.style.cssText&&(e.style.cssText=t.style.cssText),i.appendChild(e)}),t.parentNode.replaceChild(i,t),i.firstElementChild){const t=document.createRange(),e=window.getSelection();t.selectNodeContents(i.firstElementChild),t.collapse(!1),e.removeAllRanges(),e.addRange(t)}}static removeListFormatting(t){const e=t.parentNode;let i=null;if(Array.from(t.children).forEach((o,n)=>{const r=document.createElement("P");r.innerHTML=o.innerHTML||o.textContent||"",o.style&&o.style.cssText&&(r.style.cssText=o.style.cssText),e.insertBefore(r,t),0===n&&(i=r)}),t.remove(),i){const t=document.createRange(),e=window.getSelection();t.selectNodeContents(i),t.collapse(!1),e.removeAllRanges(),e.addRange(t)}}static getParentList(t){let e=t;for(;e&&e!==document.body;){if("UL"===e.tagName||"OL"===e.tagName)return e;e=e.parentElement}return null}static getIconNameForListType(t){return{bullet:"list-bullet",ordered:"list-ordered",roman:"list-roman",alpha:"list-alpha"}[t]||"list-bullet"}static updateToolbarButtonIcon(t,e=null){let i=null;if(i=e?A.getInstanceById(e):A.getCurrentInstance(),!i)return;const o=i.getModule("toolbar");let n=null;if(o&&(n=o.getButton("list")),!n){const t=o?.getContainer();t&&(n=t.querySelector(".rich-editor-toolbar-btn.list-btn"))}if(n||(n=i.wrapper.querySelector(".rich-editor-toolbar-btn.list-btn")),!n)return;const r=ct.getIconNameForListType(t);n.title={bullet:"Bullet List",ordered:"Numbered List",roman:"Roman Numerals List",alpha:"Alphabetical List"}[t]||"List";const s=L.getIcon(r);if(s){const t=n.querySelector(".icon");t?t.innerHTML=s:n.innerHTML=`<span class="icon">${s}</span>`}}static getSelectedBlockElements(t){const e=[],i=t.startContainer,o=t.endContainer,n=ct.getBlockElement(i);if(n&&e.push(n),i!==o){let t=n;for(;t&&t!==o;){const i=ct.getNextBlockElement(t);if(!i||e.includes(i))break;e.push(i),t=i}const i=ct.getBlockElement(o);i&&!e.includes(i)&&e.push(i)}return e}static getBlockElement(t){if(!t)return null;let e=t;for(;e&&e!==document.body;){if(e.nodeType===Node.ELEMENT_NODE){const t=e.tagName;if(["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","LI"].includes(t))return e}e=e.parentNode}return null}static getNextBlockElement(t){let e=t.nextSibling;for(;e;){if(e.nodeType===Node.ELEMENT_NODE){const t=e.tagName;if(["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","LI"].includes(t))return e}e=e.nextSibling}return null}apply(t="bullet"){ct.applyListToCurrentSelection(t,this.editorId)}remove(){const t=window.getSelection();if(!t||!t.rangeCount)return;const e=t.getRangeAt(0),i=ct.getParentList(e.commonAncestorContainer);i&&ct.removeListFormatting(i)}toggle(){this.listPicker.isVisible?this.listPicker.hide():this.showListPicker()}showListPicker(){const t=A.getInstanceById(this.editorId);if(!t)return;const e=t.getModule("toolbar");let i=null;if(e&&(i=e.getButton("list")),!i){const t=e?.getContainer();t&&(i=t.querySelector(".rich-editor-toolbar-btn.list-btn"))}i||(i=t.wrapper.querySelector(".rich-editor-toolbar-btn.list-btn")),i&&this.listPicker.show(i)}isActive(t=null){const e=ct.getCurrentListType();return e?ct.updateToolbarButtonIcon(e,this.editorId):ct.updateToolbarButtonIcon("bullet",this.editorId),!!e}static getCurrentListType(){const t=window.getSelection();if(!t||!t.rangeCount)return null;const e=t.getRangeAt(0),i=ct.getParentList(e.commonAncestorContainer);return i?ct.getListType(i):null}getCurrentListType(){return ct.getCurrentListType()}}class dt extends H{static formatName="indent";static tagName="DIV";static attribute="style";constructor(){super()}static create(t){const e=document.createElement("DIV");return t&&(e.style.paddingLeft=t),e}static applyIndentToCurrentSelection(t){const e=window.getSelection();if(e&&e.rangeCount){z();try{const i=e.getRangeAt(0),o=dt.getSelectedBlockElements(i);if(0===o.length){const o=document.createElement("DIV");o.style.paddingLeft="increase"===t?"20px":"0px";const n=i.toString()||"";n?(o.textContent=n,i.deleteContents(),i.insertNode(o)):(i.insertNode(o),o.innerHTML="<br>");const r=document.createRange();r.selectNodeContents(o),r.collapse(!1),e.removeAllRanges(),e.addRange(r)}else o.forEach(e=>{dt.applyIndentToBlock(e,t)})}catch(t){}setTimeout(()=>{const t=A.getCurrentInstance();t&&"function"==typeof t.onContentChange&&t.onContentChange()},0)}}static applyIndentToBlock(t,e){if(!t||!t.style)return;const i=parseInt(t.style.paddingLeft)||0;let o;o="increase"===e?i+20:Math.max(0,i-20),t.style.paddingLeft=0===o?"":o+"px"}static getSelectedBlockElements(t){const e=[],i=t.startContainer,o=t.endContainer,n=dt.getBlockElement(i);if(n&&e.push(n),i!==o){let t=n;for(;t&&t!==o;){const i=dt.getNextBlockElement(t);if(!i||e.includes(i))break;e.push(i),t=i}const i=dt.getBlockElement(o);i&&!e.includes(i)&&e.push(i)}return e}static getBlockElement(t){if(!t)return null;let e=t;for(;e&&e!==document.body;){if(e.nodeType===Node.ELEMENT_NODE){const t=e.tagName;if(["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","LI"].includes(t))return e}e=e.parentNode}return null}static getNextBlockElement(t){let e=t.nextSibling;for(;e;){if(e.nodeType===Node.ELEMENT_NODE){const t=e.tagName;if(["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","LI"].includes(t))return e}e=e.nextSibling}return null}apply(t="increase"){dt.applyIndentToCurrentSelection(t)}remove(){dt.applyIndentToCurrentSelection("remove")}isActive(){const t=window.getSelection();if(!t||!t.rangeCount)return!1;const e=t.getRangeAt(0),i=dt.getBlockElement(e.commonAncestorContainer);if(!i)return!1;return(parseInt(i.style.paddingLeft)||0)>0}static getCurrentIndentLevel(){const t=window.getSelection();if(!t||!t.rangeCount)return 0;const e=t.getRangeAt(0),i=dt.getBlockElement(e.commonAncestorContainer);return i&&parseInt(i.style.paddingLeft)||0}getCurrentIndentLevel(){return dt.getCurrentIndentLevel()}}class pt extends dt{static formatName="indent-increase";apply(){dt.applyIndentToCurrentSelection("increase")}toggle(){this.apply()}isActive(){return!1}}class ht extends dt{static formatName="indent-decrease";apply(){dt.applyIndentToCurrentSelection("decrease")}toggle(){this.apply()}isActive(){return!1}}class ut{constructor(t={}){this.options={emojis:["😀","😁","😂","🤣","😃","😄","😅","😆","😉","😊","😋","😎","😍","🥰","😘","😗","😙","😚","🙂","🤗","😳","🥺","😦","😧","😨","😰","😥","😢","😭","😱","🤬","😈","👿","💀","☠️","💩","🤡","👹","👺","👻"],onEmojiSelect:null,...t},this.popup=null,this.isVisible=!1,this.clickOutsideHandler=null,this.createEmojiPicker()}detectOS(){const t=navigator.platform.toLowerCase();return t.includes("mac")?"mac":(t.includes("win"),"windows")}getEmojiShortcutMessage(){return"mac"===this.detectOS()?'<div style="color: rgb(113, 120, 124); font-style: normal; font-weight: 400; line-height: normal; text-align: center;">Get more emojis with <span style="border-radius: 2.2px; background: #EEE; padding: 2px 4px;">⌘</span> <span style="color: #000;">+</span> <span style="border-radius: 2.2px; background: #EEE; padding: 2px 4px;">CTRL</span> <span style="color: #000;">+</span> <span style="border-radius: 2.2px; background: #EEE; padding: 2px 4px;">SPACE</span></div>':'<div style="color: rgb(113, 120, 124); font-style: normal; font-weight: 400; line-height: normal; text-align: center;">Get more emojis with <span style="border-radius: 2.2px; background: #EEE; padding: 2px 4px;">WIN</span> <span style="color: #000;">+</span> <span style="border-radius: 2.2px; background: #EEE; padding: 2px 4px;">.</span></div>'}createEmojiPicker(){this.popup=document.createElement("div"),this.popup.className="emoji-picker-popup",this.createEmojiGrid();const t=document.createElement("div");t.className="emoji-text-message",t.innerHTML=this.getEmojiShortcutMessage(),this.popup.appendChild(t),q(this.popup)}createEmojiGrid(){const t=document.createElement("div");t.className="emoji-grid",this.options.emojis.forEach(e=>{const i=document.createElement("button");i.type="button",i.className="emoji-button",i.textContent=e,i.title=e,i.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),this.selectEmoji(e)}),t.appendChild(i)}),this.popup.appendChild(t)}setupClickOutside(){this.clickOutsideHandler&&document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=t=>{this.popup.contains(t.target)||this.hide()},setTimeout(()=>{document.addEventListener("click",this.clickOutsideHandler)},100)}removeClickOutside(){this.clickOutsideHandler&&(document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=null)}show(t){if(!t)return;document.body.contains(this.popup)||q(this.popup);const e=$(t,this.popup,{offsetY:5,offsetX:0});W(this.popup,e),this.popup.classList.add("visible"),this.isVisible=!0,this.setupClickOutside()}hide(){this.popup.classList.remove("visible"),this.isVisible=!1,this.removeClickOutside()}selectEmoji(t){this.options.onEmojiSelect&&this.options.onEmojiSelect(t),this.hide()}destroy(){this.removeClickOutside(),this.popup&&this.popup.parentNode&&this.popup.parentNode.removeChild(this.popup),this.popup=null,this.isVisible=!1}}class mt extends R{static formatName="emoji";static tagName="SPAN";static className="emoji";constructor(){super();const t=A.getCurrentInstance();if(!t)return;this.editorId=t.instanceId;let e=t.getPopupInstance("emoji");e||(e=new ut({onEmojiSelect:t=>{mt.insertEmojiAtCurrentPosition(t,this.editorId)},editor:t,editorId:this.editorId}),t.setPopupInstance("emoji",e)),this.emojiPicker=e}static createForEditor(t){const e=A.getInstanceById(t);if(!e)return null;const i=A.currentInstance;A.currentInstance=e;const o=new mt;return A.currentInstance=i,o}static create(t){const e=document.createElement("SPAN");return e.className="emoji",e.textContent=t,e.setAttribute("data-emoji",t),e}static insertEmojiAtCurrentPosition(t,e=null){let i=null;if(i=e?A.getInstanceById(e):A.getCurrentInstance(),!i)return;const o=window.getSelection();if(o&&o.rangeCount)try{const e=o.getRangeAt(0);let n=e.startContainer,r=null;for(n.nodeType===Node.TEXT_NODE&&(n=n.parentNode);n&&n!==i.element;){if(n.classList&&n.classList.contains("emoji")){r=n;break}n=n.parentNode}r&&(e.setStartAfter(r),e.collapse(!0),o.removeAllRanges(),o.addRange(e));const s=mt.create(t);e.deleteContents(),e.insertNode(s);const a=document.createTextNode("​");e.setStartAfter(s),e.insertNode(a),e.setStartAfter(a),e.collapse(!0),o.removeAllRanges(),o.addRange(e),i&&"function"==typeof i.onContentChange&&i.onContentChange()}catch(t){}}apply(t){t?mt.insertEmojiAtCurrentPosition(t,this.editorId):this.showEmojiPicker()}remove(){const t=window.getSelection();if(!t||!t.rangeCount)return;const e=t.getRangeAt(0),i=this.getEmojiElement(e);if(i){const t=document.createTextNode(i.textContent);i.parentNode.replaceChild(t,i)}}toggle(){this.emojiPicker.isVisible?this.emojiPicker.hide():this.showEmojiPicker()}showEmojiPicker(){const t=A.getInstanceById(this.editorId);if(!t)return;const e=t.getModule("toolbar");let i=null;if(e&&(i=e.getButton("emoji")),!i){const t=e?.getContainer();t&&(i=t.querySelector(".rich-editor-toolbar-btn.emoji-btn"))}i||(i=t.wrapper.querySelector(".rich-editor-toolbar-btn.emoji-btn")),i&&this.emojiPicker.show(i)}isActive(){const t=window.getSelection();if(!t||!t.rangeCount)return!1;const e=t.getRangeAt(0);return null!==this.getEmojiElement(e)}getEmojiElement(t){let e=t.commonAncestorContainer;if(e.nodeType===Node.TEXT_NODE&&(e=e.parentNode),e.classList&&e.classList.contains("emoji"))return e;const i=t.cloneContents().querySelector(".emoji");return i||null}}class gt extends R{static formatName="image";static tagName="IMG";static className="inserted-image";constructor(){super();const t=A.getCurrentInstance();t&&(this.editorId=t.instanceId)}static createForEditor(t){const e=A.getInstanceById(t);if(!e)return null;const i=A.currentInstance;A.currentInstance=e;const o=new gt;return A.currentInstance=i,o}static create(t,e=""){if(!a(t,{allowDataImage:!0}))return null;const i=document.createElement("IMG");return i.src=t,i.alt=e||"Inserted image",i.className="inserted-image",i.style.maxWidth="100%",i.style.height="auto",i.setAttribute("contenteditable","false"),i}static insertImageAtCurrentPosition(t,e="",i=null){let o=null;if(o=i?A.getInstanceById(i):A.getCurrentInstance(),!o)return;const n=window.getSelection();if(n){if(!n.rangeCount||!o.editor.contains(n.anchorNode)){const t=document.createRange();t.selectNodeContents(o.editor),t.collapse(!1),n.removeAllRanges(),n.addRange(t)}try{const i=n.getRangeAt(0),r=gt.create(t,e);if(!r)return;i.deleteContents(),i.insertNode(r);const s=document.createTextNode(" ");i.setStartAfter(r),i.insertNode(s),i.setStartAfter(s),i.collapse(!0),n.removeAllRanges(),n.addRange(i),o&&"function"==typeof o.onContentChange&&o.onContentChange()}catch(t){}setTimeout(()=>{const t=A.getCurrentInstance();t&&"function"==typeof t.onContentChange&&t.onContentChange()},0)}}apply(t,e){t?gt.insertImageAtCurrentPosition(t,e,this.editorId):this.openFilePicker()}openFilePicker(){const t=A.getInstanceById(this.editorId);if(!t)return;const e=window.getSelection(),i=e&&e.rangeCount?e.getRangeAt(0).cloneRange():null,o=document.createElement("input");o.type="file",o.accept=t.options.image&&t.options.image.accept||"image/*",o.style.display="none",o.addEventListener("change",()=>{const e=o.files&&o.files[0];if(e){t.focus();const o=window.getSelection();if(i)o.removeAllRanges(),o.addRange(i);else if(!o.rangeCount||!t.editor.contains(o.anchorNode)){const e=document.createRange();e.selectNodeContents(t.editor),e.collapse(!1),o.removeAllRanges(),o.addRange(e)}t.insertImageFile(e)}o.remove()}),document.body.appendChild(o),o.click()}remove(){const t=window.getSelection();if(!t||!t.rangeCount)return;const e=t.getRangeAt(0),i=this.getImageElement(e);i&&i.remove()}toggle(){this.openFilePicker()}isActive(){const t=window.getSelection();if(!t||!t.rangeCount)return!1;const e=t.getRangeAt(0);return null!==this.getImageElement(e)}getImageElement(t){let e=t.commonAncestorContainer;if(e.nodeType===Node.TEXT_NODE&&(e=e.parentNode),"IMG"===e.tagName&&e.classList&&e.classList.contains("inserted-image"))return e;const i=t.cloneContents().querySelector(".inserted-image");return i||null}static async handleFileUpload(t){return new Promise((e,i)=>{if(!t||!t.type.startsWith("image/"))return void i(new Error("Please select a valid image file"));const o=new FileReader;o.onload=t=>{e(t.target.result)},o.onerror=()=>{i(new Error("Failed to read file"))},o.readAsDataURL(t)})}static validateImageUrl(t){return new Promise(e=>{const i=["jpg","jpeg","png","gif","bmp","webp","svg"].some(e=>t.toLowerCase().includes(`.${e}`));if(t.startsWith("data:image/"))return void e(!0);if(!/^https?:\/\//.test(t))return void e(!1);if(i)return void e(!0);const o=new gt;o.onload=()=>{e(!0)},o.onerror=()=>{t.includes("imgur.com")||t.includes("drive.google.com")||i?e(!0):e(!1)},setTimeout(()=>{i||t.includes("imgur.com")||t.includes("drive.google.com")?e(!0):e(!1)},5e3),o.src=t})}}var ft=Object.freeze({__proto__:null,default:gt});class yt{constructor(t={}){this.options={onVideoInsert:null,editor:null,...t},this.popup=null,this.isVisible=!1,this.clickOutsideHandler=null,this.selectedVideoSrc=null,this.savedSelection=null,this.createVideoPopup()}createVideoPopup(){this.popup=document.createElement("div"),this.popup.className="video-popup";const t=document.createElement("div");t.className="video-popup-content";const e=document.createElement("h3");e.textContent="Insert video",e.className="yjd-input-title",t.appendChild(e);const i=document.createElement("div");i.className="video-input-container";const o=document.createElement("p");o.textContent="Your video url",o.className="yjd-input-label";const n=document.createElement("div");n.className="yjd-input-upload-group",this.inputGroup=n,this.urlInput=document.createElement("input"),this.urlInput.type="url",this.urlInput.className="yjd-input",this.urlInput.placeholder="Please enter your video URL",this.urlInput.addEventListener("input",()=>{this.updateInsertButton();const t=this.urlInput.value.trim();t&&this.isValidVideoUrl(t)?this.showPreview(t):this.removePreview(),this.urlInput.value.trim()?this.customButton.style.display="none":this.customButton.style.display="block"}),this.fileInput=document.createElement("input"),this.fileInput.type="file",this.fileInput.accept="video/*",this.fileInput.className="image-input-hidden",this.fileInput.addEventListener("change",t=>this.handleFileSelect(t));const r=document.createElement("button");r.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" x2="12" y1="3" y2="15"/></svg>',r.className="yjd-custom-upload-button",this.customButton=r,r.addEventListener("click",()=>this.fileInput.click()),this.createPreviewContainer(),n.appendChild(this.urlInput),n.appendChild(this.fileInput),n.appendChild(r),i.appendChild(o),i.appendChild(n),i.appendChild(this.previewContainer),t.appendChild(i);const s=document.createElement("div");s.className="yjd-button-container";const a=document.createElement("button");a.type="button",a.className="image-button yjd-button-cancel",a.textContent="Cancel",a.addEventListener("click",()=>{this.hide(),this.options.editor&&setTimeout(()=>this.options.editor.focus(),0)}),this.insertButton=document.createElement("button"),this.insertButton.type="button",this.insertButton.className="image-button yjd-button-confirm button-disable",this.insertButton.textContent="Add video",this.insertButton.disabled=!0,this.insertButton.addEventListener("click",()=>{this.insertVideo(),this.options.editor&&setTimeout(()=>this.options.editor.focus(),0)}),s.appendChild(a),s.appendChild(this.insertButton),t.appendChild(s),this.popup.appendChild(t),q(this.popup),this.options.editor&&"function"==typeof this.options.editor.preventFocusLoss&&this.options.editor.preventFocusLoss(this.popup)}async handleFileSelect(t){const e=t.target.files[0];if(e)try{const{default:t}=await Promise.resolve().then(function(){return vt});this.selectedVideoSrc=await t.handleFileUpload(e),this.urlInput.value="",this.showPreview(this.selectedVideoSrc),this.updateInsertButton()}catch(t){alert(t.message)}}updateInsertButton(){const t=this.selectedVideoSrc||this.urlInput.value.trim();this.insertButton.disabled=!t,this.insertButton.classList.toggle("button-disable",!t)}showPreview(t){t&&(this.videoPreview.src=t,this.previewContainer.style.display="block",this.selectedVideoSrc=t,this.toggleInputGroup(!1),this.recalculatePosition())}removePreview(){this.selectedVideoSrc=null,this.previewContainer.style.display="none",this.videoPreview.src="",this.toggleInputGroup(!0),this.fileInput&&(this.fileInput.value=""),this.updateInsertButton(),this.recalculatePosition()}toggleInputGroup(t){this.inputGroup&&(t?(this.inputGroup.style.display="flex",this.inputGroup.style.visibility="visible",this.customButton&&(this.customButton.style.pointerEvents="auto")):(this.inputGroup.style.display="none",this.inputGroup.style.visibility="hidden"))}createPreviewContainer(){this.previewContainer=document.createElement("div"),this.previewContainer.className="video-preview-container",this.previewContainer.style.cssText="display: none; position: relative;",this.videoPreview=document.createElement("video"),this.videoPreview.className="video-preview",this.videoPreview.style.cssText="max-width: 100%; max-height: 200px; border-radius: 8px; object-fit: contain;",this.videoPreview.controls=!0,this.videoPreview.muted=!0,this.removeButton=document.createElement("button"),this.removeButton.className="video-remove-button",this.removeButton.innerHTML="×",this.removeButton.style.cssText="\n position: absolute; top: 5px; right: 5px; background: rgba(0,0,0,0.7);\n color: white; border: none; border-radius: 50%; width: 24px; height: 24px;\n cursor: pointer; font-size: 16px; font-weight: bold;\n ",this.removeButton.addEventListener("click",()=>this.removePreview()),this.previewContainer.appendChild(this.videoPreview),this.previewContainer.appendChild(this.removeButton)}isValidVideoUrl(t){try{const e=new URL(t),i=[".mp4",".webm",".ogg",".mov",".avi",".mkv"],o=["youtube.com","youtu.be","vimeo.com","dailymotion.com"],n=e.pathname.toLowerCase(),r=i.some(t=>n.endsWith(t)),s=o.some(t=>e.hostname.includes(t));return r||s}catch{return!1}}async insertVideo(){let t=this.selectedVideoSrc||this.urlInput.value.trim();if(t){try{const{default:e}=await Promise.resolve().then(function(){return vt});if(!await e.validateVideoUrl(t))return void alert("Invalid video URL. Please check the URL and try again.")}catch(t){return void alert("Error validating video URL.")}this.restoreSelection(),this.options.onVideoInsert&&this.options.onVideoInsert(t),this.hide(),this.reset()}}reset(){this.fileInput.value="",this.urlInput.value="",this.selectedVideoSrc=null,this.previewContainer.style.display="none",this.videoPreview.src="",this.toggleInputGroup(!0),this.updateInsertButton(),this.customButton.style.display="block"}saveSelection(){const t=window.getSelection();t&&t.rangeCount>0&&(this.savedSelection=t.getRangeAt(0).cloneRange())}restoreSelection(){if(this.savedSelection){const t=window.getSelection();t.removeAllRanges(),t.addRange(this.savedSelection)}}setupClickOutside(){this.clickOutsideHandler&&document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=t=>{this.popup.contains(t.target)||this.hide()},setTimeout(()=>{document.addEventListener("click",this.clickOutsideHandler)},100)}removeClickOutside(){this.clickOutsideHandler&&(document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=null)}show(t){if(!t)return;this.saveSelection(),this.reset(),this.currentAnchor=t;const e=$(t,this.popup,{offsetY:5,offsetX:0});W(this.popup,e),this.popup.classList.add("visible"),this.isVisible=!0,this.setupClickOutside()}recalculatePosition(){this.currentAnchor&&this.isVisible&&setTimeout(()=>{const t=$(this.currentAnchor,this.popup,{offsetY:5,offsetX:0});W(this.popup,t)},10)}hide(){this.popup.classList.remove("visible"),this.isVisible=!1,this.removeClickOutside(),this.savedSelection=null}destroy(){this.removeClickOutside(),this.popup&&this.popup.parentNode&&this.popup.parentNode.removeChild(this.popup),this.popup=null,this.isVisible=!1}}class bt extends R{static formatName="video";static tagName="VIDEO";static className="inserted-video";constructor(){super();const t=A.getCurrentInstance();if(!t)return;this.editorId=t.instanceId;let e=t.getPopupInstance("video");e||(e=new yt({onVideoInsert:t=>{bt.insertVideoAtCurrentPosition(t,this.editorId)},editor:t,editorId:this.editorId}),t.setPopupInstance("video",e)),this.videoPopup=e}static createForEditor(t){const e=A.getInstanceById(t);if(!e)return null;const i=A.currentInstance;A.currentInstance=e;const o=new bt;return A.currentInstance=i,o}static create(t){if(bt.isYouTubeUrl(t))return bt.createYouTubeEmbed(t);if(!a(t))return null;const e=document.createElement("VIDEO");return e.src=t,e.className="inserted-video",e.controls=!0,e.style.maxWidth="100%",e.style.height="auto",e.setAttribute("contenteditable","false"),e}static createYouTubeEmbed(t){const e=bt.getYouTubeVideoId(t);if(!e)throw new Error("Invalid YouTube URL");const i=document.createElement("IFRAME");return i.src=`https://www.youtube.com/embed/${e}`,i.className="inserted-video youtube-video",i.width="560",i.height="315",i.style.maxWidth="100%",i.style.width="560px",i.style.height="315px",i.style.position="relative",i.style.display="block",i.setAttribute("frameborder","0"),i.setAttribute("allowfullscreen",""),i.setAttribute("contenteditable","false"),i}static insertVideoAtCurrentPosition(t,e=null){let i=null;if(i=e?A.getInstanceById(e):A.getCurrentInstance(),!i)return;const o=window.getSelection();if(o&&o.rangeCount)try{const e=o.getRangeAt(0),n=bt.create(t);if(!n)return;e.deleteContents(),e.insertNode(n);const r=document.createTextNode(" ");e.setStartAfter(n),e.insertNode(r),e.setStartAfter(r),e.collapse(!0),o.removeAllRanges(),o.addRange(e),i&&"function"==typeof i.onContentChange&&i.onContentChange()}catch(t){}}apply(t){t?bt.insertVideoAtCurrentPosition(t,this.editorId):this.showVideoPopup()}remove(){const t=window.getSelection();if(!t||!t.rangeCount)return;const e=t.getRangeAt(0),i=this.getVideoElement(e);i&&i.remove()}toggle(){this.videoPopup.isVisible?this.videoPopup.hide():this.showVideoPopup()}showVideoPopup(){const t=A.getInstanceById(this.editorId);if(!t)return;const e=t.getModule("toolbar");let i=null;if(e&&(i=e.getButton("video")),!i){const t=e?.getContainer();t&&(i=t.querySelector(".rich-editor-toolbar-btn.video-btn"))}i||(i=t.wrapper.querySelector(".rich-editor-toolbar-btn.video-btn")),i&&this.videoPopup.show(i)}isActive(){const t=window.getSelection();if(!t||!t.rangeCount)return!1;const e=t.getRangeAt(0);return null!==this.getVideoElement(e)}getVideoElement(t){let e=t.commonAncestorContainer;if(e.nodeType===Node.TEXT_NODE&&(e=e.parentNode),("VIDEO"===e.tagName||"IFRAME"===e.tagName)&&e.classList&&e.classList.contains("inserted-video"))return e;const i=t.cloneContents().querySelector(".inserted-video");return i||null}static async handleFileUpload(t){return new Promise((e,i)=>{if(!t||!t.type.startsWith("video/"))return void i(new Error("Please select a valid video file"));const o=new FileReader;o.onload=t=>{e(t.target.result)},o.onerror=()=>{i(new Error("Failed to read file"))},o.readAsDataURL(t)})}static validateVideoUrl(t){return new Promise(e=>{if(bt.isYouTubeUrl(t))return void e(!0);if(["mp4","webm","ogg","mov","avi","mkv"].some(e=>t.toLowerCase().includes(`.${e}`)))return void e(!0);const i=document.createElement("video");i.onloadedmetadata=()=>{e(!0)},i.onerror=()=>{e(!1)},setTimeout(()=>{e(!1)},5e3),i.src=t})}static isYouTubeUrl(t){return/(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/embed\/)([a-zA-Z0-9_-]{11})/.test(t)}static getYouTubeVideoId(t){const e=t.match(/(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/embed\/)([a-zA-Z0-9_-]{11})/);return e?e[1]:null}}var vt=Object.freeze({__proto__:null,default:bt});class xt{constructor(t={}){this.options={onTagInsert:null,editor:null,...t},this.popup=null,this.isVisible=!1,this.clickOutsideHandler=null,this.selectedTagType="mention",this.createTagPopup()}createTagPopup(){this.popup=document.createElement("div"),this.popup.className="tag-popup";const t=document.createElement("div");t.className="tag-popup-content";const e=document.createElement("h3");e.textContent="Insert tags",e.className="yjd-input-title",t.appendChild(e);const i=document.createElement("div");i.className="yjd-input-group";const o=document.createElement("label");o.textContent="Type",o.className="yjd-input-label",this.typeSelect=document.createElement("select"),this.typeSelect.className="yjd-select-input",this.typeSelect.innerHTML='\n <option value="mention">Mention</option>\n <option value="hashtag">Hashtag</option>\n <option value="custom">Custom</option>\n ',this.typeSelect.addEventListener("change",()=>this.updateSuggestions()),i.appendChild(o),i.appendChild(this.typeSelect),t.appendChild(i);const n=document.createElement("div");n.className="yjd-input-group";const r=document.createElement("label");r.textContent="Content",r.className="yjd-input-label",this.contentInput=document.createElement("input"),this.contentInput.type="text",this.contentInput.className="yjd-input",this.contentInput.placeholder="Please enter tag content",this.contentInput.addEventListener("input",()=>this.updateInsertButton()),this.contentInput.addEventListener("keydown",t=>{"Enter"===t.key&&(t.preventDefault(),this.insertTag())}),n.appendChild(r),n.appendChild(this.contentInput),t.appendChild(n);const s=document.createElement("div");s.className="yjd-input-group",this.suggestionsContainer=document.createElement("div"),this.suggestionsContainer.className="tag-suggestions-container";const a=document.createElement("label");a.textContent="Suggestions",a.className="yjd-input-label",this.suggestionsList=document.createElement("div"),this.suggestionsList.className="yjd-suggestions-list",this.suggestionsContainer.appendChild(this.suggestionsList),s.appendChild(a),s.appendChild(this.suggestionsContainer),t.appendChild(s);const l=document.createElement("div");l.className="yjd-button-container";const c=document.createElement("button");c.type="button",c.className="yjd-button-cancel",c.textContent="Cancel",c.addEventListener("click",()=>this.hide()),this.insertButton=document.createElement("button"),this.insertButton.type="button",this.insertButton.className="yjd-button-confirm",this.insertButton.textContent="Insert Tag",this.insertButton.disabled=!0,this.insertButton.addEventListener("click",()=>this.insertTag()),l.appendChild(c),l.appendChild(this.insertButton),t.appendChild(l),this.popup.appendChild(t),q(this.popup),this.options.editor&&"function"==typeof this.options.editor.preventFocusLoss&&this.options.editor.preventFocusLoss(this.popup),this.updateSuggestions()}updateSuggestions(){this.selectedTagType=this.typeSelect.value,this.suggestionsList.innerHTML="";this.getSuggestions(this.selectedTagType).forEach(t=>{const e=document.createElement("button");e.type="button",e.className="yjd-suggestion-button",e.textContent=t,e.addEventListener("click",()=>{this.contentInput.value=t,this.updateInsertButton(),this.contentInput.focus()}),this.suggestionsList.appendChild(e)})}getSuggestions(t){return{mention:["john","admin","team","support"],hashtag:["urgent","done","important"],custom:["warning","info","success"]}[t]||[]}updateInsertButton(){const t=this.contentInput.value.trim();this.insertButton.disabled=!t}insertTag(){const t=this.contentInput.value.trim();t&&(this.options.onTagInsert&&this.options.onTagInsert(this.selectedTagType,t),this.hide(),this.reset())}reset(){this.contentInput.value="",this.typeSelect.value="mention",this.selectedTagType="mention",this.updateInsertButton(),this.updateSuggestions()}setupClickOutside(){this.clickOutsideHandler&&document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=t=>{this.popup.contains(t.target)||this.hide()},setTimeout(()=>{document.addEventListener("click",this.clickOutsideHandler)},100)}removeClickOutside(){this.clickOutsideHandler&&(document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=null)}show(t){if(!t)return;const e=$(t,this.popup,{offsetY:5,offsetX:0});W(this.popup,e),this.popup.classList.add("visible"),this.isVisible=!0,this.setupClickOutside(),setTimeout(()=>{this.contentInput.focus()},100)}hide(){this.popup.classList.remove("visible"),this.isVisible=!1,this.removeClickOutside()}destroy(){this.removeClickOutside(),this.popup&&this.popup.parentNode&&this.popup.parentNode.removeChild(this.popup),this.popup=null,this.isVisible=!1}}class wt extends R{static formatName="tag";static tagName="SPAN";static className="custom-tag";static savedRanges=new Map;constructor(){super();const t=A.getCurrentInstance();if(!t)return;this.editorId=t.instanceId;let e=t.getPopupInstance("tag");e||(e=new xt({onTagInsert:(t,e)=>{wt.insertTagAtCurrentPosition(t,e,this.editorId)},editor:t,editorId:this.editorId}),t.setPopupInstance("tag",e)),this.tagPopup=e}static createForEditor(t){const e=A.getInstanceById(t);if(!e)return null;const i=A.currentInstance;A.currentInstance=e;const o=new wt;return A.currentInstance=i,o}static create(t,e){const i=document.createElement("SPAN");i.className=`custom-tag tag-${t}`;let o=e;return"mention"===t?o=`@${e}`:"hashtag"===t?o=`#${e}`:"custom"===t&&(o=`<${e}>`),i.textContent=o,i.setAttribute("data-tag-type",t),i.setAttribute("data-tag-content",e),i.setAttribute("contenteditable","false"),i}static insertTagAtCurrentPosition(t,e,i=null){let o=null;if(o=i?A.getInstanceById(i):A.getCurrentInstance(),!o)return;const n=window.getSelection();if(n)try{const r=wt.savedRanges.get(i);if(r)n.removeAllRanges(),n.addRange(r),wt.savedRanges.delete(i);else if(!n.rangeCount)return;const s=n.getRangeAt(0),a=wt.create(t,e);s.deleteContents(),s.insertNode(a);const l=document.createTextNode(" ");s.setStartAfter(a),s.insertNode(l),s.setStartAfter(l),s.collapse(!0),n.removeAllRanges(),n.addRange(s),o&&o.element&&o.element.focus(),o&&"function"==typeof o.onContentChange&&o.onContentChange()}catch(t){}}apply(t,e){if(t&&e)wt.insertTagAtCurrentPosition(t,e,this.editorId);else{const t=window.getSelection();t&&t.rangeCount>0&&wt.savedRanges.set(this.editorId,t.getRangeAt(0).cloneRange()),this.showTagPopup()}}remove(){const t=window.getSelection();if(!t||!t.rangeCount)return;const e=t.getRangeAt(0),i=this.getTagElement(e);if(i){const t=document.createTextNode(i.textContent);i.parentNode.replaceChild(t,i)}}toggle(){if(this.tagPopup.isVisible)this.tagPopup.hide();else{const t=window.getSelection();t&&t.rangeCount>0&&wt.savedRanges.set(this.editorId,t.getRangeAt(0).cloneRange()),this.showTagPopup()}}showTagPopup(){const t=A.getInstanceById(this.editorId);if(!t)return;const e=t.getModule("toolbar");let i=null;if(e&&(i=e.getButton("tag")),!i){const t=e?.getContainer();t&&(i=t.querySelector(".rich-editor-toolbar-btn.tag-btn"))}i||(i=t.wrapper.querySelector(".rich-editor-toolbar-btn.tag-btn")),i&&this.tagPopup.show(i)}isActive(){const t=window.getSelection();if(!t||!t.rangeCount)return!1;const e=t.getRangeAt(0);return null!==this.getTagElement(e)}getTagElement(t){let e=t.commonAncestorContainer;if(e.nodeType===Node.TEXT_NODE&&(e=e.parentNode),e.classList&&e.classList.contains("custom-tag"))return e;return t.cloneContents().querySelector(".custom-tag")||null}static getSuggestions(t){return{mention:["john","sarah","admin","team","support"],hashtag:["urgent","todo","done","review","important"],custom:["note","warning","tip","info","success"]}[t]||[]}}class Ct extends R{static formatName="textSize";static tagName="SPAN";constructor(){super();const t=A.getCurrentInstance();if(!t)return;this.editorId=t.instanceId;let e=t.getPopupInstance("text-size");if(!e){const i=Ct.getSizeMap(),o=Object.values(i).map(t=>({value:t.size,label:t.element,title:t.title}));e=new tt({items:o,displayProperty:"label",valueProperty:"value",className:"text-size-select",onItemSelect:t=>{Ct.applyTextSizeToCurrentSelection(t,this.editorId)},editor:t,editorId:this.editorId}),t.setPopupInstance("text-size",e)}this.customSelect=e}static createForEditor(t){const e=A.getInstanceById(t);if(!e)return null;const i=A.currentInstance;A.currentInstance=e;const o=new Ct;return A.currentInstance=i,o}static getSizeMap(){return{1:{size:"1",element:"<span >XX-Small</span>",title:"XX-Small"},2:{size:"2",element:"<span >X-Small</span>",title:"X-Small"},3:{size:"3",element:"<span >Small</span>",title:"Small"},4:{size:"4",element:"<span >Medium</span>",title:"Medium"},5:{size:"5",element:"<span >Large</span>",title:"Large"},6:{size:"6",element:"<span >X-Large</span>",title:"X-Large"},7:{size:"7",element:"<span >XX-Large</span>",title:"XX-Large"}}}static getSizeDisplayName(t){const e=this.getSizeMap();return e[t]?.title||"Medium"}updateButtonText(){const t=this.getCurrentSize(),e=Ct.getSizeDisplayName(t||"4"),i=A.getInstanceById(this.editorId);if(!i)return;const o=i.getModule("toolbar");let n=null;if(o&&(n=o.getButton("text-size")),!n){const t=o?.getContainer();t&&(n=t.querySelector(".rich-editor-toolbar-btn.text-size-btn"))}n||(n=i.wrapper.querySelector(".rich-editor-toolbar-btn.text-size-btn")),n&&n.updateText?n.updateText(e):n&&(n.textContent=e)}static updateButtonTextStatic(t=null){let e=null;if(e=t?A.getInstanceById(t):A.getCurrentInstance(),!e)return;const i=Ct.getCurrentSizeStatic(),o=Ct.getSizeDisplayName(i||"4"),n=e.getModule("toolbar");let r=null;if(n&&(r=n.getButton("text-size")),!r){const t=n?.getContainer();t&&(r=t.querySelector(".rich-editor-toolbar-btn.text-size-btn"))}r||(r=e.wrapper.querySelector(".rich-editor-toolbar-btn.text-size-btn")),r&&r.updateText?r.updateText(o):r&&(r.textContent=o)}static create(t="4"){const e=document.createElement("span");return e.style.fontSize=Ct.sizeToCss(t),e}static applyTextSizeToCurrentSelection(t,e=null){let i=null;if(i=e?A.getInstanceById(e):A.getCurrentInstance(),!i)return;const o=window.getSelection();if(!o||!o.rangeCount)return;z();const n=Ct.createForEditor(e);n&&(n.apply(t),n.updateButtonText()),setTimeout(()=>{i&&"function"==typeof i.onContentChange&&i.onContentChange()},0)}static sizeToCss(t){return{1:"10px",2:"12px",3:"14px",4:"16px",5:"20px",6:"28px",7:"36px"}[String(t)]||"16px"}apply(t="4"){const e=window.getSelection();if(!e||!e.rangeCount)return;z();const o=e.getRangeAt(0);if(!o.collapsed){i("fontSize",String(t));const e=window.getSelection();if(e.rangeCount>0){const t=e.getRangeAt(0).commonAncestorContainer;t.nodeType===Node.TEXT_NODE?t.parentNode.normalize():t.normalize()}return}let n=o.startContainer;o.startOffset,n.nodeType===Node.TEXT_NODE&&(n=n.parentNode);const r=n.closest&&n.closest("font");if(r&&"​"===r.textContent)return void r.setAttribute("size",String(t));if(r&&r.firstChild&&r.firstChild.nodeType===Node.TEXT_NODE){const e=r.firstChild,i=o.startOffset,n=e.data.slice(0,i),s=e.data.slice(i),a=r.parentNode;if(0===i){const e=document.createElement("font");e.setAttribute("size",String(t)),e.appendChild(document.createTextNode("​")),a.insertBefore(e,r),l(e)}else if(i===e.data.length){const e=document.createElement("font");e.setAttribute("size",String(t)),e.appendChild(document.createTextNode("​")),a.insertBefore(e,r.nextSibling),l(e)}else{const e=document.createElement("font");e.setAttribute("size",r.getAttribute("size")),e.appendChild(document.createTextNode(n));const i=document.createElement("font");i.setAttribute("size",String(t)),i.appendChild(document.createTextNode("​"));const o=document.createElement("font");o.setAttribute("size",r.getAttribute("size")),o.appendChild(document.createTextNode(s)),a.insertBefore(e,r),a.insertBefore(i,r),a.insertBefore(o,r),a.removeChild(r),l(i)}return}const s=document.createElement("font");s.setAttribute("size",String(t));const a=document.createTextNode("​");function l(t){const e=window.getSelection(),i=document.createRange(),o=t.firstChild;i.setStart(o,o.length),i.collapse(!0),e.removeAllRanges(),e.addRange(i)}s.appendChild(a),o.insertNode(s),l(s)}async toggle(){this.customSelect.isVisible?this.customSelect.hide():await this.showSizePicker()}async showSizePicker(){const t=A.getInstanceById(this.editorId);if(!t)return;const e=t.getModule("toolbar");let i=null;if(e&&(i=e.getButton("text-size")),!i){const t=e?.getContainer();t&&(i=t.querySelector(".rich-editor-toolbar-btn.text-size-btn"))}if(i||(i=t.wrapper.querySelector(".rich-editor-toolbar-btn.text-size-btn")),!i)return;const o=this.getCurrentSize();o&&this.customSelect.setCurrentValue(o),await this.customSelect.show(i)}isActive(t=null){return this.updateButtonText(),!1}getCurrentSize(){return Ct.getCurrentSizeStatic()}static getCurrentSizeStatic(){const t=window.getSelection();if(!t||!t.rangeCount)return"4";try{const t=function(t){try{return document.queryCommandValue(t)||""}catch(t){return""}}("fontSize"),e=parseInt(t,10);if(!isNaN(e)&&e>=1&&e<=7)return String(e)}catch(t){}let e=t.getRangeAt(0).startContainer;for(e.nodeType===Node.TEXT_NODE&&(e=e.parentElement);e&&e!==document.body;){if(e.nodeType===Node.ELEMENT_NODE){const t=e,i=t.style?.fontSize;if(i)return this.normalizeCssSizeToExecSize(i);const o=window.getComputedStyle(t).fontSize;if(o)return this.normalizeCssSizeToExecSize(o)}e=e.parentElement}return"4"}normalizeCssSizeToExecSize(t){const e=parseFloat(t);if(isNaN(e))return"4";const i=[10,12,14,16,20,28,36];let o=3,n=1/0;for(let t=0;t<i.length;t++){const r=Math.abs(e-i[t]);r<n&&(n=r,o=t)}return String(o+1)}}class Et{constructor(t={}){this.options={onImport:null,...t},this.popup=null,this.isVisible=!1,this.clickOutsideHandler=null,this.selectedFile=null,this.fileType=null,this.createImportPopup()}createImportPopup(){this.popup=document.createElement("div"),this.popup.className="import-popup";const t=document.createElement("div");t.className="import-popup-content";const e=document.createElement("h3");e.textContent="Import File",e.className="import-popup-title",t.appendChild(e);const i=document.createElement("div");i.className="import-type-container";const o=document.createElement("label");o.textContent="File Type:",o.className="import-input-label",this.typeSelect=document.createElement("select"),this.typeSelect.className="import-type-select",this.typeSelect.innerHTML='\n <option value="">Select file type...</option>\n <option value="html">HTML (.html, .htm)</option>\n <option value="excel">Excel/CSV (.csv, .xlsx, .xls)</option>\n <option value="pdf">PDF (.pdf)</option>\n <option value="word">Word (.doc, .docx)</option>\n ',this.typeSelect.addEventListener("change",()=>this.updateFileInput()),i.appendChild(o),i.appendChild(this.typeSelect),t.appendChild(i),this.fileInput=document.createElement("input"),this.fileInput.type="file",this.fileInput.className="import-file-input",this.fileInput.disabled=!0,this.fileInput.addEventListener("change",t=>this.handleFileSelect(t)),t.appendChild(this.fileInput),this.fileInfo=document.createElement("div"),this.fileInfo.className="import-file-info",this.fileInfo.style.display="none",t.appendChild(this.fileInfo);const n=document.createElement("div");n.className="import-button-container";const r=document.createElement("button");r.type="button",r.className="import-button cancel-button",r.textContent="Cancel",r.addEventListener("click",()=>this.hide()),this.importButton=document.createElement("button"),this.importButton.type="button",this.importButton.className="import-button import-button-main",this.importButton.textContent="Import",this.importButton.disabled=!0,this.importButton.addEventListener("click",()=>this.processImport()),n.appendChild(r),n.appendChild(this.importButton),t.appendChild(n),this.popup.appendChild(t),q(this.popup)}updateFileInput(){const t=this.typeSelect.value;if(t){this.fileType=t,this.fileInput.disabled=!1;const e=this.getAcceptTypes(t);this.fileInput.accept=e}else this.fileType=null,this.fileInput.disabled=!0,this.fileInput.accept="";this.updateImportButton()}getAcceptTypes(t){return{html:".html,.htm,text/html",excel:".csv,.xlsx,.xls,text/csv",pdf:".pdf,application/pdf",word:".doc,.docx"}[t]||""}handleFileSelect(t){const e=t.target.files[0];e&&this.setSelectedFile(e)}setSelectedFile(t){this.selectedFile=t,this.fileInfo.style.display="block",this.fileInfo.innerHTML=`\n <div><strong>Name:</strong> ${t.name}</div>\n <div><strong>Size:</strong> ${this.formatFileSize(t.size)}</div>\n <div><strong>Type:</strong> ${t.type||"Unknown"}</div>\n `,this.updateImportButton()}formatFileSize(t){if(0===t)return"0 Bytes";const e=Math.floor(Math.log(t)/Math.log(1024));return parseFloat((t/Math.pow(1024,e)).toFixed(2))+" "+["Bytes","KB","MB","GB"][e]}updateImportButton(){this.importButton.disabled=!this.selectedFile||!this.fileType}async processImport(){if(this.selectedFile&&this.fileType)try{let t;if("html"===this.fileType)t=await this.readAsText(this.selectedFile);else if("excel"===this.fileType){if(!this.selectedFile.name.toLowerCase().endsWith(".csv"))return void alert("Excel files (.xlsx/.xls) require additional libraries. Please use CSV format.");{const e=await this.readAsText(this.selectedFile);t=this.parseCSV(e)}}else{if("pdf"===this.fileType)return void alert("PDF import requires additional libraries. Feature coming soon.");if("word"===this.fileType)return void alert("Word document import requires additional libraries. Feature coming soon.")}this.options.onImport&&this.options.onImport(t,this.fileType),this.hide(),this.reset()}catch(t){alert("Error importing file: "+t.message)}}parseCSV(t){const e=t.split("\n"),i=[];return e.forEach(t=>{if(t.trim()){const e=t.split(",").map(t=>t.trim().replace(/^["']|["']$/g,""));i.push(e)}}),i}readAsText(t){return new Promise((e,i)=>{const o=new FileReader;o.onload=t=>e(t.target.result),o.onerror=()=>i(new Error("Failed to read file")),o.readAsText(t)})}reset(){this.selectedFile=null,this.fileType=null,this.typeSelect.value="",this.fileInput.value="",this.fileInput.disabled=!0,this.fileInfo.style.display="none",this.updateImportButton()}setupClickOutside(){this.clickOutsideHandler&&document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=t=>{this.popup.contains(t.target)||this.hide()},setTimeout(()=>{document.addEventListener("click",this.clickOutsideHandler)},100)}removeClickOutside(){this.clickOutsideHandler&&(document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=null)}show(t){if(!t)return;const e=$(t,this.popup,{offsetY:5,offsetX:0});W(this.popup,e),this.popup.classList.add("visible"),this.isVisible=!0,this.setupClickOutside()}hide(){this.popup.classList.remove("visible"),this.isVisible=!1,this.removeClickOutside()}destroy(){this.removeClickOutside(),this.popup&&this.popup.parentNode&&this.popup.parentNode.removeChild(this.popup),this.popup=null,this.isVisible=!1}}class kt extends R{static formatName="import";static tagName="DIV";static className="imported-content";constructor(){super();const t=A.getCurrentInstance();if(!t)return;this.editorId=t.instanceId;let e=t.getPopupInstance("import");e||(e=new Et({onImport:(t,e)=>{kt.insertImportedContent(t,e,this.editorId)},editor:t,editorId:this.editorId}),t.setPopupInstance("import",e)),this.importPopup=e}static createForEditor(t){const e=A.getInstanceById(t);if(!e)return null;const i=A.currentInstance;A.currentInstance=e;const o=new kt;return A.currentInstance=i,o}static insertImportedContent(t,e,i=null){let o=null;if(o=i?A.getInstanceById(i):A.getCurrentInstance(),!o)return;const n=window.getSelection();if(n&&n.rangeCount)try{const i=n.getRangeAt(0);let r;r="html"===e?kt.processHtmlContent(t):"excel"===e?kt.processExcelContent(t):kt.processTextContent(t),i.deleteContents(),i.insertNode(r),i.setStartAfter(r),i.collapse(!0),n.removeAllRanges(),n.addRange(i),o&&"function"==typeof o.onContentChange&&o.onContentChange()}catch(t){}}static processHtmlContent(t){const e=document.createElement("div");return e.className="imported-content html-content",e.innerHTML=d(t),kt.cleanHtmlContent(e),e}static processExcelContent(t){const e=document.createElement("div");if(e.className="imported-content excel-content",!Array.isArray(t)||0===t.length)return e.textContent="No data to import",e;const i=document.createElement("table");if(i.className="imported-table",t.length>0){const e=document.createElement("thead"),o=document.createElement("tr");t[0].forEach(t=>{const e=document.createElement("th");e.textContent=t||"",o.appendChild(e)}),e.appendChild(o),i.appendChild(e)}if(t.length>1){const e=document.createElement("tbody");for(let i=1;i<t.length;i++){const o=document.createElement("tr");t[i].forEach(t=>{const e=document.createElement("td");e.textContent=t||"",o.appendChild(e)}),e.appendChild(o)}i.appendChild(e)}return e.appendChild(i),e}static processTextContent(t){const e=document.createElement("div");e.className="imported-content text-content";return t.split(/\n\s*\n/).forEach(t=>{if(t.trim()){const i=document.createElement("p");i.textContent=t.trim(),e.appendChild(i)}}),e}static cleanHtmlContent(t){const e=["p","div","span","h1","h2","h3","h4","h5","h6","strong","b","em","i","u","ul","ol","li","br","table","thead","tbody","tr","th","td"],i=["class","style"],o=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,null,!1),n=[];for(;o.nextNode();){const t=o.currentNode;if(!e.includes(t.tagName.toLowerCase())){n.push(t);continue}Array.from(t.attributes).forEach(e=>{i.includes(e.name.toLowerCase())||t.removeAttribute(e.name)})}n.forEach(t=>{t.parentNode&&t.parentNode.removeChild(t)})}static parseCSV(t){const e=t.split("\n"),i=[];return e.forEach(t=>{if(t.trim()){const e=t.split(",").map(t=>t.trim().replace(/^["']|["']$/g,""));i.push(e)}}),i}apply(){this.showImportPopup()}toggle(){this.importPopup.isVisible?this.importPopup.hide():this.showImportPopup()}showImportPopup(){const t=A.getInstanceById(this.editorId);if(!t)return;const e=t.getModule("toolbar");let i=null;if(e&&(i=e.getButton("import")),!i){const t=e?.getContainer();t&&(i=t.querySelector(".rich-editor-toolbar-btn.import-btn"))}i||(i=t.wrapper.querySelector(".rich-editor-toolbar-btn.import-btn")),i&&this.importPopup.show(i)}isActive(){return!1}static getSupportedTypes(){return{html:{extensions:[".html",".htm"],mimeTypes:["text/html"],name:"HTML Files"},excel:{extensions:[".csv",".xlsx",".xls"],mimeTypes:["text/csv","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],name:"Excel Files"},pdf:{extensions:[".pdf"],mimeTypes:["application/pdf"],name:"PDF Files"},word:{extensions:[".doc",".docx"],mimeTypes:["application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document"],name:"Word Documents"}}}}function jt(t="Button",e={}){const{width:i="auto",icon:o=null}=e,n=document.createElement("button");if(n.type="button",n.className="custom-select-button",o){const t=L.createIconElement(o);t.className="select-lead-icon",n.appendChild(t)}const r=document.createElement("span");r.textContent=t,r.className="button-text";const s=L.createIconElement("dropdown");return s.className="dropdown-icon",n.appendChild(r),n.appendChild(s),n.style.width=i,n.style.padding="0px 5px 0px 8px",n.style.setProperty("height","32px","important"),n.style.setProperty("borderRadius","6px","important"),n.style.setProperty("alignItems","center","important"),n.style.fontSize="14px",n.style.fontWeight="400",n.style.color="#374151",n.style.background="#FFFFFF",n.style.cursor="pointer",n.style.border="1px solid #d1d5db",n.style.display="flex",n.style.justifyContent="space-between",n.style.alignItems="center",r.style.flex="1",r.style.textAlign="left",n.updateText=function(t){r.textContent=t},n}class Tt extends e{static DEFAULTS={container:null,toolbar1:[{group:"text-format",items:["bold","italic","underline","strike"]},{group:"paragraph",items:["heading"]},{group:"colors",items:["color","background"]},{group:"link",items:["link"]},{group:"paragraph-ops",items:["list","indent-increase","indent-decrease","text-align"]},{group:"insert",items:["image","table"]},{group:"history",items:["undo","redo"]},{group:"more",items:["more"]}],toolbar2:[{group:"font",items:["font-family","text-size","line-height"]},{group:"script",items:["subscript","superscript","capitalization"]},{group:"media",items:["emoji","video","tag","horizontal-rule"]},{group:"tools",items:["clear-format","text-direction","find","code-view"]}]};constructor(t,e={}){if(super(t,e),this.buttons=new Map,this.toolbar2Visible=!1,this.events=new Map,Array.isArray(e.toolbar))this.options={container:null,toolbar1:[{group:"text-format",items:e.toolbar}],toolbar2:[]};else if("full"===e.toolbar)this.options={...Tt.DEFAULTS,...e};else if("compact"===e.toolbar)this.options={container:null,toolbar1:[{group:"text-format",items:["bold","italic","underline"]},{group:"link",items:["link"]},{group:"paragraph-ops",items:["list"]},{group:"insert",items:["image","emoji"]},{group:"more",items:["more"]}],toolbar2:[]};else if(e.toolbar&&"object"==typeof e.toolbar&&Array.isArray(e.toolbar.exclude)){const t=new Set(e.toolbar.exclude),i=e=>(e||[]).map(e=>({...e,items:e.items.filter(e=>!t.has(e))})).filter(t=>t.items.length&&(1===t.items.length&&t.items[0],!0));this.options={container:null,toolbar1:i(Tt.DEFAULTS.toolbar1),toolbar2:i(Tt.DEFAULTS.toolbar2)}}else e.toolbar1||e.toolbar2?this.options={container:null,toolbar1:e.toolbar1||[],toolbar2:e.toolbar2||[]}:this.options={...Tt.DEFAULTS,...e};this.init(),this.preloadIcons()}init(){this.container=this.createToolbarContainer()}async preloadIcons(){}createToolbarContainer(){const t=document.createElement("div");t.className="rich-editor-toolbar-container",t.setAttribute("role","toolbar"),t.setAttribute("aria-label","Text formatting"),this.editor.preventFocusLoss(t),t.addEventListener("pointerdown",t=>{t.target.closest("button")&&t.preventDefault()}),this.toolbar1=document.createElement("div"),this.toolbar1.className="rich-editor-toolbar-1",this.toolbar2=document.createElement("div"),this.toolbar2.className="rich-editor-toolbar-2",this.toolbar2.style.display="none",this.flowGroups=[];return[...this.options.toolbar1||[],...this.options.toolbar2||[]].forEach(t=>{if(!t||!t.group||!Array.isArray(t.items))return;if(1===t.items.length&&"more"===t.items[0])return;const e=document.createElement("div");e.className=`toolbar-group toolbar-group-${t.group}`,t.items.forEach(t=>{"string"==typeof t&&this.addButton(e,t)}),this.toolbar1.appendChild(e),this.flowGroups.push(e)}),this.addMoreButton(this.toolbar1),this.moreBtn=this.buttons.get("more"),this.moreBtn&&this.moreBtn.classList.add("more-btn"),t.appendChild(this.toolbar1),t.appendChild(this.toolbar2),"undefined"!=typeof ResizeObserver&&(this._ro=new ResizeObserver(()=>this._scheduleReflow()),this._ro.observe(t)),requestAnimationFrame(()=>this.reflow()),this._setupKeyboardNav(t),t}_focusableButtons(){return Array.from(this.container.querySelectorAll(".rich-editor-toolbar-btn, .custom-select-button")).filter(t=>!t.disabled&&null!==t.offsetParent)}_updateRoving(){this._focusableButtons().forEach((t,e)=>{t.tabIndex=0===e?0:-1})}_setupKeyboardNav(t){t.addEventListener("keydown",t=>{if(!["ArrowLeft","ArrowRight","Home","End"].includes(t.key))return;const e=this._focusableButtons();if(!e.length)return;const i=e.indexOf(document.activeElement);let o;o="Home"===t.key?0:"End"===t.key?e.length-1:-1===i?0:"ArrowRight"===t.key?(i+1)%e.length:(i-1+e.length)%e.length,t.preventDefault(),e.forEach(t=>{t.tabIndex=-1}),e[o].tabIndex=0,e[o].focus()})}_scheduleReflow(){this._reflowQueued||(this._reflowQueued=!0,requestAnimationFrame(()=>{this._reflowQueued=!1,this.reflow()}))}reflow(){if(!this.toolbar1||!this.flowGroups||!this.moreBtn)return;if(this.flowGroups.forEach(t=>this.toolbar1.insertBefore(t,this.moreBtn)),"undefined"!=typeof window&&window.matchMedia&&window.matchMedia("(max-width: 640px)").matches)return this.moreBtn.style.display="none",this.toolbar2.style.display="none",this.toolbar2Visible=!1,this._syncMoreButton(),void this._updateRoving();const t=getComputedStyle(this.toolbar1),e=this.toolbar1.clientWidth-(parseFloat(t.paddingLeft)||0)-(parseFloat(t.paddingRight)||0);if(e<=0)return;let i=0;if(this.flowGroups.forEach((t,e)=>{i+=t.offsetWidth+(e>0?12:0)}),i<=e)return this.moreBtn.style.display="none",this.toolbar2.style.display="none",this.toolbar2Visible=!1,this._syncMoreButton(),void this._updateRoving();const o=e-((this.moreBtn.offsetWidth||32)+12);let n=0,r=this.flowGroups.length;for(let t=0;t<this.flowGroups.length;t++){const e=this.flowGroups[t].offsetWidth+(t>0?12:0);if(n+e>o){r=t;break}n+=e}r<1&&(r=1);for(let t=r;t<this.flowGroups.length;t++)this.toolbar2.appendChild(this.flowGroups[t]);this.moreBtn.style.display="",this.toolbar2.style.display=this.toolbar2Visible?"flex":"none",this._syncMoreButton(),this._updateRoving()}_syncMoreButton(){const t=this.moreBtn;t&&(t.setAttribute("aria-expanded",this.toolbar2Visible?"true":"false"),this.toolbar2Visible?(t.classList.add("active"),t.title="Hide more options"):(t.classList.remove("active"),t.title="More options"))}createToolbar(t,e){const i=document.createElement("div");return i.className=t,Array.isArray(e)&&e.forEach(t=>{if(t&&t.group&&Array.isArray(t.items)){const e=document.createElement("div");e.className=`toolbar-group toolbar-group-${t.group}`,t.items.forEach(t=>{"string"==typeof t&&this.addButton(e,t)}),i.appendChild(e)}}),i}addButton(t,e){if("more"===e)return this.addMoreButton(t);const i={heading:{text:"Paragraph",width:"124px",title:"Paragraph style",icon:"heading"},"font-family":{text:"Font Family",width:"156px",title:"Font",icon:"font-family"},"line-height":{text:"Line Height",width:"116px",title:"Line spacing",icon:"line-height"},capitalization:{text:"Capitalization",width:"146px",title:"Letter case",icon:"capitalization"},"text-size":{text:"Text Size",width:"116px",title:"Font size",icon:"text-size"}};if(i[e]){const o=i[e],n=jt(o.text,{width:o.width,icon:o.icon});return n.dataset.command=e,n.classList.add("rich-editor-toolbar-btn",`${e}-btn`),n.title=o.title,n.setAttribute("aria-label",o.title),n.setAttribute("aria-haspopup","true"),n.addEventListener("click",t=>{t.preventDefault(),this.emit("toolbar-click",{command:e,button:n}),setTimeout(()=>{this.editor.focus()},0)}),this.buttons.set(e,n),t.appendChild(n),n}const o={"text-align":{icon:"align-left",title:"Align Left"},list:{icon:"list",title:"List"}};if(o[e]){const i=o[e],n=document.createElement("button");n.type="button",n.className=`rich-editor-toolbar-btn ${e}-btn`,n.dataset.command=e,n.title=i.title,n.setAttribute("aria-label",i.title);const r=L.getIcon(i.icon);return r?n.innerHTML=`<span class="icon">${r}</span>`:n.textContent="text-align"===e?"≡":"•",n.addEventListener("click",t=>{t.preventDefault(),this.emit("toolbar-click",{command:e,button:n}),setTimeout(()=>{this.editor.focus()},0)}),this.buttons.set(e,n),t.appendChild(n),n}const n=document.createElement("button");n.type="button",n.className=`rich-editor-toolbar-btn ${e}-btn`,n.dataset.command=e;const r=L.createIconElement(e,{width:"16px",height:"16px"});n.appendChild(r);if(n.title={bold:"Bold (Ctrl+B)",italic:"Italic (Ctrl+I)",underline:"Underline (Ctrl+U)",strike:"Strikethrough",subscript:"Subscript",superscript:"Superscript",color:"Text Color",background:"Background Color",link:"Insert/Edit Link",table:"Insert Table",undo:"Undo (Ctrl+Z)",redo:"Redo (Ctrl+Y)","indent-increase":"Increase Indent","indent-decrease":"Decrease Indent",emoji:"Insert Emoji",image:"Insert Image",file:"Attach File",video:"Insert Video",tag:"Insert Tag","horizontal-rule":"Insert Horizontal Rule","clear-format":"Clear Formatting","text-direction":"Toggle Text Direction (LTR/RTL)",find:"Find & Replace (Ctrl+F)",import:"Import Files","code-view":"Switch to HTML Editor"}[e]||e,n.setAttribute("aria-label",n.title),"color"===e||"background"===e){const t=document.createElement("span");t.className="rte-swatch",n.appendChild(t)}return"code-view"===e&&setTimeout(()=>{r.innerHTML.trim()||(r.innerHTML="&lt;/&gt;",r.style.fontSize="12px",r.style.fontWeight="bold")},1e3),n.addEventListener("click",t=>{t.preventDefault(),this.emit("toolbar-click",{command:e,button:n}),setTimeout(()=>{this.editor.focus()},0)}),this.buttons.set(e,n),t.appendChild(n),n}addMoreButton(t){const e=document.createElement("button");e.type="button",e.className="rich-editor-toolbar-btn more-btn",e.dataset.command="more";const i=L.createIconElement("more",{width:"16px",height:"16px"});return e.appendChild(i),e.title="More Options",e.setAttribute("aria-label","More Options"),e.setAttribute("aria-expanded","false"),e.addEventListener("click",t=>{t.preventDefault(),this.toggleToolbar2(),setTimeout(()=>{this.editor.focus()},0)}),this.buttons.set("more",e),t.appendChild(e),e}toggleToolbar2(){this.moreBtn&&"none"===this.moreBtn.style.display||(this.toolbar2Visible=!this.toolbar2Visible,this.toolbar2.style.display=this.toolbar2Visible?"flex":"none",this._syncMoreButton(),this._updateRoving())}getContainer(){return this.container}getButton(t){return this.buttons.get(t)}setButtonActive(t,e){const i=this.buttons.get(t);i&&i.classList&&(e?i.classList.add("active"):i.classList.remove("active"),i.setAttribute("aria-pressed",e?"true":"false"))}setButtonDisabled(t,e){const i=this.buttons.get(t);i&&(i.disabled=e,i.style.opacity=e?"0.5":"1",i.style.cursor=e?"not-allowed":"pointer")}setButtonTitle(t,e){const i=this.buttons.get(t);i&&(i.title=e)}isToolbar2Visible(){return this.toolbar2Visible}on(t,e){this.events.has(t)||this.events.set(t,[]),this.events.get(t).push(e)}emit(t,e){const i=this.events.get(t);i&&i.forEach(t=>{try{t(e)}catch(t){}})}destroy(){this._ro&&(this._ro.disconnect(),this._ro=null),this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container),this.buttons.clear(),this.events.clear()}}class It extends e{static DEFAULTS={delay:1e3,maxStack:100,userOnly:!1};constructor(t,e={}){super(t,e),this.stack=[],this.index=-1,this.lastSave=0,this.savedSelection=null,this.init()}init(){this.setupEventListeners(),this.saveState()}setupEventListeners(){this._onInput=()=>{this.handleInput()},this._onKeydownSave=t=>{"Enter"!==t.key&&"Backspace"!==t.key&&"Delete"!==t.key||this.saveState()},this._onToolbarClick=t=>{t.target.closest(".rich-editor-toolbar-btn")&&setTimeout(()=>{this.saveState()},0)},this._onUndoRedo=t=>{!t.ctrlKey&&!t.metaKey||t.shiftKey||"z"!==t.key?((t.ctrlKey||t.metaKey)&&t.shiftKey&&"z"===t.key||(t.ctrlKey||t.metaKey)&&"y"===t.key)&&(t.preventDefault(),this.redo()):(t.preventDefault(),this.undo())},this.editor.editor.addEventListener("input",this._onInput),this.editor.editor.addEventListener("keydown",this._onKeydownSave),this.editor.wrapper.addEventListener("click",this._onToolbarClick),this.editor.editor.addEventListener("keydown",this._onUndoRedo),this.setupMutationObserver()}setupMutationObserver(){this.mutationObserver=new MutationObserver(t=>{let e=!1;for(const i of t)if("childList"===i.type||"attributes"===i.type&&(i.target.nodeType===Node.TEXT_NODE||["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","PRE","UL","OL","LI","SPAN","STRONG","EM","U","S","SUB","SUP","A","IMG","VIDEO","TABLE","TR","TD","TH"].includes(i.target.tagName))){e=!0;break}e&&(clearTimeout(this.mutationTimeout),this.mutationTimeout=setTimeout(()=>{this.saveState()},100))}),this.mutationObserver.observe(this.editor.editor,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style","class","href","src","alt","title"]})}handleInput(){const t=Date.now();t-this.lastSave>this.options.delay&&(this.saveState(),this.lastSave=t)}saveState(){const t=this.editor.getContent(),e=this.saveSelection();if(this.stack.length>0&&this.stack[this.index]?.content===t)return;const i=Date.now();this.lastSave&&i-this.lastSave<50||(this.index<this.stack.length-1&&this.stack.splice(this.index+1),this.stack.push({content:t,selection:e,timestamp:i}),this.stack.length>this.options.maxStack?this.stack.shift():this.index++,this.lastSave=i)}undo(){if(!this.canUndo())return!1;this.index--;const t=this.stack[this.index];return this.restoreState(t),this.onHistoryChange("undo"),!0}redo(){if(!this.canRedo())return!1;this.index++;const t=this.stack[this.index];return this.restoreState(t),this.onHistoryChange("redo"),!0}canUndo(){return this.index>0}canRedo(){return this.index<this.stack.length-1}restoreState(t){t&&(this.editor.setContent(t.content),t.selection&&setTimeout(()=>{this.restoreSelection(t.selection)},10))}saveSelection(){const t=window.getSelection();if(!t||!t.rangeCount)return null;const e=t.getRangeAt(0),i=this.editor.editor;return{startOffset:this.getOffsetInEditor(e.startContainer,e.startOffset,i),endOffset:this.getOffsetInEditor(e.endContainer,e.endOffset,i),collapsed:e.collapsed}}restoreSelection(t){if(!t)return;const e=this.editor.editor,i=document.createRange(),o=window.getSelection();try{const n=this.getNodeAtOffset(e,t.startOffset),r=this.getNodeAtOffset(e,t.endOffset);n&&r&&(i.setStart(n.node,n.offset),i.setEnd(r.node,r.offset),o.removeAllRanges(),o.addRange(i))}catch(t){this.editor.focus()}}getOffsetInEditor(t,e,i){let o=0;const n=document.createTreeWalker(i,NodeFilter.SHOW_TEXT,null,!1);let r;for(;r=n.nextNode();){if(r===t)return o+e;o+=r.textContent.length}return o}getNodeAtOffset(t,e){let i=0;const o=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,null,!1);let n;for(;n=o.nextNode();){const t=n.textContent.length;if(i+t>=e)return{node:n,offset:e-i};i+=t}return{node:t.lastChild||t,offset:0}}clear(){this.stack=[],this.index=-1,this.saveState()}getState(){return{canUndo:this.canUndo(),canRedo:this.canRedo(),stackLength:this.stack.length,currentIndex:this.index}}onHistoryChange(t){this.editor.modules.forEach(e=>{e!==this&&"function"==typeof e.onHistoryChange&&e.onHistoryChange(t,this.getState())});const e=new CustomEvent("historychange",{detail:{action:t,state:this.getState()}});this.editor.editor.dispatchEvent(e)}forceSave(){const t=this.lastSave;this.lastSave=0,this.saveState(),this.lastSave=t}saveBeforeFormat(){this.forceSave()}destroy(){this._onInput&&(this.editor.editor.removeEventListener("input",this._onInput),this.editor.editor.removeEventListener("keydown",this._onKeydownSave),this.editor.editor.removeEventListener("keydown",this._onUndoRedo),this.editor.wrapper.removeEventListener("click",this._onToolbarClick),this._onInput=this._onKeydownSave=this._onUndoRedo=this._onToolbarClick=null),this.mutationObserver&&(this.mutationObserver.disconnect(),this.mutationObserver=null),this.mutationTimeout&&(clearTimeout(this.mutationTimeout),this.mutationTimeout=null),this.stack=[],this.index=-1,this.savedSelection=null}}class St extends e{static DEFAULTS={showOnSelection:!0,showOnEnter:!0,buttons:["bold","italic","underline","strike","code"]};constructor(t,e={}){super(t,e),this.blockToolbar=null,this.isVisible=!1,this.currentSelection=null,this.currentCursorPosition=null,this.originalTags=new Map,this.init()}init(){this.preloadIcons(),this.createBlockToolbar(),this.setupEventListeners()}async preloadIcons(){}createBlockToolbar(){this.blockToolbar=document.createElement("div"),this.blockToolbar.className="block-toolbar";const t=document.createElement("div");t.className="block-toolbar-container";const e={bold:{icon:"bold",title:"Bold (Ctrl+B)"},italic:{icon:"italic",title:"Italic (Ctrl+I)"},underline:{icon:"underline",title:"Underline (Ctrl+U)"},strike:{icon:"strike",title:"Strikethrough"},code:{icon:"code",title:"Code"},"font-family":{icon:"font-family",title:"Font Family"},link:{icon:"link",title:"Insert link"},color:{icon:"color",title:"Text color"},background:{icon:"background",title:"Background color"}};(Array.isArray(this.options.buttons)&&this.options.buttons.length?this.options.buttons:["bold","italic","underline","strike","code","font-family"]).map(t=>({cmd:t,icon:e[t]&&e[t].icon||t,title:e[t]&&e[t].title||t})).forEach(({cmd:e,icon:i,title:o})=>{const n=document.createElement("button");n.className="block-toolbar-btn",n.title=o,n.dataset.command=e;const r=L.createIconElement(i,{width:"16px",height:"16px"});n.appendChild(r),n.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),this.handleCommand(e,n)}),t.appendChild(n)});const i=document.createElement("div");i.className="block-toolbar-arrow",this.blockToolbar.appendChild(t),this.blockToolbar.appendChild(i),this.editor.wrapper.appendChild(this.blockToolbar)}setupEventListeners(){this._onEditorMouseup=()=>{setTimeout(()=>this.handleSelectionChange(),0)},this._onEditorKeydown=t=>{"Enter"!==t.key||t.shiftKey||requestAnimationFrame(()=>{setTimeout(()=>this.showAtCursorAfterEnter(),10)})},this._onDocMousedown=t=>{t.target.closest(".font-family-select-popup")||t.target.closest(".custom-select-popup")||t.target.closest(".block-toolbar")||t.target.closest(".rich-editor-area")||this.hide()},this._onWindowScroll=()=>{this.isVisible&&this.updateToolbarPosition()},this._onEditorScroll=()=>{this.isVisible&&this.updateToolbarPosition()},this._onEditorKeyup=t=>{"Enter"===t.key&&t.shiftKey?this.hide():this.isVisible?this.updateButtonStates():this.handleSelectionChange()},this.options.showOnSelection&&this.editor.editor.addEventListener("mouseup",this._onEditorMouseup),this.options.showOnEnter&&this.editor.editor.addEventListener("keydown",this._onEditorKeydown),document.addEventListener("mousedown",this._onDocMousedown),window.addEventListener("scroll",this._onWindowScroll),this.editor.editor.addEventListener("scroll",this._onEditorScroll),this.editor.editor.addEventListener("keyup",this._onEditorKeyup)}handleSelectionChange(){const t=window.getSelection();if(!t||0===t.rangeCount)return this.hide();const e=t.getRangeAt(0);if(!(this.editor.isSelectionInEditableArea?this.editor.isSelectionInEditableArea(t):this.editor.editor.contains(e.commonAncestorContainer)))return this.hide();!e.collapsed&&t.toString().trim().length>0?this.showAtSelection(t):this.hide()}showAtSelection(t){if(!t||0===t.rangeCount)return;this.currentSelection=t,this.currentCursorPosition=null;const e=t.getRangeAt(0).getBoundingClientRect(),i=this.editor.wrapper.getBoundingClientRect(),o=window.pageYOffset||document.documentElement.scrollTop,n=window.pageXOffset||document.documentElement.scrollLeft;this.showAt(e.left+e.width/2-i.left+n,e.top-i.top+o-10)}showAtCursorAfterEnter(){this.editor.focus();const t=window.getSelection();if(!t||0===t.rangeCount)return;const e=t.getRangeAt(0);if(!(this.editor.isSelectionInEditableArea?this.editor.isSelectionInEditableArea(t):this.editor.editor.contains(e.commonAncestorContainer)))return;this.ensureCursorAtEndOfLine(e),this.currentSelection=t,this.currentCursorPosition=this.getCursorPositionAfterEnter();const i=this.currentCursorPosition;if(!i)return;const o=this.editor.wrapper.getBoundingClientRect(),n=window.pageYOffset||document.documentElement.scrollTop,r=window.pageXOffset||document.documentElement.scrollLeft;this.showAt(i.left-o.left+r,i.top-o.top+n-10)}ensureCursorAtEndOfLine(t){if(!t.collapsed)return;const e=window.getSelection(),i=t.startContainer;if(i.nodeType===Node.TEXT_NODE){const o=i.textContent.length;t.startOffset<o&&(t.setStart(i,o),t.setEnd(i,o),e.removeAllRanges(),e.addRange(t))}else if(i.nodeType===Node.ELEMENT_NODE){const o=document.createTreeWalker(i,NodeFilter.SHOW_TEXT,null,!1);let n,r=null;for(;n=o.nextNode();)r=n;if(r){const i=r.textContent.length;t.setStart(r,i),t.setEnd(r,i),e.removeAllRanges(),e.addRange(t)}}}getCursorPositionAfterEnter(){const t=window.getSelection();if(!t||0===t.rangeCount)return null;const e=t.getRangeAt(0),i=document.createElement("span");i.innerHTML="&#8203;",i.style.position="absolute",i.style.visibility="hidden",i.style.pointerEvents="none",e.insertNode(i);const o=i.getBoundingClientRect();i.parentNode&&i.parentNode.removeChild(i);const n=document.createRange();return n.setStart(e.startContainer,e.startOffset),n.collapse(!0),t.removeAllRanges(),t.addRange(n),o}showAtCursor(){const t=window.getSelection();if(!t||0===t.rangeCount)return;const e=t.getRangeAt(0);if(!(this.editor.isSelectionInEditableArea?this.editor.isSelectionInEditableArea(t):this.editor.editor.contains(e.commonAncestorContainer)))return;let i;if(e.collapsed){const o=document.createElement("span");o.innerHTML="&#8203;",o.style.position="absolute",o.style.visibility="hidden",o.style.pointerEvents="none",e.insertNode(o),i=o.getBoundingClientRect(),o.parentNode&&o.parentNode.removeChild(o);const n=document.createRange();n.setStart(e.startContainer,e.startOffset),n.collapse(!0),t.removeAllRanges(),t.addRange(n)}else i=e.getBoundingClientRect();const o=this.editor.wrapper.getBoundingClientRect(),n=window.pageYOffset||document.documentElement.scrollTop,r=window.pageXOffset||document.documentElement.scrollLeft;this.showAt(i.left-o.left+r,i.top-o.top+n-10)}showAt(t,e){this.blockToolbar&&(this.blockToolbar.classList.add("visible"),this.isVisible=!0,this.ensureToolbarInViewport(t,e),this.updateButtonStates())}ensureToolbarInViewport(t,e){if(!this.blockToolbar)return;const i=this.editor.editor,o=i.getBoundingClientRect();this.blockToolbar.getBoundingClientRect();const n=this.editor.wrapper.querySelector(".rich-editor-toolbar-container"),r=n?n.getBoundingClientRect():null;let s=t-this.blockToolbar.offsetWidth/2,a=o.y+e-r.height-i.scrollTop-(o.y+window.scrollY)+n.offsetHeight-49,l="50%",c="down";if(s<0&&(s=t-.1*this.blockToolbar.offsetWidth,s<0&&(s=0),l="10%"),s+this.blockToolbar.offsetWidth>this.editor.wrapper.offsetWidth-2&&(s=t-.9*this.blockToolbar.offsetWidth,l="90%"),a<r.height&&(a=o.y+e-r.height-i.scrollTop+100-(o.y+window.scrollY)+n.offsetHeight-49,c="up",a<r.height))return void this.hide();if(a>o.height)return void this.hide();const d=this.blockToolbar.querySelector(".block-toolbar-arrow");d&&(d.style.left=l,"up"===c?(d.style.bottom="auto",d.style.top="-8px",d.style.borderTop="none",d.style.borderBottom="8px solid #fff",d.style.borderLeft="6px solid transparent",d.style.borderRight="6px solid transparent"):(d.style.top="auto",d.style.bottom="-8px",d.style.borderBottom="none",d.style.borderTop="8px solid #fff",d.style.borderLeft="6px solid transparent",d.style.borderRight="6px solid transparent")),this.blockToolbar.style.left=s+"px",this.blockToolbar.style.top=a+"px"}updateToolbarPosition(){if(!this.isVisible)return;const t=window.getSelection();if(!t||0===t.rangeCount)return void this.hide();const e=t.getRangeAt(0);if(!(this.editor.isSelectionInEditableArea?this.editor.isSelectionInEditableArea(t):this.editor.editor.contains(e.commonAncestorContainer)))return void this.hide();let i;if(e.collapsed){const o=document.createElement("span");o.innerHTML="&#8203;",o.style.position="absolute",o.style.visibility="hidden",o.style.pointerEvents="none";try{e.insertNode(o),i=o.getBoundingClientRect(),o.parentNode&&o.parentNode.removeChild(o);const n=document.createRange();n.setStart(e.startContainer,e.startOffset),n.collapse(!0),t.removeAllRanges(),t.addRange(n)}catch(t){return void this.hide()}}else i=e.getBoundingClientRect();const o=this.editor.wrapper.getBoundingClientRect(),n=window.pageYOffset||document.documentElement.scrollTop,r=window.pageXOffset||document.documentElement.scrollLeft;let s,a;e.collapsed?(s=i.left-o.left+r,a=i.top-o.top+n-10):(s=i.left+i.width/2-o.left+r,a=i.top-o.top+n-10),this.updateToolbarAt(s,a);const l=this.editor.registry.get("formats/font-family");l&&l.selectInstance&&l.selectInstance.isVisible&&l.selectInstance.updatePosition()}updateToolbarAt(t,e){this.blockToolbar&&(this.ensureToolbarInViewport(t,e),this.updateButtonStates())}hide(){if(!this.blockToolbar||!this.isVisible)return;this.blockToolbar.classList.remove("visible"),this.isVisible=!1,this.currentSelection=null,this.currentCursorPosition=null;const t=this.editor.registry.get("formats/font-family");t&&t.selectInstance&&t.selectInstance.hide()}handleCommand(t,e){const o=window.getSelection();if(!(!this.editor.isSelectionInEditableArea||this.editor.isSelectionInEditableArea(o)))return void this.hide();if("font-family"===t){const i=this.editor.registry.get("formats/font-family");if(i){return(new i).toggle(e),this.updateButtonState(t,e),void this.editor.focus()}}if("code"===t){const i=this.editor.registry.get("formats/heading");if(i){const o=new i,n=o.getCurrentTag();if("PRE"===n){const t=window.getSelection();if(t&&t.rangeCount){const e=t.getRangeAt(0),i=this.getBlockElement(e.startContainer);if(i){const t=this.originalTags.get(i)||"P";o.apply(t),this.originalTags.delete(i)}else o.apply("P")}else o.apply("P")}else{const t=window.getSelection();if(t&&t.rangeCount){const e=t.getRangeAt(0),i=this.getBlockElement(e.startContainer);i&&this.originalTags.set(i,n||"P")}o.apply("PRE")}return this.updateButtonState(t,e),void this.editor.focus()}}const n=this.editor.registry.get(`formats/${t}`);if(n){const t=new n;"function"==typeof t.toggle?t.toggle():"function"==typeof t.apply&&t.apply()}else i(t);this.updateButtonState(t,e),this.editor.focus()}updateButtonStates(){if(!this.blockToolbar)return;this.blockToolbar.querySelectorAll(".block-toolbar-btn").forEach(t=>{const e=t.dataset.command;this.updateButtonState(e,t)})}updateButtonState(t,e){if(!e)return;let i=!1;if("font-family"===t){const t=this.editor.registry.get("formats/font-family");if(t){i=(new t).isActive()}}else if("code"===t){const t=this.editor.registry.get("formats/heading");if(t){i="PRE"===(new t).getCurrentTag()}}else if("strike"===t){const e=this.editor.registry.get(`formats/${t}`);if(e){i=(new e).isActive()}}else i=n(t);i?e.classList.add("active"):e.classList.remove("active")}getBlockElement(t){if(!t)return null;if(t.nodeType===Node.ELEMENT_NODE){if(["H1","H2","H3","H4","H5","H6","P","PRE","BLOCKQUOTE","DIV"].includes(t.tagName))return t}let e=t;for(;e&&e!==this.editor.editor;){if(e.nodeType===Node.ELEMENT_NODE){if(["H1","H2","H3","H4","H5","H6","P","PRE","BLOCKQUOTE","DIV"].includes(e.tagName))return e}e=e.parentNode}return null}destroy(){this._onDocMousedown&&(document.removeEventListener("mousedown",this._onDocMousedown),window.removeEventListener("scroll",this._onWindowScroll),this.editor.editor.removeEventListener("mouseup",this._onEditorMouseup),this.editor.editor.removeEventListener("keydown",this._onEditorKeydown),this.editor.editor.removeEventListener("scroll",this._onEditorScroll),this.editor.editor.removeEventListener("keyup",this._onEditorKeyup),this._onDocMousedown=this._onWindowScroll=this._onEditorMouseup=null,this._onEditorKeydown=this._onEditorScroll=this._onEditorKeyup=null),this.blockToolbar&&this.blockToolbar.parentNode&&this.blockToolbar.parentNode.removeChild(this.blockToolbar),this.blockToolbar=null,this.isVisible=!1,this.originalTags.clear()}}class Nt extends e{static DEFAULTS={fadeDelay:3e3,buttons:["tableProfile","deleteTable","insertRowAbove","insertRowBelow","deleteRow","insertColRight","insertColLeft","deleteCol"]};constructor(t,e={}){super(t,e),this.tableToolbar=null,this.currentTable=null,this.currentCell=null,this.hideTimeout=null,this.isVisible=!1,this.init()}async init(){await this.createTableToolbar(),this.setupEventListeners()}async createTableToolbar(){this.tableToolbar=document.createElement("div"),this.tableToolbar.className="table-toolbar";const t=document.createElement("div");t.className="table-toolbar-container";const e=[{name:"table-actions",buttons:[{cmd:"tableProfile",icon:"icon-table-profile",title:"Table Profile"},{cmd:"deleteTable",icon:"icon-delete-table",title:"Delete Table"}]},{name:"row-actions",buttons:[{cmd:"insertRowAbove",icon:"icon-add-row-above",title:"Add Row Above"},{cmd:"insertRowBelow",icon:"icon-add-row-below",title:"Add Row Below"},{cmd:"deleteRow",icon:"icon-delete-row",title:"Delete Selected Row"}]},{name:"col-actions",buttons:[{cmd:"insertColRight",icon:"icon-add-col-right",title:"Add Column Right"},{cmd:"insertColLeft",icon:"icon-add-col-left",title:"Add Column Left"},{cmd:"deleteCol",icon:"icon-delete-col",title:"Delete Selected Column"}]}];for(const i of e){const e=document.createElement("div");e.className=`table-toolbar-group ${i.name}`;for(const{cmd:t,icon:o,title:n}of i.buttons){const i=document.createElement("button");i.className="table-toolbar-btn",i.title=n,i.dataset.command=t;const r=L.getIcon(o.replace("icon-",""));r&&(i.innerHTML=r),i.addEventListener("click",e=>{e.preventDefault(),e.stopPropagation(),this.handleCommand(t,i)}),e.appendChild(i)}t.appendChild(e)}const i=document.createElement("div");i.className="table-toolbar-arrow",this.tableToolbar.appendChild(t),this.tableToolbar.appendChild(i),this.editor.wrapper.appendChild(this.tableToolbar)}setupEventListeners(){this._onEditorClick=t=>{const e=t.target.closest("td, th"),i=t.target.closest("table");if(i&&e){if(!(!this.editor.isNodeInEditableArea||this.editor.isNodeInEditableArea(i)))return void this.hide();this.currentTable=i,this.currentCell=e,this.showAtTable(i)}else this.hide()},this._onDocMousedown=t=>{t.target.closest(".table-toolbar")||t.target.closest("table")||this.hide()},this._onWindowScroll=()=>{this.isVisible&&this.currentTable&&this.updateToolbarPosition()},this._onEditorScroll=()=>{this.isVisible&&this.currentTable&&this.updateToolbarPosition()},this.editor.editor.addEventListener("click",this._onEditorClick),document.addEventListener("mousedown",this._onDocMousedown),window.addEventListener("scroll",this._onWindowScroll),this.editor.editor.addEventListener("scroll",this._onEditorScroll),this._onEditorKeyup=t=>{if(this.isVisible&&this.currentTable){const t=window.getSelection();if(t&&t.rangeCount>0){const e=t.getRangeAt(0).startContainer,i=e.nodeType===Node.TEXT_NODE?e.parentElement.closest("td, th"):e.closest("td, th");if(i&&i!==this.currentCell){if(!(!this.editor.isNodeInEditableArea||this.editor.isNodeInEditableArea(i)))return void this.hide();this.currentCell=i}}}},this.editor.editor.addEventListener("keyup",this._onEditorKeyup)}updateToolbarPosition(){if(!this.isVisible||!this.currentTable)return;if(!document.body.contains(this.currentTable))return void this.hide();if(!(!this.editor.isNodeInEditableArea||this.editor.isNodeInEditableArea(this.currentTable)))return void this.hide();const t=this.currentTable.getBoundingClientRect(),e=this.editor.wrapper.getBoundingClientRect(),i=window.pageYOffset||document.documentElement.scrollTop,o=window.pageXOffset||document.documentElement.scrollLeft;this.updateToolbarAt(t.left-e.left+o,t.top-e.top+i,t.width,t.height)}updateToolbarAt(t,e,i,o){this.tableToolbar&&this.ensureToolbarInViewport(t,e,i,o)}showAtTable(t){if(!t||!this.tableToolbar)return;const e=t.getBoundingClientRect(),i=this.editor.wrapper.getBoundingClientRect(),o=window.pageYOffset||document.documentElement.scrollTop,n=window.pageXOffset||document.documentElement.scrollLeft;this.showAt(e.left-i.left+n,e.top-i.top+o,e.width,e.height)}showAt(t,e,i,o){this.tableToolbar&&(this.tableToolbar.classList.add("visible"),this.isVisible=!0,this.ensureToolbarInViewport(t,e,i,o),this.clearHideTimeout())}ensureToolbarInViewport(t,e,i,o){if(!this.tableToolbar)return;const n=this.editor.editor.getBoundingClientRect();this.tableToolbar.getBoundingClientRect();const r=this.editor.wrapper.querySelector(".rich-editor-toolbar-container"),s=r?r.getBoundingClientRect():null;let a=t+i/2-this.tableToolbar.offsetWidth/2,l=e-60-document.documentElement.scrollTop,c="50%",d="down";if(a<0&&(a=t-.1*this.tableToolbar.offsetWidth,a<0&&(a=0),c="10%"),a+this.tableToolbar.offsetWidth>this.editor.wrapper.offsetWidth-2&&(a=t-.9*this.tableToolbar.offsetWidth,c="90%"),l<(s?s.height:48)&&(l=e+o+10-document.documentElement.scrollTop,d="up",l<(s?s.height:48)))return void this.hide();if(l>n.height)return void this.hide();const p=this.tableToolbar.querySelector(".table-toolbar-arrow");p&&(p.style.left=c,"up"===d?(p.style.bottom="auto",p.style.top="-8px",p.style.borderTop="none",p.style.borderBottom="8px solid #fff",p.style.borderLeft="6px solid transparent",p.style.borderRight="6px solid transparent"):(p.style.top="auto",p.style.bottom="-8px",p.style.borderBottom="none",p.style.borderTop="8px solid #fff",p.style.borderLeft="6px solid transparent",p.style.borderRight="6px solid transparent")),this.tableToolbar.style.left=a+"px",this.tableToolbar.style.top=l+"px"}hide(){this.tableToolbar&&this.isVisible&&(this.tableToolbar.classList.remove("visible"),this.isVisible=!1,this.currentTable=null,this.currentCell=null,this.clearHideTimeout())}clearHideTimeout(){this.hideTimeout&&(clearTimeout(this.hideTimeout),this.hideTimeout=null)}handleCommand(t,e){if(!this.currentTable||!this.currentCell)return;if(!this.editor.isNodeInEditableArea||this.editor.isNodeInEditableArea(this.currentTable)){switch(t){case"tableProfile":this.showTableProfile();break;case"deleteTable":this.deleteTable();break;case"insertRowAbove":this.insertRowAbove();break;case"insertRowBelow":this.insertRowBelow();break;case"deleteRow":this.deleteRow();break;case"insertColRight":this.insertColumnRight();break;case"insertColLeft":this.insertColumnLeft();break;case"deleteCol":this.deleteColumn()}this.editor.focus()}else this.hide()}insertRowAbove(){const t=this.currentCell.parentElement,e=this.createNewRow(t.cells.length);t.parentElement.insertBefore(e,t),this.editor.resizeHandles&&this.editor.resizeHandles.checkAndUpdateHandles()}insertRowBelow(){const t=this.currentCell.parentElement,e=this.createNewRow(t.cells.length);t.nextElementSibling?t.parentElement.insertBefore(e,t.nextElementSibling):t.parentElement.appendChild(e),this.editor.resizeHandles&&this.editor.resizeHandles.checkAndUpdateHandles()}insertColumnLeft(){const t=Array.from(this.currentCell.parentElement.children).indexOf(this.currentCell);(this.currentTable.querySelector("tbody")||this.currentTable).querySelectorAll("tr").forEach(e=>{const i=this.createNewCell(),o=e.children[t];o?e.insertBefore(i,o):e.appendChild(i)}),this.editor.resizeHandles&&this.editor.resizeHandles.checkAndUpdateHandles()}insertColumnRight(){const t=Array.from(this.currentCell.parentElement.children).indexOf(this.currentCell);(this.currentTable.querySelector("tbody")||this.currentTable).querySelectorAll("tr").forEach(e=>{const i=this.createNewCell(),o=e.children[t+1];o?e.insertBefore(i,o):e.appendChild(i)}),this.editor.resizeHandles&&this.editor.resizeHandles.checkAndUpdateHandles()}deleteRow(){const t=this.currentCell.parentElement;t.parentElement.children.length<=1||(t.remove(),this.editor.resizeHandles&&this.editor.resizeHandles.checkAndUpdateHandles(),this.hide())}deleteColumn(){const t=Array.from(this.currentCell.parentElement.children).indexOf(this.currentCell),e=(this.currentTable.querySelector("tbody")||this.currentTable).querySelectorAll("tr");this.currentCell.parentElement.children.length<=1||(e.forEach(e=>{e.children[t]&&e.children[t].remove()}),this.editor.resizeHandles&&this.editor.resizeHandles.checkAndUpdateHandles(),this.hide())}showTableProfile(){if(!this.currentTable)return;const t=this.currentTable.querySelectorAll("tr").length,e=this.currentTable.querySelector("tr")?this.currentTable.querySelector("tr").querySelectorAll("td, th").length:0,i=t,o=e,n=t*e,r=this.currentTable.offsetWidth,s=this.currentTable.offsetHeight;alert(`Table Profile:\nRows: ${i}\nColumns: ${o}\nTotal Cells: ${n}\nWidth: ${r}px\nHeight: ${s}px`)}deleteTable(){this.editor.resizeHandles&&this.editor.resizeHandles.hideHandles(),this.currentTable.remove(),this.hide()}createNewRow(t){const e=document.createElement("tr");for(let i=0;i<t;i++)e.appendChild(this.createNewCell());return e}createNewCell(){const t=document.createElement("td");return t.innerHTML="&nbsp;",t.style.minWidth="50px",t.style.minHeight="24px",t.style.padding="4px 8px",t.style.border="1px solid #ddd",t.style.verticalAlign="top",t.contentEditable="true",t}destroy(){this._onDocMousedown&&(document.removeEventListener("mousedown",this._onDocMousedown),window.removeEventListener("scroll",this._onWindowScroll),this.editor.editor.removeEventListener("click",this._onEditorClick),this.editor.editor.removeEventListener("scroll",this._onEditorScroll),this.editor.editor.removeEventListener("keyup",this._onEditorKeyup),this._onDocMousedown=this._onWindowScroll=this._onEditorClick=null,this._onEditorScroll=this._onEditorKeyup=null),this.tableToolbar&&this.tableToolbar.parentNode&&this.tableToolbar.parentNode.removeChild(this.tableToolbar),this.clearHideTimeout(),this.tableToolbar=null,this.currentTable=null,this.currentCell=null,this.isVisible=!1}}class Lt extends e{constructor(t,e={}){super(t,e),this.isCodeView=!1,this.originalContent="",this.codeTextarea=null,this.disabledModules=new Set,this.init()}init(){this.editor.on("toolbar-click",t=>{"code-view"===t.command&&this.toggleCodeView()})}toggleCodeView(){this.isCodeView?this.showNormalView():this.showCodeView(),this.updateToolbarButton()}showCodeView(){const t=this.editor.editor;if(!t)return;this.originalContent=t.innerHTML,this.codeTextarea=document.createElement("textarea"),this.codeTextarea.className="code-view-textarea",this.codeTextarea.value=this.formatHTML(this.originalContent),t.style.display="none",t.parentNode.insertBefore(this.codeTextarea,t);const e=this.editor.wrapper;e&&e.classList.add("code-view-active"),this.codeTextarea.focus(),this.isCodeView=!0,"function"==typeof this.editor.updateStatusbar&&this.editor.updateStatusbar(),this.disableOtherFeatures(),this.codeTextarea.addEventListener("input",()=>{this.updateOriginalContent()})}showNormalView(){const t=this.editor.editor;if(!t||!this.codeTextarea)return;const e=this.codeTextarea.value;this.codeTextarea.parentNode.removeChild(this.codeTextarea),this.codeTextarea=null;const i=this.editor.wrapper;i&&i.classList.remove("code-view-active"),t.style.display="",t.innerHTML=d(e),t.focus(),this.isCodeView=!1,this.enableOtherFeatures(),this.editor.onContentChange()}disableOtherFeatures(){const t=this.editor.getModule("toolbar");if(t){["bold","italic","underline","strike","subscript","superscript","color","background","link","table","heading","font-family","line-height","capitalization","text-align","list","indent-increase","indent-decrease","text-size","emoji","image","video","tag","import","undo","redo","clear-format","horizontal-rule","text-direction","find","more"].forEach(e=>{t.setButtonDisabled(e,!0)}),t.setButtonDisabled("code-view",!1),t.setButtonDisabled("theme",!1)}this.disableEditorEvents(),this.disableOtherModules(),this.hideAllPopups()}enableOtherFeatures(){const t=this.editor.getModule("toolbar");if(t){["bold","italic","underline","strike","subscript","superscript","color","background","link","table","heading","font-family","line-height","capitalization","text-align","list","indent-increase","indent-decrease","text-size","emoji","image","video","tag","import","undo","redo","clear-format","horizontal-rule","text-direction","find","more"].forEach(e=>{t.setButtonDisabled(e,!1)})}this.enableEditorEvents(),this.enableOtherModules()}disableEditorEvents(){const t=this.editor.editor;t&&(t.contentEditable=!1,t.style.opacity="0.5",t.style.pointerEvents="none",t.style.cursor="not-allowed",t.title='Editor is disabled in code view mode. Click "Switch to Visual Editor" to return to normal editing.')}enableEditorEvents(){const t=this.editor.editor;t&&(t.contentEditable=!0,t.style.opacity="",t.style.pointerEvents="",t.style.cursor="",t.title="")}disableOtherModules(){["history","block-toolbar","table-toolbar","resize-handles"].forEach(t=>{const e=this.editor.getModule(t);if(e)if("function"==typeof e.disable)e.disable(),this.disabledModules.add(t);else if(e.getContainer&&"function"==typeof e.getContainer){const i=e.getContainer();i&&(i.style.display="none",this.disabledModules.add(t))}})}enableOtherModules(){this.disabledModules.forEach(t=>{const e=this.editor.getModule(t);if(e)if("function"==typeof e.enable)e.enable();else if(e.getContainer&&"function"==typeof e.getContainer){const t=e.getContainer();t&&(t.style.display="")}}),this.disabledModules.clear()}updateOriginalContent(){if(this.codeTextarea){this.originalContent=this.codeTextarea.value;const t=this.codeTextarea.value;this.editor.options.onChange&&"function"==typeof this.editor.options.onChange&&this.editor.options.onChange(t),this.editor.emit("text-change",t),"function"==typeof this.editor.updateStatusbar&&this.editor.updateStatusbar()}}formatHTML(t){let e=t;e=e.replace(/></g,">\n<"),e=e.replace(/>([^<>\s][^<]*)</g,">\n$1\n<");const i=e.split("\n"),o=[],n=[];for(let t of i){const e=t.trim();if(!e)continue;if(/^<\/(\w+)/.test(e)){const t=e.match(/^<\/(\w+)/);if(t){const e=t[1];for(let t=n.length-1;t>=0;t--)if(n[t]===e){n.splice(t,1);break}}}let i=n.length;e.startsWith("<")||(i=n.length),o.push(" ".repeat(4*i)+e);const r=e.match(/^<(\w+)/);if(r&&!e.startsWith("</")&&!e.endsWith("/>")&&!["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"].includes(r[1].toLowerCase())){const t=r[1];n.push(t)}}return o.join("\n")}updateToolbarButton(){const t=this.editor.getModule("toolbar");if(t){t.setButtonActive("code-view",this.isCodeView);const e=this.isCodeView?"Switch to Visual Editor":"Switch to HTML Editor";t.setButtonTitle("code-view",e)}}isInCodeView(){return this.isCodeView}getCurrentContent(){return this.isCodeView&&this.codeTextarea?this.codeTextarea.value:this.editor.editor.innerHTML}setContent(t){this.isCodeView&&this.codeTextarea?(this.codeTextarea.value=this.formatHTML(t),this.updateOriginalContent()):this.editor.editor.innerHTML=t}hideAllPopups(){document.querySelectorAll(".rich-editor-popup, .color-picker-popup, .emoji-picker-popup, .link-popup, .image-popup, .video-popup, .table-popup, .tag-popup, .import-popup").forEach(t=>{t.parentNode&&t.parentNode.removeChild(t)}),this.editor.popupInstances&&this.editor.popupInstances.clear()}destroy(){this.isCodeView&&this.showNormalView(),this.codeTextarea&&this.codeTextarea.parentNode&&this.codeTextarea.parentNode.removeChild(this.codeTextarea),this.codeTextarea=null,this.originalContent="",this.isCodeView=!1,this.disabledModules.clear()}}class At extends e{constructor(t,e={}){super(t,e),this.hits=[],this.activeIndex=-1,this.caseSensitive=!1,this.isOpen=!1,this.buildPanel(),this.bindEvents()}buildPanel(){const t=document.createElement("div");t.className="yjd-find-replace";const e=(t,e)=>{const i=document.createElement("input");return i.type="text",i.placeholder=t,i.className=`yjd-find-input ${e}`,i.setAttribute("aria-label",t),i},i=(t,e,i="",o=null)=>{const n=document.createElement("button");if(n.type="button",o){const e=L.getIcon(o);n.innerHTML=e?`<span class="icon">${e}</span>`:t}else n.textContent=t;return n.title=e,n.setAttribute("aria-label",e),n.className=`yjd-find-btn ${i}`.trim(),n},o=document.createElement("div");o.className="yjd-find-row";const n=document.createElement("div");n.className="yjd-find-row",this.findInput=e("Find","yjd-find-field"),this.replaceInput=e("Replace with","yjd-find-field"),this.countEl=document.createElement("span"),this.countEl.className="yjd-find-count",this.countEl.textContent="0/0",this.prevBtn=i("","Previous match","yjd-find-icon","chevron-up"),this.nextBtn=i("","Next match","yjd-find-icon","chevron-down"),this.caseBtn=i("Aa","Match case","yjd-find-icon yjd-find-toggle"),this.closeBtn=i("","Close (Esc)","yjd-find-icon yjd-find-close","close"),this.replaceBtn=i("Replace","Replace current"),this.replaceAllBtn=i("Replace all","Replace all matches"),o.append(this.findInput,this.countEl,this.prevBtn,this.nextBtn,this.caseBtn,this.closeBtn),n.append(this.replaceInput,this.replaceBtn,this.replaceAllBtn),t.append(o,n),this.panel=t,this.editor.wrapper.appendChild(t)}bindEvents(){this._onKeydown=t=>{!t.ctrlKey&&!t.metaKey||t.shiftKey||t.altKey||"f"!==t.key.toLowerCase()||(t.preventDefault(),this.open())},this.editor.editor.addEventListener("keydown",this._onKeydown),this._onToolbarClick=t=>{t&&"find"===t.command&&this.open()},this.editor.on("toolbar-click",this._onToolbarClick),this.findInput.addEventListener("input",()=>this.runSearch()),this.findInput.addEventListener("keydown",t=>{"Enter"===t.key?(t.preventDefault(),this.navigate(t.shiftKey?-1:1)):"Escape"===t.key&&(t.preventDefault(),this.close())}),this.replaceInput.addEventListener("keydown",t=>{"Enter"===t.key?(t.preventDefault(),this.replaceCurrent()):"Escape"===t.key&&(t.preventDefault(),this.close())}),this.prevBtn.addEventListener("click",()=>this.navigate(-1)),this.nextBtn.addEventListener("click",()=>this.navigate(1)),this.replaceBtn.addEventListener("click",()=>this.replaceCurrent()),this.replaceAllBtn.addEventListener("click",()=>this.replaceAll()),this.caseBtn.addEventListener("click",()=>{this.caseSensitive=!this.caseSensitive,this.caseBtn.classList.toggle("active",this.caseSensitive),this.caseBtn.setAttribute("aria-pressed",this.caseSensitive?"true":"false"),this.runSearch()}),this.closeBtn.addEventListener("click",()=>this.close())}open(){this.isOpen=!0,this.panel.classList.add("open");const t=this.editor.wrapper.querySelector(".rich-editor-toolbar-container");t&&(this.panel.style.top=t.offsetHeight+6+"px");const e=window.getSelection(),i=e&&!e.isCollapsed?e.toString():"";i&&!i.includes("\n")&&(this.findInput.value=i),this.findInput.focus(),this.findInput.select(),this.runSearch()}close(){this.isOpen=!1,this.panel.classList.remove("open"),this.clearHighlights(),this.hits=[],this.activeIndex=-1,this.editor.focus()}escapeRegex(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}clearHighlights(){this.editor.editor.querySelectorAll("mark.yjd-find-hit").forEach(t=>{const e=t.parentNode;if(e){for(;t.firstChild;)e.insertBefore(t.firstChild,t);e.removeChild(t),e.normalize()}})}runSearch(){this.clearHighlights(),this.hits=[],this.activeIndex=-1;const t=this.findInput.value;if(!t)return void this.updateCount();let e;try{e=new RegExp(this.escapeRegex(t),this.caseSensitive?"g":"gi")}catch(t){return void this.updateCount()}const i=this.editor.editor,o=document.createTreeWalker(i,NodeFilter.SHOW_TEXT,null),n=[];let r;for(;r=o.nextNode();)r.nodeValue&&r.nodeValue.length&&n.push(r);n.forEach(t=>{const i=t.nodeValue,o=[];let n;for(e.lastIndex=0;null!==(n=e.exec(i));)0!==n[0].length?o.push([n.index,n.index+n[0].length]):e.lastIndex++;for(let e=o.length-1;e>=0;e--){const i=document.createRange();i.setStart(t,o[e][0]),i.setEnd(t,o[e][1]);const n=document.createElement("mark");n.className="yjd-find-hit";try{i.surroundContents(n)}catch(t){}}}),this.hits=Array.from(i.querySelectorAll("mark.yjd-find-hit")),this.hits.length&&(this.activeIndex=0,this.highlightActive(!0)),this.updateCount()}highlightActive(t){this.hits.forEach((t,e)=>{t.classList.toggle("active",e===this.activeIndex)}),t&&this.activeIndex>=0&&this.hits[this.activeIndex]&&this.hits[this.activeIndex].scrollIntoView({block:"nearest",inline:"nearest"})}navigate(t){this.hits.length&&(this.activeIndex=(this.activeIndex+t+this.hits.length)%this.hits.length,this.highlightActive(!0),this.updateCount())}updateCount(){const t=this.hits.length,e=t?this.activeIndex+1:0;this.countEl.textContent=`${e}/${t}`}replaceCurrent(){if(this.activeIndex<0||!this.hits[this.activeIndex])return;const t=this.editor.getModule("history");t&&"function"==typeof t.saveBeforeFormat&&t.saveBeforeFormat();const e=this.hits[this.activeIndex],i=this.activeIndex,o=e.parentNode;o.replaceChild(document.createTextNode(this.replaceInput.value),e),o.normalize(),this.editor.onContentChange(),this.runSearch(),this.hits.length&&(this.activeIndex=Math.min(i,this.hits.length-1),this.highlightActive(!0),this.updateCount())}replaceAll(){if(!this.hits.length)return;const t=this.editor.getModule("history");t&&"function"==typeof t.saveBeforeFormat&&t.saveBeforeFormat();const e=this.replaceInput.value;this.hits.forEach(t=>{const i=t.parentNode;i&&i.replaceChild(document.createTextNode(e),t)}),this.editor.editor.normalize(),this.editor.onContentChange(),this.runSearch()}destroy(){this.editor.editor.removeEventListener("keydown",this._onKeydown),this.editor.off("toolbar-click",this._onToolbarClick),this.clearHighlights(),this.panel&&this.panel.parentNode&&this.panel.parentNode.removeChild(this.panel),super.destroy()}}class Bt extends e{constructor(t,e={}){super(t,e),this.isOpen=!1,this.activeIndex=0,this.query="",this.filtered=[],this.commands=this.buildCommands(),this.buildMenu(),this.bindEvents()}buildCommands(){const t=this.editor;return[{id:"h1",label:"Heading 1",hint:"Big section heading",icon:"heading",run:()=>t.setBlockType("h1")},{id:"h2",label:"Heading 2",hint:"Medium heading",icon:"heading",run:()=>t.setBlockType("h2")},{id:"h3",label:"Heading 3",hint:"Small heading",icon:"heading",run:()=>t.setBlockType("h3")},{id:"ul",label:"Bullet list",hint:"Unordered list",icon:"list-bullet",run:()=>t.setBlockType("ul")},{id:"ol",label:"Numbered list",hint:"Ordered list",icon:"list-ordered",run:()=>t.setBlockType("ol")},{id:"quote",label:"Quote",hint:"Blockquote",icon:"code",run:()=>t.setBlockType("blockquote")},{id:"code",label:"Code block",hint:"Preformatted code",icon:"code-view",run:()=>t.setBlockType("pre")},{id:"hr",label:"Divider",hint:"Horizontal rule",icon:"horizontal-rule",run:()=>t.insertHorizontalRule()},{id:"table",label:"Table",hint:"3×3 table",icon:"table",run:()=>this.insertTable()},{id:"p",label:"Text",hint:"Plain paragraph",icon:"font-family",run:()=>t.setBlockType("p")}]}insertTable(){const t=this.editor.registry.get("formats/table");t&&"function"==typeof t.createTableElement&&"function"==typeof this.editor.insertBlock&&this.editor.insertBlock(t.createTableElement(3,3))}buildMenu(){const t=document.createElement("div");t.className="yjd-slash-menu",t.setAttribute("role","listbox"),t.style.display="none",this.menu=t,document.body.appendChild(t)}bindEvents(){this._onInput=()=>this.handleInput(),this.editor.editor.addEventListener("input",this._onInput),this._onKeydown=t=>{if(!this.isOpen)return;["ArrowDown","ArrowUp","Enter","Escape"].includes(t.key)&&(t.preventDefault(),t.stopPropagation()),"ArrowDown"===t.key?this.move(1):"ArrowUp"===t.key?this.move(-1):"Enter"===t.key?this.choose(this.activeIndex):"Escape"===t.key&&this.close()},this.editor.editor.addEventListener("keydown",this._onKeydown,!0),this._onDocPointer=t=>{this.isOpen&&!this.menu.contains(t.target)&&this.close()},document.addEventListener("pointerdown",this._onDocPointer,!0)}handleInput(){const t=window.getSelection();if(!t||!t.isCollapsed||!t.rangeCount)return this.close();const e=t.getRangeAt(0),i=e.startContainer;if(i.nodeType!==Node.TEXT_NODE)return this.close();const o=i.textContent.slice(0,e.startOffset).match(/(?:^|\s)\/([^\s/]*)$/);if(!o)return this.close();this.query=o[1],this.slashNode=i,this.slashStart=e.startOffset-this.query.length-1;const n=this.query.toLowerCase();if(this.filtered=this.commands.filter(t=>t.label.toLowerCase().includes(n)||t.id.toLowerCase().includes(n)||(t.hint||"").toLowerCase().includes(n)),!this.filtered.length)return this.close();this.activeIndex=0,this.render(),this.open(e)}open(t){this.isOpen=!0,this.menu.style.display="block";const e=t.getBoundingClientRect(),i=e.left||(t.startContainer.parentElement||this.editor.editor).getBoundingClientRect().left,o=e.bottom||e.top;this.menu.style.left=`${Math.round(i+window.scrollX)}px`,this.menu.style.top=`${Math.round(o+window.scrollY+6)}px`;const n=this.menu.offsetHeight;e.bottom+n+8>window.innerHeight&&(this.menu.style.top=`${Math.round(e.top+window.scrollY-n-6)}px`)}close(){this.isOpen&&(this.isOpen=!1,this.menu.style.display="none")}move(t){this.activeIndex=(this.activeIndex+t+this.filtered.length)%this.filtered.length,this.render()}render(){this.menu.innerHTML="",this.filtered.forEach((t,e)=>{const i=document.createElement("button");i.type="button",i.className="yjd-slash-item"+(e===this.activeIndex?" active":""),i.setAttribute("role","option"),i.setAttribute("aria-selected",e===this.activeIndex?"true":"false");const o=document.createElement("span");o.className="yjd-slash-icon",o.innerHTML=L.getIcon(t.icon)||"";const n=document.createElement("span");n.className="yjd-slash-text",n.innerHTML=`<span class="yjd-slash-label">${t.label}</span><span class="yjd-slash-hint">${t.hint}</span>`,i.append(o,n),i.addEventListener("pointerdown",t=>{t.preventDefault(),this.choose(e)}),this.menu.appendChild(i)})}choose(t){const e=this.filtered[t];if(!e)return this.close();try{const t=this.slashNode,e=window.getSelection(),i=document.createRange();i.setStart(t,this.slashStart),i.setEnd(t,this.slashStart+this.query.length+1),i.deleteContents();const o=document.createRange();o.setStart(t,this.slashStart),o.collapse(!0),e.removeAllRanges(),e.addRange(o)}catch(t){}this.close(),this.editor.focus(),e.run(this.editor)}destroy(){this.editor.editor.removeEventListener("input",this._onInput),this.editor.editor.removeEventListener("keydown",this._onKeydown,!0),document.removeEventListener("pointerdown",this._onDocPointer,!0),this.menu&&this.menu.parentNode&&this.menu.parentNode.removeChild(this.menu),super.destroy()}}class Rt extends e{static THEME_VARS=["--rte-accent","--rte-accent-ink","--rte-accent-weak","--rte-ink","--rte-muted","--rte-border","--rte-bg","--rte-radius-md","--rte-shadow"];constructor(t,e={}){super(t,e),this.isOpen=!1,this.activeIndex=0,this.items=[],this.sources=this._buildSources(),this.buildMenu(),this.bindEvents()}_buildSources(){const t=this.editor.options.mention||this.options||{},e={},i=t.renderItem;return"function"==typeof t.source&&(e[t.trigger||"@"]={source:t.source,renderItem:t.renderItem||i}),(t.triggers||[]).forEach(t=>{t&&t.char&&"function"==typeof t.source&&(e[t.char]={source:t.source,renderItem:t.renderItem||i})}),e}get enabled(){return Object.keys(this.sources).length>0}buildMenu(){const t=document.createElement("div");t.className="yjd-mention-menu",t.setAttribute("role","listbox"),t.style.display="none",this.menu=t,document.body.appendChild(t)}bindEvents(){this.enabled&&(this._onInput=()=>this.handleInput(),this.editor.editor.addEventListener("input",this._onInput),this._onKeydown=t=>{if(!this.isOpen)return;["ArrowDown","ArrowUp","Enter","Tab","Escape"].includes(t.key)&&(t.preventDefault(),t.stopPropagation()),"ArrowDown"===t.key?this.move(1):"ArrowUp"===t.key?this.move(-1):"Enter"===t.key||"Tab"===t.key?this.choose(this.activeIndex):"Escape"===t.key&&this.close()},this.editor.editor.addEventListener("keydown",this._onKeydown,!0),this._onDocPointer=t=>{this.isOpen&&!this.menu.contains(t.target)&&this.close()},document.addEventListener("pointerdown",this._onDocPointer,!0))}handleInput(){const t=window.getSelection();if(!t||!t.isCollapsed||!t.rangeCount)return this.close();const e=t.getRangeAt(0),i=e.startContainer;if(i.nodeType!==Node.TEXT_NODE)return this.close();const o=Object.keys(this.sources).map(t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join(""),n=i.textContent.slice(0,e.startOffset).match(new RegExp(`(?:^|\\s)([${o}])([^\\s${o}]*)$`));if(!n)return this.close();this.char=n[1],this.query=n[2],this.node=i,this.start=e.startOffset-this.query.length-1,this._loadFor(e)}_loadFor(t){const e=this.sources[this.char];if(!e)return this.close();clearTimeout(this._t);const i=this.query,o=this.char;this._t=setTimeout(()=>{Promise.resolve(e.source(i)).then(n=>{if(this.char===o&&this.query===i){if(this.items=Array.isArray(n)?n:[],!this.items.length)return this.close();this.activeIndex=0,this.render(e.renderItem),this.open(t)}}).catch(()=>this.close())},120)}open(t){this.isOpen=!0,this.menu.style.display="block",this._applyTheme();const e=t.getBoundingClientRect(),i=e.left||(t.startContainer.parentElement||this.editor.editor).getBoundingClientRect().left,o=e.bottom||e.top;this.menu.style.left=`${Math.round(i+window.scrollX)}px`,this.menu.style.top=`${Math.round(o+window.scrollY+6)}px`;const n=this.menu.offsetHeight;e.bottom+n+8>window.innerHeight&&(this.menu.style.top=`${Math.round(e.top+window.scrollY-n-6)}px`)}close(){this.isOpen&&(this.isOpen=!1,this.menu.style.display="none")}_applyTheme(){const t=this.editor.wrapper||this.editor.root;if(!t)return;const e=getComputedStyle(t);Rt.THEME_VARS.forEach(t=>{const i=e.getPropertyValue(t);i&&this.menu.style.setProperty(t,i.trim())})}move(t){this.activeIndex=(this.activeIndex+t+this.items.length)%this.items.length,[...this.menu.children].forEach((t,e)=>{t.classList.toggle("active",e===this.activeIndex),t.setAttribute("aria-selected",e===this.activeIndex?"true":"false")})}render(t){this.menu.innerHTML="",this.items.forEach((e,i)=>{const o=document.createElement("button");o.type="button",o.className="yjd-mention-item"+(i===this.activeIndex?" active":""),o.setAttribute("role","option"),o.setAttribute("aria-selected",i===this.activeIndex?"true":"false");const n=e.name||e.label||e.id||"",r=e.avatar_url?`<img class="yjd-mention-avatar" src="${e.avatar_url}" alt="">`:e.icon?`<span class="yjd-mention-ico">${e.icon}</span>`:"";o.innerHTML="function"==typeof t?t(e):`${r}<span class="yjd-mention-name">${this.char}${n}</span>`,o.addEventListener("pointerdown",t=>{t.preventDefault(),this.choose(i)}),this.menu.appendChild(o)})}choose(t){const e=this.items[t];if(!e)return this.close();const i=e.name||e.label||e.id||"";try{const t=this.node,o=window.getSelection(),n=document.createRange();n.setStart(t,this.start),n.setEnd(t,this.start+this.query.length+1),n.deleteContents();const r=document.createElement("span");r.className="mention",r.setAttribute("data-id",String(null!=e.id?e.id:"")),r.setAttribute("data-trigger",this.char),r.setAttribute("contenteditable","false"),r.textContent=this.char+i,n.insertNode(r);const s=document.createTextNode(" ");r.after(s);const a=document.createRange();a.setStart(s,1),a.collapse(!0),o.removeAllRanges(),o.addRange(a)}catch(t){}this.close(),this.editor.focus(),"function"==typeof this.editor.onContentChange&&this.editor.onContentChange(),this.editor.emit("mention:select",e)}destroy(){this._onInput&&this.editor.editor.removeEventListener("input",this._onInput),this._onKeydown&&this.editor.editor.removeEventListener("keydown",this._onKeydown,!0),this._onDocPointer&&document.removeEventListener("pointerdown",this._onDocPointer,!0),this.menu&&this.menu.parentNode&&this.menu.parentNode.removeChild(this.menu),super.destroy()}}class Ht extends e{static DEFAULTS={minWidth:50,minHeight:50,maxWidth:800,maxHeight:600,maintainAspectRatio:!0,snapToGrid:!1,gridSize:10};constructor(t,e={}){super(t,e),this.activeElement=null,this.handles=[],this.isResizing=!1,this.startX=0,this.startY=0,this.startWidth=0,this.startHeight=0,this.currentHandle=null,this.aspectRatio=1,this.init()}init(){this.createHandles(),this.setupEventListeners()}createHandles(){this.handlesContainer=document.createElement("div"),this.handlesContainer.className="resize-handles-container",this.handlesContainer.style.position="absolute",this.handlesContainer.style.pointerEvents="none",this.handlesContainer.style.zIndex="997",this.handlesContainer.style.display="none";[{name:"nw",cursor:"nw-resize",position:{top:-4,left:-4}},{name:"ne",cursor:"ne-resize",position:{top:-4,right:-4}},{name:"sw",cursor:"sw-resize",position:{bottom:-4,left:-4}},{name:"se",cursor:"se-resize",position:{bottom:-4,right:-4}}].forEach(t=>{const e=this.createHandle(t);this.handles.push(e),this.handlesContainer.appendChild(e)}),this.editor.wrapper.appendChild(this.handlesContainer)}createHandle(t){const e=document.createElement("div");return e.className=`resize-handle resize-handle-${t.name}`,e.style.position="absolute",e.style.width="8px",e.style.height="8px",e.style.backgroundColor="#3b82f6",e.style.border="1px solid #fff",e.style.borderRadius="50%",e.style.cursor=t.cursor,e.style.pointerEvents="auto",e.style.boxShadow="0 2px 4px rgba(0,0,0,0.2)",e.style.zIndex="999",e.dataset.handle=t.name,Object.entries(t.position).forEach(([t,i])=>{e.style[t]=i+"px"}),e.addEventListener("mousedown",e=>this.handleMouseDown(e,t.name)),e}setupEventListeners(){this._onEditorClick=t=>this.handleElementClick(t),this._onDocClick=t=>{this.isClickOnResizableElement(t)||this.isClickOnHandle(t)||this.hideHandles()},this._onDocMousemove=t=>this.handleMouseMove(t),this._onDocMouseup=t=>this.handleMouseUp(t),this._onWindowScroll=()=>{this.activeElement&&this.updateHandlePosition()},this._onEditorScroll=()=>{this.activeElement&&this.updateHandlePosition()},this.editor.editor.addEventListener("click",this._onEditorClick),document.addEventListener("click",this._onDocClick),document.addEventListener("mousemove",this._onDocMousemove),document.addEventListener("mouseup",this._onDocMouseup),window.addEventListener("scroll",this._onWindowScroll),this.editor.editor.addEventListener("scroll",this._onEditorScroll),this.setupMutationObserver()}handleElementClick(t){const e=t.target;let i=this.findResizableElement(e);i&&(t.preventDefault(),t.stopPropagation(),this.showHandles(i))}findResizableElement(t){if(this.isResizableElement(t))return t;if("TD"===t.tagName||"TH"===t.tagName||"TR"===t.tagName||"TBODY"===t.tagName){let e=t.parentElement;for(;e&&"TABLE"!==e.tagName;)e=e.parentElement;if(e&&this.isResizableElement(e))return e}let e=t.parentElement;for(;e&&e!==this.editor.wrapper;){if(this.isResizableElement(e))return e;e=e.parentElement}return null}isResizableElement(t){const e=t.classList.contains("inserted-image"),i=t.classList.contains("inserted-video"),o=t.classList.contains("rich-editor-table");return e||i||o}isClickOnResizableElement(t){return this.isResizableElement(t.target)}isClickOnHandle(t){return t.target.classList.contains("resize-handle")}showHandles(t){this.activeElement=t,this.updateHandlePosition(),this.handlesContainer.style.display="block",(t.classList.contains("inserted-image")||t.classList.contains("inserted-video"))&&(this.aspectRatio=t.offsetWidth/t.offsetHeight),t.classList.contains("rich-editor-table")&&(t.style.position="relative",t.style.display="table",this.lastTableWidth=t.offsetWidth,this.lastTableHeight=t.offsetHeight,this.setupTableSizeMonitoring(t))}hideHandles(){this.tableSizeInterval&&(clearInterval(this.tableSizeInterval),this.tableSizeInterval=null),this.activeElement=null,this.handlesContainer.style.display="none"}updateHandlePosition(){if(!this.activeElement)return;if(!document.body.contains(this.activeElement))return void this.hideHandles();const t=this.activeElement.getBoundingClientRect(),e=this.editor.wrapper.getBoundingClientRect(),i=this.editor.wrapper.scrollTop||0,o=this.editor.wrapper.scrollLeft||0,n=t.top-e.top+i,r=t.left-e.left+o,s=t.width,a=t.height,l=n+a;this.handlesContainer.style.top=n+"px",this.handlesContainer.style.left=r+"px",this.handlesContainer.style.width=s+"px",this.handlesContainer.style.height=a+"px",(l<0||n>e.height)&&this.hideHandles()}handleMouseDown(t,e){t.preventDefault(),t.stopPropagation(),this.isResizing=!0,this.currentHandle=e,this.startX=t.clientX,this.startY=t.clientY,this.startWidth=this.activeElement.offsetWidth,this.startHeight=this.activeElement.offsetHeight;const i=this.activeElement.getBoundingClientRect();this.startLeft=i.left,this.startTop=i.top,this.activeElement.classList.add("resizing"),document.body.style.cursor=t.target.style.cursor,document.body.style.userSelect="none"}handleMouseMove(t){if(!this.isResizing||!this.activeElement)return;const e=t.clientX-this.startX,i=t.clientY-this.startY;let o=this.startWidth,n=this.startHeight;switch(this.currentHandle){case"nw":o=this.startWidth-e,n=this.startHeight-i;break;case"ne":o=this.startWidth+e,n=this.startHeight-i;break;case"sw":o=this.startWidth-e,n=this.startHeight+i;break;case"se":o=this.startWidth+e,n=this.startHeight+i}let r=this.options.maxWidth;const s=this.editor&&this.editor.editor;if(s){const t=getComputedStyle(s),e=s.clientWidth-(parseFloat(t.paddingLeft)||0)-(parseFloat(t.paddingRight)||0);e>0&&(r=Math.min(r,e))}if(o=Math.max(this.options.minWidth,Math.min(r,o)),n=Math.max(this.options.minHeight,Math.min(this.options.maxHeight,n)),(this.activeElement.classList.contains("inserted-image")||this.activeElement.classList.contains("inserted-video"))&&this.options.maintainAspectRatio){const t=o/this.aspectRatio,e=n*this.aspectRatio;Math.abs(o-e)<Math.abs(n-t)?o=e:n=t,o>r&&(o=r,n=o/this.aspectRatio)}this.options.snapToGrid&&(o=Math.round(o/this.options.gridSize)*this.options.gridSize,n=Math.round(n/this.options.gridSize)*this.options.gridSize),this.applyDimensions(o,n),this.updateHandlePosition(),this.emit("element-resize",{element:this.activeElement,width:o,height:n,handle:this.currentHandle})}handleMouseUp(t){this.isResizing&&(this.isResizing=!1,this.currentHandle=null,this.activeElement&&this.activeElement.classList.remove("resizing"),document.body.style.cursor="",document.body.style.userSelect="",this.emit("element-resize-complete",{element:this.activeElement,width:this.activeElement.offsetWidth,height:this.activeElement.offsetHeight}))}applyDimensions(t,e){if(this.activeElement)if(this.activeElement.classList.contains("rich-editor-table")){this.activeElement.style.width=t+"px",this.activeElement.style.minWidth=t+"px",this.activeElement.style.height=e+"px",this.activeElement.style.minHeight=e+"px";const i=this.activeElement.querySelectorAll("tr"),o=i.length>0?i[0].querySelectorAll("td, th").length:0;if(i.length>0&&o>0){const n=Math.floor(t/o),r=Math.floor(e/i.length);this.activeElement.querySelectorAll("td, th").forEach(t=>{t.style.minWidth=n+"px",t.style.minHeight=r+"px",t.style.height=r+"px"})}}else this.activeElement.style.width=t+"px",this.activeElement.style.height=e+"px","IFRAME"===this.activeElement.tagName&&(this.activeElement.width=t,this.activeElement.height=e)}getActiveElement(){return this.activeElement}setActiveElement(t){this.isResizableElement(t)&&this.showHandles(t)}checkAndUpdateHandles(){if(this.activeElement){if(!document.body.contains(this.activeElement)||!this.isResizableElement(this.activeElement))return void this.hideHandles();this.updateHandlePosition(),this.activeElement.classList.contains("rich-editor-table")&&this.checkTableSizeChange()}}refreshHandles(){this.activeElement&&document.body.contains(this.activeElement)&&this.updateHandlePosition()}setupTableSizeMonitoring(t){this.tableSizeInterval&&clearInterval(this.tableSizeInterval),this.tableSizeInterval=setInterval(()=>{this.activeElement&&this.activeElement.classList.contains("rich-editor-table")?this.checkTableSizeChange():(clearInterval(this.tableSizeInterval),this.tableSizeInterval=null)},100)}checkTableSizeChange(){if(!this.activeElement||!this.activeElement.classList.contains("rich-editor-table"))return;const t=this.activeElement.offsetWidth,e=this.activeElement.offsetHeight;(Math.abs(t-this.lastTableWidth)>1||Math.abs(e-this.lastTableHeight)>1)&&(this.lastTableWidth=t,this.lastTableHeight=e,this.updateHandlePosition(),this.emit("table-size-changed",{element:this.activeElement,width:t,height:e,previousWidth:this.lastTableWidth,previousHeight:this.lastTableHeight}))}setupMutationObserver(){"undefined"!=typeof MutationObserver&&(this.mutationObserver=new MutationObserver(t=>{let e=!1;t.forEach(t=>{if(this.activeElement){if("childList"===t.type){if(t.removedNodes)for(let i of t.removedNodes)if(i===this.activeElement||i.contains(this.activeElement)){e=!0;break}(t.target===this.activeElement||t.target.nodeType===Node.ELEMENT_NODE&&this.activeElement.contains(t.target))&&(e=!0)}if("characterData"===t.type&&this.activeElement.classList.contains("rich-editor-table")){let i=t.target;for(;i&&i!==this.activeElement;)i=i.parentNode;i===this.activeElement&&(e=!0)}if("attributes"===t.type&&this.activeElement.classList.contains("rich-editor-table")){const i=t.attributeName;"style"!==i&&"class"!==i||(e=!0)}}}),e&&setTimeout(()=>{this.checkAndUpdateHandles()},0)}),this.mutationObserver.observe(this.editor.editor,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style","class"],characterData:!0,characterDataOldValue:!0}))}setMaintainAspectRatio(t){this.options.maintainAspectRatio=t}setConstraints(t,e,i,o){this.options.minWidth=t||this.options.minWidth,this.options.minHeight=e||this.options.minHeight,this.options.maxWidth=i||this.options.maxWidth,this.options.maxHeight=o||this.options.maxHeight}destroy(){this.hideHandles(),this._onDocClick&&(this.editor.editor.removeEventListener("click",this._onEditorClick),document.removeEventListener("click",this._onDocClick),document.removeEventListener("mousemove",this._onDocMousemove),document.removeEventListener("mouseup",this._onDocMouseup),window.removeEventListener("scroll",this._onWindowScroll),this.editor.editor.removeEventListener("scroll",this._onEditorScroll),this._onEditorClick=this._onDocClick=this._onDocMousemove=null,this._onDocMouseup=this._onWindowScroll=this._onEditorScroll=null),this.handlesContainer&&this.handlesContainer.remove(),this.tableSizeInterval&&(clearInterval(this.tableSizeInterval),this.tableSizeInterval=null),this.mutationObserver&&(this.mutationObserver.disconnect(),this.mutationObserver=null),super.destroy()}}class zt{constructor(t={}){this.options={onImageInsert:null,editor:null,...t},this.popup=null,this.isVisible=!1,this.clickOutsideHandler=null,this.selectedImageSrc=null,this.savedSelection=null,this.resizeHandler=null,this.createImagePopup()}createImagePopup(){this.popup=document.createElement("div"),this.popup.className="image-popup";const t=document.createElement("div");t.className="image-popup-content";const e=document.createElement("h3");e.textContent="Insert image",e.className="yjd-input-title",t.appendChild(e);const i=document.createElement("div");i.className="image-input-container";const o=document.createElement("p");o.textContent="Your image url",o.className="yjd-input-label";const n=document.createElement("div");n.className="yjd-input-upload-group",this.inputGroup=n,this.urlInput=document.createElement("input"),this.urlInput.type="url",this.urlInput.className="yjd-input",this.urlInput.placeholder="Please enter your image URL",this.fileInput=document.createElement("input"),this.fileInput.type="file",this.fileInput.accept="image/*",this.fileInput.className="image-input-hidden",this.fileInput.addEventListener("change",t=>this.handleFileSelect(t));const r=document.createElement("button");r.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" x2="12" y1="3" y2="15"/></svg>',r.className="yjd-custom-upload-button",this.customButton=r,r.addEventListener("click",()=>this.fileInput.click()),this.createPreviewContainer(),n.appendChild(this.urlInput),n.appendChild(this.fileInput),n.appendChild(r),i.appendChild(o),i.appendChild(n),i.appendChild(this.previewContainer),t.appendChild(i),this.urlInput.addEventListener("input",()=>{this.updateInsertButton();const t=this.urlInput.value.trim();t&&this.isValidImageUrl(t)?this.showPreview(t):this.removePreview(),this.urlInput.value.trim()?this.customButton.style.display="none":this.customButton.style.display="flex"});const s=document.createElement("div");s.className="yjd-button-container";const a=document.createElement("button");a.type="button",a.className="image-button yjd-button-cancel",a.textContent="Cancel",a.addEventListener("click",()=>{this.hide(),this.options.editor&&setTimeout(()=>this.options.editor.focus(),0)}),this.insertButton=document.createElement("button"),this.insertButton.type="button",this.insertButton.className="image-button yjd-button-confirm button-disable",this.insertButton.textContent="Add image",this.insertButton.disabled=!0,this.insertButton.addEventListener("click",()=>{this.insertImage(),this.options.editor&&setTimeout(()=>this.options.editor.focus(),0)}),s.appendChild(a),s.appendChild(this.insertButton),t.appendChild(s),this.popup.appendChild(t),q(this.popup),this.options.editor&&"function"==typeof this.options.editor.preventFocusLoss&&this.options.editor.preventFocusLoss(this.popup)}async handleFileSelect(t){const e=t.target.files[0];if(e)try{const{default:t}=await Promise.resolve().then(function(){return ft});this.selectedImageSrc=await t.handleFileUpload(e),this.urlInput.value="",this.showPreview(this.selectedImageSrc),this.updateInsertButton()}catch(t){alert(t.message)}}updateInsertButton(){const t=this.selectedImageSrc||this.urlInput.value.trim();this.insertButton.disabled=!t,this.insertButton.classList.toggle("button-disable",!t)}showPreview(t){t&&(this.imagePreview.src=t,this.previewContainer.style.display="block",this.selectedImageSrc=t,this.toggleInputGroup(!1),this.recalculatePosition())}removePreview(){this.selectedImageSrc=null,this.previewContainer.style.display="none",this.imagePreview.src="",this.toggleInputGroup(!0),this.fileInput&&(this.fileInput.value=""),this.updateInsertButton(),this.recalculatePosition()}toggleInputGroup(t){this.inputGroup&&(t?(this.inputGroup.style.display="flex",this.inputGroup.style.visibility="visible",this.customButton&&(this.customButton.style.pointerEvents="auto")):(this.inputGroup.style.display="none",this.inputGroup.style.visibility="hidden"))}createPreviewContainer(){this.previewContainer=document.createElement("div"),this.previewContainer.className="image-preview-container",this.previewContainer.style.cssText="display: none; position: relative;",this.imagePreview=document.createElement("img"),this.imagePreview.className="image-preview",this.imagePreview.style.cssText="max-width: 100%; max-height: 200px; border-radius: 8px; object-fit: contain;",this.removeButton=document.createElement("button"),this.removeButton.className="image-remove-button",this.removeButton.innerHTML="×",this.removeButton.style.cssText="\n position: absolute; top: 5px; right: 5px; background: rgba(0,0,0,0.7);\n color: white; border: none; border-radius: 50%; width: 24px; height: 24px;\n cursor: pointer; font-size: 16px; font-weight: bold;\n ",this.removeButton.addEventListener("click",()=>this.removePreview()),this.previewContainer.appendChild(this.imagePreview),this.previewContainer.appendChild(this.removeButton)}isValidImageUrl(t){try{const e=new URL(t),i=[".jpg",".jpeg",".png",".gif",".webp",".svg",".bmp"],o=["imgur.com","images.unsplash.com","picsum.photos","via.placeholder.com"],n=e.pathname.toLowerCase(),r=i.some(t=>n.endsWith(t)),s=o.some(t=>e.hostname.includes(t));return r||s}catch{return!1}}async insertImage(){let t=this.selectedImageSrc||this.urlInput.value.trim();if(t){try{const{default:e}=await Promise.resolve().then(function(){return ft});if(!await e.validateImageUrl(t))return void alert("Invalid image URL. Please check the URL and try again.")}catch(t){return void alert("Error validating image URL.")}this.restoreSelection(),this.options.onImageInsert&&this.options.onImageInsert(t,""),this.hide(),this.reset()}}reset(){this.fileInput.value="",this.urlInput.value="",this.selectedImageSrc=null,this.previewContainer.style.display="none",this.imagePreview.src="",this.toggleInputGroup(!0),this.updateInsertButton(),this.customButton.style.display="block"}saveSelection(){const t=window.getSelection();t&&t.rangeCount>0&&(this.savedSelection=t.getRangeAt(0).cloneRange())}restoreSelection(){if(this.savedSelection){const t=window.getSelection();t.removeAllRanges(),t.addRange(this.savedSelection)}}setupClickOutside(){this.clickOutsideHandler&&document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=t=>{this.popup.contains(t.target)||this.hide()},setTimeout(()=>{document.addEventListener("click",this.clickOutsideHandler)},100)}setupResizeHandler(){this.resizeHandler&&window.removeEventListener("resize",this.resizeHandler),this.resizeHandler=()=>{this.isVisible&&this.recalculatePosition()},window.addEventListener("resize",this.resizeHandler)}removeResizeHandler(){this.resizeHandler&&(window.removeEventListener("resize",this.resizeHandler),this.resizeHandler=null)}removeClickOutside(){this.clickOutsideHandler&&(document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=null)}show(t){if(!t)return;this.saveSelection(),this.reset(),this.currentAnchor=t;const e=$(t,this.popup,{offsetY:5,offsetX:0});W(this.popup,e),this.popup.classList.add("visible"),this.isVisible=!0,this.setupClickOutside()}recalculatePosition(){this.currentAnchor&&this.isVisible&&setTimeout(()=>{const t=$(this.currentAnchor,this.popup,{offsetY:5,offsetX:0});W(this.popup,t)},10)}hide(){this.popup.classList.remove("visible"),this.isVisible=!1,this.removeClickOutside(),this.savedSelection=null}destroy(){this.removeClickOutside(),this.popup&&this.popup.parentNode&&this.popup.parentNode.removeChild(this.popup),this.popup=null,this.isVisible=!1}}t.register("formats/bold",M,!0),t.register("formats/italic",O,!0),t.register("formats/underline",P,!0),t.register("formats/strike",_,!0),t.register("formats/subscript",F,!0),t.register("formats/superscript",D,!0),t.register("formats/color",K,!0),t.register("formats/background",G,!0),t.register("formats/link",Q,!0),t.register("formats/table",J,!0),t.register("formats/heading",et,!0),t.register("formats/font-family",it,!0),t.register("formats/line-height",ot,!0),t.register("formats/capitalization",nt,!0),t.register("formats/text-align",st,!0),t.register("formats/list",ct,!0),t.register("formats/indent",dt,!0),t.register("formats/indent-increase",pt,!0),t.register("formats/indent-decrease",ht,!0),t.register("formats/emoji",mt,!0),t.register("formats/image",gt,!0),t.register("formats/video",bt,!0),t.register("formats/tag",wt,!0),t.register("formats/text-size",Ct,!0),t.register("formats/import",kt,!0),t.register("modules/toolbar",Tt,!0),t.register("modules/history",It,!0),t.register("modules/block-toolbar",St,!0),t.register("modules/table-toolbar",Nt,!0),t.register("modules/code-view",Lt,!0),t.register("modules/find-replace",At,!0),t.register("modules/slash-menu",Bt,!0),t.register("modules/mention",Rt,!0),t.register("modules/resize-handles",Ht,!0),t.register("ui/color-picker",X,!0),t.register("ui/text-align-picker",rt,!0),t.register("ui/list-picker",lt,!0),t.register("ui/emoji-picker",ut,!0),t.register("ui/image-popup",zt,!0),t.register("ui/video-popup",yt,!0),t.register("ui/tag-popup",xt,!0),t.register("ui/custom-button",jt,!0),class{static loaded=!1;static styleElement=null;static loadStyles(){if(this.loaded)return Promise.resolve();try{this.styleElement=document.createElement("style"),this.styleElement.id="rich-editor-styles",this.styleElement.textContent='@keyframes rte-pop-in{0%{opacity:0;transform:translateY(-2px)}to{opacity:1;transform:none}}@keyframes yjd-slash-in{0%{opacity:0;transform:translateY(-2px)}to{opacity:1;transform:none}}@keyframes yjd-spin{to{transform:rotate(360deg)}}.yjd-rich-editor,.yjd-rich-editor .rich-editor-area{background:#fff;position:relative;box-sizing:border-box}.yjd-rich-editor{border:1px solid #d1d5db;border-radius:8px;overflow:hidden;margin:0 auto;display:flex;flex-direction:column}@layer base{.yjd-rich-editor .toolbar-container ::file-selector-button,.yjd-rich-editor .toolbar-container button,.yjd-rich-editor .toolbar-container input,.yjd-rich-editor .toolbar-container optgroup,.yjd-rich-editor .toolbar-container select,.yjd-rich-editor .toolbar-container textarea{font:500 14px/1.4"Inter",Arial,sans-serif!important;letter-spacing:normal!important;font-feature-settings:normal!important;font-variation-settings:normal!important}.yjd-rich-editor .emoji-picker-popup .emoji-button,.yjd-rich-editor .emoji-picker-popup button.emoji-button{font-size:20px!important}}@layer base{.yjd-rich-editor .rich-editor-popup-container ::file-selector-button,.yjd-rich-editor .rich-editor-popup-container button,.yjd-rich-editor .rich-editor-popup-container input,.yjd-rich-editor .rich-editor-popup-container optgroup,.yjd-rich-editor .rich-editor-popup-container select,.yjd-rich-editor .rich-editor-popup-container textarea{font:500 14px/1.4"Inter",Arial,sans-serif!important;letter-spacing:normal!important;font-feature-settings:normal!important;font-variation-settings:normal!important}.yjd-rich-editor .emoji-picker-popup .emoji-button,.yjd-rich-editor .emoji-picker-popup button.emoji-button{font-size:20px!important}}.yjd-rich-editor .rich-editor-area{flex:1 1 auto;min-height:40px;outline:0;overflow-y:auto;border:0;text-align:left;font-family:inherit;color:#2c3e50}.yjd-rich-editor .rich-editor-area[data-placeholder]:before{content:attr(data-placeholder);color:#9ca3af;pointer-events:none;position:absolute;top:0;left:0;right:0;padding:inherit;box-sizing:border-box;font:inherit;font-style:italic;line-height:inherit;display:none;z-index:1}.yjd-rich-editor .custom-select-item-button.current .item-checkmark,.yjd-rich-editor .rich-editor-area div,.yjd-rich-editor .rich-editor-area[data-placeholder].placeholder-visible:before{display:block}.yjd-rich-editor .rich-editor-area b,.yjd-rich-editor .rich-editor-area strong{font-weight:700}.yjd-rich-editor .rich-editor-area em,.yjd-rich-editor .rich-editor-area i{font-style:italic}.yjd-rich-editor .rich-editor-area u{text-decoration:underline}.yjd-rich-editor .rich-editor-area a{color:#2563eb;text-decoration:underline;cursor:pointer;color:var(--rte-accent-ink);text-decoration-color:var(--rte-accent-ring);text-underline-offset:2px}.yjd-content p,.yjd-rich-editor .rich-editor-area p{margin:0 0 1em}.yjd-content h1,.yjd-rich-editor .rich-editor-area h1{font-size:2em;font-weight:700;margin:.67em 0}.yjd-content h2,.yjd-rich-editor .rich-editor-area h2{font-size:1.5em;font-weight:700;margin:.75em 0}.yjd-content h3,.yjd-rich-editor .rich-editor-area h3{font-size:1.25em;font-weight:700;margin:.83em 0}.yjd-content h4,.yjd-rich-editor .rich-editor-area h4{font-size:1.1em;font-weight:700;margin:1em 0}.yjd-content h5,.yjd-rich-editor .rich-editor-area h5{font-size:1em;font-weight:700;margin:1.25em 0}.yjd-content h6,.yjd-rich-editor .rich-editor-area h6{font-size:.875em;font-weight:700;margin:1.5em 0;color:#555}.yjd-content ol,.yjd-content ul{margin:0 0 1em 2em;padding:0}.yjd-rich-editor .rich-editor-area ol,.yjd-rich-editor .rich-editor-area ul{padding:0}.yjd-rich-editor .rich-editor-area li{margin:.25em 0 4px;line-height:1.6}.yjd-rich-editor .rich-editor-area code,.yjd-rich-editor .rich-editor-area pre{font-family:Consolas,Menlo,Monaco,"Courier New",monospace;background:#f1f2f3;overflow-x:auto}.yjd-rich-editor .rich-editor-area pre{border-radius:4px;display:block;margin:1em 0;background-color:#f1f2f3;width:96%;white-space:pre;word-wrap:normal;background:#20242f;color:#ececf5;border-radius:var(--rte-radius-md);padding:14px 16px;border:0}.yjd-rich-editor .rich-editor-area code{display:inline;background:var(--rte-chrome-2);border-radius:6px;padding:2px 6px;font-size:.9em}.yjd-content blockquote{margin:1em 0;padding:4px 12px}.yjd-content blockquote,.yjd-rich-editor .rich-editor-area blockquote{border-left:4px solid #d1d5db;color:#555;font-style:italic;background:#f9fafb}.yjd-rich-editor .rich-editor-area sub{font-size:.75em;vertical-align:sub;line-height:1}.yjd-rich-editor .rich-editor-area sup{font-size:.75em;vertical-align:super;line-height:1}.yjd-rich-editor .rich-editor-area:empty::before{content:"";display:block}.yjd-rich-editor .rich-editor-statusbar{position:relative;z-index:1000;border-top:1px solid #d1d5db;background:#f9fafb;font-size:13px;color:#6b7280;font-family:inherit;min-height:32px;box-sizing:border-box}.yjd-rich-editor .rich-editor-toolbar-container{border-bottom:1px solid #d1d5db;position:relative;z-index:1000}.yjd-rich-editor .rich-editor-toolbar-1,.yjd-rich-editor .rich-editor-toolbar-2{gap:20px;background:#fcfcfc;min-height:48px;box-sizing:border-box;width:100%;z-index:1000;position:relative}.yjd-rich-editor .rich-editor-toolbar-2{display:none;overflow:hidden}.yjd-rich-editor .rich-editor-toolbar-2.visible{display:flex}.yjd-rich-editor .rich-editor-toolbar-btn{width:22px;border-radius:4px;font-size:14px;font-weight:500}.yjd-rich-editor .custom-select-button span{justify-content:left!important}.yjd-rich-editor .custom-select-button:focus{outline:0;border-color:#3b82f6;box-shadow:0 0 0 1px rgba(59,130,246,.1)}.yjd-rich-editor .rich-editor-toolbar-btn span{display:flex!important;align-items:center;justify-content:center}.yjd-rich-editor .rich-editor-toolbar-btn:hover{background:#eee!important;cursor:pointer}.yjd-rich-editor .block-toolbar-btn{border-radius:4px;padding:4px;cursor:pointer;font-size:14px;font-weight:500;align-items:center;justify-content:center;display:inline-flex}.yjd-rich-editor .block-toolbar-btn:hover{background:#eee}.yjd-rich-editor .block-toolbar-btn.active{background:#ccc;color:#136fdf!important}.yjd-rich-editor .block-toolbar-btn.active svg,.yjd-rich-editor .block-toolbar-btn.active svg path{fill:#136fdf!important}.yjd-rich-editor .block-toolbar-container{display:flex;align-items:center;background:#fff;border-radius:6.9px;box-shadow:0 4px 24px rgba(0,0,0,.13)}.yjd-rich-editor .block-toolbar-arrow{position:absolute;bottom:-6px;left:50%;transform:translateX(-50%);width:0;height:0;border-left:6px solid transparent;border-right:6px solid transparent;border-top:6px solid #fff;filter:drop-shadow(0 2px 4px rgba(0,0,0,.1))}.yjd-rich-editor .table-toolbar-container{display:flex;align-items:center;background:#fff;border-radius:6px;box-shadow:0 4px 24px rgba(0,0,0,.13)}.yjd-rich-editor .table-toolbar-arrow{position:absolute;bottom:-6px;left:50%;transform:translateX(-50%);width:0;height:0;border-left:6px solid transparent;border-right:6px solid transparent;border-top:6px solid #fff;filter:drop-shadow(0 2px 4px rgba(0,0,0,.1))}.yjd-rich-editor .block-toolbar{display:none;position:absolute;z-index:1001;background:0 0;border:0;border-radius:6.9px;box-sizing:border-box;padding:0;gap:0;flex-direction:column;align-items:center}.yjd-rich-editor .block-toolbar.visible{display:flex}.yjd-rich-editor .color-picker-popup{position:absolute;background:#fff;display:none;border-radius:6.9px;padding:8px;z-index:1000;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.yjd-rich-editor .capitalization-select-popup.visible,.yjd-rich-editor .color-picker-popup.visible,.yjd-rich-editor .custom-select-popup.visible,.yjd-rich-editor .font-family-select-popup.visible,.yjd-rich-editor .heading-select-popup.visible,.yjd-rich-editor .line-height-select-popup.visible,.yjd-rich-editor .text-size-select-popup.visible{display:block!important}.yjd-rich-editor .capitalization-select-popup,.yjd-rich-editor .custom-select-popup,.yjd-rich-editor .font-family-select-popup,.yjd-rich-editor .heading-select-popup,.yjd-rich-editor .line-height-select-popup,.yjd-rich-editor .text-size-select-popup{position:absolute;background:#fff;display:none;border:1px solid #d1d5db;border-radius:6.9px;z-index:1002;max-height:200px;overflow-y:auto;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.yjd-rich-editor .image-popup,.yjd-rich-editor .link-popup,.yjd-rich-editor .tag-popup,.yjd-rich-editor .video-popup{width:299px}.yjd-rich-editor .item-list{display:flex;flex-direction:column;gap:2px}.yjd-rich-editor .heading-select-popup{width:190px;max-width:100vw}.yjd-rich-editor .capitalization-select-popup{width:150px;max-width:100vw}.yjd-rich-editor .font-family-select-popup{width:190px;max-width:100vw}.yjd-rich-editor .line-height-select-popup{width:80px;max-width:100vw}.yjd-rich-editor .text-size-select-popup{width:150px;max-width:100vw}.yjd-rich-editor .custom-select-item-button{width:100%;border:0;background:0 0;border-radius:6px;cursor:pointer;text-align:left;transition:all .2s ease;font-size:14px;line-height:1.4;color:#111827;display:flex;align-items:center;justify-content:space-between;pointer-events:auto}.yjd-rich-editor .custom-select-item-button:hover{background:#eee}.yjd-rich-editor .custom-select-item-button.current{background:#eee!important}.yjd-rich-editor .custom-select-item-button .item-checkmark{display:none}.yjd-rich-editor .item-text{flex:1}.yjd-rich-editor .dropdown-icon{display:inline-flex!important;align-items:center;justify-content:center;width:16px;height:16px;flex:0 0 auto}.yjd-rich-editor .dropdown-icon svg{width:16px;height:16px;display:block;stroke:currentColor;fill:none}.yjd-rich-editor .color-grid{display:grid;grid-template-columns:repeat(6,1fr);gap:6px 4px;margin-bottom:12px}.yjd-rich-editor .color-button{width:24px;height:24px;border:0;border-radius:50%;cursor:pointer;transition:all .2s ease;padding:0;margin:0;pointer-events:auto}.yjd-rich-editor .color-button:hover{transform:scale(1.1);border-color:#374151;box-shadow:0 2px 4px rgba(0,0,0,.1)}.yjd-rich-editor .custom-color-container{position:relative;padding-top:8px;display:flex;align-items:center;gap:8px;z-index:0}.yjd-rich-editor .custom-color-container::before{content:"";position:absolute;top:0;left:-8px;width:calc(100% + 16px);height:0;border-top:1px solid #e5e7eb;z-index:-1}.yjd-rich-editor .custom-color-label{font-size:12px;color:#6b7280;margin:0}.yjd-rich-editor .yjd-input-label,.yjd-rich-editor .yjd-input-title{margin:0;color:#252424;font-size:16px;font-style:normal;line-height:normal}.yjd-rich-editor .yjd-input-label{font-size:14px;font-weight:700}.yjd-rich-editor .yjd-input-group{display:flex;flex-direction:column;gap:8px}.yjd-rich-editor .yjd-input{flex:1 1 auto;min-width:0;max-width:100%;max-height:37px;border-radius:10px;border:1px solid #e1e1e1;color:#252424!important}.yjd-rich-editor .yjd-input:focus{border-color:#3b82f6;box-shadow:0 0 0 1px rgba(59,130,246,.1)}.yjd-rich-editor .yjd-button-container{display:flex;justify-content:flex-end;gap:4px}.yjd-rich-editor .yjd-button-cancel,.yjd-rich-editor .yjd-button-confirm{border-radius:6px;align-items:center;box-shadow:0 1px 3.3px 0 rgba(0,0,0,.04);font-style:normal;line-height:normal;cursor:pointer}.yjd-rich-editor .yjd-button-confirm{background:#181616}.yjd-rich-editor .yjd-button-cancel{border:1px solid #e0e0e0;background:#fff;color:#2a2727}.yjd-rich-editor .button-disable{cursor:not-allowed}.yjd-rich-editor .link-popup{position:absolute;background:#fff;font-family:"Lato",sans-serif;display:none;border:0;border-radius:10px;z-index:1000;margin:0;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.yjd-rich-editor .link-popup.visible{display:block!important}.yjd-rich-editor .link-popup-content{display:flex;flex-direction:column;gap:16px;padding:16px}.yjd-rich-editor .yjd-input-upload-group{display:flex;align-items:center;gap:4px}.yjd-rich-editor .yjd-custom-upload-button{display:flex!important;align-items:center;justify-content:center;padding:0;border:1px solid #e1e1e1;background:#fff;width:34px;height:34px;border-radius:10px;cursor:pointer}.yjd-rich-editor .yjd-suggestions-list{display:flex;flex-wrap:wrap;gap:8px;flex:1 1 auto;min-width:0;max-width:100%}.yjd-rich-editor .yjd-suggestion-button{border:0;display:flex;padding:4px 10px;justify-content:center;align-items:center;border-radius:30px;background:#f5f5f5;cursor:pointer;font-size:14px;color:#252424!important}.yjd-rich-editor .yjd-select-input{border-radius:10px;border:1px solid #e1e1e1;max-height:37px;align-items:center;color:#252424!important}.yjd-rich-editor .yjd-select-input:focus{border-color:#3b82f6;box-shadow:0 0 0 1px rgba(59,130,246,.1)}.yjd-rich-editor .table-popup{position:absolute;background:#fff;font-family:"Lato",sans-serif;display:none;border:1px solid #d1d5db;border-radius:6.9px;z-index:1000;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.yjd-rich-editor .table-popup.visible{display:block!important}.yjd-rich-editor .table-popup-content{padding:8px;display:flex;flex-direction:column;align-items:center;gap:12px;position:relative}.yjd-rich-editor .table-popup-content>*{position:relative;width:100%}.yjd-rich-editor .table-popup-content>:not(:last-child)::after{content:"";position:absolute;bottom:-8px;left:-8px;right:-8px;height:1px;background-color:#e5e7eb}.yjd-rich-editor .table-grid-selector{display:grid;grid-template-columns:repeat(8,1fr);gap:1px;border-bottom:1px solid #eee}.yjd-rich-editor .table-size-display{display:flex;align-items:center;justify-content:center;font-family:"Lato",sans-serif;color:#252424!important;font-size:12px;font-style:normal;font-weight:400;line-height:normal}.yjd-rich-editor .table-grid-cell{width:20px;height:20px;background:#fff;border:1px solid #eee;cursor:pointer;transition:background-color .1s ease;border-radius:2px}.yjd-rich-editor .table-grid-cell.highlighted,.yjd-rich-editor .table-grid-cell:hover{background:#eee}.yjd-rich-editor .rich-editor-table{border-collapse:collapse;width:100%;max-width:100%;box-sizing:border-box;margin:16px 0;font-size:14px;line-height:1.5;position:relative;display:table;table-layout:fixed}.yjd-rich-editor .rich-editor-table td{box-sizing:border-box;border:1px solid #d1d5db;padding:8px 12px;min-height:28px;vertical-align:top;background:#fff;overflow-wrap:break-word}.yjd-rich-editor .rich-editor-table td:focus{outline-offset:-2px;background:#fefefe}.yjd-rich-editor .table-toolbar{position:absolute;display:none;z-index:1002;background:0 0;border:0;border-radius:6.9px;opacity:0;pointer-events:none}.yjd-rich-editor .table-toolbar-group{display:flex;gap:8px;align-items:center}.yjd-rich-editor .table-toolbar.visible{display:block;opacity:1;pointer-events:auto;transform:translateY(0)}.yjd-rich-editor .table-toolbar-btn{padding:4px;display:inline-flex;align-items:center;justify-content:center;border-radius:4px;font-size:12px;font-weight:500;cursor:pointer;transition:all .15s ease;white-space:nowrap}.yjd-rich-editor .table-toolbar-btn:hover{background:#f3f4f6;color:#111827}.yjd-rich-editor .table-toolbar-btn:active{background:#e5e7eb;border-color:#9ca3af;color:#136fdf!important}@media (max-width:768px){.yjd-rich-editor .table-toolbar-container{flex-wrap:wrap;max-width:200px;gap:2px}.yjd-rich-editor .table-toolbar-btn{height:24px;min-width:24px;font-size:10px;padding:2px 4px}}.yjd-rich-editor .text-align-picker-popup{position:absolute;background:#fff;display:none;border:1px solid #d1d5db;border-radius:6.9px;z-index:1000;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.yjd-rich-editor .text-align-picker-popup.visible{display:block!important}.yjd-rich-editor .align-button-container{display:flex}.yjd-rich-editor .align-button .icon-wrapper{display:flex;margin-left:8px;align-items:center;justify-content:center}.yjd-rich-editor .align-button .label-text{color:#252424;font-size:12px;font-style:normal;font-weight:400;line-height:normal}.yjd-rich-editor .align-button{border-radius:3.456px;background:#fff;border:0;align-items:center;display:flex;cursor:pointer;pointer-events:auto}.yjd-rich-editor .align-button:hover{background:#f3f4f6}.yjd-rich-editor .align-button.active{background:#e5e7eb}.yjd-rich-editor .align-button.active svg{color:#1f2937}.yjd-rich-editor .list-picker-popup{position:absolute;background:#fff;display:none;border-radius:6.9px;box-shadow:0 4px 16px rgba(0,0,0,.1);z-index:1000;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.yjd-rich-editor .list-picker-popup.visible{display:block!important}.yjd-rich-editor .list-button-container{display:grid;grid-template-columns:repeat(3,1fr)}.yjd-rich-editor .list-button{border-radius:3.46px;display:flex}.yjd-rich-editor .list-button:hover{background:#f3f4f6}.yjd-rich-editor .list-button.active{background:#eee}.yjd-rich-editor .list-button svg{color:#374151}.yjd-rich-editor .list-button.active svg{color:#fff}.yjd-rich-editor .rich-editor-area ul.checklist{list-style:none;padding-left:0}.yjd-rich-editor .rich-editor-area ul.checklist li{position:relative;padding-left:25px;margin-bottom:4px}.yjd-rich-editor .rich-editor-area ul.checklist li input[type=checkbox]{position:absolute;left:0;top:2px;margin:0;cursor:pointer}.yjd-rich-editor .rich-editor-area ol,.yjd-rich-editor .rich-editor-area ul{margin:12px 0;padding-left:20px}.yjd-rich-editor .rich-editor-area .indented,.yjd-rich-editor .rich-editor-area [style*=padding-left]{transition:padding-left .2s ease}.yjd-rich-editor .indent-decrease-btn svg,.yjd-rich-editor .indent-increase-btn svg{width:16px;height:16px;fill:#454545}.yjd-rich-editor .indent-decrease-btn:hover svg,.yjd-rich-editor .indent-increase-btn:hover svg{fill:#454545}.yjd-rich-editor .indent-decrease-btn:disabled,.yjd-rich-editor .indent-increase-btn:disabled{opacity:.5;cursor:not-allowed}.yjd-rich-editor .indent-decrease-btn:disabled svg,.yjd-rich-editor .indent-increase-btn:disabled svg{fill:#9ca3af}.yjd-rich-editor .emoji-picker-popup{position:absolute;z-index:10000;background:#fff;border-radius:8px;padding:8px;display:none;overflow-y:auto;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.yjd-rich-editor .emoji-picker-popup.visible{display:block}.yjd-rich-editor .emoji-grid{display:grid;grid-template-columns:repeat(10,1fr);gap:4px;max-height:240px;overflow-y:auto}.yjd-rich-editor .emoji-text-message{margin-top:4px;color:#71787c;text-align:center;font-family:"Segoe UI",Arial,sans-serif;font-size:12px;font-style:normal;font-weight:400;line-height:normal}.yjd-rich-editor .emoji-button{width:28px;height:28px;border:0;background:0 0;padding:0;border-radius:4px;cursor:pointer;font-size:20px!important;display:flex;align-items:center;justify-content:center;transition:background-color .2s ease;pointer-events:auto}.yjd-rich-editor .emoji-button:hover{background-color:#f3f4f6}.yjd-rich-editor .emoji{font-size:1.1em;line-height:1}.yjd-rich-editor .image-popup{position:absolute;z-index:10000;background:#fff;font-family:"Lato",sans-serif;border-radius:10px;display:none;margin:0;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.yjd-rich-editor .image-popup.visible,.yjd-rich-editor .tag-popup.visible,.yjd-rich-editor .video-popup.visible{display:block}.yjd-rich-editor .image-popup-content{display:flex;flex-direction:column;gap:16px;padding:16px}.yjd-rich-editor .image-input-container{gap:8px;display:flex;flex-direction:column}.yjd-rich-editor .image-input-hidden{display:none}.yjd-rich-editor .video-popup{position:absolute;z-index:10000;background:#fff;font-family:"Lato",sans-serif;border-radius:10px;display:none;margin:0;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.yjd-rich-editor .video-popup-content{display:flex;flex-direction:column;gap:16px;padding:16px}.yjd-rich-editor .video-input-container{gap:8px;display:flex;flex-direction:column}.yjd-rich-editor .inserted-image,.yjd-rich-editor .inserted-video{max-width:100%;height:auto;margin:4px 0;border-radius:4px;display:block}.yjd-rich-editor .inserted-video{background:#000}.yjd-rich-editor .tag-popup{position:absolute;z-index:10000;background:#fff;font-family:"Lato",sans-serif;border-radius:10px;display:none;margin:0;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.tag-popup{max-height:80vh;overflow-y:auto}.tag-suggestions-container{max-height:200px;overflow-y:auto}.yjd-rich-editor .tag-popup-content{display:flex;flex-direction:column;gap:16px;padding:16px}.yjd-rich-editor .tag-type-container{gap:8px;display:flex;flex-direction:column}.yjd-rich-editor .custom-tag{display:inline-block;padding:2px 6px;border-radius:12px;font-size:.85em;font-weight:500;cursor:pointer;margin:0 2px}.yjd-rich-editor .custom-tag.tag-mention{background:#dbeafe;color:#1d4ed8}.yjd-rich-editor .custom-tag.tag-hashtag{background:#dcfce7;color:#166534}.yjd-rich-editor .custom-tag.tag-custom{background:#fef3c7;color:#92400e}.yjd-rich-editor .custom-tag:hover{opacity:.8}.yjd-rich-editor .import-popup{position:absolute;z-index:10000;background:#fff;border:1px solid #d1d5db;border-radius:8px;display:none;width:400px;max-width:90vw;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.yjd-rich-editor .import-popup.visible{display:block}.yjd-rich-editor .import-popup-content{padding:20px}.yjd-rich-editor .import-popup-title{margin:0 0 20px;font-size:18px;font-weight:600;color:#1f2937}.yjd-rich-editor .import-type-container{margin-bottom:20px}.yjd-rich-editor .import-input-label{display:block;margin-bottom:8px;font-size:14px;font-weight:500;color:#374151}.yjd-rich-editor .import-type-select{border:1px solid #d1d5db;border-radius:6px;font-size:14px;background:#fff;color:#374151}.yjd-rich-editor .import-type-select:focus{border-color:#3b82f6;box-shadow:0 0 0 1px rgba(59,130,246,.1)}.yjd-rich-editor .import-file-input{width:100%;padding:10px 12px;border:1px solid #d1d5db;border-radius:6px;font-size:14px;background:#fff;color:#374151;margin-bottom:16px;cursor:pointer;box-sizing:border-box}.yjd-rich-editor .import-file-input:disabled{background-color:#f3f4f6;cursor:not-allowed;opacity:.5}.yjd-rich-editor .import-file-input:focus{outline:0;border-color:#3b82f6;box-shadow:0 0 0 1px rgba(59,130,246,.1)}.yjd-rich-editor .import-file-info{padding:12px;background-color:#f9fafb;border:1px solid #e5e7eb;border-radius:6px;margin-bottom:16px;font-size:14px;color:#374151}.yjd-rich-editor .import-file-info div{margin-bottom:4px}.yjd-rich-editor .import-file-info div:last-child{margin-bottom:0}.yjd-rich-editor .import-button-container{display:flex;justify-content:flex-end;gap:10px;margin-top:20px}.yjd-rich-editor .import-button{padding:10px 20px;border:1px solid #d1d5db;border-radius:6px;font-size:14px;font-weight:500;cursor:pointer;transition:all .2s}.yjd-rich-editor .import-button:hover{background-color:#f3f4f6}.yjd-rich-editor .import-button.import-button-main{background-color:#3b82f6;color:#fff;border-color:#3b82f6}.yjd-rich-editor .import-button.import-button-main:hover{background-color:#2563eb}.yjd-rich-editor .import-button.import-button-main:disabled{background-color:#9ca3af;border-color:#9ca3af;cursor:not-allowed}.yjd-rich-editor .import-button.cancel-button{background-color:#fff;color:#6b7280}.yjd-rich-editor .import-button.cancel-button:hover,.yjd-rich-editor .imported-table tr:hover{background-color:#f9fafb}.yjd-rich-editor .imported-content{margin:16px 0;padding:16px;border:1px dashed #d1d5db;border-radius:6px;background-color:#f9fafb}.yjd-rich-editor .imported-content.html-content{border-color:#3b82f6;background-color:#eff6ff}.yjd-rich-editor .imported-content.excel-content{border-color:#10b981;background-color:#f0fdf4}.yjd-rich-editor .imported-content.text-content{border-color:#f59e0b;background-color:#fffbeb}.yjd-rich-editor .imported-table{width:100%;border-collapse:collapse;font-size:14px;background:#fff;border-radius:4px;overflow:hidden;box-shadow:0 1px 3px rgba(0,0,0,.1)}.yjd-rich-editor .imported-table td,.yjd-rich-editor .imported-table th{padding:12px;text-align:left;border-bottom:1px solid #e5e7eb}.yjd-rich-editor .imported-table th{background-color:#f3f4f6;font-weight:600;color:#374151}.yjd-rich-editor .imported-content p{margin:8px 0;line-height:1.6;color:#374151}.yjd-rich-editor .imported-content p:first-child{margin-top:0}.yjd-rich-editor .imported-content p:last-child{margin-bottom:0}.yjd-rich-editor .code-view-textarea{width:100%;height:500px;font-family:"Consolas","Monaco","Courier New",monospace;font-size:14px;line-height:1.5;padding:16px;background-color:#f8fafc;color:#374151;resize:vertical;border:0;outline:0;white-space:pre;word-wrap:break-word;tab-size:2;box-sizing:border-box}@media (max-width:768px){.yjd-rich-editor .code-view-textarea{font-size:13px;padding:12px}.yjd-rich-editor.code-view-active::after{top:5px;right:5px;font-size:11px;padding:3px 6px}}.yjd-rich-editor .resize-handles-container{position:absolute;pointer-events:none;z-index:997;display:none}.yjd-rich-editor .resize-handles-container.active{display:block}.yjd-rich-editor .resize-handle{position:absolute;width:8px;height:8px;background-color:#3b82f6;pointer-events:auto;box-shadow:0 2px 4px rgba(0,0,0,.2);transition:all .2s ease;z-index:999}.yjd-rich-editor .resize-handle:hover{background-color:#2563eb;transform:scale(1.2);box-shadow:0 2px 6px rgba(0,0,0,.3)}.yjd-rich-editor .resize-handle-nw{top:-4px;left:-4px;cursor:nw-resize}.yjd-rich-editor .resize-handle-ne{top:-4px;right:-4px;cursor:ne-resize}.yjd-rich-editor .resize-handle-sw{bottom:-4px;left:-4px;cursor:sw-resize}.yjd-rich-editor .resize-handle-se{bottom:-4px;right:-4px;cursor:se-resize}.yjd-rich-editor .inserted-image.resizing,.yjd-rich-editor .inserted-video.resizing,.yjd-rich-editor .rich-editor-table.resizing{outline:2px solid #3b82f6;outline-offset:2px;opacity:.8}.yjd-rich-editor .inserted-image.resizing,.yjd-rich-editor .inserted-video.resizing{-webkit-user-select:none;user-select:none;pointer-events:none}.yjd-rich-editor .rich-editor-table.resizing{-webkit-user-select:none;user-select:none}.yjd-rich-editor .rich-editor-table.resizing td{pointer-events:none}.yjd-rich-editor .inserted-image:hover,.yjd-rich-editor .inserted-video:hover,.yjd-rich-editor .rich-editor-table:hover{outline:1px solid #3b82f6;outline-offset:1px;cursor:pointer}@media (max-width:768px){.yjd-rich-editor .resize-handle{width:12px;height:12px}.yjd-rich-editor .resize-handle-nw{top:-6px;left:-6px}.yjd-rich-editor .resize-handle-ne{top:-6px;right:-6px}.yjd-rich-editor .resize-handle-sw{bottom:-6px;left:-6px}.yjd-rich-editor .resize-handle-se{bottom:-6px;right:-6px}}@media (max-width:849px){.yjd-rich-editor{margin:0;width:100%!important;max-width:100%!important}.yjd-rich-editor .rich-editor-area{padding:12px;min-height:150px;font-size:14px;line-height:1.4}.yjd-rich-editor .rich-editor-statusbar{padding:6px 8px;font-size:11px;flex-wrap:wrap;gap:8px}.yjd-rich-editor .editor-dropdown,.yjd-rich-editor .editor-popup{position:fixed!important;top:50%!important;left:50%!important;transform:translate(-50%,-50%)!important;width:90%!important;max-width:320px!important;max-height:80vh!important;overflow-y:auto;z-index:10000}.yjd-rich-editor .editor-popup::before{content:"";position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,.5);z-index:-1}.yjd-rich-editor .color-picker{width:100%!important;max-width:280px!important}.yjd-rich-editor .color-picker-grid{grid-template-columns:repeat(6,1fr)!important;gap:8px!important}.yjd-rich-editor .color-picker-item{width:32px!important;height:32px!important}.yjd-rich-editor .table-popup{max-width:300px!important}.yjd-rich-editor .table-size-grid{grid-template-columns:repeat(8,1fr)!important;gap:2px!important}.yjd-rich-editor .table-size-cell{width:24px!important;height:24px!important}.yjd-rich-editor .list-picker{width:100%!important;max-width:250px!important}.yjd-rich-editor .list-picker-btn{padding:12px!important;font-size:14px!important}.yjd-rich-editor .text-align-picker{width:100%!important;max-width:200px!important}.yjd-rich-editor .image-popup,.yjd-rich-editor .import-popup,.yjd-rich-editor .link-popup,.yjd-rich-editor .video-popup{width:90%!important;max-width:350px!important}.yjd-rich-editor .media-upload-area{min-height:100px!important;padding:20px!important}.yjd-rich-editor .tag-popup{width:90%!important;max-width:320px!important}.yjd-rich-editor .emoji-picker{width:100%!important;max-width:300px!important;max-height:350px!important}.yjd-rich-editor .emoji-grid{grid-template-columns:repeat(8,1fr)!important;gap:4px!important}.yjd-rich-editor .emoji-item{width:32px!important;height:32px!important;font-size:18px!important}.yjd-rich-editor .code-view-textarea{font-size:12px!important;padding:8px!important;line-height:1.3!important}.yjd-rich-editor .rich-editor-area h1{font-size:1.5em!important;margin:.5em 0!important}.yjd-rich-editor .rich-editor-area h2{font-size:1.3em!important;margin:.5em 0!important}.yjd-rich-editor .rich-editor-area h3{font-size:1.1em!important;margin:.5em 0!important}.yjd-rich-editor .rich-editor-area p{margin:.8em 0!important}.yjd-rich-editor .rich-editor-area ol,.yjd-rich-editor .rich-editor-area ul{padding-left:20px!important;margin:.8em 0!important}.yjd-rich-editor .rich-editor-area blockquote{padding-left:12px!important;margin:.8em 0!important;font-size:14px!important}.yjd-rich-editor .rich-editor-area table{font-size:13px!important;overflow-x:auto!important;display:block!important;white-space:nowrap!important}.yjd-rich-editor .rich-editor-area td,.yjd-rich-editor .rich-editor-area th{padding:6px 8px!important;min-width:60px!important}}@media (max-width:290px){.yjd-rich-editor .emoji-picker{max-width:calc(100vw - 20px)!important}.yjd-rich-editor .emoji-grid{grid-template-columns:repeat(auto-fit,minmax(30px,1fr))!important}}@media print{.yjd-rich-editor .rich-editor-statusbar,.yjd-rich-editor .rich-editor-toolbar-1,.yjd-rich-editor .rich-editor-toolbar-2{display:none!important}.yjd-rich-editor{border:0!important;box-shadow:none!important}.yjd-rich-editor .rich-editor-area{padding:0!important;background:#fff!important;color:#000!important}}.yjd-rich-editor .rich-editor-popup-container{position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none;z-index:1005;overflow:visible;max-height:90%;overflow-y:auto}.yjd-rich-editor .capitalization-select-popup button,.yjd-rich-editor .color-picker-popup button,.yjd-rich-editor .custom-color-input,.yjd-rich-editor .custom-select-popup button,.yjd-rich-editor .custom-tag,.yjd-rich-editor .emoji-picker-popup button,.yjd-rich-editor .font-family-select-popup button,.yjd-rich-editor .heading-select-popup button,.yjd-rich-editor .image-input-hidden,.yjd-rich-editor .image-popup button,.yjd-rich-editor .image-popup input,.yjd-rich-editor .image-popup select,.yjd-rich-editor .import-csv-input,.yjd-rich-editor .import-file-input,.yjd-rich-editor .import-html-input,.yjd-rich-editor .import-input,.yjd-rich-editor .import-json-input,.yjd-rich-editor .import-markdown-input,.yjd-rich-editor .import-popup button,.yjd-rich-editor .import-popup input,.yjd-rich-editor .import-popup select,.yjd-rich-editor .import-text-input,.yjd-rich-editor .import-toml-input,.yjd-rich-editor .import-type-select,.yjd-rich-editor .import-url-input,.yjd-rich-editor .import-xml-input,.yjd-rich-editor .import-yaml-input,.yjd-rich-editor .line-height-select-popup button,.yjd-rich-editor .link-popup button,.yjd-rich-editor .link-popup input,.yjd-rich-editor .link-popup select,.yjd-rich-editor .list-button,.yjd-rich-editor .list-picker-popup button,.yjd-rich-editor .table-popup button,.yjd-rich-editor .table-popup input,.yjd-rich-editor .table-toolbar-btn,.yjd-rich-editor .tag-popup button,.yjd-rich-editor .tag-popup input,.yjd-rich-editor .tag-popup select,.yjd-rich-editor .tag-type-select,.yjd-rich-editor .tag-value-input,.yjd-rich-editor .text-align-picker-popup button,.yjd-rich-editor .text-size-select-popup button,.yjd-rich-editor .video-input-hidden,.yjd-rich-editor .video-popup button,.yjd-rich-editor .video-popup input,.yjd-rich-editor .video-popup select,.yjd-rich-editor .yjd-button-cancel,.yjd-rich-editor .yjd-button-confirm,.yjd-rich-editor .yjd-custom-upload-button,.yjd-rich-editor .yjd-input,.yjd-rich-editor .yjd-select-input,.yjd-rich-editor .yjd-suggestion-button{pointer-events:auto!important}.yjd-rich-editor .rich-editor-popup-container>*{pointer-events:auto}.yjd-rich-editor .rich-editor-popup-container .color-picker-popup,.yjd-rich-editor .rich-editor-popup-container .custom-select-popup,.yjd-rich-editor .rich-editor-popup-container .emoji-picker-popup,.yjd-rich-editor .rich-editor-popup-container .image-popup,.yjd-rich-editor .rich-editor-popup-container .import-popup,.yjd-rich-editor .rich-editor-popup-container .link-popup,.yjd-rich-editor .rich-editor-popup-container .list-picker-popup,.yjd-rich-editor .rich-editor-popup-container .table-popup,.yjd-rich-editor .rich-editor-popup-container .tag-popup,.yjd-rich-editor .rich-editor-popup-container .text-align-picker-popup,.yjd-rich-editor .rich-editor-popup-container .video-popup{position:absolute!important;z-index:1001!important}.yjd-rich-editor{--rte-bg:#ffffff;--rte-chrome:#fbfbfd;--rte-chrome-2:#f2f2f7;--rte-border:#e9e9f1;--rte-border-strong:#dadae6;--rte-ink:#20242f;--rte-muted:#767c8e;--rte-accent:#6d5efc;--rte-accent-ink:#5a48ee;--rte-accent-weak:#efedff;--rte-accent-ring:rgba(109, 94, 252, 0.28);--rte-danger:#e5484d;--rte-radius:14px;--rte-radius-md:11px;--rte-radius-sm:8px;--rte-shadow-sm:0 1px 2px rgba(20, 24, 46, 0.06);--rte-shadow:0 12px 32px -8px rgba(20, 24, 46, 0.20), 0 4px 10px -4px rgba(20, 24, 46, 0.10);--rte-t:140ms cubic-bezier(0.4, 0, 0.2, 1);border:1px solid var(--rte-border)!important;border-radius:var(--rte-radius)!important;background:var(--rte-bg);color:var(--rte-ink);box-shadow:var(--rte-shadow-sm);font-family:system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif}.yjd-rich-editor .rich-editor-popup-container button,.yjd-rich-editor .rich-editor-popup-container input,.yjd-rich-editor .rich-editor-popup-container select,.yjd-rich-editor .rich-editor-popup-container textarea,.yjd-rich-editor .toolbar-container button,.yjd-rich-editor .toolbar-container input,.yjd-rich-editor .toolbar-container select,.yjd-rich-editor .toolbar-container textarea{font-family:system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif!important}.yjd-rich-editor .rich-editor-toolbar-container{background:var(--rte-chrome);border-bottom:1px solid var(--rte-border)}.yjd-rich-editor .rich-editor-toolbar-1,.yjd-rich-editor .rich-editor-toolbar-2{display:flex;align-items:center;column-gap:0;row-gap:4px;padding:8px 12px}.yjd-rich-editor .rich-editor-toolbar-2{justify-content:flex-start}.yjd-rich-editor .rich-editor-toolbar-2.visible{border-top:1px solid var(--rte-border)}.yjd-rich-editor .toolbar-group{display:flex;align-items:center;gap:2px;border-right:none;margin:0;padding:0}.yjd-rich-editor .toolbar-group+.toolbar-group{margin-left:12px}.yjd-rich-editor .rich-editor-toolbar-btn{color:var(--rte-ink)}.yjd-rich-editor .custom-select-button,.yjd-rich-editor .rich-editor-toolbar-btn{display:inline-flex;align-items:center;justify-content:center;gap:6px;min-width:32px;height:32px;padding:0 8px;border:1px solid transparent;border-radius:var(--rte-radius-sm);background:0 0;cursor:pointer;transition:background var(--rte-t),color var(--rte-t),box-shadow var(--rte-t),border-color var(--rte-t)}.yjd-rich-editor .rich-editor-toolbar-btn:hover{background:var(--rte-chrome-2)}.yjd-rich-editor .custom-select-button:hover{background:var(--rte-chrome-2);color:var(--rte-ink)}.yjd-rich-editor .rich-editor-toolbar-btn.active{background:var(--rte-accent-weak);border-color:transparent}.yjd-rich-editor .rich-editor-toolbar-btn:disabled,.yjd-rich-editor .rich-editor-toolbar-btn[disabled]{opacity:.38!important;cursor:not-allowed!important}.yjd-rich-editor .custom-select-button:focus-visible,.yjd-rich-editor .rich-editor-toolbar-btn:focus-visible{outline:0;border-color:var(--rte-accent);box-shadow:0 0 0 3px var(--rte-accent-ring)}.yjd-rich-editor .rich-editor-statusbar{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:7px 14px;background:var(--rte-chrome);border-top:1px solid var(--rte-border)}.yjd-rich-editor .rich-editor-breadcrumb,.yjd-rich-editor .wordcount{color:var(--rte-muted);font-size:12px;letter-spacing:.01em}.yjd-rich-editor .rich-editor-area{color:var(--rte-ink);font-size:16px;line-height:1.75;padding:22px 24px}.yjd-rich-editor .rich-editor-area[data-placeholder].placeholder-visible:before{color:var(--rte-muted);opacity:.55}.yjd-rich-editor .rich-editor-area blockquote{border-left:3px solid var(--rte-accent);background:var(--rte-accent-weak);border-radius:0 var(--rte-radius-sm) var(--rte-radius-sm)0;padding:8px 16px;color:var(--rte-ink);margin:12px 0}.yjd-rich-editor .rich-editor-area pre code{background:0 0;color:inherit;padding:0}.yjd-rich-editor .capitalization-select-popup,.yjd-rich-editor .color-picker-popup,.yjd-rich-editor .custom-select-popup,.yjd-rich-editor .emoji-picker-popup,.yjd-rich-editor .font-family-select-popup,.yjd-rich-editor .heading-select-popup,.yjd-rich-editor .image-popup,.yjd-rich-editor .import-popup,.yjd-rich-editor .line-height-select-popup,.yjd-rich-editor .link-popup,.yjd-rich-editor .table-popup,.yjd-rich-editor .tag-popup,.yjd-rich-editor .text-align-picker-popup,.yjd-rich-editor .text-size-select-popup,.yjd-rich-editor .video-popup{background:var(--rte-bg);border:1px solid var(--rte-border);box-shadow:var(--rte-shadow)}.yjd-rich-editor .custom-select-item-button{color:var(--rte-ink);transition:background var(--rte-t),color var(--rte-t)}.yjd-rich-editor .custom-select-item-button:hover{background:var(--rte-chrome-2)}.yjd-rich-editor .custom-select-item-button.current .item-checkmark{color:var(--rte-accent-ink)}.yjd-rich-editor .yjd-input{transition:border-color var(--rte-t),box-shadow var(--rte-t)}.yjd-rich-editor .yjd-input:focus{outline:0}.yjd-rich-editor .yjd-input-title{color:var(--rte-ink);font-weight:600}.yjd-rich-editor .yjd-input-label{color:var(--rte-muted)}.yjd-rich-editor .yjd-button-confirm{border:0}.yjd-rich-editor .yjd-button-cancel{background:var(--rte-chrome-2)}.yjd-rich-editor .yjd-button-cancel:hover{background:#e9e9f2}.yjd-rich-editor .yjd-custom-upload-button{border-radius:var(--rte-radius-sm);border:1px dashed var(--rte-border-strong);color:var(--rte-accent-ink);background:var(--rte-accent-weak);transition:background var(--rte-t),border-color var(--rte-t)}.yjd-rich-editor .yjd-custom-upload-button:hover{border-color:var(--rte-accent)}.yjd-rich-editor .block-toolbar-container,.yjd-rich-editor .table-toolbar-container{background:var(--rte-bg);border:1px solid var(--rte-border);border-radius:var(--rte-radius-md);box-shadow:var(--rte-shadow);padding:4px;gap:2px}.yjd-rich-editor .block-toolbar-btn,.yjd-rich-editor .table-toolbar-btn{border:1px solid transparent;border-radius:var(--rte-radius-sm);background:0 0;color:var(--rte-ink);transition:background var(--rte-t),color var(--rte-t)}.yjd-rich-editor .block-toolbar-btn:hover,.yjd-rich-editor .table-toolbar-btn:hover{background:var(--rte-chrome-2)}.yjd-rich-editor .block-toolbar-btn.active{background:var(--rte-accent-weak);color:var(--rte-accent-ink)}.yjd-rich-editor .block-toolbar-btn.active .icon svg,.yjd-rich-editor .block-toolbar-btn.active .icon svg path{fill:var(--rte-accent-ink)}.yjd-rich-editor .rich-editor-table td{border:1px solid var(--rte-border-strong)!important}.yjd-rich-editor .rich-editor-table td:focus{outline:0;box-shadow:inset 0 0 0 2px var(--rte-accent);background:var(--rte-accent-weak)}.yjd-rich-editor .table-grid-cell.highlighted{background:var(--rte-accent);border-color:var(--rte-accent)}.yjd-rich-editor .resize-handle{background:var(--rte-accent)!important;border:2px solid #fff!important;border-radius:50%!important;box-shadow:var(--rte-shadow-sm)!important}.yjd-rich-editor .yjd-find-replace{position:absolute;top:10px;right:10px;z-index:1100;display:none;flex-direction:column;gap:8px;padding:10px;background:var(--rte-bg);border:1px solid var(--rte-border);border-radius:var(--rte-radius-md);box-shadow:var(--rte-shadow);font:13px/1.4 system-ui,-apple-system,sans-serif;max-width:calc(100% - 20px)}.yjd-rich-editor .yjd-find-replace.open{display:flex}.yjd-rich-editor .yjd-find-row{display:flex;align-items:center;gap:6px}.yjd-rich-editor .yjd-find-input{flex:1 1 auto;min-width:150px;transition:border-color var(--rte-t),box-shadow var(--rte-t)}.yjd-rich-editor .yjd-find-input:focus{outline:0}.yjd-rich-editor .yjd-find-count{min-width:46px;text-align:center;color:var(--rte-muted);font-variant-numeric:tabular-nums}.yjd-rich-editor .yjd-find-btn{border:1px solid var(--rte-border);background:var(--rte-chrome);color:var(--rte-ink);cursor:pointer}.yjd-rich-editor .yjd-find-btn:hover{background:var(--rte-chrome-2)}.yjd-rich-editor .yjd-find-btn:focus-visible{outline:0;border-color:var(--rte-accent);box-shadow:0 0 0 3px var(--rte-accent-ring)}.yjd-rich-editor .yjd-find-icon{width:30px;padding:0;font-size:15px;line-height:1}.yjd-rich-editor .yjd-find-toggle.active{background:var(--rte-accent-weak);color:var(--rte-accent-ink);border-color:transparent}.yjd-rich-editor .yjd-find-replace .yjd-find-btn.yjd-find-close:hover{background:#fdecec;color:var(--rte-danger);border-color:#f6caca}.yjd-rich-editor .yjd-find-replace-input{flex:1 1 auto}.yjd-rich-editor .yjd-find-row .yjd-find-btn:not(.yjd-find-icon){flex:0 0 auto}.yjd-rich-editor mark.yjd-find-hit{background:#fff1b8;color:inherit;border-radius:3px}.yjd-rich-editor mark.yjd-find-hit.active{background:var(--rte-accent);color:#fff}@media (prefers-reduced-motion:reduce){.yjd-rich-editor *{transition-duration:.01ms!important;animation-duration:.01ms!important}}.yjd-rich-editor .block-toolbar-btn svg [fill="#454545"],.yjd-rich-editor .icon svg [fill="#010101"],.yjd-rich-editor .icon svg [fill="#231F20"],.yjd-rich-editor .icon svg [fill="#454545"],.yjd-rich-editor .icon svg[fill="#454545"],.yjd-rich-editor .table-toolbar-btn svg [fill="#454545"]{fill:currentColor}.yjd-rich-editor .block-toolbar-btn .icon,.yjd-rich-editor .rich-editor-toolbar-btn .icon,.yjd-rich-editor .table-toolbar-btn .icon{display:inline-flex;align-items:center;justify-content:center;width:18px;height:18px;color:inherit}.yjd-rich-editor .block-toolbar-btn .icon svg,.yjd-rich-editor .rich-editor-toolbar-btn .icon svg,.yjd-rich-editor .table-toolbar-btn .icon svg{width:auto!important;height:16px!important;max-width:18px;display:block}.yjd-rich-editor .rich-editor-toolbar-btn .icon svg,.yjd-rich-editor .rich-editor-toolbar-btn .icon svg path{fill:currentColor}.yjd-rich-editor .rich-editor-toolbar-btn{color:#4b5060}.yjd-rich-editor .rich-editor-toolbar-btn:hover{color:var(--rte-ink)}.yjd-rich-editor .rich-editor-toolbar-btn.active,.yjd-rich-editor .rich-editor-toolbar-btn.active .icon svg [fill]{color:var(--rte-accent-ink)!important;fill:var(--rte-accent-ink)!important}.yjd-rich-editor .rich-editor-toolbar-btn.active .icon svg,.yjd-rich-editor .rich-editor-toolbar-btn.active .icon svg path{fill:var(--rte-accent-ink)!important}.yjd-rich-editor .custom-select-button,.yjd-rich-editor .rich-editor-toolbar-btn{box-shadow:none}.yjd-rich-editor .custom-select-button{border-color:var(--rte-border);background:var(--rte-bg);color:var(--rte-ink);font-weight:500}.yjd-rich-editor .custom-select-button:hover{border-color:var(--rte-border-strong);background:var(--rte-bg)}.yjd-rich-editor .dropdown-icon{color:var(--rte-muted)}.yjd-rich-editor .capitalization-select-popup,.yjd-rich-editor .color-picker-popup,.yjd-rich-editor .custom-select-popup,.yjd-rich-editor .font-family-select-popup,.yjd-rich-editor .heading-select-popup,.yjd-rich-editor .image-popup,.yjd-rich-editor .import-popup,.yjd-rich-editor .line-height-select-popup,.yjd-rich-editor .link-popup,.yjd-rich-editor .table-popup,.yjd-rich-editor .tag-popup,.yjd-rich-editor .text-size-select-popup,.yjd-rich-editor .video-popup{border-color:var(--rte-border);border-radius:var(--rte-radius-md);box-shadow:0 10px 30px -10px rgba(20,24,46,.18),0 2px 6px -2px rgba(20,24,46,.08)}.yjd-rich-editor .emoji-picker-popup,.yjd-rich-editor .text-align-picker-popup{border-color:var(--rte-border);box-shadow:0 10px 30px -10px rgba(20,24,46,.18),0 2px 6px -2px rgba(20,24,46,.08)}.yjd-rich-editor .emoji-picker-popup{border-radius:var(--rte-radius-md)}.yjd-rich-editor .capitalization-select-popup,.yjd-rich-editor .custom-select-popup,.yjd-rich-editor .font-family-select-popup,.yjd-rich-editor .heading-select-popup,.yjd-rich-editor .line-height-select-popup,.yjd-rich-editor .text-size-select-popup{padding:6px}.yjd-rich-editor .capitalization-select-popup.visible,.yjd-rich-editor .color-picker-popup.visible,.yjd-rich-editor .custom-select-popup.visible,.yjd-rich-editor .font-family-select-popup.visible,.yjd-rich-editor .heading-select-popup.visible,.yjd-rich-editor .image-popup.visible,.yjd-rich-editor .line-height-select-popup.visible,.yjd-rich-editor .link-popup.visible,.yjd-rich-editor .table-popup.visible,.yjd-rich-editor .tag-popup.visible,.yjd-rich-editor .text-align-picker-popup.visible,.yjd-rich-editor .text-size-select-popup.visible,.yjd-rich-editor .video-popup.visible,.yjd-rich-editor .yjd-find-replace.open{animation:rte-pop-in 90ms ease-out}.yjd-rich-editor .yjd-input{height:36px;border:1px solid var(--rte-border);border-radius:var(--rte-radius-sm);background:var(--rte-bg);color:var(--rte-ink)}.yjd-rich-editor .yjd-select-input{height:36px;background:var(--rte-bg);font-size:14px}.yjd-rich-editor .yjd-find-input{height:36px;border:1px solid var(--rte-border);border-radius:var(--rte-radius-sm);background:var(--rte-bg);color:var(--rte-ink)}.yjd-rich-editor .yjd-find-input::placeholder,.yjd-rich-editor .yjd-input::placeholder,.yjd-rich-editor .yjd-select-input::placeholder{color:var(--rte-muted);opacity:.7}.yjd-rich-editor .yjd-find-input:focus,.yjd-rich-editor .yjd-input:focus{border-color:var(--rte-accent);box-shadow:0 0 0 3px var(--rte-accent-ring)}.yjd-rich-editor .yjd-button-cancel,.yjd-rich-editor .yjd-button-confirm,.yjd-rich-editor .yjd-find-btn{height:36px;padding:0 16px;font-size:14px;font-weight:500;border-radius:var(--rte-radius-sm);box-shadow:none;transition:background var(--rte-t),color var(--rte-t),border-color var(--rte-t)}.yjd-rich-editor .yjd-button-confirm{background:var(--rte-accent);border:1px solid var(--rte-accent);color:#fff}.yjd-rich-editor .yjd-button-confirm:hover{background:var(--rte-accent-ink);border-color:var(--rte-accent-ink)}.yjd-rich-editor .yjd-button-cancel{background:0 0;border:1px solid var(--rte-border);color:var(--rte-muted)}.yjd-rich-editor .yjd-button-cancel:hover{background:var(--rte-chrome-2);color:var(--rte-ink)}.yjd-rich-editor .yjd-find-btn:not(.yjd-find-icon){background:0 0;border:1px solid var(--rte-border);color:var(--rte-ink)}.yjd-rich-editor .yjd-find-btn:not(.yjd-find-icon):hover{background:var(--rte-chrome-2)}.yjd-rich-editor .yjd-find-btn.yjd-find-icon{height:32px;width:32px;color:var(--rte-muted);background:0 0;border:1px solid transparent}.yjd-rich-editor .yjd-find-btn.yjd-find-icon:hover{background:var(--rte-chrome-2);color:var(--rte-ink)}@media (prefers-reduced-motion:reduce){.yjd-rich-editor .color-picker-popup.visible,.yjd-rich-editor .yjd-find-replace.open,.yjd-rich-editor [class$=-popup].visible,.yjd-rich-editor [class*=select-popup].visible{animation:none!important}}.yjd-rich-editor .icon svg{display:block;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;overflow:visible}.yjd-rich-editor .icon svg line,.yjd-rich-editor .icon svg path,.yjd-rich-editor .icon svg polyline,.yjd-rich-editor .icon svg rect{fill:none!important;stroke:currentColor}.yjd-rich-editor .icon svg [fill=currentColor],.yjd-rich-editor .list-button svg [fill=currentColor],.yjd-rich-editor .table-toolbar-btn svg [fill=currentColor]{fill:currentColor!important;stroke:none!important}.yjd-rich-editor .rich-editor-toolbar-btn .icon svg{color:#565b6b}.yjd-rich-editor .rich-editor-toolbar-btn:hover .icon svg{color:var(--rte-ink)}.yjd-rich-editor .rich-editor-toolbar-btn.active .icon svg,.yjd-rich-editor .rich-editor-toolbar-btn.active .icon svg line,.yjd-rich-editor .rich-editor-toolbar-btn.active .icon svg path,.yjd-rich-editor .rich-editor-toolbar-btn.active .icon svg polyline,.yjd-rich-editor .rich-editor-toolbar-btn.active .icon svg rect{color:var(--rte-accent-ink)!important;stroke:var(--rte-accent-ink)!important;fill:none!important}.yjd-rich-editor .rich-editor-toolbar-btn.active .icon svg [fill=currentColor]{fill:var(--rte-accent-ink)!important;stroke:none!important}.yjd-rich-editor .block-toolbar-btn.active .icon svg,.yjd-rich-editor .block-toolbar-btn.active .icon svg path{stroke:var(--rte-accent-ink)!important;fill:none!important}.yjd-rich-editor .list-picker-popup{background:var(--rte-bg);border:1px solid var(--rte-border);border-radius:var(--rte-radius-md);box-shadow:var(--rte-shadow);padding:6px}.yjd-rich-editor .list-picker-popup.visible{animation:rte-pop-in 90ms ease-out}.yjd-rich-editor .list-button-container{display:flex;align-items:center;gap:2px}.yjd-rich-editor .list-button{display:inline-flex;align-items:center;justify-content:center;width:34px;height:32px;padding:0;border:1px solid transparent;border-radius:var(--rte-radius-sm);background:0 0;color:#565b6b;cursor:pointer;transition:background var(--rte-t),color var(--rte-t)}.yjd-rich-editor .list-button:hover{background:var(--rte-chrome-2);color:var(--rte-ink)}.yjd-rich-editor .list-button.active{background:var(--rte-accent-weak);color:var(--rte-accent-ink)}.yjd-rich-editor .icon svg,.yjd-rich-editor .list-button svg,.yjd-rich-editor .table-toolbar-btn svg{width:auto!important;height:16px!important;max-width:20px;fill:none!important}.yjd-rich-editor .list-button svg{stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}.yjd-rich-editor .table-toolbar-btn svg{display:block}.yjd-rich-editor .table-toolbar-btn{color:#565b6b}.yjd-rich-editor .table-toolbar-btn:hover{color:var(--rte-ink)}.yjd-rich-editor .align-button{border-radius:var(--rte-radius-sm);background:0 0;color:var(--rte-ink);transition:background var(--rte-t),color var(--rte-t)}.yjd-rich-editor .align-button:hover{background:var(--rte-chrome-2);border-color:transparent}.yjd-rich-editor .align-button.active{background:var(--rte-accent-weak);color:var(--rte-accent-ink);border-color:transparent}.yjd-rich-editor .align-button svg,.yjd-rich-editor .table-toolbar-btn svg,.yjd-slash-icon svg{stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}.yjd-rich-editor .align-button svg{width:auto!important;height:16px!important;color:inherit;fill:none!important}.yjd-rich-editor .align-button.active svg{color:var(--rte-accent-ink)}.yjd-rich-editor .yjd-custom-upload-button svg{width:17px;height:17px;fill:none;stroke:var(--rte-accent-ink)}.yjd-rich-editor .text-align-picker-popup{min-width:168px}.yjd-rich-editor .align-button,.yjd-rich-editor .align-button .label-text{white-space:nowrap}.yjd-rich-editor .rich-editor-toolbar-1{flex-wrap:nowrap!important;overflow:hidden}.yjd-rich-editor .rich-editor-toolbar-2{border-top:1px solid var(--rte-border)}.yjd-rich-editor .custom-select-button,.yjd-rich-editor .rich-editor-toolbar-btn,.yjd-rich-editor .toolbar-group{flex:0 0 auto}.yjd-rich-editor .block-toolbar-arrow,.yjd-rich-editor .table-toolbar-arrow{display:none!important}.yjd-slash-menu{position:absolute;z-index:2000;min-width:264px;max-width:320px;max-height:320px;overflow-y:auto;padding:6px;background:#fff;border:1px solid #e9e9f1;border-radius:12px;box-shadow:0 12px 32px -8px rgba(20,24,46,.2),0 4px 10px -4px rgba(20,24,46,.1);font:14px/1.4 system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;animation:yjd-slash-in 90ms ease-out}.yjd-slash-item{display:flex;align-items:center;gap:10px;width:100%;padding:8px 10px;border:0;background:0 0;border-radius:8px;cursor:pointer;text-align:left;color:#20242f}.yjd-slash-item.active,.yjd-slash-item:hover{background:#efedff;color:#5a48ee}.yjd-slash-icon{display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;flex:0 0 auto;border-radius:7px;background:#f2f2f7;color:inherit}.yjd-slash-item.active .yjd-slash-icon{background:#fff}.yjd-slash-icon svg{width:auto;height:16px;fill:none}.yjd-slash-icon svg [fill=currentColor]{fill:currentColor;stroke:none}.yjd-slash-text{display:flex;flex-direction:column;line-height:1.25;min-width:0}.yjd-slash-label{font-weight:500}.yjd-slash-hint{font-size:12px;color:#767c8e}.yjd-slash-item.active .yjd-slash-hint{color:#8b7ff0}@media (prefers-reduced-motion:reduce){.yjd-slash-menu{animation:none}}.yjd-rich-editor .rich-editor-toolbar-btn.background-btn,.yjd-rich-editor .rich-editor-toolbar-btn.color-btn{position:relative}.yjd-rich-editor .rich-editor-toolbar-btn .rte-swatch{position:absolute;left:50%;bottom:5px;transform:translateX(-50%);width:16px;height:3px;border-radius:2px;background:var(--rte-ink, #20242f);pointer-events:none;box-shadow:0 0 0 1px rgba(0,0,0,.06)}.yjd-rich-editor .rich-editor-toolbar-btn.background-btn .rte-swatch{background:0 0;box-shadow:inset 0 0 0 1px var(--rte-border, #e9e9f1)}.yjd-rich-editor .rich-editor-toolbar-btn.background-btn.has-color .rte-swatch{box-shadow:0 0 0 1px rgba(0,0,0,.06)}.yjd-rich-editor .rich-editor-toolbar-btn.background-btn .icon,.yjd-rich-editor .rich-editor-toolbar-btn.color-btn .icon{transform:translateY(-1px)}.yjd-rich-editor .link-popup.link-popup--inline{width:auto;min-width:320px;max-width:min(92vw,420px);padding:10px}.yjd-rich-editor .link-popup--inline .link-popup-content{display:flex;flex-direction:column;gap:8px}.yjd-rich-editor .link-popup--inline .link-popup-row{display:flex;align-items:center;gap:8px}.yjd-rich-editor .link-popup--inline .link-popup-row .yjd-input{flex:1;min-width:0;margin:0}.yjd-rich-editor .link-popup--inline .link-popup-apply{flex:0 0 auto;white-space:nowrap;padding:8px 16px;margin:0}.yjd-rich-editor .custom-select-item-button{min-height:34px;padding:6px 10px!important;gap:10px;border-radius:var(--rte-radius-sm)!important}.yjd-rich-editor .custom-select-item-button.current,.yjd-rich-editor .custom-select-item-button:hover{background:var(--rte-accent-weak)!important;color:var(--rte-accent-ink)!important}.yjd-rich-editor .custom-select-item-button.current{font-weight:600}.yjd-rich-editor .font-family-select-popup .custom-select-item-button,.yjd-rich-editor .heading-select-popup .custom-select-item-button,.yjd-rich-editor .text-size-select-popup .custom-select-item-button{line-height:1.15}.yjd-rich-editor .import-type-select,.yjd-rich-editor .tag-type-select,.yjd-rich-editor .yjd-select-input,.yjd-rich-editor select{-webkit-appearance:none;-moz-appearance:none;appearance:none;width:100%;box-sizing:border-box;padding:10px 36px 10px 12px;font:500 14px/1.4 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;color:var(--rte-ink);background-color:var(--rte-bg);background-image:url("data:image/svg+xml,%3Csvg%20xmlns=\'http://www.w3.org/2000/svg\'%20width=\'16\'%20height=\'16\'%20viewBox=\'0%200%2024%2024\'%20fill=\'none\'%20stroke=\'%23767c8e\'%20stroke-width=\'2\'%20stroke-linecap=\'round\'%20stroke-linejoin=\'round\'%3E%3Cpath%20d=\'m6%209%206%206%206-6\'/%3E%3C/svg%3E");background-repeat:no-repeat;background-position:right 12px center;background-size:16px;border:1px solid var(--rte-border-strong);border-radius:var(--rte-radius-sm);cursor:pointer;transition:border-color var(--rte-t),box-shadow var(--rte-t)}.yjd-rich-editor .import-type-select:hover,.yjd-rich-editor .tag-type-select:hover,.yjd-rich-editor .yjd-select-input:hover,.yjd-rich-editor select:hover{border-color:var(--rte-accent)}.yjd-rich-editor .import-type-select:focus,.yjd-rich-editor .tag-type-select:focus,.yjd-rich-editor .yjd-select-input:focus,.yjd-rich-editor select:focus{outline:0;border-color:var(--rte-accent);box-shadow:0 0 0 3px var(--rte-accent-ring)}.yjd-rich-editor .yjd-find-input,.yjd-rich-editor .yjd-input{box-sizing:border-box;padding:10px 12px;font-size:14px;line-height:1.4}.yjd-rich-editor .table-grid-cell:hover{background:var(--rte-accent-weak)!important;border-color:var(--rte-accent)!important}.yjd-rich-editor .rich-editor-toolbar-1{justify-content:flex-start!important}.yjd-rich-editor .rich-editor-toolbar-1 .more-btn{margin-left:auto!important}@media (max-width:640px){.yjd-rich-editor .rich-editor-toolbar-1{flex-wrap:nowrap!important;overflow-x:auto!important;overflow-y:hidden;-webkit-overflow-scrolling:touch;scrollbar-width:none;justify-content:flex-start!important;padding:6px 8px;scroll-padding:8px}.yjd-rich-editor .rich-editor-toolbar-1::-webkit-scrollbar{display:none}.yjd-rich-editor .rich-editor-toolbar-1 .more-btn,.yjd-rich-editor .rich-editor-toolbar-2{display:none!important}.yjd-rich-editor .toolbar-group{flex:0 0 auto}.yjd-rich-editor .toolbar-group+.toolbar-group{margin-left:8px}.yjd-rich-editor .custom-select-button,.yjd-rich-editor .rich-editor-toolbar-btn{min-width:32px;height:32px;padding:0 8px;flex:0 0 auto}.yjd-rich-editor .custom-select-button{max-width:none}}.yjd-rich-editor .rich-editor-toolbar-btn.rte-hidden{display:none!important}.yjd-rich-editor .rich-editor-area>:first-child{margin-top:0!important}.yjd-rich-editor .rich-editor-area>:last-child{margin-bottom:0!important}.yjd-rich-editor .align-button-container{flex-direction:row!important;width:auto!important;height:auto!important;gap:4px}.yjd-rich-editor .align-button{width:34px!important;min-height:34px!important;height:34px!important;padding:0!important;gap:0!important;justify-content:center!important}.yjd-rich-editor .text-align-picker-popup{width:auto!important}.yjd-rich-editor .rich-editor-toolbar-2{flex-wrap:nowrap!important;overflow-x:auto;overflow-y:hidden;-webkit-overflow-scrolling:touch;scrollbar-width:none}.yjd-rich-editor .rich-editor-toolbar-2::-webkit-scrollbar{display:none}.yjd-rich-editor .rich-editor-toolbar-2 .toolbar-group{flex:0 0 auto}.yjd-rich-editor .custom-select-header{padding:8px 12px 6px;font-size:11px;font-weight:600;letter-spacing:.05em;text-transform:uppercase;color:var(--rte-muted);border-bottom:1px solid var(--rte-border);margin-bottom:4px;white-space:nowrap}.yjd-rich-editor .custom-select-button .select-lead-icon{width:16px;height:16px;display:inline-flex;align-items:center;justify-content:center;color:var(--rte-muted);margin-right:4px}.yjd-rich-editor .custom-select-button .select-lead-icon svg{width:16px;height:16px;display:block;stroke:currentColor;fill:none}.yjd-rich-editor .custom-select-button{white-space:nowrap;overflow:hidden}.yjd-rich-editor .custom-select-button .button-text{flex:1 1 auto;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.yjd-rich-editor .custom-select-button .dropdown-icon,.yjd-rich-editor .custom-select-button .select-lead-icon{flex:0 0 auto}.yjd-rich-editor .text-align-picker-popup{padding:6px!important;border-radius:var(--rte-radius-md)!important}.yjd-rich-editor .align-button-container{padding:0!important}.yjd-rich-editor .rich-editor-breadcrumb,.yjd-rich-editor .wordcount{color:#5b6373}.yjd-rich-editor .yjd-find-btn{display:inline-flex;align-items:center;justify-content:center}.yjd-rich-editor .yjd-find-icon .icon,.yjd-rich-editor .yjd-find-icon .icon svg{width:16px;height:16px;display:block}.yjd-mention-ico svg,.yjd-rich-editor .yjd-find-icon .icon svg{stroke:currentColor;fill:none}.mention{display:inline;padding:0 2px;border-radius:4px;background:#efedff;color:#5a48ee;font-weight:500;text-decoration:none;white-space:nowrap}.mention[data-trigger="#"]{background:#e8f3ff;color:#1f6feb}.yjd-mention-menu{position:absolute;z-index:2000;min-width:220px;max-width:320px;max-height:280px;overflow-y:auto;padding:6px;background:var(--rte-bg, #ffffff);border:1px solid var(--rte-border, #e9e9f1);border-radius:var(--rte-radius-md, 12px);box-shadow:var(--rte-shadow, 0 12px 32px -8px rgba(20, 24, 46, 0.20), 0 4px 10px -4px rgba(20, 24, 46, 0.10));font:14px/1.4 system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;animation:yjd-slash-in 90ms ease-out}.yjd-mention-item{display:flex;align-items:center;gap:10px;width:100%;padding:7px 10px;border:0;background:0 0;border-radius:8px;cursor:pointer;text-align:left;color:var(--rte-ink, #20242f)}.yjd-mention-item.active,.yjd-mention-item:hover{background:var(--rte-accent-weak, #efedff);color:var(--rte-accent-ink, #5a48ee)}.yjd-mention-avatar,.yjd-mention-ico{width:26px;height:26px;flex:0 0 auto;border-radius:50%}.yjd-mention-avatar{object-fit:cover;background:#f2f2f7}.yjd-mention-ico{display:inline-flex;align-items:center;justify-content:center;background:var(--rte-accent-weak, #efedff);color:var(--rte-accent-ink, #5a48ee)}.yjd-mention-ico svg{width:16px;height:16px}.yjd-mention-name{font-weight:500;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}@media (prefers-reduced-motion:reduce){.yjd-mention-menu{animation:none}}.yjd-content{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;font-size:16px;line-height:1.6;color:#20242f;word-wrap:break-word}.yjd-content>:first-child{margin-top:0}.yjd-content>:last-child{margin-bottom:0}.yjd-content li{margin:.25em 0}.yjd-content a{color:#2563eb;text-decoration:underline}.yjd-content code,.yjd-content pre{font-family:Consolas,Menlo,Monaco,"Courier New",monospace;background:#f1f2f3;padding:2px 6px;border-radius:4px}.yjd-content pre{padding:12px 14px;border-radius:6px;margin:1em 0;overflow-x:auto;white-space:pre}.yjd-content pre code{background:0 0;padding:0}.yjd-content img{max-width:100%;height:auto;border-radius:4px}.yjd-content hr{border:0;border-top:1px solid #d1d5db;margin:1.5em 0}.yjd-content table{border-collapse:collapse;width:100%;margin:1em 0}.yjd-content table td,.yjd-content table th{border:1px solid #d1d5db;padding:8px 10px;text-align:left}.yjd-file-chip{display:inline-flex;align-items:center;gap:7px;max-width:100%;vertical-align:baseline;padding:3px 10px 3px 8px;margin:0 1px;border:1px solid #e0e0ec;border-radius:8px;background:#f7f7fb;color:#20242f;text-decoration:none;font-size:.9em;line-height:1.5;white-space:nowrap}.yjd-file-chip:hover{border-color:#6d5efc;background:#efedff}.yjd-file-chip[data-state=uploading]{opacity:.6}.yjd-file-ico{display:inline-flex;flex:0 0 auto;color:#5a48ee}.yjd-file-ico svg{width:15px;height:15px;stroke:currentColor;fill:none}.yjd-file-name{font-weight:500;overflow:hidden;text-overflow:ellipsis;max-width:22em}.yjd-file-size{color:#767c8e;font-variant-numeric:tabular-nums}.yjd-spinner{display:inline-block;width:15px;height:15px;flex:0 0 auto;border:2px solid var(--rte-accent-weak, #d9d4ff);border-top-color:var(--rte-accent, #6d5efc);border-radius:50%;animation:yjd-spin .7s linear infinite;vertical-align:middle}@media (prefers-reduced-motion:reduce){.yjd-spinner{animation-duration:2s}}.yjd-upload{display:inline-flex;align-items:center;gap:9px;vertical-align:middle;max-width:100%;padding:10px 14px;margin:2px 0;border:1px dashed var(--rte-border-strong, #c9c5ec);border-radius:10px;background:var(--rte-accent-weak, #f3f1ff);color:var(--rte-muted, #5b6373);font-size:.9em;user-select:none}.yjd-upload-label{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:18em}.rich-editor-area.yjd-drag-over{outline:2px dashed var(--rte-accent, #6d5efc);outline-offset:-4px;background:var(--rte-accent-weak, #f6f5ff)}',document.head.appendChild(this.styleElement),this.loaded=!0}catch(t){this.loadFallbackStyles()}return Promise.resolve()}static loadFallbackStyles(){this.styleElement=document.createElement("style"),this.styleElement.id="rich-editor-styles-fallback",this.styleElement.textContent="\n .yjd-rich-editor { \n position: relative; \n background: #fff; \n border: 1px solid #ddd; \n border-radius: 4px; \n display: flex; \n flex-direction: column; \n font-family: system-ui, sans-serif; \n }\n .yjd-rich-editor .rich-editor-area { \n flex: 1; \n padding: 20px; \n outline: none; \n min-height: 100px; \n }\n .yjd-rich-editor .rich-editor-toolbar { \n display: flex; \n gap: 4px; \n padding: 8px; \n border-bottom: 1px solid #ddd; \n background: #f9f9f9; \n }\n .yjd-rich-editor .rich-editor-toolbar-btn { \n padding: 4px 8px; \n border: 1px solid #ccc; \n border-radius: 3px; \n background: #fff; \n cursor: pointer; \n }\n .yjd-rich-editor .table-grid-selector { \n position: absolute; \n background: white; \n border: 1px solid #ccc; \n border-radius: 4px; \n padding: 10px; \n box-shadow: 0 2px 8px rgba(0,0,0,0.15); \n z-index: 1000; \n display: none; \n }\n .yjd-rich-editor .table-grid-cell { \n width: 20px; \n height: 20px; \n border: 1px solid #ddd; \n cursor: pointer; \n background: white; \n }\n ",document.head.appendChild(this.styleElement),this.loaded=!0}static unloadStyles(){this.styleElement&&this.styleElement.parentNode&&(this.styleElement.parentNode.removeChild(this.styleElement),this.styleElement=null,this.loaded=!1)}static isLoaded(){return this.loaded}static async reloadStyles(){this.unloadStyles(),await this.loadStyles()}static addCustomCSS(t,e="rich-editor-custom"){const i=document.getElementById(e);i&&i.remove();const o=document.createElement("style");o.id=e,o.textContent=t,document.head.appendChild(o)}}.loadStyles().catch(t=>{});class Mt extends A{static register(e,i,o=!1){t.register(e,i,o)}static get(e){return t.get(e)}static create(t,e={}){return new Mt(t,e)}static fromTextarea(t,e={}){const i="string"==typeof t?document.querySelector(t):t;if(!i)throw new Error("RichEditor.fromTextarea: textarea not found");const o="markdown"===e.format?"markdown":"html",n=t=>"markdown"===o?t.getMarkdown():t.getContent(),r=(t,e)=>"markdown"===o?t.setMarkdown(e||""):t.setHTML(e||""),s=document.createElement("div");i.after(s),i.style.display="none",i.setAttribute("aria-hidden","true");const a=Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype,"value");let l=i.value||"",c=!1;const d=l,p=new Mt(s,{width:"100%",...e,content:null!=e.content?e.content:"markdown"===o?y(d):d});Object.defineProperty(i,"value",{configurable:!0,get:()=>l,set(t){l=null==t?"":String(t),a.set.call(i,l),c||r(p,l)}});const h=()=>{const t=n(p);l!==t&&(l=t,c=!0,a.set.call(i,t),i.dispatchEvent(new Event("input",{bubbles:!0})),i.dispatchEvent(new Event("change",{bubbles:!0})),c=!1)};p.on("change",h),h(),p.textarea=i,p.getValue=()=>n(p),p.setValue=t=>{r(p,t)};const u=p.destroy.bind(p);return p.destroy=()=>{const t=n(p);p.off("change",h),u(),s.remove(),delete i.value,a.set.call(i,t),i.style.display="",i.removeAttribute("aria-hidden")},p}}var Ot=Object.freeze({__proto__:null,Background:G,BlockFormat:H,BlockToolbar:St,Bold:M,Capitalization:nt,CodeView:Lt,Color:K,ColorPicker:X,Editor:A,Emoji:mt,EmojiPicker:ut,FindReplace:At,FontFamily:it,Format:B,Heading:et,History:It,IconUtils:L,Image:gt,ImagePopup:zt,Import:kt,Indent:dt,IndentDecrease:ht,IndentIncrease:pt,InlineFormat:R,Italic:O,LineHeight:ot,Link:Q,LinkPopup:Y,List:ct,ListPicker:lt,Mention:Rt,Module:e,ResizeHandles:Ht,RichEditor:Mt,SlashMenu:Bt,Strike:_,Subscript:F,Superscript:D,Table:J,TablePopup:Z,TableToolbar:Nt,Tag:wt,TagPopup:xt,TextAlign:st,TextAlignPicker:rt,TextSize:Ct,Toolbar:Tt,Underline:P,Video:bt,VideoPopup:yt,createCustomButton:jt,createEditor:function(t,e={}){return new Mt(t,e)},default:Mt,domToJson:k,htmlToMarkdown:p,jsonToHtml:T,markdownToHtml:y,registry:t,renderStatic:function(t,e){const i=d(t||""),o=e||document.createElement("div");return o.classList.add("yjd-content"),o.innerHTML=i,o},yjd:Mt});for(const[t,e]of Object.entries(Ot))"default"===t||t in Mt||(Mt[t]=e);return Mt}),"undefined"!=typeof window&&(window.RichEditor=window.RichEditor||window.yjd);
2
2
  //# sourceMappingURL=rich-editor.min.js.map