@coco-vexel/coco-office-editor 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,15 +1,22 @@
1
- 'use strict';var pack=require('@coco-vexel/coco-office/pack'),wordView=require('@coco-vexel/coco-office/word-view'),prosemirrorState=require('prosemirror-state'),prosemirrorModel=require('prosemirror-model');require('prosemirror-commands'),require('prosemirror-keymap'),require('prosemirror-view');var excel=require('@coco-vexel/coco-office/excel'),ppt=require('@coco-vexel/coco-office/ppt');var lh=Object.defineProperty,dh=Object.defineProperties;var ch=Object.getOwnPropertyDescriptors;var Ro=Object.getOwnPropertySymbols;var ld=Object.prototype.hasOwnProperty,dd=Object.prototype.propertyIsEnumerable;var ka=(e,t,n)=>t in e?lh(e,t,{enumerable:true,configurable:true,writable:true,value:n}):e[t]=n,v=(e,t)=>{for(var n in t||(t={}))ld.call(t,n)&&ka(e,n,t[n]);if(Ro)for(var n of Ro(t))dd.call(t,n)&&ka(e,n,t[n]);return e},$=(e,t)=>dh(e,ch(t));var In=(e,t)=>{var n={};for(var r in e)ld.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Ro)for(var r of Ro(e))t.indexOf(r)<0&&dd.call(e,r)&&(n[r]=e[r]);return n};var O=(e,t,n)=>ka(e,typeof t!="symbol"?t+"":t,n);var ln=class extends Error{constructor(n){super(`${n} editor is read-only`);O(this,"code","EDITOR_READ_ONLY");this.name="EditorReadOnlyError";}};var Sd="http://schemas.openxmlformats.org/officeDocument/2006/relationships",xh="http://schemas.openxmlformats.org/package/2006/relationships",Zt="http://schemas.openxmlformats.org/drawingml/2006/main",cd="urn:schemas-microsoft-com:vml",yh={firstRow:true,lastRow:false,firstColumn:true,lastColumn:false,noHorizontalBand:false,noVerticalBand:true};async function hE(e){let t=await pack.fromZip(e);return Na(t,wordView.buildIndices(t))}function gE(e){let t=pack.fromFlatOpc(e);return Na(t,wordView.buildIndices(t))}async function bE(e){return Na(e._getPackage(),e._getIndices())}function Na(e,t){var g;let n=[],r=[],o=[],i=new Set,s=new Map(wordView.listTables(e,t,{scope:"all",includeNested:true,includeCellTexts:true}).map(h=>[h.tableId,h])),a=new Map;for(let[h,y]of t.tblIdx)a.set(y,h);let l=new Map,c=new Map(wordView.listDrawings(e,t,{scope:"all"}).map(h=>[h.drawingId,h])),u=new Map;for(let h of c.values()){if(!h.anchorParaId)continue;let y=(g=u.get(h.anchorParaId))!=null?g:[];y.push(h),u.set(h.anchorParaId,y);}let f=new Map;for(let[h,y]of t.drawingIdx){l.set(y,h);let k=Qh(e,t,h,c.get(h));k&&f.set(h,k);}let p=Eh(e),w={indices:t,drawingIdByElement:l,drawingInfoById:c,drawingsByAnchorParaId:u,imagesByDrawingId:f,theme:p,documentDefaults:ng(e,p),numbering:rg(e),numberingCounters:new Map,defaultParagraphStyleId:cg(e),paragraphStyleFormats:dg(e,t,p),tableStyleFormats:ug(e,p),hyperlinkByElement:Ph(e)};for(let h of wordView.listStories(e,{kinds:["body"]})){let y=Id(h.id,h.root,{context:w,attachedCommentIds:i,tableIdByElement:a,tableInfoById:s});n.push(...y.blocks),r.push(...y.paragraphs),o.push(...y.tables);}let b=Rh(e,{context:w,attachedCommentIds:i,tableIdByElement:a,tableInfoById:s});return {kind:"word",defaults:w.documentDefaults,pageLayout:vh(e),sections:Ih(e),headers:b.headers,footers:b.footers,blocks:n,paragraphs:r,tables:o,detachedComments:Ng(t,i),detachedRevisions:[]}}function vh(e){let t=e.parts.get("word/document.xml"),n=t==null?void 0:t.xmlDom;if(!n)return;let r=n.getElementsByTagNameNS(wordView.W_NS,"body")[0];if(!r)return;let o=kh(r);if(o)return kd(o)}function kd(e){var f,p,w,b;let t=U(e,wordView.W_NS,"pgSz"),n=U(e,wordView.W_NS,"pgMar"),r=Cg(e,wordView.W_NS,"docGrid"),o=t?Me(t,"w"):void 0,i=t?Me(t,"h"):void 0;if(o===void 0||i===void 0)return;let s=t?t.getAttributeNS(wordView.W_NS,"orient"):null,a={width:o,height:i,margin:{top:n&&(f=Me(n,"top"))!=null?f:1440,right:n&&(p=Me(n,"right"))!=null?p:1440,bottom:n&&(w=Me(n,"bottom"))!=null?w:1440,left:n&&(b=Me(n,"left"))!=null?b:1440}},l=n?Me(n,"header"):void 0,c=n?Me(n,"footer"):void 0;l!==void 0&&(a.headerDistance=l),c!==void 0&&(a.footerDistance=c);let u=r?Sh(r):void 0;return u&&(a.docGrid=u),s==="landscape"?a.orientation="landscape":s==="portrait"&&(a.orientation="portrait"),a}function Sh(e){let t=e.getAttributeNS(wordView.W_NS,"type"),n=t==="default"||t==="lines"||t==="linesAndChars"||t==="snapToChars"?t:void 0,r=Me(e,"linePitch"),o=Me(e,"charSpace");if(!(n===void 0&&r===void 0&&o===void 0))return v(v(v({},n!==void 0?{type:n}:{}),r!==void 0?{linePitch:r}:{}),o!==void 0?{charSpace:o}:{})}function kh(e){for(let t=e.childNodes.length-1;t>=0;t--){let n=e.childNodes[t];if(!n||n.nodeType!==1)continue;let r=n;if(r.namespaceURI===wordView.W_NS){if(r.localName==="sectPr")return r;if(r.localName==="p"){let o=U(r,wordView.W_NS,"pPr"),i=o?U(o,wordView.W_NS,"sectPr"):null;if(i)return i}}}return null}function Eh(e){var i;let t={colors:new Map,fonts:new Map},n=(i=e.parts.get("word/theme/theme1.xml"))==null?void 0:i.xmlDom;if(!n)return t;let r=n.getElementsByTagNameNS(Zt,"clrScheme")[0];if(r)for(let s of ["dk1","lt1","dk2","lt2","accent1","accent2","accent3","accent4","accent5","accent6","hlink","folHlink"]){let a=Ch(r,s);a&&t.colors.set(s,a);}let o=n.getElementsByTagNameNS(Zt,"fontScheme")[0];return o&&(ud(t.fonts,U(o,Zt,"majorFont"),"major"),ud(t.fonts,U(o,Zt,"minorFont"),"minor")),t}function Ch(e,t){var r;let n=U(e,Zt,t);if(n)for(let o=0;o<n.childNodes.length;o++){let i=n.childNodes[o];if(!i||i.nodeType!==1||i.namespaceURI!==Zt)continue;let s=i,a=(r=s.getAttribute("val"))!=null?r:s.getAttribute("lastClr"),l=Aa(a);if(l)return l}}function ud(e,t,n){if(!t)return;let r=Ea(U(t,Zt,"latin")),o=Ea(U(t,Zt,"ea"))||r,i=Ea(U(t,Zt,"cs"))||r;r&&(e.set(`${n}Ascii`,r),e.set(`${n}HAnsi`,r)),o&&e.set(`${n}EastAsia`,o),i&&e.set(`${n}Bidi`,i);}function Ea(e){var n;let t=(n=e==null?void 0:e.getAttribute("typeface"))!=null?n:void 0;return t&&t.length>0?t:void 0}function Ih(e){let t=Nh(e);if(t.length>0)return t;let n=wordView.listSections(e);return n.length>0?n.map(r=>{var o,i;return $(v({sectionIndex:r.sectionIndex,firstParaId:r.firstParaId,lastParaId:r.lastParaId},r.type?{type:r.type}:{}),{headerRefs:(o=r.headerRefs)!=null?o:[],footerRefs:(i=r.footerRefs)!=null?i:[],titlePage:r.titlePage===true})}):[]}function Nh(e){let t=wordView.listStories(e,{kinds:["body"]})[0];if(!t)return [];let n=Cd(t.partPath),r=[],o,i,s=0;for(let a=0;a<t.root.childNodes.length;a++){let l=t.root.childNodes[a];if(!l||l.nodeType!==1)continue;let c=l;if(c.namespaceURI===wordView.W_NS){if(c.localName==="p"){let u=Ta("body",c,s++);o||(o=u),i=u;let f=Lo(c,wordView.W_NS,["pPr","sectPr"]);f&&o&&i&&(r.push(pd(r.length,o,i,f,e,n)),o=void 0);continue}if(c.localName==="tbl"){s++;continue}c.localName==="sectPr"&&o&&i&&(r.push(pd(r.length,o,i,c,e,n)),o=void 0);}}return r}function pd(e,t,n,r,o,i){var f;let s={sectionIndex:e,firstParaId:t,lastParaId:n,headerRefs:fd(o,r,i,"headerReference"),footerRefs:fd(o,r,i,"footerReference"),titlePage:U(r,wordView.W_NS,"titlePg")!==null},a=kd(r);a&&(s.pageLayout=a);let l=U(r,wordView.W_NS,"pgNumType"),c=l?Me(l,"start"):void 0;c!==void 0&&(s.pageNumberStart=c);let u=(f=U(r,wordView.W_NS,"type"))==null?void 0:f.getAttributeNS(wordView.W_NS,"val");return (u==="nextPage"||u==="continuous"||u==="evenPage"||u==="oddPage"||u==="nextColumn")&&(s.type=u),s}function fd(e,t,n,r){if(!n)return [];let o=Ed(e,n);if(!o)return [];let i=[];for(let s of ht(t,wordView.W_NS,r)){let a=s.getAttributeNS(Sd,"id");if(!a)continue;let l=o.get(a);if(!l)continue;let c=s.getAttributeNS(wordView.W_NS,"type");i.push({type:c==="first"||c==="even"?c:"default",partName:Th(n,l)});}return i}function Ed(e,t){let n=e.parts.get(t),r=n==null?void 0:n.xmlDom;if(!r)return null;let o=new Map,i=r.getElementsByTagNameNS(xh,"Relationship");for(let s=0;s<i.length;s++){let a=i[s],l=a==null?void 0:a.getAttribute("Id"),c=a==null?void 0:a.getAttribute("Target");l&&c&&o.set(l,c);}return o}function Th(e,t){if(t.startsWith("/"))return t.slice(1);let r=e.lastIndexOf("/_rels/");return r<0?t:`${e.slice(0,r)}/${t}`.replace(/\\/g,"/")}function Cd(e){let t=e.lastIndexOf("/"),n=t>=0?e.slice(0,t):"",r=e.slice(t+1);return n.length>0?`${n}/_rels/${r}.rels`:`_rels/${r}.rels`}function Ph(e){var n,r;let t=new Map;for(let o of wordView.listStories(e,{kinds:["body","header","footer"]})){let i=Cd(o.partPath),s=i?Ed(e,i):null,a=o.root.getElementsByTagNameNS(wordView.W_NS,"hyperlink");for(let l=0;l<a.length;l+=1){let c=a[l];if(!c)continue;let u=c.getAttributeNS(Sd,"id"),f=u?s==null?void 0:s.get(u):void 0,p=(n=c.getAttributeNS(wordView.W_NS,"anchor"))!=null?n:void 0,w=(r=c.getAttributeNS(wordView.W_NS,"tooltip"))!=null?r:void 0;!f&&!p||t.set(c,v(v(v({},f?{target:f}:{}),p?{anchor:p}:{}),w?{tooltip:w}:{}));}}return t}function Ta(e,t,n){var r;return ((r=t.getAttributeNS(wordView.W14_NS,"paraId"))==null?void 0:r.toUpperCase())||`${e}:p:${n}`}function Id(e,t,n){let r=[],o=[],i=[],s=n.flattenSdt?Mh(t,n.suppressPlaceholderSdtContent===true):Nd(t);for(let a=0;a<s.length;a++){let l=s[a];if(l.localName==="p"){let c=Bo(e,l,n.context,n.attachedCommentIds,Ta(e,l,a),n.suppressPlaceholderSdtContent===true);r.push(c),o.push(c);}else if(l.localName==="tbl"){let c=n.tableIdByElement.get(l),u=c?n.tableInfoById.get(c):void 0;if(!c||!u)continue;let f=Td(u,l,e,n.context,n.attachedCommentIds,n.tableIdByElement,n.tableInfoById,n.suppressPlaceholderSdtContent===true);r.push(f),i.push(f),o.push(...Pd(f)),i.push(...Md(f));}}return {blocks:r,paragraphs:o,tables:i}}function Nd(e){let t=[];for(let n=0;n<e.childNodes.length;n++){let r=e.childNodes[n];if(!r||r.nodeType!==1||r.namespaceURI!==wordView.W_NS)continue;let o=r;(o.localName==="p"||o.localName==="tbl")&&t.push(o);}return t}function Mh(e,t=false){let n=[],r=o=>{if(o.namespaceURI===wordView.W_NS&&!(t&&Zd(o))){if(o.localName==="p"||o.localName==="tbl"){n.push(o);return}if(!(o.localName!=="sdt"&&o.localName!=="sdtContent"))for(let i=0;i<o.childNodes.length;i++){let s=o.childNodes[i];(s==null?void 0:s.nodeType)===1&&r(s);}}};for(let o=0;o<e.childNodes.length;o++){let i=e.childNodes[o];(i==null?void 0:i.nodeType)===1&&r(i);}return n}function Rh(e,t){let n=[],r=[];for(let o of wordView.listStories(e,{kinds:["header","footer"]})){if(o.kind!=="header"&&o.kind!=="footer")continue;let i=Id(o.id,o.root,$(v({},t),{flattenSdt:true,suppressPlaceholderSdtContent:true})),s={kind:o.kind,partName:o.partPath,blocks:i.blocks,paragraphs:i.paragraphs,tables:i.tables};o.kind==="header"?n.push(s):r.push(s);}return {headers:n,footers:r}}function Bo(e,t,n,r,o,i=false){let s=wordView.buildParagraphInfo(e,t,"full",true,{structuralWhitespace:true}),a=s.paraId||o||"",l=Xh(t,a,n,i);for(let g of l.spans)g.kind==="comment"&&r.add(g.commentId);let c={type:"paragraph",paraId:a,story:s.story,text:l.text,flags:{hasComments:s.hasComments===true,hasRevisions:s.hasRevisions===true,hasBookmarks:s.hasBookmarks===true,hasMath:s.hasMath===true},segments:l.segments,spans:l.spans};s.styleId!==void 0&&(c.styleId=s.styleId);let u=s.styleId!==void 0?n.paragraphStyleFormats.get(s.styleId):n.defaultParagraphStyleId?n.paragraphStyleFormats.get(n.defaultParagraphStyleId):void 0,f=Ah(t,n.theme),p=yr(Lo(t,wordView.W_NS,["pPr"]),n.theme),w=Bt(Bt(Bt(n.documentDefaults.paragraph,u),f),s.format),b=Bt(w,p);return b!=null&&b.numbering&&(b.numbering=ag(b.numbering,n),og(b,n)),b!==void 0&&(c.format=b),s.table!==void 0&&(c.table=s.table),c}function Ah(e,t){for(let n of ht(e,wordView.W_NS,"r")){let r=Yt(n,t);if(r)return r}for(let n of ht(e,wordView.W_NS,"hyperlink")){let r=ht(n,wordView.W_NS,"r")[0],o=r?Yt(r,t):void 0;if(o)return o}for(let n of ["ins","del","fldSimple"])for(let r of ht(e,wordView.W_NS,n)){let o=ht(r,wordView.W_NS,"r")[0],i=o?Yt(o,t):void 0;if(i)return i}}function Td(e,t,n,r,o,i,s,a=false){var y,k,C,N,L;let l=Kh((y=e.cellGrid)!=null?y:[]),c=Oh(t),u=Hh(t),f=e.tableStyleId?r.tableStyleFormats.get(e.tableStyleId):void 0,p=(k=$h(t))!=null?k:f==null?void 0:f.cellMargin,w=(C=Vh(t))!=null?C:f==null?void 0:f.borders,b=Bh(t),g=Ad(f==null?void 0:f.tableLook,Fh(t)),h=0;return $(v(v(v($(v({type:"table",tableId:e.tableId},e.tableStyleId?{tableStyleId:e.tableStyleId}:{}),{columnWidths:e.columnWidths}),b?{layout:b}:{}),g?{tableLook:g}:{}),w?{borders:w}:{}),{rows:(L=(N=e.cellGrid)==null?void 0:N.map((D,W)=>{let V=Wh(c[W]);return $(v(v(v({},e.rowHeights[W]?{height:e.rowHeights[W]}:{}),V.isHeader?{isHeader:true}:{}),V.cantSplit?{cantSplit:true}:{}),{cells:D.map((ee,pe)=>{var ye,ke,Ae,Fe,Ge,Qe,wt,an,dt,Ct,pt,Ye,Vt,ct,_t;let re=f?_h(f,W,pe,(ye=e.cellGrid)!=null?ye:[],g):void 0,we=u[h++],he=we?Lh(we,{storyId:n,tableId:e.tableId,context:r,attachedCommentIds:o,tableIdByElement:i,tableInfoById:s,suppressPlaceholderSdtContent:a}):void 0,xe=he!=null&&he.paragraphs.length?he.paragraphs:ee.paragraphIds.map(It=>r.indices.paraIdx.get(It.toUpperCase())).filter(It=>It!==void 0).map(It=>Bo(n,It,r,o,void 0,a)),Ve=xe.length>0?xe:Uh(e.tableId,W,pe,ee.text),z={text:ee.text,gridSpan:ee.gridSpan,vMerge:ee.vMerge,blocks:he!=null&&he.blocks.length?he.blocks:Ve,paragraphs:Ve};if(re!=null&&re.paragraphFormat)for(let It of (ke=he==null?void 0:he.directParagraphs)!=null?ke:z.paragraphs)It.format=Bt(re.paragraphFormat,It.format);let Z=l.get(`${W}:${pe}`);Z!==void 0&&Z>1&&(z.rowSpan=Z),ee.width!==void 0&&(z.width=ee.width);let H=zh(we,r.theme),Y=(wt=(Qe=(Fe=H==null?void 0:H.margin)!=null?Fe:(Ae=re==null?void 0:re.cell)==null?void 0:Ae.margin)!=null?Qe:(Ge=f==null?void 0:f.cell)==null?void 0:Ge.margin)!=null?wt:p;Y&&(z.margin=Y);let X=(pt=(dt=H==null?void 0:H.borders)!=null?dt:(an=re==null?void 0:re.cell)==null?void 0:an.borders)!=null?pt:(Ct=f==null?void 0:f.cell)==null?void 0:Ct.borders;return X&&(z.borders=X),((Ye=f==null?void 0:f.cell)==null?void 0:Ye.shading)!==void 0&&(z.shading=f.cell.shading),((Vt=re==null?void 0:re.cell)==null?void 0:Vt.shading)!==void 0&&(z.shading=re.cell.shading),ee.shading!==void 0&&(z.shading=ee.shading),(H==null?void 0:H.shading)!==void 0&&(z.shading=H.shading),((ct=f==null?void 0:f.cell)==null?void 0:ct.verticalAlignment)!==void 0&&(z.verticalAlignment=f.cell.verticalAlignment),((_t=re==null?void 0:re.cell)==null?void 0:_t.verticalAlignment)!==void 0&&(z.verticalAlignment=re.cell.verticalAlignment),(H==null?void 0:H.verticalAlignment)!==void 0&&(z.verticalAlignment=H.verticalAlignment),ee.verticalAlignment!==void 0&&(z.verticalAlignment=ee.verticalAlignment),(H==null?void 0:H.noWrap)!==void 0&&(z.noWrap=H.noWrap),z})})}))!=null?L:[]})}function Lh(e,t){let n=[],r=[],o=[],i=Nd(e);for(let s=0;s<i.length;s+=1){let a=i[s];if(a.localName==="p"){let f=Bo(t.storyId,a,t.context,t.attachedCommentIds,Ta(t.storyId,a,s),t.suppressPlaceholderSdtContent);n.push(f),r.push(f),o.push(f);continue}let l=t.tableIdByElement.get(a),c=l?t.tableInfoById.get(l):void 0;if(!l||!c)continue;let u=Td(c,a,t.storyId,t.context,t.attachedCommentIds,t.tableIdByElement,t.tableInfoById,t.suppressPlaceholderSdtContent);n.push(u),r.push(...Pd(u));}return {blocks:n,paragraphs:r,directParagraphs:o}}function Pd(e){return e.rows.flatMap(t=>t.cells.flatMap(n=>n.paragraphs))}function Md(e){return e.rows.flatMap(t=>t.cells.flatMap(n=>n.blocks.flatMap(r=>r.type==="table"?[r,...Md(r)]:[])))}function Wh(e){let t={};if(!e)return t;let n=U(e,wordView.W_NS,"trPr");if(!n)return t;let r=it(U(n,wordView.W_NS,"tblHeader"));(r!==void 0?r:U(n,wordView.W_NS,"tblHeader")!==null)&&(t.isHeader=true);let o=it(U(n,wordView.W_NS,"cantSplit"));return (o!==void 0?o:U(n,wordView.W_NS,"cantSplit")!==null)&&(t.cantSplit=true),t}function Bh(e){let t=U(e,wordView.W_NS,"tblPr");if(!t)return;let n={},r=U(t,wordView.W_NS,"tblW");if(r){let c=Me(r,"w"),u=hd(r.getAttributeNS(wordView.W_NS,"type"));c!==void 0&&(n.width=c),u!==void 0&&(n.widthType=u);}let o=U(t,wordView.W_NS,"tblInd"),i=o?Me(o,"w"):void 0;i!==void 0&&(n.indent=i);let s=U(t,wordView.W_NS,"tblCellSpacing");if(s){let c=Me(s,"w"),u=hd(s.getAttributeNS(wordView.W_NS,"type"));c!==void 0&&(n.cellSpacing=c),u!==void 0&&(n.cellSpacingType=u);}let a=U(t,wordView.W_NS,"jc"),l=a?Dh(a.getAttributeNS(wordView.W_NS,"val")):void 0;return l!==void 0&&(n.alignment=l),Object.keys(n).length>0?n:void 0}function Fh(e){let t=U(e,wordView.W_NS,"tblPr");if(t)return Rd(t)}function Rd(e){var g;let t=U(e,wordView.W_NS,"tblLook"),n={},r=(g=t==null?void 0:t.getAttributeNS(wordView.W_NS,"val"))!=null?g:null,o=r?Number.parseInt(r,16):Number.NaN,i=h=>Number.isFinite(o)?(o&h)!==0:void 0,s=(h,y)=>{var C;let k=(C=t==null?void 0:t.getAttributeNS(wordView.W_NS,h))!=null?C:null;return k!==null?Yd(k):i(y)},a=s("firstRow",32);a!==void 0&&(n.firstRow=a);let l=s("lastRow",64);l!==void 0&&(n.lastRow=l);let c=s("firstColumn",128);c!==void 0&&(n.firstColumn=c);let u=s("lastColumn",256);u!==void 0&&(n.lastColumn=u);let f=s("noHBand",512);f!==void 0&&(n.noHorizontalBand=f);let p=s("noVBand",1024);p!==void 0&&(n.noVerticalBand=p);let w=md(U(e,wordView.W_NS,"tblStyleRowBandSize"));w!==void 0&&(n.rowBandSize=w);let b=md(U(e,wordView.W_NS,"tblStyleColBandSize"));return b!==void 0&&(n.columnBandSize=b),Object.keys(n).length>0?n:void 0}function Ad(e,t){if(!(!e&&!t))return v(v({},e!=null?e:{}),t!=null?t:{})}function md(e){let t=e?Me(e,"val"):void 0;return t!==void 0&&t>0?t:void 0}function hd(e){if(e==="auto"||e==="dxa"||e==="pct")return e}function Dh(e){if(e==="left"||e==="center"||e==="right")return e}function Hh(e){let t=[];for(let n of ht(e,wordView.W_NS,"tr"))t.push(...ht(n,wordView.W_NS,"tc"));return t}function Oh(e){return ht(e,wordView.W_NS,"tr")}function $h(e){let t=U(e,wordView.W_NS,"tblPr"),n=t?U(t,wordView.W_NS,"tblCellMar"):null;return Pa(n)}function zh(e,t){if(e)return Ra(U(e,wordView.W_NS,"tcPr"),t)}function Pa(e){if(!e)return;let t={};for(let n of ["top","right","bottom","left"]){let r=U(e,wordView.W_NS,n),o=r?Me(r,"w"):void 0;o!==void 0&&(t[n]=o);}return Object.keys(t).length>0?t:void 0}function Vh(e){let t=U(e,wordView.W_NS,"tblPr");return t?Ld(t):void 0}function Ld(e){let t=U(e,wordView.W_NS,"tblBorders");if(!t)return;let n={};for(let r of ["top","right","bottom","left","insideH","insideV"]){let o=Wd(U(t,wordView.W_NS,r));o&&(n[r]=o);}return Object.keys(n).length>0?n:void 0}function Gh(e){let t=U(e,wordView.W_NS,"tcBorders");if(!t)return;let n={};for(let r of ["top","right","bottom","left"]){let o=Wd(U(t,wordView.W_NS,r));o&&(n[r]=o);}return Object.keys(n).length>0?n:void 0}function Fo(e,t){var i,s,a;if(!e)return;let n=(i=Aa(e.getAttributeNS(wordView.W_NS,"fill")))!=null?i:_d(t,e.getAttributeNS(wordView.W_NS,"themeFill")),r=(s=e.getAttributeNS(wordView.W_NS,"color"))!=null?s:void 0,o=(a=e.getAttributeNS(wordView.W_NS,"val"))!=null?a:void 0;return v(v(v({},n?{fill:qd(n,e.getAttributeNS(wordView.W_NS,"themeFillTint"),e.getAttributeNS(wordView.W_NS,"themeFillShade"))}:{}),r?{color:r}:{}),o?{val:o}:{})}function jh(e){let t=e==null?void 0:e.getAttributeNS(wordView.W_NS,"val");return t==="top"||t==="center"||t==="bottom"||t==="both"?t:void 0}function Wd(e){var o,i;if(!e)return;let t=(o=e.getAttributeNS(wordView.W_NS,"val"))!=null?o:void 0,n=(i=e.getAttributeNS(wordView.W_NS,"color"))!=null?i:void 0,r=Me(e,"sz");return v(v(v({},t?{val:t}:{}),n?{color:n}:{}),r!==void 0?{size:r}:{})}function Uh(e,t,n,r){return r.length===0?[]:r.split(`
2
- `).map((o,i)=>({type:"paragraph",paraId:`${e}:r${t}:c${n}:p${i}`,story:"body",text:o,flags:{hasComments:false,hasRevisions:false,hasBookmarks:false,hasMath:false},segments:o.length>0?[{kind:"text",from:0,to:o.length,text:o}]:[],spans:[]}))}function Kh(e){var r,o;let t=Bd(e),n=new Map;for(let i=0;i<t.length;i++){let s=(r=t[i])!=null?r:[];for(let a=0;a<s.length;a++){let l=s[a];if(!l||l.cell.vMerge!=="restart")continue;let c=1;for(let u=i+1;u<t.length&&((o=t[u])==null?void 0:o.find(p=>p.startColumn===l.startColumn&&p.cell.vMerge==="continue"));u++)c+=1;c>1&&n.set(`${i}:${a}`,c);}}return n}function Bd(e){return e.map(t=>{let n=0;return t.map(r=>{let o=n,i=Math.max(1,r.gridSpan);return n+=i,{startColumn:o,endColumn:n-1,columnSpan:i,cell:r}})})}function _h(e,t,n,r,o){var b;let i=e.conditions;if(!i)return;let s=Bd(r),a=(b=s[t])==null?void 0:b[n];if(!a)return;let l=r.length,c=Math.max(0,...s.flatMap(g=>g.map(h=>h.endColumn))),u=qh(o),f=u.rowBandSize,p=u.columnBandSize,w;return !u.noHorizontalBand&&Math.floor(t/f)%2===0?w=xt(w,i.band1Horz):u.noHorizontalBand||(w=xt(w,i.band2Horz)),!u.noVerticalBand&&Math.floor(a.startColumn/p)%2===0?w=xt(w,i.band1Vert):u.noVerticalBand||(w=xt(w,i.band2Vert)),u.firstRow&&t===0&&(w=xt(w,i.firstRow)),u.lastRow&&t===l-1&&(w=xt(w,i.lastRow)),u.firstColumn&&a.startColumn===0&&(w=xt(w,i.firstCol)),u.lastColumn&&a.endColumn===c&&(w=xt(w,i.lastCol)),u.firstRow&&u.firstColumn&&t===0&&a.startColumn===0&&(w=xt(w,i.nwCell)),u.firstRow&&u.lastColumn&&t===0&&a.endColumn===c&&(w=xt(w,i.neCell)),u.lastRow&&u.firstColumn&&t===l-1&&a.startColumn===0&&(w=xt(w,i.swCell)),u.lastRow&&u.lastColumn&&t===l-1&&a.endColumn===c&&(w=xt(w,i.seCell)),w}function qh(e){var t,n;return $(v(v({},yh),e!=null?e:{}),{rowBandSize:(t=e==null?void 0:e.rowBandSize)!=null?t:1,columnBandSize:(n=e==null?void 0:e.columnBandSize)!=null?n:1})}function Xh(e,t,n,r=false){var we,he,xe,Ve;let o=[],i=[],s=new Map,a=new Set,l=new Set,c=0,u=null,f="",p=z=>Jd(z,r),w=z=>{let Z=f.length;return f+=z,{from:Z,to:f.length}},b=e.childNodes;for(let z=0;z<b.length;z++){let Z=b[z];if(!Z||Z.nodeType!==1)continue;let H=Z;if(H.namespaceURI!==wordView.W_NS){g("unknown",H);continue}if(H.localName==="pPr")continue;if(H.localName==="hyperlink"){h(H);continue}let Y=xd(H,"commentRangeStart");if(Y!==null){s.set(Y,f.length);continue}let X=xd(H,"commentRangeEnd");if(X!==null){let Ae=s.get(X);if(Ae!==void 0){let Fe=Ig(n.indices,X,t,Ae,f.length,f);Fe&&i.push(Fe),s.delete(X);}continue}if(H.localName==="ins"||H.localName==="del"){let Ae=H.localName==="ins"?"insert":"delete",Fe=La(H,Ae==="delete"?"delText":"t"),{from:Ge,to:Qe}=w(Fe),wt=(we=H.getAttributeNS(wordView.W_NS,"id"))!=null?we:"",an=ht(H,wordView.W_NS,"r")[0],dt=an?Yt(an,n.theme):void 0,Ct=$(v({kind:"revision",from:Ge,to:Qe,text:Fe},dt?{format:dt}:{}),{revisionId:wt,revisionKind:Ae,author:(he=H.getAttributeNS(wordView.W_NS,"author"))!=null?he:"",date:(xe=H.getAttributeNS(wordView.W_NS,"date"))!=null?xe:""});o.push(Ct),wt.length>0&&i.push({kind:"revision",id:`revision:${wt}`,revisionId:wt,revisionKind:Ae,paraId:t,from:Ge,to:Qe,text:Fe,author:Ct.author,date:Ct.date});continue}if(H.localName==="r"&&Tg(H)){y(H);continue}if(u&&H.localName==="r"){C(H);continue}if(H.localName==="fldSimple"&&k(H)||H.localName==="r"&&Fg(H))continue;if(H.localName==="r"&&Rg(H)){V(H);continue}let ye=H.localName==="r"?Ag(H):[];if(ye.length>0){for(let Ae of ye)ee(Ae);continue}if(Mg(H)){ee(H);continue}let ke=p(H);if(ke.length>0){let{from:Ae,to:Fe}=w(ke),Ge={kind:"text",from:Ae,to:Fe,text:ke};if(H.localName==="r"){let Qe=Yt(H,n.theme);Qe&&(Ge.format=Qe);}o.push(Ge);}}D(),pe(e);for(let z of (Ve=n.drawingsByAnchorParaId.get(t))!=null?Ve:[])a.has(z.drawingId)||re(z);return {text:f,segments:o,spans:i.sort((z,Z)=>z.from-Z.from||z.to-Z.to||z.id.localeCompare(Z.id))};function g(z,Z){let{from:H,to:Y}=w("\uFFFC");o.push({kind:"placeholder",from:H,to:Y,placeholderKind:z,sourceTag:Z.localName});}function h(z){let Z=n.hyperlinkByElement.get(z);for(let H=0;H<z.childNodes.length;H+=1){let Y=z.childNodes[H];if(!Y||Y.nodeType!==1)continue;let X=Y;if(X.namespaceURI!==wordView.W_NS||X.localName!=="r")continue;let ye=p(X);if(ye.length===0)continue;let{from:ke,to:Ae}=w(ye),Fe={kind:"text",from:ke,to:Ae,text:ye},Ge=Yt(X,n.theme);Ge&&(Fe.format=Ge),Z&&(Fe.hyperlink=v({},Z)),o.push(Fe);}}function y(z){var H;let Z=Yt(z,n.theme);for(let Y=0;Y<z.childNodes.length;Y++){let X=z.childNodes[Y];if(!X||X.nodeType!==1)continue;let ye=X;if(ye.namespaceURI!==wordView.W_NS)continue;if(ye.localName==="fldChar"){let Qe=ye.getAttributeNS(wordView.W_NS,"fldCharType");Qe==="begin"?(D(),u={instruction:"",cachedText:"",inResult:false,format:Z}):Qe==="separate"&&u?u.inResult=true:Qe==="end"&&u&&(N(u),u=null);continue}if(u&&ye.localName==="instrText"){u.instruction+=(H=ye.textContent)!=null?H:"";continue}let ke=Pg(ye);if(ke.length===0)continue;if(u){u.inResult&&(u.cachedText+=ke);continue}let{from:Ae,to:Fe}=w(ke),Ge={kind:"text",from:Ae,to:Fe,text:ke};Z&&(Ge.format=Z),o.push(Ge);}}function k(z){var X;let Z=(X=z.getAttributeNS(wordView.W_NS,"instr"))!=null?X:"",H=yd(Z);if(!H)return false;let Y=p(z);return L(H,Z,Y,Yt(z,n.theme)),true}function C(z){let Z=p(z);Z.length>0&&(u!=null&&u.inResult)&&(u.cachedText+=Z);}function N(z){let Z=yd(z.instruction);if(Z){L(Z,z.instruction,z.cachedText,z.format);return}W(z);}function L(z,Z,H,Y){let{from:X,to:ye}=w("\uFFFC"),ke={kind:"field",from:X,to:ye,fieldKind:z,instruction:Z,cachedText:H};Y&&(ke.format=Y),o.push(ke);}function D(){u&&(W(u),u=null);}function W(z){if(z.cachedText.length===0)return;let{from:Z,to:H}=w(z.cachedText),Y={kind:"text",from:Z,to:H,text:z.cachedText};z.format&&(Y.format=z.format),o.push(Y);}function V(z){let Z=Yt(z,n.theme);for(let H=0;H<z.childNodes.length;H++){let Y=z.childNodes[H];if(!Y||Y.nodeType!==1)continue;let X=Y;if(X.namespaceURI!==wordView.W_NS)continue;if(X.localName==="br"&&X.getAttributeNS(wordView.W_NS,"type")==="page"){g("pageBreak",X);continue}let ye=p(X);if(ye.length===0)continue;let{from:ke,to:Ae}=w(ye),Fe={kind:"text",from:ke,to:Ae,text:ye};Z&&(Fe.format=Z),o.push(Fe);}}function ee(z){if(z.namespaceURI===wordView.W_NS&&z.localName==="pict"){let Ae=Lg(z,t,c);if(!Ae||l.has(z))return;l.add(z),c+=1;let{from:Fe,to:Ge}=w("\uFFFC");o.push($(v({},Ae),{from:Fe,to:Ge}));return}let Z=n.drawingIdByElement.get(z),H=Z?n.imagesByDrawingId.get(Z):void 0,Y=Z?n.drawingInfoById.get(Z):void 0;if(Z&&Y&&Y.kind!=="picture"){a.add(Z),re(Y);return}if(!Z||!H){g("drawing",z);return}let{from:X,to:ye}=w("\uFFFC");a.add(Z);let ke={kind:"image",from:X,to:ye,drawingId:Z,src:H.src,contentType:H.contentType};H.width!==void 0&&(ke.width=H.width),H.height!==void 0&&(ke.height=H.height),H.anchoringMode!==void 0&&(ke.anchoringMode=H.anchoringMode),H.wrap!==void 0&&(ke.wrap=H.wrap),H.position!==void 0&&(ke.position=H.position),o.push(ke);}function pe(z){for(let Z of ["drawing","pict"]){let H=z.getElementsByTagNameNS(wordView.W_NS,Z);for(let Y=0;Y<H.length;Y++){let X=H[Y];if(!X)continue;if(Z==="pict"){if(l.has(X))continue;ee(X);continue}let ye=n.drawingIdByElement.get(X);!ye||a.has(ye)||ee(X);}}}function re(z){var Ae;if(z.kind==="picture"||(a.add(z.drawingId),Yh(z,n)))return;let Z=z.kind==="textBox"&&(Ae=z.innerText)!=null?Ae:"",{from:H,to:Y}=w(Z.length>0?Z:"\uFFFC"),X={kind:"drawing",from:H,to:Y,drawingId:z.drawingId,drawingKind:z.kind};Z.length>0&&(X.text=Z);let ye=Fd(z.extentEMU);ye.width!==void 0&&(X.width=ye.width),ye.height!==void 0&&(X.height=ye.height),z.anchoringMode!==void 0&&(X.anchoringMode=z.anchoringMode),z.wrap!==void 0&&(X.wrap=z.wrap),z.position!==void 0&&(X.position=z.position),z.hasBorder!==void 0&&(X.hasBorder=z.hasBorder),z.hasFill!==void 0&&(X.hasFill=z.hasFill),z.isLineOrConnector!==void 0&&(X.isLineOrConnector=z.isLineOrConnector),z.innerTextAlign!==void 0&&(X.innerTextAlign=z.innerTextAlign);let ke=Jh(z,n);ke.length>0&&(X.paragraphs=ke),o.push(X);}}var gd=127e3;function Yh(e,t){var s,a,l,c;if(e.kind!=="textBox"||e.anchoringMode!=="anchor"||e.extentEMU.cx<=0||e.extentEMU.cy<=0||e.extentEMU.cx>gd||e.extentEMU.cy>gd)return false;let n=(a=(s=e.position)==null?void 0:s.horizontal)==null?void 0:a.posOffset,r=(c=(l=e.position)==null?void 0:l.vertical)==null?void 0:c.posOffset;if(!(n!==void 0&&n<0||r!==void 0&&r<0))return false;let o=t.indices.drawingIdx.get(e.drawingId);if(!o)return false;let i=o.getElementsByTagNameNS(wordView.W_NS,"txbxContent")[0];return i?Zh(i):false}function Zh(e){var o,i;let t=[],n=0,r=e.getElementsByTagName("*");for(let s=0;s<r.length;s+=1){let a=r[s];if(!(!a||a.namespaceURI!==wordView.W_NS)){if(a.localName==="fldChar"){let l=a.getAttributeNS(wordView.W_NS,"fldCharType");if(l==="begin")t.push({instruction:""});else if(l==="end"){let c=t.pop();if(!c||!/^SET\b/i.test(c.instruction.trim()))return false;n+=1;}continue}if(a.localName==="instrText"){let l=t[t.length-1];if(!l)return false;l.instruction+=(o=a.textContent)!=null?o:"";continue}if(a.localName==="t"&&((i=a.textContent)!=null?i:"").trim().length>0&&t.length===0)return false}}return t.length===0&&n>0}function Jh(e,t){if(e.kind!=="textBox"||!e.innerParagraphIds||e.innerParagraphIds.length===0)return [];let n=new Set;return e.innerParagraphIds.flatMap(r=>{let o=t.indices.paraIdx.get(r);return o?[Bo("body",o,t,n,r)]:[]})}function Qh(e,t,n,r){let o=wordView.getImageBytesSync(e,t,n);if(!o)return null;let i={src:`data:${o.contentType};base64,${tg(o.bytes)}`,contentType:o.contentType};r&&(i.anchoringMode=r.anchoringMode,r.wrap!==void 0&&(i.wrap=r.wrap),r.position!==void 0&&(i.position=r.position));let s=eg(o);return s.width!==void 0&&(i.width=s.width),s.height!==void 0&&(i.height=s.height),i}function eg(e){return Fd(e.extentEMU)}function Fd(e){let{cx:t,cy:n}=e;return {width:t>0?Math.round(t/914400*96):void 0,height:n>0?Math.round(n/914400*96):void 0}}function tg(e){let t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n="",r=0;for(;r+2<e.length;r+=3){let o=e[r]<<16|e[r+1]<<8|e[r+2];n+=Nn(t,o>>18&63),n+=Nn(t,o>>12&63),n+=Nn(t,o>>6&63),n+=Nn(t,o&63);}if(r<e.length){let o=e[r],i=r+1<e.length?e[r+1]:0,s=o<<16|i<<8;n+=Nn(t,s>>18&63),n+=Nn(t,s>>12&63),n+=r+1<e.length?Nn(t,s>>6&63):"=",n+="=";}return n}function Nn(e,t){return e.charAt(t)}function ng(e,t){let n={},r=Ma(e);if(!r)return n;let o=r.getElementsByTagNameNS(wordView.W_NS,"docDefaults")[0];if(!o)return n;let i=Lo(o,wordView.W_NS,["rPrDefault","rPr"]),s=i?Vd(i,t):void 0;s&&(n.run=s);let a=Lo(o,wordView.W_NS,["pPrDefault","pPr"]);if(a){let l=yr(a,t);l&&(n.paragraph=l);}return n}function Ma(e){for(let t of e.parts.values())if(t.contentType==="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"&&t.xmlDom)return t.xmlDom;return null}function rg(e){var s,a,l,c,u,f,p;let t=ig(e);if(!t)return {nums:new Map};let n=new Map,r=t.getElementsByTagNameNS(wordView.W_NS,"abstractNum");for(let w=0;w<r.length;w++){let b=r[w];if(!b)continue;let g=b.getAttributeNS(wordView.W_NS,"abstractNumId");if(!g)continue;let h=new Map;for(let y of ht(b,wordView.W_NS,"lvl")){let k=(s=Me(y,"ilvl"))!=null?s:0,C=(l=(a=U(y,wordView.W_NS,"numFmt"))==null?void 0:a.getAttributeNS(wordView.W_NS,"val"))!=null?l:void 0,N=(u=(c=U(y,wordView.W_NS,"lvlText"))==null?void 0:c.getAttributeNS(wordView.W_NS,"val"))!=null?u:void 0,L=U(y,wordView.W_NS,"start"),D=L&&(f=Me(L,"val"))!=null?f:1,W=yr(U(y,wordView.W_NS,"pPr"));h.set(k,v(v(v({ilvl:k,start:D},C?{numFmt:C}:{}),N?{lvlText:N}:{}),W?{paragraphFormat:W}:{}));}n.set(g,h);}let o=new Map,i=t.getElementsByTagNameNS(wordView.W_NS,"num");for(let w=0;w<i.length;w++){let b=i[w];if(!b)continue;let g=b.getAttributeNS(wordView.W_NS,"numId"),h=(p=U(b,wordView.W_NS,"abstractNumId"))==null?void 0:p.getAttributeNS(wordView.W_NS,"val");if(!g||!h)continue;let y=n.get(h);y&&o.set(g,y);}return {nums:o}}function og(e,t){var o,i;if(!e.numbering)return;let n=(o=t.numbering.nums.get(e.numbering.numId))==null?void 0:o.get(e.numbering.ilvl),r=n==null?void 0:n.paragraphFormat;if(r){if(r.indent!==void 0){let s=(i=e.indent)!=null?i:{};e.indent=v({},s),r.indent.left!==void 0&&(s.left===void 0||s.left===0)&&(e.indent.left=r.indent.left),r.indent.right!==void 0&&s.right===void 0&&(e.indent.right=r.indent.right),r.indent.firstLine!==void 0&&s.firstLine===void 0&&(e.indent.firstLine=r.indent.firstLine);}e.spacing===void 0&&r.spacing!==void 0&&(e.spacing=v({},r.spacing)),e.alignment===void 0&&r.alignment!==void 0&&(e.alignment=r.alignment);}}function ig(e){for(let t of e.parts.values())if(t.contentType==="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml"&&t.xmlDom)return t.xmlDom;return null}function ag(e,t){var l,c,u,f,p;let n=(l=t.numbering.nums.get(e.numId))==null?void 0:l.get(e.ilvl),r=(c=e.numFmt)!=null?c:n==null?void 0:n.numFmt,o=(u=e.lvlText)!=null?u:n==null?void 0:n.lvlText,i=v(v(v(v({},e),r?{numFmt:r}:{}),o?{lvlText:o}:{}),(n==null?void 0:n.start)!==void 0?{start:n.start}:{}),s=`${i.numId}:${i.ilvl}`;if(r==="bullet")return i.label=sg(o),i;let a=((p=t.numberingCounters.get(s))!=null?p:((f=n==null?void 0:n.start)!=null?f:1)-1)+1;return t.numberingCounters.set(s,a),i.label=lg(a,r,o),i}function sg(e){let t=e==null?void 0:e.replace(/%\d+/g,"").trim();return t&&t.length>0?t:"\u2022"}function lg(e,t,n){let r=t==="lowerLetter"?bd(e,false):t==="upperLetter"?bd(e,true):String(e);return n?n.replace(/%\d+/g,r):`${r}.`}function bd(e,t){let n=Math.max(1,e),r="";for(;n>0;)n-=1,r=String.fromCharCode((t?65:97)+n%26)+r,n=Math.floor(n/26);return r}function dg(e,t,n){var i,s;let r=new Map;for(let a of e.parts.values()){if(a.contentType!=="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"||!a.xmlDom)continue;let l=a.xmlDom.getElementsByTagNameNS(wordView.W_NS,"style");for(let c=0;c<l.length;c++){let u=l[c];if(!u)continue;let f=u.getAttributeNS(wordView.W_NS,"styleId");if(!f||((i=u.getAttributeNS(wordView.W_NS,"type"))!=null?i:"paragraph")!=="paragraph")continue;let w={},b=(s=U(u,wordView.W_NS,"basedOn"))==null?void 0:s.getAttributeNS(wordView.W_NS,"val");b&&(w.basedOn=b);let g=gg(u,n);g&&(w.format=g),r.set(f,w);}}let o=new Map;for(let a of r.keys()){let l=Od(a,r,new Set);l&&o.set(a,l);}for(let a of t.stylesIdx.values()){if(a.outlineLevel===void 0)continue;let l=o.get(a.styleId);o.set(a.styleId,Bt(l,{outlineLevel:a.outlineLevel}));}return o}function cg(e){var r;let t=Ma(e);if(!t)return;let n=t.getElementsByTagNameNS(wordView.W_NS,"style");for(let o=0;o<n.length;o++){let i=n[o];if(!i||((r=i.getAttributeNS(wordView.W_NS,"type"))!=null?r:"paragraph")!=="paragraph"||i.getAttributeNS(wordView.W_NS,"default")!=="1")continue;let a=i.getAttributeNS(wordView.W_NS,"styleId");if(a)return a}}function ug(e,t){var s,a;let n=new Map,r=Ma(e);if(!r)return new Map;let o=r.getElementsByTagNameNS(wordView.W_NS,"style");for(let l=0;l<o.length;l++){let c=o[l];if(!c)continue;let u=c.getAttributeNS(wordView.W_NS,"styleId");if(!u||((s=c.getAttributeNS(wordView.W_NS,"type"))!=null?s:"paragraph")!=="table")continue;let p={},w=(a=U(c,wordView.W_NS,"basedOn"))==null?void 0:a.getAttributeNS(wordView.W_NS,"val");w&&(p.basedOn=w);let b=pg(c,t);b&&(p.format=b),n.set(u,p);}let i=new Map;for(let l of n.keys()){let c=Dd(l,n,new Set);c&&i.set(l,c);}return i}function Dd(e,t,n){if(n.has(e))return;n.add(e);let r=t.get(e);if(!r)return;let o=r.basedOn?Dd(r.basedOn,t,n):void 0;return Ia(o,r.format)}function pg(e,t){let n=Ia(Hd(U(e,wordView.W_NS,"tblPr"),U(e,wordView.W_NS,"tcPr"),t),fg(e,t)),r=mg(e,t);return r?Ia(n,{conditions:r}):n}function fg(e,t){for(let n of ht(e,wordView.W_NS,"tblStylePr"))if(n.getAttributeNS(wordView.W_NS,"type")==="wholeTable")return Hd(U(n,wordView.W_NS,"tblPr"),U(n,wordView.W_NS,"tcPr"),t)}function mg(e,t){let n={};for(let r of ht(e,wordView.W_NS,"tblStylePr")){let o=r.getAttributeNS(wordView.W_NS,"type");if(o!=="firstRow"&&o!=="lastRow"&&o!=="firstCol"&&o!=="lastCol"&&o!=="band1Horz"&&o!=="band2Horz"&&o!=="band1Vert"&&o!=="band2Vert"&&o!=="nwCell"&&o!=="neCell"&&o!=="swCell"&&o!=="seCell")continue;let i=hg(r,t);i&&(n[o]=i);}return Object.keys(n).length>0?n:void 0}function hg(e,t){let n={},r=Ra(U(e,wordView.W_NS,"tcPr"),t);r&&(n.cell=r);let o=Bt(yr(U(e,wordView.W_NS,"pPr"),t),$d(U(e,wordView.W_NS,"rPr"),t));return o&&(n.paragraphFormat=o),Object.keys(n).length>0?n:void 0}function Hd(e,t,n){let r={};if(e){let o=Ld(e);o&&(r.borders=o);let i=Pa(U(e,wordView.W_NS,"tblCellMar"));i&&(r.cellMargin=i);let s=Rd(e);s&&(r.tableLook=s);}if(t){let o=Ra(t,n);o&&(r.cell=o);}return Object.keys(r).length>0?r:void 0}function Ra(e,t){if(!e)return;let n={},r=Pa(U(e,wordView.W_NS,"tcMar"));r&&(n.margin=r);let o=Gh(e);o&&(n.borders=o);let i=Fo(U(e,wordView.W_NS,"shd"),t);i&&(n.shading=i);let s=jh(U(e,wordView.W_NS,"vAlign"));s&&(n.verticalAlignment=s);let a=it(U(e,wordView.W_NS,"noWrap"));return (a!==void 0?a:U(e,wordView.W_NS,"noWrap")!==null)&&(n.noWrap=true),Object.keys(n).length>0?n:void 0}function Ia(e,t){var r,o,i,s,a,l,c,u,f,p,w,b,g,h,y,k,C,N,L,D;if(!e&&!t)return;let n=v(v({},e!=null?e:{}),t!=null?t:{});if((e!=null&&e.borders||t!=null&&t.borders)&&(n.borders=v(v({},(r=e==null?void 0:e.borders)!=null?r:{}),(o=t==null?void 0:t.borders)!=null?o:{})),(e!=null&&e.cellMargin||t!=null&&t.cellMargin)&&(n.cellMargin=v(v({},(i=e==null?void 0:e.cellMargin)!=null?i:{}),(s=t==null?void 0:t.cellMargin)!=null?s:{})),(e!=null&&e.tableLook||t!=null&&t.tableLook)&&(n.tableLook=Ad(e==null?void 0:e.tableLook,t==null?void 0:t.tableLook)),(e!=null&&e.cell||t!=null&&t.cell)&&(n.cell=v(v({},(a=e==null?void 0:e.cell)!=null?a:{}),(l=t==null?void 0:t.cell)!=null?l:{}),((c=e==null?void 0:e.cell)!=null&&c.margin||(u=t==null?void 0:t.cell)!=null&&u.margin)&&(n.cell.margin=v(v({},(p=(f=e==null?void 0:e.cell)==null?void 0:f.margin)!=null?p:{}),(b=(w=t==null?void 0:t.cell)==null?void 0:w.margin)!=null?b:{})),((g=e==null?void 0:e.cell)!=null&&g.borders||(h=t==null?void 0:t.cell)!=null&&h.borders)&&(n.cell.borders=v(v({},(k=(y=e==null?void 0:e.cell)==null?void 0:y.borders)!=null?k:{}),(N=(C=t==null?void 0:t.cell)==null?void 0:C.borders)!=null?N:{}))),(e!=null&&e.paragraphFormat||t!=null&&t.paragraphFormat)&&(n.paragraphFormat=Bt(e==null?void 0:e.paragraphFormat,t==null?void 0:t.paragraphFormat)),e!=null&&e.conditions||t!=null&&t.conditions){n.conditions=v({},(L=e==null?void 0:e.conditions)!=null?L:{});for(let[W,V]of Object.entries((D=t==null?void 0:t.conditions)!=null?D:{}))n.conditions[W]=xt(n.conditions[W],V);}return n}function xt(e,t){var r,o,i,s,a,l,c,u,f,p,w,b,g,h;if(!e&&!t)return;let n=v(v({},e!=null?e:{}),t!=null?t:{});return (e!=null&&e.cell||t!=null&&t.cell)&&(n.cell=v(v({},(r=e==null?void 0:e.cell)!=null?r:{}),(o=t==null?void 0:t.cell)!=null?o:{}),((i=e==null?void 0:e.cell)!=null&&i.margin||(s=t==null?void 0:t.cell)!=null&&s.margin)&&(n.cell.margin=v(v({},(l=(a=e==null?void 0:e.cell)==null?void 0:a.margin)!=null?l:{}),(u=(c=t==null?void 0:t.cell)==null?void 0:c.margin)!=null?u:{})),((f=e==null?void 0:e.cell)!=null&&f.borders||(p=t==null?void 0:t.cell)!=null&&p.borders)&&(n.cell.borders=v(v({},(b=(w=e==null?void 0:e.cell)==null?void 0:w.borders)!=null?b:{}),(h=(g=t==null?void 0:t.cell)==null?void 0:g.borders)!=null?h:{}))),(e!=null&&e.paragraphFormat||t!=null&&t.paragraphFormat)&&(n.paragraphFormat=Bt(e==null?void 0:e.paragraphFormat,t==null?void 0:t.paragraphFormat)),n}function Od(e,t,n){if(n.has(e))return;n.add(e);let r=t.get(e);if(!r)return;let o=r.basedOn?Od(r.basedOn,t,n):void 0;return Bt(o,r.format)}function gg(e,t){let n=yr(U(e,wordView.W_NS,"pPr"),t),r=$d(U(e,wordView.W_NS,"rPr"),t);return Bt(n,r)}function yr(e,t){var o,i;let n={},r=false;if(e){let s=U(e,wordView.W_NS,"jc"),a=s==null?void 0:s.getAttributeNS(wordView.W_NS,"val");(a==="left"||a==="center"||a==="right"||a==="both"||a==="distribute")&&(n.alignment=a,r=true);let l=U(e,wordView.W_NS,"ind");if(l){let N=Me(l,"left"),L=Me(l,"right"),D=Me(l,"firstLine"),W=Me(l,"hanging"),V=D!==void 0?D:W!==void 0?-W:void 0;(N!==void 0||L!==void 0||V!==void 0)&&(n.indent={},N!==void 0&&(n.indent.left=N),L!==void 0&&(n.indent.right=L),V!==void 0&&(n.indent.firstLine=V),r=true);}let c=U(e,wordView.W_NS,"spacing");if(c){let N=Me(c,"before"),L=Me(c,"after"),D=Me(c,"line"),W=c.getAttributeNS(wordView.W_NS,"lineRule"),V=W==="auto"||W==="exact"||W==="atLeast"?W:void 0;(N!==void 0||L!==void 0||D!==void 0||V!==void 0)&&(n.spacing={},N!==void 0&&(n.spacing.before=N),L!==void 0&&(n.spacing.after=L),D!==void 0&&(n.spacing.line=D),V!==void 0&&(n.spacing.lineRule=V),r=true);}let u=bg(U(e,wordView.W_NS,"tabs"));u!==void 0&&(n.tabStops=u,r=true);let f=U(e,wordView.W_NS,"outlineLvl"),p=f?Me(f,"val"):void 0;p!==void 0&&p>=0&&p<=9&&(n.outlineLevel=p,r=true);let w=U(e,wordView.W_NS,"numPr");if(w){let N=(o=U(w,wordView.W_NS,"numId"))==null?void 0:o.getAttributeNS(wordView.W_NS,"val");N&&N!=="0"&&(n.hasNumbering=true,n.numbering={numId:N,ilvl:U(w,wordView.W_NS,"ilvl")&&(i=Me(U(w,wordView.W_NS,"ilvl"),"val"))!=null?i:0},r=true);}zd(U(e,wordView.W_NS,"rPr"),n,t,false)&&(r=true),wg(e,n)&&(r=true);let b=Fo(U(e,wordView.W_NS,"shd"),t);b&&(n.shading=b,r=true);let g=it(U(e,wordView.W_NS,"keepNext"));g!==void 0&&(n.keepNext=g,r=true);let h=it(U(e,wordView.W_NS,"keepLines"));h!==void 0&&(n.keepLines=h,r=true);let y=it(U(e,wordView.W_NS,"widowControl"));y!==void 0&&(n.widowControl=y,r=true);let k=it(U(e,wordView.W_NS,"snapToGrid"));k!==void 0&&(n.snapToGrid=k,r=true);let C=it(U(e,wordView.W_NS,"pageBreakBefore"));C!==void 0&&(n.pageBreakBefore=C,r=true),U(e,wordView.W_NS,"sectPr")&&(n.hasSectionBreak=true,r=true);}return r?n:void 0}function bg(e){if(!e)return;let t=[];for(let n of ht(e,wordView.W_NS,"tab")){let r=n.getAttributeNS(wordView.W_NS,"val"),o=r==="left"||r==="center"||r==="right"||r==="decimal"||r==="bar"?r:void 0,i=Me(n,"pos");if(!o||i===void 0)continue;let s=n.getAttributeNS(wordView.W_NS,"leader"),a=s==="none"||s==="dot"||s==="hyphen"||s==="underscore"||s==="heavy"||s==="middleDot"?s:void 0;t.push(v({alignment:o,position:i},a?{leader:a}:{}));}return t.length>0?t:void 0}function $d(e,t){let n={};return zd(e,n,t)?n:void 0}function zd(e,t,n,r=true){if(!e)return false;let o=false,i=Ud(e,n);i&&(t.fontFamily=i,o=true);let s=U(e,wordView.W_NS,"sz"),a=s?Me(s,"val"):void 0;a!==void 0&&(t.fontSize=a/2,o=true);let l=it(U(e,wordView.W_NS,"b"));if(l!==void 0&&(t.bold=l,o=true),r){let p=Kd(U(e,wordView.W_NS,"color"),n);p&&(t.color=p,o=true);}let c=jd(e);c!==void 0&&(t.characterSpacing=c,o=true);let u=Gd(U(e,wordView.W_NS,"highlight"));u&&(t.highlight=u,o=true);let f=Fo(U(e,wordView.W_NS,"shd"),n);return f&&(t.shading=f,o=true),o}function wg(e,t){let n=U(e,wordView.W_NS,"pBdr");if(!n)return false;let r={};for(let o of ["top","right","bottom","left","between","bar"]){let i=xg(U(n,wordView.W_NS,o));i&&(r[o]=i);}return Object.keys(r).length===0?false:(t.borders=r,r.bottom&&(t.borderBottom=r.bottom),true)}function Bt(e,t){var r,o,i,s,a,l;if(!e&&!t)return;let n=v(v({},e!=null?e:{}),t!=null?t:{});return (e!=null&&e.indent||t!=null&&t.indent)&&(n.indent=v(v({},(r=e==null?void 0:e.indent)!=null?r:{}),(o=t==null?void 0:t.indent)!=null?o:{})),(e!=null&&e.spacing||t!=null&&t.spacing)&&(n.spacing=v(v({},(i=e==null?void 0:e.spacing)!=null?i:{}),(s=t==null?void 0:t.spacing)!=null?s:{})),(e&&"borders"in e&&e.borders||t&&"borders"in t&&t.borders)&&(n.borders=v(v({},(a=e==null?void 0:e.borders)!=null?a:{}),(l=t==null?void 0:t.borders)!=null?l:{}),n.borders.bottom&&(n.borderBottom=n.borders.bottom)),t&&"tabStops"in t&&t.tabStops!==void 0?n.tabStops=t.tabStops.map(c=>v({},c)):e&&"tabStops"in e&&e.tabStops!==void 0&&(n.tabStops=e.tabStops.map(c=>v({},c))),n}function Me(e,t){let n=e.getAttributeNS(wordView.W_NS,t);if(n===null)return;let r=Number(n);return Number.isFinite(r)?r:void 0}function xg(e){var s;if(!e)return;let t=(s=e.getAttributeNS(wordView.W_NS,"val"))!=null?s:void 0;if(t==="none"||t==="nil")return;let n={val:t},r=e.getAttributeNS(wordView.W_NS,"color"),o=Me(e,"sz"),i=Me(e,"space");return r&&(n.color=r),o!==void 0&&(n.size=o),i!==void 0&&(n.space=i),n}function Yt(e,t){let n=U(e,wordView.W_NS,"rPr");if(!n)return;let r=Vd(n,t);return r&&Object.keys(r).length>0?r:void 0}function Vd(e,t){let n={},r=Ud(e,t);r&&(n.fontFamily=r);let o=it(U(e,wordView.W_NS,"b"));o!==void 0&&(n.bold=o);let i=it(U(e,wordView.W_NS,"i"));i!==void 0&&(n.italic=i);let s=U(e,wordView.W_NS,"u");if(s){let y=s.getAttributeNS(wordView.W_NS,"val");n.underline=y!=="none"&&y!=="0"&&y!=="false";}let a=it(U(e,wordView.W_NS,"strike"));a!==void 0&&(n.strike=a);let l=it(U(e,wordView.W_NS,"dstrike"));l!==void 0&&(n.doubleStrike=l);let c=it(U(e,wordView.W_NS,"caps"));c!==void 0&&(n.caps=c);let u=it(U(e,wordView.W_NS,"smallCaps"));u!==void 0&&(n.smallCaps=u);let f=U(e,wordView.W_NS,"sz");if(f){let y=f.getAttributeNS(wordView.W_NS,"val"),k=y!==null?Number(y):NaN;Number.isFinite(k)&&(n.fontSize=k/2);}let p=U(e,wordView.W_NS,"color");if(p){let y=Kd(p,t);y&&(n.color=y);}let w=jd(e);w!==void 0&&(n.characterSpacing=w);let b=yg(U(e,wordView.W_NS,"vertAlign"));b&&(n.verticalAlign=b);let g=Gd(U(e,wordView.W_NS,"highlight"));g&&(n.highlight=g);let h=Fo(U(e,wordView.W_NS,"shd"),t);return h&&(n.shading=h),Object.keys(n).length>0?n:void 0}function Gd(e){var n;let t=(n=e==null?void 0:e.getAttributeNS(wordView.W_NS,"val"))!=null?n:void 0;return t&&t!=="none"?t:void 0}function jd(e){let t=U(e,wordView.W_NS,"spacing");return t?Me(t,"val"):void 0}function yg(e){let t=e==null?void 0:e.getAttributeNS(wordView.W_NS,"val");return t==="baseline"||t==="superscript"||t==="subscript"?t:void 0}function Ud(e,t){let n=U(e,wordView.W_NS,"rFonts");if(!n)return;let r=n.getAttributeNS(wordView.W_NS,"eastAsia")||Ao(t,n.getAttributeNS(wordView.W_NS,"eastAsiaTheme")),o=n.getAttributeNS(wordView.W_NS,"ascii")||n.getAttributeNS(wordView.W_NS,"hAnsi")||Ao(t,n.getAttributeNS(wordView.W_NS,"asciiTheme"))||Ao(t,n.getAttributeNS(wordView.W_NS,"hAnsiTheme"));return o&&r&&vg(o)?o===r?o:`${o}, ${r}`:r||o||n.getAttributeNS(wordView.W_NS,"cs")||Ao(t,n.getAttributeNS(wordView.W_NS,"csTheme"))||void 0}function vg(e){let t=e.trim().toLowerCase();return t==="calibri"||t==="aptos"||t==="arial"}function Kd(e,t){if(!e)return;let n=Aa(e.getAttributeNS(wordView.W_NS,"val")),r=n!=null?n:_d(t,e.getAttributeNS(wordView.W_NS,"themeColor"));if(r)return qd(r,e.getAttributeNS(wordView.W_NS,"themeTint"),e.getAttributeNS(wordView.W_NS,"themeShade"))}function _d(e,t){if(!(!e||!t))return e.colors.get(t)}function Ao(e,t){if(!(!e||!t))return e.fonts.get(Sg(t))}function Sg(e){var n;return (n={"+mj-lt":"majorHAnsi","+mn-lt":"minorHAnsi","+mj-ea":"majorEastAsia","+mn-ea":"minorEastAsia","+mj-cs":"majorBidi","+mn-cs":"minorBidi",majorAscii:"majorHAnsi",minorAscii:"minorHAnsi",majorLatin:"majorHAnsi",minorLatin:"minorHAnsi",majorCs:"majorBidi",minorCs:"minorBidi"}[e])!=null?n:e}function Aa(e){if(!(!e||e==="auto")){if(/^[0-9a-f]{6}$/i.test(e))return e.toUpperCase();if(/^[0-9a-f]{8}$/i.test(e))return e.slice(2).toUpperCase()}}function qd(e,t,n){let r=wd(t);if(r!==void 0)return kg(e,r/255);let o=wd(n);return o!==void 0?Eg(e,o/255):e}function wd(e){if(!e||!/^[0-9a-f]{2}$/i.test(e))return;let t=Number.parseInt(e,16);return Number.isFinite(t)?t:void 0}function kg(e,t){return Xd(e,n=>n+(255-n)*t)}function Eg(e,t){return Xd(e,n=>n*t)}function Xd(e,t){return [0,2,4].map(r=>Number.parseInt(e.slice(r,r+2),16)).map(r=>Math.max(0,Math.min(255,Math.round(t(r))))).map(r=>r.toString(16).toUpperCase().padStart(2,"0")).join("")}function it(e){if(!e)return;let t=e.getAttributeNS(wordView.W_NS,"val");return Yd(t)}function Yd(e){return e!=="0"&&e!=="false"&&e!=="off"}function Zd(e){if(e.namespaceURI!==wordView.W_NS||e.localName!=="sdt")return false;let t=U(e,wordView.W_NS,"sdtPr");return t?it(U(t,wordView.W_NS,"showingPlcHdr"))===true:false}function U(e,t,n){for(let r=0;r<e.childNodes.length;r++){let o=e.childNodes[r];if((o==null?void 0:o.nodeType)===1&&o.namespaceURI===t&&o.localName===n)return o}return null}function Cg(e,t,n){for(let r=e.childNodes.length-1;r>=0;r--){let o=e.childNodes[r];if((o==null?void 0:o.nodeType)===1&&o.namespaceURI===t&&o.localName===n)return o}return null}function ht(e,t,n){let r=[];for(let o=0;o<e.childNodes.length;o++){let i=e.childNodes[o];(i==null?void 0:i.nodeType)===1&&i.namespaceURI===t&&i.localName===n&&r.push(i);}return r}function Lo(e,t,n){let r=e;for(let o of n)if(r=r?U(r,t,o):null,!r)return null;return r}function Ig(e,t,n,r,o,i){var l,c;let s=e.commentIdx.get(t);if(!(s!=null&&s.comment))return null;let a=La(s.comment,"t");return {kind:"comment",id:`comment:${t}`,commentId:t,paraId:n,from:r,to:o,text:i.slice(r,o),rangeKind:r===0&&o===i.length?"paragraph":"text",author:(l=s.comment.getAttributeNS(wordView.W_NS,"author"))!=null?l:"",date:(c=s.comment.getAttributeNS(wordView.W_NS,"date"))!=null?c:"",body:a}}function Ng(e,t){var r,o;let n=[];for(let[i,s]of e.commentIdx)t.has(i)||!s.comment||n.push({id:i,author:(r=s.comment.getAttributeNS(wordView.W_NS,"author"))!=null?r:"",date:(o=s.comment.getAttributeNS(wordView.W_NS,"date"))!=null?o:"",text:La(s.comment,"t"),rangeKind:"complex"});return n}function xd(e,t){if(e.namespaceURI!==wordView.W_NS||e.localName!==t)return null;let n=e.getAttributeNS(wordView.W_NS,"id");if(n===null)return null;let r=Number(n);return Number.isFinite(r)?r:null}function Jd(e,t=false){let n="";function r(o){var s;if(o.nodeType!==1)return;let i=o;if(i.namespaceURI===wordView.W_NS&&!(t&&Zd(i))){if(i.localName==="t"){n+=(s=i.textContent)!=null?s:"";return}if(i.localName==="tab"||i.localName==="ptab"){n+=" ";return}if(i.localName==="br"){let a=i.getAttributeNS(wordView.W_NS,"type");(a===null||a===""||a==="textWrapping")&&(n+=`
3
- `);return}if(i.localName!=="delText"&&i.localName!=="commentReference")for(let a=0;a<i.childNodes.length;a++){let l=i.childNodes[a];l&&r(l);}}}return r(e),n}function Tg(e){for(let t=0;t<e.childNodes.length;t++){let n=e.childNodes[t];if(!n||n.nodeType!==1)continue;let r=n;if(r.namespaceURI===wordView.W_NS&&(r.localName==="fldChar"||r.localName==="instrText"))return true}return false}function Pg(e){var t;if(e.localName==="t")return (t=e.textContent)!=null?t:"";if(e.localName==="tab"||e.localName==="ptab")return " ";if(e.localName==="br"){let n=e.getAttributeNS(wordView.W_NS,"type");return n===null||n===""||n==="textWrapping"?`
4
- `:""}return e.localName==="delText"||e.localName==="commentReference"||e.localName==="instrText"?"":Jd(e)}function yd(e){var r;let n=(r=e.replace(/\\\*\s+MERGEFORMAT/gi,"").replace(/\\\*\s+CHARFORMAT/gi,"").trim().toUpperCase().split(/\s+/)[0])!=null?r:"";return n==="PAGE"?"pageNumber":n==="NUMPAGES"?"totalPages":n==="SECTIONPAGES"?"sectionPages":null}function La(e,t){var o,i;let n=e.getElementsByTagNameNS(wordView.W_NS,t),r="";for(let s=0;s<n.length;s++)r+=(i=(o=n[s])==null?void 0:o.textContent)!=null?i:"";return r}function Mg(e){return e.namespaceURI===wordView.W_NS&&(e.localName==="drawing"||e.localName==="pict")}function Rg(e){for(let t=0;t<e.childNodes.length;t++){let n=e.childNodes[t];if(!n||n.nodeType!==1)continue;let r=n;if(r.namespaceURI===wordView.W_NS&&r.localName==="br"&&r.getAttributeNS(wordView.W_NS,"type")==="page")return true}return false}function Ag(e){let t=[];for(let n=0;n<e.childNodes.length;n++){let r=e.childNodes[n];(r==null?void 0:r.nodeType)===1&&r.namespaceURI===wordView.W_NS&&(r.localName==="drawing"||r.localName==="pict")&&t.push(r);}return t}function Lg(e,t,n){var u,f;if(e.namespaceURI!==wordView.W_NS||e.localName!=="pict")return null;let r=e.getElementsByTagNameNS(cd,"line")[0];if(!r)return null;let o=Wg(r.getAttribute("style")),i=r.getElementsByTagNameNS(cd,"stroke")[0],s=Ca(o.get("width")),a=Ca(o.get("height")),l=Bg((u=i==null?void 0:i.getAttribute("color"))!=null?u:r.getAttribute("strokecolor")),c=Ca((f=i==null?void 0:i.getAttribute("weight"))!=null?f:r.getAttribute("strokeweight"));return v(v(v(v({kind:"drawing",drawingId:`${t}:vml-line:${n+1}`,drawingKind:"shape",isLineOrConnector:true,hasBorder:true},s!==void 0?{width:s}:{}),a!==void 0?{height:a}:{}),l?{strokeColor:l}:{}),c!==void 0?{strokeWidth:c}:{})}function Wg(e){var n;let t=new Map;for(let r of (n=e==null?void 0:e.split(";"))!=null?n:[]){let o=r.indexOf(":");if(o<0)continue;let i=r.slice(0,o).trim().toLowerCase(),s=r.slice(o+1).trim();i&&s&&t.set(i,s);}return t}function Ca(e){var o,i;if(!e)return;let t=/^(-?(?:\d+\.?\d*|\.\d+))(pt|px|in|cm|mm)?$/i.exec(e.trim());if(!t)return;let n=Number(t[1]);if(!Number.isFinite(n))return;let r=(i=(o=t[2])==null?void 0:o.toLowerCase())!=null?i:"px";return r==="pt"?n*(96/72):r==="in"?n*96:r==="cm"?n*(96/2.54):r==="mm"?n*(96/25.4):n}function Bg(e){if(!e)return;let t=e.trim();if(/^#[0-9a-f]{6}$/i.test(t))return t.toUpperCase();if(/^[0-9a-f]{6}$/i.test(t))return `#${t.toUpperCase()}`}function Fg(e){for(let t=0;t<e.childNodes.length;t++){let n=e.childNodes[t];if(!n||n.nodeType!==1)continue;let r=n;if(r.namespaceURI!==wordView.W_NS)return false;if(!(r.localName==="rPr"||r.localName==="commentReference"||r.localName==="bookmarkStart"||r.localName==="bookmarkEnd"||r.localName==="commentRangeStart"||r.localName==="commentRangeEnd"))return false}return true}function Dg(e){let t=e.blocks.filter(o=>o.type==="paragraph"),n=tc(e),r=Og(e);return {topLevelBlocks:e.blocks.length,topLevelParagraphs:t.length,tableBlocks:e.tables.length,tableParagraphs:n.length,allParagraphs:r.length,topLevelImages:Wa(t),tableImages:Wa(n),allImages:Wa(r),topLevelDrawings:Ba(t),tableDrawings:Ba(n),allDrawings:Ba(r),pageBreaks:Vg(r)}}function yE(e,t){var i;let n=Dg(e),r=t?Hg(t):[],o=zg(r);return {editor:n,native:{blocks:(i=t==null?void 0:t.blocks.length)!=null?i:0,paragraphs:r.length,images:o,drawings:Qd(r),pageBreaks:ec(r)},missing:{paragraphs:n.allParagraphs-r.length,images:n.allImages-o,drawings:n.allDrawings-Qd(r),pageBreaks:n.pageBreaks-ec(r)}}}function vE(e){return [...vr(e.blocks),...e.headers.flatMap(t=>vr(t.blocks)),...e.footers.flatMap(t=>vr(t.blocks))]}function Hg(e){return vr(e.blocks)}function vr(e){return e.flatMap(t=>t.kind==="paragraph"?[t]:t.rows.flatMap(n=>n.cells.flatMap(r=>r.vMerge==="continue"?[]:vr(r.blocks))))}function Og(e){return [...e.blocks.filter(n=>n.type==="paragraph"),...tc(e)]}function tc(e){return $g(e.tables)}function $g(e){return e.flatMap(t=>t.rows.flatMap(n=>n.cells.flatMap(r=>r.vMerge==="continue"?[]:r.paragraphs)))}function Wa(e){return e.reduce((t,n)=>t+n.segments.filter(r=>r.kind==="image").length,0)}function Ba(e){return e.reduce((t,n)=>t+n.segments.filter(r=>r.kind==="drawing").length,0)}function zg(e){return e.reduce((t,n)=>t+n.content.filter(r=>r.kind==="image").length,0)}function Qd(e){return e.reduce((t,n)=>t+n.content.filter(r=>r.kind==="drawing").length,0)}function Vg(e){return e.reduce((t,n)=>t+n.segments.filter(r=>r.kind==="placeholder"&&r.placeholderKind==="pageBreak").length,0)}function ec(e){return e.reduce((t,n)=>t+n.content.filter(r=>r.kind==="pageBreak").length,0)}function Fa(e){var o,i,s,a,l,c,u,f;let t={};if(!e)return Sr(t);jg(e,t),e.alignment&&(t["text-align"]=Ug(e.alignment)),((o=e.indent)==null?void 0:o.left)!==void 0&&Gg(e)&&(t["margin-left"]=yt(e.indent.left)),((i=e.indent)==null?void 0:i.right)!==void 0&&(t["margin-right"]=yt(e.indent.right)),((s=e.indent)==null?void 0:s.firstLine)!==void 0&&(t["text-indent"]=yt(e.indent.firstLine)),((a=e.spacing)==null?void 0:a.before)!==void 0&&(t["margin-top"]=yt(e.spacing.before)),((l=e.spacing)==null?void 0:l.after)!==void 0&&(t["margin-bottom"]=yt(e.spacing.after));let n=Jg((c=e.spacing)==null?void 0:c.line,(u=e.spacing)==null?void 0:u.lineRule,e.snapToGrid);n&&(t["line-height"]=n),e.fontSize!==void 0&&(t["font-size"]=`${e.fontSize}pt`),e.fontFamily!==void 0&&(t["font-family"]=ic(e.fontFamily)),e.characterSpacing!==void 0&&(t["letter-spacing"]=yt(e.characterSpacing)),e.bold!==void 0&&(t["font-weight"]=e.bold?"700":"400");let r=(f=rc(e.shading))!=null?f:oc(e.highlight);return r&&(t["background-color"]=r),Xg(e,t),Sr(t)}function Gg(e){var t;return !(e.numbering&&((t=e.indent)==null?void 0:t.left)===0&&e.indent.firstLine===void 0)}function jg(e,t){e.outlineLevel!==void 0&&(e.outlineLevel===0?(t["font-size"]="16pt",t["font-weight"]="700",t["line-height"]="1.28"):e.outlineLevel===1?(t["font-size"]="14pt",t["font-weight"]="700",t["line-height"]="1.3"):e.outlineLevel===2&&(t["font-size"]="12pt",t["font-weight"]="700",t["line-height"]="1.35"));}function Oo(e){var o;let t={};if(!e)return Sr(t);e.bold!==void 0&&(t["font-weight"]=e.bold?"700":"400"),e.italic!==void 0&&(t["font-style"]=e.italic?"italic":"normal"),_g(e,t),e.caps&&(t["text-transform"]="uppercase"),e.smallCaps&&(t["font-variant-caps"]="small-caps"),e.fontSize!==void 0&&(t["font-size"]=`${e.fontSize}pt`),e.fontFamily!==void 0&&(t["font-family"]=ic(e.fontFamily)),e.characterSpacing!==void 0&&(t["letter-spacing"]=yt(e.characterSpacing)),e.verticalAlign&&(t["vertical-align"]=qg(e.verticalAlign),e.verticalAlign!=="baseline"&&e.fontSize===void 0&&(t["font-size"]="smaller"));let n=jn(e.color);n&&(t.color=n);let r=(o=oc(e.highlight))!=null?o:rc(e.shading);return r&&(t["background-color"]=r),Sr(t)}function nc(e){var r;let t={};e.width!==void 0&&e.width>0&&(t.width=yt(e.width)),e.margin&&(e.margin.top!==void 0&&(t["padding-top"]=yt(e.margin.top)),e.margin.right!==void 0&&(t["padding-right"]=yt(e.margin.right)),e.margin.bottom!==void 0&&(t["padding-bottom"]=yt(e.margin.bottom)),e.margin.left!==void 0&&(t["padding-left"]=yt(e.margin.left)));let n=jn((r=e.shading)==null?void 0:r.fill);return n&&(t["background-color"]=n),e.verticalAlignment&&(t["vertical-align"]=Kg(e.verticalAlignment)),e.noWrap&&(t["white-space"]="nowrap"),e.borders&&(Ho(t,"top",e.borders.top),Ho(t,"right",e.borders.right),Ho(t,"bottom",e.borders.bottom),Ho(t,"left",e.borders.left)),Sr(t)}function jn(e){return !e||e==="auto"?null:/^[0-9a-f]{6}$/i.test(e)?`#${e}`:null}function rc(e){return !e||e.val==="nil"||e.val==="clear"&&!e.fill?null:jn(e.fill)}function oc(e){var n;return !e||e==="none"?null:(n={black:"#000000",blue:"#0000ff",cyan:"#00ffff",green:"#00ff00",magenta:"#ff00ff",red:"#ff0000",yellow:"#ffff00",white:"#ffffff",darkBlue:"#000080",darkCyan:"#008080",darkGreen:"#008000",darkMagenta:"#800080",darkRed:"#800000",darkYellow:"#808000",darkGray:"#808080",lightGray:"#c0c0c0"}[e])!=null?n:jn(e)}function Sr(e){return {declarations:e,cssText:Object.entries(e).map(([t,n])=>`${t}: ${n}`).join("; ")}}function Ug(e){return e==="both"||e==="distribute"?"justify":e}function Kg(e){return e==="center"||e==="both"?"middle":e}function _g(e,t){let n=[];if(e.underline&&n.push("underline"),(e.strike||e.doubleStrike)&&n.push("line-through"),n.length>0){t["text-decoration-line"]=n.join(" "),e.doubleStrike&&(t["text-decoration-style"]="double");return}(e.underline===false||e.strike===false||e.doubleStrike===false)&&(t["text-decoration-line"]="none");}function qg(e){return e==="superscript"?"super":e==="subscript"?"sub":"baseline"}function Xg(e,t){var r,o,i;let n=(r=e.borders)!=null?r:e.borderBottom?{bottom:e.borderBottom}:void 0;n&&(Do(t,"top",n.top),Do(t,"right",n.right),Do(t,"bottom",(o=n.bottom)!=null?o:n.between),Do(t,"left",(i=n.left)!=null?i:n.bar));}function Do(e,t,n){let r=Yg(n);r&&(e[`border-${t}`]=r,e[`padding-${t}`]=(n==null?void 0:n.space)!==void 0?`${n.space}pt`:"4pt");}function Yg(e){var o;if(!e||e.val==="none"||e.val==="nil")return null;let t=(o=jn(e.color))!=null?o:"#000000",n=e.size!==void 0?Math.max(.75,e.size/8):.75,r=e.val==="double"?"double":"solid";return `${n}pt ${r} ${t}`}function Ho(e,t,n){if(!n)return;let r=Zg(n);e[`border-${t}`]=r!=null?r:"0";}function Zg(e){var o;if(e.val==="none"||e.val==="nil")return null;let t=(o=jn(e.color))!=null?o:"#000000",n=e.size!==void 0?Math.max(.5,e.size/8):.75,r=e.val==="double"?"double":"solid";return `${n}pt ${r} ${t}`}function Jg(e,t,n){return e===void 0?null:t==="exact"||t==="atLeast"?yt(e):n!==true?String(e/240):`calc(var(--coco-word-doc-grid-line-height, 1em) * ${e/240})`}function yt(e){return `${e/20}pt`}function ic(e){let t=e.split(",").map(o=>o.trim()).filter(o=>o.length>0),n=Qg(t);return [...[...new Set([...t,...n.families])].map(eb),n.generic].join(", ")}function Qg(e){let t=e.join(" ");return /(?:楷体|kaiti|stkaiti)/i.test(t)?{families:["Kaiti SC","STKaiti","KaiTi","KaiTi_GB2312","DFKai-SB"],generic:"serif"}:/(?:仿宋|fangsong|stfangsong)/i.test(t)?{families:["STFangsong","FangSong","FangSong_GB2312","Noto Serif CJK SC"],generic:"serif"}:/(?:黑体|heiti|simhei|微软雅黑|microsoft yahei|pingfang)/i.test(t)?{families:["STHeiti","Heiti SC","PingFang SC","Microsoft YaHei","Noto Sans CJK SC"],generic:"sans-serif"}:{families:["SimSun","Songti SC","STSong","Noto Serif CJK SC"],generic:"serif"}}function eb(e){return `"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/[\r\n\f]/g," ")}"`}function Ha(e){return $(v(v({kind:"word"},e.defaults?{defaults:e.defaults}:{}),e.pageLayout?{pageLayout:e.pageLayout}:{}),{sections:e.sections,headers:e.headers.map(ac),footers:e.footers.map(ac),blocks:e.blocks.map(t=>$a(t))})}function _(e,t){var n,r;return (r=(n=be(e,t))==null?void 0:n.paragraph)!=null?r:null}function Oa(e,t){var r,o;let n=be(e,t);return (o=(r=n==null?void 0:n.previous)==null?void 0:r.paraId)!=null?o:null}function be(e,t){var n,r;return (r=(n=Da(e.blocks,t))!=null?n:e.headers.reduce((o,i)=>o!=null?o:Da(i.blocks,t),null))!=null?r:e.footers.reduce((o,i)=>o!=null?o:Da(i.blocks,t),null)}function Jt(e,t){var n,r;return (r=(n=zo(e.blocks,t))!=null?n:e.headers.reduce((o,i)=>o!=null?o:zo(i.blocks,t),null))!=null?r:e.footers.reduce((o,i)=>o!=null?o:zo(i.blocks,t),null)}function Oe(e,t){var n,r;return (r=(n=$o(e.blocks,t))!=null?n:e.headers.reduce((o,i)=>o!=null?o:$o(i.blocks,t),null))!=null?r:e.footers.reduce((o,i)=>o!=null?o:$o(i.blocks,t),null)}function $o(e,t){for(let n=0;n<e.length;n+=1){let r=e[n];if((r==null?void 0:r.kind)==="table"){if(r.tableId===t)return {table:r,container:e,tableIndex:n};for(let o of r.rows)for(let i of o.cells){let s=$o(i.blocks,t);if(s)return s}}}return null}function zo(e,t){for(let n=0;n<e.length;n+=1){let r=e[n];if((r==null?void 0:r.kind)==="table")for(let o=0;o<r.rows.length;o+=1){let i=r.rows[o],s=0;for(let a=0;a<i.cells.length;a+=1){let l=i.cells[a],c=zo(l.blocks,t);if(c)return c;if(l.blocks.some(u=>u.kind==="paragraph"&&u.paraId===t))return {table:r,container:e,tableIndex:n,row:i,rowIndex:o,cell:l,cellIndex:a,columnIndex:s};s+=Math.max(1,l.gridSpan);}}}return null}function Da(e,t){for(let n=0;n<e.length;n+=1){let r=e[n];if((r==null?void 0:r.kind)==="paragraph"&&r.paraId===t){let o=e[n-1];return {paragraph:r,previous:(o==null?void 0:o.kind)==="paragraph"?o:null,container:e,index:n,insertAfter(i){e.splice(n+1,0,i);},remove(){e.splice(n,1);}}}if((r==null?void 0:r.kind)==="table"){let o=sb(r,t);if(o)return o}}return null}function _e(e){return [...kr(e.blocks),...e.headers.flatMap(t=>kr(t.blocks)),...e.footers.flatMap(t=>kr(t.blocks))]}function kr(e){return e.flatMap(t=>t.kind==="paragraph"?[t]:t.rows.flatMap(n=>n.cells.flatMap(r=>kr(r.blocks))))}function Te(e){return e.content.map(t=>{var n;return t.kind==="text"?t.text:t.kind==="field"?(n=t.cachedText)!=null?n:"\uFFFC":t.kind==="drawing"&&t.text?t.text:"\uFFFC"}).join("")}function Tn(e){let t=new Set(_e(e).map(r=>r.paraId).filter(Boolean)),n="";do n=Math.floor(Math.random()*4294967295).toString(16).toUpperCase().padStart(8,"0");while(!n||t.has(n));return n}function $a(e){return e.type==="table"?$(v(v($(v({kind:"table",tableId:e.tableId},e.tableStyleId?{tableStyleId:e.tableStyleId}:{}),{columnWidths:e.columnWidths}),e.layout?{layout:e.layout}:{}),e.borders?{borders:e.borders}:{}),{rows:e.rows.map(t=>$(v(v(v({},t.height?{height:t.height}:{}),t.isHeader?{isHeader:true}:{}),t.cantSplit?{cantSplit:true}:{}),{cells:t.cells.map(n=>tb(n))}))}):sc(e)}function ac(e){return {kind:e.kind,partName:e.partName,blocks:e.blocks.map(t=>$a(t))}}function tb(e){var o;let n=((o=e.blocks)!=null?o:e.paragraphs).map(i=>$a(i)),r={gridSpan:e.gridSpan,blocks:n,paragraphs:kr(n)};return e.rowSpan!==void 0&&(r.rowSpan=e.rowSpan),e.vMerge!==void 0&&(r.vMerge=e.vMerge),e.width!==void 0&&(r.width=e.width),e.margin!==void 0&&(r.margin=e.margin),e.borders!==void 0&&(r.borders=e.borders),e.shading!==void 0&&(r.shading=e.shading),e.verticalAlignment!==void 0&&(r.verticalAlignment=e.verticalAlignment),e.noWrap!==void 0&&(r.noWrap=e.noWrap),r}function sc(e){var n,r;let t=e.spans.filter(o=>o.kind==="comment");return {kind:"paragraph",paraId:e.paraId,story:e.story,styleId:(n=e.styleId)!=null?n:null,format:(r=e.format)!=null?r:null,content:e.segments.flatMap(o=>o.kind==="text"?ob(o,t):o.kind==="revision"?rb(o):o.kind==="field"?nb(o):o.kind==="image"?ib(o):o.kind==="drawing"?ab(o):o.kind==="placeholder"&&o.placeholderKind==="pageBreak"?[{kind:"pageBreak"}]:[])}}function nb(e){var t;return [$(v({kind:"field",fieldKind:e.fieldKind,instruction:e.instruction},e.cachedText!==void 0?{cachedText:e.cachedText}:{}),{format:(t=e.format)!=null?t:null})]}function rb(e){var t;return e.text.length===0?[]:[{kind:"text",text:e.text,format:(t=e.format)!=null?t:null,marks:[{kind:"revision",id:`revision:${e.revisionId}`,revisionId:e.revisionId,revisionKind:e.revisionKind,author:e.author,date:e.date}]}]}function ob(e,t){var o,i,s;if(e.text.length===0)return [];let n=[],r=e.from;for(let a of t){let l=Math.max(e.from,a.from),c=Math.min(e.to,a.to);c<=l||(l>r&&n.push(v({kind:"text",text:e.text.slice(r-e.from,l-e.from),format:(o=e.format)!=null?o:null},e.hyperlink?{hyperlink:v({},e.hyperlink)}:{})),n.push($(v({kind:"text",text:e.text.slice(l-e.from,c-e.from),format:(i=e.format)!=null?i:null},e.hyperlink?{hyperlink:v({},e.hyperlink)}:{}),{marks:[{kind:"comment",id:a.id,commentId:a.commentId,author:a.author,date:a.date,body:a.body}]})),r=c);}return r<e.to&&n.push(v({kind:"text",text:e.text.slice(r-e.from),format:(s=e.format)!=null?s:null},e.hyperlink?{hyperlink:v({},e.hyperlink)}:{})),n}function ib(e){return [v(v(v(v(v({kind:"image",drawingId:e.drawingId,src:e.src},e.width!==void 0?{width:e.width}:{}),e.height!==void 0?{height:e.height}:{}),e.anchoringMode!==void 0?{anchoringMode:e.anchoringMode}:{}),e.wrap!==void 0?{wrap:e.wrap}:{}),e.position!==void 0?{position:e.position}:{})]}function ab(e){let t={kind:"drawing",drawingId:e.drawingId,drawingKind:e.drawingKind};return e.text!==void 0&&(t.text=e.text),e.width!==void 0&&(t.width=e.width),e.height!==void 0&&(t.height=e.height),e.anchoringMode!==void 0&&(t.anchoringMode=e.anchoringMode),e.wrap!==void 0&&(t.wrap=e.wrap),e.position!==void 0&&(t.position=e.position),e.hasBorder!==void 0&&(t.hasBorder=e.hasBorder),e.hasFill!==void 0&&(t.hasFill=e.hasFill),e.isLineOrConnector!==void 0&&(t.isLineOrConnector=e.isLineOrConnector),e.strokeColor!==void 0&&(t.strokeColor=e.strokeColor),e.strokeWidth!==void 0&&(t.strokeWidth=e.strokeWidth),e.innerTextAlign!==void 0&&(t.innerTextAlign=e.innerTextAlign),e.paragraphs&&e.paragraphs.length>0&&(t.paragraphs=e.paragraphs.map(n=>sc(n))),[t]}function sb(e,t){var n;for(let r of e.rows)for(let o of r.cells){let i=o.paragraphs.findIndex(a=>a.paraId===t),s=o.blocks.findIndex(a=>a.kind==="paragraph"&&a.paraId===t);if(i>=0&&s>=0)return {paragraph:o.paragraphs[i],previous:(n=o.paragraphs[i-1])!=null?n:null,container:o.blocks,index:s,insertAfter(a){o.paragraphs.splice(i+1,0,a),o.blocks.splice(s+1,0,a);},remove(){o.paragraphs.splice(i,1),o.blocks.splice(s,1);}}}return null}function Va(e){let t=pb(e),n=e.cells.reduce((o,i)=>o+lc(i),0),r=e.cells.reduce((o,i)=>o+dc(i),0);return e.isHeader?{kind:"repeat-header",risks:t,textLength:r,paragraphCount:n}:t.includes("cant-split")?{kind:"keep-together",risks:t,textLength:r,paragraphCount:n}:t.length>0?{kind:"unsplittable",risks:t,textLength:r,paragraphCount:n}:r===0?{kind:"keep-together",risks:["empty-row"],textLength:r,paragraphCount:n}:n>e.cells.length?{kind:"block-fragmentable",risks:t,textLength:r,paragraphCount:n}:{kind:"text-fragmentable",risks:t,textLength:r,paragraphCount:n}}function IE(e){let t={tables:0,rows:0,repeatHeaderRows:0,keepTogetherRows:0,blockFragmentableRows:0,textFragmentableRows:0,unsplittableRows:0,risks:{"cant-split":0,"row-span":0,"vertical-merge":0,"nested-table":0,media:0,field:0,"page-break":0,comment:0,revision:0,"empty-row":0}};Vo(e.blocks,t);for(let n of e.headers)Vo(n.blocks,t);for(let n of e.footers)Vo(n.blocks,t);return t}function NE(e,t){if(Va(e).kind!=="block-fragmentable"||t.cellBlockCounts.length!==e.cells.length)return null;let r=[],o=[],i=false,s=false;for(let a=0;a<e.cells.length;a+=1){let l=e.cells[a],c=cb(l,t.cellBlockCounts[a]);if(!c)return null;r.push(c.head),o.push(c.tail),i||(i=c.head.blocks.length>0),s||(s=c.tail.blocks.length>0);}return !i||!s?null:{head:$(v({},e),{height:void 0,cells:r}),tail:$(v({},e),{height:void 0,cells:o})}}function TE(e,t){if(Va(e).kind!=="text-fragmentable"||t.cellTextOffsets.length!==e.cells.length)return null;let r=[],o=[];for(let i=0;i<e.cells.length;i+=1){let s=lb(e.cells[i],t.cellTextOffsets[i]);if(!s)return null;r.push(s.head),o.push(s.tail);}return {head:$(v({},e),{height:void 0,cells:r}),tail:$(v({},e),{height:void 0,cells:o})}}function lb(e,t){if(e.blocks.length!==1)return null;let n=e.blocks[0];if(!n||n.kind!=="paragraph")return null;let r=db(n,t);return r?{head:$(v({},e),{blocks:[r.head],paragraphs:[r.head]}),tail:$(v({},e),{blocks:[r.tail],paragraphs:[r.tail]})}:null}function db(e,t){let n=e.content.reduce((s,a)=>s+(a.kind==="text"?a.text.length:0),0);if(!Number.isInteger(t)||t<=0||t>=n)return null;let r=[],o=[],i=0;for(let s of e.content){if(s.kind!=="text")return null;let a=i,l=i+s.text.length;if(i=l,l<=t){r.push(s);continue}if(a>=t){o.push(s);continue}let c=t-a;r.push($(v({},s),{text:s.text.slice(0,c)})),o.push($(v({},s),{text:s.text.slice(c)}));}return r.length===0||o.length===0?null:{head:$(v({},e),{content:r}),tail:$(v({},e),{content:o})}}function cb(e,t){if(!Number.isInteger(t)||t<0||t>e.blocks.length)return null;let n=e.blocks.slice(0,t),r=e.blocks.slice(t);return n.length===0&&r.length===0||n.length===0||r.length===0?null:{head:$(v({},e),{blocks:n,paragraphs:n.flatMap(za)}),tail:$(v({},e),{blocks:r,paragraphs:r.flatMap(za)})}}function Vo(e,t){for(let n of e)n.kind==="table"&&ub(n,t);}function ub(e,t){t.tables+=1;for(let n of e.rows){t.rows+=1;let r=Va(n);r.kind==="repeat-header"?t.repeatHeaderRows+=1:r.kind==="keep-together"?t.keepTogetherRows+=1:r.kind==="block-fragmentable"?t.blockFragmentableRows+=1:r.kind==="text-fragmentable"?t.textFragmentableRows+=1:t.unsplittableRows+=1;for(let o of r.risks)t.risks[o]+=1;for(let o of n.cells)Vo(o.blocks,t);}}function pb(e){var n;let t=new Set;e.cantSplit&&t.add("cant-split");for(let r of e.cells)((n=r.rowSpan)!=null?n:1)>1&&t.add("row-span"),(r.vMerge==="restart"||r.vMerge==="continue")&&t.add("vertical-merge"),fb(r,t);return [...t]}function fb(e,t){for(let n of e.blocks){if(n.kind==="table"){t.add("nested-table");continue}mb(n,t);}}function mb(e,t){for(let n of e.content)hb(n,t);}function hb(e,t){var n,r;(e.kind==="image"||e.kind==="drawing")&&t.add("media"),e.kind==="field"&&t.add("field"),e.kind==="pageBreak"&&t.add("page-break"),e.kind==="text"&&((n=e.marks)!=null&&n.some(o=>o.kind==="comment")&&t.add("comment"),(r=e.marks)!=null&&r.some(o=>o.kind==="revision")&&t.add("revision"));}function lc(e){return e.blocks.reduce((t,n)=>n.kind==="paragraph"?t+1:t+n.rows.reduce((r,o)=>r+o.cells.reduce((i,s)=>i+lc(s),0),0),0)}function dc(e){return e.blocks.reduce((t,n)=>t+gb(n),0)}function za(e){return e.kind==="paragraph"?[e]:e.rows.flatMap(t=>t.cells.flatMap(n=>n.blocks.flatMap(za)))}function gb(e){return e.kind==="paragraph"?e.content.reduce((t,n)=>t+(n.kind==="text"?n.text.length:0),0):e.rows.reduce((t,n)=>t+n.cells.reduce((r,o)=>r+dc(o),0),0)}function dn(e){return e?e.numFmt==="bullet"?"bullet":"numbered":null}function Ga(e,t,n=0){let r=Ua(n);return {numId:bb(e,t),ilvl:r,numFmt:t==="bullet"?"bullet":hc(r),lvlText:t==="bullet"?mc(r):`%${r+1}.`,start:1}}function ja(e,t){var o,i;let n=Ua(t),r=(o=dn(e))!=null?o:"numbered";return $(v({},e),{ilvl:n,numFmt:r==="bullet"?"bullet":hc(n),lvlText:r==="bullet"?mc(n):`%${n+1}.`,start:(i=e.start)!=null?i:1})}function Go(e){var n,r,o,i;let t=new Map;for(let s of _e(e)){let a=(n=s.format)==null?void 0:n.numbering;if(!((r=s.format)!=null&&r.hasNumbering)||!a)continue;let l=`${s.story}:${a.numId}:${a.ilvl}`;if(dn(a)==="bullet"){a.label=xb(a.lvlText);continue}let c=((i=t.get(l))!=null?i:((o=a.start)!=null?o:1)-1)+1;t.set(l,c),a.label=yb(c,a.numFmt,a.lvlText);}}function pc(e){return {left:(Ua(e)+1)*720,firstLine:-360}}function fc(e,t,n){let r=new Set(t);for(let o of t){let i=be(e,o);if(!i)continue;let s=[i.container[i.index-1],i.container[i.index+1]];for(let a of s){if((a==null?void 0:a.kind)!=="paragraph"||r.has(a.paraId))continue;let l=wb(a,n);if(l)return v({},l)}}return null}function bb(e,t){let n=new Set(_e(e).map(i=>{var s,a;return (a=(s=i.format)==null?void 0:s.numbering)==null?void 0:a.numId}).filter(i=>!!i)),r=1,o="";do o=`coco-${t}-${r}`,r+=1;while(n.has(o));return o}function wb(e,t){var r;let n=(r=e.format)!=null&&r.hasNumbering?e.format.numbering:void 0;return !n||dn(n)!==t?null:n.numId.startsWith(`coco-${t}-`)?n:null}function Ua(e){return Math.max(0,Math.min(8,Math.round(e)))}function mc(e){return ["\u2022","\u25E6","\u25AA"][e%3]}function hc(e){return ["decimal","lowerLetter","lowerRoman"][e%3]}function xb(e){return (e==null?void 0:e.replace(/%\d+/g,"").trim())||"\u2022"}function yb(e,t,n){let r=t==="lowerLetter"?cc(e,false):t==="upperLetter"?cc(e,true):t==="lowerRoman"?uc(e).toLowerCase():t==="upperRoman"?uc(e):String(e);return n?n.replace(/%\d+/g,r):`${r}.`}function cc(e,t){let n=Math.max(1,e),r="";for(;n>0;)n-=1,r=String.fromCharCode((t?65:97)+n%26)+r,n=Math.floor(n/26);return r}function uc(e){let t=Math.max(1,Math.min(3999,e)),n="",r=[[1e3,"M"],[900,"CM"],[500,"D"],[400,"CD"],[100,"C"],[90,"XC"],[50,"L"],[40,"XL"],[10,"X"],[9,"IX"],[5,"V"],[4,"IV"],[1,"I"]];for(let[o,i]of r)for(;t>=o;)n+=i,t-=o;return n}function nt(e){return Ft(e)}function Ir(e){var n,r;if(e.rows.length===0)return false;let t=(r=(n=e.rows[0])==null?void 0:n.cells.length)!=null?r:0;return t>0&&e.rows.every(o=>o.cells.length===t&&o.cells.every(i=>i.gridSpan===1&&(i.rowSpan===void 0||i.rowSpan===1)&&i.vMerge==null))}function wc(e,t,n,r,o,i=()=>Tn(e),s=()=>Pb(e)){var N,L,D,W,V,ee;let a=be(e,t);if(!a||a.container!==e.blocks)return null;let l=Math.max(1,Math.min(20,Math.trunc(r))),c=Math.max(1,Math.min(20,Math.trunc(o)));if(!Number.isFinite(r)||!Number.isFinite(o))return null;let u=a.paragraph,f=Ft([u]),p=Math.max(0,Math.min(n,Te(u).length)),w=pn(u.content,p);u.content=w.before;let b={kind:"paragraph",paraId:i(),story:u.story,styleId:u.styleId,format:u.format?jt(u.format):null,content:w.after},g=s(),h=Math.max(1440,((L=(N=e.pageLayout)==null?void 0:N.width)!=null?L:11906)-((W=(D=e.pageLayout)==null?void 0:D.margin.left)!=null?W:1440)-((ee=(V=e.pageLayout)==null?void 0:V.margin.right)!=null?ee:1440)),y=Math.max(360,Math.floor(h/c)),k={kind:"table",tableId:g,columnWidths:Array.from({length:c},()=>y),layout:{width:y*c,widthType:"dxa",alignment:"left"},borders:Ka("000000"),rows:Array.from({length:l},()=>({cells:Array.from({length:c},()=>{let pe={kind:"paragraph",paraId:i(),story:u.story,styleId:null,format:null,content:[{kind:"text",text:"",format:null}]};return {gridSpan:1,width:y,borders:Ka("000000"),blocks:[pe],paragraphs:[pe]}})}))},C=[u,k,b];return a.container.splice(a.index,1,...C),{changes:[{kind:"table",op:"insert-table",tableId:g,rowIndex:0,columnIndex:0}],cursor:{paraId:k.rows[0].cells[0].paragraphs[0].paraId,offset:0},container:a.container,startIndex:a.index,beforeBlocks:f,afterBlocks:Ft(C)}}function xc(e,t,n=()=>Tn(e)){var a,l,c;let r=Oe(e,t);if(!r||r.container!==e.blocks)return null;let o=(l=(a=r.table.rows[0])==null?void 0:a.cells[0])==null?void 0:l.paragraphs[0],i={kind:"paragraph",paraId:n(),story:(c=o==null?void 0:o.story)!=null?c:"word/document.xml",styleId:null,format:null,content:[{kind:"text",text:"",format:null}]},s=Ft([r.table]);return r.container.splice(r.tableIndex,1,i),{changes:[{kind:"table",op:"delete-table",tableId:t,rowIndex:0,columnIndex:0}],cursor:{paraId:i.paraId,offset:0},container:r.container,startIndex:r.tableIndex,beforeBlocks:s,afterBlocks:Ft([i])}}function yc(e,t,n,r=()=>Tn(e)){var u,f;let o=Jt(e,t);if(!o||!Ir(o.table))return null;let{table:i,rowIndex:s,cellIndex:a}=o;if(n.kind==="insert-row"){let p=s+(n.position==="after"?1:0),w=Sb(o.row,r);return i.rows.splice(p,0,w),{change:{kind:"table",op:"insert-row",tableId:i.tableId,rowIndex:p,columnIndex:a},cursor:{paraId:cn((u=w.cells[a])!=null?u:w.cells[0]).paraId,offset:0}}}if(n.kind==="delete-row"){if(i.rows.length<=1)return null;i.rows.splice(s,1);let p=i.rows[Math.min(s,i.rows.length-1)];return {change:{kind:"table",op:"delete-row",tableId:i.tableId,rowIndex:s,columnIndex:a},cursor:{paraId:cn(p.cells[Math.min(a,p.cells.length-1)]).paraId,offset:0}}}if(n.kind==="insert-column"){let p=a+(n.position==="after"?1:0);for(let g of i.rows){let h=g.cells[Math.min(a,g.cells.length-1)];g.cells.splice(p,0,Xa(h,r));}let w=(f=i.columnWidths[Math.min(a,i.columnWidths.length-1)])!=null?f:0;i.columnWidths.splice(p,0,w);let b=i.rows[s];return {change:{kind:"table",op:"insert-column",tableId:i.tableId,rowIndex:s,columnIndex:p},cursor:{paraId:cn(b.cells[p]).paraId,offset:0}}}if(i.rows[0].cells.length<=1)return null;for(let p of i.rows)p.cells.splice(a,1);a<i.columnWidths.length&&i.columnWidths.splice(a,1);let l=i.rows[s],c=l.cells[Math.min(a,l.cells.length-1)];return {change:{kind:"table",op:"delete-column",tableId:i.tableId,rowIndex:s,columnIndex:a},cursor:{paraId:cn(c).paraId,offset:0}}}function qa(e,t,n){var a;let r=Jt(e,t);if(!r)return null;let o=JSON.stringify({shading:r.cell.shading,verticalAlignment:r.cell.verticalAlignment,borders:r.cell.borders}),i={};if(n.backgroundColor!==void 0){let l=gc(n.backgroundColor);if(n.backgroundColor!==null&&!l)return null;l?r.cell.shading={fill:l,val:"clear"}:delete r.cell.shading,i.backgroundColor=l?`#${l}`:null;}if(n.verticalAlignment!==void 0&&(n.verticalAlignment?r.cell.verticalAlignment=n.verticalAlignment:delete r.cell.verticalAlignment,i.verticalAlignment=(a=n.verticalAlignment)!=null?a:null),n.borderColor!==void 0){let l=gc(n.borderColor);if(n.borderColor!==null&&!l)return null;r.cell.borders=l?Ka(l):vb(),i.borderColor=l?`#${l}`:null;}let s=JSON.stringify({shading:r.cell.shading,verticalAlignment:r.cell.verticalAlignment,borders:r.cell.borders});return o===s?null:{change:{kind:"table",op:"format-cell",tableId:r.table.tableId,rowIndex:r.rowIndex,columnIndex:r.columnIndex,format:i},cursor:{paraId:t,offset:0}}}function at(e,t){let n=Math.max(0,Math.min(t.anchor.rowIndex,t.focus.rowIndex)),r=Math.min(e.rows.length-1,Math.max(t.anchor.rowIndex,t.focus.rowIndex)),o=Math.max(0,Math.min(t.anchor.columnIndex,t.focus.columnIndex)),i=Math.max(t.anchor.columnIndex,t.focus.columnIndex),s=[];for(let a=n;a<=r;a+=1){let l=e.rows[a];if(!l)continue;let c=0;for(let u of l.cells){let f=Math.max(1,u.gridSpan),p=c+f-1;c<=i&&p>=o&&s.push({cell:u,rowIndex:a,columnIndex:c}),c+=f;}}return s}function vc(e,t,n){let r=Oe(e,t);if(!r)return null;let o=Math.min(n.anchor.rowIndex,n.focus.rowIndex),i=Math.max(n.anchor.rowIndex,n.focus.rowIndex),s=Math.min(n.anchor.columnIndex,n.focus.columnIndex),a=Math.max(n.anchor.columnIndex,n.focus.columnIndex);if(o<0||o>=r.table.rows.length||i>=r.table.rows.length||o!==i&&s!==a)return null;let l=r.table.rows[o];if(!l)return null;if(o!==i){let g=r.table.rows.slice(o,i+1).map(N=>N.cells[s]);if(g.some(N=>!N||N.gridSpan!==1||N.vMerge!=null))return null;let h=g,y=h[0],k=h.flatMap(N=>N.blocks.map(jt)),C=k.flatMap(N=>N.kind==="paragraph"?[N]:Cr([N]));y.blocks=k,y.paragraphs=C,y.rowSpan=h.length,y.vMerge="restart";for(let N of h.slice(1)){let L=N.paragraphs[0];L&&(L.content=[{kind:"text",text:"",format:null}]),N.blocks=L?[L]:[],N.paragraphs=L?[L]:[],N.rowSpan=void 0,N.vMerge="continue";}return {change:{kind:"table",op:"merge-cells",tableId:t,rowIndex:o,columnIndex:s,endRowIndex:i},cursor:{paraId:y.paragraphs[0].paraId,offset:0}}}if(s===a)return null;let c=at(r.table,n).filter(g=>g.rowIndex===o);if(c.length<2||c.some(g=>g.cell.gridSpan!==1||g.cell.vMerge!=null))return null;let u=c[0],f=c[c.length-1];if(u.columnIndex!==s||f.columnIndex!==a||c.length!==a-s+1)return null;let p=c.flatMap(({cell:g})=>g.blocks.map(jt)),w=p.flatMap(g=>g.kind==="paragraph"?[g]:Cr([g]));u.cell.blocks=p,u.cell.paragraphs=w,u.cell.gridSpan=c.length;let b=l.cells.indexOf(u.cell);return b<0?null:(l.cells.splice(b,c.length,u.cell),{change:{kind:"table",op:"merge-cells",tableId:t,rowIndex:o,columnIndex:s,endColumnIndex:a},cursor:{paraId:u.cell.paragraphs[0].paraId,offset:0}})}function Sc(e,t,n,r,o=()=>Tn(e)){var p,w;let i=Oe(e,t),s=i==null?void 0:i.table.rows[n];if(!i||!s)return null;let a=0,l=s.cells.findIndex(b=>{let g=a===r;return a+=Math.max(1,b.gridSpan),g}),c=l>=0?s.cells[l]:null;if(!c)return null;if(c.vMerge==="restart"&&((p=c.rowSpan)!=null?p:1)>1){let b=n+((w=c.rowSpan)!=null?w:1)-1;if(b>=i.table.rows.length)return null;let g=i.table.rows.slice(n,b+1).map(h=>h.cells[r]);if(g.length!==c.rowSpan||g.some((h,y)=>!h||h.gridSpan!==1?true:y===0?h.vMerge!=="restart":h.vMerge!=="continue"))return null;c.rowSpan=void 0,c.vMerge=void 0;for(let h of g.slice(1))h.rowSpan=void 0,h.vMerge=void 0;return {change:{kind:"table",op:"split-cell",tableId:t,rowIndex:n,columnIndex:r,endRowIndex:b},cursor:{paraId:c.paragraphs[0].paraId,offset:0}}}if(c.gridSpan<=1||c.vMerge!=null||c.rowSpan&&c.rowSpan>1)return null;let u=c.gridSpan;c.gridSpan=1;let f=Array.from({length:u-1},()=>Xa(c,o));return s.cells.splice(l+1,0,...f),{change:{kind:"table",op:"split-cell",tableId:t,rowIndex:n,columnIndex:r},cursor:{paraId:c.paragraphs[0].paraId,offset:0}}}function kc(e,t,n,r){let o=Oe(e,t);if(!o)return null;let i=[],s=null;for(let{cell:a}of at(o.table,n)){let l=cn(a).paraId;s!=null||(s={paraId:l,offset:0});let c=qa(e,l,r);c&&i.push(c.change);}return s&&i.length>0?{changes:i,cursor:s}:null}function Ec(e,t,n){var s;let r=Oe(e,t);if(!r)return null;let o=[],i=null;for(let{cell:a,rowIndex:l,columnIndex:c}of at(r.table,n)){let u=cn(a);i!=null||(i={paraId:u.paraId,offset:0}),!(a.blocks.length===1&&u.content.length===1&&((s=u.content[0])==null?void 0:s.kind)==="text"&&u.content[0].text.length===0)&&(u.content=[{kind:"text",text:"",format:null}],a.blocks=[u],a.paragraphs=[u],o.push({kind:"table",op:"clear-cell",tableId:t,rowIndex:l,columnIndex:c}));}return i&&o.length>0?{changes:o,cursor:i}:null}function Cc(e,t,n,r){var u,f,p;let o=Oe(e,t);if(!o||r.length===0||r.every(w=>w.length===0))return null;let i=r.length,s=Math.max(0,...r.map(w=>w.length)),a={anchor:n,focus:{rowIndex:n.rowIndex+i-1,columnIndex:n.columnIndex+s-1}},l=[],c=null;for(let{cell:w,rowIndex:b,columnIndex:g}of at(o.table,a)){let h=(u=r[b-n.rowIndex])==null?void 0:u[g-n.columnIndex];if(h===void 0)continue;let y=cn(w);if(c!=null||(c={paraId:y.paraId,offset:h.length}),w.paragraphs.map(N=>Te(N)).join(`
5
- `)===h&&w.blocks.length===1)continue;let C=(p=(f=y.content.find(N=>N.kind==="text"))==null?void 0:f.format)!=null?p:null;y.content=[{kind:"text",text:h,format:C?jt(C):null}],w.blocks=[y],w.paragraphs=[y],l.push({kind:"table",op:"replace-cell",tableId:t,rowIndex:b,columnIndex:g,text:h});}return c&&l.length>0?{changes:l,cursor:c}:null}function Ic(e,t,n,r){var c;let o=Oe(e,t);if(!o||r.length===0||r.every(u=>u.length===0))return null;let i=Math.max(0,...r.map(u=>u.length)),s={anchor:n,focus:{rowIndex:n.rowIndex+r.length-1,columnIndex:n.columnIndex+i-1}},a=[],l=null;for(let{cell:u,rowIndex:f,columnIndex:p}of at(o.table,s)){let w=(c=r[f-n.rowIndex])==null?void 0:c[p-n.columnIndex];if(!w)continue;let b=Kc(e,w.blocks),g=Cr(b);g.length!==0&&(u.blocks=b,u.paragraphs=g,Er(u,"margin",w.format.margin),Er(u,"borders",w.format.borders),Er(u,"shading",w.format.shading),Er(u,"verticalAlignment",w.format.verticalAlignment),Er(u,"noWrap",w.format.noWrap),l!=null||(l={paraId:g[0].paraId,offset:Te(g[0]).length}),a.push({kind:"table",op:"replace-cell",tableId:t,rowIndex:f,columnIndex:p,cellSnapshot:jt(u)}));}return l&&a.length>0?{changes:a,cursor:l}:null}function Er(e,t,n){n===void 0?delete e[t]:e[t]=jt(n);}function gc(e){if(e===null)return null;let t=e.trim().replace(/^#/,"").toUpperCase();return /^[0-9A-F]{6}$/.test(t)?t:null}function Ka(e){let t={val:"single",color:e,size:4};return {top:v({},t),right:v({},t),bottom:v({},t),left:v({},t)}}function vb(){let e={val:"nil"};return {top:v({},e),right:v({},e),bottom:v({},e),left:v({},e)}}function Sb(e,t){let o=e,{cells:n}=o,r=In(o,["cells"]);return $(v({},jt(r)),{cells:n.map(i=>Xa(i,t))})}function Xa(e,t){let a=e,{blocks:n,paragraphs:r}=a,o=In(a,["blocks","paragraphs"]),i=cn(e),s={kind:"paragraph",paraId:t(),story:i.story,styleId:i.styleId,format:i.format?jt(i.format):null,content:[{kind:"text",text:"",format:null}]};return $(v({},jt(o)),{gridSpan:1,blocks:[s],paragraphs:[s]})}function cn(e){let t=e.paragraphs[0];if(!t)throw new Error("Native table cell must contain at least one paragraph");return t}function jt(e){return JSON.parse(JSON.stringify(e))}function Qt(e,t,n,r){let o=_(e,t);return !o||r.length===0?null:(o.content=Gc(o.content,n,r),{kind:"text",op:"insert",paraId:t,offset:n,text:r})}function Nc(e,t,n,r,o={}){var u;let i=_(e,t);if(!i||!r)return null;let s=(u=o.drawingId)!=null?u:Cb(e),a=Uo(o.width),l=Uo(o.height),c=pn(i.content,n);return i.content=He([...c.before,v(v({kind:"image",drawingId:s,src:r},a?{width:a}:{}),l?{height:l}:{}),...c.after]),v(v({kind:"image",op:"insert",paraId:t,offset:n,drawingId:s,src:r},a?{width:a}:{}),l?{height:l}:{})}function Tc(e,t,n){let r=_(e,t);if(!r)return null;let o=Math.max(0,Math.min(n,Te(r).length)),i=pn(r.content,o);return r.content=He([...i.before,{kind:"pageBreak"},...i.after]),{kind:"page-break",op:"insert",paraId:t,offset:o}}function _o(e,t,n){let r=_(e,t);if(!r||n<0)return false;let o=0;for(let i of r.content){let s=$e(i);if(n>=o&&n<o+s)return i.kind==="pageBreak";o+=s;}return false}function Pc(e,t,n,r){let o=_(e,t),i=Nt(n,r);if(!o||i.from===i.to)return false;let s=0;for(let a of o.content){let l=$e(a);if(a.kind==="pageBreak"&&i.from<s+l&&i.to>s)return true;s+=l;}return false}function Mc(e,t,n,r){let o=_(e,t),i=o==null?void 0:o.content.find(c=>c.kind==="image"&&c.drawingId===n),s=Uo(r.width),a=Uo(r.height);if(!o||!i||!s||!a||i.width===s&&i.height===a)return null;i.width=s,i.height=a;let l=0;for(let c of o.content){if(c===i)break;l+=$e(c);}return {kind:"image",op:"resize",paraId:t,offset:l,drawingId:n,width:s,height:a}}function Nr(e,t,n){let r=be(e,t);if(!r)return null;let{paragraph:o}=r;if(n>0)return Eb(o,n);let i=r.previous;return i?(i.content=He([...i.content,...o.content]),r.remove(),{kind:"block",op:"merge",paraId:i.paraId}):null}function Tr(e,t,n){let r=be(e,t);if(!r)return null;let{paragraph:o}=r;if(n<jo(o.content))return jc(o,n);let i=r.container[r.index+1];return (i==null?void 0:i.kind)!=="paragraph"?null:(o.content=He([...o.content,...i.content]),r.container.splice(r.index+1,1),{kind:"block",op:"merge",paraId:o.paraId})}function un(e,t,n,r){let o=_(e,t),i=Nt(n,r);if(!o||i.from===i.to)return [];let s=Ib(o,i.from,i.to);return o.content=s.content,s.changes}function qo(e,t,n){var w;if(t.paraId===n.paraId)return un(e,t.paraId,t.offset,n.offset);let r=be(e,t.paraId),o=be(e,n.paraId);if(!r||!o)return [];if(r.container!==o.container)return [];let i=r.index<o.index?{start:r,end:o,startOffset:t.offset,endOffset:n.offset}:{start:o,end:r,startOffset:n.offset,endOffset:t.offset};if(i.start.paragraph.content.some(b=>b.kind!=="text")||i.end.paragraph.content.some(b=>b.kind!=="text"))return [];if(i.start.container.slice(i.start.index,i.end.index+1).some(b=>b.kind!=="paragraph"))return [];for(let b=i.start.index+1;b<i.end.index;b+=1){let g=i.start.container[b];if((g==null?void 0:g.kind)!=="paragraph"||g.content.some(h=>h.kind!=="text"))return []}let s=[],a=Te(i.start.paragraph),l=Te(i.end.paragraph),c=Math.max(0,Math.min(i.startOffset,a.length)),u=Math.max(0,Math.min(i.endOffset,l.length)),f=`${a.slice(0,c)}${l.slice(u)}`,p=i.end.index-i.start.index;for(let b=i.end.index;b>i.start.index;b-=1){let g=i.start.container[b];if((g==null?void 0:g.kind)==="paragraph"){if(g===i.end.paragraph&&u<l.length)s.push({kind:"text",op:"delete",paraId:g.paraId,offset:0,text:l.slice(0,u)});else {let h=Te(g);h.length>0&&s.push({kind:"text",op:"delete",paraId:g.paraId,offset:0,text:h});}(w=be(e,g.paraId))==null||w.remove();}}c<a.length&&s.push({kind:"text",op:"delete",paraId:i.start.paragraph.paraId,offset:c,text:a.slice(c)});for(let b=0;b<p;b+=1)s.push({kind:"block",op:"merge",paraId:i.start.paragraph.paraId});return i.start.paragraph.content=f.length>0?[{kind:"text",text:f,format:_c(i.start.paragraph.content,c)}]:[],s}function Rc(e,t,n,r){let o=be(e,t.paraId),i=be(e,n.paraId);if(!o||!i||o.container!==e.blocks||i.container!==e.blocks)return null;let s=o.index<i.index||o.index===i.index&&t.offset<=n.offset?{start:o,end:i,startOffset:t.offset,endOffset:n.offset}:{start:i,end:o,startOffset:n.offset,endOffset:t.offset};if(s.start.index===s.end.index||s.start.paragraph.content.some(b=>b.kind!=="text")||s.end.paragraph.content.some(b=>b.kind!=="text"))return null;let a=e.blocks.slice(s.start.index,s.end.index+1);if(!a.slice(1,-1).some(b=>b.kind==="table"||b.content.some(g=>g.kind!=="text")))return null;let l=Ft(a),c=Te(s.start.paragraph).length,u=Te(s.end.paragraph).length,f=Math.max(0,Math.min(s.startOffset,c)),p=Math.max(0,Math.min(s.endOffset,u)),w=[...un(e,s.end.paragraph.paraId,0,p),...un(e,s.start.paragraph.paraId,f,c)];if(s.start.paragraph.content=He([...s.start.paragraph.content,...s.end.paragraph.content]),e.blocks.splice(s.start.index+1,s.end.index-s.start.index),r.length>0){let b=Qt(e,s.start.paragraph.paraId,f,r);b&&w.push(b);}return w.push({kind:"structure",op:"delete-range",startParaId:s.start.paragraph.paraId,endParaId:s.end.paragraph.paraId,deletedBlockIds:a.slice(1).map(Uc)}),{changes:w,cursor:{paraId:s.start.paragraph.paraId,offset:f+r.length},container:e.blocks,startIndex:s.start.index,beforeBlocks:l,afterBlocks:Ft([s.start.paragraph])}}function Ya(e,t,n){let r=Nb(e,t,n);if(!r||r.blocks.length<2&&!Tb(r.blocks))return null;let o=Ft(r.blocks),i=o[0],s=o[o.length-1];return (i==null?void 0:i.kind)!=="paragraph"||(s==null?void 0:s.kind)!=="paragraph"?null:(i.content=pn(i.content,r.startOffset).after,s.content=pn(s.content,r.endOffset).before,o)}function Ac(e,t,n,r){if(t.paraId!==n.paraId||r.length===0)return null;let o=be(e,t.paraId);if(!o||o.container!==e.blocks)return null;let i=r[0],s=r[r.length-1];if((i==null?void 0:i.kind)!=="paragraph"||(s==null?void 0:s.kind)!=="paragraph")return null;let a=Ft([o.paragraph]),l=Te(o.paragraph).length,c=Math.max(0,Math.min(t.offset,n.offset,l)),u=Math.max(c,Math.min(Math.max(t.offset,n.offset),l)),f=pn(o.paragraph.content,c).before,p=pn(o.paragraph.content,u).after,w=Kc(e,r),b=w[0],g=w[w.length-1];if((b==null?void 0:b.kind)!=="paragraph"||(g==null?void 0:g.kind)!=="paragraph")return null;f.length===0&&p.length===0&&(o.paragraph.styleId=b.styleId,o.paragraph.format=b.format?jt(b.format):null),o.paragraph.content=He([...f,...b.content]);let y={paraId:o.paragraph.paraId,offset:jo(o.paragraph.content)},k=[o.paragraph];w.length===1?o.paragraph.content=He([...o.paragraph.content,...p]):(g.content=He([...g.content,...p]),k.push(...w.slice(1)),y={paraId:g.paraId,offset:jo(g.content)-jo(p)}),e.blocks.splice(o.index,1,...k);let C=Ft(k);return {changes:[{kind:"structure",op:"insert-range",paraId:o.paragraph.paraId,insertedBlockIds:k.slice(1).map(Uc)}],cursor:y,container:e.blocks,startIndex:o.index,beforeBlocks:a,afterBlocks:C}}function Pr(e,t,n,r,o){let i=Nt(n,r),s=un(e,t,i.from,i.to),a=Qt(e,t,i.from,o);return a?[...s,a]:s}function Lc(e,t,n,r){if(t.paraId===n.paraId)return Pr(e,t.paraId,t.offset,n.offset,r);let o=be(e,t.paraId),i=be(e,n.paraId);if(!o||!i||o.container!==i.container)return [];let s=o.index<i.index?t:n,a=qo(e,t,n);if(a.length===0||r.length===0)return a;let l=Qt(e,s.paraId,s.offset,r);return l?[...a,l]:a}function Za(e,t,n,r){var b,g,h,y,k,C,N,L;let o=be(e,t.paraId),i=be(e,n.paraId);if(!o||!i||o.container!==i.container)return null;let s=o.index<i.index||o.index===i.index&&t.offset<=n.offset?t:n,a=qo(e,t,n),l=_(e,s.paraId);if(!l||l.content.some(D=>D.kind!=="text"))return null;let c=r.replace(/\r\n?/g,`
1
+ 'use strict';var pack=require('@coco-vexel/coco-office/pack'),wordView=require('@coco-vexel/coco-office/word-view'),prosemirrorState=require('prosemirror-state'),prosemirrorModel=require('prosemirror-model');require('prosemirror-commands'),require('prosemirror-keymap'),require('prosemirror-view');var excel=require('@coco-vexel/coco-office/excel'),ppt=require('@coco-vexel/coco-office/ppt');var ph=Object.defineProperty,fh=Object.defineProperties;var mh=Object.getOwnPropertyDescriptors;var Wo=Object.getOwnPropertySymbols;var pd=Object.prototype.hasOwnProperty,fd=Object.prototype.propertyIsEnumerable;var Na=(e,t,n)=>t in e?ph(e,t,{enumerable:true,configurable:true,writable:true,value:n}):e[t]=n,v=(e,t)=>{for(var n in t||(t={}))pd.call(t,n)&&Na(e,n,t[n]);if(Wo)for(var n of Wo(t))fd.call(t,n)&&Na(e,n,t[n]);return e},$=(e,t)=>fh(e,mh(t));var Nn=(e,t)=>{var n={};for(var r in e)pd.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Wo)for(var r of Wo(e))t.indexOf(r)<0&&fd.call(e,r)&&(n[r]=e[r]);return n};var O=(e,t,n)=>Na(e,typeof t!="symbol"?t+"":t,n);var dn=class extends Error{constructor(n){super(`${n} editor is read-only`);O(this,"code","EDITOR_READ_ONLY");this.name="EditorReadOnlyError";}};var Id="http://schemas.openxmlformats.org/officeDocument/2006/relationships",kh="http://schemas.openxmlformats.org/package/2006/relationships",Jt="http://schemas.openxmlformats.org/drawingml/2006/main",md="urn:schemas-microsoft-com:vml",Eh={firstRow:true,lastRow:false,firstColumn:true,lastColumn:false,noHorizontalBand:false,noVerticalBand:true};async function CE(e){let t=await pack.fromZip(e);return Ra(t,wordView.buildIndices(t))}function IE(e){let t=pack.fromFlatOpc(e);return Ra(t,wordView.buildIndices(t))}async function NE(e){return Ra(e._getPackage(),e._getIndices())}function Ra(e,t){var g;let n=[],r=[],o=[],i=new Set,s=new Map(wordView.listTables(e,t,{scope:"all",includeNested:true,includeCellTexts:true}).map(h=>[h.tableId,h])),a=new Map;for(let[h,y]of t.tblIdx)a.set(y,h);let l=new Map,c=new Map(wordView.listDrawings(e,t,{scope:"all"}).map(h=>[h.drawingId,h])),u=new Map;for(let h of c.values()){if(!h.anchorParaId)continue;let y=(g=u.get(h.anchorParaId))!=null?g:[];y.push(h),u.set(h.anchorParaId,y);}let f=new Map;for(let[h,y]of t.drawingIdx){l.set(y,h);let k=rg(e,t,h,c.get(h));k&&f.set(h,k);}let p=Th(e),w={indices:t,drawingIdByElement:l,drawingInfoById:c,drawingsByAnchorParaId:u,imagesByDrawingId:f,theme:p,documentDefaults:ag(e,p),numbering:sg(e),numberingCounters:new Map,defaultParagraphStyleId:mg(e),paragraphStyleFormats:fg(e,t,p),tableStyleFormats:hg(e,p),hyperlinkByElement:Lh(e)};for(let h of wordView.listStories(e,{kinds:["body"]})){let y=Md(h.id,h.root,{context:w,attachedCommentIds:i,tableIdByElement:a,tableInfoById:s});n.push(...y.blocks),r.push(...y.paragraphs),o.push(...y.tables);}let b=Bh(e,{context:w,attachedCommentIds:i,tableIdByElement:a,tableInfoById:s});return {kind:"word",defaults:w.documentDefaults,pageLayout:Ch(e),sections:Mh(e),headers:b.headers,footers:b.footers,blocks:n,paragraphs:r,tables:o,detachedComments:Rg(t,i),detachedRevisions:[]}}function Ch(e){let t=e.parts.get("word/document.xml"),n=t==null?void 0:t.xmlDom;if(!n)return;let r=n.getElementsByTagNameNS(wordView.W_NS,"body")[0];if(!r)return;let o=Nh(r);if(o)return Nd(o)}function Nd(e){var f,p,w,b;let t=U(e,wordView.W_NS,"pgSz"),n=U(e,wordView.W_NS,"pgMar"),r=Pg(e,wordView.W_NS,"docGrid"),o=t?Me(t,"w"):void 0,i=t?Me(t,"h"):void 0;if(o===void 0||i===void 0)return;let s=t?t.getAttributeNS(wordView.W_NS,"orient"):null,a={width:o,height:i,margin:{top:n&&(f=Me(n,"top"))!=null?f:1440,right:n&&(p=Me(n,"right"))!=null?p:1440,bottom:n&&(w=Me(n,"bottom"))!=null?w:1440,left:n&&(b=Me(n,"left"))!=null?b:1440}},l=n?Me(n,"header"):void 0,c=n?Me(n,"footer"):void 0;l!==void 0&&(a.headerDistance=l),c!==void 0&&(a.footerDistance=c);let u=r?Ih(r):void 0;return u&&(a.docGrid=u),s==="landscape"?a.orientation="landscape":s==="portrait"&&(a.orientation="portrait"),a}function Ih(e){let t=e.getAttributeNS(wordView.W_NS,"type"),n=t==="default"||t==="lines"||t==="linesAndChars"||t==="snapToChars"?t:void 0,r=Me(e,"linePitch"),o=Me(e,"charSpace");if(!(n===void 0&&r===void 0&&o===void 0))return v(v(v({},n!==void 0?{type:n}:{}),r!==void 0?{linePitch:r}:{}),o!==void 0?{charSpace:o}:{})}function Nh(e){for(let t=e.childNodes.length-1;t>=0;t--){let n=e.childNodes[t];if(!n||n.nodeType!==1)continue;let r=n;if(r.namespaceURI===wordView.W_NS){if(r.localName==="sectPr")return r;if(r.localName==="p"){let o=U(r,wordView.W_NS,"pPr"),i=o?U(o,wordView.W_NS,"sectPr"):null;if(i)return i}}}return null}function Th(e){var i;let t={colors:new Map,fonts:new Map},n=(i=e.parts.get("word/theme/theme1.xml"))==null?void 0:i.xmlDom;if(!n)return t;let r=n.getElementsByTagNameNS(Jt,"clrScheme")[0];if(r)for(let s of ["dk1","lt1","dk2","lt2","accent1","accent2","accent3","accent4","accent5","accent6","hlink","folHlink"]){let a=Ph(r,s);a&&t.colors.set(s,a);}let o=n.getElementsByTagNameNS(Jt,"fontScheme")[0];return o&&(hd(t.fonts,U(o,Jt,"majorFont"),"major"),hd(t.fonts,U(o,Jt,"minorFont"),"minor")),t}function Ph(e,t){var r;let n=U(e,Jt,t);if(n)for(let o=0;o<n.childNodes.length;o++){let i=n.childNodes[o];if(!i||i.nodeType!==1||i.namespaceURI!==Jt)continue;let s=i,a=(r=s.getAttribute("val"))!=null?r:s.getAttribute("lastClr"),l=Da(a);if(l)return l}}function hd(e,t,n){if(!t)return;let r=Ta(U(t,Jt,"latin")),o=Ta(U(t,Jt,"ea"))||r,i=Ta(U(t,Jt,"cs"))||r;r&&(e.set(`${n}Ascii`,r),e.set(`${n}HAnsi`,r)),o&&e.set(`${n}EastAsia`,o),i&&e.set(`${n}Bidi`,i);}function Ta(e){var n;let t=(n=e==null?void 0:e.getAttribute("typeface"))!=null?n:void 0;return t&&t.length>0?t:void 0}function Mh(e){let t=Rh(e);if(t.length>0)return t;let n=wordView.listSections(e);return n.length>0?n.map(r=>{var o,i;return $(v({sectionIndex:r.sectionIndex,firstParaId:r.firstParaId,lastParaId:r.lastParaId},r.type?{type:r.type}:{}),{headerRefs:(o=r.headerRefs)!=null?o:[],footerRefs:(i=r.footerRefs)!=null?i:[],titlePage:r.titlePage===true})}):[]}function Rh(e){let t=wordView.listStories(e,{kinds:["body"]})[0];if(!t)return [];let n=Pd(t.partPath),r=[],o,i,s=0;for(let a=0;a<t.root.childNodes.length;a++){let l=t.root.childNodes[a];if(!l||l.nodeType!==1)continue;let c=l;if(c.namespaceURI===wordView.W_NS){if(c.localName==="p"){let u=Aa("body",c,s++);o||(o=u),i=u;let f=Do(c,wordView.W_NS,["pPr","sectPr"]);f&&o&&i&&(r.push(gd(r.length,o,i,f,e,n)),o=void 0);continue}if(c.localName==="tbl"){s++;continue}c.localName==="sectPr"&&o&&i&&(r.push(gd(r.length,o,i,c,e,n)),o=void 0);}}return r}function gd(e,t,n,r,o,i){var f;let s={sectionIndex:e,firstParaId:t,lastParaId:n,headerRefs:bd(o,r,i,"headerReference"),footerRefs:bd(o,r,i,"footerReference"),titlePage:U(r,wordView.W_NS,"titlePg")!==null},a=Nd(r);a&&(s.pageLayout=a);let l=U(r,wordView.W_NS,"pgNumType"),c=l?Me(l,"start"):void 0;c!==void 0&&(s.pageNumberStart=c);let u=(f=U(r,wordView.W_NS,"type"))==null?void 0:f.getAttributeNS(wordView.W_NS,"val");return (u==="nextPage"||u==="continuous"||u==="evenPage"||u==="oddPage"||u==="nextColumn")&&(s.type=u),s}function bd(e,t,n,r){if(!n)return [];let o=Td(e,n);if(!o)return [];let i=[];for(let s of ht(t,wordView.W_NS,r)){let a=s.getAttributeNS(Id,"id");if(!a)continue;let l=o.get(a);if(!l)continue;let c=s.getAttributeNS(wordView.W_NS,"type");i.push({type:c==="first"||c==="even"?c:"default",partName:Ah(n,l)});}return i}function Td(e,t){let n=e.parts.get(t),r=n==null?void 0:n.xmlDom;if(!r)return null;let o=new Map,i=r.getElementsByTagNameNS(kh,"Relationship");for(let s=0;s<i.length;s++){let a=i[s],l=a==null?void 0:a.getAttribute("Id"),c=a==null?void 0:a.getAttribute("Target");l&&c&&o.set(l,c);}return o}function Ah(e,t){if(t.startsWith("/"))return t.slice(1);let r=e.lastIndexOf("/_rels/");return r<0?t:`${e.slice(0,r)}/${t}`.replace(/\\/g,"/")}function Pd(e){let t=e.lastIndexOf("/"),n=t>=0?e.slice(0,t):"",r=e.slice(t+1);return n.length>0?`${n}/_rels/${r}.rels`:`_rels/${r}.rels`}function Lh(e){var n,r;let t=new Map;for(let o of wordView.listStories(e,{kinds:["body","header","footer"]})){let i=Pd(o.partPath),s=i?Td(e,i):null,a=o.root.getElementsByTagNameNS(wordView.W_NS,"hyperlink");for(let l=0;l<a.length;l+=1){let c=a[l];if(!c)continue;let u=c.getAttributeNS(Id,"id"),f=u?s==null?void 0:s.get(u):void 0,p=(n=c.getAttributeNS(wordView.W_NS,"anchor"))!=null?n:void 0,w=(r=c.getAttributeNS(wordView.W_NS,"tooltip"))!=null?r:void 0;!f&&!p||t.set(c,v(v(v({},f?{target:f}:{}),p?{anchor:p}:{}),w?{tooltip:w}:{}));}}return t}function Aa(e,t,n){var r;return ((r=t.getAttributeNS(wordView.W14_NS,"paraId"))==null?void 0:r.toUpperCase())||`${e}:p:${n}`}function Md(e,t,n){let r=[],o=[],i=[],s=n.flattenSdt?Wh(t,n.suppressPlaceholderSdtContent===true):Rd(t);for(let a=0;a<s.length;a++){let l=s[a];if(l.localName==="p"){let c=Ho(e,l,n.context,n.attachedCommentIds,Aa(e,l,a),n.suppressPlaceholderSdtContent===true);r.push(c),o.push(c);}else if(l.localName==="tbl"){let c=n.tableIdByElement.get(l),u=c?n.tableInfoById.get(c):void 0;if(!c||!u)continue;let f=Ad(u,l,e,n.context,n.attachedCommentIds,n.tableIdByElement,n.tableInfoById,n.suppressPlaceholderSdtContent===true);r.push(f),i.push(f),o.push(...Ld(f)),i.push(...Wd(f));}}return {blocks:r,paragraphs:o,tables:i}}function Rd(e){let t=[];for(let n=0;n<e.childNodes.length;n++){let r=e.childNodes[n];if(!r||r.nodeType!==1||r.namespaceURI!==wordView.W_NS)continue;let o=r;(o.localName==="p"||o.localName==="tbl")&&t.push(o);}return t}function Wh(e,t=false){let n=[],r=o=>{if(o.namespaceURI===wordView.W_NS&&!(t&&tc(o))){if(o.localName==="p"||o.localName==="tbl"){n.push(o);return}if(!(o.localName!=="sdt"&&o.localName!=="sdtContent"))for(let i=0;i<o.childNodes.length;i++){let s=o.childNodes[i];(s==null?void 0:s.nodeType)===1&&r(s);}}};for(let o=0;o<e.childNodes.length;o++){let i=e.childNodes[o];(i==null?void 0:i.nodeType)===1&&r(i);}return n}function Bh(e,t){let n=[],r=[];for(let o of wordView.listStories(e,{kinds:["header","footer"]})){if(o.kind!=="header"&&o.kind!=="footer")continue;let i=Md(o.id,o.root,$(v({},t),{flattenSdt:true,suppressPlaceholderSdtContent:true})),s={kind:o.kind,partName:o.partPath,blocks:i.blocks,paragraphs:i.paragraphs,tables:i.tables};o.kind==="header"?n.push(s):r.push(s);}return {headers:n,footers:r}}function Ho(e,t,n,r,o,i=false){let s=wordView.buildParagraphInfo(e,t,"full",true,{structuralWhitespace:true}),a=s.paraId||o||"",l=Qh(t,a,n,i);for(let g of l.spans)g.kind==="comment"&&r.add(g.commentId);let c={type:"paragraph",paraId:a,story:s.story,text:l.text,flags:{hasComments:s.hasComments===true,hasRevisions:s.hasRevisions===true,hasBookmarks:s.hasBookmarks===true,hasMath:s.hasMath===true},segments:l.segments,spans:l.spans};s.styleId!==void 0&&(c.styleId=s.styleId);let u=s.styleId!==void 0?n.paragraphStyleFormats.get(s.styleId):n.defaultParagraphStyleId?n.paragraphStyleFormats.get(n.defaultParagraphStyleId):void 0,f=Dh(t,n.theme),p=Sr(Do(t,wordView.W_NS,["pPr"]),n.theme),w=Bt(Bt(Bt(n.documentDefaults.paragraph,u),f),s.format),b=Bt(w,p);return b!=null&&b.numbering&&(b.numbering=cg(b.numbering,n),lg(b,n)),b!==void 0&&(c.format=b),s.table!==void 0&&(c.table=s.table),c}function Dh(e,t){for(let n of ht(e,wordView.W_NS,"r")){let r=Zt(n,t);if(r)return r}for(let n of ht(e,wordView.W_NS,"hyperlink")){let r=ht(n,wordView.W_NS,"r")[0],o=r?Zt(r,t):void 0;if(o)return o}for(let n of ["ins","del","fldSimple"])for(let r of ht(e,wordView.W_NS,n)){let o=ht(r,wordView.W_NS,"r")[0],i=o?Zt(o,t):void 0;if(i)return i}}function Ad(e,t,n,r,o,i,s,a=false){var y,k,C,N,L;let l=Yh((y=e.cellGrid)!=null?y:[]),c=Gh(t),u=Vh(t),f=e.tableStyleId?r.tableStyleFormats.get(e.tableStyleId):void 0,p=(k=jh(t))!=null?k:f==null?void 0:f.cellMargin,w=(C=Kh(t))!=null?C:f==null?void 0:f.borders,b=Oh(t),g=Dd(f==null?void 0:f.tableLook,$h(t)),h=0;return $(v(v(v($(v({type:"table",tableId:e.tableId},e.tableStyleId?{tableStyleId:e.tableStyleId}:{}),{columnWidths:e.columnWidths}),b?{layout:b}:{}),g?{tableLook:g}:{}),w?{borders:w}:{}),{rows:(L=(N=e.cellGrid)==null?void 0:N.map((F,W)=>{let V=Hh(c[W]);return $(v(v(v({},e.rowHeights[W]?{height:e.rowHeights[W]}:{}),V.isHeader?{isHeader:true}:{}),V.cantSplit?{cantSplit:true}:{}),{cells:F.map((ee,pe)=>{var ye,ke,Ae,De,Ge,Qe,wt,sn,dt,Ct,pt,Ye,Vt,ct,qt;let re=f?Zh(f,W,pe,(ye=e.cellGrid)!=null?ye:[],g):void 0,we=u[h++],he=we?Fh(we,{storyId:n,tableId:e.tableId,context:r,attachedCommentIds:o,tableIdByElement:i,tableInfoById:s,suppressPlaceholderSdtContent:a}):void 0,xe=he!=null&&he.paragraphs.length?he.paragraphs:ee.paragraphIds.map(It=>r.indices.paraIdx.get(It.toUpperCase())).filter(It=>It!==void 0).map(It=>Ho(n,It,r,o,void 0,a)),Ve=xe.length>0?xe:Xh(e.tableId,W,pe,ee.text),z={text:ee.text,gridSpan:ee.gridSpan,vMerge:ee.vMerge,blocks:he!=null&&he.blocks.length?he.blocks:Ve,paragraphs:Ve};if(re!=null&&re.paragraphFormat)for(let It of (ke=he==null?void 0:he.directParagraphs)!=null?ke:z.paragraphs)It.format=Bt(re.paragraphFormat,It.format);let Z=l.get(`${W}:${pe}`);Z!==void 0&&Z>1&&(z.rowSpan=Z),ee.width!==void 0&&(z.width=ee.width);let H=Uh(we,r.theme),Y=(wt=(Qe=(De=H==null?void 0:H.margin)!=null?De:(Ae=re==null?void 0:re.cell)==null?void 0:Ae.margin)!=null?Qe:(Ge=f==null?void 0:f.cell)==null?void 0:Ge.margin)!=null?wt:p;Y&&(z.margin=Y);let X=(pt=(dt=H==null?void 0:H.borders)!=null?dt:(sn=re==null?void 0:re.cell)==null?void 0:sn.borders)!=null?pt:(Ct=f==null?void 0:f.cell)==null?void 0:Ct.borders;return X&&(z.borders=X),((Ye=f==null?void 0:f.cell)==null?void 0:Ye.shading)!==void 0&&(z.shading=f.cell.shading),((Vt=re==null?void 0:re.cell)==null?void 0:Vt.shading)!==void 0&&(z.shading=re.cell.shading),ee.shading!==void 0&&(z.shading=ee.shading),(H==null?void 0:H.shading)!==void 0&&(z.shading=H.shading),((ct=f==null?void 0:f.cell)==null?void 0:ct.verticalAlignment)!==void 0&&(z.verticalAlignment=f.cell.verticalAlignment),((qt=re==null?void 0:re.cell)==null?void 0:qt.verticalAlignment)!==void 0&&(z.verticalAlignment=re.cell.verticalAlignment),(H==null?void 0:H.verticalAlignment)!==void 0&&(z.verticalAlignment=H.verticalAlignment),ee.verticalAlignment!==void 0&&(z.verticalAlignment=ee.verticalAlignment),(H==null?void 0:H.noWrap)!==void 0&&(z.noWrap=H.noWrap),z})})}))!=null?L:[]})}function Fh(e,t){let n=[],r=[],o=[],i=Rd(e);for(let s=0;s<i.length;s+=1){let a=i[s];if(a.localName==="p"){let f=Ho(t.storyId,a,t.context,t.attachedCommentIds,Aa(t.storyId,a,s),t.suppressPlaceholderSdtContent);n.push(f),r.push(f),o.push(f);continue}let l=t.tableIdByElement.get(a),c=l?t.tableInfoById.get(l):void 0;if(!l||!c)continue;let u=Ad(c,a,t.storyId,t.context,t.attachedCommentIds,t.tableIdByElement,t.tableInfoById,t.suppressPlaceholderSdtContent);n.push(u),r.push(...Ld(u));}return {blocks:n,paragraphs:r,directParagraphs:o}}function Ld(e){return e.rows.flatMap(t=>t.cells.flatMap(n=>n.paragraphs))}function Wd(e){return e.rows.flatMap(t=>t.cells.flatMap(n=>n.blocks.flatMap(r=>r.type==="table"?[r,...Wd(r)]:[])))}function Hh(e){let t={};if(!e)return t;let n=U(e,wordView.W_NS,"trPr");if(!n)return t;let r=it(U(n,wordView.W_NS,"tblHeader"));(r!==void 0?r:U(n,wordView.W_NS,"tblHeader")!==null)&&(t.isHeader=true);let o=it(U(n,wordView.W_NS,"cantSplit"));return (o!==void 0?o:U(n,wordView.W_NS,"cantSplit")!==null)&&(t.cantSplit=true),t}function Oh(e){let t=U(e,wordView.W_NS,"tblPr");if(!t)return;let n={},r=U(t,wordView.W_NS,"tblW");if(r){let c=Me(r,"w"),u=xd(r.getAttributeNS(wordView.W_NS,"type"));c!==void 0&&(n.width=c),u!==void 0&&(n.widthType=u);}let o=U(t,wordView.W_NS,"tblInd"),i=o?Me(o,"w"):void 0;i!==void 0&&(n.indent=i);let s=U(t,wordView.W_NS,"tblCellSpacing");if(s){let c=Me(s,"w"),u=xd(s.getAttributeNS(wordView.W_NS,"type"));c!==void 0&&(n.cellSpacing=c),u!==void 0&&(n.cellSpacingType=u);}let a=U(t,wordView.W_NS,"jc"),l=a?zh(a.getAttributeNS(wordView.W_NS,"val")):void 0;return l!==void 0&&(n.alignment=l),Object.keys(n).length>0?n:void 0}function $h(e){let t=U(e,wordView.W_NS,"tblPr");if(t)return Bd(t)}function Bd(e){var g;let t=U(e,wordView.W_NS,"tblLook"),n={},r=(g=t==null?void 0:t.getAttributeNS(wordView.W_NS,"val"))!=null?g:null,o=r?Number.parseInt(r,16):Number.NaN,i=h=>Number.isFinite(o)?(o&h)!==0:void 0,s=(h,y)=>{var C;let k=(C=t==null?void 0:t.getAttributeNS(wordView.W_NS,h))!=null?C:null;return k!==null?ec(k):i(y)},a=s("firstRow",32);a!==void 0&&(n.firstRow=a);let l=s("lastRow",64);l!==void 0&&(n.lastRow=l);let c=s("firstColumn",128);c!==void 0&&(n.firstColumn=c);let u=s("lastColumn",256);u!==void 0&&(n.lastColumn=u);let f=s("noHBand",512);f!==void 0&&(n.noHorizontalBand=f);let p=s("noVBand",1024);p!==void 0&&(n.noVerticalBand=p);let w=wd(U(e,wordView.W_NS,"tblStyleRowBandSize"));w!==void 0&&(n.rowBandSize=w);let b=wd(U(e,wordView.W_NS,"tblStyleColBandSize"));return b!==void 0&&(n.columnBandSize=b),Object.keys(n).length>0?n:void 0}function Dd(e,t){if(!(!e&&!t))return v(v({},e!=null?e:{}),t!=null?t:{})}function wd(e){let t=e?Me(e,"val"):void 0;return t!==void 0&&t>0?t:void 0}function xd(e){if(e==="auto"||e==="dxa"||e==="pct")return e}function zh(e){if(e==="left"||e==="center"||e==="right")return e}function Vh(e){let t=[];for(let n of ht(e,wordView.W_NS,"tr"))t.push(...ht(n,wordView.W_NS,"tc"));return t}function Gh(e){return ht(e,wordView.W_NS,"tr")}function jh(e){let t=U(e,wordView.W_NS,"tblPr"),n=t?U(t,wordView.W_NS,"tblCellMar"):null;return La(n)}function Uh(e,t){if(e)return Ba(U(e,wordView.W_NS,"tcPr"),t)}function La(e){if(!e)return;let t={};for(let n of ["top","right","bottom","left"]){let r=U(e,wordView.W_NS,n),o=r?Me(r,"w"):void 0;o!==void 0&&(t[n]=o);}return Object.keys(t).length>0?t:void 0}function Kh(e){let t=U(e,wordView.W_NS,"tblPr");return t?Fd(t):void 0}function Fd(e){let t=U(e,wordView.W_NS,"tblBorders");if(!t)return;let n={};for(let r of ["top","right","bottom","left","insideH","insideV"]){let o=Hd(U(t,wordView.W_NS,r));o&&(n[r]=o);}return Object.keys(n).length>0?n:void 0}function _h(e){let t=U(e,wordView.W_NS,"tcBorders");if(!t)return;let n={};for(let r of ["top","right","bottom","left"]){let o=Hd(U(t,wordView.W_NS,r));o&&(n[r]=o);}return Object.keys(n).length>0?n:void 0}function Oo(e,t){var i,s,a;if(!e)return;let n=(i=Da(e.getAttributeNS(wordView.W_NS,"fill")))!=null?i:Zd(t,e.getAttributeNS(wordView.W_NS,"themeFill")),r=(s=e.getAttributeNS(wordView.W_NS,"color"))!=null?s:void 0,o=(a=e.getAttributeNS(wordView.W_NS,"val"))!=null?a:void 0;return v(v(v({},n?{fill:Jd(n,e.getAttributeNS(wordView.W_NS,"themeFillTint"),e.getAttributeNS(wordView.W_NS,"themeFillShade"))}:{}),r?{color:r}:{}),o?{val:o}:{})}function qh(e){let t=e==null?void 0:e.getAttributeNS(wordView.W_NS,"val");return t==="top"||t==="center"||t==="bottom"||t==="both"?t:void 0}function Hd(e){var o,i;if(!e)return;let t=(o=e.getAttributeNS(wordView.W_NS,"val"))!=null?o:void 0,n=(i=e.getAttributeNS(wordView.W_NS,"color"))!=null?i:void 0,r=Me(e,"sz");return v(v(v({},t?{val:t}:{}),n?{color:n}:{}),r!==void 0?{size:r}:{})}function Xh(e,t,n,r){return r.length===0?[]:r.split(`
2
+ `).map((o,i)=>({type:"paragraph",paraId:`${e}:r${t}:c${n}:p${i}`,story:"body",text:o,flags:{hasComments:false,hasRevisions:false,hasBookmarks:false,hasMath:false},segments:o.length>0?[{kind:"text",from:0,to:o.length,text:o}]:[],spans:[]}))}function Yh(e){var r,o;let t=Od(e),n=new Map;for(let i=0;i<t.length;i++){let s=(r=t[i])!=null?r:[];for(let a=0;a<s.length;a++){let l=s[a];if(!l||l.cell.vMerge!=="restart")continue;let c=1;for(let u=i+1;u<t.length&&((o=t[u])==null?void 0:o.find(p=>p.startColumn===l.startColumn&&p.cell.vMerge==="continue"));u++)c+=1;c>1&&n.set(`${i}:${a}`,c);}}return n}function Od(e){return e.map(t=>{let n=0;return t.map(r=>{let o=n,i=Math.max(1,r.gridSpan);return n+=i,{startColumn:o,endColumn:n-1,columnSpan:i,cell:r}})})}function Zh(e,t,n,r,o){var b;let i=e.conditions;if(!i)return;let s=Od(r),a=(b=s[t])==null?void 0:b[n];if(!a)return;let l=r.length,c=Math.max(0,...s.flatMap(g=>g.map(h=>h.endColumn))),u=Jh(o),f=u.rowBandSize,p=u.columnBandSize,w;return !u.noHorizontalBand&&Math.floor(t/f)%2===0?w=xt(w,i.band1Horz):u.noHorizontalBand||(w=xt(w,i.band2Horz)),!u.noVerticalBand&&Math.floor(a.startColumn/p)%2===0?w=xt(w,i.band1Vert):u.noVerticalBand||(w=xt(w,i.band2Vert)),u.firstRow&&t===0&&(w=xt(w,i.firstRow)),u.lastRow&&t===l-1&&(w=xt(w,i.lastRow)),u.firstColumn&&a.startColumn===0&&(w=xt(w,i.firstCol)),u.lastColumn&&a.endColumn===c&&(w=xt(w,i.lastCol)),u.firstRow&&u.firstColumn&&t===0&&a.startColumn===0&&(w=xt(w,i.nwCell)),u.firstRow&&u.lastColumn&&t===0&&a.endColumn===c&&(w=xt(w,i.neCell)),u.lastRow&&u.firstColumn&&t===l-1&&a.startColumn===0&&(w=xt(w,i.swCell)),u.lastRow&&u.lastColumn&&t===l-1&&a.endColumn===c&&(w=xt(w,i.seCell)),w}function Jh(e){var t,n;return $(v(v({},Eh),e!=null?e:{}),{rowBandSize:(t=e==null?void 0:e.rowBandSize)!=null?t:1,columnBandSize:(n=e==null?void 0:e.columnBandSize)!=null?n:1})}function Qh(e,t,n,r=false){var we,he,xe,Ve;let o=[],i=[],s=new Map,a=new Set,l=new Set,c=0,u=null,f="",p=z=>nc(z,r),w=z=>{let Z=f.length;return f+=z,{from:Z,to:f.length}},b=e.childNodes;for(let z=0;z<b.length;z++){let Z=b[z];if(!Z||Z.nodeType!==1)continue;let H=Z;if(H.namespaceURI!==wordView.W_NS){g("unknown",H);continue}if(H.localName==="pPr")continue;if(H.localName==="hyperlink"){h(H);continue}let Y=kd(H,"commentRangeStart");if(Y!==null){s.set(Y,f.length);continue}let X=kd(H,"commentRangeEnd");if(X!==null){let Ae=s.get(X);if(Ae!==void 0){let De=Mg(n.indices,X,t,Ae,f.length,f);De&&i.push(De),s.delete(X);}continue}if(H.localName==="ins"||H.localName==="del"){let Ae=H.localName==="ins"?"insert":"delete",De=Fa(H,Ae==="delete"?"delText":"t"),{from:Ge,to:Qe}=w(De),wt=(we=H.getAttributeNS(wordView.W_NS,"id"))!=null?we:"",sn=ht(H,wordView.W_NS,"r")[0],dt=sn?Zt(sn,n.theme):void 0,Ct=$(v({kind:"revision",from:Ge,to:Qe,text:De},dt?{format:dt}:{}),{revisionId:wt,revisionKind:Ae,author:(he=H.getAttributeNS(wordView.W_NS,"author"))!=null?he:"",date:(xe=H.getAttributeNS(wordView.W_NS,"date"))!=null?xe:""});o.push(Ct),wt.length>0&&i.push({kind:"revision",id:`revision:${wt}`,revisionId:wt,revisionKind:Ae,paraId:t,from:Ge,to:Qe,text:De,author:Ct.author,date:Ct.date});continue}if(H.localName==="r"&&Ag(H)){y(H);continue}if(u&&H.localName==="r"){C(H);continue}if(H.localName==="fldSimple"&&k(H)||H.localName==="r"&&$g(H))continue;if(H.localName==="r"&&Bg(H)){V(H);continue}let ye=H.localName==="r"?Dg(H):[];if(ye.length>0){for(let Ae of ye)ee(Ae);continue}if(Wg(H)){ee(H);continue}let ke=p(H);if(ke.length>0){let{from:Ae,to:De}=w(ke),Ge={kind:"text",from:Ae,to:De,text:ke};if(H.localName==="r"){let Qe=Zt(H,n.theme);Qe&&(Ge.format=Qe);}o.push(Ge);}}F(),pe(e);for(let z of (Ve=n.drawingsByAnchorParaId.get(t))!=null?Ve:[])a.has(z.drawingId)||re(z);return {text:f,segments:o,spans:i.sort((z,Z)=>z.from-Z.from||z.to-Z.to||z.id.localeCompare(Z.id))};function g(z,Z){let{from:H,to:Y}=w("\uFFFC");o.push({kind:"placeholder",from:H,to:Y,placeholderKind:z,sourceTag:Z.localName});}function h(z){let Z=n.hyperlinkByElement.get(z);for(let H=0;H<z.childNodes.length;H+=1){let Y=z.childNodes[H];if(!Y||Y.nodeType!==1)continue;let X=Y;if(X.namespaceURI!==wordView.W_NS||X.localName!=="r")continue;let ye=p(X);if(ye.length===0)continue;let{from:ke,to:Ae}=w(ye),De={kind:"text",from:ke,to:Ae,text:ye},Ge=Zt(X,n.theme);Ge&&(De.format=Ge),Z&&(De.hyperlink=v({},Z)),o.push(De);}}function y(z){var H;let Z=Zt(z,n.theme);for(let Y=0;Y<z.childNodes.length;Y++){let X=z.childNodes[Y];if(!X||X.nodeType!==1)continue;let ye=X;if(ye.namespaceURI!==wordView.W_NS)continue;if(ye.localName==="fldChar"){let Qe=ye.getAttributeNS(wordView.W_NS,"fldCharType");Qe==="begin"?(F(),u={instruction:"",cachedText:"",inResult:false,format:Z}):Qe==="separate"&&u?u.inResult=true:Qe==="end"&&u&&(N(u),u=null);continue}if(u&&ye.localName==="instrText"){u.instruction+=(H=ye.textContent)!=null?H:"";continue}let ke=Lg(ye);if(ke.length===0)continue;if(u){u.inResult&&(u.cachedText+=ke);continue}let{from:Ae,to:De}=w(ke),Ge={kind:"text",from:Ae,to:De,text:ke};Z&&(Ge.format=Z),o.push(Ge);}}function k(z){var X;let Z=(X=z.getAttributeNS(wordView.W_NS,"instr"))!=null?X:"",H=Ed(Z);if(!H)return false;let Y=p(z);return L(H,Z,Y,Zt(z,n.theme)),true}function C(z){let Z=p(z);Z.length>0&&(u!=null&&u.inResult)&&(u.cachedText+=Z);}function N(z){let Z=Ed(z.instruction);if(Z){L(Z,z.instruction,z.cachedText,z.format);return}W(z);}function L(z,Z,H,Y){let{from:X,to:ye}=w("\uFFFC"),ke={kind:"field",from:X,to:ye,fieldKind:z,instruction:Z,cachedText:H};Y&&(ke.format=Y),o.push(ke);}function F(){u&&(W(u),u=null);}function W(z){if(z.cachedText.length===0)return;let{from:Z,to:H}=w(z.cachedText),Y={kind:"text",from:Z,to:H,text:z.cachedText};z.format&&(Y.format=z.format),o.push(Y);}function V(z){let Z=Zt(z,n.theme);for(let H=0;H<z.childNodes.length;H++){let Y=z.childNodes[H];if(!Y||Y.nodeType!==1)continue;let X=Y;if(X.namespaceURI!==wordView.W_NS)continue;if(X.localName==="br"&&X.getAttributeNS(wordView.W_NS,"type")==="page"){g("pageBreak",X);continue}let ye=p(X);if(ye.length===0)continue;let{from:ke,to:Ae}=w(ye),De={kind:"text",from:ke,to:Ae,text:ye};Z&&(De.format=Z),o.push(De);}}function ee(z){if(z.namespaceURI===wordView.W_NS&&z.localName==="pict"){let Ae=Fg(z,t,c);if(!Ae||l.has(z))return;l.add(z),c+=1;let{from:De,to:Ge}=w("\uFFFC");o.push($(v({},Ae),{from:De,to:Ge}));return}let Z=n.drawingIdByElement.get(z),H=Z?n.imagesByDrawingId.get(Z):void 0,Y=Z?n.drawingInfoById.get(Z):void 0;if(Z&&Y&&Y.kind!=="picture"){a.add(Z),re(Y);return}if(!Z||!H){g("drawing",z);return}let{from:X,to:ye}=w("\uFFFC");a.add(Z);let ke={kind:"image",from:X,to:ye,drawingId:Z,src:H.src,contentType:H.contentType};H.width!==void 0&&(ke.width=H.width),H.height!==void 0&&(ke.height=H.height),H.anchoringMode!==void 0&&(ke.anchoringMode=H.anchoringMode),H.wrap!==void 0&&(ke.wrap=H.wrap),H.position!==void 0&&(ke.position=H.position),o.push(ke);}function pe(z){for(let Z of ["drawing","pict"]){let H=z.getElementsByTagNameNS(wordView.W_NS,Z);for(let Y=0;Y<H.length;Y++){let X=H[Y];if(!X)continue;if(Z==="pict"){if(l.has(X))continue;ee(X);continue}let ye=n.drawingIdByElement.get(X);!ye||a.has(ye)||ee(X);}}}function re(z){var Ae;if(z.kind==="picture"||(a.add(z.drawingId),eg(z,n)))return;let Z=z.kind==="textBox"&&(Ae=z.innerText)!=null?Ae:"",{from:H,to:Y}=w(Z.length>0?Z:"\uFFFC"),X={kind:"drawing",from:H,to:Y,drawingId:z.drawingId,drawingKind:z.kind};Z.length>0&&(X.text=Z);let ye=$d(z.extentEMU);ye.width!==void 0&&(X.width=ye.width),ye.height!==void 0&&(X.height=ye.height),z.anchoringMode!==void 0&&(X.anchoringMode=z.anchoringMode),z.wrap!==void 0&&(X.wrap=z.wrap),z.position!==void 0&&(X.position=z.position),z.hasBorder!==void 0&&(X.hasBorder=z.hasBorder),z.hasFill!==void 0&&(X.hasFill=z.hasFill),z.isLineOrConnector!==void 0&&(X.isLineOrConnector=z.isLineOrConnector),z.innerTextAlign!==void 0&&(X.innerTextAlign=z.innerTextAlign);let ke=ng(z,n);ke.length>0&&(X.paragraphs=ke),o.push(X);}}var yd=127e3;function eg(e,t){var s,a,l,c;if(e.kind!=="textBox"||e.anchoringMode!=="anchor"||e.extentEMU.cx<=0||e.extentEMU.cy<=0||e.extentEMU.cx>yd||e.extentEMU.cy>yd)return false;let n=(a=(s=e.position)==null?void 0:s.horizontal)==null?void 0:a.posOffset,r=(c=(l=e.position)==null?void 0:l.vertical)==null?void 0:c.posOffset;if(!(n!==void 0&&n<0||r!==void 0&&r<0))return false;let o=t.indices.drawingIdx.get(e.drawingId);if(!o)return false;let i=o.getElementsByTagNameNS(wordView.W_NS,"txbxContent")[0];return i?tg(i):false}function tg(e){var o,i;let t=[],n=0,r=e.getElementsByTagName("*");for(let s=0;s<r.length;s+=1){let a=r[s];if(!(!a||a.namespaceURI!==wordView.W_NS)){if(a.localName==="fldChar"){let l=a.getAttributeNS(wordView.W_NS,"fldCharType");if(l==="begin")t.push({instruction:""});else if(l==="end"){let c=t.pop();if(!c||!/^SET\b/i.test(c.instruction.trim()))return false;n+=1;}continue}if(a.localName==="instrText"){let l=t[t.length-1];if(!l)return false;l.instruction+=(o=a.textContent)!=null?o:"";continue}if(a.localName==="t"&&((i=a.textContent)!=null?i:"").trim().length>0&&t.length===0)return false}}return t.length===0&&n>0}function ng(e,t){if(e.kind!=="textBox"||!e.innerParagraphIds||e.innerParagraphIds.length===0)return [];let n=new Set;return e.innerParagraphIds.flatMap(r=>{let o=t.indices.paraIdx.get(r);return o?[Ho("body",o,t,n,r)]:[]})}function rg(e,t,n,r){let o=wordView.getImageBytesSync(e,t,n);if(!o)return null;let i={src:`data:${o.contentType};base64,${ig(o.bytes)}`,contentType:o.contentType};r&&(i.anchoringMode=r.anchoringMode,r.wrap!==void 0&&(i.wrap=r.wrap),r.position!==void 0&&(i.position=r.position));let s=og(o);return s.width!==void 0&&(i.width=s.width),s.height!==void 0&&(i.height=s.height),i}function og(e){return $d(e.extentEMU)}function $d(e){let{cx:t,cy:n}=e;return {width:t>0?Math.round(t/914400*96):void 0,height:n>0?Math.round(n/914400*96):void 0}}function ig(e){let t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n="",r=0;for(;r+2<e.length;r+=3){let o=e[r]<<16|e[r+1]<<8|e[r+2];n+=Tn(t,o>>18&63),n+=Tn(t,o>>12&63),n+=Tn(t,o>>6&63),n+=Tn(t,o&63);}if(r<e.length){let o=e[r],i=r+1<e.length?e[r+1]:0,s=o<<16|i<<8;n+=Tn(t,s>>18&63),n+=Tn(t,s>>12&63),n+=r+1<e.length?Tn(t,s>>6&63):"=",n+="=";}return n}function Tn(e,t){return e.charAt(t)}function ag(e,t){let n={},r=Wa(e);if(!r)return n;let o=r.getElementsByTagNameNS(wordView.W_NS,"docDefaults")[0];if(!o)return n;let i=Do(o,wordView.W_NS,["rPrDefault","rPr"]),s=i?Kd(i,t):void 0;s&&(n.run=s);let a=Do(o,wordView.W_NS,["pPrDefault","pPr"]);if(a){let l=Sr(a,t);l&&(n.paragraph=l);}return n}function Wa(e){for(let t of e.parts.values())if(t.contentType==="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"&&t.xmlDom)return t.xmlDom;return null}function sg(e){var s,a,l,c,u,f,p;let t=dg(e);if(!t)return {nums:new Map};let n=new Map,r=t.getElementsByTagNameNS(wordView.W_NS,"abstractNum");for(let w=0;w<r.length;w++){let b=r[w];if(!b)continue;let g=b.getAttributeNS(wordView.W_NS,"abstractNumId");if(!g)continue;let h=new Map;for(let y of ht(b,wordView.W_NS,"lvl")){let k=(s=Me(y,"ilvl"))!=null?s:0,C=(l=(a=U(y,wordView.W_NS,"numFmt"))==null?void 0:a.getAttributeNS(wordView.W_NS,"val"))!=null?l:void 0,N=(u=(c=U(y,wordView.W_NS,"lvlText"))==null?void 0:c.getAttributeNS(wordView.W_NS,"val"))!=null?u:void 0,L=U(y,wordView.W_NS,"start"),F=L&&(f=Me(L,"val"))!=null?f:1,W=Sr(U(y,wordView.W_NS,"pPr"));h.set(k,v(v(v({ilvl:k,start:F},C?{numFmt:C}:{}),N?{lvlText:N}:{}),W?{paragraphFormat:W}:{}));}n.set(g,h);}let o=new Map,i=t.getElementsByTagNameNS(wordView.W_NS,"num");for(let w=0;w<i.length;w++){let b=i[w];if(!b)continue;let g=b.getAttributeNS(wordView.W_NS,"numId"),h=(p=U(b,wordView.W_NS,"abstractNumId"))==null?void 0:p.getAttributeNS(wordView.W_NS,"val");if(!g||!h)continue;let y=n.get(h);y&&o.set(g,y);}return {nums:o}}function lg(e,t){var o,i;if(!e.numbering)return;let n=(o=t.numbering.nums.get(e.numbering.numId))==null?void 0:o.get(e.numbering.ilvl),r=n==null?void 0:n.paragraphFormat;if(r){if(r.indent!==void 0){let s=(i=e.indent)!=null?i:{};e.indent=v({},s),r.indent.left!==void 0&&(s.left===void 0||s.left===0)&&(e.indent.left=r.indent.left),r.indent.right!==void 0&&s.right===void 0&&(e.indent.right=r.indent.right),r.indent.firstLine!==void 0&&s.firstLine===void 0&&(e.indent.firstLine=r.indent.firstLine);}e.spacing===void 0&&r.spacing!==void 0&&(e.spacing=v({},r.spacing)),e.alignment===void 0&&r.alignment!==void 0&&(e.alignment=r.alignment);}}function dg(e){for(let t of e.parts.values())if(t.contentType==="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml"&&t.xmlDom)return t.xmlDom;return null}function cg(e,t){var l,c,u,f,p;let n=(l=t.numbering.nums.get(e.numId))==null?void 0:l.get(e.ilvl),r=(c=e.numFmt)!=null?c:n==null?void 0:n.numFmt,o=(u=e.lvlText)!=null?u:n==null?void 0:n.lvlText,i=v(v(v(v({},e),r?{numFmt:r}:{}),o?{lvlText:o}:{}),(n==null?void 0:n.start)!==void 0?{start:n.start}:{}),s=`${i.numId}:${i.ilvl}`;if(r==="bullet")return i.label=ug(o),i;let a=((p=t.numberingCounters.get(s))!=null?p:((f=n==null?void 0:n.start)!=null?f:1)-1)+1;return t.numberingCounters.set(s,a),i.label=pg(a,r,o),i}function ug(e){let t=e==null?void 0:e.replace(/%\d+/g,"").trim();return t&&t.length>0?t:"\u2022"}function pg(e,t,n){let r=t==="lowerLetter"?vd(e,false):t==="upperLetter"?vd(e,true):String(e);return n?n.replace(/%\d+/g,r):`${r}.`}function vd(e,t){let n=Math.max(1,e),r="";for(;n>0;)n-=1,r=String.fromCharCode((t?65:97)+n%26)+r,n=Math.floor(n/26);return r}function fg(e,t,n){var i,s;let r=new Map;for(let a of e.parts.values()){if(a.contentType!=="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"||!a.xmlDom)continue;let l=a.xmlDom.getElementsByTagNameNS(wordView.W_NS,"style");for(let c=0;c<l.length;c++){let u=l[c];if(!u)continue;let f=u.getAttributeNS(wordView.W_NS,"styleId");if(!f||((i=u.getAttributeNS(wordView.W_NS,"type"))!=null?i:"paragraph")!=="paragraph")continue;let w={},b=(s=U(u,wordView.W_NS,"basedOn"))==null?void 0:s.getAttributeNS(wordView.W_NS,"val");b&&(w.basedOn=b);let g=yg(u,n);g&&(w.format=g),r.set(f,w);}}let o=new Map;for(let a of r.keys()){let l=Gd(a,r,new Set);l&&o.set(a,l);}for(let a of t.stylesIdx.values()){if(a.outlineLevel===void 0)continue;let l=o.get(a.styleId);o.set(a.styleId,Bt(l,{outlineLevel:a.outlineLevel}));}return o}function mg(e){var r;let t=Wa(e);if(!t)return;let n=t.getElementsByTagNameNS(wordView.W_NS,"style");for(let o=0;o<n.length;o++){let i=n[o];if(!i||((r=i.getAttributeNS(wordView.W_NS,"type"))!=null?r:"paragraph")!=="paragraph"||i.getAttributeNS(wordView.W_NS,"default")!=="1")continue;let a=i.getAttributeNS(wordView.W_NS,"styleId");if(a)return a}}function hg(e,t){var s,a;let n=new Map,r=Wa(e);if(!r)return new Map;let o=r.getElementsByTagNameNS(wordView.W_NS,"style");for(let l=0;l<o.length;l++){let c=o[l];if(!c)continue;let u=c.getAttributeNS(wordView.W_NS,"styleId");if(!u||((s=c.getAttributeNS(wordView.W_NS,"type"))!=null?s:"paragraph")!=="table")continue;let p={},w=(a=U(c,wordView.W_NS,"basedOn"))==null?void 0:a.getAttributeNS(wordView.W_NS,"val");w&&(p.basedOn=w);let b=gg(c,t);b&&(p.format=b),n.set(u,p);}let i=new Map;for(let l of n.keys()){let c=zd(l,n,new Set);c&&i.set(l,c);}return i}function zd(e,t,n){if(n.has(e))return;n.add(e);let r=t.get(e);if(!r)return;let o=r.basedOn?zd(r.basedOn,t,n):void 0;return Ma(o,r.format)}function gg(e,t){let n=Ma(Vd(U(e,wordView.W_NS,"tblPr"),U(e,wordView.W_NS,"tcPr"),t),bg(e,t)),r=wg(e,t);return r?Ma(n,{conditions:r}):n}function bg(e,t){for(let n of ht(e,wordView.W_NS,"tblStylePr"))if(n.getAttributeNS(wordView.W_NS,"type")==="wholeTable")return Vd(U(n,wordView.W_NS,"tblPr"),U(n,wordView.W_NS,"tcPr"),t)}function wg(e,t){let n={};for(let r of ht(e,wordView.W_NS,"tblStylePr")){let o=r.getAttributeNS(wordView.W_NS,"type");if(o!=="firstRow"&&o!=="lastRow"&&o!=="firstCol"&&o!=="lastCol"&&o!=="band1Horz"&&o!=="band2Horz"&&o!=="band1Vert"&&o!=="band2Vert"&&o!=="nwCell"&&o!=="neCell"&&o!=="swCell"&&o!=="seCell")continue;let i=xg(r,t);i&&(n[o]=i);}return Object.keys(n).length>0?n:void 0}function xg(e,t){let n={},r=Ba(U(e,wordView.W_NS,"tcPr"),t);r&&(n.cell=r);let o=Bt(Sr(U(e,wordView.W_NS,"pPr"),t),jd(U(e,wordView.W_NS,"rPr"),t));return o&&(n.paragraphFormat=o),Object.keys(n).length>0?n:void 0}function Vd(e,t,n){let r={};if(e){let o=Fd(e);o&&(r.borders=o);let i=La(U(e,wordView.W_NS,"tblCellMar"));i&&(r.cellMargin=i);let s=Bd(e);s&&(r.tableLook=s);}if(t){let o=Ba(t,n);o&&(r.cell=o);}return Object.keys(r).length>0?r:void 0}function Ba(e,t){if(!e)return;let n={},r=La(U(e,wordView.W_NS,"tcMar"));r&&(n.margin=r);let o=_h(e);o&&(n.borders=o);let i=Oo(U(e,wordView.W_NS,"shd"),t);i&&(n.shading=i);let s=qh(U(e,wordView.W_NS,"vAlign"));s&&(n.verticalAlignment=s);let a=it(U(e,wordView.W_NS,"noWrap"));return (a!==void 0?a:U(e,wordView.W_NS,"noWrap")!==null)&&(n.noWrap=true),Object.keys(n).length>0?n:void 0}function Ma(e,t){var r,o,i,s,a,l,c,u,f,p,w,b,g,h,y,k,C,N,L,F;if(!e&&!t)return;let n=v(v({},e!=null?e:{}),t!=null?t:{});if((e!=null&&e.borders||t!=null&&t.borders)&&(n.borders=v(v({},(r=e==null?void 0:e.borders)!=null?r:{}),(o=t==null?void 0:t.borders)!=null?o:{})),(e!=null&&e.cellMargin||t!=null&&t.cellMargin)&&(n.cellMargin=v(v({},(i=e==null?void 0:e.cellMargin)!=null?i:{}),(s=t==null?void 0:t.cellMargin)!=null?s:{})),(e!=null&&e.tableLook||t!=null&&t.tableLook)&&(n.tableLook=Dd(e==null?void 0:e.tableLook,t==null?void 0:t.tableLook)),(e!=null&&e.cell||t!=null&&t.cell)&&(n.cell=v(v({},(a=e==null?void 0:e.cell)!=null?a:{}),(l=t==null?void 0:t.cell)!=null?l:{}),((c=e==null?void 0:e.cell)!=null&&c.margin||(u=t==null?void 0:t.cell)!=null&&u.margin)&&(n.cell.margin=v(v({},(p=(f=e==null?void 0:e.cell)==null?void 0:f.margin)!=null?p:{}),(b=(w=t==null?void 0:t.cell)==null?void 0:w.margin)!=null?b:{})),((g=e==null?void 0:e.cell)!=null&&g.borders||(h=t==null?void 0:t.cell)!=null&&h.borders)&&(n.cell.borders=v(v({},(k=(y=e==null?void 0:e.cell)==null?void 0:y.borders)!=null?k:{}),(N=(C=t==null?void 0:t.cell)==null?void 0:C.borders)!=null?N:{}))),(e!=null&&e.paragraphFormat||t!=null&&t.paragraphFormat)&&(n.paragraphFormat=Bt(e==null?void 0:e.paragraphFormat,t==null?void 0:t.paragraphFormat)),e!=null&&e.conditions||t!=null&&t.conditions){n.conditions=v({},(L=e==null?void 0:e.conditions)!=null?L:{});for(let[W,V]of Object.entries((F=t==null?void 0:t.conditions)!=null?F:{}))n.conditions[W]=xt(n.conditions[W],V);}return n}function xt(e,t){var r,o,i,s,a,l,c,u,f,p,w,b,g,h;if(!e&&!t)return;let n=v(v({},e!=null?e:{}),t!=null?t:{});return (e!=null&&e.cell||t!=null&&t.cell)&&(n.cell=v(v({},(r=e==null?void 0:e.cell)!=null?r:{}),(o=t==null?void 0:t.cell)!=null?o:{}),((i=e==null?void 0:e.cell)!=null&&i.margin||(s=t==null?void 0:t.cell)!=null&&s.margin)&&(n.cell.margin=v(v({},(l=(a=e==null?void 0:e.cell)==null?void 0:a.margin)!=null?l:{}),(u=(c=t==null?void 0:t.cell)==null?void 0:c.margin)!=null?u:{})),((f=e==null?void 0:e.cell)!=null&&f.borders||(p=t==null?void 0:t.cell)!=null&&p.borders)&&(n.cell.borders=v(v({},(b=(w=e==null?void 0:e.cell)==null?void 0:w.borders)!=null?b:{}),(h=(g=t==null?void 0:t.cell)==null?void 0:g.borders)!=null?h:{}))),(e!=null&&e.paragraphFormat||t!=null&&t.paragraphFormat)&&(n.paragraphFormat=Bt(e==null?void 0:e.paragraphFormat,t==null?void 0:t.paragraphFormat)),n}function Gd(e,t,n){if(n.has(e))return;n.add(e);let r=t.get(e);if(!r)return;let o=r.basedOn?Gd(r.basedOn,t,n):void 0;return Bt(o,r.format)}function yg(e,t){let n=Sr(U(e,wordView.W_NS,"pPr"),t),r=jd(U(e,wordView.W_NS,"rPr"),t);return Bt(n,r)}function Sr(e,t){var o,i;let n={},r=false;if(e){let s=U(e,wordView.W_NS,"jc"),a=s==null?void 0:s.getAttributeNS(wordView.W_NS,"val");(a==="left"||a==="center"||a==="right"||a==="both"||a==="distribute")&&(n.alignment=a,r=true);let l=U(e,wordView.W_NS,"ind");if(l){let N=Me(l,"left"),L=Me(l,"right"),F=Me(l,"firstLine"),W=Me(l,"hanging"),V=F!==void 0?F:W!==void 0?-W:void 0;(N!==void 0||L!==void 0||V!==void 0)&&(n.indent={},N!==void 0&&(n.indent.left=N),L!==void 0&&(n.indent.right=L),V!==void 0&&(n.indent.firstLine=V),r=true);}let c=U(e,wordView.W_NS,"spacing");if(c){let N=Me(c,"before"),L=Me(c,"after"),F=Me(c,"line"),W=c.getAttributeNS(wordView.W_NS,"lineRule"),V=W==="auto"||W==="exact"||W==="atLeast"?W:void 0;(N!==void 0||L!==void 0||F!==void 0||V!==void 0)&&(n.spacing={},N!==void 0&&(n.spacing.before=N),L!==void 0&&(n.spacing.after=L),F!==void 0&&(n.spacing.line=F),V!==void 0&&(n.spacing.lineRule=V),r=true);}let u=vg(U(e,wordView.W_NS,"tabs"));u!==void 0&&(n.tabStops=u,r=true);let f=U(e,wordView.W_NS,"outlineLvl"),p=f?Me(f,"val"):void 0;p!==void 0&&p>=0&&p<=9&&(n.outlineLevel=p,r=true);let w=U(e,wordView.W_NS,"numPr");if(w){let N=(o=U(w,wordView.W_NS,"numId"))==null?void 0:o.getAttributeNS(wordView.W_NS,"val");N&&N!=="0"&&(n.hasNumbering=true,n.numbering={numId:N,ilvl:U(w,wordView.W_NS,"ilvl")&&(i=Me(U(w,wordView.W_NS,"ilvl"),"val"))!=null?i:0},r=true);}Ud(U(e,wordView.W_NS,"rPr"),n,t,false)&&(r=true),Sg(e,n)&&(r=true);let b=Oo(U(e,wordView.W_NS,"shd"),t);b&&(n.shading=b,r=true);let g=it(U(e,wordView.W_NS,"keepNext"));g!==void 0&&(n.keepNext=g,r=true);let h=it(U(e,wordView.W_NS,"keepLines"));h!==void 0&&(n.keepLines=h,r=true);let y=it(U(e,wordView.W_NS,"widowControl"));y!==void 0&&(n.widowControl=y,r=true);let k=it(U(e,wordView.W_NS,"snapToGrid"));k!==void 0&&(n.snapToGrid=k,r=true);let C=it(U(e,wordView.W_NS,"pageBreakBefore"));C!==void 0&&(n.pageBreakBefore=C,r=true),U(e,wordView.W_NS,"sectPr")&&(n.hasSectionBreak=true,r=true);}return r?n:void 0}function vg(e){if(!e)return;let t=[];for(let n of ht(e,wordView.W_NS,"tab")){let r=n.getAttributeNS(wordView.W_NS,"val"),o=r==="left"||r==="center"||r==="right"||r==="decimal"||r==="bar"?r:void 0,i=Me(n,"pos");if(!o||i===void 0)continue;let s=n.getAttributeNS(wordView.W_NS,"leader"),a=s==="none"||s==="dot"||s==="hyphen"||s==="underscore"||s==="heavy"||s==="middleDot"?s:void 0;t.push(v({alignment:o,position:i},a?{leader:a}:{}));}return t.length>0?t:void 0}function jd(e,t){let n={};return Ud(e,n,t)?n:void 0}function Ud(e,t,n,r=true){if(!e)return false;let o=false,i=Xd(e,n);i&&(t.fontFamily=i,o=true);let s=U(e,wordView.W_NS,"sz"),a=s?Me(s,"val"):void 0;a!==void 0&&(t.fontSize=a/2,o=true);let l=it(U(e,wordView.W_NS,"b"));if(l!==void 0&&(t.bold=l,o=true),r){let p=Yd(U(e,wordView.W_NS,"color"),n);p&&(t.color=p,o=true);}let c=qd(e);c!==void 0&&(t.characterSpacing=c,o=true);let u=_d(U(e,wordView.W_NS,"highlight"));u&&(t.highlight=u,o=true);let f=Oo(U(e,wordView.W_NS,"shd"),n);return f&&(t.shading=f,o=true),o}function Sg(e,t){let n=U(e,wordView.W_NS,"pBdr");if(!n)return false;let r={};for(let o of ["top","right","bottom","left","between","bar"]){let i=kg(U(n,wordView.W_NS,o));i&&(r[o]=i);}return Object.keys(r).length===0?false:(t.borders=r,r.bottom&&(t.borderBottom=r.bottom),true)}function Bt(e,t){var r,o,i,s,a,l;if(!e&&!t)return;let n=v(v({},e!=null?e:{}),t!=null?t:{});return (e!=null&&e.indent||t!=null&&t.indent)&&(n.indent=v(v({},(r=e==null?void 0:e.indent)!=null?r:{}),(o=t==null?void 0:t.indent)!=null?o:{})),(e!=null&&e.spacing||t!=null&&t.spacing)&&(n.spacing=v(v({},(i=e==null?void 0:e.spacing)!=null?i:{}),(s=t==null?void 0:t.spacing)!=null?s:{})),(e&&"borders"in e&&e.borders||t&&"borders"in t&&t.borders)&&(n.borders=v(v({},(a=e==null?void 0:e.borders)!=null?a:{}),(l=t==null?void 0:t.borders)!=null?l:{}),n.borders.bottom&&(n.borderBottom=n.borders.bottom)),t&&"tabStops"in t&&t.tabStops!==void 0?n.tabStops=t.tabStops.map(c=>v({},c)):e&&"tabStops"in e&&e.tabStops!==void 0&&(n.tabStops=e.tabStops.map(c=>v({},c))),n}function Me(e,t){let n=e.getAttributeNS(wordView.W_NS,t);if(n===null)return;let r=Number(n);return Number.isFinite(r)?r:void 0}function kg(e){var s;if(!e)return;let t=(s=e.getAttributeNS(wordView.W_NS,"val"))!=null?s:void 0;if(t==="none"||t==="nil")return;let n={val:t},r=e.getAttributeNS(wordView.W_NS,"color"),o=Me(e,"sz"),i=Me(e,"space");return r&&(n.color=r),o!==void 0&&(n.size=o),i!==void 0&&(n.space=i),n}function Zt(e,t){let n=U(e,wordView.W_NS,"rPr");if(!n)return;let r=Kd(n,t);return r&&Object.keys(r).length>0?r:void 0}function Kd(e,t){let n={},r=Xd(e,t);r&&(n.fontFamily=r);let o=it(U(e,wordView.W_NS,"b"));o!==void 0&&(n.bold=o);let i=it(U(e,wordView.W_NS,"i"));i!==void 0&&(n.italic=i);let s=U(e,wordView.W_NS,"u");if(s){let y=s.getAttributeNS(wordView.W_NS,"val");n.underline=y!=="none"&&y!=="0"&&y!=="false";}let a=it(U(e,wordView.W_NS,"strike"));a!==void 0&&(n.strike=a);let l=it(U(e,wordView.W_NS,"dstrike"));l!==void 0&&(n.doubleStrike=l);let c=it(U(e,wordView.W_NS,"caps"));c!==void 0&&(n.caps=c);let u=it(U(e,wordView.W_NS,"smallCaps"));u!==void 0&&(n.smallCaps=u);let f=U(e,wordView.W_NS,"sz");if(f){let y=f.getAttributeNS(wordView.W_NS,"val"),k=y!==null?Number(y):NaN;Number.isFinite(k)&&(n.fontSize=k/2);}let p=U(e,wordView.W_NS,"color");if(p){let y=Yd(p,t);y&&(n.color=y);}let w=qd(e);w!==void 0&&(n.characterSpacing=w);let b=Eg(U(e,wordView.W_NS,"vertAlign"));b&&(n.verticalAlign=b);let g=_d(U(e,wordView.W_NS,"highlight"));g&&(n.highlight=g);let h=Oo(U(e,wordView.W_NS,"shd"),t);return h&&(n.shading=h),Object.keys(n).length>0?n:void 0}function _d(e){var n;let t=(n=e==null?void 0:e.getAttributeNS(wordView.W_NS,"val"))!=null?n:void 0;return t&&t!=="none"?t:void 0}function qd(e){let t=U(e,wordView.W_NS,"spacing");return t?Me(t,"val"):void 0}function Eg(e){let t=e==null?void 0:e.getAttributeNS(wordView.W_NS,"val");return t==="baseline"||t==="superscript"||t==="subscript"?t:void 0}function Xd(e,t){let n=U(e,wordView.W_NS,"rFonts");if(!n)return;let r=n.getAttributeNS(wordView.W_NS,"eastAsia")||Bo(t,n.getAttributeNS(wordView.W_NS,"eastAsiaTheme")),o=n.getAttributeNS(wordView.W_NS,"ascii")||n.getAttributeNS(wordView.W_NS,"hAnsi")||Bo(t,n.getAttributeNS(wordView.W_NS,"asciiTheme"))||Bo(t,n.getAttributeNS(wordView.W_NS,"hAnsiTheme"));return o&&r&&Cg(o)?o===r?o:`${o}, ${r}`:r||o||n.getAttributeNS(wordView.W_NS,"cs")||Bo(t,n.getAttributeNS(wordView.W_NS,"csTheme"))||void 0}function Cg(e){let t=e.trim().toLowerCase();return t==="calibri"||t==="aptos"||t==="arial"}function Yd(e,t){if(!e)return;let n=Da(e.getAttributeNS(wordView.W_NS,"val")),r=n!=null?n:Zd(t,e.getAttributeNS(wordView.W_NS,"themeColor"));if(r)return Jd(r,e.getAttributeNS(wordView.W_NS,"themeTint"),e.getAttributeNS(wordView.W_NS,"themeShade"))}function Zd(e,t){if(!(!e||!t))return e.colors.get(t)}function Bo(e,t){if(!(!e||!t))return e.fonts.get(Ig(t))}function Ig(e){var n;return (n={"+mj-lt":"majorHAnsi","+mn-lt":"minorHAnsi","+mj-ea":"majorEastAsia","+mn-ea":"minorEastAsia","+mj-cs":"majorBidi","+mn-cs":"minorBidi",majorAscii:"majorHAnsi",minorAscii:"minorHAnsi",majorLatin:"majorHAnsi",minorLatin:"minorHAnsi",majorCs:"majorBidi",minorCs:"minorBidi"}[e])!=null?n:e}function Da(e){if(!(!e||e==="auto")){if(/^[0-9a-f]{6}$/i.test(e))return e.toUpperCase();if(/^[0-9a-f]{8}$/i.test(e))return e.slice(2).toUpperCase()}}function Jd(e,t,n){let r=Sd(t);if(r!==void 0)return Ng(e,r/255);let o=Sd(n);return o!==void 0?Tg(e,o/255):e}function Sd(e){if(!e||!/^[0-9a-f]{2}$/i.test(e))return;let t=Number.parseInt(e,16);return Number.isFinite(t)?t:void 0}function Ng(e,t){return Qd(e,n=>n+(255-n)*t)}function Tg(e,t){return Qd(e,n=>n*t)}function Qd(e,t){return [0,2,4].map(r=>Number.parseInt(e.slice(r,r+2),16)).map(r=>Math.max(0,Math.min(255,Math.round(t(r))))).map(r=>r.toString(16).toUpperCase().padStart(2,"0")).join("")}function it(e){if(!e)return;let t=e.getAttributeNS(wordView.W_NS,"val");return ec(t)}function ec(e){return e!=="0"&&e!=="false"&&e!=="off"}function tc(e){if(e.namespaceURI!==wordView.W_NS||e.localName!=="sdt")return false;let t=U(e,wordView.W_NS,"sdtPr");return t?it(U(t,wordView.W_NS,"showingPlcHdr"))===true:false}function U(e,t,n){for(let r=0;r<e.childNodes.length;r++){let o=e.childNodes[r];if((o==null?void 0:o.nodeType)===1&&o.namespaceURI===t&&o.localName===n)return o}return null}function Pg(e,t,n){for(let r=e.childNodes.length-1;r>=0;r--){let o=e.childNodes[r];if((o==null?void 0:o.nodeType)===1&&o.namespaceURI===t&&o.localName===n)return o}return null}function ht(e,t,n){let r=[];for(let o=0;o<e.childNodes.length;o++){let i=e.childNodes[o];(i==null?void 0:i.nodeType)===1&&i.namespaceURI===t&&i.localName===n&&r.push(i);}return r}function Do(e,t,n){let r=e;for(let o of n)if(r=r?U(r,t,o):null,!r)return null;return r}function Mg(e,t,n,r,o,i){var l,c;let s=e.commentIdx.get(t);if(!(s!=null&&s.comment))return null;let a=Fa(s.comment,"t");return {kind:"comment",id:`comment:${t}`,commentId:t,paraId:n,from:r,to:o,text:i.slice(r,o),rangeKind:r===0&&o===i.length?"paragraph":"text",author:(l=s.comment.getAttributeNS(wordView.W_NS,"author"))!=null?l:"",date:(c=s.comment.getAttributeNS(wordView.W_NS,"date"))!=null?c:"",body:a}}function Rg(e,t){var r,o;let n=[];for(let[i,s]of e.commentIdx)t.has(i)||!s.comment||n.push({id:i,author:(r=s.comment.getAttributeNS(wordView.W_NS,"author"))!=null?r:"",date:(o=s.comment.getAttributeNS(wordView.W_NS,"date"))!=null?o:"",text:Fa(s.comment,"t"),rangeKind:"complex"});return n}function kd(e,t){if(e.namespaceURI!==wordView.W_NS||e.localName!==t)return null;let n=e.getAttributeNS(wordView.W_NS,"id");if(n===null)return null;let r=Number(n);return Number.isFinite(r)?r:null}function nc(e,t=false){let n="";function r(o){var s;if(o.nodeType!==1)return;let i=o;if(i.namespaceURI===wordView.W_NS&&!(t&&tc(i))){if(i.localName==="t"){n+=(s=i.textContent)!=null?s:"";return}if(i.localName==="tab"||i.localName==="ptab"){n+=" ";return}if(i.localName==="br"){let a=i.getAttributeNS(wordView.W_NS,"type");(a===null||a===""||a==="textWrapping")&&(n+=`
3
+ `);return}if(i.localName!=="delText"&&i.localName!=="commentReference")for(let a=0;a<i.childNodes.length;a++){let l=i.childNodes[a];l&&r(l);}}}return r(e),n}function Ag(e){for(let t=0;t<e.childNodes.length;t++){let n=e.childNodes[t];if(!n||n.nodeType!==1)continue;let r=n;if(r.namespaceURI===wordView.W_NS&&(r.localName==="fldChar"||r.localName==="instrText"))return true}return false}function Lg(e){var t;if(e.localName==="t")return (t=e.textContent)!=null?t:"";if(e.localName==="tab"||e.localName==="ptab")return " ";if(e.localName==="br"){let n=e.getAttributeNS(wordView.W_NS,"type");return n===null||n===""||n==="textWrapping"?`
4
+ `:""}return e.localName==="delText"||e.localName==="commentReference"||e.localName==="instrText"?"":nc(e)}function Ed(e){var r;let n=(r=e.replace(/\\\*\s+MERGEFORMAT/gi,"").replace(/\\\*\s+CHARFORMAT/gi,"").trim().toUpperCase().split(/\s+/)[0])!=null?r:"";return n==="PAGE"?"pageNumber":n==="NUMPAGES"?"totalPages":n==="SECTIONPAGES"?"sectionPages":null}function Fa(e,t){var o,i;let n=e.getElementsByTagNameNS(wordView.W_NS,t),r="";for(let s=0;s<n.length;s++)r+=(i=(o=n[s])==null?void 0:o.textContent)!=null?i:"";return r}function Wg(e){return e.namespaceURI===wordView.W_NS&&(e.localName==="drawing"||e.localName==="pict")}function Bg(e){for(let t=0;t<e.childNodes.length;t++){let n=e.childNodes[t];if(!n||n.nodeType!==1)continue;let r=n;if(r.namespaceURI===wordView.W_NS&&r.localName==="br"&&r.getAttributeNS(wordView.W_NS,"type")==="page")return true}return false}function Dg(e){let t=[];for(let n=0;n<e.childNodes.length;n++){let r=e.childNodes[n];(r==null?void 0:r.nodeType)===1&&r.namespaceURI===wordView.W_NS&&(r.localName==="drawing"||r.localName==="pict")&&t.push(r);}return t}function Fg(e,t,n){var u,f;if(e.namespaceURI!==wordView.W_NS||e.localName!=="pict")return null;let r=e.getElementsByTagNameNS(md,"line")[0];if(!r)return null;let o=Hg(r.getAttribute("style")),i=r.getElementsByTagNameNS(md,"stroke")[0],s=Pa(o.get("width")),a=Pa(o.get("height")),l=Og((u=i==null?void 0:i.getAttribute("color"))!=null?u:r.getAttribute("strokecolor")),c=Pa((f=i==null?void 0:i.getAttribute("weight"))!=null?f:r.getAttribute("strokeweight"));return v(v(v(v({kind:"drawing",drawingId:`${t}:vml-line:${n+1}`,drawingKind:"shape",isLineOrConnector:true,hasBorder:true},s!==void 0?{width:s}:{}),a!==void 0?{height:a}:{}),l?{strokeColor:l}:{}),c!==void 0?{strokeWidth:c}:{})}function Hg(e){var n;let t=new Map;for(let r of (n=e==null?void 0:e.split(";"))!=null?n:[]){let o=r.indexOf(":");if(o<0)continue;let i=r.slice(0,o).trim().toLowerCase(),s=r.slice(o+1).trim();i&&s&&t.set(i,s);}return t}function Pa(e){var o,i;if(!e)return;let t=/^(-?(?:\d+\.?\d*|\.\d+))(pt|px|in|cm|mm)?$/i.exec(e.trim());if(!t)return;let n=Number(t[1]);if(!Number.isFinite(n))return;let r=(i=(o=t[2])==null?void 0:o.toLowerCase())!=null?i:"px";return r==="pt"?n*(96/72):r==="in"?n*96:r==="cm"?n*(96/2.54):r==="mm"?n*(96/25.4):n}function Og(e){if(!e)return;let t=e.trim();if(/^#[0-9a-f]{6}$/i.test(t))return t.toUpperCase();if(/^[0-9a-f]{6}$/i.test(t))return `#${t.toUpperCase()}`}function $g(e){for(let t=0;t<e.childNodes.length;t++){let n=e.childNodes[t];if(!n||n.nodeType!==1)continue;let r=n;if(r.namespaceURI!==wordView.W_NS)return false;if(!(r.localName==="rPr"||r.localName==="commentReference"||r.localName==="bookmarkStart"||r.localName==="bookmarkEnd"||r.localName==="commentRangeStart"||r.localName==="commentRangeEnd"))return false}return true}function zg(e){let t=e.blocks.filter(o=>o.type==="paragraph"),n=ic(e),r=Gg(e);return {topLevelBlocks:e.blocks.length,topLevelParagraphs:t.length,tableBlocks:e.tables.length,tableParagraphs:n.length,allParagraphs:r.length,topLevelImages:Ha(t),tableImages:Ha(n),allImages:Ha(r),topLevelDrawings:Oa(t),tableDrawings:Oa(n),allDrawings:Oa(r),pageBreaks:Kg(r)}}function ME(e,t){var i;let n=zg(e),r=t?Vg(t):[],o=Ug(r);return {editor:n,native:{blocks:(i=t==null?void 0:t.blocks.length)!=null?i:0,paragraphs:r.length,images:o,drawings:rc(r),pageBreaks:oc(r)},missing:{paragraphs:n.allParagraphs-r.length,images:n.allImages-o,drawings:n.allDrawings-rc(r),pageBreaks:n.pageBreaks-oc(r)}}}function RE(e){return [...kr(e.blocks),...e.headers.flatMap(t=>kr(t.blocks)),...e.footers.flatMap(t=>kr(t.blocks))]}function Vg(e){return kr(e.blocks)}function kr(e){return e.flatMap(t=>t.kind==="paragraph"?[t]:t.rows.flatMap(n=>n.cells.flatMap(r=>r.vMerge==="continue"?[]:kr(r.blocks))))}function Gg(e){return [...e.blocks.filter(n=>n.type==="paragraph"),...ic(e)]}function ic(e){return jg(e.tables)}function jg(e){return e.flatMap(t=>t.rows.flatMap(n=>n.cells.flatMap(r=>r.vMerge==="continue"?[]:r.paragraphs)))}function Ha(e){return e.reduce((t,n)=>t+n.segments.filter(r=>r.kind==="image").length,0)}function Oa(e){return e.reduce((t,n)=>t+n.segments.filter(r=>r.kind==="drawing").length,0)}function Ug(e){return e.reduce((t,n)=>t+n.content.filter(r=>r.kind==="image").length,0)}function rc(e){return e.reduce((t,n)=>t+n.content.filter(r=>r.kind==="drawing").length,0)}function Kg(e){return e.reduce((t,n)=>t+n.segments.filter(r=>r.kind==="placeholder"&&r.placeholderKind==="pageBreak").length,0)}function oc(e){return e.reduce((t,n)=>t+n.content.filter(r=>r.kind==="pageBreak").length,0)}function Cr(e){var o,i,s,a,l,c,u,f;let t={};if(!e)return Er(t);qg(e,t),e.alignment&&(t["text-align"]=Xg(e.alignment)),((o=e.indent)==null?void 0:o.left)!==void 0&&_g(e)&&(t["margin-left"]=yt(e.indent.left)),((i=e.indent)==null?void 0:i.right)!==void 0&&(t["margin-right"]=yt(e.indent.right)),((s=e.indent)==null?void 0:s.firstLine)!==void 0&&(t["text-indent"]=yt(e.indent.firstLine)),((a=e.spacing)==null?void 0:a.before)!==void 0&&(t["margin-top"]=yt(e.spacing.before)),((l=e.spacing)==null?void 0:l.after)!==void 0&&(t["margin-bottom"]=yt(e.spacing.after));let n=nb((c=e.spacing)==null?void 0:c.line,(u=e.spacing)==null?void 0:u.lineRule,e.snapToGrid);n&&(t["line-height"]=n),e.fontSize!==void 0&&(t["font-size"]=`${e.fontSize}pt`),e.fontFamily!==void 0&&(t["font-family"]=lc(e.fontFamily)),e.characterSpacing!==void 0&&(t["letter-spacing"]=yt(e.characterSpacing)),e.bold!==void 0&&(t["font-weight"]=e.bold?"700":"400");let r=(f=ac(e.shading))!=null?f:sc(e.highlight);return r&&(t["background-color"]=r),Qg(e,t),Er(t)}function _g(e){var t;return !(e.numbering&&((t=e.indent)==null?void 0:t.left)===0&&e.indent.firstLine===void 0)}function qg(e,t){e.outlineLevel!==void 0&&(e.outlineLevel===0?(t["font-size"]="16pt",t["font-weight"]="700",t["line-height"]="1.28"):e.outlineLevel===1?(t["font-size"]="14pt",t["font-weight"]="700",t["line-height"]="1.3"):e.outlineLevel===2&&(t["font-size"]="12pt",t["font-weight"]="700",t["line-height"]="1.35"));}function Un(e){var o;let t={};if(!e)return Er(t);e.bold!==void 0&&(t["font-weight"]=e.bold?"700":"400"),e.italic!==void 0&&(t["font-style"]=e.italic?"italic":"normal"),Zg(e,t),e.caps&&(t["text-transform"]="uppercase"),e.smallCaps&&(t["font-variant-caps"]="small-caps"),e.fontSize!==void 0&&(t["font-size"]=`${e.fontSize}pt`),e.fontFamily!==void 0&&(t["font-family"]=lc(e.fontFamily)),e.characterSpacing!==void 0&&(t["letter-spacing"]=yt(e.characterSpacing)),e.verticalAlign&&(t["vertical-align"]=Jg(e.verticalAlign),e.verticalAlign!=="baseline"&&e.fontSize===void 0&&(t["font-size"]="smaller"));let n=Kn(e.color);n&&(t.color=n);let r=(o=sc(e.highlight))!=null?o:ac(e.shading);return r&&(t["background-color"]=r),Er(t)}function Vo(e){var r;let t={};e.width!==void 0&&e.width>0&&(t.width=yt(e.width)),e.margin&&(e.margin.top!==void 0&&(t["padding-top"]=yt(e.margin.top)),e.margin.right!==void 0&&(t["padding-right"]=yt(e.margin.right)),e.margin.bottom!==void 0&&(t["padding-bottom"]=yt(e.margin.bottom)),e.margin.left!==void 0&&(t["padding-left"]=yt(e.margin.left)));let n=Kn((r=e.shading)==null?void 0:r.fill);return n&&(t["background-color"]=n),e.verticalAlignment&&(t["vertical-align"]=Yg(e.verticalAlignment)),e.noWrap&&(t["white-space"]="nowrap"),e.borders&&(zo(t,"top",e.borders.top),zo(t,"right",e.borders.right),zo(t,"bottom",e.borders.bottom),zo(t,"left",e.borders.left)),Er(t)}function Kn(e){return !e||e==="auto"?null:/^[0-9a-f]{6}$/i.test(e)?`#${e}`:null}function ac(e){return !e||e.val==="nil"||e.val==="clear"&&!e.fill?null:Kn(e.fill)}function sc(e){var n;return !e||e==="none"?null:(n={black:"#000000",blue:"#0000ff",cyan:"#00ffff",green:"#00ff00",magenta:"#ff00ff",red:"#ff0000",yellow:"#ffff00",white:"#ffffff",darkBlue:"#000080",darkCyan:"#008080",darkGreen:"#008000",darkMagenta:"#800080",darkRed:"#800000",darkYellow:"#808000",darkGray:"#808080",lightGray:"#c0c0c0"}[e])!=null?n:Kn(e)}function Er(e){return {declarations:e,cssText:Object.entries(e).map(([t,n])=>`${t}: ${n}`).join("; ")}}function Xg(e){return e==="both"||e==="distribute"?"justify":e}function Yg(e){return e==="center"||e==="both"?"middle":e}function Zg(e,t){let n=[];if(e.underline&&n.push("underline"),(e.strike||e.doubleStrike)&&n.push("line-through"),n.length>0){t["text-decoration-line"]=n.join(" "),e.doubleStrike&&(t["text-decoration-style"]="double");return}(e.underline===false||e.strike===false||e.doubleStrike===false)&&(t["text-decoration-line"]="none");}function Jg(e){return e==="superscript"?"super":e==="subscript"?"sub":"baseline"}function Qg(e,t){var r,o,i;let n=(r=e.borders)!=null?r:e.borderBottom?{bottom:e.borderBottom}:void 0;n&&($o(t,"top",n.top),$o(t,"right",n.right),$o(t,"bottom",(o=n.bottom)!=null?o:n.between),$o(t,"left",(i=n.left)!=null?i:n.bar));}function $o(e,t,n){let r=eb(n);r&&(e[`border-${t}`]=r,e[`padding-${t}`]=(n==null?void 0:n.space)!==void 0?`${n.space}pt`:"4pt");}function eb(e){var o;if(!e||e.val==="none"||e.val==="nil")return null;let t=(o=Kn(e.color))!=null?o:"#000000",n=e.size!==void 0?Math.max(.75,e.size/8):.75,r=e.val==="double"?"double":"solid";return `${n}pt ${r} ${t}`}function zo(e,t,n){if(!n)return;let r=tb(n);e[`border-${t}`]=r!=null?r:"0";}function tb(e){var o;if(e.val==="none"||e.val==="nil")return null;let t=(o=Kn(e.color))!=null?o:"#000000",n=e.size!==void 0?Math.max(.5,e.size/8):.75,r=e.val==="double"?"double":"solid";return `${n}pt ${r} ${t}`}function nb(e,t,n){return e===void 0?null:t==="exact"||t==="atLeast"?yt(e):n!==true?String(e/240):`calc(var(--coco-word-doc-grid-line-height, 1em) * ${e/240})`}function yt(e){return `${e/20}pt`}function lc(e){let t=e.split(",").map(o=>o.trim()).filter(o=>o.length>0),n=rb(t);return [...[...new Set([...t,...n.families])].map(ob),n.generic].join(", ")}function rb(e){let t=e.join(" ");return /(?:楷体|kaiti|stkaiti)/i.test(t)?{families:["Kaiti SC","STKaiti","KaiTi","KaiTi_GB2312","DFKai-SB"],generic:"serif"}:/(?:仿宋|fangsong|stfangsong)/i.test(t)?{families:["STFangsong","FangSong","FangSong_GB2312","Noto Serif CJK SC"],generic:"serif"}:/(?:黑体|heiti|simhei|微软雅黑|microsoft yahei|pingfang)/i.test(t)?{families:["STHeiti","Heiti SC","PingFang SC","Microsoft YaHei","Noto Sans CJK SC"],generic:"sans-serif"}:{families:["SimSun","Songti SC","STSong","Noto Serif CJK SC"],generic:"serif"}}function ob(e){return `"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/[\r\n\f]/g," ")}"`}function BE(e,t={}){var l,c;let n=cb((l=t.startBlock)!=null?l:0,0,e.blocks.length),r=Math.max(1,Math.floor((c=t.maxChars)!=null?c:12e3)),o=[],i=19,s=n;for(;s<e.blocks.length;){let u=dc(e.blocks[s]),f=o.length>0?1:0;if(o.length>0&&i+f+u.length>r)break;o.push(u),i+=f+u.length,s+=1;}let a=o.length>0?`<article>
5
+ ${o.join(`
6
+ `)}
7
+ </article>`:"<article></article>";return s<e.blocks.length?{html:a,nextBlock:s}:{html:a}}function dc(e){return e.type==="table"?db(e):ib(e)}function ib(e){let t=ab(e),n=Cr(e.format).cssText,r=[`data-para-id="${jt(e.paraId)}"`,n?`style="${jt(n)}"`:""].filter(Boolean).join(" "),o=sb(e);return `<${t} ${r}>${o||"&nbsp;"}</${t}>`}function ab(e){var n;let t=(n=e.format)==null?void 0:n.outlineLevel;return t===void 0||t<0||t>5?"p":`h${t+1}`}function sb(e){var r,o;let t=(o=(r=e.format)==null?void 0:r.numbering)==null?void 0:o.label,n=t?`${$a(t)} `:"";return e.segments.length===0?n+Go(e.text):n+e.segments.map(lb).join("")}function lb(e){var o,i;if(e.kind==="image")return `<img data-drawing-id="${jt(e.drawingId)}" alt="[\u56FE\u7247]">`;if(e.kind==="drawing"){let s=e.text?Go(e.text):"[\u7ED8\u56FE]";return `<span data-drawing-id="${jt(e.drawingId)}">${s}</span>`}if(e.kind==="placeholder")return e.placeholderKind==="pageBreak"?'<br data-page-break="true">':`<span data-object="${jt(e.placeholderKind)}">[\u5BF9\u8C61]</span>`;if(e.kind==="field"){let s=Go((o=e.cachedText)!=null?o:"");return `<span data-field="${jt(e.fieldKind)}">${s}</span>`}let t=Un(e.format).cssText,n=Go(e.text),r=t?` style="${jt(t)}"`:"";if(e.kind==="revision"){let s=e.revisionKind==="delete"?"del":"ins";return `<${s}${r}>${n}</${s}>`}if(e.hyperlink){let s=(i=e.hyperlink.target)!=null?i:e.hyperlink.anchor;return `<a${s?` href="${jt(s)}"`:""}${r}>${n}</a>`}return t?`<span${r}>${n}</span>`:n}function db(e){let t=e.rows.map(n=>`<tr>${n.cells.map(o=>{let i=Vo(o).cssText,s=[o.gridSpan>1?`colspan="${o.gridSpan}"`:"",o.rowSpan!==void 0&&o.rowSpan>1?`rowspan="${o.rowSpan}"`:"",i?`style="${jt(i)}"`:""].filter(Boolean).join(" "),a=o.blocks.map(dc).join(`
8
+ `);return `<td${s?` ${s}`:""}>${a||"&nbsp;"}</td>`}).join("")}</tr>`).join(`
9
+ `);return `<table data-table-id="${jt(e.tableId)}">
10
+ ${t}
11
+ </table>`}function Go(e){return $a(e).replace(/\t/g,"&#9;").replace(/\r\n|\r|\n/g,"<br>")}function $a(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function jt(e){return $a(e).replace(/"/g,"&quot;")}function cb(e,t,n){return Math.min(n,Math.max(t,Math.floor(e)))}function Va(e){return $(v(v({kind:"word"},e.defaults?{defaults:e.defaults}:{}),e.pageLayout?{pageLayout:e.pageLayout}:{}),{sections:e.sections,headers:e.headers.map(cc),footers:e.footers.map(cc),blocks:e.blocks.map(t=>ja(t))})}function _(e,t){var n,r;return (r=(n=be(e,t))==null?void 0:n.paragraph)!=null?r:null}function Ga(e,t){var r,o;let n=be(e,t);return (o=(r=n==null?void 0:n.previous)==null?void 0:r.paraId)!=null?o:null}function be(e,t){var n,r;return (r=(n=za(e.blocks,t))!=null?n:e.headers.reduce((o,i)=>o!=null?o:za(i.blocks,t),null))!=null?r:e.footers.reduce((o,i)=>o!=null?o:za(i.blocks,t),null)}function Qt(e,t){var n,r;return (r=(n=Uo(e.blocks,t))!=null?n:e.headers.reduce((o,i)=>o!=null?o:Uo(i.blocks,t),null))!=null?r:e.footers.reduce((o,i)=>o!=null?o:Uo(i.blocks,t),null)}function Oe(e,t){var n,r;return (r=(n=jo(e.blocks,t))!=null?n:e.headers.reduce((o,i)=>o!=null?o:jo(i.blocks,t),null))!=null?r:e.footers.reduce((o,i)=>o!=null?o:jo(i.blocks,t),null)}function jo(e,t){for(let n=0;n<e.length;n+=1){let r=e[n];if((r==null?void 0:r.kind)==="table"){if(r.tableId===t)return {table:r,container:e,tableIndex:n};for(let o of r.rows)for(let i of o.cells){let s=jo(i.blocks,t);if(s)return s}}}return null}function Uo(e,t){for(let n=0;n<e.length;n+=1){let r=e[n];if((r==null?void 0:r.kind)==="table")for(let o=0;o<r.rows.length;o+=1){let i=r.rows[o],s=0;for(let a=0;a<i.cells.length;a+=1){let l=i.cells[a],c=Uo(l.blocks,t);if(c)return c;if(l.blocks.some(u=>u.kind==="paragraph"&&u.paraId===t))return {table:r,container:e,tableIndex:n,row:i,rowIndex:o,cell:l,cellIndex:a,columnIndex:s};s+=Math.max(1,l.gridSpan);}}}return null}function za(e,t){for(let n=0;n<e.length;n+=1){let r=e[n];if((r==null?void 0:r.kind)==="paragraph"&&r.paraId===t){let o=e[n-1];return {paragraph:r,previous:(o==null?void 0:o.kind)==="paragraph"?o:null,container:e,index:n,insertAfter(i){e.splice(n+1,0,i);},remove(){e.splice(n,1);}}}if((r==null?void 0:r.kind)==="table"){let o=bb(r,t);if(o)return o}}return null}function _e(e){return [...Ir(e.blocks),...e.headers.flatMap(t=>Ir(t.blocks)),...e.footers.flatMap(t=>Ir(t.blocks))]}function Ir(e){return e.flatMap(t=>t.kind==="paragraph"?[t]:t.rows.flatMap(n=>n.cells.flatMap(r=>Ir(r.blocks))))}function Te(e){return e.content.map(t=>{var n;return t.kind==="text"?t.text:t.kind==="field"?(n=t.cachedText)!=null?n:"\uFFFC":t.kind==="drawing"&&t.text?t.text:"\uFFFC"}).join("")}function Pn(e){let t=new Set(_e(e).map(r=>r.paraId).filter(Boolean)),n="";do n=Math.floor(Math.random()*4294967295).toString(16).toUpperCase().padStart(8,"0");while(!n||t.has(n));return n}function ja(e){return e.type==="table"?$(v(v($(v({kind:"table",tableId:e.tableId},e.tableStyleId?{tableStyleId:e.tableStyleId}:{}),{columnWidths:e.columnWidths}),e.layout?{layout:e.layout}:{}),e.borders?{borders:e.borders}:{}),{rows:e.rows.map(t=>$(v(v(v({},t.height?{height:t.height}:{}),t.isHeader?{isHeader:true}:{}),t.cantSplit?{cantSplit:true}:{}),{cells:t.cells.map(n=>ub(n))}))}):uc(e)}function cc(e){return {kind:e.kind,partName:e.partName,blocks:e.blocks.map(t=>ja(t))}}function ub(e){var o;let n=((o=e.blocks)!=null?o:e.paragraphs).map(i=>ja(i)),r={gridSpan:e.gridSpan,blocks:n,paragraphs:Ir(n)};return e.rowSpan!==void 0&&(r.rowSpan=e.rowSpan),e.vMerge!==void 0&&(r.vMerge=e.vMerge),e.width!==void 0&&(r.width=e.width),e.margin!==void 0&&(r.margin=e.margin),e.borders!==void 0&&(r.borders=e.borders),e.shading!==void 0&&(r.shading=e.shading),e.verticalAlignment!==void 0&&(r.verticalAlignment=e.verticalAlignment),e.noWrap!==void 0&&(r.noWrap=e.noWrap),r}function uc(e){var n,r;let t=e.spans.filter(o=>o.kind==="comment");return {kind:"paragraph",paraId:e.paraId,story:e.story,styleId:(n=e.styleId)!=null?n:null,format:(r=e.format)!=null?r:null,content:e.segments.flatMap(o=>o.kind==="text"?mb(o,t):o.kind==="revision"?fb(o):o.kind==="field"?pb(o):o.kind==="image"?hb(o):o.kind==="drawing"?gb(o):o.kind==="placeholder"&&o.placeholderKind==="pageBreak"?[{kind:"pageBreak"}]:[])}}function pb(e){var t;return [$(v({kind:"field",fieldKind:e.fieldKind,instruction:e.instruction},e.cachedText!==void 0?{cachedText:e.cachedText}:{}),{format:(t=e.format)!=null?t:null})]}function fb(e){var t;return e.text.length===0?[]:[{kind:"text",text:e.text,format:(t=e.format)!=null?t:null,marks:[{kind:"revision",id:`revision:${e.revisionId}`,revisionId:e.revisionId,revisionKind:e.revisionKind,author:e.author,date:e.date}]}]}function mb(e,t){var o,i,s;if(e.text.length===0)return [];let n=[],r=e.from;for(let a of t){let l=Math.max(e.from,a.from),c=Math.min(e.to,a.to);c<=l||(l>r&&n.push(v({kind:"text",text:e.text.slice(r-e.from,l-e.from),format:(o=e.format)!=null?o:null},e.hyperlink?{hyperlink:v({},e.hyperlink)}:{})),n.push($(v({kind:"text",text:e.text.slice(l-e.from,c-e.from),format:(i=e.format)!=null?i:null},e.hyperlink?{hyperlink:v({},e.hyperlink)}:{}),{marks:[{kind:"comment",id:a.id,commentId:a.commentId,author:a.author,date:a.date,body:a.body}]})),r=c);}return r<e.to&&n.push(v({kind:"text",text:e.text.slice(r-e.from),format:(s=e.format)!=null?s:null},e.hyperlink?{hyperlink:v({},e.hyperlink)}:{})),n}function hb(e){return [v(v(v(v(v({kind:"image",drawingId:e.drawingId,src:e.src},e.width!==void 0?{width:e.width}:{}),e.height!==void 0?{height:e.height}:{}),e.anchoringMode!==void 0?{anchoringMode:e.anchoringMode}:{}),e.wrap!==void 0?{wrap:e.wrap}:{}),e.position!==void 0?{position:e.position}:{})]}function gb(e){let t={kind:"drawing",drawingId:e.drawingId,drawingKind:e.drawingKind};return e.text!==void 0&&(t.text=e.text),e.width!==void 0&&(t.width=e.width),e.height!==void 0&&(t.height=e.height),e.anchoringMode!==void 0&&(t.anchoringMode=e.anchoringMode),e.wrap!==void 0&&(t.wrap=e.wrap),e.position!==void 0&&(t.position=e.position),e.hasBorder!==void 0&&(t.hasBorder=e.hasBorder),e.hasFill!==void 0&&(t.hasFill=e.hasFill),e.isLineOrConnector!==void 0&&(t.isLineOrConnector=e.isLineOrConnector),e.strokeColor!==void 0&&(t.strokeColor=e.strokeColor),e.strokeWidth!==void 0&&(t.strokeWidth=e.strokeWidth),e.innerTextAlign!==void 0&&(t.innerTextAlign=e.innerTextAlign),e.paragraphs&&e.paragraphs.length>0&&(t.paragraphs=e.paragraphs.map(n=>uc(n))),[t]}function bb(e,t){var n;for(let r of e.rows)for(let o of r.cells){let i=o.paragraphs.findIndex(a=>a.paraId===t),s=o.blocks.findIndex(a=>a.kind==="paragraph"&&a.paraId===t);if(i>=0&&s>=0)return {paragraph:o.paragraphs[i],previous:(n=o.paragraphs[i-1])!=null?n:null,container:o.blocks,index:s,insertAfter(a){o.paragraphs.splice(i+1,0,a),o.blocks.splice(s+1,0,a);},remove(){o.paragraphs.splice(i,1),o.blocks.splice(s,1);}}}return null}function Ka(e){let t=Sb(e),n=e.cells.reduce((o,i)=>o+pc(i),0),r=e.cells.reduce((o,i)=>o+fc(i),0);return e.isHeader?{kind:"repeat-header",risks:t,textLength:r,paragraphCount:n}:t.includes("cant-split")?{kind:"keep-together",risks:t,textLength:r,paragraphCount:n}:t.length>0?{kind:"unsplittable",risks:t,textLength:r,paragraphCount:n}:r===0?{kind:"keep-together",risks:["empty-row"],textLength:r,paragraphCount:n}:n>e.cells.length?{kind:"block-fragmentable",risks:t,textLength:r,paragraphCount:n}:{kind:"text-fragmentable",risks:t,textLength:r,paragraphCount:n}}function OE(e){let t={tables:0,rows:0,repeatHeaderRows:0,keepTogetherRows:0,blockFragmentableRows:0,textFragmentableRows:0,unsplittableRows:0,risks:{"cant-split":0,"row-span":0,"vertical-merge":0,"nested-table":0,media:0,field:0,"page-break":0,comment:0,revision:0,"empty-row":0}};Ko(e.blocks,t);for(let n of e.headers)Ko(n.blocks,t);for(let n of e.footers)Ko(n.blocks,t);return t}function $E(e,t){if(Ka(e).kind!=="block-fragmentable"||t.cellBlockCounts.length!==e.cells.length)return null;let r=[],o=[],i=false,s=false;for(let a=0;a<e.cells.length;a+=1){let l=e.cells[a],c=yb(l,t.cellBlockCounts[a]);if(!c)return null;r.push(c.head),o.push(c.tail),i||(i=c.head.blocks.length>0),s||(s=c.tail.blocks.length>0);}return !i||!s?null:{head:$(v({},e),{height:void 0,cells:r}),tail:$(v({},e),{height:void 0,cells:o})}}function zE(e,t){if(Ka(e).kind!=="text-fragmentable"||t.cellTextOffsets.length!==e.cells.length)return null;let r=[],o=[];for(let i=0;i<e.cells.length;i+=1){let s=wb(e.cells[i],t.cellTextOffsets[i]);if(!s)return null;r.push(s.head),o.push(s.tail);}return {head:$(v({},e),{height:void 0,cells:r}),tail:$(v({},e),{height:void 0,cells:o})}}function wb(e,t){if(e.blocks.length!==1)return null;let n=e.blocks[0];if(!n||n.kind!=="paragraph")return null;let r=xb(n,t);return r?{head:$(v({},e),{blocks:[r.head],paragraphs:[r.head]}),tail:$(v({},e),{blocks:[r.tail],paragraphs:[r.tail]})}:null}function xb(e,t){let n=e.content.reduce((s,a)=>s+(a.kind==="text"?a.text.length:0),0);if(!Number.isInteger(t)||t<=0||t>=n)return null;let r=[],o=[],i=0;for(let s of e.content){if(s.kind!=="text")return null;let a=i,l=i+s.text.length;if(i=l,l<=t){r.push(s);continue}if(a>=t){o.push(s);continue}let c=t-a;r.push($(v({},s),{text:s.text.slice(0,c)})),o.push($(v({},s),{text:s.text.slice(c)}));}return r.length===0||o.length===0?null:{head:$(v({},e),{content:r}),tail:$(v({},e),{content:o})}}function yb(e,t){if(!Number.isInteger(t)||t<0||t>e.blocks.length)return null;let n=e.blocks.slice(0,t),r=e.blocks.slice(t);return n.length===0&&r.length===0||n.length===0||r.length===0?null:{head:$(v({},e),{blocks:n,paragraphs:n.flatMap(Ua)}),tail:$(v({},e),{blocks:r,paragraphs:r.flatMap(Ua)})}}function Ko(e,t){for(let n of e)n.kind==="table"&&vb(n,t);}function vb(e,t){t.tables+=1;for(let n of e.rows){t.rows+=1;let r=Ka(n);r.kind==="repeat-header"?t.repeatHeaderRows+=1:r.kind==="keep-together"?t.keepTogetherRows+=1:r.kind==="block-fragmentable"?t.blockFragmentableRows+=1:r.kind==="text-fragmentable"?t.textFragmentableRows+=1:t.unsplittableRows+=1;for(let o of r.risks)t.risks[o]+=1;for(let o of n.cells)Ko(o.blocks,t);}}function Sb(e){var n;let t=new Set;e.cantSplit&&t.add("cant-split");for(let r of e.cells)((n=r.rowSpan)!=null?n:1)>1&&t.add("row-span"),(r.vMerge==="restart"||r.vMerge==="continue")&&t.add("vertical-merge"),kb(r,t);return [...t]}function kb(e,t){for(let n of e.blocks){if(n.kind==="table"){t.add("nested-table");continue}Eb(n,t);}}function Eb(e,t){for(let n of e.content)Cb(n,t);}function Cb(e,t){var n,r;(e.kind==="image"||e.kind==="drawing")&&t.add("media"),e.kind==="field"&&t.add("field"),e.kind==="pageBreak"&&t.add("page-break"),e.kind==="text"&&((n=e.marks)!=null&&n.some(o=>o.kind==="comment")&&t.add("comment"),(r=e.marks)!=null&&r.some(o=>o.kind==="revision")&&t.add("revision"));}function pc(e){return e.blocks.reduce((t,n)=>n.kind==="paragraph"?t+1:t+n.rows.reduce((r,o)=>r+o.cells.reduce((i,s)=>i+pc(s),0),0),0)}function fc(e){return e.blocks.reduce((t,n)=>t+Ib(n),0)}function Ua(e){return e.kind==="paragraph"?[e]:e.rows.flatMap(t=>t.cells.flatMap(n=>n.blocks.flatMap(Ua)))}function Ib(e){return e.kind==="paragraph"?e.content.reduce((t,n)=>t+(n.kind==="text"?n.text.length:0),0):e.rows.reduce((t,n)=>t+n.cells.reduce((r,o)=>r+fc(o),0),0)}function cn(e){return e?e.numFmt==="bullet"?"bullet":"numbered":null}function _a(e,t,n=0){let r=Xa(n);return {numId:Nb(e,t),ilvl:r,numFmt:t==="bullet"?"bullet":xc(r),lvlText:t==="bullet"?wc(r):`%${r+1}.`,start:1}}function qa(e,t){var o,i;let n=Xa(t),r=(o=cn(e))!=null?o:"numbered";return $(v({},e),{ilvl:n,numFmt:r==="bullet"?"bullet":xc(n),lvlText:r==="bullet"?wc(n):`%${n+1}.`,start:(i=e.start)!=null?i:1})}function _o(e){var n,r,o,i;let t=new Map;for(let s of _e(e)){let a=(n=s.format)==null?void 0:n.numbering;if(!((r=s.format)!=null&&r.hasNumbering)||!a)continue;let l=`${s.story}:${a.numId}:${a.ilvl}`;if(cn(a)==="bullet"){a.label=Pb(a.lvlText);continue}let c=((i=t.get(l))!=null?i:((o=a.start)!=null?o:1)-1)+1;t.set(l,c),a.label=Mb(c,a.numFmt,a.lvlText);}}function gc(e){return {left:(Xa(e)+1)*720,firstLine:-360}}function bc(e,t,n){let r=new Set(t);for(let o of t){let i=be(e,o);if(!i)continue;let s=[i.container[i.index-1],i.container[i.index+1]];for(let a of s){if((a==null?void 0:a.kind)!=="paragraph"||r.has(a.paraId))continue;let l=Tb(a,n);if(l)return v({},l)}}return null}function Nb(e,t){let n=new Set(_e(e).map(i=>{var s,a;return (a=(s=i.format)==null?void 0:s.numbering)==null?void 0:a.numId}).filter(i=>!!i)),r=1,o="";do o=`coco-${t}-${r}`,r+=1;while(n.has(o));return o}function Tb(e,t){var r;let n=(r=e.format)!=null&&r.hasNumbering?e.format.numbering:void 0;return !n||cn(n)!==t?null:n.numId.startsWith(`coco-${t}-`)?n:null}function Xa(e){return Math.max(0,Math.min(8,Math.round(e)))}function wc(e){return ["\u2022","\u25E6","\u25AA"][e%3]}function xc(e){return ["decimal","lowerLetter","lowerRoman"][e%3]}function Pb(e){return (e==null?void 0:e.replace(/%\d+/g,"").trim())||"\u2022"}function Mb(e,t,n){let r=t==="lowerLetter"?mc(e,false):t==="upperLetter"?mc(e,true):t==="lowerRoman"?hc(e).toLowerCase():t==="upperRoman"?hc(e):String(e);return n?n.replace(/%\d+/g,r):`${r}.`}function mc(e,t){let n=Math.max(1,e),r="";for(;n>0;)n-=1,r=String.fromCharCode((t?65:97)+n%26)+r,n=Math.floor(n/26);return r}function hc(e){let t=Math.max(1,Math.min(3999,e)),n="",r=[[1e3,"M"],[900,"CM"],[500,"D"],[400,"CD"],[100,"C"],[90,"XC"],[50,"L"],[40,"XL"],[10,"X"],[9,"IX"],[5,"V"],[4,"IV"],[1,"I"]];for(let[o,i]of r)for(;t>=o;)n+=i,t-=o;return n}function nt(e){return Dt(e)}function Pr(e){var n,r;if(e.rows.length===0)return false;let t=(r=(n=e.rows[0])==null?void 0:n.cells.length)!=null?r:0;return t>0&&e.rows.every(o=>o.cells.length===t&&o.cells.every(i=>i.gridSpan===1&&(i.rowSpan===void 0||i.rowSpan===1)&&i.vMerge==null))}function Sc(e,t,n,r,o,i=()=>Pn(e),s=()=>Ob(e)){var N,L,F,W,V,ee;let a=be(e,t);if(!a||a.container!==e.blocks)return null;let l=Math.max(1,Math.min(20,Math.trunc(r))),c=Math.max(1,Math.min(20,Math.trunc(o)));if(!Number.isFinite(r)||!Number.isFinite(o))return null;let u=a.paragraph,f=Dt([u]),p=Math.max(0,Math.min(n,Te(u).length)),w=fn(u.content,p);u.content=w.before;let b={kind:"paragraph",paraId:i(),story:u.story,styleId:u.styleId,format:u.format?Ut(u.format):null,content:w.after},g=s(),h=Math.max(1440,((L=(N=e.pageLayout)==null?void 0:N.width)!=null?L:11906)-((W=(F=e.pageLayout)==null?void 0:F.margin.left)!=null?W:1440)-((ee=(V=e.pageLayout)==null?void 0:V.margin.right)!=null?ee:1440)),y=Math.max(360,Math.floor(h/c)),k={kind:"table",tableId:g,columnWidths:Array.from({length:c},()=>y),layout:{width:y*c,widthType:"dxa",alignment:"left"},borders:Ya("000000"),rows:Array.from({length:l},()=>({cells:Array.from({length:c},()=>{let pe={kind:"paragraph",paraId:i(),story:u.story,styleId:null,format:null,content:[{kind:"text",text:"",format:null}]};return {gridSpan:1,width:y,borders:Ya("000000"),blocks:[pe],paragraphs:[pe]}})}))},C=[u,k,b];return a.container.splice(a.index,1,...C),{changes:[{kind:"table",op:"insert-table",tableId:g,rowIndex:0,columnIndex:0}],cursor:{paraId:k.rows[0].cells[0].paragraphs[0].paraId,offset:0},container:a.container,startIndex:a.index,beforeBlocks:f,afterBlocks:Dt(C)}}function kc(e,t,n=()=>Pn(e)){var a,l,c;let r=Oe(e,t);if(!r||r.container!==e.blocks)return null;let o=(l=(a=r.table.rows[0])==null?void 0:a.cells[0])==null?void 0:l.paragraphs[0],i={kind:"paragraph",paraId:n(),story:(c=o==null?void 0:o.story)!=null?c:"word/document.xml",styleId:null,format:null,content:[{kind:"text",text:"",format:null}]},s=Dt([r.table]);return r.container.splice(r.tableIndex,1,i),{changes:[{kind:"table",op:"delete-table",tableId:t,rowIndex:0,columnIndex:0}],cursor:{paraId:i.paraId,offset:0},container:r.container,startIndex:r.tableIndex,beforeBlocks:s,afterBlocks:Dt([i])}}function Ec(e,t,n,r=()=>Pn(e)){var u,f;let o=Qt(e,t);if(!o||!Pr(o.table))return null;let{table:i,rowIndex:s,cellIndex:a}=o;if(n.kind==="insert-row"){let p=s+(n.position==="after"?1:0),w=Ab(o.row,r);return i.rows.splice(p,0,w),{change:{kind:"table",op:"insert-row",tableId:i.tableId,rowIndex:p,columnIndex:a},cursor:{paraId:un((u=w.cells[a])!=null?u:w.cells[0]).paraId,offset:0}}}if(n.kind==="delete-row"){if(i.rows.length<=1)return null;i.rows.splice(s,1);let p=i.rows[Math.min(s,i.rows.length-1)];return {change:{kind:"table",op:"delete-row",tableId:i.tableId,rowIndex:s,columnIndex:a},cursor:{paraId:un(p.cells[Math.min(a,p.cells.length-1)]).paraId,offset:0}}}if(n.kind==="insert-column"){let p=a+(n.position==="after"?1:0);for(let g of i.rows){let h=g.cells[Math.min(a,g.cells.length-1)];g.cells.splice(p,0,Qa(h,r));}let w=(f=i.columnWidths[Math.min(a,i.columnWidths.length-1)])!=null?f:0;i.columnWidths.splice(p,0,w);let b=i.rows[s];return {change:{kind:"table",op:"insert-column",tableId:i.tableId,rowIndex:s,columnIndex:p},cursor:{paraId:un(b.cells[p]).paraId,offset:0}}}if(i.rows[0].cells.length<=1)return null;for(let p of i.rows)p.cells.splice(a,1);a<i.columnWidths.length&&i.columnWidths.splice(a,1);let l=i.rows[s],c=l.cells[Math.min(a,l.cells.length-1)];return {change:{kind:"table",op:"delete-column",tableId:i.tableId,rowIndex:s,columnIndex:a},cursor:{paraId:un(c).paraId,offset:0}}}function Ja(e,t,n){var a;let r=Qt(e,t);if(!r)return null;let o=JSON.stringify({shading:r.cell.shading,verticalAlignment:r.cell.verticalAlignment,borders:r.cell.borders}),i={};if(n.backgroundColor!==void 0){let l=yc(n.backgroundColor);if(n.backgroundColor!==null&&!l)return null;l?r.cell.shading={fill:l,val:"clear"}:delete r.cell.shading,i.backgroundColor=l?`#${l}`:null;}if(n.verticalAlignment!==void 0&&(n.verticalAlignment?r.cell.verticalAlignment=n.verticalAlignment:delete r.cell.verticalAlignment,i.verticalAlignment=(a=n.verticalAlignment)!=null?a:null),n.borderColor!==void 0){let l=yc(n.borderColor);if(n.borderColor!==null&&!l)return null;r.cell.borders=l?Ya(l):Rb(),i.borderColor=l?`#${l}`:null;}let s=JSON.stringify({shading:r.cell.shading,verticalAlignment:r.cell.verticalAlignment,borders:r.cell.borders});return o===s?null:{change:{kind:"table",op:"format-cell",tableId:r.table.tableId,rowIndex:r.rowIndex,columnIndex:r.columnIndex,format:i},cursor:{paraId:t,offset:0}}}function at(e,t){let n=Math.max(0,Math.min(t.anchor.rowIndex,t.focus.rowIndex)),r=Math.min(e.rows.length-1,Math.max(t.anchor.rowIndex,t.focus.rowIndex)),o=Math.max(0,Math.min(t.anchor.columnIndex,t.focus.columnIndex)),i=Math.max(t.anchor.columnIndex,t.focus.columnIndex),s=[];for(let a=n;a<=r;a+=1){let l=e.rows[a];if(!l)continue;let c=0;for(let u of l.cells){let f=Math.max(1,u.gridSpan),p=c+f-1;c<=i&&p>=o&&s.push({cell:u,rowIndex:a,columnIndex:c}),c+=f;}}return s}function Cc(e,t,n){let r=Oe(e,t);if(!r)return null;let o=Math.min(n.anchor.rowIndex,n.focus.rowIndex),i=Math.max(n.anchor.rowIndex,n.focus.rowIndex),s=Math.min(n.anchor.columnIndex,n.focus.columnIndex),a=Math.max(n.anchor.columnIndex,n.focus.columnIndex);if(o<0||o>=r.table.rows.length||i>=r.table.rows.length||o!==i&&s!==a)return null;let l=r.table.rows[o];if(!l)return null;if(o!==i){let g=r.table.rows.slice(o,i+1).map(N=>N.cells[s]);if(g.some(N=>!N||N.gridSpan!==1||N.vMerge!=null))return null;let h=g,y=h[0],k=h.flatMap(N=>N.blocks.map(Ut)),C=k.flatMap(N=>N.kind==="paragraph"?[N]:Tr([N]));y.blocks=k,y.paragraphs=C,y.rowSpan=h.length,y.vMerge="restart";for(let N of h.slice(1)){let L=N.paragraphs[0];L&&(L.content=[{kind:"text",text:"",format:null}]),N.blocks=L?[L]:[],N.paragraphs=L?[L]:[],N.rowSpan=void 0,N.vMerge="continue";}return {change:{kind:"table",op:"merge-cells",tableId:t,rowIndex:o,columnIndex:s,endRowIndex:i},cursor:{paraId:y.paragraphs[0].paraId,offset:0}}}if(s===a)return null;let c=at(r.table,n).filter(g=>g.rowIndex===o);if(c.length<2||c.some(g=>g.cell.gridSpan!==1||g.cell.vMerge!=null))return null;let u=c[0],f=c[c.length-1];if(u.columnIndex!==s||f.columnIndex!==a||c.length!==a-s+1)return null;let p=c.flatMap(({cell:g})=>g.blocks.map(Ut)),w=p.flatMap(g=>g.kind==="paragraph"?[g]:Tr([g]));u.cell.blocks=p,u.cell.paragraphs=w,u.cell.gridSpan=c.length;let b=l.cells.indexOf(u.cell);return b<0?null:(l.cells.splice(b,c.length,u.cell),{change:{kind:"table",op:"merge-cells",tableId:t,rowIndex:o,columnIndex:s,endColumnIndex:a},cursor:{paraId:u.cell.paragraphs[0].paraId,offset:0}})}function Ic(e,t,n,r,o=()=>Pn(e)){var p,w;let i=Oe(e,t),s=i==null?void 0:i.table.rows[n];if(!i||!s)return null;let a=0,l=s.cells.findIndex(b=>{let g=a===r;return a+=Math.max(1,b.gridSpan),g}),c=l>=0?s.cells[l]:null;if(!c)return null;if(c.vMerge==="restart"&&((p=c.rowSpan)!=null?p:1)>1){let b=n+((w=c.rowSpan)!=null?w:1)-1;if(b>=i.table.rows.length)return null;let g=i.table.rows.slice(n,b+1).map(h=>h.cells[r]);if(g.length!==c.rowSpan||g.some((h,y)=>!h||h.gridSpan!==1?true:y===0?h.vMerge!=="restart":h.vMerge!=="continue"))return null;c.rowSpan=void 0,c.vMerge=void 0;for(let h of g.slice(1))h.rowSpan=void 0,h.vMerge=void 0;return {change:{kind:"table",op:"split-cell",tableId:t,rowIndex:n,columnIndex:r,endRowIndex:b},cursor:{paraId:c.paragraphs[0].paraId,offset:0}}}if(c.gridSpan<=1||c.vMerge!=null||c.rowSpan&&c.rowSpan>1)return null;let u=c.gridSpan;c.gridSpan=1;let f=Array.from({length:u-1},()=>Qa(c,o));return s.cells.splice(l+1,0,...f),{change:{kind:"table",op:"split-cell",tableId:t,rowIndex:n,columnIndex:r},cursor:{paraId:c.paragraphs[0].paraId,offset:0}}}function Nc(e,t,n,r){let o=Oe(e,t);if(!o)return null;let i=[],s=null;for(let{cell:a}of at(o.table,n)){let l=un(a).paraId;s!=null||(s={paraId:l,offset:0});let c=Ja(e,l,r);c&&i.push(c.change);}return s&&i.length>0?{changes:i,cursor:s}:null}function Tc(e,t,n){var s;let r=Oe(e,t);if(!r)return null;let o=[],i=null;for(let{cell:a,rowIndex:l,columnIndex:c}of at(r.table,n)){let u=un(a);i!=null||(i={paraId:u.paraId,offset:0}),!(a.blocks.length===1&&u.content.length===1&&((s=u.content[0])==null?void 0:s.kind)==="text"&&u.content[0].text.length===0)&&(u.content=[{kind:"text",text:"",format:null}],a.blocks=[u],a.paragraphs=[u],o.push({kind:"table",op:"clear-cell",tableId:t,rowIndex:l,columnIndex:c}));}return i&&o.length>0?{changes:o,cursor:i}:null}function Pc(e,t,n,r){var u,f,p;let o=Oe(e,t);if(!o||r.length===0||r.every(w=>w.length===0))return null;let i=r.length,s=Math.max(0,...r.map(w=>w.length)),a={anchor:n,focus:{rowIndex:n.rowIndex+i-1,columnIndex:n.columnIndex+s-1}},l=[],c=null;for(let{cell:w,rowIndex:b,columnIndex:g}of at(o.table,a)){let h=(u=r[b-n.rowIndex])==null?void 0:u[g-n.columnIndex];if(h===void 0)continue;let y=un(w);if(c!=null||(c={paraId:y.paraId,offset:h.length}),w.paragraphs.map(N=>Te(N)).join(`
12
+ `)===h&&w.blocks.length===1)continue;let C=(p=(f=y.content.find(N=>N.kind==="text"))==null?void 0:f.format)!=null?p:null;y.content=[{kind:"text",text:h,format:C?Ut(C):null}],w.blocks=[y],w.paragraphs=[y],l.push({kind:"table",op:"replace-cell",tableId:t,rowIndex:b,columnIndex:g,text:h});}return c&&l.length>0?{changes:l,cursor:c}:null}function Mc(e,t,n,r){var c;let o=Oe(e,t);if(!o||r.length===0||r.every(u=>u.length===0))return null;let i=Math.max(0,...r.map(u=>u.length)),s={anchor:n,focus:{rowIndex:n.rowIndex+r.length-1,columnIndex:n.columnIndex+i-1}},a=[],l=null;for(let{cell:u,rowIndex:f,columnIndex:p}of at(o.table,s)){let w=(c=r[f-n.rowIndex])==null?void 0:c[p-n.columnIndex];if(!w)continue;let b=Yc(e,w.blocks),g=Tr(b);g.length!==0&&(u.blocks=b,u.paragraphs=g,Nr(u,"margin",w.format.margin),Nr(u,"borders",w.format.borders),Nr(u,"shading",w.format.shading),Nr(u,"verticalAlignment",w.format.verticalAlignment),Nr(u,"noWrap",w.format.noWrap),l!=null||(l={paraId:g[0].paraId,offset:Te(g[0]).length}),a.push({kind:"table",op:"replace-cell",tableId:t,rowIndex:f,columnIndex:p,cellSnapshot:Ut(u)}));}return l&&a.length>0?{changes:a,cursor:l}:null}function Nr(e,t,n){n===void 0?delete e[t]:e[t]=Ut(n);}function yc(e){if(e===null)return null;let t=e.trim().replace(/^#/,"").toUpperCase();return /^[0-9A-F]{6}$/.test(t)?t:null}function Ya(e){let t={val:"single",color:e,size:4};return {top:v({},t),right:v({},t),bottom:v({},t),left:v({},t)}}function Rb(){let e={val:"nil"};return {top:v({},e),right:v({},e),bottom:v({},e),left:v({},e)}}function Ab(e,t){let o=e,{cells:n}=o,r=Nn(o,["cells"]);return $(v({},Ut(r)),{cells:n.map(i=>Qa(i,t))})}function Qa(e,t){let a=e,{blocks:n,paragraphs:r}=a,o=Nn(a,["blocks","paragraphs"]),i=un(e),s={kind:"paragraph",paraId:t(),story:i.story,styleId:i.styleId,format:i.format?Ut(i.format):null,content:[{kind:"text",text:"",format:null}]};return $(v({},Ut(o)),{gridSpan:1,blocks:[s],paragraphs:[s]})}function un(e){let t=e.paragraphs[0];if(!t)throw new Error("Native table cell must contain at least one paragraph");return t}function Ut(e){return JSON.parse(JSON.stringify(e))}function en(e,t,n,r){let o=_(e,t);return !o||r.length===0?null:(o.content=_c(o.content,n,r),{kind:"text",op:"insert",paraId:t,offset:n,text:r})}function Rc(e,t,n,r,o={}){var u;let i=_(e,t);if(!i||!r)return null;let s=(u=o.drawingId)!=null?u:Bb(e),a=Xo(o.width),l=Xo(o.height),c=fn(i.content,n);return i.content=He([...c.before,v(v({kind:"image",drawingId:s,src:r},a?{width:a}:{}),l?{height:l}:{}),...c.after]),v(v({kind:"image",op:"insert",paraId:t,offset:n,drawingId:s,src:r},a?{width:a}:{}),l?{height:l}:{})}function Ac(e,t,n){let r=_(e,t);if(!r)return null;let o=Math.max(0,Math.min(n,Te(r).length)),i=fn(r.content,o);return r.content=He([...i.before,{kind:"pageBreak"},...i.after]),{kind:"page-break",op:"insert",paraId:t,offset:o}}function Zo(e,t,n){let r=_(e,t);if(!r||n<0)return false;let o=0;for(let i of r.content){let s=$e(i);if(n>=o&&n<o+s)return i.kind==="pageBreak";o+=s;}return false}function Lc(e,t,n,r){let o=_(e,t),i=Nt(n,r);if(!o||i.from===i.to)return false;let s=0;for(let a of o.content){let l=$e(a);if(a.kind==="pageBreak"&&i.from<s+l&&i.to>s)return true;s+=l;}return false}function Wc(e,t,n,r){let o=_(e,t),i=o==null?void 0:o.content.find(c=>c.kind==="image"&&c.drawingId===n),s=Xo(r.width),a=Xo(r.height);if(!o||!i||!s||!a||i.width===s&&i.height===a)return null;i.width=s,i.height=a;let l=0;for(let c of o.content){if(c===i)break;l+=$e(c);}return {kind:"image",op:"resize",paraId:t,offset:l,drawingId:n,width:s,height:a}}function Mr(e,t,n){let r=be(e,t);if(!r)return null;let{paragraph:o}=r;if(n>0)return Wb(o,n);let i=r.previous;return i?(i.content=He([...i.content,...o.content]),r.remove(),{kind:"block",op:"merge",paraId:i.paraId}):null}function Rr(e,t,n){let r=be(e,t);if(!r)return null;let{paragraph:o}=r;if(n<qo(o.content))return qc(o,n);let i=r.container[r.index+1];return (i==null?void 0:i.kind)!=="paragraph"?null:(o.content=He([...o.content,...i.content]),r.container.splice(r.index+1,1),{kind:"block",op:"merge",paraId:o.paraId})}function pn(e,t,n,r){let o=_(e,t),i=Nt(n,r);if(!o||i.from===i.to)return [];let s=Db(o,i.from,i.to);return o.content=s.content,s.changes}function Jo(e,t,n){var w;if(t.paraId===n.paraId)return pn(e,t.paraId,t.offset,n.offset);let r=be(e,t.paraId),o=be(e,n.paraId);if(!r||!o)return [];if(r.container!==o.container)return [];let i=r.index<o.index?{start:r,end:o,startOffset:t.offset,endOffset:n.offset}:{start:o,end:r,startOffset:n.offset,endOffset:t.offset};if(i.start.paragraph.content.some(b=>b.kind!=="text")||i.end.paragraph.content.some(b=>b.kind!=="text"))return [];if(i.start.container.slice(i.start.index,i.end.index+1).some(b=>b.kind!=="paragraph"))return [];for(let b=i.start.index+1;b<i.end.index;b+=1){let g=i.start.container[b];if((g==null?void 0:g.kind)!=="paragraph"||g.content.some(h=>h.kind!=="text"))return []}let s=[],a=Te(i.start.paragraph),l=Te(i.end.paragraph),c=Math.max(0,Math.min(i.startOffset,a.length)),u=Math.max(0,Math.min(i.endOffset,l.length)),f=`${a.slice(0,c)}${l.slice(u)}`,p=i.end.index-i.start.index;for(let b=i.end.index;b>i.start.index;b-=1){let g=i.start.container[b];if((g==null?void 0:g.kind)==="paragraph"){if(g===i.end.paragraph&&u<l.length)s.push({kind:"text",op:"delete",paraId:g.paraId,offset:0,text:l.slice(0,u)});else {let h=Te(g);h.length>0&&s.push({kind:"text",op:"delete",paraId:g.paraId,offset:0,text:h});}(w=be(e,g.paraId))==null||w.remove();}}c<a.length&&s.push({kind:"text",op:"delete",paraId:i.start.paragraph.paraId,offset:c,text:a.slice(c)});for(let b=0;b<p;b+=1)s.push({kind:"block",op:"merge",paraId:i.start.paragraph.paraId});return i.start.paragraph.content=f.length>0?[{kind:"text",text:f,format:Zc(i.start.paragraph.content,c)}]:[],s}function Bc(e,t,n,r){let o=be(e,t.paraId),i=be(e,n.paraId);if(!o||!i||o.container!==e.blocks||i.container!==e.blocks)return null;let s=o.index<i.index||o.index===i.index&&t.offset<=n.offset?{start:o,end:i,startOffset:t.offset,endOffset:n.offset}:{start:i,end:o,startOffset:n.offset,endOffset:t.offset};if(s.start.index===s.end.index||s.start.paragraph.content.some(b=>b.kind!=="text")||s.end.paragraph.content.some(b=>b.kind!=="text"))return null;let a=e.blocks.slice(s.start.index,s.end.index+1);if(!a.slice(1,-1).some(b=>b.kind==="table"||b.content.some(g=>g.kind!=="text")))return null;let l=Dt(a),c=Te(s.start.paragraph).length,u=Te(s.end.paragraph).length,f=Math.max(0,Math.min(s.startOffset,c)),p=Math.max(0,Math.min(s.endOffset,u)),w=[...pn(e,s.end.paragraph.paraId,0,p),...pn(e,s.start.paragraph.paraId,f,c)];if(s.start.paragraph.content=He([...s.start.paragraph.content,...s.end.paragraph.content]),e.blocks.splice(s.start.index+1,s.end.index-s.start.index),r.length>0){let b=en(e,s.start.paragraph.paraId,f,r);b&&w.push(b);}return w.push({kind:"structure",op:"delete-range",startParaId:s.start.paragraph.paraId,endParaId:s.end.paragraph.paraId,deletedBlockIds:a.slice(1).map(Xc)}),{changes:w,cursor:{paraId:s.start.paragraph.paraId,offset:f+r.length},container:e.blocks,startIndex:s.start.index,beforeBlocks:l,afterBlocks:Dt([s.start.paragraph])}}function es(e,t,n){let r=Fb(e,t,n);if(!r||r.blocks.length<2&&!Hb(r.blocks))return null;let o=Dt(r.blocks),i=o[0],s=o[o.length-1];return (i==null?void 0:i.kind)!=="paragraph"||(s==null?void 0:s.kind)!=="paragraph"?null:(i.content=fn(i.content,r.startOffset).after,s.content=fn(s.content,r.endOffset).before,o)}function Dc(e,t,n,r){if(t.paraId!==n.paraId||r.length===0)return null;let o=be(e,t.paraId);if(!o||o.container!==e.blocks)return null;let i=r[0],s=r[r.length-1];if((i==null?void 0:i.kind)!=="paragraph"||(s==null?void 0:s.kind)!=="paragraph")return null;let a=Dt([o.paragraph]),l=Te(o.paragraph).length,c=Math.max(0,Math.min(t.offset,n.offset,l)),u=Math.max(c,Math.min(Math.max(t.offset,n.offset),l)),f=fn(o.paragraph.content,c).before,p=fn(o.paragraph.content,u).after,w=Yc(e,r),b=w[0],g=w[w.length-1];if((b==null?void 0:b.kind)!=="paragraph"||(g==null?void 0:g.kind)!=="paragraph")return null;f.length===0&&p.length===0&&(o.paragraph.styleId=b.styleId,o.paragraph.format=b.format?Ut(b.format):null),o.paragraph.content=He([...f,...b.content]);let y={paraId:o.paragraph.paraId,offset:qo(o.paragraph.content)},k=[o.paragraph];w.length===1?o.paragraph.content=He([...o.paragraph.content,...p]):(g.content=He([...g.content,...p]),k.push(...w.slice(1)),y={paraId:g.paraId,offset:qo(g.content)-qo(p)}),e.blocks.splice(o.index,1,...k);let C=Dt(k);return {changes:[{kind:"structure",op:"insert-range",paraId:o.paragraph.paraId,insertedBlockIds:k.slice(1).map(Xc)}],cursor:y,container:e.blocks,startIndex:o.index,beforeBlocks:a,afterBlocks:C}}function Ar(e,t,n,r,o){let i=Nt(n,r),s=pn(e,t,i.from,i.to),a=en(e,t,i.from,o);return a?[...s,a]:s}function Fc(e,t,n,r){if(t.paraId===n.paraId)return Ar(e,t.paraId,t.offset,n.offset,r);let o=be(e,t.paraId),i=be(e,n.paraId);if(!o||!i||o.container!==i.container)return [];let s=o.index<i.index?t:n,a=Jo(e,t,n);if(a.length===0||r.length===0)return a;let l=en(e,s.paraId,s.offset,r);return l?[...a,l]:a}function ts(e,t,n,r){var b,g,h,y,k,C,N,L;let o=be(e,t.paraId),i=be(e,n.paraId);if(!o||!i||o.container!==i.container)return null;let s=o.index<i.index||o.index===i.index&&t.offset<=n.offset?t:n,a=Jo(e,t,n),l=_(e,s.paraId);if(!l||l.content.some(F=>F.kind!=="text"))return null;let c=r.replace(/\r\n?/g,`
6
13
  `).split(`
7
- `),u=[s.paraId],f=s.paraId,p=Math.max(0,Math.min(s.offset,Te(l).length)),w=Qt(e,f,p,(b=c[0])!=null?b:"");w&&a.push(w);for(let D=1;D<c.length;D+=1){let W=Tn(e),V=ts(e,f,p+((h=(g=c[D-1])==null?void 0:g.length)!=null?h:0),W);if(!V)return null;a.push(V),u.push(W),f=W,p=0;let ee=Qt(e,f,0,(y=c[D])!=null?y:"");ee&&a.push(ee);}return {changes:a,cursor:{paraId:f,offset:c.length===1?p+((C=(k=c[0])==null?void 0:k.length)!=null?C:0):(L=(N=c[c.length-1])==null?void 0:N.length)!=null?L:0},paragraphIds:u}}function Ja(e,t,n,r,o){var u;let i=_(e,t),s=Nt(n,r);if(!i||s.from===s.to)return null;let a=0,l=false,c=[];for(let f of i.content){let p=$e(f);if(f.kind!=="text"||a+p<=s.from||a>=s.to){c.push(f),a+=p;continue}let w=Math.max(0,s.from-a),b=Math.min(p,s.to-a);w>0&&c.push($(v({},f),{text:f.text.slice(0,w)})),b>w&&(c.push($(v({},f),{text:f.text.slice(w,b),format:v(v({},(u=f.format)!=null?u:{}),o)})),l=true),b<p&&c.push($(v({},f),{text:f.text.slice(b)})),a+=p;}return l?(i.content=He(c),{kind:"format",op:"run",paraId:t,from:s.from,to:s.to,format:o}):null}function Qa(e,t,n,r,o){var f,p,w;let i=_(e,t),s=Nt(n,r);if(!i||s.from===s.to)return null;let a=0,l=false,c=[],u=$(v({kind:"comment",id:`comment:${o.commentId}`,commentId:o.commentId},o.parentCommentId!==void 0?{parentCommentId:o.parentCommentId}:{}),{author:o.author,date:o.date,body:o.body});for(let b of i.content){let g=$e(b);if(b.kind!=="text"||a+g<=s.from||a>=s.to){c.push(b),a+=g;continue}let h=Math.max(0,s.from-a),y=Math.min(g,s.to-a);if(h>0&&c.push($(v({},b),{text:b.text.slice(0,h)})),y>h){let k=b.text.slice(h,y);if(o.preserveExistingComments&&((f=b.marks)!=null&&f.some(C=>C.kind==="comment")))c.push($(v({},b),{text:k})),c.push($(v({},b),{text:k,marks:[u,...(p=b.marks)!=null?p:[]]}));else {let C=((w=b.marks)!=null?w:[]).filter(N=>N.kind!=="comment");c.push($(v({},b),{text:k,marks:[...C,u]}));}l=true;}y<g&&c.push($(v({},b),{text:b.text.slice(y)})),a+=g;}return l?(i.content=He(c),{kind:"annotation",op:"insert",paraId:t,from:s.from,to:s.to,commentId:o.commentId,body:o.body,parentCommentId:o.parentCommentId}):null}function Wc(e,t,n){let r=[];for(let o of _e(e)){let i=0,s=null,a=null,l=false,c=o.content.map(u=>{var w,b;let f=$e(u);return u.kind!=="text"||!((w=u.marks)==null?void 0:w.find(g=>g.kind==="comment"&&g.commentId===t))?(i+=f,u):(s=s===null?i:s,a=i+f,l=true,i+=f,$(v({},u),{marks:(b=u.marks)==null?void 0:b.map(g=>g.kind==="comment"&&g.commentId===t?$(v({},g),{body:n}):g)}))});!l||s===null||a===null||(o.content=He(c),r.push({kind:"annotation",op:"update",paraId:o.paraId,from:s,to:a,commentId:t,body:n}));}return r}function Bc(e,t){let n=[];for(let r of _e(e)){let o=0,i=null,s=null,a=false,l=r.content.map(c=>{var w,b,g;let u=$e(c);if(c.kind!=="text"||!((b=(w=c.marks)==null?void 0:w.some(h=>h.kind==="comment"&&h.commentId===t))!=null?b:false))return o+=u,c;i=i===null?o:i,s=o+u,a=true,o+=u;let p=(g=c.marks)==null?void 0:g.filter(h=>!(h.kind==="comment"&&h.commentId===t));return p&&p.length>0?$(v({},c),{marks:p}):$(v({},c),{marks:void 0})});!a||i===null||s===null||(r.content=He(l),n.push({kind:"annotation",op:"delete",paraId:r.paraId,from:i,to:s,commentId:t}));}return n}function Dt(e,t,n,r,o){var f,p;let i=_(e,t),s=Nt(n,r);if(!i||s.from===s.to)return null;let a=0,l=false,c=[],u={kind:"revision",id:`revision:${o.revisionId}`,revisionId:o.revisionId,revisionKind:o.revisionKind,author:o.author,date:o.date};for(let w of i.content){let b=$e(w);if(w.kind!=="text"||a+b<=s.from||a>=s.to){c.push(w),a+=b;continue}let g=Math.max(0,s.from-a),h=Math.min(b,s.to-a);if(g>0&&c.push($(v({},w),{text:w.text.slice(0,g)})),h>g){let y=((f=w.marks)!=null?f:[]).find(k=>k.kind==="revision");if(!(o.revisionKind==="delete"&&(y==null?void 0:y.revisionKind)==="insert")){let k=((p=w.marks)!=null?p:[]).filter(C=>C.kind!=="revision");c.push($(v({},w),{text:w.text.slice(g,h),marks:[...k,u]}));}l=true;}h<b&&c.push($(v({},w),{text:w.text.slice(h)})),a+=b;}return l?(i.content=He(c),{kind:"revision",op:o.revisionKind,paraId:t,from:s.from,to:s.to,revisionId:o.revisionId,revisionKind:o.revisionKind}):null}function Fc(e,t,n,r,o){var p,w,b,g;let i=_(e,t),s=Nt(n,r);if(!i||s.from===s.to)return null;let a=0,l=false,c="",u="insert",f=[];for(let h of i.content){let y=$e(h);if(h.kind!=="text"||a+y<=s.from||a>=s.to){f.push(h),a+=y;continue}let k=Math.max(0,s.from-a),C=Math.min(y,s.to-a);if(k>0&&f.push($(v({},h),{text:h.text.slice(0,k)})),C>k){let N=h.text.slice(k,C),L=((p=h.marks)!=null?p:[]).find(D=>D.kind==="revision");L?(l=true,c=(w=L.revisionId)!=null?w:L.id.replace(/^revision:/,""),u=(b=L.revisionKind)!=null?b:"insert",(o==="accept"?u==="insert":u==="delete")&&f.push($(v({},h),{text:N,marks:((g=h.marks)!=null?g:[]).filter(W=>W.kind!=="revision")}))):f.push($(v({},h),{text:N}));}C<y&&f.push($(v({},h),{text:h.text.slice(C)})),a+=y;}return l?(i.content=He(f),{kind:"revision",op:o,paraId:t,from:s.from,to:s.to,revisionId:c,revisionKind:u}):null}function Dc(e,t,n,r,o){let i=_(e,t),s=Nt(n,r);if(!i||s.from===s.to)return null;let a=0,l=false,c="",u=[];for(let f of i.content){let p=$e(f);if(f.kind!=="text"||a+p<=s.from||a>=s.to){u.push(f),a+=p;continue}let w=Math.max(0,s.from-a),b=Math.min(p,s.to-a);if(w>0&&u.push($(v({},f),{text:f.text.slice(0,w)})),b>w){let g=f.formatRevision;g?(c=g.revisionId,l=true,u.push($(v({},f),{text:f.text.slice(w,b),format:o==="reject"?g.beforeFormat?v({},g.beforeFormat):null:f.format,formatRevision:void 0}))):u.push($(v({},f),{text:f.text.slice(w,b)}));}b<p&&u.push($(v({},f),{text:f.text.slice(b)})),a+=p;}return l?(i.content=He(u),{kind:"format",op:o,paraId:t,from:s.from,to:s.to,format:{},revisionId:c,revisionKind:"format"}):null}function es(e,t,n,r,o){var f;let i=_(e,t),s=Nt(n,r);if(!i||s.from===s.to)return null;let a=o?Rb(o):null;if(o&&!a)return null;let l=0,c=false,u=[];for(let p of i.content){let w=$e(p);if(p.kind!=="text"||l+w<=s.from||l>=s.to){u.push(p),l+=w;continue}let b=Math.max(0,s.from-l),g=Math.min(w,s.to-l);if(b>0&&u.push($(v({},p),{text:p.text.slice(0,b)})),g>b){let h=$(v({},p),{text:p.text.slice(b,g)});a?h.hyperlink=v({},a):delete h.hyperlink,u.push(h),_a((f=p.hyperlink)!=null?f:null,a)||(c=true);}g<w&&u.push($(v({},p),{text:p.text.slice(g)})),l+=w;}return c?(i.content=He(u),v({kind:"hyperlink",op:a?"set":"remove",paraId:t,from:s.from,to:s.to},a?{hyperlink:a}:{})):null}function Un(e,t,n){var i,s,a;let r=_(e,t);if(!r)return null;let o=(i=r.format)!=null?i:{};return r.format=v(v({},o),n),n.indent&&(r.format.indent=v(v({},(s=o.indent)!=null?s:{}),n.indent)),n.spacing&&(r.format.spacing=v(v({},(a=o.spacing)!=null?a:{}),n.spacing)),{kind:"format",op:"paragraph",paraId:t,format:n}}function Hc(e,t,n,r){let o=_(e,t),i=Nt(n,r);if(!o||i.from===i.to)return null;let s=0,a=false,l=[];for(let c of o.content){let u=$e(c);if(c.kind!=="text"||s+u<=i.from||s>=i.to){l.push(c),s+=u;continue}let f=Math.max(0,i.from-s),p=Math.min(u,i.to-s);f>0&&l.push($(v({},c),{text:c.text.slice(0,f)})),p>f&&(l.push($(v({},c),{text:c.text.slice(f,p),format:null})),c.format&&Object.keys(c.format).length>0&&(a=true)),p<u&&l.push($(v({},c),{text:c.text.slice(p)})),s+=u;}return a?(o.content=He(l),{kind:"format",op:"run",paraId:t,from:i.from,to:i.to,format:{},clear:true}):null}function Mr(e,t,n){var i,s,a;let r=_(e,t);if(!r)return null;let o=(i=r.format)!=null?i:{};if(n)r.format=$(v({},o),{hasNumbering:true,numbering:v({},n),indent:v(v({},(s=o.indent)!=null?s:{}),pc(n.ilvl))});else {let l=$(v({},o),{hasNumbering:false,indent:$(v({},(a=o.indent)!=null?a:{}),{left:0,firstLine:0})});delete l.numbering,r.format=l;}return {kind:"list",paraId:t,numbering:n?v({},n):null}}function FE(e,t,n,r){var l;let o=_(e,t),i=Nt(n,r);if(!o||i.from===i.to)return false;let s=0,a=false;for(let c of o.content){let u=$e(c);if(c.kind==="text"&&s+u>i.from&&s<i.to&&(a=true,((l=c.format)==null?void 0:l.bold)!==true))return false;s+=u;}return a}function Oc(e,t,n){let r=_(e,t);if(!r)return null;let o=0,i=[],s=null;for(let a of r.content)!s&&a.kind==="image"&&a.drawingId===n?s={kind:"image",op:"delete",paraId:t,offset:o,drawingId:n}:i.push(a),o+=$e(a);return s?(r.content=He(i),s):null}function $c(e,t,n,r,o,i){var p;let s=_(e,t),a=Nt(n,r);if(!s||a.from===a.to)return null;let l=0,c=false,u=[],f=w=>{let b=0;for(let g of o.content){let h=$e(g);if(g.kind==="text"&&w>=b&&w<b+h)return g.format?v({},g.format):null;b+=h;}return null};for(let w of s.content){let b=$e(w);if(w.kind!=="text"||l+b<=a.from||l>=a.to){u.push(w),l+=b;continue}let g=Math.max(0,a.from-l),h=Math.min(b,a.to-l);g>0&&u.push($(v({},w),{text:w.text.slice(0,g)})),h>g&&(u.push($(v({},w),{text:w.text.slice(g,h),formatRevision:(p=w.formatRevision)!=null?p:{kind:"format",revisionId:i.revisionId,beforeFormat:f(l+g),author:i.author,date:i.date}})),c=true),h<b&&u.push($(v({},w),{text:w.text.slice(h)})),l+=b;}return c?(s.content=He(u),{kind:"format",op:"run",paraId:t,from:a.from,to:a.to,format:{},revisionId:i.revisionId,revisionKind:"format",beforeFormat:f(a.from)}):null}function zc(e,t,n,r){let o=_(e,t);if(!o)return null;let i=0;for(let s=0;s<o.content.length;s+=1){let a=o.content[s];if((a==null?void 0:a.kind)!=="image"||a.drawingId!==n){i+=a?$e(a):0;continue}let l=a.revision;return l?(l.revisionKind==="delete"&&r==="accept"||l.revisionKind==="insert"&&r==="reject"?o.content.splice(s,1):a.revision=void 0,o.content=He(o.content),{kind:"image",op:r,paraId:t,offset:i,drawingId:n,revisionId:l.revisionId,revisionKind:l.revisionKind}):null}return null}function Vc(e,t,n,r){let o=_(e,t);if(!o)return null;let i=0;for(let s of o.content){if(s.kind!=="image"||s.drawingId!==n){i+=$e(s);continue}let a=s.formatRevision;if(!a)return null;r==="reject"&&(s.width=a.beforeWidth,s.height=a.beforeHeight);let l=a.revisionId;return s.formatRevision=void 0,{kind:"image",op:r,paraId:t,offset:i,drawingId:n,revisionId:l,revisionKind:"format"}}return null}function ts(e,t,n,r=Tn(e)){let o=be(e,t);if(!o)return null;let{paragraph:i}=o,s=pn(i.content,n);return i.content=s.before,o.insertAfter({kind:"paragraph",paraId:r,story:i.story,styleId:i.styleId,format:i.format?JSON.parse(JSON.stringify(i.format)):null,content:s.after}),{kind:"block",op:"split",paraId:t,newParaId:r,offset:n}}function Rr(e,t,n){let r=_(e,t);if(!r||r.content.some(a=>a.kind!=="text"))return null;let o=Te(r);if(o===n)return null;let i=Ab(o,n),s=r.content;return i.deletedText.length>0&&(s=kb(s,i.offset,i.deletedText.length)),i.insertedText.length>0&&(s=Gc(s,i.offset,i.insertedText,_c(r.content,i.offset))),r.content=s,i.deletedText.length===0?{kind:"text",op:"insert",paraId:t,offset:i.offset,text:i.insertedText}:i.insertedText.length===0?{kind:"text",op:"delete",paraId:t,offset:i.offset,text:i.deletedText}:{kind:"text",op:"replace",paraId:t,offset:i.offset,text:i.insertedText,deletedText:i.deletedText}}function Gc(e,t,n,r=null){let o=[],i=0,s=false;for(let a of e){let l=$e(a);if(!s&&t<=i+l){if(a.kind==="text"){let c=Math.max(0,t-i);o.push($(v({},a),{text:`${a.text.slice(0,c)}${n}${a.text.slice(c)}`}));}else t<=i?o.push({kind:"text",text:n,format:r},a):o.push(a,{kind:"text",text:n,format:r});s=true;}else o.push(a);i+=l;}return s||o.push({kind:"text",text:n,format:r}),He(o)}function kb(e,t,n){if(n<=0)return e;let r=[],o=0,i=t+n;for(let s of e){let a=$e(s),l=o+a;if(s.kind!=="text"||l<=t||o>=i)r.push(s);else {let c=Math.max(0,t-o),u=Math.max(0,l-i),f=`${s.text.slice(0,c)}${s.text.slice(s.text.length-u)}`;f.length>0&&r.push($(v({},s),{text:f}));}o=l;}return He(r)}function Eb(e,t){return jc(e,t-1)}function Cb(e){let t=new Set(_e(e).flatMap(r=>r.content.filter(o=>o.kind==="image"||o.kind==="drawing").map(o=>o.drawingId))),n=1;for(;t.has(`coco-clipboard-${n}`);)n+=1;return `coco-clipboard-${n}`}function jc(e,t){if(t<0)return null;let n=[],r=0,o=null;for(let i of e.content){let s=$e(i);if(!o&&t>=r&&t<r+s)if(i.kind==="image")o={kind:"image",op:"delete",paraId:e.paraId,offset:t,drawingId:i.drawingId};else if(i.kind==="pageBreak")o={kind:"page-break",op:"delete",paraId:e.paraId,offset:t};else if(i.kind==="text"){let a=t-r,l=i.text.slice(a,a+1),c=`${i.text.slice(0,a)}${i.text.slice(a+1)}`;c.length>0&&n.push($(v({},i),{text:c})),o={kind:"text",op:"delete",paraId:e.paraId,offset:t,text:l};}else n.push(i);else n.push(i);r+=s;}return o?(e.content=He(n),o):null}function Ib(e,t,n){let r=[],o=[],i=0;for(let s of e.content){let a=$e(s),l=i+a;if(!(t<l&&n>i)){r.push(s),i=l;continue}if(s.kind==="text"){let u=Math.max(0,t-i),f=Math.min(s.text.length,n-i),p=s.text.slice(u,f),w=`${s.text.slice(0,u)}${s.text.slice(f)}`;w.length>0&&r.push($(v({},s),{text:w})),p.length>0&&o.push({kind:"text",op:"delete",paraId:e.paraId,offset:i+u,text:p});}else s.kind==="image"?o.push({kind:"image",op:"delete",paraId:e.paraId,offset:i,drawingId:s.drawingId}):s.kind==="pageBreak"?o.push({kind:"page-break",op:"delete",paraId:e.paraId,offset:i}):r.push(s);i=l;}return {content:He(r),changes:o.sort((s,a)=>bc(a)-bc(s))}}function pn(e,t){let n=[],r=[],o=0,i=false;for(let s of e){let a=$e(s);if(!i&&t<=o+a){if(s.kind==="text"){let l=Math.max(0,t-o);l>0&&n.push($(v({},s),{text:s.text.slice(0,l)})),l<s.text.length&&r.push($(v({},s),{text:s.text.slice(l)}));}else t<=o?r.push(s):n.push(s);i=true;}else i?r.push(s):n.push(s);o+=a;}return {before:He(n),after:He(r)}}function $e(e){return e.kind==="text"?e.text.length:1}function Uo(e){if(!(!Number.isFinite(e)||e===void 0||e<=0))return Math.max(1,Math.round(e*100)/100)}function Nt(e,t){let n=Math.max(0,Math.min(e,t)),r=Math.max(0,Math.max(e,t));return {from:n,to:r}}function bc(e){return "offset"in e&&typeof e.offset=="number"?e.offset:0}function He(e){var n,r,o,i;let t=[];for(let s of e)if(s.kind==="text"){if(s.text.length===0)continue;let a=t[t.length-1];(a==null?void 0:a.kind)==="text"&&Mb(a.format,s.format)&&_a((n=a.hyperlink)!=null?n:null,(r=s.hyperlink)!=null?r:null)&&_a((o=a.marks)!=null?o:null,(i=s.marks)!=null?i:null)?a.text+=s.text:t.push(v({},s));}else t.push(s);return t}function Ft(e){let t=JSON.parse(JSON.stringify(e));return ns(t),t}function Uc(e){return e.kind==="paragraph"?e.paraId:e.tableId}function Nb(e,t,n){let r=be(e,t.paraId),o=be(e,n.paraId);if(!r||!o||r.container!==e.blocks||o.container!==e.blocks)return null;let i=r.index<o.index||r.index===o.index&&t.offset<=n.offset?{start:r,end:o,startOffset:t.offset,endOffset:n.offset}:{start:o,end:r,startOffset:n.offset,endOffset:t.offset};return i.start.index===i.end.index||i.start.paragraph.content.some(s=>s.kind!=="text")||i.end.paragraph.content.some(s=>s.kind!=="text")?null:{blocks:e.blocks.slice(i.start.index,i.end.index+1),startOffset:Math.max(0,Math.min(i.startOffset,Te(i.start.paragraph).length)),endOffset:Math.max(0,Math.min(i.endOffset,Te(i.end.paragraph).length))}}function Tb(e){return e.slice(1,-1).some(t=>t.kind==="table"||t.content.some(n=>n.kind!=="text"))}function Kc(e,t){let n=Ft(t),r=new Set(_e(e).map(c=>c.paraId)),o=new Set,i=new Set;Ko(e.blocks,c=>{if(c.kind==="table")i.add(c.tableId);else for(let u of c.content)(u.kind==="image"||u.kind==="drawing")&&o.add(u.drawingId);});let s=Date.now()>>>0,a=()=>{let c="";do s=s+1>>>0,c=s.toString(16).toUpperCase().padStart(8,"0");while(r.has(c));return r.add(c),c},l=(c,u)=>{let f=1;for(;c.has(`${u}-${f}`);)f+=1;let p=`${u}-${f}`;return c.add(p),p};return Ko(n,c=>{if(c.kind==="table"){c.tableId=l(i,"coco-clipboard-table");return}c.paraId=a();for(let u of c.content)if((u.kind==="image"||u.kind==="drawing")&&(u.drawingId=l(o,"coco-clipboard-drawing")),u.kind==="drawing"&&u.paragraphs)for(let f of u.paragraphs)f.paraId=a();}),ns(n),n}function Pb(e){let t=new Set;for(let r of [e.blocks,...e.headers.map(o=>o.blocks),...e.footers.map(o=>o.blocks)])Ko(r,o=>{o.kind==="table"&&t.add(o.tableId);});let n=1;for(;t.has(`coco-table-${n}`);)n+=1;return `coco-table-${n}`}function Ko(e,t){for(let n of e)if(t(n),n.kind==="table")for(let r of n.rows)for(let o of r.cells)Ko(o.blocks,t);}function ns(e){for(let t of e)if(t.kind==="table")for(let n of t.rows)for(let r of n.cells)ns(r.blocks),r.paragraphs=Cr(r.blocks);}function Cr(e){return e.flatMap(t=>t.kind==="paragraph"?[t]:t.rows.flatMap(n=>n.cells.flatMap(r=>Cr(r.blocks))))}function jo(e){return e.reduce((t,n)=>t+$e(n),0)}function Mb(e,t){return JSON.stringify(e!=null?e:null)===JSON.stringify(t!=null?t:null)}function Rb(e){var o,i,s;let t=(o=e.target)==null?void 0:o.trim(),n=(i=e.anchor)==null?void 0:i.trim().replace(/^#/,""),r=(s=e.tooltip)==null?void 0:s.trim();return !t&&!n?null:v(v(v({},t?{target:t}:{}),n?{anchor:n}:{}),r?{tooltip:r}:{})}function _a(e,t){return JSON.stringify(e)===JSON.stringify(t)}function _c(e,t){let n=0,r=null;for(let o of e){let i=$e(o);if(o.kind==="text"){if(t>=n&&t<=n+i)return o.format;r=o.format;}n+=i;}return r}function Ab(e,t){let n=0;for(;n<e.length&&n<t.length&&e.charCodeAt(n)===t.charCodeAt(n);)n+=1;let r=e.length,o=t.length;for(;r>n&&o>n&&e.charCodeAt(r-1)===t.charCodeAt(o-1);)r-=1,o-=1;return {offset:n,deletedText:e.slice(n,r),insertedText:t.slice(n,o)}}var qc=/^data:(image\/(?:png|jpeg|gif|webp));base64,([a-z0-9+/]*={0,2})$/i,Lb=new Set(["http:","https:","mailto:","tel:"]);function Ar(e){let t=e.trim();return qc.test(t)?t:null}function Xc(e){let t=Ar(e),n=t?qc.exec(t):null;if(!n)throw new Error("Only embedded PNG, JPEG, GIF, or WebP images are supported");let r=atob(n[2]),o=new Uint8Array(r.length);for(let i=0;i<r.length;i++)o[i]=r.charCodeAt(i);return new Blob([o],{type:n[1].toLowerCase()})}function Lr(e,t){if(e)try{let n=new URL(e.trim());if(Lb.has(n.protocol))return n.href}catch(n){}return t?`#${encodeURIComponent(t)}`:"#"}var Yc=260;function ou(){Pn("coco-word-native-document"),Pn("coco-word-native-page"),Pn("coco-word-native-page-body"),Pn("coco-word-native-story"),Pn("coco-word-native-p"),Pn("coco-word-native-drawing"),Pn("coco-word-native-table");}function iu(e){var s,a;let t=document.createElement("coco-word-native-document");t.contentEditable="true",t.spellcheck=false,Wb(e)&&t.classList.add("uses-natural-paragraph-flow"),Fb(e)&&t.classList.add("uses-compact-latin-tables"),Db(e)&&t.classList.add("uses-rowspan-table-group-splitting");let n=Oo((s=e.defaults)==null?void 0:s.run).cssText;n.length>0&&t.setAttribute("style",n);for(let l of e.headers)t.appendChild(nu(l));let r=Bb(e),o=r!==void 0&&ds(e);for(let l of e.blocks)t.appendChild(Or(l,{implicitGridForParagraphs:o,implicitGridLinePitch:r})),Pw(l)&&(o=false);for(let l of e.footers)t.appendChild(nu(l));if(t.querySelector(".coco-word-comment, .coco-word-revision-insert, .coco-word-revision-delete, .coco-word-revision-format, [data-revision-id]")!==null)if(t.classList.add("has-annotation-rail"),((a=e.pageLayout)==null?void 0:a.width)!==void 0)t.style.minWidth=`${gs(e.pageLayout.width)+Yc}px`;else {let l=`calc(100% + ${Yc}px)`;t.style.width=l,t.style.minWidth=l;}return t}function Wb(e){if(e.blocks.length>300)return false;let t=[e.pageLayout,...e.sections.map(n=>n.pageLayout)].filter(n=>n!==void 0);return t.length===0?false:t.every(n=>n.docGrid===void 0)?true:!ds(e)}function Bb(e){var n,r;return (r=(n=[e.pageLayout,...e.sections.map(o=>o.pageLayout)].filter(o=>o!==void 0).find(o=>{var i;return ((i=o.docGrid)==null?void 0:i.linePitch)!==void 0}))==null?void 0:n.docGrid)==null?void 0:r.linePitch}function Fb(e){return e.blocks.some(t=>t.kind==="table")&&!ds(e)}function Db(e){return e.blocks.filter(n=>n.kind==="table").length<10?false:Hb(e)<=5}function Hb(e){return e.blocks.reduce((t,n)=>t+au(n),0)}function au(e){return e.kind==="paragraph"?e.content.filter(t=>t.kind==="image"||t.kind==="drawing").length:e.rows.reduce((t,n)=>t+n.cells.reduce((r,o)=>r+o.blocks.reduce((i,s)=>i+au(s),0),0),0)}function ds(e){let t=0,n=0;for(let r of e.blocks.slice(0,160)){for(let o of Ob(r))for(let i of o)/\s/.test(i)||(n++,/[\u3400-\u9FFF\uF900-\uFAFF]/.test(i)&&t++);if(n>=1200)break}return t>=24&&t/Math.max(n,1)>=.08}function Ob(e){if(e.kind==="paragraph")return e.content.filter(n=>n.kind==="text").map(n=>n.text);let t=[];for(let n of e.rows)for(let r of n.cells)for(let o of r.paragraphs)t.push(...o.content.filter(i=>i.kind==="text").map(i=>i.text));return t}function su(e,t){let n=t.pageLayout;if(!n||e.dataset.paginated==="true")return;e.dataset.paginated="true",e.classList.add("is-paginated");let r=Array.from(e.children),o=r.filter(y=>y instanceof HTMLElement&&y.tagName.toLowerCase()==="coco-word-native-story"&&y.dataset.storyKind==="header"),i=r.filter(y=>y instanceof HTMLElement&&y.tagName.toLowerCase()==="coco-word-native-story"&&y.dataset.storyKind==="footer"),s=r.filter(y=>y instanceof HTMLElement&&y.tagName.toLowerCase()!=="coco-word-native-story");e.replaceChildren();let a=new Map,l=0,c=Fr(t,l,n),u=(y=l)=>{var C;let k=((C=a.get(y))!=null?C:0)+1;return a.set(y,k),l=y,c=Fr(t,y,n),Cu(e,t,c,o,i,e.children.length+1,y,k)},f=u(),p=f.querySelector("coco-word-native-page-body"),w=()=>Math.max(120,Math.round(p.getBoundingClientRect().height)||vw(c)),b=()=>(f=u(),p=f.querySelector("coco-word-native-page-body"),p),g=y=>{var N,L,D;if(y===l||p.children.length>0)return;let k=(N=a.get(l))!=null?N:0;k>1?a.set(l,k-1):a.delete(l);let C=((L=a.get(y))!=null?L:0)+1;a.set(y,C),l=y,c=Fr(t,y,n),Iu(f,t,c,o,i,Number((D=f.dataset.pageNumber)!=null?D:"1"),y,C);},h=(y,k)=>{var V;let C=(V=qb(y,t))!=null?V:l;p.children.length===0&&g(C),ps(y)&&p.children.length>0&&(b(),g(C)),p.appendChild(y);let N=gw(y);N&&Br(f);let L=y.querySelector(".coco-word-page-break")!==null;if(p.scrollHeight>w()){let ee=_b(p,y);if(ee){if(y.matches("coco-word-native-table")){if(p.removeChild(y),rs(y,p,w,b)){N||Br(f);let re=Zo(y,t),we=Jc(y,t);we!==null&&(l=we),(L||re)&&Qc(b,re);return}p.appendChild(y);}p.removeChild(y),p.removeChild(ee),b(),g(C),p.appendChild(ee),p.appendChild(y),y.matches("coco-word-native-table")&&p.scrollHeight>w()&&(p.removeChild(y),rs(y,p,w,b)||p.appendChild(y));}else {p.removeChild(y);let pe=Xb(y,p,w);pe?(b(),g(C),p.appendChild(pe)):rs(y,p,w,b)||(b(),g(C),p.appendChild(y));}}else y.matches("coco-word-native-table")&&Zb(y,p,w,b,k);N||Br(f);let D=Zo(y,t),W=Jc(y,t);W!==null&&(l=W),(L||D)&&Qc(b,D);};for(let y=0;y<s.length;y+=1)h(s[y],y===s.length-1);yu(e),vu(e),ku(e),Au(e,t),mn(e);}function lu(e,t,n){let r=e.querySelector(`coco-word-native-page-body coco-word-native-p[data-para-id="${n}"]`),o=r==null?void 0:r.closest("coco-word-native-page");if(!r||!o||!t.pageLayout)return false;let i=en(e),s=i.indexOf(o);if(s<0)return false;let a=Ub(e),l=false,c=false;for(let u=s;u<i.length;u+=1){let f=i[u],p=Ht(f);if(p)for(;Xo(p);){if(Vb(e,t,f,i[u+1],a)){i=en(e),l=true;continue}let w=zb(p);if(w.length===0||w.length>=p.children.length)break;let b=i[u+1];(!b||Yo(f,b,t))&&(b=cu(e,t,f,b,a),i=en(e),c=true);let g=Ht(b);if(!g)break;for(let h of [...w].reverse())g.insertBefore(h,g.firstChild);l=true;}}i=en(e),s=Math.max(0,Math.min(s,Math.max(0,i.length-1))-1);for(let u=s;u<i.length-1;u+=1){let f=i[u],p=i[u+1],w=Ht(f),b=Ht(p);if(!(!w||!b||Yo(f,p,t))){for(;Gb(w,b);)l=true;for(;;){let g=us(b);if(g.length===0||!du(w,g[0],t))break;for(let h of g)w.appendChild(h);if(Xo(w,8)){for(let h of [...g].reverse())b.insertBefore(h,b.firstChild);if(g.length>1){let h=g[0];if(w.appendChild(h),!Xo(w,8)){l=true;continue}b.insertBefore(h,b.firstChild);}break}l=true;}Su(p)&&(p.remove(),i=en(e),u-=1,c=true);}}return l?(yu(e),vu(e),ku(e),c&&Kb(e,t,a),Au(e,t),mn(e),true):false}function cs(e,t,n){let r={overflowPx:0,canBackfillPrevious:false,canBackfillNext:false},o=e.querySelector(`coco-word-native-page-body coco-word-native-p[data-para-id="${n}"]`),i=o==null?void 0:o.closest("coco-word-native-page"),s=en(e),a=i?s.indexOf(i):-1;if(!o||!i||a<0)return r;let l=Ht(i);if(!l)return r;let c=Math.max(120,Math.round(l.getBoundingClientRect().height)),u=Math.max(0,l.scrollHeight-c),f=s[a-1],p=f?Ht(f):null,w=!!(f&&p&&us(l).some(y=>uu(y,n))&&Zc(f,i,p,l,t)),b=s[a+1],g=b?Ht(b):null,h=!!(b&&g&&Zc(i,b,l,g,t));return {overflowPx:u,canBackfillPrevious:w,canBackfillNext:h}}function Zc(e,t,n,r,o){if(Yo(e,t,o))return false;let i=Math.max(0,Math.round(n.getBoundingClientRect().height)-xu(n));if(i<=0)return false;let s=n.lastElementChild,a=r.firstElementChild;if(s instanceof HTMLElement&&a instanceof HTMLElement&&s.matches("coco-word-native-table")&&a.matches("coco-word-native-table")&&s.dataset.tableId===a.dataset.tableId){let c=Array.from(a.querySelectorAll(":scope > table > tbody > tr")).filter(f=>f.dataset.repeatedHeader!=="true"),u=Hr(c)[0];if(u&&!Rn(u)&&fu(u)<=i+8)return true}let l=us(r);return l.length===0||!du(n,l[0],o)?false:$b(l)<=i+8}function $b(e){return e.reduce((t,n)=>{let r=window.getComputedStyle(n),o=Number.parseFloat(r.marginTop)||0,i=Number.parseFloat(r.marginBottom)||0;return t+n.getBoundingClientRect().height+o+i},0)}function Ot(e,t,n){let r=e.querySelector(`coco-word-native-page-body coco-word-native-p[data-para-id="${n}"]`),o=r==null?void 0:r.closest("coco-word-native-page"),i=en(e),s=o?i.indexOf(o):-1;if(s<0)return false;let a=false;for(let l of t.blocks){if(l.kind!=="table")continue;let c=Array.from(e.querySelectorAll(`coco-word-native-table[data-table-id="${l.tableId}"]`)),u=c[0],f=u==null?void 0:u.closest("coco-word-native-page");if(!(!u||!f||i.indexOf(f)<s)){u.replaceWith(Bu(l));for(let p of c.slice(1))p.remove();a=true;}}return a}function en(e){return Array.from(e.children).filter(t=>t instanceof HTMLElement&&t.tagName.toLowerCase()==="coco-word-native-page")}function Ht(e){return e.querySelector(":scope > coco-word-native-page-body")}function Xo(e,t=1){let n=Math.max(120,Math.round(e.getBoundingClientRect().height));return e.scrollHeight>n+t}function zb(e){let t=e.lastElementChild;if(!(t instanceof HTMLElement))return [];let n=[t],r=t.previousElementSibling;return r instanceof HTMLElement&&r.matches('coco-word-native-p[data-keep-next="true"]')&&n.unshift(r),n}function us(e){let t=e.firstElementChild;if(!(t instanceof HTMLElement))return [];let n=[t],r=t.nextElementSibling;return t.matches('coco-word-native-p[data-keep-next="true"]')&&r instanceof HTMLElement&&n.push(r),n}function Vb(e,t,n,r,o){let i=Ht(n),s=i==null?void 0:i.lastElementChild;if(!(s instanceof HTMLElement)||!s.matches("coco-word-native-table"))return false;let a=s.querySelector(":scope > table"),l=a==null?void 0:a.querySelector(":scope > tbody");if(!a||!l)return false;let u=Array.from(l.children).filter(ei).filter(C=>C.dataset.repeatedHeader!=="true"),f=Hr(u);if(f.length<2)return false;let p=f[f.length-1];if(Rn(p))return false;let w=r;(!w||Yo(n,w,t))&&(w=cu(e,t,n,w,o));let b=Ht(w);if(!b)return false;let g=s.dataset.tableId,h=Array.from(b.children).find(C=>C instanceof HTMLElement&&C.matches("coco-word-native-table")&&C.dataset.tableId===g);if(!h){h=Kn(s,a),b.insertBefore(h,b.firstChild);let C=h.querySelector(":scope > table > tbody");C&&Wr(C,jb(e,g));}let y=h.querySelector(":scope > table > tbody");if(!y)return false;let k=Array.from(y.children).find(C=>C instanceof HTMLTableRowElement&&C.dataset.repeatedHeader!=="true");Dr(l,p);for(let C of p)y.insertBefore(C,k!=null?k:null);return true}function Gb(e,t){var c,u;let n=e.lastElementChild,r=t.firstElementChild;if(!(n instanceof HTMLElement)||!(r instanceof HTMLElement)||!n.matches("coco-word-native-table")||!r.matches("coco-word-native-table")||n.dataset.tableId!==r.dataset.tableId)return false;let o=n.querySelector(":scope > table > tbody"),i=r.querySelector(":scope > table > tbody");if(!o||!i)return false;let s=Array.from(i.children).filter(ei).filter(f=>f.dataset.repeatedHeader!=="true"),a=Hr(s)[0];if(!a||Rn(a))return false;let l=(u=(c=a[a.length-1])==null?void 0:c.nextElementSibling)!=null?u:null;if(_n(o,a),Xo(e,8)){for(let f of a)i.insertBefore(f,l);return false}return i.querySelector('tr:not([data-repeated-header="true"])')===null&&r.remove(),true}function jb(e,t){if(!t)return [];let n=Array.from(e.querySelectorAll("coco-word-native-table")).find(r=>r.dataset.tableId===t&&r.querySelector('tr[data-repeat-header="true"]'));return n?Array.from(n.querySelectorAll('tr[data-repeat-header="true"]')):[]}function Yo(e,t,n){if(e.dataset.sectionIndex!==t.dataset.sectionIndex)return true;let r=Ht(e),o=Ht(t),i=r==null?void 0:r.lastElementChild,s=o==null?void 0:o.firstElementChild;if(s instanceof HTMLElement&&ps(s))return true;if(!(i instanceof HTMLElement))return false;if(i.querySelector(".coco-word-page-break"))return true;let a=Zo(i,n);return a!==null&&a!=="continuous"&&a!=="nextColumn"}function du(e,t,n){if(ps(t))return false;let r=e.lastElementChild;if(!(r instanceof HTMLElement))return true;if(r.querySelector(".coco-word-page-break"))return false;let o=Zo(r,n);return o===null||o==="continuous"||o==="nextColumn"}function Ub(e){var o;let t=new Set,n=[],r=[];for(let i of Array.from(e.querySelectorAll(":scope > coco-word-native-page > coco-word-native-story"))){let s=i.dataset.storyKind,a=`${s!=null?s:""}:${(o=i.dataset.partName)!=null?o:""}`;t.has(a)||(t.add(a),s==="header"&&n.push(i),s==="footer"&&r.push(i));}return {headers:n,footers:r}}function cu(e,t,n,r,o){let i=en(e),s=i.indexOf(n),a=fn(n.dataset.sectionIndex,0),l=i.slice(0,s+1).filter(u=>fn(u.dataset.sectionIndex,0)===a).length+1,c=Cu(e,t,Fr(t,a,t.pageLayout),o.headers,o.footers,s+2,a,l);return r&&e.insertBefore(c,r),c}function Kb(e,t,n){for(let r of en(e)){let o=fn(r.dataset.pageNumber,1),i=fn(r.dataset.sectionIndex,0),s=fn(r.dataset.sectionPageNumber,1);Iu(r,t,Fr(t,i,t.pageLayout),n.headers,n.footers,o,i,s);}}function ps(e){return e.matches('coco-word-native-p[data-page-break-before="true"]')}function _b(e,t){let n=t.previousElementSibling;return !(n instanceof HTMLElement)||!n.matches('coco-word-native-p[data-keep-next="true"]')?null:n.previousElementSibling instanceof HTMLElement?n:null}function Zo(e,t){var o;if(!e.matches('coco-word-native-p[data-section-break="true"]'))return null;let n=e.dataset.paraId;if(!n)return "nextPage";let r=t.sections.find(i=>i.lastParaId===n);return (o=r==null?void 0:r.type)!=null?o:"nextPage"}function Jc(e,t){let n=t.sections.find(r=>r.lastParaId&&uu(e,r.lastParaId));return n?Math.min(n.sectionIndex+1,Math.max(0,t.sections.length-1)):null}function qb(e,t){if(t.sections.length===0)return null;let n=pu(e);if(n.length===0)return null;let r=t.sections.find(i=>n.includes(i.firstParaId));if(r)return r.sectionIndex;let o=t.sections.find(i=>n.includes(i.lastParaId));return o?o.sectionIndex:null}function uu(e,t){return pu(e).includes(t)}function pu(e){if(e.matches("coco-word-native-p")){let t=e.dataset.paraId;return t?[t]:[]}return Array.from(e.querySelectorAll("coco-word-native-p")).map(t=>t.dataset.paraId).filter(t=>t!==void 0&&t.length>0)}function Qc(e,t){var i;if(t==="continuous"||t==="nextColumn")return;let r=e().closest("coco-word-native-page"),o=Number((i=r==null?void 0:r.getAttribute("data-page-number"))!=null?i:"0");t==="oddPage"&&o%2===0&&e(),t==="evenPage"&&o%2===1&&e();}function Xb(e,t,n){if(!e.matches("coco-word-native-p")||e.dataset.keepLines==="true"||e.dataset.pageBreakBefore==="true"||e.querySelector("img, coco-word-native-drawing, coco-word-native-table, .coco-word-page-break, .coco-word-tab-row"))return null;let r=Tt(e);if(r<2)return null;let o=null,i=1,s=r-1;for(;i<=s;){let a=Math.floor((i+s)/2),l=mu(e,a);if(!l||Tt(l.head)===0||Tt(l.tail)===0){s=a-1;continue}t.appendChild(l.head),t.scrollHeight<=n()?((o==null?void 0:o.head.parentElement)===t&&t.removeChild(o.head),o=l,i=a+1):(t.removeChild(l.head),s=a-1);}return !o||o.head.parentElement!==t?null:o.tail}function rs(e,t,n,r){if(e.tagName.toLowerCase()!=="coco-word-native-table")return false;let o=e.querySelector(":scope > table"),i=o==null?void 0:o.querySelector(":scope > tbody"),s=i?Array.from(i.children).filter(ei):[],a=Hr(s);if(!o||a.length<2)return false;let l=t,c=Kn(e,o),u=c.querySelector("tbody"),f=s.filter(b=>b.dataset.repeatHeader==="true"),p=Yb(a,f),w=0;l.appendChild(c);for(let b of a){let g=Rn(b);if(!g&&w>=p&&(l=r(),c=Kn(e,o),u=c.querySelector("tbody"),l.appendChild(c),Wr(u,f),w=0),_n(u,b),g||(w+=1),l.children.length<=1&&u.children.length<=b.length||l.scrollHeight<=n())continue;Dr(u,b),g||(w=Math.max(0,w-1));let h=Jb(u,b,l,n()),y=h!=null?h:nw(u,b,l,n()),k=y!=null?y:rw(u,b,l,n());if(k){g||(w+=1),l=r(),c=Kn(e,o),u=c.querySelector("tbody"),l.appendChild(c),w=0,Wr(u,f),_n(u,k),g||(w=1);continue}u.children.length===0&&l.removeChild(c),l=r(),c=Kn(e,o),u=c.querySelector("tbody"),l.appendChild(c),w=0,g||Wr(u,f),_n(u,b),g||(w=1);}return true}function Yb(e,t){let n=e.filter(r=>!Rn(r)).length;return t.length===0||n<30?Number.POSITIVE_INFINITY:8}function Zb(e,t,n,r,o){var C;let i=n(),s=i-xu(t),a=fw(e,i);if(s>=a||o&&uw(t,i))return false;let l=e.querySelector(":scope > table"),c=l==null?void 0:l.querySelector(":scope > tbody"),u=c?Array.from(c.children).filter(ei):[],f=Hr(u);if(!l||!c||f.length<4)return false;let p=u.filter(N=>N.dataset.repeatHeader==="true"),w=s,b=0,g=[];for(;f.length>1&&w+b<a;){let N=f.pop();if(!N||Rn(N))break;b+=fu(N),Dr(c,N),g.unshift(N);}if(g.length===0)return false;let h=r(),y=Kn(e,l),k=y.querySelector("tbody");h.appendChild(y),Rn((C=g[0])!=null?C:[])||Wr(k,p);for(let N of g)_n(k,N);return true}function fu(e){return e.reduce((t,n)=>t+n.getBoundingClientRect().height,0)}function Jb(e,t,n,r){if(!e.closest("coco-word-native-document.uses-rowspan-table-group-splitting")||t.length<2||t.some(i=>i.dataset.repeatHeader==="true"||i.dataset.cantSplit==="true"))return null;let o=null;for(let i=1;i<t.length;i+=1){let s=Qb(t,i);if(s){o&&Dr(e,o.head);for(let a of s.head)e.appendChild(a);if(n.scrollHeight<=r)o=s;else {Dr(e,s.head),o&&_n(e,o.head);break}}}return o?o.tail:null}function Qb(e,t){if(t<=0||t>=e.length)return null;let n=ew(e),r=e.slice(0,t).map(s=>s.cloneNode(true)),o=e.slice(t).map(s=>s.cloneNode(true)),i=n.filter(s=>s.row<t&&s.row+s.rowSpan>t);if(i.length===0)return null;for(let s of i){let a=r[s.row],l=a==null?void 0:a.cells[s.cellIndex];l&&(l.rowSpan=t-s.row);let c=s.cell.cloneNode(false);c.rowSpan=s.row+s.rowSpan-t,c.colSpan=s.colSpan,c.dataset.rowFragmentContinuation="true",c.classList.add("is-rowspan-continuation"),tw(o[0],c,s.column,n,t);}return {head:r,tail:o}}function ew(e){var r,o;let t=[],n=[];for(let i=0;i<e.length;i+=1){let s=e[i],a=0;for(let l=0;l<s.cells.length;l+=1){for(;((r=n[a])!=null?r:0)>i;)a+=1;let c=s.cells[l],u=Math.max(1,c.colSpan),f=Math.max(1,c.rowSpan);t.push({row:i,cellIndex:l,column:a,colSpan:u,rowSpan:f,cell:c});for(let p=0;p<u;p+=1)n[a+p]=Math.max((o=n[a+p])!=null?o:0,i+f);a+=u;}}return t}function tw(e,t,n,r,o){let s=r.filter(l=>l.row===o).sort((l,c)=>l.column-c.column).find(l=>l.column>n),a=s?e.cells[s.cellIndex]:null;e.insertBefore(t,a!=null?a:null);}function nw(e,t,n,r){if(t.length!==1)return null;let o=t[0];if(!lw(o))return null;let i=null,s=0,a=1;for(let l=0;l<8;l+=1){let c=(s+a)/2,u=dw(o,c);if(!u){a=c;continue}e.appendChild(u.head),n.scrollHeight<=r?((i==null?void 0:i.head.parentElement)===e&&e.removeChild(i.head),i=u,s=c):(e.removeChild(u.head),a=c);}return !i||i.head.parentElement!==e?null:[i.tail]}function rw(e,t,n,r){if(t.length!==1)return null;let o=t[0];if(!ow(o))return null;let i=null,s=0,a=1;for(let l=0;l<9;l+=1){let c=(s+a)/2,u=iw(o,c);if(!u){a=c;continue}e.appendChild(u.head),n.scrollHeight<=r?((i==null?void 0:i.head.parentElement)===e&&e.removeChild(i.head),i=u,s=c):(e.removeChild(u.head),a=c);}return !i||i.head.parentElement!==e?null:[i.tail]}function ow(e){if(e.dataset.repeatHeader==="true"||e.dataset.cantSplit==="true"||Array.from(e.cells).some(n=>n.rowSpan>1||n.colSpan>1))return false;let t=Array.from(e.cells);return t.some(n=>gu(n))?false:bu(e)?t.some(n=>is(n)):t.every(n=>is(n))}function iw(e,t){let n=tu(e),r=tu(e);for(let o of Array.from(e.cells)){let i=aw(o,t);if(!i)return null;n.appendChild(i.head),r.appendChild(i.tail);}return {head:n,tail:r}}function aw(e,t){if(!is(e))return wu(e);let n=Array.from(e.children).find(l=>l instanceof HTMLElement&&l.tagName.toLowerCase()==="coco-word-native-p");if(!n)return null;let r=Tt(n),o=Math.max(1,Math.min(r-1,Math.round(r*t))),i=mu(n,o);if(!i||Tt(i.head)===0||Tt(i.tail)===0)return null;let s=e.cloneNode(false),a=e.cloneNode(false);return s.appendChild(i.head),a.appendChild(i.tail),{head:s,tail:a}}function mu(e,t){let n=Tt(e);if(!Number.isInteger(t)||t<=0||t>=n)return null;let r=e.cloneNode(false),o=e.cloneNode(false);return hu(Array.from(e.childNodes),t,r,o),r.dataset.splitFragment="head",o.dataset.splitFragment="tail",{head:r,tail:o}}function hu(e,t,n,r){let o=t;for(let i of e){let s=Tt(i);if(s===0){o>0?n.appendChild(i.cloneNode(true)):r.appendChild(i.cloneNode(true));continue}if(s<=o){n.appendChild(i.cloneNode(true)),o-=s;continue}if(o<=0){r.appendChild(i.cloneNode(true));continue}sw(i,o,n,r),o=0;}}function sw(e,t,n,r){var s;if(e.nodeType===Node.TEXT_NODE){let a=(s=e.textContent)!=null?s:"";n.appendChild(document.createTextNode(a.slice(0,t))),r.appendChild(document.createTextNode(a.slice(t)));return}if(!(e instanceof HTMLElement))return;let o=e.cloneNode(false),i=e.cloneNode(false);hu(Array.from(e.childNodes),t,o,i),Tt(o)>0&&n.appendChild(o),Tt(i)>0&&r.appendChild(i);}function Tt(e){var t,n;return e.nodeType===Node.TEXT_NODE?(n=(t=e.textContent)==null?void 0:t.length)!=null?n:0:Array.from(e.childNodes).reduce((r,o)=>r+Tt(o),0)}function lw(e){if(e.dataset.repeatHeader==="true"||e.dataset.cantSplit==="true"||Array.from(e.cells).some(n=>n.rowSpan>1||n.colSpan>1))return false;let t=Array.from(e.cells);return t.some(n=>gu(n))?false:bu(e)?t.some(n=>os(n)):t.every(n=>os(n))}function dw(e,t){let n=eu(e),r=eu(e);for(let o of Array.from(e.cells)){let i=cw(o,t);if(!i)return null;n.appendChild(i.head),r.appendChild(i.tail);}return {head:n,tail:r}}function cw(e,t){if(!os(e))return wu(e);let n=Array.from(e.childNodes).filter(s=>s instanceof HTMLElement);if(n.length<2)return null;let r=Math.max(1,Math.min(n.length-1,Math.round(n.length*t))),o=e.cloneNode(false),i=e.cloneNode(false);for(let s=0;s<n.length;s+=1){let a=n[s].cloneNode(true);s<r?o.appendChild(a):i.appendChild(a);}return {head:o,tail:i}}function gu(e){return e.querySelector("coco-word-native-drawing, coco-word-native-table, .coco-word-native-field, .coco-word-page-break, .coco-word-comment, .coco-word-revision-delete, .coco-word-revision-insert")!==null}function bu(e){var t;return ((t=e.closest("coco-word-native-document"))==null?void 0:t.classList.contains("uses-natural-paragraph-flow"))===true}function os(e){return Array.from(e.childNodes).filter(t=>t instanceof HTMLElement).length>=2}function is(e){if(e.querySelector("img"))return false;let t=Array.from(e.children).filter(n=>n instanceof HTMLElement);return t.length===1&&t[0].tagName.toLowerCase()==="coco-word-native-p"&&Tt(t[0])>1}function wu(e){let t=e.cloneNode(true),n=e.cloneNode(false);return n.dataset.rowFragmentStatic="true",{head:t,tail:n}}function eu(e){let t=e.cloneNode(false);return t.dataset.rowFragment="block",t.style.removeProperty("height"),t.style.removeProperty("--coco-word-row-height"),delete t.dataset.heightRule,t}function tu(e){let t=e.cloneNode(false);return t.dataset.rowFragment="text",t.style.removeProperty("height"),t.style.removeProperty("--coco-word-row-height"),delete t.dataset.heightRule,t}function uw(e,t){return e.scrollHeight>t+1?false:pw(e)<=t*.75}function pw(e){let t=0;for(let n of Array.from(e.children)){if(!(n instanceof HTMLElement))continue;let r=n.getBoundingClientRect(),o=window.getComputedStyle(n),i=Number.parseFloat(o.marginTop)||0,s=Number.parseFloat(o.marginBottom)||0;t+=r.height+i+s;}return t}function xu(e){let t=e.getBoundingClientRect(),n=0;for(let r of Array.from(e.children)){if(!(r instanceof HTMLElement))continue;let o=r.getBoundingClientRect(),i=window.getComputedStyle(r),s=Number.parseFloat(i.marginBottom)||0;n=Math.max(n,o.bottom-t.top+s);}return n}function fw(e,t){if(t<700)return 0;let n=e.querySelectorAll("tr").length,r=e.closest("coco-word-native-document.uses-compact-latin-tables")?8:4;return n<r?0:96}function Hr(e){let t=[],n=0,r=0;for(let o=0;o<e.length;o++){r=Math.max(r,o);for(let i of Array.from(e[o].cells))r=Math.max(r,o+Math.max(1,i.rowSpan)-1);o===r&&(t.push(e.slice(n,o+1)),n=o+1);}return n<e.length&&t.push(e.slice(n)),t}function _n(e,t){for(let r of t)e.appendChild(r);let n=e.closest("coco-word-native-table");n&&fs(n);}function Rn(e){var t;return ((t=e[0])==null?void 0:t.dataset.repeatHeader)==="true"}function Wr(e,t){for(let r of t){let o=r.cloneNode(true);o.dataset.repeatedHeader="true",e.appendChild(o);}let n=e.closest("coco-word-native-table");n&&fs(n);}function Dr(e,t){for(let n of t)n.parentElement===e&&e.removeChild(n);}function Kn(e,t){let n=e.cloneNode(false);n.classList.add("is-table-fragment");let r=t.cloneNode(false),o=t.querySelector(":scope > colgroup");return o&&r.appendChild(o.cloneNode(true)),r.appendChild(document.createElement("tbody")),n.appendChild(r),n}function fs(e){e.contentEditable="true";for(let t of Array.from(e.querySelectorAll("td, th")))t.contentEditable="true";for(let t of Array.from(e.querySelectorAll("coco-word-native-p")))t.contentEditable="true",t.childNodes.length===0&&t.appendChild(document.createTextNode(""));}function yu(e){for(;;){let t=Array.from(e.querySelectorAll(":scope > coco-word-native-page"));if(t.length<2)return;let n=t[t.length-1];if(!mw(n))return;let r=t[t.length-2],o=r.querySelector(":scope > coco-word-native-page-body"),i=n.querySelector(":scope > coco-word-native-page-body"),s=n.querySelector(":scope > .coco-word-native-page-overlay"),a=n.querySelector(":scope > .coco-word-native-page-behind-layer");if(!o||!i||!s&&!a)return;if(a){let l=as(r,"behind");for(let c of Array.from(a.children))l.appendChild(c);}if(s){let l=as(r,"front");for(let c of Array.from(s.children))l.appendChild(c);}for(let l of Array.from(i.children))o.appendChild(l);n.remove();}}function vu(e){for(let t of Array.from(e.querySelectorAll("coco-word-native-page")))Su(t)&&t.remove();}function Su(e){var r,o,i,s;let t=e.querySelector(":scope > coco-word-native-page-body");return !t||t.children.length>0?false:((o=(r=e.querySelector(":scope > .coco-word-native-page-overlay"))==null?void 0:r.children.length)!=null?o:0)+((s=(i=e.querySelector(":scope > .coco-word-native-page-behind-layer"))==null?void 0:i.children.length)!=null?s:0)===0}function ku(e){let t=new Map;Array.from(e.querySelectorAll(":scope > coco-word-native-page")).forEach((r,o)=>{var a;let i=fn(r.dataset.sectionIndex,0),s=((a=t.get(i))!=null?a:0)+1;t.set(i,s),r.dataset.pageNumber=String(o+1),r.dataset.sectionPageNumber=String(s);});}function mw(e){var s,a;let t=e.querySelector(":scope > coco-word-native-page-body"),n=e.querySelector(":scope > .coco-word-native-page-overlay"),r=e.querySelector(":scope > .coco-word-native-page-behind-layer"),o=((s=n==null?void 0:n.children.length)!=null?s:0)+((a=r==null?void 0:r.children.length)!=null?a:0);if(!t||o===0)return false;let i=Array.from(t.children).filter(l=>l instanceof HTMLElement);return i.length===0?false:i.every(l=>{var c;return l.matches("coco-word-native-p.is-flow-empty")&&((c=l.textContent)!=null?c:"").trim().length===0&&l.getBoundingClientRect().height<=1})}function ei(e){return e instanceof HTMLTableRowElement}function Br(e){let t=new Set,n=Array.from(e.querySelectorAll(':scope .is-absolute-anchor:not([data-page-layer-anchor="true"])'));for(let r of n){if(!Eu(r))continue;let o=r.closest("coco-word-native-p");o&&t.add(o);let i=r.closest("coco-word-native-story");i!=null&&i.dataset.storyKind&&(r.dataset.sourceStoryKind=i.dataset.storyKind),i!=null&&i.dataset.partName&&(r.dataset.sourcePartName=i.dataset.partName),r.dataset.pageLayerAnchor="true";let s=r.dataset.wrap==="behind"?"behind":"front";r.dataset.pageLayer=s,r.classList.add("is-page-layer-anchor"),as(e,s).appendChild(r);}for(let r of t)r.classList.toggle("is-flow-empty",!bw(r));hw(e);}function as(e,t){let n=t==="behind"?"coco-word-native-page-behind-layer":"coco-word-native-page-overlay",r=e.querySelector(`:scope > .${n}`);if(r)return r;let o=document.createElement("div");if(o.className=n,o.contentEditable="false",t==="behind"){let i=Array.from(e.children).find(s=>s.tagName.toLowerCase()!=="coco-word-native-story");e.insertBefore(o,i!=null?i:e.firstChild);}else e.appendChild(o);return o}function hw(e){var t,n;(t=e.querySelector(":scope > .coco-word-native-page-behind-layer:empty"))==null||t.remove(),(n=e.querySelector(":scope > .coco-word-native-page-overlay:empty"))==null||n.remove();}function Eu(e){let t=e.dataset.positionVerticalRelativeFrom,n=e.dataset.positionHorizontalRelativeFrom;return ss(t||n)}function ss(e){return e==="page"||e==="margin"}function gw(e){var n;if(!e.matches("coco-word-native-p")||((n=e.textContent)!=null?n:"").trim().length>0)return false;let t=Array.from(e.children);return t.length===0?false:t.every(r=>r instanceof HTMLElement&&r.classList.contains("is-absolute-anchor")&&Eu(r))}function bw(e){var t;if(((t=e.textContent)!=null?t:"").trim().length>0)return true;for(let n of Array.from(e.children))if(n instanceof HTMLElement&&!(n.dataset.pageLayerAnchor==="true"||n.classList.contains("is-page-layer-anchor"))&&!n.classList.contains("coco-word-tab-marker"))return true;return false}function Cu(e,t,n,r,o,i,s,a){let l=document.createElement("coco-word-native-page");l.dataset.pageNumber=String(i),l.dataset.sectionIndex=String(s),l.dataset.sectionPageNumber=String(a);let c=Mu(t,s,i,a);l.dataset.displayPageNumber=String(c),Ru(l,n);for(let u of Jo(t,"header",i,s,a,r))l.appendChild(Qo(u,c,a));l.appendChild(document.createElement("coco-word-native-page-body"));for(let u of Jo(t,"footer",i,s,a,o))l.appendChild(Qo(u,c,a));return Br(l),e.appendChild(l),l}function Iu(e,t,n,r,o,i,s,a){var u,f;let l=e.querySelector("coco-word-native-page-body");if(!l)return;e.dataset.sectionIndex=String(s),e.dataset.sectionPageNumber=String(a);let c=Mu(t,s,i,a);e.dataset.displayPageNumber=String(c),Ru(e,n),(u=e.querySelector(":scope > .coco-word-native-page-overlay"))==null||u.remove(),(f=e.querySelector(":scope > .coco-word-native-page-behind-layer"))==null||f.remove();for(let p of Array.from(e.querySelectorAll(":scope > coco-word-native-story")))e.removeChild(p);for(let p of Jo(t,"header",i,s,a,r))e.insertBefore(Qo(p,c,a),l);for(let p of Jo(t,"footer",i,s,a,o))e.appendChild(Qo(p,c,a));Br(e);}function mn(e){var t;for(let n of Array.from(e.querySelectorAll(":scope > coco-word-native-page"))){(t=n.querySelector(":scope > .coco-word-native-comment-layer"))==null||t.remove();let r=yw(n);if(r.length>0){let o=document.createElement("div");o.className="coco-word-native-comment-layer",o.contentEditable="false",n.appendChild(o),r.sort((i,s)=>i.top-s.top||i.commentId-s.commentId).forEach((i,s)=>{let a=document.createElement("aside");a.className="coco-word-native-comment-bubble",a.dataset.annotationAnchorTop=String(i.top),a.dataset.commentId=String(i.commentId),a.dataset.commentBody=i.body,i.parentCommentId!==void 0&&Number.isFinite(i.parentCommentId)&&(a.dataset.parentCommentId=String(i.parentCommentId),a.classList.add("coco-word-native-comment-reply")),i.paraId&&(a.dataset.paraId=i.paraId),i.from!==void 0&&(a.dataset.from=String(i.from)),i.to!==void 0&&(a.dataset.to=String(i.to)),a.style.setProperty("--coco-word-comment-index",String(s));let l=document.createElement("div");l.className="coco-word-native-comment-meta",l.textContent=[i.author||`Comment ${i.commentId}`,i.date?Nu(i.date):""].filter(Boolean).join(" \xB7 "),i.parentCommentId!==void 0&&Number.isFinite(i.parentCommentId)&&(l.textContent=`\u56DE\u590D #${i.parentCommentId} \xB7 ${l.textContent}`);let c=document.createElement("div");c.className="coco-word-native-comment-body",c.textContent=i.body||"(empty comment)";let u=document.createElement("div");u.className="coco-word-native-comment-actions";let f=document.createElement("button");f.type="button",f.className="coco-word-native-comment-menu-button",f.dataset.commentMenu="true",f.dataset.commentId=String(i.commentId),f.setAttribute("aria-label","\u6279\u6CE8\u64CD\u4F5C"),f.title="\u6279\u6CE8\u64CD\u4F5C",f.textContent="\u22EF",u.appendChild(f);let p=document.createElement("div");p.className="coco-word-native-comment-menu",p.hidden=true,p.dataset.commentMenuFor=String(i.commentId);for(let[w,b]of [["reply","\u56DE\u590D"],["edit","\u7F16\u8F91"],["delete","\u5220\u9664"]]){let g=document.createElement("button");g.type="button",g.className="coco-word-native-comment-menu-item",g.dataset.commentAction=w,g.dataset.commentId=String(i.commentId),g.textContent=b,p.appendChild(g);}u.appendChild(p),a.appendChild(l),a.appendChild(c),a.appendChild(u),o.appendChild(a);});}ww(n),xw(n);}}function ww(e){var a,l,c,u,f,p,w,b,g,h,y;(a=e.querySelector(":scope > .coco-word-native-revision-layer"))==null||a.remove();let t=new Map,n=e.getBoundingClientRect();for(let k of Array.from(e.querySelectorAll(".coco-word-revision-insert[data-revision-id], .coco-word-revision-delete[data-revision-id], .coco-word-revision-format[data-revision-id], img[data-revision-id], coco-word-native-table[data-revision-id]"))){let C=(l=k.dataset.revisionId)!=null?l:"";if(!C)continue;let N=k.dataset.revisionKind==="format"?"format":k.dataset.revisionKind==="delete"||k.classList.contains("coco-word-revision-delete")?"delete":"insert",L=k.getBoundingClientRect(),D=`${N}:${C}`,W=t.get(D),V=Tu(k);t.set(D,{id:C,kind:N,author:(c=k.dataset.revisionAuthor)!=null?c:"",date:(u=k.dataset.revisionDate)!=null?u:"",text:`${(f=W==null?void 0:W.text)!=null?f:""}${(w=(p=k.dataset.revisionText)!=null?p:k.textContent)!=null?w:""}`,top:(b=W==null?void 0:W.top)!=null?b:Math.max(0,L.top-n.top),paraId:(g=W==null?void 0:W.paraId)!=null?g:V==null?void 0:V.paraId,from:(h=W==null?void 0:W.from)!=null?h:V==null?void 0:V.from,to:(y=V==null?void 0:V.to)!=null?y:W==null?void 0:W.to});}if(t.size===0)return;let r=document.createElement("div");r.className="coco-word-native-revision-layer",r.contentEditable="false",e.appendChild(r);let o=Array.from(t.values()).sort((k,C)=>k.top-C.top||k.id.localeCompare(C.id)),i=new Map;for(let k of o){let C=k.paraId?`paragraph:${k.paraId}`:`position:${Math.round(k.top/48)}`,N=i.get(C);N?N.push(k):i.set(C,[k]);}let s=k=>{let C=document.createElement("aside");C.className=`coco-word-native-revision-bubble is-${k.kind}`,C.dataset.annotationAnchorTop=String(k.top),C.dataset.revisionId=k.id,C.dataset.revisionKind=k.kind,k.paraId&&(C.dataset.paraId=k.paraId),k.from!==void 0&&(C.dataset.from=String(k.from)),k.to!==void 0&&(C.dataset.to=String(k.to));let N=document.createElement("div");N.className="coco-word-native-revision-header";let L=document.createElement("span");L.className="coco-word-native-revision-meta",L.textContent=[k.author||"User",Nu(k.date)].filter(Boolean).join(" \xB7 "),N.appendChild(L),C.appendChild(N);let D=document.createElement("div");D.className="coco-word-native-revision-content",D.textContent=k.text||"(\u7A7A\u5185\u5BB9)",C.appendChild(D);let W=document.createElement("div");W.className="coco-word-native-revision-actions";for(let[V,ee,pe]of [["accept","\u2713","\u63A5\u53D7\u4FEE\u8BA2"],["reject","\xD7","\u62D2\u7EDD\u4FEE\u8BA2"]]){let re=document.createElement("button");re.type="button",re.dataset.revisionAction=V,re.dataset.revisionId=k.id,re.dataset.revisionKind=k.kind,re.textContent=ee,re.setAttribute("aria-label",pe),re.title=pe,re.className=`is-${V}`,W.appendChild(re);}return C.appendChild(W),C};for(let k of i.values()){if(k.length===1){r.appendChild(s(k[0]));continue}let C=document.createElement("section");C.className="coco-word-native-revision-group",C.dataset.annotationAnchorTop=String(k[0].top);let N=k[0].paraId;N&&(C.dataset.paraId=N);let L=document.createElement("button");L.type="button",L.className="coco-word-native-revision-group-toggle",L.dataset.revisionGroupToggle="true",L.setAttribute("aria-expanded","false");let D=document.createElement("strong");D.textContent=`\u672C\u6BB5 ${k.length} \u6761\u4FEE\u8BA2`;let W=k.reduce((re,we)=>(re[we.kind]+=1,re),{insert:0,delete:0,format:0}),V=document.createElement("span");V.textContent=[W.delete?`${W.delete} \u5220`:"",W.insert?`${W.insert} \u589E`:"",W.format?`${W.format} \u683C\u5F0F`:""].filter(Boolean).join(" \xB7 ");let ee=document.createElement("span");ee.className="coco-word-native-revision-group-affordance",ee.textContent="\u5C55\u5F00",L.append(D,V,ee);let pe=document.createElement("div");pe.className="coco-word-native-revision-group-list",pe.hidden=true,k.forEach(re=>pe.appendChild(s(re))),C.append(L,pe),r.appendChild(C);}}function xw(e){let n=Array.from(e.querySelectorAll(":scope > .coco-word-native-comment-layer > .coco-word-native-comment-bubble, :scope > .coco-word-native-revision-layer > .coco-word-native-revision-bubble, :scope > .coco-word-native-revision-layer > .coco-word-native-revision-group")).map(i=>({element:i,anchorTop:Math.max(0,Number(i.dataset.annotationAnchorTop)||0),height:Math.max(44,Math.ceil(i.getBoundingClientRect().height)),top:0}));if(n.length===0)return;n.sort((i,s)=>i.anchorTop-s.anchorTop);let r=0;n.forEach((i,s)=>{i.top=Math.max(i.anchorTop,s===0?0:r+8),r=i.top+i.height;});let o=Math.max(0,Math.ceil(e.getBoundingClientRect().height));if(o>0&&r>o){let i=o;for(let s=n.length-1;s>=0;s-=1){let a=n[s];a.top=Math.min(a.top,i-a.height),i=a.top-8;}if(n[0].top<0){let s=-n[0].top;n.forEach(a=>{a.top+=s;});}}for(let i of n){let s=i.element.classList.contains("coco-word-native-comment-bubble")?"--coco-word-comment-top":"--coco-word-revision-top";i.element.style.setProperty(s,`${Math.round(i.top)}px`);}}function Nu(e){if(!e)return "";let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}function yw(e){var r,o,i,s,a,l,c,u,f,p,w,b,g,h,y,k,C;let t=e.getBoundingClientRect(),n=new Map;for(let N of Array.from(e.querySelectorAll(".coco-word-comment[data-comment-id]"))){let L=Number(N.dataset.commentId);if(!Number.isFinite(L))continue;let D=N.getBoundingClientRect(),W=Tu(N),V=n.get(L),ee=!(V!=null&&V.paraId)||!(W!=null&&W.paraId)||V.paraId===W.paraId;n.set(L,{commentId:L,author:(o=(r=V==null?void 0:V.author)!=null?r:N.dataset.commentAuthor)!=null?o:"",date:(s=(i=V==null?void 0:V.date)!=null?i:N.dataset.commentDate)!=null?s:"",body:(l=(a=V==null?void 0:V.body)!=null?a:N.dataset.commentBody)!=null?l:"",top:(c=V==null?void 0:V.top)!=null?c:Math.max(0,D.top-t.top),parentCommentId:(u=V==null?void 0:V.parentCommentId)!=null?u:N.dataset.parentCommentId?Number(N.dataset.parentCommentId):void 0,paraId:(f=V==null?void 0:V.paraId)!=null?f:W==null?void 0:W.paraId,from:ee?Math.min((w=(p=V==null?void 0:V.from)!=null?p:W==null?void 0:W.from)!=null?w:Number.POSITIVE_INFINITY,(b=W==null?void 0:W.from)!=null?b:Number.POSITIVE_INFINITY):(g=V==null?void 0:V.from)!=null?g:W==null?void 0:W.from,to:ee?Math.max((y=(h=V==null?void 0:V.to)!=null?h:W==null?void 0:W.to)!=null?y:Number.NEGATIVE_INFINITY,(k=W==null?void 0:W.to)!=null?k:Number.NEGATIVE_INFINITY):(C=V==null?void 0:V.to)!=null?C:W==null?void 0:W.to});}return Array.from(n.values()).map(N=>v(v(v({},N),Number.isFinite(N.from)?{from:N.from}:{from:void 0}),Number.isFinite(N.to)?{to:N.to}:{to:void 0})).sort((N,L)=>N.top-L.top||N.commentId-L.commentId)}function Tu(e){var s;let t=e.closest("coco-word-native-p[data-para-id]");if(!t)return null;let n=0,r=false,o=a=>{var l,c;if(!r){if(a===e){r=true;return}if(a.nodeType===Node.TEXT_NODE){n+=(c=(l=a.textContent)==null?void 0:l.length)!=null?c:0;return}if(!(a instanceof HTMLElement&&a.classList.contains("coco-word-comment-widget")))for(let u of Array.from(a.childNodes))o(u);}};if(o(t),!r)return null;let i=Array.from(e.childNodes).reduce((a,l)=>a+Pu(l),0);return {paraId:(s=t.dataset.paraId)!=null?s:"",from:n,to:n+Math.max(1,i)}}function Pu(e){var t,n;return e.nodeType===Node.TEXT_NODE?(n=(t=e.textContent)==null?void 0:t.length)!=null?n:0:e instanceof HTMLElement&&e.classList.contains("coco-word-comment-widget")?0:e instanceof HTMLImageElement||e instanceof HTMLElement&&e.matches("coco-word-native-drawing, coco-word-native-table, .coco-word-page-break")?1:Array.from(e.childNodes).reduce((r,o)=>r+Pu(o),0)}function Fr(e,t,n){var r,o;return (o=(r=e.sections.find(i=>i.sectionIndex===t))==null?void 0:r.pageLayout)!=null?o:n}function Mu(e,t,n,r){let o=e.sections.find(i=>i.sectionIndex===t);return (o==null?void 0:o.pageNumberStart)!==void 0?o.pageNumberStart+r-1:n}function Ru(e,t){var n,r,o;e.style.width=vt(t.width),e.style.height=vt(t.height),e.style.paddingTop=vt(t.margin.top),e.style.paddingRight=vt(t.margin.right),e.style.paddingBottom=vt(t.margin.bottom),e.style.paddingLeft=vt(t.margin.left),e.style.setProperty("--coco-word-page-margin-top",vt(t.margin.top)),e.style.setProperty("--coco-word-page-margin-left",vt(t.margin.left)),e.style.setProperty("--coco-word-page-margin-right",vt(t.margin.right)),e.style.setProperty("--coco-word-page-margin-bottom",vt(t.margin.bottom)),e.style.setProperty("--coco-word-header-distance",vt((n=t.headerDistance)!=null?n:Math.round(t.margin.top/2))),e.style.setProperty("--coco-word-footer-distance",vt((r=t.footerDistance)!=null?r:Math.round(t.margin.bottom/2))),((o=t.docGrid)==null?void 0:o.linePitch)!==void 0&&t.docGrid.linePitch>0?e.style.setProperty("--coco-word-doc-grid-line-height",vt(t.docGrid.linePitch)):e.style.removeProperty("--coco-word-doc-grid-line-height");}function vw(e){return Math.max(120,gs(e.height-e.margin.top-e.margin.bottom))}function Jo(e,t,n,r,o,i){var u,f;if(i.length<=1)return i;let s=(u=e.sections.find(p=>p.sectionIndex===r))!=null?u:e.sections[0],a=Sw(e,t,(f=s==null?void 0:s.sectionIndex)!=null?f:r),l=Ew(a,(s==null?void 0:s.titlePage)===true,n,o);if(!l&&!kw(e,t))return i;if(l){let p=i.find(w=>w.dataset.partName===l);return p?[p]:[]}let c=i.find(p=>!p.classList.contains("is-empty"));return c?[c]:[i[0]]}function Sw(e,t,n){for(let r=n;r>=0;r--){let o=e.sections.find(s=>s.sectionIndex===r),i=t==="header"?o==null?void 0:o.headerRefs:o==null?void 0:o.footerRefs;if(i&&i.length>0)return i}return []}function kw(e,t){return e.sections.some(n=>t==="header"?n.headerRefs.length>0:n.footerRefs.length>0)}function Ew(e,t,n,r){var o,i;if(e.length===0)return null;if(r===1&&t){let s=e.find(a=>a.type==="first");if(s)return s.partName}if(n%2===0){let s=e.find(a=>a.type==="even");if(s)return s.partName}return (i=(o=e.find(s=>s.type==="default"))==null?void 0:o.partName)!=null?i:e[0].partName}function nu(e){let t=document.createElement("coco-word-native-story");t.setAttribute("data-story-kind",e.kind),t.setAttribute("data-part-name",e.partName),Nw(e)||t.classList.add("is-empty");for(let n of e.blocks)t.appendChild(Or(n));return t}function Qo(e,t,n){let r=e.cloneNode(true);for(let o of Array.from(r.querySelectorAll("[data-field-kind]")))o.dataset.fieldKind==="pageNumber"&&(o.textContent=String(t)),o.dataset.pageNumber=String(t),o.dataset.sectionPageNumber=String(n);return r}function Au(e,t){var i,s,a,l;let n=Array.from(e.querySelectorAll(":scope > coco-word-native-page")),r=new Map;for(let c of n){let u=Number((i=c.dataset.sectionIndex)!=null?i:"0");r.set(u,((s=r.get(u))!=null?s:0)+1);}let o=Cw(t,n,r);for(let c of n){let u=ru(c.dataset.pageNumber,1),f=fn(c.dataset.sectionIndex,0),p=ru(c.dataset.sectionPageNumber,u),w=((a=o.get(f))!=null?a:u)+p-1,b=(l=r.get(f))!=null?l:p;c.dataset.displayPageNumber=String(w);for(let g of Array.from(c.querySelectorAll("[data-field-kind]")))g.dataset.fieldKind==="pageNumber"?g.textContent=String(w):g.dataset.fieldKind==="totalPages"?g.textContent=String(n.length):g.dataset.fieldKind==="sectionPages"&&(g.textContent=String(b)),g.dataset.pageNumber=String(w),g.dataset.sectionPageNumber=String(p),g.dataset.totalPages=String(n.length),g.dataset.sectionPages=String(b);}}function Cw(e,t,n){let r=[],o=new Set;for(let i of t){let s=fn(i.dataset.sectionIndex,0);o.has(s)||(o.add(s),r.push(s));}return Iw(e.sections,r,n)}function Iw(e,t,n){var i,s;let r=new Map,o=1;for(let a of t){let l=e.find(u=>u.sectionIndex===a),c=(i=l==null?void 0:l.pageNumberStart)!=null?i:o;r.set(a,c),o=c+((s=n.get(a))!=null?s:0);}return r}function ru(e,t){let n=Number(e);return Number.isInteger(n)&&n>0?n:t}function fn(e,t){let n=Number(e);return Number.isInteger(n)&&n>=0?n:t}function Nw(e){return e.blocks.some(t=>t.kind==="table"?t.rows.length>0:t.content.some(n=>n.kind==="text"?n.text.trim().length>0:(n.kind==="field",true)))}function Or(e,t={}){return e.kind==="paragraph"?$r(e,t):Bu(e)}function $r(e,t={}){var s,a,l,c,u,f,p,w,b,g,h,y;let n=document.createElement("coco-word-native-p");n.setAttribute("data-para-id",e.paraId),n.setAttribute("data-story",e.story),e.styleId&&n.setAttribute("data-style-id",e.styleId),((s=e.format)==null?void 0:s.outlineLevel)!==void 0&&n.setAttribute("data-outline-level",String(e.format.outlineLevel)),(a=e.format)!=null&&a.hasNumbering&&(n.setAttribute("data-numbering","true"),n.setAttribute("data-numbering-label",(c=(l=e.format.numbering)==null?void 0:l.label)!=null?c:"\u2022")),(u=e.format)!=null&&u.pageBreakBefore&&n.setAttribute("data-page-break-before","true"),(f=e.format)!=null&&f.hasSectionBreak&&n.setAttribute("data-section-break","true"),(p=e.format)!=null&&p.keepNext&&n.setAttribute("data-keep-next","true"),(w=e.format)!=null&&w.keepLines&&n.setAttribute("data-keep-lines","true"),((b=e.format)==null?void 0:b.widowControl)!==void 0&&n.setAttribute("data-widow-control",String(e.format.widowControl)),((g=e.format)==null?void 0:g.snapToGrid)!==void 0&&n.setAttribute("data-snap-to-grid",String(e.format.snapToGrid));let r=Tw(e,t)?$(v({},e.format),{snapToGrid:true,spacing:$(v({},(y=(h=e.format)==null?void 0:h.spacing)!=null?y:{}),{line:t.implicitGridLinePitch,lineRule:"exact"})}):e.format,o=Fa(r).cssText;o.length>0&&n.setAttribute("style",o),n.contentEditable="inherit",n.tabIndex=0,n.setAttribute("role","textbox"),n.spellcheck=false;let i=Mw(e);if(i)return n.classList.add("has-tab-stops"),n.appendChild(i),n;for(let k of e.content)if(k.kind==="text")n.appendChild(hs(k));else if(k.kind==="field")n.appendChild(Lu(k));else if(k.kind==="image")n.appendChild(ms(k));else if(k.kind==="drawing")n.appendChild(Ww(k));else {let C=document.createElement("span");C.className="coco-word-page-break",C.contentEditable="false",C.setAttribute("data-kind","page-break"),C.setAttribute("aria-label","Page break"),n.appendChild(C);}return n.childNodes.length===0&&n.appendChild(document.createTextNode("")),n}function ms(e){var r,o,i,s;let t=document.createElement("img"),n=Ar(e.src);return n&&(t.src=n),t.alt=e.drawingId,t.dataset.drawingId=e.drawingId,e.revision&&(t.classList.add(e.revision.revisionKind==="delete"?"coco-word-revision-delete":"coco-word-revision-insert"),t.dataset.revisionId=e.revision.revisionId,t.dataset.revisionKind=e.revision.revisionKind,t.dataset.revisionAuthor=(r=e.revision.author)!=null?r:"",t.dataset.revisionDate=(o=e.revision.date)!=null?o:"",t.dataset.revisionText="\u56FE\u7247"),e.formatRevision&&(t.classList.add("coco-word-revision-format"),t.dataset.revisionId=e.formatRevision.revisionId,t.dataset.revisionKind="format",t.dataset.revisionAuthor=(i=e.formatRevision.author)!=null?i:"",t.dataset.revisionDate=(s=e.formatRevision.date)!=null?s:"",t.dataset.revisionText="\u56FE\u7247\u5C3A\u5BF8"),e.anchoringMode&&(t.dataset.anchoringMode=e.anchoringMode),e.wrap&&(t.dataset.wrap=e.wrap),e.width&&(t.style.width=`${e.width}px`),e.height&&(t.style.height=`${e.height}px`),jw(t,e),t}function Tw(e,t){var n,r,o;return !t.implicitGridForParagraphs||((n=e.format)==null?void 0:n.snapToGrid)!==void 0?false:((o=(r=e.format)==null?void 0:r.spacing)==null?void 0:o.line)===void 0&&t.implicitGridLinePitch!==void 0}function Pw(e){var t;return e.kind==="paragraph"?((t=e.format)==null?void 0:t.snapToGrid)===false:e.rows.some(n=>n.cells.some(r=>r.paragraphs.some(o=>{var i;return ((i=o.format)==null?void 0:i.snapToGrid)===false})))}function Mw(e){var c,u,f;let t=(c=e.format)==null?void 0:c.tabStops;if(!t||t.length===0)return null;let n=e.content.reduce((p,w)=>p+(w.kind==="text"?Lw(w.text):0),0);if(n!==1&&n!==2||!e.content.every(p=>p.kind==="text"))return null;let r=t.find(p=>p.alignment==="right");if(!r)return null;let o=r.leader!==void 0&&r.leader!=="none",i=Rw(e);if(!o&&!Aw(i))return null;let s=document.createElement("span");s.className=n===2?"coco-word-tab-row is-three-part-tab":"coco-word-tab-row is-right-tab",s.style.setProperty("--coco-word-tab-stop",Mn(r.position)),o&&(s.classList.add(`has-leader-${r.leader}`),s.dataset.tabLeader=r.leader);let a=Array.from({length:n+1},(p,w)=>{let b=document.createElement("span");return b.className=`coco-word-tab-segment is-segment-${w}`,b}),l=0;for(let p of e.content){if(p.kind!=="text")continue;let w=p.text.split(" ");for(let b=0;b<w.length;b++){let g=(u=w[b])!=null?u:"";g.length>0&&((f=a[l])==null||f.appendChild(hs($(v({},p),{text:g})))),b<w.length-1&&(l=Math.min(l+1,a.length-1));}}for(let p=0;p<a.length;p++){if(p>0){let w=document.createElement("span");w.className="coco-word-tab-marker",w.textContent=" ",s.appendChild(w);}s.appendChild(a[p]);}return s}function Rw(e){var n,r;let t=[""];for(let o of e.content){if(o.kind!=="text")continue;let i=o.text.split(" ");t[t.length-1]+=(n=i[0])!=null?n:"";for(let s=1;s<i.length;s++)t.push((r=i[s])!=null?r:"");}return t}function Aw(e){return e.length<2||e.length>3?false:e.every(t=>t.trim().length<=32)}function Lw(e){return e.split(" ").length-1}function Ww(e){var i,s,a,l;let t=document.createElement("coco-word-native-drawing");if(t.contentEditable="false",t.dataset.drawingId=e.drawingId,t.dataset.drawingKind=e.drawingKind,e.anchoringMode&&(t.dataset.anchoringMode=e.anchoringMode),e.wrap&&(t.dataset.wrap=e.wrap),t.classList.add(`is-${e.drawingKind.toLowerCase()}`),e.hasBorder&&t.classList.add("has-border"),e.hasFill&&t.classList.add("has-fill"),e.isLineOrConnector){t.classList.add("is-line-or-connector");let c=Fw(e);t.classList.add(c.vertical?"is-vertical-line":"is-horizontal-line"),t.style[c.property]=c.value;}let n=((s=(i=e.text)==null?void 0:i.trim().length)!=null?s:0)>0||((l=(a=e.paragraphs)==null?void 0:a.some(c=>c.content.some(u=>u.kind==="text"&&u.text.trim().length>0)))!=null?l:false);(e.drawingKind==="textBox"&&!n&&!e.hasBorder||!n&&!e.hasBorder&&!e.hasFill&&!e.isLineOrConnector)&&t.classList.add("is-empty");let o=Hw(e);if(o&&(t.style.width=o),e.isLineOrConnector?e.height&&(t.style.height=`${e.height}px`):e.height&&Dw(e)&&(t.style.minHeight=`${e.height}px`),Gw(t,e),e.paragraphs&&e.paragraphs.length>0)for(let c of e.paragraphs)t.appendChild($w(c));else if(e.text&&e.text.length>0){let c=document.createElement("span");c.className="coco-word-native-drawing-text",e.innerTextAlign&&(c.style.textAlign=qw(e.innerTextAlign)),c.textContent=e.text,t.appendChild(c);}else t.setAttribute("aria-label",e.drawingKind);return t}function Bw(e){var t,n;return ((t=e.height)!=null?t:0)>Math.max(1,((n=e.width)!=null?n:0)*2)}function Fw(e){var n,r;let t=Bw(e);return {vertical:t,property:t?"borderLeft":"borderTop",value:`${(n=e.strokeWidth)!=null?n:1}px solid ${(r=e.strokeColor)!=null?r:"#111827"}`}}function Dw(e){return !(e.drawingKind==="textBox"&&!e.hasBorder&&!e.hasFill)}function Hw(e){if(!e.width)return;if(e.anchoringMode==="anchor"&&Ow(e.wrap))return `${e.width}px`;let t=e.isLineOrConnector?"100%":"max(1px, calc(100% - 4pt))";return `min(${e.width}px, ${t})`}function Ow(e){return e==="none"||e==="behind"||e==="inFront"}function $w(e){let t=document.createElement("div");t.className="coco-word-native-drawing-paragraph";let n=Fa(e.format).cssText;n.length>0&&t.setAttribute("style",n);for(let r of e.content)r.kind==="text"?t.appendChild(hs(r)):r.kind==="field"?t.appendChild(Lu(r)):(r.kind==="image"||r.kind==="drawing")&&t.appendChild(document.createTextNode(r.kind==="drawing"&&r.text?r.text:"\uFFFC"));return t}function hs(e){var s,a,l,c,u,f,p,w,b;if(e.kind!=="text")return document.createTextNode("");let t=Oo(e.format).cssText,n=(s=e.marks)==null?void 0:s.find(g=>g.kind==="comment"),r=(a=e.marks)==null?void 0:a.find(g=>g.kind==="revision"),o=e.formatRevision;if(!n&&!r&&!o&&!e.hyperlink&&t.length===0)return document.createTextNode(e.text);let i=e.hyperlink?document.createElement("a"):document.createElement("span");if(t.length>0&&i.setAttribute("style",t),e.hyperlink){let g=Lr(e.hyperlink.target,e.hyperlink.anchor);i.classList.add("coco-word-hyperlink"),i.setAttribute("href",g),i.dataset.hyperlinkTarget=(l=e.hyperlink.target)!=null?l:"",i.dataset.hyperlinkAnchor=(c=e.hyperlink.anchor)!=null?c:"",e.hyperlink.tooltip&&(i.title=e.hyperlink.tooltip),e.hyperlink.target&&(i.setAttribute("target","_blank"),i.setAttribute("rel","noopener noreferrer"));}return n&&(i.classList.add("coco-word-comment"),i.dataset.commentId=String(n.commentId),i.dataset.commentAuthor=n.author,i.dataset.commentDate=n.date,i.dataset.commentBody=n.body,n.parentCommentId!==void 0&&(i.dataset.parentCommentId=String(n.parentCommentId),i.classList.add("coco-word-comment-reply")),i.title=zw(n)),r&&(i.classList.add(r.revisionKind==="delete"?"coco-word-revision-delete":"coco-word-revision-insert"),i.dataset.revisionId=(u=r.revisionId)!=null?u:"",i.dataset.revisionKind=r.revisionKind,i.dataset.revisionAuthor=(f=r.author)!=null?f:"",i.dataset.revisionDate=(p=r.date)!=null?p:"",i.title=Vw(r)),o&&(i.classList.add("coco-word-revision-format"),i.dataset.revisionId=o.revisionId,i.dataset.revisionKind="format",i.dataset.revisionAuthor=(w=o.author)!=null?w:"",i.dataset.revisionDate=(b=o.date)!=null?b:"",i.title="\u683C\u5F0F\u4FEE\u8BA2"),i.appendChild(document.createTextNode(e.text)),i}function Lu(e){var r;let t=document.createElement("span");t.className="coco-word-native-field",t.dataset.fieldKind=e.fieldKind,t.dataset.fieldInstruction=e.instruction;let n=Oo(e.format).cssText;return n.length>0&&t.setAttribute("style",n),t.contentEditable="false",t.textContent=(r=e.cachedText)!=null?r:"",t}function zw(e){var r,o;let t=e.author?`${e.author}: `:"",n=(o=(r=e.body)==null?void 0:r.trim())!=null?o:"";return n.length>0?`Comment ${e.commentId} ${t}${n}`:`Comment ${e.commentId}`}function Vw(e){let t=e.revisionKind==="delete"?"Deleted":"Inserted",n=e.author?` by ${e.author}`:"",r=e.date?` on ${e.date}`:"",o=e.revisionId?` (${e.revisionId})`:"";return `${t}${n}${r}${o}`}function Gw(e,t){t.anchoringMode==="anchor"&&(e.classList.add("coco-word-anchor-drawing"),Wu(e,t));}function jw(e,t){t.anchoringMode==="anchor"&&(e.classList.add("coco-word-anchor-image"),Wu(e,t));}function Wu(e,t){let n=Uw(t);for(let r of n.classNames)e.classList.add(r);for(let[r,o]of Object.entries(n.dataset))e.dataset[r]=o;for(let[r,o]of Object.entries(n.styleProperties))e.style.setProperty(r,o);}function Uw(e){var a,l,c,u;let t=[],n={},r={};Kw(e.position,n,r);let o=_w(e.position),i=(l=(a=e.position)==null?void 0:a.horizontal)==null?void 0:l.relativeFrom,s=(u=(c=e.position)==null?void 0:c.vertical)==null?void 0:u.relativeFrom;return e.wrap==="square"||e.wrap==="tight"||e.wrap==="through"?o==="left"?t.push("is-float-left"):o==="right"?t.push("is-float-right"):o==="center"?t.push("is-centered"):t.push("is-float-right"):e.wrap==="behind"||e.wrap==="inFront"||e.wrap==="none"?(t.push("is-overlay-like"),t.push("is-absolute-anchor"),ss(s)?t.push("is-page-relative-anchor"):t.push("is-paragraph-relative-anchor"),i==="column"&&t.push("is-column-relative-anchor"),o==="left"&&t.push("is-anchor-left"),o==="right"&&t.push("is-anchor-right"),o==="center"&&t.push("is-anchor-center"),e.wrap==="behind"&&t.push("is-behind-text"),e.wrap==="inFront"&&t.push("is-in-front-of-text")):e.wrap==="topAndBottom"&&(t.push("is-top-bottom"),o==="center"&&t.push("is-centered")),{classNames:t,dataset:n,styleProperties:r}}function Kw(e,t,n){let r=e==null?void 0:e.horizontal,o=e==null?void 0:e.vertical;r!=null&&r.relativeFrom&&(t.positionHorizontalRelativeFrom=r.relativeFrom),o!=null&&o.relativeFrom&&(t.positionVerticalRelativeFrom=o.relativeFrom),r!=null&&r.align&&(t.positionHorizontalAlign=r.align),o!=null&&o.align&&(t.positionVerticalAlign=o.align),(r==null?void 0:r.posOffset)!==void 0&&(t.positionHorizontalOffset=String(r.posOffset),n["--coco-word-anchor-left"]=`${ls(r.posOffset)}px`),(o==null?void 0:o.posOffset)!==void 0&&(t.positionVerticalOffset=String(o.posOffset),n["--coco-word-anchor-top"]=`${ls(o.posOffset)}px`);}function _w(e){let t=e==null?void 0:e.horizontal;if(!t)return null;if(t.align==="left"||t.align==="inside")return "left";if(t.align==="right"||t.align==="outside")return "right";if(t.align==="center")return "center";if(t.posOffset===void 0)return null;let n=ls(t.posOffset);return n<=8?"left":n>=240?"right":null}function qw(e){return e==="both"?"justify":e}function Bu(e){var s,a,l,c;let t=document.createElement("coco-word-native-table");t.setAttribute("data-table-id",e.tableId),e.revision&&(t.classList.add(e.revision.revisionKind==="delete"?"coco-word-revision-delete":"coco-word-revision-insert"),t.dataset.revisionId=e.revision.revisionId,t.dataset.revisionKind=e.revision.revisionKind,t.dataset.revisionAuthor=(s=e.revision.author)!=null?s:"",t.dataset.revisionDate=(a=e.revision.date)!=null?a:"",t.dataset.revisionText="\u8868\u683C\u7ED3\u6784"),e.tableStyleId&&t.setAttribute("data-style-id",e.tableStyleId);let n=document.createElement("table"),r=Qw(e);if(r&&n.style.setProperty("--coco-word-table-border",r),Jw(n,e),e.columnWidths.some(u=>u>0)){let u=document.createElement("colgroup"),f=0;for(let p of e.columnWidths)f+=Math.max(0,p);for(let p of e.columnWidths){let w=document.createElement("col");p>0&&(w.style.width=((l=e.layout)==null?void 0:l.widthType)==="pct"&&f>0?`${p/f*100}%`:Mn(p)),u.appendChild(w);}n.appendChild(u),f>0&&n.style.width.length===0&&(n.style.width=Mn(f));}let o=document.createElement("tbody"),i=Xw(e);for(let u=0;u<e.rows.length;u+=1){let f=e.rows[u],p=document.createElement("tr");if(p.dataset.rowIndex=String(u),f.isHeader&&(p.dataset.repeatHeader="true"),f.cantSplit&&(p.dataset.cantSplit="true"),f.height&&f.height.val>0){let b=Mn(f.height.val);p.dataset.heightRule=(c=f.height.hRule)!=null?c:"auto",p.style.setProperty("--coco-word-row-height",b),f.height.hRule,p.style.height=b;}let w=0;for(let b of f.cells){let g=Math.max(1,b.gridSpan),h=w;if(w+=g,b.vMerge==="continue")continue;let y=document.createElement("td");y.dataset.rowIndex=String(u),y.dataset.cellIndex=String(f.cells.indexOf(b)),y.dataset.columnIndex=String(h),b.gridSpan>1&&(y.colSpan=b.gridSpan),b.rowSpan&&b.rowSpan>1&&(y.rowSpan=b.rowSpan);let k=nc($(v({},b),{borders:Yw(e,b,{rowIndex:u,rowCount:e.rows.length,columnIndex:h,columnSpan:g,columnCount:i})})).cssText;k.length>0&&y.setAttribute("style",k),y.contentEditable="true";for(let C of b.blocks){let N=Or(C);for(let L of [...N.matches("coco-word-native-p")?[N]:[],...Array.from(N.querySelectorAll("coco-word-native-p"))])L.contentEditable="true";y.appendChild(N);}p.appendChild(y);}o.appendChild(p);}return n.appendChild(o),t.appendChild(n),fs(t),t}function Xw(e){let t=e.columnWidths.filter(n=>n>0).length;return t>0?t:Math.max(1,...e.rows.map(n=>n.cells.reduce((r,o)=>r+Math.max(1,o.gridSpan),0)))}function Yw(e,t,n){var o;let r=e.borders;if(!(!r&&!t.borders))return v(v({},Zw(r,n)),(o=t.borders)!=null?o:{})}function Zw(e,t){var a,l,c,u;if(!e)return {};let n={val:"nil"},r=t.rowIndex===0,o=t.rowIndex>=t.rowCount-1,i=t.columnIndex===0,s=t.columnIndex+t.columnSpan>=t.columnCount;return {top:(a=r?e.top:e.insideH)!=null?a:n,right:(l=s?e.right:e.insideV)!=null?l:n,bottom:(c=o?e.bottom:e.insideH)!=null?c:n,left:(u=i?e.left:e.insideV)!=null?u:n}}function Jw(e,t){let n=t.layout;n&&(n.width!==void 0&&n.width>0&&(n.widthType==="pct"?e.style.width=`${n.width/50}%`:n.widthType!=="auto"&&(e.style.width=Mn(n.width))),n.alignment==="center"?(e.style.marginLeft="auto",e.style.marginRight="auto"):n.alignment==="right"?(e.style.marginLeft="auto",e.style.marginRight="0"):n.indent!==void 0&&n.indent>0&&(e.style.marginLeft=Mn(n.indent)),n.cellSpacing!==void 0&&n.cellSpacing>0&&(e.style.borderCollapse="separate",e.style.borderSpacing=n.cellSpacingType==="pct"?`${n.cellSpacing/50}%`:Mn(n.cellSpacing)));}function Mn(e){return `${e/20}pt`}function vt(e){return `${gs(e)}px`}function gs(e){return e/15}function ls(e){return e/914400*96}function Qw(e){var i,s,a,l,c,u,f,p,w,b,g;let t=(g=(w=(f=(c=(a=(i=e.borders)==null?void 0:i.insideH)!=null?a:(s=e.borders)==null?void 0:s.insideV)!=null?c:(l=e.borders)==null?void 0:l.top)!=null?f:(u=e.borders)==null?void 0:u.left)!=null?w:(p=e.borders)==null?void 0:p.bottom)!=null?g:(b=e.borders)==null?void 0:b.right;if(!t||t.val==="none"||t.val==="nil")return null;let n=t.color&&/^[0-9a-f]{6}$/i.test(t.color)?`#${t.color}`:"#d4d4d8",r=t.size!==void 0?Math.max(.5,t.size/8):.75,o=t.val==="double"?"double":"solid";return `${r}pt ${o} ${n}`}function Pn(e){customElements.get(e)||customElements.define(e,class extends HTMLElement{});}function kt(e){var n,r;let t=e.getRootNode();return t instanceof ShadowRoot?(r=(n=t.getSelection)==null?void 0:n.call(t))!=null?r:null:e.ownerDocument.getSelection()}function ut(e){var o;let t=kt(e);if(!t||t.rangeCount===0)return null;let n=t.getRangeAt(0),r=St(n.startContainer);return !r||!e.contains(r)?null:{paraId:(o=r.dataset.paraId)!=null?o:"",offset:ti(r,n.startContainer,n.startOffset)}}function st(e){let t=ut(e);return t?{kind:"caret",paraId:t.paraId,offset:t.offset}:null}function ze(e){var s,a;let t=kt(e);if(!t||t.rangeCount===0||!t.anchorNode||!t.focusNode)return null;let n=St(t.anchorNode),r=St(t.focusNode);if(!n||!r||!e.contains(n)||!e.contains(r))return null;let o={paraId:(s=n.dataset.paraId)!=null?s:"",offset:ti(n,t.anchorNode,t.anchorOffset)},i={paraId:(a=r.dataset.paraId)!=null?a:"",offset:ti(r,t.focusNode,t.focusOffset)};return t.isCollapsed?{kind:"caret",paraId:o.paraId,offset:o.offset}:{kind:"text-range",anchor:o,focus:i}}function Du(e,t,n){var i;let r=ex(t,n);if(!r)return null;let o=St(r.node);return !o||!e.contains(o)?null:{paraId:(i=o.dataset.paraId)!=null?i:"",offset:ti(o,r.node,r.offset)}}function lt(e,t){let n=e.querySelector(`coco-word-native-p[data-para-id="${t.paraId}"]`);if(!n)return;n.focus({preventScroll:true});let r=document.createRange(),o=An(n,t.offset);r.setStart(o.node,o.offset),r.setEnd(o.node,o.offset);let i=kt(e);i&&(i.removeAllRanges(),i.addRange(r));}function hn(e,t,n){let r=e.querySelector(`coco-word-native-p[data-para-id="${t.paraId}"]`),o=e.querySelector(`coco-word-native-p[data-para-id="${n.paraId}"]`);if(!r||!o)return;let i=An(r,t.offset),s=An(o,n.offset),a=kt(e);a&&(r.focus({preventScroll:true}),a.removeAllRanges(),a.setBaseAndExtent(i.node,i.offset,s.node,s.offset));}function Hu(e,t){let n=St(t);if(!n||!e.contains(n))return false;let r=document.createRange();r.selectNodeContents(t);let o=kt(e);return o?(n.focus({preventScroll:true}),o.removeAllRanges(),o.addRange(r),true):false}function Ou(e,t,n,r){let o=e.querySelector(`coco-word-native-p[data-para-id="${t}"]`);if(!o)return null;let i=An(o,n),s=An(o,r),a=document.createRange();return a.setStart(i.node,i.offset),a.setEnd(s.node,s.offset),a}function bs(e,t,n){let r=e.querySelector(`coco-word-native-p[data-para-id="${t.paraId}"]`),o=e.querySelector(`coco-word-native-p[data-para-id="${n.paraId}"]`);if(!r||!o)return null;let i=An(r,t.offset),s=An(o,n.offset),a=document.createRange();return a.setStart(i.node,i.offset),a.setEnd(s.node,s.offset),a}function ex(e,t){var i,s;let n=document,r=(i=n.caretPositionFromPoint)==null?void 0:i.call(n,e,t);if(r)return {node:r.offsetNode,offset:r.offset};let o=(s=n.caretRangeFromPoint)==null?void 0:s.call(n,e,t);return o?{node:o.startContainer,offset:o.startOffset}:null}function $u(e,t){Et(e);let n=e.querySelector(`coco-word-native-p[data-para-id="${t.paraId}"] img[data-drawing-id="${t.drawingId}"]`);n==null||n.classList.add("is-selected");}function Et(e){e.querySelectorAll("coco-word-native-p img.is-selected").forEach(t=>{t.classList.remove("is-selected");});}function ni(e,t){var i,s;let n=0,r=document.createTreeWalker(e,NodeFilter.SHOW_TEXT|NodeFilter.SHOW_ELEMENT),o=r.nextNode();for(;o;){if(o===t)return n;o.nodeType===Node.TEXT_NODE?n+=(s=(i=o.textContent)==null?void 0:i.length)!=null?s:0:o instanceof HTMLImageElement&&(n+=1),o=r.nextNode();}return n}function St(e){let t=e.nodeType===Node.ELEMENT_NODE?e:e.parentNode;for(;t;){if(t instanceof HTMLElement&&t.tagName==="COCO-WORD-NATIVE-P")return t;t=t.parentNode;}return null}function ti(e,t,n){let r=0,o=null,i=s=>{var a,l,c,u;if(o===null){if(s===t){if(s.nodeType===Node.TEXT_NODE){o=r+Math.max(0,Math.min(n,(l=(a=s.textContent)==null?void 0:a.length)!=null?l:0));return}let f=Math.max(0,Math.min(n,s.childNodes.length));for(let p=0;p<f;p+=1)r+=zu(s.childNodes[p]);o=r;return}if(s.nodeType===Node.TEXT_NODE){r+=(u=(c=s.textContent)==null?void 0:c.length)!=null?u:0;return}if(ws(s)){r+=1;return}for(let f=0;f<s.childNodes.length;f+=1)i(s.childNodes[f]);}};return i(e),o!=null?o:r}function zu(e){var n,r;if(e.nodeType===Node.TEXT_NODE)return (r=(n=e.textContent)==null?void 0:n.length)!=null?r:0;if(ws(e))return 1;let t=0;for(let o=0;o<e.childNodes.length;o+=1)t+=zu(e.childNodes[o]);return t}function An(e,t){var s,a;let n=document.createTreeWalker(e,NodeFilter.SHOW_TEXT|NodeFilter.SHOW_ELEMENT),r=n.nextNode(),o=t;for(;r;){if(r.nodeType===Node.TEXT_NODE){let l=(a=(s=r.textContent)==null?void 0:s.length)!=null?a:0;if(o<=l)return {node:r,offset:o};o-=l;}else if(ws(r)){if(o===0)return Fu(r,"before");if(o===1)return Fu(r,"after");o-=1;}r=n.nextNode();}let i=document.createTextNode("");return e.appendChild(i),{node:i,offset:0}}function ws(e){return e instanceof HTMLElement&&(e instanceof HTMLImageElement||e.classList.contains("coco-word-page-break"))}function Fu(e,t){let n=e.parentNode;if(!n)return {node:e,offset:0};let r=Array.prototype.indexOf.call(n.childNodes,e);return {node:n,offset:Math.max(0,r+(t==="after"?1:0))}}function xs(e,t){if(t.query.length===0)return [];let n=t.matchCase?"gu":"giu",r=new RegExp(nx(t.query),n),o=[];for(let i of Gu(e.blocks)){let s=Te(i);for(let a of s.matchAll(r)){let l=a.index,c=l+a[0].length;t.wholeWord&&!tx(s,l,c)||o.push({id:`${i.paraId}:${l}:${c}`,paraId:i.paraId,from:l,to:c,text:a[0]});}}return o}function Gu(e){return e.flatMap(t=>t.kind==="paragraph"?[t]:t.rows.flatMap(n=>n.cells.flatMap(r=>Gu(r.blocks))))}function tx(e,t,n){let r=t>0?e[t-1]:"",o=n<e.length?e[n]:"";return !Vu(r)&&!Vu(o)}function Vu(e){return e.length>0&&/[\p{L}\p{N}_]/u.test(e)}function nx(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var ri="application/x-coco-word-blocks+json";function Uu(e){let t=new DOMParser().parseFromString(e,"text/html"),n=Array.from(t.body.querySelectorAll("p, li, h1, h2, h3, h4, h5, h6")).filter(o=>o.tagName!=="LI"||!o.querySelector("p"));return (n.length>0?n:[t.body]).map(o=>{var a;let i={text:"",runs:[]},s=o.closest("li");return s&&(i.listType=((a=s.parentElement)==null?void 0:a.tagName)==="OL"?"numbered":"bullet"),Yu(o,{},i),i.text=i.text.replace(/\u00a0/g," "),i})}function Ss(e){var r;let t="",n=null;for(let o of e){o.listType!==n&&(n&&(t+=n==="numbered"?"</ol>":"</ul>"),n=(r=o.listType)!=null?r:null,n&&(t+=n==="numbered"?"<ol>":"<ul>"));let i=ox(o);t+=n?`<li>${i}</li>`:`<p>${i}</p>`;}return n&&(t+=n==="numbered"?"</ol>":"</ul>"),t}function ks(e){return JSON.stringify({version:1,blocks:e})}function Ku(e){if(!e||e.length>2e7)return null;try{let t=JSON.parse(e);return !zr(t)||t.version!==1||!Array.isArray(t.blocks)||t.blocks.length===0||t.blocks.length>1e3?null:t.blocks.every(qu)?t.blocks:null}catch(t){return null}}function Es(e){return e.map(_u).join(`
8
- `)}function _u(e){return e.kind==="paragraph"?Te(e):e.rows.map(t=>t.cells.map(n=>n.blocks.map(_u).join(`
14
+ `),u=[s.paraId],f=s.paraId,p=Math.max(0,Math.min(s.offset,Te(l).length)),w=en(e,f,p,(b=c[0])!=null?b:"");w&&a.push(w);for(let F=1;F<c.length;F+=1){let W=Pn(e),V=is(e,f,p+((h=(g=c[F-1])==null?void 0:g.length)!=null?h:0),W);if(!V)return null;a.push(V),u.push(W),f=W,p=0;let ee=en(e,f,0,(y=c[F])!=null?y:"");ee&&a.push(ee);}return {changes:a,cursor:{paraId:f,offset:c.length===1?p+((C=(k=c[0])==null?void 0:k.length)!=null?C:0):(L=(N=c[c.length-1])==null?void 0:N.length)!=null?L:0},paragraphIds:u}}function ns(e,t,n,r,o){var u;let i=_(e,t),s=Nt(n,r);if(!i||s.from===s.to)return null;let a=0,l=false,c=[];for(let f of i.content){let p=$e(f);if(f.kind!=="text"||a+p<=s.from||a>=s.to){c.push(f),a+=p;continue}let w=Math.max(0,s.from-a),b=Math.min(p,s.to-a);w>0&&c.push($(v({},f),{text:f.text.slice(0,w)})),b>w&&(c.push($(v({},f),{text:f.text.slice(w,b),format:v(v({},(u=f.format)!=null?u:{}),o)})),l=true),b<p&&c.push($(v({},f),{text:f.text.slice(b)})),a+=p;}return l?(i.content=He(c),{kind:"format",op:"run",paraId:t,from:s.from,to:s.to,format:o}):null}function rs(e,t,n,r,o){var f,p,w;let i=_(e,t),s=Nt(n,r);if(!i||s.from===s.to)return null;let a=0,l=false,c=[],u=$(v({kind:"comment",id:`comment:${o.commentId}`,commentId:o.commentId},o.parentCommentId!==void 0?{parentCommentId:o.parentCommentId}:{}),{author:o.author,date:o.date,body:o.body});for(let b of i.content){let g=$e(b);if(b.kind!=="text"||a+g<=s.from||a>=s.to){c.push(b),a+=g;continue}let h=Math.max(0,s.from-a),y=Math.min(g,s.to-a);if(h>0&&c.push($(v({},b),{text:b.text.slice(0,h)})),y>h){let k=b.text.slice(h,y);if(o.preserveExistingComments&&((f=b.marks)!=null&&f.some(C=>C.kind==="comment")))c.push($(v({},b),{text:k})),c.push($(v({},b),{text:k,marks:[u,...(p=b.marks)!=null?p:[]]}));else {let C=((w=b.marks)!=null?w:[]).filter(N=>N.kind!=="comment");c.push($(v({},b),{text:k,marks:[...C,u]}));}l=true;}y<g&&c.push($(v({},b),{text:b.text.slice(y)})),a+=g;}return l?(i.content=He(c),{kind:"annotation",op:"insert",paraId:t,from:s.from,to:s.to,commentId:o.commentId,body:o.body,parentCommentId:o.parentCommentId}):null}function Hc(e,t,n){let r=[];for(let o of _e(e)){let i=0,s=null,a=null,l=false,c=o.content.map(u=>{var w,b;let f=$e(u);return u.kind!=="text"||!((w=u.marks)==null?void 0:w.find(g=>g.kind==="comment"&&g.commentId===t))?(i+=f,u):(s=s===null?i:s,a=i+f,l=true,i+=f,$(v({},u),{marks:(b=u.marks)==null?void 0:b.map(g=>g.kind==="comment"&&g.commentId===t?$(v({},g),{body:n}):g)}))});!l||s===null||a===null||(o.content=He(c),r.push({kind:"annotation",op:"update",paraId:o.paraId,from:s,to:a,commentId:t,body:n}));}return r}function Oc(e,t){let n=[];for(let r of _e(e)){let o=0,i=null,s=null,a=false,l=r.content.map(c=>{var w,b,g;let u=$e(c);if(c.kind!=="text"||!((b=(w=c.marks)==null?void 0:w.some(h=>h.kind==="comment"&&h.commentId===t))!=null?b:false))return o+=u,c;i=i===null?o:i,s=o+u,a=true,o+=u;let p=(g=c.marks)==null?void 0:g.filter(h=>!(h.kind==="comment"&&h.commentId===t));return p&&p.length>0?$(v({},c),{marks:p}):$(v({},c),{marks:void 0})});!a||i===null||s===null||(r.content=He(l),n.push({kind:"annotation",op:"delete",paraId:r.paraId,from:i,to:s,commentId:t}));}return n}function Ft(e,t,n,r,o){var f,p;let i=_(e,t),s=Nt(n,r);if(!i||s.from===s.to)return null;let a=0,l=false,c=[],u={kind:"revision",id:`revision:${o.revisionId}`,revisionId:o.revisionId,revisionKind:o.revisionKind,author:o.author,date:o.date};for(let w of i.content){let b=$e(w);if(w.kind!=="text"||a+b<=s.from||a>=s.to){c.push(w),a+=b;continue}let g=Math.max(0,s.from-a),h=Math.min(b,s.to-a);if(g>0&&c.push($(v({},w),{text:w.text.slice(0,g)})),h>g){let y=((f=w.marks)!=null?f:[]).find(k=>k.kind==="revision");if(!(o.revisionKind==="delete"&&(y==null?void 0:y.revisionKind)==="insert")){let k=((p=w.marks)!=null?p:[]).filter(C=>C.kind!=="revision");c.push($(v({},w),{text:w.text.slice(g,h),marks:[...k,u]}));}l=true;}h<b&&c.push($(v({},w),{text:w.text.slice(h)})),a+=b;}return l?(i.content=He(c),{kind:"revision",op:o.revisionKind,paraId:t,from:s.from,to:s.to,revisionId:o.revisionId,revisionKind:o.revisionKind}):null}function $c(e,t,n,r,o){var p,w,b,g;let i=_(e,t),s=Nt(n,r);if(!i||s.from===s.to)return null;let a=0,l=false,c="",u="insert",f=[];for(let h of i.content){let y=$e(h);if(h.kind!=="text"||a+y<=s.from||a>=s.to){f.push(h),a+=y;continue}let k=Math.max(0,s.from-a),C=Math.min(y,s.to-a);if(k>0&&f.push($(v({},h),{text:h.text.slice(0,k)})),C>k){let N=h.text.slice(k,C),L=((p=h.marks)!=null?p:[]).find(F=>F.kind==="revision");L?(l=true,c=(w=L.revisionId)!=null?w:L.id.replace(/^revision:/,""),u=(b=L.revisionKind)!=null?b:"insert",(o==="accept"?u==="insert":u==="delete")&&f.push($(v({},h),{text:N,marks:((g=h.marks)!=null?g:[]).filter(W=>W.kind!=="revision")}))):f.push($(v({},h),{text:N}));}C<y&&f.push($(v({},h),{text:h.text.slice(C)})),a+=y;}return l?(i.content=He(f),{kind:"revision",op:o,paraId:t,from:s.from,to:s.to,revisionId:c,revisionKind:u}):null}function zc(e,t,n,r,o){let i=_(e,t),s=Nt(n,r);if(!i||s.from===s.to)return null;let a=0,l=false,c="",u=[];for(let f of i.content){let p=$e(f);if(f.kind!=="text"||a+p<=s.from||a>=s.to){u.push(f),a+=p;continue}let w=Math.max(0,s.from-a),b=Math.min(p,s.to-a);if(w>0&&u.push($(v({},f),{text:f.text.slice(0,w)})),b>w){let g=f.formatRevision;g?(c=g.revisionId,l=true,u.push($(v({},f),{text:f.text.slice(w,b),format:o==="reject"?g.beforeFormat?v({},g.beforeFormat):null:f.format,formatRevision:void 0}))):u.push($(v({},f),{text:f.text.slice(w,b)}));}b<p&&u.push($(v({},f),{text:f.text.slice(b)})),a+=p;}return l?(i.content=He(u),{kind:"format",op:o,paraId:t,from:s.from,to:s.to,format:{},revisionId:c,revisionKind:"format"}):null}function os(e,t,n,r,o){var f;let i=_(e,t),s=Nt(n,r);if(!i||s.from===s.to)return null;let a=o?zb(o):null;if(o&&!a)return null;let l=0,c=false,u=[];for(let p of i.content){let w=$e(p);if(p.kind!=="text"||l+w<=s.from||l>=s.to){u.push(p),l+=w;continue}let b=Math.max(0,s.from-l),g=Math.min(w,s.to-l);if(b>0&&u.push($(v({},p),{text:p.text.slice(0,b)})),g>b){let h=$(v({},p),{text:p.text.slice(b,g)});a?h.hyperlink=v({},a):delete h.hyperlink,u.push(h),Za((f=p.hyperlink)!=null?f:null,a)||(c=true);}g<w&&u.push($(v({},p),{text:p.text.slice(g)})),l+=w;}return c?(i.content=He(u),v({kind:"hyperlink",op:a?"set":"remove",paraId:t,from:s.from,to:s.to},a?{hyperlink:a}:{})):null}function _n(e,t,n){var i,s,a;let r=_(e,t);if(!r)return null;let o=(i=r.format)!=null?i:{};return r.format=v(v({},o),n),n.indent&&(r.format.indent=v(v({},(s=o.indent)!=null?s:{}),n.indent)),n.spacing&&(r.format.spacing=v(v({},(a=o.spacing)!=null?a:{}),n.spacing)),{kind:"format",op:"paragraph",paraId:t,format:n}}function Vc(e,t,n,r){let o=_(e,t),i=Nt(n,r);if(!o||i.from===i.to)return null;let s=0,a=false,l=[];for(let c of o.content){let u=$e(c);if(c.kind!=="text"||s+u<=i.from||s>=i.to){l.push(c),s+=u;continue}let f=Math.max(0,i.from-s),p=Math.min(u,i.to-s);f>0&&l.push($(v({},c),{text:c.text.slice(0,f)})),p>f&&(l.push($(v({},c),{text:c.text.slice(f,p),format:null})),c.format&&Object.keys(c.format).length>0&&(a=true)),p<u&&l.push($(v({},c),{text:c.text.slice(p)})),s+=u;}return a?(o.content=He(l),{kind:"format",op:"run",paraId:t,from:i.from,to:i.to,format:{},clear:true}):null}function Lr(e,t,n){var i,s,a;let r=_(e,t);if(!r)return null;let o=(i=r.format)!=null?i:{};if(n)r.format=$(v({},o),{hasNumbering:true,numbering:v({},n),indent:v(v({},(s=o.indent)!=null?s:{}),gc(n.ilvl))});else {let l=$(v({},o),{hasNumbering:false,indent:$(v({},(a=o.indent)!=null?a:{}),{left:0,firstLine:0})});delete l.numbering,r.format=l;}return {kind:"list",paraId:t,numbering:n?v({},n):null}}function XE(e,t,n,r){var l;let o=_(e,t),i=Nt(n,r);if(!o||i.from===i.to)return false;let s=0,a=false;for(let c of o.content){let u=$e(c);if(c.kind==="text"&&s+u>i.from&&s<i.to&&(a=true,((l=c.format)==null?void 0:l.bold)!==true))return false;s+=u;}return a}function Gc(e,t,n){let r=_(e,t);if(!r)return null;let o=0,i=[],s=null;for(let a of r.content)!s&&a.kind==="image"&&a.drawingId===n?s={kind:"image",op:"delete",paraId:t,offset:o,drawingId:n}:i.push(a),o+=$e(a);return s?(r.content=He(i),s):null}function jc(e,t,n,r,o,i){var p;let s=_(e,t),a=Nt(n,r);if(!s||a.from===a.to)return null;let l=0,c=false,u=[],f=w=>{let b=0;for(let g of o.content){let h=$e(g);if(g.kind==="text"&&w>=b&&w<b+h)return g.format?v({},g.format):null;b+=h;}return null};for(let w of s.content){let b=$e(w);if(w.kind!=="text"||l+b<=a.from||l>=a.to){u.push(w),l+=b;continue}let g=Math.max(0,a.from-l),h=Math.min(b,a.to-l);g>0&&u.push($(v({},w),{text:w.text.slice(0,g)})),h>g&&(u.push($(v({},w),{text:w.text.slice(g,h),formatRevision:(p=w.formatRevision)!=null?p:{kind:"format",revisionId:i.revisionId,beforeFormat:f(l+g),author:i.author,date:i.date}})),c=true),h<b&&u.push($(v({},w),{text:w.text.slice(h)})),l+=b;}return c?(s.content=He(u),{kind:"format",op:"run",paraId:t,from:a.from,to:a.to,format:{},revisionId:i.revisionId,revisionKind:"format",beforeFormat:f(a.from)}):null}function Uc(e,t,n,r){let o=_(e,t);if(!o)return null;let i=0;for(let s=0;s<o.content.length;s+=1){let a=o.content[s];if((a==null?void 0:a.kind)!=="image"||a.drawingId!==n){i+=a?$e(a):0;continue}let l=a.revision;return l?(l.revisionKind==="delete"&&r==="accept"||l.revisionKind==="insert"&&r==="reject"?o.content.splice(s,1):a.revision=void 0,o.content=He(o.content),{kind:"image",op:r,paraId:t,offset:i,drawingId:n,revisionId:l.revisionId,revisionKind:l.revisionKind}):null}return null}function Kc(e,t,n,r){let o=_(e,t);if(!o)return null;let i=0;for(let s of o.content){if(s.kind!=="image"||s.drawingId!==n){i+=$e(s);continue}let a=s.formatRevision;if(!a)return null;r==="reject"&&(s.width=a.beforeWidth,s.height=a.beforeHeight);let l=a.revisionId;return s.formatRevision=void 0,{kind:"image",op:r,paraId:t,offset:i,drawingId:n,revisionId:l,revisionKind:"format"}}return null}function is(e,t,n,r=Pn(e)){let o=be(e,t);if(!o)return null;let{paragraph:i}=o,s=fn(i.content,n);return i.content=s.before,o.insertAfter({kind:"paragraph",paraId:r,story:i.story,styleId:i.styleId,format:i.format?JSON.parse(JSON.stringify(i.format)):null,content:s.after}),{kind:"block",op:"split",paraId:t,newParaId:r,offset:n}}function Wr(e,t,n){let r=_(e,t);if(!r||r.content.some(a=>a.kind!=="text"))return null;let o=Te(r);if(o===n)return null;let i=Vb(o,n),s=r.content;return i.deletedText.length>0&&(s=Lb(s,i.offset,i.deletedText.length)),i.insertedText.length>0&&(s=_c(s,i.offset,i.insertedText,Zc(r.content,i.offset))),r.content=s,i.deletedText.length===0?{kind:"text",op:"insert",paraId:t,offset:i.offset,text:i.insertedText}:i.insertedText.length===0?{kind:"text",op:"delete",paraId:t,offset:i.offset,text:i.deletedText}:{kind:"text",op:"replace",paraId:t,offset:i.offset,text:i.insertedText,deletedText:i.deletedText}}function _c(e,t,n,r=null){let o=[],i=0,s=false;for(let a of e){let l=$e(a);if(!s&&t<=i+l){if(a.kind==="text"){let c=Math.max(0,t-i);o.push($(v({},a),{text:`${a.text.slice(0,c)}${n}${a.text.slice(c)}`}));}else t<=i?o.push({kind:"text",text:n,format:r},a):o.push(a,{kind:"text",text:n,format:r});s=true;}else o.push(a);i+=l;}return s||o.push({kind:"text",text:n,format:r}),He(o)}function Lb(e,t,n){if(n<=0)return e;let r=[],o=0,i=t+n;for(let s of e){let a=$e(s),l=o+a;if(s.kind!=="text"||l<=t||o>=i)r.push(s);else {let c=Math.max(0,t-o),u=Math.max(0,l-i),f=`${s.text.slice(0,c)}${s.text.slice(s.text.length-u)}`;f.length>0&&r.push($(v({},s),{text:f}));}o=l;}return He(r)}function Wb(e,t){return qc(e,t-1)}function Bb(e){let t=new Set(_e(e).flatMap(r=>r.content.filter(o=>o.kind==="image"||o.kind==="drawing").map(o=>o.drawingId))),n=1;for(;t.has(`coco-clipboard-${n}`);)n+=1;return `coco-clipboard-${n}`}function qc(e,t){if(t<0)return null;let n=[],r=0,o=null;for(let i of e.content){let s=$e(i);if(!o&&t>=r&&t<r+s)if(i.kind==="image")o={kind:"image",op:"delete",paraId:e.paraId,offset:t,drawingId:i.drawingId};else if(i.kind==="pageBreak")o={kind:"page-break",op:"delete",paraId:e.paraId,offset:t};else if(i.kind==="text"){let a=t-r,l=i.text.slice(a,a+1),c=`${i.text.slice(0,a)}${i.text.slice(a+1)}`;c.length>0&&n.push($(v({},i),{text:c})),o={kind:"text",op:"delete",paraId:e.paraId,offset:t,text:l};}else n.push(i);else n.push(i);r+=s;}return o?(e.content=He(n),o):null}function Db(e,t,n){let r=[],o=[],i=0;for(let s of e.content){let a=$e(s),l=i+a;if(!(t<l&&n>i)){r.push(s),i=l;continue}if(s.kind==="text"){let u=Math.max(0,t-i),f=Math.min(s.text.length,n-i),p=s.text.slice(u,f),w=`${s.text.slice(0,u)}${s.text.slice(f)}`;w.length>0&&r.push($(v({},s),{text:w})),p.length>0&&o.push({kind:"text",op:"delete",paraId:e.paraId,offset:i+u,text:p});}else s.kind==="image"?o.push({kind:"image",op:"delete",paraId:e.paraId,offset:i,drawingId:s.drawingId}):s.kind==="pageBreak"?o.push({kind:"page-break",op:"delete",paraId:e.paraId,offset:i}):r.push(s);i=l;}return {content:He(r),changes:o.sort((s,a)=>vc(a)-vc(s))}}function fn(e,t){let n=[],r=[],o=0,i=false;for(let s of e){let a=$e(s);if(!i&&t<=o+a){if(s.kind==="text"){let l=Math.max(0,t-o);l>0&&n.push($(v({},s),{text:s.text.slice(0,l)})),l<s.text.length&&r.push($(v({},s),{text:s.text.slice(l)}));}else t<=o?r.push(s):n.push(s);i=true;}else i?r.push(s):n.push(s);o+=a;}return {before:He(n),after:He(r)}}function $e(e){return e.kind==="text"?e.text.length:1}function Xo(e){if(!(!Number.isFinite(e)||e===void 0||e<=0))return Math.max(1,Math.round(e*100)/100)}function Nt(e,t){let n=Math.max(0,Math.min(e,t)),r=Math.max(0,Math.max(e,t));return {from:n,to:r}}function vc(e){return "offset"in e&&typeof e.offset=="number"?e.offset:0}function He(e){var n,r,o,i;let t=[];for(let s of e)if(s.kind==="text"){if(s.text.length===0)continue;let a=t[t.length-1];(a==null?void 0:a.kind)==="text"&&$b(a.format,s.format)&&Za((n=a.hyperlink)!=null?n:null,(r=s.hyperlink)!=null?r:null)&&Za((o=a.marks)!=null?o:null,(i=s.marks)!=null?i:null)?a.text+=s.text:t.push(v({},s));}else t.push(s);return t}function Dt(e){let t=JSON.parse(JSON.stringify(e));return as(t),t}function Xc(e){return e.kind==="paragraph"?e.paraId:e.tableId}function Fb(e,t,n){let r=be(e,t.paraId),o=be(e,n.paraId);if(!r||!o||r.container!==e.blocks||o.container!==e.blocks)return null;let i=r.index<o.index||r.index===o.index&&t.offset<=n.offset?{start:r,end:o,startOffset:t.offset,endOffset:n.offset}:{start:o,end:r,startOffset:n.offset,endOffset:t.offset};return i.start.index===i.end.index||i.start.paragraph.content.some(s=>s.kind!=="text")||i.end.paragraph.content.some(s=>s.kind!=="text")?null:{blocks:e.blocks.slice(i.start.index,i.end.index+1),startOffset:Math.max(0,Math.min(i.startOffset,Te(i.start.paragraph).length)),endOffset:Math.max(0,Math.min(i.endOffset,Te(i.end.paragraph).length))}}function Hb(e){return e.slice(1,-1).some(t=>t.kind==="table"||t.content.some(n=>n.kind!=="text"))}function Yc(e,t){let n=Dt(t),r=new Set(_e(e).map(c=>c.paraId)),o=new Set,i=new Set;Yo(e.blocks,c=>{if(c.kind==="table")i.add(c.tableId);else for(let u of c.content)(u.kind==="image"||u.kind==="drawing")&&o.add(u.drawingId);});let s=Date.now()>>>0,a=()=>{let c="";do s=s+1>>>0,c=s.toString(16).toUpperCase().padStart(8,"0");while(r.has(c));return r.add(c),c},l=(c,u)=>{let f=1;for(;c.has(`${u}-${f}`);)f+=1;let p=`${u}-${f}`;return c.add(p),p};return Yo(n,c=>{if(c.kind==="table"){c.tableId=l(i,"coco-clipboard-table");return}c.paraId=a();for(let u of c.content)if((u.kind==="image"||u.kind==="drawing")&&(u.drawingId=l(o,"coco-clipboard-drawing")),u.kind==="drawing"&&u.paragraphs)for(let f of u.paragraphs)f.paraId=a();}),as(n),n}function Ob(e){let t=new Set;for(let r of [e.blocks,...e.headers.map(o=>o.blocks),...e.footers.map(o=>o.blocks)])Yo(r,o=>{o.kind==="table"&&t.add(o.tableId);});let n=1;for(;t.has(`coco-table-${n}`);)n+=1;return `coco-table-${n}`}function Yo(e,t){for(let n of e)if(t(n),n.kind==="table")for(let r of n.rows)for(let o of r.cells)Yo(o.blocks,t);}function as(e){for(let t of e)if(t.kind==="table")for(let n of t.rows)for(let r of n.cells)as(r.blocks),r.paragraphs=Tr(r.blocks);}function Tr(e){return e.flatMap(t=>t.kind==="paragraph"?[t]:t.rows.flatMap(n=>n.cells.flatMap(r=>Tr(r.blocks))))}function qo(e){return e.reduce((t,n)=>t+$e(n),0)}function $b(e,t){return JSON.stringify(e!=null?e:null)===JSON.stringify(t!=null?t:null)}function zb(e){var o,i,s;let t=(o=e.target)==null?void 0:o.trim(),n=(i=e.anchor)==null?void 0:i.trim().replace(/^#/,""),r=(s=e.tooltip)==null?void 0:s.trim();return !t&&!n?null:v(v(v({},t?{target:t}:{}),n?{anchor:n}:{}),r?{tooltip:r}:{})}function Za(e,t){return JSON.stringify(e)===JSON.stringify(t)}function Zc(e,t){let n=0,r=null;for(let o of e){let i=$e(o);if(o.kind==="text"){if(t>=n&&t<=n+i)return o.format;r=o.format;}n+=i;}return r}function Vb(e,t){let n=0;for(;n<e.length&&n<t.length&&e.charCodeAt(n)===t.charCodeAt(n);)n+=1;let r=e.length,o=t.length;for(;r>n&&o>n&&e.charCodeAt(r-1)===t.charCodeAt(o-1);)r-=1,o-=1;return {offset:n,deletedText:e.slice(n,r),insertedText:t.slice(n,o)}}var Jc=/^data:(image\/(?:png|jpeg|gif|webp));base64,([a-z0-9+/]*={0,2})$/i,Gb=new Set(["http:","https:","mailto:","tel:"]);function Br(e){let t=e.trim();return Jc.test(t)?t:null}function Qc(e){let t=Br(e),n=t?Jc.exec(t):null;if(!n)throw new Error("Only embedded PNG, JPEG, GIF, or WebP images are supported");let r=atob(n[2]),o=new Uint8Array(r.length);for(let i=0;i<r.length;i++)o[i]=r.charCodeAt(i);return new Blob([o],{type:n[1].toLowerCase()})}function Dr(e,t){if(e)try{let n=new URL(e.trim());if(Gb.has(n.protocol))return n.href}catch(n){}return t?`#${encodeURIComponent(t)}`:"#"}var eu=260;function lu(){Mn("coco-word-native-document"),Mn("coco-word-native-page"),Mn("coco-word-native-page-body"),Mn("coco-word-native-story"),Mn("coco-word-native-p"),Mn("coco-word-native-drawing"),Mn("coco-word-native-table");}function du(e){var s,a;let t=document.createElement("coco-word-native-document");t.contentEditable="true",t.spellcheck=false,jb(e)&&t.classList.add("uses-natural-paragraph-flow"),Kb(e)&&t.classList.add("uses-compact-latin-tables"),_b(e)&&t.classList.add("uses-rowspan-table-group-splitting");let n=Un((s=e.defaults)==null?void 0:s.run).cssText;n.length>0&&t.setAttribute("style",n);for(let l of e.headers)t.appendChild(au(l));let r=Ub(e),o=r!==void 0&&fs(e);for(let l of e.blocks)t.appendChild(Vr(l,{implicitGridForParagraphs:o,implicitGridLinePitch:r})),Ow(l)&&(o=false);for(let l of e.footers)t.appendChild(au(l));if(t.querySelector(".coco-word-comment, .coco-word-revision-insert, .coco-word-revision-delete, .coco-word-revision-format, [data-revision-id]")!==null)if(t.classList.add("has-annotation-rail"),((a=e.pageLayout)==null?void 0:a.width)!==void 0)t.style.minWidth=`${ys(e.pageLayout.width)+eu}px`;else {let l=`calc(100% + ${eu}px)`;t.style.width=l,t.style.minWidth=l;}return t}function jb(e){if(e.blocks.length>300)return false;let t=[e.pageLayout,...e.sections.map(n=>n.pageLayout)].filter(n=>n!==void 0);return t.length===0?false:t.every(n=>n.docGrid===void 0)?true:!fs(e)}function Ub(e){var n,r;return (r=(n=[e.pageLayout,...e.sections.map(o=>o.pageLayout)].filter(o=>o!==void 0).find(o=>{var i;return ((i=o.docGrid)==null?void 0:i.linePitch)!==void 0}))==null?void 0:n.docGrid)==null?void 0:r.linePitch}function Kb(e){return e.blocks.some(t=>t.kind==="table")&&!fs(e)}function _b(e){return e.blocks.filter(n=>n.kind==="table").length<10?false:qb(e)<=5}function qb(e){return e.blocks.reduce((t,n)=>t+cu(n),0)}function cu(e){return e.kind==="paragraph"?e.content.filter(t=>t.kind==="image"||t.kind==="drawing").length:e.rows.reduce((t,n)=>t+n.cells.reduce((r,o)=>r+o.blocks.reduce((i,s)=>i+cu(s),0),0),0)}function fs(e){let t=0,n=0;for(let r of e.blocks.slice(0,160)){for(let o of Xb(r))for(let i of o)/\s/.test(i)||(n++,/[\u3400-\u9FFF\uF900-\uFAFF]/.test(i)&&t++);if(n>=1200)break}return t>=24&&t/Math.max(n,1)>=.08}function Xb(e){if(e.kind==="paragraph")return e.content.filter(n=>n.kind==="text").map(n=>n.text);let t=[];for(let n of e.rows)for(let r of n.cells)for(let o of r.paragraphs)t.push(...o.content.filter(i=>i.kind==="text").map(i=>i.text));return t}function uu(e,t){let n=t.pageLayout;if(!n||e.dataset.paginated==="true")return;e.dataset.paginated="true",e.classList.add("is-paginated");let r=Array.from(e.children),o=r.filter(y=>y instanceof HTMLElement&&y.tagName.toLowerCase()==="coco-word-native-story"&&y.dataset.storyKind==="header"),i=r.filter(y=>y instanceof HTMLElement&&y.tagName.toLowerCase()==="coco-word-native-story"&&y.dataset.storyKind==="footer"),s=r.filter(y=>y instanceof HTMLElement&&y.tagName.toLowerCase()!=="coco-word-native-story");e.replaceChildren();let a=new Map,l=0,c=Or(t,l,n),u=(y=l)=>{var C;let k=((C=a.get(y))!=null?C:0)+1;return a.set(y,k),l=y,c=Or(t,y,n),Pu(e,t,c,o,i,e.children.length+1,y,k)},f=u(),p=f.querySelector("coco-word-native-page-body"),w=()=>Math.max(120,Math.round(p.getBoundingClientRect().height)||Rw(c)),b=()=>(f=u(),p=f.querySelector("coco-word-native-page-body"),p),g=y=>{var N,L,F;if(y===l||p.children.length>0)return;let k=(N=a.get(l))!=null?N:0;k>1?a.set(l,k-1):a.delete(l);let C=((L=a.get(y))!=null?L:0)+1;a.set(y,C),l=y,c=Or(t,y,n),Mu(f,t,c,o,i,Number((F=f.dataset.pageNumber)!=null?F:"1"),y,C);},h=(y,k)=>{var V;let C=(V=ow(y,t))!=null?V:l;p.children.length===0&&g(C),gs(y)&&p.children.length>0&&(b(),g(C)),p.appendChild(y);let N=Iw(y);N&&Hr(f);let L=y.querySelector(".coco-word-page-break")!==null;if(p.scrollHeight>w()){let ee=rw(p,y);if(ee){if(y.matches("coco-word-native-table")){if(p.removeChild(y),ss(y,p,w,b)){N||Hr(f);let re=ti(y,t),we=nu(y,t);we!==null&&(l=we),(L||re)&&ru(b,re);return}p.appendChild(y);}p.removeChild(y),p.removeChild(ee),b(),g(C),p.appendChild(ee),p.appendChild(y),y.matches("coco-word-native-table")&&p.scrollHeight>w()&&(p.removeChild(y),ss(y,p,w,b)||p.appendChild(y));}else {p.removeChild(y);let pe=iw(y,p,w);pe?(b(),g(C),p.appendChild(pe)):ss(y,p,w,b)||(b(),g(C),p.appendChild(y));}}else y.matches("coco-word-native-table")&&sw(y,p,w,b,k);N||Hr(f);let F=ti(y,t),W=nu(y,t);W!==null&&(l=W),(L||F)&&ru(b,F);};for(let y=0;y<s.length;y+=1)h(s[y],y===s.length-1);Eu(e),Cu(e),Nu(e),Du(e,t),hn(e);}function pu(e,t,n){let r=e.querySelector(`coco-word-native-page-body coco-word-native-p[data-para-id="${n}"]`),o=r==null?void 0:r.closest("coco-word-native-page");if(!r||!o||!t.pageLayout)return false;let i=tn(e),s=i.indexOf(o);if(s<0)return false;let a=tw(e),l=false,c=false;for(let u=s;u<i.length;u+=1){let f=i[u],p=Ht(f);if(p)for(;Qo(p);){if(Jb(e,t,f,i[u+1],a)){i=tn(e),l=true;continue}let w=Zb(p);if(w.length===0||w.length>=p.children.length)break;let b=i[u+1];(!b||ei(f,b,t))&&(b=mu(e,t,f,b,a),i=tn(e),c=true);let g=Ht(b);if(!g)break;for(let h of [...w].reverse())g.insertBefore(h,g.firstChild);l=true;}}i=tn(e),s=Math.max(0,Math.min(s,Math.max(0,i.length-1))-1);for(let u=s;u<i.length-1;u+=1){let f=i[u],p=i[u+1],w=Ht(f),b=Ht(p);if(!(!w||!b||ei(f,p,t))){for(;Qb(w,b);)l=true;for(;;){let g=hs(b);if(g.length===0||!fu(w,g[0],t))break;for(let h of g)w.appendChild(h);if(Qo(w,8)){for(let h of [...g].reverse())b.insertBefore(h,b.firstChild);if(g.length>1){let h=g[0];if(w.appendChild(h),!Qo(w,8)){l=true;continue}b.insertBefore(h,b.firstChild);}break}l=true;}Iu(p)&&(p.remove(),i=tn(e),u-=1,c=true);}}return l?(Eu(e),Cu(e),Nu(e),c&&nw(e,t,a),Du(e,t),hn(e),true):false}function ms(e,t,n){let r={overflowPx:0,canBackfillPrevious:false,canBackfillNext:false},o=e.querySelector(`coco-word-native-page-body coco-word-native-p[data-para-id="${n}"]`),i=o==null?void 0:o.closest("coco-word-native-page"),s=tn(e),a=i?s.indexOf(i):-1;if(!o||!i||a<0)return r;let l=Ht(i);if(!l)return r;let c=Math.max(120,Math.round(l.getBoundingClientRect().height)),u=Math.max(0,l.scrollHeight-c),f=s[a-1],p=f?Ht(f):null,w=!!(f&&p&&hs(l).some(y=>hu(y,n))&&tu(f,i,p,l,t)),b=s[a+1],g=b?Ht(b):null,h=!!(b&&g&&tu(i,b,l,g,t));return {overflowPx:u,canBackfillPrevious:w,canBackfillNext:h}}function tu(e,t,n,r,o){if(ei(e,t,o))return false;let i=Math.max(0,Math.round(n.getBoundingClientRect().height)-ku(n));if(i<=0)return false;let s=n.lastElementChild,a=r.firstElementChild;if(s instanceof HTMLElement&&a instanceof HTMLElement&&s.matches("coco-word-native-table")&&a.matches("coco-word-native-table")&&s.dataset.tableId===a.dataset.tableId){let c=Array.from(a.querySelectorAll(":scope > table > tbody > tr")).filter(f=>f.dataset.repeatedHeader!=="true"),u=zr(c)[0];if(u&&!An(u)&&bu(u)<=i+8)return true}let l=hs(r);return l.length===0||!fu(n,l[0],o)?false:Yb(l)<=i+8}function Yb(e){return e.reduce((t,n)=>{let r=window.getComputedStyle(n),o=Number.parseFloat(r.marginTop)||0,i=Number.parseFloat(r.marginBottom)||0;return t+n.getBoundingClientRect().height+o+i},0)}function Ot(e,t,n){let r=e.querySelector(`coco-word-native-page-body coco-word-native-p[data-para-id="${n}"]`),o=r==null?void 0:r.closest("coco-word-native-page"),i=tn(e),s=o?i.indexOf(o):-1;if(s<0)return false;let a=false;for(let l of t.blocks){if(l.kind!=="table")continue;let c=Array.from(e.querySelectorAll(`coco-word-native-table[data-table-id="${l.tableId}"]`)),u=c[0],f=u==null?void 0:u.closest("coco-word-native-page");if(!(!u||!f||i.indexOf(f)<s)){u.replaceWith(Ou(l));for(let p of c.slice(1))p.remove();a=true;}}return a}function tn(e){return Array.from(e.children).filter(t=>t instanceof HTMLElement&&t.tagName.toLowerCase()==="coco-word-native-page")}function Ht(e){return e.querySelector(":scope > coco-word-native-page-body")}function Qo(e,t=1){let n=Math.max(120,Math.round(e.getBoundingClientRect().height));return e.scrollHeight>n+t}function Zb(e){let t=e.lastElementChild;if(!(t instanceof HTMLElement))return [];let n=[t],r=t.previousElementSibling;return r instanceof HTMLElement&&r.matches('coco-word-native-p[data-keep-next="true"]')&&n.unshift(r),n}function hs(e){let t=e.firstElementChild;if(!(t instanceof HTMLElement))return [];let n=[t],r=t.nextElementSibling;return t.matches('coco-word-native-p[data-keep-next="true"]')&&r instanceof HTMLElement&&n.push(r),n}function Jb(e,t,n,r,o){let i=Ht(n),s=i==null?void 0:i.lastElementChild;if(!(s instanceof HTMLElement)||!s.matches("coco-word-native-table"))return false;let a=s.querySelector(":scope > table"),l=a==null?void 0:a.querySelector(":scope > tbody");if(!a||!l)return false;let u=Array.from(l.children).filter(oi).filter(C=>C.dataset.repeatedHeader!=="true"),f=zr(u);if(f.length<2)return false;let p=f[f.length-1];if(An(p))return false;let w=r;(!w||ei(n,w,t))&&(w=mu(e,t,n,w,o));let b=Ht(w);if(!b)return false;let g=s.dataset.tableId,h=Array.from(b.children).find(C=>C instanceof HTMLElement&&C.matches("coco-word-native-table")&&C.dataset.tableId===g);if(!h){h=qn(s,a),b.insertBefore(h,b.firstChild);let C=h.querySelector(":scope > table > tbody");C&&Fr(C,ew(e,g));}let y=h.querySelector(":scope > table > tbody");if(!y)return false;let k=Array.from(y.children).find(C=>C instanceof HTMLTableRowElement&&C.dataset.repeatedHeader!=="true");$r(l,p);for(let C of p)y.insertBefore(C,k!=null?k:null);return true}function Qb(e,t){var c,u;let n=e.lastElementChild,r=t.firstElementChild;if(!(n instanceof HTMLElement)||!(r instanceof HTMLElement)||!n.matches("coco-word-native-table")||!r.matches("coco-word-native-table")||n.dataset.tableId!==r.dataset.tableId)return false;let o=n.querySelector(":scope > table > tbody"),i=r.querySelector(":scope > table > tbody");if(!o||!i)return false;let s=Array.from(i.children).filter(oi).filter(f=>f.dataset.repeatedHeader!=="true"),a=zr(s)[0];if(!a||An(a))return false;let l=(u=(c=a[a.length-1])==null?void 0:c.nextElementSibling)!=null?u:null;if(Xn(o,a),Qo(e,8)){for(let f of a)i.insertBefore(f,l);return false}return i.querySelector('tr:not([data-repeated-header="true"])')===null&&r.remove(),true}function ew(e,t){if(!t)return [];let n=Array.from(e.querySelectorAll("coco-word-native-table")).find(r=>r.dataset.tableId===t&&r.querySelector('tr[data-repeat-header="true"]'));return n?Array.from(n.querySelectorAll('tr[data-repeat-header="true"]')):[]}function ei(e,t,n){if(e.dataset.sectionIndex!==t.dataset.sectionIndex)return true;let r=Ht(e),o=Ht(t),i=r==null?void 0:r.lastElementChild,s=o==null?void 0:o.firstElementChild;if(s instanceof HTMLElement&&gs(s))return true;if(!(i instanceof HTMLElement))return false;if(i.querySelector(".coco-word-page-break"))return true;let a=ti(i,n);return a!==null&&a!=="continuous"&&a!=="nextColumn"}function fu(e,t,n){if(gs(t))return false;let r=e.lastElementChild;if(!(r instanceof HTMLElement))return true;if(r.querySelector(".coco-word-page-break"))return false;let o=ti(r,n);return o===null||o==="continuous"||o==="nextColumn"}function tw(e){var o;let t=new Set,n=[],r=[];for(let i of Array.from(e.querySelectorAll(":scope > coco-word-native-page > coco-word-native-story"))){let s=i.dataset.storyKind,a=`${s!=null?s:""}:${(o=i.dataset.partName)!=null?o:""}`;t.has(a)||(t.add(a),s==="header"&&n.push(i),s==="footer"&&r.push(i));}return {headers:n,footers:r}}function mu(e,t,n,r,o){let i=tn(e),s=i.indexOf(n),a=mn(n.dataset.sectionIndex,0),l=i.slice(0,s+1).filter(u=>mn(u.dataset.sectionIndex,0)===a).length+1,c=Pu(e,t,Or(t,a,t.pageLayout),o.headers,o.footers,s+2,a,l);return r&&e.insertBefore(c,r),c}function nw(e,t,n){for(let r of tn(e)){let o=mn(r.dataset.pageNumber,1),i=mn(r.dataset.sectionIndex,0),s=mn(r.dataset.sectionPageNumber,1);Mu(r,t,Or(t,i,t.pageLayout),n.headers,n.footers,o,i,s);}}function gs(e){return e.matches('coco-word-native-p[data-page-break-before="true"]')}function rw(e,t){let n=t.previousElementSibling;return !(n instanceof HTMLElement)||!n.matches('coco-word-native-p[data-keep-next="true"]')?null:n.previousElementSibling instanceof HTMLElement?n:null}function ti(e,t){var o;if(!e.matches('coco-word-native-p[data-section-break="true"]'))return null;let n=e.dataset.paraId;if(!n)return "nextPage";let r=t.sections.find(i=>i.lastParaId===n);return (o=r==null?void 0:r.type)!=null?o:"nextPage"}function nu(e,t){let n=t.sections.find(r=>r.lastParaId&&hu(e,r.lastParaId));return n?Math.min(n.sectionIndex+1,Math.max(0,t.sections.length-1)):null}function ow(e,t){if(t.sections.length===0)return null;let n=gu(e);if(n.length===0)return null;let r=t.sections.find(i=>n.includes(i.firstParaId));if(r)return r.sectionIndex;let o=t.sections.find(i=>n.includes(i.lastParaId));return o?o.sectionIndex:null}function hu(e,t){return gu(e).includes(t)}function gu(e){if(e.matches("coco-word-native-p")){let t=e.dataset.paraId;return t?[t]:[]}return Array.from(e.querySelectorAll("coco-word-native-p")).map(t=>t.dataset.paraId).filter(t=>t!==void 0&&t.length>0)}function ru(e,t){var i;if(t==="continuous"||t==="nextColumn")return;let r=e().closest("coco-word-native-page"),o=Number((i=r==null?void 0:r.getAttribute("data-page-number"))!=null?i:"0");t==="oddPage"&&o%2===0&&e(),t==="evenPage"&&o%2===1&&e();}function iw(e,t,n){if(!e.matches("coco-word-native-p")||e.dataset.keepLines==="true"||e.dataset.pageBreakBefore==="true"||e.querySelector("img, coco-word-native-drawing, coco-word-native-table, .coco-word-page-break, .coco-word-tab-row"))return null;let r=Tt(e);if(r<2)return null;let o=null,i=1,s=r-1;for(;i<=s;){let a=Math.floor((i+s)/2),l=wu(e,a);if(!l||Tt(l.head)===0||Tt(l.tail)===0){s=a-1;continue}t.appendChild(l.head),t.scrollHeight<=n()?((o==null?void 0:o.head.parentElement)===t&&t.removeChild(o.head),o=l,i=a+1):(t.removeChild(l.head),s=a-1);}return !o||o.head.parentElement!==t?null:o.tail}function ss(e,t,n,r){if(e.tagName.toLowerCase()!=="coco-word-native-table")return false;let o=e.querySelector(":scope > table"),i=o==null?void 0:o.querySelector(":scope > tbody"),s=i?Array.from(i.children).filter(oi):[],a=zr(s);if(!o||a.length<2)return false;let l=t,c=qn(e,o),u=c.querySelector("tbody"),f=s.filter(b=>b.dataset.repeatHeader==="true"),p=aw(a,f),w=0;l.appendChild(c);for(let b of a){let g=An(b);if(!g&&w>=p&&(l=r(),c=qn(e,o),u=c.querySelector("tbody"),l.appendChild(c),Fr(u,f),w=0),Xn(u,b),g||(w+=1),l.children.length<=1&&u.children.length<=b.length||l.scrollHeight<=n())continue;$r(u,b),g||(w=Math.max(0,w-1));let h=lw(u,b,l,n()),y=h!=null?h:pw(u,b,l,n()),k=y!=null?y:fw(u,b,l,n());if(k){g||(w+=1),l=r(),c=qn(e,o),u=c.querySelector("tbody"),l.appendChild(c),w=0,Fr(u,f),Xn(u,k),g||(w=1);continue}u.children.length===0&&l.removeChild(c),l=r(),c=qn(e,o),u=c.querySelector("tbody"),l.appendChild(c),w=0,g||Fr(u,f),Xn(u,b),g||(w=1);}return true}function aw(e,t){let n=e.filter(r=>!An(r)).length;return t.length===0||n<30?Number.POSITIVE_INFINITY:8}function sw(e,t,n,r,o){var C;let i=n(),s=i-ku(t),a=kw(e,i);if(s>=a||o&&vw(t,i))return false;let l=e.querySelector(":scope > table"),c=l==null?void 0:l.querySelector(":scope > tbody"),u=c?Array.from(c.children).filter(oi):[],f=zr(u);if(!l||!c||f.length<4)return false;let p=u.filter(N=>N.dataset.repeatHeader==="true"),w=s,b=0,g=[];for(;f.length>1&&w+b<a;){let N=f.pop();if(!N||An(N))break;b+=bu(N),$r(c,N),g.unshift(N);}if(g.length===0)return false;let h=r(),y=qn(e,l),k=y.querySelector("tbody");h.appendChild(y),An((C=g[0])!=null?C:[])||Fr(k,p);for(let N of g)Xn(k,N);return true}function bu(e){return e.reduce((t,n)=>t+n.getBoundingClientRect().height,0)}function lw(e,t,n,r){if(!e.closest("coco-word-native-document.uses-rowspan-table-group-splitting")||t.length<2||t.some(i=>i.dataset.repeatHeader==="true"||i.dataset.cantSplit==="true"))return null;let o=null;for(let i=1;i<t.length;i+=1){let s=dw(t,i);if(s){o&&$r(e,o.head);for(let a of s.head)e.appendChild(a);if(n.scrollHeight<=r)o=s;else {$r(e,s.head),o&&Xn(e,o.head);break}}}return o?o.tail:null}function dw(e,t){if(t<=0||t>=e.length)return null;let n=cw(e),r=e.slice(0,t).map(s=>s.cloneNode(true)),o=e.slice(t).map(s=>s.cloneNode(true)),i=n.filter(s=>s.row<t&&s.row+s.rowSpan>t);if(i.length===0)return null;for(let s of i){let a=r[s.row],l=a==null?void 0:a.cells[s.cellIndex];l&&(l.rowSpan=t-s.row);let c=s.cell.cloneNode(false);c.rowSpan=s.row+s.rowSpan-t,c.colSpan=s.colSpan,c.dataset.rowFragmentContinuation="true",c.classList.add("is-rowspan-continuation"),uw(o[0],c,s.column,n,t);}return {head:r,tail:o}}function cw(e){var r,o;let t=[],n=[];for(let i=0;i<e.length;i+=1){let s=e[i],a=0;for(let l=0;l<s.cells.length;l+=1){for(;((r=n[a])!=null?r:0)>i;)a+=1;let c=s.cells[l],u=Math.max(1,c.colSpan),f=Math.max(1,c.rowSpan);t.push({row:i,cellIndex:l,column:a,colSpan:u,rowSpan:f,cell:c});for(let p=0;p<u;p+=1)n[a+p]=Math.max((o=n[a+p])!=null?o:0,i+f);a+=u;}}return t}function uw(e,t,n,r,o){let s=r.filter(l=>l.row===o).sort((l,c)=>l.column-c.column).find(l=>l.column>n),a=s?e.cells[s.cellIndex]:null;e.insertBefore(t,a!=null?a:null);}function pw(e,t,n,r){if(t.length!==1)return null;let o=t[0];if(!ww(o))return null;let i=null,s=0,a=1;for(let l=0;l<8;l+=1){let c=(s+a)/2,u=xw(o,c);if(!u){a=c;continue}e.appendChild(u.head),n.scrollHeight<=r?((i==null?void 0:i.head.parentElement)===e&&e.removeChild(i.head),i=u,s=c):(e.removeChild(u.head),a=c);}return !i||i.head.parentElement!==e?null:[i.tail]}function fw(e,t,n,r){if(t.length!==1)return null;let o=t[0];if(!mw(o))return null;let i=null,s=0,a=1;for(let l=0;l<9;l+=1){let c=(s+a)/2,u=hw(o,c);if(!u){a=c;continue}e.appendChild(u.head),n.scrollHeight<=r?((i==null?void 0:i.head.parentElement)===e&&e.removeChild(i.head),i=u,s=c):(e.removeChild(u.head),a=c);}return !i||i.head.parentElement!==e?null:[i.tail]}function mw(e){if(e.dataset.repeatHeader==="true"||e.dataset.cantSplit==="true"||Array.from(e.cells).some(n=>n.rowSpan>1||n.colSpan>1))return false;let t=Array.from(e.cells);return t.some(n=>yu(n))?false:vu(e)?t.some(n=>ds(n)):t.every(n=>ds(n))}function hw(e,t){let n=iu(e),r=iu(e);for(let o of Array.from(e.cells)){let i=gw(o,t);if(!i)return null;n.appendChild(i.head),r.appendChild(i.tail);}return {head:n,tail:r}}function gw(e,t){if(!ds(e))return Su(e);let n=Array.from(e.children).find(l=>l instanceof HTMLElement&&l.tagName.toLowerCase()==="coco-word-native-p");if(!n)return null;let r=Tt(n),o=Math.max(1,Math.min(r-1,Math.round(r*t))),i=wu(n,o);if(!i||Tt(i.head)===0||Tt(i.tail)===0)return null;let s=e.cloneNode(false),a=e.cloneNode(false);return s.appendChild(i.head),a.appendChild(i.tail),{head:s,tail:a}}function wu(e,t){let n=Tt(e);if(!Number.isInteger(t)||t<=0||t>=n)return null;let r=e.cloneNode(false),o=e.cloneNode(false);return xu(Array.from(e.childNodes),t,r,o),r.dataset.splitFragment="head",o.dataset.splitFragment="tail",{head:r,tail:o}}function xu(e,t,n,r){let o=t;for(let i of e){let s=Tt(i);if(s===0){o>0?n.appendChild(i.cloneNode(true)):r.appendChild(i.cloneNode(true));continue}if(s<=o){n.appendChild(i.cloneNode(true)),o-=s;continue}if(o<=0){r.appendChild(i.cloneNode(true));continue}bw(i,o,n,r),o=0;}}function bw(e,t,n,r){var s;if(e.nodeType===Node.TEXT_NODE){let a=(s=e.textContent)!=null?s:"";n.appendChild(document.createTextNode(a.slice(0,t))),r.appendChild(document.createTextNode(a.slice(t)));return}if(!(e instanceof HTMLElement))return;let o=e.cloneNode(false),i=e.cloneNode(false);xu(Array.from(e.childNodes),t,o,i),Tt(o)>0&&n.appendChild(o),Tt(i)>0&&r.appendChild(i);}function Tt(e){var t,n;return e.nodeType===Node.TEXT_NODE?(n=(t=e.textContent)==null?void 0:t.length)!=null?n:0:Array.from(e.childNodes).reduce((r,o)=>r+Tt(o),0)}function ww(e){if(e.dataset.repeatHeader==="true"||e.dataset.cantSplit==="true"||Array.from(e.cells).some(n=>n.rowSpan>1||n.colSpan>1))return false;let t=Array.from(e.cells);return t.some(n=>yu(n))?false:vu(e)?t.some(n=>ls(n)):t.every(n=>ls(n))}function xw(e,t){let n=ou(e),r=ou(e);for(let o of Array.from(e.cells)){let i=yw(o,t);if(!i)return null;n.appendChild(i.head),r.appendChild(i.tail);}return {head:n,tail:r}}function yw(e,t){if(!ls(e))return Su(e);let n=Array.from(e.childNodes).filter(s=>s instanceof HTMLElement);if(n.length<2)return null;let r=Math.max(1,Math.min(n.length-1,Math.round(n.length*t))),o=e.cloneNode(false),i=e.cloneNode(false);for(let s=0;s<n.length;s+=1){let a=n[s].cloneNode(true);s<r?o.appendChild(a):i.appendChild(a);}return {head:o,tail:i}}function yu(e){return e.querySelector("coco-word-native-drawing, coco-word-native-table, .coco-word-native-field, .coco-word-page-break, .coco-word-comment, .coco-word-revision-delete, .coco-word-revision-insert")!==null}function vu(e){var t;return ((t=e.closest("coco-word-native-document"))==null?void 0:t.classList.contains("uses-natural-paragraph-flow"))===true}function ls(e){return Array.from(e.childNodes).filter(t=>t instanceof HTMLElement).length>=2}function ds(e){if(e.querySelector("img"))return false;let t=Array.from(e.children).filter(n=>n instanceof HTMLElement);return t.length===1&&t[0].tagName.toLowerCase()==="coco-word-native-p"&&Tt(t[0])>1}function Su(e){let t=e.cloneNode(true),n=e.cloneNode(false);return n.dataset.rowFragmentStatic="true",{head:t,tail:n}}function ou(e){let t=e.cloneNode(false);return t.dataset.rowFragment="block",t.style.removeProperty("height"),t.style.removeProperty("--coco-word-row-height"),delete t.dataset.heightRule,t}function iu(e){let t=e.cloneNode(false);return t.dataset.rowFragment="text",t.style.removeProperty("height"),t.style.removeProperty("--coco-word-row-height"),delete t.dataset.heightRule,t}function vw(e,t){return e.scrollHeight>t+1?false:Sw(e)<=t*.75}function Sw(e){let t=0;for(let n of Array.from(e.children)){if(!(n instanceof HTMLElement))continue;let r=n.getBoundingClientRect(),o=window.getComputedStyle(n),i=Number.parseFloat(o.marginTop)||0,s=Number.parseFloat(o.marginBottom)||0;t+=r.height+i+s;}return t}function ku(e){let t=e.getBoundingClientRect(),n=0;for(let r of Array.from(e.children)){if(!(r instanceof HTMLElement))continue;let o=r.getBoundingClientRect(),i=window.getComputedStyle(r),s=Number.parseFloat(i.marginBottom)||0;n=Math.max(n,o.bottom-t.top+s);}return n}function kw(e,t){if(t<700)return 0;let n=e.querySelectorAll("tr").length,r=e.closest("coco-word-native-document.uses-compact-latin-tables")?8:4;return n<r?0:96}function zr(e){let t=[],n=0,r=0;for(let o=0;o<e.length;o++){r=Math.max(r,o);for(let i of Array.from(e[o].cells))r=Math.max(r,o+Math.max(1,i.rowSpan)-1);o===r&&(t.push(e.slice(n,o+1)),n=o+1);}return n<e.length&&t.push(e.slice(n)),t}function Xn(e,t){for(let r of t)e.appendChild(r);let n=e.closest("coco-word-native-table");n&&bs(n);}function An(e){var t;return ((t=e[0])==null?void 0:t.dataset.repeatHeader)==="true"}function Fr(e,t){for(let r of t){let o=r.cloneNode(true);o.dataset.repeatedHeader="true",e.appendChild(o);}let n=e.closest("coco-word-native-table");n&&bs(n);}function $r(e,t){for(let n of t)n.parentElement===e&&e.removeChild(n);}function qn(e,t){let n=e.cloneNode(false);n.classList.add("is-table-fragment");let r=t.cloneNode(false),o=t.querySelector(":scope > colgroup");return o&&r.appendChild(o.cloneNode(true)),r.appendChild(document.createElement("tbody")),n.appendChild(r),n}function bs(e){e.contentEditable="true";for(let t of Array.from(e.querySelectorAll("td, th")))t.contentEditable="true";for(let t of Array.from(e.querySelectorAll("coco-word-native-p")))t.contentEditable="true",t.childNodes.length===0&&t.appendChild(document.createTextNode(""));}function Eu(e){for(;;){let t=Array.from(e.querySelectorAll(":scope > coco-word-native-page"));if(t.length<2)return;let n=t[t.length-1];if(!Ew(n))return;let r=t[t.length-2],o=r.querySelector(":scope > coco-word-native-page-body"),i=n.querySelector(":scope > coco-word-native-page-body"),s=n.querySelector(":scope > .coco-word-native-page-overlay"),a=n.querySelector(":scope > .coco-word-native-page-behind-layer");if(!o||!i||!s&&!a)return;if(a){let l=cs(r,"behind");for(let c of Array.from(a.children))l.appendChild(c);}if(s){let l=cs(r,"front");for(let c of Array.from(s.children))l.appendChild(c);}for(let l of Array.from(i.children))o.appendChild(l);n.remove();}}function Cu(e){for(let t of Array.from(e.querySelectorAll("coco-word-native-page")))Iu(t)&&t.remove();}function Iu(e){var r,o,i,s;let t=e.querySelector(":scope > coco-word-native-page-body");return !t||t.children.length>0?false:((o=(r=e.querySelector(":scope > .coco-word-native-page-overlay"))==null?void 0:r.children.length)!=null?o:0)+((s=(i=e.querySelector(":scope > .coco-word-native-page-behind-layer"))==null?void 0:i.children.length)!=null?s:0)===0}function Nu(e){let t=new Map;Array.from(e.querySelectorAll(":scope > coco-word-native-page")).forEach((r,o)=>{var a;let i=mn(r.dataset.sectionIndex,0),s=((a=t.get(i))!=null?a:0)+1;t.set(i,s),r.dataset.pageNumber=String(o+1),r.dataset.sectionPageNumber=String(s);});}function Ew(e){var s,a;let t=e.querySelector(":scope > coco-word-native-page-body"),n=e.querySelector(":scope > .coco-word-native-page-overlay"),r=e.querySelector(":scope > .coco-word-native-page-behind-layer"),o=((s=n==null?void 0:n.children.length)!=null?s:0)+((a=r==null?void 0:r.children.length)!=null?a:0);if(!t||o===0)return false;let i=Array.from(t.children).filter(l=>l instanceof HTMLElement);return i.length===0?false:i.every(l=>{var c;return l.matches("coco-word-native-p.is-flow-empty")&&((c=l.textContent)!=null?c:"").trim().length===0&&l.getBoundingClientRect().height<=1})}function oi(e){return e instanceof HTMLTableRowElement}function Hr(e){let t=new Set,n=Array.from(e.querySelectorAll(':scope .is-absolute-anchor:not([data-page-layer-anchor="true"])'));for(let r of n){if(!Tu(r))continue;let o=r.closest("coco-word-native-p");o&&t.add(o);let i=r.closest("coco-word-native-story");i!=null&&i.dataset.storyKind&&(r.dataset.sourceStoryKind=i.dataset.storyKind),i!=null&&i.dataset.partName&&(r.dataset.sourcePartName=i.dataset.partName),r.dataset.pageLayerAnchor="true";let s=r.dataset.wrap==="behind"?"behind":"front";r.dataset.pageLayer=s,r.classList.add("is-page-layer-anchor"),cs(e,s).appendChild(r);}for(let r of t)r.classList.toggle("is-flow-empty",!Nw(r));Cw(e);}function cs(e,t){let n=t==="behind"?"coco-word-native-page-behind-layer":"coco-word-native-page-overlay",r=e.querySelector(`:scope > .${n}`);if(r)return r;let o=document.createElement("div");if(o.className=n,o.contentEditable="false",t==="behind"){let i=Array.from(e.children).find(s=>s.tagName.toLowerCase()!=="coco-word-native-story");e.insertBefore(o,i!=null?i:e.firstChild);}else e.appendChild(o);return o}function Cw(e){var t,n;(t=e.querySelector(":scope > .coco-word-native-page-behind-layer:empty"))==null||t.remove(),(n=e.querySelector(":scope > .coco-word-native-page-overlay:empty"))==null||n.remove();}function Tu(e){let t=e.dataset.positionVerticalRelativeFrom,n=e.dataset.positionHorizontalRelativeFrom;return us(t||n)}function us(e){return e==="page"||e==="margin"}function Iw(e){var n;if(!e.matches("coco-word-native-p")||((n=e.textContent)!=null?n:"").trim().length>0)return false;let t=Array.from(e.children);return t.length===0?false:t.every(r=>r instanceof HTMLElement&&r.classList.contains("is-absolute-anchor")&&Tu(r))}function Nw(e){var t;if(((t=e.textContent)!=null?t:"").trim().length>0)return true;for(let n of Array.from(e.children))if(n instanceof HTMLElement&&!(n.dataset.pageLayerAnchor==="true"||n.classList.contains("is-page-layer-anchor"))&&!n.classList.contains("coco-word-tab-marker"))return true;return false}function Pu(e,t,n,r,o,i,s,a){let l=document.createElement("coco-word-native-page");l.dataset.pageNumber=String(i),l.dataset.sectionIndex=String(s),l.dataset.sectionPageNumber=String(a);let c=Wu(t,s,i,a);l.dataset.displayPageNumber=String(c),Bu(l,n);for(let u of ni(t,"header",i,s,a,r))l.appendChild(ri(u,c,a));l.appendChild(document.createElement("coco-word-native-page-body"));for(let u of ni(t,"footer",i,s,a,o))l.appendChild(ri(u,c,a));return Hr(l),e.appendChild(l),l}function Mu(e,t,n,r,o,i,s,a){var u,f;let l=e.querySelector("coco-word-native-page-body");if(!l)return;e.dataset.sectionIndex=String(s),e.dataset.sectionPageNumber=String(a);let c=Wu(t,s,i,a);e.dataset.displayPageNumber=String(c),Bu(e,n),(u=e.querySelector(":scope > .coco-word-native-page-overlay"))==null||u.remove(),(f=e.querySelector(":scope > .coco-word-native-page-behind-layer"))==null||f.remove();for(let p of Array.from(e.querySelectorAll(":scope > coco-word-native-story")))e.removeChild(p);for(let p of ni(t,"header",i,s,a,r))e.insertBefore(ri(p,c,a),l);for(let p of ni(t,"footer",i,s,a,o))e.appendChild(ri(p,c,a));Hr(e);}function hn(e){var t;for(let n of Array.from(e.querySelectorAll(":scope > coco-word-native-page"))){(t=n.querySelector(":scope > .coco-word-native-comment-layer"))==null||t.remove();let r=Mw(n);if(r.length>0){let o=document.createElement("div");o.className="coco-word-native-comment-layer",o.contentEditable="false",n.appendChild(o),r.sort((i,s)=>i.top-s.top||i.commentId-s.commentId).forEach((i,s)=>{let a=document.createElement("aside");a.className="coco-word-native-comment-bubble",a.dataset.annotationAnchorTop=String(i.top),a.dataset.commentId=String(i.commentId),a.dataset.commentBody=i.body,i.parentCommentId!==void 0&&Number.isFinite(i.parentCommentId)&&(a.dataset.parentCommentId=String(i.parentCommentId),a.classList.add("coco-word-native-comment-reply")),i.paraId&&(a.dataset.paraId=i.paraId),i.from!==void 0&&(a.dataset.from=String(i.from)),i.to!==void 0&&(a.dataset.to=String(i.to)),a.style.setProperty("--coco-word-comment-index",String(s));let l=document.createElement("div");l.className="coco-word-native-comment-meta",l.textContent=[i.author||`Comment ${i.commentId}`,i.date?Ru(i.date):""].filter(Boolean).join(" \xB7 "),i.parentCommentId!==void 0&&Number.isFinite(i.parentCommentId)&&(l.textContent=`\u56DE\u590D #${i.parentCommentId} \xB7 ${l.textContent}`);let c=document.createElement("div");c.className="coco-word-native-comment-body",c.textContent=i.body||"(empty comment)";let u=document.createElement("div");u.className="coco-word-native-comment-actions";let f=document.createElement("button");f.type="button",f.className="coco-word-native-comment-menu-button",f.dataset.commentMenu="true",f.dataset.commentId=String(i.commentId),f.setAttribute("aria-label","\u6279\u6CE8\u64CD\u4F5C"),f.title="\u6279\u6CE8\u64CD\u4F5C",f.textContent="\u22EF",u.appendChild(f);let p=document.createElement("div");p.className="coco-word-native-comment-menu",p.hidden=true,p.dataset.commentMenuFor=String(i.commentId);for(let[w,b]of [["reply","\u56DE\u590D"],["edit","\u7F16\u8F91"],["delete","\u5220\u9664"]]){let g=document.createElement("button");g.type="button",g.className="coco-word-native-comment-menu-item",g.dataset.commentAction=w,g.dataset.commentId=String(i.commentId),g.textContent=b,p.appendChild(g);}u.appendChild(p),a.appendChild(l),a.appendChild(c),a.appendChild(u),o.appendChild(a);});}Tw(n),Pw(n);}}function Tw(e){var a,l,c,u,f,p,w,b,g,h,y;(a=e.querySelector(":scope > .coco-word-native-revision-layer"))==null||a.remove();let t=new Map,n=e.getBoundingClientRect();for(let k of Array.from(e.querySelectorAll(".coco-word-revision-insert[data-revision-id], .coco-word-revision-delete[data-revision-id], .coco-word-revision-format[data-revision-id], img[data-revision-id], coco-word-native-table[data-revision-id]"))){let C=(l=k.dataset.revisionId)!=null?l:"";if(!C)continue;let N=k.dataset.revisionKind==="format"?"format":k.dataset.revisionKind==="delete"||k.classList.contains("coco-word-revision-delete")?"delete":"insert",L=k.getBoundingClientRect(),F=`${N}:${C}`,W=t.get(F),V=Au(k);t.set(F,{id:C,kind:N,author:(c=k.dataset.revisionAuthor)!=null?c:"",date:(u=k.dataset.revisionDate)!=null?u:"",text:`${(f=W==null?void 0:W.text)!=null?f:""}${(w=(p=k.dataset.revisionText)!=null?p:k.textContent)!=null?w:""}`,top:(b=W==null?void 0:W.top)!=null?b:Math.max(0,L.top-n.top),paraId:(g=W==null?void 0:W.paraId)!=null?g:V==null?void 0:V.paraId,from:(h=W==null?void 0:W.from)!=null?h:V==null?void 0:V.from,to:(y=V==null?void 0:V.to)!=null?y:W==null?void 0:W.to});}if(t.size===0)return;let r=document.createElement("div");r.className="coco-word-native-revision-layer",r.contentEditable="false",e.appendChild(r);let o=Array.from(t.values()).sort((k,C)=>k.top-C.top||k.id.localeCompare(C.id)),i=new Map;for(let k of o){let C=k.paraId?`paragraph:${k.paraId}`:`position:${Math.round(k.top/48)}`,N=i.get(C);N?N.push(k):i.set(C,[k]);}let s=k=>{let C=document.createElement("aside");C.className=`coco-word-native-revision-bubble is-${k.kind}`,C.dataset.annotationAnchorTop=String(k.top),C.dataset.revisionId=k.id,C.dataset.revisionKind=k.kind,k.paraId&&(C.dataset.paraId=k.paraId),k.from!==void 0&&(C.dataset.from=String(k.from)),k.to!==void 0&&(C.dataset.to=String(k.to));let N=document.createElement("div");N.className="coco-word-native-revision-header";let L=document.createElement("span");L.className="coco-word-native-revision-meta",L.textContent=[k.author||"User",Ru(k.date)].filter(Boolean).join(" \xB7 "),N.appendChild(L),C.appendChild(N);let F=document.createElement("div");F.className="coco-word-native-revision-content",F.textContent=k.text||"(\u7A7A\u5185\u5BB9)",C.appendChild(F);let W=document.createElement("div");W.className="coco-word-native-revision-actions";for(let[V,ee,pe]of [["accept","\u2713","\u63A5\u53D7\u4FEE\u8BA2"],["reject","\xD7","\u62D2\u7EDD\u4FEE\u8BA2"]]){let re=document.createElement("button");re.type="button",re.dataset.revisionAction=V,re.dataset.revisionId=k.id,re.dataset.revisionKind=k.kind,re.textContent=ee,re.setAttribute("aria-label",pe),re.title=pe,re.className=`is-${V}`,W.appendChild(re);}return C.appendChild(W),C};for(let k of i.values()){if(k.length===1){r.appendChild(s(k[0]));continue}let C=document.createElement("section");C.className="coco-word-native-revision-group",C.dataset.annotationAnchorTop=String(k[0].top);let N=k[0].paraId;N&&(C.dataset.paraId=N);let L=document.createElement("button");L.type="button",L.className="coco-word-native-revision-group-toggle",L.dataset.revisionGroupToggle="true",L.setAttribute("aria-expanded","false");let F=document.createElement("strong");F.textContent=`\u672C\u6BB5 ${k.length} \u6761\u4FEE\u8BA2`;let W=k.reduce((re,we)=>(re[we.kind]+=1,re),{insert:0,delete:0,format:0}),V=document.createElement("span");V.textContent=[W.delete?`${W.delete} \u5220`:"",W.insert?`${W.insert} \u589E`:"",W.format?`${W.format} \u683C\u5F0F`:""].filter(Boolean).join(" \xB7 ");let ee=document.createElement("span");ee.className="coco-word-native-revision-group-affordance",ee.textContent="\u5C55\u5F00",L.append(F,V,ee);let pe=document.createElement("div");pe.className="coco-word-native-revision-group-list",pe.hidden=true,k.forEach(re=>pe.appendChild(s(re))),C.append(L,pe),r.appendChild(C);}}function Pw(e){let n=Array.from(e.querySelectorAll(":scope > .coco-word-native-comment-layer > .coco-word-native-comment-bubble, :scope > .coco-word-native-revision-layer > .coco-word-native-revision-bubble, :scope > .coco-word-native-revision-layer > .coco-word-native-revision-group")).map(i=>({element:i,anchorTop:Math.max(0,Number(i.dataset.annotationAnchorTop)||0),height:Math.max(44,Math.ceil(i.getBoundingClientRect().height)),top:0}));if(n.length===0)return;n.sort((i,s)=>i.anchorTop-s.anchorTop);let r=0;n.forEach((i,s)=>{i.top=Math.max(i.anchorTop,s===0?0:r+8),r=i.top+i.height;});let o=Math.max(0,Math.ceil(e.getBoundingClientRect().height));if(o>0&&r>o){let i=o;for(let s=n.length-1;s>=0;s-=1){let a=n[s];a.top=Math.min(a.top,i-a.height),i=a.top-8;}if(n[0].top<0){let s=-n[0].top;n.forEach(a=>{a.top+=s;});}}for(let i of n){let s=i.element.classList.contains("coco-word-native-comment-bubble")?"--coco-word-comment-top":"--coco-word-revision-top";i.element.style.setProperty(s,`${Math.round(i.top)}px`);}}function Ru(e){if(!e)return "";let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}function Mw(e){var r,o,i,s,a,l,c,u,f,p,w,b,g,h,y,k,C;let t=e.getBoundingClientRect(),n=new Map;for(let N of Array.from(e.querySelectorAll(".coco-word-comment[data-comment-id]"))){let L=Number(N.dataset.commentId);if(!Number.isFinite(L))continue;let F=N.getBoundingClientRect(),W=Au(N),V=n.get(L),ee=!(V!=null&&V.paraId)||!(W!=null&&W.paraId)||V.paraId===W.paraId;n.set(L,{commentId:L,author:(o=(r=V==null?void 0:V.author)!=null?r:N.dataset.commentAuthor)!=null?o:"",date:(s=(i=V==null?void 0:V.date)!=null?i:N.dataset.commentDate)!=null?s:"",body:(l=(a=V==null?void 0:V.body)!=null?a:N.dataset.commentBody)!=null?l:"",top:(c=V==null?void 0:V.top)!=null?c:Math.max(0,F.top-t.top),parentCommentId:(u=V==null?void 0:V.parentCommentId)!=null?u:N.dataset.parentCommentId?Number(N.dataset.parentCommentId):void 0,paraId:(f=V==null?void 0:V.paraId)!=null?f:W==null?void 0:W.paraId,from:ee?Math.min((w=(p=V==null?void 0:V.from)!=null?p:W==null?void 0:W.from)!=null?w:Number.POSITIVE_INFINITY,(b=W==null?void 0:W.from)!=null?b:Number.POSITIVE_INFINITY):(g=V==null?void 0:V.from)!=null?g:W==null?void 0:W.from,to:ee?Math.max((y=(h=V==null?void 0:V.to)!=null?h:W==null?void 0:W.to)!=null?y:Number.NEGATIVE_INFINITY,(k=W==null?void 0:W.to)!=null?k:Number.NEGATIVE_INFINITY):(C=V==null?void 0:V.to)!=null?C:W==null?void 0:W.to});}return Array.from(n.values()).map(N=>v(v(v({},N),Number.isFinite(N.from)?{from:N.from}:{from:void 0}),Number.isFinite(N.to)?{to:N.to}:{to:void 0})).sort((N,L)=>N.top-L.top||N.commentId-L.commentId)}function Au(e){var s;let t=e.closest("coco-word-native-p[data-para-id]");if(!t)return null;let n=0,r=false,o=a=>{var l,c;if(!r){if(a===e){r=true;return}if(a.nodeType===Node.TEXT_NODE){n+=(c=(l=a.textContent)==null?void 0:l.length)!=null?c:0;return}if(!(a instanceof HTMLElement&&a.classList.contains("coco-word-comment-widget")))for(let u of Array.from(a.childNodes))o(u);}};if(o(t),!r)return null;let i=Array.from(e.childNodes).reduce((a,l)=>a+Lu(l),0);return {paraId:(s=t.dataset.paraId)!=null?s:"",from:n,to:n+Math.max(1,i)}}function Lu(e){var t,n;return e.nodeType===Node.TEXT_NODE?(n=(t=e.textContent)==null?void 0:t.length)!=null?n:0:e instanceof HTMLElement&&e.classList.contains("coco-word-comment-widget")?0:e instanceof HTMLImageElement||e instanceof HTMLElement&&e.matches("coco-word-native-drawing, coco-word-native-table, .coco-word-page-break")?1:Array.from(e.childNodes).reduce((r,o)=>r+Lu(o),0)}function Or(e,t,n){var r,o;return (o=(r=e.sections.find(i=>i.sectionIndex===t))==null?void 0:r.pageLayout)!=null?o:n}function Wu(e,t,n,r){let o=e.sections.find(i=>i.sectionIndex===t);return (o==null?void 0:o.pageNumberStart)!==void 0?o.pageNumberStart+r-1:n}function Bu(e,t){var n,r,o;e.style.width=vt(t.width),e.style.height=vt(t.height),e.style.paddingTop=vt(t.margin.top),e.style.paddingRight=vt(t.margin.right),e.style.paddingBottom=vt(t.margin.bottom),e.style.paddingLeft=vt(t.margin.left),e.style.setProperty("--coco-word-page-margin-top",vt(t.margin.top)),e.style.setProperty("--coco-word-page-margin-left",vt(t.margin.left)),e.style.setProperty("--coco-word-page-margin-right",vt(t.margin.right)),e.style.setProperty("--coco-word-page-margin-bottom",vt(t.margin.bottom)),e.style.setProperty("--coco-word-header-distance",vt((n=t.headerDistance)!=null?n:Math.round(t.margin.top/2))),e.style.setProperty("--coco-word-footer-distance",vt((r=t.footerDistance)!=null?r:Math.round(t.margin.bottom/2))),((o=t.docGrid)==null?void 0:o.linePitch)!==void 0&&t.docGrid.linePitch>0?e.style.setProperty("--coco-word-doc-grid-line-height",vt(t.docGrid.linePitch)):e.style.removeProperty("--coco-word-doc-grid-line-height");}function Rw(e){return Math.max(120,ys(e.height-e.margin.top-e.margin.bottom))}function ni(e,t,n,r,o,i){var u,f;if(i.length<=1)return i;let s=(u=e.sections.find(p=>p.sectionIndex===r))!=null?u:e.sections[0],a=Aw(e,t,(f=s==null?void 0:s.sectionIndex)!=null?f:r),l=Ww(a,(s==null?void 0:s.titlePage)===true,n,o);if(!l&&!Lw(e,t))return i;if(l){let p=i.find(w=>w.dataset.partName===l);return p?[p]:[]}let c=i.find(p=>!p.classList.contains("is-empty"));return c?[c]:[i[0]]}function Aw(e,t,n){for(let r=n;r>=0;r--){let o=e.sections.find(s=>s.sectionIndex===r),i=t==="header"?o==null?void 0:o.headerRefs:o==null?void 0:o.footerRefs;if(i&&i.length>0)return i}return []}function Lw(e,t){return e.sections.some(n=>t==="header"?n.headerRefs.length>0:n.footerRefs.length>0)}function Ww(e,t,n,r){var o,i;if(e.length===0)return null;if(r===1&&t){let s=e.find(a=>a.type==="first");if(s)return s.partName}if(n%2===0){let s=e.find(a=>a.type==="even");if(s)return s.partName}return (i=(o=e.find(s=>s.type==="default"))==null?void 0:o.partName)!=null?i:e[0].partName}function au(e){let t=document.createElement("coco-word-native-story");t.setAttribute("data-story-kind",e.kind),t.setAttribute("data-part-name",e.partName),Fw(e)||t.classList.add("is-empty");for(let n of e.blocks)t.appendChild(Vr(n));return t}function ri(e,t,n){let r=e.cloneNode(true);for(let o of Array.from(r.querySelectorAll("[data-field-kind]")))o.dataset.fieldKind==="pageNumber"&&(o.textContent=String(t)),o.dataset.pageNumber=String(t),o.dataset.sectionPageNumber=String(n);return r}function Du(e,t){var i,s,a,l;let n=Array.from(e.querySelectorAll(":scope > coco-word-native-page")),r=new Map;for(let c of n){let u=Number((i=c.dataset.sectionIndex)!=null?i:"0");r.set(u,((s=r.get(u))!=null?s:0)+1);}let o=Bw(t,n,r);for(let c of n){let u=su(c.dataset.pageNumber,1),f=mn(c.dataset.sectionIndex,0),p=su(c.dataset.sectionPageNumber,u),w=((a=o.get(f))!=null?a:u)+p-1,b=(l=r.get(f))!=null?l:p;c.dataset.displayPageNumber=String(w);for(let g of Array.from(c.querySelectorAll("[data-field-kind]")))g.dataset.fieldKind==="pageNumber"?g.textContent=String(w):g.dataset.fieldKind==="totalPages"?g.textContent=String(n.length):g.dataset.fieldKind==="sectionPages"&&(g.textContent=String(b)),g.dataset.pageNumber=String(w),g.dataset.sectionPageNumber=String(p),g.dataset.totalPages=String(n.length),g.dataset.sectionPages=String(b);}}function Bw(e,t,n){let r=[],o=new Set;for(let i of t){let s=mn(i.dataset.sectionIndex,0);o.has(s)||(o.add(s),r.push(s));}return Dw(e.sections,r,n)}function Dw(e,t,n){var i,s;let r=new Map,o=1;for(let a of t){let l=e.find(u=>u.sectionIndex===a),c=(i=l==null?void 0:l.pageNumberStart)!=null?i:o;r.set(a,c),o=c+((s=n.get(a))!=null?s:0);}return r}function su(e,t){let n=Number(e);return Number.isInteger(n)&&n>0?n:t}function mn(e,t){let n=Number(e);return Number.isInteger(n)&&n>=0?n:t}function Fw(e){return e.blocks.some(t=>t.kind==="table"?t.rows.length>0:t.content.some(n=>n.kind==="text"?n.text.trim().length>0:(n.kind==="field",true)))}function Vr(e,t={}){return e.kind==="paragraph"?Gr(e,t):Ou(e)}function Gr(e,t={}){var s,a,l,c,u,f,p,w,b,g,h,y;let n=document.createElement("coco-word-native-p");n.setAttribute("data-para-id",e.paraId),n.setAttribute("data-story",e.story),e.styleId&&n.setAttribute("data-style-id",e.styleId),((s=e.format)==null?void 0:s.outlineLevel)!==void 0&&n.setAttribute("data-outline-level",String(e.format.outlineLevel)),(a=e.format)!=null&&a.hasNumbering&&(n.setAttribute("data-numbering","true"),n.setAttribute("data-numbering-label",(c=(l=e.format.numbering)==null?void 0:l.label)!=null?c:"\u2022")),(u=e.format)!=null&&u.pageBreakBefore&&n.setAttribute("data-page-break-before","true"),(f=e.format)!=null&&f.hasSectionBreak&&n.setAttribute("data-section-break","true"),(p=e.format)!=null&&p.keepNext&&n.setAttribute("data-keep-next","true"),(w=e.format)!=null&&w.keepLines&&n.setAttribute("data-keep-lines","true"),((b=e.format)==null?void 0:b.widowControl)!==void 0&&n.setAttribute("data-widow-control",String(e.format.widowControl)),((g=e.format)==null?void 0:g.snapToGrid)!==void 0&&n.setAttribute("data-snap-to-grid",String(e.format.snapToGrid));let r=Hw(e,t)?$(v({},e.format),{snapToGrid:true,spacing:$(v({},(y=(h=e.format)==null?void 0:h.spacing)!=null?y:{}),{line:t.implicitGridLinePitch,lineRule:"exact"})}):e.format,o=Cr(r).cssText;o.length>0&&n.setAttribute("style",o),n.contentEditable="inherit",n.tabIndex=0,n.setAttribute("role","textbox"),n.spellcheck=false;let i=$w(e);if(i)return n.classList.add("has-tab-stops"),n.appendChild(i),n;for(let k of e.content)if(k.kind==="text")n.appendChild(xs(k));else if(k.kind==="field")n.appendChild(Fu(k));else if(k.kind==="image")n.appendChild(ws(k));else if(k.kind==="drawing")n.appendChild(jw(k));else {let C=document.createElement("span");C.className="coco-word-page-break",C.contentEditable="false",C.setAttribute("data-kind","page-break"),C.setAttribute("aria-label","Page break"),n.appendChild(C);}return n.childNodes.length===0&&n.appendChild(document.createTextNode("")),n}function ws(e){var r,o,i,s;let t=document.createElement("img"),n=Br(e.src);return n&&(t.src=n),t.alt=e.drawingId,t.dataset.drawingId=e.drawingId,e.revision&&(t.classList.add(e.revision.revisionKind==="delete"?"coco-word-revision-delete":"coco-word-revision-insert"),t.dataset.revisionId=e.revision.revisionId,t.dataset.revisionKind=e.revision.revisionKind,t.dataset.revisionAuthor=(r=e.revision.author)!=null?r:"",t.dataset.revisionDate=(o=e.revision.date)!=null?o:"",t.dataset.revisionText="\u56FE\u7247"),e.formatRevision&&(t.classList.add("coco-word-revision-format"),t.dataset.revisionId=e.formatRevision.revisionId,t.dataset.revisionKind="format",t.dataset.revisionAuthor=(i=e.formatRevision.author)!=null?i:"",t.dataset.revisionDate=(s=e.formatRevision.date)!=null?s:"",t.dataset.revisionText="\u56FE\u7247\u5C3A\u5BF8"),e.anchoringMode&&(t.dataset.anchoringMode=e.anchoringMode),e.wrap&&(t.dataset.wrap=e.wrap),e.width&&(t.style.width=`${e.width}px`),e.height&&(t.style.height=`${e.height}px`),ex(t,e),t}function Hw(e,t){var n,r,o;return !t.implicitGridForParagraphs||((n=e.format)==null?void 0:n.snapToGrid)!==void 0?false:((o=(r=e.format)==null?void 0:r.spacing)==null?void 0:o.line)===void 0&&t.implicitGridLinePitch!==void 0}function Ow(e){var t;return e.kind==="paragraph"?((t=e.format)==null?void 0:t.snapToGrid)===false:e.rows.some(n=>n.cells.some(r=>r.paragraphs.some(o=>{var i;return ((i=o.format)==null?void 0:i.snapToGrid)===false})))}function $w(e){var c,u,f;let t=(c=e.format)==null?void 0:c.tabStops;if(!t||t.length===0)return null;let n=e.content.reduce((p,w)=>p+(w.kind==="text"?Gw(w.text):0),0);if(n!==1&&n!==2||!e.content.every(p=>p.kind==="text"))return null;let r=t.find(p=>p.alignment==="right");if(!r)return null;let o=r.leader!==void 0&&r.leader!=="none",i=zw(e);if(!o&&!Vw(i))return null;let s=document.createElement("span");s.className=n===2?"coco-word-tab-row is-three-part-tab":"coco-word-tab-row is-right-tab",s.style.setProperty("--coco-word-tab-stop",Rn(r.position)),o&&(s.classList.add(`has-leader-${r.leader}`),s.dataset.tabLeader=r.leader);let a=Array.from({length:n+1},(p,w)=>{let b=document.createElement("span");return b.className=`coco-word-tab-segment is-segment-${w}`,b}),l=0;for(let p of e.content){if(p.kind!=="text")continue;let w=p.text.split(" ");for(let b=0;b<w.length;b++){let g=(u=w[b])!=null?u:"";g.length>0&&((f=a[l])==null||f.appendChild(xs($(v({},p),{text:g})))),b<w.length-1&&(l=Math.min(l+1,a.length-1));}}for(let p=0;p<a.length;p++){if(p>0){let w=document.createElement("span");w.className="coco-word-tab-marker",w.textContent=" ",s.appendChild(w);}s.appendChild(a[p]);}return s}function zw(e){var n,r;let t=[""];for(let o of e.content){if(o.kind!=="text")continue;let i=o.text.split(" ");t[t.length-1]+=(n=i[0])!=null?n:"";for(let s=1;s<i.length;s++)t.push((r=i[s])!=null?r:"");}return t}function Vw(e){return e.length<2||e.length>3?false:e.every(t=>t.trim().length<=32)}function Gw(e){return e.split(" ").length-1}function jw(e){var i,s,a,l;let t=document.createElement("coco-word-native-drawing");if(t.contentEditable="false",t.dataset.drawingId=e.drawingId,t.dataset.drawingKind=e.drawingKind,e.anchoringMode&&(t.dataset.anchoringMode=e.anchoringMode),e.wrap&&(t.dataset.wrap=e.wrap),t.classList.add(`is-${e.drawingKind.toLowerCase()}`),e.hasBorder&&t.classList.add("has-border"),e.hasFill&&t.classList.add("has-fill"),e.isLineOrConnector){t.classList.add("is-line-or-connector");let c=Kw(e);t.classList.add(c.vertical?"is-vertical-line":"is-horizontal-line"),t.style[c.property]=c.value;}let n=((s=(i=e.text)==null?void 0:i.trim().length)!=null?s:0)>0||((l=(a=e.paragraphs)==null?void 0:a.some(c=>c.content.some(u=>u.kind==="text"&&u.text.trim().length>0)))!=null?l:false);(e.drawingKind==="textBox"&&!n&&!e.hasBorder||!n&&!e.hasBorder&&!e.hasFill&&!e.isLineOrConnector)&&t.classList.add("is-empty");let o=qw(e);if(o&&(t.style.width=o),e.isLineOrConnector?e.height&&(t.style.height=`${e.height}px`):e.height&&_w(e)&&(t.style.minHeight=`${e.height}px`),Qw(t,e),e.paragraphs&&e.paragraphs.length>0)for(let c of e.paragraphs)t.appendChild(Yw(c));else if(e.text&&e.text.length>0){let c=document.createElement("span");c.className="coco-word-native-drawing-text",e.innerTextAlign&&(c.style.textAlign=ox(e.innerTextAlign)),c.textContent=e.text,t.appendChild(c);}else t.setAttribute("aria-label",e.drawingKind);return t}function Uw(e){var t,n;return ((t=e.height)!=null?t:0)>Math.max(1,((n=e.width)!=null?n:0)*2)}function Kw(e){var n,r;let t=Uw(e);return {vertical:t,property:t?"borderLeft":"borderTop",value:`${(n=e.strokeWidth)!=null?n:1}px solid ${(r=e.strokeColor)!=null?r:"#111827"}`}}function _w(e){return !(e.drawingKind==="textBox"&&!e.hasBorder&&!e.hasFill)}function qw(e){if(!e.width)return;if(e.anchoringMode==="anchor"&&Xw(e.wrap))return `${e.width}px`;let t=e.isLineOrConnector?"100%":"max(1px, calc(100% - 4pt))";return `min(${e.width}px, ${t})`}function Xw(e){return e==="none"||e==="behind"||e==="inFront"}function Yw(e){let t=document.createElement("div");t.className="coco-word-native-drawing-paragraph";let n=Cr(e.format).cssText;n.length>0&&t.setAttribute("style",n);for(let r of e.content)r.kind==="text"?t.appendChild(xs(r)):r.kind==="field"?t.appendChild(Fu(r)):(r.kind==="image"||r.kind==="drawing")&&t.appendChild(document.createTextNode(r.kind==="drawing"&&r.text?r.text:"\uFFFC"));return t}function xs(e){var s,a,l,c,u,f,p,w,b;if(e.kind!=="text")return document.createTextNode("");let t=Un(e.format).cssText,n=(s=e.marks)==null?void 0:s.find(g=>g.kind==="comment"),r=(a=e.marks)==null?void 0:a.find(g=>g.kind==="revision"),o=e.formatRevision;if(!n&&!r&&!o&&!e.hyperlink&&t.length===0)return document.createTextNode(e.text);let i=e.hyperlink?document.createElement("a"):document.createElement("span");if(t.length>0&&i.setAttribute("style",t),e.hyperlink){let g=Dr(e.hyperlink.target,e.hyperlink.anchor);i.classList.add("coco-word-hyperlink"),i.setAttribute("href",g),i.dataset.hyperlinkTarget=(l=e.hyperlink.target)!=null?l:"",i.dataset.hyperlinkAnchor=(c=e.hyperlink.anchor)!=null?c:"",e.hyperlink.tooltip&&(i.title=e.hyperlink.tooltip),e.hyperlink.target&&(i.setAttribute("target","_blank"),i.setAttribute("rel","noopener noreferrer"));}return n&&(i.classList.add("coco-word-comment"),i.dataset.commentId=String(n.commentId),i.dataset.commentAuthor=n.author,i.dataset.commentDate=n.date,i.dataset.commentBody=n.body,n.parentCommentId!==void 0&&(i.dataset.parentCommentId=String(n.parentCommentId),i.classList.add("coco-word-comment-reply")),i.title=Zw(n)),r&&(i.classList.add(r.revisionKind==="delete"?"coco-word-revision-delete":"coco-word-revision-insert"),i.dataset.revisionId=(u=r.revisionId)!=null?u:"",i.dataset.revisionKind=r.revisionKind,i.dataset.revisionAuthor=(f=r.author)!=null?f:"",i.dataset.revisionDate=(p=r.date)!=null?p:"",i.title=Jw(r)),o&&(i.classList.add("coco-word-revision-format"),i.dataset.revisionId=o.revisionId,i.dataset.revisionKind="format",i.dataset.revisionAuthor=(w=o.author)!=null?w:"",i.dataset.revisionDate=(b=o.date)!=null?b:"",i.title="\u683C\u5F0F\u4FEE\u8BA2"),i.appendChild(document.createTextNode(e.text)),i}function Fu(e){var r;let t=document.createElement("span");t.className="coco-word-native-field",t.dataset.fieldKind=e.fieldKind,t.dataset.fieldInstruction=e.instruction;let n=Un(e.format).cssText;return n.length>0&&t.setAttribute("style",n),t.contentEditable="false",t.textContent=(r=e.cachedText)!=null?r:"",t}function Zw(e){var r,o;let t=e.author?`${e.author}: `:"",n=(o=(r=e.body)==null?void 0:r.trim())!=null?o:"";return n.length>0?`Comment ${e.commentId} ${t}${n}`:`Comment ${e.commentId}`}function Jw(e){let t=e.revisionKind==="delete"?"Deleted":"Inserted",n=e.author?` by ${e.author}`:"",r=e.date?` on ${e.date}`:"",o=e.revisionId?` (${e.revisionId})`:"";return `${t}${n}${r}${o}`}function Qw(e,t){t.anchoringMode==="anchor"&&(e.classList.add("coco-word-anchor-drawing"),Hu(e,t));}function ex(e,t){t.anchoringMode==="anchor"&&(e.classList.add("coco-word-anchor-image"),Hu(e,t));}function Hu(e,t){let n=tx(t);for(let r of n.classNames)e.classList.add(r);for(let[r,o]of Object.entries(n.dataset))e.dataset[r]=o;for(let[r,o]of Object.entries(n.styleProperties))e.style.setProperty(r,o);}function tx(e){var a,l,c,u;let t=[],n={},r={};nx(e.position,n,r);let o=rx(e.position),i=(l=(a=e.position)==null?void 0:a.horizontal)==null?void 0:l.relativeFrom,s=(u=(c=e.position)==null?void 0:c.vertical)==null?void 0:u.relativeFrom;return e.wrap==="square"||e.wrap==="tight"||e.wrap==="through"?o==="left"?t.push("is-float-left"):o==="right"?t.push("is-float-right"):o==="center"?t.push("is-centered"):t.push("is-float-right"):e.wrap==="behind"||e.wrap==="inFront"||e.wrap==="none"?(t.push("is-overlay-like"),t.push("is-absolute-anchor"),us(s)?t.push("is-page-relative-anchor"):t.push("is-paragraph-relative-anchor"),i==="column"&&t.push("is-column-relative-anchor"),o==="left"&&t.push("is-anchor-left"),o==="right"&&t.push("is-anchor-right"),o==="center"&&t.push("is-anchor-center"),e.wrap==="behind"&&t.push("is-behind-text"),e.wrap==="inFront"&&t.push("is-in-front-of-text")):e.wrap==="topAndBottom"&&(t.push("is-top-bottom"),o==="center"&&t.push("is-centered")),{classNames:t,dataset:n,styleProperties:r}}function nx(e,t,n){let r=e==null?void 0:e.horizontal,o=e==null?void 0:e.vertical;r!=null&&r.relativeFrom&&(t.positionHorizontalRelativeFrom=r.relativeFrom),o!=null&&o.relativeFrom&&(t.positionVerticalRelativeFrom=o.relativeFrom),r!=null&&r.align&&(t.positionHorizontalAlign=r.align),o!=null&&o.align&&(t.positionVerticalAlign=o.align),(r==null?void 0:r.posOffset)!==void 0&&(t.positionHorizontalOffset=String(r.posOffset),n["--coco-word-anchor-left"]=`${ps(r.posOffset)}px`),(o==null?void 0:o.posOffset)!==void 0&&(t.positionVerticalOffset=String(o.posOffset),n["--coco-word-anchor-top"]=`${ps(o.posOffset)}px`);}function rx(e){let t=e==null?void 0:e.horizontal;if(!t)return null;if(t.align==="left"||t.align==="inside")return "left";if(t.align==="right"||t.align==="outside")return "right";if(t.align==="center")return "center";if(t.posOffset===void 0)return null;let n=ps(t.posOffset);return n<=8?"left":n>=240?"right":null}function ox(e){return e==="both"?"justify":e}function Ou(e){var s,a,l,c;let t=document.createElement("coco-word-native-table");t.setAttribute("data-table-id",e.tableId),e.revision&&(t.classList.add(e.revision.revisionKind==="delete"?"coco-word-revision-delete":"coco-word-revision-insert"),t.dataset.revisionId=e.revision.revisionId,t.dataset.revisionKind=e.revision.revisionKind,t.dataset.revisionAuthor=(s=e.revision.author)!=null?s:"",t.dataset.revisionDate=(a=e.revision.date)!=null?a:"",t.dataset.revisionText="\u8868\u683C\u7ED3\u6784"),e.tableStyleId&&t.setAttribute("data-style-id",e.tableStyleId);let n=document.createElement("table"),r=dx(e);if(r&&n.style.setProperty("--coco-word-table-border",r),lx(n,e),e.columnWidths.some(u=>u>0)){let u=document.createElement("colgroup"),f=0;for(let p of e.columnWidths)f+=Math.max(0,p);for(let p of e.columnWidths){let w=document.createElement("col");p>0&&(w.style.width=((l=e.layout)==null?void 0:l.widthType)==="pct"&&f>0?`${p/f*100}%`:Rn(p)),u.appendChild(w);}n.appendChild(u),f>0&&n.style.width.length===0&&(n.style.width=Rn(f));}let o=document.createElement("tbody"),i=ix(e);for(let u=0;u<e.rows.length;u+=1){let f=e.rows[u],p=document.createElement("tr");if(p.dataset.rowIndex=String(u),f.isHeader&&(p.dataset.repeatHeader="true"),f.cantSplit&&(p.dataset.cantSplit="true"),f.height&&f.height.val>0){let b=Rn(f.height.val);p.dataset.heightRule=(c=f.height.hRule)!=null?c:"auto",p.style.setProperty("--coco-word-row-height",b),f.height.hRule,p.style.height=b;}let w=0;for(let b of f.cells){let g=Math.max(1,b.gridSpan),h=w;if(w+=g,b.vMerge==="continue")continue;let y=document.createElement("td");y.dataset.rowIndex=String(u),y.dataset.cellIndex=String(f.cells.indexOf(b)),y.dataset.columnIndex=String(h),b.gridSpan>1&&(y.colSpan=b.gridSpan),b.rowSpan&&b.rowSpan>1&&(y.rowSpan=b.rowSpan);let k=Vo($(v({},b),{borders:ax(e,b,{rowIndex:u,rowCount:e.rows.length,columnIndex:h,columnSpan:g,columnCount:i})})).cssText;k.length>0&&y.setAttribute("style",k),y.contentEditable="true";for(let C of b.blocks){let N=Vr(C);for(let L of [...N.matches("coco-word-native-p")?[N]:[],...Array.from(N.querySelectorAll("coco-word-native-p"))])L.contentEditable="true";y.appendChild(N);}p.appendChild(y);}o.appendChild(p);}return n.appendChild(o),t.appendChild(n),bs(t),t}function ix(e){let t=e.columnWidths.filter(n=>n>0).length;return t>0?t:Math.max(1,...e.rows.map(n=>n.cells.reduce((r,o)=>r+Math.max(1,o.gridSpan),0)))}function ax(e,t,n){var o;let r=e.borders;if(!(!r&&!t.borders))return v(v({},sx(r,n)),(o=t.borders)!=null?o:{})}function sx(e,t){var a,l,c,u;if(!e)return {};let n={val:"nil"},r=t.rowIndex===0,o=t.rowIndex>=t.rowCount-1,i=t.columnIndex===0,s=t.columnIndex+t.columnSpan>=t.columnCount;return {top:(a=r?e.top:e.insideH)!=null?a:n,right:(l=s?e.right:e.insideV)!=null?l:n,bottom:(c=o?e.bottom:e.insideH)!=null?c:n,left:(u=i?e.left:e.insideV)!=null?u:n}}function lx(e,t){let n=t.layout;n&&(n.width!==void 0&&n.width>0&&(n.widthType==="pct"?e.style.width=`${n.width/50}%`:n.widthType!=="auto"&&(e.style.width=Rn(n.width))),n.alignment==="center"?(e.style.marginLeft="auto",e.style.marginRight="auto"):n.alignment==="right"?(e.style.marginLeft="auto",e.style.marginRight="0"):n.indent!==void 0&&n.indent>0&&(e.style.marginLeft=Rn(n.indent)),n.cellSpacing!==void 0&&n.cellSpacing>0&&(e.style.borderCollapse="separate",e.style.borderSpacing=n.cellSpacingType==="pct"?`${n.cellSpacing/50}%`:Rn(n.cellSpacing)));}function Rn(e){return `${e/20}pt`}function vt(e){return `${ys(e)}px`}function ys(e){return e/15}function ps(e){return e/914400*96}function dx(e){var i,s,a,l,c,u,f,p,w,b,g;let t=(g=(w=(f=(c=(a=(i=e.borders)==null?void 0:i.insideH)!=null?a:(s=e.borders)==null?void 0:s.insideV)!=null?c:(l=e.borders)==null?void 0:l.top)!=null?f:(u=e.borders)==null?void 0:u.left)!=null?w:(p=e.borders)==null?void 0:p.bottom)!=null?g:(b=e.borders)==null?void 0:b.right;if(!t||t.val==="none"||t.val==="nil")return null;let n=t.color&&/^[0-9a-f]{6}$/i.test(t.color)?`#${t.color}`:"#d4d4d8",r=t.size!==void 0?Math.max(.5,t.size/8):.75,o=t.val==="double"?"double":"solid";return `${r}pt ${o} ${n}`}function Mn(e){customElements.get(e)||customElements.define(e,class extends HTMLElement{});}function kt(e){var n,r;let t=e.getRootNode();return t instanceof ShadowRoot?(r=(n=t.getSelection)==null?void 0:n.call(t))!=null?r:null:e.ownerDocument.getSelection()}function ut(e){var o;let t=kt(e);if(!t||t.rangeCount===0)return null;let n=t.getRangeAt(0),r=St(n.startContainer);return !r||!e.contains(r)?null:{paraId:(o=r.dataset.paraId)!=null?o:"",offset:ii(r,n.startContainer,n.startOffset)}}function st(e){let t=ut(e);return t?{kind:"caret",paraId:t.paraId,offset:t.offset}:null}function ze(e){var s,a;let t=kt(e);if(!t||t.rangeCount===0||!t.anchorNode||!t.focusNode)return null;let n=St(t.anchorNode),r=St(t.focusNode);if(!n||!r||!e.contains(n)||!e.contains(r))return null;let o={paraId:(s=n.dataset.paraId)!=null?s:"",offset:ii(n,t.anchorNode,t.anchorOffset)},i={paraId:(a=r.dataset.paraId)!=null?a:"",offset:ii(r,t.focusNode,t.focusOffset)};return t.isCollapsed?{kind:"caret",paraId:o.paraId,offset:o.offset}:{kind:"text-range",anchor:o,focus:i}}function zu(e,t,n){var i;let r=cx(t,n);if(!r)return null;let o=St(r.node);return !o||!e.contains(o)?null:{paraId:(i=o.dataset.paraId)!=null?i:"",offset:ii(o,r.node,r.offset)}}function lt(e,t){let n=e.querySelector(`coco-word-native-p[data-para-id="${t.paraId}"]`);if(!n)return;n.focus({preventScroll:true});let r=document.createRange(),o=Ln(n,t.offset);r.setStart(o.node,o.offset),r.setEnd(o.node,o.offset);let i=kt(e);i&&(i.removeAllRanges(),i.addRange(r));}function gn(e,t,n){let r=e.querySelector(`coco-word-native-p[data-para-id="${t.paraId}"]`),o=e.querySelector(`coco-word-native-p[data-para-id="${n.paraId}"]`);if(!r||!o)return;let i=Ln(r,t.offset),s=Ln(o,n.offset),a=kt(e);a&&(r.focus({preventScroll:true}),a.removeAllRanges(),a.setBaseAndExtent(i.node,i.offset,s.node,s.offset));}function Vu(e,t){let n=St(t);if(!n||!e.contains(n))return false;let r=document.createRange();r.selectNodeContents(t);let o=kt(e);return o?(n.focus({preventScroll:true}),o.removeAllRanges(),o.addRange(r),true):false}function Gu(e,t,n,r){let o=e.querySelector(`coco-word-native-p[data-para-id="${t}"]`);if(!o)return null;let i=Ln(o,n),s=Ln(o,r),a=document.createRange();return a.setStart(i.node,i.offset),a.setEnd(s.node,s.offset),a}function vs(e,t,n){let r=e.querySelector(`coco-word-native-p[data-para-id="${t.paraId}"]`),o=e.querySelector(`coco-word-native-p[data-para-id="${n.paraId}"]`);if(!r||!o)return null;let i=Ln(r,t.offset),s=Ln(o,n.offset),a=document.createRange();return a.setStart(i.node,i.offset),a.setEnd(s.node,s.offset),a}function cx(e,t){var i,s;let n=document,r=(i=n.caretPositionFromPoint)==null?void 0:i.call(n,e,t);if(r)return {node:r.offsetNode,offset:r.offset};let o=(s=n.caretRangeFromPoint)==null?void 0:s.call(n,e,t);return o?{node:o.startContainer,offset:o.startOffset}:null}function ju(e,t){Et(e);let n=e.querySelector(`coco-word-native-p[data-para-id="${t.paraId}"] img[data-drawing-id="${t.drawingId}"]`);n==null||n.classList.add("is-selected");}function Et(e){e.querySelectorAll("coco-word-native-p img.is-selected").forEach(t=>{t.classList.remove("is-selected");});}function ai(e,t){var i,s;let n=0,r=document.createTreeWalker(e,NodeFilter.SHOW_TEXT|NodeFilter.SHOW_ELEMENT),o=r.nextNode();for(;o;){if(o===t)return n;o.nodeType===Node.TEXT_NODE?n+=(s=(i=o.textContent)==null?void 0:i.length)!=null?s:0:o instanceof HTMLImageElement&&(n+=1),o=r.nextNode();}return n}function St(e){let t=e.nodeType===Node.ELEMENT_NODE?e:e.parentNode;for(;t;){if(t instanceof HTMLElement&&t.tagName==="COCO-WORD-NATIVE-P")return t;t=t.parentNode;}return null}function ii(e,t,n){let r=0,o=null,i=s=>{var a,l,c,u;if(o===null){if(s===t){if(s.nodeType===Node.TEXT_NODE){o=r+Math.max(0,Math.min(n,(l=(a=s.textContent)==null?void 0:a.length)!=null?l:0));return}let f=Math.max(0,Math.min(n,s.childNodes.length));for(let p=0;p<f;p+=1)r+=Uu(s.childNodes[p]);o=r;return}if(s.nodeType===Node.TEXT_NODE){r+=(u=(c=s.textContent)==null?void 0:c.length)!=null?u:0;return}if(Ss(s)){r+=1;return}for(let f=0;f<s.childNodes.length;f+=1)i(s.childNodes[f]);}};return i(e),o!=null?o:r}function Uu(e){var n,r;if(e.nodeType===Node.TEXT_NODE)return (r=(n=e.textContent)==null?void 0:n.length)!=null?r:0;if(Ss(e))return 1;let t=0;for(let o=0;o<e.childNodes.length;o+=1)t+=Uu(e.childNodes[o]);return t}function Ln(e,t){var s,a;let n=document.createTreeWalker(e,NodeFilter.SHOW_TEXT|NodeFilter.SHOW_ELEMENT),r=n.nextNode(),o=t;for(;r;){if(r.nodeType===Node.TEXT_NODE){let l=(a=(s=r.textContent)==null?void 0:s.length)!=null?a:0;if(o<=l)return {node:r,offset:o};o-=l;}else if(Ss(r)){if(o===0)return $u(r,"before");if(o===1)return $u(r,"after");o-=1;}r=n.nextNode();}let i=document.createTextNode("");return e.appendChild(i),{node:i,offset:0}}function Ss(e){return e instanceof HTMLElement&&(e instanceof HTMLImageElement||e.classList.contains("coco-word-page-break"))}function $u(e,t){let n=e.parentNode;if(!n)return {node:e,offset:0};let r=Array.prototype.indexOf.call(n.childNodes,e);return {node:n,offset:Math.max(0,r+(t==="after"?1:0))}}function ks(e,t){if(t.query.length===0)return [];let n=t.matchCase?"gu":"giu",r=new RegExp(px(t.query),n),o=[];for(let i of _u(e.blocks)){let s=Te(i);for(let a of s.matchAll(r)){let l=a.index,c=l+a[0].length;t.wholeWord&&!ux(s,l,c)||o.push({id:`${i.paraId}:${l}:${c}`,paraId:i.paraId,from:l,to:c,text:a[0]});}}return o}function _u(e){return e.flatMap(t=>t.kind==="paragraph"?[t]:t.rows.flatMap(n=>n.cells.flatMap(r=>_u(r.blocks))))}function ux(e,t,n){let r=t>0?e[t-1]:"",o=n<e.length?e[n]:"";return !Ku(r)&&!Ku(o)}function Ku(e){return e.length>0&&/[\p{L}\p{N}_]/u.test(e)}function px(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var si="application/x-coco-word-blocks+json";function Xu(e){let t=new DOMParser().parseFromString(e,"text/html"),n=Array.from(t.body.querySelectorAll("p, li, h1, h2, h3, h4, h5, h6")).filter(o=>o.tagName!=="LI"||!o.querySelector("p"));return (n.length>0?n:[t.body]).map(o=>{var a;let i={text:"",runs:[]},s=o.closest("li");return s&&(i.listType=((a=s.parentElement)==null?void 0:a.tagName)==="OL"?"numbered":"bullet"),ep(o,{},i),i.text=i.text.replace(/\u00a0/g," "),i})}function Is(e){var r;let t="",n=null;for(let o of e){o.listType!==n&&(n&&(t+=n==="numbered"?"</ol>":"</ul>"),n=(r=o.listType)!=null?r:null,n&&(t+=n==="numbered"?"<ol>":"<ul>"));let i=mx(o);t+=n?`<li>${i}</li>`:`<p>${i}</p>`;}return n&&(t+=n==="numbered"?"</ol>":"</ul>"),t}function Ns(e){return JSON.stringify({version:1,blocks:e})}function Yu(e){if(!e||e.length>2e7)return null;try{let t=JSON.parse(e);return !jr(t)||t.version!==1||!Array.isArray(t.blocks)||t.blocks.length===0||t.blocks.length>1e3?null:t.blocks.every(Ju)?t.blocks:null}catch(t){return null}}function Ts(e){return e.map(Zu).join(`
15
+ `)}function Zu(e){return e.kind==="paragraph"?Te(e):e.rows.map(t=>t.cells.map(n=>n.blocks.map(Zu).join(`
9
16
  `)).join(" ")).join(`
10
- `)}function qu(e){return zr(e)?e.kind==="paragraph"?typeof e.paraId=="string"&&typeof e.story=="string"&&Array.isArray(e.content)&&e.content.length<=1e5&&e.content.every(rx):e.kind!=="table"||typeof e.tableId!="string"||!Array.isArray(e.rows)||e.rows.length>1e4?false:e.rows.every(t=>zr(t)&&Array.isArray(t.cells)&&t.cells.length<=1e3&&t.cells.every(n=>zr(n)&&Array.isArray(n.blocks)&&n.blocks.length<=1e4&&n.blocks.every(qu))):false}function rx(e){return !zr(e)||typeof e.kind!="string"?false:e.kind==="text"?typeof e.text=="string":e.kind==="image"?typeof e.drawingId=="string"&&typeof e.src=="string":e.kind==="drawing"?typeof e.drawingId=="string":e.kind==="pageBreak"?true:e.kind==="field"?typeof e.fieldKind=="string"&&typeof e.instruction=="string":false}function zr(e){return typeof e=="object"&&e!==null}function ox(e){let t="",n=0,r=[...e.runs].map(o=>$(v({},o),{from:Math.max(0,o.from),to:Math.min(e.text.length,o.to)})).filter(o=>o.to>o.from).sort((o,i)=>o.from-i.from||o.to-i.to);for(let o of r){if(o.from>n&&(t+=ys(e.text.slice(n,o.from))),o.from<n)continue;let i=ys(e.text.slice(o.from,o.to)),s=ix(o.format),a=s?`<span style="${vs(s)}">${i}</span>`:i;if(o.hyperlink){let l=Lr(o.hyperlink.target,o.hyperlink.anchor),c=o.hyperlink.tooltip?` title="${vs(o.hyperlink.tooltip)}"`:"";a=`<a href="${vs(l)}"${c}>${a}</a>`;}t+=a,n=o.to;}return n<e.text.length&&(t+=ys(e.text.slice(n))),t||"<br>"}function ix(e){let t=[];e.bold!==void 0&&t.push(`font-weight:${e.bold?"700":"400"}`),e.italic!==void 0&&t.push(`font-style:${e.italic?"italic":"normal"}`);let n=[];return e.underline&&n.push("underline"),(e.strike||e.doubleStrike)&&n.push("line-through"),n.length>0?t.push(`text-decoration-line:${n.join(" ")}`):(e.underline===false||e.strike===false||e.doubleStrike===false)&&t.push("text-decoration-line:none"),e.fontFamily&&t.push(`font-family:${e.fontFamily}`),e.fontSize!==void 0&&t.push(`font-size:${e.fontSize}pt`),e.color&&t.push(`color:#${e.color.replace(/^#/,"")}`),e.highlight&&e.highlight!=="none"&&t.push(`background-color:#${e.highlight.replace(/^#/,"")}`),e.verticalAlign&&t.push(`vertical-align:${e.verticalAlign}`),e.caps&&t.push("text-transform:uppercase"),e.smallCaps&&t.push("font-variant-caps:small-caps"),e.characterSpacing!==void 0&&t.push(`letter-spacing:${e.characterSpacing/20}pt`),t.join(";")}function ys(e){return Xu(e).replace(/\r\n?|\n/g,"<br>")}function Xu(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function vs(e){return Xu(e).replace(/"/g,"&quot;")}function Yu(e,t,n,r){var s;if(e.nodeType===Node.TEXT_NODE){let a=(s=e.textContent)!=null?s:"";if(!a)return;let l=n.text.length;n.text+=a,(Object.keys(t).length>0||r)&&n.runs.push(v({from:l,to:n.text.length,format:t},r?{hyperlink:r}:{}));return}if(!(e instanceof HTMLElement))return;if(e.tagName==="BR"){n.text+=`
11
- `;return}let o=v(v({},t),sx(e)),i=e.tagName==="A"?ax(e):r;for(let a of Array.from(e.childNodes))Yu(a,o,n,i);}function ax(e){var o,i;let t=(o=e.getAttribute("href"))==null?void 0:o.trim();if(!t)return;let n=(i=e.getAttribute("title"))==null?void 0:i.trim();if(t.startsWith("#")){let s=t.slice(1);try{s=decodeURIComponent(s);}catch(a){return}return s?v({anchor:s},n?{tooltip:n}:{}):void 0}let r=Lr(t,void 0);return r==="#"?void 0:v({target:r},n?{tooltip:n}:{})}function sx(e){let t=e.style,n={};(e.matches("b, strong")||Number.parseInt(t.fontWeight,10)>=600)&&(n.bold=true),(e.matches("i, em")||t.fontStyle==="italic")&&(n.italic=true);let r=t.textDecorationLine||t.textDecoration;(e.matches("u")||r.includes("underline"))&&(n.underline=true),(e.matches("s, strike, del")||r.includes("line-through"))&&(n.strike=true),t.fontFamily&&(n.fontFamily=t.fontFamily.replace(/["']/g,""));let o=lx(t.fontSize);o!==null&&(n.fontSize=o);let i=ju(t.color),s=ju(t.backgroundColor);return i&&(n.color=i),s&&(n.highlight=s),n}function ju(e){let t=e.trim();if(!t||t==="transparent")return null;let n=/^#([\da-f]{3}|[\da-f]{6})$/i.exec(t);if(n){let o=n[1];return (o.length===3?o.split("").map(i=>i+i).join(""):o).toUpperCase()}let r=/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/i.exec(t);return r?r.slice(1,4).map(o=>Math.max(0,Math.min(255,Number(o))).toString(16).padStart(2,"0")).join("").toUpperCase():null}function lx(e){var r;let t=/^([\d.]+)(pt|px)$/i.exec(e.trim());if(!t)return null;let n=Number(t[1]);return Number.isFinite(n)?((r=t[2])==null?void 0:r.toLowerCase())==="px"?n*.75:n:null}var Ms="http://www.w3.org/XML/1998/namespace",Bn="http://schemas.openxmlformats.org/officeDocument/2006/relationships",$t="http://schemas.openxmlformats.org/package/2006/relationships",Pt="http://schemas.openxmlformats.org/drawingml/2006/main",Yn="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",qn="http://schemas.openxmlformats.org/drawingml/2006/picture",ii="http://schemas.openxmlformats.org/package/2006/content-types",op="application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",Zu="application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml",Ju="http://schemas.microsoft.com/office/2011/relationships/commentsExtended",tn="http://schemas.microsoft.com/office/word/2012/wordml",Qu=`${Bn}/hyperlink`,ip="application/vnd.openxmlformats-package.relationships+xml";function cx(e){let t=[],n=[],r=new Map;for(let o of e)o.kind==="table"&&o.revisionId&&o.revisionAction&&r.set(o.revisionId,o.revisionAction);for(let o of e){if(o.kind==="table"&&o.revisionAction||o.kind==="table"&&o.revisionId&&r.get(o.revisionId)==="reject")continue;let i=ux(o,{allowTrackedTable:o.kind==="table"&&!!o.revisionId&&r.get(o.revisionId)==="accept"});i?t.push(i):n.push({change:o,reason:mx(o)});}return {target:"word/document.xml",patches:t,unsupported:n}}function eC(e,t,n=wordView.buildIndices(e)){let r=cx(t),o=fx(e,n,r.patches);return v({plan:r},o)}function ux(e,t={}){var n;if(e.kind==="text")return v({kind:"paragraph-text",op:e.op,paraId:e.paraId,offset:e.offset,text:e.text},e.deletedText!==void 0?{deletedText:e.deletedText}:{});if(e.kind==="format"&&e.op==="run"&&e.revisionId&&e.revisionKind==="format")return v({kind:"format-revision",op:"run",paraId:e.paraId,from:e.from,to:e.to,revisionId:e.revisionId},e.beforeFormat!==void 0?{beforeFormat:e.beforeFormat}:{});if(e.kind==="format"&&e.op==="run")return {kind:"paragraph-format",paraId:e.paraId,from:e.from,to:e.to,format:e.format};if(e.kind==="format"&&(e.op==="accept"||e.op==="reject")&&e.revisionId)return {kind:"format-revision",op:e.op,paraId:e.paraId,from:e.from,to:e.to,revisionId:e.revisionId};if(e.kind==="image"&&e.op==="delete")return {kind:"drawing-delete",paraId:e.paraId,drawingId:e.drawingId,offset:e.offset};if(e.kind==="image"&&e.op==="resize"&&e.width&&e.height)return {kind:"drawing-resize",paraId:e.paraId,drawingId:e.drawingId,offset:e.offset,width:e.width,height:e.height};if(e.kind==="image"&&e.op==="insert"&&e.src&&e.width&&e.height)return {kind:"drawing-insert",paraId:e.paraId,drawingId:e.drawingId,offset:e.offset,src:e.src,width:e.width,height:e.height};if(e.kind==="image"&&(e.op==="accept"||e.op==="reject")&&e.revisionId&&(e.revisionKind==="insert"||e.revisionKind==="delete"))return {kind:"drawing-revision",op:e.op,paraId:e.paraId,drawingId:e.drawingId,offset:e.offset,revisionId:e.revisionId,revisionKind:e.revisionKind};if(e.kind==="block"&&e.op==="split"&&e.newParaId&&e.offset!==void 0)return {kind:"paragraph-split",paraId:e.paraId,newParaId:e.newParaId,offset:e.offset};if(e.kind==="block"&&e.op==="merge")return {kind:"paragraph-merge",paraId:e.paraId};if(e.kind==="hyperlink"){if(e.from>=e.to)return null;let r=e.hyperlink;return e.op==="set"&&(!(r!=null&&r.target)||!sp(r.target)||r.anchor)?null:v({kind:"hyperlink",op:e.op,paraId:e.paraId,from:e.from,to:e.to},e.op==="set"&&r?{hyperlink:r}:{})}return e.kind==="table"&&(!e.revisionId||t.allowTrackedTable===true)&&e.op!=="insert-table"&&e.op!=="delete-table"&&e.op!=="format-cell"&&e.op!=="clear-cell"&&e.op!=="replace-cell"?v(v({kind:"table-structure",op:e.op,tableId:e.tableId,rowIndex:e.rowIndex,columnIndex:e.columnIndex},e.endColumnIndex!==void 0?{endColumnIndex:e.endColumnIndex}:{}),e.endRowIndex!==void 0?{endRowIndex:e.endRowIndex}:{}):e.kind==="table"&&e.op==="insert-table"&&e.tableSnapshot&&e.anchorParaId?{kind:"table-insert",anchorParaId:e.anchorParaId,anchorOffset:(n=e.anchorOffset)!=null?n:0,table:e.tableSnapshot}:e.kind==="table"&&e.op==="format-cell"&&e.format?{kind:"table-cell-format",tableId:e.tableId,rowIndex:e.rowIndex,columnIndex:e.columnIndex,format:e.format}:e.kind==="table"&&e.op==="clear-cell"?{kind:"table-cell-clear",tableId:e.tableId,rowIndex:e.rowIndex,columnIndex:e.columnIndex}:e.kind==="table"&&e.op==="replace-cell"&&e.text!==void 0?{kind:"table-cell-replace",tableId:e.tableId,rowIndex:e.rowIndex,columnIndex:e.columnIndex,text:e.text}:e.kind==="table"&&e.op==="replace-cell"&&e.cellSnapshot?ap(e.cellSnapshot)?null:{kind:"table-cell-replace-rich",tableId:e.tableId,rowIndex:e.rowIndex,columnIndex:e.columnIndex,cell:e.cellSnapshot}:e.kind==="annotation"&&(e.op==="insert"||e.op==="delete"||e.op==="update")?v(v({kind:"comment",op:e.op,paraId:e.paraId,from:e.from,to:e.to,commentId:e.commentId},e.parentCommentId!==void 0?{parentCommentId:e.parentCommentId}:{}),e.body!==void 0?{body:e.body}:{}):e.kind==="revision"?{kind:"revision",op:e.op,paraId:e.paraId,from:e.from,to:e.to,revisionId:e.revisionId,revisionKind:e.revisionKind}:e.kind==="table"&&e.op==="delete-table"&&t.allowTrackedTable===true?{kind:"table-delete",tableId:e.tableId}:null}function px(e,t,n){var i,s;let r=[],o=[];for(let a of n){if(a.kind==="drawing-delete"||a.kind==="drawing-resize"||a.kind==="drawing-revision"){let u=t.drawingIdx.get(a.drawingId);if(!u&&a.kind==="drawing-revision"){let p=t.paraIdx.get(a.paraId.toUpperCase());u=p&&(i=Bx(p,a.offset))!=null?i:void 0;}if(!u){o.push({patch:a,reason:`drawing not found: ${a.drawingId}`});continue}let f=Xn(e,u);if(!f){o.push({patch:a,reason:`drawing part not found: ${a.drawingId}`});continue}r.push({kind:"drawing",patch:a,partPath:f,drawing:u,paragraph:(s=t.paraIdx.get(a.paraId.toUpperCase()))!=null?s:null});continue}if(a.kind==="drawing-insert"){let u=t.paraIdx.get(a.paraId.toUpperCase());if(!u){o.push({patch:a,reason:`paragraph not found: ${a.paraId}`});continue}let f=Xn(e,u);if(!f){o.push({patch:a,reason:`paragraph part not found: ${a.paraId}`});continue}r.push({kind:"drawing",patch:a,partPath:f,drawing:u,paragraph:u});continue}if(a.kind==="comment"){let u=t.paraIdx.get(a.paraId.toUpperCase());if(!u){o.push({patch:a,reason:`paragraph not found: ${a.paraId}`});continue}let f=Xn(e,u);if(!f){o.push({patch:a,reason:`paragraph part not found: ${a.paraId}`});continue}r.push({kind:"comment",patch:a,partPath:f,paragraph:u});continue}if(a.kind==="table-insert"){let u=t.paraIdx.get(a.anchorParaId.toUpperCase());if(!u){o.push({patch:a,reason:`anchor paragraph not found: ${a.anchorParaId}`});continue}let f=Xn(e,u);if(!f){o.push({patch:a,reason:`paragraph part not found: ${a.anchorParaId}`});continue}r.push({kind:"table",patch:a,partPath:f,table:u,paragraph:u});continue}if(a.kind==="table-structure"||a.kind==="table-cell-format"||a.kind==="table-cell-clear"||a.kind==="table-cell-replace"||a.kind==="table-cell-replace-rich"||a.kind==="table-delete"){let u=t.tblIdx.get(a.tableId);if(!u){o.push({patch:a,reason:`table not found: ${a.tableId}`});continue}let f=Xn(e,u);if(!f){o.push({patch:a,reason:`table part not found: ${a.tableId}`});continue}r.push({kind:"table",patch:a,partPath:f,table:u});continue}let l=t.paraIdx.get(a.paraId.toUpperCase());if(!l){o.push({patch:a,reason:`paragraph not found: ${a.paraId}`});continue}let c=Xn(e,l);if(!c){o.push({patch:a,reason:`paragraph part not found: ${a.paraId}`});continue}r.push({kind:"paragraph",patch:a,partPath:c,paragraph:l});}return {resolved:r,unresolved:o}}function fx(e,t,n){var l,c;let r=[],o=[],i=[],s=new Set,a=t;for(let u of n){let f=px(e,a,[u]);if(f.unresolved.length>0){i.push(...f.unresolved);continue}let p=f.resolved[0];if(!p)continue;let w=up(e,p.kind==="paragraph"?p.paragraph:p.kind==="drawing"?p.drawing:p.kind==="table"?p.table:p.paragraph);if(!w){o.push({patch:p.patch,reason:`part not found: ${p.partPath}`});continue}if(p.kind==="drawing"){if(p.patch.kind==="drawing-insert"){let g=Kx(e,p.partPath,(l=p.paragraph)!=null?l:p.drawing,p.patch);if(!g.ok){o.push({patch:p.patch,reason:g.reason});continue}pack.markDirty(w),r.push(p.patch),a=wordView.buildIndices(e);continue}if(p.patch.kind==="drawing-revision"){(p.patch.revisionKind==="insert"&&p.patch.op==="reject"||p.patch.revisionKind==="delete"&&p.patch.op==="accept")&&rp(p.drawing),pack.markDirty(w),r.push(p.patch),a=wordView.buildIndices(e);continue}if(p.patch.kind==="drawing-resize"){let g=Ux(p.drawing,p.patch.width,p.patch.height);if(!g.ok){o.push({patch:p.patch,reason:g.reason});continue}pack.markDirty(w),r.push(p.patch),a=wordView.buildIndices(e);continue}rp(p.drawing),pack.markDirty(w),r.push(p.patch),a=wordView.buildIndices(e);continue}if(p.kind==="table"){if(p.patch.kind==="table-insert"){let h=xx(p.table.ownerDocument,p.patch.table,e,p.partPath);(c=p.table.parentNode)==null||c.insertBefore(h,p.table.nextSibling),pack.markDirty(w),r.push(p.patch),a=wordView.buildIndices(e);continue}if(p.patch.kind==="table-cell-format"){let h=yx(p.table,p.patch);if(!h.ok){o.push({patch:p.patch,reason:h.reason});continue}pack.markDirty(w),r.push(p.patch),a=wordView.buildIndices(e);continue}if(p.patch.kind==="table-cell-clear"){let h=vx(p.table,p.patch);if(!h.ok){o.push({patch:p.patch,reason:h.reason});continue}pack.markDirty(w),r.push(p.patch),a=wordView.buildIndices(e);continue}if(p.patch.kind==="table-cell-replace"){let h=Sx(p.table,p.patch);if(!h.ok){o.push({patch:p.patch,reason:h.reason});continue}pack.markDirty(w),r.push(p.patch),a=wordView.buildIndices(e);continue}if(p.patch.kind==="table-cell-replace-rich"){let h=kx(e,p.partPath,p.table,p.patch);if(!h.ok){o.push({patch:p.patch,reason:h.reason});continue}pack.markDirty(w),r.push(p.patch),a=wordView.buildIndices(e);continue}if(p.patch.kind==="table-delete"){Ue(p.table),pack.markDirty(w),r.push(p.patch),a=wordView.buildIndices(e);continue}let g=Ex(p.table,p.patch);if(!g.ok){o.push({patch:p.patch,reason:g.reason});continue}pack.markDirty(w),r.push(p.patch),a=wordView.buildIndices(e);continue}if(p.kind==="comment"){let g=ty(e,p.partPath,p.paragraph,p.patch);if(!g.ok){o.push({patch:p.patch,reason:g.reason});continue}pack.markDirty(w),r.push(p.patch),a=wordView.buildIndices(e);continue}if(p.patch.kind==="revision"){let g=qx(p.paragraph,p.patch);if(!g.ok){if((p.patch.op==="accept"||p.patch.op==="reject")&&g.reason===`revision not found: ${p.patch.revisionId}`&&s.has(p.patch.revisionId)){r.push(p.patch);continue}o.push({patch:p.patch,reason:g.reason});continue}pack.markDirty(w),r.push(p.patch),(p.patch.op==="accept"||p.patch.op==="reject")&&s.add(p.patch.revisionId),a=wordView.buildIndices(e);continue}if(p.patch.kind==="paragraph-format"){let g=Xx(p.paragraph,p.patch);if(!g.ok){o.push({patch:p.patch,reason:g.reason});continue}pack.markDirty(w),r.push(p.patch),a=wordView.buildIndices(e);continue}if(p.patch.kind==="format-revision"){let g=Yx(p.paragraph,p.patch);if(!g.ok){o.push({patch:p.patch,reason:g.reason});continue}pack.markDirty(w),r.push(p.patch),a=wordView.buildIndices(e);continue}if(p.patch.kind==="paragraph-split"){let g=Hx(p.paragraph,p.patch.offset,p.patch.newParaId);if(!g.ok){o.push({patch:p.patch,reason:g.reason});continue}pack.markDirty(w),r.push(p.patch),a=wordView.buildIndices(e);continue}if(p.patch.kind==="paragraph-merge"){let g=Ox(p.paragraph);if(!g.ok){o.push({patch:p.patch,reason:g.reason});continue}pack.markDirty(w),r.push(p.patch),a=wordView.buildIndices(e);continue}if(p.patch.kind==="hyperlink"){let g=hx(e,p.partPath,p.paragraph,p.patch);if(!g.ok){o.push({patch:p.patch,reason:g.reason});continue}pack.markDirty(w),r.push(p.patch),a=wordView.buildIndices(e);continue}let b=Ax(p.paragraph,p.patch);if(!b.ok){o.push({patch:p.patch,reason:b.reason});continue}pack.markDirty(w),r.push(p.patch);}return {applied:r,skipped:o,unresolved:i}}function mx(e){var t;return e.kind==="block"&&e.op==="split"?"paragraph split change is missing newParaId or offset":e.kind==="hyperlink"?e.op==="set"&&((t=e.hyperlink)!=null&&t.anchor)?"hyperlink anchors are not yet written back":"only external http/https hyperlinks can be written back":e.kind==="image"&&e.op==="resize"?"image resize is missing width or height":e.kind==="image"&&e.op==="insert"?"image insert requires data URL, width, and height":e.kind==="table"?e.op==="replace-cell"&&e.cellSnapshot&&ap(e.cellSnapshot)?"table cell rich replacement does not yet write back drawings or hyperlink anchors":e.revisionId||e.revisionKind?"table revision writeback requires an original table structure snapshot":"table structure change is not supported for DOCX writeback":`unsupported native change: ${e.kind}/${"op"in e?e.op:"unknown"}`}function ap(e){return e.blocks.some(t=>t.kind!=="paragraph"||t.content.some(n=>n.kind==="drawing"||n.kind==="text"&&n.hyperlink!==void 0&&!n.hyperlink.target))}function sp(e){try{let t=new URL(e).protocol.toLowerCase();return t==="http:"||t==="https:"}catch(t){return false}}function hx(e,t,n,r){var f,p,w;let o=oe(n).filter(b=>!(b.namespaceURI===wordView.W_NS&&b.localName==="pPr")),i=o.reduce((b,g)=>b+zt(g),0);if(r.from<0||r.to>i||r.from>=r.to)return {ok:false,reason:`hyperlink range out of range: ${r.from}:${r.to}`};if(o.some(b=>{var g;return b.namespaceURI!==wordView.W_NS||!["r","hyperlink"].includes((g=b.localName)!=null?g:"")}))return {ok:false,reason:"hyperlink patch only supports text runs and existing hyperlinks"};if(o.some(b=>wx(b)))return {ok:false,reason:"hyperlink patch cannot cross inline objects"};let s=null,a=null;if(r.op==="set"){let b=(f=r.hyperlink)==null?void 0:f.target;if(!b||!sp(b))return {ok:false,reason:"only external http/https hyperlinks can be written back"};let g=dp(e,t,b);s=g.id,a=g.part;}let l=[],c=0,u=[];for(let b of o){let g=zt(b),h=Math.max(0,r.from-c),y=Math.min(g,r.to-c);if(!(h<y)){l.push(b),c+=g;continue}if(h>0){let N=Zn(b,0,h);N&&l.push(N);}let C=Zn(b,h,y);if(C&&u.push(...bx(C)),y<g){let N=Zn(b,y,g);N&&l.push(N);}c+=g;}if(r.op==="set"){let b=n.ownerDocument;if(!b||!s)return {ok:false,reason:"paragraph has no owner document or relationship"};let g=b.createElementNS(wordView.W_NS,"w:hyperlink");g.setAttributeNS(Bn,"r:id",s);let h=(w=(p=r.hyperlink)==null?void 0:p.tooltip)==null?void 0:w.trim();h&&g.setAttributeNS(wordView.W_NS,"w:tooltip",h);for(let y of u)g.appendChild(y);gx(l,g,r);}else lp(l,u,r);for(let b of o)Ue(b);for(let b of l)n.appendChild(b);return a&&pack.markDirty(a),{ok:true}}function gx(e,t,n){lp(e,[t],n);}function lp(e,t,n){let r=0,o=false,i=[];for(let s of e)!o&&r>=n.from&&(i.push(...t),o=true),i.push(s),r+=zt(s);o||i.push(...t),e.splice(0,e.length,...i);}function Zn(e,t,n){if(n<=t)return null;let r=e.cloneNode(true);return Ns(r,t,n),zt(r)>0?r:null}function bx(e){return e.namespaceURI===wordView.W_NS&&e.localName==="hyperlink"?oe(e).filter(t=>t.namespaceURI===wordView.W_NS&&t.localName==="r"):[e]}function wx(e){return e.getElementsByTagNameNS(wordView.W_NS,"drawing").length>0||e.getElementsByTagNameNS(wordView.W_NS,"pict").length>0}function dp(e,t,n){var u,f,p,w,b;let r=si(t),o=e.parts.get(r);if(!(o!=null&&o.xmlDom)){let g=(u=Array.from(e.parts.values()).find(y=>y.xmlDom))==null?void 0:u.xmlDom;if(!g)throw new Error("cannot create hyperlink relationships without an XML part");let h=(f=g.implementation)==null?void 0:f.createDocument($t,"Relationships",null);if(!h)throw new Error("XML implementation cannot create relationship document");o=pack.createXmlPart({path:r,contentType:ip,xmlDom:h}),pack.setPart(e,o);}let i=o.xmlDom;if(!i)throw new Error(`relationship part has no XML DOM: ${r}`);let s=i.getElementsByTagNameNS($t,"Relationship");for(let g=0;g<s.length;g+=1){let h=s[g];if((h==null?void 0:h.getAttribute("Type"))===Qu&&h.getAttribute("Target")===n)return {id:(p=h.getAttribute("Id"))!=null?p:"",part:o}}let a=new Set;for(let g=0;g<s.length;g+=1){let h=(w=s[g])==null?void 0:w.getAttribute("Id");h&&a.add(h);}let l=1;for(;a.has(`rId${l}`);)l+=1;let c=i.createElementNS($t,"Relationship");return c.setAttribute("Id",`rId${l}`),c.setAttribute("Type",Qu),c.setAttribute("Target",n),c.setAttribute("TargetMode","External"),(b=i.documentElement)==null||b.appendChild(c),{id:`rId${l}`,part:o}}function si(e){let t=e.lastIndexOf("/"),n=t>=0?e.slice(0,t):"",r=e.slice(t+1);return n?`${n}/_rels/${r}.rels`:`_rels/${r}.rels`}function xx(e,t,n,r){var u,f,p,w,b,g;let o=h=>e.createElementNS(wordView.W_NS,`w:${h}`),i=o("tbl"),s=o("tblPr"),a=o("tblW");a.setAttributeNS(wordView.W_NS,"w:w",String(Math.max(0,Math.round((f=(u=t.layout)==null?void 0:u.width)!=null?f:0)))),a.setAttributeNS(wordView.W_NS,"w:type",((p=t.layout)==null?void 0:p.widthType)==="pct"?"pct":"dxa"),s.appendChild(a);let l=o("tblBorders");for(let h of ["top","left","bottom","right","insideH","insideV"]){let y=o(h);y.setAttributeNS(wordView.W_NS,"w:val","single"),y.setAttributeNS(wordView.W_NS,"w:sz","4"),y.setAttributeNS(wordView.W_NS,"w:color",(g=(b=(w=t.borders)==null?void 0:w[h])==null?void 0:b.color)!=null?g:"D9D9D9"),l.appendChild(y);}s.appendChild(l),i.appendChild(s);let c=o("tblGrid");for(let h of t.columnWidths){let y=o("gridCol");y.setAttributeNS(wordView.W_NS,"w:w",String(Math.max(1,Math.round(h)))),c.appendChild(y);}i.appendChild(c);for(let h of t.rows){let y=o("tr");for(let k of h.cells)y.appendChild(cp(e,k,n,r));i.appendChild(y);}return i}function cp(e,t,n,r){var u,f,p,w,b,g;let o=h=>e.createElementNS(wordView.W_NS,`w:${h}`),i=o("tc"),s=o("tcPr"),a=o("tcW");if(a.setAttributeNS(wordView.W_NS,"w:w",String(Math.max(1,Math.round((u=t.width)!=null?u:0)))),a.setAttributeNS(wordView.W_NS,"w:type","dxa"),s.appendChild(a),(f=t.shading)!=null&&f.fill){let h=o("shd");h.setAttributeNS(wordView.W_NS,"w:val",(p=t.shading.val)!=null?p:"clear"),h.setAttributeNS(wordView.W_NS,"w:fill",t.shading.fill.replace(/^#/,"").toUpperCase()),s.appendChild(h);}if(t.verticalAlignment){let h=o("vAlign");h.setAttributeNS(wordView.W_NS,"w:val",t.verticalAlignment),s.appendChild(h);}i.appendChild(s);let l=t.blocks.filter(h=>h.kind==="paragraph"),c=l.length>0?l:[null];for(let h of c){let y=o("p");if(h)for(let k of h.content){if(k.kind==="image"){let L=bp(k.src);if(!L)continue;let D=wp(n,r,L.bytes,L.extension,L.contentType);y.appendChild(gp(e,D.id,k.drawingId,(w=k.width)!=null?w:96,(b=k.height)!=null?b:96)),pack.markDirty(D.part),pack.markDirty(D.mediaPart),xp(n,L.extension,L.contentType);continue}if(k.kind!=="text")continue;let C=o("r");if(k.format){let L=o("rPr");if(k.format.bold&&L.appendChild(o("b")),k.format.italic&&L.appendChild(o("i")),k.format.underline){let D=o("u");D.setAttributeNS(wordView.W_NS,"w:val","single"),L.appendChild(D);}if(k.format.strike&&L.appendChild(o("strike")),k.format.color){let D=o("color");D.setAttributeNS(wordView.W_NS,"w:val",k.format.color.replace(/^#/,"").toUpperCase()),L.appendChild(D);}if(k.format.fontSize){let D=o("sz");D.setAttributeNS(wordView.W_NS,"w:val",String(Math.round(k.format.fontSize*2))),L.appendChild(D);}if(k.format.fontFamily){let D=o("rFonts");for(let W of ["ascii","hAnsi","eastAsia"])D.setAttributeNS(wordView.W_NS,`w:${W}`,k.format.fontFamily);L.appendChild(D);}L.childNodes.length>0&&C.appendChild(L);}let N=o("t");if(N.textContent=k.text,/^\s|\s$/.test(k.text)&&N.setAttributeNS(Ms,"xml:space","preserve"),C.appendChild(N),(g=k.hyperlink)!=null&&g.target){let L=dp(n,r,k.hyperlink.target),D=e.createElementNS(wordView.W_NS,"w:hyperlink");D.setAttributeNS(Bn,"r:id",L.id),D.appendChild(C),y.appendChild(D),pack.markDirty(L.part);}else y.appendChild(C);}y.firstChild||y.appendChild(o("r")),i.appendChild(y);}return i}function yx(e,t){let r=oe(e).filter(l=>l.namespaceURI===wordView.W_NS&&l.localName==="tr")[t.rowIndex];if(!r)return {ok:false,reason:`table row out of range: ${t.rowIndex}`};let i=oe(r).filter(l=>l.namespaceURI===wordView.W_NS&&l.localName==="tc")[t.columnIndex];if(!i)return {ok:false,reason:`table column out of range: ${t.columnIndex}`};let s=e.ownerDocument,a=oe(i).find(l=>l.namespaceURI===wordView.W_NS&&l.localName==="tcPr");if(a||(a=s.createElementNS(wordView.W_NS,"w:tcPr"),i.insertBefore(a,i.firstChild)),t.format.backgroundColor!==void 0){let l=oe(a).find(c=>c.namespaceURI===wordView.W_NS&&c.localName==="shd");if(t.format.backgroundColor===null)l&&Ue(l);else {let c=l!=null?l:s.createElementNS(wordView.W_NS,"w:shd");c.setAttributeNS(wordView.W_NS,"w:val","clear"),c.setAttributeNS(wordView.W_NS,"w:fill",t.format.backgroundColor.replace(/^#/,"").toUpperCase()),l||a.appendChild(c);}}if(t.format.verticalAlignment!==void 0){let l=oe(a).find(c=>c.namespaceURI===wordView.W_NS&&c.localName==="vAlign");if(t.format.verticalAlignment===null)l&&Ue(l);else {let c=l!=null?l:s.createElementNS(wordView.W_NS,"w:vAlign");c.setAttributeNS(wordView.W_NS,"w:val",t.format.verticalAlignment),l||a.appendChild(c);}}if(t.format.borderColor!==void 0){let l=oe(a).find(u=>u.namespaceURI===wordView.W_NS&&u.localName==="tcBorders"),c=l!=null?l:s.createElementNS(wordView.W_NS,"w:tcBorders");for(let u of ["top","left","bottom","right","insideH","insideV"]){let f=oe(c).find(p=>p.namespaceURI===wordView.W_NS&&p.localName===u);f||(f=s.createElementNS(wordView.W_NS,`w:${u}`),c.appendChild(f)),f.setAttributeNS(wordView.W_NS,"w:val",t.format.borderColor===null?"nil":"single"),t.format.borderColor!==null&&(f.setAttributeNS(wordView.W_NS,"w:sz","4"),f.setAttributeNS(wordView.W_NS,"w:color",t.format.borderColor.replace(/^#/,"").toUpperCase()));}l||a.appendChild(c);}return {ok:true}}function vx(e,t){let r=oe(e).filter(a=>a.namespaceURI===wordView.W_NS&&a.localName==="tr")[t.rowIndex];if(!r)return {ok:false,reason:`table row out of range: ${t.rowIndex}`};let i=oe(r).filter(a=>a.namespaceURI===wordView.W_NS&&a.localName==="tc")[t.columnIndex];if(!i)return {ok:false,reason:`table column out of range: ${t.columnIndex}`};let s=oe(i).find(a=>a.namespaceURI===wordView.W_NS&&a.localName==="tcPr");for(let a of oe(i))a!==s&&Ue(a);return i.appendChild(i.ownerDocument.createElementNS(wordView.W_NS,"w:p")),{ok:true}}function Sx(e,t){let r=oe(e).filter(p=>p.namespaceURI===wordView.W_NS&&p.localName==="tr")[t.rowIndex];if(!r)return {ok:false,reason:`table row out of range: ${t.rowIndex}`};let i=oe(r).filter(p=>p.namespaceURI===wordView.W_NS&&p.localName==="tc")[t.columnIndex];if(!i)return {ok:false,reason:`table column out of range: ${t.columnIndex}`};let s=oe(i).find(p=>p.namespaceURI===wordView.W_NS&&p.localName==="tcPr"),a=oe(i).find(p=>p.namespaceURI===wordView.W_NS&&p.localName==="p");for(let p of oe(i))p!==s&&Ue(p);let l=i.ownerDocument.createElementNS(wordView.W_NS,"w:p"),c=a&&oe(a).find(p=>p.namespaceURI===wordView.W_NS&&p.localName==="pPr");c&&l.appendChild(c.cloneNode(true));let u=i.ownerDocument.createElementNS(wordView.W_NS,"w:r"),f=i.ownerDocument.createElementNS(wordView.W_NS,"w:t");return f.textContent=t.text,/^\s|\s$/.test(t.text)&&f.setAttributeNS(Ms,"xml:space","preserve"),u.appendChild(f),l.appendChild(u),i.appendChild(l),{ok:true}}function kx(e,t,n,r){let i=oe(n).filter(c=>c.namespaceURI===wordView.W_NS&&c.localName==="tr")[r.rowIndex];if(!i)return {ok:false,reason:`table row out of range: ${r.rowIndex}`};let a=oe(i).filter(c=>c.namespaceURI===wordView.W_NS&&c.localName==="tc")[r.columnIndex];if(!a)return {ok:false,reason:`table column out of range: ${r.columnIndex}`};let l=cp(n.ownerDocument,r.cell,e,t);for(let c of oe(a))Ue(c);for(let c of oe(l))a.appendChild(c.cloneNode(true));return {ok:true}}function Ex(e,t){var u,f,p,w;let n=oe(e).filter(b=>b.namespaceURI===wordView.W_NS&&b.localName==="tr");if(n.length===0)return {ok:false,reason:"table has no rows"};if(t.op==="insert-row"||t.op==="delete-row"){if(t.rowIndex<0||t.rowIndex>=n.length+(t.op==="insert-row"?1:0))return {ok:false,reason:`table row out of range: ${t.rowIndex}`};if(t.op==="delete-row")return n.length<=1?{ok:false,reason:"cannot delete the only table row"}:(Ue(n[t.rowIndex]),{ok:true});let b=n[Math.min(t.rowIndex,n.length-1)],g=Ix(b);return e.insertBefore(g,(u=n[t.rowIndex])!=null?u:null),{ok:true}}let r=n[t.rowIndex];if(!r)return {ok:false,reason:`table row out of range: ${t.rowIndex}`};let o=oe(r).filter(b=>b.namespaceURI===wordView.W_NS&&b.localName==="tc");if(t.op==="insert-column"||t.op==="delete-column"){if(o.length===0)return {ok:false,reason:"table row has no cells"};if(t.columnIndex<0||t.columnIndex>=o.length+(t.op==="insert-column"?1:0))return {ok:false,reason:`table column out of range: ${t.columnIndex}`};let b=n.map(g=>oe(g).filter(h=>h.namespaceURI===wordView.W_NS&&h.localName==="tc"));if(b.some(g=>g.length!==o.length||g.some(h=>Ln(h)!==1||oi(h))))return {ok:false,reason:"table column structure is not a regular non-merged grid"};for(let g of b)if(t.op==="delete-column"){if(g.length<=1)return {ok:false,reason:"cannot delete the only table column"};Ue(g[t.columnIndex]);}else {let h=g[Math.min(t.columnIndex,g.length-1)],y=Cs(h);(p=g[0].parentNode)==null||p.insertBefore(y,(f=g[t.columnIndex])!=null?f:null);}return Rx(e,t.op==="insert-column"?"insert":"delete",t.columnIndex),{ok:true}}if(t.op==="merge-cells"){if(t.endRowIndex!==void 0&&t.endRowIndex>t.rowIndex){if(t.columnIndex<0||t.endRowIndex>=n.length)return {ok:false,reason:`vertical merge row out of range: ${t.rowIndex}:${t.endRowIndex}`};let h=n.slice(t.rowIndex,t.endRowIndex+1).map(y=>oe(y).filter(k=>k.namespaceURI===wordView.W_NS&&k.localName==="tc")[t.columnIndex]);if(h.some(y=>!y||Ln(y)!==1||oi(y)))return {ok:false,reason:"vertical merge requires a regular non-merged column"};ep(h[0],"restart");for(let y of h.slice(1)){ep(y,"continue");let k=oe(y).find(C=>C.namespaceURI===wordView.W_NS&&C.localName==="tcPr");for(let C of oe(y))C!==k&&Ue(C);y.appendChild(y.ownerDocument.createElementNS(wordView.W_NS,"w:p"));}return {ok:true}}let b=(w=t.endColumnIndex)!=null?w:t.columnIndex+1;if(t.columnIndex<0||b>=o.length||b<=t.columnIndex)return {ok:false,reason:`merge start column out of range: ${t.columnIndex}`};if(o.some(h=>Ln(h)!==1||oi(h)))return {ok:false,reason:"cell merge requires a regular non-merged row"};let g=o[t.columnIndex];for(let h=t.columnIndex+1;h<=b;h+=1){let y=o[h];Nx(g,y),Ue(y);}return Tx(g,b-t.columnIndex+1),{ok:true}}if(t.endRowIndex!==void 0&&t.endRowIndex>t.rowIndex){if(t.columnIndex<0||t.endRowIndex>=n.length)return {ok:false,reason:`vertical split row out of range: ${t.rowIndex}:${t.endRowIndex}`};let b=n.slice(t.rowIndex,t.endRowIndex+1).map(g=>oe(g).filter(h=>h.namespaceURI===wordView.W_NS&&h.localName==="tc")[t.columnIndex]);if(b.some((g,h)=>{var C;if(!g||Ln(g)!==1)return true;let y=(C=oe(g).find(N=>N.namespaceURI===wordView.W_NS&&N.localName==="tcPr"))==null?void 0:C.getElementsByTagNameNS(wordView.W_NS,"vMerge")[0],k=y==null?void 0:y.getAttributeNS(wordView.W_NS,"val");return h===0?k!=="restart":k!=="continue"}))return {ok:false,reason:"cell is not a vertically merged cell"};for(let g of b)Cx(g);return {ok:true}}let i=n[t.rowIndex],s=oe(i).filter(b=>b.namespaceURI===wordView.W_NS&&b.localName==="tc"),a=0,l=s.find(b=>{let g=a===t.columnIndex;return a+=Ln(b),g});if(!l)return {ok:false,reason:`split column out of range: ${t.columnIndex}`};if(oi(l)||Ln(l)<=1)return {ok:false,reason:"cell is not a horizontally merged cell"};let c=Ln(l);Px(l);for(let b=1;b<c;b+=1){let g=Cs(l);i.insertBefore(g,l.nextSibling);}return {ok:true}}function ep(e,t){var i;let n=e.ownerDocument,r=oe(e).find(s=>s.namespaceURI===wordView.W_NS&&s.localName==="tcPr");r||(r=n.createElementNS(wordView.W_NS,"w:tcPr"),e.insertBefore(r,e.firstChild));let o=(i=oe(r).find(s=>s.namespaceURI===wordView.W_NS&&s.localName==="vMerge"))!=null?i:n.createElementNS(wordView.W_NS,"w:vMerge");o.setAttributeNS(wordView.W_NS,"w:val",t),o.parentNode||r.appendChild(o);}function Cx(e){let t=oe(e).find(r=>r.namespaceURI===wordView.W_NS&&r.localName==="tcPr"),n=t&&oe(t).find(r=>r.namespaceURI===wordView.W_NS&&r.localName==="vMerge");n&&Ue(n);}function Ix(e){let t=e.cloneNode(true),n=oe(t).filter(r=>r.namespaceURI===wordView.W_NS&&r.localName==="tc");for(let r of n){let o=Cs(r);hp(r,o);}return t}function Cs(e){let t=e.ownerDocument,n=t.createElementNS(wordView.W_NS,"w:tc"),r=oe(e).find(a=>a.namespaceURI===wordView.W_NS&&a.localName==="tcPr");r&&n.appendChild(r.cloneNode(true));let o=t.createElementNS(wordView.W_NS,"w:p"),i=oe(e).find(a=>a.namespaceURI===wordView.W_NS&&a.localName==="p"),s=i&&oe(i).find(a=>a.namespaceURI===wordView.W_NS&&a.localName==="pPr");return s&&o.appendChild(s.cloneNode(true)),o.appendChild(t.createElementNS(wordView.W_NS,"w:r")),n.appendChild(o),n}function Nx(e,t){for(let n of oe(t))n.namespaceURI===wordView.W_NS&&n.localName==="tcPr"||e.appendChild(n.cloneNode(true));}function Ln(e){var r,o;let t=(o=(r=oe(e).find(i=>i.namespaceURI===wordView.W_NS&&i.localName==="tcPr"))==null?void 0:r.getElementsByTagNameNS(wordView.W_NS,"gridSpan")[0])==null?void 0:o.getAttributeNS(wordView.W_NS,"val"),n=Number(t);return Number.isFinite(n)&&n>0?n:1}function oi(e){var t;return !!((t=oe(e).find(n=>n.namespaceURI===wordView.W_NS&&n.localName==="tcPr"))!=null&&t.getElementsByTagNameNS(wordView.W_NS,"vMerge").length)}function Tx(e,t){let n=Mx(e,"tcPr"),r=oe(n).find(o=>o.namespaceURI===wordView.W_NS&&o.localName==="gridSpan");r||(r=e.ownerDocument.createElementNS(wordView.W_NS,"w:gridSpan"),n.appendChild(r)),r.setAttributeNS(wordView.W_NS,"w:val",String(t));}function Px(e){let t=oe(e).find(r=>r.namespaceURI===wordView.W_NS&&r.localName==="tcPr"),n=t&&oe(t).find(r=>r.namespaceURI===wordView.W_NS&&r.localName==="gridSpan");n&&Ue(n);}function Mx(e,t){let n=oe(e).find(o=>o.namespaceURI===wordView.W_NS&&o.localName===t);if(n)return n;let r=e.ownerDocument.createElementNS(wordView.W_NS,`w:${t}`);return e.insertBefore(r,e.firstChild),r}function Rx(e,t,n){var a;let r=oe(e).find(l=>l.namespaceURI===wordView.W_NS&&l.localName==="tblGrid");if(!r)return;let o=oe(r).filter(l=>l.namespaceURI===wordView.W_NS&&l.localName==="gridCol");if(t==="delete"){o.length>1&&o[n]&&Ue(o[n]);return}let i=o[Math.min(n,o.length-1)];if(!i)return;let s=i.cloneNode(true);r.insertBefore(s,(a=o[n])!=null?a:null);}function Xn(e,t){var n,r;return (r=(n=up(e,t))==null?void 0:n.path)!=null?r:null}function up(e,t){let n=t.nodeType===9?t:t.ownerDocument;if(!n)return null;for(let r of e.parts.values())if(r.xmlDom===n)return r;return null}function Ax(e,t){var n,r;return t.op==="insert"?pp(e,t.offset,t.text):t.op==="delete"?tp(e,t.offset,t.text.length,""):tp(e,t.offset,(r=(n=t.deletedText)==null?void 0:n.length)!=null?r:0,t.text)}function pp(e,t,n){var a,l,c;if(n.length===0)return {ok:true};let r=jr(e),o=r.reduce((u,f)=>u+f.length,0);if(Lx(e)&&t===o)return np(e,n),{ok:true};if(r.every(u=>u.kind!=="text"))return t!==0?{ok:false,reason:`insert offset out of range: ${t}`}:(np(e,n),{ok:true});let i=Is(r,t,true);if(!i)return {ok:false,reason:`insert offset out of range: ${t}`};if(i.node.localName==="delText"&&i.localOffset===((l=(a=i.node.textContent)==null?void 0:a.length)!=null?l:0)){let u=Wx(i.node,"del"),f=u==null?void 0:u.parentNode;if(u&&f===e){let p=e.ownerDocument;if(!p)return {ok:false,reason:"paragraph has no owner document"};let w=p.createElementNS(wordView.W_NS,"w:r"),b=p.createElementNS(wordView.W_NS,"w:t");return b.textContent=n,gn(b),w.appendChild(b),e.insertBefore(w,u.nextSibling),{ok:true}}}let s=(c=i.node.textContent)!=null?c:"";return i.node.textContent=`${s.slice(0,i.localOffset)}${n}${s.slice(i.localOffset)}`,gn(i.node),{ok:true}}function tp(e,t,n,r){var p,w;if(n===0)return pp(e,t,r);let o=jr(e),i=o.filter(b=>b.kind==="text").map(b=>b.node),s=Is(o,t,false),a=Is(o,t+n,true);if(!s||!a)return {ok:false,reason:`text range out of range: ${t}:${n}`};let l=(p=s.node.textContent)!=null?p:"";if(s.node===a.node)return s.node.textContent=`${l.slice(0,s.localOffset)}${r}${l.slice(a.localOffset)}`,gn(s.node),{ok:true};let c=i.indexOf(s.node),u=i.indexOf(a.node);if(c<0||u<0||c>u)return {ok:false,reason:`text range out of range: ${t}:${n}`};let f=(w=a.node.textContent)!=null?w:"";s.node.textContent=`${l.slice(0,s.localOffset)}${r}`,gn(s.node);for(let b=c+1;b<u;b++)i[b].textContent="";return a.node.textContent=f.slice(a.localOffset),gn(a.node),{ok:true}}function jr(e){let t=[];return mp(e,t),t}function Lx(e){return e.getElementsByTagNameNS(wordView.W_NS,"fldChar").length>0||e.getElementsByTagNameNS(wordView.W_NS,"instrText").length>0}function fp(e){return jr(e).filter(t=>t.kind==="text").map(t=>t.node)}function mp(e,t){var r,o,i,s;if(e.nodeType!==1)return;let n=e;if(n.namespaceURI===wordView.W_NS&&n.localName==="t"){t.push({kind:"text",node:n,length:(o=(r=n.textContent)==null?void 0:r.length)!=null?o:0});return}if(n.namespaceURI===wordView.W_NS&&n.localName==="delText"){t.push({kind:"text",node:n,length:(s=(i=n.textContent)==null?void 0:i.length)!=null?s:0});return}if(n.namespaceURI===wordView.W_NS&&n.localName==="drawing"||n.namespaceURI===wordView.W_NS&&n.localName==="pict"){t.push({kind:"object",node:n,length:1});return}for(let a=0;a<n.childNodes.length;a+=1){let l=n.childNodes[a];l&&mp(l,t);}}function Wx(e,t){let n=e.parentNode;for(;n&&n.nodeType===1;){let r=n;if(r.namespaceURI===wordView.W_NS&&r.localName===t)return r;if(r.namespaceURI===wordView.W_NS&&r.localName==="p")return null;n=n.parentNode;}return null}function Bx(e,t){let n=0,r=jr(e);for(let o of r){if(o.kind==="object"&&t>=n&&t<=n+o.length)return o.node;n+=o.length;}return null}function Is(e,t,n){var o;let r=0;for(let i=0;i<e.length;i+=1){let s=e[i],a=r+s.length;if(s.kind==="text"){if(t>=r&&(t<a||n&&t===a))return {node:s.node,localOffset:t-r}}else if(t>=r&&t<=a)return (o=Fx(e,i))!=null?o:Dx(e,i);r=a;}return null}function Fx(e,t){for(let n=t+1;n<e.length;n+=1){let r=e[n];if(r.kind==="text")return {node:r.node,localOffset:0}}return null}function Dx(e,t){for(let n=t-1;n>=0;n-=1){let r=e[n];if(r.kind==="text")return {node:r.node,localOffset:r.length}}return null}function np(e,t){let n=e.ownerDocument;if(!n)return;let r=n.createElementNS(wordView.W_NS,"w:r"),o=n.createElementNS(wordView.W_NS,"w:t");o.textContent=t,gn(o),r.appendChild(o),e.appendChild(r);}function gn(e){var n;let t=(n=e.textContent)!=null?n:"";/^\s|\s$|\s{2,}/.test(t)&&e.setAttributeNS(Ms,"xml:space","preserve");}function Hx(e,t,n){let r=e.parentNode,o=e.ownerDocument;if(!r||!o)return {ok:false,reason:"paragraph has no parent document"};let i=oe(e).filter(u=>!(u.namespaceURI===wordView.W_NS&&u.localName==="pPr")),s=i.reduce((u,f)=>u+zt(f),0);if(t<0||t>s)return {ok:false,reason:`split offset out of range: ${t}`};let a=$x(o,i,t),l=o.createElementNS(wordView.W_NS,"w:p");Vx(e,l,n);let c=oe(e).find(u=>u.namespaceURI===wordView.W_NS&&u.localName==="pPr");c&&l.appendChild(c.cloneNode(true));for(let u of a)l.appendChild(u);return r.insertBefore(l,e.nextSibling),{ok:true}}function Ox(e){let t=Gx(e);if(!t)return {ok:false,reason:"next paragraph not found for merge"};for(let n of oe(t))n.namespaceURI===wordView.W_NS&&n.localName==="pPr"||e.appendChild(n.cloneNode(true));return Ue(t),{ok:true}}function $x(e,t,n){let r=[],o=0,i=false;for(let s of t){let a=zt(s),l=o+a;if(i)r.push(s.cloneNode(true)),Ue(s);else if(n<=o)r.push(s.cloneNode(true)),Ue(s);else if(!(n>=l)){let c=zx(e,s,n-o);c.after&&r.push(c.after),i=true;}!i&&n===l&&(i=true),o=l;}return r}function zx(e,t,n){let r=t.cloneNode(true),o=t.cloneNode(true);return Ns(r,0,n),Ns(o,n,zt(t)),hp(t,r),jx(o)||zt(o)>0?{after:o}:{after:null}}function Ns(e,t,n){var i;let r=fp(e),o=0;for(let s of r){let a=(i=s.textContent)!=null?i:"",l=o+a.length,c=Math.max(0,t-o),u=Math.min(a.length,n-o);s.textContent=c<u?a.slice(c,u):"",gn(s),o=l;}}function zt(e){var o,i,s;if(e.namespaceURI===wordView.W_NS&&e.localName==="drawing")return 1;let t=0,n=e.getElementsByTagNameNS(wordView.W_NS,"t");for(let a=0;a<n.length;a++)t+=(s=(i=(o=n[a])==null?void 0:o.textContent)==null?void 0:i.length)!=null?s:0;let r=e.getElementsByTagNameNS(wordView.W_NS,"drawing");return t+=r.length,t}function Vx(e,t,n){for(let r=0;r<e.attributes.length;r++){let o=e.attributes[r];o&&(o.namespaceURI===wordView.W14_NS&&o.localName==="paraId"||t.setAttributeNS(o.namespaceURI,o.name,o.value));}t.setAttributeNS(wordView.W14_NS,"w14:paraId",n);}function oe(e){let t=[];for(let n=0;n<e.childNodes.length;n++){let r=e.childNodes[n];(r==null?void 0:r.nodeType)===1&&t.push(r);}return t}function Gx(e){let t=e.nextSibling;for(;t;){if(t.nodeType===1){let n=t;return n.namespaceURI===wordView.W_NS&&n.localName==="p"?n:null}t=t.nextSibling;}return null}function jx(e){return fp(e).some(t=>{var n;return ((n=t.textContent)!=null?n:"").length>0})}function Ue(e){var t;(t=e.parentNode)==null||t.removeChild(e);}function hp(e,t){var n;(n=e.parentNode)==null||n.replaceChild(t,e);}function rp(e){var n;let t=e.parentNode;if(t){if(fy(t)&&t.namespaceURI===wordView.W_NS&&t.localName==="r"&&py(t)){(n=t.parentNode)==null||n.removeChild(t);return}t.removeChild(e);}}function Ux(e,t,n){if(!Number.isFinite(t)||!Number.isFinite(n)||t<=0||n<=0)return {ok:false,reason:"image size must be positive finite pixels"};let r=Math.round(t/96*914400),o=Math.round(n/96*914400),i=oe(e).find(l=>l.namespaceURI===Yn&&(l.localName==="inline"||l.localName==="anchor"));if(!i)return {ok:false,reason:"drawing has no wp:inline or wp:anchor container"};let s=oe(i).find(l=>l.namespaceURI===Yn&&l.localName==="extent");if(!s)return {ok:false,reason:"drawing has no wp:extent"};s.setAttribute("cx",String(r)),s.setAttribute("cy",String(o));let a=i.getElementsByTagNameNS(Pt,"xfrm");for(let l=0;l<a.length;l+=1){let c=a[l],u=c&&oe(c).find(f=>f.namespaceURI===Pt&&f.localName==="ext");u&&(u.setAttribute("cx",String(r)),u.setAttribute("cy",String(o)));}return {ok:true}}function Kx(e,t,n,r){let o=bp(r.src);if(!o)return {ok:false,reason:"image insert requires a base64 data:image URL"};let i=wp(e,t,o.bytes,o.extension,o.contentType),s=gp(n.ownerDocument,i.id,r.drawingId,r.width,r.height),a=oe(n).filter(p=>!(p.namespaceURI===wordView.W_NS&&p.localName==="pPr")),l=a.reduce((p,w)=>p+zt(w),0);if(r.offset<0||r.offset>l)return {ok:false,reason:`image insert offset out of range: ${r.offset}`};let c=[],u=0,f=false;for(let p of a){let w=zt(p);if(!f&&r.offset<=u&&(c.push(s),f=true),!f&&r.offset<u+w&&p.namespaceURI===wordView.W_NS&&p.localName==="r"){let b=Zn(p,0,r.offset-u),g=Zn(p,r.offset-u,w);b&&c.push(b),c.push(s),f=true,g&&c.push(g);}else c.push(p);u+=w;}f||c.push(s);for(let p of a)Ue(p);for(let p of c)n.appendChild(p);return pack.markDirty(i.part),pack.markDirty(i.mediaPart),xp(e,o.extension,o.contentType),{ok:true}}function gp(e,t,n,r,o){let i=Math.round(r/96*914400),s=Math.round(o/96*914400),a=e.createElementNS(wordView.W_NS,"w:r"),l=e.createElementNS(wordView.W_NS,"w:drawing"),c=e.createElementNS(Yn,"wp:inline"),u=e.createElementNS(Yn,"wp:extent");u.setAttribute("cx",String(i)),u.setAttribute("cy",String(s)),c.appendChild(u);let f=e.createElementNS(Yn,"wp:docPr");f.setAttribute("id",String(Math.abs(_x(n))+1)),f.setAttribute("name",`Picture ${n}`),c.appendChild(f),c.appendChild(e.createElementNS(Yn,"wp:cNvGraphicFramePr"));let p=e.createElementNS(Pt,"a:graphic"),w=e.createElementNS(Pt,"a:graphicData");w.setAttribute("uri","http://schemas.openxmlformats.org/drawingml/2006/picture");let b=e.createElementNS(qn,"pic:pic"),g=e.createElementNS(qn,"pic:nvPicPr"),h=e.createElementNS(qn,"pic:cNvPr");h.setAttribute("id","0"),h.setAttribute("name",`image-${n}`),g.appendChild(h),g.appendChild(e.createElementNS(qn,"pic:cNvPicPr")),b.appendChild(g);let y=e.createElementNS(qn,"pic:blipFill"),k=e.createElementNS(Pt,"a:blip");k.setAttributeNS(Bn,"r:embed",t),y.appendChild(k);let C=e.createElementNS(Pt,"a:stretch");C.appendChild(e.createElementNS(Pt,"a:fillRect")),y.appendChild(C),b.appendChild(y);let N=e.createElementNS(qn,"pic:spPr"),L=e.createElementNS(Pt,"a:xfrm"),D=e.createElementNS(Pt,"a:ext");D.setAttribute("cx",String(i)),D.setAttribute("cy",String(s)),L.appendChild(e.createElementNS(Pt,"a:off")),L.appendChild(D),N.appendChild(L);let W=e.createElementNS(Pt,"a:prstGeom");return W.setAttribute("prst","rect"),W.appendChild(e.createElementNS(Pt,"a:avLst")),N.appendChild(W),b.appendChild(N),w.appendChild(b),p.appendChild(w),c.appendChild(p),l.appendChild(c),a.appendChild(l),a}function bp(e){let t=/^data:(image\/(png|jpeg|jpg|gif|bmp|webp));base64,([a-z0-9+/=\s]+)$/i.exec(e.trim());if(!t)return null;let n=t[1].toLowerCase()==="image/jpg"?"image/jpeg":t[1].toLowerCase(),r=n==="image/jpeg"?"jpeg":n.slice(6),o=atob(t[3].replace(/\s/g,""));return {bytes:Uint8Array.from(o,i=>i.charCodeAt(0)),extension:r,contentType:n}}function wp(e,t,n,r,o){var g,h,y,k;let i=si(t),s=e.parts.get(i);if(!(s!=null&&s.xmlDom)){let C=(g=Array.from(e.parts.values()).find(L=>L.xmlDom))==null?void 0:g.xmlDom;if(!C)throw new Error("cannot create image relationships without an XML part");let N=(h=C.implementation)==null?void 0:h.createDocument($t,"Relationships",null);if(!N)throw new Error("XML implementation cannot create relationship document");s=pack.createXmlPart({path:i,contentType:ip,xmlDom:N}),pack.setPart(e,s);}let a=s.xmlDom;if(!a)throw new Error(`relationship part has no XML DOM: ${i}`);let l=a.getElementsByTagNameNS($t,"Relationship"),c=1,u=new Set;for(let C=0;C<l.length;C+=1){let N=(y=l[C])==null?void 0:y.getAttribute("Id");N&&u.add(N);}for(;u.has(`rId${c}`);)c+=1;let f=1;for(;e.parts.has(`word/media/image${f}.${r}`);)f+=1;let p=`word/media/image${f}.${r}`,w=pack.createBinaryPart({path:p,contentType:o,bytes:n});pack.setPart(e,w);let b=a.createElementNS($t,"Relationship");return b.setAttribute("Id",`rId${c}`),b.setAttribute("Type",`${Bn}/image`),b.setAttribute("Target",`media/image${f}.${r}`),(k=a.documentElement)==null||k.appendChild(b),{id:`rId${c}`,part:s,mediaPart:w}}function xp(e,t,n){var a,l,c;let r=pack.getPart(e,"[Content_Types].xml"),o=r==null?void 0:r.xmlDom;if(!r||!o)return;let i=o.getElementsByTagNameNS("http://schemas.openxmlformats.org/package/2006/content-types","Default");for(let u=0;u<i.length;u+=1)if(((l=(a=i[u])==null?void 0:a.getAttribute("Extension"))==null?void 0:l.toLowerCase())===t.toLowerCase())return;let s=o.createElementNS("http://schemas.openxmlformats.org/package/2006/content-types","Default");s.setAttribute("Extension",t),s.setAttribute("ContentType",n),(c=o.documentElement)==null||c.appendChild(s),pack.markDirty(r);}function _x(e){let t=0;for(let n=0;n<e.length;n+=1)t=t*31+e.charCodeAt(n)|0;return t}function qx(e,t){var l,c,u;if(t.op==="accept"||t.op==="reject"){let f=t.revisionKind==="insert"?"ins":"del",w=Array.from(e.getElementsByTagNameNS(wordView.W_NS,f)).filter(b=>b.getAttributeNS(wordView.W_NS,"id")===t.revisionId);if(w.length===0)return {ok:false,reason:`revision not found: ${t.revisionId}`};for(let b of w){let g=b.parentNode;if(!g)continue;if(!(f==="ins"&&t.op==="accept"||f==="del"&&t.op==="reject")){g.removeChild(b);continue}let y=Array.from(b.childNodes);if(f==="del")for(let k of y)k.nodeType===1&&ey(k);for(let k of y)g.insertBefore(k,b);g.removeChild(b);}return {ok:true}}if(t.from<0||t.to<=t.from)return {ok:false,reason:"revision range is empty or invalid"};let n=0,r=[],o=-1,i=[];for(let f of Array.from(e.childNodes)){if(f.nodeType!==1||f.namespaceURI!==wordView.W_NS){i.push(f);continue}let p=f;if(p.localName==="ins"||p.localName==="del"){i.push(p),n+=(c=(l=p.textContent)==null?void 0:l.length)!=null?c:0;continue}if(p.localName!=="r"){i.push(p);continue}let w=Array.from(p.getElementsByTagNameNS(wordView.W_NS,"t"));if(w.length!==1)return {ok:false,reason:"revision writeback requires runs with one text node"};let b=(u=w[0].textContent)!=null?u:"",g=n,h=n+b.length;if(n=h,h<=t.from||g>=t.to){i.push(p);continue}let y=Math.max(0,t.from-g),k=Math.min(b.length,t.to-g);y>0&&i.push(Jn(p,b.slice(0,y))),k>y&&(o<0&&(o=i.length),r.push(Jn(p,b.slice(y,k)))),k<b.length&&i.push(Jn(p,b.slice(k)));}if(r.length===0||t.to>n)return {ok:false,reason:`revision range out of range: ${t.from}:${t.to}`};let s=e.ownerDocument;if(!s)return {ok:false,reason:"revision paragraph has no owner document"};let a=s.createElementNS(wordView.W_NS,t.revisionKind==="insert"?"w:ins":"w:del");a.setAttributeNS(wordView.W_NS,"w:id",t.revisionId),a.setAttributeNS(wordView.W_NS,"w:author","User"),a.setAttributeNS(wordView.W_NS,"w:date",new Date().toISOString());for(let f of r)t.revisionKind==="delete"&&Qx(f),a.appendChild(f);for(i.splice(o<0?i.length:o,0,a),Jx(i);e.firstChild;)e.removeChild(e.firstChild);for(let f of i)e.appendChild(f);return {ok:true}}function Xx(e,t){var s;if(t.from<0||t.to<=t.from)return {ok:false,reason:"format range is empty or invalid"};if(e.getElementsByTagNameNS(wordView.W_NS,"ins").length>0||e.getElementsByTagNameNS(wordView.W_NS,"del").length>0){let a=Array.from(e.getElementsByTagNameNS(wordView.W_NS,"r")),l=0,c=0;for(let u of a){let f=yp(u);if(f.length===0)continue;let p=l,w=l+f.length;if(l=w,!(w<=t.from||p>=t.to)){if(t.from>p||t.to<w)return {ok:false,reason:"format writeback requires whole runs inside tracked content"};Ts(u,t.format),c+=f.length;}}return c===0||t.to>l?{ok:false,reason:`format range out of range: ${t.from}:${t.to}`}:{ok:true}}let r=[],o=0,i=0;for(let a of Array.from(e.childNodes)){if(a.nodeType!==1||a.namespaceURI!==wordView.W_NS||a.localName!=="r"){r.push(a);continue}let l=a,c=Array.from(l.getElementsByTagNameNS(wordView.W_NS,"t"));if(c.length!==1)return {ok:false,reason:"format writeback requires runs with one text node"};let u=(s=c[0].textContent)!=null?s:"",f=o,p=o+u.length;if(o=p,p<=t.from||f>=t.to){r.push(l);continue}let w=Math.max(0,t.from-f),b=Math.min(u.length,t.to-f);if(w>0&&r.push(Jn(l,u.slice(0,w))),b>w){let g=Jn(l,u.slice(w,b));Ts(g,t.format),r.push(g),i+=b-w;}b<u.length&&r.push(Jn(l,u.slice(b)));}if(i===0||t.to>o)return {ok:false,reason:`format range out of range: ${t.from}:${t.to}`};for(;e.firstChild;)e.removeChild(e.firstChild);for(let a of r)e.appendChild(a);return {ok:true}}function Yx(e,t){var o;let n=Array.from(e.getElementsByTagNameNS(wordView.W_NS,"r"));if(t.op==="run"){if(t.beforeFormat===void 0)return {ok:false,reason:"format revision is missing beforeFormat snapshot"};let i=0,s=0;for(let a of n){let l=yp(a),c=i,u=i+l.length;if(i=u,u<=t.from||c>=t.to)continue;if(t.from>c||t.to<u)return {ok:false,reason:"format revision currently requires whole runs"};let f=Zx(a);Wn(f,"rPrChange");let p=f.ownerDocument.createElementNS(wordView.W_NS,"w:rPrChange");p.setAttributeNS(wordView.W_NS,"w:id",t.revisionId),p.setAttributeNS(wordView.W_NS,"w:author","User"),p.setAttributeNS(wordView.W_NS,"w:date",new Date().toISOString());let w=f.ownerDocument.createElementNS(wordView.W_NS,"w:r");Ts(w,(o=t.beforeFormat)!=null?o:{});let b=oe(w).find(g=>g.namespaceURI===wordView.W_NS&&g.localName==="rPr");if(b)for(let g of Array.from(b.childNodes))p.appendChild(g);f.appendChild(p),s+=l.length;}return s===0||t.to>i?{ok:false,reason:`format revision range not found: ${t.from}:${t.to}`}:{ok:true}}let r=0;for(let i of n){let s=oe(i).find(l=>l.namespaceURI===wordView.W_NS&&l.localName==="rPr"),a=s&&oe(s).find(l=>l.namespaceURI===wordView.W_NS&&l.localName==="rPrChange"&&l.getAttributeNS(wordView.W_NS,"id")===t.revisionId);if(!(!a||!s)){if(t.op==="reject"){for(let l of Array.from(s.childNodes))l!==a&&s.removeChild(l);for(let l of Array.from(a.childNodes))s.appendChild(l.cloneNode(true));}s.removeChild(a),r+=1;}}return r>0?{ok:true}:{ok:false,reason:`format revision not found: ${t.revisionId}`}}function yp(e){return Array.from(e.getElementsByTagNameNS(wordView.W_NS,"t")).concat(Array.from(e.getElementsByTagNameNS(wordView.W_NS,"delText"))).map(t=>{var n;return (n=t.textContent)!=null?n:""}).join("")}function Zx(e){let t=oe(e).find(r=>r.namespaceURI===wordView.W_NS&&r.localName==="rPr");if(t)return t;let n=e.ownerDocument.createElementNS(wordView.W_NS,"w:rPr");return e.insertBefore(n,e.firstChild),n}function Ts(e,t){var i,s,a;let n=e.ownerDocument,r=(i=oe(e).find(l=>l.namespaceURI===wordView.W_NS&&l.localName==="rPr"))!=null?i:null;r||(r=n.createElementNS(wordView.W_NS,"w:rPr"),e.insertBefore(r,e.firstChild));let o=[["bold","b"],["italic","i"],["strike","strike"],["doubleStrike","dstrike"],["caps","caps"],["smallCaps","smallCaps"]];for(let[l,c]of o)t[l]!==void 0&&(Wn(r,c),t[l]&&r.appendChild(n.createElementNS(wordView.W_NS,`w:${c}`)));if(t.underline!==void 0&&(Wn(r,"u"),t.underline)){let l=n.createElementNS(wordView.W_NS,"w:u");l.setAttribute("val","single"),r.appendChild(l);}if(t.color!==void 0&&(Wn(r,"color"),t.color)){let l=n.createElementNS(wordView.W_NS,"w:color");l.setAttribute("val",t.color.replace(/^#/,"").toUpperCase()),r.appendChild(l);}if(t.highlight!==void 0||t.shading!==void 0){Wn(r,"shd");let l=(a=(s=t.shading)==null?void 0:s.fill)!=null?a:t.highlight;if(l){let c=n.createElementNS(wordView.W_NS,"w:shd");c.setAttribute("val","clear"),c.setAttribute("fill",l.replace(/^#/,"").toUpperCase()),r.appendChild(c);}}if(t.fontSize!==void 0){Wn(r,"sz");let l=n.createElementNS(wordView.W_NS,"w:sz");l.setAttribute("val",String(Math.round(t.fontSize*2))),r.appendChild(l);}if(t.fontFamily!==void 0){Wn(r,"rFonts");let l=n.createElementNS(wordView.W_NS,"w:rFonts");l.setAttribute("ascii",t.fontFamily),l.setAttribute("hAnsi",t.fontFamily),l.setAttribute("eastAsia",t.fontFamily),l.setAttribute("cs",t.fontFamily),r.appendChild(l);}}function Wn(e,t){for(let n of oe(e))n.namespaceURI===wordView.W_NS&&n.localName===t&&e.removeChild(n);}function Jx(e){for(let t=1;t<e.length;t+=1){let n=e[t-1],r=e[t];if((n==null?void 0:n.nodeType)!==1||(r==null?void 0:r.nodeType)!==1)continue;let o=n,i=r;if(!(o.namespaceURI!==wordView.W_NS||i.namespaceURI!==wordView.W_NS||o.localName!==i.localName||o.localName!=="ins"&&o.localName!=="del"||o.getAttributeNS(wordView.W_NS,"id")!==i.getAttributeNS(wordView.W_NS,"id"))){for(let s of Array.from(i.childNodes))o.appendChild(s);e.splice(t,1),t-=1;}}}function Jn(e,t){let n=e.cloneNode(true),r=n.getElementsByTagNameNS(wordView.W_NS,"t")[0];return r&&(r.textContent=t),n}function Qx(e){var r;let t=e.ownerDocument,n=Array.from(e.getElementsByTagNameNS(wordView.W_NS,"t"));for(let o of n){let i=t.createElementNS(wordView.W_NS,"w:delText");for(let s=0;s<o.attributes.length;s+=1){let a=o.attributes[s];a&&i.setAttributeNS(a.namespaceURI,a.name,a.value);}i.textContent=o.textContent,(r=o.parentNode)==null||r.replaceChild(i,o);}}function ey(e){var r;let t=e.ownerDocument,n=Array.from(e.getElementsByTagNameNS(wordView.W_NS,"delText"));for(let o of n){let i=t.createElementNS(wordView.W_NS,"w:t");for(let s=0;s<o.attributes.length;s+=1){let a=o.attributes[s];a&&i.setAttributeNS(a.namespaceURI,a.name,a.value);}i.textContent=o.textContent,(r=o.parentNode)==null||r.replaceChild(i,o);}}function ty(e,t,n,r){var s;if(r.op==="insert"){if(r.from<0||r.to<=r.from)return {ok:false,reason:"comment range is empty or invalid"};let a=jr(n).reduce((c,u)=>c+u.length,0);if(r.to>a)return {ok:false,reason:`comment range out of range: ${r.from}:${r.to}`};ny(e,t),cy(n,r.from,r.to,r.commentId);let l=new Date().toISOString();return iy(e,r.commentId,(s=r.body)!=null?s:"","User",l),r.parentCommentId!==void 0&&ay(e,r.commentId,r.parentCommentId),{ok:true}}if(r.op==="update"){if(r.body===void 0)return {ok:false,reason:"comment update requires body"};let a=e.parts.get("word/comments.xml"),l=a==null?void 0:a.xmlDom;if(!a||!l)return {ok:false,reason:"comments.xml part not found"};let c=l.getElementsByTagNameNS(wordView.W_NS,"comment");for(let u=0;u<c.length;u+=1){let f=c[u];if((f==null?void 0:f.getAttributeNS(wordView.W_NS,"id"))!==String(r.commentId))continue;let p=f.getElementsByTagNameNS(wordView.W_NS,"t");if(p.length===0){let w=l.createElementNS(wordView.W_NS,"w:p"),b=l.createElementNS(wordView.W_NS,"w:r"),g=l.createElementNS(wordView.W_NS,"w:t");g.textContent=r.body,b.appendChild(g),w.appendChild(b),f.appendChild(w);}else {p[0].textContent=r.body;for(let w=p.length-1;w>=1;w-=1)Ue(p[w]);}return pack.markDirty(a),{ok:true}}return {ok:false,reason:`comment not found: ${r.commentId}`}}uy(e,r.commentId),ly(e,r.commentId);let o=e.parts.get("word/comments.xml"),i=o==null?void 0:o.xmlDom;if(i){let a=i.getElementsByTagNameNS(wordView.W_NS,"comment");for(let l=0;l<a.length;l+=1){let c=a[l];(c==null?void 0:c.getAttributeNS(wordView.W_NS,"id"))===String(r.commentId)&&Ue(c);}pack.markDirty(o);}return {ok:true}}function ny(e,t){var r,o;let n=e.parts.get("word/comments.xml");if(!(n!=null&&n.xmlDom)){let i=(r=Array.from(e.parts.values()).find(a=>a.xmlDom))==null?void 0:r.xmlDom;if(!i)throw new Error("cannot create comments.xml without an XML part");let s=(o=i.implementation)==null?void 0:o.createDocument(wordView.W_NS,"w:comments",null);if(!s)throw new Error("XML implementation cannot create comments.xml");n=pack.createXmlPart({path:"word/comments.xml",contentType:op,xmlDom:s}),pack.setPart(e,n),ry(e);}return oy(e,t),n}function ry(e){var i,s;let t=pack.getPart(e,"[Content_Types].xml"),n=t==null?void 0:t.xmlDom;if(!t||!n)return;let r=n.getElementsByTagNameNS(ii,"Override");for(let a=0;a<r.length;a+=1)if(((i=r[a])==null?void 0:i.getAttribute("PartName"))==="/word/comments.xml")return;let o=n.createElementNS(ii,"Override");o.setAttribute("PartName","/word/comments.xml"),o.setAttribute("ContentType",op),(s=n.documentElement)==null||s.appendChild(o),pack.markDirty(t);}function oy(e,t){var c,u,f;let n=si(t),r=e.parts.get(n);if(!(r!=null&&r.xmlDom))return;let o=r.xmlDom,i=o.getElementsByTagNameNS($t,"Relationship");for(let p=0;p<i.length;p+=1)if(((c=i[p])==null?void 0:c.getAttribute("Type"))===`${Bn}/comments`)return;let s=new Set;for(let p=0;p<i.length;p+=1){let w=(u=i[p])==null?void 0:u.getAttribute("Id");w&&s.add(w);}let a=1;for(;s.has(`rId${a}`);)a+=1;let l=o.createElementNS($t,"Relationship");l.setAttribute("Id",`rId${a}`),l.setAttribute("Type",`${Bn}/comments`),l.setAttribute("Target","comments.xml"),(f=o.documentElement)==null||f.appendChild(l),pack.markDirty(r);}function iy(e,t,n,r,o){let i=e.parts.get("word/comments.xml"),s=i==null?void 0:i.xmlDom;if(!i||!s)return;let a=s.documentElement;if(!a||Array.from(s.getElementsByTagNameNS(wordView.W_NS,"comment")).some(p=>p.getAttributeNS(wordView.W_NS,"id")===String(t)))return;let l=s.createElementNS(wordView.W_NS,"w:comment");l.setAttributeNS(wordView.W_NS,"w:id",String(t)),l.setAttributeNS(wordView.W_NS,"w:author",r),l.setAttributeNS(wordView.W_NS,"w:date",o),l.setAttributeNS(wordView.W_NS,"w:initials",r.slice(0,1));let c=s.createElementNS(wordView.W_NS,"w:p");c.setAttributeNS(wordView.W14_NS,"w14:paraId",sy(t));let u=s.createElementNS(wordView.W_NS,"w:r"),f=s.createElementNS(wordView.W_NS,"w:t");f.textContent=n,gn(f),u.appendChild(f),c.appendChild(u),l.appendChild(c),a.appendChild(l),pack.markDirty(i);}function ay(e,t,n){let r=e.parts.get("word/comments.xml"),o=r==null?void 0:r.xmlDom;if(!o)return;let i=w=>{var g,h,y;let b=o.getElementsByTagNameNS(wordView.W_NS,"comment");for(let k=0;k<b.length;k+=1){if(((g=b[k])==null?void 0:g.getAttributeNS(wordView.W_NS,"id"))!==String(w))continue;let C=(h=b[k])==null?void 0:h.getElementsByTagNameNS(wordView.W_NS,"p")[0];return (y=C==null?void 0:C.getAttributeNS(wordView.W14_NS,"paraId"))!=null?y:null}return null},s=i(t),a=i(n);if(!s||!a)return;let l=dy(e,"word/document.xml"),c=l.xmlDom,u=c==null?void 0:c.documentElement;if(!c||!u||Array.from(u.getElementsByTagNameNS(tn,"commentEx")).some(w=>w.getAttributeNS(tn,"paraId")===s))return;let p=c.createElementNS(tn,"w15:commentEx");p.setAttributeNS(tn,"w15:paraId",s),p.setAttributeNS(tn,"w15:paraIdParent",a),u.appendChild(p),pack.markDirty(l);}function sy(e){return e.toString(16).padStart(8,"0").slice(-8)}function ly(e,t){var c,u,f,p;let n=e.parts.get("word/comments.xml"),r=n==null?void 0:n.xmlDom,o=e.parts.get("word/commentsExtended.xml"),i=o==null?void 0:o.xmlDom;if(!r||!i)return;let s=r.getElementsByTagNameNS(wordView.W_NS,"comment"),a=null;for(let w=0;w<s.length;w+=1)if(((c=s[w])==null?void 0:c.getAttributeNS(wordView.W_NS,"id"))===String(t)){a=(p=(f=(u=s[w])==null?void 0:u.getElementsByTagNameNS(wordView.W_NS,"p")[0])==null?void 0:f.getAttributeNS(wordView.W14_NS,"paraId"))!=null?p:null;break}if(!a)return;let l=Array.from(i.getElementsByTagNameNS(tn,"commentEx"));for(let w of l)(w.getAttributeNS(tn,"paraId")===a||w.getAttributeNS(tn,"paraIdParent")===a)&&(Ue(w),pack.markDirty(o));}function dy(e,t){var s,a,l,c,u,f;let n=e.parts.get("word/commentsExtended.xml");if(!(n!=null&&n.xmlDom)){let p=(l=(s=e.parts.get(t))==null?void 0:s.xmlDom)!=null?l:(a=Array.from(e.parts.values()).find(b=>b.xmlDom))==null?void 0:a.xmlDom;if(!p)throw new Error("cannot create commentsExtended.xml without an XML part");let w=(c=p.implementation)==null?void 0:c.createDocument(tn,"w15:commentsEx",null);if(!w)throw new Error("XML implementation cannot create commentsExtended.xml");n=pack.createXmlPart({path:"word/commentsExtended.xml",contentType:Zu,xmlDom:w}),pack.setPart(e,n);}let r=pack.getPart(e,"[Content_Types].xml");if(r!=null&&r.xmlDom){let p=r.xmlDom.getElementsByTagNameNS(ii,"Override");if(!Array.from(p).some(w=>w.getAttribute("PartName")==="/word/commentsExtended.xml")){let w=r.xmlDom.createElementNS(ii,"Override");w.setAttribute("PartName","/word/commentsExtended.xml"),w.setAttribute("ContentType",Zu),(u=r.xmlDom.documentElement)==null||u.appendChild(w),pack.markDirty(r);}}let o=e.parts.get(si(t)),i=o==null?void 0:o.xmlDom;if(i&&!Array.from(i.getElementsByTagNameNS($t,"Relationship")).some(p=>p.getAttribute("Type")===Ju)){let p=i.getElementsByTagNameNS($t,"Relationship"),w=new Set(Array.from(p).map(h=>h.getAttribute("Id")).filter(Boolean)),b=1;for(;w.has(`rId${b}`);)b+=1;let g=i.createElementNS($t,"Relationship");g.setAttribute("Id",`rId${b}`),g.setAttribute("Type",Ju),g.setAttribute("Target","commentsExtended.xml"),(f=i.documentElement)==null||f.appendChild(g),pack.markDirty(o);}return n}function cy(e,t,n,r){let o=e.ownerDocument,i=o.createElementNS(wordView.W_NS,"w:commentRangeStart");i.setAttributeNS(wordView.W_NS,"w:id",String(r));let s=o.createElementNS(wordView.W_NS,"w:commentRangeEnd");s.setAttributeNS(wordView.W_NS,"w:id",String(r));let a=o.createElementNS(wordView.W_NS,"w:r"),l=o.createElementNS(wordView.W_NS,"w:commentReference");l.setAttributeNS(wordView.W_NS,"w:id",String(r)),a.appendChild(l);let c=new Map;c.set(t,[i]),c.set(n,[s,a]);let u=oe(e).filter(w=>!(w.namespaceURI===wordView.W_NS&&w.localName==="pPr")),f=[],p=0;for(let w of u){let b=c.get(p);b&&f.push(...b);let g=zt(w),h=[t,n].filter(k=>k>p&&k<p+g).sort((k,C)=>k-C),y=0;for(let k of [...h,p+g]){let C=Zn(w,y,k-p);C&&f.push(C);let N=k,L=c.get(N);L&&f.push(...L),y=k-p;}g===0&&f.push(w),p+=g;}for(let w of [t,n])if(w===p){let b=c.get(w);b&&f.push(...b);}for(let w of u)Ue(w);for(let w of f)e.appendChild(w);}function uy(e,t){for(let n of e.parts.values()){let r=n.xmlDom;if(r)for(let o of ["commentRangeStart","commentRangeEnd","commentReference"]){let i=r.getElementsByTagNameNS(wordView.W_NS,o),s=[];for(let a=0;a<i.length;a+=1){let l=i[a];(l==null?void 0:l.getAttributeNS(wordView.W_NS,"id"))===String(t)&&s.push(l);}for(let a of s){let l=a.parentNode;o==="commentReference"&&(l==null?void 0:l.nodeType)===1&&l.namespaceURI===wordView.W_NS&&l.localName==="r"?Ue(l):Ue(a);}s.length>0&&pack.markDirty(n);}}}function py(e){for(let t=0;t<e.childNodes.length;t++){let n=e.childNodes[t];if(!n||n.nodeType!==1)continue;let r=n;if(!(r.namespaceURI===wordView.W_NS&&(r.localName==="rPr"||r.localName==="drawing")))return false}return true}function fy(e){return e.nodeType===1}var Ut=new prosemirrorModel.Schema({nodes:{doc:{content:"block+"},paragraph:{group:"block",content:"inline*",attrs:{paraId:{default:""},story:{default:"body"},styleId:{default:null},format:{default:null}},parseDOM:[{tag:"p"}],toDOM:e=>["p",hy(e.attrs),0]},table:{group:"block",content:"table_row+",attrs:{tableId:{default:""},columnWidths:{default:null}},tableRole:"table",toDOM:e=>["div",{class:"coco-word-table-scroll"},["table",gy(e.attrs),["tbody",0]]]},table_row:{content:"table_cell+",tableRole:"row",toDOM:()=>["tr",0]},table_cell:{content:"block+",attrs:{colspan:{default:1},rowspan:{default:1},width:{default:null},shading:{default:null},verticalAlignment:{default:null}},tableRole:"cell",toDOM:e=>["td",by(e.attrs),0]},image:{inline:true,group:"inline",atom:true,attrs:{src:{},alt:{default:""},width:{default:null},height:{default:null},drawingId:{default:null}},toDOM:e=>["img",wy(e.attrs)]},text:{group:"inline"}},marks:{strong:{parseDOM:[{tag:"strong"},{tag:"b"}],toDOM:()=>["strong",0]},em:{parseDOM:[{tag:"em"},{tag:"i"}],toDOM:()=>["em",0]},underline:{parseDOM:[{tag:"u"}],toDOM:()=>["u",0]},textStyle:{attrs:{color:{default:null},fontSize:{default:null}},parseDOM:[{tag:"span"}],toDOM:e=>["span",yy(e.attrs),0]}}});new prosemirrorState.PluginKey("coco-word-decorations");var Sp=new prosemirrorState.PluginKey("coco-word-structure-normalization");function hy(e){let t={};typeof e.paraId=="string"&&e.paraId.length>0&&(t["data-para-id"]=e.paraId),typeof e.story=="string"&&e.story.length>0&&(t["data-story"]=e.story),typeof e.styleId=="string"&&e.styleId.length>0&&(t["data-style-id"]=e.styleId);let n=vy(e.format)?e.format:null;(n==null?void 0:n.outlineLevel)!==void 0&&(t["data-outline-level"]=String(n.outlineLevel));let r=Sy(n);return r.length>0&&(t.style=r),t}function gy(e){let t={};return typeof e.tableId=="string"&&e.tableId.length>0&&(t["data-table-id"]=e.tableId),t}function by(e){let t={};typeof e.colspan=="number"&&e.colspan>1&&(t.colspan=String(e.colspan)),typeof e.rowspan=="number"&&e.rowspan>1&&(t.rowspan=String(e.rowspan));let n=[];if(typeof e.width=="number"&&e.width>0&&n.push(`width: ${Fn(e.width)}`),xy(e.shading)){let r=Rs(e.shading.fill);r&&n.push(`background-color: ${r}`);}return typeof e.verticalAlignment=="string"&&n.push(`vertical-align: ${e.verticalAlignment==="center"?"middle":e.verticalAlignment}`),n.length>0&&(t.style=n.join("; ")),t}function wy(e){let t={src:typeof e.src=="string"?e.src:"",alt:typeof e.alt=="string"?e.alt:""};typeof e.drawingId=="string"&&(t["data-drawing-id"]=e.drawingId);let n=[];return typeof e.width=="number"&&e.width>0&&n.push(`width: ${e.width}px`),typeof e.height=="number"&&e.height>0&&n.push(`height: ${e.height}px`),n.length>0&&(t.style=n.join("; ")),t}function xy(e){return e!==null&&typeof e=="object"}function yy(e){let t=[],n=typeof e.color=="string"?Rs(e.color):null;return n&&t.push(`color: ${n}`),typeof e.fontSize=="number"&&t.push(`font-size: ${e.fontSize}pt`),t.length>0?{style:t.join("; ")}:{}}function vy(e){return e!==null&&typeof e=="object"}function Sy(e){var o,i,s,a,l,c,u,f,p;if(!e)return "";let t=[];e.alignment&&t.push(`text-align: ${ky(e.alignment)}`),((o=e.indent)==null?void 0:o.left)!==void 0&&t.push(`margin-left: ${Fn(e.indent.left)}`),((i=e.indent)==null?void 0:i.right)!==void 0&&t.push(`margin-right: ${Fn(e.indent.right)}`),((s=e.indent)==null?void 0:s.firstLine)!==void 0&&t.push(`text-indent: ${Fn(e.indent.firstLine)}`),((a=e.spacing)==null?void 0:a.before)!==void 0&&t.push(`margin-top: ${Fn(e.spacing.before)}`),((l=e.spacing)==null?void 0:l.after)!==void 0&&t.push(`margin-bottom: ${Fn(e.spacing.after)}`);let n=Cy((c=e.spacing)==null?void 0:c.line,(u=e.spacing)==null?void 0:u.lineRule);n&&t.push(`line-height: ${n}`),e.fontSize!==void 0&&t.push(`font-size: ${e.fontSize}pt`),e.bold!==void 0&&t.push(`font-weight: ${e.bold?"700":"400"}`);let r=Ey(e.borderBottom);return r&&(t.push(`border-bottom: ${r}`),t.push(`padding-bottom: ${(p=(f=e.borderBottom)==null?void 0:f.space)!=null?p:4}pt`)),t.join("; ")}function ky(e){return e==="both"||e==="distribute"?"justify":e}function Ey(e){var o;if(!e||e.val==="none"||e.val==="nil")return null;let t=(o=Rs(e.color))!=null?o:"#000000",n=e.size!==void 0?Math.max(.75,e.size/8):.75,r=e.val==="double"?"double":"solid";return `${n}pt ${r} ${t}`}function Cy(e,t){return e===void 0?null:t==="exact"||t==="atLeast"?Fn(e):String(e/240)}function Fn(e){return `${e/20}pt`}function Rs(e){return !e||e==="auto"?null:/^[0-9a-f]{6}$/i.test(e)?`#${e}`:null}var Kr=new prosemirrorState.PluginKey("coco-word-editing"),Ty=0;function xC(e={}){return new prosemirrorState.Plugin({key:Kr,appendTransaction(t,n,r){if(!t.some(s=>s.docChanged)||t.every(s=>s.getMeta(Sp)))return null;let o=My(n.doc,r.doc),i=o.length>0?o:Wy(n.doc,r.doc);return i.length>0?Tp(r.tr,i):null},state:{init:()=>({changes:[]}),apply(t,n){var i,s;let r=t.getMeta(Kr);if(!((i=r==null?void 0:r.changes)!=null&&i.length))return n;let o={changes:[...n.changes,...r.changes]};return (s=e.onChangeSet)==null||s.call(e,o),o}}})}function yC(e){var t;return (t=Kr.getState(e))!=null?t:{changes:[]}}function vC(e){var a,l;let{from:t,to:n,empty:r}=e.selection,o=e.selection.$from,i=Oy(o,"table_cell"),s=i===null?null:{depth:i,colspan:Number((a=o.node(i).attrs.colspan)!=null?a:1),rowspan:Number((l=o.node(i).attrs.rowspan)!=null?l:1)};return {from:t,to:n,empty:r,selectedText:e.doc.textBetween(t,n,`
12
- `),paragraphs:Ws(e,t,n),tableCell:s}}function SC(e,t,n){let r=Ut.marks.strong;return Ls(e,t,n,r,{},"strong")}function kC(e){return (t,n,r)=>!Number.isFinite(e)||e<=0?false:Ls(t,n,r,Ut.marks.textStyle,{fontSize:e},"textStyle")}function EC(e){return (t,n,r)=>{let o=Hy(e);return o?Ls(t,n,r,Ut.marks.textStyle,{color:o},"textStyle"):false}}function CC(e){return (t,n)=>{let r=Ws(t,t.selection.from,t.selection.to);if(r.length===0)return false;if(!n)return true;let o=t.tr;return t.doc.nodesBetween(t.selection.from,t.selection.to,(i,s)=>{if(i.type!==Ut.nodes.paragraph)return true;let a=Dy(i.attrs.format,{alignment:e});return o=o.setNodeMarkup(s,void 0,$(v({},i.attrs),{format:a})),false}),o=Np(o,{kind:"paragraph",from:t.selection.from,to:t.selection.to,paragraphs:r,target:li(r),status:"captured",attr:"alignment",value:e}),n(o.scrollIntoView()),true}}function Ls(e,t,n,r,o,i){let{from:s,to:a,empty:l}=e.selection;if(l)return false;let c=Ws(e,s,a);if(c.length===0)return false;let u=i==="strong"&&Py(e.doc,s,a,r);if(!t)return true;let f=e.tr;return u?f=f.removeMark(s,a,r):f=f.addMark(s,a,r.create(o)),f=Np(f,{kind:"mark",from:s,to:a,paragraphs:c,target:li(c),status:"captured",mark:i,value:i==="strong"?!u:o}),t(f.scrollIntoView()),n==null||n.focus(),true}function Ws(e,t,n){let r=[],o=Math.max(n,t+1);return e.doc.nodesBetween(t,o,(i,s)=>{if(i.type!==Ut.nodes.paragraph)return true;let a=s+1,l=a+i.content.size;return r.push({paraId:typeof i.attrs.paraId=="string"?i.attrs.paraId:"",from:Math.max(t,a)-a,to:Math.min(n,l)-a,text:i.textContent,styleId:typeof i.attrs.styleId=="string"?i.attrs.styleId:null,story:typeof i.attrs.story=="string"?i.attrs.story:"body"}),false}),r}function li(e){var n;let t=e[0];return v({story:(n=t==null?void 0:t.story)!=null?n:"body"},t!=null&&t.paraId?{paraId:t.paraId}:{})}function Py(e,t,n,r){let o=false;return e.nodesBetween(t,n,i=>(o||!i.isText||(o=r.isInSet(i.marks)!==void 0),!o)),o}function Np(e,t){return Tp(e,[t])}function Tp(e,t){var o,i;let n=(o=e.getMeta(Kr))!=null?o:{},r=(i=n.changes)!=null?i:[];return e.setMeta(Kr,$(v({},n),{changes:[...r,...t.map(s=>$(v({},s),{id:`word-edit:${++Ty}`,createdAt:Date.now()}))]}))}function My(e,t){let n=Ep(e),r=Ep(t),o=Ry(n,r);if(o)return [o];let i=Ay(n,r);if(i)return [i];let s=Ly(n,r);return s?[s]:[]}function Ry(e,t){if(t.length!==e.length+1)return null;for(let n=0;n<e.length;n+=1){if(!di(e.slice(0,n),t.slice(0,n))||!di(e.slice(n+1),t.slice(n+2)))continue;let r=e[n],o=t[n],i=t[n+1];if(!(r.block.kind!=="paragraph"||o.block.kind!=="paragraph"||i.block.kind!=="paragraph"||o.block.text+i.block.text!==r.block.text))return {kind:"block",blockOp:"split",from:r.pos,to:r.pos+r.size,paragraphs:Bs([o,i]),target:Fs(r.block),status:"captured",blocks:[o.block,i.block],deletedBlocks:[r.block],value:{before:r.block,after:[o.block,i.block]}}}return null}function Ay(e,t){if(e.length!==t.length+1)return null;for(let n=0;n<t.length;n+=1){if(!di(e.slice(0,n),t.slice(0,n))||!di(e.slice(n+2),t.slice(n+1)))continue;let r=e[n],o=e[n+1],i=t[n];if(!(r.block.kind!=="paragraph"||o.block.kind!=="paragraph"||i.block.kind!=="paragraph"||r.block.text+o.block.text!==i.block.text))return {kind:"block",blockOp:"merge",from:r.pos,to:o.pos+o.size,paragraphs:Bs([i]),target:Fs(i.block),status:"captured",blocks:[i.block],deletedBlocks:[r.block,o.block],value:{before:[r.block,o.block],after:i.block}}}return null}function Ly(e,t){var f,p,w,b,g;let n=0,r=Math.min(e.length,t.length);for(;n<r&&As(e[n],t[n]);)n+=1;let o=0,i=Math.min(e.length-n,t.length-n);for(;o<i&&As(e[e.length-1-o],t[t.length-1-o]);)o+=1;let s=e.slice(n,e.length-o),a=t.slice(n,t.length-o);if(s.length===0&&a.length===0)return null;let l=(f=a[0])!=null?f:s[0],c=(w=(p=a[a.length-1])!=null?p:s[s.length-1])!=null?w:l;return {kind:"block",blockOp:a.length>0&&s.length>0?"replace":a.length>0?"insert":"delete",from:(b=l==null?void 0:l.pos)!=null?b:0,to:c?c.pos+c.size:(g=l==null?void 0:l.pos)!=null?g:0,paragraphs:Bs(a.length>0?a:s),target:l?Fs(l.block):{story:"body"},status:"captured",blocks:a.map(h=>h.block),deletedBlocks:s.map(h=>h.block),value:{before:s.map(h=>h.block),after:a.map(h=>h.block)}}}function Wy(e,t){let n=kp(e),r=kp(t),o=new Map(n.map(s=>[s.paraId,s])),i=[];for(let s of r){if(!s.paraId)continue;let a=o.get(s.paraId);if(!a||Mp(a.content,s.content))continue;let l=Fy(a.content,s.content);if(!l)continue;let c=s.pos+1+l.from,u=s.pos+1+l.toAfter,f={paraId:s.paraId,from:l.from,to:l.toAfter,text:s.text,styleId:s.styleId,story:s.story};if(Cp(l.insertedContent)&&Cp(l.deletedContent)){i.push({kind:"text",from:c,to:u,paragraphs:[f],target:li([f]),status:"captured",textOp:l.operation,text:Ip(l.insertedContent),deletedText:Ip(l.deletedContent),value:{operation:l.operation,before:a.text,after:s.text}});continue}i.push({kind:"content",from:c,to:u,paragraphs:[f],target:li([f]),status:"captured",contentOp:l.operation,content:Ur(l.insertedContent),deletedContent:Ur(l.deletedContent),value:{operation:l.operation,before:Ur(a.content.map(p=>p.content)),after:Ur(s.content.map(p=>p.content))}});}return i}function kp(e){let t=[];return e.descendants((n,r)=>n.type!==Ut.nodes.paragraph?true:(t.push({paraId:typeof n.attrs.paraId=="string"?n.attrs.paraId:"",pos:r,text:n.textContent,content:Pp(n),styleId:typeof n.attrs.styleId=="string"?n.attrs.styleId:null,story:typeof n.attrs.story=="string"?n.attrs.story:"body"}),false)),t}function Ep(e){let t=[];return e.forEach((n,r,o)=>{if(n.type===Ut.nodes.paragraph){let i=typeof n.attrs.paraId=="string"?n.attrs.paraId:"",s=typeof n.attrs.story=="string"?n.attrs.story:"body",a={kind:"paragraph",paraId:i,story:s,styleId:typeof n.attrs.styleId=="string"?n.attrs.styleId:null,text:n.textContent,content:Ur(Pp(n).map(l=>l.content))};t.push({key:`paragraph:${i||o}`,pos:r,size:n.nodeSize,block:a});return}if(n.type===Ut.nodes.table){let i=typeof n.attrs.tableId=="string"?n.attrs.tableId:"",s={kind:"table",tableId:i,text:n.textContent};t.push({key:`table:${i||o}`,pos:r,size:n.nodeSize,block:s});}}),t}function di(e,t){return e.length===t.length&&e.every((n,r)=>As(n,t[r]))}function As(e,t){return e.key===t.key}function Bs(e){return e.flatMap(t=>t.block.kind!=="paragraph"?[]:[{paraId:t.block.paraId,from:0,to:t.block.text.length,text:t.block.text,styleId:t.block.styleId,story:t.block.story}])}function Fs(e){return e.kind==="table"?v({story:"body"},e.tableId?{tableId:e.tableId}:{}):v({story:e.story},e.paraId?{paraId:e.paraId}:{})}function Pp(e){let t=[];return e.forEach(n=>{var r,o;if(n.isText){for(let i of (r=n.text)!=null?r:"")t.push({key:`text:${i}`,content:{kind:"text",text:i}});return}if(n.type===Ut.nodes.image){let i=By(n);t.push({key:`image:${(o=i.drawingId)!=null?o:i.src}`,content:i});return}t.push({key:`${n.type.name}:${JSON.stringify(n.attrs)}`,content:{kind:"text",text:n.textContent}});}),t}function By(e){return {kind:"image",drawingId:typeof e.attrs.drawingId=="string"?e.attrs.drawingId:null,alt:typeof e.attrs.alt=="string"?e.attrs.alt:"",src:typeof e.attrs.src=="string"?e.attrs.src:"",width:typeof e.attrs.width=="number"?e.attrs.width:null,height:typeof e.attrs.height=="number"?e.attrs.height:null}}function Fy(e,t){var f,p,w,b;if(Mp(e,t))return null;let n=0,r=Math.min(e.length,t.length);for(;n<r&&((f=e[n])==null?void 0:f.key)===((p=t[n])==null?void 0:p.key);)n+=1;let o=0,i=Math.min(e.length-n,t.length-n);for(;o<i&&((w=e[e.length-1-o])==null?void 0:w.key)===((b=t[t.length-1-o])==null?void 0:b.key);)o+=1;let s=e.length-o,a=t.length-o,l=t.slice(n,a).map(g=>g.content),c=e.slice(n,s).map(g=>g.content);return {operation:l.length>0&&c.length>0?"replace":l.length>0?"insert":"delete",from:n,toBefore:s,toAfter:a,insertedContent:l,deletedContent:c}}function Mp(e,t){return e.length===t.length&&e.every((n,r)=>{var o;return n.key===((o=t[r])==null?void 0:o.key)})}function Cp(e){return e.every(t=>t.kind==="text")}function Ip(e){return e.map(t=>t.kind==="text"?t.text:"").join("")}function Ur(e){let t=[];for(let n of e){let r=t[t.length-1];n.kind==="text"&&(r==null?void 0:r.kind)==="text"?r.text+=n.text:t.push(v({},n));}return t}function Dy(e,t){return v(v({},e!==null&&typeof e=="object"?e:{}),t)}function Hy(e){let t=e.trim().replace(/^#/,"");return /^[0-9a-f]{6}$/i.test(t)?t.toUpperCase():null}function Oy(e,t){for(let n=e.depth;n>0;n-=1)if(e.node(n).type.name===t)return n;return null}var Rp=`.coco-word-editor {
17
+ `)}function Ju(e){return jr(e)?e.kind==="paragraph"?typeof e.paraId=="string"&&typeof e.story=="string"&&Array.isArray(e.content)&&e.content.length<=1e5&&e.content.every(fx):e.kind!=="table"||typeof e.tableId!="string"||!Array.isArray(e.rows)||e.rows.length>1e4?false:e.rows.every(t=>jr(t)&&Array.isArray(t.cells)&&t.cells.length<=1e3&&t.cells.every(n=>jr(n)&&Array.isArray(n.blocks)&&n.blocks.length<=1e4&&n.blocks.every(Ju))):false}function fx(e){return !jr(e)||typeof e.kind!="string"?false:e.kind==="text"?typeof e.text=="string":e.kind==="image"?typeof e.drawingId=="string"&&typeof e.src=="string":e.kind==="drawing"?typeof e.drawingId=="string":e.kind==="pageBreak"?true:e.kind==="field"?typeof e.fieldKind=="string"&&typeof e.instruction=="string":false}function jr(e){return typeof e=="object"&&e!==null}function mx(e){let t="",n=0,r=[...e.runs].map(o=>$(v({},o),{from:Math.max(0,o.from),to:Math.min(e.text.length,o.to)})).filter(o=>o.to>o.from).sort((o,i)=>o.from-i.from||o.to-i.to);for(let o of r){if(o.from>n&&(t+=Es(e.text.slice(n,o.from))),o.from<n)continue;let i=Es(e.text.slice(o.from,o.to)),s=hx(o.format),a=s?`<span style="${Cs(s)}">${i}</span>`:i;if(o.hyperlink){let l=Dr(o.hyperlink.target,o.hyperlink.anchor),c=o.hyperlink.tooltip?` title="${Cs(o.hyperlink.tooltip)}"`:"";a=`<a href="${Cs(l)}"${c}>${a}</a>`;}t+=a,n=o.to;}return n<e.text.length&&(t+=Es(e.text.slice(n))),t||"<br>"}function hx(e){let t=[];e.bold!==void 0&&t.push(`font-weight:${e.bold?"700":"400"}`),e.italic!==void 0&&t.push(`font-style:${e.italic?"italic":"normal"}`);let n=[];return e.underline&&n.push("underline"),(e.strike||e.doubleStrike)&&n.push("line-through"),n.length>0?t.push(`text-decoration-line:${n.join(" ")}`):(e.underline===false||e.strike===false||e.doubleStrike===false)&&t.push("text-decoration-line:none"),e.fontFamily&&t.push(`font-family:${e.fontFamily}`),e.fontSize!==void 0&&t.push(`font-size:${e.fontSize}pt`),e.color&&t.push(`color:#${e.color.replace(/^#/,"")}`),e.highlight&&e.highlight!=="none"&&t.push(`background-color:#${e.highlight.replace(/^#/,"")}`),e.verticalAlign&&t.push(`vertical-align:${e.verticalAlign}`),e.caps&&t.push("text-transform:uppercase"),e.smallCaps&&t.push("font-variant-caps:small-caps"),e.characterSpacing!==void 0&&t.push(`letter-spacing:${e.characterSpacing/20}pt`),t.join(";")}function Es(e){return Qu(e).replace(/\r\n?|\n/g,"<br>")}function Qu(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function Cs(e){return Qu(e).replace(/"/g,"&quot;")}function ep(e,t,n,r){var s;if(e.nodeType===Node.TEXT_NODE){let a=(s=e.textContent)!=null?s:"";if(!a)return;let l=n.text.length;n.text+=a,(Object.keys(t).length>0||r)&&n.runs.push(v({from:l,to:n.text.length,format:t},r?{hyperlink:r}:{}));return}if(!(e instanceof HTMLElement))return;if(e.tagName==="BR"){n.text+=`
18
+ `;return}let o=v(v({},t),bx(e)),i=e.tagName==="A"?gx(e):r;for(let a of Array.from(e.childNodes))ep(a,o,n,i);}function gx(e){var o,i;let t=(o=e.getAttribute("href"))==null?void 0:o.trim();if(!t)return;let n=(i=e.getAttribute("title"))==null?void 0:i.trim();if(t.startsWith("#")){let s=t.slice(1);try{s=decodeURIComponent(s);}catch(a){return}return s?v({anchor:s},n?{tooltip:n}:{}):void 0}let r=Dr(t,void 0);return r==="#"?void 0:v({target:r},n?{tooltip:n}:{})}function bx(e){let t=e.style,n={};(e.matches("b, strong")||Number.parseInt(t.fontWeight,10)>=600)&&(n.bold=true),(e.matches("i, em")||t.fontStyle==="italic")&&(n.italic=true);let r=t.textDecorationLine||t.textDecoration;(e.matches("u")||r.includes("underline"))&&(n.underline=true),(e.matches("s, strike, del")||r.includes("line-through"))&&(n.strike=true),t.fontFamily&&(n.fontFamily=t.fontFamily.replace(/["']/g,""));let o=wx(t.fontSize);o!==null&&(n.fontSize=o);let i=qu(t.color),s=qu(t.backgroundColor);return i&&(n.color=i),s&&(n.highlight=s),n}function qu(e){let t=e.trim();if(!t||t==="transparent")return null;let n=/^#([\da-f]{3}|[\da-f]{6})$/i.exec(t);if(n){let o=n[1];return (o.length===3?o.split("").map(i=>i+i).join(""):o).toUpperCase()}let r=/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/i.exec(t);return r?r.slice(1,4).map(o=>Math.max(0,Math.min(255,Number(o))).toString(16).padStart(2,"0")).join("").toUpperCase():null}function wx(e){var r;let t=/^([\d.]+)(pt|px)$/i.exec(e.trim());if(!t)return null;let n=Number(t[1]);return Number.isFinite(n)?((r=t[2])==null?void 0:r.toLowerCase())==="px"?n*.75:n:null}var Ws="http://www.w3.org/XML/1998/namespace",Dn="http://schemas.openxmlformats.org/officeDocument/2006/relationships",$t="http://schemas.openxmlformats.org/package/2006/relationships",Pt="http://schemas.openxmlformats.org/drawingml/2006/main",Jn="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",Yn="http://schemas.openxmlformats.org/drawingml/2006/picture",di="http://schemas.openxmlformats.org/package/2006/content-types",lp="application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",tp="application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml",np="http://schemas.microsoft.com/office/2011/relationships/commentsExtended",nn="http://schemas.microsoft.com/office/word/2012/wordml",rp=`${Dn}/hyperlink`,dp="application/vnd.openxmlformats-package.relationships+xml";function yx(e){let t=[],n=[],r=new Map;for(let o of e)o.kind==="table"&&o.revisionId&&o.revisionAction&&r.set(o.revisionId,o.revisionAction);for(let o of e){if(o.kind==="table"&&o.revisionAction||o.kind==="table"&&o.revisionId&&r.get(o.revisionId)==="reject")continue;let i=vx(o,{allowTrackedTable:o.kind==="table"&&!!o.revisionId&&r.get(o.revisionId)==="accept"});i?t.push(i):n.push({change:o,reason:Ex(o)});}return {target:"word/document.xml",patches:t,unsupported:n}}function fC(e,t,n=wordView.buildIndices(e)){let r=yx(t),o=kx(e,n,r.patches);return v({plan:r},o)}function vx(e,t={}){var n;if(e.kind==="text")return v({kind:"paragraph-text",op:e.op,paraId:e.paraId,offset:e.offset,text:e.text},e.deletedText!==void 0?{deletedText:e.deletedText}:{});if(e.kind==="format"&&e.op==="run"&&e.revisionId&&e.revisionKind==="format")return v({kind:"format-revision",op:"run",paraId:e.paraId,from:e.from,to:e.to,revisionId:e.revisionId},e.beforeFormat!==void 0?{beforeFormat:e.beforeFormat}:{});if(e.kind==="format"&&e.op==="run")return {kind:"paragraph-format",paraId:e.paraId,from:e.from,to:e.to,format:e.format};if(e.kind==="format"&&(e.op==="accept"||e.op==="reject")&&e.revisionId)return {kind:"format-revision",op:e.op,paraId:e.paraId,from:e.from,to:e.to,revisionId:e.revisionId};if(e.kind==="image"&&e.op==="delete")return {kind:"drawing-delete",paraId:e.paraId,drawingId:e.drawingId,offset:e.offset};if(e.kind==="image"&&e.op==="resize"&&e.width&&e.height)return {kind:"drawing-resize",paraId:e.paraId,drawingId:e.drawingId,offset:e.offset,width:e.width,height:e.height};if(e.kind==="image"&&e.op==="insert"&&e.src&&e.width&&e.height)return {kind:"drawing-insert",paraId:e.paraId,drawingId:e.drawingId,offset:e.offset,src:e.src,width:e.width,height:e.height};if(e.kind==="image"&&(e.op==="accept"||e.op==="reject")&&e.revisionId&&(e.revisionKind==="insert"||e.revisionKind==="delete"))return {kind:"drawing-revision",op:e.op,paraId:e.paraId,drawingId:e.drawingId,offset:e.offset,revisionId:e.revisionId,revisionKind:e.revisionKind};if(e.kind==="block"&&e.op==="split"&&e.newParaId&&e.offset!==void 0)return {kind:"paragraph-split",paraId:e.paraId,newParaId:e.newParaId,offset:e.offset};if(e.kind==="block"&&e.op==="merge")return {kind:"paragraph-merge",paraId:e.paraId};if(e.kind==="hyperlink"){if(e.from>=e.to)return null;let r=e.hyperlink;return e.op==="set"&&(!(r!=null&&r.target)||!up(r.target)||r.anchor)?null:v({kind:"hyperlink",op:e.op,paraId:e.paraId,from:e.from,to:e.to},e.op==="set"&&r?{hyperlink:r}:{})}return e.kind==="table"&&(!e.revisionId||t.allowTrackedTable===true)&&e.op!=="insert-table"&&e.op!=="delete-table"&&e.op!=="format-cell"&&e.op!=="clear-cell"&&e.op!=="replace-cell"?v(v({kind:"table-structure",op:e.op,tableId:e.tableId,rowIndex:e.rowIndex,columnIndex:e.columnIndex},e.endColumnIndex!==void 0?{endColumnIndex:e.endColumnIndex}:{}),e.endRowIndex!==void 0?{endRowIndex:e.endRowIndex}:{}):e.kind==="table"&&e.op==="insert-table"&&e.tableSnapshot&&e.anchorParaId?{kind:"table-insert",anchorParaId:e.anchorParaId,anchorOffset:(n=e.anchorOffset)!=null?n:0,table:e.tableSnapshot}:e.kind==="table"&&e.op==="format-cell"&&e.format?{kind:"table-cell-format",tableId:e.tableId,rowIndex:e.rowIndex,columnIndex:e.columnIndex,format:e.format}:e.kind==="table"&&e.op==="clear-cell"?{kind:"table-cell-clear",tableId:e.tableId,rowIndex:e.rowIndex,columnIndex:e.columnIndex}:e.kind==="table"&&e.op==="replace-cell"&&e.text!==void 0?{kind:"table-cell-replace",tableId:e.tableId,rowIndex:e.rowIndex,columnIndex:e.columnIndex,text:e.text}:e.kind==="table"&&e.op==="replace-cell"&&e.cellSnapshot?cp(e.cellSnapshot)?null:{kind:"table-cell-replace-rich",tableId:e.tableId,rowIndex:e.rowIndex,columnIndex:e.columnIndex,cell:e.cellSnapshot}:e.kind==="annotation"&&(e.op==="insert"||e.op==="delete"||e.op==="update")?v(v({kind:"comment",op:e.op,paraId:e.paraId,from:e.from,to:e.to,commentId:e.commentId},e.parentCommentId!==void 0?{parentCommentId:e.parentCommentId}:{}),e.body!==void 0?{body:e.body}:{}):e.kind==="revision"?{kind:"revision",op:e.op,paraId:e.paraId,from:e.from,to:e.to,revisionId:e.revisionId,revisionKind:e.revisionKind}:e.kind==="table"&&e.op==="delete-table"&&t.allowTrackedTable===true?{kind:"table-delete",tableId:e.tableId}:null}function Sx(e,t,n){var i,s;let r=[],o=[];for(let a of n){if(a.kind==="drawing-delete"||a.kind==="drawing-resize"||a.kind==="drawing-revision"){let u=t.drawingIdx.get(a.drawingId);if(!u&&a.kind==="drawing-revision"){let p=t.paraIdx.get(a.paraId.toUpperCase());u=p&&(i=Ux(p,a.offset))!=null?i:void 0;}if(!u){o.push({patch:a,reason:`drawing not found: ${a.drawingId}`});continue}let f=Zn(e,u);if(!f){o.push({patch:a,reason:`drawing part not found: ${a.drawingId}`});continue}r.push({kind:"drawing",patch:a,partPath:f,drawing:u,paragraph:(s=t.paraIdx.get(a.paraId.toUpperCase()))!=null?s:null});continue}if(a.kind==="drawing-insert"){let u=t.paraIdx.get(a.paraId.toUpperCase());if(!u){o.push({patch:a,reason:`paragraph not found: ${a.paraId}`});continue}let f=Zn(e,u);if(!f){o.push({patch:a,reason:`paragraph part not found: ${a.paraId}`});continue}r.push({kind:"drawing",patch:a,partPath:f,drawing:u,paragraph:u});continue}if(a.kind==="comment"){let u=t.paraIdx.get(a.paraId.toUpperCase());if(!u){o.push({patch:a,reason:`paragraph not found: ${a.paraId}`});continue}let f=Zn(e,u);if(!f){o.push({patch:a,reason:`paragraph part not found: ${a.paraId}`});continue}r.push({kind:"comment",patch:a,partPath:f,paragraph:u});continue}if(a.kind==="table-insert"){let u=t.paraIdx.get(a.anchorParaId.toUpperCase());if(!u){o.push({patch:a,reason:`anchor paragraph not found: ${a.anchorParaId}`});continue}let f=Zn(e,u);if(!f){o.push({patch:a,reason:`paragraph part not found: ${a.anchorParaId}`});continue}r.push({kind:"table",patch:a,partPath:f,table:u,paragraph:u});continue}if(a.kind==="table-structure"||a.kind==="table-cell-format"||a.kind==="table-cell-clear"||a.kind==="table-cell-replace"||a.kind==="table-cell-replace-rich"||a.kind==="table-delete"){let u=t.tblIdx.get(a.tableId);if(!u){o.push({patch:a,reason:`table not found: ${a.tableId}`});continue}let f=Zn(e,u);if(!f){o.push({patch:a,reason:`table part not found: ${a.tableId}`});continue}r.push({kind:"table",patch:a,partPath:f,table:u});continue}let l=t.paraIdx.get(a.paraId.toUpperCase());if(!l){o.push({patch:a,reason:`paragraph not found: ${a.paraId}`});continue}let c=Zn(e,l);if(!c){o.push({patch:a,reason:`paragraph part not found: ${a.paraId}`});continue}r.push({kind:"paragraph",patch:a,partPath:c,paragraph:l});}return {resolved:r,unresolved:o}}function kx(e,t,n){var l,c;let r=[],o=[],i=[],s=new Set,a=t;for(let u of n){let f=Sx(e,a,[u]);if(f.unresolved.length>0){i.push(...f.unresolved);continue}let p=f.resolved[0];if(!p)continue;let w=hp(e,p.kind==="paragraph"?p.paragraph:p.kind==="drawing"?p.drawing:p.kind==="table"?p.table:p.paragraph);if(!w){o.push({patch:p.patch,reason:`part not found: ${p.partPath}`});continue}if(p.kind==="drawing"){if(p.patch.kind==="drawing-insert"){let g=ny(e,p.partPath,(l=p.paragraph)!=null?l:p.drawing,p.patch);if(!g.ok){o.push({patch:p.patch,reason:g.reason});continue}pack.markDirty(w),r.push(p.patch),a=wordView.buildIndices(e);continue}if(p.patch.kind==="drawing-revision"){(p.patch.revisionKind==="insert"&&p.patch.op==="reject"||p.patch.revisionKind==="delete"&&p.patch.op==="accept")&&sp(p.drawing),pack.markDirty(w),r.push(p.patch),a=wordView.buildIndices(e);continue}if(p.patch.kind==="drawing-resize"){let g=ty(p.drawing,p.patch.width,p.patch.height);if(!g.ok){o.push({patch:p.patch,reason:g.reason});continue}pack.markDirty(w),r.push(p.patch),a=wordView.buildIndices(e);continue}sp(p.drawing),pack.markDirty(w),r.push(p.patch),a=wordView.buildIndices(e);continue}if(p.kind==="table"){if(p.patch.kind==="table-insert"){let h=Px(p.table.ownerDocument,p.patch.table,e,p.partPath);(c=p.table.parentNode)==null||c.insertBefore(h,p.table.nextSibling),pack.markDirty(w),r.push(p.patch),a=wordView.buildIndices(e);continue}if(p.patch.kind==="table-cell-format"){let h=Mx(p.table,p.patch);if(!h.ok){o.push({patch:p.patch,reason:h.reason});continue}pack.markDirty(w),r.push(p.patch),a=wordView.buildIndices(e);continue}if(p.patch.kind==="table-cell-clear"){let h=Rx(p.table,p.patch);if(!h.ok){o.push({patch:p.patch,reason:h.reason});continue}pack.markDirty(w),r.push(p.patch),a=wordView.buildIndices(e);continue}if(p.patch.kind==="table-cell-replace"){let h=Ax(p.table,p.patch);if(!h.ok){o.push({patch:p.patch,reason:h.reason});continue}pack.markDirty(w),r.push(p.patch),a=wordView.buildIndices(e);continue}if(p.patch.kind==="table-cell-replace-rich"){let h=Lx(e,p.partPath,p.table,p.patch);if(!h.ok){o.push({patch:p.patch,reason:h.reason});continue}pack.markDirty(w),r.push(p.patch),a=wordView.buildIndices(e);continue}if(p.patch.kind==="table-delete"){Ue(p.table),pack.markDirty(w),r.push(p.patch),a=wordView.buildIndices(e);continue}let g=Wx(p.table,p.patch);if(!g.ok){o.push({patch:p.patch,reason:g.reason});continue}pack.markDirty(w),r.push(p.patch),a=wordView.buildIndices(e);continue}if(p.kind==="comment"){let g=uy(e,p.partPath,p.paragraph,p.patch);if(!g.ok){o.push({patch:p.patch,reason:g.reason});continue}pack.markDirty(w),r.push(p.patch),a=wordView.buildIndices(e);continue}if(p.patch.kind==="revision"){let g=oy(p.paragraph,p.patch);if(!g.ok){if((p.patch.op==="accept"||p.patch.op==="reject")&&g.reason===`revision not found: ${p.patch.revisionId}`&&s.has(p.patch.revisionId)){r.push(p.patch);continue}o.push({patch:p.patch,reason:g.reason});continue}pack.markDirty(w),r.push(p.patch),(p.patch.op==="accept"||p.patch.op==="reject")&&s.add(p.patch.revisionId),a=wordView.buildIndices(e);continue}if(p.patch.kind==="paragraph-format"){let g=iy(p.paragraph,p.patch);if(!g.ok){o.push({patch:p.patch,reason:g.reason});continue}pack.markDirty(w),r.push(p.patch),a=wordView.buildIndices(e);continue}if(p.patch.kind==="format-revision"){let g=ay(p.paragraph,p.patch);if(!g.ok){o.push({patch:p.patch,reason:g.reason});continue}pack.markDirty(w),r.push(p.patch),a=wordView.buildIndices(e);continue}if(p.patch.kind==="paragraph-split"){let g=qx(p.paragraph,p.patch.offset,p.patch.newParaId);if(!g.ok){o.push({patch:p.patch,reason:g.reason});continue}pack.markDirty(w),r.push(p.patch),a=wordView.buildIndices(e);continue}if(p.patch.kind==="paragraph-merge"){let g=Xx(p.paragraph);if(!g.ok){o.push({patch:p.patch,reason:g.reason});continue}pack.markDirty(w),r.push(p.patch),a=wordView.buildIndices(e);continue}if(p.patch.kind==="hyperlink"){let g=Cx(e,p.partPath,p.paragraph,p.patch);if(!g.ok){o.push({patch:p.patch,reason:g.reason});continue}pack.markDirty(w),r.push(p.patch),a=wordView.buildIndices(e);continue}let b=Vx(p.paragraph,p.patch);if(!b.ok){o.push({patch:p.patch,reason:b.reason});continue}pack.markDirty(w),r.push(p.patch);}return {applied:r,skipped:o,unresolved:i}}function Ex(e){var t;return e.kind==="block"&&e.op==="split"?"paragraph split change is missing newParaId or offset":e.kind==="hyperlink"?e.op==="set"&&((t=e.hyperlink)!=null&&t.anchor)?"hyperlink anchors are not yet written back":"only external http/https hyperlinks can be written back":e.kind==="image"&&e.op==="resize"?"image resize is missing width or height":e.kind==="image"&&e.op==="insert"?"image insert requires data URL, width, and height":e.kind==="table"?e.op==="replace-cell"&&e.cellSnapshot&&cp(e.cellSnapshot)?"table cell rich replacement does not yet write back drawings or hyperlink anchors":e.revisionId||e.revisionKind?"table revision writeback requires an original table structure snapshot":"table structure change is not supported for DOCX writeback":`unsupported native change: ${e.kind}/${"op"in e?e.op:"unknown"}`}function cp(e){return e.blocks.some(t=>t.kind!=="paragraph"||t.content.some(n=>n.kind==="drawing"||n.kind==="text"&&n.hyperlink!==void 0&&!n.hyperlink.target))}function up(e){try{let t=new URL(e).protocol.toLowerCase();return t==="http:"||t==="https:"}catch(t){return false}}function Cx(e,t,n,r){var f,p,w;let o=oe(n).filter(b=>!(b.namespaceURI===wordView.W_NS&&b.localName==="pPr")),i=o.reduce((b,g)=>b+zt(g),0);if(r.from<0||r.to>i||r.from>=r.to)return {ok:false,reason:`hyperlink range out of range: ${r.from}:${r.to}`};if(o.some(b=>{var g;return b.namespaceURI!==wordView.W_NS||!["r","hyperlink"].includes((g=b.localName)!=null?g:"")}))return {ok:false,reason:"hyperlink patch only supports text runs and existing hyperlinks"};if(o.some(b=>Tx(b)))return {ok:false,reason:"hyperlink patch cannot cross inline objects"};let s=null,a=null;if(r.op==="set"){let b=(f=r.hyperlink)==null?void 0:f.target;if(!b||!up(b))return {ok:false,reason:"only external http/https hyperlinks can be written back"};let g=fp(e,t,b);s=g.id,a=g.part;}let l=[],c=0,u=[];for(let b of o){let g=zt(b),h=Math.max(0,r.from-c),y=Math.min(g,r.to-c);if(!(h<y)){l.push(b),c+=g;continue}if(h>0){let N=Qn(b,0,h);N&&l.push(N);}let C=Qn(b,h,y);if(C&&u.push(...Nx(C)),y<g){let N=Qn(b,y,g);N&&l.push(N);}c+=g;}if(r.op==="set"){let b=n.ownerDocument;if(!b||!s)return {ok:false,reason:"paragraph has no owner document or relationship"};let g=b.createElementNS(wordView.W_NS,"w:hyperlink");g.setAttributeNS(Dn,"r:id",s);let h=(w=(p=r.hyperlink)==null?void 0:p.tooltip)==null?void 0:w.trim();h&&g.setAttributeNS(wordView.W_NS,"w:tooltip",h);for(let y of u)g.appendChild(y);Ix(l,g,r);}else pp(l,u,r);for(let b of o)Ue(b);for(let b of l)n.appendChild(b);return a&&pack.markDirty(a),{ok:true}}function Ix(e,t,n){pp(e,[t],n);}function pp(e,t,n){let r=0,o=false,i=[];for(let s of e)!o&&r>=n.from&&(i.push(...t),o=true),i.push(s),r+=zt(s);o||i.push(...t),e.splice(0,e.length,...i);}function Qn(e,t,n){if(n<=t)return null;let r=e.cloneNode(true);return Rs(r,t,n),zt(r)>0?r:null}function Nx(e){return e.namespaceURI===wordView.W_NS&&e.localName==="hyperlink"?oe(e).filter(t=>t.namespaceURI===wordView.W_NS&&t.localName==="r"):[e]}function Tx(e){return e.getElementsByTagNameNS(wordView.W_NS,"drawing").length>0||e.getElementsByTagNameNS(wordView.W_NS,"pict").length>0}function fp(e,t,n){var u,f,p,w,b;let r=ui(t),o=e.parts.get(r);if(!(o!=null&&o.xmlDom)){let g=(u=Array.from(e.parts.values()).find(y=>y.xmlDom))==null?void 0:u.xmlDom;if(!g)throw new Error("cannot create hyperlink relationships without an XML part");let h=(f=g.implementation)==null?void 0:f.createDocument($t,"Relationships",null);if(!h)throw new Error("XML implementation cannot create relationship document");o=pack.createXmlPart({path:r,contentType:dp,xmlDom:h}),pack.setPart(e,o);}let i=o.xmlDom;if(!i)throw new Error(`relationship part has no XML DOM: ${r}`);let s=i.getElementsByTagNameNS($t,"Relationship");for(let g=0;g<s.length;g+=1){let h=s[g];if((h==null?void 0:h.getAttribute("Type"))===rp&&h.getAttribute("Target")===n)return {id:(p=h.getAttribute("Id"))!=null?p:"",part:o}}let a=new Set;for(let g=0;g<s.length;g+=1){let h=(w=s[g])==null?void 0:w.getAttribute("Id");h&&a.add(h);}let l=1;for(;a.has(`rId${l}`);)l+=1;let c=i.createElementNS($t,"Relationship");return c.setAttribute("Id",`rId${l}`),c.setAttribute("Type",rp),c.setAttribute("Target",n),c.setAttribute("TargetMode","External"),(b=i.documentElement)==null||b.appendChild(c),{id:`rId${l}`,part:o}}function ui(e){let t=e.lastIndexOf("/"),n=t>=0?e.slice(0,t):"",r=e.slice(t+1);return n?`${n}/_rels/${r}.rels`:`_rels/${r}.rels`}function Px(e,t,n,r){var u,f,p,w,b,g;let o=h=>e.createElementNS(wordView.W_NS,`w:${h}`),i=o("tbl"),s=o("tblPr"),a=o("tblW");a.setAttributeNS(wordView.W_NS,"w:w",String(Math.max(0,Math.round((f=(u=t.layout)==null?void 0:u.width)!=null?f:0)))),a.setAttributeNS(wordView.W_NS,"w:type",((p=t.layout)==null?void 0:p.widthType)==="pct"?"pct":"dxa"),s.appendChild(a);let l=o("tblBorders");for(let h of ["top","left","bottom","right","insideH","insideV"]){let y=o(h);y.setAttributeNS(wordView.W_NS,"w:val","single"),y.setAttributeNS(wordView.W_NS,"w:sz","4"),y.setAttributeNS(wordView.W_NS,"w:color",(g=(b=(w=t.borders)==null?void 0:w[h])==null?void 0:b.color)!=null?g:"D9D9D9"),l.appendChild(y);}s.appendChild(l),i.appendChild(s);let c=o("tblGrid");for(let h of t.columnWidths){let y=o("gridCol");y.setAttributeNS(wordView.W_NS,"w:w",String(Math.max(1,Math.round(h)))),c.appendChild(y);}i.appendChild(c);for(let h of t.rows){let y=o("tr");for(let k of h.cells)y.appendChild(mp(e,k,n,r));i.appendChild(y);}return i}function mp(e,t,n,r){var u,f,p,w,b,g;let o=h=>e.createElementNS(wordView.W_NS,`w:${h}`),i=o("tc"),s=o("tcPr"),a=o("tcW");if(a.setAttributeNS(wordView.W_NS,"w:w",String(Math.max(1,Math.round((u=t.width)!=null?u:0)))),a.setAttributeNS(wordView.W_NS,"w:type","dxa"),s.appendChild(a),(f=t.shading)!=null&&f.fill){let h=o("shd");h.setAttributeNS(wordView.W_NS,"w:val",(p=t.shading.val)!=null?p:"clear"),h.setAttributeNS(wordView.W_NS,"w:fill",t.shading.fill.replace(/^#/,"").toUpperCase()),s.appendChild(h);}if(t.verticalAlignment){let h=o("vAlign");h.setAttributeNS(wordView.W_NS,"w:val",t.verticalAlignment),s.appendChild(h);}i.appendChild(s);let l=t.blocks.filter(h=>h.kind==="paragraph"),c=l.length>0?l:[null];for(let h of c){let y=o("p");if(h)for(let k of h.content){if(k.kind==="image"){let L=vp(k.src);if(!L)continue;let F=Sp(n,r,L.bytes,L.extension,L.contentType);y.appendChild(yp(e,F.id,k.drawingId,(w=k.width)!=null?w:96,(b=k.height)!=null?b:96)),pack.markDirty(F.part),pack.markDirty(F.mediaPart),kp(n,L.extension,L.contentType);continue}if(k.kind!=="text")continue;let C=o("r");if(k.format){let L=o("rPr");if(k.format.bold&&L.appendChild(o("b")),k.format.italic&&L.appendChild(o("i")),k.format.underline){let F=o("u");F.setAttributeNS(wordView.W_NS,"w:val","single"),L.appendChild(F);}if(k.format.strike&&L.appendChild(o("strike")),k.format.color){let F=o("color");F.setAttributeNS(wordView.W_NS,"w:val",k.format.color.replace(/^#/,"").toUpperCase()),L.appendChild(F);}if(k.format.fontSize){let F=o("sz");F.setAttributeNS(wordView.W_NS,"w:val",String(Math.round(k.format.fontSize*2))),L.appendChild(F);}if(k.format.fontFamily){let F=o("rFonts");for(let W of ["ascii","hAnsi","eastAsia"])F.setAttributeNS(wordView.W_NS,`w:${W}`,k.format.fontFamily);L.appendChild(F);}L.childNodes.length>0&&C.appendChild(L);}let N=o("t");if(N.textContent=k.text,/^\s|\s$/.test(k.text)&&N.setAttributeNS(Ws,"xml:space","preserve"),C.appendChild(N),(g=k.hyperlink)!=null&&g.target){let L=fp(n,r,k.hyperlink.target),F=e.createElementNS(wordView.W_NS,"w:hyperlink");F.setAttributeNS(Dn,"r:id",L.id),F.appendChild(C),y.appendChild(F),pack.markDirty(L.part);}else y.appendChild(C);}y.firstChild||y.appendChild(o("r")),i.appendChild(y);}return i}function Mx(e,t){let r=oe(e).filter(l=>l.namespaceURI===wordView.W_NS&&l.localName==="tr")[t.rowIndex];if(!r)return {ok:false,reason:`table row out of range: ${t.rowIndex}`};let i=oe(r).filter(l=>l.namespaceURI===wordView.W_NS&&l.localName==="tc")[t.columnIndex];if(!i)return {ok:false,reason:`table column out of range: ${t.columnIndex}`};let s=e.ownerDocument,a=oe(i).find(l=>l.namespaceURI===wordView.W_NS&&l.localName==="tcPr");if(a||(a=s.createElementNS(wordView.W_NS,"w:tcPr"),i.insertBefore(a,i.firstChild)),t.format.backgroundColor!==void 0){let l=oe(a).find(c=>c.namespaceURI===wordView.W_NS&&c.localName==="shd");if(t.format.backgroundColor===null)l&&Ue(l);else {let c=l!=null?l:s.createElementNS(wordView.W_NS,"w:shd");c.setAttributeNS(wordView.W_NS,"w:val","clear"),c.setAttributeNS(wordView.W_NS,"w:fill",t.format.backgroundColor.replace(/^#/,"").toUpperCase()),l||a.appendChild(c);}}if(t.format.verticalAlignment!==void 0){let l=oe(a).find(c=>c.namespaceURI===wordView.W_NS&&c.localName==="vAlign");if(t.format.verticalAlignment===null)l&&Ue(l);else {let c=l!=null?l:s.createElementNS(wordView.W_NS,"w:vAlign");c.setAttributeNS(wordView.W_NS,"w:val",t.format.verticalAlignment),l||a.appendChild(c);}}if(t.format.borderColor!==void 0){let l=oe(a).find(u=>u.namespaceURI===wordView.W_NS&&u.localName==="tcBorders"),c=l!=null?l:s.createElementNS(wordView.W_NS,"w:tcBorders");for(let u of ["top","left","bottom","right","insideH","insideV"]){let f=oe(c).find(p=>p.namespaceURI===wordView.W_NS&&p.localName===u);f||(f=s.createElementNS(wordView.W_NS,`w:${u}`),c.appendChild(f)),f.setAttributeNS(wordView.W_NS,"w:val",t.format.borderColor===null?"nil":"single"),t.format.borderColor!==null&&(f.setAttributeNS(wordView.W_NS,"w:sz","4"),f.setAttributeNS(wordView.W_NS,"w:color",t.format.borderColor.replace(/^#/,"").toUpperCase()));}l||a.appendChild(c);}return {ok:true}}function Rx(e,t){let r=oe(e).filter(a=>a.namespaceURI===wordView.W_NS&&a.localName==="tr")[t.rowIndex];if(!r)return {ok:false,reason:`table row out of range: ${t.rowIndex}`};let i=oe(r).filter(a=>a.namespaceURI===wordView.W_NS&&a.localName==="tc")[t.columnIndex];if(!i)return {ok:false,reason:`table column out of range: ${t.columnIndex}`};let s=oe(i).find(a=>a.namespaceURI===wordView.W_NS&&a.localName==="tcPr");for(let a of oe(i))a!==s&&Ue(a);return i.appendChild(i.ownerDocument.createElementNS(wordView.W_NS,"w:p")),{ok:true}}function Ax(e,t){let r=oe(e).filter(p=>p.namespaceURI===wordView.W_NS&&p.localName==="tr")[t.rowIndex];if(!r)return {ok:false,reason:`table row out of range: ${t.rowIndex}`};let i=oe(r).filter(p=>p.namespaceURI===wordView.W_NS&&p.localName==="tc")[t.columnIndex];if(!i)return {ok:false,reason:`table column out of range: ${t.columnIndex}`};let s=oe(i).find(p=>p.namespaceURI===wordView.W_NS&&p.localName==="tcPr"),a=oe(i).find(p=>p.namespaceURI===wordView.W_NS&&p.localName==="p");for(let p of oe(i))p!==s&&Ue(p);let l=i.ownerDocument.createElementNS(wordView.W_NS,"w:p"),c=a&&oe(a).find(p=>p.namespaceURI===wordView.W_NS&&p.localName==="pPr");c&&l.appendChild(c.cloneNode(true));let u=i.ownerDocument.createElementNS(wordView.W_NS,"w:r"),f=i.ownerDocument.createElementNS(wordView.W_NS,"w:t");return f.textContent=t.text,/^\s|\s$/.test(t.text)&&f.setAttributeNS(Ws,"xml:space","preserve"),u.appendChild(f),l.appendChild(u),i.appendChild(l),{ok:true}}function Lx(e,t,n,r){let i=oe(n).filter(c=>c.namespaceURI===wordView.W_NS&&c.localName==="tr")[r.rowIndex];if(!i)return {ok:false,reason:`table row out of range: ${r.rowIndex}`};let a=oe(i).filter(c=>c.namespaceURI===wordView.W_NS&&c.localName==="tc")[r.columnIndex];if(!a)return {ok:false,reason:`table column out of range: ${r.columnIndex}`};let l=mp(n.ownerDocument,r.cell,e,t);for(let c of oe(a))Ue(c);for(let c of oe(l))a.appendChild(c.cloneNode(true));return {ok:true}}function Wx(e,t){var u,f,p,w;let n=oe(e).filter(b=>b.namespaceURI===wordView.W_NS&&b.localName==="tr");if(n.length===0)return {ok:false,reason:"table has no rows"};if(t.op==="insert-row"||t.op==="delete-row"){if(t.rowIndex<0||t.rowIndex>=n.length+(t.op==="insert-row"?1:0))return {ok:false,reason:`table row out of range: ${t.rowIndex}`};if(t.op==="delete-row")return n.length<=1?{ok:false,reason:"cannot delete the only table row"}:(Ue(n[t.rowIndex]),{ok:true});let b=n[Math.min(t.rowIndex,n.length-1)],g=Dx(b);return e.insertBefore(g,(u=n[t.rowIndex])!=null?u:null),{ok:true}}let r=n[t.rowIndex];if(!r)return {ok:false,reason:`table row out of range: ${t.rowIndex}`};let o=oe(r).filter(b=>b.namespaceURI===wordView.W_NS&&b.localName==="tc");if(t.op==="insert-column"||t.op==="delete-column"){if(o.length===0)return {ok:false,reason:"table row has no cells"};if(t.columnIndex<0||t.columnIndex>=o.length+(t.op==="insert-column"?1:0))return {ok:false,reason:`table column out of range: ${t.columnIndex}`};let b=n.map(g=>oe(g).filter(h=>h.namespaceURI===wordView.W_NS&&h.localName==="tc"));if(b.some(g=>g.length!==o.length||g.some(h=>Wn(h)!==1||li(h))))return {ok:false,reason:"table column structure is not a regular non-merged grid"};for(let g of b)if(t.op==="delete-column"){if(g.length<=1)return {ok:false,reason:"cannot delete the only table column"};Ue(g[t.columnIndex]);}else {let h=g[Math.min(t.columnIndex,g.length-1)],y=Ps(h);(p=g[0].parentNode)==null||p.insertBefore(y,(f=g[t.columnIndex])!=null?f:null);}return zx(e,t.op==="insert-column"?"insert":"delete",t.columnIndex),{ok:true}}if(t.op==="merge-cells"){if(t.endRowIndex!==void 0&&t.endRowIndex>t.rowIndex){if(t.columnIndex<0||t.endRowIndex>=n.length)return {ok:false,reason:`vertical merge row out of range: ${t.rowIndex}:${t.endRowIndex}`};let h=n.slice(t.rowIndex,t.endRowIndex+1).map(y=>oe(y).filter(k=>k.namespaceURI===wordView.W_NS&&k.localName==="tc")[t.columnIndex]);if(h.some(y=>!y||Wn(y)!==1||li(y)))return {ok:false,reason:"vertical merge requires a regular non-merged column"};op(h[0],"restart");for(let y of h.slice(1)){op(y,"continue");let k=oe(y).find(C=>C.namespaceURI===wordView.W_NS&&C.localName==="tcPr");for(let C of oe(y))C!==k&&Ue(C);y.appendChild(y.ownerDocument.createElementNS(wordView.W_NS,"w:p"));}return {ok:true}}let b=(w=t.endColumnIndex)!=null?w:t.columnIndex+1;if(t.columnIndex<0||b>=o.length||b<=t.columnIndex)return {ok:false,reason:`merge start column out of range: ${t.columnIndex}`};if(o.some(h=>Wn(h)!==1||li(h)))return {ok:false,reason:"cell merge requires a regular non-merged row"};let g=o[t.columnIndex];for(let h=t.columnIndex+1;h<=b;h+=1){let y=o[h];Fx(g,y),Ue(y);}return Hx(g,b-t.columnIndex+1),{ok:true}}if(t.endRowIndex!==void 0&&t.endRowIndex>t.rowIndex){if(t.columnIndex<0||t.endRowIndex>=n.length)return {ok:false,reason:`vertical split row out of range: ${t.rowIndex}:${t.endRowIndex}`};let b=n.slice(t.rowIndex,t.endRowIndex+1).map(g=>oe(g).filter(h=>h.namespaceURI===wordView.W_NS&&h.localName==="tc")[t.columnIndex]);if(b.some((g,h)=>{var C;if(!g||Wn(g)!==1)return true;let y=(C=oe(g).find(N=>N.namespaceURI===wordView.W_NS&&N.localName==="tcPr"))==null?void 0:C.getElementsByTagNameNS(wordView.W_NS,"vMerge")[0],k=y==null?void 0:y.getAttributeNS(wordView.W_NS,"val");return h===0?k!=="restart":k!=="continue"}))return {ok:false,reason:"cell is not a vertically merged cell"};for(let g of b)Bx(g);return {ok:true}}let i=n[t.rowIndex],s=oe(i).filter(b=>b.namespaceURI===wordView.W_NS&&b.localName==="tc"),a=0,l=s.find(b=>{let g=a===t.columnIndex;return a+=Wn(b),g});if(!l)return {ok:false,reason:`split column out of range: ${t.columnIndex}`};if(li(l)||Wn(l)<=1)return {ok:false,reason:"cell is not a horizontally merged cell"};let c=Wn(l);Ox(l);for(let b=1;b<c;b+=1){let g=Ps(l);i.insertBefore(g,l.nextSibling);}return {ok:true}}function op(e,t){var i;let n=e.ownerDocument,r=oe(e).find(s=>s.namespaceURI===wordView.W_NS&&s.localName==="tcPr");r||(r=n.createElementNS(wordView.W_NS,"w:tcPr"),e.insertBefore(r,e.firstChild));let o=(i=oe(r).find(s=>s.namespaceURI===wordView.W_NS&&s.localName==="vMerge"))!=null?i:n.createElementNS(wordView.W_NS,"w:vMerge");o.setAttributeNS(wordView.W_NS,"w:val",t),o.parentNode||r.appendChild(o);}function Bx(e){let t=oe(e).find(r=>r.namespaceURI===wordView.W_NS&&r.localName==="tcPr"),n=t&&oe(t).find(r=>r.namespaceURI===wordView.W_NS&&r.localName==="vMerge");n&&Ue(n);}function Dx(e){let t=e.cloneNode(true),n=oe(t).filter(r=>r.namespaceURI===wordView.W_NS&&r.localName==="tc");for(let r of n){let o=Ps(r);xp(r,o);}return t}function Ps(e){let t=e.ownerDocument,n=t.createElementNS(wordView.W_NS,"w:tc"),r=oe(e).find(a=>a.namespaceURI===wordView.W_NS&&a.localName==="tcPr");r&&n.appendChild(r.cloneNode(true));let o=t.createElementNS(wordView.W_NS,"w:p"),i=oe(e).find(a=>a.namespaceURI===wordView.W_NS&&a.localName==="p"),s=i&&oe(i).find(a=>a.namespaceURI===wordView.W_NS&&a.localName==="pPr");return s&&o.appendChild(s.cloneNode(true)),o.appendChild(t.createElementNS(wordView.W_NS,"w:r")),n.appendChild(o),n}function Fx(e,t){for(let n of oe(t))n.namespaceURI===wordView.W_NS&&n.localName==="tcPr"||e.appendChild(n.cloneNode(true));}function Wn(e){var r,o;let t=(o=(r=oe(e).find(i=>i.namespaceURI===wordView.W_NS&&i.localName==="tcPr"))==null?void 0:r.getElementsByTagNameNS(wordView.W_NS,"gridSpan")[0])==null?void 0:o.getAttributeNS(wordView.W_NS,"val"),n=Number(t);return Number.isFinite(n)&&n>0?n:1}function li(e){var t;return !!((t=oe(e).find(n=>n.namespaceURI===wordView.W_NS&&n.localName==="tcPr"))!=null&&t.getElementsByTagNameNS(wordView.W_NS,"vMerge").length)}function Hx(e,t){let n=$x(e,"tcPr"),r=oe(n).find(o=>o.namespaceURI===wordView.W_NS&&o.localName==="gridSpan");r||(r=e.ownerDocument.createElementNS(wordView.W_NS,"w:gridSpan"),n.appendChild(r)),r.setAttributeNS(wordView.W_NS,"w:val",String(t));}function Ox(e){let t=oe(e).find(r=>r.namespaceURI===wordView.W_NS&&r.localName==="tcPr"),n=t&&oe(t).find(r=>r.namespaceURI===wordView.W_NS&&r.localName==="gridSpan");n&&Ue(n);}function $x(e,t){let n=oe(e).find(o=>o.namespaceURI===wordView.W_NS&&o.localName===t);if(n)return n;let r=e.ownerDocument.createElementNS(wordView.W_NS,`w:${t}`);return e.insertBefore(r,e.firstChild),r}function zx(e,t,n){var a;let r=oe(e).find(l=>l.namespaceURI===wordView.W_NS&&l.localName==="tblGrid");if(!r)return;let o=oe(r).filter(l=>l.namespaceURI===wordView.W_NS&&l.localName==="gridCol");if(t==="delete"){o.length>1&&o[n]&&Ue(o[n]);return}let i=o[Math.min(n,o.length-1)];if(!i)return;let s=i.cloneNode(true);r.insertBefore(s,(a=o[n])!=null?a:null);}function Zn(e,t){var n,r;return (r=(n=hp(e,t))==null?void 0:n.path)!=null?r:null}function hp(e,t){let n=t.nodeType===9?t:t.ownerDocument;if(!n)return null;for(let r of e.parts.values())if(r.xmlDom===n)return r;return null}function Vx(e,t){var n,r;return t.op==="insert"?gp(e,t.offset,t.text):t.op==="delete"?ip(e,t.offset,t.text.length,""):ip(e,t.offset,(r=(n=t.deletedText)==null?void 0:n.length)!=null?r:0,t.text)}function gp(e,t,n){var a,l,c;if(n.length===0)return {ok:true};let r=_r(e),o=r.reduce((u,f)=>u+f.length,0);if(Gx(e)&&t===o)return ap(e,n),{ok:true};if(r.every(u=>u.kind!=="text"))return t!==0?{ok:false,reason:`insert offset out of range: ${t}`}:(ap(e,n),{ok:true});let i=Ms(r,t,true);if(!i)return {ok:false,reason:`insert offset out of range: ${t}`};if(i.node.localName==="delText"&&i.localOffset===((l=(a=i.node.textContent)==null?void 0:a.length)!=null?l:0)){let u=jx(i.node,"del"),f=u==null?void 0:u.parentNode;if(u&&f===e){let p=e.ownerDocument;if(!p)return {ok:false,reason:"paragraph has no owner document"};let w=p.createElementNS(wordView.W_NS,"w:r"),b=p.createElementNS(wordView.W_NS,"w:t");return b.textContent=n,bn(b),w.appendChild(b),e.insertBefore(w,u.nextSibling),{ok:true}}}let s=(c=i.node.textContent)!=null?c:"";return i.node.textContent=`${s.slice(0,i.localOffset)}${n}${s.slice(i.localOffset)}`,bn(i.node),{ok:true}}function ip(e,t,n,r){var p,w;if(n===0)return gp(e,t,r);let o=_r(e),i=o.filter(b=>b.kind==="text").map(b=>b.node),s=Ms(o,t,false),a=Ms(o,t+n,true);if(!s||!a)return {ok:false,reason:`text range out of range: ${t}:${n}`};let l=(p=s.node.textContent)!=null?p:"";if(s.node===a.node)return s.node.textContent=`${l.slice(0,s.localOffset)}${r}${l.slice(a.localOffset)}`,bn(s.node),{ok:true};let c=i.indexOf(s.node),u=i.indexOf(a.node);if(c<0||u<0||c>u)return {ok:false,reason:`text range out of range: ${t}:${n}`};let f=(w=a.node.textContent)!=null?w:"";s.node.textContent=`${l.slice(0,s.localOffset)}${r}`,bn(s.node);for(let b=c+1;b<u;b++)i[b].textContent="";return a.node.textContent=f.slice(a.localOffset),bn(a.node),{ok:true}}function _r(e){let t=[];return wp(e,t),t}function Gx(e){return e.getElementsByTagNameNS(wordView.W_NS,"fldChar").length>0||e.getElementsByTagNameNS(wordView.W_NS,"instrText").length>0}function bp(e){return _r(e).filter(t=>t.kind==="text").map(t=>t.node)}function wp(e,t){var r,o,i,s;if(e.nodeType!==1)return;let n=e;if(n.namespaceURI===wordView.W_NS&&n.localName==="t"){t.push({kind:"text",node:n,length:(o=(r=n.textContent)==null?void 0:r.length)!=null?o:0});return}if(n.namespaceURI===wordView.W_NS&&n.localName==="delText"){t.push({kind:"text",node:n,length:(s=(i=n.textContent)==null?void 0:i.length)!=null?s:0});return}if(n.namespaceURI===wordView.W_NS&&n.localName==="drawing"||n.namespaceURI===wordView.W_NS&&n.localName==="pict"){t.push({kind:"object",node:n,length:1});return}for(let a=0;a<n.childNodes.length;a+=1){let l=n.childNodes[a];l&&wp(l,t);}}function jx(e,t){let n=e.parentNode;for(;n&&n.nodeType===1;){let r=n;if(r.namespaceURI===wordView.W_NS&&r.localName===t)return r;if(r.namespaceURI===wordView.W_NS&&r.localName==="p")return null;n=n.parentNode;}return null}function Ux(e,t){let n=0,r=_r(e);for(let o of r){if(o.kind==="object"&&t>=n&&t<=n+o.length)return o.node;n+=o.length;}return null}function Ms(e,t,n){var o;let r=0;for(let i=0;i<e.length;i+=1){let s=e[i],a=r+s.length;if(s.kind==="text"){if(t>=r&&(t<a||n&&t===a))return {node:s.node,localOffset:t-r}}else if(t>=r&&t<=a)return (o=Kx(e,i))!=null?o:_x(e,i);r=a;}return null}function Kx(e,t){for(let n=t+1;n<e.length;n+=1){let r=e[n];if(r.kind==="text")return {node:r.node,localOffset:0}}return null}function _x(e,t){for(let n=t-1;n>=0;n-=1){let r=e[n];if(r.kind==="text")return {node:r.node,localOffset:r.length}}return null}function ap(e,t){let n=e.ownerDocument;if(!n)return;let r=n.createElementNS(wordView.W_NS,"w:r"),o=n.createElementNS(wordView.W_NS,"w:t");o.textContent=t,bn(o),r.appendChild(o),e.appendChild(r);}function bn(e){var n;let t=(n=e.textContent)!=null?n:"";/^\s|\s$|\s{2,}/.test(t)&&e.setAttributeNS(Ws,"xml:space","preserve");}function qx(e,t,n){let r=e.parentNode,o=e.ownerDocument;if(!r||!o)return {ok:false,reason:"paragraph has no parent document"};let i=oe(e).filter(u=>!(u.namespaceURI===wordView.W_NS&&u.localName==="pPr")),s=i.reduce((u,f)=>u+zt(f),0);if(t<0||t>s)return {ok:false,reason:`split offset out of range: ${t}`};let a=Yx(o,i,t),l=o.createElementNS(wordView.W_NS,"w:p");Jx(e,l,n);let c=oe(e).find(u=>u.namespaceURI===wordView.W_NS&&u.localName==="pPr");c&&l.appendChild(c.cloneNode(true));for(let u of a)l.appendChild(u);return r.insertBefore(l,e.nextSibling),{ok:true}}function Xx(e){let t=Qx(e);if(!t)return {ok:false,reason:"next paragraph not found for merge"};for(let n of oe(t))n.namespaceURI===wordView.W_NS&&n.localName==="pPr"||e.appendChild(n.cloneNode(true));return Ue(t),{ok:true}}function Yx(e,t,n){let r=[],o=0,i=false;for(let s of t){let a=zt(s),l=o+a;if(i)r.push(s.cloneNode(true)),Ue(s);else if(n<=o)r.push(s.cloneNode(true)),Ue(s);else if(!(n>=l)){let c=Zx(e,s,n-o);c.after&&r.push(c.after),i=true;}!i&&n===l&&(i=true),o=l;}return r}function Zx(e,t,n){let r=t.cloneNode(true),o=t.cloneNode(true);return Rs(r,0,n),Rs(o,n,zt(t)),xp(t,r),ey(o)||zt(o)>0?{after:o}:{after:null}}function Rs(e,t,n){var i;let r=bp(e),o=0;for(let s of r){let a=(i=s.textContent)!=null?i:"",l=o+a.length,c=Math.max(0,t-o),u=Math.min(a.length,n-o);s.textContent=c<u?a.slice(c,u):"",bn(s),o=l;}}function zt(e){var o,i,s;if(e.namespaceURI===wordView.W_NS&&e.localName==="drawing")return 1;let t=0,n=e.getElementsByTagNameNS(wordView.W_NS,"t");for(let a=0;a<n.length;a++)t+=(s=(i=(o=n[a])==null?void 0:o.textContent)==null?void 0:i.length)!=null?s:0;let r=e.getElementsByTagNameNS(wordView.W_NS,"drawing");return t+=r.length,t}function Jx(e,t,n){for(let r=0;r<e.attributes.length;r++){let o=e.attributes[r];o&&(o.namespaceURI===wordView.W14_NS&&o.localName==="paraId"||t.setAttributeNS(o.namespaceURI,o.name,o.value));}t.setAttributeNS(wordView.W14_NS,"w14:paraId",n);}function oe(e){let t=[];for(let n=0;n<e.childNodes.length;n++){let r=e.childNodes[n];(r==null?void 0:r.nodeType)===1&&t.push(r);}return t}function Qx(e){let t=e.nextSibling;for(;t;){if(t.nodeType===1){let n=t;return n.namespaceURI===wordView.W_NS&&n.localName==="p"?n:null}t=t.nextSibling;}return null}function ey(e){return bp(e).some(t=>{var n;return ((n=t.textContent)!=null?n:"").length>0})}function Ue(e){var t;(t=e.parentNode)==null||t.removeChild(e);}function xp(e,t){var n;(n=e.parentNode)==null||n.replaceChild(t,e);}function sp(e){var n;let t=e.parentNode;if(t){if(ky(t)&&t.namespaceURI===wordView.W_NS&&t.localName==="r"&&Sy(t)){(n=t.parentNode)==null||n.removeChild(t);return}t.removeChild(e);}}function ty(e,t,n){if(!Number.isFinite(t)||!Number.isFinite(n)||t<=0||n<=0)return {ok:false,reason:"image size must be positive finite pixels"};let r=Math.round(t/96*914400),o=Math.round(n/96*914400),i=oe(e).find(l=>l.namespaceURI===Jn&&(l.localName==="inline"||l.localName==="anchor"));if(!i)return {ok:false,reason:"drawing has no wp:inline or wp:anchor container"};let s=oe(i).find(l=>l.namespaceURI===Jn&&l.localName==="extent");if(!s)return {ok:false,reason:"drawing has no wp:extent"};s.setAttribute("cx",String(r)),s.setAttribute("cy",String(o));let a=i.getElementsByTagNameNS(Pt,"xfrm");for(let l=0;l<a.length;l+=1){let c=a[l],u=c&&oe(c).find(f=>f.namespaceURI===Pt&&f.localName==="ext");u&&(u.setAttribute("cx",String(r)),u.setAttribute("cy",String(o)));}return {ok:true}}function ny(e,t,n,r){let o=vp(r.src);if(!o)return {ok:false,reason:"image insert requires a base64 data:image URL"};let i=Sp(e,t,o.bytes,o.extension,o.contentType),s=yp(n.ownerDocument,i.id,r.drawingId,r.width,r.height),a=oe(n).filter(p=>!(p.namespaceURI===wordView.W_NS&&p.localName==="pPr")),l=a.reduce((p,w)=>p+zt(w),0);if(r.offset<0||r.offset>l)return {ok:false,reason:`image insert offset out of range: ${r.offset}`};let c=[],u=0,f=false;for(let p of a){let w=zt(p);if(!f&&r.offset<=u&&(c.push(s),f=true),!f&&r.offset<u+w&&p.namespaceURI===wordView.W_NS&&p.localName==="r"){let b=Qn(p,0,r.offset-u),g=Qn(p,r.offset-u,w);b&&c.push(b),c.push(s),f=true,g&&c.push(g);}else c.push(p);u+=w;}f||c.push(s);for(let p of a)Ue(p);for(let p of c)n.appendChild(p);return pack.markDirty(i.part),pack.markDirty(i.mediaPart),kp(e,o.extension,o.contentType),{ok:true}}function yp(e,t,n,r,o){let i=Math.round(r/96*914400),s=Math.round(o/96*914400),a=e.createElementNS(wordView.W_NS,"w:r"),l=e.createElementNS(wordView.W_NS,"w:drawing"),c=e.createElementNS(Jn,"wp:inline"),u=e.createElementNS(Jn,"wp:extent");u.setAttribute("cx",String(i)),u.setAttribute("cy",String(s)),c.appendChild(u);let f=e.createElementNS(Jn,"wp:docPr");f.setAttribute("id",String(Math.abs(ry(n))+1)),f.setAttribute("name",`Picture ${n}`),c.appendChild(f),c.appendChild(e.createElementNS(Jn,"wp:cNvGraphicFramePr"));let p=e.createElementNS(Pt,"a:graphic"),w=e.createElementNS(Pt,"a:graphicData");w.setAttribute("uri","http://schemas.openxmlformats.org/drawingml/2006/picture");let b=e.createElementNS(Yn,"pic:pic"),g=e.createElementNS(Yn,"pic:nvPicPr"),h=e.createElementNS(Yn,"pic:cNvPr");h.setAttribute("id","0"),h.setAttribute("name",`image-${n}`),g.appendChild(h),g.appendChild(e.createElementNS(Yn,"pic:cNvPicPr")),b.appendChild(g);let y=e.createElementNS(Yn,"pic:blipFill"),k=e.createElementNS(Pt,"a:blip");k.setAttributeNS(Dn,"r:embed",t),y.appendChild(k);let C=e.createElementNS(Pt,"a:stretch");C.appendChild(e.createElementNS(Pt,"a:fillRect")),y.appendChild(C),b.appendChild(y);let N=e.createElementNS(Yn,"pic:spPr"),L=e.createElementNS(Pt,"a:xfrm"),F=e.createElementNS(Pt,"a:ext");F.setAttribute("cx",String(i)),F.setAttribute("cy",String(s)),L.appendChild(e.createElementNS(Pt,"a:off")),L.appendChild(F),N.appendChild(L);let W=e.createElementNS(Pt,"a:prstGeom");return W.setAttribute("prst","rect"),W.appendChild(e.createElementNS(Pt,"a:avLst")),N.appendChild(W),b.appendChild(N),w.appendChild(b),p.appendChild(w),c.appendChild(p),l.appendChild(c),a.appendChild(l),a}function vp(e){let t=/^data:(image\/(png|jpeg|jpg|gif|bmp|webp));base64,([a-z0-9+/=\s]+)$/i.exec(e.trim());if(!t)return null;let n=t[1].toLowerCase()==="image/jpg"?"image/jpeg":t[1].toLowerCase(),r=n==="image/jpeg"?"jpeg":n.slice(6),o=atob(t[3].replace(/\s/g,""));return {bytes:Uint8Array.from(o,i=>i.charCodeAt(0)),extension:r,contentType:n}}function Sp(e,t,n,r,o){var g,h,y,k;let i=ui(t),s=e.parts.get(i);if(!(s!=null&&s.xmlDom)){let C=(g=Array.from(e.parts.values()).find(L=>L.xmlDom))==null?void 0:g.xmlDom;if(!C)throw new Error("cannot create image relationships without an XML part");let N=(h=C.implementation)==null?void 0:h.createDocument($t,"Relationships",null);if(!N)throw new Error("XML implementation cannot create relationship document");s=pack.createXmlPart({path:i,contentType:dp,xmlDom:N}),pack.setPart(e,s);}let a=s.xmlDom;if(!a)throw new Error(`relationship part has no XML DOM: ${i}`);let l=a.getElementsByTagNameNS($t,"Relationship"),c=1,u=new Set;for(let C=0;C<l.length;C+=1){let N=(y=l[C])==null?void 0:y.getAttribute("Id");N&&u.add(N);}for(;u.has(`rId${c}`);)c+=1;let f=1;for(;e.parts.has(`word/media/image${f}.${r}`);)f+=1;let p=`word/media/image${f}.${r}`,w=pack.createBinaryPart({path:p,contentType:o,bytes:n});pack.setPart(e,w);let b=a.createElementNS($t,"Relationship");return b.setAttribute("Id",`rId${c}`),b.setAttribute("Type",`${Dn}/image`),b.setAttribute("Target",`media/image${f}.${r}`),(k=a.documentElement)==null||k.appendChild(b),{id:`rId${c}`,part:s,mediaPart:w}}function kp(e,t,n){var a,l,c;let r=pack.getPart(e,"[Content_Types].xml"),o=r==null?void 0:r.xmlDom;if(!r||!o)return;let i=o.getElementsByTagNameNS("http://schemas.openxmlformats.org/package/2006/content-types","Default");for(let u=0;u<i.length;u+=1)if(((l=(a=i[u])==null?void 0:a.getAttribute("Extension"))==null?void 0:l.toLowerCase())===t.toLowerCase())return;let s=o.createElementNS("http://schemas.openxmlformats.org/package/2006/content-types","Default");s.setAttribute("Extension",t),s.setAttribute("ContentType",n),(c=o.documentElement)==null||c.appendChild(s),pack.markDirty(r);}function ry(e){let t=0;for(let n=0;n<e.length;n+=1)t=t*31+e.charCodeAt(n)|0;return t}function oy(e,t){var l,c,u;if(t.op==="accept"||t.op==="reject"){let f=t.revisionKind==="insert"?"ins":"del",w=Array.from(e.getElementsByTagNameNS(wordView.W_NS,f)).filter(b=>b.getAttributeNS(wordView.W_NS,"id")===t.revisionId);if(w.length===0)return {ok:false,reason:`revision not found: ${t.revisionId}`};for(let b of w){let g=b.parentNode;if(!g)continue;if(!(f==="ins"&&t.op==="accept"||f==="del"&&t.op==="reject")){g.removeChild(b);continue}let y=Array.from(b.childNodes);if(f==="del")for(let k of y)k.nodeType===1&&cy(k);for(let k of y)g.insertBefore(k,b);g.removeChild(b);}return {ok:true}}if(t.from<0||t.to<=t.from)return {ok:false,reason:"revision range is empty or invalid"};let n=0,r=[],o=-1,i=[];for(let f of Array.from(e.childNodes)){if(f.nodeType!==1||f.namespaceURI!==wordView.W_NS){i.push(f);continue}let p=f;if(p.localName==="ins"||p.localName==="del"){i.push(p),n+=(c=(l=p.textContent)==null?void 0:l.length)!=null?c:0;continue}if(p.localName!=="r"){i.push(p);continue}let w=Array.from(p.getElementsByTagNameNS(wordView.W_NS,"t"));if(w.length!==1)return {ok:false,reason:"revision writeback requires runs with one text node"};let b=(u=w[0].textContent)!=null?u:"",g=n,h=n+b.length;if(n=h,h<=t.from||g>=t.to){i.push(p);continue}let y=Math.max(0,t.from-g),k=Math.min(b.length,t.to-g);y>0&&i.push(er(p,b.slice(0,y))),k>y&&(o<0&&(o=i.length),r.push(er(p,b.slice(y,k)))),k<b.length&&i.push(er(p,b.slice(k)));}if(r.length===0||t.to>n)return {ok:false,reason:`revision range out of range: ${t.from}:${t.to}`};let s=e.ownerDocument;if(!s)return {ok:false,reason:"revision paragraph has no owner document"};let a=s.createElementNS(wordView.W_NS,t.revisionKind==="insert"?"w:ins":"w:del");a.setAttributeNS(wordView.W_NS,"w:id",t.revisionId),a.setAttributeNS(wordView.W_NS,"w:author","User"),a.setAttributeNS(wordView.W_NS,"w:date",new Date().toISOString());for(let f of r)t.revisionKind==="delete"&&dy(f),a.appendChild(f);for(i.splice(o<0?i.length:o,0,a),ly(i);e.firstChild;)e.removeChild(e.firstChild);for(let f of i)e.appendChild(f);return {ok:true}}function iy(e,t){var s;if(t.from<0||t.to<=t.from)return {ok:false,reason:"format range is empty or invalid"};if(e.getElementsByTagNameNS(wordView.W_NS,"ins").length>0||e.getElementsByTagNameNS(wordView.W_NS,"del").length>0){let a=Array.from(e.getElementsByTagNameNS(wordView.W_NS,"r")),l=0,c=0;for(let u of a){let f=Ep(u);if(f.length===0)continue;let p=l,w=l+f.length;if(l=w,!(w<=t.from||p>=t.to)){if(t.from>p||t.to<w)return {ok:false,reason:"format writeback requires whole runs inside tracked content"};As(u,t.format),c+=f.length;}}return c===0||t.to>l?{ok:false,reason:`format range out of range: ${t.from}:${t.to}`}:{ok:true}}let r=[],o=0,i=0;for(let a of Array.from(e.childNodes)){if(a.nodeType!==1||a.namespaceURI!==wordView.W_NS||a.localName!=="r"){r.push(a);continue}let l=a,c=Array.from(l.getElementsByTagNameNS(wordView.W_NS,"t"));if(c.length!==1)return {ok:false,reason:"format writeback requires runs with one text node"};let u=(s=c[0].textContent)!=null?s:"",f=o,p=o+u.length;if(o=p,p<=t.from||f>=t.to){r.push(l);continue}let w=Math.max(0,t.from-f),b=Math.min(u.length,t.to-f);if(w>0&&r.push(er(l,u.slice(0,w))),b>w){let g=er(l,u.slice(w,b));As(g,t.format),r.push(g),i+=b-w;}b<u.length&&r.push(er(l,u.slice(b)));}if(i===0||t.to>o)return {ok:false,reason:`format range out of range: ${t.from}:${t.to}`};for(;e.firstChild;)e.removeChild(e.firstChild);for(let a of r)e.appendChild(a);return {ok:true}}function ay(e,t){var o;let n=Array.from(e.getElementsByTagNameNS(wordView.W_NS,"r"));if(t.op==="run"){if(t.beforeFormat===void 0)return {ok:false,reason:"format revision is missing beforeFormat snapshot"};let i=0,s=0;for(let a of n){let l=Ep(a),c=i,u=i+l.length;if(i=u,u<=t.from||c>=t.to)continue;if(t.from>c||t.to<u)return {ok:false,reason:"format revision currently requires whole runs"};let f=sy(a);Bn(f,"rPrChange");let p=f.ownerDocument.createElementNS(wordView.W_NS,"w:rPrChange");p.setAttributeNS(wordView.W_NS,"w:id",t.revisionId),p.setAttributeNS(wordView.W_NS,"w:author","User"),p.setAttributeNS(wordView.W_NS,"w:date",new Date().toISOString());let w=f.ownerDocument.createElementNS(wordView.W_NS,"w:r");As(w,(o=t.beforeFormat)!=null?o:{});let b=oe(w).find(g=>g.namespaceURI===wordView.W_NS&&g.localName==="rPr");if(b)for(let g of Array.from(b.childNodes))p.appendChild(g);f.appendChild(p),s+=l.length;}return s===0||t.to>i?{ok:false,reason:`format revision range not found: ${t.from}:${t.to}`}:{ok:true}}let r=0;for(let i of n){let s=oe(i).find(l=>l.namespaceURI===wordView.W_NS&&l.localName==="rPr"),a=s&&oe(s).find(l=>l.namespaceURI===wordView.W_NS&&l.localName==="rPrChange"&&l.getAttributeNS(wordView.W_NS,"id")===t.revisionId);if(!(!a||!s)){if(t.op==="reject"){for(let l of Array.from(s.childNodes))l!==a&&s.removeChild(l);for(let l of Array.from(a.childNodes))s.appendChild(l.cloneNode(true));}s.removeChild(a),r+=1;}}return r>0?{ok:true}:{ok:false,reason:`format revision not found: ${t.revisionId}`}}function Ep(e){return Array.from(e.getElementsByTagNameNS(wordView.W_NS,"t")).concat(Array.from(e.getElementsByTagNameNS(wordView.W_NS,"delText"))).map(t=>{var n;return (n=t.textContent)!=null?n:""}).join("")}function sy(e){let t=oe(e).find(r=>r.namespaceURI===wordView.W_NS&&r.localName==="rPr");if(t)return t;let n=e.ownerDocument.createElementNS(wordView.W_NS,"w:rPr");return e.insertBefore(n,e.firstChild),n}function As(e,t){var i,s,a;let n=e.ownerDocument,r=(i=oe(e).find(l=>l.namespaceURI===wordView.W_NS&&l.localName==="rPr"))!=null?i:null;r||(r=n.createElementNS(wordView.W_NS,"w:rPr"),e.insertBefore(r,e.firstChild));let o=[["bold","b"],["italic","i"],["strike","strike"],["doubleStrike","dstrike"],["caps","caps"],["smallCaps","smallCaps"]];for(let[l,c]of o)t[l]!==void 0&&(Bn(r,c),t[l]&&r.appendChild(n.createElementNS(wordView.W_NS,`w:${c}`)));if(t.underline!==void 0&&(Bn(r,"u"),t.underline)){let l=n.createElementNS(wordView.W_NS,"w:u");l.setAttribute("val","single"),r.appendChild(l);}if(t.color!==void 0&&(Bn(r,"color"),t.color)){let l=n.createElementNS(wordView.W_NS,"w:color");l.setAttribute("val",t.color.replace(/^#/,"").toUpperCase()),r.appendChild(l);}if(t.highlight!==void 0||t.shading!==void 0){Bn(r,"shd");let l=(a=(s=t.shading)==null?void 0:s.fill)!=null?a:t.highlight;if(l){let c=n.createElementNS(wordView.W_NS,"w:shd");c.setAttribute("val","clear"),c.setAttribute("fill",l.replace(/^#/,"").toUpperCase()),r.appendChild(c);}}if(t.fontSize!==void 0){Bn(r,"sz");let l=n.createElementNS(wordView.W_NS,"w:sz");l.setAttribute("val",String(Math.round(t.fontSize*2))),r.appendChild(l);}if(t.fontFamily!==void 0){Bn(r,"rFonts");let l=n.createElementNS(wordView.W_NS,"w:rFonts");l.setAttribute("ascii",t.fontFamily),l.setAttribute("hAnsi",t.fontFamily),l.setAttribute("eastAsia",t.fontFamily),l.setAttribute("cs",t.fontFamily),r.appendChild(l);}}function Bn(e,t){for(let n of oe(e))n.namespaceURI===wordView.W_NS&&n.localName===t&&e.removeChild(n);}function ly(e){for(let t=1;t<e.length;t+=1){let n=e[t-1],r=e[t];if((n==null?void 0:n.nodeType)!==1||(r==null?void 0:r.nodeType)!==1)continue;let o=n,i=r;if(!(o.namespaceURI!==wordView.W_NS||i.namespaceURI!==wordView.W_NS||o.localName!==i.localName||o.localName!=="ins"&&o.localName!=="del"||o.getAttributeNS(wordView.W_NS,"id")!==i.getAttributeNS(wordView.W_NS,"id"))){for(let s of Array.from(i.childNodes))o.appendChild(s);e.splice(t,1),t-=1;}}}function er(e,t){let n=e.cloneNode(true),r=n.getElementsByTagNameNS(wordView.W_NS,"t")[0];return r&&(r.textContent=t),n}function dy(e){var r;let t=e.ownerDocument,n=Array.from(e.getElementsByTagNameNS(wordView.W_NS,"t"));for(let o of n){let i=t.createElementNS(wordView.W_NS,"w:delText");for(let s=0;s<o.attributes.length;s+=1){let a=o.attributes[s];a&&i.setAttributeNS(a.namespaceURI,a.name,a.value);}i.textContent=o.textContent,(r=o.parentNode)==null||r.replaceChild(i,o);}}function cy(e){var r;let t=e.ownerDocument,n=Array.from(e.getElementsByTagNameNS(wordView.W_NS,"delText"));for(let o of n){let i=t.createElementNS(wordView.W_NS,"w:t");for(let s=0;s<o.attributes.length;s+=1){let a=o.attributes[s];a&&i.setAttributeNS(a.namespaceURI,a.name,a.value);}i.textContent=o.textContent,(r=o.parentNode)==null||r.replaceChild(i,o);}}function uy(e,t,n,r){var s;if(r.op==="insert"){if(r.from<0||r.to<=r.from)return {ok:false,reason:"comment range is empty or invalid"};let a=_r(n).reduce((c,u)=>c+u.length,0);if(r.to>a)return {ok:false,reason:`comment range out of range: ${r.from}:${r.to}`};py(e,t),yy(n,r.from,r.to,r.commentId);let l=new Date().toISOString();return hy(e,r.commentId,(s=r.body)!=null?s:"","User",l),r.parentCommentId!==void 0&&gy(e,r.commentId,r.parentCommentId),{ok:true}}if(r.op==="update"){if(r.body===void 0)return {ok:false,reason:"comment update requires body"};let a=e.parts.get("word/comments.xml"),l=a==null?void 0:a.xmlDom;if(!a||!l)return {ok:false,reason:"comments.xml part not found"};let c=l.getElementsByTagNameNS(wordView.W_NS,"comment");for(let u=0;u<c.length;u+=1){let f=c[u];if((f==null?void 0:f.getAttributeNS(wordView.W_NS,"id"))!==String(r.commentId))continue;let p=f.getElementsByTagNameNS(wordView.W_NS,"t");if(p.length===0){let w=l.createElementNS(wordView.W_NS,"w:p"),b=l.createElementNS(wordView.W_NS,"w:r"),g=l.createElementNS(wordView.W_NS,"w:t");g.textContent=r.body,b.appendChild(g),w.appendChild(b),f.appendChild(w);}else {p[0].textContent=r.body;for(let w=p.length-1;w>=1;w-=1)Ue(p[w]);}return pack.markDirty(a),{ok:true}}return {ok:false,reason:`comment not found: ${r.commentId}`}}vy(e,r.commentId),wy(e,r.commentId);let o=e.parts.get("word/comments.xml"),i=o==null?void 0:o.xmlDom;if(i){let a=i.getElementsByTagNameNS(wordView.W_NS,"comment");for(let l=0;l<a.length;l+=1){let c=a[l];(c==null?void 0:c.getAttributeNS(wordView.W_NS,"id"))===String(r.commentId)&&Ue(c);}pack.markDirty(o);}return {ok:true}}function py(e,t){var r,o;let n=e.parts.get("word/comments.xml");if(!(n!=null&&n.xmlDom)){let i=(r=Array.from(e.parts.values()).find(a=>a.xmlDom))==null?void 0:r.xmlDom;if(!i)throw new Error("cannot create comments.xml without an XML part");let s=(o=i.implementation)==null?void 0:o.createDocument(wordView.W_NS,"w:comments",null);if(!s)throw new Error("XML implementation cannot create comments.xml");n=pack.createXmlPart({path:"word/comments.xml",contentType:lp,xmlDom:s}),pack.setPart(e,n),fy(e);}return my(e,t),n}function fy(e){var i,s;let t=pack.getPart(e,"[Content_Types].xml"),n=t==null?void 0:t.xmlDom;if(!t||!n)return;let r=n.getElementsByTagNameNS(di,"Override");for(let a=0;a<r.length;a+=1)if(((i=r[a])==null?void 0:i.getAttribute("PartName"))==="/word/comments.xml")return;let o=n.createElementNS(di,"Override");o.setAttribute("PartName","/word/comments.xml"),o.setAttribute("ContentType",lp),(s=n.documentElement)==null||s.appendChild(o),pack.markDirty(t);}function my(e,t){var c,u,f;let n=ui(t),r=e.parts.get(n);if(!(r!=null&&r.xmlDom))return;let o=r.xmlDom,i=o.getElementsByTagNameNS($t,"Relationship");for(let p=0;p<i.length;p+=1)if(((c=i[p])==null?void 0:c.getAttribute("Type"))===`${Dn}/comments`)return;let s=new Set;for(let p=0;p<i.length;p+=1){let w=(u=i[p])==null?void 0:u.getAttribute("Id");w&&s.add(w);}let a=1;for(;s.has(`rId${a}`);)a+=1;let l=o.createElementNS($t,"Relationship");l.setAttribute("Id",`rId${a}`),l.setAttribute("Type",`${Dn}/comments`),l.setAttribute("Target","comments.xml"),(f=o.documentElement)==null||f.appendChild(l),pack.markDirty(r);}function hy(e,t,n,r,o){let i=e.parts.get("word/comments.xml"),s=i==null?void 0:i.xmlDom;if(!i||!s)return;let a=s.documentElement;if(!a||Array.from(s.getElementsByTagNameNS(wordView.W_NS,"comment")).some(p=>p.getAttributeNS(wordView.W_NS,"id")===String(t)))return;let l=s.createElementNS(wordView.W_NS,"w:comment");l.setAttributeNS(wordView.W_NS,"w:id",String(t)),l.setAttributeNS(wordView.W_NS,"w:author",r),l.setAttributeNS(wordView.W_NS,"w:date",o),l.setAttributeNS(wordView.W_NS,"w:initials",r.slice(0,1));let c=s.createElementNS(wordView.W_NS,"w:p");c.setAttributeNS(wordView.W14_NS,"w14:paraId",by(t));let u=s.createElementNS(wordView.W_NS,"w:r"),f=s.createElementNS(wordView.W_NS,"w:t");f.textContent=n,bn(f),u.appendChild(f),c.appendChild(u),l.appendChild(c),a.appendChild(l),pack.markDirty(i);}function gy(e,t,n){let r=e.parts.get("word/comments.xml"),o=r==null?void 0:r.xmlDom;if(!o)return;let i=w=>{var g,h,y;let b=o.getElementsByTagNameNS(wordView.W_NS,"comment");for(let k=0;k<b.length;k+=1){if(((g=b[k])==null?void 0:g.getAttributeNS(wordView.W_NS,"id"))!==String(w))continue;let C=(h=b[k])==null?void 0:h.getElementsByTagNameNS(wordView.W_NS,"p")[0];return (y=C==null?void 0:C.getAttributeNS(wordView.W14_NS,"paraId"))!=null?y:null}return null},s=i(t),a=i(n);if(!s||!a)return;let l=xy(e,"word/document.xml"),c=l.xmlDom,u=c==null?void 0:c.documentElement;if(!c||!u||Array.from(u.getElementsByTagNameNS(nn,"commentEx")).some(w=>w.getAttributeNS(nn,"paraId")===s))return;let p=c.createElementNS(nn,"w15:commentEx");p.setAttributeNS(nn,"w15:paraId",s),p.setAttributeNS(nn,"w15:paraIdParent",a),u.appendChild(p),pack.markDirty(l);}function by(e){return e.toString(16).padStart(8,"0").slice(-8)}function wy(e,t){var c,u,f,p;let n=e.parts.get("word/comments.xml"),r=n==null?void 0:n.xmlDom,o=e.parts.get("word/commentsExtended.xml"),i=o==null?void 0:o.xmlDom;if(!r||!i)return;let s=r.getElementsByTagNameNS(wordView.W_NS,"comment"),a=null;for(let w=0;w<s.length;w+=1)if(((c=s[w])==null?void 0:c.getAttributeNS(wordView.W_NS,"id"))===String(t)){a=(p=(f=(u=s[w])==null?void 0:u.getElementsByTagNameNS(wordView.W_NS,"p")[0])==null?void 0:f.getAttributeNS(wordView.W14_NS,"paraId"))!=null?p:null;break}if(!a)return;let l=Array.from(i.getElementsByTagNameNS(nn,"commentEx"));for(let w of l)(w.getAttributeNS(nn,"paraId")===a||w.getAttributeNS(nn,"paraIdParent")===a)&&(Ue(w),pack.markDirty(o));}function xy(e,t){var s,a,l,c,u,f;let n=e.parts.get("word/commentsExtended.xml");if(!(n!=null&&n.xmlDom)){let p=(l=(s=e.parts.get(t))==null?void 0:s.xmlDom)!=null?l:(a=Array.from(e.parts.values()).find(b=>b.xmlDom))==null?void 0:a.xmlDom;if(!p)throw new Error("cannot create commentsExtended.xml without an XML part");let w=(c=p.implementation)==null?void 0:c.createDocument(nn,"w15:commentsEx",null);if(!w)throw new Error("XML implementation cannot create commentsExtended.xml");n=pack.createXmlPart({path:"word/commentsExtended.xml",contentType:tp,xmlDom:w}),pack.setPart(e,n);}let r=pack.getPart(e,"[Content_Types].xml");if(r!=null&&r.xmlDom){let p=r.xmlDom.getElementsByTagNameNS(di,"Override");if(!Array.from(p).some(w=>w.getAttribute("PartName")==="/word/commentsExtended.xml")){let w=r.xmlDom.createElementNS(di,"Override");w.setAttribute("PartName","/word/commentsExtended.xml"),w.setAttribute("ContentType",tp),(u=r.xmlDom.documentElement)==null||u.appendChild(w),pack.markDirty(r);}}let o=e.parts.get(ui(t)),i=o==null?void 0:o.xmlDom;if(i&&!Array.from(i.getElementsByTagNameNS($t,"Relationship")).some(p=>p.getAttribute("Type")===np)){let p=i.getElementsByTagNameNS($t,"Relationship"),w=new Set(Array.from(p).map(h=>h.getAttribute("Id")).filter(Boolean)),b=1;for(;w.has(`rId${b}`);)b+=1;let g=i.createElementNS($t,"Relationship");g.setAttribute("Id",`rId${b}`),g.setAttribute("Type",np),g.setAttribute("Target","commentsExtended.xml"),(f=i.documentElement)==null||f.appendChild(g),pack.markDirty(o);}return n}function yy(e,t,n,r){let o=e.ownerDocument,i=o.createElementNS(wordView.W_NS,"w:commentRangeStart");i.setAttributeNS(wordView.W_NS,"w:id",String(r));let s=o.createElementNS(wordView.W_NS,"w:commentRangeEnd");s.setAttributeNS(wordView.W_NS,"w:id",String(r));let a=o.createElementNS(wordView.W_NS,"w:r"),l=o.createElementNS(wordView.W_NS,"w:commentReference");l.setAttributeNS(wordView.W_NS,"w:id",String(r)),a.appendChild(l);let c=new Map;c.set(t,[i]),c.set(n,[s,a]);let u=oe(e).filter(w=>!(w.namespaceURI===wordView.W_NS&&w.localName==="pPr")),f=[],p=0;for(let w of u){let b=c.get(p);b&&f.push(...b);let g=zt(w),h=[t,n].filter(k=>k>p&&k<p+g).sort((k,C)=>k-C),y=0;for(let k of [...h,p+g]){let C=Qn(w,y,k-p);C&&f.push(C);let N=k,L=c.get(N);L&&f.push(...L),y=k-p;}g===0&&f.push(w),p+=g;}for(let w of [t,n])if(w===p){let b=c.get(w);b&&f.push(...b);}for(let w of u)Ue(w);for(let w of f)e.appendChild(w);}function vy(e,t){for(let n of e.parts.values()){let r=n.xmlDom;if(r)for(let o of ["commentRangeStart","commentRangeEnd","commentReference"]){let i=r.getElementsByTagNameNS(wordView.W_NS,o),s=[];for(let a=0;a<i.length;a+=1){let l=i[a];(l==null?void 0:l.getAttributeNS(wordView.W_NS,"id"))===String(t)&&s.push(l);}for(let a of s){let l=a.parentNode;o==="commentReference"&&(l==null?void 0:l.nodeType)===1&&l.namespaceURI===wordView.W_NS&&l.localName==="r"?Ue(l):Ue(a);}s.length>0&&pack.markDirty(n);}}}function Sy(e){for(let t=0;t<e.childNodes.length;t++){let n=e.childNodes[t];if(!n||n.nodeType!==1)continue;let r=n;if(!(r.namespaceURI===wordView.W_NS&&(r.localName==="rPr"||r.localName==="drawing")))return false}return true}function ky(e){return e.nodeType===1}var Kt=new prosemirrorModel.Schema({nodes:{doc:{content:"block+"},paragraph:{group:"block",content:"inline*",attrs:{paraId:{default:""},story:{default:"body"},styleId:{default:null},format:{default:null}},parseDOM:[{tag:"p"}],toDOM:e=>["p",Cy(e.attrs),0]},table:{group:"block",content:"table_row+",attrs:{tableId:{default:""},columnWidths:{default:null}},tableRole:"table",toDOM:e=>["div",{class:"coco-word-table-scroll"},["table",Iy(e.attrs),["tbody",0]]]},table_row:{content:"table_cell+",tableRole:"row",toDOM:()=>["tr",0]},table_cell:{content:"block+",attrs:{colspan:{default:1},rowspan:{default:1},width:{default:null},shading:{default:null},verticalAlignment:{default:null}},tableRole:"cell",toDOM:e=>["td",Ny(e.attrs),0]},image:{inline:true,group:"inline",atom:true,attrs:{src:{},alt:{default:""},width:{default:null},height:{default:null},drawingId:{default:null}},toDOM:e=>["img",Ty(e.attrs)]},text:{group:"inline"}},marks:{strong:{parseDOM:[{tag:"strong"},{tag:"b"}],toDOM:()=>["strong",0]},em:{parseDOM:[{tag:"em"},{tag:"i"}],toDOM:()=>["em",0]},underline:{parseDOM:[{tag:"u"}],toDOM:()=>["u",0]},textStyle:{attrs:{color:{default:null},fontSize:{default:null}},parseDOM:[{tag:"span"}],toDOM:e=>["span",My(e.attrs),0]}}});new prosemirrorState.PluginKey("coco-word-decorations");var Ip=new prosemirrorState.PluginKey("coco-word-structure-normalization");function Cy(e){let t={};typeof e.paraId=="string"&&e.paraId.length>0&&(t["data-para-id"]=e.paraId),typeof e.story=="string"&&e.story.length>0&&(t["data-story"]=e.story),typeof e.styleId=="string"&&e.styleId.length>0&&(t["data-style-id"]=e.styleId);let n=Ry(e.format)?e.format:null;(n==null?void 0:n.outlineLevel)!==void 0&&(t["data-outline-level"]=String(n.outlineLevel));let r=Ay(n);return r.length>0&&(t.style=r),t}function Iy(e){let t={};return typeof e.tableId=="string"&&e.tableId.length>0&&(t["data-table-id"]=e.tableId),t}function Ny(e){let t={};typeof e.colspan=="number"&&e.colspan>1&&(t.colspan=String(e.colspan)),typeof e.rowspan=="number"&&e.rowspan>1&&(t.rowspan=String(e.rowspan));let n=[];if(typeof e.width=="number"&&e.width>0&&n.push(`width: ${Fn(e.width)}`),Py(e.shading)){let r=Bs(e.shading.fill);r&&n.push(`background-color: ${r}`);}return typeof e.verticalAlignment=="string"&&n.push(`vertical-align: ${e.verticalAlignment==="center"?"middle":e.verticalAlignment}`),n.length>0&&(t.style=n.join("; ")),t}function Ty(e){let t={src:typeof e.src=="string"?e.src:"",alt:typeof e.alt=="string"?e.alt:""};typeof e.drawingId=="string"&&(t["data-drawing-id"]=e.drawingId);let n=[];return typeof e.width=="number"&&e.width>0&&n.push(`width: ${e.width}px`),typeof e.height=="number"&&e.height>0&&n.push(`height: ${e.height}px`),n.length>0&&(t.style=n.join("; ")),t}function Py(e){return e!==null&&typeof e=="object"}function My(e){let t=[],n=typeof e.color=="string"?Bs(e.color):null;return n&&t.push(`color: ${n}`),typeof e.fontSize=="number"&&t.push(`font-size: ${e.fontSize}pt`),t.length>0?{style:t.join("; ")}:{}}function Ry(e){return e!==null&&typeof e=="object"}function Ay(e){var o,i,s,a,l,c,u,f,p;if(!e)return "";let t=[];e.alignment&&t.push(`text-align: ${Ly(e.alignment)}`),((o=e.indent)==null?void 0:o.left)!==void 0&&t.push(`margin-left: ${Fn(e.indent.left)}`),((i=e.indent)==null?void 0:i.right)!==void 0&&t.push(`margin-right: ${Fn(e.indent.right)}`),((s=e.indent)==null?void 0:s.firstLine)!==void 0&&t.push(`text-indent: ${Fn(e.indent.firstLine)}`),((a=e.spacing)==null?void 0:a.before)!==void 0&&t.push(`margin-top: ${Fn(e.spacing.before)}`),((l=e.spacing)==null?void 0:l.after)!==void 0&&t.push(`margin-bottom: ${Fn(e.spacing.after)}`);let n=By((c=e.spacing)==null?void 0:c.line,(u=e.spacing)==null?void 0:u.lineRule);n&&t.push(`line-height: ${n}`),e.fontSize!==void 0&&t.push(`font-size: ${e.fontSize}pt`),e.bold!==void 0&&t.push(`font-weight: ${e.bold?"700":"400"}`);let r=Wy(e.borderBottom);return r&&(t.push(`border-bottom: ${r}`),t.push(`padding-bottom: ${(p=(f=e.borderBottom)==null?void 0:f.space)!=null?p:4}pt`)),t.join("; ")}function Ly(e){return e==="both"||e==="distribute"?"justify":e}function Wy(e){var o;if(!e||e.val==="none"||e.val==="nil")return null;let t=(o=Bs(e.color))!=null?o:"#000000",n=e.size!==void 0?Math.max(.75,e.size/8):.75,r=e.val==="double"?"double":"solid";return `${n}pt ${r} ${t}`}function By(e,t){return e===void 0?null:t==="exact"||t==="atLeast"?Fn(e):String(e/240)}function Fn(e){return `${e/20}pt`}function Bs(e){return !e||e==="auto"?null:/^[0-9a-f]{6}$/i.test(e)?`#${e}`:null}var Xr=new prosemirrorState.PluginKey("coco-word-editing"),Hy=0;function AC(e={}){return new prosemirrorState.Plugin({key:Xr,appendTransaction(t,n,r){if(!t.some(s=>s.docChanged)||t.every(s=>s.getMeta(Ip)))return null;let o=$y(n.doc,r.doc),i=o.length>0?o:jy(n.doc,r.doc);return i.length>0?Ap(r.tr,i):null},state:{init:()=>({changes:[]}),apply(t,n){var i,s;let r=t.getMeta(Xr);if(!((i=r==null?void 0:r.changes)!=null&&i.length))return n;let o={changes:[...n.changes,...r.changes]};return (s=e.onChangeSet)==null||s.call(e,o),o}}})}function LC(e){var t;return (t=Xr.getState(e))!=null?t:{changes:[]}}function WC(e){var a,l;let{from:t,to:n,empty:r}=e.selection,o=e.selection.$from,i=Xy(o,"table_cell"),s=i===null?null:{depth:i,colspan:Number((a=o.node(i).attrs.colspan)!=null?a:1),rowspan:Number((l=o.node(i).attrs.rowspan)!=null?l:1)};return {from:t,to:n,empty:r,selectedText:e.doc.textBetween(t,n,`
19
+ `),paragraphs:Hs(e,t,n),tableCell:s}}function BC(e,t,n){let r=Kt.marks.strong;return Fs(e,t,n,r,{},"strong")}function DC(e){return (t,n,r)=>!Number.isFinite(e)||e<=0?false:Fs(t,n,r,Kt.marks.textStyle,{fontSize:e},"textStyle")}function FC(e){return (t,n,r)=>{let o=qy(e);return o?Fs(t,n,r,Kt.marks.textStyle,{color:o},"textStyle"):false}}function HC(e){return (t,n)=>{let r=Hs(t,t.selection.from,t.selection.to);if(r.length===0)return false;if(!n)return true;let o=t.tr;return t.doc.nodesBetween(t.selection.from,t.selection.to,(i,s)=>{if(i.type!==Kt.nodes.paragraph)return true;let a=_y(i.attrs.format,{alignment:e});return o=o.setNodeMarkup(s,void 0,$(v({},i.attrs),{format:a})),false}),o=Rp(o,{kind:"paragraph",from:t.selection.from,to:t.selection.to,paragraphs:r,target:pi(r),status:"captured",attr:"alignment",value:e}),n(o.scrollIntoView()),true}}function Fs(e,t,n,r,o,i){let{from:s,to:a,empty:l}=e.selection;if(l)return false;let c=Hs(e,s,a);if(c.length===0)return false;let u=i==="strong"&&Oy(e.doc,s,a,r);if(!t)return true;let f=e.tr;return u?f=f.removeMark(s,a,r):f=f.addMark(s,a,r.create(o)),f=Rp(f,{kind:"mark",from:s,to:a,paragraphs:c,target:pi(c),status:"captured",mark:i,value:i==="strong"?!u:o}),t(f.scrollIntoView()),n==null||n.focus(),true}function Hs(e,t,n){let r=[],o=Math.max(n,t+1);return e.doc.nodesBetween(t,o,(i,s)=>{if(i.type!==Kt.nodes.paragraph)return true;let a=s+1,l=a+i.content.size;return r.push({paraId:typeof i.attrs.paraId=="string"?i.attrs.paraId:"",from:Math.max(t,a)-a,to:Math.min(n,l)-a,text:i.textContent,styleId:typeof i.attrs.styleId=="string"?i.attrs.styleId:null,story:typeof i.attrs.story=="string"?i.attrs.story:"body"}),false}),r}function pi(e){var n;let t=e[0];return v({story:(n=t==null?void 0:t.story)!=null?n:"body"},t!=null&&t.paraId?{paraId:t.paraId}:{})}function Oy(e,t,n,r){let o=false;return e.nodesBetween(t,n,i=>(o||!i.isText||(o=r.isInSet(i.marks)!==void 0),!o)),o}function Rp(e,t){return Ap(e,[t])}function Ap(e,t){var o,i;let n=(o=e.getMeta(Xr))!=null?o:{},r=(i=n.changes)!=null?i:[];return e.setMeta(Xr,$(v({},n),{changes:[...r,...t.map(s=>$(v({},s),{id:`word-edit:${++Hy}`,createdAt:Date.now()}))]}))}function $y(e,t){let n=Tp(e),r=Tp(t),o=zy(n,r);if(o)return [o];let i=Vy(n,r);if(i)return [i];let s=Gy(n,r);return s?[s]:[]}function zy(e,t){if(t.length!==e.length+1)return null;for(let n=0;n<e.length;n+=1){if(!fi(e.slice(0,n),t.slice(0,n))||!fi(e.slice(n+1),t.slice(n+2)))continue;let r=e[n],o=t[n],i=t[n+1];if(!(r.block.kind!=="paragraph"||o.block.kind!=="paragraph"||i.block.kind!=="paragraph"||o.block.text+i.block.text!==r.block.text))return {kind:"block",blockOp:"split",from:r.pos,to:r.pos+r.size,paragraphs:Os([o,i]),target:$s(r.block),status:"captured",blocks:[o.block,i.block],deletedBlocks:[r.block],value:{before:r.block,after:[o.block,i.block]}}}return null}function Vy(e,t){if(e.length!==t.length+1)return null;for(let n=0;n<t.length;n+=1){if(!fi(e.slice(0,n),t.slice(0,n))||!fi(e.slice(n+2),t.slice(n+1)))continue;let r=e[n],o=e[n+1],i=t[n];if(!(r.block.kind!=="paragraph"||o.block.kind!=="paragraph"||i.block.kind!=="paragraph"||r.block.text+o.block.text!==i.block.text))return {kind:"block",blockOp:"merge",from:r.pos,to:o.pos+o.size,paragraphs:Os([i]),target:$s(i.block),status:"captured",blocks:[i.block],deletedBlocks:[r.block,o.block],value:{before:[r.block,o.block],after:i.block}}}return null}function Gy(e,t){var f,p,w,b,g;let n=0,r=Math.min(e.length,t.length);for(;n<r&&Ds(e[n],t[n]);)n+=1;let o=0,i=Math.min(e.length-n,t.length-n);for(;o<i&&Ds(e[e.length-1-o],t[t.length-1-o]);)o+=1;let s=e.slice(n,e.length-o),a=t.slice(n,t.length-o);if(s.length===0&&a.length===0)return null;let l=(f=a[0])!=null?f:s[0],c=(w=(p=a[a.length-1])!=null?p:s[s.length-1])!=null?w:l;return {kind:"block",blockOp:a.length>0&&s.length>0?"replace":a.length>0?"insert":"delete",from:(b=l==null?void 0:l.pos)!=null?b:0,to:c?c.pos+c.size:(g=l==null?void 0:l.pos)!=null?g:0,paragraphs:Os(a.length>0?a:s),target:l?$s(l.block):{story:"body"},status:"captured",blocks:a.map(h=>h.block),deletedBlocks:s.map(h=>h.block),value:{before:s.map(h=>h.block),after:a.map(h=>h.block)}}}function jy(e,t){let n=Np(e),r=Np(t),o=new Map(n.map(s=>[s.paraId,s])),i=[];for(let s of r){if(!s.paraId)continue;let a=o.get(s.paraId);if(!a||Wp(a.content,s.content))continue;let l=Ky(a.content,s.content);if(!l)continue;let c=s.pos+1+l.from,u=s.pos+1+l.toAfter,f={paraId:s.paraId,from:l.from,to:l.toAfter,text:s.text,styleId:s.styleId,story:s.story};if(Pp(l.insertedContent)&&Pp(l.deletedContent)){i.push({kind:"text",from:c,to:u,paragraphs:[f],target:pi([f]),status:"captured",textOp:l.operation,text:Mp(l.insertedContent),deletedText:Mp(l.deletedContent),value:{operation:l.operation,before:a.text,after:s.text}});continue}i.push({kind:"content",from:c,to:u,paragraphs:[f],target:pi([f]),status:"captured",contentOp:l.operation,content:qr(l.insertedContent),deletedContent:qr(l.deletedContent),value:{operation:l.operation,before:qr(a.content.map(p=>p.content)),after:qr(s.content.map(p=>p.content))}});}return i}function Np(e){let t=[];return e.descendants((n,r)=>n.type!==Kt.nodes.paragraph?true:(t.push({paraId:typeof n.attrs.paraId=="string"?n.attrs.paraId:"",pos:r,text:n.textContent,content:Lp(n),styleId:typeof n.attrs.styleId=="string"?n.attrs.styleId:null,story:typeof n.attrs.story=="string"?n.attrs.story:"body"}),false)),t}function Tp(e){let t=[];return e.forEach((n,r,o)=>{if(n.type===Kt.nodes.paragraph){let i=typeof n.attrs.paraId=="string"?n.attrs.paraId:"",s=typeof n.attrs.story=="string"?n.attrs.story:"body",a={kind:"paragraph",paraId:i,story:s,styleId:typeof n.attrs.styleId=="string"?n.attrs.styleId:null,text:n.textContent,content:qr(Lp(n).map(l=>l.content))};t.push({key:`paragraph:${i||o}`,pos:r,size:n.nodeSize,block:a});return}if(n.type===Kt.nodes.table){let i=typeof n.attrs.tableId=="string"?n.attrs.tableId:"",s={kind:"table",tableId:i,text:n.textContent};t.push({key:`table:${i||o}`,pos:r,size:n.nodeSize,block:s});}}),t}function fi(e,t){return e.length===t.length&&e.every((n,r)=>Ds(n,t[r]))}function Ds(e,t){return e.key===t.key}function Os(e){return e.flatMap(t=>t.block.kind!=="paragraph"?[]:[{paraId:t.block.paraId,from:0,to:t.block.text.length,text:t.block.text,styleId:t.block.styleId,story:t.block.story}])}function $s(e){return e.kind==="table"?v({story:"body"},e.tableId?{tableId:e.tableId}:{}):v({story:e.story},e.paraId?{paraId:e.paraId}:{})}function Lp(e){let t=[];return e.forEach(n=>{var r,o;if(n.isText){for(let i of (r=n.text)!=null?r:"")t.push({key:`text:${i}`,content:{kind:"text",text:i}});return}if(n.type===Kt.nodes.image){let i=Uy(n);t.push({key:`image:${(o=i.drawingId)!=null?o:i.src}`,content:i});return}t.push({key:`${n.type.name}:${JSON.stringify(n.attrs)}`,content:{kind:"text",text:n.textContent}});}),t}function Uy(e){return {kind:"image",drawingId:typeof e.attrs.drawingId=="string"?e.attrs.drawingId:null,alt:typeof e.attrs.alt=="string"?e.attrs.alt:"",src:typeof e.attrs.src=="string"?e.attrs.src:"",width:typeof e.attrs.width=="number"?e.attrs.width:null,height:typeof e.attrs.height=="number"?e.attrs.height:null}}function Ky(e,t){var f,p,w,b;if(Wp(e,t))return null;let n=0,r=Math.min(e.length,t.length);for(;n<r&&((f=e[n])==null?void 0:f.key)===((p=t[n])==null?void 0:p.key);)n+=1;let o=0,i=Math.min(e.length-n,t.length-n);for(;o<i&&((w=e[e.length-1-o])==null?void 0:w.key)===((b=t[t.length-1-o])==null?void 0:b.key);)o+=1;let s=e.length-o,a=t.length-o,l=t.slice(n,a).map(g=>g.content),c=e.slice(n,s).map(g=>g.content);return {operation:l.length>0&&c.length>0?"replace":l.length>0?"insert":"delete",from:n,toBefore:s,toAfter:a,insertedContent:l,deletedContent:c}}function Wp(e,t){return e.length===t.length&&e.every((n,r)=>{var o;return n.key===((o=t[r])==null?void 0:o.key)})}function Pp(e){return e.every(t=>t.kind==="text")}function Mp(e){return e.map(t=>t.kind==="text"?t.text:"").join("")}function qr(e){let t=[];for(let n of e){let r=t[t.length-1];n.kind==="text"&&(r==null?void 0:r.kind)==="text"?r.text+=n.text:t.push(v({},n));}return t}function _y(e,t){return v(v({},e!==null&&typeof e=="object"?e:{}),t)}function qy(e){let t=e.trim().replace(/^#/,"");return /^[0-9a-f]{6}$/i.test(t)?t.toUpperCase():null}function Xy(e,t){for(let n=e.depth;n>0;n-=1)if(e.node(n).type.name===t)return n;return null}var Bp=`.coco-word-editor {
13
20
  background: #f4f5f7;
14
21
  color: #202124;
15
22
  font-family:
@@ -1517,32 +1524,32 @@ coco-word-native-table.coco-word-revision-delete {
1517
1524
  .coco-word-dialog-button:hover {
1518
1525
  filter: brightness(0.96);
1519
1526
  }
1520
- `;function Bp(e,t){var s,a,l,c,u,f,p,w,b;let n=$y(e,t),r=Hp(e,t),o=Fp(e,t),i=_r(e,t);return {selectionKind:(s=t==null?void 0:t.kind)!=null?s:null,trackRevisions:false,bold:(a=Xe(n.map(g=>{var h;return (h=g.bold)!=null?h:false}),false))!=null?a:false,italic:(l=Xe(n.map(g=>{var h;return (h=g.italic)!=null?h:false}),false))!=null?l:false,underline:(c=Xe(n.map(g=>{var h;return (h=g.underline)!=null?h:false}),false))!=null?c:false,strike:(u=Xe(n.map(g=>{var h;return (h=g.strike)!=null?h:false}),false))!=null?u:false,fontFamily:Xe(n.map(g=>{var h;return (h=g.fontFamily)!=null?h:null}),null),fontSize:Xe(n.map(g=>{var h;return (h=g.fontSize)!=null?h:null}),null),textColor:Xe(n.map(g=>qr(g.color)),null),highlightColor:Xe(n.map(g=>jy(g.highlight)),null),hyperlink:Dp(e,t),paragraphAlignment:Xe(r.map(g=>{var h;return Wp((h=g.format)==null?void 0:h.alignment)}),null),leftIndent:Xe(r.map(g=>{var h,y,k;return (k=(y=(h=g.format)==null?void 0:h.indent)==null?void 0:y.left)!=null?k:0}),0),rightIndent:Xe(r.map(g=>{var h,y,k;return (k=(y=(h=g.format)==null?void 0:h.indent)==null?void 0:y.right)!=null?k:0}),0),firstLineIndent:Xe(r.map(g=>{var h,y,k;return (k=(y=(h=g.format)==null?void 0:h.indent)==null?void 0:y.firstLine)!=null?k:0}),0),spacingBefore:Xe(r.map(g=>{var h,y,k;return (k=(y=(h=g.format)==null?void 0:h.spacing)==null?void 0:y.before)!=null?k:0}),0),spacingAfter:Xe(r.map(g=>{var h,y,k;return (k=(y=(h=g.format)==null?void 0:h.spacing)==null?void 0:y.after)!=null?k:0}),0),lineSpacing:Op(r.map(g=>{var y,k,C,N,L;let h=(k=(y=g.format)==null?void 0:y.spacing)==null?void 0:k.line;return h===void 0?null:{line:h,lineRule:(L=(N=(C=g.format)==null?void 0:C.spacing)==null?void 0:N.lineRule)!=null?L:"auto"}})),listType:Xe(r.map(g=>{var h;return (h=g.format)!=null&&h.hasNumbering?dn(g.format.numbering):null}),null),listLevel:Xe(r.map(g=>{var h,y,k;return (h=g.format)!=null&&h.hasNumbering?(k=(y=g.format.numbering)==null?void 0:y.ilvl)!=null?k:0:null}),null),image:o&&(t==null?void 0:t.kind)==="object"?{objectId:o.drawingId,width:(f=o.width)!=null?f:null,height:(p=o.height)!=null?p:null,alignment:Wp((b=(w=r[0])==null?void 0:w.format)==null?void 0:b.alignment)}:null,table:i}}function Mt(e,t,n){var r,o,i,s,a,l;if(n.kind==="toggle-track-revisions"||n.kind==="accept-revision"||n.kind==="reject-revision"||n.kind==="accept-all-revisions"||n.kind==="reject-all-revisions")return true;if(!t)return false;if(n.kind==="insert-image")return (t.kind==="caret"||t.kind==="text-range")&&n.src.trim().length>0;if(n.kind==="insert-table")return t.kind!=="caret"||!Number.isInteger(n.rows)||!Number.isInteger(n.columns)||n.rows<1||n.rows>20||n.columns<1||n.columns>20?false:((r=be(e,t.paraId))==null?void 0:r.container)===e.blocks;if(n.kind==="delete-table"){let c=_r(e,t);return !!c&&((o=Oe(e,c.tableId))==null?void 0:o.container)===e.blocks}if(n.kind==="set-image-size"||n.kind==="set-image-alignment")return t.kind==="object"&&t.objectKind==="image"&&t.objectId===n.objectId&&!!Fp(e,t);if(n.kind==="insert-table-row"||n.kind==="delete-table-row"||n.kind==="insert-table-column"||n.kind==="delete-table-column"){let c=_r(e,t);return c!=null&&c.structuralEditingSupported?n.kind==="delete-table-row"?c.rowCount>1:n.kind==="delete-table-column"?c.columnCount>1:true:false}if(n.kind==="set-table-cell-background"||n.kind==="set-table-cell-vertical-alignment"||n.kind==="set-table-cell-borders")return _r(e,t)!==null;if(n.kind==="merge-table-cells"||n.kind==="split-table-cell"){if(t.kind!=="table-cell-range")return false;let c=Oe(e,t.tableId);if(!c)return false;let u=at(c.table,t);if(n.kind==="merge-table-cells")return Ir(c.table)?t.anchor.rowIndex===t.focus.rowIndex&&u.length>=2&&u.every(w=>w.cell.gridSpan===1&&w.cell.vMerge==null):false;let f=u.length===1?u[0].cell:null;return !!f&&(f.gridSpan>1&&f.vMerge==null&&((i=f.rowSpan)!=null?i:1)===1||f.vMerge==="restart"&&((s=f.rowSpan)!=null?s:1)>1)}return n.kind==="clear-table-cells"?t.kind==="table-cell-range"&&_r(e,t)!==null:n.kind==="set-hyperlink"?t.kind==="text-range"&&!!((a=n.hyperlink.target)!=null&&a.trim()||(l=n.hyperlink.anchor)!=null&&l.trim()):n.kind==="remove-hyperlink"?t.kind==="text-range"&&Dp(e,t)!==null:n.kind==="insert-text"||n.kind==="split-paragraph"||n.kind==="insert-page-break"?t.kind==="caret"&&!!_(e,t.paraId):n.kind==="delete-object"?t.kind==="object"&&t.objectKind===n.objectKind:n.kind==="replace-range"||n.kind==="delete-range"?n.anchor.paraId===n.focus.paraId&&!!_(e,n.anchor.paraId):n.kind==="toggle-bold"||n.kind==="toggle-italic"||n.kind==="toggle-underline"||n.kind==="toggle-strike"||n.kind==="set-font-family"||n.kind==="set-font-size"||n.kind==="set-text-color"||n.kind==="set-highlight-color"||n.kind==="clear-text-format"?t.kind==="text-range"&&ui(e,t).some(c=>c.to>c.from):n.kind==="set-paragraph-alignment"||n.kind==="set-paragraph-indent"||n.kind==="adjust-paragraph-left-indent"||n.kind==="set-paragraph-spacing"||n.kind==="set-paragraph-line-spacing"||n.kind==="toggle-list"||n.kind==="remove-list"||n.kind==="adjust-list-level"?Hp(e,t).length>0:n.kind==="delete-backward"?t.kind==="caret"||t.kind==="object"||t.kind==="table-cell-range":n.kind==="delete-forward"&&(t.kind==="caret"||t.kind==="table-cell-range")}function _r(e,t){var o,i,s,a;if(!t)return null;if(t.kind==="table-cell-range"){let l=Oe(e,t.tableId);if(!l)return null;let c=at(l.table,t);if(c.length===0)return null;let u=Math.min(t.anchor.rowIndex,t.focus.rowIndex),f=Math.max(t.anchor.rowIndex,t.focus.rowIndex),p=Math.min(t.anchor.columnIndex,t.focus.columnIndex),w=Math.max(t.anchor.columnIndex,t.focus.columnIndex);return {tableId:l.table.tableId,rowIndex:t.anchor.rowIndex,rowCount:l.table.rows.length,columnIndex:t.anchor.columnIndex,columnCount:Math.max(0,...l.table.rows.map(b=>b.cells.reduce((g,h)=>g+Math.max(1,h.gridSpan),0))),range:{startRow:u,endRow:f,startColumn:p,endColumn:w,cellCount:c.length},structuralEditingSupported:Ir(l.table),backgroundColor:Xe(c.map(({cell:b})=>{var g;return qr((g=b.shading)==null?void 0:g.fill)}),null),verticalAlignment:Xe(c.map(({cell:b})=>{var g;return (g=b.verticalAlignment)!=null?g:null}),null),borderColor:Xe(c.map(({cell:b})=>Ap(b.borders)),null),bordersVisible:Xe(c.map(({cell:b})=>Lp(b.borders)),false)}}let n=t.kind==="text-range"?t.anchor.paraId:t.paraId,r=Jt(e,n);return r?{tableId:r.table.tableId,rowIndex:r.rowIndex,rowCount:r.table.rows.length,columnIndex:r.columnIndex,columnCount:(i=(o=r.table.rows[0])==null?void 0:o.cells.length)!=null?i:0,range:null,structuralEditingSupported:Ir(r.table),backgroundColor:qr((s=r.cell.shading)==null?void 0:s.fill),verticalAlignment:(a=r.cell.verticalAlignment)!=null?a:null,borderColor:Ap(r.cell.borders),bordersVisible:Lp(r.cell.borders)}:null}function Ap(e){let t=[e==null?void 0:e.top,e==null?void 0:e.right,e==null?void 0:e.bottom,e==null?void 0:e.left].find(n=>n&&n.val!=="nil"&&n.val!=="none");return qr(t==null?void 0:t.color)}function Lp(e){return [e==null?void 0:e.top,e==null?void 0:e.right,e==null?void 0:e.bottom,e==null?void 0:e.left].some(t=>!!t&&t.val!=="nil"&&t.val!=="none")}function Fp(e,t){var r;if((t==null?void 0:t.kind)!=="object"||t.objectKind!=="image")return null;let n=_(e,t.paraId);return (r=n==null?void 0:n.content.find(o=>o.kind==="image"&&o.drawingId===t.objectId))!=null?r:null}function $y(e,t){if(!t||t.kind==="object"||t.kind==="table-cell-range")return [];if(t.kind==="caret"){let n=_(e,t.paraId);if(!n)return [];let r=Vy(e,n,t.offset);return r?[r]:[]}return ui(e,t).flatMap(n=>zy(e,n))}function Dp(e,t){var r,o,i,s,a;if(!t||t.kind==="object"||t.kind==="table-cell-range")return null;if(t.kind==="caret"){let l=_(e,t.paraId);if(!l)return null;let c=0,u=null;for(let f of l.content){let p=ci(f);if(f.kind==="text"){if(t.offset>c&&t.offset<=c+p)return (r=f.hyperlink)!=null?r:null;if(t.offset===c)return (u==null?void 0:u.kind)==="text"?(i=(o=u.hyperlink)!=null?o:f.hyperlink)!=null?i:null:(s=f.hyperlink)!=null?s:null;u=f;}c+=p;}return (u==null?void 0:u.kind)==="text"&&(a=u.hyperlink)!=null?a:null}let n=ui(e,t).flatMap(l=>{var p;let c=_(e,l.paraId);if(!c)return [];let u=[],f=0;for(let w of c.content){let b=ci(w);w.kind==="text"&&f+b>l.from&&f<l.to&&u.push((p=w.hyperlink)!=null?p:null),f+=b;}return u});return Op(n)}function zy(e,t){let n=_(e,t.paraId);if(!n)return [];let r=[],o=0;for(let i of n.content){let s=ci(i);i.kind==="text"&&o+s>t.from&&o<t.to&&r.push(Ds(e,n,i.format)),o+=s;}return r}function Vy(e,t,n){let r=0,o=null;for(let i of t.content){let s=ci(i);if(i.kind==="text"){let a=Ds(e,t,i.format);if(n>r&&n<=r+s)return a;if(n===r)return o!=null?o:a;o=a;}r+=s;}return o!=null?o:Ds(e,t,null)}function Ds(e,t,n){var o,i;let r=t.format;return v(v(v({},(i=(o=e.defaults)==null?void 0:o.run)!=null?i:{}),r!=null?r:{}),n!=null?n:{})}function Hp(e,t){if(!t)return [];if(t.kind==="table-cell-range")return [];if(t.kind==="caret"||t.kind==="object"){let n=_(e,t.paraId);return n?[n]:[]}return ui(e,t).map(n=>_(e,n.paraId)).filter(n=>n!==null)}function ui(e,t){let n=Gy(e,t);if(!n)return [];if(n.anchor.paraId===n.focus.paraId)return [{paraId:n.anchor.paraId,from:n.anchor.offset,to:n.focus.offset}];let r=be(e,n.anchor.paraId),o=be(e,n.focus.paraId);if(!r||!o||r.container!==o.container)return [];let i=[];for(let s=r.index;s<=o.index;s+=1){let a=r.container[s];if((a==null?void 0:a.kind)!=="paragraph")return [];i.push({paraId:a.paraId,from:s===r.index?n.anchor.offset:0,to:s===o.index?n.focus.offset:Te(a).length});}return i}function Gy(e,t){if(t.anchor.paraId===t.focus.paraId)return t.anchor.offset<=t.focus.offset?{anchor:t.anchor,focus:t.focus}:{anchor:t.focus,focus:t.anchor};let n=be(e,t.anchor.paraId),r=be(e,t.focus.paraId);return !n||!r||n.container!==r.container?null:n.index<r.index?{anchor:t.anchor,focus:t.focus}:{anchor:t.focus,focus:t.anchor}}function ci(e){var t;return e.kind==="text"?e.text.length:e.kind==="field"?((t=e.cachedText)!=null?t:"\uFFFC").length:e.kind==="drawing"&&e.text?e.text.length:1}function Xe(e,t){return e.length===0?t:e.every(n=>n===e[0])?e[0]:"mixed"}function Op(e){var n;if(e.length===0||e.every(r=>r===null))return null;let t=JSON.stringify(e[0]);return e.every(r=>JSON.stringify(r)===t)?(n=e[0])!=null?n:null:"mixed"}function qr(e){if(!e||e.toLowerCase()==="auto")return null;let t=e.replace(/^#/,"").toUpperCase();return /^[0-9A-F]{6}$/.test(t)?`#${t}`:e}function jy(e){var t;return !e||e.toLowerCase()==="none"?null:(t=qr(e))!=null?t:e}function Wp(e){return e==="center"||e==="right"||e==="both"?e:e==="distribute"?"both":"left"}function $p(e,t,n){let r=0;for(;r<e.length&&r<t.length&&e[r]===t[r];)r+=1;return {revision:n,changes:t.slice(r),revertedChanges:e.slice(r),totalChangeCount:t.length}}var Xr=new WeakMap,Hs="application/x-coco-word-table-cells+json",Yr="application/x-coco-word-image",Up="coco-image:",Zr=new Map,Os=0,Uy=0,$s=0,zs=0;function KC(e,t,n={}){var id,ad,sd;ou();let r=e,o=null;if(n.styleIsolation!=="none"){r.replaceChildren(),o=(id=r.shadowRoot)!=null?id:r.attachShadow({mode:"open"}),o.replaceChildren();let d=r.ownerDocument.createElement("style");d.textContent=`
1527
+ `;function Op(e,t){var s,a,l,c,u,f,p,w,b;let n=Yy(e,t),r=Vp(e,t),o=$p(e,t),i=Yr(e,t);return {selectionKind:(s=t==null?void 0:t.kind)!=null?s:null,trackRevisions:false,bold:(a=Xe(n.map(g=>{var h;return (h=g.bold)!=null?h:false}),false))!=null?a:false,italic:(l=Xe(n.map(g=>{var h;return (h=g.italic)!=null?h:false}),false))!=null?l:false,underline:(c=Xe(n.map(g=>{var h;return (h=g.underline)!=null?h:false}),false))!=null?c:false,strike:(u=Xe(n.map(g=>{var h;return (h=g.strike)!=null?h:false}),false))!=null?u:false,fontFamily:Xe(n.map(g=>{var h;return (h=g.fontFamily)!=null?h:null}),null),fontSize:Xe(n.map(g=>{var h;return (h=g.fontSize)!=null?h:null}),null),textColor:Xe(n.map(g=>Zr(g.color)),null),highlightColor:Xe(n.map(g=>ev(g.highlight)),null),hyperlink:zp(e,t),paragraphAlignment:Xe(r.map(g=>{var h;return Hp((h=g.format)==null?void 0:h.alignment)}),null),leftIndent:Xe(r.map(g=>{var h,y,k;return (k=(y=(h=g.format)==null?void 0:h.indent)==null?void 0:y.left)!=null?k:0}),0),rightIndent:Xe(r.map(g=>{var h,y,k;return (k=(y=(h=g.format)==null?void 0:h.indent)==null?void 0:y.right)!=null?k:0}),0),firstLineIndent:Xe(r.map(g=>{var h,y,k;return (k=(y=(h=g.format)==null?void 0:h.indent)==null?void 0:y.firstLine)!=null?k:0}),0),spacingBefore:Xe(r.map(g=>{var h,y,k;return (k=(y=(h=g.format)==null?void 0:h.spacing)==null?void 0:y.before)!=null?k:0}),0),spacingAfter:Xe(r.map(g=>{var h,y,k;return (k=(y=(h=g.format)==null?void 0:h.spacing)==null?void 0:y.after)!=null?k:0}),0),lineSpacing:Gp(r.map(g=>{var y,k,C,N,L;let h=(k=(y=g.format)==null?void 0:y.spacing)==null?void 0:k.line;return h===void 0?null:{line:h,lineRule:(L=(N=(C=g.format)==null?void 0:C.spacing)==null?void 0:N.lineRule)!=null?L:"auto"}})),listType:Xe(r.map(g=>{var h;return (h=g.format)!=null&&h.hasNumbering?cn(g.format.numbering):null}),null),listLevel:Xe(r.map(g=>{var h,y,k;return (h=g.format)!=null&&h.hasNumbering?(k=(y=g.format.numbering)==null?void 0:y.ilvl)!=null?k:0:null}),null),image:o&&(t==null?void 0:t.kind)==="object"?{objectId:o.drawingId,width:(f=o.width)!=null?f:null,height:(p=o.height)!=null?p:null,alignment:Hp((b=(w=r[0])==null?void 0:w.format)==null?void 0:b.alignment)}:null,table:i}}function Mt(e,t,n){var r,o,i,s,a,l;if(n.kind==="toggle-track-revisions"||n.kind==="accept-revision"||n.kind==="reject-revision"||n.kind==="accept-all-revisions"||n.kind==="reject-all-revisions")return true;if(!t)return false;if(n.kind==="insert-image")return (t.kind==="caret"||t.kind==="text-range")&&n.src.trim().length>0;if(n.kind==="insert-table")return t.kind!=="caret"||!Number.isInteger(n.rows)||!Number.isInteger(n.columns)||n.rows<1||n.rows>20||n.columns<1||n.columns>20?false:((r=be(e,t.paraId))==null?void 0:r.container)===e.blocks;if(n.kind==="delete-table"){let c=Yr(e,t);return !!c&&((o=Oe(e,c.tableId))==null?void 0:o.container)===e.blocks}if(n.kind==="set-image-size"||n.kind==="set-image-alignment")return t.kind==="object"&&t.objectKind==="image"&&t.objectId===n.objectId&&!!$p(e,t);if(n.kind==="insert-table-row"||n.kind==="delete-table-row"||n.kind==="insert-table-column"||n.kind==="delete-table-column"){let c=Yr(e,t);return c!=null&&c.structuralEditingSupported?n.kind==="delete-table-row"?c.rowCount>1:n.kind==="delete-table-column"?c.columnCount>1:true:false}if(n.kind==="set-table-cell-background"||n.kind==="set-table-cell-vertical-alignment"||n.kind==="set-table-cell-borders")return Yr(e,t)!==null;if(n.kind==="merge-table-cells"||n.kind==="split-table-cell"){if(t.kind!=="table-cell-range")return false;let c=Oe(e,t.tableId);if(!c)return false;let u=at(c.table,t);if(n.kind==="merge-table-cells")return Pr(c.table)?t.anchor.rowIndex===t.focus.rowIndex&&u.length>=2&&u.every(w=>w.cell.gridSpan===1&&w.cell.vMerge==null):false;let f=u.length===1?u[0].cell:null;return !!f&&(f.gridSpan>1&&f.vMerge==null&&((i=f.rowSpan)!=null?i:1)===1||f.vMerge==="restart"&&((s=f.rowSpan)!=null?s:1)>1)}return n.kind==="clear-table-cells"?t.kind==="table-cell-range"&&Yr(e,t)!==null:n.kind==="set-hyperlink"?t.kind==="text-range"&&!!((a=n.hyperlink.target)!=null&&a.trim()||(l=n.hyperlink.anchor)!=null&&l.trim()):n.kind==="remove-hyperlink"?t.kind==="text-range"&&zp(e,t)!==null:n.kind==="insert-text"||n.kind==="split-paragraph"||n.kind==="insert-page-break"?t.kind==="caret"&&!!_(e,t.paraId):n.kind==="delete-object"?t.kind==="object"&&t.objectKind===n.objectKind:n.kind==="replace-range"||n.kind==="delete-range"?n.anchor.paraId===n.focus.paraId&&!!_(e,n.anchor.paraId):n.kind==="toggle-bold"||n.kind==="toggle-italic"||n.kind==="toggle-underline"||n.kind==="toggle-strike"||n.kind==="set-font-family"||n.kind==="set-font-size"||n.kind==="set-text-color"||n.kind==="set-highlight-color"||n.kind==="clear-text-format"?t.kind==="text-range"&&hi(e,t).some(c=>c.to>c.from):n.kind==="set-paragraph-alignment"||n.kind==="set-paragraph-indent"||n.kind==="adjust-paragraph-left-indent"||n.kind==="set-paragraph-spacing"||n.kind==="set-paragraph-line-spacing"||n.kind==="toggle-list"||n.kind==="remove-list"||n.kind==="adjust-list-level"?Vp(e,t).length>0:n.kind==="delete-backward"?t.kind==="caret"||t.kind==="object"||t.kind==="table-cell-range":n.kind==="delete-forward"&&(t.kind==="caret"||t.kind==="table-cell-range")}function Yr(e,t){var o,i,s,a;if(!t)return null;if(t.kind==="table-cell-range"){let l=Oe(e,t.tableId);if(!l)return null;let c=at(l.table,t);if(c.length===0)return null;let u=Math.min(t.anchor.rowIndex,t.focus.rowIndex),f=Math.max(t.anchor.rowIndex,t.focus.rowIndex),p=Math.min(t.anchor.columnIndex,t.focus.columnIndex),w=Math.max(t.anchor.columnIndex,t.focus.columnIndex);return {tableId:l.table.tableId,rowIndex:t.anchor.rowIndex,rowCount:l.table.rows.length,columnIndex:t.anchor.columnIndex,columnCount:Math.max(0,...l.table.rows.map(b=>b.cells.reduce((g,h)=>g+Math.max(1,h.gridSpan),0))),range:{startRow:u,endRow:f,startColumn:p,endColumn:w,cellCount:c.length},structuralEditingSupported:Pr(l.table),backgroundColor:Xe(c.map(({cell:b})=>{var g;return Zr((g=b.shading)==null?void 0:g.fill)}),null),verticalAlignment:Xe(c.map(({cell:b})=>{var g;return (g=b.verticalAlignment)!=null?g:null}),null),borderColor:Xe(c.map(({cell:b})=>Dp(b.borders)),null),bordersVisible:Xe(c.map(({cell:b})=>Fp(b.borders)),false)}}let n=t.kind==="text-range"?t.anchor.paraId:t.paraId,r=Qt(e,n);return r?{tableId:r.table.tableId,rowIndex:r.rowIndex,rowCount:r.table.rows.length,columnIndex:r.columnIndex,columnCount:(i=(o=r.table.rows[0])==null?void 0:o.cells.length)!=null?i:0,range:null,structuralEditingSupported:Pr(r.table),backgroundColor:Zr((s=r.cell.shading)==null?void 0:s.fill),verticalAlignment:(a=r.cell.verticalAlignment)!=null?a:null,borderColor:Dp(r.cell.borders),bordersVisible:Fp(r.cell.borders)}:null}function Dp(e){let t=[e==null?void 0:e.top,e==null?void 0:e.right,e==null?void 0:e.bottom,e==null?void 0:e.left].find(n=>n&&n.val!=="nil"&&n.val!=="none");return Zr(t==null?void 0:t.color)}function Fp(e){return [e==null?void 0:e.top,e==null?void 0:e.right,e==null?void 0:e.bottom,e==null?void 0:e.left].some(t=>!!t&&t.val!=="nil"&&t.val!=="none")}function $p(e,t){var r;if((t==null?void 0:t.kind)!=="object"||t.objectKind!=="image")return null;let n=_(e,t.paraId);return (r=n==null?void 0:n.content.find(o=>o.kind==="image"&&o.drawingId===t.objectId))!=null?r:null}function Yy(e,t){if(!t||t.kind==="object"||t.kind==="table-cell-range")return [];if(t.kind==="caret"){let n=_(e,t.paraId);if(!n)return [];let r=Jy(e,n,t.offset);return r?[r]:[]}return hi(e,t).flatMap(n=>Zy(e,n))}function zp(e,t){var r,o,i,s,a;if(!t||t.kind==="object"||t.kind==="table-cell-range")return null;if(t.kind==="caret"){let l=_(e,t.paraId);if(!l)return null;let c=0,u=null;for(let f of l.content){let p=mi(f);if(f.kind==="text"){if(t.offset>c&&t.offset<=c+p)return (r=f.hyperlink)!=null?r:null;if(t.offset===c)return (u==null?void 0:u.kind)==="text"?(i=(o=u.hyperlink)!=null?o:f.hyperlink)!=null?i:null:(s=f.hyperlink)!=null?s:null;u=f;}c+=p;}return (u==null?void 0:u.kind)==="text"&&(a=u.hyperlink)!=null?a:null}let n=hi(e,t).flatMap(l=>{var p;let c=_(e,l.paraId);if(!c)return [];let u=[],f=0;for(let w of c.content){let b=mi(w);w.kind==="text"&&f+b>l.from&&f<l.to&&u.push((p=w.hyperlink)!=null?p:null),f+=b;}return u});return Gp(n)}function Zy(e,t){let n=_(e,t.paraId);if(!n)return [];let r=[],o=0;for(let i of n.content){let s=mi(i);i.kind==="text"&&o+s>t.from&&o<t.to&&r.push(zs(e,n,i.format)),o+=s;}return r}function Jy(e,t,n){let r=0,o=null;for(let i of t.content){let s=mi(i);if(i.kind==="text"){let a=zs(e,t,i.format);if(n>r&&n<=r+s)return a;if(n===r)return o!=null?o:a;o=a;}r+=s;}return o!=null?o:zs(e,t,null)}function zs(e,t,n){var o,i;let r=t.format;return v(v(v({},(i=(o=e.defaults)==null?void 0:o.run)!=null?i:{}),r!=null?r:{}),n!=null?n:{})}function Vp(e,t){if(!t)return [];if(t.kind==="table-cell-range")return [];if(t.kind==="caret"||t.kind==="object"){let n=_(e,t.paraId);return n?[n]:[]}return hi(e,t).map(n=>_(e,n.paraId)).filter(n=>n!==null)}function hi(e,t){let n=Qy(e,t);if(!n)return [];if(n.anchor.paraId===n.focus.paraId)return [{paraId:n.anchor.paraId,from:n.anchor.offset,to:n.focus.offset}];let r=be(e,n.anchor.paraId),o=be(e,n.focus.paraId);if(!r||!o||r.container!==o.container)return [];let i=[];for(let s=r.index;s<=o.index;s+=1){let a=r.container[s];if((a==null?void 0:a.kind)!=="paragraph")return [];i.push({paraId:a.paraId,from:s===r.index?n.anchor.offset:0,to:s===o.index?n.focus.offset:Te(a).length});}return i}function Qy(e,t){if(t.anchor.paraId===t.focus.paraId)return t.anchor.offset<=t.focus.offset?{anchor:t.anchor,focus:t.focus}:{anchor:t.focus,focus:t.anchor};let n=be(e,t.anchor.paraId),r=be(e,t.focus.paraId);return !n||!r||n.container!==r.container?null:n.index<r.index?{anchor:t.anchor,focus:t.focus}:{anchor:t.focus,focus:t.anchor}}function mi(e){var t;return e.kind==="text"?e.text.length:e.kind==="field"?((t=e.cachedText)!=null?t:"\uFFFC").length:e.kind==="drawing"&&e.text?e.text.length:1}function Xe(e,t){return e.length===0?t:e.every(n=>n===e[0])?e[0]:"mixed"}function Gp(e){var n;if(e.length===0||e.every(r=>r===null))return null;let t=JSON.stringify(e[0]);return e.every(r=>JSON.stringify(r)===t)?(n=e[0])!=null?n:null:"mixed"}function Zr(e){if(!e||e.toLowerCase()==="auto")return null;let t=e.replace(/^#/,"").toUpperCase();return /^[0-9A-F]{6}$/.test(t)?`#${t}`:e}function ev(e){var t;return !e||e.toLowerCase()==="none"?null:(t=Zr(e))!=null?t:e}function Hp(e){return e==="center"||e==="right"||e==="both"?e:e==="distribute"?"both":"left"}function jp(e,t,n){let r=0;for(;r<e.length&&r<t.length&&e[r]===t[r];)r+=1;return {revision:n,changes:t.slice(r),revertedChanges:e.slice(r),totalChangeCount:t.length}}var Jr=new WeakMap,Vs="application/x-coco-word-table-cells+json",Qr="application/x-coco-word-image",Xp="coco-image:",eo=new Map,Gs=0,tv=0,js=0,Us=0;function iI(e,t,n={}){var dd,cd,ud;lu();let r=e,o=null;if(n.styleIsolation!=="none"){r.replaceChildren(),o=(dd=r.shadowRoot)!=null?dd:r.attachShadow({mode:"open"}),o.replaceChildren();let d=r.ownerDocument.createElement("style");d.textContent=`
1521
1528
  :host { display: block; position: relative; min-width: 0; min-height: 0; }
1522
1529
  *, *::before, *::after { box-sizing: border-box; }
1523
1530
  button, input, textarea, select { font: inherit; line-height: normal; }
1524
1531
  button { margin: 0; }
1525
- ${(ad=n.styleText)!=null?ad:Rp}`,o.appendChild(d);let m=r.ownerDocument.createElement("div");m.className="coco-word-editor coco-word-native-editor-surface",m.setAttribute("part","surface"),o.appendChild(m),r.classList.add("coco-word-editor-host"),r.style.display="block",r.style.position="relative",r.style.minWidth="0",r.style.minHeight="0",e=m;}let i=r;e.classList.add("coco-word-native-editor-host");let s=t,a=Ha(s),l=false,c=n.readOnly===true,u=[],f=[],p=0,w=new Set(_e(a).map(d=>d.paraId)),b=Date.now()>>>0,g=null,h=null,y=null,k=n.trackRevisions===true,C=null,N=false,L=null,D=null,W=null,V=null,ee=null,pe=null,re=null,we=null,he=false,xe=null,Ve=null,z=null,Z=null,H=null,Y=[],X=[],ye=new WeakSet,ke=false,Fe=false,Ge=false,Qe=false,wt={change:new Set,selectionChange:new Set},an=(d,m)=>{for(let x of wt[d])x(m);},dt=()=>Xr.set(document,e),Ct=d=>$(v({},Bp(a,d)),{trackRevisions:k}),pt=null,Ye=null,Vt=null,ct=null,_t=false,It=false,Rt=()=>{Vt==null||Vt.remove(),Vt=null;},po=d=>{var I;if(!(d instanceof Element))return null;let m=d.closest("coco-word-native-table td[data-row-index][data-column-index]"),x=m==null?void 0:m.closest("coco-word-native-table[data-table-id]"),S=Number(m==null?void 0:m.dataset.rowIndex),E=Number(m==null?void 0:m.dataset.columnIndex);return !m||!x||!Number.isInteger(S)||!Number.isInteger(E)?null:{tableId:(I=x.dataset.tableId)!=null?I:"",point:{rowIndex:S,columnIndex:E},element:m}},fo=d=>{for(let T of Array.from(e.querySelectorAll("td.is-cell-range-selected")))T.classList.remove("is-cell-range-selected","is-cell-range-anchor","is-cell-range-focus"),T.removeAttribute("aria-selected");if((d==null?void 0:d.kind)!=="table-cell-range")return;let m=Array.from(e.querySelectorAll("coco-word-native-table[data-table-id]")).find(T=>T.dataset.tableId===d.tableId);if(!m)return;let x=Math.min(d.anchor.rowIndex,d.focus.rowIndex),S=Math.max(d.anchor.rowIndex,d.focus.rowIndex),E=Math.min(d.anchor.columnIndex,d.focus.columnIndex),I=Math.max(d.anchor.columnIndex,d.focus.columnIndex);for(let T of Array.from(m.querySelectorAll("td[data-row-index][data-column-index]"))){let P=Number(T.dataset.rowIndex),R=Number(T.dataset.columnIndex),B=P+Math.max(1,T.rowSpan)-1,F=R+Math.max(1,T.colSpan)-1;P<=S&&B>=x&&R<=I&&F>=E&&(T.classList.add("is-cell-range-selected"),T.setAttribute("aria-selected","true"),P===d.anchor.rowIndex&&R===d.anchor.columnIndex&&T.classList.add("is-cell-range-anchor"),P===d.focus.rowIndex&&R===d.focus.columnIndex&&T.classList.add("is-cell-range-focus"));}},Qi=++Uy,ea=`coco-word-search-match-${Qi}`,ta=`coco-word-search-active-${Qi}`,na=`coco-word-preserved-selection-${Qi}`,ra=document.createElement("style");ra.textContent=`
1526
- ::highlight(${ea}) { background-color: rgb(250 204 21 / 42%); }
1527
- ::highlight(${ta}) { background-color: rgb(249 115 22 / 68%); color: inherit; }
1528
- ::highlight(${na}) { background-color: rgb(0 120 215 / 34%); color: inherit; }
1529
- `,(o!=null?o:document.head).appendChild(ra);let ft=(sd=globalThis.CSS)==null?void 0:sd.highlights,pr=globalThis.Highlight,Sl=()=>{ft==null||ft.delete(ea),ft==null||ft.delete(ta);},oa=()=>{ft==null||ft.delete(na);},ot=(d=false)=>{if(oa(),(h==null?void 0:h.kind)!=="text-range"||!d&&(document.activeElement===i||e.contains(document.activeElement))||!ft||!pr)return;let m=et(a,h),x=bs(e,m.anchor,m.focus);x&&!x.collapsed&&ft.set(na,new pr(x));},mo=()=>{if(Sl(),!C||!ft||!pr)return;let d=[],m=null;C.matches.forEach((x,S)=>{let E=Ou(e,x.paraId,x.from,x.to);E&&(S===C.activeIndex?m=E:d.push(E));}),d.length>0&&ft.set(ea,new pr(...d)),m&&ft.set(ta,new pr(m));},ho=()=>C?{options:v({},C.options),matches:C.matches.map(d=>v({},d)),activeIndex:C.activeIndex}:null,Fm=()=>{if(!C)return;let d=xs(a,C.options);C={options:v({},C.options),matches:d,activeIndex:d.length===0?-1:Math.min(Math.max(0,C.activeIndex),d.length-1)},mo(),ot();},kl=()=>{let d=C&&C.activeIndex>=0?C.matches[C.activeIndex]:null,m=d?e.querySelector(`coco-word-native-p[data-para-id="${d.paraId}"]`):null;m==null||m.scrollIntoView({block:"center",inline:"nearest"});},Dm=d=>{let m={query:d.query,matchCase:!!d.matchCase,wholeWord:!!d.wholeWord},x=xs(a,m);return C={options:m,matches:x,activeIndex:x.length>0?0:-1},mo(),kl(),ho()},Hm=(d="forward")=>{if(!C||C.matches.length===0)return ho();let m=d==="backward"?-1:1;return C=$(v({},C),{activeIndex:(C.activeIndex+m+C.matches.length)%C.matches.length}),mo(),kl(),ho()},ia=()=>{C=null,Sl();},On=()=>{pt==null||pt.remove(),pt=null;},aa=()=>{if(!pt||!g)return;let d=e.querySelector(`coco-word-native-p[data-para-id="${g.paraId}"] img[data-drawing-id="${g.drawingId}"]`);if(!d){On();return}let m=e.getBoundingClientRect(),x=d.getBoundingClientRect();pt.style.left=`${x.right-m.left+e.scrollLeft-6}px`,pt.style.top=`${x.bottom-m.top+e.scrollTop-6}px`;},Gt=()=>{if(c){On();return}if(!g){On();return}if($u(e,g),!!e.querySelector(`coco-word-native-p[data-para-id="${g.paraId}"] img[data-drawing-id="${g.drawingId}"]`)){if(!(pt!=null&&pt.isConnected)){let m=document.createElement("button");m.type="button",m.className="coco-word-image-resize-handle",m.title="Resize image",m.setAttribute("aria-label","Resize image"),m.contentEditable="false",m.addEventListener("click",x=>{x.preventDefault(),x.stopPropagation();}),m.addEventListener("pointerdown",x=>{if(!g||x.button!==0)return;dt();let S=v({},g),E=e.querySelector(`coco-word-native-p[data-para-id="${S.paraId}"] img[data-drawing-id="${S.drawingId}"]`);if(!E)return;Ye==null||Ye(),x.preventDefault(),x.stopPropagation(),m.setPointerCapture(x.pointerId);let I=E.getBoundingClientRect(),T=x.clientX,P=x.clientY,R=Math.max(1,I.width),B=Math.max(1,I.height),F=R/B,G=R,te=B,ae=Ne=>{let j=Ne.clientX-T,q=Ne.clientY-P;if(Ne.shiftKey)G=Math.max(24,R+j),te=Math.max(24,B+q);else {let J=Math.abs(j)>=Math.abs(q)?j:q*F;G=Math.max(24,R+J),te=Math.max(24,G/F);}E.style.width=`${G}px`,E.style.height=`${te}px`,aa();},ge=Ne=>{Ye==null||Ye(),Ye=null,m.hasPointerCapture(Ne.pointerId)&&m.releasePointerCapture(Ne.pointerId),ve({kind:"set-image-size",objectId:S.drawingId,width:Math.round(G*100)/100,height:Math.round(te*100)/100});};document.addEventListener("pointermove",ae,true),document.addEventListener("pointerup",ge,true),document.addEventListener("pointercancel",ge,true),Ye=()=>{document.removeEventListener("pointermove",ae,true),document.removeEventListener("pointerup",ge,true),document.removeEventListener("pointercancel",ge,true);};}),e.appendChild(m),pt=m;}aa();}},go=()=>aa();window.addEventListener("resize",go),document.addEventListener("scroll",go,true);let El=()=>{if(r.setAttribute("aria-readonly",String(c)),e.dataset.readOnly=String(c),!!c){for(let d of Array.from(e.querySelectorAll('[contenteditable="true"]')))d.contentEditable="false";On();}},Pe=(d,m)=>{D!==null&&(window.clearTimeout(D),D=null),W!==null&&(window.clearTimeout(W),W=null),Go(a);let x=iu(a);e.replaceChildren(x),su(x,a),El(),da(x);let S=(m==null?void 0:m.kind)==="table-cell-range"?m:(h==null?void 0:h.kind)==="table-cell-range"?h:null;fo(S),mo(),ot(),g&&Gt(),(m==null?void 0:m.kind)==="text-range"?hn(e,m.anchor,m.focus):d&&lt(e,d);},sa=(d,m)=>{var I;let x=_(a,d);if(!x){Pe(m);return}let S=Array.from(e.querySelectorAll(`coco-word-native-p[data-para-id="${d}"]`));if(S.length===0){Pe(m);return}for(let T of S)T.replaceWith($r(x));El();let E=(I=e.querySelector(":scope > coco-word-native-document"))!=null?I:e.querySelector("coco-word-native-document");E&&mn(E),g&&Gt(),m&&lt(e,m);},Le=(d,m,x)=>{let S=e.querySelector(":scope > coco-word-native-document");if(!S)return false;let E=lu(S,a,d);da(S);for(let I of Array.from(S.querySelectorAll(`coco-word-native-p[data-para-id="${d}"] img`)))I.complete||ye.has(I)||(ye.add(I),I.addEventListener("load",()=>{ye.delete(I),Le(d);},{once:true}));return (x==null?void 0:x.kind)==="text-range"?hn(e,x.anchor,x.focus):m&&lt(e,m),E},sn=(d,m=180,x)=>{he||we||(W!==null&&window.clearTimeout(W),W=window.setTimeout(()=>{var I;if(W=null,he||we)return;let S=(I=e.querySelector(":scope > coco-word-native-document"))!=null?I:e.querySelector("coco-word-native-document");if(!S||x&&!x(S))return;let E=(h==null?void 0:h.kind)==="object"?h:ze(e);if((E==null?void 0:E.kind)==="text-range")Le(d,void 0,E);else if((E==null?void 0:E.kind)==="object")Le(d),g={paraId:E.paraId,drawingId:E.objectId},Gt();else {let T=(E==null?void 0:E.kind)==="caret"?E:ut(e);Le(d,T!=null?T:void 0);}},m));},bo=(d,m=80)=>{var E;let x=(E=e.querySelector(":scope > coco-word-native-document"))!=null?E:e.querySelector("coco-word-native-document");if(!x)return;let S=false;for(let I of Array.from(x.querySelectorAll(`coco-word-native-p[data-para-id="${d}"] img`)))I.complete||ye.has(I)||(S=true,ye.add(I),I.addEventListener("load",()=>{ye.delete(I),sn(d,0);},{once:true}),I.addEventListener("error",()=>ye.delete(I),{once:true}));sn(d,S?800:m);},fr=d=>{var x;if((xe==null?void 0:xe.paraId)===d)return;let m=(x=e.querySelector(":scope > coco-word-native-document"))!=null?x:e.querySelector("coco-word-native-document");m&&(xe={paraId:d,measurement:cs(m,a,d)});},la=d=>{sn(d,700,m=>{let x=xe;if(xe=null,!x||x.paraId!==d)return false;let S=cs(m,a,d);return S.overflowPx>Math.max(1,x.measurement.overflowPx+1)||!x.measurement.canBackfillPrevious&&S.canBackfillPrevious||!x.measurement.canBackfillNext&&S.canBackfillNext});},wo=new WeakMap,xo=new ResizeObserver(d=>{var m,x;for(let S of d){let E=S.target;if(!(E instanceof HTMLElement))continue;let I=Math.round(S.contentRect.height),T=wo.get(E);if(wo.set(E,I),T===void 0||Math.abs(T-I)<=1)continue;let P=(m=E.querySelector("coco-word-native-p[data-para-id]"))==null?void 0:m.dataset.paraId;if(P){let R=document.activeElement;if(R&&E.contains(R)){let B=(x=R.closest("coco-word-native-p[data-para-id]"))==null?void 0:x.dataset.paraId;la(B!=null?B:P);}else sn(P);}}}),da=d=>{for(let m of Array.from(d.querySelectorAll("coco-word-native-table")))wo.has(m)||(wo.set(m,Math.round(m.getBoundingClientRect().height)),xo.observe(m));},Ie=(d="immediate")=>{if(l)return;let m=()=>{var S;Fm();let x=$p(f,u,++p);f=u.slice(),(S=n.onChange)==null||S.call(n,x),an("change",x);};if(d==="immediate"){ee!==null&&(window.clearTimeout(ee),ee=null),m();return}ee!==null&&window.clearTimeout(ee),ee=window.setTimeout(()=>{ee=null,m();},180);},ca=()=>{l||(pe!==null&&window.clearTimeout(pe),pe=window.setTimeout(()=>{var x,S;pe=null;let d=(x=h!=null?h:ze(e))!=null?x:st(e),m={selection:d,commandState:Ct(d)};(S=n.onSelectionChange)==null||S.call(n,m),an("selectionChange",m);},80));},Cl=d=>{z=d,Z!==null&&window.clearTimeout(Z),Z=window.setTimeout(()=>{z=null,Z=null;},1e3);},Om=(d,m,x)=>{let S=Array.from(e.querySelectorAll(`coco-word-native-p[data-para-id="${d}"] img[data-drawing-id="${m}"]`));for(let E of S)E.remove();Et(e),x&&lt(e,x);},vn=(d,m,x={})=>{Array.isArray(d)?u.push(...d):d&&u.push(d),d&&(X.length=0),x.localParaId?(sa(x.localParaId,m),sn(x.localParaId)):Pe(m),Ie();},yo=d=>{let m=_(a,d);return !!m&&m.content.every(x=>x.kind==="text")},ua=d=>{let m=_(a,d);return m?Te(m).length:0},mr=(d,m,x,S)=>{var P,R;let E=_(a,d);if(!E)return null;let I=S==="before"?m-1:S==="after"?m+1:m;if(I<0)return null;let T=0;for(let B of E.content){let F=B.kind==="text"?B.text.length:1;if(I>=T&&I<T+F){let G=B.kind==="text"?(P=B.marks)==null?void 0:P.find(te=>te.kind==="revision"&&te.revisionKind===x):void 0;return G&&"revisionId"in G&&(R=G.revisionId)!=null?R:null}T+=F;}return null},Il=(d,m)=>{var x;return !k||!m||m.kind!=="text"||m.op!=="insert"&&m.op!=="replace"||m.text.length===0?null:Dt(a,d,m.offset,m.offset+m.text.length,{revisionId:(x=mr(d,m.offset,"insert","before"))!=null?x:rt(a),revisionKind:"insert",author:"User",date:new Date().toISOString()})},pa=d=>{let m=be(a,d.anchor.paraId),x=be(a,d.focus.paraId);if(!m||!x||m.container!==x.container)return null;let S=Math.min(m.index,x.index),E=Math.max(m.index,x.index),I=[];for(let T=S;T<=E;T+=1){let P=m.container[T];if((P==null?void 0:P.kind)!=="paragraph"||P.content.some(R=>R.kind!=="text"))return null;I.push(ue(P));}return I},Nl=d=>{let m=pa(d);return m&&m.length>1?m:null},$m=d=>{let m=Nl(d);return m?(re={range:d,beforeParagraphs:m,changesStart:u.length},true):false},vo=d=>{var T;let m=d.anchor.paraId;if(d.focus.paraId!==m)return;let x=e.querySelector(`coco-word-native-p[data-para-id="${m}"]`),S=_(a,m);if(!(x!=null&&x.closest("coco-word-native-table"))||!S||((T=H==null?void 0:H.afterParagraphs[0])==null?void 0:T.paraId)===m)return;let E=ue(S),I={source:"browser",patchMode:"individual",skipDeferredRender:true,range:d,beforeParagraphs:[E],afterParagraphs:[E],changesStart:u.length,changes:[]};Y.push(I),X.length=0,H=I;},Tl=d=>{if(c){d.preventDefault();return}he=true,Ve!==null&&(window.clearTimeout(Ve),Ve=null),we&&fa(),D!==null&&(window.clearTimeout(D),D=null),W!==null&&(window.clearTimeout(W),W=null),ee!==null&&(window.clearTimeout(ee),ee=null),pe!==null&&(window.clearTimeout(pe),pe=null);let m=ze(e),x=d.target instanceof Node?St(d.target):null,S=x==null?void 0:x.dataset.paraId,E=ut(e),I=S?{paraId:S,offset:(E==null?void 0:E.paraId)===S?E.offset:ua(S)}:E,T=I?_(a,I.paraId):null;if(!I||!T||T.content.some(R=>R.kind!=="text"))return;fr(I.paraId),H=null;let P=(m==null?void 0:m.kind)==="text-range"&&m.anchor.paraId===I.paraId&&m.focus.paraId===I.paraId?{anchor:v({},m.anchor),focus:v({},m.focus)}:{anchor:I,focus:I};we={paraId:I.paraId,beforeParagraph:ue(T),changesStart:u.length,range:P};},fa=()=>{var R;Ve=null;let d=we;if(we=null,!d)return;let m=_(a,d.paraId);if(!m)return;let x=e.querySelector(`coco-word-native-p[data-para-id="${d.paraId}"]`);if(!x)return;let S=Rr(a,d.paraId,(R=x.textContent)!=null?R:"");S&&u.push(S);let E=Il(d.paraId,S);E&&u.push(E);let I=ue(m);if(JSON.stringify(I)===JSON.stringify(d.beforeParagraph)){u.splice(d.changesStart);return}let T={source:"browser",patchMode:"individual",skipDeferredRender:true,range:d.range,beforeParagraphs:[d.beforeParagraph],afterParagraphs:[I],changesStart:d.changesStart,changes:u.slice(d.changesStart)};Y.push(T),X.length=0;let P=ut(e);P&&ne(v({kind:"caret"},P)),la(d.paraId),E&&sa(d.paraId,P!=null?P:void 0),Ie("deferred");},Pl=()=>{he=false,Ve!==null&&window.clearTimeout(Ve),Ve=window.setTimeout(fa,80);},So=(d,m)=>{var R,B;let x=new Set([...d.beforeParagraphs,...d.afterParagraphs].map(F=>F.paraId)),S=(R=[...d.beforeParagraphs,...d.afterParagraphs].find(F=>_(a,F.paraId)))==null?void 0:R.paraId;if(!S)return false;let E=be(a,S);if(!E)return false;if(d.patchMode==="individual"){for(let F of m){let G=be(a,F.paraId);if(!G)return false;Object.assign(G.paragraph,ue(F));}return true}let I=Array.from(x).filter(F=>_(a,F));if(I.length===0||m.length===0)return false;let T=ue(m[0]);Object.assign(E.paragraph,T);for(let F of I)F!==S&&((B=be(a,F))==null||B.remove());let P=T.paraId;for(let F of m.slice(1)){let G=be(a,P);if(!G)return false;let te=ue(F);G.insertAfter(te),P=te.paraId;}return true},zm=()=>{var T;if(!re)return false;let d=re;re=null;let m=d.beforeParagraphs.map(P=>Kp(e,P.paraId)),x=m.every(P=>P!==null),S=[];if(x)for(let P=0;P<d.beforeParagraphs.length;P+=1){let R=d.beforeParagraphs[P],B=Rr(a,R.paraId,(T=m[P])!=null?T:"");B&&S.push(B);}else S.push(...qo(a,d.range.anchor,d.range.focus));if(S.length===0)return false;u.push(...S);let E=d.beforeParagraphs.map(P=>_(a,P.paraId)).filter(P=>P!==null);if(E.length>0){let P=$(v({},d),{source:"browser",afterParagraphs:E.map(ue),changes:S});Y.push(P),H=null,X.length=0;}let I=ut(e);return I&&ne({kind:"caret",paraId:I.paraId,offset:I.offset}),Le(d.beforeParagraphs[0].paraId,I!=null?I:void 0),Ie("deferred"),true},Vm=()=>{let d=Y[Y.length-1];if(!d||Qn(d)||!pi(e,d.beforeParagraphs)||!So(d,d.beforeParagraphs))return false;Y.pop(),X.push(d),u.splice(d.changesStart);let m=ut(e);return m&&ne({kind:"caret",paraId:m.paraId,offset:m.offset}),Le(d.beforeParagraphs[0].paraId,m!=null?m:void 0),Ie("deferred"),true},Gm=()=>{let d=X[X.length-1];if(!d||Qn(d)||!pi(e,d.afterParagraphs)||!So(d,d.afterParagraphs))return false;X.pop(),Y.push(d),u.splice(d.changesStart),u.push(...d.changes);let m=ut(e);return m&&ne({kind:"caret",paraId:m.paraId,offset:m.offset}),Le(d.beforeParagraphs[0].paraId,m!=null?m:void 0),Ie("deferred"),true},At=(d,m,x)=>{var B,F,G;if(d.patchMode==="individual"){let te=false;for(let ge of m){let Ne=Array.from(e.querySelectorAll(`coco-word-native-p[data-para-id="${ge.paraId}"]`));for(let j of Ne)j.replaceWith($r(ge)),te=true;}x&&lt(e,x);let ae=e.querySelector(":scope > coco-word-native-document");return ae&&mn(ae),te}let S=new Set([...d.beforeParagraphs,...d.afterParagraphs].map(te=>te.paraId)),E=Array.from(S).flatMap(te=>Array.from(e.querySelectorAll(`coco-word-native-p[data-para-id="${te}"]`))),I=(B=d.beforeParagraphs[0])==null?void 0:B.paraId,T=(F=E.find(te=>te.dataset.paraId===I))!=null?F:E[0];if(!T)return false;let P=m.map(te=>$r(te));T.replaceWith(...P);for(let te of E)te!==T&&te.isConnected&&te.remove();x&&lt(e,x);let R=(G=e.querySelector(":scope > coco-word-native-document"))!=null?G:e.querySelector("coco-word-native-document");return R&&mn(R),true},Ml=(d,m,x)=>(d.container.splice(d.startIndex,x,...nt(m)),true),Lt=(d,m,x,S)=>{var B,F;let E=[...d.beforeBlocks,...d.afterBlocks].flatMap(G=>qy(e,G)),I=((B=d.afterBlocks[0])==null?void 0:B.kind)==="paragraph"?d.afterBlocks[0].paraId:((F=d.beforeBlocks[0])==null?void 0:F.kind)==="paragraph"?d.beforeBlocks[0].paraId:null,T=I?e.querySelector(`coco-word-native-p[data-para-id="${I}"]`):E[0];if(!T)return false;let P=m.map(G=>Or(G));T.replaceWith(...P);for(let G of E)G!==T&&G.isConnected&&G.remove();let R=e.querySelector(":scope > coco-word-native-document");return R&&da(R),R&&mn(R),S?hn(e,S.anchor,S.focus):x&&lt(e,x),true},jm=d=>{let m=e.querySelector(`coco-word-native-p[data-para-id="${d.anchor.paraId}"]`),x=e.querySelector(`coco-word-native-p[data-para-id="${d.focus.paraId}"]`);return !!m&&!!x&&m.closest("coco-word-native-page")!==x.closest("coco-word-native-page")},Rl=(d,m)=>{let x=Nl(d);if(!x)return false;let S={range:d,beforeParagraphs:x,changesStart:u.length},E=Lc(a,d.anchor,d.focus,m);if(E.length===0)return false;let I=x.map(R=>_(a,R.paraId)).filter(R=>R!==null).map(ue);if(I.length===0)return false;let T=$(v({},S),{source:"local",afterParagraphs:I,changes:E}),P={paraId:d.anchor.paraId,offset:d.anchor.offset+m.length};return u.push(...E),Y.push(T),H=m.length>0?T:null,X.length=0,At(T,I,P)?Le(x[0].paraId,P):Pe(P),ne(v({kind:"caret"},P)),Ie("deferred"),true},ko=(d,m)=>{let x=Rc(a,d.anchor,d.focus,m);if(!x)return false;let S={source:"local",range:d,container:x.container,startIndex:x.startIndex,beforeBlocks:x.beforeBlocks,afterBlocks:x.afterBlocks,changesStart:u.length,changes:x.changes};if(u.push(...x.changes),Y.push(S),X.length=0,H=null,g=null,!Lt(S,x.afterBlocks,x.cursor))Pe(x.cursor);else {let E=e.querySelector(":scope > coco-word-native-document");E&&Ot(E,a,x.cursor.paraId),Le(x.cursor.paraId,x.cursor);}return ne(v({kind:"caret"},x.cursor)),Ie("deferred"),true},Um=(d,m)=>{let x=Ac(a,d.anchor,d.focus,m);if(!x)return false;let S={source:"local",range:d,container:x.container,startIndex:x.startIndex,beforeBlocks:x.beforeBlocks,afterBlocks:x.afterBlocks,changesStart:u.length,changes:x.changes};u.push(...x.changes),Y.push(S),X.length=0,H=null,g=null;for(let E of _e(a))w.add(E.paraId);if(!Lt(S,x.afterBlocks,x.cursor))Pe(x.cursor);else {let E=e.querySelector(":scope > coco-word-native-document");E&&Ot(E,a,x.cursor.paraId),Le(x.cursor.paraId,x.cursor);}return ne(v({kind:"caret"},x.cursor)),Ie("deferred"),true},Km=(d,m)=>{let x=d.kind==="table-cell-range"?(()=>{var Ne,j,q;let te=(Ne=Oe(a,d.tableId))==null?void 0:Ne.table,ae=te?(j=at(te,d)[0])==null?void 0:j.cell:null,ge=(q=ae==null?void 0:ae.paragraphs[0])==null?void 0:q.paraId;return ge?{paraId:ge,offset:0}:null})():d.kind==="text-range"?d.anchor:{paraId:d.paraId,offset:d.offset};if(!x)return false;let S=Jt(a,x.paraId);if(!S)return false;let E=nt([S.table])[0];if(!E||E.kind!=="table")return false;let I=m.kind==="insert-table-row"?{kind:"insert-row",position:m.position}:m.kind==="delete-table-row"?{kind:"delete-row"}:m.kind==="insert-table-column"?{kind:"insert-column",position:m.position}:{kind:"delete-column"},T=yc(a,x.paraId,I,wr);if(!T)return false;let P=nt([S.table])[0];if(!P||P.kind!=="table")return false;let R=k?rt(a):null,B=m.kind==="insert-table-row"||m.kind==="insert-table-column"?"insert":"delete";R&&(S.table.revision={kind:"revision",id:`revision:${R}`,revisionId:R,revisionKind:B,author:"User",date:new Date().toISOString()},P.revision=v({},S.table.revision),T.change.kind==="table"&&(T.change.revisionId=R,T.change.revisionKind=B,T.change.beforeTable=E));let F=v({kind:"caret"},T.cursor),G={source:"local",range:{anchor:x,focus:x},container:S.container,startIndex:S.tableIndex,beforeBlocks:[E],afterBlocks:[P],changesStart:u.length,changes:[T.change],beforeSelection:d,afterSelection:F};if(u.push(T.change),Y.push(G),X.length=0,H=null,g=null,!Lt(G,G.afterBlocks,T.cursor))Pe(T.cursor);else {let te=e.querySelector(":scope > coco-word-native-document");te&&Ot(te,a,T.cursor.paraId),Le(T.cursor.paraId,T.cursor);}return ne(F),Ie("deferred"),true},_m=(d,m)=>{let x=Oe(a,d.tableId);if(!x)return false;let S=nt([x.table])[0];if(!S||S.kind!=="table")return false;let I=at(x.table,d)[0],T=m.kind==="merge-table-cells"?vc(a,d.tableId,d):I?Sc(a,d.tableId,I.rowIndex,I.columnIndex,wr):null;if(!T)return false;let P=nt([x.table])[0];if(!P||P.kind!=="table")return false;let R=k?rt(a):null,B=m.kind==="merge-table-cells"?"insert":"delete";R&&(x.table.revision={kind:"revision",id:`revision:${R}`,revisionId:R,revisionKind:B,author:"User",date:new Date().toISOString()},P.revision=v({},x.table.revision),T.change.kind==="table"&&(T.change.revisionId=R,T.change.revisionKind=B,T.change.beforeTable=S));let F={source:"local",range:{anchor:{paraId:T.cursor.paraId,offset:T.cursor.offset},focus:{paraId:T.cursor.paraId,offset:T.cursor.offset}},container:x.container,startIndex:x.tableIndex,beforeBlocks:[S],afterBlocks:[P],changesStart:u.length,changes:[T.change],beforeSelection:d,afterSelection:v({kind:"caret"},T.cursor)};if(u.push(T.change),Y.push(F),X.length=0,H=null,g=null,!Lt(F,F.afterBlocks,T.cursor))Pe(T.cursor);else {let G=e.querySelector(":scope > coco-word-native-document");G&&Ot(G,a,T.cursor.paraId),Le(T.cursor.paraId,T.cursor);}return ne(v({kind:"caret"},T.cursor)),Ie("deferred"),true},qm=(d,m)=>{let x=d.kind==="text-range"?d.anchor:d.kind==="table-cell-range"?(()=>{var F,G;let R=(F=Oe(a,d.tableId))==null?void 0:F.table,B=R?(G=at(R,d)[0])==null?void 0:G.cell.paragraphs[0]:null;return B?{paraId:B.paraId,offset:0}:null})():{paraId:d.paraId,offset:d.offset};if(!x)return false;let S=m.kind==="insert-table"?d.kind==="caret"?wc(a,d.paraId,d.offset,m.rows,m.columns,wr):null:(()=>{var B;let R=(B=Ct(d).table)==null?void 0:B.tableId;return R?xc(a,R,wr):null})();if(!S)return false;let E=k?rt(a):null,I=m.kind==="insert-table"?"insert":"delete";if(E){let R=S.afterBlocks.find(B=>B.kind==="table");(R==null?void 0:R.kind)==="table"&&(R.revision={kind:"revision",id:`revision:${E}`,revisionId:E,revisionKind:I,author:"User",date:new Date().toISOString()},S.changes.forEach(B=>{if(B.kind==="table"){B.revisionId=E,B.revisionKind=I;let F=S.beforeBlocks.find(G=>G.kind==="table");if((F==null?void 0:F.kind)==="table"&&(B.beforeTable=F),B.op==="insert-table"){B.anchorParaId=x.paraId,B.anchorOffset=x.offset;let G=S.afterBlocks.find(te=>te.kind==="table");(G==null?void 0:G.kind)==="table"&&(B.tableSnapshot=G);}}}));}for(let R of S.changes){if(R.kind!=="table"||R.op!=="insert-table")continue;R.anchorParaId=x.paraId,R.anchorOffset=x.offset;let B=S.afterBlocks.find(F=>F.kind==="table");(B==null?void 0:B.kind)==="table"&&(R.tableSnapshot=B);}let T=v({kind:"caret"},S.cursor),P={source:"local",range:{anchor:x,focus:d.kind==="text-range"?d.focus:x},container:S.container,startIndex:S.startIndex,beforeBlocks:S.beforeBlocks,afterBlocks:S.afterBlocks,changesStart:u.length,changes:S.changes,beforeSelection:d,afterSelection:T};u.push(...S.changes),Y.push(P),X.length=0,H=null,g=null;for(let R of _e(a))w.add(R.paraId);if(!Lt(P,P.afterBlocks,S.cursor))Pe(S.cursor);else {let R=e.querySelector(":scope > coco-word-native-document");R&&Ot(R,a,S.cursor.paraId),Le(S.cursor.paraId,S.cursor);}return ne(T),Ie("deferred"),true},Xm=(d,m)=>{var ae,ge;let x=d.kind==="table-cell-range"?Oe(a,d.tableId):null,S=d.kind==="table-cell-range"&&x?(ae=at(x.table,d)[0])==null?void 0:ae.cell:null,E=d.kind==="table-cell-range"?(ge=S==null?void 0:S.paragraphs[0])!=null&&ge.paraId?{paraId:S.paragraphs[0].paraId,offset:0}:null:d.kind==="text-range"?d.anchor:{paraId:d.paraId,offset:d.offset};if(!E)return false;let I=x!=null?x:Jt(a,E.paraId);if(!I)return false;let T=nt([I.table])[0];if(!T||T.kind!=="table")return false;let P=m.kind==="set-table-cell-background"?{backgroundColor:m.color}:m.kind==="set-table-cell-vertical-alignment"?{verticalAlignment:m.alignment}:{borderColor:m.color},R=d.kind==="table-cell-range"?kc(a,d.tableId,d,P):qa(a,E.paraId,P);if(!R)return false;let B=nt([I.table])[0];if(!B||B.kind!=="table")return false;let F={source:"local",range:{anchor:E,focus:E},container:I.container,startIndex:I.tableIndex,beforeBlocks:[T],afterBlocks:[B],changesStart:u.length,changes:"changes"in R?R.changes:[R.change],beforeSelection:d,afterSelection:d};u.push(...F.changes),Y.push(F),X.length=0,H=null;let G=d.kind==="caret"?d:void 0,te=d.kind==="text-range"?d:void 0;if(!Lt(F,F.afterBlocks,G,te))Pe(G,d);else {Wt(d);let Ne=e.querySelector(":scope > coco-word-native-document");Ne&&Ot(Ne,a,E.paraId),Le(E.paraId,G,te),Wt(d);}return ne(d),Ie("deferred"),true},$n=d=>{let m=Oe(a,d.tableId);if(!m)return false;let x=nt([m.table])[0];if(!x||x.kind!=="table")return false;let S=Ec(a,d.tableId,d);if(!S)return false;let E=nt([m.table])[0];if(!E||E.kind!=="table")return false;let I={source:"local",range:{anchor:S.cursor,focus:S.cursor},container:m.container,startIndex:m.tableIndex,beforeBlocks:[x],afterBlocks:[E],changesStart:u.length,changes:S.changes,beforeSelection:d,afterSelection:d};if(u.push(...S.changes),Y.push(I),X.length=0,H=null,!Lt(I,I.afterBlocks))Pe(void 0,d);else {let T=e.querySelector(":scope > coco-word-native-document");T&&Ot(T,a,S.cursor.paraId),Le(S.cursor.paraId);}return ne(d),Ie("deferred"),true},ma=(d,m)=>{var te,ae,ge;let x=Oe(a,d.tableId);if(!x)return false;let S=nt([x.table])[0];if(!S||S.kind!=="table")return false;let E={rowIndex:Math.min(d.anchor.rowIndex,d.focus.rowIndex),columnIndex:Math.min(d.anchor.columnIndex,d.focus.columnIndex)},I=(ae=(te=m.content)!=null?te:m.text)!=null?ae:[],T=m.content?Ic(a,d.tableId,E,m.content):Cc(a,d.tableId,E,(ge=m.text)!=null?ge:[]);if(!T)return false;let P=nt([x.table])[0];if(!P||P.kind!=="table")return false;let R=I.length,B=Math.max(1,...I.map(Ne=>Ne.length)),F={kind:"table-cell-range",tableId:d.tableId,anchor:E,focus:{rowIndex:Math.min(x.table.rows.length-1,E.rowIndex+R-1),columnIndex:E.columnIndex+B-1}},G={source:"local",range:{anchor:T.cursor,focus:T.cursor},container:x.container,startIndex:x.tableIndex,beforeBlocks:[S],afterBlocks:[P],changesStart:u.length,changes:T.changes,beforeSelection:d,afterSelection:F};if(u.push(...T.changes),Y.push(G),X.length=0,H=null,!Lt(G,G.afterBlocks))Pe(void 0,F);else {let Ne=e.querySelector(":scope > coco-word-native-document");Ne&&Ot(Ne,a,T.cursor.paraId),Le(T.cursor.paraId);}return ne(F),Ie("deferred"),true},Wt=d=>{if(d){if(d.kind==="text-range"){hn(e,d.anchor,d.focus);return}if(d.kind==="object"){g={paraId:d.paraId,drawingId:d.objectId},Gt();return}if(d.kind==="table-cell-range"){fo(d);return}lt(e,d);}},Ym=()=>{var S;let d=Y[Y.length-1];if(!d)return false;if(Qn(d)){let E=(S=d.beforeSelection)!=null?S:{kind:"text-range",anchor:d.range.anchor,focus:d.range.focus},I=E.kind==="caret"?E:void 0,T=E.kind==="text-range"?E:void 0;if(!Ml(d,d.beforeBlocks,d.afterBlocks.length));Lt(d,d.beforeBlocks,I,T)||Pe(I,E),Wt(E),Y.pop(),X.push(d),H=null,u.splice(d.changesStart),ne(E);let P=e.querySelector(":scope > coco-word-native-document");P&&Ot(P,a,d.range.anchor.paraId);let R=E.kind==="text-range"?E.anchor.paraId:E.kind==="table-cell-range"?d.range.anchor.paraId:E.paraId;return Le(R,I,T),Ie("deferred"),true}if(d.source==="browser"&&!d.skipDeferredRender&&!pi(e,d.afterParagraphs))return false;let m={paraId:d.beforeParagraphs[0].paraId,offset:d.range.anchor.offset};if(!So(d,d.beforeParagraphs))return false;let x=Vp(d,"before");if(d.forceFullRender){Y.pop(),X.push(d),H=null,u.splice(d.changesStart);let E=x!=null?x:v({kind:"caret"},m);return ne(E),Pe(E.kind==="caret"?E:void 0,E),Wt(E),Ie("deferred"),true}if(!At(d,d.beforeParagraphs,x?void 0:m))return false;if(Wt(x),Y.pop(),X.push(d),H=null,u.splice(d.changesStart),ne(x!=null?x:v({kind:"caret"},m)),Gp(d)||d.skipDeferredRender){let E=d.beforeParagraphs[0].paraId;d.deferLayoutReflow?bo(E):Le(E,x?void 0:m,(x==null?void 0:x.kind)==="text-range"?x:void 0),Wt(x),d.deferLayoutReflow||sn(E);}return Ie("deferred"),true},Zm=()=>{var S;let d=X[X.length-1];if(!d)return false;if(Qn(d)){let E=(S=d.afterSelection)!=null?S:{kind:"caret",paraId:d.afterBlocks[0].kind==="paragraph"?d.afterBlocks[0].paraId:d.range.anchor.paraId,offset:d.range.anchor.offset},I=E.kind==="caret"?E:void 0,T=E.kind==="text-range"?E:void 0;if(!Ml(d,d.afterBlocks,d.beforeBlocks.length));Lt(d,d.afterBlocks,I,T)||Pe(I,E),Wt(E),X.pop(),Y.push(d),H=null,u.splice(d.changesStart),u.push(...d.changes),ne(E);let P=E.kind==="text-range"?E.anchor.paraId:E.kind==="table-cell-range"?d.range.anchor.paraId:E.paraId,R=e.querySelector(":scope > coco-word-native-document");return R&&Ot(R,a,P),Le(P,I,T),Ie("deferred"),true}if(d.source==="browser"&&!d.skipDeferredRender&&!pi(e,d.beforeParagraphs))return false;let m={paraId:d.afterParagraphs[0].paraId,offset:d.range.anchor.offset};if(!So(d,d.afterParagraphs))return false;let x=Vp(d,"after");if(d.forceFullRender){X.pop(),Y.push(d),H=null,u.splice(d.changesStart),u.push(...d.changes);let E=x!=null?x:v({kind:"caret"},m);return ne(E),Pe(E.kind==="caret"?E:void 0,E),Wt(E),Ie("deferred"),true}if(!At(d,d.afterParagraphs,x?void 0:m))return false;if(Wt(x),X.pop(),Y.push(d),H=null,u.splice(d.changesStart),u.push(...d.changes),ne(x!=null?x:v({kind:"caret"},m)),Gp(d)||d.skipDeferredRender){let E=d.beforeParagraphs[0].paraId;d.deferLayoutReflow?bo(E):Le(E,x?void 0:m,(x==null?void 0:x.kind)==="text-range"?x:void 0),Wt(x),d.deferLayoutReflow||sn(E);}return Ie("deferred"),true},hr=()=>l||c||Y.length===0?false:(dt(),Ym()),gr=()=>l||c||X.length===0?false:(dt(),Zm()),ne=d=>{if(d&&dt(),(d==null?void 0:d.kind)!=="object"&&On(),fo(d),Xy(h,d)){ot();return}h=d,ot(),ca();},br=(d,m,x)=>{if(!d||(m==null?void 0:m.kind)!=="image")return false;let S=_(a,m.paraId);if(!S)return false;let E={source:"local",patchMode:"individual",deferLayoutReflow:true,range:{anchor:x,focus:x},beforeParagraphs:[d],afterParagraphs:[ue(S)],changesStart:u.length,changes:[m],beforeSelection:{kind:"object",paraId:m.paraId,objectKind:"image",objectId:m.drawingId,offset:m.offset},afterSelection:v({kind:"caret"},x)};return u.push(m),Y.push(E),X.length=0,H=null,Om(m.paraId,m.drawingId,x),bo(m.paraId),g=null,ne(v({kind:"caret"},x)),Ie("deferred"),true},Sn=(d,m,x)=>{let S=_(a,d),E=S==null?void 0:S.content.find(T=>T.kind==="image"&&T.drawingId===m);if(k&&S&&(E==null?void 0:E.kind)==="image"){let T=ue(S),P=rt(a);return E.revision={kind:"revision",id:`revision:${P}`,revisionId:P,revisionKind:"delete",author:"User",date:new Date().toISOString()},mt({kind:"object",paraId:d,objectKind:"image",objectId:m,offset:x.offset},[T],[{kind:"image",op:"delete",paraId:d,offset:x.offset,drawingId:m,revisionId:P,revisionKind:"delete"}],true)}let I=S?ue(S):null;return br(I,Oc(a,d,m),x)},kn=(d,m,x=v({kind:"caret"},d),S)=>{let E=_(a,d.paraId);if(!E)return false;let I=m==="delete-backward"?d.offset-1:d.offset;if(m!=="insert"&&!_o(a,d.paraId,I))return false;let T=ue(E),P=m==="insert"?Tc(a,d.paraId,d.offset):m==="delete-backward"?Nr(a,d.paraId,d.offset):Tr(a,d.paraId,d.offset),R=_(a,d.paraId);if(!P||P.kind!=="page-break"||!R)return false;let B={paraId:d.paraId,offset:m==="insert"?d.offset+1:m==="delete-backward"?Math.max(0,d.offset-1):d.offset},F=S!=null?S:v({kind:"caret"},B),G=F.kind==="caret"?F:B,te={source:"local",patchMode:"individual",forceFullRender:true,range:{anchor:d,focus:d},beforeParagraphs:[T],afterParagraphs:[ue(R)],changesStart:u.length,changes:[P],beforeSelection:x,afterSelection:F};return u.push(P),Y.push(te),X.length=0,H=null,g=null,Pe(G,F),ne(F),Ie("deferred"),true},Eo=d=>{if(d.anchor.paraId!==d.focus.paraId)return false;let m=fi(d.anchor.offset,d.focus.offset);if(!Pc(a,d.anchor.paraId,m.from,m.to))return false;let x=_(a,d.anchor.paraId);if(!x)return false;let S=ue(x),E=un(a,d.anchor.paraId,m.from,m.to),I=_(a,d.anchor.paraId);if(!I||!E.some(R=>R.kind==="page-break"))return false;let T={kind:"caret",paraId:d.anchor.paraId,offset:m.from},P={source:"local",patchMode:"individual",forceFullRender:true,range:{anchor:d.anchor,focus:d.focus},beforeParagraphs:[S],afterParagraphs:[ue(I)],changesStart:u.length,changes:E,beforeSelection:d,afterSelection:T};return u.push(...E),Y.push(P),X.length=0,H=null,Pe(T,T),ne(T),Ie("deferred"),true},Co=(d,m)=>{let x=be(a,d.paraId);if(!x)return false;if(m==="backward"&&d.offset===0&&x.previous){let I=Te(x.previous).length;return _o(a,x.previous.paraId,I-1)?kn({paraId:x.previous.paraId,offset:I},"delete-backward",d,d):false}let S=x.container[x.index+1],E=(S==null?void 0:S.kind)==="paragraph"?S:null;return m==="forward"&&d.offset===Te(x.paragraph).length&&E&&_o(a,E.paraId,0)?kn({paraId:E.paraId,offset:0},"delete-forward",d,d):false},En=(d,m,x,S)=>{if(d.anchor.paraId!==d.focus.paraId)return false;let E=_(a,d.anchor.paraId);if(!E)return false;let I=ue(E),T=S(),P=Array.isArray(T)?T:T?[T]:[],R=_(a,d.anchor.paraId);if(P.length===0||!R)return false;let B=v({kind:"caret"},x),F={source:"local",patchMode:"individual",range:d,beforeParagraphs:[I],afterParagraphs:[ue(R)],changesStart:u.length,changes:P,beforeSelection:m,afterSelection:B};return u.push(...P),Y.push(F),X.length=0,H=null,At(F,F.afterParagraphs,x)?Le(d.anchor.paraId,x):Pe(x),ne(B),Ie("deferred"),true},qt=d=>{if((d==null?void 0:d.kind)!=="text-range")return [];let m=et(a,d);if(m.anchor.paraId===m.focus.paraId)return [{paraId:m.anchor.paraId,from:m.anchor.offset,to:m.focus.offset}];let x=be(a,m.anchor.paraId),S=be(a,m.focus.paraId);if(!x||!S||x.container!==S.container)return [];let E=[];for(let I=x.index;I<=S.index;I+=1){let T=x.container[I];if((T==null?void 0:T.kind)!=="paragraph")return [];E.push({paraId:T.paraId,from:I===x.index?m.anchor.offset:0,to:I===S.index?m.focus.offset:Te(T).length});}return E},Al=d=>d?d.kind==="caret"||d.kind==="object"?[d.paraId]:qt(d).map(m=>m.paraId):[],Ll=d=>{if((d==null?void 0:d.kind)!=="text-range")return null;let m=qt(d);return m.length===0?null:m.map(x=>Te(_(a,x.paraId)).slice(x.from,x.to)).join(`
1530
- `)},Wl=d=>qt(d).map(m=>{var P;let x=_(a,m.paraId),S=Te(x).slice(m.from,m.to),E=[],I=0;for(let R of x.content){let B=Zy(R),F=I+B.length,G=Math.max(m.from,I),te=Math.min(m.to,F),ae=R.kind==="text"||R.kind==="field"?R.format:null,ge=R.kind==="text"?R.hyperlink:void 0;(ae||ge)&&te>G&&E.push(v({from:G-m.from,to:te-m.from,format:v({},ae!=null?ae:{})},ge?{hyperlink:v({},ge)}:{})),I=F;}let T=(P=x.format)!=null&&P.hasNumbering&&x.format.numbering?dn(x.format.numbering):null;return v({text:S,runs:E},T?{listType:T}:{})}),zn=(d,m,x)=>{var R;if(k&&!x&&d.anchor.paraId===d.focus.paraId)return ve({kind:"replace-range",anchor:d.anchor,focus:d.focus,text:m});if(ko(d,m))return true;let S=pa(d);if(!S)return false;let E=Za(a,d.anchor,d.focus,m);if(!E||E.changes.length===0)return false;for(let B of E.paragraphIds)w.add(B);let I=null;for(let B=0;B<((R=x==null?void 0:x.length)!=null?R:0);B+=1){let F=x[B],G=E.paragraphIds[B];if(!G)break;let te=B===0?d.anchor.offset:0;for(let ae of F.runs){if(Object.keys(ae.format).length>0){let ge=Ja(a,G,te+ae.from,te+ae.to,ae.format);ge&&E.changes.push(ge);}if(ae.hyperlink){let ge=es(a,G,te+ae.from,te+ae.to,ae.hyperlink);ge&&E.changes.push(ge);}}if(F.listType){(!I||I.type!==F.listType)&&(I={type:F.listType,numbering:Ga(a,F.listType)});let ae=Mr(a,G,I.numbering);ae&&E.changes.push(ae);}else I=null;}if(k){let B=rt(a),F=E.changes.filter(G=>G.kind==="text"&&(G.op==="insert"||G.op==="replace")&&G.text.length>0).map(G=>Dt(a,G.paraId,G.offset,G.offset+G.text.length,{revisionId:B,revisionKind:"insert",author:"User",date:new Date().toISOString()})).filter(G=>G!==null);E.changes.push(...F);}Go(a);let T=E.paragraphIds.map(B=>_(a,B)).filter(B=>B!==null).map(ue),P={source:"local",range:d,beforeParagraphs:S,afterParagraphs:T,changesStart:u.length,changes:E.changes};return u.push(...E.changes),Y.push(P),X.length=0,H=null,g=null,At(P,T,E.cursor)?Le(S[0].paraId,E.cursor):Pe(E.cursor),ne(v({kind:"caret"},E.cursor)),Ie("deferred"),true},ha=(d,m,x={})=>{var G,te;let S=pa(d);if(!S)return false;let E=Za(a,d.anchor,d.focus,"");if(!E)return false;for(let ae of E.paragraphIds)w.add(ae);let I=Nc(a,E.cursor.paraId,E.cursor.offset,m,x);if(!I||I.kind!=="image")return false;let T=[...E.changes,I];if(k){let ae=rt(a),ge=(G=_(a,I.paraId))==null?void 0:G.content.find(Ne=>Ne.kind==="image"&&Ne.drawingId===I.drawingId);(ge==null?void 0:ge.kind)==="image"&&(ge.revision={kind:"revision",id:`revision:${ae}`,revisionId:ae,revisionKind:"insert",author:"User",date:new Date().toISOString()},T.push({kind:"image",op:"insert",paraId:I.paraId,offset:I.offset,drawingId:I.drawingId,revisionId:ae,revisionKind:"insert"}));}let P={paraId:E.cursor.paraId,offset:E.cursor.offset+1},R=E.paragraphIds.map(ae=>_(a,ae)).filter(ae=>ae!==null).map(ue),B=v({source:"local",patchMode:"individual",deferLayoutReflow:true,range:d,beforeParagraphs:S,afterParagraphs:R,changesStart:u.length,changes:T},x.select?{beforeSelection:d.anchor.paraId===d.focus.paraId&&d.anchor.offset===d.focus.offset?v({kind:"caret"},d.anchor):{kind:"text-range",anchor:d.anchor,focus:d.focus},afterSelection:{kind:"object",paraId:E.cursor.paraId,objectKind:"image",objectId:I.drawingId,offset:E.cursor.offset}}:{});u.push(...T),Y.push(B),X.length=0,g=x.select?{paraId:E.cursor.paraId,drawingId:I.drawingId}:null,H=null;let F=(te=_(a,I.paraId))==null?void 0:te.content.find(ae=>ae.kind==="image"&&ae.drawingId===I.drawingId);return (!F||F.kind!=="image"||!Jm(d,F,P))&&(At(B,R,P)||Pe(P)),bo(S[0].paraId),g&&Gt(),ne(g?{kind:"object",paraId:g.paraId,objectKind:"image",objectId:g.drawingId,offset:E.cursor.offset}:v({kind:"caret"},P)),Ie("deferred"),true},Jm=(d,m,x)=>{if(d.anchor.paraId!==d.focus.paraId)return false;let S=bs(e,d.anchor,d.focus);if(!S)return false;let E=e.querySelector(`coco-word-native-p[data-para-id="${d.anchor.paraId}"]`);return !E||!E.contains(S.commonAncestorContainer)?false:(S.deleteContents(),S.insertNode(ms(m)),lt(e,x),true)},wr=()=>{let d="";do b=b+1>>>0,d=b.toString(16).toUpperCase().padStart(8,"0");while(!d||w.has(d));return w.add(d),d},ga=(d,m=wr())=>{let x=_(a,d.paraId);if(!x)return false;let S=ue(x),E=ts(a,d.paraId,d.offset,m);if(!E)return false;let I=[d.paraId,m].map(R=>_(a,R)).filter(R=>R!==null).map(ue);if(I.length!==2)return false;let T={paraId:m,offset:0},P={source:"local",skipDeferredRender:true,range:{anchor:d,focus:d},beforeParagraphs:[S],afterParagraphs:I,changesStart:u.length,changes:[E]};return u.push(E),Y.push(P),X.length=0,H=null,g=null,At(P,I,T)?Le(d.paraId,T):Pe(T),ne(v({kind:"caret"},T)),Ie("deferred"),true},Bl=d=>{if(d.offset!==0)return false;let m=be(a,d.paraId),x=m==null?void 0:m.previous;if(!m||!x)return false;let S=[ue(x),ue(m.paragraph)],E={paraId:x.paraId,offset:Te(x).length},I=u.length,T=Nr(a,d.paraId,0),P=_(a,x.paraId);if(!T||T.kind!=="block"||!P)return false;let R={source:"local",skipDeferredRender:true,range:{anchor:d,focus:d},beforeParagraphs:S,afterParagraphs:[ue(P)],changesStart:I,changes:[T]};return u.push(T),Y.push(R),X.length=0,H=null,g=null,At(R,R.afterParagraphs,E)?Le(x.paraId,E):Pe(E),ne(v({kind:"caret"},E)),Ie("deferred"),true},Fl=d=>{let m=be(a,d.paraId);if(!m||d.offset!==Te(m.paragraph).length)return false;let x=m.container[m.index+1];if((x==null?void 0:x.kind)!=="paragraph")return false;let S=[ue(m.paragraph),ue(x)],E=u.length,I=Tr(a,d.paraId,d.offset),T=_(a,d.paraId);if(!I||I.kind!=="block"||!T)return false;let P={source:"local",skipDeferredRender:true,range:{anchor:d,focus:d},beforeParagraphs:S,afterParagraphs:[ue(T)],changesStart:E,changes:[I]};return u.push(I),Y.push(P),X.length=0,H=null,g=null,At(P,P.afterParagraphs,d)?Le(d.paraId,d):Pe(d),ne(v({kind:"caret"},d)),Ie("deferred"),true},mt=(d,m,x,S=false)=>{if(d.kind==="table-cell-range"||x.length===0||m.length===0)return false;let E=m.map(R=>_(a,R.paraId)).filter(R=>R!==null).map(ue),T={source:"local",patchMode:"individual",range:d.kind==="text-range"?et(a,d):{anchor:{paraId:d.paraId,offset:d.offset},focus:{paraId:d.paraId,offset:d.offset}},beforeParagraphs:m,afterParagraphs:E,changesStart:u.length,changes:x,beforeSelection:d,afterSelection:d};u.push(...x),Y.push(T),X.length=0,H=null,At(T,E)||Pe();let P=e.querySelector(":scope > coco-word-native-document");if(P&&mn(P),d.kind==="text-range"?hn(e,d.anchor,d.focus):d.kind==="object"?(g={paraId:d.paraId,drawingId:d.objectId},Gt()):lt(e,{paraId:d.paraId,offset:d.offset}),S){let R=d.kind==="text-range"?void 0:{paraId:d.paraId,offset:d.offset};Le(m[0].paraId,R,d);}return d.kind==="object"&&g&&Gt(),ne(d),Ie("deferred"),true},Dl=(d,m)=>{if(d.length===0)return 0;let x=Array.from(new Set(d.map(F=>F.paraId))),S=x.map(F=>_(a,F)).filter(F=>F!==null).map(ue);if(S.length===0)return 0;let E=u.length,I=[],T=[...d].sort((F,G)=>F.paraId===G.paraId?G.from-F.from:x.indexOf(G.paraId)-x.indexOf(F.paraId));for(let F of T)I.push(...Pr(a,F.paraId,F.from,F.to,m));if(I.length===0)return 0;let P=S.map(F=>_(a,F.paraId)).filter(F=>F!==null).map(ue),R=d[0],B=v({source:"local",patchMode:"individual",range:{anchor:{paraId:R.paraId,offset:R.from},focus:{paraId:R.paraId,offset:R.to}},beforeParagraphs:S,afterParagraphs:P,changesStart:E,changes:I},h?{beforeSelection:h,afterSelection:h}:{});return u.push(...I),Y.push(B),X.length=0,H=null,At(B,P)?Wt(h):Pe(void 0,h!=null?h:void 0),Le(R.paraId),Ie(),d.length},Qm=d=>{if(c)return false;let m=C&&C.activeIndex>=0?C.matches[C.activeIndex]:null;return m?Dl([m],d)>0:false},eh=d=>c?0:C?Dl(C.matches,d):0,ve=d=>{var x,S,E,I,T,P,R,B,F,G,te,ae,ge,Ne;if(l||c)return false;dt();let m=(x=h!=null?h:ze(e))!=null?x:st(e);if(d.kind==="toggle-track-revisions")return k=!k,ca(),true;if(d.kind==="accept-revision"||d.kind==="reject-revision"||d.kind==="accept-all-revisions"||d.kind==="reject-all-revisions"){let j=d.kind==="accept-revision"||d.kind==="reject-revision"?d.revisionId:void 0,q=d.kind==="accept-revision"||d.kind==="reject-revision"?d.revisionKind:void 0,J=d.kind==="accept-all-revisions"||d.kind==="reject-all-revisions",Q=new Set(Y.flatMap(ce=>Qn(ce)?ce.changes.filter(me=>me.kind==="table"&&!!(me.revisionAction&&me.revisionId)).map(me=>me.revisionId):[])),de=ce=>(ce&&J&&ve(d),ce),le=Y.filter(ce=>Qn(ce)&&ce.changes.some(me=>me.kind==="table"&&!me.revisionAction&&!!me.revisionId&&!Q.has(me.revisionId))&&ce.afterBlocks.some(me=>{var Ce,ie,Ke;if(me.kind!=="table"||((Ce=me.revision)==null?void 0:Ce.kind)!=="revision"||Q.has(me.revision.revisionId))return false;let Re=(Ke=(ie=Oe(a,me.tableId))==null?void 0:ie.table.revision)==null?void 0:Ke.revisionId;return J?!!Re:Re===me.revision.revisionId&&me.revision.revisionId===j&&(!q||me.revision.revisionKind===q)}));if(le.length>0){let ce=d.kind==="accept-revision"||d.kind==="accept-all-revisions"?"accept":"reject",me=new Map;for(let Re of le){let Ce=Re.afterBlocks.find(Ke=>{var je;return Ke.kind==="table"&&((je=Ke.revision)==null?void 0:je.kind)==="revision"});if(!Ce||Ce.kind!=="table"||!Ce.revision)continue;let ie=(S=me.get(Ce.tableId))!=null?S:[];ie.push(Re),me.set(Ce.tableId,ie);}for(let[Re,Ce]of me){let ie=Ce[Ce.length-1];if(!ie)continue;let Ke=ie.afterBlocks.find(Mo=>{var Gn;return Mo.kind==="table"&&((Gn=Mo.revision)==null?void 0:Gn.kind)==="revision"});if(!Ke||Ke.kind!=="table"||!Ke.revision)continue;let je=Oe(a,Re);if(!je)continue;let Xt=[nt([je.table])[0]],Cn=nt([je.table])[0];if(!Cn||Cn.kind!=="table")continue;ce==="accept"&&(Cn.revision=void 0,je.table.revision=void 0);let Vn=ce==="accept"?[Cn]:nt((I=(E=Ce[0])==null?void 0:E.beforeBlocks)!=null?I:ie.beforeBlocks);ce==="reject"&&je.container.splice(je.tableIndex,1,...nt(Vn));let Po=Ce.flatMap(Mo=>Mo.changes.filter(Gn=>Gn.kind==="table").map(Gn=>$(v({},Gn),{revisionAction:ce}))),Sa={source:"local",range:ie.range,container:je.container,startIndex:je.tableIndex,beforeBlocks:Xt,afterBlocks:Vn,changesStart:u.length,changes:Po,beforeSelection:m!=null?m:void 0,afterSelection:m!=null?m:void 0};u.push(...Sa.changes),Y.push(Sa),X.length=0,Lt(Sa,Vn,void 0)?Le(((T=Xt[0])==null?void 0:T.kind)==="paragraph"?Xt[0].paraId:(F=(B=(R=(P=je.table.rows[0])==null?void 0:P.cells[0])==null?void 0:R.paragraphs[0])==null?void 0:B.paraId)!=null?F:"",void 0):Pe(),Ie("deferred");}return de(true)}let K=_e(a).flatMap(ce=>{var Ce;let me=0,Re=[];for(let ie of ce.content)ie.kind==="image"&&(((Ce=ie.revision)==null?void 0:Ce.kind)==="revision"&&(J||ie.revision.revisionId===j&&(!q||ie.revision.revisionKind===q))||ie.formatRevision&&(J||ie.formatRevision.revisionId===j&&(!q||q==="format")))&&Re.push({paraId:ce.paraId,drawingId:ie.drawingId,offset:me}),me+=ie.kind==="text"?ie.text.length:1;return Re});if(K.length>0){let ce=d.kind==="accept-revision"||d.kind==="accept-all-revisions"?"accept":"reject",me=Array.from(new Set(K.map(ie=>ie.paraId))).map(ie=>_(a,ie)).filter(ie=>ie!==null).map(ue),Re=K.map(ie=>{var je;let Ke=(je=_(a,ie.paraId))==null?void 0:je.content.find(Xt=>Xt.kind==="image"&&Xt.drawingId===ie.drawingId);return (Ke==null?void 0:Ke.kind)==="image"&&Ke.formatRevision?Vc(a,ie.paraId,ie.drawingId,ce):zc(a,ie.paraId,ie.drawingId,ce)}).filter(ie=>ie!==null);if(Re.length===0)return false;let Ce=K[0];return de(mt({kind:"caret",paraId:Ce.paraId,offset:Ce.offset},me,Re,true))}let Ee=_e(a).flatMap(ce=>{let me=0,Re=[];for(let Ce of ce.content){let ie=Ce.kind==="text"?Ce.text.length:1;Ce.kind==="text"&&Ce.formatRevision&&(J||Ce.formatRevision.revisionId===j&&(!q||q==="format"))&&Re.push({paraId:ce.paraId,from:me,to:me+ie}),me+=ie;}return Re});if(Ee.length>0){let ce=d.kind==="accept-revision"||d.kind==="accept-all-revisions"?"accept":"reject",me=Array.from(new Set(Ee.map(ie=>ie.paraId))).map(ie=>_(a,ie)).filter(ie=>ie!==null).map(ue),Re=Ee.map(ie=>Dc(a,ie.paraId,ie.from,ie.to,ce)).filter(ie=>ie!==null);if(Re.length===0)return false;let Ce=Ee[0];return de(mt({kind:"caret",paraId:Ce.paraId,offset:Ce.from},me,Re,true))}let De=J?_e(a).flatMap(ce=>{var Ce;let me=[],Re=0;for(let ie of ce.content){let Ke=ie.kind==="text"?ie.text.length:1;ie.kind==="text"&&((Ce=ie.marks)!=null&&Ce.some(je=>je.kind==="revision"))&&me.push({paraId:ce.paraId,from:Re,to:Re+Ke}),Re+=Ke;}return me}):j?_e(a).flatMap(ce=>{var Ce;let me=[],Re=0;for(let ie of ce.content){let Ke=ie.kind==="text"?ie.text.length:1;ie.kind==="text"&&((Ce=ie.marks)!=null&&Ce.some(je=>je.kind==="revision"&&je.revisionId===j&&(!q||je.revisionKind===q)))&&me.push({paraId:ce.paraId,from:Re,to:Re+Ke}),Re+=Ke;}return me}):qt(m);if(De.length===0)return false;(J||j)&&De.sort((ce,me)=>ce.paraId===me.paraId?me.from-ce.from||me.to-ce.to:me.paraId.localeCompare(ce.paraId));let fe=De.map(ce=>_(a,ce.paraId)).filter(ce=>ce!==null).map(ue),Be=d.kind==="accept-revision"||d.kind==="accept-all-revisions"?"accept":"reject",se=De.map(ce=>Fc(a,ce.paraId,ce.from,ce.to,Be)).filter(ce=>ce!==null);if(se.length===0)return false;let Ze=m!=null?m:{kind:"caret",paraId:De[0].paraId,offset:De[0].from};return de(mt(Ze,fe,se,false))}if(d.kind==="insert-text"&&(m==null?void 0:m.kind)==="caret"){let j={paraId:m.paraId,offset:m.offset+d.text.length};return En({anchor:m,focus:m},m,j,()=>{var Q;let q=Qt(a,m.paraId,m.offset,d.text);if(!k||!q||d.text.length===0)return q;let J=Dt(a,m.paraId,m.offset,j.offset,{revisionId:(Q=mr(m.paraId,m.offset,"insert","before"))!=null?Q:rt(a),revisionKind:"insert",author:"User",date:new Date().toISOString()});return J?[q,J]:q})}if(d.kind==="replace-range"&&d.anchor.paraId===d.focus.paraId){let j=fi(d.anchor.offset,d.focus.offset),q={kind:"text-range",anchor:d.anchor,focus:d.focus};return k?En({anchor:d.anchor,focus:d.focus},q,{paraId:d.anchor.paraId,offset:j.to+d.text.length},()=>{let J=[],Q=Dt(a,d.anchor.paraId,j.from,j.to,{revisionId:rt(a),revisionKind:"delete",author:"User",date:new Date().toISOString()});if(Q&&J.push(Q),d.text.length>0){let de=Qt(a,d.anchor.paraId,j.to,d.text);de&&J.push(de);let le=Dt(a,d.anchor.paraId,j.to,j.to+d.text.length,{revisionId:rt(a),revisionKind:"insert",author:"User",date:new Date().toISOString()});le&&J.push(le);}return J}):En({anchor:d.anchor,focus:d.focus},q,{paraId:d.anchor.paraId,offset:j.from+d.text.length},()=>Pr(a,d.anchor.paraId,j.from,j.to,d.text))}if(d.kind==="delete-range"&&k){let j={kind:"text-range",anchor:d.anchor,focus:d.focus},q=qt(j);if(q.length===0)return false;let J=Array.from(new Map(q.map(K=>_(a,K.paraId)).filter(K=>K!==null).map(K=>[K.paraId,ue(K)])).values()),Q=rt(a),de=q.map(K=>Dt(a,K.paraId,K.from,K.to,{revisionId:Q,revisionKind:"delete",author:"User",date:new Date().toISOString()})).filter(K=>K!==null);if(de.length===0)return false;let le=mt(j,J,de,false);if(le){let K=et(a,j),Ee={paraId:K.anchor.paraId,offset:K.anchor.offset};lt(e,Ee),ne(v({kind:"caret"},Ee));}return le}if(d.kind==="delete-range"&&d.anchor.paraId===d.focus.paraId){let j={kind:"text-range",anchor:d.anchor,focus:d.focus};if(Eo(j))return true;let q=fi(d.anchor.offset,d.focus.offset);return k?En({anchor:d.anchor,focus:d.focus},j,{paraId:d.anchor.paraId,offset:q.from},()=>{var J;return Dt(a,d.anchor.paraId,q.from,q.to,{revisionId:(J=mr(d.anchor.paraId,q.from,"delete","at"))!=null?J:rt(a),revisionKind:"delete",author:"User",date:new Date().toISOString()})}):En({anchor:d.anchor,focus:d.focus},j,{paraId:d.anchor.paraId,offset:q.from},()=>un(a,d.anchor.paraId,q.from,q.to))}if(d.kind==="split-paragraph"&&(m==null?void 0:m.kind)==="caret")return ga({paraId:m.paraId,offset:m.offset});if(d.kind==="insert-page-break"&&(m==null?void 0:m.kind)==="caret")return kn(m,"insert");if(d.kind==="insert-image"&&m&&(m.kind==="caret"||m.kind==="text-range")){let j=m.kind==="text-range"?et(a,m):{anchor:{paraId:m.paraId,offset:m.offset},focus:{paraId:m.paraId,offset:m.offset}};return ha(j,d.src,$(v(v({},d.width?{width:d.width}:{}),d.height?{height:d.height}:{}),{select:true}))}if(d.kind==="set-image-size"&&(m==null?void 0:m.kind)==="object"&&m.objectKind==="image"&&m.objectId===d.objectId){let j=_(a,m.paraId);if(!j)return false;let q=ue(j),J=j.content.find(K=>K.kind==="image"&&K.drawingId===m.objectId),Q=(J==null?void 0:J.kind)==="image"?J.width:void 0,de=(J==null?void 0:J.kind)==="image"?J.height:void 0,le=Mc(a,m.paraId,m.objectId,{width:d.width,height:d.height});if(k&&le){let K=j.content.find(Ee=>Ee.kind==="image"&&Ee.drawingId===m.objectId);(K==null?void 0:K.kind)==="image"&&(K.formatRevision={kind:"format",revisionId:rt(a),beforeWidth:Q,beforeHeight:de,afterWidth:d.width,afterHeight:d.height,author:"User",date:new Date().toISOString()},le.kind==="image"&&(le.revisionId=K.formatRevision.revisionId,le.revisionKind="format"));}return mt(m,[q],le?[le]:[],true)}if(d.kind==="set-image-alignment"&&(m==null?void 0:m.kind)==="object"&&m.objectKind==="image"&&m.objectId===d.objectId)return ve({kind:"set-paragraph-alignment",alignment:d.alignment});if(m&&(d.kind==="insert-table"||d.kind==="delete-table"))return qm(m,d);if(m&&(d.kind==="insert-table-row"||d.kind==="delete-table-row"||d.kind==="insert-table-column"||d.kind==="delete-table-column"))return Km(m,d);if((m==null?void 0:m.kind)==="table-cell-range"&&(d.kind==="merge-table-cells"||d.kind==="split-table-cell"))return _m(m,d);if(m&&(d.kind==="set-table-cell-background"||d.kind==="set-table-cell-vertical-alignment"||d.kind==="set-table-cell-borders"))return Xm(m,d);if(d.kind==="clear-table-cells"&&(m==null?void 0:m.kind)==="table-cell-range")return $n(m);if(d.kind==="delete-backward"){if((m==null?void 0:m.kind)==="table-cell-range")return $n(m);if((m==null?void 0:m.kind)==="text-range")return Eo(m)?true:k?ve({kind:"delete-range",anchor:m.anchor,focus:m.focus}):zn(et(a,m),"");if((m==null?void 0:m.kind)==="object"&&m.objectKind==="image"){let j={paraId:m.paraId,offset:m.offset};return Sn(m.paraId,m.objectId,j)}if((m==null?void 0:m.kind)==="caret"){if(k&&m.offset>0){let de=m.offset-1;return En({anchor:m,focus:m},m,{paraId:m.paraId,offset:de},()=>{var le;return Dt(a,m.paraId,de,m.offset,{revisionId:(le=mr(m.paraId,de,"delete","after"))!=null?le:rt(a),revisionKind:"delete",author:"User",date:new Date().toISOString()})})}if(kn(m,"delete-backward")||Co(m,"backward")||Bl({paraId:m.paraId,offset:m.offset}))return true;let j=_(a,m.paraId),q=j?ue(j):null,J=Nr(a,m.paraId,m.offset),Q={paraId:m.offset>0?m.paraId:(G=Oa(a,m.paraId))!=null?G:m.paraId,offset:Math.max(0,m.offset-1)};return (J==null?void 0:J.kind)==="image"?br(q,J,Q):vn(J,Q,(J==null?void 0:J.kind)==="block"?{}:{localParaId:m.paraId}),true}}if(d.kind==="delete-forward"&&(m==null?void 0:m.kind)==="table-cell-range")return $n(m);if(d.kind==="delete-forward"&&(m==null?void 0:m.kind)==="text-range")return Eo(m)?true:k?ve({kind:"delete-range",anchor:m.anchor,focus:m.focus}):zn(et(a,m),"");if(d.kind==="delete-forward"&&(m==null?void 0:m.kind)==="caret"){if(k&&m.offset<ua(m.paraId))return En({anchor:m,focus:m},m,m,()=>{var de;return Dt(a,m.paraId,m.offset,m.offset+1,{revisionId:(de=mr(m.paraId,m.offset,"delete","at"))!=null?de:rt(a),revisionKind:"delete",author:"User",date:new Date().toISOString()})});if(kn(m,"delete-forward")||Co(m,"forward")||Fl({paraId:m.paraId,offset:m.offset}))return true;let j=_(a,m.paraId),q=j?ue(j):null,J=Tr(a,m.paraId,m.offset),Q={paraId:m.paraId,offset:m.offset};return (J==null?void 0:J.kind)==="image"?br(q,J,Q):vn(J,Q,{localParaId:m.paraId}),true}if(d.kind==="delete-object"&&(m==null?void 0:m.kind)==="object"){let j={paraId:m.paraId,offset:m.offset};return Sn(m.paraId,d.objectId,j)}if((d.kind==="set-hyperlink"||d.kind==="remove-hyperlink")&&(m==null?void 0:m.kind)==="text-range"){let j=qt(m),q=j.map(Q=>_(a,Q.paraId)).filter(Q=>Q!==null).map(ue),J=j.map(Q=>es(a,Q.paraId,Q.from,Q.to,d.kind==="set-hyperlink"?d.hyperlink:null)).filter(Q=>Q!==null);return mt(m,q,J,false)}if(d.kind==="add-comment"&&(m==null?void 0:m.kind)==="text-range"){let j=qt(m);if(j.length===0||!d.body.trim())return false;let q=j.map(K=>_(a,K.paraId)).filter(K=>K!==null).map(ue),J=zp(a),Q=(te=d.date)!=null?te:new Date().toISOString(),de=j.map(K=>{var Ee;return Qa(a,K.paraId,K.from,K.to,{commentId:J,author:(Ee=d.author)!=null?Ee:"User",date:Q,body:d.body.trim()})}).filter(K=>K!==null),le=mt(m,q,de,false);return le&&de.length>1&&Pe(),le}if(d.kind==="edit-comment"||d.kind==="delete-comment"){if(d.kind==="edit-comment"&&!d.body.trim())return false;let j=_e(a).filter(Q=>Q.content.some(de=>{var le;return de.kind==="text"&&((le=de.marks)==null?void 0:le.some(K=>K.kind==="comment"&&K.commentId===d.commentId))})).map(ue);if(j.length===0)return false;let q=d.kind==="edit-comment"?Wc(a,d.commentId,d.body.trim()):Bc(a,d.commentId);if(q.length===0)return false;let J=m!=null?m:{kind:"caret",paraId:j[0].paraId,offset:0};return mt(J,j,q,false)}if(d.kind==="reply-comment"){let j=d.body.trim();if(!j)return false;let q=null;for(let le of _e(a)){let K=0;for(let Ee of le.content){let De=Ee.kind==="text"?Ee.text.length:1;if(Ee.kind==="text"&&((ae=Ee.marks)!=null&&ae.some(fe=>fe.kind==="comment"&&fe.commentId===d.commentId))){q={paragraph:le,from:K,to:K+De};break}K+=De;}if(q)break}if(!q)return false;let J=ue(q.paragraph),Q=zp(a),de=Qa(a,q.paragraph.paraId,q.from,q.to,{commentId:Q,parentCommentId:d.commentId,preserveExistingComments:true,author:"User",date:new Date().toISOString(),body:j});return de?(Pe(),mt(m!=null?m:{kind:"caret",paraId:q.paragraph.paraId,offset:q.from},[J],[de],false)):false}if(d.kind==="add-revision"&&(m==null?void 0:m.kind)==="text-range"){let j=qt(m);if(j.length===0)return false;let q=j.map(le=>_(a,le.paraId)).filter(le=>le!==null).map(ue),J=rt(a),Q=(ge=d.date)!=null?ge:new Date().toISOString(),de=j.map(le=>{var K;return Dt(a,le.paraId,le.from,le.to,{revisionId:J,revisionKind:d.revisionKind,author:(K=d.author)!=null?K:"User",date:Q})}).filter(le=>le!==null);return mt(m,q,de,false)}if(d.kind==="toggle-bold"||d.kind==="toggle-italic"||d.kind==="toggle-underline"||d.kind==="toggle-strike"||d.kind==="set-font-family"||d.kind==="set-font-size"||d.kind==="set-text-color"||d.kind==="set-highlight-color"||d.kind==="clear-text-format"){let j=qt(m);if((m==null?void 0:m.kind)!=="text-range"||j.length===0)return false;let q=j.map(K=>_(a,K.paraId)).filter(K=>K!==null).map(ue),J=Ct(m),Q=null;if(d.kind==="toggle-bold"&&(Q={bold:J.bold!==true}),d.kind==="toggle-italic"&&(Q={italic:J.italic!==true}),d.kind==="toggle-underline"&&(Q={underline:J.underline!==true}),d.kind==="toggle-strike"&&(Q={strike:J.strike!==true}),d.kind==="set-font-family"&&d.fontFamily.trim()&&(Q={fontFamily:d.fontFamily.trim()}),d.kind==="set-font-size"&&(Q={fontSize:d.fontSize}),d.kind==="set-text-color"&&(Q={color:d.color.replace(/^#/,"").toUpperCase()}),d.kind==="set-highlight-color"&&(Q={highlight:d.color?d.color.replace(/^#/,"").toUpperCase():"none"}),d.kind!=="clear-text-format"&&!Q)return false;let de=j.map(K=>d.kind==="clear-text-format"?Hc(a,K.paraId,K.from,K.to):Ja(a,K.paraId,K.from,K.to,Q)).filter(K=>K!==null);if(k){let K=rt(a),Ee=j.map(De=>$c(a,De.paraId,De.from,De.to,q.find(fe=>fe.paraId===De.paraId),{revisionId:K,author:"User",date:new Date().toISOString()})).filter(De=>De!==null);de.push(...Ee);}let le=d.kind==="toggle-bold"||d.kind==="toggle-italic"||d.kind==="set-font-family"||d.kind==="set-font-size"||d.kind==="clear-text-format";return mt(m,q,de,le)}if(d.kind==="set-paragraph-alignment"||d.kind==="set-paragraph-indent"||d.kind==="adjust-paragraph-left-indent"||d.kind==="set-paragraph-spacing"||d.kind==="set-paragraph-line-spacing"){let j=Array.from(new Set(Al(m)));if(!m||j.length===0)return false;let q=j.map(Q=>_(a,Q)).filter(Q=>Q!==null).map(ue),J=j.map(Q=>{var le,K,Ee;let de=_(a,Q);if(!de)return null;if(d.kind==="set-paragraph-alignment")return Un(a,Q,{alignment:d.alignment});if(d.kind==="set-paragraph-indent")return Un(a,Q,{indent:Qy(d.indent)});if(d.kind==="adjust-paragraph-left-indent"){let De=Math.max(0,((Ee=(K=(le=de.format)==null?void 0:le.indent)==null?void 0:K.left)!=null?Ee:0)+d.delta);return Un(a,Q,{indent:{left:De}})}return d.kind==="set-paragraph-spacing"?Un(a,Q,{spacing:ev(d.spacing)}):Un(a,Q,{spacing:{line:Math.max(0,d.line),lineRule:d.lineRule}})}).filter(Q=>Q!==null);return mt(m,q,J,d.kind!=="set-paragraph-alignment")}if(d.kind==="toggle-list"||d.kind==="remove-list"||d.kind==="adjust-list-level"){let j=Array.from(new Set(Al(m)));if(!m||j.length===0)return false;let q=j.map(K=>_(a,K)).filter(K=>K!==null),J=q.map(ue),Q=d.kind==="toggle-list"&&q.every(K=>{var Ee;return ((Ee=K.format)==null?void 0:Ee.hasNumbering)&&dn(K.format.numbering)===d.listType}),de=d.kind==="toggle-list"&&!Q?(Ne=fc(a,j,d.listType))!=null?Ne:Ga(a,d.listType):null,le=q.map(K=>{var Ee,De,fe,Be,se;if(d.kind==="remove-list"||Q)return (Ee=K.format)!=null&&Ee.hasNumbering?Mr(a,K.paraId,null):null;if(d.kind==="toggle-list"&&de){let Ze=(Be=(fe=(De=K.format)==null?void 0:De.numbering)==null?void 0:fe.ilvl)!=null?Be:0;return Mr(a,K.paraId,ja(de,Ze))}if(d.kind==="adjust-list-level"){let Ze=(se=K.format)!=null&&se.hasNumbering?K.format.numbering:void 0;return Ze?Mr(a,K.paraId,ja(Ze,Ze.ilvl+d.delta)):null}return null}).filter(K=>K!==null);return Go(a),mt(m,J,le,true)}return false},Hl=d=>{var P;let m=(P=Oe(a,d.tableId))==null?void 0:P.table;if(!m)return null;let x=Math.min(d.anchor.rowIndex,d.focus.rowIndex),S=Math.max(d.anchor.rowIndex,d.focus.rowIndex),E=Math.min(d.anchor.columnIndex,d.focus.columnIndex),I=Math.max(d.anchor.columnIndex,d.focus.columnIndex),T=Array.from({length:S-x+1},()=>Array.from({length:I-E+1},()=>null));for(let{cell:R,rowIndex:B,columnIndex:F}of at(m,d)){let G=T[B-x];G&&F>=E&&F<=I&&(G[F-E]={text:R.paragraphs.map(te=>Te(te)).join(`
1531
- `),blocks:nt(R.blocks),format:th(R)});}return {version:1,cells:T}},th=d=>JSON.parse(JSON.stringify(v(v(v(v(v({},d.margin?{margin:d.margin}:{}),d.borders?{borders:d.borders}:{}),d.shading?{shading:d.shading}:{}),d.verticalAlignment?{verticalAlignment:d.verticalAlignment}:{}),d.noWrap!==void 0?{noWrap:d.noWrap}:{}))),Ol=d=>d.cells.map(m=>m.map(x=>{var S;return ((S=x==null?void 0:x.text)!=null?S:"").replace(/[\t\r\n]+/g," ")}).join(" ")).join(`
1532
- `),nh=d=>{var x,S;let m=(S=(x=d.clipboardData)==null?void 0:x.getData(Hs))!=null?S:"";if(!m)return null;try{let E=JSON.parse(m);if(E.version===1&&Array.isArray(E.cells)&&E.cells.every(I=>Array.isArray(I)&&I.every(T=>T===null||typeof T=="object"&&typeof T.text=="string"&&Array.isArray(T.blocks)&&typeof T.format=="object")))return E}catch(E){return null}return null},rh=d=>{var S,E;let m=(E=(S=d.clipboardData)==null?void 0:S.getData("text/plain"))!=null?E:"";if(!m)return [];let x=m.replace(/\r\n?/g,`
1532
+ ${(cd=n.styleText)!=null?cd:Bp}`,o.appendChild(d);let m=r.ownerDocument.createElement("div");m.className="coco-word-editor coco-word-native-editor-surface",m.setAttribute("part","surface"),o.appendChild(m),r.classList.add("coco-word-editor-host"),r.style.display="block",r.style.position="relative",r.style.minWidth="0",r.style.minHeight="0",e=m;}let i=r;e.classList.add("coco-word-native-editor-host");let s=t,a=Va(s),l=false,c=n.readOnly===true,u=[],f=[],p=0,w=new Set(_e(a).map(d=>d.paraId)),b=Date.now()>>>0,g=null,h=null,y=null,k=n.trackRevisions===true,C=null,N=false,L=null,F=null,W=null,V=null,ee=null,pe=null,re=null,we=null,he=false,xe=null,Ve=null,z=null,Z=null,H=null,Y=[],X=[],ye=new WeakSet,ke=false,De=false,Ge=false,Qe=false,wt={change:new Set,selectionChange:new Set},sn=(d,m)=>{for(let x of wt[d])x(m);},dt=()=>Jr.set(document,e),Ct=d=>$(v({},Op(a,d)),{trackRevisions:k}),pt=null,Ye=null,Vt=null,ct=null,qt=false,It=false,Rt=()=>{Vt==null||Vt.remove(),Vt=null;},ho=d=>{var I;if(!(d instanceof Element))return null;let m=d.closest("coco-word-native-table td[data-row-index][data-column-index]"),x=m==null?void 0:m.closest("coco-word-native-table[data-table-id]"),S=Number(m==null?void 0:m.dataset.rowIndex),E=Number(m==null?void 0:m.dataset.columnIndex);return !m||!x||!Number.isInteger(S)||!Number.isInteger(E)?null:{tableId:(I=x.dataset.tableId)!=null?I:"",point:{rowIndex:S,columnIndex:E},element:m}},go=d=>{for(let T of Array.from(e.querySelectorAll("td.is-cell-range-selected")))T.classList.remove("is-cell-range-selected","is-cell-range-anchor","is-cell-range-focus"),T.removeAttribute("aria-selected");if((d==null?void 0:d.kind)!=="table-cell-range")return;let m=Array.from(e.querySelectorAll("coco-word-native-table[data-table-id]")).find(T=>T.dataset.tableId===d.tableId);if(!m)return;let x=Math.min(d.anchor.rowIndex,d.focus.rowIndex),S=Math.max(d.anchor.rowIndex,d.focus.rowIndex),E=Math.min(d.anchor.columnIndex,d.focus.columnIndex),I=Math.max(d.anchor.columnIndex,d.focus.columnIndex);for(let T of Array.from(m.querySelectorAll("td[data-row-index][data-column-index]"))){let P=Number(T.dataset.rowIndex),R=Number(T.dataset.columnIndex),B=P+Math.max(1,T.rowSpan)-1,D=R+Math.max(1,T.colSpan)-1;P<=S&&B>=x&&R<=I&&D>=E&&(T.classList.add("is-cell-range-selected"),T.setAttribute("aria-selected","true"),P===d.anchor.rowIndex&&R===d.anchor.columnIndex&&T.classList.add("is-cell-range-anchor"),P===d.focus.rowIndex&&R===d.focus.columnIndex&&T.classList.add("is-cell-range-focus"));}},ra=++tv,oa=`coco-word-search-match-${ra}`,ia=`coco-word-search-active-${ra}`,aa=`coco-word-preserved-selection-${ra}`,sa=document.createElement("style");sa.textContent=`
1533
+ ::highlight(${oa}) { background-color: rgb(250 204 21 / 42%); }
1534
+ ::highlight(${ia}) { background-color: rgb(249 115 22 / 68%); color: inherit; }
1535
+ ::highlight(${aa}) { background-color: rgb(0 120 215 / 34%); color: inherit; }
1536
+ `,(o!=null?o:document.head).appendChild(sa);let ft=(ud=globalThis.CSS)==null?void 0:ud.highlights,mr=globalThis.Highlight,Il=()=>{ft==null||ft.delete(oa),ft==null||ft.delete(ia);},la=()=>{ft==null||ft.delete(aa);},ot=(d=false)=>{if(la(),(h==null?void 0:h.kind)!=="text-range"||!d&&(document.activeElement===i||e.contains(document.activeElement))||!ft||!mr)return;let m=et(a,h),x=vs(e,m.anchor,m.focus);x&&!x.collapsed&&ft.set(aa,new mr(x));},bo=()=>{if(Il(),!C||!ft||!mr)return;let d=[],m=null;C.matches.forEach((x,S)=>{let E=Gu(e,x.paraId,x.from,x.to);E&&(S===C.activeIndex?m=E:d.push(E));}),d.length>0&&ft.set(oa,new mr(...d)),m&&ft.set(ia,new mr(m));},wo=()=>C?{options:v({},C.options),matches:C.matches.map(d=>v({},d)),activeIndex:C.activeIndex}:null,$m=()=>{if(!C)return;let d=ks(a,C.options);C={options:v({},C.options),matches:d,activeIndex:d.length===0?-1:Math.min(Math.max(0,C.activeIndex),d.length-1)},bo(),ot();},Nl=()=>{let d=C&&C.activeIndex>=0?C.matches[C.activeIndex]:null,m=d?e.querySelector(`coco-word-native-p[data-para-id="${d.paraId}"]`):null;m==null||m.scrollIntoView({block:"center",inline:"nearest"});},zm=d=>{let m={query:d.query,matchCase:!!d.matchCase,wholeWord:!!d.wholeWord},x=ks(a,m);return C={options:m,matches:x,activeIndex:x.length>0?0:-1},bo(),Nl(),wo()},Vm=(d="forward")=>{if(!C||C.matches.length===0)return wo();let m=d==="backward"?-1:1;return C=$(v({},C),{activeIndex:(C.activeIndex+m+C.matches.length)%C.matches.length}),bo(),Nl(),wo()},da=()=>{C=null,Il();},$n=()=>{pt==null||pt.remove(),pt=null;},ca=()=>{if(!pt||!g)return;let d=e.querySelector(`coco-word-native-p[data-para-id="${g.paraId}"] img[data-drawing-id="${g.drawingId}"]`);if(!d){$n();return}let m=e.getBoundingClientRect(),x=d.getBoundingClientRect();pt.style.left=`${x.right-m.left+e.scrollLeft-6}px`,pt.style.top=`${x.bottom-m.top+e.scrollTop-6}px`;},Gt=()=>{if(c){$n();return}if(!g){$n();return}if(ju(e,g),!!e.querySelector(`coco-word-native-p[data-para-id="${g.paraId}"] img[data-drawing-id="${g.drawingId}"]`)){if(!(pt!=null&&pt.isConnected)){let m=document.createElement("button");m.type="button",m.className="coco-word-image-resize-handle",m.title="Resize image",m.setAttribute("aria-label","Resize image"),m.contentEditable="false",m.addEventListener("click",x=>{x.preventDefault(),x.stopPropagation();}),m.addEventListener("pointerdown",x=>{if(!g||x.button!==0)return;dt();let S=v({},g),E=e.querySelector(`coco-word-native-p[data-para-id="${S.paraId}"] img[data-drawing-id="${S.drawingId}"]`);if(!E)return;Ye==null||Ye(),x.preventDefault(),x.stopPropagation(),m.setPointerCapture(x.pointerId);let I=E.getBoundingClientRect(),T=x.clientX,P=x.clientY,R=Math.max(1,I.width),B=Math.max(1,I.height),D=R/B,G=R,te=B,ae=Ne=>{let j=Ne.clientX-T,q=Ne.clientY-P;if(Ne.shiftKey)G=Math.max(24,R+j),te=Math.max(24,B+q);else {let J=Math.abs(j)>=Math.abs(q)?j:q*D;G=Math.max(24,R+J),te=Math.max(24,G/D);}E.style.width=`${G}px`,E.style.height=`${te}px`,ca();},ge=Ne=>{Ye==null||Ye(),Ye=null,m.hasPointerCapture(Ne.pointerId)&&m.releasePointerCapture(Ne.pointerId),ve({kind:"set-image-size",objectId:S.drawingId,width:Math.round(G*100)/100,height:Math.round(te*100)/100});};document.addEventListener("pointermove",ae,true),document.addEventListener("pointerup",ge,true),document.addEventListener("pointercancel",ge,true),Ye=()=>{document.removeEventListener("pointermove",ae,true),document.removeEventListener("pointerup",ge,true),document.removeEventListener("pointercancel",ge,true);};}),e.appendChild(m),pt=m;}ca();}},xo=()=>ca();window.addEventListener("resize",xo),document.addEventListener("scroll",xo,true);let Tl=()=>{if(r.setAttribute("aria-readonly",String(c)),e.dataset.readOnly=String(c),!!c){for(let d of Array.from(e.querySelectorAll('[contenteditable="true"]')))d.contentEditable="false";$n();}},Pe=(d,m)=>{F!==null&&(window.clearTimeout(F),F=null),W!==null&&(window.clearTimeout(W),W=null),_o(a);let x=du(a);e.replaceChildren(x),uu(x,a),Tl(),fa(x);let S=(m==null?void 0:m.kind)==="table-cell-range"?m:(h==null?void 0:h.kind)==="table-cell-range"?h:null;go(S),bo(),ot(),g&&Gt(),(m==null?void 0:m.kind)==="text-range"?gn(e,m.anchor,m.focus):d&&lt(e,d);},ua=(d,m)=>{var I;let x=_(a,d);if(!x){Pe(m);return}let S=Array.from(e.querySelectorAll(`coco-word-native-p[data-para-id="${d}"]`));if(S.length===0){Pe(m);return}for(let T of S)T.replaceWith(Gr(x));Tl();let E=(I=e.querySelector(":scope > coco-word-native-document"))!=null?I:e.querySelector("coco-word-native-document");E&&hn(E),g&&Gt(),m&&lt(e,m);},Le=(d,m,x)=>{let S=e.querySelector(":scope > coco-word-native-document");if(!S)return false;let E=pu(S,a,d);fa(S);for(let I of Array.from(S.querySelectorAll(`coco-word-native-p[data-para-id="${d}"] img`)))I.complete||ye.has(I)||(ye.add(I),I.addEventListener("load",()=>{ye.delete(I),Le(d);},{once:true}));return (x==null?void 0:x.kind)==="text-range"?gn(e,x.anchor,x.focus):m&&lt(e,m),E},ln=(d,m=180,x)=>{he||we||(W!==null&&window.clearTimeout(W),W=window.setTimeout(()=>{var I;if(W=null,he||we)return;let S=(I=e.querySelector(":scope > coco-word-native-document"))!=null?I:e.querySelector("coco-word-native-document");if(!S||x&&!x(S))return;let E=(h==null?void 0:h.kind)==="object"?h:ze(e);if((E==null?void 0:E.kind)==="text-range")Le(d,void 0,E);else if((E==null?void 0:E.kind)==="object")Le(d),g={paraId:E.paraId,drawingId:E.objectId},Gt();else {let T=(E==null?void 0:E.kind)==="caret"?E:ut(e);Le(d,T!=null?T:void 0);}},m));},yo=(d,m=80)=>{var E;let x=(E=e.querySelector(":scope > coco-word-native-document"))!=null?E:e.querySelector("coco-word-native-document");if(!x)return;let S=false;for(let I of Array.from(x.querySelectorAll(`coco-word-native-p[data-para-id="${d}"] img`)))I.complete||ye.has(I)||(S=true,ye.add(I),I.addEventListener("load",()=>{ye.delete(I),ln(d,0);},{once:true}),I.addEventListener("error",()=>ye.delete(I),{once:true}));ln(d,S?800:m);},hr=d=>{var x;if((xe==null?void 0:xe.paraId)===d)return;let m=(x=e.querySelector(":scope > coco-word-native-document"))!=null?x:e.querySelector("coco-word-native-document");m&&(xe={paraId:d,measurement:ms(m,a,d)});},pa=d=>{ln(d,700,m=>{let x=xe;if(xe=null,!x||x.paraId!==d)return false;let S=ms(m,a,d);return S.overflowPx>Math.max(1,x.measurement.overflowPx+1)||!x.measurement.canBackfillPrevious&&S.canBackfillPrevious||!x.measurement.canBackfillNext&&S.canBackfillNext});},vo=new WeakMap,So=new ResizeObserver(d=>{var m,x;for(let S of d){let E=S.target;if(!(E instanceof HTMLElement))continue;let I=Math.round(S.contentRect.height),T=vo.get(E);if(vo.set(E,I),T===void 0||Math.abs(T-I)<=1)continue;let P=(m=E.querySelector("coco-word-native-p[data-para-id]"))==null?void 0:m.dataset.paraId;if(P){let R=document.activeElement;if(R&&E.contains(R)){let B=(x=R.closest("coco-word-native-p[data-para-id]"))==null?void 0:x.dataset.paraId;pa(B!=null?B:P);}else ln(P);}}}),fa=d=>{for(let m of Array.from(d.querySelectorAll("coco-word-native-table")))vo.has(m)||(vo.set(m,Math.round(m.getBoundingClientRect().height)),So.observe(m));},Ie=(d="immediate")=>{if(l)return;let m=()=>{var S;$m();let x=jp(f,u,++p);f=u.slice(),(S=n.onChange)==null||S.call(n,x),sn("change",x);};if(d==="immediate"){ee!==null&&(window.clearTimeout(ee),ee=null),m();return}ee!==null&&window.clearTimeout(ee),ee=window.setTimeout(()=>{ee=null,m();},180);},ma=()=>{l||(pe!==null&&window.clearTimeout(pe),pe=window.setTimeout(()=>{var x,S;pe=null;let d=(x=h!=null?h:ze(e))!=null?x:st(e),m={selection:d,commandState:Ct(d)};(S=n.onSelectionChange)==null||S.call(n,m),sn("selectionChange",m);},80));},Pl=d=>{z=d,Z!==null&&window.clearTimeout(Z),Z=window.setTimeout(()=>{z=null,Z=null;},1e3);},Gm=(d,m,x)=>{let S=Array.from(e.querySelectorAll(`coco-word-native-p[data-para-id="${d}"] img[data-drawing-id="${m}"]`));for(let E of S)E.remove();Et(e),x&&lt(e,x);},Sn=(d,m,x={})=>{Array.isArray(d)?u.push(...d):d&&u.push(d),d&&(X.length=0),x.localParaId?(ua(x.localParaId,m),ln(x.localParaId)):Pe(m),Ie();},ko=d=>{let m=_(a,d);return !!m&&m.content.every(x=>x.kind==="text")},ha=d=>{let m=_(a,d);return m?Te(m).length:0},gr=(d,m,x,S)=>{var P,R;let E=_(a,d);if(!E)return null;let I=S==="before"?m-1:S==="after"?m+1:m;if(I<0)return null;let T=0;for(let B of E.content){let D=B.kind==="text"?B.text.length:1;if(I>=T&&I<T+D){let G=B.kind==="text"?(P=B.marks)==null?void 0:P.find(te=>te.kind==="revision"&&te.revisionKind===x):void 0;return G&&"revisionId"in G&&(R=G.revisionId)!=null?R:null}T+=D;}return null},Ml=(d,m)=>{var x;return !k||!m||m.kind!=="text"||m.op!=="insert"&&m.op!=="replace"||m.text.length===0?null:Ft(a,d,m.offset,m.offset+m.text.length,{revisionId:(x=gr(d,m.offset,"insert","before"))!=null?x:rt(a),revisionKind:"insert",author:"User",date:new Date().toISOString()})},ga=d=>{let m=be(a,d.anchor.paraId),x=be(a,d.focus.paraId);if(!m||!x||m.container!==x.container)return null;let S=Math.min(m.index,x.index),E=Math.max(m.index,x.index),I=[];for(let T=S;T<=E;T+=1){let P=m.container[T];if((P==null?void 0:P.kind)!=="paragraph"||P.content.some(R=>R.kind!=="text"))return null;I.push(ue(P));}return I},Rl=d=>{let m=ga(d);return m&&m.length>1?m:null},jm=d=>{let m=Rl(d);return m?(re={range:d,beforeParagraphs:m,changesStart:u.length},true):false},Eo=d=>{var T;let m=d.anchor.paraId;if(d.focus.paraId!==m)return;let x=e.querySelector(`coco-word-native-p[data-para-id="${m}"]`),S=_(a,m);if(!(x!=null&&x.closest("coco-word-native-table"))||!S||((T=H==null?void 0:H.afterParagraphs[0])==null?void 0:T.paraId)===m)return;let E=ue(S),I={source:"browser",patchMode:"individual",skipDeferredRender:true,range:d,beforeParagraphs:[E],afterParagraphs:[E],changesStart:u.length,changes:[]};Y.push(I),X.length=0,H=I;},Al=d=>{if(c){d.preventDefault();return}he=true,Ve!==null&&(window.clearTimeout(Ve),Ve=null),we&&ba(),F!==null&&(window.clearTimeout(F),F=null),W!==null&&(window.clearTimeout(W),W=null),ee!==null&&(window.clearTimeout(ee),ee=null),pe!==null&&(window.clearTimeout(pe),pe=null);let m=ze(e),x=d.target instanceof Node?St(d.target):null,S=x==null?void 0:x.dataset.paraId,E=ut(e),I=S?{paraId:S,offset:(E==null?void 0:E.paraId)===S?E.offset:ha(S)}:E,T=I?_(a,I.paraId):null;if(!I||!T||T.content.some(R=>R.kind!=="text"))return;hr(I.paraId),H=null;let P=(m==null?void 0:m.kind)==="text-range"&&m.anchor.paraId===I.paraId&&m.focus.paraId===I.paraId?{anchor:v({},m.anchor),focus:v({},m.focus)}:{anchor:I,focus:I};we={paraId:I.paraId,beforeParagraph:ue(T),changesStart:u.length,range:P};},ba=()=>{var R;Ve=null;let d=we;if(we=null,!d)return;let m=_(a,d.paraId);if(!m)return;let x=e.querySelector(`coco-word-native-p[data-para-id="${d.paraId}"]`);if(!x)return;let S=Wr(a,d.paraId,(R=x.textContent)!=null?R:"");S&&u.push(S);let E=Ml(d.paraId,S);E&&u.push(E);let I=ue(m);if(JSON.stringify(I)===JSON.stringify(d.beforeParagraph)){u.splice(d.changesStart);return}let T={source:"browser",patchMode:"individual",skipDeferredRender:true,range:d.range,beforeParagraphs:[d.beforeParagraph],afterParagraphs:[I],changesStart:d.changesStart,changes:u.slice(d.changesStart)};Y.push(T),X.length=0;let P=ut(e);P&&ne(v({kind:"caret"},P)),pa(d.paraId),E&&ua(d.paraId,P!=null?P:void 0),Ie("deferred");},Ll=()=>{he=false,Ve!==null&&window.clearTimeout(Ve),Ve=window.setTimeout(ba,80);},Co=(d,m)=>{var R,B;let x=new Set([...d.beforeParagraphs,...d.afterParagraphs].map(D=>D.paraId)),S=(R=[...d.beforeParagraphs,...d.afterParagraphs].find(D=>_(a,D.paraId)))==null?void 0:R.paraId;if(!S)return false;let E=be(a,S);if(!E)return false;if(d.patchMode==="individual"){for(let D of m){let G=be(a,D.paraId);if(!G)return false;Object.assign(G.paragraph,ue(D));}return true}let I=Array.from(x).filter(D=>_(a,D));if(I.length===0||m.length===0)return false;let T=ue(m[0]);Object.assign(E.paragraph,T);for(let D of I)D!==S&&((B=be(a,D))==null||B.remove());let P=T.paraId;for(let D of m.slice(1)){let G=be(a,P);if(!G)return false;let te=ue(D);G.insertAfter(te),P=te.paraId;}return true},Um=()=>{var T;if(!re)return false;let d=re;re=null;let m=d.beforeParagraphs.map(P=>Yp(e,P.paraId)),x=m.every(P=>P!==null),S=[];if(x)for(let P=0;P<d.beforeParagraphs.length;P+=1){let R=d.beforeParagraphs[P],B=Wr(a,R.paraId,(T=m[P])!=null?T:"");B&&S.push(B);}else S.push(...Jo(a,d.range.anchor,d.range.focus));if(S.length===0)return false;u.push(...S);let E=d.beforeParagraphs.map(P=>_(a,P.paraId)).filter(P=>P!==null);if(E.length>0){let P=$(v({},d),{source:"browser",afterParagraphs:E.map(ue),changes:S});Y.push(P),H=null,X.length=0;}let I=ut(e);return I&&ne({kind:"caret",paraId:I.paraId,offset:I.offset}),Le(d.beforeParagraphs[0].paraId,I!=null?I:void 0),Ie("deferred"),true},Km=()=>{let d=Y[Y.length-1];if(!d||tr(d)||!gi(e,d.beforeParagraphs)||!Co(d,d.beforeParagraphs))return false;Y.pop(),X.push(d),u.splice(d.changesStart);let m=ut(e);return m&&ne({kind:"caret",paraId:m.paraId,offset:m.offset}),Le(d.beforeParagraphs[0].paraId,m!=null?m:void 0),Ie("deferred"),true},_m=()=>{let d=X[X.length-1];if(!d||tr(d)||!gi(e,d.afterParagraphs)||!Co(d,d.afterParagraphs))return false;X.pop(),Y.push(d),u.splice(d.changesStart),u.push(...d.changes);let m=ut(e);return m&&ne({kind:"caret",paraId:m.paraId,offset:m.offset}),Le(d.beforeParagraphs[0].paraId,m!=null?m:void 0),Ie("deferred"),true},At=(d,m,x)=>{var B,D,G;if(d.patchMode==="individual"){let te=false;for(let ge of m){let Ne=Array.from(e.querySelectorAll(`coco-word-native-p[data-para-id="${ge.paraId}"]`));for(let j of Ne)j.replaceWith(Gr(ge)),te=true;}x&&lt(e,x);let ae=e.querySelector(":scope > coco-word-native-document");return ae&&hn(ae),te}let S=new Set([...d.beforeParagraphs,...d.afterParagraphs].map(te=>te.paraId)),E=Array.from(S).flatMap(te=>Array.from(e.querySelectorAll(`coco-word-native-p[data-para-id="${te}"]`))),I=(B=d.beforeParagraphs[0])==null?void 0:B.paraId,T=(D=E.find(te=>te.dataset.paraId===I))!=null?D:E[0];if(!T)return false;let P=m.map(te=>Gr(te));T.replaceWith(...P);for(let te of E)te!==T&&te.isConnected&&te.remove();x&&lt(e,x);let R=(G=e.querySelector(":scope > coco-word-native-document"))!=null?G:e.querySelector("coco-word-native-document");return R&&hn(R),true},Wl=(d,m,x)=>(d.container.splice(d.startIndex,x,...nt(m)),true),Lt=(d,m,x,S)=>{var B,D;let E=[...d.beforeBlocks,...d.afterBlocks].flatMap(G=>ov(e,G)),I=((B=d.afterBlocks[0])==null?void 0:B.kind)==="paragraph"?d.afterBlocks[0].paraId:((D=d.beforeBlocks[0])==null?void 0:D.kind)==="paragraph"?d.beforeBlocks[0].paraId:null,T=I?e.querySelector(`coco-word-native-p[data-para-id="${I}"]`):E[0];if(!T)return false;let P=m.map(G=>Vr(G));T.replaceWith(...P);for(let G of E)G!==T&&G.isConnected&&G.remove();let R=e.querySelector(":scope > coco-word-native-document");return R&&fa(R),R&&hn(R),S?gn(e,S.anchor,S.focus):x&&lt(e,x),true},qm=d=>{let m=e.querySelector(`coco-word-native-p[data-para-id="${d.anchor.paraId}"]`),x=e.querySelector(`coco-word-native-p[data-para-id="${d.focus.paraId}"]`);return !!m&&!!x&&m.closest("coco-word-native-page")!==x.closest("coco-word-native-page")},Bl=(d,m)=>{let x=Rl(d);if(!x)return false;let S={range:d,beforeParagraphs:x,changesStart:u.length},E=Fc(a,d.anchor,d.focus,m);if(E.length===0)return false;let I=x.map(R=>_(a,R.paraId)).filter(R=>R!==null).map(ue);if(I.length===0)return false;let T=$(v({},S),{source:"local",afterParagraphs:I,changes:E}),P={paraId:d.anchor.paraId,offset:d.anchor.offset+m.length};return u.push(...E),Y.push(T),H=m.length>0?T:null,X.length=0,At(T,I,P)?Le(x[0].paraId,P):Pe(P),ne(v({kind:"caret"},P)),Ie("deferred"),true},Io=(d,m)=>{let x=Bc(a,d.anchor,d.focus,m);if(!x)return false;let S={source:"local",range:d,container:x.container,startIndex:x.startIndex,beforeBlocks:x.beforeBlocks,afterBlocks:x.afterBlocks,changesStart:u.length,changes:x.changes};if(u.push(...x.changes),Y.push(S),X.length=0,H=null,g=null,!Lt(S,x.afterBlocks,x.cursor))Pe(x.cursor);else {let E=e.querySelector(":scope > coco-word-native-document");E&&Ot(E,a,x.cursor.paraId),Le(x.cursor.paraId,x.cursor);}return ne(v({kind:"caret"},x.cursor)),Ie("deferred"),true},Xm=(d,m)=>{let x=Dc(a,d.anchor,d.focus,m);if(!x)return false;let S={source:"local",range:d,container:x.container,startIndex:x.startIndex,beforeBlocks:x.beforeBlocks,afterBlocks:x.afterBlocks,changesStart:u.length,changes:x.changes};u.push(...x.changes),Y.push(S),X.length=0,H=null,g=null;for(let E of _e(a))w.add(E.paraId);if(!Lt(S,x.afterBlocks,x.cursor))Pe(x.cursor);else {let E=e.querySelector(":scope > coco-word-native-document");E&&Ot(E,a,x.cursor.paraId),Le(x.cursor.paraId,x.cursor);}return ne(v({kind:"caret"},x.cursor)),Ie("deferred"),true},Ym=(d,m)=>{let x=d.kind==="table-cell-range"?(()=>{var Ne,j,q;let te=(Ne=Oe(a,d.tableId))==null?void 0:Ne.table,ae=te?(j=at(te,d)[0])==null?void 0:j.cell:null,ge=(q=ae==null?void 0:ae.paragraphs[0])==null?void 0:q.paraId;return ge?{paraId:ge,offset:0}:null})():d.kind==="text-range"?d.anchor:{paraId:d.paraId,offset:d.offset};if(!x)return false;let S=Qt(a,x.paraId);if(!S)return false;let E=nt([S.table])[0];if(!E||E.kind!=="table")return false;let I=m.kind==="insert-table-row"?{kind:"insert-row",position:m.position}:m.kind==="delete-table-row"?{kind:"delete-row"}:m.kind==="insert-table-column"?{kind:"insert-column",position:m.position}:{kind:"delete-column"},T=Ec(a,x.paraId,I,yr);if(!T)return false;let P=nt([S.table])[0];if(!P||P.kind!=="table")return false;let R=k?rt(a):null,B=m.kind==="insert-table-row"||m.kind==="insert-table-column"?"insert":"delete";R&&(S.table.revision={kind:"revision",id:`revision:${R}`,revisionId:R,revisionKind:B,author:"User",date:new Date().toISOString()},P.revision=v({},S.table.revision),T.change.kind==="table"&&(T.change.revisionId=R,T.change.revisionKind=B,T.change.beforeTable=E));let D=v({kind:"caret"},T.cursor),G={source:"local",range:{anchor:x,focus:x},container:S.container,startIndex:S.tableIndex,beforeBlocks:[E],afterBlocks:[P],changesStart:u.length,changes:[T.change],beforeSelection:d,afterSelection:D};if(u.push(T.change),Y.push(G),X.length=0,H=null,g=null,!Lt(G,G.afterBlocks,T.cursor))Pe(T.cursor);else {let te=e.querySelector(":scope > coco-word-native-document");te&&Ot(te,a,T.cursor.paraId),Le(T.cursor.paraId,T.cursor);}return ne(D),Ie("deferred"),true},Zm=(d,m)=>{let x=Oe(a,d.tableId);if(!x)return false;let S=nt([x.table])[0];if(!S||S.kind!=="table")return false;let I=at(x.table,d)[0],T=m.kind==="merge-table-cells"?Cc(a,d.tableId,d):I?Ic(a,d.tableId,I.rowIndex,I.columnIndex,yr):null;if(!T)return false;let P=nt([x.table])[0];if(!P||P.kind!=="table")return false;let R=k?rt(a):null,B=m.kind==="merge-table-cells"?"insert":"delete";R&&(x.table.revision={kind:"revision",id:`revision:${R}`,revisionId:R,revisionKind:B,author:"User",date:new Date().toISOString()},P.revision=v({},x.table.revision),T.change.kind==="table"&&(T.change.revisionId=R,T.change.revisionKind=B,T.change.beforeTable=S));let D={source:"local",range:{anchor:{paraId:T.cursor.paraId,offset:T.cursor.offset},focus:{paraId:T.cursor.paraId,offset:T.cursor.offset}},container:x.container,startIndex:x.tableIndex,beforeBlocks:[S],afterBlocks:[P],changesStart:u.length,changes:[T.change],beforeSelection:d,afterSelection:v({kind:"caret"},T.cursor)};if(u.push(T.change),Y.push(D),X.length=0,H=null,g=null,!Lt(D,D.afterBlocks,T.cursor))Pe(T.cursor);else {let G=e.querySelector(":scope > coco-word-native-document");G&&Ot(G,a,T.cursor.paraId),Le(T.cursor.paraId,T.cursor);}return ne(v({kind:"caret"},T.cursor)),Ie("deferred"),true},Jm=(d,m)=>{let x=d.kind==="text-range"?d.anchor:d.kind==="table-cell-range"?(()=>{var D,G;let R=(D=Oe(a,d.tableId))==null?void 0:D.table,B=R?(G=at(R,d)[0])==null?void 0:G.cell.paragraphs[0]:null;return B?{paraId:B.paraId,offset:0}:null})():{paraId:d.paraId,offset:d.offset};if(!x)return false;let S=m.kind==="insert-table"?d.kind==="caret"?Sc(a,d.paraId,d.offset,m.rows,m.columns,yr):null:(()=>{var B;let R=(B=Ct(d).table)==null?void 0:B.tableId;return R?kc(a,R,yr):null})();if(!S)return false;let E=k?rt(a):null,I=m.kind==="insert-table"?"insert":"delete";if(E){let R=S.afterBlocks.find(B=>B.kind==="table");(R==null?void 0:R.kind)==="table"&&(R.revision={kind:"revision",id:`revision:${E}`,revisionId:E,revisionKind:I,author:"User",date:new Date().toISOString()},S.changes.forEach(B=>{if(B.kind==="table"){B.revisionId=E,B.revisionKind=I;let D=S.beforeBlocks.find(G=>G.kind==="table");if((D==null?void 0:D.kind)==="table"&&(B.beforeTable=D),B.op==="insert-table"){B.anchorParaId=x.paraId,B.anchorOffset=x.offset;let G=S.afterBlocks.find(te=>te.kind==="table");(G==null?void 0:G.kind)==="table"&&(B.tableSnapshot=G);}}}));}for(let R of S.changes){if(R.kind!=="table"||R.op!=="insert-table")continue;R.anchorParaId=x.paraId,R.anchorOffset=x.offset;let B=S.afterBlocks.find(D=>D.kind==="table");(B==null?void 0:B.kind)==="table"&&(R.tableSnapshot=B);}let T=v({kind:"caret"},S.cursor),P={source:"local",range:{anchor:x,focus:d.kind==="text-range"?d.focus:x},container:S.container,startIndex:S.startIndex,beforeBlocks:S.beforeBlocks,afterBlocks:S.afterBlocks,changesStart:u.length,changes:S.changes,beforeSelection:d,afterSelection:T};u.push(...S.changes),Y.push(P),X.length=0,H=null,g=null;for(let R of _e(a))w.add(R.paraId);if(!Lt(P,P.afterBlocks,S.cursor))Pe(S.cursor);else {let R=e.querySelector(":scope > coco-word-native-document");R&&Ot(R,a,S.cursor.paraId),Le(S.cursor.paraId,S.cursor);}return ne(T),Ie("deferred"),true},Qm=(d,m)=>{var ae,ge;let x=d.kind==="table-cell-range"?Oe(a,d.tableId):null,S=d.kind==="table-cell-range"&&x?(ae=at(x.table,d)[0])==null?void 0:ae.cell:null,E=d.kind==="table-cell-range"?(ge=S==null?void 0:S.paragraphs[0])!=null&&ge.paraId?{paraId:S.paragraphs[0].paraId,offset:0}:null:d.kind==="text-range"?d.anchor:{paraId:d.paraId,offset:d.offset};if(!E)return false;let I=x!=null?x:Qt(a,E.paraId);if(!I)return false;let T=nt([I.table])[0];if(!T||T.kind!=="table")return false;let P=m.kind==="set-table-cell-background"?{backgroundColor:m.color}:m.kind==="set-table-cell-vertical-alignment"?{verticalAlignment:m.alignment}:{borderColor:m.color},R=d.kind==="table-cell-range"?Nc(a,d.tableId,d,P):Ja(a,E.paraId,P);if(!R)return false;let B=nt([I.table])[0];if(!B||B.kind!=="table")return false;let D={source:"local",range:{anchor:E,focus:E},container:I.container,startIndex:I.tableIndex,beforeBlocks:[T],afterBlocks:[B],changesStart:u.length,changes:"changes"in R?R.changes:[R.change],beforeSelection:d,afterSelection:d};u.push(...D.changes),Y.push(D),X.length=0,H=null;let G=d.kind==="caret"?d:void 0,te=d.kind==="text-range"?d:void 0;if(!Lt(D,D.afterBlocks,G,te))Pe(G,d);else {Wt(d);let Ne=e.querySelector(":scope > coco-word-native-document");Ne&&Ot(Ne,a,E.paraId),Le(E.paraId,G,te),Wt(d);}return ne(d),Ie("deferred"),true},zn=d=>{let m=Oe(a,d.tableId);if(!m)return false;let x=nt([m.table])[0];if(!x||x.kind!=="table")return false;let S=Tc(a,d.tableId,d);if(!S)return false;let E=nt([m.table])[0];if(!E||E.kind!=="table")return false;let I={source:"local",range:{anchor:S.cursor,focus:S.cursor},container:m.container,startIndex:m.tableIndex,beforeBlocks:[x],afterBlocks:[E],changesStart:u.length,changes:S.changes,beforeSelection:d,afterSelection:d};if(u.push(...S.changes),Y.push(I),X.length=0,H=null,!Lt(I,I.afterBlocks))Pe(void 0,d);else {let T=e.querySelector(":scope > coco-word-native-document");T&&Ot(T,a,S.cursor.paraId),Le(S.cursor.paraId);}return ne(d),Ie("deferred"),true},wa=(d,m)=>{var te,ae,ge;let x=Oe(a,d.tableId);if(!x)return false;let S=nt([x.table])[0];if(!S||S.kind!=="table")return false;let E={rowIndex:Math.min(d.anchor.rowIndex,d.focus.rowIndex),columnIndex:Math.min(d.anchor.columnIndex,d.focus.columnIndex)},I=(ae=(te=m.content)!=null?te:m.text)!=null?ae:[],T=m.content?Mc(a,d.tableId,E,m.content):Pc(a,d.tableId,E,(ge=m.text)!=null?ge:[]);if(!T)return false;let P=nt([x.table])[0];if(!P||P.kind!=="table")return false;let R=I.length,B=Math.max(1,...I.map(Ne=>Ne.length)),D={kind:"table-cell-range",tableId:d.tableId,anchor:E,focus:{rowIndex:Math.min(x.table.rows.length-1,E.rowIndex+R-1),columnIndex:E.columnIndex+B-1}},G={source:"local",range:{anchor:T.cursor,focus:T.cursor},container:x.container,startIndex:x.tableIndex,beforeBlocks:[S],afterBlocks:[P],changesStart:u.length,changes:T.changes,beforeSelection:d,afterSelection:D};if(u.push(...T.changes),Y.push(G),X.length=0,H=null,!Lt(G,G.afterBlocks))Pe(void 0,D);else {let Ne=e.querySelector(":scope > coco-word-native-document");Ne&&Ot(Ne,a,T.cursor.paraId),Le(T.cursor.paraId);}return ne(D),Ie("deferred"),true},Wt=d=>{if(d){if(d.kind==="text-range"){gn(e,d.anchor,d.focus);return}if(d.kind==="object"){g={paraId:d.paraId,drawingId:d.objectId},Gt();return}if(d.kind==="table-cell-range"){go(d);return}lt(e,d);}},eh=()=>{var S;let d=Y[Y.length-1];if(!d)return false;if(tr(d)){let E=(S=d.beforeSelection)!=null?S:{kind:"text-range",anchor:d.range.anchor,focus:d.range.focus},I=E.kind==="caret"?E:void 0,T=E.kind==="text-range"?E:void 0;if(!Wl(d,d.beforeBlocks,d.afterBlocks.length));Lt(d,d.beforeBlocks,I,T)||Pe(I,E),Wt(E),Y.pop(),X.push(d),H=null,u.splice(d.changesStart),ne(E);let P=e.querySelector(":scope > coco-word-native-document");P&&Ot(P,a,d.range.anchor.paraId);let R=E.kind==="text-range"?E.anchor.paraId:E.kind==="table-cell-range"?d.range.anchor.paraId:E.paraId;return Le(R,I,T),Ie("deferred"),true}if(d.source==="browser"&&!d.skipDeferredRender&&!gi(e,d.afterParagraphs))return false;let m={paraId:d.beforeParagraphs[0].paraId,offset:d.range.anchor.offset};if(!Co(d,d.beforeParagraphs))return false;let x=Kp(d,"before");if(d.forceFullRender){Y.pop(),X.push(d),H=null,u.splice(d.changesStart);let E=x!=null?x:v({kind:"caret"},m);return ne(E),Pe(E.kind==="caret"?E:void 0,E),Wt(E),Ie("deferred"),true}if(!At(d,d.beforeParagraphs,x?void 0:m))return false;if(Wt(x),Y.pop(),X.push(d),H=null,u.splice(d.changesStart),ne(x!=null?x:v({kind:"caret"},m)),_p(d)||d.skipDeferredRender){let E=d.beforeParagraphs[0].paraId;d.deferLayoutReflow?yo(E):Le(E,x?void 0:m,(x==null?void 0:x.kind)==="text-range"?x:void 0),Wt(x),d.deferLayoutReflow||ln(E);}return Ie("deferred"),true},th=()=>{var S;let d=X[X.length-1];if(!d)return false;if(tr(d)){let E=(S=d.afterSelection)!=null?S:{kind:"caret",paraId:d.afterBlocks[0].kind==="paragraph"?d.afterBlocks[0].paraId:d.range.anchor.paraId,offset:d.range.anchor.offset},I=E.kind==="caret"?E:void 0,T=E.kind==="text-range"?E:void 0;if(!Wl(d,d.afterBlocks,d.beforeBlocks.length));Lt(d,d.afterBlocks,I,T)||Pe(I,E),Wt(E),X.pop(),Y.push(d),H=null,u.splice(d.changesStart),u.push(...d.changes),ne(E);let P=E.kind==="text-range"?E.anchor.paraId:E.kind==="table-cell-range"?d.range.anchor.paraId:E.paraId,R=e.querySelector(":scope > coco-word-native-document");return R&&Ot(R,a,P),Le(P,I,T),Ie("deferred"),true}if(d.source==="browser"&&!d.skipDeferredRender&&!gi(e,d.beforeParagraphs))return false;let m={paraId:d.afterParagraphs[0].paraId,offset:d.range.anchor.offset};if(!Co(d,d.afterParagraphs))return false;let x=Kp(d,"after");if(d.forceFullRender){X.pop(),Y.push(d),H=null,u.splice(d.changesStart),u.push(...d.changes);let E=x!=null?x:v({kind:"caret"},m);return ne(E),Pe(E.kind==="caret"?E:void 0,E),Wt(E),Ie("deferred"),true}if(!At(d,d.afterParagraphs,x?void 0:m))return false;if(Wt(x),X.pop(),Y.push(d),H=null,u.splice(d.changesStart),u.push(...d.changes),ne(x!=null?x:v({kind:"caret"},m)),_p(d)||d.skipDeferredRender){let E=d.beforeParagraphs[0].paraId;d.deferLayoutReflow?yo(E):Le(E,x?void 0:m,(x==null?void 0:x.kind)==="text-range"?x:void 0),Wt(x),d.deferLayoutReflow||ln(E);}return Ie("deferred"),true},br=()=>l||c||Y.length===0?false:(dt(),eh()),wr=()=>l||c||X.length===0?false:(dt(),th()),ne=d=>{if(d&&dt(),(d==null?void 0:d.kind)!=="object"&&$n(),go(d),iv(h,d)){ot();return}h=d,ot(),ma();},xr=(d,m,x)=>{if(!d||(m==null?void 0:m.kind)!=="image")return false;let S=_(a,m.paraId);if(!S)return false;let E={source:"local",patchMode:"individual",deferLayoutReflow:true,range:{anchor:x,focus:x},beforeParagraphs:[d],afterParagraphs:[ue(S)],changesStart:u.length,changes:[m],beforeSelection:{kind:"object",paraId:m.paraId,objectKind:"image",objectId:m.drawingId,offset:m.offset},afterSelection:v({kind:"caret"},x)};return u.push(m),Y.push(E),X.length=0,H=null,Gm(m.paraId,m.drawingId,x),yo(m.paraId),g=null,ne(v({kind:"caret"},x)),Ie("deferred"),true},kn=(d,m,x)=>{let S=_(a,d),E=S==null?void 0:S.content.find(T=>T.kind==="image"&&T.drawingId===m);if(k&&S&&(E==null?void 0:E.kind)==="image"){let T=ue(S),P=rt(a);return E.revision={kind:"revision",id:`revision:${P}`,revisionId:P,revisionKind:"delete",author:"User",date:new Date().toISOString()},mt({kind:"object",paraId:d,objectKind:"image",objectId:m,offset:x.offset},[T],[{kind:"image",op:"delete",paraId:d,offset:x.offset,drawingId:m,revisionId:P,revisionKind:"delete"}],true)}let I=S?ue(S):null;return xr(I,Gc(a,d,m),x)},En=(d,m,x=v({kind:"caret"},d),S)=>{let E=_(a,d.paraId);if(!E)return false;let I=m==="delete-backward"?d.offset-1:d.offset;if(m!=="insert"&&!Zo(a,d.paraId,I))return false;let T=ue(E),P=m==="insert"?Ac(a,d.paraId,d.offset):m==="delete-backward"?Mr(a,d.paraId,d.offset):Rr(a,d.paraId,d.offset),R=_(a,d.paraId);if(!P||P.kind!=="page-break"||!R)return false;let B={paraId:d.paraId,offset:m==="insert"?d.offset+1:m==="delete-backward"?Math.max(0,d.offset-1):d.offset},D=S!=null?S:v({kind:"caret"},B),G=D.kind==="caret"?D:B,te={source:"local",patchMode:"individual",forceFullRender:true,range:{anchor:d,focus:d},beforeParagraphs:[T],afterParagraphs:[ue(R)],changesStart:u.length,changes:[P],beforeSelection:x,afterSelection:D};return u.push(P),Y.push(te),X.length=0,H=null,g=null,Pe(G,D),ne(D),Ie("deferred"),true},No=d=>{if(d.anchor.paraId!==d.focus.paraId)return false;let m=bi(d.anchor.offset,d.focus.offset);if(!Lc(a,d.anchor.paraId,m.from,m.to))return false;let x=_(a,d.anchor.paraId);if(!x)return false;let S=ue(x),E=pn(a,d.anchor.paraId,m.from,m.to),I=_(a,d.anchor.paraId);if(!I||!E.some(R=>R.kind==="page-break"))return false;let T={kind:"caret",paraId:d.anchor.paraId,offset:m.from},P={source:"local",patchMode:"individual",forceFullRender:true,range:{anchor:d.anchor,focus:d.focus},beforeParagraphs:[S],afterParagraphs:[ue(I)],changesStart:u.length,changes:E,beforeSelection:d,afterSelection:T};return u.push(...E),Y.push(P),X.length=0,H=null,Pe(T,T),ne(T),Ie("deferred"),true},To=(d,m)=>{let x=be(a,d.paraId);if(!x)return false;if(m==="backward"&&d.offset===0&&x.previous){let I=Te(x.previous).length;return Zo(a,x.previous.paraId,I-1)?En({paraId:x.previous.paraId,offset:I},"delete-backward",d,d):false}let S=x.container[x.index+1],E=(S==null?void 0:S.kind)==="paragraph"?S:null;return m==="forward"&&d.offset===Te(x.paragraph).length&&E&&Zo(a,E.paraId,0)?En({paraId:E.paraId,offset:0},"delete-forward",d,d):false},Cn=(d,m,x,S)=>{if(d.anchor.paraId!==d.focus.paraId)return false;let E=_(a,d.anchor.paraId);if(!E)return false;let I=ue(E),T=S(),P=Array.isArray(T)?T:T?[T]:[],R=_(a,d.anchor.paraId);if(P.length===0||!R)return false;let B=v({kind:"caret"},x),D={source:"local",patchMode:"individual",range:d,beforeParagraphs:[I],afterParagraphs:[ue(R)],changesStart:u.length,changes:P,beforeSelection:m,afterSelection:B};return u.push(...P),Y.push(D),X.length=0,H=null,At(D,D.afterParagraphs,x)?Le(d.anchor.paraId,x):Pe(x),ne(B),Ie("deferred"),true},Xt=d=>{if((d==null?void 0:d.kind)!=="text-range")return [];let m=et(a,d);if(m.anchor.paraId===m.focus.paraId)return [{paraId:m.anchor.paraId,from:m.anchor.offset,to:m.focus.offset}];let x=be(a,m.anchor.paraId),S=be(a,m.focus.paraId);if(!x||!S||x.container!==S.container)return [];let E=[];for(let I=x.index;I<=S.index;I+=1){let T=x.container[I];if((T==null?void 0:T.kind)!=="paragraph")return [];E.push({paraId:T.paraId,from:I===x.index?m.anchor.offset:0,to:I===S.index?m.focus.offset:Te(T).length});}return E},Dl=d=>d?d.kind==="caret"||d.kind==="object"?[d.paraId]:Xt(d).map(m=>m.paraId):[],Fl=d=>{if((d==null?void 0:d.kind)!=="text-range")return null;let m=Xt(d);return m.length===0?null:m.map(x=>Te(_(a,x.paraId)).slice(x.from,x.to)).join(`
1537
+ `)},Hl=d=>Xt(d).map(m=>{var P;let x=_(a,m.paraId),S=Te(x).slice(m.from,m.to),E=[],I=0;for(let R of x.content){let B=sv(R),D=I+B.length,G=Math.max(m.from,I),te=Math.min(m.to,D),ae=R.kind==="text"||R.kind==="field"?R.format:null,ge=R.kind==="text"?R.hyperlink:void 0;(ae||ge)&&te>G&&E.push(v({from:G-m.from,to:te-m.from,format:v({},ae!=null?ae:{})},ge?{hyperlink:v({},ge)}:{})),I=D;}let T=(P=x.format)!=null&&P.hasNumbering&&x.format.numbering?cn(x.format.numbering):null;return v({text:S,runs:E},T?{listType:T}:{})}),Vn=(d,m,x)=>{var R;if(k&&!x&&d.anchor.paraId===d.focus.paraId)return ve({kind:"replace-range",anchor:d.anchor,focus:d.focus,text:m});if(Io(d,m))return true;let S=ga(d);if(!S)return false;let E=ts(a,d.anchor,d.focus,m);if(!E||E.changes.length===0)return false;for(let B of E.paragraphIds)w.add(B);let I=null;for(let B=0;B<((R=x==null?void 0:x.length)!=null?R:0);B+=1){let D=x[B],G=E.paragraphIds[B];if(!G)break;let te=B===0?d.anchor.offset:0;for(let ae of D.runs){if(Object.keys(ae.format).length>0){let ge=ns(a,G,te+ae.from,te+ae.to,ae.format);ge&&E.changes.push(ge);}if(ae.hyperlink){let ge=os(a,G,te+ae.from,te+ae.to,ae.hyperlink);ge&&E.changes.push(ge);}}if(D.listType){(!I||I.type!==D.listType)&&(I={type:D.listType,numbering:_a(a,D.listType)});let ae=Lr(a,G,I.numbering);ae&&E.changes.push(ae);}else I=null;}if(k){let B=rt(a),D=E.changes.filter(G=>G.kind==="text"&&(G.op==="insert"||G.op==="replace")&&G.text.length>0).map(G=>Ft(a,G.paraId,G.offset,G.offset+G.text.length,{revisionId:B,revisionKind:"insert",author:"User",date:new Date().toISOString()})).filter(G=>G!==null);E.changes.push(...D);}_o(a);let T=E.paragraphIds.map(B=>_(a,B)).filter(B=>B!==null).map(ue),P={source:"local",range:d,beforeParagraphs:S,afterParagraphs:T,changesStart:u.length,changes:E.changes};return u.push(...E.changes),Y.push(P),X.length=0,H=null,g=null,At(P,T,E.cursor)?Le(S[0].paraId,E.cursor):Pe(E.cursor),ne(v({kind:"caret"},E.cursor)),Ie("deferred"),true},xa=(d,m,x={})=>{var G,te;let S=ga(d);if(!S)return false;let E=ts(a,d.anchor,d.focus,"");if(!E)return false;for(let ae of E.paragraphIds)w.add(ae);let I=Rc(a,E.cursor.paraId,E.cursor.offset,m,x);if(!I||I.kind!=="image")return false;let T=[...E.changes,I];if(k){let ae=rt(a),ge=(G=_(a,I.paraId))==null?void 0:G.content.find(Ne=>Ne.kind==="image"&&Ne.drawingId===I.drawingId);(ge==null?void 0:ge.kind)==="image"&&(ge.revision={kind:"revision",id:`revision:${ae}`,revisionId:ae,revisionKind:"insert",author:"User",date:new Date().toISOString()},T.push({kind:"image",op:"insert",paraId:I.paraId,offset:I.offset,drawingId:I.drawingId,revisionId:ae,revisionKind:"insert"}));}let P={paraId:E.cursor.paraId,offset:E.cursor.offset+1},R=E.paragraphIds.map(ae=>_(a,ae)).filter(ae=>ae!==null).map(ue),B=v({source:"local",patchMode:"individual",deferLayoutReflow:true,range:d,beforeParagraphs:S,afterParagraphs:R,changesStart:u.length,changes:T},x.select?{beforeSelection:d.anchor.paraId===d.focus.paraId&&d.anchor.offset===d.focus.offset?v({kind:"caret"},d.anchor):{kind:"text-range",anchor:d.anchor,focus:d.focus},afterSelection:{kind:"object",paraId:E.cursor.paraId,objectKind:"image",objectId:I.drawingId,offset:E.cursor.offset}}:{});u.push(...T),Y.push(B),X.length=0,g=x.select?{paraId:E.cursor.paraId,drawingId:I.drawingId}:null,H=null;let D=(te=_(a,I.paraId))==null?void 0:te.content.find(ae=>ae.kind==="image"&&ae.drawingId===I.drawingId);return (!D||D.kind!=="image"||!nh(d,D,P))&&(At(B,R,P)||Pe(P)),yo(S[0].paraId),g&&Gt(),ne(g?{kind:"object",paraId:g.paraId,objectKind:"image",objectId:g.drawingId,offset:E.cursor.offset}:v({kind:"caret"},P)),Ie("deferred"),true},nh=(d,m,x)=>{if(d.anchor.paraId!==d.focus.paraId)return false;let S=vs(e,d.anchor,d.focus);if(!S)return false;let E=e.querySelector(`coco-word-native-p[data-para-id="${d.anchor.paraId}"]`);return !E||!E.contains(S.commonAncestorContainer)?false:(S.deleteContents(),S.insertNode(ws(m)),lt(e,x),true)},yr=()=>{let d="";do b=b+1>>>0,d=b.toString(16).toUpperCase().padStart(8,"0");while(!d||w.has(d));return w.add(d),d},ya=(d,m=yr())=>{let x=_(a,d.paraId);if(!x)return false;let S=ue(x),E=is(a,d.paraId,d.offset,m);if(!E)return false;let I=[d.paraId,m].map(R=>_(a,R)).filter(R=>R!==null).map(ue);if(I.length!==2)return false;let T={paraId:m,offset:0},P={source:"local",skipDeferredRender:true,range:{anchor:d,focus:d},beforeParagraphs:[S],afterParagraphs:I,changesStart:u.length,changes:[E]};return u.push(E),Y.push(P),X.length=0,H=null,g=null,At(P,I,T)?Le(d.paraId,T):Pe(T),ne(v({kind:"caret"},T)),Ie("deferred"),true},Ol=d=>{if(d.offset!==0)return false;let m=be(a,d.paraId),x=m==null?void 0:m.previous;if(!m||!x)return false;let S=[ue(x),ue(m.paragraph)],E={paraId:x.paraId,offset:Te(x).length},I=u.length,T=Mr(a,d.paraId,0),P=_(a,x.paraId);if(!T||T.kind!=="block"||!P)return false;let R={source:"local",skipDeferredRender:true,range:{anchor:d,focus:d},beforeParagraphs:S,afterParagraphs:[ue(P)],changesStart:I,changes:[T]};return u.push(T),Y.push(R),X.length=0,H=null,g=null,At(R,R.afterParagraphs,E)?Le(x.paraId,E):Pe(E),ne(v({kind:"caret"},E)),Ie("deferred"),true},$l=d=>{let m=be(a,d.paraId);if(!m||d.offset!==Te(m.paragraph).length)return false;let x=m.container[m.index+1];if((x==null?void 0:x.kind)!=="paragraph")return false;let S=[ue(m.paragraph),ue(x)],E=u.length,I=Rr(a,d.paraId,d.offset),T=_(a,d.paraId);if(!I||I.kind!=="block"||!T)return false;let P={source:"local",skipDeferredRender:true,range:{anchor:d,focus:d},beforeParagraphs:S,afterParagraphs:[ue(T)],changesStart:E,changes:[I]};return u.push(I),Y.push(P),X.length=0,H=null,g=null,At(P,P.afterParagraphs,d)?Le(d.paraId,d):Pe(d),ne(v({kind:"caret"},d)),Ie("deferred"),true},mt=(d,m,x,S=false)=>{if(d.kind==="table-cell-range"||x.length===0||m.length===0)return false;let E=m.map(R=>_(a,R.paraId)).filter(R=>R!==null).map(ue),T={source:"local",patchMode:"individual",range:d.kind==="text-range"?et(a,d):{anchor:{paraId:d.paraId,offset:d.offset},focus:{paraId:d.paraId,offset:d.offset}},beforeParagraphs:m,afterParagraphs:E,changesStart:u.length,changes:x,beforeSelection:d,afterSelection:d};u.push(...x),Y.push(T),X.length=0,H=null,At(T,E)||Pe();let P=e.querySelector(":scope > coco-word-native-document");if(P&&hn(P),d.kind==="text-range"?gn(e,d.anchor,d.focus):d.kind==="object"?(g={paraId:d.paraId,drawingId:d.objectId},Gt()):lt(e,{paraId:d.paraId,offset:d.offset}),S){let R=d.kind==="text-range"?void 0:{paraId:d.paraId,offset:d.offset};Le(m[0].paraId,R,d);}return d.kind==="object"&&g&&Gt(),ne(d),Ie("deferred"),true},zl=(d,m)=>{if(d.length===0)return 0;let x=Array.from(new Set(d.map(D=>D.paraId))),S=x.map(D=>_(a,D)).filter(D=>D!==null).map(ue);if(S.length===0)return 0;let E=u.length,I=[],T=[...d].sort((D,G)=>D.paraId===G.paraId?G.from-D.from:x.indexOf(G.paraId)-x.indexOf(D.paraId));for(let D of T)I.push(...Ar(a,D.paraId,D.from,D.to,m));if(I.length===0)return 0;let P=S.map(D=>_(a,D.paraId)).filter(D=>D!==null).map(ue),R=d[0],B=v({source:"local",patchMode:"individual",range:{anchor:{paraId:R.paraId,offset:R.from},focus:{paraId:R.paraId,offset:R.to}},beforeParagraphs:S,afterParagraphs:P,changesStart:E,changes:I},h?{beforeSelection:h,afterSelection:h}:{});return u.push(...I),Y.push(B),X.length=0,H=null,At(B,P)?Wt(h):Pe(void 0,h!=null?h:void 0),Le(R.paraId),Ie(),d.length},rh=d=>{if(c)return false;let m=C&&C.activeIndex>=0?C.matches[C.activeIndex]:null;return m?zl([m],d)>0:false},oh=d=>c?0:C?zl(C.matches,d):0,ve=d=>{var x,S,E,I,T,P,R,B,D,G,te,ae,ge,Ne;if(l||c)return false;dt();let m=(x=h!=null?h:ze(e))!=null?x:st(e);if(d.kind==="toggle-track-revisions")return k=!k,ma(),true;if(d.kind==="accept-revision"||d.kind==="reject-revision"||d.kind==="accept-all-revisions"||d.kind==="reject-all-revisions"){let j=d.kind==="accept-revision"||d.kind==="reject-revision"?d.revisionId:void 0,q=d.kind==="accept-revision"||d.kind==="reject-revision"?d.revisionKind:void 0,J=d.kind==="accept-all-revisions"||d.kind==="reject-all-revisions",Q=new Set(Y.flatMap(ce=>tr(ce)?ce.changes.filter(me=>me.kind==="table"&&!!(me.revisionAction&&me.revisionId)).map(me=>me.revisionId):[])),de=ce=>(ce&&J&&ve(d),ce),le=Y.filter(ce=>tr(ce)&&ce.changes.some(me=>me.kind==="table"&&!me.revisionAction&&!!me.revisionId&&!Q.has(me.revisionId))&&ce.afterBlocks.some(me=>{var Ce,ie,Ke;if(me.kind!=="table"||((Ce=me.revision)==null?void 0:Ce.kind)!=="revision"||Q.has(me.revision.revisionId))return false;let Re=(Ke=(ie=Oe(a,me.tableId))==null?void 0:ie.table.revision)==null?void 0:Ke.revisionId;return J?!!Re:Re===me.revision.revisionId&&me.revision.revisionId===j&&(!q||me.revision.revisionKind===q)}));if(le.length>0){let ce=d.kind==="accept-revision"||d.kind==="accept-all-revisions"?"accept":"reject",me=new Map;for(let Re of le){let Ce=Re.afterBlocks.find(Ke=>{var je;return Ke.kind==="table"&&((je=Ke.revision)==null?void 0:je.kind)==="revision"});if(!Ce||Ce.kind!=="table"||!Ce.revision)continue;let ie=(S=me.get(Ce.tableId))!=null?S:[];ie.push(Re),me.set(Ce.tableId,ie);}for(let[Re,Ce]of me){let ie=Ce[Ce.length-1];if(!ie)continue;let Ke=ie.afterBlocks.find(Lo=>{var jn;return Lo.kind==="table"&&((jn=Lo.revision)==null?void 0:jn.kind)==="revision"});if(!Ke||Ke.kind!=="table"||!Ke.revision)continue;let je=Oe(a,Re);if(!je)continue;let Yt=[nt([je.table])[0]],In=nt([je.table])[0];if(!In||In.kind!=="table")continue;ce==="accept"&&(In.revision=void 0,je.table.revision=void 0);let Gn=ce==="accept"?[In]:nt((I=(E=Ce[0])==null?void 0:E.beforeBlocks)!=null?I:ie.beforeBlocks);ce==="reject"&&je.container.splice(je.tableIndex,1,...nt(Gn));let Ao=Ce.flatMap(Lo=>Lo.changes.filter(jn=>jn.kind==="table").map(jn=>$(v({},jn),{revisionAction:ce}))),Ia={source:"local",range:ie.range,container:je.container,startIndex:je.tableIndex,beforeBlocks:Yt,afterBlocks:Gn,changesStart:u.length,changes:Ao,beforeSelection:m!=null?m:void 0,afterSelection:m!=null?m:void 0};u.push(...Ia.changes),Y.push(Ia),X.length=0,Lt(Ia,Gn,void 0)?Le(((T=Yt[0])==null?void 0:T.kind)==="paragraph"?Yt[0].paraId:(D=(B=(R=(P=je.table.rows[0])==null?void 0:P.cells[0])==null?void 0:R.paragraphs[0])==null?void 0:B.paraId)!=null?D:"",void 0):Pe(),Ie("deferred");}return de(true)}let K=_e(a).flatMap(ce=>{var Ce;let me=0,Re=[];for(let ie of ce.content)ie.kind==="image"&&(((Ce=ie.revision)==null?void 0:Ce.kind)==="revision"&&(J||ie.revision.revisionId===j&&(!q||ie.revision.revisionKind===q))||ie.formatRevision&&(J||ie.formatRevision.revisionId===j&&(!q||q==="format")))&&Re.push({paraId:ce.paraId,drawingId:ie.drawingId,offset:me}),me+=ie.kind==="text"?ie.text.length:1;return Re});if(K.length>0){let ce=d.kind==="accept-revision"||d.kind==="accept-all-revisions"?"accept":"reject",me=Array.from(new Set(K.map(ie=>ie.paraId))).map(ie=>_(a,ie)).filter(ie=>ie!==null).map(ue),Re=K.map(ie=>{var je;let Ke=(je=_(a,ie.paraId))==null?void 0:je.content.find(Yt=>Yt.kind==="image"&&Yt.drawingId===ie.drawingId);return (Ke==null?void 0:Ke.kind)==="image"&&Ke.formatRevision?Kc(a,ie.paraId,ie.drawingId,ce):Uc(a,ie.paraId,ie.drawingId,ce)}).filter(ie=>ie!==null);if(Re.length===0)return false;let Ce=K[0];return de(mt({kind:"caret",paraId:Ce.paraId,offset:Ce.offset},me,Re,true))}let Ee=_e(a).flatMap(ce=>{let me=0,Re=[];for(let Ce of ce.content){let ie=Ce.kind==="text"?Ce.text.length:1;Ce.kind==="text"&&Ce.formatRevision&&(J||Ce.formatRevision.revisionId===j&&(!q||q==="format"))&&Re.push({paraId:ce.paraId,from:me,to:me+ie}),me+=ie;}return Re});if(Ee.length>0){let ce=d.kind==="accept-revision"||d.kind==="accept-all-revisions"?"accept":"reject",me=Array.from(new Set(Ee.map(ie=>ie.paraId))).map(ie=>_(a,ie)).filter(ie=>ie!==null).map(ue),Re=Ee.map(ie=>zc(a,ie.paraId,ie.from,ie.to,ce)).filter(ie=>ie!==null);if(Re.length===0)return false;let Ce=Ee[0];return de(mt({kind:"caret",paraId:Ce.paraId,offset:Ce.from},me,Re,true))}let Fe=J?_e(a).flatMap(ce=>{var Ce;let me=[],Re=0;for(let ie of ce.content){let Ke=ie.kind==="text"?ie.text.length:1;ie.kind==="text"&&((Ce=ie.marks)!=null&&Ce.some(je=>je.kind==="revision"))&&me.push({paraId:ce.paraId,from:Re,to:Re+Ke}),Re+=Ke;}return me}):j?_e(a).flatMap(ce=>{var Ce;let me=[],Re=0;for(let ie of ce.content){let Ke=ie.kind==="text"?ie.text.length:1;ie.kind==="text"&&((Ce=ie.marks)!=null&&Ce.some(je=>je.kind==="revision"&&je.revisionId===j&&(!q||je.revisionKind===q)))&&me.push({paraId:ce.paraId,from:Re,to:Re+Ke}),Re+=Ke;}return me}):Xt(m);if(Fe.length===0)return false;(J||j)&&Fe.sort((ce,me)=>ce.paraId===me.paraId?me.from-ce.from||me.to-ce.to:me.paraId.localeCompare(ce.paraId));let fe=Fe.map(ce=>_(a,ce.paraId)).filter(ce=>ce!==null).map(ue),Be=d.kind==="accept-revision"||d.kind==="accept-all-revisions"?"accept":"reject",se=Fe.map(ce=>$c(a,ce.paraId,ce.from,ce.to,Be)).filter(ce=>ce!==null);if(se.length===0)return false;let Ze=m!=null?m:{kind:"caret",paraId:Fe[0].paraId,offset:Fe[0].from};return de(mt(Ze,fe,se,false))}if(d.kind==="insert-text"&&(m==null?void 0:m.kind)==="caret"){let j={paraId:m.paraId,offset:m.offset+d.text.length};return Cn({anchor:m,focus:m},m,j,()=>{var Q;let q=en(a,m.paraId,m.offset,d.text);if(!k||!q||d.text.length===0)return q;let J=Ft(a,m.paraId,m.offset,j.offset,{revisionId:(Q=gr(m.paraId,m.offset,"insert","before"))!=null?Q:rt(a),revisionKind:"insert",author:"User",date:new Date().toISOString()});return J?[q,J]:q})}if(d.kind==="replace-range"&&d.anchor.paraId===d.focus.paraId){let j=bi(d.anchor.offset,d.focus.offset),q={kind:"text-range",anchor:d.anchor,focus:d.focus};return k?Cn({anchor:d.anchor,focus:d.focus},q,{paraId:d.anchor.paraId,offset:j.to+d.text.length},()=>{let J=[],Q=Ft(a,d.anchor.paraId,j.from,j.to,{revisionId:rt(a),revisionKind:"delete",author:"User",date:new Date().toISOString()});if(Q&&J.push(Q),d.text.length>0){let de=en(a,d.anchor.paraId,j.to,d.text);de&&J.push(de);let le=Ft(a,d.anchor.paraId,j.to,j.to+d.text.length,{revisionId:rt(a),revisionKind:"insert",author:"User",date:new Date().toISOString()});le&&J.push(le);}return J}):Cn({anchor:d.anchor,focus:d.focus},q,{paraId:d.anchor.paraId,offset:j.from+d.text.length},()=>Ar(a,d.anchor.paraId,j.from,j.to,d.text))}if(d.kind==="delete-range"&&k){let j={kind:"text-range",anchor:d.anchor,focus:d.focus},q=Xt(j);if(q.length===0)return false;let J=Array.from(new Map(q.map(K=>_(a,K.paraId)).filter(K=>K!==null).map(K=>[K.paraId,ue(K)])).values()),Q=rt(a),de=q.map(K=>Ft(a,K.paraId,K.from,K.to,{revisionId:Q,revisionKind:"delete",author:"User",date:new Date().toISOString()})).filter(K=>K!==null);if(de.length===0)return false;let le=mt(j,J,de,false);if(le){let K=et(a,j),Ee={paraId:K.anchor.paraId,offset:K.anchor.offset};lt(e,Ee),ne(v({kind:"caret"},Ee));}return le}if(d.kind==="delete-range"&&d.anchor.paraId===d.focus.paraId){let j={kind:"text-range",anchor:d.anchor,focus:d.focus};if(No(j))return true;let q=bi(d.anchor.offset,d.focus.offset);return k?Cn({anchor:d.anchor,focus:d.focus},j,{paraId:d.anchor.paraId,offset:q.from},()=>{var J;return Ft(a,d.anchor.paraId,q.from,q.to,{revisionId:(J=gr(d.anchor.paraId,q.from,"delete","at"))!=null?J:rt(a),revisionKind:"delete",author:"User",date:new Date().toISOString()})}):Cn({anchor:d.anchor,focus:d.focus},j,{paraId:d.anchor.paraId,offset:q.from},()=>pn(a,d.anchor.paraId,q.from,q.to))}if(d.kind==="split-paragraph"&&(m==null?void 0:m.kind)==="caret")return ya({paraId:m.paraId,offset:m.offset});if(d.kind==="insert-page-break"&&(m==null?void 0:m.kind)==="caret")return En(m,"insert");if(d.kind==="insert-image"&&m&&(m.kind==="caret"||m.kind==="text-range")){let j=m.kind==="text-range"?et(a,m):{anchor:{paraId:m.paraId,offset:m.offset},focus:{paraId:m.paraId,offset:m.offset}};return xa(j,d.src,$(v(v({},d.width?{width:d.width}:{}),d.height?{height:d.height}:{}),{select:true}))}if(d.kind==="set-image-size"&&(m==null?void 0:m.kind)==="object"&&m.objectKind==="image"&&m.objectId===d.objectId){let j=_(a,m.paraId);if(!j)return false;let q=ue(j),J=j.content.find(K=>K.kind==="image"&&K.drawingId===m.objectId),Q=(J==null?void 0:J.kind)==="image"?J.width:void 0,de=(J==null?void 0:J.kind)==="image"?J.height:void 0,le=Wc(a,m.paraId,m.objectId,{width:d.width,height:d.height});if(k&&le){let K=j.content.find(Ee=>Ee.kind==="image"&&Ee.drawingId===m.objectId);(K==null?void 0:K.kind)==="image"&&(K.formatRevision={kind:"format",revisionId:rt(a),beforeWidth:Q,beforeHeight:de,afterWidth:d.width,afterHeight:d.height,author:"User",date:new Date().toISOString()},le.kind==="image"&&(le.revisionId=K.formatRevision.revisionId,le.revisionKind="format"));}return mt(m,[q],le?[le]:[],true)}if(d.kind==="set-image-alignment"&&(m==null?void 0:m.kind)==="object"&&m.objectKind==="image"&&m.objectId===d.objectId)return ve({kind:"set-paragraph-alignment",alignment:d.alignment});if(m&&(d.kind==="insert-table"||d.kind==="delete-table"))return Jm(m,d);if(m&&(d.kind==="insert-table-row"||d.kind==="delete-table-row"||d.kind==="insert-table-column"||d.kind==="delete-table-column"))return Ym(m,d);if((m==null?void 0:m.kind)==="table-cell-range"&&(d.kind==="merge-table-cells"||d.kind==="split-table-cell"))return Zm(m,d);if(m&&(d.kind==="set-table-cell-background"||d.kind==="set-table-cell-vertical-alignment"||d.kind==="set-table-cell-borders"))return Qm(m,d);if(d.kind==="clear-table-cells"&&(m==null?void 0:m.kind)==="table-cell-range")return zn(m);if(d.kind==="delete-backward"){if((m==null?void 0:m.kind)==="table-cell-range")return zn(m);if((m==null?void 0:m.kind)==="text-range")return No(m)?true:k?ve({kind:"delete-range",anchor:m.anchor,focus:m.focus}):Vn(et(a,m),"");if((m==null?void 0:m.kind)==="object"&&m.objectKind==="image"){let j={paraId:m.paraId,offset:m.offset};return kn(m.paraId,m.objectId,j)}if((m==null?void 0:m.kind)==="caret"){if(k&&m.offset>0){let de=m.offset-1;return Cn({anchor:m,focus:m},m,{paraId:m.paraId,offset:de},()=>{var le;return Ft(a,m.paraId,de,m.offset,{revisionId:(le=gr(m.paraId,de,"delete","after"))!=null?le:rt(a),revisionKind:"delete",author:"User",date:new Date().toISOString()})})}if(En(m,"delete-backward")||To(m,"backward")||Ol({paraId:m.paraId,offset:m.offset}))return true;let j=_(a,m.paraId),q=j?ue(j):null,J=Mr(a,m.paraId,m.offset),Q={paraId:m.offset>0?m.paraId:(G=Ga(a,m.paraId))!=null?G:m.paraId,offset:Math.max(0,m.offset-1)};return (J==null?void 0:J.kind)==="image"?xr(q,J,Q):Sn(J,Q,(J==null?void 0:J.kind)==="block"?{}:{localParaId:m.paraId}),true}}if(d.kind==="delete-forward"&&(m==null?void 0:m.kind)==="table-cell-range")return zn(m);if(d.kind==="delete-forward"&&(m==null?void 0:m.kind)==="text-range")return No(m)?true:k?ve({kind:"delete-range",anchor:m.anchor,focus:m.focus}):Vn(et(a,m),"");if(d.kind==="delete-forward"&&(m==null?void 0:m.kind)==="caret"){if(k&&m.offset<ha(m.paraId))return Cn({anchor:m,focus:m},m,m,()=>{var de;return Ft(a,m.paraId,m.offset,m.offset+1,{revisionId:(de=gr(m.paraId,m.offset,"delete","at"))!=null?de:rt(a),revisionKind:"delete",author:"User",date:new Date().toISOString()})});if(En(m,"delete-forward")||To(m,"forward")||$l({paraId:m.paraId,offset:m.offset}))return true;let j=_(a,m.paraId),q=j?ue(j):null,J=Rr(a,m.paraId,m.offset),Q={paraId:m.paraId,offset:m.offset};return (J==null?void 0:J.kind)==="image"?xr(q,J,Q):Sn(J,Q,{localParaId:m.paraId}),true}if(d.kind==="delete-object"&&(m==null?void 0:m.kind)==="object"){let j={paraId:m.paraId,offset:m.offset};return kn(m.paraId,d.objectId,j)}if((d.kind==="set-hyperlink"||d.kind==="remove-hyperlink")&&(m==null?void 0:m.kind)==="text-range"){let j=Xt(m),q=j.map(Q=>_(a,Q.paraId)).filter(Q=>Q!==null).map(ue),J=j.map(Q=>os(a,Q.paraId,Q.from,Q.to,d.kind==="set-hyperlink"?d.hyperlink:null)).filter(Q=>Q!==null);return mt(m,q,J,false)}if(d.kind==="add-comment"&&(m==null?void 0:m.kind)==="text-range"){let j=Xt(m);if(j.length===0||!d.body.trim())return false;let q=j.map(K=>_(a,K.paraId)).filter(K=>K!==null).map(ue),J=Up(a),Q=(te=d.date)!=null?te:new Date().toISOString(),de=j.map(K=>{var Ee;return rs(a,K.paraId,K.from,K.to,{commentId:J,author:(Ee=d.author)!=null?Ee:"User",date:Q,body:d.body.trim()})}).filter(K=>K!==null),le=mt(m,q,de,false);return le&&de.length>1&&Pe(),le}if(d.kind==="edit-comment"||d.kind==="delete-comment"){if(d.kind==="edit-comment"&&!d.body.trim())return false;let j=_e(a).filter(Q=>Q.content.some(de=>{var le;return de.kind==="text"&&((le=de.marks)==null?void 0:le.some(K=>K.kind==="comment"&&K.commentId===d.commentId))})).map(ue);if(j.length===0)return false;let q=d.kind==="edit-comment"?Hc(a,d.commentId,d.body.trim()):Oc(a,d.commentId);if(q.length===0)return false;let J=m!=null?m:{kind:"caret",paraId:j[0].paraId,offset:0};return mt(J,j,q,false)}if(d.kind==="reply-comment"){let j=d.body.trim();if(!j)return false;let q=null;for(let le of _e(a)){let K=0;for(let Ee of le.content){let Fe=Ee.kind==="text"?Ee.text.length:1;if(Ee.kind==="text"&&((ae=Ee.marks)!=null&&ae.some(fe=>fe.kind==="comment"&&fe.commentId===d.commentId))){q={paragraph:le,from:K,to:K+Fe};break}K+=Fe;}if(q)break}if(!q)return false;let J=ue(q.paragraph),Q=Up(a),de=rs(a,q.paragraph.paraId,q.from,q.to,{commentId:Q,parentCommentId:d.commentId,preserveExistingComments:true,author:"User",date:new Date().toISOString(),body:j});return de?(Pe(),mt(m!=null?m:{kind:"caret",paraId:q.paragraph.paraId,offset:q.from},[J],[de],false)):false}if(d.kind==="add-revision"&&(m==null?void 0:m.kind)==="text-range"){let j=Xt(m);if(j.length===0)return false;let q=j.map(le=>_(a,le.paraId)).filter(le=>le!==null).map(ue),J=rt(a),Q=(ge=d.date)!=null?ge:new Date().toISOString(),de=j.map(le=>{var K;return Ft(a,le.paraId,le.from,le.to,{revisionId:J,revisionKind:d.revisionKind,author:(K=d.author)!=null?K:"User",date:Q})}).filter(le=>le!==null);return mt(m,q,de,false)}if(d.kind==="toggle-bold"||d.kind==="toggle-italic"||d.kind==="toggle-underline"||d.kind==="toggle-strike"||d.kind==="set-font-family"||d.kind==="set-font-size"||d.kind==="set-text-color"||d.kind==="set-highlight-color"||d.kind==="clear-text-format"){let j=Xt(m);if((m==null?void 0:m.kind)!=="text-range"||j.length===0)return false;let q=j.map(K=>_(a,K.paraId)).filter(K=>K!==null).map(ue),J=Ct(m),Q=null;if(d.kind==="toggle-bold"&&(Q={bold:J.bold!==true}),d.kind==="toggle-italic"&&(Q={italic:J.italic!==true}),d.kind==="toggle-underline"&&(Q={underline:J.underline!==true}),d.kind==="toggle-strike"&&(Q={strike:J.strike!==true}),d.kind==="set-font-family"&&d.fontFamily.trim()&&(Q={fontFamily:d.fontFamily.trim()}),d.kind==="set-font-size"&&(Q={fontSize:d.fontSize}),d.kind==="set-text-color"&&(Q={color:d.color.replace(/^#/,"").toUpperCase()}),d.kind==="set-highlight-color"&&(Q={highlight:d.color?d.color.replace(/^#/,"").toUpperCase():"none"}),d.kind!=="clear-text-format"&&!Q)return false;let de=j.map(K=>d.kind==="clear-text-format"?Vc(a,K.paraId,K.from,K.to):ns(a,K.paraId,K.from,K.to,Q)).filter(K=>K!==null);if(k){let K=rt(a),Ee=j.map(Fe=>jc(a,Fe.paraId,Fe.from,Fe.to,q.find(fe=>fe.paraId===Fe.paraId),{revisionId:K,author:"User",date:new Date().toISOString()})).filter(Fe=>Fe!==null);de.push(...Ee);}let le=d.kind==="toggle-bold"||d.kind==="toggle-italic"||d.kind==="set-font-family"||d.kind==="set-font-size"||d.kind==="clear-text-format";return mt(m,q,de,le)}if(d.kind==="set-paragraph-alignment"||d.kind==="set-paragraph-indent"||d.kind==="adjust-paragraph-left-indent"||d.kind==="set-paragraph-spacing"||d.kind==="set-paragraph-line-spacing"){let j=Array.from(new Set(Dl(m)));if(!m||j.length===0)return false;let q=j.map(Q=>_(a,Q)).filter(Q=>Q!==null).map(ue),J=j.map(Q=>{var le,K,Ee;let de=_(a,Q);if(!de)return null;if(d.kind==="set-paragraph-alignment")return _n(a,Q,{alignment:d.alignment});if(d.kind==="set-paragraph-indent")return _n(a,Q,{indent:dv(d.indent)});if(d.kind==="adjust-paragraph-left-indent"){let Fe=Math.max(0,((Ee=(K=(le=de.format)==null?void 0:le.indent)==null?void 0:K.left)!=null?Ee:0)+d.delta);return _n(a,Q,{indent:{left:Fe}})}return d.kind==="set-paragraph-spacing"?_n(a,Q,{spacing:cv(d.spacing)}):_n(a,Q,{spacing:{line:Math.max(0,d.line),lineRule:d.lineRule}})}).filter(Q=>Q!==null);return mt(m,q,J,d.kind!=="set-paragraph-alignment")}if(d.kind==="toggle-list"||d.kind==="remove-list"||d.kind==="adjust-list-level"){let j=Array.from(new Set(Dl(m)));if(!m||j.length===0)return false;let q=j.map(K=>_(a,K)).filter(K=>K!==null),J=q.map(ue),Q=d.kind==="toggle-list"&&q.every(K=>{var Ee;return ((Ee=K.format)==null?void 0:Ee.hasNumbering)&&cn(K.format.numbering)===d.listType}),de=d.kind==="toggle-list"&&!Q?(Ne=bc(a,j,d.listType))!=null?Ne:_a(a,d.listType):null,le=q.map(K=>{var Ee,Fe,fe,Be,se;if(d.kind==="remove-list"||Q)return (Ee=K.format)!=null&&Ee.hasNumbering?Lr(a,K.paraId,null):null;if(d.kind==="toggle-list"&&de){let Ze=(Be=(fe=(Fe=K.format)==null?void 0:Fe.numbering)==null?void 0:fe.ilvl)!=null?Be:0;return Lr(a,K.paraId,qa(de,Ze))}if(d.kind==="adjust-list-level"){let Ze=(se=K.format)!=null&&se.hasNumbering?K.format.numbering:void 0;return Ze?Lr(a,K.paraId,qa(Ze,Ze.ilvl+d.delta)):null}return null}).filter(K=>K!==null);return _o(a),mt(m,J,le,true)}return false},Vl=d=>{var P;let m=(P=Oe(a,d.tableId))==null?void 0:P.table;if(!m)return null;let x=Math.min(d.anchor.rowIndex,d.focus.rowIndex),S=Math.max(d.anchor.rowIndex,d.focus.rowIndex),E=Math.min(d.anchor.columnIndex,d.focus.columnIndex),I=Math.max(d.anchor.columnIndex,d.focus.columnIndex),T=Array.from({length:S-x+1},()=>Array.from({length:I-E+1},()=>null));for(let{cell:R,rowIndex:B,columnIndex:D}of at(m,d)){let G=T[B-x];G&&D>=E&&D<=I&&(G[D-E]={text:R.paragraphs.map(te=>Te(te)).join(`
1538
+ `),blocks:nt(R.blocks),format:ih(R)});}return {version:1,cells:T}},ih=d=>JSON.parse(JSON.stringify(v(v(v(v(v({},d.margin?{margin:d.margin}:{}),d.borders?{borders:d.borders}:{}),d.shading?{shading:d.shading}:{}),d.verticalAlignment?{verticalAlignment:d.verticalAlignment}:{}),d.noWrap!==void 0?{noWrap:d.noWrap}:{}))),Gl=d=>d.cells.map(m=>m.map(x=>{var S;return ((S=x==null?void 0:x.text)!=null?S:"").replace(/[\t\r\n]+/g," ")}).join(" ")).join(`
1539
+ `),ah=d=>{var x,S;let m=(S=(x=d.clipboardData)==null?void 0:x.getData(Vs))!=null?S:"";if(!m)return null;try{let E=JSON.parse(m);if(E.version===1&&Array.isArray(E.cells)&&E.cells.every(I=>Array.isArray(I)&&I.every(T=>T===null||typeof T=="object"&&typeof T.text=="string"&&Array.isArray(T.blocks)&&typeof T.format=="object")))return E}catch(E){return null}return null},sh=d=>{var S,E;let m=(E=(S=d.clipboardData)==null?void 0:S.getData("text/plain"))!=null?E:"";if(!m)return [];let x=m.replace(/\r\n?/g,`
1533
1540
  `).split(`
1534
- `);return x[x.length-1]===""&&x.pop(),x.map(I=>I.split(" "))},ba=d=>{var E,I,T;if(g&&d.clipboardData){let P=g,R=(E=_(a,P.paraId))==null?void 0:E.content.find(B=>B.kind==="image"&&B.drawingId===P.drawingId);if(!R||R.kind!=="image")return;d.preventDefault(),d.clipboardData.setData(Yr,mi(R.src)),d.clipboardData.setData("text/html",`<img src="${hi(R.src)}">`),wa(P).catch(B=>{console.warn("Unable to copy the selected image",B);});return}let m=(h==null?void 0:h.kind)==="object"||(h==null?void 0:h.kind)==="table-cell-range"?h:(I=ze(e))!=null?I:h;if((m==null?void 0:m.kind)==="table-cell-range"&&d.clipboardData){let P=Hl(m);if(!P)return;d.preventDefault(),d.clipboardData.setData(Hs,JSON.stringify(P)),d.clipboardData.setData("text/plain",Ol(P));return}if((m==null?void 0:m.kind)==="object"&&m.objectKind==="image"&&d.clipboardData){let P=(T=_(a,m.paraId))==null?void 0:T.content.find(R=>R.kind==="image"&&R.drawingId===m.objectId);if(!P||P.kind!=="image")return;d.preventDefault(),d.clipboardData.setData(Yr,mi(P.src)),d.clipboardData.setData("text/html",`<img src="${hi(P.src)}">`),wa({paraId:m.paraId,drawingId:m.objectId}).catch(R=>{console.warn("Unable to copy the selected image",R);});return}if((m==null?void 0:m.kind)==="text-range"&&d.clipboardData){let P=et(a,m),R=Ya(a,P.anchor,P.focus);if(R){d.preventDefault(),d.clipboardData.setData(ri,ks(R)),d.clipboardData.setData("text/plain",Es(R));return}}let x=Ll(m);if(x===null||!d.clipboardData)return;d.preventDefault(),d.clipboardData.setData("text/plain",x);let S=Wl(m);S.length>0&&d.clipboardData.setData("text/html",Ss(S));},wa=async d=>{var S;let m=(S=_(a,d.paraId))==null?void 0:S.content.find(E=>E.kind==="image"&&E.drawingId===d.drawingId);if(!m||m.kind!=="image")return;let x=await Jy(m.src);await navigator.clipboard.write([new ClipboardItem({"image/png":x})]);},$l=d=>{var E,I,T;if(c){ba(d);return}if(g&&d.clipboardData){let P=g,R=(E=_(a,P.paraId))==null?void 0:E.content.find(G=>G.kind==="image"&&G.drawingId===P.drawingId);if(!R||R.kind!=="image")return;d.preventDefault(),d.clipboardData.setData(Yr,mi(R.src)),d.clipboardData.setData("text/html",`<img src="${hi(R.src)}">`);let B=e.querySelector(`coco-word-native-p[data-para-id="${P.paraId}"]`),F=e.querySelector(`img[data-drawing-id="${P.drawingId}"]`);if(!B||!F)return;Sn(P.paraId,P.drawingId,{paraId:P.paraId,offset:ni(B,F)});return}let m=(h==null?void 0:h.kind)==="object"||(h==null?void 0:h.kind)==="table-cell-range"?h:(I=ze(e))!=null?I:h;if((m==null?void 0:m.kind)==="table-cell-range"&&d.clipboardData){let P=Hl(m);if(!P)return;d.preventDefault(),d.clipboardData.setData(Hs,JSON.stringify(P)),d.clipboardData.setData("text/plain",Ol(P)),$n(m);return}if((m==null?void 0:m.kind)==="object"&&m.objectKind==="image"&&d.clipboardData){let P=(T=_(a,m.paraId))==null?void 0:T.content.find(R=>R.kind==="image"&&R.drawingId===m.objectId);if(!P||P.kind!=="image")return;d.preventDefault(),d.clipboardData.setData(Yr,mi(P.src)),d.clipboardData.setData("text/html",`<img src="${hi(P.src)}">`),Sn(m.paraId,m.objectId,{paraId:m.paraId,offset:m.offset});return}if((m==null?void 0:m.kind)==="text-range"&&d.clipboardData){let P=et(a,m),R=Ya(a,P.anchor,P.focus);if(R){d.preventDefault(),d.clipboardData.setData(ri,ks(R)),d.clipboardData.setData("text/plain",Es(R)),ko(P,"");return}}let x=Ll(m);if(x===null||(m==null?void 0:m.kind)!=="text-range"||!d.clipboardData)return;d.preventDefault(),d.clipboardData.setData("text/plain",x);let S=Wl(m);S.length>0&&d.clipboardData.setData("text/html",Ss(S)),zn(et(a,m),"");},zl=d=>{var F,G,te,ae,ge,Ne,j,q,J,Q,de,le,K,Ee,De,fe,Be;if(c){d.preventDefault();return}let m=(h==null?void 0:h.kind)==="table-cell-range"?h:null;if(m){let se=nh(d),Ze=se?[]:rh(d);(se&&ma(m,{content:se.cells})||Ze.length>0&&ma(m,{text:Ze}))&&d.preventDefault();return}let x=Ku((G=(F=d.clipboardData)==null?void 0:F.getData(ri))!=null?G:"");if(x){let se=(ae=(te=ze(e))!=null?te:h)!=null?ae:st(e);if(!se||se.kind==="object"||se.kind==="table-cell-range")return;let Ze=se.kind==="text-range"?et(a,se):{anchor:{paraId:se.paraId,offset:se.offset},focus:{paraId:se.paraId,offset:se.offset}};if(Um(Ze,x)){d.preventDefault();return}}let S=Yy((Ne=(ge=d.clipboardData)==null?void 0:ge.getData(Yr))!=null?Ne:"");if(S){let se=(q=(j=ze(e))!=null?j:h)!=null?q:st(e);if(!se||se.kind==="object"||se.kind==="table-cell-range")return;let Ze=se.kind==="text-range"?et(a,se):{anchor:{paraId:se.paraId,offset:se.offset},focus:{paraId:se.paraId,offset:se.offset}};d.preventDefault(),ha(Ze,S);return}let E=Array.from((Q=(J=d.clipboardData)==null?void 0:J.files)!=null?Q:[]).find(se=>se.type.startsWith("image/"));if(E){let se=(le=(de=ze(e))!=null?de:h)!=null?le:st(e);if(!se||se.kind==="object"||se.kind==="table-cell-range")return;let Ze=se.kind==="text-range"?et(a,se):{anchor:{paraId:se.paraId,offset:se.offset},focus:{paraId:se.paraId,offset:se.offset}};d.preventDefault(),jp(E).then(ce=>ha(Ze,ce));return}let I=(Ee=(K=d.clipboardData)==null?void 0:K.getData("text/html"))!=null?Ee:"",T=I?Uu(I):[],P=T.length>0?T.map(se=>se.text).join(`
1535
- `):(De=d.clipboardData)==null?void 0:De.getData("text/plain");if(P===void 0)return;let R=(Be=(fe=ze(e))!=null?fe:h)!=null?Be:st(e);if(!R||R.kind==="object"||R.kind==="table-cell-range")return;let B=R.kind==="text-range"?et(a,R):{anchor:{paraId:R.paraId,offset:R.offset},focus:{paraId:R.paraId,offset:R.offset}};d.preventDefault(),zn(B,P,T.length>0?T:void 0);},oh=()=>{var m;let d=(m=h!=null?h:ze(e))!=null?m:st(e);return (d==null?void 0:d.kind)==="object"&&d.objectKind==="image"?Sn(d.paraId,d.objectId,{paraId:d.paraId,offset:d.offset}):(d==null?void 0:d.kind)==="text-range"?zn(et(a,d),""):(d==null?void 0:d.kind)==="table-cell-range"?$n(d):false},ih=async()=>{var d,m;if(typeof((d=navigator.clipboard)==null?void 0:d.readText)=="function")try{let x=await navigator.clipboard.readText(),S=(m=h!=null?h:ze(e))!=null?m:st(e);if(!S||S.kind==="object")return;if(S.kind==="table-cell-range"){let I=x.replace(/\r\n?/g,`
1541
+ `);return x[x.length-1]===""&&x.pop(),x.map(I=>I.split(" "))},va=d=>{var E,I,T;if(g&&d.clipboardData){let P=g,R=(E=_(a,P.paraId))==null?void 0:E.content.find(B=>B.kind==="image"&&B.drawingId===P.drawingId);if(!R||R.kind!=="image")return;d.preventDefault(),d.clipboardData.setData(Qr,wi(R.src)),d.clipboardData.setData("text/html",`<img src="${xi(R.src)}">`),Sa(P).catch(B=>{console.warn("Unable to copy the selected image",B);});return}let m=(h==null?void 0:h.kind)==="object"||(h==null?void 0:h.kind)==="table-cell-range"?h:(I=ze(e))!=null?I:h;if((m==null?void 0:m.kind)==="table-cell-range"&&d.clipboardData){let P=Vl(m);if(!P)return;d.preventDefault(),d.clipboardData.setData(Vs,JSON.stringify(P)),d.clipboardData.setData("text/plain",Gl(P));return}if((m==null?void 0:m.kind)==="object"&&m.objectKind==="image"&&d.clipboardData){let P=(T=_(a,m.paraId))==null?void 0:T.content.find(R=>R.kind==="image"&&R.drawingId===m.objectId);if(!P||P.kind!=="image")return;d.preventDefault(),d.clipboardData.setData(Qr,wi(P.src)),d.clipboardData.setData("text/html",`<img src="${xi(P.src)}">`),Sa({paraId:m.paraId,drawingId:m.objectId}).catch(R=>{console.warn("Unable to copy the selected image",R);});return}if((m==null?void 0:m.kind)==="text-range"&&d.clipboardData){let P=et(a,m),R=es(a,P.anchor,P.focus);if(R){d.preventDefault(),d.clipboardData.setData(si,Ns(R)),d.clipboardData.setData("text/plain",Ts(R));return}}let x=Fl(m);if(x===null||!d.clipboardData)return;d.preventDefault(),d.clipboardData.setData("text/plain",x);let S=Hl(m);S.length>0&&d.clipboardData.setData("text/html",Is(S));},Sa=async d=>{var S;let m=(S=_(a,d.paraId))==null?void 0:S.content.find(E=>E.kind==="image"&&E.drawingId===d.drawingId);if(!m||m.kind!=="image")return;let x=await lv(m.src);await navigator.clipboard.write([new ClipboardItem({"image/png":x})]);},jl=d=>{var E,I,T;if(c){va(d);return}if(g&&d.clipboardData){let P=g,R=(E=_(a,P.paraId))==null?void 0:E.content.find(G=>G.kind==="image"&&G.drawingId===P.drawingId);if(!R||R.kind!=="image")return;d.preventDefault(),d.clipboardData.setData(Qr,wi(R.src)),d.clipboardData.setData("text/html",`<img src="${xi(R.src)}">`);let B=e.querySelector(`coco-word-native-p[data-para-id="${P.paraId}"]`),D=e.querySelector(`img[data-drawing-id="${P.drawingId}"]`);if(!B||!D)return;kn(P.paraId,P.drawingId,{paraId:P.paraId,offset:ai(B,D)});return}let m=(h==null?void 0:h.kind)==="object"||(h==null?void 0:h.kind)==="table-cell-range"?h:(I=ze(e))!=null?I:h;if((m==null?void 0:m.kind)==="table-cell-range"&&d.clipboardData){let P=Vl(m);if(!P)return;d.preventDefault(),d.clipboardData.setData(Vs,JSON.stringify(P)),d.clipboardData.setData("text/plain",Gl(P)),zn(m);return}if((m==null?void 0:m.kind)==="object"&&m.objectKind==="image"&&d.clipboardData){let P=(T=_(a,m.paraId))==null?void 0:T.content.find(R=>R.kind==="image"&&R.drawingId===m.objectId);if(!P||P.kind!=="image")return;d.preventDefault(),d.clipboardData.setData(Qr,wi(P.src)),d.clipboardData.setData("text/html",`<img src="${xi(P.src)}">`),kn(m.paraId,m.objectId,{paraId:m.paraId,offset:m.offset});return}if((m==null?void 0:m.kind)==="text-range"&&d.clipboardData){let P=et(a,m),R=es(a,P.anchor,P.focus);if(R){d.preventDefault(),d.clipboardData.setData(si,Ns(R)),d.clipboardData.setData("text/plain",Ts(R)),Io(P,"");return}}let x=Fl(m);if(x===null||(m==null?void 0:m.kind)!=="text-range"||!d.clipboardData)return;d.preventDefault(),d.clipboardData.setData("text/plain",x);let S=Hl(m);S.length>0&&d.clipboardData.setData("text/html",Is(S)),Vn(et(a,m),"");},Ul=d=>{var D,G,te,ae,ge,Ne,j,q,J,Q,de,le,K,Ee,Fe,fe,Be;if(c){d.preventDefault();return}let m=(h==null?void 0:h.kind)==="table-cell-range"?h:null;if(m){let se=ah(d),Ze=se?[]:sh(d);(se&&wa(m,{content:se.cells})||Ze.length>0&&wa(m,{text:Ze}))&&d.preventDefault();return}let x=Yu((G=(D=d.clipboardData)==null?void 0:D.getData(si))!=null?G:"");if(x){let se=(ae=(te=ze(e))!=null?te:h)!=null?ae:st(e);if(!se||se.kind==="object"||se.kind==="table-cell-range")return;let Ze=se.kind==="text-range"?et(a,se):{anchor:{paraId:se.paraId,offset:se.offset},focus:{paraId:se.paraId,offset:se.offset}};if(Xm(Ze,x)){d.preventDefault();return}}let S=av((Ne=(ge=d.clipboardData)==null?void 0:ge.getData(Qr))!=null?Ne:"");if(S){let se=(q=(j=ze(e))!=null?j:h)!=null?q:st(e);if(!se||se.kind==="object"||se.kind==="table-cell-range")return;let Ze=se.kind==="text-range"?et(a,se):{anchor:{paraId:se.paraId,offset:se.offset},focus:{paraId:se.paraId,offset:se.offset}};d.preventDefault(),xa(Ze,S);return}let E=Array.from((Q=(J=d.clipboardData)==null?void 0:J.files)!=null?Q:[]).find(se=>se.type.startsWith("image/"));if(E){let se=(le=(de=ze(e))!=null?de:h)!=null?le:st(e);if(!se||se.kind==="object"||se.kind==="table-cell-range")return;let Ze=se.kind==="text-range"?et(a,se):{anchor:{paraId:se.paraId,offset:se.offset},focus:{paraId:se.paraId,offset:se.offset}};d.preventDefault(),qp(E).then(ce=>xa(Ze,ce));return}let I=(Ee=(K=d.clipboardData)==null?void 0:K.getData("text/html"))!=null?Ee:"",T=I?Xu(I):[],P=T.length>0?T.map(se=>se.text).join(`
1542
+ `):(Fe=d.clipboardData)==null?void 0:Fe.getData("text/plain");if(P===void 0)return;let R=(Be=(fe=ze(e))!=null?fe:h)!=null?Be:st(e);if(!R||R.kind==="object"||R.kind==="table-cell-range")return;let B=R.kind==="text-range"?et(a,R):{anchor:{paraId:R.paraId,offset:R.offset},focus:{paraId:R.paraId,offset:R.offset}};d.preventDefault(),Vn(B,P,T.length>0?T:void 0);},lh=()=>{var m;let d=(m=h!=null?h:ze(e))!=null?m:st(e);return (d==null?void 0:d.kind)==="object"&&d.objectKind==="image"?kn(d.paraId,d.objectId,{paraId:d.paraId,offset:d.offset}):(d==null?void 0:d.kind)==="text-range"?Vn(et(a,d),""):(d==null?void 0:d.kind)==="table-cell-range"?zn(d):false},dh=async()=>{var d,m;if(typeof((d=navigator.clipboard)==null?void 0:d.readText)=="function")try{let x=await navigator.clipboard.readText(),S=(m=h!=null?h:ze(e))!=null?m:st(e);if(!S||S.kind==="object")return;if(S.kind==="table-cell-range"){let I=x.replace(/\r\n?/g,`
1536
1543
  `).split(`
1537
- `).map(T=>T.split(" "));ma(S,{text:I});return}let E=S.kind==="text-range"?et(a,S):{anchor:{paraId:S.paraId,offset:S.offset},focus:{paraId:S.paraId,offset:S.offset}};zn(E,x);}catch(x){console.warn("Unable to paste from the context menu",x);}},xa=(d="add",m,x="")=>{let S=document.createElement("div");S.className="coco-word-dialog-backdrop";let E=document.createElement("section");E.className="coco-word-dialog",E.setAttribute("role","dialog"),E.setAttribute("aria-modal","true"),E.setAttribute("aria-labelledby","coco-word-comment-dialog-title");let I=document.createElement("h2");I.id="coco-word-comment-dialog-title",I.textContent=d==="edit"?"\u7F16\u8F91\u6279\u6CE8":d==="reply"?"\u56DE\u590D\u6279\u6CE8":"\u6DFB\u52A0\u6279\u6CE8";let T=document.createElement("textarea");T.className="coco-word-dialog-input",T.placeholder="\u6279\u6CE8\u5185\u5BB9",T.rows=4,T.value=x;let P=document.createElement("div");P.className="coco-word-dialog-actions";let R=document.createElement("button");R.type="button",R.className="coco-word-dialog-button is-secondary",R.textContent="\u53D6\u6D88";let B=document.createElement("button");B.type="button",B.className="coco-word-dialog-button is-primary",B.textContent="\u786E\u5B9A";let F=()=>S.remove();R.addEventListener("click",F),S.addEventListener("click",G=>{G.target===S&&F();}),E.addEventListener("keydown",G=>{G.key==="Escape"&&F(),G.key==="Enter"&&(G.ctrlKey||G.metaKey)&&(G.preventDefault(),B.click());}),B.addEventListener("click",()=>{let G=T.value.trim();if(!G){T.focus();return}ve(d==="edit"&&m!==void 0?{kind:"edit-comment",commentId:m,body:G}:d==="reply"&&m!==void 0?{kind:"reply-comment",commentId:m,body:G}:{kind:"add-comment",body:G}),F();}),P.append(R,B),E.append(I,T,P),S.appendChild(E),(o!=null?o:document.body).appendChild(S),T.focus();},ah=()=>{var E,I,T;let d=(E=h!=null?h:ze(e))!=null?E:st(e),m=Ct(d),x=(d==null?void 0:d.kind)==="text-range"||(d==null?void 0:d.kind)==="object"||(d==null?void 0:d.kind)==="table-cell-range",S=[{label:"\u526A\u5207",disabled:!x,action:()=>document.execCommand("cut")},{label:"\u590D\u5236",disabled:!x,action:()=>document.execCommand("copy")},{label:"\u7C98\u8D34\u4E3A\u7EAF\u6587\u672C",disabled:(d==null?void 0:d.kind)==="object"||typeof((I=navigator.clipboard)==null?void 0:I.readText)!="function",action:ih},{label:"\u5220\u9664",disabled:!x,action:()=>oh()}];if((d==null?void 0:d.kind)==="text-range"&&(S.push({label:"\u6DFB\u52A0\u6279\u6CE8",separatorBefore:true,action:xa}),S.push({label:"\u6807\u8BB0\u4E3A\u63D2\u5165\u4FEE\u8BA2",action:()=>ve({kind:"add-revision",revisionKind:"insert"})}),S.push({label:"\u6807\u8BB0\u4E3A\u5220\u9664\u4FEE\u8BA2",action:()=>ve({kind:"add-revision",revisionKind:"delete"})}),S.push({label:m.bold===true?"\u53D6\u6D88\u52A0\u7C97":"\u52A0\u7C97",separatorBefore:true,disabled:!Mt(a,d,{kind:"toggle-bold"}),action:()=>ve({kind:"toggle-bold"})}),S.push({label:"\u6E05\u9664\u6587\u672C\u683C\u5F0F",action:()=>ve({kind:"clear-text-format"})}),m.hyperlink!==null&&S.push({label:"\u79FB\u9664\u8D85\u94FE\u63A5",disabled:!Mt(a,d,{kind:"remove-hyperlink"}),action:()=>ve({kind:"remove-hyperlink"})})),(d==null?void 0:d.kind)==="caret"&&Mt(a,d,{kind:"insert-table",rows:2,columns:2})&&S.push({label:"\u63D2\u5165 2 \xD7 2 \u8868\u683C",separatorBefore:true,action:()=>ve({kind:"insert-table",rows:2,columns:2})}),(d==null?void 0:d.kind)==="object"&&d.objectKind==="image"&&(S.push({label:"\u56FE\u7247\u5DE6\u5BF9\u9F50",separatorBefore:true,action:()=>ve({kind:"set-image-alignment",objectId:d.objectId,alignment:"left"})}),S.push({label:"\u56FE\u7247\u5C45\u4E2D",action:()=>ve({kind:"set-image-alignment",objectId:d.objectId,alignment:"center"})}),S.push({label:"\u56FE\u7247\u53F3\u5BF9\u9F50",action:()=>ve({kind:"set-image-alignment",objectId:d.objectId,alignment:"right"})})),m.table){let P=(T=m.table.range)!=null?T:{startRow:m.table.rowIndex,endRow:m.table.rowIndex,startColumn:m.table.columnIndex,endColumn:m.table.columnIndex};S.push({label:"\u9009\u62E9\u6574\u884C",separatorBefore:true,action:()=>ne({kind:"table-cell-range",tableId:m.table.tableId,anchor:{rowIndex:P.startRow,columnIndex:0},focus:{rowIndex:P.endRow,columnIndex:Math.max(0,m.table.columnCount-1)}})}),S.push({label:"\u9009\u62E9\u6574\u5217",action:()=>ne({kind:"table-cell-range",tableId:m.table.tableId,anchor:{rowIndex:0,columnIndex:P.startColumn},focus:{rowIndex:Math.max(0,m.table.rowCount-1),columnIndex:P.endColumn}})}),S.push({label:"\u5728\u4E0A\u65B9\u63D2\u5165\u884C",disabled:!Mt(a,d,{kind:"insert-table-row"}),action:()=>ve({kind:"insert-table-row",position:"before"})}),S.push({label:"\u5728\u4E0B\u65B9\u63D2\u5165\u884C",disabled:!Mt(a,d,{kind:"insert-table-row"}),action:()=>ve({kind:"insert-table-row",position:"after"})}),S.push({label:"\u5220\u9664\u5F53\u524D\u884C",disabled:!Mt(a,d,{kind:"delete-table-row"}),action:()=>ve({kind:"delete-table-row"})}),S.push({label:"\u5728\u5DE6\u4FA7\u63D2\u5165\u5217",disabled:!Mt(a,d,{kind:"insert-table-column"}),action:()=>ve({kind:"insert-table-column",position:"before"})}),S.push({label:"\u5728\u53F3\u4FA7\u63D2\u5165\u5217",disabled:!Mt(a,d,{kind:"insert-table-column"}),action:()=>ve({kind:"insert-table-column",position:"after"})}),S.push({label:"\u5220\u9664\u5F53\u524D\u5217",disabled:!Mt(a,d,{kind:"delete-table-column"}),action:()=>ve({kind:"delete-table-column"})}),S.push({label:"\u5220\u9664\u8868\u683C",separatorBefore:true,disabled:!Mt(a,d,{kind:"delete-table"}),action:()=>ve({kind:"delete-table"})});for(let[R,B]of [["\u5355\u5143\u683C\u9876\u90E8\u5BF9\u9F50","top"],["\u5355\u5143\u683C\u5782\u76F4\u5C45\u4E2D","center"],["\u5355\u5143\u683C\u5E95\u90E8\u5BF9\u9F50","bottom"]])S.push({label:R,action:()=>ve({kind:"set-table-cell-vertical-alignment",alignment:B})});}return S.push({label:"\u64A4\u9500",separatorBefore:true,disabled:!Y.length,action:()=>hr()},{label:"\u91CD\u505A",disabled:!X.length,action:()=>gr()}),S},sh=d=>{var I,T;let m=d.target;if(m instanceof HTMLImageElement){let P=St(m),R=P==null?void 0:P.dataset.paraId,B=m.dataset.drawingId;if(P&&R&&B){let F={kind:"object",paraId:R,objectKind:"image",objectId:B,offset:ni(P,m)};return g={paraId:R,drawingId:B},Gt(),ne(F),F}}let x=po(m);if(x){if((h==null?void 0:h.kind)==="table-cell-range"&&h.tableId===x.tableId){let R=Math.min(h.anchor.rowIndex,h.focus.rowIndex),B=Math.max(h.anchor.rowIndex,h.focus.rowIndex),F=Math.min(h.anchor.columnIndex,h.focus.columnIndex),G=Math.max(h.anchor.columnIndex,h.focus.columnIndex);if(x.point.rowIndex>=R&&x.point.rowIndex<=B&&x.point.columnIndex>=F&&x.point.columnIndex<=G)return h}let P={kind:"table-cell-range",tableId:x.tableId,anchor:x.point,focus:x.point};return (I=kt(e))==null||I.removeAllRanges(),ne(P),P}let S=(T=Du(e,d.clientX,d.clientY))!=null?T:ut(e);if(!S)return h;if((h==null?void 0:h.kind)==="text-range"){let P=et(a,h),R=be(a,P.anchor.paraId),B=be(a,P.focus.paraId),F=be(a,S.paraId);if(R&&B&&F&&R.container===B.container&&R.container===F.container){let G=F.index>R.index||F.index===R.index&&S.offset>=P.anchor.offset,te=F.index<B.index||F.index===B.index&&S.offset<=P.focus.offset;if(G&&te)return h}}g=null,Et(e),lt(e,S);let E=v({kind:"caret"},S);return ne(E),E},Vl=d=>{var S;if(c||n.contextMenu===false)return;d.preventDefault(),d.stopPropagation(),dt(),Rt(),sh(d);let m=document.createElement("div");m.className="coco-word-context-menu",m.setAttribute("role","menu"),m.contentEditable="false";for(let E of ah()){if(E.separatorBefore){let T=document.createElement("div");T.className="coco-word-context-menu-separator",T.setAttribute("role","separator"),m.appendChild(T);}let I=document.createElement("button");I.type="button",I.className="coco-word-context-menu-item",I.textContent=E.label,I.disabled=(S=E.disabled)!=null?S:false,I.setAttribute("role","menuitem"),I.addEventListener("mousedown",T=>T.preventDefault()),I.addEventListener("click",()=>{let T=E.action();Rt(),T instanceof Promise&&T.catch(P=>console.warn("Context menu action failed",P));}),m.appendChild(I);}(o!=null?o:document.body).appendChild(m),Vt=m;let x=m.getBoundingClientRect();m.style.left=`${Math.max(4,Math.min(d.clientX,window.innerWidth-x.width-4))}px`,m.style.top=`${Math.max(4,Math.min(d.clientY,window.innerHeight-x.height-4))}px`;},Gl=d=>{Vt&&!Vt.contains(d.target)&&Rt();},jl=d=>{d.key==="Escape"&&Rt();},Ul=d=>{var E;if(c){d.preventDefault();return}if(d.inputType===z){d.preventDefault(),z=null,Z!==null&&window.clearTimeout(Z),Z=null;return}if(d.inputType==="historyUndo"&&hr()){d.preventDefault(),d.stopPropagation();return}if(d.inputType==="historyRedo"&&gr()){d.preventDefault(),d.stopPropagation();return}if(d.isComposing||he||we||d.inputType==="insertCompositionText"||d.inputType==="deleteCompositionText"||d.inputType==="insertFromComposition")return;if(g&&d.inputType==="deleteContentBackward"){d.preventDefault();let I={paraId:g.paraId,offset:0};Sn(g.paraId,g.drawingId,I);return}let m=ze(e),x=(m==null?void 0:m.kind)==="text-range"?m:(h==null?void 0:h.kind)==="text-range"?h:m;if(k&&x&&(d.inputType==="insertText"||d.inputType==="deleteContentBackward"||d.inputType==="deleteContentForward")){if(x.kind==="caret"||x.kind==="text-range"&&x.anchor.paraId===x.focus.paraId){d.preventDefault(),d.inputType==="insertText"&&d.data?x.kind==="caret"?ve({kind:"insert-text",text:d.data}):ve({kind:"replace-range",anchor:x.anchor,focus:x.focus,text:d.data}):d.inputType==="deleteContentBackward"?x.kind==="text-range"&&x.anchor.offset!==x.focus.offset?ve({kind:"delete-range",anchor:x.anchor,focus:x.focus}):ve({kind:"delete-backward"}):d.inputType==="deleteContentForward"&&(x.kind==="text-range"&&x.anchor.offset!==x.focus.offset?ve({kind:"delete-range",anchor:x.anchor,focus:x.focus}):ve({kind:"delete-forward"}));return}if(x.kind==="text-range"&&(d.inputType==="deleteContentBackward"||d.inputType==="deleteContentForward")){d.preventDefault(),ve({kind:"delete-range",anchor:x.anchor,focus:x.focus});return}}if((x==null?void 0:x.kind)==="text-range"&&x.anchor.paraId===x.focus.paraId){let I=fi(x.anchor.offset,x.focus.offset);if(yo(x.anchor.paraId)&&(d.inputType==="insertText"&&d.data||d.inputType==="deleteContentBackward"||d.inputType==="deleteContentForward")){g=null,fr(x.anchor.paraId),vo({anchor:{paraId:x.anchor.paraId,offset:I.from},focus:{paraId:x.focus.paraId,offset:I.to}}),ne(x);return}if(d.inputType==="insertText"&&d.data){d.preventDefault(),g=null,ne({kind:"caret",paraId:x.anchor.paraId,offset:I.from+d.data.length}),vn(Pr(a,x.anchor.paraId,I.from,I.to,d.data),{paraId:x.anchor.paraId,offset:I.from+d.data.length},{localParaId:x.anchor.paraId});return}if(d.inputType==="deleteContentBackward"||d.inputType==="deleteContentForward"){if(d.preventDefault(),g=null,Eo(x))return;ne({kind:"caret",paraId:x.anchor.paraId,offset:I.from}),vn(un(a,x.anchor.paraId,I.from,I.to),{paraId:x.anchor.paraId,offset:I.from},{localParaId:x.anchor.paraId});return}}if((x==null?void 0:x.kind)==="text-range"&&x.anchor.paraId!==x.focus.paraId){let I=et(a,x);if(d.inputType==="insertText"&&d.data){if(d.preventDefault(),g=null,ko(I,d.data))return;Rl(I,d.data);return}if(d.inputType==="deleteContentBackward"||d.inputType==="deleteContentForward"){if(ko(I,"")){d.preventDefault();return}if(!jm(I)&&$m(I)){g=null,ne({kind:"caret",paraId:I.anchor.paraId,offset:I.anchor.offset});return}d.preventDefault(),g=null,ne({kind:"caret",paraId:I.anchor.paraId,offset:I.anchor.offset}),Rl(I,"");return}d.preventDefault(),ne(x);return}let S=(x==null?void 0:x.kind)==="caret"?x:ut(e);if(S){if(g=null,ne({kind:"caret",paraId:S.paraId,offset:S.offset}),d.inputType==="insertText"&&d.data&&d.data!==`
1538
- `&&d.data!=="\r"&&yo(S.paraId)){fr(S.paraId),vo({anchor:S,focus:S});return}if(d.inputType==="deleteContentBackward"&&S.offset>0&&yo(S.paraId)){fr(S.paraId),vo({anchor:S,focus:S});return}if(d.inputType==="deleteContentForward"&&S.offset<ua(S.paraId)&&yo(S.paraId)){fr(S.paraId),vo({anchor:S,focus:S});return}if(d.inputType==="insertText"&&(d.data===`
1539
- `||d.data==="\r")||d.inputType==="insertParagraph"){if(d.preventDefault(),N){N=false,L!==null&&window.clearTimeout(L),L=null;return}ga(S);}else if(d.inputType==="insertText"&&d.data)d.preventDefault(),vn(Qt(a,S.paraId,S.offset,d.data),{paraId:S.paraId,offset:S.offset+d.data.length},{localParaId:S.paraId});else if(d.inputType==="deleteContentBackward"){if(d.preventDefault(),kn(S,"delete-backward")||Co(v({kind:"caret"},S),"backward")||Bl(S))return;let I=_(a,S.paraId),T=I?ue(I):null,P=Nr(a,S.paraId,S.offset),R={paraId:S.offset>0?S.paraId:(E=Oa(a,S.paraId))!=null?E:S.paraId,offset:Math.max(0,S.offset-1)};(P==null?void 0:P.kind)==="image"?br(T,P,R):vn(P,R,(P==null?void 0:P.kind)==="block"?{}:{localParaId:S.paraId});}else if(d.inputType==="deleteContentForward"){if(d.preventDefault(),kn(S,"delete-forward")||Co(v({kind:"caret"},S),"forward")||Fl(S))return;let I=_(a,S.paraId),T=I?ue(I):null,P=Tr(a,S.paraId,S.offset),R={paraId:S.paraId,offset:S.offset};(P==null?void 0:P.kind)==="image"?br(T,P,R):vn(P,R,{localParaId:S.paraId});}}},Io=d=>{var R,B,F,G,te,ae,ge,Ne;if(l)return;if(d.currentTarget===document){if(d.composedPath().includes(e)||Xr.get(document)!==e)return}else dt();if(he||d.isComposing||d.keyCode===229)return;if((d.ctrlKey||d.metaKey)&&!d.shiftKey&&d.key.toLowerCase()==="c"&&g&&typeof((R=navigator.clipboard)==null?void 0:R.write)=="function"&&typeof ClipboardItem!="undefined"){let j=g;d.preventDefault(),d.stopPropagation(),wa(j).catch(q=>{console.warn("Unable to copy the selected image",q);});return}if(c){(d.ctrlKey||d.metaKey)&&(d.key.toLowerCase()==="z"||d.key.toLowerCase()==="y")&&(d.preventDefault(),d.stopPropagation());return}let x=(d.ctrlKey||d.metaKey)&&!d.shiftKey&&d.key.toLowerCase()==="z",S=(d.ctrlKey||d.metaKey)&&d.shiftKey&&d.key.toLowerCase()==="z"||(d.ctrlKey||d.metaKey)&&d.key.toLowerCase()==="y";(x||S)&&z&&(z=null,Z!==null&&window.clearTimeout(Z),Z=null);let E=x||S?ut(e):null,I=(B=E==null?void 0:E.paraId)!=null?B:h&&"paraId"in h?h.paraId:null;if(x&&hr()){Cl("historyUndo"),d.preventDefault(),d.stopPropagation();return}if(S&&gr()){Cl("historyRedo"),d.preventDefault(),d.stopPropagation();return}if((d.ctrlKey||d.metaKey)&&!d.shiftKey&&d.key==="Enter"){let j=(F=h!=null?h:ze(e))!=null?F:st(e);(j==null?void 0:j.kind)==="caret"&&ve({kind:"insert-page-break"})&&(d.preventDefault(),d.stopPropagation());return}if((x||S)&&(V!==null&&window.clearTimeout(V),xo.disconnect(),V=window.setTimeout(()=>{var de,le;V=null;let j=ut(e),q=(de=j==null?void 0:j.paraId)!=null?de:I;if(!q)return;let J=e.querySelector(`coco-word-native-p[data-para-id="${q}"]`),Q=_(a,q);if(J&&Q&&Q.content.every(K=>K.kind==="text")){let K=Rr(a,q,(le=J.textContent)!=null?le:"");K&&(u.push(K),Ie("deferred"));}Le(q,j!=null?j:void 0);},120)),(h==null?void 0:h.kind)==="table-cell-range"){if(d.key==="Escape"){d.preventDefault(),ne(null);return}if(d.key==="Enter"||d.key==="F2"){let q=(G=Oe(a,h.tableId))==null?void 0:G.table,J=q?(te=at(q,h)[0])==null?void 0:te.cell:null,Q=J==null?void 0:J.paragraphs[0];if(Q){d.preventDefault();let de={paraId:Q.paraId,offset:Te(Q).length};lt(e,de),ne(v({kind:"caret"},de));}return}let j=d.key==="ArrowLeft"?{row:0,column:-1}:d.key==="ArrowRight"?{row:0,column:1}:d.key==="ArrowUp"?{row:-1,column:0}:d.key==="ArrowDown"?{row:1,column:0}:null;if(j){let q=(ae=Oe(a,h.tableId))==null?void 0:ae.table,J=q?Math.max(1,...q.rows.map(de=>de.cells.reduce((le,K)=>le+Math.max(1,K.gridSpan),0))):1,Q={rowIndex:Math.max(0,Math.min(((ge=q==null?void 0:q.rows.length)!=null?ge:1)-1,h.focus.rowIndex+j.row)),columnIndex:Math.max(0,Math.min(J-1,h.focus.columnIndex+j.column))};d.preventDefault(),ne({kind:"table-cell-range",tableId:h.tableId,anchor:d.shiftKey?h.anchor:Q,focus:Q});return}}if(!d.shiftKey&&["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"].includes(d.key)&&(H=null),g&&(d.key==="Backspace"||d.key==="Delete")){d.preventDefault();let j={paraId:g.paraId,offset:0};Sn(g.paraId,g.drawingId,j);return}if((h==null?void 0:h.kind)==="table-cell-range"&&(d.key==="Backspace"||d.key==="Delete")){d.preventDefault(),d.stopPropagation(),$n(h);return}if(d.key!=="Enter")return;let T=ut(e);if(!T)return;d.preventDefault(),d.stopPropagation();let P=_(a,T.paraId);if((Ne=P==null?void 0:P.format)!=null&&Ne.hasNumbering&&P.format.numbering&&Te(P).length===0){g=null,ne({kind:"caret",paraId:T.paraId,offset:0}),ve({kind:"remove-list"});return}g=null,N=true,L!==null&&window.clearTimeout(L),L=window.setTimeout(()=>{N=false,L=null;},0),ga(T);},Kl=d=>{if(!(l||d.composedPath().includes(e)||Xr.get(document)!==e)){if(c){d.preventDefault(),d.stopPropagation();return}(d.inputType==="historyUndo"&&hr()||d.inputType==="historyRedo"&&gr())&&(d.preventDefault(),d.stopPropagation());}},ya=(d,m)=>{let x=d.querySelector(":scope > .coco-word-native-revision-group-list"),S=d.querySelector(":scope > .coco-word-native-revision-group-toggle");if(!x||!S)return;d.classList.toggle("is-expanded",m),x.hidden=!m,S.setAttribute("aria-expanded",String(m));let E=S.querySelector(".coco-word-native-revision-group-affordance");E&&(E.textContent=m?"\u6536\u8D77":"\u5C55\u5F00");},_l=d=>{e.querySelectorAll(".coco-word-native-revision-group.is-expanded").forEach(m=>{m!==d&&ya(m,false);});},ql=d=>{var Ne,j,q,J,Q,de,le,K,Ee,De;let m=(Ne=d.composedPath().find(fe=>fe instanceof HTMLButtonElement&&fe.matches("[data-revision-action][data-revision-id]")))!=null?Ne:d.target instanceof Element?d.target.closest("[data-revision-action][data-revision-id]"):null;if(m){d.preventDefault(),d.stopPropagation();let fe=m.dataset.revisionId;fe&&ve({kind:m.dataset.revisionAction==="accept"?"accept-revision":"reject-revision",revisionId:fe,revisionKind:m.dataset.revisionKind});return}let x=(j=d.composedPath().find(fe=>fe instanceof HTMLButtonElement&&fe.matches("[data-revision-group-toggle]")))!=null?j:d.target instanceof Element?d.target.closest("[data-revision-group-toggle]"):null;if(x){d.preventDefault(),d.stopPropagation();let fe=x.closest(".coco-word-native-revision-group"),Be=fe==null?void 0:fe.querySelector(":scope > .coco-word-native-revision-group-list");if(!fe||!Be)return;let se=Be.hidden;_l(fe),ya(fe,se);return}let S=(q=d.composedPath().find(fe=>fe instanceof HTMLButtonElement&&fe.matches("[data-comment-menu][data-comment-id]")))!=null?q:d.target instanceof Element?d.target.closest("[data-comment-menu][data-comment-id]"):null;if(S){d.preventDefault(),d.stopPropagation();let fe=S.dataset.commentId;if(!fe)return;let Be=(J=S.parentElement)==null?void 0:J.querySelector(`[data-comment-menu-for="${CSS.escape(fe)}"]`);if(!Be)return;e.querySelectorAll(".coco-word-native-comment-menu:not([hidden])").forEach(se=>{se!==Be&&(se.hidden=true);}),Be.hidden=!Be.hidden;return}let E=(Q=d.composedPath().find(fe=>fe instanceof HTMLButtonElement&&fe.matches("[data-comment-action][data-comment-id]")))!=null?Q:d.target instanceof Element?d.target.closest("[data-comment-action][data-comment-id]"):null;if(E){d.preventDefault(),d.stopPropagation();let fe=Number(E.dataset.commentId);if(!Number.isFinite(fe))return;let Be=E.closest(".coco-word-native-comment-bubble");E.dataset.commentAction==="edit"?xa("edit",fe,(de=Be==null?void 0:Be.dataset.commentBody)!=null?de:""):E.dataset.commentAction==="reply"?xa("reply",fe):ve({kind:"delete-comment",commentId:fe});return}if(Fe){Fe=false,d.preventDefault(),d.stopPropagation();return}if(It){It=false,d.preventDefault(),d.stopPropagation();return}if(Ge){d.preventDefault(),d.stopPropagation(),ot(true),queueMicrotask(()=>{Ge=false,ot(true);});return}dt(),H=null;let I=d.target,T=I instanceof Element?I.closest(".coco-word-comment[data-comment-id]"):null,P=I instanceof Element?I.closest(".coco-word-revision-insert[data-revision-id], .coco-word-revision-delete[data-revision-id], .coco-word-revision-format[data-revision-id], img[data-revision-id], coco-word-native-table[data-revision-id]"):null,R=I instanceof Element?I.closest(".coco-word-native-comment-bubble, .coco-word-native-revision-bubble"):null,B=R!=null?R:T?e.querySelector(`.coco-word-native-comment-bubble[data-comment-id="${CSS.escape((le=T.dataset.commentId)!=null?le:"")}"]`):P?e.querySelector(`.coco-word-native-revision-bubble[data-revision-id="${CSS.escape((K=P.dataset.revisionId)!=null?K:"")}"][data-revision-kind="${CSS.escape((Ee=P.dataset.revisionKind)!=null?Ee:P.classList.contains("coco-word-revision-delete")?"delete":"insert")}"]`):null;if(B){let fe=B.closest(".coco-word-native-revision-group");fe&&(_l(fe),ya(fe,true));let Be=B.dataset.paraId,se=Number(B.dataset.from),Ze=Number(B.dataset.to);if(Be&&Number.isFinite(se)&&Number.isFinite(Ze)){d.preventDefault(),d.stopPropagation(),e.querySelectorAll(".coco-word-native-comment-bubble.is-selected, .coco-word-native-revision-bubble.is-selected").forEach(Re=>Re.classList.remove("is-selected")),B.classList.add("is-selected");let ce={kind:"text-range",anchor:{paraId:Be,offset:se},focus:{paraId:Be,offset:Math.max(se+1,Ze)}};ne(ce);let me=T!=null?T:(()=>{var Ke,je,Xt,Cn,Vn,Po;let Re=R==null?void 0:R.closest("coco-word-native-page");if(!Re)return null;let ie=B.dataset.revisionKind?`.coco-word-revision-insert[data-revision-id="${CSS.escape((Ke=B.dataset.revisionId)!=null?Ke:"")}"], .coco-word-revision-delete[data-revision-id="${CSS.escape((je=B.dataset.revisionId)!=null?je:"")}"], .coco-word-revision-format[data-revision-id="${CSS.escape((Xt=B.dataset.revisionId)!=null?Xt:"")}"], img[data-revision-id="${CSS.escape((Cn=B.dataset.revisionId)!=null?Cn:"")}"], coco-word-native-table[data-revision-id="${CSS.escape((Vn=B.dataset.revisionId)!=null?Vn:"")}"]`:`.coco-word-comment[data-comment-id="${CSS.escape((Po=B.dataset.commentId)!=null?Po:"")}"]`;return Re.querySelector(ie)})();(!me||!Hu(e,me))&&hn(e,ce.anchor,ce.focus);return}}let F=po(I);if(F){if(d.preventDefault(),d.stopPropagation(),g=null,Et(e),(De=kt(e))==null||De.removeAllRanges(),(h==null?void 0:h.kind)==="table-cell-range"&&h.tableId===F.tableId&&F.point.rowIndex>=Math.min(h.anchor.rowIndex,h.focus.rowIndex)&&F.point.rowIndex<=Math.max(h.anchor.rowIndex,h.focus.rowIndex)&&F.point.columnIndex>=Math.min(h.anchor.columnIndex,h.focus.columnIndex)&&F.point.columnIndex<=Math.max(h.anchor.columnIndex,h.focus.columnIndex))return;ne({kind:"table-cell-range",tableId:F.tableId,anchor:F.point,focus:F.point});return}let G=I instanceof Element?I.closest("a.coco-word-hyperlink"):null;if(G){if(c)return;if(d.preventDefault(),(d.ctrlKey||d.metaKey)&&_y(G.dataset.hyperlinkTarget)){window.open(G.dataset.hyperlinkTarget,"_blank","noopener,noreferrer");return}}if(!(I instanceof HTMLImageElement)){let fe=I instanceof Node?St(I):null,Be=ze(e);if(g=null,Et(e),fe)return;if((Be==null?void 0:Be.kind)==="text-range"){ne(Be);return}let se=ut(e);se&&lt(e,se),ne(se?{kind:"caret",paraId:se.paraId,offset:se.offset}:null);return}let te=St(I),ae=te==null?void 0:te.dataset.paraId,ge=I.dataset.drawingId;!te||!ae||!ge||(te.focus(),g={paraId:ae,drawingId:ge},Et(e),Gt(),ne({kind:"object",paraId:ae,objectKind:"image",objectId:ge,offset:ni(te,I)}));},Xl=d=>{var P;if(d.button!==0||(Qe=false,d.target instanceof Node&&St(d.target)&&(y=null),d.target instanceof HTMLImageElement))return;let m=d.target instanceof Element?d.target:null,x=m?St(m):null,S=(m==null?void 0:m.closest("coco-word-native-page, coco-word-native-p, coco-word-native-table"))!==null,E=m==null?void 0:m.closest("button, input, textarea, select, a");!x&&!S&&!E&&(h==null?void 0:h.kind)==="text-range"?(Ge=true,ot(true)):Ge=false;let I=po(d.target);if(I&&(Ge=false),!I){ct=null,ke=true;return}ke=false;let T=I.point;if(d.shiftKey){if((h==null?void 0:h.kind)==="table-cell-range"&&h.tableId===I.tableId)T=h.anchor;else if(h&&h.kind!=="table-cell-range"){let R=h.kind==="text-range"?h.anchor.paraId:h.paraId,B=Jt(a,R);(B==null?void 0:B.table.tableId)===I.tableId&&(T={rowIndex:B.rowIndex,columnIndex:B.columnIndex});}d.preventDefault(),(P=kt(e))==null||P.removeAllRanges(),ct={tableId:I.tableId,point:T},_t=true,ne({kind:"table-cell-range",tableId:I.tableId,anchor:T,focus:I.point});return}ct={tableId:I.tableId,point:I.point},_t=false;},Yl=d=>{var x;if(ke&&(d.buttons&1)!==0){return}if(!ct||(d.buttons&1)===0)return;let m=po(d.target);!m||m.tableId!==ct.tableId||!_t&&m.point.rowIndex===ct.point.rowIndex&&m.point.columnIndex===ct.point.columnIndex||(d.preventDefault(),(x=kt(e))==null||x.removeAllRanges(),_t=true,ne({kind:"table-cell-range",tableId:ct.tableId,anchor:ct.point,focus:m.point}));},No=()=>{var m;if(ke){let x=ze(e);(x==null?void 0:x.kind)==="text-range"&&(y=x,ne(x),Fe=true),ke=false;}if(_t){(m=kt(e))==null||m.removeAllRanges(),fo(h),It=true,_t=false,ct=null;return}ct=null;let d=ze(e);(d==null?void 0:d.kind)==="text-range"&&(y=d,g=null,Et(e),ne(d));},Zl=()=>{(ct||ke)&&No();},Jl=()=>{var x;if(l||he||we||(h==null?void 0:h.kind)==="object"&&g||(h==null?void 0:h.kind)==="table-cell-range")return;if(Fe&&y){ne(y),ot(true);return}if(Ge){ot(true);return}if(Qe){ot(true);return}let d=document.activeElement;if(d instanceof HTMLElement&&d!==document.body&&d!==i&&!e.contains(d)){ot();return}oa();let m=(x=ze(e))!=null?x:st(e);(m==null?void 0:m.kind)==="text-range"&&(y=m),m&&(dt(),ne(m));},Ql=d=>{d.target;d.composedPath().some(E=>E instanceof Element&&E.matches("coco-word-native-page, coco-word-native-p, coco-word-native-table"))?Qe=false:(h==null?void 0:h.kind)==="text-range"&&(Qe=true),queueMicrotask(ot);},xr=d=>{let m=d.composedPath(),x=m.some(I=>I instanceof Element&&I.matches("coco-word-native-page, coco-word-native-p, coco-word-native-table")),S=m.some(I=>I instanceof HTMLButtonElement&&I.matches("[data-revision-action][data-revision-id], [data-revision-group-toggle]"));if(l||d.button!==0||x||S)return;let E=y!=null?y:(h==null?void 0:h.kind)==="text-range"?h:ze(e);(E==null?void 0:E.kind)==="text-range"&&(h!==E&&ne(E),Qe=true,Ge=true,ot(true),queueMicrotask(()=>ot(true)),window.setTimeout(()=>ot(true),0));},ed=d=>{xr(d),window.setTimeout(()=>ot(true),0);},td=d=>{c&&d.preventDefault();},To=d=>{e.classList.toggle("is-hyperlink-navigation-mode",d.ctrlKey||d.metaKey);},nd=()=>{e.classList.remove("is-hyperlink-navigation-mode");},rd=d=>{var R,B,F,G;if(c)return;let m=d;if(m.inputType===z){z=null,Z!==null&&window.clearTimeout(Z),Z=null;return}if(m.isComposing||he||m.inputType==="insertCompositionText"||m.inputType==="deleteCompositionText")return;if(we){Ve!==null&&window.clearTimeout(Ve),fa();return}if(zm()||m.inputType==="historyUndo"&&Vm()||m.inputType==="historyRedo"&&Gm())return;let x=ut(e),S=(R=St(d.target))!=null?R:x?e.querySelector(`coco-word-native-p[data-para-id="${x.paraId}"]`):null;if(!S||!e.contains(S))return;let E=(B=S.dataset.paraId)!=null?B:"",I=_(a,E);if(!I||I.content.some(te=>te.kind!=="text"))return;let T=Rr(a,E,(F=S.textContent)!=null?F:"");if(!T){(m.inputType==="historyUndo"||m.inputType==="historyRedo")&&sn(E);return}u.push(T);let P=Il(E,T);P&&u.push(P),H&&m.inputType!=="historyUndo"&&m.inputType!=="historyRedo"&&((G=H.afterParagraphs[0])==null?void 0:G.paraId)===E?(H.changes.push(T),H.afterParagraphs=[ue(I)]):H=null,X.length=0,la(E),x&&ne({kind:"caret",paraId:x.paraId,offset:x.offset}),P&&sa(E,x!=null?x:void 0),Ie("deferred");},va=d=>{var x,S;if(l)return false;if(!d){let E=kt(e);return E&&(e.contains(E.anchorNode)||e.contains(E.focusNode))&&E.removeAllRanges(),g=null,Et(e),ne(null),true}if(d.kind==="caret")return _(a,d.paraId)?(g=null,Et(e),lt(e,d),ne(d),true):false;if(d.kind==="text-range")return !_(a,d.anchor.paraId)||!_(a,d.focus.paraId)?false:(g=null,Et(e),hn(e,d.anchor,d.focus),ne(d),true);if(d.kind==="table-cell-range"){let E=(x=Oe(a,d.tableId))==null?void 0:x.table;return !E||at(E,d).length===0?false:(g=null,Et(e),(S=kt(e))==null||S.removeAllRanges(),ne(d),true)}let m=e.querySelector(`coco-word-native-p[data-para-id="${d.paraId}"] img[data-drawing-id="${d.objectId}"]`);return !_(a,d.paraId)||!m?false:(g={paraId:d.paraId,drawingId:d.objectId},Et(e),Gt(),ne(d),true)},od=()=>{D!==null&&window.clearTimeout(D),W!==null&&window.clearTimeout(W),V!==null&&window.clearTimeout(V),ee!==null&&window.clearTimeout(ee),pe!==null&&window.clearTimeout(pe),L!==null&&window.clearTimeout(L),Ve!==null&&window.clearTimeout(Ve),Z!==null&&window.clearTimeout(Z),D=null,W=null,V=null,ee=null,pe=null,L=null,Ve=null,Z=null;};return e.addEventListener("beforeinput",Ul),e.addEventListener("compositionstart",Tl),e.addEventListener("compositionend",Pl),e.addEventListener("copy",ba),e.addEventListener("cut",$l),e.addEventListener("paste",zl),e.addEventListener("drop",td),e.addEventListener("keydown",Io),e.addEventListener("mousedown",Xl),e.addEventListener("click",ql),e.addEventListener("mouseup",No),e.addEventListener("input",rd),e.addEventListener("contextmenu",Vl),document.addEventListener("keydown",Io,true),document.addEventListener("beforeinput",Kl,true),document.addEventListener("selectionchange",Jl),document.addEventListener("focusin",Ql),document.addEventListener("pointerdown",xr,true),document.addEventListener("pointerup",xr,true),document.addEventListener("click",ed,true),document.addEventListener("keydown",To,true),document.addEventListener("keyup",To,true),document.addEventListener("mousemove",Yl),document.addEventListener("pointerdown",Gl,true),document.addEventListener("keydown",jl,true),document.addEventListener("scroll",Rt,true),window.addEventListener("resize",Rt),window.addEventListener("mouseup",Zl),window.addEventListener("blur",nd),Pe(),{kind:"native-word",get destroyed(){return l},isReadOnly(){return c},setReadOnly(d){l||c===d||(c=d,Rt(),c&&(Ye==null||Ye(),Ye=null,re=null,we=null,H=null,he=false),Pe(void 0,h!=null?h:void 0));},destroy(){l||(l=true,e.removeEventListener("beforeinput",Ul),e.removeEventListener("compositionstart",Tl),e.removeEventListener("compositionend",Pl),e.removeEventListener("copy",ba),e.removeEventListener("cut",$l),e.removeEventListener("paste",zl),e.removeEventListener("drop",td),e.removeEventListener("keydown",Io),e.removeEventListener("mousedown",Xl),e.removeEventListener("click",ql),e.removeEventListener("mouseup",No),e.removeEventListener("input",rd),e.removeEventListener("contextmenu",Vl),document.removeEventListener("keydown",Io,true),document.removeEventListener("beforeinput",Kl,true),document.removeEventListener("selectionchange",Jl),document.removeEventListener("focusin",Ql),document.removeEventListener("pointerdown",xr,true),document.removeEventListener("pointerup",xr,true),document.removeEventListener("click",ed,true),document.removeEventListener("keydown",To,true),document.removeEventListener("keyup",To,true),document.removeEventListener("mousemove",Yl),document.removeEventListener("pointerdown",Gl,true),document.removeEventListener("keydown",jl,true),document.removeEventListener("scroll",Rt,true),window.removeEventListener("resize",Rt),window.removeEventListener("mouseup",Zl),window.removeEventListener("blur",nd),window.removeEventListener("resize",go),document.removeEventListener("scroll",go,true),Ye==null||Ye(),Ye=null,Rt(),ia(),oa(),ra.remove(),od(),xo.disconnect(),Xr.get(document)===e&&Xr.delete(document),wt.change.clear(),wt.selectionChange.clear(),o?o.replaceChildren():e.replaceChildren(),e.classList.remove("coco-word-native-editor-host"),e.classList.remove("is-hyperlink-navigation-mode"),r.classList.remove("coco-word-editor-host"));},loadDocument(d){if(l)throw new Error("Cannot load a document into a destroyed Word editor");od(),xo.disconnect(),s=d,Rt(),ia(),a=Ha(s),u.length=0,f=[],w.clear();for(let m of _e(a))w.add(m.paraId);b=Date.now()>>>0,g=null,On(),h=null,re=null,we=null,H=null,he=false,xe=null,z=null,Y.length=0,X.length=0,Pe(),ca();},getSourceView(){return s},getDocument(){return a},getSelection(){var d;return (d=h!=null?h:ze(e))!=null?d:st(e)},setSelection(d){return va(d)},focus(){var x;if(l)return false;let d=(x=h!=null?h:ze(e))!=null?x:st(e);if(d)return va(d);let m=_e(a)[0];return m?va({kind:"caret",paraId:m.paraId,offset:0}):false},async insertImage(d,m={}){if(l)return false;let x=typeof d=="string"?d:await jp(d);return ve(v({kind:"insert-image",src:x},m))},search:Dm,getSearchState(){return ho()},findNext:Hm,replaceCurrent:Qm,replaceAll:eh,clearSearch:ia,getCommandState(){var m;let d=(m=h!=null?h:ze(e))!=null?m:st(e);return Ct(d)},getChanges(){return u.slice()},canUndo(){return !l&&!c&&Y.length>0},canRedo(){return !l&&!c&&X.length>0},undo:hr,redo:gr,canDispatch(d){var x;if(l||c)return false;let m=(x=h!=null?h:ze(e))!=null?x:st(e);return Mt(a,m,d)},dispatch:ve,subscribe(d,m){if(l)return ()=>{};let x=m;return wt[d].add(x),()=>wt[d].delete(x)}}}function ue(e){return $(v({},e),{format:e.format?Jr(e.format):null,content:e.content.map(Ky)})}function Ky(e){return e.kind==="pageBreak"?{kind:"pageBreak"}:e.kind==="text"?v(v($(v({},e),{format:e.format?Jr(e.format):null}),e.marks?{marks:e.marks.map(t=>v({},t))}:{}),e.hyperlink?{hyperlink:v({},e.hyperlink)}:{}):e.kind==="field"?$(v({},e),{format:e.format?Jr(e.format):null}):e.kind==="image"?v(v({},e),e.position?{position:Jr(e.position)}:{}):v(v(v({},e),e.position?{position:Jr(e.position)}:{}),e.paragraphs?{paragraphs:e.paragraphs.map(ue)}:{})}function Jr(e){return JSON.parse(JSON.stringify(e))}function _y(e){return !!e&&/^(https?:|mailto:|tel:)/i.test(e.trim())}function Qn(e){return "beforeBlocks"in e}function qy(e,t){let n=t.kind==="paragraph"?`coco-word-native-p[data-para-id="${t.paraId}"]`:`coco-word-native-table[data-table-id="${t.tableId}"]`;return Array.from(e.querySelectorAll(n))}function zp(e){var n;let t=$s;for(let r of _e(e))for(let o of r.content)if(o.kind==="text")for(let i of (n=o.marks)!=null?n:[])i.kind==="comment"&&(t=Math.max(t,i.commentId));return $s=t+1,$s}function rt(e){var n,r,o,i;let t=zs;for(let s of _e(e))for(let a of s.content)if(a.kind==="text"){for(let u of (n=a.marks)!=null?n:[]){if(u.kind!=="revision")continue;let f=Number(u.revisionId);Number.isInteger(f)&&(t=Math.max(t,f));}let l=a.formatRevision,c=Number(l==null?void 0:l.revisionId);Number.isInteger(c)&&(t=Math.max(t,c));}else if(a.kind==="image"){let l=Number((i=(r=a.revision)==null?void 0:r.revisionId)!=null?i:(o=a.formatRevision)==null?void 0:o.revisionId);Number.isInteger(l)&&(t=Math.max(t,l));}return zs=t+1,String(zs)}function Xy(e,t){return (e==null?void 0:e.kind)!==(t==null?void 0:t.kind)?false:!e||!t?e===t:e.kind==="caret"&&t.kind==="caret"?e.paraId===t.paraId&&e.offset===t.offset:e.kind==="object"&&t.kind==="object"?e.paraId===t.paraId&&e.objectKind===t.objectKind&&e.objectId===t.objectId:e.kind==="text-range"&&t.kind==="text-range"?e.anchor.paraId===t.anchor.paraId&&e.anchor.offset===t.anchor.offset&&e.focus.paraId===t.focus.paraId&&e.focus.offset===t.focus.offset:e.kind==="table-cell-range"&&t.kind==="table-cell-range"?e.tableId===t.tableId&&e.anchor.rowIndex===t.anchor.rowIndex&&e.anchor.columnIndex===t.anchor.columnIndex&&e.focus.rowIndex===t.focus.rowIndex&&e.focus.columnIndex===t.focus.columnIndex:false}function Vp(e,t){let n=t==="before"?e.beforeSelection:e.afterSelection;return n||(!e.changes.every(r=>r.kind==="format"||r.kind==="list")||e.range.anchor.paraId===e.range.focus.paraId&&e.range.anchor.offset===e.range.focus.offset?null:{kind:"text-range",anchor:e.range.anchor,focus:e.range.focus})}function Gp(e){return e.skipDeferredRender?false:e.changes.some(t=>t.kind==="block"||t.kind==="image"||t.kind==="page-break"||t.kind==="list"?true:t.kind!=="format"?false:t.op==="paragraph"?t.format.alignment===void 0:t.clear===true||t.format.bold!==void 0||t.format.italic!==void 0||t.format.fontFamily!==void 0||t.format.fontSize!==void 0)}function Kp(e,t){var n,r;return (r=(n=e.querySelector(`coco-word-native-p[data-para-id="${t}"]`))==null?void 0:n.textContent)!=null?r:null}function pi(e,t){return t.every(n=>Kp(e,n.paraId)===Te(n))}function fi(e,t){return {from:Math.max(0,Math.min(e,t)),to:Math.max(0,Math.max(e,t))}}function jp(e){return new Promise((t,n)=>{let r=new FileReader;r.addEventListener("load",()=>{var o;return t(String((o=r.result)!=null?o:""))}),r.addEventListener("error",()=>{var o;return n((o=r.error)!=null?o:new Error("Unable to read clipboard image"))}),r.readAsDataURL(e);})}function mi(e){let t=Ar(e);if(!t)return "";Os=Os+1>>>0;let n=`${Up}${Date.now().toString(36)}-${Os.toString(36)}`;for(Zr.set(n,t);Zr.size>8;){let r=Zr.keys().next().value;if(!r)break;Zr.delete(r);}return n}function Yy(e){var t;return e.startsWith(Up)?(t=Zr.get(e))!=null?t:"":e}function Zy(e){var t;return e.kind==="text"?e.text:e.kind==="field"?(t=e.cachedText)!=null?t:"\uFFFC":e.kind==="drawing"&&e.text?e.text:"\uFFFC"}async function Jy(e){let t=Xc(e);if(t.type==="image/png")return t;let n=await createImageBitmap(t);try{let r=document.createElement("canvas");r.width=n.width,r.height=n.height;let o=r.getContext("2d");if(!o)throw new Error("Unable to create clipboard image canvas");return o.drawImage(n,0,0),await new Promise((i,s)=>{r.toBlob(a=>a?i(a):s(new Error("Unable to encode clipboard image")),"image/png");})}finally{n.close();}}function hi(e){return e.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;")}function Qy(e){let t={};return Number.isFinite(e.left)&&(t.left=Math.max(0,e.left)),Number.isFinite(e.right)&&(t.right=Math.max(0,e.right)),Number.isFinite(e.firstLine)&&(t.firstLine=e.firstLine),t}function ev(e){let t={};return Number.isFinite(e.before)&&(t.before=Math.max(0,e.before)),Number.isFinite(e.after)&&(t.after=Math.max(0,e.after)),t}function et(e,t){if(t.anchor.paraId===t.focus.paraId&&t.anchor.offset<=t.focus.offset)return {anchor:t.anchor,focus:t.focus};if(t.anchor.paraId!==t.focus.paraId){let n=be(e,t.anchor.paraId),r=be(e,t.focus.paraId);if(n&&r&&n.container===r.container)return n.index<=r.index?{anchor:t.anchor,focus:t.focus}:{anchor:t.focus,focus:t.anchor}}return {anchor:t.focus,focus:t.anchor}}function gi(e,t){return `${e}:${t}`}function Qr(e,t,n={}){var f,p,w;let r=new Map,o=new Map,i=new Map,s=new Map,a=new Map,l=new Map,c=(f=n.minimumRows)!=null?f:100,u=(p=n.minimumColumns)!=null?p:26;for(let b of e.rows)i.set(b.index,b),c=Math.max(c,b.index);for(let b of e.columns){for(let g=b.min;g<=b.max;g++)s.set(g,b);u=Math.max(u,b.max);}for(let b of e.cells){let g=qp(b,t,n.formulaResults,n.date1904);r.set(b.address,g),o.set(gi(b.row,b.column),g),c=Math.max(c,b.row),u=Math.max(u,b.column);}for(let[b,g]of (w=n.formulaResults)!=null?w:[]){if(r.has(b)||g.error)continue;let h=excel.parseCellAddress(b),y={address:b,row:h.row,column:h.column,kind:"formula",value:null},k=qp(y,t,n.formulaResults,n.date1904);r.set(b,k),o.set(gi(h.row,h.column),k),c=Math.max(c,h.row),u=Math.max(u,h.column);}for(let b of e.mergedRanges){let g=excel.parseRangeAddress(b.address),h=g.startRow+g.rowCount-1,y=g.startColumn+g.columnCount-1,k={startRow:g.startRow,startColumn:g.startColumn,endRow:h,endColumn:y},C=excel.formatCellAddress(g.startRow,g.startColumn),N={address:b.address,range:k,masterAddress:C,source:b};a.set(C,N),c=Math.max(c,h),u=Math.max(u,y);for(let L=g.startRow;L<=h;L++)for(let D=g.startColumn;D<=y;D++){let W=excel.formatCellAddress(L,D);W!==C&&l.set(W,C);}}return {sheetId:e.id,sheetName:e.name,source:e,styles:t,cellsByAddress:r,cellsByRowColumn:o,rowMetaByIndex:i,columnMetaByIndex:s,mergeMasterByAddress:a,mergeFollowerByAddress:l,maxRow:c,maxColumn:u}}function qe(e,t,n){return e.cellsByRowColumn.get(gi(t,n))}function qp(e,t,n,r=false){var a,l;let o=n==null?void 0:n.get(e.address),i=o&&!o.error?o.value:void 0,s=Array.isArray(i)?(l=(a=i[0])==null?void 0:a[0])!=null?l:null:i!=null?i:e.value;return {row:e.row,column:e.column,address:e.address,kind:e.kind,value:s,displayText:rv(e,t,s,o,r),formula:e.formula,styleId:e.styleId,source:e}}function rv(e,t,n,r,o=false){return r!=null&&r.error?r.displayText:n!==null?iv(n,ov(e,t),o):""}function ov(e,t){var n,r;return (r=t.cellFormats[(n=e.styleId)!=null?n:0])==null?void 0:r.numberFormatCode}function iv(e,t,n=false){if(e===null)return "";if(typeof e!="number"||!t)return String(e);let r=t.toLowerCase();return r.includes("%")?`${wi(e*100,bi(t))}%`:r.includes("$")?`$${wi(e,bi(t),true)}`:av(r)?sv(e,r,n):t.includes(",")?wi(e,bi(t),true):t.includes(".")?wi(e,bi(t)):String(e)}function bi(e){var n,r;let t=/\.(0+)/.exec(e);return (r=(n=t==null?void 0:t[1])==null?void 0:n.length)!=null?r:0}function wi(e,t,n=false){return new Intl.NumberFormat("en-US",{minimumFractionDigits:t,maximumFractionDigits:t,useGrouping:n}).format(e)}function av(e){return ["d-mmm","mmm-yy","h:mm am/pm","h:mm:ss am/pm","h:mm","h:mm:ss","mm:ss","[h]:mm:ss","mmss.0"].includes(e)?true:/(^|[^a-z])y{2,4}([^a-z]|$)/.test(e)&&/(^|[^a-z])d{1,2}([^a-z]|$)/.test(e)}function sv(e,t,n){if(!Number.isFinite(e))return String(e);let r=Math.floor(e),o=e-r,i=Math.round(o*86400)%86400,s=Math.floor(i/3600),a=Math.floor(i%3600/60),l=i%60,c=s%12||12,u=s<12?"AM":"PM",f=D=>String(D).padStart(2,"0");if(t==="h:mm am/pm")return `${c}:${f(a)} ${u}`;if(t==="h:mm:ss am/pm")return `${c}:${f(a)}:${f(l)} ${u}`;if(t==="h:mm")return `${s}:${f(a)}`;if(t==="h:mm:ss")return `${s}:${f(a)}:${f(l)}`;if(t==="mm:ss")return `${f(a)}:${f(l)}`;if(t==="[h]:mm:ss")return `${Math.floor(e*24)}:${f(a)}:${f(l)}`;if(t==="mmss.0")return `${f(a)}${f(l)}.0`;let p=!n&&r===60,w=n?Date.UTC(1904,0,1):Date.UTC(1899,11,30),b=new Date(w+r*864e5),g=p?1900:b.getUTCFullYear(),h=p?2:b.getUTCMonth()+1,y=p?29:b.getUTCDate(),k=f(h),C=f(y),N=f(g%100),L=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][h-1];return t==="mm-dd-yy"?`${k}-${C}-${N}`:t==="d-mmm-yy"?`${y}-${L}-${N}`:t==="d-mmm"?`${y}-${L}`:t==="mmm-yy"?`${L}-${N}`:t==="m/d/yy h:mm"?`${h}/${y}/${N} ${s}:${f(a)}`:`${g}-${k}-${C}`}var dv=22,cv=96,uv=48,pv=24,fv=96/72,Vs=7,mv=5,xi=class{constructor(t,n={}){O(this,"model",t);O(this,"defaultRowHeight");O(this,"defaultColumnWidth");O(this,"rowHeaderWidth");O(this,"columnHeaderHeight");O(this,"rowCount");O(this,"columnCount");O(this,"rowOffsets");O(this,"columnOffsets");O(this,"rowHeights");O(this,"columnWidths");var r,o,i,s,a,l;this.defaultRowHeight=(r=n.defaultRowHeight)!=null?r:dv,this.defaultColumnWidth=(o=n.defaultColumnWidth)!=null?o:cv,this.rowHeaderWidth=(i=n.rowHeaderWidth)!=null?i:uv,this.columnHeaderHeight=(s=n.columnHeaderHeight)!=null?s:pv,this.rowCount=Math.max((a=n.rowCount)!=null?a:0,t.maxRow),this.columnCount=Math.max((l=n.columnCount)!=null?l:0,t.maxColumn),this.rowHeights=hv(t,this.rowCount,this.defaultRowHeight),this.columnWidths=gv(t,this.columnCount,this.defaultColumnWidth),this.rowOffsets=Xp(this.rowHeights),this.columnOffsets=Xp(this.columnWidths);}totalWidth(){var t;return (t=this.columnOffsets[this.columnOffsets.length-1])!=null?t:0}totalHeight(){var t;return (t=this.rowOffsets[this.rowOffsets.length-1])!=null?t:0}getColumnWidth(t){var n;return (n=this.columnWidths[t-1])!=null?n:this.defaultColumnWidth}getRowHeight(t){var n;return (n=this.rowHeights[t-1])!=null?n:this.defaultRowHeight}getColumnX(t){var n;return (n=this.columnOffsets[Math.max(0,t-1)])!=null?n:0}getRowY(t){var n;return (n=this.rowOffsets[Math.max(0,t-1)])!=null?n:0}getCellLogicalRect(t,n){return {x:this.getColumnX(n),y:this.getRowY(t),width:this.getColumnWidth(n),height:this.getRowHeight(t)}}getRangeLogicalRect(t){let n=this.getColumnX(t.startColumn),r=this.getRowY(t.startRow),o=this.getColumnX(t.endColumn)+this.getColumnWidth(t.endColumn),i=this.getRowY(t.endRow)+this.getRowHeight(t.endRow);return {x:n,y:r,width:o-n,height:i-r}}getVisibleRange(t,n,r,o=1,i=1){let s=Math.max(i,this.columnAt(t)),a=Math.max(o,this.rowAt(n)),l=Math.max(s,Math.min(this.columnCount,this.columnAt(t+r.width)+1)),c=Math.max(a,Math.min(this.rowCount,this.rowAt(n+r.height)+1));return {startRow:a,startColumn:s,endRow:c,endColumn:l}}rowAt(t){return Zp(Yp(this.rowOffsets,t),this.rowCount)}columnAt(t){return Zp(Yp(this.columnOffsets,t),this.columnCount)}hitTestLogical(t,n){let r=this.columnAt(t),o=this.rowAt(n);return o<1||r<1||o>this.rowCount||r>this.columnCount?{kind:"none"}:{kind:"cell",row:o,column:r,address:excel.formatCellAddress(o,r)}}};function hv(e,t,n){let r=[];for(let o=1;o<=t;o++){let i=e.rowMetaByIndex.get(o);r.push(i!=null&&i.hidden?0:(i==null?void 0:i.height)===void 0?n:i.height*fv);}return r}function gv(e,t,n){let r=[];for(let o=1;o<=t;o++){let i=e.columnMetaByIndex.get(o);r.push(i!=null&&i.hidden?0:(i==null?void 0:i.width)===void 0?n:bv(i.width));}return r}function bv(e){return !Number.isFinite(e)||e<=0?0:Math.floor((256*e+Math.floor(128/Vs))/256*Vs)}function yi(e){return !Number.isFinite(e)||e<=0?0:Math.floor((e-mv)/Vs*256)/256}function Xp(e){var n;let t=[0];for(let r of e)t.push(((n=t[t.length-1])!=null?n:0)+r);return t}function Yp(e,t){var o;if(t<=0)return 1;let n=0,r=e.length-1;for(;n<r;){let i=Math.floor((n+r+1)/2);((o=e[i])!=null?o:0)<=t?n=i:r=i-1;}return n+1}function Zp(e,t){return Math.max(1,Math.min(t,e))}var vi=class{constructor(t,n){O(this,"layout",t);O(this,"scroll");O(this,"freeze");O(this,"viewportSize");O(this,"viewports");var r,o,i,s,a,l,c,u;this.viewportSize=n.viewportSize,this.freeze={frozenRows:Math.max(0,(o=(r=n.freeze)==null?void 0:r.frozenRows)!=null?o:0),frozenColumns:Math.max(0,(s=(i=n.freeze)==null?void 0:i.frozenColumns)!=null?s:0)},this.scroll=xv(t,this.freeze,n.viewportSize,{x:(l=(a=n.scroll)==null?void 0:a.x)!=null?l:0,y:(u=(c=n.scroll)==null?void 0:c.y)!=null?u:0}),this.viewports=yv(t,this.viewportSize,this.scroll,this.freeze);}hitTest(t){let n=this.findViewport(t);if(!n)return {kind:"none"};if(n.kind==="corner")return {kind:"corner"};let r=t.x-n.screenRect.x+n.originX,o=t.y-n.screenRect.y+n.originY;return n.kind==="columnHeaderScrollable"||n.kind==="columnHeaderFrozen"?{kind:"columnHeader",column:this.layout.columnAt(r)}:n.kind==="rowHeaderScrollable"||n.kind==="rowHeaderFrozen"?{kind:"rowHeader",row:this.layout.rowAt(o)}:this.layout.hitTestLogical(r,o)}findViewport(t){for(let n=this.viewports.length-1;n>=0;n--){let r=this.viewports[n];if(r&&vv(r.screenRect,t))return r}}cellScreenRect(t,n,r){let o=this.layout.getCellLogicalRect(t,n);return {x:r.screenRect.x+o.x-r.originX,y:r.screenRect.y+o.y-r.originY,width:o.width,height:o.height}}};function Si(e){var n;let t=(n=e.sheetViews[0])==null?void 0:n.pane;return wv(t)}function wv(e){var t,n;return !e||e.state!=="frozen"?{frozenRows:0,frozenColumns:0}:{frozenRows:Math.max(0,Math.floor((t=e.ySplit)!=null?t:0)),frozenColumns:Math.max(0,Math.floor((n=e.xSplit)!=null?n:0))}}function xv(e,t,n,r){let o=e.getColumnX(t.frozenColumns+1),i=e.getRowY(t.frozenRows+1),s=Math.max(0,n.width-e.rowHeaderWidth-o),a=Math.max(0,n.height-e.columnHeaderHeight-i),l=Math.max(0,e.totalWidth()-o-s),c=Math.max(0,e.totalHeight()-i-a);return {x:Math.max(0,Math.min(l,r.x)),y:Math.max(0,Math.min(c,r.y))}}function yv(e,t,n,r){let o=e.rowHeaderWidth,i=e.columnHeaderHeight,s=e.getColumnX(r.frozenColumns+1),a=e.getRowY(r.frozenRows+1),l=s+n.x,c=a+n.y,u=Math.max(0,t.width-o),f=Math.max(0,t.height-i),p=o+s,w=i+a,b=Math.max(0,t.width-p),g=Math.max(0,t.height-w),h=[];return h.push({kind:"corner",screenRect:{x:0,y:0,width:o,height:i},originX:0,originY:0,rows:{start:1,end:0},columns:{start:1,end:0}}),r.frozenColumns>0&&h.push({kind:"columnHeaderFrozen",screenRect:{x:o,y:0,width:Math.min(s,u),height:i},originX:0,originY:0,rows:{start:1,end:0},columns:{start:1,end:r.frozenColumns}}),h.push({kind:"columnHeaderScrollable",screenRect:{x:o+s,y:0,width:Math.max(0,t.width-o-s),height:i},originX:l,originY:0,rows:{start:1,end:0},columns:js(e,l,b,r.frozenColumns+1)}),r.frozenRows>0&&h.push({kind:"rowHeaderFrozen",screenRect:{x:0,y:i,width:o,height:Math.min(a,f)},originX:0,originY:0,rows:{start:1,end:r.frozenRows},columns:{start:1,end:0}}),h.push({kind:"rowHeaderScrollable",screenRect:{x:0,y:i+a,width:o,height:Math.max(0,t.height-i-a)},originX:0,originY:c,rows:Gs(e,c,g,r.frozenRows+1),columns:{start:1,end:0}}),r.frozenRows>0&&r.frozenColumns>0&&h.push({kind:"frozenTopLeft",screenRect:{x:o,y:i,width:s,height:a},originX:0,originY:0,rows:{start:1,end:r.frozenRows},columns:{start:1,end:r.frozenColumns}}),r.frozenRows>0&&h.push({kind:"frozenTop",screenRect:{x:p,y:i,width:b,height:a},originX:l,originY:0,rows:{start:1,end:r.frozenRows},columns:js(e,l,b,r.frozenColumns+1)}),r.frozenColumns>0&&h.push({kind:"frozenLeft",screenRect:{x:o,y:w,width:s,height:g},originX:0,originY:c,rows:Gs(e,c,g,r.frozenRows+1),columns:{start:1,end:r.frozenColumns}}),h.push({kind:"main",screenRect:{x:p,y:w,width:b,height:g},originX:l,originY:c,rows:Gs(e,c,g,r.frozenRows+1),columns:js(e,l,b,r.frozenColumns+1)}),h.filter(y=>y.screenRect.width>0&&y.screenRect.height>0)}function Gs(e,t,n,r){let o=e.getVisibleRange(0,t,{width:1,height:n},r,1);return {start:o.startRow,end:o.endRow}}function js(e,t,n,r){let o=e.getVisibleRange(t,0,{width:n,height:1},1,r);return {start:o.startColumn,end:o.endColumn}}function vv(e,t){return t.x>=e.x&&t.y>=e.y&&t.x<e.x+e.width&&t.y<e.y+e.height}function Ei(e,t,n){var l,c,u,f,p,w,b,g,h,y,k,C,N,L;let r=(l=e.cellFormats[t!=null?t:0])!=null?l:{},o=(u=e.fonts[(c=r.fontId)!=null?c:0])!=null?u:{},i=(f=o.size)!=null?f:11,s=(w=e.fills[(p=r.fillId)!=null?p:0])!=null?w:{},a=(g=e.borders[(b=r.borderId)!=null?b:0])!=null?g:{};return {font:Sv(o.bold,o.italic,i,(h=o.name)!=null?h:"Arial"),fontSize:i,underline:o.underline===true,fontColor:(k=(y=o.color)==null?void 0:y.rgb)!=null?k:"#111827",fillColor:(N=(C=s.foregroundColor)==null?void 0:C.rgb)!=null?N:"#FFFFFF",wrapText:((L=r.alignment)==null?void 0:L.wrapText)===true,border:a,horizontalAlign:Ev(r,n),verticalAlign:Cv(r)}}function Jp(e,t){let n={};for(let a=t.startColumn;a<=t.endColumn;a++)(n.top)!=null||(n.top=ki(e,t.startRow,a,"top")),(n.bottom)!=null||(n.bottom=ki(e,t.endRow,a,"bottom"));for(let a=t.startRow;a<=t.endRow;a++)(n.left)!=null||(n.left=ki(e,a,t.startColumn,"left")),(n.right)!=null||(n.right=ki(e,a,t.endColumn,"right"));return n}function ki(e,t,n,r){var s,a,l,c;let o=qe(e,t,n),i=(a=e.styles.cellFormats[(s=o==null?void 0:o.styleId)!=null?s:0])!=null?a:{};return (c=e.styles.borders[(l=i.borderId)!=null?l:0])==null?void 0:c[r]}function Sv(e,t,n,r){let o=[];return t&&o.push("italic"),e&&o.push("600"),o.push(`${n}px`),o.push(kv(r)),o.join(" ")}function kv(e){return /\s/.test(e)?JSON.stringify(e):e}function Ev(e,t){var n;switch((n=e.alignment)==null?void 0:n.horizontal){case "left":return "left";case "center":return "center";case "right":return "right"}return (t==null?void 0:t.kind)==="number"||(t==null?void 0:t.kind)==="formula"&&typeof t.value=="number"?"right":(t==null?void 0:t.kind)==="boolean"||(t==null?void 0:t.kind)==="error"?"center":"left"}function Cv(e){var t;switch((t=e.alignment)==null?void 0:t.vertical){case "top":return "top";case "center":case "middle":return "middle";case "bottom":return "bottom";default:return "bottom"}}var Ti=class{constructor(t){O(this,"options",t);O(this,"baseCtx");O(this,"headerCtx");O(this,"overlayCtx");O(this,"cssWidth",1);O(this,"cssHeight",1);O(this,"scaleX",1);O(this,"scaleY",1);O(this,"headerFiltersEnabled",true);O(this,"headerFilterColumns",null);O(this,"activeHeaderFilterColumns",new Set);this.baseCtx=Ci(t.baseCanvas),this.headerCtx=Ci(t.headerCanvas),this.overlayCtx=Ci(t.overlayCanvas);}resize(t,n,r=globalThis.devicePixelRatio||1){this.cssWidth=Math.max(1,t),this.cssHeight=Math.max(1,n);let o=Math.max(1,r||1);for(let i of [this.options.baseCanvas,this.options.headerCanvas,this.options.overlayCanvas]){i.style.width=`${this.cssWidth}px`,i.style.height=`${this.cssHeight}px`,i.width=Math.max(1,Math.ceil(this.cssWidth*o)),i.height=Math.max(1,Math.ceil(this.cssHeight*o));let s=Ci(i);this.scaleX=i.width/this.cssWidth,this.scaleY=i.height/this.cssHeight,s.setTransform(this.scaleX,0,0,this.scaleY,0,0),s.imageSmoothingEnabled=false;}}setHeaderFiltersEnabled(t){this.headerFiltersEnabled=t;}setHeaderFilterColumns(t){this.headerFilterColumns=t===null?null:new Set(t);}setActiveHeaderFilterColumns(t){this.activeHeaderFilterColumns=new Set(t);}render(t,n){this.clearAll(t,n),this.drawCells(t,n),this.drawHeaders(t,n);}clearOverlay(){Ii(this.overlayCtx,this.options.overlayCanvas);}renderSelection(t,n,r,o={}){this.clearOverlay();let i=this.overlayCtx;for(let s of n.viewports){if(!Ni(s))continue;let a=ef(r,{startRow:s.rows.start,endRow:s.rows.end,startColumn:s.columns.start,endColumn:s.columns.end});if(!a)continue;let l=t.getRangeLogicalRect(a),c=Us(l,s);eo(i,s.screenRect,()=>{i.fillStyle="rgba(37, 99, 235, 0.08)",i.fillRect(c.x,c.y,c.width,c.height),i.strokeStyle="#2563EB",i.lineWidth=2/this.scaleX,i.setLineDash([]),no(i,_s(c,1),this.scaleX,this.scaleY);});}o.showFillHandle&&this.drawFillHandle(t,n,r);}fillHandleRect(t,n,r){for(let o of n.viewports){if(!Ni(o)||r.endRow<o.rows.start||r.endRow>o.rows.end||r.endColumn<o.columns.start||r.endColumn>o.columns.end)continue;let i=n.cellScreenRect(r.endRow,r.endColumn,o),s=7;return {x:i.x+i.width-s/2,y:i.y+i.height-s/2,width:s,height:s}}return null}renderCopiedRange(t,n,r){this.renderDashedRange(t,n,r,{stroke:"#1D4ED8"});}renderDashedRange(t,n,r,o){let i=this.overlayCtx;for(let s of n.viewports){if(!Ni(s))continue;let a=ef(r,{startRow:s.rows.start,endRow:s.rows.end,startColumn:s.columns.start,endColumn:s.columns.end});if(!a)continue;let l=t.getRangeLogicalRect(a),c=Us(l,s);eo(i,s.screenRect,()=>{i.save(),o.fill&&(i.fillStyle=o.fill,i.fillRect(c.x,c.y,c.width,c.height)),i.strokeStyle=o.stroke,i.lineWidth=2/this.scaleX,i.setLineDash([4,3]),i.lineDashOffset=0,no(i,_s(c,2),this.scaleX,this.scaleY),i.restore();});}}clearAll(t,n){Ii(this.baseCtx,this.options.baseCanvas),Ii(this.headerCtx,this.options.headerCanvas),Ii(this.overlayCtx,this.options.overlayCanvas);}drawFillHandle(t,n,r){let o=this.fillHandleRect(t,n,r);if(!o)return;let i=this.overlayCtx;i.save(),i.fillStyle="#2563EB",i.fillRect(o.x,o.y,o.width,o.height),i.strokeStyle="#FFFFFF",i.lineWidth=1/this.scaleX,no(i,_s(o,.5),this.scaleX,this.scaleY),i.restore();}drawCells(t,n){let r=this.baseCtx;r.save(),r.fillStyle="#FFFFFF",r.fillRect(0,0,this.cssWidth,this.cssHeight),r.restore();for(let o of n.viewports)Ni(o)&&eo(r,o.screenRect,()=>{for(let i=o.rows.start;i<=o.rows.end;i++)for(let s=o.columns.start;s<=o.columns.end;s++){let a=excel.formatCellAddress(i,s);if(!t.model.mergeFollowerByAddress.get(a)&&(this.drawCell(r,t,n,o,i,s,{drawBorder:false,reserveTrailingSpace:this.headerFiltersEnabled&&i===1}),this.headerFiltersEnabled&&i===1&&(this.headerFilterColumns===null||this.headerFilterColumns.has(s)))){let c=t.getCellLogicalRect(i,s),u={x:o.screenRect.x+c.x-o.originX,y:o.screenRect.y+c.y-o.originY,width:c.width,height:c.height};Nv(r,u,this.scaleX,this.scaleY,this.activeHeaderFilterColumns.has(s));}}for(let i=o.rows.start;i<=o.rows.end;i++)for(let s=o.columns.start;s<=o.columns.end;s++){let a=excel.formatCellAddress(i,s);t.model.mergeFollowerByAddress.get(a)||this.drawCell(r,t,n,o,i,s,{drawContent:false});}});}drawCell(t,n,r,o,i,s,a={}){let l=qe(n.model,i,s),c=l?n.model.mergeMasterByAddress.get(l.address):void 0,u=c?Us(n.getRangeLogicalRect(c.range),o):r.cellScreenRect(i,s,o),f=Ei(n.model.styles,l==null?void 0:l.styleId,l),p=c?Jp(n.model,c.range):f.border;if(a.drawContent!==false&&(t.fillStyle=f.fillColor,t.fillRect(u.x,u.y,u.width,u.height),t.strokeStyle="#E5E7EB",t.lineWidth=1/this.scaleX,no(t,u,this.scaleX,this.scaleY)),a.drawBorder!==false&&Tv(t,u,p,this.scaleX,this.scaleY),a.drawContent===false||!(l!=null&&l.displayText))return;t.save(),t.font=f.font,t.fillStyle=f.fontColor,t.textAlign=f.horizontalAlign,t.textBaseline="middle";let w=6,b=a.reserveTrailingSpace&&u.width>=28?22:0,g={x:u.x,y:u.y,width:Math.max(1,u.width-b),height:u.height},h=f.horizontalAlign==="right"?g.x+g.width-w:f.horizontalAlign==="center"?g.x+g.width/2:g.x+w;eo(t,g,()=>{let y=f.wrapText||l.displayText.includes(`
1540
- `)?Mv(t,l.displayText,Math.max(1,g.width-w*2)):[l.displayText],k=f.fontSize*1.2,C=y.length*k,N=Pv(u,f,w,C,k);for(let L=0;L<y.length;L++){let D=y[L],W=N+L*k;t.fillText(D,h,W),f.underline&&Rv(t,D,h,W,f,this.scaleX,this.scaleY);}}),t.restore();}drawHeaders(t,n){let r=this.headerCtx;for(let o of n.viewports)eo(r,o.screenRect,()=>{if(o.kind==="corner")Ks(r,o.screenRect,"",this.scaleX,this.scaleY);else if(o.kind==="columnHeaderFrozen"||o.kind==="columnHeaderScrollable")for(let i=o.columns.start;i<=o.columns.end;i++){let s=t.getCellLogicalRect(1,i),a={x:o.screenRect.x+s.x-o.originX,y:o.screenRect.y,width:s.width,height:o.screenRect.height};Ks(r,a,excel.columnIndexToName(i),this.scaleX,this.scaleY);}else if(o.kind==="rowHeaderFrozen"||o.kind==="rowHeaderScrollable")for(let i=o.rows.start;i<=o.rows.end;i++){let s=t.getCellLogicalRect(i,1),a={x:o.screenRect.x,y:o.screenRect.y+s.y-o.originY,width:o.screenRect.width,height:s.height};Ks(r,a,String(i),this.scaleX,this.scaleY);}});}};function Nv(e,t,n,r,o=false){if(t.width<28)return;let i=t.x+t.width-10,s=t.y+t.height/2;e.save(),e.strokeStyle=o?"#2563EB":"#64748B",e.lineWidth=1/n,e.lineCap="round",e.beginPath(),e.moveTo(i-4,s-3),e.lineTo(i+4,s-3),e.lineTo(i+1,s+1),e.lineTo(i+1,s+4),e.lineTo(i-1,s+3),e.lineTo(i-1,s+1),e.closePath(),e.stroke(),e.restore();}function ef(e,t){let n=Math.max(e.startRow,t.startRow),r=Math.max(e.startColumn,t.startColumn),o=Math.min(e.endRow,t.endRow),i=Math.min(e.endColumn,t.endColumn);return n>o||r>i?null:{startRow:n,startColumn:r,endRow:o,endColumn:i}}function Ci(e){let t=e.getContext("2d");if(!t)throw new Error("SpreadsheetCanvasRenderer: 2D canvas context is unavailable");return t}function Ii(e,t){let n=Number.parseFloat(t.style.width)||t.width,r=Number.parseFloat(t.style.height)||t.height;e.clearRect(0,0,n,r);}function eo(e,t,n){e.save(),e.beginPath(),e.rect(t.x,t.y,t.width,t.height),e.clip(),n(),e.restore();}function Ni(e){return e.kind==="main"||e.kind==="frozenTop"||e.kind==="frozenLeft"||e.kind==="frozenTopLeft"}function Us(e,t){return {x:t.screenRect.x+e.x-t.originX,y:t.screenRect.y+e.y-t.originY,width:e.width,height:e.height}}function Ks(e,t,n,r,o){e.fillStyle="#F3F4F6",e.fillRect(t.x,t.y,t.width,t.height),e.strokeStyle="#D1D5DB",e.lineWidth=1/r,no(e,t,r,o),n&&(e.font="12px Arial",e.fillStyle="#374151",e.textAlign="center",e.textBaseline="middle",e.fillText(n,t.x+t.width/2,t.y+t.height/2));}function Tv(e,t,n,r,o){var i,s,a,l,c,u,f,p;!n.left&&!n.right&&!n.top&&!n.bottom||(e.save(),e.lineWidth=1/r,e.setLineDash([]),n.top&&(e.strokeStyle=(s=(i=n.top.color)==null?void 0:i.rgb)!=null?s:"#111827",to(e,t.x,t.y,t.x+t.width,t.y,r,o)),n.right&&(e.strokeStyle=(l=(a=n.right.color)==null?void 0:a.rgb)!=null?l:"#111827",to(e,t.x+t.width,t.y,t.x+t.width,t.y+t.height,r,o)),n.bottom&&(e.strokeStyle=(u=(c=n.bottom.color)==null?void 0:c.rgb)!=null?u:"#111827",to(e,t.x,t.y+t.height,t.x+t.width,t.y+t.height,r,o)),n.left&&(e.strokeStyle=(p=(f=n.left.color)==null?void 0:f.rgb)!=null?p:"#111827",to(e,t.x,t.y,t.x,t.y+t.height,r,o)),e.restore());}function Pv(e,t,n,r,o){return t.verticalAlign==="top"?e.y+n+o/2:t.verticalAlign==="bottom"?e.y+e.height-n-r+o/2:e.y+(e.height-r)/2+o/2}function Mv(e,t,n){let r=[];for(let o of t.split(/\r?\n/)){if(o===""){r.push("");continue}let i="";for(let s of o){let a=i+s;i&&e.measureText(a).width>n?(r.push(i),i=s):i=a;}i&&r.push(i);}return r.length>0?r:[""]}function to(e,t,n,r,o,i,s){e.beginPath(),e.moveTo(bn(t,i),bn(n,s)),e.lineTo(bn(r,i),bn(o,s)),e.stroke();}function Rv(e,t,n,r,o,i,s){let a=e.measureText(t),l=a.width,c=o.horizontalAlign==="right"?n-l:o.horizontalAlign==="center"?n-l/2:n,u=Math.max(2,(a.actualBoundingBoxDescent||o.fontSize*.18)+1);e.save(),e.strokeStyle=o.fontColor,e.lineWidth=1/i,to(e,c,r+u,c+l,r+u,i,s),e.restore();}function _s(e,t){return {x:e.x+t,y:e.y+t,width:Math.max(0,e.width-t*2),height:Math.max(0,e.height-t*2)}}function no(e,t,n,r){let o=bn(t.x,n),i=bn(t.y,r),s=bn(t.x+t.width,n),a=bn(t.y+t.height,r);e.strokeRect(o,i,Math.max(0,s-o),Math.max(0,a-i));}function bn(e,t){return (Math.round(e*t)+.5)/t}function gt(e,t){return {kind:"cell",active:{row:e,column:t},range:{startRow:e,startColumn:t,endRow:e,endColumn:t}}}function qs(e,t){return {kind:"row",active:{row:e,column:1},range:{startRow:e,startColumn:1,endRow:e,endColumn:t.columnCount}}}function vI(e,t,n){let r=We({startRow:e,startColumn:1,endRow:t,endColumn:n.columnCount});return {kind:"row",active:{row:r.startRow,column:1},range:r}}function Xs(e,t){return {kind:"column",active:{row:1,column:e},range:{startRow:1,startColumn:e,endRow:t.rowCount,endColumn:e}}}function SI(e,t,n){let r=We({startRow:1,startColumn:e,endRow:n.rowCount,endColumn:t});return {kind:"column",active:{row:1,column:r.startColumn},range:r}}function We(e){return {startRow:Math.min(e.startRow,e.endRow),startColumn:Math.min(e.startColumn,e.endColumn),endRow:Math.max(e.startRow,e.endRow),endColumn:Math.max(e.startColumn,e.endColumn)}}function Pi(e,t,n,r){var o,i;return e.kind==="row"?{kind:"row",active:e.active,range:We({startRow:e.active.row,startColumn:1,endRow:t,endColumn:(o=r==null?void 0:r.columnCount)!=null?o:e.range.endColumn})}:e.kind==="column"?{kind:"column",active:e.active,range:We({startRow:1,startColumn:e.active.column,endRow:(i=r==null?void 0:r.rowCount)!=null?i:e.range.endRow,endColumn:n})}:{kind:"cell",active:e.active,range:We({startRow:e.active.row,startColumn:e.active.column,endRow:t,endColumn:n})}}function kI(e,t,n,r){return gt(er(e.active.row+t,1,r.rowCount),er(e.active.column+n,1,r.columnCount))}function Kt(e,t){var r;if(e.kind!=="cell")return e;let n=(r=Bv(e.active.row,e.active.column,t))!=null?r:e.active;return $(v({},e),{active:n,range:Lv(e.range,t)})}function Lv(e,t){let n=We(e),r=true;for(;r;){r=false;for(let o of t.mergeMasterByAddress.values()){if(!Wv(n,o.range))continue;let i={startRow:Math.min(n.startRow,o.range.startRow),startColumn:Math.min(n.startColumn,o.range.startColumn),endRow:Math.max(n.endRow,o.range.endRow),endColumn:Math.max(n.endColumn,o.range.endColumn)};r=i.startRow!==n.startRow||i.startColumn!==n.startColumn||i.endRow!==n.endRow||i.endColumn!==n.endColumn,n=i;}}return n}function EI(e,t,n,r,o){let i=er(tf(e.active.row,t,n),1,r.rowCount),s=er(e.active.column,1,r.columnCount);return e.kind==="row"?qs(i,{columnCount:r.columnCount}):Kt(gt(i,s),o)}function CI(e,t,n,r,o){let i=er(e.active.row,1,r.rowCount),s=er(tf(e.active.column,t,n),1,r.columnCount);return e.kind==="column"?Xs(s,{rowCount:r.rowCount}):Kt(gt(i,s),o)}function tf(e,t,n){let r=t+n-1;return e<t?e:e>r?e-n:t}function Wv(e,t){return !(e.endRow<t.startRow||e.startRow>t.endRow||e.endColumn<t.startColumn||e.startColumn>t.endColumn)}function Bv(e,t,n){let r=n.mergeFollowerByAddress.get(excel.formatCellAddress(e,t));if(!r)return null;let o=n.mergeMasterByAddress.get(r);return o?{row:o.range.startRow,column:o.range.startColumn}:null}function er(e,t,n){return Math.max(t,Math.min(n,e))}function Ys(e,t){let n=Hv(e,t);return {text:n,values:Zs(n),styleIds:Vv(e,t),merges:zv(e,t)}}function Hv(e,t){let n=[];for(let r=t.startRow;r<=t.endRow;r++){let o=[];for(let i=t.startColumn;i<=t.endColumn;i++)o.push(Ov($v(e,r,i)));n.push(o.join(" "));}return n.join(`
1541
- `)}function Zs(e){return e.replace(/\r\n/g,`
1544
+ `).map(T=>T.split(" "));wa(S,{text:I});return}let E=S.kind==="text-range"?et(a,S):{anchor:{paraId:S.paraId,offset:S.offset},focus:{paraId:S.paraId,offset:S.offset}};Vn(E,x);}catch(x){console.warn("Unable to paste from the context menu",x);}},ka=(d="add",m,x="")=>{let S=document.createElement("div");S.className="coco-word-dialog-backdrop";let E=document.createElement("section");E.className="coco-word-dialog",E.setAttribute("role","dialog"),E.setAttribute("aria-modal","true"),E.setAttribute("aria-labelledby","coco-word-comment-dialog-title");let I=document.createElement("h2");I.id="coco-word-comment-dialog-title",I.textContent=d==="edit"?"\u7F16\u8F91\u6279\u6CE8":d==="reply"?"\u56DE\u590D\u6279\u6CE8":"\u6DFB\u52A0\u6279\u6CE8";let T=document.createElement("textarea");T.className="coco-word-dialog-input",T.placeholder="\u6279\u6CE8\u5185\u5BB9",T.rows=4,T.value=x;let P=document.createElement("div");P.className="coco-word-dialog-actions";let R=document.createElement("button");R.type="button",R.className="coco-word-dialog-button is-secondary",R.textContent="\u53D6\u6D88";let B=document.createElement("button");B.type="button",B.className="coco-word-dialog-button is-primary",B.textContent="\u786E\u5B9A";let D=()=>S.remove();R.addEventListener("click",D),S.addEventListener("click",G=>{G.target===S&&D();}),E.addEventListener("keydown",G=>{G.key==="Escape"&&D(),G.key==="Enter"&&(G.ctrlKey||G.metaKey)&&(G.preventDefault(),B.click());}),B.addEventListener("click",()=>{let G=T.value.trim();if(!G){T.focus();return}ve(d==="edit"&&m!==void 0?{kind:"edit-comment",commentId:m,body:G}:d==="reply"&&m!==void 0?{kind:"reply-comment",commentId:m,body:G}:{kind:"add-comment",body:G}),D();}),P.append(R,B),E.append(I,T,P),S.appendChild(E),(o!=null?o:document.body).appendChild(S),T.focus();},ch=()=>{var E,I,T;let d=(E=h!=null?h:ze(e))!=null?E:st(e),m=Ct(d),x=(d==null?void 0:d.kind)==="text-range"||(d==null?void 0:d.kind)==="object"||(d==null?void 0:d.kind)==="table-cell-range",S=[{label:"\u526A\u5207",disabled:!x,action:()=>document.execCommand("cut")},{label:"\u590D\u5236",disabled:!x,action:()=>document.execCommand("copy")},{label:"\u7C98\u8D34\u4E3A\u7EAF\u6587\u672C",disabled:(d==null?void 0:d.kind)==="object"||typeof((I=navigator.clipboard)==null?void 0:I.readText)!="function",action:dh},{label:"\u5220\u9664",disabled:!x,action:()=>lh()}];if((d==null?void 0:d.kind)==="text-range"&&(S.push({label:"\u6DFB\u52A0\u6279\u6CE8",separatorBefore:true,action:ka}),S.push({label:"\u6807\u8BB0\u4E3A\u63D2\u5165\u4FEE\u8BA2",action:()=>ve({kind:"add-revision",revisionKind:"insert"})}),S.push({label:"\u6807\u8BB0\u4E3A\u5220\u9664\u4FEE\u8BA2",action:()=>ve({kind:"add-revision",revisionKind:"delete"})}),S.push({label:m.bold===true?"\u53D6\u6D88\u52A0\u7C97":"\u52A0\u7C97",separatorBefore:true,disabled:!Mt(a,d,{kind:"toggle-bold"}),action:()=>ve({kind:"toggle-bold"})}),S.push({label:"\u6E05\u9664\u6587\u672C\u683C\u5F0F",action:()=>ve({kind:"clear-text-format"})}),m.hyperlink!==null&&S.push({label:"\u79FB\u9664\u8D85\u94FE\u63A5",disabled:!Mt(a,d,{kind:"remove-hyperlink"}),action:()=>ve({kind:"remove-hyperlink"})})),(d==null?void 0:d.kind)==="caret"&&Mt(a,d,{kind:"insert-table",rows:2,columns:2})&&S.push({label:"\u63D2\u5165 2 \xD7 2 \u8868\u683C",separatorBefore:true,action:()=>ve({kind:"insert-table",rows:2,columns:2})}),(d==null?void 0:d.kind)==="object"&&d.objectKind==="image"&&(S.push({label:"\u56FE\u7247\u5DE6\u5BF9\u9F50",separatorBefore:true,action:()=>ve({kind:"set-image-alignment",objectId:d.objectId,alignment:"left"})}),S.push({label:"\u56FE\u7247\u5C45\u4E2D",action:()=>ve({kind:"set-image-alignment",objectId:d.objectId,alignment:"center"})}),S.push({label:"\u56FE\u7247\u53F3\u5BF9\u9F50",action:()=>ve({kind:"set-image-alignment",objectId:d.objectId,alignment:"right"})})),m.table){let P=(T=m.table.range)!=null?T:{startRow:m.table.rowIndex,endRow:m.table.rowIndex,startColumn:m.table.columnIndex,endColumn:m.table.columnIndex};S.push({label:"\u9009\u62E9\u6574\u884C",separatorBefore:true,action:()=>ne({kind:"table-cell-range",tableId:m.table.tableId,anchor:{rowIndex:P.startRow,columnIndex:0},focus:{rowIndex:P.endRow,columnIndex:Math.max(0,m.table.columnCount-1)}})}),S.push({label:"\u9009\u62E9\u6574\u5217",action:()=>ne({kind:"table-cell-range",tableId:m.table.tableId,anchor:{rowIndex:0,columnIndex:P.startColumn},focus:{rowIndex:Math.max(0,m.table.rowCount-1),columnIndex:P.endColumn}})}),S.push({label:"\u5728\u4E0A\u65B9\u63D2\u5165\u884C",disabled:!Mt(a,d,{kind:"insert-table-row"}),action:()=>ve({kind:"insert-table-row",position:"before"})}),S.push({label:"\u5728\u4E0B\u65B9\u63D2\u5165\u884C",disabled:!Mt(a,d,{kind:"insert-table-row"}),action:()=>ve({kind:"insert-table-row",position:"after"})}),S.push({label:"\u5220\u9664\u5F53\u524D\u884C",disabled:!Mt(a,d,{kind:"delete-table-row"}),action:()=>ve({kind:"delete-table-row"})}),S.push({label:"\u5728\u5DE6\u4FA7\u63D2\u5165\u5217",disabled:!Mt(a,d,{kind:"insert-table-column"}),action:()=>ve({kind:"insert-table-column",position:"before"})}),S.push({label:"\u5728\u53F3\u4FA7\u63D2\u5165\u5217",disabled:!Mt(a,d,{kind:"insert-table-column"}),action:()=>ve({kind:"insert-table-column",position:"after"})}),S.push({label:"\u5220\u9664\u5F53\u524D\u5217",disabled:!Mt(a,d,{kind:"delete-table-column"}),action:()=>ve({kind:"delete-table-column"})}),S.push({label:"\u5220\u9664\u8868\u683C",separatorBefore:true,disabled:!Mt(a,d,{kind:"delete-table"}),action:()=>ve({kind:"delete-table"})});for(let[R,B]of [["\u5355\u5143\u683C\u9876\u90E8\u5BF9\u9F50","top"],["\u5355\u5143\u683C\u5782\u76F4\u5C45\u4E2D","center"],["\u5355\u5143\u683C\u5E95\u90E8\u5BF9\u9F50","bottom"]])S.push({label:R,action:()=>ve({kind:"set-table-cell-vertical-alignment",alignment:B})});}return S.push({label:"\u64A4\u9500",separatorBefore:true,disabled:!Y.length,action:()=>br()},{label:"\u91CD\u505A",disabled:!X.length,action:()=>wr()}),S},uh=d=>{var I,T;let m=d.target;if(m instanceof HTMLImageElement){let P=St(m),R=P==null?void 0:P.dataset.paraId,B=m.dataset.drawingId;if(P&&R&&B){let D={kind:"object",paraId:R,objectKind:"image",objectId:B,offset:ai(P,m)};return g={paraId:R,drawingId:B},Gt(),ne(D),D}}let x=ho(m);if(x){if((h==null?void 0:h.kind)==="table-cell-range"&&h.tableId===x.tableId){let R=Math.min(h.anchor.rowIndex,h.focus.rowIndex),B=Math.max(h.anchor.rowIndex,h.focus.rowIndex),D=Math.min(h.anchor.columnIndex,h.focus.columnIndex),G=Math.max(h.anchor.columnIndex,h.focus.columnIndex);if(x.point.rowIndex>=R&&x.point.rowIndex<=B&&x.point.columnIndex>=D&&x.point.columnIndex<=G)return h}let P={kind:"table-cell-range",tableId:x.tableId,anchor:x.point,focus:x.point};return (I=kt(e))==null||I.removeAllRanges(),ne(P),P}let S=(T=zu(e,d.clientX,d.clientY))!=null?T:ut(e);if(!S)return h;if((h==null?void 0:h.kind)==="text-range"){let P=et(a,h),R=be(a,P.anchor.paraId),B=be(a,P.focus.paraId),D=be(a,S.paraId);if(R&&B&&D&&R.container===B.container&&R.container===D.container){let G=D.index>R.index||D.index===R.index&&S.offset>=P.anchor.offset,te=D.index<B.index||D.index===B.index&&S.offset<=P.focus.offset;if(G&&te)return h}}g=null,Et(e),lt(e,S);let E=v({kind:"caret"},S);return ne(E),E},Kl=d=>{var S;if(c||n.contextMenu===false)return;d.preventDefault(),d.stopPropagation(),dt(),Rt(),uh(d);let m=document.createElement("div");m.className="coco-word-context-menu",m.setAttribute("role","menu"),m.contentEditable="false";for(let E of ch()){if(E.separatorBefore){let T=document.createElement("div");T.className="coco-word-context-menu-separator",T.setAttribute("role","separator"),m.appendChild(T);}let I=document.createElement("button");I.type="button",I.className="coco-word-context-menu-item",I.textContent=E.label,I.disabled=(S=E.disabled)!=null?S:false,I.setAttribute("role","menuitem"),I.addEventListener("mousedown",T=>T.preventDefault()),I.addEventListener("click",()=>{let T=E.action();Rt(),T instanceof Promise&&T.catch(P=>console.warn("Context menu action failed",P));}),m.appendChild(I);}(o!=null?o:document.body).appendChild(m),Vt=m;let x=m.getBoundingClientRect();m.style.left=`${Math.max(4,Math.min(d.clientX,window.innerWidth-x.width-4))}px`,m.style.top=`${Math.max(4,Math.min(d.clientY,window.innerHeight-x.height-4))}px`;},_l=d=>{Vt&&!Vt.contains(d.target)&&Rt();},ql=d=>{d.key==="Escape"&&Rt();},Xl=d=>{var E;if(c){d.preventDefault();return}if(d.inputType===z){d.preventDefault(),z=null,Z!==null&&window.clearTimeout(Z),Z=null;return}if(d.inputType==="historyUndo"&&br()){d.preventDefault(),d.stopPropagation();return}if(d.inputType==="historyRedo"&&wr()){d.preventDefault(),d.stopPropagation();return}if(d.isComposing||he||we||d.inputType==="insertCompositionText"||d.inputType==="deleteCompositionText"||d.inputType==="insertFromComposition")return;if(g&&d.inputType==="deleteContentBackward"){d.preventDefault();let I={paraId:g.paraId,offset:0};kn(g.paraId,g.drawingId,I);return}let m=ze(e),x=(m==null?void 0:m.kind)==="text-range"?m:(h==null?void 0:h.kind)==="text-range"?h:m;if(k&&x&&(d.inputType==="insertText"||d.inputType==="deleteContentBackward"||d.inputType==="deleteContentForward")){if(x.kind==="caret"||x.kind==="text-range"&&x.anchor.paraId===x.focus.paraId){d.preventDefault(),d.inputType==="insertText"&&d.data?x.kind==="caret"?ve({kind:"insert-text",text:d.data}):ve({kind:"replace-range",anchor:x.anchor,focus:x.focus,text:d.data}):d.inputType==="deleteContentBackward"?x.kind==="text-range"&&x.anchor.offset!==x.focus.offset?ve({kind:"delete-range",anchor:x.anchor,focus:x.focus}):ve({kind:"delete-backward"}):d.inputType==="deleteContentForward"&&(x.kind==="text-range"&&x.anchor.offset!==x.focus.offset?ve({kind:"delete-range",anchor:x.anchor,focus:x.focus}):ve({kind:"delete-forward"}));return}if(x.kind==="text-range"&&(d.inputType==="deleteContentBackward"||d.inputType==="deleteContentForward")){d.preventDefault(),ve({kind:"delete-range",anchor:x.anchor,focus:x.focus});return}}if((x==null?void 0:x.kind)==="text-range"&&x.anchor.paraId===x.focus.paraId){let I=bi(x.anchor.offset,x.focus.offset);if(ko(x.anchor.paraId)&&(d.inputType==="insertText"&&d.data||d.inputType==="deleteContentBackward"||d.inputType==="deleteContentForward")){g=null,hr(x.anchor.paraId),Eo({anchor:{paraId:x.anchor.paraId,offset:I.from},focus:{paraId:x.focus.paraId,offset:I.to}}),ne(x);return}if(d.inputType==="insertText"&&d.data){d.preventDefault(),g=null,ne({kind:"caret",paraId:x.anchor.paraId,offset:I.from+d.data.length}),Sn(Ar(a,x.anchor.paraId,I.from,I.to,d.data),{paraId:x.anchor.paraId,offset:I.from+d.data.length},{localParaId:x.anchor.paraId});return}if(d.inputType==="deleteContentBackward"||d.inputType==="deleteContentForward"){if(d.preventDefault(),g=null,No(x))return;ne({kind:"caret",paraId:x.anchor.paraId,offset:I.from}),Sn(pn(a,x.anchor.paraId,I.from,I.to),{paraId:x.anchor.paraId,offset:I.from},{localParaId:x.anchor.paraId});return}}if((x==null?void 0:x.kind)==="text-range"&&x.anchor.paraId!==x.focus.paraId){let I=et(a,x);if(d.inputType==="insertText"&&d.data){if(d.preventDefault(),g=null,Io(I,d.data))return;Bl(I,d.data);return}if(d.inputType==="deleteContentBackward"||d.inputType==="deleteContentForward"){if(Io(I,"")){d.preventDefault();return}if(!qm(I)&&jm(I)){g=null,ne({kind:"caret",paraId:I.anchor.paraId,offset:I.anchor.offset});return}d.preventDefault(),g=null,ne({kind:"caret",paraId:I.anchor.paraId,offset:I.anchor.offset}),Bl(I,"");return}d.preventDefault(),ne(x);return}let S=(x==null?void 0:x.kind)==="caret"?x:ut(e);if(S){if(g=null,ne({kind:"caret",paraId:S.paraId,offset:S.offset}),d.inputType==="insertText"&&d.data&&d.data!==`
1545
+ `&&d.data!=="\r"&&ko(S.paraId)){hr(S.paraId),Eo({anchor:S,focus:S});return}if(d.inputType==="deleteContentBackward"&&S.offset>0&&ko(S.paraId)){hr(S.paraId),Eo({anchor:S,focus:S});return}if(d.inputType==="deleteContentForward"&&S.offset<ha(S.paraId)&&ko(S.paraId)){hr(S.paraId),Eo({anchor:S,focus:S});return}if(d.inputType==="insertText"&&(d.data===`
1546
+ `||d.data==="\r")||d.inputType==="insertParagraph"){if(d.preventDefault(),N){N=false,L!==null&&window.clearTimeout(L),L=null;return}ya(S);}else if(d.inputType==="insertText"&&d.data)d.preventDefault(),Sn(en(a,S.paraId,S.offset,d.data),{paraId:S.paraId,offset:S.offset+d.data.length},{localParaId:S.paraId});else if(d.inputType==="deleteContentBackward"){if(d.preventDefault(),En(S,"delete-backward")||To(v({kind:"caret"},S),"backward")||Ol(S))return;let I=_(a,S.paraId),T=I?ue(I):null,P=Mr(a,S.paraId,S.offset),R={paraId:S.offset>0?S.paraId:(E=Ga(a,S.paraId))!=null?E:S.paraId,offset:Math.max(0,S.offset-1)};(P==null?void 0:P.kind)==="image"?xr(T,P,R):Sn(P,R,(P==null?void 0:P.kind)==="block"?{}:{localParaId:S.paraId});}else if(d.inputType==="deleteContentForward"){if(d.preventDefault(),En(S,"delete-forward")||To(v({kind:"caret"},S),"forward")||$l(S))return;let I=_(a,S.paraId),T=I?ue(I):null,P=Rr(a,S.paraId,S.offset),R={paraId:S.paraId,offset:S.offset};(P==null?void 0:P.kind)==="image"?xr(T,P,R):Sn(P,R,{localParaId:S.paraId});}}},Po=d=>{var R,B,D,G,te,ae,ge,Ne;if(l)return;if(d.currentTarget===document){if(d.composedPath().includes(e)||Jr.get(document)!==e)return}else dt();if(he||d.isComposing||d.keyCode===229)return;if((d.ctrlKey||d.metaKey)&&!d.shiftKey&&d.key.toLowerCase()==="c"&&g&&typeof((R=navigator.clipboard)==null?void 0:R.write)=="function"&&typeof ClipboardItem!="undefined"){let j=g;d.preventDefault(),d.stopPropagation(),Sa(j).catch(q=>{console.warn("Unable to copy the selected image",q);});return}if(c){(d.ctrlKey||d.metaKey)&&(d.key.toLowerCase()==="z"||d.key.toLowerCase()==="y")&&(d.preventDefault(),d.stopPropagation());return}let x=(d.ctrlKey||d.metaKey)&&!d.shiftKey&&d.key.toLowerCase()==="z",S=(d.ctrlKey||d.metaKey)&&d.shiftKey&&d.key.toLowerCase()==="z"||(d.ctrlKey||d.metaKey)&&d.key.toLowerCase()==="y";(x||S)&&z&&(z=null,Z!==null&&window.clearTimeout(Z),Z=null);let E=x||S?ut(e):null,I=(B=E==null?void 0:E.paraId)!=null?B:h&&"paraId"in h?h.paraId:null;if(x&&br()){Pl("historyUndo"),d.preventDefault(),d.stopPropagation();return}if(S&&wr()){Pl("historyRedo"),d.preventDefault(),d.stopPropagation();return}if((d.ctrlKey||d.metaKey)&&!d.shiftKey&&d.key==="Enter"){let j=(D=h!=null?h:ze(e))!=null?D:st(e);(j==null?void 0:j.kind)==="caret"&&ve({kind:"insert-page-break"})&&(d.preventDefault(),d.stopPropagation());return}if((x||S)&&(V!==null&&window.clearTimeout(V),So.disconnect(),V=window.setTimeout(()=>{var de,le;V=null;let j=ut(e),q=(de=j==null?void 0:j.paraId)!=null?de:I;if(!q)return;let J=e.querySelector(`coco-word-native-p[data-para-id="${q}"]`),Q=_(a,q);if(J&&Q&&Q.content.every(K=>K.kind==="text")){let K=Wr(a,q,(le=J.textContent)!=null?le:"");K&&(u.push(K),Ie("deferred"));}Le(q,j!=null?j:void 0);},120)),(h==null?void 0:h.kind)==="table-cell-range"){if(d.key==="Escape"){d.preventDefault(),ne(null);return}if(d.key==="Enter"||d.key==="F2"){let q=(G=Oe(a,h.tableId))==null?void 0:G.table,J=q?(te=at(q,h)[0])==null?void 0:te.cell:null,Q=J==null?void 0:J.paragraphs[0];if(Q){d.preventDefault();let de={paraId:Q.paraId,offset:Te(Q).length};lt(e,de),ne(v({kind:"caret"},de));}return}let j=d.key==="ArrowLeft"?{row:0,column:-1}:d.key==="ArrowRight"?{row:0,column:1}:d.key==="ArrowUp"?{row:-1,column:0}:d.key==="ArrowDown"?{row:1,column:0}:null;if(j){let q=(ae=Oe(a,h.tableId))==null?void 0:ae.table,J=q?Math.max(1,...q.rows.map(de=>de.cells.reduce((le,K)=>le+Math.max(1,K.gridSpan),0))):1,Q={rowIndex:Math.max(0,Math.min(((ge=q==null?void 0:q.rows.length)!=null?ge:1)-1,h.focus.rowIndex+j.row)),columnIndex:Math.max(0,Math.min(J-1,h.focus.columnIndex+j.column))};d.preventDefault(),ne({kind:"table-cell-range",tableId:h.tableId,anchor:d.shiftKey?h.anchor:Q,focus:Q});return}}if(!d.shiftKey&&["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"].includes(d.key)&&(H=null),g&&(d.key==="Backspace"||d.key==="Delete")){d.preventDefault();let j={paraId:g.paraId,offset:0};kn(g.paraId,g.drawingId,j);return}if((h==null?void 0:h.kind)==="table-cell-range"&&(d.key==="Backspace"||d.key==="Delete")){d.preventDefault(),d.stopPropagation(),zn(h);return}if(d.key!=="Enter")return;let T=ut(e);if(!T)return;d.preventDefault(),d.stopPropagation();let P=_(a,T.paraId);if((Ne=P==null?void 0:P.format)!=null&&Ne.hasNumbering&&P.format.numbering&&Te(P).length===0){g=null,ne({kind:"caret",paraId:T.paraId,offset:0}),ve({kind:"remove-list"});return}g=null,N=true,L!==null&&window.clearTimeout(L),L=window.setTimeout(()=>{N=false,L=null;},0),ya(T);},Yl=d=>{if(!(l||d.composedPath().includes(e)||Jr.get(document)!==e)){if(c){d.preventDefault(),d.stopPropagation();return}(d.inputType==="historyUndo"&&br()||d.inputType==="historyRedo"&&wr())&&(d.preventDefault(),d.stopPropagation());}},Ea=(d,m)=>{let x=d.querySelector(":scope > .coco-word-native-revision-group-list"),S=d.querySelector(":scope > .coco-word-native-revision-group-toggle");if(!x||!S)return;d.classList.toggle("is-expanded",m),x.hidden=!m,S.setAttribute("aria-expanded",String(m));let E=S.querySelector(".coco-word-native-revision-group-affordance");E&&(E.textContent=m?"\u6536\u8D77":"\u5C55\u5F00");},Zl=d=>{e.querySelectorAll(".coco-word-native-revision-group.is-expanded").forEach(m=>{m!==d&&Ea(m,false);});},Jl=d=>{var Ne,j,q,J,Q,de,le,K,Ee,Fe;let m=(Ne=d.composedPath().find(fe=>fe instanceof HTMLButtonElement&&fe.matches("[data-revision-action][data-revision-id]")))!=null?Ne:d.target instanceof Element?d.target.closest("[data-revision-action][data-revision-id]"):null;if(m){d.preventDefault(),d.stopPropagation();let fe=m.dataset.revisionId;fe&&ve({kind:m.dataset.revisionAction==="accept"?"accept-revision":"reject-revision",revisionId:fe,revisionKind:m.dataset.revisionKind});return}let x=(j=d.composedPath().find(fe=>fe instanceof HTMLButtonElement&&fe.matches("[data-revision-group-toggle]")))!=null?j:d.target instanceof Element?d.target.closest("[data-revision-group-toggle]"):null;if(x){d.preventDefault(),d.stopPropagation();let fe=x.closest(".coco-word-native-revision-group"),Be=fe==null?void 0:fe.querySelector(":scope > .coco-word-native-revision-group-list");if(!fe||!Be)return;let se=Be.hidden;Zl(fe),Ea(fe,se);return}let S=(q=d.composedPath().find(fe=>fe instanceof HTMLButtonElement&&fe.matches("[data-comment-menu][data-comment-id]")))!=null?q:d.target instanceof Element?d.target.closest("[data-comment-menu][data-comment-id]"):null;if(S){d.preventDefault(),d.stopPropagation();let fe=S.dataset.commentId;if(!fe)return;let Be=(J=S.parentElement)==null?void 0:J.querySelector(`[data-comment-menu-for="${CSS.escape(fe)}"]`);if(!Be)return;e.querySelectorAll(".coco-word-native-comment-menu:not([hidden])").forEach(se=>{se!==Be&&(se.hidden=true);}),Be.hidden=!Be.hidden;return}let E=(Q=d.composedPath().find(fe=>fe instanceof HTMLButtonElement&&fe.matches("[data-comment-action][data-comment-id]")))!=null?Q:d.target instanceof Element?d.target.closest("[data-comment-action][data-comment-id]"):null;if(E){d.preventDefault(),d.stopPropagation();let fe=Number(E.dataset.commentId);if(!Number.isFinite(fe))return;let Be=E.closest(".coco-word-native-comment-bubble");E.dataset.commentAction==="edit"?ka("edit",fe,(de=Be==null?void 0:Be.dataset.commentBody)!=null?de:""):E.dataset.commentAction==="reply"?ka("reply",fe):ve({kind:"delete-comment",commentId:fe});return}if(De){De=false,d.preventDefault(),d.stopPropagation();return}if(It){It=false,d.preventDefault(),d.stopPropagation();return}if(Ge){d.preventDefault(),d.stopPropagation(),ot(true),queueMicrotask(()=>{Ge=false,ot(true);});return}dt(),H=null;let I=d.target,T=I instanceof Element?I.closest(".coco-word-comment[data-comment-id]"):null,P=I instanceof Element?I.closest(".coco-word-revision-insert[data-revision-id], .coco-word-revision-delete[data-revision-id], .coco-word-revision-format[data-revision-id], img[data-revision-id], coco-word-native-table[data-revision-id]"):null,R=I instanceof Element?I.closest(".coco-word-native-comment-bubble, .coco-word-native-revision-bubble"):null,B=R!=null?R:T?e.querySelector(`.coco-word-native-comment-bubble[data-comment-id="${CSS.escape((le=T.dataset.commentId)!=null?le:"")}"]`):P?e.querySelector(`.coco-word-native-revision-bubble[data-revision-id="${CSS.escape((K=P.dataset.revisionId)!=null?K:"")}"][data-revision-kind="${CSS.escape((Ee=P.dataset.revisionKind)!=null?Ee:P.classList.contains("coco-word-revision-delete")?"delete":"insert")}"]`):null;if(B){let fe=B.closest(".coco-word-native-revision-group");fe&&(Zl(fe),Ea(fe,true));let Be=B.dataset.paraId,se=Number(B.dataset.from),Ze=Number(B.dataset.to);if(Be&&Number.isFinite(se)&&Number.isFinite(Ze)){d.preventDefault(),d.stopPropagation(),e.querySelectorAll(".coco-word-native-comment-bubble.is-selected, .coco-word-native-revision-bubble.is-selected").forEach(Re=>Re.classList.remove("is-selected")),B.classList.add("is-selected");let ce={kind:"text-range",anchor:{paraId:Be,offset:se},focus:{paraId:Be,offset:Math.max(se+1,Ze)}};ne(ce);let me=T!=null?T:(()=>{var Ke,je,Yt,In,Gn,Ao;let Re=R==null?void 0:R.closest("coco-word-native-page");if(!Re)return null;let ie=B.dataset.revisionKind?`.coco-word-revision-insert[data-revision-id="${CSS.escape((Ke=B.dataset.revisionId)!=null?Ke:"")}"], .coco-word-revision-delete[data-revision-id="${CSS.escape((je=B.dataset.revisionId)!=null?je:"")}"], .coco-word-revision-format[data-revision-id="${CSS.escape((Yt=B.dataset.revisionId)!=null?Yt:"")}"], img[data-revision-id="${CSS.escape((In=B.dataset.revisionId)!=null?In:"")}"], coco-word-native-table[data-revision-id="${CSS.escape((Gn=B.dataset.revisionId)!=null?Gn:"")}"]`:`.coco-word-comment[data-comment-id="${CSS.escape((Ao=B.dataset.commentId)!=null?Ao:"")}"]`;return Re.querySelector(ie)})();(!me||!Vu(e,me))&&gn(e,ce.anchor,ce.focus);return}}let D=ho(I);if(D){if(d.preventDefault(),d.stopPropagation(),g=null,Et(e),(Fe=kt(e))==null||Fe.removeAllRanges(),(h==null?void 0:h.kind)==="table-cell-range"&&h.tableId===D.tableId&&D.point.rowIndex>=Math.min(h.anchor.rowIndex,h.focus.rowIndex)&&D.point.rowIndex<=Math.max(h.anchor.rowIndex,h.focus.rowIndex)&&D.point.columnIndex>=Math.min(h.anchor.columnIndex,h.focus.columnIndex)&&D.point.columnIndex<=Math.max(h.anchor.columnIndex,h.focus.columnIndex))return;ne({kind:"table-cell-range",tableId:D.tableId,anchor:D.point,focus:D.point});return}let G=I instanceof Element?I.closest("a.coco-word-hyperlink"):null;if(G){if(c)return;if(d.preventDefault(),(d.ctrlKey||d.metaKey)&&rv(G.dataset.hyperlinkTarget)){window.open(G.dataset.hyperlinkTarget,"_blank","noopener,noreferrer");return}}if(!(I instanceof HTMLImageElement)){let fe=I instanceof Node?St(I):null,Be=ze(e);if(g=null,Et(e),fe)return;if((Be==null?void 0:Be.kind)==="text-range"){ne(Be);return}let se=ut(e);se&&lt(e,se),ne(se?{kind:"caret",paraId:se.paraId,offset:se.offset}:null);return}let te=St(I),ae=te==null?void 0:te.dataset.paraId,ge=I.dataset.drawingId;!te||!ae||!ge||(te.focus(),g={paraId:ae,drawingId:ge},Et(e),Gt(),ne({kind:"object",paraId:ae,objectKind:"image",objectId:ge,offset:ai(te,I)}));},Ql=d=>{var P;if(d.button!==0||(Qe=false,d.target instanceof Node&&St(d.target)&&(y=null),d.target instanceof HTMLImageElement))return;let m=d.target instanceof Element?d.target:null,x=m?St(m):null,S=(m==null?void 0:m.closest("coco-word-native-page, coco-word-native-p, coco-word-native-table"))!==null,E=m==null?void 0:m.closest("button, input, textarea, select, a");!x&&!S&&!E&&(h==null?void 0:h.kind)==="text-range"?(Ge=true,ot(true)):Ge=false;let I=ho(d.target);if(I&&(Ge=false),!I){ct=null,ke=true;return}ke=false;let T=I.point;if(d.shiftKey){if((h==null?void 0:h.kind)==="table-cell-range"&&h.tableId===I.tableId)T=h.anchor;else if(h&&h.kind!=="table-cell-range"){let R=h.kind==="text-range"?h.anchor.paraId:h.paraId,B=Qt(a,R);(B==null?void 0:B.table.tableId)===I.tableId&&(T={rowIndex:B.rowIndex,columnIndex:B.columnIndex});}d.preventDefault(),(P=kt(e))==null||P.removeAllRanges(),ct={tableId:I.tableId,point:T},qt=true,ne({kind:"table-cell-range",tableId:I.tableId,anchor:T,focus:I.point});return}ct={tableId:I.tableId,point:I.point},qt=false;},ed=d=>{var x;if(ke&&(d.buttons&1)!==0){return}if(!ct||(d.buttons&1)===0)return;let m=ho(d.target);!m||m.tableId!==ct.tableId||!qt&&m.point.rowIndex===ct.point.rowIndex&&m.point.columnIndex===ct.point.columnIndex||(d.preventDefault(),(x=kt(e))==null||x.removeAllRanges(),qt=true,ne({kind:"table-cell-range",tableId:ct.tableId,anchor:ct.point,focus:m.point}));},Mo=()=>{var m;if(ke){let x=ze(e);(x==null?void 0:x.kind)==="text-range"&&(y=x,ne(x),De=true),ke=false;}if(qt){(m=kt(e))==null||m.removeAllRanges(),go(h),It=true,qt=false,ct=null;return}ct=null;let d=ze(e);(d==null?void 0:d.kind)==="text-range"&&(y=d,g=null,Et(e),ne(d));},td=()=>{(ct||ke)&&Mo();},nd=()=>{var x;if(l||he||we||(h==null?void 0:h.kind)==="object"&&g||(h==null?void 0:h.kind)==="table-cell-range")return;if(De&&y){ne(y),ot(true);return}if(Ge){ot(true);return}if(Qe){ot(true);return}let d=document.activeElement;if(d instanceof HTMLElement&&d!==document.body&&d!==i&&!e.contains(d)){ot();return}la();let m=(x=ze(e))!=null?x:st(e);(m==null?void 0:m.kind)==="text-range"&&(y=m),m&&(dt(),ne(m));},rd=d=>{d.target;d.composedPath().some(E=>E instanceof Element&&E.matches("coco-word-native-page, coco-word-native-p, coco-word-native-table"))?Qe=false:(h==null?void 0:h.kind)==="text-range"&&(Qe=true),queueMicrotask(ot);},vr=d=>{let m=d.composedPath(),x=m.some(I=>I instanceof Element&&I.matches("coco-word-native-page, coco-word-native-p, coco-word-native-table")),S=m.some(I=>I instanceof HTMLButtonElement&&I.matches("[data-revision-action][data-revision-id], [data-revision-group-toggle]"));if(l||d.button!==0||x||S)return;let E=y!=null?y:(h==null?void 0:h.kind)==="text-range"?h:ze(e);(E==null?void 0:E.kind)==="text-range"&&(h!==E&&ne(E),Qe=true,Ge=true,ot(true),queueMicrotask(()=>ot(true)),window.setTimeout(()=>ot(true),0));},od=d=>{vr(d),window.setTimeout(()=>ot(true),0);},id=d=>{c&&d.preventDefault();},Ro=d=>{e.classList.toggle("is-hyperlink-navigation-mode",d.ctrlKey||d.metaKey);},ad=()=>{e.classList.remove("is-hyperlink-navigation-mode");},sd=d=>{var R,B,D,G;if(c)return;let m=d;if(m.inputType===z){z=null,Z!==null&&window.clearTimeout(Z),Z=null;return}if(m.isComposing||he||m.inputType==="insertCompositionText"||m.inputType==="deleteCompositionText")return;if(we){Ve!==null&&window.clearTimeout(Ve),ba();return}if(Um()||m.inputType==="historyUndo"&&Km()||m.inputType==="historyRedo"&&_m())return;let x=ut(e),S=(R=St(d.target))!=null?R:x?e.querySelector(`coco-word-native-p[data-para-id="${x.paraId}"]`):null;if(!S||!e.contains(S))return;let E=(B=S.dataset.paraId)!=null?B:"",I=_(a,E);if(!I||I.content.some(te=>te.kind!=="text"))return;let T=Wr(a,E,(D=S.textContent)!=null?D:"");if(!T){(m.inputType==="historyUndo"||m.inputType==="historyRedo")&&ln(E);return}u.push(T);let P=Ml(E,T);P&&u.push(P),H&&m.inputType!=="historyUndo"&&m.inputType!=="historyRedo"&&((G=H.afterParagraphs[0])==null?void 0:G.paraId)===E?(H.changes.push(T),H.afterParagraphs=[ue(I)]):H=null,X.length=0,pa(E),x&&ne({kind:"caret",paraId:x.paraId,offset:x.offset}),P&&ua(E,x!=null?x:void 0),Ie("deferred");},Ca=d=>{var x,S;if(l)return false;if(!d){let E=kt(e);return E&&(e.contains(E.anchorNode)||e.contains(E.focusNode))&&E.removeAllRanges(),g=null,Et(e),ne(null),true}if(d.kind==="caret")return _(a,d.paraId)?(g=null,Et(e),lt(e,d),ne(d),true):false;if(d.kind==="text-range")return !_(a,d.anchor.paraId)||!_(a,d.focus.paraId)?false:(g=null,Et(e),gn(e,d.anchor,d.focus),ne(d),true);if(d.kind==="table-cell-range"){let E=(x=Oe(a,d.tableId))==null?void 0:x.table;return !E||at(E,d).length===0?false:(g=null,Et(e),(S=kt(e))==null||S.removeAllRanges(),ne(d),true)}let m=e.querySelector(`coco-word-native-p[data-para-id="${d.paraId}"] img[data-drawing-id="${d.objectId}"]`);return !_(a,d.paraId)||!m?false:(g={paraId:d.paraId,drawingId:d.objectId},Et(e),Gt(),ne(d),true)},ld=()=>{F!==null&&window.clearTimeout(F),W!==null&&window.clearTimeout(W),V!==null&&window.clearTimeout(V),ee!==null&&window.clearTimeout(ee),pe!==null&&window.clearTimeout(pe),L!==null&&window.clearTimeout(L),Ve!==null&&window.clearTimeout(Ve),Z!==null&&window.clearTimeout(Z),F=null,W=null,V=null,ee=null,pe=null,L=null,Ve=null,Z=null;};return e.addEventListener("beforeinput",Xl),e.addEventListener("compositionstart",Al),e.addEventListener("compositionend",Ll),e.addEventListener("copy",va),e.addEventListener("cut",jl),e.addEventListener("paste",Ul),e.addEventListener("drop",id),e.addEventListener("keydown",Po),e.addEventListener("mousedown",Ql),e.addEventListener("click",Jl),e.addEventListener("mouseup",Mo),e.addEventListener("input",sd),e.addEventListener("contextmenu",Kl),document.addEventListener("keydown",Po,true),document.addEventListener("beforeinput",Yl,true),document.addEventListener("selectionchange",nd),document.addEventListener("focusin",rd),document.addEventListener("pointerdown",vr,true),document.addEventListener("pointerup",vr,true),document.addEventListener("click",od,true),document.addEventListener("keydown",Ro,true),document.addEventListener("keyup",Ro,true),document.addEventListener("mousemove",ed),document.addEventListener("pointerdown",_l,true),document.addEventListener("keydown",ql,true),document.addEventListener("scroll",Rt,true),window.addEventListener("resize",Rt),window.addEventListener("mouseup",td),window.addEventListener("blur",ad),Pe(),{kind:"native-word",get destroyed(){return l},isReadOnly(){return c},setReadOnly(d){l||c===d||(c=d,Rt(),c&&(Ye==null||Ye(),Ye=null,re=null,we=null,H=null,he=false),Pe(void 0,h!=null?h:void 0));},destroy(){l||(l=true,e.removeEventListener("beforeinput",Xl),e.removeEventListener("compositionstart",Al),e.removeEventListener("compositionend",Ll),e.removeEventListener("copy",va),e.removeEventListener("cut",jl),e.removeEventListener("paste",Ul),e.removeEventListener("drop",id),e.removeEventListener("keydown",Po),e.removeEventListener("mousedown",Ql),e.removeEventListener("click",Jl),e.removeEventListener("mouseup",Mo),e.removeEventListener("input",sd),e.removeEventListener("contextmenu",Kl),document.removeEventListener("keydown",Po,true),document.removeEventListener("beforeinput",Yl,true),document.removeEventListener("selectionchange",nd),document.removeEventListener("focusin",rd),document.removeEventListener("pointerdown",vr,true),document.removeEventListener("pointerup",vr,true),document.removeEventListener("click",od,true),document.removeEventListener("keydown",Ro,true),document.removeEventListener("keyup",Ro,true),document.removeEventListener("mousemove",ed),document.removeEventListener("pointerdown",_l,true),document.removeEventListener("keydown",ql,true),document.removeEventListener("scroll",Rt,true),window.removeEventListener("resize",Rt),window.removeEventListener("mouseup",td),window.removeEventListener("blur",ad),window.removeEventListener("resize",xo),document.removeEventListener("scroll",xo,true),Ye==null||Ye(),Ye=null,Rt(),da(),la(),sa.remove(),ld(),So.disconnect(),Jr.get(document)===e&&Jr.delete(document),wt.change.clear(),wt.selectionChange.clear(),o?o.replaceChildren():e.replaceChildren(),e.classList.remove("coco-word-native-editor-host"),e.classList.remove("is-hyperlink-navigation-mode"),r.classList.remove("coco-word-editor-host"));},loadDocument(d){if(l)throw new Error("Cannot load a document into a destroyed Word editor");ld(),So.disconnect(),s=d,Rt(),da(),a=Va(s),u.length=0,f=[],w.clear();for(let m of _e(a))w.add(m.paraId);b=Date.now()>>>0,g=null,$n(),h=null,re=null,we=null,H=null,he=false,xe=null,z=null,Y.length=0,X.length=0,Pe(),ma();},getSourceView(){return s},getDocument(){return a},getSelection(){var d;return (d=h!=null?h:ze(e))!=null?d:st(e)},setSelection(d){return Ca(d)},focus(){var x;if(l)return false;let d=(x=h!=null?h:ze(e))!=null?x:st(e);if(d)return Ca(d);let m=_e(a)[0];return m?Ca({kind:"caret",paraId:m.paraId,offset:0}):false},async insertImage(d,m={}){if(l)return false;let x=typeof d=="string"?d:await qp(d);return ve(v({kind:"insert-image",src:x},m))},search:zm,getSearchState(){return wo()},findNext:Vm,replaceCurrent:rh,replaceAll:oh,clearSearch:da,getCommandState(){var m;let d=(m=h!=null?h:ze(e))!=null?m:st(e);return Ct(d)},getChanges(){return u.slice()},canUndo(){return !l&&!c&&Y.length>0},canRedo(){return !l&&!c&&X.length>0},undo:br,redo:wr,canDispatch(d){var x;if(l||c)return false;let m=(x=h!=null?h:ze(e))!=null?x:st(e);return Mt(a,m,d)},dispatch:ve,subscribe(d,m){if(l)return ()=>{};let x=m;return wt[d].add(x),()=>wt[d].delete(x)}}}function ue(e){return $(v({},e),{format:e.format?to(e.format):null,content:e.content.map(nv)})}function nv(e){return e.kind==="pageBreak"?{kind:"pageBreak"}:e.kind==="text"?v(v($(v({},e),{format:e.format?to(e.format):null}),e.marks?{marks:e.marks.map(t=>v({},t))}:{}),e.hyperlink?{hyperlink:v({},e.hyperlink)}:{}):e.kind==="field"?$(v({},e),{format:e.format?to(e.format):null}):e.kind==="image"?v(v({},e),e.position?{position:to(e.position)}:{}):v(v(v({},e),e.position?{position:to(e.position)}:{}),e.paragraphs?{paragraphs:e.paragraphs.map(ue)}:{})}function to(e){return JSON.parse(JSON.stringify(e))}function rv(e){return !!e&&/^(https?:|mailto:|tel:)/i.test(e.trim())}function tr(e){return "beforeBlocks"in e}function ov(e,t){let n=t.kind==="paragraph"?`coco-word-native-p[data-para-id="${t.paraId}"]`:`coco-word-native-table[data-table-id="${t.tableId}"]`;return Array.from(e.querySelectorAll(n))}function Up(e){var n;let t=js;for(let r of _e(e))for(let o of r.content)if(o.kind==="text")for(let i of (n=o.marks)!=null?n:[])i.kind==="comment"&&(t=Math.max(t,i.commentId));return js=t+1,js}function rt(e){var n,r,o,i;let t=Us;for(let s of _e(e))for(let a of s.content)if(a.kind==="text"){for(let u of (n=a.marks)!=null?n:[]){if(u.kind!=="revision")continue;let f=Number(u.revisionId);Number.isInteger(f)&&(t=Math.max(t,f));}let l=a.formatRevision,c=Number(l==null?void 0:l.revisionId);Number.isInteger(c)&&(t=Math.max(t,c));}else if(a.kind==="image"){let l=Number((i=(r=a.revision)==null?void 0:r.revisionId)!=null?i:(o=a.formatRevision)==null?void 0:o.revisionId);Number.isInteger(l)&&(t=Math.max(t,l));}return Us=t+1,String(Us)}function iv(e,t){return (e==null?void 0:e.kind)!==(t==null?void 0:t.kind)?false:!e||!t?e===t:e.kind==="caret"&&t.kind==="caret"?e.paraId===t.paraId&&e.offset===t.offset:e.kind==="object"&&t.kind==="object"?e.paraId===t.paraId&&e.objectKind===t.objectKind&&e.objectId===t.objectId:e.kind==="text-range"&&t.kind==="text-range"?e.anchor.paraId===t.anchor.paraId&&e.anchor.offset===t.anchor.offset&&e.focus.paraId===t.focus.paraId&&e.focus.offset===t.focus.offset:e.kind==="table-cell-range"&&t.kind==="table-cell-range"?e.tableId===t.tableId&&e.anchor.rowIndex===t.anchor.rowIndex&&e.anchor.columnIndex===t.anchor.columnIndex&&e.focus.rowIndex===t.focus.rowIndex&&e.focus.columnIndex===t.focus.columnIndex:false}function Kp(e,t){let n=t==="before"?e.beforeSelection:e.afterSelection;return n||(!e.changes.every(r=>r.kind==="format"||r.kind==="list")||e.range.anchor.paraId===e.range.focus.paraId&&e.range.anchor.offset===e.range.focus.offset?null:{kind:"text-range",anchor:e.range.anchor,focus:e.range.focus})}function _p(e){return e.skipDeferredRender?false:e.changes.some(t=>t.kind==="block"||t.kind==="image"||t.kind==="page-break"||t.kind==="list"?true:t.kind!=="format"?false:t.op==="paragraph"?t.format.alignment===void 0:t.clear===true||t.format.bold!==void 0||t.format.italic!==void 0||t.format.fontFamily!==void 0||t.format.fontSize!==void 0)}function Yp(e,t){var n,r;return (r=(n=e.querySelector(`coco-word-native-p[data-para-id="${t}"]`))==null?void 0:n.textContent)!=null?r:null}function gi(e,t){return t.every(n=>Yp(e,n.paraId)===Te(n))}function bi(e,t){return {from:Math.max(0,Math.min(e,t)),to:Math.max(0,Math.max(e,t))}}function qp(e){return new Promise((t,n)=>{let r=new FileReader;r.addEventListener("load",()=>{var o;return t(String((o=r.result)!=null?o:""))}),r.addEventListener("error",()=>{var o;return n((o=r.error)!=null?o:new Error("Unable to read clipboard image"))}),r.readAsDataURL(e);})}function wi(e){let t=Br(e);if(!t)return "";Gs=Gs+1>>>0;let n=`${Xp}${Date.now().toString(36)}-${Gs.toString(36)}`;for(eo.set(n,t);eo.size>8;){let r=eo.keys().next().value;if(!r)break;eo.delete(r);}return n}function av(e){var t;return e.startsWith(Xp)?(t=eo.get(e))!=null?t:"":e}function sv(e){var t;return e.kind==="text"?e.text:e.kind==="field"?(t=e.cachedText)!=null?t:"\uFFFC":e.kind==="drawing"&&e.text?e.text:"\uFFFC"}async function lv(e){let t=Qc(e);if(t.type==="image/png")return t;let n=await createImageBitmap(t);try{let r=document.createElement("canvas");r.width=n.width,r.height=n.height;let o=r.getContext("2d");if(!o)throw new Error("Unable to create clipboard image canvas");return o.drawImage(n,0,0),await new Promise((i,s)=>{r.toBlob(a=>a?i(a):s(new Error("Unable to encode clipboard image")),"image/png");})}finally{n.close();}}function xi(e){return e.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;")}function dv(e){let t={};return Number.isFinite(e.left)&&(t.left=Math.max(0,e.left)),Number.isFinite(e.right)&&(t.right=Math.max(0,e.right)),Number.isFinite(e.firstLine)&&(t.firstLine=e.firstLine),t}function cv(e){let t={};return Number.isFinite(e.before)&&(t.before=Math.max(0,e.before)),Number.isFinite(e.after)&&(t.after=Math.max(0,e.after)),t}function et(e,t){if(t.anchor.paraId===t.focus.paraId&&t.anchor.offset<=t.focus.offset)return {anchor:t.anchor,focus:t.focus};if(t.anchor.paraId!==t.focus.paraId){let n=be(e,t.anchor.paraId),r=be(e,t.focus.paraId);if(n&&r&&n.container===r.container)return n.index<=r.index?{anchor:t.anchor,focus:t.focus}:{anchor:t.focus,focus:t.anchor}}return {anchor:t.focus,focus:t.anchor}}function yi(e,t){return `${e}:${t}`}function no(e,t,n={}){var f,p,w;let r=new Map,o=new Map,i=new Map,s=new Map,a=new Map,l=new Map,c=(f=n.minimumRows)!=null?f:100,u=(p=n.minimumColumns)!=null?p:26;for(let b of e.rows)i.set(b.index,b),c=Math.max(c,b.index);for(let b of e.columns){for(let g=b.min;g<=b.max;g++)s.set(g,b);u=Math.max(u,b.max);}for(let b of e.cells){let g=Jp(b,t,n.formulaResults,n.date1904);r.set(b.address,g),o.set(yi(b.row,b.column),g),c=Math.max(c,b.row),u=Math.max(u,b.column);}for(let[b,g]of (w=n.formulaResults)!=null?w:[]){if(r.has(b)||g.error)continue;let h=excel.parseCellAddress(b),y={address:b,row:h.row,column:h.column,kind:"formula",value:null},k=Jp(y,t,n.formulaResults,n.date1904);r.set(b,k),o.set(yi(h.row,h.column),k),c=Math.max(c,h.row),u=Math.max(u,h.column);}for(let b of e.mergedRanges){let g=excel.parseRangeAddress(b.address),h=g.startRow+g.rowCount-1,y=g.startColumn+g.columnCount-1,k={startRow:g.startRow,startColumn:g.startColumn,endRow:h,endColumn:y},C=excel.formatCellAddress(g.startRow,g.startColumn),N={address:b.address,range:k,masterAddress:C,source:b};a.set(C,N),c=Math.max(c,h),u=Math.max(u,y);for(let L=g.startRow;L<=h;L++)for(let F=g.startColumn;F<=y;F++){let W=excel.formatCellAddress(L,F);W!==C&&l.set(W,C);}}return {sheetId:e.id,sheetName:e.name,source:e,styles:t,cellsByAddress:r,cellsByRowColumn:o,rowMetaByIndex:i,columnMetaByIndex:s,mergeMasterByAddress:a,mergeFollowerByAddress:l,maxRow:c,maxColumn:u}}function qe(e,t,n){return e.cellsByRowColumn.get(yi(t,n))}function Jp(e,t,n,r=false){var a,l;let o=n==null?void 0:n.get(e.address),i=o&&!o.error?o.value:void 0,s=Array.isArray(i)?(l=(a=i[0])==null?void 0:a[0])!=null?l:null:i!=null?i:e.value;return {row:e.row,column:e.column,address:e.address,kind:e.kind,value:s,displayText:fv(e,t,s,o,r),formula:e.formula,styleId:e.styleId,source:e}}function fv(e,t,n,r,o=false){return r!=null&&r.error?r.displayText:n!==null?hv(n,mv(e,t),o):""}function mv(e,t){var n,r;return (r=t.cellFormats[(n=e.styleId)!=null?n:0])==null?void 0:r.numberFormatCode}function hv(e,t,n=false){if(e===null)return "";if(typeof e!="number"||!t)return String(e);let r=t.toLowerCase();return r.includes("%")?`${Si(e*100,vi(t))}%`:r.includes("$")?`$${Si(e,vi(t),true)}`:gv(r)?bv(e,r,n):t.includes(",")?Si(e,vi(t),true):t.includes(".")?Si(e,vi(t)):String(e)}function vi(e){var n,r;let t=/\.(0+)/.exec(e);return (r=(n=t==null?void 0:t[1])==null?void 0:n.length)!=null?r:0}function Si(e,t,n=false){return new Intl.NumberFormat("en-US",{minimumFractionDigits:t,maximumFractionDigits:t,useGrouping:n}).format(e)}function gv(e){return ["d-mmm","mmm-yy","h:mm am/pm","h:mm:ss am/pm","h:mm","h:mm:ss","mm:ss","[h]:mm:ss","mmss.0"].includes(e)?true:/(^|[^a-z])y{2,4}([^a-z]|$)/.test(e)&&/(^|[^a-z])d{1,2}([^a-z]|$)/.test(e)}function bv(e,t,n){if(!Number.isFinite(e))return String(e);let r=Math.floor(e),o=e-r,i=Math.round(o*86400)%86400,s=Math.floor(i/3600),a=Math.floor(i%3600/60),l=i%60,c=s%12||12,u=s<12?"AM":"PM",f=F=>String(F).padStart(2,"0");if(t==="h:mm am/pm")return `${c}:${f(a)} ${u}`;if(t==="h:mm:ss am/pm")return `${c}:${f(a)}:${f(l)} ${u}`;if(t==="h:mm")return `${s}:${f(a)}`;if(t==="h:mm:ss")return `${s}:${f(a)}:${f(l)}`;if(t==="mm:ss")return `${f(a)}:${f(l)}`;if(t==="[h]:mm:ss")return `${Math.floor(e*24)}:${f(a)}:${f(l)}`;if(t==="mmss.0")return `${f(a)}${f(l)}.0`;let p=!n&&r===60,w=n?Date.UTC(1904,0,1):Date.UTC(1899,11,30),b=new Date(w+r*864e5),g=p?1900:b.getUTCFullYear(),h=p?2:b.getUTCMonth()+1,y=p?29:b.getUTCDate(),k=f(h),C=f(y),N=f(g%100),L=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][h-1];return t==="mm-dd-yy"?`${k}-${C}-${N}`:t==="d-mmm-yy"?`${y}-${L}-${N}`:t==="d-mmm"?`${y}-${L}`:t==="mmm-yy"?`${L}-${N}`:t==="m/d/yy h:mm"?`${h}/${y}/${N} ${s}:${f(a)}`:`${g}-${k}-${C}`}var xv=22,yv=96,vv=48,Sv=24,kv=96/72,Ks=7,Ev=5,ki=class{constructor(t,n={}){O(this,"model",t);O(this,"defaultRowHeight");O(this,"defaultColumnWidth");O(this,"rowHeaderWidth");O(this,"columnHeaderHeight");O(this,"rowCount");O(this,"columnCount");O(this,"rowOffsets");O(this,"columnOffsets");O(this,"rowHeights");O(this,"columnWidths");var r,o,i,s,a,l;this.defaultRowHeight=(r=n.defaultRowHeight)!=null?r:xv,this.defaultColumnWidth=(o=n.defaultColumnWidth)!=null?o:yv,this.rowHeaderWidth=(i=n.rowHeaderWidth)!=null?i:vv,this.columnHeaderHeight=(s=n.columnHeaderHeight)!=null?s:Sv,this.rowCount=Math.max((a=n.rowCount)!=null?a:0,t.maxRow),this.columnCount=Math.max((l=n.columnCount)!=null?l:0,t.maxColumn),this.rowHeights=Cv(t,this.rowCount,this.defaultRowHeight),this.columnWidths=Iv(t,this.columnCount,this.defaultColumnWidth),this.rowOffsets=Qp(this.rowHeights),this.columnOffsets=Qp(this.columnWidths);}totalWidth(){var t;return (t=this.columnOffsets[this.columnOffsets.length-1])!=null?t:0}totalHeight(){var t;return (t=this.rowOffsets[this.rowOffsets.length-1])!=null?t:0}getColumnWidth(t){var n;return (n=this.columnWidths[t-1])!=null?n:this.defaultColumnWidth}getRowHeight(t){var n;return (n=this.rowHeights[t-1])!=null?n:this.defaultRowHeight}getColumnX(t){var n;return (n=this.columnOffsets[Math.max(0,t-1)])!=null?n:0}getRowY(t){var n;return (n=this.rowOffsets[Math.max(0,t-1)])!=null?n:0}getCellLogicalRect(t,n){return {x:this.getColumnX(n),y:this.getRowY(t),width:this.getColumnWidth(n),height:this.getRowHeight(t)}}getRangeLogicalRect(t){let n=this.getColumnX(t.startColumn),r=this.getRowY(t.startRow),o=this.getColumnX(t.endColumn)+this.getColumnWidth(t.endColumn),i=this.getRowY(t.endRow)+this.getRowHeight(t.endRow);return {x:n,y:r,width:o-n,height:i-r}}getVisibleRange(t,n,r,o=1,i=1){let s=Math.max(i,this.columnAt(t)),a=Math.max(o,this.rowAt(n)),l=Math.max(s,Math.min(this.columnCount,this.columnAt(t+r.width)+1)),c=Math.max(a,Math.min(this.rowCount,this.rowAt(n+r.height)+1));return {startRow:a,startColumn:s,endRow:c,endColumn:l}}rowAt(t){return tf(ef(this.rowOffsets,t),this.rowCount)}columnAt(t){return tf(ef(this.columnOffsets,t),this.columnCount)}hitTestLogical(t,n){let r=this.columnAt(t),o=this.rowAt(n);return o<1||r<1||o>this.rowCount||r>this.columnCount?{kind:"none"}:{kind:"cell",row:o,column:r,address:excel.formatCellAddress(o,r)}}};function Cv(e,t,n){let r=[];for(let o=1;o<=t;o++){let i=e.rowMetaByIndex.get(o);r.push(i!=null&&i.hidden?0:(i==null?void 0:i.height)===void 0?n:i.height*kv);}return r}function Iv(e,t,n){let r=[];for(let o=1;o<=t;o++){let i=e.columnMetaByIndex.get(o);r.push(i!=null&&i.hidden?0:(i==null?void 0:i.width)===void 0?n:Nv(i.width));}return r}function Nv(e){return !Number.isFinite(e)||e<=0?0:Math.floor((256*e+Math.floor(128/Ks))/256*Ks)}function Ei(e){return !Number.isFinite(e)||e<=0?0:Math.floor((e-Ev)/Ks*256)/256}function Qp(e){var n;let t=[0];for(let r of e)t.push(((n=t[t.length-1])!=null?n:0)+r);return t}function ef(e,t){var o;if(t<=0)return 1;let n=0,r=e.length-1;for(;n<r;){let i=Math.floor((n+r+1)/2);((o=e[i])!=null?o:0)<=t?n=i:r=i-1;}return n+1}function tf(e,t){return Math.max(1,Math.min(t,e))}var Ci=class{constructor(t,n){O(this,"layout",t);O(this,"scroll");O(this,"freeze");O(this,"viewportSize");O(this,"viewports");var r,o,i,s,a,l,c,u;this.viewportSize=n.viewportSize,this.freeze={frozenRows:Math.max(0,(o=(r=n.freeze)==null?void 0:r.frozenRows)!=null?o:0),frozenColumns:Math.max(0,(s=(i=n.freeze)==null?void 0:i.frozenColumns)!=null?s:0)},this.scroll=Pv(t,this.freeze,n.viewportSize,{x:(l=(a=n.scroll)==null?void 0:a.x)!=null?l:0,y:(u=(c=n.scroll)==null?void 0:c.y)!=null?u:0}),this.viewports=Mv(t,this.viewportSize,this.scroll,this.freeze);}hitTest(t){let n=this.findViewport(t);if(!n)return {kind:"none"};if(n.kind==="corner")return {kind:"corner"};let r=t.x-n.screenRect.x+n.originX,o=t.y-n.screenRect.y+n.originY;return n.kind==="columnHeaderScrollable"||n.kind==="columnHeaderFrozen"?{kind:"columnHeader",column:this.layout.columnAt(r)}:n.kind==="rowHeaderScrollable"||n.kind==="rowHeaderFrozen"?{kind:"rowHeader",row:this.layout.rowAt(o)}:this.layout.hitTestLogical(r,o)}findViewport(t){for(let n=this.viewports.length-1;n>=0;n--){let r=this.viewports[n];if(r&&Rv(r.screenRect,t))return r}}cellScreenRect(t,n,r){let o=this.layout.getCellLogicalRect(t,n);return {x:r.screenRect.x+o.x-r.originX,y:r.screenRect.y+o.y-r.originY,width:o.width,height:o.height}}};function Ii(e){var n;let t=(n=e.sheetViews[0])==null?void 0:n.pane;return Tv(t)}function Tv(e){var t,n;return !e||e.state!=="frozen"?{frozenRows:0,frozenColumns:0}:{frozenRows:Math.max(0,Math.floor((t=e.ySplit)!=null?t:0)),frozenColumns:Math.max(0,Math.floor((n=e.xSplit)!=null?n:0))}}function Pv(e,t,n,r){let o=e.getColumnX(t.frozenColumns+1),i=e.getRowY(t.frozenRows+1),s=Math.max(0,n.width-e.rowHeaderWidth-o),a=Math.max(0,n.height-e.columnHeaderHeight-i),l=Math.max(0,e.totalWidth()-o-s),c=Math.max(0,e.totalHeight()-i-a);return {x:Math.max(0,Math.min(l,r.x)),y:Math.max(0,Math.min(c,r.y))}}function Mv(e,t,n,r){let o=e.rowHeaderWidth,i=e.columnHeaderHeight,s=e.getColumnX(r.frozenColumns+1),a=e.getRowY(r.frozenRows+1),l=s+n.x,c=a+n.y,u=Math.max(0,t.width-o),f=Math.max(0,t.height-i),p=o+s,w=i+a,b=Math.max(0,t.width-p),g=Math.max(0,t.height-w),h=[];return h.push({kind:"corner",screenRect:{x:0,y:0,width:o,height:i},originX:0,originY:0,rows:{start:1,end:0},columns:{start:1,end:0}}),r.frozenColumns>0&&h.push({kind:"columnHeaderFrozen",screenRect:{x:o,y:0,width:Math.min(s,u),height:i},originX:0,originY:0,rows:{start:1,end:0},columns:{start:1,end:r.frozenColumns}}),h.push({kind:"columnHeaderScrollable",screenRect:{x:o+s,y:0,width:Math.max(0,t.width-o-s),height:i},originX:l,originY:0,rows:{start:1,end:0},columns:qs(e,l,b,r.frozenColumns+1)}),r.frozenRows>0&&h.push({kind:"rowHeaderFrozen",screenRect:{x:0,y:i,width:o,height:Math.min(a,f)},originX:0,originY:0,rows:{start:1,end:r.frozenRows},columns:{start:1,end:0}}),h.push({kind:"rowHeaderScrollable",screenRect:{x:0,y:i+a,width:o,height:Math.max(0,t.height-i-a)},originX:0,originY:c,rows:_s(e,c,g,r.frozenRows+1),columns:{start:1,end:0}}),r.frozenRows>0&&r.frozenColumns>0&&h.push({kind:"frozenTopLeft",screenRect:{x:o,y:i,width:s,height:a},originX:0,originY:0,rows:{start:1,end:r.frozenRows},columns:{start:1,end:r.frozenColumns}}),r.frozenRows>0&&h.push({kind:"frozenTop",screenRect:{x:p,y:i,width:b,height:a},originX:l,originY:0,rows:{start:1,end:r.frozenRows},columns:qs(e,l,b,r.frozenColumns+1)}),r.frozenColumns>0&&h.push({kind:"frozenLeft",screenRect:{x:o,y:w,width:s,height:g},originX:0,originY:c,rows:_s(e,c,g,r.frozenRows+1),columns:{start:1,end:r.frozenColumns}}),h.push({kind:"main",screenRect:{x:p,y:w,width:b,height:g},originX:l,originY:c,rows:_s(e,c,g,r.frozenRows+1),columns:qs(e,l,b,r.frozenColumns+1)}),h.filter(y=>y.screenRect.width>0&&y.screenRect.height>0)}function _s(e,t,n,r){let o=e.getVisibleRange(0,t,{width:1,height:n},r,1);return {start:o.startRow,end:o.endRow}}function qs(e,t,n,r){let o=e.getVisibleRange(t,0,{width:n,height:1},1,r);return {start:o.startColumn,end:o.endColumn}}function Rv(e,t){return t.x>=e.x&&t.y>=e.y&&t.x<e.x+e.width&&t.y<e.y+e.height}function Ti(e,t,n){var l,c,u,f,p,w,b,g,h,y,k,C,N,L;let r=(l=e.cellFormats[t!=null?t:0])!=null?l:{},o=(u=e.fonts[(c=r.fontId)!=null?c:0])!=null?u:{},i=(f=o.size)!=null?f:11,s=(w=e.fills[(p=r.fillId)!=null?p:0])!=null?w:{},a=(g=e.borders[(b=r.borderId)!=null?b:0])!=null?g:{};return {font:Av(o.bold,o.italic,i,(h=o.name)!=null?h:"Arial"),fontSize:i,underline:o.underline===true,fontColor:(k=(y=o.color)==null?void 0:y.rgb)!=null?k:"#111827",fillColor:(N=(C=s.foregroundColor)==null?void 0:C.rgb)!=null?N:"#FFFFFF",wrapText:((L=r.alignment)==null?void 0:L.wrapText)===true,border:a,horizontalAlign:Wv(r,n),verticalAlign:Bv(r)}}function nf(e,t){let n={};for(let a=t.startColumn;a<=t.endColumn;a++)(n.top)!=null||(n.top=Ni(e,t.startRow,a,"top")),(n.bottom)!=null||(n.bottom=Ni(e,t.endRow,a,"bottom"));for(let a=t.startRow;a<=t.endRow;a++)(n.left)!=null||(n.left=Ni(e,a,t.startColumn,"left")),(n.right)!=null||(n.right=Ni(e,a,t.endColumn,"right"));return n}function Ni(e,t,n,r){var s,a,l,c;let o=qe(e,t,n),i=(a=e.styles.cellFormats[(s=o==null?void 0:o.styleId)!=null?s:0])!=null?a:{};return (c=e.styles.borders[(l=i.borderId)!=null?l:0])==null?void 0:c[r]}function Av(e,t,n,r){let o=[];return t&&o.push("italic"),e&&o.push("600"),o.push(`${n}px`),o.push(Lv(r)),o.join(" ")}function Lv(e){return /\s/.test(e)?JSON.stringify(e):e}function Wv(e,t){var n;switch((n=e.alignment)==null?void 0:n.horizontal){case "left":return "left";case "center":return "center";case "right":return "right"}return (t==null?void 0:t.kind)==="number"||(t==null?void 0:t.kind)==="formula"&&typeof t.value=="number"?"right":(t==null?void 0:t.kind)==="boolean"||(t==null?void 0:t.kind)==="error"?"center":"left"}function Bv(e){var t;switch((t=e.alignment)==null?void 0:t.vertical){case "top":return "top";case "center":case "middle":return "middle";case "bottom":return "bottom";default:return "bottom"}}var Ai=class{constructor(t){O(this,"options",t);O(this,"baseCtx");O(this,"headerCtx");O(this,"overlayCtx");O(this,"cssWidth",1);O(this,"cssHeight",1);O(this,"scaleX",1);O(this,"scaleY",1);O(this,"headerFiltersEnabled",true);O(this,"headerFilterColumns",null);O(this,"activeHeaderFilterColumns",new Set);this.baseCtx=Pi(t.baseCanvas),this.headerCtx=Pi(t.headerCanvas),this.overlayCtx=Pi(t.overlayCanvas);}resize(t,n,r=globalThis.devicePixelRatio||1){this.cssWidth=Math.max(1,t),this.cssHeight=Math.max(1,n);let o=Math.max(1,r||1);for(let i of [this.options.baseCanvas,this.options.headerCanvas,this.options.overlayCanvas]){i.style.width=`${this.cssWidth}px`,i.style.height=`${this.cssHeight}px`,i.width=Math.max(1,Math.ceil(this.cssWidth*o)),i.height=Math.max(1,Math.ceil(this.cssHeight*o));let s=Pi(i);this.scaleX=i.width/this.cssWidth,this.scaleY=i.height/this.cssHeight,s.setTransform(this.scaleX,0,0,this.scaleY,0,0),s.imageSmoothingEnabled=false;}}setHeaderFiltersEnabled(t){this.headerFiltersEnabled=t;}setHeaderFilterColumns(t){this.headerFilterColumns=t===null?null:new Set(t);}setActiveHeaderFilterColumns(t){this.activeHeaderFilterColumns=new Set(t);}render(t,n){this.clearAll(t,n),this.drawCells(t,n),this.drawHeaders(t,n);}clearOverlay(){Mi(this.overlayCtx,this.options.overlayCanvas);}renderSelection(t,n,r,o={}){this.clearOverlay();let i=this.overlayCtx;for(let s of n.viewports){if(!Ri(s))continue;let a=of(r,{startRow:s.rows.start,endRow:s.rows.end,startColumn:s.columns.start,endColumn:s.columns.end});if(!a)continue;let l=t.getRangeLogicalRect(a),c=Xs(l,s);ro(i,s.screenRect,()=>{i.fillStyle="rgba(37, 99, 235, 0.08)",i.fillRect(c.x,c.y,c.width,c.height),i.strokeStyle="#2563EB",i.lineWidth=2/this.scaleX,i.setLineDash([]),io(i,Zs(c,1),this.scaleX,this.scaleY);});}o.showFillHandle&&this.drawFillHandle(t,n,r);}fillHandleRect(t,n,r){for(let o of n.viewports){if(!Ri(o)||r.endRow<o.rows.start||r.endRow>o.rows.end||r.endColumn<o.columns.start||r.endColumn>o.columns.end)continue;let i=n.cellScreenRect(r.endRow,r.endColumn,o),s=7;return {x:i.x+i.width-s/2,y:i.y+i.height-s/2,width:s,height:s}}return null}renderCopiedRange(t,n,r){this.renderDashedRange(t,n,r,{stroke:"#1D4ED8"});}renderDashedRange(t,n,r,o){let i=this.overlayCtx;for(let s of n.viewports){if(!Ri(s))continue;let a=of(r,{startRow:s.rows.start,endRow:s.rows.end,startColumn:s.columns.start,endColumn:s.columns.end});if(!a)continue;let l=t.getRangeLogicalRect(a),c=Xs(l,s);ro(i,s.screenRect,()=>{i.save(),o.fill&&(i.fillStyle=o.fill,i.fillRect(c.x,c.y,c.width,c.height)),i.strokeStyle=o.stroke,i.lineWidth=2/this.scaleX,i.setLineDash([4,3]),i.lineDashOffset=0,io(i,Zs(c,2),this.scaleX,this.scaleY),i.restore();});}}clearAll(t,n){Mi(this.baseCtx,this.options.baseCanvas),Mi(this.headerCtx,this.options.headerCanvas),Mi(this.overlayCtx,this.options.overlayCanvas);}drawFillHandle(t,n,r){let o=this.fillHandleRect(t,n,r);if(!o)return;let i=this.overlayCtx;i.save(),i.fillStyle="#2563EB",i.fillRect(o.x,o.y,o.width,o.height),i.strokeStyle="#FFFFFF",i.lineWidth=1/this.scaleX,io(i,Zs(o,.5),this.scaleX,this.scaleY),i.restore();}drawCells(t,n){let r=this.baseCtx;r.save(),r.fillStyle="#FFFFFF",r.fillRect(0,0,this.cssWidth,this.cssHeight),r.restore();for(let o of n.viewports)Ri(o)&&ro(r,o.screenRect,()=>{for(let i=o.rows.start;i<=o.rows.end;i++)for(let s=o.columns.start;s<=o.columns.end;s++){let a=excel.formatCellAddress(i,s);if(!t.model.mergeFollowerByAddress.get(a)&&(this.drawCell(r,t,n,o,i,s,{drawBorder:false,reserveTrailingSpace:this.headerFiltersEnabled&&i===1}),this.headerFiltersEnabled&&i===1&&(this.headerFilterColumns===null||this.headerFilterColumns.has(s)))){let c=t.getCellLogicalRect(i,s),u={x:o.screenRect.x+c.x-o.originX,y:o.screenRect.y+c.y-o.originY,width:c.width,height:c.height};Fv(r,u,this.scaleX,this.scaleY,this.activeHeaderFilterColumns.has(s));}}for(let i=o.rows.start;i<=o.rows.end;i++)for(let s=o.columns.start;s<=o.columns.end;s++){let a=excel.formatCellAddress(i,s);t.model.mergeFollowerByAddress.get(a)||this.drawCell(r,t,n,o,i,s,{drawContent:false});}});}drawCell(t,n,r,o,i,s,a={}){let l=qe(n.model,i,s),c=l?n.model.mergeMasterByAddress.get(l.address):void 0,u=c?Xs(n.getRangeLogicalRect(c.range),o):r.cellScreenRect(i,s,o),f=Ti(n.model.styles,l==null?void 0:l.styleId,l),p=c?nf(n.model,c.range):f.border;if(a.drawContent!==false&&(t.fillStyle=f.fillColor,t.fillRect(u.x,u.y,u.width,u.height),t.strokeStyle="#E5E7EB",t.lineWidth=1/this.scaleX,io(t,u,this.scaleX,this.scaleY)),a.drawBorder!==false&&Hv(t,u,p,this.scaleX,this.scaleY),a.drawContent===false||!(l!=null&&l.displayText))return;t.save(),t.font=f.font,t.fillStyle=f.fontColor,t.textAlign=f.horizontalAlign,t.textBaseline="middle";let w=6,b=a.reserveTrailingSpace&&u.width>=28?22:0,g={x:u.x,y:u.y,width:Math.max(1,u.width-b),height:u.height},h=f.horizontalAlign==="right"?g.x+g.width-w:f.horizontalAlign==="center"?g.x+g.width/2:g.x+w;ro(t,g,()=>{let y=f.wrapText||l.displayText.includes(`
1547
+ `)?$v(t,l.displayText,Math.max(1,g.width-w*2)):[l.displayText],k=f.fontSize*1.2,C=y.length*k,N=Ov(u,f,w,C,k);for(let L=0;L<y.length;L++){let F=y[L],W=N+L*k;t.fillText(F,h,W),f.underline&&zv(t,F,h,W,f,this.scaleX,this.scaleY);}}),t.restore();}drawHeaders(t,n){let r=this.headerCtx;for(let o of n.viewports)ro(r,o.screenRect,()=>{if(o.kind==="corner")Ys(r,o.screenRect,"",this.scaleX,this.scaleY);else if(o.kind==="columnHeaderFrozen"||o.kind==="columnHeaderScrollable")for(let i=o.columns.start;i<=o.columns.end;i++){let s=t.getCellLogicalRect(1,i),a={x:o.screenRect.x+s.x-o.originX,y:o.screenRect.y,width:s.width,height:o.screenRect.height};Ys(r,a,excel.columnIndexToName(i),this.scaleX,this.scaleY);}else if(o.kind==="rowHeaderFrozen"||o.kind==="rowHeaderScrollable")for(let i=o.rows.start;i<=o.rows.end;i++){let s=t.getCellLogicalRect(i,1),a={x:o.screenRect.x,y:o.screenRect.y+s.y-o.originY,width:o.screenRect.width,height:s.height};Ys(r,a,String(i),this.scaleX,this.scaleY);}});}};function Fv(e,t,n,r,o=false){if(t.width<28)return;let i=t.x+t.width-10,s=t.y+t.height/2;e.save(),e.strokeStyle=o?"#2563EB":"#64748B",e.lineWidth=1/n,e.lineCap="round",e.beginPath(),e.moveTo(i-4,s-3),e.lineTo(i+4,s-3),e.lineTo(i+1,s+1),e.lineTo(i+1,s+4),e.lineTo(i-1,s+3),e.lineTo(i-1,s+1),e.closePath(),e.stroke(),e.restore();}function of(e,t){let n=Math.max(e.startRow,t.startRow),r=Math.max(e.startColumn,t.startColumn),o=Math.min(e.endRow,t.endRow),i=Math.min(e.endColumn,t.endColumn);return n>o||r>i?null:{startRow:n,startColumn:r,endRow:o,endColumn:i}}function Pi(e){let t=e.getContext("2d");if(!t)throw new Error("SpreadsheetCanvasRenderer: 2D canvas context is unavailable");return t}function Mi(e,t){let n=Number.parseFloat(t.style.width)||t.width,r=Number.parseFloat(t.style.height)||t.height;e.clearRect(0,0,n,r);}function ro(e,t,n){e.save(),e.beginPath(),e.rect(t.x,t.y,t.width,t.height),e.clip(),n(),e.restore();}function Ri(e){return e.kind==="main"||e.kind==="frozenTop"||e.kind==="frozenLeft"||e.kind==="frozenTopLeft"}function Xs(e,t){return {x:t.screenRect.x+e.x-t.originX,y:t.screenRect.y+e.y-t.originY,width:e.width,height:e.height}}function Ys(e,t,n,r,o){e.fillStyle="#F3F4F6",e.fillRect(t.x,t.y,t.width,t.height),e.strokeStyle="#D1D5DB",e.lineWidth=1/r,io(e,t,r,o),n&&(e.font="12px Arial",e.fillStyle="#374151",e.textAlign="center",e.textBaseline="middle",e.fillText(n,t.x+t.width/2,t.y+t.height/2));}function Hv(e,t,n,r,o){var i,s,a,l,c,u,f,p;!n.left&&!n.right&&!n.top&&!n.bottom||(e.save(),e.lineWidth=1/r,e.setLineDash([]),n.top&&(e.strokeStyle=(s=(i=n.top.color)==null?void 0:i.rgb)!=null?s:"#111827",oo(e,t.x,t.y,t.x+t.width,t.y,r,o)),n.right&&(e.strokeStyle=(l=(a=n.right.color)==null?void 0:a.rgb)!=null?l:"#111827",oo(e,t.x+t.width,t.y,t.x+t.width,t.y+t.height,r,o)),n.bottom&&(e.strokeStyle=(u=(c=n.bottom.color)==null?void 0:c.rgb)!=null?u:"#111827",oo(e,t.x,t.y+t.height,t.x+t.width,t.y+t.height,r,o)),n.left&&(e.strokeStyle=(p=(f=n.left.color)==null?void 0:f.rgb)!=null?p:"#111827",oo(e,t.x,t.y,t.x,t.y+t.height,r,o)),e.restore());}function Ov(e,t,n,r,o){return t.verticalAlign==="top"?e.y+n+o/2:t.verticalAlign==="bottom"?e.y+e.height-n-r+o/2:e.y+(e.height-r)/2+o/2}function $v(e,t,n){let r=[];for(let o of t.split(/\r?\n/)){if(o===""){r.push("");continue}let i="";for(let s of o){let a=i+s;i&&e.measureText(a).width>n?(r.push(i),i=s):i=a;}i&&r.push(i);}return r.length>0?r:[""]}function oo(e,t,n,r,o,i,s){e.beginPath(),e.moveTo(wn(t,i),wn(n,s)),e.lineTo(wn(r,i),wn(o,s)),e.stroke();}function zv(e,t,n,r,o,i,s){let a=e.measureText(t),l=a.width,c=o.horizontalAlign==="right"?n-l:o.horizontalAlign==="center"?n-l/2:n,u=Math.max(2,(a.actualBoundingBoxDescent||o.fontSize*.18)+1);e.save(),e.strokeStyle=o.fontColor,e.lineWidth=1/i,oo(e,c,r+u,c+l,r+u,i,s),e.restore();}function Zs(e,t){return {x:e.x+t,y:e.y+t,width:Math.max(0,e.width-t*2),height:Math.max(0,e.height-t*2)}}function io(e,t,n,r){let o=wn(t.x,n),i=wn(t.y,r),s=wn(t.x+t.width,n),a=wn(t.y+t.height,r);e.strokeRect(o,i,Math.max(0,s-o),Math.max(0,a-i));}function wn(e,t){return (Math.round(e*t)+.5)/t}function gt(e,t){return {kind:"cell",active:{row:e,column:t},range:{startRow:e,startColumn:t,endRow:e,endColumn:t}}}function Js(e,t){return {kind:"row",active:{row:e,column:1},range:{startRow:e,startColumn:1,endRow:e,endColumn:t.columnCount}}}function WI(e,t,n){let r=We({startRow:e,startColumn:1,endRow:t,endColumn:n.columnCount});return {kind:"row",active:{row:r.startRow,column:1},range:r}}function Qs(e,t){return {kind:"column",active:{row:1,column:e},range:{startRow:1,startColumn:e,endRow:t.rowCount,endColumn:e}}}function BI(e,t,n){let r=We({startRow:1,startColumn:e,endRow:n.rowCount,endColumn:t});return {kind:"column",active:{row:1,column:r.startColumn},range:r}}function We(e){return {startRow:Math.min(e.startRow,e.endRow),startColumn:Math.min(e.startColumn,e.endColumn),endRow:Math.max(e.startRow,e.endRow),endColumn:Math.max(e.startColumn,e.endColumn)}}function Li(e,t,n,r){var o,i;return e.kind==="row"?{kind:"row",active:e.active,range:We({startRow:e.active.row,startColumn:1,endRow:t,endColumn:(o=r==null?void 0:r.columnCount)!=null?o:e.range.endColumn})}:e.kind==="column"?{kind:"column",active:e.active,range:We({startRow:1,startColumn:e.active.column,endRow:(i=r==null?void 0:r.rowCount)!=null?i:e.range.endRow,endColumn:n})}:{kind:"cell",active:e.active,range:We({startRow:e.active.row,startColumn:e.active.column,endRow:t,endColumn:n})}}function DI(e,t,n,r){return gt(nr(e.active.row+t,1,r.rowCount),nr(e.active.column+n,1,r.columnCount))}function _t(e,t){var r;if(e.kind!=="cell")return e;let n=(r=Uv(e.active.row,e.active.column,t))!=null?r:e.active;return $(v({},e),{active:n,range:Gv(e.range,t)})}function Gv(e,t){let n=We(e),r=true;for(;r;){r=false;for(let o of t.mergeMasterByAddress.values()){if(!jv(n,o.range))continue;let i={startRow:Math.min(n.startRow,o.range.startRow),startColumn:Math.min(n.startColumn,o.range.startColumn),endRow:Math.max(n.endRow,o.range.endRow),endColumn:Math.max(n.endColumn,o.range.endColumn)};r=i.startRow!==n.startRow||i.startColumn!==n.startColumn||i.endRow!==n.endRow||i.endColumn!==n.endColumn,n=i;}}return n}function FI(e,t,n,r,o){let i=nr(af(e.active.row,t,n),1,r.rowCount),s=nr(e.active.column,1,r.columnCount);return e.kind==="row"?Js(i,{columnCount:r.columnCount}):_t(gt(i,s),o)}function HI(e,t,n,r,o){let i=nr(e.active.row,1,r.rowCount),s=nr(af(e.active.column,t,n),1,r.columnCount);return e.kind==="column"?Qs(s,{rowCount:r.rowCount}):_t(gt(i,s),o)}function af(e,t,n){let r=t+n-1;return e<t?e:e>r?e-n:t}function jv(e,t){return !(e.endRow<t.startRow||e.startRow>t.endRow||e.endColumn<t.startColumn||e.startColumn>t.endColumn)}function Uv(e,t,n){let r=n.mergeFollowerByAddress.get(excel.formatCellAddress(e,t));if(!r)return null;let o=n.mergeMasterByAddress.get(r);return o?{row:o.range.startRow,column:o.range.startColumn}:null}function nr(e,t,n){return Math.max(t,Math.min(n,e))}function el(e,t){let n=qv(e,t);return {text:n,values:tl(n),styleIds:Jv(e,t),merges:Zv(e,t)}}function qv(e,t){let n=[];for(let r=t.startRow;r<=t.endRow;r++){let o=[];for(let i=t.startColumn;i<=t.endColumn;i++)o.push(Xv(Yv(e,r,i)));n.push(o.join(" "));}return n.join(`
1548
+ `)}function tl(e){return e.replace(/\r\n/g,`
1542
1549
  `).replace(/\r/g,`
1543
1550
  `).split(`
1544
- `).filter((t,n,r)=>!(n===r.length-1&&t==="")).map(t=>t.split(" ").map(jv))}function MI(e,t,n){let r=Math.max(1,n.length),o=Math.max(1,n.reduce((i,s)=>Math.max(i,s.length),0));return excel.formatRangeAddress(e,t,r,o)}function Ov(e){return e.replace(/\t/g," ").replace(/\r?\n/g," ")}function $v(e,t,n){var o,i;let r=excel.formatCellAddress(t,n);return e.mergeFollowerByAddress.has(r)?"":(i=(o=qe(e,t,n))==null?void 0:o.displayText)!=null?i:""}function zv(e,t){let n=[];for(let r of e.mergeMasterByAddress.values())Gv(t,r.range)&&n.push({startRowOffset:r.range.startRow-t.startRow,startColumnOffset:r.range.startColumn-t.startColumn,rowCount:r.range.endRow-r.range.startRow+1,columnCount:r.range.endColumn-r.range.startColumn+1});return n}function Vv(e,t){var r;let n=[];for(let o=t.startRow;o<=t.endRow;o++){let i=[];for(let s=t.startColumn;s<=t.endColumn;s++)i.push((r=qe(e,o,s))==null?void 0:r.styleId);n.push(i);}return n}function Gv(e,t){return t.startRow>=e.startRow&&t.endRow<=e.endRow&&t.startColumn>=e.startColumn&&t.endColumn<=e.endColumn}function jv(e){if(e==="")return null;let t=Number(e);return Number.isFinite(t)&&e.trim()!==""?t:e==="TRUE"?true:e==="FALSE"?false:e}function rf(e,t,n){var a;let r=Qs(t),o=Qs(n),i=Kv(r,o);if(Js(r,e)||Js(o,e))throw new Error("Auto fill does not support merged cells");let s=[];for(let l=o.startRow;l<=o.endRow;l++)for(let c=o.startColumn;c<=o.endColumn;c++){if(qv(l,c,r))continue;let u=i==="down"?r.startRow+nf(l-r.startRow,of(r)):l,f=i==="right"?r.startColumn+nf(c-r.startColumn,af(r)):c,p=qe(e,u,f),w=_v(e,r,i,l,c),b=p!=null&&p.formula?excel.shiftFormulaReferences(p.formula,l-u,c-f):void 0;s.push({row:l,column:c,value:b?null:(a=w!=null?w:p==null?void 0:p.source.value)!=null?a:null,formula:b,styleId:p==null?void 0:p.styleId});}return {direction:i,source:r,target:o,cells:s}}function el(e,t){return !Js(Qs(t),e)}function Kv(e,t){if(t.startRow===e.startRow&&t.startColumn===e.startColumn&&t.endColumn===e.endColumn&&t.endRow>e.endRow)return "down";if(t.startRow===e.startRow&&t.endRow===e.endRow&&t.startColumn===e.startColumn&&t.endColumn>e.endColumn)return "right";throw new Error("Auto fill target must extend the source selection down or right")}function _v(e,t,n,r,o){let i=n==="down"?of(t):af(t);if(i<2)return;let s=Array.from({length:i},(c,u)=>{let f=n==="down"?t.startRow+u:r,p=n==="right"?t.startColumn+u:o,w=qe(e,f,p);return w!=null&&w.formula||w==null?void 0:w.source.value});if(!s.every(c=>typeof c=="number"&&Number.isFinite(c)))return;let a=s[1]-s[0];if(!s.every((c,u)=>u===0||c===s[0]+a*u))return;let l=n==="down"?r-t.startRow:o-t.startColumn;return s[0]+a*l}function Js(e,t){for(let n of t.mergeMasterByAddress.values())if(Xv(e,n.range))return true;return false}function Qs(e){return {startRow:Math.min(e.startRow,e.endRow),startColumn:Math.min(e.startColumn,e.endColumn),endRow:Math.max(e.startRow,e.endRow),endColumn:Math.max(e.startColumn,e.endColumn)}}function of(e){return e.endRow-e.startRow+1}function af(e){return e.endColumn-e.startColumn+1}function qv(e,t,n){return e>=n.startRow&&e<=n.endRow&&t>=n.startColumn&&t<=n.endColumn}function Xv(e,t){return !(e.endRow<t.startRow||e.startRow>t.endRow||e.endColumn<t.startColumn||e.startColumn>t.endColumn)}function nf(e,t){return (e%t+t)%t}async function DI(e,t,n,r){await e.worksheets.getItem(t).getCell(n).setValue(r);}async function HI(e,t,n,r){await e.worksheets.getItem(t).getCell(n).setFormula(r);}async function OI(e,t,n,r,o){let i=o.length,s=o.reduce((l,c)=>Math.max(l,c.length),0),a=o.map(l=>{let c=l.slice();for(;c.length<s;)c.push(null);return c});await e.worksheets.getItem(t).getRange(excel.formatRangeAddress(n,r,i,s)).setValues(a);}async function $I(e,t,n,r,o,i){await e.worksheets.getItem(t).getRange(excel.formatRangeAddress(n,r,o,i)).clear();}async function zI(e,t,n,r){await e.worksheets.getItem(t).getRange(excel.formatCellAddress(n,1)).setRowHeight(r);}async function VI(e,t,n,r){await e.worksheets.getItem(t).getRange(excel.formatCellAddress(1,n)).setColumnWidth(yi(r));}function uf(e,t){let n=t.query.trim();if(!n)return [];let r=[],o=[...e.cellsByAddress.values()].sort((i,s)=>i.row-s.row||i.column-s.column);for(let i of o)if(pf(i,t.matchCase===true).includes(tl(n,t.matchCase===true)))if(i.formula){let s=n.startsWith("=")?n.slice(1):n;r.push({address:i.address,formula:cf(i.formula,s,t.replacement,t.matchCase===true)});}else {let s=i.value===null?"":String(i.value);r.push({address:i.address,value:cf(s,n,t.replacement,t.matchCase===true)});}return r}function jI(e,t){let n=tl(t.query,t.matchCase===true);if(!n)return [];let r=[],o=[...e.cellsByAddress.values()].sort((i,s)=>i.row-s.row||i.column-s.column);for(let i of o)pf(i,t.matchCase===true).includes(n)&&r.push({row:i.row,column:i.column,address:i.address,text:i.displayText});return r}function UI(e,t,n="forward"){var r,o,i,s;return e.length===0?null:n==="backward"?(o=(r=[...e].reverse().find(a=>df(a,t)<0))!=null?r:e[e.length-1])!=null?o:null:(s=(i=e.find(a=>df(a,t)>0))!=null?i:e[0])!=null?s:null}function KI(e){return {startRow:e.row,startColumn:e.column,endRow:e.row,endColumn:e.column}}function pf(e,t){let n=[e.displayText,Yv(e.value),e.formula?`=${e.formula}`:""].filter(Boolean);return tl(n.join(`
1545
- `),t)}function Yv(e){return e===null?"":String(e)}function tl(e,t){let n=e.trim();return t?n:n.toLocaleLowerCase()}function df(e,t){return e.row===t.row?e.column-t.column:e.row-t.row}function cf(e,t,n,r){if(!t)return e;let o=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return e.replace(new RegExp(o,r?"g":"gi"),n)}function nl(e,t,n){var o,i;let r=new Set;for(let s=t.startRow+1;s<=t.endRow;s+=1)r.add((i=(o=qe(e,s,n))==null?void 0:o.displayText)!=null?i:"");return [...r].sort((s,a)=>s.localeCompare(a,void 0,{numeric:true}))}function XI(e,t,n){var o,i,s;let r=new Set;for(let a=t.startRow+1;a<=t.endRow;a+=1)(o=e.rowMetaByIndex.get(a))!=null&&o.hidden||r.add((s=(i=qe(e,a,n))==null?void 0:i.displayText)!=null?s:"");return [...r].sort((a,l)=>a.localeCompare(l,void 0,{numeric:true}))}function ff(e,t,n,r){var s,a;let o=new Set(typeof r=="string"?[r]:r),i=[];for(let l=t.startRow+1;l<=t.endRow;l+=1)o.has((a=(s=qe(e,l,n))==null?void 0:s.displayText)!=null?a:"")||i.push(l);return i}function mf(e,t,n){let r=n.map(i=>[i.column,new Set(i.values)]),o=[];for(let i=t.startRow+1;i<=t.endRow;i+=1)r.every(([a,l])=>{var c,u;return l.has((u=(c=qe(e,i,a))==null?void 0:c.displayText)!=null?u:"")})||o.push(i);return o}function hf(e,t,n,r){let o=Array.from({length:t.endRow-t.startRow},(i,s)=>t.startRow+s+1);return o.sort((i,s)=>{var u,f,p,w;let a=(f=(u=qe(e,i,n))==null?void 0:u.displayText)!=null?f:"",l=(w=(p=qe(e,s,n))==null?void 0:p.displayText)!=null?w:"";if(a===""&&l!=="")return 1;if(a!==""&&l==="")return -1;let c=a.localeCompare(l,void 0,{numeric:true,sensitivity:"base"});return (r==="desc"?-c:c)||i-s}),o}var Mi=class e{constructor(t,n={}){O(this,"state",t);O(this,"activeTransaction",null);O(this,"activeTransactionSource",null);O(this,"transactionNeedsRefresh",false);O(this,"readOnlyValue");this.readOnlyValue=n.readOnly===true;}static async fromZip(t,n={}){let s=n,{readOnly:r}=s,o=In(s,["readOnly"]),i=await excel.ExcelWorkbook.fromZip(t,o);return e.fromWorkbook(i,{readOnly:r})}static async fromWorkbook(t,n={}){let r=await t.toModel(),o=r.sheets[0];if(!o)throw new Error("SpreadsheetEditorRuntime: workbook has no sheets");let i=new excel.SpreadsheetFormulaEngine(o,{sheets:r.sheets}),s=i.calculate();return new e({workbook:t,model:r,activeSheetName:o.name,formulaResults:s,formulaEngine:i,activeSheet:Qr(o,r.styles,{formulaResults:s,date1904:r.date1904})},n)}isReadOnly(){return this.readOnlyValue}setReadOnly(t){if(this.activeTransaction)throw new Error("SpreadsheetEditorRuntime: cannot change read-only state during a transaction");this.readOnlyValue=t;}workbook(){return this.assertWritable(),this.state.workbook}model(){return this.state.model}activeSheetName(){return this.state.activeSheetName}activeSheet(){return this.state.activeSheet}canUndo(){return !this.readOnlyValue&&this.state.workbook.history().canUndo()}canRedo(){return !this.readOnlyValue&&this.state.workbook.history().canRedo()}async undo(){this.assertWritable();let t=await this.state.workbook.history().undo();return t?(await this.refresh(),t):null}async redo(){this.assertWritable();let t=await this.state.workbook.history().redo();return t?(await this.refresh(),t):null}async runUserTransaction(t,n){return this.assertWritable(),this.runScopedTransaction("user",r=>this.state.workbook.history().runGroup($(v({},t),{source:"user"}),r),n)}async runAgentTransaction(t,n){return this.assertWritable(),this.runScopedTransaction("agent",r=>this.state.workbook.history().runAgentGroup(t,r),()=>n(this))}async previewAgentTransaction(t,n){var s;let r=wf(this.state.model),o=await excel.ExcelWorkbook.fromModel(r,{mode:"inline"}),i=await e.fromWorkbook(o);await i.setActiveSheet(this.state.activeSheetName);try{let a=await i.runAgentTransaction(t,n),l=wf(i.model()),c=excel.diffExcelWorkbookModels(r,l);return {result:a,summary:(s=a==null?void 0:a.summary)!=null?s:null,diff:c,diffSummary:aS(c),beforeModel:r,afterModel:l,activeSheetName:i.activeSheetName()}}finally{await i.dispose();}}async setActiveSheet(t){let n=this.state.model.sheets.find(i=>i.name===t);if(!n)throw new Error(`SpreadsheetEditorRuntime: sheet not found: ${t}`);let r=new excel.SpreadsheetFormulaEngine(n,{sheets:this.state.model.sheets}),o=r.calculate();this.state.activeSheetName=n.name,this.state.formulaResults=o,this.state.formulaEngine=r,this.state.activeSheet=Qr(n,this.state.model.styles,{formulaResults:o,date1904:this.state.model.date1904});}async addSheet(t){await this.runWorksheetStructureMutation(n=>n.addSheet(t),()=>this.state.workbook.worksheets.add(t).then(()=>{})),await this.setActiveSheet(t);}async renameSheet(t,n){let r=t===this.state.activeSheetName;await this.runWorksheetStructureMutation(o=>o.renameSheet(t,n),()=>this.state.workbook.worksheets.getItem(t).rename(n)),r&&await this.setActiveSheet(n);}async copySheet(t,n){await this.runWorksheetStructureMutation(r=>r.copySheet(t,n),()=>this.state.workbook.worksheets.copy(t,n).then(()=>{})),await this.setActiveSheet(n);}async deleteSheet(t){var i;let n=this.state.model.sheets.findIndex(s=>s.name===t);if(n===-1)throw new Error(`SpreadsheetEditorRuntime: sheet not found: ${t}`);if(this.state.model.sheets.length===1)throw new Error("SpreadsheetEditorRuntime: cannot delete the last worksheet");let r=(i=this.state.model.sheets[n+1])!=null?i:this.state.model.sheets[n-1],o=t===this.state.activeSheetName;await this.runWorksheetStructureMutation(s=>s.deleteSheet(t),()=>this.state.workbook.worksheets.deleteItem(t)),o&&r&&await this.setActiveSheet(r.name);}async moveSheet(t,n){await this.runWorksheetStructureMutation(r=>r.moveSheet(t,n),()=>this.state.workbook.worksheets.move(t,n));}async refresh(){var i;let t=await this.state.workbook.toModel(),n=(i=t.sheets.find(s=>s.name===this.state.activeSheetName))!=null?i:t.sheets[0];if(!n)throw new Error("SpreadsheetEditorRuntime: workbook has no sheets");let r=new excel.SpreadsheetFormulaEngine(n,{sheets:t.sheets}),o=r.calculate();this.state=$(v({},this.state),{model:t,activeSheetName:n.name,formulaResults:o,formulaEngine:r,activeSheet:Qr(n,t.styles,{formulaResults:o,date1904:t.date1904})});}async setCellValue(t,n,r={}){let o=this.editableCellAddress(t);await this.runUserMutation(this.cellEditHistoryGroup(`Set ${o}`,o,r),async i=>{await i.setCellValue(this.state.activeSheetName,o,n);});}async setCellFormula(t,n,r={}){let o=this.editableCellAddress(t);await this.runUserMutation(this.cellEditHistoryGroup(`Set ${o} formula`,o,r),async i=>{await i.setCellFormula(this.state.activeSheetName,o,n);});}async replaceAll(t,n,r=false){let o=uf(this.state.activeSheet,{query:t,replacement:n,matchCase:r});return o.length===0?0:(await this.runUserMutation({label:`Replace ${t}`},async i=>{var s;for(let a of o)a.formula!==void 0?await i.setCellFormula(this.state.activeSheetName,a.address,a.formula):await i.setCellValue(this.state.activeSheetName,a.address,(s=a.value)!=null?s:null);}),o.length)}async filterRows(t,n,r,o){let i={startRow:t,startColumn:r,endRow:n,endColumn:r},s=o===null?[]:ff(this.state.activeSheet,$(v({},i),{startColumn:1,endColumn:this.state.activeSheet.maxColumn}),r,o);await this.runUserMutation({label:o===null?"Clear filter":"Filter rows"},async a=>{await a.runSnapshot("Filter rows","spreadsheet row filter",async()=>{await this.state.workbook.executeCode(`
1551
+ `).filter((t,n,r)=>!(n===r.length-1&&t==="")).map(t=>t.split(" ").map(eS))}function GI(e,t,n){let r=Math.max(1,n.length),o=Math.max(1,n.reduce((i,s)=>Math.max(i,s.length),0));return excel.formatRangeAddress(e,t,r,o)}function Xv(e){return e.replace(/\t/g," ").replace(/\r?\n/g," ")}function Yv(e,t,n){var o,i;let r=excel.formatCellAddress(t,n);return e.mergeFollowerByAddress.has(r)?"":(i=(o=qe(e,t,n))==null?void 0:o.displayText)!=null?i:""}function Zv(e,t){let n=[];for(let r of e.mergeMasterByAddress.values())Qv(t,r.range)&&n.push({startRowOffset:r.range.startRow-t.startRow,startColumnOffset:r.range.startColumn-t.startColumn,rowCount:r.range.endRow-r.range.startRow+1,columnCount:r.range.endColumn-r.range.startColumn+1});return n}function Jv(e,t){var r;let n=[];for(let o=t.startRow;o<=t.endRow;o++){let i=[];for(let s=t.startColumn;s<=t.endColumn;s++)i.push((r=qe(e,o,s))==null?void 0:r.styleId);n.push(i);}return n}function Qv(e,t){return t.startRow>=e.startRow&&t.endRow<=e.endRow&&t.startColumn>=e.startColumn&&t.endColumn<=e.endColumn}function eS(e){if(e==="")return null;let t=Number(e);return Number.isFinite(t)&&e.trim()!==""?t:e==="TRUE"?true:e==="FALSE"?false:e}function lf(e,t,n){var a;let r=rl(t),o=rl(n),i=nS(r,o);if(nl(r,e)||nl(o,e))throw new Error("Auto fill does not support merged cells");let s=[];for(let l=o.startRow;l<=o.endRow;l++)for(let c=o.startColumn;c<=o.endColumn;c++){if(oS(l,c,r))continue;let u=i==="down"?r.startRow+sf(l-r.startRow,df(r)):l,f=i==="right"?r.startColumn+sf(c-r.startColumn,cf(r)):c,p=qe(e,u,f),w=rS(e,r,i,l,c),b=p!=null&&p.formula?excel.shiftFormulaReferences(p.formula,l-u,c-f):void 0;s.push({row:l,column:c,value:b?null:(a=w!=null?w:p==null?void 0:p.source.value)!=null?a:null,formula:b,styleId:p==null?void 0:p.styleId});}return {direction:i,source:r,target:o,cells:s}}function ol(e,t){return !nl(rl(t),e)}function nS(e,t){if(t.startRow===e.startRow&&t.startColumn===e.startColumn&&t.endColumn===e.endColumn&&t.endRow>e.endRow)return "down";if(t.startRow===e.startRow&&t.endRow===e.endRow&&t.startColumn===e.startColumn&&t.endColumn>e.endColumn)return "right";throw new Error("Auto fill target must extend the source selection down or right")}function rS(e,t,n,r,o){let i=n==="down"?df(t):cf(t);if(i<2)return;let s=Array.from({length:i},(c,u)=>{let f=n==="down"?t.startRow+u:r,p=n==="right"?t.startColumn+u:o,w=qe(e,f,p);return w!=null&&w.formula||w==null?void 0:w.source.value});if(!s.every(c=>typeof c=="number"&&Number.isFinite(c)))return;let a=s[1]-s[0];if(!s.every((c,u)=>u===0||c===s[0]+a*u))return;let l=n==="down"?r-t.startRow:o-t.startColumn;return s[0]+a*l}function nl(e,t){for(let n of t.mergeMasterByAddress.values())if(iS(e,n.range))return true;return false}function rl(e){return {startRow:Math.min(e.startRow,e.endRow),startColumn:Math.min(e.startColumn,e.endColumn),endRow:Math.max(e.startRow,e.endRow),endColumn:Math.max(e.startColumn,e.endColumn)}}function df(e){return e.endRow-e.startRow+1}function cf(e){return e.endColumn-e.startColumn+1}function oS(e,t,n){return e>=n.startRow&&e<=n.endRow&&t>=n.startColumn&&t<=n.endColumn}function iS(e,t){return !(e.endRow<t.startRow||e.startRow>t.endRow||e.endColumn<t.startColumn||e.startColumn>t.endColumn)}function sf(e,t){return (e%t+t)%t}async function YI(e,t,n,r){await e.worksheets.getItem(t).getCell(n).setValue(r);}async function ZI(e,t,n,r){await e.worksheets.getItem(t).getCell(n).setFormula(r);}async function JI(e,t,n,r,o){let i=o.length,s=o.reduce((l,c)=>Math.max(l,c.length),0),a=o.map(l=>{let c=l.slice();for(;c.length<s;)c.push(null);return c});await e.worksheets.getItem(t).getRange(excel.formatRangeAddress(n,r,i,s)).setValues(a);}async function QI(e,t,n,r,o,i){await e.worksheets.getItem(t).getRange(excel.formatRangeAddress(n,r,o,i)).clear();}async function eN(e,t,n,r){await e.worksheets.getItem(t).getRange(excel.formatCellAddress(n,1)).setRowHeight(r);}async function tN(e,t,n,r){await e.worksheets.getItem(t).getRange(excel.formatCellAddress(1,n)).setColumnWidth(Ei(r));}function hf(e,t){let n=t.query.trim();if(!n)return [];let r=[],o=[...e.cellsByAddress.values()].sort((i,s)=>i.row-s.row||i.column-s.column);for(let i of o)if(gf(i,t.matchCase===true).includes(il(n,t.matchCase===true)))if(i.formula){let s=n.startsWith("=")?n.slice(1):n;r.push({address:i.address,formula:mf(i.formula,s,t.replacement,t.matchCase===true)});}else {let s=i.value===null?"":String(i.value);r.push({address:i.address,value:mf(s,n,t.replacement,t.matchCase===true)});}return r}function rN(e,t){let n=il(t.query,t.matchCase===true);if(!n)return [];let r=[],o=[...e.cellsByAddress.values()].sort((i,s)=>i.row-s.row||i.column-s.column);for(let i of o)gf(i,t.matchCase===true).includes(n)&&r.push({row:i.row,column:i.column,address:i.address,text:i.displayText});return r}function oN(e,t,n="forward"){var r,o,i,s;return e.length===0?null:n==="backward"?(o=(r=[...e].reverse().find(a=>ff(a,t)<0))!=null?r:e[e.length-1])!=null?o:null:(s=(i=e.find(a=>ff(a,t)>0))!=null?i:e[0])!=null?s:null}function iN(e){return {startRow:e.row,startColumn:e.column,endRow:e.row,endColumn:e.column}}function gf(e,t){let n=[e.displayText,aS(e.value),e.formula?`=${e.formula}`:""].filter(Boolean);return il(n.join(`
1552
+ `),t)}function aS(e){return e===null?"":String(e)}function il(e,t){let n=e.trim();return t?n:n.toLocaleLowerCase()}function ff(e,t){return e.row===t.row?e.column-t.column:e.row-t.row}function mf(e,t,n,r){if(!t)return e;let o=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return e.replace(new RegExp(o,r?"g":"gi"),n)}function al(e,t,n){var o,i;let r=new Set;for(let s=t.startRow+1;s<=t.endRow;s+=1)r.add((i=(o=qe(e,s,n))==null?void 0:o.displayText)!=null?i:"");return [...r].sort((s,a)=>s.localeCompare(a,void 0,{numeric:true}))}function lN(e,t,n){var o,i,s;let r=new Set;for(let a=t.startRow+1;a<=t.endRow;a+=1)(o=e.rowMetaByIndex.get(a))!=null&&o.hidden||r.add((s=(i=qe(e,a,n))==null?void 0:i.displayText)!=null?s:"");return [...r].sort((a,l)=>a.localeCompare(l,void 0,{numeric:true}))}function bf(e,t,n,r){var s,a;let o=new Set(typeof r=="string"?[r]:r),i=[];for(let l=t.startRow+1;l<=t.endRow;l+=1)o.has((a=(s=qe(e,l,n))==null?void 0:s.displayText)!=null?a:"")||i.push(l);return i}function wf(e,t,n){let r=n.map(i=>[i.column,new Set(i.values)]),o=[];for(let i=t.startRow+1;i<=t.endRow;i+=1)r.every(([a,l])=>{var c,u;return l.has((u=(c=qe(e,i,a))==null?void 0:c.displayText)!=null?u:"")})||o.push(i);return o}function xf(e,t,n,r){let o=Array.from({length:t.endRow-t.startRow},(i,s)=>t.startRow+s+1);return o.sort((i,s)=>{var u,f,p,w;let a=(f=(u=qe(e,i,n))==null?void 0:u.displayText)!=null?f:"",l=(w=(p=qe(e,s,n))==null?void 0:p.displayText)!=null?w:"";if(a===""&&l!=="")return 1;if(a!==""&&l==="")return -1;let c=a.localeCompare(l,void 0,{numeric:true,sensitivity:"base"});return (r==="desc"?-c:c)||i-s}),o}var Wi=class e{constructor(t,n={}){O(this,"state",t);O(this,"activeTransaction",null);O(this,"activeTransactionSource",null);O(this,"transactionNeedsRefresh",false);O(this,"readOnlyValue");this.readOnlyValue=n.readOnly===true;}static async fromZip(t,n={}){let s=n,{readOnly:r}=s,o=Nn(s,["readOnly"]),i=await excel.ExcelWorkbook.fromZip(t,o);return e.fromWorkbook(i,{readOnly:r})}static async fromWorkbook(t,n={}){let r=await t.toModel(),o=r.sheets[0];if(!o)throw new Error("SpreadsheetEditorRuntime: workbook has no sheets");let i=new excel.SpreadsheetFormulaEngine(o,{sheets:r.sheets}),s=i.calculate();return new e({workbook:t,model:r,activeSheetName:o.name,formulaResults:s,formulaEngine:i,activeSheet:no(o,r.styles,{formulaResults:s,date1904:r.date1904})},n)}isReadOnly(){return this.readOnlyValue}setReadOnly(t){if(this.activeTransaction)throw new Error("SpreadsheetEditorRuntime: cannot change read-only state during a transaction");this.readOnlyValue=t;}workbook(){return this.assertWritable(),this.state.workbook}model(){return this.state.model}activeSheetName(){return this.state.activeSheetName}activeSheet(){return this.state.activeSheet}canUndo(){return !this.readOnlyValue&&this.state.workbook.history().canUndo()}canRedo(){return !this.readOnlyValue&&this.state.workbook.history().canRedo()}async undo(){this.assertWritable();let t=await this.state.workbook.history().undo();return t?(await this.refresh(),t):null}async redo(){this.assertWritable();let t=await this.state.workbook.history().redo();return t?(await this.refresh(),t):null}async runUserTransaction(t,n){return this.assertWritable(),this.runScopedTransaction("user",r=>this.state.workbook.history().runGroup($(v({},t),{source:"user"}),r),n)}async runAgentTransaction(t,n){return this.assertWritable(),this.runScopedTransaction("agent",r=>this.state.workbook.history().runAgentGroup(t,r),()=>n(this))}async previewAgentTransaction(t,n){var s;let r=Sf(this.state.model),o=await excel.ExcelWorkbook.fromModel(r,{mode:"inline"}),i=await e.fromWorkbook(o);await i.setActiveSheet(this.state.activeSheetName);try{let a=await i.runAgentTransaction(t,n),l=Sf(i.model()),c=excel.diffExcelWorkbookModels(r,l);return {result:a,summary:(s=a==null?void 0:a.summary)!=null?s:null,diff:c,diffSummary:gS(c),beforeModel:r,afterModel:l,activeSheetName:i.activeSheetName()}}finally{await i.dispose();}}async setActiveSheet(t){let n=this.state.model.sheets.find(i=>i.name===t);if(!n)throw new Error(`SpreadsheetEditorRuntime: sheet not found: ${t}`);let r=new excel.SpreadsheetFormulaEngine(n,{sheets:this.state.model.sheets}),o=r.calculate();this.state.activeSheetName=n.name,this.state.formulaResults=o,this.state.formulaEngine=r,this.state.activeSheet=no(n,this.state.model.styles,{formulaResults:o,date1904:this.state.model.date1904});}async addSheet(t){await this.runWorksheetStructureMutation(n=>n.addSheet(t),()=>this.state.workbook.worksheets.add(t).then(()=>{})),await this.setActiveSheet(t);}async renameSheet(t,n){let r=t===this.state.activeSheetName;await this.runWorksheetStructureMutation(o=>o.renameSheet(t,n),()=>this.state.workbook.worksheets.getItem(t).rename(n)),r&&await this.setActiveSheet(n);}async copySheet(t,n){await this.runWorksheetStructureMutation(r=>r.copySheet(t,n),()=>this.state.workbook.worksheets.copy(t,n).then(()=>{})),await this.setActiveSheet(n);}async deleteSheet(t){var i;let n=this.state.model.sheets.findIndex(s=>s.name===t);if(n===-1)throw new Error(`SpreadsheetEditorRuntime: sheet not found: ${t}`);if(this.state.model.sheets.length===1)throw new Error("SpreadsheetEditorRuntime: cannot delete the last worksheet");let r=(i=this.state.model.sheets[n+1])!=null?i:this.state.model.sheets[n-1],o=t===this.state.activeSheetName;await this.runWorksheetStructureMutation(s=>s.deleteSheet(t),()=>this.state.workbook.worksheets.deleteItem(t)),o&&r&&await this.setActiveSheet(r.name);}async moveSheet(t,n){await this.runWorksheetStructureMutation(r=>r.moveSheet(t,n),()=>this.state.workbook.worksheets.move(t,n));}async refresh(){var i;let t=await this.state.workbook.toModel(),n=(i=t.sheets.find(s=>s.name===this.state.activeSheetName))!=null?i:t.sheets[0];if(!n)throw new Error("SpreadsheetEditorRuntime: workbook has no sheets");let r=new excel.SpreadsheetFormulaEngine(n,{sheets:t.sheets}),o=r.calculate();this.state=$(v({},this.state),{model:t,activeSheetName:n.name,formulaResults:o,formulaEngine:r,activeSheet:no(n,t.styles,{formulaResults:o,date1904:t.date1904})});}async setCellValue(t,n,r={}){let o=this.editableCellAddress(t);await this.runUserMutation(this.cellEditHistoryGroup(`Set ${o}`,o,r),async i=>{await i.setCellValue(this.state.activeSheetName,o,n);});}async setCellFormula(t,n,r={}){let o=this.editableCellAddress(t);await this.runUserMutation(this.cellEditHistoryGroup(`Set ${o} formula`,o,r),async i=>{await i.setCellFormula(this.state.activeSheetName,o,n);});}async replaceAll(t,n,r=false){let o=hf(this.state.activeSheet,{query:t,replacement:n,matchCase:r});return o.length===0?0:(await this.runUserMutation({label:`Replace ${t}`},async i=>{var s;for(let a of o)a.formula!==void 0?await i.setCellFormula(this.state.activeSheetName,a.address,a.formula):await i.setCellValue(this.state.activeSheetName,a.address,(s=a.value)!=null?s:null);}),o.length)}async filterRows(t,n,r,o){let i={startRow:t,startColumn:r,endRow:n,endColumn:r},s=o===null?[]:bf(this.state.activeSheet,$(v({},i),{startColumn:1,endColumn:this.state.activeSheet.maxColumn}),r,o);await this.runUserMutation({label:o===null?"Clear filter":"Filter rows"},async a=>{await a.runSnapshot("Filter rows","spreadsheet row filter",async()=>{await this.state.workbook.executeCode(`
1546
1553
  const sheet = workbook.worksheets.getItem(args.sheetName);
1547
1554
  const hidden = new Set(args.hiddenRows);
1548
1555
  for (let index = args.startRow + 1; index <= args.endRow; index += 1) {
@@ -1556,7 +1563,7 @@ coco-word-native-table.coco-word-revision-delete {
1556
1563
  }
1557
1564
  }
1558
1565
  sheet.model.rows.sort((left, right) => left.index - right.index);
1559
- `,{sheetName:this.state.activeSheetName,startRow:t,endRow:n,hiddenRows:s});});});}async filterRowsByColumns(t,n,r){let o={startRow:t,endRow:n,endColumn:this.state.activeSheet.maxColumn},i=mf(this.state.activeSheet,o,r);await this.runUserMutation({label:"Filter rows"},async s=>{await s.runSnapshot("Filter rows","spreadsheet row filter",async()=>{await this.state.workbook.executeCode(`
1566
+ `,{sheetName:this.state.activeSheetName,startRow:t,endRow:n,hiddenRows:s});});});}async filterRowsByColumns(t,n,r){let o={startRow:t,endRow:n,endColumn:this.state.activeSheet.maxColumn},i=wf(this.state.activeSheet,o,r);await this.runUserMutation({label:"Filter rows"},async s=>{await s.runSnapshot("Filter rows","spreadsheet row filter",async()=>{await this.state.workbook.executeCode(`
1560
1567
  const sheet = workbook.worksheets.getItem(args.sheetName);
1561
1568
  const hidden = new Set(args.hiddenRows);
1562
1569
  for (let index = args.startRow + 1; index <= args.endRow; index += 1) {
@@ -1570,7 +1577,7 @@ coco-word-native-table.coco-word-revision-delete {
1570
1577
  }
1571
1578
  }
1572
1579
  sheet.model.rows.sort((left, right) => left.index - right.index);
1573
- `,{sheetName:this.state.activeSheetName,startRow:t,endRow:n,hiddenRows:i});});});}async sortRows(t,n,r,o){let i={startRow:t,endRow:n,endColumn:this.state.activeSheet.maxColumn},s=hf(this.state.activeSheet,i,r,o),a=new Map(s.map((c,u)=>[c,t+u+1])),l=this.state.activeSheet.source.cells.filter(c=>c.formula).map(c=>{var u;return [c.address,excel.rewriteFormulaForRowSort((u=c.formula)!=null?u:"",a,{sheetName:this.state.activeSheetName})]});await this.runUserMutation({label:o==="asc"?"Sort ascending":"Sort descending"},async c=>{await c.runSnapshot("Sort rows","spreadsheet row sort",async()=>{await this.state.workbook.executeCode(`
1580
+ `,{sheetName:this.state.activeSheetName,startRow:t,endRow:n,hiddenRows:i});});});}async sortRows(t,n,r,o){let i={startRow:t,endRow:n,endColumn:this.state.activeSheet.maxColumn},s=xf(this.state.activeSheet,i,r,o),a=new Map(s.map((c,u)=>[c,t+u+1])),l=this.state.activeSheet.source.cells.filter(c=>c.formula).map(c=>{var u;return [c.address,excel.rewriteFormulaForRowSort((u=c.formula)!=null?u:"",a,{sheetName:this.state.activeSheetName})]});await this.runUserMutation({label:o==="asc"?"Sort ascending":"Sort descending"},async c=>{await c.runSnapshot("Sort rows","spreadsheet row sort",async()=>{await this.state.workbook.executeCode(`
1574
1581
  const sheet = workbook.worksheets.getItem(args.sheetName);
1575
1582
  const rowMap = new Map(args.rowMap);
1576
1583
  const formulas = new Map(args.formulas);
@@ -1598,14 +1605,14 @@ coco-word-native-table.coco-word-revision-delete {
1598
1605
  }
1599
1606
  sheet.model.cells.sort((left, right) => left.row - right.row || left.column - right.column);
1600
1607
  sheet.model.rows.sort((left, right) => left.index - right.index);
1601
- `,{sheetName:this.state.activeSheetName,rowMap:[...a.entries()],formulas:l});});});}async setRangeValues(t,n,r){let o=r.length,i=r.reduce((a,l)=>Math.max(a,l.length),0),s=r.map(a=>{let l=a.slice();for(;l.length<i;)l.push(null);return l});await this.runUserMutation({label:"Set range values"},async a=>{await a.setRangeValues(this.state.activeSheetName,excel.formatRangeAddress(t,n,o,i),s);});}async autoFillRange(t,n){let r=rf(this.state.activeSheet,t,n);r.cells.length!==0&&await this.runUserMutation({label:"Auto fill"},async o=>{for(let i of r.cells){let s=excel.formatCellAddress(i.row,i.column);i.formula?await o.setCellFormula(this.state.activeSheetName,s,i.formula):await o.setCellValue(this.state.activeSheetName,s,i.value),await o.setRangeStyleId(this.state.activeSheetName,s,i.styleId);}});}async pasteRangeValues(t,n,r,o=[],i=[]){await this.pasteRange(t,n,r,{mode:"all",merges:o,styleIds:i});}async pasteRange(t,n,r,o={}){var w;let i=(w=o.mode)!=null?w:"all",s=r.length,a=r.reduce((b,g)=>Math.max(b,g.length),0),l=r.map(b=>{let g=b.slice();for(;g.length<a;)g.push(null);return g}),c=Math.max(1,s),u=Math.max(1,a),f={startRow:t,startColumn:n,endRow:t+c-1,endColumn:n+u-1},p=[...this.state.activeSheet.mergeMasterByAddress.values()].filter(b=>sS(f,b.range)).map(b=>b.address);await this.runUserMutation({label:iS(i)},async b=>{var g,h;if(i!=="formats"){for(let y of p)await b.unmergeRange(this.state.activeSheetName,y);await b.setRangeValues(this.state.activeSheetName,excel.formatRangeAddress(t,n,c,u),l);}i!=="values"&&await rS(b,this.state.activeSheetName,t,n,u,(g=o.styleIds)!=null?g:[]),i==="all"&&await oS(b,this.state.activeSheetName,t,n,(h=o.merges)!=null?h:[]);});}async clearRange(t,n,r,o){await this.runUserMutation({label:"Clear range"},async i=>{await i.clearRange(this.state.activeSheetName,excel.formatRangeAddress(t,n,r,o));});}async setRowHeight(t,n){await this.runUserMutation({label:"Set row height"},async r=>{await r.setRowHeight(this.state.activeSheetName,t,n);});}async setColumnWidth(t,n){await this.runUserMutation({label:"Set column width"},async r=>{await r.setColumnWidth(this.state.activeSheetName,t,yi(n));});}async setFreezePanes(t,n){let r=bf(t),o=bf(n),i=nS(this.state.activeSheet.source.sheetViews,r,o);await this.runUserMutation({label:r||o?"Freeze panes":"Unfreeze panes"},async s=>{await s.setSheetViews(this.state.activeSheetName,i);});}async insertRows(t,n=1){await this.runUserMutation({label:"Insert rows"},async r=>{await r.insertRows(this.state.activeSheetName,t,n);});}async deleteRows(t,n=1){await this.runUserMutation({label:"Delete rows"},async r=>{await r.deleteRows(this.state.activeSheetName,t,n);});}async insertColumns(t,n=1){await this.runUserMutation({label:"Insert columns"},async r=>{await r.insertColumns(this.state.activeSheetName,t,n);});}async deleteColumns(t,n=1){await this.runUserMutation({label:"Delete columns"},async r=>{await r.deleteColumns(this.state.activeSheetName,t,n);});}async setRangeBold(t,n,r,o,i){await this.runUserMutation({label:"Set bold"},async s=>{await s.setRangeBold(this.state.activeSheetName,excel.formatRangeAddress(t,n,r,o),i);});}async setRangeItalic(t,n,r,o,i){await this.runUserMutation({label:"Set italic"},async s=>{await s.setRangeItalic(this.state.activeSheetName,excel.formatRangeAddress(t,n,r,o),i);});}async setRangeUnderline(t,n,r,o,i){await this.runUserMutation({label:"Set underline"},async s=>{await s.setRangeUnderline(this.state.activeSheetName,excel.formatRangeAddress(t,n,r,o),i);});}async setRangeFontColor(t,n,r,o,i){await this.runUserMutation({label:"Set font color"},async s=>{await s.setRangeFontColor(this.state.activeSheetName,excel.formatRangeAddress(t,n,r,o),i);});}async setRangeFillColor(t,n,r,o,i){await this.runUserMutation({label:"Set fill color"},async s=>{await s.setRangeFillColor(this.state.activeSheetName,excel.formatRangeAddress(t,n,r,o),i);});}async setRangeHorizontalAlign(t,n,r,o,i){await this.runUserMutation({label:"Set horizontal align"},async s=>{await s.setRangeHorizontalAlign(this.state.activeSheetName,excel.formatRangeAddress(t,n,r,o),i);});}async setRangeVerticalAlign(t,n,r,o,i){await this.runUserMutation({label:"Set vertical align"},async s=>{await s.setRangeVerticalAlign(this.state.activeSheetName,excel.formatRangeAddress(t,n,r,o),i);});}async setRangeNumberFormat(t,n,r,o,i){await this.runUserMutation({label:"Set number format"},async s=>{await s.setRangeNumberFormat(this.state.activeSheetName,excel.formatRangeAddress(t,n,r,o),i);});}async clearRangeFormat(t,n,r,o){await this.runUserMutation({label:"Clear format"},async i=>{await i.clearRangeFormat(this.state.activeSheetName,excel.formatRangeAddress(t,n,r,o));});}async mergeRange(t,n,r,o){let i=excel.formatRangeAddress(t,n,r,o),s=await this.cellStyleId(excel.formatCellAddress(t,n));await this.runUserMutation({label:"Merge range"},async a=>{await a.setRangeStyleId(this.state.activeSheetName,i,s),await a.mergeRange(this.state.activeSheetName,i);});}async unmergeRanges(t){if(t.length===0)return;let n=t.map(r=>{let o=[...this.state.activeSheet.mergeMasterByAddress.values()].find(s=>s.address===r),i=o?excel.formatCellAddress(o.range.startRow,o.range.startColumn):lS(r);return {address:r,masterAddress:i}});await this.runUserMutation({label:"Unmerge ranges"},async r=>{for(let o of n)await r.setRangeStyleId(this.state.activeSheetName,o.address,await this.cellStyleId(o.masterAddress)),await r.unmergeRange(this.state.activeSheetName,o.address);});}async setRangeBorder(t,n,r,o,i){if(i==="clear"){await this.runUserMutation({label:"Clear border"},async a=>{await a.setRangeBorder(this.state.activeSheetName,excel.formatRangeAddress(t,n,r,o),{});});return}let s=tS();if(i==="all"){await this.runUserMutation({label:"Set all borders"},async a=>{await a.setRangeBorder(this.state.activeSheetName,excel.formatRangeAddress(t,n,r,o),{left:s,right:s,top:s,bottom:s});});return}await this.runUserMutation({label:`Set ${i} borders`},async a=>{await a.setRangeBorder(this.state.activeSheetName,excel.formatRangeAddress(t,n,r,o),{});for(let l=0;l<r;l++)for(let c=0;c<o;c++){let u={};i==="outer"?(l===0&&(u.top=s),l===r-1&&(u.bottom=s),c===0&&(u.left=s),c===o-1&&(u.right=s)):(c<o-1&&(u.right=s),l<r-1&&(u.bottom=s)),Object.keys(u).length!==0&&await a.setRangeBorder(this.state.activeSheetName,excel.formatCellAddress(t+l,n+c),u);}});}async toZip(){return this.state.workbook.toZip()}async moveChart(t,n){await this.runUserMutation({label:"Move chart"},async r=>{await r.runSnapshot("Move chart","spreadsheet chart position",async()=>{let o=this.state.model.sheets.find(p=>p.name===this.state.activeSheetName),i=o==null?void 0:o.charts[t];if(!o||!i)return;let s=o.drawings.findIndex(p=>p.path===i.drawingPath),a=s>=0?o.drawings[s]:o.drawings[0];if(!a)return;let l=a.anchors.findIndex(p=>{var w;return ((w=p.object)==null?void 0:w.kind)==="chart"&&(!i.relationshipId||p.object.relationshipId===i.relationshipId)});if(l<0)return;let u=(await this.state.workbook.worksheets.getItem(this.state.activeSheetName).drawings.items())[s>=0?s:0],f=u==null?void 0:u.anchors.getItem(l);f&&(f.from.setRow(n.from.row),f.from.setColumn(n.from.column),f.from.setRowOffset(n.from.rowOffset),f.from.setColumnOffset(n.from.columnOffset),n.to&&(f.to.setRow(n.to.row),f.to.setColumn(n.to.column),f.to.setRowOffset(n.to.rowOffset),f.to.setColumnOffset(n.to.columnOffset)));});});}async dispose(){await this.state.workbook.dispose();}editableCellAddress(t){var o;let n=excel.parseCellAddress(t),r=excel.formatCellAddress(n.row,n.column);return (o=this.state.activeSheet.mergeFollowerByAddress.get(r))!=null?o:r}rebuildActiveSheetRenderModel(){this.state.formulaResults=this.state.formulaEngine.calculate(),this.state.activeSheet=Qr(this.state.activeSheet.source,this.state.model.styles,{formulaResults:this.state.formulaResults,date1904:this.state.model.date1904});}async runUserMutation(t,n){if(this.assertWritable(),this.activeTransaction){await n(this.activeTransaction),this.transactionNeedsRefresh=true;return}await this.runScopedTransaction("user",r=>this.state.workbook.history().runGroup($(v({},t),{source:"user"}),r),async()=>{if(!this.activeTransaction)throw new Error("SpreadsheetEditorRuntime: transaction not active");await n(this.activeTransaction),this.transactionNeedsRefresh=true;});}async runWorksheetStructureMutation(t,n){if(this.assertWritable(),this.activeTransactionSource==="agent"&&this.activeTransaction){await t(this.activeTransaction),this.transactionNeedsRefresh=true,await this.refresh();return}await n(),await this.refresh();}async cellStyleId(t){var n;return (n=(await this.state.workbook.worksheets.getItem(this.state.activeSheetName).getRange(t).styleIds())[0])==null?void 0:n[0]}async runScopedTransaction(t,n,r){if(this.assertWritable(),this.activeTransaction)return await r(),this.transactionNeedsRefresh=true,null;let o=this.transactionNeedsRefresh;this.transactionNeedsRefresh=false;try{let i=await n(async a=>{this.activeTransaction=a,this.activeTransactionSource=t;try{await r();}finally{this.activeTransaction=null,this.activeTransactionSource=null;}});return (this.transactionNeedsRefresh||i!==null)&&await this.refresh(),i}finally{this.activeTransaction=null,this.activeTransactionSource=null,this.transactionNeedsRefresh=o;}}assertWritable(){if(this.readOnlyValue)throw new ln("spreadsheet")}cellEditHistoryGroup(t,n,r){var i;let o={label:t};return r.mergeUndo?$(v({},o),{mergeKey:`edit:${this.state.activeSheetName}!${n}`,mergeWindowMs:(i=r.mergeWindowMs)!=null?i:1e3}):o}range(t,n,r,o){return this.state.workbook.worksheets.getItem(this.state.activeSheetName).getRange(excel.formatRangeAddress(t,n,r,o))}};function tS(){return {style:"thin",color:{rgb:"#111827"}}}function bf(e){return Number.isFinite(e)?Math.max(0,Math.floor(e)):0}function nS(e,t,n){var i;if(!t&&!n)return e.map((s,a)=>$(v({},s),{pane:a===0?void 0:s.pane?v({},s.pane):void 0,selections:s.selections.map(l=>v({},l))}));let r=(i=e[0])!=null?i:{workbookViewId:0,selections:[]},o={xSplit:n||void 0,ySplit:t||void 0,topLeftCell:excel.formatCellAddress(t+1,n+1),activePane:t&&n?"bottomRight":t?"bottomLeft":"topRight",state:"frozen"};return [$(v({},r),{pane:o,selections:r.selections.map(s=>v({},s))}),...e.slice(1).map(s=>$(v({},s),{pane:s.pane?v({},s.pane):void 0,selections:s.selections.map(a=>v({},a))}))]}async function rS(e,t,n,r,o,i){for(let s=0;s<i.length;s++){let a=i[s];if(a)for(let l=0;l<o;l++)await e.setRangeStyleId(t,excel.formatCellAddress(n+s,r+l),a[l]);}}async function oS(e,t,n,r,o){for(let i of o)await e.mergeRange(t,excel.formatRangeAddress(n+i.startRowOffset,r+i.startColumnOffset,i.rowCount,i.columnCount));}function iS(e){switch(e){case "values":return "Paste values";case "formats":return "Paste formats";default:return "Paste range"}}function wf(e){return JSON.parse(JSON.stringify(e))}function aS(e){var r,o,i,s,a,l;let t={total:0,added:0,modified:0,deleted:0},n=[];for(let c of e.sheets)for(let u of c.cells)t.total+=1,t[u.kind]+=1,!(n.length>=20)&&n.push({sheetName:(o=(r=c.afterName)!=null?r:c.beforeName)!=null?o:c.sheetId,address:u.address,kind:u.kind,before:(s=(i=u.before)==null?void 0:i.value)!=null?s:null,after:(l=(a=u.after)==null?void 0:a.value)!=null?l:null});return {changed:e.changed,changedSheets:e.sheets.length,sheetNames:e.sheets.map(c=>{var u,f;return (f=(u=c.afterName)!=null?u:c.beforeName)!=null?f:c.sheetId}),cellChanges:t,structuralChanged:e.sheets.some(c=>c.structuralChanged),objectChanged:e.sheets.some(c=>c.objectChanged),sampleCells:n}}function sS(e,t){return !(e.endRow<t.startRow||e.startRow>t.endRow||e.endColumn<t.startColumn||e.startColumn>t.endColumn)}function lS(e){let t=excel.parseRangeAddress(e);return excel.formatCellAddress(t.startRow,t.startColumn)}async function sN(e,t,n={}){return {action:t,context:n,transaction:await e.previewAgentTransaction(xf(t),r=>t.run(r,n))}}async function lN(e,t,n={}){return {action:t,context:n,transaction:await e.runAgentTransaction(xf(t),r=>t.run(r,n))}}function xf(e){var t;return {label:e.label,actor:e.actor,description:e.description,agentRunId:e.agentRunId,agentStepId:e.agentStepId,agentActionId:(t=e.agentActionId)!=null?t:e.id,metadata:e.metadata}}var Ri=class{constructor(t){O(this,"options",t);this.options.textarea.addEventListener("keydown",n=>{n.key==="Escape"?(n.preventDefault(),this.cancel()):n.key==="Enter"&&!n.shiftKey&&(n.preventDefault(),this.commit());});}open(t,n){let r=this.options.textarea;r.value=n,r.style.display="block",r.style.position="absolute",r.style.left=`${t.x}px`,r.style.top=`${t.y}px`,r.style.width=`${Math.max(1,t.width)}px`,r.style.height=`${Math.max(1,t.height)}px`,r.focus(),r.select();}async commit(){let t=this.options.textarea.value;this.close(),await this.options.onCommit(t);}cancel(){var t,n;this.close(),(n=(t=this.options).onCancel)==null||n.call(t);}close(){this.options.textarea.style.display="none";}};function vf(e,t,n){return {x:Math.max(0,e.x+t),y:Math.max(0,e.y+n)}}function Sf(e,t,n,r,o=12){let i=e.getColumnX(n.frozenColumns+1),s=e.getRowY(n.frozenRows+1),a=Math.max(0,t.width-e.rowHeaderWidth-i-o),l=Math.max(0,t.height-e.columnHeaderHeight-s-o),c=a,u=l,f=Math.max(0,e.totalWidth()-i),p=Math.max(0,e.totalHeight()-s);return {horizontal:yf(f,c,a,r.x),vertical:yf(p,u,l,r.y)}}function Ai(e,t){if(e.maxScroll<=0)return 0;let n=Math.max(0,e.trackLength-e.thumbLength);return n<=0?0:Math.max(0,Math.min(n,t))/n*e.maxScroll}function yf(e,t,n,r){let o=Math.max(0,e-t);if(n<=0||e<=0||o<=0)return {trackLength:n,thumbStart:0,thumbLength:n,maxScroll:0};let i=Math.max(24,Math.min(n,t/e*n)),s=Math.max(0,n-i),a=o<=0?0:Math.max(0,Math.min(o,r))/o*s;return {trackLength:n,thumbStart:a,thumbLength:i,maxScroll:o}}var fN=24,mN=12,hN=4;function ol(e,t,n){for(let r of t){if(r.kind==="columnHeaderFrozen"||r.kind==="columnHeaderScrollable"){let o=dS(e,r,n);if(o)return o}if(r.kind==="rowHeaderFrozen"||r.kind==="rowHeaderScrollable"){let o=cS(e,r,n);if(o)return o}}return null}function kf(e,t){return $(v({},e),{startClientX:t.clientX,startClientY:t.clientY,currentSize:e.startSize,currentGuidePosition:e.guidePosition})}function il(e,t){let n=e.kind==="column"?t.clientX-e.startClientX:t.clientY-e.startClientY,r=Math.max(e.minSize,Math.round(e.startSize+n));return $(v({},e),{currentSize:r,currentGuidePosition:e.guidePosition+r-e.startSize})}function dS(e,t,n){if(!Ef(t.screenRect,n,4))return null;for(let r=t.columns.start;r<=t.columns.end;r++){let o=e.getCellLogicalRect(1,r),s=t.screenRect.x+o.x-t.originX+o.width;if(Math.abs(n.x-s)<=4)return {kind:"column",index:r,startSize:e.getColumnWidth(r),guidePosition:s,minSize:24}}return null}function cS(e,t,n){if(!Ef(t.screenRect,n,4))return null;for(let r=t.rows.start;r<=t.rows.end;r++){let o=e.getCellLogicalRect(r,1),s=t.screenRect.y+o.y-t.originY+o.height;if(Math.abs(n.y-s)<=4)return {kind:"row",index:r,startSize:e.getRowHeight(r),guidePosition:s,minSize:12}}return null}function Ef(e,t,n=0){return t.x>=e.x-n&&t.y>=e.y-n&&t.x<=e.x+e.width+n&&t.y<=e.y+e.height+n}function yN(e,t){var o,i,s,a,l,c;let n=uS(),r=We(t.range);for(let u=r.startRow;u<=r.endRow;u++)for(let f=r.startColumn;f<=r.endColumn;f++){let p=pS(e,u,f),w=(i=e.styles.fonts[(o=p.fontId)!=null?o:0])!=null?i:{},b=(a=e.styles.fills[(s=p.fillId)!=null?s:0])!=null?a:{},g=(c=e.styles.borders[(l=p.borderId)!=null?l:0])!=null?c:{};rn(n.bold,w.bold===true),rn(n.italic,w.italic===true),rn(n.underline,w.underline===true),rn(n.fontColor,w.color),rn(n.fillColor,b.foregroundColor),rn(n.numberFormatCode,p.numberFormatCode),rn(n.horizontal,fS(p)),rn(n.vertical,mS(p)),rn(n.border,g);}return {font:{bold:on(n.bold),italic:on(n.italic),underline:on(n.underline),color:on(n.fontColor)},fill:{foregroundColor:on(n.fillColor)},numberFormatCode:on(n.numberFormatCode),alignment:{horizontal:on(n.horizontal),vertical:on(n.vertical)},border:on(n.border)}}function uS(){return {bold:nn(),italic:nn(),underline:nn(),fontColor:nn(),fillColor:nn(),numberFormatCode:nn(),horizontal:nn(),vertical:nn(),border:nn()}}function nn(){return {hasValue:false,value:void 0,mixed:false}}function rn(e,t){if(!e.hasValue){e.hasValue=true,e.value=t;return}hS(e.value,t)||(e.mixed=true);}function on(e){return e.mixed?"mixed":e.value}function pS(e,t,n){var o,i;let r=qe(e,t,n);return (i=e.styles.cellFormats[(o=r==null?void 0:r.styleId)!=null?o:0])!=null?i:{}}function fS(e){var t,n;return ((t=e.alignment)==null?void 0:t.horizontal)==="center"||((n=e.alignment)==null?void 0:n.horizontal)==="right"?e.alignment.horizontal:"left"}function mS(e){var t,n;return ((t=e.alignment)==null?void 0:t.vertical)==="top"||((n=e.alignment)==null?void 0:n.vertical)==="center"?e.alignment.vertical:"bottom"}function hS(e,t){return JSON.stringify(e!=null?e:null)===JSON.stringify(t!=null?t:null)}async function HN(e,t,n={}){let r=new sl(e,n);return await r.loadWorkbook(t),r}var sl=class{constructor(t,n){O(this,"host",t);O(this,"options",n);O(this,"renderRoot");O(this,"runtimeValue",null);O(this,"renderer",null);O(this,"layout",null);O(this,"viewport",null);O(this,"scroll",{x:0,y:0});O(this,"scrollbarState",null);O(this,"listeners",new Set);O(this,"stateListeners",new Set);O(this,"baseCanvas",document.createElement("canvas"));O(this,"headerCanvas",document.createElement("canvas"));O(this,"overlayCanvas",document.createElement("canvas"));O(this,"unsupportedObjectLayer",document.createElement("div"));O(this,"sheetTabs",document.createElement("div"));O(this,"horizontalScrollbar",document.createElement("div"));O(this,"verticalScrollbar",document.createElement("div"));O(this,"horizontalThumb",document.createElement("div"));O(this,"verticalThumb",document.createElement("div"));O(this,"cellEditorElement",document.createElement("textarea"));O(this,"resizeGuide",document.createElement("div"));O(this,"contextMenu",document.createElement("div"));O(this,"filterMenu",document.createElement("div"));O(this,"cellEditor");O(this,"resizeObserver");O(this,"disposed",false);O(this,"drag",null);O(this,"selectionState",gt(1,1));O(this,"editingCell",null);O(this,"editingCellStyle",null);O(this,"clipboardPayload",null);O(this,"selecting",false);O(this,"resizeDrag",null);O(this,"autoFillDrag",null);O(this,"selectedChartIndex",null);O(this,"chartDrag",null);O(this,"columnFilters",new Map);O(this,"filterMenuColumn",null);O(this,"copiedRange",null);O(this,"formulaReferenceRanges",[]);O(this,"lastStateKey","");O(this,"transactionDepth",0);O(this,"transactionChanged",false);O(this,"readOnlyValue");O(this,"handleClick",t=>{if(this.eventPathContains(t,this.contextMenu)||this.eventPathContains(t,this.filterMenu))return;if(this.filterMenu.style.display==="block"&&this.hideFilterMenu(),this.editingCell){if(this.eventPathContains(t,this.cellEditorElement))return;this.cellEditor.cancel();}if(!this.viewport||!this.layout)return;let n=this.chartAtPoint(this.eventPoint(t));if(n){this.selectedChartIndex=n.chartIndex,this.render(),t.preventDefault();return}this.selectedChartIndex=null;let r=this.viewport.hitTest(this.eventPoint(t));if(!(r.kind!=="cell"&&r.kind!=="rowHeader"&&r.kind!=="columnHeader")){if(r.kind==="cell"&&r.row===1&&this.isFilterIconHit(r.column,t)){if(this.isReadOnly())return;this.openFilterMenu(r.column,t.clientX,t.clientY),t.preventDefault();return}if(r.kind==="cell"){let o=this.runtime().activeSheet();this.selectionState=Kt(gt(r.row,r.column),o);}this.host.focus(),this.render();}});O(this,"handleFilterMenuClick",t=>{var i;if(this.isReadOnly()){this.hideFilterMenu();return}let r=(i=t.target.closest("[data-filter-action]"))==null?void 0:i.dataset.filterAction;if(!r||this.filterMenuColumn===null)return;if(r==="cancel"){this.hideFilterMenu();return}let o=this.filterMenuColumn;if(r==="clear")this.columnFilters.delete(o);else if(r==="apply"){let s=Array.from(this.filterMenu.querySelectorAll("input[data-filter-value]:checked")).map(a=>{var l;return (l=a.dataset.filterValue)!=null?l:""});this.columnFilters.set(o,s);}this.hideFilterMenu(),this.applyColumnFilters();});O(this,"handleDoubleClick",t=>{if(!this.viewport||!this.layout)return;let n=this.viewport.hitTest(this.eventPoint(t));if(n.kind==="cell"){if(this.selectionState=Kt(gt(n.row,n.column),this.runtime().activeSheet()),this.isReadOnly()){this.render();return}this.openCellEditor(),t.preventDefault();}});O(this,"handlePointerDown",t=>{var c;if(this.editingCell){if(this.eventPathContains(t,this.cellEditorElement))return;this.cellEditor.cancel();}if(t.button!==0||!this.viewport||!this.layout)return;let n=this.eventPoint(t),r=this.chartAtPoint(n);if(r){if(this.selectedChartIndex=r.chartIndex,this.isReadOnly()){this.render(),t.preventDefault();return}this.chartDrag={chartIndex:r.chartIndex,pointer:n,startRect:r.logicalRect,previewRect:r.logicalRect},this.host.setPointerCapture(t.pointerId),this.render(),t.preventDefault();return}this.selectedChartIndex=null;let o=ol(this.layout,this.viewport.viewports,n);if(o&&!this.isReadOnly()){this.resizeDrag=kf(o,t),this.host.setPointerCapture(t.pointerId),this.host.style.cursor=o.kind==="column"?"col-resize":"row-resize",this.updateResizeGuide(this.resizeDrag),t.preventDefault();return}let i=We(this.selectionState.range),s=(c=this.renderer)==null?void 0:c.fillHandleRect(this.layout,this.viewport,i);if(!this.isReadOnly()&&s&&Cf(s,n)&&el(this.runtime().activeSheet(),i)){this.autoFillDrag={source:i,preview:null},this.host.setPointerCapture(t.pointerId),t.preventDefault();return}let a=this.viewport.hitTest(n);if(a.kind!=="cell"&&a.kind!=="rowHeader"&&a.kind!=="columnHeader")return;let l=this.runtime().activeSheet();a.kind==="cell"?this.selectionState=Kt(gt(a.row,a.column),l):a.kind==="rowHeader"?this.selectionState=qs(a.row,{columnCount:this.layout.columnCount}):this.selectionState=Xs(a.column,{rowCount:this.layout.rowCount}),this.selecting=true,this.host.setPointerCapture(t.pointerId),this.render(),t.preventDefault();});O(this,"handlePointerMove",t=>{if(!this.viewport||!this.layout)return;if(this.chartDrag){let o=this.eventPoint(t),i=o.x-this.chartDrag.pointer.x,s=o.y-this.chartDrag.pointer.y;this.chartDrag.previewRect=$(v({},this.chartDrag.startRect),{x:Math.max(0,this.chartDrag.startRect.x+i),y:Math.max(0,this.chartDrag.startRect.y+s)}),this.host.style.cursor="grabbing",this.render(),t.preventDefault();return}if(!this.resizeDrag&&!this.autoFillDrag&&!this.selecting&&!this.editingCell){let o=this.isReadOnly()?null:ol(this.layout,this.viewport.viewports,this.eventPoint(t));this.host.style.cursor=o?o.kind==="column"?"col-resize":"row-resize":"";}if(this.resizeDrag){this.resizeDrag=il(this.resizeDrag,t),this.updateResizeGuide(this.resizeDrag);return}if(this.autoFillDrag){let o=this.viewport.hitTest(this.eventPoint(t));this.autoFillDrag.preview=vS(this.autoFillDrag.source,o),this.render(),t.preventDefault();return}if(!this.selecting)return;let n=this.viewport.hitTest(this.eventPoint(t));if(n.kind==="none"||n.kind==="corner")return;let r=this.runtime().activeSheet();n.kind==="cell"?this.selectionState=Kt(Pi(this.selectionState,n.row,n.column,{rowCount:this.layout.rowCount,columnCount:this.layout.columnCount}),r):n.kind==="rowHeader"&&this.selectionState.kind==="row"?this.selectionState=Pi(this.selectionState,n.row,1,{columnCount:this.layout.columnCount,rowCount:this.layout.rowCount}):n.kind==="columnHeader"&&this.selectionState.kind==="column"&&(this.selectionState=Pi(this.selectionState,1,n.column,{columnCount:this.layout.columnCount,rowCount:this.layout.rowCount})),this.render(),t.preventDefault();});O(this,"handlePointerUp",t=>{if(this.chartDrag){let n=this.chartDrag;if(this.chartDrag=null,this.host.style.cursor="",this.host.hasPointerCapture(t.pointerId)&&this.host.releasePointerCapture(t.pointerId),n.previewRect.x===n.startRect.x&&n.previewRect.y===n.startRect.y){this.render(),t.preventDefault();return}let r=this.chartAnchorAtIndex(n.chartIndex);if(r&&this.layout){let o=wS(this.layout,n.previewRect,r);this.runtime().moveChart(n.chartIndex,o).then(async()=>{this.render(),await this.emitChange();});}else this.render();t.preventDefault();return}if(this.resizeDrag){let n=il(this.resizeDrag,t);this.resizeDrag=null,this.host.style.cursor="",this.hideResizeGuide(),this.host.hasPointerCapture(t.pointerId)&&this.host.releasePointerCapture(t.pointerId),this.commitResizeDrag(n),t.preventDefault();return}if(this.autoFillDrag){let n=this.autoFillDrag;this.autoFillDrag=null,this.host.hasPointerCapture(t.pointerId)&&this.host.releasePointerCapture(t.pointerId),n.preview?this.runtime().autoFillRange(n.source,n.preview).then(async()=>{this.selectionState=$(v({},this.selectionState),{range:n.preview}),this.render(),await this.emitChange();}):this.render(),t.preventDefault();return}this.selecting&&(this.selecting=false,this.host.hasPointerCapture(t.pointerId)&&this.host.releasePointerCapture(t.pointerId),this.host.style.cursor="");});O(this,"handlePointerLeave",()=>{!this.resizeDrag&&!this.autoFillDrag&&!this.chartDrag&&(this.host.style.cursor="");});O(this,"handleKeyDown",t=>{if(this.editingCell)return;let{row:n,column:r}=this.selectionState.active;if(t.key==="F2"||t.key==="Enter"){if(this.isReadOnly())return;t.preventDefault(),this.openCellEditor();return}let i={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1]}[t.key];if(!i)return;let s=this.runtime().activeSheet();this.selectionState=gt(Math.max(1,Math.min(s.maxRow,n+i[0])),Math.max(1,Math.min(s.maxColumn,r+i[1]))),t.preventDefault(),this.render();});O(this,"handleCopy",t=>{var o;let n=We(this.selectionState.range),r=Ys(this.runtime().activeSheet(),n);this.clipboardPayload=r,this.copiedRange=n,(o=t.clipboardData)==null||o.setData("text/plain",r.text),t.preventDefault();});O(this,"handlePaste",t=>{var o,i,s,a,l;if(this.isReadOnly()){t.preventDefault();return}let n=(i=(o=t.clipboardData)==null?void 0:o.getData("text/plain"))!=null?i:"";if(!n)return;t.preventDefault();let r=((s=this.clipboardPayload)==null?void 0:s.text)===n?this.clipboardPayload.values:Zs(n);this.runtime().pasteRange(this.selectionState.active.row,this.selectionState.active.column,r,{mode:"all",merges:((a=this.clipboardPayload)==null?void 0:a.text)===n?this.clipboardPayload.merges:[],styleIds:((l=this.clipboardPayload)==null?void 0:l.text)===n?this.clipboardPayload.styleIds:[]}).then(async()=>{let c=Kt({kind:"cell",active:this.selectionState.active,range:{startRow:this.selectionState.active.row,startColumn:this.selectionState.active.column,endRow:this.selectionState.active.row+r.length-1,endColumn:this.selectionState.active.column+Math.max(1,r.reduce((u,f)=>Math.max(u,f.length),0))-1}},this.runtime().activeSheet());this.selectionState=c,this.copiedRange=We(c.range),this.render(),await this.emitChange();});});O(this,"handleContextMenu",t=>{if(!this.viewport||!this.layout)return;let n=this.chartAtPoint(this.eventPoint(t));if(n){this.selectedChartIndex=n.chartIndex,this.hideContextMenu(),this.hideFilterMenu(),this.render(),t.preventDefault();return}let r=this.viewport.hitTest(this.eventPoint(t));r.kind==="cell"&&!this.selectionContainsCell(r.row,r.column)&&(this.selectionState=Kt(gt(r.row,r.column),this.runtime().activeSheet()),this.render()),!(r.kind!=="cell"&&r.kind!=="rowHeader"&&r.kind!=="columnHeader")&&(t.preventDefault(),this.renderContextMenu(t.clientX,t.clientY,this.isReadOnly()?void 0:r.kind==="columnHeader"?r.column:void 0));});O(this,"handleDocumentPointerDown",t=>{let n=t.composedPath();n.includes(this.contextMenu)||n.includes(this.filterMenu)||(this.hideContextMenu(),this.hideFilterMenu());});O(this,"handleWheel",t=>{if(!this.runtimeValue)return;t.preventDefault();let n=vf(this.scroll,t.deltaX,t.deltaY);this.setScroll(n.x,n.y);});var r;if(this.readOnlyValue=n.readOnly===true,t.replaceChildren(),this.renderRoot=n.styleIsolation==="none"?t:(r=t.shadowRoot)!=null?r:t.attachShadow({mode:"open"}),this.renderRoot.replaceChildren(),this.renderRoot instanceof ShadowRoot){let o=document.createElement("style");o.textContent=`
1608
+ `,{sheetName:this.state.activeSheetName,rowMap:[...a.entries()],formulas:l});});});}async setRangeValues(t,n,r){let o=r.length,i=r.reduce((a,l)=>Math.max(a,l.length),0),s=r.map(a=>{let l=a.slice();for(;l.length<i;)l.push(null);return l});await this.runUserMutation({label:"Set range values"},async a=>{await a.setRangeValues(this.state.activeSheetName,excel.formatRangeAddress(t,n,o,i),s);});}async autoFillRange(t,n){let r=lf(this.state.activeSheet,t,n);r.cells.length!==0&&await this.runUserMutation({label:"Auto fill"},async o=>{for(let i of r.cells){let s=excel.formatCellAddress(i.row,i.column);i.formula?await o.setCellFormula(this.state.activeSheetName,s,i.formula):await o.setCellValue(this.state.activeSheetName,s,i.value),await o.setRangeStyleId(this.state.activeSheetName,s,i.styleId);}});}async pasteRangeValues(t,n,r,o=[],i=[]){await this.pasteRange(t,n,r,{mode:"all",merges:o,styleIds:i});}async pasteRange(t,n,r,o={}){var w;let i=(w=o.mode)!=null?w:"all",s=r.length,a=r.reduce((b,g)=>Math.max(b,g.length),0),l=r.map(b=>{let g=b.slice();for(;g.length<a;)g.push(null);return g}),c=Math.max(1,s),u=Math.max(1,a),f={startRow:t,startColumn:n,endRow:t+c-1,endColumn:n+u-1},p=[...this.state.activeSheet.mergeMasterByAddress.values()].filter(b=>bS(f,b.range)).map(b=>b.address);await this.runUserMutation({label:hS(i)},async b=>{var g,h;if(i!=="formats"){for(let y of p)await b.unmergeRange(this.state.activeSheetName,y);await b.setRangeValues(this.state.activeSheetName,excel.formatRangeAddress(t,n,c,u),l);}i!=="values"&&await fS(b,this.state.activeSheetName,t,n,u,(g=o.styleIds)!=null?g:[]),i==="all"&&await mS(b,this.state.activeSheetName,t,n,(h=o.merges)!=null?h:[]);});}async clearRange(t,n,r,o){await this.runUserMutation({label:"Clear range"},async i=>{await i.clearRange(this.state.activeSheetName,excel.formatRangeAddress(t,n,r,o));});}async setRowHeight(t,n){await this.runUserMutation({label:"Set row height"},async r=>{await r.setRowHeight(this.state.activeSheetName,t,n);});}async setColumnWidth(t,n){await this.runUserMutation({label:"Set column width"},async r=>{await r.setColumnWidth(this.state.activeSheetName,t,Ei(n));});}async setFreezePanes(t,n){let r=vf(t),o=vf(n),i=pS(this.state.activeSheet.source.sheetViews,r,o);await this.runUserMutation({label:r||o?"Freeze panes":"Unfreeze panes"},async s=>{await s.setSheetViews(this.state.activeSheetName,i);});}async insertRows(t,n=1){await this.runUserMutation({label:"Insert rows"},async r=>{await r.insertRows(this.state.activeSheetName,t,n);});}async deleteRows(t,n=1){await this.runUserMutation({label:"Delete rows"},async r=>{await r.deleteRows(this.state.activeSheetName,t,n);});}async insertColumns(t,n=1){await this.runUserMutation({label:"Insert columns"},async r=>{await r.insertColumns(this.state.activeSheetName,t,n);});}async deleteColumns(t,n=1){await this.runUserMutation({label:"Delete columns"},async r=>{await r.deleteColumns(this.state.activeSheetName,t,n);});}async setRangeBold(t,n,r,o,i){await this.runUserMutation({label:"Set bold"},async s=>{await s.setRangeBold(this.state.activeSheetName,excel.formatRangeAddress(t,n,r,o),i);});}async setRangeItalic(t,n,r,o,i){await this.runUserMutation({label:"Set italic"},async s=>{await s.setRangeItalic(this.state.activeSheetName,excel.formatRangeAddress(t,n,r,o),i);});}async setRangeUnderline(t,n,r,o,i){await this.runUserMutation({label:"Set underline"},async s=>{await s.setRangeUnderline(this.state.activeSheetName,excel.formatRangeAddress(t,n,r,o),i);});}async setRangeFontColor(t,n,r,o,i){await this.runUserMutation({label:"Set font color"},async s=>{await s.setRangeFontColor(this.state.activeSheetName,excel.formatRangeAddress(t,n,r,o),i);});}async setRangeFillColor(t,n,r,o,i){await this.runUserMutation({label:"Set fill color"},async s=>{await s.setRangeFillColor(this.state.activeSheetName,excel.formatRangeAddress(t,n,r,o),i);});}async setRangeHorizontalAlign(t,n,r,o,i){await this.runUserMutation({label:"Set horizontal align"},async s=>{await s.setRangeHorizontalAlign(this.state.activeSheetName,excel.formatRangeAddress(t,n,r,o),i);});}async setRangeVerticalAlign(t,n,r,o,i){await this.runUserMutation({label:"Set vertical align"},async s=>{await s.setRangeVerticalAlign(this.state.activeSheetName,excel.formatRangeAddress(t,n,r,o),i);});}async setRangeNumberFormat(t,n,r,o,i){await this.runUserMutation({label:"Set number format"},async s=>{await s.setRangeNumberFormat(this.state.activeSheetName,excel.formatRangeAddress(t,n,r,o),i);});}async clearRangeFormat(t,n,r,o){await this.runUserMutation({label:"Clear format"},async i=>{await i.clearRangeFormat(this.state.activeSheetName,excel.formatRangeAddress(t,n,r,o));});}async mergeRange(t,n,r,o){let i=excel.formatRangeAddress(t,n,r,o),s=await this.cellStyleId(excel.formatCellAddress(t,n));await this.runUserMutation({label:"Merge range"},async a=>{await a.setRangeStyleId(this.state.activeSheetName,i,s),await a.mergeRange(this.state.activeSheetName,i);});}async unmergeRanges(t){if(t.length===0)return;let n=t.map(r=>{let o=[...this.state.activeSheet.mergeMasterByAddress.values()].find(s=>s.address===r),i=o?excel.formatCellAddress(o.range.startRow,o.range.startColumn):wS(r);return {address:r,masterAddress:i}});await this.runUserMutation({label:"Unmerge ranges"},async r=>{for(let o of n)await r.setRangeStyleId(this.state.activeSheetName,o.address,await this.cellStyleId(o.masterAddress)),await r.unmergeRange(this.state.activeSheetName,o.address);});}async setRangeBorder(t,n,r,o,i){if(i==="clear"){await this.runUserMutation({label:"Clear border"},async a=>{await a.setRangeBorder(this.state.activeSheetName,excel.formatRangeAddress(t,n,r,o),{});});return}let s=uS();if(i==="all"){await this.runUserMutation({label:"Set all borders"},async a=>{await a.setRangeBorder(this.state.activeSheetName,excel.formatRangeAddress(t,n,r,o),{left:s,right:s,top:s,bottom:s});});return}await this.runUserMutation({label:`Set ${i} borders`},async a=>{await a.setRangeBorder(this.state.activeSheetName,excel.formatRangeAddress(t,n,r,o),{});for(let l=0;l<r;l++)for(let c=0;c<o;c++){let u={};i==="outer"?(l===0&&(u.top=s),l===r-1&&(u.bottom=s),c===0&&(u.left=s),c===o-1&&(u.right=s)):(c<o-1&&(u.right=s),l<r-1&&(u.bottom=s)),Object.keys(u).length!==0&&await a.setRangeBorder(this.state.activeSheetName,excel.formatCellAddress(t+l,n+c),u);}});}async toZip(){return this.state.workbook.toZip()}async moveChart(t,n){await this.runUserMutation({label:"Move chart"},async r=>{await r.runSnapshot("Move chart","spreadsheet chart position",async()=>{let o=this.state.model.sheets.find(p=>p.name===this.state.activeSheetName),i=o==null?void 0:o.charts[t];if(!o||!i)return;let s=o.drawings.findIndex(p=>p.path===i.drawingPath),a=s>=0?o.drawings[s]:o.drawings[0];if(!a)return;let l=a.anchors.findIndex(p=>{var w;return ((w=p.object)==null?void 0:w.kind)==="chart"&&(!i.relationshipId||p.object.relationshipId===i.relationshipId)});if(l<0)return;let u=(await this.state.workbook.worksheets.getItem(this.state.activeSheetName).drawings.items())[s>=0?s:0],f=u==null?void 0:u.anchors.getItem(l);f&&(f.from.setRow(n.from.row),f.from.setColumn(n.from.column),f.from.setRowOffset(n.from.rowOffset),f.from.setColumnOffset(n.from.columnOffset),n.to&&(f.to.setRow(n.to.row),f.to.setColumn(n.to.column),f.to.setRowOffset(n.to.rowOffset),f.to.setColumnOffset(n.to.columnOffset)));});});}async dispose(){await this.state.workbook.dispose();}editableCellAddress(t){var o;let n=excel.parseCellAddress(t),r=excel.formatCellAddress(n.row,n.column);return (o=this.state.activeSheet.mergeFollowerByAddress.get(r))!=null?o:r}rebuildActiveSheetRenderModel(){this.state.formulaResults=this.state.formulaEngine.calculate(),this.state.activeSheet=no(this.state.activeSheet.source,this.state.model.styles,{formulaResults:this.state.formulaResults,date1904:this.state.model.date1904});}async runUserMutation(t,n){if(this.assertWritable(),this.activeTransaction){await n(this.activeTransaction),this.transactionNeedsRefresh=true;return}await this.runScopedTransaction("user",r=>this.state.workbook.history().runGroup($(v({},t),{source:"user"}),r),async()=>{if(!this.activeTransaction)throw new Error("SpreadsheetEditorRuntime: transaction not active");await n(this.activeTransaction),this.transactionNeedsRefresh=true;});}async runWorksheetStructureMutation(t,n){if(this.assertWritable(),this.activeTransactionSource==="agent"&&this.activeTransaction){await t(this.activeTransaction),this.transactionNeedsRefresh=true,await this.refresh();return}await n(),await this.refresh();}async cellStyleId(t){var n;return (n=(await this.state.workbook.worksheets.getItem(this.state.activeSheetName).getRange(t).styleIds())[0])==null?void 0:n[0]}async runScopedTransaction(t,n,r){if(this.assertWritable(),this.activeTransaction)return await r(),this.transactionNeedsRefresh=true,null;let o=this.transactionNeedsRefresh;this.transactionNeedsRefresh=false;try{let i=await n(async a=>{this.activeTransaction=a,this.activeTransactionSource=t;try{await r();}finally{this.activeTransaction=null,this.activeTransactionSource=null;}});return (this.transactionNeedsRefresh||i!==null)&&await this.refresh(),i}finally{this.activeTransaction=null,this.activeTransactionSource=null,this.transactionNeedsRefresh=o;}}assertWritable(){if(this.readOnlyValue)throw new dn("spreadsheet")}cellEditHistoryGroup(t,n,r){var i;let o={label:t};return r.mergeUndo?$(v({},o),{mergeKey:`edit:${this.state.activeSheetName}!${n}`,mergeWindowMs:(i=r.mergeWindowMs)!=null?i:1e3}):o}range(t,n,r,o){return this.state.workbook.worksheets.getItem(this.state.activeSheetName).getRange(excel.formatRangeAddress(t,n,r,o))}};function uS(){return {style:"thin",color:{rgb:"#111827"}}}function vf(e){return Number.isFinite(e)?Math.max(0,Math.floor(e)):0}function pS(e,t,n){var i;if(!t&&!n)return e.map((s,a)=>$(v({},s),{pane:a===0?void 0:s.pane?v({},s.pane):void 0,selections:s.selections.map(l=>v({},l))}));let r=(i=e[0])!=null?i:{workbookViewId:0,selections:[]},o={xSplit:n||void 0,ySplit:t||void 0,topLeftCell:excel.formatCellAddress(t+1,n+1),activePane:t&&n?"bottomRight":t?"bottomLeft":"topRight",state:"frozen"};return [$(v({},r),{pane:o,selections:r.selections.map(s=>v({},s))}),...e.slice(1).map(s=>$(v({},s),{pane:s.pane?v({},s.pane):void 0,selections:s.selections.map(a=>v({},a))}))]}async function fS(e,t,n,r,o,i){for(let s=0;s<i.length;s++){let a=i[s];if(a)for(let l=0;l<o;l++)await e.setRangeStyleId(t,excel.formatCellAddress(n+s,r+l),a[l]);}}async function mS(e,t,n,r,o){for(let i of o)await e.mergeRange(t,excel.formatRangeAddress(n+i.startRowOffset,r+i.startColumnOffset,i.rowCount,i.columnCount));}function hS(e){switch(e){case "values":return "Paste values";case "formats":return "Paste formats";default:return "Paste range"}}function Sf(e){return JSON.parse(JSON.stringify(e))}function gS(e){var r,o,i,s,a,l;let t={total:0,added:0,modified:0,deleted:0},n=[];for(let c of e.sheets)for(let u of c.cells)t.total+=1,t[u.kind]+=1,!(n.length>=20)&&n.push({sheetName:(o=(r=c.afterName)!=null?r:c.beforeName)!=null?o:c.sheetId,address:u.address,kind:u.kind,before:(s=(i=u.before)==null?void 0:i.value)!=null?s:null,after:(l=(a=u.after)==null?void 0:a.value)!=null?l:null});return {changed:e.changed,changedSheets:e.sheets.length,sheetNames:e.sheets.map(c=>{var u,f;return (f=(u=c.afterName)!=null?u:c.beforeName)!=null?f:c.sheetId}),cellChanges:t,structuralChanged:e.sheets.some(c=>c.structuralChanged),objectChanged:e.sheets.some(c=>c.objectChanged),sampleCells:n}}function bS(e,t){return !(e.endRow<t.startRow||e.startRow>t.endRow||e.endColumn<t.startColumn||e.startColumn>t.endColumn)}function wS(e){let t=excel.parseRangeAddress(e);return excel.formatCellAddress(t.startRow,t.startColumn)}async function yN(e,t,n={}){return {action:t,context:n,transaction:await e.previewAgentTransaction(kf(t),r=>t.run(r,n))}}async function vN(e,t,n={}){return {action:t,context:n,transaction:await e.runAgentTransaction(kf(t),r=>t.run(r,n))}}function kf(e){var t;return {label:e.label,actor:e.actor,description:e.description,agentRunId:e.agentRunId,agentStepId:e.agentStepId,agentActionId:(t=e.agentActionId)!=null?t:e.id,metadata:e.metadata}}var Bi=class{constructor(t){O(this,"options",t);this.options.textarea.addEventListener("keydown",n=>{n.key==="Escape"?(n.preventDefault(),this.cancel()):n.key==="Enter"&&!n.shiftKey&&(n.preventDefault(),this.commit());});}open(t,n){let r=this.options.textarea;r.value=n,r.style.display="block",r.style.position="absolute",r.style.left=`${t.x}px`,r.style.top=`${t.y}px`,r.style.width=`${Math.max(1,t.width)}px`,r.style.height=`${Math.max(1,t.height)}px`,r.focus(),r.select();}async commit(){let t=this.options.textarea.value;this.close(),await this.options.onCommit(t);}cancel(){var t,n;this.close(),(n=(t=this.options).onCancel)==null||n.call(t);}close(){this.options.textarea.style.display="none";}};function Cf(e,t,n){return {x:Math.max(0,e.x+t),y:Math.max(0,e.y+n)}}function If(e,t,n,r,o=12){let i=e.getColumnX(n.frozenColumns+1),s=e.getRowY(n.frozenRows+1),a=Math.max(0,t.width-e.rowHeaderWidth-i-o),l=Math.max(0,t.height-e.columnHeaderHeight-s-o),c=a,u=l,f=Math.max(0,e.totalWidth()-i),p=Math.max(0,e.totalHeight()-s);return {horizontal:Ef(f,c,a,r.x),vertical:Ef(p,u,l,r.y)}}function Di(e,t){if(e.maxScroll<=0)return 0;let n=Math.max(0,e.trackLength-e.thumbLength);return n<=0?0:Math.max(0,Math.min(n,t))/n*e.maxScroll}function Ef(e,t,n,r){let o=Math.max(0,e-t);if(n<=0||e<=0||o<=0)return {trackLength:n,thumbStart:0,thumbLength:n,maxScroll:0};let i=Math.max(24,Math.min(n,t/e*n)),s=Math.max(0,n-i),a=o<=0?0:Math.max(0,Math.min(o,r))/o*s;return {trackLength:n,thumbStart:a,thumbLength:i,maxScroll:o}}var IN=24,NN=12,TN=4;function ll(e,t,n){for(let r of t){if(r.kind==="columnHeaderFrozen"||r.kind==="columnHeaderScrollable"){let o=xS(e,r,n);if(o)return o}if(r.kind==="rowHeaderFrozen"||r.kind==="rowHeaderScrollable"){let o=yS(e,r,n);if(o)return o}}return null}function Nf(e,t){return $(v({},e),{startClientX:t.clientX,startClientY:t.clientY,currentSize:e.startSize,currentGuidePosition:e.guidePosition})}function dl(e,t){let n=e.kind==="column"?t.clientX-e.startClientX:t.clientY-e.startClientY,r=Math.max(e.minSize,Math.round(e.startSize+n));return $(v({},e),{currentSize:r,currentGuidePosition:e.guidePosition+r-e.startSize})}function xS(e,t,n){if(!Tf(t.screenRect,n,4))return null;for(let r=t.columns.start;r<=t.columns.end;r++){let o=e.getCellLogicalRect(1,r),s=t.screenRect.x+o.x-t.originX+o.width;if(Math.abs(n.x-s)<=4)return {kind:"column",index:r,startSize:e.getColumnWidth(r),guidePosition:s,minSize:24}}return null}function yS(e,t,n){if(!Tf(t.screenRect,n,4))return null;for(let r=t.rows.start;r<=t.rows.end;r++){let o=e.getCellLogicalRect(r,1),s=t.screenRect.y+o.y-t.originY+o.height;if(Math.abs(n.y-s)<=4)return {kind:"row",index:r,startSize:e.getRowHeight(r),guidePosition:s,minSize:12}}return null}function Tf(e,t,n=0){return t.x>=e.x-n&&t.y>=e.y-n&&t.x<=e.x+e.width+n&&t.y<=e.y+e.height+n}function LN(e,t){var o,i,s,a,l,c;let n=vS(),r=We(t.range);for(let u=r.startRow;u<=r.endRow;u++)for(let f=r.startColumn;f<=r.endColumn;f++){let p=SS(e,u,f),w=(i=e.styles.fonts[(o=p.fontId)!=null?o:0])!=null?i:{},b=(a=e.styles.fills[(s=p.fillId)!=null?s:0])!=null?a:{},g=(c=e.styles.borders[(l=p.borderId)!=null?l:0])!=null?c:{};on(n.bold,w.bold===true),on(n.italic,w.italic===true),on(n.underline,w.underline===true),on(n.fontColor,w.color),on(n.fillColor,b.foregroundColor),on(n.numberFormatCode,p.numberFormatCode),on(n.horizontal,kS(p)),on(n.vertical,ES(p)),on(n.border,g);}return {font:{bold:an(n.bold),italic:an(n.italic),underline:an(n.underline),color:an(n.fontColor)},fill:{foregroundColor:an(n.fillColor)},numberFormatCode:an(n.numberFormatCode),alignment:{horizontal:an(n.horizontal),vertical:an(n.vertical)},border:an(n.border)}}function vS(){return {bold:rn(),italic:rn(),underline:rn(),fontColor:rn(),fillColor:rn(),numberFormatCode:rn(),horizontal:rn(),vertical:rn(),border:rn()}}function rn(){return {hasValue:false,value:void 0,mixed:false}}function on(e,t){if(!e.hasValue){e.hasValue=true,e.value=t;return}CS(e.value,t)||(e.mixed=true);}function an(e){return e.mixed?"mixed":e.value}function SS(e,t,n){var o,i;let r=qe(e,t,n);return (i=e.styles.cellFormats[(o=r==null?void 0:r.styleId)!=null?o:0])!=null?i:{}}function kS(e){var t,n;return ((t=e.alignment)==null?void 0:t.horizontal)==="center"||((n=e.alignment)==null?void 0:n.horizontal)==="right"?e.alignment.horizontal:"left"}function ES(e){var t,n;return ((t=e.alignment)==null?void 0:t.vertical)==="top"||((n=e.alignment)==null?void 0:n.vertical)==="center"?e.alignment.vertical:"bottom"}function CS(e,t){return JSON.stringify(e!=null?e:null)===JSON.stringify(t!=null?t:null)}async function ZN(e,t,n={}){let r=new ul(e,n);return await r.loadWorkbook(t),r}var ul=class{constructor(t,n){O(this,"host",t);O(this,"options",n);O(this,"renderRoot");O(this,"runtimeValue",null);O(this,"renderer",null);O(this,"layout",null);O(this,"viewport",null);O(this,"scroll",{x:0,y:0});O(this,"scrollbarState",null);O(this,"listeners",new Set);O(this,"stateListeners",new Set);O(this,"baseCanvas",document.createElement("canvas"));O(this,"headerCanvas",document.createElement("canvas"));O(this,"overlayCanvas",document.createElement("canvas"));O(this,"unsupportedObjectLayer",document.createElement("div"));O(this,"sheetTabs",document.createElement("div"));O(this,"horizontalScrollbar",document.createElement("div"));O(this,"verticalScrollbar",document.createElement("div"));O(this,"horizontalThumb",document.createElement("div"));O(this,"verticalThumb",document.createElement("div"));O(this,"cellEditorElement",document.createElement("textarea"));O(this,"resizeGuide",document.createElement("div"));O(this,"contextMenu",document.createElement("div"));O(this,"filterMenu",document.createElement("div"));O(this,"cellEditor");O(this,"resizeObserver");O(this,"disposed",false);O(this,"drag",null);O(this,"selectionState",gt(1,1));O(this,"editingCell",null);O(this,"editingCellStyle",null);O(this,"clipboardPayload",null);O(this,"selecting",false);O(this,"resizeDrag",null);O(this,"autoFillDrag",null);O(this,"selectedChartIndex",null);O(this,"chartDrag",null);O(this,"columnFilters",new Map);O(this,"filterMenuColumn",null);O(this,"copiedRange",null);O(this,"formulaReferenceRanges",[]);O(this,"lastStateKey","");O(this,"transactionDepth",0);O(this,"transactionChanged",false);O(this,"readOnlyValue");O(this,"handleClick",t=>{if(this.eventPathContains(t,this.contextMenu)||this.eventPathContains(t,this.filterMenu))return;if(this.filterMenu.style.display==="block"&&this.hideFilterMenu(),this.editingCell){if(this.eventPathContains(t,this.cellEditorElement))return;this.cellEditor.cancel();}if(!this.viewport||!this.layout)return;let n=this.chartAtPoint(this.eventPoint(t));if(n){this.selectedChartIndex=n.chartIndex,this.render(),t.preventDefault();return}this.selectedChartIndex=null;let r=this.viewport.hitTest(this.eventPoint(t));if(!(r.kind!=="cell"&&r.kind!=="rowHeader"&&r.kind!=="columnHeader")){if(r.kind==="cell"&&r.row===1&&this.isFilterIconHit(r.column,t)){if(this.isReadOnly())return;this.openFilterMenu(r.column,t.clientX,t.clientY),t.preventDefault();return}if(r.kind==="cell"){let o=this.runtime().activeSheet();this.selectionState=_t(gt(r.row,r.column),o);}this.host.focus(),this.render();}});O(this,"handleFilterMenuClick",t=>{var i;if(this.isReadOnly()){this.hideFilterMenu();return}let r=(i=t.target.closest("[data-filter-action]"))==null?void 0:i.dataset.filterAction;if(!r||this.filterMenuColumn===null)return;if(r==="cancel"){this.hideFilterMenu();return}let o=this.filterMenuColumn;if(r==="clear")this.columnFilters.delete(o);else if(r==="apply"){let s=Array.from(this.filterMenu.querySelectorAll("input[data-filter-value]:checked")).map(a=>{var l;return (l=a.dataset.filterValue)!=null?l:""});this.columnFilters.set(o,s);}this.hideFilterMenu(),this.applyColumnFilters();});O(this,"handleDoubleClick",t=>{if(!this.viewport||!this.layout)return;let n=this.viewport.hitTest(this.eventPoint(t));if(n.kind==="cell"){if(this.selectionState=_t(gt(n.row,n.column),this.runtime().activeSheet()),this.isReadOnly()){this.render();return}this.openCellEditor(),t.preventDefault();}});O(this,"handlePointerDown",t=>{var c;if(this.editingCell){if(this.eventPathContains(t,this.cellEditorElement))return;this.cellEditor.cancel();}if(t.button!==0||!this.viewport||!this.layout)return;let n=this.eventPoint(t),r=this.chartAtPoint(n);if(r){if(this.selectedChartIndex=r.chartIndex,this.isReadOnly()){this.render(),t.preventDefault();return}this.chartDrag={chartIndex:r.chartIndex,pointer:n,startRect:r.logicalRect,previewRect:r.logicalRect},this.host.setPointerCapture(t.pointerId),this.render(),t.preventDefault();return}this.selectedChartIndex=null;let o=ll(this.layout,this.viewport.viewports,n);if(o&&!this.isReadOnly()){this.resizeDrag=Nf(o,t),this.host.setPointerCapture(t.pointerId),this.host.style.cursor=o.kind==="column"?"col-resize":"row-resize",this.updateResizeGuide(this.resizeDrag),t.preventDefault();return}let i=We(this.selectionState.range),s=(c=this.renderer)==null?void 0:c.fillHandleRect(this.layout,this.viewport,i);if(!this.isReadOnly()&&s&&Pf(s,n)&&ol(this.runtime().activeSheet(),i)){this.autoFillDrag={source:i,preview:null},this.host.setPointerCapture(t.pointerId),t.preventDefault();return}let a=this.viewport.hitTest(n);if(a.kind!=="cell"&&a.kind!=="rowHeader"&&a.kind!=="columnHeader")return;let l=this.runtime().activeSheet();a.kind==="cell"?this.selectionState=_t(gt(a.row,a.column),l):a.kind==="rowHeader"?this.selectionState=Js(a.row,{columnCount:this.layout.columnCount}):this.selectionState=Qs(a.column,{rowCount:this.layout.rowCount}),this.selecting=true,this.host.setPointerCapture(t.pointerId),this.render(),t.preventDefault();});O(this,"handlePointerMove",t=>{if(!this.viewport||!this.layout)return;if(this.chartDrag){let o=this.eventPoint(t),i=o.x-this.chartDrag.pointer.x,s=o.y-this.chartDrag.pointer.y;this.chartDrag.previewRect=$(v({},this.chartDrag.startRect),{x:Math.max(0,this.chartDrag.startRect.x+i),y:Math.max(0,this.chartDrag.startRect.y+s)}),this.host.style.cursor="grabbing",this.render(),t.preventDefault();return}if(!this.resizeDrag&&!this.autoFillDrag&&!this.selecting&&!this.editingCell){let o=this.isReadOnly()?null:ll(this.layout,this.viewport.viewports,this.eventPoint(t));this.host.style.cursor=o?o.kind==="column"?"col-resize":"row-resize":"";}if(this.resizeDrag){this.resizeDrag=dl(this.resizeDrag,t),this.updateResizeGuide(this.resizeDrag);return}if(this.autoFillDrag){let o=this.viewport.hitTest(this.eventPoint(t));this.autoFillDrag.preview=RS(this.autoFillDrag.source,o),this.render(),t.preventDefault();return}if(!this.selecting)return;let n=this.viewport.hitTest(this.eventPoint(t));if(n.kind==="none"||n.kind==="corner")return;let r=this.runtime().activeSheet();n.kind==="cell"?this.selectionState=_t(Li(this.selectionState,n.row,n.column,{rowCount:this.layout.rowCount,columnCount:this.layout.columnCount}),r):n.kind==="rowHeader"&&this.selectionState.kind==="row"?this.selectionState=Li(this.selectionState,n.row,1,{columnCount:this.layout.columnCount,rowCount:this.layout.rowCount}):n.kind==="columnHeader"&&this.selectionState.kind==="column"&&(this.selectionState=Li(this.selectionState,1,n.column,{columnCount:this.layout.columnCount,rowCount:this.layout.rowCount})),this.render(),t.preventDefault();});O(this,"handlePointerUp",t=>{if(this.chartDrag){let n=this.chartDrag;if(this.chartDrag=null,this.host.style.cursor="",this.host.hasPointerCapture(t.pointerId)&&this.host.releasePointerCapture(t.pointerId),n.previewRect.x===n.startRect.x&&n.previewRect.y===n.startRect.y){this.render(),t.preventDefault();return}let r=this.chartAnchorAtIndex(n.chartIndex);if(r&&this.layout){let o=TS(this.layout,n.previewRect,r);this.runtime().moveChart(n.chartIndex,o).then(async()=>{this.render(),await this.emitChange();});}else this.render();t.preventDefault();return}if(this.resizeDrag){let n=dl(this.resizeDrag,t);this.resizeDrag=null,this.host.style.cursor="",this.hideResizeGuide(),this.host.hasPointerCapture(t.pointerId)&&this.host.releasePointerCapture(t.pointerId),this.commitResizeDrag(n),t.preventDefault();return}if(this.autoFillDrag){let n=this.autoFillDrag;this.autoFillDrag=null,this.host.hasPointerCapture(t.pointerId)&&this.host.releasePointerCapture(t.pointerId),n.preview?this.runtime().autoFillRange(n.source,n.preview).then(async()=>{this.selectionState=$(v({},this.selectionState),{range:n.preview}),this.render(),await this.emitChange();}):this.render(),t.preventDefault();return}this.selecting&&(this.selecting=false,this.host.hasPointerCapture(t.pointerId)&&this.host.releasePointerCapture(t.pointerId),this.host.style.cursor="");});O(this,"handlePointerLeave",()=>{!this.resizeDrag&&!this.autoFillDrag&&!this.chartDrag&&(this.host.style.cursor="");});O(this,"handleKeyDown",t=>{if(this.editingCell)return;let{row:n,column:r}=this.selectionState.active;if(t.key==="F2"||t.key==="Enter"){if(this.isReadOnly())return;t.preventDefault(),this.openCellEditor();return}let i={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1]}[t.key];if(!i)return;let s=this.runtime().activeSheet();this.selectionState=gt(Math.max(1,Math.min(s.maxRow,n+i[0])),Math.max(1,Math.min(s.maxColumn,r+i[1]))),t.preventDefault(),this.render();});O(this,"handleCopy",t=>{var o;let n=We(this.selectionState.range),r=el(this.runtime().activeSheet(),n);this.clipboardPayload=r,this.copiedRange=n,(o=t.clipboardData)==null||o.setData("text/plain",r.text),t.preventDefault();});O(this,"handlePaste",t=>{var o,i,s,a,l;if(this.isReadOnly()){t.preventDefault();return}let n=(i=(o=t.clipboardData)==null?void 0:o.getData("text/plain"))!=null?i:"";if(!n)return;t.preventDefault();let r=((s=this.clipboardPayload)==null?void 0:s.text)===n?this.clipboardPayload.values:tl(n);this.runtime().pasteRange(this.selectionState.active.row,this.selectionState.active.column,r,{mode:"all",merges:((a=this.clipboardPayload)==null?void 0:a.text)===n?this.clipboardPayload.merges:[],styleIds:((l=this.clipboardPayload)==null?void 0:l.text)===n?this.clipboardPayload.styleIds:[]}).then(async()=>{let c=_t({kind:"cell",active:this.selectionState.active,range:{startRow:this.selectionState.active.row,startColumn:this.selectionState.active.column,endRow:this.selectionState.active.row+r.length-1,endColumn:this.selectionState.active.column+Math.max(1,r.reduce((u,f)=>Math.max(u,f.length),0))-1}},this.runtime().activeSheet());this.selectionState=c,this.copiedRange=We(c.range),this.render(),await this.emitChange();});});O(this,"handleContextMenu",t=>{if(!this.viewport||!this.layout)return;let n=this.chartAtPoint(this.eventPoint(t));if(n){this.selectedChartIndex=n.chartIndex,this.hideContextMenu(),this.hideFilterMenu(),this.render(),t.preventDefault();return}let r=this.viewport.hitTest(this.eventPoint(t));r.kind==="cell"&&!this.selectionContainsCell(r.row,r.column)&&(this.selectionState=_t(gt(r.row,r.column),this.runtime().activeSheet()),this.render()),!(r.kind!=="cell"&&r.kind!=="rowHeader"&&r.kind!=="columnHeader")&&(t.preventDefault(),this.renderContextMenu(t.clientX,t.clientY,this.isReadOnly()?void 0:r.kind==="columnHeader"?r.column:void 0));});O(this,"handleDocumentPointerDown",t=>{let n=t.composedPath();n.includes(this.contextMenu)||n.includes(this.filterMenu)||(this.hideContextMenu(),this.hideFilterMenu());});O(this,"handleWheel",t=>{if(!this.runtimeValue)return;t.preventDefault();let n=Cf(this.scroll,t.deltaX,t.deltaY);this.setScroll(n.x,n.y);});var r;if(this.readOnlyValue=n.readOnly===true,t.replaceChildren(),this.renderRoot=n.styleIsolation==="none"?t:(r=t.shadowRoot)!=null?r:t.attachShadow({mode:"open"}),this.renderRoot.replaceChildren(),this.renderRoot instanceof ShadowRoot){let o=document.createElement("style");o.textContent=`
1602
1609
  :host { display: block; position: relative; min-width: 0; min-height: 0; }
1603
1610
  *, *::before, *::after { box-sizing: border-box; }
1604
1611
  button, input, textarea, select { font: 13px Arial, sans-serif; line-height: normal; }
1605
1612
  button { margin: 0; }
1606
- `,this.renderRoot.appendChild(o);}t.classList.add("coco-spreadsheet-editor-host"),Object.assign(t.style,{position:"relative",overflow:"hidden"});for(let o of [this.baseCanvas,this.headerCanvas,this.overlayCanvas])Object.assign(o.style,{position:"absolute",inset:"0",display:"block"}),this.renderRoot.appendChild(o);this.unsupportedObjectLayer.className="coco-spreadsheet-unsupported-object-layer",Object.assign(this.unsupportedObjectLayer.style,{position:"absolute",inset:"0",zIndex:"4",overflow:"hidden",pointerEvents:"none"}),this.renderRoot.appendChild(this.unsupportedObjectLayer),this.cellEditorElement.className="coco-spreadsheet-cell-editor",Object.assign(this.cellEditorElement.style,{position:"absolute",zIndex:"20",display:"none",resize:"none",overflow:"hidden",padding:"2px 4px",border:"2px solid #2563eb",outline:"none",font:"13px Arial, sans-serif",lineHeight:"normal",whiteSpace:"pre-wrap",overflowWrap:"break-word"}),this.renderRoot.appendChild(this.cellEditorElement),this.resizeGuide.className="coco-spreadsheet-resize-guide",Object.assign(this.resizeGuide.style,{position:"absolute",zIndex:"25",display:"none",pointerEvents:"none",background:"#2563eb"}),this.renderRoot.appendChild(this.resizeGuide),this.contextMenu.className="coco-spreadsheet-context-menu",Object.assign(this.contextMenu.style,{position:"fixed",zIndex:"50",display:"none",minWidth:"160px",padding:"4px",background:"#ffffff",border:"1px solid #cbd5e1",borderRadius:"6px",boxShadow:"0 8px 24px rgba(15, 23, 42, 0.16)"}),this.renderRoot.appendChild(this.contextMenu),this.filterMenu.className="coco-spreadsheet-filter-menu",Object.assign(this.filterMenu.style,{position:"fixed",zIndex:"60",display:"none",width:"240px",maxHeight:"360px",overflow:"auto",padding:"8px",background:"#ffffff",border:"1px solid #cbd5e1",borderRadius:"6px",boxShadow:"0 8px 24px rgba(15, 23, 42, 0.16)"}),this.renderRoot.appendChild(this.filterMenu),this.cellEditor=new Ri({textarea:this.cellEditorElement,onCommit:async o=>this.commitCellEdit(o),onCancel:()=>{this.editingCell=null,this.editingCellStyle=null,this.formulaReferenceRanges=[],this.render();}}),this.cellEditorElement.addEventListener("input",()=>{this.editingCell&&(this.formulaReferenceRanges=Tf(this.cellEditorElement.value),this.render());}),this.configureScrollbar(this.horizontalScrollbar,this.horizontalThumb,true),this.configureScrollbar(this.verticalScrollbar,this.verticalThumb,false),this.renderRoot.append(this.horizontalScrollbar,this.verticalScrollbar),this.sheetTabs.className="coco-spreadsheet-editor-tabs",n.showSheetTabs!==false&&this.renderRoot.appendChild(this.sheetTabs),this.renderer=new Ti({baseCanvas:this.baseCanvas,headerCanvas:this.headerCanvas,overlayCanvas:this.overlayCanvas}),t.addEventListener("wheel",this.handleWheel,{passive:false}),t.addEventListener("click",this.handleClick),t.addEventListener("dblclick",this.handleDoubleClick),t.addEventListener("pointerdown",this.handlePointerDown),t.addEventListener("pointermove",this.handlePointerMove),t.addEventListener("pointerup",this.handlePointerUp),t.addEventListener("pointerleave",this.handlePointerLeave),t.addEventListener("keydown",this.handleKeyDown),t.addEventListener("copy",this.handleCopy),t.addEventListener("paste",this.handlePaste),t.addEventListener("contextmenu",this.handleContextMenu),document.addEventListener("pointerdown",this.handleDocumentPointerDown),this.filterMenu.addEventListener("click",this.handleFilterMenuClick),t.tabIndex=0,this.resizeObserver=new ResizeObserver(()=>this.render()),this.resizeObserver.observe(t);}runtime(){if(!this.runtimeValue)throw new Error("SpreadsheetEditor: workbook is not loaded");return this.runtimeValue}isReadOnly(){return this.readOnlyValue}setReadOnly(t){this.disposed||this.isReadOnly()===t||(this.cellEditor.cancel(),this.resizeDrag=null,this.autoFillDrag=null,this.chartDrag=null,this.selecting=false,this.hideResizeGuide(),this.hideContextMenu(),this.hideFilterMenu(),this.runtime().setReadOnly(t),this.readOnlyValue=t,this.host.setAttribute("aria-readonly",String(t)),this.render());}selection(){return this.selectionState}cellState(t){var i,s,a,l;let n=this.runtime().activeSheet(),r=n.cellsByAddress.get(t);if(!r){let c=t.match(/^([A-Z]+)(\d+)$/i);if(!c)throw new Error(`SpreadsheetEditor: invalid cell address ${t}`);let u=yS(c[1]),f=Number(c[2]);return {address:t.toUpperCase(),row:f,column:u,value:null,displayText:""}}let o=n.styles.cellFormats[(i=r.styleId)!=null?i:0];return {address:r.address,row:r.row,column:r.column,value:r.value,displayText:r.displayText,formula:r.formula,styleId:r.styleId,format:o?{font:n.styles.fonts[(s=o.fontId)!=null?s:0],fill:n.styles.fills[(a=o.fillId)!=null?a:0],border:n.styles.borders[(l=o.borderId)!=null?l:0],alignment:o.alignment,numberFormatCode:o.numberFormatCode}:void 0}}freezeState(){return Si(this.runtime().activeSheet().source)}filterState(){return new Map([...this.columnFilters.entries()].map(([t,n])=>[t,[...n]]))}activeSheetName(){return this.runtime().activeSheetName()}async setActiveSheet(t){await this.runtime().setActiveSheet(t),this.scroll={x:0,y:0},this.selectionState=gt(1,1),this.render(),this.renderTabs();}async addSheet(t){await this.runtime().addSheet(t),this.scroll={x:0,y:0},this.selectionState=gt(1,1),this.renderTabs(),this.render(),await this.emitChange();}async renameSheet(t,n){await this.runtime().renameSheet(t,n),this.renderTabs(),this.render(),await this.emitChange();}async copySheet(t,n){await this.runtime().copySheet(t,n),this.scroll={x:0,y:0},this.selectionState=gt(1,1),this.renderTabs(),this.render(),await this.emitChange();}async deleteSheet(t){await this.runtime().deleteSheet(t),this.scroll={x:0,y:0},this.selectionState=gt(1,1),this.renderTabs(),this.render(),await this.emitChange();}async moveSheet(t,n){await this.runtime().moveSheet(t,n),this.renderTabs(),this.render(),await this.emitChange();}async setCellValue(t,n){await this.runtime().setCellValue(t,n,{mergeUndo:true}),this.render(),await this.emitChange();}async setCellFormula(t,n){await this.runtime().setCellFormula(t,n,{mergeUndo:true}),this.render(),await this.emitChange();}async formatSelection(t){await this.applyFormat(t);}async setSelectionFontColor(t){let n=We(this.selectionState.range);await this.runtime().setRangeFontColor(n.startRow,n.startColumn,n.endRow-n.startRow+1,n.endColumn-n.startColumn+1,t),this.render(),await this.emitChange();}async setSelectionFillColor(t){let n=We(this.selectionState.range);await this.runtime().setRangeFillColor(n.startRow,n.startColumn,n.endRow-n.startRow+1,n.endColumn-n.startColumn+1,t),this.render(),await this.emitChange();}async setSelectionHorizontalAlign(t){await this.applyAlignment(t);}async setSelectionVerticalAlign(t){let n=We(this.selectionState.range);await this.runtime().setRangeVerticalAlign(n.startRow,n.startColumn,n.endRow-n.startRow+1,n.endColumn-n.startColumn+1,t),this.render(),await this.emitChange();}async setSelectionNumberFormat(t){let n=We(this.selectionState.range);await this.runtime().setRangeNumberFormat(n.startRow,n.startColumn,n.endRow-n.startRow+1,n.endColumn-n.startColumn+1,t),this.render(),await this.emitChange();}async setSelectionBorder(t){let n=We(this.selectionState.range);await this.runtime().setRangeBorder(n.startRow,n.startColumn,n.endRow-n.startRow+1,n.endColumn-n.startColumn+1,t),this.render(),await this.emitChange();}async loadWorkbook(t){this.assertAlive();let n=this.runtimeValue;this.runtimeValue=null,this.scroll={x:0,y:0},n&&await n.dispose(),this.runtimeValue=await Mi.fromZip(t,{workbookId:this.options.workbookId,mode:"inline",readOnly:this.readOnlyValue}),this.host.setAttribute("aria-readonly",String(this.isReadOnly())),this.renderTabs(),this.render();}async toZip(){return this.runtime().toZip()}canUndo(){return this.runtime().canUndo()}canRedo(){return this.runtime().canRedo()}async undo(){await this.runtime().undo(),this.render(),await this.emitChange();}async redo(){await this.runtime().redo(),this.render(),await this.emitChange();}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}subscribeState(t){return this.stateListeners.add(t),()=>this.stateListeners.delete(t)}async runTransaction(t,n){this.transactionDepth+=1;try{await this.runtime().runUserTransaction(t,()=>n(this));}finally{this.transactionDepth-=1,this.transactionDepth===0&&this.transactionChanged&&(this.transactionChanged=false,this.render(),await this.emitChange());}}destroy(){if(this.disposed)return;this.disposed=true,this.resizeObserver.disconnect(),this.host.removeEventListener("wheel",this.handleWheel),this.host.removeEventListener("click",this.handleClick),this.host.removeEventListener("dblclick",this.handleDoubleClick),this.host.removeEventListener("pointerdown",this.handlePointerDown),this.host.removeEventListener("pointermove",this.handlePointerMove),this.host.removeEventListener("pointerup",this.handlePointerUp),this.host.removeEventListener("pointerleave",this.handlePointerLeave),this.host.removeEventListener("keydown",this.handleKeyDown),this.host.removeEventListener("copy",this.handleCopy),this.host.removeEventListener("paste",this.handlePaste),this.host.removeEventListener("contextmenu",this.handleContextMenu),document.removeEventListener("pointerdown",this.handleDocumentPointerDown),this.contextMenu.remove(),this.filterMenu.remove(),this.unsupportedObjectLayer.remove(),this.host.replaceChildren();let t=this.runtimeValue;this.runtimeValue=null,t==null||t.dispose();}render(){var f;let t=this.runtimeValue,n=this.renderer;if(!t||!n||this.disposed)return;let r=this.host.getBoundingClientRect(),o=Math.max(1,r.width),i=Math.max(1,r.height-(this.options.showSheetTabs===false?0:40)),s=new xi(t.activeSheet()),a={width:Math.max(1,o-12),height:Math.max(1,i-12)},l=new vi(s,{viewportSize:a,scroll:this.scroll,freeze:Si(t.activeSheet().source)});this.layout=s,this.viewport=l,this.scroll=l.scroll,this.scrollbarState=Sf(s,a,Si(t.activeSheet().source),this.scroll),n.resize(o,i);let c=this.options.enableHeaderFilters===true&&!this.isReadOnly();n.setHeaderFiltersEnabled(c),n.setHeaderFilterColumns(c?Array.from({length:s.columnCount},(p,w)=>w+1):null),n.setActiveHeaderFilterColumns(Array.from(this.columnFilters.keys())),n.render(s,l);let u=We(this.selectionState.range);n.renderSelection(s,l,u,{showFillHandle:!this.isReadOnly()&&el(t.activeSheet(),u)}),this.updateCellEditorPosition(),(f=this.autoFillDrag)!=null&&f.preview&&n.renderDashedRange(s,l,this.autoFillDrag.preview,{stroke:"#16A34A",fill:"rgba(34, 197, 94, 0.08)"});for(let p of this.formulaReferenceRanges)n.renderDashedRange(s,l,p.range,{stroke:p.stroke});this.copiedRange&&n.renderCopiedRange(s,l,this.copiedRange),this.renderUnsupportedChartNotices(s,l),this.emitStateIfChanged(t.activeSheetName()),this.updateScrollbars();}renderUnsupportedChartNotices(t,n){var o,i,s;this.unsupportedObjectLayer.replaceChildren();let r=(o=this.runtimeValue)==null?void 0:o.activeSheet().source;if(!(!r||r.charts.length===0))for(let a=0;a<r.charts.length;a+=1){let l=r.charts[a];if(!l)continue;let c=al(r.drawings,l),u=((i=this.chartDrag)==null?void 0:i.chartIndex)===a?this.chartDrag.previewRect:If(t,c);if(u)for(let f of Nf(u,n)){let p=document.createElement("div");p.className="coco-spreadsheet-unsupported-chart",Object.assign(p.style,{position:"absolute",left:`${f.x}px`,top:`${f.y}px`,width:`${Math.max(1,f.width)}px`,height:`${Math.max(1,f.height)}px`,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:"6px",padding:"12px",boxSizing:"border-box",overflow:"hidden",background:"rgba(248, 250, 252, 0.94)",color:"#475569",textAlign:"center",font:"13px Arial, sans-serif",lineHeight:"1.4",cursor:this.isReadOnly()?"default":((s=this.chartDrag)==null?void 0:s.chartIndex)===a?"grabbing":"move",border:this.selectedChartIndex===a?"2px solid #2563eb":"1px dashed #94a3b8",boxShadow:this.selectedChartIndex===a?"0 0 0 1px rgba(37, 99, 235, 0.18)":"none"});let w=document.createElement("strong");w.textContent=l.title?`\u56FE\u8868\uFF1A${l.title}`:"\u56FE\u8868",w.style.color="#334155";let b=document.createElement("span");b.textContent="\u5F53\u524D\u7F16\u8F91\u5668\u6682\u4E0D\u652F\u6301\u56FE\u8868\u6E32\u67D3";let g=document.createElement("span");g.textContent="\u8BF7\u4F7F\u7528 Excel \u6216 WPS \u6253\u5F00\u6587\u4EF6\u67E5\u770B",p.append(w,b,g),this.unsupportedObjectLayer.appendChild(p);}}}chartAnchorAtIndex(t){var o;let n=(o=this.runtimeValue)==null?void 0:o.activeSheet().source,r=n==null?void 0:n.charts[t];return r?al(n.drawings,r):void 0}chartAtPoint(t){var r;let n=(r=this.runtimeValue)==null?void 0:r.activeSheet().source;if(!n||!this.layout||!this.viewport)return null;for(let o=n.charts.length-1;o>=0;o-=1){let i=n.charts[o];if(!i)continue;let s=al(n.drawings,i),a=If(this.layout,s);if(a&&Nf(a,this.viewport).some(l=>Cf(l,t)))return {chartIndex:o,logicalRect:a}}return null}updateResizeGuide(t){t.kind==="column"?Object.assign(this.resizeGuide.style,{display:"block",left:`${Math.round(t.currentGuidePosition)}px`,top:"0",bottom:"0",width:"2px",height:""}):Object.assign(this.resizeGuide.style,{display:"block",left:"0",top:`${Math.round(t.currentGuidePosition)}px`,right:"0",height:"2px",width:""});}hideResizeGuide(){this.resizeGuide.style.display="none";}renderContextMenu(t,n,r){let o=this.isReadOnly()?[{label:"Copy",action:()=>this.copySelection()}]:[{label:"Undo",disabled:!this.canUndo(),action:()=>this.undo()},{label:"Redo",disabled:!this.canRedo(),action:()=>this.redo()},{label:"Copy",action:()=>this.copySelection()},{label:"Paste",action:()=>this.pasteFromClipboard()},{label:"Clear cells",action:()=>this.clearSelection()},{label:"Clear format",action:()=>this.clearSelectionFormat()},{label:"Bold",action:()=>this.applyFormat("bold")},{label:"Italic",action:()=>this.applyFormat("italic")},{label:"Underline",action:()=>this.applyFormat("underline")},{label:"Align left",action:()=>this.applyAlignment("left")},{label:"Align center",action:()=>this.applyAlignment("center")},{label:"Align right",action:()=>this.applyAlignment("right")},{label:"Merge cells",action:()=>this.mergeSelection()},{label:"Unmerge cells",action:()=>this.unmergeSelection()},{label:"Freeze above and left",action:()=>this.freezeSelection()}];r!==void 0&&(o.unshift({label:"Filter column",action:()=>this.openFilterMenu(r,t,n)}),o.splice(1,0,{label:"Sort A-Z",action:()=>this.sortColumn(r,"asc")},{label:"Sort Z-A",action:()=>this.sortColumn(r,"desc")})),this.contextMenu.replaceChildren();for(let i of o){let s=document.createElement("button");s.type="button",s.textContent=i.label,s.disabled=i.disabled===true,Object.assign(s.style,{display:"block",width:"100%",padding:"6px 10px",border:"0",background:"transparent",textAlign:"left",cursor:s.disabled?"default":"pointer"}),s.addEventListener("mouseenter",()=>{s.disabled||(s.style.background="#eff6ff");}),s.addEventListener("mouseleave",()=>{s.style.background="transparent";}),s.addEventListener("click",()=>{this.hideContextMenu(),i.action();}),this.contextMenu.appendChild(s);}Object.assign(this.contextMenu.style,{left:`${t}px`,top:`${n}px`,display:"block"});}openFilterMenu(t,n,r){var c;if(this.filterMenu.style.display==="block"&&this.filterMenuColumn===t){this.hideFilterMenu();return}let o=this.runtime().activeSheet(),i={startRow:1,endRow:o.maxRow,endColumn:o.maxColumn},s=new Set((c=this.columnFilters.get(t))!=null?c:nl(o,i,t));this.filterMenuColumn=t,this.filterMenu.replaceChildren();let a=document.createElement("strong");a.textContent=`Filter ${t}`,a.style.display="block",a.style.marginBottom="6px",this.filterMenu.appendChild(a);for(let u of nl(o,i,t)){let f=document.createElement("label");f.style.display="block",f.style.padding="3px 0";let p=document.createElement("input");p.type="checkbox",p.checked=s.has(u),p.dataset.filterValue=u,p.style.marginRight="8px",f.append(p,u===""?"(blank)":u),this.filterMenu.appendChild(f);}let l=document.createElement("div");l.style.display="flex",l.style.gap="6px",l.style.marginTop="8px";for(let[u,f]of [["Apply","apply"],["Clear filter","clear"],["Cancel","cancel"]]){let p=document.createElement("button");p.type="button",p.textContent=u,p.dataset.filterAction=f,l.appendChild(p);}this.filterMenu.appendChild(l),Object.assign(this.filterMenu.style,{left:`${n}px`,top:`${r}px`,display:"block"});}hideFilterMenu(){this.filterMenu.style.display="none",this.filterMenuColumn=null;}isFilterIconHit(t,n){if(!this.layout||!this.viewport)return false;let r=this.eventPoint(n),o=this.viewport.findViewport(r);if(!o)return false;let i=this.viewport.cellScreenRect(1,t,o);return i.width>=28&&r.x>=i.x+i.width-22&&r.x<=i.x+i.width}async applyColumnFilters(){let t=this.runtime().activeSheet(),n=Array.from(this.columnFilters.entries()).filter(([,r])=>r.length>0).map(([r,o])=>({column:r,values:o}));await this.runtime().filterRowsByColumns(1,t.maxRow,n),this.render(),await this.emitChange();}async sortColumn(t,n){let r=this.runtime().activeSheet();await this.runtime().sortRows(1,r.maxRow,t,n),this.render(),await this.emitChange();}async sortActiveColumn(t){await this.sortColumn(this.selectionState.active.column,t);}async filterColumn(t,n){this.assertWritable(),n===null?this.columnFilters.delete(t):this.columnFilters.set(t,[...n]),await this.applyColumnFilters();}hideContextMenu(){this.contextMenu.style.display="none";}selectionContainsCell(t,n){let r=We(this.selectionState.range);return t>=r.startRow&&t<=r.endRow&&n>=r.startColumn&&n<=r.endColumn}async copySelection(){let t=Ys(this.runtime().activeSheet(),We(this.selectionState.range));this.clipboardPayload=t;try{await navigator.clipboard.writeText(t.text);}catch(n){}}async pasteFromClipboard(){var r;let t="";try{t=await navigator.clipboard.readText();}catch(o){return}if(!t)return;let n=new ClipboardEvent("paste",{clipboardData:new DataTransfer});(r=n.clipboardData)==null||r.setData("text/plain",t),this.handlePaste(n);}async clearSelection(){let t=We(this.selectionState.range);await this.runtime().clearRange(t.startRow,t.startColumn,t.endRow-t.startRow+1,t.endColumn-t.startColumn+1),this.render(),await this.emitChange();}async clearSelectionFormat(){let t=We(this.selectionState.range);await this.runtime().clearRangeFormat(t.startRow,t.startColumn,t.endRow-t.startRow+1,t.endColumn-t.startColumn+1),this.render(),await this.emitChange();}async applyFormat(t){let n=We(this.selectionState.range),r=n.endRow-n.startRow+1,o=n.endColumn-n.startColumn+1;t==="bold"&&await this.runtime().setRangeBold(n.startRow,n.startColumn,r,o,true),t==="italic"&&await this.runtime().setRangeItalic(n.startRow,n.startColumn,r,o,true),t==="underline"&&await this.runtime().setRangeUnderline(n.startRow,n.startColumn,r,o,true),this.render(),await this.emitChange();}async applyAlignment(t){let n=We(this.selectionState.range);await this.runtime().setRangeHorizontalAlign(n.startRow,n.startColumn,n.endRow-n.startRow+1,n.endColumn-n.startColumn+1,t),this.render(),await this.emitChange();}async mergeSelection(){let t=We(this.selectionState.range);t.startRow===t.endRow&&t.startColumn===t.endColumn||(await this.runtime().mergeRange(t.startRow,t.startColumn,t.endRow-t.startRow+1,t.endColumn-t.startColumn+1),this.selectionState=Kt(this.selectionState,this.runtime().activeSheet()),this.render(),await this.emitChange());}async unmergeSelection(){let t=We(this.selectionState.range),n=[...this.runtime().activeSheet().mergeMasterByAddress.values()].filter(r=>SS(t,r.range)).map(r=>r.address);n.length!==0&&(await this.runtime().unmergeRanges(n),this.render(),await this.emitChange());}async freezeSelection(){let t=this.selectionState.active;await this.runtime().setFreezePanes(Math.max(0,t.row-1),Math.max(0,t.column-1)),this.render(),await this.emitChange();}async commitResizeDrag(t){if(t.currentSize===t.startSize){this.render();return}t.kind==="column"?await this.runtime().setColumnWidth(t.index,t.currentSize):await this.runtime().setRowHeight(t.index,t.currentSize*72/96),this.render(),await this.emitChange();}openCellEditor(){var f,p;if(this.isReadOnly()||!this.layout||!this.viewport)return;let t=this.selectionState.active,n=this.viewport.findViewport({x:this.layout.rowHeaderWidth+1,y:this.layout.columnHeaderHeight+1}),r=qe(this.runtime().activeSheet(),t.row,t.column),o=Ei(this.runtime().activeSheet().styles,r==null?void 0:r.styleId,r);Object.assign(this.cellEditorElement.style,{font:o.font,color:o.fontColor,textDecoration:o.underline?"underline":"none",textAlign:o.horizontalAlign});let i=(f=this.viewport.viewports.find(w=>w.kind==="main"))!=null?f:n;if(!i)return;let s=We(this.selectionState.range),a=this.viewport.cellScreenRect(s.startRow,s.startColumn,i),l=this.viewport.cellScreenRect(s.endRow,s.endColumn,i),c={x:a.x,y:a.y,width:l.x+l.width-a.x,height:l.y+l.height-a.y};this.editingCell=t,this.editingCellStyle=o;let u=r!=null&&r.formula?`=${r.formula}`:(p=r==null?void 0:r.displayText)!=null?p:"";this.formulaReferenceRanges=Tf(u),this.cellEditor.open(c,u),this.alignCellEditor(c,o),this.render();}async commitCellEdit(t){let n=this.editingCell;if(this.editingCell=null,this.editingCellStyle=null,this.formulaReferenceRanges=[],!n)return;this.assertWritable();let r=excel.formatCellAddress(n.row,n.column);t.startsWith("=")?await this.runtime().setCellFormula(r,t.slice(1),{mergeUndo:true}):await this.runtime().setCellValue(r,bS(t),{mergeUndo:true}),this.render(),await this.emitChange();}eventPoint(t){let n=this.host.getBoundingClientRect();return {x:t.clientX-n.left,y:t.clientY-n.top}}assertWritable(){if(this.isReadOnly())throw new ln("spreadsheet")}eventPathContains(t,n){return t.composedPath().includes(n)}updateCellEditorPosition(){let t=this.editingCell,n=this.layout,r=this.viewport;if(!t||!n||!r)return;let o=r.viewports.find(c=>c.kind!=="columnHeaderFrozen"&&c.kind!=="columnHeaderScrollable"&&c.kind!=="rowHeaderFrozen"&&c.kind!=="rowHeaderScrollable"&&t.row>=c.rows.start&&t.row<=c.rows.end&&t.column>=c.columns.start&&t.column<=c.columns.end);if(!o){this.cellEditorElement.style.display="none";return}let i=We(this.selectionState.range),s=r.cellScreenRect(i.startRow,i.startColumn,o),a=r.cellScreenRect(i.endRow,i.endColumn,o),l={x:s.x,y:s.y,width:a.x+a.width-s.x,height:a.y+a.height-s.y};this.cellEditorElement.style.left=`${l.x}px`,this.cellEditorElement.style.top=`${l.y}px`,this.cellEditorElement.style.width=`${Math.max(1,l.width)}px`,this.cellEditorElement.style.height=`${Math.max(1,l.height)}px`,this.cellEditorElement.style.display="block",this.editingCellStyle&&this.alignCellEditor(l,this.editingCellStyle);}alignCellEditor(t,n){let r=this.cellEditorElement,o=4,i=2;r.style.padding=`${i}px ${o}px`;let s=Math.max(0,t.height-r.scrollHeight),a=n.verticalAlign==="bottom"?i+s:n.verticalAlign==="middle"?i+s/2:i;r.style.paddingTop=`${a}px`;}async emitChange(){var n,r;if(this.transactionDepth>0){this.transactionChanged=true;return}let t={kind:"workbookChange",bytes:await this.toZip()};for(let o of this.listeners)o(t);await((r=(n=this.options).onChange)==null?void 0:r.call(n,t));}emitStateIfChanged(t){var s,a,l,c;let n=this.selectionState,r=`${n.kind}:${n.active.row}:${n.active.column}:${n.range.startRow}:${n.range.startColumn}:${n.range.endRow}:${n.range.endColumn}:${(a=(s=this.editingCell)==null?void 0:s.row)!=null?a:0}:${(c=(l=this.editingCell)==null?void 0:l.column)!=null?c:0}`,o=`${t}|${r}`;if(o===this.lastStateKey)return;this.lastStateKey=o;let i={kind:"stateChange",activeSheetName:t,selection:n,editingCell:this.editingCell};for(let u of this.stateListeners)u(i);}renderTabs(){if(!(this.options.showSheetTabs===false||!this.runtimeValue)){this.sheetTabs.replaceChildren(),Object.assign(this.sheetTabs.style,{position:"absolute",left:"0",right:"0",bottom:"0",height:"40px",display:"flex",alignItems:"center",gap:"8px",padding:"0 12px",background:"#eef1f5",borderTop:"1px solid #e2e8f0",boxSizing:"border-box",overflowX:"auto",overflowY:"hidden"});for(let t of this.runtimeValue.model().sheets){let n=document.createElement("button");n.type="button",n.textContent=t.name,n.dataset.active=String(t.name===this.runtimeValue.activeSheetName()),Object.assign(n.style,{height:"32px",minWidth:"64px",padding:"0 14px",border:"0",borderTop:t.name===this.runtimeValue.activeSheetName()?"2px solid #2563eb":"2px solid transparent",borderRadius:"3px 3px 0 0",background:t.name===this.runtimeValue.activeSheetName()?"#ffffff":"transparent",color:t.name===this.runtimeValue.activeSheetName()?"#1d4ed8":"#475569",font:"13px Arial, sans-serif",fontWeight:t.name===this.runtimeValue.activeSheetName()?"600":"400",cursor:"pointer",whiteSpace:"nowrap"}),n.addEventListener("mouseenter",()=>{n.dataset.active!=="true"&&(n.style.background="#e2e8f0");}),n.addEventListener("mouseleave",()=>{n.dataset.active!=="true"&&(n.style.background="transparent");}),n.addEventListener("click",()=>{this.setActiveSheet(t.name);}),this.sheetTabs.appendChild(n);}}}configureScrollbar(t,n,r){t.className="coco-spreadsheet-editor-scrollbar",Object.assign(t.style,v({position:"absolute",zIndex:"10",background:"#f1f5f9",border:"1px solid #cbd5e1",cursor:"pointer"},r?{left:"48px",bottom:"40px",height:"12px"}:{top:"24px",right:"0",bottom:"52px",width:"12px"})),n.className="coco-spreadsheet-editor-scrollbar-thumb",Object.assign(n.style,{position:"absolute",background:"#94a3b8",borderRadius:"999px"}),t.appendChild(n),t.addEventListener("pointerdown",o=>{var l;let i=(l=this.scrollbarState)==null?void 0:l[r?"horizontal":"vertical"];if(!i||i.maxScroll<=0)return;let s=t.getBoundingClientRect(),a=r?o.clientX-s.left:o.clientY-s.top;this.drag={axis:r?"horizontal":"vertical",pointer:a,thumb:i.thumbStart},t.setPointerCapture(o.pointerId),this.setScroll(r?Ai(i,a-i.thumbLength/2):this.scroll.x,r?this.scroll.y:Ai(i,a-i.thumbLength/2));}),t.addEventListener("pointermove",o=>{var u;let i=this.drag,s=(u=this.scrollbarState)==null?void 0:u[r?"horizontal":"vertical"];if(!i||!s||i.axis!==(r?"horizontal":"vertical"))return;let a=t.getBoundingClientRect(),l=r?o.clientX-a.left:o.clientY-a.top,c=Ai(s,i.thumb+l-i.pointer);this.setScroll(r?c:this.scroll.x,r?this.scroll.y:c);}),t.addEventListener("pointerup",()=>{this.drag=null;});}updateScrollbars(){let t=this.scrollbarState,n=this.layout,r=this.viewport;if(!t||!n||!r)return;let o=t.horizontal,i=t.vertical;this.horizontalScrollbar.style.display=o.maxScroll>0?"block":"none",this.verticalScrollbar.style.display=i.maxScroll>0?"block":"none",Object.assign(this.horizontalScrollbar.style,{left:`${n.rowHeaderWidth+n.getColumnX(r.freeze.frozenColumns+1)}px`,width:`${o.trackLength}px`}),Object.assign(this.horizontalThumb.style,{left:`${o.thumbStart}px`,width:`${o.thumbLength}px`,top:"1px",bottom:"1px"}),Object.assign(this.verticalScrollbar.style,{top:`${n.columnHeaderHeight+n.getRowY(r.freeze.frozenRows+1)}px`,height:`${i.trackLength}px`}),Object.assign(this.verticalThumb.style,{top:`${i.thumbStart}px`,height:`${i.thumbLength}px`,left:"1px",right:"1px"});}setScroll(t,n){this.scroll={x:t,y:n},this.render();}assertAlive(){if(this.disposed)throw new Error("SpreadsheetEditor: editor has been destroyed")}};function bS(e){if(e==="")return null;if(e==="TRUE")return true;if(e==="FALSE")return false;let t=Number(e);return Number.isFinite(t)&&e.trim()!==""?t:e}function Cf(e,t){return t.x>=e.x&&t.y>=e.y&&t.x<=e.x+e.width&&t.y<=e.y+e.height}function al(e,t){var o;let n=e.find(i=>i.path===t.drawingPath);return ((o=n==null?void 0:n.anchors)!=null?o:e.flatMap(i=>i.anchors)).find(i=>{var s;return ((s=i.object)==null?void 0:s.kind)==="chart"&&(!t.relationshipId||i.object.relationshipId===t.relationshipId)})}function If(e,t){var u,f;if(!t||t.kind==="absolute"||!t.from)return null;let n=Li(t.from.column),r=Li(t.from.row),o=t.to?Li(t.to.column):n+5,i=t.to?Li(t.to.row):r+12,s=e.getColumnX(n)+Wi(t.from.columnOffset),a=e.getRowY(r)+Wi(t.from.rowOffset),l=e.getColumnX(o)+Wi((u=t.to)==null?void 0:u.columnOffset),c=e.getRowY(i)+Wi((f=t.to)==null?void 0:f.rowOffset);return {x:s,y:a,width:Math.max(1,l-s),height:Math.max(1,c-a)}}function Nf(e,t){let n=[];for(let r of t.viewports){if(!xS(r))continue;let o=r.originX,i=r.originY,s=r.originX+r.screenRect.width,a=r.originY+r.screenRect.height,l=Math.max(e.x,o),c=Math.max(e.y,i),u=Math.min(e.x+e.width,s),f=Math.min(e.y+e.height,a);u<=l||f<=c||n.push({x:r.screenRect.x+l-r.originX,y:r.screenRect.y+c-r.originY,width:u-l,height:f-c});}return n}function wS(e,t,n){let r=(s,a)=>{let l=e.columnAt(Math.max(0,s)),c=e.rowAt(Math.max(0,a));return {column:l-1,row:c-1,columnOffset:Math.round((s-e.getColumnX(l))*9525),rowOffset:Math.round((a-e.getRowY(c))*9525)}},o=r(t.x,t.y),i=n.to?r(t.x+t.width,t.y+t.height):void 0;return {from:o,to:i}}function xS(e){return e.kind==="main"||e.kind==="frozenTop"||e.kind==="frozenLeft"||e.kind==="frozenTopLeft"}function Li(e){return Math.max(1,Math.floor(e!=null?e:0)+1)}function Wi(e){return Number.isFinite(e)?(e!=null?e:0)/9525:0}function yS(e){let t=0;for(let n of e.toUpperCase())t=t*26+n.charCodeAt(0)-64;return t}function vS(e,t){if(t.kind!=="cell")return null;let n=Math.max(0,t.row-e.endRow),r=Math.max(0,t.column-e.endColumn);return !n&&!r?null:n>=r?$(v({},e),{endRow:e.endRow+n}):$(v({},e),{endColumn:e.endColumn+r})}function SS(e,t){return !(e.endRow<t.startRow||e.startRow>t.endRow||e.endColumn<t.startColumn||e.startColumn>t.endColumn)}function Tf(e){var r;if(!e.startsWith("="))return [];let t=(r=e.match(/(?:\$?[A-Z]{1,3}\$?\d+)(?::(?:\$?[A-Z]{1,3}\$?\d+))?/g))!=null?r:[],n=["#DC2626","#16A34A","#7C3AED","#EA580C","#0891B2"];return t.flatMap((o,i)=>{var f,p,w;let s=o.split(":"),a=(f=s[0])!=null?f:"",l=(p=s[1])!=null?p:a,c=Pf(a),u=Pf(l);return !c||!u?[]:[{range:We({startRow:c.row,startColumn:c.column,endRow:u.row,endColumn:u.column}),stroke:(w=n[i%n.length])!=null?w:"#DC2626"}]})}function Pf(e){var o,i;let t=e.replace(/\$/g,"").match(/^([A-Z]{1,3})(\d+)$/);if(!t)return null;let n=0;for(let s of (o=t[1])!=null?o:"")n=n*26+s.charCodeAt(0)-64;let r=Number((i=t[2])!=null?i:"");return Number.isFinite(r)&&r>0&&n>0?{row:r,column:n}:null}var ES={width:9144e3,height:5143500},Fi=new Set(["placeholder","textBox","geometricShape","line"]),Lf=new WeakMap;function io(e){var n;let t=(n=e.slideSize)!=null?n:ES;return {size:t,slides:e.slides.map(r=>CS(r,t))}}function CS(e,t){var l,c,u,f,p,w,b,g,h,y;let n=(c=(l=e.layout)==null?void 0:l.shapes)!=null?c:[],o=[...[...((p=(f=(u=e.layout)==null?void 0:u.master)==null?void 0:f.shapes)!=null?p:[]).map(k=>ll(k,"master")),...n.map(k=>ll(k,"layout"))].filter(NS),...e.shapes.map(k=>PS(k,e.layout))],i=o.flatMap(Wf),s=(y=(b=e.background)!=null?b:(w=e.layout)==null?void 0:w.background)!=null?y:(h=(g=e.layout)==null?void 0:g.master)==null?void 0:h.background,a=s!=null?s:IS(o,t);return $(v({id:e.id,index:e.index,name:e.name,title:e.title,size:t},s?{background:s}:{}),{nodes:i.map((k,C)=>ao(k,{slideSize:t,index:C,background:s,backgroundFill:a})),groups:o.flatMap(k=>Bf(k,{background:s,backgroundFill:a})),source:e})}function IS(e,t){var r;let n=e.find(o=>{var s;let i=oo(o.geometry);return o.kind==="picture"&&!!((s=o.image)!=null&&s.targetPath)&&i.left<=t.width*.02&&i.top<=t.height*.02&&i.width>=t.width*.96&&i.height>=t.height*.96});return (r=n==null?void 0:n.image)!=null&&r.targetPath?{imagePath:n.image.targetPath}:void 0}function ll(e,t){var n;return $(v({},e),{id:`${t}:${e.id}`,children:(n=e.children)==null?void 0:n.map(r=>ll(r,t))})}function NS(e){return e.placeholder?false:e.kind==="group"||e.kind==="picture"||e.kind==="geometricShape"||e.kind==="line"||e.kind==="textBox"}function Wf(e){var t;return e.kind!=="group"?[e]:((t=e.children)!=null?t:[]).flatMap(n=>Wf(Ff(e,n)))}function Bf(e,t={}){var n;return e.kind!=="group"?[]:[ao(e,{background:t.background,backgroundFill:t.backgroundFill}),...((n=e.children)!=null?n:[]).map(r=>Ff(e,r)).flatMap(r=>Bf(r,t))]}function Ff(e,t){var N,L,D,W,V;let n=oo(e.geometry),r=(N=e.raw)==null?void 0:N.groupTransform,o=oo(t.geometry),i=(L=r==null?void 0:r.childLeft)!=null?L:n.left,s=(D=r==null?void 0:r.childTop)!=null?D:n.top,a=(r==null?void 0:r.childWidth)||n.width||1,l=(r==null?void 0:r.childHeight)||n.height||1,c=n.width/a,u=n.height/l,f=(o.left-i)*c,p=(o.top-s)*u,w=o.width*c,b=o.height*u,g=n.flipHorizontal?n.left+n.width-f-w:n.left+f,h=n.flipVertical?n.top+n.height-p-b:n.top+p,y=TS({left:g,top:h,width:w,height:b},n),k=Df(((W=n.rotation)!=null?W:0)+((V=o.rotation)!=null?V:0)),C=$(v({},t),{id:`${e.id}:${t.id}`,geometry:$(v({},t.geometry),{left:y.left,top:y.top,width:w,height:b,rotation:k,flipHorizontal:!!n.flipHorizontal!=!!o.flipHorizontal,flipVertical:!!n.flipVertical!=!!o.flipVertical}),children:t.children});return Lf.set(C,{parentId:e.id,parentName:e.name,parentBounds:n,parentTransform:{childLeft:i,childTop:s,childWidth:a,childHeight:l}}),C}function TS(e,t){if(!t.rotation)return e;let n=t.rotation*Math.PI/180,r=t.left+t.width/2,o=t.top+t.height/2,i=e.left+e.width/2,s=e.top+e.height/2,a=i-r,l=s-o,c=r+a*Math.cos(n)-l*Math.sin(n),u=o+a*Math.sin(n)+l*Math.cos(n);return $(v({},e),{left:c-e.width/2,top:u-e.height/2})}function Df(e){let t=(e%360+360)%360;return t===0?void 0:t}function PS(e,t){if(!e.placeholder)return e;let n=ppt.resolvePptEffectivePlaceholderProperties(e,t);return v($(v({},e),{placeholder:n.placeholder,geometry:n.geometry,style:n.style}),e.text?{text:$(v({},e.text),{style:n.textStyle,body:n.textBody})}:{})}function ao(e,t={}){var c,u,f,p,w,b,g,h,y,k,C,N,L,D,W,V,ee;let n=Hf(e),r=n.editText||n.editTextStyle||n.editTableCells||n.editGeometry||n.editShapeStyle,o=e.style,i=((c=e.raw)==null?void 0:c.useBackgroundFill)===true,s=i?void 0:(f=(u=e.style)==null?void 0:u.fillColor)!=null?f:AS(e,t),a=LS((p=e.text)==null?void 0:p.style,{fillColor:s,background:t.background}),l=oo(e.geometry);return $(v({id:e.id,name:e.name,kind:e.kind,bounds:RS(e,l),text:(b=(w=e.text)==null?void 0:w.text)!=null?b:MS(e),textStyle:a,textParagraphs:(g=e.text)==null?void 0:g.paragraphs,textBody:(h=e.text)==null?void 0:h.body,imagePath:(y=e.image)==null?void 0:y.targetPath,imageCrop:(k=e.image)==null?void 0:k.crop,imageFillRect:(C=e.image)==null?void 0:C.fillRect,imageOpacity:(N=e.image)==null?void 0:N.opacity,chart:e.chart,table:e.table,fillColor:s,fillGradient:i||o==null?void 0:o.fillGradient,opacity:o==null?void 0:o.opacity,lineColor:o==null?void 0:o.lineColor,lineGradient:o==null?void 0:o.lineGradient,lineOpacity:o==null?void 0:o.lineOpacity,lineWidth:o==null?void 0:o.lineWidth,lineCap:o==null?void 0:o.lineCap,lineDash:o==null?void 0:o.lineDash,lineHeadEnd:o==null?void 0:o.lineHeadEnd,lineTailEnd:o==null?void 0:o.lineTailEnd,shadow:o==null?void 0:o.shadow,presetGeometry:(L=e.raw)==null?void 0:L.presetGeometry,presetAdjustments:(D=e.raw)==null?void 0:D.presetAdjustments,customGeometry:(W=e.raw)==null?void 0:W.customGeometry,threeD:(V=e.raw)==null?void 0:V.threeD,usesBackgroundFill:i},i&&t.backgroundFill?{backgroundFill:t.backgroundFill}:{}),{locked:!r,editable:r,capabilities:n,groupContext:HS(e),source:e,children:((ee=e.children)!=null?ee:[]).map(pe=>ao(pe,{background:t.background,backgroundFill:t.backgroundFill}))})}function MS(e){if(e.table)return e.table.values.map(t=>t.join(" ")).join(`
1607
- `)}function RS(e,t){if(!e.table)return t;let n=Mf(e.table.columnWidths),r=Mf(e.table.rowHeights);return n===void 0&&r===void 0?t:v(v(v({},t),Rf(t.width,n)?{width:n}:{}),Rf(t.height,r)?{height:r}:{})}function Mf(e){if(!(e!=null&&e.length))return;let t=e.reduce((n,r)=>n+r,0);return Number.isFinite(t)&&t>0?t:void 0}function Rf(e,t){return t===void 0?false:!Number.isFinite(e)||e<=0?true:t/e>1.15}function AS(e,t){var o;let n=oo(e.geometry),r=t.slideSize;if(t.index===0&&e.kind==="geometricShape"&&!((o=e.text)!=null&&o.text)&&r&&n.left<=0&&n.top<=0&&n.width>=r.width*.95&&n.height>=r.height*.95)return "#1D3F80"}function LS(e,t){var r,o;if(e!=null&&e.color)return e;let n=(o=t.fillColor)!=null?o:(r=t.background)==null?void 0:r.fillColor;return !n||!WS(n)?e:$(v({},e),{color:"#FFFFFF"})}function WS(e){let t=/^#?([0-9a-f]{6})$/i.exec(e);if(!t)return false;let n=t[1],r=Number.parseInt(n.slice(0,2),16),o=Number.parseInt(n.slice(2,4),16),i=Number.parseInt(n.slice(4,6),16);return (.2126*r+.7152*o+.0722*i)/255<.45}function VN(e){let t=Hf(e);return t.editText||t.editTextStyle||t.editTableCells||t.editGeometry||t.editShapeStyle}function Hf(e){if(FS(e))return {select:true,editText:false,editTextStyle:false,editTableCells:false,editGeometry:false,editShapeStyle:false,reason:"Inherited from layout/master",reasons:Af("\u7EE7\u627F\u81EA\u6BCD\u7248/\u7248\u5F0F\uFF0C\u5F53\u524D\u53EA\u652F\u6301\u67E5\u770B")};if(DS(e)){let n=!!e.text&&Fi.has(e.kind),r=e.kind==="table"&&!!e.table;return {select:true,editText:n,editTextStyle:n,editTableCells:r,editGeometry:true,editShapeStyle:false,reason:"Flattened group child",reasons:ro({editText:n?void 0:Bi(e),editTextStyle:n?void 0:Bi(e),editTableCells:r?void 0:"\u5F53\u524D\u5BF9\u8C61\u4E0D\u662F\u8868\u683C",editShapeStyle:"\u7EC4\u5185\u5B50\u5BF9\u8C61\u6682\u4E0D\u652F\u6301\u8BE5\u9879\u76F4\u63A5\u7F16\u8F91"})}}if(e.kind==="table")return {select:true,editText:false,editTextStyle:false,editTableCells:true,editGeometry:true,editShapeStyle:true,reasons:ro({editText:"\u8868\u683C\u6587\u5B57\u8BF7\u4F7F\u7528\u5355\u5143\u683C\u7F16\u8F91",editTextStyle:"\u8868\u683C\u6587\u5B57\u6837\u5F0F\u5F53\u524D\u4E0D\u5728\u9AD8\u9891\u5DE5\u5177\u680F\u5F00\u653E"})};if(e.kind==="picture")return {select:true,editText:false,editTextStyle:false,editTableCells:false,editGeometry:true,editShapeStyle:true,reasons:ro({editText:"\u56FE\u7247\u5BF9\u8C61\u6CA1\u6709\u53EF\u7F16\u8F91\u6587\u5B57",editTextStyle:"\u56FE\u7247\u5BF9\u8C61\u6CA1\u6709\u53EF\u7F16\u8F91\u6587\u5B57\u6837\u5F0F",editTableCells:"\u5F53\u524D\u5BF9\u8C61\u4E0D\u662F\u8868\u683C"})};if(e.kind==="chart"||e.kind==="smartArt"||e.kind==="group"){let n=BS(e.kind);return {select:true,editText:false,editTextStyle:false,editTableCells:false,editGeometry:true,editShapeStyle:false,reason:"Limited editor support for this object type",reasons:ro({editText:n.text,editTextStyle:n.textStyle,editTableCells:"\u5F53\u524D\u5BF9\u8C61\u4E0D\u662F\u8868\u683C",editShapeStyle:n.shapeStyle})}}let t=!!e.text&&Fi.has(e.kind);return Fi.has(e.kind)?{select:true,editText:t,editTextStyle:t,editTableCells:false,editGeometry:true,editShapeStyle:true,reasons:ro({editText:t?void 0:Bi(e),editTextStyle:t?void 0:Bi(e),editTableCells:"\u5F53\u524D\u5BF9\u8C61\u4E0D\u662F\u8868\u683C"})}:{select:true,editText:false,editTextStyle:false,editTableCells:false,editGeometry:false,editShapeStyle:false,reason:"Unsupported object type",reasons:Af("\u5F53\u524D\u5BF9\u8C61\u7C7B\u578B\u6682\u4E0D\u652F\u6301\u5E38\u89C4\u7F16\u8F91")}}function ro(e){return Object.fromEntries(Object.entries(e).filter(t=>!!t[1]))}function Af(e){return {editText:e,editTextStyle:e,editTableCells:e,editGeometry:e,editShapeStyle:e}}function Bi(e){return e.text?Fi.has(e.kind)?"\u5F53\u524D\u5BF9\u8C61\u6587\u5B57\u6682\u4E0D\u652F\u6301\u7F16\u8F91":"\u5F53\u524D\u5BF9\u8C61\u7C7B\u578B\u6682\u4E0D\u652F\u6301\u6587\u5B57\u7F16\u8F91":"\u5F53\u524D\u5BF9\u8C61\u6CA1\u6709\u53EF\u7F16\u8F91\u6587\u5B57\u5185\u5BB9"}function BS(e){return e==="chart"?{text:"\u56FE\u8868\u6587\u5B57\u7ED1\u5B9A\u5728\u56FE\u8868\u6570\u636E\u4E2D\uFF0C\u5F53\u524D\u4EC5\u5F00\u653E\u6574\u4F53\u4F4D\u7F6E\u5C3A\u5BF8",textStyle:"\u56FE\u8868\u5185\u90E8\u6587\u5B57\u6837\u5F0F\u6682\u672A\u5F00\u653E",shapeStyle:"\u56FE\u8868\u5F62\u72B6\u6837\u5F0F\u6682\u672A\u5F00\u653E"}:e==="smartArt"?{text:"SmartArt \u5185\u90E8\u6587\u672C\u7ED3\u6784\u6682\u672A\u5F00\u653E",textStyle:"SmartArt \u5185\u90E8\u6587\u5B57\u6837\u5F0F\u6682\u672A\u5F00\u653E",shapeStyle:"SmartArt \u6837\u5F0F\u6682\u672A\u5F00\u653E"}:{text:"\u7EC4\u5408\u5BF9\u8C61\u8BF7\u53CC\u51FB\u6216\u70B9\u9009\u7EC4\u5185\u5B50\u5BF9\u8C61\u7F16\u8F91\u6587\u5B57",textStyle:"\u7EC4\u5408\u5BF9\u8C61\u8BF7\u9009\u4E2D\u7EC4\u5185\u6587\u672C\u5B50\u5BF9\u8C61\u7F16\u8F91\u6587\u5B57\u6837\u5F0F",shapeStyle:"\u7EC4\u5408\u5BF9\u8C61\u6682\u4E0D\u652F\u6301\u6574\u4F53\u5F62\u72B6\u6837\u5F0F\u7F16\u8F91"}}function FS(e){return e.id.startsWith("layout:")||e.id.startsWith("master:")}function DS(e){return e.id.includes(":")}function Of(e,t){var w;if(!e.groupContext)return t;let n=e.groupContext.parentBounds,r=e.groupContext.parentTransform,o=v(v({},e.bounds),t),i=n.width/(r.childWidth||n.width||1),s=n.height/(r.childHeight||n.height||1),a=OS(o.left+o.width/2,o.top+o.height/2,n),l=a.x-o.width/2,c=a.y-o.height/2,u=n.flipHorizontal?n.left+n.width-l-o.width:l-n.left,f=n.flipVertical?n.top+n.height-c-o.height:c-n.top,p={};return t.left!==void 0&&(p.left=u/i+r.childLeft),t.top!==void 0&&(p.top=f/s+r.childTop),t.width!==void 0&&(p.width=o.width/i),t.height!==void 0&&(p.height=o.height/s),t.rotation!==void 0&&(p.rotation=Df(t.rotation-((w=n.rotation)!=null?w:0))),t.flipHorizontal!==void 0&&(p.flipHorizontal=!!n.flipHorizontal!=!!t.flipHorizontal),t.flipVertical!==void 0&&(p.flipVertical=!!n.flipVertical!=!!t.flipVertical),p}function HS(e){return Lf.get(e)}function OS(e,t,n){if(!n.rotation)return {x:e,y:t};let r=-n.rotation*Math.PI/180,o=n.left+n.width/2,i=n.top+n.height/2,s=e-o,a=t-i;return {x:o+s*Math.cos(r)-a*Math.sin(r),y:i+s*Math.sin(r)+a*Math.cos(r)}}function oo(e={}){var t,n,r,o;return {left:(t=e.left)!=null?t:0,top:(n=e.top)!=null?n:0,width:(r=e.width)!=null?r:0,height:(o=e.height)!=null?o:0,rotation:e.rotation,flipHorizontal:e.flipHorizontal,flipVertical:e.flipVertical}}function tr(e,t){var n,r;return typeof t=="number"?(n=e.slides.find(o=>o.index===t))!=null?n:null:(r=e.slides.find(o=>o.id===t||o.name===t))!=null?r:null}function so(e,t){let n=[...e.nodes,...e.groups];for(;n.length>0;){let r=n.shift();if(r.id===t||r.name===t)return r;n.unshift(...r.children);}return null}async function _N(e,t={}){let n=await ppt.Presentation.fromZip(e,{presentationId:t.presentationId,mode:"inline"});return zf(n,t)}async function qN(e,t={}){var r;let n=await ppt.Presentation.fromModel(e,{presentationId:(r=t.presentationId)!=null?r:e.id,mode:"inline"});return zf(n,t)}async function zf(e,t={}){let[n,r,o]=await Promise.all([e.toModel(),$S(e,t),zS(e)]);return {presentation:e,model:n,scene:io(n),images:r,fonts:o}}async function $S(e,t){if(typeof Blob=="undefined"||typeof URL=="undefined"||typeof URL.createObjectURL!="function")return {};let n=await e.exportImages(),r=await Promise.all(n.map(async o=>{var s;let i=await((s=t.resolveImagePreview)==null?void 0:s.call(t,{path:o.path,contentType:o.contentType,bytes:o.bytes}));return [o.path,i!=null?i:{url:URL.createObjectURL(new Blob([Vf(o.bytes)],{type:o.contentType})),contentType:o.contentType}]}));return Object.fromEntries(r)}async function zS(e){return typeof Blob=="undefined"||typeof URL=="undefined"||typeof URL.createObjectURL!="function"?[]:(await e.exportFonts()).map(n=>v(v({url:URL.createObjectURL(new Blob([Vf(n.bytes)],{type:n.contentType})),contentType:n.contentType,family:n.family},n.weight?{weight:n.weight}:{}),n.style?{style:n.style}:{}))}function Vf(e){let t=new Uint8Array(e.byteLength);return t.set(e),t.buffer}var Di=class{constructor(t,n={}){O(this,"presentationValue");O(this,"modelValue");O(this,"sceneValue");O(this,"selectionValue",null);O(this,"revisionValue",0);O(this,"undoStack",[]);O(this,"redoStack",[]);O(this,"textBodyOverrides",new Map);O(this,"maxHistory");O(this,"readOnlyValue");O(this,"changeListeners",new Set);O(this,"selectionListeners",new Set);var r;this.presentationValue=t.presentation,this.modelValue=t.model,this.sceneValue=t.scene,this.maxHistory=(r=n.maxHistory)!=null?r:50,this.readOnlyValue=n.readOnly===true,this.selectionValue=t.scene.slides[0]?{kind:"slide",slideId:t.scene.slides[0].id}:null;}presentation(){return this.assertWritable(),this.presentationValue}model(){return this.modelValue}scene(){return this.sceneValue}selection(){return this.selectionValue}revision(){return this.revisionValue}isReadOnly(){return this.readOnlyValue}setReadOnly(t){this.readOnlyValue=t;}canUndo(){return !this.readOnlyValue&&this.undoStack.length>0}canRedo(){return !this.readOnlyValue&&this.redoStack.length>0}subscribe(t,n){let r=t==="change"?this.changeListeners:this.selectionListeners;return r.add(n),()=>r.delete(n)}async dispatch(t){if(t.kind==="select-slide"||t.kind==="select-shape"){await this.applySelectionCommand(t);return}this.assertWritable();let n=await this.presentationValue.toZip(),r=await this.applyEditCommand(t);this.pushUndo(n),this.redoStack.length=0,await this.refreshAfterChange(t),r!==void 0&&this.setSelection(r);}async undo(){this.assertWritable();let t=this.undoStack.pop();if(!t)return;let n=this.selectionValue;this.redoStack.push(this.historyEntry(await this.presentationValue.toZip())),this.restoreTextBodyOverrides(t.textBodyOverrides),await this.replacePresentation(t.bytes,n);}async redo(){this.assertWritable();let t=this.redoStack.pop();if(!t)return;let n=this.selectionValue;this.undoStack.push(this.historyEntry(await this.presentationValue.toZip())),this.restoreTextBodyOverrides(t.textBodyOverrides),await this.replacePresentation(t.bytes,n);}async loadPresentation(t){this.undoStack.length=0,this.redoStack.length=0,this.textBodyOverrides.clear(),await this.replacePresentation(t);}async toPptx(){return this.presentationValue.toZip()}async verifyExport(){let t=await this.toPptx(),n=await ppt.Presentation.fromZip(t,{mode:"inline"});try{return await n.toModel()}finally{await n.dispose();}}async destroy(){await this.presentationValue.dispose(),this.undoStack.length=0,this.redoStack.length=0,this.changeListeners.clear(),this.selectionListeners.clear();}assertWritable(){if(this.readOnlyValue)throw new ln("ppt")}async applySelectionCommand(t){let n=tr(this.sceneValue,t.slideIdOrIndex);if(!n)throw new Error(`PPT slide not found: ${String(t.slideIdOrIndex)}`);if(t.kind==="select-slide"){this.setSelection({kind:"slide",slideId:n.id});return}let r=so(n,t.shapeIdOrName);if(!r)throw new Error(`PPT shape not found: ${t.shapeIdOrName}`);this.setSelection({kind:"shape",slideId:n.id,shapeId:r.id});}async applyEditCommand(t){var s,a;if(t.kind==="delete-shape"||t.kind==="duplicate-shape"||t.kind==="paste-shape"||t.kind==="bring-shape-to-front"||t.kind==="send-shape-to-back")return this.applyShapeCollectionCommand(t);let n=this.assertEditableSceneNodeForCommand(t),r=tr(this.sceneValue,t.slideIdOrIndex);if(!r)throw new Error(`PPT slide not found: ${String(t.slideIdOrIndex)}`);let o=this.presentationValue.slides.getItem(t.slideIdOrIndex),i=KS(o.shapes,t.shapeIdOrName);if(t.kind==="set-shape-text"){await i.text.setText(t.text,{preserveFirstRunStyle:true});return}if(t.kind==="set-shape-text-style"){await i.text.setTextStyle(t.style);return}if(t.kind==="set-table-cell-text"){await i.table.setCellText(t.row,t.column,t.text);return}if(t.kind==="set-shape-geometry"){if(t.preserveTextSizeOnResize&&GS(n)){let l=$(v({},n.textBody),{autoFit:"none",wrap:(a=(s=n.textBody)==null?void 0:s.wrap)!=null?a:"square"});await i.text.setBodyProperties(l),this.textBodyOverrides.set(VS(r.id,n.id),l);}await i.setGeometry(Of(n,t.geometry));return}await i.setStyle(t.style);}assertEditableSceneNodeForCommand(t){var o;let n=tr(this.sceneValue,t.slideIdOrIndex);if(!n)throw new Error(`PPT slide not found: ${String(t.slideIdOrIndex)}`);let r=(o=so(n,t.shapeIdOrName))!=null?o:US(n,t.shapeIdOrName);if(!r)throw new Error(`PPT shape not found: ${t.shapeIdOrName}`);if(_S(t)&&(r.locked||r.id.includes(":")||!r.editable))throw new Error(`PPT shape collection operation is not editable: ${r.id}`);if(t.kind==="set-shape-text"&&!r.capabilities.editText)throw new Error(`PPT shape is not text-editable: ${r.id}`);if(t.kind==="set-shape-text-style"&&!r.capabilities.editTextStyle)throw new Error(`PPT shape text style is not editable: ${r.id}`);if(t.kind==="set-table-cell-text"&&!r.capabilities.editTableCells)throw new Error(`PPT shape table cells are not editable: ${r.id}`);if(t.kind==="set-shape-geometry"&&!r.capabilities.editGeometry)throw new Error(`PPT shape geometry is not editable: ${r.id}`);if(t.kind==="set-shape-style"&&!r.capabilities.editShapeStyle)throw new Error(`PPT shape style is not editable: ${r.id}`);return r}async applyShapeCollectionCommand(t){var c,u,f,p,w,b,g,h;this.assertEditableSceneNodeForCommand(t);let n=tr(this.sceneValue,t.slideIdOrIndex);if(!n)throw new Error(`PPT slide not found: ${String(t.slideIdOrIndex)}`);let r=so(n,t.shapeIdOrName);if(!r)throw new Error(`PPT shape not found: ${t.shapeIdOrName}`);let i=this.presentationValue.slides.getItem(t.slideIdOrIndex).shapes.getItem(t.shapeIdOrName);if(t.kind==="delete-shape")return await i.delete(),{kind:"slide",slideId:n.id};if(t.kind==="bring-shape-to-front")return await i.bringToFront(),{kind:"shape",slideId:n.id,shapeId:r.id};if(t.kind==="send-shape-to-back")return await i.sendToBack(),{kind:"shape",slideId:n.id,shapeId:r.id};let s={left:typeof r.bounds.left=="number"?r.bounds.left+((u=(c=t.offset)==null?void 0:c.left)!=null?u:18e4):r.bounds.left,top:typeof r.bounds.top=="number"?r.bounds.top+((p=(f=t.offset)==null?void 0:f.top)!=null?p:18e4):r.bounds.top,width:(b=(w=t.offset)==null?void 0:w.width)!=null?b:r.bounds.width,height:(h=(g=t.offset)==null?void 0:g.height)!=null?h:r.bounds.height},l=await(await i.duplicate({geometry:s})).toModel();return {kind:"shape",slideId:n.id,shapeId:l.id}}async refreshAfterChange(t){this.modelValue=await this.presentationValue.toModel(),this.sceneValue=io(this.modelValue),this.applyTextBodyOverrides(),this.revisionValue+=1,this.changeListeners.forEach(n=>n({revision:this.revisionValue,command:t,model:this.modelValue,scene:this.sceneValue}));}async replacePresentation(t,n=null){let r=await ppt.Presentation.fromZip(t,{mode:"inline"});if(await this.presentationValue.dispose(),this.presentationValue=r,this.modelValue=await r.toModel(),this.sceneValue=io(this.modelValue),this.applyTextBodyOverrides(),n){let i=this.sceneValue.slides.find(s=>s.id===n.slideId);if(n.kind==="slide"&&i){this.setSelection({kind:"slide",slideId:i.id});return}if(n.kind==="shape"&&(i!=null&&i.nodes.some(s=>s.id===n.shapeId))){this.setSelection({kind:"shape",slideId:i.id,shapeId:n.shapeId});return}}let o=this.sceneValue.slides[0];this.setSelection(o?{kind:"slide",slideId:o.id}:null);}setSelection(t){this.selectionValue=t,this.selectionListeners.forEach(n=>n({selection:t}));}pushUndo(t){this.undoStack.push(this.historyEntry(t)),this.undoStack.length>this.maxHistory&&this.undoStack.shift();}historyEntry(t){return {bytes:t,textBodyOverrides:new Map(this.textBodyOverrides)}}restoreTextBodyOverrides(t){this.textBodyOverrides.clear(),t.forEach((n,r)=>this.textBodyOverrides.set(r,v({},n)));}applyTextBodyOverrides(){var t;for(let[n,r]of this.textBodyOverrides){let[o,i]=n.split("\0");if(!o||!i)continue;let s=tr(this.sceneValue,o),a=s?so(s,i):null;!a||!a.text&&!((t=a.textParagraphs)!=null&&t.length)||(a.textBody=v(v({},a.textBody),r));}}};function VS(e,t){return `${e}\0${t}`}function GS(e){var t;return !!(e.capabilities.editGeometry&&jS(e)&&(e.text||(t=e.textParagraphs)!=null&&t.length))}function jS(e){return e.kind==="placeholder"||e.kind==="textBox"||e.kind==="geometricShape"}function US(e,t){let n=e.source.shapes.find(r=>r.id===t||r.name===t);return n?ao(n,{slideSize:e.size,background:e.background}):null}function KS(e,t){let n=t.split(":").filter(Boolean);if(n.length<=1)return e.getItem(t);let r=e.getItem(n[0]);for(let o of n.slice(1))r=r.group.getItem(o);return r}function _S(e){return e.kind==="delete-shape"||e.kind==="duplicate-shape"||e.kind==="paste-shape"||e.kind==="bring-shape-to-front"||e.kind==="send-shape-to-back"}var jf=24e4,co=91440,qS=91440,dl=4,Uf=7,nr=128,XS=8,Hi=2,YS=2,Oi=4;function iT(e,t,n={}){return new pl(e,t,n)}function ZS(e){if(e.kind==="line"||e.kind!=="geometricShape"||e.customGeometry||e.presetGeometry&&e.presetGeometry!=="ellipse"||e.text||!e.fillColor)return false;let t=Math.min(e.bounds.width,e.bounds.height),n=Math.max(e.bounds.width,e.bounds.height);return t<=0?false:n/t<1.2}function xn(e,t,n){var c,u,f,p;let r=Math.max(co,(c=n.width)!=null?c:e.width),o=Math.max(co,(u=n.height)!=null?u:e.height),i=Math.min(jf,r),s=Math.min(jf,o),a=_i((f=n.left)!=null?f:e.left,-r+i,t.width-i),l=_i((p=n.top)!=null?p:e.top,-o+s,t.height-s);return $(v({},e),{left:a,top:l,width:r,height:o})}function _i(e,t,n){return Math.max(t,Math.min(n,e))}function $i(e,t,n){let r=n==="x"?e.size.width:e.size.height,o=[{value:0,kind:"slide",role:"start"},{value:r/2,kind:"slide",role:"center"},{value:r,kind:"slide",role:"end"}];for(let i of e.nodes){if(!JS(i,t))continue;let s=n==="x"?i.bounds.left:i.bounds.top,a=n==="x"?i.bounds.width:i.bounds.height;o.push({value:s,kind:"shape",role:"start",referenceShapeId:i.id},{value:s+a/2,kind:"shape",role:"center",referenceShapeId:i.id},{value:s+a,kind:"shape",role:"end",referenceShapeId:i.id});}return o}function JS(e,t){return e.id!==t&&e.kind!=="line"&&!e.locked&&!e.id.includes(":")&&e.capabilities.select&&e.capabilities.editGeometry&&e.bounds.width>co&&e.bounds.height>co}function zi(e,t,n,r={}){let o=null;for(let i of e)for(let s of t){if(r.matchRole!==false&&i.role!==s.role)continue;let a=Math.abs(i.value-s.value);a>n||(!o||a<o.distance)&&(o={source:i,target:s,distance:a});}return o}function Kf(e,t,n,r){let o=t/2,i=Math.abs(n.offset-o)<1?(r-e)*2:r-e;return Math.max(co,i)}function Dn(e){return !e.locked&&!e.id.includes(":")&&(e.capabilities.editGeometry||e.capabilities.editText||e.capabilities.editShapeStyle||e.capabilities.editTableCells)}function QS(e){let t=e.groupContext;return t?$(v({},e),{id:t.parentId,name:t.parentName,kind:"group",bounds:t.parentBounds,text:void 0,textStyle:void 0,textParagraphs:void 0,textBody:void 0,groupContext:void 0,locked:false,editable:true,capabilities:{select:true,editText:false,editTextStyle:false,editTableCells:false,editGeometry:true,editShapeStyle:false,reason:"Parent group"},children:[]}):e}function e0(e){var i,s;if(e.kind!=="picture"||!e.customGeometry||e.customGeometry.paths.length!==1)return false;let t=Math.min(e.bounds.width,e.bounds.height),n=Math.max(e.bounds.width,e.bounds.height);if(t<=0||n/t>1.12)return false;let r=(s=(i=e.customGeometry.paths[0])==null?void 0:i.commands)!=null?s:[];return r.filter(a=>a.kind==="cubicBezierTo").length>=4&&r.some(a=>a.kind==="close")}var pl=class{constructor(t,n,r){O(this,"root");O(this,"sessionValue");O(this,"imageResources");O(this,"fontResources");O(this,"referencedFontFamilies");O(this,"slideList",document.createElement("div"));O(this,"canvas",document.createElement("div"));O(this,"contextMenu",document.createElement("div"));O(this,"snapGuides",document.createElement("div"));O(this,"options");O(this,"handleCanvasClick",()=>{this.dispatchCurrentSlideSelection();});O(this,"handleWindowMouseMove",t=>{this.updateDrag(t);});O(this,"handleWindowMouseUp",t=>{this.finishDrag(t);});O(this,"handleWindowKeyDown",t=>{this.handleKeyDown(t);});O(this,"handleWindowPointerDown",t=>{this.dismissContextMenu(t);});O(this,"handleWindowScroll",()=>this.hideContextMenu());O(this,"handleCanvasSelectStart",t=>this.handleSelectStart(t));O(this,"handleSlideListScroll",()=>this.scheduleThumbnailRender());O(this,"dragState",null);O(this,"suppressClickAfterDrag",false);O(this,"clipboardShape",null);O(this,"thumbnailFrame",0);O(this,"thumbnailRasterEpoch",0);O(this,"thumbnailCanvasCache",new Map);O(this,"pendingCommands",new Set);this.options=r,this.root=r.styleIsolation==="none"?t:t.attachShadow({mode:"open"}),this.sessionValue=new Di(n,{readOnly:r.readOnly}),this.imageResources=n.images,this.fontResources=n.fonts,this.referencedFontFamilies=f0(n);let o=p0(this.fontResources,this.referencedFontFamilies);m0(this.scheduleFontRenderRefresh(o)),this.mount(),this.sessionValue.subscribe("change",async i=>{var s,a;this.thumbnailRasterEpoch++,this.render(),await((a=(s=this.options).onChange)==null?void 0:a.call(s,{revision:i.revision,bytes:await this.sessionValue.toPptx()}));}),this.sessionValue.subscribe("selectionChange",()=>this.renderSelection()),this.render();}session(){return this.sessionValue}selection(){return this.sessionValue.selection()}isReadOnly(){return this.sessionValue.isReadOnly()}setReadOnly(t){if(this.isReadOnly()===t)return;let n=this.root.querySelector('[contenteditable="true"]');n==null||n.dispatchEvent(new KeyboardEvent("keydown",{key:"Escape",bubbles:true,cancelable:true})),this.dragState&&(this.restoreDragElementBounds(this.dragState),this.clearDragVisualState(this.dragState.element,true),this.dragState=null,this.hideSnapGuides()),this.hideContextMenu(),this.sessionValue.setReadOnly(t),this.render();}async dispatch(t){let n=this.dispatchAndRender(t);this.pendingCommands.add(n);try{await n;}finally{this.pendingCommands.delete(n);}}async dispatchAndRender(t){var r,o;let n=(r=this.currentSlide())==null?void 0:r.id;if(await this.sessionValue.dispatch(t),t.kind==="select-slide"||t.kind==="select-shape"){if(((o=this.currentSlide())==null?void 0:o.id)!==n){this.render();return}this.renderSelection();return}this.render();}async loadPresentation(t){await this.sessionValue.loadPresentation(t),this.thumbnailCanvasCache.clear(),this.thumbnailRasterEpoch++,this.render();}async toPptx(){var t;return (t=this.root.querySelector('[contenteditable="true"]'))==null||t.dispatchEvent(new FocusEvent("blur")),await Promise.all([...this.pendingCommands]),this.sessionValue.toPptx()}canUndo(){return this.sessionValue.canUndo()}canRedo(){return this.sessionValue.canRedo()}async undo(){await this.sessionValue.undo(),this.render();}async redo(){await this.sessionValue.redo(),this.render();}async destroy(){for(this.canvas.removeEventListener("click",this.handleCanvasClick),this.canvas.removeEventListener("selectstart",this.handleCanvasSelectStart),this.slideList.removeEventListener("scroll",this.handleSlideListScroll),this.thumbnailFrame&&cancelAnimationFrame(this.thumbnailFrame),this.thumbnailRasterEpoch++,window.removeEventListener("mousemove",this.handleWindowMouseMove),window.removeEventListener("mouseup",this.handleWindowMouseUp),window.removeEventListener("keydown",this.handleWindowKeyDown),window.removeEventListener("pointerdown",this.handleWindowPointerDown),window.removeEventListener("scroll",this.handleWindowScroll,true),await this.sessionValue.destroy();this.root.firstChild;)this.root.removeChild(this.root.firstChild);}mount(){let t=document.createElement("style");t.textContent=`
1608
- ${c0(this.fontResources)}
1613
+ `,this.renderRoot.appendChild(o);}t.classList.add("coco-spreadsheet-editor-host"),Object.assign(t.style,{position:"relative",overflow:"hidden"});for(let o of [this.baseCanvas,this.headerCanvas,this.overlayCanvas])Object.assign(o.style,{position:"absolute",inset:"0",display:"block"}),this.renderRoot.appendChild(o);this.unsupportedObjectLayer.className="coco-spreadsheet-unsupported-object-layer",Object.assign(this.unsupportedObjectLayer.style,{position:"absolute",inset:"0",zIndex:"4",overflow:"hidden",pointerEvents:"none"}),this.renderRoot.appendChild(this.unsupportedObjectLayer),this.cellEditorElement.className="coco-spreadsheet-cell-editor",Object.assign(this.cellEditorElement.style,{position:"absolute",zIndex:"20",display:"none",resize:"none",overflow:"hidden",padding:"2px 4px",border:"2px solid #2563eb",outline:"none",font:"13px Arial, sans-serif",lineHeight:"normal",whiteSpace:"pre-wrap",overflowWrap:"break-word"}),this.renderRoot.appendChild(this.cellEditorElement),this.resizeGuide.className="coco-spreadsheet-resize-guide",Object.assign(this.resizeGuide.style,{position:"absolute",zIndex:"25",display:"none",pointerEvents:"none",background:"#2563eb"}),this.renderRoot.appendChild(this.resizeGuide),this.contextMenu.className="coco-spreadsheet-context-menu",Object.assign(this.contextMenu.style,{position:"fixed",zIndex:"50",display:"none",minWidth:"160px",padding:"4px",background:"#ffffff",border:"1px solid #cbd5e1",borderRadius:"6px",boxShadow:"0 8px 24px rgba(15, 23, 42, 0.16)"}),this.renderRoot.appendChild(this.contextMenu),this.filterMenu.className="coco-spreadsheet-filter-menu",Object.assign(this.filterMenu.style,{position:"fixed",zIndex:"60",display:"none",width:"240px",maxHeight:"360px",overflow:"auto",padding:"8px",background:"#ffffff",border:"1px solid #cbd5e1",borderRadius:"6px",boxShadow:"0 8px 24px rgba(15, 23, 42, 0.16)"}),this.renderRoot.appendChild(this.filterMenu),this.cellEditor=new Bi({textarea:this.cellEditorElement,onCommit:async o=>this.commitCellEdit(o),onCancel:()=>{this.editingCell=null,this.editingCellStyle=null,this.formulaReferenceRanges=[],this.render();}}),this.cellEditorElement.addEventListener("input",()=>{this.editingCell&&(this.formulaReferenceRanges=Af(this.cellEditorElement.value),this.render());}),this.configureScrollbar(this.horizontalScrollbar,this.horizontalThumb,true),this.configureScrollbar(this.verticalScrollbar,this.verticalThumb,false),this.renderRoot.append(this.horizontalScrollbar,this.verticalScrollbar),this.sheetTabs.className="coco-spreadsheet-editor-tabs",n.showSheetTabs!==false&&this.renderRoot.appendChild(this.sheetTabs),this.renderer=new Ai({baseCanvas:this.baseCanvas,headerCanvas:this.headerCanvas,overlayCanvas:this.overlayCanvas}),t.addEventListener("wheel",this.handleWheel,{passive:false}),t.addEventListener("click",this.handleClick),t.addEventListener("dblclick",this.handleDoubleClick),t.addEventListener("pointerdown",this.handlePointerDown),t.addEventListener("pointermove",this.handlePointerMove),t.addEventListener("pointerup",this.handlePointerUp),t.addEventListener("pointerleave",this.handlePointerLeave),t.addEventListener("keydown",this.handleKeyDown),t.addEventListener("copy",this.handleCopy),t.addEventListener("paste",this.handlePaste),t.addEventListener("contextmenu",this.handleContextMenu),document.addEventListener("pointerdown",this.handleDocumentPointerDown),this.filterMenu.addEventListener("click",this.handleFilterMenuClick),t.tabIndex=0,this.resizeObserver=new ResizeObserver(()=>this.render()),this.resizeObserver.observe(t);}runtime(){if(!this.runtimeValue)throw new Error("SpreadsheetEditor: workbook is not loaded");return this.runtimeValue}isReadOnly(){return this.readOnlyValue}setReadOnly(t){this.disposed||this.isReadOnly()===t||(this.cellEditor.cancel(),this.resizeDrag=null,this.autoFillDrag=null,this.chartDrag=null,this.selecting=false,this.hideResizeGuide(),this.hideContextMenu(),this.hideFilterMenu(),this.runtime().setReadOnly(t),this.readOnlyValue=t,this.host.setAttribute("aria-readonly",String(t)),this.render());}selection(){return this.selectionState}cellState(t){var i,s,a,l;let n=this.runtime().activeSheet(),r=n.cellsByAddress.get(t);if(!r){let c=t.match(/^([A-Z]+)(\d+)$/i);if(!c)throw new Error(`SpreadsheetEditor: invalid cell address ${t}`);let u=MS(c[1]),f=Number(c[2]);return {address:t.toUpperCase(),row:f,column:u,value:null,displayText:""}}let o=n.styles.cellFormats[(i=r.styleId)!=null?i:0];return {address:r.address,row:r.row,column:r.column,value:r.value,displayText:r.displayText,formula:r.formula,styleId:r.styleId,format:o?{font:n.styles.fonts[(s=o.fontId)!=null?s:0],fill:n.styles.fills[(a=o.fillId)!=null?a:0],border:n.styles.borders[(l=o.borderId)!=null?l:0],alignment:o.alignment,numberFormatCode:o.numberFormatCode}:void 0}}freezeState(){return Ii(this.runtime().activeSheet().source)}filterState(){return new Map([...this.columnFilters.entries()].map(([t,n])=>[t,[...n]]))}activeSheetName(){return this.runtime().activeSheetName()}async setActiveSheet(t){await this.runtime().setActiveSheet(t),this.scroll={x:0,y:0},this.selectionState=gt(1,1),this.render(),this.renderTabs();}async addSheet(t){await this.runtime().addSheet(t),this.scroll={x:0,y:0},this.selectionState=gt(1,1),this.renderTabs(),this.render(),await this.emitChange();}async renameSheet(t,n){await this.runtime().renameSheet(t,n),this.renderTabs(),this.render(),await this.emitChange();}async copySheet(t,n){await this.runtime().copySheet(t,n),this.scroll={x:0,y:0},this.selectionState=gt(1,1),this.renderTabs(),this.render(),await this.emitChange();}async deleteSheet(t){await this.runtime().deleteSheet(t),this.scroll={x:0,y:0},this.selectionState=gt(1,1),this.renderTabs(),this.render(),await this.emitChange();}async moveSheet(t,n){await this.runtime().moveSheet(t,n),this.renderTabs(),this.render(),await this.emitChange();}async setCellValue(t,n){await this.runtime().setCellValue(t,n,{mergeUndo:true}),this.render(),await this.emitChange();}async setCellFormula(t,n){await this.runtime().setCellFormula(t,n,{mergeUndo:true}),this.render(),await this.emitChange();}async formatSelection(t){await this.applyFormat(t);}async setSelectionFontColor(t){let n=We(this.selectionState.range);await this.runtime().setRangeFontColor(n.startRow,n.startColumn,n.endRow-n.startRow+1,n.endColumn-n.startColumn+1,t),this.render(),await this.emitChange();}async setSelectionFillColor(t){let n=We(this.selectionState.range);await this.runtime().setRangeFillColor(n.startRow,n.startColumn,n.endRow-n.startRow+1,n.endColumn-n.startColumn+1,t),this.render(),await this.emitChange();}async setSelectionHorizontalAlign(t){await this.applyAlignment(t);}async setSelectionVerticalAlign(t){let n=We(this.selectionState.range);await this.runtime().setRangeVerticalAlign(n.startRow,n.startColumn,n.endRow-n.startRow+1,n.endColumn-n.startColumn+1,t),this.render(),await this.emitChange();}async setSelectionNumberFormat(t){let n=We(this.selectionState.range);await this.runtime().setRangeNumberFormat(n.startRow,n.startColumn,n.endRow-n.startRow+1,n.endColumn-n.startColumn+1,t),this.render(),await this.emitChange();}async setSelectionBorder(t){let n=We(this.selectionState.range);await this.runtime().setRangeBorder(n.startRow,n.startColumn,n.endRow-n.startRow+1,n.endColumn-n.startColumn+1,t),this.render(),await this.emitChange();}async loadWorkbook(t){this.assertAlive();let n=this.runtimeValue;this.runtimeValue=null,this.scroll={x:0,y:0},n&&await n.dispose(),this.runtimeValue=await Wi.fromZip(t,{workbookId:this.options.workbookId,mode:"inline",readOnly:this.readOnlyValue}),this.host.setAttribute("aria-readonly",String(this.isReadOnly())),this.renderTabs(),this.render();}async toZip(){return this.runtime().toZip()}canUndo(){return this.runtime().canUndo()}canRedo(){return this.runtime().canRedo()}async undo(){await this.runtime().undo(),this.render(),await this.emitChange();}async redo(){await this.runtime().redo(),this.render(),await this.emitChange();}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}subscribeState(t){return this.stateListeners.add(t),()=>this.stateListeners.delete(t)}async runTransaction(t,n){this.transactionDepth+=1;try{await this.runtime().runUserTransaction(t,()=>n(this));}finally{this.transactionDepth-=1,this.transactionDepth===0&&this.transactionChanged&&(this.transactionChanged=false,this.render(),await this.emitChange());}}destroy(){if(this.disposed)return;this.disposed=true,this.resizeObserver.disconnect(),this.host.removeEventListener("wheel",this.handleWheel),this.host.removeEventListener("click",this.handleClick),this.host.removeEventListener("dblclick",this.handleDoubleClick),this.host.removeEventListener("pointerdown",this.handlePointerDown),this.host.removeEventListener("pointermove",this.handlePointerMove),this.host.removeEventListener("pointerup",this.handlePointerUp),this.host.removeEventListener("pointerleave",this.handlePointerLeave),this.host.removeEventListener("keydown",this.handleKeyDown),this.host.removeEventListener("copy",this.handleCopy),this.host.removeEventListener("paste",this.handlePaste),this.host.removeEventListener("contextmenu",this.handleContextMenu),document.removeEventListener("pointerdown",this.handleDocumentPointerDown),this.contextMenu.remove(),this.filterMenu.remove(),this.unsupportedObjectLayer.remove(),this.host.replaceChildren();let t=this.runtimeValue;this.runtimeValue=null,t==null||t.dispose();}render(){var f;let t=this.runtimeValue,n=this.renderer;if(!t||!n||this.disposed)return;let r=this.host.getBoundingClientRect(),o=Math.max(1,r.width),i=Math.max(1,r.height-(this.options.showSheetTabs===false?0:40)),s=new ki(t.activeSheet()),a={width:Math.max(1,o-12),height:Math.max(1,i-12)},l=new Ci(s,{viewportSize:a,scroll:this.scroll,freeze:Ii(t.activeSheet().source)});this.layout=s,this.viewport=l,this.scroll=l.scroll,this.scrollbarState=If(s,a,Ii(t.activeSheet().source),this.scroll),n.resize(o,i);let c=this.options.enableHeaderFilters===true&&!this.isReadOnly();n.setHeaderFiltersEnabled(c),n.setHeaderFilterColumns(c?Array.from({length:s.columnCount},(p,w)=>w+1):null),n.setActiveHeaderFilterColumns(Array.from(this.columnFilters.keys())),n.render(s,l);let u=We(this.selectionState.range);n.renderSelection(s,l,u,{showFillHandle:!this.isReadOnly()&&ol(t.activeSheet(),u)}),this.updateCellEditorPosition(),(f=this.autoFillDrag)!=null&&f.preview&&n.renderDashedRange(s,l,this.autoFillDrag.preview,{stroke:"#16A34A",fill:"rgba(34, 197, 94, 0.08)"});for(let p of this.formulaReferenceRanges)n.renderDashedRange(s,l,p.range,{stroke:p.stroke});this.copiedRange&&n.renderCopiedRange(s,l,this.copiedRange),this.renderUnsupportedChartNotices(s,l),this.emitStateIfChanged(t.activeSheetName()),this.updateScrollbars();}renderUnsupportedChartNotices(t,n){var o,i,s;this.unsupportedObjectLayer.replaceChildren();let r=(o=this.runtimeValue)==null?void 0:o.activeSheet().source;if(!(!r||r.charts.length===0))for(let a=0;a<r.charts.length;a+=1){let l=r.charts[a];if(!l)continue;let c=cl(r.drawings,l),u=((i=this.chartDrag)==null?void 0:i.chartIndex)===a?this.chartDrag.previewRect:Mf(t,c);if(u)for(let f of Rf(u,n)){let p=document.createElement("div");p.className="coco-spreadsheet-unsupported-chart",Object.assign(p.style,{position:"absolute",left:`${f.x}px`,top:`${f.y}px`,width:`${Math.max(1,f.width)}px`,height:`${Math.max(1,f.height)}px`,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:"6px",padding:"12px",boxSizing:"border-box",overflow:"hidden",background:"rgba(248, 250, 252, 0.94)",color:"#475569",textAlign:"center",font:"13px Arial, sans-serif",lineHeight:"1.4",cursor:this.isReadOnly()?"default":((s=this.chartDrag)==null?void 0:s.chartIndex)===a?"grabbing":"move",border:this.selectedChartIndex===a?"2px solid #2563eb":"1px dashed #94a3b8",boxShadow:this.selectedChartIndex===a?"0 0 0 1px rgba(37, 99, 235, 0.18)":"none"});let w=document.createElement("strong");w.textContent=l.title?`\u56FE\u8868\uFF1A${l.title}`:"\u56FE\u8868",w.style.color="#334155";let b=document.createElement("span");b.textContent="\u5F53\u524D\u7F16\u8F91\u5668\u6682\u4E0D\u652F\u6301\u56FE\u8868\u6E32\u67D3";let g=document.createElement("span");g.textContent="\u8BF7\u4F7F\u7528 Excel \u6216 WPS \u6253\u5F00\u6587\u4EF6\u67E5\u770B",p.append(w,b,g),this.unsupportedObjectLayer.appendChild(p);}}}chartAnchorAtIndex(t){var o;let n=(o=this.runtimeValue)==null?void 0:o.activeSheet().source,r=n==null?void 0:n.charts[t];return r?cl(n.drawings,r):void 0}chartAtPoint(t){var r;let n=(r=this.runtimeValue)==null?void 0:r.activeSheet().source;if(!n||!this.layout||!this.viewport)return null;for(let o=n.charts.length-1;o>=0;o-=1){let i=n.charts[o];if(!i)continue;let s=cl(n.drawings,i),a=Mf(this.layout,s);if(a&&Rf(a,this.viewport).some(l=>Pf(l,t)))return {chartIndex:o,logicalRect:a}}return null}updateResizeGuide(t){t.kind==="column"?Object.assign(this.resizeGuide.style,{display:"block",left:`${Math.round(t.currentGuidePosition)}px`,top:"0",bottom:"0",width:"2px",height:""}):Object.assign(this.resizeGuide.style,{display:"block",left:"0",top:`${Math.round(t.currentGuidePosition)}px`,right:"0",height:"2px",width:""});}hideResizeGuide(){this.resizeGuide.style.display="none";}renderContextMenu(t,n,r){let o=this.isReadOnly()?[{label:"Copy",action:()=>this.copySelection()}]:[{label:"Undo",disabled:!this.canUndo(),action:()=>this.undo()},{label:"Redo",disabled:!this.canRedo(),action:()=>this.redo()},{label:"Copy",action:()=>this.copySelection()},{label:"Paste",action:()=>this.pasteFromClipboard()},{label:"Clear cells",action:()=>this.clearSelection()},{label:"Clear format",action:()=>this.clearSelectionFormat()},{label:"Bold",action:()=>this.applyFormat("bold")},{label:"Italic",action:()=>this.applyFormat("italic")},{label:"Underline",action:()=>this.applyFormat("underline")},{label:"Align left",action:()=>this.applyAlignment("left")},{label:"Align center",action:()=>this.applyAlignment("center")},{label:"Align right",action:()=>this.applyAlignment("right")},{label:"Merge cells",action:()=>this.mergeSelection()},{label:"Unmerge cells",action:()=>this.unmergeSelection()},{label:"Freeze above and left",action:()=>this.freezeSelection()}];r!==void 0&&(o.unshift({label:"Filter column",action:()=>this.openFilterMenu(r,t,n)}),o.splice(1,0,{label:"Sort A-Z",action:()=>this.sortColumn(r,"asc")},{label:"Sort Z-A",action:()=>this.sortColumn(r,"desc")})),this.contextMenu.replaceChildren();for(let i of o){let s=document.createElement("button");s.type="button",s.textContent=i.label,s.disabled=i.disabled===true,Object.assign(s.style,{display:"block",width:"100%",padding:"6px 10px",border:"0",background:"transparent",textAlign:"left",cursor:s.disabled?"default":"pointer"}),s.addEventListener("mouseenter",()=>{s.disabled||(s.style.background="#eff6ff");}),s.addEventListener("mouseleave",()=>{s.style.background="transparent";}),s.addEventListener("click",()=>{this.hideContextMenu(),i.action();}),this.contextMenu.appendChild(s);}Object.assign(this.contextMenu.style,{left:`${t}px`,top:`${n}px`,display:"block"});}openFilterMenu(t,n,r){var c;if(this.filterMenu.style.display==="block"&&this.filterMenuColumn===t){this.hideFilterMenu();return}let o=this.runtime().activeSheet(),i={startRow:1,endRow:o.maxRow,endColumn:o.maxColumn},s=new Set((c=this.columnFilters.get(t))!=null?c:al(o,i,t));this.filterMenuColumn=t,this.filterMenu.replaceChildren();let a=document.createElement("strong");a.textContent=`Filter ${t}`,a.style.display="block",a.style.marginBottom="6px",this.filterMenu.appendChild(a);for(let u of al(o,i,t)){let f=document.createElement("label");f.style.display="block",f.style.padding="3px 0";let p=document.createElement("input");p.type="checkbox",p.checked=s.has(u),p.dataset.filterValue=u,p.style.marginRight="8px",f.append(p,u===""?"(blank)":u),this.filterMenu.appendChild(f);}let l=document.createElement("div");l.style.display="flex",l.style.gap="6px",l.style.marginTop="8px";for(let[u,f]of [["Apply","apply"],["Clear filter","clear"],["Cancel","cancel"]]){let p=document.createElement("button");p.type="button",p.textContent=u,p.dataset.filterAction=f,l.appendChild(p);}this.filterMenu.appendChild(l),Object.assign(this.filterMenu.style,{left:`${n}px`,top:`${r}px`,display:"block"});}hideFilterMenu(){this.filterMenu.style.display="none",this.filterMenuColumn=null;}isFilterIconHit(t,n){if(!this.layout||!this.viewport)return false;let r=this.eventPoint(n),o=this.viewport.findViewport(r);if(!o)return false;let i=this.viewport.cellScreenRect(1,t,o);return i.width>=28&&r.x>=i.x+i.width-22&&r.x<=i.x+i.width}async applyColumnFilters(){let t=this.runtime().activeSheet(),n=Array.from(this.columnFilters.entries()).filter(([,r])=>r.length>0).map(([r,o])=>({column:r,values:o}));await this.runtime().filterRowsByColumns(1,t.maxRow,n),this.render(),await this.emitChange();}async sortColumn(t,n){let r=this.runtime().activeSheet();await this.runtime().sortRows(1,r.maxRow,t,n),this.render(),await this.emitChange();}async sortActiveColumn(t){await this.sortColumn(this.selectionState.active.column,t);}async filterColumn(t,n){this.assertWritable(),n===null?this.columnFilters.delete(t):this.columnFilters.set(t,[...n]),await this.applyColumnFilters();}hideContextMenu(){this.contextMenu.style.display="none";}selectionContainsCell(t,n){let r=We(this.selectionState.range);return t>=r.startRow&&t<=r.endRow&&n>=r.startColumn&&n<=r.endColumn}async copySelection(){let t=el(this.runtime().activeSheet(),We(this.selectionState.range));this.clipboardPayload=t;try{await navigator.clipboard.writeText(t.text);}catch(n){}}async pasteFromClipboard(){var r;let t="";try{t=await navigator.clipboard.readText();}catch(o){return}if(!t)return;let n=new ClipboardEvent("paste",{clipboardData:new DataTransfer});(r=n.clipboardData)==null||r.setData("text/plain",t),this.handlePaste(n);}async clearSelection(){let t=We(this.selectionState.range);await this.runtime().clearRange(t.startRow,t.startColumn,t.endRow-t.startRow+1,t.endColumn-t.startColumn+1),this.render(),await this.emitChange();}async clearSelectionFormat(){let t=We(this.selectionState.range);await this.runtime().clearRangeFormat(t.startRow,t.startColumn,t.endRow-t.startRow+1,t.endColumn-t.startColumn+1),this.render(),await this.emitChange();}async applyFormat(t){let n=We(this.selectionState.range),r=n.endRow-n.startRow+1,o=n.endColumn-n.startColumn+1;t==="bold"&&await this.runtime().setRangeBold(n.startRow,n.startColumn,r,o,true),t==="italic"&&await this.runtime().setRangeItalic(n.startRow,n.startColumn,r,o,true),t==="underline"&&await this.runtime().setRangeUnderline(n.startRow,n.startColumn,r,o,true),this.render(),await this.emitChange();}async applyAlignment(t){let n=We(this.selectionState.range);await this.runtime().setRangeHorizontalAlign(n.startRow,n.startColumn,n.endRow-n.startRow+1,n.endColumn-n.startColumn+1,t),this.render(),await this.emitChange();}async mergeSelection(){let t=We(this.selectionState.range);t.startRow===t.endRow&&t.startColumn===t.endColumn||(await this.runtime().mergeRange(t.startRow,t.startColumn,t.endRow-t.startRow+1,t.endColumn-t.startColumn+1),this.selectionState=_t(this.selectionState,this.runtime().activeSheet()),this.render(),await this.emitChange());}async unmergeSelection(){let t=We(this.selectionState.range),n=[...this.runtime().activeSheet().mergeMasterByAddress.values()].filter(r=>AS(t,r.range)).map(r=>r.address);n.length!==0&&(await this.runtime().unmergeRanges(n),this.render(),await this.emitChange());}async freezeSelection(){let t=this.selectionState.active;await this.runtime().setFreezePanes(Math.max(0,t.row-1),Math.max(0,t.column-1)),this.render(),await this.emitChange();}async commitResizeDrag(t){if(t.currentSize===t.startSize){this.render();return}t.kind==="column"?await this.runtime().setColumnWidth(t.index,t.currentSize):await this.runtime().setRowHeight(t.index,t.currentSize*72/96),this.render(),await this.emitChange();}openCellEditor(){var f,p;if(this.isReadOnly()||!this.layout||!this.viewport)return;let t=this.selectionState.active,n=this.viewport.findViewport({x:this.layout.rowHeaderWidth+1,y:this.layout.columnHeaderHeight+1}),r=qe(this.runtime().activeSheet(),t.row,t.column),o=Ti(this.runtime().activeSheet().styles,r==null?void 0:r.styleId,r);Object.assign(this.cellEditorElement.style,{font:o.font,color:o.fontColor,textDecoration:o.underline?"underline":"none",textAlign:o.horizontalAlign});let i=(f=this.viewport.viewports.find(w=>w.kind==="main"))!=null?f:n;if(!i)return;let s=We(this.selectionState.range),a=this.viewport.cellScreenRect(s.startRow,s.startColumn,i),l=this.viewport.cellScreenRect(s.endRow,s.endColumn,i),c={x:a.x,y:a.y,width:l.x+l.width-a.x,height:l.y+l.height-a.y};this.editingCell=t,this.editingCellStyle=o;let u=r!=null&&r.formula?`=${r.formula}`:(p=r==null?void 0:r.displayText)!=null?p:"";this.formulaReferenceRanges=Af(u),this.cellEditor.open(c,u),this.alignCellEditor(c,o),this.render();}async commitCellEdit(t){let n=this.editingCell;if(this.editingCell=null,this.editingCellStyle=null,this.formulaReferenceRanges=[],!n)return;this.assertWritable();let r=excel.formatCellAddress(n.row,n.column);t.startsWith("=")?await this.runtime().setCellFormula(r,t.slice(1),{mergeUndo:true}):await this.runtime().setCellValue(r,NS(t),{mergeUndo:true}),this.render(),await this.emitChange();}eventPoint(t){let n=this.host.getBoundingClientRect();return {x:t.clientX-n.left,y:t.clientY-n.top}}assertWritable(){if(this.isReadOnly())throw new dn("spreadsheet")}eventPathContains(t,n){return t.composedPath().includes(n)}updateCellEditorPosition(){let t=this.editingCell,n=this.layout,r=this.viewport;if(!t||!n||!r)return;let o=r.viewports.find(c=>c.kind!=="columnHeaderFrozen"&&c.kind!=="columnHeaderScrollable"&&c.kind!=="rowHeaderFrozen"&&c.kind!=="rowHeaderScrollable"&&t.row>=c.rows.start&&t.row<=c.rows.end&&t.column>=c.columns.start&&t.column<=c.columns.end);if(!o){this.cellEditorElement.style.display="none";return}let i=We(this.selectionState.range),s=r.cellScreenRect(i.startRow,i.startColumn,o),a=r.cellScreenRect(i.endRow,i.endColumn,o),l={x:s.x,y:s.y,width:a.x+a.width-s.x,height:a.y+a.height-s.y};this.cellEditorElement.style.left=`${l.x}px`,this.cellEditorElement.style.top=`${l.y}px`,this.cellEditorElement.style.width=`${Math.max(1,l.width)}px`,this.cellEditorElement.style.height=`${Math.max(1,l.height)}px`,this.cellEditorElement.style.display="block",this.editingCellStyle&&this.alignCellEditor(l,this.editingCellStyle);}alignCellEditor(t,n){let r=this.cellEditorElement,o=4,i=2;r.style.padding=`${i}px ${o}px`;let s=Math.max(0,t.height-r.scrollHeight),a=n.verticalAlign==="bottom"?i+s:n.verticalAlign==="middle"?i+s/2:i;r.style.paddingTop=`${a}px`;}async emitChange(){var n,r;if(this.transactionDepth>0){this.transactionChanged=true;return}let t={kind:"workbookChange",bytes:await this.toZip()};for(let o of this.listeners)o(t);await((r=(n=this.options).onChange)==null?void 0:r.call(n,t));}emitStateIfChanged(t){var s,a,l,c;let n=this.selectionState,r=`${n.kind}:${n.active.row}:${n.active.column}:${n.range.startRow}:${n.range.startColumn}:${n.range.endRow}:${n.range.endColumn}:${(a=(s=this.editingCell)==null?void 0:s.row)!=null?a:0}:${(c=(l=this.editingCell)==null?void 0:l.column)!=null?c:0}`,o=`${t}|${r}`;if(o===this.lastStateKey)return;this.lastStateKey=o;let i={kind:"stateChange",activeSheetName:t,selection:n,editingCell:this.editingCell};for(let u of this.stateListeners)u(i);}renderTabs(){if(!(this.options.showSheetTabs===false||!this.runtimeValue)){this.sheetTabs.replaceChildren(),Object.assign(this.sheetTabs.style,{position:"absolute",left:"0",right:"0",bottom:"0",height:"40px",display:"flex",alignItems:"center",gap:"8px",padding:"0 12px",background:"#eef1f5",borderTop:"1px solid #e2e8f0",boxSizing:"border-box",overflowX:"auto",overflowY:"hidden"});for(let t of this.runtimeValue.model().sheets){let n=document.createElement("button");n.type="button",n.textContent=t.name,n.dataset.active=String(t.name===this.runtimeValue.activeSheetName()),Object.assign(n.style,{height:"32px",minWidth:"64px",padding:"0 14px",border:"0",borderTop:t.name===this.runtimeValue.activeSheetName()?"2px solid #2563eb":"2px solid transparent",borderRadius:"3px 3px 0 0",background:t.name===this.runtimeValue.activeSheetName()?"#ffffff":"transparent",color:t.name===this.runtimeValue.activeSheetName()?"#1d4ed8":"#475569",font:"13px Arial, sans-serif",fontWeight:t.name===this.runtimeValue.activeSheetName()?"600":"400",cursor:"pointer",whiteSpace:"nowrap"}),n.addEventListener("mouseenter",()=>{n.dataset.active!=="true"&&(n.style.background="#e2e8f0");}),n.addEventListener("mouseleave",()=>{n.dataset.active!=="true"&&(n.style.background="transparent");}),n.addEventListener("click",()=>{this.setActiveSheet(t.name);}),this.sheetTabs.appendChild(n);}}}configureScrollbar(t,n,r){t.className="coco-spreadsheet-editor-scrollbar",Object.assign(t.style,v({position:"absolute",zIndex:"10",background:"#f1f5f9",border:"1px solid #cbd5e1",cursor:"pointer"},r?{left:"48px",bottom:"40px",height:"12px"}:{top:"24px",right:"0",bottom:"52px",width:"12px"})),n.className="coco-spreadsheet-editor-scrollbar-thumb",Object.assign(n.style,{position:"absolute",background:"#94a3b8",borderRadius:"999px"}),t.appendChild(n),t.addEventListener("pointerdown",o=>{var l;let i=(l=this.scrollbarState)==null?void 0:l[r?"horizontal":"vertical"];if(!i||i.maxScroll<=0)return;let s=t.getBoundingClientRect(),a=r?o.clientX-s.left:o.clientY-s.top;this.drag={axis:r?"horizontal":"vertical",pointer:a,thumb:i.thumbStart},t.setPointerCapture(o.pointerId),this.setScroll(r?Di(i,a-i.thumbLength/2):this.scroll.x,r?this.scroll.y:Di(i,a-i.thumbLength/2));}),t.addEventListener("pointermove",o=>{var u;let i=this.drag,s=(u=this.scrollbarState)==null?void 0:u[r?"horizontal":"vertical"];if(!i||!s||i.axis!==(r?"horizontal":"vertical"))return;let a=t.getBoundingClientRect(),l=r?o.clientX-a.left:o.clientY-a.top,c=Di(s,i.thumb+l-i.pointer);this.setScroll(r?c:this.scroll.x,r?this.scroll.y:c);}),t.addEventListener("pointerup",()=>{this.drag=null;});}updateScrollbars(){let t=this.scrollbarState,n=this.layout,r=this.viewport;if(!t||!n||!r)return;let o=t.horizontal,i=t.vertical;this.horizontalScrollbar.style.display=o.maxScroll>0?"block":"none",this.verticalScrollbar.style.display=i.maxScroll>0?"block":"none",Object.assign(this.horizontalScrollbar.style,{left:`${n.rowHeaderWidth+n.getColumnX(r.freeze.frozenColumns+1)}px`,width:`${o.trackLength}px`}),Object.assign(this.horizontalThumb.style,{left:`${o.thumbStart}px`,width:`${o.thumbLength}px`,top:"1px",bottom:"1px"}),Object.assign(this.verticalScrollbar.style,{top:`${n.columnHeaderHeight+n.getRowY(r.freeze.frozenRows+1)}px`,height:`${i.trackLength}px`}),Object.assign(this.verticalThumb.style,{top:`${i.thumbStart}px`,height:`${i.thumbLength}px`,left:"1px",right:"1px"});}setScroll(t,n){this.scroll={x:t,y:n},this.render();}assertAlive(){if(this.disposed)throw new Error("SpreadsheetEditor: editor has been destroyed")}};function NS(e){if(e==="")return null;if(e==="TRUE")return true;if(e==="FALSE")return false;let t=Number(e);return Number.isFinite(t)&&e.trim()!==""?t:e}function Pf(e,t){return t.x>=e.x&&t.y>=e.y&&t.x<=e.x+e.width&&t.y<=e.y+e.height}function cl(e,t){var o;let n=e.find(i=>i.path===t.drawingPath);return ((o=n==null?void 0:n.anchors)!=null?o:e.flatMap(i=>i.anchors)).find(i=>{var s;return ((s=i.object)==null?void 0:s.kind)==="chart"&&(!t.relationshipId||i.object.relationshipId===t.relationshipId)})}function Mf(e,t){var u,f;if(!t||t.kind==="absolute"||!t.from)return null;let n=Fi(t.from.column),r=Fi(t.from.row),o=t.to?Fi(t.to.column):n+5,i=t.to?Fi(t.to.row):r+12,s=e.getColumnX(n)+Hi(t.from.columnOffset),a=e.getRowY(r)+Hi(t.from.rowOffset),l=e.getColumnX(o)+Hi((u=t.to)==null?void 0:u.columnOffset),c=e.getRowY(i)+Hi((f=t.to)==null?void 0:f.rowOffset);return {x:s,y:a,width:Math.max(1,l-s),height:Math.max(1,c-a)}}function Rf(e,t){let n=[];for(let r of t.viewports){if(!PS(r))continue;let o=r.originX,i=r.originY,s=r.originX+r.screenRect.width,a=r.originY+r.screenRect.height,l=Math.max(e.x,o),c=Math.max(e.y,i),u=Math.min(e.x+e.width,s),f=Math.min(e.y+e.height,a);u<=l||f<=c||n.push({x:r.screenRect.x+l-r.originX,y:r.screenRect.y+c-r.originY,width:u-l,height:f-c});}return n}function TS(e,t,n){let r=(s,a)=>{let l=e.columnAt(Math.max(0,s)),c=e.rowAt(Math.max(0,a));return {column:l-1,row:c-1,columnOffset:Math.round((s-e.getColumnX(l))*9525),rowOffset:Math.round((a-e.getRowY(c))*9525)}},o=r(t.x,t.y),i=n.to?r(t.x+t.width,t.y+t.height):void 0;return {from:o,to:i}}function PS(e){return e.kind==="main"||e.kind==="frozenTop"||e.kind==="frozenLeft"||e.kind==="frozenTopLeft"}function Fi(e){return Math.max(1,Math.floor(e!=null?e:0)+1)}function Hi(e){return Number.isFinite(e)?(e!=null?e:0)/9525:0}function MS(e){let t=0;for(let n of e.toUpperCase())t=t*26+n.charCodeAt(0)-64;return t}function RS(e,t){if(t.kind!=="cell")return null;let n=Math.max(0,t.row-e.endRow),r=Math.max(0,t.column-e.endColumn);return !n&&!r?null:n>=r?$(v({},e),{endRow:e.endRow+n}):$(v({},e),{endColumn:e.endColumn+r})}function AS(e,t){return !(e.endRow<t.startRow||e.startRow>t.endRow||e.endColumn<t.startColumn||e.startColumn>t.endColumn)}function Af(e){var r;if(!e.startsWith("="))return [];let t=(r=e.match(/(?:\$?[A-Z]{1,3}\$?\d+)(?::(?:\$?[A-Z]{1,3}\$?\d+))?/g))!=null?r:[],n=["#DC2626","#16A34A","#7C3AED","#EA580C","#0891B2"];return t.flatMap((o,i)=>{var f,p,w;let s=o.split(":"),a=(f=s[0])!=null?f:"",l=(p=s[1])!=null?p:a,c=Lf(a),u=Lf(l);return !c||!u?[]:[{range:We({startRow:c.row,startColumn:c.column,endRow:u.row,endColumn:u.column}),stroke:(w=n[i%n.length])!=null?w:"#DC2626"}]})}function Lf(e){var o,i;let t=e.replace(/\$/g,"").match(/^([A-Z]{1,3})(\d+)$/);if(!t)return null;let n=0;for(let s of (o=t[1])!=null?o:"")n=n*26+s.charCodeAt(0)-64;let r=Number((i=t[2])!=null?i:"");return Number.isFinite(r)&&r>0&&n>0?{row:r,column:n}:null}var WS={width:9144e3,height:5143500},$i=new Set(["placeholder","textBox","geometricShape","line"]),Ff=new WeakMap;function lo(e){var n;let t=(n=e.slideSize)!=null?n:WS;return {size:t,slides:e.slides.map(r=>BS(r,t))}}function BS(e,t){var l,c,u,f,p,w,b,g,h,y;let n=(c=(l=e.layout)==null?void 0:l.shapes)!=null?c:[],o=[...[...((p=(f=(u=e.layout)==null?void 0:u.master)==null?void 0:f.shapes)!=null?p:[]).map(k=>pl(k,"master")),...n.map(k=>pl(k,"layout"))].filter(FS),...e.shapes.map(k=>OS(k,e.layout))],i=o.flatMap(Hf),s=(y=(b=e.background)!=null?b:(w=e.layout)==null?void 0:w.background)!=null?y:(h=(g=e.layout)==null?void 0:g.master)==null?void 0:h.background,a=s!=null?s:DS(o,t);return $(v({id:e.id,index:e.index,name:e.name,title:e.title,size:t},s?{background:s}:{}),{nodes:i.map((k,C)=>co(k,{slideSize:t,index:C,background:s,backgroundFill:a})),groups:o.flatMap(k=>Of(k,{background:s,backgroundFill:a})),source:e})}function DS(e,t){var r;let n=e.find(o=>{var s;let i=so(o.geometry);return o.kind==="picture"&&!!((s=o.image)!=null&&s.targetPath)&&i.left<=t.width*.02&&i.top<=t.height*.02&&i.width>=t.width*.96&&i.height>=t.height*.96});return (r=n==null?void 0:n.image)!=null&&r.targetPath?{imagePath:n.image.targetPath}:void 0}function pl(e,t){var n;return $(v({},e),{id:`${t}:${e.id}`,children:(n=e.children)==null?void 0:n.map(r=>pl(r,t))})}function FS(e){return e.placeholder?false:e.kind==="group"||e.kind==="picture"||e.kind==="geometricShape"||e.kind==="line"||e.kind==="textBox"}function Hf(e){var t;return e.kind!=="group"?[e]:((t=e.children)!=null?t:[]).flatMap(n=>Hf($f(e,n)))}function Of(e,t={}){var n;return e.kind!=="group"?[]:[co(e,{background:t.background,backgroundFill:t.backgroundFill}),...((n=e.children)!=null?n:[]).map(r=>$f(e,r)).flatMap(r=>Of(r,t))]}function $f(e,t){var N,L,F,W,V;let n=so(e.geometry),r=(N=e.raw)==null?void 0:N.groupTransform,o=so(t.geometry),i=(L=r==null?void 0:r.childLeft)!=null?L:n.left,s=(F=r==null?void 0:r.childTop)!=null?F:n.top,a=(r==null?void 0:r.childWidth)||n.width||1,l=(r==null?void 0:r.childHeight)||n.height||1,c=n.width/a,u=n.height/l,f=(o.left-i)*c,p=(o.top-s)*u,w=o.width*c,b=o.height*u,g=n.flipHorizontal?n.left+n.width-f-w:n.left+f,h=n.flipVertical?n.top+n.height-p-b:n.top+p,y=HS({left:g,top:h,width:w,height:b},n),k=zf(((W=n.rotation)!=null?W:0)+((V=o.rotation)!=null?V:0)),C=$(v({},t),{id:`${e.id}:${t.id}`,geometry:$(v({},t.geometry),{left:y.left,top:y.top,width:w,height:b,rotation:k,flipHorizontal:!!n.flipHorizontal!=!!o.flipHorizontal,flipVertical:!!n.flipVertical!=!!o.flipVertical}),children:t.children});return Ff.set(C,{parentId:e.id,parentName:e.name,parentBounds:n,parentTransform:{childLeft:i,childTop:s,childWidth:a,childHeight:l}}),C}function HS(e,t){if(!t.rotation)return e;let n=t.rotation*Math.PI/180,r=t.left+t.width/2,o=t.top+t.height/2,i=e.left+e.width/2,s=e.top+e.height/2,a=i-r,l=s-o,c=r+a*Math.cos(n)-l*Math.sin(n),u=o+a*Math.sin(n)+l*Math.cos(n);return $(v({},e),{left:c-e.width/2,top:u-e.height/2})}function zf(e){let t=(e%360+360)%360;return t===0?void 0:t}function OS(e,t){if(!e.placeholder)return e;let n=ppt.resolvePptEffectivePlaceholderProperties(e,t);return v($(v({},e),{placeholder:n.placeholder,geometry:n.geometry,style:n.style}),e.text?{text:$(v({},e.text),{style:n.textStyle,body:n.textBody})}:{})}function co(e,t={}){var c,u,f,p,w,b,g,h,y,k,C,N,L,F,W,V,ee;let n=Vf(e),r=n.editText||n.editTextStyle||n.editTableCells||n.editGeometry||n.editShapeStyle,o=e.style,i=((c=e.raw)==null?void 0:c.useBackgroundFill)===true,s=i?void 0:(f=(u=e.style)==null?void 0:u.fillColor)!=null?f:VS(e,t),a=GS((p=e.text)==null?void 0:p.style,{fillColor:s,background:t.background}),l=so(e.geometry);return $(v({id:e.id,name:e.name,kind:e.kind,bounds:zS(e,l),text:(b=(w=e.text)==null?void 0:w.text)!=null?b:$S(e),textStyle:a,textParagraphs:(g=e.text)==null?void 0:g.paragraphs,textBody:(h=e.text)==null?void 0:h.body,imagePath:(y=e.image)==null?void 0:y.targetPath,imageCrop:(k=e.image)==null?void 0:k.crop,imageFillRect:(C=e.image)==null?void 0:C.fillRect,imageOpacity:(N=e.image)==null?void 0:N.opacity,chart:e.chart,table:e.table,fillColor:s,fillGradient:i||o==null?void 0:o.fillGradient,opacity:o==null?void 0:o.opacity,lineColor:o==null?void 0:o.lineColor,lineGradient:o==null?void 0:o.lineGradient,lineOpacity:o==null?void 0:o.lineOpacity,lineWidth:o==null?void 0:o.lineWidth,lineCap:o==null?void 0:o.lineCap,lineDash:o==null?void 0:o.lineDash,lineHeadEnd:o==null?void 0:o.lineHeadEnd,lineTailEnd:o==null?void 0:o.lineTailEnd,shadow:o==null?void 0:o.shadow,presetGeometry:(L=e.raw)==null?void 0:L.presetGeometry,presetAdjustments:(F=e.raw)==null?void 0:F.presetAdjustments,customGeometry:(W=e.raw)==null?void 0:W.customGeometry,threeD:(V=e.raw)==null?void 0:V.threeD,usesBackgroundFill:i},i&&t.backgroundFill?{backgroundFill:t.backgroundFill}:{}),{locked:!r,editable:r,capabilities:n,groupContext:qS(e),source:e,children:((ee=e.children)!=null?ee:[]).map(pe=>co(pe,{background:t.background,backgroundFill:t.backgroundFill}))})}function $S(e){if(e.table)return e.table.values.map(t=>t.join(" ")).join(`
1614
+ `)}function zS(e,t){if(!e.table)return t;let n=Wf(e.table.columnWidths),r=Wf(e.table.rowHeights);return n===void 0&&r===void 0?t:v(v(v({},t),Bf(t.width,n)?{width:n}:{}),Bf(t.height,r)?{height:r}:{})}function Wf(e){if(!(e!=null&&e.length))return;let t=e.reduce((n,r)=>n+r,0);return Number.isFinite(t)&&t>0?t:void 0}function Bf(e,t){return t===void 0?false:!Number.isFinite(e)||e<=0?true:t/e>1.15}function VS(e,t){var o;let n=so(e.geometry),r=t.slideSize;if(t.index===0&&e.kind==="geometricShape"&&!((o=e.text)!=null&&o.text)&&r&&n.left<=0&&n.top<=0&&n.width>=r.width*.95&&n.height>=r.height*.95)return "#1D3F80"}function GS(e,t){var r,o;if(e!=null&&e.color)return e;let n=(o=t.fillColor)!=null?o:(r=t.background)==null?void 0:r.fillColor;return !n||!jS(n)?e:$(v({},e),{color:"#FFFFFF"})}function jS(e){let t=/^#?([0-9a-f]{6})$/i.exec(e);if(!t)return false;let n=t[1],r=Number.parseInt(n.slice(0,2),16),o=Number.parseInt(n.slice(2,4),16),i=Number.parseInt(n.slice(4,6),16);return (.2126*r+.7152*o+.0722*i)/255<.45}function tT(e){let t=Vf(e);return t.editText||t.editTextStyle||t.editTableCells||t.editGeometry||t.editShapeStyle}function Vf(e){if(KS(e))return {select:true,editText:false,editTextStyle:false,editTableCells:false,editGeometry:false,editShapeStyle:false,reason:"Inherited from layout/master",reasons:Df("\u7EE7\u627F\u81EA\u6BCD\u7248/\u7248\u5F0F\uFF0C\u5F53\u524D\u53EA\u652F\u6301\u67E5\u770B")};if(_S(e)){let n=!!e.text&&$i.has(e.kind),r=e.kind==="table"&&!!e.table;return {select:true,editText:n,editTextStyle:n,editTableCells:r,editGeometry:true,editShapeStyle:false,reason:"Flattened group child",reasons:ao({editText:n?void 0:Oi(e),editTextStyle:n?void 0:Oi(e),editTableCells:r?void 0:"\u5F53\u524D\u5BF9\u8C61\u4E0D\u662F\u8868\u683C",editShapeStyle:"\u7EC4\u5185\u5B50\u5BF9\u8C61\u6682\u4E0D\u652F\u6301\u8BE5\u9879\u76F4\u63A5\u7F16\u8F91"})}}if(e.kind==="table")return {select:true,editText:false,editTextStyle:false,editTableCells:true,editGeometry:true,editShapeStyle:true,reasons:ao({editText:"\u8868\u683C\u6587\u5B57\u8BF7\u4F7F\u7528\u5355\u5143\u683C\u7F16\u8F91",editTextStyle:"\u8868\u683C\u6587\u5B57\u6837\u5F0F\u5F53\u524D\u4E0D\u5728\u9AD8\u9891\u5DE5\u5177\u680F\u5F00\u653E"})};if(e.kind==="picture")return {select:true,editText:false,editTextStyle:false,editTableCells:false,editGeometry:true,editShapeStyle:true,reasons:ao({editText:"\u56FE\u7247\u5BF9\u8C61\u6CA1\u6709\u53EF\u7F16\u8F91\u6587\u5B57",editTextStyle:"\u56FE\u7247\u5BF9\u8C61\u6CA1\u6709\u53EF\u7F16\u8F91\u6587\u5B57\u6837\u5F0F",editTableCells:"\u5F53\u524D\u5BF9\u8C61\u4E0D\u662F\u8868\u683C"})};if(e.kind==="chart"||e.kind==="smartArt"||e.kind==="group"){let n=US(e.kind);return {select:true,editText:false,editTextStyle:false,editTableCells:false,editGeometry:true,editShapeStyle:false,reason:"Limited editor support for this object type",reasons:ao({editText:n.text,editTextStyle:n.textStyle,editTableCells:"\u5F53\u524D\u5BF9\u8C61\u4E0D\u662F\u8868\u683C",editShapeStyle:n.shapeStyle})}}let t=!!e.text&&$i.has(e.kind);return $i.has(e.kind)?{select:true,editText:t,editTextStyle:t,editTableCells:false,editGeometry:true,editShapeStyle:true,reasons:ao({editText:t?void 0:Oi(e),editTextStyle:t?void 0:Oi(e),editTableCells:"\u5F53\u524D\u5BF9\u8C61\u4E0D\u662F\u8868\u683C"})}:{select:true,editText:false,editTextStyle:false,editTableCells:false,editGeometry:false,editShapeStyle:false,reason:"Unsupported object type",reasons:Df("\u5F53\u524D\u5BF9\u8C61\u7C7B\u578B\u6682\u4E0D\u652F\u6301\u5E38\u89C4\u7F16\u8F91")}}function ao(e){return Object.fromEntries(Object.entries(e).filter(t=>!!t[1]))}function Df(e){return {editText:e,editTextStyle:e,editTableCells:e,editGeometry:e,editShapeStyle:e}}function Oi(e){return e.text?$i.has(e.kind)?"\u5F53\u524D\u5BF9\u8C61\u6587\u5B57\u6682\u4E0D\u652F\u6301\u7F16\u8F91":"\u5F53\u524D\u5BF9\u8C61\u7C7B\u578B\u6682\u4E0D\u652F\u6301\u6587\u5B57\u7F16\u8F91":"\u5F53\u524D\u5BF9\u8C61\u6CA1\u6709\u53EF\u7F16\u8F91\u6587\u5B57\u5185\u5BB9"}function US(e){return e==="chart"?{text:"\u56FE\u8868\u6587\u5B57\u7ED1\u5B9A\u5728\u56FE\u8868\u6570\u636E\u4E2D\uFF0C\u5F53\u524D\u4EC5\u5F00\u653E\u6574\u4F53\u4F4D\u7F6E\u5C3A\u5BF8",textStyle:"\u56FE\u8868\u5185\u90E8\u6587\u5B57\u6837\u5F0F\u6682\u672A\u5F00\u653E",shapeStyle:"\u56FE\u8868\u5F62\u72B6\u6837\u5F0F\u6682\u672A\u5F00\u653E"}:e==="smartArt"?{text:"SmartArt \u5185\u90E8\u6587\u672C\u7ED3\u6784\u6682\u672A\u5F00\u653E",textStyle:"SmartArt \u5185\u90E8\u6587\u5B57\u6837\u5F0F\u6682\u672A\u5F00\u653E",shapeStyle:"SmartArt \u6837\u5F0F\u6682\u672A\u5F00\u653E"}:{text:"\u7EC4\u5408\u5BF9\u8C61\u8BF7\u53CC\u51FB\u6216\u70B9\u9009\u7EC4\u5185\u5B50\u5BF9\u8C61\u7F16\u8F91\u6587\u5B57",textStyle:"\u7EC4\u5408\u5BF9\u8C61\u8BF7\u9009\u4E2D\u7EC4\u5185\u6587\u672C\u5B50\u5BF9\u8C61\u7F16\u8F91\u6587\u5B57\u6837\u5F0F",shapeStyle:"\u7EC4\u5408\u5BF9\u8C61\u6682\u4E0D\u652F\u6301\u6574\u4F53\u5F62\u72B6\u6837\u5F0F\u7F16\u8F91"}}function KS(e){return e.id.startsWith("layout:")||e.id.startsWith("master:")}function _S(e){return e.id.includes(":")}function Gf(e,t){var w;if(!e.groupContext)return t;let n=e.groupContext.parentBounds,r=e.groupContext.parentTransform,o=v(v({},e.bounds),t),i=n.width/(r.childWidth||n.width||1),s=n.height/(r.childHeight||n.height||1),a=XS(o.left+o.width/2,o.top+o.height/2,n),l=a.x-o.width/2,c=a.y-o.height/2,u=n.flipHorizontal?n.left+n.width-l-o.width:l-n.left,f=n.flipVertical?n.top+n.height-c-o.height:c-n.top,p={};return t.left!==void 0&&(p.left=u/i+r.childLeft),t.top!==void 0&&(p.top=f/s+r.childTop),t.width!==void 0&&(p.width=o.width/i),t.height!==void 0&&(p.height=o.height/s),t.rotation!==void 0&&(p.rotation=zf(t.rotation-((w=n.rotation)!=null?w:0))),t.flipHorizontal!==void 0&&(p.flipHorizontal=!!n.flipHorizontal!=!!t.flipHorizontal),t.flipVertical!==void 0&&(p.flipVertical=!!n.flipVertical!=!!t.flipVertical),p}function qS(e){return Ff.get(e)}function XS(e,t,n){if(!n.rotation)return {x:e,y:t};let r=-n.rotation*Math.PI/180,o=n.left+n.width/2,i=n.top+n.height/2,s=e-o,a=t-i;return {x:o+s*Math.cos(r)-a*Math.sin(r),y:i+s*Math.sin(r)+a*Math.cos(r)}}function so(e={}){var t,n,r,o;return {left:(t=e.left)!=null?t:0,top:(n=e.top)!=null?n:0,width:(r=e.width)!=null?r:0,height:(o=e.height)!=null?o:0,rotation:e.rotation,flipHorizontal:e.flipHorizontal,flipVertical:e.flipVertical}}function rr(e,t){var n,r;return typeof t=="number"?(n=e.slides.find(o=>o.index===t))!=null?n:null:(r=e.slides.find(o=>o.id===t||o.name===t))!=null?r:null}function uo(e,t){let n=[...e.nodes,...e.groups];for(;n.length>0;){let r=n.shift();if(r.id===t||r.name===t)return r;n.unshift(...r.children);}return null}async function aT(e,t={}){let n=await ppt.Presentation.fromZip(e,{presentationId:t.presentationId,mode:"inline"});return Uf(n,t)}async function sT(e,t={}){var r;let n=await ppt.Presentation.fromModel(e,{presentationId:(r=t.presentationId)!=null?r:e.id,mode:"inline"});return Uf(n,t)}async function Uf(e,t={}){let[n,r,o]=await Promise.all([e.toModel(),YS(e,t),ZS(e)]);return {presentation:e,model:n,scene:lo(n),images:r,fonts:o}}async function YS(e,t){if(typeof Blob=="undefined"||typeof URL=="undefined"||typeof URL.createObjectURL!="function")return {};let n=await e.exportImages(),r=await Promise.all(n.map(async o=>{var s;let i=await((s=t.resolveImagePreview)==null?void 0:s.call(t,{path:o.path,contentType:o.contentType,bytes:o.bytes}));return [o.path,i!=null?i:{url:URL.createObjectURL(new Blob([Kf(o.bytes)],{type:o.contentType})),contentType:o.contentType}]}));return Object.fromEntries(r)}async function ZS(e){return typeof Blob=="undefined"||typeof URL=="undefined"||typeof URL.createObjectURL!="function"?[]:(await e.exportFonts()).map(n=>v(v({url:URL.createObjectURL(new Blob([Kf(n.bytes)],{type:n.contentType})),contentType:n.contentType,family:n.family},n.weight?{weight:n.weight}:{}),n.style?{style:n.style}:{}))}function Kf(e){let t=new Uint8Array(e.byteLength);return t.set(e),t.buffer}var zi=class{constructor(t,n={}){O(this,"presentationValue");O(this,"modelValue");O(this,"sceneValue");O(this,"selectionValue",null);O(this,"revisionValue",0);O(this,"undoStack",[]);O(this,"redoStack",[]);O(this,"textBodyOverrides",new Map);O(this,"maxHistory");O(this,"readOnlyValue");O(this,"changeListeners",new Set);O(this,"selectionListeners",new Set);var r;this.presentationValue=t.presentation,this.modelValue=t.model,this.sceneValue=t.scene,this.maxHistory=(r=n.maxHistory)!=null?r:50,this.readOnlyValue=n.readOnly===true,this.selectionValue=t.scene.slides[0]?{kind:"slide",slideId:t.scene.slides[0].id}:null;}presentation(){return this.assertWritable(),this.presentationValue}model(){return this.modelValue}scene(){return this.sceneValue}selection(){return this.selectionValue}revision(){return this.revisionValue}isReadOnly(){return this.readOnlyValue}setReadOnly(t){this.readOnlyValue=t;}canUndo(){return !this.readOnlyValue&&this.undoStack.length>0}canRedo(){return !this.readOnlyValue&&this.redoStack.length>0}subscribe(t,n){let r=t==="change"?this.changeListeners:this.selectionListeners;return r.add(n),()=>r.delete(n)}async dispatch(t){if(t.kind==="select-slide"||t.kind==="select-shape"){await this.applySelectionCommand(t);return}this.assertWritable();let n=await this.presentationValue.toZip(),r=await this.applyEditCommand(t);this.pushUndo(n),this.redoStack.length=0,await this.refreshAfterChange(t),r!==void 0&&this.setSelection(r);}async undo(){this.assertWritable();let t=this.undoStack.pop();if(!t)return;let n=this.selectionValue;this.redoStack.push(this.historyEntry(await this.presentationValue.toZip())),this.restoreTextBodyOverrides(t.textBodyOverrides),await this.replacePresentation(t.bytes,n);}async redo(){this.assertWritable();let t=this.redoStack.pop();if(!t)return;let n=this.selectionValue;this.undoStack.push(this.historyEntry(await this.presentationValue.toZip())),this.restoreTextBodyOverrides(t.textBodyOverrides),await this.replacePresentation(t.bytes,n);}async loadPresentation(t){this.undoStack.length=0,this.redoStack.length=0,this.textBodyOverrides.clear(),await this.replacePresentation(t);}async toPptx(){return this.presentationValue.toZip()}async verifyExport(){let t=await this.toPptx(),n=await ppt.Presentation.fromZip(t,{mode:"inline"});try{return await n.toModel()}finally{await n.dispose();}}async destroy(){await this.presentationValue.dispose(),this.undoStack.length=0,this.redoStack.length=0,this.changeListeners.clear(),this.selectionListeners.clear();}assertWritable(){if(this.readOnlyValue)throw new dn("ppt")}async applySelectionCommand(t){let n=rr(this.sceneValue,t.slideIdOrIndex);if(!n)throw new Error(`PPT slide not found: ${String(t.slideIdOrIndex)}`);if(t.kind==="select-slide"){this.setSelection({kind:"slide",slideId:n.id});return}let r=uo(n,t.shapeIdOrName);if(!r)throw new Error(`PPT shape not found: ${t.shapeIdOrName}`);this.setSelection({kind:"shape",slideId:n.id,shapeId:r.id});}async applyEditCommand(t){var s,a;if(t.kind==="delete-shape"||t.kind==="duplicate-shape"||t.kind==="paste-shape"||t.kind==="bring-shape-to-front"||t.kind==="send-shape-to-back")return this.applyShapeCollectionCommand(t);let n=this.assertEditableSceneNodeForCommand(t),r=rr(this.sceneValue,t.slideIdOrIndex);if(!r)throw new Error(`PPT slide not found: ${String(t.slideIdOrIndex)}`);let o=this.presentationValue.slides.getItem(t.slideIdOrIndex),i=n0(o.shapes,t.shapeIdOrName);if(t.kind==="set-shape-text"){await i.text.setText(t.text,{preserveFirstRunStyle:true});return}if(t.kind==="set-shape-text-style"){await i.text.setTextStyle(t.style);return}if(t.kind==="set-table-cell-text"){await i.table.setCellText(t.row,t.column,t.text);return}if(t.kind==="set-shape-geometry"){if(t.preserveTextSizeOnResize&&QS(n)){let l=$(v({},n.textBody),{autoFit:"none",wrap:(a=(s=n.textBody)==null?void 0:s.wrap)!=null?a:"square"});await i.text.setBodyProperties(l),this.textBodyOverrides.set(JS(r.id,n.id),l);}await i.setGeometry(Gf(n,t.geometry));return}await i.setStyle(t.style);}assertEditableSceneNodeForCommand(t){var o;let n=rr(this.sceneValue,t.slideIdOrIndex);if(!n)throw new Error(`PPT slide not found: ${String(t.slideIdOrIndex)}`);let r=(o=uo(n,t.shapeIdOrName))!=null?o:t0(n,t.shapeIdOrName);if(!r)throw new Error(`PPT shape not found: ${t.shapeIdOrName}`);if(r0(t)&&(r.locked||r.id.includes(":")||!r.editable))throw new Error(`PPT shape collection operation is not editable: ${r.id}`);if(t.kind==="set-shape-text"&&!r.capabilities.editText)throw new Error(`PPT shape is not text-editable: ${r.id}`);if(t.kind==="set-shape-text-style"&&!r.capabilities.editTextStyle)throw new Error(`PPT shape text style is not editable: ${r.id}`);if(t.kind==="set-table-cell-text"&&!r.capabilities.editTableCells)throw new Error(`PPT shape table cells are not editable: ${r.id}`);if(t.kind==="set-shape-geometry"&&!r.capabilities.editGeometry)throw new Error(`PPT shape geometry is not editable: ${r.id}`);if(t.kind==="set-shape-style"&&!r.capabilities.editShapeStyle)throw new Error(`PPT shape style is not editable: ${r.id}`);return r}async applyShapeCollectionCommand(t){var c,u,f,p,w,b,g,h;this.assertEditableSceneNodeForCommand(t);let n=rr(this.sceneValue,t.slideIdOrIndex);if(!n)throw new Error(`PPT slide not found: ${String(t.slideIdOrIndex)}`);let r=uo(n,t.shapeIdOrName);if(!r)throw new Error(`PPT shape not found: ${t.shapeIdOrName}`);let i=this.presentationValue.slides.getItem(t.slideIdOrIndex).shapes.getItem(t.shapeIdOrName);if(t.kind==="delete-shape")return await i.delete(),{kind:"slide",slideId:n.id};if(t.kind==="bring-shape-to-front")return await i.bringToFront(),{kind:"shape",slideId:n.id,shapeId:r.id};if(t.kind==="send-shape-to-back")return await i.sendToBack(),{kind:"shape",slideId:n.id,shapeId:r.id};let s={left:typeof r.bounds.left=="number"?r.bounds.left+((u=(c=t.offset)==null?void 0:c.left)!=null?u:18e4):r.bounds.left,top:typeof r.bounds.top=="number"?r.bounds.top+((p=(f=t.offset)==null?void 0:f.top)!=null?p:18e4):r.bounds.top,width:(b=(w=t.offset)==null?void 0:w.width)!=null?b:r.bounds.width,height:(h=(g=t.offset)==null?void 0:g.height)!=null?h:r.bounds.height},l=await(await i.duplicate({geometry:s})).toModel();return {kind:"shape",slideId:n.id,shapeId:l.id}}async refreshAfterChange(t){this.modelValue=await this.presentationValue.toModel(),this.sceneValue=lo(this.modelValue),this.applyTextBodyOverrides(),this.revisionValue+=1,this.changeListeners.forEach(n=>n({revision:this.revisionValue,command:t,model:this.modelValue,scene:this.sceneValue}));}async replacePresentation(t,n=null){let r=await ppt.Presentation.fromZip(t,{mode:"inline"});if(await this.presentationValue.dispose(),this.presentationValue=r,this.modelValue=await r.toModel(),this.sceneValue=lo(this.modelValue),this.applyTextBodyOverrides(),n){let i=this.sceneValue.slides.find(s=>s.id===n.slideId);if(n.kind==="slide"&&i){this.setSelection({kind:"slide",slideId:i.id});return}if(n.kind==="shape"&&(i!=null&&i.nodes.some(s=>s.id===n.shapeId))){this.setSelection({kind:"shape",slideId:i.id,shapeId:n.shapeId});return}}let o=this.sceneValue.slides[0];this.setSelection(o?{kind:"slide",slideId:o.id}:null);}setSelection(t){this.selectionValue=t,this.selectionListeners.forEach(n=>n({selection:t}));}pushUndo(t){this.undoStack.push(this.historyEntry(t)),this.undoStack.length>this.maxHistory&&this.undoStack.shift();}historyEntry(t){return {bytes:t,textBodyOverrides:new Map(this.textBodyOverrides)}}restoreTextBodyOverrides(t){this.textBodyOverrides.clear(),t.forEach((n,r)=>this.textBodyOverrides.set(r,v({},n)));}applyTextBodyOverrides(){var t;for(let[n,r]of this.textBodyOverrides){let[o,i]=n.split("\0");if(!o||!i)continue;let s=rr(this.sceneValue,o),a=s?uo(s,i):null;!a||!a.text&&!((t=a.textParagraphs)!=null&&t.length)||(a.textBody=v(v({},a.textBody),r));}}};function JS(e,t){return `${e}\0${t}`}function QS(e){var t;return !!(e.capabilities.editGeometry&&e0(e)&&(e.text||(t=e.textParagraphs)!=null&&t.length))}function e0(e){return e.kind==="placeholder"||e.kind==="textBox"||e.kind==="geometricShape"}function t0(e,t){let n=e.source.shapes.find(r=>r.id===t||r.name===t);return n?co(n,{slideSize:e.size,background:e.background}):null}function n0(e,t){let n=t.split(":").filter(Boolean);if(n.length<=1)return e.getItem(t);let r=e.getItem(n[0]);for(let o of n.slice(1))r=r.group.getItem(o);return r}function r0(e){return e.kind==="delete-shape"||e.kind==="duplicate-shape"||e.kind==="paste-shape"||e.kind==="bring-shape-to-front"||e.kind==="send-shape-to-back"}var qf=24e4,fo=91440,o0=91440,fl=4,Xf=7,or=128,i0=8,Vi=2,a0=2,Gi=4;function wT(e,t,n={}){return new gl(e,t,n)}function s0(e){if(e.kind==="line"||e.kind!=="geometricShape"||e.customGeometry||e.presetGeometry&&e.presetGeometry!=="ellipse"||e.text||!e.fillColor)return false;let t=Math.min(e.bounds.width,e.bounds.height),n=Math.max(e.bounds.width,e.bounds.height);return t<=0?false:n/t<1.2}function yn(e,t,n){var c,u,f,p;let r=Math.max(fo,(c=n.width)!=null?c:e.width),o=Math.max(fo,(u=n.height)!=null?u:e.height),i=Math.min(qf,r),s=Math.min(qf,o),a=Zi((f=n.left)!=null?f:e.left,-r+i,t.width-i),l=Zi((p=n.top)!=null?p:e.top,-o+s,t.height-s);return $(v({},e),{left:a,top:l,width:r,height:o})}function Zi(e,t,n){return Math.max(t,Math.min(n,e))}function ji(e,t,n){let r=n==="x"?e.size.width:e.size.height,o=[{value:0,kind:"slide",role:"start"},{value:r/2,kind:"slide",role:"center"},{value:r,kind:"slide",role:"end"}];for(let i of e.nodes){if(!l0(i,t))continue;let s=n==="x"?i.bounds.left:i.bounds.top,a=n==="x"?i.bounds.width:i.bounds.height;o.push({value:s,kind:"shape",role:"start",referenceShapeId:i.id},{value:s+a/2,kind:"shape",role:"center",referenceShapeId:i.id},{value:s+a,kind:"shape",role:"end",referenceShapeId:i.id});}return o}function l0(e,t){return e.id!==t&&e.kind!=="line"&&!e.locked&&!e.id.includes(":")&&e.capabilities.select&&e.capabilities.editGeometry&&e.bounds.width>fo&&e.bounds.height>fo}function Ui(e,t,n,r={}){let o=null;for(let i of e)for(let s of t){if(r.matchRole!==false&&i.role!==s.role)continue;let a=Math.abs(i.value-s.value);a>n||(!o||a<o.distance)&&(o={source:i,target:s,distance:a});}return o}function Yf(e,t,n,r){let o=t/2,i=Math.abs(n.offset-o)<1?(r-e)*2:r-e;return Math.max(fo,i)}function Hn(e){return !e.locked&&!e.id.includes(":")&&(e.capabilities.editGeometry||e.capabilities.editText||e.capabilities.editShapeStyle||e.capabilities.editTableCells)}function d0(e){let t=e.groupContext;return t?$(v({},e),{id:t.parentId,name:t.parentName,kind:"group",bounds:t.parentBounds,text:void 0,textStyle:void 0,textParagraphs:void 0,textBody:void 0,groupContext:void 0,locked:false,editable:true,capabilities:{select:true,editText:false,editTextStyle:false,editTableCells:false,editGeometry:true,editShapeStyle:false,reason:"Parent group"},children:[]}):e}function c0(e){var i,s;if(e.kind!=="picture"||!e.customGeometry||e.customGeometry.paths.length!==1)return false;let t=Math.min(e.bounds.width,e.bounds.height),n=Math.max(e.bounds.width,e.bounds.height);if(t<=0||n/t>1.12)return false;let r=(s=(i=e.customGeometry.paths[0])==null?void 0:i.commands)!=null?s:[];return r.filter(a=>a.kind==="cubicBezierTo").length>=4&&r.some(a=>a.kind==="close")}var gl=class{constructor(t,n,r){O(this,"root");O(this,"sessionValue");O(this,"imageResources");O(this,"fontResources");O(this,"referencedFontFamilies");O(this,"slideList",document.createElement("div"));O(this,"canvas",document.createElement("div"));O(this,"contextMenu",document.createElement("div"));O(this,"snapGuides",document.createElement("div"));O(this,"options");O(this,"handleCanvasClick",()=>{this.dispatchCurrentSlideSelection();});O(this,"handleWindowMouseMove",t=>{this.updateDrag(t);});O(this,"handleWindowMouseUp",t=>{this.finishDrag(t);});O(this,"handleWindowKeyDown",t=>{this.handleKeyDown(t);});O(this,"handleWindowPointerDown",t=>{this.dismissContextMenu(t);});O(this,"handleWindowScroll",()=>this.hideContextMenu());O(this,"handleCanvasSelectStart",t=>this.handleSelectStart(t));O(this,"handleSlideListScroll",()=>this.scheduleThumbnailRender());O(this,"dragState",null);O(this,"suppressClickAfterDrag",false);O(this,"clipboardShape",null);O(this,"thumbnailFrame",0);O(this,"thumbnailRasterEpoch",0);O(this,"thumbnailCanvasCache",new Map);O(this,"pendingCommands",new Set);this.options=r,this.root=r.styleIsolation==="none"?t:t.attachShadow({mode:"open"}),this.sessionValue=new zi(n,{readOnly:r.readOnly}),this.imageResources=n.images,this.fontResources=n.fonts,this.referencedFontFamilies=k0(n);let o=S0(this.fontResources,this.referencedFontFamilies);E0(this.scheduleFontRenderRefresh(o)),this.mount(),this.sessionValue.subscribe("change",async i=>{var s,a;this.thumbnailRasterEpoch++,this.render(),await((a=(s=this.options).onChange)==null?void 0:a.call(s,{revision:i.revision,bytes:await this.sessionValue.toPptx()}));}),this.sessionValue.subscribe("selectionChange",()=>this.renderSelection()),this.render();}session(){return this.sessionValue}selection(){return this.sessionValue.selection()}isReadOnly(){return this.sessionValue.isReadOnly()}setReadOnly(t){if(this.isReadOnly()===t)return;let n=this.root.querySelector('[contenteditable="true"]');n==null||n.dispatchEvent(new KeyboardEvent("keydown",{key:"Escape",bubbles:true,cancelable:true})),this.dragState&&(this.restoreDragElementBounds(this.dragState),this.clearDragVisualState(this.dragState.element,true),this.dragState=null,this.hideSnapGuides()),this.hideContextMenu(),this.sessionValue.setReadOnly(t),this.render();}async dispatch(t){let n=this.dispatchAndRender(t);this.pendingCommands.add(n);try{await n;}finally{this.pendingCommands.delete(n);}}async dispatchAndRender(t){var r,o;let n=(r=this.currentSlide())==null?void 0:r.id;if(await this.sessionValue.dispatch(t),t.kind==="select-slide"||t.kind==="select-shape"){if(((o=this.currentSlide())==null?void 0:o.id)!==n){this.render();return}this.renderSelection();return}this.render();}async loadPresentation(t){await this.sessionValue.loadPresentation(t),this.thumbnailCanvasCache.clear(),this.thumbnailRasterEpoch++,this.render();}async toPptx(){var t;return (t=this.root.querySelector('[contenteditable="true"]'))==null||t.dispatchEvent(new FocusEvent("blur")),await Promise.all([...this.pendingCommands]),this.sessionValue.toPptx()}canUndo(){return this.sessionValue.canUndo()}canRedo(){return this.sessionValue.canRedo()}async undo(){await this.sessionValue.undo(),this.render();}async redo(){await this.sessionValue.redo(),this.render();}async destroy(){for(this.canvas.removeEventListener("click",this.handleCanvasClick),this.canvas.removeEventListener("selectstart",this.handleCanvasSelectStart),this.slideList.removeEventListener("scroll",this.handleSlideListScroll),this.thumbnailFrame&&cancelAnimationFrame(this.thumbnailFrame),this.thumbnailRasterEpoch++,window.removeEventListener("mousemove",this.handleWindowMouseMove),window.removeEventListener("mouseup",this.handleWindowMouseUp),window.removeEventListener("keydown",this.handleWindowKeyDown),window.removeEventListener("pointerdown",this.handleWindowPointerDown),window.removeEventListener("scroll",this.handleWindowScroll,true),await this.sessionValue.destroy();this.root.firstChild;)this.root.removeChild(this.root.firstChild);}mount(){let t=document.createElement("style");t.textContent=`
1615
+ ${y0(this.fontResources)}
1609
1616
  :host, .coco-ppt-editor { box-sizing: border-box; width: 100%; height: 100%; min-height: 360px; }
1610
1617
  .coco-ppt-editor { display: grid; grid-template-columns: 160px minmax(0, 1fr); background: #f4f6f8; color: #17202a; font: 13px/1.4 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
1611
1618
  .coco-ppt-editor[data-show-slide-list="false"] { grid-template-columns: minmax(0, 1fr); }
@@ -1677,7 +1684,7 @@ coco-word-native-table.coco-word-revision-delete {
1677
1684
  .coco-ppt-context-menu button:disabled { color: #94a3b8; cursor: default; }
1678
1685
  .coco-ppt-context-menu span { color: #64748b; font-size: 11px; }
1679
1686
  .coco-ppt-context-menu hr { border: 0; border-top: 1px solid #e2e8f0; margin: 4px 0; }
1680
- `;let n=document.createElement("div");n.className="coco-ppt-editor",n.dataset.showSlideList=String(this.options.showSlideList!==false),n.dataset.readOnly=String(this.isReadOnly()),this.slideList.className="coco-ppt-slides";let r=document.createElement("div");r.className="coco-ppt-stage",this.canvas.className="coco-ppt-canvas",this.contextMenu.className="coco-ppt-context-menu",this.snapGuides.className="coco-ppt-snap-guides",r.append(this.canvas),n.append(this.slideList,r),this.root.append(t,n,this.contextMenu),this.canvas.addEventListener("click",this.handleCanvasClick),this.canvas.addEventListener("selectstart",this.handleCanvasSelectStart),this.slideList.addEventListener("scroll",this.handleSlideListScroll,{passive:true}),window.addEventListener("mousemove",this.handleWindowMouseMove),window.addEventListener("mouseup",this.handleWindowMouseUp),window.addEventListener("keydown",this.handleWindowKeyDown),window.addEventListener("pointerdown",this.handleWindowPointerDown),window.addEventListener("scroll",this.handleWindowScroll,true);}scheduleFontRenderRefresh(t){return typeof document=="undefined"||!document.fonts?Promise.resolve():t.then(()=>Promise.all([...new Set(this.fontResources.map(n=>n.family))].map(n=>document.fonts.load(`16px ${fl(n)}`)))).then(()=>Promise.all(this.referencedFontFamilies.map(n=>document.fonts.load(`16px ${fl(n)}`)))).then(()=>document.fonts.ready).then(()=>{this.render();}).catch(()=>{})}render(){let t=this.root.querySelector(".coco-ppt-editor");t&&(t.dataset.readOnly=String(this.isReadOnly()));let n=this.sessionValue.scene();this.slideList.replaceChildren(...this.options.showSlideList===false?[]:n.slides.map(i=>{var u;let s=document.createElement("button");s.className="coco-ppt-thumb",s.type="button",s.dataset.slideId=i.id,s.dataset.slideIndex=String(i.index),s.dataset.selected=((u=this.sessionValue.selection())==null?void 0:u.slideId)===i.id?"true":"false";let a=document.createElement("div");a.className="coco-ppt-thumb-preview";let l=document.createElement("div");l.className="coco-ppt-thumb-placeholder";let c=document.createElement("span");return c.className="coco-ppt-thumb-number",c.textContent=String(i.index+1),s.append(a,l,c),s.addEventListener("click",()=>{this.dispatch({kind:"select-slide",slideIdOrIndex:i.id});}),s})),this.options.showSlideList!==false&&this.renderVisibleThumbnails(n.slides);let r=this.currentSlide();if(!r){this.canvas.replaceChildren(),this.hideContextMenu();return}let o=this.computeScale(r);this.canvas.style.width=`${r.size.width*o}px`,this.canvas.style.height=`${r.size.height*o}px`,this.canvas.style.background=ml(r.background,this.imageResources),this.canvas.replaceChildren(...r.nodes.map(i=>this.renderNode(i,o,r)),this.snapGuides),this.hideSnapGuides(),this.hideContextMenu(),this.renderSelection();}renderVisibleThumbnails(t){let n=Array.from(this.slideList.querySelectorAll(".coco-ppt-thumb")),r=this.visibleThumbnailRange(t.length);n.forEach((o,i)=>{let s=o.querySelector(".coco-ppt-thumb-preview"),a=o.querySelector(".coco-ppt-thumb-placeholder");if(!s||!a)return;if(i<r.start||i>=r.end){s.replaceChildren(),delete o.dataset.previewRendered,delete o.dataset.previewMode,a.hidden=false;return}if(o.dataset.previewRendered==="true")return;let l=t[i];if(!l)return;let c=cl(l),u=this.thumbnailCanvasCache.get(l.id);(u==null?void 0:u.fingerprint)===c?(s.replaceChildren(qf(u.canvas)),o.dataset.previewMode="canvas"):(s.replaceChildren(this.renderThumbnailSlide(l)),o.dataset.previewMode="dom",this.rasterizeThumbnail(o,l)),o.dataset.previewRendered="true",a.hidden=true;});}visibleThumbnailRange(t){let n=nr*.5625+XS,r=this.slideList.clientHeight||n*Math.min(t,5),o=Math.max(0,Math.floor(this.slideList.scrollTop/n)-Hi),i=Math.ceil(r/n)+Hi*2,s=this.sessionValue.selection(),a=(s==null?void 0:s.slideId)!==void 0?this.sessionValue.scene().slides.findIndex(u=>u.id===s.slideId):-1,l=a>=0?Math.min(o,Math.max(0,a-Hi)):o,c=a>=0?Math.max(o+i,Math.min(t,a+Hi+1)):o+i;return {start:l,end:Math.min(t,c)}}renderThumbnailSlide(t){let n=document.createElement("div");n.className="coco-ppt-thumb-slide";let o=nr*Oi/t.size.width;return n.style.width=`${t.size.width*o}px`,n.style.height=`${t.size.height*o}px`,n.style.transform=`scale(${1/Oi})`,n.style.background=ml(t.background,this.imageResources),n.replaceChildren(...t.nodes.map(i=>this.renderNode(i,o,t,false))),n}async rasterizeThumbnail(t,n){var c,u;let r=this.thumbnailRasterEpoch,o=cl(n);if(await _f(),await _f(),r!==this.thumbnailRasterEpoch||!t.isConnected)return;let i=t.querySelector(".coco-ppt-thumb-preview"),s=i==null?void 0:i.querySelector(".coco-ppt-thumb-slide");if(!i||!s)return;let a=await o0(s,nr,nr*(n.size.height/n.size.width),YS,(u=(c=this.root.querySelector("style"))==null?void 0:c.textContent)!=null?u:"",nr*Oi,nr*Oi*(n.size.height/n.size.width));if(!a||r!==this.thumbnailRasterEpoch||!t.isConnected)return;let l=this.sessionValue.scene().slides.find(f=>f.id===n.id);!l||cl(l)!==o||(this.thumbnailCanvasCache.set(n.id,{fingerprint:o,canvas:a}),i.replaceChildren(qf(a)),t.dataset.previewMode="canvas");}scheduleThumbnailRender(){this.thumbnailFrame||(this.thumbnailFrame=requestAnimationFrame(()=>{this.thumbnailFrame=0,this.renderVisibleThumbnails(this.sessionValue.scene().slides);}));}renderNode(t,n,r,o=true){var h,y,k;let i=document.createElement("div"),s=Sm(t),a=t.presetGeometry==="frame",l=s?km(t):"horizontal",c=Math.max(s&&l==="vertical"?12:1,t.bounds.width*n),u=Math.max(s&&l==="horizontal"?12:1,t.bounds.height*n);i.className=o?"coco-ppt-node":"coco-ppt-thumb-node",i.dataset.kind=t.kind,i.dataset.locked=String(t.locked),o&&(i.dataset.draggable=String(!this.isReadOnly()&&t.capabilities.editGeometry),i.dataset.resizable=String(!this.isReadOnly()&&t.capabilities.editGeometry),i.dataset.shapeId=t.id),i.style.left=`${t.bounds.left*n-(s&&l==="vertical"?c/2:0)}px`,i.style.top=`${t.bounds.top*n-(s&&l==="horizontal"?u/2:0)}px`,i.style.width=`${c}px`,i.style.height=`${u}px`;let f=[];t.bounds.rotation&&f.push(`rotate(${t.bounds.rotation}deg)`),t.bounds.flipHorizontal&&f.push("scaleX(-1)"),t.bounds.flipVertical&&f.push("scaleY(-1)"),f.length>0&&(i.style.transform=f.join(" "));let p=Im(t),w=sk(t.presetGeometry),b=!!(w&&t.text&&!t.customGeometry&&!p);if(t.usesBackgroundFill&&t.backgroundFill?ek(i,t.backgroundFill,t,r,n,this.imageResources):t.customGeometry||p||b||t.kind==="table"||s||a?i.style.background="transparent":t.fillGradient&&t.fillGradient.colors.length>1?i.style.background=cr(t.fillGradient,dr(t)):t.fillColor&&(i.style.background=lr(t.fillColor,dr(t))),z0(t)&&(i.style.overflow="visible"),(t.presetGeometry==="roundRect"||t.presetGeometry==="round1Rect")&&(i.style.borderRadius=`${ar(t)*n}px`),t.presetGeometry==="round2DiagRect"){let C=`${ar(t)*n}px`;i.style.borderRadius=`${C} 0 ${C} 0`;}if(t.presetGeometry==="round2SameRect"){let C=`${ar(t)*n}px`;i.style.borderRadius=`${C} ${C} 0 0`;}if((t.presetGeometry==="ellipse"||ZS(t)||e0(t))&&(i.style.borderRadius="9999px"),w&&!b&&!p&&(i.style.clipPath=w),a?(i.style.borderStyle="solid",i.style.borderWidth=`${tk(t,n)}px`,t.fillGradient&&t.fillGradient.colors.length>1?(i.style.borderImageSource=cr(t.fillGradient),i.style.borderImageSlice="1"):t.fillColor&&(i.style.borderColor=t.fillColor)):!t.customGeometry&&!p&&!b&&!s&&t.kind!=="picture"&&t.lineColor&&(i.style.borderStyle=wl(t.lineDash),i.style.borderWidth=`${Math.max(1,((h=t.lineWidth)!=null?h:9525)*n)}px`,i.style.borderColor=lr(t.lineColor,t.lineOpacity)),t.shadow&&(i.style.boxShadow=Pm(t.shadow,n)),this.applyTextStyle(i,t,n),A0(i,t,n),b&&w&&i.append(rk(t,n,w)),t.customGeometry&&t.kind!=="picture"&&i.append(vk(t)),p&&i.append(lk(t,n)),s)i.append(Ik(t,n));else if(t.kind==="chart")i.append(Fk(t));else if(t.kind==="table"){let C=Mk(t,n,o);o&&(C.addEventListener("click",N=>{N.stopPropagation(),!this.consumeSuppressedClick()&&(this.notifyTableCellSelection(r,t,N),this.dispatch({kind:"select-shape",slideIdOrIndex:r.id,shapeIdOrName:t.id}));}),C.addEventListener("dblclick",N=>{if(this.isReadOnly())return;let L=Yf(N);if(!L||!t.capabilities.editTableCells)return;N.stopPropagation();let D=Number(L.dataset.row),W=Number(L.dataset.column);!Number.isInteger(D)||!Number.isInteger(W)||this.startTableCellEdit(L,r,t,D,W);})),i.append(C);}else if(t.kind==="picture"){let C=t.imagePath?this.imageResources[t.imagePath]:void 0,N=C==null?void 0:C.url;if(N&&gl(C.contentType,t.imagePath)){if(gk(t,r))i.append(xk(t,N));else {let L=document.createElement("img");L.src=N,L.alt=(y=t.name)!=null?y:"",C0(L,t),t.imageOpacity!==void 0&&(L.style.opacity=String(Math.max(0,Math.min(1,t.imageOpacity)))),i.append(L);}t.lineColor&&i.append(Ck(t,n));}else i.dataset.unsupportedImage=t.imagePath?"true":"missing",C!=null&&C.contentType&&(i.dataset.imageContentType=C.contentType),t.imagePath&&(i.dataset.imagePath=t.imagePath),i.append(T0(t,C==null?void 0:C.contentType));}else {let C=(k=t.text)!=null?k:"";if(t.customGeometry||p||b||M0(t)){let N=document.createElement("div");N.className="coco-ppt-text-layer",R0(N,t),tm(N,t,n,C),i.append(N),nm(N,t),rm(N,t);}else tm(i,t,n,C),nm(i,t),rm(i,t);}if(nk(t)&&i.append(Ek(t,n)),!o)return i;let g=document.createElement("div");return g.className="coco-ppt-resize-handle",g.addEventListener("mousedown",C=>{this.isReadOnly()||!t.capabilities.editGeometry||(C.preventDefault(),C.stopPropagation(),this.startDrag(C,"resize",r,t,n,i));}),i.append(g),i.addEventListener("click",C=>{var L,D;if(this.hideContextMenu(),C.stopPropagation(),this.consumeSuppressedClick())return;if(C.altKey){let W=this.selection(),V=x0(r,C,n,(W==null?void 0:W.kind)==="shape"?W.shapeId:t.id);if(V){this.dispatch({kind:"select-shape",slideIdOrIndex:r.id,shapeIdOrName:V.node.id}),(D=(L=this.options).onObjectAction)==null||D.call(L,{action:"cycle-selection",slideId:r.id,shapeId:V.node.id,kind:V.node.kind,name:V.node.name,reason:`\u5DF2\u5207\u6362\u5230\u91CD\u53E0\u5BF9\u8C61 ${V.index+1}/${V.count}`,candidateIndex:V.index,candidateCount:V.count});return}}let N=this.pointerOperationNode(r,t,C,n);if(N){this.dispatch({kind:"select-shape",slideIdOrIndex:r.id,shapeIdOrName:N.id});return}this.dispatch({kind:"select-shape",slideIdOrIndex:r.id,shapeIdOrName:t.id});}),i.addEventListener("contextmenu",C=>{var L;if(this.isReadOnly())return;C.preventDefault(),C.stopPropagation();let N=(L=this.pointerOperationNode(r,t,C,n))!=null?L:t;this.dispatch({kind:"select-shape",slideIdOrIndex:r.id,shapeIdOrName:N.id}).then(()=>this.showContextMenu(C,r,N));}),i.addEventListener("mousedown",C=>{var D,W;let N=(D=this.pointerOperationNode(r,t,C,n))!=null?D:t,L=(W=ul(this.canvas,N.id))!=null?W:i;b0(L,C.target)||this.isReadOnly()||C.button!==0||!N.capabilities.editGeometry||(C.preventDefault(),C.stopPropagation(),this.startDrag(C,"move",r,N,n,L));}),i.addEventListener("dblclick",C=>{var L,D,W;if(this.isReadOnly())return;C.stopPropagation();let N=Qf(r,t,C,n);if(N){this.startTextEdit((L=ul(this.canvas,N.id))!=null?L:i,r,N);return}if(!t.capabilities.editText){this.sessionValue.dispatch({kind:"select-shape",slideIdOrIndex:r.id,shapeIdOrName:t.id}).then(()=>this.renderSelection()),(W=(D=this.options).onObjectAction)==null||W.call(D,{action:"blocked-text-edit",slideId:r.id,shapeId:t.id,kind:t.kind,name:t.name,reason:S0(t)});return}this.startTextEdit(i,r,t);}),i}pointerOperationNode(t,n,r,o){let i=this.selection();return (i==null?void 0:i.kind)==="shape"&&i.slideId===t.id&&i.shapeId===n.id?n:Qf(t,n,r,o)}notifyTableCellSelection(t,n,r){var a,l;let o=Yf(r);if(!o||!n.capabilities.editTableCells)return;let i=Number(o.dataset.row),s=Number(o.dataset.column);!Number.isInteger(i)||!Number.isInteger(s)||(l=(a=this.options).onTableCellSelectionChange)==null||l.call(a,{slideId:t.id,shapeId:n.id,row:i,column:s,text:dm(o,n,i,s)});}applyTextStyle(t,n,r){var s,a,l,c;let o=n.textStyle;o&&(hl(t,w0(n,o),r),o.alignment&&(bl(t,o.alignment),o.alignment==="center"&&(t.style.justifyContent="center"),o.alignment==="right"&&(t.style.justifyContent="flex-end")));let i=n.kind==="table"?void 0:n.textBody;if(i){let u=(s=i.insetLeft)!=null?s:91440,f=(a=i.insetTop)!=null?a:45720,p=(l=i.insetRight)!=null?l:91440,w=(c=i.insetBottom)!=null?c:45720,b=L0(n,r);t.style.padding=`${f*r+b}px ${p*r}px ${w*r}px ${u*r}px`,wm(i)&&(t.style.writingMode="vertical-rl",t.style.textOrientation="upright"),i.anchor==="middle"&&(t.style.alignItems="center"),i.anchor==="bottom"&&(t.style.alignItems="flex-end"),i.anchor==="top"&&(t.style.alignItems="flex-start");}}startTextEdit(t,n,r){var p,w,b,g;if(this.isReadOnly())return;let o=(p=r.text)!=null?p:"",i=h0(t),s=false;this.sessionValue.dispatch({kind:"select-shape",slideIdOrIndex:n.id,shapeIdOrName:r.id}).then(()=>this.renderSelection()),(b=(w=this.options).onTextEditStateChange)==null||b.call(w,{state:"start",slideId:n.id,shapeId:r.id,text:o}),i.contentEditable="true",i.spellcheck=false,i.setAttribute("role","textbox"),i.setAttribute("aria-label",(g=r.name)!=null?g:"PPT text"),t.dataset.editing="true",this.canvas.dataset.interactionMode="editing",i.textContent=o,i.focus();let a=i.ownerDocument.getSelection();if(a){let h=i.ownerDocument.createRange();h.selectNodeContents(i),h.collapse(false),a.removeAllRanges(),a.addRange(h);}let l=h=>{var k,C,N,L,D;if(s)return;s=true,i.contentEditable="false",i.removeAttribute("role"),i.removeAttribute("aria-label"),delete t.dataset.editing,delete this.canvas.dataset.interactionMode,i.removeEventListener("blur",f),i.removeEventListener("keydown",c),i.removeEventListener("paste",u);let y=(k=i.textContent)!=null?k:"";if(!h){i.textContent=o,(N=(C=this.options).onTextEditStateChange)==null||N.call(C,{state:"cancel",slideId:n.id,shapeId:r.id,text:o}),this.render();return}(D=(L=this.options).onTextEditStateChange)==null||D.call(L,{state:"commit",slideId:n.id,shapeId:r.id,text:y}),y!==o?this.dispatch({kind:"set-shape-text",slideIdOrIndex:n.id,shapeIdOrName:r.id,text:y}):this.render();},c=h=>{if(h.key==="Escape"){h.preventDefault(),l(false);return}h.key==="Enter"&&!h.shiftKey&&(h.preventDefault(),l(true));},u=h=>{var k;let y=(k=h.clipboardData)==null?void 0:k.getData("text/plain");y!==void 0&&(h.preventDefault(),em(i,y));},f=()=>l(true);i.addEventListener("blur",f),i.addEventListener("keydown",c),i.addEventListener("paste",u);}startTableCellEdit(t,n,r,o,i){var w,b,g;if(this.isReadOnly())return;let s=dm(t,r,o,i),a=false;this.sessionValue.dispatch({kind:"select-shape",slideIdOrIndex:n.id,shapeIdOrName:r.id}).then(()=>this.renderSelection()),(b=(w=this.options).onTableCellSelectionChange)==null||b.call(w,{slideId:n.id,shapeId:r.id,row:o,column:i,text:s}),t.contentEditable="true",t.spellcheck=false,this.canvas.dataset.interactionMode="editing",t.setAttribute("role","textbox"),t.setAttribute("aria-label",`${(g=r.name)!=null?g:"PPT table"} cell ${o+1},${i+1}`),t.textContent=s,t.focus();let l=t.ownerDocument.getSelection();if(l){let h=t.ownerDocument.createRange();h.selectNodeContents(t),h.collapse(false),l.removeAllRanges(),l.addRange(h);}let c=h=>{var k;if(a)return;a=true,t.contentEditable="false",delete this.canvas.dataset.interactionMode,t.removeAttribute("role"),t.removeAttribute("aria-label"),t.removeEventListener("blur",p),t.removeEventListener("keydown",u),t.removeEventListener("paste",f);let y=(k=t.textContent)!=null?k:"";if(!h){t.textContent=s,t.dataset.cellText=s;return}y!==s?(t.dataset.cellText=y,this.dispatch({kind:"set-table-cell-text",slideIdOrIndex:n.id,shapeIdOrName:r.id,row:o,column:i,text:y})):this.render();},u=h=>{if(h.key==="Escape"){h.preventDefault(),c(false);return}h.key==="Enter"&&!h.shiftKey&&(h.preventDefault(),c(true));},f=h=>{var k;let y=(k=h.clipboardData)==null?void 0:k.getData("text/plain");y!==void 0&&(h.preventDefault(),em(t,y));},p=()=>c(true);t.addEventListener("blur",p),t.addEventListener("keydown",u),t.addEventListener("paste",f);}startDrag(t,n,r,o,i,s){this.isReadOnly()||(n==="resize"&&t0(s,o),this.dragState={mode:n,slideId:r.id,shapeId:o.id,slideSize:r.size,startClientX:t.clientX,startClientY:t.clientY,startBounds:v({},o.bounds),scale:i,element:s,active:false},this.sessionValue.dispatch({kind:"select-shape",slideIdOrIndex:r.id,shapeIdOrName:o.id}).then(()=>this.renderSelection()));}updateDrag(t){let n=this.dragState;if(!n)return;if(Math.hypot(t.clientX-n.startClientX,t.clientY-n.startClientY)<=dl){this.restoreDragElementBounds(n),this.hideSnapGuides(),n.active=false,this.clearDragVisualState(n.element,true);return}n.active=true,n.element.dataset.dragging="true",this.canvas.dataset.interactionMode="dragging";let o=(t.clientX-n.startClientX)/n.scale,i=(t.clientY-n.startClientY)/n.scale;if(n.mode==="move"){let{bounds:a}=t.altKey?{bounds:xn(n.startBounds,n.slideSize,{left:n.startBounds.left+o,top:n.startBounds.top+i})}:this.snapDragBounds(n,{left:n.startBounds.left+o,top:n.startBounds.top+i});t.altKey&&this.hideSnapGuides(),n.element.style.left=`${a.left*n.scale}px`,n.element.style.top=`${a.top*n.scale}px`;return}let{bounds:s}=t.altKey?{bounds:xn(n.startBounds,n.slideSize,{width:n.startBounds.width+o,height:n.startBounds.height+i})}:this.snapResizeBounds(n,{width:n.startBounds.width+o,height:n.startBounds.height+i});t.altKey&&this.hideSnapGuides(),n.element.style.width=`${s.width*n.scale}px`,n.element.style.height=`${s.height*n.scale}px`;}async finishDrag(t){var a,l;let n=this.dragState;if(!n)return;this.dragState=null;let r=(t.clientX-n.startClientX)/n.scale,o=(t.clientY-n.startClientY)/n.scale,i=Math.hypot(t.clientX-n.startClientX,t.clientY-n.startClientY);if(i<=dl||!n.active){this.hideSnapGuides(),this.clearDragVisualState(n.element);return}this.suppressClickAfterDrag=this.suppressClickAfterDrag||i>dl;let s=t.altKey?xn(n.startBounds,n.slideSize,n.mode==="move"?{left:n.startBounds.left+r,top:n.startBounds.top+o}:{width:n.startBounds.width+r,height:n.startBounds.height+o}):n.mode==="move"?this.snapDragBounds(n,{left:n.startBounds.left+r,top:n.startBounds.top+o}):this.snapResizeBounds(n,{width:n.startBounds.width+r,height:n.startBounds.height+o});if(this.hideSnapGuides(),this.clearDragVisualState(n.element),await this.dispatch({kind:"set-shape-geometry",slideIdOrIndex:n.slideId,shapeIdOrName:n.shapeId,geometry:"bounds"in s?s.bounds:s,preserveTextSizeOnResize:n.mode==="resize"}),"snapped"in s&&s.snapped){let c=this.currentSlide(),u=c==null?void 0:c.nodes.find(f=>f.id===n.shapeId);c&&u&&((l=(a=this.options).onObjectAction)==null||l.call(a,{action:"snap-geometry",slideId:c.id,shapeId:u.id,kind:u.kind,name:u.name,reason:this.snapActionReason(s,c)}));}}snapActionReason(t,n){let r=[...new Set(t.guides.map(o=>o.referenceShapeId).filter(o=>!!o))].map(o=>n.nodes.find(i=>i.id===o)).filter(o=>!!o).map(o=>o.name||o.id);return r.length>0?`\u5DF2\u5438\u9644\u5230 ${r.join("\u3001")}`:"\u5DF2\u5438\u9644\u5230\u9875\u9762\u53C2\u8003\u7EBF"}snapDragBounds(t,n){let r=xn(t.startBounds,t.slideSize,n),o=this.sessionValue.scene().slides.find(u=>u.id===t.slideId);if(!o)return this.hideSnapGuides(),{bounds:r,guides:[],snapped:false};let i=Math.min(18e4,Uf/t.scale),s=zi([{offset:0,value:r.left,role:"start"},{offset:r.width/2,value:r.left+r.width/2,role:"center"},{offset:r.width,value:r.left+r.width,role:"end"}],$i(o,t.shapeId,"x"),i),a=zi([{offset:0,value:r.top,role:"start"},{offset:r.height/2,value:r.top+r.height/2,role:"center"},{offset:r.height,value:r.top+r.height,role:"end"}],$i(o,t.shapeId,"y"),i),l=xn(t.startBounds,t.slideSize,{left:s?s.target.value-s.source.offset:r.left,top:a?a.target.value-a.source.offset:r.top}),c=[...s?[{axis:"x",value:s.target.value,kind:s.target.kind,referenceShapeId:s.target.referenceShapeId}]:[],...a?[{axis:"y",value:a.target.value,kind:a.target.kind,referenceShapeId:a.target.referenceShapeId}]:[]];return this.renderSnapGuides(c,t.scale),{bounds:l,guides:c,snapped:c.length>0}}snapResizeBounds(t,n){let r=xn(t.startBounds,t.slideSize,n),o=this.sessionValue.scene().slides.find(u=>u.id===t.slideId);if(!o)return this.hideSnapGuides(),{bounds:r,guides:[],snapped:false};let i=Math.min(18e4,Uf/t.scale),s=zi([{offset:r.width/2,value:r.left+r.width/2,role:"center"},{offset:r.width,value:r.left+r.width,role:"end"}],$i(o,t.shapeId,"x"),i,{matchRole:false}),a=zi([{offset:r.height/2,value:r.top+r.height/2,role:"center"},{offset:r.height,value:r.top+r.height,role:"end"}],$i(o,t.shapeId,"y"),i,{matchRole:false}),l=xn(t.startBounds,t.slideSize,{width:s?Kf(r.left,r.width,s.source,s.target.value):r.width,height:a?Kf(r.top,r.height,a.source,a.target.value):r.height}),c=[...s?[{axis:"x",value:s.target.value,kind:s.target.kind,referenceShapeId:s.target.referenceShapeId}]:[],...a?[{axis:"y",value:a.target.value,kind:a.target.kind,referenceShapeId:a.target.referenceShapeId}]:[]];return this.renderSnapGuides(c,t.scale),{bounds:l,guides:c,snapped:c.length>0}}renderSnapGuides(t,n){this.clearSnapReferenceHighlights();let r=new Set(t.map(o=>o.referenceShapeId).filter(o=>!!o));for(let o of r){let i=ul(this.canvas,o);i&&(i.dataset.snapReference="true");}this.snapGuides.replaceChildren(...t.map(o=>{let i=document.createElement("div");return i.className="coco-ppt-snap-guide",i.dataset.axis=o.axis,i.dataset.kind=o.kind,o.referenceShapeId&&(i.dataset.referenceShapeId=o.referenceShapeId),o.axis==="x"?i.style.left=`${o.value*n}px`:i.style.top=`${o.value*n}px`,i}));}hideSnapGuides(){this.clearSnapReferenceHighlights(),this.snapGuides.replaceChildren();}clearDragVisualState(t,n=false){delete t.dataset.dragging,(n||!this.dragState)&&delete this.canvas.dataset.interactionMode;}restoreDragElementBounds(t){if(t.mode==="move"){t.element.style.left=`${t.startBounds.left*t.scale}px`,t.element.style.top=`${t.startBounds.top*t.scale}px`;return}t.element.style.width=`${t.startBounds.width*t.scale}px`,t.element.style.height=`${t.startBounds.height*t.scale}px`;}clearSnapReferenceHighlights(){this.canvas.querySelectorAll('.coco-ppt-node[data-snap-reference="true"]').forEach(t=>{delete t.dataset.snapReference;});}handleKeyDown(t){if(t.defaultPrevented||this.dragState||Jf(t.target)||this.root.querySelector('[contenteditable="true"]'))return;let n=this.selection();if((n==null?void 0:n.kind)!=="shape")return;let r=this.sessionValue.scene().slides.find(c=>c.id===n.slideId),o=r==null?void 0:r.nodes.find(c=>c.id===n.shapeId);if(!r||!o)return;let i=t.ctrlKey||t.metaKey;if(this.isReadOnly())return;if(i&&t.key.toLowerCase()==="c"){t.preventDefault(),this.copySelectedShape(r,o);return}if(i&&t.key.toLowerCase()==="v"){t.preventDefault(),this.pasteClipboardShape(r,o);return}if(i&&t.key.toLowerCase()==="d"){t.preventDefault(),this.duplicateSelectedShape(r,o);return}if(i&&t.shiftKey&&t.key==="]"){t.preventDefault(),this.bringSelectedShapeToFront(r,o);return}if(i&&t.shiftKey&&t.key==="["){t.preventDefault(),this.sendSelectedShapeToBack(r,o);return}if(t.key==="Delete"||t.key==="Backspace"){if(!Dn(o))return;t.preventDefault(),this.deleteSelectedShape(r,o);return}let s=g0(t.key);if(!s||!o.capabilities.editGeometry)return;let a=qS*(t.shiftKey?10:1),l=xn(o.bounds,r.size,{left:o.bounds.left+s.dx*a,top:o.bounds.top+s.dy*a});t.preventDefault(),this.dispatch({kind:"set-shape-geometry",slideIdOrIndex:r.id,shapeIdOrName:o.id,geometry:{left:l.left,top:l.top}}).then(()=>{var c,u;(u=(c=this.options).onObjectAction)==null||u.call(c,{action:"nudge-geometry",slideId:r.id,shapeId:o.id,kind:o.kind,name:o.name,reason:`\u5DF2\u79FB\u52A8\u5BF9\u8C61 ${s.label}${t.shiftKey?" 10\u6B65":" 1\u6B65"}`});});}handleSelectStart(t){this.isReadOnly()||Jf(t.target)||t.target instanceof HTMLElement&&t.target.closest('[contenteditable="true"]')||t.preventDefault();}copySelectedShape(t,n){var r,o;Dn(n)&&(this.clipboardShape={slideId:t.id,shapeId:n.id},(o=(r=this.options).onObjectAction)==null||o.call(r,{action:"copy-shape",slideId:t.id,shapeId:n.id,kind:n.kind,name:n.name,reason:"\u5DF2\u590D\u5236\u5BF9\u8C61"}));}pasteClipboardShape(t,n){if(!this.clipboardShape)return;let r=this.clipboardShape;this.dispatch({kind:"paste-shape",slideIdOrIndex:r.slideId,shapeIdOrName:r.shapeId}).then(()=>{var i,s;let o=this.selection();(s=(i=this.options).onObjectAction)==null||s.call(i,{action:"paste-shape",slideId:r.slideId,shapeId:(o==null?void 0:o.kind)==="shape"?o.shapeId:n.id,kind:n.kind,name:n.name,reason:"\u5DF2\u7C98\u8D34\u5BF9\u8C61"});});}duplicateSelectedShape(t,n){Dn(n)&&this.dispatch({kind:"duplicate-shape",slideIdOrIndex:t.id,shapeIdOrName:n.id}).then(()=>{var o,i;let r=this.selection();(i=(o=this.options).onObjectAction)==null||i.call(o,{action:"duplicate-shape",slideId:t.id,shapeId:(r==null?void 0:r.kind)==="shape"?r.shapeId:n.id,kind:n.kind,name:n.name,reason:"\u5DF2\u91CD\u590D\u5BF9\u8C61"});});}bringSelectedShapeToFront(t,n){Dn(n)&&this.dispatch({kind:"bring-shape-to-front",slideIdOrIndex:t.id,shapeIdOrName:n.id}).then(()=>{var r,o;(o=(r=this.options).onObjectAction)==null||o.call(r,{action:"bring-shape-to-front",slideId:t.id,shapeId:n.id,kind:n.kind,name:n.name,reason:"\u5DF2\u7F6E\u4E8E\u9876\u5C42"});});}sendSelectedShapeToBack(t,n){Dn(n)&&this.dispatch({kind:"send-shape-to-back",slideIdOrIndex:t.id,shapeIdOrName:n.id}).then(()=>{var r,o;(o=(r=this.options).onObjectAction)==null||o.call(r,{action:"send-shape-to-back",slideId:t.id,shapeId:n.id,kind:n.kind,name:n.name,reason:"\u5DF2\u7F6E\u4E8E\u5E95\u5C42"});});}showContextMenu(t,n,r){if(this.isReadOnly())return;let o=Dn(r),i=!!this.clipboardShape,s=u=>()=>{this.hideContextMenu(),u();};this.contextMenu.replaceChildren(rr("\u590D\u5236","Ctrl+C",o,s(()=>this.copySelectedShape(n,r))),rr("\u7C98\u8D34","Ctrl+V",i,s(()=>this.pasteClipboardShape(n,r))),rr("\u91CD\u590D","Ctrl+D",o,s(()=>this.duplicateSelectedShape(n,r))),Zf(),rr("\u7F6E\u4E8E\u9876\u5C42","Ctrl+Shift+]",o,s(()=>this.bringSelectedShapeToFront(n,r))),rr("\u7F6E\u4E8E\u5E95\u5C42","Ctrl+Shift+[",o,s(()=>this.sendSelectedShapeToBack(n,r))),Zf(),rr("\u5220\u9664","Del",o,s(()=>this.deleteSelectedShape(n,r))));let a=this.root instanceof ShadowRoot?this.root.host.getBoundingClientRect():this.root.getBoundingClientRect(),l=_i(t.clientX,a.left+4,window.innerWidth-170),c=_i(t.clientY,a.top+4,window.innerHeight-220);this.contextMenu.style.left=`${l}px`,this.contextMenu.style.top=`${c}px`,this.contextMenu.dataset.shapeId=r.id,this.contextMenu.dataset.open="true";}deleteSelectedShape(t,n){Dn(n)&&this.dispatch({kind:"delete-shape",slideIdOrIndex:t.id,shapeIdOrName:n.id}).then(()=>{var r,o;(o=(r=this.options).onObjectAction)==null||o.call(r,{action:"delete-shape",slideId:t.id,shapeId:n.id,kind:n.kind,name:n.name,reason:"\u5DF2\u5220\u9664\u5BF9\u8C61"});});}async dispatchCurrentSlideSelection(){if(this.consumeSuppressedClick())return;let t=this.currentSlide();t&&await this.dispatch({kind:"select-slide",slideIdOrIndex:t.id});}consumeSuppressedClick(){return this.suppressClickAfterDrag?(this.suppressClickAfterDrag=false,true):false}dismissContextMenu(t){let n=t.composedPath()[0];n instanceof Node&&this.contextMenu.contains(n)||this.hideContextMenu();}hideContextMenu(){delete this.contextMenu.dataset.open,delete this.contextMenu.dataset.shapeId;}renderSelection(){this.canvas.querySelectorAll(".coco-ppt-parent-group-outline").forEach(n=>n.remove());let t=this.sessionValue.selection();this.slideList.querySelectorAll(".coco-ppt-thumb").forEach((n,r)=>{let o=this.sessionValue.scene().slides[r];n.dataset.selected=(t==null?void 0:t.slideId)===(o==null?void 0:o.id)?"true":"false";}),this.canvas.querySelectorAll(".coco-ppt-node").forEach(n=>{n.dataset.selected=(t==null?void 0:t.kind)==="shape"&&n.dataset.shapeId===t.shapeId?"true":"false";}),this.renderParentGroupSelection(t);}renderParentGroupSelection(t){var c,u;if((t==null?void 0:t.kind)!=="shape")return;let n=this.sessionValue.scene().slides.find(f=>f.id===t.slideId),r=(c=n==null?void 0:n.nodes.find(f=>f.id===t.shapeId))!=null?c:n==null?void 0:n.groups.find(f=>f.id===t.shapeId),o=r!=null&&r.groupContext?(u=n==null?void 0:n.groups.find(f=>{var p;return f.id===((p=r.groupContext)==null?void 0:p.parentId)}))!=null?u:QS(r):(r==null?void 0:r.kind)==="group"?r:null;if(!n||!o)return;let i=this.computeScale(n),s=document.createElement("div");s.className="coco-ppt-parent-group-outline",s.dataset.shapeId=o.id,s.dataset.selected=t.shapeId===o.id?"true":"false",s.title=`\u7236\u7EC4\uFF1A${o.name||o.id}`,s.style.left=`${o.bounds.left*i}px`,s.style.top=`${o.bounds.top*i}px`,s.style.width=`${o.bounds.width*i}px`,s.style.height=`${o.bounds.height*i}px`;let a=f=>{f.preventDefault(),f.stopPropagation(),this.startDrag(f,"move",n,o,i,s);};["top","right","bottom","left"].forEach(f=>{let p=document.createElement("div");p.className="coco-ppt-parent-group-edge",p.dataset.edge=f,p.title="\u62D6\u52A8\u7236\u7EC4",p.addEventListener("mousedown",a),s.append(p);});let l=document.createElement("div");l.className="coco-ppt-parent-group-handle",l.title="\u62D6\u52A8\u7236\u7EC4",l.addEventListener("mousedown",a),s.append(l),this.canvas.append(s);}currentSlide(){var r,o,i;let t=this.sessionValue.scene(),n=this.sessionValue.selection();return (n==null?void 0:n.kind)==="slide"||(n==null?void 0:n.kind)==="shape"?(o=(r=t.slides.find(s=>s.id===n.slideId))!=null?r:t.slides[0])!=null?o:null:(i=t.slides[0])!=null?i:null}computeScale(t){let n=this.canvas.parentElement,r=n?Math.max(1,n.clientWidth-48):960,o=n?Math.max(1,n.clientHeight-48):540;return Math.min(960/t.size.width,540/t.size.height,r/t.size.width,o/t.size.height)}};function t0(e,t){var r,o;if(!n0(t))return;let n=(o=(r=e.querySelector(".coco-ppt-rich-text, .coco-ppt-distributed-text"))!=null?r:e.querySelector(".coco-ppt-text-layer"))!=null?o:e;e.dataset.textResizePreview="wrap",n.dataset.textResizePreview="wrap",n.style.transform="",n.style.transformOrigin="",n.style.width="",e.style.whiteSpace="pre-wrap",e.style.overflowWrap="anywhere",e.querySelectorAll(".coco-ppt-rich-text, .coco-ppt-paragraph").forEach(i=>{i.style.whiteSpace="pre-wrap",i.style.overflowWrap="anywhere";});}function n0(e){var t;return !!(e.capabilities.editGeometry&&r0(e)&&(e.text||(t=e.textParagraphs)!=null&&t.length))}function r0(e){return e.kind==="placeholder"||e.kind==="textBox"||e.kind==="geometricShape"}function _f(){return new Promise(e=>requestAnimationFrame(()=>e()))}async function o0(e,t,n,r,o,i=t,s=n){if(typeof XMLSerializer=="undefined"||typeof Blob=="undefined"||typeof URL=="undefined"||typeof URL.createObjectURL!="function")return null;await i0(e);let a=document.createElement("canvas");a.width=Math.max(1,Math.round(t*r)),a.height=Math.max(1,Math.round(n*r));let l=a.getContext("2d");if(!l)return null;let c=document.createElement("div");c.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),c.style.width=`${i}px`,c.style.height=`${s}px`,c.style.position="relative",c.style.overflow="hidden",c.style.background="#fff";let u=document.createElement("style");u.textContent=o;let f=e.cloneNode(true);await a0(f),f.style.position="relative",f.style.left="0",f.style.top="0",f.style.transform="none",c.append(u,f);let p=new XMLSerializer().serializeToString(c),w=`<svg xmlns="http://www.w3.org/2000/svg" width="${a.width}" height="${a.height}" viewBox="0 0 ${i} ${s}"><foreignObject width="100%" height="100%">${p}</foreignObject></svg>`,b=URL.createObjectURL(new Blob([w],{type:"image/svg+xml;charset=utf-8"}));try{let g=await d0(b);return l.drawImage(g,0,0,a.width,a.height),a}catch(g){return null}finally{URL.revokeObjectURL(b);}}function qf(e){let t=document.createElement("canvas");t.className="coco-ppt-thumb-canvas",t.width=e.width,t.height=e.height;let n=t.getContext("2d");return n&&n.drawImage(e,0,0),t}function cl(e){return JSON.stringify({size:e.size,background:e.background,nodes:e.nodes.map(t=>mm(t))})}function mm(e){return {id:e.id,kind:e.kind,bounds:e.bounds,text:e.text,textParagraphs:e.textParagraphs,textStyle:e.textStyle,textBody:e.textBody,table:e.table,fillColor:e.fillColor,fillGradient:e.fillGradient,opacity:e.opacity,lineColor:e.lineColor,lineGradient:e.lineGradient,lineOpacity:e.lineOpacity,lineWidth:e.lineWidth,lineDash:e.lineDash,presetGeometry:e.presetGeometry,presetAdjustments:e.presetAdjustments,customGeometry:e.customGeometry,imagePath:e.imagePath,imageCrop:e.imageCrop,imageFillRect:e.imageFillRect,imageOpacity:e.imageOpacity,shadow:e.shadow,threeD:e.threeD,children:e.children.map(t=>mm(t))}}async function i0(e){let t=Array.from(e.querySelectorAll("img"));await Promise.all(t.map(async n=>{if(!(n.complete&&n.naturalWidth>0)){if(typeof n.decode=="function"){await n.decode().catch(()=>{});return}await new Promise(r=>{let o=()=>r();n.addEventListener("load",o,{once:true}),n.addEventListener("error",o,{once:true}),setTimeout(o,500);});}}));}async function a0(e){let t=Array.from(e.querySelectorAll("img"));await Promise.all(t.map(async n=>{n.alt="";let r=n.getAttribute("src");if(!r||r.startsWith("data:"))return;let o=await s0(r).catch(()=>{});o&&n.setAttribute("src",o);}));}async function s0(e){let t=await fetch(e);if(!t.ok)throw new Error(`Failed to inline thumbnail image: ${t.status}`);let n=await t.blob();return l0(n)}function l0(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=()=>{typeof r.result=="string"?t(r.result):n(new Error("Failed to read thumbnail image blob."));},r.onerror=()=>{var o;return n((o=r.error)!=null?o:new Error("Failed to read thumbnail image blob."))},r.readAsDataURL(e);})}function d0(e){return new Promise((t,n)=>{let r=new Image;r.onload=()=>t(r),r.onerror=()=>n(new Error("Failed to rasterize PPT thumbnail.")),r.src=e;})}function c0(e){return e.filter(u0).map(n=>{var s,a;let r=bm(n.family),o=(s=n.weight)!=null?s:400,i=(a=n.style)!=null?a:"normal";return `@font-face { font-family: ${r}; src: url(${E0(n.url)}); font-weight: ${o}; font-style: ${i}; }`}).join(`
1681
- `)}function u0(e){return /font\/(ttf|otf|woff|woff2)|application\/font-(sfnt|woff|woff2)/i.test(e.contentType)}function p0(e,t=[]){if(typeof document=="undefined")return Promise.resolve();let n=new Set(e.map(o=>o.family));for(let o of t)n.add(o);let r=[];for(let o of n){let i=k0(o);if(!i)continue;let s=`coco-ppt-google-font-${o.replace(/[^a-zA-Z0-9_-]/g,"_")}`,a=document.getElementById(s);if(a){r.push(Xf(a));continue}let l=document.createElement("link");l.id=s,l.rel="stylesheet",l.href=i,r.push(Xf(l)),document.head.append(l);}return Promise.all(r).then(()=>{})}function f0(e){let t=new Set,n=o=>{o!=null&&o.trim()&&t.add(o.trim());},r=o=>{var i,s,a,l,c,u,f,p;n((i=o.textStyle)==null?void 0:i.fontFamily);for(let w of (s=o.textParagraphs)!=null?s:[]){n((a=w.style)==null?void 0:a.bulletFontFamily);for(let b of (l=w.runs)!=null?l:[])n((c=b.style)==null?void 0:c.fontFamily);}for(let w of (f=(u=o.table)==null?void 0:u.cellStyles)!=null?f:[])for(let b of w)n((p=b==null?void 0:b.textStyle)==null?void 0:p.fontFamily);for(let w of o.children)r(w);};for(let o of e.scene.slides)for(let i of o.nodes)r(i);return [...t]}function m0(e){globalThis.__cocoPptFontRenderReady=e;}function Xf(e){return e.sheet?Promise.resolve():new Promise(t=>{let n=()=>t();e.addEventListener("load",n,{once:true}),e.addEventListener("error",n,{once:true}),window.setTimeout(n,5e3);})}function h0(e){var t;return (t=e.querySelector(".coco-ppt-text-layer"))!=null?t:e}function Yf(e){let t=e.target;return t instanceof HTMLElement?t.closest("td[data-row][data-column]"):null}function rr(e,t,n,r){let o=document.createElement("button");o.type="button",o.disabled=!n;let i=document.createElement("strong");i.textContent=e;let s=document.createElement("span");return s.textContent=t,o.append(i,s),o.addEventListener("click",()=>{o.disabled||r();}),o}function Zf(){return document.createElement("hr")}function g0(e){return e==="ArrowLeft"?{dx:-1,dy:0,label:"\u5DE6"}:e==="ArrowRight"?{dx:1,dy:0,label:"\u53F3"}:e==="ArrowUp"?{dx:0,dy:-1,label:"\u4E0A"}:e==="ArrowDown"?{dx:0,dy:1,label:"\u4E0B"}:null}function Jf(e){if(!(e instanceof HTMLElement))return false;if(e.isContentEditable)return true;let t=e.tagName.toLowerCase();return t==="input"||t==="textarea"||t==="select"}function b0(e,t){return e.isContentEditable||t instanceof HTMLElement&&t.isContentEditable?true:!!e.querySelector('[contenteditable="true"]')}function w0(e,t){var a;let n=(a=e.textParagraphs)==null?void 0:a.filter(c=>c.runs.length>0);if(!(n!=null&&n.length)||!vm(e,n))return t;let l=t,{textGradient:r,textFill:o,textOutlineColor:i}=l;return In(l,["textGradient","textFill","textOutlineColor"])}function Qf(e,t,n,r){if(t.capabilities.editText||v0(t))return null;let o=hm(n,r);if(!o)return null;let i=e.nodes.findIndex(a=>a.id===t.id),s=e.nodes.slice(0,i<0?e.nodes.length:i);for(let a=s.length-1;a>=0;a--){let l=s[a];if(l.capabilities.editText&&gm(o.x,o.y,l.bounds))return l}return null}function x0(e,t,n,r){let o=y0(e,t,n);if(o.length<2)return null;let s=(Math.max(0,o.findIndex(a=>a.id===r))+1)%o.length;return {node:o[s],index:s,count:o.length}}function y0(e,t,n){let r=hm(t,n);if(!r)return [];let o=[];for(let i=e.nodes.length-1;i>=0;i--){let s=e.nodes[i];s.capabilities.select&&gm(r.x,r.y,s.bounds)&&o.push(s);}return o}function v0(e){return e.kind==="table"||e.kind==="chart"||e.kind==="smartArt"}function hm(e,t){var o;let n=e.currentTarget&&typeof e.currentTarget.parentElement=="object"&&(o=e.currentTarget.parentElement)!=null?o:null,r=n==null?void 0:n.getBoundingClientRect();return r?{x:(e.clientX-r.left)/t,y:(e.clientY-r.top)/t}:null}function gm(e,t,n){return e>=n.left&&e<=n.left+n.width&&t>=n.top&&t<=n.top+n.height}function ul(e,t){for(let n of Array.from(e.querySelectorAll(".coco-ppt-node")))if(n.dataset.shapeId===t)return n;return null}function em(e,t){var s,a;let n=e.ownerDocument.getSelection();if(!n||n.rangeCount===0){e.textContent=`${(s=e.textContent)!=null?s:""}${t}`;return}let r=n.getRangeAt(0);if(!(e===r.commonAncestorContainer||e.contains(r.commonAncestorContainer))){e.textContent=`${(a=e.textContent)!=null?a:""}${t}`;return}r.deleteContents();let i=e.ownerDocument.createTextNode(t);r.insertNode(i),r.setStartAfter(i),r.setEndAfter(i),n.removeAllRanges(),n.addRange(r);}function S0(e){var t;return (t=e.capabilities.reasons)!=null&&t.editText?e.capabilities.reasons.editText:e.capabilities.reason?e.capabilities.reason:e.kind==="table"?"\u8868\u683C\u8BF7\u4F7F\u7528\u5355\u5143\u683C\u7F16\u8F91":e.kind==="picture"?"\u56FE\u7247\u5BF9\u8C61\u4E0D\u652F\u6301\u6587\u5B57\u7F16\u8F91":e.kind==="chart"?"\u56FE\u8868\u5F53\u524D\u4EC5\u652F\u6301\u9009\u62E9\u548C\u4F4D\u7F6E\u7F16\u8F91":e.kind==="smartArt"?"SmartArt \u5F53\u524D\u4EC5\u652F\u6301\u9009\u62E9\u548C\u4F4D\u7F6E\u7F16\u8F91":e.kind==="group"?"\u7EC4\u5408\u5BF9\u8C61\u5F53\u524D\u4EC5\u652F\u6301\u9009\u62E9\u548C\u4F4D\u7F6E\u7F16\u8F91":"\u8BE5\u5BF9\u8C61\u4E0D\u652F\u6301\u6587\u5B57\u7F16\u8F91"}function k0(e){return {Cuprum:"https://fonts.googleapis.com/css2?family=Cuprum:ital,wght@0,400;0,700;1,400;1,700&display=swap",Podkova:"https://fonts.googleapis.com/css2?family=Podkova:wght@400;700&display=swap",Ubuntu:"https://fonts.googleapis.com/css2?family=Ubuntu:ital,wght@0,400;0,700;1,400;1,700&display=swap"}[e]}function fl(e){return [bm(e),'"Calibri"','"Microsoft YaHei"','"Segoe UI"',"sans-serif"].join(", ")}function bm(e){return `"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function E0(e){return `"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function lr(e,t){var a;if(t===void 0||t>=1)return e;let n=Math.max(0,Math.min(1,t)),r=(a=e.match(/^#([0-9a-fA-F]{6})$/))==null?void 0:a[1];if(!r)return e;let o=Number.parseInt(r.slice(0,2),16),i=Number.parseInt(r.slice(2,4),16),s=Number.parseInt(r.slice(4,6),16);return `rgba(${o}, ${i}, ${s}, ${n})`}function dr(e){var t;return e.opacity!==void 0?Math.max(0,Math.min(1,e.opacity)):((t=e.threeD)==null?void 0:t.material)==="translucentPowder"?.52:void 0}function C0(e,t){if(t.imageFillRect){N0(e,t);return}I0(e,t);}function I0(e,t){var c,u,f,p;let n=t.imageCrop;if(!n)return;let r=(c=n.left)!=null?c:0,o=(u=n.right)!=null?u:0,i=(f=n.top)!=null?f:0,s=(p=n.bottom)!=null?p:0,a=Math.max(.01,1-r-o),l=Math.max(.01,1-i-s);e.style.position="absolute",e.style.left=`${-r/a*100}%`,e.style.top=`${-i/l*100}%`,e.style.width=`${1/a*100}%`,e.style.height=`${1/l*100}%`;}function N0(e,t){var a,l,c,u;let n=t.imageFillRect;if(!n)return;let r=(a=n.left)!=null?a:0,o=(l=n.right)!=null?l:0,i=(c=n.top)!=null?c:0,s=(u=n.bottom)!=null?u:0;e.style.position="absolute",e.style.left=`${r*100}%`,e.style.top=`${i*100}%`,e.style.width=`${Math.max(.01,1-r-o)*100}%`,e.style.height=`${Math.max(.01,1-i-s)*100}%`;}function T0(e,t){var o,i;let n=document.createElement("div");n.className="coco-ppt-unsupported-image";let r=(i=(o=e.imagePath)==null?void 0:o.split(".").pop())==null?void 0:i.toUpperCase();return n.textContent=r||P0(t)||"IMAGE",n.title=e.imagePath?`Unsupported image: ${e.imagePath}`:"Missing image resource",n}function P0(e){if(e)return e.includes("emf")?"EMF":e.includes("wmf")?"WMF":e.includes("svg")?"SVG":"IMAGE"}function tm(e,t,n,r){var a,l;let o=(a=t.textParagraphs)==null?void 0:a.filter(c=>c.runs.length>0),i=wm(t.textBody);if(!(o!=null&&o.length)||!vm(t,o)){!i&&((l=t.textStyle)==null?void 0:l.alignment)==="distributed"&&Array.from(r).length>1?j0(e,r):e.textContent=r;return}let s=document.createElement("div");s.className="coco-ppt-rich-text",o.forEach(c=>{var p,w,b,g;let u=document.createElement("div");u.className="coco-ppt-paragraph",(p=c.style)!=null&&p.alignment&&bl(u,c.style.alignment),K0(u,c.style,n,{verticalText:i});let f=!i&&((w=c.style)==null?void 0:w.alignment)==="distributed"&&!((b=c.style)!=null&&b.bullet);if(f&&(u.style.display="flex",u.style.justifyContent="space-between",u.style.alignItems="baseline",u.style.width="100%"),(g=c.style)!=null&&g.bullet){u.dataset.bullet="true";let h=document.createElement("span");h.className="coco-ppt-bullet",h.textContent=c.style.bullet,c.style.bulletColor&&(h.style.color=c.style.bulletColor),q0(h,c.style,n,c.text),u.append(h);}c.runs.forEach((h,y)=>{(f?Array.from(h.text):[h.text]).forEach(C=>{let N=document.createElement("span");N.textContent=C;let L=Z0(t,c,h,y);L&&hl(N,L,n),u.append(N);});}),s.append(u);}),e.append(s);}function wm(e){return (e==null?void 0:e.vertical)==="eastAsian"||(e==null?void 0:e.vertical)==="vertical"}function nm(e,t){var n;((n=t.textBody)==null?void 0:n.wrap)==="none"&&xm(e);}function rm(e,t){var n,r;((n=t.textBody)==null?void 0:n.autoFit)==="normal"&&(!t.text&&!((r=t.textParagraphs)!=null&&r.length)||(D0(t)&&!O0(t)&&xm(e),requestAnimationFrame(()=>{var p;if(e.dataset.textResizePreview==="wrap")return;let o=e.clientWidth,i=e.clientHeight;if(o<=0||i<=0)return;let s=e.scrollWidth,a=e.scrollHeight,l=s>o?o/s:1,c=a>i?i/a:1,u=Math.max(.25,Math.min(1,l,c));if(u>=.995)return;let f=(p=e.querySelector(".coco-ppt-rich-text, .coco-ppt-distributed-text"))!=null?p:e;f.dataset.textResizePreview!=="wrap"&&(f.style.transformOrigin=$0(t),f.style.transform=`scale(${u})`,f.style.width=`${100/u}%`);})));}function M0(e){var t;return !!((e.text||(t=e.textParagraphs)!=null&&t.length)&&(e.bounds.flipHorizontal||e.bounds.flipVertical))}function R0(e,t){let n=[];t.bounds.flipHorizontal&&n.push("scaleX(-1)"),t.bounds.flipVertical&&n.push("scaleY(-1)"),n.length!==0&&(e.style.transform=n.join(" "),e.style.transformOrigin="center");}function xm(e){e.style.whiteSpace="nowrap",e.querySelectorAll(".coco-ppt-rich-text, .coco-ppt-paragraph").forEach(t=>{t.style.whiteSpace="nowrap";});}function A0(e,t,n){var o,i,s;if(!B0(t,n))return;let r=((s=(i=(o=t.textStyle)==null?void 0:o.fontSize)!=null?i:Yi(t))!=null?s:28)*12700*n;e.style.letterSpacing=`${Math.max(1,Math.min(2.4,r*.035))}px`;}function L0(e,t){var r,o;if(!W0(e))return 0;let n=(o=(r=e.textStyle)==null?void 0:r.fontSize)!=null?o:Yi(e);return n?n*12700*t*.18:0}function W0(e){var i,s,a,l,c,u,f,p,w;if(e.kind!=="textBox"&&e.kind!=="placeholder"||((i=e.textBody)==null?void 0:i.anchor)!=="top"||e.textBody.wrap!=="square"||e.fillColor||e.fillGradient||e.lineColor||e.lineGradient)return false;let t=(a=(s=e.textStyle)==null?void 0:s.fontFamily)!=null?a:ym(e);if(!t||!/\bCuprum\b/i.test(t))return false;let n=(c=(l=e.textStyle)==null?void 0:l.fontSize)!=null?c:Yi(e);if(!n||n<72)return false;let r=(u=e.textParagraphs)==null?void 0:u.filter(b=>{var h;return ((h=b.text)!=null?h:b.runs.map(y=>y.text).join("")).trim().length>0});if(r&&r.length!==1)return false;let o=((w=(p=(f=r==null?void 0:r[0])==null?void 0:f.text)!=null?p:e.text)!=null?w:"").trim();return o.length>=12&&!/[\u3400-\u9fff]/.test(o)}function B0(e,t){var l,c,u,f,p,w,b,g,h,y,k,C,N,L,D,W,V,ee,pe,re;if(((l=e.textBody)==null?void 0:l.wrap)!=="square"||F0(e)||((w=(c=e.textStyle)==null?void 0:c.alignment)!=null?w:(p=(f=(u=e.textParagraphs)==null?void 0:u[0])==null?void 0:f.style)==null?void 0:p.alignment)!=="center")return false;let r=(g=(b=e.textStyle)==null?void 0:b.fontFamily)!=null?g:ym(e);if(!r||!/\bJosefin Sans\b/i.test(r))return false;let o=((C=(k=(y=(h=e.textParagraphs)==null?void 0:h[0])==null?void 0:y.text)!=null?k:e.text)!=null?C:"").replace(/\s+/g," ").trim();if(o.length<24||/[a-z\u3400-\u9fff]/.test(o)||!/^[A-Z0-9][A-Z0-9\s&:;,.!?'"()/+-]*$/.test(o))return false;let i=(L=(N=e.textStyle)==null?void 0:N.fontSize)!=null?L:Yi(e);if(!i)return false;let s=(re=(pe=(D=e.textStyle)==null?void 0:D.lineHeight)!=null?pe:(ee=(V=(W=e.textParagraphs)==null?void 0:W[0])==null?void 0:V.style)==null?void 0:ee.lineHeight)!=null?re:1.2,a=i*12700*t*s;return e.bounds.height*t>=a*1.75}function F0(e){var t,n;return !!(((t=e.textStyle)==null?void 0:t.characterSpacing)!==void 0||(n=e.textParagraphs)!=null&&n.some(r=>r.runs.some(o=>{var i;return ((i=o.style)==null?void 0:i.characterSpacing)!==void 0})))}function Yi(e){var t,n;for(let r of (t=e.textParagraphs)!=null?t:[])for(let o of r.runs)if(((n=o.style)==null?void 0:n.fontSize)!==void 0)return o.style.fontSize}function ym(e){var t,n;for(let r of (t=e.textParagraphs)!=null?t:[])for(let o of r.runs)if((n=o.style)!=null&&n.fontFamily)return o.style.fontFamily}function D0(e){var r,o,i,s,a,l;let t=(r=e.textParagraphs)==null?void 0:r.filter(c=>c.runs.length>0);if(t&&t.length!==1||(i=(o=t==null?void 0:t[0])==null?void 0:o.style)!=null&&i.bullet)return false;let n=(l=(a=(s=t==null?void 0:t[0])==null?void 0:s.text)!=null?a:e.text)!=null?l:"";return n.length>0&&!n.includes(`
1682
- `)&&!n.includes("\r")}function H0(e){var o,i,s,a,l,c,u,f,p,w;if(((o=e.textBody)==null?void 0:o.wrap)!=="square"||((c=(i=e.textStyle)==null?void 0:i.alignment)!=null?c:(l=(a=(s=e.textParagraphs)==null?void 0:s[0])==null?void 0:a.style)==null?void 0:l.alignment)!=="center")return false;let t=((w=(p=(f=(u=e.textParagraphs)==null?void 0:u[0])==null?void 0:f.text)!=null?p:e.text)!=null?w:"").trim();if(!/^[\u3400-\u9fff]{4,6}$/.test(t))return false;let n=Math.min(e.bounds.width,e.bounds.height),r=Math.max(e.bounds.width,e.bounds.height);return n>0&&r<=11e5&&r/n<1.25}function O0(e){var r,o,i,s,a,l,c;if(H0(e))return true;if(((r=e.textBody)==null?void 0:r.wrap)!=="square")return false;let t=((a=(s=(i=(o=e.textParagraphs)==null?void 0:o[0])==null?void 0:i.text)!=null?s:e.text)!=null?a:"").trim();return t.length<18?false:((c=(l=t.match(/[\u3400-\u9fff]/g))==null?void 0:l.length)!=null?c:0)>=12?true:/[\s,。;、,.]/.test(t)}function $0(e){var n,r,o,i,s;let t=(s=(n=e.textStyle)==null?void 0:n.alignment)!=null?s:(i=(o=(r=e.textParagraphs)==null?void 0:r[0])==null?void 0:o.style)==null?void 0:i.alignment;return t==="right"?"right top":t==="center"?"center top":"top left"}function z0(e){var t;return e.kind!=="textBox"||!e.text&&!((t=e.textParagraphs)!=null&&t.length)||e.customGeometry||Im(e)||Sm(e)?false:!V0(e)&&!G0(e)}function V0(e){var t,n;return (t=e.fillGradient)!=null&&t.colors.length?((n=e.fillGradient.opacities)!=null?n:[]).some(r=>r>0)||!e.fillGradient.opacities:!!(e.fillColor&&e.opacity!==0)}function G0(e){var t,n;return !e.lineColor&&!((t=e.lineGradient)!=null&&t.colors.length)||e.lineOpacity===0?false:((n=e.lineWidth)!=null?n:9525)>0}function j0(e,t){let n=document.createElement("div");n.className="coco-ppt-distributed-text",Array.from(t).forEach(r=>{let o=document.createElement("span");o.textContent=r,n.append(o);}),e.append(n);}function vm(e,t){return t.some(n=>{var r;return !!((r=n.style)!=null&&r.bullet)||U0(n.style)||n.runs.some(o=>!!o.hyperlink||o.style!==void 0&&Y0(o.style,e.textStyle))})}function U0(e){return (e==null?void 0:e.lineHeight)!==void 0||(e==null?void 0:e.marginLeft)!==void 0||(e==null?void 0:e.textIndent)!==void 0||(e==null?void 0:e.spaceBefore)!==void 0||(e==null?void 0:e.spaceAfter)!==void 0}function K0(e,t,n,r={}){if(t){if(t.lineHeight!==void 0&&(e.style.lineHeight=String(_0(t))),t.marginLeft!==void 0&&(e.style.paddingLeft=`${t.marginLeft*n}px`),t.textIndent!==void 0&&(e.style.textIndent=`${t.textIndent*n}px`),r.verticalText){t.spaceBefore!==void 0&&(e.style.marginRight=Vi(t.spaceBefore,n)),t.spaceAfter!==void 0&&(e.style.marginLeft=Vi(t.spaceAfter,n));return}t.spaceBefore!==void 0&&(e.style.marginTop=Vi(t.spaceBefore,n)),t.spaceAfter!==void 0&&(e.style.marginBottom=Vi(t.spaceAfter,n));}}function _0(e){var n;let t=(n=e.lineHeight)!=null?n:1.2;return e.bullet?t*1.15:t}function q0(e,t,n,r=""){(t==null?void 0:t.bulletSize)!==void 0&&(t.bulletSize>4?e.style.fontSize=`${t.bulletSize*12700*n}px`:t.bulletSize>0&&(e.style.fontSize=`${t.bulletSize}em`)),X0(t,r)&&(e.style.width="0.5em",e.style.marginRight="0.12em",e.style.transform="scale(0.62)",e.style.transformOrigin="center",e.style.verticalAlign="middle");}function X0(e,t=""){var o,i;if(!e)return false;let n=(i=(o=e.bulletFontFamily)==null?void 0:o.toLowerCase())!=null?i:"",r=Array.from(t.trim()).length;return e.bullet==="\u25A1"&&e.alignment==="center"&&r>0&&r<=4&&(n.includes("wingdings")||n.includes("webdings"))&&e.textIndent!==void 0&&e.textIndent<0&&e.marginLeft!==void 0&&e.marginLeft<=Math.abs(e.textIndent)*1.25}function Vi(e,t){return e>10?`${e*t}px`:`${e}em`}function Y0(e,t){let n=e,r=t;return e.fontSize!==void 0&&e.fontSize!==(t==null?void 0:t.fontSize)||e.fontFamily!==void 0&&e.fontFamily!==(t==null?void 0:t.fontFamily)||e.color!==void 0&&e.color!==(t==null?void 0:t.color)||n.textFill!==void 0&&n.textFill!==(r==null?void 0:r.textFill)||n.textGradient!==void 0&&n.textGradient!==(r==null?void 0:r.textGradient)||n.textOutlineColor!==void 0&&n.textOutlineColor!==(r==null?void 0:r.textOutlineColor)||n.textShadow!==void 0&&n.textShadow!==(r==null?void 0:r.textShadow)||e.bold!==void 0&&e.bold!==(t==null?void 0:t.bold)||e.italic!==void 0&&e.italic!==(t==null?void 0:t.italic)||e.underline!==void 0&&e.underline!==(t==null?void 0:t.underline)||e.characterSpacing!==void 0&&e.characterSpacing!==(t==null?void 0:t.characterSpacing)}function Z0(e,t,n,r){var i,s,a,l;if(!J0(e,t,n,r))return om(n,n.style);let o=Q0(t.runs.slice(0,r));return om(n,$(v({},n.style),{color:(s=(i=n.style)==null?void 0:i.color)!=null?s:"#000000",fontSize:(l=(a=n.style)==null?void 0:a.fontSize)!=null?l:Math.max(12,Math.round((o!=null?o:28)*.72))}))}function om(e,t){if(!e.hyperlink)return t;let n=v({},t!=null?t:{});return n.textFill===void 0&&n.textGradient===void 0&&(n.color="#0563C1"),n.underline===void 0&&(n.underline=true),n}function J0(e,t,n,r){var a,l,c;if(r<=0||(a=n.style)!=null&&a.color&&n.style.fontSize!==void 0||((l=e.textBody)==null?void 0:l.autoFit)!=="shape"||!/[\u3400-\u9fff]/.test(n.text))return false;let o=t.runs.slice(0,r).map(u=>u.text).join(""),i=/^\s*\d{1,2}\s*[、..,,]\s*(.*)$/u.exec(o);return !i||Array.from((c=i[1])!=null?c:"").filter(u=>/[\u3400-\u9fff]/.test(u)).length>2?false:t.runs.slice(0,r).some(u=>{let f=u.style;return (f==null?void 0:f.color)!==void 0||(f==null?void 0:f.fontSize)!==void 0})}function Q0(e){var t;for(let n of e)if(((t=n.style)==null?void 0:t.fontSize)!==void 0)return n.style.fontSize}function hl(e,t,n){var r,o,i;t.fontSize&&(e.style.fontSize=`${Math.max(1,t.fontSize*12700*n)}px`),t.fontFamily&&(e.style.fontFamily=fl(t.fontFamily)),t.lineHeight&&(e.style.lineHeight=String(t.lineHeight)),t.characterSpacing!==void 0&&(e.style.letterSpacing=`${t.characterSpacing*12700*n}px`),t.color&&(e.style.color=t.color),(r=t.textGradient)!=null&&r.colors.length&&t.textGradient.colors.length>1&&(e.style.backgroundImage=cr(t.textGradient),e.style.backgroundClip="text",e.style.setProperty("-webkit-background-clip","text"),e.style.color="transparent",e.style.setProperty("-webkit-text-fill-color","transparent")),t.textFill==="none"&&(e.style.color=(i=(o=t.textOutlineColor)!=null?o:t.color)!=null?i:"transparent",e.style.setProperty("-webkit-text-fill-color","transparent")),t.textOutlineColor&&e.style.setProperty("-webkit-text-stroke",`1px ${t.textOutlineColor}`),t.textShadow&&(e.style.textShadow=Pm(t.textShadow,n)),t.bold!==void 0&&(e.style.fontWeight=t.bold?"700":"400"),t.italic!==void 0&&(e.style.fontStyle=t.italic?"italic":"normal"),t.underline!==void 0&&(e.style.textDecorationLine=t.underline?"underline":"none");}function gl(e,t){var r;let n=(r=e==null?void 0:e.toLowerCase())!=null?r:"";return n==="image/png"||n==="image/jpeg"||n==="image/jpg"||n==="image/gif"||n==="image/webp"||n==="image/svg+xml"?true:!!(t&&/\.(?:png|jpe?g|gif|webp|svg)$/i.test(t))}function bl(e,t){if(t==="distributed"){e.style.textAlign="justify",e.style.textAlignLast="justify";return}e.style.textAlign=t==="justify"?"justify":t;}function Sm(e){if(e.customGeometry)return false;let t=e.presetGeometry,n=Math.min(e.bounds.width,e.bounds.height),r=Math.max(e.bounds.width,e.bounds.height);return (t==="line"||t==="straightConnector1")&&r>0&&(n===0||n/r<.02)}function km(e){return e.bounds.height>e.bounds.width?"vertical":"horizontal"}function ml(e,t={}){var n;if(e!=null&&e.imagePath){let r=t[e.imagePath],o=r==null?void 0:r.url;if(o&&gl(r.contentType,e.imagePath))return `url("${o}") center / cover no-repeat`}return e!=null&&e.fillGradient&&e.fillGradient.colors.length>1?cr(e.fillGradient):(n=e==null?void 0:e.fillColor)!=null?n:"#fff"}function ek(e,t,n,r,o,i){if(t!=null&&t.imagePath){let s=i[t.imagePath],a=s==null?void 0:s.url;if(a&&gl(s.contentType,t.imagePath)){e.style.backgroundImage=`url("${a}")`,e.style.backgroundRepeat="no-repeat",e.style.backgroundSize=`${r.size.width*o}px ${r.size.height*o}px`,e.style.backgroundPosition=`${-n.bounds.left*o}px ${-n.bounds.top*o}px`;return}}e.style.background=ml(t,i);}function ar(e){var r;let t=(r=e.presetAdjustments)==null?void 0:r.adj,n=t===void 0?.08:Math.max(0,Math.min(.5,t/1e5));return Math.min(e.bounds.width,e.bounds.height)*n}function tk(e,t){var o,i,s;let n=(s=(o=e.presetAdjustments)==null?void 0:o.adj)!=null?s:(i=e.presetAdjustments)==null?void 0:i.adj1,r=n===void 0?.125:Math.max(.02,Math.min(.45,n/1e5));return Math.max(1,Math.min(e.bounds.width,e.bounds.height)*r*t)}function nk(e){return !e.customGeometry&&e.kind!=="line"&&!e.lineColor&&!!e.lineGradient&&e.lineGradient.colors.length>1&&(e.presetGeometry==="roundRect"||e.presetGeometry==="round1Rect"||e.presetGeometry==="ellipse")}function rk(e,t,n){var o;let r=document.createElement("div");return r.className="coco-ppt-css-geometry",r.style.clipPath=n,e.fillGradient&&e.fillGradient.colors.length>1?r.style.background=cr(e.fillGradient,dr(e)):e.fillColor&&(r.style.background=lr(e.fillColor,dr(e))),e.lineColor&&(r.style.borderStyle=wl(e.lineDash),r.style.borderWidth=`${Math.max(1,((o=e.lineWidth)!=null?o:9525)*t)}px`,r.style.borderColor=lr(e.lineColor,e.lineOpacity)),r}function cr(e,t=1){return `linear-gradient(${Em(e)}deg, ${ik(e,t).join(", ")})`}function Em(e){return e.angle===void 0?160:ok(e.angle+90)}function ok(e){return (e%360+360)%360}function ik(e,t=1){return ak(e).map(n=>{let r=Math.max(0,Math.min(1,n.opacity*t)),o=r<1?Cm(n.color,r):n.color;return n.position===void 0?o:`${o} ${n.position}%`})}function ak(e){return e.colors.map((t,n)=>{var s,a,l,c,u;let r=xl(t),o=(s=e.positions)==null?void 0:s[n],i=Math.max(0,Math.min(1,(c=(l=(a=e.opacities)==null?void 0:a[n])!=null?l:r==null?void 0:r.opacity)!=null?c:1));return {color:(u=r==null?void 0:r.color)!=null?u:t,position:o===void 0?void 0:Math.max(0,Math.min(100,o)),opacity:i,index:n}}).sort((t,n)=>t.position===void 0&&n.position===void 0?t.index-n.index:t.position===void 0?1:n.position===void 0?-1:t.position-n.position||t.index-n.index).map(({color:t,position:n,opacity:r})=>({color:t,position:n,opacity:r}))}function Cm(e,t){var s;let n=(s=e.match(/^#([0-9a-fA-F]{6})$/))==null?void 0:s[1];if(!n)return e;let r=Number.parseInt(n.slice(0,2),16),o=Number.parseInt(n.slice(2,4),16),i=Number.parseInt(n.slice(4,6),16);return `rgba(${r}, ${o}, ${i}, ${Math.max(0,Math.min(1,t))})`}function sk(e){switch(e){case "parallelogram":return "polygon(18% 0, 100% 0, 82% 100%, 0 100%)";case "trapezoid":return "polygon(18% 0, 82% 0, 100% 100%, 0 100%)";case "snip2DiagRect":return "polygon(8% 0, 100% 0, 100% 92%, 92% 100%, 0 100%, 0 8%)";case "rtTriangle":return "polygon(0 0, 100% 100%, 0 100%)";case "triangle":return "polygon(50% 0, 100% 100%, 0 100%)";case "diamond":return "polygon(50% 0, 100% 50%, 50% 100%, 0 50%)";case "pentagon":return "polygon(0 0, 72% 0, 100% 50%, 72% 100%, 0 100%, 22% 50%)";case "hexagon":return "polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%)";case "homePlate":return "polygon(50% 0, 100% 25%, 100% 100%, 0 100%, 0 25%)";case "leftRightArrow":return "polygon(0 50%, 18% 0, 82% 0, 100% 50%, 82% 100%, 18% 100%)";case "chevron":return "polygon(0 0, 72% 0, 100% 50%, 72% 100%, 0 100%, 28% 50%)";case "plaque":return "polygon(0 12%, 3% 12%, 3% 0, 97% 0, 97% 12%, 100% 12%, 100% 88%, 97% 88%, 97% 100%, 3% 100%, 3% 88%, 0 88%)";case "rightArrow":return "polygon(0 0, 78% 0, 100% 50%, 78% 100%, 0 100%)";case "leftArrow":return "polygon(22% 0, 100% 0, 100% 100%, 22% 100%, 0 50%)";case "bentArrow":return "polygon(0 0, 30% 0, 30% 58%, 82% 58%, 82% 35%, 100% 70%, 82% 100%, 82% 77%, 12% 77%, 12% 18%, 0 18%)";default:return}}function wl(e){return e==="dot"||e==="sysDot"?"dotted":e&&e!=="solid"?"dashed":"solid"}function Zi(e,t){if(!e||e==="solid"||t<=0)return;let n=Math.max(1,t),r=/^cust:(\d+):(\d+)$/i.exec(e);if(r){let o=Number(r[1])/1e5,i=Number(r[2])/1e5;if(o>0&&i>=0)return `${n*o} ${n*i}`}switch(e){case "dot":case "sysDot":return `${n} ${n*2}`;case "dash":case "sysDash":return `${n*4} ${n*2}`;case "dashDot":case "sysDashDot":return `${n*4} ${n*2} ${n} ${n*2}`;case "lgDash":return `${n*8} ${n*3}`;case "lgDashDot":return `${n*8} ${n*3} ${n} ${n*3}`;case "lgDashDotDot":return `${n*8} ${n*3} ${n} ${n*3} ${n} ${n*3}`;default:return `${n*4} ${n*2}`}}function Im(e){return e.presetGeometry==="curvedUpArrow"||e.presetGeometry==="donut"||e.presetGeometry==="arc"||e.presetGeometry==="blockArc"||e.presetGeometry==="plaque"||e.presetGeometry==="parallelogram"||e.presetGeometry==="trapezoid"||e.presetGeometry==="snip2DiagRect"||e.presetGeometry==="rtTriangle"||e.presetGeometry==="triangle"||e.presetGeometry==="diamond"||e.presetGeometry==="pentagon"||e.presetGeometry==="hexagon"||e.presetGeometry==="homePlate"||e.presetGeometry==="leftRightArrow"||e.presetGeometry==="chevron"||e.presetGeometry==="rightArrow"||e.presetGeometry==="leftArrow"||e.presetGeometry==="bentArrow"}function lk(e,t){var p,w,b;let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.classList.add("coco-ppt-preset-geometry");let r=Math.max(1,e.bounds.width*t),o=Math.max(1,e.bounds.height*t),i=dk(e,t,r,o);(e.shadow||i>0)&&(n.style.overflow="visible"),n.setAttribute("viewBox","0 0 100 100"),n.setAttribute("preserveAspectRatio","none");let s=e.fillGradient&&e.fillGradient.colors.length>1?`coco-ppt-preset-gradient-${e.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`:void 0,a=e.lineGradient&&e.lineGradient.colors.length>1?`coco-ppt-preset-line-gradient-${e.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`:void 0;if(s&&e.fillGradient&&Hn(n,s,e.fillGradient),a&&e.lineGradient&&Hn(n,a,e.lineGradient),i>0){let g=document.createElementNS("http://www.w3.org/2000/svg","path");g.classList.add("coco-ppt-preset-extrusion"),g.setAttribute("d",im(e)),(e.presetGeometry==="donut"||e.presetGeometry==="blockArc")&&g.setAttribute("fill-rule","evenodd"),g.setAttribute("fill",ck(e)),g.setAttribute("transform",`translate(${or(i*.38)} ${or(i)})`),g.setAttribute("stroke","none"),n.append(g);}let l=document.createElementNS("http://www.w3.org/2000/svg","path");l.setAttribute("d",im(e)),(e.presetGeometry==="donut"||e.presetGeometry==="blockArc")&&l.setAttribute("fill-rule","evenodd");let c=e.lineColor||e.lineGradient?Math.max(.5,((p=e.lineWidth)!=null?p:9525)*t*100/Math.max(r,o)):0;l.setAttribute("fill",e.presetGeometry==="arc"?"none":s?`url(#${s})`:(w=e.fillColor)!=null?w:"none");let u=dr(e);u!==void 0&&e.presetGeometry!=="arc"&&l.setAttribute("fill-opacity",String(u)),l.setAttribute("stroke",a?`url(#${a})`:(b=e.lineColor)!=null?b:"none"),l.setAttribute("stroke-width",String(c)),e.lineOpacity!==void 0&&l.setAttribute("stroke-opacity",String(Math.max(0,Math.min(1,e.lineOpacity))));let f=Zi(e.lineDash,c);return f&&l.setAttribute("stroke-dasharray",f),l.setAttribute("stroke-linejoin","round"),e.presetGeometry==="arc"&&(l.setAttribute("stroke-linecap","round"),hk(n,l,e)),n.append(l),n}function dk(e,t,n,r){var s,a;let o=(a=(s=e.threeD)==null?void 0:s.extrusionHeight)!=null?a:0;if(o<=0||e.presetGeometry==="arc")return 0;let i=o*t*100/Math.max(n,r);return Math.max(.8,Math.min(3,i))}function ck(e){var o,i,s,a,l;let t=(s=(i=(o=e.fillGradient)==null?void 0:o.colors[0])!=null?i:e.fillColor)!=null?s:"#64748B",n=xl(t),r=((a=e.threeD)==null?void 0:a.material)==="translucentPowder"?.12:.18;return Cm(uk((l=n==null?void 0:n.color)!=null?l:t,.8),r)}function uk(e,t){let n=/^#?([0-9a-f]{6})$/i.exec(e);if(!n)return e;let r=n[1],o=Number.parseInt(r.slice(0,2),16),i=Number.parseInt(r.slice(2,4),16),s=Number.parseInt(r.slice(4,6),16);return `#${sr(o*t)}${sr(i*t)}${sr(s*t)}`}function im(e){switch(e.presetGeometry){case "curvedUpArrow":return ["M 16 88","C 3 61 9 28 38 13","C 60 2 87 9 97 34","L 82 36","C 74 22 59 18 45 24","C 23 33 17 61 28 82","Z","M 76 21","L 100 38","L 74 53","Z"].join(" ");case "donut":return ["M 50 2","A 48 48 0 1 1 49.99 2","M 50 27","A 23 23 0 1 0 50.01 27"].join(" ");case "blockArc":return pk(e);case "plaque":return "M 4 0 H 96 Q 96 8 100 8 V 92 Q 96 92 96 100 H 4 Q 4 92 0 92 V 8 Q 4 8 4 0 Z";case "parallelogram":return "M 18 0 H 100 L 82 100 H 0 Z";case "trapezoid":return "M 18 0 H 82 L 100 100 H 0 Z";case "snip2DiagRect":return "M 8 0 H 100 V 92 L 92 100 H 0 V 8 Z";case "rtTriangle":return "M 0 0 L 100 100 H 0 Z";case "triangle":return "M 50 0 L 100 100 H 0 Z";case "diamond":return "M 50 0 L 100 50 L 50 100 L 0 50 Z";case "pentagon":return "M 0 0 H 72 L 100 50 L 72 100 H 0 L 22 50 Z";case "hexagon":return "M 25 0 H 75 L 100 50 L 75 100 H 25 L 0 50 Z";case "homePlate":return "M 50 0 L 100 25 V 100 H 0 V 25 Z";case "leftRightArrow":return "M 0 50 L 18 0 H 82 L 100 50 L 82 100 H 18 Z";case "chevron":return "M 0 0 H 72 L 100 50 L 72 100 H 0 L 28 50 Z";case "rightArrow":return "M 0 0 H 78 L 100 50 L 78 100 H 0 Z";case "leftArrow":return "M 22 0 H 100 V 100 H 22 L 0 50 Z";case "bentArrow":return "M 0 0 H 30 V 58 H 82 V 35 L 100 70 L 82 100 V 77 H 12 V 18 H 0 Z";case "arc":return mk(e);default:return ""}}function pk(e){var g,h,y,k,C,N;let t=((h=(g=e.presetAdjustments)==null?void 0:g.adj1)!=null?h:0)/6e4,n=((k=(y=e.presetAdjustments)==null?void 0:y.adj2)!=null?k:54e5)/6e4,r=fk(n-t),o=t+r,i=48,s=Math.max(.08,Math.min(.42,((N=(C=e.presetAdjustments)==null?void 0:C.adj3)!=null?N:25e3)/1e5)),a=i*(1-s),l=lo(t,i),c=lo(o,i),u=lo(o,a),f=lo(t,a),p=Math.abs(r)>180?1:0,w=r>=0?1:0,b=w?0:1;return [`M ${l.x.toFixed(3)} ${l.y.toFixed(3)}`,`A ${i} ${i} 0 ${p} ${w} ${c.x.toFixed(3)} ${c.y.toFixed(3)}`,`L ${u.x.toFixed(3)} ${u.y.toFixed(3)}`,`A ${a.toFixed(3)} ${a.toFixed(3)} 0 ${p} ${b} ${f.x.toFixed(3)} ${f.y.toFixed(3)}`,"Z"].join(" ")}function fk(e){if(!Number.isFinite(e)||e===0)return 90;let t=e%360;return t>330&&(t=330),t<-330&&(t=-330),Math.abs(t)<8&&(t=t<0?-8:8),t}function mk(e){var a,l,c,u,f,p,w,b;let t=am((l=(a=e.presetAdjustments)==null?void 0:a.adj1)!=null?l:18e6),n=am((u=(c=e.presetAdjustments)==null?void 0:c.adj2)!=null?u:0),r=((p=(f=e.presetAdjustments)==null?void 0:f.adj1)!=null?p:18e6)/6e4,s=((((b=(w=e.presetAdjustments)==null?void 0:w.adj2)!=null?b:0)/6e4-r)%360+360)%360>180?1:0;return `M ${t.x.toFixed(3)} ${t.y.toFixed(3)} A 48 48 0 ${s} 1 ${n.x.toFixed(3)} ${n.y.toFixed(3)}`}function am(e){return lo(e/6e4,48)}function lo(e,t){let n=e/180*Math.PI;return {x:50+t*Math.cos(n),y:50+t*Math.sin(n)}}function hk(e,t,n){var s,a;if(n.lineHeadEnd!=="triangle"&&n.lineTailEnd!=="triangle")return;let r=`coco-ppt-arc-arrow-${n.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`,o=document.createElementNS("http://www.w3.org/2000/svg","marker");o.setAttribute("id",r),o.setAttribute("viewBox","0 0 10 10"),o.setAttribute("markerWidth","7"),o.setAttribute("markerHeight","7"),o.setAttribute("refX","5"),o.setAttribute("refY","5"),o.setAttribute("orient","auto-start-reverse");let i=document.createElementNS("http://www.w3.org/2000/svg","path");i.setAttribute("d","M 0 0 L 10 5 L 0 10 Z"),i.setAttribute("fill",(a=(s=n.lineColor)!=null?s:n.fillColor)!=null?a:"#000000"),o.append(i),e.append(o),n.lineHeadEnd==="triangle"&&t.setAttribute("marker-start",`url(#${r})`),n.lineTailEnd==="triangle"&&t.setAttribute("marker-end",`url(#${r})`);}function gk(e,t){if(!e.customGeometry||bk(e.customGeometry))return false;let n=Math.max(0,e.bounds.width)*Math.max(0,e.bounds.height),r=Math.max(1,t.size.width*t.size.height),o=n/r>.85,i=Math.abs(e.bounds.left)<t.size.width*.05&&Math.abs(e.bounds.top)<t.size.height*.05;return !(o&&i)}function bk(e){var a,l;if(e.paths.length!==1)return false;let t=e.paths[0];if(!t)return false;let n=(a=t.width)!=null?a:0,r=(l=t.height)!=null?l:0;if(n<=0||r<=0)return false;let o=[];for(let c of t.commands)if(c.kind==="moveTo"||c.kind==="lineTo")o.push({x:c.x,y:c.y});else if(c.kind!=="close")return false;let i=wk(o);return i.length!==4&&i.length!==5?false:[{x:0,y:0},{x:n,y:0},{x:n,y:r},{x:0,y:r}].every(c=>i.some(u=>qi(u.x,c.x)&&qi(u.y,c.y)))}function wk(e){let t=[];for(let n of e)t.some(r=>qi(r.x,n.x)&&qi(r.y,n.y))||t.push(n);return t}function qi(e,t){return Math.abs(e-t)<=1}function xk(e,t){var u,f,p,w,b,g,h,y;let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.classList.add("coco-ppt-custom-geometry","coco-ppt-picture-clip");let r=Math.max(1,(p=(f=(u=e.customGeometry)==null?void 0:u.paths[0])==null?void 0:f.width)!=null?p:e.bounds.width),o=Math.max(1,(g=(b=(w=e.customGeometry)==null?void 0:w.paths[0])==null?void 0:b.height)!=null?g:e.bounds.height);n.setAttribute("viewBox",`0 0 ${r} ${o}`),n.setAttribute("preserveAspectRatio","none");let i=`coco-ppt-picture-clip-${e.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`,s=document.createElementNS("http://www.w3.org/2000/svg","defs"),a=document.createElementNS("http://www.w3.org/2000/svg","clipPath");a.setAttribute("id",i);for(let k of (y=(h=e.customGeometry)==null?void 0:h.paths)!=null?y:[]){let C=document.createElementNS("http://www.w3.org/2000/svg","path");C.setAttribute("d",Tm(k.commands)),Nm(k.commands)&&C.setAttribute("fill-rule","evenodd"),a.append(C);}s.append(a),n.append(s);let l=document.createElementNS("http://www.w3.org/2000/svg","image");l.setAttribute("href",t),l.setAttributeNS("http://www.w3.org/1999/xlink","href",t);let c=yk(e,r,o);return l.setAttribute("x",String(c.x)),l.setAttribute("y",String(c.y)),l.setAttribute("width",String(c.width)),l.setAttribute("height",String(c.height)),l.setAttribute("preserveAspectRatio","none"),l.setAttribute("clip-path",`url(#${i})`),e.imageOpacity!==void 0&&l.setAttribute("opacity",String(Math.max(0,Math.min(1,e.imageOpacity)))),n.append(l),n}function yk(e,t,n){var u,f,p,w,b,g,h,y;if(e.imageFillRect){let k=(u=e.imageFillRect.left)!=null?u:0,C=(f=e.imageFillRect.right)!=null?f:0,N=(p=e.imageFillRect.top)!=null?p:0,L=(w=e.imageFillRect.bottom)!=null?w:0;return {x:k*t,y:N*n,width:Math.max(.01,1-k-C)*t,height:Math.max(.01,1-N-L)*n}}let r=e.imageCrop;if(!r)return {x:0,y:0,width:t,height:n};let o=(b=r.left)!=null?b:0,i=(g=r.right)!=null?g:0,s=(h=r.top)!=null?h:0,a=(y=r.bottom)!=null?y:0,l=Math.max(.01,1-o-i),c=Math.max(.01,1-s-a);return {x:-o/l*t,y:-s/c*n,width:1/l*t,height:1/c*n}}function vk(e,t){var a,l,c,u,f,p,w,b,g,h;let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.classList.add("coco-ppt-custom-geometry");let r=(c=(l=(a=e.customGeometry)==null?void 0:a.paths[0])==null?void 0:l.width)!=null?c:e.bounds.width,o=(p=(f=(u=e.customGeometry)==null?void 0:u.paths[0])==null?void 0:f.height)!=null?p:e.bounds.height;n.setAttribute("viewBox",`0 0 ${Math.max(1,r)} ${Math.max(1,o)}`),n.setAttribute("preserveAspectRatio","none");let i=e.fillGradient&&e.fillGradient.colors.length>1?`coco-ppt-gradient-${e.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`:void 0,s=e.lineGradient&&e.lineGradient.colors.length>1?`coco-ppt-custom-line-gradient-${e.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`:void 0;i&&e.fillGradient&&Hn(n,i,e.fillGradient),s&&e.lineGradient&&Hn(n,s,e.lineGradient);for(let y of (b=(w=e.customGeometry)==null?void 0:w.paths)!=null?b:[]){let k=kk(e,y),C=Sk(y),N=C?document.createElementNS("http://www.w3.org/2000/svg","ellipse"):document.createElementNS("http://www.w3.org/2000/svg","path");C?(N.setAttribute("cx",String(C.cx)),N.setAttribute("cy",String(C.cy)),N.setAttribute("rx",String(C.rx)),N.setAttribute("ry",String(C.ry))):(N.setAttribute("d",Tm(y.commands)),Nm(y.commands)&&N.setAttribute("fill-rule","evenodd"));let L=!(e.kind==="line"&&e.lineDash);N.setAttribute("fill",L?i?`url(#${i})`:(g=e.fillColor)!=null?g:"none":"none");let D=dr(e);L&&D!==void 0&&N.setAttribute("fill-opacity",String(D)),N.setAttribute("stroke",s?`url(#${s})`:(h=e.lineColor)!=null?h:"none"),N.setAttribute("stroke-width",String(k)),e.lineOpacity!==void 0&&N.setAttribute("stroke-opacity",String(Math.max(0,Math.min(1,e.lineOpacity))));let W=Zi(e.lineDash,k);W&&N.setAttribute("stroke-dasharray",W),N.setAttribute("stroke-linejoin","round"),N.setAttribute("stroke-linecap","round"),n.append(N);}return n}function Sk(e){var u,f,p,w,b,g;let t=e.width,n=e.height;if(!t||!n||t<=0||n<=0)return;let r=e.commands;if(r.length!==6||((u=r[0])==null?void 0:u.kind)!=="moveTo"||((f=r[1])==null?void 0:f.kind)!=="cubicBezierTo"||((p=r[2])==null?void 0:p.kind)!=="cubicBezierTo"||((w=r[3])==null?void 0:w.kind)!=="cubicBezierTo"||((b=r[4])==null?void 0:b.kind)!=="cubicBezierTo"||((g=r[5])==null?void 0:g.kind)!=="close")return;let o=t/2,i=n/2,s=[r[0],r[1],r[2],r[3],r[4]],a=[{x:t,y:i},{x:o,y:n},{x:0,y:i},{x:o,y:0},{x:t,y:i}],l=Math.max(t,n)*.003;return s.every((h,y)=>h.kind!=="moveTo"&&h.kind!=="cubicBezierTo"?false:Math.abs(h.x-a[y].x)<=l&&Math.abs(h.y-a[y].y)<=l)?{cx:o,cy:i,rx:t/2,ry:n/2}:void 0}function Nm(e){return e.filter(t=>t.kind==="moveTo").length>1}function kk(e,t){if(!e.lineWidth)return 0;let n=t.width&&e.bounds.width?t.width/e.bounds.width:void 0,r=t.height&&e.bounds.height?t.height/e.bounds.height:void 0,o=[n,r].filter(s=>s!==void 0&&Number.isFinite(s)&&s>0),i=o.length>0?Math.max(...o):1;return Math.max(.5,e.lineWidth*i)}function Ek(e,t){var u;let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.classList.add("coco-ppt-gradient-outline");let r=Math.max(1,e.bounds.width*t),o=Math.max(1,e.bounds.height*t),i=Math.max(1,((u=e.lineWidth)!=null?u:9525)*t),s=i/2,a=`coco-ppt-line-gradient-${e.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`;n.setAttribute("viewBox",`0 0 ${r} ${o}`),n.setAttribute("preserveAspectRatio","none"),Hn(n,a,e.lineGradient);let l=e.presetGeometry==="ellipse"?document.createElementNS("http://www.w3.org/2000/svg","ellipse"):document.createElementNS("http://www.w3.org/2000/svg","rect");l.tagName==="ellipse"?(l.setAttribute("cx",String(r/2)),l.setAttribute("cy",String(o/2)),l.setAttribute("rx",String(Math.max(0,r/2-s))),l.setAttribute("ry",String(Math.max(0,o/2-s)))):(l.setAttribute("x",String(s)),l.setAttribute("y",String(s)),l.setAttribute("width",String(Math.max(0,r-i))),l.setAttribute("height",String(Math.max(0,o-i))),l.setAttribute("rx",String(Math.max(0,ar(e)*t-s))),l.setAttribute("ry",String(Math.max(0,ar(e)*t-s)))),l.setAttribute("fill","none"),l.setAttribute("stroke",`url(#${a})`),l.setAttribute("stroke-width",String(i)),e.lineOpacity!==void 0&&l.setAttribute("stroke-opacity",String(Math.max(0,Math.min(1,e.lineOpacity))));let c=Zi(e.lineDash,i);return c&&l.setAttribute("stroke-dasharray",c),n.append(l),n}function Ck(e,t){var u,f;let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.classList.add("coco-ppt-solid-outline");let r=Math.max(1,e.bounds.width*t),o=Math.max(1,e.bounds.height*t),i=Math.max(1,((u=e.lineWidth)!=null?u:9525)*t),s=e.kind!=="picture",a=s?i/2:0;s||(n.style.overflow="visible"),n.setAttribute("viewBox",`0 0 ${r} ${o}`),n.setAttribute("preserveAspectRatio","none");let l=e.presetGeometry==="ellipse"?document.createElementNS("http://www.w3.org/2000/svg","ellipse"):document.createElementNS("http://www.w3.org/2000/svg","rect");if(l.tagName==="ellipse")l.setAttribute("cx",String(r/2)),l.setAttribute("cy",String(o/2)),l.setAttribute("rx",String(Math.max(0,r/2-a))),l.setAttribute("ry",String(Math.max(0,o/2-a)));else {l.setAttribute("x",String(a)),l.setAttribute("y",String(a)),l.setAttribute("width",String(Math.max(0,r-a*2))),l.setAttribute("height",String(Math.max(0,o-a*2)));let p=e.presetGeometry==="roundRect"||e.presetGeometry==="round1Rect"?Math.max(0,ar(e)*t-a):0;l.setAttribute("rx",String(p)),l.setAttribute("ry",String(p));}l.setAttribute("fill","none"),l.setAttribute("stroke",(f=e.lineColor)!=null?f:"none"),l.setAttribute("stroke-width",String(i)),e.lineOpacity!==void 0&&l.setAttribute("stroke-opacity",String(Math.max(0,Math.min(1,e.lineOpacity))));let c=Zi(e.lineDash,i);return c&&l.setAttribute("stroke-dasharray",c),n.append(l),n}function Ik(e,t){var b,g;let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.classList.add("coco-ppt-line-geometry");let r=km(e)==="vertical",o=Math.max(r?12:1,e.bounds.width*t),i=Math.max(r?1:12,e.bounds.height*t);n.setAttribute("viewBox",`0 0 ${o} ${i}`),n.setAttribute("preserveAspectRatio","none");let s=Math.max(1,((b=e.lineWidth)!=null?b:9525)*t),a=e.lineGradient&&e.lineGradient.colors.length>1?`coco-ppt-connector-gradient-${e.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`:void 0;a&&e.lineGradient&&Hn(n,a,e.lineGradient);let l=a?`url(#${a})`:lr((g=e.lineColor)!=null?g:"#000000",e.lineOpacity),c=Nk(s),u=Math.max(5,s*3.2),f=Math.max(5,s*2.6),p=sm(e.lineHeadEnd),w=sm(e.lineTailEnd);if(r){let h=o/2,y=p?Math.min(i,u):0,k=w?Math.max(0,i-u):i;ur(n,h,y,h,k,l,s,e.lineOpacity,e.lineCap),e.lineHeadEnd==="oval"&&yn(n,h,0,c,l),e.lineTailEnd==="oval"&&yn(n,h,i,c,l),p&&Ui(n,h,0,"up",u,f,l,e.lineOpacity),w&&Ui(n,h,i,"down",u,f,l,e.lineOpacity);}else {let h=i/2,y=p?Math.min(o,u):0,k=w?Math.max(0,o-u):o;ur(n,y,h,k,h,l,s,e.lineOpacity,e.lineCap),e.lineHeadEnd==="oval"&&yn(n,0,h,c,l),e.lineTailEnd==="oval"&&yn(n,o,h,c,l),p&&Ui(n,0,h,"left",u,f,l,e.lineOpacity),w&&Ui(n,o,h,"right",u,f,l,e.lineOpacity);}return n}function Nk(e){return Math.max(3,e*3)}function sm(e){return e==="arrow"||e==="triangle"}function Tm(e){let t=[],n;for(let r of e)if(r.kind==="moveTo")t.push(`M ${r.x} ${r.y}`),n={x:r.x,y:r.y};else if(r.kind==="lineTo")t.push(`L ${r.x} ${r.y}`),n={x:r.x,y:r.y};else if(r.kind==="cubicBezierTo")t.push(`C ${r.x1} ${r.y1} ${r.x2} ${r.y2} ${r.x} ${r.y}`),n={x:r.x,y:r.y};else if(r.kind==="arcTo"){let o=Tk(r,n);o&&(t.push(o.path),n=o.end);}else t.push("Z");return t.join(" ")}function Tk(e,t){if(!t||e.wR<=0||e.hR<=0||e.swAng===0)return;let n=e.stAng/6e4,r=e.swAng/6e4,o=n+r,i=lm(e.wR,e.hR,n),s={x:t.x-i.x,y:t.y-i.y},a=lm(e.wR,e.hR,o),l={x:s.x+a.x,y:s.y+a.y},c=Math.abs(r)>180?1:0,u=r>=0?1:0;return {path:`A ${or(e.wR)} ${or(e.hR)} 0 ${c} ${u} ${or(l.x)} ${or(l.y)}`,end:l}}function lm(e,t,n){let r=n/180*Math.PI;return {x:e*Math.cos(r),y:t*Math.sin(r)}}function or(e){return Number.isInteger(e)?String(e):e.toFixed(3).replace(/\.?0+$/,"")}function Hn(e,t,n){let r=document.createElementNS("http://www.w3.org/2000/svg","defs"),o=Array.isArray(n)?n:n.colors,i=Array.isArray(n)?void 0:n.positions,s=Array.isArray(n)?void 0:n.opacities,a=document.createElementNS("http://www.w3.org/2000/svg","linearGradient"),l=Array.isArray(n)?{x1:0,y1:0,x2:100,y2:100}:Pk(Em(n));a.setAttribute("id",t),a.setAttribute("x1",`${l.x1}%`),a.setAttribute("y1",`${l.y1}%`),a.setAttribute("x2",`${l.x2}%`),a.setAttribute("y2",`${l.y2}%`),o.map((c,u)=>{var b,g,h,y;let f=(b=i==null?void 0:i[u])!=null?b:u/Math.max(1,o.length-1)*100,p=xl(c),w=Math.max(0,Math.min(1,(h=(g=s==null?void 0:s[u])!=null?g:p==null?void 0:p.opacity)!=null?h:1));return {color:(y=p==null?void 0:p.color)!=null?y:c,offset:Math.max(0,Math.min(100,f)),opacity:w}}).sort((c,u)=>c.offset-u.offset).forEach(c=>{let u=document.createElementNS("http://www.w3.org/2000/svg","stop");u.setAttribute("offset",`${c.offset}%`),u.setAttribute("stop-color",c.color),c.opacity<1&&u.setAttribute("stop-opacity",String(c.opacity)),a.append(u);}),r.append(a),e.append(r);}function Pk(e){let t=e*Math.PI/180,n=Math.sin(t),r=-Math.cos(t),o=50/Math.max(Math.abs(n),Math.abs(r),1e-4);return {x1:Gi(50-n*o),y1:Gi(50-r*o),x2:Gi(50+n*o),y2:Gi(50+r*o)}}function Gi(e){return Math.round(Math.max(0,Math.min(100,e))*1e3)/1e3}function xl(e){let t=/^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})(?:\s*,\s*([0-9.]+)\s*)?\)$/i.exec(e);if(!t)return;let n=Math.max(0,Math.min(255,Number(t[1]))),r=Math.max(0,Math.min(255,Number(t[2]))),o=Math.max(0,Math.min(255,Number(t[3]))),i=t[4]===void 0?1:Math.max(0,Math.min(1,Number(t[4])));return {color:`#${sr(n)}${sr(r)}${sr(o)}`,opacity:i}}function sr(e){return Math.round(e).toString(16).padStart(2,"0").toUpperCase()}function Mk(e,t,n=true){var c,u,f,p,w,b,g,h,y,k,C,N,L,D,W;let r=document.createElement("table");r.className="coco-ppt-table";let o=e.table;if(!o)return r;let i=Math.max(o.rowCount,o.values.length),s=Math.max(o.columnCount,...o.values.map(V=>V.length),1),a=(u=(c=o.columnWidths)==null?void 0:c.reduce((V,ee)=>V+ee,0))!=null?u:0;if(a>0){let V=document.createElement("colgroup");for(let ee=0;ee<s;ee++){let pe=document.createElement("col"),re=(f=o.columnWidths)==null?void 0:f[ee];re&&(pe.style.width=`${re/a*100}%`),V.append(pe);}r.append(V);}let l=(w=(p=o.rowHeights)==null?void 0:p.reduce((V,ee)=>V+ee,0))!=null?w:0;for(let V=0;V<i;V++){let ee=document.createElement("tr"),pe=(b=o.rowHeights)==null?void 0:b[V];ee.style.height=l>0&&pe?`${pe/l*100}%`:`${100/i}%`;for(let re=0;re<s;re++){let we=Bk(o,V,re);if(we!=null&&we.hMerge||we!=null&&we.vMerge)continue;let he=document.createElement("td"),xe=(h=(g=o.cellStyles)==null?void 0:g[V])==null?void 0:h[re];n&&(he.dataset.row=String(V),he.dataset.column=String(re));let Ve=(k=(y=o.values[V])==null?void 0:y[re])!=null?k:"";if(he.dataset.cellText=Ve,Ak(he,Ve),we!=null&&we.columnSpan&&we.columnSpan>1&&(he.colSpan=we.columnSpan),we!=null&&we.rowSpan&&we.rowSpan>1&&(he.rowSpan=we.rowSpan),xe!=null&&xe.fillGradient&&xe.fillGradient.colors.length>1?he.style.background=cr(xe.fillGradient):xe!=null&&xe.fillColor&&!Lk(xe.fillColor)&&(he.style.background=xe.fillColor),xe!=null&&xe.body){let z=xe.body,Z=(C=z.insetLeft)!=null?C:91440,H=(N=z.insetTop)!=null?N:45720,Y=(L=z.insetRight)!=null?L:91440,X=(D=z.insetBottom)!=null?D:45720;he.style.padding=`${H*t}px ${Y*t}px ${X*t}px ${Z*t}px`,z.anchor==="middle"&&(he.style.verticalAlign="middle"),z.anchor==="bottom"&&(he.style.verticalAlign="bottom"),z.anchor==="top"&&(he.style.verticalAlign="top");}xe!=null&&xe.textStyle&&hl(he,xe.textStyle,t),(W=xe==null?void 0:xe.textStyle)!=null&&W.alignment&&bl(he,xe.textStyle.alignment),Rk(he,xe,t),ee.append(he);}r.append(ee);}return r}function Rk(e,t,n){let r=t==null?void 0:t.borders;r&&(ji(e,"Left",r.left,n),ji(e,"Right",r.right,n),ji(e,"Top",r.top,n),ji(e,"Bottom",r.bottom,n));}function ji(e,t,n,r){var a,l;if(!n)return;let o=`border${t}Style`,i=`border${t}Width`,s=`border${t}Color`;if(n.hidden){e.style[o]="none",e.style[i]="0";return}e.style[o]=wl(n.dash),e.style[i]=`${Math.max(1,((a=n.width)!=null?a:9525)*r)}px`,e.style[s]=lr((l=n.color)!=null?l:"#94A3B8",n.opacity);}function Ak(e,t){let n=t.split(/\r?\n/);if(n.length<=1){e.textContent=t;return}n.forEach((r,o)=>{o>0&&e.append(document.createElement("br"));let i=document.createElement("span");i.textContent=r,o>0&&(i.className="coco-ppt-table-cell-secondary-line",i.style.fontSize="0.7em",i.style.fontWeight="400"),e.append(i);});}function dm(e,t,n,r){var o,i,s,a,l;return (l=(a=(s=e.dataset.cellText)!=null?s:(i=(o=t.table)==null?void 0:o.values[n])==null?void 0:i[r])!=null?a:e.textContent)!=null?l:""}function Lk(e){let t=/^#?([0-9a-f]{6})$/i.exec(e);if(!t)return false;let n=t[1],r=Number.parseInt(n.slice(0,2),16),o=Number.parseInt(n.slice(2,4),16),i=Number.parseInt(n.slice(4,6),16);return (.2126*r+.7152*o+.0722*i)/255>.9}function Pm(e,t){var a,l,c;let n=((a=e.distance)!=null?a:0)*t,r=((l=e.direction)!=null?l:0)*Math.PI/180,o=Math.cos(r)*n,i=Math.sin(r)*n,s=((c=e.blur)!=null?c:0)*t;return `${o}px ${i}px ${s}px ${Wk(e)}`}function Wk(e){var l,c;let t=(l=e.color)!=null?l:"#000000",n=(c=e.opacity)!=null?c:.25,r=/^#?([0-9a-f]{6})$/i.exec(t);if(!r)return t;let o=r[1],i=Number.parseInt(o.slice(0,2),16),s=Number.parseInt(o.slice(2,4),16),a=Number.parseInt(o.slice(4,6),16);return `rgba(${i}, ${s}, ${a}, ${Math.max(0,Math.min(1,n))})`}function Bk(e,t,n){var r;return (r=e.mergedCells)==null?void 0:r.find(o=>o.row===t&&o.column===n)}function Fk(e){var h,y,k,C,N,L,D,W,V,ee,pe,re,we,he,xe,Ve;let t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("viewBox","0 0 100 60"),t.setAttribute("width","100%"),t.setAttribute("height","100%"),t.setAttribute("preserveAspectRatio","none");let n=(h=e.chart)==null?void 0:h.data;if(!(n!=null&&n.series.length))return bt(t,(y=e.name)!=null?y:"Chart",4,8,4,"#17202a"),t;let r=(C=(k=e.chart)==null?void 0:k.type)!=null?C:"",o=(N=e.chart)==null?void 0:N.grouping,i=Dk(n.series,r,o),s=Math.max(...i,1),a=Math.min(...i,0),l=(D=(L=e.chart)==null?void 0:L.axes)==null?void 0:D.value,c=(V=(W=e.chart)==null?void 0:W.axes)==null?void 0:V.category,u=(ee=l==null?void 0:l.min)!=null?ee:a>=0?0:a,f=(pe=l==null?void 0:l.max)!=null?pe:a>=0?$k(s):s,p=Hk(e),w=zk(u,f,l==null?void 0:l.majorUnit);if(r.includes("doughnut")||r.includes("pie"))return Qk(t,n.series,p),t;if(r.includes("radar"))return rE(t,n.series,p,(re=l==null?void 0:l.max)!=null?re:s),t;(l==null?void 0:l.majorGridlines)!==false&&jk(t,p,w,e,l,c),(l==null?void 0:l.deleted)!==true&&(l==null?void 0:l.tickLabelPosition)!=="none"&&Uk(t,p,u,f,w),Vk(t,e,p);let b=n.series.filter(z=>{var Z,H,Y;return ((Y=(H=z.type)!=null?H:(Z=e.chart)==null?void 0:Z.type)!=null?Y:"").includes("bar")}),g=n.series.filter(z=>{var Z;return ((Z=z.type)!=null?Z:"").includes("line")});return b.length>0?(qk(t,b,p,u,f,e,o),pm(t,(he=(we=b[0])==null?void 0:we.categories)!=null?he:[],p),b.some(z=>z.showValueLabels)&&Jk(t,b,p,u,f),g.length>0&&cm(t,g,p,u,f,void 0,e),g.some(z=>z.showValueLabels)&&fm(t,g,p,u,f)):(cm(t,n.series,p,u,f,["#22C7F2","#22C7F2","#94A3B8","#F59E0B"],e),pm(t,(Ve=(xe=n.series.find(z=>{var Z;return (Z=z.categories)==null?void 0:Z.length}))==null?void 0:xe.categories)!=null?Ve:[],p),n.series.some(z=>z.showValueLabels)&&fm(t,n.series,p,u,f)),t}function Dk(e,t,n){var s;let r=e.filter(a=>{var l;return ((l=a.type)!=null?l:t).includes("bar")});if(!Rm(n)||r.length<=1)return e.flatMap(a=>a.values);let o=Math.max(...r.map(a=>a.values.length),1),i=[];for(let a=0;a<o;a++){let l=0,c=0;for(let u of r){let f=(s=u.values[a])!=null?s:0;f>=0?l+=f:c+=f;}i.push(l,c);}return i}function Hk(e){var u,f,p,w,b,g,h,y,k,C,N,L,D,W,V,ee;let t=(u=e.chart)==null?void 0:u.plotLayout,n=(p=(f=e.chart)==null?void 0:f.type)!=null?p:"";if(!t)return Am((g=(b=(w=e.chart)==null?void 0:w.data)==null?void 0:b.series)!=null?g:[])?{left:7,top:8,width:88,height:40}:Ok(e)?{left:18,top:8,width:72,height:40}:((k=(y=(h=e.chart)==null?void 0:h.axes)==null?void 0:y.value)==null?void 0:k.deleted)===true?{left:6,top:8,width:90,height:40}:{left:18,top:8,width:76,height:40};let o=((L=(N=(C=e.chart)==null?void 0:C.axes)==null?void 0:N.value)==null?void 0:L.deleted)!==true&&!n.includes("doughnut")&&!n.includes("pie")&&!n.includes("radar")?14:4,i=((D=t.x)!=null?D:.12)*100,s=((W=t.y)!=null?W:.13)*60,a=((V=t.width)!=null?V:.82)*100,l=((ee=t.height)!=null?ee:.67)*60,c=Math.max(o,Math.min(20,i));return {left:c,top:Math.max(3,Math.min(12,s)),width:Math.max(40,Math.min(92,Math.min(a,96-c))),height:Math.max(24,Math.min(50,l))}}function Ok(e){var i,s,a,l,c,u,f,p;let t=e.chart,n=(i=t==null?void 0:t.type)!=null?i:"";if(!t||!n.includes("bar")||t.plotLayout)return false;let r=(a=(s=t.data)==null?void 0:s.series)!=null?a:[];if(r.length!==1)return false;let o=Math.max((u=(c=(l=r[0])==null?void 0:l.categories)==null?void 0:c.length)!=null?u:0,(p=(f=r[0])==null?void 0:f.values.length)!=null?p:0);return o>0&&o<=2}function $k(e){if(e<=0)return 1;if(e<=10)return Math.max(1,Math.ceil(e));let t=e*1.1,n=10**Math.floor(Math.log10(t));return Math.ceil(t/n)*n}function zk(e,t,n){let r=Math.abs(t-e);return n&&n>0?Math.max(1,Math.min(8,Math.round(r/n))):Number.isInteger(r)&&r>0&&r<=6?r:4}function Vk(e,t,n){var c,u,f,p,w,b,g;let r=(p=(c=t.chart)==null?void 0:c.title)!=null?p:(f=(u=t.chart)==null?void 0:u.data)==null?void 0:f.title;r&&bt(e,r,n.left+n.width*.5,Math.max(4,n.top-3.2),3.1,"#17202A","middle");let o=(g=(b=(w=t.chart)==null?void 0:w.data)==null?void 0:b.series)!=null?g:[],i=o.map(h=>h.name).filter(h=>!!h).slice(0,4);if(i.length===0)return;let s=["#C50D13","#0EA5E9","#F59E0B","#A3E635"],a=n.left+n.width*.78,l=Math.max(4,n.top-2.4);i.forEach((h,y)=>{var N,L,D,W,V,ee;let k=(N=o.find(pe=>pe.name===h))!=null?N:o[y],C=k?Gk(e,k,y,s):s[y];k&&((L=k.type)!=null?L:"").includes("line")?(ur(e,a,l-1.1,a+2.3,l-1.1,C,.45),yn(e,a+1.15,l-1.1,.45,(W=(D=k.marker)==null?void 0:D.fillColor)!=null?W:"#FFFFFF",(ee=(V=k.marker)==null?void 0:V.lineColor)!=null?ee:C,.32),bt(e,h,a+2.8,l-.45,2.2,"#64748B")):(uo(e,a,l-1.8,1.4,1.4,C),bt(e,h,a+2,l-.45,2.2,"#64748B")),a+=Math.max(9,Array.from(h).length*2.2+4.5);});}function Gk(e,t,n,r){var o,i;return ((o=t.type)!=null?o:"").includes("line")?(i=t.lineColor)!=null?i:r[n]:Ji(e,t,n,r)}function jk(e,t,n,r,o,i){var l,c;let s=(l=o==null?void 0:o.gridlineColor)!=null?l:"#E8EDF3",a=um(o==null?void 0:o.gridlineWidth,r,.35);for(let u=0;u<=n;u++){let f=t.top+t.height/n*u;ur(e,t.left,f,t.left+t.width,f,s,a);}ur(e,t.left,t.top+t.height,t.left+t.width,t.top+t.height,(c=i==null?void 0:i.lineColor)!=null?c:"#CBD5E1",um(i==null?void 0:i.lineWidth,r,.45));}function Uk(e,t,n,r,o){for(let i=0;i<=o;i++){let s=r-(r-n)/o*i,a=t.top+t.height/o*i+1;bt(e,yl(s),t.left-1.8,a,3,"#9AA6B2","end");}}function yl(e){return Number.isInteger(e)?String(e):e.toFixed(1).replace(/\.0$/,"")}function cm(e,t,n,r,o,i=["#CBD5E1","#94A3B8","#F59E0B","#A3E635"],s){t.forEach((a,l)=>{var p,w,b,g,h,y,k;if(a.values.length===0)return;let c=a.values.map((C,N)=>{let L=n.left+(a.values.length===1?n.width/2:n.width*N/(a.values.length-1)),D=n.top+n.height-(C-r)/Math.max(1,o-r)*n.height;return {x:L,y:D}}),u=_k(c,a.smooth===true),f=(p=a.lineColor)!=null?p:i[l%i.length];if(Bm(e,u,f,Mm(a,s)),((w=a.marker)==null?void 0:w.symbol)!=="none"){let C=Math.max(.5,Math.min(1.6,((g=(b=a.marker)==null?void 0:b.size)!=null?g:5)*.18)),N=(y=(h=a.marker)==null?void 0:h.fillColor)!=null?y:f,L=(k=a.marker)==null?void 0:k.lineColor,D=Kk(a,s);c.forEach(W=>yn(e,W.x,W.y,C,N,L,D));}});}function Kk(e,t){var n;if(!(!((n=e.marker)!=null&&n.lineWidth)||!(t!=null&&t.bounds.width)))return Math.max(.25,Math.min(1,e.marker.lineWidth/t.bounds.width*100))}function Mm(e,t){return !e.lineWidth||!(t!=null&&t.bounds.width)?.8:Math.max(.3,Math.min(1.2,e.lineWidth/t.bounds.width*100))}function _k(e,t){if(e.length===0)return "";if(!t||e.length<3)return e.map((r,o)=>`${o===0?"M":"L"} ${r.x} ${r.y}`).join(" ");let n=[`M ${e[0].x} ${e[0].y}`];for(let r=0;r<e.length-1;r++){let o=e[Math.max(0,r-1)],i=e[r],s=e[r+1],a=e[Math.min(e.length-1,r+2)],l={x:i.x+(s.x-o.x)/6,y:i.y+(s.y-o.y)/6},c={x:s.x-(a.x-i.x)/6,y:s.y-(a.y-i.y)/6};n.push(`C ${l.x} ${l.y} ${c.x} ${c.y} ${s.x} ${s.y}`);}return n.join(" ")}function qk(e,t,n,r,o,i,s){if(Rm(s)&&t.length>1){Yk(e,t,n,r,o,i);return}if(Am(t)){Xk(e,t,n,r,o,i);return}let a=["#C50D13","#0EA5E9","#F59E0B","#A3E635"],l=Math.max(...t.map(f=>f.values.length),1),c=n.width/l,u=Math.max(1,c*.48/Math.max(t.length,1));t.forEach((f,p)=>{let w=Ji(e,f,p,a);f.values.forEach((b,g)=>{var C,N;let h=(b-r)/Math.max(1,o-r)*n.height,y=n.left+g*c+(c-u*t.length)/2+p*u,k=n.top+n.height-h;uo(e,y,k,u,h,(N=(C=f.pointColors)==null?void 0:C[g])!=null?N:w,f.borderColor,vl(f,i));});});}function Xk(e,t,n,r,o,i){let s=["#C50D13","#0EA5E9","#F59E0B","#A3E635"],a=Math.max(...t.map(u=>u.values.length),1),l=n.width/a,c=Math.max(1,l*.34);t.forEach((u,f)=>{let p=Ji(e,u,f,s);u.values.forEach((w,b)=>{var k,C;let g=Xi(w,n,r,o),h=Xi(0,n,r,o),y=n.left+b*l+(l-c)/2;uo(e,y,Math.min(g,h),c,Math.max(.1,Math.abs(h-g)),(C=(k=u.pointColors)==null?void 0:k[b])!=null?C:p,u.borderColor,vl(u,i));});});}function Yk(e,t,n,r,o,i){let s=["#C50D13","#0EA5E9","#F59E0B","#A3E635"],a=Math.max(...t.map(p=>p.values.length),1),l=n.width/a,c=Math.max(1,l*.46),u=new Array(a).fill(Math.max(0,r)),f=new Array(a).fill(Math.min(0,o));t.forEach((p,w)=>{let b=Ji(e,p,w,s);p.values.forEach((g,h)=>{var D,W;let y=g>=0?u[h]:f[h],k=y+g,C=Xi(y,n,r,o),N=Xi(k,n,r,o),L=n.left+h*l+(l-c)/2;uo(e,L,Math.min(C,N),c,Math.max(.1,Math.abs(N-C)),(W=(D=p.pointColors)==null?void 0:D[h])!=null?W:b,p.borderColor,vl(p,i)),g>=0?u[h]=k:f[h]=k;});});}function Xi(e,t,n,r){return t.top+t.height-(e-n)/Math.max(1,r-n)*t.height}function Rm(e){return e==="stacked"||e==="percentStacked"}function Am(e){return new Set(e.map(n=>{var r;return (r=n.chartGroup)!=null?r:0})).size>1&&e.every(n=>!n.type||n.type.includes("bar"))}function vl(e,t){if(e.borderWidth)return Lm(t!=null&&t.bounds.width?e.borderWidth/t.bounds.width*100:void 0,void 0)}function um(e,t,n){var r;return (r=Lm(e!==void 0&&t.bounds.width?e/t.bounds.width*100:void 0,n))!=null?r:n}function Lm(e,t){return e===void 0?t:Math.max(.15,Math.min(1.4,e))}function Ji(e,t,n,r){var o,i;if((o=t.fillGradient)!=null&&o.colors.length&&t.fillGradient.colors.length>1){let s=`coco-chart-gradient-${n}-${t.fillGradient.colors.join("-").replace(/[^a-zA-Z0-9_-]/g,"_")}`;return Hn(e,s,t.fillGradient),`url(#${s})`}return (i=t.fillColor)!=null?i:r[n%r.length]}function Zk(e,t,n){var r,o,i;return (i=(o=(r=e.pointColors)==null?void 0:r[t])!=null?o:e.fillColor)!=null?i:n[t%n.length]}function pm(e,t,n){if(t.length===0)return;let r=n.width/t.length;t.forEach((o,i)=>{bt(e,o,n.left+r*i+r/2,n.top+n.height+5.2,3.2,"#64748B","middle");});}function Jk(e,t,n,r,o){let i=Math.max(...t.map(l=>l.values.length),1),s=n.width/i,a=Math.max(1,s*.48/Math.max(t.length,1));t.forEach((l,c)=>{l.showValueLabels&&l.values.forEach((u,f)=>{let p=(u-r)/Math.max(1,o-r)*n.height,w=n.left+f*s+(s-a*t.length)/2+c*a+a/2,b=n.top+n.height-p-2;bt(e,String(u),w,b,3,"#A7AEB8","middle");});});}function fm(e,t,n,r,o){t.forEach(i=>{!i.showValueLabels||i.values.length===0||i.values.forEach((s,a)=>{let l=n.left+(i.values.length===1?n.width/2:n.width*a/(i.values.length-1)),c=n.top+n.height-(s-r)/Math.max(1,o-r)*n.height;bt(e,String(s),l,Math.max(n.top+2,c-2.2),2.6,"#374151","middle");});});}function Qk(e,t,n){var w;let r=t[0];if(!(r!=null&&r.values.length))return;let o=["#1D4ED8","#E3B363","#60A5FA","#94A3B8","#F59E0B","#22C7F2"],i=r.values.reduce((b,g)=>b+Math.max(0,g),0)||1,s=n.left+n.width*.42,a=n.top+n.height*.5,l=Math.min(n.width,n.height)*.34,c=l*.58,u=-90;r.values.forEach((b,g)=>{let h=Math.max(0,b)/i*360,y=u,k=u+h;if(oE(e,s,a,l,c,y,k,Zk(r,g,o)),r.showCategoryNameLabels||r.showPercentLabels||r.showValueLabels){let C=eE(r,b,g,i);if(C.length>0){let N=tE(r,g,s,a,l+3.6,n,(y+k)/2);lE(e,C,N.x,N.y,1.9,"#334155",N.x>=s?"start":"end");}}u+=h;}),yn(e,s,a,c*.92,"#FFFFFF");let f=nE(r.name);f&&bt(e,f,s,a-1.8,1.8,"#64748B","middle");let p=r.values[0];p!==void 0&&bt(e,Wm(p,i),s,a+3.4,3.9,"#1E3A8A","middle"),iE(e,(w=r.categories)!=null?w:[],o,n.left+n.width*.72,n.top+9);}function eE(e,t,n,r){var s;let o=[],i=(s=e.categories)==null?void 0:s[n];return e.showCategoryNameLabels&&i&&o.push(i),e.showValueLabels&&o.push(yl(t)),e.showPercentLabels&&o.push(Wm(t,r)),o}function tE(e,t,n,r,o,i,s){return ir(n,r,o,s)}function Wm(e,t){let r=(e>0&&e<=1&&t<=2?e:e/Math.max(1,t))*100;return `${Number.isInteger(r)?r.toFixed(0):r.toFixed(1)}%`}function nE(e){let t=(e!=null?e:"").trim();if(!t)return "";let n=Array.from(t);return n.length<=6?t:`${n.slice(0,5).join("")}\u2026`}function rE(e,t,n,r){var c;let o=t[0];if(!(o!=null&&o.values.length))return;let i=o.values.length,s=n.left+n.width*.48,a=n.top+n.height*.5,l=Math.min(n.width,n.height)*.35;for(let u=1;u<=4;u++)Bm(e,aE(i,s,a,l*u/4),"#CBD5E1",.25);for(let u=0;u<i;u++){let f=Ki(u,i,s,a,l);ur(e,s,a,f.x,f.y,"#E2E8F0",.25);}t.forEach((u,f)=>{var b;if(!u.values.length)return;let p=u.values.slice(0,i).map((g,h)=>Ki(h,i,s,a,Math.max(0,g)/Math.max(1,r)*l)),w=document.createElementNS("http://www.w3.org/2000/svg","path");w.setAttribute("d",p.map((g,h)=>`${h===0?"M":"L"} ${g.x} ${g.y}`).join(" ")+" Z"),w.setAttribute("fill",f===0?"rgba(37, 99, 235, 0.08)":"none"),w.setAttribute("stroke",(b=u.lineColor)!=null?b:"#2563EB"),w.setAttribute("stroke-width",String(Mm(u,void 0))),e.append(w),u.marker&&u.marker.symbol!=="none"&&p.forEach(g=>{var h;return yn(e,g.x,g.y,.9,(h=u.lineColor)!=null?h:"#2563EB")}),u.showValueLabels&&u.values.slice(0,i).forEach((g,h)=>{var k;let y=p[h];bt(e,yl(g),y.x,y.y-1.2,2.2,(k=u.lineColor)!=null?k:"#2563EB","middle");});}),((c=o.categories)!=null?c:[]).slice(0,i).forEach((u,f)=>{let p=Ki(f,i,s,a,l+5);bt(e,u,p.x,p.y+1,2.6,"#64748B","middle");});}function oE(e,t,n,r,o,i,s,a){let c=Math.max(.01,s-i)>180?1:0,u=ir(t,n,r,i),f=ir(t,n,r,s),p=ir(t,n,o,s),w=ir(t,n,o,i),b=document.createElementNS("http://www.w3.org/2000/svg","path");b.setAttribute("d",[`M ${u.x} ${u.y}`,`A ${r} ${r} 0 ${c} 1 ${f.x} ${f.y}`,`L ${p.x} ${p.y}`,`A ${o} ${o} 0 ${c} 0 ${w.x} ${w.y}`,"Z"].join(" ")),b.setAttribute("fill",a),e.append(b);}function iE(e,t,n,r,o){t.slice(0,6).forEach((i,s)=>{uo(e,r,o+s*5,2.4,2.4,n[s%n.length]),bt(e,i,r+3.6,o+s*5+2.2,2.7,"#334155");});}function aE(e,t,n,r,o){return Array.from({length:e},(i,s)=>{let a=Ki(s,e,t,n,r);return `${s===0?"M":"L"} ${a.x} ${a.y}`}).join(" ")+(" Z")}function Ki(e,t,n,r,o){return ir(n,r,o,-90+360*e/t)}function ir(e,t,n,r){let o=r*Math.PI/180;return {x:e+Math.cos(o)*n,y:t+Math.sin(o)*n}}function ur(e,t,n,r,o,i,s,a,l){let c=document.createElementNS("http://www.w3.org/2000/svg","line");c.setAttribute("x1",String(t)),c.setAttribute("y1",String(n)),c.setAttribute("x2",String(r)),c.setAttribute("y2",String(o)),c.setAttribute("stroke",i),c.setAttribute("stroke-width",String(s)),c.setAttribute("stroke-linecap",sE(l)),a!==void 0&&c.setAttribute("stroke-opacity",String(Math.max(0,Math.min(1,a)))),e.append(c);}function sE(e){return e==="rnd"?"round":e==="sq"?"square":"butt"}function Bm(e,t,n,r){let o=document.createElementNS("http://www.w3.org/2000/svg","path");o.setAttribute("d",t),o.setAttribute("fill","none"),o.setAttribute("stroke",n),o.setAttribute("stroke-width",String(r)),o.setAttribute("stroke-linejoin","round"),o.setAttribute("stroke-linecap","round"),e.append(o);}function yn(e,t,n,r,o,i,s){let a=document.createElementNS("http://www.w3.org/2000/svg","circle");a.setAttribute("cx",String(t)),a.setAttribute("cy",String(n)),a.setAttribute("r",String(r)),a.setAttribute("fill",o),i&&a.setAttribute("stroke",i),s!==void 0&&a.setAttribute("stroke-width",String(s)),e.append(a);}function Ui(e,t,n,r,o,i,s,a){let l=i/2,c=r==="right"?[[t,n],[t-o,n-l],[t-o,n+l]]:r==="left"?[[t,n],[t+o,n-l],[t+o,n+l]]:r==="down"?[[t,n],[t-l,n-o],[t+l,n-o]]:[[t,n],[t-l,n+o],[t+l,n+o]],u=document.createElementNS("http://www.w3.org/2000/svg","polygon");u.classList.add("coco-ppt-line-arrow"),u.setAttribute("points",c.map(f=>f.join(",")).join(" ")),u.setAttribute("fill",s),a!==void 0&&u.setAttribute("fill-opacity",String(Math.max(0,Math.min(1,a)))),e.append(u);}function uo(e,t,n,r,o,i,s,a){let l=document.createElementNS("http://www.w3.org/2000/svg","rect");l.setAttribute("x",String(t)),l.setAttribute("y",String(n)),l.setAttribute("width",String(r)),l.setAttribute("height",String(o)),l.setAttribute("fill",i),s&&a!==void 0&&(l.setAttribute("stroke",s),l.setAttribute("stroke-width",String(a))),e.append(l);}function bt(e,t,n,r,o,i,s="start"){let a=document.createElementNS("http://www.w3.org/2000/svg","text");a.setAttribute("x",String(n)),a.setAttribute("y",String(r)),a.setAttribute("font-size",String(o)),a.setAttribute("fill",i),a.setAttribute("text-anchor",s),a.textContent=t,e.append(a);}function lE(e,t,n,r,o,i,s="start"){t.forEach((a,l)=>{bt(e,a,n,r+l*o*1.2,o,i,s);});}
1683
- exports.DEFAULT_PPT_SLIDE_SIZE=ES;exports.EditorReadOnlyError=ln;exports.NATIVE_BLOCK_CLIPBOARD_TYPE=ri;exports.PptEditorSession=Di;exports.SPREADSHEET_COLUMN_RESIZE_MIN=fN;exports.SPREADSHEET_RESIZE_HIT_TOLERANCE=hN;exports.SPREADSHEET_ROW_RESIZE_MIN=mN;exports.SpreadsheetCanvasRenderer=Ti;exports.SpreadsheetCellEditor=Ri;exports.SpreadsheetEditorRuntime=Mi;exports.SpreadsheetLayout=xi;exports.SpreadsheetViewportManager=vi;exports.adjacentNativeListNumbering=fc;exports.allNativeParagraphs=_e;exports.analyzeNativeTableRowPagination=Va;exports.applyNativeWordChangesToPackage=eC;exports.applySpreadsheetAgentAction=lN;exports.applyWheelDelta=vf;exports.applyWordOoxmlPatches=fx;exports.bodyParagraphs=Gu;exports.buildPptEditorViewFromModel=qN;exports.buildPptEditorViewFromPptx=_N;exports.buildPptEditorViewFromPresentation=zf;exports.buildPptPresentationScene=io;exports.buildPptSceneNode=ao;exports.buildPptSlideScene=CS;exports.buildSpreadsheetAutoFillPlan=rf;exports.buildSpreadsheetClipboardPayload=Ys;exports.buildSpreadsheetReplacePlan=uf;exports.buildSpreadsheetSheetRenderModel=Qr;exports.buildWordEditorView=bE;exports.buildWordEditorViewFromDocx=hE;exports.buildWordEditorViewFromFlatOpc=gE;exports.buildWordEditorViewFromPackage=Na;exports.canDispatchNativeWordCommand=Mt;exports.clampScroll=xv;exports.clearNativeImageSelection=Et;exports.clearSpreadsheetRange=$I;exports.cloneNativeWordBlocks=nt;exports.collectNativeParagraphs=vE;exports.colorToCss=jn;exports.computeScrollbarState=Sf;exports.createColumnRangeSelection=SI;exports.createColumnSelection=Xs;exports.createNativeListNumbering=Ga;exports.createNativeParaId=Tn;exports.createNativeSelectionRange=bs;exports.createNativeTextRange=Ou;exports.createNativeWordDocument=Ha;exports.createRowRangeSelection=vI;exports.createRowSelection=qs;exports.createSelection=gt;exports.createWordEditingPlugin=xC;exports.cssPixelsToExcelColumnWidth=yi;exports.currentNativeCursor=ut;exports.currentNativeSelection=ze;exports.defineNativeWordElements=ou;exports.excelColumnWidthToCssPixels=bv;exports.expandRangeForMergedRanges=Lv;exports.expandSelectionForMergedRanges=Kt;exports.extendSelection=Pi;exports.findNativeParagraph=_;exports.findNativeParagraphLocation=be;exports.findNativeTableCellLocation=Jt;exports.findNativeTableLocation=Oe;exports.findPptSceneNode=so;exports.findPptSceneSlide=tr;exports.findSpreadsheetMatches=jI;exports.formatSpreadsheetDisplayValue=iv;exports.freezeStateFromPane=wv;exports.freezeStateFromSheet=Si;exports.getNativeWordCommandState=Bp;exports.getRenderCell=qe;exports.getWordChangeSet=yC;exports.getWordSelectionInfo=vC;exports.hitSpreadsheetResizeHandle=ol;exports.imageOffset=ni;exports.isPptShapeEditable=VN;exports.layoutNativePageAnnotationBubbles=xw;exports.measureNativeDocumentReflowFromParagraph=cs;exports.moveSelection=kI;exports.nativeAddComment=Qa;exports.nativeAddFormatRevision=$c;exports.nativeAddRevision=Dt;exports.nativeAnchorLayoutMetadata=Uw;exports.nativeBlockClipboardText=Es;exports.nativeClearRunFormat=Hc;exports.nativeClearTableCellRange=Ec;exports.nativeCopyBlockRange=Ya;exports.nativeCursorFromPoint=Du;exports.nativeDeleteBackward=Nr;exports.nativeDeleteComment=Bc;exports.nativeDeleteForward=Tr;exports.nativeDeleteImage=Oc;exports.nativeDeleteRange=un;exports.nativeDeleteTable=xc;exports.nativeDeleteTextRangeAcrossParagraphs=qo;exports.nativeDrawingWidthCss=Hw;exports.nativeEditTableStructure=yc;exports.nativeInsertImage=Nc;exports.nativeInsertPageBreak=Tc;exports.nativeInsertTable=wc;exports.nativeInsertText=Qt;exports.nativeLineStrokeStyle=Fw;exports.nativeListIndent=pc;exports.nativeListType=dn;exports.nativeMergeTableCells=vc;exports.nativeNumberingAtLevel=ja;exports.nativePageBreakAt=_o;exports.nativeParagraphText=Te;exports.nativeRangeContainsPageBreak=Pc;exports.nativeReplaceBlockRangeAcrossParagraphs=Rc;exports.nativeReplaceRange=Pr;exports.nativeReplaceRangeWithBlocks=Ac;exports.nativeReplaceTableCellRangeContent=Ic;exports.nativeReplaceTableCellRangeText=Cc;exports.nativeReplaceTextRangeAcrossParagraphs=Lc;exports.nativeReplaceTextRangeWithParagraphs=Za;exports.nativeResolveFormatRevision=Dc;exports.nativeResolveImageFormatRevision=Vc;exports.nativeResolveImageRevision=zc;exports.nativeResolveRevision=Fc;exports.nativeSelection=kt;exports.nativeSelectionFromCursor=st;exports.nativeSetHyperlink=es;exports.nativeSetImageSize=Mc;exports.nativeSetParagraphFormat=Un;exports.nativeSetParagraphList=Mr;exports.nativeSetRunFormat=Ja;exports.nativeSetTableCellFormat=qa;exports.nativeSetTableCellRangeFormat=kc;exports.nativeSplitParagraph=ts;exports.nativeSplitTableCell=Sc;exports.nativeSyncParagraphText=Rr;exports.nativeTableCellsInRange=at;exports.nativeTableSupportsStructuralEditing=Ir;exports.nativeTextRangeIsBold=FE;exports.nativeUpdateComment=Wc;exports.nextSpreadsheetMatch=UI;exports.normalizePptGeometry=oo;exports.normalizeSelectionRange=We;exports.paginateNativeDocument=su;exports.parentNativeParagraph=St;exports.parseNativeBlockClipboard=Ku;exports.parseNativeClipboardHtml=Uu;exports.parseTsv=Zs;exports.planWordOoxmlPatch=ux;exports.planWordOoxmlPatches=cx;exports.pptSceneGeometryToSourceGeometry=Of;exports.pptSceneNodeCapabilities=Hf;exports.previewSpreadsheetAgentAction=sN;exports.previousNativeParagraphId=Oa;exports.rangeAddressForMatrix=MI;exports.rangeForSpreadsheetMatch=KI;exports.rebuildNativeTableFragmentsFromParagraph=Ot;exports.reflowNativeDocumentFromParagraph=lu;exports.refreshNativeNumberingLabels=Go;exports.refreshNativePageCommentBubbles=mn;exports.renderNativeBlock=Or;exports.renderNativeDocument=iu;exports.renderNativeImage=ms;exports.renderNativeParagraph=$r;exports.renderNativePptEditor=iT;exports.renderNativeTable=Bu;exports.renderNativeWordEditor=KC;exports.renderSpreadsheetEditor=HN;exports.resolveNativeSectionPageNumberStarts=Iw;exports.resolveNativeTableCellBorders=Yw;exports.resolveParagraphStyle=Fa;exports.resolveRunStyle=Oo;exports.resolveSpreadsheetCellStyle=Ei;exports.resolveSpreadsheetRangeBorder=Jp;exports.resolveTableCellStyle=nc;exports.resolveWordOoxmlPatchTargets=px;exports.restoreNativeCursor=lt;exports.restoreNativeElementSelection=Hu;exports.restoreNativeTextSelection=hn;exports.rowColumnKey=gi;exports.scrollFromThumbPosition=Ai;exports.searchNativeWordDocument=xs;exports.selectNativeImage=$u;exports.selectionAfterColumnDeletion=CI;exports.selectionAfterRowDeletion=EI;exports.serializeNativeBlockClipboard=ks;exports.serializeNativeClipboardHtml=Ss;exports.serializeRangeToTsv=Hv;exports.setColor=EC;exports.setFontSize=kC;exports.setParagraphAlign=CC;exports.setSpreadsheetCellFormula=HI;exports.setSpreadsheetCellValue=DI;exports.setSpreadsheetColumnWidth=VI;exports.setSpreadsheetRangeValues=OI;exports.setSpreadsheetRowHeight=zI;exports.splitNativeTableRowAtBlockBoundary=NE;exports.splitNativeTableRowAtTextOffset=TE;exports.spreadsheetFilterValues=nl;exports.spreadsheetRowsForColumnFilters=mf;exports.spreadsheetRowsForFilter=ff;exports.spreadsheetSortRows=hf;exports.spreadsheetVisibleFilterValues=XI;exports.startSpreadsheetResizeDrag=kf;exports.summarizeEditorCoverage=Dg;exports.summarizeNativeCoverage=yE;exports.summarizeNativeTablePagination=IE;exports.summarizeSpreadsheetSelectionFormat=yN;exports.supportsSpreadsheetAutoFill=el;exports.toggleBold=SC;exports.updateSpreadsheetResizeDrag=il;exports.wordEditingPluginKey=Kr;
1687
+ `;let n=document.createElement("div");n.className="coco-ppt-editor",n.dataset.showSlideList=String(this.options.showSlideList!==false),n.dataset.readOnly=String(this.isReadOnly()),this.slideList.className="coco-ppt-slides";let r=document.createElement("div");r.className="coco-ppt-stage",this.canvas.className="coco-ppt-canvas",this.contextMenu.className="coco-ppt-context-menu",this.snapGuides.className="coco-ppt-snap-guides",r.append(this.canvas),n.append(this.slideList,r),this.root.append(t,n,this.contextMenu),this.canvas.addEventListener("click",this.handleCanvasClick),this.canvas.addEventListener("selectstart",this.handleCanvasSelectStart),this.slideList.addEventListener("scroll",this.handleSlideListScroll,{passive:true}),window.addEventListener("mousemove",this.handleWindowMouseMove),window.addEventListener("mouseup",this.handleWindowMouseUp),window.addEventListener("keydown",this.handleWindowKeyDown),window.addEventListener("pointerdown",this.handleWindowPointerDown),window.addEventListener("scroll",this.handleWindowScroll,true);}scheduleFontRenderRefresh(t){return typeof document=="undefined"||!document.fonts?Promise.resolve():t.then(()=>Promise.all([...new Set(this.fontResources.map(n=>n.family))].map(n=>document.fonts.load(`16px ${bl(n)}`)))).then(()=>Promise.all(this.referencedFontFamilies.map(n=>document.fonts.load(`16px ${bl(n)}`)))).then(()=>document.fonts.ready).then(()=>{this.render();}).catch(()=>{})}render(){let t=this.root.querySelector(".coco-ppt-editor");t&&(t.dataset.readOnly=String(this.isReadOnly()));let n=this.sessionValue.scene();this.slideList.replaceChildren(...this.options.showSlideList===false?[]:n.slides.map(i=>{var u;let s=document.createElement("button");s.className="coco-ppt-thumb",s.type="button",s.dataset.slideId=i.id,s.dataset.slideIndex=String(i.index),s.dataset.selected=((u=this.sessionValue.selection())==null?void 0:u.slideId)===i.id?"true":"false";let a=document.createElement("div");a.className="coco-ppt-thumb-preview";let l=document.createElement("div");l.className="coco-ppt-thumb-placeholder";let c=document.createElement("span");return c.className="coco-ppt-thumb-number",c.textContent=String(i.index+1),s.append(a,l,c),s.addEventListener("click",()=>{this.dispatch({kind:"select-slide",slideIdOrIndex:i.id});}),s})),this.options.showSlideList!==false&&this.renderVisibleThumbnails(n.slides);let r=this.currentSlide();if(!r){this.canvas.replaceChildren(),this.hideContextMenu();return}let o=this.computeScale(r);this.canvas.style.width=`${r.size.width*o}px`,this.canvas.style.height=`${r.size.height*o}px`,this.canvas.style.background=wl(r.background,this.imageResources),this.canvas.replaceChildren(...r.nodes.map(i=>this.renderNode(i,o,r)),this.snapGuides),this.hideSnapGuides(),this.hideContextMenu(),this.renderSelection();}renderVisibleThumbnails(t){let n=Array.from(this.slideList.querySelectorAll(".coco-ppt-thumb")),r=this.visibleThumbnailRange(t.length);n.forEach((o,i)=>{let s=o.querySelector(".coco-ppt-thumb-preview"),a=o.querySelector(".coco-ppt-thumb-placeholder");if(!s||!a)return;if(i<r.start||i>=r.end){s.replaceChildren(),delete o.dataset.previewRendered,delete o.dataset.previewMode,a.hidden=false;return}if(o.dataset.previewRendered==="true")return;let l=t[i];if(!l)return;let c=ml(l),u=this.thumbnailCanvasCache.get(l.id);(u==null?void 0:u.fingerprint)===c?(s.replaceChildren(Jf(u.canvas)),o.dataset.previewMode="canvas"):(s.replaceChildren(this.renderThumbnailSlide(l)),o.dataset.previewMode="dom",this.rasterizeThumbnail(o,l)),o.dataset.previewRendered="true",a.hidden=true;});}visibleThumbnailRange(t){let n=or*.5625+i0,r=this.slideList.clientHeight||n*Math.min(t,5),o=Math.max(0,Math.floor(this.slideList.scrollTop/n)-Vi),i=Math.ceil(r/n)+Vi*2,s=this.sessionValue.selection(),a=(s==null?void 0:s.slideId)!==void 0?this.sessionValue.scene().slides.findIndex(u=>u.id===s.slideId):-1,l=a>=0?Math.min(o,Math.max(0,a-Vi)):o,c=a>=0?Math.max(o+i,Math.min(t,a+Vi+1)):o+i;return {start:l,end:Math.min(t,c)}}renderThumbnailSlide(t){let n=document.createElement("div");n.className="coco-ppt-thumb-slide";let o=or*Gi/t.size.width;return n.style.width=`${t.size.width*o}px`,n.style.height=`${t.size.height*o}px`,n.style.transform=`scale(${1/Gi})`,n.style.background=wl(t.background,this.imageResources),n.replaceChildren(...t.nodes.map(i=>this.renderNode(i,o,t,false))),n}async rasterizeThumbnail(t,n){var c,u;let r=this.thumbnailRasterEpoch,o=ml(n);if(await Zf(),await Zf(),r!==this.thumbnailRasterEpoch||!t.isConnected)return;let i=t.querySelector(".coco-ppt-thumb-preview"),s=i==null?void 0:i.querySelector(".coco-ppt-thumb-slide");if(!i||!s)return;let a=await m0(s,or,or*(n.size.height/n.size.width),a0,(u=(c=this.root.querySelector("style"))==null?void 0:c.textContent)!=null?u:"",or*Gi,or*Gi*(n.size.height/n.size.width));if(!a||r!==this.thumbnailRasterEpoch||!t.isConnected)return;let l=this.sessionValue.scene().slides.find(f=>f.id===n.id);!l||ml(l)!==o||(this.thumbnailCanvasCache.set(n.id,{fingerprint:o,canvas:a}),i.replaceChildren(Jf(a)),t.dataset.previewMode="canvas");}scheduleThumbnailRender(){this.thumbnailFrame||(this.thumbnailFrame=requestAnimationFrame(()=>{this.thumbnailFrame=0,this.renderVisibleThumbnails(this.sessionValue.scene().slides);}));}renderNode(t,n,r,o=true){var h,y,k;let i=document.createElement("div"),s=Im(t),a=t.presetGeometry==="frame",l=s?Nm(t):"horizontal",c=Math.max(s&&l==="vertical"?12:1,t.bounds.width*n),u=Math.max(s&&l==="horizontal"?12:1,t.bounds.height*n);i.className=o?"coco-ppt-node":"coco-ppt-thumb-node",i.dataset.kind=t.kind,i.dataset.locked=String(t.locked),o&&(i.dataset.draggable=String(!this.isReadOnly()&&t.capabilities.editGeometry),i.dataset.resizable=String(!this.isReadOnly()&&t.capabilities.editGeometry),i.dataset.shapeId=t.id),i.style.left=`${t.bounds.left*n-(s&&l==="vertical"?c/2:0)}px`,i.style.top=`${t.bounds.top*n-(s&&l==="horizontal"?u/2:0)}px`,i.style.width=`${c}px`,i.style.height=`${u}px`;let f=[];t.bounds.rotation&&f.push(`rotate(${t.bounds.rotation}deg)`),t.bounds.flipHorizontal&&f.push("scaleX(-1)"),t.bounds.flipVertical&&f.push("scaleY(-1)"),f.length>0&&(i.style.transform=f.join(" "));let p=Mm(t),w=bk(t.presetGeometry),b=!!(w&&t.text&&!t.customGeometry&&!p);if(t.usesBackgroundFill&&t.backgroundFill?ck(i,t.backgroundFill,t,r,n,this.imageResources):t.customGeometry||p||b||t.kind==="table"||s||a?i.style.background="transparent":t.fillGradient&&t.fillGradient.colors.length>1?i.style.background=pr(t.fillGradient,ur(t)):t.fillColor&&(i.style.background=cr(t.fillColor,ur(t))),Z0(t)&&(i.style.overflow="visible"),(t.presetGeometry==="roundRect"||t.presetGeometry==="round1Rect")&&(i.style.borderRadius=`${lr(t)*n}px`),t.presetGeometry==="round2DiagRect"){let C=`${lr(t)*n}px`;i.style.borderRadius=`${C} 0 ${C} 0`;}if(t.presetGeometry==="round2SameRect"){let C=`${lr(t)*n}px`;i.style.borderRadius=`${C} ${C} 0 0`;}if((t.presetGeometry==="ellipse"||s0(t)||c0(t))&&(i.style.borderRadius="9999px"),w&&!b&&!p&&(i.style.clipPath=w),a?(i.style.borderStyle="solid",i.style.borderWidth=`${uk(t,n)}px`,t.fillGradient&&t.fillGradient.colors.length>1?(i.style.borderImageSource=pr(t.fillGradient),i.style.borderImageSlice="1"):t.fillColor&&(i.style.borderColor=t.fillColor)):!t.customGeometry&&!p&&!b&&!s&&t.kind!=="picture"&&t.lineColor&&(i.style.borderStyle=Sl(t.lineDash),i.style.borderWidth=`${Math.max(1,((h=t.lineWidth)!=null?h:9525)*n)}px`,i.style.borderColor=cr(t.lineColor,t.lineOpacity)),t.shadow&&(i.style.boxShadow=Lm(t.shadow,n)),this.applyTextStyle(i,t,n),V0(i,t,n),b&&w&&i.append(fk(t,n,w)),t.customGeometry&&t.kind!=="picture"&&i.append(Rk(t)),p&&i.append(wk(t,n)),s)i.append(Dk(t,n));else if(t.kind==="chart")i.append(Kk(t));else if(t.kind==="table"){let C=$k(t,n,o);o&&(C.addEventListener("click",N=>{N.stopPropagation(),!this.consumeSuppressedClick()&&(this.notifyTableCellSelection(r,t,N),this.dispatch({kind:"select-shape",slideIdOrIndex:r.id,shapeIdOrName:t.id}));}),C.addEventListener("dblclick",N=>{if(this.isReadOnly())return;let L=em(N);if(!L||!t.capabilities.editTableCells)return;N.stopPropagation();let F=Number(L.dataset.row),W=Number(L.dataset.column);!Number.isInteger(F)||!Number.isInteger(W)||this.startTableCellEdit(L,r,t,F,W);})),i.append(C);}else if(t.kind==="picture"){let C=t.imagePath?this.imageResources[t.imagePath]:void 0,N=C==null?void 0:C.url;if(N&&yl(C.contentType,t.imagePath)){if(Ik(t,r))i.append(Pk(t,N));else {let L=document.createElement("img");L.src=N,L.alt=(y=t.name)!=null?y:"",B0(L,t),t.imageOpacity!==void 0&&(L.style.opacity=String(Math.max(0,Math.min(1,t.imageOpacity)))),i.append(L);}t.lineColor&&i.append(Bk(t,n));}else i.dataset.unsupportedImage=t.imagePath?"true":"missing",C!=null&&C.contentType&&(i.dataset.imageContentType=C.contentType),t.imagePath&&(i.dataset.imagePath=t.imagePath),i.append(H0(t,C==null?void 0:C.contentType));}else {let C=(k=t.text)!=null?k:"";if(t.customGeometry||p||b||$0(t)){let N=document.createElement("div");N.className="coco-ppt-text-layer",z0(N,t),im(N,t,n,C),i.append(N),am(N,t),sm(N,t);}else im(i,t,n,C),am(i,t),sm(i,t);}if(pk(t)&&i.append(Wk(t,n)),!o)return i;let g=document.createElement("div");return g.className="coco-ppt-resize-handle",g.addEventListener("mousedown",C=>{this.isReadOnly()||!t.capabilities.editGeometry||(C.preventDefault(),C.stopPropagation(),this.startDrag(C,"resize",r,t,n,i));}),i.append(g),i.addEventListener("click",C=>{var L,F;if(this.hideContextMenu(),C.stopPropagation(),this.consumeSuppressedClick())return;if(C.altKey){let W=this.selection(),V=P0(r,C,n,(W==null?void 0:W.kind)==="shape"?W.shapeId:t.id);if(V){this.dispatch({kind:"select-shape",slideIdOrIndex:r.id,shapeIdOrName:V.node.id}),(F=(L=this.options).onObjectAction)==null||F.call(L,{action:"cycle-selection",slideId:r.id,shapeId:V.node.id,kind:V.node.kind,name:V.node.name,reason:`\u5DF2\u5207\u6362\u5230\u91CD\u53E0\u5BF9\u8C61 ${V.index+1}/${V.count}`,candidateIndex:V.index,candidateCount:V.count});return}}let N=this.pointerOperationNode(r,t,C,n);if(N){this.dispatch({kind:"select-shape",slideIdOrIndex:r.id,shapeIdOrName:N.id});return}this.dispatch({kind:"select-shape",slideIdOrIndex:r.id,shapeIdOrName:t.id});}),i.addEventListener("contextmenu",C=>{var L;if(this.isReadOnly())return;C.preventDefault(),C.stopPropagation();let N=(L=this.pointerOperationNode(r,t,C,n))!=null?L:t;this.dispatch({kind:"select-shape",slideIdOrIndex:r.id,shapeIdOrName:N.id}).then(()=>this.showContextMenu(C,r,N));}),i.addEventListener("mousedown",C=>{var F,W;let N=(F=this.pointerOperationNode(r,t,C,n))!=null?F:t,L=(W=hl(this.canvas,N.id))!=null?W:i;N0(L,C.target)||this.isReadOnly()||C.button!==0||!N.capabilities.editGeometry||(C.preventDefault(),C.stopPropagation(),this.startDrag(C,"move",r,N,n,L));}),i.addEventListener("dblclick",C=>{var L,F,W;if(this.isReadOnly())return;C.stopPropagation();let N=rm(r,t,C,n);if(N){this.startTextEdit((L=hl(this.canvas,N.id))!=null?L:i,r,N);return}if(!t.capabilities.editText){this.sessionValue.dispatch({kind:"select-shape",slideIdOrIndex:r.id,shapeIdOrName:t.id}).then(()=>this.renderSelection()),(W=(F=this.options).onObjectAction)==null||W.call(F,{action:"blocked-text-edit",slideId:r.id,shapeId:t.id,kind:t.kind,name:t.name,reason:A0(t)});return}this.startTextEdit(i,r,t);}),i}pointerOperationNode(t,n,r,o){let i=this.selection();return (i==null?void 0:i.kind)==="shape"&&i.slideId===t.id&&i.shapeId===n.id?n:rm(t,n,r,o)}notifyTableCellSelection(t,n,r){var a,l;let o=em(r);if(!o||!n.capabilities.editTableCells)return;let i=Number(o.dataset.row),s=Number(o.dataset.column);!Number.isInteger(i)||!Number.isInteger(s)||(l=(a=this.options).onTableCellSelectionChange)==null||l.call(a,{slideId:t.id,shapeId:n.id,row:i,column:s,text:fm(o,n,i,s)});}applyTextStyle(t,n,r){var s,a,l,c;let o=n.textStyle;o&&(xl(t,T0(n,o),r),o.alignment&&(vl(t,o.alignment),o.alignment==="center"&&(t.style.justifyContent="center"),o.alignment==="right"&&(t.style.justifyContent="flex-end")));let i=n.kind==="table"?void 0:n.textBody;if(i){let u=(s=i.insetLeft)!=null?s:91440,f=(a=i.insetTop)!=null?a:45720,p=(l=i.insetRight)!=null?l:91440,w=(c=i.insetBottom)!=null?c:45720,b=G0(n,r);t.style.padding=`${f*r+b}px ${p*r}px ${w*r}px ${u*r}px`,Sm(i)&&(t.style.writingMode="vertical-rl",t.style.textOrientation="upright"),i.anchor==="middle"&&(t.style.alignItems="center"),i.anchor==="bottom"&&(t.style.alignItems="flex-end"),i.anchor==="top"&&(t.style.alignItems="flex-start");}}startTextEdit(t,n,r){var p,w,b,g;if(this.isReadOnly())return;let o=(p=r.text)!=null?p:"",i=C0(t),s=false;this.sessionValue.dispatch({kind:"select-shape",slideIdOrIndex:n.id,shapeIdOrName:r.id}).then(()=>this.renderSelection()),(b=(w=this.options).onTextEditStateChange)==null||b.call(w,{state:"start",slideId:n.id,shapeId:r.id,text:o}),i.contentEditable="true",i.spellcheck=false,i.setAttribute("role","textbox"),i.setAttribute("aria-label",(g=r.name)!=null?g:"PPT text"),t.dataset.editing="true",this.canvas.dataset.interactionMode="editing",i.textContent=o,i.focus();let a=i.ownerDocument.getSelection();if(a){let h=i.ownerDocument.createRange();h.selectNodeContents(i),h.collapse(false),a.removeAllRanges(),a.addRange(h);}let l=h=>{var k,C,N,L,F;if(s)return;s=true,i.contentEditable="false",i.removeAttribute("role"),i.removeAttribute("aria-label"),delete t.dataset.editing,delete this.canvas.dataset.interactionMode,i.removeEventListener("blur",f),i.removeEventListener("keydown",c),i.removeEventListener("paste",u);let y=(k=i.textContent)!=null?k:"";if(!h){i.textContent=o,(N=(C=this.options).onTextEditStateChange)==null||N.call(C,{state:"cancel",slideId:n.id,shapeId:r.id,text:o}),this.render();return}(F=(L=this.options).onTextEditStateChange)==null||F.call(L,{state:"commit",slideId:n.id,shapeId:r.id,text:y}),y!==o?this.dispatch({kind:"set-shape-text",slideIdOrIndex:n.id,shapeIdOrName:r.id,text:y}):this.render();},c=h=>{if(h.key==="Escape"){h.preventDefault(),l(false);return}h.key==="Enter"&&!h.shiftKey&&(h.preventDefault(),l(true));},u=h=>{var k;let y=(k=h.clipboardData)==null?void 0:k.getData("text/plain");y!==void 0&&(h.preventDefault(),om(i,y));},f=()=>l(true);i.addEventListener("blur",f),i.addEventListener("keydown",c),i.addEventListener("paste",u);}startTableCellEdit(t,n,r,o,i){var w,b,g;if(this.isReadOnly())return;let s=fm(t,r,o,i),a=false;this.sessionValue.dispatch({kind:"select-shape",slideIdOrIndex:n.id,shapeIdOrName:r.id}).then(()=>this.renderSelection()),(b=(w=this.options).onTableCellSelectionChange)==null||b.call(w,{slideId:n.id,shapeId:r.id,row:o,column:i,text:s}),t.contentEditable="true",t.spellcheck=false,this.canvas.dataset.interactionMode="editing",t.setAttribute("role","textbox"),t.setAttribute("aria-label",`${(g=r.name)!=null?g:"PPT table"} cell ${o+1},${i+1}`),t.textContent=s,t.focus();let l=t.ownerDocument.getSelection();if(l){let h=t.ownerDocument.createRange();h.selectNodeContents(t),h.collapse(false),l.removeAllRanges(),l.addRange(h);}let c=h=>{var k;if(a)return;a=true,t.contentEditable="false",delete this.canvas.dataset.interactionMode,t.removeAttribute("role"),t.removeAttribute("aria-label"),t.removeEventListener("blur",p),t.removeEventListener("keydown",u),t.removeEventListener("paste",f);let y=(k=t.textContent)!=null?k:"";if(!h){t.textContent=s,t.dataset.cellText=s;return}y!==s?(t.dataset.cellText=y,this.dispatch({kind:"set-table-cell-text",slideIdOrIndex:n.id,shapeIdOrName:r.id,row:o,column:i,text:y})):this.render();},u=h=>{if(h.key==="Escape"){h.preventDefault(),c(false);return}h.key==="Enter"&&!h.shiftKey&&(h.preventDefault(),c(true));},f=h=>{var k;let y=(k=h.clipboardData)==null?void 0:k.getData("text/plain");y!==void 0&&(h.preventDefault(),om(t,y));},p=()=>c(true);t.addEventListener("blur",p),t.addEventListener("keydown",u),t.addEventListener("paste",f);}startDrag(t,n,r,o,i,s){this.isReadOnly()||(n==="resize"&&u0(s,o),this.dragState={mode:n,slideId:r.id,shapeId:o.id,slideSize:r.size,startClientX:t.clientX,startClientY:t.clientY,startBounds:v({},o.bounds),scale:i,element:s,active:false},this.sessionValue.dispatch({kind:"select-shape",slideIdOrIndex:r.id,shapeIdOrName:o.id}).then(()=>this.renderSelection()));}updateDrag(t){let n=this.dragState;if(!n)return;if(Math.hypot(t.clientX-n.startClientX,t.clientY-n.startClientY)<=fl){this.restoreDragElementBounds(n),this.hideSnapGuides(),n.active=false,this.clearDragVisualState(n.element,true);return}n.active=true,n.element.dataset.dragging="true",this.canvas.dataset.interactionMode="dragging";let o=(t.clientX-n.startClientX)/n.scale,i=(t.clientY-n.startClientY)/n.scale;if(n.mode==="move"){let{bounds:a}=t.altKey?{bounds:yn(n.startBounds,n.slideSize,{left:n.startBounds.left+o,top:n.startBounds.top+i})}:this.snapDragBounds(n,{left:n.startBounds.left+o,top:n.startBounds.top+i});t.altKey&&this.hideSnapGuides(),n.element.style.left=`${a.left*n.scale}px`,n.element.style.top=`${a.top*n.scale}px`;return}let{bounds:s}=t.altKey?{bounds:yn(n.startBounds,n.slideSize,{width:n.startBounds.width+o,height:n.startBounds.height+i})}:this.snapResizeBounds(n,{width:n.startBounds.width+o,height:n.startBounds.height+i});t.altKey&&this.hideSnapGuides(),n.element.style.width=`${s.width*n.scale}px`,n.element.style.height=`${s.height*n.scale}px`;}async finishDrag(t){var a,l;let n=this.dragState;if(!n)return;this.dragState=null;let r=(t.clientX-n.startClientX)/n.scale,o=(t.clientY-n.startClientY)/n.scale,i=Math.hypot(t.clientX-n.startClientX,t.clientY-n.startClientY);if(i<=fl||!n.active){this.hideSnapGuides(),this.clearDragVisualState(n.element);return}this.suppressClickAfterDrag=this.suppressClickAfterDrag||i>fl;let s=t.altKey?yn(n.startBounds,n.slideSize,n.mode==="move"?{left:n.startBounds.left+r,top:n.startBounds.top+o}:{width:n.startBounds.width+r,height:n.startBounds.height+o}):n.mode==="move"?this.snapDragBounds(n,{left:n.startBounds.left+r,top:n.startBounds.top+o}):this.snapResizeBounds(n,{width:n.startBounds.width+r,height:n.startBounds.height+o});if(this.hideSnapGuides(),this.clearDragVisualState(n.element),await this.dispatch({kind:"set-shape-geometry",slideIdOrIndex:n.slideId,shapeIdOrName:n.shapeId,geometry:"bounds"in s?s.bounds:s,preserveTextSizeOnResize:n.mode==="resize"}),"snapped"in s&&s.snapped){let c=this.currentSlide(),u=c==null?void 0:c.nodes.find(f=>f.id===n.shapeId);c&&u&&((l=(a=this.options).onObjectAction)==null||l.call(a,{action:"snap-geometry",slideId:c.id,shapeId:u.id,kind:u.kind,name:u.name,reason:this.snapActionReason(s,c)}));}}snapActionReason(t,n){let r=[...new Set(t.guides.map(o=>o.referenceShapeId).filter(o=>!!o))].map(o=>n.nodes.find(i=>i.id===o)).filter(o=>!!o).map(o=>o.name||o.id);return r.length>0?`\u5DF2\u5438\u9644\u5230 ${r.join("\u3001")}`:"\u5DF2\u5438\u9644\u5230\u9875\u9762\u53C2\u8003\u7EBF"}snapDragBounds(t,n){let r=yn(t.startBounds,t.slideSize,n),o=this.sessionValue.scene().slides.find(u=>u.id===t.slideId);if(!o)return this.hideSnapGuides(),{bounds:r,guides:[],snapped:false};let i=Math.min(18e4,Xf/t.scale),s=Ui([{offset:0,value:r.left,role:"start"},{offset:r.width/2,value:r.left+r.width/2,role:"center"},{offset:r.width,value:r.left+r.width,role:"end"}],ji(o,t.shapeId,"x"),i),a=Ui([{offset:0,value:r.top,role:"start"},{offset:r.height/2,value:r.top+r.height/2,role:"center"},{offset:r.height,value:r.top+r.height,role:"end"}],ji(o,t.shapeId,"y"),i),l=yn(t.startBounds,t.slideSize,{left:s?s.target.value-s.source.offset:r.left,top:a?a.target.value-a.source.offset:r.top}),c=[...s?[{axis:"x",value:s.target.value,kind:s.target.kind,referenceShapeId:s.target.referenceShapeId}]:[],...a?[{axis:"y",value:a.target.value,kind:a.target.kind,referenceShapeId:a.target.referenceShapeId}]:[]];return this.renderSnapGuides(c,t.scale),{bounds:l,guides:c,snapped:c.length>0}}snapResizeBounds(t,n){let r=yn(t.startBounds,t.slideSize,n),o=this.sessionValue.scene().slides.find(u=>u.id===t.slideId);if(!o)return this.hideSnapGuides(),{bounds:r,guides:[],snapped:false};let i=Math.min(18e4,Xf/t.scale),s=Ui([{offset:r.width/2,value:r.left+r.width/2,role:"center"},{offset:r.width,value:r.left+r.width,role:"end"}],ji(o,t.shapeId,"x"),i,{matchRole:false}),a=Ui([{offset:r.height/2,value:r.top+r.height/2,role:"center"},{offset:r.height,value:r.top+r.height,role:"end"}],ji(o,t.shapeId,"y"),i,{matchRole:false}),l=yn(t.startBounds,t.slideSize,{width:s?Yf(r.left,r.width,s.source,s.target.value):r.width,height:a?Yf(r.top,r.height,a.source,a.target.value):r.height}),c=[...s?[{axis:"x",value:s.target.value,kind:s.target.kind,referenceShapeId:s.target.referenceShapeId}]:[],...a?[{axis:"y",value:a.target.value,kind:a.target.kind,referenceShapeId:a.target.referenceShapeId}]:[]];return this.renderSnapGuides(c,t.scale),{bounds:l,guides:c,snapped:c.length>0}}renderSnapGuides(t,n){this.clearSnapReferenceHighlights();let r=new Set(t.map(o=>o.referenceShapeId).filter(o=>!!o));for(let o of r){let i=hl(this.canvas,o);i&&(i.dataset.snapReference="true");}this.snapGuides.replaceChildren(...t.map(o=>{let i=document.createElement("div");return i.className="coco-ppt-snap-guide",i.dataset.axis=o.axis,i.dataset.kind=o.kind,o.referenceShapeId&&(i.dataset.referenceShapeId=o.referenceShapeId),o.axis==="x"?i.style.left=`${o.value*n}px`:i.style.top=`${o.value*n}px`,i}));}hideSnapGuides(){this.clearSnapReferenceHighlights(),this.snapGuides.replaceChildren();}clearDragVisualState(t,n=false){delete t.dataset.dragging,(n||!this.dragState)&&delete this.canvas.dataset.interactionMode;}restoreDragElementBounds(t){if(t.mode==="move"){t.element.style.left=`${t.startBounds.left*t.scale}px`,t.element.style.top=`${t.startBounds.top*t.scale}px`;return}t.element.style.width=`${t.startBounds.width*t.scale}px`,t.element.style.height=`${t.startBounds.height*t.scale}px`;}clearSnapReferenceHighlights(){this.canvas.querySelectorAll('.coco-ppt-node[data-snap-reference="true"]').forEach(t=>{delete t.dataset.snapReference;});}handleKeyDown(t){if(t.defaultPrevented||this.dragState||nm(t.target)||this.root.querySelector('[contenteditable="true"]'))return;let n=this.selection();if((n==null?void 0:n.kind)!=="shape")return;let r=this.sessionValue.scene().slides.find(c=>c.id===n.slideId),o=r==null?void 0:r.nodes.find(c=>c.id===n.shapeId);if(!r||!o)return;let i=t.ctrlKey||t.metaKey;if(this.isReadOnly())return;if(i&&t.key.toLowerCase()==="c"){t.preventDefault(),this.copySelectedShape(r,o);return}if(i&&t.key.toLowerCase()==="v"){t.preventDefault(),this.pasteClipboardShape(r,o);return}if(i&&t.key.toLowerCase()==="d"){t.preventDefault(),this.duplicateSelectedShape(r,o);return}if(i&&t.shiftKey&&t.key==="]"){t.preventDefault(),this.bringSelectedShapeToFront(r,o);return}if(i&&t.shiftKey&&t.key==="["){t.preventDefault(),this.sendSelectedShapeToBack(r,o);return}if(t.key==="Delete"||t.key==="Backspace"){if(!Hn(o))return;t.preventDefault(),this.deleteSelectedShape(r,o);return}let s=I0(t.key);if(!s||!o.capabilities.editGeometry)return;let a=o0*(t.shiftKey?10:1),l=yn(o.bounds,r.size,{left:o.bounds.left+s.dx*a,top:o.bounds.top+s.dy*a});t.preventDefault(),this.dispatch({kind:"set-shape-geometry",slideIdOrIndex:r.id,shapeIdOrName:o.id,geometry:{left:l.left,top:l.top}}).then(()=>{var c,u;(u=(c=this.options).onObjectAction)==null||u.call(c,{action:"nudge-geometry",slideId:r.id,shapeId:o.id,kind:o.kind,name:o.name,reason:`\u5DF2\u79FB\u52A8\u5BF9\u8C61 ${s.label}${t.shiftKey?" 10\u6B65":" 1\u6B65"}`});});}handleSelectStart(t){this.isReadOnly()||nm(t.target)||t.target instanceof HTMLElement&&t.target.closest('[contenteditable="true"]')||t.preventDefault();}copySelectedShape(t,n){var r,o;Hn(n)&&(this.clipboardShape={slideId:t.id,shapeId:n.id},(o=(r=this.options).onObjectAction)==null||o.call(r,{action:"copy-shape",slideId:t.id,shapeId:n.id,kind:n.kind,name:n.name,reason:"\u5DF2\u590D\u5236\u5BF9\u8C61"}));}pasteClipboardShape(t,n){if(!this.clipboardShape)return;let r=this.clipboardShape;this.dispatch({kind:"paste-shape",slideIdOrIndex:r.slideId,shapeIdOrName:r.shapeId}).then(()=>{var i,s;let o=this.selection();(s=(i=this.options).onObjectAction)==null||s.call(i,{action:"paste-shape",slideId:r.slideId,shapeId:(o==null?void 0:o.kind)==="shape"?o.shapeId:n.id,kind:n.kind,name:n.name,reason:"\u5DF2\u7C98\u8D34\u5BF9\u8C61"});});}duplicateSelectedShape(t,n){Hn(n)&&this.dispatch({kind:"duplicate-shape",slideIdOrIndex:t.id,shapeIdOrName:n.id}).then(()=>{var o,i;let r=this.selection();(i=(o=this.options).onObjectAction)==null||i.call(o,{action:"duplicate-shape",slideId:t.id,shapeId:(r==null?void 0:r.kind)==="shape"?r.shapeId:n.id,kind:n.kind,name:n.name,reason:"\u5DF2\u91CD\u590D\u5BF9\u8C61"});});}bringSelectedShapeToFront(t,n){Hn(n)&&this.dispatch({kind:"bring-shape-to-front",slideIdOrIndex:t.id,shapeIdOrName:n.id}).then(()=>{var r,o;(o=(r=this.options).onObjectAction)==null||o.call(r,{action:"bring-shape-to-front",slideId:t.id,shapeId:n.id,kind:n.kind,name:n.name,reason:"\u5DF2\u7F6E\u4E8E\u9876\u5C42"});});}sendSelectedShapeToBack(t,n){Hn(n)&&this.dispatch({kind:"send-shape-to-back",slideIdOrIndex:t.id,shapeIdOrName:n.id}).then(()=>{var r,o;(o=(r=this.options).onObjectAction)==null||o.call(r,{action:"send-shape-to-back",slideId:t.id,shapeId:n.id,kind:n.kind,name:n.name,reason:"\u5DF2\u7F6E\u4E8E\u5E95\u5C42"});});}showContextMenu(t,n,r){if(this.isReadOnly())return;let o=Hn(r),i=!!this.clipboardShape,s=u=>()=>{this.hideContextMenu(),u();};this.contextMenu.replaceChildren(ir("\u590D\u5236","Ctrl+C",o,s(()=>this.copySelectedShape(n,r))),ir("\u7C98\u8D34","Ctrl+V",i,s(()=>this.pasteClipboardShape(n,r))),ir("\u91CD\u590D","Ctrl+D",o,s(()=>this.duplicateSelectedShape(n,r))),tm(),ir("\u7F6E\u4E8E\u9876\u5C42","Ctrl+Shift+]",o,s(()=>this.bringSelectedShapeToFront(n,r))),ir("\u7F6E\u4E8E\u5E95\u5C42","Ctrl+Shift+[",o,s(()=>this.sendSelectedShapeToBack(n,r))),tm(),ir("\u5220\u9664","Del",o,s(()=>this.deleteSelectedShape(n,r))));let a=this.root instanceof ShadowRoot?this.root.host.getBoundingClientRect():this.root.getBoundingClientRect(),l=Zi(t.clientX,a.left+4,window.innerWidth-170),c=Zi(t.clientY,a.top+4,window.innerHeight-220);this.contextMenu.style.left=`${l}px`,this.contextMenu.style.top=`${c}px`,this.contextMenu.dataset.shapeId=r.id,this.contextMenu.dataset.open="true";}deleteSelectedShape(t,n){Hn(n)&&this.dispatch({kind:"delete-shape",slideIdOrIndex:t.id,shapeIdOrName:n.id}).then(()=>{var r,o;(o=(r=this.options).onObjectAction)==null||o.call(r,{action:"delete-shape",slideId:t.id,shapeId:n.id,kind:n.kind,name:n.name,reason:"\u5DF2\u5220\u9664\u5BF9\u8C61"});});}async dispatchCurrentSlideSelection(){if(this.consumeSuppressedClick())return;let t=this.currentSlide();t&&await this.dispatch({kind:"select-slide",slideIdOrIndex:t.id});}consumeSuppressedClick(){return this.suppressClickAfterDrag?(this.suppressClickAfterDrag=false,true):false}dismissContextMenu(t){let n=t.composedPath()[0];n instanceof Node&&this.contextMenu.contains(n)||this.hideContextMenu();}hideContextMenu(){delete this.contextMenu.dataset.open,delete this.contextMenu.dataset.shapeId;}renderSelection(){this.canvas.querySelectorAll(".coco-ppt-parent-group-outline").forEach(n=>n.remove());let t=this.sessionValue.selection();this.slideList.querySelectorAll(".coco-ppt-thumb").forEach((n,r)=>{let o=this.sessionValue.scene().slides[r];n.dataset.selected=(t==null?void 0:t.slideId)===(o==null?void 0:o.id)?"true":"false";}),this.canvas.querySelectorAll(".coco-ppt-node").forEach(n=>{n.dataset.selected=(t==null?void 0:t.kind)==="shape"&&n.dataset.shapeId===t.shapeId?"true":"false";}),this.renderParentGroupSelection(t);}renderParentGroupSelection(t){var c,u;if((t==null?void 0:t.kind)!=="shape")return;let n=this.sessionValue.scene().slides.find(f=>f.id===t.slideId),r=(c=n==null?void 0:n.nodes.find(f=>f.id===t.shapeId))!=null?c:n==null?void 0:n.groups.find(f=>f.id===t.shapeId),o=r!=null&&r.groupContext?(u=n==null?void 0:n.groups.find(f=>{var p;return f.id===((p=r.groupContext)==null?void 0:p.parentId)}))!=null?u:d0(r):(r==null?void 0:r.kind)==="group"?r:null;if(!n||!o)return;let i=this.computeScale(n),s=document.createElement("div");s.className="coco-ppt-parent-group-outline",s.dataset.shapeId=o.id,s.dataset.selected=t.shapeId===o.id?"true":"false",s.title=`\u7236\u7EC4\uFF1A${o.name||o.id}`,s.style.left=`${o.bounds.left*i}px`,s.style.top=`${o.bounds.top*i}px`,s.style.width=`${o.bounds.width*i}px`,s.style.height=`${o.bounds.height*i}px`;let a=f=>{f.preventDefault(),f.stopPropagation(),this.startDrag(f,"move",n,o,i,s);};["top","right","bottom","left"].forEach(f=>{let p=document.createElement("div");p.className="coco-ppt-parent-group-edge",p.dataset.edge=f,p.title="\u62D6\u52A8\u7236\u7EC4",p.addEventListener("mousedown",a),s.append(p);});let l=document.createElement("div");l.className="coco-ppt-parent-group-handle",l.title="\u62D6\u52A8\u7236\u7EC4",l.addEventListener("mousedown",a),s.append(l),this.canvas.append(s);}currentSlide(){var r,o,i;let t=this.sessionValue.scene(),n=this.sessionValue.selection();return (n==null?void 0:n.kind)==="slide"||(n==null?void 0:n.kind)==="shape"?(o=(r=t.slides.find(s=>s.id===n.slideId))!=null?r:t.slides[0])!=null?o:null:(i=t.slides[0])!=null?i:null}computeScale(t){let n=this.canvas.parentElement,r=n?Math.max(1,n.clientWidth-48):960,o=n?Math.max(1,n.clientHeight-48):540;return Math.min(960/t.size.width,540/t.size.height,r/t.size.width,o/t.size.height)}};function u0(e,t){var r,o;if(!p0(t))return;let n=(o=(r=e.querySelector(".coco-ppt-rich-text, .coco-ppt-distributed-text"))!=null?r:e.querySelector(".coco-ppt-text-layer"))!=null?o:e;e.dataset.textResizePreview="wrap",n.dataset.textResizePreview="wrap",n.style.transform="",n.style.transformOrigin="",n.style.width="",e.style.whiteSpace="pre-wrap",e.style.overflowWrap="anywhere",e.querySelectorAll(".coco-ppt-rich-text, .coco-ppt-paragraph").forEach(i=>{i.style.whiteSpace="pre-wrap",i.style.overflowWrap="anywhere";});}function p0(e){var t;return !!(e.capabilities.editGeometry&&f0(e)&&(e.text||(t=e.textParagraphs)!=null&&t.length))}function f0(e){return e.kind==="placeholder"||e.kind==="textBox"||e.kind==="geometricShape"}function Zf(){return new Promise(e=>requestAnimationFrame(()=>e()))}async function m0(e,t,n,r,o,i=t,s=n){if(typeof XMLSerializer=="undefined"||typeof Blob=="undefined"||typeof URL=="undefined"||typeof URL.createObjectURL!="function")return null;await h0(e);let a=document.createElement("canvas");a.width=Math.max(1,Math.round(t*r)),a.height=Math.max(1,Math.round(n*r));let l=a.getContext("2d");if(!l)return null;let c=document.createElement("div");c.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),c.style.width=`${i}px`,c.style.height=`${s}px`,c.style.position="relative",c.style.overflow="hidden",c.style.background="#fff";let u=document.createElement("style");u.textContent=o;let f=e.cloneNode(true);await g0(f),f.style.position="relative",f.style.left="0",f.style.top="0",f.style.transform="none",c.append(u,f);let p=new XMLSerializer().serializeToString(c),w=`<svg xmlns="http://www.w3.org/2000/svg" width="${a.width}" height="${a.height}" viewBox="0 0 ${i} ${s}"><foreignObject width="100%" height="100%">${p}</foreignObject></svg>`,b=URL.createObjectURL(new Blob([w],{type:"image/svg+xml;charset=utf-8"}));try{let g=await x0(b);return l.drawImage(g,0,0,a.width,a.height),a}catch(g){return null}finally{URL.revokeObjectURL(b);}}function Jf(e){let t=document.createElement("canvas");t.className="coco-ppt-thumb-canvas",t.width=e.width,t.height=e.height;let n=t.getContext("2d");return n&&n.drawImage(e,0,0),t}function ml(e){return JSON.stringify({size:e.size,background:e.background,nodes:e.nodes.map(t=>wm(t))})}function wm(e){return {id:e.id,kind:e.kind,bounds:e.bounds,text:e.text,textParagraphs:e.textParagraphs,textStyle:e.textStyle,textBody:e.textBody,table:e.table,fillColor:e.fillColor,fillGradient:e.fillGradient,opacity:e.opacity,lineColor:e.lineColor,lineGradient:e.lineGradient,lineOpacity:e.lineOpacity,lineWidth:e.lineWidth,lineDash:e.lineDash,presetGeometry:e.presetGeometry,presetAdjustments:e.presetAdjustments,customGeometry:e.customGeometry,imagePath:e.imagePath,imageCrop:e.imageCrop,imageFillRect:e.imageFillRect,imageOpacity:e.imageOpacity,shadow:e.shadow,threeD:e.threeD,children:e.children.map(t=>wm(t))}}async function h0(e){let t=Array.from(e.querySelectorAll("img"));await Promise.all(t.map(async n=>{if(!(n.complete&&n.naturalWidth>0)){if(typeof n.decode=="function"){await n.decode().catch(()=>{});return}await new Promise(r=>{let o=()=>r();n.addEventListener("load",o,{once:true}),n.addEventListener("error",o,{once:true}),setTimeout(o,500);});}}));}async function g0(e){let t=Array.from(e.querySelectorAll("img"));await Promise.all(t.map(async n=>{n.alt="";let r=n.getAttribute("src");if(!r||r.startsWith("data:"))return;let o=await b0(r).catch(()=>{});o&&n.setAttribute("src",o);}));}async function b0(e){let t=await fetch(e);if(!t.ok)throw new Error(`Failed to inline thumbnail image: ${t.status}`);let n=await t.blob();return w0(n)}function w0(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=()=>{typeof r.result=="string"?t(r.result):n(new Error("Failed to read thumbnail image blob."));},r.onerror=()=>{var o;return n((o=r.error)!=null?o:new Error("Failed to read thumbnail image blob."))},r.readAsDataURL(e);})}function x0(e){return new Promise((t,n)=>{let r=new Image;r.onload=()=>t(r),r.onerror=()=>n(new Error("Failed to rasterize PPT thumbnail.")),r.src=e;})}function y0(e){return e.filter(v0).map(n=>{var s,a;let r=vm(n.family),o=(s=n.weight)!=null?s:400,i=(a=n.style)!=null?a:"normal";return `@font-face { font-family: ${r}; src: url(${W0(n.url)}); font-weight: ${o}; font-style: ${i}; }`}).join(`
1688
+ `)}function v0(e){return /font\/(ttf|otf|woff|woff2)|application\/font-(sfnt|woff|woff2)/i.test(e.contentType)}function S0(e,t=[]){if(typeof document=="undefined")return Promise.resolve();let n=new Set(e.map(o=>o.family));for(let o of t)n.add(o);let r=[];for(let o of n){let i=L0(o);if(!i)continue;let s=`coco-ppt-google-font-${o.replace(/[^a-zA-Z0-9_-]/g,"_")}`,a=document.getElementById(s);if(a){r.push(Qf(a));continue}let l=document.createElement("link");l.id=s,l.rel="stylesheet",l.href=i,r.push(Qf(l)),document.head.append(l);}return Promise.all(r).then(()=>{})}function k0(e){let t=new Set,n=o=>{o!=null&&o.trim()&&t.add(o.trim());},r=o=>{var i,s,a,l,c,u,f,p;n((i=o.textStyle)==null?void 0:i.fontFamily);for(let w of (s=o.textParagraphs)!=null?s:[]){n((a=w.style)==null?void 0:a.bulletFontFamily);for(let b of (l=w.runs)!=null?l:[])n((c=b.style)==null?void 0:c.fontFamily);}for(let w of (f=(u=o.table)==null?void 0:u.cellStyles)!=null?f:[])for(let b of w)n((p=b==null?void 0:b.textStyle)==null?void 0:p.fontFamily);for(let w of o.children)r(w);};for(let o of e.scene.slides)for(let i of o.nodes)r(i);return [...t]}function E0(e){globalThis.__cocoPptFontRenderReady=e;}function Qf(e){return e.sheet?Promise.resolve():new Promise(t=>{let n=()=>t();e.addEventListener("load",n,{once:true}),e.addEventListener("error",n,{once:true}),window.setTimeout(n,5e3);})}function C0(e){var t;return (t=e.querySelector(".coco-ppt-text-layer"))!=null?t:e}function em(e){let t=e.target;return t instanceof HTMLElement?t.closest("td[data-row][data-column]"):null}function ir(e,t,n,r){let o=document.createElement("button");o.type="button",o.disabled=!n;let i=document.createElement("strong");i.textContent=e;let s=document.createElement("span");return s.textContent=t,o.append(i,s),o.addEventListener("click",()=>{o.disabled||r();}),o}function tm(){return document.createElement("hr")}function I0(e){return e==="ArrowLeft"?{dx:-1,dy:0,label:"\u5DE6"}:e==="ArrowRight"?{dx:1,dy:0,label:"\u53F3"}:e==="ArrowUp"?{dx:0,dy:-1,label:"\u4E0A"}:e==="ArrowDown"?{dx:0,dy:1,label:"\u4E0B"}:null}function nm(e){if(!(e instanceof HTMLElement))return false;if(e.isContentEditable)return true;let t=e.tagName.toLowerCase();return t==="input"||t==="textarea"||t==="select"}function N0(e,t){return e.isContentEditable||t instanceof HTMLElement&&t.isContentEditable?true:!!e.querySelector('[contenteditable="true"]')}function T0(e,t){var a;let n=(a=e.textParagraphs)==null?void 0:a.filter(c=>c.runs.length>0);if(!(n!=null&&n.length)||!Cm(e,n))return t;let l=t,{textGradient:r,textFill:o,textOutlineColor:i}=l;return Nn(l,["textGradient","textFill","textOutlineColor"])}function rm(e,t,n,r){if(t.capabilities.editText||R0(t))return null;let o=xm(n,r);if(!o)return null;let i=e.nodes.findIndex(a=>a.id===t.id),s=e.nodes.slice(0,i<0?e.nodes.length:i);for(let a=s.length-1;a>=0;a--){let l=s[a];if(l.capabilities.editText&&ym(o.x,o.y,l.bounds))return l}return null}function P0(e,t,n,r){let o=M0(e,t,n);if(o.length<2)return null;let s=(Math.max(0,o.findIndex(a=>a.id===r))+1)%o.length;return {node:o[s],index:s,count:o.length}}function M0(e,t,n){let r=xm(t,n);if(!r)return [];let o=[];for(let i=e.nodes.length-1;i>=0;i--){let s=e.nodes[i];s.capabilities.select&&ym(r.x,r.y,s.bounds)&&o.push(s);}return o}function R0(e){return e.kind==="table"||e.kind==="chart"||e.kind==="smartArt"}function xm(e,t){var o;let n=e.currentTarget&&typeof e.currentTarget.parentElement=="object"&&(o=e.currentTarget.parentElement)!=null?o:null,r=n==null?void 0:n.getBoundingClientRect();return r?{x:(e.clientX-r.left)/t,y:(e.clientY-r.top)/t}:null}function ym(e,t,n){return e>=n.left&&e<=n.left+n.width&&t>=n.top&&t<=n.top+n.height}function hl(e,t){for(let n of Array.from(e.querySelectorAll(".coco-ppt-node")))if(n.dataset.shapeId===t)return n;return null}function om(e,t){var s,a;let n=e.ownerDocument.getSelection();if(!n||n.rangeCount===0){e.textContent=`${(s=e.textContent)!=null?s:""}${t}`;return}let r=n.getRangeAt(0);if(!(e===r.commonAncestorContainer||e.contains(r.commonAncestorContainer))){e.textContent=`${(a=e.textContent)!=null?a:""}${t}`;return}r.deleteContents();let i=e.ownerDocument.createTextNode(t);r.insertNode(i),r.setStartAfter(i),r.setEndAfter(i),n.removeAllRanges(),n.addRange(r);}function A0(e){var t;return (t=e.capabilities.reasons)!=null&&t.editText?e.capabilities.reasons.editText:e.capabilities.reason?e.capabilities.reason:e.kind==="table"?"\u8868\u683C\u8BF7\u4F7F\u7528\u5355\u5143\u683C\u7F16\u8F91":e.kind==="picture"?"\u56FE\u7247\u5BF9\u8C61\u4E0D\u652F\u6301\u6587\u5B57\u7F16\u8F91":e.kind==="chart"?"\u56FE\u8868\u5F53\u524D\u4EC5\u652F\u6301\u9009\u62E9\u548C\u4F4D\u7F6E\u7F16\u8F91":e.kind==="smartArt"?"SmartArt \u5F53\u524D\u4EC5\u652F\u6301\u9009\u62E9\u548C\u4F4D\u7F6E\u7F16\u8F91":e.kind==="group"?"\u7EC4\u5408\u5BF9\u8C61\u5F53\u524D\u4EC5\u652F\u6301\u9009\u62E9\u548C\u4F4D\u7F6E\u7F16\u8F91":"\u8BE5\u5BF9\u8C61\u4E0D\u652F\u6301\u6587\u5B57\u7F16\u8F91"}function L0(e){return {Cuprum:"https://fonts.googleapis.com/css2?family=Cuprum:ital,wght@0,400;0,700;1,400;1,700&display=swap",Podkova:"https://fonts.googleapis.com/css2?family=Podkova:wght@400;700&display=swap",Ubuntu:"https://fonts.googleapis.com/css2?family=Ubuntu:ital,wght@0,400;0,700;1,400;1,700&display=swap"}[e]}function bl(e){return [vm(e),'"Calibri"','"Microsoft YaHei"','"Segoe UI"',"sans-serif"].join(", ")}function vm(e){return `"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function W0(e){return `"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function cr(e,t){var a;if(t===void 0||t>=1)return e;let n=Math.max(0,Math.min(1,t)),r=(a=e.match(/^#([0-9a-fA-F]{6})$/))==null?void 0:a[1];if(!r)return e;let o=Number.parseInt(r.slice(0,2),16),i=Number.parseInt(r.slice(2,4),16),s=Number.parseInt(r.slice(4,6),16);return `rgba(${o}, ${i}, ${s}, ${n})`}function ur(e){var t;return e.opacity!==void 0?Math.max(0,Math.min(1,e.opacity)):((t=e.threeD)==null?void 0:t.material)==="translucentPowder"?.52:void 0}function B0(e,t){if(t.imageFillRect){F0(e,t);return}D0(e,t);}function D0(e,t){var c,u,f,p;let n=t.imageCrop;if(!n)return;let r=(c=n.left)!=null?c:0,o=(u=n.right)!=null?u:0,i=(f=n.top)!=null?f:0,s=(p=n.bottom)!=null?p:0,a=Math.max(.01,1-r-o),l=Math.max(.01,1-i-s);e.style.position="absolute",e.style.left=`${-r/a*100}%`,e.style.top=`${-i/l*100}%`,e.style.width=`${1/a*100}%`,e.style.height=`${1/l*100}%`;}function F0(e,t){var a,l,c,u;let n=t.imageFillRect;if(!n)return;let r=(a=n.left)!=null?a:0,o=(l=n.right)!=null?l:0,i=(c=n.top)!=null?c:0,s=(u=n.bottom)!=null?u:0;e.style.position="absolute",e.style.left=`${r*100}%`,e.style.top=`${i*100}%`,e.style.width=`${Math.max(.01,1-r-o)*100}%`,e.style.height=`${Math.max(.01,1-i-s)*100}%`;}function H0(e,t){var o,i;let n=document.createElement("div");n.className="coco-ppt-unsupported-image";let r=(i=(o=e.imagePath)==null?void 0:o.split(".").pop())==null?void 0:i.toUpperCase();return n.textContent=r||O0(t)||"IMAGE",n.title=e.imagePath?`Unsupported image: ${e.imagePath}`:"Missing image resource",n}function O0(e){if(e)return e.includes("emf")?"EMF":e.includes("wmf")?"WMF":e.includes("svg")?"SVG":"IMAGE"}function im(e,t,n,r){var a,l;let o=(a=t.textParagraphs)==null?void 0:a.filter(c=>c.runs.length>0),i=Sm(t.textBody);if(!(o!=null&&o.length)||!Cm(t,o)){!i&&((l=t.textStyle)==null?void 0:l.alignment)==="distributed"&&Array.from(r).length>1?ek(e,r):e.textContent=r;return}let s=document.createElement("div");s.className="coco-ppt-rich-text",o.forEach(c=>{var p,w,b,g;let u=document.createElement("div");u.className="coco-ppt-paragraph",(p=c.style)!=null&&p.alignment&&vl(u,c.style.alignment),nk(u,c.style,n,{verticalText:i});let f=!i&&((w=c.style)==null?void 0:w.alignment)==="distributed"&&!((b=c.style)!=null&&b.bullet);if(f&&(u.style.display="flex",u.style.justifyContent="space-between",u.style.alignItems="baseline",u.style.width="100%"),(g=c.style)!=null&&g.bullet){u.dataset.bullet="true";let h=document.createElement("span");h.className="coco-ppt-bullet",h.textContent=c.style.bullet,c.style.bulletColor&&(h.style.color=c.style.bulletColor),ok(h,c.style,n,c.text),u.append(h);}c.runs.forEach((h,y)=>{(f?Array.from(h.text):[h.text]).forEach(C=>{let N=document.createElement("span");N.textContent=C;let L=sk(t,c,h,y);L&&xl(N,L,n),u.append(N);});}),s.append(u);}),e.append(s);}function Sm(e){return (e==null?void 0:e.vertical)==="eastAsian"||(e==null?void 0:e.vertical)==="vertical"}function am(e,t){var n;((n=t.textBody)==null?void 0:n.wrap)==="none"&&km(e);}function sm(e,t){var n,r;((n=t.textBody)==null?void 0:n.autoFit)==="normal"&&(!t.text&&!((r=t.textParagraphs)!=null&&r.length)||(_0(t)&&!X0(t)&&km(e),requestAnimationFrame(()=>{var p;if(e.dataset.textResizePreview==="wrap")return;let o=e.clientWidth,i=e.clientHeight;if(o<=0||i<=0)return;let s=e.scrollWidth,a=e.scrollHeight,l=s>o?o/s:1,c=a>i?i/a:1,u=Math.max(.25,Math.min(1,l,c));if(u>=.995)return;let f=(p=e.querySelector(".coco-ppt-rich-text, .coco-ppt-distributed-text"))!=null?p:e;f.dataset.textResizePreview!=="wrap"&&(f.style.transformOrigin=Y0(t),f.style.transform=`scale(${u})`,f.style.width=`${100/u}%`);})));}function $0(e){var t;return !!((e.text||(t=e.textParagraphs)!=null&&t.length)&&(e.bounds.flipHorizontal||e.bounds.flipVertical))}function z0(e,t){let n=[];t.bounds.flipHorizontal&&n.push("scaleX(-1)"),t.bounds.flipVertical&&n.push("scaleY(-1)"),n.length!==0&&(e.style.transform=n.join(" "),e.style.transformOrigin="center");}function km(e){e.style.whiteSpace="nowrap",e.querySelectorAll(".coco-ppt-rich-text, .coco-ppt-paragraph").forEach(t=>{t.style.whiteSpace="nowrap";});}function V0(e,t,n){var o,i,s;if(!U0(t,n))return;let r=((s=(i=(o=t.textStyle)==null?void 0:o.fontSize)!=null?i:ea(t))!=null?s:28)*12700*n;e.style.letterSpacing=`${Math.max(1,Math.min(2.4,r*.035))}px`;}function G0(e,t){var r,o;if(!j0(e))return 0;let n=(o=(r=e.textStyle)==null?void 0:r.fontSize)!=null?o:ea(e);return n?n*12700*t*.18:0}function j0(e){var i,s,a,l,c,u,f,p,w;if(e.kind!=="textBox"&&e.kind!=="placeholder"||((i=e.textBody)==null?void 0:i.anchor)!=="top"||e.textBody.wrap!=="square"||e.fillColor||e.fillGradient||e.lineColor||e.lineGradient)return false;let t=(a=(s=e.textStyle)==null?void 0:s.fontFamily)!=null?a:Em(e);if(!t||!/\bCuprum\b/i.test(t))return false;let n=(c=(l=e.textStyle)==null?void 0:l.fontSize)!=null?c:ea(e);if(!n||n<72)return false;let r=(u=e.textParagraphs)==null?void 0:u.filter(b=>{var h;return ((h=b.text)!=null?h:b.runs.map(y=>y.text).join("")).trim().length>0});if(r&&r.length!==1)return false;let o=((w=(p=(f=r==null?void 0:r[0])==null?void 0:f.text)!=null?p:e.text)!=null?w:"").trim();return o.length>=12&&!/[\u3400-\u9fff]/.test(o)}function U0(e,t){var l,c,u,f,p,w,b,g,h,y,k,C,N,L,F,W,V,ee,pe,re;if(((l=e.textBody)==null?void 0:l.wrap)!=="square"||K0(e)||((w=(c=e.textStyle)==null?void 0:c.alignment)!=null?w:(p=(f=(u=e.textParagraphs)==null?void 0:u[0])==null?void 0:f.style)==null?void 0:p.alignment)!=="center")return false;let r=(g=(b=e.textStyle)==null?void 0:b.fontFamily)!=null?g:Em(e);if(!r||!/\bJosefin Sans\b/i.test(r))return false;let o=((C=(k=(y=(h=e.textParagraphs)==null?void 0:h[0])==null?void 0:y.text)!=null?k:e.text)!=null?C:"").replace(/\s+/g," ").trim();if(o.length<24||/[a-z\u3400-\u9fff]/.test(o)||!/^[A-Z0-9][A-Z0-9\s&:;,.!?'"()/+-]*$/.test(o))return false;let i=(L=(N=e.textStyle)==null?void 0:N.fontSize)!=null?L:ea(e);if(!i)return false;let s=(re=(pe=(F=e.textStyle)==null?void 0:F.lineHeight)!=null?pe:(ee=(V=(W=e.textParagraphs)==null?void 0:W[0])==null?void 0:V.style)==null?void 0:ee.lineHeight)!=null?re:1.2,a=i*12700*t*s;return e.bounds.height*t>=a*1.75}function K0(e){var t,n;return !!(((t=e.textStyle)==null?void 0:t.characterSpacing)!==void 0||(n=e.textParagraphs)!=null&&n.some(r=>r.runs.some(o=>{var i;return ((i=o.style)==null?void 0:i.characterSpacing)!==void 0})))}function ea(e){var t,n;for(let r of (t=e.textParagraphs)!=null?t:[])for(let o of r.runs)if(((n=o.style)==null?void 0:n.fontSize)!==void 0)return o.style.fontSize}function Em(e){var t,n;for(let r of (t=e.textParagraphs)!=null?t:[])for(let o of r.runs)if((n=o.style)!=null&&n.fontFamily)return o.style.fontFamily}function _0(e){var r,o,i,s,a,l;let t=(r=e.textParagraphs)==null?void 0:r.filter(c=>c.runs.length>0);if(t&&t.length!==1||(i=(o=t==null?void 0:t[0])==null?void 0:o.style)!=null&&i.bullet)return false;let n=(l=(a=(s=t==null?void 0:t[0])==null?void 0:s.text)!=null?a:e.text)!=null?l:"";return n.length>0&&!n.includes(`
1689
+ `)&&!n.includes("\r")}function q0(e){var o,i,s,a,l,c,u,f,p,w;if(((o=e.textBody)==null?void 0:o.wrap)!=="square"||((c=(i=e.textStyle)==null?void 0:i.alignment)!=null?c:(l=(a=(s=e.textParagraphs)==null?void 0:s[0])==null?void 0:a.style)==null?void 0:l.alignment)!=="center")return false;let t=((w=(p=(f=(u=e.textParagraphs)==null?void 0:u[0])==null?void 0:f.text)!=null?p:e.text)!=null?w:"").trim();if(!/^[\u3400-\u9fff]{4,6}$/.test(t))return false;let n=Math.min(e.bounds.width,e.bounds.height),r=Math.max(e.bounds.width,e.bounds.height);return n>0&&r<=11e5&&r/n<1.25}function X0(e){var r,o,i,s,a,l,c;if(q0(e))return true;if(((r=e.textBody)==null?void 0:r.wrap)!=="square")return false;let t=((a=(s=(i=(o=e.textParagraphs)==null?void 0:o[0])==null?void 0:i.text)!=null?s:e.text)!=null?a:"").trim();return t.length<18?false:((c=(l=t.match(/[\u3400-\u9fff]/g))==null?void 0:l.length)!=null?c:0)>=12?true:/[\s,。;、,.]/.test(t)}function Y0(e){var n,r,o,i,s;let t=(s=(n=e.textStyle)==null?void 0:n.alignment)!=null?s:(i=(o=(r=e.textParagraphs)==null?void 0:r[0])==null?void 0:o.style)==null?void 0:i.alignment;return t==="right"?"right top":t==="center"?"center top":"top left"}function Z0(e){var t;return e.kind!=="textBox"||!e.text&&!((t=e.textParagraphs)!=null&&t.length)||e.customGeometry||Mm(e)||Im(e)?false:!J0(e)&&!Q0(e)}function J0(e){var t,n;return (t=e.fillGradient)!=null&&t.colors.length?((n=e.fillGradient.opacities)!=null?n:[]).some(r=>r>0)||!e.fillGradient.opacities:!!(e.fillColor&&e.opacity!==0)}function Q0(e){var t,n;return !e.lineColor&&!((t=e.lineGradient)!=null&&t.colors.length)||e.lineOpacity===0?false:((n=e.lineWidth)!=null?n:9525)>0}function ek(e,t){let n=document.createElement("div");n.className="coco-ppt-distributed-text",Array.from(t).forEach(r=>{let o=document.createElement("span");o.textContent=r,n.append(o);}),e.append(n);}function Cm(e,t){return t.some(n=>{var r;return !!((r=n.style)!=null&&r.bullet)||tk(n.style)||n.runs.some(o=>!!o.hyperlink||o.style!==void 0&&ak(o.style,e.textStyle))})}function tk(e){return (e==null?void 0:e.lineHeight)!==void 0||(e==null?void 0:e.marginLeft)!==void 0||(e==null?void 0:e.textIndent)!==void 0||(e==null?void 0:e.spaceBefore)!==void 0||(e==null?void 0:e.spaceAfter)!==void 0}function nk(e,t,n,r={}){if(t){if(t.lineHeight!==void 0&&(e.style.lineHeight=String(rk(t))),t.marginLeft!==void 0&&(e.style.paddingLeft=`${t.marginLeft*n}px`),t.textIndent!==void 0&&(e.style.textIndent=`${t.textIndent*n}px`),r.verticalText){t.spaceBefore!==void 0&&(e.style.marginRight=Ki(t.spaceBefore,n)),t.spaceAfter!==void 0&&(e.style.marginLeft=Ki(t.spaceAfter,n));return}t.spaceBefore!==void 0&&(e.style.marginTop=Ki(t.spaceBefore,n)),t.spaceAfter!==void 0&&(e.style.marginBottom=Ki(t.spaceAfter,n));}}function rk(e){var n;let t=(n=e.lineHeight)!=null?n:1.2;return e.bullet?t*1.15:t}function ok(e,t,n,r=""){(t==null?void 0:t.bulletSize)!==void 0&&(t.bulletSize>4?e.style.fontSize=`${t.bulletSize*12700*n}px`:t.bulletSize>0&&(e.style.fontSize=`${t.bulletSize}em`)),ik(t,r)&&(e.style.width="0.5em",e.style.marginRight="0.12em",e.style.transform="scale(0.62)",e.style.transformOrigin="center",e.style.verticalAlign="middle");}function ik(e,t=""){var o,i;if(!e)return false;let n=(i=(o=e.bulletFontFamily)==null?void 0:o.toLowerCase())!=null?i:"",r=Array.from(t.trim()).length;return e.bullet==="\u25A1"&&e.alignment==="center"&&r>0&&r<=4&&(n.includes("wingdings")||n.includes("webdings"))&&e.textIndent!==void 0&&e.textIndent<0&&e.marginLeft!==void 0&&e.marginLeft<=Math.abs(e.textIndent)*1.25}function Ki(e,t){return e>10?`${e*t}px`:`${e}em`}function ak(e,t){let n=e,r=t;return e.fontSize!==void 0&&e.fontSize!==(t==null?void 0:t.fontSize)||e.fontFamily!==void 0&&e.fontFamily!==(t==null?void 0:t.fontFamily)||e.color!==void 0&&e.color!==(t==null?void 0:t.color)||n.textFill!==void 0&&n.textFill!==(r==null?void 0:r.textFill)||n.textGradient!==void 0&&n.textGradient!==(r==null?void 0:r.textGradient)||n.textOutlineColor!==void 0&&n.textOutlineColor!==(r==null?void 0:r.textOutlineColor)||n.textShadow!==void 0&&n.textShadow!==(r==null?void 0:r.textShadow)||e.bold!==void 0&&e.bold!==(t==null?void 0:t.bold)||e.italic!==void 0&&e.italic!==(t==null?void 0:t.italic)||e.underline!==void 0&&e.underline!==(t==null?void 0:t.underline)||e.characterSpacing!==void 0&&e.characterSpacing!==(t==null?void 0:t.characterSpacing)}function sk(e,t,n,r){var i,s,a,l;if(!lk(e,t,n,r))return lm(n,n.style);let o=dk(t.runs.slice(0,r));return lm(n,$(v({},n.style),{color:(s=(i=n.style)==null?void 0:i.color)!=null?s:"#000000",fontSize:(l=(a=n.style)==null?void 0:a.fontSize)!=null?l:Math.max(12,Math.round((o!=null?o:28)*.72))}))}function lm(e,t){if(!e.hyperlink)return t;let n=v({},t!=null?t:{});return n.textFill===void 0&&n.textGradient===void 0&&(n.color="#0563C1"),n.underline===void 0&&(n.underline=true),n}function lk(e,t,n,r){var a,l,c;if(r<=0||(a=n.style)!=null&&a.color&&n.style.fontSize!==void 0||((l=e.textBody)==null?void 0:l.autoFit)!=="shape"||!/[\u3400-\u9fff]/.test(n.text))return false;let o=t.runs.slice(0,r).map(u=>u.text).join(""),i=/^\s*\d{1,2}\s*[、..,,]\s*(.*)$/u.exec(o);return !i||Array.from((c=i[1])!=null?c:"").filter(u=>/[\u3400-\u9fff]/.test(u)).length>2?false:t.runs.slice(0,r).some(u=>{let f=u.style;return (f==null?void 0:f.color)!==void 0||(f==null?void 0:f.fontSize)!==void 0})}function dk(e){var t;for(let n of e)if(((t=n.style)==null?void 0:t.fontSize)!==void 0)return n.style.fontSize}function xl(e,t,n){var r,o,i;t.fontSize&&(e.style.fontSize=`${Math.max(1,t.fontSize*12700*n)}px`),t.fontFamily&&(e.style.fontFamily=bl(t.fontFamily)),t.lineHeight&&(e.style.lineHeight=String(t.lineHeight)),t.characterSpacing!==void 0&&(e.style.letterSpacing=`${t.characterSpacing*12700*n}px`),t.color&&(e.style.color=t.color),(r=t.textGradient)!=null&&r.colors.length&&t.textGradient.colors.length>1&&(e.style.backgroundImage=pr(t.textGradient),e.style.backgroundClip="text",e.style.setProperty("-webkit-background-clip","text"),e.style.color="transparent",e.style.setProperty("-webkit-text-fill-color","transparent")),t.textFill==="none"&&(e.style.color=(i=(o=t.textOutlineColor)!=null?o:t.color)!=null?i:"transparent",e.style.setProperty("-webkit-text-fill-color","transparent")),t.textOutlineColor&&e.style.setProperty("-webkit-text-stroke",`1px ${t.textOutlineColor}`),t.textShadow&&(e.style.textShadow=Lm(t.textShadow,n)),t.bold!==void 0&&(e.style.fontWeight=t.bold?"700":"400"),t.italic!==void 0&&(e.style.fontStyle=t.italic?"italic":"normal"),t.underline!==void 0&&(e.style.textDecorationLine=t.underline?"underline":"none");}function yl(e,t){var r;let n=(r=e==null?void 0:e.toLowerCase())!=null?r:"";return n==="image/png"||n==="image/jpeg"||n==="image/jpg"||n==="image/gif"||n==="image/webp"||n==="image/svg+xml"?true:!!(t&&/\.(?:png|jpe?g|gif|webp|svg)$/i.test(t))}function vl(e,t){if(t==="distributed"){e.style.textAlign="justify",e.style.textAlignLast="justify";return}e.style.textAlign=t==="justify"?"justify":t;}function Im(e){if(e.customGeometry)return false;let t=e.presetGeometry,n=Math.min(e.bounds.width,e.bounds.height),r=Math.max(e.bounds.width,e.bounds.height);return (t==="line"||t==="straightConnector1")&&r>0&&(n===0||n/r<.02)}function Nm(e){return e.bounds.height>e.bounds.width?"vertical":"horizontal"}function wl(e,t={}){var n;if(e!=null&&e.imagePath){let r=t[e.imagePath],o=r==null?void 0:r.url;if(o&&yl(r.contentType,e.imagePath))return `url("${o}") center / cover no-repeat`}return e!=null&&e.fillGradient&&e.fillGradient.colors.length>1?pr(e.fillGradient):(n=e==null?void 0:e.fillColor)!=null?n:"#fff"}function ck(e,t,n,r,o,i){if(t!=null&&t.imagePath){let s=i[t.imagePath],a=s==null?void 0:s.url;if(a&&yl(s.contentType,t.imagePath)){e.style.backgroundImage=`url("${a}")`,e.style.backgroundRepeat="no-repeat",e.style.backgroundSize=`${r.size.width*o}px ${r.size.height*o}px`,e.style.backgroundPosition=`${-n.bounds.left*o}px ${-n.bounds.top*o}px`;return}}e.style.background=wl(t,i);}function lr(e){var r;let t=(r=e.presetAdjustments)==null?void 0:r.adj,n=t===void 0?.08:Math.max(0,Math.min(.5,t/1e5));return Math.min(e.bounds.width,e.bounds.height)*n}function uk(e,t){var o,i,s;let n=(s=(o=e.presetAdjustments)==null?void 0:o.adj)!=null?s:(i=e.presetAdjustments)==null?void 0:i.adj1,r=n===void 0?.125:Math.max(.02,Math.min(.45,n/1e5));return Math.max(1,Math.min(e.bounds.width,e.bounds.height)*r*t)}function pk(e){return !e.customGeometry&&e.kind!=="line"&&!e.lineColor&&!!e.lineGradient&&e.lineGradient.colors.length>1&&(e.presetGeometry==="roundRect"||e.presetGeometry==="round1Rect"||e.presetGeometry==="ellipse")}function fk(e,t,n){var o;let r=document.createElement("div");return r.className="coco-ppt-css-geometry",r.style.clipPath=n,e.fillGradient&&e.fillGradient.colors.length>1?r.style.background=pr(e.fillGradient,ur(e)):e.fillColor&&(r.style.background=cr(e.fillColor,ur(e))),e.lineColor&&(r.style.borderStyle=Sl(e.lineDash),r.style.borderWidth=`${Math.max(1,((o=e.lineWidth)!=null?o:9525)*t)}px`,r.style.borderColor=cr(e.lineColor,e.lineOpacity)),r}function pr(e,t=1){return `linear-gradient(${Tm(e)}deg, ${hk(e,t).join(", ")})`}function Tm(e){return e.angle===void 0?160:mk(e.angle+90)}function mk(e){return (e%360+360)%360}function hk(e,t=1){return gk(e).map(n=>{let r=Math.max(0,Math.min(1,n.opacity*t)),o=r<1?Pm(n.color,r):n.color;return n.position===void 0?o:`${o} ${n.position}%`})}function gk(e){return e.colors.map((t,n)=>{var s,a,l,c,u;let r=kl(t),o=(s=e.positions)==null?void 0:s[n],i=Math.max(0,Math.min(1,(c=(l=(a=e.opacities)==null?void 0:a[n])!=null?l:r==null?void 0:r.opacity)!=null?c:1));return {color:(u=r==null?void 0:r.color)!=null?u:t,position:o===void 0?void 0:Math.max(0,Math.min(100,o)),opacity:i,index:n}}).sort((t,n)=>t.position===void 0&&n.position===void 0?t.index-n.index:t.position===void 0?1:n.position===void 0?-1:t.position-n.position||t.index-n.index).map(({color:t,position:n,opacity:r})=>({color:t,position:n,opacity:r}))}function Pm(e,t){var s;let n=(s=e.match(/^#([0-9a-fA-F]{6})$/))==null?void 0:s[1];if(!n)return e;let r=Number.parseInt(n.slice(0,2),16),o=Number.parseInt(n.slice(2,4),16),i=Number.parseInt(n.slice(4,6),16);return `rgba(${r}, ${o}, ${i}, ${Math.max(0,Math.min(1,t))})`}function bk(e){switch(e){case "parallelogram":return "polygon(18% 0, 100% 0, 82% 100%, 0 100%)";case "trapezoid":return "polygon(18% 0, 82% 0, 100% 100%, 0 100%)";case "snip2DiagRect":return "polygon(8% 0, 100% 0, 100% 92%, 92% 100%, 0 100%, 0 8%)";case "rtTriangle":return "polygon(0 0, 100% 100%, 0 100%)";case "triangle":return "polygon(50% 0, 100% 100%, 0 100%)";case "diamond":return "polygon(50% 0, 100% 50%, 50% 100%, 0 50%)";case "pentagon":return "polygon(0 0, 72% 0, 100% 50%, 72% 100%, 0 100%, 22% 50%)";case "hexagon":return "polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%)";case "homePlate":return "polygon(50% 0, 100% 25%, 100% 100%, 0 100%, 0 25%)";case "leftRightArrow":return "polygon(0 50%, 18% 0, 82% 0, 100% 50%, 82% 100%, 18% 100%)";case "chevron":return "polygon(0 0, 72% 0, 100% 50%, 72% 100%, 0 100%, 28% 50%)";case "plaque":return "polygon(0 12%, 3% 12%, 3% 0, 97% 0, 97% 12%, 100% 12%, 100% 88%, 97% 88%, 97% 100%, 3% 100%, 3% 88%, 0 88%)";case "rightArrow":return "polygon(0 0, 78% 0, 100% 50%, 78% 100%, 0 100%)";case "leftArrow":return "polygon(22% 0, 100% 0, 100% 100%, 22% 100%, 0 50%)";case "bentArrow":return "polygon(0 0, 30% 0, 30% 58%, 82% 58%, 82% 35%, 100% 70%, 82% 100%, 82% 77%, 12% 77%, 12% 18%, 0 18%)";default:return}}function Sl(e){return e==="dot"||e==="sysDot"?"dotted":e&&e!=="solid"?"dashed":"solid"}function ta(e,t){if(!e||e==="solid"||t<=0)return;let n=Math.max(1,t),r=/^cust:(\d+):(\d+)$/i.exec(e);if(r){let o=Number(r[1])/1e5,i=Number(r[2])/1e5;if(o>0&&i>=0)return `${n*o} ${n*i}`}switch(e){case "dot":case "sysDot":return `${n} ${n*2}`;case "dash":case "sysDash":return `${n*4} ${n*2}`;case "dashDot":case "sysDashDot":return `${n*4} ${n*2} ${n} ${n*2}`;case "lgDash":return `${n*8} ${n*3}`;case "lgDashDot":return `${n*8} ${n*3} ${n} ${n*3}`;case "lgDashDotDot":return `${n*8} ${n*3} ${n} ${n*3} ${n} ${n*3}`;default:return `${n*4} ${n*2}`}}function Mm(e){return e.presetGeometry==="curvedUpArrow"||e.presetGeometry==="donut"||e.presetGeometry==="arc"||e.presetGeometry==="blockArc"||e.presetGeometry==="plaque"||e.presetGeometry==="parallelogram"||e.presetGeometry==="trapezoid"||e.presetGeometry==="snip2DiagRect"||e.presetGeometry==="rtTriangle"||e.presetGeometry==="triangle"||e.presetGeometry==="diamond"||e.presetGeometry==="pentagon"||e.presetGeometry==="hexagon"||e.presetGeometry==="homePlate"||e.presetGeometry==="leftRightArrow"||e.presetGeometry==="chevron"||e.presetGeometry==="rightArrow"||e.presetGeometry==="leftArrow"||e.presetGeometry==="bentArrow"}function wk(e,t){var p,w,b;let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.classList.add("coco-ppt-preset-geometry");let r=Math.max(1,e.bounds.width*t),o=Math.max(1,e.bounds.height*t),i=xk(e,t,r,o);(e.shadow||i>0)&&(n.style.overflow="visible"),n.setAttribute("viewBox","0 0 100 100"),n.setAttribute("preserveAspectRatio","none");let s=e.fillGradient&&e.fillGradient.colors.length>1?`coco-ppt-preset-gradient-${e.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`:void 0,a=e.lineGradient&&e.lineGradient.colors.length>1?`coco-ppt-preset-line-gradient-${e.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`:void 0;if(s&&e.fillGradient&&On(n,s,e.fillGradient),a&&e.lineGradient&&On(n,a,e.lineGradient),i>0){let g=document.createElementNS("http://www.w3.org/2000/svg","path");g.classList.add("coco-ppt-preset-extrusion"),g.setAttribute("d",dm(e)),(e.presetGeometry==="donut"||e.presetGeometry==="blockArc")&&g.setAttribute("fill-rule","evenodd"),g.setAttribute("fill",yk(e)),g.setAttribute("transform",`translate(${ar(i*.38)} ${ar(i)})`),g.setAttribute("stroke","none"),n.append(g);}let l=document.createElementNS("http://www.w3.org/2000/svg","path");l.setAttribute("d",dm(e)),(e.presetGeometry==="donut"||e.presetGeometry==="blockArc")&&l.setAttribute("fill-rule","evenodd");let c=e.lineColor||e.lineGradient?Math.max(.5,((p=e.lineWidth)!=null?p:9525)*t*100/Math.max(r,o)):0;l.setAttribute("fill",e.presetGeometry==="arc"?"none":s?`url(#${s})`:(w=e.fillColor)!=null?w:"none");let u=ur(e);u!==void 0&&e.presetGeometry!=="arc"&&l.setAttribute("fill-opacity",String(u)),l.setAttribute("stroke",a?`url(#${a})`:(b=e.lineColor)!=null?b:"none"),l.setAttribute("stroke-width",String(c)),e.lineOpacity!==void 0&&l.setAttribute("stroke-opacity",String(Math.max(0,Math.min(1,e.lineOpacity))));let f=ta(e.lineDash,c);return f&&l.setAttribute("stroke-dasharray",f),l.setAttribute("stroke-linejoin","round"),e.presetGeometry==="arc"&&(l.setAttribute("stroke-linecap","round"),Ck(n,l,e)),n.append(l),n}function xk(e,t,n,r){var s,a;let o=(a=(s=e.threeD)==null?void 0:s.extrusionHeight)!=null?a:0;if(o<=0||e.presetGeometry==="arc")return 0;let i=o*t*100/Math.max(n,r);return Math.max(.8,Math.min(3,i))}function yk(e){var o,i,s,a,l;let t=(s=(i=(o=e.fillGradient)==null?void 0:o.colors[0])!=null?i:e.fillColor)!=null?s:"#64748B",n=kl(t),r=((a=e.threeD)==null?void 0:a.material)==="translucentPowder"?.12:.18;return Pm(vk((l=n==null?void 0:n.color)!=null?l:t,.8),r)}function vk(e,t){let n=/^#?([0-9a-f]{6})$/i.exec(e);if(!n)return e;let r=n[1],o=Number.parseInt(r.slice(0,2),16),i=Number.parseInt(r.slice(2,4),16),s=Number.parseInt(r.slice(4,6),16);return `#${dr(o*t)}${dr(i*t)}${dr(s*t)}`}function dm(e){switch(e.presetGeometry){case "curvedUpArrow":return ["M 16 88","C 3 61 9 28 38 13","C 60 2 87 9 97 34","L 82 36","C 74 22 59 18 45 24","C 23 33 17 61 28 82","Z","M 76 21","L 100 38","L 74 53","Z"].join(" ");case "donut":return ["M 50 2","A 48 48 0 1 1 49.99 2","M 50 27","A 23 23 0 1 0 50.01 27"].join(" ");case "blockArc":return Sk(e);case "plaque":return "M 4 0 H 96 Q 96 8 100 8 V 92 Q 96 92 96 100 H 4 Q 4 92 0 92 V 8 Q 4 8 4 0 Z";case "parallelogram":return "M 18 0 H 100 L 82 100 H 0 Z";case "trapezoid":return "M 18 0 H 82 L 100 100 H 0 Z";case "snip2DiagRect":return "M 8 0 H 100 V 92 L 92 100 H 0 V 8 Z";case "rtTriangle":return "M 0 0 L 100 100 H 0 Z";case "triangle":return "M 50 0 L 100 100 H 0 Z";case "diamond":return "M 50 0 L 100 50 L 50 100 L 0 50 Z";case "pentagon":return "M 0 0 H 72 L 100 50 L 72 100 H 0 L 22 50 Z";case "hexagon":return "M 25 0 H 75 L 100 50 L 75 100 H 25 L 0 50 Z";case "homePlate":return "M 50 0 L 100 25 V 100 H 0 V 25 Z";case "leftRightArrow":return "M 0 50 L 18 0 H 82 L 100 50 L 82 100 H 18 Z";case "chevron":return "M 0 0 H 72 L 100 50 L 72 100 H 0 L 28 50 Z";case "rightArrow":return "M 0 0 H 78 L 100 50 L 78 100 H 0 Z";case "leftArrow":return "M 22 0 H 100 V 100 H 22 L 0 50 Z";case "bentArrow":return "M 0 0 H 30 V 58 H 82 V 35 L 100 70 L 82 100 V 77 H 12 V 18 H 0 Z";case "arc":return Ek(e);default:return ""}}function Sk(e){var g,h,y,k,C,N;let t=((h=(g=e.presetAdjustments)==null?void 0:g.adj1)!=null?h:0)/6e4,n=((k=(y=e.presetAdjustments)==null?void 0:y.adj2)!=null?k:54e5)/6e4,r=kk(n-t),o=t+r,i=48,s=Math.max(.08,Math.min(.42,((N=(C=e.presetAdjustments)==null?void 0:C.adj3)!=null?N:25e3)/1e5)),a=i*(1-s),l=po(t,i),c=po(o,i),u=po(o,a),f=po(t,a),p=Math.abs(r)>180?1:0,w=r>=0?1:0,b=w?0:1;return [`M ${l.x.toFixed(3)} ${l.y.toFixed(3)}`,`A ${i} ${i} 0 ${p} ${w} ${c.x.toFixed(3)} ${c.y.toFixed(3)}`,`L ${u.x.toFixed(3)} ${u.y.toFixed(3)}`,`A ${a.toFixed(3)} ${a.toFixed(3)} 0 ${p} ${b} ${f.x.toFixed(3)} ${f.y.toFixed(3)}`,"Z"].join(" ")}function kk(e){if(!Number.isFinite(e)||e===0)return 90;let t=e%360;return t>330&&(t=330),t<-330&&(t=-330),Math.abs(t)<8&&(t=t<0?-8:8),t}function Ek(e){var a,l,c,u,f,p,w,b;let t=cm((l=(a=e.presetAdjustments)==null?void 0:a.adj1)!=null?l:18e6),n=cm((u=(c=e.presetAdjustments)==null?void 0:c.adj2)!=null?u:0),r=((p=(f=e.presetAdjustments)==null?void 0:f.adj1)!=null?p:18e6)/6e4,s=((((b=(w=e.presetAdjustments)==null?void 0:w.adj2)!=null?b:0)/6e4-r)%360+360)%360>180?1:0;return `M ${t.x.toFixed(3)} ${t.y.toFixed(3)} A 48 48 0 ${s} 1 ${n.x.toFixed(3)} ${n.y.toFixed(3)}`}function cm(e){return po(e/6e4,48)}function po(e,t){let n=e/180*Math.PI;return {x:50+t*Math.cos(n),y:50+t*Math.sin(n)}}function Ck(e,t,n){var s,a;if(n.lineHeadEnd!=="triangle"&&n.lineTailEnd!=="triangle")return;let r=`coco-ppt-arc-arrow-${n.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`,o=document.createElementNS("http://www.w3.org/2000/svg","marker");o.setAttribute("id",r),o.setAttribute("viewBox","0 0 10 10"),o.setAttribute("markerWidth","7"),o.setAttribute("markerHeight","7"),o.setAttribute("refX","5"),o.setAttribute("refY","5"),o.setAttribute("orient","auto-start-reverse");let i=document.createElementNS("http://www.w3.org/2000/svg","path");i.setAttribute("d","M 0 0 L 10 5 L 0 10 Z"),i.setAttribute("fill",(a=(s=n.lineColor)!=null?s:n.fillColor)!=null?a:"#000000"),o.append(i),e.append(o),n.lineHeadEnd==="triangle"&&t.setAttribute("marker-start",`url(#${r})`),n.lineTailEnd==="triangle"&&t.setAttribute("marker-end",`url(#${r})`);}function Ik(e,t){if(!e.customGeometry||Nk(e.customGeometry))return false;let n=Math.max(0,e.bounds.width)*Math.max(0,e.bounds.height),r=Math.max(1,t.size.width*t.size.height),o=n/r>.85,i=Math.abs(e.bounds.left)<t.size.width*.05&&Math.abs(e.bounds.top)<t.size.height*.05;return !(o&&i)}function Nk(e){var a,l;if(e.paths.length!==1)return false;let t=e.paths[0];if(!t)return false;let n=(a=t.width)!=null?a:0,r=(l=t.height)!=null?l:0;if(n<=0||r<=0)return false;let o=[];for(let c of t.commands)if(c.kind==="moveTo"||c.kind==="lineTo")o.push({x:c.x,y:c.y});else if(c.kind!=="close")return false;let i=Tk(o);return i.length!==4&&i.length!==5?false:[{x:0,y:0},{x:n,y:0},{x:n,y:r},{x:0,y:r}].every(c=>i.some(u=>Ji(u.x,c.x)&&Ji(u.y,c.y)))}function Tk(e){let t=[];for(let n of e)t.some(r=>Ji(r.x,n.x)&&Ji(r.y,n.y))||t.push(n);return t}function Ji(e,t){return Math.abs(e-t)<=1}function Pk(e,t){var u,f,p,w,b,g,h,y;let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.classList.add("coco-ppt-custom-geometry","coco-ppt-picture-clip");let r=Math.max(1,(p=(f=(u=e.customGeometry)==null?void 0:u.paths[0])==null?void 0:f.width)!=null?p:e.bounds.width),o=Math.max(1,(g=(b=(w=e.customGeometry)==null?void 0:w.paths[0])==null?void 0:b.height)!=null?g:e.bounds.height);n.setAttribute("viewBox",`0 0 ${r} ${o}`),n.setAttribute("preserveAspectRatio","none");let i=`coco-ppt-picture-clip-${e.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`,s=document.createElementNS("http://www.w3.org/2000/svg","defs"),a=document.createElementNS("http://www.w3.org/2000/svg","clipPath");a.setAttribute("id",i);for(let k of (y=(h=e.customGeometry)==null?void 0:h.paths)!=null?y:[]){let C=document.createElementNS("http://www.w3.org/2000/svg","path");C.setAttribute("d",Am(k.commands)),Rm(k.commands)&&C.setAttribute("fill-rule","evenodd"),a.append(C);}s.append(a),n.append(s);let l=document.createElementNS("http://www.w3.org/2000/svg","image");l.setAttribute("href",t),l.setAttributeNS("http://www.w3.org/1999/xlink","href",t);let c=Mk(e,r,o);return l.setAttribute("x",String(c.x)),l.setAttribute("y",String(c.y)),l.setAttribute("width",String(c.width)),l.setAttribute("height",String(c.height)),l.setAttribute("preserveAspectRatio","none"),l.setAttribute("clip-path",`url(#${i})`),e.imageOpacity!==void 0&&l.setAttribute("opacity",String(Math.max(0,Math.min(1,e.imageOpacity)))),n.append(l),n}function Mk(e,t,n){var u,f,p,w,b,g,h,y;if(e.imageFillRect){let k=(u=e.imageFillRect.left)!=null?u:0,C=(f=e.imageFillRect.right)!=null?f:0,N=(p=e.imageFillRect.top)!=null?p:0,L=(w=e.imageFillRect.bottom)!=null?w:0;return {x:k*t,y:N*n,width:Math.max(.01,1-k-C)*t,height:Math.max(.01,1-N-L)*n}}let r=e.imageCrop;if(!r)return {x:0,y:0,width:t,height:n};let o=(b=r.left)!=null?b:0,i=(g=r.right)!=null?g:0,s=(h=r.top)!=null?h:0,a=(y=r.bottom)!=null?y:0,l=Math.max(.01,1-o-i),c=Math.max(.01,1-s-a);return {x:-o/l*t,y:-s/c*n,width:1/l*t,height:1/c*n}}function Rk(e,t){var a,l,c,u,f,p,w,b,g,h;let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.classList.add("coco-ppt-custom-geometry");let r=(c=(l=(a=e.customGeometry)==null?void 0:a.paths[0])==null?void 0:l.width)!=null?c:e.bounds.width,o=(p=(f=(u=e.customGeometry)==null?void 0:u.paths[0])==null?void 0:f.height)!=null?p:e.bounds.height;n.setAttribute("viewBox",`0 0 ${Math.max(1,r)} ${Math.max(1,o)}`),n.setAttribute("preserveAspectRatio","none");let i=e.fillGradient&&e.fillGradient.colors.length>1?`coco-ppt-gradient-${e.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`:void 0,s=e.lineGradient&&e.lineGradient.colors.length>1?`coco-ppt-custom-line-gradient-${e.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`:void 0;i&&e.fillGradient&&On(n,i,e.fillGradient),s&&e.lineGradient&&On(n,s,e.lineGradient);for(let y of (b=(w=e.customGeometry)==null?void 0:w.paths)!=null?b:[]){let k=Lk(e,y),C=Ak(y),N=C?document.createElementNS("http://www.w3.org/2000/svg","ellipse"):document.createElementNS("http://www.w3.org/2000/svg","path");C?(N.setAttribute("cx",String(C.cx)),N.setAttribute("cy",String(C.cy)),N.setAttribute("rx",String(C.rx)),N.setAttribute("ry",String(C.ry))):(N.setAttribute("d",Am(y.commands)),Rm(y.commands)&&N.setAttribute("fill-rule","evenodd"));let L=!(e.kind==="line"&&e.lineDash);N.setAttribute("fill",L?i?`url(#${i})`:(g=e.fillColor)!=null?g:"none":"none");let F=ur(e);L&&F!==void 0&&N.setAttribute("fill-opacity",String(F)),N.setAttribute("stroke",s?`url(#${s})`:(h=e.lineColor)!=null?h:"none"),N.setAttribute("stroke-width",String(k)),e.lineOpacity!==void 0&&N.setAttribute("stroke-opacity",String(Math.max(0,Math.min(1,e.lineOpacity))));let W=ta(e.lineDash,k);W&&N.setAttribute("stroke-dasharray",W),N.setAttribute("stroke-linejoin","round"),N.setAttribute("stroke-linecap","round"),n.append(N);}return n}function Ak(e){var u,f,p,w,b,g;let t=e.width,n=e.height;if(!t||!n||t<=0||n<=0)return;let r=e.commands;if(r.length!==6||((u=r[0])==null?void 0:u.kind)!=="moveTo"||((f=r[1])==null?void 0:f.kind)!=="cubicBezierTo"||((p=r[2])==null?void 0:p.kind)!=="cubicBezierTo"||((w=r[3])==null?void 0:w.kind)!=="cubicBezierTo"||((b=r[4])==null?void 0:b.kind)!=="cubicBezierTo"||((g=r[5])==null?void 0:g.kind)!=="close")return;let o=t/2,i=n/2,s=[r[0],r[1],r[2],r[3],r[4]],a=[{x:t,y:i},{x:o,y:n},{x:0,y:i},{x:o,y:0},{x:t,y:i}],l=Math.max(t,n)*.003;return s.every((h,y)=>h.kind!=="moveTo"&&h.kind!=="cubicBezierTo"?false:Math.abs(h.x-a[y].x)<=l&&Math.abs(h.y-a[y].y)<=l)?{cx:o,cy:i,rx:t/2,ry:n/2}:void 0}function Rm(e){return e.filter(t=>t.kind==="moveTo").length>1}function Lk(e,t){if(!e.lineWidth)return 0;let n=t.width&&e.bounds.width?t.width/e.bounds.width:void 0,r=t.height&&e.bounds.height?t.height/e.bounds.height:void 0,o=[n,r].filter(s=>s!==void 0&&Number.isFinite(s)&&s>0),i=o.length>0?Math.max(...o):1;return Math.max(.5,e.lineWidth*i)}function Wk(e,t){var u;let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.classList.add("coco-ppt-gradient-outline");let r=Math.max(1,e.bounds.width*t),o=Math.max(1,e.bounds.height*t),i=Math.max(1,((u=e.lineWidth)!=null?u:9525)*t),s=i/2,a=`coco-ppt-line-gradient-${e.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`;n.setAttribute("viewBox",`0 0 ${r} ${o}`),n.setAttribute("preserveAspectRatio","none"),On(n,a,e.lineGradient);let l=e.presetGeometry==="ellipse"?document.createElementNS("http://www.w3.org/2000/svg","ellipse"):document.createElementNS("http://www.w3.org/2000/svg","rect");l.tagName==="ellipse"?(l.setAttribute("cx",String(r/2)),l.setAttribute("cy",String(o/2)),l.setAttribute("rx",String(Math.max(0,r/2-s))),l.setAttribute("ry",String(Math.max(0,o/2-s)))):(l.setAttribute("x",String(s)),l.setAttribute("y",String(s)),l.setAttribute("width",String(Math.max(0,r-i))),l.setAttribute("height",String(Math.max(0,o-i))),l.setAttribute("rx",String(Math.max(0,lr(e)*t-s))),l.setAttribute("ry",String(Math.max(0,lr(e)*t-s)))),l.setAttribute("fill","none"),l.setAttribute("stroke",`url(#${a})`),l.setAttribute("stroke-width",String(i)),e.lineOpacity!==void 0&&l.setAttribute("stroke-opacity",String(Math.max(0,Math.min(1,e.lineOpacity))));let c=ta(e.lineDash,i);return c&&l.setAttribute("stroke-dasharray",c),n.append(l),n}function Bk(e,t){var u,f;let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.classList.add("coco-ppt-solid-outline");let r=Math.max(1,e.bounds.width*t),o=Math.max(1,e.bounds.height*t),i=Math.max(1,((u=e.lineWidth)!=null?u:9525)*t),s=e.kind!=="picture",a=s?i/2:0;s||(n.style.overflow="visible"),n.setAttribute("viewBox",`0 0 ${r} ${o}`),n.setAttribute("preserveAspectRatio","none");let l=e.presetGeometry==="ellipse"?document.createElementNS("http://www.w3.org/2000/svg","ellipse"):document.createElementNS("http://www.w3.org/2000/svg","rect");if(l.tagName==="ellipse")l.setAttribute("cx",String(r/2)),l.setAttribute("cy",String(o/2)),l.setAttribute("rx",String(Math.max(0,r/2-a))),l.setAttribute("ry",String(Math.max(0,o/2-a)));else {l.setAttribute("x",String(a)),l.setAttribute("y",String(a)),l.setAttribute("width",String(Math.max(0,r-a*2))),l.setAttribute("height",String(Math.max(0,o-a*2)));let p=e.presetGeometry==="roundRect"||e.presetGeometry==="round1Rect"?Math.max(0,lr(e)*t-a):0;l.setAttribute("rx",String(p)),l.setAttribute("ry",String(p));}l.setAttribute("fill","none"),l.setAttribute("stroke",(f=e.lineColor)!=null?f:"none"),l.setAttribute("stroke-width",String(i)),e.lineOpacity!==void 0&&l.setAttribute("stroke-opacity",String(Math.max(0,Math.min(1,e.lineOpacity))));let c=ta(e.lineDash,i);return c&&l.setAttribute("stroke-dasharray",c),n.append(l),n}function Dk(e,t){var b,g;let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.classList.add("coco-ppt-line-geometry");let r=Nm(e)==="vertical",o=Math.max(r?12:1,e.bounds.width*t),i=Math.max(r?1:12,e.bounds.height*t);n.setAttribute("viewBox",`0 0 ${o} ${i}`),n.setAttribute("preserveAspectRatio","none");let s=Math.max(1,((b=e.lineWidth)!=null?b:9525)*t),a=e.lineGradient&&e.lineGradient.colors.length>1?`coco-ppt-connector-gradient-${e.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`:void 0;a&&e.lineGradient&&On(n,a,e.lineGradient);let l=a?`url(#${a})`:cr((g=e.lineColor)!=null?g:"#000000",e.lineOpacity),c=Fk(s),u=Math.max(5,s*3.2),f=Math.max(5,s*2.6),p=um(e.lineHeadEnd),w=um(e.lineTailEnd);if(r){let h=o/2,y=p?Math.min(i,u):0,k=w?Math.max(0,i-u):i;fr(n,h,y,h,k,l,s,e.lineOpacity,e.lineCap),e.lineHeadEnd==="oval"&&vn(n,h,0,c,l),e.lineTailEnd==="oval"&&vn(n,h,i,c,l),p&&Xi(n,h,0,"up",u,f,l,e.lineOpacity),w&&Xi(n,h,i,"down",u,f,l,e.lineOpacity);}else {let h=i/2,y=p?Math.min(o,u):0,k=w?Math.max(0,o-u):o;fr(n,y,h,k,h,l,s,e.lineOpacity,e.lineCap),e.lineHeadEnd==="oval"&&vn(n,0,h,c,l),e.lineTailEnd==="oval"&&vn(n,o,h,c,l),p&&Xi(n,0,h,"left",u,f,l,e.lineOpacity),w&&Xi(n,o,h,"right",u,f,l,e.lineOpacity);}return n}function Fk(e){return Math.max(3,e*3)}function um(e){return e==="arrow"||e==="triangle"}function Am(e){let t=[],n;for(let r of e)if(r.kind==="moveTo")t.push(`M ${r.x} ${r.y}`),n={x:r.x,y:r.y};else if(r.kind==="lineTo")t.push(`L ${r.x} ${r.y}`),n={x:r.x,y:r.y};else if(r.kind==="cubicBezierTo")t.push(`C ${r.x1} ${r.y1} ${r.x2} ${r.y2} ${r.x} ${r.y}`),n={x:r.x,y:r.y};else if(r.kind==="arcTo"){let o=Hk(r,n);o&&(t.push(o.path),n=o.end);}else t.push("Z");return t.join(" ")}function Hk(e,t){if(!t||e.wR<=0||e.hR<=0||e.swAng===0)return;let n=e.stAng/6e4,r=e.swAng/6e4,o=n+r,i=pm(e.wR,e.hR,n),s={x:t.x-i.x,y:t.y-i.y},a=pm(e.wR,e.hR,o),l={x:s.x+a.x,y:s.y+a.y},c=Math.abs(r)>180?1:0,u=r>=0?1:0;return {path:`A ${ar(e.wR)} ${ar(e.hR)} 0 ${c} ${u} ${ar(l.x)} ${ar(l.y)}`,end:l}}function pm(e,t,n){let r=n/180*Math.PI;return {x:e*Math.cos(r),y:t*Math.sin(r)}}function ar(e){return Number.isInteger(e)?String(e):e.toFixed(3).replace(/\.?0+$/,"")}function On(e,t,n){let r=document.createElementNS("http://www.w3.org/2000/svg","defs"),o=Array.isArray(n)?n:n.colors,i=Array.isArray(n)?void 0:n.positions,s=Array.isArray(n)?void 0:n.opacities,a=document.createElementNS("http://www.w3.org/2000/svg","linearGradient"),l=Array.isArray(n)?{x1:0,y1:0,x2:100,y2:100}:Ok(Tm(n));a.setAttribute("id",t),a.setAttribute("x1",`${l.x1}%`),a.setAttribute("y1",`${l.y1}%`),a.setAttribute("x2",`${l.x2}%`),a.setAttribute("y2",`${l.y2}%`),o.map((c,u)=>{var b,g,h,y;let f=(b=i==null?void 0:i[u])!=null?b:u/Math.max(1,o.length-1)*100,p=kl(c),w=Math.max(0,Math.min(1,(h=(g=s==null?void 0:s[u])!=null?g:p==null?void 0:p.opacity)!=null?h:1));return {color:(y=p==null?void 0:p.color)!=null?y:c,offset:Math.max(0,Math.min(100,f)),opacity:w}}).sort((c,u)=>c.offset-u.offset).forEach(c=>{let u=document.createElementNS("http://www.w3.org/2000/svg","stop");u.setAttribute("offset",`${c.offset}%`),u.setAttribute("stop-color",c.color),c.opacity<1&&u.setAttribute("stop-opacity",String(c.opacity)),a.append(u);}),r.append(a),e.append(r);}function Ok(e){let t=e*Math.PI/180,n=Math.sin(t),r=-Math.cos(t),o=50/Math.max(Math.abs(n),Math.abs(r),1e-4);return {x1:_i(50-n*o),y1:_i(50-r*o),x2:_i(50+n*o),y2:_i(50+r*o)}}function _i(e){return Math.round(Math.max(0,Math.min(100,e))*1e3)/1e3}function kl(e){let t=/^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})(?:\s*,\s*([0-9.]+)\s*)?\)$/i.exec(e);if(!t)return;let n=Math.max(0,Math.min(255,Number(t[1]))),r=Math.max(0,Math.min(255,Number(t[2]))),o=Math.max(0,Math.min(255,Number(t[3]))),i=t[4]===void 0?1:Math.max(0,Math.min(1,Number(t[4])));return {color:`#${dr(n)}${dr(r)}${dr(o)}`,opacity:i}}function dr(e){return Math.round(e).toString(16).padStart(2,"0").toUpperCase()}function $k(e,t,n=true){var c,u,f,p,w,b,g,h,y,k,C,N,L,F,W;let r=document.createElement("table");r.className="coco-ppt-table";let o=e.table;if(!o)return r;let i=Math.max(o.rowCount,o.values.length),s=Math.max(o.columnCount,...o.values.map(V=>V.length),1),a=(u=(c=o.columnWidths)==null?void 0:c.reduce((V,ee)=>V+ee,0))!=null?u:0;if(a>0){let V=document.createElement("colgroup");for(let ee=0;ee<s;ee++){let pe=document.createElement("col"),re=(f=o.columnWidths)==null?void 0:f[ee];re&&(pe.style.width=`${re/a*100}%`),V.append(pe);}r.append(V);}let l=(w=(p=o.rowHeights)==null?void 0:p.reduce((V,ee)=>V+ee,0))!=null?w:0;for(let V=0;V<i;V++){let ee=document.createElement("tr"),pe=(b=o.rowHeights)==null?void 0:b[V];ee.style.height=l>0&&pe?`${pe/l*100}%`:`${100/i}%`;for(let re=0;re<s;re++){let we=Uk(o,V,re);if(we!=null&&we.hMerge||we!=null&&we.vMerge)continue;let he=document.createElement("td"),xe=(h=(g=o.cellStyles)==null?void 0:g[V])==null?void 0:h[re];n&&(he.dataset.row=String(V),he.dataset.column=String(re));let Ve=(k=(y=o.values[V])==null?void 0:y[re])!=null?k:"";if(he.dataset.cellText=Ve,Vk(he,Ve),we!=null&&we.columnSpan&&we.columnSpan>1&&(he.colSpan=we.columnSpan),we!=null&&we.rowSpan&&we.rowSpan>1&&(he.rowSpan=we.rowSpan),xe!=null&&xe.fillGradient&&xe.fillGradient.colors.length>1?he.style.background=pr(xe.fillGradient):xe!=null&&xe.fillColor&&!Gk(xe.fillColor)&&(he.style.background=xe.fillColor),xe!=null&&xe.body){let z=xe.body,Z=(C=z.insetLeft)!=null?C:91440,H=(N=z.insetTop)!=null?N:45720,Y=(L=z.insetRight)!=null?L:91440,X=(F=z.insetBottom)!=null?F:45720;he.style.padding=`${H*t}px ${Y*t}px ${X*t}px ${Z*t}px`,z.anchor==="middle"&&(he.style.verticalAlign="middle"),z.anchor==="bottom"&&(he.style.verticalAlign="bottom"),z.anchor==="top"&&(he.style.verticalAlign="top");}xe!=null&&xe.textStyle&&xl(he,xe.textStyle,t),(W=xe==null?void 0:xe.textStyle)!=null&&W.alignment&&vl(he,xe.textStyle.alignment),zk(he,xe,t),ee.append(he);}r.append(ee);}return r}function zk(e,t,n){let r=t==null?void 0:t.borders;r&&(qi(e,"Left",r.left,n),qi(e,"Right",r.right,n),qi(e,"Top",r.top,n),qi(e,"Bottom",r.bottom,n));}function qi(e,t,n,r){var a,l;if(!n)return;let o=`border${t}Style`,i=`border${t}Width`,s=`border${t}Color`;if(n.hidden){e.style[o]="none",e.style[i]="0";return}e.style[o]=Sl(n.dash),e.style[i]=`${Math.max(1,((a=n.width)!=null?a:9525)*r)}px`,e.style[s]=cr((l=n.color)!=null?l:"#94A3B8",n.opacity);}function Vk(e,t){let n=t.split(/\r?\n/);if(n.length<=1){e.textContent=t;return}n.forEach((r,o)=>{o>0&&e.append(document.createElement("br"));let i=document.createElement("span");i.textContent=r,o>0&&(i.className="coco-ppt-table-cell-secondary-line",i.style.fontSize="0.7em",i.style.fontWeight="400"),e.append(i);});}function fm(e,t,n,r){var o,i,s,a,l;return (l=(a=(s=e.dataset.cellText)!=null?s:(i=(o=t.table)==null?void 0:o.values[n])==null?void 0:i[r])!=null?a:e.textContent)!=null?l:""}function Gk(e){let t=/^#?([0-9a-f]{6})$/i.exec(e);if(!t)return false;let n=t[1],r=Number.parseInt(n.slice(0,2),16),o=Number.parseInt(n.slice(2,4),16),i=Number.parseInt(n.slice(4,6),16);return (.2126*r+.7152*o+.0722*i)/255>.9}function Lm(e,t){var a,l,c;let n=((a=e.distance)!=null?a:0)*t,r=((l=e.direction)!=null?l:0)*Math.PI/180,o=Math.cos(r)*n,i=Math.sin(r)*n,s=((c=e.blur)!=null?c:0)*t;return `${o}px ${i}px ${s}px ${jk(e)}`}function jk(e){var l,c;let t=(l=e.color)!=null?l:"#000000",n=(c=e.opacity)!=null?c:.25,r=/^#?([0-9a-f]{6})$/i.exec(t);if(!r)return t;let o=r[1],i=Number.parseInt(o.slice(0,2),16),s=Number.parseInt(o.slice(2,4),16),a=Number.parseInt(o.slice(4,6),16);return `rgba(${i}, ${s}, ${a}, ${Math.max(0,Math.min(1,n))})`}function Uk(e,t,n){var r;return (r=e.mergedCells)==null?void 0:r.find(o=>o.row===t&&o.column===n)}function Kk(e){var h,y,k,C,N,L,F,W,V,ee,pe,re,we,he,xe,Ve;let t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("viewBox","0 0 100 60"),t.setAttribute("width","100%"),t.setAttribute("height","100%"),t.setAttribute("preserveAspectRatio","none");let n=(h=e.chart)==null?void 0:h.data;if(!(n!=null&&n.series.length))return bt(t,(y=e.name)!=null?y:"Chart",4,8,4,"#17202a"),t;let r=(C=(k=e.chart)==null?void 0:k.type)!=null?C:"",o=(N=e.chart)==null?void 0:N.grouping,i=_k(n.series,r,o),s=Math.max(...i,1),a=Math.min(...i,0),l=(F=(L=e.chart)==null?void 0:L.axes)==null?void 0:F.value,c=(V=(W=e.chart)==null?void 0:W.axes)==null?void 0:V.category,u=(ee=l==null?void 0:l.min)!=null?ee:a>=0?0:a,f=(pe=l==null?void 0:l.max)!=null?pe:a>=0?Yk(s):s,p=qk(e),w=Zk(u,f,l==null?void 0:l.majorUnit);if(r.includes("doughnut")||r.includes("pie"))return dE(t,n.series,p),t;if(r.includes("radar"))return fE(t,n.series,p,(re=l==null?void 0:l.max)!=null?re:s),t;(l==null?void 0:l.majorGridlines)!==false&&eE(t,p,w,e,l,c),(l==null?void 0:l.deleted)!==true&&(l==null?void 0:l.tickLabelPosition)!=="none"&&tE(t,p,u,f,w),Jk(t,e,p);let b=n.series.filter(z=>{var Z,H,Y;return ((Y=(H=z.type)!=null?H:(Z=e.chart)==null?void 0:Z.type)!=null?Y:"").includes("bar")}),g=n.series.filter(z=>{var Z;return ((Z=z.type)!=null?Z:"").includes("line")});return b.length>0?(oE(t,b,p,u,f,e,o),gm(t,(he=(we=b[0])==null?void 0:we.categories)!=null?he:[],p),b.some(z=>z.showValueLabels)&&lE(t,b,p,u,f),g.length>0&&mm(t,g,p,u,f,void 0,e),g.some(z=>z.showValueLabels)&&bm(t,g,p,u,f)):(mm(t,n.series,p,u,f,["#22C7F2","#22C7F2","#94A3B8","#F59E0B"],e),gm(t,(Ve=(xe=n.series.find(z=>{var Z;return (Z=z.categories)==null?void 0:Z.length}))==null?void 0:xe.categories)!=null?Ve:[],p),n.series.some(z=>z.showValueLabels)&&bm(t,n.series,p,u,f)),t}function _k(e,t,n){var s;let r=e.filter(a=>{var l;return ((l=a.type)!=null?l:t).includes("bar")});if(!Bm(n)||r.length<=1)return e.flatMap(a=>a.values);let o=Math.max(...r.map(a=>a.values.length),1),i=[];for(let a=0;a<o;a++){let l=0,c=0;for(let u of r){let f=(s=u.values[a])!=null?s:0;f>=0?l+=f:c+=f;}i.push(l,c);}return i}function qk(e){var u,f,p,w,b,g,h,y,k,C,N,L,F,W,V,ee;let t=(u=e.chart)==null?void 0:u.plotLayout,n=(p=(f=e.chart)==null?void 0:f.type)!=null?p:"";if(!t)return Dm((g=(b=(w=e.chart)==null?void 0:w.data)==null?void 0:b.series)!=null?g:[])?{left:7,top:8,width:88,height:40}:Xk(e)?{left:18,top:8,width:72,height:40}:((k=(y=(h=e.chart)==null?void 0:h.axes)==null?void 0:y.value)==null?void 0:k.deleted)===true?{left:6,top:8,width:90,height:40}:{left:18,top:8,width:76,height:40};let o=((L=(N=(C=e.chart)==null?void 0:C.axes)==null?void 0:N.value)==null?void 0:L.deleted)!==true&&!n.includes("doughnut")&&!n.includes("pie")&&!n.includes("radar")?14:4,i=((F=t.x)!=null?F:.12)*100,s=((W=t.y)!=null?W:.13)*60,a=((V=t.width)!=null?V:.82)*100,l=((ee=t.height)!=null?ee:.67)*60,c=Math.max(o,Math.min(20,i));return {left:c,top:Math.max(3,Math.min(12,s)),width:Math.max(40,Math.min(92,Math.min(a,96-c))),height:Math.max(24,Math.min(50,l))}}function Xk(e){var i,s,a,l,c,u,f,p;let t=e.chart,n=(i=t==null?void 0:t.type)!=null?i:"";if(!t||!n.includes("bar")||t.plotLayout)return false;let r=(a=(s=t.data)==null?void 0:s.series)!=null?a:[];if(r.length!==1)return false;let o=Math.max((u=(c=(l=r[0])==null?void 0:l.categories)==null?void 0:c.length)!=null?u:0,(p=(f=r[0])==null?void 0:f.values.length)!=null?p:0);return o>0&&o<=2}function Yk(e){if(e<=0)return 1;if(e<=10)return Math.max(1,Math.ceil(e));let t=e*1.1,n=10**Math.floor(Math.log10(t));return Math.ceil(t/n)*n}function Zk(e,t,n){let r=Math.abs(t-e);return n&&n>0?Math.max(1,Math.min(8,Math.round(r/n))):Number.isInteger(r)&&r>0&&r<=6?r:4}function Jk(e,t,n){var c,u,f,p,w,b,g;let r=(p=(c=t.chart)==null?void 0:c.title)!=null?p:(f=(u=t.chart)==null?void 0:u.data)==null?void 0:f.title;r&&bt(e,r,n.left+n.width*.5,Math.max(4,n.top-3.2),3.1,"#17202A","middle");let o=(g=(b=(w=t.chart)==null?void 0:w.data)==null?void 0:b.series)!=null?g:[],i=o.map(h=>h.name).filter(h=>!!h).slice(0,4);if(i.length===0)return;let s=["#C50D13","#0EA5E9","#F59E0B","#A3E635"],a=n.left+n.width*.78,l=Math.max(4,n.top-2.4);i.forEach((h,y)=>{var N,L,F,W,V,ee;let k=(N=o.find(pe=>pe.name===h))!=null?N:o[y],C=k?Qk(e,k,y,s):s[y];k&&((L=k.type)!=null?L:"").includes("line")?(fr(e,a,l-1.1,a+2.3,l-1.1,C,.45),vn(e,a+1.15,l-1.1,.45,(W=(F=k.marker)==null?void 0:F.fillColor)!=null?W:"#FFFFFF",(ee=(V=k.marker)==null?void 0:V.lineColor)!=null?ee:C,.32),bt(e,h,a+2.8,l-.45,2.2,"#64748B")):(mo(e,a,l-1.8,1.4,1.4,C),bt(e,h,a+2,l-.45,2.2,"#64748B")),a+=Math.max(9,Array.from(h).length*2.2+4.5);});}function Qk(e,t,n,r){var o,i;return ((o=t.type)!=null?o:"").includes("line")?(i=t.lineColor)!=null?i:r[n]:na(e,t,n,r)}function eE(e,t,n,r,o,i){var l,c;let s=(l=o==null?void 0:o.gridlineColor)!=null?l:"#E8EDF3",a=hm(o==null?void 0:o.gridlineWidth,r,.35);for(let u=0;u<=n;u++){let f=t.top+t.height/n*u;fr(e,t.left,f,t.left+t.width,f,s,a);}fr(e,t.left,t.top+t.height,t.left+t.width,t.top+t.height,(c=i==null?void 0:i.lineColor)!=null?c:"#CBD5E1",hm(i==null?void 0:i.lineWidth,r,.45));}function tE(e,t,n,r,o){for(let i=0;i<=o;i++){let s=r-(r-n)/o*i,a=t.top+t.height/o*i+1;bt(e,El(s),t.left-1.8,a,3,"#9AA6B2","end");}}function El(e){return Number.isInteger(e)?String(e):e.toFixed(1).replace(/\.0$/,"")}function mm(e,t,n,r,o,i=["#CBD5E1","#94A3B8","#F59E0B","#A3E635"],s){t.forEach((a,l)=>{var p,w,b,g,h,y,k;if(a.values.length===0)return;let c=a.values.map((C,N)=>{let L=n.left+(a.values.length===1?n.width/2:n.width*N/(a.values.length-1)),F=n.top+n.height-(C-r)/Math.max(1,o-r)*n.height;return {x:L,y:F}}),u=rE(c,a.smooth===true),f=(p=a.lineColor)!=null?p:i[l%i.length];if(Om(e,u,f,Wm(a,s)),((w=a.marker)==null?void 0:w.symbol)!=="none"){let C=Math.max(.5,Math.min(1.6,((g=(b=a.marker)==null?void 0:b.size)!=null?g:5)*.18)),N=(y=(h=a.marker)==null?void 0:h.fillColor)!=null?y:f,L=(k=a.marker)==null?void 0:k.lineColor,F=nE(a,s);c.forEach(W=>vn(e,W.x,W.y,C,N,L,F));}});}function nE(e,t){var n;if(!(!((n=e.marker)!=null&&n.lineWidth)||!(t!=null&&t.bounds.width)))return Math.max(.25,Math.min(1,e.marker.lineWidth/t.bounds.width*100))}function Wm(e,t){return !e.lineWidth||!(t!=null&&t.bounds.width)?.8:Math.max(.3,Math.min(1.2,e.lineWidth/t.bounds.width*100))}function rE(e,t){if(e.length===0)return "";if(!t||e.length<3)return e.map((r,o)=>`${o===0?"M":"L"} ${r.x} ${r.y}`).join(" ");let n=[`M ${e[0].x} ${e[0].y}`];for(let r=0;r<e.length-1;r++){let o=e[Math.max(0,r-1)],i=e[r],s=e[r+1],a=e[Math.min(e.length-1,r+2)],l={x:i.x+(s.x-o.x)/6,y:i.y+(s.y-o.y)/6},c={x:s.x-(a.x-i.x)/6,y:s.y-(a.y-i.y)/6};n.push(`C ${l.x} ${l.y} ${c.x} ${c.y} ${s.x} ${s.y}`);}return n.join(" ")}function oE(e,t,n,r,o,i,s){if(Bm(s)&&t.length>1){aE(e,t,n,r,o,i);return}if(Dm(t)){iE(e,t,n,r,o,i);return}let a=["#C50D13","#0EA5E9","#F59E0B","#A3E635"],l=Math.max(...t.map(f=>f.values.length),1),c=n.width/l,u=Math.max(1,c*.48/Math.max(t.length,1));t.forEach((f,p)=>{let w=na(e,f,p,a);f.values.forEach((b,g)=>{var C,N;let h=(b-r)/Math.max(1,o-r)*n.height,y=n.left+g*c+(c-u*t.length)/2+p*u,k=n.top+n.height-h;mo(e,y,k,u,h,(N=(C=f.pointColors)==null?void 0:C[g])!=null?N:w,f.borderColor,Cl(f,i));});});}function iE(e,t,n,r,o,i){let s=["#C50D13","#0EA5E9","#F59E0B","#A3E635"],a=Math.max(...t.map(u=>u.values.length),1),l=n.width/a,c=Math.max(1,l*.34);t.forEach((u,f)=>{let p=na(e,u,f,s);u.values.forEach((w,b)=>{var k,C;let g=Qi(w,n,r,o),h=Qi(0,n,r,o),y=n.left+b*l+(l-c)/2;mo(e,y,Math.min(g,h),c,Math.max(.1,Math.abs(h-g)),(C=(k=u.pointColors)==null?void 0:k[b])!=null?C:p,u.borderColor,Cl(u,i));});});}function aE(e,t,n,r,o,i){let s=["#C50D13","#0EA5E9","#F59E0B","#A3E635"],a=Math.max(...t.map(p=>p.values.length),1),l=n.width/a,c=Math.max(1,l*.46),u=new Array(a).fill(Math.max(0,r)),f=new Array(a).fill(Math.min(0,o));t.forEach((p,w)=>{let b=na(e,p,w,s);p.values.forEach((g,h)=>{var F,W;let y=g>=0?u[h]:f[h],k=y+g,C=Qi(y,n,r,o),N=Qi(k,n,r,o),L=n.left+h*l+(l-c)/2;mo(e,L,Math.min(C,N),c,Math.max(.1,Math.abs(N-C)),(W=(F=p.pointColors)==null?void 0:F[h])!=null?W:b,p.borderColor,Cl(p,i)),g>=0?u[h]=k:f[h]=k;});});}function Qi(e,t,n,r){return t.top+t.height-(e-n)/Math.max(1,r-n)*t.height}function Bm(e){return e==="stacked"||e==="percentStacked"}function Dm(e){return new Set(e.map(n=>{var r;return (r=n.chartGroup)!=null?r:0})).size>1&&e.every(n=>!n.type||n.type.includes("bar"))}function Cl(e,t){if(e.borderWidth)return Fm(t!=null&&t.bounds.width?e.borderWidth/t.bounds.width*100:void 0,void 0)}function hm(e,t,n){var r;return (r=Fm(e!==void 0&&t.bounds.width?e/t.bounds.width*100:void 0,n))!=null?r:n}function Fm(e,t){return e===void 0?t:Math.max(.15,Math.min(1.4,e))}function na(e,t,n,r){var o,i;if((o=t.fillGradient)!=null&&o.colors.length&&t.fillGradient.colors.length>1){let s=`coco-chart-gradient-${n}-${t.fillGradient.colors.join("-").replace(/[^a-zA-Z0-9_-]/g,"_")}`;return On(e,s,t.fillGradient),`url(#${s})`}return (i=t.fillColor)!=null?i:r[n%r.length]}function sE(e,t,n){var r,o,i;return (i=(o=(r=e.pointColors)==null?void 0:r[t])!=null?o:e.fillColor)!=null?i:n[t%n.length]}function gm(e,t,n){if(t.length===0)return;let r=n.width/t.length;t.forEach((o,i)=>{bt(e,o,n.left+r*i+r/2,n.top+n.height+5.2,3.2,"#64748B","middle");});}function lE(e,t,n,r,o){let i=Math.max(...t.map(l=>l.values.length),1),s=n.width/i,a=Math.max(1,s*.48/Math.max(t.length,1));t.forEach((l,c)=>{l.showValueLabels&&l.values.forEach((u,f)=>{let p=(u-r)/Math.max(1,o-r)*n.height,w=n.left+f*s+(s-a*t.length)/2+c*a+a/2,b=n.top+n.height-p-2;bt(e,String(u),w,b,3,"#A7AEB8","middle");});});}function bm(e,t,n,r,o){t.forEach(i=>{!i.showValueLabels||i.values.length===0||i.values.forEach((s,a)=>{let l=n.left+(i.values.length===1?n.width/2:n.width*a/(i.values.length-1)),c=n.top+n.height-(s-r)/Math.max(1,o-r)*n.height;bt(e,String(s),l,Math.max(n.top+2,c-2.2),2.6,"#374151","middle");});});}function dE(e,t,n){var w;let r=t[0];if(!(r!=null&&r.values.length))return;let o=["#1D4ED8","#E3B363","#60A5FA","#94A3B8","#F59E0B","#22C7F2"],i=r.values.reduce((b,g)=>b+Math.max(0,g),0)||1,s=n.left+n.width*.42,a=n.top+n.height*.5,l=Math.min(n.width,n.height)*.34,c=l*.58,u=-90;r.values.forEach((b,g)=>{let h=Math.max(0,b)/i*360,y=u,k=u+h;if(mE(e,s,a,l,c,y,k,sE(r,g,o)),r.showCategoryNameLabels||r.showPercentLabels||r.showValueLabels){let C=cE(r,b,g,i);if(C.length>0){let N=uE(r,g,s,a,l+3.6,n,(y+k)/2);wE(e,C,N.x,N.y,1.9,"#334155",N.x>=s?"start":"end");}}u+=h;}),vn(e,s,a,c*.92,"#FFFFFF");let f=pE(r.name);f&&bt(e,f,s,a-1.8,1.8,"#64748B","middle");let p=r.values[0];p!==void 0&&bt(e,Hm(p,i),s,a+3.4,3.9,"#1E3A8A","middle"),hE(e,(w=r.categories)!=null?w:[],o,n.left+n.width*.72,n.top+9);}function cE(e,t,n,r){var s;let o=[],i=(s=e.categories)==null?void 0:s[n];return e.showCategoryNameLabels&&i&&o.push(i),e.showValueLabels&&o.push(El(t)),e.showPercentLabels&&o.push(Hm(t,r)),o}function uE(e,t,n,r,o,i,s){return sr(n,r,o,s)}function Hm(e,t){let r=(e>0&&e<=1&&t<=2?e:e/Math.max(1,t))*100;return `${Number.isInteger(r)?r.toFixed(0):r.toFixed(1)}%`}function pE(e){let t=(e!=null?e:"").trim();if(!t)return "";let n=Array.from(t);return n.length<=6?t:`${n.slice(0,5).join("")}\u2026`}function fE(e,t,n,r){var c;let o=t[0];if(!(o!=null&&o.values.length))return;let i=o.values.length,s=n.left+n.width*.48,a=n.top+n.height*.5,l=Math.min(n.width,n.height)*.35;for(let u=1;u<=4;u++)Om(e,gE(i,s,a,l*u/4),"#CBD5E1",.25);for(let u=0;u<i;u++){let f=Yi(u,i,s,a,l);fr(e,s,a,f.x,f.y,"#E2E8F0",.25);}t.forEach((u,f)=>{var b;if(!u.values.length)return;let p=u.values.slice(0,i).map((g,h)=>Yi(h,i,s,a,Math.max(0,g)/Math.max(1,r)*l)),w=document.createElementNS("http://www.w3.org/2000/svg","path");w.setAttribute("d",p.map((g,h)=>`${h===0?"M":"L"} ${g.x} ${g.y}`).join(" ")+" Z"),w.setAttribute("fill",f===0?"rgba(37, 99, 235, 0.08)":"none"),w.setAttribute("stroke",(b=u.lineColor)!=null?b:"#2563EB"),w.setAttribute("stroke-width",String(Wm(u,void 0))),e.append(w),u.marker&&u.marker.symbol!=="none"&&p.forEach(g=>{var h;return vn(e,g.x,g.y,.9,(h=u.lineColor)!=null?h:"#2563EB")}),u.showValueLabels&&u.values.slice(0,i).forEach((g,h)=>{var k;let y=p[h];bt(e,El(g),y.x,y.y-1.2,2.2,(k=u.lineColor)!=null?k:"#2563EB","middle");});}),((c=o.categories)!=null?c:[]).slice(0,i).forEach((u,f)=>{let p=Yi(f,i,s,a,l+5);bt(e,u,p.x,p.y+1,2.6,"#64748B","middle");});}function mE(e,t,n,r,o,i,s,a){let c=Math.max(.01,s-i)>180?1:0,u=sr(t,n,r,i),f=sr(t,n,r,s),p=sr(t,n,o,s),w=sr(t,n,o,i),b=document.createElementNS("http://www.w3.org/2000/svg","path");b.setAttribute("d",[`M ${u.x} ${u.y}`,`A ${r} ${r} 0 ${c} 1 ${f.x} ${f.y}`,`L ${p.x} ${p.y}`,`A ${o} ${o} 0 ${c} 0 ${w.x} ${w.y}`,"Z"].join(" ")),b.setAttribute("fill",a),e.append(b);}function hE(e,t,n,r,o){t.slice(0,6).forEach((i,s)=>{mo(e,r,o+s*5,2.4,2.4,n[s%n.length]),bt(e,i,r+3.6,o+s*5+2.2,2.7,"#334155");});}function gE(e,t,n,r,o){return Array.from({length:e},(i,s)=>{let a=Yi(s,e,t,n,r);return `${s===0?"M":"L"} ${a.x} ${a.y}`}).join(" ")+(" Z")}function Yi(e,t,n,r,o){return sr(n,r,o,-90+360*e/t)}function sr(e,t,n,r){let o=r*Math.PI/180;return {x:e+Math.cos(o)*n,y:t+Math.sin(o)*n}}function fr(e,t,n,r,o,i,s,a,l){let c=document.createElementNS("http://www.w3.org/2000/svg","line");c.setAttribute("x1",String(t)),c.setAttribute("y1",String(n)),c.setAttribute("x2",String(r)),c.setAttribute("y2",String(o)),c.setAttribute("stroke",i),c.setAttribute("stroke-width",String(s)),c.setAttribute("stroke-linecap",bE(l)),a!==void 0&&c.setAttribute("stroke-opacity",String(Math.max(0,Math.min(1,a)))),e.append(c);}function bE(e){return e==="rnd"?"round":e==="sq"?"square":"butt"}function Om(e,t,n,r){let o=document.createElementNS("http://www.w3.org/2000/svg","path");o.setAttribute("d",t),o.setAttribute("fill","none"),o.setAttribute("stroke",n),o.setAttribute("stroke-width",String(r)),o.setAttribute("stroke-linejoin","round"),o.setAttribute("stroke-linecap","round"),e.append(o);}function vn(e,t,n,r,o,i,s){let a=document.createElementNS("http://www.w3.org/2000/svg","circle");a.setAttribute("cx",String(t)),a.setAttribute("cy",String(n)),a.setAttribute("r",String(r)),a.setAttribute("fill",o),i&&a.setAttribute("stroke",i),s!==void 0&&a.setAttribute("stroke-width",String(s)),e.append(a);}function Xi(e,t,n,r,o,i,s,a){let l=i/2,c=r==="right"?[[t,n],[t-o,n-l],[t-o,n+l]]:r==="left"?[[t,n],[t+o,n-l],[t+o,n+l]]:r==="down"?[[t,n],[t-l,n-o],[t+l,n-o]]:[[t,n],[t-l,n+o],[t+l,n+o]],u=document.createElementNS("http://www.w3.org/2000/svg","polygon");u.classList.add("coco-ppt-line-arrow"),u.setAttribute("points",c.map(f=>f.join(",")).join(" ")),u.setAttribute("fill",s),a!==void 0&&u.setAttribute("fill-opacity",String(Math.max(0,Math.min(1,a)))),e.append(u);}function mo(e,t,n,r,o,i,s,a){let l=document.createElementNS("http://www.w3.org/2000/svg","rect");l.setAttribute("x",String(t)),l.setAttribute("y",String(n)),l.setAttribute("width",String(r)),l.setAttribute("height",String(o)),l.setAttribute("fill",i),s&&a!==void 0&&(l.setAttribute("stroke",s),l.setAttribute("stroke-width",String(a))),e.append(l);}function bt(e,t,n,r,o,i,s="start"){let a=document.createElementNS("http://www.w3.org/2000/svg","text");a.setAttribute("x",String(n)),a.setAttribute("y",String(r)),a.setAttribute("font-size",String(o)),a.setAttribute("fill",i),a.setAttribute("text-anchor",s),a.textContent=t,e.append(a);}function wE(e,t,n,r,o,i,s="start"){t.forEach((a,l)=>{bt(e,a,n,r+l*o*1.2,o,i,s);});}
1690
+ exports.DEFAULT_PPT_SLIDE_SIZE=WS;exports.EditorReadOnlyError=dn;exports.NATIVE_BLOCK_CLIPBOARD_TYPE=si;exports.PptEditorSession=zi;exports.SPREADSHEET_COLUMN_RESIZE_MIN=IN;exports.SPREADSHEET_RESIZE_HIT_TOLERANCE=TN;exports.SPREADSHEET_ROW_RESIZE_MIN=NN;exports.SpreadsheetCanvasRenderer=Ai;exports.SpreadsheetCellEditor=Bi;exports.SpreadsheetEditorRuntime=Wi;exports.SpreadsheetLayout=ki;exports.SpreadsheetViewportManager=Ci;exports.adjacentNativeListNumbering=bc;exports.allNativeParagraphs=_e;exports.analyzeNativeTableRowPagination=Ka;exports.applyNativeWordChangesToPackage=fC;exports.applySpreadsheetAgentAction=vN;exports.applyWheelDelta=Cf;exports.applyWordOoxmlPatches=kx;exports.bodyParagraphs=_u;exports.buildPptEditorViewFromModel=sT;exports.buildPptEditorViewFromPptx=aT;exports.buildPptEditorViewFromPresentation=Uf;exports.buildPptPresentationScene=lo;exports.buildPptSceneNode=co;exports.buildPptSlideScene=BS;exports.buildSpreadsheetAutoFillPlan=lf;exports.buildSpreadsheetClipboardPayload=el;exports.buildSpreadsheetReplacePlan=hf;exports.buildSpreadsheetSheetRenderModel=no;exports.buildWordEditorView=NE;exports.buildWordEditorViewFromDocx=CE;exports.buildWordEditorViewFromFlatOpc=IE;exports.buildWordEditorViewFromPackage=Ra;exports.canDispatchNativeWordCommand=Mt;exports.clampScroll=Pv;exports.clearNativeImageSelection=Et;exports.clearSpreadsheetRange=QI;exports.cloneNativeWordBlocks=nt;exports.collectNativeParagraphs=RE;exports.colorToCss=Kn;exports.computeScrollbarState=If;exports.createColumnRangeSelection=BI;exports.createColumnSelection=Qs;exports.createNativeListNumbering=_a;exports.createNativeParaId=Pn;exports.createNativeSelectionRange=vs;exports.createNativeTextRange=Gu;exports.createNativeWordDocument=Va;exports.createRowRangeSelection=WI;exports.createRowSelection=Js;exports.createSelection=gt;exports.createWordEditingPlugin=AC;exports.cssPixelsToExcelColumnWidth=Ei;exports.currentNativeCursor=ut;exports.currentNativeSelection=ze;exports.defineNativeWordElements=lu;exports.excelColumnWidthToCssPixels=Nv;exports.expandRangeForMergedRanges=Gv;exports.expandSelectionForMergedRanges=_t;exports.extendSelection=Li;exports.findNativeParagraph=_;exports.findNativeParagraphLocation=be;exports.findNativeTableCellLocation=Qt;exports.findNativeTableLocation=Oe;exports.findPptSceneNode=uo;exports.findPptSceneSlide=rr;exports.findSpreadsheetMatches=rN;exports.formatSpreadsheetDisplayValue=hv;exports.freezeStateFromPane=Tv;exports.freezeStateFromSheet=Ii;exports.getNativeWordCommandState=Op;exports.getRenderCell=qe;exports.getWordChangeSet=LC;exports.getWordSelectionInfo=WC;exports.hitSpreadsheetResizeHandle=ll;exports.imageOffset=ai;exports.isPptShapeEditable=tT;exports.layoutNativePageAnnotationBubbles=Pw;exports.measureNativeDocumentReflowFromParagraph=ms;exports.moveSelection=DI;exports.nativeAddComment=rs;exports.nativeAddFormatRevision=jc;exports.nativeAddRevision=Ft;exports.nativeAnchorLayoutMetadata=tx;exports.nativeBlockClipboardText=Ts;exports.nativeClearRunFormat=Vc;exports.nativeClearTableCellRange=Tc;exports.nativeCopyBlockRange=es;exports.nativeCursorFromPoint=zu;exports.nativeDeleteBackward=Mr;exports.nativeDeleteComment=Oc;exports.nativeDeleteForward=Rr;exports.nativeDeleteImage=Gc;exports.nativeDeleteRange=pn;exports.nativeDeleteTable=kc;exports.nativeDeleteTextRangeAcrossParagraphs=Jo;exports.nativeDrawingWidthCss=qw;exports.nativeEditTableStructure=Ec;exports.nativeInsertImage=Rc;exports.nativeInsertPageBreak=Ac;exports.nativeInsertTable=Sc;exports.nativeInsertText=en;exports.nativeLineStrokeStyle=Kw;exports.nativeListIndent=gc;exports.nativeListType=cn;exports.nativeMergeTableCells=Cc;exports.nativeNumberingAtLevel=qa;exports.nativePageBreakAt=Zo;exports.nativeParagraphText=Te;exports.nativeRangeContainsPageBreak=Lc;exports.nativeReplaceBlockRangeAcrossParagraphs=Bc;exports.nativeReplaceRange=Ar;exports.nativeReplaceRangeWithBlocks=Dc;exports.nativeReplaceTableCellRangeContent=Mc;exports.nativeReplaceTableCellRangeText=Pc;exports.nativeReplaceTextRangeAcrossParagraphs=Fc;exports.nativeReplaceTextRangeWithParagraphs=ts;exports.nativeResolveFormatRevision=zc;exports.nativeResolveImageFormatRevision=Kc;exports.nativeResolveImageRevision=Uc;exports.nativeResolveRevision=$c;exports.nativeSelection=kt;exports.nativeSelectionFromCursor=st;exports.nativeSetHyperlink=os;exports.nativeSetImageSize=Wc;exports.nativeSetParagraphFormat=_n;exports.nativeSetParagraphList=Lr;exports.nativeSetRunFormat=ns;exports.nativeSetTableCellFormat=Ja;exports.nativeSetTableCellRangeFormat=Nc;exports.nativeSplitParagraph=is;exports.nativeSplitTableCell=Ic;exports.nativeSyncParagraphText=Wr;exports.nativeTableCellsInRange=at;exports.nativeTableSupportsStructuralEditing=Pr;exports.nativeTextRangeIsBold=XE;exports.nativeUpdateComment=Hc;exports.nextSpreadsheetMatch=oN;exports.normalizePptGeometry=so;exports.normalizeSelectionRange=We;exports.paginateNativeDocument=uu;exports.parentNativeParagraph=St;exports.parseNativeBlockClipboard=Yu;exports.parseNativeClipboardHtml=Xu;exports.parseTsv=tl;exports.planWordOoxmlPatch=vx;exports.planWordOoxmlPatches=yx;exports.pptSceneGeometryToSourceGeometry=Gf;exports.pptSceneNodeCapabilities=Vf;exports.previewSpreadsheetAgentAction=yN;exports.previousNativeParagraphId=Ga;exports.rangeAddressForMatrix=GI;exports.rangeForSpreadsheetMatch=iN;exports.rebuildNativeTableFragmentsFromParagraph=Ot;exports.reflowNativeDocumentFromParagraph=pu;exports.refreshNativeNumberingLabels=_o;exports.refreshNativePageCommentBubbles=hn;exports.renderNativeBlock=Vr;exports.renderNativeDocument=du;exports.renderNativeImage=ws;exports.renderNativeParagraph=Gr;exports.renderNativePptEditor=wT;exports.renderNativeTable=Ou;exports.renderNativeWordEditor=iI;exports.renderNormalizedDocumentHtmlPage=BE;exports.renderSpreadsheetEditor=ZN;exports.resolveNativeSectionPageNumberStarts=Dw;exports.resolveNativeTableCellBorders=ax;exports.resolveParagraphStyle=Cr;exports.resolveRunStyle=Un;exports.resolveSpreadsheetCellStyle=Ti;exports.resolveSpreadsheetRangeBorder=nf;exports.resolveTableCellStyle=Vo;exports.resolveWordOoxmlPatchTargets=Sx;exports.restoreNativeCursor=lt;exports.restoreNativeElementSelection=Vu;exports.restoreNativeTextSelection=gn;exports.rowColumnKey=yi;exports.scrollFromThumbPosition=Di;exports.searchNativeWordDocument=ks;exports.selectNativeImage=ju;exports.selectionAfterColumnDeletion=HI;exports.selectionAfterRowDeletion=FI;exports.serializeNativeBlockClipboard=Ns;exports.serializeNativeClipboardHtml=Is;exports.serializeRangeToTsv=qv;exports.setColor=FC;exports.setFontSize=DC;exports.setParagraphAlign=HC;exports.setSpreadsheetCellFormula=ZI;exports.setSpreadsheetCellValue=YI;exports.setSpreadsheetColumnWidth=tN;exports.setSpreadsheetRangeValues=JI;exports.setSpreadsheetRowHeight=eN;exports.splitNativeTableRowAtBlockBoundary=$E;exports.splitNativeTableRowAtTextOffset=zE;exports.spreadsheetFilterValues=al;exports.spreadsheetRowsForColumnFilters=wf;exports.spreadsheetRowsForFilter=bf;exports.spreadsheetSortRows=xf;exports.spreadsheetVisibleFilterValues=lN;exports.startSpreadsheetResizeDrag=Nf;exports.summarizeEditorCoverage=zg;exports.summarizeNativeCoverage=ME;exports.summarizeNativeTablePagination=OE;exports.summarizeSpreadsheetSelectionFormat=LN;exports.supportsSpreadsheetAutoFill=ol;exports.toggleBold=BC;exports.updateSpreadsheetResizeDrag=dl;exports.wordEditingPluginKey=Xr;