fable-editor 1.2.6 → 1.2.7

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.
@@ -1053,7 +1053,7 @@
1053
1053
  transform: rotate(-90deg);
1054
1054
  }
1055
1055
 
1056
- [dir=rtl] .pop .mi .subarrow svg {
1056
+ .pop[dir=rtl] .mi .subarrow svg {
1057
1057
  transform: rotate(90deg);
1058
1058
  }
1059
1059
 
@@ -1 +1 @@
1
- {"version":3,"file":"editor.d.ts","sourceRoot":"","sources":["../../src/core/editor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,cAAc,EAA6B,MAAM,SAAS,CAAC;AAuIvG,qBAAa,WAAY,YAAW,cAAc;IAC9C,OAAO,CAAC,MAAM,CAAC,eAAe,CAAK;IAEnC,OAAO,CAAC,OAAO,CAYb;IACF,OAAO,CAAC,IAAI,CAAwB;IACpC,OAAO,CAAC,YAAY,CAAoD;IACxE,OAAO,CAAC,cAAc,CAAiC;IAEvD,OAAO,CAAC,KAAK,CAAe;IAC5B,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,EAAE,CAAe;IACzB,OAAO,CAAC,SAAS,CAAe;IAChC,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,QAAQ,CAAoB;IAEpC,OAAO,CAAC,UAAU,CAAsB;IACxC,OAAO,CAAC,SAAS,CAAa;IAC9B,OAAO,CAAC,SAAS,CAAa;IAE9B,OAAO,CAAC,OAAO,CAA4B;IAC3C,OAAO,CAAC,SAAS,CAA4B;IAC7C,OAAO,CAAC,SAAS,CAA4B;IAC7C,OAAO,CAAC,MAAM,CAA4B;IAE1C,OAAO,CAAC,SAAS,CAAiC;IAClD,OAAO,CAAC,SAAS,CAA4B;IAC7C,OAAO,CAAC,UAAU,CAAqB;IACvC,OAAO,CAAC,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 6 11M11 11h0"/></svg>
6
6
  </span>
7
- `,this.sbHelp=this.statusbar.querySelector(".mid"),this.sbWords=this.statusbar.querySelector(".words");const e=this.statusbar.querySelector(".grip");this.bindGrip(e),this.shell.appendChild(this.menubar),this.shell.appendChild(this.toolbar),this.shell.appendChild(this.ed),this.shell.appendChild(this.statusbar),this.contentStyle&&(this.contentStyleEl=document.createElement("style"),this.contentStyleEl.textContent=this.scopeContentStyle(this.contentStyle),this.shell.appendChild(this.contentStyleEl)),t.appendChild(this.shell),Pt(),this.options.statusbar||(this.statusbar.style.display="none"),this.imgInput=document.createElement("input"),this.imgInput.type="file",this.imgInput.accept=this.options.imageFileTypes.join(","),this.imgInput.style.display="none",t.appendChild(this.imgInput),this.vidInput=document.createElement("input"),this.vidInput.type="file",this.vidInput.accept=this.options.videoFileTypes.join(","),this.vidInput.style.display="none",t.appendChild(this.vidInput),this.docInput=document.createElement("input"),this.docInput.type="file",this.docInput.accept=".docx,application/vnd.openxmlformats-officedocument.wordprocessingml.document",this.docInput.style.display="none",t.appendChild(this.docInput)}applyTheme(t){const e=document.documentElement;t.primaryColor&&e.style.setProperty("--fable-primary",t.primaryColor),t.toolbarGroupBackground&&e.style.setProperty("--fable-tgrp-bg",t.toolbarGroupBackground),t.uiFontFamily&&e.style.setProperty("--fable-ui-font",t.uiFontFamily)}scopeContentStyle(t){return t.replace(/\bbody\b/g,"."+this.contentClass)}bindGrip(t){let e=0,i=0;const s=l=>{e=l.clientY,i=this.ed.offsetHeight,l.preventDefault();const o=r=>{this.ed.style.height=Math.max(120,i+r.clientY-e)+"px"},n=()=>{window.removeEventListener("mousemove",o),window.removeEventListener("mouseup",n)};window.addEventListener("mousemove",o),window.addEventListener("mouseup",n)};t.addEventListener("mousedown",s),this.listeners.push(()=>t.removeEventListener("mousedown",s))}bindEvents(){if(this.onDoc("mousedown",t=>{this.openPop&&!this.openPop.contains(t.target)&&!this.popAnchor.contains(t.target)&&!(this.openSubEl&&this.openSubEl.contains(t.target))&&this.closePop()}),this.onDoc("keydown",t=>{t.key==="Escape"&&(this.closePop(),this.closeDlg())}),this.onDoc("selectionchange",()=>{const t=window.getSelection();t&&this.ed.contains(t.anchorNode)?(this.saveSel(),this.refreshState(),this.updateSelToolbar(t),this.positionCellMarker()):this.clearSelToolbar()}),this.on(this.ed,"input",()=>{this.refreshState(),this.onChange(),this.positionTableHandles(),this.positionImageHandles(),this.positionImgPhCtx(),this.positionTplCtx(),this.positionVphCtx(),this.positionVidCtx(),this.positionCodeCtx()}),this.on(this.ed,"keydown",t=>{t.altKey&&t.key==="0"&&(t.preventDefault(),this.helpDlg()),(t.key==="Delete"||t.key==="Backspace")&&this.phActive&&(t.preventDefault(),this.removeImgPlaceholder()),(t.key==="Delete"||t.key==="Backspace")&&this.vphActive&&(t.preventDefault(),this.removeVphPlaceholder()),t.key==="`"&&!t.ctrlKey&&!t.metaKey&&!t.altKey&&this.tryCodeTyping(t),t.key==="Enter"&&!t.shiftKey&&!t.ctrlKey&&!t.metaKey&&!t.altKey&&this.tryExitBlockquote(t)}),this.on(this.ed,"paste",t=>this.handlePaste(t)),this.on(this.ed,"drop",t=>{var l,o,n,r;t.preventDefault();const e=t.target,i=(l=e.closest)==null?void 0:l.call(e,".img-ph:not(.vid-ph)");if(i&&this.ed.contains(i)&&!this.options.readonly){const c=Array.from(((o=t.dataTransfer)==null?void 0:o.files)||[]).find(h=>h.type.startsWith("image/"));c&&this.readImageFileInto(c,i);return}const s=(n=e.closest)==null?void 0:n.call(e,".vid-ph");if(s&&this.ed.contains(s)&&!this.options.readonly){const c=Array.from(((r=t.dataTransfer)==null?void 0:r.files)||[]).find(h=>h.type.startsWith("video/"));c&&this.readVideoFileInto(c,s)}}),this.on(this.ed,"dragover",t=>t.preventDefault()),this.on(this.ed,"mousedown",t=>{var h,d,m,g,u,v,b;const e=t.target,i=(h=e.closest)==null?void 0:h.call(e,"table");i&&this.ed.contains(i)?this.selectTableForResize(i):this.clearTableHandles();const s=(d=e.closest)==null?void 0:d.call(e,".img-ph:not(.vid-ph)");s&&this.ed.contains(s)&&!this.options.readonly?(t.preventDefault(),this.ed.focus(),this.selectImgPlaceholder(s)):this.clearImgPlaceholderSel();const l=(m=e.closest)==null?void 0:m.call(e,".vid-ph");l&&this.ed.contains(l)&&!this.options.readonly?(t.preventDefault(),this.ed.focus(),this.selectVphPlaceholder(l)):this.clearVphPlaceholderSel();const o=(g=e.closest)==null?void 0:g.call(e,".tpl");o&&this.ed.contains(o)&&!this.options.readonly?this.selectTemplate(o):this.clearTplSel();const n=(u=e.closest)==null?void 0:u.call(e,"pre.code-block");n&&this.ed.contains(n)&&!this.options.readonly?(t.preventDefault(),this.selectCodeEl(n)):this.clearCodeSel();const r=(v=e.closest)==null?void 0:v.call(e,"img");r&&this.ed.contains(r)&&!this.options.readonly?(t.preventDefault(),this.selectImage(r)):this.clearImageHandles();const c=(b=e.closest)==null?void 0:b.call(e,"video, .video-embed");c&&this.ed.contains(c)&&!this.options.readonly?(t.preventDefault(),this.selectVideo(c)):this.clearVidHandles()}),this.on(this.ed,"mouseover",t=>{var i,s;if(this.options.readonly)return;const e=(s=(i=t.target).closest)==null?void 0:s.call(i,"img");e&&this.ed.contains(e)&&(this.cancelImgHide(),this.selectImage(e))}),this.on(this.ed,"mouseout",t=>{var s,l,o,n;const e=(l=(s=t.target).closest)==null?void 0:l.call(s,"img");if(!e)return;const i=t.relatedTarget;i&&((o=this.imgCtx)!=null&&o.contains(i)||this.imgHandles.some(r=>r.contains(i))||((n=i.closest)==null?void 0:n.call(i,"img"))===e)||this.scheduleImgHide()}),this.on(this.ed,"scroll",()=>{this.positionTableHandles(),this.positionImageHandles(),this.positionImgPhCtx(),this.positionTplCtx(),this.positionVphCtx(),this.positionVidCtx(),this.positionCodeCtx()}),this.onWin("scroll",()=>{this.positionTableHandles(),this.positionImageHandles(),this.positionImgPhCtx(),this.positionTplCtx(),this.positionVphCtx(),this.positionVidCtx(),this.positionCodeCtx(),this.repositionSelToolbar()},!0),this.onWin("resize",()=>{this.positionTableHandles(),this.positionImageHandles(),this.positionImgPhCtx(),this.positionTplCtx(),this.positionVphCtx(),this.positionVidCtx(),this.positionCodeCtx(),this.repositionSelToolbar(),this.updateToolbarOverflow()}),typeof ResizeObserver<"u"){const t=new ResizeObserver(()=>this.updateToolbarOverflow());t.observe(this.shell),this.listeners.push(()=>t.disconnect())}this.on(this.imgInput,"change",()=>{var s;const t=(s=this.imgInput.files)==null?void 0:s[0];if(!t)return;const e=this.phUploadTarget;if(this.phUploadTarget=null,e&&this.ed.contains(e)){this.readImageFileInto(t,e);return}const i=new FileReader;i.onload=()=>{this.restoreSel(),document.execCommand("insertHTML",!1,`<img src="${i.result}" title="${t.name.replace(/"/g,"")}" alt="">`),this.onChange()},i.readAsDataURL(t)}),this.on(this.vidInput,"change",()=>{var s;const t=(s=this.vidInput.files)==null?void 0:s[0];if(!t)return;const e=this.vphUploadTarget;if(this.vphUploadTarget=null,e&&this.ed.contains(e)){this.readVideoFileInto(t,e);return}const i=new FileReader;i.onload=()=>{this.restoreSel(),document.execCommand("insertHTML",!1,`<video controls src="${i.result}" title="${t.name.replace(/"/g,"")}"></video>`),this.onChange()},i.readAsDataURL(t)}),this.on(this.docInput,"change",()=>{var e;const t=(e=this.docInput.files)==null?void 0:e[0];t&&this.importWordFile(t).catch(()=>alert(this.t("importfail")))}),this.onDoc("mousedown",t=>{this.ed.contains(t.target)||t.target===this.tblCorner||this.tblColBars.includes(t.target)||this.tblCtx&&this.tblCtx.contains(t.target)||this.imgHandles.includes(t.target)||this.imgCtx&&this.imgCtx.contains(t.target)||this.phCtx&&this.phCtx.contains(t.target)||this.tplCtx&&this.tplCtx.contains(t.target)||this.selCtx&&this.selCtx.contains(t.target)||this.vphCtx&&this.vphCtx.contains(t.target)||this.vidCtx&&this.vidCtx.contains(t.target)||this.codeCtx&&this.codeCtx.contains(t.target)||this.openPop&&this.openPop.contains(t.target)||this.openSubEl&&this.openSubEl.contains(t.target)||(this.clearTableHandles(),this.clearImageHandles(),this.clearImgPlaceholderSel(),this.clearTplSel(),this.clearVphPlaceholderSel(),this.clearVidHandles(),this.clearCodeSel(),this.clearSelToolbar())})}on(t,e,i){t.addEventListener(e,i),this.listeners.push(()=>t.removeEventListener(e,i))}onDoc(t,e){document.addEventListener(t,e),this.listeners.push(()=>document.removeEventListener(t,e))}onWin(t,e,i){window.addEventListener(t,e,i),this.listeners.push(()=>window.removeEventListener(t,e,i))}getContent(){return this.ed.innerHTML}getContentForEmail(){const t=(o,n)=>{const r=(o.getAttribute("style")||"").trim();o.setAttribute("style",r?r.replace(/;?$/,"; ")+n:n)},e=document.createElement("div");e.innerHTML=this.ed.innerHTML;let i=null;e.querySelectorAll("[dir]").forEach(o=>{const n=(o.getAttribute("dir")||"").toLowerCase();if(n!=="rtl"&&n!=="ltr")return;const r=n;i||(i=r),/text-align\s*:/i.test(o.getAttribute("style")||"")||t(o,`text-align:${r==="rtl"?"right":"left"}`)}),e.querySelectorAll(Ft).forEach(o=>{const n=(o.getAttribute("dir")||"").toLowerCase();if(n==="rtl"||n==="ltr")return;const r=Ot(rt(o));if(!r)return;i||(i=r),o.setAttribute("dir",r);const c=/text-align\s*:/i.test(o.getAttribute("style")||"");t(o,c?`direction:${r}`:`direction:${r};text-align:${r==="rtl"?"right":"left"}`)});const s=i||this.ed.getAttribute("dir")||this.dir();return e.querySelectorAll("table:not([dir])").forEach(o=>{o.setAttribute("dir",s),/direction\s*:/i.test(o.getAttribute("style")||"")||t(o,`direction:${s}`)}),`<div dir="${s}" style="direction:${s};text-align:${s==="rtl"?"right":"left"}">${e.innerHTML}</div>`}setContent(t){this.ed.innerHTML=t||"<p><br></p>",this.refreshState(),this.clearTableHandles(),this.clearImageHandles(),this.clearImgPlaceholderSel(),this.clearTplSel(),this.clearVphPlaceholderSel(),this.clearVidHandles(),this.clearCodeSel(),this.clearSelToolbar(),this.onChange()}insertContent(t){this.restoreSel(),document.execCommand("insertHTML",!1,t),this.saveSel(),this.refreshState(),this.onChange()}setLanguage(t){this.lang=t,this.initUI()}focus(){this.ed.focus()}async importWordFile(t){const e=await It(t);this.recordRevision(),this.setContent(e),this.recordRevision()}restoreDraft(){let t=null;try{t=localStorage.getItem(this.draftStorageKey)}catch{}if(!t)return!1;try{const e=JSON.parse(t);return e.html?(this.recordRevision(),this.setContent(e.html),!0):!1}catch{return!1}}getRevisions(){return this.revisions.slice()}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.revTimer!=null&&window.clearTimeout(this.revTimer),this.draftTimer!=null&&window.clearTimeout(this.draftTimer),this.closePop(),this.closeDlg(),this.clearTableHandles(),this.clearImageHandles(),this.clearImgPlaceholderSel(),this.clearTplSel(),this.clearVphPlaceholderSel(),this.clearVidHandles(),this.clearCodeSel(),this.clearSelToolbar(),this.listeners.forEach(t=>t()),this.listeners=[],this.shell&&this.shell.parentNode&&this.shell.parentNode.removeChild(this.shell),this.imgInput&&this.imgInput.parentNode&&this.imgInput.parentNode.removeChild(this.imgInput),this.vidInput&&this.vidInput.parentNode&&this.vidInput.parentNode.removeChild(this.vidInput),this.docInput&&this.docInput.parentNode&&this.docInput.parentNode.removeChild(this.docInput),this.contentStyleEl=null)}saveSel(){const t=window.getSelection();t&&t.rangeCount&&this.ed.contains(t.anchorNode)&&(this.savedRange=t.getRangeAt(0).cloneRange())}restoreSel(){if(!this.savedRange){this.ed.focus();return}this.ed.focus();const t=window.getSelection();t&&(t.removeAllRanges(),t.addRange(this.savedRange))}exec(t,e){this.restoreSel(),document.execCommand("styleWithCSS",!1,t!=="fontSize"?"true":"false"),document.execCommand(t,!1,e??void 0),this.saveSel(),this.refreshState(),this.onChange()}closestBlock(t){for(;t&&t!==this.ed;){if(t.nodeType===1&&/^(P|DIV|H[1-6]|LI|PRE|BLOCKQUOTE|TD|TH)$/i.test(t.tagName))return t;t=t.parentNode}return null}tryExitBlockquote(t){const e=window.getSelection();if(!e||!e.isCollapsed||!e.anchorNode||!this.ed.contains(e.anchorNode))return;const i=this.closestBlock(e.anchorNode);if(!i||i.tagName==="BLOCKQUOTE"||(i.textContent||"").trim()!=="")return;const s=i.closest("blockquote");if(!s||!this.ed.contains(s)||i!==s.lastElementChild)return;t.preventDefault();const l=document.createElement("p");l.appendChild(document.createElement("br")),s.after(l),i.remove(),s.firstElementChild||s.remove();const o=document.createRange();o.setStart(l,0),o.collapse(!0),e.removeAllRanges(),e.addRange(o),this.saveSel(),this.onChange()}selectedBlocks(){const t=window.getSelection();if(!t||!t.rangeCount||!this.ed.contains(t.anchorNode))return[];const e=t.getRangeAt(0),i=Array.from(this.ed.querySelectorAll("p,h1,h2,h3,h4,h5,h6,li,pre,blockquote,td,th")).filter(s=>e.intersectsNode(s));if(!i.length){const s=this.closestBlock(t.anchorNode);if(s)return[s]}return i}onChange(){this.options.onChange(this.ed.innerHTML),this.scheduleRevision(),this.scheduleDraftSave()}recordRevision(){const t=this.ed.innerHTML,e=this.revisions[this.revisions.length-1];e&&e.html===t||(this.revisions.push({time:Date.now(),html:t}),this.revisions.length>30&&this.revisions.shift())}scheduleRevision(){this.revTimer!=null&&window.clearTimeout(this.revTimer),this.revTimer=window.setTimeout(()=>{this.revTimer=null,this.recordRevision()},1500)}scheduleDraftSave(){this.draftTimer!=null&&window.clearTimeout(this.draftTimer),this.draftTimer=window.setTimeout(()=>{this.draftTimer=null;try{localStorage.setItem(this.draftStorageKey,JSON.stringify({time:Date.now(),html:this.ed.innerHTML}))}catch{}},800)}revisionDlg(){this.recordRevision(),this.dialog(this.t("revhistory"),t=>{if(!this.revisions.length){t.innerHTML=`<p style="color:#556">${this.t("revempty")}</p>`;return}const e=document.createElement("div");e.className="revwrap";const i=document.createElement("div");i.className="revlist";const s=document.createElement("div");s.className="revprev";const l=document.createElement("button");l.type="button",l.className="revrestore",l.textContent=this.t("restore");let o=this.revisions.length-1;const n=new Intl.DateTimeFormat(this.lang==="ar"?"ar-AE":"en-GB",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit"}),r={},c=h=>{o=h,this.revisions.forEach((d,m)=>{var g;return(g=r[m])==null?void 0:g.classList.toggle("on",m===h)}),s.innerHTML=this.revisions[h].html,l.disabled=h===this.revisions.length-1};for(let h=this.revisions.length-1;h>=0;h--){const d=this.revisions[h],m=document.createElement("button");m.type="button";const g=(new DOMParser().parseFromString(d.html,"text/html").body.textContent||"").trim(),u=g?g.split(/\s+/).length:0,v=h===this.revisions.length-1;m.innerHTML=`<span>${v?this.t("currentver"):n.format(new Date(d.time))}</span><span class="wc">${u} ${this.t("words")}</span>`,m.addEventListener("click",()=>c(h)),r[h]=m,i.appendChild(m)}i.append(l),l.addEventListener("click",()=>{const h=this.revisions[o];h&&(this.recordRevision(),this.setContent(h.html),this.recordRevision(),this.closeDlg())}),e.append(i,s),t.appendChild(e),c(o)})}closeSub(){var t;(t=this.openSubEl)==null||t.remove(),this.openSubEl=null}closePop(){var t;this.closeSub(),this.openPop&&(this.openPop.remove(),this.openPop=null,(t=this.popAnchor)==null||t.classList.remove("open"),this.popAnchor=null,this.setOpTarget(null))}openSubFor(t,e){this.closeSub();const i=document.createElement("div");i.className="pop sub",i.dir=this.dir(),t.subBuild?t.subBuild(i):t.sub&&this.menuItems(i,t.sub),i.addEventListener("mousedown",r=>{r.target.tagName!=="INPUT"&&r.preventDefault()}),document.body.appendChild(i);const s=e.getBoundingClientRect();let o=this.dir()==="rtl"?s.left-i.offsetWidth+2:s.right-2;o=Math.max(8,Math.min(o+scrollX,scrollX+innerWidth-i.offsetWidth-8));let n=s.top+scrollY-6;n=Math.max(8+scrollY,Math.min(n,scrollY+innerHeight-i.offsetHeight-8)),i.style.left=o+"px",i.style.top=n+"px",this.openSubEl=i}popup(t,e,i){if(this.openPop&&this.popAnchor===t){this.closePop();return}this.closePop();const s=document.createElement("div");s.className="pop"+(i?" "+i:""),s.dir=this.dir(),e(s),document.body.appendChild(s);const l=t.getBoundingClientRect();s.style.minWidth=Math.max(160,Math.round(l.width))+"px",s.style.top=l.bottom+scrollY+2+"px";let n=this.dir()==="rtl"?l.right-s.offsetWidth:l.left;n=Math.max(8,Math.min(n+scrollX,scrollX+innerWidth-s.offsetWidth-8)),s.style.left=n+"px",s.addEventListener("mousedown",r=>{r.target.tagName!=="INPUT"&&r.preventDefault()}),this.openPop=s,this.popAnchor=t,t.classList.add("open")}menuItems(t,e){e.forEach(i=>{if(i==="|"){t.insertAdjacentHTML("beforeend",'<div class="sep"></div>');return}const s=!!(i.sub||i.subBuild),l=document.createElement("button");l.className="mi"+(i.on?" on":""),l.innerHTML=`<span class="ic">${i.icon||""}</span><span class="prev" ${i.previewStyle?`style="${i.previewStyle}"`:""}>${i.label}</span>${i.shortcut?`<span class="sc">${i.shortcut}</span>`:""}${s?`<span class="subarrow">${a.chev}</span>`:""}`,l.addEventListener("click",()=>{i.action&&(this.closePop(),i.action())}),l.addEventListener("mouseenter",()=>{var o;s?this.openSubFor(i,l):this.openSubEl&&t!==this.openSubEl&&this.closeSub(),(o=i.hover)==null||o.call(i,!0)}),l.addEventListener("mouseleave",()=>{var o;return(o=i.hover)==null?void 0:o.call(i,!1)}),t.appendChild(l)})}tbtn(t,e,i,s){const l=document.createElement("button");return l.className="tbtn",l.type="button",l.title=e,l.innerHTML=t,s&&(l.dataset.id=s),l.addEventListener("mousedown",o=>o.preventDefault()),l.addEventListener("click",i),l}stepBtn(t){const e=t>0?"+":"−",i=t>0?a.fontsizeup:a.fontsizedown,s=this.tbtn(i,this.t("fontsize")+" "+e,()=>this.stepFontSize(t));return s.addEventListener("mousedown",()=>this.saveSel()),s}menuTbtn(t,e,i,s){const l=this.tbtn(t,e,()=>i(l),s);return l.classList.add("hasmenu"),l.insertAdjacentHTML("beforeend",a.chev),l.addEventListener("mousedown",()=>this.saveSel()),l}colorChips(){const t=s=>{const l=document.createElement("button");return l.type="button",l.className="cchip",l.title=s,l.addEventListener("mousedown",o=>{o.preventDefault(),this.saveSel()}),l},e=pt.map(s=>{const l=t(this.t("forecolor"));return l.style.background=s,l.addEventListener("click",()=>this.applyColor("fore",s)),l}),i=t(this.t("forecolor"));return i.classList.add("more"),i.dataset.cb="fore",i.innerHTML=a.chev,i.addEventListener("click",()=>this.colorMenu(i,"fore")),[...e,i]}group(...t){const e=document.createElement("div");return e.className="tgrp",t.forEach(i=>{i.classList.add("gbtn"),e.appendChild(i)}),e}tsel(t,e,i,s){const l=document.createElement("button");return l.className="tsel "+t,l.type="button",l.dataset.id=e,l.innerHTML=`<span class="lbl empty">${i||""}</span>${a.chev}`,l.addEventListener("mousedown",o=>{o.preventDefault(),this.saveSel()}),l.addEventListener("click",()=>s(l)),l}setListStyle(t,e){var l,o;this.restoreSel();const i=window.getSelection();if(!i)return;let s=(l=this.closestBlock(i.anchorNode))==null?void 0:l.closest(t);s||(this.exec(t==="ol"?"insertOrderedList":"insertUnorderedList"),s=(o=this.closestBlock(i.anchorNode))==null?void 0:o.closest(t)),s&&(s.style.listStyleType=e),this.saveSel(),this.onChange()}listMenu(t,e){var c;const i=e==="ol"?"insertOrderedList":"insertUnorderedList",s=e==="ol"?[["lower-alpha",a.ol_alpha],["lower-roman",a.ol_roman],["upper-alpha",a.ol_alphau],["upper-roman",a.ol_romanu]]:[["circle",a.ul_circle],["square",a.ul_square]],l=this.tArr(e==="ol"?"liststyles_ol":"liststyles_ul").slice(1),o=window.getSelection(),n=o?(c=this.closestBlock(o.anchorNode))==null?void 0:c.closest(e):null,r=n?n.style.listStyleType:"";this.popup(t,h=>{this.menuItems(h,[{label:this.t(e==="ol"?"numlist":"bullist"),icon:e==="ol"?a.numlist:a.bullist,on:document.queryCommandState(i),action:()=>this.exec(i)}]),h.insertAdjacentHTML("beforeend",'<div class="sep"></div>');const d=document.createElement("div");d.className="mi-grid",s.forEach(([m,g],u)=>{const v=document.createElement("button");v.className="mi"+(r===m?" on":""),v.innerHTML=`<span class="ic">${g}</span><span class="prev">${l[u]}</span>`,v.addEventListener("click",()=>{this.closePop(),this.setListStyle(e,m)}),d.appendChild(v)}),h.appendChild(d)})}buildPaletteInto(t,e,i){const s=document.createElement("div");s.className="cpal",st.forEach(d=>{const m=document.createElement("button");m.type="button",m.style.background=d,m.title=d,m.addEventListener("click",()=>{this.closePop(),i(d)}),s.appendChild(m)}),t.appendChild(s),t.insertAdjacentHTML("beforeend",'<div class="sep"></div>');const l=document.createElement("div");l.className="cfoot";const o=/^#[0-9a-f]{6}$/i.test(e)?e:"#000000",n=document.createElement("div");n.className="cswatch cur",n.title=this.t("currentcolor"),n.style.background=o,n.innerHTML=a.check;const r=document.createElement("button");r.type="button",r.className="cswatch nocolor",r.title=this.t("removecolor"),r.addEventListener("click",()=>{this.closePop(),i(null)});const c=document.createElement("label");c.className="cswatch cwheel",c.title=this.t("customcolor"),c.innerHTML=a.palette;const h=document.createElement("input");h.type="color",h.value=o,h.addEventListener("change",()=>{this.closePop(),i(h.value)}),c.appendChild(h),l.append(n,r,c),t.appendChild(l)}colorMenu(t,e){this.popup(t,i=>{const s=e==="fore"?this.foreColor:this.backColor;this.buildPaletteInto(i,s,l=>this.applyColor(e,l))},e==="fore"?"pop-forecolor":"pop-backcolor")}applyColor(t,e){t==="fore"?(this.foreColor=e||"#000000",this.exec("foreColor",e||"#000000")):(this.backColor=e||"transparent",this.exec("hiliteColor",e||"transparent")),this.syncColorSwatches(this.toolbar),this.selCtx&&this.syncColorSwatches(this.selCtx)}syncColorSwatches(t){t.querySelectorAll("[data-cb=fore]").forEach(e=>e.style.background=this.foreColor),t.querySelectorAll("[data-cb=back]").forEach(e=>e.style.background=this.backColor)}fontItems(){return this.options.fontFamilyFormats.map(([t,e])=>({label:t,previewStyle:`font-family:${e}`,on:this.currentFont()===t,action:()=>this.exec("fontName",e)}))}fontMenu(t){this.popup(t,e=>this.menuItems(e,this.fontItems()))}sizeItems(){return it.map(t=>({label:t,on:this.currentSize()===t,action:()=>this.applyFontSize(t)}))}sizeMenu(t){this.popup(t,e=>this.menuItems(e,this.sizeItems()))}ensureSizeTarget(){const t=window.getSelection();if(!t)return;if(!t.rangeCount){const o=document.createRange();o.selectNodeContents(this.ed),o.collapse(!0),t.addRange(o)}if(!t.isCollapsed)return;const e=t.getRangeAt(0),i=e.startContainer;if(i.nodeType===3){const o=i.data;let n=e.startOffset,r=e.startOffset;for(;n>0&&/\S/.test(o[n-1]);)n--;for(;r<o.length&&/\S/.test(o[r]);)r++;if(r>n){const c=document.createRange();c.setStart(i,n),c.setEnd(i,r),t.removeAllRanges(),t.addRange(c),this.savedRange=c.cloneRange();return}}const s=document.createTextNode("​");e.insertNode(s);const l=document.createRange();l.setStart(s,0),l.setEnd(s,1),t.removeAllRanges(),t.addRange(l),this.savedRange=l.cloneRange()}applyFontSize(t){this.restoreSel(),this.ensureSizeTarget(),document.execCommand("styleWithCSS",!1,"false"),document.execCommand("fontSize",!1,"7");const e=[];if(this.ed.querySelectorAll('font[size="7"]').forEach(i=>{const s=document.createElement("span");for(s.style.fontSize=t;i.firstChild;)s.appendChild(i.firstChild);i.replaceWith(s),e.push(s)}),e.length){const i=document.createRange();i.setStart(e[0],0),i.setEnd(e[e.length-1],e[e.length-1].childNodes.length);const s=window.getSelection();s&&(s.removeAllRanges(),s.addRange(i))}this.saveSel(),this.refreshState(),this.onChange()}stepFontSize(t){const e=parseInt(this.currentSize(),10)||14,i=Math.min(dt,Math.max(ht,e+t));i!==e&&this.applyFontSize(i+"px")}transformCase(t){this.restoreSel();const e=window.getSelection();if(!e||!e.rangeCount||e.isCollapsed)return;const i=e.getRangeAt(0),s=document.createTreeWalker(this.ed,NodeFilter.SHOW_TEXT),l=[];let o;for(;o=s.nextNode();)i.intersectsNode(o)&&l.push(o);l.forEach(n=>{const r=n===i.startContainer?i.startOffset:0,c=n===i.endContainer?i.endOffset:n.data.length;if(c<=r)return;const h=n.data.slice(r,c);let d=h;t==="lower"?d=h.toLowerCase():t==="upper"?d=h.toUpperCase():d=h.replace(/(^|\s)(\S)/g,(m,g,u)=>g+u.toUpperCase()),n.replaceData(r,c-r,d)}),this.saveSel(),this.refreshState(),this.onChange()}caseItems(){return[{label:this.t("lowercase"),icon:a.lowercaseic,action:()=>this.transformCase("lower")},{label:this.t("uppercase"),icon:a.uppercaseic,action:()=>this.transformCase("upper")},{label:this.t("capitalize"),icon:a.capitalizeic,action:()=>this.transformCase("capitalize")}]}caseMenu(t){this.popup(t,e=>this.menuItems(e,this.caseItems()))}applyBlockStyle(t,e){this.restoreSel();const i=this.selectedBlocks(),s=t==="lineHeight"?"line-height":t==="wordSpacing"?"word-spacing":"letter-spacing";i.forEach(l=>{e?l.style[t]=e:l.style.removeProperty(s)}),this.saveSel(),this.onChange()}currentBlockStyle(t){const e=window.getSelection(),i=e?this.closestBlock(e.anchorNode):null;return i&&i.style[t]||""}blockStyleItems(t,e){const i=this.currentBlockStyle(t);return[{label:this.t("normal"),on:!i,action:()=>this.applyBlockStyle(t,"")},...e.map(s=>({label:s,on:i===s,action:()=>this.applyBlockStyle(t,s)}))]}lineHeightMenu(t){this.popup(t,e=>this.menuItems(e,this.blockStyleItems("lineHeight",V)))}wordSpacingMenu(t){this.popup(t,e=>this.menuItems(e,this.blockStyleItems("wordSpacing",W)))}letterSpacingMenu(t){this.popup(t,e=>this.menuItems(e,this.blockStyleItems("letterSpacing",j)))}closestAnchor(){const t=window.getSelection();let e=t&&this.ed.contains(t.anchorNode)?t.anchorNode:null;for(;e&&e!==this.ed;){if(e.nodeType===1&&e.tagName==="A")return e;e=e.parentNode}return null}linkDlg(){this.saveSel();const t=this.closestAnchor();let e;const i=[];t&&i.push({label:this.t("unlink"),action:()=>{const s=document.createRange();s.selectNodeContents(t);const l=window.getSelection();l&&(l.removeAllRanges(),l.addRange(s)),document.execCommand("unlink"),this.closeDlg(),this.onChange()}}),i.push({label:this.t("cancel"),action:()=>this.closeDlg()},{label:this.t("save"),primary:!0,action:()=>{const s=e.value.trim();if(this.closeDlg(),!s)return;if(t){t.setAttribute("href",s),this.onChange();return}this.restoreSel();const l=window.getSelection();!l||l.isCollapsed?document.execCommand("insertHTML",!1,`<a href="${s.replace(/"/g,"&quot;")}">${s.replace(/&/g,"&amp;").replace(/</g,"&lt;")}</a>`):(document.execCommand("styleWithCSS",!1,"false"),document.execCommand("createLink",!1,s)),this.saveSel(),this.onChange()}}),this.dialog(this.t("linkttl"),s=>{const l=document.createElement("div");l.style.cssText="display:flex;align-items:center;gap:10px;margin:10px 0;min-width:360px";const o=document.createElement("span");o.style.cssText="width:60px;color:#556;flex:none",o.textContent=this.t("linkurl"),e=document.createElement("input"),e.type="url",e.placeholder="https://",e.style.cssText="flex:1;border:1px solid #cfd6df;border-radius:6px;padding:7px 9px;font:14px inherit",e.value=(t==null?void 0:t.getAttribute("href"))||"",l.append(o,e),s.appendChild(l),setTimeout(()=>e.focus(),0)},i)}blockItems(){return $.map(([t])=>({label:this.blockLabel(t),previewStyle:t.startsWith("h")?`font-weight:700;font-size:${22-2*+t[1]}px`:t==="pre"?"font-family:monospace":"",on:this.currentBlock()===t,action:()=>this.exec("formatBlock","<"+t+">")}))}blocksMenu(t){this.popup(t,e=>this.menuItems(e,this.blockItems()))}alignItems(){return[["justifyLeft","alignleft",a.alignleft],["justifyCenter","aligncenter",a.aligncenter],["justifyRight","alignright",a.alignright],["justifyFull","alignjustify",a.alignjustify]].map(([e,i,s])=>({label:this.t(i),icon:s,on:document.queryCommandState(e),action:()=>this.exec(e)}))}blockLabel(t){return t==="p"?this.t("para"):t==="pre"?this.t("pre"):this.t("heading")+" "+t[1]}tableGrid(t,e){this.popup(t,i=>this.buildTableGridInto(i,e))}buildTableGridInto(t,e){{const i=document.createElement("div");i.className="tgridwrap";const s=document.createElement("div");s.className="tgrid";const l=document.createElement("div");l.className="tgridlbl",l.textContent="1 × 1";const o=[];for(let n=0;n<8;n++)for(let r=0;r<10;r++){const c=document.createElement("span");c.dataset.r=String(n),c.dataset.c=String(r),c.addEventListener("mouseenter",()=>{o.forEach(h=>h.classList.toggle("hot",+h.dataset.r<=n&&+h.dataset.c<=r)),l.textContent=r+1+" × "+(n+1)}),c.addEventListener("click",()=>{this.closePop(),this.insertTable(n+1,r+1),e==null||e()}),o.push(c),s.appendChild(c)}i.append(s,l),t.appendChild(i)}}insertTable(t,e){this.restoreSel();let i='<table style="border-collapse:collapse;width:100%;table-layout:fixed"><tbody>';for(let s=0;s<t;s++){i+="<tr>";for(let l=0;l<e;l++)i+='<td style="border:1px solid #b9c2cc"><br></td>';i+="</tr>"}i+="</tbody></table><p><br></p>",document.execCommand("insertHTML",!1,i),this.saveSel(),this.onChange()}setDir(t){this.restoreSel();const e=this.selectedBlocks();e.length?e.forEach(i=>i.setAttribute("dir",t)):this.ed.setAttribute("dir",t),this.saveSel(),this.refreshState(),this.onChange()}parseToolbarString(t){return t.split("|").map(e=>e.trim().split(/\s+/).filter(Boolean)).filter(e=>e.length>0)}buildToolbarRegistry(){const t=this.tbtn(a.tableic,this.t("quicktable"),()=>this.tableGrid(t)),e={undo:()=>this.tbtn(a.undo,this.t("undo"),()=>this.exec("undo")),redo:()=>this.tbtn(a.redo,this.t("redo"),()=>this.exec("redo")),preview:()=>this.tbtn(a.prevw,this.t("preview"),()=>this.previewDlg()),print:()=>this.tbtn(a.printic,this.t("print"),()=>this.printDoc()),importword:()=>this.tbtn(a.wordic,this.t("importword"),()=>this.pickWordDoc()),revhistory:()=>this.tbtn(a.historyic,this.t("revhistory"),()=>this.revisionDlg()),fontfamily:()=>this.tsel("w-font","fontsel","",i=>this.fontMenu(i)),fontsize:()=>this.tsel("w-size","sizesel","",i=>this.sizeMenu(i)),fontsizeincrease:()=>this.stepBtn(1),fontsizedecrease:()=>this.stepBtn(-1),bold:()=>this.tbtn(a.bold,this.t("bold"),()=>this.exec("bold"),"bold"),italic:()=>this.tbtn(a.italic,this.t("italic"),()=>this.exec("italic"),"italic"),underline:()=>this.tbtn(a.underline,this.t("underline"),()=>this.exec("underline"),"underline"),strikethrough:()=>this.tbtn(a.strikethrough,this.t("strikethrough"),()=>this.exec("strikeThrough"),"strikeThrough"),forecolor:()=>this.colorChips(),backcolor:()=>this.menuTbtn(a.backcolor+'<span class="colorbar" data-cb="back"></span>',this.t("backcolor"),i=>this.colorMenu(i,"back")),alignleft:()=>this.tbtn(a.alignleft,this.t("alignleft"),()=>this.exec("justifyLeft"),"justifyLeft"),aligncenter:()=>this.tbtn(a.aligncenter,this.t("aligncenter"),()=>this.exec("justifyCenter"),"justifyCenter"),alignright:()=>this.tbtn(a.alignright,this.t("alignright"),()=>this.exec("justifyRight"),"justifyRight"),alignjustify:()=>this.tbtn(a.alignjustify,this.t("alignjustify"),()=>this.exec("justifyFull"),"justifyFull"),bullist:()=>this.menuTbtn(a.bullist,this.t("bullist"),i=>this.listMenu(i,"ul"),"insertUnorderedList"),numlist:()=>this.menuTbtn(a.numlist,this.t("numlist"),i=>this.listMenu(i,"ol"),"insertOrderedList"),outdent:()=>this.tbtn(a.outdent,this.t("outdent"),()=>this.exec("outdent")),indent:()=>this.tbtn(a.indent,this.t("indent"),()=>this.exec("indent")),link:()=>this.tbtn(a.link,this.t("linkttl"),()=>this.linkDlg()),blockquote:()=>this.tbtn(a.quote,this.t("quote"),()=>this.toggleBlock("blockquote"),"blockquote"),code:()=>this.tbtn(a.inlinecodeic,this.t("code"),()=>this.toggleInlineCode(),"code"),codesample:()=>this.tbtn(a.codesampleic,this.t("codesample"),()=>this.codeDlg()),changecase:()=>this.menuTbtn(a.caseic,this.t("changecase"),i=>this.caseMenu(i)),lineheight:()=>this.menuTbtn(a.lineheight,this.t("lineheight"),i=>this.lineHeightMenu(i)),wordspacing:()=>this.menuTbtn(a.wordspacing,this.t("wordspacing"),i=>this.wordSpacingMenu(i)),letterspacing:()=>this.menuTbtn(a.letterspacing,this.t("letterspacing"),i=>this.letterSpacingMenu(i)),removeformat:()=>this.tbtn(a.clearformatic,this.t("removeformat"),()=>this.exec("removeFormat")),blocks:()=>this.tsel("w-block","blocksel",this.t("para"),i=>this.blocksMenu(i)),ltr:()=>this.tbtn(a.ltr,this.t("ltr"),()=>this.setDir("ltr"),"ltr"),rtl:()=>this.tbtn(a.rtl,this.t("rtl"),()=>this.setDir("rtl"),"rtl"),quickimage:()=>this.tbtn(a.image,this.t("quickimage"),()=>this.insertImagePlaceholder()),quickvideo:()=>this.tbtn(a.video,this.t("quickvideo"),()=>this.videoDlg()),quicktable:()=>t,template:()=>this.menuTbtn(a.templateic,this.t("template"),i=>this.templateMenu(i)),charmap:()=>this.tbtn(a.charic,this.t("charmap"),()=>this.charMap()),emoji:()=>this.tbtn(a.emojiic,this.t("emoji"),()=>this.emojiMap()),fullscreen:()=>this.tbtn(a.fullscreen,this.t("fullscreen"),()=>this.toggleFullscreen(),"fullscreen"),sourcecode:()=>this.tbtn(a.srcic,this.t("sourcecode"),()=>this.sourceDlg())};return e.styles=e.blocks,e.image=e.quickimage,e.media=e.quickvideo,e.table=e.quicktable,e}buildToolbar(){this.toolbar.innerHTML="";const t=this.options.toolbar===!0?at:this.options.toolbar,e=this.buildToolbarRegistry();this.parseToolbarString(t).forEach(i=>{const s=[];i.forEach(l=>{const o=e[l];if(!o){console.warn(`FableEditor: unknown toolbar item "${l}"`);return}const n=o();Array.isArray(n)?s.push(...n):s.push(n)}),s.length&&this.toolbar.appendChild(this.group(...s))}),this.tbrMore=this.tbtn(a.more,this.t("more"),()=>{this.tbrExpanded=!this.tbrExpanded,this.updateToolbarOverflow()}),this.tbrMore.classList.add("tbr-more"),this.toolbar.appendChild(this.tbrMore),this.syncColorSwatches(this.toolbar),this.updateToolbarOverflow()}updateToolbarOverflow(){const t=this.toolbar;if(!this.tbrMore)return;t.classList.add("tbr-measure");const e=t.scrollWidth>t.clientWidth+1;t.classList.remove("tbr-measure");const i=this.shell.offsetWidth<I.TBR_COLLAPSE_MAX;if(!e||!i){this.tbrExpanded=!1,t.classList.remove("collapsible","expanded"),this.tbrMore.classList.remove("on");return}t.classList.add("collapsible"),t.classList.toggle("expanded",this.tbrExpanded),this.tbrMore.classList.toggle("on",this.tbrExpanded)}mItem(t,e,i,s){return{label:this.t(t),icon:e,action:i,shortcut:s}}buildMenubar(){this.menubar.innerHTML="";const t={file:[this.mItem("newdoc",a.newic,()=>{this.recordRevision(),this.ed.innerHTML="<p><br></p>",this.onChange()}),"|",this.mItem("importword",a.wordic,()=>this.pickWordDoc()),this.mItem("restoredraft",a.draftic,()=>{this.restoreDraft()||alert(this.t("draftempty"))}),this.mItem("revhistory",a.historyic,()=>this.revisionDlg()),"|",this.mItem("preview",a.prevw,()=>this.previewDlg()),this.mItem("print",a.printic,()=>this.printDoc(),"Ctrl+P")],edit:[this.mItem("undo",a.undo,()=>this.exec("undo"),"Ctrl+Z"),this.mItem("redo",a.redo,()=>this.exec("redo"),"Ctrl+Y"),"|",this.mItem("cut",a.cutic,()=>this.exec("cut"),"Ctrl+X"),this.mItem("copy",a.copyic,()=>this.exec("copy"),"Ctrl+C"),this.mItem("paste",a.pasteic,()=>alert(this.t("pastehint")),"Ctrl+V"),"|",this.mItem("selectall",a.selall,()=>this.exec("selectAll"),"Ctrl+A")],view:[this.mItem("fullscreen",a.fullscreen,()=>this.toggleFullscreen()),this.mItem("preview",a.prevw,()=>this.previewDlg()),this.mItem("sourcecode",a.srcic,()=>this.sourceDlg())],insert:[this.mItem("link",a.link,()=>this.linkDlg()),this.mItem("image",a.image,()=>this.insertImagePlaceholder()),this.mItem("video",a.video,()=>this.videoDlg()),{label:this.t("inserttable"),icon:a.tableic,action:()=>this.tableGrid(this.menubar.querySelector('[data-menu-key="table"]')||this.menubar)},this.mItem("codesample",a.codesampleic,()=>this.codeDlg()),{label:this.t("template"),icon:a.templateic,subBuild:s=>this.buildTemplatePickInto(s)},this.mItem("hr",a.hric,()=>this.exec("insertHorizontalRule")),"|",this.mItem("charmap",a.charic,()=>this.charMap()),this.mItem("emoji",a.emojiic,()=>this.emojiMap()),this.mItem("datetime",a.dateic,()=>this.exec("insertText",new Date().toLocaleString(this.lang==="ar"?"ar-AE":"en-GB"))),"|",{label:this.t("pagebreak"),icon:a.pbic,action:()=>{this.restoreSel(),document.execCommand("insertHTML",!1,'<hr class="pagebreak"><p><br></p>'),this.onChange()}},this.mItem("nbsp",a.nbspic,()=>this.exec("insertText"," "))],format:[this.mItem("bold",a.bold,()=>this.exec("bold"),"Ctrl+B"),this.mItem("italic",a.italic,()=>this.exec("italic"),"Ctrl+I"),this.mItem("underline",a.underline,()=>this.exec("underline"),"Ctrl+U"),this.mItem("strikethrough",a.strikethrough,()=>this.exec("strikeThrough")),this.mItem("superscript",a.superscriptic,()=>this.exec("superscript")),this.mItem("subscript",a.subscriptic,()=>this.exec("subscript")),this.mItem("code",a.inlinecodeic,()=>this.toggleInlineCode()),this.mItem("quote",a.quote,()=>this.toggleBlock("blockquote")),"|",{label:this.t("fontfamily"),subBuild:s=>this.menuItems(s,this.fontItems())},{label:this.t("fontsize"),subBuild:s=>this.menuItems(s,this.sizeItems())},{label:this.t("blocks"),subBuild:s=>this.menuItems(s,this.blockItems())},{label:this.t("align"),subBuild:s=>this.menuItems(s,this.alignItems())},{label:this.t("lineheight"),icon:a.lineheight,subBuild:s=>this.menuItems(s,this.blockStyleItems("lineHeight",V))},{label:this.t("wordspacing"),icon:a.wordspacing,subBuild:s=>this.menuItems(s,this.blockStyleItems("wordSpacing",W))},{label:this.t("letterspacing"),icon:a.letterspacing,subBuild:s=>this.menuItems(s,this.blockStyleItems("letterSpacing",j))},"|",{label:this.t("forecolor"),icon:a.palette,subBuild:s=>this.buildPaletteInto(s,this.foreColor,l=>this.applyColor("fore",l))},{label:this.t("backcolor"),icon:a.backcolor,subBuild:s=>this.buildPaletteInto(s,this.backColor,l=>this.applyColor("back",l))},"|",this.mItem("bullist",a.bullist,()=>this.exec("insertUnorderedList")),this.mItem("numlist",a.numlist,()=>this.exec("insertOrderedList")),this.mItem("outdent",a.outdent,()=>this.exec("outdent")),this.mItem("indent",a.indent,()=>this.exec("indent")),"|",this.mItem("ltr",a.ltr,()=>this.setDir("ltr")),this.mItem("rtl",a.rtl,()=>this.setDir("rtl")),"|",{label:this.t("changecase"),icon:a.caseic,sub:this.caseItems()},"|",this.mItem("clearformat",a.clearformatic,()=>this.exec("removeFormat"))],tools:[this.mItem("sourcecode",a.srcic,()=>this.sourceDlg()),this.mItem("wordcount",a.wcic,()=>this.wordCountDlg())],table:[{label:this.t("inserttable"),icon:a.tableic,subBuild:s=>this.buildTableGridInto(s)},"|",{label:this.t("cell"),sub:[{label:this.t("cellprops"),icon:a.tableic,action:()=>this.cellPropsDlg()},{label:this.t("cellbg"),icon:a.palette,subBuild:s=>this.buildCellFillInto(s)}]},{label:this.t("row"),sub:[{label:this.t("rowabove"),icon:a.rowbefore,action:()=>this.tableOp("rowabove"),hover:s=>this.setOpTarget(s?"row":null)},{label:this.t("rowbelow"),icon:a.rowafter,action:()=>this.tableOp("rowbelow"),hover:s=>this.setOpTarget(s?"row":null)},{label:this.t("delrow"),icon:a.rowdelete,action:()=>this.tableOp("delrow"),hover:s=>this.setOpTarget(s?"row":null)},"|",{label:this.t("moverowup"),icon:a.moverowup,action:()=>this.tableMove("rowup"),hover:s=>this.setOpTarget(s?"row":null)},{label:this.t("moverowdown"),icon:a.moverowdown,action:()=>this.tableMove("rowdown"),hover:s=>this.setOpTarget(s?"row":null)},"|",{label:this.t("rowprops"),icon:a.tableic,action:()=>this.rowPropsDlg(),hover:s=>this.setOpTarget(s?"row":null)}]},{label:this.t("column"),sub:[{label:this.t("colbefore"),icon:a.colbefore,action:()=>this.tableOp("colbefore"),hover:s=>this.setOpTarget(s?"col":null)},{label:this.t("colafter"),icon:a.colafter,action:()=>this.tableOp("colafter"),hover:s=>this.setOpTarget(s?"col":null)},{label:this.t("delcol"),icon:a.coldelete,action:()=>this.tableOp("delcol"),hover:s=>this.setOpTarget(s?"col":null)},"|",{label:this.t("movecolleft"),icon:a.movecolleft,action:()=>this.tableMove("colleft"),hover:s=>this.setOpTarget(s?"col":null)},{label:this.t("movecolright"),icon:a.movecolright,action:()=>this.tableMove("colright"),hover:s=>this.setOpTarget(s?"col":null)},"|",{label:this.t("colprops"),icon:a.tableic,action:()=>this.colPropsDlg(),hover:s=>this.setOpTarget(s?"col":null)}]},"|",{label:this.t("tablepropsttl"),icon:a.tableic,action:()=>{const s=this.currentCell();if(!s){alert(this.t("nocell"));return}this.tblActive=s.closest("table"),this.tablePropsDlg()}},{label:this.t("deltable"),icon:a.trash,action:()=>this.tableOp("deltable")}],help:[this.mItem("helpttl",a.helpic,()=>this.helpDlg(),"Alt+0")]},e=this.options.menubar===!0?ct:this.options.menubar,i=new Set;e.split(/\s+/).filter(Boolean).forEach(s=>{if(i.has(s))return;if(i.add(s),!t[s]){console.warn(`FableEditor: unknown menubar item "${s}"`);return}const l=document.createElement("button");l.type="button",l.textContent=this.t(s),l.dataset.menuKey=s,l.addEventListener("mousedown",o=>{o.preventDefault(),this.saveSel()}),l.addEventListener("click",()=>this.popup(l,o=>this.menuItems(o,t[s]))),this.menubar.appendChild(l)})}tableOp(t){var r,c,h;this.restoreSel();const e=window.getSelection();if(!e)return;const i=((r=this.closestBlock(e.anchorNode))==null?void 0:r.closest("td,th"))||(e.anchorNode&&e.anchorNode.nodeType===1?(h=(c=e.anchorNode).closest)==null?void 0:h.call(c,"td,th"):null);if(!i)return;const s=i.parentElement,l=i.closest("table"),o=Array.from(s.children).indexOf(i),n=()=>{const d=s.cloneNode(!1);return Array.from(s.children).forEach(m=>{const g=document.createElement("td"),u=m.getAttribute("style");u&&g.setAttribute("style",u),g.style.removeProperty("background-color"),g.innerHTML="<br>",d.appendChild(g)}),d};if(t==="rowabove"&&s.before(n()),t==="rowbelow"&&s.after(n()),t==="delrow"){const d=s.parentElement;s.remove(),d.querySelector("tr")||l.remove()}(t==="colbefore"||t==="colafter")&&l.querySelectorAll("tr").forEach(d=>{const m=d.children[Math.min(o,d.children.length-1)],g=document.createElement("td"),u=m.getAttribute("style");u&&g.setAttribute("style",u),g.style.removeProperty("width"),g.style.removeProperty("background-color"),g.innerHTML="<br>",t==="colbefore"?m.before(g):m.after(g)}),t==="delcol"&&(l.querySelectorAll("tr").forEach(d=>{var m;return(m=d.children[o])==null?void 0:m.remove()}),l.querySelector("td,th")||l.remove()),t==="deltable"&&l.remove(),this.onChange(),this.positionTableHandles()}tableMove(t){this.restoreSel();const e=this.currentCell();if(!e)return;const i=e.parentElement,s=e.closest("table"),l=Array.from(i.children).indexOf(e);if(t==="rowup"){const r=i.previousElementSibling;r&&r.before(i)}if(t==="rowdown"){const r=i.nextElementSibling;r&&r.after(i)}t==="colleft"&&l>0&&s.querySelectorAll("tr").forEach(r=>{const c=r.children[l],h=r.children[l-1];c&&h&&h.before(c)}),t==="colright"&&s.querySelectorAll("tr").forEach(r=>{const c=r.children[l],h=r.children[l+1];c&&h&&h.after(c)});const o=document.createRange();o.selectNodeContents(e),o.collapse(!0);const n=window.getSelection();n&&(n.removeAllRanges(),n.addRange(o)),this.saveSel(),this.onChange(),this.positionTableHandles(),this.positionCellMarker()}alignTable(t){const e=this.tblActive;e&&(e.style.marginLeft=t==="left"?"0":"auto",e.style.marginRight=t==="right"?"0":"auto",this.onChange(),this.positionTableHandles())}buildCellFillInto(t){const e=s=>{const l=this.currentCell();if(!l){alert(this.t("nocell"));return}this.setOrClear(l,"background-color",s||""),this.onChange()},i=this.currentCell();this.buildPaletteInto(t,this.cssToHex(i?i.style.backgroundColor:""),e)}cssToHex(t){const e=t.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);return e?"#"+e.slice(1,4).map(i=>(+i).toString(16).padStart(2,"0")).join(""):t}cellFillMenu(t){this.popup(t,e=>this.buildCellFillInto(e),"pop-cellbg")}applyTableProps(t,e){e.width?t.style.width=/^\d+$/.test(e.width)?e.width+"px":e.width:t.style.removeProperty("width");const i=Array.from(t.querySelectorAll("td,th"));e.cellpadding!==""?i.forEach(s=>s.style.padding=e.cellpadding+"px"):i.forEach(s=>s.style.removeProperty("padding")),e.cellspacing!==""?(t.style.borderCollapse="separate",t.style.borderSpacing=e.cellspacing+"px"):(t.style.borderCollapse="collapse",t.style.removeProperty("border-spacing")),e.border!==""&&+e.border>0?(t.style.border=e.border+"px solid #b9c2cc",i.forEach(s=>s.style.border=e.border+"px solid #b9c2cc")):(t.style.removeProperty("border"),i.forEach(s=>s.style.removeProperty("border"))),t.style.removeProperty("margin-left"),t.style.removeProperty("margin-right"),e.align==="center"?(t.style.marginLeft="auto",t.style.marginRight="auto"):e.align==="right"?(t.style.marginLeft="auto",t.style.marginRight="0"):e.align==="left"&&(t.style.marginLeft="0",t.style.marginRight="auto")}tablePropsDlg(){const t=this.tblActive;if(!t)return;let e,i,s,l,o;const n="display:flex;align-items:center;gap:10px;margin:10px 0",r="width:120px;color:#556;flex:none",c="flex:1;border:1px solid #cfd6df;border-radius:6px;padding:7px 9px;font:14px inherit",h=t.querySelector("td,th"),d=t.style.width||"",m=h&&h.style.padding?parseFloat(h.style.padding):"",g=t.style.borderSpacing?parseFloat(t.style.borderSpacing):"",u=t.style.borderWidth?parseFloat(t.style.borderWidth):"",v=t.style.marginLeft,b=t.style.marginRight,x=v==="auto"&&b==="auto"?"center":v==="auto"?"right":b==="auto"&&v==="0"?"left":"";this.dialog(this.t("tablepropsttl"),C=>{const S=(w,k)=>{const L=document.createElement("div");L.style.cssText=n;const H=document.createElement("span");H.style.cssText=r,H.textContent=this.t(w),L.append(H,k),C.appendChild(L)};e=document.createElement("input"),e.type="text",e.style.cssText=c,e.placeholder="e.g. 600px or 100%",e.value=d,S("tblwidth",e),i=document.createElement("input"),i.type="number",i.min="0",i.style.cssText=c,i.value=String(m),S("tblcellpadding",i),s=document.createElement("input"),s.type="number",s.min="0",s.style.cssText=c,s.value=String(g),S("tblcellspacing",s),l=document.createElement("input"),l.type="number",l.min="0",l.style.cssText=c,l.value=String(u),S("tblborder",l),o=document.createElement("select"),o.style.cssText=c,[["","alignnone"],["left","alignleft"],["center","aligncenter"],["right","alignright"]].forEach(([w,k])=>{const L=document.createElement("option");L.value=w,L.textContent=this.t(k),w===x&&(L.selected=!0),o.appendChild(L)}),S("tblalign",o)},[{label:this.t("cancel"),action:()=>this.closeDlg()},{label:this.t("save"),primary:!0,action:()=>{this.applyTableProps(t,{width:e.value.trim(),cellpadding:i.value.trim(),cellspacing:s.value.trim(),border:l.value.trim(),align:o.value}),this.closeDlg(),this.onChange(),this.positionTableHandles()}}])}currentCell(){let t=this.savedRange?this.savedRange.startContainer:null;if(!t||!this.ed.contains(t)){const e=window.getSelection();t=e&&this.ed.contains(e.anchorNode)?e.anchorNode:null}for(;t&&t!==this.ed;){if(t.nodeType===1&&/^(TD|TH)$/.test(t.tagName))return t;t=t.parentNode}return null}toHexColor(t){if(/^#[0-9a-fA-F]{6}$/.test(t))return t;const e=/rgba?\((\d+)[,\s]+(\d+)[,\s]+(\d+)/.exec(t);return e?"#"+[e[1],e[2],e[3]].map(i=>(+i).toString(16).padStart(2,"0")).join(""):""}formRow(t,e,i){const s=document.createElement("div");s.style.cssText="display:flex;align-items:center;gap:10px;margin:10px 0;min-width:360px";const l=document.createElement("span");l.style.cssText="width:120px;color:#556;flex:none",l.textContent=e,s.append(l,i),t.appendChild(s)}formInput(t,e=""){const i=document.createElement("input");return i.type="text",i.style.cssText="flex:1;border:1px solid #cfd6df;border-radius:6px;padding:7px 9px;font:14px inherit;min-width:0",i.value=t,i.placeholder=e,i}formSelect(t,e){const i=document.createElement("select");return i.style.cssText="flex:1;border:1px solid #cfd6df;border-radius:6px;padding:7px 9px;font:14px inherit;background:#fff",t.forEach(([s,l])=>{const o=document.createElement("option");o.value=s,o.textContent=l,s===e&&(o.selected=!0),i.appendChild(o)}),i}formBg(t){const e=document.createElement("div");e.style.cssText="flex:1;display:flex;align-items:center;gap:8px";const i=this.toHexColor(t),s=document.createElement("input");s.type="color",s.value=i||"#ffffff",s.style.cssText="width:36px;height:29px;border:1px solid #cfd6df;border-radius:4px;padding:1px;background:none;cursor:pointer";const l=document.createElement("label");l.style.cssText="display:flex;align-items:center;gap:6px;cursor:pointer;color:#556";const o=document.createElement("input");return o.type="checkbox",o.checked=!!i,l.append(o,document.createTextNode(this.t("fill"))),s.addEventListener("input",()=>o.checked=!0),e.append(s,l),{wrap:e,color:s,fill:o}}setOrClear(t,e,i){i?t.style.setProperty(e,/^(width|height)$/.test(e)&&/^\d+$/.test(i)?i+"px":i):t.style.removeProperty(e)}cellPropsDlg(){const t=this.currentCell();if(!t){alert(this.t("nocell"));return}let e,i,s,l,o;this.dialog(this.t("cellprops").replace("…",""),n=>{e=this.formInput(t.style.width,"e.g. 120px / 25%"),this.formRow(n,this.t("tblwidth"),e),i=this.formInput(t.style.height,"e.g. 40px"),this.formRow(n,this.t("tblheight"),i),s=this.formSelect([["",this.t("alignnone")],["left",this.t("alignleft")],["center",this.t("aligncenter")],["right",this.t("alignright")]],t.style.textAlign||""),this.formRow(n,this.t("tblalign"),s),l=this.formSelect([["",this.t("alignnone")],["top",this.t("valigntop")],["middle",this.t("valignmiddle")],["bottom",this.t("valignbottom")]],t.style.verticalAlign||""),this.formRow(n,this.t("valign"),l),o=this.formBg(t.style.backgroundColor||""),this.formRow(n,this.t("backcolor"),o.wrap)},[{label:this.t("cancel"),action:()=>this.closeDlg()},{label:this.t("save"),primary:!0,action:()=>{this.setOrClear(t,"width",e.value.trim()),this.setOrClear(t,"height",i.value.trim()),this.setOrClear(t,"text-align",s.value),this.setOrClear(t,"vertical-align",l.value),this.setOrClear(t,"background-color",o.fill.checked?o.color.value:""),this.closeDlg(),this.onChange(),this.positionTableHandles()}}])}rowPropsDlg(){const t=this.currentCell();if(!t){alert(this.t("nocell"));return}const e=t.parentElement;let i,s;this.dialog(this.t("rowprops").replace("…",""),l=>{i=this.formInput(e.style.height,"e.g. 40px"),this.formRow(l,this.t("tblheight"),i),s=this.formBg(e.style.backgroundColor||""),this.formRow(l,this.t("backcolor"),s.wrap)},[{label:this.t("cancel"),action:()=>this.closeDlg()},{label:this.t("save"),primary:!0,action:()=>{this.setOrClear(e,"height",i.value.trim()),this.setOrClear(e,"background-color",s.fill.checked?s.color.value:""),this.closeDlg(),this.onChange(),this.positionTableHandles()}}])}colPropsDlg(){const t=this.currentCell();if(!t){alert(this.t("nocell"));return}const e=t.parentElement,i=t.closest("table"),s=Array.from(e.children).indexOf(t),l=Array.from(i.rows).map(r=>r.cells[s]).filter(Boolean);let o,n;this.dialog(this.t("colprops").replace("…",""),r=>{o=this.formInput(t.style.width,"e.g. 120px / 25%"),this.formRow(r,this.t("tblwidth"),o),n=this.formBg(t.style.backgroundColor||""),this.formRow(r,this.t("backcolor"),n.wrap)},[{label:this.t("cancel"),action:()=>this.closeDlg()},{label:this.t("save"),primary:!0,action:()=>{l.forEach(r=>{this.setOrClear(r,"width",o.value.trim()),this.setOrClear(r,"background-color",n.fill.checked?n.color.value:"")}),this.closeDlg(),this.onChange(),this.positionTableHandles()}}])}closeDlg(){this.dlgOvl&&(this.dlgOvl.remove(),this.dlgOvl=null)}dialog(t,e,i){this.closeDlg(),this.closePop(),this.dlgOvl=document.createElement("div"),this.dlgOvl.className="ovl";const s=document.createElement("div");s.className="dlg",s.dir=this.dir(),s.innerHTML=`<header><span>${t}</span><button type="button">×</button></header>
7
+ `,this.sbHelp=this.statusbar.querySelector(".mid"),this.sbWords=this.statusbar.querySelector(".words");const e=this.statusbar.querySelector(".grip");this.bindGrip(e),this.shell.appendChild(this.menubar),this.shell.appendChild(this.toolbar),this.shell.appendChild(this.ed),this.shell.appendChild(this.statusbar),this.contentStyle&&(this.contentStyleEl=document.createElement("style"),this.contentStyleEl.textContent=this.scopeContentStyle(this.contentStyle),this.shell.appendChild(this.contentStyleEl)),t.appendChild(this.shell),Pt(),this.options.statusbar||(this.statusbar.style.display="none"),this.imgInput=document.createElement("input"),this.imgInput.type="file",this.imgInput.accept=this.options.imageFileTypes.join(","),this.imgInput.style.display="none",t.appendChild(this.imgInput),this.vidInput=document.createElement("input"),this.vidInput.type="file",this.vidInput.accept=this.options.videoFileTypes.join(","),this.vidInput.style.display="none",t.appendChild(this.vidInput),this.docInput=document.createElement("input"),this.docInput.type="file",this.docInput.accept=".docx,application/vnd.openxmlformats-officedocument.wordprocessingml.document",this.docInput.style.display="none",t.appendChild(this.docInput)}applyTheme(t){const e=document.documentElement;t.primaryColor&&e.style.setProperty("--fable-primary",t.primaryColor),t.toolbarGroupBackground&&e.style.setProperty("--fable-tgrp-bg",t.toolbarGroupBackground),t.uiFontFamily&&e.style.setProperty("--fable-ui-font",t.uiFontFamily)}scopeContentStyle(t){return t.replace(/\bbody\b/g,"."+this.contentClass)}bindGrip(t){let e=0,i=0;const s=l=>{e=l.clientY,i=this.ed.offsetHeight,l.preventDefault();const o=r=>{this.ed.style.height=Math.max(120,i+r.clientY-e)+"px"},n=()=>{window.removeEventListener("mousemove",o),window.removeEventListener("mouseup",n)};window.addEventListener("mousemove",o),window.addEventListener("mouseup",n)};t.addEventListener("mousedown",s),this.listeners.push(()=>t.removeEventListener("mousedown",s))}bindEvents(){if(this.onDoc("mousedown",t=>{this.openPop&&!this.openPop.contains(t.target)&&!this.popAnchor.contains(t.target)&&!(this.openSubEl&&this.openSubEl.contains(t.target))&&this.closePop()}),this.onDoc("keydown",t=>{t.key==="Escape"&&(this.closePop(),this.closeDlg())}),this.onDoc("selectionchange",()=>{const t=window.getSelection();t&&this.ed.contains(t.anchorNode)?(this.saveSel(),this.refreshState(),this.updateSelToolbar(t),this.positionCellMarker()):this.clearSelToolbar()}),this.on(this.ed,"input",()=>{this.refreshState(),this.onChange(),this.positionTableHandles(),this.positionImageHandles(),this.positionImgPhCtx(),this.positionTplCtx(),this.positionVphCtx(),this.positionVidCtx(),this.positionCodeCtx()}),this.on(this.ed,"keydown",t=>{t.altKey&&t.key==="0"&&(t.preventDefault(),this.helpDlg()),(t.key==="Delete"||t.key==="Backspace")&&this.phActive&&(t.preventDefault(),this.removeImgPlaceholder()),(t.key==="Delete"||t.key==="Backspace")&&this.vphActive&&(t.preventDefault(),this.removeVphPlaceholder()),t.key==="`"&&!t.ctrlKey&&!t.metaKey&&!t.altKey&&this.tryCodeTyping(t),t.key==="Enter"&&!t.shiftKey&&!t.ctrlKey&&!t.metaKey&&!t.altKey&&this.tryExitBlockquote(t)}),this.on(this.ed,"paste",t=>this.handlePaste(t)),this.on(this.ed,"drop",t=>{var l,o,n,r;t.preventDefault();const e=t.target,i=(l=e.closest)==null?void 0:l.call(e,".img-ph:not(.vid-ph)");if(i&&this.ed.contains(i)&&!this.options.readonly){const c=Array.from(((o=t.dataTransfer)==null?void 0:o.files)||[]).find(h=>h.type.startsWith("image/"));c&&this.readImageFileInto(c,i);return}const s=(n=e.closest)==null?void 0:n.call(e,".vid-ph");if(s&&this.ed.contains(s)&&!this.options.readonly){const c=Array.from(((r=t.dataTransfer)==null?void 0:r.files)||[]).find(h=>h.type.startsWith("video/"));c&&this.readVideoFileInto(c,s)}}),this.on(this.ed,"dragover",t=>t.preventDefault()),this.on(this.ed,"mousedown",t=>{var h,d,m,g,u,v,b;const e=t.target,i=(h=e.closest)==null?void 0:h.call(e,"table");i&&this.ed.contains(i)?this.selectTableForResize(i):this.clearTableHandles();const s=(d=e.closest)==null?void 0:d.call(e,".img-ph:not(.vid-ph)");s&&this.ed.contains(s)&&!this.options.readonly?(t.preventDefault(),this.ed.focus(),this.selectImgPlaceholder(s)):this.clearImgPlaceholderSel();const l=(m=e.closest)==null?void 0:m.call(e,".vid-ph");l&&this.ed.contains(l)&&!this.options.readonly?(t.preventDefault(),this.ed.focus(),this.selectVphPlaceholder(l)):this.clearVphPlaceholderSel();const o=(g=e.closest)==null?void 0:g.call(e,".tpl");o&&this.ed.contains(o)&&!this.options.readonly?this.selectTemplate(o):this.clearTplSel();const n=(u=e.closest)==null?void 0:u.call(e,"pre.code-block");n&&this.ed.contains(n)&&!this.options.readonly?(t.preventDefault(),this.selectCodeEl(n)):this.clearCodeSel();const r=(v=e.closest)==null?void 0:v.call(e,"img");r&&this.ed.contains(r)&&!this.options.readonly?(t.preventDefault(),this.selectImage(r)):this.clearImageHandles();const c=(b=e.closest)==null?void 0:b.call(e,"video, .video-embed");c&&this.ed.contains(c)&&!this.options.readonly?(t.preventDefault(),this.selectVideo(c)):this.clearVidHandles()}),this.on(this.ed,"mouseover",t=>{var i,s;if(this.options.readonly)return;const e=(s=(i=t.target).closest)==null?void 0:s.call(i,"img");e&&this.ed.contains(e)&&(this.cancelImgHide(),this.selectImage(e))}),this.on(this.ed,"mouseout",t=>{var s,l,o,n;const e=(l=(s=t.target).closest)==null?void 0:l.call(s,"img");if(!e)return;const i=t.relatedTarget;i&&((o=this.imgCtx)!=null&&o.contains(i)||this.imgHandles.some(r=>r.contains(i))||((n=i.closest)==null?void 0:n.call(i,"img"))===e)||this.scheduleImgHide()}),this.on(this.ed,"scroll",()=>{this.positionTableHandles(),this.positionImageHandles(),this.positionImgPhCtx(),this.positionTplCtx(),this.positionVphCtx(),this.positionVidCtx(),this.positionCodeCtx()}),this.onWin("scroll",()=>{this.closePop(),this.positionTableHandles(),this.positionImageHandles(),this.positionImgPhCtx(),this.positionTplCtx(),this.positionVphCtx(),this.positionVidCtx(),this.positionCodeCtx(),this.repositionSelToolbar()},!0),this.onWin("resize",()=>{this.positionTableHandles(),this.positionImageHandles(),this.positionImgPhCtx(),this.positionTplCtx(),this.positionVphCtx(),this.positionVidCtx(),this.positionCodeCtx(),this.repositionSelToolbar(),this.updateToolbarOverflow()}),typeof ResizeObserver<"u"){const t=new ResizeObserver(()=>this.updateToolbarOverflow());t.observe(this.shell),this.listeners.push(()=>t.disconnect())}this.on(this.imgInput,"change",()=>{var s;const t=(s=this.imgInput.files)==null?void 0:s[0];if(!t)return;const e=this.phUploadTarget;if(this.phUploadTarget=null,e&&this.ed.contains(e)){this.readImageFileInto(t,e);return}const i=new FileReader;i.onload=()=>{this.restoreSel(),document.execCommand("insertHTML",!1,`<img src="${i.result}" title="${t.name.replace(/"/g,"")}" alt="">`),this.onChange()},i.readAsDataURL(t)}),this.on(this.vidInput,"change",()=>{var s;const t=(s=this.vidInput.files)==null?void 0:s[0];if(!t)return;const e=this.vphUploadTarget;if(this.vphUploadTarget=null,e&&this.ed.contains(e)){this.readVideoFileInto(t,e);return}const i=new FileReader;i.onload=()=>{this.restoreSel(),document.execCommand("insertHTML",!1,`<video controls src="${i.result}" title="${t.name.replace(/"/g,"")}"></video>`),this.onChange()},i.readAsDataURL(t)}),this.on(this.docInput,"change",()=>{var e;const t=(e=this.docInput.files)==null?void 0:e[0];t&&this.importWordFile(t).catch(()=>alert(this.t("importfail")))}),this.onDoc("mousedown",t=>{this.ed.contains(t.target)||t.target===this.tblCorner||this.tblColBars.includes(t.target)||this.tblCtx&&this.tblCtx.contains(t.target)||this.imgHandles.includes(t.target)||this.imgCtx&&this.imgCtx.contains(t.target)||this.phCtx&&this.phCtx.contains(t.target)||this.tplCtx&&this.tplCtx.contains(t.target)||this.selCtx&&this.selCtx.contains(t.target)||this.vphCtx&&this.vphCtx.contains(t.target)||this.vidCtx&&this.vidCtx.contains(t.target)||this.codeCtx&&this.codeCtx.contains(t.target)||this.openPop&&this.openPop.contains(t.target)||this.openSubEl&&this.openSubEl.contains(t.target)||(this.clearTableHandles(),this.clearImageHandles(),this.clearImgPlaceholderSel(),this.clearTplSel(),this.clearVphPlaceholderSel(),this.clearVidHandles(),this.clearCodeSel(),this.clearSelToolbar())})}on(t,e,i){t.addEventListener(e,i),this.listeners.push(()=>t.removeEventListener(e,i))}onDoc(t,e){document.addEventListener(t,e),this.listeners.push(()=>document.removeEventListener(t,e))}onWin(t,e,i){window.addEventListener(t,e,i),this.listeners.push(()=>window.removeEventListener(t,e,i))}getContent(){return this.ed.innerHTML}getContentForEmail(){const t=(o,n)=>{const r=(o.getAttribute("style")||"").trim();o.setAttribute("style",r?r.replace(/;?$/,"; ")+n:n)},e=document.createElement("div");e.innerHTML=this.ed.innerHTML;let i=null;e.querySelectorAll("[dir]").forEach(o=>{const n=(o.getAttribute("dir")||"").toLowerCase();if(n!=="rtl"&&n!=="ltr")return;const r=n;i||(i=r),/text-align\s*:/i.test(o.getAttribute("style")||"")||t(o,`text-align:${r==="rtl"?"right":"left"}`)}),e.querySelectorAll(Ft).forEach(o=>{const n=(o.getAttribute("dir")||"").toLowerCase();if(n==="rtl"||n==="ltr")return;const r=Ot(rt(o));if(!r)return;i||(i=r),o.setAttribute("dir",r);const c=/text-align\s*:/i.test(o.getAttribute("style")||"");t(o,c?`direction:${r}`:`direction:${r};text-align:${r==="rtl"?"right":"left"}`)});const s=i||this.ed.getAttribute("dir")||this.dir();return e.querySelectorAll("table:not([dir])").forEach(o=>{o.setAttribute("dir",s),/direction\s*:/i.test(o.getAttribute("style")||"")||t(o,`direction:${s}`)}),`<div dir="${s}" style="direction:${s};text-align:${s==="rtl"?"right":"left"}">${e.innerHTML}</div>`}setContent(t){this.ed.innerHTML=t||"<p><br></p>",this.refreshState(),this.clearTableHandles(),this.clearImageHandles(),this.clearImgPlaceholderSel(),this.clearTplSel(),this.clearVphPlaceholderSel(),this.clearVidHandles(),this.clearCodeSel(),this.clearSelToolbar(),this.onChange()}insertContent(t){this.restoreSel(),document.execCommand("insertHTML",!1,t),this.saveSel(),this.refreshState(),this.onChange()}setLanguage(t){this.lang=t,this.initUI()}focus(){this.ed.focus()}async importWordFile(t){const e=await It(t);this.recordRevision(),this.setContent(e),this.recordRevision()}restoreDraft(){let t=null;try{t=localStorage.getItem(this.draftStorageKey)}catch{}if(!t)return!1;try{const e=JSON.parse(t);return e.html?(this.recordRevision(),this.setContent(e.html),!0):!1}catch{return!1}}getRevisions(){return this.revisions.slice()}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.revTimer!=null&&window.clearTimeout(this.revTimer),this.draftTimer!=null&&window.clearTimeout(this.draftTimer),this.closePop(),this.closeDlg(),this.clearTableHandles(),this.clearImageHandles(),this.clearImgPlaceholderSel(),this.clearTplSel(),this.clearVphPlaceholderSel(),this.clearVidHandles(),this.clearCodeSel(),this.clearSelToolbar(),this.listeners.forEach(t=>t()),this.listeners=[],this.shell&&this.shell.parentNode&&this.shell.parentNode.removeChild(this.shell),this.imgInput&&this.imgInput.parentNode&&this.imgInput.parentNode.removeChild(this.imgInput),this.vidInput&&this.vidInput.parentNode&&this.vidInput.parentNode.removeChild(this.vidInput),this.docInput&&this.docInput.parentNode&&this.docInput.parentNode.removeChild(this.docInput),this.contentStyleEl=null)}saveSel(){const t=window.getSelection();t&&t.rangeCount&&this.ed.contains(t.anchorNode)&&(this.savedRange=t.getRangeAt(0).cloneRange())}restoreSel(){if(!this.savedRange){this.ed.focus();return}this.ed.focus();const t=window.getSelection();t&&(t.removeAllRanges(),t.addRange(this.savedRange))}exec(t,e){this.restoreSel(),document.execCommand("styleWithCSS",!1,t!=="fontSize"?"true":"false"),document.execCommand(t,!1,e??void 0),this.saveSel(),this.refreshState(),this.onChange()}closestBlock(t){for(;t&&t!==this.ed;){if(t.nodeType===1&&/^(P|DIV|H[1-6]|LI|PRE|BLOCKQUOTE|TD|TH)$/i.test(t.tagName))return t;t=t.parentNode}return null}tryExitBlockquote(t){const e=window.getSelection();if(!e||!e.isCollapsed||!e.anchorNode||!this.ed.contains(e.anchorNode))return;const i=this.closestBlock(e.anchorNode);if(!i||i.tagName==="BLOCKQUOTE"||(i.textContent||"").trim()!=="")return;const s=i.closest("blockquote");if(!s||!this.ed.contains(s)||i!==s.lastElementChild)return;t.preventDefault();const l=document.createElement("p");l.appendChild(document.createElement("br")),s.after(l),i.remove(),s.firstElementChild||s.remove();const o=document.createRange();o.setStart(l,0),o.collapse(!0),e.removeAllRanges(),e.addRange(o),this.saveSel(),this.onChange()}selectedBlocks(){const t=window.getSelection();if(!t||!t.rangeCount||!this.ed.contains(t.anchorNode))return[];const e=t.getRangeAt(0),i=Array.from(this.ed.querySelectorAll("p,h1,h2,h3,h4,h5,h6,li,pre,blockquote,td,th")).filter(s=>e.intersectsNode(s));if(!i.length){const s=this.closestBlock(t.anchorNode);if(s)return[s]}return i}onChange(){this.options.onChange(this.ed.innerHTML),this.scheduleRevision(),this.scheduleDraftSave()}recordRevision(){const t=this.ed.innerHTML,e=this.revisions[this.revisions.length-1];e&&e.html===t||(this.revisions.push({time:Date.now(),html:t}),this.revisions.length>30&&this.revisions.shift())}scheduleRevision(){this.revTimer!=null&&window.clearTimeout(this.revTimer),this.revTimer=window.setTimeout(()=>{this.revTimer=null,this.recordRevision()},1500)}scheduleDraftSave(){this.draftTimer!=null&&window.clearTimeout(this.draftTimer),this.draftTimer=window.setTimeout(()=>{this.draftTimer=null;try{localStorage.setItem(this.draftStorageKey,JSON.stringify({time:Date.now(),html:this.ed.innerHTML}))}catch{}},800)}revisionDlg(){this.recordRevision(),this.dialog(this.t("revhistory"),t=>{if(!this.revisions.length){t.innerHTML=`<p style="color:#556">${this.t("revempty")}</p>`;return}const e=document.createElement("div");e.className="revwrap";const i=document.createElement("div");i.className="revlist";const s=document.createElement("div");s.className="revprev";const l=document.createElement("button");l.type="button",l.className="revrestore",l.textContent=this.t("restore");let o=this.revisions.length-1;const n=new Intl.DateTimeFormat(this.lang==="ar"?"ar-AE":"en-GB",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit"}),r={},c=h=>{o=h,this.revisions.forEach((d,m)=>{var g;return(g=r[m])==null?void 0:g.classList.toggle("on",m===h)}),s.innerHTML=this.revisions[h].html,l.disabled=h===this.revisions.length-1};for(let h=this.revisions.length-1;h>=0;h--){const d=this.revisions[h],m=document.createElement("button");m.type="button";const g=(new DOMParser().parseFromString(d.html,"text/html").body.textContent||"").trim(),u=g?g.split(/\s+/).length:0,v=h===this.revisions.length-1;m.innerHTML=`<span>${v?this.t("currentver"):n.format(new Date(d.time))}</span><span class="wc">${u} ${this.t("words")}</span>`,m.addEventListener("click",()=>c(h)),r[h]=m,i.appendChild(m)}i.append(l),l.addEventListener("click",()=>{const h=this.revisions[o];h&&(this.recordRevision(),this.setContent(h.html),this.recordRevision(),this.closeDlg())}),e.append(i,s),t.appendChild(e),c(o)})}closeSub(){var t;(t=this.openSubEl)==null||t.remove(),this.openSubEl=null}closePop(){var t;this.closeSub(),this.openPop&&(this.openPop.remove(),this.openPop=null,(t=this.popAnchor)==null||t.classList.remove("open"),this.popAnchor=null,this.setOpTarget(null))}openSubFor(t,e){this.closeSub();const i=document.createElement("div");i.className="pop sub",i.dir=this.dir(),t.subBuild?t.subBuild(i):t.sub&&this.menuItems(i,t.sub),i.addEventListener("mousedown",r=>{r.target.tagName!=="INPUT"&&r.preventDefault()}),document.body.appendChild(i);const s=e.getBoundingClientRect();let o=this.dir()==="rtl"?s.left-i.offsetWidth+2:s.right-2;o=Math.max(8,Math.min(o+scrollX,scrollX+innerWidth-i.offsetWidth-8));let n=s.top+scrollY-6;n=Math.max(8+scrollY,Math.min(n,scrollY+innerHeight-i.offsetHeight-8)),i.style.left=o+"px",i.style.top=n+"px",this.openSubEl=i}popup(t,e,i){if(this.openPop&&this.popAnchor===t){this.closePop();return}this.closePop();const s=document.createElement("div");s.className="pop"+(i?" "+i:""),s.dir=this.dir(),e(s),document.body.appendChild(s);const l=t.getBoundingClientRect();s.style.minWidth=Math.max(160,Math.round(l.width))+"px",s.style.top=l.bottom+scrollY+2+"px";let n=this.dir()==="rtl"?l.right-s.offsetWidth:l.left;n=Math.max(8,Math.min(n+scrollX,scrollX+innerWidth-s.offsetWidth-8)),s.style.left=n+"px",s.addEventListener("mousedown",r=>{r.target.tagName!=="INPUT"&&r.preventDefault()}),this.openPop=s,this.popAnchor=t,t.classList.add("open")}menuItems(t,e){e.forEach(i=>{if(i==="|"){t.insertAdjacentHTML("beforeend",'<div class="sep"></div>');return}const s=!!(i.sub||i.subBuild),l=document.createElement("button");l.className="mi"+(i.on?" on":""),l.innerHTML=`<span class="ic">${i.icon||""}</span><span class="prev" ${i.previewStyle?`style="${i.previewStyle}"`:""}>${i.label}</span>${i.shortcut?`<span class="sc">${i.shortcut}</span>`:""}${s?`<span class="subarrow">${a.chev}</span>`:""}`,l.addEventListener("click",()=>{i.action&&(this.closePop(),i.action())}),l.addEventListener("mouseenter",()=>{var o;s?this.openSubFor(i,l):this.openSubEl&&t!==this.openSubEl&&this.closeSub(),(o=i.hover)==null||o.call(i,!0)}),l.addEventListener("mouseleave",()=>{var o;return(o=i.hover)==null?void 0:o.call(i,!1)}),t.appendChild(l)})}tbtn(t,e,i,s){const l=document.createElement("button");return l.className="tbtn",l.type="button",l.title=e,l.innerHTML=t,s&&(l.dataset.id=s),l.addEventListener("mousedown",o=>o.preventDefault()),l.addEventListener("click",i),l}stepBtn(t){const e=t>0?"+":"−",i=t>0?a.fontsizeup:a.fontsizedown,s=this.tbtn(i,this.t("fontsize")+" "+e,()=>this.stepFontSize(t));return s.addEventListener("mousedown",()=>this.saveSel()),s}menuTbtn(t,e,i,s){const l=this.tbtn(t,e,()=>i(l),s);return l.classList.add("hasmenu"),l.insertAdjacentHTML("beforeend",a.chev),l.addEventListener("mousedown",()=>this.saveSel()),l}colorChips(){const t=s=>{const l=document.createElement("button");return l.type="button",l.className="cchip",l.title=s,l.addEventListener("mousedown",o=>{o.preventDefault(),this.saveSel()}),l},e=pt.map(s=>{const l=t(this.t("forecolor"));return l.style.background=s,l.addEventListener("click",()=>this.applyColor("fore",s)),l}),i=t(this.t("forecolor"));return i.classList.add("more"),i.dataset.cb="fore",i.innerHTML=a.chev,i.addEventListener("click",()=>this.colorMenu(i,"fore")),[...e,i]}group(...t){const e=document.createElement("div");return e.className="tgrp",t.forEach(i=>{i.classList.add("gbtn"),e.appendChild(i)}),e}tsel(t,e,i,s){const l=document.createElement("button");return l.className="tsel "+t,l.type="button",l.dataset.id=e,l.innerHTML=`<span class="lbl empty">${i||""}</span>${a.chev}`,l.addEventListener("mousedown",o=>{o.preventDefault(),this.saveSel()}),l.addEventListener("click",()=>s(l)),l}setListStyle(t,e){var l,o;this.restoreSel();const i=window.getSelection();if(!i)return;let s=(l=this.closestBlock(i.anchorNode))==null?void 0:l.closest(t);s||(this.exec(t==="ol"?"insertOrderedList":"insertUnorderedList"),s=(o=this.closestBlock(i.anchorNode))==null?void 0:o.closest(t)),s&&(s.style.listStyleType=e),this.saveSel(),this.onChange()}listMenu(t,e){var c;const i=e==="ol"?"insertOrderedList":"insertUnorderedList",s=e==="ol"?[["lower-alpha",a.ol_alpha],["lower-roman",a.ol_roman],["upper-alpha",a.ol_alphau],["upper-roman",a.ol_romanu]]:[["circle",a.ul_circle],["square",a.ul_square]],l=this.tArr(e==="ol"?"liststyles_ol":"liststyles_ul").slice(1),o=window.getSelection(),n=o?(c=this.closestBlock(o.anchorNode))==null?void 0:c.closest(e):null,r=n?n.style.listStyleType:"";this.popup(t,h=>{this.menuItems(h,[{label:this.t(e==="ol"?"numlist":"bullist"),icon:e==="ol"?a.numlist:a.bullist,on:document.queryCommandState(i),action:()=>this.exec(i)}]),h.insertAdjacentHTML("beforeend",'<div class="sep"></div>');const d=document.createElement("div");d.className="mi-grid",s.forEach(([m,g],u)=>{const v=document.createElement("button");v.className="mi"+(r===m?" on":""),v.innerHTML=`<span class="ic">${g}</span><span class="prev">${l[u]}</span>`,v.addEventListener("click",()=>{this.closePop(),this.setListStyle(e,m)}),d.appendChild(v)}),h.appendChild(d)})}buildPaletteInto(t,e,i){const s=document.createElement("div");s.className="cpal",st.forEach(d=>{const m=document.createElement("button");m.type="button",m.style.background=d,m.title=d,m.addEventListener("click",()=>{this.closePop(),i(d)}),s.appendChild(m)}),t.appendChild(s),t.insertAdjacentHTML("beforeend",'<div class="sep"></div>');const l=document.createElement("div");l.className="cfoot";const o=/^#[0-9a-f]{6}$/i.test(e)?e:"#000000",n=document.createElement("div");n.className="cswatch cur",n.title=this.t("currentcolor"),n.style.background=o,n.innerHTML=a.check;const r=document.createElement("button");r.type="button",r.className="cswatch nocolor",r.title=this.t("removecolor"),r.addEventListener("click",()=>{this.closePop(),i(null)});const c=document.createElement("label");c.className="cswatch cwheel",c.title=this.t("customcolor"),c.innerHTML=a.palette;const h=document.createElement("input");h.type="color",h.value=o,h.addEventListener("change",()=>{this.closePop(),i(h.value)}),c.appendChild(h),l.append(n,r,c),t.appendChild(l)}colorMenu(t,e){this.popup(t,i=>{const s=e==="fore"?this.foreColor:this.backColor;this.buildPaletteInto(i,s,l=>this.applyColor(e,l))},e==="fore"?"pop-forecolor":"pop-backcolor")}applyColor(t,e){t==="fore"?(this.foreColor=e||"#000000",this.exec("foreColor",e||"#000000")):(this.backColor=e||"transparent",this.exec("hiliteColor",e||"transparent")),this.syncColorSwatches(this.toolbar),this.selCtx&&this.syncColorSwatches(this.selCtx)}syncColorSwatches(t){t.querySelectorAll("[data-cb=fore]").forEach(e=>e.style.background=this.foreColor),t.querySelectorAll("[data-cb=back]").forEach(e=>e.style.background=this.backColor)}fontItems(){return this.options.fontFamilyFormats.map(([t,e])=>({label:t,previewStyle:`font-family:${e}`,on:this.currentFont()===t,action:()=>this.exec("fontName",e)}))}fontMenu(t){this.popup(t,e=>this.menuItems(e,this.fontItems()))}sizeItems(){return it.map(t=>({label:t,on:this.currentSize()===t,action:()=>this.applyFontSize(t)}))}sizeMenu(t){this.popup(t,e=>this.menuItems(e,this.sizeItems()))}ensureSizeTarget(){const t=window.getSelection();if(!t)return;if(!t.rangeCount){const o=document.createRange();o.selectNodeContents(this.ed),o.collapse(!0),t.addRange(o)}if(!t.isCollapsed)return;const e=t.getRangeAt(0),i=e.startContainer;if(i.nodeType===3){const o=i.data;let n=e.startOffset,r=e.startOffset;for(;n>0&&/\S/.test(o[n-1]);)n--;for(;r<o.length&&/\S/.test(o[r]);)r++;if(r>n){const c=document.createRange();c.setStart(i,n),c.setEnd(i,r),t.removeAllRanges(),t.addRange(c),this.savedRange=c.cloneRange();return}}const s=document.createTextNode("​");e.insertNode(s);const l=document.createRange();l.setStart(s,0),l.setEnd(s,1),t.removeAllRanges(),t.addRange(l),this.savedRange=l.cloneRange()}applyFontSize(t){this.restoreSel(),this.ensureSizeTarget(),document.execCommand("styleWithCSS",!1,"false"),document.execCommand("fontSize",!1,"7");const e=[];if(this.ed.querySelectorAll('font[size="7"]').forEach(i=>{const s=document.createElement("span");for(s.style.fontSize=t;i.firstChild;)s.appendChild(i.firstChild);i.replaceWith(s),e.push(s)}),e.length){const i=document.createRange();i.setStart(e[0],0),i.setEnd(e[e.length-1],e[e.length-1].childNodes.length);const s=window.getSelection();s&&(s.removeAllRanges(),s.addRange(i))}this.saveSel(),this.refreshState(),this.onChange()}stepFontSize(t){const e=parseInt(this.currentSize(),10)||14,i=Math.min(dt,Math.max(ht,e+t));i!==e&&this.applyFontSize(i+"px")}transformCase(t){this.restoreSel();const e=window.getSelection();if(!e||!e.rangeCount||e.isCollapsed)return;const i=e.getRangeAt(0),s=document.createTreeWalker(this.ed,NodeFilter.SHOW_TEXT),l=[];let o;for(;o=s.nextNode();)i.intersectsNode(o)&&l.push(o);l.forEach(n=>{const r=n===i.startContainer?i.startOffset:0,c=n===i.endContainer?i.endOffset:n.data.length;if(c<=r)return;const h=n.data.slice(r,c);let d=h;t==="lower"?d=h.toLowerCase():t==="upper"?d=h.toUpperCase():d=h.replace(/(^|\s)(\S)/g,(m,g,u)=>g+u.toUpperCase()),n.replaceData(r,c-r,d)}),this.saveSel(),this.refreshState(),this.onChange()}caseItems(){return[{label:this.t("lowercase"),icon:a.lowercaseic,action:()=>this.transformCase("lower")},{label:this.t("uppercase"),icon:a.uppercaseic,action:()=>this.transformCase("upper")},{label:this.t("capitalize"),icon:a.capitalizeic,action:()=>this.transformCase("capitalize")}]}caseMenu(t){this.popup(t,e=>this.menuItems(e,this.caseItems()))}applyBlockStyle(t,e){this.restoreSel();const i=this.selectedBlocks(),s=t==="lineHeight"?"line-height":t==="wordSpacing"?"word-spacing":"letter-spacing";i.forEach(l=>{e?l.style[t]=e:l.style.removeProperty(s)}),this.saveSel(),this.onChange()}currentBlockStyle(t){const e=window.getSelection(),i=e?this.closestBlock(e.anchorNode):null;return i&&i.style[t]||""}blockStyleItems(t,e){const i=this.currentBlockStyle(t);return[{label:this.t("normal"),on:!i,action:()=>this.applyBlockStyle(t,"")},...e.map(s=>({label:s,on:i===s,action:()=>this.applyBlockStyle(t,s)}))]}lineHeightMenu(t){this.popup(t,e=>this.menuItems(e,this.blockStyleItems("lineHeight",V)))}wordSpacingMenu(t){this.popup(t,e=>this.menuItems(e,this.blockStyleItems("wordSpacing",W)))}letterSpacingMenu(t){this.popup(t,e=>this.menuItems(e,this.blockStyleItems("letterSpacing",j)))}closestAnchor(){const t=window.getSelection();let e=t&&this.ed.contains(t.anchorNode)?t.anchorNode:null;for(;e&&e!==this.ed;){if(e.nodeType===1&&e.tagName==="A")return e;e=e.parentNode}return null}linkDlg(){this.saveSel();const t=this.closestAnchor();let e;const i=[];t&&i.push({label:this.t("unlink"),action:()=>{const s=document.createRange();s.selectNodeContents(t);const l=window.getSelection();l&&(l.removeAllRanges(),l.addRange(s)),document.execCommand("unlink"),this.closeDlg(),this.onChange()}}),i.push({label:this.t("cancel"),action:()=>this.closeDlg()},{label:this.t("save"),primary:!0,action:()=>{const s=e.value.trim();if(this.closeDlg(),!s)return;if(t){t.setAttribute("href",s),this.onChange();return}this.restoreSel();const l=window.getSelection();!l||l.isCollapsed?document.execCommand("insertHTML",!1,`<a href="${s.replace(/"/g,"&quot;")}">${s.replace(/&/g,"&amp;").replace(/</g,"&lt;")}</a>`):(document.execCommand("styleWithCSS",!1,"false"),document.execCommand("createLink",!1,s)),this.saveSel(),this.onChange()}}),this.dialog(this.t("linkttl"),s=>{const l=document.createElement("div");l.style.cssText="display:flex;align-items:center;gap:10px;margin:10px 0;min-width:360px";const o=document.createElement("span");o.style.cssText="width:60px;color:#556;flex:none",o.textContent=this.t("linkurl"),e=document.createElement("input"),e.type="url",e.placeholder="https://",e.style.cssText="flex:1;border:1px solid #cfd6df;border-radius:6px;padding:7px 9px;font:14px inherit",e.value=(t==null?void 0:t.getAttribute("href"))||"",l.append(o,e),s.appendChild(l),setTimeout(()=>e.focus(),0)},i)}blockItems(){return $.map(([t])=>({label:this.blockLabel(t),previewStyle:t.startsWith("h")?`font-weight:700;font-size:${22-2*+t[1]}px`:t==="pre"?"font-family:monospace":"",on:this.currentBlock()===t,action:()=>this.exec("formatBlock","<"+t+">")}))}blocksMenu(t){this.popup(t,e=>this.menuItems(e,this.blockItems()))}alignItems(){return[["justifyLeft","alignleft",a.alignleft],["justifyCenter","aligncenter",a.aligncenter],["justifyRight","alignright",a.alignright],["justifyFull","alignjustify",a.alignjustify]].map(([e,i,s])=>({label:this.t(i),icon:s,on:document.queryCommandState(e),action:()=>this.exec(e)}))}blockLabel(t){return t==="p"?this.t("para"):t==="pre"?this.t("pre"):this.t("heading")+" "+t[1]}tableGrid(t,e){this.popup(t,i=>this.buildTableGridInto(i,e))}buildTableGridInto(t,e){{const i=document.createElement("div");i.className="tgridwrap";const s=document.createElement("div");s.className="tgrid";const l=document.createElement("div");l.className="tgridlbl",l.textContent="1 × 1";const o=[];for(let n=0;n<8;n++)for(let r=0;r<10;r++){const c=document.createElement("span");c.dataset.r=String(n),c.dataset.c=String(r),c.addEventListener("mouseenter",()=>{o.forEach(h=>h.classList.toggle("hot",+h.dataset.r<=n&&+h.dataset.c<=r)),l.textContent=r+1+" × "+(n+1)}),c.addEventListener("click",()=>{this.closePop(),this.insertTable(n+1,r+1),e==null||e()}),o.push(c),s.appendChild(c)}i.append(s,l),t.appendChild(i)}}insertTable(t,e){this.restoreSel();let i='<table style="border-collapse:collapse;width:100%;table-layout:fixed"><tbody>';for(let s=0;s<t;s++){i+="<tr>";for(let l=0;l<e;l++)i+='<td style="border:1px solid #b9c2cc"><br></td>';i+="</tr>"}i+="</tbody></table><p><br></p>",document.execCommand("insertHTML",!1,i),this.saveSel(),this.onChange()}setDir(t){this.restoreSel();const e=this.selectedBlocks();e.length?e.forEach(i=>i.setAttribute("dir",t)):this.ed.setAttribute("dir",t),this.saveSel(),this.refreshState(),this.onChange()}parseToolbarString(t){return t.split("|").map(e=>e.trim().split(/\s+/).filter(Boolean)).filter(e=>e.length>0)}buildToolbarRegistry(){const t=this.tbtn(a.tableic,this.t("quicktable"),()=>this.tableGrid(t)),e={undo:()=>this.tbtn(a.undo,this.t("undo"),()=>this.exec("undo")),redo:()=>this.tbtn(a.redo,this.t("redo"),()=>this.exec("redo")),preview:()=>this.tbtn(a.prevw,this.t("preview"),()=>this.previewDlg()),print:()=>this.tbtn(a.printic,this.t("print"),()=>this.printDoc()),importword:()=>this.tbtn(a.wordic,this.t("importword"),()=>this.pickWordDoc()),revhistory:()=>this.tbtn(a.historyic,this.t("revhistory"),()=>this.revisionDlg()),fontfamily:()=>this.tsel("w-font","fontsel","",i=>this.fontMenu(i)),fontsize:()=>this.tsel("w-size","sizesel","",i=>this.sizeMenu(i)),fontsizeincrease:()=>this.stepBtn(1),fontsizedecrease:()=>this.stepBtn(-1),bold:()=>this.tbtn(a.bold,this.t("bold"),()=>this.exec("bold"),"bold"),italic:()=>this.tbtn(a.italic,this.t("italic"),()=>this.exec("italic"),"italic"),underline:()=>this.tbtn(a.underline,this.t("underline"),()=>this.exec("underline"),"underline"),strikethrough:()=>this.tbtn(a.strikethrough,this.t("strikethrough"),()=>this.exec("strikeThrough"),"strikeThrough"),forecolor:()=>this.colorChips(),backcolor:()=>this.menuTbtn(a.backcolor+'<span class="colorbar" data-cb="back"></span>',this.t("backcolor"),i=>this.colorMenu(i,"back")),alignleft:()=>this.tbtn(a.alignleft,this.t("alignleft"),()=>this.exec("justifyLeft"),"justifyLeft"),aligncenter:()=>this.tbtn(a.aligncenter,this.t("aligncenter"),()=>this.exec("justifyCenter"),"justifyCenter"),alignright:()=>this.tbtn(a.alignright,this.t("alignright"),()=>this.exec("justifyRight"),"justifyRight"),alignjustify:()=>this.tbtn(a.alignjustify,this.t("alignjustify"),()=>this.exec("justifyFull"),"justifyFull"),bullist:()=>this.menuTbtn(a.bullist,this.t("bullist"),i=>this.listMenu(i,"ul"),"insertUnorderedList"),numlist:()=>this.menuTbtn(a.numlist,this.t("numlist"),i=>this.listMenu(i,"ol"),"insertOrderedList"),outdent:()=>this.tbtn(a.outdent,this.t("outdent"),()=>this.exec("outdent")),indent:()=>this.tbtn(a.indent,this.t("indent"),()=>this.exec("indent")),link:()=>this.tbtn(a.link,this.t("linkttl"),()=>this.linkDlg()),blockquote:()=>this.tbtn(a.quote,this.t("quote"),()=>this.toggleBlock("blockquote"),"blockquote"),code:()=>this.tbtn(a.inlinecodeic,this.t("code"),()=>this.toggleInlineCode(),"code"),codesample:()=>this.tbtn(a.codesampleic,this.t("codesample"),()=>this.codeDlg()),changecase:()=>this.menuTbtn(a.caseic,this.t("changecase"),i=>this.caseMenu(i)),lineheight:()=>this.menuTbtn(a.lineheight,this.t("lineheight"),i=>this.lineHeightMenu(i)),wordspacing:()=>this.menuTbtn(a.wordspacing,this.t("wordspacing"),i=>this.wordSpacingMenu(i)),letterspacing:()=>this.menuTbtn(a.letterspacing,this.t("letterspacing"),i=>this.letterSpacingMenu(i)),removeformat:()=>this.tbtn(a.clearformatic,this.t("removeformat"),()=>this.exec("removeFormat")),blocks:()=>this.tsel("w-block","blocksel",this.t("para"),i=>this.blocksMenu(i)),ltr:()=>this.tbtn(a.ltr,this.t("ltr"),()=>this.setDir("ltr"),"ltr"),rtl:()=>this.tbtn(a.rtl,this.t("rtl"),()=>this.setDir("rtl"),"rtl"),quickimage:()=>this.tbtn(a.image,this.t("quickimage"),()=>this.insertImagePlaceholder()),quickvideo:()=>this.tbtn(a.video,this.t("quickvideo"),()=>this.videoDlg()),quicktable:()=>t,template:()=>this.menuTbtn(a.templateic,this.t("template"),i=>this.templateMenu(i)),charmap:()=>this.tbtn(a.charic,this.t("charmap"),()=>this.charMap()),emoji:()=>this.tbtn(a.emojiic,this.t("emoji"),()=>this.emojiMap()),fullscreen:()=>this.tbtn(a.fullscreen,this.t("fullscreen"),()=>this.toggleFullscreen(),"fullscreen"),sourcecode:()=>this.tbtn(a.srcic,this.t("sourcecode"),()=>this.sourceDlg())};return e.styles=e.blocks,e.image=e.quickimage,e.media=e.quickvideo,e.table=e.quicktable,e}buildToolbar(){this.toolbar.innerHTML="";const t=this.options.toolbar===!0?at:this.options.toolbar,e=this.buildToolbarRegistry();this.parseToolbarString(t).forEach(i=>{const s=[];i.forEach(l=>{const o=e[l];if(!o){console.warn(`FableEditor: unknown toolbar item "${l}"`);return}const n=o();Array.isArray(n)?s.push(...n):s.push(n)}),s.length&&this.toolbar.appendChild(this.group(...s))}),this.tbrMore=this.tbtn(a.more,this.t("more"),()=>{this.tbrExpanded=!this.tbrExpanded,this.updateToolbarOverflow()}),this.tbrMore.classList.add("tbr-more"),this.toolbar.appendChild(this.tbrMore),this.syncColorSwatches(this.toolbar),this.updateToolbarOverflow()}updateToolbarOverflow(){const t=this.toolbar;if(!this.tbrMore)return;t.classList.add("tbr-measure");const e=t.scrollWidth>t.clientWidth+1;t.classList.remove("tbr-measure");const i=this.shell.offsetWidth<I.TBR_COLLAPSE_MAX;if(!e||!i){this.tbrExpanded=!1,t.classList.remove("collapsible","expanded"),this.tbrMore.classList.remove("on");return}t.classList.add("collapsible"),t.classList.toggle("expanded",this.tbrExpanded),this.tbrMore.classList.toggle("on",this.tbrExpanded)}mItem(t,e,i,s){return{label:this.t(t),icon:e,action:i,shortcut:s}}buildMenubar(){this.menubar.innerHTML="";const t={file:[this.mItem("newdoc",a.newic,()=>{this.recordRevision(),this.ed.innerHTML="<p><br></p>",this.onChange()}),"|",this.mItem("importword",a.wordic,()=>this.pickWordDoc()),this.mItem("restoredraft",a.draftic,()=>{this.restoreDraft()||alert(this.t("draftempty"))}),this.mItem("revhistory",a.historyic,()=>this.revisionDlg()),"|",this.mItem("preview",a.prevw,()=>this.previewDlg()),this.mItem("print",a.printic,()=>this.printDoc(),"Ctrl+P")],edit:[this.mItem("undo",a.undo,()=>this.exec("undo"),"Ctrl+Z"),this.mItem("redo",a.redo,()=>this.exec("redo"),"Ctrl+Y"),"|",this.mItem("cut",a.cutic,()=>this.exec("cut"),"Ctrl+X"),this.mItem("copy",a.copyic,()=>this.exec("copy"),"Ctrl+C"),this.mItem("paste",a.pasteic,()=>alert(this.t("pastehint")),"Ctrl+V"),"|",this.mItem("selectall",a.selall,()=>this.exec("selectAll"),"Ctrl+A")],view:[this.mItem("fullscreen",a.fullscreen,()=>this.toggleFullscreen()),this.mItem("preview",a.prevw,()=>this.previewDlg()),this.mItem("sourcecode",a.srcic,()=>this.sourceDlg())],insert:[this.mItem("link",a.link,()=>this.linkDlg()),this.mItem("image",a.image,()=>this.insertImagePlaceholder()),this.mItem("video",a.video,()=>this.videoDlg()),{label:this.t("inserttable"),icon:a.tableic,action:()=>this.tableGrid(this.menubar.querySelector('[data-menu-key="table"]')||this.menubar)},this.mItem("codesample",a.codesampleic,()=>this.codeDlg()),{label:this.t("template"),icon:a.templateic,subBuild:s=>this.buildTemplatePickInto(s)},this.mItem("hr",a.hric,()=>this.exec("insertHorizontalRule")),"|",this.mItem("charmap",a.charic,()=>this.charMap()),this.mItem("emoji",a.emojiic,()=>this.emojiMap()),this.mItem("datetime",a.dateic,()=>this.exec("insertText",new Date().toLocaleString(this.lang==="ar"?"ar-AE":"en-GB"))),"|",{label:this.t("pagebreak"),icon:a.pbic,action:()=>{this.restoreSel(),document.execCommand("insertHTML",!1,'<hr class="pagebreak"><p><br></p>'),this.onChange()}},this.mItem("nbsp",a.nbspic,()=>this.exec("insertText"," "))],format:[this.mItem("bold",a.bold,()=>this.exec("bold"),"Ctrl+B"),this.mItem("italic",a.italic,()=>this.exec("italic"),"Ctrl+I"),this.mItem("underline",a.underline,()=>this.exec("underline"),"Ctrl+U"),this.mItem("strikethrough",a.strikethrough,()=>this.exec("strikeThrough")),this.mItem("superscript",a.superscriptic,()=>this.exec("superscript")),this.mItem("subscript",a.subscriptic,()=>this.exec("subscript")),this.mItem("code",a.inlinecodeic,()=>this.toggleInlineCode()),this.mItem("quote",a.quote,()=>this.toggleBlock("blockquote")),"|",{label:this.t("fontfamily"),subBuild:s=>this.menuItems(s,this.fontItems())},{label:this.t("fontsize"),subBuild:s=>this.menuItems(s,this.sizeItems())},{label:this.t("blocks"),subBuild:s=>this.menuItems(s,this.blockItems())},{label:this.t("align"),subBuild:s=>this.menuItems(s,this.alignItems())},{label:this.t("lineheight"),icon:a.lineheight,subBuild:s=>this.menuItems(s,this.blockStyleItems("lineHeight",V))},{label:this.t("wordspacing"),icon:a.wordspacing,subBuild:s=>this.menuItems(s,this.blockStyleItems("wordSpacing",W))},{label:this.t("letterspacing"),icon:a.letterspacing,subBuild:s=>this.menuItems(s,this.blockStyleItems("letterSpacing",j))},"|",{label:this.t("forecolor"),icon:a.palette,subBuild:s=>this.buildPaletteInto(s,this.foreColor,l=>this.applyColor("fore",l))},{label:this.t("backcolor"),icon:a.backcolor,subBuild:s=>this.buildPaletteInto(s,this.backColor,l=>this.applyColor("back",l))},"|",this.mItem("bullist",a.bullist,()=>this.exec("insertUnorderedList")),this.mItem("numlist",a.numlist,()=>this.exec("insertOrderedList")),this.mItem("outdent",a.outdent,()=>this.exec("outdent")),this.mItem("indent",a.indent,()=>this.exec("indent")),"|",this.mItem("ltr",a.ltr,()=>this.setDir("ltr")),this.mItem("rtl",a.rtl,()=>this.setDir("rtl")),"|",{label:this.t("changecase"),icon:a.caseic,sub:this.caseItems()},"|",this.mItem("clearformat",a.clearformatic,()=>this.exec("removeFormat"))],tools:[this.mItem("sourcecode",a.srcic,()=>this.sourceDlg()),this.mItem("wordcount",a.wcic,()=>this.wordCountDlg())],table:[{label:this.t("inserttable"),icon:a.tableic,subBuild:s=>this.buildTableGridInto(s)},"|",{label:this.t("cell"),sub:[{label:this.t("cellprops"),icon:a.tableic,action:()=>this.cellPropsDlg()},{label:this.t("cellbg"),icon:a.palette,subBuild:s=>this.buildCellFillInto(s)}]},{label:this.t("row"),sub:[{label:this.t("rowabove"),icon:a.rowbefore,action:()=>this.tableOp("rowabove"),hover:s=>this.setOpTarget(s?"row":null)},{label:this.t("rowbelow"),icon:a.rowafter,action:()=>this.tableOp("rowbelow"),hover:s=>this.setOpTarget(s?"row":null)},{label:this.t("delrow"),icon:a.rowdelete,action:()=>this.tableOp("delrow"),hover:s=>this.setOpTarget(s?"row":null)},"|",{label:this.t("moverowup"),icon:a.moverowup,action:()=>this.tableMove("rowup"),hover:s=>this.setOpTarget(s?"row":null)},{label:this.t("moverowdown"),icon:a.moverowdown,action:()=>this.tableMove("rowdown"),hover:s=>this.setOpTarget(s?"row":null)},"|",{label:this.t("rowprops"),icon:a.tableic,action:()=>this.rowPropsDlg(),hover:s=>this.setOpTarget(s?"row":null)}]},{label:this.t("column"),sub:[{label:this.t("colbefore"),icon:a.colbefore,action:()=>this.tableOp("colbefore"),hover:s=>this.setOpTarget(s?"col":null)},{label:this.t("colafter"),icon:a.colafter,action:()=>this.tableOp("colafter"),hover:s=>this.setOpTarget(s?"col":null)},{label:this.t("delcol"),icon:a.coldelete,action:()=>this.tableOp("delcol"),hover:s=>this.setOpTarget(s?"col":null)},"|",{label:this.t("movecolleft"),icon:a.movecolleft,action:()=>this.tableMove("colleft"),hover:s=>this.setOpTarget(s?"col":null)},{label:this.t("movecolright"),icon:a.movecolright,action:()=>this.tableMove("colright"),hover:s=>this.setOpTarget(s?"col":null)},"|",{label:this.t("colprops"),icon:a.tableic,action:()=>this.colPropsDlg(),hover:s=>this.setOpTarget(s?"col":null)}]},"|",{label:this.t("tablepropsttl"),icon:a.tableic,action:()=>{const s=this.currentCell();if(!s){alert(this.t("nocell"));return}this.tblActive=s.closest("table"),this.tablePropsDlg()}},{label:this.t("deltable"),icon:a.trash,action:()=>this.tableOp("deltable")}],help:[this.mItem("helpttl",a.helpic,()=>this.helpDlg(),"Alt+0")]},e=this.options.menubar===!0?ct:this.options.menubar,i=new Set;e.split(/\s+/).filter(Boolean).forEach(s=>{if(i.has(s))return;if(i.add(s),!t[s]){console.warn(`FableEditor: unknown menubar item "${s}"`);return}const l=document.createElement("button");l.type="button",l.textContent=this.t(s),l.dataset.menuKey=s,l.addEventListener("mousedown",o=>{o.preventDefault(),this.saveSel()}),l.addEventListener("click",()=>this.popup(l,o=>this.menuItems(o,t[s]))),this.menubar.appendChild(l)})}tableOp(t){var r,c,h;this.restoreSel();const e=window.getSelection();if(!e)return;const i=((r=this.closestBlock(e.anchorNode))==null?void 0:r.closest("td,th"))||(e.anchorNode&&e.anchorNode.nodeType===1?(h=(c=e.anchorNode).closest)==null?void 0:h.call(c,"td,th"):null);if(!i)return;const s=i.parentElement,l=i.closest("table"),o=Array.from(s.children).indexOf(i),n=()=>{const d=s.cloneNode(!1);return Array.from(s.children).forEach(m=>{const g=document.createElement("td"),u=m.getAttribute("style");u&&g.setAttribute("style",u),g.style.removeProperty("background-color"),g.innerHTML="<br>",d.appendChild(g)}),d};if(t==="rowabove"&&s.before(n()),t==="rowbelow"&&s.after(n()),t==="delrow"){const d=s.parentElement;s.remove(),d.querySelector("tr")||l.remove()}(t==="colbefore"||t==="colafter")&&l.querySelectorAll("tr").forEach(d=>{const m=d.children[Math.min(o,d.children.length-1)],g=document.createElement("td"),u=m.getAttribute("style");u&&g.setAttribute("style",u),g.style.removeProperty("width"),g.style.removeProperty("background-color"),g.innerHTML="<br>",t==="colbefore"?m.before(g):m.after(g)}),t==="delcol"&&(l.querySelectorAll("tr").forEach(d=>{var m;return(m=d.children[o])==null?void 0:m.remove()}),l.querySelector("td,th")||l.remove()),t==="deltable"&&l.remove(),this.onChange(),this.positionTableHandles()}tableMove(t){this.restoreSel();const e=this.currentCell();if(!e)return;const i=e.parentElement,s=e.closest("table"),l=Array.from(i.children).indexOf(e);if(t==="rowup"){const r=i.previousElementSibling;r&&r.before(i)}if(t==="rowdown"){const r=i.nextElementSibling;r&&r.after(i)}t==="colleft"&&l>0&&s.querySelectorAll("tr").forEach(r=>{const c=r.children[l],h=r.children[l-1];c&&h&&h.before(c)}),t==="colright"&&s.querySelectorAll("tr").forEach(r=>{const c=r.children[l],h=r.children[l+1];c&&h&&h.after(c)});const o=document.createRange();o.selectNodeContents(e),o.collapse(!0);const n=window.getSelection();n&&(n.removeAllRanges(),n.addRange(o)),this.saveSel(),this.onChange(),this.positionTableHandles(),this.positionCellMarker()}alignTable(t){const e=this.tblActive;e&&(e.style.marginLeft=t==="left"?"0":"auto",e.style.marginRight=t==="right"?"0":"auto",this.onChange(),this.positionTableHandles())}buildCellFillInto(t){const e=s=>{const l=this.currentCell();if(!l){alert(this.t("nocell"));return}this.setOrClear(l,"background-color",s||""),this.onChange()},i=this.currentCell();this.buildPaletteInto(t,this.cssToHex(i?i.style.backgroundColor:""),e)}cssToHex(t){const e=t.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);return e?"#"+e.slice(1,4).map(i=>(+i).toString(16).padStart(2,"0")).join(""):t}cellFillMenu(t){this.popup(t,e=>this.buildCellFillInto(e),"pop-cellbg")}applyTableProps(t,e){e.width?t.style.width=/^\d+$/.test(e.width)?e.width+"px":e.width:t.style.removeProperty("width");const i=Array.from(t.querySelectorAll("td,th"));e.cellpadding!==""?i.forEach(s=>s.style.padding=e.cellpadding+"px"):i.forEach(s=>s.style.removeProperty("padding")),e.cellspacing!==""?(t.style.borderCollapse="separate",t.style.borderSpacing=e.cellspacing+"px"):(t.style.borderCollapse="collapse",t.style.removeProperty("border-spacing")),e.border!==""&&+e.border>0?(t.style.border=e.border+"px solid #b9c2cc",i.forEach(s=>s.style.border=e.border+"px solid #b9c2cc")):(t.style.removeProperty("border"),i.forEach(s=>s.style.removeProperty("border"))),t.style.removeProperty("margin-left"),t.style.removeProperty("margin-right"),e.align==="center"?(t.style.marginLeft="auto",t.style.marginRight="auto"):e.align==="right"?(t.style.marginLeft="auto",t.style.marginRight="0"):e.align==="left"&&(t.style.marginLeft="0",t.style.marginRight="auto")}tablePropsDlg(){const t=this.tblActive;if(!t)return;let e,i,s,l,o;const n="display:flex;align-items:center;gap:10px;margin:10px 0",r="width:120px;color:#556;flex:none",c="flex:1;border:1px solid #cfd6df;border-radius:6px;padding:7px 9px;font:14px inherit",h=t.querySelector("td,th"),d=t.style.width||"",m=h&&h.style.padding?parseFloat(h.style.padding):"",g=t.style.borderSpacing?parseFloat(t.style.borderSpacing):"",u=t.style.borderWidth?parseFloat(t.style.borderWidth):"",v=t.style.marginLeft,b=t.style.marginRight,x=v==="auto"&&b==="auto"?"center":v==="auto"?"right":b==="auto"&&v==="0"?"left":"";this.dialog(this.t("tablepropsttl"),C=>{const S=(w,k)=>{const L=document.createElement("div");L.style.cssText=n;const H=document.createElement("span");H.style.cssText=r,H.textContent=this.t(w),L.append(H,k),C.appendChild(L)};e=document.createElement("input"),e.type="text",e.style.cssText=c,e.placeholder="e.g. 600px or 100%",e.value=d,S("tblwidth",e),i=document.createElement("input"),i.type="number",i.min="0",i.style.cssText=c,i.value=String(m),S("tblcellpadding",i),s=document.createElement("input"),s.type="number",s.min="0",s.style.cssText=c,s.value=String(g),S("tblcellspacing",s),l=document.createElement("input"),l.type="number",l.min="0",l.style.cssText=c,l.value=String(u),S("tblborder",l),o=document.createElement("select"),o.style.cssText=c,[["","alignnone"],["left","alignleft"],["center","aligncenter"],["right","alignright"]].forEach(([w,k])=>{const L=document.createElement("option");L.value=w,L.textContent=this.t(k),w===x&&(L.selected=!0),o.appendChild(L)}),S("tblalign",o)},[{label:this.t("cancel"),action:()=>this.closeDlg()},{label:this.t("save"),primary:!0,action:()=>{this.applyTableProps(t,{width:e.value.trim(),cellpadding:i.value.trim(),cellspacing:s.value.trim(),border:l.value.trim(),align:o.value}),this.closeDlg(),this.onChange(),this.positionTableHandles()}}])}currentCell(){let t=this.savedRange?this.savedRange.startContainer:null;if(!t||!this.ed.contains(t)){const e=window.getSelection();t=e&&this.ed.contains(e.anchorNode)?e.anchorNode:null}for(;t&&t!==this.ed;){if(t.nodeType===1&&/^(TD|TH)$/.test(t.tagName))return t;t=t.parentNode}return null}toHexColor(t){if(/^#[0-9a-fA-F]{6}$/.test(t))return t;const e=/rgba?\((\d+)[,\s]+(\d+)[,\s]+(\d+)/.exec(t);return e?"#"+[e[1],e[2],e[3]].map(i=>(+i).toString(16).padStart(2,"0")).join(""):""}formRow(t,e,i){const s=document.createElement("div");s.style.cssText="display:flex;align-items:center;gap:10px;margin:10px 0;min-width:360px";const l=document.createElement("span");l.style.cssText="width:120px;color:#556;flex:none",l.textContent=e,s.append(l,i),t.appendChild(s)}formInput(t,e=""){const i=document.createElement("input");return i.type="text",i.style.cssText="flex:1;border:1px solid #cfd6df;border-radius:6px;padding:7px 9px;font:14px inherit;min-width:0",i.value=t,i.placeholder=e,i}formSelect(t,e){const i=document.createElement("select");return i.style.cssText="flex:1;border:1px solid #cfd6df;border-radius:6px;padding:7px 9px;font:14px inherit;background:#fff",t.forEach(([s,l])=>{const o=document.createElement("option");o.value=s,o.textContent=l,s===e&&(o.selected=!0),i.appendChild(o)}),i}formBg(t){const e=document.createElement("div");e.style.cssText="flex:1;display:flex;align-items:center;gap:8px";const i=this.toHexColor(t),s=document.createElement("input");s.type="color",s.value=i||"#ffffff",s.style.cssText="width:36px;height:29px;border:1px solid #cfd6df;border-radius:4px;padding:1px;background:none;cursor:pointer";const l=document.createElement("label");l.style.cssText="display:flex;align-items:center;gap:6px;cursor:pointer;color:#556";const o=document.createElement("input");return o.type="checkbox",o.checked=!!i,l.append(o,document.createTextNode(this.t("fill"))),s.addEventListener("input",()=>o.checked=!0),e.append(s,l),{wrap:e,color:s,fill:o}}setOrClear(t,e,i){i?t.style.setProperty(e,/^(width|height)$/.test(e)&&/^\d+$/.test(i)?i+"px":i):t.style.removeProperty(e)}cellPropsDlg(){const t=this.currentCell();if(!t){alert(this.t("nocell"));return}let e,i,s,l,o;this.dialog(this.t("cellprops").replace("…",""),n=>{e=this.formInput(t.style.width,"e.g. 120px / 25%"),this.formRow(n,this.t("tblwidth"),e),i=this.formInput(t.style.height,"e.g. 40px"),this.formRow(n,this.t("tblheight"),i),s=this.formSelect([["",this.t("alignnone")],["left",this.t("alignleft")],["center",this.t("aligncenter")],["right",this.t("alignright")]],t.style.textAlign||""),this.formRow(n,this.t("tblalign"),s),l=this.formSelect([["",this.t("alignnone")],["top",this.t("valigntop")],["middle",this.t("valignmiddle")],["bottom",this.t("valignbottom")]],t.style.verticalAlign||""),this.formRow(n,this.t("valign"),l),o=this.formBg(t.style.backgroundColor||""),this.formRow(n,this.t("backcolor"),o.wrap)},[{label:this.t("cancel"),action:()=>this.closeDlg()},{label:this.t("save"),primary:!0,action:()=>{this.setOrClear(t,"width",e.value.trim()),this.setOrClear(t,"height",i.value.trim()),this.setOrClear(t,"text-align",s.value),this.setOrClear(t,"vertical-align",l.value),this.setOrClear(t,"background-color",o.fill.checked?o.color.value:""),this.closeDlg(),this.onChange(),this.positionTableHandles()}}])}rowPropsDlg(){const t=this.currentCell();if(!t){alert(this.t("nocell"));return}const e=t.parentElement;let i,s;this.dialog(this.t("rowprops").replace("…",""),l=>{i=this.formInput(e.style.height,"e.g. 40px"),this.formRow(l,this.t("tblheight"),i),s=this.formBg(e.style.backgroundColor||""),this.formRow(l,this.t("backcolor"),s.wrap)},[{label:this.t("cancel"),action:()=>this.closeDlg()},{label:this.t("save"),primary:!0,action:()=>{this.setOrClear(e,"height",i.value.trim()),this.setOrClear(e,"background-color",s.fill.checked?s.color.value:""),this.closeDlg(),this.onChange(),this.positionTableHandles()}}])}colPropsDlg(){const t=this.currentCell();if(!t){alert(this.t("nocell"));return}const e=t.parentElement,i=t.closest("table"),s=Array.from(e.children).indexOf(t),l=Array.from(i.rows).map(r=>r.cells[s]).filter(Boolean);let o,n;this.dialog(this.t("colprops").replace("…",""),r=>{o=this.formInput(t.style.width,"e.g. 120px / 25%"),this.formRow(r,this.t("tblwidth"),o),n=this.formBg(t.style.backgroundColor||""),this.formRow(r,this.t("backcolor"),n.wrap)},[{label:this.t("cancel"),action:()=>this.closeDlg()},{label:this.t("save"),primary:!0,action:()=>{l.forEach(r=>{this.setOrClear(r,"width",o.value.trim()),this.setOrClear(r,"background-color",n.fill.checked?n.color.value:"")}),this.closeDlg(),this.onChange(),this.positionTableHandles()}}])}closeDlg(){this.dlgOvl&&(this.dlgOvl.remove(),this.dlgOvl=null)}dialog(t,e,i){this.closeDlg(),this.closePop(),this.dlgOvl=document.createElement("div"),this.dlgOvl.className="ovl";const s=document.createElement("div");s.className="dlg",s.dir=this.dir(),s.innerHTML=`<header><span>${t}</span><button type="button">×</button></header>
8
8
  <div class="body"></div><footer></footer>`,s.querySelector("header button").onclick=()=>this.closeDlg(),e(s.querySelector(".body")),(i||[{label:this.t("close"),primary:!0,action:()=>this.closeDlg()}]).forEach(l=>{const o=document.createElement("button");o.type="button",o.textContent=l.label,l.primary&&(o.className="pri"),o.onclick=l.action,s.querySelector("footer").appendChild(o)}),this.dlgOvl.appendChild(s),this.dlgOvl.addEventListener("mousedown",l=>{l.target===this.dlgOvl&&this.closeDlg()}),document.body.appendChild(this.dlgOvl)}sourceDlg(){let t;this.dialog(this.t("srcttl"),e=>{t=document.createElement("textarea"),t.value=this.ed.innerHTML.replace(/></g,`>
9
9
  <`),e.appendChild(t)},[{label:this.t("cancel"),action:()=>this.closeDlg()},{label:this.t("save"),primary:!0,action:()=>{this.ed.innerHTML=t.value,this.closeDlg(),this.onChange()}}])}helpDlg(){this.dialog(this.t("helpttl"),t=>{const e=[["Ctrl+B",this.t("bold")],["Ctrl+I",this.t("italic")],["Ctrl+U",this.t("underline")],["Ctrl+Z",this.t("undo")],["Ctrl+Y",this.t("redo")],["Ctrl+A",this.t("selectall")],["Alt+0",this.t("helpttl")]];t.innerHTML=`<p style="color:#556">${this.t("shortcuts")}</p>
10
10
  <table class="kbd">${e.map(i=>`<tr><td>${i[1]}</td><td><kbd>${i[0]}</kbd></td></tr>`).join("")}</table>`})}wordCountDlg(){this.dialog(this.t("wcttl"),t=>{var e;t.innerHTML=`<table class="kbd">
@@ -2533,7 +2533,7 @@ const I = class I {
2533
2533
  }), this.onWin(
2534
2534
  "scroll",
2535
2535
  () => {
2536
- this.positionTableHandles(), this.positionImageHandles(), this.positionImgPhCtx(), this.positionTplCtx(), this.positionVphCtx(), this.positionVidCtx(), this.positionCodeCtx(), this.repositionSelToolbar();
2536
+ this.closePop(), this.positionTableHandles(), this.positionImageHandles(), this.positionImgPhCtx(), this.positionTplCtx(), this.positionVphCtx(), this.positionVidCtx(), this.positionCodeCtx(), this.repositionSelToolbar();
2537
2537
  },
2538
2538
  !0
2539
2539
  ), this.onWin("resize", () => {