@ones-editor/editor 0.0.3-beta.242 → 0.0.3-beta.244

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -429,7 +429,7 @@ ${s}
429
429
  \`\`\`
430
430
  ${l}`:`<p><pre><code>${s}</code></pre></p>
431
431
  <p>${l}</p>`}const q0={blockType:"code",blockKind:"complex",createBlockContent:ZP,getBlockTextLength:QP,getRangeFromPoint:YP,moveCaret:JP,getCaretRect:KP,updateSelection:XP,clearSelection:eN,getChildContainers:tN,getNextContainer:nN,getSelectedContainers:oN,convertFrom:AP,handleBlockElementUpdated:rN,getOptions:sN,getBlockProperties:lN,convertTo:cN},G0={...Dn,blockType:"code-line"};class aN{constructor(e){m(this,"handleSelectionChange",()=>{const e=this.editor.selection;if(!e.range.isCollapsed())return;const t=e.focusedBlock;if(!Bc(this.editor,t))return;const o=t,r=e.range.focus.offset,i=O4(this.editor,o,r,"code-caret");i.scrollIntoView({block:"nearest"}),setTimeout(()=>{i.remove(),this.editor.selection.caret.update()})});this.editor=e,e.addListener("selectionChanged",this.handleSelectionChange)}destroy(){this.editor.removeListener("selectionChanged",this.handleSelectionChange)}}function v9(n,e){const t=n.split(`
432
- `).map(s=>({id:K(),type:"text",text:Pi(s)})),o=K();return{blocks:{root:[{children:[o],type:"code",id:K(),...e}],[o]:t},meta:{},comments:{}}}class uN{handleBeforeCopy(e,t,o){const r=e.getFocusedBlock();if(!Bc(e,r))return;const i=N0(r),s=e.getBlockData(i),{language:l,nowrap:a}=s;if(e.selection.range.isCollapsed()){const h=e.getBlockString(r);return v9(h,{language:l,nowrap:a})}const d=e.getSelectedText();return v9(d,{language:l,nowrap:a})}}function dN(n){if(!n.isWritable())return!1;const e=n.getFocusedBlock();if(!!Bc(n,e)){if(n.selection.range.isCollapsed()){const t=n.selection.range.start;return n.insertTextToBlock(e,t.offset," "),!0}return n.undoManager.runInGroup(()=>{lr(n).forEach(o=>{n.insertTextToBlock(o.block,0," ")})}),!0}}function hN(n){if(!n.isWritable())return!1;const e=n.getFocusedBlock();if(!Bc(n,e))return;const t=[" "," "];return n.undoManager.runInGroup(()=>{lr(n).forEach(r=>{const i=st(n.getBlockText(r.block));for(let s=0;s<t.length;s++){const l=t[s];if(i.startsWith(l)){n.deleteTextFromBlock(r.block,0,l.length);break}}})}),!0}function fN(n){const e=n.getFocusedBlock(),t=oe(e);if(Ge(t))return;const o=ne(t);if(!o||De(o)!=="code")return;const r=n.selection.range;if(!!r.isSimple()&&!OA(t,r))return Xg(n,t),!0}const mN={Tab:dN,"Shift+Tab":hN,"CtrlOrCmd+A":fN},xu=S("code-text-decorate");class Nf{decorateText(e,t,o){var v;if(g(xu,t.length>0,"invalid path"),t.length===1)return{};const r=t[t.length-2];if(e.doc.getBlockData(r.containerId,r.blockIndex).type!=="code")return{};const s=o;if(s.length===0)return{};const l=st(s),a=e.doc.getBlockData(r.containerId,r.blockIndex),d=ga.default.tokenize(l,(v=ga.default.languages[a.language])!=null?v:ga.default.languages.plain),h=(B,D)=>{if(g(xu,B,"no token"),typeof B=="string")return[{insert:B,attributes:me.default(D)}];g(xu,B instanceof ga.default.Token,"invalid token type");const x=B.content,_=me.default(D);return _[`style-code-${B.type}`]=!0,typeof x=="string"?[{insert:x,attributes:_}]:Array.isArray(x)?x.map(z=>h(z,_)).flat():(g(xu,x instanceof ga.default.Token,"invalid token"),h(x,_))},C=d.map(B=>h(B,{})).flat();return g(xu,rn(C)===rn(s),"failed to highlight code, text length mismatch"),{text:C}}}const gN={code:{title:"\u4EE3\u7801",abstract:"\u4EE3\u7801",wrap:"\u6362\u884C",copy:"\u590D\u5236",caption:"\u8BF4\u660E",search:"\u8F93\u5165\u5173\u952E\u8BCD\u641C\u7D22",copySuccess:"\u590D\u5236\u6210\u529F"}},pN={code:{title:"Code",abstract:"Code",wrap:"Wrap",copy:"Copy",caption:"Caption",search:"Search",copySuccess:"Copied successfully"}},CN={code:{title:"\u30B3\u30FC\u30C9",abstract:"\u30B3\u30FC\u30C9",wrap:"\u6298\u308A\u8FD4\u3059",copy:"\u8907\u88FD",caption:"\u4F8B\u8A3C\u3059\u308B",search:"\u30AD\u30FC\u30EF\u30FC\u30C9\u3067\u691C\u7D22",copySuccess:"\u30B3\u30D4\u30FC\u3055\u308C\u307E\u3057\u305F"}};L.mergeLang({"zh-CN":gN,"en-US":pN,"ja-JP":CN});function AN(n,e,t,o){const r=n.getBlockByIndex(e,t);if(ue(n,r)!==o)return!1;const i=st(n.getBlockText(r));if(![...i].every(h=>h==="|")||i.length<3||!n.editorBlocks.hasBlock("table"))return!1;const s=n.editorBlocks.getBlockClass("table");if(!s.convertFrom)return!1;const l=s.convertFrom(n,r,{offset:o});if(!l)return!1;const{blockData:a,focusBlockId:d}=l;return a?(n.undoManager.runInGroup(()=>{var p;const h=n.insertBlock(e,t,a,kt(n,d!=null?d:a.id,0));n.deleteBlock(r),(p=l.onConverted)==null||p.call(l,n,h)}),!0):!1}const bN={mermaid:{blockType:"embed",reg:/^```mermaid$/,data:{embedType:"mermaid"}},flowchart:{blockType:"embed",reg:/^```flowchart$/,data:{embedType:"flowchart"}},plantuml:{blockType:"embed",reg:/^```plantuml$/,data:{embedType:"plantuml"}},code:{blockType:"code",reg:/^```\S+$/},code2:{blockType:"code",reg:/^```$/},table:{blockType:"table",reg:/^\|.+\|.+\|$/},math:{blockType:"embed",reg:/^\$\$.+\$\$$/},image:{blockType:"embed",reg:/^!\[[^\]]*\]\((?<filename>.*?)(?="|\))(?<optionalPart>".*")?\)/,data:{embedType:"image"}},dividing:{blockType:"embed",reg:/^-{3,}$/,data:{embedType:"dividing-line"}},toc:{blockType:"embed",reg:/^\[toc\]/,data:{embedType:"toc"}}},vN={orderedList:{reg:/^(\d)+(\.|。)$/,blockType:"list",data:{listType:"ordered"}},unorderedList1:{reg:/^\*$/,blockType:"list",data:{listType:"unordered"}},unorderedList2:{reg:/^-$/,blockType:"list",data:{listType:"unordered"}},checkList1:{reg:/^\[\s?\]$/,blockType:"list",data:{listType:"unchecked"}},checkList2:{reg:/^\[X\]$/i,blockType:"list",data:{listType:"checked"}},image:{blockType:"embed",reg:/^!\[[^\]]*\]\((?<filename>.*?)(?="|\))(?<optionalPart>".*")?\)/,data:{embedType:"image"}}};function $f(n,e,t,o,r){const i=n.getContainerById(e);if(!Ge(i)){const s=ne(i);if(s&&br(s))return!0}return!1}function y9(n,e,t,o,r){if($f(n,e))return!1;if(r==="enter"&&AN(n,e,t,o))return!0;const i=n.getBlockByIndex(e,t),s=st(Tn(n.getBlockText(i),o).left).trim(),l=r==="enter"?bN:vN;for(const[,a]of Object.entries(l)){if(!s.match(a.reg))continue;return!!n.undoManager.runInGroup(()=>{var B;const h=ah(n,i,a.blockType,{offset:o,data:a.data});if(!h)return null;const{blockData:p,focusBlockId:C}=h;if(!p)return null;const v=n.insertBlock(e,t,p,kt(n,C!=null?C:p.id,0));return n.deleteBlock(i),(B=h.onConverted)==null||B.call(h,n,v),{newBlock:v,focusBlockId:C}})}return!1}function yN(n,e,t,o){const r=n.getBlockByIndex(e,t);return n.getBlockString(r,{boxReplacement:" "}).substring(0,o)!==">"?!1:(n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,0,o+1),n.updateBlockData(r,{quoted:!0},kt(n,r,0))}),!0)}const kN={"#":1,"##":2,"###":3,"####":4,"#####":5,"######":6,"#######":7,"########":8};function wN(n,e,t,o){const r=n.getBlockByIndex(e,t),i=n.getBlockString(r,{boxReplacement:" "}).substring(0,o);let s=kN[i];if(!s)return!1;const l=n.getBlockData(r).heading;return l&&l==s&&(s=null),n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,0,o+1),n.updateBlockData(r,{heading:s},kt(n,r,0))}),!0}function BN(n,e,t,o){return!!(wN(n,e,t,o)||yN(n,e,t,o))}const EN=S("match-text-style");function xN(n,e){if(n.length<e.length*2+1||!n.endsWith(e)||n.substring(0,n.length-1).endsWith(e))return-1;const t=n.substring(0,n.length-e.length),o=t.lastIndexOf(e);return o===-1?-1:o===0?0:t.substring(o-1).startsWith(e)?-1:o}const IN={"*":{type:"style",styles:["style-italic"],boxType:""},"**":{type:"style",styles:["style-bold"],boxType:""},"***":{type:"style",styles:["style-bold","style-italic"],boxType:""},"~~":{type:"style",styles:["style-strikethrough"],boxType:""},"`":{type:"style",styles:["style-code"],boxType:""},$$:{type:"box",styles:[],boxType:"math"}};function TN(n,e,t,o){var C,v;const r=n.getBlockByIndex(e,t),i=n.getBlockText(r),{left:s}=Tn(i,o),l=bg(s),a=rn(s)-l.length,d=Object.entries(IN);for(const[B,D]of d){const x=xN(l,B);if(x===-1)continue;const _=a+x,R=o,H=B.length,z=st(Vt(i,_+H,R-_-H*2).middle);if(D.type==="style"){const Z={};D.styles.forEach(fe=>{Z[fe]=!0});const ee=Pi(z,Z);n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,_,R-_),n.insertTextToBlock(r,_,ee)})}else if(D.type==="box")try{const Z=(v=(C=n.editorBoxes.getBoxClass(D.boxType)).convertFrom)==null?void 0:v.call(C,n,z);if(!Z)continue;n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,_,R-_),n.insertBoxToBlock(r,_,Z)})}catch(Z){EN.warn(`failed to convert to box, ${Z.message}`);continue}return!0}const h=/\[([^\]]+)\]\((https?:\/\/\S+)\)\s*$/,p=l.match(h);if(p){const B=p.index,D=p[1],x=p[2],_=B,R=o,z={..._a(i,_),link:x};return n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,_,R-_),n.insertTextToBlock(r,_,Pi(D,z))}),!0}return!1}class Hf{handleAfterInsertText(e,t,o,r,i){if(i===" "){if($f(e,t))return!1;if(BN(e,t,o,r)||TN(e,t,o,r))return!0}return!1}handleBeforeKeyDown(e,t){if(!e.selection.range.isSimple())return!1;const{containerId:r,blockIndex:i,offset:s}=e.getTextPosition();if(te(e,e.getBlockByIndex(r,i))){if(or(t,"Enter")){if(y9(e,r,i,s,"enter"))return!0}else if(or(t,"Space")&&y9(e,r,i,s,"space"))return!0}return!1}}const DN={"en-US":{placeholder:{default:"Type / for commands",heading:"Heading {heading}",list:"List",mention:"Quickly assign tasks and use @ to mention yourself or others",quote:"Quote",title:"Enter document title"}},"zh-CN":{placeholder:{default:"\u8F93\u5165\u300C/\u300D\u5FEB\u901F\u63D2\u5165",heading:"\u6807\u9898{heading}",list:"\u5217\u8868",mention:"\u5FEB\u901F\u5206\u914D\u4EFB\u52A1\uFF0C@\u63D0\u53CA\u81EA\u5DF1\u6216\u4ED6\u4EBA",quote:"\u5F15\u7528",title:"\u8BF7\u8F93\u5165\u6587\u6863\u6807\u9898"}},"ja-JP":{placeholder:{default:"\u300C/\u300D\u3092\u5165\u529B\u3057\u3066\u7D20\u65E9\u304F\u633F\u5165\u3059\u308B",heading:"\u898B\u51FA\u3057{heading}",list:"\u30EA\u30B9\u30C8",mention:"\u81EA\u5206\u3084\u30E1\u30F3\u30D0\u30FC\u3092\uFF20\u3057\u3001\u30BF\u30B9\u30AF\u3092\u7D20\u65E9\u304F\u5272\u308A\u5F53\u3066\u307E\u3059",quote:"\u5F15\u7528",title:"\u30BF\u30A4\u30C8\u30EB\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"}}};L.mergeLang(DN);function Iu(n,e){const t=Ni(n,e);return!!(t.text&&rn(t.text)===0&&!e.querySelector(".inputting-insertion"))}function k9(n,e){var o;Le(e).removeAttribute("data-content-placeholder"),(o=e.querySelector("[data-type=block-tools] .block-placeholder-container"))==null||o.remove()}function jf(n,e,t){var r;if(!Iu(n,e)){k9(n,e);return}const o=Le(e);if(typeof t=="string")o.setAttribute("data-content-placeholder",t);else{const i=tt(e),s=(r=i.querySelector(".block-placeholder-container"))!=null?r:k("div",["block-placeholder-container"],i);s.innerHTML="",s.appendChild(t)}}function SN(n){const e=n.getAttribute("data-style-heading");return e?L.t("placeholder.heading",{heading:e}):n.getAttribute("data-style-quoted")?L.t("placeholder.quote"):null}function LN(n){const e=n.getAttribute("data-list-type");return e?e==="ordered"||e==="unordered"?L.t("placeholder.list"):L.t("placeholder.mention"):null}function w9(n){switch(De(n)){case"text":return SN(n);case"list":return LN(n);default:return null}}function MN(n){if(lo(n))return!1;const e=ne(oe(n));return e?De(e)==="code":!1}function RN(n){return!lo(n)}function ON(n,e){var h,p;const t=n.selection.focusedBlock,o=De(t),r=e.contentPlaceholder||L.t("placeholder.default");let i=r;if(o&&Ia(n,o)&&t){if(!n.isBlockWritable(t)||MN(t))return;RN(t)&&(i=L.t("placeholder.common.contentInTable")),i=(h=w9(t))!=null?h:i}const s=n.getFirstBlock(),l=Qe(s);if(!l)return;const a=Qe(l);if(a&&!e.addPlaceholderToAllCurrentEmptyBlock)return;if(!a&&Iu(n,l)){jf(n,l,(p=w9(l))!=null?p:r);return}const d=n.getFocusedBlock();!Iu(n,d)||d!==s&&jf(n,d,i)}function _N(n,e){var r,i;const t=n.getFirstBlock(),o=Le(t);Iu(n,t)?(o.setAttribute("data-title-placeholder",(r=e.titlePlaceholder)!=null?r:L.t("placeholder.title")),o.setAttribute("data-title-placeholder-readonly",(i=e.readonlyTitlePlaceholder)!=null?i:"")):(o.removeAttribute("data-title-placeholder"),o.removeAttribute("data-title-placeholder-readonly"))}function FN(n){n.rootContainer.querySelectorAll("[data-content-placeholder").forEach(e=>{e.removeAttribute("data-content-placeholder")}),n.rootContainer.querySelectorAll("[data-type=block-tools] .block-placeholder-container").forEach(e=>{e.remove()})}function PN(n,e){FN(n),n.selection.range.isCollapsed()&&(_N(n,e),ON(n,e))}const qne="";function NN(n){for(let e=1;e<n.length;e++){const t=n[e];if(t.attributes&&Object.keys(t.attributes).length)return!0}return!1}const B9=S("enforce-title");class Tu{constructor(e,t={headingLevel:1}){m(this,"handleSelectionChange",e=>{setTimeout(()=>{this.applyPlaceholder(e)})});this.options=t,this.handleChanged(e),this.applyPlaceholder(e),e.addListener("selectionChanged",this.handleSelectionChange)}destroy(e){e.removeListener("selectionChanged",this.handleSelectionChange)}handleBeforeKeyDown(e,t){if(!e.selection.range.isSimple())return!1;const{containerId:r,blockIndex:i,offset:s}=e.getTextPosition();if(!Tu.isDocumentTitleBlock(r,i)||!or(t,"Enter"))return!1;let l=!1,a=null;To(e.rootContainer)===2&&(a=Hr(e.rootContainer,1),ue(e,a)===0&&(l=!0));const d=e.getFirstBlock();return e.undoManager.runInGroup(()=>{e.breakTextBlock(d,s,{forceInsertAfter:!0}),l&&a&&e.deleteBlock(a)}),!0}handleChanged(e){var t,o;try{const r=e.doc.getContainerBlocks(ce(e.rootContainer));g(B9,r.length>0,"root container is empty");const i=r[0];if(i.type!=="text"){const s=ur("",{heading:(t=this.options.headingLevel)!=null?t:1});e.insertBlock(ce(e.rootContainer),0,s,e.selection.range.toDocRange());return}if(g(B9,i.text,"invalid text block"),NN(i.text)||i.quoted||i.heading!==this.options.headingLevel){const s=e.getBlockById(i.id),l=e.getBlockString(s),a=ur(l,{heading:(o=this.options.headingLevel)!=null?o:1,quoted:!1}),d=e.selection.focusedBlock;let h=e.selection.range;const p=e.insertBlock(ce(e.rootContainer),0,a);d===s&&(h=kt(e,a.id,ue(e,p))),Oh(e,s,h)}if(r.length>1)return;e.insertTextBlock("",ce(e.rootContainer),1,{newRange:e.selection.range.toDocRange()})}finally{this.applyPlaceholder(e)}}handleRemoteChanged(e){setTimeout(()=>{this.applyPlaceholder(e)})}handleUpdateCompositionText(e){this.applyPlaceholder(e)}applyPlaceholder(e){var t,o;!((t=this.options)!=null&&t.titlePlaceholder)&&!((o=this.options)!=null&&o.contentPlaceholder)||PN(e,this.options)}static isDocumentTitleBlock(e,t){return e==="root"&&t===0}}const $N=S("image-data"),E9=1e3,Z0=400,HN=10;function Ec(n){return n.src.startsWith("empty:")||!n.src}function jN(n){return n.src.startsWith("http:")||n.src.startsWith("https:")}function x9(n){return`${qd.default(n)}_width`}function I9(n){return`${qd.default(n)}_height`}function T9(n){return`${n}_flex`}function D9(n){let e=n.getBoundingClientRect().width;return e-=Number.parseFloat(window.getComputedStyle(n).paddingLeft)+Number.parseFloat(window.getComputedStyle(n).paddingRight),e}function Du(n){if(n.every(r=>typeof r.flex=="number"&&r.flex))return;const e=100,o=n.map(r=>{const i=r.height==="auto"?r.width/e:r.height/e;return r.width/i}).reduce((r,i)=>r+i,0);n.forEach(r=>{const i=r.height==="auto"?r.width/e:r.height/e,s=r.width/i;r.flex=s/o})}function xc(n){const e=(r,i)=>{r||(r=`empty:${i}`);const s=x9(r),l=I9(r),a=T9(i);let d=n[s],h=n[l],p=n[a];return typeof d=="string"&&(d=Number.parseInt(d,10)),typeof h=="string"&&(h=Number.parseInt(h,10)),typeof p=="string"&&(p=Number.parseInt(p,10)),d&&h?{src:r,width:d,height:h,flex:p,virtualSize:!1}:d&&!h?{src:r,width:d,height:"auto",flex:p,virtualSize:!1}:(d=E9,h=Z0,{src:r,width:d,height:h,flex:p,virtualSize:!0})};let t=[];const o=n.src;return Array.isArray(o)?t=o.map(e):typeof o=="string"&&(t=o.split("|").map(e)),Du(t),t}function Vo(n){const e=n.embedData;return xc(n.embedData).length>1?100:e.widthPercent}function UN(n,e,t,o){const r=xc(e.embedData);if(r.length>1||o)return"100%";const i=Vo(e),s=n.rootContainer.getBoundingClientRect().width;if(i){const l=D9(t);return`${Math.min(s*i/100,l)}px`}return r[0].width?`${r[0].width}px`:"auto"}function cn(n,e){const o={src:n.map(r=>r.src).join("|"),widthPercent:e};return n.forEach((r,i)=>{if(r.width&&r.height&&!r.virtualSize){const l=r.src||`empty:${i}`,a=x9(l);o[a]=r.width;const d=I9(l);r.height!=="auto"&&(o[d]=r.height)}g($N,r.flex,"no image flex");const s=T9(i);o[s]=r.flex}),o}function zN(n,e,t,o){const r=xc(e.embedData),i=r.length===1?n.rootContainer:t;if(r.length===1&&o)return`${Z0}px`;if(r.some(h=>h.height==="auto"))return"auto";const s=Vo(e);if(!s)return"";let l=i.getBoundingClientRect().width*(s/100);if(l-=Number.parseFloat(window.getComputedStyle(i).paddingLeft)+Number.parseFloat(window.getComputedStyle(i).paddingRight),i===n.rootContainer&&i!==t&&(l=Math.min(l,D9(t))),r.length===1){const h=r[0];return h.virtualSize?"":`${h.height/(h.width/l)}px`}l-=(r.length-1)*HN;const a=r.reduce((h,p)=>h+p.flex,0);let d=0;for(const h of r){const C=l*h.flex/a/h.width*h.height;d=Math.max(C,d)}return`${d}px`}function VN(n){return n.reduce((t,o)=>t+o.flex,0)}function WN(n,e){k("div",["resize-gripper",e],n).setAttribute("data-resize-type",e)}function Q0(n){return tt(n).querySelector(".block-resizer")}function qN(n){const e=Q0(n);e&&re(e,"active")}function S9(n,e,t){const o=n.getBoundingClientRect(),r=e.getBoundingClientRect(),i=r.top-o.top,s=r.left-o.left,l=r.width,a=r.height;t.style.top=`${i}px`,t.style.left=`${s}px`,t.style.width=`${l}px`,t.style.height=`${a}px`}function GN(n,e,t,o){const r=Q0(n);if(r)return W(r,"active"),S9(n,e,r),r;const i=tt(n),s=k("div",["block-resizer"],i);return S9(n,e,s),t.resize.forEach(l=>{WN(s,l)}),s.addEventListener("mousedown",o),W(s,"active"),s}function Y0(n,e){const t=Q0(n);if(!t||!et(n,e))return;const o=n.getBoundingClientRect(),r=e.getBoundingClientRect(),i=r.top-o.top,s=r.left-o.left,l=r.width,a=r.height;t.style.top=`${i}px`,t.style.left=`${s}px`,t.style.width=`${l}px`,t.style.height=`${a}px`}const Gne="",ZN=S("block-resizer");class Su extends vt.TypedEmitter{constructor(t,o){super();m(this,"resizableElement");m(this,"block",null);m(this,"startRect",null);m(this,"startPos",null);m(this,"resizeType",null);m(this,"enabled",!1);m(this,"handleMouseDown",t=>{t.preventDefault(),t.stopPropagation();const o=this.getResizableElement();if(!o||t.button!==0)return;const r=t.target;if(!r||!(r instanceof HTMLElement))return;const i=r.getAttribute("data-resize-type");!i||(this.bindEvents(),this.startRect=o.getBoundingClientRect(),this.startPos=t,this.resizeType=i,va(window.getComputedStyle(r).cursor),this.block&&this.editor.selection.selectBlock(this.block,0))});m(this,"handleMouseMove",t=>{if(!this.startPos||!this.startRect||!this.resizeType||!this.getResizableElement()||!this.block)return;const r=t.x-this.startPos.x,i=t.y-this.startPos.y,s=this.startRect;let{top:l,left:a,right:d,bottom:h}=s;(this.resizeType==="bottom"||this.resizeType==="bottom-left"||this.resizeType==="bottom-right")&&(h+=i),(this.resizeType==="top"||this.resizeType==="top-left"||this.resizeType==="top-right")&&(l+=i),(this.resizeType==="left"||this.resizeType==="top-left"||this.resizeType==="bottom-left")&&(a+=r),(this.resizeType==="right"||this.resizeType==="top-right"||this.resizeType==="bottom-right")&&(d+=r);const p=d>a?d-a:0,C=h>l?h-l:0,v=new DOMRect(a,l,p,C);this.emit("resizing",this,v);const B=this.getResizableElement();B&&Y0(this.block,B)});m(this,"handleMouseUp",t=>{if(t.button!==0)return;va(""),this.unbindEvents(),this.emit("resized",this);const o=this.getResizableElement();!o||!this.block||Y0(this.block,o)});this.editor=t,this.options=o}enableResize(t,o){this.block=t,this.resizableElement=o,this.createResizer(),this.enabled=!0}disableResize(){!this.block||(qN(this.block),this.enabled=!1)}update(t,o){this.block=t,this.resizableElement=o,this.getResizableElement()&&this.enabled&&this.createResizer()}updateResizer(){const t=this.getResizableElement();t&&this.block&&Y0(this.block,t)}getBlock(){return this.block}destroy(){}getResizableElement(){return this.resizableElement?this.resizableElement:this.block?Le(this.block):null}createResizer(){const t=this.getResizableElement();!t||!this.block||(g(ZN,et(this.block,t),"not a block child element"),GN(this.block,t,this.options,this.handleMouseDown))}bindEvents(){document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("mouseup",this.handleMouseUp)}unbindEvents(){document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp)}}const QN=S("image-dom");function L9(n){return n.querySelector(".uploading-progress-mask")}function YN(n){const e=L9(n);if(e)return e;const t=k("div",["uploading-progress-mask"],n),o=k("div",["uploading-progress-bar"],t);return k("div",["uploading-progress-bar-value"],o),o}function JN(n){const t=YN(n).querySelector(".uploading-progress-bar-value");return g(QN,t,"no progress value"),t}function M9(n,e){const t=JN(n);t.style.width=`${e}%`}function KN(n){var e;(e=L9(n))==null||e.remove()}function Lu(n,e,t,o){const r=t!=null?t:n.findBlockById(e.id);if(!r)return;const i=o||oe(r),s=!!r.querySelector(".images > .image-container.error, .images > .image-container.empty "),l=UN(n,e,i,s),a=zN(n,e,i,s),d=Le(r);l==="auto"?d.style.width=l:(d.style.maxWidth=l,d.style.width="100%");const h=r.querySelector(".images");!h||(h.style.height=a||"none")}function XN(n){let e;return n.forEach((t,o)=>{o.toLocaleLowerCase()==="content-type"&&(e=t)}),e!=null?e:""}async function e$(n){try{const e=await fetch(n,{credentials:"same-origin"}),t=await e.blob(),o=XN(e.headers).toLocaleLowerCase();let r="";if(o){const s=km.default[o].extensions;s&&s.length>0&&(r=s[0])}return new File([t],`${Date.now()}.${r}`,{type:o})}catch{return null}}function Ji(n,e){const t=typeof e=="string"?e:ie(e);return n.getCustom(`image-${t}`)}function Uf(n,e){if(!e||!(e instanceof Node))return null;const t=ne(e);return t?Ji(n,t):null}function yr(n){return Array.from(n.querySelectorAll(".image-container"))}const J0=S("table-resize-drag-drop");class t${constructor(e,t,o,r){m(this,"cursor","col-resize");m(this,"initWidths");this.editor=e,this.elem=t,this.data=o,this.mouseDownEvent=r;const i=this.data.block,l=Ji(this.editor,i).getImages(),a=this.data.splitterIndex;g(J0,a>=0&&a<l.length-1,`invalid splitter index: ${a}`);const h=yr(i).map(p=>p.getBoundingClientRect().width);this.initWidths=h}onDragStart(e,t,o){if(!this.editor.isWritable())return;const r=this.data.block;Ji(this.editor,r).setResizing(!0)}onDragging(e,t,o,r,i){const s=this.data.block,l=Ji(this.editor,s),a=me.default(l.getImages()),d=this.data.splitterIndex;g(J0,d>=0&&d<a.length-1,`invalid splitter index: ${d}`);const h=this.initWidths[d],p=this.initWidths[d+1];if(h+p<100)return;let C=r;h+C<50&&(C=50-h),p-C<50&&(C=p-50);const D=[...this.initWidths];D[d]+=C,D[d+1]-=C;const x=yr(s);g(J0,x.length===a.length,"invalid image data");const _=D.reduce((z,Z)=>z+Z,0);for(let z=0;z<a.length;z++){const Z=D[z]/_;a[z].flex=Z,x[z].style.flexGrow=`${Z}`}const R=me.default(this.editor.getBlockData(s)),H=cn(a,Vo(R));R.embedData=H,Lu(this.editor,R,s,null)}onDragEnd(e,t,o,r,i){const s=this.data.block,l=Ji(this.editor,s),d=yr(s).map(h=>Number.parseFloat(h.style.flexGrow));l.updateFlex(d),l.setResizing(!1)}}function R9(n){var e;return!n||!(n instanceof HTMLElement)?null:xe(n,"image-splitter")?n:(e=n.closest(".image-splitter"))!=null?e:null}function n$(n,e){var s;const t=R9(e.target);if(!t)return;const o=ne(t);if(!o)return;Ji(n,o).setSelectedIndex(-1),n.selection.selectBlock(o,0);const r=Number.parseInt((s=t.getAttribute("data-index"))!=null?s:"",10);if(Number.isNaN(r)||typeof r!="number")return;const i={block:o,splitterIndex:r};Dm(new t$(n,t,i,e))}function o$(n,e){e.preventDefault(),e.stopPropagation();const t=R9(e.target);if(!t)return;const o=ne(t);!o||Ji(n,o).resetFlex()}function r$(n,e,t,o){const r=k("div",["image-splitter"],t);k("div",["image-splitter-indicator"],r),r.setAttribute("data-index",`${o}`),n.domEvents.addEventListener(r,"mousedown",n$),n.domEvents.addEventListener(r,"dblclick",o$)}const i$=S("image-item");function O9(n){return!n||!(n instanceof Node)?null:ne(n)}function _9(n){const e=O9(n);return e?yr(e):[]}function K0(n){if(!n||!(n instanceof Node))return null;const e=n instanceof Element?n:n.parentElement;if(!e)return null;const t=e.closest(".image-container");return t||null}function Mu(n){const e=K0(n);return e?_9(n).indexOf(e):-1}async function s$(n,e){const t=Uf(n,e.target);if(!t)return;const o=Mu(e.target);if(o===-1)return;const r=e.target;if(!(r instanceof HTMLImageElement))return;const i=t.getImages()[o];if(Ec(i)||n.readonly||!t.isAutoFix()||(setTimeout(()=>{t.setAutoFix(!1)},400),i.height==="auto"&&t.fixImageSize(o,r),i.virtualSize&&t.fixImageSize(o,r),!i||!jN(i)||i.downloading))return;i.downloading=!0;const s=await e$(i.src);s?t.replaceImage(o,s):i$.warn(`failed to download image: ${i.src}`)}function l$(n,e,t){if(e.querySelector(".load-error"))return;const r=t.src.startsWith("http:")||t.src.startsWith("https:"),i=k("div",["load-error"],e),s=k("div",["error-icon"],i);s.innerHTML=rv;const l=k("div",["error-message"],i);r?(l.innerHTML=L.t("image.load.remote.failed"),n.domEvents.addEventListener(i,"click",(a,d)=>{d.preventDefault(),d.target instanceof HTMLElement&&d.target.tagName==="A"&&window.open(t.src,"_blank")})):(l.innerHTML=L.t("image.load.failed"),n.domEvents.addEventListener(i,"click",(a,d)=>{d.preventDefault(),d.stopPropagation(),d.target instanceof HTMLElement&&d.target.tagName==="A"&&d$(a,d.target)}))}function X0(n,e){setTimeout(()=>{if(et(n.rootContainer,e)){const t=n.getBlockData(e);Lu(n,t,null,null)}})}function c$(n,e){const t=Uf(n,e.target);if(!t)return;const o=Mu(e.target);if(o===-1)return;const r=t.getImages()[o];if(!r)return;const i=K0(e.target);if(!i)return;W(i,"error","error-load");const s=ne(i);s&&X0(n,s),i.innerHTML="",l$(n,i,r)}function a$(n,e,t){if(e.querySelector(".upload-error"))return;const r=k("div",["upload-error"],e),i=k("div",["error-icon"],r);i.innerHTML=rv;const s=k("div",["error-message"],r);s.innerHTML=L.t("image.upload.failed"),n.domEvents.addEventListener(r,"click",(l,a)=>{if(a.preventDefault(),!a.target||!(a.target instanceof Element)||a.target.tagName!=="A")return;const d=Uf(l,a.target),h=Mu(a.target);!d||h===-1||d.replaceImage(h,t)})}function F9(n,e,t,o,r){const i=yr(e)[t];!i||(W(i,"error","error-upload"),X0(n,e),i.innerHTML="",a$(n,i,r))}function P9(n,e,t,o,r,i,s){const l=k("div",["image-container"],t);if(l.setAttribute("data-src",o.src),s.length>1&&(l.style.flexShrink=`${o.flex}`,l.style.flexGrow=`${o.flex}`),i===r&&W(l,"active"),Ec(o)){W(l,"empty");const d=k("div",["upload-image-icon"],l);return d.innerHTML=wL,l}const a=k("img",["editor-image"],l);if(a.src=n.doc.buildResourceUrl(o.src),n.domEvents.addEventListener(a,"load",s$),n.domEvents.addEventListener(a,"error",c$),o.src.startsWith("https:")||o.src.startsWith("http:")){const d=k("div",["image-warning"],l);d.innerHTML=ov,d.setAttribute(`data-editor-tooltip-${n.clientId}`,L.t("image.load.remote.tooltip"))}return l}function u$(n,e,t,o,r){const i=k("div",["images"],t);return o.forEach((s,l)=>{l>0&&r$(n,e,i,l-1),P9(n,e,i,s,l,r,o)}),o.length>1&&W(e,"multi"),i}function N9(n,e,t,o,r,i){const l=Array.from(e.querySelectorAll(".image-container"))[o];if(!l)return;const a=P9(n,e,null,t,o,r,i);l.insertAdjacentElement("beforebegin",a),l.remove(),X0(n,e)}function Ru(n,e){return yr(n)[e]}function d$(n,e){const t=O9(e);if(!t)return;const o=Mu(e);if(o===-1)return;const r=Uf(n,e);if(!r)return;const i=r.getImages()[o];N9(n,t,i,o,r.getSelectedIndex(),r.getImages())}function Wo(n){return De(n)==="embed"&&fn(n)==="image"}async function $9(n){return new Promise((e,t)=>{const o=new Image;o.onload=()=>{e({width:o.naturalWidth,height:o.naturalHeight})},o.onerror=t,o.src=n})}async function h$(n){const e=await Ul(n);return $9(e)}function H9(n){var o;let e="image/*";const t=(o=n.getComponentOptions("image"))==null?void 0:o.allowedMedias;return t&&(e=t.map(r=>`.${r}`).join(",")),e}function j9(n,e){var s;const{maxSize:t,allowedMedias:o,callbacks:r}=(s=n.getComponentOptions("image"))!=null?s:{};if(t&&e.size>t){const l=new Error("image is too large");throw l.code="MaxMediaSize",r!=null&&r.onError&&(r==null||r.onError(n,l)),l}const i=Ba(e.name);if(o&&!o.includes(i)){const l=new Error(`media file is not allowed: ${i}`);throw l.code="NotAllowedFile",r!=null&&r.onError&&(r==null||r.onError(n,l)),l}}function U9(n){return n.startsWith("image/")}const z9=S("image-object");class Tt{constructor(e,t){m(this,"images",[]);m(this,"selectedIndex",-1);m(this,"blockResizer");m(this,"resizing",!1);m(this,"parentContainerResizerObserver",null);m(this,"autoFix",!1);m(this,"handleMouseDown",async(e,t)=>{const o=Mu(t.target);if(o===-1)return;const r=this.images[o];Ec(r)||this.setSelectedIndex(o)});m(this,"handleRootContainerResize",()=>{this.handleEditorResize(this.editor.rootContainer)});m(this,"handleEditorResize",e=>{if(this.isEmpty()||this.resizing)return;const t=this.editor.findBlockById(this.blockData.id);!t||oe(t)===e&&Lu(this.editor,this.blockData,t,null)});m(this,"handleResizing",(e,t)=>{const o=this.editor.findBlockById(this.blockData.id);if(!o)return;this.autoFix||this.setAutoFix(!0);const i=this.editor.rootContainer.getBoundingClientRect().width,s=o.getBoundingClientRect();let l=t.width>s.width?s.width:t.width;l<50&&(l=50);const a=l*100/i;this.blockData.embedData.widthPercent=a,Lu(this.editor,this.blockData,o,null)});m(this,"handleResized",e=>{const t=this.editor.findBlockById(this.blockData.id);if(!t)return;const o=cn(this.images,Vo(this.blockData));this.editor.updateEmbedData(t,o),this.blockResizer.enableResize(t)});m(this,"fixImageSizes",Mt.default(()=>{const e=this.editor.findBlockById(this.blockData.id);if(!e)return;const t=cn(this.images,Vo(this.blockData));this.editor.updateEmbedData(e,t)},1e3));this.editor=e,this.blockData=t,this.blockResizer=new Su(this.editor,{resize:["top-left","top-right","bottom-left","bottom-right"]}),this.blockResizer.addListener("resizing",this.handleResizing),this.blockResizer.addListener("resized",this.handleResized),this.images=xc(this.blockData.embedData)}destroy(){var e;this.blockResizer.removeAllListeners(),this.blockResizer.destroy(),this.editor.domEvents.removeEventListener(null,null,this.handleMouseDown),(e=this.parentContainerResizerObserver)==null||e.disconnect()}setAutoFix(e){this.autoFix=e}isAutoFix(){return this.autoFix}createContent(e,t,o){const r=u$(this.editor,t,o,this.images,this.selectedIndex);if(this.editor.domEvents.addEventListener(o,"mousedown",this.handleMouseDown),this.editor.addListener("resize",this.handleRootContainerResize),Mo(e)){const s=()=>{this.handleEditorResize(e)};this.parentContainerResizerObserver=new ResizeObserver(s),this.parentContainerResizerObserver.observe(e)}const i=()=>!!(this.images.length===1&&this.images[0].virtualSize);this.isEmpty()&&i()&&W(r,"empty"),Lu(this.editor,this.blockData,t,e),setTimeout(()=>{const s=this.editor.findBlockById(this.blockData.id);s&&this.blockResizer.update(s)})}getImages(){return this.images}getWidthPercent(){return Vo(this.blockData)}isEmpty(){return this.images.length===1&&Ec(this.images[0])}setResizing(e){this.resizing=e}getSelectedIndex(){return this.selectedIndex}getBlock(){return this.editor.findBlockById(this.blockData.id)}setSelectedIndex(e){const t=this.getBlock();if(!t||e===this.selectedIndex)return;if(this.selectedIndex!==-1){const r=Ru(t,this.selectedIndex);r&&re(r,"active")}this.selectedIndex=e;const o=Ru(t,e);o&&W(o,"active")}async requestUploadImage(e){const t=this.editor.findBlockById(this.blockData.id);if(!t)return;const o=Ru(t,e);if(xe(o,"error"))return;const r=H9(this.editor),i=await zl(r);await this.replaceImage(e,i)}tryEnableResizer(){const e=this.editor.findBlockById(this.blockData.id);if(!e||!this.editor.isWritable())return;const t=Ru(e,0);!this.isEmpty()&&this.images.length===1&&!xe(t,"error")&&this.blockResizer.enableResize(e)}disableResizer(){this.blockResizer.disableResize()}fixImageSize(e,t){const o=this.images[e];Ec(o)||(o.height==="auto"&&(o.height=t.height),o.width=t.naturalWidth,o.height=t.naturalHeight,o.virtualSize=!1,this.fixImageSizes())}removeImage(e){const t=this.editor.findBlockById(this.blockData.id);if(!t||e===-1||e>=this.images.length)return!1;const o=me.default(this.images);if(o.splice(e,1),o.length===0)return this.editor.deleteBlock(t),!0;o[0].flex=NaN,Du(o),this.selectedIndex>=o.length&&(this.selectedIndex=o.length-1);const r=cn(o,Vo(this.blockData));return this.editor.updateEmbedData(t,r),!0}async replaceImage(e,t){const o=this.editor.findBlockById(this.blockData.id);if(!o)return!1;try{const i=await Ul(t),s=this.images[e];if(s.virtualSize){const{width:a,height:d}=await $9(i);s.width=a,s.height=d,s.virtualSize=!1;const h=cn(this.images,Vo(this.blockData));this.editor.updateEmbedData(o,h)}const l={...s,src:i};N9(this.editor,o,l,e,this.selectedIndex,this.images),setTimeout(()=>{this.blockResizer.update(o)})}catch(i){return F9(this.editor,o,e,i,t),!1}const r=Ru(o,e);if(!r)return!1;W(r,"uploading"),M9(r,0),W(o,"media-block-uploading");try{const i=await this.editor.doc.uploadResource(t,{onProgress:a=>{M9(r,a)}});re(r,"uploading"),this.images[e].src=i.resourceId;const s=this.editor.findBlockById(this.blockData.id);if(!s)return!1;re(s,"media-block-uploading");const l=cn(this.images,Vo(this.blockData));return this.editor.updateEmbedData(s,l),!0}catch(i){z9.error(i);const s=this.editor.findBlockById(this.blockData.id);return s&&(re(r,"uploading"),KN(r),F9(this.editor,s,e,i,t),re(s,"media-block-uploading")),!1}}updateFlex(e){const t=this.editor.findBlockById(this.blockData.id);if(!t)return;g(z9,e.length===this.images.length,"invalid flex");for(let r=0;r<this.images.length;r++)this.images[r].flex=e[r];const o=cn(this.images,Vo(this.blockData));this.editor.updateEmbedData(t,o)}resetFlex(){const e=this.editor.findBlockById(this.blockData.id);if(!e)return;const t=me.default(this.images);t[0].flex=NaN,Du(t);const o=cn(t,Vo(this.blockData));this.editor.updateEmbedData(e,o)}setData(e){this.blockData=e,this.images=xc(e.embedData)}static create(e,t){const o=e.addCustom(`image-${t.id}`,()=>new Tt(e,t));return o.setData(t),o}static getImageObject(e,t){let o;return typeof t=="string"?o=t:o=ie(t),e.getCustom(`image-${o}`)}}const Zne="",Qne="";function zf(n){const e=tt(n);let t=e.querySelector(":scope > .block-helper");return t||(t=k("div",["block-helper"],e),k("span",["helper-sizer"],t,"A")),t}function e2(n,e,t){const o=zf(n),i=Array.from(o.children).find(s=>{var a;return Number.parseInt((a=s.getAttribute("data-index"))!=null?a:"0",10)>t});o.insertBefore(e,i!=null?i:null)}const V9=40,f$=20;class m${findTargetBlock(e,t){const o=t.target;if(o&&o instanceof Element){const a=ne(o);if(a&&et(e.rootContainer,a))return a}let r=t.clientX,i=t.clientY;const s=e.rootContainer.getBoundingClientRect().left;r<s&&s-r<V9&&(r+=V9);let l=document.elementFromPoint(r,i);if(l){const a=ne(l);if(a&&et(e.rootContainer,a))return a}if(i-=f$,l=document.elementFromPoint(r,i),l){const a=ne(l);if(a&&et(e.rootContainer,a))return a}return null}destroy(){}}class g$ extends Df{constructor(t){super(t,{trigger:[],id:"empty-block-menu"});m(this,"currentBlock",null)}get isVisible(){return this.suggest.menu.isVisible}isInMenu(t){return this.menu.isInCommandBar(t)}show(){const o=this.editor.selection.focusedBlock;this.suggest.popup(o,0,"","")}setBlock(t){this.currentBlock=t}}function p$(n,e,t){const o=Ym(n,e);if(!o)return[];const r=[];return Object.values(o).forEach(i=>{t!=null&&t.has(i.group)||r.push(...i.commands.map(s=>({...s,source:"block-command",blockMenuItemCustomData:i.group})))}),r}function t2(n,e,t){const o=L0(n,t),r=i=>{i.forEach(s=>{s.source=e,s.children&&r(s.children)})};return r(o),o}function C$(n,e,t,o=!1){var d,h;const r=oe(e);let s=be(e);ut(n,e)||o||(s+=1);const l=ce(r),a=t;return a.commandProvider?a.commandProvider.executeCommand(n,t,{from:"block-menu",containerId:l,blockIndex:s}):(h=(d=a.blockOptions)==null?void 0:d.handleInsertEmptyBlock)==null?void 0:h.call(d,n,{containerId:l,blockIndex:s,item:t})}function A$(n,e){const t=So(n,e),o=n.getBlockData(e);return!(t!=="text"||o.heading)}class W9{constructor(e,t,o){m(this,"source","text-style");m(this,"id","text-style-item");m(this,"name","Text styles");m(this,"element");m(this,"textStylesTooltips",{});m(this,"createHeadingItemElement",(e,t,o)=>{var i;const r=I0();this.createItem("text",lu,t,A$(this.editor,e)),(i=r.insertBlockCommandItems)==null||i.forEach(s=>{s.id&&s.icon&&this.createItem(s.id,s.icon,t,o?o===Number(s.value):!1)})});m(this,"createListItemElement",(e,t,o)=>{const{checkbox:r,ordered:i}=o,l=De(e)==="list",a=l&&i===!1&&!r,d=l&&i,h=l&&!!r;this.createItem("unordered-list",uv,t,a),this.createItem("ordered-list",dv,t,d),this.createItem("check-list",cv,t,h)});m(this,"handleClick",(e,t)=>{var l,a;if(!t.target||!(t.target instanceof Node))return;const o=t.target instanceof Element?t.target:t.target.parentElement;if(!o)return;const r=o.closest(".text-style-item");if(!r)return;const i=r.id,s="heading-";if(i==="text"&&If(e,this.block,null),i.startsWith(s)){const d=Number.parseInt(i.substring(s.length),10);d&&If(e,this.block,d)}if(i==="blockquote"&&B0(e,this.block),i.startsWith("align")){const d=i.replace(/^align-/,"");S7(e,this.block,d)}(i==="unordered-list"||i==="ordered-list"||i==="check-list")&&x0(e,this.block,i),(a=(l=this.options).onAfterStyleItemClick)==null||a.call(l)});m(this,"calcTextStyleItemTooltipsEnum",()=>{this.textStylesTooltips={text:{title:L.t("commands.text")},blockquote:{title:L.t("commands.quote")},"align-left":{title:L.t("commands.alignLeft")},"align-center":{title:L.t("commands.alignCenter")},"align-right":{title:L.t("commands.alignRight")},"unordered-list":{title:L.t("commands.unordered")},"ordered-list":{title:L.t("commands.ordered")},"check-list":{title:L.t("commands.check")}};let e=1;for(;e<=8;)this.textStylesTooltips[`heading-${e}`]={title:L.t("commands.heading",{name:`${e}`})},e++});this.editor=e,this.block=t,this.options=o,this.calcTextStyleItemTooltipsEnum(),this.element=this.createItemElement(e,t),e.domEvents.addEventListener(this.element,"click",this.handleClick)}createItemElement(e,t){const o=k("div",["text-styles"],null),r=k("div",["text-style-section"],o),i=e.getBlockData(t);if(!this.options.fromEmbed){const l=i.heading,a=i.quoted;this.createHeadingItemElement(t,r,l),this.createListItemElement(t,r,i),this.createItem("blockquote",av,r,!!a)}const s=i.align||"left";return this.createItem("align-left",su,r,s==="left"),this.createItem("align-center",Rp,r,s==="center"),this.createItem("align-right",Mp,r,s==="right"),o}createItem(e,t,o,r=!1){const i=["style-icon","text-style-item"];r&&i.push("active");const s=$l(t,i,o);s.id=e;const l=this.textStylesTooltips[e];if(!l)return;const{title:a,shortcut:d}=l;s.setAttribute(`data-editor-tooltip-${this.editor.clientId}`,a),d&&s.setAttribute(`data-editor-tooltip-desc-${this.editor.clientId}`,io(d))}}function q9(){return{source:"separator",type:"separator",id:`section-${K()}`,name:""}}const G9={copy:HL,cut:jL,delete:UL,"lock-block":zL,"unlock-block":VL,comment:ic},b$=["image","video"];function v$(n,e,t){const o=[],r=te(n,e),i=It(e)&&b$.includes(fn(e)),s=i&&(fn(e)!=="image"||fn(e)==="image"&&yr(e).length===1);if(r?o.push(new W9(n,e,t)):i&&s&&o.push(new W9(n,e,{...t,fromEmbed:!0})),!ut(n,e)){(r||i&&s)&&o.push(q9());const l=p$(n,e,new Set(["hovering-toolbar"]));l.sort((a,d)=>{var h,p;return((h=a.order)!=null?h:0)-((p=d.order)!=null?p:0)}),l.forEach(a=>{a.id in G9&&(a.icon=G9[a.id])}),o.push(...l)}return ut(n,e)?o.push(...t2(n,"insert-block",{withPlainText:!1,from:"block-menu"})):o.push(q9(),{id:"insert-block-before",icon:WL,name:L.t("blockMenu.command.insertAbove"),children:t2(n,"insert-block-before",{withPlainText:!0,from:"block-menu"}),childrenMenuId:"quick-menu",source:"insert-block-before"},{id:"insert-block-after",icon:qL,name:L.t("blockMenu.command.insertAfter"),children:t2(n,"insert-block",{withPlainText:!0,from:"block-menu"}),source:"insert-block",childrenMenuId:"quick-menu"}),o}function y$(n,e,t){if(t.source==="block-command"){const o=t.blockMenuItemCustomData;f4(n,e,o,t)}else(t.source==="insert-block"||t.source==="insert-block-before")&&C$(n,e,t,t.source==="insert-block-before")}const k$=S("exclusive-block");function n2(n,e,t,o){var l;W(e,"block-exclusive");const r=Ye(n,e),i=(l=r.getBlockProperties)==null?void 0:l.call(r,n,e),{abstract:s}=i||{};e.setAttribute("data-user-name",o),e.setAttribute("data-user-id",t),e.setAttribute("data-exclusive-tips",L.t("exclusive.tips",{editor:o,embedType:s||L.t("exclusive.fallbackAbstract")}))}function Z9(n){re(n,"block-exclusive"),n.removeAttribute("data-user-name"),n.removeAttribute("data-user-id"),n.removeAttribute("data-exclusive-tips")}function w$(n,e,t,o,r){k$.debug(`block ${ie(e)} ${t?"exclusive":"unexclusive"}, ${o}, ${r}`),t?n2(n,e,o,r):Z9(e)}function Ou(n){return n.classList.contains("block-exclusive")}function Q9(n,e){e.blockIds.forEach(t=>{const o=n.findBlockById(t);o&&w$(n,o,e.exclusive,e.userId,e.displayName)})}class Ki{constructor(e){m(this,"exclusiveBlockIds",new Set);m(this,"exclusiveBlockTimer",0);m(this,"remoteExclusiveBlockIds",new Map);m(this,"handleUserChanged",e=>{const t=new Set(e.map(r=>r.userId));Array.from(this.remoteExclusiveBlockIds.entries()).forEach(([r,i])=>{if(!t.has(i.userId)){this.remoteExclusiveBlockIds.delete(r);const s={...i,exclusive:!1};Q9(this.editor,s)}});const o=Array.from(this.exclusiveBlockIds).map(r=>this.editor.findBlockById(r)).filter(r=>!!r);o.length>0&&this.broadcastExclusiveBlockMessage(o,!0)});this.editor=e,e.doc.registerCallback(this),e.doc.getRemoteUsers().addListener("change",this.handleUserChanged)}destroy(){this.stopExclusiveBlockTimer(),this.editor.doc.unregisterCallback(this),this.editor.doc.getRemoteUsers().addListener("change",this.handleUserChanged)}onCustomMessage(e){if(e.type==="exclusiveBlock"){const t=e;Q9(this.editor,t),t.blockIds.forEach(o=>{t.exclusive?this.remoteExclusiveBlockIds.set(o,t):this.remoteExclusiveBlockIds.delete(o)})}}getExclusiveMessage(e){return this.remoteExclusiveBlockIds.get(e)}broadcastExclusiveBlockMessage(e,t){if(this.editor.readonly||e.length===0)return;const o=this.editor.doc.getUser(),r={type:"exclusiveBlock",userId:o.userId,displayName:o.displayName,blockIds:e.map(i=>ie(i)),exclusive:t};this.editor.doc.broadcastMessage(r)}exclusiveBlock(e){this.exclusiveBlockIds.has(ie(e))||(this.broadcastExclusiveBlockMessage([e],!0),this.exclusiveBlockIds.add(ie(e)),this.exclusiveBlockIds.size===1&&this.startExclusiveBlockTimer())}unexclusiveBlock(e){!this.exclusiveBlockIds.has(ie(e))||(this.exclusiveBlockIds.delete(ie(e)),this.broadcastExclusiveBlockMessage([e],!1),this.exclusiveBlockIds.size===0&&this.stopExclusiveBlockTimer())}startExclusiveBlockTimer(){this.exclusiveBlockTimer=window.setInterval(()=>{Array.from(this.exclusiveBlockIds.keys()).forEach(e=>{this.broadcastExclusiveBlockMessage([this.editor.getBlockById(e)],!0)})},30*1e3)}stopExclusiveBlockTimer(){clearInterval(this.exclusiveBlockTimer),this.exclusiveBlockTimer=0}static get(e){return e.addCustom("exclusiveBlock",()=>new Ki(e))}static register(e){return this.get(e)}}function o2(n,e){Ki.get(n).exclusiveBlock(e)}function r2(n,e){Ki.get(n).unexclusiveBlock(e)}class Y9{writable(e,t){if(Array.isArray(t)){for(const o of t)if(Ou(o))return!1;return}if(Ou(t))return!1}create(e,t,o,r,i){const s=Ki.get(e).getExclusiveMessage(i.id);s&&n2(e,r,s.userId,s.displayName)}update(e,t,o,r,i){const s=Ki.get(e).getExclusiveMessage(i.id);s?n2(e,r,s.userId,s.displayName):Z9(r)}}const Yne="",B$={exclusive:{tips:"\u300C{editor}\u300D\u6B63\u5728\u7F16\u8F91\uFF0C\u300C{embedType}\u300D\u4E0D\u652F\u6301\u591A\u4EBA\u7F16\u8F91",fallbackAbstract:"\u8BE5 Block"}},E$={exclusive:{tips:"\u300C{editor}\u300Dis editing\uFF0C\u300C{embedType}\u300Ddoes not support multi-person editing",fallbackAbstract:"This Block"}},x$={exclusive:{tips:"\u300C{editor}\u300D\u306F\u7DE8\u96C6\u4E2D\u3067\u3059\u3002\u300C{embedType}\u300D\u306F\u8907\u6570\u4EBA\u3067\u540C\u6642\u7DE8\u96C6\u3067\u304D\u307E\u305B\u3093",fallbackAbstract:"\u3053\u306E\u8981\u7D20"}};L.mergeLang({"zh-CN":B$,"en-US":E$,"ja-JP":x$});function _u(n,e){return n.getBlockData(e).lock}function Vf(n,e){return!!_u(n,e)}function Fu(n,e){const t=_u(n,e);return t?t.userId===n.doc.getUser().userId:!1}function i2(n,e){const t=_u(n,e);return t?t.userId!==n.doc.getUser().userId:!1}function I$(n,e){if(n.readonly||!n.isBlockWritable(e)||Vf(n,e)&&!Fu(n,e))return;const t=n.doc.getUser(),o={userId:t.userId,displayName:t.displayName,locked:Date.now()},i={...n.getBlockData(e),lock:o};n.updateBlockData(e,i)}function T$(n,e){if(!Fu(n,e))return;const t={lock:null};n.updateBlockData(e,t)}const D$=10,S$=80;class s2{constructor(){m(this,"executeCommand",(e,t,o)=>{const r=o.data;if(!r||!r.blockId)return;const i=e.getBlockById(r.blockId);r.type==="lock"?I$(e,i):r.type==="unlock"&&T$(e,i)})}create(e,t,o,r,i){const s=i.lock;s&&(s.userId!==e.doc.getUser().userId?W(r,"locked-by-others"):W(r,"locked-by-self"))}update(e,t,o,r,i){const s=i.lock;if(s)if(s.userId!==e.doc.getUser().userId){W(r,"locked-by-others");const l=e.selection.focusedBlock;(l===r||et(r,l))&&(te(e,r)||De(r)==="code")&&e.insertTextBlock("",ce(o),be(r)+1)}else W(r,"locked-by-self");else re(r,"locked-by-others"),re(r,"locked-by-self")}writable(e,t){let o=[];Array.isArray(t)?o=t:o.push(t);for(const r of o){if(i2(e,r))return!1;if(lo(r))return;let i=Es(r);for(;i;){if(i2(e,i))return!1;i=Es(i)}}}commands(e,t){const o=Vf(e,t),r=Fu(e,t),i=Ou(t),s={blockId:ie(t),type:"lock"},l={id:"lock-block",name:"",data:s,order:10};if(o)if(r)l.id="unlock-block",l.name=L.t("locker.unlock"),s.type="unlock";else{const a=_u(e,t);let d=(a==null?void 0:a.displayName)||"";const h=F5(d,D$,S$);(h==null?void 0:h.length)!==d.length&&(l.ellipsisTooltip=a==null?void 0:a.displayName,d=h||""),l.name=L.t("locker.lockedBy",{name:d}),l.states=["disabled"]}else i?(l.name=L.t("locker.lock"),l.states=["disabled"]):l.name=L.t("locker.lock");return{group:"block-locker",commands:[l],executeCommand:this.executeCommand}}}const Jne="",L$={locker:{lock:"\u9501\u5B9A",unlock:"\u89E3\u9664\u9501\u5B9A",lockedBy:"\u88AB {name} \u9501\u5B9A"}},M$={locker:{lock:"Lock",unlock:"Unlock",lockedBy:"Locked by {name}"}},R$={locker:{lock:"\u30ED\u30C3\u30AF",unlock:"\u30ED\u30C3\u30AF\u89E3\u9664",lockedBy:"{name}\u304C\u30ED\u30C3\u30AF\u3057\u307E\u3057\u305F"}};L.mergeLang({"zh-CN":L$,"en-US":M$,"ja-JP":R$});class Wf{async handleBeforePasteDoc(e,t){return Object.values(t.blocks).forEach(o=>{o.forEach(r=>{delete r.lock})}),!1}}const O$=S("standard-block-actions");class _${constructor(){m(this,"executeCommand",(e,t,o)=>{const r=o.data;try{const i=e.getBlockById(r);if(o.id==="delete"){e.deleteBlock(i);return}o.id==="copy"&&Wh(e,i),o.id==="cut"&&(Wh(e,i),e.deleteBlock(i))}catch(i){O$.error(`failed to execute block command: ${JSON.stringify(i)}`)}})}commands(e,t){const o=Vf(e,t),r=o&&Fu(e,t),i=ie(t),s=V0(),l=Ou(t),a={id:"copy",name:L.t("blockMenu.command.copy"),data:i,order:1,states:s?[]:["disabled"],disableReason:s?void 0:L.t("copyCutProperty.unsafeEnvTips",{shortCut:io("CtrlOrCmd+C"),operation:L.t("copyCutProperty.copy")})},d={id:"cut",name:L.t("blockMenu.command.cut"),data:i,order:2,states:o&&!r||!s||l?["disabled"]:[],disableReason:s?void 0:L.t("copyCutProperty.unsafeEnvTips",{shortCut:io("CtrlOrCmd+X"),operation:L.t("copyCutProperty.cut")})},h={id:"delete",name:L.t("blockMenu.command.delete"),data:i,order:3,states:o&&!r||l?["disabled"]:[]};return{group:"standard-block-actions",commands:[a,d,h],executeCommand:this.executeCommand}}}const J9=S("block-menu");class F${constructor(e){m(this,"menu");m(this,"currentBlock",null);m(this,"commandBlock",null);m(this,"handleShow",()=>{g(J9,this.currentBlock,"no target block before show block menu");const e=v$(this.editor,this.currentBlock,{onAfterStyleItemClick:this.close});this.menu.updateItems(e),this.commandBlock=this.currentBlock});m(this,"handleClose",()=>{$p(this.editor)&&this.editor.focus()});m(this,"handleItemClick",(e,t)=>{g(J9,this.commandBlock,"no command block before show block menu"),y$(this.editor,this.commandBlock,t),t.element||this.close()});m(this,"close",()=>{this.menu.close("clickItem")});this.editor=e,this.menu=new Us([],void 0,{id:"block-menu"}),this.menu.on("show",this.handleShow),this.menu.on("close",this.handleClose),this.menu.on("click",this.handleItemClick),e.blockHooks.push(new _$)}show(e,t){this.menu.manualShow(e,{placement:"bottom-start",...t})}isInMenu(e){return this.menu.isInCommandBar(e)}setBlock(e){this.currentBlock=e}get isVisible(){return this.menu.isVisible}destroy(){this.menu.destroy()}}const P$=1e3;async function N$(n,e){const{width:t}=n.rootContainer.getBoundingClientRect(),o=e.getBoundingClientRect();return o.width>t||o.height>=P$?"":(await K3.default.toSvg(e)).replace(/margin-block:.*?;/,"").replace(/margin:.*?;/,"")}const $$=S("drag-preview-image");class H${constructor(e){m(this,"startPosition",null);m(this,"dragContainer",null);m(this,"handleDragStart",async(e,t)=>{const o=e.target;g($$,o instanceof Element,`Invalid Drag target:${o}`);const{x:r,y:i}=e;this.startPosition={x:r,y:i};const s=k("div",["drag-image-container"],this.editor.rootContainer),l=k("img",["drag-image"],s),a=k("span",["drag-loading"],s);a.innerHTML=YL;const{x:d,width:h,height:p,y:C}=o.getBoundingClientRect(),v=this.editor.rootContainer.getBoundingClientRect(),B=t.getBoundingClientRect();s.style.left=`${d+h}px`,s.style.top=`${C+p}px`,s.style.width=`${Math.min(v.width/2,B.width)}px`,this.dragContainer=s;const x=await N$(this.editor,t);x?l.src=x:W(s,"drag-placeholder"),xm(s,{status:"loaded"})});m(this,"handleDrag",e=>{if(this.startPosition&&this.dragContainer){const{x:t,y:o}=e;if(t===0&&o===0){this.dragContainer.style.transition="transform 0.15s, opacity .15s",this.dragContainer.style.transform="",this.dragContainer.style.opacity="0";return}const{x:r,y:i}=this.startPosition,s=t-r,l=o-i;this.dragContainer.style.transform=`translate(${s}px, ${l}px)`}});m(this,"handleDragEnd",()=>{this.dragContainer&&(this.dragContainer.remove(),this.startPosition=null,this.dragContainer=null)});this.editor=e}}const K9="drag-preview-element";function j$(n){if(xe(n,K9))return n;const e=n.querySelector(`.${K9}`);return e||(It(n)?Le(n):n)}const qf=S("block-menu-drag-handler");function l2(n,e){return new DragEvent(e,{bubbles:!0,cancelable:!0,view:window,screenX:n.screenX,screenY:n.screenY,dataTransfer:new DataTransfer,clientX:n.clientX,clientY:n.clientY})}class U${constructor(e,t){m(this,"dragPreview");m(this,"autoScroll");m(this,"oldPos",{x:0,y:0});m(this,"handleMouseDown",e=>{const t=this.button.blockMenu.currentBlock;if(g(qf,t,"no dragged block"),e.button!==0)return;if(!this.editor.isBlockWritable(t)){e.preventDefault(),e.stopPropagation();return}const{x:o,y:r}=e;this.oldPos={x:o,y:r},document.addEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.addEventListener("mousemove",this.handleDrag)});m(this,"handleDragStart",e=>{var s,l;const t=so(this.button.buttonElement);this.autoScroll||(this.autoScroll=new rh({scrollElement:t,trackMouseEvent:"mousemove",edge:{top:50,bottom:50}}));const o=this.button.blockMenu.currentBlock;g(qf,o,"no dragged block"),(l=(s=Ye(this.editor,o)).notify)==null||l.call(s,this.editor,"beginDrag");const r=l2(e,"dragstart");G$(this.editor,r,o),window.isDragging=!0,this.button.buttonElement.style.opacity="0";const i=j$(o);this.dragPreview.handleDragStart(e,i),this.autoScroll.active(),W(o,"dragging"),W(this.editor.contentElement,"dragging")});m(this,"handleDrag",e=>{const{target:t,x:o,y:r}=e;if(this.oldPos.x===o&&this.oldPos.y===r)return;window.isDragging||this.handleDragStart(e),this.oldPos={x:o,y:r},g(qf,t instanceof Element,"target is invalid"),this.dragPreview.handleDrag(e);const i=l2(e,"dragover");this.editor.contentElement.dispatchEvent(i)});m(this,"handleDragEnd",e=>{var r;const t=this.button.blockMenu.currentBlock;g(qf,t,"no dragged block"),window.isDragging=!1,this.button.buttonElement.style.opacity="1",this.dragPreview.handleDragEnd(),(r=this.autoScroll)==null||r.inactive(),re(t,"dragging"),re(this.editor.contentElement,"dragging"),document.removeEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.removeEventListener("mousemove",this.handleDrag);const o=l2(e,"drop");this.editor.contentElement.dispatchEvent(o)});this.editor=e,this.button=t,this.button.buttonElement.addEventListener("mousedown",this.handleMouseDown),this.dragPreview=new H$(e)}destroy(){this.button.buttonElement.removeEventListener("mousedown",this.handleMouseDown)}}class Pu{constructor(e){m(this,"highlightedBlockId","");m(this,"handleSelectionChange",()=>{this.clearHighlightedBlock()});this.editor=e,this.editor.addListener("selectionChanged",this.handleSelectionChange)}highlightBlock(e){this.clearHighlightedBlock(),this.highlightedBlockId=ie(e),W(e,"highlighted")}clearHighlightedBlock(){if(this.highlightedBlockId){const e=this.editor.findBlockById(this.highlightedBlockId);e&&re(e,"highlighted"),this.highlightedBlockId=""}}destroy(){}static register(e){return e.addCustom("editor-block-highlighter",()=>new Pu(e))}static get(e){return e.getCustom("editor-block-highlighter")}}class X9{constructor(e){m(this,"buttonElement");m(this,"emptyBlockMenu");m(this,"blockMenu");m(this,"dragHandler");m(this,"handleHoverBlock",(e,t,o)=>{if(this.emptyBlockMenu.isVisible||this.blockMenu.isVisible||!this.editor.isWritable())return;const r=this.editor.getCustom("editor-tooltip");if(r&&r.visible()&&(r.hide(),this.buttonElement.setAttribute("data-tooltip-hide-at",`${Date.now()}`)),!e){this.buttonElement.parentElement&&(this.blockMenu.isInMenu(o.target)||this.buttonElement.remove());return}const i=Qm(e);this.editor.getBlockIndex(i)===0&&this.editor.getBlockData(i).heading===1||(this.updateButton(i),e2(i,this.buttonElement,Number.MAX_SAFE_INTEGER))});m(this,"handleButtonClick",()=>{if(this.buttonElement.getAttribute("data-type")==="move"){const o=this.blockMenu.currentBlock;if(!o)return;this.editor.selection.selectBlock(o,0),this.blockMenu.show(this.buttonElement,{placement:"bottom-end"}),setTimeout(()=>{Pu.get(this.editor).highlightBlock(o)});return}const t=this.emptyBlockMenu.currentBlock;!t||(this.editor.selection.selectBlock(t,0),setTimeout(()=>{this.editor.focus(),this.updatePlaceholder(t),this.emptyBlockMenu.show()}))});m(this,"updatePlaceholder",e=>{Le(e).setAttribute("data-content-placeholder",L.t("blockMenu.button.searchPlaceholder"))});m(this,"handleChanged",()=>{const e=this.emptyBlockMenu.currentBlock;if(!e)return;if(this.blockMenu.currentBlock){const o=ie(this.blockMenu.currentBlock);if(!this.editor.findBlockById(o)&&this.blockMenu.isVisible){this.blockMenu.close();return}}const t=ut(this.editor,e)?"insert":"move";this.buttonElement.getAttribute("data-type")!==t&&this.setButtonType(t)});this.editor=e,this.buttonElement=this.createButton(),this.emptyBlockMenu=new g$(e),this.blockMenu=new F$(e),this.editor.addListener("docChanged",this.handleChanged),this.buttonElement.addEventListener("click",this.handleButtonClick),this.dragHandler=new U$(this.editor,this);const t=Ct.get(e);t.addListener("change",this.handleHoverBlock),t.addFinder(new m$),Pu.register(this.editor)}destroy(){Ct.get(this.editor).removeListener("change",this.handleHoverBlock),this.buttonElement.removeEventListener("click",this.handleButtonClick),this.editor.removeListener("docChanged",this.handleChanged),this.emptyBlockMenu.destroy(),this.blockMenu.destroy(),this.buttonElement.remove(),this.dragHandler.destroy()}createButton(){const e=k("button",["block-button"],null);return e.setAttribute(`data-editor-tooltip-${this.editor.clientId}`,L.t("blockMenu.button.tips")),e.innerHTML=hv,e}setButtonType(e){this.buttonElement.setAttribute("data-type",e);const t=`data-editor-tooltip-${this.editor.clientId}-dynamic`;this.buttonElement.hasAttribute(t)&&this.buttonElement.removeAttribute(t),e==="insert"?(this.buttonElement.innerHTML=QL,this.buttonElement.setAttribute(t,L.t("blockMenu.button.insertTips"))):(this.buttonElement.innerHTML=hv,this.buttonElement.setAttribute(t,L.t("blockMenu.button.tips")))}updateButton(e){this.emptyBlockMenu.setBlock(e),this.blockMenu.setBlock(e),ut(this.editor,e)?this.setButtonType("insert"):this.setButtonType("move")}}const z$={blockMenu:{section:{basics:"\u57FA\u7840",system:"\u7CFB\u7EDF",styles:"\u6837\u5F0F",common:"\u901A\u7528",actions:"\u64CD\u4F5C",thirdParty:"\u7B2C\u4E09\u65B9\u5185\u5BB9"},command:{insertAbove:"\u5728\u4E0A\u65B9\u63D2\u5165",insertAfter:"\u5728\u4E0B\u65B9\u63D2\u5165",copy:"\u590D\u5236",cut:"\u526A\u5207",delete:"\u5220\u9664"},button:{searchPlaceholder:"\u8F93\u5165\u5173\u952E\u8BCD\u641C\u7D22",tips:`\u957F\u6309\u62D6\u62FD
432
+ `).map(s=>({id:K(),type:"text",text:Pi(s)})),o=K();return{blocks:{root:[{children:[o],type:"code",id:K(),...e}],[o]:t},meta:{},comments:{}}}class uN{handleBeforeCopy(e,t,o){const r=e.getFocusedBlock();if(!Bc(e,r))return;const i=N0(r),s=e.getBlockData(i),{language:l,nowrap:a}=s;if(e.selection.range.isCollapsed()){const h=e.getBlockString(r);return v9(h,{language:l,nowrap:a})}const d=e.getSelectedText();return v9(d,{language:l,nowrap:a})}}function dN(n){if(!n.isWritable())return!1;const e=n.getFocusedBlock();if(!!Bc(n,e)){if(n.selection.range.isCollapsed()){const t=n.selection.range.start;return n.insertTextToBlock(e,t.offset," "),!0}return n.undoManager.runInGroup(()=>{lr(n).forEach(o=>{n.insertTextToBlock(o.block,0," ")})}),!0}}function hN(n){if(!n.isWritable())return!1;const e=n.getFocusedBlock();if(!Bc(n,e))return;const t=[" "," "];return n.undoManager.runInGroup(()=>{lr(n).forEach(r=>{const i=st(n.getBlockText(r.block));for(let s=0;s<t.length;s++){const l=t[s];if(i.startsWith(l)){n.deleteTextFromBlock(r.block,0,l.length);break}}})}),!0}function fN(n){const e=n.getFocusedBlock(),t=oe(e);if(Ge(t))return;const o=ne(t);if(!o||De(o)!=="code")return;const r=n.selection.range;if(!!r.isSimple()&&!OA(t,r))return Xg(n,t),!0}const mN={Tab:dN,"Shift+Tab":hN,"CtrlOrCmd+A":fN},xu=S("code-text-decorate");class Nf{decorateText(e,t,o){var v;if(g(xu,t.length>0,"invalid path"),t.length===1)return{};const r=t[t.length-2];if(e.doc.getBlockData(r.containerId,r.blockIndex).type!=="code")return{};const s=o;if(s.length===0)return{};const l=st(s),a=e.doc.getBlockData(r.containerId,r.blockIndex),d=ga.default.tokenize(l,(v=ga.default.languages[a.language])!=null?v:ga.default.languages.plain),h=(B,D)=>{if(g(xu,B,"no token"),typeof B=="string")return[{insert:B,attributes:me.default(D)}];g(xu,B instanceof ga.default.Token,"invalid token type");const x=B.content,_=me.default(D);return _[`style-code-${B.type}`]=!0,typeof x=="string"?[{insert:x,attributes:_}]:Array.isArray(x)?x.map(z=>h(z,_)).flat():(g(xu,x instanceof ga.default.Token,"invalid token"),h(x,_))},C=d.map(B=>h(B,{})).flat();return g(xu,rn(C)===rn(s),"failed to highlight code, text length mismatch"),{text:C}}}const gN={code:{title:"\u4EE3\u7801",abstract:"\u4EE3\u7801",wrap:"\u6362\u884C",copy:"\u590D\u5236",caption:"\u8BF4\u660E",search:"\u8F93\u5165\u5173\u952E\u8BCD\u641C\u7D22",copySuccess:"\u590D\u5236\u6210\u529F"}},pN={code:{title:"Code",abstract:"Code",wrap:"Wrap",copy:"Copy",caption:"Caption",search:"Search",copySuccess:"Copied successfully"}},CN={code:{title:"\u30B3\u30FC\u30C9",abstract:"\u30B3\u30FC\u30C9",wrap:"\u6298\u308A\u8FD4\u3059",copy:"\u8907\u88FD",caption:"\u4F8B\u8A3C\u3059\u308B",search:"\u30AD\u30FC\u30EF\u30FC\u30C9\u3067\u691C\u7D22",copySuccess:"\u30B3\u30D4\u30FC\u3055\u308C\u307E\u3057\u305F"}};L.mergeLang({"zh-CN":gN,"en-US":pN,"ja-JP":CN});function AN(n,e,t,o){const r=n.getBlockByIndex(e,t);if(ue(n,r)!==o)return!1;const i=st(n.getBlockText(r));if(![...i].every(h=>h==="|")||i.length<3||!n.editorBlocks.hasBlock("table"))return!1;const s=n.editorBlocks.getBlockClass("table");if(!s.convertFrom)return!1;const l=s.convertFrom(n,r,{offset:o});if(!l)return!1;const{blockData:a,focusBlockId:d}=l;return a?(n.undoManager.runInGroup(()=>{var p;const h=n.insertBlock(e,t,a,kt(n,d!=null?d:a.id,0));n.deleteBlock(r),(p=l.onConverted)==null||p.call(l,n,h)}),!0):!1}const bN={mermaid:{blockType:"embed",reg:/^```mermaid$/,data:{embedType:"mermaid"}},flowchart:{blockType:"embed",reg:/^```flowchart$/,data:{embedType:"flowchart"}},plantuml:{blockType:"embed",reg:/^```plantuml$/,data:{embedType:"plantuml"}},code:{blockType:"code",reg:/^```\S+$/},code2:{blockType:"code",reg:/^```$/},table:{blockType:"table",reg:/^\|.+\|.+\|$/},math:{blockType:"embed",reg:/^\$\$.+\$\$$/},image:{blockType:"embed",reg:/^!\[[^\]]*\]\((?<filename>.*?)(?="|\))(?<optionalPart>".*")?\)/,data:{embedType:"image"}},dividing:{blockType:"embed",reg:/^-{3,}$/,data:{embedType:"dividing-line"}},toc:{blockType:"embed",reg:/^\[toc\]/,data:{embedType:"toc"}}},vN={orderedList:{reg:/^(\d)+(\.|。)$/,blockType:"list",data:{listType:"ordered"}},unorderedList1:{reg:/^\*$/,blockType:"list",data:{listType:"unordered"}},unorderedList2:{reg:/^-$/,blockType:"list",data:{listType:"unordered"}},checkList1:{reg:/^\[\s?\]$/,blockType:"list",data:{listType:"unchecked"}},checkList2:{reg:/^\[X\]$/i,blockType:"list",data:{listType:"checked"}},image:{blockType:"embed",reg:/^!\[[^\]]*\]\((?<filename>.*?)(?="|\))(?<optionalPart>".*")?\)/,data:{embedType:"image"}}};function $f(n,e,t,o,r){const i=n.getContainerById(e);if(!Ge(i)){const s=ne(i);if(s&&br(s))return!0}return!1}function y9(n,e,t,o,r){if($f(n,e))return!1;if(r==="enter"&&AN(n,e,t,o))return!0;const i=n.getBlockByIndex(e,t),s=st(Tn(n.getBlockText(i),o).left).trim(),l=r==="enter"?bN:vN;for(const[,a]of Object.entries(l)){if(!s.match(a.reg))continue;return!!n.undoManager.runInGroup(()=>{var B;const h=ah(n,i,a.blockType,{offset:o,data:a.data});if(!h)return null;const{blockData:p,focusBlockId:C}=h;if(!p)return null;const v=n.insertBlock(e,t,p,kt(n,C!=null?C:p.id,0));return n.deleteBlock(i),(B=h.onConverted)==null||B.call(h,n,v),{newBlock:v,focusBlockId:C}})}return!1}function yN(n,e,t,o){const r=n.getBlockByIndex(e,t);return n.getBlockString(r,{boxReplacement:" "}).substring(0,o)!==">"?!1:(n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,0,o+1),n.updateBlockData(r,{quoted:!0},kt(n,r,0))}),!0)}const kN={"#":1,"##":2,"###":3,"####":4,"#####":5,"######":6,"#######":7,"########":8};function wN(n,e,t,o){const r=n.getBlockByIndex(e,t),i=n.getBlockString(r,{boxReplacement:" "}).substring(0,o);let s=kN[i];if(!s)return!1;const l=n.getBlockData(r).heading;return l&&l==s&&(s=null),n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,0,o+1),n.updateBlockData(r,{heading:s},kt(n,r,0))}),!0}function BN(n,e,t,o){return!!(wN(n,e,t,o)||yN(n,e,t,o))}const EN=S("match-text-style");function xN(n,e){if(n.length<e.length*2+1||!n.endsWith(e)||n.substring(0,n.length-1).endsWith(e))return-1;const t=n.substring(0,n.length-e.length),o=t.lastIndexOf(e);return o===-1?-1:o===0?0:t.substring(o-1).startsWith(e)?-1:o}const IN={"*":{type:"style",styles:["style-italic"],boxType:""},"**":{type:"style",styles:["style-bold"],boxType:""},"***":{type:"style",styles:["style-bold","style-italic"],boxType:""},"~~":{type:"style",styles:["style-strikethrough"],boxType:""},"`":{type:"style",styles:["style-code"],boxType:""},$$:{type:"box",styles:[],boxType:"math"}};function TN(n,e,t,o){var C,v;const r=n.getBlockByIndex(e,t),i=n.getBlockText(r),{left:s}=Tn(i,o),l=bg(s),a=rn(s)-l.length,d=Object.entries(IN);for(const[B,D]of d){const x=xN(l,B);if(x===-1)continue;const _=a+x,R=o,H=B.length,z=st(Vt(i,_+H,R-_-H*2).middle);if(D.type==="style"){const Z={};D.styles.forEach(fe=>{Z[fe]=!0});const ee=Pi(z,Z);n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,_,R-_),n.insertTextToBlock(r,_,ee)})}else if(D.type==="box")try{const Z=(v=(C=n.editorBoxes.getBoxClass(D.boxType)).convertFrom)==null?void 0:v.call(C,n,z);if(!Z)continue;n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,_,R-_),n.insertBoxToBlock(r,_,Z)})}catch(Z){EN.warn(`failed to convert to box, ${Z.message}`);continue}return!0}const h=/\[([^\]]+)\]\((https?:\/\/\S+)\)\s*$/,p=l.match(h);if(p){const B=p.index,D=p[1],x=p[2],_=B,R=o,z={..._a(i,_),link:x};return n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,_,R-_),n.insertTextToBlock(r,_,Pi(D,z))}),!0}return!1}class Hf{handleAfterInsertText(e,t,o,r,i){if(i===" "){if($f(e,t))return!1;if(BN(e,t,o,r)||TN(e,t,o,r))return!0}return!1}handleBeforeKeyDown(e,t){if(!e.selection.range.isSimple())return!1;const{containerId:r,blockIndex:i,offset:s}=e.getTextPosition();if(te(e,e.getBlockByIndex(r,i))){if(or(t,"Enter")){if(y9(e,r,i,s,"enter"))return!0}else if(or(t,"Space")&&y9(e,r,i,s,"space"))return!0}return!1}}const DN={"en-US":{placeholder:{default:"Type / for commands",heading:"Heading {heading}",list:"List",mention:"Quickly assign tasks and use @ to mention yourself or others",quote:"Quote",title:"Enter document title"}},"zh-CN":{placeholder:{default:"\u8F93\u5165\u300C/\u300D\u5FEB\u901F\u63D2\u5165",heading:"\u6807\u9898{heading}",list:"\u5217\u8868",mention:"\u5FEB\u901F\u5206\u914D\u4EFB\u52A1\uFF0C@\u63D0\u53CA\u81EA\u5DF1\u6216\u4ED6\u4EBA",quote:"\u5F15\u7528",title:"\u8BF7\u8F93\u5165\u6587\u6863\u6807\u9898"}},"ja-JP":{placeholder:{default:"\u300C/\u300D\u3092\u5165\u529B\u3057\u3066\u7D20\u65E9\u304F\u633F\u5165\u3059\u308B",heading:"\u898B\u51FA\u3057{heading}",list:"\u30EA\u30B9\u30C8",mention:"\u81EA\u5206\u3084\u30E1\u30F3\u30D0\u30FC\u3092\uFF20\u3057\u3001\u30BF\u30B9\u30AF\u3092\u7D20\u65E9\u304F\u5272\u308A\u5F53\u3066\u307E\u3059",quote:"\u5F15\u7528",title:"\u30BF\u30A4\u30C8\u30EB\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"}}};L.mergeLang(DN);function Iu(n,e){const t=Ni(n,e);return!!(t.text&&rn(t.text)===0&&!e.querySelector(".inputting-insertion"))}function k9(n,e){var o;Le(e).removeAttribute("data-content-placeholder"),(o=e.querySelector("[data-type=block-tools] .block-placeholder-container"))==null||o.remove()}function jf(n,e,t){var r;if(!Iu(n,e)){k9(n,e);return}const o=Le(e);if(typeof t=="string")o.setAttribute("data-content-placeholder",t);else{const i=tt(e),s=(r=i.querySelector(".block-placeholder-container"))!=null?r:k("div",["block-placeholder-container"],i);s.innerHTML="",s.appendChild(t)}}function SN(n){const e=n.getAttribute("data-style-heading");return e?L.t("placeholder.heading",{heading:e}):n.getAttribute("data-style-quoted")?L.t("placeholder.quote"):null}function LN(n){const e=n.getAttribute("data-list-type");return e?e==="ordered"||e==="unordered"?L.t("placeholder.list"):L.t("placeholder.mention"):null}function w9(n){switch(De(n)){case"text":return SN(n);case"list":return LN(n);default:return null}}function MN(n){if(lo(n))return!1;const e=ne(oe(n));return e?De(e)==="code":!1}function RN(n){return!lo(n)}function ON(n,e){var h,p;const t=n.selection.focusedBlock,o=De(t),r=e.contentPlaceholder||L.t("placeholder.default");let i=r;if(o&&Ia(n,o)&&t){if(!n.isBlockWritable(t)||MN(t))return;RN(t)&&(i=L.t("placeholder.common.contentInTable")),i=(h=w9(t))!=null?h:i}const s=n.getFirstBlock(),l=Qe(s);if(!l)return;const a=Qe(l);if(a&&!e.addPlaceholderToAllCurrentEmptyBlock)return;if(!a&&Iu(n,l)){jf(n,l,(p=w9(l))!=null?p:r);return}const d=n.getFocusedBlock();!Iu(n,d)||d!==s&&jf(n,d,i)}function _N(n,e){var r,i;const t=n.getFirstBlock(),o=Le(t);Iu(n,t)?(o.setAttribute("data-title-placeholder",(r=e.titlePlaceholder)!=null?r:L.t("placeholder.title")),o.setAttribute("data-title-placeholder-readonly",(i=e.readonlyTitlePlaceholder)!=null?i:"")):(o.removeAttribute("data-title-placeholder"),o.removeAttribute("data-title-placeholder-readonly"))}function FN(n){n.rootContainer.querySelectorAll("[data-content-placeholder").forEach(e=>{e.removeAttribute("data-content-placeholder")}),n.rootContainer.querySelectorAll("[data-type=block-tools] .block-placeholder-container").forEach(e=>{e.remove()})}function PN(n,e){FN(n),n.selection.range.isCollapsed()&&(_N(n,e),ON(n,e))}const qne="";function NN(n){for(let e=1;e<n.length;e++){const t=n[e];if(t.attributes&&Object.keys(t.attributes).length)return!0}return!1}const B9=S("enforce-title");class Tu{constructor(e,t={headingLevel:1}){m(this,"handleSelectionChange",e=>{setTimeout(()=>{this.applyPlaceholder(e)})});this.options=t,this.handleChanged(e),this.applyPlaceholder(e),e.addListener("selectionChanged",this.handleSelectionChange)}destroy(e){e.removeListener("selectionChanged",this.handleSelectionChange)}handleBeforeKeyDown(e,t){if(!e.selection.range.isSimple())return!1;const{containerId:r,blockIndex:i,offset:s}=e.getTextPosition();if(!Tu.isDocumentTitleBlock(r,i)||!or(t,"Enter"))return!1;let l=!1,a=null;To(e.rootContainer)===2&&(a=Hr(e.rootContainer,1),ue(e,a)===0&&(l=!0));const d=e.getFirstBlock();return e.undoManager.runInGroup(()=>{e.breakTextBlock(d,s,{forceInsertAfter:!0}),l&&a&&e.deleteBlock(a)}),!0}handleChanged(e){var t,o;try{const r=e.doc.getContainerBlocks(ce(e.rootContainer));g(B9,r.length>0,"root container is empty");const i=r[0];if(i.type!=="text"){const s=ur("",{heading:(t=this.options.headingLevel)!=null?t:1});e.insertBlock(ce(e.rootContainer),0,s,e.selection.range.toDocRange());return}if(g(B9,i.text,"invalid text block"),NN(i.text)||i.quoted||i.heading!==this.options.headingLevel){const s=e.getBlockById(i.id),l=e.getBlockString(s),a=ur(l,{heading:(o=this.options.headingLevel)!=null?o:1,quoted:!1}),d=e.selection.focusedBlock;let h=e.selection.range;const p=e.insertBlock(ce(e.rootContainer),0,a);d===s&&(h=kt(e,a.id,ue(e,p))),Oh(e,s,h)}if(r.length>1)return;e.insertTextBlock("",ce(e.rootContainer),1,{newRange:e.selection.range.toDocRange()})}finally{this.applyPlaceholder(e)}}handleRemoteChanged(e){setTimeout(()=>{this.applyPlaceholder(e)})}handleUpdateCompositionText(e){this.applyPlaceholder(e)}applyPlaceholder(e){var t,o;!((t=this.options)!=null&&t.titlePlaceholder)&&!((o=this.options)!=null&&o.contentPlaceholder)||PN(e,this.options)}static isDocumentTitleBlock(e,t){return e==="root"&&t===0}}const $N=S("image-data"),E9=1e3,Z0=400,HN=10;function Ec(n){return n.src.startsWith("empty:")||!n.src}function jN(n){return n.src.startsWith("http:")||n.src.startsWith("https:")}function x9(n){return`${qd.default(n)}_width`}function I9(n){return`${qd.default(n)}_height`}function T9(n){return`${n}_flex`}function D9(n){let e=n.getBoundingClientRect().width;return e-=Number.parseFloat(window.getComputedStyle(n).paddingLeft)+Number.parseFloat(window.getComputedStyle(n).paddingRight),e}function Du(n){if(n.every(r=>typeof r.flex=="number"&&r.flex))return;const e=100,o=n.map(r=>{const i=r.height==="auto"?r.width/e:r.height/e;return r.width/i}).reduce((r,i)=>r+i,0);n.forEach(r=>{const i=r.height==="auto"?r.width/e:r.height/e,s=r.width/i;r.flex=s/o})}function xc(n){const e=(r,i)=>{r||(r=`empty:${i}`);const s=x9(r),l=I9(r),a=T9(i);let d=n[s],h=n[l],p=n[a];return typeof d=="string"&&(d=Number.parseInt(d,10)),typeof h=="string"&&(h=Number.parseInt(h,10)),typeof p=="string"&&(p=Number.parseInt(p,10)),d&&h?{src:r,width:d,height:h,flex:p,virtualSize:!1}:d&&!h?{src:r,width:d,height:"auto",flex:p,virtualSize:!1}:(d=E9,h=Z0,{src:r,width:d,height:h,flex:p,virtualSize:!0})};let t=[];const o=n.src;return Array.isArray(o)?t=o.map(e):typeof o=="string"&&(t=o.split("|").map(e)),Du(t),t}function Vo(n){const e=n.embedData;return xc(n.embedData).length>1?100:e.widthPercent}function UN(n,e,t,o){const r=xc(e.embedData);if(r.length>1||o)return"100%";const i=Vo(e),s=n.rootContainer.getBoundingClientRect().width;if(i){const l=D9(t);return`${Math.min(s*i/100,l)}px`}return r[0].width?`${r[0].width}px`:"auto"}function cn(n,e){const o={src:n.map(r=>r.src).join("|"),widthPercent:e};return n.forEach((r,i)=>{if(r.width&&r.height&&!r.virtualSize){const l=r.src||`empty:${i}`,a=x9(l);o[a]=r.width;const d=I9(l);r.height!=="auto"&&(o[d]=r.height)}g($N,r.flex,"no image flex");const s=T9(i);o[s]=r.flex}),o}function zN(n,e,t,o){const r=xc(e.embedData),i=r.length===1?n.rootContainer:t;if(r.length===1&&o)return`${Z0}px`;if(r.some(h=>h.height==="auto"))return"auto";const s=Vo(e);if(!s)return"";let l=i.getBoundingClientRect().width*(s/100);if(l-=Number.parseFloat(window.getComputedStyle(i).paddingLeft)+Number.parseFloat(window.getComputedStyle(i).paddingRight),i===n.rootContainer&&i!==t&&(l=Math.min(l,D9(t))),r.length===1){const h=r[0];return h.virtualSize?"":`${h.height/(h.width/l)}px`}l-=(r.length-1)*HN;const a=r.reduce((h,p)=>h+p.flex,0);let d=0;for(const h of r){const C=l*h.flex/a/h.width*h.height;d=Math.max(C,d)}return`${d}px`}function VN(n){return n.reduce((t,o)=>t+o.flex,0)}function WN(n,e){k("div",["resize-gripper",e],n).setAttribute("data-resize-type",e)}function Q0(n){return tt(n).querySelector(".block-resizer")}function qN(n){const e=Q0(n);e&&re(e,"active")}function S9(n,e,t){const o=n.getBoundingClientRect(),r=e.getBoundingClientRect(),i=r.top-o.top,s=r.left-o.left,l=r.width,a=r.height;t.style.top=`${i}px`,t.style.left=`${s}px`,t.style.width=`${l}px`,t.style.height=`${a}px`}function GN(n,e,t,o){const r=Q0(n);if(r)return W(r,"active"),S9(n,e,r),r;const i=tt(n),s=k("div",["block-resizer"],i);return S9(n,e,s),t.resize.forEach(l=>{WN(s,l)}),s.addEventListener("mousedown",o),W(s,"active"),s}function Y0(n,e){const t=Q0(n);if(!t||!et(n,e))return;const o=n.getBoundingClientRect(),r=e.getBoundingClientRect(),i=r.top-o.top,s=r.left-o.left,l=r.width,a=r.height;t.style.top=`${i}px`,t.style.left=`${s}px`,t.style.width=`${l}px`,t.style.height=`${a}px`}const Gne="",ZN=S("block-resizer");class Su extends vt.TypedEmitter{constructor(t,o){super();m(this,"resizableElement");m(this,"block",null);m(this,"startRect",null);m(this,"startPos",null);m(this,"resizeType",null);m(this,"enabled",!1);m(this,"handleMouseDown",t=>{t.preventDefault(),t.stopPropagation();const o=this.getResizableElement();if(!o||t.button!==0)return;const r=t.target;if(!r||!(r instanceof HTMLElement))return;const i=r.getAttribute("data-resize-type");!i||(this.bindEvents(),this.startRect=o.getBoundingClientRect(),this.startPos=t,this.resizeType=i,va(window.getComputedStyle(r).cursor),this.block&&this.editor.selection.selectBlock(this.block,0))});m(this,"handleMouseMove",t=>{if(!this.startPos||!this.startRect||!this.resizeType||!this.getResizableElement()||!this.block)return;const r=t.x-this.startPos.x,i=t.y-this.startPos.y,s=this.startRect;let{top:l,left:a,right:d,bottom:h}=s;(this.resizeType==="bottom"||this.resizeType==="bottom-left"||this.resizeType==="bottom-right")&&(h+=i),(this.resizeType==="top"||this.resizeType==="top-left"||this.resizeType==="top-right")&&(l+=i),(this.resizeType==="left"||this.resizeType==="top-left"||this.resizeType==="bottom-left")&&(a+=r),(this.resizeType==="right"||this.resizeType==="top-right"||this.resizeType==="bottom-right")&&(d+=r);const p=d>a?d-a:0,C=h>l?h-l:0,v=new DOMRect(a,l,p,C);this.emit("resizing",this,v);const B=this.getResizableElement();B&&Y0(this.block,B)});m(this,"handleMouseUp",t=>{if(t.button!==0)return;va(""),this.unbindEvents(),this.emit("resized",this);const o=this.getResizableElement();!o||!this.block||Y0(this.block,o)});this.editor=t,this.options=o}enableResize(t,o){this.block=t,this.resizableElement=o,this.createResizer(),this.enabled=!0}disableResize(){!this.block||(qN(this.block),this.enabled=!1)}update(t,o){this.block=t,this.resizableElement=o,this.getResizableElement()&&this.enabled&&this.createResizer()}updateResizer(){const t=this.getResizableElement();t&&this.block&&Y0(this.block,t)}getBlock(){return this.block}destroy(){}getResizableElement(){return this.resizableElement?this.resizableElement:this.block?Le(this.block):null}createResizer(){const t=this.getResizableElement();!t||!this.block||(g(ZN,et(this.block,t),"not a block child element"),GN(this.block,t,this.options,this.handleMouseDown))}bindEvents(){document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("mouseup",this.handleMouseUp)}unbindEvents(){document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp)}}const QN=S("image-dom");function L9(n){return n.querySelector(".uploading-progress-mask")}function YN(n){const e=L9(n);if(e)return e;const t=k("div",["uploading-progress-mask"],n),o=k("div",["uploading-progress-bar"],t);return k("div",["uploading-progress-bar-value"],o),o}function JN(n){const t=YN(n).querySelector(".uploading-progress-bar-value");return g(QN,t,"no progress value"),t}function M9(n,e){const t=JN(n);t.style.width=`${e}%`}function KN(n){var e;(e=L9(n))==null||e.remove()}function Lu(n,e,t,o){const r=t!=null?t:n.findBlockById(e.id);if(!r)return;const i=o||oe(r),s=!!r.querySelector(".images > .image-container.error, .images > .image-container.empty "),l=UN(n,e,i,s),a=zN(n,e,i,s),d=Le(r);l==="auto"?d.style.width=l:(d.style.maxWidth=l,d.style.width="100%");const h=r.querySelector(".images");!h||(h.style.height=a||"none")}function XN(n){let e;return n.forEach((t,o)=>{o.toLocaleLowerCase()==="content-type"&&(e=t)}),e!=null?e:""}async function e$(n){try{const e=await fetch(n,{credentials:"same-origin"}),t=await e.blob(),o=XN(e.headers).toLocaleLowerCase();let r="";if(o){const s=km.default[o].extensions;s&&s.length>0&&(r=s[0])}return new File([t],`${Date.now()}.${r}`,{type:o})}catch{return null}}function Ji(n,e){const t=typeof e=="string"?e:ie(e);return n.getCustom(`image-${t}`)}function Uf(n,e){if(!e||!(e instanceof Node))return null;const t=ne(e);return t?Ji(n,t):null}function yr(n){return Array.from(n.querySelectorAll(".image-container"))}const J0=S("table-resize-drag-drop");class t${constructor(e,t,o,r){m(this,"cursor","col-resize");m(this,"initWidths");this.editor=e,this.elem=t,this.data=o,this.mouseDownEvent=r;const i=this.data.block,l=Ji(this.editor,i).getImages(),a=this.data.splitterIndex;g(J0,a>=0&&a<l.length-1,`invalid splitter index: ${a}`);const h=yr(i).map(p=>p.getBoundingClientRect().width);this.initWidths=h}onDragStart(e,t,o){if(!this.editor.isWritable())return;const r=this.data.block;Ji(this.editor,r).setResizing(!0)}onDragging(e,t,o,r,i){const s=this.data.block,l=Ji(this.editor,s),a=me.default(l.getImages()),d=this.data.splitterIndex;g(J0,d>=0&&d<a.length-1,`invalid splitter index: ${d}`);const h=this.initWidths[d],p=this.initWidths[d+1];if(h+p<100)return;let C=r;h+C<50&&(C=50-h),p-C<50&&(C=p-50);const D=[...this.initWidths];D[d]+=C,D[d+1]-=C;const x=yr(s);g(J0,x.length===a.length,"invalid image data");const _=D.reduce((z,Z)=>z+Z,0);for(let z=0;z<a.length;z++){const Z=D[z]/_;a[z].flex=Z,x[z].style.flexGrow=`${Z}`}const R=me.default(this.editor.getBlockData(s)),H=cn(a,Vo(R));R.embedData=H,Lu(this.editor,R,s,null)}onDragEnd(e,t,o,r,i){const s=this.data.block,l=Ji(this.editor,s),d=yr(s).map(h=>Number.parseFloat(h.style.flexGrow));l.updateFlex(d),l.setResizing(!1)}}function R9(n){var e;return!n||!(n instanceof HTMLElement)?null:xe(n,"image-splitter")?n:(e=n.closest(".image-splitter"))!=null?e:null}function n$(n,e){var s;const t=R9(e.target);if(!t)return;const o=ne(t);if(!o)return;Ji(n,o).setSelectedIndex(-1),n.selection.selectBlock(o,0);const r=Number.parseInt((s=t.getAttribute("data-index"))!=null?s:"",10);if(Number.isNaN(r)||typeof r!="number")return;const i={block:o,splitterIndex:r};Dm(new t$(n,t,i,e))}function o$(n,e){e.preventDefault(),e.stopPropagation();const t=R9(e.target);if(!t)return;const o=ne(t);!o||Ji(n,o).resetFlex()}function r$(n,e,t,o){const r=k("div",["image-splitter"],t);k("div",["image-splitter-indicator"],r),r.setAttribute("data-index",`${o}`),n.domEvents.addEventListener(r,"mousedown",n$),n.domEvents.addEventListener(r,"dblclick",o$)}const i$=S("image-item");function O9(n){return!n||!(n instanceof Node)?null:ne(n)}function _9(n){const e=O9(n);return e?yr(e):[]}function K0(n){if(!n||!(n instanceof Node))return null;const e=n instanceof Element?n:n.parentElement;if(!e)return null;const t=e.closest(".image-container");return t||null}function Mu(n){const e=K0(n);return e?_9(n).indexOf(e):-1}async function s$(n,e){const t=Uf(n,e.target);if(!t)return;const o=Mu(e.target);if(o===-1)return;const r=e.target;if(!(r instanceof HTMLImageElement))return;const i=t.getImages()[o];if(Ec(i)||n.readonly||!t.isAutoFix()||(setTimeout(()=>{t.setAutoFix(!1)},400),i.height==="auto"&&t.fixImageSize(o,r),i.virtualSize&&t.fixImageSize(o,r),!i||!jN(i)||i.downloading))return;i.downloading=!0;const s=await e$(i.src);s?t.replaceImage(o,s):i$.warn(`failed to download image: ${i.src}`)}function l$(n,e,t){if(e.querySelector(".load-error"))return;const r=t.src.startsWith("http:")||t.src.startsWith("https:"),i=k("div",["load-error"],e),s=k("div",["error-icon"],i);s.innerHTML=rv;const l=k("div",["error-message"],i);r?(l.innerHTML=L.t("image.load.remote.failed"),n.domEvents.addEventListener(i,"click",(a,d)=>{d.preventDefault(),d.target instanceof HTMLElement&&d.target.tagName==="A"&&window.open(t.src,"_blank")})):(l.innerHTML=L.t("image.load.failed"),n.domEvents.addEventListener(i,"click",(a,d)=>{d.preventDefault(),d.stopPropagation(),d.target instanceof HTMLElement&&d.target.tagName==="A"&&d$(a,d.target)}))}function X0(n,e){setTimeout(()=>{if(et(n.rootContainer,e)){const t=n.getBlockData(e);Lu(n,t,null,null)}})}function c$(n,e){const t=Uf(n,e.target);if(!t)return;const o=Mu(e.target);if(o===-1)return;const r=t.getImages()[o];if(!r)return;const i=K0(e.target);if(!i)return;W(i,"error","error-load");const s=ne(i);s&&X0(n,s),i.innerHTML="",l$(n,i,r)}function a$(n,e,t){if(e.querySelector(".upload-error"))return;const r=k("div",["upload-error"],e),i=k("div",["error-icon"],r);i.innerHTML=rv;const s=k("div",["error-message"],r);s.innerHTML=L.t("image.upload.failed"),n.domEvents.addEventListener(r,"click",(l,a)=>{if(a.preventDefault(),!a.target||!(a.target instanceof Element)||a.target.tagName!=="A")return;const d=Uf(l,a.target),h=Mu(a.target);!d||h===-1||d.replaceImage(h,t)})}function F9(n,e,t,o,r){const i=yr(e)[t];!i||(W(i,"error","error-upload"),X0(n,e),i.innerHTML="",a$(n,i,r))}function P9(n,e,t,o,r,i,s){const l=k("div",["image-container"],t);if(l.setAttribute("data-src",o.src),s.length>1&&(l.style.flexShrink=`${o.flex}`,l.style.flexGrow=`${o.flex}`),i===r&&W(l,"active"),Ec(o)){W(l,"empty");const d=k("div",["upload-image-icon"],l);return d.innerHTML=wL,l}const a=k("img",["editor-image"],l);if(a.src=n.doc.buildResourceUrl(o.src),n.domEvents.addEventListener(a,"load",s$),n.domEvents.addEventListener(a,"error",c$),o.src.startsWith("https:")||o.src.startsWith("http:")){const d=k("div",["image-warning"],l);d.innerHTML=ov,d.setAttribute(`data-editor-tooltip-${n.clientId}`,L.t("image.load.remote.tooltip"))}return l}function u$(n,e,t,o,r){const i=k("div",["images"],t);return o.forEach((s,l)=>{l>0&&r$(n,e,i,l-1),P9(n,e,i,s,l,r,o)}),o.length>1&&W(e,"multi"),i}function N9(n,e,t,o,r,i){const l=Array.from(e.querySelectorAll(".image-container"))[o];if(!l)return;const a=P9(n,e,null,t,o,r,i);l.insertAdjacentElement("beforebegin",a),l.remove(),X0(n,e)}function Ru(n,e){return yr(n)[e]}function d$(n,e){const t=O9(e);if(!t)return;const o=Mu(e);if(o===-1)return;const r=Uf(n,e);if(!r)return;const i=r.getImages()[o];N9(n,t,i,o,r.getSelectedIndex(),r.getImages())}function Wo(n){return De(n)==="embed"&&fn(n)==="image"}async function $9(n){return new Promise((e,t)=>{const o=new Image;o.onload=()=>{e({width:o.naturalWidth,height:o.naturalHeight})},o.onerror=t,o.src=n})}async function h$(n){const e=await Ul(n);return $9(e)}function H9(n){var o;let e="image/*";const t=(o=n.getComponentOptions("image"))==null?void 0:o.allowedMedias;return t&&(e=t.map(r=>`.${r}`).join(",")),e}function j9(n,e){var s;const{maxSize:t,allowedMedias:o,callbacks:r}=(s=n.getComponentOptions("image"))!=null?s:{};if(t&&e.size>t){const l=new Error("image is too large");throw l.code="MaxMediaSize",r!=null&&r.onError&&(r==null||r.onError(n,l)),l}const i=Ba(e.name);if(o&&!o.includes(i)){const l=new Error(`media file is not allowed: ${i}`);throw l.code="NotAllowedFile",r!=null&&r.onError&&(r==null||r.onError(n,l)),l}}function U9(n){return n.startsWith("image/")}const z9=S("image-object");class Tt{constructor(e,t){m(this,"images",[]);m(this,"selectedIndex",-1);m(this,"blockResizer");m(this,"resizing",!1);m(this,"parentContainerResizerObserver",null);m(this,"autoFix",!1);m(this,"handleMouseDown",async(e,t)=>{const o=Mu(t.target);if(o===-1)return;const r=this.images[o];Ec(r)||this.setSelectedIndex(o)});m(this,"handleRootContainerResize",()=>{this.handleEditorResize(this.editor.rootContainer)});m(this,"handleEditorResize",e=>{if(this.isEmpty()||this.resizing)return;const t=this.editor.findBlockById(this.blockData.id);!t||oe(t)===e&&Lu(this.editor,this.blockData,t,null)});m(this,"handleResizing",(e,t)=>{const o=this.editor.findBlockById(this.blockData.id);if(!o)return;this.autoFix||this.setAutoFix(!0);const i=this.editor.rootContainer.getBoundingClientRect().width,s=o.getBoundingClientRect();let l=t.width>s.width?s.width:t.width;l<50&&(l=50);const a=l*100/i;this.blockData.embedData.widthPercent=a,Lu(this.editor,this.blockData,o,null)});m(this,"handleResized",e=>{const t=this.editor.findBlockById(this.blockData.id);if(!t)return;const o=cn(this.images,Vo(this.blockData));this.editor.updateEmbedData(t,o),this.blockResizer.enableResize(t)});m(this,"fixImageSizes",Mt.default(()=>{const e=this.editor.findBlockById(this.blockData.id);if(!e)return;const t=cn(this.images,Vo(this.blockData));this.editor.updateEmbedData(e,t)},1e3));this.editor=e,this.blockData=t,this.blockResizer=new Su(this.editor,{resize:["top-left","top-right","bottom-left","bottom-right"]}),this.blockResizer.addListener("resizing",this.handleResizing),this.blockResizer.addListener("resized",this.handleResized),this.images=xc(this.blockData.embedData)}destroy(){var e;this.blockResizer.removeAllListeners(),this.blockResizer.destroy(),this.editor.domEvents.removeEventListener(null,null,this.handleMouseDown),(e=this.parentContainerResizerObserver)==null||e.disconnect()}setAutoFix(e){this.autoFix=e}isAutoFix(){return this.autoFix}createContent(e,t,o){const r=u$(this.editor,t,o,this.images,this.selectedIndex);if(this.editor.domEvents.addEventListener(o,"mousedown",this.handleMouseDown),this.editor.addListener("resize",this.handleRootContainerResize),Mo(e)){const s=()=>{this.handleEditorResize(e)};this.parentContainerResizerObserver=new ResizeObserver(s),this.parentContainerResizerObserver.observe(e)}const i=()=>!!(this.images.length===1&&this.images[0].virtualSize);this.isEmpty()&&i()&&W(r,"empty"),Lu(this.editor,this.blockData,t,e),setTimeout(()=>{const s=this.editor.findBlockById(this.blockData.id);s&&this.blockResizer.update(s)})}getImages(){return this.images}getWidthPercent(){return Vo(this.blockData)}isEmpty(){return this.images.length===1&&Ec(this.images[0])}setResizing(e){this.resizing=e}getSelectedIndex(){return this.selectedIndex}getBlock(){return this.editor.findBlockById(this.blockData.id)}setSelectedIndex(e){const t=this.getBlock();if(!t||e===this.selectedIndex)return;if(this.selectedIndex!==-1){const r=Ru(t,this.selectedIndex);r&&re(r,"active")}this.selectedIndex=e;const o=Ru(t,e);o&&W(o,"active")}async requestUploadImage(e){const t=this.editor.findBlockById(this.blockData.id);if(!t)return;const o=Ru(t,e);if(xe(o,"error"))return;const r=H9(this.editor),i=await zl(r);await this.replaceImage(e,i)}tryEnableResizer(){const e=this.editor.findBlockById(this.blockData.id);if(!e||!this.editor.isWritable())return;const t=Ru(e,0);!this.isEmpty()&&this.images.length===1&&!xe(t,"error")&&this.blockResizer.enableResize(e)}disableResizer(){this.blockResizer.disableResize()}fixImageSize(e,t){const o=this.images[e];Ec(o)||(o.height==="auto"&&(o.height=t.height),o.width=t.naturalWidth,o.height=t.naturalHeight,o.virtualSize=!1,this.fixImageSizes())}removeImage(e){const t=this.editor.findBlockById(this.blockData.id);if(!t||e===-1||e>=this.images.length)return!1;const o=me.default(this.images);if(o.splice(e,1),o.length===0)return this.editor.deleteBlock(t),!0;o[0].flex=NaN,Du(o),this.selectedIndex>=o.length&&(this.selectedIndex=o.length-1);const r=cn(o,Vo(this.blockData));return this.editor.updateEmbedData(t,r),!0}async replaceImage(e,t){const o=this.editor.findBlockById(this.blockData.id);if(!o)return!1;try{const i=await Ul(t),s=this.images[e];if(s.virtualSize){const{width:a,height:d}=await $9(i);s.width=a,s.height=d,s.virtualSize=!1;const h=cn(this.images,Vo(this.blockData));this.editor.updateEmbedData(o,h)}const l={...s,src:i};N9(this.editor,o,l,e,this.selectedIndex,this.images),setTimeout(()=>{this.blockResizer.update(o)})}catch(i){return F9(this.editor,o,e,i,t),!1}const r=Ru(o,e);if(!r)return!1;W(r,"uploading"),M9(r,0),W(o,"media-block-uploading");try{const i=await this.editor.doc.uploadResource(t,{onProgress:a=>{M9(r,a)}});re(r,"uploading"),this.images[e].src=i.resourceId;const s=this.editor.findBlockById(this.blockData.id);if(!s)return!1;re(s,"media-block-uploading");const l=cn(this.images,Vo(this.blockData));return this.editor.updateEmbedData(s,l),!0}catch(i){z9.error(i);const s=this.editor.findBlockById(this.blockData.id);return s&&(re(r,"uploading"),KN(r),F9(this.editor,s,e,i,t),re(s,"media-block-uploading")),!1}}updateFlex(e){const t=this.editor.findBlockById(this.blockData.id);if(!t)return;g(z9,e.length===this.images.length,"invalid flex");for(let r=0;r<this.images.length;r++)this.images[r].flex=e[r];const o=cn(this.images,Vo(this.blockData));this.editor.updateEmbedData(t,o)}resetFlex(){const e=this.editor.findBlockById(this.blockData.id);if(!e)return;const t=me.default(this.images);t[0].flex=NaN,Du(t);const o=cn(t,Vo(this.blockData));this.editor.updateEmbedData(e,o)}setData(e){this.blockData=e,this.images=xc(e.embedData)}static create(e,t){const o=e.addCustom(`image-${t.id}`,()=>new Tt(e,t));return o.setData(t),o}static getImageObject(e,t){let o;return typeof t=="string"?o=t:o=ie(t),e.getCustom(`image-${o}`)}}const Zne="",Qne="";function zf(n){const e=tt(n);let t=e.querySelector(":scope > .block-helper");return t||(t=k("div",["block-helper"],e),k("span",["helper-sizer"],t,"A")),t}function e2(n,e,t){const o=zf(n),i=Array.from(o.children).find(s=>{var a;return Number.parseInt((a=s.getAttribute("data-index"))!=null?a:"0",10)>t});o.insertBefore(e,i!=null?i:null)}const V9=40,f$=20;class m${findTargetBlock(e,t){const o=t.target;if(o&&o instanceof Element){const a=ne(o);if(a&&et(e.rootContainer,a))return a}let r=t.clientX,i=t.clientY;const s=e.rootContainer.getBoundingClientRect().left;r<s&&s-r<V9&&(r+=V9);let l=document.elementFromPoint(r,i);if(l){const a=ne(l);if(a&&et(e.rootContainer,a))return a}if(i-=f$,l=document.elementFromPoint(r,i),l){const a=ne(l);if(a&&et(e.rootContainer,a))return a}return null}destroy(){}}class g$ extends Df{constructor(t){super(t,{trigger:[],id:"empty-block-menu"});m(this,"currentBlock",null)}get isVisible(){return this.suggest.menu.isVisible}isInMenu(t){return this.menu.isInCommandBar(t)}show(){const o=this.editor.selection.focusedBlock;this.suggest.popup(o,0,"","")}setBlock(t){this.currentBlock=t}}function p$(n,e,t){const o=Ym(n,e);if(!o)return[];const r=[];return Object.values(o).forEach(i=>{t!=null&&t.has(i.group)||r.push(...i.commands.map(s=>({...s,source:"block-command",blockMenuItemCustomData:i.group})))}),r}function t2(n,e,t){const o=L0(n,t),r=i=>{i.forEach(s=>{s.source=e,s.children&&r(s.children)})};return r(o),o}function C$(n,e,t,o=!1){var d,h;const r=oe(e);let s=be(e);ut(n,e)||o||(s+=1);const l=ce(r),a=t;return a.commandProvider?a.commandProvider.executeCommand(n,t,{from:"block-menu",containerId:l,blockIndex:s}):(h=(d=a.blockOptions)==null?void 0:d.handleInsertEmptyBlock)==null?void 0:h.call(d,n,{containerId:l,blockIndex:s,item:t})}function A$(n,e){const t=So(n,e),o=n.getBlockData(e);return!(t!=="text"||o.heading)}class W9{constructor(e,t,o){m(this,"source","text-style");m(this,"id","text-style-item");m(this,"name","Text styles");m(this,"element");m(this,"textStylesTooltips",{});m(this,"createHeadingItemElement",(e,t,o)=>{var i;const r=I0();this.createItem("text",lu,t,A$(this.editor,e)),(i=r.insertBlockCommandItems)==null||i.forEach(s=>{s.id&&s.icon&&this.createItem(s.id,s.icon,t,o?o===Number(s.value):!1)})});m(this,"createListItemElement",(e,t,o)=>{const{checkbox:r,ordered:i}=o,l=De(e)==="list",a=l&&i===!1&&!r,d=l&&i,h=l&&!!r;this.createItem("unordered-list",uv,t,a),this.createItem("ordered-list",dv,t,d),this.createItem("check-list",cv,t,h)});m(this,"handleClick",(e,t)=>{var l,a;if(!t.target||!(t.target instanceof Node))return;const o=t.target instanceof Element?t.target:t.target.parentElement;if(!o)return;const r=o.closest(".text-style-item");if(!r)return;const i=r.id,s="heading-";if(i==="text"&&If(e,this.block,null),i.startsWith(s)){const d=Number.parseInt(i.substring(s.length),10);d&&If(e,this.block,d)}if(i==="blockquote"&&B0(e,this.block),i.startsWith("align")){const d=i.replace(/^align-/,"");S7(e,this.block,d)}(i==="unordered-list"||i==="ordered-list"||i==="check-list")&&x0(e,this.block,i),(a=(l=this.options).onAfterStyleItemClick)==null||a.call(l)});m(this,"calcTextStyleItemTooltipsEnum",()=>{this.textStylesTooltips={text:{title:L.t("commands.text")},blockquote:{title:L.t("commands.quote")},"align-left":{title:L.t("commands.alignLeft")},"align-center":{title:L.t("commands.alignCenter")},"align-right":{title:L.t("commands.alignRight")},"unordered-list":{title:L.t("commands.unordered")},"ordered-list":{title:L.t("commands.ordered")},"check-list":{title:L.t("commands.check")}};let e=1;for(;e<=8;)this.textStylesTooltips[`heading-${e}`]={title:L.t("commands.heading",{name:`${e}`})},e++});this.editor=e,this.block=t,this.options=o,this.calcTextStyleItemTooltipsEnum(),this.element=this.createItemElement(e,t),e.domEvents.addEventListener(this.element,"click",this.handleClick)}createItemElement(e,t){const o=k("div",["text-styles"],null),r=k("div",["text-style-section"],o),i=e.getBlockData(t);if(!this.options.fromEmbed){const l=i.heading,a=i.quoted;this.createHeadingItemElement(t,r,l),this.createListItemElement(t,r,i),this.createItem("blockquote",av,r,!!a)}const s=i.align||"left";return this.createItem("align-left",su,r,s==="left"),this.createItem("align-center",Rp,r,s==="center"),this.createItem("align-right",Mp,r,s==="right"),o}createItem(e,t,o,r=!1){const i=["style-icon","text-style-item"];r&&i.push("active");const s=$l(t,i,o);s.id=e;const l=this.textStylesTooltips[e];if(!l)return;const{title:a,shortcut:d}=l;s.setAttribute(`data-editor-tooltip-${this.editor.clientId}`,a),d&&s.setAttribute(`data-editor-tooltip-desc-${this.editor.clientId}`,io(d))}}function q9(){return{source:"separator",type:"separator",id:`section-${K()}`,name:""}}const G9={copy:HL,cut:jL,delete:UL,"lock-block":zL,"unlock-block":VL,comment:ic},b$=["image","video"];function v$(n,e,t){const o=[],r=te(n,e),i=It(e)&&b$.includes(fn(e)),s=i&&(fn(e)!=="image"||fn(e)==="image"&&yr(e).length===1);if(r?o.push(new W9(n,e,t)):i&&s&&o.push(new W9(n,e,{...t,fromEmbed:!0})),!ut(n,e)){(r||i&&s)&&o.push(q9());const l=p$(n,e,new Set(["hovering-toolbar"]));l.sort((a,d)=>{var h,p;return((h=a.order)!=null?h:0)-((p=d.order)!=null?p:0)}),l.forEach(a=>{a.id in G9&&(a.icon=G9[a.id])}),o.push(...l)}return ut(n,e)?o.push(...t2(n,"insert-block",{withPlainText:!1,from:"block-menu"})):o.push(q9(),{id:"insert-block-before",icon:WL,name:L.t("blockMenu.command.insertAbove"),children:t2(n,"insert-block-before",{withPlainText:!0,from:"block-menu"}),childrenMenuId:"quick-menu",source:"insert-block-before"},{id:"insert-block-after",icon:qL,name:L.t("blockMenu.command.insertAfter"),children:t2(n,"insert-block",{withPlainText:!0,from:"block-menu"}),source:"insert-block",childrenMenuId:"quick-menu"}),o}function y$(n,e,t){if(t.source==="block-command"){const o=t.blockMenuItemCustomData;f4(n,e,o,t)}else(t.source==="insert-block"||t.source==="insert-block-before")&&C$(n,e,t,t.source==="insert-block-before")}const k$=S("exclusive-block");function n2(n,e,t,o){var l;W(e,"block-exclusive");const r=Ye(n,e),i=(l=r.getBlockProperties)==null?void 0:l.call(r,n,e),{abstract:s}=i||{};e.setAttribute("data-user-name",o),e.setAttribute("data-user-id",t),e.setAttribute("data-exclusive-tips",L.t("exclusive.tips",{editor:o,embedType:s||L.t("exclusive.fallbackAbstract")}))}function Z9(n){re(n,"block-exclusive"),n.removeAttribute("data-user-name"),n.removeAttribute("data-user-id"),n.removeAttribute("data-exclusive-tips")}function w$(n,e,t,o,r){k$.debug(`block ${ie(e)} ${t?"exclusive":"unexclusive"}, ${o}, ${r}`),t?n2(n,e,o,r):Z9(e)}function Ou(n){return n.classList.contains("block-exclusive")}function Q9(n,e){e.blockIds.forEach(t=>{const o=n.findBlockById(t);o&&w$(n,o,e.exclusive,e.userId,e.displayName)})}class Ki{constructor(e){m(this,"exclusiveBlockIds",new Set);m(this,"exclusiveBlockTimer",0);m(this,"remoteExclusiveBlockIds",new Map);m(this,"handleUserChanged",e=>{const t=new Set(e.map(r=>r.userId));Array.from(this.remoteExclusiveBlockIds.entries()).forEach(([r,i])=>{if(!t.has(i.userId)){this.remoteExclusiveBlockIds.delete(r);const s={...i,exclusive:!1};Q9(this.editor,s)}});const o=Array.from(this.exclusiveBlockIds).map(r=>this.editor.findBlockById(r)).filter(r=>!!r);o.length>0&&this.broadcastExclusiveBlockMessage(o,!0)});this.editor=e,e.doc.registerCallback(this),e.doc.getRemoteUsers().addListener("change",this.handleUserChanged)}destroy(){this.stopExclusiveBlockTimer(),this.editor.doc.unregisterCallback(this),this.editor.doc.getRemoteUsers().addListener("change",this.handleUserChanged)}onCustomMessage(e){if(e.type==="exclusiveBlock"){const t=e;Q9(this.editor,t),t.blockIds.forEach(o=>{t.exclusive?this.remoteExclusiveBlockIds.set(o,t):this.remoteExclusiveBlockIds.delete(o)})}}getExclusiveMessage(e){return this.remoteExclusiveBlockIds.get(e)}broadcastExclusiveBlockMessage(e,t){if(this.editor.readonly||e.length===0)return;const o=this.editor.doc.getUser(),r={type:"exclusiveBlock",userId:o.userId,displayName:o.displayName,blockIds:e.map(i=>ie(i)),exclusive:t};this.editor.doc.broadcastMessage(r)}exclusiveBlock(e){this.exclusiveBlockIds.has(ie(e))||(this.broadcastExclusiveBlockMessage([e],!0),this.exclusiveBlockIds.add(ie(e)),this.exclusiveBlockIds.size===1&&this.startExclusiveBlockTimer())}unexclusiveBlock(e){!this.exclusiveBlockIds.has(ie(e))||(this.exclusiveBlockIds.delete(ie(e)),this.broadcastExclusiveBlockMessage([e],!1),this.exclusiveBlockIds.size===0&&this.stopExclusiveBlockTimer())}startExclusiveBlockTimer(){this.exclusiveBlockTimer=window.setInterval(()=>{Array.from(this.exclusiveBlockIds.keys()).forEach(e=>{this.broadcastExclusiveBlockMessage([this.editor.getBlockById(e)],!0)})},30*1e3)}stopExclusiveBlockTimer(){clearInterval(this.exclusiveBlockTimer),this.exclusiveBlockTimer=0}static get(e){return e.addCustom("exclusiveBlock",()=>new Ki(e))}static register(e){return this.get(e)}}function o2(n,e){Ki.get(n).exclusiveBlock(e)}function r2(n,e){Ki.get(n).unexclusiveBlock(e)}class Y9{writable(e,t){if(Array.isArray(t)){for(const o of t)if(Ou(o))return!1;return}if(Ou(t))return!1}create(e,t,o,r,i){const s=Ki.get(e).getExclusiveMessage(i.id);s&&n2(e,r,s.userId,s.displayName)}update(e,t,o,r,i){const s=Ki.get(e).getExclusiveMessage(i.id);s?n2(e,r,s.userId,s.displayName):Z9(r)}}const Yne="",B$={exclusive:{tips:"\u300C{editor}\u300D\u6B63\u5728\u7F16\u8F91\uFF0C\u300C{embedType}\u300D\u4E0D\u652F\u6301\u591A\u4EBA\u7F16\u8F91",fallbackAbstract:"\u8BE5 Block"}},E$={exclusive:{tips:"\u300C{editor}\u300Dis editing\uFF0C\u300C{embedType}\u300Ddoes not support multi-person editing",fallbackAbstract:"This Block"}},x$={exclusive:{tips:"\u300C{editor}\u300D\u306F\u7DE8\u96C6\u4E2D\u3067\u3059\u3002\u300C{embedType}\u300D\u306F\u8907\u6570\u4EBA\u3067\u540C\u6642\u7DE8\u96C6\u3067\u304D\u307E\u305B\u3093",fallbackAbstract:"\u3053\u306E\u8981\u7D20"}};L.mergeLang({"zh-CN":B$,"en-US":E$,"ja-JP":x$});function _u(n,e){return n.getBlockData(e).lock}function Vf(n,e){return!!_u(n,e)}function Fu(n,e){const t=_u(n,e);return t?t.userId===n.doc.getUser().userId:!1}function i2(n,e){const t=_u(n,e);return t?t.userId!==n.doc.getUser().userId:!1}function I$(n,e){if(n.readonly||!n.isBlockWritable(e)||Vf(n,e)&&!Fu(n,e))return;const t=n.doc.getUser(),o={userId:t.userId,displayName:t.displayName,locked:Date.now()},i={...n.getBlockData(e),lock:o};n.updateBlockData(e,i)}function T$(n,e){if(!Fu(n,e))return;const t={lock:null};n.updateBlockData(e,t)}const D$=10,S$=80;class s2{constructor(){m(this,"executeCommand",(e,t,o)=>{const r=o.data;if(!r||!r.blockId)return;const i=e.getBlockById(r.blockId);r.type==="lock"?I$(e,i):r.type==="unlock"&&T$(e,i)})}create(e,t,o,r,i){const s=i.lock;s&&(s.userId!==e.doc.getUser().userId?W(r,"locked-by-others"):W(r,"locked-by-self"))}update(e,t,o,r,i){const s=i.lock;if(s)if(s.userId!==e.doc.getUser().userId){W(r,"locked-by-others");const l=e.selection.focusedBlock;(l===r||et(r,l))&&(te(e,r)||De(r)==="code")&&e.insertTextBlock("",ce(o),be(r)+1)}else W(r,"locked-by-self");else re(r,"locked-by-others"),re(r,"locked-by-self")}writable(e,t){let o=[];Array.isArray(t)?o=t:o.push(t);for(const r of o){if(i2(e,r))return!1;if(lo(r))return;let i=Es(r);for(;i;){if(i2(e,i))return!1;i=Es(i)}}}commands(e,t){const o=Vf(e,t),r=Fu(e,t),i=Ou(t),s={blockId:ie(t),type:"lock"},l={id:"lock-block",name:"",data:s,order:10};if(o)if(r)l.id="unlock-block",l.name=L.t("locker.unlock"),s.type="unlock";else{const a=_u(e,t);let d=(a==null?void 0:a.displayName)||"";const h=F5(d,D$,S$);(h==null?void 0:h.length)!==d.length&&(l.ellipsisTooltip=a==null?void 0:a.displayName,d=h||""),l.name=L.t("locker.lockedBy",{name:d}),l.states=["disabled"]}else i?(l.name=L.t("locker.lock"),l.states=["disabled"]):l.name=L.t("locker.lock");return{group:"block-locker",commands:[l],executeCommand:this.executeCommand}}}const Jne="",L$={locker:{lock:"\u9501\u5B9A",unlock:"\u89E3\u9664\u9501\u5B9A",lockedBy:"\u88AB {name} \u9501\u5B9A"}},M$={locker:{lock:"Lock",unlock:"Unlock",lockedBy:"Locked by {name}"}},R$={locker:{lock:"\u30ED\u30C3\u30AF",unlock:"\u30ED\u30C3\u30AF\u89E3\u9664",lockedBy:"{name}\u304C\u30ED\u30C3\u30AF\u3057\u307E\u3057\u305F"}};L.mergeLang({"zh-CN":L$,"en-US":M$,"ja-JP":R$});class Wf{async handleBeforePasteDoc(e,t){return Object.values(t.blocks).forEach(o=>{o.forEach(r=>{delete r.lock})}),!1}}const O$=S("standard-block-actions");class _${constructor(){m(this,"executeCommand",(e,t,o)=>{const r=o.data;try{const i=e.getBlockById(r);if(o.id==="delete"){e.deleteBlock(i);return}o.id==="copy"&&Wh(e,i),o.id==="cut"&&(Wh(e,i),e.deleteBlock(i))}catch(i){O$.error(`failed to execute block command: ${JSON.stringify(i)}`)}})}commands(e,t){const o=Vf(e,t),r=o&&Fu(e,t),i=ie(t),s=V0(),l=Ou(t),a={id:"copy",name:L.t("blockMenu.command.copy"),data:i,order:10,states:s?[]:["disabled"],disableReason:s?void 0:L.t("copyCutProperty.unsafeEnvTips",{shortCut:io("CtrlOrCmd+C"),operation:L.t("copyCutProperty.copy")})},d={id:"cut",name:L.t("blockMenu.command.cut"),data:i,order:20,states:o&&!r||!s||l?["disabled"]:[],disableReason:s?void 0:L.t("copyCutProperty.unsafeEnvTips",{shortCut:io("CtrlOrCmd+X"),operation:L.t("copyCutProperty.cut")})},h={id:"delete",name:L.t("blockMenu.command.delete"),data:i,order:30,states:o&&!r||l?["disabled"]:[]};return{group:"standard-block-actions",commands:[a,d,h],executeCommand:this.executeCommand}}}const J9=S("block-menu");class F${constructor(e){m(this,"menu");m(this,"currentBlock",null);m(this,"commandBlock",null);m(this,"handleShow",()=>{g(J9,this.currentBlock,"no target block before show block menu");const e=v$(this.editor,this.currentBlock,{onAfterStyleItemClick:this.close});this.menu.updateItems(e),this.commandBlock=this.currentBlock});m(this,"handleClose",()=>{$p(this.editor)&&this.editor.focus()});m(this,"handleItemClick",(e,t)=>{g(J9,this.commandBlock,"no command block before show block menu"),y$(this.editor,this.commandBlock,t),t.element||this.close()});m(this,"close",()=>{this.menu.close("clickItem")});this.editor=e,this.menu=new Us([],void 0,{id:"block-menu"}),this.menu.on("show",this.handleShow),this.menu.on("close",this.handleClose),this.menu.on("click",this.handleItemClick),e.blockHooks.push(new _$)}show(e,t){this.menu.manualShow(e,{placement:"bottom-start",...t})}isInMenu(e){return this.menu.isInCommandBar(e)}setBlock(e){this.currentBlock=e}get isVisible(){return this.menu.isVisible}destroy(){this.menu.destroy()}}const P$=1e3;async function N$(n,e){const{width:t}=n.rootContainer.getBoundingClientRect(),o=e.getBoundingClientRect();return o.width>t||o.height>=P$?"":(await K3.default.toSvg(e)).replace(/margin-block:.*?;/,"").replace(/margin:.*?;/,"")}const $$=S("drag-preview-image");class H${constructor(e){m(this,"startPosition",null);m(this,"dragContainer",null);m(this,"handleDragStart",async(e,t)=>{const o=e.target;g($$,o instanceof Element,`Invalid Drag target:${o}`);const{x:r,y:i}=e;this.startPosition={x:r,y:i};const s=k("div",["drag-image-container"],this.editor.rootContainer),l=k("img",["drag-image"],s),a=k("span",["drag-loading"],s);a.innerHTML=YL;const{x:d,width:h,height:p,y:C}=o.getBoundingClientRect(),v=this.editor.rootContainer.getBoundingClientRect(),B=t.getBoundingClientRect();s.style.left=`${d+h}px`,s.style.top=`${C+p}px`,s.style.width=`${Math.min(v.width/2,B.width)}px`,this.dragContainer=s;const x=await N$(this.editor,t);x?l.src=x:W(s,"drag-placeholder"),xm(s,{status:"loaded"})});m(this,"handleDrag",e=>{if(this.startPosition&&this.dragContainer){const{x:t,y:o}=e;if(t===0&&o===0){this.dragContainer.style.transition="transform 0.15s, opacity .15s",this.dragContainer.style.transform="",this.dragContainer.style.opacity="0";return}const{x:r,y:i}=this.startPosition,s=t-r,l=o-i;this.dragContainer.style.transform=`translate(${s}px, ${l}px)`}});m(this,"handleDragEnd",()=>{this.dragContainer&&(this.dragContainer.remove(),this.startPosition=null,this.dragContainer=null)});this.editor=e}}const K9="drag-preview-element";function j$(n){if(xe(n,K9))return n;const e=n.querySelector(`.${K9}`);return e||(It(n)?Le(n):n)}const qf=S("block-menu-drag-handler");function l2(n,e){return new DragEvent(e,{bubbles:!0,cancelable:!0,view:window,screenX:n.screenX,screenY:n.screenY,dataTransfer:new DataTransfer,clientX:n.clientX,clientY:n.clientY})}class U${constructor(e,t){m(this,"dragPreview");m(this,"autoScroll");m(this,"oldPos",{x:0,y:0});m(this,"handleMouseDown",e=>{const t=this.button.blockMenu.currentBlock;if(g(qf,t,"no dragged block"),e.button!==0)return;if(!this.editor.isBlockWritable(t)){e.preventDefault(),e.stopPropagation();return}const{x:o,y:r}=e;this.oldPos={x:o,y:r},document.addEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.addEventListener("mousemove",this.handleDrag)});m(this,"handleDragStart",e=>{var s,l;const t=so(this.button.buttonElement);this.autoScroll||(this.autoScroll=new rh({scrollElement:t,trackMouseEvent:"mousemove",edge:{top:50,bottom:50}}));const o=this.button.blockMenu.currentBlock;g(qf,o,"no dragged block"),(l=(s=Ye(this.editor,o)).notify)==null||l.call(s,this.editor,"beginDrag");const r=l2(e,"dragstart");G$(this.editor,r,o),window.isDragging=!0,this.button.buttonElement.style.opacity="0";const i=j$(o);this.dragPreview.handleDragStart(e,i),this.autoScroll.active(),W(o,"dragging"),W(this.editor.contentElement,"dragging")});m(this,"handleDrag",e=>{const{target:t,x:o,y:r}=e;if(this.oldPos.x===o&&this.oldPos.y===r)return;window.isDragging||this.handleDragStart(e),this.oldPos={x:o,y:r},g(qf,t instanceof Element,"target is invalid"),this.dragPreview.handleDrag(e);const i=l2(e,"dragover");this.editor.contentElement.dispatchEvent(i)});m(this,"handleDragEnd",e=>{var r;const t=this.button.blockMenu.currentBlock;g(qf,t,"no dragged block"),window.isDragging=!1,this.button.buttonElement.style.opacity="1",this.dragPreview.handleDragEnd(),(r=this.autoScroll)==null||r.inactive(),re(t,"dragging"),re(this.editor.contentElement,"dragging"),document.removeEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.removeEventListener("mousemove",this.handleDrag);const o=l2(e,"drop");this.editor.contentElement.dispatchEvent(o)});this.editor=e,this.button=t,this.button.buttonElement.addEventListener("mousedown",this.handleMouseDown),this.dragPreview=new H$(e)}destroy(){this.button.buttonElement.removeEventListener("mousedown",this.handleMouseDown)}}class Pu{constructor(e){m(this,"highlightedBlockId","");m(this,"handleSelectionChange",()=>{this.clearHighlightedBlock()});this.editor=e,this.editor.addListener("selectionChanged",this.handleSelectionChange)}highlightBlock(e){this.clearHighlightedBlock(),this.highlightedBlockId=ie(e),W(e,"highlighted")}clearHighlightedBlock(){if(this.highlightedBlockId){const e=this.editor.findBlockById(this.highlightedBlockId);e&&re(e,"highlighted"),this.highlightedBlockId=""}}destroy(){}static register(e){return e.addCustom("editor-block-highlighter",()=>new Pu(e))}static get(e){return e.getCustom("editor-block-highlighter")}}class X9{constructor(e){m(this,"buttonElement");m(this,"emptyBlockMenu");m(this,"blockMenu");m(this,"dragHandler");m(this,"handleHoverBlock",(e,t,o)=>{if(this.emptyBlockMenu.isVisible||this.blockMenu.isVisible||!this.editor.isWritable())return;const r=this.editor.getCustom("editor-tooltip");if(r&&r.visible()&&(r.hide(),this.buttonElement.setAttribute("data-tooltip-hide-at",`${Date.now()}`)),!e){this.buttonElement.parentElement&&(this.blockMenu.isInMenu(o.target)||this.buttonElement.remove());return}const i=Qm(e);this.editor.getBlockIndex(i)===0&&this.editor.getBlockData(i).heading===1||(this.updateButton(i),e2(i,this.buttonElement,Number.MAX_SAFE_INTEGER))});m(this,"handleButtonClick",()=>{if(this.buttonElement.getAttribute("data-type")==="move"){const o=this.blockMenu.currentBlock;if(!o)return;this.editor.selection.selectBlock(o,0),this.blockMenu.show(this.buttonElement,{placement:"bottom-end"}),setTimeout(()=>{Pu.get(this.editor).highlightBlock(o)});return}const t=this.emptyBlockMenu.currentBlock;!t||(this.editor.selection.selectBlock(t,0),setTimeout(()=>{this.editor.focus(),this.updatePlaceholder(t),this.emptyBlockMenu.show()}))});m(this,"updatePlaceholder",e=>{Le(e).setAttribute("data-content-placeholder",L.t("blockMenu.button.searchPlaceholder"))});m(this,"handleChanged",()=>{const e=this.emptyBlockMenu.currentBlock;if(!e)return;if(this.blockMenu.currentBlock){const o=ie(this.blockMenu.currentBlock);if(!this.editor.findBlockById(o)&&this.blockMenu.isVisible){this.blockMenu.close();return}}const t=ut(this.editor,e)?"insert":"move";this.buttonElement.getAttribute("data-type")!==t&&this.setButtonType(t)});this.editor=e,this.buttonElement=this.createButton(),this.emptyBlockMenu=new g$(e),this.blockMenu=new F$(e),this.editor.addListener("docChanged",this.handleChanged),this.buttonElement.addEventListener("click",this.handleButtonClick),this.dragHandler=new U$(this.editor,this);const t=Ct.get(e);t.addListener("change",this.handleHoverBlock),t.addFinder(new m$),Pu.register(this.editor)}destroy(){Ct.get(this.editor).removeListener("change",this.handleHoverBlock),this.buttonElement.removeEventListener("click",this.handleButtonClick),this.editor.removeListener("docChanged",this.handleChanged),this.emptyBlockMenu.destroy(),this.blockMenu.destroy(),this.buttonElement.remove(),this.dragHandler.destroy()}createButton(){const e=k("button",["block-button"],null);return e.setAttribute(`data-editor-tooltip-${this.editor.clientId}`,L.t("blockMenu.button.tips")),e.innerHTML=hv,e}setButtonType(e){this.buttonElement.setAttribute("data-type",e);const t=`data-editor-tooltip-${this.editor.clientId}-dynamic`;this.buttonElement.hasAttribute(t)&&this.buttonElement.removeAttribute(t),e==="insert"?(this.buttonElement.innerHTML=QL,this.buttonElement.setAttribute(t,L.t("blockMenu.button.insertTips"))):(this.buttonElement.innerHTML=hv,this.buttonElement.setAttribute(t,L.t("blockMenu.button.tips")))}updateButton(e){this.emptyBlockMenu.setBlock(e),this.blockMenu.setBlock(e),ut(this.editor,e)?this.setButtonType("insert"):this.setButtonType("move")}}const z$={blockMenu:{section:{basics:"\u57FA\u7840",system:"\u7CFB\u7EDF",styles:"\u6837\u5F0F",common:"\u901A\u7528",actions:"\u64CD\u4F5C",thirdParty:"\u7B2C\u4E09\u65B9\u5185\u5BB9"},command:{insertAbove:"\u5728\u4E0A\u65B9\u63D2\u5165",insertAfter:"\u5728\u4E0B\u65B9\u63D2\u5165",copy:"\u590D\u5236",cut:"\u526A\u5207",delete:"\u5220\u9664"},button:{searchPlaceholder:"\u8F93\u5165\u5173\u952E\u8BCD\u641C\u7D22",tips:`\u957F\u6309\u62D6\u62FD
433
433
  \u70B9\u51FB\u6253\u5F00\u83DC\u5355`,insertTips:"\u70B9\u51FB\u6DFB\u52A0\u533A\u5757"}}},V$={blockMenu:{section:{basics:"Basic",system:"System",styles:"Styles",common:"Common",actions:"Actions",thirdParty:"Third-party content"},command:{insertAbove:"Insert above",insertAfter:"Insert below",copy:"Copy",cut:"Cut",delete:"Delete"},button:{searchPlaceholder:"Search",tips:`Hold to drag
434
434
  Click to open the menu`,insertTips:"Click to add block"}}},W$={blockMenu:{section:{basics:"\u4E00\u822C",system:"\u30B7\u30B9\u30C6\u30E0",styles:"\u30B9\u30BF\u30A4\u30EB",common:"\u4E00\u822C",actions:"\u64CD\u4F5C",thirdParty:"\u5916\u90E8\u30B3\u30F3\u30C6\u30F3\u30C4"},command:{insertAbove:"\u4E0A\u306B\u633F\u5165",insertAfter:"\u4E0B\u306B\u633F\u5165",copy:"\u8907\u88FD",cut:"\u5207\u308B",delete:"\u524A\u9664"},button:{searchPlaceholder:"\u30AD\u30FC\u30EF\u30FC\u30C9\u3067\u691C\u7D22",tips:"\u3092\u30C9\u30E9\u30C3\u30B0\u3057\u3066\u30AF\u30EA\u30C3\u30AF\u3067\u30E1\u30CB\u30E5\u30FC\u3092\u8868\u793A",insertTips:"\u30AF\u30EA\u30C3\u30AF\u3057\u3066\u30D6\u30ED\u30C3\u30AF\u3092\u8FFD\u52A0"}}};L.mergeLang({"zh-CN":z$,"en-US":V$,"ja-JP":W$});const Kne="";class q${constructor(){m(this,"dragObject",null)}setData(e){this.dragObject=e}getData(){return this.dragObject}clearData(){this.dragObject=null}destroy(){}}function Gf(n){return n.addCustom("drag-data",()=>new q$)}function c2(n,e){if(!e)return null;const t=Gf(n).getData();return!t||t.editorId!==n.id?null:t}function ey(n,e){const t=c2(n,e);return t?n.findBlockById(t.blockId):null}function G$(n,e,t){if(!e.dataTransfer)return;const r=oe(t),i=ce(r),s=ie(t),l={type:"block",editorId:n.id,containerId:i,blockId:s};Gf(n).setData(l)}function Z$(n,e,t,o,r){if(!e.dataTransfer)return;const s=oe(t),l=ce(s),a=ie(t),d={type:"custom",customType:o,editorId:n.id,containerId:l,blockId:a,data:r};Gf(n).setData(d)}function Q$(n){Gf(n).clearData()}const Y$=S("drop-indicator"),Zf=2;class J${constructor(e){m(this,"indicator");m(this,"target",null);this.editor=e,this.indicator=k("div",["editor-drop-indicator"],this.editor.contentElement)}show(e,t){const o=this.getIndicatorRect(e,t),r=this.editor.rootElement.getBoundingClientRect(),i=o.top-r.top,s=o.left-r.left;this.indicator.style.top=`${i}px`,this.indicator.style.left=`${s}px`,this.indicator.style.width=`${o.width}px`,this.indicator.style.height=`${o.height}px`,this.indicator.style.display="",this.target={block:e,insertPos:t}}hide(){this.indicator.style.display="none",this.target=null}getIndicatorRect(e,t){if(typeof t!="string")return t.rect;if(t==="before"){const s=Is(e);if(!s){g(Y$,Mo(oe(e)),"block does not in a child container");const d=e.getBoundingClientRect();return new DOMRect(d.x,d.y,d.width,Zf)}const l=s.getBoundingClientRect(),a=e.getBoundingClientRect();return new DOMRect(l.x,(l.bottom+a.top)/2,l.width,Zf)}const o=Ts(e);if(!o){const s=e.getBoundingClientRect();return new DOMRect(s.x,s.bottom,s.width,Zf)}const r=e.getBoundingClientRect(),i=o.getBoundingClientRect();return new DOMRect(r.x,(r.bottom+i.top)/2,r.width,Zf)}}const K$=S("find-drop-target");function X$(n,e){const t=document.elementFromPoint(n,e);if(!t)return null;if(jr(t)&&Mo(t))return t;const o=t.firstElementChild;return o&&jr(o)&&Mo(o)?o:null}function eH(n,e){const s=e,l=n;for(let a=0;a<2;a++){const d=l+a*50;for(let h=0;h<5;h++){const p=s+h*8,C=document.elementFromPoint(d,p);if(C){const D=ne(C);if(D)return D}if(h===0)continue;const v=s-h*8,B=document.elementFromPoint(d,v);if(B){const D=ne(B);if(D)return D}}}return null}function tH(n,e,t){const o=document.elementFromPoint(e,t);if(o){const h=ne(o);if(h&&!Me(n,h))return h}const r=new Set,i=X$(e,t);if(i){const h=i.getBoundingClientRect();t<h.top+h.height/2?r.add(yt(i)):r.add(Qt(i))}const s=eH(e,t);s&&r.add(s);const l=Array.from(r),a=h=>{for(let p=0;p<l.length;p++){const C=l[p];if(h!==C&&et(h,C))return!0}return!1},d=l.filter(h=>!a(h));return d.length>0?d[0]:null}function a2(n,e){if(n.readonly)return!1;const t=oe(e);if(Ge(t))return!0;const o=ne(t);return g(K$,o,"no parent block"),n.isBlockWritable(o)?a2(n,o):!1}const nH=S("drop-target");function oH(n,e){let t={};return/image/.test(e.type)?t=n.editorEmbeds.getEmbedClass("image"):/audio/.test(e.type)?t=n.editorEmbeds.getEmbedClass("audio"):/video/.test(e.type)&&(t=n.editorEmbeds.getEmbedClass("video")),g(nH,t,`unSupport file type ${e.type}`),t}async function ty(n,e,t,o){var i,s;let r=o;for(const l of e){const a=oH(n,l);a.getOptions&&await((s=(i=a.getOptions(n)).handleInsertEmptyEmbed)==null?void 0:s.call(i,n,{containerId:t,blockIndex:r,data:{file:l}}))&&(r+=1)}}class rH{constructor(e){m(this,"handleDrop",(e,t,o,r)=>{if(Array.isArray(t)){const i=t;if(i.length>0){const s=ce(o);return ty(e,i,s,r),!0}}return!1});this.editor=e}}class Nu{constructor(e){m(this,"indicator");m(this,"lastDropOverResult");m(this,"handlers",[]);m(this,"handleDragOver",e=>{if(!this.editor.isWritable())return;const t=i=>{var d,h;const s=c2(this.editor,i.dataTransfer),l=ey(this.editor,i.dataTransfer),a=this.findTargetBlock(l,i.x,i.y);if(a&&et(this.editor.rootContainer,a)){const p=this.findInsertPos(l,a,i.x,i.y,(h=s!=null?s:(d=i.dataTransfer)==null?void 0:d.items)!=null?h:null);if(p)return this.indicator.show(a,p),"move"}return this.indicator.hide(),"none"},o=(i,s)=>{i.dataTransfer&&(i.dataTransfer.dropEffect=s),s==="move"&&i.preventDefault()};if(this.lastDropOverResult&&e.x===this.lastDropOverResult.x&&e.y===this.lastDropOverResult.y){const i=this.lastDropOverResult.dropEffect;o(e,i);return}const r=t(e);o(e,r),this.lastDropOverResult={x:e.x,y:e.y,dropEffect:r}});m(this,"handleDrop",e=>{var i,s;e.stopPropagation(),setTimeout(()=>{this.indicator.hide()});const t=c2(this.editor,e.dataTransfer),o=Array.from((s=(i=e.dataTransfer)==null?void 0:i.files)!=null?s:[]);if(!t&&o.length===0){e.dataTransfer&&(e.dataTransfer.dropEffect="none");return}const r=this.indicator.target;if(r){const{block:l,insertPos:a}=r,d=ey(this.editor,e.dataTransfer);this.editor.undoManager.runInGroup(()=>{const h=Ye(this.editor,l);if(h.handleDrop&&h.handleDrop(this.editor,l,t!=null?t:o,a,{isSourceBlock:!1,targetBlock:l})){e.preventDefault(),this.editor.focus();return}if(d){const p=Ye(this.editor,d);if(p.handleDrop&&p.handleDrop(this.editor,d,t!=null?t:o,a,{isSourceBlock:!0,targetBlock:l})){e.preventDefault(),this.editor.focus();return}}if(typeof a=="string"){const p=oe(l);let C=be(l);a==="after"&&(C+=1),e.preventDefault();for(let v=0;v<this.handlers.length;v++)if(this.handlers[v].handleDrop(this.editor,d!=null?d:o,p,C)){this.editor.focus();return}if(d){const v=this.editor.getBlockData(d),B=$i(this.editor.editorBlocks,this.editor.doc.toJSON(),v),[D]=this.editor.insertDocAt(p,C,B);this.editor.selection.selectBlock(D,0),Pu.get(this.editor).highlightBlock(D),this.editor.deleteBlock(d),this.editor.focus()}}}),Q$(this.editor)}});m(this,"handleDragLeave",()=>{this.indicator.hide()});this.editor=e,this.indicator=new J$(this.editor),this.handlers.push(new rH(this.editor)),this.editor.contentElement.addEventListener("dragover",this.handleDragOver),this.editor.contentElement.addEventListener("dragleave",this.handleDragLeave),this.editor.contentElement.addEventListener("drop",this.handleDrop)}destroy(){this.editor.contentElement.removeEventListener("dragover",this.handleDragOver),this.editor.contentElement.removeEventListener("dragleave",this.handleDragLeave),this.editor.contentElement.removeEventListener("drop",this.handleDrop),this.handlers=[]}addHandler(e){this.handlers.push(e)}static register(e){return e.addCustom("drop-target",()=>new Nu(e))}static get(e){return e.getCustom("drop-target")}static find(e){return e.findCustom("drop-target")}canInsertAfter(e,t){return!(this.editor.readonly||Ts(t)===e&&e||!a2(this.editor,t))}canInsertBefore(e,t){return!(this.editor.readonly||Is(t)===e&&e||!a2(this.editor,t)||Ge(oe(t))&&be(t)===0)}canDrop(e,t){return e===null||e===t?!0:!et(e,t)}findTargetBlock(e,t,o){let r=tH(this.editor,t,o);if(!r||!et(this.editor.rootContainer,r))return null;const i=oe(r),s=ne(i);return s&&De(s)==="code"&&(r=s),this.canDrop(e,r)?r:null}findInsertPos(e,t,o,r,i){let s=t;for(;s;){const a=Ye(this.editor,s);if(a.handleDropOver){const d=a.handleDropOver(this.editor,s,i,o,r);if(d)return d;if(d===!1)return null}s=Es(s)}if(e===t)return"";const l=t.getBoundingClientRect();if(l.top<=r&&r<=l.bottom){if(r<l.top+l.height/2){if(this.canInsertBefore(e,t))return"before";if(this.canInsertAfter(e,t))return"after"}else{if(this.canInsertAfter(e,t))return"after";if(this.canInsertBefore(e,t))return"before"}return""}return r<l.top&&this.canInsertBefore(e,t)?"before":l.bottom<r&&this.canInsertAfter(e,t)?"after":""}}function ny(n,e,t){const o=Tt.getImageObject(n,e),r=me.default(o.getImages());if(r.length===1){n.deleteBlock(e);return}if(t===-1||t>=r.length)return;const i=VN(r);if(r.splice(t,1),r.length===1){const l=r[0],a=100*(l.flex/i);l.flex=1;const d=cn([l],a);n.updateEmbedData(e,d);return}r[0].flex=NaN,Du(r);const s=cn(r,o.getWidthPercent());n.updateEmbedData(e,s)}function iH(n,e,t,o){if(e.length===0||o==="after"||o==="before")return!1;let r=o.data;const i=Tt.getImageObject(n,t),s=me.default(i.getImages()),l=[],a=[];e.forEach(p=>{U9(p.type)&&s.length+l.length<6?l.push(p):a.push(p)}),l.forEach(p=>{try{j9(n,p)}catch{return}const C={src:"",flex:1,width:0,height:0,virtualSize:!0};s.splice(r,0,C);const v=cn(s,i.getWidthPercent());n.updateEmbedData(t,v),i.replaceImage(r,p),r+=1});const d=n.getBlockIndex(t)+1,h=ce(oe(t));return ty(n,a,h,d),!0}function sH(n,e,t,o,r){var s,l,a;if(nh(t))return iH(n,t,e,o);if(t.type!=="custom"||t.customType!=="image"||!t.data)return;const i=t.data;if(r.isSourceBlock){const d=r.targetBlock,h=oe(d);let p=be(d);o==="after"&&(p+=1);const v=100*(i.boundingRect.width/n.rootContainer.getBoundingClientRect().width),B=cn([i.image],v),D={id:K(),type:"embed",embedType:"image",embedData:B},x=(l=(s=n.options.componentsOptions)==null?void 0:s.image)==null?void 0:l.defaultAlign;x&&(D.align=x),n.insertBlock(ce(h),p,D),ny(n,e,i.index),(a=n.findCustom("drag-handler"))==null||a.handleDragEnd()}else{if(typeof o=="string")return;const d=e;let h=o.data;const p=Tt.getImageObject(n,d),C=me.default(p.getImages());h>C.length&&(h=C.length),n.undoManager.runInGroup(()=>{var B,D;p.setAutoFix(!0);const v=n.getBlockById(t.blockId);if(v===d){const x=i.index,_=h,R=i.image;if(x===_||_===x+1)return;let H=_;x<_?(C.splice(_,0,R),C.splice(x,1),H-=1):(C.splice(x,1),C.splice(_,0,R));const z=cn(C,p.getWidthPercent());n.updateEmbedData(d,z),p.setSelectedIndex(H),(B=n.findCustom("drag-handler"))==null||B.handleDragEnd()}else{C.splice(h,0,i.image),C[0].flex=NaN,Du(C);const x=cn(C,p.getWidthPercent());n.updateEmbedData(d,x),ny(n,v,i.index),(D=n.findCustom("drag-handler"))==null||D.handleDragEnd(),p.setSelectedIndex(h),n.selection.selectBlock(d,0)}})}return!0}const lH=2;function Qf(n,e,t){const o=yr(e);if(t<=0){const s=o[0].getBoundingClientRect();return new DOMRect(s.left-4,s.top,2,s.height)}if(t===o.length){const s=o[t-1].getBoundingClientRect();return new DOMRect(s.right+2,s.top,2,s.height)}const r=o[t-1].getBoundingClientRect(),i=o[t].getBoundingClientRect();return new DOMRect((i.left+r.right)/2-1,r.top,lH,r.height)}function cH(n,e,t,o,r){for(let i=0;i<t.length;i++){const l=t[i].getBoundingClientRect();if(o<=l.right)return o<=l.left+l.width/2?{rect:Qf(n,e,i),data:i}:{rect:Qf(n,e,i+1),data:i+1}}return o>t[t.length-1].getBoundingClientRect().right?{rect:Qf(n,e,t.length),data:t.length}:{rect:Qf(n,e,t.length),data:0}}function aH(n,e,t,o,r){const i=yr(e);if(t instanceof DataTransferItemList){if(!Array.from(t).some(s=>U9(s.type))||i.length>=6)return}else{if((t==null?void 0:t.type)==="block"||i.length>=6&&(t==null?void 0:t.blockId)!==ie(e))return;const s=ie(e);if(i.length===1&&s===(t==null?void 0:t.blockId))return}return cH(n,e,i,o)}async function uH(n){return await K3.default.toSvg(n)}function u2(n,e){return new DragEvent(e,{bubbles:!0,cancelable:!0,view:window,screenX:n.screenX,screenY:n.screenY,dataTransfer:new DataTransfer,clientX:n.clientX,clientY:n.clientY})}class dH{constructor(e){m(this,"img");m(this,"dragContainer",null);m(this,"autoScroll",null);m(this,"imageContainer",null);m(this,"startPosition",null);m(this,"handleMouseDown",e=>{const t=e.target;if(!t||!(t instanceof HTMLImageElement)||e.button!==0)return;const o=ne(t);if(!o||!Wo(o)||!this.editor.isBlockWritable(o)||this.editor.readonly)return;const r=Tt.getImageObject(this.editor,o);if(this.imageContainer=K0(e.target),!this.imageContainer)return;const s=_9(e.target).indexOf(this.imageContainer);if(s===-1)return;const l=r.getImages()[s];if(!l)return;const{x:a,y:d}=e;this.startPosition={x:a,y:d};const h={image:l,index:s,boundingRect:this.imageContainer.getBoundingClientRect()},p=u2(e,"dragstart");Z$(this.editor,p,o,"image",h),document.addEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.addEventListener("mousemove",this.handleDrag),e.preventDefault()});m(this,"handleDragStart",async e=>{if(!this.imageContainer)return;const t=ne(this.imageContainer);if(!t)return;const{x:o,y:r}=e,{width:i,height:s}=e.target.getBoundingClientRect(),l=tt(t),a=k("div",["drag-container"],l);a.style.left=`${o-i/4}px`,a.style.top=`${r-s/4}px`,a.style.width=`${Math.max(i/2,16)}px`,a.style.height=`${s/2}px`,this.dragContainer=a,W(this.editor.contentElement,"dragging");const d=so(t);this.autoScroll=new rh({scrollElement:d,trackMouseEvent:"mousemove",edge:{top:50,bottom:50}}),this.autoScroll.active();const h=k("img",["drag-target"],a),C=await uH(this.imageContainer);C&&(h.src=C)});m(this,"handleDrag",e=>{var i;const{x:t,y:o}=e;if(((i=this.startPosition)==null?void 0:i.x)===t&&this.startPosition.y===o)return;if(window.isDragging||(window.isDragging=!0,this.handleDragStart(e)),this.startPosition&&this.dragContainer){const{x:s,y:l}=e;if(s===0&&l===0){this.dragContainer.style.transform="",this.dragContainer.style.opacity="0";return}const{x:a,y:d}=this.startPosition,h=s-a,p=l-d;this.dragContainer.style.transform=`translate(${h}px, ${p}px)`,this.dragContainer.style.opacity="0.5"}const r=u2(e,"dragover");this.editor.contentElement.dispatchEvent(r)});m(this,"handleDragEnd",e=>{var t;if(window.isDragging=!1,this.dragContainer&&this.dragContainer.remove(),this.dragContainer=null,this.startPosition=null,this.imageContainer=null,(t=this.autoScroll)==null||t.inactive(),re(this.editor.contentElement,"dragging"),document.removeEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.removeEventListener("mousemove",this.handleDrag),e){const o=u2(e,"drop");this.editor.contentElement.dispatchEvent(o)}});this.editor=e,this.editor.rootContainer.addEventListener("mousedown",this.handleMouseDown),this.img=new Image,this.img.src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"}destroy(){this.editor.rootContainer.removeEventListener("mousedown",this.handleMouseDown)}}class hH{constructor(e){m(this,"handleFocusBlockChanged",(e,t,o)=>{const i=this.editor.getFocusedBlock();if(i&&Wo(i)){const s=Tt.getImageObject(this.editor,i);s.getImages().length>0&&s.getSelectedIndex()===-1&&s.setSelectedIndex(0)}o&&Wo(o)&&e.findCustom(`image-${o.id}`)&&Tt.getImageObject(this.editor,o).blockResizer.disableResize()});this.editor=e,this.editor.addListener("focusBlockChanged",this.handleFocusBlockChanged)}destroy(){this.editor.removeListener("focusBlockChanged",this.handleFocusBlockChanged)}}class fH{constructor(e){m(this,"currentResizer",null);m(this,"handleHoveringBlockChange",(e,t)=>{window.isDragging||(t&&this.disable(t),e&&(this.currentResizer=e,this.enable(e)))});this.editor=e,Ct.get(e).addListener("change",this.handleHoveringBlockChange)}destroy(){Ct.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}disable(e){Wo(e)&&Tt.getImageObject(this.editor,e).disableResizer()}enable(e){if(Wo(e)){const t=Tt.getImageObject(this.editor,e);this.editor.isBlockWritable(e)&&t.tryEnableResizer()}}}const mH={image:{title:"\u56FE\u7247",upload:{failed:'<div class="line-1">\u56FE\u7247\u4E0A\u4F20\u5931\u8D25</div><div class="line-2">\u7F51\u7EDC\u670D\u52A1\u5F02\u5E38\uFF0C\u4F60\u53EF\u4EE5 <a href="" class="retry-upload">\u91CD\u8BD5</a></div>'},load:{failed:'<div class="line-1">\u56FE\u7247\u52A0\u8F7D\u5931\u8D25</div><div class="line-2">\u7F51\u7EDC\u670D\u52A1\u5F02\u5E38\uFF0C\u4F60\u53EF\u4EE5 <a href="" class="retry-upload">\u91CD\u8BD5</a></div>',remote:{failed:'<div class="line-1">\u56FE\u7247\u52A0\u8F7D\u5931\u8D25</div><div class="line-2">\u8BE5\u56FE\u7247\u6765\u81EA\u5916\u90E8\u94FE\u63A5\uFF0C\u5916\u90E8\u94FE\u63A5\u5DF2\u5931\u6548</div><div class="line-3">\u8BF7\u5C06\u539F\u56FE\u4FDD\u5B58\u5230\u672C\u5730\u540E\u4E0A\u4F20\uFF0C <a href="" class="retry-upload">\u6253\u5F00\u56FE\u7247\u94FE\u63A5</a></div>',tooltip:"\u8BE5\u56FE\u7247\u6765\u81EA\u5916\u90E8\u94FE\u63A5\uFF0C\u5982\u679C\u94FE\u63A5\u5931\u6548\u56FE\u7247\u5C06\u65E0\u6CD5\u67E5\u770B\uFF0C\u5EFA\u8BAE\u4FDD\u5B58\u5230\u672C\u5730\u540E\u6DFB\u52A0\u5230\u9875\u9762\u4E2D"}},abstract:"\u56FE\u7247"}},gH={image:{title:"Image",upload:{failed:'<div class="line-1">Image upload failed</div><div class="line-2">Network error, you can <a href="" class="retry-upload">Retry</a></div>'},load:{failed:'<div class="line-1">Image failed to load</div><div class="line-2">Network error, you can <a href="" class="retry-upload">Retry</a></div>',remote:{failed:'<div class="line-1">Failed to load image</div><div class="line-2">This picture is from an expired external link</div><div class="line-3">Please save the original image to local drives and upload it. <a href="" class="retry-upload">Open image link</a></div>',tooltip:"This picture is from an external link. If the link expires, the picture will not be available. It's recommended to save it to local drives and add it to the page."}},abstract:"Image"}},pH={image:{title:"\u753B\u50CF",upload:{failed:'<div class="line-1">\u753B\u50CF\u3092\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F</div><div class="line-2">\u304A\u4F7F\u3044\u306E\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u63A5\u7D9A\u306B\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002\u6B21\u306E\u64CD\u4F5C\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002 <a href="" class="retry-upload">\u518D\u8A66\u884C</a></div>'},load:{failed:'<div class="line-1">\u753B\u50CF\u3092\u8AAD\u307F\u8FBC\u3081\u307E\u305B\u3093\u3067\u3057\u305F</div><div class="line-2">\u304A\u4F7F\u3044\u306E\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u63A5\u7D9A\u306B\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002\u6B21\u306E\u64CD\u4F5C\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002 <a href="" class="retry-upload">\u518D\u8A66\u884C</a></div>',remote:{failed:'<div class="line-1">\u753B\u50CF\u3092\u8AAD\u307F\u8FBC\u3081\u307E\u305B\u3093\u3067\u3057\u305F</div><div class="line-2">\u3053\u306E\u753B\u50CF\u306B\u30EA\u30F3\u30AF\u3057\u3066\u3044\u308B URL \u304C\u7121\u52B9\u306B\u306A\u3063\u3066\u3044\u307E\u3059\u306E\u3067\u3001\u8868\u793A\u3067\u304D\u307E\u305B\u3093</div><div class="line-3">\u753B\u50CF\u3092\u30ED\u30FC\u30AB\u30EB\u306B\u4FDD\u5B58\u3057\u3066\u30A2\u30C3\u30D7\u30ED\u30FC\u30C0\u3057\u3066\u304F\u3060\u3055\u3044 <a href="" class="retry-upload">\u753B\u50CF\u30EA\u30F3\u30AF\u3092\u958B\u304F</a></div>',tooltip:"\u3053\u306E\u753B\u50CF\u306F\u5916\u90E8\u306B\u30EA\u30F3\u30AF\u3057\u3066\u3044\u308B\u305F\u3081\u3001\u30EA\u30F3\u30AF\u304C\u7121\u52B9\u306B\u306A\u308B\u3068\u3001\u8868\u793A\u3067\u304D\u306A\u304F\u306A\u308A\u307E\u3059\u306E\u3067\u3001\u30ED\u30FC\u30AB\u30EB\u306B\u4FDD\u5B58\u3057\u3001\u30DA\u30FC\u30B8\u306B\u633F\u5165\u3059\u308B\u3053\u3068\u3092\u304A\u52E7\u3081\u3057\u307E\u3059"}},abstract:"\u753B\u50CF"}};L.mergeLang({"zh-CN":mH,"en-US":gH,"ja-JP":pH});function CH(n,e,t,o){const r=n.getBlockByIndex(e,t),i=n.getBlockText(r),{left:s}=Tn(i,o),l=st(s);let a=o;if(l.endsWith("![]()"))a-=5;else if(l.endsWith("![]"))a-=3;else return!1;const d=o;return zl("image/*").then(h=>{n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,a,d-a);let p=t+1;st(n.getBlockText(r)).trim()?(Kl(n,r,a,{forceInsertAfter:!0}),a===0&&(n.deleteBlock(r),p--)):(n.deleteBlock(r),p--),Jm(n,"image",e,p,{file:h})})}),!0}class AH{handleAfterInsertText(e,t,o,r,i){if(i===" "){if($f(e,t))return!1;if(CH(e,t,o,r))return!0}return!1}}function bH(n){const e=n.getFocusedBlock(),t=Ts(e);if(t&&Wo(t)){n.selection.selectBlock(t,0);const o=Tt.getImageObject(n,t);return o.getImages().length>0&&o.setSelectedIndex(0),!0}}function vH(n){const e=n.getFocusedBlock(),t=Is(e);if(t&&Wo(t)){n.selection.selectBlock(t,0);const o=Tt.getImageObject(n,t);return o.getImages().length>0&&o.setSelectedIndex(0),!0}}function yH(n){const t=n.getFocusedBlock();if(t&&Wo(t)){const o=Tt.getImageObject(n,t),r=o.getImages();if(r.length>0){const i=o.getSelectedIndex();if(i===-1)return o.setSelectedIndex(r.length-1),!0;if(i>0)return o.setSelectedIndex(i-1),!0}}}function kH(n){const t=n.getFocusedBlock();if(t&&Wo(t)){const o=Tt.getImageObject(n,t),r=o.getImages();if(r.length>0){const i=o.getSelectedIndex();if(i===-1)return o.setSelectedIndex(0),!0;if(i<r.length-1)return o.setSelectedIndex(i+1),!0}}}function d2(n){const t=n.getFocusedBlock();if(t&&Wo(t)){const o=Tt.getImageObject(n,t);if(o.getImages().length>0){const i=o.getSelectedIndex();if(i!==-1)return o.removeImage(i),!0}}}const wH={ArrowLeft:yH,ArrowRight:kH,ArrowUp:vH,ArrowDown:bH,Delete:d2,Backspace:d2},BH=S("copy-image");function EH(n,e,t,o){const r=t.getImages()[o],i=t.getImages().length===1?t.getWidthPercent():r.flex*100,s=cn([r],i),l={id:K(),type:"embed",embedType:"image",embedData:s},a=n.options.componentsOptions.image;a!=null&&a.defaultAlign&&(l.align=a.defaultAlign);const d={blocks:{root:[l]},comments:{},meta:{}},h=document.createElement("canvas");h.width=e.naturalWidth,h.height=e.naturalHeight;const p=h.getContext("2d");if(!p)return;const C={},v={};try{p.drawImage(e,0,0,h.width,h.height);const z=h.toDataURL("image/png").replace(/^data:image\/(png|jpg);base64,/,""),Z=Om(z),ee=new File([Z],`${Date.now()}.png`,{type:"image/png"});C["image/png"]=ee}catch(H){BH.error(H)}Vh(n,d);const D=`<img src="${n.doc.buildResourceUrl(r.src,{withToken:!0})}" />`,x=zh(D,d),_=$a(n,d);C["text/plain"]=new Blob([_],{type:"text/plain"}),v["text/plain"]=_;const R=new Blob([x],{type:"text/html"});return C["text/html"]=R,v["text/html"]=x,[C,v]}function xH(n,e,t,o,r){const i=EH(n,e,t,o);if(!i)return;const[s,l]=i;if(s){const a=Object.entries(s).map(([d,h])=>({type:d,data:h}));return Pm(a).then(d=>{if(!d&&r){const h=r.clipboardData;h&&(h.setData("text/plain",l["text/plain"]),h.setData("text/html",l["text/html"]))}}),!0}}function oy(n,e){const t=n.selection.range;if(t.start.blockId!==t.end.blockId)return;const r=n.getFocusedBlock();if(r&&Wo(r)){const i=Tt.getImageObject(n,r);if(i.getImages().length>0){const l=i.getSelectedIndex();if(l!==-1){const d=yr(r)[l].querySelector("img");if(d)return xH(n,d,i,l,e)}}}}class IH{constructor(e){this.editor=e,setTimeout(()=>{this.editor.input.addHandler(this)})}handleBeforeCopy(e,t,o){if(oy(e,t))return!0}handleBeforeCut(e,t){if(oy(e,t))return d2(e),!0}destroy(){}}class h2{constructor(e){this.editor=e,setTimeout(()=>{this.editor.input.addHandler(this)})}async handleAfterPasteDoc(e,t,o){return Object.values(t.blocks).forEach(r=>{r.forEach(i=>{if(i.type==="embed"&&i.embedType==="image"){const s=i.embedData;if(Array.isArray(s.src))return;if(s.src.startsWith("https:")||s.src.startsWith("http:")){const l=o.blockIdMap.get(i.id);l&&Ji(e,l).setAutoFix(!0)}}})}),!1}destroy(){}}const TH=S("image-embed");function DH(n,e,t,o,r,i){Tt.create(n,t).createContent(r,i,e),n.addCustom("image-select-handler",()=>new hH(n)),n.addCustom("image-copy-handler",()=>new IH(n)),setTimeout(()=>{n.addCustom("drag-handler",()=>new dH(n));const l=n.addCustom("image-resizer",()=>new fH(n)),a=t.embedData;Ec(a)?l.disable(i):l.currentResizer===i&&l.enable(i)})}function SH(n,e,t,o){const r=e.embedData,i=xc(r);return o==="html"?i.map(s=>`<img src="${n.doc.buildResourceUrl(s.src,{withToken:!0})}">`).join(""):o==="markdown"?`${i.map(l=>`![img](${n.doc.buildResourceUrl(l.src,{withToken:!0})})`).join(`
435
435
  `)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ones-editor/editor",
3
- "version": "0.0.3-beta.242",
3
+ "version": "0.0.3-beta.244",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",