@bireturn/word-editor 1.0.7 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- (function(J,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("vue-virtual-scroller"),require("lucide-vue-next")):typeof define=="function"&&define.amd?define(["exports","vue","vue-virtual-scroller","lucide-vue-next"],e):(J=typeof globalThis<"u"?globalThis:J||self,e(J.WordEditor={},J.Vue,J.VueVirtualScroller,J.LucideVueNext))})(this,function(J,e,Ee,M){"use strict";var io=Object.defineProperty;var ro=(J,e,Ee)=>e in J?io(J,e,{enumerable:!0,configurable:!0,writable:!0,value:Ee}):J[e]=Ee;var N=(J,e,Ee)=>ro(J,typeof e!="symbol"?e+"":e,Ee);const bt={class:"we-vt-context-menu--option-wrapper modern-menu-wrapper"},_t=["onMouseenter","onMouseleave"],wt=["onClick"],xt={class:"we-vt-context-menu--link-content menu-label"},Et={key:0,class:"we-vt-context-menu--submenu modern-submenu"},Ct=["onClick"],Bt={class:"we-vt-context-menu--link-content submenu-label"},Mt={__name:"ContextMenu",props:{e:{type:Object,default:()=>({})},row:{type:Object,default:()=>({})},menuConfig:{type:Object,default:()=>({body:{}})}},emits:["close","menuClick"],setup(n,{emit:t}){const o=t,a=n,i=e.computed(()=>{var H,A;return{left:`${(H=a.e)==null?void 0:H.pageX}px`,top:`${(A=a.e)==null?void 0:A.pageY}px`}}),c=e.ref([]),y=e.ref(null);let s=null;const m=e.ref(),f=(H,A,u)=>{if(H.children&&H.children.length>0){A&&A.preventDefault()&&A.stopPropagation();return}H.disabled||(u?o("menuClick",{...H,parent:u.code},a.row):o("menuClick",H,a.row)),A&&A.preventDefault()&&A.stopPropagation()},F=H=>{let A=H.target;for(;A&&A!=m.value;)A=A.parentNode;A!=m.value&&o("close")},T=(H,A)=>{H.currentTarget.classList.add("link--active"),s&&(clearTimeout(s),s=null),A.children&&A.children.length>0?y.value=A.code:s=setTimeout(()=>{y.value=null},100)},R=(H,A)=>{H.currentTarget.classList.remove("link--active"),A.children&&A.children.length>0&&(s=setTimeout(()=>{y.value===A.code&&(y.value=null)},300))},_=H=>{s&&(clearTimeout(s),s=null),H.currentTarget.classList.add("link--active")},v=H=>{H.currentTarget.classList.remove("link--active")},X=H=>{const A=H.code||"",u=(H.name||"").toLowerCase(),C={"add-current":M.Navigation,"add-next":M.ArrowDown,"add-child":M.PlusCircle,paste:M.Clipboard,delete:M.Trash2,copy:M.Copy,cut:M.Move,edit:M.Edit,export_part_section:M.Layers,export_part_chapter:M.FileDown,export_full:M.Download,pdf:M.FileText,word:M.Type,excel:M.Grid,txt:M.FileText,view:M.Eye,preview:M.Eye,expand:M.Plus,collapse:M.Minus,"sort-asc":M.SortAsc,"sort-desc":M.SortDesc,filter:M.Filter,search:M.Search,permission:M.ShieldCheck,share:M.Share,lock:M.Lock,unlock:M.Globe,info:M.Info,settings:M.Settings,history:M.History,refresh:M.RotateCcw,save:M.Save,upload:M.Upload,download:M.Download,more:M.MoreHorizontal};return C[A]?C[A]:u.includes("添加")||u.includes("add")?u.includes("当前")||u.includes("current")?M.Navigation:u.includes("下")||u.includes("next")?M.ArrowDown:u.includes("子")||u.includes("child")?M.PlusCircle:M.Plus:u.includes("导出")||u.includes("export")?u.includes("节")||u.includes("section")?M.Layers:u.includes("章")||u.includes("chapter")?M.FileDown:M.Download:u.includes("粘贴")||u.includes("paste")?M.Clipboard:u.includes("删除")||u.includes("delete")?M.Trash2:u.includes("pdf")?M.FileText:u.includes("word")?M.Type:M.MoreHorizontal};return e.onMounted(()=>{var H,A,u,C,L,S,$;(H=a.menuConfig)!=null&&H.visibleMethod&&typeof((A=a.menuConfig)==null?void 0:A.visibleMethod)=="function"&&((L=a.menuConfig)==null||L.visibleMethod({options:(C=(u=a.menuConfig)==null?void 0:u.body)==null?void 0:C.options,row:a.row})),c.value=((($=(S=a.menuConfig)==null?void 0:S.body)==null?void 0:$.options)||[]).flat(),document.addEventListener("click",F,!0)}),e.onUnmounted(()=>{document.removeEventListener("click",F,!0)}),(H,A)=>(e.openBlock(),e.createElementBlock("div",{class:"we-vt-table--context-menu-wrapper virtual-table-menu modern-virtual-menu",ref_key:"contextMenuRef",ref:m,style:e.normalizeStyle([{display:"inline-block"},i.value])},[e.createElementVNode("ul",bt,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(c.value,u=>(e.openBlock(),e.createElementBlock("li",{class:e.normalizeClass({"link--disabled":u.disabled,"has-children":u.children&&u.children.length>0,"modern-menu-item":!0}),key:u.code,onMouseenter:C=>T(C,u),onMouseleave:C=>R(C,u)},[e.createElementVNode("a",{class:"we-vt-context-menu--link modern-menu-link",onClick:C=>f(u,C)},[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(X(u)),{size:16,class:"menu-icon"})),e.createElementVNode("span",xt,e.toDisplayString(u.name),1),u.children&&u.children.length>0?(e.openBlock(),e.createBlock(e.unref(M.ChevronRight),{key:0,size:14,class:"submenu-arrow"})):e.createCommentVNode("",!0)],8,wt),u.children&&u.children.length>0&&y.value===u.code?(e.openBlock(),e.createElementBlock("ul",Et,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(u.children,C=>(e.openBlock(),e.createElementBlock("li",{key:C.code,class:e.normalizeClass({"link--disabled":C.disabled,"modern-submenu-item":!0}),onMouseenter:_,onMouseleave:v},[e.createElementVNode("a",{class:"we-vt-context-menu--link modern-submenu-link",onClick:L=>f(C,L,u)},[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(X(C)),{size:14,class:"submenu-icon"})),e.createElementVNode("span",Bt,e.toDisplayString(C.name),1)],8,Ct)],34))),128))])):e.createCommentVNode("",!0)],42,_t))),128))])],4))}},Qe=Symbol("component_container");function St(n,t,o){const a=e.h(n,{...t},o),i=document.createElement("div");return document.body.appendChild(i),a[Qe]=i,e.render(a,i),a.component}function Ft(n){var o;const t=n.vnode[Qe];e.render(null,t),t!=null&&t.checkVisibility&&(t!=null&&t.checkVisibility())&&((o=document.body)==null||o.removeChild(t))}let et;const It=n=>{et=St(Mt,n,null)},Tt=function(n){const t=n.onClose;return n.onClose=()=>{t&&t.call(),Ft(et)},It(n),n};function At(n,t,o){const a=(o==null?void 0:o.keyField)||(o==null?void 0:o.rowField)||"node_id",i=(o==null?void 0:o.parentField)||"parent_id",c=(o==null?void 0:o.parentField)||"order";if(!(n!=null&&n.length))return n;const y={};n.forEach(F=>{const T=F[i];y[T]||(y[T]=[]),y[T].push(F)});function s(F){const T=y[F]||[];T.sort((_,v)=>_[c]&&v[c]?_[c]-v[c]:0);const R=[];return T.forEach(_=>{R.push(_),R.push(...s(_[a]))}),R}let m=[];if(Array.isArray(t))m=t;else{const F=new Set(n.map(_=>_[a])),T=n.filter(_=>!F.has(_[i]));if(T.length===0)throw new Error("无法确定根节点:可能存在循环引用或数据不完整");const R={};T.forEach(_=>{const v=_[i];R[v]=(R[v]||0)+1}),m=Object.entries(R).map(([_])=>_)}let f=[];return m.forEach(F=>{f=f.concat(s(F))}),f}function tt(n,t,o){let a;for(;n&&n.nodeType&&n!==document;){if(n.className&&n.className.split&&n.className.split(" ").indexOf(t)>-1)return a=n,a;if(n===o)return null;n=n.parentNode}return a}function Pt(n){return typeof n=="function"||Object.prototype.toString.call(n)==="[object Object]"&&!e.isVNode(n)}const Lt=e.defineComponent({name:"VirtualTable",props:{data:{type:Array,required:!0,default:()=>[]},rowConfig:{type:Object,default:()=>({keyField:"node_id"})},editConfig:{type:Object,default:null},treeConfig:{type:Object,default:null},menuConfig:{type:Object,default:()=>({body:{}})},showHeader:{type:Boolean,default:!0},rowClassName:{type:Function,default:null},pageConfig:{type:Object,default:()=>({enabled:!1,pageHeight:842,pageWidth:595,margin:40,gap:10,showPageHeader:!0,showPageBorder:!1,pageBorderPadding:5,pageBorderStyle:"1px solid #000",headerHeight:0,footerHeight:0,showPageNumber:!0})},pageData:{type:Object,default:null}},emits:["current-change","menu-click","edit-activated","edit-closed","scroll-end","selection-change"],setup(n,{emit:t,slots:o,expose:a}){var kt;const i=e.getCurrentInstance(),c=e.ref(),y=e.ref(!1),s=e.ref(null),m=e.ref(null),f=e.ref([]);let F=new Map;const T=new Map;e.ref(0);const R=e.ref([]);e.ref([]);const _=e.ref(new Set),v=e.ref(new Set),X=e.ref(null),H=2,A=new WeakMap,u=e.ref(null),C=e.ref(""),L=new Set,S=e.computed(()=>{try{return Array.isArray(f.value)?f.value:[]}catch{return[]}}),$=l=>{var p,h,g;if(!l)return 30;if(l.height)return l.height;const r=`${l.content_type}_${((p=l.content)==null?void 0:p.length)||0}_${((h=l.title)==null?void 0:h.length)||0}_${l._editing?1:0}`;if(A.has(l)){const w=A.get(l);if(w.key===r)return w.height}let d=30;switch(l.content_type){case"image":d=150;break;case"table-row":d=l.rowHeight||35;break;case"table":const x=((l.content||"").match(/<tr/g)||[]).length;d=Math.max(100,x*35+30);break;case"flowchart":d=200;break;default:{const k=(l.content||"").length,b=(l.title||"").length,E=k+b,P=((g=(l.content||"").match(/[\u4e00-\u9fa5]/g))==null?void 0:g.length)||0,D=E-P,I=P*12+D*6,B=Math.max(1,Math.ceil(I/760));d=Math.max(20,B*18),l._editing&&(d+=20);break}}return A.set(l,{key:r,height:d}),d},q=e.computed(()=>{if(S.value.length===0)return 30;const l=S.value.slice(0,Math.min(100,S.value.length));if(l.length===0)return 30;const r=l.reduce((p,h)=>p+$(h),0)/l.length,d=Math.max(20,Math.floor(r*.6));return Math.min(d,60)});let Y;const Xe=(l,r)=>{t("menu-click",{menu:l,row:r}),Y==null||Y.onClose(),Y=null},V=l=>{var d,p,h,g,w;if(!((h=(p=(d=n.menuConfig)==null?void 0:d.body)==null?void 0:p.options)!=null&&h.length))return;Y==null||Y.onClose(),Y=null;let r=l.target;for(;r&&(r!=null&&r.getAttribute)&&!(r!=null&&r.getAttribute("data-id"))&&r!==((g=c.value)==null?void 0:g.$el);)r=r.parentNode;if((w=r==null?void 0:r.getAttribute)!=null&&w.call(r,"data-id")){const x=r.getAttribute("data-id"),k=ye(x);k&&(Y=Tt({e:l,row:k,menuConfig:n.menuConfig,onMenuClick:Xe}),l.preventDefault(),l.stopPropagation())}},le=l=>{var d,p,h;if(!s.value)return;let r=l.target;for(;r&&(r!=null&&r.getAttribute)&&!(r!=null&&r.getAttribute("data-id"))&&r!==((d=c.value)==null?void 0:d.$el);)if(r=r.parentNode,r!=null&&r.classList&&["el-popper","ck-body-wrapper"].some(g=>r.classList.contains(g)))return;((p=r==null?void 0:r.getAttribute)==null?void 0:p.call(r,"data-id"))!=((h=s.value)==null?void 0:h.node_id)&&(s.value._editing=!1,t("edit-closed",{row:s.value,column:{},$table:i==null?void 0:i.exposed}),s.value=null)};((kt=n.editConfig)==null?void 0:kt.trigger)==="dblclick"&&e.watch(()=>s.value,l=>{document.removeEventListener("click",le,!0),l&&setTimeout(()=>{document.addEventListener("click",le,!0)},200)});const se=l=>JSON.stringify(l.map(r=>{var d;return{id:r[n.rowConfig.keyField],content:((d=r.content)==null?void 0:d.length)||0,type:r.content_type,editing:r._editing}})),ue=()=>{if(!n.pageConfig.enabled){R.value=[{items:f.value,startIndex:0,endIndex:f.value.length}];return}if(n.pageData&&Object.keys(n.pageData).length){const l=[],r=n.rowConfig.keyField||"node_id",d=new Map;f.value.forEach(h=>{d.set(String(h[r]),h)}),Object.keys(n.pageData).sort((h,g)=>parseInt(h)-parseInt(g)).forEach(h=>{const g=n.pageData[h],w=[];g.forEach(x=>{const k=d.get(String(x));k&&w.push(k)}),w.length>0&&l.push({items:w,pageNumber:parseInt(h),height:w.reduce((x,k)=>x+$(k),0)})}),R.value=l}else{const{pageHeight:l,margin:r,headerHeight:d=0}=n.pageConfig,h=Math.max(100,l-r*2-d-20),g=[];let w=[],x=0,k=0,b=1;f.value.forEach((E,P)=>{const D=$(E);(E.layer||0)<=2&&w.length>0?(g.push({items:[...w],startIndex:k,endIndex:P,height:x,pageNumber:b++}),w=[E],x=D,k=P):x+D>h&&w.length>0?(g.push({items:[...w],startIndex:k,endIndex:P,height:x,pageNumber:b++}),w=[E],x=Math.min(D,h),k=P):(w.push(E),x+=D)}),w.length>0&&g.push({items:w,startIndex:k,endIndex:f.value.length,height:x,pageNumber:b}),R.value=g}},Ae=()=>{try{const l=Array.isArray(n.data)?n.data:[],r=se(l);if(!(r!==C.value)&&f.value.length>0)return;C.value=r;const p=(n.treeConfig?At(l,void 0,n.treeConfig):l).map((g,w)=>{const x=g[n.rowConfig.keyField],k=T.get(x);if(!k||k.content!==g.content||k.content_type!==g.content_type){L.add(x);const b={...g,index:w,_editing:g._editing||!1,_original:(k==null?void 0:k._original)||{...g}};return T.set(x,b),b}return k.index=w,k});f.value=p,ue();const h=new Set(p.map(g=>g[n.rowConfig.keyField]));for(const[g]of T)h.has(g)||(T.delete(g),L.delete(g))}catch{f.value=[],R.value=[],T.clear(),L.clear()}};e.watch(()=>n.data,(l,r)=>{try{if(!Array.isArray(l))return;e.nextTick(()=>{if(Ae(),n.pageConfig.enabled){v.value.clear(),_.value.clear();for(let d=0;d<Math.min(3,R.value.length);d++)v.value.add(d);e.nextTick(()=>{ne()})}})}catch{}},{deep:!1,immediate:!1}),e.watch(()=>n.pageData,()=>{if(n.pageConfig.enabled){ue(),v.value.clear(),_.value.clear();for(let l=0;l<Math.min(3,R.value.length);l++)v.value.add(l);e.nextTick(()=>{ne()})}},{deep:!0}),e.watch(()=>n.pageConfig,()=>{if(n.pageConfig.enabled){ue(),v.value.clear(),_.value.clear();for(let l=0;l<Math.min(3,R.value.length);l++)v.value.add(l);e.nextTick(()=>{ne()})}},{deep:!0}),e.watch(m,()=>t("current-change",{row:m.value}));let _e=null;const ce=()=>{window.ResizeObserver&&(_e=new ResizeObserver(l=>{var r,d;for(const p of l){const h=(r=p.target.dataset)==null?void 0:r.id;if(!h)continue;const g=ye(h);if(!g)continue;const w=p.contentRect.height,x=((d=A.get(g))==null?void 0:d.height)||0;if(Math.abs(x-w)>5){const k=A.get(g)||{};A.set(g,{...k,height:w}),requestAnimationFrame(()=>{var E;const b=p.target.__vueParentComponent;(E=b==null?void 0:b.proxy)!=null&&E.updateSize&&b.proxy.updateSize()})}}}),e.nextTick(()=>{var d;const l=(d=c.value)==null?void 0:d.$el;if(!l)return;l.querySelectorAll("[data-id]").forEach(p=>{p.dataset.id&&_e.observe(p)})}))},te=()=>{u.value&&(u.value.disconnect(),u.value=null),_e&&(_e.disconnect(),_e=null)},ne=()=>{n.pageConfig.enabled&&(X.value&&X.value.disconnect(),X.value=new IntersectionObserver(l=>{l.forEach(r=>{const d=parseInt(r.target.dataset.pageIndex);if(r.isIntersecting){_.value.add(d);for(let p=Math.max(0,d-H);p<=Math.min(R.value.length-1,d+H);p++)v.value.add(p)}else _.value.delete(d),setTimeout(()=>{_.value.has(d)||Array.from(_.value).some(h=>Math.abs(h-d)<=H*2)||v.value.delete(d)},3e3)})},{root:null,rootMargin:"100px",threshold:.01}),e.nextTick(()=>{const l=document.querySelector(".a4-pages-container");l&&l.querySelectorAll(".a4-page-placeholder").forEach(d=>{X.value.observe(d)})}))};e.onMounted(()=>{Ae(),e.nextTick(()=>{var l;if(ce(),he.setup(),ne(),((l=n.editConfig)==null?void 0:l.trigger)==="contenteditable"&&(document.addEventListener("selectionchange",we),document.addEventListener("mouseup",Re)),n.pageConfig.enabled)for(let r=0;r<Math.min(3,R.value.length);r++)v.value.add(r)}),y.value=!0}),e.onUnmounted(()=>{var l;te(),he.cleanup(),X.value&&(X.value.disconnect(),X.value=null),((l=n.editConfig)==null?void 0:l.trigger)==="contenteditable"&&(document.removeEventListener("selectionchange",we),document.removeEventListener("mouseup",Re)),U&&clearTimeout(U),F=new Map,T.clear(),v.value.clear(),_.value.clear()});const he={handlers:new Map,setup(){e.nextTick(()=>{var r;const l=(r=c.value)==null?void 0:r.$el;l&&(l.addEventListener("click",this.handleClick.bind(this),{passive:!0}),l.addEventListener("dblclick",this.handleDblClick.bind(this),{passive:!0}))})},handleClick(l){const r=l.target.closest("[data-id]");if(!r)return;const d=r.dataset.id,p=ye(d);p&&Oe(p)},handleDblClick(l){var h;if(!((h=n.editConfig)!=null&&h.trigger)==="dblclick")return;const r=l.target.closest("[data-id]");if(!r)return;const d=r.dataset.id,p=ye(d);p&&Pe(p)},cleanup(){var r,d;const l=(d=(r=c.value)==null?void 0:r.$el)==null?void 0:d.querySelector(".virtual-table-wrapper");l&&(l.removeEventListener("click",this.handleClick),l.removeEventListener("dblclick",this.handleDblClick))}},ge=l=>{Oe(l)},ae=l=>Pe(l);let Z=null,oe;const ie=({row:l,column:r},d,p)=>{var w,x;const h=p||d.target,g=tt(h,"virtual-table-cell",(w=c.value)==null?void 0:w.$el);Z===g&&oe&&(clearTimeout(oe),Z=null),((x=s.value)==null?void 0:x[n.rowConfig.keyField])!=(l==null?void 0:l[n.rowConfig.keyField])&&setTimeout(()=>{var b,E;s.value=l;let k=(b=h==null?void 0:h.getAttribute)==null?void 0:b.call(h,"field");if(!k){try{const P=document.getSelection();let D=P==null?void 0:P.anchorNode;D&&D.nodeType===3&&(D=D.parentElement);const I=(E=D==null?void 0:D.closest)==null?void 0:E.call(D,"[field]");I&&(k=I.getAttribute("field"))}catch{}if(!k&&(d!=null&&d.composedPath)){for(const P of d.composedPath())if(P!=null&&P.getAttribute&&P.getAttribute("field")){k=P.getAttribute("field");break}}}t("edit-activated",{row:l,column:{...r,field:k},$table:i==null?void 0:i.exposed})},200)},pe=({row:l,column:r},d,p)=>{var g;const h=p||d.target;Z=tt(h,"virtual-table-cell",(g=c.value)==null?void 0:g.$el),oe&&clearTimeout(oe),oe=setTimeout(()=>{var k,b,E,P,D;const w=l.content_type;let x=(k=h==null?void 0:h.getAttribute)==null?void 0:k.call(h,"field");if(!x){try{const I=document.getSelection();let B=I==null?void 0:I.anchorNode;B&&B.nodeType===3&&(B=B.parentElement);const j=(b=B==null?void 0:B.closest)==null?void 0:b.call(B,"[field]");j&&(x=j.getAttribute("field"))}catch{}if(!x&&(d!=null&&d.composedPath)){for(const I of d.composedPath())if(I!=null&&I.getAttribute&&I.getAttribute("field")){x=I.getAttribute("field");break}}}if(w!=="table"){if(w==="text"){let I=null,B=null;if((E=h==null?void 0:h.getAttribute)!=null&&E.call(h,"field")?I=h:(P=h==null?void 0:h.closest)!=null&&P.call(h,"[field]")&&(I=h.closest("[field]")),I&&(B=I.textContent),x&&B!==void 0&&B!==null){B=B.trim();const j=((D=l[x])==null?void 0:D.trim())||"";B!==j&&(l[x]=B)}}}t("edit-closed",{row:l,column:{...r,field:x},$table:i==null?void 0:i.exposed})},50)};let O=null,U=null;const W=l=>{var r;((r=n.editConfig)==null?void 0:r.trigger)==="contenteditable"&&me("focusin",l)},Q=l=>{var r,d,p,h,g;if(((r=n.editConfig)==null?void 0:r.trigger)==="contenteditable")if(O!=null&&O.cellEl){let w=O.fieldEl;!w&&O.field&&(w=(p=(d=O.cellEl)==null?void 0:d.querySelector)==null?void 0:p.call(d,`[field="${O.field}"]`)),w||(w=((g=(h=O.cellEl).querySelector)==null?void 0:g.call(h,"[field]"))||O.cellEl),pe(O,{target:w},w),O=null}else me("focusout",l)},me=(l,r)=>{var d,p,h,g,w,x;try{const k=document.getSelection();let b=k==null?void 0:k.anchorNode;b&&b.nodeType===3&&(b=b.parentElement);const E=(d=b==null?void 0:b.closest)==null?void 0:d.call(b,".virtual-table-cell"),P=(p=b==null?void 0:b.closest)==null?void 0:p.call(b,".virtual-table-row");if(!E||!P)return;const D=P.getAttribute("data-id"),I=E.getAttribute("data-prop"),B=ye(D),j=Me.value.find(de=>`${de.prop}`==`${I}`)||{},K=((h=b==null?void 0:b.closest)==null?void 0:h.call(b,"[field]"))||null,z=((g=K==null?void 0:K.getAttribute)==null?void 0:g.call(K,"field"))||void 0;l==="focusin"?(O={row:B,column:j,cellEl:E,rowEl:P,fieldEl:K,field:z},ie({row:B,column:j},r,K||((w=b==null?void 0:b.closest)==null?void 0:w.call(b,"[field]")))):pe({row:B,column:j},r,K||((x=b==null?void 0:b.closest)==null?void 0:x.call(b,"[field]")))}catch{}},we=()=>{var l;((l=n.editConfig)==null?void 0:l.trigger)==="contenteditable"&&(U&&clearTimeout(U),U=setTimeout(()=>{var r,d,p,h,g,w,x,k,b,E,P,D,I,B;try{const j=document.getSelection();if(j.rangeCount===0)return;const K=j.getRangeAt(0);let z=K.startContainer;z.nodeType===3&&(z=z.parentElement);const de=(r=z==null?void 0:z.closest)==null?void 0:r.call(z,".virtual-table-cell"),ke=(d=z==null?void 0:z.closest)==null?void 0:d.call(z,".virtual-table-row");if(!de||!ke)return;const xe=ke.getAttribute("data-id"),Se=de.getAttribute("data-prop"),fe=ye(xe),ee=Me.value.find(G=>`${G.prop}`==`${Se}`)||{};if(!O||((p=O.row)==null?void 0:p[n.rowConfig.keyField])!==(fe==null?void 0:fe[n.rowConfig.keyField])||((h=O.column)==null?void 0:h.prop)!==(ee==null?void 0:ee.prop)){if(O){let G=O.fieldEl;!G&&O.field&&(G=(w=(g=O.cellEl)==null?void 0:g.querySelector)==null?void 0:w.call(g,`[field="${O.field}"]`)),G||(G=((k=(x=O.cellEl)==null?void 0:x.querySelector)==null?void 0:k.call(x,"[field]"))||O.cellEl),pe(O,{target:G},G)}O={row:fe,column:ee,cellEl:de,rowEl:ke,fieldEl:((b=z==null?void 0:z.closest)==null?void 0:b.call(z,"[field]"))||null,field:((D=(P=((E=z==null?void 0:z.closest)==null?void 0:E.call(z,"[field]"))||null)==null?void 0:P.getAttribute)==null?void 0:D.call(P,"field"))||void 0},ie({row:fe,column:ee},{target:de},de)}if(j.toString()){const G=K.endContainer.nodeType===3?K.endContainer.parentElement:K.endContainer,je=(I=G==null?void 0:G.closest)==null?void 0:I.call(G,".virtual-table-cell"),Ke=(B=G==null?void 0:G.closest)==null?void 0:B.call(G,".virtual-table-row")}}catch{}},50))},Re=()=>{var l;((l=n.editConfig)==null?void 0:l.trigger)==="contenteditable"&&setTimeout(()=>{var p,h,g,w;const r=document.getSelection();if(!r)return;const d=r.toString();if(d){const x=r.rangeCount>0?r.getRangeAt(0):null;let k=null,b=null;try{if(x){let E=x.startContainer;(E==null?void 0:E.nodeType)===3&&(E=E.parentElement);const P=(p=E==null?void 0:E.closest)==null?void 0:p.call(E,".virtual-table-cell"),D=(h=E==null?void 0:E.closest)==null?void 0:h.call(E,".virtual-table-row");k=P&&D?{rowId:D.getAttribute("data-id"),prop:P.getAttribute("data-prop")}:null;let I=x.endContainer;(I==null?void 0:I.nodeType)===3&&(I=I.parentElement);const B=(g=I==null?void 0:I.closest)==null?void 0:g.call(I,".virtual-table-cell"),j=(w=I==null?void 0:I.closest)==null?void 0:w.call(I,".virtual-table-row");b=B&&j?{rowId:j.getAttribute("data-id"),prop:B.getAttribute("data-prop")}:null}}catch{}t("selection-change",{text:d,selection:r,range:x,start:k,end:b})}},10)},Vn=l=>(l==null?void 0:l._editing)===!0,vn=l=>l!=null&&l.parent_id?F.get(l.parent_id):null,jn=l=>{var d;const r=f.value.findIndex(p=>p[n.rowConfig.keyField]==l[n.rowConfig.keyField]);return r<1?null:((d=f.value[r-1])==null?void 0:d.layer)===l.layer?f.value[r-1]:null},Kn=l=>{const r=f.value.findIndex(d=>d[n.rowConfig.keyField]==l[n.rowConfig.keyField]);return r>=f.value.length-1?null:f.value[r+1]},ye=l=>{if(!l)return null;let r=T.get(l);return r||(typeof l=="number"?T.get(`${l}`):typeof l=="string"&&/^\d+$/.test(l)?T.get(Number(l)):null)};let He=null;const qn=l=>{He&&cancelAnimationFrame(He),He=requestAnimationFrame(()=>{var p;const r=n.rowConfig.keyField,d=l[r];if(n.pageConfig.enabled){let h=-1;for(let g=0;g<R.value.length;g++)if(R.value[g].items.some(k=>k[r]===d)){h=g;break}if(h!==-1){for(let g=Math.max(0,h-1);g<=Math.min(R.value.length-1,h+1);g++)v.value.has(g)||v.value.add(g);e.nextTick(()=>{const g=document.querySelector(".a4-pages-container");if(!g)return;const w=(x=0)=>{const k=g.querySelector(`[data-id="${d}"]`);if(k){let b=0,E=k;for(;E&&E!==g;)b+=E.offsetTop,E=E.offsetParent;const P=g.clientHeight;let D=b-P*.3;D=Math.max(0,D);const I=g.scrollTop,B=Math.abs(D-I),j=K=>{const z=g.scrollTop,de=K-z,ke=Math.min(800,Math.max(300,B*.5)),xe=performance.now(),Se=ee=>ee<.5?4*ee*ee*ee:1-Math.pow(-2*ee+2,3)/2,fe=ee=>{const Le=ee-xe,G=Math.min(Le/ke,1),je=Se(G),Ke=z+de*je;g.scrollTop=Ke,G<1?requestAnimationFrame(fe):setTimeout(()=>{g.scrollTop=K},50)};requestAnimationFrame(fe)};B>3e3?g.scrollTo({top:D,behavior:"instant"}):j(D),k.classList.add("row--highlight"),setTimeout(()=>{k.classList.remove("row--highlight")},1500)}else x<10&&setTimeout(()=>w(x+1),150)};setTimeout(w,200)})}}else{const h=f.value.findIndex(g=>g[r]===d);h!==-1&&((p=c.value)!=null&&p.scrollToItem)&&c.value.scrollToItem(h)}He=null})},Oe=l=>{if(l){if(!y.value){setTimeout(()=>Oe(l),200);return}m.value=l,m.value!==s.value&&s.value&&(s.value._editing=!1,setTimeout(()=>{s.value=null},200))}},Pe=(l,r)=>new Promise(d=>{var p,h;if(!((p=n==null?void 0:n.editConfig)!=null&&p.beforeEditMethod&&typeof((h=n==null?void 0:n.editConfig)==null?void 0:h.beforeEditMethod)=="function"&&!n.editConfig.beforeEditMethod({row:l}))){if(!l||!y.value){setTimeout(()=>Pe(l),200);return}l!==s.value&&(f.value.forEach(g=>{g._editing&&t("edit-closed",{row:g,column:{field:r},$table:i==null?void 0:i.exposed}),g._editing=!1}),l._editing=!0,setTimeout(()=>{s.value=l,t("edit-activated",{row:l,column:{field:r},$table:i==null?void 0:i.exposed}),d(!0)}))}}),Un=l=>Pe(l),Ze=()=>{if(ue(),n.pageConfig.enabled){const l=Array.from(_.value);if(l.length>0){const r=Math.min(...l);for(let d=Math.max(0,r-1);d<=Math.min(R.value.length-1,r+2);d++)v.value.add(d)}else for(let r=0;r<Math.min(3,R.value.length);r++)v.value.add(r);e.nextTick(()=>{ne()})}e.nextTick(()=>{!n.pageConfig.enabled&&c.value&&c.value.$forceUpdate&&c.value.$forceUpdate()})},Wn=(l,r)=>new Promise(d=>{let p=-1;if(r==-1){const h=ye(l.parent_id);for(p=f.value.findIndex(g=>g[n.rowConfig.keyField]==h[n.rowConfig.keyField])+1;f.value[p].parent_id==h[n.rowConfig.keyField];)p+=1}else p=f.value.findIndex(h=>h[n.rowConfig.keyField]==r[n.rowConfig.keyField]);F.set(l.node_id,l),T.set(l[n.rowConfig.keyField],l),f.value.splice(p,0,l),Ze(),d({row:l})}),Gn=(l,r)=>new Promise(d=>{const p=f.value.findIndex(h=>h[n.rowConfig.keyField]==r[n.rowConfig.keyField])+1;F.set(l.node_id,l),T.set(l[n.rowConfig.keyField],l),f.value.splice(p,0,l),Ze(),d({row:l})}),gt=l=>{const r=f.value.findIndex(d=>d[n.rowConfig.keyField]==l[n.rowConfig.keyField]||d===l);if(r>-1){const d=l[n.rowConfig.keyField];F.delete(l.node_id),T.delete(d),f.value.splice(r,1),Ze()}},Jn=(l,r)=>{if(!l||!l[n.rowConfig.keyField])return!1;const d=l._original;return d?r?l[r]!==d[r]:Object.keys(d).some(p=>d[p]!==l[p]):!1},Xn=l=>l&&l[n.rowConfig.keyField]&&!l._original,Yn=(l,r)=>{l&&l[n.rowConfig.keyField]&&(r&&Object.assign(l,r),l._original={...l,_editing:void 0,_X_ROW_CHILD:void 0,_original:void 0})},Zn=l=>{if(l&&l[n.rowConfig.keyField]){const r=ye(l[n.rowConfig.keyField]);r._original?Object.assign(r,r._original):gt(r)}},Qn=()=>{},eo=()=>{m.value={}},pt=l=>{var d,p,h;let r=f.value.findIndex(g=>g[n.rowConfig.keyField]==l[n.rowConfig.keyField]);if(r>-1&&n.treeConfig){const g=((d=n.treeConfig)==null?void 0:d.keyField)||((p=n.treeConfig)==null?void 0:p.rowField)||"node_id",w=((h=n.treeConfig)==null?void 0:h.parentField)||"parent_id",x=[],k=new Map;k.set(l[g],!0);for(let b=r+1;b<f.value.length;b++){const E=f.value[b];if(E&&k.has(E[w]))x.push(E),k.set(E[g]);else break}return x}return[]};a({isEditByRow:Vn,getParentRow:vn,getSiblingRow:jn,getNextRow:Kn,getRowById:ye,scrollToRow:qn,setCurrentRow:Oe,setEditRow:Pe,setEditCell:Un,insertAt:Wn,insertNextAt:Gn,isUpdateByRow:Jn,isInsertByRow:Xn,reloadRow:Yn,revertData:Zn,remove:gt,setAllTreeExpand:Qn,clearCurrentRow:eo,getAllChilds:pt});const Me=e.computed(()=>o.default().filter(l=>{var r;return((r=l.type)==null?void 0:r.name)==="VirtualTableColumn"}).map(l=>{var r,d,p;return{prop:(r=l.props)==null?void 0:r.prop,title:(d=l.props)==null?void 0:d.title,width:(p=l.props)==null?void 0:p.width,slots:l.children}})),Ne=l=>{try{return l===0?{width:"0px"}:l?{flex:/^\d+$/.test(l)?`0 0 ${l}px`:`0 0 ${l}`}:{flex:"1 1 100%"}}catch(r){return console.warn("[VirtualTable] computeColumnWidth error:",r),{flex:"1 1 100%"}}},mt=e.computed(()=>{var l;return(l=n.treeConfig)!=null&&l.childCurrent&&m.value?pt(m.value).map(r=>r[n.rowConfig.keyField]):[]}),yt=e.ref({viewStartIndex:0,viewEndIndex:0,visibleStartIndex:0,visibleEndIndex:0});let Ve=null,ve=null;const to=(l,r)=>{Ve&&cancelAnimationFrame(Ve),Ve=requestAnimationFrame(()=>{t("scroll-end",{...yt.value}),Ve=null})},no=(l,r,d,p)=>{ve&&cancelAnimationFrame(ve),ve=requestAnimationFrame(()=>{yt.value={viewStartIndex:l,viewEndIndex:r,visibleStartIndex:d,visibleEndIndex:p},ve=null})},oo=(l,r)=>{var D,I;const{pageHeight:d,margin:p,showPageBorder:h,pageBorderPadding:g,pageBorderStyle:w,showPageHeader:x,headerHeight:k=0,footerHeight:b=0,showPageNumber:E}=n.pageConfig,P=l.pageNumber||r+1;return v.value.has(r)?e.createVNode(e.Fragment,null,[x!==!1&&(o["page-header"]||k>0)?e.createVNode("div",{class:"a4-page-header",style:{minHeight:`${Math.max(k,1)}px`}},[(D=o["page-header"])==null?void 0:D.call(o,{pageNumber:P,pageIndex:r,totalPages:R.value.length})]):null,r===0&&n.showHeader?e.createVNode("div",{class:"a4-table-header"},[e.createVNode("div",{class:"virtual-table-header we-vt-table--header we-vt-table--header-wrapper"},[Me.value.map(B=>{var j,K,z;return e.createVNode("div",{class:"we-vt-header--column",key:B.prop,style:Ne(B.width)},[e.createVNode("div",{class:"we-vt-cell"},[(j=B.slots)!=null&&j.header?(z=(K=B.slots)==null?void 0:K.header)==null?void 0:z.call(K,{column:B}):B.title])])})])]):null,e.createVNode("div",{class:"a4-page-content",style:{...h?{border:w,padding:`${g}px`}:{}}},[l.items.map(B=>{var j,K;return e.createVNode("div",{key:B[n.rowConfig.keyField],"data-id":B[n.rowConfig.keyField],class:{"virtual-table-row":!0,"we-vt-body--row":!0,"row--current":B[n.rowConfig.keyField]===((j=m.value)==null?void 0:j[n.rowConfig.keyField])||((K=n.treeConfig)==null?void 0:K.childCurrent)&&mt.value.includes(B[n.rowConfig.keyField])},style:{width:"100%"},onClick:()=>ge(B),onDblclick:()=>ae(B)},[Me.value.map(z=>{var de,ke,xe,Se,fe,ee,Le;return e.createVNode("div",{key:z.prop,class:"virtual-table-cell we-vt-cell",style:Ne(z.width),"data-prop":z.prop},[B._editing&&((de=n.editConfig)==null?void 0:de.trigger)==="dblclick"?((ke=z.slots)==null?void 0:ke.edit)&&((Se=(xe=z.slots)==null?void 0:xe.edit)==null?void 0:Se.call(xe,{row:B,column:z})):((fe=z.slots)==null?void 0:fe.default)&&((Le=(ee=z.slots)==null?void 0:ee.default)==null?void 0:Le.call(ee,{row:B,column:z}))])})])})]),o["page-footer"]?e.createVNode("div",{class:"a4-page-footer"},[(I=o["page-footer"])==null?void 0:I.call(o,{pageNumber:P,pageIndex:r,totalPages:R.value.length})]):e.createVNode("div",{class:"a4-page-footer",contenteditable:"false"},[E!==!1?e.createVNode("span",{class:"page-number",contenteditable:"false"},[P,e.createTextVNode(" / "),R.value.length]):null])]):e.createVNode("div",{class:"a4-page-loading"},[e.createVNode("div",{class:"loading-spinner"},null),e.createVNode("div",{class:"loading-text"},[e.createTextVNode("加载中...")])])},lo=()=>{var w;const{pageHeight:l,pageWidth:r,margin:d,gap:p,showPageBorder:h,pageBorderPadding:g}=n.pageConfig;return e.createVNode("div",{class:"virtual-table we-vt-table we-vt-table--render-default border--none"},[e.createVNode("div",{class:"a4-pages-container",contenteditable:((w=n.editConfig)==null?void 0:w.trigger)==="contenteditable"?"true":void 0,onContextmenu:V,onFocusin:W,onFocusout:Q},[R.value.map((x,k)=>{const b=v.value.has(k);return e.createVNode("div",{key:`page-${k}`,class:b?"a4-page":"a4-page-placeholder","data-page-index":k,style:{width:`${r}px`,minHeight:`${l}px`,marginBottom:`${p}px`,padding:b?`${h?d-g:d}px`:"0",paddingBottom:b?"12px":"0",boxSizing:"border-box",position:"relative"}},[oo(x,k)])})])])},ao=()=>{var l;return e.createVNode("div",{class:"virtual-table we-vt-table we-vt-table--render-default border--none"},[n.showHeader?e.createVNode("div",{class:"virtual-table-header we-vt-table--header we-vt-table--header-wrapper"},[Me.value.map(r=>{var d,p,h;return e.createVNode("div",{class:"we-vt-header--column",key:r.prop,style:Ne(r.width)},[e.createVNode("div",{class:"we-vt-cell"},[(d=r.slots)!=null&&d.header?(h=(p=r.slots)==null?void 0:p.header)==null?void 0:h.call(p,{column:r}):r.title]),e.createVNode("div",{class:"we-vt-resizable is--line"},null)])})]):void 0,e.createVNode(Ee.DynamicScroller,{ref:c,items:S.value,minItemSize:q.value,keyField:n.rowConfig.keyField,emitUpdate:!1,buffer:300,class:"virtual-table-wrapper",contenteditable:((l=n.editConfig)==null?void 0:l.trigger)==="contenteditable"?"true":void 0,onContextmenu:V,onScrollend:to,onUpdate:no,onFocusin:W,onFocusout:Q},{default:({item:r,index:d,active:p})=>{var g,w,x;let h;return e.createVNode(Ee.DynamicScrollerItem,{key:r[n.rowConfig.keyField],item:r,active:p,sizeDependencies:[(g=r.content)==null?void 0:g.length,r._editing,r.content_type],"data-id":r[n.rowConfig.keyField],"data-index":d,"data-active":p,class:{"virtual-table-row":!0,"we-vt-body--row":!0,"row--current":r[n.rowConfig.keyField]===((w=m.value)==null?void 0:w[n.rowConfig.keyField])||((x=n.treeConfig)==null?void 0:x.childCurrent)&&mt.value.includes(r[n.rowConfig.keyField])}},Pt(h=Me.value.map(k=>{var b,E,P,D,I,B,j;return e.createVNode("div",{key:k.prop,class:"virtual-table-cell we-vt-cell",style:Ne(k.width),"data-prop":k.prop},[r._editing&&((b=n.editConfig)==null?void 0:b.trigger)==="dblclick"?((E=k.slots)==null?void 0:E.edit)&&((D=(P=k.slots)==null?void 0:P.edit)==null?void 0:D.call(P,{row:r,column:k})):((I=k.slots)==null?void 0:I.default)&&((j=(B=k.slots)==null?void 0:B.default)==null?void 0:j.call(B,{row:r,column:k}))])}))?h:{default:()=>[h]})}})])};return()=>n.pageConfig.enabled?lo():ao()}}),Ce=(n,t)=>{const o=n.__vccOpts||n;for(const[a,i]of t)o[a]=i;return o},$t=Ce(Lt,[["__scopeId","data-v-bd96f5fb"]]),zt={name:"VirtualTableColumn",props:{prop:String,label:String,width:[String,Number]}};function Dt(n,t,o,a,i,c){return e.renderSlot(n.$slots,"default")}const Rt=Ce(zt,[["render",Dt]]),Ht={class:"catalog-node"},Ot=["title"],Nt={class:"catalog-node__text"},Vt={key:0,class:"catalog-node__children"},vt=Ce({__name:"CatalogNode",props:{item:{type:Object,required:!0},depth:{type:Number,default:0},activeId:{type:String,default:""}},emits:["navigate"],setup(n,{emit:t}){const o=n,a=t,i=e.ref(!0),c=e.computed(()=>o.item.children&&o.item.children.length>0);function y(s){s.stopPropagation(),i.value=!i.value}return(s,m)=>{const f=e.resolveComponent("CatalogNode",!0);return e.openBlock(),e.createElementBlock("div",Ht,[e.createElementVNode("div",{class:e.normalizeClass(["catalog-node__label",{"is-active":n.activeId===n.item.nodeId}]),style:e.normalizeStyle({paddingLeft:10+n.depth*14+"px"}),title:n.item.name,onClick:m[0]||(m[0]=F=>a("navigate",n.item))},[e.createElementVNode("span",{class:"catalog-node__toggle",onClick:y},[c.value?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(i.value?e.unref(M.ChevronDown):e.unref(M.ChevronRight)),{key:0,size:14})):e.createCommentVNode("",!0)]),e.createElementVNode("span",Nt,e.toDisplayString(n.item.name||"(无标题)"),1)],14,Ot),c.value&&i.value?(e.openBlock(),e.createElementBlock("div",Vt,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.item.children,F=>(e.openBlock(),e.createBlock(f,{key:F.nodeId,item:F,depth:n.depth+1,"active-id":n.activeId,onNavigate:m[1]||(m[1]=T=>a("navigate",T))},null,8,["item","depth","active-id"]))),128))])):e.createCommentVNode("",!0)])}}},[["__scopeId","data-v-ac882917"]]),jt={key:0,class:"catalog catalog--collapsed"},Kt={key:1,class:"catalog"},qt={class:"catalog__header"},Ut={class:"catalog__title"},Wt={class:"catalog__body"},Gt={key:0,class:"catalog__empty"},Jt=Ce({__name:"index",props:{items:{type:Array,default:()=>[]}},emits:["navigate"],setup(n,{emit:t}){const o=t,a=e.ref(!1),i=e.ref("");function c(y){i.value=y.nodeId,o("navigate",y)}return(y,s)=>a.value?(e.openBlock(),e.createElementBlock("div",jt,[e.createElementVNode("button",{class:"catalog__icon-btn",title:"展开目录",onClick:s[0]||(s[0]=m=>a.value=!1)},[e.createVNode(e.unref(M.PanelLeftOpen),{size:18})])])):(e.openBlock(),e.createElementBlock("div",Kt,[e.createElementVNode("div",qt,[e.createElementVNode("span",Ut,[e.createVNode(e.unref(M.ListTree),{size:16}),s[2]||(s[2]=e.createTextVNode(" 目录 ",-1))]),e.createElementVNode("button",{class:"catalog__icon-btn",title:"收起目录",onClick:s[1]||(s[1]=m=>a.value=!0)},[e.createVNode(e.unref(M.PanelLeftClose),{size:18})])]),e.createElementVNode("div",Wt,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.items,m=>(e.openBlock(),e.createBlock(vt,{key:m.nodeId,item:m,"active-id":i.value,onNavigate:c},null,8,["item","active-id"]))),128)),n.items.length?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",Gt," 暂无目录 "))])]))}},[["__scopeId","data-v-8becafa1"]]),Xt={first:1,second:2,third:3,fourth:4,fifth:5,sixth:6};function Yt(n){return n.blockType!=="title"||!n.level?0:Xt[n.level]||1}function Zt(n){const t=[];for(const i of n||[]){const c=Yt(i);c&&t.push({id:i.node_id,nodeId:i.node_id,name:(i.content||"").trim(),level:c,children:[]})}if(!t.length)return[];const o=(i,c)=>{const y=c.children[c.children.length-1];y&&i.level>y.level?o(i,y):c.children.push(i)},a=[];for(const i of t){const c=a[a.length-1];c&&i.level>c.level?o(i,c):a.push(i)}return a}const Qt={first:0,second:1,third:2,fourth:3,fifth:4,sixth:5,seventh:6,eighth:7};function $e(n,t){let o="",a=n;const i=t?65:97;for(;a>0;){const c=(a-1)%26;o=String.fromCharCode(i+c)+o,a=Math.floor((a-1)/26)}return o}const nt=[n=>n.toString(),n=>$e(n,!0),n=>`(${n})`,n=>`(${$e(n,!1)})`,n=>`${n})`,n=>`${$e(n,!1)})`,n=>`<${n}>`,n=>`<${$e(n,!1)}>`];function en(){const n=new Array(8).fill(0);return{next(t,o){const a=Qt[t];if(a==null)return"";n[a]++;for(let c=a+1;c<n.length;c++)n[c]=0;if(o!=null&&o!=="")return`${o} `;const i=nt[Math.min(a,nt.length-1)];return`${i(n[a])}. `}}}const Fe=14,ot=760,lt=756,tn={left:"left",center:"center",right:"right",alignment:"justify",justify:"justify"};function at(n){const t=[];let o=!1;const a=i=>{if(o){if(i&&i.value!=null&&/^[\n200B]+$/.test(i.value)){t.push(i);return}o=!1,t.push({...i,_coverBreakBefore:!0})}else t.push(i)};for(const i of n||[]){if(i&&i.type==="pageBreak"){o=!0;continue}if(i&&i.type==="area"){const c=at(i.valueList||[]),y=(i.areaId||"").includes("cover");for(const s of c)a(s);y&&(o=!0)}else a(i)}return t}function Ie(n){const t=at(n),o=[];let a=[],i=0,c=null;const y=m=>{a.length&&(o.push({type:"paragraph",elements:[...a],rowFlex:m}),a=[])},s=()=>{if(i===0)return;const m=c;y(m);for(let f=1;f<i;f++)o.push({type:"paragraph",elements:[],rowFlex:m});i=0,c=null};for(const m of t||[])if(m.type==="table")s(),y(),o.push({type:"table",el:m});else if(m.type==="title")s(),y(),o.push({type:"title",el:m});else if(m.type==="list"){s(),y();const f=[];let F=[];for(const T of m.valueList||[])T.value===`
2
- `||T.value==="​"?(f.push([...F]),F=[]):F.push(T);(F.length||f.length===0)&&f.push([...F]),o.push({type:"list",listType:m.listType||"ul",listStyle:m.listStyle||"disc",items:f})}else if(m.listId){s(),y();const f=m.value==="​"||m.value===""?[]:[m];o.push({type:"list",listType:m.listType||"ul",listStyle:m.listStyle||"disc",items:[f]})}else m.value!=null&&/^[\n200B]+$/.test(m.value)?(i+=m.value.length,m.rowFlex&&(c=m.rowFlex)):(s(),a.push(m));return s(),y(),o}function Be(n){const t=n.filter(f=>f.type==="image").reduce((f,F)=>f+(F.height||F.width||0),0),o=n.filter(f=>f.type!=="image").map(f=>f.value||"").join("");if(!o)return t||20;const a=n.reduce((f,F)=>Math.max(f,F.size||0),0)||14,i=a+6,c=(o.match(/[一-龥]/g)||[]).length,y=o.length-c,s=c*a+y*(a*.5),m=Math.max(1,Math.ceil(s/ot));return t+Math.max(i,m*i)}function nn(n){if(!n||!n.length)return[[]];const t=[];let o=[];for(const a of n)a.type==="image"&&(a.width||0)>=ot?(o.length&&(t.push(o),o=[]),t.push([a])):o.push(a);return o.length&&t.push(o),t.length?t:[[]]}function it(n){if(n.length===0)return[];const t=new Array(n.length).fill(0);n.forEach((c,y)=>{(c.tdList||[]).forEach(s=>{const m=s.rowspan||1;if(m>1){const f=Math.min(y+m-1,n.length-1);t[y]=Math.max(t[y],f);for(let F=1;F<m&&y+F<n.length;F++)t[y+F]=Math.max(t[y+F],f)}})});const o=[];let a=0,i=0;for(let c=0;c<n.length;c++)i=Math.max(i,t[c]),i<=c&&(o.push(n.slice(a,c+1)),a=c+1,i=0);return a<n.length&&o.push(n.slice(a)),o}function qe(n){const t=(n==null?void 0:n.width)||0;return!t||t<=lt?1:lt/t}function rt(n){var c,y;const t=n.elements||[],o=((c=t.find(s=>s.rowFlex))==null?void 0:c.rowFlex)||n.rowFlex,a={textAlign:tn[o]||"left"},i=(y=t.find(s=>s.rowMargin))==null?void 0:y.rowMargin;return i&&(a.lineHeight=i),a}function on(n){var c;const t=Ie(n.value);let o=0,a=0,i=!1;for(const y of t)if(y.type==="paragraph"){if(!y.elements.length)continue;o++;for(const s of y.elements)(s.type==="image"||s.type==="table")&&(i=!0),a+=(s.value||"").length}else y.type==="list"?(o+=((c=y.items)==null?void 0:c.length)||1,i=!0):(o++,i=!0);return o>1||a>30||i?"top":n.verticalAlign||"middle"}function re(n){const t={};n.font&&(t.fontFamily=n.font),t.fontSize=(n.size||Fe)+"px",n.bold!=null&&(t.fontWeight=n.bold?"bold":"normal"),n.italic!=null&&(t.fontStyle=n.italic?"italic":"normal"),n.color&&(t.color=n.color),n.highlight&&n.highlight!=="rgb(255, 255, 255)"&&n.highlight!=="#ffffff"&&(t.backgroundColor=n.highlight);const o=[n.underline&&"underline",n.strikeout&&"line-through"].filter(Boolean).join(" ");return o&&(t.textDecoration=o),n.letterSpacing&&(t.letterSpacing=n.letterSpacing+"px"),t}const ln=5;function st(n,t=!1){var a,i;let o=0;for(const c of n)if(c.type==="table"){const y=((a=c.el)==null?void 0:a.trList)||[];o+=y.reduce((s,m)=>s+(m.height||m.minHeight||35),0)}else if(c.type==="title")o+=Be(c.titleValueList||((i=c.el)==null?void 0:i.valueList)||[]);else if(c.type==="paragraph")o+=Be(c.elements||[]);else if(c.type==="list"){const y=Math.round(18),s=(c.items||[]).reduce((m,f)=>m+(f.length?Be(f):y),0);o+=Math.max(s,y)}return o+(t&&o>0?ln:0)}const an={key:0,class:"empty-line"},rn=["href"],sn=["src"],cn=["checked"],dn=["checked"],hn={key:4,class:"ctrl-input"},fn=["checked"],un=["checked"],gn={key:0},pn=["colspan","rowspan"],mn={key:0},yn=["src"],kn=["href"],bn=["checked"],_n=["checked"],wn=["checked"],Ue=Ce({__name:"DocBlock",props:{block:{type:Object,required:!0},isHeaderFooter:{type:Boolean,default:!1}},setup(n){const t=n,o=e.inject("bindTableObserver",null),a=e.computed(()=>t.isHeaderFooter?0:t.block.indentPx??0);return(i,c)=>{var y;return n.block.blockType==="title"?(e.openBlock(),e.createElementBlock("p",{key:0,class:e.normalizeClass(["doc-title",`doc-title--${n.block.level}`]),style:e.normalizeStyle({paddingLeft:a.value?a.value+"px":void 0})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.block.titleValueList||[],(s,m)=>(e.openBlock(),e.createElementBlock("span",{key:m,style:e.normalizeStyle(e.unref(re)(s))},e.toDisplayString(s.value),5))),128))],6)):n.block.blockType==="paragraph"?(e.openBlock(),e.createElementBlock("p",{key:1,class:"doc-para",style:e.normalizeStyle({...e.unref(rt)(n.block),paddingLeft:a.value?a.value+"px":void 0})},[n.block.elements.length?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("span",an," ")),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.block.elements,(s,m)=>{var f,F,T,R,_,v,X,H,A,u,C,L,S;return e.openBlock(),e.createElementBlock(e.Fragment,{key:m},[!s.type||s.type==="text"?(e.openBlock(),e.createElementBlock("span",{key:0,style:e.normalizeStyle(e.unref(re)(s))},e.toDisplayString(s.value),5)):s.type==="hyperlink"?(e.openBlock(),e.createElementBlock("a",{key:1,href:s.url,class:"doc-link",target:"_blank",rel:"noopener"},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s.valueList||[],($,q)=>(e.openBlock(),e.createElementBlock("span",{key:q,style:e.normalizeStyle(e.unref(re)($))},e.toDisplayString($.value),5))),128))],8,rn)):s.type==="image"?(e.openBlock(),e.createElementBlock("img",{key:2,src:s.value,class:"doc-image",style:e.normalizeStyle({width:s.width?s.width+"px":"auto",height:s.height?s.height+"px":"auto"})},null,12,sn)):s.type==="control"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:3},[((f=s.control)==null?void 0:f.type)==="text"?(e.openBlock(),e.createElementBlock("span",{key:0,style:e.normalizeStyle({fontSize:(s.control.size||12)+"px"})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s.control.value||[],($,q)=>(e.openBlock(),e.createElementBlock("span",{key:q,style:e.normalizeStyle(e.unref(re)($))},e.toDisplayString($.value),5))),128))],4)):((F=s.control)==null?void 0:F.type)==="input"?(e.openBlock(),e.createElementBlock("span",{key:1,class:"ctrl-input",style:e.normalizeStyle({minWidth:(s.control.minWidth||60)+"px",fontSize:(s.control.size||12)+"px"})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s.control.value||[],($,q)=>(e.openBlock(),e.createElementBlock("span",{key:q},e.toDisplayString($.value),1))),128))],4)):((T=s.control)==null?void 0:T.type)==="radio"?(e.openBlock(),e.createElementBlock("span",{key:2,class:e.normalizeClass(["ctrl-options",{"ctrl-options--vertical":((_=(R=s.control.extension)==null?void 0:R.elementAttributes)==null?void 0:_.layout)==="vertical"}]),style:e.normalizeStyle({fontSize:(s.control.size||e.unref(Fe))+"px"})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s.control.valueSets||[],($,q)=>(e.openBlock(),e.createElementBlock("label",{key:q,class:"ctrl-option"},[e.createElementVNode("input",{type:"radio",disabled:"",checked:s.control.code===$.code},null,8,cn),e.createTextVNode(" "+e.toDisplayString($.value),1)]))),128))],6)):((v=s.control)==null?void 0:v.type)==="checkbox"?(e.openBlock(),e.createElementBlock("span",{key:3,class:e.normalizeClass(["ctrl-options",{"ctrl-options--vertical":((H=(X=s.control.extension)==null?void 0:X.elementAttributes)==null?void 0:H.layout)==="vertical"}]),style:e.normalizeStyle({fontSize:(s.control.size||e.unref(Fe))+"px"})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s.control.valueSets||[],($,q)=>(e.openBlock(),e.createElementBlock("label",{key:q,class:"ctrl-option"},[e.createElementVNode("input",{type:"checkbox",disabled:"",checked:(s.control.code||"").split(",").includes($.code)},null,8,dn),e.createTextVNode(" "+e.toDisplayString($.value),1)]))),128))],6)):((A=s.control)==null?void 0:A.type)==="select"?(e.openBlock(),e.createElementBlock("span",hn,e.toDisplayString(((C=(u=s.control.value)==null?void 0:u[0])==null?void 0:C.value)||s.control.placeholder||""),1)):e.createCommentVNode("",!0)],64)):s.type==="checkbox"?(e.openBlock(),e.createElementBlock("input",{key:4,type:"checkbox",checked:!!((L=s.checkbox)!=null&&L.value),disabled:"",class:"el-check"},null,8,fn)):s.type==="radio"?(e.openBlock(),e.createElementBlock("input",{key:5,type:"radio",checked:!!((S=s.radio)!=null&&S.value),disabled:"",class:"el-check"},null,8,un)):s.type==="superscript"?(e.openBlock(),e.createElementBlock("sup",{key:6,style:e.normalizeStyle(e.unref(re)(s))},e.toDisplayString(s.value),5)):s.type==="subscript"?(e.openBlock(),e.createElementBlock("sub",{key:7,style:e.normalizeStyle(e.unref(re)(s))},e.toDisplayString(s.value),5)):s.type==="tab"?(e.openBlock(),e.createElementBlock("span",{key:8,class:"doc-tab",style:e.normalizeStyle({width:(s.size||e.unref(Fe))+"px"})},null,4)):e.createCommentVNode("",!0)],64)}),128))],4)):n.block.blockType==="list"?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(n.block.listType==="ol"?"ol":"ul"),{key:2,class:"doc-list",style:e.normalizeStyle({listStyleType:n.block.listStyle==="decimal"?"decimal":n.block.listStyle==="lower-alpha"?"lower-alpha":"disc",paddingLeft:a.value?a.value+24+"px":void 0})},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.block.items,(s,m)=>(e.openBlock(),e.createElementBlock("li",{key:m,class:"doc-list-item"},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s,(f,F)=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:F},[!f.type||f.type==="text"?(e.openBlock(),e.createElementBlock("span",{key:0,style:e.normalizeStyle(e.unref(re)(f))},e.toDisplayString(f.value),5)):f.type==="superscript"?(e.openBlock(),e.createElementBlock("sup",{key:1,style:e.normalizeStyle(e.unref(re)(f))},e.toDisplayString(f.value),5)):f.type==="subscript"?(e.openBlock(),e.createElementBlock("sub",{key:2,style:e.normalizeStyle(e.unref(re)(f))},e.toDisplayString(f.value),5)):e.createCommentVNode("",!0)],64))),128))]))),128))]),_:1},8,["style"])):n.block.blockType==="table-row-group"?(e.openBlock(),e.createElementBlock("div",{key:3,class:e.normalizeClass(["doc-table-row-wrap",{"is-first":n.block.isFirst,"is-last":n.block.isLast,"is-page-break":n.block.isPageBreak}]),style:e.normalizeStyle({display:n.block.tableRowFlex?"flex":void 0,justifyContent:n.block.tableRowFlex==="right"?"flex-end":n.block.tableRowFlex==="center"?"center":n.block.tableRowFlex==="left"?"flex-start":void 0,paddingLeft:a.value?a.value+"px":void 0})},[e.createElementVNode("div",{style:e.normalizeStyle({overflow:n.block.sliceHeight!=null?"hidden":void 0,height:n.block.sliceHeight!=null?(n.block.isLast?n.block.sliceHeight+1:n.block.sliceHeight)+"px":void 0,width:n.block.tableEl.width?"max-content":"100%"})},[e.createElementVNode("table",{ref:n.block._baseKey&&e.unref(o)?s=>e.unref(o)(s,n.block._baseKey):void 0,class:e.normalizeClass(["doc-table",{"doc-table--no-border":n.block.tableEl.borderType==="empty","doc-table--header-footer":n.isHeaderFooter}]),style:e.normalizeStyle({width:n.block.tableEl.width?(n.isHeaderFooter?n.block.tableEl.width:n.block.tableEl.width*e.unref(qe)(n.block.tableEl))+"px":"100%",transform:n.block.sliceOffset?`translateY(-${n.block.sliceOffset}px)`:void 0})},[(y=n.block.tableEl.colgroup)!=null&&y.length?(e.openBlock(),e.createElementBlock("colgroup",gn,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.block.tableEl.colgroup,(s,m)=>(e.openBlock(),e.createElementBlock("col",{key:m,style:e.normalizeStyle({width:(n.isHeaderFooter?s.width:s.width*e.unref(qe)(n.block.tableEl))+"px"})},null,4))),128))])):e.createCommentVNode("",!0),e.createElementVNode("tbody",null,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.block.trGroup,(s,m)=>(e.openBlock(),e.createElementBlock("tr",{key:m,style:e.normalizeStyle({height:(s.height||s.minHeight||30)+"px"})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s.tdList||[],(f,F)=>(e.openBlock(),e.createElementBlock("td",{key:F,colspan:f.colspan||1,rowspan:f.rowspan||1,style:e.normalizeStyle({backgroundColor:f.backgroundColor||void 0,verticalAlign:e.unref(on)(f),width:f.width?f.width*e.unref(qe)(n.block.tableEl)+"px":void 0,height:f.height?f.height+"px":void 0})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(Ie)(f.value),(T,R)=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:R},[T.type==="paragraph"?(e.openBlock(),e.createElementBlock("p",{key:0,class:"cell-para",style:e.normalizeStyle(e.unref(rt)(T))},[T.elements.length?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("span",mn," ")),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(T.elements,(_,v)=>{var X,H,A,u,C,L,S;return e.openBlock(),e.createElementBlock(e.Fragment,{key:v},[!_.type||_.type==="text"?(e.openBlock(),e.createElementBlock("span",{key:0,style:e.normalizeStyle(e.unref(re)(_))},e.toDisplayString(_.value),5)):_.type==="image"?(e.openBlock(),e.createElementBlock("img",{key:1,src:_.value,class:"doc-image",style:e.normalizeStyle({width:_.width?_.width+"px":"auto",height:_.height?_.height+"px":"auto"})},null,12,yn)):_.type==="hyperlink"?(e.openBlock(),e.createElementBlock("a",{key:2,href:_.url,class:"doc-link",target:"_blank"},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(_.valueList||[],($,q)=>(e.openBlock(),e.createElementBlock("span",{key:q,style:e.normalizeStyle(e.unref(re)($))},e.toDisplayString($.value),5))),128))],8,kn)):_.type==="control"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:3},[((X=_.control)==null?void 0:X.type)==="text"?(e.openBlock(),e.createElementBlock("span",{key:0,style:e.normalizeStyle({fontSize:(_.control.size||12)+"px"})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(_.control.value||[],($,q)=>(e.openBlock(),e.createElementBlock("span",{key:q,style:e.normalizeStyle(e.unref(re)($))},e.toDisplayString($.value),5))),128))],4)):((H=_.control)==null?void 0:H.type)==="input"?(e.openBlock(),e.createElementBlock("span",{key:1,class:"ctrl-input",style:e.normalizeStyle({fontSize:(_.control.size||12)+"px"})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(_.control.value||[],($,q)=>(e.openBlock(),e.createElementBlock("span",{key:q},e.toDisplayString($.value),1))),128))],4)):((A=_.control)==null?void 0:A.type)==="radio"?(e.openBlock(),e.createElementBlock("span",{key:2,class:e.normalizeClass(["ctrl-options",{"ctrl-options--vertical":((C=(u=_.control.extension)==null?void 0:u.elementAttributes)==null?void 0:C.layout)==="vertical"}])},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(_.control.valueSets||[],($,q)=>(e.openBlock(),e.createElementBlock("label",{key:q,class:"ctrl-option"},[e.createElementVNode("input",{type:"radio",disabled:"",checked:_.control.code===$.code},null,8,bn),e.createTextVNode(e.toDisplayString($.value),1)]))),128))],2)):e.createCommentVNode("",!0)],64)):_.type==="checkbox"?(e.openBlock(),e.createElementBlock("input",{key:4,type:"checkbox",checked:!!((L=_.checkbox)!=null&&L.value),disabled:"",class:"el-check"},null,8,_n)):_.type==="radio"?(e.openBlock(),e.createElementBlock("input",{key:5,type:"radio",checked:!!((S=_.radio)!=null&&S.value),disabled:"",class:"el-check"},null,8,wn)):_.type==="superscript"?(e.openBlock(),e.createElementBlock("sup",{key:6,style:e.normalizeStyle(e.unref(re)(_))},e.toDisplayString(_.value),5)):_.type==="subscript"?(e.openBlock(),e.createElementBlock("sub",{key:7,style:e.normalizeStyle(e.unref(re)(_))},e.toDisplayString(_.value),5)):_.type==="tab"?(e.openBlock(),e.createElementBlock("span",{key:8,class:"doc-tab",style:e.normalizeStyle({width:(_.size||e.unref(Fe))+"px"})},null,4)):e.createCommentVNode("",!0)],64)}),128))],4)):e.createCommentVNode("",!0)],64))),128))],12,pn))),128))],4))),128))])],6)],4)],6)):e.createCommentVNode("",!0)}}},[["__scopeId","data-v-3ddfa762"]]),xn={class:"editor-layout word-editor-scope"},En={class:"editor-container"},Cn={key:0,class:"editor-loading"},Bn={class:"doc-header"},Mn={class:"doc-footer"},Sn={class:"doc-page-number"},Fn=1123,In=50,Tn=20,An=Ce({__name:"index",props:{data:{type:Array,default:()=>[]},loading:{type:Boolean,default:!1}},setup(n){const t=n,o=e.computed(()=>{const u=t.data;return u?!Array.isArray(u)&&u.main?u.main:Array.isArray(u)?u:[]:[]}),a=e.ref(null),i=e.ref({});let c=null;e.onMounted(()=>{c=new ResizeObserver(u=>{const C={};for(const L of u){const S=L.target._rowKey;if(!S)continue;const $=Math.round(L.contentRect.height);$>(i.value[S]||0)&&(C[S]=$)}Object.keys(C).length&&(i.value={...i.value,...C})})}),e.onUnmounted(()=>{c==null||c.disconnect(),c=null});function y(u,C){!u||!c||(u._rowKey=C,c.observe(u))}e.provide("bindTableObserver",y);const s=e.computed(()=>Math.max(100,Fn-In*2-T.value-Tn)),m=e.computed(()=>{const u=Ie(o.value),C=[],L=s.value;let S=0;const $=en(),q={first:0,second:1,third:2,fourth:3,fifth:4,sixth:5,seventh:6,eighth:7};let Y=-1;const Xe=V=>{var le,se,ue;return!!((le=V.el)!=null&&le._coverBreakBefore||(ue=(se=V.elements)==null?void 0:se[0])!=null&&ue._coverBreakBefore)};return u.forEach((V,le)=>{var ue,Ae,_e,Ye;const se=Xe(V);if(se&&(S=0),V.type==="title"){const ce=V.el.valueList||[],te=$.next(V.el.level,(ue=V.el.extension)==null?void 0:ue.startIndex),ne=ce.some(Z=>{var oe;return(oe=Z.extension)==null?void 0:oe.isIndex});let he=ce;if(!ne&&te){const Z=ce[0]||{};he=[{value:te,size:Z.size,bold:Z.bold,italic:Z.italic,color:Z.color,font:Z.font,extension:{isIndex:!0}},...ce]}const ge=he.map(Z=>Z.value||"").join(""),ae=Be(he);S=S+ae>L&&S>0?ae:S+ae,Y=q[V.el.level]??0,C.push({node_id:`blk_${le}_0`,layer:se?1:100,blockType:"title",level:V.el.level,titleEl:V.el,titleValueList:he,content_type:"text",content:ge,height:ae,indentPx:Y*20})}else if(V.type==="paragraph"){const ce=nn(V.elements),te=Y>=0?(Y+1)*20:0;ce.forEach((ne,he)=>{const ge=ne.map(Z=>Z.value||"").join(""),ae=Be(ne);S=S+ae>L&&S>0?ae:S+ae,C.push({node_id:`blk_${le}_${he}`,layer:se&&he===0?1:100,blockType:"paragraph",elements:ne,rowFlex:V.rowFlex,content_type:"text",content:ge,height:ae,indentPx:te})})}else if(V.type==="table"){const ce=!!((Ae=V.el.extension)!=null&&Ae.isTitleTable),te=((_e=V.el.extension)==null?void 0:_e.elementType)==="signOff",ne=((Ye=V.el.extension)==null?void 0:Ye.elementType)==="stepTable",he=te||ne,ge=ce||te?0:Y>=0?(Y+1)*20:0,ae=it(V.el.trList||[]),Z=ae.length;if(he){const oe=ae.flat(),ie=oe.reduce((U,W)=>U+(W.height||W.minHeight||35),0),pe=`blk_${le}_0`,O=Math.max(ie,i.value[pe]||0);if(S>0&&S+O>L&&(S=0),O>L){const U=Math.ceil(O/L);for(let W=0;W<U;W++){const Q=W*L,me=Math.min(L,O-Q),we=W>0||S>0;S=me,C.push({node_id:`blk_${le}_0_s${W}`,layer:se&&W===0?1:100,blockType:"table-row-group",content_type:"table-row",rowHeight:O,trGroup:oe,tableEl:V.el,tableRowFlex:V.el.rowFlex||null,isFirst:W===0,isLast:W===U-1,isPageBreak:we,sliceOffset:Q,sliceHeight:me,_baseKey:W===0?pe:void 0,height:me,indentPx:ge})}}else{const U=S>0;S=S+O>L?O:S+O,C.push({node_id:`blk_${le}_0`,layer:se?1:100,blockType:"table-row-group",content_type:"table-row",rowHeight:O,trGroup:oe,tableEl:V.el,tableRowFlex:V.el.rowFlex||null,isFirst:!0,isLast:!0,isPageBreak:U,indentPx:ge})}}else ae.forEach((oe,ie)=>{const pe=`blk_${le}_${ie}`,O=oe.reduce((W,Q)=>W+(Q.height||Q.minHeight||35),0),U=Math.max(O,i.value[pe]||0);if(U>L){const W=Math.ceil(U/L);for(let Q=0;Q<W;Q++){const me=Q*L,we=Math.min(L,U-me),Re=Q>0||S>0;S=we,C.push({node_id:`blk_${le}_${ie}_s${Q}`,layer:se&&ie===0&&Q===0?1:100,blockType:"table-row-group",content_type:"table-row",rowHeight:U,trGroup:oe,tableEl:V.el,tableRowFlex:V.el.rowFlex||null,isFirst:ie===0&&Q===0,isLast:ie===Z-1&&Q===W-1,isPageBreak:Re,sliceOffset:me,sliceHeight:we,_baseKey:Q===0?pe:void 0,height:we,indentPx:ge})}}else{const W=ie>0&&S+U>L;S=S+U>L?U:S+U,C.push({node_id:`blk_${le}_${ie}`,layer:se&&ie===0?1:100,blockType:"table-row-group",content_type:"table-row",rowHeight:U,trGroup:oe,tableEl:V.el,tableRowFlex:V.el.rowFlex||null,isFirst:ie===0,isLast:ie===Z-1,isPageBreak:W,indentPx:ge})}})}else if(V.type==="list"){const ce=Math.round(18);let te=0;for(const ne of V.items)te+=ne.length?Be(ne):ce;te=Math.max(te,ce),S=S+te>L&&S>0?te:S+te,C.push({node_id:`blk_${le}_0`,layer:se?1:100,blockType:"list",listType:V.listType,listStyle:V.listStyle,items:V.items,height:te,indentPx:Y>=0?(Y+1)*20:0})}}),C}),f=e.computed(()=>{var C;const u=(C=t.data)==null?void 0:C.header;return u!=null&&u.length?Ie(u):[]}),F=e.computed(()=>{var C;const u=(C=t.data)==null?void 0:C.footer;return u!=null&&u.length?Ie(u):[]}),T=e.computed(()=>st(f.value,!0)),R=e.computed(()=>st(F.value,!0)),_=e.computed(()=>f.value.length>0),v=e.computed(()=>F.value.length>0);function X(u){var L,S,$;const C=u.type==="table";return{blockType:C?"table-row-group":u.type,elements:u.elements,rowFlex:u.rowFlex,level:(L=u.el)==null?void 0:L.level,titleValueList:((S=u.el)==null?void 0:S.valueList)||u.titleValueList,listType:u.listType,listStyle:u.listStyle,items:u.items,indentPx:0,trGroup:C?it(u.el.trList).flat():void 0,tableEl:C?u.el:void 0,isFirst:!0,isLast:!0,tableRowFlex:(($=u.el)==null?void 0:$.rowFlex)||null}}const H=e.computed(()=>Zt(m.value));function A(u){var C;(C=a.value)==null||C.scrollToRow({node_id:u.nodeId})}return(u,C)=>(e.openBlock(),e.createElementBlock("div",xn,[e.createVNode(Jt,{items:H.value,onNavigate:A},null,8,["items"]),e.createElementVNode("div",En,[n.loading?(e.openBlock(),e.createElementBlock("div",Cn," 加载中… ")):(e.openBlock(),e.createBlock(e.unref($t),{key:1,ref_key:"virtualTableRef",ref:a,"show-header":!1,"row-config":{keyField:"node_id"},"page-config":{enabled:!0,pageHeight:1123,pageWidth:860,margin:50,gap:16,showPageHeader:_.value,showPageBorder:!0,pageBorderPadding:5,pageBorderStyle:"1px solid #333",headerHeight:T.value,footerHeight:R.value,showPageNumber:!0},data:m.value},e.createSlots({default:e.withCtx(()=>[e.createVNode(e.unref(Rt),null,{default:e.withCtx(({row:L})=>[e.createVNode(Ue,{block:L},null,8,["block"])]),_:1})]),_:2},[_.value?{name:"page-header",fn:e.withCtx(()=>[e.createElementVNode("div",Bn,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(f.value,(L,S)=>(e.openBlock(),e.createBlock(Ue,{key:S,block:X(L),"is-header-footer":!0},null,8,["block"]))),128))])]),key:"0"}:void 0,v.value?{name:"page-footer",fn:e.withCtx(({pageNumber:L,totalPages:S})=>[e.createElementVNode("div",Mn,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(F.value,($,q)=>(e.openBlock(),e.createBlock(Ue,{key:q,block:X($),"is-header-footer":!0},null,8,["block"]))),128)),e.createElementVNode("div",Sn,e.toDisplayString(L)+" / "+e.toDisplayString(S),1)])]),key:"1"}:void 0]),1032,["page-config","data"]))])]))}},[["__scopeId","data-v-70681e24"]]),ct="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";function ze(n=10){const t=crypto.getRandomValues(new Uint8Array(n));return Array.from(t).map(o=>ct[o%ct.length]).join("")}class De{constructor(t){N(this,"data");this.data=e.reactive({id:ze(),version:1,sections:[this.createEmptySection()],pageWidth:595,pageHeight:842,marginTop:72,marginBottom:72,marginLeft:90,marginRight:90,...t})}createEmptySection(){return{id:ze(),paragraphs:[this.createEmptyParagraph()]}}createEmptyParagraph(t){return{id:ze(),type:"paragraph",format:t??{},children:[]}}createTextElement(t,o){return{id:ze(),type:"text",value:t,format:o??{}}}getSectionCount(){return this.data.sections.length}getParagraphCount(t=0){var o;return((o=this.data.sections[t])==null?void 0:o.paragraphs.length)??0}getAllParagraphs(){const t=[];return this.data.sections.forEach((o,a)=>{o.paragraphs.forEach((i,c)=>{t.push({paragraph:i,sectionIndex:a,paragraphIndex:c})})}),t}getParagraphAt(t,o){var a;return((a=this.data.sections[t])==null?void 0:a.paragraphs[o])??null}getElementAt(t){const o=this.getParagraphAt(t.sectionIndex,t.paragraphIndex);return(o==null?void 0:o.children[t.elementIndex])??null}insertText(t,o,a){const i=this.getParagraphAt(t.sectionIndex,t.paragraphIndex);if(!i)return;const c=i.children[t.elementIndex];if(c&&c.type==="text")c.value=c.value.slice(0,t.offset)+o+c.value.slice(t.offset);else{const y=this.createTextElement(o,a);i.children.splice(t.elementIndex,0,y)}this.bumpVersion()}deleteAt(t,o){const a=this.getParagraphAt(t.sectionIndex,t.paragraphIndex);if(!a)return;const i=a.children[t.elementIndex];!i||i.type!=="text"||(i.value=i.value.slice(0,t.offset)+i.value.slice(t.offset+o),i.value===""&&a.children.splice(t.elementIndex,1),this.bumpVersion())}insertParagraph(t,o,a){const i=this.data.sections[t];if(!i)throw new Error(`Section ${t} not found`);const c=this.createEmptyParagraph(a);return i.paragraphs.splice(o+1,0,c),this.bumpVersion(),c}mergeParagraphs(t,o){const a=this.data.sections[t];if(!a)return;const i=a.paragraphs[o],c=a.paragraphs[o+1];!i||!c||(i.children.push(...c.children),a.paragraphs.splice(o+1,1),this.bumpVersion())}updateParagraphFormat(t,o,a){const i=this.getParagraphAt(t,o);i&&(i.format={...i.format,...a},this.bumpVersion())}updateElementFormat(t,o){const a=this.getElementAt(t);a&&(a.format={...a.format,...o},this.bumpVersion())}updateRangeFormat(t,o,a){const i=this.getAllParagraphs();let c=!1;for(const{paragraph:y,sectionIndex:s,paragraphIndex:m}of i){const f=s===t.sectionIndex&&m===t.paragraphIndex,F=s===o.sectionIndex&&m===o.paragraphIndex;if(f&&(c=!0),c)for(let T=0;T<y.children.length;T++){const R=y.children[T];if(!(f&&T<t.elementIndex)){if(F&&T>o.elementIndex)break;R.format={...R.format,...a}}}if(F)break}this.bumpVersion()}bumpVersion(){this.data.version++}toJSON(){return JSON.stringify(this.data,null,2)}static fromJSON(t){const o=JSON.parse(t),a=new De;return Object.assign(a.data,o),a}}function be(n=0,t=0,o=0,a=0){return{sectionIndex:n,paragraphIndex:t,elementIndex:o,offset:a}}function dt(n,t){return n.sectionIndex===t.sectionIndex&&n.paragraphIndex===t.paragraphIndex&&n.elementIndex===t.elementIndex&&n.offset===t.offset}class We{constructor(t){N(this,"_selection",e.reactive({anchor:be(),focus:be(),isCollapsed:!0}));N(this,"_docModel");N(this,"hasSelection",e.computed(()=>!this._selection.isCollapsed));this._docModel=t}get selection(){return this._selection}setCursor(t){this._selection.anchor={...t},this._selection.focus={...t},this._selection.isCollapsed=!0}setSelection(t,o){this._selection.anchor={...t},this._selection.focus={...o},this._selection.isCollapsed=dt(t,o)}collapse(t=!0){t?this._selection.anchor={...this._selection.focus}:this._selection.focus={...this._selection.anchor},this._selection.isCollapsed=!0}selectAll(){const t=this._docModel.data.sections,o=t[t.length-1],a=o==null?void 0:o.paragraphs[o.paragraphs.length-1],i=a==null?void 0:a.children[a.children.length-1],c=(i==null?void 0:i.type)==="text"?i.value.length:0;this._selection.anchor=be(0,0,0,0),this._selection.focus=be(t.length-1,((o==null?void 0:o.paragraphs.length)??1)-1,((a==null?void 0:a.children.length)??0)===0?0:((a==null?void 0:a.children.length)??1)-1,c),this._selection.isCollapsed=!1}moveForward(t=!1){const o=this._selection.focus,a=this._docModel.getParagraphAt(o.sectionIndex,o.paragraphIndex);if(!a)return;const i=a.children[o.elementIndex];if((i==null?void 0:i.type)==="text"&&o.offset<i.value.length){const y={...o,offset:o.offset+1};this._applyMove(y,t);return}if(o.elementIndex<a.children.length-1){const y={...o,elementIndex:o.elementIndex+1,offset:0};this._applyMove(y,t);return}const c=this._getNextParagraphPoint(o);c&&this._applyMove(c,t)}moveBackward(t=!1){const o=this._selection.focus;if(o.offset>0){const i={...o,offset:o.offset-1};this._applyMove(i,t);return}if(o.elementIndex>0){const i=this._docModel.getParagraphAt(o.sectionIndex,o.paragraphIndex),c=i==null?void 0:i.children[o.elementIndex-1],y=(c==null?void 0:c.type)==="text"?c.value.length:0,s={...o,elementIndex:o.elementIndex-1,offset:y};this._applyMove(s,t);return}const a=this._getPrevParagraphPoint(o);a&&this._applyMove(a,t)}_applyMove(t,o){o?(this._selection.focus=t,this._selection.isCollapsed=dt(this._selection.anchor,t)):(this._selection.anchor={...t},this._selection.focus={...t},this._selection.isCollapsed=!0)}_getNextParagraphPoint(t){const o=this._docModel.data.sections[t.sectionIndex];return o?t.paragraphIndex<o.paragraphs.length-1?be(t.sectionIndex,t.paragraphIndex+1,0,0):t.sectionIndex<this._docModel.data.sections.length-1?be(t.sectionIndex+1,0,0,0):null:null}_getPrevParagraphPoint(t){if(t.paragraphIndex>0){const o=this._docModel.getParagraphAt(t.sectionIndex,t.paragraphIndex-1);if(!o)return null;const a=o.children.length-1,i=o.children[a],c=(i==null?void 0:i.type)==="text"?i.value.length:0;return be(t.sectionIndex,t.paragraphIndex-1,Math.max(a,0),c)}if(t.sectionIndex>0){const o=this._docModel.data.sections[t.sectionIndex-1];if(!o)return null;const a=o.paragraphs.length-1,i=o.paragraphs[a],c=((i==null?void 0:i.children.length)??0)-1,y=i==null?void 0:i.children[c],s=(y==null?void 0:y.type)==="text"?y.value.length:0;return be(t.sectionIndex-1,a,Math.max(c,0),s)}return null}static domToModelPoint(t,o){let a=t instanceof Element?t:t.parentElement;for(;a;){const i=a.getAttribute("data-si"),c=a.getAttribute("data-pi"),y=a.getAttribute("data-ei");if(i!==null&&c!==null&&y!==null)return{sectionIndex:parseInt(i),paragraphIndex:parseInt(c),elementIndex:parseInt(y),offset:o};a=a.parentElement}return null}}const Pn=200;class Ln{constructor(){N(this,"_undoStack",[]);N(this,"_redoStack",[])}get canUndo(){return this._undoStack.length>0}get canRedo(){return this._redoStack.length>0}push(t){var a,i;this._redoStack=[];const o=this._undoStack[this._undoStack.length-1];if(o&&((a=t.canMergeWith)!=null&&a.call(t,o))){(i=o.merge)==null||i.call(o,t);return}this._undoStack.push(t),this._undoStack.length>Pn&&this._undoStack.shift()}undo(){const t=this._undoStack.pop();return t?(t.undo(),this._redoStack.push(t),!0):!1}redo(){const t=this._redoStack.pop();return t?(t.execute(),this._undoStack.push(t),!0):!1}clear(){this._undoStack=[],this._redoStack=[]}}class $n{constructor(t,o,a,i,c){N(this,"name","insertText");N(this,"_point");N(this,"_text");N(this,"_format");this.docModel=t,this.selectionManager=o,this._point={...a},this._text=i,this._format=c}execute(){this.docModel.insertText(this._point,this._text,this._format),this.selectionManager.setCursor({...this._point,offset:this._point.offset+this._text.length})}undo(){this.docModel.deleteAt(this._point,this._text.length),this.selectionManager.setCursor(this._point)}canMergeWith(t){if(t.name!=="insertText")return!1;const o=t;return o._point.sectionIndex===this._point.sectionIndex&&o._point.paragraphIndex===this._point.paragraphIndex&&o._point.elementIndex===this._point.elementIndex&&o._point.offset===this._point.offset+this._text.length}merge(t){const o=t;this._text+=o._text}}class zn{constructor(t,o){N(this,"name","insertParagraph");N(this,"_insertedParagraphId",null);this.docModel=t,this.selectionManager=o}execute(){var m,f;const{focus:t}=this.selectionManager.selection,{sectionIndex:o,paragraphIndex:a}=t,i=this.docModel.getParagraphAt(o,a);if(!i)return;const c=t.elementIndex,y=i.children.splice(c),s=this.docModel.createEmptyParagraph(i.format);s.children.push(...y),this._insertedParagraphId=s.id,this.docModel.data.sections[o].paragraphs.splice(a+1,0,s),(f=(m=this.docModel).bumpVersion)==null||f.call(m),this.selectionManager.setCursor({sectionIndex:o,paragraphIndex:a+1,elementIndex:0,offset:0})}undo(){const{focus:t}=this.selectionManager.selection,{sectionIndex:o,paragraphIndex:a}=t;a!==0&&(this.docModel.mergeParagraphs(o,a-1),this.selectionManager.setCursor({sectionIndex:o,paragraphIndex:a-1,elementIndex:0,offset:0}))}}class ht{constructor(t,o,a){N(this,"name");N(this,"_deletedText","");this.docModel=t,this.selectionManager=o,this.name=a==="backward"?"deleteBackward":"deleteForward"}execute(){const{focus:t,isCollapsed:o}=this.selectionManager.selection;if(o)if(this.name==="deleteBackward")if(t.offset>0){const a={...t,offset:t.offset-1},i=this.docModel.getElementAt(t);(i==null?void 0:i.type)==="text"&&(this._deletedText=i.value[t.offset-1]??""),this.docModel.deleteAt(a,1),this.selectionManager.setCursor(a)}else(t.paragraphIndex>0||t.elementIndex>0)&&(this.docModel.mergeParagraphs(t.sectionIndex,t.paragraphIndex-1),this.selectionManager.setCursor({...t,paragraphIndex:t.paragraphIndex-1}));else{const a=this.docModel.getElementAt(t);if((a==null?void 0:a.type)==="text"&&t.offset<a.value.length)this._deletedText=a.value[t.offset],this.docModel.deleteAt(t,1);else{const i=this.docModel.data.sections[t.sectionIndex];i&&t.paragraphIndex<i.paragraphs.length-1&&this.docModel.mergeParagraphs(t.sectionIndex,t.paragraphIndex)}}}undo(){if(this._deletedText){const{focus:t}=this.selectionManager.selection;this.docModel.insertText(t,this._deletedText)}}}class Te{constructor(t,o,a,i){N(this,"name");N(this,"_prevFormat",{});this.docModel=t,this.selectionManager=o,this._value=i,this.name=a}execute(){const{anchor:t,focus:o}=this.selectionManager.selection,a=this._getFormatKey();if(!a)return;const i={};if(this._isToggle()){const c=this._getCurrentValue(a);i[a]=!c}else i[a]=this._value;this.docModel.updateRangeFormat(t,o,i)}undo(){const{anchor:t,focus:o}=this.selectionManager.selection;this.docModel.updateRangeFormat(t,o,this._prevFormat)}_isToggle(){return["bold","italic","underline","strikethrough","superscript","subscript"].includes(this.name)}_getFormatKey(){return{bold:"bold",italic:"italic",underline:"underline",strikethrough:"strikethrough",fontSize:"fontSize",fontFamily:"fontFamily",color:"color",backgroundColor:"backgroundColor"}[this.name]??null}_getCurrentValue(t){var i;const{focus:o}=this.selectionManager.selection,a=this.docModel.getElementAt(o);return(i=a==null?void 0:a.format)==null?void 0:i[t]}}class Ge{constructor(t,o,a,i){N(this,"name","textAlign");this.docModel=t,this.selectionManager=o,this._formatKey=a,this._value=i}execute(){const{focus:t}=this.selectionManager.selection,o={};o[this._formatKey]=this._value,this.docModel.updateParagraphFormat(t.sectionIndex,t.paragraphIndex,o)}undo(){}}class Dn{constructor(t,o,a){N(this,"_factories",new Map);this.docModel=t,this.selectionManager=o,this.historyManager=a,this._registerBuiltinCommands()}_registerBuiltinCommands(){this.register("insertText",o=>{const{focus:a}=this.selectionManager.selection;return new $n(this.docModel,this.selectionManager,a,o)}),this.register("insertParagraph",()=>new zn(this.docModel,this.selectionManager)),this.register("deleteBackward",()=>new ht(this.docModel,this.selectionManager,"backward")),this.register("deleteForward",()=>new ht(this.docModel,this.selectionManager,"forward")),this.register("undo",()=>null),this.register("redo",()=>null),["bold","italic","underline","strikethrough","superscript","subscript"].forEach(o=>{this.register(o,()=>new Te(this.docModel,this.selectionManager,o))}),this.register("fontSize",o=>new Te(this.docModel,this.selectionManager,"fontSize",o)),this.register("fontFamily",o=>new Te(this.docModel,this.selectionManager,"fontFamily",o)),this.register("color",o=>new Te(this.docModel,this.selectionManager,"color",o)),this.register("backgroundColor",o=>new Te(this.docModel,this.selectionManager,"backgroundColor",o)),this.register("textAlign",o=>new Ge(this.docModel,this.selectionManager,"textAlign",o)),this.register("lineHeight",o=>new Ge(this.docModel,this.selectionManager,"lineHeight",o)),this.register("heading",o=>new Ge(this.docModel,this.selectionManager,"heading",o)),this.register("selectAll",()=>(this.selectionManager.selectAll(),null)),this.register("setSelection",o=>{if(o){const a=o;this.selectionManager.setSelection(a.anchor,a.focus)}return null})}register(t,o){this._factories.set(t,o)}exec(t,o){if(t==="undo"){this.historyManager.undo();return}if(t==="redo"){this.historyManager.redo();return}const a=this._factories.get(t);if(!a){console.warn(`[CommandManager] 未注册命令: ${t}`);return}const i=a(o);i&&(i.execute(),this.historyManager.push(i))}}class Rn{constructor(t,o){N(this,"_el",null);N(this,"_commandManager");N(this,"_selectionManager");N(this,"_composing",!1);N(this,"_boundKeydown");N(this,"_boundBeforeInput");N(this,"_boundCompositionStart");N(this,"_boundCompositionEnd");N(this,"_boundSelectionChange");this._commandManager=t,this._selectionManager=o,this._boundKeydown=this._onKeydown.bind(this),this._boundBeforeInput=this._onBeforeInput.bind(this),this._boundCompositionStart=()=>{this._composing=!0},this._boundCompositionEnd=this._onCompositionEnd.bind(this),this._boundSelectionChange=this._onSelectionChange.bind(this)}attach(t){this._el=t,t.addEventListener("keydown",this._boundKeydown),t.addEventListener("beforeinput",this._boundBeforeInput),t.addEventListener("compositionstart",this._boundCompositionStart),t.addEventListener("compositionend",this._boundCompositionEnd),document.addEventListener("selectionchange",this._boundSelectionChange)}detach(){this._el&&(this._el.removeEventListener("keydown",this._boundKeydown),this._el.removeEventListener("beforeinput",this._boundBeforeInput),this._el.removeEventListener("compositionstart",this._boundCompositionStart),this._el.removeEventListener("compositionend",this._boundCompositionEnd),document.removeEventListener("selectionchange",this._boundSelectionChange),this._el=null)}_onKeydown(t){const o=t.key,a=t.ctrlKey||t.metaKey,i=t.shiftKey;if(a)switch(o){case"z":t.preventDefault(),i?this._commandManager.exec("redo"):this._commandManager.exec("undo");return;case"b":t.preventDefault(),this._commandManager.exec("bold");return;case"i":t.preventDefault(),this._commandManager.exec("italic");return;case"u":t.preventDefault(),this._commandManager.exec("underline");return;case"a":t.preventDefault(),this._commandManager.exec("selectAll");return}switch(o){case"Enter":t.preventDefault(),this._composing||this._commandManager.exec("insertParagraph");break;case"Backspace":t.preventDefault(),this._composing||this._commandManager.exec("deleteBackward");break;case"Delete":t.preventDefault(),this._composing||this._commandManager.exec("deleteForward");break;case"ArrowLeft":t.preventDefault(),this._selectionManager.moveBackward(i);break;case"ArrowRight":t.preventDefault(),this._selectionManager.moveForward(i);break;case"Tab":t.preventDefault(),this._commandManager.exec("insertText"," ");break}}_onBeforeInput(t){t.preventDefault(),!this._composing&&t.data&&this._commandManager.exec("insertText",t.data)}_onCompositionEnd(t){this._composing=!1,t.data&&this._commandManager.exec("insertText",t.data)}_onSelectionChange(){const t=window.getSelection();if(!t||!this._el)return;const o=t.anchorNode,a=t.focusNode;if(!o||!a||!this._el.contains(o)&&!this._el.contains(a))return;const i=We.domToModelPoint(o,t.anchorOffset),c=We.domToModelPoint(a,t.focusOffset);i&&c&&this._selectionManager.setSelection(i,c)}}class ft{constructor(t={}){N(this,"docModel");N(this,"selection");N(this,"history");N(this,"commands");N(this,"input");N(this,"_readonly");N(this,"_plugins",[]);N(this,"_inputEl",null);var o;this._readonly=t.readonly??!1,this.docModel=new De(t.initialDocument),this.selection=new We(this.docModel),this.history=new Ln,this.commands=new Dn(this.docModel,this.selection,this.history),this.input=new Rn(this.commands,this.selection),(o=t.plugins)==null||o.forEach(a=>this.use(a))}exec(t,o){if(this._readonly&&!this._isReadCommand(t)){console.warn("[Editor] 只读模式,忽略写操作");return}this.commands.exec(t,o)}mount(t){this._inputEl=t,this._readonly||this.input.attach(t)}unmount(){this.input.detach(),this._inputEl=null}use(t){return this._plugins.find(o=>o.name===t.name)?(console.warn(`[Editor] 插件 ${t.name} 已安装`),this):(t.install(this),this._plugins.push(t),this)}getJSON(){return this.docModel.toJSON()}loadJSON(t){const o=De.fromJSON(t);Object.assign(this.docModel.data,o.data),this.history.clear()}get isReadonly(){return this._readonly}_isReadCommand(t){return["undo","redo","selectAll","setSelection"].includes(t)}}const Je=Symbol("editor");function Hn(n){const t=new ft(n);return e.provide(Je,t),e.onUnmounted(()=>{t.unmount()}),t}function On(){const n=e.inject(Je);if(!n)throw new Error("[useEditor] 必须在 EditorContainer 组件内使用");return n}const ut=An,Nn={install(n){n.component("EditorContainer",ut)}};J.Editor=ft,J.EditorContainer=ut,J.EditorKey=Je,J.createEditor=Hn,J.default=Nn,J.useEditor=On,Object.defineProperties(J,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
1
+ (function(Y,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("vue-virtual-scroller"),require("lucide-vue-next")):typeof define=="function"&&define.amd?define(["exports","vue","vue-virtual-scroller","lucide-vue-next"],e):(Y=typeof globalThis<"u"?globalThis:Y||self,e(Y.WordEditor={},Y.Vue,Y.VueVirtualScroller,Y.LucideVueNext))})(this,function(Y,e,Ce,S){"use strict";var io=Object.defineProperty;var ro=(Y,e,Ce)=>e in Y?io(Y,e,{enumerable:!0,configurable:!0,writable:!0,value:Ce}):Y[e]=Ce;var V=(Y,e,Ce)=>ro(Y,typeof e!="symbol"?e+"":e,Ce);const bt={class:"we-vt-context-menu--option-wrapper modern-menu-wrapper"},_t=["onMouseenter","onMouseleave"],wt=["onClick"],xt={class:"we-vt-context-menu--link-content menu-label"},Et={key:0,class:"we-vt-context-menu--submenu modern-submenu"},Ct=["onClick"],Bt={class:"we-vt-context-menu--link-content submenu-label"},Mt={__name:"ContextMenu",props:{e:{type:Object,default:()=>({})},row:{type:Object,default:()=>({})},menuConfig:{type:Object,default:()=>({body:{}})}},emits:["close","menuClick"],setup(n,{emit:t}){const o=t,a=n,i=e.computed(()=>{var O,A;return{left:`${(O=a.e)==null?void 0:O.pageX}px`,top:`${(A=a.e)==null?void 0:A.pageY}px`}}),s=e.ref([]),p=e.ref(null);let m=null;const y=e.ref(),c=(O,A,f)=>{if(O.children&&O.children.length>0){A&&A.preventDefault()&&A.stopPropagation();return}O.disabled||(f?o("menuClick",{...O,parent:f.code},a.row):o("menuClick",O,a.row)),A&&A.preventDefault()&&A.stopPropagation()},C=O=>{let A=O.target;for(;A&&A!=y.value;)A=A.parentNode;A!=y.value&&o("close")},_=(O,A)=>{O.currentTarget.classList.add("link--active"),m&&(clearTimeout(m),m=null),A.children&&A.children.length>0?p.value=A.code:m=setTimeout(()=>{p.value=null},100)},R=(O,A)=>{O.currentTarget.classList.remove("link--active"),A.children&&A.children.length>0&&(m=setTimeout(()=>{p.value===A.code&&(p.value=null)},300))},H=O=>{m&&(clearTimeout(m),m=null),O.currentTarget.classList.add("link--active")},j=O=>{O.currentTarget.classList.remove("link--active")},F=O=>{const A=O.code||"",f=(O.name||"").toLowerCase(),B={"add-current":S.Navigation,"add-next":S.ArrowDown,"add-child":S.PlusCircle,paste:S.Clipboard,delete:S.Trash2,copy:S.Copy,cut:S.Move,edit:S.Edit,export_part_section:S.Layers,export_part_chapter:S.FileDown,export_full:S.Download,pdf:S.FileText,word:S.Type,excel:S.Grid,txt:S.FileText,view:S.Eye,preview:S.Eye,expand:S.Plus,collapse:S.Minus,"sort-asc":S.SortAsc,"sort-desc":S.SortDesc,filter:S.Filter,search:S.Search,permission:S.ShieldCheck,share:S.Share,lock:S.Lock,unlock:S.Globe,info:S.Info,settings:S.Settings,history:S.History,refresh:S.RotateCcw,save:S.Save,upload:S.Upload,download:S.Download,more:S.MoreHorizontal};return B[A]?B[A]:f.includes("添加")||f.includes("add")?f.includes("当前")||f.includes("current")?S.Navigation:f.includes("下")||f.includes("next")?S.ArrowDown:f.includes("子")||f.includes("child")?S.PlusCircle:S.Plus:f.includes("导出")||f.includes("export")?f.includes("节")||f.includes("section")?S.Layers:f.includes("章")||f.includes("chapter")?S.FileDown:S.Download:f.includes("粘贴")||f.includes("paste")?S.Clipboard:f.includes("删除")||f.includes("delete")?S.Trash2:f.includes("pdf")?S.FileText:f.includes("word")?S.Type:S.MoreHorizontal};return e.onMounted(()=>{var O,A,f,B,$,I,q;(O=a.menuConfig)!=null&&O.visibleMethod&&typeof((A=a.menuConfig)==null?void 0:A.visibleMethod)=="function"&&(($=a.menuConfig)==null||$.visibleMethod({options:(B=(f=a.menuConfig)==null?void 0:f.body)==null?void 0:B.options,row:a.row})),s.value=(((q=(I=a.menuConfig)==null?void 0:I.body)==null?void 0:q.options)||[]).flat(),document.addEventListener("click",C,!0)}),e.onUnmounted(()=>{document.removeEventListener("click",C,!0)}),(O,A)=>(e.openBlock(),e.createElementBlock("div",{class:"we-vt-table--context-menu-wrapper virtual-table-menu modern-virtual-menu",ref_key:"contextMenuRef",ref:y,style:e.normalizeStyle([{display:"inline-block"},i.value])},[e.createElementVNode("ul",bt,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s.value,f=>(e.openBlock(),e.createElementBlock("li",{class:e.normalizeClass({"link--disabled":f.disabled,"has-children":f.children&&f.children.length>0,"modern-menu-item":!0}),key:f.code,onMouseenter:B=>_(B,f),onMouseleave:B=>R(B,f)},[e.createElementVNode("a",{class:"we-vt-context-menu--link modern-menu-link",onClick:B=>c(f,B)},[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(F(f)),{size:16,class:"menu-icon"})),e.createElementVNode("span",xt,e.toDisplayString(f.name),1),f.children&&f.children.length>0?(e.openBlock(),e.createBlock(e.unref(S.ChevronRight),{key:0,size:14,class:"submenu-arrow"})):e.createCommentVNode("",!0)],8,wt),f.children&&f.children.length>0&&p.value===f.code?(e.openBlock(),e.createElementBlock("ul",Et,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(f.children,B=>(e.openBlock(),e.createElementBlock("li",{key:B.code,class:e.normalizeClass({"link--disabled":B.disabled,"modern-submenu-item":!0}),onMouseenter:H,onMouseleave:j},[e.createElementVNode("a",{class:"we-vt-context-menu--link modern-submenu-link",onClick:$=>c(B,$,f)},[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(F(B)),{size:14,class:"submenu-icon"})),e.createElementVNode("span",Bt,e.toDisplayString(B.name),1)],8,Ct)],34))),128))])):e.createCommentVNode("",!0)],42,_t))),128))])],4))}},Qe=Symbol("component_container");function St(n,t,o){const a=e.h(n,{...t},o),i=document.createElement("div");return document.body.appendChild(i),a[Qe]=i,e.render(a,i),a.component}function Ft(n){var o;const t=n.vnode[Qe];e.render(null,t),t!=null&&t.checkVisibility&&(t!=null&&t.checkVisibility())&&((o=document.body)==null||o.removeChild(t))}let et;const It=n=>{et=St(Mt,n,null)},Tt=function(n){const t=n.onClose;return n.onClose=()=>{t&&t.call(),Ft(et)},It(n),n};function At(n,t,o){const a=(o==null?void 0:o.keyField)||(o==null?void 0:o.rowField)||"node_id",i=(o==null?void 0:o.parentField)||"parent_id",s=(o==null?void 0:o.parentField)||"order";if(!(n!=null&&n.length))return n;const p={};n.forEach(C=>{const _=C[i];p[_]||(p[_]=[]),p[_].push(C)});function m(C){const _=p[C]||[];_.sort((H,j)=>H[s]&&j[s]?H[s]-j[s]:0);const R=[];return _.forEach(H=>{R.push(H),R.push(...m(H[a]))}),R}let y=[];if(Array.isArray(t))y=t;else{const C=new Set(n.map(H=>H[a])),_=n.filter(H=>!C.has(H[i]));if(_.length===0)throw new Error("无法确定根节点:可能存在循环引用或数据不完整");const R={};_.forEach(H=>{const j=H[i];R[j]=(R[j]||0)+1}),y=Object.entries(R).map(([H])=>H)}let c=[];return y.forEach(C=>{c=c.concat(m(C))}),c}function tt(n,t,o){let a;for(;n&&n.nodeType&&n!==document;){if(n.className&&n.className.split&&n.className.split(" ").indexOf(t)>-1)return a=n,a;if(n===o)return null;n=n.parentNode}return a}function Pt(n){return typeof n=="function"||Object.prototype.toString.call(n)==="[object Object]"&&!e.isVNode(n)}const Lt=e.defineComponent({name:"VirtualTable",props:{data:{type:Array,required:!0,default:()=>[]},rowConfig:{type:Object,default:()=>({keyField:"node_id"})},editConfig:{type:Object,default:null},treeConfig:{type:Object,default:null},menuConfig:{type:Object,default:()=>({body:{}})},showHeader:{type:Boolean,default:!0},rowClassName:{type:Function,default:null},pageConfig:{type:Object,default:()=>({enabled:!1,pageHeight:842,pageWidth:595,margin:40,gap:10,showPageHeader:!0,showPageBorder:!1,pageBorderPadding:5,pageBorderStyle:"1px solid #000",headerHeight:0,footerHeight:0,showPageNumber:!0})},pageData:{type:Object,default:null}},emits:["current-change","menu-click","edit-activated","edit-closed","scroll-end","selection-change"],setup(n,{emit:t,slots:o,expose:a}){var kt;const i=e.getCurrentInstance(),s=e.ref(),p=e.ref(!1),m=e.ref(null),y=e.ref(null),c=e.ref([]);let C=new Map;const _=new Map;e.ref(0);const R=e.ref([]);e.ref([]);const H=e.ref(new Set),j=e.ref(new Set),F=e.ref(null),O=2,A=new WeakMap,f=e.ref(null),B=e.ref(""),$=new Set,I=e.computed(()=>{try{return Array.isArray(c.value)?c.value:[]}catch{return[]}}),q=l=>{var g,h,u;if(!l)return 30;if(l.height)return l.height;const r=`${l.content_type}_${((g=l.content)==null?void 0:g.length)||0}_${((h=l.title)==null?void 0:h.length)||0}_${l._editing?1:0}`;if(A.has(l)){const w=A.get(l);if(w.key===r)return w.height}let d=30;switch(l.content_type){case"image":d=150;break;case"table-row":d=l.rowHeight||35;break;case"table":const x=((l.content||"").match(/<tr/g)||[]).length;d=Math.max(100,x*35+30);break;case"flowchart":d=200;break;default:{const k=(l.content||"").length,b=(l.title||"").length,E=k+b,P=((u=(l.content||"").match(/[\u4e00-\u9fa5]/g))==null?void 0:u.length)||0,D=E-P,T=P*12+D*6,M=Math.max(1,Math.ceil(T/760));d=Math.max(20,M*18),l._editing&&(d+=20);break}}return A.set(l,{key:r,height:d}),d},fe=e.computed(()=>{if(I.value.length===0)return 30;const l=I.value.slice(0,Math.min(100,I.value.length));if(l.length===0)return 30;const r=l.reduce((g,h)=>g+q(h),0)/l.length,d=Math.max(20,Math.floor(r*.6));return Math.min(d,60)});let L;const X=(l,r)=>{t("menu-click",{menu:l,row:r}),L==null||L.onClose(),L=null},v=l=>{var d,g,h,u,w;if(!((h=(g=(d=n.menuConfig)==null?void 0:d.body)==null?void 0:g.options)!=null&&h.length))return;L==null||L.onClose(),L=null;let r=l.target;for(;r&&(r!=null&&r.getAttribute)&&!(r!=null&&r.getAttribute("data-id"))&&r!==((u=s.value)==null?void 0:u.$el);)r=r.parentNode;if((w=r==null?void 0:r.getAttribute)!=null&&w.call(r,"data-id")){const x=r.getAttribute("data-id"),k=ke(x);k&&(L=Tt({e:l,row:k,menuConfig:n.menuConfig,onMenuClick:X}),l.preventDefault(),l.stopPropagation())}},le=l=>{var d,g,h;if(!m.value)return;let r=l.target;for(;r&&(r!=null&&r.getAttribute)&&!(r!=null&&r.getAttribute("data-id"))&&r!==((d=s.value)==null?void 0:d.$el);)if(r=r.parentNode,r!=null&&r.classList&&["el-popper","ck-body-wrapper"].some(u=>r.classList.contains(u)))return;((g=r==null?void 0:r.getAttribute)==null?void 0:g.call(r,"data-id"))!=((h=m.value)==null?void 0:h.node_id)&&(m.value._editing=!1,t("edit-closed",{row:m.value,column:{},$table:i==null?void 0:i.exposed}),m.value=null)};((kt=n.editConfig)==null?void 0:kt.trigger)==="dblclick"&&e.watch(()=>m.value,l=>{document.removeEventListener("click",le,!0),l&&setTimeout(()=>{document.addEventListener("click",le,!0)},200)});const se=l=>JSON.stringify(l.map(r=>{var d;return{id:r[n.rowConfig.keyField],content:((d=r.content)==null?void 0:d.length)||0,type:r.content_type,editing:r._editing}})),ge=()=>{if(!n.pageConfig.enabled){R.value=[{items:c.value,startIndex:0,endIndex:c.value.length}];return}if(n.pageData&&Object.keys(n.pageData).length){const l=[],r=n.rowConfig.keyField||"node_id",d=new Map;c.value.forEach(h=>{d.set(String(h[r]),h)}),Object.keys(n.pageData).sort((h,u)=>parseInt(h)-parseInt(u)).forEach(h=>{const u=n.pageData[h],w=[];u.forEach(x=>{const k=d.get(String(x));k&&w.push(k)}),w.length>0&&l.push({items:w,pageNumber:parseInt(h),height:w.reduce((x,k)=>x+q(k),0)})}),R.value=l}else{const{pageHeight:l,margin:r,headerHeight:d=0}=n.pageConfig,h=Math.max(100,l-r*2-d-20),u=[];let w=[],x=0,k=0,b=1;c.value.forEach((E,P)=>{const D=q(E);(E.layer||0)<=2&&w.length>0?(u.push({items:[...w],startIndex:k,endIndex:P,height:x,pageNumber:b++}),w=[E],x=D,k=P):x+D>h&&w.length>0?(u.push({items:[...w],startIndex:k,endIndex:P,height:x,pageNumber:b++}),w=[E],x=Math.min(D,h),k=P):(w.push(E),x+=D)}),w.length>0&&u.push({items:w,startIndex:k,endIndex:c.value.length,height:x,pageNumber:b}),R.value=u}},Pe=()=>{try{const l=Array.isArray(n.data)?n.data:[],r=se(l);if(!(r!==B.value)&&c.value.length>0)return;B.value=r;const g=(n.treeConfig?At(l,void 0,n.treeConfig):l).map((u,w)=>{const x=u[n.rowConfig.keyField],k=_.get(x);if(!k||k.content!==u.content||k.content_type!==u.content_type){$.add(x);const b={...u,index:w,_editing:u._editing||!1,_original:(k==null?void 0:k._original)||{...u}};return _.set(x,b),b}return k.index=w,k});c.value=g,ge();const h=new Set(g.map(u=>u[n.rowConfig.keyField]));for(const[u]of _)h.has(u)||(_.delete(u),$.delete(u))}catch{c.value=[],R.value=[],_.clear(),$.clear()}};e.watch(()=>n.data,(l,r)=>{try{if(!Array.isArray(l))return;e.nextTick(()=>{if(Pe(),n.pageConfig.enabled){j.value.clear(),H.value.clear();for(let d=0;d<Math.min(3,R.value.length);d++)j.value.add(d);e.nextTick(()=>{ne()})}})}catch{}},{deep:!1,immediate:!1}),e.watch(()=>n.pageData,()=>{if(n.pageConfig.enabled){ge(),j.value.clear(),H.value.clear();for(let l=0;l<Math.min(3,R.value.length);l++)j.value.add(l);e.nextTick(()=>{ne()})}},{deep:!0}),e.watch(()=>n.pageConfig,()=>{if(n.pageConfig.enabled){ge(),j.value.clear(),H.value.clear();for(let l=0;l<Math.min(3,R.value.length);l++)j.value.add(l);e.nextTick(()=>{ne()})}},{deep:!0}),e.watch(y,()=>t("current-change",{row:y.value}));let we=null;const ce=()=>{window.ResizeObserver&&(we=new ResizeObserver(l=>{var r,d;for(const g of l){const h=(r=g.target.dataset)==null?void 0:r.id;if(!h)continue;const u=ke(h);if(!u)continue;const w=g.contentRect.height,x=((d=A.get(u))==null?void 0:d.height)||0;if(Math.abs(x-w)>5){const k=A.get(u)||{};A.set(u,{...k,height:w}),requestAnimationFrame(()=>{var E;const b=g.target.__vueParentComponent;(E=b==null?void 0:b.proxy)!=null&&E.updateSize&&b.proxy.updateSize()})}}}),e.nextTick(()=>{var d;const l=(d=s.value)==null?void 0:d.$el;if(!l)return;l.querySelectorAll("[data-id]").forEach(g=>{g.dataset.id&&we.observe(g)})}))},te=()=>{f.value&&(f.value.disconnect(),f.value=null),we&&(we.disconnect(),we=null)},ne=()=>{n.pageConfig.enabled&&(F.value&&F.value.disconnect(),F.value=new IntersectionObserver(l=>{l.forEach(r=>{const d=parseInt(r.target.dataset.pageIndex);if(r.isIntersecting){H.value.add(d);for(let g=Math.max(0,d-O);g<=Math.min(R.value.length-1,d+O);g++)j.value.add(g)}else H.value.delete(d),setTimeout(()=>{H.value.has(d)||Array.from(H.value).some(h=>Math.abs(h-d)<=O*2)||j.value.delete(d)},3e3)})},{root:null,rootMargin:"100px",threshold:.01}),e.nextTick(()=>{const l=document.querySelector(".a4-pages-container");l&&l.querySelectorAll(".a4-page-placeholder").forEach(d=>{F.value.observe(d)})}))};e.onMounted(()=>{Pe(),e.nextTick(()=>{var l;if(ce(),he.setup(),ne(),((l=n.editConfig)==null?void 0:l.trigger)==="contenteditable"&&(document.addEventListener("selectionchange",xe),document.addEventListener("mouseup",He)),n.pageConfig.enabled)for(let r=0;r<Math.min(3,R.value.length);r++)j.value.add(r)}),p.value=!0}),e.onUnmounted(()=>{var l;te(),he.cleanup(),F.value&&(F.value.disconnect(),F.value=null),((l=n.editConfig)==null?void 0:l.trigger)==="contenteditable"&&(document.removeEventListener("selectionchange",xe),document.removeEventListener("mouseup",He)),W&&clearTimeout(W),C=new Map,_.clear(),j.value.clear(),H.value.clear()});const he={handlers:new Map,setup(){e.nextTick(()=>{var r;const l=(r=s.value)==null?void 0:r.$el;l&&(l.addEventListener("click",this.handleClick.bind(this),{passive:!0}),l.addEventListener("dblclick",this.handleDblClick.bind(this),{passive:!0}))})},handleClick(l){const r=l.target.closest("[data-id]");if(!r)return;const d=r.dataset.id,g=ke(d);g&&Ne(g)},handleDblClick(l){var h;if(!((h=n.editConfig)!=null&&h.trigger)==="dblclick")return;const r=l.target.closest("[data-id]");if(!r)return;const d=r.dataset.id,g=ke(d);g&&Le(g)},cleanup(){var r,d;const l=(d=(r=s.value)==null?void 0:r.$el)==null?void 0:d.querySelector(".virtual-table-wrapper");l&&(l.removeEventListener("click",this.handleClick),l.removeEventListener("dblclick",this.handleDblClick))}},pe=l=>{Ne(l)},ae=l=>Le(l);let Z=null,oe;const ie=({row:l,column:r},d,g)=>{var w,x;const h=g||d.target,u=tt(h,"virtual-table-cell",(w=s.value)==null?void 0:w.$el);Z===u&&oe&&(clearTimeout(oe),Z=null),((x=m.value)==null?void 0:x[n.rowConfig.keyField])!=(l==null?void 0:l[n.rowConfig.keyField])&&setTimeout(()=>{var b,E;m.value=l;let k=(b=h==null?void 0:h.getAttribute)==null?void 0:b.call(h,"field");if(!k){try{const P=document.getSelection();let D=P==null?void 0:P.anchorNode;D&&D.nodeType===3&&(D=D.parentElement);const T=(E=D==null?void 0:D.closest)==null?void 0:E.call(D,"[field]");T&&(k=T.getAttribute("field"))}catch{}if(!k&&(d!=null&&d.composedPath)){for(const P of d.composedPath())if(P!=null&&P.getAttribute&&P.getAttribute("field")){k=P.getAttribute("field");break}}}t("edit-activated",{row:l,column:{...r,field:k},$table:i==null?void 0:i.exposed})},200)},me=({row:l,column:r},d,g)=>{var u;const h=g||d.target;Z=tt(h,"virtual-table-cell",(u=s.value)==null?void 0:u.$el),oe&&clearTimeout(oe),oe=setTimeout(()=>{var k,b,E,P,D;const w=l.content_type;let x=(k=h==null?void 0:h.getAttribute)==null?void 0:k.call(h,"field");if(!x){try{const T=document.getSelection();let M=T==null?void 0:T.anchorNode;M&&M.nodeType===3&&(M=M.parentElement);const K=(b=M==null?void 0:M.closest)==null?void 0:b.call(M,"[field]");K&&(x=K.getAttribute("field"))}catch{}if(!x&&(d!=null&&d.composedPath)){for(const T of d.composedPath())if(T!=null&&T.getAttribute&&T.getAttribute("field")){x=T.getAttribute("field");break}}}if(w!=="table"){if(w==="text"){let T=null,M=null;if((E=h==null?void 0:h.getAttribute)!=null&&E.call(h,"field")?T=h:(P=h==null?void 0:h.closest)!=null&&P.call(h,"[field]")&&(T=h.closest("[field]")),T&&(M=T.textContent),x&&M!==void 0&&M!==null){M=M.trim();const K=((D=l[x])==null?void 0:D.trim())||"";M!==K&&(l[x]=M)}}}t("edit-closed",{row:l,column:{...r,field:x},$table:i==null?void 0:i.exposed})},50)};let N=null,W=null;const G=l=>{var r;((r=n.editConfig)==null?void 0:r.trigger)==="contenteditable"&&ye("focusin",l)},Q=l=>{var r,d,g,h,u;if(((r=n.editConfig)==null?void 0:r.trigger)==="contenteditable")if(N!=null&&N.cellEl){let w=N.fieldEl;!w&&N.field&&(w=(g=(d=N.cellEl)==null?void 0:d.querySelector)==null?void 0:g.call(d,`[field="${N.field}"]`)),w||(w=((u=(h=N.cellEl).querySelector)==null?void 0:u.call(h,"[field]"))||N.cellEl),me(N,{target:w},w),N=null}else ye("focusout",l)},ye=(l,r)=>{var d,g,h,u,w,x;try{const k=document.getSelection();let b=k==null?void 0:k.anchorNode;b&&b.nodeType===3&&(b=b.parentElement);const E=(d=b==null?void 0:b.closest)==null?void 0:d.call(b,".virtual-table-cell"),P=(g=b==null?void 0:b.closest)==null?void 0:g.call(b,".virtual-table-row");if(!E||!P)return;const D=P.getAttribute("data-id"),T=E.getAttribute("data-prop"),M=ke(D),K=Se.value.find(de=>`${de.prop}`==`${T}`)||{},U=((h=b==null?void 0:b.closest)==null?void 0:h.call(b,"[field]"))||null,z=((u=U==null?void 0:U.getAttribute)==null?void 0:u.call(U,"field"))||void 0;l==="focusin"?(N={row:M,column:K,cellEl:E,rowEl:P,fieldEl:U,field:z},ie({row:M,column:K},r,U||((w=b==null?void 0:b.closest)==null?void 0:w.call(b,"[field]")))):me({row:M,column:K},r,U||((x=b==null?void 0:b.closest)==null?void 0:x.call(b,"[field]")))}catch{}},xe=()=>{var l;((l=n.editConfig)==null?void 0:l.trigger)==="contenteditable"&&(W&&clearTimeout(W),W=setTimeout(()=>{var r,d,g,h,u,w,x,k,b,E,P,D,T,M;try{const K=document.getSelection();if(K.rangeCount===0)return;const U=K.getRangeAt(0);let z=U.startContainer;z.nodeType===3&&(z=z.parentElement);const de=(r=z==null?void 0:z.closest)==null?void 0:r.call(z,".virtual-table-cell"),be=(d=z==null?void 0:z.closest)==null?void 0:d.call(z,".virtual-table-row");if(!de||!be)return;const Ee=be.getAttribute("data-id"),Fe=de.getAttribute("data-prop"),ue=ke(Ee),ee=Se.value.find(J=>`${J.prop}`==`${Fe}`)||{};if(!N||((g=N.row)==null?void 0:g[n.rowConfig.keyField])!==(ue==null?void 0:ue[n.rowConfig.keyField])||((h=N.column)==null?void 0:h.prop)!==(ee==null?void 0:ee.prop)){if(N){let J=N.fieldEl;!J&&N.field&&(J=(w=(u=N.cellEl)==null?void 0:u.querySelector)==null?void 0:w.call(u,`[field="${N.field}"]`)),J||(J=((k=(x=N.cellEl)==null?void 0:x.querySelector)==null?void 0:k.call(x,"[field]"))||N.cellEl),me(N,{target:J},J)}N={row:ue,column:ee,cellEl:de,rowEl:be,fieldEl:((b=z==null?void 0:z.closest)==null?void 0:b.call(z,"[field]"))||null,field:((D=(P=((E=z==null?void 0:z.closest)==null?void 0:E.call(z,"[field]"))||null)==null?void 0:P.getAttribute)==null?void 0:D.call(P,"field"))||void 0},ie({row:ue,column:ee},{target:de},de)}if(K.toString()){const J=U.endContainer.nodeType===3?U.endContainer.parentElement:U.endContainer,Ke=(T=J==null?void 0:J.closest)==null?void 0:T.call(J,".virtual-table-cell"),Ue=(M=J==null?void 0:J.closest)==null?void 0:M.call(J,".virtual-table-row")}}catch{}},50))},He=()=>{var l;((l=n.editConfig)==null?void 0:l.trigger)==="contenteditable"&&setTimeout(()=>{var g,h,u,w;const r=document.getSelection();if(!r)return;const d=r.toString();if(d){const x=r.rangeCount>0?r.getRangeAt(0):null;let k=null,b=null;try{if(x){let E=x.startContainer;(E==null?void 0:E.nodeType)===3&&(E=E.parentElement);const P=(g=E==null?void 0:E.closest)==null?void 0:g.call(E,".virtual-table-cell"),D=(h=E==null?void 0:E.closest)==null?void 0:h.call(E,".virtual-table-row");k=P&&D?{rowId:D.getAttribute("data-id"),prop:P.getAttribute("data-prop")}:null;let T=x.endContainer;(T==null?void 0:T.nodeType)===3&&(T=T.parentElement);const M=(u=T==null?void 0:T.closest)==null?void 0:u.call(T,".virtual-table-cell"),K=(w=T==null?void 0:T.closest)==null?void 0:w.call(T,".virtual-table-row");b=M&&K?{rowId:K.getAttribute("data-id"),prop:M.getAttribute("data-prop")}:null}}catch{}t("selection-change",{text:d,selection:r,range:x,start:k,end:b})}},10)},Vn=l=>(l==null?void 0:l._editing)===!0,vn=l=>l!=null&&l.parent_id?C.get(l.parent_id):null,jn=l=>{var d;const r=c.value.findIndex(g=>g[n.rowConfig.keyField]==l[n.rowConfig.keyField]);return r<1?null:((d=c.value[r-1])==null?void 0:d.layer)===l.layer?c.value[r-1]:null},Kn=l=>{const r=c.value.findIndex(d=>d[n.rowConfig.keyField]==l[n.rowConfig.keyField]);return r>=c.value.length-1?null:c.value[r+1]},ke=l=>{if(!l)return null;let r=_.get(l);return r||(typeof l=="number"?_.get(`${l}`):typeof l=="string"&&/^\d+$/.test(l)?_.get(Number(l)):null)};let Oe=null;const Un=l=>{Oe&&cancelAnimationFrame(Oe),Oe=requestAnimationFrame(()=>{var g;const r=n.rowConfig.keyField,d=l[r];if(n.pageConfig.enabled){let h=-1;for(let u=0;u<R.value.length;u++)if(R.value[u].items.some(k=>k[r]===d)){h=u;break}if(h!==-1){for(let u=Math.max(0,h-1);u<=Math.min(R.value.length-1,h+1);u++)j.value.has(u)||j.value.add(u);e.nextTick(()=>{const u=document.querySelector(".a4-pages-container");if(!u)return;const w=(x=0)=>{const k=u.querySelector(`[data-id="${d}"]`);if(k){let b=0,E=k;for(;E&&E!==u;)b+=E.offsetTop,E=E.offsetParent;const P=u.clientHeight;let D=b-P*.3;D=Math.max(0,D);const T=u.scrollTop,M=Math.abs(D-T),K=U=>{const z=u.scrollTop,de=U-z,be=Math.min(800,Math.max(300,M*.5)),Ee=performance.now(),Fe=ee=>ee<.5?4*ee*ee*ee:1-Math.pow(-2*ee+2,3)/2,ue=ee=>{const $e=ee-Ee,J=Math.min($e/be,1),Ke=Fe(J),Ue=z+de*Ke;u.scrollTop=Ue,J<1?requestAnimationFrame(ue):setTimeout(()=>{u.scrollTop=U},50)};requestAnimationFrame(ue)};M>3e3?u.scrollTo({top:D,behavior:"instant"}):K(D),k.classList.add("row--highlight"),setTimeout(()=>{k.classList.remove("row--highlight")},1500)}else x<10&&setTimeout(()=>w(x+1),150)};setTimeout(w,200)})}}else{const h=c.value.findIndex(u=>u[r]===d);h!==-1&&((g=s.value)!=null&&g.scrollToItem)&&s.value.scrollToItem(h)}Oe=null})},Ne=l=>{if(l){if(!p.value){setTimeout(()=>Ne(l),200);return}y.value=l,y.value!==m.value&&m.value&&(m.value._editing=!1,setTimeout(()=>{m.value=null},200))}},Le=(l,r)=>new Promise(d=>{var g,h;if(!((g=n==null?void 0:n.editConfig)!=null&&g.beforeEditMethod&&typeof((h=n==null?void 0:n.editConfig)==null?void 0:h.beforeEditMethod)=="function"&&!n.editConfig.beforeEditMethod({row:l}))){if(!l||!p.value){setTimeout(()=>Le(l),200);return}l!==m.value&&(c.value.forEach(u=>{u._editing&&t("edit-closed",{row:u,column:{field:r},$table:i==null?void 0:i.exposed}),u._editing=!1}),l._editing=!0,setTimeout(()=>{m.value=l,t("edit-activated",{row:l,column:{field:r},$table:i==null?void 0:i.exposed}),d(!0)}))}}),qn=l=>Le(l),Ze=()=>{if(ge(),n.pageConfig.enabled){const l=Array.from(H.value);if(l.length>0){const r=Math.min(...l);for(let d=Math.max(0,r-1);d<=Math.min(R.value.length-1,r+2);d++)j.value.add(d)}else for(let r=0;r<Math.min(3,R.value.length);r++)j.value.add(r);e.nextTick(()=>{ne()})}e.nextTick(()=>{!n.pageConfig.enabled&&s.value&&s.value.$forceUpdate&&s.value.$forceUpdate()})},Wn=(l,r)=>new Promise(d=>{let g=-1;if(r==-1){const h=ke(l.parent_id);for(g=c.value.findIndex(u=>u[n.rowConfig.keyField]==h[n.rowConfig.keyField])+1;c.value[g].parent_id==h[n.rowConfig.keyField];)g+=1}else g=c.value.findIndex(h=>h[n.rowConfig.keyField]==r[n.rowConfig.keyField]);C.set(l.node_id,l),_.set(l[n.rowConfig.keyField],l),c.value.splice(g,0,l),Ze(),d({row:l})}),Gn=(l,r)=>new Promise(d=>{const g=c.value.findIndex(h=>h[n.rowConfig.keyField]==r[n.rowConfig.keyField])+1;C.set(l.node_id,l),_.set(l[n.rowConfig.keyField],l),c.value.splice(g,0,l),Ze(),d({row:l})}),gt=l=>{const r=c.value.findIndex(d=>d[n.rowConfig.keyField]==l[n.rowConfig.keyField]||d===l);if(r>-1){const d=l[n.rowConfig.keyField];C.delete(l.node_id),_.delete(d),c.value.splice(r,1),Ze()}},Jn=(l,r)=>{if(!l||!l[n.rowConfig.keyField])return!1;const d=l._original;return d?r?l[r]!==d[r]:Object.keys(d).some(g=>d[g]!==l[g]):!1},Xn=l=>l&&l[n.rowConfig.keyField]&&!l._original,Yn=(l,r)=>{l&&l[n.rowConfig.keyField]&&(r&&Object.assign(l,r),l._original={...l,_editing:void 0,_X_ROW_CHILD:void 0,_original:void 0})},Zn=l=>{if(l&&l[n.rowConfig.keyField]){const r=ke(l[n.rowConfig.keyField]);r._original?Object.assign(r,r._original):gt(r)}},Qn=()=>{},eo=()=>{y.value={}},pt=l=>{var d,g,h;let r=c.value.findIndex(u=>u[n.rowConfig.keyField]==l[n.rowConfig.keyField]);if(r>-1&&n.treeConfig){const u=((d=n.treeConfig)==null?void 0:d.keyField)||((g=n.treeConfig)==null?void 0:g.rowField)||"node_id",w=((h=n.treeConfig)==null?void 0:h.parentField)||"parent_id",x=[],k=new Map;k.set(l[u],!0);for(let b=r+1;b<c.value.length;b++){const E=c.value[b];if(E&&k.has(E[w]))x.push(E),k.set(E[u]);else break}return x}return[]};a({isEditByRow:Vn,getParentRow:vn,getSiblingRow:jn,getNextRow:Kn,getRowById:ke,scrollToRow:Un,setCurrentRow:Ne,setEditRow:Le,setEditCell:qn,insertAt:Wn,insertNextAt:Gn,isUpdateByRow:Jn,isInsertByRow:Xn,reloadRow:Yn,revertData:Zn,remove:gt,setAllTreeExpand:Qn,clearCurrentRow:eo,getAllChilds:pt});const Se=e.computed(()=>o.default().filter(l=>{var r;return((r=l.type)==null?void 0:r.name)==="VirtualTableColumn"}).map(l=>{var r,d,g;return{prop:(r=l.props)==null?void 0:r.prop,title:(d=l.props)==null?void 0:d.title,width:(g=l.props)==null?void 0:g.width,slots:l.children}})),Ve=l=>{try{return l===0?{width:"0px"}:l?{flex:/^\d+$/.test(l)?`0 0 ${l}px`:`0 0 ${l}`}:{flex:"1 1 100%"}}catch(r){return console.warn("[VirtualTable] computeColumnWidth error:",r),{flex:"1 1 100%"}}},mt=e.computed(()=>{var l;return(l=n.treeConfig)!=null&&l.childCurrent&&y.value?pt(y.value).map(r=>r[n.rowConfig.keyField]):[]}),yt=e.ref({viewStartIndex:0,viewEndIndex:0,visibleStartIndex:0,visibleEndIndex:0});let ve=null,je=null;const to=(l,r)=>{ve&&cancelAnimationFrame(ve),ve=requestAnimationFrame(()=>{t("scroll-end",{...yt.value}),ve=null})},no=(l,r,d,g)=>{je&&cancelAnimationFrame(je),je=requestAnimationFrame(()=>{yt.value={viewStartIndex:l,viewEndIndex:r,visibleStartIndex:d,visibleEndIndex:g},je=null})},oo=(l,r)=>{var D,T;const{pageHeight:d,margin:g,showPageBorder:h,pageBorderPadding:u,pageBorderStyle:w,showPageHeader:x,headerHeight:k=0,footerHeight:b=0,showPageNumber:E}=n.pageConfig,P=l.pageNumber||r+1;return j.value.has(r)?e.createVNode(e.Fragment,null,[x!==!1&&(o["page-header"]||k>0)?e.createVNode("div",{class:"a4-page-header",style:{minHeight:`${Math.max(k,1)}px`}},[(D=o["page-header"])==null?void 0:D.call(o,{pageNumber:P,pageIndex:r,totalPages:R.value.length})]):null,r===0&&n.showHeader?e.createVNode("div",{class:"a4-table-header"},[e.createVNode("div",{class:"virtual-table-header we-vt-table--header we-vt-table--header-wrapper"},[Se.value.map(M=>{var K,U,z;return e.createVNode("div",{class:"we-vt-header--column",key:M.prop,style:Ve(M.width)},[e.createVNode("div",{class:"we-vt-cell"},[(K=M.slots)!=null&&K.header?(z=(U=M.slots)==null?void 0:U.header)==null?void 0:z.call(U,{column:M}):M.title])])})])]):null,e.createVNode("div",{class:"a4-page-content",style:{...h?{border:w,padding:`${u}px`}:{}}},[l.items.map(M=>{var K,U;return e.createVNode("div",{key:M[n.rowConfig.keyField],"data-id":M[n.rowConfig.keyField],class:{"virtual-table-row":!0,"we-vt-body--row":!0,"row--current":M[n.rowConfig.keyField]===((K=y.value)==null?void 0:K[n.rowConfig.keyField])||((U=n.treeConfig)==null?void 0:U.childCurrent)&&mt.value.includes(M[n.rowConfig.keyField])},style:{width:"100%"},onClick:()=>pe(M),onDblclick:()=>ae(M)},[Se.value.map(z=>{var de,be,Ee,Fe,ue,ee,$e;return e.createVNode("div",{key:z.prop,class:"virtual-table-cell we-vt-cell",style:Ve(z.width),"data-prop":z.prop},[M._editing&&((de=n.editConfig)==null?void 0:de.trigger)==="dblclick"?((be=z.slots)==null?void 0:be.edit)&&((Fe=(Ee=z.slots)==null?void 0:Ee.edit)==null?void 0:Fe.call(Ee,{row:M,column:z})):((ue=z.slots)==null?void 0:ue.default)&&(($e=(ee=z.slots)==null?void 0:ee.default)==null?void 0:$e.call(ee,{row:M,column:z}))])})])})]),o["page-footer"]?e.createVNode("div",{class:"a4-page-footer"},[(T=o["page-footer"])==null?void 0:T.call(o,{pageNumber:P,pageIndex:r,totalPages:R.value.length})]):e.createVNode("div",{class:"a4-page-footer",contenteditable:"false"},[E!==!1?e.createVNode("span",{class:"page-number",contenteditable:"false"},[P,e.createTextVNode(" / "),R.value.length]):null])]):e.createVNode("div",{class:"a4-page-loading"},[e.createVNode("div",{class:"loading-spinner"},null),e.createVNode("div",{class:"loading-text"},[e.createTextVNode("加载中...")])])},lo=()=>{var w;const{pageHeight:l,pageWidth:r,margin:d,gap:g,showPageBorder:h,pageBorderPadding:u}=n.pageConfig;return e.createVNode("div",{class:"virtual-table we-vt-table we-vt-table--render-default border--none"},[e.createVNode("div",{class:"a4-pages-container",contenteditable:((w=n.editConfig)==null?void 0:w.trigger)==="contenteditable"?"true":void 0,onContextmenu:v,onFocusin:G,onFocusout:Q},[R.value.map((x,k)=>{const b=j.value.has(k);return e.createVNode("div",{key:`page-${k}`,class:b?"a4-page":"a4-page-placeholder","data-page-index":k,style:{width:`${r}px`,minHeight:`${l}px`,marginBottom:`${g}px`,padding:b?`${h?d-u:d}px`:"0",paddingBottom:b?"12px":"0",boxSizing:"border-box",position:"relative"}},[oo(x,k)])})])])},ao=()=>{var l;return e.createVNode("div",{class:"virtual-table we-vt-table we-vt-table--render-default border--none"},[n.showHeader?e.createVNode("div",{class:"virtual-table-header we-vt-table--header we-vt-table--header-wrapper"},[Se.value.map(r=>{var d,g,h;return e.createVNode("div",{class:"we-vt-header--column",key:r.prop,style:Ve(r.width)},[e.createVNode("div",{class:"we-vt-cell"},[(d=r.slots)!=null&&d.header?(h=(g=r.slots)==null?void 0:g.header)==null?void 0:h.call(g,{column:r}):r.title]),e.createVNode("div",{class:"we-vt-resizable is--line"},null)])})]):void 0,e.createVNode(Ce.DynamicScroller,{ref:s,items:I.value,minItemSize:fe.value,keyField:n.rowConfig.keyField,emitUpdate:!1,buffer:300,class:"virtual-table-wrapper",contenteditable:((l=n.editConfig)==null?void 0:l.trigger)==="contenteditable"?"true":void 0,onContextmenu:v,onScrollend:to,onUpdate:no,onFocusin:G,onFocusout:Q},{default:({item:r,index:d,active:g})=>{var u,w,x;let h;return e.createVNode(Ce.DynamicScrollerItem,{key:r[n.rowConfig.keyField],item:r,active:g,sizeDependencies:[(u=r.content)==null?void 0:u.length,r._editing,r.content_type],"data-id":r[n.rowConfig.keyField],"data-index":d,"data-active":g,class:{"virtual-table-row":!0,"we-vt-body--row":!0,"row--current":r[n.rowConfig.keyField]===((w=y.value)==null?void 0:w[n.rowConfig.keyField])||((x=n.treeConfig)==null?void 0:x.childCurrent)&&mt.value.includes(r[n.rowConfig.keyField])}},Pt(h=Se.value.map(k=>{var b,E,P,D,T,M,K;return e.createVNode("div",{key:k.prop,class:"virtual-table-cell we-vt-cell",style:Ve(k.width),"data-prop":k.prop},[r._editing&&((b=n.editConfig)==null?void 0:b.trigger)==="dblclick"?((E=k.slots)==null?void 0:E.edit)&&((D=(P=k.slots)==null?void 0:P.edit)==null?void 0:D.call(P,{row:r,column:k})):((T=k.slots)==null?void 0:T.default)&&((K=(M=k.slots)==null?void 0:M.default)==null?void 0:K.call(M,{row:r,column:k}))])}))?h:{default:()=>[h]})}})])};return()=>n.pageConfig.enabled?lo():ao()}}),Be=(n,t)=>{const o=n.__vccOpts||n;for(const[a,i]of t)o[a]=i;return o},$t=Be(Lt,[["__scopeId","data-v-bd96f5fb"]]),zt={name:"VirtualTableColumn",props:{prop:String,label:String,width:[String,Number]}};function Rt(n,t,o,a,i,s){return e.renderSlot(n.$slots,"default")}const Dt=Be(zt,[["render",Rt]]),Ht={class:"catalog-node"},Ot=["title"],Nt={class:"catalog-node__text"},Vt={key:0,class:"catalog-node__children"},vt=Be({__name:"CatalogNode",props:{item:{type:Object,required:!0},depth:{type:Number,default:0},activeId:{type:String,default:""}},emits:["navigate"],setup(n,{emit:t}){const o=n,a=t,i=e.ref(!0),s=e.computed(()=>o.item.children&&o.item.children.length>0);function p(m){m.stopPropagation(),i.value=!i.value}return(m,y)=>{const c=e.resolveComponent("CatalogNode",!0);return e.openBlock(),e.createElementBlock("div",Ht,[e.createElementVNode("div",{class:e.normalizeClass(["catalog-node__label",{"is-active":n.activeId===n.item.nodeId}]),style:e.normalizeStyle({paddingLeft:10+n.depth*14+"px"}),title:n.item.name,onClick:y[0]||(y[0]=C=>a("navigate",n.item))},[e.createElementVNode("span",{class:"catalog-node__toggle",onClick:p},[s.value?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(i.value?e.unref(S.ChevronDown):e.unref(S.ChevronRight)),{key:0,size:14})):e.createCommentVNode("",!0)]),e.createElementVNode("span",Nt,e.toDisplayString(n.item.name||"(无标题)"),1)],14,Ot),s.value&&i.value?(e.openBlock(),e.createElementBlock("div",Vt,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.item.children,C=>(e.openBlock(),e.createBlock(c,{key:C.nodeId,item:C,depth:n.depth+1,"active-id":n.activeId,onNavigate:y[1]||(y[1]=_=>a("navigate",_))},null,8,["item","depth","active-id"]))),128))])):e.createCommentVNode("",!0)])}}},[["__scopeId","data-v-ac882917"]]),jt={key:0,class:"catalog catalog--collapsed"},Kt={key:1,class:"catalog"},Ut={class:"catalog__header"},qt={class:"catalog__title"},Wt={class:"catalog__body"},Gt={key:0,class:"catalog__empty"},Jt=Be({__name:"index",props:{items:{type:Array,default:()=>[]}},emits:["navigate"],setup(n,{emit:t}){const o=t,a=e.ref(!1),i=e.ref("");function s(p){i.value=p.nodeId,o("navigate",p)}return(p,m)=>a.value?(e.openBlock(),e.createElementBlock("div",jt,[e.createElementVNode("button",{class:"catalog__icon-btn",title:"展开目录",onClick:m[0]||(m[0]=y=>a.value=!1)},[e.createVNode(e.unref(S.PanelLeftOpen),{size:18})])])):(e.openBlock(),e.createElementBlock("div",Kt,[e.createElementVNode("div",Ut,[e.createElementVNode("span",qt,[e.createVNode(e.unref(S.ListTree),{size:16}),m[2]||(m[2]=e.createTextVNode(" 目录 ",-1))]),e.createElementVNode("button",{class:"catalog__icon-btn",title:"收起目录",onClick:m[1]||(m[1]=y=>a.value=!0)},[e.createVNode(e.unref(S.PanelLeftClose),{size:18})])]),e.createElementVNode("div",Wt,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.items,y=>(e.openBlock(),e.createBlock(vt,{key:y.nodeId,item:y,"active-id":i.value,onNavigate:s},null,8,["item","active-id"]))),128)),n.items.length?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",Gt," 暂无目录 "))])]))}},[["__scopeId","data-v-8becafa1"]]),Xt={first:1,second:2,third:3,fourth:4,fifth:5,sixth:6};function Yt(n){return n.blockType!=="title"||!n.level?0:Xt[n.level]||1}function Zt(n){const t=[];for(const i of n||[]){const s=Yt(i);s&&t.push({id:i.node_id,nodeId:i.node_id,name:(i.content||"").trim(),level:s,children:[]})}if(!t.length)return[];const o=(i,s)=>{const p=s.children[s.children.length-1];p&&i.level>p.level?o(i,p):s.children.push(i)},a=[];for(const i of t){const s=a[a.length-1];s&&i.level>s.level?o(i,s):a.push(i)}return a}const Qt={first:0,second:1,third:2,fourth:3,fifth:4,sixth:5,seventh:6,eighth:7};function ze(n,t){let o="",a=n;const i=t?65:97;for(;a>0;){const s=(a-1)%26;o=String.fromCharCode(i+s)+o,a=Math.floor((a-1)/26)}return o}const nt=[n=>n.toString(),n=>ze(n,!0),n=>`(${n})`,n=>`(${ze(n,!1)})`,n=>`${n})`,n=>`${ze(n,!1)})`,n=>`<${n}>`,n=>`<${ze(n,!1)}>`];function en(){const n=new Array(8).fill(0);return{next(t,o){const a=Qt[t];if(a==null)return"";n[a]++;for(let s=a+1;s<n.length;s++)n[s]=0;if(o!=null&&o!=="")return`${o} `;const i=nt[Math.min(a,nt.length-1)];return`${i(n[a])}. `}}}const Ie=14,ot=760,lt=756,tn={left:"left",center:"center",right:"right",alignment:"justify",justify:"justify"};function at(n){const t=[];let o=!1;const a=i=>{if(o){if(i&&i.value!=null&&/^[\n200B]+$/.test(i.value)){t.push(i);return}o=!1,t.push({...i,_coverBreakBefore:!0})}else t.push(i)};for(const i of n||[]){if(i&&i.type==="pageBreak"){o=!0;continue}if(i&&i.type==="area"){const s=at(i.valueList||[]),p=(i.areaId||"").includes("cover");for(const m of s)a(m);p&&(o=!0)}else a(i)}return t}function Te(n){const t=at(n),o=[];let a=[],i=0,s=null;const p=y=>{a.length&&(o.push({type:"paragraph",elements:[...a],rowFlex:y}),a=[])},m=()=>{if(i===0)return;const y=s;p(y);for(let c=1;c<i;c++)o.push({type:"paragraph",elements:[],rowFlex:y});i=0,s=null};for(const y of t||[])if(y.type==="table")m(),p(),o.push({type:"table",el:y});else if(y.type==="title")m(),p(),o.push({type:"title",el:y});else if(y.type==="list"){m(),p();const c=[];let C=[];for(const _ of y.valueList||[])_.value===`
2
+ `||_.value==="​"?(c.push([...C]),C=[]):C.push(_);(C.length||c.length===0)&&c.push([...C]),o.push({type:"list",listType:y.listType||"ul",listStyle:y.listStyle||"disc",items:c})}else if(y.listId){m(),p();const c=y.value==="​"||y.value===""?[]:[y];o.push({type:"list",listType:y.listType||"ul",listStyle:y.listStyle||"disc",items:[c]})}else y.value!=null&&/^[\n200B]+$/.test(y.value)?(i+=y.value.length,y.rowFlex&&(s=y.rowFlex)):(m(),a.push(y));return m(),p(),o}function Me(n){const t=n.filter(c=>c.type==="image").reduce((c,C)=>c+(C.height||C.width||0),0),o=n.filter(c=>c.type!=="image").map(c=>c.value||"").join("");if(!o)return t||20;const a=n.reduce((c,C)=>Math.max(c,C.size||0),0)||14,i=a+6,s=(o.match(/[一-龥]/g)||[]).length,p=o.length-s,m=s*a+p*(a*.5),y=Math.max(1,Math.ceil(m/ot));return t+Math.max(i,y*i)}function nn(n){if(!n||!n.length)return[[]];const t=[];let o=[];for(const a of n)a.type==="image"&&(a.width||0)>=ot?(o.length&&(t.push(o),o=[]),t.push([a])):o.push(a);return o.length&&t.push(o),t.length?t:[[]]}function it(n){if(n.length===0)return[];const t=new Array(n.length).fill(0);n.forEach((s,p)=>{(s.tdList||[]).forEach(m=>{const y=m.rowspan||1;if(y>1){const c=Math.min(p+y-1,n.length-1);t[p]=Math.max(t[p],c);for(let C=1;C<y&&p+C<n.length;C++)t[p+C]=Math.max(t[p+C],c)}})});const o=[];let a=0,i=0;for(let s=0;s<n.length;s++)i=Math.max(i,t[s]),i<=s&&(o.push(n.slice(a,s+1)),a=s+1,i=0);return a<n.length&&o.push(n.slice(a)),o}function qe(n){const t=(n==null?void 0:n.width)||0;return!t||t<=lt?1:lt/t}function rt(n){var s,p;const t=n.elements||[],o=((s=t.find(m=>m.rowFlex))==null?void 0:s.rowFlex)||n.rowFlex,a={textAlign:tn[o]||"left"},i=(p=t.find(m=>m.rowMargin))==null?void 0:p.rowMargin;return i&&(a.lineHeight=i),a}function on(n){var s;const t=Te(n.value);let o=0,a=0,i=!1;for(const p of t)if(p.type==="paragraph"){if(!p.elements.length)continue;o++;for(const m of p.elements)(m.type==="image"||m.type==="table")&&(i=!0),a+=(m.value||"").length}else p.type==="list"?(o+=((s=p.items)==null?void 0:s.length)||1,i=!0):(o++,i=!0);return o>1||a>30||i?"top":n.verticalAlign||"middle"}function re(n){const t={};n.font&&(t.fontFamily=n.font),t.fontSize=(n.size||Ie)+"px",n.bold!=null&&(t.fontWeight=n.bold?"bold":"normal"),n.italic!=null&&(t.fontStyle=n.italic?"italic":"normal"),n.color&&(t.color=n.color),n.highlight&&n.highlight!=="rgb(255, 255, 255)"&&n.highlight!=="#ffffff"&&(t.backgroundColor=n.highlight);const o=[n.underline&&"underline",n.strikeout&&"line-through"].filter(Boolean).join(" ");return o&&(t.textDecoration=o),n.letterSpacing&&(t.letterSpacing=n.letterSpacing+"px"),t}const ln=5;function st(n,t=!1){var a,i;let o=0;for(const s of n)if(s.type==="table"){const p=((a=s.el)==null?void 0:a.trList)||[];o+=p.reduce((m,y)=>m+(y.height||y.minHeight||35),0)}else if(s.type==="title")o+=Me(s.titleValueList||((i=s.el)==null?void 0:i.valueList)||[]);else if(s.type==="paragraph")o+=Me(s.elements||[]);else if(s.type==="list"){const p=Math.round(18),m=(s.items||[]).reduce((y,c)=>y+(c.length?Me(c):p),0);o+=Math.max(m,p)}return o+(t&&o>0?ln:0)}const an={key:0,class:"empty-line"},rn=["href"],sn=["src"],cn=["checked"],dn=["checked"],hn={key:4,class:"ctrl-input"},fn=["checked"],un=["checked"],gn={key:0},pn=["colspan","rowspan"],mn={key:0},yn=["src"],kn=["href"],bn=["checked"],_n=["checked"],wn=["checked"],We=Be({__name:"DocBlock",props:{block:{type:Object,required:!0},isHeaderFooter:{type:Boolean,default:!1}},setup(n){const t=n,o=e.inject("bindTableObserver",null),a=e.inject("resolveImageUrl",null);function i(p){if(!p)return"";const m=(a==null?void 0:a.value)||a;return typeof m=="function"?m(p):p}const s=e.computed(()=>t.isHeaderFooter?0:t.block.indentPx??0);return(p,m)=>{var y;return n.block.blockType==="title"?(e.openBlock(),e.createElementBlock("p",{key:0,class:e.normalizeClass(["doc-title",`doc-title--${n.block.level}`]),style:e.normalizeStyle({paddingLeft:s.value?s.value+"px":void 0})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.block.titleValueList||[],(c,C)=>(e.openBlock(),e.createElementBlock("span",{key:C,style:e.normalizeStyle(e.unref(re)(c))},e.toDisplayString(c.value),5))),128))],6)):n.block.blockType==="paragraph"?(e.openBlock(),e.createElementBlock("p",{key:1,class:"doc-para",style:e.normalizeStyle({...e.unref(rt)(n.block),paddingLeft:s.value?s.value+"px":void 0})},[n.block.elements.length?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("span",an," ")),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.block.elements,(c,C)=>{var _,R,H,j,F,O,A,f,B,$,I,q,fe;return e.openBlock(),e.createElementBlock(e.Fragment,{key:C},[!c.type||c.type==="text"?(e.openBlock(),e.createElementBlock("span",{key:0,style:e.normalizeStyle(e.unref(re)(c))},e.toDisplayString(c.value),5)):c.type==="hyperlink"?(e.openBlock(),e.createElementBlock("a",{key:1,href:c.url,class:"doc-link",target:"_blank",rel:"noopener"},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(c.valueList||[],(L,X)=>(e.openBlock(),e.createElementBlock("span",{key:X,style:e.normalizeStyle(e.unref(re)(L))},e.toDisplayString(L.value),5))),128))],8,rn)):c.type==="image"?(e.openBlock(),e.createElementBlock("img",{key:2,src:i(c.value),class:"doc-image",style:e.normalizeStyle({width:c.width?c.width+"px":"auto",height:c.height?c.height+"px":"auto"})},null,12,sn)):c.type==="control"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:3},[((_=c.control)==null?void 0:_.type)==="text"?(e.openBlock(),e.createElementBlock("span",{key:0,style:e.normalizeStyle({fontSize:(c.control.size||12)+"px"})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(c.control.value||[],(L,X)=>(e.openBlock(),e.createElementBlock("span",{key:X,style:e.normalizeStyle(e.unref(re)(L))},e.toDisplayString(L.value),5))),128))],4)):((R=c.control)==null?void 0:R.type)==="input"?(e.openBlock(),e.createElementBlock("span",{key:1,class:"ctrl-input",style:e.normalizeStyle({minWidth:(c.control.minWidth||60)+"px",fontSize:(c.control.size||12)+"px"})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(c.control.value||[],(L,X)=>(e.openBlock(),e.createElementBlock("span",{key:X},e.toDisplayString(L.value),1))),128))],4)):((H=c.control)==null?void 0:H.type)==="radio"?(e.openBlock(),e.createElementBlock("span",{key:2,class:e.normalizeClass(["ctrl-options",{"ctrl-options--vertical":((F=(j=c.control.extension)==null?void 0:j.elementAttributes)==null?void 0:F.layout)==="vertical"}]),style:e.normalizeStyle({fontSize:(c.control.size||e.unref(Ie))+"px"})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(c.control.valueSets||[],(L,X)=>(e.openBlock(),e.createElementBlock("label",{key:X,class:"ctrl-option"},[e.createElementVNode("input",{type:"radio",disabled:"",checked:c.control.code===L.code},null,8,cn),e.createTextVNode(" "+e.toDisplayString(L.value),1)]))),128))],6)):((O=c.control)==null?void 0:O.type)==="checkbox"?(e.openBlock(),e.createElementBlock("span",{key:3,class:e.normalizeClass(["ctrl-options",{"ctrl-options--vertical":((f=(A=c.control.extension)==null?void 0:A.elementAttributes)==null?void 0:f.layout)==="vertical"}]),style:e.normalizeStyle({fontSize:(c.control.size||e.unref(Ie))+"px"})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(c.control.valueSets||[],(L,X)=>(e.openBlock(),e.createElementBlock("label",{key:X,class:"ctrl-option"},[e.createElementVNode("input",{type:"checkbox",disabled:"",checked:(c.control.code||"").split(",").includes(L.code)},null,8,dn),e.createTextVNode(" "+e.toDisplayString(L.value),1)]))),128))],6)):((B=c.control)==null?void 0:B.type)==="select"?(e.openBlock(),e.createElementBlock("span",hn,e.toDisplayString(((I=($=c.control.value)==null?void 0:$[0])==null?void 0:I.value)||c.control.placeholder||""),1)):e.createCommentVNode("",!0)],64)):c.type==="checkbox"?(e.openBlock(),e.createElementBlock("input",{key:4,type:"checkbox",checked:!!((q=c.checkbox)!=null&&q.value),disabled:"",class:"el-check"},null,8,fn)):c.type==="radio"?(e.openBlock(),e.createElementBlock("input",{key:5,type:"radio",checked:!!((fe=c.radio)!=null&&fe.value),disabled:"",class:"el-check"},null,8,un)):c.type==="superscript"?(e.openBlock(),e.createElementBlock("sup",{key:6,style:e.normalizeStyle(e.unref(re)(c))},e.toDisplayString(c.value),5)):c.type==="subscript"?(e.openBlock(),e.createElementBlock("sub",{key:7,style:e.normalizeStyle(e.unref(re)(c))},e.toDisplayString(c.value),5)):c.type==="tab"?(e.openBlock(),e.createElementBlock("span",{key:8,class:"doc-tab",style:e.normalizeStyle({width:(c.size||e.unref(Ie))+"px"})},null,4)):e.createCommentVNode("",!0)],64)}),128))],4)):n.block.blockType==="list"?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(n.block.listType==="ol"?"ol":"ul"),{key:2,class:"doc-list",style:e.normalizeStyle({listStyleType:n.block.listStyle==="decimal"?"decimal":n.block.listStyle==="lower-alpha"?"lower-alpha":"disc",paddingLeft:s.value?s.value+24+"px":void 0})},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.block.items,(c,C)=>(e.openBlock(),e.createElementBlock("li",{key:C,class:"doc-list-item"},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(c,(_,R)=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:R},[!_.type||_.type==="text"?(e.openBlock(),e.createElementBlock("span",{key:0,style:e.normalizeStyle(e.unref(re)(_))},e.toDisplayString(_.value),5)):_.type==="superscript"?(e.openBlock(),e.createElementBlock("sup",{key:1,style:e.normalizeStyle(e.unref(re)(_))},e.toDisplayString(_.value),5)):_.type==="subscript"?(e.openBlock(),e.createElementBlock("sub",{key:2,style:e.normalizeStyle(e.unref(re)(_))},e.toDisplayString(_.value),5)):e.createCommentVNode("",!0)],64))),128))]))),128))]),_:1},8,["style"])):n.block.blockType==="table-row-group"?(e.openBlock(),e.createElementBlock("div",{key:3,class:e.normalizeClass(["doc-table-row-wrap",{"is-first":n.block.isFirst,"is-last":n.block.isLast,"is-page-break":n.block.isPageBreak}]),style:e.normalizeStyle({display:n.block.tableRowFlex?"flex":void 0,justifyContent:n.block.tableRowFlex==="right"?"flex-end":n.block.tableRowFlex==="center"?"center":n.block.tableRowFlex==="left"?"flex-start":void 0,paddingLeft:s.value?s.value+"px":void 0})},[e.createElementVNode("div",{style:e.normalizeStyle({overflow:n.block.sliceHeight!=null?"hidden":void 0,height:n.block.sliceHeight!=null?(n.block.isLast?n.block.sliceHeight+1:n.block.sliceHeight)+"px":void 0,width:n.block.tableEl.width?"max-content":"100%"})},[e.createElementVNode("table",{ref:n.block._baseKey&&e.unref(o)?c=>e.unref(o)(c,n.block._baseKey):void 0,class:e.normalizeClass(["doc-table",{"doc-table--no-border":n.block.tableEl.borderType==="empty","doc-table--header-footer":n.isHeaderFooter}]),style:e.normalizeStyle({width:n.block.tableEl.width?(n.isHeaderFooter?n.block.tableEl.width:n.block.tableEl.width*e.unref(qe)(n.block.tableEl))+"px":"100%",transform:n.block.sliceOffset?`translateY(-${n.block.sliceOffset}px)`:void 0})},[(y=n.block.tableEl.colgroup)!=null&&y.length?(e.openBlock(),e.createElementBlock("colgroup",gn,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.block.tableEl.colgroup,(c,C)=>(e.openBlock(),e.createElementBlock("col",{key:C,style:e.normalizeStyle({width:(n.isHeaderFooter?c.width:c.width*e.unref(qe)(n.block.tableEl))+"px"})},null,4))),128))])):e.createCommentVNode("",!0),e.createElementVNode("tbody",null,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.block.trGroup,(c,C)=>(e.openBlock(),e.createElementBlock("tr",{key:C,style:e.normalizeStyle({height:(c.height||c.minHeight||30)+"px"})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(c.tdList||[],(_,R)=>(e.openBlock(),e.createElementBlock("td",{key:R,colspan:_.colspan||1,rowspan:_.rowspan||1,style:e.normalizeStyle({backgroundColor:_.backgroundColor||void 0,verticalAlign:e.unref(on)(_),width:_.width?_.width*e.unref(qe)(n.block.tableEl)+"px":void 0,height:_.height?_.height+"px":void 0})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(Te)(_.value),(H,j)=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:j},[H.type==="paragraph"?(e.openBlock(),e.createElementBlock("p",{key:0,class:"cell-para",style:e.normalizeStyle(e.unref(rt)(H))},[H.elements.length?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("span",mn," ")),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(H.elements,(F,O)=>{var A,f,B,$,I,q,fe;return e.openBlock(),e.createElementBlock(e.Fragment,{key:O},[!F.type||F.type==="text"?(e.openBlock(),e.createElementBlock("span",{key:0,style:e.normalizeStyle(e.unref(re)(F))},e.toDisplayString(F.value),5)):F.type==="image"?(e.openBlock(),e.createElementBlock("img",{key:1,src:i(F.value),class:"doc-image",style:e.normalizeStyle({width:F.width?F.width+"px":"auto",height:F.height?F.height+"px":"auto"})},null,12,yn)):F.type==="hyperlink"?(e.openBlock(),e.createElementBlock("a",{key:2,href:F.url,class:"doc-link",target:"_blank"},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(F.valueList||[],(L,X)=>(e.openBlock(),e.createElementBlock("span",{key:X,style:e.normalizeStyle(e.unref(re)(L))},e.toDisplayString(L.value),5))),128))],8,kn)):F.type==="control"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:3},[((A=F.control)==null?void 0:A.type)==="text"?(e.openBlock(),e.createElementBlock("span",{key:0,style:e.normalizeStyle({fontSize:(F.control.size||12)+"px"})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(F.control.value||[],(L,X)=>(e.openBlock(),e.createElementBlock("span",{key:X,style:e.normalizeStyle(e.unref(re)(L))},e.toDisplayString(L.value),5))),128))],4)):((f=F.control)==null?void 0:f.type)==="input"?(e.openBlock(),e.createElementBlock("span",{key:1,class:"ctrl-input",style:e.normalizeStyle({fontSize:(F.control.size||12)+"px"})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(F.control.value||[],(L,X)=>(e.openBlock(),e.createElementBlock("span",{key:X},e.toDisplayString(L.value),1))),128))],4)):((B=F.control)==null?void 0:B.type)==="radio"?(e.openBlock(),e.createElementBlock("span",{key:2,class:e.normalizeClass(["ctrl-options",{"ctrl-options--vertical":((I=($=F.control.extension)==null?void 0:$.elementAttributes)==null?void 0:I.layout)==="vertical"}])},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(F.control.valueSets||[],(L,X)=>(e.openBlock(),e.createElementBlock("label",{key:X,class:"ctrl-option"},[e.createElementVNode("input",{type:"radio",disabled:"",checked:F.control.code===L.code},null,8,bn),e.createTextVNode(e.toDisplayString(L.value),1)]))),128))],2)):e.createCommentVNode("",!0)],64)):F.type==="checkbox"?(e.openBlock(),e.createElementBlock("input",{key:4,type:"checkbox",checked:!!((q=F.checkbox)!=null&&q.value),disabled:"",class:"el-check"},null,8,_n)):F.type==="radio"?(e.openBlock(),e.createElementBlock("input",{key:5,type:"radio",checked:!!((fe=F.radio)!=null&&fe.value),disabled:"",class:"el-check"},null,8,wn)):F.type==="superscript"?(e.openBlock(),e.createElementBlock("sup",{key:6,style:e.normalizeStyle(e.unref(re)(F))},e.toDisplayString(F.value),5)):F.type==="subscript"?(e.openBlock(),e.createElementBlock("sub",{key:7,style:e.normalizeStyle(e.unref(re)(F))},e.toDisplayString(F.value),5)):F.type==="tab"?(e.openBlock(),e.createElementBlock("span",{key:8,class:"doc-tab",style:e.normalizeStyle({width:(F.size||e.unref(Ie))+"px"})},null,4)):e.createCommentVNode("",!0)],64)}),128))],4)):e.createCommentVNode("",!0)],64))),128))],12,pn))),128))],4))),128))])],6)],4)],6)):e.createCommentVNode("",!0)}}},[["__scopeId","data-v-88bdb013"]]),xn={class:"editor-layout word-editor-scope"},En={class:"editor-container"},Cn={key:0,class:"editor-loading"},Bn={class:"doc-header"},Mn={class:"doc-footer"},Sn={class:"doc-page-number"},Fn=1123,In=50,Tn=20,An=Be({__name:"index",props:{data:{type:Array,default:()=>[]},loading:{type:Boolean,default:!1},resolveImageUrl:{type:Function,default:null}},setup(n){const t=n,o=e.computed(()=>{const f=t.data;return f?!Array.isArray(f)&&f.main?f.main:Array.isArray(f)?f:[]:[]}),a=e.ref(null),i=e.ref({});let s=null;e.onMounted(()=>{s=new ResizeObserver(f=>{const B={};for(const $ of f){const I=$.target._rowKey;if(!I)continue;const q=Math.round($.contentRect.height);q>(i.value[I]||0)&&(B[I]=q)}Object.keys(B).length&&(i.value={...i.value,...B})})}),e.onUnmounted(()=>{s==null||s.disconnect(),s=null});function p(f,B){!f||!s||(f._rowKey=B,s.observe(f))}e.provide("bindTableObserver",p),e.provide("resolveImageUrl",e.toRef(t,"resolveImageUrl"));const m=e.computed(()=>Math.max(100,Fn-In*2-_.value-Tn)),y=e.computed(()=>{const f=Te(o.value),B=[],$=m.value;let I=0;const q=en(),fe={first:0,second:1,third:2,fourth:3,fifth:4,sixth:5,seventh:6,eighth:7};let L=-1;const X=v=>{var le,se,ge;return!!((le=v.el)!=null&&le._coverBreakBefore||(ge=(se=v.elements)==null?void 0:se[0])!=null&&ge._coverBreakBefore)};return f.forEach((v,le)=>{var ge,Pe,we,Ye;const se=X(v);if(se&&(I=0),v.type==="title"){const ce=v.el.valueList||[],te=q.next(v.el.level,(ge=v.el.extension)==null?void 0:ge.startIndex),ne=ce.some(Z=>{var oe;return(oe=Z.extension)==null?void 0:oe.isIndex});let he=ce;if(!ne&&te){const Z=ce[0]||{};he=[{value:te,size:Z.size,bold:Z.bold,italic:Z.italic,color:Z.color,font:Z.font,extension:{isIndex:!0}},...ce]}const pe=he.map(Z=>Z.value||"").join(""),ae=Me(he);I=I+ae>$&&I>0?ae:I+ae,L=fe[v.el.level]??0,B.push({node_id:`blk_${le}_0`,layer:se?1:100,blockType:"title",level:v.el.level,titleEl:v.el,titleValueList:he,content_type:"text",content:pe,height:ae,indentPx:L*20})}else if(v.type==="paragraph"){const ce=nn(v.elements),te=L>=0?(L+1)*20:0;ce.forEach((ne,he)=>{const pe=ne.map(Z=>Z.value||"").join(""),ae=Me(ne);I=I+ae>$&&I>0?ae:I+ae,B.push({node_id:`blk_${le}_${he}`,layer:se&&he===0?1:100,blockType:"paragraph",elements:ne,rowFlex:v.rowFlex,content_type:"text",content:pe,height:ae,indentPx:te})})}else if(v.type==="table"){const ce=!!((Pe=v.el.extension)!=null&&Pe.isTitleTable),te=((we=v.el.extension)==null?void 0:we.elementType)==="signOff",ne=((Ye=v.el.extension)==null?void 0:Ye.elementType)==="stepTable",he=te||ne,pe=ce||te?0:L>=0?(L+1)*20:0,ae=it(v.el.trList||[]),Z=ae.length;if(he){const oe=ae.flat(),ie=oe.reduce((W,G)=>W+(G.height||G.minHeight||35),0),me=`blk_${le}_0`,N=Math.max(ie,i.value[me]||0);if(I>0&&I+N>$&&(I=0),N>$){const W=Math.ceil(N/$);for(let G=0;G<W;G++){const Q=G*$,ye=Math.min($,N-Q),xe=G>0||I>0;I=ye,B.push({node_id:`blk_${le}_0_s${G}`,layer:se&&G===0?1:100,blockType:"table-row-group",content_type:"table-row",rowHeight:N,trGroup:oe,tableEl:v.el,tableRowFlex:v.el.rowFlex||null,isFirst:G===0,isLast:G===W-1,isPageBreak:xe,sliceOffset:Q,sliceHeight:ye,_baseKey:G===0?me:void 0,height:ye,indentPx:pe})}}else{const W=I>0;I=I+N>$?N:I+N,B.push({node_id:`blk_${le}_0`,layer:se?1:100,blockType:"table-row-group",content_type:"table-row",rowHeight:N,trGroup:oe,tableEl:v.el,tableRowFlex:v.el.rowFlex||null,isFirst:!0,isLast:!0,isPageBreak:W,indentPx:pe})}}else ae.forEach((oe,ie)=>{const me=`blk_${le}_${ie}`,N=oe.reduce((G,Q)=>G+(Q.height||Q.minHeight||35),0),W=Math.max(N,i.value[me]||0);if(W>$){const G=Math.ceil(W/$);for(let Q=0;Q<G;Q++){const ye=Q*$,xe=Math.min($,W-ye),He=Q>0||I>0;I=xe,B.push({node_id:`blk_${le}_${ie}_s${Q}`,layer:se&&ie===0&&Q===0?1:100,blockType:"table-row-group",content_type:"table-row",rowHeight:W,trGroup:oe,tableEl:v.el,tableRowFlex:v.el.rowFlex||null,isFirst:ie===0&&Q===0,isLast:ie===Z-1&&Q===G-1,isPageBreak:He,sliceOffset:ye,sliceHeight:xe,_baseKey:Q===0?me:void 0,height:xe,indentPx:pe})}}else{const G=ie>0&&I+W>$;I=I+W>$?W:I+W,B.push({node_id:`blk_${le}_${ie}`,layer:se&&ie===0?1:100,blockType:"table-row-group",content_type:"table-row",rowHeight:W,trGroup:oe,tableEl:v.el,tableRowFlex:v.el.rowFlex||null,isFirst:ie===0,isLast:ie===Z-1,isPageBreak:G,indentPx:pe})}})}else if(v.type==="list"){const ce=Math.round(18);let te=0;for(const ne of v.items)te+=ne.length?Me(ne):ce;te=Math.max(te,ce),I=I+te>$&&I>0?te:I+te,B.push({node_id:`blk_${le}_0`,layer:se?1:100,blockType:"list",listType:v.listType,listStyle:v.listStyle,items:v.items,height:te,indentPx:L>=0?(L+1)*20:0})}}),B}),c=e.computed(()=>{var B;const f=(B=t.data)==null?void 0:B.header;return f!=null&&f.length?Te(f):[]}),C=e.computed(()=>{var B;const f=(B=t.data)==null?void 0:B.footer;return f!=null&&f.length?Te(f):[]}),_=e.computed(()=>st(c.value,!0)),R=e.computed(()=>st(C.value,!0)),H=e.computed(()=>c.value.length>0),j=e.computed(()=>C.value.length>0);function F(f){var $,I,q;const B=f.type==="table";return{blockType:B?"table-row-group":f.type,elements:f.elements,rowFlex:f.rowFlex,level:($=f.el)==null?void 0:$.level,titleValueList:((I=f.el)==null?void 0:I.valueList)||f.titleValueList,listType:f.listType,listStyle:f.listStyle,items:f.items,indentPx:0,trGroup:B?it(f.el.trList).flat():void 0,tableEl:B?f.el:void 0,isFirst:!0,isLast:!0,tableRowFlex:((q=f.el)==null?void 0:q.rowFlex)||null}}const O=e.computed(()=>Zt(y.value));function A(f){var B;(B=a.value)==null||B.scrollToRow({node_id:f.nodeId})}return(f,B)=>(e.openBlock(),e.createElementBlock("div",xn,[e.createVNode(Jt,{items:O.value,onNavigate:A},null,8,["items"]),e.createElementVNode("div",En,[n.loading?(e.openBlock(),e.createElementBlock("div",Cn," 加载中… ")):(e.openBlock(),e.createBlock(e.unref($t),{key:1,ref_key:"virtualTableRef",ref:a,"show-header":!1,"row-config":{keyField:"node_id"},"page-config":{enabled:!0,pageHeight:1123,pageWidth:860,margin:50,gap:16,showPageHeader:H.value,showPageBorder:!0,pageBorderPadding:5,pageBorderStyle:"1px solid #333",headerHeight:_.value,footerHeight:R.value,showPageNumber:!0},data:y.value},e.createSlots({default:e.withCtx(()=>[e.createVNode(e.unref(Dt),null,{default:e.withCtx(({row:$})=>[e.createVNode(We,{block:$},null,8,["block"])]),_:1})]),_:2},[H.value?{name:"page-header",fn:e.withCtx(()=>[e.createElementVNode("div",Bn,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(c.value,($,I)=>(e.openBlock(),e.createBlock(We,{key:I,block:F($),"is-header-footer":!0},null,8,["block"]))),128))])]),key:"0"}:void 0,j.value?{name:"page-footer",fn:e.withCtx(({pageNumber:$,totalPages:I})=>[e.createElementVNode("div",Mn,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(C.value,(q,fe)=>(e.openBlock(),e.createBlock(We,{key:fe,block:F(q),"is-header-footer":!0},null,8,["block"]))),128)),e.createElementVNode("div",Sn,e.toDisplayString($)+" / "+e.toDisplayString(I),1)])]),key:"1"}:void 0]),1032,["page-config","data"]))])]))}},[["__scopeId","data-v-c0e32534"]]),ct="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";function Re(n=10){const t=crypto.getRandomValues(new Uint8Array(n));return Array.from(t).map(o=>ct[o%ct.length]).join("")}class De{constructor(t){V(this,"data");this.data=e.reactive({id:Re(),version:1,sections:[this.createEmptySection()],pageWidth:595,pageHeight:842,marginTop:72,marginBottom:72,marginLeft:90,marginRight:90,...t})}createEmptySection(){return{id:Re(),paragraphs:[this.createEmptyParagraph()]}}createEmptyParagraph(t){return{id:Re(),type:"paragraph",format:t??{},children:[]}}createTextElement(t,o){return{id:Re(),type:"text",value:t,format:o??{}}}getSectionCount(){return this.data.sections.length}getParagraphCount(t=0){var o;return((o=this.data.sections[t])==null?void 0:o.paragraphs.length)??0}getAllParagraphs(){const t=[];return this.data.sections.forEach((o,a)=>{o.paragraphs.forEach((i,s)=>{t.push({paragraph:i,sectionIndex:a,paragraphIndex:s})})}),t}getParagraphAt(t,o){var a;return((a=this.data.sections[t])==null?void 0:a.paragraphs[o])??null}getElementAt(t){const o=this.getParagraphAt(t.sectionIndex,t.paragraphIndex);return(o==null?void 0:o.children[t.elementIndex])??null}insertText(t,o,a){const i=this.getParagraphAt(t.sectionIndex,t.paragraphIndex);if(!i)return;const s=i.children[t.elementIndex];if(s&&s.type==="text")s.value=s.value.slice(0,t.offset)+o+s.value.slice(t.offset);else{const p=this.createTextElement(o,a);i.children.splice(t.elementIndex,0,p)}this.bumpVersion()}deleteAt(t,o){const a=this.getParagraphAt(t.sectionIndex,t.paragraphIndex);if(!a)return;const i=a.children[t.elementIndex];!i||i.type!=="text"||(i.value=i.value.slice(0,t.offset)+i.value.slice(t.offset+o),i.value===""&&a.children.splice(t.elementIndex,1),this.bumpVersion())}insertParagraph(t,o,a){const i=this.data.sections[t];if(!i)throw new Error(`Section ${t} not found`);const s=this.createEmptyParagraph(a);return i.paragraphs.splice(o+1,0,s),this.bumpVersion(),s}mergeParagraphs(t,o){const a=this.data.sections[t];if(!a)return;const i=a.paragraphs[o],s=a.paragraphs[o+1];!i||!s||(i.children.push(...s.children),a.paragraphs.splice(o+1,1),this.bumpVersion())}updateParagraphFormat(t,o,a){const i=this.getParagraphAt(t,o);i&&(i.format={...i.format,...a},this.bumpVersion())}updateElementFormat(t,o){const a=this.getElementAt(t);a&&(a.format={...a.format,...o},this.bumpVersion())}updateRangeFormat(t,o,a){const i=this.getAllParagraphs();let s=!1;for(const{paragraph:p,sectionIndex:m,paragraphIndex:y}of i){const c=m===t.sectionIndex&&y===t.paragraphIndex,C=m===o.sectionIndex&&y===o.paragraphIndex;if(c&&(s=!0),s)for(let _=0;_<p.children.length;_++){const R=p.children[_];if(!(c&&_<t.elementIndex)){if(C&&_>o.elementIndex)break;R.format={...R.format,...a}}}if(C)break}this.bumpVersion()}bumpVersion(){this.data.version++}toJSON(){return JSON.stringify(this.data,null,2)}static fromJSON(t){const o=JSON.parse(t),a=new De;return Object.assign(a.data,o),a}}function _e(n=0,t=0,o=0,a=0){return{sectionIndex:n,paragraphIndex:t,elementIndex:o,offset:a}}function dt(n,t){return n.sectionIndex===t.sectionIndex&&n.paragraphIndex===t.paragraphIndex&&n.elementIndex===t.elementIndex&&n.offset===t.offset}class Ge{constructor(t){V(this,"_selection",e.reactive({anchor:_e(),focus:_e(),isCollapsed:!0}));V(this,"_docModel");V(this,"hasSelection",e.computed(()=>!this._selection.isCollapsed));this._docModel=t}get selection(){return this._selection}setCursor(t){this._selection.anchor={...t},this._selection.focus={...t},this._selection.isCollapsed=!0}setSelection(t,o){this._selection.anchor={...t},this._selection.focus={...o},this._selection.isCollapsed=dt(t,o)}collapse(t=!0){t?this._selection.anchor={...this._selection.focus}:this._selection.focus={...this._selection.anchor},this._selection.isCollapsed=!0}selectAll(){const t=this._docModel.data.sections,o=t[t.length-1],a=o==null?void 0:o.paragraphs[o.paragraphs.length-1],i=a==null?void 0:a.children[a.children.length-1],s=(i==null?void 0:i.type)==="text"?i.value.length:0;this._selection.anchor=_e(0,0,0,0),this._selection.focus=_e(t.length-1,((o==null?void 0:o.paragraphs.length)??1)-1,((a==null?void 0:a.children.length)??0)===0?0:((a==null?void 0:a.children.length)??1)-1,s),this._selection.isCollapsed=!1}moveForward(t=!1){const o=this._selection.focus,a=this._docModel.getParagraphAt(o.sectionIndex,o.paragraphIndex);if(!a)return;const i=a.children[o.elementIndex];if((i==null?void 0:i.type)==="text"&&o.offset<i.value.length){const p={...o,offset:o.offset+1};this._applyMove(p,t);return}if(o.elementIndex<a.children.length-1){const p={...o,elementIndex:o.elementIndex+1,offset:0};this._applyMove(p,t);return}const s=this._getNextParagraphPoint(o);s&&this._applyMove(s,t)}moveBackward(t=!1){const o=this._selection.focus;if(o.offset>0){const i={...o,offset:o.offset-1};this._applyMove(i,t);return}if(o.elementIndex>0){const i=this._docModel.getParagraphAt(o.sectionIndex,o.paragraphIndex),s=i==null?void 0:i.children[o.elementIndex-1],p=(s==null?void 0:s.type)==="text"?s.value.length:0,m={...o,elementIndex:o.elementIndex-1,offset:p};this._applyMove(m,t);return}const a=this._getPrevParagraphPoint(o);a&&this._applyMove(a,t)}_applyMove(t,o){o?(this._selection.focus=t,this._selection.isCollapsed=dt(this._selection.anchor,t)):(this._selection.anchor={...t},this._selection.focus={...t},this._selection.isCollapsed=!0)}_getNextParagraphPoint(t){const o=this._docModel.data.sections[t.sectionIndex];return o?t.paragraphIndex<o.paragraphs.length-1?_e(t.sectionIndex,t.paragraphIndex+1,0,0):t.sectionIndex<this._docModel.data.sections.length-1?_e(t.sectionIndex+1,0,0,0):null:null}_getPrevParagraphPoint(t){if(t.paragraphIndex>0){const o=this._docModel.getParagraphAt(t.sectionIndex,t.paragraphIndex-1);if(!o)return null;const a=o.children.length-1,i=o.children[a],s=(i==null?void 0:i.type)==="text"?i.value.length:0;return _e(t.sectionIndex,t.paragraphIndex-1,Math.max(a,0),s)}if(t.sectionIndex>0){const o=this._docModel.data.sections[t.sectionIndex-1];if(!o)return null;const a=o.paragraphs.length-1,i=o.paragraphs[a],s=((i==null?void 0:i.children.length)??0)-1,p=i==null?void 0:i.children[s],m=(p==null?void 0:p.type)==="text"?p.value.length:0;return _e(t.sectionIndex-1,a,Math.max(s,0),m)}return null}static domToModelPoint(t,o){let a=t instanceof Element?t:t.parentElement;for(;a;){const i=a.getAttribute("data-si"),s=a.getAttribute("data-pi"),p=a.getAttribute("data-ei");if(i!==null&&s!==null&&p!==null)return{sectionIndex:parseInt(i),paragraphIndex:parseInt(s),elementIndex:parseInt(p),offset:o};a=a.parentElement}return null}}const Pn=200;class Ln{constructor(){V(this,"_undoStack",[]);V(this,"_redoStack",[])}get canUndo(){return this._undoStack.length>0}get canRedo(){return this._redoStack.length>0}push(t){var a,i;this._redoStack=[];const o=this._undoStack[this._undoStack.length-1];if(o&&((a=t.canMergeWith)!=null&&a.call(t,o))){(i=o.merge)==null||i.call(o,t);return}this._undoStack.push(t),this._undoStack.length>Pn&&this._undoStack.shift()}undo(){const t=this._undoStack.pop();return t?(t.undo(),this._redoStack.push(t),!0):!1}redo(){const t=this._redoStack.pop();return t?(t.execute(),this._undoStack.push(t),!0):!1}clear(){this._undoStack=[],this._redoStack=[]}}class $n{constructor(t,o,a,i,s){V(this,"name","insertText");V(this,"_point");V(this,"_text");V(this,"_format");this.docModel=t,this.selectionManager=o,this._point={...a},this._text=i,this._format=s}execute(){this.docModel.insertText(this._point,this._text,this._format),this.selectionManager.setCursor({...this._point,offset:this._point.offset+this._text.length})}undo(){this.docModel.deleteAt(this._point,this._text.length),this.selectionManager.setCursor(this._point)}canMergeWith(t){if(t.name!=="insertText")return!1;const o=t;return o._point.sectionIndex===this._point.sectionIndex&&o._point.paragraphIndex===this._point.paragraphIndex&&o._point.elementIndex===this._point.elementIndex&&o._point.offset===this._point.offset+this._text.length}merge(t){const o=t;this._text+=o._text}}class zn{constructor(t,o){V(this,"name","insertParagraph");V(this,"_insertedParagraphId",null);this.docModel=t,this.selectionManager=o}execute(){var y,c;const{focus:t}=this.selectionManager.selection,{sectionIndex:o,paragraphIndex:a}=t,i=this.docModel.getParagraphAt(o,a);if(!i)return;const s=t.elementIndex,p=i.children.splice(s),m=this.docModel.createEmptyParagraph(i.format);m.children.push(...p),this._insertedParagraphId=m.id,this.docModel.data.sections[o].paragraphs.splice(a+1,0,m),(c=(y=this.docModel).bumpVersion)==null||c.call(y),this.selectionManager.setCursor({sectionIndex:o,paragraphIndex:a+1,elementIndex:0,offset:0})}undo(){const{focus:t}=this.selectionManager.selection,{sectionIndex:o,paragraphIndex:a}=t;a!==0&&(this.docModel.mergeParagraphs(o,a-1),this.selectionManager.setCursor({sectionIndex:o,paragraphIndex:a-1,elementIndex:0,offset:0}))}}class ht{constructor(t,o,a){V(this,"name");V(this,"_deletedText","");this.docModel=t,this.selectionManager=o,this.name=a==="backward"?"deleteBackward":"deleteForward"}execute(){const{focus:t,isCollapsed:o}=this.selectionManager.selection;if(o)if(this.name==="deleteBackward")if(t.offset>0){const a={...t,offset:t.offset-1},i=this.docModel.getElementAt(t);(i==null?void 0:i.type)==="text"&&(this._deletedText=i.value[t.offset-1]??""),this.docModel.deleteAt(a,1),this.selectionManager.setCursor(a)}else(t.paragraphIndex>0||t.elementIndex>0)&&(this.docModel.mergeParagraphs(t.sectionIndex,t.paragraphIndex-1),this.selectionManager.setCursor({...t,paragraphIndex:t.paragraphIndex-1}));else{const a=this.docModel.getElementAt(t);if((a==null?void 0:a.type)==="text"&&t.offset<a.value.length)this._deletedText=a.value[t.offset],this.docModel.deleteAt(t,1);else{const i=this.docModel.data.sections[t.sectionIndex];i&&t.paragraphIndex<i.paragraphs.length-1&&this.docModel.mergeParagraphs(t.sectionIndex,t.paragraphIndex)}}}undo(){if(this._deletedText){const{focus:t}=this.selectionManager.selection;this.docModel.insertText(t,this._deletedText)}}}class Ae{constructor(t,o,a,i){V(this,"name");V(this,"_prevFormat",{});this.docModel=t,this.selectionManager=o,this._value=i,this.name=a}execute(){const{anchor:t,focus:o}=this.selectionManager.selection,a=this._getFormatKey();if(!a)return;const i={};if(this._isToggle()){const s=this._getCurrentValue(a);i[a]=!s}else i[a]=this._value;this.docModel.updateRangeFormat(t,o,i)}undo(){const{anchor:t,focus:o}=this.selectionManager.selection;this.docModel.updateRangeFormat(t,o,this._prevFormat)}_isToggle(){return["bold","italic","underline","strikethrough","superscript","subscript"].includes(this.name)}_getFormatKey(){return{bold:"bold",italic:"italic",underline:"underline",strikethrough:"strikethrough",fontSize:"fontSize",fontFamily:"fontFamily",color:"color",backgroundColor:"backgroundColor"}[this.name]??null}_getCurrentValue(t){var i;const{focus:o}=this.selectionManager.selection,a=this.docModel.getElementAt(o);return(i=a==null?void 0:a.format)==null?void 0:i[t]}}class Je{constructor(t,o,a,i){V(this,"name","textAlign");this.docModel=t,this.selectionManager=o,this._formatKey=a,this._value=i}execute(){const{focus:t}=this.selectionManager.selection,o={};o[this._formatKey]=this._value,this.docModel.updateParagraphFormat(t.sectionIndex,t.paragraphIndex,o)}undo(){}}class Rn{constructor(t,o,a){V(this,"_factories",new Map);this.docModel=t,this.selectionManager=o,this.historyManager=a,this._registerBuiltinCommands()}_registerBuiltinCommands(){this.register("insertText",o=>{const{focus:a}=this.selectionManager.selection;return new $n(this.docModel,this.selectionManager,a,o)}),this.register("insertParagraph",()=>new zn(this.docModel,this.selectionManager)),this.register("deleteBackward",()=>new ht(this.docModel,this.selectionManager,"backward")),this.register("deleteForward",()=>new ht(this.docModel,this.selectionManager,"forward")),this.register("undo",()=>null),this.register("redo",()=>null),["bold","italic","underline","strikethrough","superscript","subscript"].forEach(o=>{this.register(o,()=>new Ae(this.docModel,this.selectionManager,o))}),this.register("fontSize",o=>new Ae(this.docModel,this.selectionManager,"fontSize",o)),this.register("fontFamily",o=>new Ae(this.docModel,this.selectionManager,"fontFamily",o)),this.register("color",o=>new Ae(this.docModel,this.selectionManager,"color",o)),this.register("backgroundColor",o=>new Ae(this.docModel,this.selectionManager,"backgroundColor",o)),this.register("textAlign",o=>new Je(this.docModel,this.selectionManager,"textAlign",o)),this.register("lineHeight",o=>new Je(this.docModel,this.selectionManager,"lineHeight",o)),this.register("heading",o=>new Je(this.docModel,this.selectionManager,"heading",o)),this.register("selectAll",()=>(this.selectionManager.selectAll(),null)),this.register("setSelection",o=>{if(o){const a=o;this.selectionManager.setSelection(a.anchor,a.focus)}return null})}register(t,o){this._factories.set(t,o)}exec(t,o){if(t==="undo"){this.historyManager.undo();return}if(t==="redo"){this.historyManager.redo();return}const a=this._factories.get(t);if(!a){console.warn(`[CommandManager] 未注册命令: ${t}`);return}const i=a(o);i&&(i.execute(),this.historyManager.push(i))}}class Dn{constructor(t,o){V(this,"_el",null);V(this,"_commandManager");V(this,"_selectionManager");V(this,"_composing",!1);V(this,"_boundKeydown");V(this,"_boundBeforeInput");V(this,"_boundCompositionStart");V(this,"_boundCompositionEnd");V(this,"_boundSelectionChange");this._commandManager=t,this._selectionManager=o,this._boundKeydown=this._onKeydown.bind(this),this._boundBeforeInput=this._onBeforeInput.bind(this),this._boundCompositionStart=()=>{this._composing=!0},this._boundCompositionEnd=this._onCompositionEnd.bind(this),this._boundSelectionChange=this._onSelectionChange.bind(this)}attach(t){this._el=t,t.addEventListener("keydown",this._boundKeydown),t.addEventListener("beforeinput",this._boundBeforeInput),t.addEventListener("compositionstart",this._boundCompositionStart),t.addEventListener("compositionend",this._boundCompositionEnd),document.addEventListener("selectionchange",this._boundSelectionChange)}detach(){this._el&&(this._el.removeEventListener("keydown",this._boundKeydown),this._el.removeEventListener("beforeinput",this._boundBeforeInput),this._el.removeEventListener("compositionstart",this._boundCompositionStart),this._el.removeEventListener("compositionend",this._boundCompositionEnd),document.removeEventListener("selectionchange",this._boundSelectionChange),this._el=null)}_onKeydown(t){const o=t.key,a=t.ctrlKey||t.metaKey,i=t.shiftKey;if(a)switch(o){case"z":t.preventDefault(),i?this._commandManager.exec("redo"):this._commandManager.exec("undo");return;case"b":t.preventDefault(),this._commandManager.exec("bold");return;case"i":t.preventDefault(),this._commandManager.exec("italic");return;case"u":t.preventDefault(),this._commandManager.exec("underline");return;case"a":t.preventDefault(),this._commandManager.exec("selectAll");return}switch(o){case"Enter":t.preventDefault(),this._composing||this._commandManager.exec("insertParagraph");break;case"Backspace":t.preventDefault(),this._composing||this._commandManager.exec("deleteBackward");break;case"Delete":t.preventDefault(),this._composing||this._commandManager.exec("deleteForward");break;case"ArrowLeft":t.preventDefault(),this._selectionManager.moveBackward(i);break;case"ArrowRight":t.preventDefault(),this._selectionManager.moveForward(i);break;case"Tab":t.preventDefault(),this._commandManager.exec("insertText"," ");break}}_onBeforeInput(t){t.preventDefault(),!this._composing&&t.data&&this._commandManager.exec("insertText",t.data)}_onCompositionEnd(t){this._composing=!1,t.data&&this._commandManager.exec("insertText",t.data)}_onSelectionChange(){const t=window.getSelection();if(!t||!this._el)return;const o=t.anchorNode,a=t.focusNode;if(!o||!a||!this._el.contains(o)&&!this._el.contains(a))return;const i=Ge.domToModelPoint(o,t.anchorOffset),s=Ge.domToModelPoint(a,t.focusOffset);i&&s&&this._selectionManager.setSelection(i,s)}}class ft{constructor(t={}){V(this,"docModel");V(this,"selection");V(this,"history");V(this,"commands");V(this,"input");V(this,"_readonly");V(this,"_plugins",[]);V(this,"_inputEl",null);var o;this._readonly=t.readonly??!1,this.docModel=new De(t.initialDocument),this.selection=new Ge(this.docModel),this.history=new Ln,this.commands=new Rn(this.docModel,this.selection,this.history),this.input=new Dn(this.commands,this.selection),(o=t.plugins)==null||o.forEach(a=>this.use(a))}exec(t,o){if(this._readonly&&!this._isReadCommand(t)){console.warn("[Editor] 只读模式,忽略写操作");return}this.commands.exec(t,o)}mount(t){this._inputEl=t,this._readonly||this.input.attach(t)}unmount(){this.input.detach(),this._inputEl=null}use(t){return this._plugins.find(o=>o.name===t.name)?(console.warn(`[Editor] 插件 ${t.name} 已安装`),this):(t.install(this),this._plugins.push(t),this)}getJSON(){return this.docModel.toJSON()}loadJSON(t){const o=De.fromJSON(t);Object.assign(this.docModel.data,o.data),this.history.clear()}get isReadonly(){return this._readonly}_isReadCommand(t){return["undo","redo","selectAll","setSelection"].includes(t)}}const Xe=Symbol("editor");function Hn(n){const t=new ft(n);return e.provide(Xe,t),e.onUnmounted(()=>{t.unmount()}),t}function On(){const n=e.inject(Xe);if(!n)throw new Error("[useEditor] 必须在 EditorContainer 组件内使用");return n}const ut=An,Nn={install(n){n.component("EditorContainer",ut)}};Y.Editor=ft,Y.EditorContainer=ut,Y.EditorKey=Xe,Y.createEditor=Hn,Y.default=Nn,Y.useEditor=On,Object.defineProperties(Y,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bireturn/word-editor",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "类 Word 的 Web 富文本编辑器,基于canvas-editor的数据结构渲染",
5
5
  "type": "module",
6
6
  "files": [