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