@bireturn/word-editor 1.0.0 → 1.0.1

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