@bireturn/word-editor 1.0.3 → 1.0.4

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 +0,0 @@
1
- (function(oe,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):(oe=typeof globalThis<"u"?globalThis:oe||self,e(oe.WordEditor={},oe.Vue,oe.VueVirtualScroller,oe.LucideVueNext))})(this,function(oe,e,be,B){"use strict";var Vn=Object.defineProperty;var jn=(oe,e,be)=>e in oe?Vn(oe,e,{enumerable:!0,configurable:!0,writable:!0,value:be}):oe[e]=be;var V=(oe,e,be)=>jn(oe,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`}}),f=e.ref([]),P=e.ref(null);let I=null;const N=e.ref(),A=(q,v,F)=>{if(q.children&&q.children.length>0){v&&v.preventDefault()&&v.stopPropagation();return}q.disabled||(F?n("menuClick",{...q,parent:F.code},i.row):n("menuClick",q,i.row)),v&&v.preventDefault()&&v.stopPropagation()},J=q=>{let v=q.target;for(;v&&v!=N.value;)v=v.parentNode;v!=N.value&&n("close")},H=(q,v)=>{q.currentTarget.classList.add("link--active"),I&&(clearTimeout(I),I=null),v.children&&v.children.length>0?P.value=v.code:I=setTimeout(()=>{P.value=null},100)},K=(q,v)=>{q.currentTarget.classList.remove("link--active"),v.children&&v.children.length>0&&(I=setTimeout(()=>{P.value===v.code&&(P.value=null)},300))},X=q=>{I&&(clearTimeout(I),I=null),q.currentTarget.classList.add("link--active")},Y=q=>{q.currentTarget.classList.remove("link--active")},ue=q=>{const v=q.code||"",F=(q.name||"").toLowerCase(),j={"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 j[v]?j[v]:F.includes("添加")||F.includes("add")?F.includes("当前")||F.includes("current")?B.Navigation:F.includes("下")||F.includes("next")?B.ArrowDown:F.includes("子")||F.includes("child")?B.PlusCircle:B.Plus:F.includes("导出")||F.includes("export")?F.includes("节")||F.includes("section")?B.Layers:F.includes("章")||F.includes("chapter")?B.FileDown:B.Download:F.includes("粘贴")||F.includes("paste")?B.Clipboard:F.includes("删除")||F.includes("delete")?B.Trash2:F.includes("pdf")?B.FileText:F.includes("word")?B.Type:B.MoreHorizontal};return e.onMounted(()=>{var q,v,F,j,y,k,c;(q=i.menuConfig)!=null&&q.visibleMethod&&typeof((v=i.menuConfig)==null?void 0:v.visibleMethod)=="function"&&((y=i.menuConfig)==null||y.visibleMethod({options:(j=(F=i.menuConfig)==null?void 0:F.body)==null?void 0:j.options,row:i.row})),f.value=(((c=(k=i.menuConfig)==null?void 0:k.body)==null?void 0:c.options)||[]).flat(),document.addEventListener("click",J,!0)}),e.onUnmounted(()=>{document.removeEventListener("click",J,!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:N,style:e.normalizeStyle([{display:"inline-block"},r.value])},[e.createElementVNode("ul",ht,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(f.value,F=>(e.openBlock(),e.createElementBlock("li",{class:e.normalizeClass({"link--disabled":F.disabled,"has-children":F.children&&F.children.length>0,"modern-menu-item":!0}),key:F.code,onMouseenter:j=>H(j,F),onMouseleave:j=>K(j,F)},[e.createElementVNode("a",{class:"we-vt-context-menu--link modern-menu-link",onClick:j=>A(F,j)},[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(ue(F)),{size:16,class:"menu-icon"})),e.createElementVNode("span",gt,e.toDisplayString(F.name),1),F.children&&F.children.length>0?(e.openBlock(),e.createBlock(e.unref(B.ChevronRight),{key:0,size:14,class:"submenu-arrow"})):e.createCommentVNode("",!0)],8,ut),F.children&&F.children.length>0&&P.value===F.code?(e.openBlock(),e.createElementBlock("ul",pt,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(F.children,j=>(e.openBlock(),e.createElementBlock("li",{key:j.code,class:e.normalizeClass({"link--disabled":j.disabled,"modern-submenu-item":!0}),onMouseenter:X,onMouseleave:Y},[e.createElementVNode("a",{class:"we-vt-context-menu--link modern-submenu-link",onClick:y=>A(j,y,F)},[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(ue(j)),{size:14,class:"submenu-icon"})),e.createElementVNode("span",yt,e.toDisplayString(j.name),1)],8,mt)],34))),128))])):e.createCommentVNode("",!0)],42,ft))),128))])],4))}},We=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[We]=r,e.render(i,r),i.component}function bt(l){var n;const t=l.vnode[We];e.render(null,t),t!=null&&t.checkVisibility&&(t!=null&&t.checkVisibility())&&((n=document.body)==null||n.removeChild(t))}let Ue;const xt=l=>{Ue=_t(kt,l,null)},Ct=function(l){const t=l.onClose;return l.onClose=()=>{t&&t.call(),bt(Ue)},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",f=(n==null?void 0:n.parentField)||"order";if(!(l!=null&&l.length))return l;const P={};l.forEach(J=>{const H=J[r];P[H]||(P[H]=[]),P[H].push(J)});function I(J){const H=P[J]||[];H.sort((X,Y)=>X[f]&&Y[f]?X[f]-Y[f]:0);const K=[];return H.forEach(X=>{K.push(X),K.push(...I(X[i]))}),K}let N=[];if(Array.isArray(t))N=t;else{const J=new Set(l.map(X=>X[i])),H=l.filter(X=>!J.has(X[r]));if(H.length===0)throw new Error("无法确定根节点:可能存在循环引用或数据不完整");const K={};H.forEach(X=>{const Y=X[r];K[Y]=(K[Y]||0)+1}),N=Object.entries(K).map(([X])=>X)}let A=[];return N.forEach(J=>{A=A.concat(I(J))}),A}function Ge(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(),f=e.ref(),P=e.ref(!1),I=e.ref(null),N=e.ref(null),A=e.ref([]);let J=new Map;const H=new Map;e.ref(0);const K=e.ref([]);e.ref([]);const X=e.ref(new Set),Y=e.ref(new Set),ue=e.ref(null),q=2,v=new WeakMap,F=e.ref(null),j=e.ref(""),y=new Set,k=e.computed(()=>{try{return Array.isArray(A.value)?A.value:[]}catch{return[]}}),c=o=>{var g,h,u;if(!o)return 30;if(o.height)return o.height;const a=`${o.content_type}_${((g=o.content)==null?void 0:g.length)||0}_${((h=o.title)==null?void 0:h.length)||0}_${o._editing?1:0}`;if(v.has(o)){const b=v.get(o);if(b.key===a)return b.height}let s=30;switch(o.content_type){case"image":s=150;break;case"table-row":s=o.rowHeight||35;break;case"table":const C=((o.content||"").match(/<tr/g)||[]).length;s=Math.max(100,C*35+30);break;case"flowchart":s=200;break;default:{const m=(o.content||"").length,p=(o.title||"").length,x=m+p,z=((u=(o.content||"").match(/[\u4e00-\u9fa5]/g))==null?void 0:u.length)||0,$=x-z,T=z*12+$*6,R=Math.max(1,Math.ceil(T/760));s=Math.max(20,R*18),o._editing&&(s+=20);break}}return v.set(o,{key:a,height:s}),s},O=e.computed(()=>{if(k.value.length===0)return 30;const o=k.value.slice(0,Math.min(100,k.value.length));if(o.length===0)return 30;const a=o.reduce((g,h)=>g+c(h),0)/o.length,s=Math.max(20,Math.floor(a*.6));return Math.min(s,60)});let d;const L=(o,a)=>{t("menu-click",{menu:o,row:a}),d==null||d.onClose(),d=null},E=o=>{var s,g,h,u,b;if(!((h=(g=(s=l.menuConfig)==null?void 0:s.body)==null?void 0:g.options)!=null&&h.length))return;d==null||d.onClose(),d=null;let a=o.target;for(;a&&(a!=null&&a.getAttribute)&&!(a!=null&&a.getAttribute("data-id"))&&a!==((u=f.value)==null?void 0:u.$el);)a=a.parentNode;if((b=a==null?void 0:a.getAttribute)!=null&&b.call(a,"data-id")){const C=a.getAttribute("data-id"),m=me(C);m&&(d=Ct({e:o,row:m,menuConfig:l.menuConfig,onMenuClick:L}),o.preventDefault(),o.stopPropagation())}},w=o=>{var s,g,h;if(!I.value)return;let a=o.target;for(;a&&(a!=null&&a.getAttribute)&&!(a!=null&&a.getAttribute("data-id"))&&a!==((s=f.value)==null?void 0:s.$el);)if(a=a.parentNode,a!=null&&a.classList&&["el-popper","ck-body-wrapper"].some(u=>a.classList.contains(u)))return;((g=a==null?void 0:a.getAttribute)==null?void 0:g.call(a,"data-id"))!=((h=I.value)==null?void 0:h.node_id)&&(I.value._editing=!1,t("edit-closed",{row:I.value,column:{},$table:r==null?void 0:r.exposed}),I.value=null)};((ct=l.editConfig)==null?void 0:ct.trigger)==="dblclick"&&e.watch(()=>I.value,o=>{document.removeEventListener("click",w,!0),o&&setTimeout(()=>{document.addEventListener("click",w,!0)},200)});const M=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}})),D=()=>{if(!l.pageConfig.enabled){K.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(h=>{s.set(String(h[a]),h)}),Object.keys(l.pageData).sort((h,u)=>parseInt(h)-parseInt(u)).forEach(h=>{const u=l.pageData[h],b=[];u.forEach(C=>{const m=s.get(String(C));m&&b.push(m)}),b.length>0&&o.push({items:b,pageNumber:parseInt(h),height:b.reduce((C,m)=>C+c(m),0)})}),K.value=o}else{const{pageHeight:o,margin:a}=l.pageConfig,s=o-a*2,g=[];let h=[],u=0,b=0,C=1;A.value.forEach((m,p)=>{const x=c(m);(m.layer||0)<=2&&h.length>0?(g.push({items:[...h],startIndex:b,endIndex:p,height:u,pageNumber:C++}),h=[m],u=x,b=p):u+x>s&&h.length>0?(g.push({items:[...h],startIndex:b,endIndex:p,height:u,pageNumber:C++}),h=[m],u=Math.min(x,s),b=p):(h.push(m),u+=x)}),h.length>0&&g.push({items:h,startIndex:b,endIndex:A.value.length,height:u,pageNumber:C}),K.value=g}},_=()=>{try{const o=Array.isArray(l.data)?l.data:[],a=M(o);if(!(a!==j.value)&&A.value.length>0)return;j.value=a;const g=(l.treeConfig?wt(o,void 0,l.treeConfig):o).map((u,b)=>{const C=u[l.rowConfig.keyField],m=H.get(C);if(!m||m.content!==u.content||m.content_type!==u.content_type){y.add(C);const p={...u,index:b,_editing:u._editing||!1,_original:(m==null?void 0:m._original)||{...u}};return H.set(C,p),p}return m.index=b,m});A.value=g,D();const h=new Set(g.map(u=>u[l.rowConfig.keyField]));for(const[u]of H)h.has(u)||(H.delete(u),y.delete(u))}catch{A.value=[],K.value=[],H.clear(),y.clear()}};e.watch(()=>l.data,(o,a)=>{try{if(!Array.isArray(o))return;e.nextTick(()=>{if(_(),l.pageConfig.enabled){Y.value.clear(),X.value.clear();for(let s=0;s<Math.min(3,K.value.length);s++)Y.value.add(s);e.nextTick(()=>{Q()})}})}catch{}},{deep:!1,immediate:!1}),e.watch(()=>l.pageData,()=>{if(l.pageConfig.enabled){D(),Y.value.clear(),X.value.clear();for(let o=0;o<Math.min(3,K.value.length);o++)Y.value.add(o);e.nextTick(()=>{Q()})}},{deep:!0}),e.watch(()=>l.pageConfig,()=>{if(l.pageConfig.enabled){D(),Y.value.clear(),X.value.clear();for(let o=0;o<Math.min(3,K.value.length);o++)Y.value.add(o);e.nextTick(()=>{Q()})}},{deep:!0}),e.watch(N,()=>t("current-change",{row:N.value}));let se=null;const le=()=>{window.ResizeObserver&&(se=new ResizeObserver(o=>{var a,s;for(const g of o){const h=(a=g.target.dataset)==null?void 0:a.id;if(!h)continue;const u=me(h);if(!u)continue;const b=g.contentRect.height,C=((s=v.get(u))==null?void 0:s.height)||0;if(Math.abs(C-b)>5){const m=v.get(u)||{};v.set(u,{...m,height:b}),requestAnimationFrame(()=>{var x;const p=g.target.__vueParentComponent;(x=p==null?void 0:p.proxy)!=null&&x.updateSize&&p.proxy.updateSize()})}}}),e.nextTick(()=>{var s;const o=(s=f.value)==null?void 0:s.$el;if(!o)return;o.querySelectorAll("[data-id]").forEach(g=>{g.dataset.id&&se.observe(g)})}))},ee=()=>{F.value&&(F.value.disconnect(),F.value=null),se&&(se.disconnect(),se=null)},Q=()=>{l.pageConfig.enabled&&(ue.value&&ue.value.disconnect(),ue.value=new IntersectionObserver(o=>{o.forEach(a=>{const s=parseInt(a.target.dataset.pageIndex);if(a.isIntersecting){X.value.add(s);for(let g=Math.max(0,s-q);g<=Math.min(K.value.length-1,s+q);g++)Y.value.add(g)}else X.value.delete(s),setTimeout(()=>{X.value.has(s)||Array.from(X.value).some(h=>Math.abs(h-s)<=q*2)||Y.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=>{ue.value.observe(s)})}))};e.onMounted(()=>{_(),e.nextTick(()=>{var o;if(le(),ae.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++)Y.value.add(a)}),P.value=!0}),e.onUnmounted(()=>{var o;ee(),ae.cleanup(),ue.value&&(ue.value.disconnect(),ue.value=null),((o=l.editConfig)==null?void 0:o.trigger)==="contenteditable"&&(document.removeEventListener("selectionchange",ot),document.removeEventListener("mouseup",lt)),re&&clearTimeout(re),J=new Map,H.clear(),Y.value.clear(),X.value.clear()});const ae={handlers:new Map,setup(){e.nextTick(()=>{var a;const o=(a=f.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,g=me(s);g&&ze(g)},handleDblClick(o){var h;if(!((h=l.editConfig)!=null&&h.trigger)==="dblclick")return;const a=o.target.closest("[data-id]");if(!a)return;const s=a.dataset.id,g=me(s);g&&Se(g)},cleanup(){var a,s;const o=(s=(a=f.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))}},de=o=>{ze(o)},ne=o=>Se(o);let S=null,G;const Ae=({row:o,column:a},s,g)=>{var b,C;const h=g||s.target,u=Ge(h,"virtual-table-cell",(b=f.value)==null?void 0:b.$el);S===u&&G&&(clearTimeout(G),S=null),((C=I.value)==null?void 0:C[l.rowConfig.keyField])!=(o==null?void 0:o[l.rowConfig.keyField])&&setTimeout(()=>{var p,x;I.value=o;let m=(p=h==null?void 0:h.getAttribute)==null?void 0:p.call(h,"field");if(!m){try{const z=document.getSelection();let $=z==null?void 0:z.anchorNode;$&&$.nodeType===3&&($=$.parentElement);const T=(x=$==null?void 0:$.closest)==null?void 0:x.call($,"[field]");T&&(m=T.getAttribute("field"))}catch{}if(!m&&(s!=null&&s.composedPath)){for(const z of s.composedPath())if(z!=null&&z.getAttribute&&z.getAttribute("field")){m=z.getAttribute("field");break}}}t("edit-activated",{row:o,column:{...a,field:m},$table:r==null?void 0:r.exposed})},200)},he=({row:o,column:a},s,g)=>{var u;const h=g||s.target;S=Ge(h,"virtual-table-cell",(u=f.value)==null?void 0:u.$el),G&&clearTimeout(G),G=setTimeout(()=>{var m,p,x,z,$;const b=o.content_type;let C=(m=h==null?void 0:h.getAttribute)==null?void 0:m.call(h,"field");if(!C){try{const T=document.getSelection();let R=T==null?void 0:T.anchorNode;R&&R.nodeType===3&&(R=R.parentElement);const Z=(p=R==null?void 0:R.closest)==null?void 0:p.call(R,"[field]");Z&&(C=Z.getAttribute("field"))}catch{}if(!C&&(s!=null&&s.composedPath)){for(const T of s.composedPath())if(T!=null&&T.getAttribute&&T.getAttribute("field")){C=T.getAttribute("field");break}}}if(b!=="table"){if(b==="text"){let T=null,R=null;if((x=h==null?void 0:h.getAttribute)!=null&&x.call(h,"field")?T=h:(z=h==null?void 0:h.closest)!=null&&z.call(h,"[field]")&&(T=h.closest("[field]")),T&&(R=T.textContent),C&&R!==void 0&&R!==null){R=R.trim();const Z=(($=o[C])==null?void 0:$.trim())||"";R!==Z&&(o[C]=R)}}}t("edit-closed",{row:o,column:{...a,field:C},$table:r==null?void 0:r.exposed})},50)};let W=null,re=null;const Me=o=>{var a;((a=l.editConfig)==null?void 0:a.trigger)==="contenteditable"&&Pe("focusin",o)},xe=o=>{var a,s,g,h,u;if(((a=l.editConfig)==null?void 0:a.trigger)==="contenteditable")if(W!=null&&W.cellEl){let b=W.fieldEl;!b&&W.field&&(b=(g=(s=W.cellEl)==null?void 0:s.querySelector)==null?void 0:g.call(s,`[field="${W.field}"]`)),b||(b=((u=(h=W.cellEl).querySelector)==null?void 0:u.call(h,"[field]"))||W.cellEl),he(W,{target:b},b),W=null}else Pe("focusout",o)},Pe=(o,a)=>{var s,g,h,u,b,C;try{const m=document.getSelection();let p=m==null?void 0:m.anchorNode;p&&p.nodeType===3&&(p=p.parentElement);const x=(s=p==null?void 0:p.closest)==null?void 0:s.call(p,".virtual-table-cell"),z=(g=p==null?void 0:p.closest)==null?void 0:g.call(p,".virtual-table-row");if(!x||!z)return;const $=z.getAttribute("data-id"),T=x.getAttribute("data-prop"),R=me($),Z=Ce.value.find(ce=>`${ce.prop}`==`${T}`)||{},ie=((h=p==null?void 0:p.closest)==null?void 0:h.call(p,"[field]"))||null,U=((u=ie==null?void 0:ie.getAttribute)==null?void 0:u.call(ie,"field"))||void 0;o==="focusin"?(W={row:R,column:Z,cellEl:x,rowEl:z,fieldEl:ie,field:U},Ae({row:R,column:Z},a,ie||((b=p==null?void 0:p.closest)==null?void 0:b.call(p,"[field]")))):he({row:R,column:Z},a,ie||((C=p==null?void 0:p.closest)==null?void 0:C.call(p,"[field]")))}catch{}},ot=()=>{var o;((o=l.editConfig)==null?void 0:o.trigger)==="contenteditable"&&(re&&clearTimeout(re),re=setTimeout(()=>{var a,s,g,h,u,b,C,m,p,x,z,$,T,R;try{const Z=document.getSelection();if(Z.rangeCount===0)return;const ie=Z.getRangeAt(0);let U=ie.startContainer;U.nodeType===3&&(U=U.parentElement);const ce=(a=U==null?void 0:U.closest)==null?void 0:a.call(U,".virtual-table-cell"),ye=(s=U==null?void 0:U.closest)==null?void 0:s.call(U,".virtual-table-row");if(!ce||!ye)return;const Ke=ye.getAttribute("data-id"),qe=ce.getAttribute("data-prop"),_e=me(Ke),fe=Ce.value.find(te=>`${te.prop}`==`${qe}`)||{};if(!W||((g=W.row)==null?void 0:g[l.rowConfig.keyField])!==(_e==null?void 0:_e[l.rowConfig.keyField])||((h=W.column)==null?void 0:h.prop)!==(fe==null?void 0:fe.prop)){if(W){let te=W.fieldEl;!te&&W.field&&(te=(b=(u=W.cellEl)==null?void 0:u.querySelector)==null?void 0:b.call(u,`[field="${W.field}"]`)),te||(te=((m=(C=W.cellEl)==null?void 0:C.querySelector)==null?void 0:m.call(C,"[field]"))||W.cellEl),he(W,{target:te},te)}W={row:_e,column:fe,cellEl:ce,rowEl:ye,fieldEl:((p=U==null?void 0:U.closest)==null?void 0:p.call(U,"[field]"))||null,field:(($=(z=((x=U==null?void 0:U.closest)==null?void 0:x.call(U,"[field]"))||null)==null?void 0:z.getAttribute)==null?void 0:$.call(z,"field"))||void 0},Ae({row:_e,column:fe},{target:ce},ce)}if(Z.toString()){const te=ie.endContainer.nodeType===3?ie.endContainer.parentElement:ie.endContainer,Re=(T=te==null?void 0:te.closest)==null?void 0:T.call(te,".virtual-table-cell"),Oe=(R=te==null?void 0:te.closest)==null?void 0:R.call(te,".virtual-table-row")}}catch{}},50))},lt=()=>{var o;((o=l.editConfig)==null?void 0:o.trigger)==="contenteditable"&&setTimeout(()=>{var g,h,u,b;const a=document.getSelection();if(!a)return;const s=a.toString();if(s){const C=a.rangeCount>0?a.getRangeAt(0):null;let m=null,p=null;try{if(C){let x=C.startContainer;(x==null?void 0:x.nodeType)===3&&(x=x.parentElement);const z=(g=x==null?void 0:x.closest)==null?void 0:g.call(x,".virtual-table-cell"),$=(h=x==null?void 0:x.closest)==null?void 0:h.call(x,".virtual-table-row");m=z&&$?{rowId:$.getAttribute("data-id"),prop:z.getAttribute("data-prop")}:null;let T=C.endContainer;(T==null?void 0:T.nodeType)===3&&(T=T.parentElement);const R=(u=T==null?void 0:T.closest)==null?void 0:u.call(T,".virtual-table-cell"),Z=(b=T==null?void 0:T.closest)==null?void 0:b.call(T,".virtual-table-row");p=R&&Z?{rowId:Z.getAttribute("data-id"),prop:R.getAttribute("data-prop")}:null}}catch{}t("selection-change",{text:s,selection:a,range:C,start:m,end:p})}},10)},wn=o=>(o==null?void 0:o._editing)===!0,En=o=>o!=null&&o.parent_id?J.get(o.parent_id):null,Bn=o=>{var s;const a=A.value.findIndex(g=>g[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},Mn=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]},me=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 Le=null;const Sn=o=>{Le&&cancelAnimationFrame(Le),Le=requestAnimationFrame(()=>{var g;const a=l.rowConfig.keyField,s=o[a];if(l.pageConfig.enabled){let h=-1;for(let u=0;u<K.value.length;u++)if(K.value[u].items.some(m=>m[a]===s)){h=u;break}if(h!==-1){for(let u=Math.max(0,h-1);u<=Math.min(K.value.length-1,h+1);u++)Y.value.has(u)||Y.value.add(u);e.nextTick(()=>{const u=document.querySelector(".a4-pages-container");if(!u)return;const b=(C=0)=>{const m=u.querySelector(`[data-id="${s}"]`);if(m){let p=0,x=m;for(;x&&x!==u;)p+=x.offsetTop,x=x.offsetParent;const z=u.clientHeight;let $=p-z*.3;$=Math.max(0,$);const T=u.scrollTop,R=Math.abs($-T),Z=ie=>{const U=u.scrollTop,ce=ie-U,ye=Math.min(800,Math.max(300,R*.5)),Ke=performance.now(),qe=fe=>fe<.5?4*fe*fe*fe:1-Math.pow(-2*fe+2,3)/2,_e=fe=>{const dt=fe-Ke,te=Math.min(dt/ye,1),Re=qe(te),Oe=U+ce*Re;u.scrollTop=Oe,te<1?requestAnimationFrame(_e):setTimeout(()=>{u.scrollTop=ie},50)};requestAnimationFrame(_e)};R>3e3?u.scrollTo({top:$,behavior:"instant"}):Z($),m.classList.add("row--highlight"),setTimeout(()=>{m.classList.remove("row--highlight")},1500)}else C<10&&setTimeout(()=>b(C+1),150)};setTimeout(b,200)})}}else{const h=A.value.findIndex(u=>u[a]===s);h!==-1&&((g=f.value)!=null&&g.scrollToItem)&&f.value.scrollToItem(h)}Le=null})},ze=o=>{if(o){if(!P.value){setTimeout(()=>ze(o),200);return}N.value=o,N.value!==I.value&&I.value&&(I.value._editing=!1,setTimeout(()=>{I.value=null},200))}},Se=(o,a)=>new Promise(s=>{var g,h;if(!((g=l==null?void 0:l.editConfig)!=null&&g.beforeEditMethod&&typeof((h=l==null?void 0:l.editConfig)==null?void 0:h.beforeEditMethod)=="function"&&!l.editConfig.beforeEditMethod({row:o}))){if(!o||!P.value){setTimeout(()=>Se(o),200);return}o!==I.value&&(A.value.forEach(u=>{u._editing&&t("edit-closed",{row:u,column:{field:a},$table:r==null?void 0:r.exposed}),u._editing=!1}),o._editing=!0,setTimeout(()=>{I.value=o,t("edit-activated",{row:o,column:{field:a},$table:r==null?void 0:r.exposed}),s(!0)}))}}),In=o=>Se(o),je=()=>{if(D(),l.pageConfig.enabled){const o=Array.from(X.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++)Y.value.add(s)}else for(let a=0;a<Math.min(3,K.value.length);a++)Y.value.add(a);e.nextTick(()=>{Q()})}e.nextTick(()=>{!l.pageConfig.enabled&&f.value&&f.value.$forceUpdate&&f.value.$forceUpdate()})},Fn=(o,a)=>new Promise(s=>{let g=-1;if(a==-1){const h=me(o.parent_id);for(g=A.value.findIndex(u=>u[l.rowConfig.keyField]==h[l.rowConfig.keyField])+1;A.value[g].parent_id==h[l.rowConfig.keyField];)g+=1}else g=A.value.findIndex(h=>h[l.rowConfig.keyField]==a[l.rowConfig.keyField]);J.set(o.node_id,o),H.set(o[l.rowConfig.keyField],o),A.value.splice(g,0,o),je(),s({row:o})}),Tn=(o,a)=>new Promise(s=>{const g=A.value.findIndex(h=>h[l.rowConfig.keyField]==a[l.rowConfig.keyField])+1;J.set(o.node_id,o),H.set(o[l.rowConfig.keyField],o),A.value.splice(g,0,o),je(),s({row:o})}),at=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];J.delete(o.node_id),H.delete(s),A.value.splice(a,1),je()}},An=(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(g=>s[g]!==o[g]):!1},Pn=o=>o&&o[l.rowConfig.keyField]&&!o._original,Ln=(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})},zn=o=>{if(o&&o[l.rowConfig.keyField]){const a=me(o[l.rowConfig.keyField]);a._original?Object.assign(a,a._original):at(a)}},$n=()=>{},Dn=()=>{N.value={}},it=o=>{var s,g,h;let a=A.value.findIndex(u=>u[l.rowConfig.keyField]==o[l.rowConfig.keyField]);if(a>-1&&l.treeConfig){const u=((s=l.treeConfig)==null?void 0:s.keyField)||((g=l.treeConfig)==null?void 0:g.rowField)||"node_id",b=((h=l.treeConfig)==null?void 0:h.parentField)||"parent_id",C=[],m=new Map;m.set(o[u],!0);for(let p=a+1;p<A.value.length;p++){const x=A.value[p];if(x&&m.has(x[b]))C.push(x),m.set(x[u]);else break}return C}return[]};i({isEditByRow:wn,getParentRow:En,getSiblingRow:Bn,getNextRow:Mn,getRowById:me,scrollToRow:Sn,setCurrentRow:ze,setEditRow:Se,setEditCell:In,insertAt:Fn,insertNextAt:Tn,isUpdateByRow:An,isInsertByRow:Pn,reloadRow:Ln,revertData:zn,remove:at,setAllTreeExpand:$n,clearCurrentRow:Dn,getAllChilds:it});const Ce=e.computed(()=>n.default().filter(o=>{var a;return((a=o.type)==null?void 0:a.name)==="VirtualTableColumn"}).map(o=>{var a,s,g;return{prop:(a=o.props)==null?void 0:a.prop,title:(s=o.props)==null?void 0:s.title,width:(g=o.props)==null?void 0:g.width,slots:o.children}})),$e=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&&N.value?it(N.value).map(a=>a[l.rowConfig.keyField]):[]}),st=e.ref({viewStartIndex:0,viewEndIndex:0,visibleStartIndex:0,visibleEndIndex:0});let De=null,ve=null;const vn=(o,a)=>{De&&cancelAnimationFrame(De),De=requestAnimationFrame(()=>{t("scroll-end",{...st.value}),De=null})},Rn=(o,a,s,g)=>{ve&&cancelAnimationFrame(ve),ve=requestAnimationFrame(()=>{st.value={viewStartIndex:o,viewEndIndex:a,visibleStartIndex:s,visibleEndIndex:g},ve=null})},On=(o,a)=>{var C,m;const{pageHeight:s,margin:g,showPageBorder:h,pageBorderPadding:u,pageBorderStyle:b}=l.pageConfig;return Y.value.has(a)?e.createVNode(e.Fragment,null,[l.pageConfig.showPageHeader&&n["page-header"]?(C=n["page-header"])==null?void 0:C.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"},[Ce.value.map(p=>{var x,z,$;return e.createVNode("div",{class:"we-vt-header--column",key:p.prop,style:$e(p.width)},[e.createVNode("div",{class:"we-vt-cell"},[(x=p.slots)!=null&&x.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-g*2}px`,...h?{border:b,padding:`${u}px`}:{}}},[o.items.map(p=>{var x,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]===((x=N.value)==null?void 0:x[l.rowConfig.keyField])||((z=l.treeConfig)==null?void 0:z.childCurrent)&&rt.value.includes(p[l.rowConfig.keyField])},style:{width:"100%"},onClick:()=>de(p),onDblclick:()=>ne(p)},[Ce.value.map($=>{var T,R,Z,ie,U,ce,ye;return e.createVNode("div",{key:$.prop,class:"virtual-table-cell we-vt-cell",style:$e($.width),"data-prop":$.prop},[p._editing&&((T=l.editConfig)==null?void 0:T.trigger)==="dblclick"?((R=$.slots)==null?void 0:R.edit)&&((ie=(Z=$.slots)==null?void 0:Z.edit)==null?void 0:ie.call(Z,{row:p,column:$})):((U=$.slots)==null?void 0:U.default)&&((ye=(ce=$.slots)==null?void 0:ce.default)==null?void 0:ye.call(ce,{row:p,column:$}))])})])})]),n["page-footer"]?(m=n["page-footer"])==null?void 0:m.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("加载中...")])])},Nn=()=>{var b;const{pageHeight:o,pageWidth:a,margin:s,gap:g,showPageBorder:h,pageBorderPadding:u}=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:((b=l.editConfig)==null?void 0:b.trigger)==="contenteditable"?"true":void 0,onContextmenu:E,onFocusin:Me,onFocusout:xe},[K.value.map((C,m)=>{const p=Y.value.has(m);return e.createVNode("div",{key:`page-${m}`,class:p?"a4-page":"a4-page-placeholder","data-page-index":m,style:{width:`${a}px`,marginBottom:`${g}px`,padding:p?`${h?s-u: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),On(C,m)])})])])},Hn=()=>{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"},[Ce.value.map(a=>{var s,g,h;return e.createVNode("div",{class:"we-vt-header--column",key:a.prop,style:$e(a.width)},[e.createVNode("div",{class:"we-vt-cell"},[(s=a.slots)!=null&&s.header?(h=(g=a.slots)==null?void 0:g.header)==null?void 0:h.call(g,{column:a}):a.title]),e.createVNode("div",{class:"we-vt-resizable is--line"},null)])})]):void 0,e.createVNode(be.DynamicScroller,{ref:f,items:k.value,minItemSize:O.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:E,onScrollend:vn,onUpdate:Rn,onFocusin:Me,onFocusout:xe},{default:({item:a,index:s,active:g})=>{var u,b,C;let h;return e.createVNode(be.DynamicScrollerItem,{key:a[l.rowConfig.keyField],item:a,active:g,sizeDependencies:[(u=a.content)==null?void 0:u.length,a._editing,a.content_type],"data-id":a[l.rowConfig.keyField],"data-index":s,"data-active":g,class:{"virtual-table-row":!0,"we-vt-body--row":!0,"row--current":a[l.rowConfig.keyField]===((b=N.value)==null?void 0:b[l.rowConfig.keyField])||((C=l.treeConfig)==null?void 0:C.childCurrent)&&rt.value.includes(a[l.rowConfig.keyField])}},Et(h=Ce.value.map(m=>{var p,x,z,$,T,R,Z;return e.createVNode("div",{key:m.prop,class:"virtual-table-cell we-vt-cell",style:$e(m.width),"data-prop":m.prop},[a._editing&&((p=l.editConfig)==null?void 0:p.trigger)==="dblclick"?((x=m.slots)==null?void 0:x.edit)&&(($=(z=m.slots)==null?void 0:z.edit)==null?void 0:$.call(z,{row:a,column:m})):((T=m.slots)==null?void 0:T.default)&&((Z=(R=m.slots)==null?void 0:R.default)==null?void 0:Z.call(R,{row:a,column:m}))])}))?h:{default:()=>[h]})}})])};return()=>l.pageConfig.enabled?Nn():Hn()}}),we=(l,t)=>{const n=l.__vccOpts||l;for(const[i,r]of t)n[i]=r;return n},Mt=we(Bt,[["__scopeId","data-v-274d8f6d"]]),St={name:"VirtualTableColumn",props:{prop:String,label:String,width:[String,Number]}};function It(l,t,n,i,r,f){return e.renderSlot(l.$slots,"default")}const Ft=we(St,[["render",It]]),Tt={class:"catalog-node"},At=["title"],Pt={class:"catalog-node__text"},Lt={key:0,class:"catalog-node__children"},zt=we({__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),f=e.computed(()=>n.item.children&&n.item.children.length>0);function P(I){I.stopPropagation(),r.value=!r.value}return(I,N)=>{const A=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:N[0]||(N[0]=J=>i("navigate",l.item))},[e.createElementVNode("span",{class:"catalog-node__toggle",onClick:P},[f.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),f.value&&r.value?(e.openBlock(),e.createElementBlock("div",Lt,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(l.item.children,J=>(e.openBlock(),e.createBlock(A,{key:J.nodeId,item:J,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"},Dt={key:1,class:"catalog"},vt={class:"catalog__header"},Rt={class:"catalog__title"},Ot={class:"catalog__body"},Nt={key:0,class:"catalog__empty"},Ht=we({__name:"index",props:{items:{type:Array,default:()=>[]}},emits:["navigate"],setup(l,{emit:t}){const n=t,i=e.ref(!1),r=e.ref("");function f(P){r.value=P.nodeId,n("navigate",P)}return(P,I)=>i.value?(e.openBlock(),e.createElementBlock("div",$t,[e.createElementVNode("button",{class:"catalog__icon-btn",title:"展开目录",onClick:I[0]||(I[0]=N=>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}),I[2]||(I[2]=e.createTextVNode(" 目录 ",-1))]),e.createElementVNode("button",{class:"catalog__icon-btn",title:"收起目录",onClick:I[1]||(I[1]=N=>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,N=>(e.openBlock(),e.createBlock(zt,{key:N.nodeId,item:N,"active-id":r.value,onNavigate:f},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 f=jt(r);f&&t.push({id:r.node_id,nodeId:r.node_id,name:(r.content||"").trim(),level:f,children:[]})}if(!t.length)return[];const n=(r,f)=>{const P=f.children[f.children.length-1];P&&r.level>P.level?n(r,P):f.children.push(r)},i=[];for(const r of t){const f=i[i.length-1];f&&r.level>f.level?n(r,f):i.push(r)}return i}const qt={first:0,second:1,third:2,fourth:3,fifth:4,sixth:5,seventh:6,eighth:7};function Ie(l,t){let n="",i=l;const r=t?65:97;for(;i>0;){const f=(i-1)%26;n=String.fromCharCode(r+f)+n,i=Math.floor((i-1)/26)}return n}const Je=[l=>l.toString(),l=>Ie(l,!0),l=>`(${l})`,l=>`(${Ie(l,!1)})`,l=>`${l})`,l=>`${Ie(l,!1)})`,l=>`<${l}>`,l=>`<${Ie(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 f=i+1;f<l.length;f++)l[f]=0;if(n!=null&&n!=="")return`${n} `;const r=Je[Math.min(i,Je.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:0},an=["colspan","rowspan"],rn={key:0},sn=["src"],cn=["href"],dn=["checked"],hn=["checked"],fn=["checked"],Ee=14,ge=1123,Xe=760,Ye=756,un=we({__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 f=null;e.onMounted(()=>{f=new ResizeObserver(y=>{const k={};for(const c of y){const O=c.target._rowKey;if(!O)continue;const d=Math.round(c.contentRect.height);d>(r.value[O]||0)&&(k[O]=d)}Object.keys(k).length&&(r.value={...r.value,...k})})}),e.onUnmounted(()=>{f==null||f.disconnect(),f=null});function P(y,k){!y||!f||(y._rowKey=k,f.observe(y))}const I={left:"left",center:"center",right:"right",alignment:"justify",justify:"justify"};function N(y){const k=[];let c=!1;const O=d=>{if(c){if(d&&d.value!=null&&/^[\n\u200B]+$/.test(d.value)){k.push(d);return}c=!1,k.push({...d,_coverBreakBefore:!0})}else k.push(d)};for(const d of y||[]){if(d&&d.type==="pageBreak"){c=!0;continue}if(d&&d.type==="area"){const L=N(d.valueList||[]);for(const E of L)O(E)}else O(d)}return k}function A(y){const k=N(y),c=[];let O=[],d=0,L=null;const E=M=>{O.length&&(c.push({type:"paragraph",elements:[...O],rowFlex:M}),O=[])},w=()=>{if(d===0)return;const M=L;E(M);for(let D=1;D<d;D++)c.push({type:"paragraph",elements:[],rowFlex:M});d=0,L=null};for(const M of k||[])if(M.type==="table")w(),E(),c.push({type:"table",el:M});else if(M.type==="title")w(),E(),c.push({type:"title",el:M});else if(M.type==="list"){w(),E();const D=[];let _=[];for(const se of M.valueList||[])se.value===`
2
- `||se.value==="​"?(D.push([..._]),_=[]):_.push(se);(_.length||D.length===0)&&D.push([..._]),c.push({type:"list",listType:M.listType||"ul",listStyle:M.listStyle||"disc",items:D})}else if(M.listId){w(),E();const D=M.value==="​"||M.value===""?[]:[M];c.push({type:"list",listType:M.listType||"ul",listStyle:M.listStyle||"disc",items:[D]})}else M.value!=null&&/^[\n\u200B]+$/.test(M.value)?(d+=M.value.length,M.rowFlex&&(L=M.rowFlex)):(w(),O.push(M));return w(),E(),c}function J(y){const k=(y==null?void 0:y.width)||0;return!k||k<=Ye?1:Ye/k}function H(y){const k=y.filter(D=>D.type==="image").reduce((D,_)=>D+(_.height||_.width||0),0),c=y.filter(D=>D.type!=="image").map(D=>D.value||"").join("");if(!c)return k||20;const O=y.reduce((D,_)=>Math.max(D,_.size||0),0)||14,d=O+6,L=(c.match(/[一-龥]/g)||[]).length,E=c.length-L,w=L*O+E*(O*.5),M=Math.max(1,Math.ceil(w/Xe));return k+Math.max(d,M*d)}function K(y){if(!y||!y.length)return[[]];const k=[];let c=[];for(const O of y)O.type==="image"&&(O.width||0)>=Xe?(c.length&&(k.push(c),c=[]),k.push([O])):c.push(O);return c.length&&k.push(c),k.length?k:[[]]}function X(y){if(y.length===0)return[];const k=new Array(y.length).fill(0);y.forEach((L,E)=>{(L.tdList||[]).forEach(w=>{const M=w.rowspan||1;if(M>1){const D=Math.min(E+M-1,y.length-1);k[E]=Math.max(k[E],D);for(let _=1;_<M&&E+_<y.length;_++)k[E+_]=Math.max(k[E+_],D)}})});const c=[];let O=0,d=0;for(let L=0;L<y.length;L++)d=Math.max(d,k[L]),d<=L&&(c.push(y.slice(O,L+1)),O=L+1,d=0);return O<y.length&&c.push(y.slice(O)),c}const Y=e.computed(()=>{const y=A(n.value),k=[];let c=0;const O=Wt(),d={first:0,second:1,third:2,fourth:3,fifth:4,sixth:5,seventh:6,eighth:7};let L=-1;const E=w=>{var M,D,_;return!!((M=w.el)!=null&&M._coverBreakBefore||(_=(D=w.elements)==null?void 0:D[0])!=null&&_._coverBreakBefore)};return y.forEach((w,M)=>{var _,se,pe;const D=E(w);if(D&&(c=0),w.type==="title"){const le=w.el.valueList||[],ee=O.next(w.el.level,(_=w.el.extension)==null?void 0:_.startIndex),Q=le.some(S=>{var G;return(G=S.extension)==null?void 0:G.isIndex});let ae=le;if(!Q&&ee){const S=le[0]||{};ae=[{value:ee,size:S.size,bold:S.bold,italic:S.italic,color:S.color,font:S.font,extension:{isIndex:!0}},...le]}const de=ae.map(S=>S.value||"").join(""),ne=H(ae);c=c+ne>ge&&c>0?ne:c+ne,L=d[w.el.level]??0,k.push({node_id:`blk_${M}_0`,layer:D?1:100,blockType:"title",level:w.el.level,titleEl:w.el,titleValueList:ae,content_type:"text",content:de,height:ne,indentPx:L*20})}else if(w.type==="paragraph"){const le=K(w.elements),ee=L>=0?(L+1)*20:0;le.forEach((Q,ae)=>{const de=Q.map(S=>S.value||"").join(""),ne=H(Q);c=c+ne>ge&&c>0?ne:c+ne,k.push({node_id:`blk_${M}_${ae}`,layer:D&&ae===0?1:100,blockType:"paragraph",elements:Q,rowFlex:w.rowFlex,content_type:"text",content:de,height:ne,indentPx:ee})})}else if(w.type==="table"){const le=!!((se=w.el.extension)!=null&&se.isTitleTable),ee=((pe=w.el.extension)==null?void 0:pe.elementType)==="signOff",Q=le||ee?0:L>=0?(L+1)*20:0,ae=X(w.el.trList||[]),de=ae.length;ae.forEach((ne,S)=>{const G=`blk_${M}_${S}`,Ae=ne.reduce((W,re)=>W+(re.height||re.minHeight||35),0),he=Math.max(Ae,r.value[G]||0);if(he>ge){const W=Math.ceil(he/ge);for(let re=0;re<W;re++){const Me=re*ge,xe=Math.min(ge,he-Me),Pe=re>0||c>0;c=xe,k.push({node_id:`blk_${M}_${S}_s${re}`,layer:D&&S===0&&re===0?1:100,blockType:"table-row-group",content_type:"table-row",rowHeight:he,trGroup:ne,tableEl:w.el,tableRowFlex:w.el.rowFlex||null,isFirst:S===0&&re===0,isLast:S===de-1&&re===W-1,isPageBreak:Pe,sliceOffset:Me,sliceHeight:xe,_baseKey:re===0?G:void 0,height:xe,indentPx:Q})}}else{const W=S>0&&c+he>ge;c=c+he>ge?he:c+he,k.push({node_id:`blk_${M}_${S}`,layer:D&&S===0?1:100,blockType:"table-row-group",content_type:"table-row",rowHeight:he,trGroup:ne,tableEl:w.el,tableRowFlex:w.el.rowFlex||null,isFirst:S===0,isLast:S===de-1,isPageBreak:W,indentPx:Q})}})}else if(w.type==="list"){const le=Math.round(18);let ee=0;for(const Q of w.items)ee+=Q.length?H(Q):le;ee=Math.max(ee,le),c=c+ee>ge&&c>0?ee:c+ee,k.push({node_id:`blk_${M}_0`,layer:D?1:100,blockType:"list",listType:w.listType,listStyle:w.listStyle,items:w.items,height:ee,indentPx:L>=0?(L+1)*20:0})}}),k}),ue=e.computed(()=>Kt(Y.value));function q(y){var k;(k=i.value)==null||k.scrollToRow({node_id:y.nodeId})}function v(y){var L,E;const k=y.elements||[],c=((L=k.find(w=>w.rowFlex))==null?void 0:L.rowFlex)||y.rowFlex,O={textAlign:I[c]||"left"},d=(E=k.find(w=>w.rowMargin))==null?void 0:E.rowMargin;return d&&(O.lineHeight=d),O}function F(y){var L;const k=A(y.value);let c=0,O=0,d=!1;for(const E of k)if(E.type==="paragraph"){if(!E.elements.length)continue;c++;for(const w of E.elements)(w.type==="image"||w.type==="table")&&(d=!0),O+=(w.value||"").length}else E.type==="list"?(c+=((L=E.items)==null?void 0:L.length)||1,d=!0):(c++,d=!0);return c>1||O>30||d?"top":y.verticalAlign||"middle"}function j(y){const k={};y.font&&(k.fontFamily=y.font),k.fontSize=(y.size||Ee)+"px",y.bold!=null&&(k.fontWeight=y.bold?"bold":"normal"),y.italic!=null&&(k.fontStyle=y.italic?"italic":"normal"),y.color&&(k.color=y.color),y.highlight&&y.highlight!=="rgb(255, 255, 255)"&&y.highlight!=="#ffffff"&&(k.backgroundColor=y.highlight);const c=[y.underline&&"underline",y.strikeout&&"line-through"].filter(Boolean).join(" ");return c&&(k.textDecoration=c),y.letterSpacing&&(k.letterSpacing=y.letterSpacing+"px"),k}return(y,k)=>(e.openBlock(),e.createElementBlock("div",Ut,[e.createVNode(Ht,{items:ue.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:Y.value},{default:e.withCtx(()=>[e.createVNode(e.unref(Ft),null,{default:e.withCtx(({row:c})=>{var O;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||[],(d,L)=>(e.openBlock(),e.createElementBlock("span",{key:L,style:e.normalizeStyle(j(d))},e.toDisplayString(d.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,(d,L)=>{var E,w,M,D,_,se,pe,le,ee,Q,ae,de,ne;return e.openBlock(),e.createElementBlock(e.Fragment,{key:L},[!d.type||d.type==="text"?(e.openBlock(),e.createElementBlock("span",{key:0,style:e.normalizeStyle(j(d))},e.toDisplayString(d.value),5)):d.type==="hyperlink"?(e.openBlock(),e.createElementBlock("a",{key:1,href:d.url,class:"doc-link",target:"_blank",rel:"noopener"},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(d.valueList||[],(S,G)=>(e.openBlock(),e.createElementBlock("span",{key:G,style:e.normalizeStyle(j(S))},e.toDisplayString(S.value),5))),128))],8,Yt)):d.type==="image"?(e.openBlock(),e.createElementBlock("img",{key:2,src:d.value,class:"doc-image",style:e.normalizeStyle({width:d.width?d.width+"px":"auto",height:d.height?d.height+"px":"auto"})},null,12,Zt)):d.type==="control"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:3},[((E=d.control)==null?void 0:E.type)==="text"?(e.openBlock(),e.createElementBlock("span",{key:0,style:e.normalizeStyle({fontSize:(d.control.size||12)+"px"})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(d.control.value||[],(S,G)=>(e.openBlock(),e.createElementBlock("span",{key:G,style:e.normalizeStyle(j(S))},e.toDisplayString(S.value),5))),128))],4)):((w=d.control)==null?void 0:w.type)==="input"?(e.openBlock(),e.createElementBlock("span",{key:1,class:"ctrl-input",style:e.normalizeStyle({minWidth:(d.control.minWidth||60)+"px",fontSize:(d.control.size||12)+"px"})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(d.control.value||[],(S,G)=>(e.openBlock(),e.createElementBlock("span",{key:G},e.toDisplayString(S.value),1))),128))],4)):((M=d.control)==null?void 0:M.type)==="radio"?(e.openBlock(),e.createElementBlock("span",{key:2,class:e.normalizeClass(["ctrl-options",{"ctrl-options--vertical":((_=(D=d.control.extension)==null?void 0:D.elementAttributes)==null?void 0:_.layout)==="vertical"}]),style:e.normalizeStyle({fontSize:(d.control.size||Ee)+"px"})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(d.control.valueSets||[],(S,G)=>(e.openBlock(),e.createElementBlock("label",{key:G,class:"ctrl-option"},[e.createElementVNode("input",{type:"radio",disabled:"",checked:d.control.code===S.code},null,8,Qt),e.createTextVNode(" "+e.toDisplayString(S.value),1)]))),128))],6)):((se=d.control)==null?void 0:se.type)==="checkbox"?(e.openBlock(),e.createElementBlock("span",{key:3,class:e.normalizeClass(["ctrl-options",{"ctrl-options--vertical":((le=(pe=d.control.extension)==null?void 0:pe.elementAttributes)==null?void 0:le.layout)==="vertical"}]),style:e.normalizeStyle({fontSize:(d.control.size||Ee)+"px"})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(d.control.valueSets||[],(S,G)=>(e.openBlock(),e.createElementBlock("label",{key:G,class:"ctrl-option"},[e.createElementVNode("input",{type:"checkbox",disabled:"",checked:(d.control.code||"").split(",").includes(S.code)},null,8,en),e.createTextVNode(" "+e.toDisplayString(S.value),1)]))),128))],6)):((ee=d.control)==null?void 0:ee.type)==="select"?(e.openBlock(),e.createElementBlock("span",tn,e.toDisplayString(((ae=(Q=d.control.value)==null?void 0:Q[0])==null?void 0:ae.value)||d.control.placeholder||""),1)):e.createCommentVNode("",!0)],64)):d.type==="checkbox"?(e.openBlock(),e.createElementBlock("input",{key:4,type:"checkbox",checked:!!((de=d.checkbox)!=null&&de.value),disabled:"",class:"el-check"},null,8,nn)):d.type==="radio"?(e.openBlock(),e.createElementBlock("input",{key:5,type:"radio",checked:!!((ne=d.radio)!=null&&ne.value),disabled:"",class:"el-check"},null,8,on)):d.type==="superscript"?(e.openBlock(),e.createElementBlock("sup",{key:6,style:e.normalizeStyle(j(d))},e.toDisplayString(d.value),5)):d.type==="subscript"?(e.openBlock(),e.createElementBlock("sub",{key:7,style:e.normalizeStyle(j(d))},e.toDisplayString(d.value),5)):d.type==="tab"?(e.openBlock(),e.createElementBlock("span",{key:8,class:"doc-tab",style:e.normalizeStyle({width:(d.size||Ee)+"px"})},null,4)):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,(d,L)=>(e.openBlock(),e.createElementBlock("li",{key:L,class:"doc-list-item"},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(d,(E,w)=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:w},[!E.type||E.type==="text"?(e.openBlock(),e.createElementBlock("span",{key:0,style:e.normalizeStyle(j(E))},e.toDisplayString(E.value),5)):E.type==="superscript"?(e.openBlock(),e.createElementBlock("sup",{key:1,style:e.normalizeStyle(j(E))},e.toDisplayString(E.value),5)):E.type==="subscript"?(e.openBlock(),e.createElementBlock("sub",{key:2,style:e.normalizeStyle(j(E))},e.toDisplayString(E.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?d=>P(d,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*J(c.tableEl)+"px":"100%",transform:c.sliceOffset?`translateY(-${c.sliceOffset}px)`:void 0})},[(O=c.tableEl.colgroup)!=null&&O.length?(e.openBlock(),e.createElementBlock("colgroup",ln,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(c.tableEl.colgroup,(d,L)=>(e.openBlock(),e.createElementBlock("col",{key:L,style:e.normalizeStyle({width:d.width*J(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,(d,L)=>(e.openBlock(),e.createElementBlock("tr",{key:L,style:e.normalizeStyle({height:(d.height||d.minHeight||30)+"px"})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(d.tdList||[],(E,w)=>(e.openBlock(),e.createElementBlock("td",{key:w,colspan:E.colspan||1,rowspan:E.rowspan||1,style:e.normalizeStyle({backgroundColor:E.backgroundColor||void 0,verticalAlign:F(E),width:E.width?E.width*J(c.tableEl)+"px":void 0,height:E.height?E.height+"px":void 0})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(A(E.value),(M,D)=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:D},[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",rn," ")),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(M.elements,(_,se)=>{var pe,le,ee,Q,ae,de,ne;return e.openBlock(),e.createElementBlock(e.Fragment,{key:se},[!_.type||_.type==="text"?(e.openBlock(),e.createElementBlock("span",{key:0,style:e.normalizeStyle(j(_))},e.toDisplayString(_.value),5)):_.type==="image"?(e.openBlock(),e.createElementBlock("img",{key:1,src:_.value,class:"doc-image",style:e.normalizeStyle({width:_.width?_.width+"px":"auto",height:_.height?_.height+"px":"auto"})},null,12,sn)):_.type==="hyperlink"?(e.openBlock(),e.createElementBlock("a",{key:2,href:_.url,class:"doc-link",target:"_blank"},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(_.valueList||[],(S,G)=>(e.openBlock(),e.createElementBlock("span",{key:G,style:e.normalizeStyle(j(S))},e.toDisplayString(S.value),5))),128))],8,cn)):_.type==="control"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:3},[((pe=_.control)==null?void 0:pe.type)==="text"?(e.openBlock(),e.createElementBlock("span",{key:0,style:e.normalizeStyle({fontSize:(_.control.size||12)+"px"})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(_.control.value||[],(S,G)=>(e.openBlock(),e.createElementBlock("span",{key:G,style:e.normalizeStyle(j(S))},e.toDisplayString(S.value),5))),128))],4)):((le=_.control)==null?void 0:le.type)==="input"?(e.openBlock(),e.createElementBlock("span",{key:1,class:"ctrl-input",style:e.normalizeStyle({fontSize:(_.control.size||12)+"px"})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(_.control.value||[],(S,G)=>(e.openBlock(),e.createElementBlock("span",{key:G},e.toDisplayString(S.value),1))),128))],4)):((ee=_.control)==null?void 0:ee.type)==="radio"?(e.openBlock(),e.createElementBlock("span",{key:2,class:e.normalizeClass(["ctrl-options",{"ctrl-options--vertical":((ae=(Q=_.control.extension)==null?void 0:Q.elementAttributes)==null?void 0:ae.layout)==="vertical"}])},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(_.control.valueSets||[],(S,G)=>(e.openBlock(),e.createElementBlock("label",{key:G,class:"ctrl-option"},[e.createElementVNode("input",{type:"radio",disabled:"",checked:_.control.code===S.code},null,8,dn),e.createTextVNode(e.toDisplayString(S.value),1)]))),128))],2)):e.createCommentVNode("",!0)],64)):_.type==="checkbox"?(e.openBlock(),e.createElementBlock("input",{key:4,type:"checkbox",checked:!!((de=_.checkbox)!=null&&de.value),disabled:"",class:"el-check"},null,8,hn)):_.type==="radio"?(e.openBlock(),e.createElementBlock("input",{key:5,type:"radio",checked:!!((ne=_.radio)!=null&&ne.value),disabled:"",class:"el-check"},null,8,fn)):_.type==="superscript"?(e.openBlock(),e.createElementBlock("sup",{key:6,style:e.normalizeStyle(j(_))},e.toDisplayString(_.value),5)):_.type==="subscript"?(e.openBlock(),e.createElementBlock("sub",{key:7,style:e.normalizeStyle(j(_))},e.toDisplayString(_.value),5)):_.type==="tab"?(e.openBlock(),e.createElementBlock("span",{key:8,class:"doc-tab",style:e.normalizeStyle({width:(_.size||Ee)+"px"})},null,4)):e.createCommentVNode("",!0)],64)}),128))],4)):e.createCommentVNode("",!0)],64))),128))],12,an))),128))],4))),128))])],6)],4)],6)):e.createCommentVNode("",!0)]}),_:1})]),_:1},8,["data"]))])]))}},[["__scopeId","data-v-fbf35559"]]),Ze="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";function Fe(l=10){const t=crypto.getRandomValues(new Uint8Array(l));return Array.from(t).map(n=>Ze[n%Ze.length]).join("")}class Te{constructor(t){V(this,"data");this.data=e.reactive({id:Fe(),version:1,sections:[this.createEmptySection()],pageWidth:595,pageHeight:842,marginTop:72,marginBottom:72,marginLeft:90,marginRight:90,...t})}createEmptySection(){return{id:Fe(),paragraphs:[this.createEmptyParagraph()]}}createEmptyParagraph(t){return{id:Fe(),type:"paragraph",format:t??{},children:[]}}createTextElement(t,n){return{id:Fe(),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,f)=>{t.push({paragraph:r,sectionIndex:i,paragraphIndex:f})})}),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 f=r.children[t.elementIndex];if(f&&f.type==="text")f.value=f.value.slice(0,t.offset)+n+f.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 f=this.createEmptyParagraph(i);return r.paragraphs.splice(n+1,0,f),this.bumpVersion(),f}mergeParagraphs(t,n){const i=this.data.sections[t];if(!i)return;const r=i.paragraphs[n],f=i.paragraphs[n+1];!r||!f||(r.children.push(...f.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 f=!1;for(const{paragraph:P,sectionIndex:I,paragraphIndex:N}of r){const A=I===t.sectionIndex&&N===t.paragraphIndex,J=I===n.sectionIndex&&N===n.paragraphIndex;if(A&&(f=!0),f)for(let H=0;H<P.children.length;H++){const K=P.children[H];if(!(A&&H<t.elementIndex)){if(J&&H>n.elementIndex)break;K.format={...K.format,...i}}}if(J)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 Te;return Object.assign(i.data,n),i}}function ke(l=0,t=0,n=0,i=0){return{sectionIndex:l,paragraphIndex:t,elementIndex:n,offset:i}}function Qe(l,t){return l.sectionIndex===t.sectionIndex&&l.paragraphIndex===t.paragraphIndex&&l.elementIndex===t.elementIndex&&l.offset===t.offset}class Ne{constructor(t){V(this,"_selection",e.reactive({anchor:ke(),focus:ke(),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=Qe(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],f=(r==null?void 0:r.type)==="text"?r.value.length:0;this._selection.anchor=ke(0,0,0,0),this._selection.focus=ke(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,f),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 f=this._getNextParagraphPoint(n);f&&this._applyMove(f,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),f=r==null?void 0:r.children[n.elementIndex-1],P=(f==null?void 0:f.type)==="text"?f.value.length:0,I={...n,elementIndex:n.elementIndex-1,offset:P};this._applyMove(I,t);return}const i=this._getPrevParagraphPoint(n);i&&this._applyMove(i,t)}_applyMove(t,n){n?(this._selection.focus=t,this._selection.isCollapsed=Qe(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?ke(t.sectionIndex,t.paragraphIndex+1,0,0):t.sectionIndex<this._docModel.data.sections.length-1?ke(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],f=(r==null?void 0:r.type)==="text"?r.value.length:0;return ke(t.sectionIndex,t.paragraphIndex-1,Math.max(i,0),f)}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],f=((r==null?void 0:r.children.length)??0)-1,P=r==null?void 0:r.children[f],I=(P==null?void 0:P.type)==="text"?P.value.length:0;return ke(t.sectionIndex-1,i,Math.max(f,0),I)}return null}static domToModelPoint(t,n){let i=t instanceof Element?t:t.parentElement;for(;i;){const r=i.getAttribute("data-si"),f=i.getAttribute("data-pi"),P=i.getAttribute("data-ei");if(r!==null&&f!==null&&P!==null)return{sectionIndex:parseInt(r),paragraphIndex:parseInt(f),elementIndex:parseInt(P),offset:n};i=i.parentElement}return null}}const gn=200;class pn{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>gn&&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 mn{constructor(t,n,i,r,f){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=f}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 yn{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 f=t.elementIndex,P=r.children.splice(f),I=this.docModel.createEmptyParagraph(r.format);I.children.push(...P),this._insertedParagraphId=I.id,this.docModel.data.sections[n].paragraphs.splice(i+1,0,I),(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 et{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 Be{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 f=this._getCurrentValue(i);r[i]=!f}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 He{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 kn{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 mn(this.docModel,this.selectionManager,i,n)}),this.register("insertParagraph",()=>new yn(this.docModel,this.selectionManager)),this.register("deleteBackward",()=>new et(this.docModel,this.selectionManager,"backward")),this.register("deleteForward",()=>new et(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 He(this.docModel,this.selectionManager,"textAlign",n)),this.register("lineHeight",n=>new He(this.docModel,this.selectionManager,"lineHeight",n)),this.register("heading",n=>new He(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 _n{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=Ne.domToModelPoint(n,t.anchorOffset),f=Ne.domToModelPoint(i,t.focusOffset);r&&f&&this._selectionManager.setSelection(r,f)}}class tt{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 Te(t.initialDocument),this.selection=new Ne(this.docModel),this.history=new pn,this.commands=new kn(this.docModel,this.selection,this.history),this.input=new _n(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=Te.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 Ve=Symbol("editor");function bn(l){const t=new tt(l);return e.provide(Ve,t),e.onUnmounted(()=>{t.unmount()}),t}function xn(){const l=e.inject(Ve);if(!l)throw new Error("[useEditor] 必须在 EditorContainer 组件内使用");return l}const nt=un,Cn={install(l){l.component("EditorContainer",nt)}};oe.Editor=tt,oe.EditorContainer=nt,oe.EditorKey=Ve,oe.createEditor=bn,oe.default=Cn,oe.useEditor=xn,Object.defineProperties(oe,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});