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