@vervedoc/core 3.3.13 → 3.3.15

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/core.umd.cjs CHANGED
@@ -427,5 +427,5 @@ trailer
427
427
  >>startxref
428
428
 
429
429
  %%EOF
430
- `,l+o}boxes(e){e||(e={});const[t,n,i,s]=this.resolveScale(e),a=[];for(let r=0;r<this._tree.chld.length;r++){const{x:l,y:o,w:R,h}=this._tree.chld[r].bbox;a.push({x:t+l*i,y:n+o*s,w:R*i,h:h*s})}return a}box(e){e||(e={});const[t,n,i,s]=this.resolveScale(e);return{x:t+this._tree.bbox.x*i,y:n+this._tree.bbox.y*s,w:this._tree.bbox.w*i,h:this._tree.bbox.h*s}}}const wr=1;class Xi{constructor(e){S(this,"draw");S(this,"imageCache",new Map);S(this,"pendingImages",new Set);this.draw=e}static convertLaTextToSVG(e){return new Ir(e).svg({SCALE_X:10,SCALE_Y:10,MARGIN_X:0,MARGIN_Y:0})}render(e,t,n,i){const{scale:s=wr}=this.draw.getOptions(),a=t,r=a.width*s,l=a.height*s;if(this.imageCache.has(t.value)){const R=this.imageCache.get(t.value);e.drawImage(R,n,i,r,l);return}const o=new Promise((R,h)=>{const d=new Image;d.src=a.laTexSVG,d.onload=()=>{e.drawImage(d,n,i,r,l),this.imageCache.set(t.value,d),R()},d.onerror=h});this.pendingImages.add(o),o.finally(()=>this.pendingImages.delete(o))}awaitImages(){return Promise.all(this.pendingImages).then(()=>{})}destroy(){this.imageCache.clear(),this.pendingImages.clear()}}function vr(){return`s-${Math.random().toString(36).slice(2)}-${Date.now().toString(36)}`}function Hr(c){return typeof c=="number"}function xr(c){return Wr.has(c.type)&&!!c.value}class Ni{constructor(e){S(this,"draw");S(this,"options");S(this,"range");S(this,"searchKeyword");S(this,"searchNavigateIndex");S(this,"searchMatchList");this.draw=e,this.options=e.getOptions(),this.range=e.getRange(),this.searchNavigateIndex=null,this.searchKeyword=null,this.searchMatchList=[]}getSearchKeyword(){return this.searchKeyword}setSearchKeyword(e){this.searchKeyword=e,this.searchNavigateIndex=null}searchNavigatePre(){return!this.searchMatchList.length||!this.searchKeyword?null:(this.searchNavigateIndex===null?this.searchNavigateIndex=0:this.searchNavigateIndex=Math.max(0,this.searchNavigateIndex-1),this._applyNavigate(),this.searchNavigateIndex)}searchNavigateNext(){return!this.searchMatchList.length||!this.searchKeyword?null:(this.searchNavigateIndex===null?this.searchNavigateIndex=0:this.searchNavigateIndex=Math.min(this.searchMatchList.length-1,this.searchNavigateIndex+1),this._applyNavigate(),this.searchNavigateIndex)}_applyNavigate(){if(this.searchNavigateIndex===null)return;const e=this.searchMatchList[this.searchNavigateIndex];!e||!this.range||this.range.setCaret({path:e.path.slice(),offset:e.offset})}getSearchNavigateIndexList(){return this.searchNavigateIndex===null||!this.searchKeyword?[]:[this.searchNavigateIndex]}getSearchMatchList(){return this.searchMatchList}getSearchNavigateInfo(){return!this.searchKeyword||!this.searchMatchList.length?null:{index:this.searchNavigateIndex!==null?this.searchNavigateIndex+1:0,count:this.searchMatchList.length}}getSearchMatchListByKeyword(e,t){if(!e)return[];const n=e.toLocaleLowerCase(),i=[];return $(t,(s,a)=>{if(!xr(s))return;const r=s.value.toLocaleLowerCase();let l=r.indexOf(n);for(;l!==-1;)i.push({path:a.path.slice(),offset:l,length:e.length,groupId:vr()}),l=r.indexOf(n,l+n.length)}),i}computeSearchMatches(e){this.searchMatchList=this.getSearchMatchListByKeyword(e,this.draw.getElementList())}renderSearchHighlights(e,t){var o,R;if(!this.searchMatchList.length||!this.searchKeyword)return;const n=(R=(o=this.draw).getLayout)==null?void 0:R.call(o);if(!n)return;const i=this.options,s=i.searchMatchAlpha??.3,a=i.searchMatchColor??"#ffe58f",r=i.searchNavigateMatchColor??"#ff9c6e",l=this.getSearchNavigateIndexList();e.save(),e.globalAlpha=s;for(let h=0;h<this.searchMatchList.length;h++){const d=this.searchMatchList[h],u=this._findMatchRect(n,d);u&&u.pageNo===t&&(e.fillStyle=l.includes(h)?r:a,e.fillRect(u.x,u.y,u.width,u.height))}e.restore()}_findMatchRect(e,t){for(let n=0;n<e.pages.length;n++){const i=e.pages[n],s=this._findInBlocks(i.blocks,i.contentRect.x,i.contentRect.y,n,t);if(s)return s}return null}_findInBlocks(e,t,n,i,s){for(const a of e){if(a.kind==="table"){for(const o of a.rows)for(const R of o.cells){const h=t+a.rect.x+R.rect.x+R.contentPaddingLeft,d=n+a.rect.y+R.rect.y+R.contentPaddingTop+R.verticalOffset,u=this._findInBlocks(R.content,h,d,i,s);if(u)return u}continue}if(a.kind!=="paragraph")continue;const r=t+a.rect.x,l=n+a.rect.y;for(const o of a.lines)for(const R of o.inlines)if(this._pathMatchesInline(R,s))return{x:r+R.x,y:l+o.y,width:R.width,height:o.height,pageNo:i}}return null}_pathMatchesInline(e,t){if(!e.path)return!1;const n=e.path;if(n.length!==t.path.length)return!1;for(let i=0;i<n.length;i++)if(n[i]!==t.path[i])return!1;return!0}searchNavigateScrollIntoView(){var a,r;if(this.searchNavigateIndex===null)return;const e=this.searchMatchList[this.searchNavigateIndex];if(!e)return;const t=(r=(a=this.draw).getLayout)==null?void 0:r.call(a);if(!t)return;const n=this._findMatchRect(t,e);if(!n)return;const i=this.draw.getContainer(),s=document.createElement("div");s.style.position="absolute",s.style.width=`${n.width+50}px`,s.style.height=`${n.height+50}px`,s.style.left=`${n.x}px`,s.style.top=`${n.y}px`,i.append(s),s.scrollIntoView(!1),s.remove()}replaceSearchMatch(e,t){var o,R;if(((R=(o=this.draw).isReadonly)==null?void 0:R.call(o))||!e)return;let i=this.getSearchMatchList();const s=t==null?void 0:t.index;if(Hr(s)&&(i=[i[s]].filter(Boolean)),!i.length)return;const a=this.draw.getElementList(),r=this.searchKeyword;let l=null;for(const h of i){const d=I(a,h.path);if(!d||!d.value)continue;const u=d.value;d.value=u.slice(0,h.offset)+e+u.slice(h.offset+r.length),l||(l=h)}l&&(this.range&&this.range.setCaret({path:l.path.slice(),offset:l.offset+e.length}),this.draw.setDocument(this.draw.getDocument()),this.computeSearchMatches(r))}}const Gr=["https:","http:"];function Jr(c){try{const{protocol:e}=new URL(c,location.href);return Gr.includes(e)}catch{return!1}}const Zt=class Zt{constructor(e){S(this,"element");this.element=e}_defineIframeProperties(e){try{Object.defineProperties(e,{parent:{get:()=>null},top:{get:()=>null},__POWERED_BY_CANVAS_EDITOR__:{get:()=>!0}})}catch{}}render(e){var i;const t=(i=this.element.block)==null?void 0:i.iframeBlock,n=document.createElement("iframe");if(n.setAttribute("data-id",this.element.id??""),n.sandbox.add(...Zt.sandbox),n.style.border="none",n.style.width="100%",n.style.height="100%",t!=null&&t.src){if(!Jr(t.src))return;n.src=t.src}else t!=null&&t.srcdoc&&(n.srcdoc=t.srcdoc);n.addEventListener("load",()=>{const s=n.contentWindow;s&&this._defineIframeProperties(s)}),e.append(n)}};S(Zt,"sandbox",["allow-scripts"]);let rn=Zt;class kr{constructor(e,t){S(this,"element");S(this,"block");S(this,"blockContainer");S(this,"blockItem");this.blockContainer=e.getBlockContainer(),this.element=t,this.block=null,this.blockItem=this._createBlockItem(),this.blockContainer.append(this.blockItem)}getBlockElement(){return this.element}_createBlockItem(){const e=document.createElement("div");return e.classList.add(`${fe}-block-item`),e}render(){const e=this.element,t=e.block;t&&t.type===gi.IFRAME&&(this.block=new rn(e),this.block.render(this.blockItem))}setClientRects(e,t,n){const i=this.element.metrics;i&&(this.blockItem.style.width=`${i.width}px`,this.blockItem.style.height=`${i.height}px`),this.blockItem.style.position="absolute",this.blockItem.style.left=`${t}px`,this.blockItem.style.top=`${n}px`}remove(){this.blockItem.remove()}}class Ti{constructor(e){S(this,"draw");S(this,"container");S(this,"blockContainer");S(this,"blockMap");this.draw=e,this.container=e.getContainer(),this.blockMap=new Map,this.blockContainer=this._createBlockContainer(),this.container.append(this.blockContainer)}_createBlockContainer(){const e=document.createElement("div");return e.classList.add(`${fe}-block-container`),e.style.position="absolute",e.style.inset="0",e.style.pointerEvents="auto",e}getDraw(){return this.draw}getBlockContainer(){return this.blockContainer}render(e,t,n,i){const s=t.id;if(!s)return;const a=this.blockMap.get(s);if(a)a.setClientRects(e,n,i);else{const r=new kr(this,t);r.render(),r.setClientRects(e,n,i),this.blockMap.set(s,r)}}clear(){if(!this.blockMap.size)return;const e=this.draw.getElementList(),t=[];$(e,n=>{if(n.type==="block"){const i=n.id;i&&t.push(i)}}),this.blockMap.forEach(n=>{const i=n.getBlockElement().id;i&&!t.includes(i)&&(n.remove(),this.blockMap.delete(i))})}destroy(){this.blockMap.forEach(e=>e.remove()),this.blockMap.clear(),this.blockContainer.remove()}}class Li{constructor(){S(this,"draw",null);S(this,"container",null);S(this,"controlMap",new Map)}install(e){return this.draw=e,this.container=e.getContainer(),this._createControlContainer(),this}_createControlContainer(){var t;const e=document.createElement("div");return e.classList.add(`${fe}-control-container`),e.style.position="absolute",e.style.inset="0",e.style.pointerEvents="auto",(t=this.container)==null||t.append(e),e}render(e,t,n){!this.draw||e.id}clear(){if(!this.controlMap.size||!this.draw)return;const e=this.draw.getElementList(),t=[];$(e,n=>{if(n.type==="control"){const i=n.id;i&&t.push(i)}}),this.controlMap.forEach((n,i)=>{t.includes(i)||(n.remove(),this.controlMap.delete(i))})}destroy(){this.controlMap.forEach(e=>e.remove()),this.controlMap.clear(),this.draw=null,this.container=null}}const Cr=50,Er=300;class Wi{constructor(e){S(this,"_undoStack",[]);S(this,"_redoStack",[]);S(this,"_maxRecordCount");S(this,"_coalesceMs");S(this,"_lastPushTime",0);S(this,"_lastCoalesceKey");S(this,"_isExecuting",!1);this._maxRecordCount=(e==null?void 0:e.maxRecordCount)??Cr,this._coalesceMs=(e==null?void 0:e.coalesceMs)??Er}pushInitial(e){this._undoStack=[e],this._redoStack=[],this._lastPushTime=Date.now(),this._lastCoalesceKey=void 0}push(e,t){if(this._isExecuting)return;const n=Date.now();if(t!==void 0&&t===this._lastCoalesceKey&&n-this._lastPushTime<this._coalesceMs&&this._undoStack.length>0){this._undoStack[this._undoStack.length-1]=e,this._redoStack=[],this._lastPushTime=n;return}for(this._undoStack.push(e),this._redoStack=[],this._lastPushTime=n,this._lastCoalesceKey=t;this._undoStack.length>this._maxRecordCount;)this._undoStack.shift()}undo(e){if(this._isExecuting||this._undoStack.length<=1)return null;this._isExecuting=!0;try{return this._redoStack.push(e),this._undoStack.pop(),this._lastCoalesceKey=void 0,this._undoStack[this._undoStack.length-1]??null}finally{this._isExecuting=!1}}redo(e){if(this._isExecuting||this._redoStack.length===0)return null;this._isExecuting=!0;try{const t=this._redoStack.pop();return this._undoStack.push(t),this._lastPushTime=Date.now(),this._lastCoalesceKey=void 0,t}finally{this._isExecuting=!1}}canUndo(){return this._undoStack.length>1}canRedo(){return this._redoStack.length>0}isStackEmpty(){return this._undoStack.length<=1&&this._redoStack.length===0}clear(){this._undoStack=[],this._redoStack=[],this._lastCoalesceKey=void 0}destroy(){this.clear()}}function _r(c,e){return{doc:H(c),range:e?{anchor:e.anchor,focus:e.focus}:null}}class mi{constructor(){S(this,"_historyManager",null)}install(e){return this._historyManager=new Wi(e),this._historyManager}getHistoryManager(){return this._historyManager}destroy(){var e;(e=this._historyManager)==null||e.destroy(),this._historyManager=null}}class Ar{constructor(e){S(this,"deps");S(this,"handle",e=>{const t=this.deps.getAdapt();if(!t)return;const n=this.deps.getDraw(),i=this.deps.getCommand();this.handleEditKeys(e,t,n)||this.handleCursorKeys(e,t,n)||this.handleFormatKeys(e,i)||this.handleHistoryKeys(e,i)});this.deps=e}handleEditKeys(e,t,n){const i=e.ctrlKey||e.metaKey,s={c:"executeCopy",x:"executeCut",v:"executePaste"}[e.key.toLowerCase()];return i&&!e.altKey&&!e.shiftKey&&s?(e.preventDefault(),this.deps.dispatchCommand(s),!0):i&&e.key==="a"?(e.preventDefault(),n.selectAll(),!0):e.key==="Backspace"?(e.preventDefault(),t.deleteBackward(),!0):e.key==="Delete"?(e.preventDefault(),t.deleteForward(),!0):e.key==="Enter"?(e.preventDefault(),t.splitParagraph(),!0):e.key==="Tab"?(e.preventDefault(),t.insertText(" "),!0):e.key==="Escape"?(e.preventDefault(),this.deps.getRange().collapseToStart(),!0):!1}handleCursorKeys(e,t,n){const i=e.ctrlKey||e.metaKey;if(e.key==="ArrowLeft")return e.preventDefault(),i?n.moveCaretWordLeft():t.moveCaretLeft(),!0;if(e.key==="ArrowRight")return e.preventDefault(),i?n.moveCaretWordRight():t.moveCaretRight(),!0;if(e.key==="ArrowUp")return e.preventDefault(),n.moveCaretUp(),!0;if(e.key==="ArrowDown")return e.preventDefault(),n.moveCaretDown(),!0;if(e.key==="Home")return e.preventDefault(),i?n.moveCaretToDocStart():n.moveCaretToLineStart(),!0;if(e.key==="End")return e.preventDefault(),i?n.moveCaretToDocEnd():n.moveCaretToLineEnd(),!0;if(e.key==="PageUp"){e.preventDefault();for(let s=0;s<10;s++)n.moveCaretUp();return!0}if(e.key==="PageDown"){e.preventDefault();for(let s=0;s<10;s++)n.moveCaretDown();return!0}return!1}handleFormatKeys(e,t){if(!(e.ctrlKey||e.metaKey))return!1;const i=e.key.toLowerCase();if(!e.shiftKey&&!e.altKey){if(i==="b")return e.preventDefault(),t.executeSetBold(),!0;if(i==="i")return e.preventDefault(),t.executeSetItalic(),!0;if(i==="u")return e.preventDefault(),t.executeSetUnderline(),!0;if(i==="\\")return e.preventDefault(),t.executeClearFormat(),!0;if(i==="[")return e.preventDefault(),t.executeSizeMinus(),!0;if(i==="]")return e.preventDefault(),t.executeSizeAdd(),!0;if(i==="l")return e.preventDefault(),t.executeSetRowFlex(Se.LEFT),!0;if(i==="e")return e.preventDefault(),t.executeSetRowFlex(Se.CENTER),!0;if(i==="r")return e.preventDefault(),t.executeSetRowFlex(Se.RIGHT),!0;if(i==="j")return e.preventDefault(),t.executeSetRowFlex(Se.JUSTIFY),!0}if(e.shiftKey&&!e.altKey){if(i==="x")return e.preventDefault(),t.executeSetStrikeout(),!0;if(i==="j")return e.preventDefault(),t.executeSetRowFlex(Se.DISTRIBUTE),!0;if(i==="i")return e.preventDefault(),t.executeSetList(It.UL,wt.DISC),!0;if(i==="u")return e.preventDefault(),t.executeSetList(It.OL,wt.DECIMAL),!0}if(e.altKey&&!e.shiftKey){if(i==="0")return e.preventDefault(),t.executeSetTitle(null),!0;if(i==="1")return e.preventDefault(),t.executeSetTitle(me.FIRST),!0;if(i==="2")return e.preventDefault(),t.executeSetTitle(me.SECOND),!0;if(i==="3")return e.preventDefault(),t.executeSetTitle(me.THIRD),!0;if(i==="4")return e.preventDefault(),t.executeSetTitle(me.FOURTH),!0;if(i==="5")return e.preventDefault(),t.executeSetTitle(me.FIFTH),!0;if(i==="6")return e.preventDefault(),t.executeSetTitle(me.SIXTH),!0}return!1}handleHistoryKeys(e,t){if(!(e.ctrlKey||e.metaKey))return!1;const i=e.key.toLowerCase();return!e.shiftKey&&i==="z"?(e.preventDefault(),t.executeUndo(),!0):e.shiftKey&&i==="z"||!e.shiftKey&&i==="y"?(e.preventDefault(),t.executeRedo(),!0):i==="enter"?(e.preventDefault(),t.executePageBreak(),!0):!1}}const Br={first:1,second:2,third:3,fourth:4,fifth:5,sixth:6};function Yi(c){const e=[],t=new Map;return $(c,(n,i)=>{if(n.type!=="title")return;const s=n,a=(s.valueList??[]).map(R=>R.type==="text"?R.value:"").join(""),r=Br[s.level]??1;let l;const o=s.listNumbering;if(o&&o.numFmt!=="bullet"){const R=o.numId??o.abstractNumId??"default",h=o.level??0,d=`${R}:${h}`,u=t.get(d),p=(u??(o.start??1)-1)+1;t.set(d,p);for(const f of t.keys())f.startsWith(`${R}:`)&&Number(f.slice(R.length+1))>h&&t.delete(f);l=(o.lvlText??"%1.").replace(/%([1-9])/g,(f,g)=>{const M=Number(g)-1;return String(M===h?p:t.get(`${R}:${M}`)??o.start??1)})}e.push({id:JSON.stringify(i.path),level:r,name:a,number:l})}),{toc:e}}function Dr(c,e){const t=[];if(!e)return{results:t,count:0};const n=e.toLowerCase();return $(c,(i,s)=>{if(i.type!=="text")return;const a=(i.value||"").toLowerCase();let r=a.indexOf(n);for(;r!==-1;)t.push({path:[...s.path],offset:r,length:e.length}),r=a.indexOf(n,r+1)}),{results:t,count:t.length}}class Vi{constructor(){S(this,"worker",null);S(this,"failed",!1);S(this,"destroyed",!1);S(this,"pending",!1);S(this,"elements",[]);S(this,"tocListeners",new Set);S(this,"searchListeners",new Set);S(this,"cloneListeners",new Set);S(this,"errorListeners",new Set)}init(){if(!(this.worker||this.failed||this.destroyed))try{this.worker=new Worker(new URL("/assets/editor-worker-CG2Et0Mg.js",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:pe&&pe.tagName.toUpperCase()==="SCRIPT"&&pe.src||new URL("core.umd.cjs",document.baseURI).href),{type:"module"}),this.worker.onmessage=e=>{const t=e.data;switch(t.type){case"toc-result":this.tocListeners.forEach(n=>n({toc:t.toc}));break;case"search-result":this.searchListeners.forEach(n=>n({results:t.results,count:t.count}));break;case"clone-result":this.cloneListeners.forEach(n=>n(t.data));break;case"error":this.fallback(t.message);break}},this.worker.onerror=e=>this.fallback(e.message),this.worker.onmessageerror=()=>this.fallback("Worker message could not be decoded")}catch(e){this.failed=!0,this.errorListeners.forEach(t=>t(String(e)))}}fallback(e){var n;(n=this.worker)==null||n.terminate(),this.worker=null,this.failed=!0,this.errorListeners.forEach(i=>i(e));const t=Yi(this.elements);this.tocListeners.forEach(i=>i(t))}updateElements(e){this.destroyed||(this.elements=e,!this.pending&&(this.pending=!0,queueMicrotask(()=>this.flush())))}flush(){if(!(!this.pending||this.destroyed))if(this.pending=!1,this.init(),this.worker)try{this.worker.postMessage({type:"update",elements:this.elements})}catch(e){this.fallback(String(e))}else{const e=Yi(this.elements);this.tocListeners.forEach(t=>t(e))}}search(e){if(this.destroyed)return;if(this.flush(),this.init(),this.worker)try{this.worker.postMessage({type:"search",keyword:e});return}catch(n){this.fallback(String(n))}const t=Dr(this.elements,e);this.searchListeners.forEach(n=>n(t))}clone(e){if(this.destroyed)return;if(this.init(),this.worker)try{this.worker.postMessage({type:"clone",data:e});return}catch(n){this.fallback(String(n))}const t=H(e);this.cloneListeners.forEach(n=>n(t))}onTocResult(e){return this.tocListeners.add(e),()=>this.tocListeners.delete(e)}onSearchResult(e){return this.searchListeners.add(e),()=>this.searchListeners.delete(e)}onCloneResult(e){return this.cloneListeners.add(e),()=>this.cloneListeners.delete(e)}onError(e){return this.errorListeners.add(e),()=>this.errorListeners.delete(e)}destroy(){var e;this.destroyed=!0,(e=this.worker)==null||e.terminate(),this.worker=null,this.elements=[],this.tocListeners.clear(),this.searchListeners.clear(),this.cloneListeners.clear(),this.errorListeners.clear()}}class $r{constructor(e){S(this,"worker",null);S(this,"epoch",0);S(this,"sources",[]);S(this,"color","");S(this,"scheduled",!1);S(this,"sourcesDirty",!1);S(this,"disposed",!1);S(this,"failed",!1);S(this,"invalidated",!1);this.publish=e}invalidate(){this.epoch++,this.color="",this.invalidated=!0}update(e,t){if(this.disposed||this.failed)return;this.invalidated=!1;const n=e.length!==this.sources.length||e.some((i,s)=>i!==this.sources[s]);!n&&t===this.color||(this.sources=e,this.color=t,this.sourcesDirty||(this.sourcesDirty=n),this.epoch++,!this.scheduled&&(this.scheduled=!0,queueMicrotask(()=>this.flush())))}flush(){if(this.scheduled=!1,!(this.disposed||this.failed||this.invalidated))try{this.worker||(this.worker=new Worker(new URL("/assets/thumbnail-worker-BGjZ82h0.js",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:pe&&pe.tagName.toUpperCase()==="SCRIPT"&&pe.src||new URL("core.umd.cjs",document.baseURI).href),{type:"module"}),this.worker.onmessage=e=>{if(!(this.disposed||e.data.id!==this.epoch)){if(e.data.error){this.fail(e.data.error);return}e.data.images&&this.publish(e.data.images)}},this.worker.onerror=e=>this.fail(e.message),this.worker.onmessageerror=()=>this.fail("Thumbnail worker message could not be decoded")),this.worker.postMessage({id:this.epoch,color:this.color,...this.sourcesDirty?{sources:this.sources}:{}}),this.sourcesDirty=!1}catch(e){this.fail(String(e))}}fail(e){var t;this.failed=!0,(t=this.worker)==null||t.terminate(),this.worker=null,console.warn("[VerveDocs] Background thumbnails unavailable:",e)}destroy(){var e;this.disposed=!0,this.epoch++,(e=this.worker)==null||e.terminate(),this.worker=null,this.sources=[]}}class an{constructor(e,t,n={}){S(this,"i18n");S(this,"listener");S(this,"eventBus");S(this,"range");S(this,"draw");S(this,"command");S(this,"adapt");S(this,"destroyed",!1);S(this,"clipboardEpoch",0);S(this,"plugins",new Map);S(this,"pluginCommands",new Map);S(this,"commandChain",new ui);S(this,"pluginHost",null);S(this,"search");S(this,"block");S(this,"date");S(this,"laTex");S(this,"control");S(this,"history");S(this,"worker");S(this,"thumbnailWorker");S(this,"thumbnailSources",[]);if(!e||!(e instanceof HTMLDivElement))throw new TypeError("[DocxEditor] container 必须是 HTMLDivElement");if(!t||typeof t!="object"||!Array.isArray(t.elements))throw new TypeError("[DocxEditor] document 必须是 IDocxDocumentMeta,且 elements 为数组。不再兼容 IElement[] / IEditorData 形态。");this.i18n=ln(n.locale);const i=Nn({...n,locale:this.i18n.locale}),s=H(t);if(be(s.elements,{editorOptions:i,styles:s.styles,numbering:s.numbering}),s.sections!==void 0&&!Array.isArray(s.sections))throw new TypeError("旧 sections 内容区必须显式迁移到 contentZones");for(const R of[s.header,s.footer,...Object.values(s.contentZones??{}),...Object.values(s.headerFooterParts??{})])R&&be(R,{editorOptions:i,styles:s.styles,numbering:s.numbering});this.listener=new _t,this.thumbnailWorker=new $r(R=>{this.destroyed||this.listener.emit("thumbnailChange",R)}),this.listener.on("thumbnailAppearanceChange",()=>this.refreshThumbnailAppearance());for(const R of["contentChange","documentSet"])this.listener.on(R,()=>this.thumbnailWorker.invalidate());this.eventBus=new bn,this.range=new Un(this.listener);for(const R of["contentChange","documentSet","rangeChange","zoneChange","abilityChange"])this.listener.on(R,()=>{this.clipboardEpoch++});this.wireAfterRenderHooks();let a=null;const r=new Ar({getDraw:()=>this.draw,getCommand:()=>this.command,dispatchCommand:(R,...h)=>this.dispatchCommand(R,...h),getRange:()=>this.range,getAdapt:()=>a});this.draw=new di(e,i,{document:s,i18n:this.i18n,listener:this.listener,eventBus:this.eventBus,rangeManager:this.range,onInput:R=>{a==null||a.insertText(R)},onKeyDown:r.handle,afterRender:()=>{this.listener.emit("afterRender")},onCommand:(R,...h)=>this.commandChain.dispatch(R,...h),onZoneChange:R=>{this.listener.emit("zoneChange",R)}}),a=new pi({getDocument:()=>this.draw.getDocument(),setDocument:R=>this.draw.setDocument(R),getLayout:()=>this.draw.getLayout(),getScroller:()=>this.draw.getScroller(),getActiveDocument:()=>this.draw.getActiveDocument(),applyActiveDocument:R=>{this.draw.getZone()==="main"?this.draw.setDocument(R):this.draw.applyActiveDocument(R)},setScale:R=>this.draw.setScale(R),setPageSize:(R,h)=>this.draw.setPageSize(R,h),setRulerVisible:R=>this.draw.setRulerVisible(R),setPaperMargins:R=>this.draw.setPaperMargins(R),getOptions:()=>this.draw.getOptions(),updateOptions:R=>this.draw.updateOptions(R),getZone:()=>this.draw.getZone(),setZone:R=>this.draw.setZone(R),setZoneWithCaret:R=>this.draw.setZoneWithCaret(R),print:()=>this.draw.print(),getPageThumbnails:()=>this.draw.getPageThumbnails(),scrollPositionIntoView:R=>this.draw.scrollPositionIntoView(R)},this.range,this.listener),this.adapt=a,this.command=new fi(a),this.commandChain.use((R,h,d)=>{if(R==="requestInsertImage"){this.listener.emit("requestInsertImage");return}if(R==="requestInsertHyperlink"){this.listener.emit("requestInsertHyperlink");return}if(R==="requestInsertFormula"){this.listener.emit("requestInsertFormula");return}if(R==="executeTableProperty"){this.listener.emit("requestTableProperties");return}return d()}).use((R,h,d)=>{const u=this.pluginCommands.get(R);return typeof u=="function"?u(...h):d()}).use((R,h,d)=>{var u;if(R==="executeCopy"||R==="executeCut"){if(R==="executeCut"&&!this.command.getIsCanInput())return;const p=this.command.executeCopy();if(!navigator.clipboard)return;const f=this.clipboardGuard(),g=a.copyFragment(),M="web application/x-vervedocs+json";return(g&&typeof ClipboardItem<"u"&&((u=ClipboardItem.supports)!=null&&u.call(ClipboardItem,M))?navigator.clipboard.write([new ClipboardItem({"text/plain":new Blob([p],{type:"text/plain"}),[M]:new Blob([JSON.stringify(g)],{type:"application/x-vervedocs+json"})})]):navigator.clipboard.writeText(p)).then(()=>(R==="executeCut"&&f()&&this.command.executeCut(),p)).catch(()=>{})}if(["executePaste","executePastePlain","executePasteNoFormat"].includes(R)){if(!this.command.getIsCanInput())return;if(h.length>0)return d();if(!navigator.clipboard)return;const p=this.clipboardGuard();return(async()=>{const f="web application/x-vervedocs+json";if(R==="executePaste"&&navigator.clipboard.read){const g=await navigator.clipboard.read();for(const M of g)if(M.types.includes(f)){const O=JSON.parse(await(await M.getType(f)).text());p()&&a.pasteFragment(O);return}for(const M of g)if(M.types.includes("text/plain")){const O=await(await M.getType("text/plain")).text();p()&&this.command.executePaste(O);return}}else{const g=await navigator.clipboard.readText();p()&&this.command.executePasteNoFormat(g)}})().catch(()=>{})}return d()}).use((R,h,d)=>{if(!this.command)return;const u=this.command[R];if(typeof u=="function")return u.call(this.command,...h)}),this.history=new mi;const l=this.history.install({maxRecordCount:Number(i.historyMaxRecordCount??50),coalesceMs:300});a.setHistoryManager(l),a.pushInitialHistory(),this.search=new Ni(this.draw),this.block=new Ti(this.draw),this.date=new Si(this.draw),this.laTex=new Xi(this.draw),this.control=new Li,this.control.install(this.draw);const o=this.draw;this.pluginHost={getI18n:()=>this.i18n,getContainer:()=>o.getScroller(),getPositionList:()=>null,getRevisionAnchor:R=>o.getRevisionAnchorMap().get(R)||null,getDrawWidth:()=>Number(i.pageWidth??794),getDrawHeight:()=>Number(i.pageHeight??1123),getPageGap:()=>Number(i.pageGap??24),getOptions:()=>i,getElementList:()=>o.getDocument().elements,getDocument:()=>o.getDocument(),commitTransaction:R=>this.adapt.commitPluginTransaction(R),getGroupContext:R=>{const d=o.getGroupAnchorMap().get(R);return d?{isTable:!1,index:-1,startIndex:-1,endIndex:-1,_anchor:d}:null},executeSetGroup:R=>this.adapt.setGroup(R),executeDeleteGroup:R=>{var h;(h=this.command)==null||h.executeDeleteGroup(R)},executeLocationGroup:R=>{var h;(h=this.command)==null||h.executeLocationGroup(R)},executeUpdateOptions:R=>{this.adapt.updateOptions(R)},setActiveGroup:R=>{o.setActiveGroup(R)},setActiveRevision:(R,h)=>{o.setActiveRevision(R,h)},getEventBus:()=>this.eventBus,setChartRenderer:R=>o.setChartRenderer(R),executeInsertChart:R=>{var h;(h=this.command)==null||h.executeInsertChart(R)},executeUpdateChart:(R,h)=>{var d;(d=this.command)==null||d.executeUpdateChart(R,h)}},this.listener.on("documentSet",R=>{var h,d;for(const u of this.plugins.values())(d=(h=u.hooks)==null?void 0:h.onSetDocument)==null||d.call(h,R)}),this.worker=new Vi,this.worker.onTocResult(R=>{this.listener.emit("tocChange",R.toc)}),this.listener.on("contentChange",()=>{this.worker.updateElements(this.draw.getDocument().elements)}),this.worker.updateElements(s.elements)}clipboardGuard(){const e=this.draw.getDocument(),t=this.clipboardEpoch,n=this.draw.getZone(),i=JSON.stringify(this.range.getRange());return()=>!this.destroyed&&t===this.clipboardEpoch&&e===this.draw.getDocument()&&n===this.draw.getZone()&&i===JSON.stringify(this.range.getRange())}wireAfterRenderHooks(){this.listener.lifecycle.afterRenderListener(()=>{var e,t,n,i;for(const s of this.plugins.values())(t=(e=s.hooks)==null?void 0:e.afterRender)==null||t.call(e);if(this.renderEmbedBlocks(),(n=this.block)==null||n.clear(),(i=this.control)==null||i.clear(),this.listener.hasListeners("thumbnailChange")){const s=this.draw.getPageThumbnails(),a=this.draw.getThumbnailForegrounds();(a.length!==this.thumbnailSources.length||a.some((r,l)=>r!==this.thumbnailSources[l]))&&(this.listener.emit("thumbnailChange",s),this.thumbnailSources=a),this.refreshThumbnailAppearance(a)}})}refreshThumbnailAppearance(e){if(this.destroyed||!this.draw||!this.listener.hasListeners("thumbnailChange"))return;const t=this.draw.getOptions(),n=t.background;this.thumbnailWorker.update(e??this.draw.getThumbnailForegrounds(),t.eyeCare?"#C7EDCC":(n==null?void 0:n.color)||"#ffffff")}renderEmbedBlocks(){if(!this.block)return;const e=this.draw.getLayout();if(e){for(const t of e.pages)for(const n of t.blocks)if(n.kind==="block"){const i=t.contentRect.x+n.rect.x,s=t.contentRect.y+n.rect.y;this.block.render(t.index,n.block,i,s)}}}getDocument(){return this.draw.getDocument()}getLocale(){return this.i18n.locale}setLocale(e){this.i18n.setLocale(e)}getI18n(){return this.i18n}setDocument(e){if(!e||!Array.isArray(e.elements))throw new TypeError("[DocxEditor.setDocument] 需要 IDocxDocumentMeta");this.adapt.replaceDocument(e,!0)}use(e){var t;if(this.plugins.has(e.name)){console.warn(`[DocxEditor] 插件 "${e.name}" 已注册,忽略重复注册`);return}if(this.plugins.set(e.name,e),this.pluginHost&&e.install(this.pluginHost),e.commands)for(const[n,i]of Object.entries(e.commands))this.pluginCommands.set(n,i);(t=e.hooks)!=null&&t.onSetDocument&&e.hooks.onSetDocument(this.draw.getDocument())}getPlugin(e){return this.plugins.get(e)}dispatchCommand(e,...t){return this.commandChain.dispatch(e,...t)}destroy(){var e,t,n,i,s;this.destroyed=!0;for(const a of this.plugins.values())(e=a.destroy)==null||e.call(a);(t=this.block)==null||t.destroy(),(n=this.date)==null||n.clearDatePicker(),(i=this.control)==null||i.destroy(),(s=this.history)==null||s.destroy(),this.draw.destroy(),this.thumbnailWorker.destroy(),this.worker.destroy(),this.listener=new _t,this.eventBus.clear(),this.range.clear()}}const zr=ve.map(c=>({label:c.label,value:c.value})),jr=rt.map(c=>{const e=Ae[c];return{label:c,value:e??Number(c)}}),qr=[{label:"自动",value:120},{label:"40",value:40},{label:"50",value:50},{label:"60",value:60},{label:"70",value:70},{label:"80",value:80},{label:"90",value:90},{label:"100",value:100},{label:"120",value:120},{label:"140",value:140},{label:"160",value:160},{label:"180",value:180},{label:"200",value:200}],ea="4.0.0-tree";L.BLOCK_LEVEL_TYPES=Kt,L.BULLET_STYLES=un,L.BlockParticle=Ti,L.CanvasRenderer=vn,L.Command=fi,L.CommandAdapt=pi,L.CommandChain=ui,L.ControlComponent=Li,L.DEFAULT_EDITOR_OPTION=_e,L.DEFAULT_PAPER_SIZE=xi,L.DPI=Ht,L.DateParticle=Si,L.DocxEditor=an,L.Draw=di,L.EDITOR_FONT_OPTIONS=zr,L.EDITOR_SIZE_OPTIONS=jr,L.Editor=an,L.EventBus=bn,L.FONT_FAMILY=Ii,L.FONT_FAMILY_CSS=st,L.FONT_FAMILY_LABEL=vt,L.FONT_FAMILY_LIST=cn,L.FONT_FAMILY_MAP=ve,L.FONT_FAMILY_VALUE=hn,L.FONT_SIZE=Ae,L.FONT_SIZE_LIST=rt,L.HistoryComponent=mi,L.HistoryManager=Wi,L.KeyMap=gs,L.LINE_HEIGHT_OPTIONS=Gi,L.LIST_STYLE=wt,L.LIST_TYPE=It,L.LaTexParticle=Xi,L.LayoutEngine=In,L.Listener=_t,L.MARGIN_PRESETS=Ji,L.NUMBER_STYLES=pn,L.PAPER_SIZE_LIST=dn,L.PARAGRAPH_ATTR_KEYS=yi,L.PARAGRAPH_CONTAINER_TYPES=Ki,L.PaperDirection=wi,L.ROW_FLEX=Se,L.RangeManager=Un,L.SCHEMA_VERSION=Fi,L.SEPARATOR_STYLES=Ci,L.Search=Ni,L.TITLE_LEVEL=me,L.TITLE_LEVEL_MAP=Ei,L.TableBorder=Mt,L.TextMeasure=Nt,L.WATERMARK_SIZE_OPTIONS=qr,L.WorkerManager=Vi,L.ZOOM_LEVELS=ki,L._pathSegAsKey=ss,L.adjustFloatImagePositions=rs,L.applyImageLayout=Pt,L.clearRevision=at,L.cloneTree=H,L.comparePath=De,L.comparePosition=Fe,L.createSnapshot=_r,L.default=an,L.forEachCell=ns,L.formatElementTree=be,L.getAuthorColor=gn,L.getByPath=I,L.getParentContainer=E,L.getRevisionOldProps=Jt,L.getSharedMeasure=Tt,L.getTableColCount=is,L.hitTest=zt,L.insertAtPath=es,L.isApple=Yn,L.isMod=Ms,L.isParagraphContainer=St,L.isSamePath=z,L.isTable=Ot,L.mergeOption=Nn,L.pairBookmarkMarkers=Ln,L.ptToPx=vi,L.pxToPt=Hi,L.recordFormatRevision=On,L.removeAtPath=ts,L.replaceAtPath=qi,L.resolveHeaderFooterPart=Ct,L.restoreRevisionFormat=Di,L.snapshotRevisionFormat=Gt,L.splitParagraphs=Oe,L.toDocxExportDocument=mn,L.updateImageLayout=$e,L.version=ea,L.walkTree=$,Object.defineProperties(L,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
430
+ `,l+o}boxes(e){e||(e={});const[t,n,i,s]=this.resolveScale(e),a=[];for(let r=0;r<this._tree.chld.length;r++){const{x:l,y:o,w:R,h}=this._tree.chld[r].bbox;a.push({x:t+l*i,y:n+o*s,w:R*i,h:h*s})}return a}box(e){e||(e={});const[t,n,i,s]=this.resolveScale(e);return{x:t+this._tree.bbox.x*i,y:n+this._tree.bbox.y*s,w:this._tree.bbox.w*i,h:this._tree.bbox.h*s}}}const wr=1;class Xi{constructor(e){S(this,"draw");S(this,"imageCache",new Map);S(this,"pendingImages",new Set);this.draw=e}static convertLaTextToSVG(e){return new Ir(e).svg({SCALE_X:10,SCALE_Y:10,MARGIN_X:0,MARGIN_Y:0})}render(e,t,n,i){const{scale:s=wr}=this.draw.getOptions(),a=t,r=a.width*s,l=a.height*s;if(this.imageCache.has(t.value)){const R=this.imageCache.get(t.value);e.drawImage(R,n,i,r,l);return}const o=new Promise((R,h)=>{const d=new Image;d.src=a.laTexSVG,d.onload=()=>{e.drawImage(d,n,i,r,l),this.imageCache.set(t.value,d),R()},d.onerror=h});this.pendingImages.add(o),o.finally(()=>this.pendingImages.delete(o))}awaitImages(){return Promise.all(this.pendingImages).then(()=>{})}destroy(){this.imageCache.clear(),this.pendingImages.clear()}}function vr(){return`s-${Math.random().toString(36).slice(2)}-${Date.now().toString(36)}`}function Hr(c){return typeof c=="number"}function xr(c){return Wr.has(c.type)&&!!c.value}class Ni{constructor(e){S(this,"draw");S(this,"options");S(this,"range");S(this,"searchKeyword");S(this,"searchNavigateIndex");S(this,"searchMatchList");this.draw=e,this.options=e.getOptions(),this.range=e.getRange(),this.searchNavigateIndex=null,this.searchKeyword=null,this.searchMatchList=[]}getSearchKeyword(){return this.searchKeyword}setSearchKeyword(e){this.searchKeyword=e,this.searchNavigateIndex=null}searchNavigatePre(){return!this.searchMatchList.length||!this.searchKeyword?null:(this.searchNavigateIndex===null?this.searchNavigateIndex=0:this.searchNavigateIndex=Math.max(0,this.searchNavigateIndex-1),this._applyNavigate(),this.searchNavigateIndex)}searchNavigateNext(){return!this.searchMatchList.length||!this.searchKeyword?null:(this.searchNavigateIndex===null?this.searchNavigateIndex=0:this.searchNavigateIndex=Math.min(this.searchMatchList.length-1,this.searchNavigateIndex+1),this._applyNavigate(),this.searchNavigateIndex)}_applyNavigate(){if(this.searchNavigateIndex===null)return;const e=this.searchMatchList[this.searchNavigateIndex];!e||!this.range||this.range.setCaret({path:e.path.slice(),offset:e.offset})}getSearchNavigateIndexList(){return this.searchNavigateIndex===null||!this.searchKeyword?[]:[this.searchNavigateIndex]}getSearchMatchList(){return this.searchMatchList}getSearchNavigateInfo(){return!this.searchKeyword||!this.searchMatchList.length?null:{index:this.searchNavigateIndex!==null?this.searchNavigateIndex+1:0,count:this.searchMatchList.length}}getSearchMatchListByKeyword(e,t){if(!e)return[];const n=e.toLocaleLowerCase(),i=[];return $(t,(s,a)=>{if(!xr(s))return;const r=s.value.toLocaleLowerCase();let l=r.indexOf(n);for(;l!==-1;)i.push({path:a.path.slice(),offset:l,length:e.length,groupId:vr()}),l=r.indexOf(n,l+n.length)}),i}computeSearchMatches(e){this.searchMatchList=this.getSearchMatchListByKeyword(e,this.draw.getElementList())}renderSearchHighlights(e,t){var o,R;if(!this.searchMatchList.length||!this.searchKeyword)return;const n=(R=(o=this.draw).getLayout)==null?void 0:R.call(o);if(!n)return;const i=this.options,s=i.searchMatchAlpha??.3,a=i.searchMatchColor??"#ffe58f",r=i.searchNavigateMatchColor??"#ff9c6e",l=this.getSearchNavigateIndexList();e.save(),e.globalAlpha=s;for(let h=0;h<this.searchMatchList.length;h++){const d=this.searchMatchList[h],u=this._findMatchRect(n,d);u&&u.pageNo===t&&(e.fillStyle=l.includes(h)?r:a,e.fillRect(u.x,u.y,u.width,u.height))}e.restore()}_findMatchRect(e,t){for(let n=0;n<e.pages.length;n++){const i=e.pages[n],s=this._findInBlocks(i.blocks,i.contentRect.x,i.contentRect.y,n,t);if(s)return s}return null}_findInBlocks(e,t,n,i,s){for(const a of e){if(a.kind==="table"){for(const o of a.rows)for(const R of o.cells){const h=t+a.rect.x+R.rect.x+R.contentPaddingLeft,d=n+a.rect.y+R.rect.y+R.contentPaddingTop+R.verticalOffset,u=this._findInBlocks(R.content,h,d,i,s);if(u)return u}continue}if(a.kind!=="paragraph")continue;const r=t+a.rect.x,l=n+a.rect.y;for(const o of a.lines)for(const R of o.inlines)if(this._pathMatchesInline(R,s))return{x:r+R.x,y:l+o.y,width:R.width,height:o.height,pageNo:i}}return null}_pathMatchesInline(e,t){if(!e.path)return!1;const n=e.path;if(n.length!==t.path.length)return!1;for(let i=0;i<n.length;i++)if(n[i]!==t.path[i])return!1;return!0}searchNavigateScrollIntoView(){var a,r;if(this.searchNavigateIndex===null)return;const e=this.searchMatchList[this.searchNavigateIndex];if(!e)return;const t=(r=(a=this.draw).getLayout)==null?void 0:r.call(a);if(!t)return;const n=this._findMatchRect(t,e);if(!n)return;const i=this.draw.getContainer(),s=document.createElement("div");s.style.position="absolute",s.style.width=`${n.width+50}px`,s.style.height=`${n.height+50}px`,s.style.left=`${n.x}px`,s.style.top=`${n.y}px`,i.append(s),s.scrollIntoView(!1),s.remove()}replaceSearchMatch(e,t){var o,R;if(((R=(o=this.draw).isReadonly)==null?void 0:R.call(o))||!e)return;let i=this.getSearchMatchList();const s=t==null?void 0:t.index;if(Hr(s)&&(i=[i[s]].filter(Boolean)),!i.length)return;const a=this.draw.getElementList(),r=this.searchKeyword;let l=null;for(const h of i){const d=I(a,h.path);if(!d||!d.value)continue;const u=d.value;d.value=u.slice(0,h.offset)+e+u.slice(h.offset+r.length),l||(l=h)}l&&(this.range&&this.range.setCaret({path:l.path.slice(),offset:l.offset+e.length}),this.draw.setDocument(this.draw.getDocument()),this.computeSearchMatches(r))}}const Gr=["https:","http:"];function Jr(c){try{const{protocol:e}=new URL(c,location.href);return Gr.includes(e)}catch{return!1}}const Zt=class Zt{constructor(e){S(this,"element");this.element=e}_defineIframeProperties(e){try{Object.defineProperties(e,{parent:{get:()=>null},top:{get:()=>null},__POWERED_BY_CANVAS_EDITOR__:{get:()=>!0}})}catch{}}render(e){var i;const t=(i=this.element.block)==null?void 0:i.iframeBlock,n=document.createElement("iframe");if(n.setAttribute("data-id",this.element.id??""),n.sandbox.add(...Zt.sandbox),n.style.border="none",n.style.width="100%",n.style.height="100%",t!=null&&t.src){if(!Jr(t.src))return;n.src=t.src}else t!=null&&t.srcdoc&&(n.srcdoc=t.srcdoc);n.addEventListener("load",()=>{const s=n.contentWindow;s&&this._defineIframeProperties(s)}),e.append(n)}};S(Zt,"sandbox",["allow-scripts"]);let rn=Zt;class kr{constructor(e,t){S(this,"element");S(this,"block");S(this,"blockContainer");S(this,"blockItem");this.blockContainer=e.getBlockContainer(),this.element=t,this.block=null,this.blockItem=this._createBlockItem(),this.blockContainer.append(this.blockItem)}getBlockElement(){return this.element}_createBlockItem(){const e=document.createElement("div");return e.classList.add(`${fe}-block-item`),e}render(){const e=this.element,t=e.block;t&&t.type===gi.IFRAME&&(this.block=new rn(e),this.block.render(this.blockItem))}setClientRects(e,t,n){const i=this.element.metrics;i&&(this.blockItem.style.width=`${i.width}px`,this.blockItem.style.height=`${i.height}px`),this.blockItem.style.position="absolute",this.blockItem.style.left=`${t}px`,this.blockItem.style.top=`${n}px`}remove(){this.blockItem.remove()}}class Ti{constructor(e){S(this,"draw");S(this,"container");S(this,"blockContainer");S(this,"blockMap");this.draw=e,this.container=e.getContainer(),this.blockMap=new Map,this.blockContainer=this._createBlockContainer(),this.container.append(this.blockContainer)}_createBlockContainer(){const e=document.createElement("div");return e.classList.add(`${fe}-block-container`),e.style.position="absolute",e.style.inset="0",e.style.pointerEvents="auto",e}getDraw(){return this.draw}getBlockContainer(){return this.blockContainer}render(e,t,n,i){const s=t.id;if(!s)return;const a=this.blockMap.get(s);if(a)a.setClientRects(e,n,i);else{const r=new kr(this,t);r.render(),r.setClientRects(e,n,i),this.blockMap.set(s,r)}}clear(){if(!this.blockMap.size)return;const e=this.draw.getElementList(),t=[];$(e,n=>{if(n.type==="block"){const i=n.id;i&&t.push(i)}}),this.blockMap.forEach(n=>{const i=n.getBlockElement().id;i&&!t.includes(i)&&(n.remove(),this.blockMap.delete(i))})}destroy(){this.blockMap.forEach(e=>e.remove()),this.blockMap.clear(),this.blockContainer.remove()}}class Li{constructor(){S(this,"draw",null);S(this,"container",null);S(this,"controlMap",new Map)}install(e){return this.draw=e,this.container=e.getContainer(),this._createControlContainer(),this}_createControlContainer(){var t;const e=document.createElement("div");return e.classList.add(`${fe}-control-container`),e.style.position="absolute",e.style.inset="0",e.style.pointerEvents="auto",(t=this.container)==null||t.append(e),e}render(e,t,n){!this.draw||e.id}clear(){if(!this.controlMap.size||!this.draw)return;const e=this.draw.getElementList(),t=[];$(e,n=>{if(n.type==="control"){const i=n.id;i&&t.push(i)}}),this.controlMap.forEach((n,i)=>{t.includes(i)||(n.remove(),this.controlMap.delete(i))})}destroy(){this.controlMap.forEach(e=>e.remove()),this.controlMap.clear(),this.draw=null,this.container=null}}const Cr=50,Er=300;class Wi{constructor(e){S(this,"_undoStack",[]);S(this,"_redoStack",[]);S(this,"_maxRecordCount");S(this,"_coalesceMs");S(this,"_lastPushTime",0);S(this,"_lastCoalesceKey");S(this,"_isExecuting",!1);this._maxRecordCount=(e==null?void 0:e.maxRecordCount)??Cr,this._coalesceMs=(e==null?void 0:e.coalesceMs)??Er}pushInitial(e){this._undoStack=[e],this._redoStack=[],this._lastPushTime=Date.now(),this._lastCoalesceKey=void 0}push(e,t){if(this._isExecuting)return;const n=Date.now();if(t!==void 0&&t===this._lastCoalesceKey&&n-this._lastPushTime<this._coalesceMs&&this._undoStack.length>0){this._undoStack[this._undoStack.length-1]=e,this._redoStack=[],this._lastPushTime=n;return}for(this._undoStack.push(e),this._redoStack=[],this._lastPushTime=n,this._lastCoalesceKey=t;this._undoStack.length>this._maxRecordCount;)this._undoStack.shift()}undo(e){if(this._isExecuting||this._undoStack.length<=1)return null;this._isExecuting=!0;try{return this._redoStack.push(e),this._undoStack.pop(),this._lastCoalesceKey=void 0,this._undoStack[this._undoStack.length-1]??null}finally{this._isExecuting=!1}}redo(e){if(this._isExecuting||this._redoStack.length===0)return null;this._isExecuting=!0;try{const t=this._redoStack.pop();return this._undoStack.push(t),this._lastPushTime=Date.now(),this._lastCoalesceKey=void 0,t}finally{this._isExecuting=!1}}canUndo(){return this._undoStack.length>1}canRedo(){return this._redoStack.length>0}isStackEmpty(){return this._undoStack.length<=1&&this._redoStack.length===0}clear(){this._undoStack=[],this._redoStack=[],this._lastCoalesceKey=void 0}destroy(){this.clear()}}function _r(c,e){return{doc:H(c),range:e?{anchor:e.anchor,focus:e.focus}:null}}class mi{constructor(){S(this,"_historyManager",null)}install(e){return this._historyManager=new Wi(e),this._historyManager}getHistoryManager(){return this._historyManager}destroy(){var e;(e=this._historyManager)==null||e.destroy(),this._historyManager=null}}class Ar{constructor(e){S(this,"deps");S(this,"handle",e=>{const t=this.deps.getAdapt();if(!t)return;const n=this.deps.getDraw(),i=this.deps.getCommand();this.handleEditKeys(e,t,n)||this.handleCursorKeys(e,t,n)||this.handleFormatKeys(e,i)||this.handleHistoryKeys(e,i)});this.deps=e}handleEditKeys(e,t,n){const i=e.ctrlKey||e.metaKey,s={c:"executeCopy",x:"executeCut",v:"executePaste"}[e.key.toLowerCase()];return i&&!e.altKey&&!e.shiftKey&&s?(e.preventDefault(),this.deps.dispatchCommand(s),!0):i&&e.key==="a"?(e.preventDefault(),n.selectAll(),!0):e.key==="Backspace"?(e.preventDefault(),t.deleteBackward(),!0):e.key==="Delete"?(e.preventDefault(),t.deleteForward(),!0):e.key==="Enter"?(e.preventDefault(),t.splitParagraph(),!0):e.key==="Tab"?(e.preventDefault(),t.insertText(" "),!0):e.key==="Escape"?(e.preventDefault(),this.deps.getRange().collapseToStart(),!0):!1}handleCursorKeys(e,t,n){const i=e.ctrlKey||e.metaKey;if(e.key==="ArrowLeft")return e.preventDefault(),i?n.moveCaretWordLeft():t.moveCaretLeft(),!0;if(e.key==="ArrowRight")return e.preventDefault(),i?n.moveCaretWordRight():t.moveCaretRight(),!0;if(e.key==="ArrowUp")return e.preventDefault(),n.moveCaretUp(),!0;if(e.key==="ArrowDown")return e.preventDefault(),n.moveCaretDown(),!0;if(e.key==="Home")return e.preventDefault(),i?n.moveCaretToDocStart():n.moveCaretToLineStart(),!0;if(e.key==="End")return e.preventDefault(),i?n.moveCaretToDocEnd():n.moveCaretToLineEnd(),!0;if(e.key==="PageUp"){e.preventDefault();for(let s=0;s<10;s++)n.moveCaretUp();return!0}if(e.key==="PageDown"){e.preventDefault();for(let s=0;s<10;s++)n.moveCaretDown();return!0}return!1}handleFormatKeys(e,t){if(!(e.ctrlKey||e.metaKey))return!1;const i=e.key.toLowerCase();if(!e.shiftKey&&!e.altKey){if(i==="b")return e.preventDefault(),t.executeSetBold(),!0;if(i==="i")return e.preventDefault(),t.executeSetItalic(),!0;if(i==="u")return e.preventDefault(),t.executeSetUnderline(),!0;if(i==="\\")return e.preventDefault(),t.executeClearFormat(),!0;if(i==="[")return e.preventDefault(),t.executeSizeMinus(),!0;if(i==="]")return e.preventDefault(),t.executeSizeAdd(),!0;if(i==="l")return e.preventDefault(),t.executeSetRowFlex(Se.LEFT),!0;if(i==="e")return e.preventDefault(),t.executeSetRowFlex(Se.CENTER),!0;if(i==="r")return e.preventDefault(),t.executeSetRowFlex(Se.RIGHT),!0;if(i==="j")return e.preventDefault(),t.executeSetRowFlex(Se.JUSTIFY),!0}if(e.shiftKey&&!e.altKey){if(i==="x")return e.preventDefault(),t.executeSetStrikeout(),!0;if(i==="j")return e.preventDefault(),t.executeSetRowFlex(Se.DISTRIBUTE),!0;if(i==="i")return e.preventDefault(),t.executeSetList(It.UL,wt.DISC),!0;if(i==="u")return e.preventDefault(),t.executeSetList(It.OL,wt.DECIMAL),!0}if(e.altKey&&!e.shiftKey){if(i==="0")return e.preventDefault(),t.executeSetTitle(null),!0;if(i==="1")return e.preventDefault(),t.executeSetTitle(me.FIRST),!0;if(i==="2")return e.preventDefault(),t.executeSetTitle(me.SECOND),!0;if(i==="3")return e.preventDefault(),t.executeSetTitle(me.THIRD),!0;if(i==="4")return e.preventDefault(),t.executeSetTitle(me.FOURTH),!0;if(i==="5")return e.preventDefault(),t.executeSetTitle(me.FIFTH),!0;if(i==="6")return e.preventDefault(),t.executeSetTitle(me.SIXTH),!0}return!1}handleHistoryKeys(e,t){if(!(e.ctrlKey||e.metaKey))return!1;const i=e.key.toLowerCase();return!e.shiftKey&&i==="z"?(e.preventDefault(),t.executeUndo(),!0):e.shiftKey&&i==="z"||!e.shiftKey&&i==="y"?(e.preventDefault(),t.executeRedo(),!0):i==="enter"?(e.preventDefault(),t.executePageBreak(),!0):!1}}const Br={first:1,second:2,third:3,fourth:4,fifth:5,sixth:6};function Yi(c){const e=[],t=new Map;return $(c,(n,i)=>{if(n.type!=="title")return;const s=n,a=(s.valueList??[]).map(R=>R.type==="text"?R.value:"").join(""),r=Br[s.level]??1;let l;const o=s.listNumbering;if(o&&o.numFmt!=="bullet"){const R=o.numId??o.abstractNumId??"default",h=o.level??0,d=`${R}:${h}`,u=t.get(d),p=(u??(o.start??1)-1)+1;t.set(d,p);for(const f of t.keys())f.startsWith(`${R}:`)&&Number(f.slice(R.length+1))>h&&t.delete(f);l=(o.lvlText??"%1.").replace(/%([1-9])/g,(f,g)=>{const M=Number(g)-1;return String(M===h?p:t.get(`${R}:${M}`)??o.start??1)})}e.push({id:JSON.stringify(i.path),level:r,name:a,number:l})}),{toc:e}}function Dr(c,e){const t=[];if(!e)return{results:t,count:0};const n=e.toLowerCase();return $(c,(i,s)=>{if(i.type!=="text")return;const a=(i.value||"").toLowerCase();let r=a.indexOf(n);for(;r!==-1;)t.push({path:[...s.path],offset:r,length:e.length}),r=a.indexOf(n,r+1)}),{results:t,count:t.length}}class Vi{constructor(){S(this,"worker",null);S(this,"failed",!1);S(this,"destroyed",!1);S(this,"pending",!1);S(this,"elements",[]);S(this,"tocListeners",new Set);S(this,"searchListeners",new Set);S(this,"cloneListeners",new Set);S(this,"errorListeners",new Set)}init(){if(!(this.worker||this.failed||this.destroyed))try{this.worker=new Worker(new URL(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/editor-worker-CG2Et0Mg.js").href:new URL("assets/editor-worker-CG2Et0Mg.js",typeof document>"u"?location.href:document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||document.baseURI).href),typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:pe&&pe.tagName.toUpperCase()==="SCRIPT"&&pe.src||new URL("core.umd.cjs",document.baseURI).href),{type:"module"}),this.worker.onmessage=e=>{const t=e.data;switch(t.type){case"toc-result":this.tocListeners.forEach(n=>n({toc:t.toc}));break;case"search-result":this.searchListeners.forEach(n=>n({results:t.results,count:t.count}));break;case"clone-result":this.cloneListeners.forEach(n=>n(t.data));break;case"error":this.fallback(t.message);break}},this.worker.onerror=e=>this.fallback(e.message),this.worker.onmessageerror=()=>this.fallback("Worker message could not be decoded")}catch(e){this.failed=!0,this.errorListeners.forEach(t=>t(String(e)))}}fallback(e){var n;(n=this.worker)==null||n.terminate(),this.worker=null,this.failed=!0,this.errorListeners.forEach(i=>i(e));const t=Yi(this.elements);this.tocListeners.forEach(i=>i(t))}updateElements(e){this.destroyed||(this.elements=e,!this.pending&&(this.pending=!0,queueMicrotask(()=>this.flush())))}flush(){if(!(!this.pending||this.destroyed))if(this.pending=!1,this.init(),this.worker)try{this.worker.postMessage({type:"update",elements:this.elements})}catch(e){this.fallback(String(e))}else{const e=Yi(this.elements);this.tocListeners.forEach(t=>t(e))}}search(e){if(this.destroyed)return;if(this.flush(),this.init(),this.worker)try{this.worker.postMessage({type:"search",keyword:e});return}catch(n){this.fallback(String(n))}const t=Dr(this.elements,e);this.searchListeners.forEach(n=>n(t))}clone(e){if(this.destroyed)return;if(this.init(),this.worker)try{this.worker.postMessage({type:"clone",data:e});return}catch(n){this.fallback(String(n))}const t=H(e);this.cloneListeners.forEach(n=>n(t))}onTocResult(e){return this.tocListeners.add(e),()=>this.tocListeners.delete(e)}onSearchResult(e){return this.searchListeners.add(e),()=>this.searchListeners.delete(e)}onCloneResult(e){return this.cloneListeners.add(e),()=>this.cloneListeners.delete(e)}onError(e){return this.errorListeners.add(e),()=>this.errorListeners.delete(e)}destroy(){var e;this.destroyed=!0,(e=this.worker)==null||e.terminate(),this.worker=null,this.elements=[],this.tocListeners.clear(),this.searchListeners.clear(),this.cloneListeners.clear(),this.errorListeners.clear()}}class $r{constructor(e){S(this,"worker",null);S(this,"epoch",0);S(this,"sources",[]);S(this,"color","");S(this,"scheduled",!1);S(this,"sourcesDirty",!1);S(this,"disposed",!1);S(this,"failed",!1);S(this,"invalidated",!1);this.publish=e}invalidate(){this.epoch++,this.color="",this.invalidated=!0}update(e,t){if(this.disposed||this.failed)return;this.invalidated=!1;const n=e.length!==this.sources.length||e.some((i,s)=>i!==this.sources[s]);!n&&t===this.color||(this.sources=e,this.color=t,this.sourcesDirty||(this.sourcesDirty=n),this.epoch++,!this.scheduled&&(this.scheduled=!0,queueMicrotask(()=>this.flush())))}flush(){if(this.scheduled=!1,!(this.disposed||this.failed||this.invalidated))try{this.worker||(this.worker=new Worker(new URL(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/thumbnail-worker-BGjZ82h0.js").href:new URL("assets/thumbnail-worker-BGjZ82h0.js",typeof document>"u"?location.href:document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||document.baseURI).href),typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:pe&&pe.tagName.toUpperCase()==="SCRIPT"&&pe.src||new URL("core.umd.cjs",document.baseURI).href),{type:"module"}),this.worker.onmessage=e=>{if(!(this.disposed||e.data.id!==this.epoch)){if(e.data.error){this.fail(e.data.error);return}e.data.images&&this.publish(e.data.images)}},this.worker.onerror=e=>this.fail(e.message),this.worker.onmessageerror=()=>this.fail("Thumbnail worker message could not be decoded")),this.worker.postMessage({id:this.epoch,color:this.color,...this.sourcesDirty?{sources:this.sources}:{}}),this.sourcesDirty=!1}catch(e){this.fail(String(e))}}fail(e){var t;this.failed=!0,(t=this.worker)==null||t.terminate(),this.worker=null,console.warn("[VerveDocs] Background thumbnails unavailable:",e)}destroy(){var e;this.disposed=!0,this.epoch++,(e=this.worker)==null||e.terminate(),this.worker=null,this.sources=[]}}class an{constructor(e,t,n={}){S(this,"i18n");S(this,"listener");S(this,"eventBus");S(this,"range");S(this,"draw");S(this,"command");S(this,"adapt");S(this,"destroyed",!1);S(this,"clipboardEpoch",0);S(this,"plugins",new Map);S(this,"pluginCommands",new Map);S(this,"commandChain",new ui);S(this,"pluginHost",null);S(this,"search");S(this,"block");S(this,"date");S(this,"laTex");S(this,"control");S(this,"history");S(this,"worker");S(this,"thumbnailWorker");S(this,"thumbnailSources",[]);if(!e||!(e instanceof HTMLDivElement))throw new TypeError("[DocxEditor] container 必须是 HTMLDivElement");if(!t||typeof t!="object"||!Array.isArray(t.elements))throw new TypeError("[DocxEditor] document 必须是 IDocxDocumentMeta,且 elements 为数组。不再兼容 IElement[] / IEditorData 形态。");this.i18n=ln(n.locale);const i=Nn({...n,locale:this.i18n.locale}),s=H(t);if(be(s.elements,{editorOptions:i,styles:s.styles,numbering:s.numbering}),s.sections!==void 0&&!Array.isArray(s.sections))throw new TypeError("旧 sections 内容区必须显式迁移到 contentZones");for(const R of[s.header,s.footer,...Object.values(s.contentZones??{}),...Object.values(s.headerFooterParts??{})])R&&be(R,{editorOptions:i,styles:s.styles,numbering:s.numbering});this.listener=new _t,this.thumbnailWorker=new $r(R=>{this.destroyed||this.listener.emit("thumbnailChange",R)}),this.listener.on("thumbnailAppearanceChange",()=>this.refreshThumbnailAppearance());for(const R of["contentChange","documentSet"])this.listener.on(R,()=>this.thumbnailWorker.invalidate());this.eventBus=new bn,this.range=new Un(this.listener);for(const R of["contentChange","documentSet","rangeChange","zoneChange","abilityChange"])this.listener.on(R,()=>{this.clipboardEpoch++});this.wireAfterRenderHooks();let a=null;const r=new Ar({getDraw:()=>this.draw,getCommand:()=>this.command,dispatchCommand:(R,...h)=>this.dispatchCommand(R,...h),getRange:()=>this.range,getAdapt:()=>a});this.draw=new di(e,i,{document:s,i18n:this.i18n,listener:this.listener,eventBus:this.eventBus,rangeManager:this.range,onInput:R=>{a==null||a.insertText(R)},onKeyDown:r.handle,afterRender:()=>{this.listener.emit("afterRender")},onCommand:(R,...h)=>this.commandChain.dispatch(R,...h),onZoneChange:R=>{this.listener.emit("zoneChange",R)}}),a=new pi({getDocument:()=>this.draw.getDocument(),setDocument:R=>this.draw.setDocument(R),getLayout:()=>this.draw.getLayout(),getScroller:()=>this.draw.getScroller(),getActiveDocument:()=>this.draw.getActiveDocument(),applyActiveDocument:R=>{this.draw.getZone()==="main"?this.draw.setDocument(R):this.draw.applyActiveDocument(R)},setScale:R=>this.draw.setScale(R),setPageSize:(R,h)=>this.draw.setPageSize(R,h),setRulerVisible:R=>this.draw.setRulerVisible(R),setPaperMargins:R=>this.draw.setPaperMargins(R),getOptions:()=>this.draw.getOptions(),updateOptions:R=>this.draw.updateOptions(R),getZone:()=>this.draw.getZone(),setZone:R=>this.draw.setZone(R),setZoneWithCaret:R=>this.draw.setZoneWithCaret(R),print:()=>this.draw.print(),getPageThumbnails:()=>this.draw.getPageThumbnails(),scrollPositionIntoView:R=>this.draw.scrollPositionIntoView(R)},this.range,this.listener),this.adapt=a,this.command=new fi(a),this.commandChain.use((R,h,d)=>{if(R==="requestInsertImage"){this.listener.emit("requestInsertImage");return}if(R==="requestInsertHyperlink"){this.listener.emit("requestInsertHyperlink");return}if(R==="requestInsertFormula"){this.listener.emit("requestInsertFormula");return}if(R==="executeTableProperty"){this.listener.emit("requestTableProperties");return}return d()}).use((R,h,d)=>{const u=this.pluginCommands.get(R);return typeof u=="function"?u(...h):d()}).use((R,h,d)=>{var u;if(R==="executeCopy"||R==="executeCut"){if(R==="executeCut"&&!this.command.getIsCanInput())return;const p=this.command.executeCopy();if(!navigator.clipboard)return;const f=this.clipboardGuard(),g=a.copyFragment(),M="web application/x-vervedocs+json";return(g&&typeof ClipboardItem<"u"&&((u=ClipboardItem.supports)!=null&&u.call(ClipboardItem,M))?navigator.clipboard.write([new ClipboardItem({"text/plain":new Blob([p],{type:"text/plain"}),[M]:new Blob([JSON.stringify(g)],{type:"application/x-vervedocs+json"})})]):navigator.clipboard.writeText(p)).then(()=>(R==="executeCut"&&f()&&this.command.executeCut(),p)).catch(()=>{})}if(["executePaste","executePastePlain","executePasteNoFormat"].includes(R)){if(!this.command.getIsCanInput())return;if(h.length>0)return d();if(!navigator.clipboard)return;const p=this.clipboardGuard();return(async()=>{const f="web application/x-vervedocs+json";if(R==="executePaste"&&navigator.clipboard.read){const g=await navigator.clipboard.read();for(const M of g)if(M.types.includes(f)){const O=JSON.parse(await(await M.getType(f)).text());p()&&a.pasteFragment(O);return}for(const M of g)if(M.types.includes("text/plain")){const O=await(await M.getType("text/plain")).text();p()&&this.command.executePaste(O);return}}else{const g=await navigator.clipboard.readText();p()&&this.command.executePasteNoFormat(g)}})().catch(()=>{})}return d()}).use((R,h,d)=>{if(!this.command)return;const u=this.command[R];if(typeof u=="function")return u.call(this.command,...h)}),this.history=new mi;const l=this.history.install({maxRecordCount:Number(i.historyMaxRecordCount??50),coalesceMs:300});a.setHistoryManager(l),a.pushInitialHistory(),this.search=new Ni(this.draw),this.block=new Ti(this.draw),this.date=new Si(this.draw),this.laTex=new Xi(this.draw),this.control=new Li,this.control.install(this.draw);const o=this.draw;this.pluginHost={getI18n:()=>this.i18n,getContainer:()=>o.getScroller(),getPositionList:()=>null,getRevisionAnchor:R=>o.getRevisionAnchorMap().get(R)||null,getDrawWidth:()=>Number(i.pageWidth??794),getDrawHeight:()=>Number(i.pageHeight??1123),getPageGap:()=>Number(i.pageGap??24),getOptions:()=>i,getElementList:()=>o.getDocument().elements,getDocument:()=>o.getDocument(),commitTransaction:R=>this.adapt.commitPluginTransaction(R),getGroupContext:R=>{const d=o.getGroupAnchorMap().get(R);return d?{isTable:!1,index:-1,startIndex:-1,endIndex:-1,_anchor:d}:null},executeSetGroup:R=>this.adapt.setGroup(R),executeDeleteGroup:R=>{var h;(h=this.command)==null||h.executeDeleteGroup(R)},executeLocationGroup:R=>{var h;(h=this.command)==null||h.executeLocationGroup(R)},executeUpdateOptions:R=>{this.adapt.updateOptions(R)},setActiveGroup:R=>{o.setActiveGroup(R)},setActiveRevision:(R,h)=>{o.setActiveRevision(R,h)},getEventBus:()=>this.eventBus,setChartRenderer:R=>o.setChartRenderer(R),executeInsertChart:R=>{var h;(h=this.command)==null||h.executeInsertChart(R)},executeUpdateChart:(R,h)=>{var d;(d=this.command)==null||d.executeUpdateChart(R,h)}},this.listener.on("documentSet",R=>{var h,d;for(const u of this.plugins.values())(d=(h=u.hooks)==null?void 0:h.onSetDocument)==null||d.call(h,R)}),this.worker=new Vi,this.worker.onTocResult(R=>{this.listener.emit("tocChange",R.toc)}),this.listener.on("contentChange",()=>{this.worker.updateElements(this.draw.getDocument().elements)}),this.worker.updateElements(s.elements)}clipboardGuard(){const e=this.draw.getDocument(),t=this.clipboardEpoch,n=this.draw.getZone(),i=JSON.stringify(this.range.getRange());return()=>!this.destroyed&&t===this.clipboardEpoch&&e===this.draw.getDocument()&&n===this.draw.getZone()&&i===JSON.stringify(this.range.getRange())}wireAfterRenderHooks(){this.listener.lifecycle.afterRenderListener(()=>{var e,t,n,i;for(const s of this.plugins.values())(t=(e=s.hooks)==null?void 0:e.afterRender)==null||t.call(e);if(this.renderEmbedBlocks(),(n=this.block)==null||n.clear(),(i=this.control)==null||i.clear(),this.listener.hasListeners("thumbnailChange")){const s=this.draw.getPageThumbnails(),a=this.draw.getThumbnailForegrounds();(a.length!==this.thumbnailSources.length||a.some((r,l)=>r!==this.thumbnailSources[l]))&&(this.listener.emit("thumbnailChange",s),this.thumbnailSources=a),this.refreshThumbnailAppearance(a)}})}refreshThumbnailAppearance(e){if(this.destroyed||!this.draw||!this.listener.hasListeners("thumbnailChange"))return;const t=this.draw.getOptions(),n=t.background;this.thumbnailWorker.update(e??this.draw.getThumbnailForegrounds(),t.eyeCare?"#C7EDCC":(n==null?void 0:n.color)||"#ffffff")}renderEmbedBlocks(){if(!this.block)return;const e=this.draw.getLayout();if(e){for(const t of e.pages)for(const n of t.blocks)if(n.kind==="block"){const i=t.contentRect.x+n.rect.x,s=t.contentRect.y+n.rect.y;this.block.render(t.index,n.block,i,s)}}}getDocument(){return this.draw.getDocument()}getLocale(){return this.i18n.locale}setLocale(e){this.i18n.setLocale(e)}getI18n(){return this.i18n}setDocument(e){if(!e||!Array.isArray(e.elements))throw new TypeError("[DocxEditor.setDocument] 需要 IDocxDocumentMeta");this.adapt.replaceDocument(e,!0)}use(e){var t;if(this.plugins.has(e.name)){console.warn(`[DocxEditor] 插件 "${e.name}" 已注册,忽略重复注册`);return}if(this.plugins.set(e.name,e),this.pluginHost&&e.install(this.pluginHost),e.commands)for(const[n,i]of Object.entries(e.commands))this.pluginCommands.set(n,i);(t=e.hooks)!=null&&t.onSetDocument&&e.hooks.onSetDocument(this.draw.getDocument())}getPlugin(e){return this.plugins.get(e)}dispatchCommand(e,...t){return this.commandChain.dispatch(e,...t)}destroy(){var e,t,n,i,s;this.destroyed=!0;for(const a of this.plugins.values())(e=a.destroy)==null||e.call(a);(t=this.block)==null||t.destroy(),(n=this.date)==null||n.clearDatePicker(),(i=this.control)==null||i.destroy(),(s=this.history)==null||s.destroy(),this.draw.destroy(),this.thumbnailWorker.destroy(),this.worker.destroy(),this.listener=new _t,this.eventBus.clear(),this.range.clear()}}const zr=ve.map(c=>({label:c.label,value:c.value})),jr=rt.map(c=>{const e=Ae[c];return{label:c,value:e??Number(c)}}),qr=[{label:"自动",value:120},{label:"40",value:40},{label:"50",value:50},{label:"60",value:60},{label:"70",value:70},{label:"80",value:80},{label:"90",value:90},{label:"100",value:100},{label:"120",value:120},{label:"140",value:140},{label:"160",value:160},{label:"180",value:180},{label:"200",value:200}],ea="4.0.0-tree";L.BLOCK_LEVEL_TYPES=Kt,L.BULLET_STYLES=un,L.BlockParticle=Ti,L.CanvasRenderer=vn,L.Command=fi,L.CommandAdapt=pi,L.CommandChain=ui,L.ControlComponent=Li,L.DEFAULT_EDITOR_OPTION=_e,L.DEFAULT_PAPER_SIZE=xi,L.DPI=Ht,L.DateParticle=Si,L.DocxEditor=an,L.Draw=di,L.EDITOR_FONT_OPTIONS=zr,L.EDITOR_SIZE_OPTIONS=jr,L.Editor=an,L.EventBus=bn,L.FONT_FAMILY=Ii,L.FONT_FAMILY_CSS=st,L.FONT_FAMILY_LABEL=vt,L.FONT_FAMILY_LIST=cn,L.FONT_FAMILY_MAP=ve,L.FONT_FAMILY_VALUE=hn,L.FONT_SIZE=Ae,L.FONT_SIZE_LIST=rt,L.HistoryComponent=mi,L.HistoryManager=Wi,L.KeyMap=gs,L.LINE_HEIGHT_OPTIONS=Gi,L.LIST_STYLE=wt,L.LIST_TYPE=It,L.LaTexParticle=Xi,L.LayoutEngine=In,L.Listener=_t,L.MARGIN_PRESETS=Ji,L.NUMBER_STYLES=pn,L.PAPER_SIZE_LIST=dn,L.PARAGRAPH_ATTR_KEYS=yi,L.PARAGRAPH_CONTAINER_TYPES=Ki,L.PaperDirection=wi,L.ROW_FLEX=Se,L.RangeManager=Un,L.SCHEMA_VERSION=Fi,L.SEPARATOR_STYLES=Ci,L.Search=Ni,L.TITLE_LEVEL=me,L.TITLE_LEVEL_MAP=Ei,L.TableBorder=Mt,L.TextMeasure=Nt,L.WATERMARK_SIZE_OPTIONS=qr,L.WorkerManager=Vi,L.ZOOM_LEVELS=ki,L._pathSegAsKey=ss,L.adjustFloatImagePositions=rs,L.applyImageLayout=Pt,L.clearRevision=at,L.cloneTree=H,L.comparePath=De,L.comparePosition=Fe,L.createSnapshot=_r,L.default=an,L.forEachCell=ns,L.formatElementTree=be,L.getAuthorColor=gn,L.getByPath=I,L.getParentContainer=E,L.getRevisionOldProps=Jt,L.getSharedMeasure=Tt,L.getTableColCount=is,L.hitTest=zt,L.insertAtPath=es,L.isApple=Yn,L.isMod=Ms,L.isParagraphContainer=St,L.isSamePath=z,L.isTable=Ot,L.mergeOption=Nn,L.pairBookmarkMarkers=Ln,L.ptToPx=vi,L.pxToPt=Hi,L.recordFormatRevision=On,L.removeAtPath=ts,L.replaceAtPath=qi,L.resolveHeaderFooterPart=Ct,L.restoreRevisionFormat=Di,L.snapshotRevisionFormat=Gt,L.splitParagraphs=Oe,L.toDocxExportDocument=mn,L.updateImageLayout=$e,L.version=ea,L.walkTree=$,Object.defineProperties(L,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
431
431
  //# sourceMappingURL=core.umd.cjs.map