@coco-vexel/coco-office-editor 1.0.9 → 1.0.11

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,23 +1,23 @@
1
- 'use strict';var pack=require('@coco-vexel/coco-office/pack'),wordView=require('@coco-vexel/coco-office/word-view'),word=require('@coco-vexel/coco-office/word'),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 Gh=Object.defineProperty,jh=Object.defineProperties;var Uh=Object.getOwnPropertyDescriptors;var _o=Object.getOwnPropertySymbols;var Bd=Object.prototype.hasOwnProperty,Dd=Object.prototype.propertyIsEnumerable;var Va=(e,t,n)=>t in e?Gh(e,t,{enumerable:true,configurable:true,writable:true,value:n}):e[t]=n,v=(e,t)=>{for(var n in t||(t={}))Bd.call(t,n)&&Va(e,n,t[n]);if(_o)for(var n of _o(t))Dd.call(t,n)&&Va(e,n,t[n]);return e},H=(e,t)=>jh(e,Uh(t));var Mn=(e,t)=>{var n={};for(var r in e)Bd.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&_o)for(var r of _o(e))t.indexOf(r)<0&&Dd.call(e,r)&&(n[r]=e[r]);return n};var B=(e,t,n)=>Va(e,typeof t!="symbol"?t+"":t,n);var mn=class extends Error{constructor(n){super(`${n} editor is read-only`);B(this,"code","EDITOR_READ_ONLY");this.name="EditorReadOnlyError";}};var Fd=[{matches:/(?:楷体|kaiti|stkaiti)/i,families:["Kaiti SC","STKaiti","KaiTi","KaiTi_GB2312","DFKai-SB"],generic:"serif"},{matches:/(?:仿宋|fangsong|stfangsong)/i,families:["STFangsong","FangSong","FangSong_GB2312","Noto Serif CJK SC"],generic:"serif"},{matches:/(?:黑体|heiti|simhei|微软雅黑|microsoft yahei|pingfang)/i,families:["STHeiti","Heiti SC","PingFang SC","Microsoft YaHei","Noto Sans CJK SC"],generic:"sans-serif"},{matches:/(?:宋体|simsun|songti|stsong)/i,families:["SimSun","Songti SC","STSong","Noto Serif CJK SC"],generic:"serif"}],Kh=Fd[3];function qt(e,t=Kh){var a;let n=e.split(",").map(s=>s.trim()).filter(Boolean),r=n.join(" "),o=(a=Fd.find(s=>s.matches.test(r)))!=null?a:t;return [...[...new Set([...n,...o.families])].map(s=>`"${s.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/[\r\n\f]/g," ")}"`),...o.generic?[o.generic]:[]].join(", ")}async function Pr(e,t="\u6C49\u5B57Aa0"){var n;typeof document=="undefined"||!((n=document.fonts)!=null&&n.load)||await Promise.all([...new Set(e)].map(r=>document.fonts.load(r,t).catch(()=>[])));}var Xd="http://schemas.openxmlformats.org/officeDocument/2006/relationships",tg="http://schemas.openxmlformats.org/package/2006/relationships",xt="http://schemas.openxmlformats.org/drawingml/2006/main",Ga="http://schemas.openxmlformats.org/markup-compatibility/2006",ng="urn:schemas-microsoft-com:office:office",Ka="urn:schemas-microsoft-com:vml",rg={firstRow:true,lastRow:false,firstColumn:true,lastColumn:false,noHorizontalBand:false,noVerticalBand:true};async function wE(e){let t=await pack.fromZip(e);return qa(t,wordView.buildIndices(t))}function xE(e){let t=pack.fromFlatOpc(e);return qa(t,wordView.buildIndices(t))}async function yE(e){return qa(e._getPackage(),e._getIndices())}function qa(e,t){var g;let n=[],r=[],o=[],i=new Set,a=new Map(wordView.listTables(e,t,{scope:"all",includeNested:true,includeCellTexts:true}).map(h=>[h.tableId,h])),s=new Map;for(let[h,y]of t.tblIdx)s.set(y,h);let l=new Map,d=new Map(wordView.listDrawings(e,t,{scope:"all"}).map(h=>[h.drawingId,h])),u=new Map;for(let h of d.values()){if(!h.anchorParaId)continue;let y=(g=u.get(h.anchorParaId))!=null?g:[];y.push(h),u.set(h.anchorParaId,y);}let p=new Map;for(let[h,y]of t.drawingIdx){l.set(y,h);let S=Dg(e,t,h,d.get(h));S&&p.set(h,S);}let f=sg(e),b={indices:t,drawingIdByElement:l,drawingInfoById:d,drawingsByAnchorParaId:u,imagesByDrawingId:p,theme:f,documentDefaults:Og(e,f),numbering:$g(e),numberingCounters:new Map,defaultParagraphStyleId:_g(e),paragraphStyleFormats:Kg(e,t,f),tableStyleFormats:qg(e,f),hyperlinkByElement:fg(e)};for(let h of wordView.listStories(e,{kinds:["body"]})){let y=Qd(h.id,h.root,{context:b,attachedCommentIds:i,tableIdByElement:s,tableInfoById:a,flattenSdt:true});n.push(...y.blocks),r.push(...y.paragraphs),o.push(...y.tables);}let w=mg(e,{context:b,attachedCommentIds:i,tableIdByElement:s,tableInfoById:a});return {kind:"word",defaults:b.documentDefaults,pageLayout:og(e),sections:dg(e),headers:w.headers,footers:w.footers,blocks:n,paragraphs:r,tables:o,detachedComments:cb(t,i),detachedRevisions:[]}}function og(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=ag(r);if(o)return Yd(o)}function Yd(e){var p,f,b,w;let t=q(e,wordView.W_NS,"pgSz"),n=q(e,wordView.W_NS,"pgMar"),r=lb(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 a=t?t.getAttributeNS(wordView.W_NS,"orient"):null,s={width:o,height:i,margin:{top:n&&(p=Me(n,"top"))!=null?p:1440,right:n&&(f=Me(n,"right"))!=null?f:1440,bottom:n&&(b=Me(n,"bottom"))!=null?b:1440,left:n&&(w=Me(n,"left"))!=null?w:1440}},l=n?Me(n,"header"):void 0,d=n?Me(n,"footer"):void 0;l!==void 0&&(s.headerDistance=l),d!==void 0&&(s.footerDistance=d);let u=r?ig(r):void 0;return u&&(s.docGrid=u),a==="landscape"?s.orientation="landscape":a==="portrait"&&(s.orientation="portrait"),s}function ig(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 ag(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=q(r,wordView.W_NS,"pPr"),i=o?q(o,wordView.W_NS,"sectPr"):null;if(i)return i}}}return null}function sg(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(xt,"clrScheme")[0];if(r)for(let a of ["dk1","lt1","dk2","lt2","accent1","accent2","accent3","accent4","accent5","accent6","hlink","folHlink"]){let s=lg(r,a);s&&t.colors.set(a,s);}let o=n.getElementsByTagNameNS(xt,"fontScheme")[0];return o&&(Hd(t.fonts,q(o,xt,"majorFont"),"major"),Hd(t.fonts,q(o,xt,"minorFont"),"minor")),t}function lg(e,t){var r;let n=q(e,xt,t);if(n)for(let o=0;o<n.childNodes.length;o++){let i=n.childNodes[o];if(!i||i.nodeType!==1||i.namespaceURI!==xt)continue;let a=i,s=(r=a.getAttribute("val"))!=null?r:a.getAttribute("lastClr"),l=Rr(s);if(l)return l}}function Hd(e,t,n){if(!t)return;let r=ja(q(t,xt,"latin")),o=ja(q(t,xt,"ea"))||r,i=ja(q(t,xt,"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 ja(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 dg(e){let t=cg(e);if(t.length>0)return t;let n=wordView.listSections(e);return n.length>0?n.map(r=>{var o,i;return H(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 cg(e){let t=wordView.listStories(e,{kinds:["body"]})[0];if(!t)return [];let n=Jd(t.partPath),r=[],o,i,a=0;for(let l of Ya(t.root)){if(l.localName==="p"){let d=Xa("body",l,a++);o||(o=d),i=d;let u=Xo(l,wordView.W_NS,["pPr","sectPr"]);u&&o&&i&&(r.push(Od(r.length,o,i,u,e,n)),o=void 0);continue}if(l.localName==="tbl"){a++;continue}}let s=q(t.root,wordView.W_NS,"sectPr");return s&&o&&i&&r.push(Od(r.length,o,i,s,e,n)),r}function Od(e,t,n,r,o,i){var p;let a={sectionIndex:e,firstParaId:t,lastParaId:n,headerRefs:$d(o,r,i,"headerReference"),footerRefs:$d(o,r,i,"footerReference"),titlePage:q(r,wordView.W_NS,"titlePg")!==null},s=Yd(r);s&&(a.pageLayout=s);let l=q(r,wordView.W_NS,"pgNumType"),d=l?Me(l,"start"):void 0;d!==void 0&&(a.pageNumberStart=d);let u=(p=q(r,wordView.W_NS,"type"))==null?void 0:p.getAttributeNS(wordView.W_NS,"val");return (u==="nextPage"||u==="continuous"||u==="evenPage"||u==="oddPage"||u==="nextColumn")&&(a.type=u),a}function $d(e,t,n,r){if(!n)return [];let o=Zd(e,n);if(!o)return [];let i=[];for(let a of yt(t,wordView.W_NS,r)){let s=a.getAttributeNS(Xd,"id");if(!s)continue;let l=o.get(s);if(!l)continue;let d=a.getAttributeNS(wordView.W_NS,"type");i.push({type:d==="first"||d==="even"?d:"default",partName:ug(n,l)});}return i}function Zd(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(tg,"Relationship");for(let a=0;a<i.length;a++){let s=i[a],l=s==null?void 0:s.getAttribute("Id"),d=s==null?void 0:s.getAttribute("Target");l&&d&&o.set(l,d);}return o}function ug(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 Jd(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 fg(e){var n,r;let t=new Map;for(let o of wordView.listStories(e,{kinds:["body","header","footer"]})){let i=Jd(o.partPath),a=i?Zd(e,i):null,s=o.root.getElementsByTagNameNS(wordView.W_NS,"hyperlink");for(let l=0;l<s.length;l+=1){let d=s[l];if(!d)continue;let u=d.getAttributeNS(Xd,"id"),p=u?a==null?void 0:a.get(u):void 0,f=(n=d.getAttributeNS(wordView.W_NS,"anchor"))!=null?n:void 0,b=(r=d.getAttributeNS(wordView.W_NS,"tooltip"))!=null?r:void 0;!p&&!f||t.set(d,v(v(v({},p?{target:p}:{}),f?{anchor:f}:{}),b?{tooltip:b}:{}));}}return t}function Xa(e,t,n){var r;return ((r=t.getAttributeNS(wordView.W14_NS,"paraId"))==null?void 0:r.toUpperCase())||`${e}:p:${n}`}function Qd(e,t,n){let r=[],o=[],i=[],a=n.flattenSdt?Ya(t,n.suppressPlaceholderSdtContent===true):pg(t);for(let s=0;s<a.length;s++){let l=a[s];if(l.localName==="p"){let d=Zo(e,l,n.context,n.attachedCommentIds,Xa(e,l,s),n.suppressPlaceholderSdtContent===true);r.push(d),o.push(d);}else if(l.localName==="tbl"){let d=n.tableIdByElement.get(l),u=d?n.tableInfoById.get(d):void 0;if(!d||!u)continue;let p=ec(u,l,e,n.context,n.attachedCommentIds,n.tableIdByElement,n.tableInfoById,n.suppressPlaceholderSdtContent===true);r.push(p),i.push(p),o.push(...tc(p)),i.push(...nc(p));}}return {blocks:r,paragraphs:o,tables:i}}function pg(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 Ya(e,t=false){let n=[],r=o=>{if(o.namespaceURI===wordView.W_NS&&!(t&&Sc(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 a=o.childNodes[i];(a==null?void 0:a.nodeType)===1&&r(a);}}};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 mg(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=Qd(o.id,o.root,H(v({},t),{flattenSdt:true,suppressPlaceholderSdtContent:true})),a={kind:o.kind,partName:o.partPath,blocks:i.blocks,paragraphs:i.paragraphs,tables:i.tables};o.kind==="header"?n.push(a):r.push(a);}return {headers:n,footers:r}}function Zo(e,t,n,r,o,i=false){let a=wordView.buildParagraphInfo(e,t,"full",true,{structuralWhitespace:true}),s=a.paraId||o||"",l=Ag(t,s,n,i);for(let g of l.spans)g.kind==="comment"&&r.add(g.commentId);let d={type:"paragraph",paraId:s,story:a.story,text:l.text,flags:{hasComments:a.hasComments===true,hasRevisions:a.hasRevisions===true,hasBookmarks:a.hasBookmarks===true,hasMath:a.hasMath===true},segments:l.segments,spans:l.spans};a.styleId!==void 0&&(d.styleId=a.styleId);let u=a.styleId!==void 0?n.paragraphStyleFormats.get(a.styleId):n.defaultParagraphStyleId?n.paragraphStyleFormats.get(n.defaultParagraphStyleId):void 0,p=hg(t,n.theme),f=Mr(Xo(t,wordView.W_NS,["pPr"]),n.theme),b=Ht(Ht(Ht(n.documentDefaults.paragraph,u),p),a.format),w=Ht(b,f);return w!=null&&w.numbering&&(w.numbering=Gg(w.numbering,n),zg(w,n)),w!==void 0&&(d.format=w),a.table!==void 0&&(d.table=a.table),d}function hg(e,t){for(let n of yt(e,wordView.W_NS,"r")){let r=nn(n,t);if(r)return r}for(let n of yt(e,wordView.W_NS,"hyperlink")){let r=yt(n,wordView.W_NS,"r")[0],o=r?nn(r,t):void 0;if(o)return o}for(let n of ["ins","del","fldSimple"])for(let r of yt(e,wordView.W_NS,n)){let o=yt(r,wordView.W_NS,"r")[0],i=o?nn(o,t):void 0;if(i)return i}}function ec(e,t,n,r,o,i,a,s=false){var y,S,E,N,A;let l=Pg((y=e.cellGrid)!=null?y:[]),d=Sg(t),u=vg(t),p=e.tableStyleId?r.tableStyleFormats.get(e.tableStyleId):void 0,f=(S=kg(t))!=null?S:p==null?void 0:p.cellMargin,b=(E=Eg(t))!=null?E:p==null?void 0:p.borders,w=wg(t),g=oc(p==null?void 0:p.tableLook,xg(t)),h=0;return H(v(v(v(H(v({type:"table",tableId:e.tableId},e.tableStyleId?{tableStyleId:e.tableStyleId}:{}),{columnWidths:e.columnWidths}),w?{layout:w}:{}),g?{tableLook:g}:{}),b?{borders:b}:{}),{rows:(A=(N=e.cellGrid)==null?void 0:N.map((O,W)=>{let V=bg(d[W]);return H(v(v(v({},e.rowHeights[W]?{height:e.rowHeights[W]}:{}),V.isHeader?{isHeader:true}:{}),V.cantSplit?{cantSplit:true}:{}),{cells:O.map((ee,pe)=>{var Ce,Be,Le,Ge,et,kt,fn,ut,Rt,ht,Ze,Kt,ft,Qt,jn,gt;let oe=p?Rg(p,W,pe,(Ce=e.cellGrid)!=null?Ce:[],g):void 0,we=u[h++],me=we?gg(we,{storyId:n,tableId:e.tableId,context:r,attachedCommentIds:o,tableIdByElement:i,tableInfoById:a,suppressPlaceholderSdtContent:s}):void 0,_=me!=null&&me.paragraphs.length?me.paragraphs:ee.paragraphIds.map(pt=>r.indices.paraIdx.get(pt.toUpperCase())).filter(pt=>pt!==void 0).map(pt=>Zo(n,pt,r,o,void 0,s)),te=_.length>0?_:Tg(e.tableId,W,pe,ee.text),G={text:ee.text||((Be=me==null?void 0:me.directParagraphs.map(pt=>pt.text).join(`
2
- `))!=null?Be:""),gridSpan:ee.gridSpan,vMerge:ee.vMerge,blocks:me!=null&&me.blocks.length?me.blocks:te,paragraphs:te};if(oe!=null&&oe.paragraphFormat)for(let pt of (Le=me==null?void 0:me.directParagraphs)!=null?Le:G.paragraphs)pt.format=Ht(oe.paragraphFormat,pt.format);let $=l.get(`${W}:${pe}`);$!==void 0&&$>1&&(G.rowSpan=$),ee.width!==void 0&&(G.width=ee.width);let U=Cg(we,r.theme),X=(ut=(fn=(et=U==null?void 0:U.margin)!=null?et:(Ge=oe==null?void 0:oe.cell)==null?void 0:Ge.margin)!=null?fn:(kt=p==null?void 0:p.cell)==null?void 0:kt.margin)!=null?ut:f;X&&(G.margin=X);let ve=(Kt=(ht=U==null?void 0:U.borders)!=null?ht:(Rt=oe==null?void 0:oe.cell)==null?void 0:Rt.borders)!=null?Kt:(Ze=p==null?void 0:p.cell)==null?void 0:Ze.borders;return ve&&(G.borders=ve),((ft=p==null?void 0:p.cell)==null?void 0:ft.shading)!==void 0&&(G.shading=p.cell.shading),((Qt=oe==null?void 0:oe.cell)==null?void 0:Qt.shading)!==void 0&&(G.shading=oe.cell.shading),ee.shading!==void 0&&(G.shading=ee.shading),(U==null?void 0:U.shading)!==void 0&&(G.shading=U.shading),((jn=p==null?void 0:p.cell)==null?void 0:jn.verticalAlignment)!==void 0&&(G.verticalAlignment=p.cell.verticalAlignment),((gt=oe==null?void 0:oe.cell)==null?void 0:gt.verticalAlignment)!==void 0&&(G.verticalAlignment=oe.cell.verticalAlignment),(U==null?void 0:U.verticalAlignment)!==void 0&&(G.verticalAlignment=U.verticalAlignment),ee.verticalAlignment!==void 0&&(G.verticalAlignment=ee.verticalAlignment),(U==null?void 0:U.noWrap)!==void 0&&(G.noWrap=U.noWrap),G})})}))!=null?A:[]})}function gg(e,t){let n=[],r=[],o=[],i=Ya(e,t.suppressPlaceholderSdtContent);for(let a=0;a<i.length;a+=1){let s=i[a];if(s.localName==="p"){let p=Zo(t.storyId,s,t.context,t.attachedCommentIds,Xa(t.storyId,s,a),t.suppressPlaceholderSdtContent);n.push(p),r.push(p),o.push(p);continue}let l=t.tableIdByElement.get(s),d=l?t.tableInfoById.get(l):void 0;if(!l||!d)continue;let u=ec(d,s,t.storyId,t.context,t.attachedCommentIds,t.tableIdByElement,t.tableInfoById,t.suppressPlaceholderSdtContent);n.push(u),r.push(...tc(u));}return {blocks:n,paragraphs:r,directParagraphs:o}}function tc(e){return e.rows.flatMap(t=>t.cells.flatMap(n=>n.paragraphs))}function nc(e){return e.rows.flatMap(t=>t.cells.flatMap(n=>n.blocks.flatMap(r=>r.type==="table"?[r,...nc(r)]:[])))}function bg(e){let t={};if(!e)return t;let n=q(e,wordView.W_NS,"trPr");if(!n)return t;let r=st(q(n,wordView.W_NS,"tblHeader"));(r!==void 0?r:q(n,wordView.W_NS,"tblHeader")!==null)&&(t.isHeader=true);let o=st(q(n,wordView.W_NS,"cantSplit"));return (o!==void 0?o:q(n,wordView.W_NS,"cantSplit")!==null)&&(t.cantSplit=true),t}function wg(e){let t=q(e,wordView.W_NS,"tblPr");if(!t)return;let n={},r=q(t,wordView.W_NS,"tblW");if(r){let d=Me(r,"w"),u=Vd(r.getAttributeNS(wordView.W_NS,"type"));d!==void 0&&(n.width=d),u!==void 0&&(n.widthType=u);}let o=q(t,wordView.W_NS,"tblInd"),i=o?Me(o,"w"):void 0;i!==void 0&&(n.indent=i);let a=q(t,wordView.W_NS,"tblCellSpacing");if(a){let d=Me(a,"w"),u=Vd(a.getAttributeNS(wordView.W_NS,"type"));d!==void 0&&(n.cellSpacing=d),u!==void 0&&(n.cellSpacingType=u);}let s=q(t,wordView.W_NS,"jc"),l=s?yg(s.getAttributeNS(wordView.W_NS,"val")):void 0;return l!==void 0&&(n.alignment=l),Object.keys(n).length>0?n:void 0}function xg(e){let t=q(e,wordView.W_NS,"tblPr");if(t)return rc(t)}function rc(e){var g;let t=q(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,a=(h,y)=>{var E;let S=(E=t==null?void 0:t.getAttributeNS(wordView.W_NS,h))!=null?E:null;return S!==null?vc(S):i(y)},s=a("firstRow",32);s!==void 0&&(n.firstRow=s);let l=a("lastRow",64);l!==void 0&&(n.lastRow=l);let d=a("firstColumn",128);d!==void 0&&(n.firstColumn=d);let u=a("lastColumn",256);u!==void 0&&(n.lastColumn=u);let p=a("noHBand",512);p!==void 0&&(n.noHorizontalBand=p);let f=a("noVBand",1024);f!==void 0&&(n.noVerticalBand=f);let b=zd(q(e,wordView.W_NS,"tblStyleRowBandSize"));b!==void 0&&(n.rowBandSize=b);let w=zd(q(e,wordView.W_NS,"tblStyleColBandSize"));return w!==void 0&&(n.columnBandSize=w),Object.keys(n).length>0?n:void 0}function oc(e,t){if(!(!e&&!t))return v(v({},e!=null?e:{}),t!=null?t:{})}function zd(e){let t=e?Me(e,"val"):void 0;return t!==void 0&&t>0?t:void 0}function Vd(e){if(e==="auto"||e==="dxa"||e==="pct")return e}function yg(e){if(e==="left"||e==="center"||e==="right")return e}function vg(e){let t=[];for(let n of yt(e,wordView.W_NS,"tr"))t.push(...yt(n,wordView.W_NS,"tc"));return t}function Sg(e){return yt(e,wordView.W_NS,"tr")}function kg(e){let t=q(e,wordView.W_NS,"tblPr"),n=t?q(t,wordView.W_NS,"tblCellMar"):null;return Za(n)}function Cg(e,t){if(e)return Qa(q(e,wordView.W_NS,"tcPr"),t)}function Za(e){if(!e)return;let t={};for(let n of ["top","right","bottom","left"]){let r=q(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 Eg(e){let t=q(e,wordView.W_NS,"tblPr");return t?ic(t):void 0}function ic(e){let t=q(e,wordView.W_NS,"tblBorders");if(!t)return;let n={};for(let r of ["top","right","bottom","left","insideH","insideV"]){let o=ac(q(t,wordView.W_NS,r));o&&(n[r]=o);}return Object.keys(n).length>0?n:void 0}function Ig(e){let t=q(e,wordView.W_NS,"tcBorders");if(!t)return;let n={};for(let r of ["top","right","bottom","left"]){let o=ac(q(t,wordView.W_NS,r));o&&(n[r]=o);}return Object.keys(n).length>0?n:void 0}function Jo(e,t){var i,a,s;if(!e)return;let n=(i=Rr(e.getAttributeNS(wordView.W_NS,"fill")))!=null?i:es(t,e.getAttributeNS(wordView.W_NS,"themeFill")),r=(a=e.getAttributeNS(wordView.W_NS,"color"))!=null?a:void 0,o=(s=e.getAttributeNS(wordView.W_NS,"val"))!=null?s:void 0;return v(v(v({},n?{fill:xc(n,e.getAttributeNS(wordView.W_NS,"themeFillTint"),e.getAttributeNS(wordView.W_NS,"themeFillShade"))}:{}),r?{color:r}:{}),o?{val:o}:{})}function Ng(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 ac(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 Tg(e,t,n,r){return r.length===0?[]:r.split(`
3
- `).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 Pg(e){var r,o;let t=sc(e),n=new Map;for(let i=0;i<t.length;i++){let a=(r=t[i])!=null?r:[];for(let s=0;s<a.length;s++){let l=a[s];if(!l||l.cell.vMerge!=="restart")continue;let d=1;for(let u=i+1;u<t.length&&((o=t[u])==null?void 0:o.find(f=>f.startColumn===l.startColumn&&f.cell.vMerge==="continue"));u++)d+=1;d>1&&n.set(`${i}:${s}`,d);}}return n}function sc(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 Rg(e,t,n,r,o){var w;let i=e.conditions;if(!i)return;let a=sc(r),s=(w=a[t])==null?void 0:w[n];if(!s)return;let l=r.length,d=Math.max(0,...a.flatMap(g=>g.map(h=>h.endColumn))),u=Mg(o),p=u.rowBandSize,f=u.columnBandSize,b;return !u.noHorizontalBand&&Math.floor(t/p)%2===0?b=Ct(b,i.band1Horz):u.noHorizontalBand||(b=Ct(b,i.band2Horz)),!u.noVerticalBand&&Math.floor(s.startColumn/f)%2===0?b=Ct(b,i.band1Vert):u.noVerticalBand||(b=Ct(b,i.band2Vert)),u.firstRow&&t===0&&(b=Ct(b,i.firstRow)),u.lastRow&&t===l-1&&(b=Ct(b,i.lastRow)),u.firstColumn&&s.startColumn===0&&(b=Ct(b,i.firstCol)),u.lastColumn&&s.endColumn===d&&(b=Ct(b,i.lastCol)),u.firstRow&&u.firstColumn&&t===0&&s.startColumn===0&&(b=Ct(b,i.nwCell)),u.firstRow&&u.lastColumn&&t===0&&s.endColumn===d&&(b=Ct(b,i.neCell)),u.lastRow&&u.firstColumn&&t===l-1&&s.startColumn===0&&(b=Ct(b,i.swCell)),u.lastRow&&u.lastColumn&&t===l-1&&s.endColumn===d&&(b=Ct(b,i.seCell)),b}function Mg(e){var t,n;return H(v(v({},rg),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 Ag(e,t,n,r=false){var we,me,_,te;let o=[],i=[],a=new Map,s=new Set,l=new Set,d=0,u=null,p="",f=D=>kc(D,r),b=D=>{let G=p.length;return p+=D,{from:G,to:p.length}},w=e.childNodes;for(let D=0;D<w.length;D++){let G=w[D];if(!G||G.nodeType!==1)continue;let $=G;if($.namespaceURI!==wordView.W_NS){g("unknown",$);continue}if($.localName==="pPr")continue;if($.localName==="hyperlink"){h($);continue}let U=Kd($,"commentRangeStart");if(U!==null){a.set(U,p.length);continue}let X=Kd($,"commentRangeEnd");if(X!==null){let Be=a.get(X);if(Be!==void 0){let Le=db(n.indices,X,t,Be,p.length,p);Le&&i.push(Le),a.delete(X);}continue}if($.localName==="ins"||$.localName==="del"){let Be=$.localName==="ins"?"insert":"delete",Le=ts($,Be==="delete"?"delText":"t"),{from:Ge,to:et}=b(Le),kt=(we=$.getAttributeNS(wordView.W_NS,"id"))!=null?we:"",fn=yt($,wordView.W_NS,"r")[0],ut=fn?nn(fn,n.theme):void 0,Rt=H(v({kind:"revision",from:Ge,to:et,text:Le},ut?{format:ut}:{}),{revisionId:kt,revisionKind:Be,author:(me=$.getAttributeNS(wordView.W_NS,"author"))!=null?me:"",date:(_=$.getAttributeNS(wordView.W_NS,"date"))!=null?_:""});o.push(Rt),kt.length>0&&i.push({kind:"revision",id:`revision:${kt}`,revisionId:kt,revisionKind:Be,paraId:t,from:Ge,to:et,text:Le,author:Rt.author,date:Rt.date});continue}if($.localName==="r"&&ub($)){y($);continue}if(u&&$.localName==="r"){E($);continue}if($.localName==="fldSimple"&&S($)||$.localName==="r"&&Sb($))continue;if($.localName==="r"&&mb($)){V($);continue}let ve=$.localName==="r"?hb($):[];if(ve.length>0){for(let Be of ve)ee(Be);continue}if(pb($)){ee($);continue}let Ce=f($);if(Ce.length>0){let{from:Be,to:Le}=b(Ce),Ge={kind:"text",from:Be,to:Le,text:Ce};if($.localName==="r"){let et=nn($,n.theme);et&&(Ge.format=et);}o.push(Ge);}}O(),pe(e);for(let D of (te=n.drawingsByAnchorParaId.get(t))!=null?te:[])s.has(D.drawingId)||oe(D);return {text:p,segments:o,spans:i.sort((D,G)=>D.from-G.from||D.to-G.to||D.id.localeCompare(G.id))};function g(D,G){let{from:$,to:U}=b("\uFFFC");o.push({kind:"placeholder",from:$,to:U,placeholderKind:D,sourceTag:G.localName});}function h(D){let G=n.hyperlinkByElement.get(D);for(let $=0;$<D.childNodes.length;$+=1){let U=D.childNodes[$];if(!U||U.nodeType!==1)continue;let X=U;if(X.namespaceURI!==wordView.W_NS||X.localName!=="r")continue;let ve=f(X);if(ve.length===0)continue;let{from:Ce,to:Be}=b(ve),Le={kind:"text",from:Ce,to:Be,text:ve},Ge=nn(X,n.theme);Ge&&(Le.format=Ge),G&&(Le.hyperlink=v({},G)),o.push(Le);}}function y(D){var $;let G=nn(D,n.theme);for(let U=0;U<D.childNodes.length;U++){let X=D.childNodes[U];if(!X||X.nodeType!==1)continue;let ve=X;if(ve.namespaceURI!==wordView.W_NS)continue;if(ve.localName==="fldChar"){let et=ve.getAttributeNS(wordView.W_NS,"fldCharType");et==="begin"?(O(),u={instruction:"",cachedText:"",inResult:false,format:G}):et==="separate"&&u?u.inResult=true:et==="end"&&u&&(N(u),u=null);continue}if(u&&ve.localName==="instrText"){u.instruction+=($=ve.textContent)!=null?$:"";continue}let Ce=fb(ve);if(Ce.length===0)continue;if(u){u.inResult&&(u.cachedText+=Ce);continue}let{from:Be,to:Le}=b(Ce),Ge={kind:"text",from:Be,to:Le,text:Ce};G&&(Ge.format=G),o.push(Ge);}}function S(D){var X;let G=(X=D.getAttributeNS(wordView.W_NS,"instr"))!=null?X:"",$=_d(G);if(!$)return false;let U=f(D);return A($,G,U,nn(D,n.theme)),true}function E(D){let G=f(D);G.length>0&&(u!=null&&u.inResult)&&(u.cachedText+=G);}function N(D){let G=_d(D.instruction);if(G){A(G,D.instruction,D.cachedText,D.format);return}W(D);}function A(D,G,$,U){let{from:X,to:ve}=b("\uFFFC"),Ce={kind:"field",from:X,to:ve,fieldKind:D,instruction:G,cachedText:$};U&&(Ce.format=U),o.push(Ce);}function O(){u&&(W(u),u=null);}function W(D){if(D.cachedText.length===0)return;let{from:G,to:$}=b(D.cachedText),U={kind:"text",from:G,to:$,text:D.cachedText};D.format&&(U.format=D.format),o.push(U);}function V(D){let G=nn(D,n.theme);for(let $=0;$<D.childNodes.length;$++){let U=D.childNodes[$];if(!U||U.nodeType!==1)continue;let X=U;if(X.namespaceURI!==wordView.W_NS)continue;if(X.localName==="br"&&X.getAttributeNS(wordView.W_NS,"type")==="page"){g("pageBreak",X);continue}let ve=f(X);if(ve.length===0)continue;let{from:Ce,to:Be}=b(ve),Le={kind:"text",from:Ce,to:Be,text:ve};G&&(Le.format=G),o.push(Le);}}function ee(D){if(D.namespaceURI===wordView.W_NS&&D.localName==="pict"){if(gb(D)||bb(D,e,t,n))return;let Be=xb(D,t,d);if(!Be||l.has(D))return;l.add(D),d+=1;let{from:Le,to:Ge}=b("\uFFFC");o.push(H(v({},Be),{from:Le,to:Ge}));return}let G=n.drawingIdByElement.get(D),$=G?n.imagesByDrawingId.get(G):void 0,U=G?n.drawingInfoById.get(G):void 0;if(G&&U&&U.kind!=="picture"){s.add(G),oe(U);return}if(!G||!$){g("drawing",D);return}let{from:X,to:ve}=b("\uFFFC");s.add(G);let Ce={kind:"image",from:X,to:ve,drawingId:G,src:$.src,contentType:$.contentType};$.width!==void 0&&(Ce.width=$.width),$.height!==void 0&&(Ce.height=$.height),$.anchoringMode!==void 0&&(Ce.anchoringMode=$.anchoringMode),$.wrap!==void 0&&(Ce.wrap=$.wrap),$.position!==void 0&&(Ce.position=$.position),o.push(Ce);}function pe(D){for(let G of ["drawing","pict"]){let $=D.getElementsByTagNameNS(wordView.W_NS,G);for(let U=0;U<$.length;U++){let X=$[U];if(!X)continue;if(G==="pict"){if(l.has(X))continue;ee(X);continue}let ve=n.drawingIdByElement.get(X);!ve||s.has(ve)||ee(X);}}}function oe(D){var Be;if(D.kind==="picture"||(s.add(D.drawingId),Lg(D,n)))return;let G=D.kind==="textBox"&&(Be=D.innerText)!=null?Be:"",{from:$,to:U}=b(G.length>0?G:"\uFFFC"),X={kind:"drawing",from:$,to:U,drawingId:D.drawingId,drawingKind:D.kind};G.length>0&&(X.text=G);let ve=lc(D.extentEMU);if(ve.width!==void 0&&(X.width=ve.width),ve.height!==void 0&&(X.height=ve.height),D.anchoringMode!==void 0&&(X.anchoringMode=D.anchoringMode),D.wrap!==void 0&&(X.wrap=D.wrap),D.position!==void 0&&(X.position=D.position),D.hasBorder!==void 0&&(X.hasBorder=D.hasBorder),D.hasFill!==void 0&&(X.hasFill=D.hasFill),D.isLineOrConnector!==void 0&&(X.isLineOrConnector=D.isLineOrConnector),D.isLineOrConnector){let Le=wb(n.indices.drawingIdx.get(D.drawingId),n.theme);Le.color&&(X.strokeColor=Le.color),Le.width!==void 0&&(X.strokeWidth=Le.width);}D.innerTextAlign!==void 0&&(X.innerTextAlign=D.innerTextAlign);let Ce=Bg(D,n);Ce.length>0&&(X.paragraphs=Ce),o.push(X);}}var Gd=127e3;function Lg(e,t){var a,s,l,d;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=(s=(a=e.position)==null?void 0:a.horizontal)==null?void 0:s.posOffset,r=(d=(l=e.position)==null?void 0:l.vertical)==null?void 0:d.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?Wg(i):false}function Wg(e){var o,i;let t=[],n=0,r=e.getElementsByTagName("*");for(let a=0;a<r.length;a+=1){let s=r[a];if(!(!s||s.namespaceURI!==wordView.W_NS)){if(s.localName==="fldChar"){let l=s.getAttributeNS(wordView.W_NS,"fldCharType");if(l==="begin")t.push({instruction:""});else if(l==="end"){let d=t.pop();if(!d||!/^SET\b/i.test(d.instruction.trim()))return false;n+=1;}continue}if(s.localName==="instrText"){let l=t[t.length-1];if(!l)return false;l.instruction+=(o=s.textContent)!=null?o:"";continue}if(s.localName==="t"&&((i=s.textContent)!=null?i:"").trim().length>0&&t.length===0)return false}}return t.length===0&&n>0}function Bg(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?[Zo("body",o,t,n,r)]:[]})}function Dg(e,t,n,r){let o=wordView.getImageBytesSync(e,t,n);if(!o)return null;let i={src:`data:${o.contentType};base64,${Hg(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 a=Fg(o);return a.width!==void 0&&(i.width=a.width),a.height!==void 0&&(i.height=a.height),i}function Fg(e){return lc(e.extentEMU)}function lc(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 Hg(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+=An(t,o>>18&63),n+=An(t,o>>12&63),n+=An(t,o>>6&63),n+=An(t,o&63);}if(r<e.length){let o=e[r],i=r+1<e.length?e[r+1]:0,a=o<<16|i<<8;n+=An(t,a>>18&63),n+=An(t,a>>12&63),n+=r+1<e.length?An(t,a>>6&63):"=",n+="=";}return n}function An(e,t){return e.charAt(t)}function Og(e,t){let n={},r=Ja(e);if(!r)return n;let o=r.getElementsByTagNameNS(wordView.W_NS,"docDefaults")[0];if(!o)return n;let i=Xo(o,wordView.W_NS,["rPrDefault","rPr"]),a=i?mc(i,t):void 0;a&&(n.run=a);let s=Xo(o,wordView.W_NS,["pPrDefault","pPr"]);if(s){let l=Mr(s,t);l&&(n.paragraph=l);}return n}function Ja(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 $g(e){var a,s,l,d,u,p,f;let t=Vg(e);if(!t)return {nums:new Map};let n=new Map,r=t.getElementsByTagNameNS(wordView.W_NS,"abstractNum");for(let b=0;b<r.length;b++){let w=r[b];if(!w)continue;let g=w.getAttributeNS(wordView.W_NS,"abstractNumId");if(!g)continue;let h=new Map;for(let y of yt(w,wordView.W_NS,"lvl")){let S=(a=Me(y,"ilvl"))!=null?a:0,E=(l=(s=q(y,wordView.W_NS,"numFmt"))==null?void 0:s.getAttributeNS(wordView.W_NS,"val"))!=null?l:void 0,N=(u=(d=q(y,wordView.W_NS,"lvlText"))==null?void 0:d.getAttributeNS(wordView.W_NS,"val"))!=null?u:void 0,A=q(y,wordView.W_NS,"start"),O=A&&(p=Me(A,"val"))!=null?p:1,W=Mr(q(y,wordView.W_NS,"pPr"));h.set(S,v(v(v({ilvl:S,start:O},E?{numFmt:E}:{}),N?{lvlText:N}:{}),W?{paragraphFormat:W}:{}));}n.set(g,h);}let o=new Map,i=t.getElementsByTagNameNS(wordView.W_NS,"num");for(let b=0;b<i.length;b++){let w=i[b];if(!w)continue;let g=w.getAttributeNS(wordView.W_NS,"numId"),h=(f=q(w,wordView.W_NS,"abstractNumId"))==null?void 0:f.getAttributeNS(wordView.W_NS,"val");if(!g||!h)continue;let y=n.get(h);y&&o.set(g,y);}return {nums:o}}function zg(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 a=(i=e.indent)!=null?i:{};e.indent=v({},a),r.indent.left!==void 0&&(a.left===void 0||a.left===0)&&(e.indent.left=r.indent.left),r.indent.right!==void 0&&a.right===void 0&&(e.indent.right=r.indent.right),r.indent.firstLine!==void 0&&a.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 Vg(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 Gg(e,t){var l,d,u,p,f;let n=(l=t.numbering.nums.get(e.numId))==null?void 0:l.get(e.ilvl),r=(d=e.numFmt)!=null?d: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}:{}),a=`${i.numId}:${i.ilvl}`;if(r==="bullet")return i.label=jg(o),i;let s=((f=t.numberingCounters.get(a))!=null?f:((p=n==null?void 0:n.start)!=null?p:1)-1)+1;return t.numberingCounters.set(a,s),i.label=Ug(s,r,o),i}function jg(e){let t=e==null?void 0:e.replace(/%\d+/g,"").trim();return t&&t.length>0?t:"\u2022"}function Ug(e,t,n){let r=t==="lowerLetter"?jd(e,false):t==="upperLetter"?jd(e,true):String(e);return n?n.replace(/%\d+/g,r):`${r}.`}function jd(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 Kg(e,t,n){var i,a;let r=new Map;for(let s of e.parts.values()){if(s.contentType!=="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"||!s.xmlDom)continue;let l=s.xmlDom.getElementsByTagNameNS(wordView.W_NS,"style");for(let d=0;d<l.length;d++){let u=l[d];if(!u)continue;let p=u.getAttributeNS(wordView.W_NS,"styleId");if(!p||((i=u.getAttributeNS(wordView.W_NS,"type"))!=null?i:"paragraph")!=="paragraph")continue;let b={},w=(a=q(u,wordView.W_NS,"basedOn"))==null?void 0:a.getAttributeNS(wordView.W_NS,"val");w&&(b.basedOn=w);let g=Qg(u,n);g&&(b.format=g),r.set(p,b);}}let o=new Map;for(let s of r.keys()){let l=uc(s,r,new Set);l&&o.set(s,l);}for(let s of t.stylesIdx.values()){if(s.outlineLevel===void 0)continue;let l=o.get(s.styleId);o.set(s.styleId,Ht(l,{outlineLevel:s.outlineLevel}));}return o}function _g(e){var r;let t=Ja(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 s=i.getAttributeNS(wordView.W_NS,"styleId");if(s)return s}}function qg(e,t){var a,s;let n=new Map,r=Ja(e);if(!r)return new Map;let o=r.getElementsByTagNameNS(wordView.W_NS,"style");for(let l=0;l<o.length;l++){let d=o[l];if(!d)continue;let u=d.getAttributeNS(wordView.W_NS,"styleId");if(!u||((a=d.getAttributeNS(wordView.W_NS,"type"))!=null?a:"paragraph")!=="table")continue;let f={},b=(s=q(d,wordView.W_NS,"basedOn"))==null?void 0:s.getAttributeNS(wordView.W_NS,"val");b&&(f.basedOn=b);let w=Xg(d,t);w&&(f.format=w),n.set(u,f);}let i=new Map;for(let l of n.keys()){let d=dc(l,n,new Set);d&&i.set(l,d);}return i}function dc(e,t,n){if(n.has(e))return;n.add(e);let r=t.get(e);if(!r)return;let o=r.basedOn?dc(r.basedOn,t,n):void 0;return _a(o,r.format)}function Xg(e,t){let n=_a(cc(q(e,wordView.W_NS,"tblPr"),q(e,wordView.W_NS,"tcPr"),t),Yg(e,t)),r=Zg(e,t);return r?_a(n,{conditions:r}):n}function Yg(e,t){for(let n of yt(e,wordView.W_NS,"tblStylePr"))if(n.getAttributeNS(wordView.W_NS,"type")==="wholeTable")return cc(q(n,wordView.W_NS,"tblPr"),q(n,wordView.W_NS,"tcPr"),t)}function Zg(e,t){let n={};for(let r of yt(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=Jg(r,t);i&&(n[o]=i);}return Object.keys(n).length>0?n:void 0}function Jg(e,t){let n={},r=Qa(q(e,wordView.W_NS,"tcPr"),t);r&&(n.cell=r);let o=Ht(Mr(q(e,wordView.W_NS,"pPr"),t),fc(q(e,wordView.W_NS,"rPr"),t));return o&&(n.paragraphFormat=o),Object.keys(n).length>0?n:void 0}function cc(e,t,n){let r={};if(e){let o=ic(e);o&&(r.borders=o);let i=Za(q(e,wordView.W_NS,"tblCellMar"));i&&(r.cellMargin=i);let a=rc(e);a&&(r.tableLook=a);}if(t){let o=Qa(t,n);o&&(r.cell=o);}return Object.keys(r).length>0?r:void 0}function Qa(e,t){if(!e)return;let n={},r=Za(q(e,wordView.W_NS,"tcMar"));r&&(n.margin=r);let o=Ig(e);o&&(n.borders=o);let i=Jo(q(e,wordView.W_NS,"shd"),t);i&&(n.shading=i);let a=Ng(q(e,wordView.W_NS,"vAlign"));a&&(n.verticalAlignment=a);let s=st(q(e,wordView.W_NS,"noWrap"));return (s!==void 0?s:q(e,wordView.W_NS,"noWrap")!==null)&&(n.noWrap=true),Object.keys(n).length>0?n:void 0}function _a(e,t){var r,o,i,a,s,l,d,u,p,f,b,w,g,h,y,S,E,N,A,O;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:{}),(a=t==null?void 0:t.cellMargin)!=null?a:{})),(e!=null&&e.tableLook||t!=null&&t.tableLook)&&(n.tableLook=oc(e==null?void 0:e.tableLook,t==null?void 0:t.tableLook)),(e!=null&&e.cell||t!=null&&t.cell)&&(n.cell=v(v({},(s=e==null?void 0:e.cell)!=null?s:{}),(l=t==null?void 0:t.cell)!=null?l:{}),((d=e==null?void 0:e.cell)!=null&&d.margin||(u=t==null?void 0:t.cell)!=null&&u.margin)&&(n.cell.margin=v(v({},(f=(p=e==null?void 0:e.cell)==null?void 0:p.margin)!=null?f:{}),(w=(b=t==null?void 0:t.cell)==null?void 0:b.margin)!=null?w:{})),((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({},(S=(y=e==null?void 0:e.cell)==null?void 0:y.borders)!=null?S:{}),(N=(E=t==null?void 0:t.cell)==null?void 0:E.borders)!=null?N:{}))),(e!=null&&e.paragraphFormat||t!=null&&t.paragraphFormat)&&(n.paragraphFormat=Ht(e==null?void 0:e.paragraphFormat,t==null?void 0:t.paragraphFormat)),e!=null&&e.conditions||t!=null&&t.conditions){n.conditions=v({},(A=e==null?void 0:e.conditions)!=null?A:{});for(let[W,V]of Object.entries((O=t==null?void 0:t.conditions)!=null?O:{}))n.conditions[W]=Ct(n.conditions[W],V);}return n}function Ct(e,t){var r,o,i,a,s,l,d,u,p,f,b,w,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||(a=t==null?void 0:t.cell)!=null&&a.margin)&&(n.cell.margin=v(v({},(l=(s=e==null?void 0:e.cell)==null?void 0:s.margin)!=null?l:{}),(u=(d=t==null?void 0:t.cell)==null?void 0:d.margin)!=null?u:{})),((p=e==null?void 0:e.cell)!=null&&p.borders||(f=t==null?void 0:t.cell)!=null&&f.borders)&&(n.cell.borders=v(v({},(w=(b=e==null?void 0:e.cell)==null?void 0:b.borders)!=null?w:{}),(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=Ht(e==null?void 0:e.paragraphFormat,t==null?void 0:t.paragraphFormat)),n}function uc(e,t,n){if(n.has(e))return;n.add(e);let r=t.get(e);if(!r)return;let o=r.basedOn?uc(r.basedOn,t,n):void 0;return Ht(o,r.format)}function Qg(e,t){let n=Mr(q(e,wordView.W_NS,"pPr"),t),r=fc(q(e,wordView.W_NS,"rPr"),t);return Ht(n,r)}function Mr(e,t){var o,i;let n={},r=false;if(e){let a=q(e,wordView.W_NS,"jc"),s=a==null?void 0:a.getAttributeNS(wordView.W_NS,"val");(s==="left"||s==="center"||s==="right"||s==="both"||s==="distribute")&&(n.alignment=s,r=true);let l=q(e,wordView.W_NS,"ind");if(l){let N=Me(l,"left"),A=Me(l,"right"),O=Me(l,"firstLine"),W=Me(l,"hanging"),V=O!==void 0?O:W!==void 0?-W:void 0;(N!==void 0||A!==void 0||V!==void 0)&&(n.indent={},N!==void 0&&(n.indent.left=N),A!==void 0&&(n.indent.right=A),V!==void 0&&(n.indent.firstLine=V),r=true);}let d=q(e,wordView.W_NS,"spacing");if(d){let N=Me(d,"before"),A=Me(d,"after"),O=Me(d,"line"),W=d.getAttributeNS(wordView.W_NS,"lineRule"),V=W==="auto"||W==="exact"||W==="atLeast"?W:void 0;(N!==void 0||A!==void 0||O!==void 0||V!==void 0)&&(n.spacing={},N!==void 0&&(n.spacing.before=N),A!==void 0&&(n.spacing.after=A),O!==void 0&&(n.spacing.line=O),V!==void 0&&(n.spacing.lineRule=V),r=true);}let u=eb(q(e,wordView.W_NS,"tabs"));u!==void 0&&(n.tabStops=u,r=true);let p=q(e,wordView.W_NS,"outlineLvl"),f=p?Me(p,"val"):void 0;f!==void 0&&f>=0&&f<=9&&(n.outlineLevel=f,r=true);let b=q(e,wordView.W_NS,"numPr");if(b){let N=(o=q(b,wordView.W_NS,"numId"))==null?void 0:o.getAttributeNS(wordView.W_NS,"val");N&&N!=="0"&&(n.hasNumbering=true,n.numbering={numId:N,ilvl:q(b,wordView.W_NS,"ilvl")&&(i=Me(q(b,wordView.W_NS,"ilvl"),"val"))!=null?i:0},r=true);}pc(q(e,wordView.W_NS,"rPr"),n,t,false)&&(r=true),tb(e,n)&&(r=true);let w=Jo(q(e,wordView.W_NS,"shd"),t);w&&(n.shading=w,r=true);let g=st(q(e,wordView.W_NS,"keepNext"));g!==void 0&&(n.keepNext=g,r=true);let h=st(q(e,wordView.W_NS,"keepLines"));h!==void 0&&(n.keepLines=h,r=true);let y=st(q(e,wordView.W_NS,"widowControl"));y!==void 0&&(n.widowControl=y,r=true);let S=st(q(e,wordView.W_NS,"snapToGrid"));S!==void 0&&(n.snapToGrid=S,r=true);let E=st(q(e,wordView.W_NS,"pageBreakBefore"));E!==void 0&&(n.pageBreakBefore=E,r=true),q(e,wordView.W_NS,"sectPr")&&(n.hasSectionBreak=true,r=true);}return r?n:void 0}function eb(e){if(!e)return;let t=[];for(let n of yt(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 a=n.getAttributeNS(wordView.W_NS,"leader"),s=a==="none"||a==="dot"||a==="hyphen"||a==="underscore"||a==="heavy"||a==="middleDot"?a:void 0;t.push(v({alignment:o,position:i},s?{leader:s}:{}));}return t.length>0?t:void 0}function fc(e,t){let n={};return pc(e,n,t)?n:void 0}function pc(e,t,n,r=true){if(!e)return false;let o=false,i=bc(e,n);i&&(t.fontFamily=i,o=true);let a=q(e,wordView.W_NS,"sz"),s=a?Me(a,"val"):void 0;s!==void 0&&(t.fontSize=s/2,o=true);let l=st(q(e,wordView.W_NS,"b"));if(l!==void 0&&(t.bold=l,o=true),r){let f=wc(q(e,wordView.W_NS,"color"),n);f&&(t.color=f,o=true);}let d=gc(e);d!==void 0&&(t.characterSpacing=d,o=true);let u=hc(q(e,wordView.W_NS,"highlight"));u&&(t.highlight=u,o=true);let p=Jo(q(e,wordView.W_NS,"shd"),n);return p&&(t.shading=p,o=true),o}function tb(e,t){let n=q(e,wordView.W_NS,"pBdr");if(!n)return false;let r={};for(let o of ["top","right","bottom","left","between","bar"]){let i=nb(q(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 Ht(e,t){var r,o,i,a,s,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:{}),(a=t==null?void 0:t.spacing)!=null?a:{})),(e&&"borders"in e&&e.borders||t&&"borders"in t&&t.borders)&&(n.borders=v(v({},(s=e==null?void 0:e.borders)!=null?s:{}),(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(d=>v({},d)):e&&"tabStops"in e&&e.tabStops!==void 0&&(n.tabStops=e.tabStops.map(d=>v({},d))),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 nb(e){var a;if(!e)return;let t=(a=e.getAttributeNS(wordView.W_NS,"val"))!=null?a: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 nn(e,t){let n=q(e,wordView.W_NS,"rPr");if(!n)return;let r=mc(n,t);return r&&Object.keys(r).length>0?r:void 0}function mc(e,t){let n={},r=bc(e,t);r&&(n.fontFamily=r);let o=st(q(e,wordView.W_NS,"b"));o!==void 0&&(n.bold=o);let i=st(q(e,wordView.W_NS,"i"));i!==void 0&&(n.italic=i);let a=q(e,wordView.W_NS,"u");if(a){let y=a.getAttributeNS(wordView.W_NS,"val");n.underline=y!=="none"&&y!=="0"&&y!=="false";}let s=st(q(e,wordView.W_NS,"strike"));s!==void 0&&(n.strike=s);let l=st(q(e,wordView.W_NS,"dstrike"));l!==void 0&&(n.doubleStrike=l);let d=st(q(e,wordView.W_NS,"caps"));d!==void 0&&(n.caps=d);let u=st(q(e,wordView.W_NS,"smallCaps"));u!==void 0&&(n.smallCaps=u);let p=q(e,wordView.W_NS,"sz");if(p){let y=p.getAttributeNS(wordView.W_NS,"val"),S=y!==null?Number(y):NaN;Number.isFinite(S)&&(n.fontSize=S/2);}let f=q(e,wordView.W_NS,"color");if(f){let y=wc(f,t);y&&(n.color=y);}let b=gc(e);b!==void 0&&(n.characterSpacing=b);let w=rb(q(e,wordView.W_NS,"vertAlign"));w&&(n.verticalAlign=w);let g=hc(q(e,wordView.W_NS,"highlight"));g&&(n.highlight=g);let h=Jo(q(e,wordView.W_NS,"shd"),t);return h&&(n.shading=h),Object.keys(n).length>0?n:void 0}function hc(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 gc(e){let t=q(e,wordView.W_NS,"spacing");return t?Me(t,"val"):void 0}function rb(e){let t=e==null?void 0:e.getAttributeNS(wordView.W_NS,"val");return t==="baseline"||t==="superscript"||t==="subscript"?t:void 0}function bc(e,t){let n=q(e,wordView.W_NS,"rFonts");if(!n)return;let r=n.getAttributeNS(wordView.W_NS,"eastAsia")||qo(t,n.getAttributeNS(wordView.W_NS,"eastAsiaTheme")),o=n.getAttributeNS(wordView.W_NS,"ascii")||n.getAttributeNS(wordView.W_NS,"hAnsi")||qo(t,n.getAttributeNS(wordView.W_NS,"asciiTheme"))||qo(t,n.getAttributeNS(wordView.W_NS,"hAnsiTheme"));return o&&r&&ob(o)?o===r?o:`${o}, ${r}`:r||o||n.getAttributeNS(wordView.W_NS,"cs")||qo(t,n.getAttributeNS(wordView.W_NS,"csTheme"))||void 0}function ob(e){let t=e.trim().toLowerCase();return t==="calibri"||t==="aptos"||t==="arial"}function wc(e,t){if(!e)return;let n=Rr(e.getAttributeNS(wordView.W_NS,"val")),r=n!=null?n:es(t,e.getAttributeNS(wordView.W_NS,"themeColor"));if(r)return xc(r,e.getAttributeNS(wordView.W_NS,"themeTint"),e.getAttributeNS(wordView.W_NS,"themeShade"))}function es(e,t){if(!(!e||!t))return e.colors.get(t)}function qo(e,t){if(!(!e||!t))return e.fonts.get(ib(t))}function ib(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 Rr(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 xc(e,t,n){let r=Ud(t);if(r!==void 0)return ab(e,r/255);let o=Ud(n);return o!==void 0?sb(e,o/255):e}function Ud(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 ab(e,t){return yc(e,n=>n+(255-n)*t)}function sb(e,t){return yc(e,n=>n*t)}function yc(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 st(e){if(!e)return;let t=e.getAttributeNS(wordView.W_NS,"val");return vc(t)}function vc(e){return e!=="0"&&e!=="false"&&e!=="off"}function Sc(e){if(e.namespaceURI!==wordView.W_NS||e.localName!=="sdt")return false;let t=q(e,wordView.W_NS,"sdtPr");return t?st(q(t,wordView.W_NS,"showingPlcHdr"))===true:false}function q(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 lb(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 yt(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 Xo(e,t,n){let r=e;for(let o of n)if(r=r?q(r,t,o):null,!r)return null;return r}function db(e,t,n,r,o,i){var l,d;let a=e.commentIdx.get(t);if(!(a!=null&&a.comment))return null;let s=ts(a.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=a.comment.getAttributeNS(wordView.W_NS,"author"))!=null?l:"",date:(d=a.comment.getAttributeNS(wordView.W_NS,"date"))!=null?d:"",body:s}}function cb(e,t){var r,o;let n=[];for(let[i,a]of e.commentIdx)t.has(i)||!a.comment||n.push({id:i,author:(r=a.comment.getAttributeNS(wordView.W_NS,"author"))!=null?r:"",date:(o=a.comment.getAttributeNS(wordView.W_NS,"date"))!=null?o:"",text:ts(a.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 kc(e,t=false){let n="";function r(o){var a;if(o.nodeType!==1)return;let i=o;if(i.namespaceURI===wordView.W_NS&&!(t&&Sc(i))){if(i.localName==="t"){n+=(a=i.textContent)!=null?a:"";return}if(i.localName==="tab"||i.localName==="ptab"){n+=" ";return}if(i.localName==="br"){let s=i.getAttributeNS(wordView.W_NS,"type");(s===null||s===""||s==="textWrapping")&&(n+=`
4
- `);return}if(i.localName!=="delText"&&i.localName!=="commentReference")for(let s=0;s<i.childNodes.length;s++){let l=i.childNodes[s];l&&r(l);}}}return r(e),n}function ub(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 fb(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"?`
5
- `:""}return e.localName==="delText"||e.localName==="commentReference"||e.localName==="instrText"?"":kc(e)}function _d(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 ts(e,t){var o,i;let n=e.getElementsByTagNameNS(wordView.W_NS,t),r="";for(let a=0;a<n.length;a++)r+=(i=(o=n[a])==null?void 0:o.textContent)!=null?i:"";return r}function pb(e){return e.namespaceURI===wordView.W_NS&&(e.localName==="drawing"||e.localName==="pict")}function mb(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 hb(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 gb(e){let t=e.parentElement;for(;t&&!(t.namespaceURI===Ga&&t.localName==="Fallback");)t=t.parentElement;let n=t==null?void 0:t.parentElement;if(!n||n.namespaceURI!==Ga||n.localName!=="AlternateContent")return false;for(let r=0;r<n.childNodes.length;r+=1){let o=n.childNodes[r];if(!((o==null?void 0:o.nodeType)!==1||o.namespaceURI!==Ga||o.localName!=="Choice")&&o.getElementsByTagNameNS(wordView.W_NS,"drawing").length>0)return true}return false}function bb(e,t,n,r){var s,l;let o=e.getElementsByTagNameNS(Ka,"line")[0];if(!o||!o.hasAttributeNS(ng,"gfxdata"))return false;let i=new Set,a=t.getElementsByTagNameNS(wordView.W_NS,"drawing");for(let d=0;d<a.length;d+=1){let u=r.drawingIdByElement.get(a[d]);u&&i.add(u);}for(let d of (s=r.drawingsByAnchorParaId.get(n))!=null?s:[])i.add(d.drawingId);for(let d of i)if((l=r.drawingInfoById.get(d))!=null&&l.isLineOrConnector)return true;return false}function wb(e,t){var s;let n=e==null?void 0:e.getElementsByTagNameNS(xt,"ln")[0];if(!n)return {};let r=Number(n.getAttribute("w")),o=Number.isFinite(r)&&r>0?r/914400*96:void 0,i=q(n,xt,"solidFill"),a;if(i){let l=q(i,xt,"srgbClr"),d=q(i,xt,"schemeClr"),u=q(i,xt,"sysClr");a=Rr(l==null?void 0:l.getAttribute("val")),a!=null||(a=es(t,(s=d==null?void 0:d.getAttribute("val"))!=null?s:null)),a!=null||(a=Rr(u==null?void 0:u.getAttribute("lastClr")));}return v(v({},a?{color:`#${a}`}:{}),o!==void 0?{width:o}:{})}function xb(e,t,n){var u,p;if(e.namespaceURI!==wordView.W_NS||e.localName!=="pict")return null;let r=e.getElementsByTagNameNS(Ka,"line")[0];if(!r)return null;let o=yb(r.getAttribute("style")),i=r.getElementsByTagNameNS(Ka,"stroke")[0],a=Ua(o.get("width")),s=Ua(o.get("height")),l=vb((u=i==null?void 0:i.getAttribute("color"))!=null?u:r.getAttribute("strokecolor")),d=Ua((p=i==null?void 0:i.getAttribute("weight"))!=null?p:r.getAttribute("strokeweight"));return v(v(v(v({kind:"drawing",drawingId:`${t}:vml-line:${n+1}`,drawingKind:"shape",isLineOrConnector:true,hasBorder:true},a!==void 0?{width:a}:{}),s!==void 0?{height:s}:{}),l?{strokeColor:l}:{}),d!==void 0?{strokeWidth:d}:{})}function yb(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(),a=r.slice(o+1).trim();i&&a&&t.set(i,a);}return t}function Ua(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 vb(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 Sb(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 kb(e){let t=e.blocks.filter(o=>o.type==="paragraph"),n=Ic(e),r=Eb(e);return {topLevelBlocks:e.blocks.length,topLevelParagraphs:t.length,tableBlocks:e.tables.length,tableParagraphs:n.length,allParagraphs:r.length,topLevelImages:ns(t),tableImages:ns(n),allImages:ns(r),topLevelDrawings:rs(t),tableDrawings:rs(n),allDrawings:rs(r),pageBreaks:Tb(r)}}function kE(e,t){var i;let n=kb(e),r=t?Cb(t):[],o=Nb(r);return {editor:n,native:{blocks:(i=t==null?void 0:t.blocks.length)!=null?i:0,paragraphs:r.length,images:o,drawings:Cc(r),pageBreaks:Ec(r)},missing:{paragraphs:n.allParagraphs-r.length,images:n.allImages-o,drawings:n.allDrawings-Cc(r),pageBreaks:n.pageBreaks-Ec(r)}}}function CE(e){return [...Ar(e.blocks),...e.headers.flatMap(t=>Ar(t.blocks)),...e.footers.flatMap(t=>Ar(t.blocks))]}function Cb(e){return Ar(e.blocks)}function Ar(e){return e.flatMap(t=>t.kind==="paragraph"?[t]:t.rows.flatMap(n=>n.cells.flatMap(r=>r.vMerge==="continue"?[]:Ar(r.blocks))))}function Eb(e){return [...e.blocks.filter(n=>n.type==="paragraph"),...Ic(e)]}function Ic(e){return Ib(e.tables)}function Ib(e){return e.flatMap(t=>t.rows.flatMap(n=>n.cells.flatMap(r=>r.vMerge==="continue"?[]:r.paragraphs)))}function ns(e){return e.reduce((t,n)=>t+n.segments.filter(r=>r.kind==="image").length,0)}function rs(e){return e.reduce((t,n)=>t+n.segments.filter(r=>r.kind==="drawing").length,0)}function Nb(e){return e.reduce((t,n)=>t+n.content.filter(r=>r.kind==="image").length,0)}function Cc(e){return e.reduce((t,n)=>t+n.content.filter(r=>r.kind==="drawing").length,0)}function Tb(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 Wr(e){var o,i,a,s,l,d,u,p;let t={};if(!e)return Lr(t);Rb(e,t),e.alignment&&(t["text-align"]=Mb(e.alignment)),((o=e.indent)==null?void 0:o.left)!==void 0&&Pb(e)&&(t["margin-left"]=Et(e.indent.left)),((i=e.indent)==null?void 0:i.right)!==void 0&&(t["margin-right"]=Et(e.indent.right)),((a=e.indent)==null?void 0:a.firstLine)!==void 0&&(t["text-indent"]=Et(e.indent.firstLine)),((s=e.spacing)==null?void 0:s.before)!==void 0&&(t["margin-top"]=Et(e.spacing.before)),((l=e.spacing)==null?void 0:l.after)!==void 0&&(t["margin-bottom"]=Et(e.spacing.after));let n=Hb((d=e.spacing)==null?void 0:d.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"]=qt(e.fontFamily)),e.characterSpacing!==void 0&&(t["letter-spacing"]=Et(e.characterSpacing)),e.bold!==void 0&&(t["font-weight"]=e.bold?"700":"400");let r=(p=Nc(e.shading))!=null?p:Tc(e.highlight);return r&&(t["background-color"]=r),Bb(e,t),Lr(t)}function Pb(e){var t;return !(e.numbering&&((t=e.indent)==null?void 0:t.left)===0&&e.indent.firstLine===void 0)}function Rb(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 Yn(e){var o;let t={};if(!e)return Lr(t);e.bold!==void 0&&(t["font-weight"]=e.bold?"700":"400"),e.italic!==void 0&&(t["font-style"]=e.italic?"italic":"normal"),Lb(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"]=qt(e.fontFamily)),e.characterSpacing!==void 0&&(t["letter-spacing"]=Et(e.characterSpacing)),e.verticalAlign&&(t["vertical-align"]=Wb(e.verticalAlign),e.verticalAlign!=="baseline"&&e.fontSize===void 0&&(t["font-size"]="smaller"));let n=Zn(e.color);n&&(t.color=n);let r=(o=Tc(e.highlight))!=null?o:Nc(e.shading);return r&&(t["background-color"]=r),Lr(t)}function ti(e){var r;let t={};e.width!==void 0&&e.width>0&&(t.width=Et(e.width)),e.margin&&(e.margin.top!==void 0&&(t["padding-top"]=Et(e.margin.top)),e.margin.right!==void 0&&(t["padding-right"]=Et(e.margin.right)),e.margin.bottom!==void 0&&(t["padding-bottom"]=Et(e.margin.bottom)),e.margin.left!==void 0&&(t["padding-left"]=Et(e.margin.left)));let n=Zn((r=e.shading)==null?void 0:r.fill);return n&&(t["background-color"]=n),e.verticalAlignment&&(t["vertical-align"]=Ab(e.verticalAlignment)),e.noWrap&&(t["white-space"]="nowrap"),e.borders&&(ei(t,"top",e.borders.top),ei(t,"right",e.borders.right),ei(t,"bottom",e.borders.bottom),ei(t,"left",e.borders.left)),Lr(t)}function Zn(e){return !e||e==="auto"?null:/^[0-9a-f]{6}$/i.test(e)?`#${e}`:null}function Nc(e){return !e||e.val==="nil"||e.val==="clear"&&!e.fill?null:Zn(e.fill)}function Tc(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:Zn(e)}function Lr(e){return {declarations:e,cssText:Object.entries(e).map(([t,n])=>`${t}: ${n}`).join("; ")}}function Mb(e){return e==="both"||e==="distribute"?"justify":e}function Ab(e){return e==="center"||e==="both"?"middle":e}function Lb(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 Wb(e){return e==="superscript"?"super":e==="subscript"?"sub":"baseline"}function Bb(e,t){var r,o,i;let n=(r=e.borders)!=null?r:e.borderBottom?{bottom:e.borderBottom}:void 0;n&&(Qo(t,"top",n.top),Qo(t,"right",n.right),Qo(t,"bottom",(o=n.bottom)!=null?o:n.between),Qo(t,"left",(i=n.left)!=null?i:n.bar));}function Qo(e,t,n){let r=Db(n);r&&(e[`border-${t}`]=r,e[`padding-${t}`]=(n==null?void 0:n.space)!==void 0?`${n.space}pt`:"4pt");}function Db(e){var o;if(!e||e.val==="none"||e.val==="nil")return null;let t=(o=Zn(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 ei(e,t,n){if(!n)return;let r=Fb(n);e[`border-${t}`]=r!=null?r:"0";}function Fb(e){var o;if(e.val==="none"||e.val==="nil")return null;let t=(o=Zn(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 Hb(e,t,n){return e===void 0?null:t==="exact"||t==="atLeast"?Et(e):n!==true?String(e/240):`calc(var(--coco-word-doc-grid-line-height, 1em) * ${e/240})`}function Et(e){return `${e/20}pt`}function PE(e,t={}){var l,d;let n=jb((l=t.startBlock)!=null?l:0,0,e.blocks.length),r=Math.max(1,Math.floor((d=t.maxChars)!=null?d:12e3)),o=[],i=19,a=n;for(;a<e.blocks.length;){let u=Pc(e.blocks[a]),p=o.length>0?1:0;if(o.length>0&&i+p+u.length>r)break;o.push(u),i+=p+u.length,a+=1;}let s=o.length>0?`<article>
1
+ 'use strict';var pack=require('@coco-vexel/coco-office/pack'),wordView=require('@coco-vexel/coco-office/word-view'),word=require('@coco-vexel/coco-office/word'),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 Kh=Object.defineProperty,_h=Object.defineProperties;var qh=Object.getOwnPropertyDescriptors;var _o=Object.getOwnPropertySymbols;var Dd=Object.prototype.hasOwnProperty,Fd=Object.prototype.propertyIsEnumerable;var ja=(e,t,n)=>t in e?Kh(e,t,{enumerable:true,configurable:true,writable:true,value:n}):e[t]=n,v=(e,t)=>{for(var n in t||(t={}))Dd.call(t,n)&&ja(e,n,t[n]);if(_o)for(var n of _o(t))Fd.call(t,n)&&ja(e,n,t[n]);return e},O=(e,t)=>_h(e,qh(t));var Ln=(e,t)=>{var n={};for(var r in e)Dd.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&_o)for(var r of _o(e))t.indexOf(r)<0&&Fd.call(e,r)&&(n[r]=e[r]);return n};var D=(e,t,n)=>ja(e,typeof t!="symbol"?t+"":t,n);var mn=class extends Error{constructor(n){super(`${n} editor is read-only`);D(this,"code","EDITOR_READ_ONLY");this.name="EditorReadOnlyError";}};var Hd=[{matches:/(?:楷体|kaiti|stkaiti)/i,families:["Kaiti SC","STKaiti","KaiTi","KaiTi_GB2312","DFKai-SB"],generic:"serif"},{matches:/(?:仿宋|fangsong|stfangsong)/i,families:["STFangsong","FangSong","FangSong_GB2312","Noto Serif CJK SC"],generic:"serif"},{matches:/(?:黑体|heiti|simhei|微软雅黑|microsoft yahei|pingfang)/i,families:["STHeiti","Heiti SC","PingFang SC","Microsoft YaHei","Noto Sans CJK SC"],generic:"sans-serif"},{matches:/(?:宋体|simsun|songti|stsong)/i,families:["SimSun","Songti SC","STSong","Noto Serif CJK SC"],generic:"serif"}],Xh=Hd[3];function qt(e,t=Xh){var a;let n=e.split(",").map(s=>s.trim()).filter(Boolean),r=n.join(" "),o=(a=Hd.find(s=>s.matches.test(r)))!=null?a:t;return [...[...new Set([...n,...o.families])].map(s=>`"${s.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/[\r\n\f]/g," ")}"`),...o.generic?[o.generic]:[]].join(", ")}async function Mr(e,t="\u6C49\u5B57Aa0"){var n;typeof document=="undefined"||!((n=document.fonts)!=null&&n.load)||await Promise.all([...new Set(e)].map(r=>document.fonts.load(r,t).catch(()=>[])));}var Zd="http://schemas.openxmlformats.org/officeDocument/2006/relationships",og="http://schemas.openxmlformats.org/package/2006/relationships",xt="http://schemas.openxmlformats.org/drawingml/2006/main",Ua="http://schemas.openxmlformats.org/markup-compatibility/2006",ig="urn:schemas-microsoft-com:office:office",qa="urn:schemas-microsoft-com:vml",ag={firstRow:true,lastRow:false,firstColumn:true,lastColumn:false,noHorizontalBand:false,noVerticalBand:true};async function vE(e){let t=await pack.fromZip(e);return Ya(t,wordView.buildIndices(t))}function SE(e){let t=pack.fromFlatOpc(e);return Ya(t,wordView.buildIndices(t))}async function kE(e){return Ya(e._getPackage(),e._getIndices())}function Ya(e,t){var g;let n=[],r=[],o=[],i=new Set,a=new Map(wordView.listTables(e,t,{scope:"all",includeNested:true,includeCellTexts:true}).map(h=>[h.tableId,h])),s=new Map;for(let[h,y]of t.tblIdx)s.set(y,h);let l=new Map,d=new Map(wordView.listDrawings(e,t,{scope:"all"}).map(h=>[h.drawingId,h])),u=new Map;for(let h of d.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 S=$g(e,t,h,d.get(h));S&&f.set(h,S);}let p=cg(e),b={indices:t,drawingIdByElement:l,drawingInfoById:d,drawingsByAnchorParaId:u,imagesByDrawingId:f,theme:p,documentDefaults:Gg(e,p),numbering:jg(e),numberingCounters:new Map,defaultParagraphStyleId:Kd(e,"paragraph"),defaultTableStyleId:Kd(e,"table"),paragraphStyleFormats:Yg(e,t,p),tableStyleFormats:Zg(e,p),hyperlinkByElement:hg(e)};for(let h of wordView.listStories(e,{kinds:["body"]})){let y=tc(h.id,h.root,{context:b,attachedCommentIds:i,tableIdByElement:s,tableInfoById:a,flattenSdt:true});n.push(...y.blocks),r.push(...y.paragraphs),o.push(...y.tables);}let w=bg(e,{context:b,attachedCommentIds:i,tableIdByElement:s,tableInfoById:a});return {kind:"word",defaults:b.documentDefaults,pageLayout:sg(e),sections:fg(e),headers:w.headers,footers:w.footers,blocks:n,paragraphs:r,tables:o,detachedComments:pb(t,i),detachedRevisions:[]}}function sg(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=dg(r);if(o)return Jd(o)}function Jd(e){var f,p,b,w;let t=q(e,wordView.W_NS,"pgSz"),n=q(e,wordView.W_NS,"pgMar"),r=ub(e,wordView.W_NS,"docGrid"),o=t?Ae(t,"w"):void 0,i=t?Ae(t,"h"):void 0;if(o===void 0||i===void 0)return;let a=t?t.getAttributeNS(wordView.W_NS,"orient"):null,s={width:o,height:i,margin:{top:n&&(f=Ae(n,"top"))!=null?f:1440,right:n&&(p=Ae(n,"right"))!=null?p:1440,bottom:n&&(b=Ae(n,"bottom"))!=null?b:1440,left:n&&(w=Ae(n,"left"))!=null?w:1440}},l=n?Ae(n,"header"):void 0,d=n?Ae(n,"footer"):void 0;l!==void 0&&(s.headerDistance=l),d!==void 0&&(s.footerDistance=d);let u=r?lg(r):void 0;return u&&(s.docGrid=u),a==="landscape"?s.orientation="landscape":a==="portrait"&&(s.orientation="portrait"),s}function lg(e){let t=e.getAttributeNS(wordView.W_NS,"type"),n=t==="default"||t==="lines"||t==="linesAndChars"||t==="snapToChars"?t:void 0,r=Ae(e,"linePitch"),o=Ae(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 dg(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=q(r,wordView.W_NS,"pPr"),i=o?q(o,wordView.W_NS,"sectPr"):null;if(i)return i}}}return null}function cg(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(xt,"clrScheme")[0];if(r)for(let a of ["dk1","lt1","dk2","lt2","accent1","accent2","accent3","accent4","accent5","accent6","hlink","folHlink"]){let s=ug(r,a);s&&t.colors.set(a,s);}let o=n.getElementsByTagNameNS(xt,"fontScheme")[0];return o&&(Od(t.fonts,q(o,xt,"majorFont"),"major"),Od(t.fonts,q(o,xt,"minorFont"),"minor")),t}function ug(e,t){var r;let n=q(e,xt,t);if(n)for(let o=0;o<n.childNodes.length;o++){let i=n.childNodes[o];if(!i||i.nodeType!==1||i.namespaceURI!==xt)continue;let a=i,s=(r=a.getAttribute("val"))!=null?r:a.getAttribute("lastClr"),l=Ar(s);if(l)return l}}function Od(e,t,n){if(!t)return;let r=Ka(q(t,xt,"latin")),o=Ka(q(t,xt,"ea"))||r,i=Ka(q(t,xt,"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 Ka(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 fg(e){let t=pg(e);if(t.length>0)return t;let n=wordView.listSections(e);return n.length>0?n.map(r=>{var o,i;return O(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 pg(e){let t=wordView.listStories(e,{kinds:["body"]})[0];if(!t)return [];let n=ec(t.partPath),r=[],o,i,a=0;for(let l of Ja(t.root)){if(l.localName==="p"){let d=Za("body",l,a++);o||(o=d),i=d;let u=Xo(l,wordView.W_NS,["pPr","sectPr"]);u&&o&&i&&(r.push($d(r.length,o,i,u,e,n)),o=void 0);continue}if(l.localName==="tbl"){a++;continue}}let s=q(t.root,wordView.W_NS,"sectPr");return s&&o&&i&&r.push($d(r.length,o,i,s,e,n)),r}function $d(e,t,n,r,o,i){var f;let a={sectionIndex:e,firstParaId:t,lastParaId:n,headerRefs:zd(o,r,i,"headerReference"),footerRefs:zd(o,r,i,"footerReference"),titlePage:q(r,wordView.W_NS,"titlePg")!==null},s=Jd(r);s&&(a.pageLayout=s);let l=q(r,wordView.W_NS,"pgNumType"),d=l?Ae(l,"start"):void 0;d!==void 0&&(a.pageNumberStart=d);let u=(f=q(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")&&(a.type=u),a}function zd(e,t,n,r){if(!n)return [];let o=Qd(e,n);if(!o)return [];let i=[];for(let a of yt(t,wordView.W_NS,r)){let s=a.getAttributeNS(Zd,"id");if(!s)continue;let l=o.get(s);if(!l)continue;let d=a.getAttributeNS(wordView.W_NS,"type");i.push({type:d==="first"||d==="even"?d:"default",partName:mg(n,l)});}return i}function Qd(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(og,"Relationship");for(let a=0;a<i.length;a++){let s=i[a],l=s==null?void 0:s.getAttribute("Id"),d=s==null?void 0:s.getAttribute("Target");l&&d&&o.set(l,d);}return o}function mg(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 ec(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 hg(e){var n,r;let t=new Map;for(let o of wordView.listStories(e,{kinds:["body","header","footer"]})){let i=ec(o.partPath),a=i?Qd(e,i):null,s=o.root.getElementsByTagNameNS(wordView.W_NS,"hyperlink");for(let l=0;l<s.length;l+=1){let d=s[l];if(!d)continue;let u=d.getAttributeNS(Zd,"id"),f=u?a==null?void 0:a.get(u):void 0,p=(n=d.getAttributeNS(wordView.W_NS,"anchor"))!=null?n:void 0,b=(r=d.getAttributeNS(wordView.W_NS,"tooltip"))!=null?r:void 0;!f&&!p||t.set(d,v(v(v({},f?{target:f}:{}),p?{anchor:p}:{}),b?{tooltip:b}:{}));}}return t}function Za(e,t,n){var r;return ((r=t.getAttributeNS(wordView.W14_NS,"paraId"))==null?void 0:r.toUpperCase())||`${e}:p:${n}`}function tc(e,t,n){let r=[],o=[],i=[],a=n.flattenSdt?Ja(t,n.suppressPlaceholderSdtContent===true):gg(t);for(let s=0;s<a.length;s++){let l=a[s];if(l.localName==="p"){let d=Zo(e,l,n.context,n.attachedCommentIds,Za(e,l,s),n.suppressPlaceholderSdtContent===true);r.push(d),o.push(d);}else if(l.localName==="tbl"){let d=n.tableIdByElement.get(l),u=d?n.tableInfoById.get(d):void 0;if(!d||!u)continue;let f=nc(u,l,e,n.context,n.attachedCommentIds,n.tableIdByElement,n.tableInfoById,n.suppressPlaceholderSdtContent===true);r.push(f),i.push(f),o.push(...rc(f)),i.push(...oc(f));}}return {blocks:r,paragraphs:o,tables:i}}function gg(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 Ja(e,t=false){let n=[],r=o=>{if(o.namespaceURI===wordView.W_NS&&!(t&&Ec(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 a=o.childNodes[i];(a==null?void 0:a.nodeType)===1&&r(a);}}};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 bg(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=tc(o.id,o.root,O(v({},t),{flattenSdt:true,suppressPlaceholderSdtContent:true})),a={kind:o.kind,partName:o.partPath,blocks:i.blocks,paragraphs:i.paragraphs,tables:i.tables};o.kind==="header"?n.push(a):r.push(a);}return {headers:n,footers:r}}function Zo(e,t,n,r,o,i=false){let a=wordView.buildParagraphInfo(e,t,"full",true,{structuralWhitespace:true}),s=a.paraId||o||"",l=Dg(t,s,n,i);for(let g of l.spans)g.kind==="comment"&&r.add(g.commentId);let d={type:"paragraph",paraId:s,story:a.story,text:l.text,flags:{hasComments:a.hasComments===true,hasRevisions:a.hasRevisions===true,hasBookmarks:a.hasBookmarks===true,hasMath:a.hasMath===true},segments:l.segments,spans:l.spans};a.styleId!==void 0&&(d.styleId=a.styleId);let u=a.styleId!==void 0?n.paragraphStyleFormats.get(a.styleId):n.defaultParagraphStyleId?n.paragraphStyleFormats.get(n.defaultParagraphStyleId):void 0,f=wg(t,n.theme),p=Lr(Xo(t,wordView.W_NS,["pPr"]),n.theme),b=Ht(Ht(Ht(n.documentDefaults.paragraph,u),f),a.format),w=Ht(b,p);return w!=null&&w.numbering&&(w.numbering=_g(w.numbering,n),Ug(w,n)),w!==void 0&&(d.format=w),a.table!==void 0&&(d.table=a.table),d}function wg(e,t){for(let n of yt(e,wordView.W_NS,"r")){let r=nn(n,t);if(r)return r}for(let n of yt(e,wordView.W_NS,"hyperlink")){let r=yt(n,wordView.W_NS,"r")[0],o=r?nn(r,t):void 0;if(o)return o}for(let n of ["ins","del","fldSimple"])for(let r of yt(e,wordView.W_NS,n)){let o=yt(r,wordView.W_NS,"r")[0],i=o?nn(o,t):void 0;if(i)return i}}function nc(e,t,n,r,o,i,a,s=false){var S,k,I,A,F,L;let l=Lg((S=e.cellGrid)!=null?S:[]),d=Eg(t),u=Cg(t),f=e.tableStyleId?r.tableStyleFormats.get(e.tableStyleId):void 0,p=(k=Ig(t))!=null?k:f==null?void 0:f.cellMargin,b=(I=Pg(t))!=null?I:f==null?void 0:f.borders,w=f!=null?f:r.tableStyleFormats.get((A=r.defaultTableStyleId)!=null?A:""),g=vg(t,w==null?void 0:w.layoutMode),h=sc(f==null?void 0:f.tableLook,Sg(t)),y=0;return O(v(v(v(O(v({type:"table",tableId:e.tableId},e.tableStyleId?{tableStyleId:e.tableStyleId}:{}),{columnWidths:e.columnWidths}),g?{layout:g}:{}),h?{tableLook:h}:{}),b?{borders:b}:{}),{rows:(L=(F=e.cellGrid)==null?void 0:F.map((V,ee)=>{let fe=yg(d[ee]);return O(v(v(v({},e.rowHeights[ee]?{height:e.rowHeights[ee]}:{}),fe.isHeader?{isHeader:true}:{}),fe.cantSplit?{cantSplit:true}:{}),{cells:V.map((ae,oe)=>{var et,kt,fn,ut,Rt,mt,Ze,Kt,ft,Qt,Kn,ht,In,Nn;let ie=f?Wg(f,ee,oe,(et=e.cellGrid)!=null?et:[],h):void 0,U=u[y++],J=U?xg(U,{storyId:n,tableId:e.tableId,context:r,attachedCommentIds:o,tableIdByElement:i,tableInfoById:a,suppressPlaceholderSdtContent:s}):void 0,B=J!=null&&J.paragraphs.length?J.paragraphs:ae.paragraphIds.map(gt=>r.indices.paraIdx.get(gt.toUpperCase())).filter(gt=>gt!==void 0).map(gt=>Zo(n,gt,r,o,void 0,s)),G=B.length>0?B:Ag(e.tableId,ee,oe,ae.text),K={text:ae.text||((kt=J==null?void 0:J.directParagraphs.map(gt=>gt.text).join(`
2
+ `))!=null?kt:""),gridSpan:ae.gridSpan,vMerge:ae.vMerge,blocks:J!=null&&J.blocks.length?J.blocks:G,paragraphs:G};if(ie!=null&&ie.paragraphFormat)for(let gt of (fn=J==null?void 0:J.directParagraphs)!=null?fn:K.paragraphs)gt.format=Ht(ie.paragraphFormat,gt.format);let X=l.get(`${ee}:${oe}`);X!==void 0&&X>1&&(K.rowSpan=X),ae.width!==void 0&&(K.width=ae.width);let Se=U?q(U,wordView.W_NS,"tcPr"):null,Ce=Se&&((ut=q(Se,wordView.W_NS,"tcW"))==null?void 0:ut.getAttributeNS(wordView.W_NS,"type"));(Ce==="pct"||Ce==="auto")&&(K.widthType=Ce);let xe=Ng(U,r.theme),We=Tg((Rt=f==null?void 0:f.cell)==null?void 0:Rt.margin,(mt=ie==null?void 0:ie.cell)==null?void 0:mt.margin,p,fe.cellMargin,xe==null?void 0:xe.margin);We&&(K.margin=We);let Ge=(Qt=(Kt=xe==null?void 0:xe.borders)!=null?Kt:(Ze=ie==null?void 0:ie.cell)==null?void 0:Ze.borders)!=null?Qt:(ft=f==null?void 0:f.cell)==null?void 0:ft.borders;return Ge&&(K.borders=Ge),((Kn=f==null?void 0:f.cell)==null?void 0:Kn.shading)!==void 0&&(K.shading=f.cell.shading),((ht=ie==null?void 0:ie.cell)==null?void 0:ht.shading)!==void 0&&(K.shading=ie.cell.shading),ae.shading!==void 0&&(K.shading=ae.shading),(xe==null?void 0:xe.shading)!==void 0&&(K.shading=xe.shading),((In=f==null?void 0:f.cell)==null?void 0:In.verticalAlignment)!==void 0&&(K.verticalAlignment=f.cell.verticalAlignment),((Nn=ie==null?void 0:ie.cell)==null?void 0:Nn.verticalAlignment)!==void 0&&(K.verticalAlignment=ie.cell.verticalAlignment),(xe==null?void 0:xe.verticalAlignment)!==void 0&&(K.verticalAlignment=xe.verticalAlignment),ae.verticalAlignment!==void 0&&(K.verticalAlignment=ae.verticalAlignment),(xe==null?void 0:xe.noWrap)!==void 0&&(K.noWrap=xe.noWrap),K})})}))!=null?L:[]})}function xg(e,t){let n=[],r=[],o=[],i=Ja(e,t.suppressPlaceholderSdtContent);for(let a=0;a<i.length;a+=1){let s=i[a];if(s.localName==="p"){let f=Zo(t.storyId,s,t.context,t.attachedCommentIds,Za(t.storyId,s,a),t.suppressPlaceholderSdtContent);n.push(f),r.push(f),o.push(f);continue}let l=t.tableIdByElement.get(s),d=l?t.tableInfoById.get(l):void 0;if(!l||!d)continue;let u=nc(d,s,t.storyId,t.context,t.attachedCommentIds,t.tableIdByElement,t.tableInfoById,t.suppressPlaceholderSdtContent);n.push(u),r.push(...rc(u));}return {blocks:n,paragraphs:r,directParagraphs:o}}function rc(e){return e.rows.flatMap(t=>t.cells.flatMap(n=>n.paragraphs))}function oc(e){return e.rows.flatMap(t=>t.cells.flatMap(n=>n.blocks.flatMap(r=>r.type==="table"?[r,...oc(r)]:[])))}function yg(e){let t={};if(!e)return t;let n=q(e,wordView.W_NS,"tblPrEx"),r=n?Jo(q(n,wordView.W_NS,"tblCellMar")):void 0;r&&(t.cellMargin=r);let o=q(e,wordView.W_NS,"trPr");if(!o)return t;let i=st(q(o,wordView.W_NS,"tblHeader"));(i!==void 0?i:q(o,wordView.W_NS,"tblHeader")!==null)&&(t.isHeader=true);let a=st(q(o,wordView.W_NS,"cantSplit"));return (a!==void 0?a:q(o,wordView.W_NS,"cantSplit")!==null)&&(t.cantSplit=true),t}function ic(e){var n;let t=e&&((n=q(e,wordView.W_NS,"tblLayout"))==null?void 0:n.getAttributeNS(wordView.W_NS,"type"));return t==="autofit"||t==="fixed"?t:void 0}function vg(e,t){var f;let n=q(e,wordView.W_NS,"tblPr");if(!n)return t?{mode:t}:void 0;let r={},o=(f=ic(n))!=null?f:t;o&&(r.mode=o);let i=q(n,wordView.W_NS,"tblW");if(i){let p=Ae(i,"w"),b=Gd(i.getAttributeNS(wordView.W_NS,"type"));p!==void 0&&(r.width=p),b!==void 0&&(r.widthType=b);}let a=q(n,wordView.W_NS,"tblInd"),s=a?Ae(a,"w"):void 0;s!==void 0&&(r.indent=s);let l=q(n,wordView.W_NS,"tblCellSpacing");if(l){let p=Ae(l,"w"),b=Gd(l.getAttributeNS(wordView.W_NS,"type"));p!==void 0&&(r.cellSpacing=p),b!==void 0&&(r.cellSpacingType=b);}let d=q(n,wordView.W_NS,"jc"),u=d?kg(d.getAttributeNS(wordView.W_NS,"val")):void 0;return u!==void 0&&(r.alignment=u),Object.keys(r).length>0?r:void 0}function Sg(e){let t=q(e,wordView.W_NS,"tblPr");if(t)return ac(t)}function ac(e){var g;let t=q(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,a=(h,y)=>{var k;let S=(k=t==null?void 0:t.getAttributeNS(wordView.W_NS,h))!=null?k:null;return S!==null?Cc(S):i(y)},s=a("firstRow",32);s!==void 0&&(n.firstRow=s);let l=a("lastRow",64);l!==void 0&&(n.lastRow=l);let d=a("firstColumn",128);d!==void 0&&(n.firstColumn=d);let u=a("lastColumn",256);u!==void 0&&(n.lastColumn=u);let f=a("noHBand",512);f!==void 0&&(n.noHorizontalBand=f);let p=a("noVBand",1024);p!==void 0&&(n.noVerticalBand=p);let b=Vd(q(e,wordView.W_NS,"tblStyleRowBandSize"));b!==void 0&&(n.rowBandSize=b);let w=Vd(q(e,wordView.W_NS,"tblStyleColBandSize"));return w!==void 0&&(n.columnBandSize=w),Object.keys(n).length>0?n:void 0}function sc(e,t){if(!(!e&&!t))return v(v({},e!=null?e:{}),t!=null?t:{})}function Vd(e){let t=e?Ae(e,"val"):void 0;return t!==void 0&&t>0?t:void 0}function Gd(e){if(e==="auto"||e==="dxa"||e==="pct")return e}function kg(e){if(e==="left"||e==="center"||e==="right")return e}function Cg(e){let t=[];for(let n of yt(e,wordView.W_NS,"tr"))t.push(...yt(n,wordView.W_NS,"tc"));return t}function Eg(e){return yt(e,wordView.W_NS,"tr")}function Ig(e){let t=q(e,wordView.W_NS,"tblPr"),n=t?q(t,wordView.W_NS,"tblCellMar"):null;return Jo(n)}function Ng(e,t){if(e)return es(q(e,wordView.W_NS,"tcPr"),t)}function Jo(e){if(!e)return;let t={};for(let n of ["top","right","bottom","left"]){let r=q(e,wordView.W_NS,n),o=r?Ae(r,"w"):void 0;o!==void 0&&(t[n]=o);}return Object.keys(t).length>0?t:void 0}function Tg(...e){let t=Object.assign({},...e.filter(n=>n!==void 0));return Object.keys(t).length>0?t:void 0}function Pg(e){let t=q(e,wordView.W_NS,"tblPr");return t?lc(t):void 0}function lc(e){let t=q(e,wordView.W_NS,"tblBorders");if(!t)return;let n={};for(let r of ["top","right","bottom","left","insideH","insideV"]){let o=dc(q(t,wordView.W_NS,r));o&&(n[r]=o);}return Object.keys(n).length>0?n:void 0}function Rg(e){let t=q(e,wordView.W_NS,"tcBorders");if(!t)return;let n={};for(let r of ["top","right","bottom","left"]){let o=dc(q(t,wordView.W_NS,r));o&&(n[r]=o);}return Object.keys(n).length>0?n:void 0}function Qo(e,t){var i,a,s;if(!e)return;let n=(i=Ar(e.getAttributeNS(wordView.W_NS,"fill")))!=null?i:ts(t,e.getAttributeNS(wordView.W_NS,"themeFill")),r=(a=e.getAttributeNS(wordView.W_NS,"color"))!=null?a:void 0,o=(s=e.getAttributeNS(wordView.W_NS,"val"))!=null?s:void 0;return v(v(v({},n?{fill:Sc(n,e.getAttributeNS(wordView.W_NS,"themeFillTint"),e.getAttributeNS(wordView.W_NS,"themeFillShade"))}:{}),r?{color:r}:{}),o?{val:o}:{})}function Mg(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 dc(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=Ae(e,"sz");return v(v(v({},t?{val:t}:{}),n?{color:n}:{}),r!==void 0?{size:r}:{})}function Ag(e,t,n,r){return r.length===0?[]:r.split(`
3
+ `).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 Lg(e){var r,o;let t=cc(e),n=new Map;for(let i=0;i<t.length;i++){let a=(r=t[i])!=null?r:[];for(let s=0;s<a.length;s++){let l=a[s];if(!l||l.cell.vMerge!=="restart")continue;let d=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++)d+=1;d>1&&n.set(`${i}:${s}`,d);}}return n}function cc(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 Wg(e,t,n,r,o){var w;let i=e.conditions;if(!i)return;let a=cc(r),s=(w=a[t])==null?void 0:w[n];if(!s)return;let l=r.length,d=Math.max(0,...a.flatMap(g=>g.map(h=>h.endColumn))),u=Bg(o),f=u.rowBandSize,p=u.columnBandSize,b;return !u.noHorizontalBand&&Math.floor(t/f)%2===0?b=Ct(b,i.band1Horz):u.noHorizontalBand||(b=Ct(b,i.band2Horz)),!u.noVerticalBand&&Math.floor(s.startColumn/p)%2===0?b=Ct(b,i.band1Vert):u.noVerticalBand||(b=Ct(b,i.band2Vert)),u.firstRow&&t===0&&(b=Ct(b,i.firstRow)),u.lastRow&&t===l-1&&(b=Ct(b,i.lastRow)),u.firstColumn&&s.startColumn===0&&(b=Ct(b,i.firstCol)),u.lastColumn&&s.endColumn===d&&(b=Ct(b,i.lastCol)),u.firstRow&&u.firstColumn&&t===0&&s.startColumn===0&&(b=Ct(b,i.nwCell)),u.firstRow&&u.lastColumn&&t===0&&s.endColumn===d&&(b=Ct(b,i.neCell)),u.lastRow&&u.firstColumn&&t===l-1&&s.startColumn===0&&(b=Ct(b,i.swCell)),u.lastRow&&u.lastColumn&&t===l-1&&s.endColumn===d&&(b=Ct(b,i.seCell)),b}function Bg(e){var t,n;return O(v(v({},ag),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 Dg(e,t,n,r=false){var oe,ie,U,J;let o=[],i=[],a=new Map,s=new Set,l=new Set,d=0,u=null,f="",p=B=>Ic(B,r),b=B=>{let G=f.length;return f+=B,{from:G,to:f.length}},w=e.childNodes;for(let B=0;B<w.length;B++){let G=w[B];if(!G||G.nodeType!==1)continue;let $=G;if($.namespaceURI!==wordView.W_NS){g("unknown",$);continue}if($.localName==="pPr")continue;if($.localName==="hyperlink"){h($);continue}let K=qd($,"commentRangeStart");if(K!==null){a.set(K,f.length);continue}let X=qd($,"commentRangeEnd");if(X!==null){let xe=a.get(X);if(xe!==void 0){let We=fb(n.indices,X,t,xe,f.length,f);We&&i.push(We),a.delete(X);}continue}if($.localName==="ins"||$.localName==="del"){let xe=$.localName==="ins"?"insert":"delete",We=ns($,xe==="delete"?"delText":"t"),{from:Ge,to:et}=b(We),kt=(oe=$.getAttributeNS(wordView.W_NS,"id"))!=null?oe:"",fn=yt($,wordView.W_NS,"r")[0],ut=fn?nn(fn,n.theme):void 0,Rt=O(v({kind:"revision",from:Ge,to:et,text:We},ut?{format:ut}:{}),{revisionId:kt,revisionKind:xe,author:(ie=$.getAttributeNS(wordView.W_NS,"author"))!=null?ie:"",date:(U=$.getAttributeNS(wordView.W_NS,"date"))!=null?U:""});o.push(Rt),kt.length>0&&i.push({kind:"revision",id:`revision:${kt}`,revisionId:kt,revisionKind:xe,paraId:t,from:Ge,to:et,text:We,author:Rt.author,date:Rt.date});continue}if($.localName==="r"&&mb($)){y($);continue}if(u&&$.localName==="r"){k($);continue}if($.localName==="fldSimple"&&S($)||$.localName==="r"&&Eb($))continue;if($.localName==="r"&&bb($)){V($);continue}let Se=$.localName==="r"?wb($):[];if(Se.length>0){for(let xe of Se)ee(xe);continue}if(gb($)){ee($);continue}let Ce=p($);if(Ce.length>0){let{from:xe,to:We}=b(Ce),Ge={kind:"text",from:xe,to:We,text:Ce};if($.localName==="r"){let et=nn($,n.theme);et&&(Ge.format=et);}o.push(Ge);}}F(),fe(e);for(let B of (J=n.drawingsByAnchorParaId.get(t))!=null?J:[])s.has(B.drawingId)||ae(B);return {text:f,segments:o,spans:i.sort((B,G)=>B.from-G.from||B.to-G.to||B.id.localeCompare(G.id))};function g(B,G){let{from:$,to:K}=b("\uFFFC");o.push({kind:"placeholder",from:$,to:K,placeholderKind:B,sourceTag:G.localName});}function h(B){let G=n.hyperlinkByElement.get(B);for(let $=0;$<B.childNodes.length;$+=1){let K=B.childNodes[$];if(!K||K.nodeType!==1)continue;let X=K;if(X.namespaceURI!==wordView.W_NS||X.localName!=="r")continue;let Se=p(X);if(Se.length===0)continue;let{from:Ce,to:xe}=b(Se),We={kind:"text",from:Ce,to:xe,text:Se},Ge=nn(X,n.theme);Ge&&(We.format=Ge),G&&(We.hyperlink=v({},G)),o.push(We);}}function y(B){var $;let G=nn(B,n.theme);for(let K=0;K<B.childNodes.length;K++){let X=B.childNodes[K];if(!X||X.nodeType!==1)continue;let Se=X;if(Se.namespaceURI!==wordView.W_NS)continue;if(Se.localName==="fldChar"){let et=Se.getAttributeNS(wordView.W_NS,"fldCharType");et==="begin"?(F(),u={instruction:"",cachedText:"",inResult:false,format:G}):et==="separate"&&u?u.inResult=true:et==="end"&&u&&(I(u),u=null);continue}if(u&&Se.localName==="instrText"){u.instruction+=($=Se.textContent)!=null?$:"";continue}let Ce=hb(Se);if(Ce.length===0)continue;if(u){u.inResult&&(u.cachedText+=Ce);continue}let{from:xe,to:We}=b(Ce),Ge={kind:"text",from:xe,to:We,text:Ce};G&&(Ge.format=G),o.push(Ge);}}function S(B){var X;let G=(X=B.getAttributeNS(wordView.W_NS,"instr"))!=null?X:"",$=Xd(G);if(!$)return false;let K=p(B);return A($,G,K,nn(B,n.theme)),true}function k(B){let G=p(B);G.length>0&&(u!=null&&u.inResult)&&(u.cachedText+=G);}function I(B){let G=Xd(B.instruction);if(G){A(G,B.instruction,B.cachedText,B.format);return}L(B);}function A(B,G,$,K){let{from:X,to:Se}=b("\uFFFC"),Ce={kind:"field",from:X,to:Se,fieldKind:B,instruction:G,cachedText:$};K&&(Ce.format=K),o.push(Ce);}function F(){u&&(L(u),u=null);}function L(B){if(B.cachedText.length===0)return;let{from:G,to:$}=b(B.cachedText),K={kind:"text",from:G,to:$,text:B.cachedText};B.format&&(K.format=B.format),o.push(K);}function V(B){let G=nn(B,n.theme);for(let $=0;$<B.childNodes.length;$++){let K=B.childNodes[$];if(!K||K.nodeType!==1)continue;let X=K;if(X.namespaceURI!==wordView.W_NS)continue;if(X.localName==="br"&&X.getAttributeNS(wordView.W_NS,"type")==="page"){g("pageBreak",X);continue}let Se=p(X);if(Se.length===0)continue;let{from:Ce,to:xe}=b(Se),We={kind:"text",from:Ce,to:xe,text:Se};G&&(We.format=G),o.push(We);}}function ee(B){if(B.namespaceURI===wordView.W_NS&&B.localName==="pict"){if(xb(B)||yb(B,e,t,n))return;let xe=Sb(B,t,d);if(!xe||l.has(B))return;l.add(B),d+=1;let{from:We,to:Ge}=b("\uFFFC");o.push(O(v({},xe),{from:We,to:Ge}));return}let G=n.drawingIdByElement.get(B),$=G?n.imagesByDrawingId.get(G):void 0,K=G?n.drawingInfoById.get(G):void 0;if(G&&K&&K.kind!=="picture"){s.add(G),ae(K);return}if(!G||!$){g("drawing",B);return}let{from:X,to:Se}=b("\uFFFC");s.add(G);let Ce={kind:"image",from:X,to:Se,drawingId:G,src:$.src,contentType:$.contentType};$.width!==void 0&&(Ce.width=$.width),$.height!==void 0&&(Ce.height=$.height),$.anchoringMode!==void 0&&(Ce.anchoringMode=$.anchoringMode),$.wrap!==void 0&&(Ce.wrap=$.wrap),$.position!==void 0&&(Ce.position=$.position),o.push(Ce);}function fe(B){for(let G of ["drawing","pict"]){let $=B.getElementsByTagNameNS(wordView.W_NS,G);for(let K=0;K<$.length;K++){let X=$[K];if(!X)continue;if(G==="pict"){if(l.has(X))continue;ee(X);continue}let Se=n.drawingIdByElement.get(X);!Se||s.has(Se)||ee(X);}}}function ae(B){var xe;if(B.kind==="picture"||(s.add(B.drawingId),Fg(B,n)))return;let G=B.kind==="textBox"&&(xe=B.innerText)!=null?xe:"",{from:$,to:K}=b(G.length>0?G:"\uFFFC"),X={kind:"drawing",from:$,to:K,drawingId:B.drawingId,drawingKind:B.kind};G.length>0&&(X.text=G);let Se=uc(B.extentEMU);if(Se.width!==void 0&&(X.width=Se.width),Se.height!==void 0&&(X.height=Se.height),B.anchoringMode!==void 0&&(X.anchoringMode=B.anchoringMode),B.wrap!==void 0&&(X.wrap=B.wrap),B.position!==void 0&&(X.position=B.position),B.hasBorder!==void 0&&(X.hasBorder=B.hasBorder),B.hasFill!==void 0&&(X.hasFill=B.hasFill),B.isLineOrConnector!==void 0&&(X.isLineOrConnector=B.isLineOrConnector),B.isLineOrConnector){let We=vb(n.indices.drawingIdx.get(B.drawingId),n.theme);We.color&&(X.strokeColor=We.color),We.width!==void 0&&(X.strokeWidth=We.width);}B.innerTextAlign!==void 0&&(X.innerTextAlign=B.innerTextAlign);let Ce=Og(B,n);Ce.length>0&&(X.paragraphs=Ce),o.push(X);}}var jd=127e3;function Fg(e,t){var a,s,l,d;if(e.kind!=="textBox"||e.anchoringMode!=="anchor"||e.extentEMU.cx<=0||e.extentEMU.cy<=0||e.extentEMU.cx>jd||e.extentEMU.cy>jd)return false;let n=(s=(a=e.position)==null?void 0:a.horizontal)==null?void 0:s.posOffset,r=(d=(l=e.position)==null?void 0:l.vertical)==null?void 0:d.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?Hg(i):false}function Hg(e){var o,i;let t=[],n=0,r=e.getElementsByTagName("*");for(let a=0;a<r.length;a+=1){let s=r[a];if(!(!s||s.namespaceURI!==wordView.W_NS)){if(s.localName==="fldChar"){let l=s.getAttributeNS(wordView.W_NS,"fldCharType");if(l==="begin")t.push({instruction:""});else if(l==="end"){let d=t.pop();if(!d||!/^SET\b/i.test(d.instruction.trim()))return false;n+=1;}continue}if(s.localName==="instrText"){let l=t[t.length-1];if(!l)return false;l.instruction+=(o=s.textContent)!=null?o:"";continue}if(s.localName==="t"&&((i=s.textContent)!=null?i:"").trim().length>0&&t.length===0)return false}}return t.length===0&&n>0}function Og(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?[Zo("body",o,t,n,r)]:[]})}function $g(e,t,n,r){let o=wordView.getImageBytesSync(e,t,n);if(!o)return null;let i={src:`data:${o.contentType};base64,${Vg(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 a=zg(o);return a.width!==void 0&&(i.width=a.width),a.height!==void 0&&(i.height=a.height),i}function zg(e){return uc(e.extentEMU)}function uc(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 Vg(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+=Wn(t,o>>18&63),n+=Wn(t,o>>12&63),n+=Wn(t,o>>6&63),n+=Wn(t,o&63);}if(r<e.length){let o=e[r],i=r+1<e.length?e[r+1]:0,a=o<<16|i<<8;n+=Wn(t,a>>18&63),n+=Wn(t,a>>12&63),n+=r+1<e.length?Wn(t,a>>6&63):"=",n+="=";}return n}function Wn(e,t){return e.charAt(t)}function Gg(e,t){let n={},r=Qa(e);if(!r)return n;let o=r.getElementsByTagNameNS(wordView.W_NS,"docDefaults")[0];if(!o)return n;let i=Xo(o,wordView.W_NS,["rPrDefault","rPr"]),a=i?bc(i,t):void 0;a&&(n.run=a);let s=Xo(o,wordView.W_NS,["pPrDefault","pPr"]);if(s){let l=Lr(s,t);l&&(n.paragraph=l);}return n}function Qa(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 jg(e){var a,s,l,d,u,f,p;let t=Kg(e);if(!t)return {nums:new Map};let n=new Map,r=t.getElementsByTagNameNS(wordView.W_NS,"abstractNum");for(let b=0;b<r.length;b++){let w=r[b];if(!w)continue;let g=w.getAttributeNS(wordView.W_NS,"abstractNumId");if(!g)continue;let h=new Map;for(let y of yt(w,wordView.W_NS,"lvl")){let S=(a=Ae(y,"ilvl"))!=null?a:0,k=(l=(s=q(y,wordView.W_NS,"numFmt"))==null?void 0:s.getAttributeNS(wordView.W_NS,"val"))!=null?l:void 0,I=(u=(d=q(y,wordView.W_NS,"lvlText"))==null?void 0:d.getAttributeNS(wordView.W_NS,"val"))!=null?u:void 0,A=q(y,wordView.W_NS,"start"),F=A&&(f=Ae(A,"val"))!=null?f:1,L=Lr(q(y,wordView.W_NS,"pPr"));h.set(S,v(v(v({ilvl:S,start:F},k?{numFmt:k}:{}),I?{lvlText:I}:{}),L?{paragraphFormat:L}:{}));}n.set(g,h);}let o=new Map,i=t.getElementsByTagNameNS(wordView.W_NS,"num");for(let b=0;b<i.length;b++){let w=i[b];if(!w)continue;let g=w.getAttributeNS(wordView.W_NS,"numId"),h=(p=q(w,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 Ug(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 a=(i=e.indent)!=null?i:{};e.indent=v({},a),r.indent.left!==void 0&&(a.left===void 0||a.left===0)&&(e.indent.left=r.indent.left),r.indent.right!==void 0&&a.right===void 0&&(e.indent.right=r.indent.right),r.indent.firstLine!==void 0&&a.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 Kg(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 _g(e,t){var l,d,u,f,p;let n=(l=t.numbering.nums.get(e.numId))==null?void 0:l.get(e.ilvl),r=(d=e.numFmt)!=null?d: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}:{}),a=`${i.numId}:${i.ilvl}`;if(r==="bullet")return i.label=qg(o),i;let s=((p=t.numberingCounters.get(a))!=null?p:((f=n==null?void 0:n.start)!=null?f:1)-1)+1;return t.numberingCounters.set(a,s),i.label=Xg(s,r,o),i}function qg(e){let t=e==null?void 0:e.replace(/%\d+/g,"").trim();return t&&t.length>0?t:"\u2022"}function Xg(e,t,n){let r=t==="lowerLetter"?Ud(e,false):t==="upperLetter"?Ud(e,true):String(e);return n?n.replace(/%\d+/g,r):`${r}.`}function Ud(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 Yg(e,t,n){var i,a;let r=new Map;for(let s of e.parts.values()){if(s.contentType!=="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"||!s.xmlDom)continue;let l=s.xmlDom.getElementsByTagNameNS(wordView.W_NS,"style");for(let d=0;d<l.length;d++){let u=l[d];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 b={},w=(a=q(u,wordView.W_NS,"basedOn"))==null?void 0:a.getAttributeNS(wordView.W_NS,"val");w&&(b.basedOn=w);let g=nb(u,n);g&&(b.format=g),r.set(f,b);}}let o=new Map;for(let s of r.keys()){let l=mc(s,r,new Set);l&&o.set(s,l);}for(let s of t.stylesIdx.values()){if(s.outlineLevel===void 0)continue;let l=o.get(s.styleId);o.set(s.styleId,Ht(l,{outlineLevel:s.outlineLevel}));}return o}function Kd(e,t){var o;let n=Qa(e);if(!n)return;let r=n.getElementsByTagNameNS(wordView.W_NS,"style");for(let i=0;i<r.length;i++){let a=r[i];if(!a||((o=a.getAttributeNS(wordView.W_NS,"type"))!=null?o:"paragraph")!==t||a.getAttributeNS(wordView.W_NS,"default")!=="1")continue;let l=a.getAttributeNS(wordView.W_NS,"styleId");if(l)return l}}function Zg(e,t){var a,s;let n=new Map,r=Qa(e);if(!r)return new Map;let o=r.getElementsByTagNameNS(wordView.W_NS,"style");for(let l=0;l<o.length;l++){let d=o[l];if(!d)continue;let u=d.getAttributeNS(wordView.W_NS,"styleId");if(!u||((a=d.getAttributeNS(wordView.W_NS,"type"))!=null?a:"paragraph")!=="table")continue;let p={},b=(s=q(d,wordView.W_NS,"basedOn"))==null?void 0:s.getAttributeNS(wordView.W_NS,"val");b&&(p.basedOn=b);let w=Jg(d,t);w&&(p.format=w),n.set(u,p);}let i=new Map;for(let l of n.keys()){let d=fc(l,n,new Set);d&&i.set(l,d);}return i}function fc(e,t,n){if(n.has(e))return;n.add(e);let r=t.get(e);if(!r)return;let o=r.basedOn?fc(r.basedOn,t,n):void 0;return Xa(o,r.format)}function Jg(e,t){let n=Xa(pc(q(e,wordView.W_NS,"tblPr"),q(e,wordView.W_NS,"tcPr"),t),Qg(e,t)),r=eb(e,t);return r?Xa(n,{conditions:r}):n}function Qg(e,t){for(let n of yt(e,wordView.W_NS,"tblStylePr"))if(n.getAttributeNS(wordView.W_NS,"type")==="wholeTable")return pc(q(n,wordView.W_NS,"tblPr"),q(n,wordView.W_NS,"tcPr"),t)}function eb(e,t){let n={};for(let r of yt(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=tb(r,t);i&&(n[o]=i);}return Object.keys(n).length>0?n:void 0}function tb(e,t){let n={},r=es(q(e,wordView.W_NS,"tcPr"),t);r&&(n.cell=r);let o=Ht(Lr(q(e,wordView.W_NS,"pPr"),t),hc(q(e,wordView.W_NS,"rPr"),t));return o&&(n.paragraphFormat=o),Object.keys(n).length>0?n:void 0}function pc(e,t,n){let r={};if(e){let o=ic(e);o&&(r.layoutMode=o);let i=lc(e);i&&(r.borders=i);let a=Jo(q(e,wordView.W_NS,"tblCellMar"));a&&(r.cellMargin=a);let s=ac(e);s&&(r.tableLook=s);}if(t){let o=es(t,n);o&&(r.cell=o);}return Object.keys(r).length>0?r:void 0}function es(e,t){if(!e)return;let n={},r=Jo(q(e,wordView.W_NS,"tcMar"));r&&(n.margin=r);let o=Rg(e);o&&(n.borders=o);let i=Qo(q(e,wordView.W_NS,"shd"),t);i&&(n.shading=i);let a=Mg(q(e,wordView.W_NS,"vAlign"));a&&(n.verticalAlignment=a);let s=st(q(e,wordView.W_NS,"noWrap"));return (s!==void 0?s:q(e,wordView.W_NS,"noWrap")!==null)&&(n.noWrap=true),Object.keys(n).length>0?n:void 0}function Xa(e,t){var r,o,i,a,s,l,d,u,f,p,b,w,g,h,y,S,k,I,A,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:{}),(a=t==null?void 0:t.cellMargin)!=null?a:{})),(e!=null&&e.tableLook||t!=null&&t.tableLook)&&(n.tableLook=sc(e==null?void 0:e.tableLook,t==null?void 0:t.tableLook)),(e!=null&&e.cell||t!=null&&t.cell)&&(n.cell=v(v({},(s=e==null?void 0:e.cell)!=null?s:{}),(l=t==null?void 0:t.cell)!=null?l:{}),((d=e==null?void 0:e.cell)!=null&&d.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:{}),(w=(b=t==null?void 0:t.cell)==null?void 0:b.margin)!=null?w:{})),((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({},(S=(y=e==null?void 0:e.cell)==null?void 0:y.borders)!=null?S:{}),(I=(k=t==null?void 0:t.cell)==null?void 0:k.borders)!=null?I:{}))),(e!=null&&e.paragraphFormat||t!=null&&t.paragraphFormat)&&(n.paragraphFormat=Ht(e==null?void 0:e.paragraphFormat,t==null?void 0:t.paragraphFormat)),e!=null&&e.conditions||t!=null&&t.conditions){n.conditions=v({},(A=e==null?void 0:e.conditions)!=null?A:{});for(let[L,V]of Object.entries((F=t==null?void 0:t.conditions)!=null?F:{}))n.conditions[L]=Ct(n.conditions[L],V);}return n}function Ct(e,t){var r,o,i,a,s,l,d,u,f,p,b,w,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||(a=t==null?void 0:t.cell)!=null&&a.margin)&&(n.cell.margin=v(v({},(l=(s=e==null?void 0:e.cell)==null?void 0:s.margin)!=null?l:{}),(u=(d=t==null?void 0:t.cell)==null?void 0:d.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({},(w=(b=e==null?void 0:e.cell)==null?void 0:b.borders)!=null?w:{}),(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=Ht(e==null?void 0:e.paragraphFormat,t==null?void 0:t.paragraphFormat)),n}function mc(e,t,n){if(n.has(e))return;n.add(e);let r=t.get(e);if(!r)return;let o=r.basedOn?mc(r.basedOn,t,n):void 0;return Ht(o,r.format)}function nb(e,t){let n=Lr(q(e,wordView.W_NS,"pPr"),t),r=hc(q(e,wordView.W_NS,"rPr"),t);return Ht(n,r)}function Lr(e,t){var o,i;let n={},r=false;if(e){let a=q(e,wordView.W_NS,"jc"),s=a==null?void 0:a.getAttributeNS(wordView.W_NS,"val");(s==="left"||s==="center"||s==="right"||s==="both"||s==="distribute")&&(n.alignment=s,r=true);let l=q(e,wordView.W_NS,"ind");if(l){let I=Ae(l,"left"),A=Ae(l,"right"),F=Ae(l,"firstLine"),L=Ae(l,"hanging"),V=F!==void 0?F:L!==void 0?-L:void 0;(I!==void 0||A!==void 0||V!==void 0)&&(n.indent={},I!==void 0&&(n.indent.left=I),A!==void 0&&(n.indent.right=A),V!==void 0&&(n.indent.firstLine=V),r=true);}let d=q(e,wordView.W_NS,"spacing");if(d){let I=Ae(d,"before"),A=Ae(d,"after"),F=Ae(d,"line"),L=d.getAttributeNS(wordView.W_NS,"lineRule"),V=L==="auto"||L==="exact"||L==="atLeast"?L:void 0;(I!==void 0||A!==void 0||F!==void 0||V!==void 0)&&(n.spacing={},I!==void 0&&(n.spacing.before=I),A!==void 0&&(n.spacing.after=A),F!==void 0&&(n.spacing.line=F),V!==void 0&&(n.spacing.lineRule=V),r=true);}let u=rb(q(e,wordView.W_NS,"tabs"));u!==void 0&&(n.tabStops=u,r=true);let f=q(e,wordView.W_NS,"outlineLvl"),p=f?Ae(f,"val"):void 0;p!==void 0&&p>=0&&p<=9&&(n.outlineLevel=p,r=true);let b=q(e,wordView.W_NS,"numPr");if(b){let I=(o=q(b,wordView.W_NS,"numId"))==null?void 0:o.getAttributeNS(wordView.W_NS,"val");I&&I!=="0"&&(n.hasNumbering=true,n.numbering={numId:I,ilvl:q(b,wordView.W_NS,"ilvl")&&(i=Ae(q(b,wordView.W_NS,"ilvl"),"val"))!=null?i:0},r=true);}gc(q(e,wordView.W_NS,"rPr"),n,t,false)&&(r=true),ob(e,n)&&(r=true);let w=Qo(q(e,wordView.W_NS,"shd"),t);w&&(n.shading=w,r=true);let g=st(q(e,wordView.W_NS,"keepNext"));g!==void 0&&(n.keepNext=g,r=true);let h=st(q(e,wordView.W_NS,"keepLines"));h!==void 0&&(n.keepLines=h,r=true);let y=st(q(e,wordView.W_NS,"widowControl"));y!==void 0&&(n.widowControl=y,r=true);let S=st(q(e,wordView.W_NS,"snapToGrid"));S!==void 0&&(n.snapToGrid=S,r=true);let k=st(q(e,wordView.W_NS,"pageBreakBefore"));k!==void 0&&(n.pageBreakBefore=k,r=true),q(e,wordView.W_NS,"sectPr")&&(n.hasSectionBreak=true,r=true);}return r?n:void 0}function rb(e){if(!e)return;let t=[];for(let n of yt(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=Ae(n,"pos");if(!o||i===void 0)continue;let a=n.getAttributeNS(wordView.W_NS,"leader"),s=a==="none"||a==="dot"||a==="hyphen"||a==="underscore"||a==="heavy"||a==="middleDot"?a:void 0;t.push(v({alignment:o,position:i},s?{leader:s}:{}));}return t.length>0?t:void 0}function hc(e,t){let n={};return gc(e,n,t)?n:void 0}function gc(e,t,n,r=true){if(!e)return false;let o=false,i=yc(e,n);i&&(t.fontFamily=i,o=true);let a=q(e,wordView.W_NS,"sz"),s=a?Ae(a,"val"):void 0;s!==void 0&&(t.fontSize=s/2,o=true);let l=st(q(e,wordView.W_NS,"b"));if(l!==void 0&&(t.bold=l,o=true),r){let p=vc(q(e,wordView.W_NS,"color"),n);p&&(t.color=p,o=true);}let d=xc(e);d!==void 0&&(t.characterSpacing=d,o=true);let u=wc(q(e,wordView.W_NS,"highlight"));u&&(t.highlight=u,o=true);let f=Qo(q(e,wordView.W_NS,"shd"),n);return f&&(t.shading=f,o=true),o}function ob(e,t){let n=q(e,wordView.W_NS,"pBdr");if(!n)return false;let r={};for(let o of ["top","right","bottom","left","between","bar"]){let i=ib(q(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 Ht(e,t){var r,o,i,a,s,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:{}),(a=t==null?void 0:t.spacing)!=null?a:{})),(e&&"borders"in e&&e.borders||t&&"borders"in t&&t.borders)&&(n.borders=v(v({},(s=e==null?void 0:e.borders)!=null?s:{}),(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(d=>v({},d)):e&&"tabStops"in e&&e.tabStops!==void 0&&(n.tabStops=e.tabStops.map(d=>v({},d))),n}function Ae(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 ib(e){var a;if(!e)return;let t=(a=e.getAttributeNS(wordView.W_NS,"val"))!=null?a:void 0;if(t==="none"||t==="nil")return;let n={val:t},r=e.getAttributeNS(wordView.W_NS,"color"),o=Ae(e,"sz"),i=Ae(e,"space");return r&&(n.color=r),o!==void 0&&(n.size=o),i!==void 0&&(n.space=i),n}function nn(e,t){let n=q(e,wordView.W_NS,"rPr");if(!n)return;let r=bc(n,t);return r&&Object.keys(r).length>0?r:void 0}function bc(e,t){let n={},r=yc(e,t);r&&(n.fontFamily=r);let o=st(q(e,wordView.W_NS,"b"));o!==void 0&&(n.bold=o);let i=st(q(e,wordView.W_NS,"i"));i!==void 0&&(n.italic=i);let a=q(e,wordView.W_NS,"u");if(a){let y=a.getAttributeNS(wordView.W_NS,"val");n.underline=y!=="none"&&y!=="0"&&y!=="false";}let s=st(q(e,wordView.W_NS,"strike"));s!==void 0&&(n.strike=s);let l=st(q(e,wordView.W_NS,"dstrike"));l!==void 0&&(n.doubleStrike=l);let d=st(q(e,wordView.W_NS,"caps"));d!==void 0&&(n.caps=d);let u=st(q(e,wordView.W_NS,"smallCaps"));u!==void 0&&(n.smallCaps=u);let f=q(e,wordView.W_NS,"sz");if(f){let y=f.getAttributeNS(wordView.W_NS,"val"),S=y!==null?Number(y):NaN;Number.isFinite(S)&&(n.fontSize=S/2);}let p=q(e,wordView.W_NS,"color");if(p){let y=vc(p,t);y&&(n.color=y);}let b=xc(e);b!==void 0&&(n.characterSpacing=b);let w=ab(q(e,wordView.W_NS,"vertAlign"));w&&(n.verticalAlign=w);let g=wc(q(e,wordView.W_NS,"highlight"));g&&(n.highlight=g);let h=Qo(q(e,wordView.W_NS,"shd"),t);return h&&(n.shading=h),Object.keys(n).length>0?n:void 0}function wc(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 xc(e){let t=q(e,wordView.W_NS,"spacing");return t?Ae(t,"val"):void 0}function ab(e){let t=e==null?void 0:e.getAttributeNS(wordView.W_NS,"val");return t==="baseline"||t==="superscript"||t==="subscript"?t:void 0}function yc(e,t){let n=q(e,wordView.W_NS,"rFonts");if(!n)return;let r=n.getAttributeNS(wordView.W_NS,"eastAsia")||qo(t,n.getAttributeNS(wordView.W_NS,"eastAsiaTheme")),o=n.getAttributeNS(wordView.W_NS,"ascii")||n.getAttributeNS(wordView.W_NS,"hAnsi")||qo(t,n.getAttributeNS(wordView.W_NS,"asciiTheme"))||qo(t,n.getAttributeNS(wordView.W_NS,"hAnsiTheme"));return o&&r&&sb(o)?o===r?o:`${o}, ${r}`:r||o||n.getAttributeNS(wordView.W_NS,"cs")||qo(t,n.getAttributeNS(wordView.W_NS,"csTheme"))||void 0}function sb(e){let t=e.trim().toLowerCase();return t==="calibri"||t==="aptos"||t==="arial"}function vc(e,t){if(!e)return;let n=Ar(e.getAttributeNS(wordView.W_NS,"val")),r=n!=null?n:ts(t,e.getAttributeNS(wordView.W_NS,"themeColor"));if(r)return Sc(r,e.getAttributeNS(wordView.W_NS,"themeTint"),e.getAttributeNS(wordView.W_NS,"themeShade"))}function ts(e,t){if(!(!e||!t))return e.colors.get(t)}function qo(e,t){if(!(!e||!t))return e.fonts.get(lb(t))}function lb(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 Ar(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 Sc(e,t,n){let r=_d(t);if(r!==void 0)return db(e,r/255);let o=_d(n);return o!==void 0?cb(e,o/255):e}function _d(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 db(e,t){return kc(e,n=>n+(255-n)*t)}function cb(e,t){return kc(e,n=>n*t)}function kc(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 st(e){if(!e)return;let t=e.getAttributeNS(wordView.W_NS,"val");return Cc(t)}function Cc(e){return e!=="0"&&e!=="false"&&e!=="off"}function Ec(e){if(e.namespaceURI!==wordView.W_NS||e.localName!=="sdt")return false;let t=q(e,wordView.W_NS,"sdtPr");return t?st(q(t,wordView.W_NS,"showingPlcHdr"))===true:false}function q(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 ub(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 yt(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 Xo(e,t,n){let r=e;for(let o of n)if(r=r?q(r,t,o):null,!r)return null;return r}function fb(e,t,n,r,o,i){var l,d;let a=e.commentIdx.get(t);if(!(a!=null&&a.comment))return null;let s=ns(a.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=a.comment.getAttributeNS(wordView.W_NS,"author"))!=null?l:"",date:(d=a.comment.getAttributeNS(wordView.W_NS,"date"))!=null?d:"",body:s}}function pb(e,t){var r,o;let n=[];for(let[i,a]of e.commentIdx)t.has(i)||!a.comment||n.push({id:i,author:(r=a.comment.getAttributeNS(wordView.W_NS,"author"))!=null?r:"",date:(o=a.comment.getAttributeNS(wordView.W_NS,"date"))!=null?o:"",text:ns(a.comment,"t"),rangeKind:"complex"});return n}function qd(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 Ic(e,t=false){let n="";function r(o){var a;if(o.nodeType!==1)return;let i=o;if(i.namespaceURI===wordView.W_NS&&!(t&&Ec(i))){if(i.localName==="t"){n+=(a=i.textContent)!=null?a:"";return}if(i.localName==="tab"||i.localName==="ptab"){n+=" ";return}if(i.localName==="br"){let s=i.getAttributeNS(wordView.W_NS,"type");(s===null||s===""||s==="textWrapping")&&(n+=`
4
+ `);return}if(i.localName!=="delText"&&i.localName!=="commentReference")for(let s=0;s<i.childNodes.length;s++){let l=i.childNodes[s];l&&r(l);}}}return r(e),n}function mb(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 hb(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"?`
5
+ `:""}return e.localName==="delText"||e.localName==="commentReference"||e.localName==="instrText"?"":Ic(e)}function Xd(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 ns(e,t){var o,i;let n=e.getElementsByTagNameNS(wordView.W_NS,t),r="";for(let a=0;a<n.length;a++)r+=(i=(o=n[a])==null?void 0:o.textContent)!=null?i:"";return r}function gb(e){return e.namespaceURI===wordView.W_NS&&(e.localName==="drawing"||e.localName==="pict")}function bb(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 wb(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 xb(e){let t=e.parentElement;for(;t&&!(t.namespaceURI===Ua&&t.localName==="Fallback");)t=t.parentElement;let n=t==null?void 0:t.parentElement;if(!n||n.namespaceURI!==Ua||n.localName!=="AlternateContent")return false;for(let r=0;r<n.childNodes.length;r+=1){let o=n.childNodes[r];if(!((o==null?void 0:o.nodeType)!==1||o.namespaceURI!==Ua||o.localName!=="Choice")&&o.getElementsByTagNameNS(wordView.W_NS,"drawing").length>0)return true}return false}function yb(e,t,n,r){var s,l;let o=e.getElementsByTagNameNS(qa,"line")[0];if(!o||!o.hasAttributeNS(ig,"gfxdata"))return false;let i=new Set,a=t.getElementsByTagNameNS(wordView.W_NS,"drawing");for(let d=0;d<a.length;d+=1){let u=r.drawingIdByElement.get(a[d]);u&&i.add(u);}for(let d of (s=r.drawingsByAnchorParaId.get(n))!=null?s:[])i.add(d.drawingId);for(let d of i)if((l=r.drawingInfoById.get(d))!=null&&l.isLineOrConnector)return true;return false}function vb(e,t){var s;let n=e==null?void 0:e.getElementsByTagNameNS(xt,"ln")[0];if(!n)return {};let r=Number(n.getAttribute("w")),o=Number.isFinite(r)&&r>0?r/914400*96:void 0,i=q(n,xt,"solidFill"),a;if(i){let l=q(i,xt,"srgbClr"),d=q(i,xt,"schemeClr"),u=q(i,xt,"sysClr");a=Ar(l==null?void 0:l.getAttribute("val")),a!=null||(a=ts(t,(s=d==null?void 0:d.getAttribute("val"))!=null?s:null)),a!=null||(a=Ar(u==null?void 0:u.getAttribute("lastClr")));}return v(v({},a?{color:`#${a}`}:{}),o!==void 0?{width:o}:{})}function Sb(e,t,n){var u,f;if(e.namespaceURI!==wordView.W_NS||e.localName!=="pict")return null;let r=e.getElementsByTagNameNS(qa,"line")[0];if(!r)return null;let o=kb(r.getAttribute("style")),i=r.getElementsByTagNameNS(qa,"stroke")[0],a=_a(o.get("width")),s=_a(o.get("height")),l=Cb((u=i==null?void 0:i.getAttribute("color"))!=null?u:r.getAttribute("strokecolor")),d=_a((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},a!==void 0?{width:a}:{}),s!==void 0?{height:s}:{}),l?{strokeColor:l}:{}),d!==void 0?{strokeWidth:d}:{})}function kb(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(),a=r.slice(o+1).trim();i&&a&&t.set(i,a);}return t}function _a(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 Cb(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 Eb(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 Ib(e){let t=e.blocks.filter(o=>o.type==="paragraph"),n=Pc(e),r=Tb(e);return {topLevelBlocks:e.blocks.length,topLevelParagraphs:t.length,tableBlocks:e.tables.length,tableParagraphs:n.length,allParagraphs:r.length,topLevelImages:rs(t),tableImages:rs(n),allImages:rs(r),topLevelDrawings:os(t),tableDrawings:os(n),allDrawings:os(r),pageBreaks:Mb(r)}}function IE(e,t){var i;let n=Ib(e),r=t?Nb(t):[],o=Rb(r);return {editor:n,native:{blocks:(i=t==null?void 0:t.blocks.length)!=null?i:0,paragraphs:r.length,images:o,drawings:Nc(r),pageBreaks:Tc(r)},missing:{paragraphs:n.allParagraphs-r.length,images:n.allImages-o,drawings:n.allDrawings-Nc(r),pageBreaks:n.pageBreaks-Tc(r)}}}function NE(e){return [...Wr(e.blocks),...e.headers.flatMap(t=>Wr(t.blocks)),...e.footers.flatMap(t=>Wr(t.blocks))]}function Nb(e){return Wr(e.blocks)}function Wr(e){return e.flatMap(t=>t.kind==="paragraph"?[t]:t.rows.flatMap(n=>n.cells.flatMap(r=>r.vMerge==="continue"?[]:Wr(r.blocks))))}function Tb(e){return [...e.blocks.filter(n=>n.type==="paragraph"),...Pc(e)]}function Pc(e){return Pb(e.tables)}function Pb(e){return e.flatMap(t=>t.rows.flatMap(n=>n.cells.flatMap(r=>r.vMerge==="continue"?[]:r.paragraphs)))}function rs(e){return e.reduce((t,n)=>t+n.segments.filter(r=>r.kind==="image").length,0)}function os(e){return e.reduce((t,n)=>t+n.segments.filter(r=>r.kind==="drawing").length,0)}function Rb(e){return e.reduce((t,n)=>t+n.content.filter(r=>r.kind==="image").length,0)}function Nc(e){return e.reduce((t,n)=>t+n.content.filter(r=>r.kind==="drawing").length,0)}function Mb(e){return e.reduce((t,n)=>t+n.segments.filter(r=>r.kind==="placeholder"&&r.placeholderKind==="pageBreak").length,0)}function Tc(e){return e.reduce((t,n)=>t+n.content.filter(r=>r.kind==="pageBreak").length,0)}function Dr(e){var o,i,a,s,l,d,u,f;let t={};if(!e)return Br(t);Lb(e,t),e.alignment&&(t["text-align"]=Wb(e.alignment)),((o=e.indent)==null?void 0:o.left)!==void 0&&Ab(e)&&(t["margin-left"]=Et(e.indent.left)),((i=e.indent)==null?void 0:i.right)!==void 0&&(t["margin-right"]=Et(e.indent.right)),((a=e.indent)==null?void 0:a.firstLine)!==void 0&&(t["text-indent"]=Et(e.indent.firstLine)),((s=e.spacing)==null?void 0:s.before)!==void 0&&(t["margin-top"]=Et(e.spacing.before)),((l=e.spacing)==null?void 0:l.after)!==void 0&&(t["margin-bottom"]=Et(e.spacing.after));let n=zb((d=e.spacing)==null?void 0:d.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"]=qt(e.fontFamily)),e.characterSpacing!==void 0&&(t["letter-spacing"]=Et(e.characterSpacing)),e.bold!==void 0&&(t["font-weight"]=e.bold?"700":"400");let r=(f=Rc(e.shading))!=null?f:Mc(e.highlight);return r&&(t["background-color"]=r),Hb(e,t),Br(t)}function Ab(e){var t;return !(e.numbering&&((t=e.indent)==null?void 0:t.left)===0&&e.indent.firstLine===void 0)}function Lb(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 Jn(e){var o;let t={};if(!e)return Br(t);e.bold!==void 0&&(t["font-weight"]=e.bold?"700":"400"),e.italic!==void 0&&(t["font-style"]=e.italic?"italic":"normal"),Db(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"]=qt(e.fontFamily)),e.characterSpacing!==void 0&&(t["letter-spacing"]=Et(e.characterSpacing)),e.verticalAlign&&(t["vertical-align"]=Fb(e.verticalAlign),e.verticalAlign!=="baseline"&&e.fontSize===void 0&&(t["font-size"]="smaller"));let n=Qn(e.color);n&&(t.color=n);let r=(o=Mc(e.highlight))!=null?o:Rc(e.shading);return r&&(t["background-color"]=r),Br(t)}function ni(e){var r;let t={};e.width!==void 0&&e.width>0&&e.widthType!=="auto"&&(t.width=e.widthType==="pct"?`${e.width/50}%`:Et(e.width)),e.margin&&(e.margin.top!==void 0&&(t["padding-top"]=Et(e.margin.top)),e.margin.right!==void 0&&(t["padding-right"]=Et(e.margin.right)),e.margin.bottom!==void 0&&(t["padding-bottom"]=Et(e.margin.bottom)),e.margin.left!==void 0&&(t["padding-left"]=Et(e.margin.left)));let n=Qn((r=e.shading)==null?void 0:r.fill);return n&&(t["background-color"]=n),e.verticalAlignment&&(t["vertical-align"]=Bb(e.verticalAlignment)),e.noWrap&&(t["white-space"]="nowrap"),e.borders&&(ti(t,"top",e.borders.top),ti(t,"right",e.borders.right),ti(t,"bottom",e.borders.bottom),ti(t,"left",e.borders.left)),Br(t)}function Qn(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:Qn(e.fill)}function Mc(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:Qn(e)}function Br(e){return {declarations:e,cssText:Object.entries(e).map(([t,n])=>`${t}: ${n}`).join("; ")}}function Wb(e){return e==="both"||e==="distribute"?"justify":e}function Bb(e){return e==="center"||e==="both"?"middle":e}function Db(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 Fb(e){return e==="superscript"?"super":e==="subscript"?"sub":"baseline"}function Hb(e,t){var r,o,i;let n=(r=e.borders)!=null?r:e.borderBottom?{bottom:e.borderBottom}:void 0;n&&(ei(t,"top",n.top),ei(t,"right",n.right),ei(t,"bottom",(o=n.bottom)!=null?o:n.between),ei(t,"left",(i=n.left)!=null?i:n.bar));}function ei(e,t,n){let r=Ob(n);r&&(e[`border-${t}`]=r,e[`padding-${t}`]=(n==null?void 0:n.space)!==void 0?`${n.space}pt`:"4pt");}function Ob(e){var o;if(!e||e.val==="none"||e.val==="nil")return null;let t=(o=Qn(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 ti(e,t,n){if(!n)return;let r=$b(n);e[`border-${t}`]=r!=null?r:"0";}function $b(e){var o;if(e.val==="none"||e.val==="nil"||e.size===0)return null;let t=(o=Qn(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 zb(e,t,n){return e===void 0?null:t==="exact"||t==="atLeast"?Et(e):n!==true?String(e/240):`calc(var(--coco-word-doc-grid-line-height, 1em) * ${e/240})`}function Et(e){return `${e/20}pt`}function AE(e,t={}){var l,d;let n=_b((l=t.startBlock)!=null?l:0,0,e.blocks.length),r=Math.max(1,Math.floor((d=t.maxChars)!=null?d:12e3)),o=[],i=19,a=n;for(;a<e.blocks.length;){let u=Ac(e.blocks[a]),f=o.length>0?1:0;if(o.length>0&&i+f+u.length>r)break;o.push(u),i+=f+u.length,a+=1;}let s=o.length>0?`<article>
6
6
  ${o.join(`
7
7
  `)}
8
- </article>`:"<article></article>";return a<e.blocks.length?{html:s,nextBlock:a}:{html:s}}function Pc(e){return e.type==="table"?Gb(e):Ob(e)}function Ob(e){let t=$b(e),n=Wr(e.format).cssText,r=[`data-para-id="${Xt(e.paraId)}"`,n?`style="${Xt(n)}"`:""].filter(Boolean).join(" "),o=zb(e);return `<${t} ${r}>${o||"&nbsp;"}</${t}>`}function $b(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 zb(e){var r,o;let t=(o=(r=e.format)==null?void 0:r.numbering)==null?void 0:o.label,n=t?`${os(t)} `:"";return e.segments.length===0?n+ni(e.text):n+e.segments.map(Vb).join("")}function Vb(e){var o,i;if(e.kind==="image")return `<img data-drawing-id="${Xt(e.drawingId)}" alt="[\u56FE\u7247]">`;if(e.kind==="drawing"){let a=e.text?ni(e.text):"[\u7ED8\u56FE]";return `<span data-drawing-id="${Xt(e.drawingId)}">${a}</span>`}if(e.kind==="placeholder")return e.placeholderKind==="pageBreak"?'<br data-page-break="true">':`<span data-object="${Xt(e.placeholderKind)}">[\u5BF9\u8C61]</span>`;if(e.kind==="field"){let a=ni((o=e.cachedText)!=null?o:"");return `<span data-field="${Xt(e.fieldKind)}">${a}</span>`}let t=Yn(e.format).cssText,n=ni(e.text),r=t?` style="${Xt(t)}"`:"";if(e.kind==="revision"){let a=e.revisionKind==="delete"?"del":"ins";return `<${a}${r}>${n}</${a}>`}if(e.hyperlink){let a=(i=e.hyperlink.target)!=null?i:e.hyperlink.anchor;return `<a${a?` href="${Xt(a)}"`:""}${r}>${n}</a>`}return t?`<span${r}>${n}</span>`:n}function Gb(e){let t=e.rows.map(n=>`<tr>${n.cells.map(o=>{let i=ti(o).cssText,a=[o.gridSpan>1?`colspan="${o.gridSpan}"`:"",o.rowSpan!==void 0&&o.rowSpan>1?`rowspan="${o.rowSpan}"`:"",i?`style="${Xt(i)}"`:""].filter(Boolean).join(" "),s=o.blocks.map(Pc).join(`
8
+ </article>`:"<article></article>";return a<e.blocks.length?{html:s,nextBlock:a}:{html:s}}function Ac(e){return e.type==="table"?Kb(e):Vb(e)}function Vb(e){let t=Gb(e),n=Dr(e.format).cssText,r=[`data-para-id="${Xt(e.paraId)}"`,n?`style="${Xt(n)}"`:""].filter(Boolean).join(" "),o=jb(e);return `<${t} ${r}>${o||"&nbsp;"}</${t}>`}function Gb(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 jb(e){var r,o;let t=(o=(r=e.format)==null?void 0:r.numbering)==null?void 0:o.label,n=t?`${is(t)} `:"";return e.segments.length===0?n+ri(e.text):n+e.segments.map(Ub).join("")}function Ub(e){var o,i;if(e.kind==="image")return `<img data-drawing-id="${Xt(e.drawingId)}" alt="[\u56FE\u7247]">`;if(e.kind==="drawing"){let a=e.text?ri(e.text):"[\u7ED8\u56FE]";return `<span data-drawing-id="${Xt(e.drawingId)}">${a}</span>`}if(e.kind==="placeholder")return e.placeholderKind==="pageBreak"?'<br data-page-break="true">':`<span data-object="${Xt(e.placeholderKind)}">[\u5BF9\u8C61]</span>`;if(e.kind==="field"){let a=ri((o=e.cachedText)!=null?o:"");return `<span data-field="${Xt(e.fieldKind)}">${a}</span>`}let t=Jn(e.format).cssText,n=ri(e.text),r=t?` style="${Xt(t)}"`:"";if(e.kind==="revision"){let a=e.revisionKind==="delete"?"del":"ins";return `<${a}${r}>${n}</${a}>`}if(e.hyperlink){let a=(i=e.hyperlink.target)!=null?i:e.hyperlink.anchor;return `<a${a?` href="${Xt(a)}"`:""}${r}>${n}</a>`}return t?`<span${r}>${n}</span>`:n}function Kb(e){let t=e.rows.map(n=>`<tr>${n.cells.map(o=>{let i=ni(o).cssText,a=[o.gridSpan>1?`colspan="${o.gridSpan}"`:"",o.rowSpan!==void 0&&o.rowSpan>1?`rowspan="${o.rowSpan}"`:"",i?`style="${Xt(i)}"`:""].filter(Boolean).join(" "),s=o.blocks.map(Ac).join(`
9
9
  `);return `<td${a?` ${a}`:""}>${s||"&nbsp;"}</td>`}).join("")}</tr>`).join(`
10
10
  `);return `<table data-table-id="${Xt(e.tableId)}">
11
11
  ${t}
12
- </table>`}function ni(e){return os(e).replace(/\t/g,"&#9;").replace(/\r\n|\r|\n/g,"<br>")}function os(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function Xt(e){return os(e).replace(/"/g,"&quot;")}function jb(e,t,n){return Math.min(n,Math.max(t,Math.floor(e)))}function as(e){return H(v(v({kind:"word"},e.defaults?{defaults:e.defaults}:{}),e.pageLayout?{pageLayout:e.pageLayout}:{}),{sections:e.sections,headers:e.headers.map(Rc),footers:e.footers.map(Rc),blocks:e.blocks.map(t=>ls(t))})}function Z(e,t){var n,r;return (r=(n=ye(e,t))==null?void 0:n.paragraph)!=null?r:null}function ss(e,t){var r,o;let n=ye(e,t);return (o=(r=n==null?void 0:n.previous)==null?void 0:r.paraId)!=null?o:null}function ye(e,t){var n,r;return (r=(n=is(e.blocks,t))!=null?n:e.headers.reduce((o,i)=>o!=null?o:is(i.blocks,t),null))!=null?r:e.footers.reduce((o,i)=>o!=null?o:is(i.blocks,t),null)}function rn(e,t){var n,r;return (r=(n=oi(e.blocks,t))!=null?n:e.headers.reduce((o,i)=>o!=null?o:oi(i.blocks,t),null))!=null?r:e.footers.reduce((o,i)=>o!=null?o:oi(i.blocks,t),null)}function Oe(e,t){var n,r;return (r=(n=ri(e.blocks,t))!=null?n:e.headers.reduce((o,i)=>o!=null?o:ri(i.blocks,t),null))!=null?r:e.footers.reduce((o,i)=>o!=null?o:ri(i.blocks,t),null)}function ri(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 a=ri(i.blocks,t);if(a)return a}}}return null}function oi(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],a=0;for(let s=0;s<i.cells.length;s+=1){let l=i.cells[s],d=oi(l.blocks,t);if(d)return d;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:s,columnIndex:a};a+=Math.max(1,l.gridSpan);}}}return null}function is(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=Zb(r,t);if(o)return o}}return null}function _e(e){return [...Br(e.blocks),...e.headers.flatMap(t=>Br(t.blocks)),...e.footers.flatMap(t=>Br(t.blocks))]}function Br(e){return e.flatMap(t=>t.kind==="paragraph"?[t]:t.rows.flatMap(n=>n.cells.flatMap(r=>Br(r.blocks))))}function Ne(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 Ln(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 ls(e){return e.type==="table"?H(v(v(H(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=>H(v(v(v({},t.height?{height:t.height}:{}),t.isHeader?{isHeader:true}:{}),t.cantSplit?{cantSplit:true}:{}),{cells:t.cells.map(n=>Ub(n))}))}):Mc(e)}function Rc(e){return {kind:e.kind,partName:e.partName,blocks:e.blocks.map(t=>ls(t))}}function Ub(e){var o;let n=((o=e.blocks)!=null?o:e.paragraphs).map(i=>ls(i)),r={gridSpan:e.gridSpan,blocks:n,paragraphs:Br(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 Mc(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"?qb(o,t):o.kind==="revision"?_b(o):o.kind==="field"?Kb(o):o.kind==="image"?Xb(o):o.kind==="drawing"?Yb(o):o.kind==="placeholder"&&o.placeholderKind==="pageBreak"?[{kind:"pageBreak"}]:[])}}function Kb(e){var t;return [H(v({kind:"field",fieldKind:e.fieldKind,instruction:e.instruction},e.cachedText!==void 0?{cachedText:e.cachedText}:{}),{format:(t=e.format)!=null?t:null})]}function _b(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 qb(e,t){var o,i,a;if(e.text.length===0)return [];let n=[],r=e.from;for(let s of t){let l=Math.max(e.from,s.from),d=Math.min(e.to,s.to);d<=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(H(v({kind:"text",text:e.text.slice(l-e.from,d-e.from),format:(i=e.format)!=null?i:null},e.hyperlink?{hyperlink:v({},e.hyperlink)}:{}),{marks:[{kind:"comment",id:s.id,commentId:s.commentId,author:s.author,date:s.date,body:s.body}]})),r=d);}return r<e.to&&n.push(v({kind:"text",text:e.text.slice(r-e.from),format:(a=e.format)!=null?a:null},e.hyperlink?{hyperlink:v({},e.hyperlink)}:{})),n}function Xb(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 Yb(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=>Mc(n))),[t]}function Zb(e,t){var n;for(let r of e.rows)for(let o of r.cells){let i=o.paragraphs.findIndex(s=>s.paraId===t),a=o.blocks.findIndex(s=>s.kind==="paragraph"&&s.paraId===t);if(i>=0&&a>=0)return {paragraph:o.paragraphs[i],previous:(n=o.paragraphs[i-1])!=null?n:null,container:o.blocks,index:a,insertAfter(s){o.paragraphs.splice(i+1,0,s),o.blocks.splice(a+1,0,s);},remove(){o.paragraphs.splice(i,1),o.blocks.splice(a,1);}}}return null}function cs(e){let t=nw(e),n=e.cells.reduce((o,i)=>o+Ac(i),0),r=e.cells.reduce((o,i)=>o+Lc(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 LE(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}};ii(e.blocks,t);for(let n of e.headers)ii(n.blocks,t);for(let n of e.footers)ii(n.blocks,t);return t}function WE(e,t){if(cs(e).kind!=="block-fragmentable"||t.cellBlockCounts.length!==e.cells.length)return null;let r=[],o=[],i=false,a=false;for(let s=0;s<e.cells.length;s+=1){let l=e.cells[s],d=ew(l,t.cellBlockCounts[s]);if(!d)return null;r.push(d.head),o.push(d.tail),i||(i=d.head.blocks.length>0),a||(a=d.tail.blocks.length>0);}return !i||!a?null:{head:H(v({},e),{height:void 0,cells:r}),tail:H(v({},e),{height:void 0,cells:o})}}function BE(e,t){if(cs(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 a=Jb(e.cells[i],t.cellTextOffsets[i]);if(!a)return null;r.push(a.head),o.push(a.tail);}return {head:H(v({},e),{height:void 0,cells:r}),tail:H(v({},e),{height:void 0,cells:o})}}function Jb(e,t){if(e.blocks.length!==1)return null;let n=e.blocks[0];if(!n||n.kind!=="paragraph")return null;let r=Qb(n,t);return r?{head:H(v({},e),{blocks:[r.head],paragraphs:[r.head]}),tail:H(v({},e),{blocks:[r.tail],paragraphs:[r.tail]})}:null}function Qb(e,t){let n=e.content.reduce((a,s)=>a+(s.kind==="text"?s.text.length:0),0);if(!Number.isInteger(t)||t<=0||t>=n)return null;let r=[],o=[],i=0;for(let a of e.content){if(a.kind!=="text")return null;let s=i,l=i+a.text.length;if(i=l,l<=t){r.push(a);continue}if(s>=t){o.push(a);continue}let d=t-s;r.push(H(v({},a),{text:a.text.slice(0,d)})),o.push(H(v({},a),{text:a.text.slice(d)}));}return r.length===0||o.length===0?null:{head:H(v({},e),{content:r}),tail:H(v({},e),{content:o})}}function ew(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:H(v({},e),{blocks:n,paragraphs:n.flatMap(ds)}),tail:H(v({},e),{blocks:r,paragraphs:r.flatMap(ds)})}}function ii(e,t){for(let n of e)n.kind==="table"&&tw(n,t);}function tw(e,t){t.tables+=1;for(let n of e.rows){t.rows+=1;let r=cs(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)ii(o.blocks,t);}}function nw(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"),rw(r,t);return [...t]}function rw(e,t){for(let n of e.blocks){if(n.kind==="table"){t.add("nested-table");continue}ow(n,t);}}function ow(e,t){for(let n of e.content)iw(n,t);}function iw(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 Ac(e){return e.blocks.reduce((t,n)=>n.kind==="paragraph"?t+1:t+n.rows.reduce((r,o)=>r+o.cells.reduce((i,a)=>i+Ac(a),0),0),0)}function Lc(e){return e.blocks.reduce((t,n)=>t+aw(n),0)}function ds(e){return e.kind==="paragraph"?[e]:e.rows.flatMap(t=>t.cells.flatMap(n=>n.blocks.flatMap(ds)))}function aw(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+Lc(o),0),0)}function hn(e){return e?e.numFmt==="bullet"?"bullet":"numbered":null}function us(e,t,n=0){let r=ps(n);return {numId:sw(e,t),ilvl:r,numFmt:t==="bullet"?"bullet":Oc(r),lvlText:t==="bullet"?Hc(r):`%${r+1}.`,start:1}}function fs(e,t){var o,i;let n=ps(t),r=(o=hn(e))!=null?o:"numbered";return H(v({},e),{ilvl:n,numFmt:r==="bullet"?"bullet":Oc(n),lvlText:r==="bullet"?Hc(n):`%${n+1}.`,start:(i=e.start)!=null?i:1})}function ai(e){var n,r,o,i;let t=new Map;for(let a of _e(e)){let s=(n=a.format)==null?void 0:n.numbering;if(!((r=a.format)!=null&&r.hasNumbering)||!s)continue;let l=`${a.story}:${s.numId}:${s.ilvl}`;if(hn(s)==="bullet"){s.label=dw(s.lvlText);continue}let d=((i=t.get(l))!=null?i:((o=s.start)!=null?o:1)-1)+1;t.set(l,d),s.label=cw(d,s.numFmt,s.lvlText);}}function Dc(e){return {left:(ps(e)+1)*720,firstLine:-360}}function Fc(e,t,n){let r=new Set(t);for(let o of t){let i=ye(e,o);if(!i)continue;let a=[i.container[i.index-1],i.container[i.index+1]];for(let s of a){if((s==null?void 0:s.kind)!=="paragraph"||r.has(s.paraId))continue;let l=lw(s,n);if(l)return v({},l)}}return null}function sw(e,t){let n=new Set(_e(e).map(i=>{var a,s;return (s=(a=i.format)==null?void 0:a.numbering)==null?void 0:s.numId}).filter(i=>!!i)),r=1,o="";do o=`coco-${t}-${r}`,r+=1;while(n.has(o));return o}function lw(e,t){var r;let n=(r=e.format)!=null&&r.hasNumbering?e.format.numbering:void 0;return !n||hn(n)!==t?null:n.numId.startsWith(`coco-${t}-`)?n:null}function ps(e){return Math.max(0,Math.min(8,Math.round(e)))}function Hc(e){return ["\u2022","\u25E6","\u25AA"][e%3]}function Oc(e){return ["decimal","lowerLetter","lowerRoman"][e%3]}function dw(e){return (e==null?void 0:e.replace(/%\d+/g,"").trim())||"\u2022"}function cw(e,t,n){let r=t==="lowerLetter"?Wc(e,false):t==="upperLetter"?Wc(e,true):t==="lowerRoman"?Bc(e).toLowerCase():t==="upperRoman"?Bc(e):String(e);return n?n.replace(/%\d+/g,r):`${r}.`}function Wc(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 Bc(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 rt(e){return Ot(e)}function Hr(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 Vc(e,t,n,r,o,i=()=>Ln(e),a=()=>xw(e)){var N,A,O,W,V,ee;let s=ye(e,t);if(!s||s.container!==e.blocks)return null;let l=Math.max(1,Math.min(20,Math.trunc(r))),d=Math.max(1,Math.min(20,Math.trunc(o)));if(!Number.isFinite(r)||!Number.isFinite(o))return null;let u=s.paragraph,p=Ot([u]),f=Math.max(0,Math.min(n,Ne(u).length)),b=wn(u.content,f);u.content=b.before;let w={kind:"paragraph",paraId:i(),story:u.story,styleId:u.styleId,format:u.format?Yt(u.format):null,content:b.after},g=a(),h=Math.max(1440,((A=(N=e.pageLayout)==null?void 0:N.width)!=null?A:11906)-((W=(O=e.pageLayout)==null?void 0:O.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/d)),S={kind:"table",tableId:g,columnWidths:Array.from({length:d},()=>y),layout:{width:y*d,widthType:"dxa",alignment:"left"},borders:ms("000000"),rows:Array.from({length:l},()=>({cells:Array.from({length:d},()=>{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:ms("000000"),blocks:[pe],paragraphs:[pe]}})}))},E=[u,S,w];return s.container.splice(s.index,1,...E),{changes:[{kind:"table",op:"insert-table",tableId:g,rowIndex:0,columnIndex:0}],cursor:{paraId:S.rows[0].cells[0].paragraphs[0].paraId,offset:0},container:s.container,startIndex:s.index,beforeBlocks:p,afterBlocks:Ot(E)}}function Gc(e,t,n=()=>Ln(e)){var s,l,d;let r=Oe(e,t);if(!r||r.container!==e.blocks)return null;let o=(l=(s=r.table.rows[0])==null?void 0:s.cells[0])==null?void 0:l.paragraphs[0],i={kind:"paragraph",paraId:n(),story:(d=o==null?void 0:o.story)!=null?d:"word/document.xml",styleId:null,format:null,content:[{kind:"text",text:"",format:null}]},a=Ot([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:a,afterBlocks:Ot([i])}}function jc(e,t,n,r=()=>Ln(e)){var u,p;let o=rn(e,t);if(!o||!Hr(o.table))return null;let{table:i,rowIndex:a,cellIndex:s}=o;if(n.kind==="insert-row"){let f=a+(n.position==="after"?1:0),b=fw(o.row,r);return i.rows.splice(f,0,b),{change:{kind:"table",op:"insert-row",tableId:i.tableId,rowIndex:f,columnIndex:s},cursor:{paraId:gn((u=b.cells[s])!=null?u:b.cells[0]).paraId,offset:0}}}if(n.kind==="delete-row"){if(i.rows.length<=1)return null;i.rows.splice(a,1);let f=i.rows[Math.min(a,i.rows.length-1)];return {change:{kind:"table",op:"delete-row",tableId:i.tableId,rowIndex:a,columnIndex:s},cursor:{paraId:gn(f.cells[Math.min(s,f.cells.length-1)]).paraId,offset:0}}}if(n.kind==="insert-column"){let f=s+(n.position==="after"?1:0);for(let g of i.rows){let h=g.cells[Math.min(s,g.cells.length-1)];g.cells.splice(f,0,bs(h,r));}let b=(p=i.columnWidths[Math.min(s,i.columnWidths.length-1)])!=null?p:0;i.columnWidths.splice(f,0,b);let w=i.rows[a];return {change:{kind:"table",op:"insert-column",tableId:i.tableId,rowIndex:a,columnIndex:f},cursor:{paraId:gn(w.cells[f]).paraId,offset:0}}}if(i.rows[0].cells.length<=1)return null;for(let f of i.rows)f.cells.splice(s,1);s<i.columnWidths.length&&i.columnWidths.splice(s,1);let l=i.rows[a],d=l.cells[Math.min(s,l.cells.length-1)];return {change:{kind:"table",op:"delete-column",tableId:i.tableId,rowIndex:a,columnIndex:s},cursor:{paraId:gn(d).paraId,offset:0}}}function gs(e,t,n){var s;let r=rn(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=$c(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=(s=n.verticalAlignment)!=null?s:null),n.borderColor!==void 0){let l=$c(n.borderColor);if(n.borderColor!==null&&!l)return null;r.cell.borders=l?ms(l):uw(),i.borderColor=l?`#${l}`:null;}let a=JSON.stringify({shading:r.cell.shading,verticalAlignment:r.cell.verticalAlignment,borders:r.cell.borders});return o===a?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 tt(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),a=[];for(let s=n;s<=r;s+=1){let l=e.rows[s];if(!l)continue;let d=0;for(let u of l.cells){let p=Math.max(1,u.gridSpan),f=d+p-1;d<=i&&f>=o&&a.push({cell:u,rowIndex:s,columnIndex:d}),d+=p;}}return a}function Uc(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),a=Math.min(n.anchor.columnIndex,n.focus.columnIndex),s=Math.max(n.anchor.columnIndex,n.focus.columnIndex);if(o<0||o>=r.table.rows.length||i>=r.table.rows.length||o!==i&&a!==s)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[a]);if(g.some(N=>!N||N.gridSpan!==1||N.vMerge!=null))return null;let h=g,y=h[0],S=h.flatMap(N=>N.blocks.map(Yt)),E=S.flatMap(N=>N.kind==="paragraph"?[N]:Fr([N]));y.blocks=S,y.paragraphs=E,y.rowSpan=h.length,y.vMerge="restart";for(let N of h.slice(1)){let A=N.paragraphs[0];A&&(A.content=[{kind:"text",text:"",format:null}]),N.blocks=A?[A]:[],N.paragraphs=A?[A]:[],N.rowSpan=void 0,N.vMerge="continue";}return {change:{kind:"table",op:"merge-cells",tableId:t,rowIndex:o,columnIndex:a,endRowIndex:i},cursor:{paraId:y.paragraphs[0].paraId,offset:0}}}if(a===s)return null;let d=tt(r.table,n).filter(g=>g.rowIndex===o);if(d.length<2||d.some(g=>g.cell.gridSpan!==1||g.cell.vMerge!=null))return null;let u=d[0],p=d[d.length-1];if(u.columnIndex!==a||p.columnIndex!==s||d.length!==s-a+1)return null;let f=d.flatMap(({cell:g})=>g.blocks.map(Yt)),b=f.flatMap(g=>g.kind==="paragraph"?[g]:Fr([g]));u.cell.blocks=f,u.cell.paragraphs=b,u.cell.gridSpan=d.length;let w=l.cells.indexOf(u.cell);return w<0?null:(l.cells.splice(w,d.length,u.cell),{change:{kind:"table",op:"merge-cells",tableId:t,rowIndex:o,columnIndex:a,endColumnIndex:s},cursor:{paraId:u.cell.paragraphs[0].paraId,offset:0}})}function Kc(e,t,n,r,o=()=>Ln(e)){var f,b;let i=Oe(e,t),a=i==null?void 0:i.table.rows[n];if(!i||!a)return null;let s=0,l=a.cells.findIndex(w=>{let g=s===r;return s+=Math.max(1,w.gridSpan),g}),d=l>=0?a.cells[l]:null;if(!d)return null;if(d.vMerge==="restart"&&((f=d.rowSpan)!=null?f:1)>1){let w=n+((b=d.rowSpan)!=null?b:1)-1;if(w>=i.table.rows.length)return null;let g=i.table.rows.slice(n,w+1).map(h=>h.cells[r]);if(g.length!==d.rowSpan||g.some((h,y)=>!h||h.gridSpan!==1?true:y===0?h.vMerge!=="restart":h.vMerge!=="continue"))return null;d.rowSpan=void 0,d.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:w},cursor:{paraId:d.paragraphs[0].paraId,offset:0}}}if(d.gridSpan<=1||d.vMerge!=null||d.rowSpan&&d.rowSpan>1)return null;let u=d.gridSpan;d.gridSpan=1;let p=Array.from({length:u-1},()=>bs(d,o));return a.cells.splice(l+1,0,...p),{change:{kind:"table",op:"split-cell",tableId:t,rowIndex:n,columnIndex:r},cursor:{paraId:d.paragraphs[0].paraId,offset:0}}}function _c(e,t,n,r){let o=Oe(e,t);if(!o)return null;let i=[],a=null;for(let{cell:s}of tt(o.table,n)){let l=gn(s).paraId;a!=null||(a={paraId:l,offset:0});let d=gs(e,l,r);d&&i.push(d.change);}return a&&i.length>0?{changes:i,cursor:a}:null}function qc(e,t,n){var a;let r=Oe(e,t);if(!r)return null;let o=[],i=null;for(let{cell:s,rowIndex:l,columnIndex:d}of tt(r.table,n)){let u=gn(s);i!=null||(i={paraId:u.paraId,offset:0}),!(s.blocks.length===1&&u.content.length===1&&((a=u.content[0])==null?void 0:a.kind)==="text"&&u.content[0].text.length===0)&&(u.content=[{kind:"text",text:"",format:null}],s.blocks=[u],s.paragraphs=[u],o.push({kind:"table",op:"clear-cell",tableId:t,rowIndex:l,columnIndex:d}));}return i&&o.length>0?{changes:o,cursor:i}:null}function Xc(e,t,n,r){var u,p,f;let o=Oe(e,t);if(!o||r.length===0||r.every(b=>b.length===0))return null;let i=r.length,a=Math.max(0,...r.map(b=>b.length)),s={anchor:n,focus:{rowIndex:n.rowIndex+i-1,columnIndex:n.columnIndex+a-1}},l=[],d=null;for(let{cell:b,rowIndex:w,columnIndex:g}of tt(o.table,s)){let h=(u=r[w-n.rowIndex])==null?void 0:u[g-n.columnIndex];if(h===void 0)continue;let y=gn(b);if(d!=null||(d={paraId:y.paraId,offset:h.length}),b.paragraphs.map(N=>Ne(N)).join(`
13
- `)===h&&b.blocks.length===1)continue;let E=(f=(p=y.content.find(N=>N.kind==="text"))==null?void 0:p.format)!=null?f:null;y.content=[{kind:"text",text:h,format:E?Yt(E):null}],b.blocks=[y],b.paragraphs=[y],l.push({kind:"table",op:"replace-cell",tableId:t,rowIndex:w,columnIndex:g,text:h});}return d&&l.length>0?{changes:l,cursor:d}:null}function Yc(e,t,n,r){var d;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)),a={anchor:n,focus:{rowIndex:n.rowIndex+r.length-1,columnIndex:n.columnIndex+i-1}},s=[],l=null;for(let{cell:u,rowIndex:p,columnIndex:f}of tt(o.table,a)){let b=(d=r[p-n.rowIndex])==null?void 0:d[f-n.columnIndex];if(!b)continue;let w=gu(e,b.blocks),g=Fr(w);g.length!==0&&(u.blocks=w,u.paragraphs=g,Dr(u,"margin",b.format.margin),Dr(u,"borders",b.format.borders),Dr(u,"shading",b.format.shading),Dr(u,"verticalAlignment",b.format.verticalAlignment),Dr(u,"noWrap",b.format.noWrap),l!=null||(l={paraId:g[0].paraId,offset:Ne(g[0]).length}),s.push({kind:"table",op:"replace-cell",tableId:t,rowIndex:p,columnIndex:f,cellSnapshot:Yt(u)}));}return l&&s.length>0?{changes:s,cursor:l}:null}function Dr(e,t,n){n===void 0?delete e[t]:e[t]=Yt(n);}function $c(e){if(e===null)return null;let t=e.trim().replace(/^#/,"").toUpperCase();return /^[0-9A-F]{6}$/.test(t)?t:null}function ms(e){let t={val:"single",color:e,size:4};return {top:v({},t),right:v({},t),bottom:v({},t),left:v({},t)}}function uw(){let e={val:"nil"};return {top:v({},e),right:v({},e),bottom:v({},e),left:v({},e)}}function fw(e,t){let o=e,{cells:n}=o,r=Mn(o,["cells"]);return H(v({},Yt(r)),{cells:n.map(i=>bs(i,t))})}function bs(e,t){let s=e,{blocks:n,paragraphs:r}=s,o=Mn(s,["blocks","paragraphs"]),i=gn(e),a={kind:"paragraph",paraId:t(),story:i.story,styleId:i.styleId,format:i.format?Yt(i.format):null,content:[{kind:"text",text:"",format:null}]};return H(v({},Yt(o)),{gridSpan:1,blocks:[a],paragraphs:[a]})}function gn(e){let t=e.paragraphs[0];if(!t)throw new Error("Native table cell must contain at least one paragraph");return t}function Yt(e){return JSON.parse(JSON.stringify(e))}function on(e,t,n,r){let o=Z(e,t);return !o||r.length===0?null:(o.content=pu(o.content,n,r),{kind:"text",op:"insert",paraId:t,offset:n,text:r})}function Zc(e,t,n,r,o={}){var u;let i=Z(e,t);if(!i||!r)return null;let a=(u=o.drawingId)!=null?u:hw(e),s=li(o.width),l=li(o.height),d=wn(i.content,n);return i.content=$e([...d.before,v(v({kind:"image",drawingId:a,src:r},s?{width:s}:{}),l?{height:l}:{}),...d.after]),v(v({kind:"image",op:"insert",paraId:t,offset:n,drawingId:a,src:r},s?{width:s}:{}),l?{height:l}:{})}function Jc(e,t,n){let r=Z(e,t);if(!r)return null;let o=Math.max(0,Math.min(n,Ne(r).length)),i=wn(r.content,o);return r.content=$e([...i.before,{kind:"pageBreak"},...i.after]),{kind:"page-break",op:"insert",paraId:t,offset:o}}function ci(e,t,n){let r=Z(e,t);if(!r||n<0)return false;let o=0;for(let i of r.content){let a=ze(i);if(n>=o&&n<o+a)return i.kind==="pageBreak";o+=a;}return false}function Qc(e,t,n,r){let o=Z(e,t),i=Mt(n,r);if(!o||i.from===i.to)return false;let a=0;for(let s of o.content){let l=ze(s);if(s.kind==="pageBreak"&&i.from<a+l&&i.to>a)return true;a+=l;}return false}function eu(e,t,n,r){let o=Z(e,t),i=o==null?void 0:o.content.find(d=>d.kind==="image"&&d.drawingId===n),a=li(r.width),s=li(r.height);if(!o||!i||!a||!s||i.width===a&&i.height===s)return null;i.width=a,i.height=s;let l=0;for(let d of o.content){if(d===i)break;l+=ze(d);}return {kind:"image",op:"resize",paraId:t,offset:l,drawingId:n,width:a,height:s}}function Or(e,t,n){let r=ye(e,t);if(!r)return null;let{paragraph:o}=r;if(n>0)return mw(o,n);let i=r.previous;return i?(i.content=$e([...i.content,...o.content]),r.remove(),{kind:"block",op:"merge",paraId:i.paraId}):null}function $r(e,t,n){let r=ye(e,t);if(!r)return null;let{paragraph:o}=r;if(n<si(o.content))return mu(o,n);let i=r.container[r.index+1];return (i==null?void 0:i.kind)!=="paragraph"?null:(o.content=$e([...o.content,...i.content]),r.container.splice(r.index+1,1),{kind:"block",op:"merge",paraId:o.paraId})}function bn(e,t,n,r){let o=Z(e,t),i=Mt(n,r);if(!o||i.from===i.to)return [];let a=gw(o,i.from,i.to);return o.content=a.content,a.changes}function ui(e,t,n){var b;if(t.paraId===n.paraId)return bn(e,t.paraId,t.offset,n.offset);let r=ye(e,t.paraId),o=ye(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(w=>w.kind!=="text")||i.end.paragraph.content.some(w=>w.kind!=="text"))return [];if(i.start.container.slice(i.start.index,i.end.index+1).some(w=>w.kind!=="paragraph"))return [];for(let w=i.start.index+1;w<i.end.index;w+=1){let g=i.start.container[w];if((g==null?void 0:g.kind)!=="paragraph"||g.content.some(h=>h.kind!=="text"))return []}let a=[],s=Ne(i.start.paragraph),l=Ne(i.end.paragraph),d=Math.max(0,Math.min(i.startOffset,s.length)),u=Math.max(0,Math.min(i.endOffset,l.length)),p=`${s.slice(0,d)}${l.slice(u)}`,f=i.end.index-i.start.index;for(let w=i.end.index;w>i.start.index;w-=1){let g=i.start.container[w];if((g==null?void 0:g.kind)==="paragraph"){if(g===i.end.paragraph&&u<l.length)a.push({kind:"text",op:"delete",paraId:g.paraId,offset:0,text:l.slice(0,u)});else {let h=Ne(g);h.length>0&&a.push({kind:"text",op:"delete",paraId:g.paraId,offset:0,text:h});}(b=ye(e,g.paraId))==null||b.remove();}}d<s.length&&a.push({kind:"text",op:"delete",paraId:i.start.paragraph.paraId,offset:d,text:s.slice(d)});for(let w=0;w<f;w+=1)a.push({kind:"block",op:"merge",paraId:i.start.paragraph.paraId});return i.start.paragraph.content=p.length>0?[{kind:"text",text:p,format:bu(i.start.paragraph.content,d)}]:[],a}function tu(e,t,n,r){let o=ye(e,t.paraId),i=ye(e,n.paraId);if(!o||!i||o.container!==e.blocks||i.container!==e.blocks)return null;let a=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(a.start.index===a.end.index||a.start.paragraph.content.some(w=>w.kind!=="text")||a.end.paragraph.content.some(w=>w.kind!=="text"))return null;let s=e.blocks.slice(a.start.index,a.end.index+1);if(!s.slice(1,-1).some(w=>w.kind==="table"||w.content.some(g=>g.kind!=="text")))return null;let l=Ot(s),d=Ne(a.start.paragraph).length,u=Ne(a.end.paragraph).length,p=Math.max(0,Math.min(a.startOffset,d)),f=Math.max(0,Math.min(a.endOffset,u)),b=[...bn(e,a.end.paragraph.paraId,0,f),...bn(e,a.start.paragraph.paraId,p,d)];if(a.start.paragraph.content=$e([...a.start.paragraph.content,...a.end.paragraph.content]),e.blocks.splice(a.start.index+1,a.end.index-a.start.index),r.length>0){let w=on(e,a.start.paragraph.paraId,p,r);w&&b.push(w);}return b.push({kind:"structure",op:"delete-range",startParaId:a.start.paragraph.paraId,endParaId:a.end.paragraph.paraId,deletedBlockIds:s.slice(1).map(hu)}),{changes:b,cursor:{paraId:a.start.paragraph.paraId,offset:p+r.length},container:e.blocks,startIndex:a.start.index,beforeBlocks:l,afterBlocks:Ot([a.start.paragraph])}}function ws(e,t,n){let r=bw(e,t,n);if(!r||r.blocks.length<2&&!ww(r.blocks))return null;let o=Ot(r.blocks),i=o[0],a=o[o.length-1];return (i==null?void 0:i.kind)!=="paragraph"||(a==null?void 0:a.kind)!=="paragraph"?null:(i.content=wn(i.content,r.startOffset).after,a.content=wn(a.content,r.endOffset).before,o)}function nu(e,t,n,r){if(t.paraId!==n.paraId||r.length===0)return null;let o=ye(e,t.paraId);if(!o||o.container!==e.blocks)return null;let i=r[0],a=r[r.length-1];if((i==null?void 0:i.kind)!=="paragraph"||(a==null?void 0:a.kind)!=="paragraph")return null;let s=Ot([o.paragraph]),l=Ne(o.paragraph).length,d=Math.max(0,Math.min(t.offset,n.offset,l)),u=Math.max(d,Math.min(Math.max(t.offset,n.offset),l)),p=wn(o.paragraph.content,d).before,f=wn(o.paragraph.content,u).after,b=gu(e,r),w=b[0],g=b[b.length-1];if((w==null?void 0:w.kind)!=="paragraph"||(g==null?void 0:g.kind)!=="paragraph")return null;p.length===0&&f.length===0&&(o.paragraph.styleId=w.styleId,o.paragraph.format=w.format?Yt(w.format):null),o.paragraph.content=$e([...p,...w.content]);let y={paraId:o.paragraph.paraId,offset:si(o.paragraph.content)},S=[o.paragraph];b.length===1?o.paragraph.content=$e([...o.paragraph.content,...f]):(g.content=$e([...g.content,...f]),S.push(...b.slice(1)),y={paraId:g.paraId,offset:si(g.content)-si(f)}),e.blocks.splice(o.index,1,...S);let E=Ot(S);return {changes:[{kind:"structure",op:"insert-range",paraId:o.paragraph.paraId,insertedBlockIds:S.slice(1).map(hu)}],cursor:y,container:e.blocks,startIndex:o.index,beforeBlocks:s,afterBlocks:E}}function zr(e,t,n,r,o){let i=Mt(n,r),a=bn(e,t,i.from,i.to),s=on(e,t,i.from,o);return s?[...a,s]:a}function ru(e,t,n,r){if(t.paraId===n.paraId)return zr(e,t.paraId,t.offset,n.offset,r);let o=ye(e,t.paraId),i=ye(e,n.paraId);if(!o||!i||o.container!==i.container)return [];let a=o.index<i.index?t:n,s=ui(e,t,n);if(s.length===0||r.length===0)return s;let l=on(e,a.paraId,a.offset,r);return l?[...s,l]:s}function xs(e,t,n,r){var w,g,h,y,S,E,N,A;let o=ye(e,t.paraId),i=ye(e,n.paraId);if(!o||!i||o.container!==i.container)return null;let a=o.index<i.index||o.index===i.index&&t.offset<=n.offset?t:n,s=ui(e,t,n),l=Z(e,a.paraId);if(!l||l.content.some(O=>O.kind!=="text"))return null;let d=r.replace(/\r\n?/g,`
12
+ </table>`}function ri(e){return is(e).replace(/\t/g,"&#9;").replace(/\r\n|\r|\n/g,"<br>")}function is(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function Xt(e){return is(e).replace(/"/g,"&quot;")}function _b(e,t,n){return Math.min(n,Math.max(t,Math.floor(e)))}function ss(e){return O(v(v({kind:"word"},e.defaults?{defaults:e.defaults}:{}),e.pageLayout?{pageLayout:e.pageLayout}:{}),{sections:e.sections,headers:e.headers.map(Lc),footers:e.footers.map(Lc),blocks:e.blocks.map(t=>ds(t))})}function Z(e,t){var n,r;return (r=(n=ve(e,t))==null?void 0:n.paragraph)!=null?r:null}function ls(e,t){var r,o;let n=ve(e,t);return (o=(r=n==null?void 0:n.previous)==null?void 0:r.paraId)!=null?o:null}function ve(e,t){var n,r;return (r=(n=as(e.blocks,t))!=null?n:e.headers.reduce((o,i)=>o!=null?o:as(i.blocks,t),null))!=null?r:e.footers.reduce((o,i)=>o!=null?o:as(i.blocks,t),null)}function rn(e,t){var n,r;return (r=(n=ii(e.blocks,t))!=null?n:e.headers.reduce((o,i)=>o!=null?o:ii(i.blocks,t),null))!=null?r:e.footers.reduce((o,i)=>o!=null?o:ii(i.blocks,t),null)}function Oe(e,t){var n,r;return (r=(n=oi(e.blocks,t))!=null?n:e.headers.reduce((o,i)=>o!=null?o:oi(i.blocks,t),null))!=null?r:e.footers.reduce((o,i)=>o!=null?o:oi(i.blocks,t),null)}function oi(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 a=oi(i.blocks,t);if(a)return a}}}return null}function ii(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],a=0;for(let s=0;s<i.cells.length;s+=1){let l=i.cells[s],d=ii(l.blocks,t);if(d)return d;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:s,columnIndex:a};a+=Math.max(1,l.gridSpan);}}}return null}function as(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=ew(r,t);if(o)return o}}return null}function _e(e){return [...Fr(e.blocks),...e.headers.flatMap(t=>Fr(t.blocks)),...e.footers.flatMap(t=>Fr(t.blocks))]}function Fr(e){return e.flatMap(t=>t.kind==="paragraph"?[t]:t.rows.flatMap(n=>n.cells.flatMap(r=>Fr(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 Bn(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 ds(e){return e.type==="table"?O(v(v(O(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=>O(v(v(v({},t.height?{height:t.height}:{}),t.isHeader?{isHeader:true}:{}),t.cantSplit?{cantSplit:true}:{}),{cells:t.cells.map(n=>qb(n))}))}):Wc(e)}function Lc(e){return {kind:e.kind,partName:e.partName,blocks:e.blocks.map(t=>ds(t))}}function qb(e){var o;let n=((o=e.blocks)!=null?o:e.paragraphs).map(i=>ds(i)),r={gridSpan:e.gridSpan,blocks:n,paragraphs:Fr(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.widthType!==void 0&&(r.widthType=e.widthType),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 Wc(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"?Zb(o,t):o.kind==="revision"?Yb(o):o.kind==="field"?Xb(o):o.kind==="image"?Jb(o):o.kind==="drawing"?Qb(o):o.kind==="placeholder"&&o.placeholderKind==="pageBreak"?[{kind:"pageBreak"}]:[])}}function Xb(e){var t;return [O(v({kind:"field",fieldKind:e.fieldKind,instruction:e.instruction},e.cachedText!==void 0?{cachedText:e.cachedText}:{}),{format:(t=e.format)!=null?t:null})]}function Yb(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 Zb(e,t){var o,i,a;if(e.text.length===0)return [];let n=[],r=e.from;for(let s of t){let l=Math.max(e.from,s.from),d=Math.min(e.to,s.to);d<=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(O(v({kind:"text",text:e.text.slice(l-e.from,d-e.from),format:(i=e.format)!=null?i:null},e.hyperlink?{hyperlink:v({},e.hyperlink)}:{}),{marks:[{kind:"comment",id:s.id,commentId:s.commentId,author:s.author,date:s.date,body:s.body}]})),r=d);}return r<e.to&&n.push(v({kind:"text",text:e.text.slice(r-e.from),format:(a=e.format)!=null?a:null},e.hyperlink?{hyperlink:v({},e.hyperlink)}:{})),n}function Jb(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 Qb(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=>Wc(n))),[t]}function ew(e,t){var n;for(let r of e.rows)for(let o of r.cells){let i=o.paragraphs.findIndex(s=>s.paraId===t),a=o.blocks.findIndex(s=>s.kind==="paragraph"&&s.paraId===t);if(i>=0&&a>=0)return {paragraph:o.paragraphs[i],previous:(n=o.paragraphs[i-1])!=null?n:null,container:o.blocks,index:a,insertAfter(s){o.paragraphs.splice(i+1,0,s),o.blocks.splice(a+1,0,s);},remove(){o.paragraphs.splice(i,1),o.blocks.splice(a,1);}}}return null}function us(e){let t=iw(e),n=e.cells.reduce((o,i)=>o+Bc(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 DE(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}};ai(e.blocks,t);for(let n of e.headers)ai(n.blocks,t);for(let n of e.footers)ai(n.blocks,t);return t}function FE(e,t){if(us(e).kind!=="block-fragmentable"||t.cellBlockCounts.length!==e.cells.length)return null;let r=[],o=[],i=false,a=false;for(let s=0;s<e.cells.length;s+=1){let l=e.cells[s],d=rw(l,t.cellBlockCounts[s]);if(!d)return null;r.push(d.head),o.push(d.tail),i||(i=d.head.blocks.length>0),a||(a=d.tail.blocks.length>0);}return !i||!a?null:{head:O(v({},e),{height:void 0,cells:r}),tail:O(v({},e),{height:void 0,cells:o})}}function HE(e,t){if(us(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 a=tw(e.cells[i],t.cellTextOffsets[i]);if(!a)return null;r.push(a.head),o.push(a.tail);}return {head:O(v({},e),{height:void 0,cells:r}),tail:O(v({},e),{height:void 0,cells:o})}}function tw(e,t){if(e.blocks.length!==1)return null;let n=e.blocks[0];if(!n||n.kind!=="paragraph")return null;let r=nw(n,t);return r?{head:O(v({},e),{blocks:[r.head],paragraphs:[r.head]}),tail:O(v({},e),{blocks:[r.tail],paragraphs:[r.tail]})}:null}function nw(e,t){let n=e.content.reduce((a,s)=>a+(s.kind==="text"?s.text.length:0),0);if(!Number.isInteger(t)||t<=0||t>=n)return null;let r=[],o=[],i=0;for(let a of e.content){if(a.kind!=="text")return null;let s=i,l=i+a.text.length;if(i=l,l<=t){r.push(a);continue}if(s>=t){o.push(a);continue}let d=t-s;r.push(O(v({},a),{text:a.text.slice(0,d)})),o.push(O(v({},a),{text:a.text.slice(d)}));}return r.length===0||o.length===0?null:{head:O(v({},e),{content:r}),tail:O(v({},e),{content:o})}}function rw(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:O(v({},e),{blocks:n,paragraphs:n.flatMap(cs)}),tail:O(v({},e),{blocks:r,paragraphs:r.flatMap(cs)})}}function ai(e,t){for(let n of e)n.kind==="table"&&ow(n,t);}function ow(e,t){t.tables+=1;for(let n of e.rows){t.rows+=1;let r=us(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)ai(o.blocks,t);}}function iw(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"),aw(r,t);return [...t]}function aw(e,t){for(let n of e.blocks){if(n.kind==="table"){t.add("nested-table");continue}sw(n,t);}}function sw(e,t){for(let n of e.content)lw(n,t);}function lw(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 Bc(e){return e.blocks.reduce((t,n)=>n.kind==="paragraph"?t+1:t+n.rows.reduce((r,o)=>r+o.cells.reduce((i,a)=>i+Bc(a),0),0),0)}function Dc(e){return e.blocks.reduce((t,n)=>t+dw(n),0)}function cs(e){return e.kind==="paragraph"?[e]:e.rows.flatMap(t=>t.cells.flatMap(n=>n.blocks.flatMap(cs)))}function dw(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 hn(e){return e?e.numFmt==="bullet"?"bullet":"numbered":null}function fs(e,t,n=0){let r=ms(n);return {numId:cw(e,t),ilvl:r,numFmt:t==="bullet"?"bullet":Vc(r),lvlText:t==="bullet"?zc(r):`%${r+1}.`,start:1}}function ps(e,t){var o,i;let n=ms(t),r=(o=hn(e))!=null?o:"numbered";return O(v({},e),{ilvl:n,numFmt:r==="bullet"?"bullet":Vc(n),lvlText:r==="bullet"?zc(n):`%${n+1}.`,start:(i=e.start)!=null?i:1})}function si(e){var n,r,o,i;let t=new Map;for(let a of _e(e)){let s=(n=a.format)==null?void 0:n.numbering;if(!((r=a.format)!=null&&r.hasNumbering)||!s)continue;let l=`${a.story}:${s.numId}:${s.ilvl}`;if(hn(s)==="bullet"){s.label=fw(s.lvlText);continue}let d=((i=t.get(l))!=null?i:((o=s.start)!=null?o:1)-1)+1;t.set(l,d),s.label=pw(d,s.numFmt,s.lvlText);}}function Oc(e){return {left:(ms(e)+1)*720,firstLine:-360}}function $c(e,t,n){let r=new Set(t);for(let o of t){let i=ve(e,o);if(!i)continue;let a=[i.container[i.index-1],i.container[i.index+1]];for(let s of a){if((s==null?void 0:s.kind)!=="paragraph"||r.has(s.paraId))continue;let l=uw(s,n);if(l)return v({},l)}}return null}function cw(e,t){let n=new Set(_e(e).map(i=>{var a,s;return (s=(a=i.format)==null?void 0:a.numbering)==null?void 0:s.numId}).filter(i=>!!i)),r=1,o="";do o=`coco-${t}-${r}`,r+=1;while(n.has(o));return o}function uw(e,t){var r;let n=(r=e.format)!=null&&r.hasNumbering?e.format.numbering:void 0;return !n||hn(n)!==t?null:n.numId.startsWith(`coco-${t}-`)?n:null}function ms(e){return Math.max(0,Math.min(8,Math.round(e)))}function zc(e){return ["\u2022","\u25E6","\u25AA"][e%3]}function Vc(e){return ["decimal","lowerLetter","lowerRoman"][e%3]}function fw(e){return (e==null?void 0:e.replace(/%\d+/g,"").trim())||"\u2022"}function pw(e,t,n){let r=t==="lowerLetter"?Fc(e,false):t==="upperLetter"?Fc(e,true):t==="lowerRoman"?Hc(e).toLowerCase():t==="upperRoman"?Hc(e):String(e);return n?n.replace(/%\d+/g,r):`${r}.`}function Fc(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 rt(e){return Ot(e)}function $r(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 Uc(e,t,n,r,o,i=()=>Bn(e),a=()=>Sw(e)){var I,A,F,L,V,ee;let s=ve(e,t);if(!s||s.container!==e.blocks)return null;let l=Math.max(1,Math.min(20,Math.trunc(r))),d=Math.max(1,Math.min(20,Math.trunc(o)));if(!Number.isFinite(r)||!Number.isFinite(o))return null;let u=s.paragraph,f=Ot([u]),p=Math.max(0,Math.min(n,Te(u).length)),b=wn(u.content,p);u.content=b.before;let w={kind:"paragraph",paraId:i(),story:u.story,styleId:u.styleId,format:u.format?Yt(u.format):null,content:b.after},g=a(),h=Math.max(1440,((A=(I=e.pageLayout)==null?void 0:I.width)!=null?A:11906)-((L=(F=e.pageLayout)==null?void 0:F.margin.left)!=null?L:1440)-((ee=(V=e.pageLayout)==null?void 0:V.margin.right)!=null?ee:1440)),y=Math.max(360,Math.floor(h/d)),S={kind:"table",tableId:g,columnWidths:Array.from({length:d},()=>y),layout:{width:y*d,widthType:"dxa",alignment:"left"},borders:hs("000000"),rows:Array.from({length:l},()=>({cells:Array.from({length:d},()=>{let fe={kind:"paragraph",paraId:i(),story:u.story,styleId:null,format:null,content:[{kind:"text",text:"",format:null}]};return {gridSpan:1,width:y,borders:hs("000000"),blocks:[fe],paragraphs:[fe]}})}))},k=[u,S,w];return s.container.splice(s.index,1,...k),{changes:[{kind:"table",op:"insert-table",tableId:g,rowIndex:0,columnIndex:0}],cursor:{paraId:S.rows[0].cells[0].paragraphs[0].paraId,offset:0},container:s.container,startIndex:s.index,beforeBlocks:f,afterBlocks:Ot(k)}}function Kc(e,t,n=()=>Bn(e)){var s,l,d;let r=Oe(e,t);if(!r||r.container!==e.blocks)return null;let o=(l=(s=r.table.rows[0])==null?void 0:s.cells[0])==null?void 0:l.paragraphs[0],i={kind:"paragraph",paraId:n(),story:(d=o==null?void 0:o.story)!=null?d:"word/document.xml",styleId:null,format:null,content:[{kind:"text",text:"",format:null}]},a=Ot([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:a,afterBlocks:Ot([i])}}function _c(e,t,n,r=()=>Bn(e)){var u,f;let o=rn(e,t);if(!o||!$r(o.table))return null;let{table:i,rowIndex:a,cellIndex:s}=o;if(n.kind==="insert-row"){let p=a+(n.position==="after"?1:0),b=hw(o.row,r);return i.rows.splice(p,0,b),{change:{kind:"table",op:"insert-row",tableId:i.tableId,rowIndex:p,columnIndex:s},cursor:{paraId:gn((u=b.cells[s])!=null?u:b.cells[0]).paraId,offset:0}}}if(n.kind==="delete-row"){if(i.rows.length<=1)return null;i.rows.splice(a,1);let p=i.rows[Math.min(a,i.rows.length-1)];return {change:{kind:"table",op:"delete-row",tableId:i.tableId,rowIndex:a,columnIndex:s},cursor:{paraId:gn(p.cells[Math.min(s,p.cells.length-1)]).paraId,offset:0}}}if(n.kind==="insert-column"){let p=s+(n.position==="after"?1:0);for(let g of i.rows){let h=g.cells[Math.min(s,g.cells.length-1)];g.cells.splice(p,0,ws(h,r));}let b=(f=i.columnWidths[Math.min(s,i.columnWidths.length-1)])!=null?f:0;i.columnWidths.splice(p,0,b);let w=i.rows[a];return {change:{kind:"table",op:"insert-column",tableId:i.tableId,rowIndex:a,columnIndex:p},cursor:{paraId:gn(w.cells[p]).paraId,offset:0}}}if(i.rows[0].cells.length<=1)return null;for(let p of i.rows)p.cells.splice(s,1);s<i.columnWidths.length&&i.columnWidths.splice(s,1);let l=i.rows[a],d=l.cells[Math.min(s,l.cells.length-1)];return {change:{kind:"table",op:"delete-column",tableId:i.tableId,rowIndex:a,columnIndex:s},cursor:{paraId:gn(d).paraId,offset:0}}}function bs(e,t,n){var s;let r=rn(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=(s=n.verticalAlignment)!=null?s:null),n.borderColor!==void 0){let l=Gc(n.borderColor);if(n.borderColor!==null&&!l)return null;r.cell.borders=l?hs(l):mw(),i.borderColor=l?`#${l}`:null;}let a=JSON.stringify({shading:r.cell.shading,verticalAlignment:r.cell.verticalAlignment,borders:r.cell.borders});return o===a?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 tt(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),a=[];for(let s=n;s<=r;s+=1){let l=e.rows[s];if(!l)continue;let d=0;for(let u of l.cells){let f=Math.max(1,u.gridSpan),p=d+f-1;d<=i&&p>=o&&a.push({cell:u,rowIndex:s,columnIndex:d}),d+=f;}}return a}function qc(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),a=Math.min(n.anchor.columnIndex,n.focus.columnIndex),s=Math.max(n.anchor.columnIndex,n.focus.columnIndex);if(o<0||o>=r.table.rows.length||i>=r.table.rows.length||o!==i&&a!==s)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(I=>I.cells[a]);if(g.some(I=>!I||I.gridSpan!==1||I.vMerge!=null))return null;let h=g,y=h[0],S=h.flatMap(I=>I.blocks.map(Yt)),k=S.flatMap(I=>I.kind==="paragraph"?[I]:Or([I]));y.blocks=S,y.paragraphs=k,y.rowSpan=h.length,y.vMerge="restart";for(let I of h.slice(1)){let A=I.paragraphs[0];A&&(A.content=[{kind:"text",text:"",format:null}]),I.blocks=A?[A]:[],I.paragraphs=A?[A]:[],I.rowSpan=void 0,I.vMerge="continue";}return {change:{kind:"table",op:"merge-cells",tableId:t,rowIndex:o,columnIndex:a,endRowIndex:i},cursor:{paraId:y.paragraphs[0].paraId,offset:0}}}if(a===s)return null;let d=tt(r.table,n).filter(g=>g.rowIndex===o);if(d.length<2||d.some(g=>g.cell.gridSpan!==1||g.cell.vMerge!=null))return null;let u=d[0],f=d[d.length-1];if(u.columnIndex!==a||f.columnIndex!==s||d.length!==s-a+1)return null;let p=d.flatMap(({cell:g})=>g.blocks.map(Yt)),b=p.flatMap(g=>g.kind==="paragraph"?[g]:Or([g]));u.cell.blocks=p,u.cell.paragraphs=b,u.cell.gridSpan=d.length;let w=l.cells.indexOf(u.cell);return w<0?null:(l.cells.splice(w,d.length,u.cell),{change:{kind:"table",op:"merge-cells",tableId:t,rowIndex:o,columnIndex:a,endColumnIndex:s},cursor:{paraId:u.cell.paragraphs[0].paraId,offset:0}})}function Xc(e,t,n,r,o=()=>Bn(e)){var p,b;let i=Oe(e,t),a=i==null?void 0:i.table.rows[n];if(!i||!a)return null;let s=0,l=a.cells.findIndex(w=>{let g=s===r;return s+=Math.max(1,w.gridSpan),g}),d=l>=0?a.cells[l]:null;if(!d)return null;if(d.vMerge==="restart"&&((p=d.rowSpan)!=null?p:1)>1){let w=n+((b=d.rowSpan)!=null?b:1)-1;if(w>=i.table.rows.length)return null;let g=i.table.rows.slice(n,w+1).map(h=>h.cells[r]);if(g.length!==d.rowSpan||g.some((h,y)=>!h||h.gridSpan!==1?true:y===0?h.vMerge!=="restart":h.vMerge!=="continue"))return null;d.rowSpan=void 0,d.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:w},cursor:{paraId:d.paragraphs[0].paraId,offset:0}}}if(d.gridSpan<=1||d.vMerge!=null||d.rowSpan&&d.rowSpan>1)return null;let u=d.gridSpan;d.gridSpan=1;let f=Array.from({length:u-1},()=>ws(d,o));return a.cells.splice(l+1,0,...f),{change:{kind:"table",op:"split-cell",tableId:t,rowIndex:n,columnIndex:r},cursor:{paraId:d.paragraphs[0].paraId,offset:0}}}function Yc(e,t,n,r){let o=Oe(e,t);if(!o)return null;let i=[],a=null;for(let{cell:s}of tt(o.table,n)){let l=gn(s).paraId;a!=null||(a={paraId:l,offset:0});let d=bs(e,l,r);d&&i.push(d.change);}return a&&i.length>0?{changes:i,cursor:a}:null}function Zc(e,t,n){var a;let r=Oe(e,t);if(!r)return null;let o=[],i=null;for(let{cell:s,rowIndex:l,columnIndex:d}of tt(r.table,n)){let u=gn(s);i!=null||(i={paraId:u.paraId,offset:0}),!(s.blocks.length===1&&u.content.length===1&&((a=u.content[0])==null?void 0:a.kind)==="text"&&u.content[0].text.length===0)&&(u.content=[{kind:"text",text:"",format:null}],s.blocks=[u],s.paragraphs=[u],o.push({kind:"table",op:"clear-cell",tableId:t,rowIndex:l,columnIndex:d}));}return i&&o.length>0?{changes:o,cursor:i}:null}function Jc(e,t,n,r){var u,f,p;let o=Oe(e,t);if(!o||r.length===0||r.every(b=>b.length===0))return null;let i=r.length,a=Math.max(0,...r.map(b=>b.length)),s={anchor:n,focus:{rowIndex:n.rowIndex+i-1,columnIndex:n.columnIndex+a-1}},l=[],d=null;for(let{cell:b,rowIndex:w,columnIndex:g}of tt(o.table,s)){let h=(u=r[w-n.rowIndex])==null?void 0:u[g-n.columnIndex];if(h===void 0)continue;let y=gn(b);if(d!=null||(d={paraId:y.paraId,offset:h.length}),b.paragraphs.map(I=>Te(I)).join(`
13
+ `)===h&&b.blocks.length===1)continue;let k=(p=(f=y.content.find(I=>I.kind==="text"))==null?void 0:f.format)!=null?p:null;y.content=[{kind:"text",text:h,format:k?Yt(k):null}],b.blocks=[y],b.paragraphs=[y],l.push({kind:"table",op:"replace-cell",tableId:t,rowIndex:w,columnIndex:g,text:h});}return d&&l.length>0?{changes:l,cursor:d}:null}function Qc(e,t,n,r){var d;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)),a={anchor:n,focus:{rowIndex:n.rowIndex+r.length-1,columnIndex:n.columnIndex+i-1}},s=[],l=null;for(let{cell:u,rowIndex:f,columnIndex:p}of tt(o.table,a)){let b=(d=r[f-n.rowIndex])==null?void 0:d[p-n.columnIndex];if(!b)continue;let w=xu(e,b.blocks),g=Or(w);g.length!==0&&(u.blocks=w,u.paragraphs=g,Hr(u,"margin",b.format.margin),Hr(u,"borders",b.format.borders),Hr(u,"shading",b.format.shading),Hr(u,"verticalAlignment",b.format.verticalAlignment),Hr(u,"noWrap",b.format.noWrap),l!=null||(l={paraId:g[0].paraId,offset:Te(g[0]).length}),s.push({kind:"table",op:"replace-cell",tableId:t,rowIndex:f,columnIndex:p,cellSnapshot:Yt(u)}));}return l&&s.length>0?{changes:s,cursor:l}:null}function Hr(e,t,n){n===void 0?delete e[t]:e[t]=Yt(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 hs(e){let t={val:"single",color:e,size:4};return {top:v({},t),right:v({},t),bottom:v({},t),left:v({},t)}}function mw(){let e={val:"nil"};return {top:v({},e),right:v({},e),bottom:v({},e),left:v({},e)}}function hw(e,t){let o=e,{cells:n}=o,r=Ln(o,["cells"]);return O(v({},Yt(r)),{cells:n.map(i=>ws(i,t))})}function ws(e,t){let s=e,{blocks:n,paragraphs:r}=s,o=Ln(s,["blocks","paragraphs"]),i=gn(e),a={kind:"paragraph",paraId:t(),story:i.story,styleId:i.styleId,format:i.format?Yt(i.format):null,content:[{kind:"text",text:"",format:null}]};return O(v({},Yt(o)),{gridSpan:1,blocks:[a],paragraphs:[a]})}function gn(e){let t=e.paragraphs[0];if(!t)throw new Error("Native table cell must contain at least one paragraph");return t}function Yt(e){return JSON.parse(JSON.stringify(e))}function on(e,t,n,r){let o=Z(e,t);return !o||r.length===0?null:(o.content=gu(o.content,n,r),{kind:"text",op:"insert",paraId:t,offset:n,text:r})}function eu(e,t,n,r,o={}){var u;let i=Z(e,t);if(!i||!r)return null;let a=(u=o.drawingId)!=null?u:ww(e),s=di(o.width),l=di(o.height),d=wn(i.content,n);return i.content=$e([...d.before,v(v({kind:"image",drawingId:a,src:r},s?{width:s}:{}),l?{height:l}:{}),...d.after]),v(v({kind:"image",op:"insert",paraId:t,offset:n,drawingId:a,src:r},s?{width:s}:{}),l?{height:l}:{})}function tu(e,t,n){let r=Z(e,t);if(!r)return null;let o=Math.max(0,Math.min(n,Te(r).length)),i=wn(r.content,o);return r.content=$e([...i.before,{kind:"pageBreak"},...i.after]),{kind:"page-break",op:"insert",paraId:t,offset:o}}function ui(e,t,n){let r=Z(e,t);if(!r||n<0)return false;let o=0;for(let i of r.content){let a=Ve(i);if(n>=o&&n<o+a)return i.kind==="pageBreak";o+=a;}return false}function nu(e,t,n,r){let o=Z(e,t),i=Mt(n,r);if(!o||i.from===i.to)return false;let a=0;for(let s of o.content){let l=Ve(s);if(s.kind==="pageBreak"&&i.from<a+l&&i.to>a)return true;a+=l;}return false}function ru(e,t,n,r){let o=Z(e,t),i=o==null?void 0:o.content.find(d=>d.kind==="image"&&d.drawingId===n),a=di(r.width),s=di(r.height);if(!o||!i||!a||!s||i.width===a&&i.height===s)return null;i.width=a,i.height=s;let l=0;for(let d of o.content){if(d===i)break;l+=Ve(d);}return {kind:"image",op:"resize",paraId:t,offset:l,drawingId:n,width:a,height:s}}function zr(e,t,n){let r=ve(e,t);if(!r)return null;let{paragraph:o}=r;if(n>0)return bw(o,n);let i=r.previous;return i?(i.content=$e([...i.content,...o.content]),r.remove(),{kind:"block",op:"merge",paraId:i.paraId}):null}function Vr(e,t,n){let r=ve(e,t);if(!r)return null;let{paragraph:o}=r;if(n<li(o.content))return bu(o,n);let i=r.container[r.index+1];return (i==null?void 0:i.kind)!=="paragraph"?null:(o.content=$e([...o.content,...i.content]),r.container.splice(r.index+1,1),{kind:"block",op:"merge",paraId:o.paraId})}function bn(e,t,n,r){let o=Z(e,t),i=Mt(n,r);if(!o||i.from===i.to)return [];let a=xw(o,i.from,i.to);return o.content=a.content,a.changes}function fi(e,t,n){var b;if(t.paraId===n.paraId)return bn(e,t.paraId,t.offset,n.offset);let r=ve(e,t.paraId),o=ve(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(w=>w.kind!=="text")||i.end.paragraph.content.some(w=>w.kind!=="text"))return [];if(i.start.container.slice(i.start.index,i.end.index+1).some(w=>w.kind!=="paragraph"))return [];for(let w=i.start.index+1;w<i.end.index;w+=1){let g=i.start.container[w];if((g==null?void 0:g.kind)!=="paragraph"||g.content.some(h=>h.kind!=="text"))return []}let a=[],s=Te(i.start.paragraph),l=Te(i.end.paragraph),d=Math.max(0,Math.min(i.startOffset,s.length)),u=Math.max(0,Math.min(i.endOffset,l.length)),f=`${s.slice(0,d)}${l.slice(u)}`,p=i.end.index-i.start.index;for(let w=i.end.index;w>i.start.index;w-=1){let g=i.start.container[w];if((g==null?void 0:g.kind)==="paragraph"){if(g===i.end.paragraph&&u<l.length)a.push({kind:"text",op:"delete",paraId:g.paraId,offset:0,text:l.slice(0,u)});else {let h=Te(g);h.length>0&&a.push({kind:"text",op:"delete",paraId:g.paraId,offset:0,text:h});}(b=ve(e,g.paraId))==null||b.remove();}}d<s.length&&a.push({kind:"text",op:"delete",paraId:i.start.paragraph.paraId,offset:d,text:s.slice(d)});for(let w=0;w<p;w+=1)a.push({kind:"block",op:"merge",paraId:i.start.paragraph.paraId});return i.start.paragraph.content=f.length>0?[{kind:"text",text:f,format:yu(i.start.paragraph.content,d)}]:[],a}function ou(e,t,n,r){let o=ve(e,t.paraId),i=ve(e,n.paraId);if(!o||!i||o.container!==e.blocks||i.container!==e.blocks)return null;let a=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(a.start.index===a.end.index||a.start.paragraph.content.some(w=>w.kind!=="text")||a.end.paragraph.content.some(w=>w.kind!=="text"))return null;let s=e.blocks.slice(a.start.index,a.end.index+1);if(!s.slice(1,-1).some(w=>w.kind==="table"||w.content.some(g=>g.kind!=="text")))return null;let l=Ot(s),d=Te(a.start.paragraph).length,u=Te(a.end.paragraph).length,f=Math.max(0,Math.min(a.startOffset,d)),p=Math.max(0,Math.min(a.endOffset,u)),b=[...bn(e,a.end.paragraph.paraId,0,p),...bn(e,a.start.paragraph.paraId,f,d)];if(a.start.paragraph.content=$e([...a.start.paragraph.content,...a.end.paragraph.content]),e.blocks.splice(a.start.index+1,a.end.index-a.start.index),r.length>0){let w=on(e,a.start.paragraph.paraId,f,r);w&&b.push(w);}return b.push({kind:"structure",op:"delete-range",startParaId:a.start.paragraph.paraId,endParaId:a.end.paragraph.paraId,deletedBlockIds:s.slice(1).map(wu)}),{changes:b,cursor:{paraId:a.start.paragraph.paraId,offset:f+r.length},container:e.blocks,startIndex:a.start.index,beforeBlocks:l,afterBlocks:Ot([a.start.paragraph])}}function xs(e,t,n){let r=yw(e,t,n);if(!r||r.blocks.length<2&&!vw(r.blocks))return null;let o=Ot(r.blocks),i=o[0],a=o[o.length-1];return (i==null?void 0:i.kind)!=="paragraph"||(a==null?void 0:a.kind)!=="paragraph"?null:(i.content=wn(i.content,r.startOffset).after,a.content=wn(a.content,r.endOffset).before,o)}function iu(e,t,n,r){if(t.paraId!==n.paraId||r.length===0)return null;let o=ve(e,t.paraId);if(!o||o.container!==e.blocks)return null;let i=r[0],a=r[r.length-1];if((i==null?void 0:i.kind)!=="paragraph"||(a==null?void 0:a.kind)!=="paragraph")return null;let s=Ot([o.paragraph]),l=Te(o.paragraph).length,d=Math.max(0,Math.min(t.offset,n.offset,l)),u=Math.max(d,Math.min(Math.max(t.offset,n.offset),l)),f=wn(o.paragraph.content,d).before,p=wn(o.paragraph.content,u).after,b=xu(e,r),w=b[0],g=b[b.length-1];if((w==null?void 0:w.kind)!=="paragraph"||(g==null?void 0:g.kind)!=="paragraph")return null;f.length===0&&p.length===0&&(o.paragraph.styleId=w.styleId,o.paragraph.format=w.format?Yt(w.format):null),o.paragraph.content=$e([...f,...w.content]);let y={paraId:o.paragraph.paraId,offset:li(o.paragraph.content)},S=[o.paragraph];b.length===1?o.paragraph.content=$e([...o.paragraph.content,...p]):(g.content=$e([...g.content,...p]),S.push(...b.slice(1)),y={paraId:g.paraId,offset:li(g.content)-li(p)}),e.blocks.splice(o.index,1,...S);let k=Ot(S);return {changes:[{kind:"structure",op:"insert-range",paraId:o.paragraph.paraId,insertedBlockIds:S.slice(1).map(wu)}],cursor:y,container:e.blocks,startIndex:o.index,beforeBlocks:s,afterBlocks:k}}function Gr(e,t,n,r,o){let i=Mt(n,r),a=bn(e,t,i.from,i.to),s=on(e,t,i.from,o);return s?[...a,s]:a}function au(e,t,n,r){if(t.paraId===n.paraId)return Gr(e,t.paraId,t.offset,n.offset,r);let o=ve(e,t.paraId),i=ve(e,n.paraId);if(!o||!i||o.container!==i.container)return [];let a=o.index<i.index?t:n,s=fi(e,t,n);if(s.length===0||r.length===0)return s;let l=on(e,a.paraId,a.offset,r);return l?[...s,l]:s}function ys(e,t,n,r){var w,g,h,y,S,k,I,A;let o=ve(e,t.paraId),i=ve(e,n.paraId);if(!o||!i||o.container!==i.container)return null;let a=o.index<i.index||o.index===i.index&&t.offset<=n.offset?t:n,s=fi(e,t,n),l=Z(e,a.paraId);if(!l||l.content.some(F=>F.kind!=="text"))return null;let d=r.replace(/\r\n?/g,`
14
14
  `).split(`
15
- `),u=[a.paraId],p=a.paraId,f=Math.max(0,Math.min(a.offset,Ne(l).length)),b=on(e,p,f,(w=d[0])!=null?w:"");b&&s.push(b);for(let O=1;O<d.length;O+=1){let W=Ln(e),V=ks(e,p,f+((h=(g=d[O-1])==null?void 0:g.length)!=null?h:0),W);if(!V)return null;s.push(V),u.push(W),p=W,f=0;let ee=on(e,p,0,(y=d[O])!=null?y:"");ee&&s.push(ee);}return {changes:s,cursor:{paraId:p,offset:d.length===1?f+((E=(S=d[0])==null?void 0:S.length)!=null?E:0):(A=(N=d[d.length-1])==null?void 0:N.length)!=null?A:0},paragraphIds:u}}function ys(e,t,n,r,o){var u;let i=Z(e,t),a=Mt(n,r);if(!i||a.from===a.to)return null;let s=0,l=false,d=[];for(let p of i.content){let f=ze(p);if(p.kind!=="text"||s+f<=a.from||s>=a.to){d.push(p),s+=f;continue}let b=Math.max(0,a.from-s),w=Math.min(f,a.to-s);b>0&&d.push(H(v({},p),{text:p.text.slice(0,b)})),w>b&&(d.push(H(v({},p),{text:p.text.slice(b,w),format:v(v({},(u=p.format)!=null?u:{}),o)})),l=true),w<f&&d.push(H(v({},p),{text:p.text.slice(w)})),s+=f;}return l?(i.content=$e(d),{kind:"format",op:"run",paraId:t,from:a.from,to:a.to,format:o}):null}function vs(e,t,n,r,o){var p,f,b;let i=Z(e,t),a=Mt(n,r);if(!i||a.from===a.to)return null;let s=0,l=false,d=[],u=H(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 w of i.content){let g=ze(w);if(w.kind!=="text"||s+g<=a.from||s>=a.to){d.push(w),s+=g;continue}let h=Math.max(0,a.from-s),y=Math.min(g,a.to-s);if(h>0&&d.push(H(v({},w),{text:w.text.slice(0,h)})),y>h){let S=w.text.slice(h,y);if(o.preserveExistingComments&&((p=w.marks)!=null&&p.some(E=>E.kind==="comment")))d.push(H(v({},w),{text:S})),d.push(H(v({},w),{text:S,marks:[u,...(f=w.marks)!=null?f:[]]}));else {let E=((b=w.marks)!=null?b:[]).filter(N=>N.kind!=="comment");d.push(H(v({},w),{text:S,marks:[...E,u]}));}l=true;}y<g&&d.push(H(v({},w),{text:w.text.slice(y)})),s+=g;}return l?(i.content=$e(d),{kind:"annotation",op:"insert",paraId:t,from:a.from,to:a.to,commentId:o.commentId,body:o.body,parentCommentId:o.parentCommentId}):null}function ou(e,t,n){let r=[];for(let o of _e(e)){let i=0,a=null,s=null,l=false,d=o.content.map(u=>{var b,w;let p=ze(u);return u.kind!=="text"||!((b=u.marks)==null?void 0:b.find(g=>g.kind==="comment"&&g.commentId===t))?(i+=p,u):(a=a===null?i:a,s=i+p,l=true,i+=p,H(v({},u),{marks:(w=u.marks)==null?void 0:w.map(g=>g.kind==="comment"&&g.commentId===t?H(v({},g),{body:n}):g)}))});!l||a===null||s===null||(o.content=$e(d),r.push({kind:"annotation",op:"update",paraId:o.paraId,from:a,to:s,commentId:t,body:n}));}return r}function iu(e,t){let n=[];for(let r of _e(e)){let o=0,i=null,a=null,s=false,l=r.content.map(d=>{var b,w,g;let u=ze(d);if(d.kind!=="text"||!((w=(b=d.marks)==null?void 0:b.some(h=>h.kind==="comment"&&h.commentId===t))!=null?w:false))return o+=u,d;i=i===null?o:i,a=o+u,s=true,o+=u;let f=(g=d.marks)==null?void 0:g.filter(h=>!(h.kind==="comment"&&h.commentId===t));return f&&f.length>0?H(v({},d),{marks:f}):H(v({},d),{marks:void 0})});!s||i===null||a===null||(r.content=$e(l),n.push({kind:"annotation",op:"delete",paraId:r.paraId,from:i,to:a,commentId:t}));}return n}function $t(e,t,n,r,o){var p,f;let i=Z(e,t),a=Mt(n,r);if(!i||a.from===a.to)return null;let s=0,l=false,d=[],u={kind:"revision",id:`revision:${o.revisionId}`,revisionId:o.revisionId,revisionKind:o.revisionKind,author:o.author,date:o.date};for(let b of i.content){let w=ze(b);if(b.kind!=="text"||s+w<=a.from||s>=a.to){d.push(b),s+=w;continue}let g=Math.max(0,a.from-s),h=Math.min(w,a.to-s);if(g>0&&d.push(H(v({},b),{text:b.text.slice(0,g)})),h>g){let y=((p=b.marks)!=null?p:[]).find(S=>S.kind==="revision");if(!(o.revisionKind==="delete"&&(y==null?void 0:y.revisionKind)==="insert")){let S=((f=b.marks)!=null?f:[]).filter(E=>E.kind!=="revision");d.push(H(v({},b),{text:b.text.slice(g,h),marks:[...S,u]}));}l=true;}h<w&&d.push(H(v({},b),{text:b.text.slice(h)})),s+=w;}return l?(i.content=$e(d),{kind:"revision",op:o.revisionKind,paraId:t,from:a.from,to:a.to,revisionId:o.revisionId,revisionKind:o.revisionKind}):null}function au(e,t,n,r,o){var f,b,w,g;let i=Z(e,t),a=Mt(n,r);if(!i||a.from===a.to)return null;let s=0,l=false,d="",u="insert",p=[];for(let h of i.content){let y=ze(h);if(h.kind!=="text"||s+y<=a.from||s>=a.to){p.push(h),s+=y;continue}let S=Math.max(0,a.from-s),E=Math.min(y,a.to-s);if(S>0&&p.push(H(v({},h),{text:h.text.slice(0,S)})),E>S){let N=h.text.slice(S,E),A=((f=h.marks)!=null?f:[]).find(O=>O.kind==="revision");A?(l=true,d=(b=A.revisionId)!=null?b:A.id.replace(/^revision:/,""),u=(w=A.revisionKind)!=null?w:"insert",(o==="accept"?u==="insert":u==="delete")&&p.push(H(v({},h),{text:N,marks:((g=h.marks)!=null?g:[]).filter(W=>W.kind!=="revision")}))):p.push(H(v({},h),{text:N}));}E<y&&p.push(H(v({},h),{text:h.text.slice(E)})),s+=y;}return l?(i.content=$e(p),{kind:"revision",op:o,paraId:t,from:a.from,to:a.to,revisionId:d,revisionKind:u}):null}function su(e,t,n,r,o){let i=Z(e,t),a=Mt(n,r);if(!i||a.from===a.to)return null;let s=0,l=false,d="",u=[];for(let p of i.content){let f=ze(p);if(p.kind!=="text"||s+f<=a.from||s>=a.to){u.push(p),s+=f;continue}let b=Math.max(0,a.from-s),w=Math.min(f,a.to-s);if(b>0&&u.push(H(v({},p),{text:p.text.slice(0,b)})),w>b){let g=p.formatRevision;g?(d=g.revisionId,l=true,u.push(H(v({},p),{text:p.text.slice(b,w),format:o==="reject"?g.beforeFormat?v({},g.beforeFormat):null:p.format,formatRevision:void 0}))):u.push(H(v({},p),{text:p.text.slice(b,w)}));}w<f&&u.push(H(v({},p),{text:p.text.slice(w)})),s+=f;}return l?(i.content=$e(u),{kind:"format",op:o,paraId:t,from:a.from,to:a.to,format:{},revisionId:d,revisionKind:"format"}):null}function Ss(e,t,n,r,o){var p;let i=Z(e,t),a=Mt(n,r);if(!i||a.from===a.to)return null;let s=o?vw(o):null;if(o&&!s)return null;let l=0,d=false,u=[];for(let f of i.content){let b=ze(f);if(f.kind!=="text"||l+b<=a.from||l>=a.to){u.push(f),l+=b;continue}let w=Math.max(0,a.from-l),g=Math.min(b,a.to-l);if(w>0&&u.push(H(v({},f),{text:f.text.slice(0,w)})),g>w){let h=H(v({},f),{text:f.text.slice(w,g)});s?h.hyperlink=v({},s):delete h.hyperlink,u.push(h),hs((p=f.hyperlink)!=null?p:null,s)||(d=true);}g<b&&u.push(H(v({},f),{text:f.text.slice(g)})),l+=b;}return d?(i.content=$e(u),v({kind:"hyperlink",op:s?"set":"remove",paraId:t,from:a.from,to:a.to},s?{hyperlink:s}:{})):null}function Jn(e,t,n){var i,a,s;let r=Z(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({},(a=o.indent)!=null?a:{}),n.indent)),n.spacing&&(r.format.spacing=v(v({},(s=o.spacing)!=null?s:{}),n.spacing)),{kind:"format",op:"paragraph",paraId:t,format:n}}function lu(e,t,n,r){let o=Z(e,t),i=Mt(n,r);if(!o||i.from===i.to)return null;let a=0,s=false,l=[];for(let d of o.content){let u=ze(d);if(d.kind!=="text"||a+u<=i.from||a>=i.to){l.push(d),a+=u;continue}let p=Math.max(0,i.from-a),f=Math.min(u,i.to-a);p>0&&l.push(H(v({},d),{text:d.text.slice(0,p)})),f>p&&(l.push(H(v({},d),{text:d.text.slice(p,f),format:null})),d.format&&Object.keys(d.format).length>0&&(s=true)),f<u&&l.push(H(v({},d),{text:d.text.slice(f)})),a+=u;}return s?(o.content=$e(l),{kind:"format",op:"run",paraId:t,from:i.from,to:i.to,format:{},clear:true}):null}function Vr(e,t,n){var i,a,s;let r=Z(e,t);if(!r)return null;let o=(i=r.format)!=null?i:{};if(n)r.format=H(v({},o),{hasNumbering:true,numbering:v({},n),indent:v(v({},(a=o.indent)!=null?a:{}),Dc(n.ilvl))});else {let l=H(v({},o),{hasNumbering:false,indent:H(v({},(s=o.indent)!=null?s:{}),{left:0,firstLine:0})});delete l.numbering,r.format=l;}return {kind:"list",paraId:t,numbering:n?v({},n):null}}function GE(e,t,n,r){var l;let o=Z(e,t),i=Mt(n,r);if(!o||i.from===i.to)return false;let a=0,s=false;for(let d of o.content){let u=ze(d);if(d.kind==="text"&&a+u>i.from&&a<i.to&&(s=true,((l=d.format)==null?void 0:l.bold)!==true))return false;a+=u;}return s}function du(e,t,n){let r=Z(e,t);if(!r)return null;let o=0,i=[],a=null;for(let s of r.content)!a&&s.kind==="image"&&s.drawingId===n?a={kind:"image",op:"delete",paraId:t,offset:o,drawingId:n}:i.push(s),o+=ze(s);return a?(r.content=$e(i),a):null}function cu(e,t,n,r,o,i){var f;let a=Z(e,t),s=Mt(n,r);if(!a||s.from===s.to)return null;let l=0,d=false,u=[],p=b=>{let w=0;for(let g of o.content){let h=ze(g);if(g.kind==="text"&&b>=w&&b<w+h)return g.format?v({},g.format):null;w+=h;}return null};for(let b of a.content){let w=ze(b);if(b.kind!=="text"||l+w<=s.from||l>=s.to){u.push(b),l+=w;continue}let g=Math.max(0,s.from-l),h=Math.min(w,s.to-l);g>0&&u.push(H(v({},b),{text:b.text.slice(0,g)})),h>g&&(u.push(H(v({},b),{text:b.text.slice(g,h),formatRevision:(f=b.formatRevision)!=null?f:{kind:"format",revisionId:i.revisionId,beforeFormat:p(l+g),author:i.author,date:i.date}})),d=true),h<w&&u.push(H(v({},b),{text:b.text.slice(h)})),l+=w;}return d?(a.content=$e(u),{kind:"format",op:"run",paraId:t,from:s.from,to:s.to,format:{},revisionId:i.revisionId,revisionKind:"format",beforeFormat:p(s.from)}):null}function uu(e,t,n,r){let o=Z(e,t);if(!o)return null;let i=0;for(let a=0;a<o.content.length;a+=1){let s=o.content[a];if((s==null?void 0:s.kind)!=="image"||s.drawingId!==n){i+=s?ze(s):0;continue}let l=s.revision;return l?(l.revisionKind==="delete"&&r==="accept"||l.revisionKind==="insert"&&r==="reject"?o.content.splice(a,1):s.revision=void 0,o.content=$e(o.content),{kind:"image",op:r,paraId:t,offset:i,drawingId:n,revisionId:l.revisionId,revisionKind:l.revisionKind}):null}return null}function fu(e,t,n,r){let o=Z(e,t);if(!o)return null;let i=0;for(let a of o.content){if(a.kind!=="image"||a.drawingId!==n){i+=ze(a);continue}let s=a.formatRevision;if(!s)return null;r==="reject"&&(a.width=s.beforeWidth,a.height=s.beforeHeight);let l=s.revisionId;return a.formatRevision=void 0,{kind:"image",op:r,paraId:t,offset:i,drawingId:n,revisionId:l,revisionKind:"format"}}return null}function ks(e,t,n,r=Ln(e)){let o=ye(e,t);if(!o)return null;let{paragraph:i}=o,a=wn(i.content,n);return i.content=a.before,o.insertAfter({kind:"paragraph",paraId:r,story:i.story,styleId:i.styleId,format:i.format?JSON.parse(JSON.stringify(i.format)):null,content:a.after}),{kind:"block",op:"split",paraId:t,newParaId:r,offset:n}}function Gr(e,t,n){let r=Z(e,t);if(!r||r.content.some(s=>s.kind!=="text"))return null;let o=Ne(r);if(o===n)return null;let i=Sw(o,n),a=r.content;return i.deletedText.length>0&&(a=pw(a,i.offset,i.deletedText.length)),i.insertedText.length>0&&(a=pu(a,i.offset,i.insertedText,bu(r.content,i.offset))),r.content=a,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 pu(e,t,n,r=null){let o=[],i=0,a=false;for(let s of e){let l=ze(s);if(!a&&t<=i+l){if(s.kind==="text"){let d=Math.max(0,t-i);o.push(H(v({},s),{text:`${s.text.slice(0,d)}${n}${s.text.slice(d)}`}));}else t<=i?o.push({kind:"text",text:n,format:r},s):o.push(s,{kind:"text",text:n,format:r});a=true;}else o.push(s);i+=l;}return a||o.push({kind:"text",text:n,format:r}),$e(o)}function pw(e,t,n){if(n<=0)return e;let r=[],o=0,i=t+n;for(let a of e){let s=ze(a),l=o+s;if(a.kind!=="text"||l<=t||o>=i)r.push(a);else {let d=Math.max(0,t-o),u=Math.max(0,l-i),p=`${a.text.slice(0,d)}${a.text.slice(a.text.length-u)}`;p.length>0&&r.push(H(v({},a),{text:p}));}o=l;}return $e(r)}function mw(e,t){return mu(e,t-1)}function hw(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 mu(e,t){if(t<0)return null;let n=[],r=0,o=null;for(let i of e.content){let a=ze(i);if(!o&&t>=r&&t<r+a)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 s=t-r,l=i.text.slice(s,s+1),d=`${i.text.slice(0,s)}${i.text.slice(s+1)}`;d.length>0&&n.push(H(v({},i),{text:d})),o={kind:"text",op:"delete",paraId:e.paraId,offset:t,text:l};}else n.push(i);else n.push(i);r+=a;}return o?(e.content=$e(n),o):null}function gw(e,t,n){let r=[],o=[],i=0;for(let a of e.content){let s=ze(a),l=i+s;if(!(t<l&&n>i)){r.push(a),i=l;continue}if(a.kind==="text"){let u=Math.max(0,t-i),p=Math.min(a.text.length,n-i),f=a.text.slice(u,p),b=`${a.text.slice(0,u)}${a.text.slice(p)}`;b.length>0&&r.push(H(v({},a),{text:b})),f.length>0&&o.push({kind:"text",op:"delete",paraId:e.paraId,offset:i+u,text:f});}else a.kind==="image"?o.push({kind:"image",op:"delete",paraId:e.paraId,offset:i,drawingId:a.drawingId}):a.kind==="pageBreak"?o.push({kind:"page-break",op:"delete",paraId:e.paraId,offset:i}):r.push(a);i=l;}return {content:$e(r),changes:o.sort((a,s)=>zc(s)-zc(a))}}function wn(e,t){let n=[],r=[],o=0,i=false;for(let a of e){let s=ze(a);if(!i&&t<=o+s){if(a.kind==="text"){let l=Math.max(0,t-o);l>0&&n.push(H(v({},a),{text:a.text.slice(0,l)})),l<a.text.length&&r.push(H(v({},a),{text:a.text.slice(l)}));}else t<=o?r.push(a):n.push(a);i=true;}else i?r.push(a):n.push(a);o+=s;}return {before:$e(n),after:$e(r)}}function ze(e){return e.kind==="text"?e.text.length:1}function li(e){if(!(!Number.isFinite(e)||e===void 0||e<=0))return Math.max(1,Math.round(e*100)/100)}function Mt(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 zc(e){return "offset"in e&&typeof e.offset=="number"?e.offset:0}function $e(e){var n,r,o,i;let t=[];for(let a of e)if(a.kind==="text"){if(a.text.length===0)continue;let s=t[t.length-1];(s==null?void 0:s.kind)==="text"&&yw(s.format,a.format)&&hs((n=s.hyperlink)!=null?n:null,(r=a.hyperlink)!=null?r:null)&&hs((o=s.marks)!=null?o:null,(i=a.marks)!=null?i:null)?s.text+=a.text:t.push(v({},a));}else t.push(a);return t}function Ot(e){let t=JSON.parse(JSON.stringify(e));return Cs(t),t}function hu(e){return e.kind==="paragraph"?e.paraId:e.tableId}function bw(e,t,n){let r=ye(e,t.paraId),o=ye(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(a=>a.kind!=="text")||i.end.paragraph.content.some(a=>a.kind!=="text")?null:{blocks:e.blocks.slice(i.start.index,i.end.index+1),startOffset:Math.max(0,Math.min(i.startOffset,Ne(i.start.paragraph).length)),endOffset:Math.max(0,Math.min(i.endOffset,Ne(i.end.paragraph).length))}}function ww(e){return e.slice(1,-1).some(t=>t.kind==="table"||t.content.some(n=>n.kind!=="text"))}function gu(e,t){let n=Ot(t),r=new Set(_e(e).map(d=>d.paraId)),o=new Set,i=new Set;di(e.blocks,d=>{if(d.kind==="table")i.add(d.tableId);else for(let u of d.content)(u.kind==="image"||u.kind==="drawing")&&o.add(u.drawingId);});let a=Date.now()>>>0,s=()=>{let d="";do a=a+1>>>0,d=a.toString(16).toUpperCase().padStart(8,"0");while(r.has(d));return r.add(d),d},l=(d,u)=>{let p=1;for(;d.has(`${u}-${p}`);)p+=1;let f=`${u}-${p}`;return d.add(f),f};return di(n,d=>{if(d.kind==="table"){d.tableId=l(i,"coco-clipboard-table");return}d.paraId=s();for(let u of d.content)if((u.kind==="image"||u.kind==="drawing")&&(u.drawingId=l(o,"coco-clipboard-drawing")),u.kind==="drawing"&&u.paragraphs)for(let p of u.paragraphs)p.paraId=s();}),Cs(n),n}function xw(e){let t=new Set;for(let r of [e.blocks,...e.headers.map(o=>o.blocks),...e.footers.map(o=>o.blocks)])di(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 di(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)di(o.blocks,t);}function Cs(e){for(let t of e)if(t.kind==="table")for(let n of t.rows)for(let r of n.cells)Cs(r.blocks),r.paragraphs=Fr(r.blocks);}function Fr(e){return e.flatMap(t=>t.kind==="paragraph"?[t]:t.rows.flatMap(n=>n.cells.flatMap(r=>Fr(r.blocks))))}function si(e){return e.reduce((t,n)=>t+ze(n),0)}function yw(e,t){return JSON.stringify(e!=null?e:null)===JSON.stringify(t!=null?t:null)}function vw(e){var o,i,a;let t=(o=e.target)==null?void 0:o.trim(),n=(i=e.anchor)==null?void 0:i.trim().replace(/^#/,""),r=(a=e.tooltip)==null?void 0:a.trim();return !t&&!n?null:v(v(v({},t?{target:t}:{}),n?{anchor:n}:{}),r?{tooltip:r}:{})}function hs(e,t){return JSON.stringify(e)===JSON.stringify(t)}function bu(e,t){let n=0,r=null;for(let o of e){let i=ze(o);if(o.kind==="text"){if(t>=n&&t<=n+i)return o.format;r=o.format;}n+=i;}return r}function Sw(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 wu=/^data:(image\/(?:png|jpeg|gif|webp));base64,([a-z0-9+/]*={0,2})$/i,kw=new Set(["http:","https:","mailto:","tel:"]);function jr(e){let t=e.trim();return wu.test(t)?t:null}function xu(e){let t=jr(e),n=t?wu.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 Ur(e,t){if(e)try{let n=new URL(e.trim());if(kw.has(n.protocol))return n.href}catch(n){}return t?`#${encodeURIComponent(t)}`:"#"}var yu=260;function Tu(){Wn("coco-word-native-document"),Wn("coco-word-native-page"),Wn("coco-word-native-page-body"),Wn("coco-word-native-story"),Wn("coco-word-native-p"),Wn("coco-word-native-drawing"),Wn("coco-word-native-table");}function Pu(e){var a,s;let t=document.createElement("coco-word-native-document");t.contentEditable="true",t.spellcheck=false,Cw(e)&&t.classList.add("uses-natural-paragraph-flow"),Iw(e)&&t.classList.add("uses-compact-latin-tables"),Nw(e)&&t.classList.add("uses-rowspan-table-group-splitting");let n=Yn((a=e.defaults)==null?void 0:a.run).cssText;n.length>0&&t.setAttribute("style",n);for(let l of e.headers)t.appendChild(Iu(l));let r=Ew(e),o=r!==void 0&&Ms(e);for(let l of e.blocks)t.appendChild(Zr(l,{implicitGridForParagraphs:o,implicitGridLinePitch:r})),xx(l)&&(o=false);for(let l of e.footers)t.appendChild(Iu(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"),((s=e.pageLayout)==null?void 0:s.width)!==void 0)t.style.minWidth=`${Hs(e.pageLayout.width)+yu}px`;else {let l=`calc(100% + ${yu}px)`;t.style.width=l,t.style.minWidth=l;}return t}function Cw(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:!Ms(e)}function Ew(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 Iw(e){return e.blocks.some(t=>t.kind==="table")&&!Ms(e)}function Nw(e){return e.blocks.filter(n=>n.kind==="table").length<10?false:Tw(e)<=5}function Tw(e){return e.blocks.reduce((t,n)=>t+Ru(n),0)}function Ru(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,a)=>i+Ru(a),0),0),0)}function Ms(e){let t=0,n=0;for(let r of e.blocks.slice(0,160)){for(let o of Pw(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 Pw(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 Mu(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"),a=r.filter(y=>y instanceof HTMLElement&&y.tagName.toLowerCase()!=="coco-word-native-story");e.replaceChildren();let s=new Map,l=0,d=qr(t,l,n),u=(y=l)=>{var E;let S=((E=s.get(y))!=null?E:0)+1;return s.set(y,S),l=y,d=qr(t,y,n),Xu(e,t,d,o,i,e.children.length+1,y,S)},p=u(),f=p.querySelector("coco-word-native-page-body"),b=()=>Math.max(120,Math.round(f.getBoundingClientRect().height)||ux(d)),w=()=>(p=u(),f=p.querySelector("coco-word-native-page-body"),f),g=y=>{var N,A,O;if(y===l||f.children.length>0)return;let S=(N=s.get(l))!=null?N:0;S>1?s.set(l,S-1):s.delete(l);let E=((A=s.get(y))!=null?A:0)+1;s.set(y,E),l=y,d=qr(t,y,n),Yu(p,t,d,o,i,Number((O=p.dataset.pageNumber)!=null?O:"1"),y,E);},h=(y,S)=>{var V;let E=(V=Hw(y,t))!=null?V:l;f.children.length===0&&g(E),Ws(y)&&f.children.length>0&&(w(),g(E)),f.appendChild(y);let N=ax(y);N&&_r(p);let A=y.querySelector(".coco-word-page-break")!==null;if(f.scrollHeight>b()){let ee=Fw(f,y);if(ee){if(y.matches("coco-word-native-table")){if(f.removeChild(y),Es(y,f,b,w)){N||_r(p);let oe=mi(y,t),we=Su(y,t);we!==null&&(l=we),(A||oe)&&ku(w,oe);return}f.appendChild(y);}f.removeChild(y),f.removeChild(ee),w(),g(E),f.appendChild(ee),f.appendChild(y),y.matches("coco-word-native-table")&&f.scrollHeight>b()&&(f.removeChild(y),Es(y,f,b,w)||f.appendChild(y));}else {f.removeChild(y);let pe=Ow(y,f,b);pe?(w(),g(E),f.appendChild(pe)):Es(y,f,b,w)||(w(),g(E),f.appendChild(y));}}else y.matches("coco-word-native-table")&&zw(y,f,b,w,S);N||_r(p);let O=mi(y,t),W=Su(y,t);W!==null&&(l=W),(A||O)&&ku(w,O);};for(let y=0;y<a.length;y+=1)h(a[y],y===a.length-1);ju(e),Uu(e),_u(e),nf(e,t),yn(e);}function Au(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=an(e),a=i.indexOf(o);if(a<0)return false;let s=Bw(e),l=false,d=false;for(let u=a;u<i.length;u+=1){let p=i[u],f=zt(p);if(f)for(;fi(f);){if(Aw(e,t,p,i[u+1],s)){i=an(e),l=true;continue}let b=Mw(f);if(b.length===0||b.length>=f.children.length)break;let w=i[u+1];(!w||pi(p,w,t))&&(w=Wu(e,t,p,w,s),i=an(e),d=true);let g=zt(w);if(!g)break;for(let h of [...b].reverse())g.insertBefore(h,g.firstChild);l=true;}}i=an(e),a=Math.max(0,Math.min(a,Math.max(0,i.length-1))-1);for(let u=a;u<i.length-1;u+=1){let p=i[u],f=i[u+1],b=zt(p),w=zt(f);if(!(!b||!w||pi(p,f,t))){for(;Lw(b,w);)l=true;for(;;){let g=Ls(w);if(g.length===0||!Lu(b,g[0],t))break;for(let h of g)b.appendChild(h);if(fi(b,8)){for(let h of [...g].reverse())w.insertBefore(h,w.firstChild);if(g.length>1){let h=g[0];if(b.appendChild(h),!fi(b,8)){l=true;continue}w.insertBefore(h,w.firstChild);}break}l=true;}Ku(f)&&(f.remove(),i=an(e),u-=1,d=true);}}return l?(ju(e),Uu(e),_u(e),d&&Dw(e,t,s),nf(e,t),yn(e),true):false}function As(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"),a=an(e),s=i?a.indexOf(i):-1;if(!o||!i||s<0)return r;let l=zt(i);if(!l)return r;let d=Math.max(120,Math.round(l.getBoundingClientRect().height)),u=Math.max(0,l.scrollHeight-d),p=a[s-1],f=p?zt(p):null,b=!!(p&&f&&Ls(l).some(y=>Bu(y,n))&&vu(p,i,f,l,t)),w=a[s+1],g=w?zt(w):null,h=!!(w&&g&&vu(i,w,l,g,t));return {overflowPx:u,canBackfillPrevious:b,canBackfillNext:h}}function vu(e,t,n,r,o){if(pi(e,t,o))return false;let i=Math.max(0,Math.round(n.getBoundingClientRect().height)-Gu(n));if(i<=0)return false;let a=n.lastElementChild,s=r.firstElementChild;if(a instanceof HTMLElement&&s instanceof HTMLElement&&a.matches("coco-word-native-table")&&s.matches("coco-word-native-table")&&a.dataset.tableId===s.dataset.tableId){let d=Array.from(s.querySelectorAll(":scope > table > tbody > tr")).filter(p=>p.dataset.repeatedHeader!=="true"),u=Yr(d)[0];if(u&&!Dn(u)&&Fu(u)<=i+8)return true}let l=Ls(r);return l.length===0||!Lu(n,l[0],o)?false:Rw(l)<=i+8}function Rw(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 Vt(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=an(e),a=o?i.indexOf(o):-1;if(a<0)return false;let s=false;for(let l of t.blocks){if(l.kind!=="table")continue;let d=Array.from(e.querySelectorAll(`coco-word-native-table[data-table-id="${l.tableId}"]`)),u=d[0],p=u==null?void 0:u.closest("coco-word-native-page");if(!(!u||!p||i.indexOf(p)<a)){u.replaceWith(af(l));for(let f of d.slice(1))f.remove();s=true;}}return s}function an(e){return Array.from(e.children).filter(t=>t instanceof HTMLElement&&t.tagName.toLowerCase()==="coco-word-native-page")}function zt(e){return e.querySelector(":scope > coco-word-native-page-body")}function fi(e,t=1){let n=Math.max(120,Math.round(e.getBoundingClientRect().height));return e.scrollHeight>n+t}function Mw(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 Ls(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 Aw(e,t,n,r,o){let i=zt(n),a=i==null?void 0:i.lastElementChild;if(!(a instanceof HTMLElement)||!a.matches("coco-word-native-table"))return false;let s=a.querySelector(":scope > table"),l=s==null?void 0:s.querySelector(":scope > tbody");if(!s||!l)return false;let u=Array.from(l.children).filter(bi).filter(E=>E.dataset.repeatedHeader!=="true"),p=Yr(u);if(p.length<2)return false;let f=p[p.length-1];if(Dn(f))return false;let b=r;(!b||pi(n,b,t))&&(b=Wu(e,t,n,b,o));let w=zt(b);if(!w)return false;let g=a.dataset.tableId,h=Array.from(w.children).find(E=>E instanceof HTMLElement&&E.matches("coco-word-native-table")&&E.dataset.tableId===g);if(!h){h=Qn(a,s),w.insertBefore(h,w.firstChild);let E=h.querySelector(":scope > table > tbody");E&&Kr(E,Ww(e,g));}let y=h.querySelector(":scope > table > tbody");if(!y)return false;let S=Array.from(y.children).find(E=>E instanceof HTMLTableRowElement&&E.dataset.repeatedHeader!=="true");Xr(l,f);for(let E of f)y.insertBefore(E,S!=null?S:null);return true}function Lw(e,t){var d,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 a=Array.from(i.children).filter(bi).filter(p=>p.dataset.repeatedHeader!=="true"),s=Yr(a)[0];if(!s||Dn(s))return false;let l=(u=(d=s[s.length-1])==null?void 0:d.nextElementSibling)!=null?u:null;if(er(o,s),fi(e,8)){for(let p of s)i.insertBefore(p,l);return false}return i.querySelector('tr:not([data-repeated-header="true"])')===null&&r.remove(),true}function Ww(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 pi(e,t,n){if(e.dataset.sectionIndex!==t.dataset.sectionIndex)return true;let r=zt(e),o=zt(t),i=r==null?void 0:r.lastElementChild,a=o==null?void 0:o.firstElementChild;if(a instanceof HTMLElement&&Ws(a))return true;if(!(i instanceof HTMLElement))return false;if(i.querySelector(".coco-word-page-break"))return true;let s=mi(i,n);return s!==null&&s!=="continuous"&&s!=="nextColumn"}function Lu(e,t,n){if(Ws(t))return false;let r=e.lastElementChild;if(!(r instanceof HTMLElement))return true;if(r.querySelector(".coco-word-page-break"))return false;let o=mi(r,n);return o===null||o==="continuous"||o==="nextColumn"}function Bw(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 a=i.dataset.storyKind,s=`${a!=null?a:""}:${(o=i.dataset.partName)!=null?o:""}`;t.has(s)||(t.add(s),a==="header"&&n.push(i),a==="footer"&&r.push(i));}return {headers:n,footers:r}}function Wu(e,t,n,r,o){let i=an(e),a=i.indexOf(n),s=xn(n.dataset.sectionIndex,0),l=i.slice(0,a+1).filter(u=>xn(u.dataset.sectionIndex,0)===s).length+1,d=Xu(e,t,qr(t,s,t.pageLayout),o.headers,o.footers,a+2,s,l);return r&&e.insertBefore(d,r),d}function Dw(e,t,n){for(let r of an(e)){let o=xn(r.dataset.pageNumber,1),i=xn(r.dataset.sectionIndex,0),a=xn(r.dataset.sectionPageNumber,1);Yu(r,t,qr(t,i,t.pageLayout),n.headers,n.footers,o,i,a);}}function Ws(e){return e.matches('coco-word-native-p[data-page-break-before="true"]')}function Fw(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 mi(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 Su(e,t){let n=t.sections.find(r=>r.lastParaId&&Bu(e,r.lastParaId));return n?Math.min(n.sectionIndex+1,Math.max(0,t.sections.length-1)):null}function Hw(e,t){if(t.sections.length===0)return null;let n=Du(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 Bu(e,t){return Du(e).includes(t)}function Du(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 ku(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 Ow(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=At(e);if(r<2)return null;let o=null,i=1,a=r-1;for(;i<=a;){let s=Math.floor((i+a)/2),l=Hu(e,s);if(!l||At(l.head)===0||At(l.tail)===0){a=s-1;continue}t.appendChild(l.head),t.scrollHeight<=n()?((o==null?void 0:o.head.parentElement)===t&&t.removeChild(o.head),o=l,i=s+1):(t.removeChild(l.head),a=s-1);}return !o||o.head.parentElement!==t?null:o.tail}function Es(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"),a=i?Array.from(i.children).filter(bi):[],s=Yr(a);if(!o||s.length<2)return false;let l=t,d=Qn(e,o),u=d.querySelector("tbody"),p=a.filter(w=>w.dataset.repeatHeader==="true"),f=$w(s,p),b=0;l.appendChild(d);for(let w of s){let g=Dn(w);if(!g&&b>=f&&(l=r(),d=Qn(e,o),u=d.querySelector("tbody"),l.appendChild(d),Kr(u,p),b=0),er(u,w),g||(b+=1),l.children.length<=1&&u.children.length<=w.length||l.scrollHeight<=n())continue;Xr(u,w),g||(b=Math.max(0,b-1));let h=Vw(u,w,l,n()),y=h!=null?h:Kw(u,w,l,n()),S=y!=null?y:_w(u,w,l,n());if(S){g||(b+=1),l=r(),d=Qn(e,o),u=d.querySelector("tbody"),l.appendChild(d),b=0,Kr(u,p),er(u,S),g||(b=1);continue}u.children.length===0&&l.removeChild(d),l=r(),d=Qn(e,o),u=d.querySelector("tbody"),l.appendChild(d),b=0,g||Kr(u,p),er(u,w),g||(b=1);}return true}function $w(e,t){let n=e.filter(r=>!Dn(r)).length;return t.length===0||n<30?Number.POSITIVE_INFINITY:8}function zw(e,t,n,r,o){var E;let i=n(),a=i-Gu(t),s=rx(e,i);if(a>=s||o&&tx(t,i))return false;let l=e.querySelector(":scope > table"),d=l==null?void 0:l.querySelector(":scope > tbody"),u=d?Array.from(d.children).filter(bi):[],p=Yr(u);if(!l||!d||p.length<4)return false;let f=u.filter(N=>N.dataset.repeatHeader==="true"),b=a,w=0,g=[];for(;p.length>1&&b+w<s;){let N=p.pop();if(!N||Dn(N))break;w+=Fu(N),Xr(d,N),g.unshift(N);}if(g.length===0)return false;let h=r(),y=Qn(e,l),S=y.querySelector("tbody");h.appendChild(y),Dn((E=g[0])!=null?E:[])||Kr(S,f);for(let N of g)er(S,N);return true}function Fu(e){return e.reduce((t,n)=>t+n.getBoundingClientRect().height,0)}function Vw(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 a=Gw(t,i);if(a){o&&Xr(e,o.head);for(let s of a.head)e.appendChild(s);if(n.scrollHeight<=r)o=a;else {Xr(e,a.head),o&&er(e,o.head);break}}}return o?o.tail:null}function Gw(e,t){if(t<=0||t>=e.length)return null;let n=jw(e),r=e.slice(0,t).map(a=>a.cloneNode(true)),o=e.slice(t).map(a=>a.cloneNode(true)),i=n.filter(a=>a.row<t&&a.row+a.rowSpan>t);if(i.length===0)return null;for(let a of i){let s=r[a.row],l=s==null?void 0:s.cells[a.cellIndex];l&&(l.rowSpan=t-a.row);let d=a.cell.cloneNode(false);d.rowSpan=a.row+a.rowSpan-t,d.colSpan=a.colSpan,d.dataset.rowFragmentContinuation="true",d.classList.add("is-rowspan-continuation"),Uw(o[0],d,a.column,n,t);}return {head:r,tail:o}}function jw(e){var r,o;let t=[],n=[];for(let i=0;i<e.length;i+=1){let a=e[i],s=0;for(let l=0;l<a.cells.length;l+=1){for(;((r=n[s])!=null?r:0)>i;)s+=1;let d=a.cells[l],u=Math.max(1,d.colSpan),p=Math.max(1,d.rowSpan);t.push({row:i,cellIndex:l,column:s,colSpan:u,rowSpan:p,cell:d});for(let f=0;f<u;f+=1)n[s+f]=Math.max((o=n[s+f])!=null?o:0,i+p);s+=u;}}return t}function Uw(e,t,n,r,o){let a=r.filter(l=>l.row===o).sort((l,d)=>l.column-d.column).find(l=>l.column>n),s=a?e.cells[a.cellIndex]:null;e.insertBefore(t,s!=null?s:null);}function Kw(e,t,n,r){if(t.length!==1)return null;let o=t[0];if(!Jw(o))return null;let i=null,a=0,s=1;for(let l=0;l<8;l+=1){let d=(a+s)/2,u=Qw(o,d);if(!u){s=d;continue}e.appendChild(u.head),n.scrollHeight<=r?((i==null?void 0:i.head.parentElement)===e&&e.removeChild(i.head),i=u,a=d):(e.removeChild(u.head),s=d);}return !i||i.head.parentElement!==e?null:[i.tail]}function _w(e,t,n,r){if(t.length!==1)return null;let o=t[0];if(!qw(o))return null;let i=null,a=0,s=1;for(let l=0;l<9;l+=1){let d=(a+s)/2,u=Xw(o,d);if(!u){s=d;continue}e.appendChild(u.head),n.scrollHeight<=r?((i==null?void 0:i.head.parentElement)===e&&e.removeChild(i.head),i=u,a=d):(e.removeChild(u.head),s=d);}return !i||i.head.parentElement!==e?null:[i.tail]}function qw(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=>$u(n))?false:zu(e)?t.some(n=>Ns(n)):t.every(n=>Ns(n))}function Xw(e,t){let n=Eu(e),r=Eu(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(!Ns(e))return Vu(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=At(n),o=Math.max(1,Math.min(r-1,Math.round(r*t))),i=Hu(n,o);if(!i||At(i.head)===0||At(i.tail)===0)return null;let a=e.cloneNode(false),s=e.cloneNode(false);return a.appendChild(i.head),s.appendChild(i.tail),{head:a,tail:s}}function Hu(e,t){let n=At(e);if(!Number.isInteger(t)||t<=0||t>=n)return null;let r=e.cloneNode(false),o=e.cloneNode(false);return Ou(Array.from(e.childNodes),t,r,o),r.dataset.splitFragment="head",o.dataset.splitFragment="tail",{head:r,tail:o}}function Ou(e,t,n,r){let o=t;for(let i of e){let a=At(i);if(a===0){o>0?n.appendChild(i.cloneNode(true)):r.appendChild(i.cloneNode(true));continue}if(a<=o){n.appendChild(i.cloneNode(true)),o-=a;continue}if(o<=0){r.appendChild(i.cloneNode(true));continue}Zw(i,o,n,r),o=0;}}function Zw(e,t,n,r){var a;if(e.nodeType===Node.TEXT_NODE){let s=(a=e.textContent)!=null?a:"";n.appendChild(document.createTextNode(s.slice(0,t))),r.appendChild(document.createTextNode(s.slice(t)));return}if(!(e instanceof HTMLElement))return;let o=e.cloneNode(false),i=e.cloneNode(false);Ou(Array.from(e.childNodes),t,o,i),At(o)>0&&n.appendChild(o),At(i)>0&&r.appendChild(i);}function At(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+At(o),0)}function Jw(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=>$u(n))?false:zu(e)?t.some(n=>Is(n)):t.every(n=>Is(n))}function Qw(e,t){let n=Cu(e),r=Cu(e);for(let o of Array.from(e.cells)){let i=ex(o,t);if(!i)return null;n.appendChild(i.head),r.appendChild(i.tail);}return {head:n,tail:r}}function ex(e,t){if(!Is(e))return Vu(e);let n=Array.from(e.childNodes).filter(a=>a 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 a=0;a<n.length;a+=1){let s=n[a].cloneNode(true);a<r?o.appendChild(s):i.appendChild(s);}return {head:o,tail:i}}function $u(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 zu(e){var t;return ((t=e.closest("coco-word-native-document"))==null?void 0:t.classList.contains("uses-natural-paragraph-flow"))===true}function Is(e){return Array.from(e.childNodes).filter(t=>t instanceof HTMLElement).length>=2}function Ns(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"&&At(t[0])>1}function Vu(e){let t=e.cloneNode(true),n=e.cloneNode(false);return n.dataset.rowFragmentStatic="true",{head:t,tail:n}}function Cu(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 Eu(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 tx(e,t){return e.scrollHeight>t+1?false:nx(e)<=t*.75}function nx(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,a=Number.parseFloat(o.marginBottom)||0;t+=r.height+i+a;}return t}function Gu(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),a=Number.parseFloat(i.marginBottom)||0;n=Math.max(n,o.bottom-t.top+a);}return n}function rx(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 Yr(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 er(e,t){for(let r of t)e.appendChild(r);let n=e.closest("coco-word-native-table");n&&Bs(n);}function Dn(e){var t;return ((t=e[0])==null?void 0:t.dataset.repeatHeader)==="true"}function Kr(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 Xr(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 ju(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(!ox(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"),a=n.querySelector(":scope > .coco-word-native-page-overlay"),s=n.querySelector(":scope > .coco-word-native-page-behind-layer");if(!o||!i||!a&&!s)return;if(s){let l=Ts(r,"behind");for(let d of Array.from(s.children))l.appendChild(d);}if(a){let l=Ts(r,"front");for(let d of Array.from(a.children))l.appendChild(d);}for(let l of Array.from(i.children))o.appendChild(l);n.remove();}}function Uu(e){for(let t of Array.from(e.querySelectorAll("coco-word-native-page")))Ku(t)&&t.remove();}function Ku(e){var r,o,i,a;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)+((a=(i=e.querySelector(":scope > .coco-word-native-page-behind-layer"))==null?void 0:i.children.length)!=null?a:0)===0}function _u(e){let t=new Map;Array.from(e.querySelectorAll(":scope > coco-word-native-page")).forEach((r,o)=>{var s;let i=xn(r.dataset.sectionIndex,0),a=((s=t.get(i))!=null?s:0)+1;t.set(i,a),r.dataset.pageNumber=String(o+1),r.dataset.sectionPageNumber=String(a);});}function ox(e){var a,s;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=((a=n==null?void 0:n.children.length)!=null?a:0)+((s=r==null?void 0:r.children.length)!=null?s: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 d;return l.matches("coco-word-native-p.is-flow-empty")&&((d=l.textContent)!=null?d:"").trim().length===0&&l.getBoundingClientRect().height<=1})}function bi(e){return e instanceof HTMLTableRowElement}function _r(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(!qu(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 a=r.dataset.wrap==="behind"?"behind":"front";r.dataset.pageLayer=a,r.classList.add("is-page-layer-anchor"),Ts(e,a).appendChild(r);}for(let r of t)r.classList.toggle("is-flow-empty",!sx(r));ix(e);}function Ts(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(a=>a.tagName.toLowerCase()!=="coco-word-native-story");e.insertBefore(o,i!=null?i:e.firstChild);}else e.appendChild(o);return o}function ix(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 qu(e){let t=e.dataset.positionVerticalRelativeFrom,n=e.dataset.positionHorizontalRelativeFrom;return Ps(t||n)}function Ps(e){return e==="page"||e==="margin"}function ax(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")&&qu(r))}function sx(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 Xu(e,t,n,r,o,i,a,s){let l=document.createElement("coco-word-native-page");l.dataset.pageNumber=String(i),l.dataset.sectionIndex=String(a),l.dataset.sectionPageNumber=String(s);let d=ef(t,a,i,s);l.dataset.displayPageNumber=String(d),tf(l,n);for(let u of hi(t,"header",i,a,s,r))l.appendChild(gi(u,d,s));l.appendChild(document.createElement("coco-word-native-page-body"));for(let u of hi(t,"footer",i,a,s,o))l.appendChild(gi(u,d,s));return _r(l),e.appendChild(l),l}function Yu(e,t,n,r,o,i,a,s){var u,p;let l=e.querySelector("coco-word-native-page-body");if(!l)return;e.dataset.sectionIndex=String(a),e.dataset.sectionPageNumber=String(s);let d=ef(t,a,i,s);e.dataset.displayPageNumber=String(d),tf(e,n),(u=e.querySelector(":scope > .coco-word-native-page-overlay"))==null||u.remove(),(p=e.querySelector(":scope > .coco-word-native-page-behind-layer"))==null||p.remove();for(let f of Array.from(e.querySelectorAll(":scope > coco-word-native-story")))e.removeChild(f);for(let f of hi(t,"header",i,a,s,r))e.insertBefore(gi(f,d,s),l);for(let f of hi(t,"footer",i,a,s,o))e.appendChild(gi(f,d,s));_r(e);}function yn(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=cx(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,a)=>i.top-a.top||i.commentId-a.commentId).forEach((i,a)=>{let s=document.createElement("aside");s.className="coco-word-native-comment-bubble",s.dataset.annotationAnchorTop=String(i.top),s.dataset.commentId=String(i.commentId),s.dataset.commentBody=i.body,i.parentCommentId!==void 0&&Number.isFinite(i.parentCommentId)&&(s.dataset.parentCommentId=String(i.parentCommentId),s.classList.add("coco-word-native-comment-reply")),i.paraId&&(s.dataset.paraId=i.paraId),i.from!==void 0&&(s.dataset.from=String(i.from)),i.to!==void 0&&(s.dataset.to=String(i.to)),s.style.setProperty("--coco-word-comment-index",String(a));let l=document.createElement("div");l.className="coco-word-native-comment-meta",l.textContent=[i.author||`Comment ${i.commentId}`,i.date?Zu(i.date):""].filter(Boolean).join(" \xB7 "),i.parentCommentId!==void 0&&Number.isFinite(i.parentCommentId)&&(l.textContent=`\u56DE\u590D #${i.parentCommentId} \xB7 ${l.textContent}`);let d=document.createElement("div");d.className="coco-word-native-comment-body",d.textContent=i.body||"(empty comment)";let u=document.createElement("div");u.className="coco-word-native-comment-actions";let p=document.createElement("button");p.type="button",p.className="coco-word-native-comment-menu-button",p.dataset.commentMenu="true",p.dataset.commentId=String(i.commentId),p.setAttribute("aria-label","\u6279\u6CE8\u64CD\u4F5C"),p.title="\u6279\u6CE8\u64CD\u4F5C",p.textContent="\u22EF",u.appendChild(p);let f=document.createElement("div");f.className="coco-word-native-comment-menu",f.hidden=true,f.dataset.commentMenuFor=String(i.commentId);for(let[b,w]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=b,g.dataset.commentId=String(i.commentId),g.textContent=w,f.appendChild(g);}u.appendChild(f),s.appendChild(l),s.appendChild(d),s.appendChild(u),o.appendChild(s);});}lx(n),dx(n);}}function lx(e){var s,l,d,u,p,f,b,w,g,h,y;(s=e.querySelector(":scope > .coco-word-native-revision-layer"))==null||s.remove();let t=new Map,n=e.getBoundingClientRect();for(let S 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 E=(l=S.dataset.revisionId)!=null?l:"";if(!E)continue;let N=S.dataset.revisionKind==="format"?"format":S.dataset.revisionKind==="delete"||S.classList.contains("coco-word-revision-delete")?"delete":"insert",A=S.getBoundingClientRect(),O=`${N}:${E}`,W=t.get(O),V=Ju(S);t.set(O,{id:E,kind:N,author:(d=S.dataset.revisionAuthor)!=null?d:"",date:(u=S.dataset.revisionDate)!=null?u:"",text:`${(p=W==null?void 0:W.text)!=null?p:""}${(b=(f=S.dataset.revisionText)!=null?f:S.textContent)!=null?b:""}`,top:(w=W==null?void 0:W.top)!=null?w:Math.max(0,A.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((S,E)=>S.top-E.top||S.id.localeCompare(E.id)),i=new Map;for(let S of o){let E=S.paraId?`paragraph:${S.paraId}`:`position:${Math.round(S.top/48)}`,N=i.get(E);N?N.push(S):i.set(E,[S]);}let a=S=>{let E=document.createElement("aside");E.className=`coco-word-native-revision-bubble is-${S.kind}`,E.dataset.annotationAnchorTop=String(S.top),E.dataset.revisionId=S.id,E.dataset.revisionKind=S.kind,S.paraId&&(E.dataset.paraId=S.paraId),S.from!==void 0&&(E.dataset.from=String(S.from)),S.to!==void 0&&(E.dataset.to=String(S.to));let N=document.createElement("div");N.className="coco-word-native-revision-header";let A=document.createElement("span");A.className="coco-word-native-revision-meta",A.textContent=[S.author||"User",Zu(S.date)].filter(Boolean).join(" \xB7 "),N.appendChild(A),E.appendChild(N);let O=document.createElement("div");O.className="coco-word-native-revision-content",O.textContent=S.text||"(\u7A7A\u5185\u5BB9)",E.appendChild(O);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 oe=document.createElement("button");oe.type="button",oe.dataset.revisionAction=V,oe.dataset.revisionId=S.id,oe.dataset.revisionKind=S.kind,oe.textContent=ee,oe.setAttribute("aria-label",pe),oe.title=pe,oe.className=`is-${V}`,W.appendChild(oe);}return E.appendChild(W),E};for(let S of i.values()){if(S.length===1){r.appendChild(a(S[0]));continue}let E=document.createElement("section");E.className="coco-word-native-revision-group",E.dataset.annotationAnchorTop=String(S[0].top);let N=S[0].paraId;N&&(E.dataset.paraId=N);let A=document.createElement("button");A.type="button",A.className="coco-word-native-revision-group-toggle",A.dataset.revisionGroupToggle="true",A.setAttribute("aria-expanded","false");let O=document.createElement("strong");O.textContent=`\u672C\u6BB5 ${S.length} \u6761\u4FEE\u8BA2`;let W=S.reduce((oe,we)=>(oe[we.kind]+=1,oe),{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",A.append(O,V,ee);let pe=document.createElement("div");pe.className="coco-word-native-revision-group-list",pe.hidden=true,S.forEach(oe=>pe.appendChild(a(oe))),E.append(A,pe),r.appendChild(E);}}function dx(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,a)=>i.anchorTop-a.anchorTop);let r=0;n.forEach((i,a)=>{i.top=Math.max(i.anchorTop,a===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 a=n.length-1;a>=0;a-=1){let s=n[a];s.top=Math.min(s.top,i-s.height),i=s.top-8;}if(n[0].top<0){let a=-n[0].top;n.forEach(s=>{s.top+=a;});}}for(let i of n){let a=i.element.classList.contains("coco-word-native-comment-bubble")?"--coco-word-comment-top":"--coco-word-revision-top";i.element.style.setProperty(a,`${Math.round(i.top)}px`);}}function Zu(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 cx(e){var r,o,i,a,s,l,d,u,p,f,b,w,g,h,y,S,E;let t=e.getBoundingClientRect(),n=new Map;for(let N of Array.from(e.querySelectorAll(".coco-word-comment[data-comment-id]"))){let A=Number(N.dataset.commentId);if(!Number.isFinite(A))continue;let O=N.getBoundingClientRect(),W=Ju(N),V=n.get(A),ee=!(V!=null&&V.paraId)||!(W!=null&&W.paraId)||V.paraId===W.paraId;n.set(A,{commentId:A,author:(o=(r=V==null?void 0:V.author)!=null?r:N.dataset.commentAuthor)!=null?o:"",date:(a=(i=V==null?void 0:V.date)!=null?i:N.dataset.commentDate)!=null?a:"",body:(l=(s=V==null?void 0:V.body)!=null?s:N.dataset.commentBody)!=null?l:"",top:(d=V==null?void 0:V.top)!=null?d:Math.max(0,O.top-t.top),parentCommentId:(u=V==null?void 0:V.parentCommentId)!=null?u:N.dataset.parentCommentId?Number(N.dataset.parentCommentId):void 0,paraId:(p=V==null?void 0:V.paraId)!=null?p:W==null?void 0:W.paraId,from:ee?Math.min((b=(f=V==null?void 0:V.from)!=null?f:W==null?void 0:W.from)!=null?b:Number.POSITIVE_INFINITY,(w=W==null?void 0:W.from)!=null?w: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,(S=W==null?void 0:W.to)!=null?S:Number.NEGATIVE_INFINITY):(E=V==null?void 0:V.to)!=null?E: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,A)=>N.top-A.top||N.commentId-A.commentId)}function Ju(e){var a;let t=e.closest("coco-word-native-p[data-para-id]");if(!t)return null;let n=0,r=false,o=s=>{var l,d;if(!r){if(s===e){r=true;return}if(s.nodeType===Node.TEXT_NODE){n+=(d=(l=s.textContent)==null?void 0:l.length)!=null?d:0;return}if(!(s instanceof HTMLElement&&s.classList.contains("coco-word-comment-widget")))for(let u of Array.from(s.childNodes))o(u);}};if(o(t),!r)return null;let i=Array.from(e.childNodes).reduce((s,l)=>s+Qu(l),0);return {paraId:(a=t.dataset.paraId)!=null?a:"",from:n,to:n+Math.max(1,i)}}function Qu(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+Qu(o),0)}function qr(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 ef(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 tf(e,t){var n,r,o;e.style.width=It(t.width),e.style.height=It(t.height),e.style.paddingTop=It(t.margin.top),e.style.paddingRight=It(t.margin.right),e.style.paddingBottom=It(t.margin.bottom),e.style.paddingLeft=It(t.margin.left),e.style.setProperty("--coco-word-page-margin-top",It(t.margin.top)),e.style.setProperty("--coco-word-page-margin-left",It(t.margin.left)),e.style.setProperty("--coco-word-page-margin-right",It(t.margin.right)),e.style.setProperty("--coco-word-page-margin-bottom",It(t.margin.bottom)),e.style.setProperty("--coco-word-header-distance",It((n=t.headerDistance)!=null?n:Math.round(t.margin.top/2))),e.style.setProperty("--coco-word-footer-distance",It((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",It(t.docGrid.linePitch)):e.style.removeProperty("--coco-word-doc-grid-line-height");}function ux(e){return Math.max(120,Hs(e.height-e.margin.top-e.margin.bottom))}function hi(e,t,n,r,o,i){var u,p;if(i.length<=1)return i;let a=(u=e.sections.find(f=>f.sectionIndex===r))!=null?u:e.sections[0],s=fx(e,t,(p=a==null?void 0:a.sectionIndex)!=null?p:r),l=mx(s,(a==null?void 0:a.titlePage)===true,n,o);if(!l&&!px(e,t))return i;if(l){let f=i.find(b=>b.dataset.partName===l);return f?[f]:[]}let d=i.find(f=>!f.classList.contains("is-empty"));return d?[d]:[i[0]]}function fx(e,t,n){for(let r=n;r>=0;r--){let o=e.sections.find(a=>a.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 px(e,t){return e.sections.some(n=>t==="header"?n.headerRefs.length>0:n.footerRefs.length>0)}function mx(e,t,n,r){var o,i;if(e.length===0)return null;if(r===1&&t){let a=e.find(s=>s.type==="first");if(a)return a.partName}if(n%2===0){let a=e.find(s=>s.type==="even");if(a)return a.partName}return (i=(o=e.find(a=>a.type==="default"))==null?void 0:o.partName)!=null?i:e[0].partName}function Iu(e){let t=document.createElement("coco-word-native-story");t.setAttribute("data-story-kind",e.kind),t.setAttribute("data-part-name",e.partName),bx(e)||t.classList.add("is-empty");for(let n of e.blocks)t.appendChild(Zr(n));return t}function gi(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 nf(e,t){var i,a,s,l;let n=Array.from(e.querySelectorAll(":scope > coco-word-native-page")),r=new Map;for(let d of n){let u=Number((i=d.dataset.sectionIndex)!=null?i:"0");r.set(u,((a=r.get(u))!=null?a:0)+1);}let o=hx(t,n,r);for(let d of n){let u=Nu(d.dataset.pageNumber,1),p=xn(d.dataset.sectionIndex,0),f=Nu(d.dataset.sectionPageNumber,u),b=((s=o.get(p))!=null?s:u)+f-1,w=(l=r.get(p))!=null?l:f;d.dataset.displayPageNumber=String(b);for(let g of Array.from(d.querySelectorAll("[data-field-kind]")))g.dataset.fieldKind==="pageNumber"?g.textContent=String(b):g.dataset.fieldKind==="totalPages"?g.textContent=String(n.length):g.dataset.fieldKind==="sectionPages"&&(g.textContent=String(w)),g.dataset.pageNumber=String(b),g.dataset.sectionPageNumber=String(f),g.dataset.totalPages=String(n.length),g.dataset.sectionPages=String(w);}}function hx(e,t,n){let r=[],o=new Set;for(let i of t){let a=xn(i.dataset.sectionIndex,0);o.has(a)||(o.add(a),r.push(a));}return gx(e.sections,r,n)}function gx(e,t,n){var i,a;let r=new Map,o=1;for(let s of t){let l=e.find(u=>u.sectionIndex===s),d=(i=l==null?void 0:l.pageNumberStart)!=null?i:o;r.set(s,d),o=d+((a=n.get(s))!=null?a:0);}return r}function Nu(e,t){let n=Number(e);return Number.isInteger(n)&&n>0?n:t}function xn(e,t){let n=Number(e);return Number.isInteger(n)&&n>=0?n:t}function bx(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 Zr(e,t={}){return e.kind==="paragraph"?Jr(e,t):af(e)}function Jr(e,t={}){var a,s,l,d,u,p,f,b,w,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),((a=e.format)==null?void 0:a.outlineLevel)!==void 0&&n.setAttribute("data-outline-level",String(e.format.outlineLevel)),(s=e.format)!=null&&s.hasNumbering&&(n.setAttribute("data-numbering","true"),n.setAttribute("data-numbering-label",(d=(l=e.format.numbering)==null?void 0:l.label)!=null?d:"\u2022")),(u=e.format)!=null&&u.pageBreakBefore&&n.setAttribute("data-page-break-before","true"),(p=e.format)!=null&&p.hasSectionBreak&&n.setAttribute("data-section-break","true"),(f=e.format)!=null&&f.keepNext&&n.setAttribute("data-keep-next","true"),(b=e.format)!=null&&b.keepLines&&n.setAttribute("data-keep-lines","true"),((w=e.format)==null?void 0:w.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=wx(e,t)?H(v({},e.format),{snapToGrid:true,spacing:H(v({},(y=(h=e.format)==null?void 0:h.spacing)!=null?y:{}),{line:t.implicitGridLinePitch,lineRule:"exact"})}):e.format,o=Wr(r).cssText;o.length>0&&n.setAttribute("style",o),n.contentEditable="inherit",n.tabIndex=0,n.setAttribute("role","textbox"),n.spellcheck=false;let i=yx(e);if(i)return n.classList.add("has-tab-stops"),n.appendChild(i),n;for(let S of e.content)if(S.kind==="text")n.appendChild(Fs(S));else if(S.kind==="field")n.appendChild(rf(S));else if(S.kind==="image")n.appendChild(Ds(S));else if(S.kind==="drawing")n.appendChild(Cx(S));else {let E=document.createElement("span");E.className="coco-word-page-break",E.contentEditable="false",E.setAttribute("data-kind","page-break"),E.setAttribute("aria-label","Page break"),n.appendChild(E);}return n.childNodes.length===0&&n.appendChild(document.createTextNode("")),n}function Ds(e){var r,o,i,a;let t=document.createElement("img"),n=jr(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=(a=e.formatRevision.date)!=null?a:"",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`),Wx(t,e),t}function wx(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 xx(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 yx(e){var d,u,p;let t=(d=e.format)==null?void 0:d.tabStops;if(!t||t.length===0)return null;let n=e.content.reduce((f,b)=>f+(b.kind==="text"?kx(b.text):0),0);if(n!==1&&n!==2||!e.content.every(f=>f.kind==="text"))return null;let r=t.find(f=>f.alignment==="right");if(!r)return null;let o=r.leader!==void 0&&r.leader!=="none",i=vx(e);if(!o&&!Sx(i))return null;let a=document.createElement("span");a.className=n===2?"coco-word-tab-row is-three-part-tab":"coco-word-tab-row is-right-tab",a.style.setProperty("--coco-word-tab-stop",Bn(r.position)),o&&(a.classList.add(`has-leader-${r.leader}`),a.dataset.tabLeader=r.leader);let s=Array.from({length:n+1},(f,b)=>{let w=document.createElement("span");return w.className=`coco-word-tab-segment is-segment-${b}`,w}),l=0;for(let f of e.content){if(f.kind!=="text")continue;let b=f.text.split(" ");for(let w=0;w<b.length;w++){let g=(u=b[w])!=null?u:"";g.length>0&&((p=s[l])==null||p.appendChild(Fs(H(v({},f),{text:g})))),w<b.length-1&&(l=Math.min(l+1,s.length-1));}}for(let f=0;f<s.length;f++){if(f>0){let b=document.createElement("span");b.className="coco-word-tab-marker",b.textContent=" ",a.appendChild(b);}a.appendChild(s[f]);}return a}function vx(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 a=1;a<i.length;a++)t.push((r=i[a])!=null?r:"");}return t}function Sx(e){return e.length<2||e.length>3?false:e.every(t=>t.trim().length<=32)}function kx(e){return e.split(" ").length-1}function Cx(e){var i,a,s,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&&!e.isLineOrConnector&&t.classList.add("has-border"),e.hasFill&&t.classList.add("has-fill"),e.isLineOrConnector){t.classList.add("is-line-or-connector");let d=Ix(e);t.classList.add(d.vertical?"is-vertical-line":"is-horizontal-line"),t.style[d.property]=d.value;}let n=((a=(i=e.text)==null?void 0:i.trim().length)!=null?a:0)>0||((l=(s=e.paragraphs)==null?void 0:s.some(d=>d.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=Tx(e);if(o&&(t.style.width=o),e.isLineOrConnector?e.height&&(t.style.height=`${e.height}px`):e.height&&Nx(e)&&(t.style.minHeight=`${e.height}px`),Lx(t,e),e.paragraphs&&e.paragraphs.length>0)for(let d of e.paragraphs)t.appendChild(Rx(d));else if(e.text&&e.text.length>0){let d=document.createElement("span");d.className="coco-word-native-drawing-text",e.innerTextAlign&&(d.style.textAlign=Hx(e.innerTextAlign)),d.textContent=e.text,t.appendChild(d);}else t.setAttribute("aria-label",e.drawingKind);return t}function Ex(e){var t,n;return ((t=e.height)!=null?t:0)>Math.max(1,((n=e.width)!=null?n:0)*2)}function Ix(e){var n,r;let t=Ex(e);return {vertical:t,property:t?"borderLeft":"borderTop",value:`${(n=e.strokeWidth)!=null?n:1}px solid ${(r=e.strokeColor)!=null?r:"#111827"}`}}function Nx(e){return !(e.drawingKind==="textBox"&&!e.hasBorder&&!e.hasFill)}function Tx(e){if(!e.width)return;if(e.anchoringMode==="anchor"&&Px(e.wrap))return `${e.width}px`;let t=e.isLineOrConnector?"100%":"max(1px, calc(100% - 4pt))";return `min(${e.width}px, ${t})`}function Px(e){return e==="none"||e==="behind"||e==="inFront"}function Rx(e){let t=document.createElement("div");t.className="coco-word-native-drawing-paragraph";let n=Wr(e.format).cssText;n.length>0&&t.setAttribute("style",n);for(let r of e.content)r.kind==="text"?t.appendChild(Fs(r)):r.kind==="field"?t.appendChild(rf(r)):(r.kind==="image"||r.kind==="drawing")&&t.appendChild(document.createTextNode(r.kind==="drawing"&&r.text?r.text:"\uFFFC"));return t}function Fs(e){var a,s,l,d,u,p,f,b,w;if(e.kind!=="text")return document.createTextNode("");let t=Yn(e.format).cssText,n=(a=e.marks)==null?void 0:a.find(g=>g.kind==="comment"),r=(s=e.marks)==null?void 0:s.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=Ur(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=(d=e.hyperlink.anchor)!=null?d:"",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=Mx(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=(p=r.author)!=null?p:"",i.dataset.revisionDate=(f=r.date)!=null?f:"",i.title=Ax(r)),o&&(i.classList.add("coco-word-revision-format"),i.dataset.revisionId=o.revisionId,i.dataset.revisionKind="format",i.dataset.revisionAuthor=(b=o.author)!=null?b:"",i.dataset.revisionDate=(w=o.date)!=null?w:"",i.title="\u683C\u5F0F\u4FEE\u8BA2"),i.appendChild(document.createTextNode(e.text)),i}function rf(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=Yn(e.format).cssText;return n.length>0&&t.setAttribute("style",n),t.contentEditable="false",t.textContent=(r=e.cachedText)!=null?r:"",t}function Mx(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 Ax(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 Lx(e,t){t.anchoringMode==="anchor"&&(e.classList.add("coco-word-anchor-drawing"),of(e,t));}function Wx(e,t){t.anchoringMode==="anchor"&&(e.classList.add("coco-word-anchor-image"),of(e,t));}function of(e,t){let n=Bx(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 Bx(e){var s,l,d,u;let t=[],n={},r={};Dx(e.position,n,r);let o=Fx(e.position),i=(l=(s=e.position)==null?void 0:s.horizontal)==null?void 0:l.relativeFrom,a=(u=(d=e.position)==null?void 0:d.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"),Ps(a)?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 Dx(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"]=`${Rs(r.posOffset)}px`),(o==null?void 0:o.posOffset)!==void 0&&(t.positionVerticalOffset=String(o.posOffset),n["--coco-word-anchor-top"]=`${Rs(o.posOffset)}px`);}function Fx(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=Rs(t.posOffset);return n<=8?"left":n>=240?"right":null}function Hx(e){return e==="both"?"justify":e}function af(e){var a,s,l,d;let t=document.createElement("coco-word-native-table");t.setAttribute("data-table-id",e.tableId),jx(e)||(t.classList.add("shows-auxiliary-gridlines"),t.dataset.auxiliaryGridlines="true"),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=(a=e.revision.author)!=null?a:"",t.dataset.revisionDate=(s=e.revision.date)!=null?s:"",t.dataset.revisionText="\u8868\u683C\u7ED3\u6784"),e.tableStyleId&&t.setAttribute("data-style-id",e.tableStyleId);let n=document.createElement("table"),r=Gx(e);if(r&&n.style.setProperty("--coco-word-table-border",r),Vx(n,e),e.columnWidths.some(u=>u>0)){let u=document.createElement("colgroup"),p=0;for(let f of e.columnWidths)p+=Math.max(0,f);for(let f of e.columnWidths){let b=document.createElement("col");f>0&&(b.style.width=((l=e.layout)==null?void 0:l.widthType)==="pct"&&p>0?`${f/p*100}%`:Bn(f)),u.appendChild(b);}n.appendChild(u),p>0&&n.style.width.length===0&&(n.style.width=Bn(p));}let o=document.createElement("tbody"),i=Ox(e);for(let u=0;u<e.rows.length;u+=1){let p=e.rows[u],f=document.createElement("tr");if(f.dataset.rowIndex=String(u),p.isHeader&&(f.dataset.repeatHeader="true"),p.cantSplit&&(f.dataset.cantSplit="true"),p.height&&p.height.val>0){let w=Bn(p.height.val);f.dataset.heightRule=(d=p.height.hRule)!=null?d:"auto",f.style.setProperty("--coco-word-row-height",w),p.height.hRule,f.style.height=w;}let b=0;for(let w of p.cells){let g=Math.max(1,w.gridSpan),h=b;if(b+=g,w.vMerge==="continue")continue;let y=document.createElement("td");y.dataset.rowIndex=String(u),y.dataset.cellIndex=String(p.cells.indexOf(w)),y.dataset.columnIndex=String(h),w.gridSpan>1&&(y.colSpan=w.gridSpan),w.rowSpan&&w.rowSpan>1&&(y.rowSpan=w.rowSpan);let S=ti(H(v({},w),{borders:$x(e,w,{rowIndex:u,rowCount:e.rows.length,columnIndex:h,columnSpan:g,columnCount:i})})).cssText;S.length>0&&y.setAttribute("style",S),y.contentEditable="true";for(let E of w.blocks){let N=Zr(E);for(let A of [...N.matches("coco-word-native-p")?[N]:[],...Array.from(N.querySelectorAll("coco-word-native-p"))])A.contentEditable="true";y.appendChild(N);}f.appendChild(y);}o.appendChild(f);}return n.appendChild(o),t.appendChild(n),Bs(t),t}function Ox(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 $x(e,t,n){var o;let r=e.borders;if(!(!r&&!t.borders))return v(v({},zx(r,n)),(o=t.borders)!=null?o:{})}function zx(e,t){var s,l,d,u;if(!e)return {};let n={val:"nil"},r=t.rowIndex===0,o=t.rowIndex>=t.rowCount-1,i=t.columnIndex===0,a=t.columnIndex+t.columnSpan>=t.columnCount;return {top:(s=r?e.top:e.insideH)!=null?s:n,right:(l=a?e.right:e.insideV)!=null?l:n,bottom:(d=o?e.bottom:e.insideH)!=null?d:n,left:(u=i?e.left:e.insideV)!=null?u:n}}function Vx(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=Bn(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=Bn(n.indent)),n.cellSpacing!==void 0&&n.cellSpacing>0&&(e.style.borderCollapse="separate",e.style.borderSpacing=n.cellSpacingType==="pct"?`${n.cellSpacing/50}%`:Bn(n.cellSpacing)));}function Bn(e){return `${e/20}pt`}function It(e){return `${Hs(e)}px`}function Hs(e){return e/15}function Rs(e){return e/914400*96}function Gx(e){var i,a,s,l,d,u,p,f,b,w,g;let t=(g=(b=(p=(d=(s=(i=e.borders)==null?void 0:i.insideH)!=null?s:(a=e.borders)==null?void 0:a.insideV)!=null?d:(l=e.borders)==null?void 0:l.top)!=null?p:(u=e.borders)==null?void 0:u.left)!=null?b:(f=e.borders)==null?void 0:f.bottom)!=null?g:(w=e.borders)==null?void 0:w.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 jx(e){let t=n=>Object.values(n!=null?n:{}).some(r=>r!==void 0&&r.val!=="none"&&r.val!=="nil");return t(e.borders)||e.rows.some(n=>n.cells.some(r=>t(r.borders)))}function Wn(e){customElements.get(e)||customElements.define(e,class extends HTMLElement{});}function Tt(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 mt(e){var o;let t=Tt(e);if(!t||t.rangeCount===0)return null;let n=t.getRangeAt(0),r=Nt(n.startContainer);return !r||!e.contains(r)?null:{paraId:(o=r.dataset.paraId)!=null?o:"",offset:wi(r,n.startContainer,n.startOffset)}}function lt(e){let t=mt(e);return t?{kind:"caret",paraId:t.paraId,offset:t.offset}:null}function Ve(e){var a,s;let t=Tt(e);if(!t||t.rangeCount===0||!t.anchorNode||!t.focusNode)return null;let n=Nt(t.anchorNode),r=Nt(t.focusNode);if(!n||!r||!e.contains(n)||!e.contains(r))return null;let o={paraId:(a=n.dataset.paraId)!=null?a:"",offset:wi(n,t.anchorNode,t.anchorOffset)},i={paraId:(s=r.dataset.paraId)!=null?s:"",offset:wi(r,t.focusNode,t.focusOffset)};return t.isCollapsed?{kind:"caret",paraId:o.paraId,offset:o.offset}:{kind:"text-range",anchor:o,focus:i}}function lf(e,t,n){var i;let r=Ux(t,n);if(!r)return null;let o=Nt(r.node);return !o||!e.contains(o)?null:{paraId:(i=o.dataset.paraId)!=null?i:"",offset:wi(o,r.node,r.offset)}}function dt(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=Fn(n,t.offset);r.setStart(o.node,o.offset),r.setEnd(o.node,o.offset);let i=Tt(e);i&&(i.removeAllRanges(),i.addRange(r));}function vn(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=Fn(r,t.offset),a=Fn(o,n.offset),s=Tt(e);s&&(r.focus({preventScroll:true}),s.removeAllRanges(),s.setBaseAndExtent(i.node,i.offset,a.node,a.offset));}function df(e,t){let n=Nt(t);if(!n||!e.contains(n))return false;let r=document.createRange();r.selectNodeContents(t);let o=Tt(e);return o?(n.focus({preventScroll:true}),o.removeAllRanges(),o.addRange(r),true):false}function cf(e,t,n,r){let o=e.querySelector(`coco-word-native-p[data-para-id="${t}"]`);if(!o)return null;let i=Fn(o,n),a=Fn(o,r),s=document.createRange();return s.setStart(i.node,i.offset),s.setEnd(a.node,a.offset),s}function Os(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=Fn(r,t.offset),a=Fn(o,n.offset),s=document.createRange();return s.setStart(i.node,i.offset),s.setEnd(a.node,a.offset),s}function Ux(e,t){var i,a;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=(a=n.caretRangeFromPoint)==null?void 0:a.call(n,e,t);return o?{node:o.startContainer,offset:o.startOffset}:null}function uf(e,t){Pt(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 Pt(e){e.querySelectorAll("coco-word-native-p img.is-selected").forEach(t=>{t.classList.remove("is-selected");});}function xi(e,t){var i,a;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+=(a=(i=o.textContent)==null?void 0:i.length)!=null?a:0:o instanceof HTMLImageElement&&(n+=1),o=r.nextNode();}return n}function Nt(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 wi(e,t,n){let r=0,o=null,i=a=>{var s,l,d,u;if(o===null){if(a===t){if(a.nodeType===Node.TEXT_NODE){o=r+Math.max(0,Math.min(n,(l=(s=a.textContent)==null?void 0:s.length)!=null?l:0));return}let p=Math.max(0,Math.min(n,a.childNodes.length));for(let f=0;f<p;f+=1)r+=ff(a.childNodes[f]);o=r;return}if(a.nodeType===Node.TEXT_NODE){r+=(u=(d=a.textContent)==null?void 0:d.length)!=null?u:0;return}if($s(a)){r+=1;return}for(let p=0;p<a.childNodes.length;p+=1)i(a.childNodes[p]);}};return i(e),o!=null?o:r}function ff(e){var n,r;if(e.nodeType===Node.TEXT_NODE)return (r=(n=e.textContent)==null?void 0:n.length)!=null?r:0;if($s(e))return 1;let t=0;for(let o=0;o<e.childNodes.length;o+=1)t+=ff(e.childNodes[o]);return t}function Fn(e,t){var a,s;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=(s=(a=r.textContent)==null?void 0:a.length)!=null?s:0;if(o<=l)return {node:r,offset:o};o-=l;}else if($s(r)){if(o===0)return sf(r,"before");if(o===1)return sf(r,"after");o-=1;}r=n.nextNode();}let i=document.createTextNode("");return e.appendChild(i),{node:i,offset:0}}function $s(e){return e instanceof HTMLElement&&(e instanceof HTMLImageElement||e.classList.contains("coco-word-page-break"))}function sf(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 zs(e,t){if(t.query.length===0)return [];let n=t.matchCase?"gu":"giu",r=new RegExp(_x(t.query),n),o=[];for(let i of mf(e.blocks)){let a=Ne(i);for(let s of a.matchAll(r)){let l=s.index,d=l+s[0].length;t.wholeWord&&!Kx(a,l,d)||o.push({id:`${i.paraId}:${l}:${d}`,paraId:i.paraId,from:l,to:d,text:s[0]});}}return o}function mf(e){return e.flatMap(t=>t.kind==="paragraph"?[t]:t.rows.flatMap(n=>n.cells.flatMap(r=>mf(r.blocks))))}function Kx(e,t,n){let r=t>0?e[t-1]:"",o=n<e.length?e[n]:"";return !pf(r)&&!pf(o)}function pf(e){return e.length>0&&/[\p{L}\p{N}_]/u.test(e)}function _x(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var yi="application/x-coco-word-blocks+json";function gf(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 s;let i={text:"",runs:[]},a=o.closest("li");return a&&(i.listType=((s=a.parentElement)==null?void 0:s.tagName)==="OL"?"numbered":"bullet"),vf(o,{},i),i.text=i.text.replace(/\u00a0/g," "),i})}function js(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=Xx(o);t+=n?`<li>${i}</li>`:`<p>${i}</p>`;}return n&&(t+=n==="numbered"?"</ol>":"</ul>"),t}function Us(e){return JSON.stringify({version:1,blocks:e})}function bf(e){if(!e||e.length>2e7)return null;try{let t=JSON.parse(e);return !Qr(t)||t.version!==1||!Array.isArray(t.blocks)||t.blocks.length===0||t.blocks.length>1e3?null:t.blocks.every(xf)?t.blocks:null}catch(t){return null}}function Ks(e){return e.map(wf).join(`
16
- `)}function wf(e){return e.kind==="paragraph"?Ne(e):e.rows.map(t=>t.cells.map(n=>n.blocks.map(wf).join(`
15
+ `),u=[a.paraId],f=a.paraId,p=Math.max(0,Math.min(a.offset,Te(l).length)),b=on(e,f,p,(w=d[0])!=null?w:"");b&&s.push(b);for(let F=1;F<d.length;F+=1){let L=Bn(e),V=Cs(e,f,p+((h=(g=d[F-1])==null?void 0:g.length)!=null?h:0),L);if(!V)return null;s.push(V),u.push(L),f=L,p=0;let ee=on(e,f,0,(y=d[F])!=null?y:"");ee&&s.push(ee);}return {changes:s,cursor:{paraId:f,offset:d.length===1?p+((k=(S=d[0])==null?void 0:S.length)!=null?k:0):(A=(I=d[d.length-1])==null?void 0:I.length)!=null?A:0},paragraphIds:u}}function vs(e,t,n,r,o){var u;let i=Z(e,t),a=Mt(n,r);if(!i||a.from===a.to)return null;let s=0,l=false,d=[];for(let f of i.content){let p=Ve(f);if(f.kind!=="text"||s+p<=a.from||s>=a.to){d.push(f),s+=p;continue}let b=Math.max(0,a.from-s),w=Math.min(p,a.to-s);b>0&&d.push(O(v({},f),{text:f.text.slice(0,b)})),w>b&&(d.push(O(v({},f),{text:f.text.slice(b,w),format:v(v({},(u=f.format)!=null?u:{}),o)})),l=true),w<p&&d.push(O(v({},f),{text:f.text.slice(w)})),s+=p;}return l?(i.content=$e(d),{kind:"format",op:"run",paraId:t,from:a.from,to:a.to,format:o}):null}function Ss(e,t,n,r,o){var f,p,b;let i=Z(e,t),a=Mt(n,r);if(!i||a.from===a.to)return null;let s=0,l=false,d=[],u=O(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 w of i.content){let g=Ve(w);if(w.kind!=="text"||s+g<=a.from||s>=a.to){d.push(w),s+=g;continue}let h=Math.max(0,a.from-s),y=Math.min(g,a.to-s);if(h>0&&d.push(O(v({},w),{text:w.text.slice(0,h)})),y>h){let S=w.text.slice(h,y);if(o.preserveExistingComments&&((f=w.marks)!=null&&f.some(k=>k.kind==="comment")))d.push(O(v({},w),{text:S})),d.push(O(v({},w),{text:S,marks:[u,...(p=w.marks)!=null?p:[]]}));else {let k=((b=w.marks)!=null?b:[]).filter(I=>I.kind!=="comment");d.push(O(v({},w),{text:S,marks:[...k,u]}));}l=true;}y<g&&d.push(O(v({},w),{text:w.text.slice(y)})),s+=g;}return l?(i.content=$e(d),{kind:"annotation",op:"insert",paraId:t,from:a.from,to:a.to,commentId:o.commentId,body:o.body,parentCommentId:o.parentCommentId}):null}function su(e,t,n){let r=[];for(let o of _e(e)){let i=0,a=null,s=null,l=false,d=o.content.map(u=>{var b,w;let f=Ve(u);return u.kind!=="text"||!((b=u.marks)==null?void 0:b.find(g=>g.kind==="comment"&&g.commentId===t))?(i+=f,u):(a=a===null?i:a,s=i+f,l=true,i+=f,O(v({},u),{marks:(w=u.marks)==null?void 0:w.map(g=>g.kind==="comment"&&g.commentId===t?O(v({},g),{body:n}):g)}))});!l||a===null||s===null||(o.content=$e(d),r.push({kind:"annotation",op:"update",paraId:o.paraId,from:a,to:s,commentId:t,body:n}));}return r}function lu(e,t){let n=[];for(let r of _e(e)){let o=0,i=null,a=null,s=false,l=r.content.map(d=>{var b,w,g;let u=Ve(d);if(d.kind!=="text"||!((w=(b=d.marks)==null?void 0:b.some(h=>h.kind==="comment"&&h.commentId===t))!=null?w:false))return o+=u,d;i=i===null?o:i,a=o+u,s=true,o+=u;let p=(g=d.marks)==null?void 0:g.filter(h=>!(h.kind==="comment"&&h.commentId===t));return p&&p.length>0?O(v({},d),{marks:p}):O(v({},d),{marks:void 0})});!s||i===null||a===null||(r.content=$e(l),n.push({kind:"annotation",op:"delete",paraId:r.paraId,from:i,to:a,commentId:t}));}return n}function $t(e,t,n,r,o){var f,p;let i=Z(e,t),a=Mt(n,r);if(!i||a.from===a.to)return null;let s=0,l=false,d=[],u={kind:"revision",id:`revision:${o.revisionId}`,revisionId:o.revisionId,revisionKind:o.revisionKind,author:o.author,date:o.date};for(let b of i.content){let w=Ve(b);if(b.kind!=="text"||s+w<=a.from||s>=a.to){d.push(b),s+=w;continue}let g=Math.max(0,a.from-s),h=Math.min(w,a.to-s);if(g>0&&d.push(O(v({},b),{text:b.text.slice(0,g)})),h>g){let y=((f=b.marks)!=null?f:[]).find(S=>S.kind==="revision");if(!(o.revisionKind==="delete"&&(y==null?void 0:y.revisionKind)==="insert")){let S=((p=b.marks)!=null?p:[]).filter(k=>k.kind!=="revision");d.push(O(v({},b),{text:b.text.slice(g,h),marks:[...S,u]}));}l=true;}h<w&&d.push(O(v({},b),{text:b.text.slice(h)})),s+=w;}return l?(i.content=$e(d),{kind:"revision",op:o.revisionKind,paraId:t,from:a.from,to:a.to,revisionId:o.revisionId,revisionKind:o.revisionKind}):null}function du(e,t,n,r,o){var p,b,w,g;let i=Z(e,t),a=Mt(n,r);if(!i||a.from===a.to)return null;let s=0,l=false,d="",u="insert",f=[];for(let h of i.content){let y=Ve(h);if(h.kind!=="text"||s+y<=a.from||s>=a.to){f.push(h),s+=y;continue}let S=Math.max(0,a.from-s),k=Math.min(y,a.to-s);if(S>0&&f.push(O(v({},h),{text:h.text.slice(0,S)})),k>S){let I=h.text.slice(S,k),A=((p=h.marks)!=null?p:[]).find(F=>F.kind==="revision");A?(l=true,d=(b=A.revisionId)!=null?b:A.id.replace(/^revision:/,""),u=(w=A.revisionKind)!=null?w:"insert",(o==="accept"?u==="insert":u==="delete")&&f.push(O(v({},h),{text:I,marks:((g=h.marks)!=null?g:[]).filter(L=>L.kind!=="revision")}))):f.push(O(v({},h),{text:I}));}k<y&&f.push(O(v({},h),{text:h.text.slice(k)})),s+=y;}return l?(i.content=$e(f),{kind:"revision",op:o,paraId:t,from:a.from,to:a.to,revisionId:d,revisionKind:u}):null}function cu(e,t,n,r,o){let i=Z(e,t),a=Mt(n,r);if(!i||a.from===a.to)return null;let s=0,l=false,d="",u=[];for(let f of i.content){let p=Ve(f);if(f.kind!=="text"||s+p<=a.from||s>=a.to){u.push(f),s+=p;continue}let b=Math.max(0,a.from-s),w=Math.min(p,a.to-s);if(b>0&&u.push(O(v({},f),{text:f.text.slice(0,b)})),w>b){let g=f.formatRevision;g?(d=g.revisionId,l=true,u.push(O(v({},f),{text:f.text.slice(b,w),format:o==="reject"?g.beforeFormat?v({},g.beforeFormat):null:f.format,formatRevision:void 0}))):u.push(O(v({},f),{text:f.text.slice(b,w)}));}w<p&&u.push(O(v({},f),{text:f.text.slice(w)})),s+=p;}return l?(i.content=$e(u),{kind:"format",op:o,paraId:t,from:a.from,to:a.to,format:{},revisionId:d,revisionKind:"format"}):null}function ks(e,t,n,r,o){var f;let i=Z(e,t),a=Mt(n,r);if(!i||a.from===a.to)return null;let s=o?Cw(o):null;if(o&&!s)return null;let l=0,d=false,u=[];for(let p of i.content){let b=Ve(p);if(p.kind!=="text"||l+b<=a.from||l>=a.to){u.push(p),l+=b;continue}let w=Math.max(0,a.from-l),g=Math.min(b,a.to-l);if(w>0&&u.push(O(v({},p),{text:p.text.slice(0,w)})),g>w){let h=O(v({},p),{text:p.text.slice(w,g)});s?h.hyperlink=v({},s):delete h.hyperlink,u.push(h),gs((f=p.hyperlink)!=null?f:null,s)||(d=true);}g<b&&u.push(O(v({},p),{text:p.text.slice(g)})),l+=b;}return d?(i.content=$e(u),v({kind:"hyperlink",op:s?"set":"remove",paraId:t,from:a.from,to:a.to},s?{hyperlink:s}:{})):null}function er(e,t,n){var i,a,s;let r=Z(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({},(a=o.indent)!=null?a:{}),n.indent)),n.spacing&&(r.format.spacing=v(v({},(s=o.spacing)!=null?s:{}),n.spacing)),{kind:"format",op:"paragraph",paraId:t,format:n}}function uu(e,t,n,r){let o=Z(e,t),i=Mt(n,r);if(!o||i.from===i.to)return null;let a=0,s=false,l=[];for(let d of o.content){let u=Ve(d);if(d.kind!=="text"||a+u<=i.from||a>=i.to){l.push(d),a+=u;continue}let f=Math.max(0,i.from-a),p=Math.min(u,i.to-a);f>0&&l.push(O(v({},d),{text:d.text.slice(0,f)})),p>f&&(l.push(O(v({},d),{text:d.text.slice(f,p),format:null})),d.format&&Object.keys(d.format).length>0&&(s=true)),p<u&&l.push(O(v({},d),{text:d.text.slice(p)})),a+=u;}return s?(o.content=$e(l),{kind:"format",op:"run",paraId:t,from:i.from,to:i.to,format:{},clear:true}):null}function jr(e,t,n){var i,a,s;let r=Z(e,t);if(!r)return null;let o=(i=r.format)!=null?i:{};if(n)r.format=O(v({},o),{hasNumbering:true,numbering:v({},n),indent:v(v({},(a=o.indent)!=null?a:{}),Oc(n.ilvl))});else {let l=O(v({},o),{hasNumbering:false,indent:O(v({},(s=o.indent)!=null?s:{}),{left:0,firstLine:0})});delete l.numbering,r.format=l;}return {kind:"list",paraId:t,numbering:n?v({},n):null}}function KE(e,t,n,r){var l;let o=Z(e,t),i=Mt(n,r);if(!o||i.from===i.to)return false;let a=0,s=false;for(let d of o.content){let u=Ve(d);if(d.kind==="text"&&a+u>i.from&&a<i.to&&(s=true,((l=d.format)==null?void 0:l.bold)!==true))return false;a+=u;}return s}function fu(e,t,n){let r=Z(e,t);if(!r)return null;let o=0,i=[],a=null;for(let s of r.content)!a&&s.kind==="image"&&s.drawingId===n?a={kind:"image",op:"delete",paraId:t,offset:o,drawingId:n}:i.push(s),o+=Ve(s);return a?(r.content=$e(i),a):null}function pu(e,t,n,r,o,i){var p;let a=Z(e,t),s=Mt(n,r);if(!a||s.from===s.to)return null;let l=0,d=false,u=[],f=b=>{let w=0;for(let g of o.content){let h=Ve(g);if(g.kind==="text"&&b>=w&&b<w+h)return g.format?v({},g.format):null;w+=h;}return null};for(let b of a.content){let w=Ve(b);if(b.kind!=="text"||l+w<=s.from||l>=s.to){u.push(b),l+=w;continue}let g=Math.max(0,s.from-l),h=Math.min(w,s.to-l);g>0&&u.push(O(v({},b),{text:b.text.slice(0,g)})),h>g&&(u.push(O(v({},b),{text:b.text.slice(g,h),formatRevision:(p=b.formatRevision)!=null?p:{kind:"format",revisionId:i.revisionId,beforeFormat:f(l+g),author:i.author,date:i.date}})),d=true),h<w&&u.push(O(v({},b),{text:b.text.slice(h)})),l+=w;}return d?(a.content=$e(u),{kind:"format",op:"run",paraId:t,from:s.from,to:s.to,format:{},revisionId:i.revisionId,revisionKind:"format",beforeFormat:f(s.from)}):null}function mu(e,t,n,r){let o=Z(e,t);if(!o)return null;let i=0;for(let a=0;a<o.content.length;a+=1){let s=o.content[a];if((s==null?void 0:s.kind)!=="image"||s.drawingId!==n){i+=s?Ve(s):0;continue}let l=s.revision;return l?(l.revisionKind==="delete"&&r==="accept"||l.revisionKind==="insert"&&r==="reject"?o.content.splice(a,1):s.revision=void 0,o.content=$e(o.content),{kind:"image",op:r,paraId:t,offset:i,drawingId:n,revisionId:l.revisionId,revisionKind:l.revisionKind}):null}return null}function hu(e,t,n,r){let o=Z(e,t);if(!o)return null;let i=0;for(let a of o.content){if(a.kind!=="image"||a.drawingId!==n){i+=Ve(a);continue}let s=a.formatRevision;if(!s)return null;r==="reject"&&(a.width=s.beforeWidth,a.height=s.beforeHeight);let l=s.revisionId;return a.formatRevision=void 0,{kind:"image",op:r,paraId:t,offset:i,drawingId:n,revisionId:l,revisionKind:"format"}}return null}function Cs(e,t,n,r=Bn(e)){let o=ve(e,t);if(!o)return null;let{paragraph:i}=o,a=wn(i.content,n);return i.content=a.before,o.insertAfter({kind:"paragraph",paraId:r,story:i.story,styleId:i.styleId,format:i.format?JSON.parse(JSON.stringify(i.format)):null,content:a.after}),{kind:"block",op:"split",paraId:t,newParaId:r,offset:n}}function Ur(e,t,n){let r=Z(e,t);if(!r||r.content.some(s=>s.kind!=="text"))return null;let o=Te(r);if(o===n)return null;let i=Ew(o,n),a=r.content;return i.deletedText.length>0&&(a=gw(a,i.offset,i.deletedText.length)),i.insertedText.length>0&&(a=gu(a,i.offset,i.insertedText,yu(r.content,i.offset))),r.content=a,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 gu(e,t,n,r=null){let o=[],i=0,a=false;for(let s of e){let l=Ve(s);if(!a&&t<=i+l){if(s.kind==="text"){let d=Math.max(0,t-i);o.push(O(v({},s),{text:`${s.text.slice(0,d)}${n}${s.text.slice(d)}`}));}else t<=i?o.push({kind:"text",text:n,format:r},s):o.push(s,{kind:"text",text:n,format:r});a=true;}else o.push(s);i+=l;}return a||o.push({kind:"text",text:n,format:r}),$e(o)}function gw(e,t,n){if(n<=0)return e;let r=[],o=0,i=t+n;for(let a of e){let s=Ve(a),l=o+s;if(a.kind!=="text"||l<=t||o>=i)r.push(a);else {let d=Math.max(0,t-o),u=Math.max(0,l-i),f=`${a.text.slice(0,d)}${a.text.slice(a.text.length-u)}`;f.length>0&&r.push(O(v({},a),{text:f}));}o=l;}return $e(r)}function bw(e,t){return bu(e,t-1)}function ww(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 bu(e,t){if(t<0)return null;let n=[],r=0,o=null;for(let i of e.content){let a=Ve(i);if(!o&&t>=r&&t<r+a)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 s=t-r,l=i.text.slice(s,s+1),d=`${i.text.slice(0,s)}${i.text.slice(s+1)}`;d.length>0&&n.push(O(v({},i),{text:d})),o={kind:"text",op:"delete",paraId:e.paraId,offset:t,text:l};}else n.push(i);else n.push(i);r+=a;}return o?(e.content=$e(n),o):null}function xw(e,t,n){let r=[],o=[],i=0;for(let a of e.content){let s=Ve(a),l=i+s;if(!(t<l&&n>i)){r.push(a),i=l;continue}if(a.kind==="text"){let u=Math.max(0,t-i),f=Math.min(a.text.length,n-i),p=a.text.slice(u,f),b=`${a.text.slice(0,u)}${a.text.slice(f)}`;b.length>0&&r.push(O(v({},a),{text:b})),p.length>0&&o.push({kind:"text",op:"delete",paraId:e.paraId,offset:i+u,text:p});}else a.kind==="image"?o.push({kind:"image",op:"delete",paraId:e.paraId,offset:i,drawingId:a.drawingId}):a.kind==="pageBreak"?o.push({kind:"page-break",op:"delete",paraId:e.paraId,offset:i}):r.push(a);i=l;}return {content:$e(r),changes:o.sort((a,s)=>jc(s)-jc(a))}}function wn(e,t){let n=[],r=[],o=0,i=false;for(let a of e){let s=Ve(a);if(!i&&t<=o+s){if(a.kind==="text"){let l=Math.max(0,t-o);l>0&&n.push(O(v({},a),{text:a.text.slice(0,l)})),l<a.text.length&&r.push(O(v({},a),{text:a.text.slice(l)}));}else t<=o?r.push(a):n.push(a);i=true;}else i?r.push(a):n.push(a);o+=s;}return {before:$e(n),after:$e(r)}}function Ve(e){return e.kind==="text"?e.text.length:1}function di(e){if(!(!Number.isFinite(e)||e===void 0||e<=0))return Math.max(1,Math.round(e*100)/100)}function Mt(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 jc(e){return "offset"in e&&typeof e.offset=="number"?e.offset:0}function $e(e){var n,r,o,i;let t=[];for(let a of e)if(a.kind==="text"){if(a.text.length===0)continue;let s=t[t.length-1];(s==null?void 0:s.kind)==="text"&&kw(s.format,a.format)&&gs((n=s.hyperlink)!=null?n:null,(r=a.hyperlink)!=null?r:null)&&gs((o=s.marks)!=null?o:null,(i=a.marks)!=null?i:null)?s.text+=a.text:t.push(v({},a));}else t.push(a);return t}function Ot(e){let t=JSON.parse(JSON.stringify(e));return Es(t),t}function wu(e){return e.kind==="paragraph"?e.paraId:e.tableId}function yw(e,t,n){let r=ve(e,t.paraId),o=ve(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(a=>a.kind!=="text")||i.end.paragraph.content.some(a=>a.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 vw(e){return e.slice(1,-1).some(t=>t.kind==="table"||t.content.some(n=>n.kind!=="text"))}function xu(e,t){let n=Ot(t),r=new Set(_e(e).map(d=>d.paraId)),o=new Set,i=new Set;ci(e.blocks,d=>{if(d.kind==="table")i.add(d.tableId);else for(let u of d.content)(u.kind==="image"||u.kind==="drawing")&&o.add(u.drawingId);});let a=Date.now()>>>0,s=()=>{let d="";do a=a+1>>>0,d=a.toString(16).toUpperCase().padStart(8,"0");while(r.has(d));return r.add(d),d},l=(d,u)=>{let f=1;for(;d.has(`${u}-${f}`);)f+=1;let p=`${u}-${f}`;return d.add(p),p};return ci(n,d=>{if(d.kind==="table"){d.tableId=l(i,"coco-clipboard-table");return}d.paraId=s();for(let u of d.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=s();}),Es(n),n}function Sw(e){let t=new Set;for(let r of [e.blocks,...e.headers.map(o=>o.blocks),...e.footers.map(o=>o.blocks)])ci(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 ci(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)ci(o.blocks,t);}function Es(e){for(let t of e)if(t.kind==="table")for(let n of t.rows)for(let r of n.cells)Es(r.blocks),r.paragraphs=Or(r.blocks);}function Or(e){return e.flatMap(t=>t.kind==="paragraph"?[t]:t.rows.flatMap(n=>n.cells.flatMap(r=>Or(r.blocks))))}function li(e){return e.reduce((t,n)=>t+Ve(n),0)}function kw(e,t){return JSON.stringify(e!=null?e:null)===JSON.stringify(t!=null?t:null)}function Cw(e){var o,i,a;let t=(o=e.target)==null?void 0:o.trim(),n=(i=e.anchor)==null?void 0:i.trim().replace(/^#/,""),r=(a=e.tooltip)==null?void 0:a.trim();return !t&&!n?null:v(v(v({},t?{target:t}:{}),n?{anchor:n}:{}),r?{tooltip:r}:{})}function gs(e,t){return JSON.stringify(e)===JSON.stringify(t)}function yu(e,t){let n=0,r=null;for(let o of e){let i=Ve(o);if(o.kind==="text"){if(t>=n&&t<=n+i)return o.format;r=o.format;}n+=i;}return r}function Ew(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 vu=/^data:(image\/(?:png|jpeg|gif|webp));base64,([a-z0-9+/]*={0,2})$/i,Iw=new Set(["http:","https:","mailto:","tel:"]);function Kr(e){let t=e.trim();return vu.test(t)?t:null}function Su(e){let t=Kr(e),n=t?vu.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 _r(e,t){if(e)try{let n=new URL(e.trim());if(Iw.has(n.protocol))return n.href}catch(n){}return t?`#${encodeURIComponent(t)}`:"#"}var ku=260,Cu=typeof Intl.Segmenter=="function"?new Intl.Segmenter(void 0,{granularity:"word"}):void 0;function Ru(){Dn("coco-word-native-document"),Dn("coco-word-native-page"),Dn("coco-word-native-page-body"),Dn("coco-word-native-story"),Dn("coco-word-native-p"),Dn("coco-word-native-drawing"),Dn("coco-word-native-table");}function Mu(e){var a,s;let t=document.createElement("coco-word-native-document");t.contentEditable="true",t.spellcheck=false,Nw(e)&&t.classList.add("uses-natural-paragraph-flow"),Pw(e)&&t.classList.add("uses-compact-latin-tables"),Rw(e)&&t.classList.add("uses-rowspan-table-group-splitting");let n=Jn((a=e.defaults)==null?void 0:a.run).cssText;n.length>0&&t.setAttribute("style",n);for(let l of e.headers)t.appendChild(Tu(l));let r=Tw(e),o=r!==void 0&&Ms(e);for(let l of e.blocks)t.appendChild(Jr(l,{implicitGridForParagraphs:o,implicitGridLinePitch:r})),Cx(l)&&(o=false);for(let l of e.footers)t.appendChild(Tu(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"),((s=e.pageLayout)==null?void 0:s.width)!==void 0)t.style.minWidth=`${Hs(e.pageLayout.width)+ku}px`;else {let l=`calc(100% + ${ku}px)`;t.style.width=l,t.style.minWidth=l;}return t}function Nw(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:!Ms(e)}function Tw(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 Pw(e){return e.blocks.some(t=>t.kind==="table")&&!Ms(e)}function Rw(e){return e.blocks.filter(n=>n.kind==="table").length<10?false:Mw(e)<=5}function Mw(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,a)=>i+Au(a),0),0),0)}function Ms(e){let t=0,n=0;for(let r of e.blocks.slice(0,160)){for(let o of Aw(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 Aw(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 Lu(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"),a=r.filter(y=>y instanceof HTMLElement&&y.tagName.toLowerCase()!=="coco-word-native-story");e.replaceChildren();let s=new Map,l=0,d=Xr(t,l,n),u=(y=l)=>{var k;let S=((k=s.get(y))!=null?k:0)+1;return s.set(y,S),l=y,d=Xr(t,y,n),Ju(e,t,d,o,i,e.children.length+1,y,S)},f=u(),p=f.querySelector("coco-word-native-page-body"),b=()=>Math.max(120,Math.round(p.getBoundingClientRect().height)||gx(d)),w=()=>(f=u(),p=f.querySelector("coco-word-native-page-body"),p),g=y=>{var I,A,F;if(y===l||p.children.length>0)return;let S=(I=s.get(l))!=null?I:0;S>1?s.set(l,S-1):s.delete(l);let k=((A=s.get(y))!=null?A:0)+1;s.set(y,k),l=y,d=Xr(t,y,n),Qu(f,t,d,o,i,Number((F=f.dataset.pageNumber)!=null?F:"1"),y,k);},h=(y,S)=>{var V;let k=(V=Vw(y,t))!=null?V:l;p.children.length===0&&g(k),hi(y)&&p.children.length>0&&(w(),g(k)),p.appendChild(y);let I=fx(y);I&&bi(f);let A=y.querySelector(".coco-word-page-break")!==null;if(p.scrollHeight>b()){let ee=$w(p,y);if(!Uw(y,p,b,w)){p.removeChild(y),ee&&p.removeChild(ee);let fe=ee?null:jw(y,p,b);w(),g(k),ee&&p.appendChild(ee),p.appendChild(fe!=null?fe:y);}}else if(y.matches("coco-word-native-table")){let ee=S&&gi(S,t),ae=S&&ee&&ee!=="continuous"&&ee!=="nextColumn"&&!Zu(S)||S&&hi(S),oe=f.querySelector(':scope > coco-word-native-story[data-story-kind="footer"]:not(.is-empty)');(!ae||oe&&y.getBoundingClientRect().bottom>oe.getBoundingClientRect().top)&&_w(y,p,b,w,!S);}I||bi(f);let F=gi(y,t),L=zw(y,t);L!==null&&(l=L),(A||F)&&Gw(w,F);};for(let y=0;y<a.length;y+=1)h(a[y],a[y+1]);Ku(e),_u(e),Xu(e),af(e,t),yn(e);}function Wu(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=an(e),a=i.indexOf(o);if(a<0)return false;let s=Hw(e),l=false,d=false;for(let u=a;u<i.length;u+=1){let f=i[u],p=zt(f);if(p)for(;pi(p);){if(Bw(e,t,f,i[u+1],s)){i=an(e),l=true;continue}let b=Ww(p);if(b.length===0||b.length>=p.children.length)break;let w=i[u+1];(!w||mi(f,w,t))&&(w=Du(e,t,f,w,s),i=an(e),d=true);let g=zt(w);if(!g)break;for(let h of [...b].reverse())g.insertBefore(h,g.firstChild);l=true;}}i=an(e),a=Math.max(0,Math.min(a,Math.max(0,i.length-1))-1);for(let u=a;u<i.length-1;u+=1){let f=i[u],p=i[u+1],b=zt(f),w=zt(p);if(!(!b||!w||mi(f,p,t))){for(;Dw(b,w);)l=true;for(;;){let g=Ls(w);if(g.length===0||!Bu(b,g[0],t))break;for(let h of g)b.appendChild(h);if(pi(b,8)){for(let h of [...g].reverse())w.insertBefore(h,w.firstChild);if(g.length>1){let h=g[0];if(b.appendChild(h),!pi(b,8)){l=true;continue}w.insertBefore(h,w.firstChild);}break}l=true;}qu(p)&&(p.remove(),i=an(e),u-=1,d=true);}}return l?(Ku(e),_u(e),Xu(e),d&&Ow(e,t,s),af(e,t),yn(e),true):false}function As(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"),a=an(e),s=i?a.indexOf(i):-1;if(!o||!i||s<0)return r;let l=zt(i);if(!l)return r;let d=Math.max(120,Math.round(l.getBoundingClientRect().height)),u=Math.max(0,l.scrollHeight-d),f=a[s-1],p=f?zt(f):null,b=!!(f&&p&&Ls(l).some(y=>Fu(y,n))&&Eu(f,i,p,l,t)),w=a[s+1],g=w?zt(w):null,h=!!(w&&g&&Eu(i,w,l,g,t));return {overflowPx:u,canBackfillPrevious:b,canBackfillNext:h}}function Eu(e,t,n,r,o){if(mi(e,t,o))return false;let i=Math.max(0,Math.round(n.getBoundingClientRect().height)-Uu(n));if(i<=0)return false;let a=n.lastElementChild,s=r.firstElementChild;if(a instanceof HTMLElement&&s instanceof HTMLElement&&a.matches("coco-word-native-table")&&s.matches("coco-word-native-table")&&a.dataset.tableId===s.dataset.tableId){let d=Array.from(s.querySelectorAll(":scope > table > tbody > tr")).filter(f=>f.dataset.repeatedHeader!=="true"),u=Zr(d)[0];if(u&&!Hn(u)&&Ou(u)<=i+8)return true}let l=Ls(r);return l.length===0||!Bu(n,l[0],o)?false:Lw(l)<=i+8}function Lw(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 Vt(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=an(e),a=o?i.indexOf(o):-1;if(a<0)return false;let s=false;for(let l of t.blocks){if(l.kind!=="table")continue;let d=Array.from(e.querySelectorAll(`coco-word-native-table[data-table-id="${l.tableId}"]`)),u=d[0],f=u==null?void 0:u.closest("coco-word-native-page");if(!(!u||!f||i.indexOf(f)<a)){u.replaceWith(df(l));for(let p of d.slice(1))p.remove();s=true;}}return s}function an(e){return Array.from(e.children).filter(t=>t instanceof HTMLElement&&t.tagName.toLowerCase()==="coco-word-native-page")}function zt(e){return e.querySelector(":scope > coco-word-native-page-body")}function pi(e,t=1){let n=Math.max(120,Math.round(e.getBoundingClientRect().height));return e.scrollHeight>n+t}function Ww(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 Ls(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 Bw(e,t,n,r,o){let i=zt(n),a=i==null?void 0:i.lastElementChild;if(!(a instanceof HTMLElement)||!a.matches("coco-word-native-table"))return false;let s=a.querySelector(":scope > table"),l=s==null?void 0:s.querySelector(":scope > tbody");if(!s||!l)return false;let u=Array.from(l.children).filter(yi).filter(k=>k.dataset.repeatedHeader!=="true"),f=Zr(u);if(f.length<2)return false;let p=f[f.length-1];if(Hn(p))return false;let b=r;(!b||mi(n,b,t))&&(b=Du(e,t,n,b,o));let w=zt(b);if(!w)return false;let g=a.dataset.tableId,h=Array.from(w.children).find(k=>k instanceof HTMLElement&&k.matches("coco-word-native-table")&&k.dataset.tableId===g);if(!h){Ws(s),h=tr(a,s),w.insertBefore(h,w.firstChild);let k=h.querySelector(":scope > table > tbody");k&&qr(k,Fw(e,g));}let y=h.querySelector(":scope > table > tbody");if(!y)return false;let S=Array.from(y.children).find(k=>k instanceof HTMLTableRowElement&&k.dataset.repeatedHeader!=="true");Yr(l,p);for(let k of p)y.insertBefore(k,S!=null?S:null);return true}function Dw(e,t){var d,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 a=Array.from(i.children).filter(yi).filter(f=>f.dataset.repeatedHeader!=="true"),s=Zr(a)[0];if(!s||Hn(s))return false;let l=(u=(d=s[s.length-1])==null?void 0:d.nextElementSibling)!=null?u:null;if(nr(o,s),pi(e,8)){for(let f of s)i.insertBefore(f,l);return false}return i.querySelector('tr:not([data-repeated-header="true"])')===null&&r.remove(),true}function Fw(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 mi(e,t,n){if(e.dataset.sectionIndex!==t.dataset.sectionIndex)return true;let r=zt(e),o=zt(t),i=r==null?void 0:r.lastElementChild,a=o==null?void 0:o.firstElementChild;if(a instanceof HTMLElement&&hi(a))return true;if(!(i instanceof HTMLElement))return false;if(i.querySelector(".coco-word-page-break"))return true;let s=gi(i,n);return s!==null&&s!=="continuous"&&s!=="nextColumn"}function Bu(e,t,n){if(hi(t))return false;let r=e.lastElementChild;if(!(r instanceof HTMLElement))return true;if(r.querySelector(".coco-word-page-break"))return false;let o=gi(r,n);return o===null||o==="continuous"||o==="nextColumn"}function Hw(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 a=i.dataset.storyKind,s=`${a!=null?a:""}:${(o=i.dataset.partName)!=null?o:""}`;t.has(s)||(t.add(s),a==="header"&&n.push(i),a==="footer"&&r.push(i));}return {headers:n,footers:r}}function Du(e,t,n,r,o){let i=an(e),a=i.indexOf(n),s=xn(n.dataset.sectionIndex,0),l=i.slice(0,a+1).filter(u=>xn(u.dataset.sectionIndex,0)===s).length+1,d=Ju(e,t,Xr(t,s,t.pageLayout),o.headers,o.footers,a+2,s,l);return r&&e.insertBefore(d,r),d}function Ow(e,t,n){for(let r of an(e)){let o=xn(r.dataset.pageNumber,1),i=xn(r.dataset.sectionIndex,0),a=xn(r.dataset.sectionPageNumber,1);Qu(r,t,Xr(t,i,t.pageLayout),n.headers,n.footers,o,i,a);}}function hi(e){return e.matches('coco-word-native-p[data-page-break-before="true"]')}function $w(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 gi(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 zw(e,t){let n=t.sections.find(r=>r.lastParaId&&Fu(e,r.lastParaId));return n?Math.min(n.sectionIndex+1,Math.max(0,t.sections.length-1)):null}function Vw(e,t){if(t.sections.length===0)return null;let n=Hu(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 Fu(e,t){return Hu(e).includes(t)}function Hu(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 Gw(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 jw(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=At(e);if(r<2)return null;let o=null,i=1,a=r-1;for(;i<=a;){let s=Math.floor((i+a)/2),l=$u(e,s);if(!l||At(l.head)===0||At(l.tail)===0){a=s-1;continue}t.appendChild(l.head),t.scrollHeight<=n()?((o==null?void 0:o.head.parentElement)===t&&t.removeChild(o.head),o=l,i=s+1):(t.removeChild(l.head),a=s-1);}return !o||o.head.parentElement!==t?null:o.tail}function Uw(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"),a=i?Array.from(i.children).filter(yi):[],s=Zr(a);if(!o||s.length<2)return false;Ws(o),e.remove();let l=t,d=tr(e,o),u=d.querySelector("tbody"),f=a.filter(w=>w.dataset.repeatHeader==="true"),p=Kw(s,f),b=0;l.appendChild(d);for(let w of s){let g=Hn(w);if(!g&&b>=p&&(l=r(),d=tr(e,o),u=d.querySelector("tbody"),l.appendChild(d),qr(u,f),b=0),nr(u,w),g||(b+=1),l.children.length<=1&&u.children.length<=w.length||l.scrollHeight<=n())continue;Yr(u,w),g||(b=Math.max(0,b-1));let h=qw(u,w,l,n()),y=h!=null?h:Jw(u,w,l,n()),S=y!=null?y:Qw(u,w,l,n());if(S){g||(b+=1),l=r(),d=tr(e,o),u=d.querySelector("tbody"),l.appendChild(d),b=0,qr(u,f),nr(u,S),g||(b=1);continue}u.children.length===0&&l.removeChild(d),l=r(),d=tr(e,o),u=d.querySelector("tbody"),l.appendChild(d),b=0,g||qr(u,f),nr(u,w),g||(b=1);}return true}function Kw(e,t){let n=e.filter(r=>!Hn(r)).length;return t.length===0||n<30?Number.POSITIVE_INFINITY:8}function _w(e,t,n,r,o){var k;let i=n(),a=i-Uu(t),s=dx(e,i);if(a>=s||o&&sx(t,i))return false;let l=e.querySelector(":scope > table"),d=l==null?void 0:l.querySelector(":scope > tbody"),u=d?Array.from(d.children).filter(yi):[],f=Zr(u);if(!l||!d||f.length<4)return false;Ws(l);let p=u.filter(I=>I.dataset.repeatHeader==="true"),b=a,w=0,g=[];for(;f.length>1&&b+w<s;){let I=f.pop();if(!I||Hn(I))break;w+=Ou(I),Yr(d,I),g.unshift(I);}if(g.length===0)return false;let h=r(),y=tr(e,l),S=y.querySelector("tbody");h.appendChild(y),Hn((k=g[0])!=null?k:[])||qr(S,p);for(let I of g)nr(S,I);return true}function Ou(e){return e.reduce((t,n)=>t+n.getBoundingClientRect().height,0)}function qw(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 a=Xw(t,i);if(a){o&&Yr(e,o.head);for(let s of a.head)e.appendChild(s);if(n.scrollHeight<=r)o=a;else {Yr(e,a.head),o&&nr(e,o.head);break}}}return o?o.tail:null}function Xw(e,t){if(t<=0||t>=e.length)return null;let n=Yw(e),r=e.slice(0,t).map(a=>a.cloneNode(true)),o=e.slice(t).map(a=>a.cloneNode(true)),i=n.filter(a=>a.row<t&&a.row+a.rowSpan>t);if(i.length===0)return null;for(let a of i){let s=r[a.row],l=s==null?void 0:s.cells[a.cellIndex];l&&(l.rowSpan=t-a.row);let d=a.cell.cloneNode(false);d.rowSpan=a.row+a.rowSpan-t,d.colSpan=a.colSpan,d.dataset.rowFragmentContinuation="true",d.classList.add("is-rowspan-continuation"),Zw(o[0],d,a.column,n,t);}return {head:r,tail:o}}function Yw(e){var r,o;let t=[],n=[];for(let i=0;i<e.length;i+=1){let a=e[i],s=0;for(let l=0;l<a.cells.length;l+=1){for(;((r=n[s])!=null?r:0)>i;)s+=1;let d=a.cells[l],u=Math.max(1,d.colSpan),f=Math.max(1,d.rowSpan);t.push({row:i,cellIndex:l,column:s,colSpan:u,rowSpan:f,cell:d});for(let p=0;p<u;p+=1)n[s+p]=Math.max((o=n[s+p])!=null?o:0,i+f);s+=u;}}return t}function Zw(e,t,n,r,o){let a=r.filter(l=>l.row===o).sort((l,d)=>l.column-d.column).find(l=>l.column>n),s=a?e.cells[a.cellIndex]:null;e.insertBefore(t,s!=null?s:null);}function Jw(e,t,n,r){if(t.length!==1)return null;let o=t[0];if(!ox(o))return null;let i=null,a=0,s=1;for(let l=0;l<8;l+=1){let d=(a+s)/2,u=ix(o,d);if(!u){s=d;continue}e.appendChild(u.head),n.scrollHeight<=r?((i==null?void 0:i.head.parentElement)===e&&e.removeChild(i.head),i=u,a=d):(e.removeChild(u.head),s=d);}return !i||i.head.parentElement!==e?null:[i.tail]}function Qw(e,t,n,r){if(t.length!==1)return null;let o=t[0];if(!ex(o))return null;let i=null,a=0,s=1;for(let l=0;l<9;l+=1){let d=(a+s)/2,u=tx(o,d);if(!u){s=d;continue}e.appendChild(u.head),n.scrollHeight<=r?((i==null?void 0:i.head.parentElement)===e&&e.removeChild(i.head),i=u,a=d):(e.removeChild(u.head),s=d);}return !i||i.head.parentElement!==e?null:[i.tail]}function ex(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=>Vu(n))?false:Gu(e)?t.some(n=>Ns(n)):t.every(n=>Ns(n))}function tx(e,t){let n=Nu(e),r=Nu(e);for(let o of Array.from(e.cells)){let i=nx(o,t);if(!i)return null;n.appendChild(i.head),r.appendChild(i.tail);}return {head:n,tail:r}}function nx(e,t){if(!Ns(e))return ju(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=At(n),o=Math.max(1,Math.min(r-1,Math.round(r*t))),i=$u(n,o);if(!i||At(i.head)===0||At(i.tail)===0)return null;let a=e.cloneNode(false),s=e.cloneNode(false);return a.appendChild(i.head),s.appendChild(i.tail),{head:a,tail:s}}function $u(e,t){let n=At(e);if(!Number.isInteger(t)||t<=0||t>=n)return null;let r=e.cloneNode(false),o=e.cloneNode(false);return zu(Array.from(e.childNodes),t,r,o),r.dataset.splitFragment="head",o.dataset.splitFragment="tail",{head:r,tail:o}}function zu(e,t,n,r){let o=t;for(let i of e){let a=At(i);if(a===0){o>0?n.appendChild(i.cloneNode(true)):r.appendChild(i.cloneNode(true));continue}if(a<=o){n.appendChild(i.cloneNode(true)),o-=a;continue}if(o<=0){r.appendChild(i.cloneNode(true));continue}rx(i,o,n,r),o=0;}}function rx(e,t,n,r){var a;if(e.nodeType===Node.TEXT_NODE){let s=(a=e.textContent)!=null?a:"";n.appendChild(document.createTextNode(s.slice(0,t))),r.appendChild(document.createTextNode(s.slice(t)));return}if(!(e instanceof HTMLElement))return;let o=e.cloneNode(false),i=e.cloneNode(false);zu(Array.from(e.childNodes),t,o,i),At(o)>0&&n.appendChild(o),At(i)>0&&r.appendChild(i);}function At(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+At(o),0)}function ox(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=>Vu(n))?false:Gu(e)?t.some(n=>Is(n)):t.every(n=>Is(n))}function ix(e,t){let n=Iu(e),r=Iu(e);for(let o of Array.from(e.cells)){let i=ax(o,t);if(!i)return null;n.appendChild(i.head),r.appendChild(i.tail);}return {head:n,tail:r}}function ax(e,t){if(!Is(e))return ju(e);let n=Array.from(e.childNodes).filter(a=>a 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 a=0;a<n.length;a+=1){let s=n[a].cloneNode(true);a<r?o.appendChild(s):i.appendChild(s);}return {head:o,tail:i}}function Vu(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 Gu(e){var t;return ((t=e.closest("coco-word-native-document"))==null?void 0:t.classList.contains("uses-natural-paragraph-flow"))===true}function Is(e){return Array.from(e.childNodes).filter(t=>t instanceof HTMLElement).length>=2}function Ns(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"&&At(t[0])>1}function ju(e){let t=e.cloneNode(true),n=e.cloneNode(false);return n.dataset.rowFragmentStatic="true",{head:t,tail:n}}function Iu(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 Nu(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 sx(e,t){return e.scrollHeight>t+1?false:lx(e)<=t*.75}function lx(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,a=Number.parseFloat(o.marginBottom)||0;t+=r.height+i+a;}return t}function Uu(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),a=Number.parseFloat(i.marginBottom)||0;n=Math.max(n,o.bottom-t.top+a);}return n}function dx(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 nr(e,t){for(let r of t)e.appendChild(r);let n=e.closest("coco-word-native-table");n&&Bs(n);}function Hn(e){var t;return ((t=e[0])==null?void 0:t.dataset.repeatHeader)==="true"}function qr(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 Yr(e,t){for(let n of t)n.parentElement===e&&e.removeChild(n);}function Ws(e){if(e.dataset.layout!=="autofit"||e.hasAttribute("data-shared-grid"))return;let t=Array.from(e.querySelectorAll(":scope > colgroup > col")),n=getComputedStyle(e).width,r=t.map(o=>getComputedStyle(o).width);!n.endsWith("px")||parseFloat(n)<=0||!r.length||r.some(o=>!o.endsWith("px"))||(e.dataset.sharedGrid="true",e.style.tableLayout="fixed",e.style.width=n,t.forEach((o,i)=>{o.style.width=r[i];}));}function tr(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 Ku(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(!cx(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"),a=n.querySelector(":scope > .coco-word-native-page-overlay"),s=n.querySelector(":scope > .coco-word-native-page-behind-layer");if(!o||!i||!a&&!s)return;if(s){let l=Ts(r,"behind");for(let d of Array.from(s.children))l.appendChild(d);}if(a){let l=Ts(r,"front");for(let d of Array.from(a.children))l.appendChild(d);}for(let l of Array.from(i.children))o.appendChild(l);n.remove();}}function _u(e){for(let t of Array.from(e.querySelectorAll("coco-word-native-page")))qu(t)&&t.remove();}function qu(e){var r,o,i,a;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)+((a=(i=e.querySelector(":scope > .coco-word-native-page-behind-layer"))==null?void 0:i.children.length)!=null?a:0)===0}function Xu(e){let t=new Map;Array.from(e.querySelectorAll(":scope > coco-word-native-page")).forEach((r,o)=>{var s;let i=xn(r.dataset.sectionIndex,0),a=((s=t.get(i))!=null?s:0)+1;t.set(i,a),r.dataset.pageNumber=String(o+1),r.dataset.sectionPageNumber=String(a);});}function cx(e){var a,s;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=((a=n==null?void 0:n.children.length)!=null?a:0)+((s=r==null?void 0:r.children.length)!=null?s: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 d;return l.matches("coco-word-native-p.is-flow-empty")&&((d=l.textContent)!=null?d:"").trim().length===0&&l.getBoundingClientRect().height<=1})}function yi(e){return e instanceof HTMLTableRowElement}function bi(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(!Yu(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 a=r.dataset.wrap==="behind"?"behind":"front";r.dataset.pageLayer=a,r.classList.add("is-page-layer-anchor"),Ts(e,a).appendChild(r);}for(let r of t)r.classList.toggle("is-flow-empty",!Zu(r));ux(e);}function Ts(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(a=>a.tagName.toLowerCase()!=="coco-word-native-story");e.insertBefore(o,i!=null?i:e.firstChild);}else e.appendChild(o);return o}function ux(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 Yu(e){let t=e.dataset.positionVerticalRelativeFrom,n=e.dataset.positionHorizontalRelativeFrom;return Ps(t||n)}function Ps(e){return e==="page"||e==="margin"}function fx(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")&&Yu(r))}function Zu(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 Ju(e,t,n,r,o,i,a,s){let l=document.createElement("coco-word-native-page");l.dataset.pageNumber=String(i),l.dataset.sectionIndex=String(a),l.dataset.sectionPageNumber=String(s);let d=rf(t,a,i,s);l.dataset.displayPageNumber=String(d),of(l,n);for(let u of wi(t,"header",i,a,s,r))l.appendChild(xi(u,d,s));l.appendChild(document.createElement("coco-word-native-page-body"));for(let u of wi(t,"footer",i,a,s,o))l.appendChild(xi(u,d,s));return bi(l),e.appendChild(l),l}function Qu(e,t,n,r,o,i,a,s){var u,f;let l=e.querySelector("coco-word-native-page-body");if(!l)return;e.dataset.sectionIndex=String(a),e.dataset.sectionPageNumber=String(s);let d=rf(t,a,i,s);e.dataset.displayPageNumber=String(d),of(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 wi(t,"header",i,a,s,r))e.insertBefore(xi(p,d,s),l);for(let p of wi(t,"footer",i,a,s,o))e.appendChild(xi(p,d,s));bi(e);}function yn(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=hx(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,a)=>i.top-a.top||i.commentId-a.commentId).forEach((i,a)=>{let s=document.createElement("aside");s.className="coco-word-native-comment-bubble",s.dataset.annotationAnchorTop=String(i.top),s.dataset.commentId=String(i.commentId),s.dataset.commentBody=i.body,i.parentCommentId!==void 0&&Number.isFinite(i.parentCommentId)&&(s.dataset.parentCommentId=String(i.parentCommentId),s.classList.add("coco-word-native-comment-reply")),i.paraId&&(s.dataset.paraId=i.paraId),i.from!==void 0&&(s.dataset.from=String(i.from)),i.to!==void 0&&(s.dataset.to=String(i.to)),s.style.setProperty("--coco-word-comment-index",String(a));let l=document.createElement("div");l.className="coco-word-native-comment-meta",l.textContent=[i.author||`Comment ${i.commentId}`,i.date?ef(i.date):""].filter(Boolean).join(" \xB7 "),i.parentCommentId!==void 0&&Number.isFinite(i.parentCommentId)&&(l.textContent=`\u56DE\u590D #${i.parentCommentId} \xB7 ${l.textContent}`);let d=document.createElement("div");d.className="coco-word-native-comment-body",d.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[b,w]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=b,g.dataset.commentId=String(i.commentId),g.textContent=w,p.appendChild(g);}u.appendChild(p),s.appendChild(l),s.appendChild(d),s.appendChild(u),o.appendChild(s);});}px(n),mx(n);}}function px(e){var s,l,d,u,f,p,b,w,g,h,y;(s=e.querySelector(":scope > .coco-word-native-revision-layer"))==null||s.remove();let t=new Map,n=e.getBoundingClientRect();for(let S 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 k=(l=S.dataset.revisionId)!=null?l:"";if(!k)continue;let I=S.dataset.revisionKind==="format"?"format":S.dataset.revisionKind==="delete"||S.classList.contains("coco-word-revision-delete")?"delete":"insert",A=S.getBoundingClientRect(),F=`${I}:${k}`,L=t.get(F),V=tf(S);t.set(F,{id:k,kind:I,author:(d=S.dataset.revisionAuthor)!=null?d:"",date:(u=S.dataset.revisionDate)!=null?u:"",text:`${(f=L==null?void 0:L.text)!=null?f:""}${(b=(p=S.dataset.revisionText)!=null?p:S.textContent)!=null?b:""}`,top:(w=L==null?void 0:L.top)!=null?w:Math.max(0,A.top-n.top),paraId:(g=L==null?void 0:L.paraId)!=null?g:V==null?void 0:V.paraId,from:(h=L==null?void 0:L.from)!=null?h:V==null?void 0:V.from,to:(y=V==null?void 0:V.to)!=null?y:L==null?void 0:L.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((S,k)=>S.top-k.top||S.id.localeCompare(k.id)),i=new Map;for(let S of o){let k=S.paraId?`paragraph:${S.paraId}`:`position:${Math.round(S.top/48)}`,I=i.get(k);I?I.push(S):i.set(k,[S]);}let a=S=>{let k=document.createElement("aside");k.className=`coco-word-native-revision-bubble is-${S.kind}`,k.dataset.annotationAnchorTop=String(S.top),k.dataset.revisionId=S.id,k.dataset.revisionKind=S.kind,S.paraId&&(k.dataset.paraId=S.paraId),S.from!==void 0&&(k.dataset.from=String(S.from)),S.to!==void 0&&(k.dataset.to=String(S.to));let I=document.createElement("div");I.className="coco-word-native-revision-header";let A=document.createElement("span");A.className="coco-word-native-revision-meta",A.textContent=[S.author||"User",ef(S.date)].filter(Boolean).join(" \xB7 "),I.appendChild(A),k.appendChild(I);let F=document.createElement("div");F.className="coco-word-native-revision-content",F.textContent=S.text||"(\u7A7A\u5185\u5BB9)",k.appendChild(F);let L=document.createElement("div");L.className="coco-word-native-revision-actions";for(let[V,ee,fe]of [["accept","\u2713","\u63A5\u53D7\u4FEE\u8BA2"],["reject","\xD7","\u62D2\u7EDD\u4FEE\u8BA2"]]){let ae=document.createElement("button");ae.type="button",ae.dataset.revisionAction=V,ae.dataset.revisionId=S.id,ae.dataset.revisionKind=S.kind,ae.textContent=ee,ae.setAttribute("aria-label",fe),ae.title=fe,ae.className=`is-${V}`,L.appendChild(ae);}return k.appendChild(L),k};for(let S of i.values()){if(S.length===1){r.appendChild(a(S[0]));continue}let k=document.createElement("section");k.className="coco-word-native-revision-group",k.dataset.annotationAnchorTop=String(S[0].top);let I=S[0].paraId;I&&(k.dataset.paraId=I);let A=document.createElement("button");A.type="button",A.className="coco-word-native-revision-group-toggle",A.dataset.revisionGroupToggle="true",A.setAttribute("aria-expanded","false");let F=document.createElement("strong");F.textContent=`\u672C\u6BB5 ${S.length} \u6761\u4FEE\u8BA2`;let L=S.reduce((ae,oe)=>(ae[oe.kind]+=1,ae),{insert:0,delete:0,format:0}),V=document.createElement("span");V.textContent=[L.delete?`${L.delete} \u5220`:"",L.insert?`${L.insert} \u589E`:"",L.format?`${L.format} \u683C\u5F0F`:""].filter(Boolean).join(" \xB7 ");let ee=document.createElement("span");ee.className="coco-word-native-revision-group-affordance",ee.textContent="\u5C55\u5F00",A.append(F,V,ee);let fe=document.createElement("div");fe.className="coco-word-native-revision-group-list",fe.hidden=true,S.forEach(ae=>fe.appendChild(a(ae))),k.append(A,fe),r.appendChild(k);}}function mx(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,a)=>i.anchorTop-a.anchorTop);let r=0;n.forEach((i,a)=>{i.top=Math.max(i.anchorTop,a===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 a=n.length-1;a>=0;a-=1){let s=n[a];s.top=Math.min(s.top,i-s.height),i=s.top-8;}if(n[0].top<0){let a=-n[0].top;n.forEach(s=>{s.top+=a;});}}for(let i of n){let a=i.element.classList.contains("coco-word-native-comment-bubble")?"--coco-word-comment-top":"--coco-word-revision-top";i.element.style.setProperty(a,`${Math.round(i.top)}px`);}}function ef(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 hx(e){var r,o,i,a,s,l,d,u,f,p,b,w,g,h,y,S,k;let t=e.getBoundingClientRect(),n=new Map;for(let I of Array.from(e.querySelectorAll(".coco-word-comment[data-comment-id]"))){let A=Number(I.dataset.commentId);if(!Number.isFinite(A))continue;let F=I.getBoundingClientRect(),L=tf(I),V=n.get(A),ee=!(V!=null&&V.paraId)||!(L!=null&&L.paraId)||V.paraId===L.paraId;n.set(A,{commentId:A,author:(o=(r=V==null?void 0:V.author)!=null?r:I.dataset.commentAuthor)!=null?o:"",date:(a=(i=V==null?void 0:V.date)!=null?i:I.dataset.commentDate)!=null?a:"",body:(l=(s=V==null?void 0:V.body)!=null?s:I.dataset.commentBody)!=null?l:"",top:(d=V==null?void 0:V.top)!=null?d:Math.max(0,F.top-t.top),parentCommentId:(u=V==null?void 0:V.parentCommentId)!=null?u:I.dataset.parentCommentId?Number(I.dataset.parentCommentId):void 0,paraId:(f=V==null?void 0:V.paraId)!=null?f:L==null?void 0:L.paraId,from:ee?Math.min((b=(p=V==null?void 0:V.from)!=null?p:L==null?void 0:L.from)!=null?b:Number.POSITIVE_INFINITY,(w=L==null?void 0:L.from)!=null?w:Number.POSITIVE_INFINITY):(g=V==null?void 0:V.from)!=null?g:L==null?void 0:L.from,to:ee?Math.max((y=(h=V==null?void 0:V.to)!=null?h:L==null?void 0:L.to)!=null?y:Number.NEGATIVE_INFINITY,(S=L==null?void 0:L.to)!=null?S:Number.NEGATIVE_INFINITY):(k=V==null?void 0:V.to)!=null?k:L==null?void 0:L.to});}return Array.from(n.values()).map(I=>v(v(v({},I),Number.isFinite(I.from)?{from:I.from}:{from:void 0}),Number.isFinite(I.to)?{to:I.to}:{to:void 0})).sort((I,A)=>I.top-A.top||I.commentId-A.commentId)}function tf(e){var a;let t=e.closest("coco-word-native-p[data-para-id]");if(!t)return null;let n=0,r=false,o=s=>{var l,d;if(!r){if(s===e){r=true;return}if(s.nodeType===Node.TEXT_NODE){n+=(d=(l=s.textContent)==null?void 0:l.length)!=null?d:0;return}if(!(s instanceof HTMLElement&&s.classList.contains("coco-word-comment-widget")))for(let u of Array.from(s.childNodes))o(u);}};if(o(t),!r)return null;let i=Array.from(e.childNodes).reduce((s,l)=>s+nf(l),0);return {paraId:(a=t.dataset.paraId)!=null?a:"",from:n,to:n+Math.max(1,i)}}function nf(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+nf(o),0)}function Xr(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 rf(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 of(e,t){var r,o,i;e.style.width=It(t.width),e.style.height=It(t.height);let n=Math.abs(t.margin.top);e.toggleAttribute("data-fixed-top-margin",t.margin.top<0),e.style.paddingTop=It(n),e.style.paddingRight=It(t.margin.right),e.style.paddingBottom=It(t.margin.bottom),e.style.paddingLeft=It(t.margin.left),e.style.setProperty("--coco-word-page-margin-top",It(n)),e.style.setProperty("--coco-word-page-margin-left",It(t.margin.left)),e.style.setProperty("--coco-word-page-margin-right",It(t.margin.right)),e.style.setProperty("--coco-word-page-margin-bottom",It(t.margin.bottom)),e.style.setProperty("--coco-word-header-distance",It((r=t.headerDistance)!=null?r:Math.round(n/2))),e.style.setProperty("--coco-word-footer-distance",It((o=t.footerDistance)!=null?o:Math.round(t.margin.bottom/2))),((i=t.docGrid)==null?void 0:i.linePitch)!==void 0&&t.docGrid.linePitch>0?e.style.setProperty("--coco-word-doc-grid-line-height",It(t.docGrid.linePitch)):e.style.removeProperty("--coco-word-doc-grid-line-height");}function gx(e){return Math.max(120,Hs(e.height-Math.abs(e.margin.top)-e.margin.bottom))}function wi(e,t,n,r,o,i){var u,f;if(i.length<=1)return i;let a=(u=e.sections.find(p=>p.sectionIndex===r))!=null?u:e.sections[0],s=bx(e,t,(f=a==null?void 0:a.sectionIndex)!=null?f:r),l=xx(s,(a==null?void 0:a.titlePage)===true,n,o);if(!l&&!wx(e,t))return i;if(l){let p=i.find(b=>b.dataset.partName===l);return p?[p]:[]}let d=i.find(p=>!p.classList.contains("is-empty"));return d?[d]:[i[0]]}function bx(e,t,n){for(let r=n;r>=0;r--){let o=e.sections.find(a=>a.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 wx(e,t){return e.sections.some(n=>t==="header"?n.headerRefs.length>0:n.footerRefs.length>0)}function xx(e,t,n,r){var o,i;if(e.length===0)return null;if(r===1&&t){let a=e.find(s=>s.type==="first");if(a)return a.partName}if(n%2===0){let a=e.find(s=>s.type==="even");if(a)return a.partName}return (i=(o=e.find(a=>a.type==="default"))==null?void 0:o.partName)!=null?i:e[0].partName}function Tu(e){let t=document.createElement("coco-word-native-story");t.setAttribute("data-story-kind",e.kind),t.setAttribute("data-part-name",e.partName),Sx(e)||t.classList.add("is-empty");for(let n of e.blocks)t.appendChild(Jr(n));return t}function xi(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 af(e,t){var i,a,s,l;let n=Array.from(e.querySelectorAll(":scope > coco-word-native-page")),r=new Map;for(let d of n){let u=Number((i=d.dataset.sectionIndex)!=null?i:"0");r.set(u,((a=r.get(u))!=null?a:0)+1);}let o=yx(t,n,r);for(let d of n){let u=Pu(d.dataset.pageNumber,1),f=xn(d.dataset.sectionIndex,0),p=Pu(d.dataset.sectionPageNumber,u),b=((s=o.get(f))!=null?s:u)+p-1,w=(l=r.get(f))!=null?l:p;d.dataset.displayPageNumber=String(b);for(let g of Array.from(d.querySelectorAll("[data-field-kind]")))g.dataset.fieldKind==="pageNumber"?g.textContent=String(b):g.dataset.fieldKind==="totalPages"?g.textContent=String(n.length):g.dataset.fieldKind==="sectionPages"&&(g.textContent=String(w)),g.dataset.pageNumber=String(b),g.dataset.sectionPageNumber=String(p),g.dataset.totalPages=String(n.length),g.dataset.sectionPages=String(w);}}function yx(e,t,n){let r=[],o=new Set;for(let i of t){let a=xn(i.dataset.sectionIndex,0);o.has(a)||(o.add(a),r.push(a));}return vx(e.sections,r,n)}function vx(e,t,n){var i,a;let r=new Map,o=1;for(let s of t){let l=e.find(u=>u.sectionIndex===s),d=(i=l==null?void 0:l.pageNumberStart)!=null?i:o;r.set(s,d),o=d+((a=n.get(s))!=null?a:0);}return r}function Pu(e,t){let n=Number(e);return Number.isInteger(n)&&n>0?n:t}function xn(e,t){let n=Number(e);return Number.isInteger(n)&&n>=0?n:t}function Sx(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 Jr(e,t={}){return e.kind==="paragraph"?Qr(e,t):df(e)}function Qr(e,t={}){var l,d,u,f,p,b,w,g,h,y,S,k,I,A,F,L,V,ee,fe,ae;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),((l=e.format)==null?void 0:l.outlineLevel)!==void 0&&n.setAttribute("data-outline-level",String(e.format.outlineLevel)),(d=e.format)!=null&&d.hasNumbering&&(n.setAttribute("data-numbering","true"),n.setAttribute("data-numbering-label",(f=(u=e.format.numbering)==null?void 0:u.label)!=null?f:"\u2022")),(p=e.format)!=null&&p.pageBreakBefore&&n.setAttribute("data-page-break-before","true"),(b=e.format)!=null&&b.hasSectionBreak&&n.setAttribute("data-section-break","true"),(w=e.format)!=null&&w.keepNext&&n.setAttribute("data-keep-next","true"),(g=e.format)!=null&&g.keepLines&&n.setAttribute("data-keep-lines","true"),((h=e.format)==null?void 0:h.widowControl)!==void 0&&n.setAttribute("data-widow-control",String(e.format.widowControl)),((y=e.format)==null?void 0:y.snapToGrid)!==void 0&&n.setAttribute("data-snap-to-grid",String(e.format.snapToGrid));let r=kx(e,t)?O(v({},e.format),{snapToGrid:true,spacing:O(v({},(k=(S=e.format)==null?void 0:S.spacing)!=null?k:{}),{line:t.implicitGridLinePitch,lineRule:"exact"})}):e.format,o=Dr(r).cssText;o.length>0&&n.setAttribute("style",o),n.contentEditable="inherit",n.tabIndex=0,n.setAttribute("role","textbox"),n.spellcheck=false;let i=Ex(e);if(i)return n.classList.add("has-tab-stops"),n.appendChild(i),n;let a=e.story.startsWith("header:")||e.story.startsWith("footer:");for(let oe of e.content)if(oe.kind==="text"){let ie=Fs(oe),U=(L=(F=(I=oe.format)==null?void 0:I.fontFamily)!=null?F:(A=e.format)==null?void 0:A.fontFamily)!=null?L:"";if(a&&/^(宋体|SimSun)$/i.test(U)&&/ {2}/.test(oe.text)){let J=ie instanceof HTMLElement?ie:document.createElement("span");J.replaceChildren(...oe.text.split(/( {2,})/).filter(Boolean).map(B=>{if(B[0]!==" "||B.trim())return document.createTextNode(B);let G=document.createElement("span");return G.className="coco-word-songti-spaces",G.textContent=B,G})),n.appendChild(J);}else n.appendChild(ie);}else if(oe.kind==="field")n.appendChild(sf(oe));else if(oe.kind==="image")n.appendChild(Ds(oe));else if(oe.kind==="drawing")n.appendChild(Px(oe));else {let ie=document.createElement("span");ie.className="coco-word-page-break",ie.contentEditable="false",ie.setAttribute("data-kind","page-break"),ie.setAttribute("aria-label","Page break"),n.appendChild(ie);}n.childNodes.length===0&&n.appendChild(document.createTextNode(""));let s=(V=n.textContent)!=null?V:"";if(Cu&&((ae=(fe=(ee=e.format)==null?void 0:ee.indent)==null?void 0:fe.firstLine)!=null?ae:0)>0&&/[\u3400-\u9fff]/.test(s)){let oe=0;for(let ie of Cu.segment(s))if(ie.isWordLike&&++oe>1)break;oe===1&&n.classList.add("is-single-cjk-word");}return n}function Ds(e){var r,o,i,a;let t=document.createElement("img"),n=Kr(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=(a=e.formatRevision.date)!=null?a:"",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`),Ox(t,e),t}function kx(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 Cx(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 Ex(e){var f,p,b,w,g,h;let t=(f=e.format)==null?void 0:f.tabStops;if(!t||t.length===0)return null;let n=e.content.reduce((y,S)=>y+(S.kind==="text"?Tx(S.text):0),0);if(n!==1&&n!==2||!e.content.every(y=>y.kind==="text"))return null;let r=t.find(y=>y.alignment==="right");if(!r)return null;let o=r.leader!==void 0&&r.leader!=="none",i=n===1&&!o&&e.content.some(y=>{var S;return y.kind==="text"&&((S=y.format)==null?void 0:S.underline)===true&&y.text.includes(" ")}),a=Ix(e);if(!o&&!Nx(a))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",Fn(r.position)),o&&(s.classList.add(`has-leader-${r.leader}`),s.dataset.tabLeader=r.leader),i&&s.classList.add("has-underlined-tab");let l=Array.from({length:n+1},(y,S)=>{let k=document.createElement("span");return k.className=`coco-word-tab-segment is-segment-${S}`,k}),d=0,u=Array.from({length:l.length});for(let y of e.content){if(y.kind!=="text")continue;let S=y.text.split(" ");for(let k=0;k<S.length;k++){let I=(p=S[k])!=null?p:"",A;if(I.length>0){let F=Fs(O(v({},y),{text:I}));F instanceof HTMLElement&&(A=F),((b=y.format)==null?void 0:b.underline)===true&&A&&(u[d]=A),(w=l[d])==null||w.appendChild(F);}k<S.length-1&&(i&&((g=y.format)==null?void 0:g.underline)===true&&((h=A!=null?A:u[d])==null||h.classList.add("coco-word-underlined-tab-run")),d=Math.min(d+1,l.length-1));}}for(let y=0;y<l.length;y++){if(y>0){let S=document.createElement("span");S.className="coco-word-tab-marker",S.textContent=" ",s.appendChild(S);}s.appendChild(l[y]);}return s}function Ix(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 a=1;a<i.length;a++)t.push((r=i[a])!=null?r:"");}return t}function Nx(e){return e.length<2||e.length>3?false:e.every(t=>t.trim().length<=32)}function Tx(e){return e.split(" ").length-1}function Px(e){var i,a,s,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&&!e.isLineOrConnector&&t.classList.add("has-border"),e.hasFill&&t.classList.add("has-fill"),e.isLineOrConnector){t.classList.add("is-line-or-connector");let d=Mx(e);t.classList.add(d.vertical?"is-vertical-line":"is-horizontal-line"),t.style[d.property]=d.value;}let n=((a=(i=e.text)==null?void 0:i.trim().length)!=null?a:0)>0||((l=(s=e.paragraphs)==null?void 0:s.some(d=>d.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=Lx(e);if(o&&(t.style.width=o),e.isLineOrConnector?e.height&&(t.style.height=`${e.height}px`):e.height&&Ax(e)&&(t.style.minHeight=`${e.height}px`),Hx(t,e),e.paragraphs&&e.paragraphs.length>0)for(let d of e.paragraphs)t.appendChild(Bx(d));else if(e.text&&e.text.length>0){let d=document.createElement("span");d.className="coco-word-native-drawing-text",e.innerTextAlign&&(d.style.textAlign=Gx(e.innerTextAlign)),d.textContent=e.text,t.appendChild(d);}else t.setAttribute("aria-label",e.drawingKind);return t}function Rx(e){var t,n;return ((t=e.height)!=null?t:0)>Math.max(1,((n=e.width)!=null?n:0)*2)}function Mx(e){var n,r;let t=Rx(e);return {vertical:t,property:t?"borderLeft":"borderTop",value:`${(n=e.strokeWidth)!=null?n:1}px solid ${(r=e.strokeColor)!=null?r:"#111827"}`}}function Ax(e){return !(e.drawingKind==="textBox"&&!e.hasBorder&&!e.hasFill)}function Lx(e){if(!e.width)return;if(e.anchoringMode==="anchor"&&Wx(e.wrap))return `${e.width}px`;let t=e.isLineOrConnector?"100%":"max(1px, calc(100% - 4pt))";return `min(${e.width}px, ${t})`}function Wx(e){return e==="none"||e==="behind"||e==="inFront"}function Bx(e){let t=document.createElement("div");t.className="coco-word-native-drawing-paragraph";let n=Dr(e.format).cssText;n.length>0&&t.setAttribute("style",n);for(let r of e.content)r.kind==="text"?t.appendChild(Fs(r)):r.kind==="field"?t.appendChild(sf(r)):(r.kind==="image"||r.kind==="drawing")&&t.appendChild(document.createTextNode(r.kind==="drawing"&&r.text?r.text:"\uFFFC"));return t}function Fs(e){var a,s,l,d,u,f,p,b,w;if(e.kind!=="text")return document.createTextNode("");let t=Jn(e.format).cssText,n=(a=e.marks)==null?void 0:a.find(g=>g.kind==="comment"),r=(s=e.marks)==null?void 0:s.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=_r(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=(d=e.hyperlink.anchor)!=null?d:"",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=Dx(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=Fx(r)),o&&(i.classList.add("coco-word-revision-format"),i.dataset.revisionId=o.revisionId,i.dataset.revisionKind="format",i.dataset.revisionAuthor=(b=o.author)!=null?b:"",i.dataset.revisionDate=(w=o.date)!=null?w:"",i.title="\u683C\u5F0F\u4FEE\u8BA2"),i.appendChild(document.createTextNode(e.text)),i}function sf(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=Jn(e.format).cssText;return n.length>0&&t.setAttribute("style",n),t.contentEditable="false",t.textContent=(r=e.cachedText)!=null?r:"",t}function Dx(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 Fx(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 Hx(e,t){t.anchoringMode==="anchor"&&(e.classList.add("coco-word-anchor-drawing"),lf(e,t));}function Ox(e,t){t.anchoringMode==="anchor"&&(e.classList.add("coco-word-anchor-image"),lf(e,t));}function lf(e,t){let n=$x(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 $x(e){var s,l,d,u;let t=[],n={},r={};zx(e.position,n,r);let o=Vx(e.position),i=(l=(s=e.position)==null?void 0:s.horizontal)==null?void 0:l.relativeFrom,a=(u=(d=e.position)==null?void 0:d.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"),Ps(a)?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 zx(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"]=`${Rs(r.posOffset)}px`),(o==null?void 0:o.posOffset)!==void 0&&(t.positionVerticalOffset=String(o.posOffset),n["--coco-word-anchor-top"]=`${Rs(o.posOffset)}px`);}function Vx(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=Rs(t.posOffset);return n<=8?"left":n>=240?"right":null}function Gx(e){return e==="both"?"justify":e}function df(e){var s,l,d,u,f,p,b,w,g;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=(l=e.revision.date)!=null?l:"",t.dataset.revisionText="\u8868\u683C\u7ED3\u6784"),e.tableStyleId&&t.setAttribute("data-style-id",e.tableStyleId);let n=document.createElement("table");n.dataset.layout=(u=(d=e.layout)==null?void 0:d.mode)!=null?u:"autofit",_x(n,e);let r=jx(e),o=document.createElement("colgroup"),i=e.columnWidths.reduce((h,y)=>h+Math.max(0,y),0);for(let h=0;h<r;h++){let y=(f=e.columnWidths[h])!=null?f:0,S=document.createElement("col");y>0&&(S.style.width=((p=e.layout)==null?void 0:p.widthType)==="pct"?`${y/i*100}%`:Fn(y)),o.appendChild(S);}n.appendChild(o),i>0&&!n.style.width&&(n.style.width=Fn(i));let a=document.createElement("tbody");for(let h=0;h<e.rows.length;h+=1){let y=e.rows[h],S=document.createElement("tr");if(S.dataset.rowIndex=String(h),y.isHeader&&(S.dataset.repeatHeader="true"),y.cantSplit&&(S.dataset.cantSplit="true"),y.height&&y.height.val>0){let I=Fn(y.height.val);S.dataset.heightRule=(b=y.height.hRule)!=null?b:"auto",S.style.setProperty("--coco-word-row-height",I),y.height.hRule,S.style.height=I;}let k=0;for(let I of y.cells){let A=Math.max(1,I.gridSpan),F=k;if(k+=A,I.vMerge==="continue")continue;let L=document.createElement("td");L.dataset.rowIndex=String(h),L.dataset.cellIndex=String(y.cells.indexOf(I)),L.dataset.columnIndex=String(F),I.gridSpan>1&&(L.colSpan=I.gridSpan),I.rowSpan&&I.rowSpan>1&&(L.rowSpan=I.rowSpan);let V=ni(O(v({},I),{borders:Ux(e,I,{rowIndex:h,rowCount:e.rows.length,columnIndex:F,columnSpan:A,columnCount:r})}));V.cssText&&L.setAttribute("style",V.cssText);let ee=((g=(w=e.layout)==null?void 0:w.cellSpacing)!=null?g:0)>0,fe=["top","right","bottom","left"].map(ae=>{let oe=V.declarations[`border-${ae}`];return oe&&oe!=="0"||!ee&&ae==="top"&&h!==0||!ee&&ae==="left"&&F!==0?"0":"1px"});fe.includes("1px")&&(L.classList.add("has-editing-gridlines"),L.style.setProperty("--coco-word-grid-widths",fe.join(" "))),L.contentEditable="true";for(let ae of I.blocks){let oe=Jr(ae);for(let ie of [...oe.matches("coco-word-native-p")?[oe]:[],...Array.from(oe.querySelectorAll("coco-word-native-p"))])ie.contentEditable="true";L.appendChild(oe);}S.appendChild(L);}a.appendChild(S);}return n.appendChild(a),t.appendChild(n),Bs(t),t}function jx(e){return Math.max(1,e.columnWidths.length,...e.rows.map(t=>t.cells.reduce((n,r)=>n+Math.max(1,r.gridSpan),0)))}function Ux(e,t,n){var o,i;let r=e.borders;if(!(!r&&!t.borders))return v(v({},Kx(r,n,(o=t.rowSpan)!=null?o:1)),(i=t.borders)!=null?i:{})}function Kx(e,t,n){var l,d,u,f;if(!e)return {};let r={val:"nil"},o=t.rowIndex===0,i=t.rowIndex+n>=t.rowCount,a=t.columnIndex===0,s=t.columnIndex+t.columnSpan>=t.columnCount;return {top:(l=o?e.top:e.insideH)!=null?l:r,right:(d=s?e.right:e.insideV)!=null?d:r,bottom:(u=i?e.bottom:e.insideH)!=null?u:r,left:(f=a?e.left:e.insideV)!=null?f:r}}function _x(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=Fn(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=Fn(n.indent)),n.cellSpacing!==void 0&&n.cellSpacing>0&&(e.style.borderCollapse="separate",e.style.borderSpacing=n.cellSpacingType==="pct"?`${n.cellSpacing/50}%`:Fn(n.cellSpacing)));}function Fn(e){return `${e/20}pt`}function It(e){return `${Hs(e)}px`}function Hs(e){return e/15}function Rs(e){return e/914400*96}function Dn(e){customElements.get(e)||customElements.define(e,class extends HTMLElement{});}function Tt(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 pt(e){var o;let t=Tt(e);if(!t||t.rangeCount===0)return null;let n=t.getRangeAt(0),r=Nt(n.startContainer);return !r||!e.contains(r)?null:{paraId:(o=r.dataset.paraId)!=null?o:"",offset:vi(r,n.startContainer,n.startOffset)}}function lt(e){let t=pt(e);return t?{kind:"caret",paraId:t.paraId,offset:t.offset}:null}function ze(e){var a,s;let t=Tt(e);if(!t||t.rangeCount===0||!t.anchorNode||!t.focusNode)return null;let n=Nt(t.anchorNode),r=Nt(t.focusNode);if(!n||!r||!e.contains(n)||!e.contains(r))return null;let o={paraId:(a=n.dataset.paraId)!=null?a:"",offset:vi(n,t.anchorNode,t.anchorOffset)},i={paraId:(s=r.dataset.paraId)!=null?s:"",offset:vi(r,t.focusNode,t.focusOffset)};return t.isCollapsed?{kind:"caret",paraId:o.paraId,offset:o.offset}:{kind:"text-range",anchor:o,focus:i}}function uf(e,t,n){var i;let r=qx(t,n);if(!r)return null;let o=Nt(r.node);return !o||!e.contains(o)?null:{paraId:(i=o.dataset.paraId)!=null?i:"",offset:vi(o,r.node,r.offset)}}function dt(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=On(n,t.offset);r.setStart(o.node,o.offset),r.setEnd(o.node,o.offset);let i=Tt(e);i&&(i.removeAllRanges(),i.addRange(r));}function vn(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=On(r,t.offset),a=On(o,n.offset),s=Tt(e);s&&(r.focus({preventScroll:true}),s.removeAllRanges(),s.setBaseAndExtent(i.node,i.offset,a.node,a.offset));}function ff(e,t){let n=Nt(t);if(!n||!e.contains(n))return false;let r=document.createRange();r.selectNodeContents(t);let o=Tt(e);return o?(n.focus({preventScroll:true}),o.removeAllRanges(),o.addRange(r),true):false}function pf(e,t,n,r){let o=e.querySelector(`coco-word-native-p[data-para-id="${t}"]`);if(!o)return null;let i=On(o,n),a=On(o,r),s=document.createRange();return s.setStart(i.node,i.offset),s.setEnd(a.node,a.offset),s}function Os(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=On(r,t.offset),a=On(o,n.offset),s=document.createRange();return s.setStart(i.node,i.offset),s.setEnd(a.node,a.offset),s}function qx(e,t){var i,a;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=(a=n.caretRangeFromPoint)==null?void 0:a.call(n,e,t);return o?{node:o.startContainer,offset:o.startOffset}:null}function mf(e,t){Pt(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 Pt(e){e.querySelectorAll("coco-word-native-p img.is-selected").forEach(t=>{t.classList.remove("is-selected");});}function Si(e,t){var i,a;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+=(a=(i=o.textContent)==null?void 0:i.length)!=null?a:0:o instanceof HTMLImageElement&&(n+=1),o=r.nextNode();}return n}function Nt(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 vi(e,t,n){let r=0,o=null,i=a=>{var s,l,d,u;if(o===null){if(a===t){if(a.nodeType===Node.TEXT_NODE){o=r+Math.max(0,Math.min(n,(l=(s=a.textContent)==null?void 0:s.length)!=null?l:0));return}let f=Math.max(0,Math.min(n,a.childNodes.length));for(let p=0;p<f;p+=1)r+=hf(a.childNodes[p]);o=r;return}if(a.nodeType===Node.TEXT_NODE){r+=(u=(d=a.textContent)==null?void 0:d.length)!=null?u:0;return}if($s(a)){r+=1;return}for(let f=0;f<a.childNodes.length;f+=1)i(a.childNodes[f]);}};return i(e),o!=null?o:r}function hf(e){var n,r;if(e.nodeType===Node.TEXT_NODE)return (r=(n=e.textContent)==null?void 0:n.length)!=null?r:0;if($s(e))return 1;let t=0;for(let o=0;o<e.childNodes.length;o+=1)t+=hf(e.childNodes[o]);return t}function On(e,t){var a,s;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=(s=(a=r.textContent)==null?void 0:a.length)!=null?s:0;if(o<=l)return {node:r,offset:o};o-=l;}else if($s(r)){if(o===0)return cf(r,"before");if(o===1)return cf(r,"after");o-=1;}r=n.nextNode();}let i=document.createTextNode("");return e.appendChild(i),{node:i,offset:0}}function $s(e){return e instanceof HTMLElement&&(e instanceof HTMLImageElement||e.classList.contains("coco-word-page-break"))}function cf(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 zs(e,t){if(t.query.length===0)return [];let n=t.matchCase?"gu":"giu",r=new RegExp(Yx(t.query),n),o=[];for(let i of bf(e.blocks)){let a=Te(i);for(let s of a.matchAll(r)){let l=s.index,d=l+s[0].length;t.wholeWord&&!Xx(a,l,d)||o.push({id:`${i.paraId}:${l}:${d}`,paraId:i.paraId,from:l,to:d,text:s[0]});}}return o}function bf(e){return e.flatMap(t=>t.kind==="paragraph"?[t]:t.rows.flatMap(n=>n.cells.flatMap(r=>bf(r.blocks))))}function Xx(e,t,n){let r=t>0?e[t-1]:"",o=n<e.length?e[n]:"";return !gf(r)&&!gf(o)}function gf(e){return e.length>0&&/[\p{L}\p{N}_]/u.test(e)}function Yx(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var ki="application/x-coco-word-blocks+json";function xf(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 s;let i={text:"",runs:[]},a=o.closest("li");return a&&(i.listType=((s=a.parentElement)==null?void 0:s.tagName)==="OL"?"numbered":"bullet"),Cf(o,{},i),i.text=i.text.replace(/\u00a0/g," "),i})}function js(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=Jx(o);t+=n?`<li>${i}</li>`:`<p>${i}</p>`;}return n&&(t+=n==="numbered"?"</ol>":"</ul>"),t}function Us(e){return JSON.stringify({version:1,blocks:e})}function yf(e){if(!e||e.length>2e7)return null;try{let t=JSON.parse(e);return !eo(t)||t.version!==1||!Array.isArray(t.blocks)||t.blocks.length===0||t.blocks.length>1e3?null:t.blocks.every(Sf)?t.blocks:null}catch(t){return null}}function Ks(e){return e.map(vf).join(`
16
+ `)}function vf(e){return e.kind==="paragraph"?Te(e):e.rows.map(t=>t.cells.map(n=>n.blocks.map(vf).join(`
17
17
  `)).join(" ")).join(`
18
- `)}function xf(e){return Qr(e)?e.kind==="paragraph"?typeof e.paraId=="string"&&typeof e.story=="string"&&Array.isArray(e.content)&&e.content.length<=1e5&&e.content.every(qx):e.kind!=="table"||typeof e.tableId!="string"||!Array.isArray(e.rows)||e.rows.length>1e4?false:e.rows.every(t=>Qr(t)&&Array.isArray(t.cells)&&t.cells.length<=1e3&&t.cells.every(n=>Qr(n)&&Array.isArray(n.blocks)&&n.blocks.length<=1e4&&n.blocks.every(xf))):false}function qx(e){return !Qr(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 Qr(e){return typeof e=="object"&&e!==null}function Xx(e){let t="",n=0,r=[...e.runs].map(o=>H(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+=Vs(e.text.slice(n,o.from))),o.from<n)continue;let i=Vs(e.text.slice(o.from,o.to)),a=Yx(o.format),s=a?`<span style="${Gs(a)}">${i}</span>`:i;if(o.hyperlink){let l=Ur(o.hyperlink.target,o.hyperlink.anchor),d=o.hyperlink.tooltip?` title="${Gs(o.hyperlink.tooltip)}"`:"";s=`<a href="${Gs(l)}"${d}>${s}</a>`;}t+=s,n=o.to;}return n<e.text.length&&(t+=Vs(e.text.slice(n))),t||"<br>"}function Yx(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 Vs(e){return yf(e).replace(/\r\n?|\n/g,"<br>")}function yf(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function Gs(e){return yf(e).replace(/"/g,"&quot;")}function vf(e,t,n,r){var a;if(e.nodeType===Node.TEXT_NODE){let s=(a=e.textContent)!=null?a:"";if(!s)return;let l=n.text.length;n.text+=s,(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+=`
19
- `;return}let o=v(v({},t),Jx(e)),i=e.tagName==="A"?Zx(e):r;for(let s of Array.from(e.childNodes))vf(s,o,n,i);}function Zx(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 a=t.slice(1);try{a=decodeURIComponent(a);}catch(s){return}return a?v({anchor:a},n?{tooltip:n}:{}):void 0}let r=Ur(t,void 0);return r==="#"?void 0:v({target:r},n?{tooltip:n}:{})}function Jx(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=Qx(t.fontSize);o!==null&&(n.fontSize=o);let i=hf(t.color),a=hf(t.backgroundColor);return i&&(n.color=i),a&&(n.highlight=a),n}function hf(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 Qx(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 Js="http://www.w3.org/XML/1998/namespace",$n="http://schemas.openxmlformats.org/officeDocument/2006/relationships",Gt="http://schemas.openxmlformats.org/package/2006/relationships",Lt="http://schemas.openxmlformats.org/drawingml/2006/main",rr="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",tr="http://schemas.openxmlformats.org/drawingml/2006/picture",Si="http://schemas.openxmlformats.org/package/2006/content-types",Rf="application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",Sf="application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml",kf="http://schemas.microsoft.com/office/2011/relationships/commentsExtended",sn="http://schemas.microsoft.com/office/word/2012/wordml",Cf=`${$n}/hyperlink`,Mf="application/vnd.openxmlformats-package.relationships+xml";function ty(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=ny(o,{allowTrackedTable:o.kind==="table"&&!!o.revisionId&&r.get(o.revisionId)==="accept"});i?t.push(i):n.push({change:o,reason:iy(o)});}return {target:"word/document.xml",patches:t,unsupported:n}}function lI(e,t,n=wordView.buildIndices(e)){let r=ty(t),o=oy(e,n,r.patches);return v({plan:r},o)}function ny(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)||!Lf(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?Af(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 ry(e,t,n){var i,a;let r=[],o=[];for(let s of n){if(s.kind==="drawing-delete"||s.kind==="drawing-resize"||s.kind==="drawing-revision"){let u=t.drawingIdx.get(s.drawingId);if(!u&&s.kind==="drawing-revision"){let f=t.paraIdx.get(s.paraId.toUpperCase());u=f&&(i=Iy(f,s.offset))!=null?i:void 0;}if(!u){o.push({patch:s,reason:`drawing not found: ${s.drawingId}`});continue}let p=nr(e,u);if(!p){o.push({patch:s,reason:`drawing part not found: ${s.drawingId}`});continue}r.push({kind:"drawing",patch:s,partPath:p,drawing:u,paragraph:(a=t.paraIdx.get(s.paraId.toUpperCase()))!=null?a:null});continue}if(s.kind==="drawing-insert"){let u=t.paraIdx.get(s.paraId.toUpperCase());if(!u){o.push({patch:s,reason:`paragraph not found: ${s.paraId}`});continue}let p=nr(e,u);if(!p){o.push({patch:s,reason:`paragraph part not found: ${s.paraId}`});continue}r.push({kind:"drawing",patch:s,partPath:p,drawing:u,paragraph:u});continue}if(s.kind==="comment"){let u=t.paraIdx.get(s.paraId.toUpperCase());if(!u){o.push({patch:s,reason:`paragraph not found: ${s.paraId}`});continue}let p=nr(e,u);if(!p){o.push({patch:s,reason:`paragraph part not found: ${s.paraId}`});continue}r.push({kind:"comment",patch:s,partPath:p,paragraph:u});continue}if(s.kind==="table-insert"){let u=t.paraIdx.get(s.anchorParaId.toUpperCase());if(!u){o.push({patch:s,reason:`anchor paragraph not found: ${s.anchorParaId}`});continue}let p=nr(e,u);if(!p){o.push({patch:s,reason:`paragraph part not found: ${s.anchorParaId}`});continue}r.push({kind:"table",patch:s,partPath:p,table:u,paragraph:u});continue}if(s.kind==="table-structure"||s.kind==="table-cell-format"||s.kind==="table-cell-clear"||s.kind==="table-cell-replace"||s.kind==="table-cell-replace-rich"||s.kind==="table-delete"){let u=t.tblIdx.get(s.tableId);if(!u){o.push({patch:s,reason:`table not found: ${s.tableId}`});continue}let p=nr(e,u);if(!p){o.push({patch:s,reason:`table part not found: ${s.tableId}`});continue}r.push({kind:"table",patch:s,partPath:p,table:u});continue}let l=t.paraIdx.get(s.paraId.toUpperCase());if(!l){o.push({patch:s,reason:`paragraph not found: ${s.paraId}`});continue}let d=nr(e,l);if(!d){o.push({patch:s,reason:`paragraph part not found: ${s.paraId}`});continue}r.push({kind:"paragraph",patch:s,partPath:d,paragraph:l});}return {resolved:r,unresolved:o}}function oy(e,t,n){var l,d;let r=[],o=[],i=[],a=new Set,s=t;for(let u of n){let p=ry(e,s,[u]);if(p.unresolved.length>0){i.push(...p.unresolved);continue}let f=p.resolved[0];if(!f)continue;let b=Ff(e,f.kind==="paragraph"?f.paragraph:f.kind==="drawing"?f.drawing:f.kind==="table"?f.table:f.paragraph);if(!b){o.push({patch:f.patch,reason:`part not found: ${f.partPath}`});continue}if(f.kind==="drawing"){if(f.patch.kind==="drawing-insert"){let g=Fy(e,f.partPath,(l=f.paragraph)!=null?l:f.drawing,f.patch);if(!g.ok){o.push({patch:f.patch,reason:g.reason});continue}pack.markDirty(b),r.push(f.patch),s=wordView.buildIndices(e);continue}if(f.patch.kind==="drawing-revision"){(f.patch.revisionKind==="insert"&&f.patch.op==="reject"||f.patch.revisionKind==="delete"&&f.patch.op==="accept")&&Tf(f.drawing),pack.markDirty(b),r.push(f.patch),s=wordView.buildIndices(e);continue}if(f.patch.kind==="drawing-resize"){let g=Dy(f.drawing,f.patch.width,f.patch.height);if(!g.ok){o.push({patch:f.patch,reason:g.reason});continue}pack.markDirty(b),r.push(f.patch),s=wordView.buildIndices(e);continue}Tf(f.drawing),pack.markDirty(b),r.push(f.patch),s=wordView.buildIndices(e);continue}if(f.kind==="table"){if(f.patch.kind==="table-insert"){let h=cy(f.table.ownerDocument,f.patch.table,e,f.partPath);(d=f.table.parentNode)==null||d.insertBefore(h,f.table.nextSibling),pack.markDirty(b),r.push(f.patch),s=wordView.buildIndices(e);continue}if(f.patch.kind==="table-cell-format"){let h=uy(f.table,f.patch);if(!h.ok){o.push({patch:f.patch,reason:h.reason});continue}pack.markDirty(b),r.push(f.patch),s=wordView.buildIndices(e);continue}if(f.patch.kind==="table-cell-clear"){let h=fy(f.table,f.patch);if(!h.ok){o.push({patch:f.patch,reason:h.reason});continue}pack.markDirty(b),r.push(f.patch),s=wordView.buildIndices(e);continue}if(f.patch.kind==="table-cell-replace"){let h=py(f.table,f.patch);if(!h.ok){o.push({patch:f.patch,reason:h.reason});continue}pack.markDirty(b),r.push(f.patch),s=wordView.buildIndices(e);continue}if(f.patch.kind==="table-cell-replace-rich"){let h=my(e,f.partPath,f.table,f.patch);if(!h.ok){o.push({patch:f.patch,reason:h.reason});continue}pack.markDirty(b),r.push(f.patch),s=wordView.buildIndices(e);continue}if(f.patch.kind==="table-delete"){Ue(f.table),pack.markDirty(b),r.push(f.patch),s=wordView.buildIndices(e);continue}let g=hy(f.table,f.patch);if(!g.ok){o.push({patch:f.patch,reason:g.reason});continue}pack.markDirty(b),r.push(f.patch),s=wordView.buildIndices(e);continue}if(f.kind==="comment"){let g=Ky(e,f.partPath,f.paragraph,f.patch);if(!g.ok){o.push({patch:f.patch,reason:g.reason});continue}pack.markDirty(b),r.push(f.patch),s=wordView.buildIndices(e);continue}if(f.patch.kind==="revision"){let g=Oy(f.paragraph,f.patch);if(!g.ok){if((f.patch.op==="accept"||f.patch.op==="reject")&&g.reason===`revision not found: ${f.patch.revisionId}`&&a.has(f.patch.revisionId)){r.push(f.patch);continue}o.push({patch:f.patch,reason:g.reason});continue}pack.markDirty(b),r.push(f.patch),(f.patch.op==="accept"||f.patch.op==="reject")&&a.add(f.patch.revisionId),s=wordView.buildIndices(e);continue}if(f.patch.kind==="paragraph-format"){let g=$y(f.paragraph,f.patch);if(!g.ok){o.push({patch:f.patch,reason:g.reason});continue}pack.markDirty(b),r.push(f.patch),s=wordView.buildIndices(e);continue}if(f.patch.kind==="format-revision"){let g=zy(f.paragraph,f.patch);if(!g.ok){o.push({patch:f.patch,reason:g.reason});continue}pack.markDirty(b),r.push(f.patch),s=wordView.buildIndices(e);continue}if(f.patch.kind==="paragraph-split"){let g=Py(f.paragraph,f.patch.offset,f.patch.newParaId);if(!g.ok){o.push({patch:f.patch,reason:g.reason});continue}pack.markDirty(b),r.push(f.patch),s=wordView.buildIndices(e);continue}if(f.patch.kind==="paragraph-merge"){let g=Ry(f.paragraph);if(!g.ok){o.push({patch:f.patch,reason:g.reason});continue}pack.markDirty(b),r.push(f.patch),s=wordView.buildIndices(e);continue}if(f.patch.kind==="hyperlink"){let g=ay(e,f.partPath,f.paragraph,f.patch);if(!g.ok){o.push({patch:f.patch,reason:g.reason});continue}pack.markDirty(b),r.push(f.patch),s=wordView.buildIndices(e);continue}let w=ky(f.paragraph,f.patch);if(!w.ok){o.push({patch:f.patch,reason:w.reason});continue}pack.markDirty(b),r.push(f.patch);}return {applied:r,skipped:o,unresolved:i}}function iy(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&&Af(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 Af(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 Lf(e){try{let t=new URL(e).protocol.toLowerCase();return t==="http:"||t==="https:"}catch(t){return false}}function ay(e,t,n,r){var p,f,b;let o=se(n).filter(w=>!(w.namespaceURI===wordView.W_NS&&w.localName==="pPr")),i=o.reduce((w,g)=>w+jt(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(w=>{var g;return w.namespaceURI!==wordView.W_NS||!["r","hyperlink"].includes((g=w.localName)!=null?g:"")}))return {ok:false,reason:"hyperlink patch only supports text runs and existing hyperlinks"};if(o.some(w=>dy(w)))return {ok:false,reason:"hyperlink patch cannot cross inline objects"};let a=null,s=null;if(r.op==="set"){let w=(p=r.hyperlink)==null?void 0:p.target;if(!w||!Lf(w))return {ok:false,reason:"only external http/https hyperlinks can be written back"};let g=Bf(e,t,w);a=g.id,s=g.part;}let l=[],d=0,u=[];for(let w of o){let g=jt(w),h=Math.max(0,r.from-d),y=Math.min(g,r.to-d);if(!(h<y)){l.push(w),d+=g;continue}if(h>0){let N=or(w,0,h);N&&l.push(N);}let E=or(w,h,y);if(E&&u.push(...ly(E)),y<g){let N=or(w,y,g);N&&l.push(N);}d+=g;}if(r.op==="set"){let w=n.ownerDocument;if(!w||!a)return {ok:false,reason:"paragraph has no owner document or relationship"};let g=w.createElementNS(wordView.W_NS,"w:hyperlink");g.setAttributeNS($n,"r:id",a);let h=(b=(f=r.hyperlink)==null?void 0:f.tooltip)==null?void 0:b.trim();h&&g.setAttributeNS(wordView.W_NS,"w:tooltip",h);for(let y of u)g.appendChild(y);sy(l,g,r);}else Wf(l,u,r);for(let w of o)Ue(w);for(let w of l)n.appendChild(w);return s&&pack.markDirty(s),{ok:true}}function sy(e,t,n){Wf(e,[t],n);}function Wf(e,t,n){let r=0,o=false,i=[];for(let a of e)!o&&r>=n.from&&(i.push(...t),o=true),i.push(a),r+=jt(a);o||i.push(...t),e.splice(0,e.length,...i);}function or(e,t,n){if(n<=t)return null;let r=e.cloneNode(true);return Xs(r,t,n),jt(r)>0?r:null}function ly(e){return e.namespaceURI===wordView.W_NS&&e.localName==="hyperlink"?se(e).filter(t=>t.namespaceURI===wordView.W_NS&&t.localName==="r"):[e]}function dy(e){return e.getElementsByTagNameNS(wordView.W_NS,"drawing").length>0||e.getElementsByTagNameNS(wordView.W_NS,"pict").length>0}function Bf(e,t,n){var u,p,f,b,w;let r=Ci(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=(p=g.implementation)==null?void 0:p.createDocument(Gt,"Relationships",null);if(!h)throw new Error("XML implementation cannot create relationship document");o=pack.createXmlPart({path:r,contentType:Mf,xmlDom:h}),pack.setPart(e,o);}let i=o.xmlDom;if(!i)throw new Error(`relationship part has no XML DOM: ${r}`);let a=i.getElementsByTagNameNS(Gt,"Relationship");for(let g=0;g<a.length;g+=1){let h=a[g];if((h==null?void 0:h.getAttribute("Type"))===Cf&&h.getAttribute("Target")===n)return {id:(f=h.getAttribute("Id"))!=null?f:"",part:o}}let s=new Set;for(let g=0;g<a.length;g+=1){let h=(b=a[g])==null?void 0:b.getAttribute("Id");h&&s.add(h);}let l=1;for(;s.has(`rId${l}`);)l+=1;let d=i.createElementNS(Gt,"Relationship");return d.setAttribute("Id",`rId${l}`),d.setAttribute("Type",Cf),d.setAttribute("Target",n),d.setAttribute("TargetMode","External"),(w=i.documentElement)==null||w.appendChild(d),{id:`rId${l}`,part:o}}function Ci(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 cy(e,t,n,r){var u,p,f,b,w,g,h;let o=y=>e.createElementNS(wordView.W_NS,`w:${y}`),i=o("tbl"),a=o("tblPr"),s=o("tblW");s.setAttributeNS(wordView.W_NS,"w:w",String(Math.max(0,Math.round((p=(u=t.layout)==null?void 0:u.width)!=null?p:0)))),s.setAttributeNS(wordView.W_NS,"w:type",((f=t.layout)==null?void 0:f.widthType)==="pct"?"pct":"dxa"),a.appendChild(s);let l={};for(let y of ["top","left","bottom","right","insideH","insideV"]){let S=(b=t.borders)==null?void 0:b[y];l[y]={val:(w=S==null?void 0:S.val)!=null?w:"single",color:(g=S==null?void 0:S.color)!=null?g:"D9D9D9",size:(h=S==null?void 0:S.size)!=null?h:4};}word.writeWordTableBorders(a,"table",l),i.appendChild(a);let d=o("tblGrid");for(let y of t.columnWidths){let S=o("gridCol");S.setAttributeNS(wordView.W_NS,"w:w",String(Math.max(1,Math.round(y)))),d.appendChild(S);}i.appendChild(d);for(let y of t.rows){let S=o("tr");for(let E of y.cells)S.appendChild(Df(e,E,n,r));i.appendChild(S);}return i}function Df(e,t,n,r){var u,p,f,b,w,g;let o=h=>e.createElementNS(wordView.W_NS,`w:${h}`),i=o("tc"),a=o("tcPr"),s=o("tcW");if(s.setAttributeNS(wordView.W_NS,"w:w",String(Math.max(1,Math.round((u=t.width)!=null?u:0)))),s.setAttributeNS(wordView.W_NS,"w:type","dxa"),a.appendChild(s),(p=t.shading)!=null&&p.fill){let h=o("shd");h.setAttributeNS(wordView.W_NS,"w:val",(f=t.shading.val)!=null?f:"clear"),h.setAttributeNS(wordView.W_NS,"w:fill",t.shading.fill.replace(/^#/,"").toUpperCase()),a.appendChild(h);}if(t.verticalAlignment){let h=o("vAlign");h.setAttributeNS(wordView.W_NS,"w:val",t.verticalAlignment),a.appendChild(h);}i.appendChild(a);let l=t.blocks.filter(h=>h.kind==="paragraph"),d=l.length>0?l:[null];for(let h of d){let y=o("p");if(h)for(let S of h.content){if(S.kind==="image"){let A=Gf(S.src);if(!A)continue;let O=jf(n,r,A.bytes,A.extension,A.contentType);y.appendChild(Vf(e,O.id,S.drawingId,(b=S.width)!=null?b:96,(w=S.height)!=null?w:96)),pack.markDirty(O.part),pack.markDirty(O.mediaPart),Uf(n,A.extension,A.contentType);continue}if(S.kind!=="text")continue;let E=o("r");if(S.format){let A=o("rPr");if(S.format.bold&&A.appendChild(o("b")),S.format.italic&&A.appendChild(o("i")),S.format.underline){let O=o("u");O.setAttributeNS(wordView.W_NS,"w:val","single"),A.appendChild(O);}if(S.format.strike&&A.appendChild(o("strike")),S.format.color){let O=o("color");O.setAttributeNS(wordView.W_NS,"w:val",S.format.color.replace(/^#/,"").toUpperCase()),A.appendChild(O);}if(S.format.fontSize){let O=o("sz");O.setAttributeNS(wordView.W_NS,"w:val",String(Math.round(S.format.fontSize*2))),A.appendChild(O);}if(S.format.fontFamily){let O=o("rFonts");for(let W of ["ascii","hAnsi","eastAsia"])O.setAttributeNS(wordView.W_NS,`w:${W}`,S.format.fontFamily);A.appendChild(O);}A.childNodes.length>0&&E.appendChild(A);}let N=o("t");if(N.textContent=S.text,/^\s|\s$/.test(S.text)&&N.setAttributeNS(Js,"xml:space","preserve"),E.appendChild(N),(g=S.hyperlink)!=null&&g.target){let A=Bf(n,r,S.hyperlink.target),O=e.createElementNS(wordView.W_NS,"w:hyperlink");O.setAttributeNS($n,"r:id",A.id),O.appendChild(E),y.appendChild(O),pack.markDirty(A.part);}else y.appendChild(E);}y.firstChild||y.appendChild(o("r")),i.appendChild(y);}return i}function uy(e,t){let r=se(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=se(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 a=e.ownerDocument,s=se(i).find(l=>l.namespaceURI===wordView.W_NS&&l.localName==="tcPr");if(s||(s=a.createElementNS(wordView.W_NS,"w:tcPr"),i.insertBefore(s,i.firstChild)),t.format.backgroundColor!==void 0){let l=se(s).find(d=>d.namespaceURI===wordView.W_NS&&d.localName==="shd");if(t.format.backgroundColor===null)l&&Ue(l);else {let d=l!=null?l:a.createElementNS(wordView.W_NS,"w:shd");d.setAttributeNS(wordView.W_NS,"w:val","clear"),d.setAttributeNS(wordView.W_NS,"w:fill",t.format.backgroundColor.replace(/^#/,"").toUpperCase()),l||s.appendChild(d);}}if(t.format.verticalAlignment!==void 0){let l=se(s).find(d=>d.namespaceURI===wordView.W_NS&&d.localName==="vAlign");if(t.format.verticalAlignment===null)l&&Ue(l);else {let d=l!=null?l:a.createElementNS(wordView.W_NS,"w:vAlign");d.setAttributeNS(wordView.W_NS,"w:val",t.format.verticalAlignment),l||s.appendChild(d);}}if(t.format.borderColor!==void 0){let l=t.format.borderColor===null?{val:"nil"}:{val:"single",size:4,color:t.format.borderColor.replace(/^#/,"").toUpperCase()},d={top:v({},l),left:v({},l),bottom:v({},l),right:v({},l),insideH:v({},l),insideV:v({},l)};word.writeWordTableBorders(s,"cell",d);}return {ok:true}}function fy(e,t){let r=se(e).filter(s=>s.namespaceURI===wordView.W_NS&&s.localName==="tr")[t.rowIndex];if(!r)return {ok:false,reason:`table row out of range: ${t.rowIndex}`};let i=se(r).filter(s=>s.namespaceURI===wordView.W_NS&&s.localName==="tc")[t.columnIndex];if(!i)return {ok:false,reason:`table column out of range: ${t.columnIndex}`};let a=se(i).find(s=>s.namespaceURI===wordView.W_NS&&s.localName==="tcPr");for(let s of se(i))s!==a&&Ue(s);return i.appendChild(i.ownerDocument.createElementNS(wordView.W_NS,"w:p")),{ok:true}}function py(e,t){let r=se(e).filter(f=>f.namespaceURI===wordView.W_NS&&f.localName==="tr")[t.rowIndex];if(!r)return {ok:false,reason:`table row out of range: ${t.rowIndex}`};let i=se(r).filter(f=>f.namespaceURI===wordView.W_NS&&f.localName==="tc")[t.columnIndex];if(!i)return {ok:false,reason:`table column out of range: ${t.columnIndex}`};let a=se(i).find(f=>f.namespaceURI===wordView.W_NS&&f.localName==="tcPr"),s=se(i).find(f=>f.namespaceURI===wordView.W_NS&&f.localName==="p");for(let f of se(i))f!==a&&Ue(f);let l=i.ownerDocument.createElementNS(wordView.W_NS,"w:p"),d=s&&se(s).find(f=>f.namespaceURI===wordView.W_NS&&f.localName==="pPr");d&&l.appendChild(d.cloneNode(true));let u=i.ownerDocument.createElementNS(wordView.W_NS,"w:r"),p=i.ownerDocument.createElementNS(wordView.W_NS,"w:t");return p.textContent=t.text,/^\s|\s$/.test(t.text)&&p.setAttributeNS(Js,"xml:space","preserve"),u.appendChild(p),l.appendChild(u),i.appendChild(l),{ok:true}}function my(e,t,n,r){let i=se(n).filter(d=>d.namespaceURI===wordView.W_NS&&d.localName==="tr")[r.rowIndex];if(!i)return {ok:false,reason:`table row out of range: ${r.rowIndex}`};let s=se(i).filter(d=>d.namespaceURI===wordView.W_NS&&d.localName==="tc")[r.columnIndex];if(!s)return {ok:false,reason:`table column out of range: ${r.columnIndex}`};let l=Df(n.ownerDocument,r.cell,e,t);for(let d of se(s))Ue(d);for(let d of se(l))s.appendChild(d.cloneNode(true));return {ok:true}}function hy(e,t){var u,p,f,b;let n=se(e).filter(w=>w.namespaceURI===wordView.W_NS&&w.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 w=n[Math.min(t.rowIndex,n.length-1)],g=by(w);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=se(r).filter(w=>w.namespaceURI===wordView.W_NS&&w.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 w=n.map(g=>se(g).filter(h=>h.namespaceURI===wordView.W_NS&&h.localName==="tc"));if(w.some(g=>g.length!==o.length||g.some(h=>Hn(h)!==1||vi(h))))return {ok:false,reason:"table column structure is not a regular non-merged grid"};for(let g of w)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=_s(h);(f=g[0].parentNode)==null||f.insertBefore(y,(p=g[t.columnIndex])!=null?p:null);}return Sy(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=>se(y).filter(S=>S.namespaceURI===wordView.W_NS&&S.localName==="tc")[t.columnIndex]);if(h.some(y=>!y||Hn(y)!==1||vi(y)))return {ok:false,reason:"vertical merge requires a regular non-merged column"};Ef(h[0],"restart");for(let y of h.slice(1)){Ef(y,"continue");let S=se(y).find(E=>E.namespaceURI===wordView.W_NS&&E.localName==="tcPr");for(let E of se(y))E!==S&&Ue(E);y.appendChild(y.ownerDocument.createElementNS(wordView.W_NS,"w:p"));}return {ok:true}}let w=(b=t.endColumnIndex)!=null?b:t.columnIndex+1;if(t.columnIndex<0||w>=o.length||w<=t.columnIndex)return {ok:false,reason:`merge start column out of range: ${t.columnIndex}`};if(o.some(h=>Hn(h)!==1||vi(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<=w;h+=1){let y=o[h];wy(g,y),Ue(y);}return xy(g,w-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 w=n.slice(t.rowIndex,t.endRowIndex+1).map(g=>se(g).filter(h=>h.namespaceURI===wordView.W_NS&&h.localName==="tc")[t.columnIndex]);if(w.some((g,h)=>{var E;if(!g||Hn(g)!==1)return true;let y=(E=se(g).find(N=>N.namespaceURI===wordView.W_NS&&N.localName==="tcPr"))==null?void 0:E.getElementsByTagNameNS(wordView.W_NS,"vMerge")[0],S=y==null?void 0:y.getAttributeNS(wordView.W_NS,"val");return h===0?S!=="restart":S!=="continue"}))return {ok:false,reason:"cell is not a vertically merged cell"};for(let g of w)gy(g);return {ok:true}}let i=n[t.rowIndex],a=se(i).filter(w=>w.namespaceURI===wordView.W_NS&&w.localName==="tc"),s=0,l=a.find(w=>{let g=s===t.columnIndex;return s+=Hn(w),g});if(!l)return {ok:false,reason:`split column out of range: ${t.columnIndex}`};if(vi(l)||Hn(l)<=1)return {ok:false,reason:"cell is not a horizontally merged cell"};let d=Hn(l);yy(l);for(let w=1;w<d;w+=1){let g=_s(l);i.insertBefore(g,l.nextSibling);}return {ok:true}}function Ef(e,t){var i;let n=e.ownerDocument,r=se(e).find(a=>a.namespaceURI===wordView.W_NS&&a.localName==="tcPr");r||(r=n.createElementNS(wordView.W_NS,"w:tcPr"),e.insertBefore(r,e.firstChild));let o=(i=se(r).find(a=>a.namespaceURI===wordView.W_NS&&a.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 gy(e){let t=se(e).find(r=>r.namespaceURI===wordView.W_NS&&r.localName==="tcPr"),n=t&&se(t).find(r=>r.namespaceURI===wordView.W_NS&&r.localName==="vMerge");n&&Ue(n);}function by(e){let t=e.cloneNode(true),n=se(t).filter(r=>r.namespaceURI===wordView.W_NS&&r.localName==="tc");for(let r of n){let o=_s(r);zf(r,o);}return t}function _s(e){let t=e.ownerDocument,n=t.createElementNS(wordView.W_NS,"w:tc"),r=se(e).find(s=>s.namespaceURI===wordView.W_NS&&s.localName==="tcPr");r&&n.appendChild(r.cloneNode(true));let o=t.createElementNS(wordView.W_NS,"w:p"),i=se(e).find(s=>s.namespaceURI===wordView.W_NS&&s.localName==="p"),a=i&&se(i).find(s=>s.namespaceURI===wordView.W_NS&&s.localName==="pPr");return a&&o.appendChild(a.cloneNode(true)),o.appendChild(t.createElementNS(wordView.W_NS,"w:r")),n.appendChild(o),n}function wy(e,t){for(let n of se(t))n.namespaceURI===wordView.W_NS&&n.localName==="tcPr"||e.appendChild(n.cloneNode(true));}function Hn(e){var r,o;let t=(o=(r=se(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 vi(e){var t;return !!((t=se(e).find(n=>n.namespaceURI===wordView.W_NS&&n.localName==="tcPr"))!=null&&t.getElementsByTagNameNS(wordView.W_NS,"vMerge").length)}function xy(e,t){let n=vy(e,"tcPr"),r=se(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 yy(e){let t=se(e).find(r=>r.namespaceURI===wordView.W_NS&&r.localName==="tcPr"),n=t&&se(t).find(r=>r.namespaceURI===wordView.W_NS&&r.localName==="gridSpan");n&&Ue(n);}function vy(e,t){let n=se(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 Sy(e,t,n){var s;let r=se(e).find(l=>l.namespaceURI===wordView.W_NS&&l.localName==="tblGrid");if(!r)return;let o=se(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 a=i.cloneNode(true);r.insertBefore(a,(s=o[n])!=null?s:null);}function nr(e,t){var n,r;return (r=(n=Ff(e,t))==null?void 0:n.path)!=null?r:null}function Ff(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 ky(e,t){var n,r;return t.op==="insert"?Hf(e,t.offset,t.text):t.op==="delete"?If(e,t.offset,t.text.length,""):If(e,t.offset,(r=(n=t.deletedText)==null?void 0:n.length)!=null?r:0,t.text)}function Hf(e,t,n){var s,l,d;if(n.length===0)return {ok:true};let r=no(e),o=r.reduce((u,p)=>u+p.length,0);if(Cy(e)&&t===o)return Nf(e,n),{ok:true};if(r.every(u=>u.kind!=="text"))return t!==0?{ok:false,reason:`insert offset out of range: ${t}`}:(Nf(e,n),{ok:true});let i=qs(r,t,true);if(!i)return {ok:false,reason:`insert offset out of range: ${t}`};if(i.node.localName==="delText"&&i.localOffset===((l=(s=i.node.textContent)==null?void 0:s.length)!=null?l:0)){let u=Ey(i.node,"del"),p=u==null?void 0:u.parentNode;if(u&&p===e){let f=e.ownerDocument;if(!f)return {ok:false,reason:"paragraph has no owner document"};let b=f.createElementNS(wordView.W_NS,"w:r"),w=f.createElementNS(wordView.W_NS,"w:t");return w.textContent=n,Sn(w),b.appendChild(w),e.insertBefore(b,u.nextSibling),{ok:true}}}let a=(d=i.node.textContent)!=null?d:"";return i.node.textContent=`${a.slice(0,i.localOffset)}${n}${a.slice(i.localOffset)}`,Sn(i.node),{ok:true}}function If(e,t,n,r){var f,b;if(n===0)return Hf(e,t,r);let o=no(e),i=o.filter(w=>w.kind==="text").map(w=>w.node),a=qs(o,t,false),s=qs(o,t+n,true);if(!a||!s)return {ok:false,reason:`text range out of range: ${t}:${n}`};let l=(f=a.node.textContent)!=null?f:"";if(a.node===s.node)return a.node.textContent=`${l.slice(0,a.localOffset)}${r}${l.slice(s.localOffset)}`,Sn(a.node),{ok:true};let d=i.indexOf(a.node),u=i.indexOf(s.node);if(d<0||u<0||d>u)return {ok:false,reason:`text range out of range: ${t}:${n}`};let p=(b=s.node.textContent)!=null?b:"";a.node.textContent=`${l.slice(0,a.localOffset)}${r}`,Sn(a.node);for(let w=d+1;w<u;w++)i[w].textContent="";return s.node.textContent=p.slice(s.localOffset),Sn(s.node),{ok:true}}function no(e){let t=[];return $f(e,t),t}function Cy(e){return e.getElementsByTagNameNS(wordView.W_NS,"fldChar").length>0||e.getElementsByTagNameNS(wordView.W_NS,"instrText").length>0}function Of(e){return no(e).filter(t=>t.kind==="text").map(t=>t.node)}function $f(e,t){var r,o,i,a;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:(a=(i=n.textContent)==null?void 0:i.length)!=null?a: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 s=0;s<n.childNodes.length;s+=1){let l=n.childNodes[s];l&&$f(l,t);}}function Ey(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 Iy(e,t){let n=0,r=no(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 qs(e,t,n){var o;let r=0;for(let i=0;i<e.length;i+=1){let a=e[i],s=r+a.length;if(a.kind==="text"){if(t>=r&&(t<s||n&&t===s))return {node:a.node,localOffset:t-r}}else if(t>=r&&t<=s)return (o=Ny(e,i))!=null?o:Ty(e,i);r=s;}return null}function Ny(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 Ty(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 Nf(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,Sn(o),r.appendChild(o),e.appendChild(r);}function Sn(e){var n;let t=(n=e.textContent)!=null?n:"";/^\s|\s$|\s{2,}/.test(t)&&e.setAttributeNS(Js,"xml:space","preserve");}function Py(e,t,n){let r=e.parentNode,o=e.ownerDocument;if(!r||!o)return {ok:false,reason:"paragraph has no parent document"};let i=se(e).filter(u=>!(u.namespaceURI===wordView.W_NS&&u.localName==="pPr")),a=i.reduce((u,p)=>u+jt(p),0);if(t<0||t>a)return {ok:false,reason:`split offset out of range: ${t}`};let s=My(o,i,t),l=o.createElementNS(wordView.W_NS,"w:p");Ly(e,l,n);let d=se(e).find(u=>u.namespaceURI===wordView.W_NS&&u.localName==="pPr");d&&l.appendChild(d.cloneNode(true));for(let u of s)l.appendChild(u);return r.insertBefore(l,e.nextSibling),{ok:true}}function Ry(e){let t=Wy(e);if(!t)return {ok:false,reason:"next paragraph not found for merge"};for(let n of se(t))n.namespaceURI===wordView.W_NS&&n.localName==="pPr"||e.appendChild(n.cloneNode(true));return Ue(t),{ok:true}}function My(e,t,n){let r=[],o=0,i=false;for(let a of t){let s=jt(a),l=o+s;if(i)r.push(a.cloneNode(true)),Ue(a);else if(n<=o)r.push(a.cloneNode(true)),Ue(a);else if(!(n>=l)){let d=Ay(e,a,n-o);d.after&&r.push(d.after),i=true;}!i&&n===l&&(i=true),o=l;}return r}function Ay(e,t,n){let r=t.cloneNode(true),o=t.cloneNode(true);return Xs(r,0,n),Xs(o,n,jt(t)),zf(t,r),By(o)||jt(o)>0?{after:o}:{after:null}}function Xs(e,t,n){var i;let r=Of(e),o=0;for(let a of r){let s=(i=a.textContent)!=null?i:"",l=o+s.length,d=Math.max(0,t-o),u=Math.min(s.length,n-o);a.textContent=d<u?s.slice(d,u):"",Sn(a),o=l;}}function jt(e){var o,i,a;if(e.namespaceURI===wordView.W_NS&&e.localName==="drawing")return 1;let t=0,n=e.getElementsByTagNameNS(wordView.W_NS,"t");for(let s=0;s<n.length;s++)t+=(a=(i=(o=n[s])==null?void 0:o.textContent)==null?void 0:i.length)!=null?a:0;let r=e.getElementsByTagNameNS(wordView.W_NS,"drawing");return t+=r.length,t}function Ly(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 se(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 Wy(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 By(e){return Of(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 zf(e,t){var n;(n=e.parentNode)==null||n.replaceChild(t,e);}function Tf(e){var n;let t=e.parentNode;if(t){if(ov(t)&&t.namespaceURI===wordView.W_NS&&t.localName==="r"&&rv(t)){(n=t.parentNode)==null||n.removeChild(t);return}t.removeChild(e);}}function Dy(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=se(e).find(l=>l.namespaceURI===rr&&(l.localName==="inline"||l.localName==="anchor"));if(!i)return {ok:false,reason:"drawing has no wp:inline or wp:anchor container"};let a=se(i).find(l=>l.namespaceURI===rr&&l.localName==="extent");if(!a)return {ok:false,reason:"drawing has no wp:extent"};a.setAttribute("cx",String(r)),a.setAttribute("cy",String(o));let s=i.getElementsByTagNameNS(Lt,"xfrm");for(let l=0;l<s.length;l+=1){let d=s[l],u=d&&se(d).find(p=>p.namespaceURI===Lt&&p.localName==="ext");u&&(u.setAttribute("cx",String(r)),u.setAttribute("cy",String(o)));}return {ok:true}}function Fy(e,t,n,r){let o=Gf(r.src);if(!o)return {ok:false,reason:"image insert requires a base64 data:image URL"};let i=jf(e,t,o.bytes,o.extension,o.contentType),a=Vf(n.ownerDocument,i.id,r.drawingId,r.width,r.height),s=se(n).filter(f=>!(f.namespaceURI===wordView.W_NS&&f.localName==="pPr")),l=s.reduce((f,b)=>f+jt(b),0);if(r.offset<0||r.offset>l)return {ok:false,reason:`image insert offset out of range: ${r.offset}`};let d=[],u=0,p=false;for(let f of s){let b=jt(f);if(!p&&r.offset<=u&&(d.push(a),p=true),!p&&r.offset<u+b&&f.namespaceURI===wordView.W_NS&&f.localName==="r"){let w=or(f,0,r.offset-u),g=or(f,r.offset-u,b);w&&d.push(w),d.push(a),p=true,g&&d.push(g);}else d.push(f);u+=b;}p||d.push(a);for(let f of s)Ue(f);for(let f of d)n.appendChild(f);return pack.markDirty(i.part),pack.markDirty(i.mediaPart),Uf(e,o.extension,o.contentType),{ok:true}}function Vf(e,t,n,r,o){let i=Math.round(r/96*914400),a=Math.round(o/96*914400),s=e.createElementNS(wordView.W_NS,"w:r"),l=e.createElementNS(wordView.W_NS,"w:drawing"),d=e.createElementNS(rr,"wp:inline"),u=e.createElementNS(rr,"wp:extent");u.setAttribute("cx",String(i)),u.setAttribute("cy",String(a)),d.appendChild(u);let p=e.createElementNS(rr,"wp:docPr");p.setAttribute("id",String(Math.abs(Hy(n))+1)),p.setAttribute("name",`Picture ${n}`),d.appendChild(p),d.appendChild(e.createElementNS(rr,"wp:cNvGraphicFramePr"));let f=e.createElementNS(Lt,"a:graphic"),b=e.createElementNS(Lt,"a:graphicData");b.setAttribute("uri","http://schemas.openxmlformats.org/drawingml/2006/picture");let w=e.createElementNS(tr,"pic:pic"),g=e.createElementNS(tr,"pic:nvPicPr"),h=e.createElementNS(tr,"pic:cNvPr");h.setAttribute("id","0"),h.setAttribute("name",`image-${n}`),g.appendChild(h),g.appendChild(e.createElementNS(tr,"pic:cNvPicPr")),w.appendChild(g);let y=e.createElementNS(tr,"pic:blipFill"),S=e.createElementNS(Lt,"a:blip");S.setAttributeNS($n,"r:embed",t),y.appendChild(S);let E=e.createElementNS(Lt,"a:stretch");E.appendChild(e.createElementNS(Lt,"a:fillRect")),y.appendChild(E),w.appendChild(y);let N=e.createElementNS(tr,"pic:spPr"),A=e.createElementNS(Lt,"a:xfrm"),O=e.createElementNS(Lt,"a:ext");O.setAttribute("cx",String(i)),O.setAttribute("cy",String(a)),A.appendChild(e.createElementNS(Lt,"a:off")),A.appendChild(O),N.appendChild(A);let W=e.createElementNS(Lt,"a:prstGeom");return W.setAttribute("prst","rect"),W.appendChild(e.createElementNS(Lt,"a:avLst")),N.appendChild(W),w.appendChild(N),b.appendChild(w),f.appendChild(b),d.appendChild(f),l.appendChild(d),s.appendChild(l),s}function Gf(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 jf(e,t,n,r,o){var g,h,y,S;let i=Ci(t),a=e.parts.get(i);if(!(a!=null&&a.xmlDom)){let E=(g=Array.from(e.parts.values()).find(A=>A.xmlDom))==null?void 0:g.xmlDom;if(!E)throw new Error("cannot create image relationships without an XML part");let N=(h=E.implementation)==null?void 0:h.createDocument(Gt,"Relationships",null);if(!N)throw new Error("XML implementation cannot create relationship document");a=pack.createXmlPart({path:i,contentType:Mf,xmlDom:N}),pack.setPart(e,a);}let s=a.xmlDom;if(!s)throw new Error(`relationship part has no XML DOM: ${i}`);let l=s.getElementsByTagNameNS(Gt,"Relationship"),d=1,u=new Set;for(let E=0;E<l.length;E+=1){let N=(y=l[E])==null?void 0:y.getAttribute("Id");N&&u.add(N);}for(;u.has(`rId${d}`);)d+=1;let p=1;for(;e.parts.has(`word/media/image${p}.${r}`);)p+=1;let f=`word/media/image${p}.${r}`,b=pack.createBinaryPart({path:f,contentType:o,bytes:n});pack.setPart(e,b);let w=s.createElementNS(Gt,"Relationship");return w.setAttribute("Id",`rId${d}`),w.setAttribute("Type",`${$n}/image`),w.setAttribute("Target",`media/image${p}.${r}`),(S=s.documentElement)==null||S.appendChild(w),{id:`rId${d}`,part:a,mediaPart:b}}function Uf(e,t,n){var s,l,d;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=(s=i[u])==null?void 0:s.getAttribute("Extension"))==null?void 0:l.toLowerCase())===t.toLowerCase())return;let a=o.createElementNS("http://schemas.openxmlformats.org/package/2006/content-types","Default");a.setAttribute("Extension",t),a.setAttribute("ContentType",n),(d=o.documentElement)==null||d.appendChild(a),pack.markDirty(r);}function Hy(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,d,u;if(t.op==="accept"||t.op==="reject"){let p=t.revisionKind==="insert"?"ins":"del",b=Array.from(e.getElementsByTagNameNS(wordView.W_NS,p)).filter(w=>w.getAttributeNS(wordView.W_NS,"id")===t.revisionId);if(b.length===0)return {ok:false,reason:`revision not found: ${t.revisionId}`};for(let w of b){let g=w.parentNode;if(!g)continue;if(!(p==="ins"&&t.op==="accept"||p==="del"&&t.op==="reject")){g.removeChild(w);continue}let y=Array.from(w.childNodes);if(p==="del")for(let S of y)S.nodeType===1&&Uy(S);for(let S of y)g.insertBefore(S,w);g.removeChild(w);}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 p of Array.from(e.childNodes)){if(p.nodeType!==1||p.namespaceURI!==wordView.W_NS){i.push(p);continue}let f=p;if(f.localName==="ins"||f.localName==="del"){i.push(f),n+=(d=(l=f.textContent)==null?void 0:l.length)!=null?d:0;continue}if(f.localName!=="r"){i.push(f);continue}let b=Array.from(f.getElementsByTagNameNS(wordView.W_NS,"t"));if(b.length!==1)return {ok:false,reason:"revision writeback requires runs with one text node"};let w=(u=b[0].textContent)!=null?u:"",g=n,h=n+w.length;if(n=h,h<=t.from||g>=t.to){i.push(f);continue}let y=Math.max(0,t.from-g),S=Math.min(w.length,t.to-g);y>0&&i.push(ir(f,w.slice(0,y))),S>y&&(o<0&&(o=i.length),r.push(ir(f,w.slice(y,S)))),S<w.length&&i.push(ir(f,w.slice(S)));}if(r.length===0||t.to>n)return {ok:false,reason:`revision range out of range: ${t.from}:${t.to}`};let a=e.ownerDocument;if(!a)return {ok:false,reason:"revision paragraph has no owner document"};let s=a.createElementNS(wordView.W_NS,t.revisionKind==="insert"?"w:ins":"w:del");s.setAttributeNS(wordView.W_NS,"w:id",t.revisionId),s.setAttributeNS(wordView.W_NS,"w:author","User"),s.setAttributeNS(wordView.W_NS,"w:date",new Date().toISOString());for(let p of r)t.revisionKind==="delete"&&jy(p),s.appendChild(p);for(i.splice(o<0?i.length:o,0,s),Gy(i);e.firstChild;)e.removeChild(e.firstChild);for(let p of i)e.appendChild(p);return {ok:true}}function $y(e,t){var a;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 s=Array.from(e.getElementsByTagNameNS(wordView.W_NS,"r")),l=0,d=0;for(let u of s){let p=Kf(u);if(p.length===0)continue;let f=l,b=l+p.length;if(l=b,!(b<=t.from||f>=t.to)){if(t.from>f||t.to<b)return {ok:false,reason:"format writeback requires whole runs inside tracked content"};Ys(u,t.format),d+=p.length;}}return d===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 s of Array.from(e.childNodes)){if(s.nodeType!==1||s.namespaceURI!==wordView.W_NS||s.localName!=="r"){r.push(s);continue}let l=s,d=Array.from(l.getElementsByTagNameNS(wordView.W_NS,"t"));if(d.length!==1)return {ok:false,reason:"format writeback requires runs with one text node"};let u=(a=d[0].textContent)!=null?a:"",p=o,f=o+u.length;if(o=f,f<=t.from||p>=t.to){r.push(l);continue}let b=Math.max(0,t.from-p),w=Math.min(u.length,t.to-p);if(b>0&&r.push(ir(l,u.slice(0,b))),w>b){let g=ir(l,u.slice(b,w));Ys(g,t.format),r.push(g),i+=w-b;}w<u.length&&r.push(ir(l,u.slice(w)));}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 s of r)e.appendChild(s);return {ok:true}}function zy(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,a=0;for(let s of n){let l=Kf(s),d=i,u=i+l.length;if(i=u,u<=t.from||d>=t.to)continue;if(t.from>d||t.to<u)return {ok:false,reason:"format revision currently requires whole runs"};let p=Vy(s);On(p,"rPrChange");let f=p.ownerDocument.createElementNS(wordView.W_NS,"w:rPrChange");f.setAttributeNS(wordView.W_NS,"w:id",t.revisionId),f.setAttributeNS(wordView.W_NS,"w:author","User"),f.setAttributeNS(wordView.W_NS,"w:date",new Date().toISOString());let b=p.ownerDocument.createElementNS(wordView.W_NS,"w:r");Ys(b,(o=t.beforeFormat)!=null?o:{});let w=se(b).find(g=>g.namespaceURI===wordView.W_NS&&g.localName==="rPr");if(w)for(let g of Array.from(w.childNodes))f.appendChild(g);p.appendChild(f),a+=l.length;}return a===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 a=se(i).find(l=>l.namespaceURI===wordView.W_NS&&l.localName==="rPr"),s=a&&se(a).find(l=>l.namespaceURI===wordView.W_NS&&l.localName==="rPrChange"&&l.getAttributeNS(wordView.W_NS,"id")===t.revisionId);if(!(!s||!a)){if(t.op==="reject"){for(let l of Array.from(a.childNodes))l!==s&&a.removeChild(l);for(let l of Array.from(s.childNodes))a.appendChild(l.cloneNode(true));}a.removeChild(s),r+=1;}}return r>0?{ok:true}:{ok:false,reason:`format revision not found: ${t.revisionId}`}}function Kf(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 Vy(e){let t=se(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 Ys(e,t){var i,a,s;let n=e.ownerDocument,r=(i=se(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,d]of o)t[l]!==void 0&&(On(r,d),t[l]&&r.appendChild(n.createElementNS(wordView.W_NS,`w:${d}`)));if(t.underline!==void 0&&(On(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&&(On(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){On(r,"shd");let l=(s=(a=t.shading)==null?void 0:a.fill)!=null?s:t.highlight;if(l){let d=n.createElementNS(wordView.W_NS,"w:shd");d.setAttribute("val","clear"),d.setAttribute("fill",l.replace(/^#/,"").toUpperCase()),r.appendChild(d);}}if(t.fontSize!==void 0){On(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){On(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 On(e,t){for(let n of se(e))n.namespaceURI===wordView.W_NS&&n.localName===t&&e.removeChild(n);}function Gy(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 a of Array.from(i.childNodes))o.appendChild(a);e.splice(t,1),t-=1;}}}function ir(e,t){let n=e.cloneNode(true),r=n.getElementsByTagNameNS(wordView.W_NS,"t")[0];return r&&(r.textContent=t),n}function jy(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 a=0;a<o.attributes.length;a+=1){let s=o.attributes[a];s&&i.setAttributeNS(s.namespaceURI,s.name,s.value);}i.textContent=o.textContent,(r=o.parentNode)==null||r.replaceChild(i,o);}}function Uy(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 a=0;a<o.attributes.length;a+=1){let s=o.attributes[a];s&&i.setAttributeNS(s.namespaceURI,s.name,s.value);}i.textContent=o.textContent,(r=o.parentNode)==null||r.replaceChild(i,o);}}function Ky(e,t,n,r){var a;if(r.op==="insert"){if(r.from<0||r.to<=r.from)return {ok:false,reason:"comment range is empty or invalid"};let s=no(n).reduce((d,u)=>d+u.length,0);if(r.to>s)return {ok:false,reason:`comment range out of range: ${r.from}:${r.to}`};_y(e,t),tv(n,r.from,r.to,r.commentId);let l=new Date().toISOString();return Yy(e,r.commentId,(a=r.body)!=null?a:"","User",l),r.parentCommentId!==void 0&&Zy(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 s=e.parts.get("word/comments.xml"),l=s==null?void 0:s.xmlDom;if(!s||!l)return {ok:false,reason:"comments.xml part not found"};let d=l.getElementsByTagNameNS(wordView.W_NS,"comment");for(let u=0;u<d.length;u+=1){let p=d[u];if((p==null?void 0:p.getAttributeNS(wordView.W_NS,"id"))!==String(r.commentId))continue;let f=p.getElementsByTagNameNS(wordView.W_NS,"t");if(f.length===0){let b=l.createElementNS(wordView.W_NS,"w:p"),w=l.createElementNS(wordView.W_NS,"w:r"),g=l.createElementNS(wordView.W_NS,"w:t");g.textContent=r.body,w.appendChild(g),b.appendChild(w),p.appendChild(b);}else {f[0].textContent=r.body;for(let b=f.length-1;b>=1;b-=1)Ue(f[b]);}return pack.markDirty(s),{ok:true}}return {ok:false,reason:`comment not found: ${r.commentId}`}}nv(e,r.commentId),Qy(e,r.commentId);let o=e.parts.get("word/comments.xml"),i=o==null?void 0:o.xmlDom;if(i){let s=i.getElementsByTagNameNS(wordView.W_NS,"comment");for(let l=0;l<s.length;l+=1){let d=s[l];(d==null?void 0:d.getAttributeNS(wordView.W_NS,"id"))===String(r.commentId)&&Ue(d);}pack.markDirty(o);}return {ok:true}}function _y(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(s=>s.xmlDom))==null?void 0:r.xmlDom;if(!i)throw new Error("cannot create comments.xml without an XML part");let a=(o=i.implementation)==null?void 0:o.createDocument(wordView.W_NS,"w:comments",null);if(!a)throw new Error("XML implementation cannot create comments.xml");n=pack.createXmlPart({path:"word/comments.xml",contentType:Rf,xmlDom:a}),pack.setPart(e,n),qy(e);}return Xy(e,t),n}function qy(e){var i,a;let t=pack.getPart(e,"[Content_Types].xml"),n=t==null?void 0:t.xmlDom;if(!t||!n)return;let r=n.getElementsByTagNameNS(Si,"Override");for(let s=0;s<r.length;s+=1)if(((i=r[s])==null?void 0:i.getAttribute("PartName"))==="/word/comments.xml")return;let o=n.createElementNS(Si,"Override");o.setAttribute("PartName","/word/comments.xml"),o.setAttribute("ContentType",Rf),(a=n.documentElement)==null||a.appendChild(o),pack.markDirty(t);}function Xy(e,t){var d,u,p;let n=Ci(t),r=e.parts.get(n);if(!(r!=null&&r.xmlDom))return;let o=r.xmlDom,i=o.getElementsByTagNameNS(Gt,"Relationship");for(let f=0;f<i.length;f+=1)if(((d=i[f])==null?void 0:d.getAttribute("Type"))===`${$n}/comments`)return;let a=new Set;for(let f=0;f<i.length;f+=1){let b=(u=i[f])==null?void 0:u.getAttribute("Id");b&&a.add(b);}let s=1;for(;a.has(`rId${s}`);)s+=1;let l=o.createElementNS(Gt,"Relationship");l.setAttribute("Id",`rId${s}`),l.setAttribute("Type",`${$n}/comments`),l.setAttribute("Target","comments.xml"),(p=o.documentElement)==null||p.appendChild(l),pack.markDirty(r);}function Yy(e,t,n,r,o){let i=e.parts.get("word/comments.xml"),a=i==null?void 0:i.xmlDom;if(!i||!a)return;let s=a.documentElement;if(!s||Array.from(a.getElementsByTagNameNS(wordView.W_NS,"comment")).some(f=>f.getAttributeNS(wordView.W_NS,"id")===String(t)))return;let l=a.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 d=a.createElementNS(wordView.W_NS,"w:p");d.setAttributeNS(wordView.W14_NS,"w14:paraId",Jy(t));let u=a.createElementNS(wordView.W_NS,"w:r"),p=a.createElementNS(wordView.W_NS,"w:t");p.textContent=n,Sn(p),u.appendChild(p),d.appendChild(u),l.appendChild(d),s.appendChild(l),pack.markDirty(i);}function Zy(e,t,n){let r=e.parts.get("word/comments.xml"),o=r==null?void 0:r.xmlDom;if(!o)return;let i=b=>{var g,h,y;let w=o.getElementsByTagNameNS(wordView.W_NS,"comment");for(let S=0;S<w.length;S+=1){if(((g=w[S])==null?void 0:g.getAttributeNS(wordView.W_NS,"id"))!==String(b))continue;let E=(h=w[S])==null?void 0:h.getElementsByTagNameNS(wordView.W_NS,"p")[0];return (y=E==null?void 0:E.getAttributeNS(wordView.W14_NS,"paraId"))!=null?y:null}return null},a=i(t),s=i(n);if(!a||!s)return;let l=ev(e,"word/document.xml"),d=l.xmlDom,u=d==null?void 0:d.documentElement;if(!d||!u||Array.from(u.getElementsByTagNameNS(sn,"commentEx")).some(b=>b.getAttributeNS(sn,"paraId")===a))return;let f=d.createElementNS(sn,"w15:commentEx");f.setAttributeNS(sn,"w15:paraId",a),f.setAttributeNS(sn,"w15:paraIdParent",s),u.appendChild(f),pack.markDirty(l);}function Jy(e){return e.toString(16).padStart(8,"0").slice(-8)}function Qy(e,t){var d,u,p,f;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 a=r.getElementsByTagNameNS(wordView.W_NS,"comment"),s=null;for(let b=0;b<a.length;b+=1)if(((d=a[b])==null?void 0:d.getAttributeNS(wordView.W_NS,"id"))===String(t)){s=(f=(p=(u=a[b])==null?void 0:u.getElementsByTagNameNS(wordView.W_NS,"p")[0])==null?void 0:p.getAttributeNS(wordView.W14_NS,"paraId"))!=null?f:null;break}if(!s)return;let l=Array.from(i.getElementsByTagNameNS(sn,"commentEx"));for(let b of l)(b.getAttributeNS(sn,"paraId")===s||b.getAttributeNS(sn,"paraIdParent")===s)&&(Ue(b),pack.markDirty(o));}function ev(e,t){var a,s,l,d,u,p;let n=e.parts.get("word/commentsExtended.xml");if(!(n!=null&&n.xmlDom)){let f=(l=(a=e.parts.get(t))==null?void 0:a.xmlDom)!=null?l:(s=Array.from(e.parts.values()).find(w=>w.xmlDom))==null?void 0:s.xmlDom;if(!f)throw new Error("cannot create commentsExtended.xml without an XML part");let b=(d=f.implementation)==null?void 0:d.createDocument(sn,"w15:commentsEx",null);if(!b)throw new Error("XML implementation cannot create commentsExtended.xml");n=pack.createXmlPart({path:"word/commentsExtended.xml",contentType:Sf,xmlDom:b}),pack.setPart(e,n);}let r=pack.getPart(e,"[Content_Types].xml");if(r!=null&&r.xmlDom){let f=r.xmlDom.getElementsByTagNameNS(Si,"Override");if(!Array.from(f).some(b=>b.getAttribute("PartName")==="/word/commentsExtended.xml")){let b=r.xmlDom.createElementNS(Si,"Override");b.setAttribute("PartName","/word/commentsExtended.xml"),b.setAttribute("ContentType",Sf),(u=r.xmlDom.documentElement)==null||u.appendChild(b),pack.markDirty(r);}}let o=e.parts.get(Ci(t)),i=o==null?void 0:o.xmlDom;if(i&&!Array.from(i.getElementsByTagNameNS(Gt,"Relationship")).some(f=>f.getAttribute("Type")===kf)){let f=i.getElementsByTagNameNS(Gt,"Relationship"),b=new Set(Array.from(f).map(h=>h.getAttribute("Id")).filter(Boolean)),w=1;for(;b.has(`rId${w}`);)w+=1;let g=i.createElementNS(Gt,"Relationship");g.setAttribute("Id",`rId${w}`),g.setAttribute("Type",kf),g.setAttribute("Target","commentsExtended.xml"),(p=i.documentElement)==null||p.appendChild(g),pack.markDirty(o);}return n}function tv(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 a=o.createElementNS(wordView.W_NS,"w:commentRangeEnd");a.setAttributeNS(wordView.W_NS,"w:id",String(r));let s=o.createElementNS(wordView.W_NS,"w:r"),l=o.createElementNS(wordView.W_NS,"w:commentReference");l.setAttributeNS(wordView.W_NS,"w:id",String(r)),s.appendChild(l);let d=new Map;d.set(t,[i]),d.set(n,[a,s]);let u=se(e).filter(b=>!(b.namespaceURI===wordView.W_NS&&b.localName==="pPr")),p=[],f=0;for(let b of u){let w=d.get(f);w&&p.push(...w);let g=jt(b),h=[t,n].filter(S=>S>f&&S<f+g).sort((S,E)=>S-E),y=0;for(let S of [...h,f+g]){let E=or(b,y,S-f);E&&p.push(E);let N=S,A=d.get(N);A&&p.push(...A),y=S-f;}g===0&&p.push(b),f+=g;}for(let b of [t,n])if(b===f){let w=d.get(b);w&&p.push(...w);}for(let b of u)Ue(b);for(let b of p)e.appendChild(b);}function nv(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),a=[];for(let s=0;s<i.length;s+=1){let l=i[s];(l==null?void 0:l.getAttributeNS(wordView.W_NS,"id"))===String(t)&&a.push(l);}for(let s of a){let l=s.parentNode;o==="commentReference"&&(l==null?void 0:l.nodeType)===1&&l.namespaceURI===wordView.W_NS&&l.localName==="r"?Ue(l):Ue(s);}a.length>0&&pack.markDirty(n);}}}function rv(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 ov(e){return e.nodeType===1}var Zt=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",av(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",sv(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",lv(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",dv(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",uv(e.attrs),0]}}});new prosemirrorState.PluginKey("coco-word-decorations");var qf=new prosemirrorState.PluginKey("coco-word-structure-normalization");function av(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=fv(e.format)?e.format:null;(n==null?void 0:n.outlineLevel)!==void 0&&(t["data-outline-level"]=String(n.outlineLevel));let r=pv(n);return r.length>0&&(t.style=r),t}function sv(e){let t={};return typeof e.tableId=="string"&&e.tableId.length>0&&(t["data-table-id"]=e.tableId),t}function lv(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: ${zn(e.width)}`),cv(e.shading)){let r=Qs(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 dv(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 cv(e){return e!==null&&typeof e=="object"}function uv(e){let t=[],n=typeof e.color=="string"?Qs(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 fv(e){return e!==null&&typeof e=="object"}function pv(e){var o,i,a,s,l,d,u,p,f;if(!e)return "";let t=[];e.alignment&&t.push(`text-align: ${mv(e.alignment)}`),((o=e.indent)==null?void 0:o.left)!==void 0&&t.push(`margin-left: ${zn(e.indent.left)}`),((i=e.indent)==null?void 0:i.right)!==void 0&&t.push(`margin-right: ${zn(e.indent.right)}`),((a=e.indent)==null?void 0:a.firstLine)!==void 0&&t.push(`text-indent: ${zn(e.indent.firstLine)}`),((s=e.spacing)==null?void 0:s.before)!==void 0&&t.push(`margin-top: ${zn(e.spacing.before)}`),((l=e.spacing)==null?void 0:l.after)!==void 0&&t.push(`margin-bottom: ${zn(e.spacing.after)}`);let n=gv((d=e.spacing)==null?void 0:d.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=hv(e.borderBottom);return r&&(t.push(`border-bottom: ${r}`),t.push(`padding-bottom: ${(f=(p=e.borderBottom)==null?void 0:p.space)!=null?f:4}pt`)),t.join("; ")}function mv(e){return e==="both"||e==="distribute"?"justify":e}function hv(e){var o;if(!e||e.val==="none"||e.val==="nil")return null;let t=(o=Qs(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 gv(e,t){return e===void 0?null:t==="exact"||t==="atLeast"?zn(e):String(e/240)}function zn(e){return `${e/20}pt`}function Qs(e){return !e||e==="auto"?null:/^[0-9a-f]{6}$/i.test(e)?`#${e}`:null}var oo=new prosemirrorState.PluginKey("coco-word-editing"),xv=0;function NI(e={}){return new prosemirrorState.Plugin({key:oo,appendTransaction(t,n,r){if(!t.some(a=>a.docChanged)||t.every(a=>a.getMeta(qf)))return null;let o=vv(n.doc,r.doc),i=o.length>0?o:Ev(n.doc,r.doc);return i.length>0?ep(r.tr,i):null},state:{init:()=>({changes:[]}),apply(t,n){var i,a;let r=t.getMeta(oo);if(!((i=r==null?void 0:r.changes)!=null&&i.length))return n;let o={changes:[...n.changes,...r.changes]};return (a=e.onChangeSet)==null||a.call(e,o),o}}})}function TI(e){var t;return (t=oo.getState(e))!=null?t:{changes:[]}}function PI(e){var s,l;let{from:t,to:n,empty:r}=e.selection,o=e.selection.$from,i=Rv(o,"table_cell"),a=i===null?null:{depth:i,colspan:Number((s=o.node(i).attrs.colspan)!=null?s: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,`
20
- `),paragraphs:nl(e,t,n),tableCell:a}}function RI(e,t,n){let r=Zt.marks.strong;return tl(e,t,n,r,{},"strong")}function MI(e){return (t,n,r)=>!Number.isFinite(e)||e<=0?false:tl(t,n,r,Zt.marks.textStyle,{fontSize:e},"textStyle")}function AI(e){return (t,n,r)=>{let o=Pv(e);return o?tl(t,n,r,Zt.marks.textStyle,{color:o},"textStyle"):false}}function LI(e){return (t,n)=>{let r=nl(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,a)=>{if(i.type!==Zt.nodes.paragraph)return true;let s=Tv(i.attrs.format,{alignment:e});return o=o.setNodeMarkup(a,void 0,H(v({},i.attrs),{format:s})),false}),o=Qf(o,{kind:"paragraph",from:t.selection.from,to:t.selection.to,paragraphs:r,target:Ei(r),status:"captured",attr:"alignment",value:e}),n(o.scrollIntoView()),true}}function tl(e,t,n,r,o,i){let{from:a,to:s,empty:l}=e.selection;if(l)return false;let d=nl(e,a,s);if(d.length===0)return false;let u=i==="strong"&&yv(e.doc,a,s,r);if(!t)return true;let p=e.tr;return u?p=p.removeMark(a,s,r):p=p.addMark(a,s,r.create(o)),p=Qf(p,{kind:"mark",from:a,to:s,paragraphs:d,target:Ei(d),status:"captured",mark:i,value:i==="strong"?!u:o}),t(p.scrollIntoView()),n==null||n.focus(),true}function nl(e,t,n){let r=[],o=Math.max(n,t+1);return e.doc.nodesBetween(t,o,(i,a)=>{if(i.type!==Zt.nodes.paragraph)return true;let s=a+1,l=s+i.content.size;return r.push({paraId:typeof i.attrs.paraId=="string"?i.attrs.paraId:"",from:Math.max(t,s)-s,to:Math.min(n,l)-s,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 Ei(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 yv(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 Qf(e,t){return ep(e,[t])}function ep(e,t){var o,i;let n=(o=e.getMeta(oo))!=null?o:{},r=(i=n.changes)!=null?i:[];return e.setMeta(oo,H(v({},n),{changes:[...r,...t.map(a=>H(v({},a),{id:`word-edit:${++xv}`,createdAt:Date.now()}))]}))}function vv(e,t){let n=Yf(e),r=Yf(t),o=Sv(n,r);if(o)return [o];let i=kv(n,r);if(i)return [i];let a=Cv(n,r);return a?[a]:[]}function Sv(e,t){if(t.length!==e.length+1)return null;for(let n=0;n<e.length;n+=1){if(!Ii(e.slice(0,n),t.slice(0,n))||!Ii(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:rl([o,i]),target:ol(r.block),status:"captured",blocks:[o.block,i.block],deletedBlocks:[r.block],value:{before:r.block,after:[o.block,i.block]}}}return null}function kv(e,t){if(e.length!==t.length+1)return null;for(let n=0;n<t.length;n+=1){if(!Ii(e.slice(0,n),t.slice(0,n))||!Ii(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:rl([i]),target:ol(i.block),status:"captured",blocks:[i.block],deletedBlocks:[r.block,o.block],value:{before:[r.block,o.block],after:i.block}}}return null}function Cv(e,t){var p,f,b,w,g;let n=0,r=Math.min(e.length,t.length);for(;n<r&&el(e[n],t[n]);)n+=1;let o=0,i=Math.min(e.length-n,t.length-n);for(;o<i&&el(e[e.length-1-o],t[t.length-1-o]);)o+=1;let a=e.slice(n,e.length-o),s=t.slice(n,t.length-o);if(a.length===0&&s.length===0)return null;let l=(p=s[0])!=null?p:a[0],d=(b=(f=s[s.length-1])!=null?f:a[a.length-1])!=null?b:l;return {kind:"block",blockOp:s.length>0&&a.length>0?"replace":s.length>0?"insert":"delete",from:(w=l==null?void 0:l.pos)!=null?w:0,to:d?d.pos+d.size:(g=l==null?void 0:l.pos)!=null?g:0,paragraphs:rl(s.length>0?s:a),target:l?ol(l.block):{story:"body"},status:"captured",blocks:s.map(h=>h.block),deletedBlocks:a.map(h=>h.block),value:{before:a.map(h=>h.block),after:s.map(h=>h.block)}}}function Ev(e,t){let n=Xf(e),r=Xf(t),o=new Map(n.map(a=>[a.paraId,a])),i=[];for(let a of r){if(!a.paraId)continue;let s=o.get(a.paraId);if(!s||np(s.content,a.content))continue;let l=Nv(s.content,a.content);if(!l)continue;let d=a.pos+1+l.from,u=a.pos+1+l.toAfter,p={paraId:a.paraId,from:l.from,to:l.toAfter,text:a.text,styleId:a.styleId,story:a.story};if(Zf(l.insertedContent)&&Zf(l.deletedContent)){i.push({kind:"text",from:d,to:u,paragraphs:[p],target:Ei([p]),status:"captured",textOp:l.operation,text:Jf(l.insertedContent),deletedText:Jf(l.deletedContent),value:{operation:l.operation,before:s.text,after:a.text}});continue}i.push({kind:"content",from:d,to:u,paragraphs:[p],target:Ei([p]),status:"captured",contentOp:l.operation,content:ro(l.insertedContent),deletedContent:ro(l.deletedContent),value:{operation:l.operation,before:ro(s.content.map(f=>f.content)),after:ro(a.content.map(f=>f.content))}});}return i}function Xf(e){let t=[];return e.descendants((n,r)=>n.type!==Zt.nodes.paragraph?true:(t.push({paraId:typeof n.attrs.paraId=="string"?n.attrs.paraId:"",pos:r,text:n.textContent,content:tp(n),styleId:typeof n.attrs.styleId=="string"?n.attrs.styleId:null,story:typeof n.attrs.story=="string"?n.attrs.story:"body"}),false)),t}function Yf(e){let t=[];return e.forEach((n,r,o)=>{if(n.type===Zt.nodes.paragraph){let i=typeof n.attrs.paraId=="string"?n.attrs.paraId:"",a=typeof n.attrs.story=="string"?n.attrs.story:"body",s={kind:"paragraph",paraId:i,story:a,styleId:typeof n.attrs.styleId=="string"?n.attrs.styleId:null,text:n.textContent,content:ro(tp(n).map(l=>l.content))};t.push({key:`paragraph:${i||o}`,pos:r,size:n.nodeSize,block:s});return}if(n.type===Zt.nodes.table){let i=typeof n.attrs.tableId=="string"?n.attrs.tableId:"",a={kind:"table",tableId:i,text:n.textContent};t.push({key:`table:${i||o}`,pos:r,size:n.nodeSize,block:a});}}),t}function Ii(e,t){return e.length===t.length&&e.every((n,r)=>el(n,t[r]))}function el(e,t){return e.key===t.key}function rl(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 ol(e){return e.kind==="table"?v({story:"body"},e.tableId?{tableId:e.tableId}:{}):v({story:e.story},e.paraId?{paraId:e.paraId}:{})}function tp(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===Zt.nodes.image){let i=Iv(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 Iv(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 Nv(e,t){var p,f,b,w;if(np(e,t))return null;let n=0,r=Math.min(e.length,t.length);for(;n<r&&((p=e[n])==null?void 0:p.key)===((f=t[n])==null?void 0:f.key);)n+=1;let o=0,i=Math.min(e.length-n,t.length-n);for(;o<i&&((b=e[e.length-1-o])==null?void 0:b.key)===((w=t[t.length-1-o])==null?void 0:w.key);)o+=1;let a=e.length-o,s=t.length-o,l=t.slice(n,s).map(g=>g.content),d=e.slice(n,a).map(g=>g.content);return {operation:l.length>0&&d.length>0?"replace":l.length>0?"insert":"delete",from:n,toBefore:a,toAfter:s,insertedContent:l,deletedContent:d}}function np(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 Zf(e){return e.every(t=>t.kind==="text")}function Jf(e){return e.map(t=>t.kind==="text"?t.text:"").join("")}function ro(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 Tv(e,t){return v(v({},e!==null&&typeof e=="object"?e:{}),t)}function Pv(e){let t=e.trim().replace(/^#/,"");return /^[0-9a-f]{6}$/i.test(t)?t.toUpperCase():null}function Rv(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 {
18
+ `)}function Sf(e){return eo(e)?e.kind==="paragraph"?typeof e.paraId=="string"&&typeof e.story=="string"&&Array.isArray(e.content)&&e.content.length<=1e5&&e.content.every(Zx):e.kind!=="table"||typeof e.tableId!="string"||!Array.isArray(e.rows)||e.rows.length>1e4?false:e.rows.every(t=>eo(t)&&Array.isArray(t.cells)&&t.cells.length<=1e3&&t.cells.every(n=>eo(n)&&Array.isArray(n.blocks)&&n.blocks.length<=1e4&&n.blocks.every(Sf))):false}function Zx(e){return !eo(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 eo(e){return typeof e=="object"&&e!==null}function Jx(e){let t="",n=0,r=[...e.runs].map(o=>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+=Vs(e.text.slice(n,o.from))),o.from<n)continue;let i=Vs(e.text.slice(o.from,o.to)),a=Qx(o.format),s=a?`<span style="${Gs(a)}">${i}</span>`:i;if(o.hyperlink){let l=_r(o.hyperlink.target,o.hyperlink.anchor),d=o.hyperlink.tooltip?` title="${Gs(o.hyperlink.tooltip)}"`:"";s=`<a href="${Gs(l)}"${d}>${s}</a>`;}t+=s,n=o.to;}return n<e.text.length&&(t+=Vs(e.text.slice(n))),t||"<br>"}function Qx(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 Vs(e){return kf(e).replace(/\r\n?|\n/g,"<br>")}function kf(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function Gs(e){return kf(e).replace(/"/g,"&quot;")}function Cf(e,t,n,r){var a;if(e.nodeType===Node.TEXT_NODE){let s=(a=e.textContent)!=null?a:"";if(!s)return;let l=n.text.length;n.text+=s,(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+=`
19
+ `;return}let o=v(v({},t),ty(e)),i=e.tagName==="A"?ey(e):r;for(let s of Array.from(e.childNodes))Cf(s,o,n,i);}function ey(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 a=t.slice(1);try{a=decodeURIComponent(a);}catch(s){return}return a?v({anchor:a},n?{tooltip:n}:{}):void 0}let r=_r(t,void 0);return r==="#"?void 0:v({target:r},n?{tooltip:n}:{})}function ty(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=ny(t.fontSize);o!==null&&(n.fontSize=o);let i=wf(t.color),a=wf(t.backgroundColor);return i&&(n.color=i),a&&(n.highlight=a),n}function wf(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 ny(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 Js="http://www.w3.org/XML/1998/namespace",Vn="http://schemas.openxmlformats.org/officeDocument/2006/relationships",Gt="http://schemas.openxmlformats.org/package/2006/relationships",Lt="http://schemas.openxmlformats.org/drawingml/2006/main",ir="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",rr="http://schemas.openxmlformats.org/drawingml/2006/picture",Ei="http://schemas.openxmlformats.org/package/2006/content-types",Lf="application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",Ef="application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml",If="http://schemas.microsoft.com/office/2011/relationships/commentsExtended",sn="http://schemas.microsoft.com/office/word/2012/wordml",Nf=`${Vn}/hyperlink`,Wf="application/vnd.openxmlformats-package.relationships+xml";function oy(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=iy(o,{allowTrackedTable:o.kind==="table"&&!!o.revisionId&&r.get(o.revisionId)==="accept"});i?t.push(i):n.push({change:o,reason:ly(o)});}return {target:"word/document.xml",patches:t,unsupported:n}}function uI(e,t,n=wordView.buildIndices(e)){let r=oy(t),o=sy(e,n,r.patches);return v({plan:r},o)}function iy(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)||!Df(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?Bf(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 ay(e,t,n){var i,a;let r=[],o=[];for(let s of n){if(s.kind==="drawing-delete"||s.kind==="drawing-resize"||s.kind==="drawing-revision"){let u=t.drawingIdx.get(s.drawingId);if(!u&&s.kind==="drawing-revision"){let p=t.paraIdx.get(s.paraId.toUpperCase());u=p&&(i=Py(p,s.offset))!=null?i:void 0;}if(!u){o.push({patch:s,reason:`drawing not found: ${s.drawingId}`});continue}let f=or(e,u);if(!f){o.push({patch:s,reason:`drawing part not found: ${s.drawingId}`});continue}r.push({kind:"drawing",patch:s,partPath:f,drawing:u,paragraph:(a=t.paraIdx.get(s.paraId.toUpperCase()))!=null?a:null});continue}if(s.kind==="drawing-insert"){let u=t.paraIdx.get(s.paraId.toUpperCase());if(!u){o.push({patch:s,reason:`paragraph not found: ${s.paraId}`});continue}let f=or(e,u);if(!f){o.push({patch:s,reason:`paragraph part not found: ${s.paraId}`});continue}r.push({kind:"drawing",patch:s,partPath:f,drawing:u,paragraph:u});continue}if(s.kind==="comment"){let u=t.paraIdx.get(s.paraId.toUpperCase());if(!u){o.push({patch:s,reason:`paragraph not found: ${s.paraId}`});continue}let f=or(e,u);if(!f){o.push({patch:s,reason:`paragraph part not found: ${s.paraId}`});continue}r.push({kind:"comment",patch:s,partPath:f,paragraph:u});continue}if(s.kind==="table-insert"){let u=t.paraIdx.get(s.anchorParaId.toUpperCase());if(!u){o.push({patch:s,reason:`anchor paragraph not found: ${s.anchorParaId}`});continue}let f=or(e,u);if(!f){o.push({patch:s,reason:`paragraph part not found: ${s.anchorParaId}`});continue}r.push({kind:"table",patch:s,partPath:f,table:u,paragraph:u});continue}if(s.kind==="table-structure"||s.kind==="table-cell-format"||s.kind==="table-cell-clear"||s.kind==="table-cell-replace"||s.kind==="table-cell-replace-rich"||s.kind==="table-delete"){let u=t.tblIdx.get(s.tableId);if(!u){o.push({patch:s,reason:`table not found: ${s.tableId}`});continue}let f=or(e,u);if(!f){o.push({patch:s,reason:`table part not found: ${s.tableId}`});continue}r.push({kind:"table",patch:s,partPath:f,table:u});continue}let l=t.paraIdx.get(s.paraId.toUpperCase());if(!l){o.push({patch:s,reason:`paragraph not found: ${s.paraId}`});continue}let d=or(e,l);if(!d){o.push({patch:s,reason:`paragraph part not found: ${s.paraId}`});continue}r.push({kind:"paragraph",patch:s,partPath:d,paragraph:l});}return {resolved:r,unresolved:o}}function sy(e,t,n){var l,d;let r=[],o=[],i=[],a=new Set,s=t;for(let u of n){let f=ay(e,s,[u]);if(f.unresolved.length>0){i.push(...f.unresolved);continue}let p=f.resolved[0];if(!p)continue;let b=$f(e,p.kind==="paragraph"?p.paragraph:p.kind==="drawing"?p.drawing:p.kind==="table"?p.table:p.paragraph);if(!b){o.push({patch:p.patch,reason:`part not found: ${p.partPath}`});continue}if(p.kind==="drawing"){if(p.patch.kind==="drawing-insert"){let g=$y(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(b),r.push(p.patch),s=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")&&Mf(p.drawing),pack.markDirty(b),r.push(p.patch),s=wordView.buildIndices(e);continue}if(p.patch.kind==="drawing-resize"){let g=Oy(p.drawing,p.patch.width,p.patch.height);if(!g.ok){o.push({patch:p.patch,reason:g.reason});continue}pack.markDirty(b),r.push(p.patch),s=wordView.buildIndices(e);continue}Mf(p.drawing),pack.markDirty(b),r.push(p.patch),s=wordView.buildIndices(e);continue}if(p.kind==="table"){if(p.patch.kind==="table-insert"){let h=py(p.table.ownerDocument,p.patch.table,e,p.partPath);(d=p.table.parentNode)==null||d.insertBefore(h,p.table.nextSibling),pack.markDirty(b),r.push(p.patch),s=wordView.buildIndices(e);continue}if(p.patch.kind==="table-cell-format"){let h=my(p.table,p.patch);if(!h.ok){o.push({patch:p.patch,reason:h.reason});continue}pack.markDirty(b),r.push(p.patch),s=wordView.buildIndices(e);continue}if(p.patch.kind==="table-cell-clear"){let h=hy(p.table,p.patch);if(!h.ok){o.push({patch:p.patch,reason:h.reason});continue}pack.markDirty(b),r.push(p.patch),s=wordView.buildIndices(e);continue}if(p.patch.kind==="table-cell-replace"){let h=gy(p.table,p.patch);if(!h.ok){o.push({patch:p.patch,reason:h.reason});continue}pack.markDirty(b),r.push(p.patch),s=wordView.buildIndices(e);continue}if(p.patch.kind==="table-cell-replace-rich"){let h=by(e,p.partPath,p.table,p.patch);if(!h.ok){o.push({patch:p.patch,reason:h.reason});continue}pack.markDirty(b),r.push(p.patch),s=wordView.buildIndices(e);continue}if(p.patch.kind==="table-delete"){Ue(p.table),pack.markDirty(b),r.push(p.patch),s=wordView.buildIndices(e);continue}let g=wy(p.table,p.patch);if(!g.ok){o.push({patch:p.patch,reason:g.reason});continue}pack.markDirty(b),r.push(p.patch),s=wordView.buildIndices(e);continue}if(p.kind==="comment"){let g=Xy(e,p.partPath,p.paragraph,p.patch);if(!g.ok){o.push({patch:p.patch,reason:g.reason});continue}pack.markDirty(b),r.push(p.patch),s=wordView.buildIndices(e);continue}if(p.patch.kind==="revision"){let g=Vy(p.paragraph,p.patch);if(!g.ok){if((p.patch.op==="accept"||p.patch.op==="reject")&&g.reason===`revision not found: ${p.patch.revisionId}`&&a.has(p.patch.revisionId)){r.push(p.patch);continue}o.push({patch:p.patch,reason:g.reason});continue}pack.markDirty(b),r.push(p.patch),(p.patch.op==="accept"||p.patch.op==="reject")&&a.add(p.patch.revisionId),s=wordView.buildIndices(e);continue}if(p.patch.kind==="paragraph-format"){let g=Gy(p.paragraph,p.patch);if(!g.ok){o.push({patch:p.patch,reason:g.reason});continue}pack.markDirty(b),r.push(p.patch),s=wordView.buildIndices(e);continue}if(p.patch.kind==="format-revision"){let g=jy(p.paragraph,p.patch);if(!g.ok){o.push({patch:p.patch,reason:g.reason});continue}pack.markDirty(b),r.push(p.patch),s=wordView.buildIndices(e);continue}if(p.patch.kind==="paragraph-split"){let g=Ay(p.paragraph,p.patch.offset,p.patch.newParaId);if(!g.ok){o.push({patch:p.patch,reason:g.reason});continue}pack.markDirty(b),r.push(p.patch),s=wordView.buildIndices(e);continue}if(p.patch.kind==="paragraph-merge"){let g=Ly(p.paragraph);if(!g.ok){o.push({patch:p.patch,reason:g.reason});continue}pack.markDirty(b),r.push(p.patch),s=wordView.buildIndices(e);continue}if(p.patch.kind==="hyperlink"){let g=dy(e,p.partPath,p.paragraph,p.patch);if(!g.ok){o.push({patch:p.patch,reason:g.reason});continue}pack.markDirty(b),r.push(p.patch),s=wordView.buildIndices(e);continue}let w=Iy(p.paragraph,p.patch);if(!w.ok){o.push({patch:p.patch,reason:w.reason});continue}pack.markDirty(b),r.push(p.patch);}return {applied:r,skipped:o,unresolved:i}}function ly(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&&Bf(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 Bf(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 Df(e){try{let t=new URL(e).protocol.toLowerCase();return t==="http:"||t==="https:"}catch(t){return false}}function dy(e,t,n,r){var f,p,b;let o=de(n).filter(w=>!(w.namespaceURI===wordView.W_NS&&w.localName==="pPr")),i=o.reduce((w,g)=>w+jt(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(w=>{var g;return w.namespaceURI!==wordView.W_NS||!["r","hyperlink"].includes((g=w.localName)!=null?g:"")}))return {ok:false,reason:"hyperlink patch only supports text runs and existing hyperlinks"};if(o.some(w=>fy(w)))return {ok:false,reason:"hyperlink patch cannot cross inline objects"};let a=null,s=null;if(r.op==="set"){let w=(f=r.hyperlink)==null?void 0:f.target;if(!w||!Df(w))return {ok:false,reason:"only external http/https hyperlinks can be written back"};let g=Hf(e,t,w);a=g.id,s=g.part;}let l=[],d=0,u=[];for(let w of o){let g=jt(w),h=Math.max(0,r.from-d),y=Math.min(g,r.to-d);if(!(h<y)){l.push(w),d+=g;continue}if(h>0){let I=ar(w,0,h);I&&l.push(I);}let k=ar(w,h,y);if(k&&u.push(...uy(k)),y<g){let I=ar(w,y,g);I&&l.push(I);}d+=g;}if(r.op==="set"){let w=n.ownerDocument;if(!w||!a)return {ok:false,reason:"paragraph has no owner document or relationship"};let g=w.createElementNS(wordView.W_NS,"w:hyperlink");g.setAttributeNS(Vn,"r:id",a);let h=(b=(p=r.hyperlink)==null?void 0:p.tooltip)==null?void 0:b.trim();h&&g.setAttributeNS(wordView.W_NS,"w:tooltip",h);for(let y of u)g.appendChild(y);cy(l,g,r);}else Ff(l,u,r);for(let w of o)Ue(w);for(let w of l)n.appendChild(w);return s&&pack.markDirty(s),{ok:true}}function cy(e,t,n){Ff(e,[t],n);}function Ff(e,t,n){let r=0,o=false,i=[];for(let a of e)!o&&r>=n.from&&(i.push(...t),o=true),i.push(a),r+=jt(a);o||i.push(...t),e.splice(0,e.length,...i);}function ar(e,t,n){if(n<=t)return null;let r=e.cloneNode(true);return Xs(r,t,n),jt(r)>0?r:null}function uy(e){return e.namespaceURI===wordView.W_NS&&e.localName==="hyperlink"?de(e).filter(t=>t.namespaceURI===wordView.W_NS&&t.localName==="r"):[e]}function fy(e){return e.getElementsByTagNameNS(wordView.W_NS,"drawing").length>0||e.getElementsByTagNameNS(wordView.W_NS,"pict").length>0}function Hf(e,t,n){var u,f,p,b,w;let r=Ni(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(Gt,"Relationships",null);if(!h)throw new Error("XML implementation cannot create relationship document");o=pack.createXmlPart({path:r,contentType:Wf,xmlDom:h}),pack.setPart(e,o);}let i=o.xmlDom;if(!i)throw new Error(`relationship part has no XML DOM: ${r}`);let a=i.getElementsByTagNameNS(Gt,"Relationship");for(let g=0;g<a.length;g+=1){let h=a[g];if((h==null?void 0:h.getAttribute("Type"))===Nf&&h.getAttribute("Target")===n)return {id:(p=h.getAttribute("Id"))!=null?p:"",part:o}}let s=new Set;for(let g=0;g<a.length;g+=1){let h=(b=a[g])==null?void 0:b.getAttribute("Id");h&&s.add(h);}let l=1;for(;s.has(`rId${l}`);)l+=1;let d=i.createElementNS(Gt,"Relationship");return d.setAttribute("Id",`rId${l}`),d.setAttribute("Type",Nf),d.setAttribute("Target",n),d.setAttribute("TargetMode","External"),(w=i.documentElement)==null||w.appendChild(d),{id:`rId${l}`,part:o}}function Ni(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 py(e,t,n,r){var u,f,p,b,w,g,h,y,S;let o=k=>e.createElementNS(wordView.W_NS,`w:${k}`),i=o("tbl"),a=o("tblPr"),s=o("tblW");s.setAttributeNS(wordView.W_NS,"w:w",String(Math.max(0,Math.round((f=(u=t.layout)==null?void 0:u.width)!=null?f:0)))),s.setAttributeNS(wordView.W_NS,"w:type",(b=(p=t.layout)==null?void 0:p.widthType)!=null?b:"dxa"),a.appendChild(s);let l={};for(let k of ["top","left","bottom","right","insideH","insideV"]){let I=(w=t.borders)==null?void 0:w[k];l[k]={val:(g=I==null?void 0:I.val)!=null?g:"single",color:(h=I==null?void 0:I.color)!=null?h:"D9D9D9",size:(y=I==null?void 0:I.size)!=null?y:4};}if(word.writeWordTableBorders(a,"table",l),(S=t.layout)!=null&&S.mode){let k=o("tblLayout");k.setAttributeNS(wordView.W_NS,"w:type",t.layout.mode),a.appendChild(k);}i.appendChild(a);let d=o("tblGrid");for(let k of t.columnWidths){let I=o("gridCol");I.setAttributeNS(wordView.W_NS,"w:w",String(Math.max(1,Math.round(k)))),d.appendChild(I);}i.appendChild(d);for(let k of t.rows){let I=o("tr");for(let A of k.cells)I.appendChild(Of(e,A,n,r));i.appendChild(I);}return i}function Of(e,t,n,r){var u,f,p,b,w,g,h;let o=y=>e.createElementNS(wordView.W_NS,`w:${y}`),i=o("tc"),a=o("tcPr"),s=o("tcW");if(s.setAttributeNS(wordView.W_NS,"w:w",String(t.widthType==="auto"?0:Math.max(1,Math.round((u=t.width)!=null?u:0)))),s.setAttributeNS(wordView.W_NS,"w:type",(f=t.widthType)!=null?f:"dxa"),a.appendChild(s),(p=t.shading)!=null&&p.fill){let y=o("shd");y.setAttributeNS(wordView.W_NS,"w:val",(b=t.shading.val)!=null?b:"clear"),y.setAttributeNS(wordView.W_NS,"w:fill",t.shading.fill.replace(/^#/,"").toUpperCase()),a.appendChild(y);}if(t.verticalAlignment){let y=o("vAlign");y.setAttributeNS(wordView.W_NS,"w:val",t.verticalAlignment),a.appendChild(y);}i.appendChild(a);let l=t.blocks.filter(y=>y.kind==="paragraph"),d=l.length>0?l:[null];for(let y of d){let S=o("p");if(y)for(let k of y.content){if(k.kind==="image"){let F=Kf(k.src);if(!F)continue;let L=_f(n,r,F.bytes,F.extension,F.contentType);S.appendChild(Uf(e,L.id,k.drawingId,(w=k.width)!=null?w:96,(g=k.height)!=null?g:96)),pack.markDirty(L.part),pack.markDirty(L.mediaPart),qf(n,F.extension,F.contentType);continue}if(k.kind!=="text")continue;let I=o("r");if(k.format){let F=o("rPr");if(k.format.bold&&F.appendChild(o("b")),k.format.italic&&F.appendChild(o("i")),k.format.underline){let L=o("u");L.setAttributeNS(wordView.W_NS,"w:val","single"),F.appendChild(L);}if(k.format.strike&&F.appendChild(o("strike")),k.format.color){let L=o("color");L.setAttributeNS(wordView.W_NS,"w:val",k.format.color.replace(/^#/,"").toUpperCase()),F.appendChild(L);}if(k.format.fontSize){let L=o("sz");L.setAttributeNS(wordView.W_NS,"w:val",String(Math.round(k.format.fontSize*2))),F.appendChild(L);}if(k.format.fontFamily){let L=o("rFonts");for(let V of ["ascii","hAnsi","eastAsia"])L.setAttributeNS(wordView.W_NS,`w:${V}`,k.format.fontFamily);F.appendChild(L);}F.childNodes.length>0&&I.appendChild(F);}let A=o("t");if(A.textContent=k.text,/^\s|\s$/.test(k.text)&&A.setAttributeNS(Js,"xml:space","preserve"),I.appendChild(A),(h=k.hyperlink)!=null&&h.target){let F=Hf(n,r,k.hyperlink.target),L=e.createElementNS(wordView.W_NS,"w:hyperlink");L.setAttributeNS(Vn,"r:id",F.id),L.appendChild(I),S.appendChild(L),pack.markDirty(F.part);}else S.appendChild(I);}S.firstChild||S.appendChild(o("r")),i.appendChild(S);}return i}function my(e,t){let r=de(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=de(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 a=e.ownerDocument,s=de(i).find(l=>l.namespaceURI===wordView.W_NS&&l.localName==="tcPr");if(s||(s=a.createElementNS(wordView.W_NS,"w:tcPr"),i.insertBefore(s,i.firstChild)),t.format.backgroundColor!==void 0){let l=de(s).find(d=>d.namespaceURI===wordView.W_NS&&d.localName==="shd");if(t.format.backgroundColor===null)l&&Ue(l);else {let d=l!=null?l:a.createElementNS(wordView.W_NS,"w:shd");d.setAttributeNS(wordView.W_NS,"w:val","clear"),d.setAttributeNS(wordView.W_NS,"w:fill",t.format.backgroundColor.replace(/^#/,"").toUpperCase()),l||s.appendChild(d);}}if(t.format.verticalAlignment!==void 0){let l=de(s).find(d=>d.namespaceURI===wordView.W_NS&&d.localName==="vAlign");if(t.format.verticalAlignment===null)l&&Ue(l);else {let d=l!=null?l:a.createElementNS(wordView.W_NS,"w:vAlign");d.setAttributeNS(wordView.W_NS,"w:val",t.format.verticalAlignment),l||s.appendChild(d);}}if(t.format.borderColor!==void 0){let l=t.format.borderColor===null?{val:"nil"}:{val:"single",size:4,color:t.format.borderColor.replace(/^#/,"").toUpperCase()},d={top:v({},l),left:v({},l),bottom:v({},l),right:v({},l),insideH:v({},l),insideV:v({},l)};word.writeWordTableBorders(s,"cell",d);}return {ok:true}}function hy(e,t){let r=de(e).filter(s=>s.namespaceURI===wordView.W_NS&&s.localName==="tr")[t.rowIndex];if(!r)return {ok:false,reason:`table row out of range: ${t.rowIndex}`};let i=de(r).filter(s=>s.namespaceURI===wordView.W_NS&&s.localName==="tc")[t.columnIndex];if(!i)return {ok:false,reason:`table column out of range: ${t.columnIndex}`};let a=de(i).find(s=>s.namespaceURI===wordView.W_NS&&s.localName==="tcPr");for(let s of de(i))s!==a&&Ue(s);return i.appendChild(i.ownerDocument.createElementNS(wordView.W_NS,"w:p")),{ok:true}}function gy(e,t){let r=de(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=de(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 a=de(i).find(p=>p.namespaceURI===wordView.W_NS&&p.localName==="tcPr"),s=de(i).find(p=>p.namespaceURI===wordView.W_NS&&p.localName==="p");for(let p of de(i))p!==a&&Ue(p);let l=i.ownerDocument.createElementNS(wordView.W_NS,"w:p"),d=s&&de(s).find(p=>p.namespaceURI===wordView.W_NS&&p.localName==="pPr");d&&l.appendChild(d.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(Js,"xml:space","preserve"),u.appendChild(f),l.appendChild(u),i.appendChild(l),{ok:true}}function by(e,t,n,r){let i=de(n).filter(d=>d.namespaceURI===wordView.W_NS&&d.localName==="tr")[r.rowIndex];if(!i)return {ok:false,reason:`table row out of range: ${r.rowIndex}`};let s=de(i).filter(d=>d.namespaceURI===wordView.W_NS&&d.localName==="tc")[r.columnIndex];if(!s)return {ok:false,reason:`table column out of range: ${r.columnIndex}`};let l=Of(n.ownerDocument,r.cell,e,t);for(let d of de(s))Ue(d);for(let d of de(l))s.appendChild(d.cloneNode(true));return {ok:true}}function wy(e,t){var u,f,p,b;let n=de(e).filter(w=>w.namespaceURI===wordView.W_NS&&w.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 w=n[Math.min(t.rowIndex,n.length-1)],g=yy(w);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=de(r).filter(w=>w.namespaceURI===wordView.W_NS&&w.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 w=n.map(g=>de(g).filter(h=>h.namespaceURI===wordView.W_NS&&h.localName==="tc"));if(w.some(g=>g.length!==o.length||g.some(h=>$n(h)!==1||Ci(h))))return {ok:false,reason:"table column structure is not a regular non-merged grid"};for(let g of w)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=_s(h);(p=g[0].parentNode)==null||p.insertBefore(y,(f=g[t.columnIndex])!=null?f:null);}return Ey(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=>de(y).filter(S=>S.namespaceURI===wordView.W_NS&&S.localName==="tc")[t.columnIndex]);if(h.some(y=>!y||$n(y)!==1||Ci(y)))return {ok:false,reason:"vertical merge requires a regular non-merged column"};Tf(h[0],"restart");for(let y of h.slice(1)){Tf(y,"continue");let S=de(y).find(k=>k.namespaceURI===wordView.W_NS&&k.localName==="tcPr");for(let k of de(y))k!==S&&Ue(k);y.appendChild(y.ownerDocument.createElementNS(wordView.W_NS,"w:p"));}return {ok:true}}let w=(b=t.endColumnIndex)!=null?b:t.columnIndex+1;if(t.columnIndex<0||w>=o.length||w<=t.columnIndex)return {ok:false,reason:`merge start column out of range: ${t.columnIndex}`};if(o.some(h=>$n(h)!==1||Ci(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<=w;h+=1){let y=o[h];vy(g,y),Ue(y);}return Sy(g,w-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 w=n.slice(t.rowIndex,t.endRowIndex+1).map(g=>de(g).filter(h=>h.namespaceURI===wordView.W_NS&&h.localName==="tc")[t.columnIndex]);if(w.some((g,h)=>{var k;if(!g||$n(g)!==1)return true;let y=(k=de(g).find(I=>I.namespaceURI===wordView.W_NS&&I.localName==="tcPr"))==null?void 0:k.getElementsByTagNameNS(wordView.W_NS,"vMerge")[0],S=y==null?void 0:y.getAttributeNS(wordView.W_NS,"val");return h===0?S!=="restart":S!=="continue"}))return {ok:false,reason:"cell is not a vertically merged cell"};for(let g of w)xy(g);return {ok:true}}let i=n[t.rowIndex],a=de(i).filter(w=>w.namespaceURI===wordView.W_NS&&w.localName==="tc"),s=0,l=a.find(w=>{let g=s===t.columnIndex;return s+=$n(w),g});if(!l)return {ok:false,reason:`split column out of range: ${t.columnIndex}`};if(Ci(l)||$n(l)<=1)return {ok:false,reason:"cell is not a horizontally merged cell"};let d=$n(l);ky(l);for(let w=1;w<d;w+=1){let g=_s(l);i.insertBefore(g,l.nextSibling);}return {ok:true}}function Tf(e,t){var i;let n=e.ownerDocument,r=de(e).find(a=>a.namespaceURI===wordView.W_NS&&a.localName==="tcPr");r||(r=n.createElementNS(wordView.W_NS,"w:tcPr"),e.insertBefore(r,e.firstChild));let o=(i=de(r).find(a=>a.namespaceURI===wordView.W_NS&&a.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 xy(e){let t=de(e).find(r=>r.namespaceURI===wordView.W_NS&&r.localName==="tcPr"),n=t&&de(t).find(r=>r.namespaceURI===wordView.W_NS&&r.localName==="vMerge");n&&Ue(n);}function yy(e){let t=e.cloneNode(true),n=de(t).filter(r=>r.namespaceURI===wordView.W_NS&&r.localName==="tc");for(let r of n){let o=_s(r);jf(r,o);}return t}function _s(e){let t=e.ownerDocument,n=t.createElementNS(wordView.W_NS,"w:tc"),r=de(e).find(s=>s.namespaceURI===wordView.W_NS&&s.localName==="tcPr");r&&n.appendChild(r.cloneNode(true));let o=t.createElementNS(wordView.W_NS,"w:p"),i=de(e).find(s=>s.namespaceURI===wordView.W_NS&&s.localName==="p"),a=i&&de(i).find(s=>s.namespaceURI===wordView.W_NS&&s.localName==="pPr");return a&&o.appendChild(a.cloneNode(true)),o.appendChild(t.createElementNS(wordView.W_NS,"w:r")),n.appendChild(o),n}function vy(e,t){for(let n of de(t))n.namespaceURI===wordView.W_NS&&n.localName==="tcPr"||e.appendChild(n.cloneNode(true));}function $n(e){var r,o;let t=(o=(r=de(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 Ci(e){var t;return !!((t=de(e).find(n=>n.namespaceURI===wordView.W_NS&&n.localName==="tcPr"))!=null&&t.getElementsByTagNameNS(wordView.W_NS,"vMerge").length)}function Sy(e,t){let n=Cy(e,"tcPr"),r=de(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 ky(e){let t=de(e).find(r=>r.namespaceURI===wordView.W_NS&&r.localName==="tcPr"),n=t&&de(t).find(r=>r.namespaceURI===wordView.W_NS&&r.localName==="gridSpan");n&&Ue(n);}function Cy(e,t){let n=de(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 Ey(e,t,n){var s;let r=de(e).find(l=>l.namespaceURI===wordView.W_NS&&l.localName==="tblGrid");if(!r)return;let o=de(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 a=i.cloneNode(true);r.insertBefore(a,(s=o[n])!=null?s:null);}function or(e,t){var n,r;return (r=(n=$f(e,t))==null?void 0:n.path)!=null?r:null}function $f(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 Iy(e,t){var n,r;return t.op==="insert"?zf(e,t.offset,t.text):t.op==="delete"?Pf(e,t.offset,t.text.length,""):Pf(e,t.offset,(r=(n=t.deletedText)==null?void 0:n.length)!=null?r:0,t.text)}function zf(e,t,n){var s,l,d;if(n.length===0)return {ok:true};let r=ro(e),o=r.reduce((u,f)=>u+f.length,0);if(Ny(e)&&t===o)return Rf(e,n),{ok:true};if(r.every(u=>u.kind!=="text"))return t!==0?{ok:false,reason:`insert offset out of range: ${t}`}:(Rf(e,n),{ok:true});let i=qs(r,t,true);if(!i)return {ok:false,reason:`insert offset out of range: ${t}`};if(i.node.localName==="delText"&&i.localOffset===((l=(s=i.node.textContent)==null?void 0:s.length)!=null?l:0)){let u=Ty(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 b=p.createElementNS(wordView.W_NS,"w:r"),w=p.createElementNS(wordView.W_NS,"w:t");return w.textContent=n,Sn(w),b.appendChild(w),e.insertBefore(b,u.nextSibling),{ok:true}}}let a=(d=i.node.textContent)!=null?d:"";return i.node.textContent=`${a.slice(0,i.localOffset)}${n}${a.slice(i.localOffset)}`,Sn(i.node),{ok:true}}function Pf(e,t,n,r){var p,b;if(n===0)return zf(e,t,r);let o=ro(e),i=o.filter(w=>w.kind==="text").map(w=>w.node),a=qs(o,t,false),s=qs(o,t+n,true);if(!a||!s)return {ok:false,reason:`text range out of range: ${t}:${n}`};let l=(p=a.node.textContent)!=null?p:"";if(a.node===s.node)return a.node.textContent=`${l.slice(0,a.localOffset)}${r}${l.slice(s.localOffset)}`,Sn(a.node),{ok:true};let d=i.indexOf(a.node),u=i.indexOf(s.node);if(d<0||u<0||d>u)return {ok:false,reason:`text range out of range: ${t}:${n}`};let f=(b=s.node.textContent)!=null?b:"";a.node.textContent=`${l.slice(0,a.localOffset)}${r}`,Sn(a.node);for(let w=d+1;w<u;w++)i[w].textContent="";return s.node.textContent=f.slice(s.localOffset),Sn(s.node),{ok:true}}function ro(e){let t=[];return Gf(e,t),t}function Ny(e){return e.getElementsByTagNameNS(wordView.W_NS,"fldChar").length>0||e.getElementsByTagNameNS(wordView.W_NS,"instrText").length>0}function Vf(e){return ro(e).filter(t=>t.kind==="text").map(t=>t.node)}function Gf(e,t){var r,o,i,a;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:(a=(i=n.textContent)==null?void 0:i.length)!=null?a: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 s=0;s<n.childNodes.length;s+=1){let l=n.childNodes[s];l&&Gf(l,t);}}function Ty(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 Py(e,t){let n=0,r=ro(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 qs(e,t,n){var o;let r=0;for(let i=0;i<e.length;i+=1){let a=e[i],s=r+a.length;if(a.kind==="text"){if(t>=r&&(t<s||n&&t===s))return {node:a.node,localOffset:t-r}}else if(t>=r&&t<=s)return (o=Ry(e,i))!=null?o:My(e,i);r=s;}return null}function Ry(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 My(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 Rf(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,Sn(o),r.appendChild(o),e.appendChild(r);}function Sn(e){var n;let t=(n=e.textContent)!=null?n:"";/^\s|\s$|\s{2,}/.test(t)&&e.setAttributeNS(Js,"xml:space","preserve");}function Ay(e,t,n){let r=e.parentNode,o=e.ownerDocument;if(!r||!o)return {ok:false,reason:"paragraph has no parent document"};let i=de(e).filter(u=>!(u.namespaceURI===wordView.W_NS&&u.localName==="pPr")),a=i.reduce((u,f)=>u+jt(f),0);if(t<0||t>a)return {ok:false,reason:`split offset out of range: ${t}`};let s=Wy(o,i,t),l=o.createElementNS(wordView.W_NS,"w:p");Dy(e,l,n);let d=de(e).find(u=>u.namespaceURI===wordView.W_NS&&u.localName==="pPr");d&&l.appendChild(d.cloneNode(true));for(let u of s)l.appendChild(u);return r.insertBefore(l,e.nextSibling),{ok:true}}function Ly(e){let t=Fy(e);if(!t)return {ok:false,reason:"next paragraph not found for merge"};for(let n of de(t))n.namespaceURI===wordView.W_NS&&n.localName==="pPr"||e.appendChild(n.cloneNode(true));return Ue(t),{ok:true}}function Wy(e,t,n){let r=[],o=0,i=false;for(let a of t){let s=jt(a),l=o+s;if(i)r.push(a.cloneNode(true)),Ue(a);else if(n<=o)r.push(a.cloneNode(true)),Ue(a);else if(!(n>=l)){let d=By(e,a,n-o);d.after&&r.push(d.after),i=true;}!i&&n===l&&(i=true),o=l;}return r}function By(e,t,n){let r=t.cloneNode(true),o=t.cloneNode(true);return Xs(r,0,n),Xs(o,n,jt(t)),jf(t,r),Hy(o)||jt(o)>0?{after:o}:{after:null}}function Xs(e,t,n){var i;let r=Vf(e),o=0;for(let a of r){let s=(i=a.textContent)!=null?i:"",l=o+s.length,d=Math.max(0,t-o),u=Math.min(s.length,n-o);a.textContent=d<u?s.slice(d,u):"",Sn(a),o=l;}}function jt(e){var o,i,a;if(e.namespaceURI===wordView.W_NS&&e.localName==="drawing")return 1;let t=0,n=e.getElementsByTagNameNS(wordView.W_NS,"t");for(let s=0;s<n.length;s++)t+=(a=(i=(o=n[s])==null?void 0:o.textContent)==null?void 0:i.length)!=null?a:0;let r=e.getElementsByTagNameNS(wordView.W_NS,"drawing");return t+=r.length,t}function Dy(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 de(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 Fy(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 Hy(e){return Vf(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 jf(e,t){var n;(n=e.parentNode)==null||n.replaceChild(t,e);}function Mf(e){var n;let t=e.parentNode;if(t){if(sv(t)&&t.namespaceURI===wordView.W_NS&&t.localName==="r"&&av(t)){(n=t.parentNode)==null||n.removeChild(t);return}t.removeChild(e);}}function Oy(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=de(e).find(l=>l.namespaceURI===ir&&(l.localName==="inline"||l.localName==="anchor"));if(!i)return {ok:false,reason:"drawing has no wp:inline or wp:anchor container"};let a=de(i).find(l=>l.namespaceURI===ir&&l.localName==="extent");if(!a)return {ok:false,reason:"drawing has no wp:extent"};a.setAttribute("cx",String(r)),a.setAttribute("cy",String(o));let s=i.getElementsByTagNameNS(Lt,"xfrm");for(let l=0;l<s.length;l+=1){let d=s[l],u=d&&de(d).find(f=>f.namespaceURI===Lt&&f.localName==="ext");u&&(u.setAttribute("cx",String(r)),u.setAttribute("cy",String(o)));}return {ok:true}}function $y(e,t,n,r){let o=Kf(r.src);if(!o)return {ok:false,reason:"image insert requires a base64 data:image URL"};let i=_f(e,t,o.bytes,o.extension,o.contentType),a=Uf(n.ownerDocument,i.id,r.drawingId,r.width,r.height),s=de(n).filter(p=>!(p.namespaceURI===wordView.W_NS&&p.localName==="pPr")),l=s.reduce((p,b)=>p+jt(b),0);if(r.offset<0||r.offset>l)return {ok:false,reason:`image insert offset out of range: ${r.offset}`};let d=[],u=0,f=false;for(let p of s){let b=jt(p);if(!f&&r.offset<=u&&(d.push(a),f=true),!f&&r.offset<u+b&&p.namespaceURI===wordView.W_NS&&p.localName==="r"){let w=ar(p,0,r.offset-u),g=ar(p,r.offset-u,b);w&&d.push(w),d.push(a),f=true,g&&d.push(g);}else d.push(p);u+=b;}f||d.push(a);for(let p of s)Ue(p);for(let p of d)n.appendChild(p);return pack.markDirty(i.part),pack.markDirty(i.mediaPart),qf(e,o.extension,o.contentType),{ok:true}}function Uf(e,t,n,r,o){let i=Math.round(r/96*914400),a=Math.round(o/96*914400),s=e.createElementNS(wordView.W_NS,"w:r"),l=e.createElementNS(wordView.W_NS,"w:drawing"),d=e.createElementNS(ir,"wp:inline"),u=e.createElementNS(ir,"wp:extent");u.setAttribute("cx",String(i)),u.setAttribute("cy",String(a)),d.appendChild(u);let f=e.createElementNS(ir,"wp:docPr");f.setAttribute("id",String(Math.abs(zy(n))+1)),f.setAttribute("name",`Picture ${n}`),d.appendChild(f),d.appendChild(e.createElementNS(ir,"wp:cNvGraphicFramePr"));let p=e.createElementNS(Lt,"a:graphic"),b=e.createElementNS(Lt,"a:graphicData");b.setAttribute("uri","http://schemas.openxmlformats.org/drawingml/2006/picture");let w=e.createElementNS(rr,"pic:pic"),g=e.createElementNS(rr,"pic:nvPicPr"),h=e.createElementNS(rr,"pic:cNvPr");h.setAttribute("id","0"),h.setAttribute("name",`image-${n}`),g.appendChild(h),g.appendChild(e.createElementNS(rr,"pic:cNvPicPr")),w.appendChild(g);let y=e.createElementNS(rr,"pic:blipFill"),S=e.createElementNS(Lt,"a:blip");S.setAttributeNS(Vn,"r:embed",t),y.appendChild(S);let k=e.createElementNS(Lt,"a:stretch");k.appendChild(e.createElementNS(Lt,"a:fillRect")),y.appendChild(k),w.appendChild(y);let I=e.createElementNS(rr,"pic:spPr"),A=e.createElementNS(Lt,"a:xfrm"),F=e.createElementNS(Lt,"a:ext");F.setAttribute("cx",String(i)),F.setAttribute("cy",String(a)),A.appendChild(e.createElementNS(Lt,"a:off")),A.appendChild(F),I.appendChild(A);let L=e.createElementNS(Lt,"a:prstGeom");return L.setAttribute("prst","rect"),L.appendChild(e.createElementNS(Lt,"a:avLst")),I.appendChild(L),w.appendChild(I),b.appendChild(w),p.appendChild(b),d.appendChild(p),l.appendChild(d),s.appendChild(l),s}function Kf(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 _f(e,t,n,r,o){var g,h,y,S;let i=Ni(t),a=e.parts.get(i);if(!(a!=null&&a.xmlDom)){let k=(g=Array.from(e.parts.values()).find(A=>A.xmlDom))==null?void 0:g.xmlDom;if(!k)throw new Error("cannot create image relationships without an XML part");let I=(h=k.implementation)==null?void 0:h.createDocument(Gt,"Relationships",null);if(!I)throw new Error("XML implementation cannot create relationship document");a=pack.createXmlPart({path:i,contentType:Wf,xmlDom:I}),pack.setPart(e,a);}let s=a.xmlDom;if(!s)throw new Error(`relationship part has no XML DOM: ${i}`);let l=s.getElementsByTagNameNS(Gt,"Relationship"),d=1,u=new Set;for(let k=0;k<l.length;k+=1){let I=(y=l[k])==null?void 0:y.getAttribute("Id");I&&u.add(I);}for(;u.has(`rId${d}`);)d+=1;let f=1;for(;e.parts.has(`word/media/image${f}.${r}`);)f+=1;let p=`word/media/image${f}.${r}`,b=pack.createBinaryPart({path:p,contentType:o,bytes:n});pack.setPart(e,b);let w=s.createElementNS(Gt,"Relationship");return w.setAttribute("Id",`rId${d}`),w.setAttribute("Type",`${Vn}/image`),w.setAttribute("Target",`media/image${f}.${r}`),(S=s.documentElement)==null||S.appendChild(w),{id:`rId${d}`,part:a,mediaPart:b}}function qf(e,t,n){var s,l,d;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=(s=i[u])==null?void 0:s.getAttribute("Extension"))==null?void 0:l.toLowerCase())===t.toLowerCase())return;let a=o.createElementNS("http://schemas.openxmlformats.org/package/2006/content-types","Default");a.setAttribute("Extension",t),a.setAttribute("ContentType",n),(d=o.documentElement)==null||d.appendChild(a),pack.markDirty(r);}function zy(e){let t=0;for(let n=0;n<e.length;n+=1)t=t*31+e.charCodeAt(n)|0;return t}function Vy(e,t){var l,d,u;if(t.op==="accept"||t.op==="reject"){let f=t.revisionKind==="insert"?"ins":"del",b=Array.from(e.getElementsByTagNameNS(wordView.W_NS,f)).filter(w=>w.getAttributeNS(wordView.W_NS,"id")===t.revisionId);if(b.length===0)return {ok:false,reason:`revision not found: ${t.revisionId}`};for(let w of b){let g=w.parentNode;if(!g)continue;if(!(f==="ins"&&t.op==="accept"||f==="del"&&t.op==="reject")){g.removeChild(w);continue}let y=Array.from(w.childNodes);if(f==="del")for(let S of y)S.nodeType===1&&qy(S);for(let S of y)g.insertBefore(S,w);g.removeChild(w);}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+=(d=(l=p.textContent)==null?void 0:l.length)!=null?d:0;continue}if(p.localName!=="r"){i.push(p);continue}let b=Array.from(p.getElementsByTagNameNS(wordView.W_NS,"t"));if(b.length!==1)return {ok:false,reason:"revision writeback requires runs with one text node"};let w=(u=b[0].textContent)!=null?u:"",g=n,h=n+w.length;if(n=h,h<=t.from||g>=t.to){i.push(p);continue}let y=Math.max(0,t.from-g),S=Math.min(w.length,t.to-g);y>0&&i.push(sr(p,w.slice(0,y))),S>y&&(o<0&&(o=i.length),r.push(sr(p,w.slice(y,S)))),S<w.length&&i.push(sr(p,w.slice(S)));}if(r.length===0||t.to>n)return {ok:false,reason:`revision range out of range: ${t.from}:${t.to}`};let a=e.ownerDocument;if(!a)return {ok:false,reason:"revision paragraph has no owner document"};let s=a.createElementNS(wordView.W_NS,t.revisionKind==="insert"?"w:ins":"w:del");s.setAttributeNS(wordView.W_NS,"w:id",t.revisionId),s.setAttributeNS(wordView.W_NS,"w:author","User"),s.setAttributeNS(wordView.W_NS,"w:date",new Date().toISOString());for(let f of r)t.revisionKind==="delete"&&_y(f),s.appendChild(f);for(i.splice(o<0?i.length:o,0,s),Ky(i);e.firstChild;)e.removeChild(e.firstChild);for(let f of i)e.appendChild(f);return {ok:true}}function Gy(e,t){var a;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 s=Array.from(e.getElementsByTagNameNS(wordView.W_NS,"r")),l=0,d=0;for(let u of s){let f=Xf(u);if(f.length===0)continue;let p=l,b=l+f.length;if(l=b,!(b<=t.from||p>=t.to)){if(t.from>p||t.to<b)return {ok:false,reason:"format writeback requires whole runs inside tracked content"};Ys(u,t.format),d+=f.length;}}return d===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 s of Array.from(e.childNodes)){if(s.nodeType!==1||s.namespaceURI!==wordView.W_NS||s.localName!=="r"){r.push(s);continue}let l=s,d=Array.from(l.getElementsByTagNameNS(wordView.W_NS,"t"));if(d.length!==1)return {ok:false,reason:"format writeback requires runs with one text node"};let u=(a=d[0].textContent)!=null?a:"",f=o,p=o+u.length;if(o=p,p<=t.from||f>=t.to){r.push(l);continue}let b=Math.max(0,t.from-f),w=Math.min(u.length,t.to-f);if(b>0&&r.push(sr(l,u.slice(0,b))),w>b){let g=sr(l,u.slice(b,w));Ys(g,t.format),r.push(g),i+=w-b;}w<u.length&&r.push(sr(l,u.slice(w)));}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 s of r)e.appendChild(s);return {ok:true}}function jy(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,a=0;for(let s of n){let l=Xf(s),d=i,u=i+l.length;if(i=u,u<=t.from||d>=t.to)continue;if(t.from>d||t.to<u)return {ok:false,reason:"format revision currently requires whole runs"};let f=Uy(s);zn(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 b=f.ownerDocument.createElementNS(wordView.W_NS,"w:r");Ys(b,(o=t.beforeFormat)!=null?o:{});let w=de(b).find(g=>g.namespaceURI===wordView.W_NS&&g.localName==="rPr");if(w)for(let g of Array.from(w.childNodes))p.appendChild(g);f.appendChild(p),a+=l.length;}return a===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 a=de(i).find(l=>l.namespaceURI===wordView.W_NS&&l.localName==="rPr"),s=a&&de(a).find(l=>l.namespaceURI===wordView.W_NS&&l.localName==="rPrChange"&&l.getAttributeNS(wordView.W_NS,"id")===t.revisionId);if(!(!s||!a)){if(t.op==="reject"){for(let l of Array.from(a.childNodes))l!==s&&a.removeChild(l);for(let l of Array.from(s.childNodes))a.appendChild(l.cloneNode(true));}a.removeChild(s),r+=1;}}return r>0?{ok:true}:{ok:false,reason:`format revision not found: ${t.revisionId}`}}function Xf(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 Uy(e){let t=de(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 Ys(e,t){var i,a,s;let n=e.ownerDocument,r=(i=de(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,d]of o)t[l]!==void 0&&(zn(r,d),t[l]&&r.appendChild(n.createElementNS(wordView.W_NS,`w:${d}`)));if(t.underline!==void 0&&(zn(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&&(zn(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){zn(r,"shd");let l=(s=(a=t.shading)==null?void 0:a.fill)!=null?s:t.highlight;if(l){let d=n.createElementNS(wordView.W_NS,"w:shd");d.setAttribute("val","clear"),d.setAttribute("fill",l.replace(/^#/,"").toUpperCase()),r.appendChild(d);}}if(t.fontSize!==void 0){zn(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){zn(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 zn(e,t){for(let n of de(e))n.namespaceURI===wordView.W_NS&&n.localName===t&&e.removeChild(n);}function Ky(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 a of Array.from(i.childNodes))o.appendChild(a);e.splice(t,1),t-=1;}}}function sr(e,t){let n=e.cloneNode(true),r=n.getElementsByTagNameNS(wordView.W_NS,"t")[0];return r&&(r.textContent=t),n}function _y(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 a=0;a<o.attributes.length;a+=1){let s=o.attributes[a];s&&i.setAttributeNS(s.namespaceURI,s.name,s.value);}i.textContent=o.textContent,(r=o.parentNode)==null||r.replaceChild(i,o);}}function qy(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 a=0;a<o.attributes.length;a+=1){let s=o.attributes[a];s&&i.setAttributeNS(s.namespaceURI,s.name,s.value);}i.textContent=o.textContent,(r=o.parentNode)==null||r.replaceChild(i,o);}}function Xy(e,t,n,r){var a;if(r.op==="insert"){if(r.from<0||r.to<=r.from)return {ok:false,reason:"comment range is empty or invalid"};let s=ro(n).reduce((d,u)=>d+u.length,0);if(r.to>s)return {ok:false,reason:`comment range out of range: ${r.from}:${r.to}`};Yy(e,t),ov(n,r.from,r.to,r.commentId);let l=new Date().toISOString();return Qy(e,r.commentId,(a=r.body)!=null?a:"","User",l),r.parentCommentId!==void 0&&ev(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 s=e.parts.get("word/comments.xml"),l=s==null?void 0:s.xmlDom;if(!s||!l)return {ok:false,reason:"comments.xml part not found"};let d=l.getElementsByTagNameNS(wordView.W_NS,"comment");for(let u=0;u<d.length;u+=1){let f=d[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 b=l.createElementNS(wordView.W_NS,"w:p"),w=l.createElementNS(wordView.W_NS,"w:r"),g=l.createElementNS(wordView.W_NS,"w:t");g.textContent=r.body,w.appendChild(g),b.appendChild(w),f.appendChild(b);}else {p[0].textContent=r.body;for(let b=p.length-1;b>=1;b-=1)Ue(p[b]);}return pack.markDirty(s),{ok:true}}return {ok:false,reason:`comment not found: ${r.commentId}`}}iv(e,r.commentId),nv(e,r.commentId);let o=e.parts.get("word/comments.xml"),i=o==null?void 0:o.xmlDom;if(i){let s=i.getElementsByTagNameNS(wordView.W_NS,"comment");for(let l=0;l<s.length;l+=1){let d=s[l];(d==null?void 0:d.getAttributeNS(wordView.W_NS,"id"))===String(r.commentId)&&Ue(d);}pack.markDirty(o);}return {ok:true}}function Yy(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(s=>s.xmlDom))==null?void 0:r.xmlDom;if(!i)throw new Error("cannot create comments.xml without an XML part");let a=(o=i.implementation)==null?void 0:o.createDocument(wordView.W_NS,"w:comments",null);if(!a)throw new Error("XML implementation cannot create comments.xml");n=pack.createXmlPart({path:"word/comments.xml",contentType:Lf,xmlDom:a}),pack.setPart(e,n),Zy(e);}return Jy(e,t),n}function Zy(e){var i,a;let t=pack.getPart(e,"[Content_Types].xml"),n=t==null?void 0:t.xmlDom;if(!t||!n)return;let r=n.getElementsByTagNameNS(Ei,"Override");for(let s=0;s<r.length;s+=1)if(((i=r[s])==null?void 0:i.getAttribute("PartName"))==="/word/comments.xml")return;let o=n.createElementNS(Ei,"Override");o.setAttribute("PartName","/word/comments.xml"),o.setAttribute("ContentType",Lf),(a=n.documentElement)==null||a.appendChild(o),pack.markDirty(t);}function Jy(e,t){var d,u,f;let n=Ni(t),r=e.parts.get(n);if(!(r!=null&&r.xmlDom))return;let o=r.xmlDom,i=o.getElementsByTagNameNS(Gt,"Relationship");for(let p=0;p<i.length;p+=1)if(((d=i[p])==null?void 0:d.getAttribute("Type"))===`${Vn}/comments`)return;let a=new Set;for(let p=0;p<i.length;p+=1){let b=(u=i[p])==null?void 0:u.getAttribute("Id");b&&a.add(b);}let s=1;for(;a.has(`rId${s}`);)s+=1;let l=o.createElementNS(Gt,"Relationship");l.setAttribute("Id",`rId${s}`),l.setAttribute("Type",`${Vn}/comments`),l.setAttribute("Target","comments.xml"),(f=o.documentElement)==null||f.appendChild(l),pack.markDirty(r);}function Qy(e,t,n,r,o){let i=e.parts.get("word/comments.xml"),a=i==null?void 0:i.xmlDom;if(!i||!a)return;let s=a.documentElement;if(!s||Array.from(a.getElementsByTagNameNS(wordView.W_NS,"comment")).some(p=>p.getAttributeNS(wordView.W_NS,"id")===String(t)))return;let l=a.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 d=a.createElementNS(wordView.W_NS,"w:p");d.setAttributeNS(wordView.W14_NS,"w14:paraId",tv(t));let u=a.createElementNS(wordView.W_NS,"w:r"),f=a.createElementNS(wordView.W_NS,"w:t");f.textContent=n,Sn(f),u.appendChild(f),d.appendChild(u),l.appendChild(d),s.appendChild(l),pack.markDirty(i);}function ev(e,t,n){let r=e.parts.get("word/comments.xml"),o=r==null?void 0:r.xmlDom;if(!o)return;let i=b=>{var g,h,y;let w=o.getElementsByTagNameNS(wordView.W_NS,"comment");for(let S=0;S<w.length;S+=1){if(((g=w[S])==null?void 0:g.getAttributeNS(wordView.W_NS,"id"))!==String(b))continue;let k=(h=w[S])==null?void 0:h.getElementsByTagNameNS(wordView.W_NS,"p")[0];return (y=k==null?void 0:k.getAttributeNS(wordView.W14_NS,"paraId"))!=null?y:null}return null},a=i(t),s=i(n);if(!a||!s)return;let l=rv(e,"word/document.xml"),d=l.xmlDom,u=d==null?void 0:d.documentElement;if(!d||!u||Array.from(u.getElementsByTagNameNS(sn,"commentEx")).some(b=>b.getAttributeNS(sn,"paraId")===a))return;let p=d.createElementNS(sn,"w15:commentEx");p.setAttributeNS(sn,"w15:paraId",a),p.setAttributeNS(sn,"w15:paraIdParent",s),u.appendChild(p),pack.markDirty(l);}function tv(e){return e.toString(16).padStart(8,"0").slice(-8)}function nv(e,t){var d,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 a=r.getElementsByTagNameNS(wordView.W_NS,"comment"),s=null;for(let b=0;b<a.length;b+=1)if(((d=a[b])==null?void 0:d.getAttributeNS(wordView.W_NS,"id"))===String(t)){s=(p=(f=(u=a[b])==null?void 0:u.getElementsByTagNameNS(wordView.W_NS,"p")[0])==null?void 0:f.getAttributeNS(wordView.W14_NS,"paraId"))!=null?p:null;break}if(!s)return;let l=Array.from(i.getElementsByTagNameNS(sn,"commentEx"));for(let b of l)(b.getAttributeNS(sn,"paraId")===s||b.getAttributeNS(sn,"paraIdParent")===s)&&(Ue(b),pack.markDirty(o));}function rv(e,t){var a,s,l,d,u,f;let n=e.parts.get("word/commentsExtended.xml");if(!(n!=null&&n.xmlDom)){let p=(l=(a=e.parts.get(t))==null?void 0:a.xmlDom)!=null?l:(s=Array.from(e.parts.values()).find(w=>w.xmlDom))==null?void 0:s.xmlDom;if(!p)throw new Error("cannot create commentsExtended.xml without an XML part");let b=(d=p.implementation)==null?void 0:d.createDocument(sn,"w15:commentsEx",null);if(!b)throw new Error("XML implementation cannot create commentsExtended.xml");n=pack.createXmlPart({path:"word/commentsExtended.xml",contentType:Ef,xmlDom:b}),pack.setPart(e,n);}let r=pack.getPart(e,"[Content_Types].xml");if(r!=null&&r.xmlDom){let p=r.xmlDom.getElementsByTagNameNS(Ei,"Override");if(!Array.from(p).some(b=>b.getAttribute("PartName")==="/word/commentsExtended.xml")){let b=r.xmlDom.createElementNS(Ei,"Override");b.setAttribute("PartName","/word/commentsExtended.xml"),b.setAttribute("ContentType",Ef),(u=r.xmlDom.documentElement)==null||u.appendChild(b),pack.markDirty(r);}}let o=e.parts.get(Ni(t)),i=o==null?void 0:o.xmlDom;if(i&&!Array.from(i.getElementsByTagNameNS(Gt,"Relationship")).some(p=>p.getAttribute("Type")===If)){let p=i.getElementsByTagNameNS(Gt,"Relationship"),b=new Set(Array.from(p).map(h=>h.getAttribute("Id")).filter(Boolean)),w=1;for(;b.has(`rId${w}`);)w+=1;let g=i.createElementNS(Gt,"Relationship");g.setAttribute("Id",`rId${w}`),g.setAttribute("Type",If),g.setAttribute("Target","commentsExtended.xml"),(f=i.documentElement)==null||f.appendChild(g),pack.markDirty(o);}return n}function ov(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 a=o.createElementNS(wordView.W_NS,"w:commentRangeEnd");a.setAttributeNS(wordView.W_NS,"w:id",String(r));let s=o.createElementNS(wordView.W_NS,"w:r"),l=o.createElementNS(wordView.W_NS,"w:commentReference");l.setAttributeNS(wordView.W_NS,"w:id",String(r)),s.appendChild(l);let d=new Map;d.set(t,[i]),d.set(n,[a,s]);let u=de(e).filter(b=>!(b.namespaceURI===wordView.W_NS&&b.localName==="pPr")),f=[],p=0;for(let b of u){let w=d.get(p);w&&f.push(...w);let g=jt(b),h=[t,n].filter(S=>S>p&&S<p+g).sort((S,k)=>S-k),y=0;for(let S of [...h,p+g]){let k=ar(b,y,S-p);k&&f.push(k);let I=S,A=d.get(I);A&&f.push(...A),y=S-p;}g===0&&f.push(b),p+=g;}for(let b of [t,n])if(b===p){let w=d.get(b);w&&f.push(...w);}for(let b of u)Ue(b);for(let b of f)e.appendChild(b);}function iv(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),a=[];for(let s=0;s<i.length;s+=1){let l=i[s];(l==null?void 0:l.getAttributeNS(wordView.W_NS,"id"))===String(t)&&a.push(l);}for(let s of a){let l=s.parentNode;o==="commentReference"&&(l==null?void 0:l.nodeType)===1&&l.namespaceURI===wordView.W_NS&&l.localName==="r"?Ue(l):Ue(s);}a.length>0&&pack.markDirty(n);}}}function av(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 sv(e){return e.nodeType===1}var Zt=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",dv(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",cv(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",uv(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",fv(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",mv(e.attrs),0]}}});new prosemirrorState.PluginKey("coco-word-decorations");var Zf=new prosemirrorState.PluginKey("coco-word-structure-normalization");function dv(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=hv(e.format)?e.format:null;(n==null?void 0:n.outlineLevel)!==void 0&&(t["data-outline-level"]=String(n.outlineLevel));let r=gv(n);return r.length>0&&(t.style=r),t}function cv(e){let t={};return typeof e.tableId=="string"&&e.tableId.length>0&&(t["data-table-id"]=e.tableId),t}function uv(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: ${Gn(e.width)}`),pv(e.shading)){let r=Qs(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 fv(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 pv(e){return e!==null&&typeof e=="object"}function mv(e){let t=[],n=typeof e.color=="string"?Qs(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 hv(e){return e!==null&&typeof e=="object"}function gv(e){var o,i,a,s,l,d,u,f,p;if(!e)return "";let t=[];e.alignment&&t.push(`text-align: ${bv(e.alignment)}`),((o=e.indent)==null?void 0:o.left)!==void 0&&t.push(`margin-left: ${Gn(e.indent.left)}`),((i=e.indent)==null?void 0:i.right)!==void 0&&t.push(`margin-right: ${Gn(e.indent.right)}`),((a=e.indent)==null?void 0:a.firstLine)!==void 0&&t.push(`text-indent: ${Gn(e.indent.firstLine)}`),((s=e.spacing)==null?void 0:s.before)!==void 0&&t.push(`margin-top: ${Gn(e.spacing.before)}`),((l=e.spacing)==null?void 0:l.after)!==void 0&&t.push(`margin-bottom: ${Gn(e.spacing.after)}`);let n=xv((d=e.spacing)==null?void 0:d.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=wv(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 bv(e){return e==="both"||e==="distribute"?"justify":e}function wv(e){var o;if(!e||e.val==="none"||e.val==="nil")return null;let t=(o=Qs(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 xv(e,t){return e===void 0?null:t==="exact"||t==="atLeast"?Gn(e):String(e/240)}function Gn(e){return `${e/20}pt`}function Qs(e){return !e||e==="auto"?null:/^[0-9a-f]{6}$/i.test(e)?`#${e}`:null}var io=new prosemirrorState.PluginKey("coco-word-editing"),Sv=0;function RI(e={}){return new prosemirrorState.Plugin({key:io,appendTransaction(t,n,r){if(!t.some(a=>a.docChanged)||t.every(a=>a.getMeta(Zf)))return null;let o=Cv(n.doc,r.doc),i=o.length>0?o:Tv(n.doc,r.doc);return i.length>0?rp(r.tr,i):null},state:{init:()=>({changes:[]}),apply(t,n){var i,a;let r=t.getMeta(io);if(!((i=r==null?void 0:r.changes)!=null&&i.length))return n;let o={changes:[...n.changes,...r.changes]};return (a=e.onChangeSet)==null||a.call(e,o),o}}})}function MI(e){var t;return (t=io.getState(e))!=null?t:{changes:[]}}function AI(e){var s,l;let{from:t,to:n,empty:r}=e.selection,o=e.selection.$from,i=Lv(o,"table_cell"),a=i===null?null:{depth:i,colspan:Number((s=o.node(i).attrs.colspan)!=null?s: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,`
20
+ `),paragraphs:nl(e,t,n),tableCell:a}}function LI(e,t,n){let r=Zt.marks.strong;return tl(e,t,n,r,{},"strong")}function WI(e){return (t,n,r)=>!Number.isFinite(e)||e<=0?false:tl(t,n,r,Zt.marks.textStyle,{fontSize:e},"textStyle")}function BI(e){return (t,n,r)=>{let o=Av(e);return o?tl(t,n,r,Zt.marks.textStyle,{color:o},"textStyle"):false}}function DI(e){return (t,n)=>{let r=nl(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,a)=>{if(i.type!==Zt.nodes.paragraph)return true;let s=Mv(i.attrs.format,{alignment:e});return o=o.setNodeMarkup(a,void 0,O(v({},i.attrs),{format:s})),false}),o=np(o,{kind:"paragraph",from:t.selection.from,to:t.selection.to,paragraphs:r,target:Ti(r),status:"captured",attr:"alignment",value:e}),n(o.scrollIntoView()),true}}function tl(e,t,n,r,o,i){let{from:a,to:s,empty:l}=e.selection;if(l)return false;let d=nl(e,a,s);if(d.length===0)return false;let u=i==="strong"&&kv(e.doc,a,s,r);if(!t)return true;let f=e.tr;return u?f=f.removeMark(a,s,r):f=f.addMark(a,s,r.create(o)),f=np(f,{kind:"mark",from:a,to:s,paragraphs:d,target:Ti(d),status:"captured",mark:i,value:i==="strong"?!u:o}),t(f.scrollIntoView()),n==null||n.focus(),true}function nl(e,t,n){let r=[],o=Math.max(n,t+1);return e.doc.nodesBetween(t,o,(i,a)=>{if(i.type!==Zt.nodes.paragraph)return true;let s=a+1,l=s+i.content.size;return r.push({paraId:typeof i.attrs.paraId=="string"?i.attrs.paraId:"",from:Math.max(t,s)-s,to:Math.min(n,l)-s,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 Ti(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 kv(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 rp(e,[t])}function rp(e,t){var o,i;let n=(o=e.getMeta(io))!=null?o:{},r=(i=n.changes)!=null?i:[];return e.setMeta(io,O(v({},n),{changes:[...r,...t.map(a=>O(v({},a),{id:`word-edit:${++Sv}`,createdAt:Date.now()}))]}))}function Cv(e,t){let n=Qf(e),r=Qf(t),o=Ev(n,r);if(o)return [o];let i=Iv(n,r);if(i)return [i];let a=Nv(n,r);return a?[a]:[]}function Ev(e,t){if(t.length!==e.length+1)return null;for(let n=0;n<e.length;n+=1){if(!Pi(e.slice(0,n),t.slice(0,n))||!Pi(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:rl([o,i]),target:ol(r.block),status:"captured",blocks:[o.block,i.block],deletedBlocks:[r.block],value:{before:r.block,after:[o.block,i.block]}}}return null}function Iv(e,t){if(e.length!==t.length+1)return null;for(let n=0;n<t.length;n+=1){if(!Pi(e.slice(0,n),t.slice(0,n))||!Pi(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:rl([i]),target:ol(i.block),status:"captured",blocks:[i.block],deletedBlocks:[r.block,o.block],value:{before:[r.block,o.block],after:i.block}}}return null}function Nv(e,t){var f,p,b,w,g;let n=0,r=Math.min(e.length,t.length);for(;n<r&&el(e[n],t[n]);)n+=1;let o=0,i=Math.min(e.length-n,t.length-n);for(;o<i&&el(e[e.length-1-o],t[t.length-1-o]);)o+=1;let a=e.slice(n,e.length-o),s=t.slice(n,t.length-o);if(a.length===0&&s.length===0)return null;let l=(f=s[0])!=null?f:a[0],d=(b=(p=s[s.length-1])!=null?p:a[a.length-1])!=null?b:l;return {kind:"block",blockOp:s.length>0&&a.length>0?"replace":s.length>0?"insert":"delete",from:(w=l==null?void 0:l.pos)!=null?w:0,to:d?d.pos+d.size:(g=l==null?void 0:l.pos)!=null?g:0,paragraphs:rl(s.length>0?s:a),target:l?ol(l.block):{story:"body"},status:"captured",blocks:s.map(h=>h.block),deletedBlocks:a.map(h=>h.block),value:{before:a.map(h=>h.block),after:s.map(h=>h.block)}}}function Tv(e,t){let n=Jf(e),r=Jf(t),o=new Map(n.map(a=>[a.paraId,a])),i=[];for(let a of r){if(!a.paraId)continue;let s=o.get(a.paraId);if(!s||ip(s.content,a.content))continue;let l=Rv(s.content,a.content);if(!l)continue;let d=a.pos+1+l.from,u=a.pos+1+l.toAfter,f={paraId:a.paraId,from:l.from,to:l.toAfter,text:a.text,styleId:a.styleId,story:a.story};if(ep(l.insertedContent)&&ep(l.deletedContent)){i.push({kind:"text",from:d,to:u,paragraphs:[f],target:Ti([f]),status:"captured",textOp:l.operation,text:tp(l.insertedContent),deletedText:tp(l.deletedContent),value:{operation:l.operation,before:s.text,after:a.text}});continue}i.push({kind:"content",from:d,to:u,paragraphs:[f],target:Ti([f]),status:"captured",contentOp:l.operation,content:oo(l.insertedContent),deletedContent:oo(l.deletedContent),value:{operation:l.operation,before:oo(s.content.map(p=>p.content)),after:oo(a.content.map(p=>p.content))}});}return i}function Jf(e){let t=[];return e.descendants((n,r)=>n.type!==Zt.nodes.paragraph?true:(t.push({paraId:typeof n.attrs.paraId=="string"?n.attrs.paraId:"",pos:r,text:n.textContent,content:op(n),styleId:typeof n.attrs.styleId=="string"?n.attrs.styleId:null,story:typeof n.attrs.story=="string"?n.attrs.story:"body"}),false)),t}function Qf(e){let t=[];return e.forEach((n,r,o)=>{if(n.type===Zt.nodes.paragraph){let i=typeof n.attrs.paraId=="string"?n.attrs.paraId:"",a=typeof n.attrs.story=="string"?n.attrs.story:"body",s={kind:"paragraph",paraId:i,story:a,styleId:typeof n.attrs.styleId=="string"?n.attrs.styleId:null,text:n.textContent,content:oo(op(n).map(l=>l.content))};t.push({key:`paragraph:${i||o}`,pos:r,size:n.nodeSize,block:s});return}if(n.type===Zt.nodes.table){let i=typeof n.attrs.tableId=="string"?n.attrs.tableId:"",a={kind:"table",tableId:i,text:n.textContent};t.push({key:`table:${i||o}`,pos:r,size:n.nodeSize,block:a});}}),t}function Pi(e,t){return e.length===t.length&&e.every((n,r)=>el(n,t[r]))}function el(e,t){return e.key===t.key}function rl(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 ol(e){return e.kind==="table"?v({story:"body"},e.tableId?{tableId:e.tableId}:{}):v({story:e.story},e.paraId?{paraId:e.paraId}:{})}function op(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===Zt.nodes.image){let i=Pv(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 Pv(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 Rv(e,t){var f,p,b,w;if(ip(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&&((b=e[e.length-1-o])==null?void 0:b.key)===((w=t[t.length-1-o])==null?void 0:w.key);)o+=1;let a=e.length-o,s=t.length-o,l=t.slice(n,s).map(g=>g.content),d=e.slice(n,a).map(g=>g.content);return {operation:l.length>0&&d.length>0?"replace":l.length>0?"insert":"delete",from:n,toBefore:a,toAfter:s,insertedContent:l,deletedContent:d}}function ip(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 ep(e){return e.every(t=>t.kind==="text")}function tp(e){return e.map(t=>t.kind==="text"?t.text:"").join("")}function oo(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 Mv(e,t){return v(v({},e!==null&&typeof e=="object"?e:{}),t)}function Av(e){let t=e.trim().replace(/^#/,"");return /^[0-9a-f]{6}$/i.test(t)?t.toUpperCase():null}function Lv(e,t){for(let n=e.depth;n>0;n-=1)if(e.node(n).type.name===t)return n;return null}var ap=`.coco-word-editor {
21
21
  background: #f4f5f7;
22
22
  color: #202124;
23
23
  font-family:
@@ -687,6 +687,16 @@ coco-word-native-page > coco-word-native-story[data-story-kind="header"] {
687
687
  top: var(--coco-word-header-distance, 0);
688
688
  }
689
689
 
690
+ /* With a nonnegative top margin Word moves the body down if the header outgrows
691
+ its reserved space. Let the same flex layout that pagination measures do this. */
692
+ coco-word-native-page:not([data-fixed-top-margin]) > coco-word-native-story[data-story-kind="header"] {
693
+ position: relative;
694
+ inset: auto;
695
+ flex: none;
696
+ margin-top: calc(var(--coco-word-header-distance) - var(--coco-word-page-margin-top));
697
+ min-height: max(0px, calc(var(--coco-word-page-margin-top) - var(--coco-word-header-distance)));
698
+ }
699
+
690
700
  coco-word-native-page > coco-word-native-story[data-story-kind="footer"] {
691
701
  bottom: var(--coco-word-footer-distance, 0);
692
702
  }
@@ -748,7 +758,7 @@ coco-word-native-p.has-tab-stops {
748
758
  display: grid;
749
759
  grid-template-columns: minmax(0, 1fr) auto;
750
760
  align-items: baseline;
751
- width: 100%;
761
+ width: min(100%, var(--coco-word-tab-stop, 100%));
752
762
  column-gap: 12pt;
753
763
  }
754
764
 
@@ -756,7 +766,8 @@ coco-word-native-p.has-tab-stops {
756
766
  .coco-word-tab-row.has-leader-hyphen,
757
767
  .coco-word-tab-row.has-leader-underscore,
758
768
  .coco-word-tab-row.has-leader-heavy,
759
- .coco-word-tab-row.has-leader-middleDot {
769
+ .coco-word-tab-row.has-leader-middleDot,
770
+ .coco-word-tab-row.has-underlined-tab {
760
771
  column-gap: 4pt;
761
772
  line-height: 2;
762
773
  }
@@ -773,7 +784,8 @@ coco-word-native-p.has-tab-stops {
773
784
  text-align: left;
774
785
  }
775
786
 
776
- .coco-word-tab-row.is-right-tab[class*="has-leader-"] .coco-word-tab-segment.is-segment-0 {
787
+ .coco-word-tab-row.is-right-tab[class*="has-leader-"] .coco-word-tab-segment.is-segment-0,
788
+ .coco-word-tab-row.is-right-tab.has-underlined-tab .coco-word-tab-segment.is-segment-0 {
777
789
  display: flex;
778
790
  align-items: baseline;
779
791
  white-space: nowrap;
@@ -783,9 +795,9 @@ coco-word-native-p.has-tab-stops {
783
795
  content: "";
784
796
  flex: 1 1 auto;
785
797
  min-width: 12pt;
786
- margin: 0 3pt;
798
+ margin: 0;
787
799
  border-bottom: 1px dotted currentColor;
788
- transform: translateY(-0.25em);
800
+ transform: translateY(0.08em);
789
801
  }
790
802
 
791
803
  .coco-word-tab-row.is-right-tab.has-leader-hyphen .coco-word-tab-segment.is-segment-0::after {
@@ -801,6 +813,14 @@ coco-word-native-p.has-tab-stops {
801
813
  border-bottom-width: 2px;
802
814
  }
803
815
 
816
+ .coco-word-tab-row.is-right-tab.has-underlined-tab .coco-word-underlined-tab-run {
817
+ flex: 1 1 auto;
818
+ min-width: 12pt;
819
+ box-sizing: border-box;
820
+ border-bottom: 1px solid currentColor;
821
+ text-decoration-line: none !important;
822
+ }
823
+
804
824
  .coco-word-tab-segment.is-segment-1 {
805
825
  text-align: center;
806
826
  }
@@ -815,6 +835,12 @@ coco-word-native-p.has-tab-stops {
815
835
  display: none;
816
836
  }
817
837
 
838
+ /* In a monospace face the ASCII space and '0' both advance by exactly 1ch. */
839
+ .coco-word-songti-spaces {
840
+ font-family: monospace;
841
+ word-spacing: calc(0.5em - 1ch);
842
+ }
843
+
818
844
  coco-word-native-p[data-numbering="true"] {
819
845
  margin-left: 2.8em;
820
846
  padding-right: 0.5em;
@@ -845,20 +871,37 @@ coco-word-native-table {
845
871
  margin: 0;
846
872
  max-width: 100%;
847
873
  overflow: auto;
848
- scrollbar-gutter: stable;
849
874
  --coco-word-doc-grid-line-height: 1em;
850
875
  white-space: pre-wrap;
851
876
  }
852
877
 
853
878
  coco-word-native-table table {
854
879
  box-sizing: border-box;
855
- min-width: 100%;
880
+ width: 100%;
856
881
  max-width: none;
857
882
  margin: 0;
858
883
  border-collapse: collapse;
859
884
  table-layout: fixed;
860
885
  }
861
886
 
887
+ coco-word-native-table table[data-layout="autofit"] {
888
+ table-layout: auto;
889
+ }
890
+
891
+ coco-word-native-table table[data-layout="autofit"] > tbody > tr > td {
892
+ min-width: 0;
893
+ }
894
+
895
+ /* Keep whole words in the intrinsic width used by AutoFit. */
896
+ coco-word-native-table table[data-layout="autofit"] > tbody > tr > td > coco-word-native-p {
897
+ word-break: normal;
898
+ overflow-wrap: break-word;
899
+ }
900
+
901
+ coco-word-native-table table[data-layout="autofit"] > tbody > tr > td > coco-word-native-p.is-single-cjk-word {
902
+ word-break: keep-all;
903
+ }
904
+
862
905
  coco-word-native-table tbody {
863
906
  display: table-row-group;
864
907
  }
@@ -880,9 +923,20 @@ coco-word-native-table td {
880
923
  vertical-align: top;
881
924
  }
882
925
 
883
- /* Editor-only gridlines keep borderless OOXML tables legible without changing their document formatting. */
884
- coco-word-native-table.shows-auxiliary-gridlines > table > tbody > tr > td {
885
- border: 1px dashed rgb(148 163 184 / 72%) !important;
926
+ /* Guides sit inside the cell so they don't affect text wrapping or pagination. */
927
+ @media screen {
928
+ coco-word-native-table td.has-editing-gridlines {
929
+ position: relative;
930
+ }
931
+
932
+ coco-word-native-table td.has-editing-gridlines::before {
933
+ content: "";
934
+ position: absolute;
935
+ inset: 0;
936
+ pointer-events: none;
937
+ border: dashed #bfc3c8;
938
+ border-width: var(--coco-word-grid-widths);
939
+ }
886
940
  }
887
941
 
888
942
  coco-word-native-table td coco-word-native-p {
@@ -1530,31 +1584,31 @@ coco-word-native-table.coco-word-revision-delete {
1530
1584
  .coco-word-dialog-button:hover {
1531
1585
  filter: brightness(0.96);
1532
1586
  }
1533
- `;function sp(e,t){var a,s,l,d,u,p,f,b,w;let n=Mv(e,t),r=cp(e,t),o=lp(e,t),i=io(e,t);return {selectionKind:(a=t==null?void 0:t.kind)!=null?a:null,trackRevisions:false,bold:(s=Ye(n.map(g=>{var h;return (h=g.bold)!=null?h:false}),false))!=null?s:false,italic:(l=Ye(n.map(g=>{var h;return (h=g.italic)!=null?h:false}),false))!=null?l:false,underline:(d=Ye(n.map(g=>{var h;return (h=g.underline)!=null?h:false}),false))!=null?d:false,strike:(u=Ye(n.map(g=>{var h;return (h=g.strike)!=null?h:false}),false))!=null?u:false,fontFamily:Ye(n.map(g=>{var h;return (h=g.fontFamily)!=null?h:null}),null),fontSize:Ye(n.map(g=>{var h;return (h=g.fontSize)!=null?h:null}),null),textColor:Ye(n.map(g=>ao(g.color)),null),highlightColor:Ye(n.map(g=>Bv(g.highlight)),null),hyperlink:dp(e,t),paragraphAlignment:Ye(r.map(g=>{var h;return ap((h=g.format)==null?void 0:h.alignment)}),null),leftIndent:Ye(r.map(g=>{var h,y,S;return (S=(y=(h=g.format)==null?void 0:h.indent)==null?void 0:y.left)!=null?S:0}),0),rightIndent:Ye(r.map(g=>{var h,y,S;return (S=(y=(h=g.format)==null?void 0:h.indent)==null?void 0:y.right)!=null?S:0}),0),firstLineIndent:Ye(r.map(g=>{var h,y,S;return (S=(y=(h=g.format)==null?void 0:h.indent)==null?void 0:y.firstLine)!=null?S:0}),0),spacingBefore:Ye(r.map(g=>{var h,y,S;return (S=(y=(h=g.format)==null?void 0:h.spacing)==null?void 0:y.before)!=null?S:0}),0),spacingAfter:Ye(r.map(g=>{var h,y,S;return (S=(y=(h=g.format)==null?void 0:h.spacing)==null?void 0:y.after)!=null?S:0}),0),lineSpacing:up(r.map(g=>{var y,S,E,N,A;let h=(S=(y=g.format)==null?void 0:y.spacing)==null?void 0:S.line;return h===void 0?null:{line:h,lineRule:(A=(N=(E=g.format)==null?void 0:E.spacing)==null?void 0:N.lineRule)!=null?A:"auto"}})),listType:Ye(r.map(g=>{var h;return (h=g.format)!=null&&h.hasNumbering?hn(g.format.numbering):null}),null),listLevel:Ye(r.map(g=>{var h,y,S;return (h=g.format)!=null&&h.hasNumbering?(S=(y=g.format.numbering)==null?void 0:y.ilvl)!=null?S:0:null}),null),image:o&&(t==null?void 0:t.kind)==="object"?{objectId:o.drawingId,width:(p=o.width)!=null?p:null,height:(f=o.height)!=null?f:null,alignment:ap((w=(b=r[0])==null?void 0:b.format)==null?void 0:w.alignment)}:null,table:i}}function Wt(e,t,n){var r,o,i,a,s,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=ye(e,t.paraId))==null?void 0:r.container)===e.blocks;if(n.kind==="delete-table"){let d=io(e,t);return !!d&&((o=Oe(e,d.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&&!!lp(e,t);if(n.kind==="insert-table-row"||n.kind==="delete-table-row"||n.kind==="insert-table-column"||n.kind==="delete-table-column"){let d=io(e,t);return d!=null&&d.structuralEditingSupported?n.kind==="delete-table-row"?d.rowCount>1:n.kind==="delete-table-column"?d.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 io(e,t)!==null;if(n.kind==="merge-table-cells"||n.kind==="split-table-cell"){if(t.kind!=="table-cell-range")return false;let d=Oe(e,t.tableId);if(!d)return false;let u=tt(d.table,t);if(n.kind==="merge-table-cells")return Hr(d.table)?t.anchor.rowIndex===t.focus.rowIndex&&u.length>=2&&u.every(b=>b.cell.gridSpan===1&&b.cell.vMerge==null):false;let p=u.length===1?u[0].cell:null;return !!p&&(p.gridSpan>1&&p.vMerge==null&&((i=p.rowSpan)!=null?i:1)===1||p.vMerge==="restart"&&((a=p.rowSpan)!=null?a:1)>1)}return n.kind==="clear-table-cells"?t.kind==="table-cell-range"&&io(e,t)!==null:n.kind==="set-hyperlink"?t.kind==="text-range"&&!!((s=n.hyperlink.target)!=null&&s.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"&&!!Z(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&&!!Z(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"&&Ti(e,t).some(d=>d.to>d.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"?cp(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 io(e,t){var o,i,a,s;if(!t)return null;if(t.kind==="table-cell-range"){let l=Oe(e,t.tableId);if(!l)return null;let d=tt(l.table,t);if(d.length===0)return null;let u=Math.min(t.anchor.rowIndex,t.focus.rowIndex),p=Math.max(t.anchor.rowIndex,t.focus.rowIndex),f=Math.min(t.anchor.columnIndex,t.focus.columnIndex),b=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(w=>w.cells.reduce((g,h)=>g+Math.max(1,h.gridSpan),0))),range:{startRow:u,endRow:p,startColumn:f,endColumn:b,cellCount:d.length},structuralEditingSupported:Hr(l.table),backgroundColor:Ye(d.map(({cell:w})=>{var g;return ao((g=w.shading)==null?void 0:g.fill)}),null),verticalAlignment:Ye(d.map(({cell:w})=>{var g;return (g=w.verticalAlignment)!=null?g:null}),null),borderColor:Ye(d.map(({cell:w})=>op(w.borders)),null),bordersVisible:Ye(d.map(({cell:w})=>ip(w.borders)),false)}}let n=t.kind==="text-range"?t.anchor.paraId:t.paraId,r=rn(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:Hr(r.table),backgroundColor:ao((a=r.cell.shading)==null?void 0:a.fill),verticalAlignment:(s=r.cell.verticalAlignment)!=null?s:null,borderColor:op(r.cell.borders),bordersVisible:ip(r.cell.borders)}:null}function op(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 ao(t==null?void 0:t.color)}function ip(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 lp(e,t){var r;if((t==null?void 0:t.kind)!=="object"||t.objectKind!=="image")return null;let n=Z(e,t.paraId);return (r=n==null?void 0:n.content.find(o=>o.kind==="image"&&o.drawingId===t.objectId))!=null?r:null}function Mv(e,t){if(!t||t.kind==="object"||t.kind==="table-cell-range")return [];if(t.kind==="caret"){let n=Z(e,t.paraId);if(!n)return [];let r=Lv(e,n,t.offset);return r?[r]:[]}return Ti(e,t).flatMap(n=>Av(e,n))}function dp(e,t){var r,o,i,a,s;if(!t||t.kind==="object"||t.kind==="table-cell-range")return null;if(t.kind==="caret"){let l=Z(e,t.paraId);if(!l)return null;let d=0,u=null;for(let p of l.content){let f=Ni(p);if(p.kind==="text"){if(t.offset>d&&t.offset<=d+f)return (r=p.hyperlink)!=null?r:null;if(t.offset===d)return (u==null?void 0:u.kind)==="text"?(i=(o=u.hyperlink)!=null?o:p.hyperlink)!=null?i:null:(a=p.hyperlink)!=null?a:null;u=p;}d+=f;}return (u==null?void 0:u.kind)==="text"&&(s=u.hyperlink)!=null?s:null}let n=Ti(e,t).flatMap(l=>{var f;let d=Z(e,l.paraId);if(!d)return [];let u=[],p=0;for(let b of d.content){let w=Ni(b);b.kind==="text"&&p+w>l.from&&p<l.to&&u.push((f=b.hyperlink)!=null?f:null),p+=w;}return u});return up(n)}function Av(e,t){let n=Z(e,t.paraId);if(!n)return [];let r=[],o=0;for(let i of n.content){let a=Ni(i);i.kind==="text"&&o+a>t.from&&o<t.to&&r.push(il(e,n,i.format)),o+=a;}return r}function Lv(e,t,n){let r=0,o=null;for(let i of t.content){let a=Ni(i);if(i.kind==="text"){let s=il(e,t,i.format);if(n>r&&n<=r+a)return s;if(n===r)return o!=null?o:s;o=s;}r+=a;}return o!=null?o:il(e,t,null)}function il(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 cp(e,t){var n;if(!t)return [];if(t.kind==="table-cell-range"){let r=(n=Oe(e,t.tableId))==null?void 0:n.table;return r?tt(r,t).flatMap(({cell:o})=>o.paragraphs):[]}if(t.kind==="caret"||t.kind==="object"){let r=Z(e,t.paraId);return r?[r]:[]}return Ti(e,t).map(r=>Z(e,r.paraId)).filter(r=>r!==null)}function Ti(e,t){let n=Wv(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=ye(e,n.anchor.paraId),o=ye(e,n.focus.paraId);if(!r||!o||r.container!==o.container)return [];let i=[];for(let a=r.index;a<=o.index;a+=1){let s=r.container[a];if((s==null?void 0:s.kind)!=="paragraph")return [];i.push({paraId:s.paraId,from:a===r.index?n.anchor.offset:0,to:a===o.index?n.focus.offset:Ne(s).length});}return i}function Wv(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=ye(e,t.anchor.paraId),r=ye(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 Ni(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 Ye(e,t){return e.length===0?t:e.every(n=>n===e[0])?e[0]:"mixed"}function up(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 ao(e){if(!e||e.toLowerCase()==="auto")return null;let t=e.replace(/^#/,"").toUpperCase();return /^[0-9A-F]{6}$/.test(t)?`#${t}`:e}function Bv(e){var t;return !e||e.toLowerCase()==="none"?null:(t=ao(e))!=null?t:e}function ap(e){return e==="center"||e==="right"||e==="both"?e:e==="distribute"?"both":"left"}function fp(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 so=new WeakMap,al="application/x-coco-word-table-cells+json",lo="application/x-coco-word-image",bp="coco-image:",co=new Map,sl=0,Dv=0,ll=0,dl=0;function eN(e,t,n={}){var Ad,Ld,Wd;Tu();let r=e,o=null;if(n.styleIsolation!=="none"){r.replaceChildren(),o=(Ad=r.shadowRoot)!=null?Ad:r.attachShadow({mode:"open"}),o.replaceChildren();let c=r.ownerDocument.createElement("style");c.textContent=`
1587
+ `;function cp(e,t){var a,s,l,d,u,f,p,b,w;let n=Wv(e,t),r=pp(e,t),o=up(e,t),i=ao(e,t);return {selectionKind:(a=t==null?void 0:t.kind)!=null?a:null,trackRevisions:false,bold:(s=Ye(n.map(g=>{var h;return (h=g.bold)!=null?h:false}),false))!=null?s:false,italic:(l=Ye(n.map(g=>{var h;return (h=g.italic)!=null?h:false}),false))!=null?l:false,underline:(d=Ye(n.map(g=>{var h;return (h=g.underline)!=null?h:false}),false))!=null?d:false,strike:(u=Ye(n.map(g=>{var h;return (h=g.strike)!=null?h:false}),false))!=null?u:false,fontFamily:Ye(n.map(g=>{var h;return (h=g.fontFamily)!=null?h:null}),null),fontSize:Ye(n.map(g=>{var h;return (h=g.fontSize)!=null?h:null}),null),textColor:Ye(n.map(g=>so(g.color)),null),highlightColor:Ye(n.map(g=>Hv(g.highlight)),null),hyperlink:fp(e,t),paragraphAlignment:Ye(r.map(g=>{var h;return dp((h=g.format)==null?void 0:h.alignment)}),null),leftIndent:Ye(r.map(g=>{var h,y,S;return (S=(y=(h=g.format)==null?void 0:h.indent)==null?void 0:y.left)!=null?S:0}),0),rightIndent:Ye(r.map(g=>{var h,y,S;return (S=(y=(h=g.format)==null?void 0:h.indent)==null?void 0:y.right)!=null?S:0}),0),firstLineIndent:Ye(r.map(g=>{var h,y,S;return (S=(y=(h=g.format)==null?void 0:h.indent)==null?void 0:y.firstLine)!=null?S:0}),0),spacingBefore:Ye(r.map(g=>{var h,y,S;return (S=(y=(h=g.format)==null?void 0:h.spacing)==null?void 0:y.before)!=null?S:0}),0),spacingAfter:Ye(r.map(g=>{var h,y,S;return (S=(y=(h=g.format)==null?void 0:h.spacing)==null?void 0:y.after)!=null?S:0}),0),lineSpacing:mp(r.map(g=>{var y,S,k,I,A;let h=(S=(y=g.format)==null?void 0:y.spacing)==null?void 0:S.line;return h===void 0?null:{line:h,lineRule:(A=(I=(k=g.format)==null?void 0:k.spacing)==null?void 0:I.lineRule)!=null?A:"auto"}})),listType:Ye(r.map(g=>{var h;return (h=g.format)!=null&&h.hasNumbering?hn(g.format.numbering):null}),null),listLevel:Ye(r.map(g=>{var h,y,S;return (h=g.format)!=null&&h.hasNumbering?(S=(y=g.format.numbering)==null?void 0:y.ilvl)!=null?S: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:dp((w=(b=r[0])==null?void 0:b.format)==null?void 0:w.alignment)}:null,table:i}}function Wt(e,t,n){var r,o,i,a,s,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=ve(e,t.paraId))==null?void 0:r.container)===e.blocks;if(n.kind==="delete-table"){let d=ao(e,t);return !!d&&((o=Oe(e,d.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&&!!up(e,t);if(n.kind==="insert-table-row"||n.kind==="delete-table-row"||n.kind==="insert-table-column"||n.kind==="delete-table-column"){let d=ao(e,t);return d!=null&&d.structuralEditingSupported?n.kind==="delete-table-row"?d.rowCount>1:n.kind==="delete-table-column"?d.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 ao(e,t)!==null;if(n.kind==="merge-table-cells"||n.kind==="split-table-cell"){if(t.kind!=="table-cell-range")return false;let d=Oe(e,t.tableId);if(!d)return false;let u=tt(d.table,t);if(n.kind==="merge-table-cells")return $r(d.table)?t.anchor.rowIndex===t.focus.rowIndex&&u.length>=2&&u.every(b=>b.cell.gridSpan===1&&b.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"&&((a=f.rowSpan)!=null?a:1)>1)}return n.kind==="clear-table-cells"?t.kind==="table-cell-range"&&ao(e,t)!==null:n.kind==="set-hyperlink"?t.kind==="text-range"&&!!((s=n.hyperlink.target)!=null&&s.trim()||(l=n.hyperlink.anchor)!=null&&l.trim()):n.kind==="remove-hyperlink"?t.kind==="text-range"&&fp(e,t)!==null:n.kind==="insert-text"||n.kind==="split-paragraph"||n.kind==="insert-page-break"?t.kind==="caret"&&!!Z(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&&!!Z(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"&&Mi(e,t).some(d=>d.to>d.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"?pp(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 ao(e,t){var o,i,a,s;if(!t)return null;if(t.kind==="table-cell-range"){let l=Oe(e,t.tableId);if(!l)return null;let d=tt(l.table,t);if(d.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),b=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(w=>w.cells.reduce((g,h)=>g+Math.max(1,h.gridSpan),0))),range:{startRow:u,endRow:f,startColumn:p,endColumn:b,cellCount:d.length},structuralEditingSupported:$r(l.table),backgroundColor:Ye(d.map(({cell:w})=>{var g;return so((g=w.shading)==null?void 0:g.fill)}),null),verticalAlignment:Ye(d.map(({cell:w})=>{var g;return (g=w.verticalAlignment)!=null?g:null}),null),borderColor:Ye(d.map(({cell:w})=>sp(w.borders)),null),bordersVisible:Ye(d.map(({cell:w})=>lp(w.borders)),false)}}let n=t.kind==="text-range"?t.anchor.paraId:t.paraId,r=rn(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:$r(r.table),backgroundColor:so((a=r.cell.shading)==null?void 0:a.fill),verticalAlignment:(s=r.cell.verticalAlignment)!=null?s:null,borderColor:sp(r.cell.borders),bordersVisible:lp(r.cell.borders)}:null}function sp(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 so(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 up(e,t){var r;if((t==null?void 0:t.kind)!=="object"||t.objectKind!=="image")return null;let n=Z(e,t.paraId);return (r=n==null?void 0:n.content.find(o=>o.kind==="image"&&o.drawingId===t.objectId))!=null?r:null}function Wv(e,t){if(!t||t.kind==="object"||t.kind==="table-cell-range")return [];if(t.kind==="caret"){let n=Z(e,t.paraId);if(!n)return [];let r=Dv(e,n,t.offset);return r?[r]:[]}return Mi(e,t).flatMap(n=>Bv(e,n))}function fp(e,t){var r,o,i,a,s;if(!t||t.kind==="object"||t.kind==="table-cell-range")return null;if(t.kind==="caret"){let l=Z(e,t.paraId);if(!l)return null;let d=0,u=null;for(let f of l.content){let p=Ri(f);if(f.kind==="text"){if(t.offset>d&&t.offset<=d+p)return (r=f.hyperlink)!=null?r:null;if(t.offset===d)return (u==null?void 0:u.kind)==="text"?(i=(o=u.hyperlink)!=null?o:f.hyperlink)!=null?i:null:(a=f.hyperlink)!=null?a:null;u=f;}d+=p;}return (u==null?void 0:u.kind)==="text"&&(s=u.hyperlink)!=null?s:null}let n=Mi(e,t).flatMap(l=>{var p;let d=Z(e,l.paraId);if(!d)return [];let u=[],f=0;for(let b of d.content){let w=Ri(b);b.kind==="text"&&f+w>l.from&&f<l.to&&u.push((p=b.hyperlink)!=null?p:null),f+=w;}return u});return mp(n)}function Bv(e,t){let n=Z(e,t.paraId);if(!n)return [];let r=[],o=0;for(let i of n.content){let a=Ri(i);i.kind==="text"&&o+a>t.from&&o<t.to&&r.push(il(e,n,i.format)),o+=a;}return r}function Dv(e,t,n){let r=0,o=null;for(let i of t.content){let a=Ri(i);if(i.kind==="text"){let s=il(e,t,i.format);if(n>r&&n<=r+a)return s;if(n===r)return o!=null?o:s;o=s;}r+=a;}return o!=null?o:il(e,t,null)}function il(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 pp(e,t){var n;if(!t)return [];if(t.kind==="table-cell-range"){let r=(n=Oe(e,t.tableId))==null?void 0:n.table;return r?tt(r,t).flatMap(({cell:o})=>o.paragraphs):[]}if(t.kind==="caret"||t.kind==="object"){let r=Z(e,t.paraId);return r?[r]:[]}return Mi(e,t).map(r=>Z(e,r.paraId)).filter(r=>r!==null)}function Mi(e,t){let n=Fv(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=ve(e,n.anchor.paraId),o=ve(e,n.focus.paraId);if(!r||!o||r.container!==o.container)return [];let i=[];for(let a=r.index;a<=o.index;a+=1){let s=r.container[a];if((s==null?void 0:s.kind)!=="paragraph")return [];i.push({paraId:s.paraId,from:a===r.index?n.anchor.offset:0,to:a===o.index?n.focus.offset:Te(s).length});}return i}function Fv(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=ve(e,t.anchor.paraId),r=ve(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 Ri(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 Ye(e,t){return e.length===0?t:e.every(n=>n===e[0])?e[0]:"mixed"}function mp(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 so(e){if(!e||e.toLowerCase()==="auto")return null;let t=e.replace(/^#/,"").toUpperCase();return /^[0-9A-F]{6}$/.test(t)?`#${t}`:e}function Hv(e){var t;return !e||e.toLowerCase()==="none"?null:(t=so(e))!=null?t:e}function dp(e){return e==="center"||e==="right"||e==="both"?e:e==="distribute"?"both":"left"}function hp(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 lo=new WeakMap,al="application/x-coco-word-table-cells+json",co="application/x-coco-word-image",yp="coco-image:",uo=new Map,sl=0,Ov=0,ll=0,dl=0;function rN(e,t,n={}){var Ld,Wd,Bd;Ru();let r=e,o=null;if(n.styleIsolation!=="none"){r.replaceChildren(),o=(Ld=r.shadowRoot)!=null?Ld:r.attachShadow({mode:"open"}),o.replaceChildren();let c=r.ownerDocument.createElement("style");c.textContent=`
1534
1588
  :host { display: block; position: relative; min-width: 0; min-height: 0; }
1535
1589
  *, *::before, *::after { box-sizing: border-box; }
1536
1590
  button, input, textarea, select { font: inherit; line-height: normal; }
1537
1591
  button { margin: 0; }
1538
- ${(Ld=n.styleText)!=null?Ld:rp}`,o.appendChild(c);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 a=t,s=as(a),l=false,d=n.readOnly===true,u=[],p=[],f=0,b=new Set(_e(s).map(c=>c.paraId)),w=Date.now()>>>0,g=null,h=null,y=null,S=n.trackRevisions===true,E=null,N=false,A=null,O=null,W=null,V=null,ee=null,pe=null,oe=null,we=null,me=false,_=null,te=null,D=null,G=null,$=null,U=[],X=[],ve=new WeakSet,Ce=false,Le=false,Ge=false,et=false,kt={change:new Set,selectionChange:new Set},fn=(c,m)=>{for(let x of kt[c])x(m);},ut=()=>so.set(document,e),Rt=c=>H(v({},sp(s,c)),{trackRevisions:S}),ht=null,Ze=null,Kt=null,ft=null,Qt=false,jn=false,gt=()=>{Kt==null||Kt.remove(),Kt=null;},pt=c=>{var I;if(!(c instanceof Element))return null;let m=c.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]"),k=Number(m==null?void 0:m.dataset.rowIndex),C=Number(m==null?void 0:m.dataset.columnIndex);return !m||!x||!Number.isInteger(k)||!Number.isInteger(C)?null:{tableId:(I=x.dataset.tableId)!=null?I:"",point:{rowIndex:k,columnIndex:C},element:m}},Po=c=>{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((c==null?void 0:c.kind)!=="table-cell-range")return;let m=Array.from(e.querySelectorAll("coco-word-native-table[data-table-id]")).find(T=>T.dataset.tableId===c.tableId);if(!m)return;let x=Math.min(c.anchor.rowIndex,c.focus.rowIndex),k=Math.max(c.anchor.rowIndex,c.focus.rowIndex),C=Math.min(c.anchor.columnIndex,c.focus.columnIndex),I=Math.max(c.anchor.columnIndex,c.focus.columnIndex);for(let T of Array.from(m.querySelectorAll("td[data-row-index][data-column-index]"))){let P=Number(T.dataset.rowIndex),M=Number(T.dataset.columnIndex),F=P+Math.max(1,T.rowSpan)-1,z=M+Math.max(1,T.colSpan)-1;P<=k&&F>=x&&M<=I&&z>=C&&(T.classList.add("is-cell-range-selected"),T.setAttribute("aria-selected","true"),P===c.anchor.rowIndex&&M===c.anchor.columnIndex&&T.classList.add("is-cell-range-anchor"),P===c.focus.rowIndex&&M===c.focus.columnIndex&&T.classList.add("is-cell-range-focus"));}},wa=++Dv,xa=`coco-word-search-match-${wa}`,ya=`coco-word-search-active-${wa}`,va=`coco-word-preserved-selection-${wa}`,Sa=document.createElement("style");Sa.textContent=`
1539
- ::highlight(${xa}) { background-color: rgb(250 204 21 / 42%); }
1540
- ::highlight(${ya}) { background-color: rgb(249 115 22 / 68%); color: inherit; }
1541
- ::highlight(${va}) { background-color: rgb(0 120 215 / 34%); color: inherit; }
1542
- `,(o!=null?o:document.head).appendChild(Sa);let bt=(Wd=globalThis.CSS)==null?void 0:Wd.highlights,vr=globalThis.Highlight,Xl=()=>{bt==null||bt.delete(xa),bt==null||bt.delete(ya);},ka=()=>{bt==null||bt.delete(va);},at=(c=false)=>{if(ka(),(h==null?void 0:h.kind)!=="text-range"||!c&&(document.activeElement===i||e.contains(document.activeElement))||!bt||!vr)return;let m=nt(s,h),x=Os(e,m.anchor,m.focus);x&&!x.collapsed&&bt.set(va,new vr(x));},Ro=()=>{if(Xl(),!E||!bt||!vr)return;let c=[],m=null;E.matches.forEach((x,k)=>{let C=cf(e,x.paraId,x.from,x.to);C&&(k===E.activeIndex?m=C:c.push(C));}),c.length>0&&bt.set(xa,new vr(...c)),m&&bt.set(ya,new vr(m));},Mo=()=>E?{options:v({},E.options),matches:E.matches.map(c=>v({},c)),activeIndex:E.activeIndex}:null,bh=()=>{if(!E)return;let c=zs(s,E.options);E={options:v({},E.options),matches:c,activeIndex:c.length===0?-1:Math.min(Math.max(0,E.activeIndex),c.length-1)},Ro(),at();},Yl=()=>{let c=E&&E.activeIndex>=0?E.matches[E.activeIndex]:null,m=c?e.querySelector(`coco-word-native-p[data-para-id="${c.paraId}"]`):null;m==null||m.scrollIntoView({block:"center",inline:"nearest"});},wh=c=>{let m={query:c.query,matchCase:!!c.matchCase,wholeWord:!!c.wholeWord},x=zs(s,m);return E={options:m,matches:x,activeIndex:x.length>0?0:-1},Ro(),Yl(),Mo()},xh=(c="forward")=>{if(!E||E.matches.length===0)return Mo();let m=c==="backward"?-1:1;return E=H(v({},E),{activeIndex:(E.activeIndex+m+E.matches.length)%E.matches.length}),Ro(),Yl(),Mo()},Ca=()=>{E=null,Xl();},Un=()=>{ht==null||ht.remove(),ht=null;},Ea=()=>{if(!ht||!g)return;let c=e.querySelector(`coco-word-native-p[data-para-id="${g.paraId}"] img[data-drawing-id="${g.drawingId}"]`);if(!c){Un();return}let m=e.getBoundingClientRect(),x=c.getBoundingClientRect();ht.style.left=`${x.right-m.left+e.scrollLeft-6}px`,ht.style.top=`${x.bottom-m.top+e.scrollTop-6}px`;},_t=()=>{if(d){Un();return}if(!g){Un();return}if(uf(e,g),!!e.querySelector(`coco-word-native-p[data-para-id="${g.paraId}"] img[data-drawing-id="${g.drawingId}"]`)){if(!(ht!=null&&ht.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;ut();let k=v({},g),C=e.querySelector(`coco-word-native-p[data-para-id="${k.paraId}"] img[data-drawing-id="${k.drawingId}"]`);if(!C)return;Ze==null||Ze(),x.preventDefault(),x.stopPropagation(),m.setPointerCapture(x.pointerId);let I=C.getBoundingClientRect(),T=x.clientX,P=x.clientY,M=Math.max(1,I.width),F=Math.max(1,I.height),z=M/F,j=M,re=F,le=Pe=>{let K=Pe.clientX-T,J=Pe.clientY-P;if(Pe.shiftKey)j=Math.max(24,M+K),re=Math.max(24,F+J);else {let Q=Math.abs(K)>=Math.abs(J)?K:J*z;j=Math.max(24,M+Q),re=Math.max(24,j/z);}C.style.width=`${j}px`,C.style.height=`${re}px`,Ea();},xe=Pe=>{Ze==null||Ze(),Ze=null,m.hasPointerCapture(Pe.pointerId)&&m.releasePointerCapture(Pe.pointerId),Se({kind:"set-image-size",objectId:k.drawingId,width:Math.round(j*100)/100,height:Math.round(re*100)/100});};document.addEventListener("pointermove",le,true),document.addEventListener("pointerup",xe,true),document.addEventListener("pointercancel",xe,true),Ze=()=>{document.removeEventListener("pointermove",le,true),document.removeEventListener("pointerup",xe,true),document.removeEventListener("pointercancel",xe,true);};}),e.appendChild(m),ht=m;}Ea();}},Ao=()=>Ea();window.addEventListener("resize",Ao),document.addEventListener("scroll",Ao,true);let Zl=()=>{if(r.setAttribute("aria-readonly",String(d)),e.dataset.readOnly=String(d),!!d){for(let c of Array.from(e.querySelectorAll('[contenteditable="true"]')))c.contentEditable="false";Un();}},Re=(c,m)=>{O!==null&&(window.clearTimeout(O),O=null),W!==null&&(window.clearTimeout(W),W=null),ai(s);let x=Pu(s);e.replaceChildren(x),Mu(x,s),Zl(),Ta(x);let k=(m==null?void 0:m.kind)==="table-cell-range"?m:(h==null?void 0:h.kind)==="table-cell-range"?h:null;Po(k),Ro(),at(),g&&_t(),(m==null?void 0:m.kind)==="text-range"?vn(e,m.anchor,m.focus):c&&dt(e,c);},Ia=(c,m)=>{var I;let x=Z(s,c);if(!x){Re(m);return}let k=Array.from(e.querySelectorAll(`coco-word-native-p[data-para-id="${c}"]`));if(k.length===0){Re(m);return}for(let T of k)T.replaceWith(Jr(x));Zl();let C=(I=e.querySelector(":scope > coco-word-native-document"))!=null?I:e.querySelector("coco-word-native-document");C&&yn(C),g&&_t(),m&&dt(e,m);},De=(c,m,x)=>{let k=e.querySelector(":scope > coco-word-native-document");if(!k)return false;let C=Au(k,s,c);Ta(k);for(let I of Array.from(k.querySelectorAll(`coco-word-native-p[data-para-id="${c}"] img`)))I.complete||ve.has(I)||(ve.add(I),I.addEventListener("load",()=>{ve.delete(I),De(c);},{once:true}));return (x==null?void 0:x.kind)==="text-range"?vn(e,x.anchor,x.focus):m&&dt(e,m),C},pn=(c,m=180,x)=>{me||we||(W!==null&&window.clearTimeout(W),W=window.setTimeout(()=>{var I;if(W=null,me||we)return;let k=(I=e.querySelector(":scope > coco-word-native-document"))!=null?I:e.querySelector("coco-word-native-document");if(!k||x&&!x(k))return;let C=(h==null?void 0:h.kind)==="object"?h:Ve(e);if((C==null?void 0:C.kind)==="text-range")De(c,void 0,C);else if((C==null?void 0:C.kind)==="object")De(c),g={paraId:C.paraId,drawingId:C.objectId},_t();else {let T=(C==null?void 0:C.kind)==="caret"?C:mt(e);De(c,T!=null?T:void 0);}},m));},Lo=(c,m=80)=>{var C;let x=(C=e.querySelector(":scope > coco-word-native-document"))!=null?C:e.querySelector("coco-word-native-document");if(!x)return;let k=false;for(let I of Array.from(x.querySelectorAll(`coco-word-native-p[data-para-id="${c}"] img`)))I.complete||ve.has(I)||(k=true,ve.add(I),I.addEventListener("load",()=>{ve.delete(I),pn(c,0);},{once:true}),I.addEventListener("error",()=>ve.delete(I),{once:true}));pn(c,k?800:m);},Sr=c=>{var x;if((_==null?void 0:_.paraId)===c)return;let m=(x=e.querySelector(":scope > coco-word-native-document"))!=null?x:e.querySelector("coco-word-native-document");m&&(_={paraId:c,measurement:As(m,s,c)});},Na=c=>{pn(c,700,m=>{let x=_;if(_=null,!x||x.paraId!==c)return false;let k=As(m,s,c);return k.overflowPx>Math.max(1,x.measurement.overflowPx+1)||!x.measurement.canBackfillPrevious&&k.canBackfillPrevious||!x.measurement.canBackfillNext&&k.canBackfillNext});},Wo=new WeakMap,Bo=new ResizeObserver(c=>{var m,x;for(let k of c){let C=k.target;if(!(C instanceof HTMLElement))continue;let I=Math.round(k.contentRect.height),T=Wo.get(C);if(Wo.set(C,I),T===void 0||Math.abs(T-I)<=1)continue;let P=(m=C.querySelector("coco-word-native-p[data-para-id]"))==null?void 0:m.dataset.paraId;if(P){let M=document.activeElement;if(M&&C.contains(M)){let F=(x=M.closest("coco-word-native-p[data-para-id]"))==null?void 0:x.dataset.paraId;Na(F!=null?F:P);}else pn(P);}}}),Ta=c=>{for(let m of Array.from(c.querySelectorAll("coco-word-native-table")))Wo.has(m)||(Wo.set(m,Math.round(m.getBoundingClientRect().height)),Bo.observe(m));},Te=(c="immediate")=>{if(l)return;let m=()=>{var k;bh();let x=fp(p,u,++f);p=u.slice(),(k=n.onChange)==null||k.call(n,x),fn("change",x);};if(c==="immediate"){ee!==null&&(window.clearTimeout(ee),ee=null),m();return}ee!==null&&window.clearTimeout(ee),ee=window.setTimeout(()=>{ee=null,m();},180);},Pa=()=>{l||(pe!==null&&window.clearTimeout(pe),pe=window.setTimeout(()=>{var x,k;pe=null;let c=(x=h!=null?h:Ve(e))!=null?x:lt(e),m={selection:c,commandState:Rt(c)};(k=n.onSelectionChange)==null||k.call(n,m),fn("selectionChange",m);},80));},Jl=c=>{D=c,G!==null&&window.clearTimeout(G),G=window.setTimeout(()=>{D=null,G=null;},1e3);},yh=(c,m,x)=>{let k=Array.from(e.querySelectorAll(`coco-word-native-p[data-para-id="${c}"] img[data-drawing-id="${m}"]`));for(let C of k)C.remove();Pt(e),x&&dt(e,x);},In=(c,m,x={})=>{Array.isArray(c)?u.push(...c):c&&u.push(c),c&&(X.length=0),x.localParaId?(Ia(x.localParaId,m),pn(x.localParaId)):Re(m),Te();},Do=c=>{let m=Z(s,c);return !!m&&m.content.every(x=>x.kind==="text")},Ra=c=>{let m=Z(s,c);return m?Ne(m).length:0},kr=(c,m,x,k)=>{var P,M;let C=Z(s,c);if(!C)return null;let I=k==="before"?m-1:k==="after"?m+1:m;if(I<0)return null;let T=0;for(let F of C.content){let z=F.kind==="text"?F.text.length:1;if(I>=T&&I<T+z){let j=F.kind==="text"?(P=F.marks)==null?void 0:P.find(re=>re.kind==="revision"&&re.revisionKind===x):void 0;return j&&"revisionId"in j&&(M=j.revisionId)!=null?M:null}T+=z;}return null},Ql=(c,m)=>{var x;return !S||!m||m.kind!=="text"||m.op!=="insert"&&m.op!=="replace"||m.text.length===0?null:$t(s,c,m.offset,m.offset+m.text.length,{revisionId:(x=kr(c,m.offset,"insert","before"))!=null?x:ot(s),revisionKind:"insert",author:"User",date:new Date().toISOString()})},Ma=c=>{let m=ye(s,c.anchor.paraId),x=ye(s,c.focus.paraId);if(!m||!x||m.container!==x.container)return null;let k=Math.min(m.index,x.index),C=Math.max(m.index,x.index),I=[];for(let T=k;T<=C;T+=1){let P=m.container[T];if((P==null?void 0:P.kind)!=="paragraph"||P.content.some(M=>M.kind!=="text"))return null;I.push(he(P));}return I},ed=c=>{let m=Ma(c);return m&&m.length>1?m:null},vh=c=>{let m=ed(c);return m?(oe={range:c,beforeParagraphs:m,changesStart:u.length},true):false},Fo=c=>{var T;let m=c.anchor.paraId;if(c.focus.paraId!==m)return;let x=e.querySelector(`coco-word-native-p[data-para-id="${m}"]`),k=Z(s,m);if(!(x!=null&&x.closest("coco-word-native-table"))||!k||((T=$==null?void 0:$.afterParagraphs[0])==null?void 0:T.paraId)===m)return;let C=he(k),I={source:"browser",patchMode:"individual",skipDeferredRender:true,range:c,beforeParagraphs:[C],afterParagraphs:[C],changesStart:u.length,changes:[]};U.push(I),X.length=0,$=I;},td=c=>{if(d){c.preventDefault();return}me=true,te!==null&&(window.clearTimeout(te),te=null),we&&Aa(),O!==null&&(window.clearTimeout(O),O=null),W!==null&&(window.clearTimeout(W),W=null),ee!==null&&(window.clearTimeout(ee),ee=null),pe!==null&&(window.clearTimeout(pe),pe=null);let m=Ve(e),x=c.target instanceof Node?Nt(c.target):null,k=x==null?void 0:x.dataset.paraId,C=mt(e),I=k?{paraId:k,offset:(C==null?void 0:C.paraId)===k?C.offset:Ra(k)}:C,T=I?Z(s,I.paraId):null;if(!I||!T||T.content.some(M=>M.kind!=="text"))return;Sr(I.paraId),$=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:he(T),changesStart:u.length,range:P};},Aa=()=>{var M;te=null;let c=we;if(we=null,!c)return;let m=Z(s,c.paraId);if(!m)return;let x=e.querySelector(`coco-word-native-p[data-para-id="${c.paraId}"]`);if(!x)return;let k=Gr(s,c.paraId,(M=x.textContent)!=null?M:"");k&&u.push(k);let C=Ql(c.paraId,k);C&&u.push(C);let I=he(m);if(JSON.stringify(I)===JSON.stringify(c.beforeParagraph)){u.splice(c.changesStart);return}let T={source:"browser",patchMode:"individual",skipDeferredRender:true,range:c.range,beforeParagraphs:[c.beforeParagraph],afterParagraphs:[I],changesStart:c.changesStart,changes:u.slice(c.changesStart)};U.push(T),X.length=0;let P=mt(e);P&&ie(v({kind:"caret"},P)),Na(c.paraId),C&&Ia(c.paraId,P!=null?P:void 0),Te("deferred");},nd=()=>{me=false,te!==null&&window.clearTimeout(te),te=window.setTimeout(Aa,80);},Ho=(c,m)=>{var M,F;let x=new Set([...c.beforeParagraphs,...c.afterParagraphs].map(z=>z.paraId)),k=(M=[...c.beforeParagraphs,...c.afterParagraphs].find(z=>Z(s,z.paraId)))==null?void 0:M.paraId;if(!k)return false;let C=ye(s,k);if(!C)return false;if(c.patchMode==="individual"){for(let z of m){let j=ye(s,z.paraId);if(!j)return false;Object.assign(j.paragraph,he(z));}return true}let I=Array.from(x).filter(z=>Z(s,z));if(I.length===0||m.length===0)return false;let T=he(m[0]);Object.assign(C.paragraph,T);for(let z of I)z!==k&&((F=ye(s,z))==null||F.remove());let P=T.paraId;for(let z of m.slice(1)){let j=ye(s,P);if(!j)return false;let re=he(z);j.insertAfter(re),P=re.paraId;}return true},Sh=()=>{var T;if(!oe)return false;let c=oe;oe=null;let m=c.beforeParagraphs.map(P=>wp(e,P.paraId)),x=m.every(P=>P!==null),k=[];if(x)for(let P=0;P<c.beforeParagraphs.length;P+=1){let M=c.beforeParagraphs[P],F=Gr(s,M.paraId,(T=m[P])!=null?T:"");F&&k.push(F);}else k.push(...ui(s,c.range.anchor,c.range.focus));if(k.length===0)return false;u.push(...k);let C=c.beforeParagraphs.map(P=>Z(s,P.paraId)).filter(P=>P!==null);if(C.length>0){let P=H(v({},c),{source:"browser",afterParagraphs:C.map(he),changes:k});U.push(P),$=null,X.length=0;}let I=mt(e);return I&&ie({kind:"caret",paraId:I.paraId,offset:I.offset}),De(c.beforeParagraphs[0].paraId,I!=null?I:void 0),Te("deferred"),true},kh=()=>{let c=U[U.length-1];if(!c||ar(c)||!Pi(e,c.beforeParagraphs)||!Ho(c,c.beforeParagraphs))return false;U.pop(),X.push(c),u.splice(c.changesStart);let m=mt(e);return m&&ie({kind:"caret",paraId:m.paraId,offset:m.offset}),De(c.beforeParagraphs[0].paraId,m!=null?m:void 0),Te("deferred"),true},Ch=()=>{let c=X[X.length-1];if(!c||ar(c)||!Pi(e,c.afterParagraphs)||!Ho(c,c.afterParagraphs))return false;X.pop(),U.push(c),u.splice(c.changesStart),u.push(...c.changes);let m=mt(e);return m&&ie({kind:"caret",paraId:m.paraId,offset:m.offset}),De(c.beforeParagraphs[0].paraId,m!=null?m:void 0),Te("deferred"),true},Bt=(c,m,x)=>{var F,z,j;if(c.patchMode==="individual"){let re=false;for(let xe of m){let Pe=Array.from(e.querySelectorAll(`coco-word-native-p[data-para-id="${xe.paraId}"]`));for(let K of Pe)K.replaceWith(Jr(xe)),re=true;}x&&dt(e,x);let le=e.querySelector(":scope > coco-word-native-document");return le&&yn(le),re}let k=new Set([...c.beforeParagraphs,...c.afterParagraphs].map(re=>re.paraId)),C=Array.from(k).flatMap(re=>Array.from(e.querySelectorAll(`coco-word-native-p[data-para-id="${re}"]`))),I=(F=c.beforeParagraphs[0])==null?void 0:F.paraId,T=(z=C.find(re=>re.dataset.paraId===I))!=null?z:C[0];if(!T)return false;let P=m.map(re=>Jr(re));T.replaceWith(...P);for(let re of C)re!==T&&re.isConnected&&re.remove();x&&dt(e,x);let M=(j=e.querySelector(":scope > coco-word-native-document"))!=null?j:e.querySelector("coco-word-native-document");return M&&yn(M),true},rd=(c,m,x)=>(c.container.splice(c.startIndex,x,...rt(m)),true),Dt=(c,m,x,k)=>{var F,z;let C=[...c.beforeBlocks,...c.afterBlocks].flatMap(j=>Ov(e,j)),I=((F=c.afterBlocks[0])==null?void 0:F.kind)==="paragraph"?c.afterBlocks[0].paraId:((z=c.beforeBlocks[0])==null?void 0:z.kind)==="paragraph"?c.beforeBlocks[0].paraId:null,T=I?e.querySelector(`coco-word-native-p[data-para-id="${I}"]`):C[0];if(!T)return false;let P=m.map(j=>Zr(j));T.replaceWith(...P);for(let j of C)j!==T&&j.isConnected&&j.remove();let M=e.querySelector(":scope > coco-word-native-document");return M&&Ta(M),M&&yn(M),k?vn(e,k.anchor,k.focus):x&&dt(e,x),true},Eh=c=>{let m=e.querySelector(`coco-word-native-p[data-para-id="${c.anchor.paraId}"]`),x=e.querySelector(`coco-word-native-p[data-para-id="${c.focus.paraId}"]`);return !!m&&!!x&&m.closest("coco-word-native-page")!==x.closest("coco-word-native-page")},od=(c,m)=>{let x=ed(c);if(!x)return false;let k={range:c,beforeParagraphs:x,changesStart:u.length},C=ru(s,c.anchor,c.focus,m);if(C.length===0)return false;let I=x.map(M=>Z(s,M.paraId)).filter(M=>M!==null).map(he);if(I.length===0)return false;let T=H(v({},k),{source:"local",afterParagraphs:I,changes:C}),P={paraId:c.anchor.paraId,offset:c.anchor.offset+m.length};return u.push(...C),U.push(T),$=m.length>0?T:null,X.length=0,Bt(T,I,P)?De(x[0].paraId,P):Re(P),ie(v({kind:"caret"},P)),Te("deferred"),true},Oo=(c,m)=>{let x=tu(s,c.anchor,c.focus,m);if(!x)return false;let k={source:"local",range:c,container:x.container,startIndex:x.startIndex,beforeBlocks:x.beforeBlocks,afterBlocks:x.afterBlocks,changesStart:u.length,changes:x.changes};if(u.push(...x.changes),U.push(k),X.length=0,$=null,g=null,!Dt(k,x.afterBlocks,x.cursor))Re(x.cursor);else {let C=e.querySelector(":scope > coco-word-native-document");C&&Vt(C,s,x.cursor.paraId),De(x.cursor.paraId,x.cursor);}return ie(v({kind:"caret"},x.cursor)),Te("deferred"),true},Ih=(c,m)=>{let x=nu(s,c.anchor,c.focus,m);if(!x)return false;let k={source:"local",range:c,container:x.container,startIndex:x.startIndex,beforeBlocks:x.beforeBlocks,afterBlocks:x.afterBlocks,changesStart:u.length,changes:x.changes};u.push(...x.changes),U.push(k),X.length=0,$=null,g=null;for(let C of _e(s))b.add(C.paraId);if(!Dt(k,x.afterBlocks,x.cursor))Re(x.cursor);else {let C=e.querySelector(":scope > coco-word-native-document");C&&Vt(C,s,x.cursor.paraId),De(x.cursor.paraId,x.cursor);}return ie(v({kind:"caret"},x.cursor)),Te("deferred"),true},Nh=(c,m)=>{let x=c.kind==="table-cell-range"?(()=>{var Pe,K,J;let re=(Pe=Oe(s,c.tableId))==null?void 0:Pe.table,le=re?(K=tt(re,c)[0])==null?void 0:K.cell:null,xe=(J=le==null?void 0:le.paragraphs[0])==null?void 0:J.paraId;return xe?{paraId:xe,offset:0}:null})():c.kind==="text-range"?c.anchor:{paraId:c.paraId,offset:c.offset};if(!x)return false;let k=rn(s,x.paraId);if(!k)return false;let C=rt([k.table])[0];if(!C||C.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=jc(s,x.paraId,I,Nr);if(!T)return false;let P=rt([k.table])[0];if(!P||P.kind!=="table")return false;let M=S?ot(s):null,F=m.kind==="insert-table-row"||m.kind==="insert-table-column"?"insert":"delete";M&&(k.table.revision={kind:"revision",id:`revision:${M}`,revisionId:M,revisionKind:F,author:"User",date:new Date().toISOString()},P.revision=v({},k.table.revision),T.change.kind==="table"&&(T.change.revisionId=M,T.change.revisionKind=F,T.change.beforeTable=C));let z=v({kind:"caret"},T.cursor),j={source:"local",range:{anchor:x,focus:x},container:k.container,startIndex:k.tableIndex,beforeBlocks:[C],afterBlocks:[P],changesStart:u.length,changes:[T.change],beforeSelection:c,afterSelection:z};if(u.push(T.change),U.push(j),X.length=0,$=null,g=null,!Dt(j,j.afterBlocks,T.cursor))Re(T.cursor);else {let re=e.querySelector(":scope > coco-word-native-document");re&&Vt(re,s,T.cursor.paraId),De(T.cursor.paraId,T.cursor);}return ie(z),Te("deferred"),true},Th=(c,m)=>{let x=Oe(s,c.tableId);if(!x)return false;let k=rt([x.table])[0];if(!k||k.kind!=="table")return false;let I=tt(x.table,c)[0],T=m.kind==="merge-table-cells"?Uc(s,c.tableId,c):I?Kc(s,c.tableId,I.rowIndex,I.columnIndex,Nr):null;if(!T)return false;let P=rt([x.table])[0];if(!P||P.kind!=="table")return false;let M=S?ot(s):null,F=m.kind==="merge-table-cells"?"insert":"delete";M&&(x.table.revision={kind:"revision",id:`revision:${M}`,revisionId:M,revisionKind:F,author:"User",date:new Date().toISOString()},P.revision=v({},x.table.revision),T.change.kind==="table"&&(T.change.revisionId=M,T.change.revisionKind=F,T.change.beforeTable=k));let z={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:[k],afterBlocks:[P],changesStart:u.length,changes:[T.change],beforeSelection:c,afterSelection:v({kind:"caret"},T.cursor)};if(u.push(T.change),U.push(z),X.length=0,$=null,g=null,!Dt(z,z.afterBlocks,T.cursor))Re(T.cursor);else {let j=e.querySelector(":scope > coco-word-native-document");j&&Vt(j,s,T.cursor.paraId),De(T.cursor.paraId,T.cursor);}return ie(v({kind:"caret"},T.cursor)),Te("deferred"),true},Ph=(c,m)=>{let x=c.kind==="text-range"?c.anchor:c.kind==="table-cell-range"?(()=>{var z,j;let M=(z=Oe(s,c.tableId))==null?void 0:z.table,F=M?(j=tt(M,c)[0])==null?void 0:j.cell.paragraphs[0]:null;return F?{paraId:F.paraId,offset:0}:null})():{paraId:c.paraId,offset:c.offset};if(!x)return false;let k=m.kind==="insert-table"?c.kind==="caret"?Vc(s,c.paraId,c.offset,m.rows,m.columns,Nr):null:(()=>{var F;let M=(F=Rt(c).table)==null?void 0:F.tableId;return M?Gc(s,M,Nr):null})();if(!k)return false;let C=S?ot(s):null,I=m.kind==="insert-table"?"insert":"delete";if(C){let M=k.afterBlocks.find(F=>F.kind==="table");(M==null?void 0:M.kind)==="table"&&(M.revision={kind:"revision",id:`revision:${C}`,revisionId:C,revisionKind:I,author:"User",date:new Date().toISOString()},k.changes.forEach(F=>{if(F.kind==="table"){F.revisionId=C,F.revisionKind=I;let z=k.beforeBlocks.find(j=>j.kind==="table");if((z==null?void 0:z.kind)==="table"&&(F.beforeTable=z),F.op==="insert-table"){F.anchorParaId=x.paraId,F.anchorOffset=x.offset;let j=k.afterBlocks.find(re=>re.kind==="table");(j==null?void 0:j.kind)==="table"&&(F.tableSnapshot=j);}}}));}for(let M of k.changes){if(M.kind!=="table"||M.op!=="insert-table")continue;M.anchorParaId=x.paraId,M.anchorOffset=x.offset;let F=k.afterBlocks.find(z=>z.kind==="table");(F==null?void 0:F.kind)==="table"&&(M.tableSnapshot=F);}let T=v({kind:"caret"},k.cursor),P={source:"local",range:{anchor:x,focus:c.kind==="text-range"?c.focus:x},container:k.container,startIndex:k.startIndex,beforeBlocks:k.beforeBlocks,afterBlocks:k.afterBlocks,changesStart:u.length,changes:k.changes,beforeSelection:c,afterSelection:T};u.push(...k.changes),U.push(P),X.length=0,$=null,g=null;for(let M of _e(s))b.add(M.paraId);if(!Dt(P,P.afterBlocks,k.cursor))Re(k.cursor);else {let M=e.querySelector(":scope > coco-word-native-document");M&&Vt(M,s,k.cursor.paraId),De(k.cursor.paraId,k.cursor);}return ie(T),Te("deferred"),true},Rh=(c,m)=>{var le,xe;let x=c.kind==="table-cell-range"?Oe(s,c.tableId):null,k=c.kind==="table-cell-range"&&x?(le=tt(x.table,c)[0])==null?void 0:le.cell:null,C=c.kind==="table-cell-range"?(xe=k==null?void 0:k.paragraphs[0])!=null&&xe.paraId?{paraId:k.paragraphs[0].paraId,offset:0}:null:c.kind==="text-range"?c.anchor:{paraId:c.paraId,offset:c.offset};if(!C)return false;let I=x!=null?x:rn(s,C.paraId);if(!I)return false;let T=rt([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},M=c.kind==="table-cell-range"?_c(s,c.tableId,c,P):gs(s,C.paraId,P);if(!M)return false;let F=rt([I.table])[0];if(!F||F.kind!=="table")return false;let z={source:"local",range:{anchor:C,focus:C},container:I.container,startIndex:I.tableIndex,beforeBlocks:[T],afterBlocks:[F],changesStart:u.length,changes:"changes"in M?M.changes:[M.change],beforeSelection:c,afterSelection:c};u.push(...z.changes),U.push(z),X.length=0,$=null;let j=c.kind==="caret"?c:void 0,re=c.kind==="text-range"?c:void 0;if(!Dt(z,z.afterBlocks,j,re))Re(j,c);else {Ft(c);let Pe=e.querySelector(":scope > coco-word-native-document");Pe&&Vt(Pe,s,C.paraId),De(C.paraId,j,re),Ft(c);}return ie(c),Te("deferred"),true},Kn=c=>{let m=Oe(s,c.tableId);if(!m)return false;let x=rt([m.table])[0];if(!x||x.kind!=="table")return false;let k=qc(s,c.tableId,c);if(!k)return false;let C=rt([m.table])[0];if(!C||C.kind!=="table")return false;let I={source:"local",range:{anchor:k.cursor,focus:k.cursor},container:m.container,startIndex:m.tableIndex,beforeBlocks:[x],afterBlocks:[C],changesStart:u.length,changes:k.changes,beforeSelection:c,afterSelection:c};if(u.push(...k.changes),U.push(I),X.length=0,$=null,!Dt(I,I.afterBlocks))Re(void 0,c);else {let T=e.querySelector(":scope > coco-word-native-document");T&&Vt(T,s,k.cursor.paraId),De(k.cursor.paraId);}return ie(c),Te("deferred"),true},La=(c,m)=>{var re,le,xe;let x=Oe(s,c.tableId);if(!x)return false;let k=rt([x.table])[0];if(!k||k.kind!=="table")return false;let C={rowIndex:Math.min(c.anchor.rowIndex,c.focus.rowIndex),columnIndex:Math.min(c.anchor.columnIndex,c.focus.columnIndex)},I=(le=(re=m.content)!=null?re:m.text)!=null?le:[],T=m.content?Yc(s,c.tableId,C,m.content):Xc(s,c.tableId,C,(xe=m.text)!=null?xe:[]);if(!T)return false;let P=rt([x.table])[0];if(!P||P.kind!=="table")return false;let M=I.length,F=Math.max(1,...I.map(Pe=>Pe.length)),z={kind:"table-cell-range",tableId:c.tableId,anchor:C,focus:{rowIndex:Math.min(x.table.rows.length-1,C.rowIndex+M-1),columnIndex:C.columnIndex+F-1}},j={source:"local",range:{anchor:T.cursor,focus:T.cursor},container:x.container,startIndex:x.tableIndex,beforeBlocks:[k],afterBlocks:[P],changesStart:u.length,changes:T.changes,beforeSelection:c,afterSelection:z};if(u.push(...T.changes),U.push(j),X.length=0,$=null,!Dt(j,j.afterBlocks))Re(void 0,z);else {let Pe=e.querySelector(":scope > coco-word-native-document");Pe&&Vt(Pe,s,T.cursor.paraId),De(T.cursor.paraId);}return ie(z),Te("deferred"),true},Ft=c=>{if(c){if(c.kind==="text-range"){vn(e,c.anchor,c.focus);return}if(c.kind==="object"){g={paraId:c.paraId,drawingId:c.objectId},_t();return}if(c.kind==="table-cell-range"){Po(c);return}dt(e,c);}},Mh=()=>{var k;let c=U[U.length-1];if(!c)return false;if(ar(c)){let C=(k=c.beforeSelection)!=null?k:{kind:"text-range",anchor:c.range.anchor,focus:c.range.focus},I=C.kind==="caret"?C:void 0,T=C.kind==="text-range"?C:void 0;if(!rd(c,c.beforeBlocks,c.afterBlocks.length));Dt(c,c.beforeBlocks,I,T)||Re(I,C),Ft(C),U.pop(),X.push(c),$=null,u.splice(c.changesStart),ie(C);let P=e.querySelector(":scope > coco-word-native-document");P&&Vt(P,s,c.range.anchor.paraId);let M=C.kind==="text-range"?C.anchor.paraId:C.kind==="table-cell-range"?c.range.anchor.paraId:C.paraId;return De(M,I,T),Te("deferred"),true}if(c.source==="browser"&&!c.skipDeferredRender&&!Pi(e,c.afterParagraphs))return false;let m={paraId:c.beforeParagraphs[0].paraId,offset:c.range.anchor.offset};if(!Ho(c,c.beforeParagraphs))return false;let x=mp(c,"before");if(c.forceFullRender){U.pop(),X.push(c),$=null,u.splice(c.changesStart);let C=x!=null?x:v({kind:"caret"},m);return ie(C),Re(C.kind==="caret"?C:void 0,C),Ft(C),Te("deferred"),true}if(!Bt(c,c.beforeParagraphs,x?void 0:m))return false;if(Ft(x),U.pop(),X.push(c),$=null,u.splice(c.changesStart),ie(x!=null?x:v({kind:"caret"},m)),hp(c)||c.skipDeferredRender){let C=c.beforeParagraphs[0].paraId;c.deferLayoutReflow?Lo(C):De(C,x?void 0:m,(x==null?void 0:x.kind)==="text-range"?x:void 0),Ft(x),c.deferLayoutReflow||pn(C);}return Te("deferred"),true},Ah=()=>{var k;let c=X[X.length-1];if(!c)return false;if(ar(c)){let C=(k=c.afterSelection)!=null?k:{kind:"caret",paraId:c.afterBlocks[0].kind==="paragraph"?c.afterBlocks[0].paraId:c.range.anchor.paraId,offset:c.range.anchor.offset},I=C.kind==="caret"?C:void 0,T=C.kind==="text-range"?C:void 0;if(!rd(c,c.afterBlocks,c.beforeBlocks.length));Dt(c,c.afterBlocks,I,T)||Re(I,C),Ft(C),X.pop(),U.push(c),$=null,u.splice(c.changesStart),u.push(...c.changes),ie(C);let P=C.kind==="text-range"?C.anchor.paraId:C.kind==="table-cell-range"?c.range.anchor.paraId:C.paraId,M=e.querySelector(":scope > coco-word-native-document");return M&&Vt(M,s,P),De(P,I,T),Te("deferred"),true}if(c.source==="browser"&&!c.skipDeferredRender&&!Pi(e,c.beforeParagraphs))return false;let m={paraId:c.afterParagraphs[0].paraId,offset:c.range.anchor.offset};if(!Ho(c,c.afterParagraphs))return false;let x=mp(c,"after");if(c.forceFullRender){X.pop(),U.push(c),$=null,u.splice(c.changesStart),u.push(...c.changes);let C=x!=null?x:v({kind:"caret"},m);return ie(C),Re(C.kind==="caret"?C:void 0,C),Ft(C),Te("deferred"),true}if(!Bt(c,c.afterParagraphs,x?void 0:m))return false;if(Ft(x),X.pop(),U.push(c),$=null,u.splice(c.changesStart),u.push(...c.changes),ie(x!=null?x:v({kind:"caret"},m)),hp(c)||c.skipDeferredRender){let C=c.beforeParagraphs[0].paraId;c.deferLayoutReflow?Lo(C):De(C,x?void 0:m,(x==null?void 0:x.kind)==="text-range"?x:void 0),Ft(x),c.deferLayoutReflow||pn(C);}return Te("deferred"),true},Cr=()=>l||d||U.length===0?false:(ut(),Mh()),Er=()=>l||d||X.length===0?false:(ut(),Ah()),ie=c=>{if(c&&ut(),(c==null?void 0:c.kind)!=="object"&&Un(),Po(c),$v(h,c)){at();return}h=c,at(),Pa();},Ir=(c,m,x)=>{if(!c||(m==null?void 0:m.kind)!=="image")return false;let k=Z(s,m.paraId);if(!k)return false;let C={source:"local",patchMode:"individual",deferLayoutReflow:true,range:{anchor:x,focus:x},beforeParagraphs:[c],afterParagraphs:[he(k)],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),U.push(C),X.length=0,$=null,yh(m.paraId,m.drawingId,x),Lo(m.paraId),g=null,ie(v({kind:"caret"},x)),Te("deferred"),true},Nn=(c,m,x)=>{let k=Z(s,c),C=k==null?void 0:k.content.find(T=>T.kind==="image"&&T.drawingId===m);if(S&&k&&(C==null?void 0:C.kind)==="image"){let T=he(k),P=ot(s);return C.revision={kind:"revision",id:`revision:${P}`,revisionId:P,revisionKind:"delete",author:"User",date:new Date().toISOString()},wt({kind:"object",paraId:c,objectKind:"image",objectId:m,offset:x.offset},[T],[{kind:"image",op:"delete",paraId:c,offset:x.offset,drawingId:m,revisionId:P,revisionKind:"delete"}],true)}let I=k?he(k):null;return Ir(I,du(s,c,m),x)},Tn=(c,m,x=v({kind:"caret"},c),k)=>{let C=Z(s,c.paraId);if(!C)return false;let I=m==="delete-backward"?c.offset-1:c.offset;if(m!=="insert"&&!ci(s,c.paraId,I))return false;let T=he(C),P=m==="insert"?Jc(s,c.paraId,c.offset):m==="delete-backward"?Or(s,c.paraId,c.offset):$r(s,c.paraId,c.offset),M=Z(s,c.paraId);if(!P||P.kind!=="page-break"||!M)return false;let F={paraId:c.paraId,offset:m==="insert"?c.offset+1:m==="delete-backward"?Math.max(0,c.offset-1):c.offset},z=k!=null?k:v({kind:"caret"},F),j=z.kind==="caret"?z:F,re={source:"local",patchMode:"individual",forceFullRender:true,range:{anchor:c,focus:c},beforeParagraphs:[T],afterParagraphs:[he(M)],changesStart:u.length,changes:[P],beforeSelection:x,afterSelection:z};return u.push(P),U.push(re),X.length=0,$=null,g=null,Re(j,z),ie(z),Te("deferred"),true},$o=c=>{if(c.anchor.paraId!==c.focus.paraId)return false;let m=Ri(c.anchor.offset,c.focus.offset);if(!Qc(s,c.anchor.paraId,m.from,m.to))return false;let x=Z(s,c.anchor.paraId);if(!x)return false;let k=he(x),C=bn(s,c.anchor.paraId,m.from,m.to),I=Z(s,c.anchor.paraId);if(!I||!C.some(M=>M.kind==="page-break"))return false;let T={kind:"caret",paraId:c.anchor.paraId,offset:m.from},P={source:"local",patchMode:"individual",forceFullRender:true,range:{anchor:c.anchor,focus:c.focus},beforeParagraphs:[k],afterParagraphs:[he(I)],changesStart:u.length,changes:C,beforeSelection:c,afterSelection:T};return u.push(...C),U.push(P),X.length=0,$=null,Re(T,T),ie(T),Te("deferred"),true},zo=(c,m)=>{let x=ye(s,c.paraId);if(!x)return false;if(m==="backward"&&c.offset===0&&x.previous){let I=Ne(x.previous).length;return ci(s,x.previous.paraId,I-1)?Tn({paraId:x.previous.paraId,offset:I},"delete-backward",c,c):false}let k=x.container[x.index+1],C=(k==null?void 0:k.kind)==="paragraph"?k:null;return m==="forward"&&c.offset===Ne(x.paragraph).length&&C&&ci(s,C.paraId,0)?Tn({paraId:C.paraId,offset:0},"delete-forward",c,c):false},Pn=(c,m,x,k)=>{if(c.anchor.paraId!==c.focus.paraId)return false;let C=Z(s,c.anchor.paraId);if(!C)return false;let I=he(C),T=k(),P=Array.isArray(T)?T:T?[T]:[],M=Z(s,c.anchor.paraId);if(P.length===0||!M)return false;let F=v({kind:"caret"},x),z={source:"local",patchMode:"individual",range:c,beforeParagraphs:[I],afterParagraphs:[he(M)],changesStart:u.length,changes:P,beforeSelection:m,afterSelection:F};return u.push(...P),U.push(z),X.length=0,$=null,Bt(z,z.afterParagraphs,x)?De(c.anchor.paraId,x):Re(x),ie(F),Te("deferred"),true},en=c=>{if((c==null?void 0:c.kind)!=="text-range")return [];let m=nt(s,c);if(m.anchor.paraId===m.focus.paraId)return [{paraId:m.anchor.paraId,from:m.anchor.offset,to:m.focus.offset}];let x=ye(s,m.anchor.paraId),k=ye(s,m.focus.paraId);if(!x||!k||x.container!==k.container)return [];let C=[];for(let I=x.index;I<=k.index;I+=1){let T=x.container[I];if((T==null?void 0:T.kind)!=="paragraph")return [];C.push({paraId:T.paraId,from:I===x.index?m.anchor.offset:0,to:I===k.index?m.focus.offset:Ne(T).length});}return C},id=c=>{var m;if(!c)return [];if(c.kind==="caret"||c.kind==="object")return [c.paraId];if(c.kind==="table-cell-range"){let x=(m=Oe(s,c.tableId))==null?void 0:m.table;return x?tt(x,c).flatMap(({cell:k})=>k.paragraphs.map(C=>C.paraId)):[]}return en(c).map(x=>x.paraId)},ad=c=>{if((c==null?void 0:c.kind)!=="text-range")return null;let m=en(c);return m.length===0?null:m.map(x=>Ne(Z(s,x.paraId)).slice(x.from,x.to)).join(`
1543
- `)},sd=c=>en(c).map(m=>{var P;let x=Z(s,m.paraId),k=Ne(x).slice(m.from,m.to),C=[],I=0;for(let M of x.content){let F=Vv(M),z=I+F.length,j=Math.max(m.from,I),re=Math.min(m.to,z),le=M.kind==="text"||M.kind==="field"?M.format:null,xe=M.kind==="text"?M.hyperlink:void 0;(le||xe)&&re>j&&C.push(v({from:j-m.from,to:re-m.from,format:v({},le!=null?le:{})},xe?{hyperlink:v({},xe)}:{})),I=z;}let T=(P=x.format)!=null&&P.hasNumbering&&x.format.numbering?hn(x.format.numbering):null;return v({text:k,runs:C},T?{listType:T}:{})}),_n=(c,m,x)=>{var M;if(S&&!x&&c.anchor.paraId===c.focus.paraId)return Se({kind:"replace-range",anchor:c.anchor,focus:c.focus,text:m});if(Oo(c,m))return true;let k=Ma(c);if(!k)return false;let C=xs(s,c.anchor,c.focus,m);if(!C||C.changes.length===0)return false;for(let F of C.paragraphIds)b.add(F);let I=null;for(let F=0;F<((M=x==null?void 0:x.length)!=null?M:0);F+=1){let z=x[F],j=C.paragraphIds[F];if(!j)break;let re=F===0?c.anchor.offset:0;for(let le of z.runs){if(Object.keys(le.format).length>0){let xe=ys(s,j,re+le.from,re+le.to,le.format);xe&&C.changes.push(xe);}if(le.hyperlink){let xe=Ss(s,j,re+le.from,re+le.to,le.hyperlink);xe&&C.changes.push(xe);}}if(z.listType){(!I||I.type!==z.listType)&&(I={type:z.listType,numbering:us(s,z.listType)});let le=Vr(s,j,I.numbering);le&&C.changes.push(le);}else I=null;}if(S){let F=ot(s),z=C.changes.filter(j=>j.kind==="text"&&(j.op==="insert"||j.op==="replace")&&j.text.length>0).map(j=>$t(s,j.paraId,j.offset,j.offset+j.text.length,{revisionId:F,revisionKind:"insert",author:"User",date:new Date().toISOString()})).filter(j=>j!==null);C.changes.push(...z);}ai(s);let T=C.paragraphIds.map(F=>Z(s,F)).filter(F=>F!==null).map(he),P={source:"local",range:c,beforeParagraphs:k,afterParagraphs:T,changesStart:u.length,changes:C.changes};return u.push(...C.changes),U.push(P),X.length=0,$=null,g=null,Bt(P,T,C.cursor)?De(k[0].paraId,C.cursor):Re(C.cursor),ie(v({kind:"caret"},C.cursor)),Te("deferred"),true},Wa=(c,m,x={})=>{var j,re;let k=Ma(c);if(!k)return false;let C=xs(s,c.anchor,c.focus,"");if(!C)return false;for(let le of C.paragraphIds)b.add(le);let I=Zc(s,C.cursor.paraId,C.cursor.offset,m,x);if(!I||I.kind!=="image")return false;let T=[...C.changes,I];if(S){let le=ot(s),xe=(j=Z(s,I.paraId))==null?void 0:j.content.find(Pe=>Pe.kind==="image"&&Pe.drawingId===I.drawingId);(xe==null?void 0:xe.kind)==="image"&&(xe.revision={kind:"revision",id:`revision:${le}`,revisionId:le,revisionKind:"insert",author:"User",date:new Date().toISOString()},T.push({kind:"image",op:"insert",paraId:I.paraId,offset:I.offset,drawingId:I.drawingId,revisionId:le,revisionKind:"insert"}));}let P={paraId:C.cursor.paraId,offset:C.cursor.offset+1},M=C.paragraphIds.map(le=>Z(s,le)).filter(le=>le!==null).map(he),F=v({source:"local",patchMode:"individual",deferLayoutReflow:true,range:c,beforeParagraphs:k,afterParagraphs:M,changesStart:u.length,changes:T},x.select?{beforeSelection:c.anchor.paraId===c.focus.paraId&&c.anchor.offset===c.focus.offset?v({kind:"caret"},c.anchor):{kind:"text-range",anchor:c.anchor,focus:c.focus},afterSelection:{kind:"object",paraId:C.cursor.paraId,objectKind:"image",objectId:I.drawingId,offset:C.cursor.offset}}:{});u.push(...T),U.push(F),X.length=0,g=x.select?{paraId:C.cursor.paraId,drawingId:I.drawingId}:null,$=null;let z=(re=Z(s,I.paraId))==null?void 0:re.content.find(le=>le.kind==="image"&&le.drawingId===I.drawingId);return (!z||z.kind!=="image"||!Lh(c,z,P))&&(Bt(F,M,P)||Re(P)),Lo(k[0].paraId),g&&_t(),ie(g?{kind:"object",paraId:g.paraId,objectKind:"image",objectId:g.drawingId,offset:C.cursor.offset}:v({kind:"caret"},P)),Te("deferred"),true},Lh=(c,m,x)=>{if(c.anchor.paraId!==c.focus.paraId)return false;let k=Os(e,c.anchor,c.focus);if(!k)return false;let C=e.querySelector(`coco-word-native-p[data-para-id="${c.anchor.paraId}"]`);return !C||!C.contains(k.commonAncestorContainer)?false:(k.deleteContents(),k.insertNode(Ds(m)),dt(e,x),true)},Nr=()=>{let c="";do w=w+1>>>0,c=w.toString(16).toUpperCase().padStart(8,"0");while(!c||b.has(c));return b.add(c),c},Ba=(c,m=Nr())=>{let x=Z(s,c.paraId);if(!x)return false;let k=he(x),C=ks(s,c.paraId,c.offset,m);if(!C)return false;let I=[c.paraId,m].map(M=>Z(s,M)).filter(M=>M!==null).map(he);if(I.length!==2)return false;let T={paraId:m,offset:0},P={source:"local",skipDeferredRender:true,range:{anchor:c,focus:c},beforeParagraphs:[k],afterParagraphs:I,changesStart:u.length,changes:[C]};return u.push(C),U.push(P),X.length=0,$=null,g=null,Bt(P,I,T)?De(c.paraId,T):Re(T),ie(v({kind:"caret"},T)),Te("deferred"),true},ld=c=>{if(c.offset!==0)return false;let m=ye(s,c.paraId),x=m==null?void 0:m.previous;if(!m||!x)return false;let k=[he(x),he(m.paragraph)],C={paraId:x.paraId,offset:Ne(x).length},I=u.length,T=Or(s,c.paraId,0),P=Z(s,x.paraId);if(!T||T.kind!=="block"||!P)return false;let M={source:"local",skipDeferredRender:true,range:{anchor:c,focus:c},beforeParagraphs:k,afterParagraphs:[he(P)],changesStart:I,changes:[T]};return u.push(T),U.push(M),X.length=0,$=null,g=null,Bt(M,M.afterParagraphs,C)?De(x.paraId,C):Re(C),ie(v({kind:"caret"},C)),Te("deferred"),true},dd=c=>{let m=ye(s,c.paraId);if(!m||c.offset!==Ne(m.paragraph).length)return false;let x=m.container[m.index+1];if((x==null?void 0:x.kind)!=="paragraph")return false;let k=[he(m.paragraph),he(x)],C=u.length,I=$r(s,c.paraId,c.offset),T=Z(s,c.paraId);if(!I||I.kind!=="block"||!T)return false;let P={source:"local",skipDeferredRender:true,range:{anchor:c,focus:c},beforeParagraphs:k,afterParagraphs:[he(T)],changesStart:C,changes:[I]};return u.push(I),U.push(P),X.length=0,$=null,g=null,Bt(P,P.afterParagraphs,c)?De(c.paraId,c):Re(c),ie(v({kind:"caret"},c)),Te("deferred"),true},wt=(c,m,x,k=false)=>{if(x.length===0||m.length===0)return false;let C=m.map(M=>Z(s,M.paraId)).filter(M=>M!==null).map(he),T={source:"local",patchMode:"individual",range:c.kind==="text-range"?nt(s,c):c.kind==="table-cell-range"?{anchor:{paraId:m[0].paraId,offset:0},focus:{paraId:m[m.length-1].paraId,offset:Ne(m[m.length-1]).length}}:{anchor:{paraId:c.paraId,offset:c.offset},focus:{paraId:c.paraId,offset:c.offset}},beforeParagraphs:m,afterParagraphs:C,changesStart:u.length,changes:x,beforeSelection:c,afterSelection:c};u.push(...x),U.push(T),X.length=0,$=null,Bt(T,C)||Re();let P=e.querySelector(":scope > coco-word-native-document");if(P&&yn(P),c.kind==="text-range"?vn(e,c.anchor,c.focus):c.kind==="object"?(g={paraId:c.paraId,drawingId:c.objectId},_t()):c.kind==="caret"&&dt(e,{paraId:c.paraId,offset:c.offset}),k){let M=c.kind==="caret"||c.kind==="object"?{paraId:c.paraId,offset:c.offset}:void 0;De(m[0].paraId,M,c);}return c.kind==="object"&&g&&_t(),ie(c),Te("deferred"),true},cd=(c,m)=>{if(c.length===0)return 0;let x=Array.from(new Set(c.map(z=>z.paraId))),k=x.map(z=>Z(s,z)).filter(z=>z!==null).map(he);if(k.length===0)return 0;let C=u.length,I=[],T=[...c].sort((z,j)=>z.paraId===j.paraId?j.from-z.from:x.indexOf(j.paraId)-x.indexOf(z.paraId));for(let z of T)I.push(...zr(s,z.paraId,z.from,z.to,m));if(I.length===0)return 0;let P=k.map(z=>Z(s,z.paraId)).filter(z=>z!==null).map(he),M=c[0],F=v({source:"local",patchMode:"individual",range:{anchor:{paraId:M.paraId,offset:M.from},focus:{paraId:M.paraId,offset:M.to}},beforeParagraphs:k,afterParagraphs:P,changesStart:C,changes:I},h?{beforeSelection:h,afterSelection:h}:{});return u.push(...I),U.push(F),X.length=0,$=null,Bt(F,P)?Ft(h):Re(void 0,h!=null?h:void 0),De(M.paraId),Te(),c.length},Wh=c=>{if(d)return false;let m=E&&E.activeIndex>=0?E.matches[E.activeIndex]:null;return m?cd([m],c)>0:false},Bh=c=>d?0:E?cd(E.matches,c):0,Se=c=>{var x,k,C,I,T,P,M,F,z,j,re,le,xe,Pe;if(l||d)return false;ut();let m=(x=h!=null?h:Ve(e))!=null?x:lt(e);if(c.kind==="toggle-track-revisions")return S=!S,Pa(),true;if(c.kind==="accept-revision"||c.kind==="reject-revision"||c.kind==="accept-all-revisions"||c.kind==="reject-all-revisions"){let K=c.kind==="accept-revision"||c.kind==="reject-revision"?c.revisionId:void 0,J=c.kind==="accept-revision"||c.kind==="reject-revision"?c.revisionKind:void 0,Q=c.kind==="accept-all-revisions"||c.kind==="reject-all-revisions",ne=new Set(U.flatMap(fe=>ar(fe)?fe.changes.filter(be=>be.kind==="table"&&!!(be.revisionAction&&be.revisionId)).map(be=>be.revisionId):[])),ue=fe=>(fe&&Q&&Se(c),fe),ce=U.filter(fe=>ar(fe)&&fe.changes.some(be=>be.kind==="table"&&!be.revisionAction&&!!be.revisionId&&!ne.has(be.revisionId))&&fe.afterBlocks.some(be=>{var Ie,ae,Ke;if(be.kind!=="table"||((Ie=be.revision)==null?void 0:Ie.kind)!=="revision"||ne.has(be.revision.revisionId))return false;let We=(Ke=(ae=Oe(s,be.tableId))==null?void 0:ae.table.revision)==null?void 0:Ke.revisionId;return Q?!!We:We===be.revision.revisionId&&be.revision.revisionId===K&&(!J||be.revision.revisionKind===J)}));if(ce.length>0){let fe=c.kind==="accept-revision"||c.kind==="accept-all-revisions"?"accept":"reject",be=new Map;for(let We of ce){let Ie=We.afterBlocks.find(Ke=>{var je;return Ke.kind==="table"&&((je=Ke.revision)==null?void 0:je.kind)==="revision"});if(!Ie||Ie.kind!=="table"||!Ie.revision)continue;let ae=(k=be.get(Ie.tableId))!=null?k:[];ae.push(We),be.set(Ie.tableId,ae);}for(let[We,Ie]of be){let ae=Ie[Ie.length-1];if(!ae)continue;let Ke=ae.afterBlocks.find(Ko=>{var Xn;return Ko.kind==="table"&&((Xn=Ko.revision)==null?void 0:Xn.kind)==="revision"});if(!Ke||Ke.kind!=="table"||!Ke.revision)continue;let je=Oe(s,We);if(!je)continue;let tn=[rt([je.table])[0]],Rn=rt([je.table])[0];if(!Rn||Rn.kind!=="table")continue;fe==="accept"&&(Rn.revision=void 0,je.table.revision=void 0);let qn=fe==="accept"?[Rn]:rt((I=(C=Ie[0])==null?void 0:C.beforeBlocks)!=null?I:ae.beforeBlocks);fe==="reject"&&je.container.splice(je.tableIndex,1,...rt(qn));let Uo=Ie.flatMap(Ko=>Ko.changes.filter(Xn=>Xn.kind==="table").map(Xn=>H(v({},Xn),{revisionAction:fe}))),za={source:"local",range:ae.range,container:je.container,startIndex:je.tableIndex,beforeBlocks:tn,afterBlocks:qn,changesStart:u.length,changes:Uo,beforeSelection:m!=null?m:void 0,afterSelection:m!=null?m:void 0};u.push(...za.changes),U.push(za),X.length=0,Dt(za,qn,void 0)?De(((T=tn[0])==null?void 0:T.kind)==="paragraph"?tn[0].paraId:(z=(F=(M=(P=je.table.rows[0])==null?void 0:P.cells[0])==null?void 0:M.paragraphs[0])==null?void 0:F.paraId)!=null?z:"",void 0):Re(),Te("deferred");}return ue(true)}let Y=_e(s).flatMap(fe=>{var Ie;let be=0,We=[];for(let ae of fe.content)ae.kind==="image"&&(((Ie=ae.revision)==null?void 0:Ie.kind)==="revision"&&(Q||ae.revision.revisionId===K&&(!J||ae.revision.revisionKind===J))||ae.formatRevision&&(Q||ae.formatRevision.revisionId===K&&(!J||J==="format")))&&We.push({paraId:fe.paraId,drawingId:ae.drawingId,offset:be}),be+=ae.kind==="text"?ae.text.length:1;return We});if(Y.length>0){let fe=c.kind==="accept-revision"||c.kind==="accept-all-revisions"?"accept":"reject",be=Array.from(new Set(Y.map(ae=>ae.paraId))).map(ae=>Z(s,ae)).filter(ae=>ae!==null).map(he),We=Y.map(ae=>{var je;let Ke=(je=Z(s,ae.paraId))==null?void 0:je.content.find(tn=>tn.kind==="image"&&tn.drawingId===ae.drawingId);return (Ke==null?void 0:Ke.kind)==="image"&&Ke.formatRevision?fu(s,ae.paraId,ae.drawingId,fe):uu(s,ae.paraId,ae.drawingId,fe)}).filter(ae=>ae!==null);if(We.length===0)return false;let Ie=Y[0];return ue(wt({kind:"caret",paraId:Ie.paraId,offset:Ie.offset},be,We,true))}let Ee=_e(s).flatMap(fe=>{let be=0,We=[];for(let Ie of fe.content){let ae=Ie.kind==="text"?Ie.text.length:1;Ie.kind==="text"&&Ie.formatRevision&&(Q||Ie.formatRevision.revisionId===K&&(!J||J==="format"))&&We.push({paraId:fe.paraId,from:be,to:be+ae}),be+=ae;}return We});if(Ee.length>0){let fe=c.kind==="accept-revision"||c.kind==="accept-all-revisions"?"accept":"reject",be=Array.from(new Set(Ee.map(ae=>ae.paraId))).map(ae=>Z(s,ae)).filter(ae=>ae!==null).map(he),We=Ee.map(ae=>su(s,ae.paraId,ae.from,ae.to,fe)).filter(ae=>ae!==null);if(We.length===0)return false;let Ie=Ee[0];return ue(wt({kind:"caret",paraId:Ie.paraId,offset:Ie.from},be,We,true))}let He=Q?_e(s).flatMap(fe=>{var Ie;let be=[],We=0;for(let ae of fe.content){let Ke=ae.kind==="text"?ae.text.length:1;ae.kind==="text"&&((Ie=ae.marks)!=null&&Ie.some(je=>je.kind==="revision"))&&be.push({paraId:fe.paraId,from:We,to:We+Ke}),We+=Ke;}return be}):K?_e(s).flatMap(fe=>{var Ie;let be=[],We=0;for(let ae of fe.content){let Ke=ae.kind==="text"?ae.text.length:1;ae.kind==="text"&&((Ie=ae.marks)!=null&&Ie.some(je=>je.kind==="revision"&&je.revisionId===K&&(!J||je.revisionKind===J)))&&be.push({paraId:fe.paraId,from:We,to:We+Ke}),We+=Ke;}return be}):en(m);if(He.length===0)return false;(Q||K)&&He.sort((fe,be)=>fe.paraId===be.paraId?be.from-fe.from||be.to-fe.to:be.paraId.localeCompare(fe.paraId));let ge=He.map(fe=>Z(s,fe.paraId)).filter(fe=>fe!==null).map(he),Fe=c.kind==="accept-revision"||c.kind==="accept-all-revisions"?"accept":"reject",de=He.map(fe=>au(s,fe.paraId,fe.from,fe.to,Fe)).filter(fe=>fe!==null);if(de.length===0)return false;let Je=m!=null?m:{kind:"caret",paraId:He[0].paraId,offset:He[0].from};return ue(wt(Je,ge,de,false))}if(c.kind==="insert-text"&&(m==null?void 0:m.kind)==="caret"){let K={paraId:m.paraId,offset:m.offset+c.text.length};return Pn({anchor:m,focus:m},m,K,()=>{var ne;let J=on(s,m.paraId,m.offset,c.text);if(!S||!J||c.text.length===0)return J;let Q=$t(s,m.paraId,m.offset,K.offset,{revisionId:(ne=kr(m.paraId,m.offset,"insert","before"))!=null?ne:ot(s),revisionKind:"insert",author:"User",date:new Date().toISOString()});return Q?[J,Q]:J})}if(c.kind==="replace-range"&&c.anchor.paraId===c.focus.paraId){let K=Ri(c.anchor.offset,c.focus.offset),J={kind:"text-range",anchor:c.anchor,focus:c.focus};return S?Pn({anchor:c.anchor,focus:c.focus},J,{paraId:c.anchor.paraId,offset:K.to+c.text.length},()=>{let Q=[],ne=$t(s,c.anchor.paraId,K.from,K.to,{revisionId:ot(s),revisionKind:"delete",author:"User",date:new Date().toISOString()});if(ne&&Q.push(ne),c.text.length>0){let ue=on(s,c.anchor.paraId,K.to,c.text);ue&&Q.push(ue);let ce=$t(s,c.anchor.paraId,K.to,K.to+c.text.length,{revisionId:ot(s),revisionKind:"insert",author:"User",date:new Date().toISOString()});ce&&Q.push(ce);}return Q}):Pn({anchor:c.anchor,focus:c.focus},J,{paraId:c.anchor.paraId,offset:K.from+c.text.length},()=>zr(s,c.anchor.paraId,K.from,K.to,c.text))}if(c.kind==="delete-range"&&S){let K={kind:"text-range",anchor:c.anchor,focus:c.focus},J=en(K);if(J.length===0)return false;let Q=Array.from(new Map(J.map(Y=>Z(s,Y.paraId)).filter(Y=>Y!==null).map(Y=>[Y.paraId,he(Y)])).values()),ne=ot(s),ue=J.map(Y=>$t(s,Y.paraId,Y.from,Y.to,{revisionId:ne,revisionKind:"delete",author:"User",date:new Date().toISOString()})).filter(Y=>Y!==null);if(ue.length===0)return false;let ce=wt(K,Q,ue,false);if(ce){let Y=nt(s,K),Ee={paraId:Y.anchor.paraId,offset:Y.anchor.offset};dt(e,Ee),ie(v({kind:"caret"},Ee));}return ce}if(c.kind==="delete-range"&&c.anchor.paraId===c.focus.paraId){let K={kind:"text-range",anchor:c.anchor,focus:c.focus};if($o(K))return true;let J=Ri(c.anchor.offset,c.focus.offset);return S?Pn({anchor:c.anchor,focus:c.focus},K,{paraId:c.anchor.paraId,offset:J.from},()=>{var Q;return $t(s,c.anchor.paraId,J.from,J.to,{revisionId:(Q=kr(c.anchor.paraId,J.from,"delete","at"))!=null?Q:ot(s),revisionKind:"delete",author:"User",date:new Date().toISOString()})}):Pn({anchor:c.anchor,focus:c.focus},K,{paraId:c.anchor.paraId,offset:J.from},()=>bn(s,c.anchor.paraId,J.from,J.to))}if(c.kind==="split-paragraph"&&(m==null?void 0:m.kind)==="caret")return Ba({paraId:m.paraId,offset:m.offset});if(c.kind==="insert-page-break"&&(m==null?void 0:m.kind)==="caret")return Tn(m,"insert");if(c.kind==="insert-image"&&m&&(m.kind==="caret"||m.kind==="text-range")){let K=m.kind==="text-range"?nt(s,m):{anchor:{paraId:m.paraId,offset:m.offset},focus:{paraId:m.paraId,offset:m.offset}};return Wa(K,c.src,H(v(v({},c.width?{width:c.width}:{}),c.height?{height:c.height}:{}),{select:true}))}if(c.kind==="set-image-size"&&(m==null?void 0:m.kind)==="object"&&m.objectKind==="image"&&m.objectId===c.objectId){let K=Z(s,m.paraId);if(!K)return false;let J=he(K),Q=K.content.find(Y=>Y.kind==="image"&&Y.drawingId===m.objectId),ne=(Q==null?void 0:Q.kind)==="image"?Q.width:void 0,ue=(Q==null?void 0:Q.kind)==="image"?Q.height:void 0,ce=eu(s,m.paraId,m.objectId,{width:c.width,height:c.height});if(S&&ce){let Y=K.content.find(Ee=>Ee.kind==="image"&&Ee.drawingId===m.objectId);(Y==null?void 0:Y.kind)==="image"&&(Y.formatRevision={kind:"format",revisionId:ot(s),beforeWidth:ne,beforeHeight:ue,afterWidth:c.width,afterHeight:c.height,author:"User",date:new Date().toISOString()},ce.kind==="image"&&(ce.revisionId=Y.formatRevision.revisionId,ce.revisionKind="format"));}return wt(m,[J],ce?[ce]:[],true)}if(c.kind==="set-image-alignment"&&(m==null?void 0:m.kind)==="object"&&m.objectKind==="image"&&m.objectId===c.objectId)return Se({kind:"set-paragraph-alignment",alignment:c.alignment});if(m&&(c.kind==="insert-table"||c.kind==="delete-table"))return Ph(m,c);if(m&&(c.kind==="insert-table-row"||c.kind==="delete-table-row"||c.kind==="insert-table-column"||c.kind==="delete-table-column"))return Nh(m,c);if((m==null?void 0:m.kind)==="table-cell-range"&&(c.kind==="merge-table-cells"||c.kind==="split-table-cell"))return Th(m,c);if(m&&(c.kind==="set-table-cell-background"||c.kind==="set-table-cell-vertical-alignment"||c.kind==="set-table-cell-borders"))return Rh(m,c);if(c.kind==="clear-table-cells"&&(m==null?void 0:m.kind)==="table-cell-range")return Kn(m);if(c.kind==="delete-backward"){if((m==null?void 0:m.kind)==="table-cell-range")return Kn(m);if((m==null?void 0:m.kind)==="text-range")return $o(m)?true:S?Se({kind:"delete-range",anchor:m.anchor,focus:m.focus}):_n(nt(s,m),"");if((m==null?void 0:m.kind)==="object"&&m.objectKind==="image"){let K={paraId:m.paraId,offset:m.offset};return Nn(m.paraId,m.objectId,K)}if((m==null?void 0:m.kind)==="caret"){if(S&&m.offset>0){let ue=m.offset-1;return Pn({anchor:m,focus:m},m,{paraId:m.paraId,offset:ue},()=>{var ce;return $t(s,m.paraId,ue,m.offset,{revisionId:(ce=kr(m.paraId,ue,"delete","after"))!=null?ce:ot(s),revisionKind:"delete",author:"User",date:new Date().toISOString()})})}if(Tn(m,"delete-backward")||zo(m,"backward")||ld({paraId:m.paraId,offset:m.offset}))return true;let K=Z(s,m.paraId),J=K?he(K):null,Q=Or(s,m.paraId,m.offset),ne={paraId:m.offset>0?m.paraId:(j=ss(s,m.paraId))!=null?j:m.paraId,offset:Math.max(0,m.offset-1)};return (Q==null?void 0:Q.kind)==="image"?Ir(J,Q,ne):In(Q,ne,(Q==null?void 0:Q.kind)==="block"?{}:{localParaId:m.paraId}),true}}if(c.kind==="delete-forward"&&(m==null?void 0:m.kind)==="table-cell-range")return Kn(m);if(c.kind==="delete-forward"&&(m==null?void 0:m.kind)==="text-range")return $o(m)?true:S?Se({kind:"delete-range",anchor:m.anchor,focus:m.focus}):_n(nt(s,m),"");if(c.kind==="delete-forward"&&(m==null?void 0:m.kind)==="caret"){if(S&&m.offset<Ra(m.paraId))return Pn({anchor:m,focus:m},m,m,()=>{var ue;return $t(s,m.paraId,m.offset,m.offset+1,{revisionId:(ue=kr(m.paraId,m.offset,"delete","at"))!=null?ue:ot(s),revisionKind:"delete",author:"User",date:new Date().toISOString()})});if(Tn(m,"delete-forward")||zo(m,"forward")||dd({paraId:m.paraId,offset:m.offset}))return true;let K=Z(s,m.paraId),J=K?he(K):null,Q=$r(s,m.paraId,m.offset),ne={paraId:m.paraId,offset:m.offset};return (Q==null?void 0:Q.kind)==="image"?Ir(J,Q,ne):In(Q,ne,{localParaId:m.paraId}),true}if(c.kind==="delete-object"&&(m==null?void 0:m.kind)==="object"){let K={paraId:m.paraId,offset:m.offset};return Nn(m.paraId,c.objectId,K)}if((c.kind==="set-hyperlink"||c.kind==="remove-hyperlink")&&(m==null?void 0:m.kind)==="text-range"){let K=en(m),J=K.map(ne=>Z(s,ne.paraId)).filter(ne=>ne!==null).map(he),Q=K.map(ne=>Ss(s,ne.paraId,ne.from,ne.to,c.kind==="set-hyperlink"?c.hyperlink:null)).filter(ne=>ne!==null);return wt(m,J,Q,false)}if(c.kind==="add-comment"&&(m==null?void 0:m.kind)==="text-range"){let K=en(m);if(K.length===0||!c.body.trim())return false;let J=K.map(Y=>Z(s,Y.paraId)).filter(Y=>Y!==null).map(he),Q=pp(s),ne=(re=c.date)!=null?re:new Date().toISOString(),ue=K.map(Y=>{var Ee;return vs(s,Y.paraId,Y.from,Y.to,{commentId:Q,author:(Ee=c.author)!=null?Ee:"User",date:ne,body:c.body.trim()})}).filter(Y=>Y!==null),ce=wt(m,J,ue,false);return ce&&ue.length>1&&Re(),ce}if(c.kind==="edit-comment"||c.kind==="delete-comment"){if(c.kind==="edit-comment"&&!c.body.trim())return false;let K=_e(s).filter(ne=>ne.content.some(ue=>{var ce;return ue.kind==="text"&&((ce=ue.marks)==null?void 0:ce.some(Y=>Y.kind==="comment"&&Y.commentId===c.commentId))})).map(he);if(K.length===0)return false;let J=c.kind==="edit-comment"?ou(s,c.commentId,c.body.trim()):iu(s,c.commentId);if(J.length===0)return false;let Q=m!=null?m:{kind:"caret",paraId:K[0].paraId,offset:0};return wt(Q,K,J,false)}if(c.kind==="reply-comment"){let K=c.body.trim();if(!K)return false;let J=null;for(let ce of _e(s)){let Y=0;for(let Ee of ce.content){let He=Ee.kind==="text"?Ee.text.length:1;if(Ee.kind==="text"&&((le=Ee.marks)!=null&&le.some(ge=>ge.kind==="comment"&&ge.commentId===c.commentId))){J={paragraph:ce,from:Y,to:Y+He};break}Y+=He;}if(J)break}if(!J)return false;let Q=he(J.paragraph),ne=pp(s),ue=vs(s,J.paragraph.paraId,J.from,J.to,{commentId:ne,parentCommentId:c.commentId,preserveExistingComments:true,author:"User",date:new Date().toISOString(),body:K});return ue?(Re(),wt(m!=null?m:{kind:"caret",paraId:J.paragraph.paraId,offset:J.from},[Q],[ue],false)):false}if(c.kind==="add-revision"&&(m==null?void 0:m.kind)==="text-range"){let K=en(m);if(K.length===0)return false;let J=K.map(ce=>Z(s,ce.paraId)).filter(ce=>ce!==null).map(he),Q=ot(s),ne=(xe=c.date)!=null?xe:new Date().toISOString(),ue=K.map(ce=>{var Y;return $t(s,ce.paraId,ce.from,ce.to,{revisionId:Q,revisionKind:c.revisionKind,author:(Y=c.author)!=null?Y:"User",date:ne})}).filter(ce=>ce!==null);return wt(m,J,ue,false)}if(c.kind==="toggle-bold"||c.kind==="toggle-italic"||c.kind==="toggle-underline"||c.kind==="toggle-strike"||c.kind==="set-font-family"||c.kind==="set-font-size"||c.kind==="set-text-color"||c.kind==="set-highlight-color"||c.kind==="clear-text-format"){let K=en(m);if((m==null?void 0:m.kind)!=="text-range"||K.length===0)return false;let J=K.map(Y=>Z(s,Y.paraId)).filter(Y=>Y!==null).map(he),Q=Rt(m),ne=null;if(c.kind==="toggle-bold"&&(ne={bold:Q.bold!==true}),c.kind==="toggle-italic"&&(ne={italic:Q.italic!==true}),c.kind==="toggle-underline"&&(ne={underline:Q.underline!==true}),c.kind==="toggle-strike"&&(ne={strike:Q.strike!==true}),c.kind==="set-font-family"&&c.fontFamily.trim()&&(ne={fontFamily:c.fontFamily.trim()}),c.kind==="set-font-size"&&(ne={fontSize:c.fontSize}),c.kind==="set-text-color"&&(ne={color:c.color.replace(/^#/,"").toUpperCase()}),c.kind==="set-highlight-color"&&(ne={highlight:c.color?c.color.replace(/^#/,"").toUpperCase():"none"}),c.kind!=="clear-text-format"&&!ne)return false;let ue=K.map(Y=>c.kind==="clear-text-format"?lu(s,Y.paraId,Y.from,Y.to):ys(s,Y.paraId,Y.from,Y.to,ne)).filter(Y=>Y!==null);if(S){let Y=ot(s),Ee=K.map(He=>cu(s,He.paraId,He.from,He.to,J.find(ge=>ge.paraId===He.paraId),{revisionId:Y,author:"User",date:new Date().toISOString()})).filter(He=>He!==null);ue.push(...Ee);}let ce=c.kind==="toggle-bold"||c.kind==="toggle-italic"||c.kind==="set-font-family"||c.kind==="set-font-size"||c.kind==="clear-text-format";return wt(m,J,ue,ce)}if(c.kind==="set-paragraph-alignment"||c.kind==="set-paragraph-indent"||c.kind==="adjust-paragraph-left-indent"||c.kind==="set-paragraph-spacing"||c.kind==="set-paragraph-line-spacing"){let K=Array.from(new Set(id(m)));if(!m||K.length===0)return false;let J=K.map(ne=>Z(s,ne)).filter(ne=>ne!==null).map(he),Q=K.map(ne=>{var ce,Y,Ee;let ue=Z(s,ne);if(!ue)return null;if(c.kind==="set-paragraph-alignment")return Jn(s,ne,{alignment:c.alignment});if(c.kind==="set-paragraph-indent")return Jn(s,ne,{indent:jv(c.indent)});if(c.kind==="adjust-paragraph-left-indent"){let He=Math.max(0,((Ee=(Y=(ce=ue.format)==null?void 0:ce.indent)==null?void 0:Y.left)!=null?Ee:0)+c.delta);return Jn(s,ne,{indent:{left:He}})}return c.kind==="set-paragraph-spacing"?Jn(s,ne,{spacing:Uv(c.spacing)}):Jn(s,ne,{spacing:{line:Math.max(0,c.line),lineRule:c.lineRule}})}).filter(ne=>ne!==null);return wt(m,J,Q,c.kind!=="set-paragraph-alignment")}if(c.kind==="toggle-list"||c.kind==="remove-list"||c.kind==="adjust-list-level"){let K=Array.from(new Set(id(m)));if(!m||K.length===0)return false;let J=K.map(Y=>Z(s,Y)).filter(Y=>Y!==null),Q=J.map(he),ne=c.kind==="toggle-list"&&J.every(Y=>{var Ee;return ((Ee=Y.format)==null?void 0:Ee.hasNumbering)&&hn(Y.format.numbering)===c.listType}),ue=c.kind==="toggle-list"&&!ne?(Pe=Fc(s,K,c.listType))!=null?Pe:us(s,c.listType):null,ce=J.map(Y=>{var Ee,He,ge,Fe,de;if(c.kind==="remove-list"||ne)return (Ee=Y.format)!=null&&Ee.hasNumbering?Vr(s,Y.paraId,null):null;if(c.kind==="toggle-list"&&ue){let Je=(Fe=(ge=(He=Y.format)==null?void 0:He.numbering)==null?void 0:ge.ilvl)!=null?Fe:0;return Vr(s,Y.paraId,fs(ue,Je))}if(c.kind==="adjust-list-level"){let Je=(de=Y.format)!=null&&de.hasNumbering?Y.format.numbering:void 0;return Je?Vr(s,Y.paraId,fs(Je,Je.ilvl+c.delta)):null}return null}).filter(Y=>Y!==null);return ai(s),wt(m,Q,ce,true)}return false},ud=c=>{var P;let m=(P=Oe(s,c.tableId))==null?void 0:P.table;if(!m)return null;let x=Math.min(c.anchor.rowIndex,c.focus.rowIndex),k=Math.max(c.anchor.rowIndex,c.focus.rowIndex),C=Math.min(c.anchor.columnIndex,c.focus.columnIndex),I=Math.max(c.anchor.columnIndex,c.focus.columnIndex),T=Array.from({length:k-x+1},()=>Array.from({length:I-C+1},()=>null));for(let{cell:M,rowIndex:F,columnIndex:z}of tt(m,c)){let j=T[F-x];j&&z>=C&&z<=I&&(j[z-C]={text:M.paragraphs.map(re=>Ne(re)).join(`
1544
- `),blocks:rt(M.blocks),format:Dh(M)});}return {version:1,cells:T}},Dh=c=>JSON.parse(JSON.stringify(v(v(v(v(v({},c.margin?{margin:c.margin}:{}),c.borders?{borders:c.borders}:{}),c.shading?{shading:c.shading}:{}),c.verticalAlignment?{verticalAlignment:c.verticalAlignment}:{}),c.noWrap!==void 0?{noWrap:c.noWrap}:{}))),fd=c=>c.cells.map(m=>m.map(x=>{var k;return ((k=x==null?void 0:x.text)!=null?k:"").replace(/[\t\r\n]+/g," ")}).join(" ")).join(`
1545
- `),Fh=c=>{var x,k;let m=(k=(x=c.clipboardData)==null?void 0:x.getData(al))!=null?k:"";if(!m)return null;try{let C=JSON.parse(m);if(C.version===1&&Array.isArray(C.cells)&&C.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 C}catch(C){return null}return null},Hh=c=>{var k,C;let m=(C=(k=c.clipboardData)==null?void 0:k.getData("text/plain"))!=null?C:"";if(!m)return [];let x=m.replace(/\r\n?/g,`
1592
+ ${(Wd=n.styleText)!=null?Wd:ap}`,o.appendChild(c);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 a=t,s=ss(a),l=false,d=n.readOnly===true,u=[],f=[],p=0,b=new Set(_e(s).map(c=>c.paraId)),w=Date.now()>>>0,g=null,h=null,y=null,S=n.trackRevisions===true,k=null,I=false,A=null,F=null,L=null,V=null,ee=null,fe=null,ae=null,oe=null,ie=false,U=null,J=null,B=null,G=null,$=null,K=[],X=[],Se=new WeakSet,Ce=false,We=false,Ge=false,et=false,kt={change:new Set,selectionChange:new Set},fn=(c,m)=>{for(let x of kt[c])x(m);},ut=()=>lo.set(document,e),Rt=c=>O(v({},cp(s,c)),{trackRevisions:S}),mt=null,Ze=null,Kt=null,ft=null,Qt=false,Kn=false,ht=()=>{Kt==null||Kt.remove(),Kt=null;},In=c=>{var N;if(!(c instanceof Element))return null;let m=c.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]"),C=Number(m==null?void 0:m.dataset.rowIndex),E=Number(m==null?void 0:m.dataset.columnIndex);return !m||!x||!Number.isInteger(C)||!Number.isInteger(E)?null:{tableId:(N=x.dataset.tableId)!=null?N:"",point:{rowIndex:C,columnIndex:E},element:m}},Nn=c=>{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((c==null?void 0:c.kind)!=="table-cell-range")return;let m=Array.from(e.querySelectorAll("coco-word-native-table[data-table-id]")).find(T=>T.dataset.tableId===c.tableId);if(!m)return;let x=Math.min(c.anchor.rowIndex,c.focus.rowIndex),C=Math.max(c.anchor.rowIndex,c.focus.rowIndex),E=Math.min(c.anchor.columnIndex,c.focus.columnIndex),N=Math.max(c.anchor.columnIndex,c.focus.columnIndex);for(let T of Array.from(m.querySelectorAll("td[data-row-index][data-column-index]"))){let P=Number(T.dataset.rowIndex),M=Number(T.dataset.columnIndex),H=P+Math.max(1,T.rowSpan)-1,z=M+Math.max(1,T.colSpan)-1;P<=C&&H>=x&&M<=N&&z>=E&&(T.classList.add("is-cell-range-selected"),T.setAttribute("aria-selected","true"),P===c.anchor.rowIndex&&M===c.anchor.columnIndex&&T.classList.add("is-cell-range-anchor"),P===c.focus.rowIndex&&M===c.focus.columnIndex&&T.classList.add("is-cell-range-focus"));}},gt=++Ov,va=`coco-word-search-match-${gt}`,Sa=`coco-word-search-active-${gt}`,ka=`coco-word-preserved-selection-${gt}`,Ca=document.createElement("style");Ca.textContent=`
1593
+ ::highlight(${va}) { background-color: rgb(250 204 21 / 42%); }
1594
+ ::highlight(${Sa}) { background-color: rgb(249 115 22 / 68%); color: inherit; }
1595
+ ::highlight(${ka}) { background-color: rgb(0 120 215 / 34%); color: inherit; }
1596
+ `,(o!=null?o:document.head).appendChild(Ca);let bt=(Bd=globalThis.CSS)==null?void 0:Bd.highlights,kr=globalThis.Highlight,Xl=()=>{bt==null||bt.delete(va),bt==null||bt.delete(Sa);},Ea=()=>{bt==null||bt.delete(ka);},at=(c=false)=>{if(Ea(),(h==null?void 0:h.kind)!=="text-range"||!c&&(document.activeElement===i||e.contains(document.activeElement))||!bt||!kr)return;let m=nt(s,h),x=Os(e,m.anchor,m.focus);x&&!x.collapsed&&bt.set(ka,new kr(x));},Ro=()=>{if(Xl(),!k||!bt||!kr)return;let c=[],m=null;k.matches.forEach((x,C)=>{let E=pf(e,x.paraId,x.from,x.to);E&&(C===k.activeIndex?m=E:c.push(E));}),c.length>0&&bt.set(va,new kr(...c)),m&&bt.set(Sa,new kr(m));},Mo=()=>k?{options:v({},k.options),matches:k.matches.map(c=>v({},c)),activeIndex:k.activeIndex}:null,yh=()=>{if(!k)return;let c=zs(s,k.options);k={options:v({},k.options),matches:c,activeIndex:c.length===0?-1:Math.min(Math.max(0,k.activeIndex),c.length-1)},Ro(),at();},Yl=()=>{let c=k&&k.activeIndex>=0?k.matches[k.activeIndex]:null,m=c?e.querySelector(`coco-word-native-p[data-para-id="${c.paraId}"]`):null;m==null||m.scrollIntoView({block:"center",inline:"nearest"});},vh=c=>{let m={query:c.query,matchCase:!!c.matchCase,wholeWord:!!c.wholeWord},x=zs(s,m);return k={options:m,matches:x,activeIndex:x.length>0?0:-1},Ro(),Yl(),Mo()},Sh=(c="forward")=>{if(!k||k.matches.length===0)return Mo();let m=c==="backward"?-1:1;return k=O(v({},k),{activeIndex:(k.activeIndex+m+k.matches.length)%k.matches.length}),Ro(),Yl(),Mo()},Ia=()=>{k=null,Xl();},_n=()=>{mt==null||mt.remove(),mt=null;},Na=()=>{if(!mt||!g)return;let c=e.querySelector(`coco-word-native-p[data-para-id="${g.paraId}"] img[data-drawing-id="${g.drawingId}"]`);if(!c){_n();return}let m=e.getBoundingClientRect(),x=c.getBoundingClientRect();mt.style.left=`${x.right-m.left+e.scrollLeft-6}px`,mt.style.top=`${x.bottom-m.top+e.scrollTop-6}px`;},_t=()=>{if(d){_n();return}if(!g){_n();return}if(mf(e,g),!!e.querySelector(`coco-word-native-p[data-para-id="${g.paraId}"] img[data-drawing-id="${g.drawingId}"]`)){if(!(mt!=null&&mt.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;ut();let C=v({},g),E=e.querySelector(`coco-word-native-p[data-para-id="${C.paraId}"] img[data-drawing-id="${C.drawingId}"]`);if(!E)return;Ze==null||Ze(),x.preventDefault(),x.stopPropagation(),m.setPointerCapture(x.pointerId);let N=E.getBoundingClientRect(),T=x.clientX,P=x.clientY,M=Math.max(1,N.width),H=Math.max(1,N.height),z=M/H,j=M,re=H,ce=Me=>{let _=Me.clientX-T,Q=Me.clientY-P;if(Me.shiftKey)j=Math.max(24,M+_),re=Math.max(24,H+Q);else {let te=Math.abs(_)>=Math.abs(Q)?_:Q*z;j=Math.max(24,M+te),re=Math.max(24,j/z);}E.style.width=`${j}px`,E.style.height=`${re}px`,Na();},ye=Me=>{Ze==null||Ze(),Ze=null,m.hasPointerCapture(Me.pointerId)&&m.releasePointerCapture(Me.pointerId),ke({kind:"set-image-size",objectId:C.drawingId,width:Math.round(j*100)/100,height:Math.round(re*100)/100});};document.addEventListener("pointermove",ce,true),document.addEventListener("pointerup",ye,true),document.addEventListener("pointercancel",ye,true),Ze=()=>{document.removeEventListener("pointermove",ce,true),document.removeEventListener("pointerup",ye,true),document.removeEventListener("pointercancel",ye,true);};}),e.appendChild(m),mt=m;}Na();}},Ao=()=>Na();window.addEventListener("resize",Ao),document.addEventListener("scroll",Ao,true);let Zl=()=>{if(r.setAttribute("aria-readonly",String(d)),e.dataset.readOnly=String(d),!!d){for(let c of Array.from(e.querySelectorAll('[contenteditable="true"]')))c.contentEditable="false";_n();}},Pe=(c,m)=>{F!==null&&(window.clearTimeout(F),F=null),L!==null&&(window.clearTimeout(L),L=null),si(s);let x=Mu(s);e.replaceChildren(x),Lu(x,s),Zl(),Ra(x);let C=(m==null?void 0:m.kind)==="table-cell-range"?m:(h==null?void 0:h.kind)==="table-cell-range"?h:null;Nn(C),Ro(),at(),g&&_t(),(m==null?void 0:m.kind)==="text-range"?vn(e,m.anchor,m.focus):c&&dt(e,c);},Ta=(c,m)=>{var N;let x=Z(s,c);if(!x){Pe(m);return}let C=Array.from(e.querySelectorAll(`coco-word-native-p[data-para-id="${c}"]`));if(C.length===0){Pe(m);return}for(let T of C)T.replaceWith(Qr(x));Zl();let E=(N=e.querySelector(":scope > coco-word-native-document"))!=null?N:e.querySelector("coco-word-native-document");E&&yn(E),g&&_t(),m&&dt(e,m);},Jl=(c,m)=>c.querySelector(`table[data-shared-grid] coco-word-native-p[data-para-id="${m}"]`)!==null,De=(c,m,x)=>{var N;let C=e.querySelector(":scope > coco-word-native-document");if(!C)return false;if(Jl(C,c)){let T=x!=null?x:m?void 0:(N=ze(e))!=null?N:void 0;return Pe(m!=null?m:(T==null?void 0:T.kind)==="caret"?T:void 0,T),true}let E=Wu(C,s,c);Ra(C);for(let T of Array.from(C.querySelectorAll(`coco-word-native-p[data-para-id="${c}"] img`)))T.complete||Se.has(T)||(Se.add(T),T.addEventListener("load",()=>{Se.delete(T),De(c);},{once:true}));return (x==null?void 0:x.kind)==="text-range"?vn(e,x.anchor,x.focus):m&&dt(e,m),E},pn=(c,m=180,x)=>{ie||oe||(L!==null&&window.clearTimeout(L),L=window.setTimeout(()=>{var N;if(L=null,ie||oe)return;let C=(N=e.querySelector(":scope > coco-word-native-document"))!=null?N:e.querySelector("coco-word-native-document");if(!C||x&&!x(C))return;let E=(h==null?void 0:h.kind)==="object"?h:ze(e);if((E==null?void 0:E.kind)==="text-range")De(c,void 0,E);else if((E==null?void 0:E.kind)==="object")De(c),g={paraId:E.paraId,drawingId:E.objectId},_t();else {let T=(E==null?void 0:E.kind)==="caret"?E:pt(e);De(c,T!=null?T:void 0);}},m));},Lo=(c,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 C=false;for(let N of Array.from(x.querySelectorAll(`coco-word-native-p[data-para-id="${c}"] img`)))N.complete||Se.has(N)||(C=true,Se.add(N),N.addEventListener("load",()=>{Se.delete(N),pn(c,0);},{once:true}),N.addEventListener("error",()=>Se.delete(N),{once:true}));pn(c,C?800:m);},Cr=c=>{var x;if((U==null?void 0:U.paraId)===c)return;let m=(x=e.querySelector(":scope > coco-word-native-document"))!=null?x:e.querySelector("coco-word-native-document");m&&(U={paraId:c,measurement:As(m,s,c)});},Pa=c=>{pn(c,700,m=>{let x=U;if(U=null,!x||x.paraId!==c)return false;if(Jl(m,c))return true;let C=As(m,s,c);return C.overflowPx>Math.max(1,x.measurement.overflowPx+1)||!x.measurement.canBackfillPrevious&&C.canBackfillPrevious||!x.measurement.canBackfillNext&&C.canBackfillNext});},Wo=new WeakMap,Bo=new ResizeObserver(c=>{var m,x;for(let C of c){let E=C.target;if(!(E instanceof HTMLElement))continue;let N=Math.round(C.contentRect.height),T=Wo.get(E);if(Wo.set(E,N),T===void 0||Math.abs(T-N)<=1)continue;let P=(m=E.querySelector("coco-word-native-p[data-para-id]"))==null?void 0:m.dataset.paraId;if(P){let M=document.activeElement;if(M&&E.contains(M)){let H=(x=M.closest("coco-word-native-p[data-para-id]"))==null?void 0:x.dataset.paraId;Pa(H!=null?H:P);}else pn(P);}}}),Ra=c=>{for(let m of Array.from(c.querySelectorAll("coco-word-native-table")))Wo.has(m)||(Wo.set(m,Math.round(m.getBoundingClientRect().height)),Bo.observe(m));},Re=(c="immediate")=>{if(l)return;let m=()=>{var C;yh();let x=hp(f,u,++p);f=u.slice(),(C=n.onChange)==null||C.call(n,x),fn("change",x);};if(c==="immediate"){ee!==null&&(window.clearTimeout(ee),ee=null),m();return}ee!==null&&window.clearTimeout(ee),ee=window.setTimeout(()=>{ee=null,m();},180);},Ma=()=>{l||(fe!==null&&window.clearTimeout(fe),fe=window.setTimeout(()=>{var x,C;fe=null;let c=(x=h!=null?h:ze(e))!=null?x:lt(e),m={selection:c,commandState:Rt(c)};(C=n.onSelectionChange)==null||C.call(n,m),fn("selectionChange",m);},80));},Ql=c=>{B=c,G!==null&&window.clearTimeout(G),G=window.setTimeout(()=>{B=null,G=null;},1e3);},kh=(c,m,x)=>{let C=Array.from(e.querySelectorAll(`coco-word-native-p[data-para-id="${c}"] img[data-drawing-id="${m}"]`));for(let E of C)E.remove();Pt(e),x&&dt(e,x);},Tn=(c,m,x={})=>{Array.isArray(c)?u.push(...c):c&&u.push(c),c&&(X.length=0),x.localParaId?(Ta(x.localParaId,m),pn(x.localParaId)):Pe(m),Re();},Do=c=>{let m=Z(s,c);return !!m&&m.content.every(x=>x.kind==="text")},Aa=c=>{let m=Z(s,c);return m?Te(m).length:0},Er=(c,m,x,C)=>{var P,M;let E=Z(s,c);if(!E)return null;let N=C==="before"?m-1:C==="after"?m+1:m;if(N<0)return null;let T=0;for(let H of E.content){let z=H.kind==="text"?H.text.length:1;if(N>=T&&N<T+z){let j=H.kind==="text"?(P=H.marks)==null?void 0:P.find(re=>re.kind==="revision"&&re.revisionKind===x):void 0;return j&&"revisionId"in j&&(M=j.revisionId)!=null?M:null}T+=z;}return null},ed=(c,m)=>{var x;return !S||!m||m.kind!=="text"||m.op!=="insert"&&m.op!=="replace"||m.text.length===0?null:$t(s,c,m.offset,m.offset+m.text.length,{revisionId:(x=Er(c,m.offset,"insert","before"))!=null?x:ot(s),revisionKind:"insert",author:"User",date:new Date().toISOString()})},La=c=>{let m=ve(s,c.anchor.paraId),x=ve(s,c.focus.paraId);if(!m||!x||m.container!==x.container)return null;let C=Math.min(m.index,x.index),E=Math.max(m.index,x.index),N=[];for(let T=C;T<=E;T+=1){let P=m.container[T];if((P==null?void 0:P.kind)!=="paragraph"||P.content.some(M=>M.kind!=="text"))return null;N.push(ge(P));}return N},td=c=>{let m=La(c);return m&&m.length>1?m:null},Ch=c=>{let m=td(c);return m?(ae={range:c,beforeParagraphs:m,changesStart:u.length},true):false},Fo=c=>{var T;let m=c.anchor.paraId;if(c.focus.paraId!==m)return;let x=e.querySelector(`coco-word-native-p[data-para-id="${m}"]`),C=Z(s,m);if(!(x!=null&&x.closest("coco-word-native-table"))||!C||((T=$==null?void 0:$.afterParagraphs[0])==null?void 0:T.paraId)===m)return;let E=ge(C),N={source:"browser",patchMode:"individual",skipDeferredRender:true,range:c,beforeParagraphs:[E],afterParagraphs:[E],changesStart:u.length,changes:[]};K.push(N),X.length=0,$=N;},nd=c=>{if(d){c.preventDefault();return}ie=true,J!==null&&(window.clearTimeout(J),J=null),oe&&Wa(),F!==null&&(window.clearTimeout(F),F=null),L!==null&&(window.clearTimeout(L),L=null),ee!==null&&(window.clearTimeout(ee),ee=null),fe!==null&&(window.clearTimeout(fe),fe=null);let m=ze(e),x=c.target instanceof Node?Nt(c.target):null,C=x==null?void 0:x.dataset.paraId,E=pt(e),N=C?{paraId:C,offset:(E==null?void 0:E.paraId)===C?E.offset:Aa(C)}:E,T=N?Z(s,N.paraId):null;if(!N||!T||T.content.some(M=>M.kind!=="text"))return;Cr(N.paraId),$=null;let P=(m==null?void 0:m.kind)==="text-range"&&m.anchor.paraId===N.paraId&&m.focus.paraId===N.paraId?{anchor:v({},m.anchor),focus:v({},m.focus)}:{anchor:N,focus:N};oe={paraId:N.paraId,beforeParagraph:ge(T),changesStart:u.length,range:P};},Wa=()=>{var M;J=null;let c=oe;if(oe=null,!c)return;let m=Z(s,c.paraId);if(!m)return;let x=e.querySelector(`coco-word-native-p[data-para-id="${c.paraId}"]`);if(!x)return;let C=Ur(s,c.paraId,(M=x.textContent)!=null?M:"");C&&u.push(C);let E=ed(c.paraId,C);E&&u.push(E);let N=ge(m);if(JSON.stringify(N)===JSON.stringify(c.beforeParagraph)){u.splice(c.changesStart);return}let T={source:"browser",patchMode:"individual",skipDeferredRender:true,range:c.range,beforeParagraphs:[c.beforeParagraph],afterParagraphs:[N],changesStart:c.changesStart,changes:u.slice(c.changesStart)};K.push(T),X.length=0;let P=pt(e);P&&se(v({kind:"caret"},P)),Pa(c.paraId),E&&Ta(c.paraId,P!=null?P:void 0),Re("deferred");},rd=()=>{ie=false,J!==null&&window.clearTimeout(J),J=window.setTimeout(Wa,80);},Ho=(c,m)=>{var M,H;let x=new Set([...c.beforeParagraphs,...c.afterParagraphs].map(z=>z.paraId)),C=(M=[...c.beforeParagraphs,...c.afterParagraphs].find(z=>Z(s,z.paraId)))==null?void 0:M.paraId;if(!C)return false;let E=ve(s,C);if(!E)return false;if(c.patchMode==="individual"){for(let z of m){let j=ve(s,z.paraId);if(!j)return false;Object.assign(j.paragraph,ge(z));}return true}let N=Array.from(x).filter(z=>Z(s,z));if(N.length===0||m.length===0)return false;let T=ge(m[0]);Object.assign(E.paragraph,T);for(let z of N)z!==C&&((H=ve(s,z))==null||H.remove());let P=T.paraId;for(let z of m.slice(1)){let j=ve(s,P);if(!j)return false;let re=ge(z);j.insertAfter(re),P=re.paraId;}return true},Eh=()=>{var T;if(!ae)return false;let c=ae;ae=null;let m=c.beforeParagraphs.map(P=>vp(e,P.paraId)),x=m.every(P=>P!==null),C=[];if(x)for(let P=0;P<c.beforeParagraphs.length;P+=1){let M=c.beforeParagraphs[P],H=Ur(s,M.paraId,(T=m[P])!=null?T:"");H&&C.push(H);}else C.push(...fi(s,c.range.anchor,c.range.focus));if(C.length===0)return false;u.push(...C);let E=c.beforeParagraphs.map(P=>Z(s,P.paraId)).filter(P=>P!==null);if(E.length>0){let P=O(v({},c),{source:"browser",afterParagraphs:E.map(ge),changes:C});K.push(P),$=null,X.length=0;}let N=pt(e);return N&&se({kind:"caret",paraId:N.paraId,offset:N.offset}),De(c.beforeParagraphs[0].paraId,N!=null?N:void 0),Re("deferred"),true},Ih=()=>{let c=K[K.length-1];if(!c||lr(c)||!Ai(e,c.beforeParagraphs)||!Ho(c,c.beforeParagraphs))return false;K.pop(),X.push(c),u.splice(c.changesStart);let m=pt(e);return m&&se({kind:"caret",paraId:m.paraId,offset:m.offset}),De(c.beforeParagraphs[0].paraId,m!=null?m:void 0),Re("deferred"),true},Nh=()=>{let c=X[X.length-1];if(!c||lr(c)||!Ai(e,c.afterParagraphs)||!Ho(c,c.afterParagraphs))return false;X.pop(),K.push(c),u.splice(c.changesStart),u.push(...c.changes);let m=pt(e);return m&&se({kind:"caret",paraId:m.paraId,offset:m.offset}),De(c.beforeParagraphs[0].paraId,m!=null?m:void 0),Re("deferred"),true},Bt=(c,m,x)=>{var H,z,j;if(c.patchMode==="individual"){let re=false;for(let ye of m){let Me=Array.from(e.querySelectorAll(`coco-word-native-p[data-para-id="${ye.paraId}"]`));for(let _ of Me)_.replaceWith(Qr(ye)),re=true;}x&&dt(e,x);let ce=e.querySelector(":scope > coco-word-native-document");return ce&&yn(ce),re}let C=new Set([...c.beforeParagraphs,...c.afterParagraphs].map(re=>re.paraId)),E=Array.from(C).flatMap(re=>Array.from(e.querySelectorAll(`coco-word-native-p[data-para-id="${re}"]`))),N=(H=c.beforeParagraphs[0])==null?void 0:H.paraId,T=(z=E.find(re=>re.dataset.paraId===N))!=null?z:E[0];if(!T)return false;let P=m.map(re=>Qr(re));T.replaceWith(...P);for(let re of E)re!==T&&re.isConnected&&re.remove();x&&dt(e,x);let M=(j=e.querySelector(":scope > coco-word-native-document"))!=null?j:e.querySelector("coco-word-native-document");return M&&yn(M),true},od=(c,m,x)=>(c.container.splice(c.startIndex,x,...rt(m)),true),Dt=(c,m,x,C)=>{var H,z;let E=[...c.beforeBlocks,...c.afterBlocks].flatMap(j=>Vv(e,j)),N=((H=c.afterBlocks[0])==null?void 0:H.kind)==="paragraph"?c.afterBlocks[0].paraId:((z=c.beforeBlocks[0])==null?void 0:z.kind)==="paragraph"?c.beforeBlocks[0].paraId:null,T=N?e.querySelector(`coco-word-native-p[data-para-id="${N}"]`):E[0];if(!T)return false;let P=m.map(j=>Jr(j));T.replaceWith(...P);for(let j of E)j!==T&&j.isConnected&&j.remove();let M=e.querySelector(":scope > coco-word-native-document");return M&&Ra(M),M&&yn(M),C?vn(e,C.anchor,C.focus):x&&dt(e,x),true},Th=c=>{let m=e.querySelector(`coco-word-native-p[data-para-id="${c.anchor.paraId}"]`),x=e.querySelector(`coco-word-native-p[data-para-id="${c.focus.paraId}"]`);return !!m&&!!x&&m.closest("coco-word-native-page")!==x.closest("coco-word-native-page")},id=(c,m)=>{let x=td(c);if(!x)return false;let C={range:c,beforeParagraphs:x,changesStart:u.length},E=au(s,c.anchor,c.focus,m);if(E.length===0)return false;let N=x.map(M=>Z(s,M.paraId)).filter(M=>M!==null).map(ge);if(N.length===0)return false;let T=O(v({},C),{source:"local",afterParagraphs:N,changes:E}),P={paraId:c.anchor.paraId,offset:c.anchor.offset+m.length};return u.push(...E),K.push(T),$=m.length>0?T:null,X.length=0,Bt(T,N,P)?De(x[0].paraId,P):Pe(P),se(v({kind:"caret"},P)),Re("deferred"),true},Oo=(c,m)=>{let x=ou(s,c.anchor,c.focus,m);if(!x)return false;let C={source:"local",range:c,container:x.container,startIndex:x.startIndex,beforeBlocks:x.beforeBlocks,afterBlocks:x.afterBlocks,changesStart:u.length,changes:x.changes};if(u.push(...x.changes),K.push(C),X.length=0,$=null,g=null,!Dt(C,x.afterBlocks,x.cursor))Pe(x.cursor);else {let E=e.querySelector(":scope > coco-word-native-document");E&&Vt(E,s,x.cursor.paraId),De(x.cursor.paraId,x.cursor);}return se(v({kind:"caret"},x.cursor)),Re("deferred"),true},Ph=(c,m)=>{let x=iu(s,c.anchor,c.focus,m);if(!x)return false;let C={source:"local",range:c,container:x.container,startIndex:x.startIndex,beforeBlocks:x.beforeBlocks,afterBlocks:x.afterBlocks,changesStart:u.length,changes:x.changes};u.push(...x.changes),K.push(C),X.length=0,$=null,g=null;for(let E of _e(s))b.add(E.paraId);if(!Dt(C,x.afterBlocks,x.cursor))Pe(x.cursor);else {let E=e.querySelector(":scope > coco-word-native-document");E&&Vt(E,s,x.cursor.paraId),De(x.cursor.paraId,x.cursor);}return se(v({kind:"caret"},x.cursor)),Re("deferred"),true},Rh=(c,m)=>{let x=c.kind==="table-cell-range"?(()=>{var Me,_,Q;let re=(Me=Oe(s,c.tableId))==null?void 0:Me.table,ce=re?(_=tt(re,c)[0])==null?void 0:_.cell:null,ye=(Q=ce==null?void 0:ce.paragraphs[0])==null?void 0:Q.paraId;return ye?{paraId:ye,offset:0}:null})():c.kind==="text-range"?c.anchor:{paraId:c.paraId,offset:c.offset};if(!x)return false;let C=rn(s,x.paraId);if(!C)return false;let E=rt([C.table])[0];if(!E||E.kind!=="table")return false;let N=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=_c(s,x.paraId,N,Pr);if(!T)return false;let P=rt([C.table])[0];if(!P||P.kind!=="table")return false;let M=S?ot(s):null,H=m.kind==="insert-table-row"||m.kind==="insert-table-column"?"insert":"delete";M&&(C.table.revision={kind:"revision",id:`revision:${M}`,revisionId:M,revisionKind:H,author:"User",date:new Date().toISOString()},P.revision=v({},C.table.revision),T.change.kind==="table"&&(T.change.revisionId=M,T.change.revisionKind=H,T.change.beforeTable=E));let z=v({kind:"caret"},T.cursor),j={source:"local",range:{anchor:x,focus:x},container:C.container,startIndex:C.tableIndex,beforeBlocks:[E],afterBlocks:[P],changesStart:u.length,changes:[T.change],beforeSelection:c,afterSelection:z};if(u.push(T.change),K.push(j),X.length=0,$=null,g=null,!Dt(j,j.afterBlocks,T.cursor))Pe(T.cursor);else {let re=e.querySelector(":scope > coco-word-native-document");re&&Vt(re,s,T.cursor.paraId),De(T.cursor.paraId,T.cursor);}return se(z),Re("deferred"),true},Mh=(c,m)=>{let x=Oe(s,c.tableId);if(!x)return false;let C=rt([x.table])[0];if(!C||C.kind!=="table")return false;let N=tt(x.table,c)[0],T=m.kind==="merge-table-cells"?qc(s,c.tableId,c):N?Xc(s,c.tableId,N.rowIndex,N.columnIndex,Pr):null;if(!T)return false;let P=rt([x.table])[0];if(!P||P.kind!=="table")return false;let M=S?ot(s):null,H=m.kind==="merge-table-cells"?"insert":"delete";M&&(x.table.revision={kind:"revision",id:`revision:${M}`,revisionId:M,revisionKind:H,author:"User",date:new Date().toISOString()},P.revision=v({},x.table.revision),T.change.kind==="table"&&(T.change.revisionId=M,T.change.revisionKind=H,T.change.beforeTable=C));let z={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:[C],afterBlocks:[P],changesStart:u.length,changes:[T.change],beforeSelection:c,afterSelection:v({kind:"caret"},T.cursor)};if(u.push(T.change),K.push(z),X.length=0,$=null,g=null,!Dt(z,z.afterBlocks,T.cursor))Pe(T.cursor);else {let j=e.querySelector(":scope > coco-word-native-document");j&&Vt(j,s,T.cursor.paraId),De(T.cursor.paraId,T.cursor);}return se(v({kind:"caret"},T.cursor)),Re("deferred"),true},Ah=(c,m)=>{let x=c.kind==="text-range"?c.anchor:c.kind==="table-cell-range"?(()=>{var z,j;let M=(z=Oe(s,c.tableId))==null?void 0:z.table,H=M?(j=tt(M,c)[0])==null?void 0:j.cell.paragraphs[0]:null;return H?{paraId:H.paraId,offset:0}:null})():{paraId:c.paraId,offset:c.offset};if(!x)return false;let C=m.kind==="insert-table"?c.kind==="caret"?Uc(s,c.paraId,c.offset,m.rows,m.columns,Pr):null:(()=>{var H;let M=(H=Rt(c).table)==null?void 0:H.tableId;return M?Kc(s,M,Pr):null})();if(!C)return false;let E=S?ot(s):null,N=m.kind==="insert-table"?"insert":"delete";if(E){let M=C.afterBlocks.find(H=>H.kind==="table");(M==null?void 0:M.kind)==="table"&&(M.revision={kind:"revision",id:`revision:${E}`,revisionId:E,revisionKind:N,author:"User",date:new Date().toISOString()},C.changes.forEach(H=>{if(H.kind==="table"){H.revisionId=E,H.revisionKind=N;let z=C.beforeBlocks.find(j=>j.kind==="table");if((z==null?void 0:z.kind)==="table"&&(H.beforeTable=z),H.op==="insert-table"){H.anchorParaId=x.paraId,H.anchorOffset=x.offset;let j=C.afterBlocks.find(re=>re.kind==="table");(j==null?void 0:j.kind)==="table"&&(H.tableSnapshot=j);}}}));}for(let M of C.changes){if(M.kind!=="table"||M.op!=="insert-table")continue;M.anchorParaId=x.paraId,M.anchorOffset=x.offset;let H=C.afterBlocks.find(z=>z.kind==="table");(H==null?void 0:H.kind)==="table"&&(M.tableSnapshot=H);}let T=v({kind:"caret"},C.cursor),P={source:"local",range:{anchor:x,focus:c.kind==="text-range"?c.focus:x},container:C.container,startIndex:C.startIndex,beforeBlocks:C.beforeBlocks,afterBlocks:C.afterBlocks,changesStart:u.length,changes:C.changes,beforeSelection:c,afterSelection:T};u.push(...C.changes),K.push(P),X.length=0,$=null,g=null;for(let M of _e(s))b.add(M.paraId);if(!Dt(P,P.afterBlocks,C.cursor))Pe(C.cursor);else {let M=e.querySelector(":scope > coco-word-native-document");M&&Vt(M,s,C.cursor.paraId),De(C.cursor.paraId,C.cursor);}return se(T),Re("deferred"),true},Lh=(c,m)=>{var ce,ye;let x=c.kind==="table-cell-range"?Oe(s,c.tableId):null,C=c.kind==="table-cell-range"&&x?(ce=tt(x.table,c)[0])==null?void 0:ce.cell:null,E=c.kind==="table-cell-range"?(ye=C==null?void 0:C.paragraphs[0])!=null&&ye.paraId?{paraId:C.paragraphs[0].paraId,offset:0}:null:c.kind==="text-range"?c.anchor:{paraId:c.paraId,offset:c.offset};if(!E)return false;let N=x!=null?x:rn(s,E.paraId);if(!N)return false;let T=rt([N.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},M=c.kind==="table-cell-range"?Yc(s,c.tableId,c,P):bs(s,E.paraId,P);if(!M)return false;let H=rt([N.table])[0];if(!H||H.kind!=="table")return false;let z={source:"local",range:{anchor:E,focus:E},container:N.container,startIndex:N.tableIndex,beforeBlocks:[T],afterBlocks:[H],changesStart:u.length,changes:"changes"in M?M.changes:[M.change],beforeSelection:c,afterSelection:c};u.push(...z.changes),K.push(z),X.length=0,$=null;let j=c.kind==="caret"?c:void 0,re=c.kind==="text-range"?c:void 0;if(!Dt(z,z.afterBlocks,j,re))Pe(j,c);else {Ft(c);let Me=e.querySelector(":scope > coco-word-native-document");Me&&Vt(Me,s,E.paraId),De(E.paraId,j,re),Ft(c);}return se(c),Re("deferred"),true},qn=c=>{let m=Oe(s,c.tableId);if(!m)return false;let x=rt([m.table])[0];if(!x||x.kind!=="table")return false;let C=Zc(s,c.tableId,c);if(!C)return false;let E=rt([m.table])[0];if(!E||E.kind!=="table")return false;let N={source:"local",range:{anchor:C.cursor,focus:C.cursor},container:m.container,startIndex:m.tableIndex,beforeBlocks:[x],afterBlocks:[E],changesStart:u.length,changes:C.changes,beforeSelection:c,afterSelection:c};if(u.push(...C.changes),K.push(N),X.length=0,$=null,!Dt(N,N.afterBlocks))Pe(void 0,c);else {let T=e.querySelector(":scope > coco-word-native-document");T&&Vt(T,s,C.cursor.paraId),De(C.cursor.paraId);}return se(c),Re("deferred"),true},Ba=(c,m)=>{var re,ce,ye;let x=Oe(s,c.tableId);if(!x)return false;let C=rt([x.table])[0];if(!C||C.kind!=="table")return false;let E={rowIndex:Math.min(c.anchor.rowIndex,c.focus.rowIndex),columnIndex:Math.min(c.anchor.columnIndex,c.focus.columnIndex)},N=(ce=(re=m.content)!=null?re:m.text)!=null?ce:[],T=m.content?Qc(s,c.tableId,E,m.content):Jc(s,c.tableId,E,(ye=m.text)!=null?ye:[]);if(!T)return false;let P=rt([x.table])[0];if(!P||P.kind!=="table")return false;let M=N.length,H=Math.max(1,...N.map(Me=>Me.length)),z={kind:"table-cell-range",tableId:c.tableId,anchor:E,focus:{rowIndex:Math.min(x.table.rows.length-1,E.rowIndex+M-1),columnIndex:E.columnIndex+H-1}},j={source:"local",range:{anchor:T.cursor,focus:T.cursor},container:x.container,startIndex:x.tableIndex,beforeBlocks:[C],afterBlocks:[P],changesStart:u.length,changes:T.changes,beforeSelection:c,afterSelection:z};if(u.push(...T.changes),K.push(j),X.length=0,$=null,!Dt(j,j.afterBlocks))Pe(void 0,z);else {let Me=e.querySelector(":scope > coco-word-native-document");Me&&Vt(Me,s,T.cursor.paraId),De(T.cursor.paraId);}return se(z),Re("deferred"),true},Ft=c=>{if(c){if(c.kind==="text-range"){vn(e,c.anchor,c.focus);return}if(c.kind==="object"){g={paraId:c.paraId,drawingId:c.objectId},_t();return}if(c.kind==="table-cell-range"){Nn(c);return}dt(e,c);}},Wh=()=>{var C;let c=K[K.length-1];if(!c)return false;if(lr(c)){let E=(C=c.beforeSelection)!=null?C:{kind:"text-range",anchor:c.range.anchor,focus:c.range.focus},N=E.kind==="caret"?E:void 0,T=E.kind==="text-range"?E:void 0;if(!od(c,c.beforeBlocks,c.afterBlocks.length));Dt(c,c.beforeBlocks,N,T)||Pe(N,E),Ft(E),K.pop(),X.push(c),$=null,u.splice(c.changesStart),se(E);let P=e.querySelector(":scope > coco-word-native-document");P&&Vt(P,s,c.range.anchor.paraId);let M=E.kind==="text-range"?E.anchor.paraId:E.kind==="table-cell-range"?c.range.anchor.paraId:E.paraId;return De(M,N,T),Re("deferred"),true}if(c.source==="browser"&&!c.skipDeferredRender&&!Ai(e,c.afterParagraphs))return false;let m={paraId:c.beforeParagraphs[0].paraId,offset:c.range.anchor.offset};if(!Ho(c,c.beforeParagraphs))return false;let x=bp(c,"before");if(c.forceFullRender){K.pop(),X.push(c),$=null,u.splice(c.changesStart);let E=x!=null?x:v({kind:"caret"},m);return se(E),Pe(E.kind==="caret"?E:void 0,E),Ft(E),Re("deferred"),true}if(!Bt(c,c.beforeParagraphs,x?void 0:m))return false;if(Ft(x),K.pop(),X.push(c),$=null,u.splice(c.changesStart),se(x!=null?x:v({kind:"caret"},m)),wp(c)||c.skipDeferredRender){let E=c.beforeParagraphs[0].paraId;c.deferLayoutReflow?Lo(E):De(E,x?void 0:m,(x==null?void 0:x.kind)==="text-range"?x:void 0),Ft(x),c.deferLayoutReflow||pn(E);}return Re("deferred"),true},Bh=()=>{var C;let c=X[X.length-1];if(!c)return false;if(lr(c)){let E=(C=c.afterSelection)!=null?C:{kind:"caret",paraId:c.afterBlocks[0].kind==="paragraph"?c.afterBlocks[0].paraId:c.range.anchor.paraId,offset:c.range.anchor.offset},N=E.kind==="caret"?E:void 0,T=E.kind==="text-range"?E:void 0;if(!od(c,c.afterBlocks,c.beforeBlocks.length));Dt(c,c.afterBlocks,N,T)||Pe(N,E),Ft(E),X.pop(),K.push(c),$=null,u.splice(c.changesStart),u.push(...c.changes),se(E);let P=E.kind==="text-range"?E.anchor.paraId:E.kind==="table-cell-range"?c.range.anchor.paraId:E.paraId,M=e.querySelector(":scope > coco-word-native-document");return M&&Vt(M,s,P),De(P,N,T),Re("deferred"),true}if(c.source==="browser"&&!c.skipDeferredRender&&!Ai(e,c.beforeParagraphs))return false;let m={paraId:c.afterParagraphs[0].paraId,offset:c.range.anchor.offset};if(!Ho(c,c.afterParagraphs))return false;let x=bp(c,"after");if(c.forceFullRender){X.pop(),K.push(c),$=null,u.splice(c.changesStart),u.push(...c.changes);let E=x!=null?x:v({kind:"caret"},m);return se(E),Pe(E.kind==="caret"?E:void 0,E),Ft(E),Re("deferred"),true}if(!Bt(c,c.afterParagraphs,x?void 0:m))return false;if(Ft(x),X.pop(),K.push(c),$=null,u.splice(c.changesStart),u.push(...c.changes),se(x!=null?x:v({kind:"caret"},m)),wp(c)||c.skipDeferredRender){let E=c.beforeParagraphs[0].paraId;c.deferLayoutReflow?Lo(E):De(E,x?void 0:m,(x==null?void 0:x.kind)==="text-range"?x:void 0),Ft(x),c.deferLayoutReflow||pn(E);}return Re("deferred"),true},Ir=()=>l||d||K.length===0?false:(ut(),Wh()),Nr=()=>l||d||X.length===0?false:(ut(),Bh()),se=c=>{if(c&&ut(),(c==null?void 0:c.kind)!=="object"&&_n(),Nn(c),Gv(h,c)){at();return}h=c,at(),Ma();},Tr=(c,m,x)=>{if(!c||(m==null?void 0:m.kind)!=="image")return false;let C=Z(s,m.paraId);if(!C)return false;let E={source:"local",patchMode:"individual",deferLayoutReflow:true,range:{anchor:x,focus:x},beforeParagraphs:[c],afterParagraphs:[ge(C)],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),K.push(E),X.length=0,$=null,kh(m.paraId,m.drawingId,x),Lo(m.paraId),g=null,se(v({kind:"caret"},x)),Re("deferred"),true},Pn=(c,m,x)=>{let C=Z(s,c),E=C==null?void 0:C.content.find(T=>T.kind==="image"&&T.drawingId===m);if(S&&C&&(E==null?void 0:E.kind)==="image"){let T=ge(C),P=ot(s);return E.revision={kind:"revision",id:`revision:${P}`,revisionId:P,revisionKind:"delete",author:"User",date:new Date().toISOString()},wt({kind:"object",paraId:c,objectKind:"image",objectId:m,offset:x.offset},[T],[{kind:"image",op:"delete",paraId:c,offset:x.offset,drawingId:m,revisionId:P,revisionKind:"delete"}],true)}let N=C?ge(C):null;return Tr(N,fu(s,c,m),x)},Rn=(c,m,x=v({kind:"caret"},c),C)=>{let E=Z(s,c.paraId);if(!E)return false;let N=m==="delete-backward"?c.offset-1:c.offset;if(m!=="insert"&&!ui(s,c.paraId,N))return false;let T=ge(E),P=m==="insert"?tu(s,c.paraId,c.offset):m==="delete-backward"?zr(s,c.paraId,c.offset):Vr(s,c.paraId,c.offset),M=Z(s,c.paraId);if(!P||P.kind!=="page-break"||!M)return false;let H={paraId:c.paraId,offset:m==="insert"?c.offset+1:m==="delete-backward"?Math.max(0,c.offset-1):c.offset},z=C!=null?C:v({kind:"caret"},H),j=z.kind==="caret"?z:H,re={source:"local",patchMode:"individual",forceFullRender:true,range:{anchor:c,focus:c},beforeParagraphs:[T],afterParagraphs:[ge(M)],changesStart:u.length,changes:[P],beforeSelection:x,afterSelection:z};return u.push(P),K.push(re),X.length=0,$=null,g=null,Pe(j,z),se(z),Re("deferred"),true},$o=c=>{if(c.anchor.paraId!==c.focus.paraId)return false;let m=Li(c.anchor.offset,c.focus.offset);if(!nu(s,c.anchor.paraId,m.from,m.to))return false;let x=Z(s,c.anchor.paraId);if(!x)return false;let C=ge(x),E=bn(s,c.anchor.paraId,m.from,m.to),N=Z(s,c.anchor.paraId);if(!N||!E.some(M=>M.kind==="page-break"))return false;let T={kind:"caret",paraId:c.anchor.paraId,offset:m.from},P={source:"local",patchMode:"individual",forceFullRender:true,range:{anchor:c.anchor,focus:c.focus},beforeParagraphs:[C],afterParagraphs:[ge(N)],changesStart:u.length,changes:E,beforeSelection:c,afterSelection:T};return u.push(...E),K.push(P),X.length=0,$=null,Pe(T,T),se(T),Re("deferred"),true},zo=(c,m)=>{let x=ve(s,c.paraId);if(!x)return false;if(m==="backward"&&c.offset===0&&x.previous){let N=Te(x.previous).length;return ui(s,x.previous.paraId,N-1)?Rn({paraId:x.previous.paraId,offset:N},"delete-backward",c,c):false}let C=x.container[x.index+1],E=(C==null?void 0:C.kind)==="paragraph"?C:null;return m==="forward"&&c.offset===Te(x.paragraph).length&&E&&ui(s,E.paraId,0)?Rn({paraId:E.paraId,offset:0},"delete-forward",c,c):false},Mn=(c,m,x,C)=>{if(c.anchor.paraId!==c.focus.paraId)return false;let E=Z(s,c.anchor.paraId);if(!E)return false;let N=ge(E),T=C(),P=Array.isArray(T)?T:T?[T]:[],M=Z(s,c.anchor.paraId);if(P.length===0||!M)return false;let H=v({kind:"caret"},x),z={source:"local",patchMode:"individual",range:c,beforeParagraphs:[N],afterParagraphs:[ge(M)],changesStart:u.length,changes:P,beforeSelection:m,afterSelection:H};return u.push(...P),K.push(z),X.length=0,$=null,Bt(z,z.afterParagraphs,x)?De(c.anchor.paraId,x):Pe(x),se(H),Re("deferred"),true},en=c=>{if((c==null?void 0:c.kind)!=="text-range")return [];let m=nt(s,c);if(m.anchor.paraId===m.focus.paraId)return [{paraId:m.anchor.paraId,from:m.anchor.offset,to:m.focus.offset}];let x=ve(s,m.anchor.paraId),C=ve(s,m.focus.paraId);if(!x||!C||x.container!==C.container)return [];let E=[];for(let N=x.index;N<=C.index;N+=1){let T=x.container[N];if((T==null?void 0:T.kind)!=="paragraph")return [];E.push({paraId:T.paraId,from:N===x.index?m.anchor.offset:0,to:N===C.index?m.focus.offset:Te(T).length});}return E},ad=c=>{var m;if(!c)return [];if(c.kind==="caret"||c.kind==="object")return [c.paraId];if(c.kind==="table-cell-range"){let x=(m=Oe(s,c.tableId))==null?void 0:m.table;return x?tt(x,c).flatMap(({cell:C})=>C.paragraphs.map(E=>E.paraId)):[]}return en(c).map(x=>x.paraId)},sd=c=>{if((c==null?void 0:c.kind)!=="text-range")return null;let m=en(c);return m.length===0?null:m.map(x=>Te(Z(s,x.paraId)).slice(x.from,x.to)).join(`
1597
+ `)},ld=c=>en(c).map(m=>{var P;let x=Z(s,m.paraId),C=Te(x).slice(m.from,m.to),E=[],N=0;for(let M of x.content){let H=Uv(M),z=N+H.length,j=Math.max(m.from,N),re=Math.min(m.to,z),ce=M.kind==="text"||M.kind==="field"?M.format:null,ye=M.kind==="text"?M.hyperlink:void 0;(ce||ye)&&re>j&&E.push(v({from:j-m.from,to:re-m.from,format:v({},ce!=null?ce:{})},ye?{hyperlink:v({},ye)}:{})),N=z;}let T=(P=x.format)!=null&&P.hasNumbering&&x.format.numbering?hn(x.format.numbering):null;return v({text:C,runs:E},T?{listType:T}:{})}),Xn=(c,m,x)=>{var M;if(S&&!x&&c.anchor.paraId===c.focus.paraId)return ke({kind:"replace-range",anchor:c.anchor,focus:c.focus,text:m});if(Oo(c,m))return true;let C=La(c);if(!C)return false;let E=ys(s,c.anchor,c.focus,m);if(!E||E.changes.length===0)return false;for(let H of E.paragraphIds)b.add(H);let N=null;for(let H=0;H<((M=x==null?void 0:x.length)!=null?M:0);H+=1){let z=x[H],j=E.paragraphIds[H];if(!j)break;let re=H===0?c.anchor.offset:0;for(let ce of z.runs){if(Object.keys(ce.format).length>0){let ye=vs(s,j,re+ce.from,re+ce.to,ce.format);ye&&E.changes.push(ye);}if(ce.hyperlink){let ye=ks(s,j,re+ce.from,re+ce.to,ce.hyperlink);ye&&E.changes.push(ye);}}if(z.listType){(!N||N.type!==z.listType)&&(N={type:z.listType,numbering:fs(s,z.listType)});let ce=jr(s,j,N.numbering);ce&&E.changes.push(ce);}else N=null;}if(S){let H=ot(s),z=E.changes.filter(j=>j.kind==="text"&&(j.op==="insert"||j.op==="replace")&&j.text.length>0).map(j=>$t(s,j.paraId,j.offset,j.offset+j.text.length,{revisionId:H,revisionKind:"insert",author:"User",date:new Date().toISOString()})).filter(j=>j!==null);E.changes.push(...z);}si(s);let T=E.paragraphIds.map(H=>Z(s,H)).filter(H=>H!==null).map(ge),P={source:"local",range:c,beforeParagraphs:C,afterParagraphs:T,changesStart:u.length,changes:E.changes};return u.push(...E.changes),K.push(P),X.length=0,$=null,g=null,Bt(P,T,E.cursor)?De(C[0].paraId,E.cursor):Pe(E.cursor),se(v({kind:"caret"},E.cursor)),Re("deferred"),true},Da=(c,m,x={})=>{var j,re;let C=La(c);if(!C)return false;let E=ys(s,c.anchor,c.focus,"");if(!E)return false;for(let ce of E.paragraphIds)b.add(ce);let N=eu(s,E.cursor.paraId,E.cursor.offset,m,x);if(!N||N.kind!=="image")return false;let T=[...E.changes,N];if(S){let ce=ot(s),ye=(j=Z(s,N.paraId))==null?void 0:j.content.find(Me=>Me.kind==="image"&&Me.drawingId===N.drawingId);(ye==null?void 0:ye.kind)==="image"&&(ye.revision={kind:"revision",id:`revision:${ce}`,revisionId:ce,revisionKind:"insert",author:"User",date:new Date().toISOString()},T.push({kind:"image",op:"insert",paraId:N.paraId,offset:N.offset,drawingId:N.drawingId,revisionId:ce,revisionKind:"insert"}));}let P={paraId:E.cursor.paraId,offset:E.cursor.offset+1},M=E.paragraphIds.map(ce=>Z(s,ce)).filter(ce=>ce!==null).map(ge),H=v({source:"local",patchMode:"individual",deferLayoutReflow:true,range:c,beforeParagraphs:C,afterParagraphs:M,changesStart:u.length,changes:T},x.select?{beforeSelection:c.anchor.paraId===c.focus.paraId&&c.anchor.offset===c.focus.offset?v({kind:"caret"},c.anchor):{kind:"text-range",anchor:c.anchor,focus:c.focus},afterSelection:{kind:"object",paraId:E.cursor.paraId,objectKind:"image",objectId:N.drawingId,offset:E.cursor.offset}}:{});u.push(...T),K.push(H),X.length=0,g=x.select?{paraId:E.cursor.paraId,drawingId:N.drawingId}:null,$=null;let z=(re=Z(s,N.paraId))==null?void 0:re.content.find(ce=>ce.kind==="image"&&ce.drawingId===N.drawingId);return (!z||z.kind!=="image"||!Dh(c,z,P))&&(Bt(H,M,P)||Pe(P)),Lo(C[0].paraId),g&&_t(),se(g?{kind:"object",paraId:g.paraId,objectKind:"image",objectId:g.drawingId,offset:E.cursor.offset}:v({kind:"caret"},P)),Re("deferred"),true},Dh=(c,m,x)=>{if(c.anchor.paraId!==c.focus.paraId)return false;let C=Os(e,c.anchor,c.focus);if(!C)return false;let E=e.querySelector(`coco-word-native-p[data-para-id="${c.anchor.paraId}"]`);return !E||!E.contains(C.commonAncestorContainer)?false:(C.deleteContents(),C.insertNode(Ds(m)),dt(e,x),true)},Pr=()=>{let c="";do w=w+1>>>0,c=w.toString(16).toUpperCase().padStart(8,"0");while(!c||b.has(c));return b.add(c),c},Fa=(c,m=Pr())=>{let x=Z(s,c.paraId);if(!x)return false;let C=ge(x),E=Cs(s,c.paraId,c.offset,m);if(!E)return false;let N=[c.paraId,m].map(M=>Z(s,M)).filter(M=>M!==null).map(ge);if(N.length!==2)return false;let T={paraId:m,offset:0},P={source:"local",skipDeferredRender:true,range:{anchor:c,focus:c},beforeParagraphs:[C],afterParagraphs:N,changesStart:u.length,changes:[E]};return u.push(E),K.push(P),X.length=0,$=null,g=null,Bt(P,N,T)?De(c.paraId,T):Pe(T),se(v({kind:"caret"},T)),Re("deferred"),true},dd=c=>{if(c.offset!==0)return false;let m=ve(s,c.paraId),x=m==null?void 0:m.previous;if(!m||!x)return false;let C=[ge(x),ge(m.paragraph)],E={paraId:x.paraId,offset:Te(x).length},N=u.length,T=zr(s,c.paraId,0),P=Z(s,x.paraId);if(!T||T.kind!=="block"||!P)return false;let M={source:"local",skipDeferredRender:true,range:{anchor:c,focus:c},beforeParagraphs:C,afterParagraphs:[ge(P)],changesStart:N,changes:[T]};return u.push(T),K.push(M),X.length=0,$=null,g=null,Bt(M,M.afterParagraphs,E)?De(x.paraId,E):Pe(E),se(v({kind:"caret"},E)),Re("deferred"),true},cd=c=>{let m=ve(s,c.paraId);if(!m||c.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 C=[ge(m.paragraph),ge(x)],E=u.length,N=Vr(s,c.paraId,c.offset),T=Z(s,c.paraId);if(!N||N.kind!=="block"||!T)return false;let P={source:"local",skipDeferredRender:true,range:{anchor:c,focus:c},beforeParagraphs:C,afterParagraphs:[ge(T)],changesStart:E,changes:[N]};return u.push(N),K.push(P),X.length=0,$=null,g=null,Bt(P,P.afterParagraphs,c)?De(c.paraId,c):Pe(c),se(v({kind:"caret"},c)),Re("deferred"),true},wt=(c,m,x,C=false)=>{if(x.length===0||m.length===0)return false;let E=m.map(M=>Z(s,M.paraId)).filter(M=>M!==null).map(ge),T={source:"local",patchMode:"individual",range:c.kind==="text-range"?nt(s,c):c.kind==="table-cell-range"?{anchor:{paraId:m[0].paraId,offset:0},focus:{paraId:m[m.length-1].paraId,offset:Te(m[m.length-1]).length}}:{anchor:{paraId:c.paraId,offset:c.offset},focus:{paraId:c.paraId,offset:c.offset}},beforeParagraphs:m,afterParagraphs:E,changesStart:u.length,changes:x,beforeSelection:c,afterSelection:c};u.push(...x),K.push(T),X.length=0,$=null,Bt(T,E)||Pe();let P=e.querySelector(":scope > coco-word-native-document");if(P&&yn(P),c.kind==="text-range"?vn(e,c.anchor,c.focus):c.kind==="object"?(g={paraId:c.paraId,drawingId:c.objectId},_t()):c.kind==="caret"&&dt(e,{paraId:c.paraId,offset:c.offset}),C){let M=c.kind==="caret"||c.kind==="object"?{paraId:c.paraId,offset:c.offset}:void 0;De(m[0].paraId,M,c);}return c.kind==="object"&&g&&_t(),se(c),Re("deferred"),true},ud=(c,m)=>{if(c.length===0)return 0;let x=Array.from(new Set(c.map(z=>z.paraId))),C=x.map(z=>Z(s,z)).filter(z=>z!==null).map(ge);if(C.length===0)return 0;let E=u.length,N=[],T=[...c].sort((z,j)=>z.paraId===j.paraId?j.from-z.from:x.indexOf(j.paraId)-x.indexOf(z.paraId));for(let z of T)N.push(...Gr(s,z.paraId,z.from,z.to,m));if(N.length===0)return 0;let P=C.map(z=>Z(s,z.paraId)).filter(z=>z!==null).map(ge),M=c[0],H=v({source:"local",patchMode:"individual",range:{anchor:{paraId:M.paraId,offset:M.from},focus:{paraId:M.paraId,offset:M.to}},beforeParagraphs:C,afterParagraphs:P,changesStart:E,changes:N},h?{beforeSelection:h,afterSelection:h}:{});return u.push(...N),K.push(H),X.length=0,$=null,Bt(H,P)?Ft(h):Pe(void 0,h!=null?h:void 0),De(M.paraId),Re(),c.length},Fh=c=>{if(d)return false;let m=k&&k.activeIndex>=0?k.matches[k.activeIndex]:null;return m?ud([m],c)>0:false},Hh=c=>d?0:k?ud(k.matches,c):0,ke=c=>{var x,C,E,N,T,P,M,H,z,j,re,ce,ye,Me;if(l||d)return false;ut();let m=(x=h!=null?h:ze(e))!=null?x:lt(e);if(c.kind==="toggle-track-revisions")return S=!S,Ma(),true;if(c.kind==="accept-revision"||c.kind==="reject-revision"||c.kind==="accept-all-revisions"||c.kind==="reject-all-revisions"){let _=c.kind==="accept-revision"||c.kind==="reject-revision"?c.revisionId:void 0,Q=c.kind==="accept-revision"||c.kind==="reject-revision"?c.revisionKind:void 0,te=c.kind==="accept-all-revisions"||c.kind==="reject-all-revisions",ne=new Set(K.flatMap(he=>lr(he)?he.changes.filter(we=>we.kind==="table"&&!!(we.revisionAction&&we.revisionId)).map(we=>we.revisionId):[])),me=he=>(he&&te&&ke(c),he),pe=K.filter(he=>lr(he)&&he.changes.some(we=>we.kind==="table"&&!we.revisionAction&&!!we.revisionId&&!ne.has(we.revisionId))&&he.afterBlocks.some(we=>{var Ne,le,Ke;if(we.kind!=="table"||((Ne=we.revision)==null?void 0:Ne.kind)!=="revision"||ne.has(we.revision.revisionId))return false;let Be=(Ke=(le=Oe(s,we.tableId))==null?void 0:le.table.revision)==null?void 0:Ke.revisionId;return te?!!Be:Be===we.revision.revisionId&&we.revision.revisionId===_&&(!Q||we.revision.revisionKind===Q)}));if(pe.length>0){let he=c.kind==="accept-revision"||c.kind==="accept-all-revisions"?"accept":"reject",we=new Map;for(let Be of pe){let Ne=Be.afterBlocks.find(Ke=>{var je;return Ke.kind==="table"&&((je=Ke.revision)==null?void 0:je.kind)==="revision"});if(!Ne||Ne.kind!=="table"||!Ne.revision)continue;let le=(C=we.get(Ne.tableId))!=null?C:[];le.push(Be),we.set(Ne.tableId,le);}for(let[Be,Ne]of we){let le=Ne[Ne.length-1];if(!le)continue;let Ke=le.afterBlocks.find(Ko=>{var Zn;return Ko.kind==="table"&&((Zn=Ko.revision)==null?void 0:Zn.kind)==="revision"});if(!Ke||Ke.kind!=="table"||!Ke.revision)continue;let je=Oe(s,Be);if(!je)continue;let tn=[rt([je.table])[0]],An=rt([je.table])[0];if(!An||An.kind!=="table")continue;he==="accept"&&(An.revision=void 0,je.table.revision=void 0);let Yn=he==="accept"?[An]:rt((N=(E=Ne[0])==null?void 0:E.beforeBlocks)!=null?N:le.beforeBlocks);he==="reject"&&je.container.splice(je.tableIndex,1,...rt(Yn));let Uo=Ne.flatMap(Ko=>Ko.changes.filter(Zn=>Zn.kind==="table").map(Zn=>O(v({},Zn),{revisionAction:he}))),Ga={source:"local",range:le.range,container:je.container,startIndex:je.tableIndex,beforeBlocks:tn,afterBlocks:Yn,changesStart:u.length,changes:Uo,beforeSelection:m!=null?m:void 0,afterSelection:m!=null?m:void 0};u.push(...Ga.changes),K.push(Ga),X.length=0,Dt(Ga,Yn,void 0)?De(((T=tn[0])==null?void 0:T.kind)==="paragraph"?tn[0].paraId:(z=(H=(M=(P=je.table.rows[0])==null?void 0:P.cells[0])==null?void 0:M.paragraphs[0])==null?void 0:H.paraId)!=null?z:"",void 0):Pe(),Re("deferred");}return me(true)}let Y=_e(s).flatMap(he=>{var Ne;let we=0,Be=[];for(let le of he.content)le.kind==="image"&&(((Ne=le.revision)==null?void 0:Ne.kind)==="revision"&&(te||le.revision.revisionId===_&&(!Q||le.revision.revisionKind===Q))||le.formatRevision&&(te||le.formatRevision.revisionId===_&&(!Q||Q==="format")))&&Be.push({paraId:he.paraId,drawingId:le.drawingId,offset:we}),we+=le.kind==="text"?le.text.length:1;return Be});if(Y.length>0){let he=c.kind==="accept-revision"||c.kind==="accept-all-revisions"?"accept":"reject",we=Array.from(new Set(Y.map(le=>le.paraId))).map(le=>Z(s,le)).filter(le=>le!==null).map(ge),Be=Y.map(le=>{var je;let Ke=(je=Z(s,le.paraId))==null?void 0:je.content.find(tn=>tn.kind==="image"&&tn.drawingId===le.drawingId);return (Ke==null?void 0:Ke.kind)==="image"&&Ke.formatRevision?hu(s,le.paraId,le.drawingId,he):mu(s,le.paraId,le.drawingId,he)}).filter(le=>le!==null);if(Be.length===0)return false;let Ne=Y[0];return me(wt({kind:"caret",paraId:Ne.paraId,offset:Ne.offset},we,Be,true))}let Ie=_e(s).flatMap(he=>{let we=0,Be=[];for(let Ne of he.content){let le=Ne.kind==="text"?Ne.text.length:1;Ne.kind==="text"&&Ne.formatRevision&&(te||Ne.formatRevision.revisionId===_&&(!Q||Q==="format"))&&Be.push({paraId:he.paraId,from:we,to:we+le}),we+=le;}return Be});if(Ie.length>0){let he=c.kind==="accept-revision"||c.kind==="accept-all-revisions"?"accept":"reject",we=Array.from(new Set(Ie.map(le=>le.paraId))).map(le=>Z(s,le)).filter(le=>le!==null).map(ge),Be=Ie.map(le=>cu(s,le.paraId,le.from,le.to,he)).filter(le=>le!==null);if(Be.length===0)return false;let Ne=Ie[0];return me(wt({kind:"caret",paraId:Ne.paraId,offset:Ne.from},we,Be,true))}let He=te?_e(s).flatMap(he=>{var Ne;let we=[],Be=0;for(let le of he.content){let Ke=le.kind==="text"?le.text.length:1;le.kind==="text"&&((Ne=le.marks)!=null&&Ne.some(je=>je.kind==="revision"))&&we.push({paraId:he.paraId,from:Be,to:Be+Ke}),Be+=Ke;}return we}):_?_e(s).flatMap(he=>{var Ne;let we=[],Be=0;for(let le of he.content){let Ke=le.kind==="text"?le.text.length:1;le.kind==="text"&&((Ne=le.marks)!=null&&Ne.some(je=>je.kind==="revision"&&je.revisionId===_&&(!Q||je.revisionKind===Q)))&&we.push({paraId:he.paraId,from:Be,to:Be+Ke}),Be+=Ke;}return we}):en(m);if(He.length===0)return false;(te||_)&&He.sort((he,we)=>he.paraId===we.paraId?we.from-he.from||we.to-he.to:we.paraId.localeCompare(he.paraId));let be=He.map(he=>Z(s,he.paraId)).filter(he=>he!==null).map(ge),Fe=c.kind==="accept-revision"||c.kind==="accept-all-revisions"?"accept":"reject",ue=He.map(he=>du(s,he.paraId,he.from,he.to,Fe)).filter(he=>he!==null);if(ue.length===0)return false;let Je=m!=null?m:{kind:"caret",paraId:He[0].paraId,offset:He[0].from};return me(wt(Je,be,ue,false))}if(c.kind==="insert-text"&&(m==null?void 0:m.kind)==="caret"){let _={paraId:m.paraId,offset:m.offset+c.text.length};return Mn({anchor:m,focus:m},m,_,()=>{var ne;let Q=on(s,m.paraId,m.offset,c.text);if(!S||!Q||c.text.length===0)return Q;let te=$t(s,m.paraId,m.offset,_.offset,{revisionId:(ne=Er(m.paraId,m.offset,"insert","before"))!=null?ne:ot(s),revisionKind:"insert",author:"User",date:new Date().toISOString()});return te?[Q,te]:Q})}if(c.kind==="replace-range"&&c.anchor.paraId===c.focus.paraId){let _=Li(c.anchor.offset,c.focus.offset),Q={kind:"text-range",anchor:c.anchor,focus:c.focus};return S?Mn({anchor:c.anchor,focus:c.focus},Q,{paraId:c.anchor.paraId,offset:_.to+c.text.length},()=>{let te=[],ne=$t(s,c.anchor.paraId,_.from,_.to,{revisionId:ot(s),revisionKind:"delete",author:"User",date:new Date().toISOString()});if(ne&&te.push(ne),c.text.length>0){let me=on(s,c.anchor.paraId,_.to,c.text);me&&te.push(me);let pe=$t(s,c.anchor.paraId,_.to,_.to+c.text.length,{revisionId:ot(s),revisionKind:"insert",author:"User",date:new Date().toISOString()});pe&&te.push(pe);}return te}):Mn({anchor:c.anchor,focus:c.focus},Q,{paraId:c.anchor.paraId,offset:_.from+c.text.length},()=>Gr(s,c.anchor.paraId,_.from,_.to,c.text))}if(c.kind==="delete-range"&&S){let _={kind:"text-range",anchor:c.anchor,focus:c.focus},Q=en(_);if(Q.length===0)return false;let te=Array.from(new Map(Q.map(Y=>Z(s,Y.paraId)).filter(Y=>Y!==null).map(Y=>[Y.paraId,ge(Y)])).values()),ne=ot(s),me=Q.map(Y=>$t(s,Y.paraId,Y.from,Y.to,{revisionId:ne,revisionKind:"delete",author:"User",date:new Date().toISOString()})).filter(Y=>Y!==null);if(me.length===0)return false;let pe=wt(_,te,me,false);if(pe){let Y=nt(s,_),Ie={paraId:Y.anchor.paraId,offset:Y.anchor.offset};dt(e,Ie),se(v({kind:"caret"},Ie));}return pe}if(c.kind==="delete-range"&&c.anchor.paraId===c.focus.paraId){let _={kind:"text-range",anchor:c.anchor,focus:c.focus};if($o(_))return true;let Q=Li(c.anchor.offset,c.focus.offset);return S?Mn({anchor:c.anchor,focus:c.focus},_,{paraId:c.anchor.paraId,offset:Q.from},()=>{var te;return $t(s,c.anchor.paraId,Q.from,Q.to,{revisionId:(te=Er(c.anchor.paraId,Q.from,"delete","at"))!=null?te:ot(s),revisionKind:"delete",author:"User",date:new Date().toISOString()})}):Mn({anchor:c.anchor,focus:c.focus},_,{paraId:c.anchor.paraId,offset:Q.from},()=>bn(s,c.anchor.paraId,Q.from,Q.to))}if(c.kind==="split-paragraph"&&(m==null?void 0:m.kind)==="caret")return Fa({paraId:m.paraId,offset:m.offset});if(c.kind==="insert-page-break"&&(m==null?void 0:m.kind)==="caret")return Rn(m,"insert");if(c.kind==="insert-image"&&m&&(m.kind==="caret"||m.kind==="text-range")){let _=m.kind==="text-range"?nt(s,m):{anchor:{paraId:m.paraId,offset:m.offset},focus:{paraId:m.paraId,offset:m.offset}};return Da(_,c.src,O(v(v({},c.width?{width:c.width}:{}),c.height?{height:c.height}:{}),{select:true}))}if(c.kind==="set-image-size"&&(m==null?void 0:m.kind)==="object"&&m.objectKind==="image"&&m.objectId===c.objectId){let _=Z(s,m.paraId);if(!_)return false;let Q=ge(_),te=_.content.find(Y=>Y.kind==="image"&&Y.drawingId===m.objectId),ne=(te==null?void 0:te.kind)==="image"?te.width:void 0,me=(te==null?void 0:te.kind)==="image"?te.height:void 0,pe=ru(s,m.paraId,m.objectId,{width:c.width,height:c.height});if(S&&pe){let Y=_.content.find(Ie=>Ie.kind==="image"&&Ie.drawingId===m.objectId);(Y==null?void 0:Y.kind)==="image"&&(Y.formatRevision={kind:"format",revisionId:ot(s),beforeWidth:ne,beforeHeight:me,afterWidth:c.width,afterHeight:c.height,author:"User",date:new Date().toISOString()},pe.kind==="image"&&(pe.revisionId=Y.formatRevision.revisionId,pe.revisionKind="format"));}return wt(m,[Q],pe?[pe]:[],true)}if(c.kind==="set-image-alignment"&&(m==null?void 0:m.kind)==="object"&&m.objectKind==="image"&&m.objectId===c.objectId)return ke({kind:"set-paragraph-alignment",alignment:c.alignment});if(m&&(c.kind==="insert-table"||c.kind==="delete-table"))return Ah(m,c);if(m&&(c.kind==="insert-table-row"||c.kind==="delete-table-row"||c.kind==="insert-table-column"||c.kind==="delete-table-column"))return Rh(m,c);if((m==null?void 0:m.kind)==="table-cell-range"&&(c.kind==="merge-table-cells"||c.kind==="split-table-cell"))return Mh(m,c);if(m&&(c.kind==="set-table-cell-background"||c.kind==="set-table-cell-vertical-alignment"||c.kind==="set-table-cell-borders"))return Lh(m,c);if(c.kind==="clear-table-cells"&&(m==null?void 0:m.kind)==="table-cell-range")return qn(m);if(c.kind==="delete-backward"){if((m==null?void 0:m.kind)==="table-cell-range")return qn(m);if((m==null?void 0:m.kind)==="text-range")return $o(m)?true:S?ke({kind:"delete-range",anchor:m.anchor,focus:m.focus}):Xn(nt(s,m),"");if((m==null?void 0:m.kind)==="object"&&m.objectKind==="image"){let _={paraId:m.paraId,offset:m.offset};return Pn(m.paraId,m.objectId,_)}if((m==null?void 0:m.kind)==="caret"){if(S&&m.offset>0){let me=m.offset-1;return Mn({anchor:m,focus:m},m,{paraId:m.paraId,offset:me},()=>{var pe;return $t(s,m.paraId,me,m.offset,{revisionId:(pe=Er(m.paraId,me,"delete","after"))!=null?pe:ot(s),revisionKind:"delete",author:"User",date:new Date().toISOString()})})}if(Rn(m,"delete-backward")||zo(m,"backward")||dd({paraId:m.paraId,offset:m.offset}))return true;let _=Z(s,m.paraId),Q=_?ge(_):null,te=zr(s,m.paraId,m.offset),ne={paraId:m.offset>0?m.paraId:(j=ls(s,m.paraId))!=null?j:m.paraId,offset:Math.max(0,m.offset-1)};return (te==null?void 0:te.kind)==="image"?Tr(Q,te,ne):Tn(te,ne,(te==null?void 0:te.kind)==="block"?{}:{localParaId:m.paraId}),true}}if(c.kind==="delete-forward"&&(m==null?void 0:m.kind)==="table-cell-range")return qn(m);if(c.kind==="delete-forward"&&(m==null?void 0:m.kind)==="text-range")return $o(m)?true:S?ke({kind:"delete-range",anchor:m.anchor,focus:m.focus}):Xn(nt(s,m),"");if(c.kind==="delete-forward"&&(m==null?void 0:m.kind)==="caret"){if(S&&m.offset<Aa(m.paraId))return Mn({anchor:m,focus:m},m,m,()=>{var me;return $t(s,m.paraId,m.offset,m.offset+1,{revisionId:(me=Er(m.paraId,m.offset,"delete","at"))!=null?me:ot(s),revisionKind:"delete",author:"User",date:new Date().toISOString()})});if(Rn(m,"delete-forward")||zo(m,"forward")||cd({paraId:m.paraId,offset:m.offset}))return true;let _=Z(s,m.paraId),Q=_?ge(_):null,te=Vr(s,m.paraId,m.offset),ne={paraId:m.paraId,offset:m.offset};return (te==null?void 0:te.kind)==="image"?Tr(Q,te,ne):Tn(te,ne,{localParaId:m.paraId}),true}if(c.kind==="delete-object"&&(m==null?void 0:m.kind)==="object"){let _={paraId:m.paraId,offset:m.offset};return Pn(m.paraId,c.objectId,_)}if((c.kind==="set-hyperlink"||c.kind==="remove-hyperlink")&&(m==null?void 0:m.kind)==="text-range"){let _=en(m),Q=_.map(ne=>Z(s,ne.paraId)).filter(ne=>ne!==null).map(ge),te=_.map(ne=>ks(s,ne.paraId,ne.from,ne.to,c.kind==="set-hyperlink"?c.hyperlink:null)).filter(ne=>ne!==null);return wt(m,Q,te,false)}if(c.kind==="add-comment"&&(m==null?void 0:m.kind)==="text-range"){let _=en(m);if(_.length===0||!c.body.trim())return false;let Q=_.map(Y=>Z(s,Y.paraId)).filter(Y=>Y!==null).map(ge),te=gp(s),ne=(re=c.date)!=null?re:new Date().toISOString(),me=_.map(Y=>{var Ie;return Ss(s,Y.paraId,Y.from,Y.to,{commentId:te,author:(Ie=c.author)!=null?Ie:"User",date:ne,body:c.body.trim()})}).filter(Y=>Y!==null),pe=wt(m,Q,me,false);return pe&&me.length>1&&Pe(),pe}if(c.kind==="edit-comment"||c.kind==="delete-comment"){if(c.kind==="edit-comment"&&!c.body.trim())return false;let _=_e(s).filter(ne=>ne.content.some(me=>{var pe;return me.kind==="text"&&((pe=me.marks)==null?void 0:pe.some(Y=>Y.kind==="comment"&&Y.commentId===c.commentId))})).map(ge);if(_.length===0)return false;let Q=c.kind==="edit-comment"?su(s,c.commentId,c.body.trim()):lu(s,c.commentId);if(Q.length===0)return false;let te=m!=null?m:{kind:"caret",paraId:_[0].paraId,offset:0};return wt(te,_,Q,false)}if(c.kind==="reply-comment"){let _=c.body.trim();if(!_)return false;let Q=null;for(let pe of _e(s)){let Y=0;for(let Ie of pe.content){let He=Ie.kind==="text"?Ie.text.length:1;if(Ie.kind==="text"&&((ce=Ie.marks)!=null&&ce.some(be=>be.kind==="comment"&&be.commentId===c.commentId))){Q={paragraph:pe,from:Y,to:Y+He};break}Y+=He;}if(Q)break}if(!Q)return false;let te=ge(Q.paragraph),ne=gp(s),me=Ss(s,Q.paragraph.paraId,Q.from,Q.to,{commentId:ne,parentCommentId:c.commentId,preserveExistingComments:true,author:"User",date:new Date().toISOString(),body:_});return me?(Pe(),wt(m!=null?m:{kind:"caret",paraId:Q.paragraph.paraId,offset:Q.from},[te],[me],false)):false}if(c.kind==="add-revision"&&(m==null?void 0:m.kind)==="text-range"){let _=en(m);if(_.length===0)return false;let Q=_.map(pe=>Z(s,pe.paraId)).filter(pe=>pe!==null).map(ge),te=ot(s),ne=(ye=c.date)!=null?ye:new Date().toISOString(),me=_.map(pe=>{var Y;return $t(s,pe.paraId,pe.from,pe.to,{revisionId:te,revisionKind:c.revisionKind,author:(Y=c.author)!=null?Y:"User",date:ne})}).filter(pe=>pe!==null);return wt(m,Q,me,false)}if(c.kind==="toggle-bold"||c.kind==="toggle-italic"||c.kind==="toggle-underline"||c.kind==="toggle-strike"||c.kind==="set-font-family"||c.kind==="set-font-size"||c.kind==="set-text-color"||c.kind==="set-highlight-color"||c.kind==="clear-text-format"){let _=en(m);if((m==null?void 0:m.kind)!=="text-range"||_.length===0)return false;let Q=_.map(Y=>Z(s,Y.paraId)).filter(Y=>Y!==null).map(ge),te=Rt(m),ne=null;if(c.kind==="toggle-bold"&&(ne={bold:te.bold!==true}),c.kind==="toggle-italic"&&(ne={italic:te.italic!==true}),c.kind==="toggle-underline"&&(ne={underline:te.underline!==true}),c.kind==="toggle-strike"&&(ne={strike:te.strike!==true}),c.kind==="set-font-family"&&c.fontFamily.trim()&&(ne={fontFamily:c.fontFamily.trim()}),c.kind==="set-font-size"&&(ne={fontSize:c.fontSize}),c.kind==="set-text-color"&&(ne={color:c.color.replace(/^#/,"").toUpperCase()}),c.kind==="set-highlight-color"&&(ne={highlight:c.color?c.color.replace(/^#/,"").toUpperCase():"none"}),c.kind!=="clear-text-format"&&!ne)return false;let me=_.map(Y=>c.kind==="clear-text-format"?uu(s,Y.paraId,Y.from,Y.to):vs(s,Y.paraId,Y.from,Y.to,ne)).filter(Y=>Y!==null);if(S){let Y=ot(s),Ie=_.map(He=>pu(s,He.paraId,He.from,He.to,Q.find(be=>be.paraId===He.paraId),{revisionId:Y,author:"User",date:new Date().toISOString()})).filter(He=>He!==null);me.push(...Ie);}let pe=c.kind==="toggle-bold"||c.kind==="toggle-italic"||c.kind==="set-font-family"||c.kind==="set-font-size"||c.kind==="clear-text-format";return wt(m,Q,me,pe)}if(c.kind==="set-paragraph-alignment"||c.kind==="set-paragraph-indent"||c.kind==="adjust-paragraph-left-indent"||c.kind==="set-paragraph-spacing"||c.kind==="set-paragraph-line-spacing"){let _=Array.from(new Set(ad(m)));if(!m||_.length===0)return false;let Q=_.map(ne=>Z(s,ne)).filter(ne=>ne!==null).map(ge),te=_.map(ne=>{var pe,Y,Ie;let me=Z(s,ne);if(!me)return null;if(c.kind==="set-paragraph-alignment")return er(s,ne,{alignment:c.alignment});if(c.kind==="set-paragraph-indent")return er(s,ne,{indent:_v(c.indent)});if(c.kind==="adjust-paragraph-left-indent"){let He=Math.max(0,((Ie=(Y=(pe=me.format)==null?void 0:pe.indent)==null?void 0:Y.left)!=null?Ie:0)+c.delta);return er(s,ne,{indent:{left:He}})}return c.kind==="set-paragraph-spacing"?er(s,ne,{spacing:qv(c.spacing)}):er(s,ne,{spacing:{line:Math.max(0,c.line),lineRule:c.lineRule}})}).filter(ne=>ne!==null);return wt(m,Q,te,c.kind!=="set-paragraph-alignment")}if(c.kind==="toggle-list"||c.kind==="remove-list"||c.kind==="adjust-list-level"){let _=Array.from(new Set(ad(m)));if(!m||_.length===0)return false;let Q=_.map(Y=>Z(s,Y)).filter(Y=>Y!==null),te=Q.map(ge),ne=c.kind==="toggle-list"&&Q.every(Y=>{var Ie;return ((Ie=Y.format)==null?void 0:Ie.hasNumbering)&&hn(Y.format.numbering)===c.listType}),me=c.kind==="toggle-list"&&!ne?(Me=$c(s,_,c.listType))!=null?Me:fs(s,c.listType):null,pe=Q.map(Y=>{var Ie,He,be,Fe,ue;if(c.kind==="remove-list"||ne)return (Ie=Y.format)!=null&&Ie.hasNumbering?jr(s,Y.paraId,null):null;if(c.kind==="toggle-list"&&me){let Je=(Fe=(be=(He=Y.format)==null?void 0:He.numbering)==null?void 0:be.ilvl)!=null?Fe:0;return jr(s,Y.paraId,ps(me,Je))}if(c.kind==="adjust-list-level"){let Je=(ue=Y.format)!=null&&ue.hasNumbering?Y.format.numbering:void 0;return Je?jr(s,Y.paraId,ps(Je,Je.ilvl+c.delta)):null}return null}).filter(Y=>Y!==null);return si(s),wt(m,te,pe,true)}return false},fd=c=>{var P;let m=(P=Oe(s,c.tableId))==null?void 0:P.table;if(!m)return null;let x=Math.min(c.anchor.rowIndex,c.focus.rowIndex),C=Math.max(c.anchor.rowIndex,c.focus.rowIndex),E=Math.min(c.anchor.columnIndex,c.focus.columnIndex),N=Math.max(c.anchor.columnIndex,c.focus.columnIndex),T=Array.from({length:C-x+1},()=>Array.from({length:N-E+1},()=>null));for(let{cell:M,rowIndex:H,columnIndex:z}of tt(m,c)){let j=T[H-x];j&&z>=E&&z<=N&&(j[z-E]={text:M.paragraphs.map(re=>Te(re)).join(`
1598
+ `),blocks:rt(M.blocks),format:Oh(M)});}return {version:1,cells:T}},Oh=c=>JSON.parse(JSON.stringify(v(v(v(v(v({},c.margin?{margin:c.margin}:{}),c.borders?{borders:c.borders}:{}),c.shading?{shading:c.shading}:{}),c.verticalAlignment?{verticalAlignment:c.verticalAlignment}:{}),c.noWrap!==void 0?{noWrap:c.noWrap}:{}))),pd=c=>c.cells.map(m=>m.map(x=>{var C;return ((C=x==null?void 0:x.text)!=null?C:"").replace(/[\t\r\n]+/g," ")}).join(" ")).join(`
1599
+ `),$h=c=>{var x,C;let m=(C=(x=c.clipboardData)==null?void 0:x.getData(al))!=null?C:"";if(!m)return null;try{let E=JSON.parse(m);if(E.version===1&&Array.isArray(E.cells)&&E.cells.every(N=>Array.isArray(N)&&N.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},zh=c=>{var C,E;let m=(E=(C=c.clipboardData)==null?void 0:C.getData("text/plain"))!=null?E:"";if(!m)return [];let x=m.replace(/\r\n?/g,`
1546
1600
  `).split(`
1547
- `);return x[x.length-1]===""&&x.pop(),x.map(I=>I.split(" "))},Da=c=>{var C,I,T;if(g&&c.clipboardData){let P=g,M=(C=Z(s,P.paraId))==null?void 0:C.content.find(F=>F.kind==="image"&&F.drawingId===P.drawingId);if(!M||M.kind!=="image")return;c.preventDefault(),c.clipboardData.setData(lo,Mi(M.src)),c.clipboardData.setData("text/html",`<img src="${Ai(M.src)}">`),Fa(P).catch(F=>{console.warn("Unable to copy the selected image",F);});return}let m=(h==null?void 0:h.kind)==="object"||(h==null?void 0:h.kind)==="table-cell-range"?h:(I=Ve(e))!=null?I:h;if((m==null?void 0:m.kind)==="table-cell-range"&&c.clipboardData){let P=ud(m);if(!P)return;c.preventDefault(),c.clipboardData.setData(al,JSON.stringify(P)),c.clipboardData.setData("text/plain",fd(P));return}if((m==null?void 0:m.kind)==="object"&&m.objectKind==="image"&&c.clipboardData){let P=(T=Z(s,m.paraId))==null?void 0:T.content.find(M=>M.kind==="image"&&M.drawingId===m.objectId);if(!P||P.kind!=="image")return;c.preventDefault(),c.clipboardData.setData(lo,Mi(P.src)),c.clipboardData.setData("text/html",`<img src="${Ai(P.src)}">`),Fa({paraId:m.paraId,drawingId:m.objectId}).catch(M=>{console.warn("Unable to copy the selected image",M);});return}if((m==null?void 0:m.kind)==="text-range"&&c.clipboardData){let P=nt(s,m),M=ws(s,P.anchor,P.focus);if(M){c.preventDefault(),c.clipboardData.setData(yi,Us(M)),c.clipboardData.setData("text/plain",Ks(M));return}}let x=ad(m);if(x===null||!c.clipboardData)return;c.preventDefault(),c.clipboardData.setData("text/plain",x);let k=sd(m);k.length>0&&c.clipboardData.setData("text/html",js(k));},Fa=async c=>{var k;let m=(k=Z(s,c.paraId))==null?void 0:k.content.find(C=>C.kind==="image"&&C.drawingId===c.drawingId);if(!m||m.kind!=="image")return;let x=await Gv(m.src);await navigator.clipboard.write([new ClipboardItem({"image/png":x})]);},pd=c=>{var C,I,T;if(d){Da(c);return}if(g&&c.clipboardData){let P=g,M=(C=Z(s,P.paraId))==null?void 0:C.content.find(j=>j.kind==="image"&&j.drawingId===P.drawingId);if(!M||M.kind!=="image")return;c.preventDefault(),c.clipboardData.setData(lo,Mi(M.src)),c.clipboardData.setData("text/html",`<img src="${Ai(M.src)}">`);let F=e.querySelector(`coco-word-native-p[data-para-id="${P.paraId}"]`),z=e.querySelector(`img[data-drawing-id="${P.drawingId}"]`);if(!F||!z)return;Nn(P.paraId,P.drawingId,{paraId:P.paraId,offset:xi(F,z)});return}let m=(h==null?void 0:h.kind)==="object"||(h==null?void 0:h.kind)==="table-cell-range"?h:(I=Ve(e))!=null?I:h;if((m==null?void 0:m.kind)==="table-cell-range"&&c.clipboardData){let P=ud(m);if(!P)return;c.preventDefault(),c.clipboardData.setData(al,JSON.stringify(P)),c.clipboardData.setData("text/plain",fd(P)),Kn(m);return}if((m==null?void 0:m.kind)==="object"&&m.objectKind==="image"&&c.clipboardData){let P=(T=Z(s,m.paraId))==null?void 0:T.content.find(M=>M.kind==="image"&&M.drawingId===m.objectId);if(!P||P.kind!=="image")return;c.preventDefault(),c.clipboardData.setData(lo,Mi(P.src)),c.clipboardData.setData("text/html",`<img src="${Ai(P.src)}">`),Nn(m.paraId,m.objectId,{paraId:m.paraId,offset:m.offset});return}if((m==null?void 0:m.kind)==="text-range"&&c.clipboardData){let P=nt(s,m),M=ws(s,P.anchor,P.focus);if(M){c.preventDefault(),c.clipboardData.setData(yi,Us(M)),c.clipboardData.setData("text/plain",Ks(M)),Oo(P,"");return}}let x=ad(m);if(x===null||(m==null?void 0:m.kind)!=="text-range"||!c.clipboardData)return;c.preventDefault(),c.clipboardData.setData("text/plain",x);let k=sd(m);k.length>0&&c.clipboardData.setData("text/html",js(k)),_n(nt(s,m),"");},md=c=>{var z,j,re,le,xe,Pe,K,J,Q,ne,ue,ce,Y,Ee,He,ge,Fe;if(d){c.preventDefault();return}let m=(h==null?void 0:h.kind)==="table-cell-range"?h:null;if(m){let de=Fh(c),Je=de?[]:Hh(c);(de&&La(m,{content:de.cells})||Je.length>0&&La(m,{text:Je}))&&c.preventDefault();return}let x=bf((j=(z=c.clipboardData)==null?void 0:z.getData(yi))!=null?j:"");if(x){let de=(le=(re=Ve(e))!=null?re:h)!=null?le:lt(e);if(!de||de.kind==="object"||de.kind==="table-cell-range")return;let Je=de.kind==="text-range"?nt(s,de):{anchor:{paraId:de.paraId,offset:de.offset},focus:{paraId:de.paraId,offset:de.offset}};if(Ih(Je,x)){c.preventDefault();return}}let k=zv((Pe=(xe=c.clipboardData)==null?void 0:xe.getData(lo))!=null?Pe:"");if(k){let de=(J=(K=Ve(e))!=null?K:h)!=null?J:lt(e);if(!de||de.kind==="object"||de.kind==="table-cell-range")return;let Je=de.kind==="text-range"?nt(s,de):{anchor:{paraId:de.paraId,offset:de.offset},focus:{paraId:de.paraId,offset:de.offset}};c.preventDefault(),Wa(Je,k);return}let C=Array.from((ne=(Q=c.clipboardData)==null?void 0:Q.files)!=null?ne:[]).find(de=>de.type.startsWith("image/"));if(C){let de=(ce=(ue=Ve(e))!=null?ue:h)!=null?ce:lt(e);if(!de||de.kind==="object"||de.kind==="table-cell-range")return;let Je=de.kind==="text-range"?nt(s,de):{anchor:{paraId:de.paraId,offset:de.offset},focus:{paraId:de.paraId,offset:de.offset}};c.preventDefault(),gp(C).then(fe=>Wa(Je,fe));return}let I=(Ee=(Y=c.clipboardData)==null?void 0:Y.getData("text/html"))!=null?Ee:"",T=I?gf(I):[],P=T.length>0?T.map(de=>de.text).join(`
1548
- `):(He=c.clipboardData)==null?void 0:He.getData("text/plain");if(P===void 0)return;let M=(Fe=(ge=Ve(e))!=null?ge:h)!=null?Fe:lt(e);if(!M||M.kind==="object"||M.kind==="table-cell-range")return;let F=M.kind==="text-range"?nt(s,M):{anchor:{paraId:M.paraId,offset:M.offset},focus:{paraId:M.paraId,offset:M.offset}};c.preventDefault(),_n(F,P,T.length>0?T:void 0);},Oh=()=>{var m;let c=(m=h!=null?h:Ve(e))!=null?m:lt(e);return (c==null?void 0:c.kind)==="object"&&c.objectKind==="image"?Nn(c.paraId,c.objectId,{paraId:c.paraId,offset:c.offset}):(c==null?void 0:c.kind)==="text-range"?_n(nt(s,c),""):(c==null?void 0:c.kind)==="table-cell-range"?Kn(c):false},$h=async()=>{var c,m;if(typeof((c=navigator.clipboard)==null?void 0:c.readText)=="function")try{let x=await navigator.clipboard.readText(),k=(m=h!=null?h:Ve(e))!=null?m:lt(e);if(!k||k.kind==="object")return;if(k.kind==="table-cell-range"){let I=x.replace(/\r\n?/g,`
1601
+ `);return x[x.length-1]===""&&x.pop(),x.map(N=>N.split(" "))},Ha=c=>{var E,N,T;if(g&&c.clipboardData){let P=g,M=(E=Z(s,P.paraId))==null?void 0:E.content.find(H=>H.kind==="image"&&H.drawingId===P.drawingId);if(!M||M.kind!=="image")return;c.preventDefault(),c.clipboardData.setData(co,Wi(M.src)),c.clipboardData.setData("text/html",`<img src="${Bi(M.src)}">`),Oa(P).catch(H=>{console.warn("Unable to copy the selected image",H);});return}let m=(h==null?void 0:h.kind)==="object"||(h==null?void 0:h.kind)==="table-cell-range"?h:(N=ze(e))!=null?N:h;if((m==null?void 0:m.kind)==="table-cell-range"&&c.clipboardData){let P=fd(m);if(!P)return;c.preventDefault(),c.clipboardData.setData(al,JSON.stringify(P)),c.clipboardData.setData("text/plain",pd(P));return}if((m==null?void 0:m.kind)==="object"&&m.objectKind==="image"&&c.clipboardData){let P=(T=Z(s,m.paraId))==null?void 0:T.content.find(M=>M.kind==="image"&&M.drawingId===m.objectId);if(!P||P.kind!=="image")return;c.preventDefault(),c.clipboardData.setData(co,Wi(P.src)),c.clipboardData.setData("text/html",`<img src="${Bi(P.src)}">`),Oa({paraId:m.paraId,drawingId:m.objectId}).catch(M=>{console.warn("Unable to copy the selected image",M);});return}if((m==null?void 0:m.kind)==="text-range"&&c.clipboardData){let P=nt(s,m),M=xs(s,P.anchor,P.focus);if(M){c.preventDefault(),c.clipboardData.setData(ki,Us(M)),c.clipboardData.setData("text/plain",Ks(M));return}}let x=sd(m);if(x===null||!c.clipboardData)return;c.preventDefault(),c.clipboardData.setData("text/plain",x);let C=ld(m);C.length>0&&c.clipboardData.setData("text/html",js(C));},Oa=async c=>{var C;let m=(C=Z(s,c.paraId))==null?void 0:C.content.find(E=>E.kind==="image"&&E.drawingId===c.drawingId);if(!m||m.kind!=="image")return;let x=await Kv(m.src);await navigator.clipboard.write([new ClipboardItem({"image/png":x})]);},md=c=>{var E,N,T;if(d){Ha(c);return}if(g&&c.clipboardData){let P=g,M=(E=Z(s,P.paraId))==null?void 0:E.content.find(j=>j.kind==="image"&&j.drawingId===P.drawingId);if(!M||M.kind!=="image")return;c.preventDefault(),c.clipboardData.setData(co,Wi(M.src)),c.clipboardData.setData("text/html",`<img src="${Bi(M.src)}">`);let H=e.querySelector(`coco-word-native-p[data-para-id="${P.paraId}"]`),z=e.querySelector(`img[data-drawing-id="${P.drawingId}"]`);if(!H||!z)return;Pn(P.paraId,P.drawingId,{paraId:P.paraId,offset:Si(H,z)});return}let m=(h==null?void 0:h.kind)==="object"||(h==null?void 0:h.kind)==="table-cell-range"?h:(N=ze(e))!=null?N:h;if((m==null?void 0:m.kind)==="table-cell-range"&&c.clipboardData){let P=fd(m);if(!P)return;c.preventDefault(),c.clipboardData.setData(al,JSON.stringify(P)),c.clipboardData.setData("text/plain",pd(P)),qn(m);return}if((m==null?void 0:m.kind)==="object"&&m.objectKind==="image"&&c.clipboardData){let P=(T=Z(s,m.paraId))==null?void 0:T.content.find(M=>M.kind==="image"&&M.drawingId===m.objectId);if(!P||P.kind!=="image")return;c.preventDefault(),c.clipboardData.setData(co,Wi(P.src)),c.clipboardData.setData("text/html",`<img src="${Bi(P.src)}">`),Pn(m.paraId,m.objectId,{paraId:m.paraId,offset:m.offset});return}if((m==null?void 0:m.kind)==="text-range"&&c.clipboardData){let P=nt(s,m),M=xs(s,P.anchor,P.focus);if(M){c.preventDefault(),c.clipboardData.setData(ki,Us(M)),c.clipboardData.setData("text/plain",Ks(M)),Oo(P,"");return}}let x=sd(m);if(x===null||(m==null?void 0:m.kind)!=="text-range"||!c.clipboardData)return;c.preventDefault(),c.clipboardData.setData("text/plain",x);let C=ld(m);C.length>0&&c.clipboardData.setData("text/html",js(C)),Xn(nt(s,m),"");},hd=c=>{var z,j,re,ce,ye,Me,_,Q,te,ne,me,pe,Y,Ie,He,be,Fe;if(d){c.preventDefault();return}let m=(h==null?void 0:h.kind)==="table-cell-range"?h:null;if(m){let ue=$h(c),Je=ue?[]:zh(c);(ue&&Ba(m,{content:ue.cells})||Je.length>0&&Ba(m,{text:Je}))&&c.preventDefault();return}let x=yf((j=(z=c.clipboardData)==null?void 0:z.getData(ki))!=null?j:"");if(x){let ue=(ce=(re=ze(e))!=null?re:h)!=null?ce:lt(e);if(!ue||ue.kind==="object"||ue.kind==="table-cell-range")return;let Je=ue.kind==="text-range"?nt(s,ue):{anchor:{paraId:ue.paraId,offset:ue.offset},focus:{paraId:ue.paraId,offset:ue.offset}};if(Ph(Je,x)){c.preventDefault();return}}let C=jv((Me=(ye=c.clipboardData)==null?void 0:ye.getData(co))!=null?Me:"");if(C){let ue=(Q=(_=ze(e))!=null?_:h)!=null?Q:lt(e);if(!ue||ue.kind==="object"||ue.kind==="table-cell-range")return;let Je=ue.kind==="text-range"?nt(s,ue):{anchor:{paraId:ue.paraId,offset:ue.offset},focus:{paraId:ue.paraId,offset:ue.offset}};c.preventDefault(),Da(Je,C);return}let E=Array.from((ne=(te=c.clipboardData)==null?void 0:te.files)!=null?ne:[]).find(ue=>ue.type.startsWith("image/"));if(E){let ue=(pe=(me=ze(e))!=null?me:h)!=null?pe:lt(e);if(!ue||ue.kind==="object"||ue.kind==="table-cell-range")return;let Je=ue.kind==="text-range"?nt(s,ue):{anchor:{paraId:ue.paraId,offset:ue.offset},focus:{paraId:ue.paraId,offset:ue.offset}};c.preventDefault(),xp(E).then(he=>Da(Je,he));return}let N=(Ie=(Y=c.clipboardData)==null?void 0:Y.getData("text/html"))!=null?Ie:"",T=N?xf(N):[],P=T.length>0?T.map(ue=>ue.text).join(`
1602
+ `):(He=c.clipboardData)==null?void 0:He.getData("text/plain");if(P===void 0)return;let M=(Fe=(be=ze(e))!=null?be:h)!=null?Fe:lt(e);if(!M||M.kind==="object"||M.kind==="table-cell-range")return;let H=M.kind==="text-range"?nt(s,M):{anchor:{paraId:M.paraId,offset:M.offset},focus:{paraId:M.paraId,offset:M.offset}};c.preventDefault(),Xn(H,P,T.length>0?T:void 0);},Vh=()=>{var m;let c=(m=h!=null?h:ze(e))!=null?m:lt(e);return (c==null?void 0:c.kind)==="object"&&c.objectKind==="image"?Pn(c.paraId,c.objectId,{paraId:c.paraId,offset:c.offset}):(c==null?void 0:c.kind)==="text-range"?Xn(nt(s,c),""):(c==null?void 0:c.kind)==="table-cell-range"?qn(c):false},Gh=async()=>{var c,m;if(typeof((c=navigator.clipboard)==null?void 0:c.readText)=="function")try{let x=await navigator.clipboard.readText(),C=(m=h!=null?h:ze(e))!=null?m:lt(e);if(!C||C.kind==="object")return;if(C.kind==="table-cell-range"){let N=x.replace(/\r\n?/g,`
1549
1603
  `).split(`
1550
- `).map(T=>T.split(" "));La(k,{text:I});return}let C=k.kind==="text-range"?nt(s,k):{anchor:{paraId:k.paraId,offset:k.offset},focus:{paraId:k.paraId,offset:k.offset}};_n(C,x);}catch(x){console.warn("Unable to paste from the context menu",x);}},Ha=(c="add",m,x="")=>{let k=document.createElement("div");k.className="coco-word-dialog-backdrop";let C=document.createElement("section");C.className="coco-word-dialog",C.setAttribute("role","dialog"),C.setAttribute("aria-modal","true"),C.setAttribute("aria-labelledby","coco-word-comment-dialog-title");let I=document.createElement("h2");I.id="coco-word-comment-dialog-title",I.textContent=c==="edit"?"\u7F16\u8F91\u6279\u6CE8":c==="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 M=document.createElement("button");M.type="button",M.className="coco-word-dialog-button is-secondary",M.textContent="\u53D6\u6D88";let F=document.createElement("button");F.type="button",F.className="coco-word-dialog-button is-primary",F.textContent="\u786E\u5B9A";let z=()=>k.remove();M.addEventListener("click",z),k.addEventListener("click",j=>{j.target===k&&z();}),C.addEventListener("keydown",j=>{j.key==="Escape"&&z(),j.key==="Enter"&&(j.ctrlKey||j.metaKey)&&(j.preventDefault(),F.click());}),F.addEventListener("click",()=>{let j=T.value.trim();if(!j){T.focus();return}Se(c==="edit"&&m!==void 0?{kind:"edit-comment",commentId:m,body:j}:c==="reply"&&m!==void 0?{kind:"reply-comment",commentId:m,body:j}:{kind:"add-comment",body:j}),z();}),P.append(M,F),C.append(I,T,P),k.appendChild(C),(o!=null?o:document.body).appendChild(k),T.focus();},zh=()=>{var C,I,T;let c=(C=h!=null?h:Ve(e))!=null?C:lt(e),m=Rt(c),x=(c==null?void 0:c.kind)==="text-range"||(c==null?void 0:c.kind)==="object"||(c==null?void 0:c.kind)==="table-cell-range",k=[{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:(c==null?void 0:c.kind)==="object"||typeof((I=navigator.clipboard)==null?void 0:I.readText)!="function",action:$h},{label:"\u5220\u9664",disabled:!x,action:()=>Oh()}];if((c==null?void 0:c.kind)==="text-range"&&(k.push({label:"\u6DFB\u52A0\u6279\u6CE8",separatorBefore:true,action:Ha}),k.push({label:"\u6807\u8BB0\u4E3A\u63D2\u5165\u4FEE\u8BA2",action:()=>Se({kind:"add-revision",revisionKind:"insert"})}),k.push({label:"\u6807\u8BB0\u4E3A\u5220\u9664\u4FEE\u8BA2",action:()=>Se({kind:"add-revision",revisionKind:"delete"})}),k.push({label:m.bold===true?"\u53D6\u6D88\u52A0\u7C97":"\u52A0\u7C97",separatorBefore:true,disabled:!Wt(s,c,{kind:"toggle-bold"}),action:()=>Se({kind:"toggle-bold"})}),k.push({label:"\u6E05\u9664\u6587\u672C\u683C\u5F0F",action:()=>Se({kind:"clear-text-format"})}),m.hyperlink!==null&&k.push({label:"\u79FB\u9664\u8D85\u94FE\u63A5",disabled:!Wt(s,c,{kind:"remove-hyperlink"}),action:()=>Se({kind:"remove-hyperlink"})})),(c==null?void 0:c.kind)==="caret"&&Wt(s,c,{kind:"insert-table",rows:2,columns:2})&&k.push({label:"\u63D2\u5165 2 \xD7 2 \u8868\u683C",separatorBefore:true,action:()=>Se({kind:"insert-table",rows:2,columns:2})}),(c==null?void 0:c.kind)==="object"&&c.objectKind==="image"&&(k.push({label:"\u56FE\u7247\u5DE6\u5BF9\u9F50",separatorBefore:true,action:()=>Se({kind:"set-image-alignment",objectId:c.objectId,alignment:"left"})}),k.push({label:"\u56FE\u7247\u5C45\u4E2D",action:()=>Se({kind:"set-image-alignment",objectId:c.objectId,alignment:"center"})}),k.push({label:"\u56FE\u7247\u53F3\u5BF9\u9F50",action:()=>Se({kind:"set-image-alignment",objectId:c.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};k.push({label:"\u9009\u62E9\u6574\u884C",separatorBefore:true,action:()=>ie({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)}})}),k.push({label:"\u9009\u62E9\u6574\u5217",action:()=>ie({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}})}),k.push({label:"\u5728\u4E0A\u65B9\u63D2\u5165\u884C",disabled:!Wt(s,c,{kind:"insert-table-row"}),action:()=>Se({kind:"insert-table-row",position:"before"})}),k.push({label:"\u5728\u4E0B\u65B9\u63D2\u5165\u884C",disabled:!Wt(s,c,{kind:"insert-table-row"}),action:()=>Se({kind:"insert-table-row",position:"after"})}),k.push({label:"\u5220\u9664\u5F53\u524D\u884C",disabled:!Wt(s,c,{kind:"delete-table-row"}),action:()=>Se({kind:"delete-table-row"})}),k.push({label:"\u5728\u5DE6\u4FA7\u63D2\u5165\u5217",disabled:!Wt(s,c,{kind:"insert-table-column"}),action:()=>Se({kind:"insert-table-column",position:"before"})}),k.push({label:"\u5728\u53F3\u4FA7\u63D2\u5165\u5217",disabled:!Wt(s,c,{kind:"insert-table-column"}),action:()=>Se({kind:"insert-table-column",position:"after"})}),k.push({label:"\u5220\u9664\u5F53\u524D\u5217",disabled:!Wt(s,c,{kind:"delete-table-column"}),action:()=>Se({kind:"delete-table-column"})}),k.push({label:"\u5220\u9664\u8868\u683C",separatorBefore:true,disabled:!Wt(s,c,{kind:"delete-table"}),action:()=>Se({kind:"delete-table"})});for(let[M,F]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"]])k.push({label:M,action:()=>Se({kind:"set-table-cell-vertical-alignment",alignment:F})});}return k.push({label:"\u64A4\u9500",separatorBefore:true,disabled:!U.length,action:()=>Cr()},{label:"\u91CD\u505A",disabled:!X.length,action:()=>Er()}),k},Vh=c=>{var I,T;let m=c.target;if(m instanceof HTMLImageElement){let P=Nt(m),M=P==null?void 0:P.dataset.paraId,F=m.dataset.drawingId;if(P&&M&&F){let z={kind:"object",paraId:M,objectKind:"image",objectId:F,offset:xi(P,m)};return g={paraId:M,drawingId:F},_t(),ie(z),z}}let x=pt(m);if(x){if((h==null?void 0:h.kind)==="table-cell-range"&&h.tableId===x.tableId){let M=Math.min(h.anchor.rowIndex,h.focus.rowIndex),F=Math.max(h.anchor.rowIndex,h.focus.rowIndex),z=Math.min(h.anchor.columnIndex,h.focus.columnIndex),j=Math.max(h.anchor.columnIndex,h.focus.columnIndex);if(x.point.rowIndex>=M&&x.point.rowIndex<=F&&x.point.columnIndex>=z&&x.point.columnIndex<=j)return h}let P={kind:"table-cell-range",tableId:x.tableId,anchor:x.point,focus:x.point};return (I=Tt(e))==null||I.removeAllRanges(),ie(P),P}let k=(T=lf(e,c.clientX,c.clientY))!=null?T:mt(e);if(!k)return h;if((h==null?void 0:h.kind)==="text-range"){let P=nt(s,h),M=ye(s,P.anchor.paraId),F=ye(s,P.focus.paraId),z=ye(s,k.paraId);if(M&&F&&z&&M.container===F.container&&M.container===z.container){let j=z.index>M.index||z.index===M.index&&k.offset>=P.anchor.offset,re=z.index<F.index||z.index===F.index&&k.offset<=P.focus.offset;if(j&&re)return h}}g=null,Pt(e),dt(e,k);let C=v({kind:"caret"},k);return ie(C),C},hd=c=>{var k;if(d||n.contextMenu===false)return;c.preventDefault(),c.stopPropagation(),ut(),gt(),Vh(c);let m=document.createElement("div");m.className="coco-word-context-menu",m.setAttribute("role","menu"),m.contentEditable="false";for(let C of zh()){if(C.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=C.label,I.disabled=(k=C.disabled)!=null?k:false,I.setAttribute("role","menuitem"),I.addEventListener("mousedown",T=>T.preventDefault()),I.addEventListener("click",()=>{let T=C.action();gt(),T instanceof Promise&&T.catch(P=>console.warn("Context menu action failed",P));}),m.appendChild(I);}(o!=null?o:document.body).appendChild(m),Kt=m;let x=m.getBoundingClientRect();m.style.left=`${Math.max(4,Math.min(c.clientX,window.innerWidth-x.width-4))}px`,m.style.top=`${Math.max(4,Math.min(c.clientY,window.innerHeight-x.height-4))}px`;},gd=c=>{Kt&&!Kt.contains(c.target)&&gt();},bd=c=>{c.key==="Escape"&&gt();},wd=c=>{var C;if(d){c.preventDefault();return}if(c.inputType===D){c.preventDefault(),D=null,G!==null&&window.clearTimeout(G),G=null;return}if(c.inputType==="historyUndo"&&Cr()){c.preventDefault(),c.stopPropagation();return}if(c.inputType==="historyRedo"&&Er()){c.preventDefault(),c.stopPropagation();return}if(c.isComposing||me||we||c.inputType==="insertCompositionText"||c.inputType==="deleteCompositionText"||c.inputType==="insertFromComposition")return;if(g&&c.inputType==="deleteContentBackward"){c.preventDefault();let I={paraId:g.paraId,offset:0};Nn(g.paraId,g.drawingId,I);return}let m=Ve(e),x=(m==null?void 0:m.kind)==="text-range"?m:(h==null?void 0:h.kind)==="text-range"?h:m;if(S&&x&&(c.inputType==="insertText"||c.inputType==="deleteContentBackward"||c.inputType==="deleteContentForward")){if(x.kind==="caret"||x.kind==="text-range"&&x.anchor.paraId===x.focus.paraId){c.preventDefault(),c.inputType==="insertText"&&c.data?x.kind==="caret"?Se({kind:"insert-text",text:c.data}):Se({kind:"replace-range",anchor:x.anchor,focus:x.focus,text:c.data}):c.inputType==="deleteContentBackward"?x.kind==="text-range"&&x.anchor.offset!==x.focus.offset?Se({kind:"delete-range",anchor:x.anchor,focus:x.focus}):Se({kind:"delete-backward"}):c.inputType==="deleteContentForward"&&(x.kind==="text-range"&&x.anchor.offset!==x.focus.offset?Se({kind:"delete-range",anchor:x.anchor,focus:x.focus}):Se({kind:"delete-forward"}));return}if(x.kind==="text-range"&&(c.inputType==="deleteContentBackward"||c.inputType==="deleteContentForward")){c.preventDefault(),Se({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=Ri(x.anchor.offset,x.focus.offset);if(Do(x.anchor.paraId)&&(c.inputType==="insertText"&&c.data||c.inputType==="deleteContentBackward"||c.inputType==="deleteContentForward")){g=null,Sr(x.anchor.paraId),Fo({anchor:{paraId:x.anchor.paraId,offset:I.from},focus:{paraId:x.focus.paraId,offset:I.to}}),ie(x);return}if(c.inputType==="insertText"&&c.data){c.preventDefault(),g=null,ie({kind:"caret",paraId:x.anchor.paraId,offset:I.from+c.data.length}),In(zr(s,x.anchor.paraId,I.from,I.to,c.data),{paraId:x.anchor.paraId,offset:I.from+c.data.length},{localParaId:x.anchor.paraId});return}if(c.inputType==="deleteContentBackward"||c.inputType==="deleteContentForward"){if(c.preventDefault(),g=null,$o(x))return;ie({kind:"caret",paraId:x.anchor.paraId,offset:I.from}),In(bn(s,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=nt(s,x);if(c.inputType==="insertText"&&c.data){if(c.preventDefault(),g=null,Oo(I,c.data))return;od(I,c.data);return}if(c.inputType==="deleteContentBackward"||c.inputType==="deleteContentForward"){if(Oo(I,"")){c.preventDefault();return}if(!Eh(I)&&vh(I)){g=null,ie({kind:"caret",paraId:I.anchor.paraId,offset:I.anchor.offset});return}c.preventDefault(),g=null,ie({kind:"caret",paraId:I.anchor.paraId,offset:I.anchor.offset}),od(I,"");return}c.preventDefault(),ie(x);return}let k=(x==null?void 0:x.kind)==="caret"?x:mt(e);if(k){if(g=null,ie({kind:"caret",paraId:k.paraId,offset:k.offset}),c.inputType==="insertText"&&c.data&&c.data!==`
1551
- `&&c.data!=="\r"&&Do(k.paraId)){Sr(k.paraId),Fo({anchor:k,focus:k});return}if(c.inputType==="deleteContentBackward"&&k.offset>0&&Do(k.paraId)){Sr(k.paraId),Fo({anchor:k,focus:k});return}if(c.inputType==="deleteContentForward"&&k.offset<Ra(k.paraId)&&Do(k.paraId)){Sr(k.paraId),Fo({anchor:k,focus:k});return}if(c.inputType==="insertText"&&(c.data===`
1552
- `||c.data==="\r")||c.inputType==="insertParagraph"){if(c.preventDefault(),N){N=false,A!==null&&window.clearTimeout(A),A=null;return}Ba(k);}else if(c.inputType==="insertText"&&c.data)c.preventDefault(),In(on(s,k.paraId,k.offset,c.data),{paraId:k.paraId,offset:k.offset+c.data.length},{localParaId:k.paraId});else if(c.inputType==="deleteContentBackward"){if(c.preventDefault(),Tn(k,"delete-backward")||zo(v({kind:"caret"},k),"backward")||ld(k))return;let I=Z(s,k.paraId),T=I?he(I):null,P=Or(s,k.paraId,k.offset),M={paraId:k.offset>0?k.paraId:(C=ss(s,k.paraId))!=null?C:k.paraId,offset:Math.max(0,k.offset-1)};(P==null?void 0:P.kind)==="image"?Ir(T,P,M):In(P,M,(P==null?void 0:P.kind)==="block"?{}:{localParaId:k.paraId});}else if(c.inputType==="deleteContentForward"){if(c.preventDefault(),Tn(k,"delete-forward")||zo(v({kind:"caret"},k),"forward")||dd(k))return;let I=Z(s,k.paraId),T=I?he(I):null,P=$r(s,k.paraId,k.offset),M={paraId:k.paraId,offset:k.offset};(P==null?void 0:P.kind)==="image"?Ir(T,P,M):In(P,M,{localParaId:k.paraId});}}},Vo=c=>{var M,F,z,j,re,le,xe,Pe;if(l)return;if(c.currentTarget===document){if(c.composedPath().includes(e)||so.get(document)!==e)return}else ut();if(me||c.isComposing||c.keyCode===229)return;if((c.ctrlKey||c.metaKey)&&!c.shiftKey&&c.key.toLowerCase()==="c"&&g&&typeof((M=navigator.clipboard)==null?void 0:M.write)=="function"&&typeof ClipboardItem!="undefined"){let K=g;c.preventDefault(),c.stopPropagation(),Fa(K).catch(J=>{console.warn("Unable to copy the selected image",J);});return}if(d){(c.ctrlKey||c.metaKey)&&(c.key.toLowerCase()==="z"||c.key.toLowerCase()==="y")&&(c.preventDefault(),c.stopPropagation());return}let x=(c.ctrlKey||c.metaKey)&&!c.shiftKey&&c.key.toLowerCase()==="z",k=(c.ctrlKey||c.metaKey)&&c.shiftKey&&c.key.toLowerCase()==="z"||(c.ctrlKey||c.metaKey)&&c.key.toLowerCase()==="y";(x||k)&&D&&(D=null,G!==null&&window.clearTimeout(G),G=null);let C=x||k?mt(e):null,I=(F=C==null?void 0:C.paraId)!=null?F:h&&"paraId"in h?h.paraId:null;if(x&&Cr()){Jl("historyUndo"),c.preventDefault(),c.stopPropagation();return}if(k&&Er()){Jl("historyRedo"),c.preventDefault(),c.stopPropagation();return}if((c.ctrlKey||c.metaKey)&&!c.shiftKey&&c.key==="Enter"){let K=(z=h!=null?h:Ve(e))!=null?z:lt(e);(K==null?void 0:K.kind)==="caret"&&Se({kind:"insert-page-break"})&&(c.preventDefault(),c.stopPropagation());return}if((x||k)&&(V!==null&&window.clearTimeout(V),Bo.disconnect(),V=window.setTimeout(()=>{var ue,ce;V=null;let K=mt(e),J=(ue=K==null?void 0:K.paraId)!=null?ue:I;if(!J)return;let Q=e.querySelector(`coco-word-native-p[data-para-id="${J}"]`),ne=Z(s,J);if(Q&&ne&&ne.content.every(Y=>Y.kind==="text")){let Y=Gr(s,J,(ce=Q.textContent)!=null?ce:"");Y&&(u.push(Y),Te("deferred"));}De(J,K!=null?K:void 0);},120)),(h==null?void 0:h.kind)==="table-cell-range"){if(c.key==="Escape"){c.preventDefault(),ie(null);return}if(c.key==="Enter"||c.key==="F2"){let J=(j=Oe(s,h.tableId))==null?void 0:j.table,Q=J?(re=tt(J,h)[0])==null?void 0:re.cell:null,ne=Q==null?void 0:Q.paragraphs[0];if(ne){c.preventDefault();let ue={paraId:ne.paraId,offset:Ne(ne).length};dt(e,ue),ie(v({kind:"caret"},ue));}return}let K=c.key==="ArrowLeft"?{row:0,column:-1}:c.key==="ArrowRight"?{row:0,column:1}:c.key==="ArrowUp"?{row:-1,column:0}:c.key==="ArrowDown"?{row:1,column:0}:null;if(K){let J=(le=Oe(s,h.tableId))==null?void 0:le.table,Q=J?Math.max(1,...J.rows.map(ue=>ue.cells.reduce((ce,Y)=>ce+Math.max(1,Y.gridSpan),0))):1,ne={rowIndex:Math.max(0,Math.min(((xe=J==null?void 0:J.rows.length)!=null?xe:1)-1,h.focus.rowIndex+K.row)),columnIndex:Math.max(0,Math.min(Q-1,h.focus.columnIndex+K.column))};c.preventDefault(),ie({kind:"table-cell-range",tableId:h.tableId,anchor:c.shiftKey?h.anchor:ne,focus:ne});return}}if(!c.shiftKey&&["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"].includes(c.key)&&($=null),g&&(c.key==="Backspace"||c.key==="Delete")){c.preventDefault();let K={paraId:g.paraId,offset:0};Nn(g.paraId,g.drawingId,K);return}if((h==null?void 0:h.kind)==="table-cell-range"&&(c.key==="Backspace"||c.key==="Delete")){c.preventDefault(),c.stopPropagation(),Kn(h);return}if(c.key!=="Enter")return;let T=mt(e);if(!T)return;c.preventDefault(),c.stopPropagation();let P=Z(s,T.paraId);if((Pe=P==null?void 0:P.format)!=null&&Pe.hasNumbering&&P.format.numbering&&Ne(P).length===0){g=null,ie({kind:"caret",paraId:T.paraId,offset:0}),Se({kind:"remove-list"});return}g=null,N=true,A!==null&&window.clearTimeout(A),A=window.setTimeout(()=>{N=false,A=null;},0),Ba(T);},xd=c=>{if(!(l||c.composedPath().includes(e)||so.get(document)!==e)){if(d){c.preventDefault(),c.stopPropagation();return}(c.inputType==="historyUndo"&&Cr()||c.inputType==="historyRedo"&&Er())&&(c.preventDefault(),c.stopPropagation());}},Oa=(c,m)=>{let x=c.querySelector(":scope > .coco-word-native-revision-group-list"),k=c.querySelector(":scope > .coco-word-native-revision-group-toggle");if(!x||!k)return;c.classList.toggle("is-expanded",m),x.hidden=!m,k.setAttribute("aria-expanded",String(m));let C=k.querySelector(".coco-word-native-revision-group-affordance");C&&(C.textContent=m?"\u6536\u8D77":"\u5C55\u5F00");},yd=c=>{e.querySelectorAll(".coco-word-native-revision-group.is-expanded").forEach(m=>{m!==c&&Oa(m,false);});},vd=c=>{var Pe,K,J,Q,ne,ue,ce,Y,Ee,He;let m=(Pe=c.composedPath().find(ge=>ge instanceof HTMLButtonElement&&ge.matches("[data-revision-action][data-revision-id]")))!=null?Pe:c.target instanceof Element?c.target.closest("[data-revision-action][data-revision-id]"):null;if(m){c.preventDefault(),c.stopPropagation();let ge=m.dataset.revisionId;ge&&Se({kind:m.dataset.revisionAction==="accept"?"accept-revision":"reject-revision",revisionId:ge,revisionKind:m.dataset.revisionKind});return}let x=(K=c.composedPath().find(ge=>ge instanceof HTMLButtonElement&&ge.matches("[data-revision-group-toggle]")))!=null?K:c.target instanceof Element?c.target.closest("[data-revision-group-toggle]"):null;if(x){c.preventDefault(),c.stopPropagation();let ge=x.closest(".coco-word-native-revision-group"),Fe=ge==null?void 0:ge.querySelector(":scope > .coco-word-native-revision-group-list");if(!ge||!Fe)return;let de=Fe.hidden;yd(ge),Oa(ge,de);return}let k=(J=c.composedPath().find(ge=>ge instanceof HTMLButtonElement&&ge.matches("[data-comment-menu][data-comment-id]")))!=null?J:c.target instanceof Element?c.target.closest("[data-comment-menu][data-comment-id]"):null;if(k){c.preventDefault(),c.stopPropagation();let ge=k.dataset.commentId;if(!ge)return;let Fe=(Q=k.parentElement)==null?void 0:Q.querySelector(`[data-comment-menu-for="${CSS.escape(ge)}"]`);if(!Fe)return;e.querySelectorAll(".coco-word-native-comment-menu:not([hidden])").forEach(de=>{de!==Fe&&(de.hidden=true);}),Fe.hidden=!Fe.hidden;return}let C=(ne=c.composedPath().find(ge=>ge instanceof HTMLButtonElement&&ge.matches("[data-comment-action][data-comment-id]")))!=null?ne:c.target instanceof Element?c.target.closest("[data-comment-action][data-comment-id]"):null;if(C){c.preventDefault(),c.stopPropagation();let ge=Number(C.dataset.commentId);if(!Number.isFinite(ge))return;let Fe=C.closest(".coco-word-native-comment-bubble");C.dataset.commentAction==="edit"?Ha("edit",ge,(ue=Fe==null?void 0:Fe.dataset.commentBody)!=null?ue:""):C.dataset.commentAction==="reply"?Ha("reply",ge):Se({kind:"delete-comment",commentId:ge});return}if(Le){Le=false,c.preventDefault(),c.stopPropagation();return}if(jn){jn=false,c.preventDefault(),c.stopPropagation();return}if(Ge){c.preventDefault(),c.stopPropagation(),at(true),queueMicrotask(()=>{Ge=false,at(true);});return}ut(),$=null;let I=c.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,M=I instanceof Element?I.closest(".coco-word-native-comment-bubble, .coco-word-native-revision-bubble"):null,F=M!=null?M:T?e.querySelector(`.coco-word-native-comment-bubble[data-comment-id="${CSS.escape((ce=T.dataset.commentId)!=null?ce:"")}"]`):P?e.querySelector(`.coco-word-native-revision-bubble[data-revision-id="${CSS.escape((Y=P.dataset.revisionId)!=null?Y:"")}"][data-revision-kind="${CSS.escape((Ee=P.dataset.revisionKind)!=null?Ee:P.classList.contains("coco-word-revision-delete")?"delete":"insert")}"]`):null;if(F){let ge=F.closest(".coco-word-native-revision-group");ge&&(yd(ge),Oa(ge,true));let Fe=F.dataset.paraId,de=Number(F.dataset.from),Je=Number(F.dataset.to);if(Fe&&Number.isFinite(de)&&Number.isFinite(Je)){c.preventDefault(),c.stopPropagation(),e.querySelectorAll(".coco-word-native-comment-bubble.is-selected, .coco-word-native-revision-bubble.is-selected").forEach(We=>We.classList.remove("is-selected")),F.classList.add("is-selected");let fe={kind:"text-range",anchor:{paraId:Fe,offset:de},focus:{paraId:Fe,offset:Math.max(de+1,Je)}};ie(fe);let be=T!=null?T:(()=>{var Ke,je,tn,Rn,qn,Uo;let We=M==null?void 0:M.closest("coco-word-native-page");if(!We)return null;let ae=F.dataset.revisionKind?`.coco-word-revision-insert[data-revision-id="${CSS.escape((Ke=F.dataset.revisionId)!=null?Ke:"")}"], .coco-word-revision-delete[data-revision-id="${CSS.escape((je=F.dataset.revisionId)!=null?je:"")}"], .coco-word-revision-format[data-revision-id="${CSS.escape((tn=F.dataset.revisionId)!=null?tn:"")}"], img[data-revision-id="${CSS.escape((Rn=F.dataset.revisionId)!=null?Rn:"")}"], coco-word-native-table[data-revision-id="${CSS.escape((qn=F.dataset.revisionId)!=null?qn:"")}"]`:`.coco-word-comment[data-comment-id="${CSS.escape((Uo=F.dataset.commentId)!=null?Uo:"")}"]`;return We.querySelector(ae)})();(!be||!df(e,be))&&vn(e,fe.anchor,fe.focus);return}}let z=pt(I);if(z){if(c.preventDefault(),c.stopPropagation(),g=null,Pt(e),(He=Tt(e))==null||He.removeAllRanges(),(h==null?void 0:h.kind)==="table-cell-range"&&h.tableId===z.tableId&&z.point.rowIndex>=Math.min(h.anchor.rowIndex,h.focus.rowIndex)&&z.point.rowIndex<=Math.max(h.anchor.rowIndex,h.focus.rowIndex)&&z.point.columnIndex>=Math.min(h.anchor.columnIndex,h.focus.columnIndex)&&z.point.columnIndex<=Math.max(h.anchor.columnIndex,h.focus.columnIndex))return;ie({kind:"table-cell-range",tableId:z.tableId,anchor:z.point,focus:z.point});return}let j=I instanceof Element?I.closest("a.coco-word-hyperlink"):null;if(j){if(d)return;if(c.preventDefault(),(c.ctrlKey||c.metaKey)&&Hv(j.dataset.hyperlinkTarget)){window.open(j.dataset.hyperlinkTarget,"_blank","noopener,noreferrer");return}}if(!(I instanceof HTMLImageElement)){let ge=I instanceof Node?Nt(I):null,Fe=Ve(e);if(g=null,Pt(e),ge)return;if((Fe==null?void 0:Fe.kind)==="text-range"){ie(Fe);return}let de=mt(e);de&&dt(e,de),ie(de?{kind:"caret",paraId:de.paraId,offset:de.offset}:null);return}let re=Nt(I),le=re==null?void 0:re.dataset.paraId,xe=I.dataset.drawingId;!re||!le||!xe||(re.focus(),g={paraId:le,drawingId:xe},Pt(e),_t(),ie({kind:"object",paraId:le,objectKind:"image",objectId:xe,offset:xi(re,I)}));},Sd=c=>{var P;if(c.button!==0||(et=false,c.target instanceof Node&&Nt(c.target)&&(y=null),c.target instanceof HTMLImageElement))return;let m=c.target instanceof Element?c.target:null,x=m?Nt(m):null,k=(m==null?void 0:m.closest("coco-word-native-page, coco-word-native-p, coco-word-native-table"))!==null,C=m==null?void 0:m.closest("button, input, textarea, select, a");!x&&!k&&!C&&(h==null?void 0:h.kind)==="text-range"?(Ge=true,at(true)):Ge=false;let I=pt(c.target);if(I&&(Ge=false),!I){ft=null,Ce=true;return}Ce=false;let T=I.point;if(c.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 M=h.kind==="text-range"?h.anchor.paraId:h.paraId,F=rn(s,M);(F==null?void 0:F.table.tableId)===I.tableId&&(T={rowIndex:F.rowIndex,columnIndex:F.columnIndex});}c.preventDefault(),(P=Tt(e))==null||P.removeAllRanges(),ft={tableId:I.tableId,point:T},Qt=true,ie({kind:"table-cell-range",tableId:I.tableId,anchor:T,focus:I.point});return}ft={tableId:I.tableId,point:I.point},Qt=false;},kd=c=>{var x;if(Ce&&(c.buttons&1)!==0){return}if(!ft||(c.buttons&1)===0)return;let m=pt(c.target);!m||m.tableId!==ft.tableId||!Qt&&m.point.rowIndex===ft.point.rowIndex&&m.point.columnIndex===ft.point.columnIndex||(c.preventDefault(),(x=Tt(e))==null||x.removeAllRanges(),Qt=true,ie({kind:"table-cell-range",tableId:ft.tableId,anchor:ft.point,focus:m.point}));},Go=()=>{var m;if(Ce){let x=Ve(e);(x==null?void 0:x.kind)==="text-range"&&(y=x,ie(x),Le=true),Ce=false;}if(Qt){(m=Tt(e))==null||m.removeAllRanges(),Po(h),jn=true,Qt=false,ft=null;return}ft=null;let c=Ve(e);(c==null?void 0:c.kind)==="text-range"&&(y=c,g=null,Pt(e),ie(c));},Cd=()=>{(ft||Ce)&&Go();},Ed=()=>{var x;if(l||me||we||(h==null?void 0:h.kind)==="object"&&g||(h==null?void 0:h.kind)==="table-cell-range")return;if(Le&&y){ie(y),at(true);return}if(Ge){at(true);return}if(et){at(true);return}let c=document.activeElement;if(c instanceof HTMLElement&&c!==document.body&&c!==i&&!e.contains(c)){at();return}ka();let m=(x=Ve(e))!=null?x:lt(e);(m==null?void 0:m.kind)==="text-range"&&(y=m),m&&(ut(),ie(m));},Id=c=>{c.target;c.composedPath().some(C=>C instanceof Element&&C.matches("coco-word-native-page, coco-word-native-p, coco-word-native-table"))?et=false:(h==null?void 0:h.kind)==="text-range"&&(et=true),queueMicrotask(at);},Tr=c=>{let m=c.composedPath(),x=m.some(I=>I instanceof Element&&I.matches("coco-word-native-page, coco-word-native-p, coco-word-native-table")),k=m.some(I=>I instanceof HTMLButtonElement&&I.matches("[data-revision-action][data-revision-id], [data-revision-group-toggle]"));if(l||c.button!==0||x||k)return;let C=y!=null?y:(h==null?void 0:h.kind)==="text-range"?h:Ve(e);(C==null?void 0:C.kind)==="text-range"&&(h!==C&&ie(C),et=true,Ge=true,at(true),queueMicrotask(()=>at(true)),window.setTimeout(()=>at(true),0));},Nd=c=>{Tr(c),window.setTimeout(()=>at(true),0);},Td=c=>{d&&c.preventDefault();},jo=c=>{e.classList.toggle("is-hyperlink-navigation-mode",c.ctrlKey||c.metaKey);},Pd=()=>{e.classList.remove("is-hyperlink-navigation-mode");},Rd=c=>{var M,F,z,j;if(d)return;let m=c;if(m.inputType===D){D=null,G!==null&&window.clearTimeout(G),G=null;return}if(m.isComposing||me||m.inputType==="insertCompositionText"||m.inputType==="deleteCompositionText")return;if(we){te!==null&&window.clearTimeout(te),Aa();return}if(Sh()||m.inputType==="historyUndo"&&kh()||m.inputType==="historyRedo"&&Ch())return;let x=mt(e),k=(M=Nt(c.target))!=null?M:x?e.querySelector(`coco-word-native-p[data-para-id="${x.paraId}"]`):null;if(!k||!e.contains(k))return;let C=(F=k.dataset.paraId)!=null?F:"",I=Z(s,C);if(!I||I.content.some(re=>re.kind!=="text"))return;let T=Gr(s,C,(z=k.textContent)!=null?z:"");if(!T){(m.inputType==="historyUndo"||m.inputType==="historyRedo")&&pn(C);return}u.push(T);let P=Ql(C,T);P&&u.push(P),$&&m.inputType!=="historyUndo"&&m.inputType!=="historyRedo"&&((j=$.afterParagraphs[0])==null?void 0:j.paraId)===C?($.changes.push(T),$.afterParagraphs=[he(I)]):$=null,X.length=0,Na(C),x&&ie({kind:"caret",paraId:x.paraId,offset:x.offset}),P&&Ia(C,x!=null?x:void 0),Te("deferred");},$a=c=>{var x,k;if(l)return false;if(!c){let C=Tt(e);return C&&(e.contains(C.anchorNode)||e.contains(C.focusNode))&&C.removeAllRanges(),g=null,Pt(e),ie(null),true}if(c.kind==="caret")return Z(s,c.paraId)?(g=null,Pt(e),dt(e,c),ie(c),true):false;if(c.kind==="text-range")return !Z(s,c.anchor.paraId)||!Z(s,c.focus.paraId)?false:(g=null,Pt(e),vn(e,c.anchor,c.focus),ie(c),true);if(c.kind==="table-cell-range"){let C=(x=Oe(s,c.tableId))==null?void 0:x.table;return !C||tt(C,c).length===0?false:(g=null,Pt(e),(k=Tt(e))==null||k.removeAllRanges(),ie(c),true)}let m=e.querySelector(`coco-word-native-p[data-para-id="${c.paraId}"] img[data-drawing-id="${c.objectId}"]`);return !Z(s,c.paraId)||!m?false:(g={paraId:c.paraId,drawingId:c.objectId},Pt(e),_t(),ie(c),true)},Md=()=>{O!==null&&window.clearTimeout(O),W!==null&&window.clearTimeout(W),V!==null&&window.clearTimeout(V),ee!==null&&window.clearTimeout(ee),pe!==null&&window.clearTimeout(pe),A!==null&&window.clearTimeout(A),te!==null&&window.clearTimeout(te),G!==null&&window.clearTimeout(G),O=null,W=null,V=null,ee=null,pe=null,A=null,te=null,G=null;};return e.addEventListener("beforeinput",wd),e.addEventListener("compositionstart",td),e.addEventListener("compositionend",nd),e.addEventListener("copy",Da),e.addEventListener("cut",pd),e.addEventListener("paste",md),e.addEventListener("drop",Td),e.addEventListener("keydown",Vo),e.addEventListener("mousedown",Sd),e.addEventListener("click",vd),e.addEventListener("mouseup",Go),e.addEventListener("input",Rd),e.addEventListener("contextmenu",hd),document.addEventListener("keydown",Vo,true),document.addEventListener("beforeinput",xd,true),document.addEventListener("selectionchange",Ed),document.addEventListener("focusin",Id),document.addEventListener("pointerdown",Tr,true),document.addEventListener("pointerup",Tr,true),document.addEventListener("click",Nd,true),document.addEventListener("keydown",jo,true),document.addEventListener("keyup",jo,true),document.addEventListener("mousemove",kd),document.addEventListener("pointerdown",gd,true),document.addEventListener("keydown",bd,true),document.addEventListener("scroll",gt,true),window.addEventListener("resize",gt),window.addEventListener("mouseup",Cd),window.addEventListener("blur",Pd),Re(),{kind:"native-word",get destroyed(){return l},isReadOnly(){return d},setReadOnly(c){l||d===c||(d=c,gt(),d&&(Ze==null||Ze(),Ze=null,oe=null,we=null,$=null,me=false),Re(void 0,h!=null?h:void 0));},destroy(){l||(l=true,e.removeEventListener("beforeinput",wd),e.removeEventListener("compositionstart",td),e.removeEventListener("compositionend",nd),e.removeEventListener("copy",Da),e.removeEventListener("cut",pd),e.removeEventListener("paste",md),e.removeEventListener("drop",Td),e.removeEventListener("keydown",Vo),e.removeEventListener("mousedown",Sd),e.removeEventListener("click",vd),e.removeEventListener("mouseup",Go),e.removeEventListener("input",Rd),e.removeEventListener("contextmenu",hd),document.removeEventListener("keydown",Vo,true),document.removeEventListener("beforeinput",xd,true),document.removeEventListener("selectionchange",Ed),document.removeEventListener("focusin",Id),document.removeEventListener("pointerdown",Tr,true),document.removeEventListener("pointerup",Tr,true),document.removeEventListener("click",Nd,true),document.removeEventListener("keydown",jo,true),document.removeEventListener("keyup",jo,true),document.removeEventListener("mousemove",kd),document.removeEventListener("pointerdown",gd,true),document.removeEventListener("keydown",bd,true),document.removeEventListener("scroll",gt,true),window.removeEventListener("resize",gt),window.removeEventListener("mouseup",Cd),window.removeEventListener("blur",Pd),window.removeEventListener("resize",Ao),document.removeEventListener("scroll",Ao,true),Ze==null||Ze(),Ze=null,gt(),Ca(),ka(),Sa.remove(),Md(),Bo.disconnect(),so.get(document)===e&&so.delete(document),kt.change.clear(),kt.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(c){if(l)throw new Error("Cannot load a document into a destroyed Word editor");Md(),Bo.disconnect(),a=c,gt(),Ca(),s=as(a),u.length=0,p=[],b.clear();for(let m of _e(s))b.add(m.paraId);w=Date.now()>>>0,g=null,Un(),h=null,oe=null,we=null,$=null,me=false,_=null,D=null,U.length=0,X.length=0,Re(),Pa();},getSourceView(){return a},getDocument(){return s},getSelection(){var c;return (c=h!=null?h:Ve(e))!=null?c:lt(e)},setSelection(c){return $a(c)},focus(){var x;if(l)return false;let c=(x=h!=null?h:Ve(e))!=null?x:lt(e);if(c)return $a(c);let m=_e(s)[0];return m?$a({kind:"caret",paraId:m.paraId,offset:0}):false},async insertImage(c,m={}){if(l)return false;let x=typeof c=="string"?c:await gp(c);return Se(v({kind:"insert-image",src:x},m))},search:wh,getSearchState(){return Mo()},findNext:xh,replaceCurrent:Wh,replaceAll:Bh,clearSearch:Ca,getCommandState(){var m;let c=(m=h!=null?h:Ve(e))!=null?m:lt(e);return Rt(c)},getChanges(){return u.slice()},canUndo(){return !l&&!d&&U.length>0},canRedo(){return !l&&!d&&X.length>0},undo:Cr,redo:Er,canDispatch(c){var x;if(l||d)return false;let m=(x=h!=null?h:Ve(e))!=null?x:lt(e);return Wt(s,m,c)},dispatch:Se,subscribe(c,m){if(l)return ()=>{};let x=m;return kt[c].add(x),()=>kt[c].delete(x)}}}function he(e){return H(v({},e),{format:e.format?uo(e.format):null,content:e.content.map(Fv)})}function Fv(e){return e.kind==="pageBreak"?{kind:"pageBreak"}:e.kind==="text"?v(v(H(v({},e),{format:e.format?uo(e.format):null}),e.marks?{marks:e.marks.map(t=>v({},t))}:{}),e.hyperlink?{hyperlink:v({},e.hyperlink)}:{}):e.kind==="field"?H(v({},e),{format:e.format?uo(e.format):null}):e.kind==="image"?v(v({},e),e.position?{position:uo(e.position)}:{}):v(v(v({},e),e.position?{position:uo(e.position)}:{}),e.paragraphs?{paragraphs:e.paragraphs.map(he)}:{})}function uo(e){return JSON.parse(JSON.stringify(e))}function Hv(e){return !!e&&/^(https?:|mailto:|tel:)/i.test(e.trim())}function ar(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 pp(e){var n;let t=ll;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 ll=t+1,ll}function ot(e){var n,r,o,i;let t=dl;for(let a of _e(e))for(let s of a.content)if(s.kind==="text"){for(let u of (n=s.marks)!=null?n:[]){if(u.kind!=="revision")continue;let p=Number(u.revisionId);Number.isInteger(p)&&(t=Math.max(t,p));}let l=s.formatRevision,d=Number(l==null?void 0:l.revisionId);Number.isInteger(d)&&(t=Math.max(t,d));}else if(s.kind==="image"){let l=Number((i=(r=s.revision)==null?void 0:r.revisionId)!=null?i:(o=s.formatRevision)==null?void 0:o.revisionId);Number.isInteger(l)&&(t=Math.max(t,l));}return dl=t+1,String(dl)}function $v(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 mp(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 hp(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 wp(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=>wp(e,n.paraId)===Ne(n))}function Ri(e,t){return {from:Math.max(0,Math.min(e,t)),to:Math.max(0,Math.max(e,t))}}function gp(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=jr(e);if(!t)return "";sl=sl+1>>>0;let n=`${bp}${Date.now().toString(36)}-${sl.toString(36)}`;for(co.set(n,t);co.size>8;){let r=co.keys().next().value;if(!r)break;co.delete(r);}return n}function zv(e){var t;return e.startsWith(bp)?(t=co.get(e))!=null?t:"":e}function Vv(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 Gv(e){let t=xu(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,a)=>{r.toBlob(s=>s?i(s):a(new Error("Unable to encode clipboard image")),"image/png");})}finally{n.close();}}function Ai(e){return e.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;")}function jv(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 Uv(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 nt(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=ye(e,t.anchor.paraId),r=ye(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 Li(e,t){return `${e}:${t}`}function fo(e,t,n={}){var p,f,b;let r=new Map,o=new Map,i=new Map,a=new Map,s=new Map,l=new Map,d=(p=n.minimumRows)!=null?p:100,u=(f=n.minimumColumns)!=null?f:26;for(let w of e.rows)i.set(w.index,w),d=Math.max(d,w.index);for(let w of e.columns){for(let g=w.min;g<=w.max;g++)a.set(g,w);u=Math.max(u,w.max);}for(let w of e.cells){let g=yp(w,t,n.formulaResults,n.date1904);r.set(w.address,g),o.set(Li(w.row,w.column),g),d=Math.max(d,w.row),u=Math.max(u,w.column);}for(let[w,g]of (b=n.formulaResults)!=null?b:[]){if(r.has(w)||g.error)continue;let h=excel.parseCellAddress(w),y={address:w,row:h.row,column:h.column,kind:"formula",value:null},S=yp(y,t,n.formulaResults,n.date1904);r.set(w,S),o.set(Li(h.row,h.column),S),d=Math.max(d,h.row),u=Math.max(u,h.column);}for(let w of e.mergedRanges){let g=excel.parseRangeAddress(w.address),h=g.startRow+g.rowCount-1,y=g.startColumn+g.columnCount-1,S={startRow:g.startRow,startColumn:g.startColumn,endRow:h,endColumn:y},E=excel.formatCellAddress(g.startRow,g.startColumn),N={address:w.address,range:S,masterAddress:E,source:w};s.set(E,N),d=Math.max(d,h),u=Math.max(u,y);for(let A=g.startRow;A<=h;A++)for(let O=g.startColumn;O<=y;O++){let W=excel.formatCellAddress(A,O);W!==E&&l.set(W,E);}}return {sheetId:e.id,sheetName:e.name,source:e,styles:t,cellsByAddress:r,cellsByRowColumn:o,rowMetaByIndex:i,columnMetaByIndex:a,mergeMasterByAddress:s,mergeFollowerByAddress:l,maxRow:d,maxColumn:u}}function qe(e,t,n){return e.cellsByRowColumn.get(Li(t,n))}function yp(e,t,n,r=false){var s,l;let o=n==null?void 0:n.get(e.address),i=o&&!o.error?o.value:void 0,a=Array.isArray(i)?(l=(s=i[0])==null?void 0:s[0])!=null?l:null:i!=null?i:e.value;return {row:e.row,column:e.column,address:e.address,kind:e.kind,value:a,displayText:qv(e,t,a,o,r),formula:e.formula,styleId:e.styleId,source:e}}function qv(e,t,n,r,o=false){return r!=null&&r.error?r.displayText:n!==null?Yv(n,Xv(e,t),o):""}function Xv(e,t){var n,r;return (r=t.cellFormats[(n=e.styleId)!=null?n:0])==null?void 0:r.numberFormatCode}function Yv(e,t,n=false){if(e===null)return "";if(typeof e!="number"||!t)return String(e);let r=t.toLowerCase();return r.includes("%")?`${Bi(e*100,Wi(t))}%`:r.includes("$")?`$${Bi(e,Wi(t),true)}`:Zv(r)?Jv(e,r,n):t.includes(",")?Bi(e,Wi(t),true):t.includes(".")?Bi(e,Wi(t)):String(e)}function Wi(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 Bi(e,t,n=false){return new Intl.NumberFormat("en-US",{minimumFractionDigits:t,maximumFractionDigits:t,useGrouping:n}).format(e)}function Zv(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 Jv(e,t,n){if(!Number.isFinite(e))return String(e);let r=Math.floor(e),o=e-r,i=Math.round(o*86400)%86400,a=Math.floor(i/3600),s=Math.floor(i%3600/60),l=i%60,d=a%12||12,u=a<12?"AM":"PM",p=O=>String(O).padStart(2,"0");if(t==="h:mm am/pm")return `${d}:${p(s)} ${u}`;if(t==="h:mm:ss am/pm")return `${d}:${p(s)}:${p(l)} ${u}`;if(t==="h:mm")return `${a}:${p(s)}`;if(t==="h:mm:ss")return `${a}:${p(s)}:${p(l)}`;if(t==="mm:ss")return `${p(s)}:${p(l)}`;if(t==="[h]:mm:ss")return `${Math.floor(e*24)}:${p(s)}:${p(l)}`;if(t==="mmss.0")return `${p(s)}${p(l)}.0`;let f=!n&&r===60,b=n?Date.UTC(1904,0,1):Date.UTC(1899,11,30),w=new Date(b+r*864e5),g=f?1900:w.getUTCFullYear(),h=f?2:w.getUTCMonth()+1,y=f?29:w.getUTCDate(),S=p(h),E=p(y),N=p(g%100),A=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][h-1];return t==="mm-dd-yy"?`${S}-${E}-${N}`:t==="d-mmm-yy"?`${y}-${A}-${N}`:t==="d-mmm"?`${y}-${A}`:t==="mmm-yy"?`${A}-${N}`:t==="m/d/yy h:mm"?`${h}/${y}/${N} ${a}:${p(s)}`:`${g}-${S}-${E}`}var eS=22,tS=96,nS=48,rS=24,oS=1.2,po=7,vp=5,Di=class{constructor(t,n={}){B(this,"model",t);B(this,"defaultRowHeight");B(this,"defaultColumnWidth");B(this,"pointsToCssPixels");B(this,"maximumDigitWidth");B(this,"rowHeaderWidth");B(this,"columnHeaderHeight");B(this,"rowCount");B(this,"columnCount");B(this,"rowOffsets");B(this,"columnOffsets");B(this,"rowHeights");B(this,"columnWidths");var r,o,i,a,s,l;this.defaultRowHeight=(r=n.defaultRowHeight)!=null?r:eS,this.defaultColumnWidth=(o=n.defaultColumnWidth)!=null?o:tS,this.pointsToCssPixels=Fi(n.pointsToCssPixels,oS),this.maximumDigitWidth=Fi(n.maximumDigitWidth,po),this.rowHeaderWidth=(i=n.rowHeaderWidth)!=null?i:nS,this.columnHeaderHeight=(a=n.columnHeaderHeight)!=null?a:rS,this.rowCount=Math.max((s=n.rowCount)!=null?s:0,t.maxRow),this.columnCount=Math.max((l=n.columnCount)!=null?l:0,t.maxColumn),this.rowHeights=iS(t,this.rowCount,this.defaultRowHeight,this.pointsToCssPixels),this.columnWidths=aS(t,this.columnCount,this.defaultColumnWidth,this.maximumDigitWidth),this.rowOffsets=Sp(this.rowHeights),this.columnOffsets=Sp(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}emuToCssPixels(t){return Number.isFinite(t)?(t!=null?t:0)/12700*this.pointsToCssPixels:0}cssPixelsToEmu(t){return Number.isFinite(t)?Math.round(t/this.pointsToCssPixels*12700):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 a=Math.max(i,this.columnAt(t)),s=Math.max(o,this.rowAt(n)),l=Math.max(a,Math.min(this.columnCount,this.columnAt(t+r.width)+1)),d=Math.max(s,Math.min(this.rowCount,this.rowAt(n+r.height)+1));return {startRow:s,startColumn:a,endRow:d,endColumn:l}}rowAt(t){return Cp(kp(this.rowOffsets,t),this.rowCount)}columnAt(t){return Cp(kp(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 iS(e,t,n,r){let o=[];for(let i=1;i<=t;i++){let a=e.rowMetaByIndex.get(i);o.push(a!=null&&a.hidden?0:(a==null?void 0:a.height)===void 0?n:a.height*r);}return o}function aS(e,t,n,r){let o=[];for(let i=1;i<=t;i++){let a=e.columnMetaByIndex.get(i);o.push(a!=null&&a.hidden?0:(a==null?void 0:a.width)===void 0?n:sS(a.width,r));}return o}function sS(e,t=po){if(!Number.isFinite(e)||e<=0)return 0;let n=Fi(t,po);return Math.floor((256*e+Math.floor(128/n))/256*n)}function Hi(e,t=po){if(!Number.isFinite(e)||e<=0)return 0;let n=Fi(t,po),r=Math.floor((e-vp)/n*100+.5)/100;return Math.floor((r*n+vp)/n*256)/256}function Fi(e,t){return Number.isFinite(e)&&(e!=null?e:0)>0?e:t}function Sp(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 kp(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 Cp(e,t){return Math.max(1,Math.min(t,e))}var Oi=class{constructor(t,n){B(this,"layout",t);B(this,"scroll");B(this,"freeze");B(this,"viewportSize");B(this,"viewports");var r,o,i,a,s,l,d,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,(a=(i=n.freeze)==null?void 0:i.frozenColumns)!=null?a:0)},this.scroll=dS(t,this.freeze,n.viewportSize,{x:(l=(s=n.scroll)==null?void 0:s.x)!=null?l:0,y:(u=(d=n.scroll)==null?void 0:d.y)!=null?u:0}),this.viewports=cS(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&&uS(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 $i(e){var n;let t=(n=e.sheetViews[0])==null?void 0:n.pane;return lS(t)}function lS(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 dS(e,t,n,r){let o=e.getColumnX(t.frozenColumns+1),i=e.getRowY(t.frozenRows+1),a=Math.max(0,n.width-e.rowHeaderWidth-o),s=Math.max(0,n.height-e.columnHeaderHeight-i),l=Math.max(0,e.totalWidth()-o-a),d=Math.max(0,e.totalHeight()-i-s);return {x:Math.max(0,Math.min(l,r.x)),y:Math.max(0,Math.min(d,r.y))}}function cS(e,t,n,r){let o=e.rowHeaderWidth,i=e.columnHeaderHeight,a=e.getColumnX(r.frozenColumns+1),s=e.getRowY(r.frozenRows+1),l=a+n.x,d=s+n.y,u=Math.max(0,t.width-o),p=Math.max(0,t.height-i),f=o+a,b=i+s,w=Math.max(0,t.width-f),g=Math.max(0,t.height-b),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(a,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+a,y:0,width:Math.max(0,t.width-o-a),height:i},originX:l,originY:0,rows:{start:1,end:0},columns:ul(e,l,w,r.frozenColumns+1)}),r.frozenRows>0&&h.push({kind:"rowHeaderFrozen",screenRect:{x:0,y:i,width:o,height:Math.min(s,p)},originX:0,originY:0,rows:{start:1,end:r.frozenRows},columns:{start:1,end:0}}),h.push({kind:"rowHeaderScrollable",screenRect:{x:0,y:i+s,width:o,height:Math.max(0,t.height-i-s)},originX:0,originY:d,rows:cl(e,d,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:a,height:s},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:f,y:i,width:w,height:s},originX:l,originY:0,rows:{start:1,end:r.frozenRows},columns:ul(e,l,w,r.frozenColumns+1)}),r.frozenColumns>0&&h.push({kind:"frozenLeft",screenRect:{x:o,y:b,width:a,height:g},originX:0,originY:d,rows:cl(e,d,g,r.frozenRows+1),columns:{start:1,end:r.frozenColumns}}),h.push({kind:"main",screenRect:{x:f,y:b,width:w,height:g},originX:l,originY:d,rows:cl(e,d,g,r.frozenRows+1),columns:ul(e,l,w,r.frozenColumns+1)}),h.filter(y=>y.screenRect.width>0&&y.screenRect.height>0)}function cl(e,t,n,r){let o=e.getVisibleRange(0,t,{width:1,height:n},r,1);return {start:o.startRow,end:o.endRow}}function ul(e,t,n,r){let o=e.getVisibleRange(t,0,{width:n,height:1},1,r);return {start:o.startColumn,end:o.endColumn}}function uS(e,t){return t.x>=e.x&&t.y>=e.y&&t.x<e.x+e.width&&t.y<e.y+e.height}function mo(e,t,n){var l,d,u,p,f,b,w,g,h,y,S,E,N,A;let r=(l=e.cellFormats[t!=null?t:0])!=null?l:{},o=(u=e.fonts[(d=r.fontId)!=null?d:0])!=null?u:{},i=(p=o.size)!=null?p:11,a=(b=e.fills[(f=r.fillId)!=null?f:0])!=null?b:{},s=(g=e.borders[(w=r.borderId)!=null?w:0])!=null?g:{};return {font:fS(o.bold,o.italic,i,(h=o.name)!=null?h:"Arial"),fontSize:i,underline:o.underline===true,fontColor:(S=(y=o.color)==null?void 0:y.rgb)!=null?S:"#111827",fillColor:(N=(E=a.foregroundColor)==null?void 0:E.rgb)!=null?N:"#FFFFFF",wrapText:((A=r.alignment)==null?void 0:A.wrapText)===true,border:s,horizontalAlign:pS(r,n),verticalAlign:mS(r)}}function Ep(e,t){let n={};for(let s=t.startColumn;s<=t.endColumn;s++)(n.top)!=null||(n.top=zi(e,t.startRow,s,"top")),(n.bottom)!=null||(n.bottom=zi(e,t.endRow,s,"bottom"));for(let s=t.startRow;s<=t.endRow;s++)(n.left)!=null||(n.left=zi(e,s,t.startColumn,"left")),(n.right)!=null||(n.right=zi(e,s,t.endColumn,"right"));return n}function zi(e,t,n,r){var a,s,l,d;let o=qe(e,t,n),i=(s=e.styles.cellFormats[(a=o==null?void 0:o.styleId)!=null?a:0])!=null?s:{};return (d=e.styles.borders[(l=i.borderId)!=null?l:0])==null?void 0:d[r]}function fS(e,t,n,r){let o=[];return t&&o.push("italic"),e&&o.push("600"),o.push(`${n}pt`),o.push(qt(r,{families:[]})),o.join(" ")}function pS(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 mS(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 Ui=class{constructor(t){B(this,"options",t);B(this,"baseCtx");B(this,"headerCtx");B(this,"overlayCtx");B(this,"cssWidth",1);B(this,"cssHeight",1);B(this,"scaleX",1);B(this,"scaleY",1);B(this,"headerFiltersEnabled",true);B(this,"headerFilterColumns",null);B(this,"activeHeaderFilterColumns",new Set);this.baseCtx=Vi(t.baseCanvas),this.headerCtx=Vi(t.headerCanvas),this.overlayCtx=Vi(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 a=Vi(i);this.scaleX=i.width/this.cssWidth,this.scaleY=i.height/this.cssHeight,a.setTransform(this.scaleX,0,0,this.scaleY,0,0),a.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(){Gi(this.overlayCtx,this.options.overlayCanvas);}renderSelection(t,n,r,o={}){this.clearOverlay();let i=this.overlayCtx;for(let a of n.viewports){if(!ji(a))continue;let s=Np(r,{startRow:a.rows.start,endRow:a.rows.end,startColumn:a.columns.start,endColumn:a.columns.end});if(!s)continue;let l=t.getRangeLogicalRect(s),d=fl(l,a);ho(i,a.screenRect,()=>{i.fillStyle="rgba(37, 99, 235, 0.08)",i.fillRect(d.x,d.y,d.width,d.height),i.strokeStyle="#2563EB",i.lineWidth=2/this.scaleX,i.setLineDash([]),bo(i,ml(d,1),this.scaleX,this.scaleY);});}o.showFillHandle&&this.drawFillHandle(t,n,r);}fillHandleRect(t,n,r){for(let o of n.viewports){if(!ji(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),a=7;return {x:i.x+i.width-a/2,y:i.y+i.height-a/2,width:a,height:a}}return null}renderCopiedRange(t,n,r){this.renderDashedRange(t,n,r,{stroke:"#1D4ED8"});}renderDashedRange(t,n,r,o){let i=this.overlayCtx;for(let a of n.viewports){if(!ji(a))continue;let s=Np(r,{startRow:a.rows.start,endRow:a.rows.end,startColumn:a.columns.start,endColumn:a.columns.end});if(!s)continue;let l=t.getRangeLogicalRect(s),d=fl(l,a);ho(i,a.screenRect,()=>{i.save(),o.fill&&(i.fillStyle=o.fill,i.fillRect(d.x,d.y,d.width,d.height)),i.strokeStyle=o.stroke,i.lineWidth=2/this.scaleX,i.setLineDash([4,3]),i.lineDashOffset=0,bo(i,ml(d,2),this.scaleX,this.scaleY),i.restore();});}}clearAll(t,n){Gi(this.baseCtx,this.options.baseCanvas),Gi(this.headerCtx,this.options.headerCanvas),Gi(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,bo(i,ml(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)ji(o)&&ho(r,o.screenRect,()=>{for(let i=o.rows.start;i<=o.rows.end;i++)for(let a=o.columns.start;a<=o.columns.end;a++){let s=excel.formatCellAddress(i,a);if(!t.model.mergeFollowerByAddress.get(s)&&(this.drawCell(r,t,n,o,i,a,{drawBorder:false,reserveTrailingSpace:this.headerFiltersEnabled&&i===1}),this.headerFiltersEnabled&&i===1&&(this.headerFilterColumns===null||this.headerFilterColumns.has(a)))){let d=t.getCellLogicalRect(i,a),u={x:o.screenRect.x+d.x-o.originX,y:o.screenRect.y+d.y-o.originY,width:d.width,height:d.height};gS(r,u,this.scaleX,this.scaleY,this.activeHeaderFilterColumns.has(a));}}for(let i=o.rows.start;i<=o.rows.end;i++)for(let a=o.columns.start;a<=o.columns.end;a++){let s=excel.formatCellAddress(i,a);t.model.mergeFollowerByAddress.get(s)||this.drawCell(r,t,n,o,i,a,{drawContent:false});}});}drawCell(t,n,r,o,i,a,s={}){let l=qe(n.model,i,a),d=l?n.model.mergeMasterByAddress.get(l.address):void 0,u=d?fl(n.getRangeLogicalRect(d.range),o):r.cellScreenRect(i,a,o),p=mo(n.model.styles,l==null?void 0:l.styleId,l),f=d?Ep(n.model,d.range):p.border;if(s.drawContent!==false&&(t.fillStyle=p.fillColor,t.fillRect(u.x,u.y,u.width,u.height),t.strokeStyle="#E5E7EB",t.lineWidth=1/this.scaleX,bo(t,u,this.scaleX,this.scaleY)),s.drawBorder!==false&&bS(t,u,f,this.scaleX,this.scaleY),s.drawContent===false||!(l!=null&&l.displayText))return;t.save(),t.font=p.font,t.fillStyle=p.fontColor,t.textAlign=p.horizontalAlign,t.textBaseline="middle";let b=6,w=s.reserveTrailingSpace&&u.width>=28?22:0,g={x:u.x,y:u.y,width:Math.max(1,u.width-w),height:u.height},h=p.horizontalAlign==="right"?g.x+g.width-b:p.horizontalAlign==="center"?g.x+g.width/2:g.x+b;ho(t,g,()=>{let y=p.wrapText||l.displayText.includes(`
1553
- `)?xS(t,l.displayText,Math.max(1,g.width-b*2)):[l.displayText],S=p.fontSize*1.2,E=y.length*S,N=wS(u,p,b,E,S);for(let A=0;A<y.length;A++){let O=y[A],W=N+A*S;t.fillText(O,h,W),p.underline&&yS(t,O,h,W,p,this.scaleX,this.scaleY);}}),t.restore();}drawHeaders(t,n){let r=this.headerCtx;for(let o of n.viewports)ho(r,o.screenRect,()=>{if(o.kind==="corner")pl(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 a=t.getCellLogicalRect(1,i),s={x:o.screenRect.x+a.x-o.originX,y:o.screenRect.y,width:a.width,height:o.screenRect.height};pl(r,s,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 a=t.getCellLogicalRect(i,1),s={x:o.screenRect.x,y:o.screenRect.y+a.y-o.originY,width:o.screenRect.width,height:a.height};pl(r,s,String(i),this.scaleX,this.scaleY);}});}};function gS(e,t,n,r,o=false){if(t.width<28)return;let i=t.x+t.width-10,a=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,a-3),e.lineTo(i+4,a-3),e.lineTo(i+1,a+1),e.lineTo(i+1,a+4),e.lineTo(i-1,a+3),e.lineTo(i-1,a+1),e.closePath(),e.stroke(),e.restore();}function Np(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 Vi(e){let t=e.getContext("2d");if(!t)throw new Error("SpreadsheetCanvasRenderer: 2D canvas context is unavailable");return t}function Gi(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 ho(e,t,n){e.save(),e.beginPath(),e.rect(t.x,t.y,t.width,t.height),e.clip(),n(),e.restore();}function ji(e){return e.kind==="main"||e.kind==="frozenTop"||e.kind==="frozenLeft"||e.kind==="frozenTopLeft"}function fl(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 pl(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,bo(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 bS(e,t,n,r,o){var i,a,s,l,d,u,p,f;!n.left&&!n.right&&!n.top&&!n.bottom||(e.save(),e.lineWidth=1/r,e.setLineDash([]),n.top&&(e.strokeStyle=(a=(i=n.top.color)==null?void 0:i.rgb)!=null?a:"#111827",go(e,t.x,t.y,t.x+t.width,t.y,r,o)),n.right&&(e.strokeStyle=(l=(s=n.right.color)==null?void 0:s.rgb)!=null?l:"#111827",go(e,t.x+t.width,t.y,t.x+t.width,t.y+t.height,r,o)),n.bottom&&(e.strokeStyle=(u=(d=n.bottom.color)==null?void 0:d.rgb)!=null?u:"#111827",go(e,t.x,t.y+t.height,t.x+t.width,t.y+t.height,r,o)),n.left&&(e.strokeStyle=(f=(p=n.left.color)==null?void 0:p.rgb)!=null?f:"#111827",go(e,t.x,t.y,t.x,t.y+t.height,r,o)),e.restore());}function wS(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 xS(e,t,n){let r=[];for(let o of t.split(/\r?\n/)){if(o===""){r.push("");continue}let i="";for(let a of o){let s=i+a;i&&e.measureText(s).width>n?(r.push(i),i=a):i=s;}i&&r.push(i);}return r.length>0?r:[""]}function go(e,t,n,r,o,i,a){e.beginPath(),e.moveTo(kn(t,i),kn(n,a)),e.lineTo(kn(r,i),kn(o,a)),e.stroke();}function yS(e,t,n,r,o,i,a){let s=e.measureText(t),l=s.width,d=o.horizontalAlign==="right"?n-l:o.horizontalAlign==="center"?n-l/2:n,u=Math.max(2,(s.actualBoundingBoxDescent||o.fontSize*.18)+1);e.save(),e.strokeStyle=o.fontColor,e.lineWidth=1/i,go(e,d,r+u,d+l,r+u,i,a),e.restore();}function ml(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 bo(e,t,n,r){let o=kn(t.x,n),i=kn(t.y,r),a=kn(t.x+t.width,n),s=kn(t.y+t.height,r);e.strokeRect(o,i,Math.max(0,a-o),Math.max(0,s-i));}function kn(e,t){return (Math.round(e*t)+.5)/t}function it(e,t){return {kind:"cell",active:{row:e,column:t},range:{startRow:e,startColumn:t,endRow:e,endColumn:t}}}function Ki(e,t){return {kind:"row",active:{row:e,column:1},range:{startRow:e,startColumn:1,endRow:e,endColumn:t.columnCount}}}function RN(e,t,n){let r=Ae({startRow:e,startColumn:1,endRow:t,endColumn:n.columnCount});return {kind:"row",active:{row:r.startRow,column:1},range:r}}function _i(e,t){return {kind:"column",active:{row:1,column:e},range:{startRow:1,startColumn:e,endRow:t.rowCount,endColumn:e}}}function MN(e,t,n){let r=Ae({startRow:1,startColumn:e,endRow:n.rowCount,endColumn:t});return {kind:"column",active:{row:1,column:r.startColumn},range:r}}function Ae(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 lr(e,t,n,r){var o,i;return e.kind==="row"?{kind:"row",active:e.active,range:Ae({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:Ae({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:Ae({startRow:e.active.row,startColumn:e.active.column,endRow:t,endColumn:n})}}function AN(e,t,n,r){return it(sr(e.active.row+t,1,r.rowCount),sr(e.active.column+n,1,r.columnCount))}function ct(e,t){var r;if(e.kind!=="cell")return e;let n=(r=CS(e.active.row,e.active.column,t))!=null?r:e.active;return H(v({},e),{active:n,range:SS(e.range,t)})}function SS(e,t){let n=Ae(e),r=true;for(;r;){r=false;for(let o of t.mergeMasterByAddress.values()){if(!kS(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 LN(e,t,n,r,o){let i=sr(Tp(e.active.row,t,n),1,r.rowCount),a=sr(e.active.column,1,r.columnCount);return e.kind==="row"?Ki(i,{columnCount:r.columnCount}):ct(it(i,a),o)}function WN(e,t,n,r,o){let i=sr(e.active.row,1,r.rowCount),a=sr(Tp(e.active.column,t,n),1,r.columnCount);return e.kind==="column"?_i(a,{rowCount:r.rowCount}):ct(it(i,a),o)}function Tp(e,t,n){let r=t+n-1;return e<t?e:e>r?e-n:t}function kS(e,t){return !(e.endRow<t.startRow||e.startRow>t.endRow||e.endColumn<t.startColumn||e.startColumn>t.endColumn)}function CS(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 sr(e,t,n){return Math.max(t,Math.min(n,e))}var dr="application/x-coco-spreadsheet";function wo(e){return JSON.stringify(H(v({},e),{schema:1}))}function Pp(e){var r;let t=e.getData(dr);if(t.trimStart().startsWith("{"))return t;let n=(r=new RegExp(`\\bdata-coco-spreadsheet-payload\\s*=\\s*(["'])(.*?)\\1`,"is").exec(e.getData("text/html")))==null?void 0:r[2];if(!n)return null;if(n.length>33554432*3)throw new Error("\u590D\u5236\u7684\u5355\u5143\u683C\u6570\u636E\u8FC7\u5927\u3002");try{return decodeURIComponent(n)}catch(o){throw new Error("\u590D\u5236\u7684\u5355\u5143\u683C\u6570\u636E\u5DF2\u635F\u574F\uFF0C\u8BF7\u91CD\u65B0\u590D\u5236\u3002")}}function xo(e){var n;let t=Pp(e);if(t){if(t.length>33554432)throw new Error("\u590D\u5236\u7684\u5355\u5143\u683C\u6570\u636E\u8FC7\u5927\u3002");try{let r=JSON.parse(t);return typeof r.id=="string"?r.id:null}catch(r){throw new Error("\u590D\u5236\u7684\u5355\u5143\u683C\u6570\u636E\u5DF2\u635F\u574F\uFF0C\u8BF7\u91CD\u65B0\u590D\u5236\u3002")}}return e.getData(dr)||((n=/\bdata-coco-spreadsheet="([^"]+)"/i.exec(e.getData("text/html")))==null?void 0:n[1])||null}function wl(e){let t=Pp(e);if(!t)return null;if(t.length>33554432)throw new Error("\u590D\u5236\u7684\u5355\u5143\u683C\u6570\u636E\u8FC7\u5927\u3002");try{return NS(JSON.parse(t))}catch(n){throw new Error("\u590D\u5236\u7684\u5355\u5143\u683C\u6570\u636E\u683C\u5F0F\u65E0\u6548\uFF0C\u8BF7\u91CD\u65B0\u590D\u5236\u3002")}}function Ut(e){if(!e||typeof e!="object"||Array.isArray(e))throw new Error("Expected object");if(Object.keys(e).some(t=>t==="__proto__"||t==="constructor"||t==="prototype"))throw new Error("Invalid property");return e}function ln(e,t=32768){if(typeof e!="string"||e.length>t)throw new Error("Invalid string");return e}function Jt(e,t,n=1){if(typeof e!="number"||!Number.isInteger(e)||e<n||e>t)throw new Error("Invalid integer");return e}function ES(e){if(e===null||typeof e=="boolean"||typeof e=="string"||typeof e=="number"&&Number.isFinite(e))return e;throw new Error("Invalid cell value")}function hl(e,t,n,r){if(!Array.isArray(e)||e.length!==t)throw new Error("Invalid rows");return e.map(o=>{if(!Array.isArray(o)||o.length!==n)throw new Error("Invalid columns");return o.map(r)})}function gl(e){let t=ln(Ut(e).rgb,7);if(!/^#[0-9a-f]{6}$/i.test(t))throw new Error("Invalid color");return {rgb:t}}function bl(e,t,n,r){let o=Ut(e),i={};for(let a of t)o[a]!==void 0&&(i[a]=ln(o[a],a==="name"?1024:256));for(let a of n)if(o[a]!==void 0){let s=o[a];if(typeof s!="number"||!Number.isFinite(s)||Math.abs(s)>65535)throw new Error("Invalid style number");i[a]=s;}for(let a of r)if(o[a]!==void 0){if(typeof o[a]!="boolean")throw new Error("Invalid style boolean");i[a]=o[a];}return i}function IS(e){let t=Ut(e),n=bl(t.font,["name","scheme"],["size","family","charset"],["bold","italic","underline"]),r=Ut(t.font);r.color!==void 0&&(n.color=gl(r.color));let o=bl(t.fill,["patternType"],[],[]),i=Ut(t.fill);for(let l of ["foregroundColor","backgroundColor"])i[l]!==void 0&&(o[l]=gl(i[l]));let a=Ut(t.border),s={};for(let l of ["top","bottom","left","right","diagonal"])if(a[l]!==void 0){let d=Ut(a[l]);s[l]=v(v({},d.style!==void 0?{style:ln(d.style,64)}:{}),d.color!==void 0?{color:gl(d.color)}:{});}return v(v(v({font:n,fill:o,border:s},t.alignment!==void 0?{alignment:bl(t.alignment,["horizontal","vertical"],["textRotation","indent"],["wrapText","shrinkToFit"])}:{}),t.numberFormatId!==void 0?{numberFormatId:Jt(t.numberFormatId,65535,0)}:{}),t.numberFormatCode!==void 0?{numberFormatCode:ln(t.numberFormatCode,4096)}:{})}function NS(e){let t=Ut(e);if(t.schema!==1)throw new Error("Unsupported clipboard schema");let n=Ut(t.sourceRange),r={startRow:Jt(n.startRow,1048576),endRow:Jt(n.endRow,1048576),startColumn:Jt(n.startColumn,16384),endColumn:Jt(n.endColumn,16384)},o=r.endRow-r.startRow+1,i=r.endColumn-r.startColumn+1;if(o<1||i<1||o*i>1048576)throw new Error("Invalid range");let a=hl(t.values,o,i,ES),s=hl(t.formulas,o,i,f=>f===null?null:ln(f)),l=hl(t.styleIds,o,i,f=>f==null?void 0:Jt(f,1048576,0));if(!Array.isArray(t.merges)||t.merges.length>o*i)throw new Error("Invalid merges");let d=new Set,u=t.merges.map(f=>{let b=Ut(f),w={startRowOffset:Jt(b.startRowOffset,o-1,0),startColumnOffset:Jt(b.startColumnOffset,i-1,0),rowCount:Jt(b.rowCount,o),columnCount:Jt(b.columnCount,i)};if(w.startRowOffset+w.rowCount>o||w.startColumnOffset+w.columnCount>i)throw new Error("Merge out of range");for(let g=w.startRowOffset;g<w.startRowOffset+w.rowCount;g++)for(let h=w.startColumnOffset;h<w.startColumnOffset+w.columnCount;h++){let y=g*i+h;if(d.has(y))throw new Error("Overlapping merges");d.add(y);}return w}),p={};for(let[f,b]of Object.entries(Ut(t.styles))){if(f!=="default"&&!/^(0|[1-9]\d{0,6})$/.test(f))throw new Error("Invalid style key");p[f]=IS(b);}for(let f of l)for(let b of f)if(!Object.prototype.hasOwnProperty.call(p,b===void 0?"default":String(b)))throw new Error("Missing style definition");return H(v({schema:1,id:ln(t.id,256),sourceSheet:ln(t.sourceSheet,128)},t.sourceWorkbookId!==void 0?{sourceWorkbookId:ln(t.sourceWorkbookId,512)}:{}),{sourceRange:r,text:ln(t.text,33554432),values:a,formulas:s,styleIds:l,styles:p,merges:u})}function qi(e,t,n={}){var s,l,d;let r=MS(e,t),o=DS(e,t),i={};for(let u of o)for(let p of u){let f=p===void 0?"default":String(p);(i[f])!=null||(i[f]=excel.captureExcelCellStyle(e.styles,p));}return H(v({schema:1,id:(d=(l=(s=globalThis.crypto)==null?void 0:s.randomUUID)==null?void 0:l.call(s))!=null?d:`clipboard-${Date.now()}-${Math.random()}`},n.sourceWorkbookId?{sourceWorkbookId:n.sourceWorkbookId}:{}),{sourceSheet:e.source.name,sourceRange:v({},t),text:r,values:WS(e,t),formulas:Array.from({length:t.endRow-t.startRow+1},(u,p)=>Array.from({length:t.endColumn-t.startColumn+1},(f,b)=>{var h,y;let w=t.startRow+p,g=t.startColumn+b;return e.mergeFollowerByAddress.has(excel.formatCellAddress(w,g))?null:(y=(h=qe(e,w,g))==null?void 0:h.formula)!=null?y:null})),styleIds:o,styles:i,merges:BS(e,t)})}function MS(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(AS(LS(e,r,i)));n.push(o.join(" "));}return n.join(`
1554
- `)}function Mp(e){if(e==="")return [[null]];let t=[],n=[],r="",o=false,i=false;for(let a=0;a<e.length;a++){let s=e[a];i=false,s==='"'?o&&e[a+1]==='"'?(r+='"',a++):o||r===""?o=!o:r+=s:!o&&(s===" "||s===`
1555
- `||s==="\r")?(n.push(Rp(r)),r="",s!==" "&&(t.push(n),n=[],i=true,s==="\r"&&e[a+1]===`
1556
- `&&a++)):r+=s;}if(o)throw new Error("\u7C98\u8D34\u6570\u636E\u5305\u542B\u672A\u95ED\u5408\u7684\u5F15\u53F7\u3002");return i||(n.push(Rp(r)),t.push(n)),t}function yl(e){let t=r=>r.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),n=(r,o)=>{var s,l,d,u,p,f,b;let i=(d=e.styles)==null?void 0:d[String((l=(s=e.styleIds[r])==null?void 0:s[o])!=null?l:"default")];if(!i)return "";let a=[];i.font.name&&a.push(`font-family:'${i.font.name.replace(/['\\]/g,"\\$&")}'`),i.font.size&&a.push(`font-size:${i.font.size}pt`),i.font.bold&&a.push("font-weight:bold"),i.font.italic&&a.push("font-style:italic"),i.font.underline&&a.push("text-decoration:underline"),i.font.color&&a.push(`color:${i.font.color.rgb}`),i.fill.foregroundColor&&a.push(`background-color:${i.fill.foregroundColor.rgb}`),(u=i.alignment)!=null&&u.horizontal&&a.push(`text-align:${i.alignment.horizontal}`),(p=i.alignment)!=null&&p.vertical&&a.push(`vertical-align:${i.alignment.vertical==="center"?"middle":i.alignment.vertical}`);for(let w of ["top","bottom","left","right"]){let g=i.border[w];g!=null&&g.style&&g.style!=="none"&&a.push(`border-${w}:${g.style==="thick"?3:g.style==="medium"?2:1}px ${g.style==="double"?"double":/dash/i.test(g.style)?"dashed":/dot/i.test(g.style)?"dotted":"solid"} ${(b=(f=g.color)==null?void 0:f.rgb)!=null?b:"#000000"}`);}return a.join(";")};return `<table data-coco-spreadsheet="${t(e.id)}" data-coco-spreadsheet-payload="${encodeURIComponent(wo(e))}">${e.values.map((r,o)=>`<tr>${r.map((i,a)=>`<td style="${t(n(o,a))}">${t(String(i!=null?i:""))}</td>`).join("")}</tr>`).join("")}</table>`}function vl(e,t,n,r=false){return e.formulas.map(o=>o.map(i=>i===null||r?i:excel.shiftFormulaReferences(i,t-e.sourceRange.startRow,n-e.sourceRange.startColumn)))}function VN(e,t,n){let r=Math.max(1,n.length),o=Math.max(1,n.reduce((i,a)=>Math.max(i,a.length),0));return excel.formatRangeAddress(e,t,r,o)}function AS(e){return /[\t\r\n"]/.test(e)?`"${e.replace(/"/g,'""')}"`:e}function LS(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 WS(e,t){var r,o;let n=[];for(let i=t.startRow;i<=t.endRow;i++){let a=[];for(let s=t.startColumn;s<=t.endColumn;s++){let l=excel.formatCellAddress(i,s);a.push(e.mergeFollowerByAddress.has(l)?null:(o=(r=qe(e,i,s))==null?void 0:r.value)!=null?o:null);}n.push(a);}return n}function BS(e,t){let n=[];for(let r of e.mergeMasterByAddress.values())FS(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 DS(e,t){var r;let n=[];for(let o=t.startRow;o<=t.endRow;o++){let i=[];for(let a=t.startColumn;a<=t.endColumn;a++)i.push((r=qe(e,o,a))==null?void 0:r.styleId);n.push(i);}return n}function FS(e,t){return t.startRow>=e.startRow&&t.endRow<=e.endRow&&t.startColumn>=e.startColumn&&t.endColumn<=e.endColumn}function Rp(e){if(e==="")return null;let t=Number(e);return Number.isFinite(t)&&e.trim()!==""?t:e.toUpperCase()==="TRUE"?true:e.toUpperCase()==="FALSE"?false:e}function Lp(e,t,n){var s;let r=kl(t),o=kl(n),i=OS(r,o);if(Sl(r,e)||Sl(o,e))throw new Error("Auto fill does not support merged cells");let a=[];for(let l=o.startRow;l<=o.endRow;l++)for(let d=o.startColumn;d<=o.endColumn;d++){if(zS(l,d,r))continue;let u=i==="down"?r.startRow+Ap(l-r.startRow,Wp(r)):l,p=i==="right"?r.startColumn+Ap(d-r.startColumn,Bp(r)):d,f=qe(e,u,p),b=$S(e,r,i,l,d),w=f!=null&&f.formula?excel.shiftFormulaReferences(f.formula,l-u,d-p):void 0;a.push({row:l,column:d,value:w?null:(s=b!=null?b:f==null?void 0:f.source.value)!=null?s:null,formula:w,styleId:f==null?void 0:f.styleId});}return {direction:i,source:r,target:o,cells:a}}function Cl(e,t){return !Sl(kl(t),e)}function OS(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 $S(e,t,n,r,o){let i=n==="down"?Wp(t):Bp(t);if(i<2)return;let a=Array.from({length:i},(d,u)=>{let p=n==="down"?t.startRow+u:r,f=n==="right"?t.startColumn+u:o,b=qe(e,p,f);return b!=null&&b.formula||b==null?void 0:b.source.value});if(!a.every(d=>typeof d=="number"&&Number.isFinite(d)))return;let s=a[1]-a[0];if(!a.every((d,u)=>u===0||d===a[0]+s*u))return;let l=n==="down"?r-t.startRow:o-t.startColumn;return a[0]+s*l}function Sl(e,t){for(let n of t.mergeMasterByAddress.values())if(VS(e,n.range))return true;return false}function kl(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 Wp(e){return e.endRow-e.startRow+1}function Bp(e){return e.endColumn-e.startColumn+1}function zS(e,t,n){return e>=n.startRow&&e<=n.endRow&&t>=n.startColumn&&t<=n.endColumn}function VS(e,t){return !(e.endRow<t.startRow||e.startRow>t.endRow||e.endColumn<t.startColumn||e.startColumn>t.endColumn)}function Ap(e,t){return (e%t+t)%t}async function ZN(e,t,n,r){await e.worksheets.getItem(t).getCell(n).setValue(r);}async function JN(e,t,n,r){await e.worksheets.getItem(t).getCell(n).setFormula(r);}async function QN(e,t,n,r,o){let i=o.length,a=o.reduce((l,d)=>Math.max(l,d.length),0),s=o.map(l=>{let d=l.slice();for(;d.length<a;)d.push(null);return d});await e.worksheets.getItem(t).getRange(excel.formatRangeAddress(n,r,i,a)).setValues(s);}async function eT(e,t,n,r,o,i){await e.worksheets.getItem(t).getRange(excel.formatRangeAddress(n,r,o,i)).clear();}async function tT(e,t,n,r){await e.worksheets.getItem(t).getRange(excel.formatCellAddress(n,1)).setRowHeight(r);}async function nT(e,t,n,r){await e.worksheets.getItem(t).getRange(excel.formatCellAddress(1,n)).setColumnWidth(Hi(r));}function $p(e,t){let n=t.query.trim();if(!n)return [];let r=[],o=[...e.cellsByAddress.values()].sort((i,a)=>i.row-a.row||i.column-a.column);for(let i of o)if(zp(i,t.matchCase===true).includes(El(n,t.matchCase===true)))if(i.formula){let a=n.startsWith("=")?n.slice(1):n;r.push({address:i.address,formula:Op(i.formula,a,t.replacement,t.matchCase===true)});}else {let a=i.value===null?"":String(i.value);r.push({address:i.address,value:Op(a,n,t.replacement,t.matchCase===true)});}return r}function oT(e,t){let n=El(t.query,t.matchCase===true);if(!n)return [];let r=[],o=[...e.cellsByAddress.values()].sort((i,a)=>i.row-a.row||i.column-a.column);for(let i of o)zp(i,t.matchCase===true).includes(n)&&r.push({row:i.row,column:i.column,address:i.address,text:i.displayText});return r}function iT(e,t,n="forward"){var r,o,i,a;return e.length===0?null:n==="backward"?(o=(r=[...e].reverse().find(s=>Hp(s,t)<0))!=null?r:e[e.length-1])!=null?o:null:(a=(i=e.find(s=>Hp(s,t)>0))!=null?i:e[0])!=null?a:null}function aT(e){return {startRow:e.row,startColumn:e.column,endRow:e.row,endColumn:e.column}}function zp(e,t){let n=[e.displayText,GS(e.value),e.formula?`=${e.formula}`:""].filter(Boolean);return El(n.join(`
1557
- `),t)}function GS(e){return e===null?"":String(e)}function El(e,t){let n=e.trim();return t?n:n.toLocaleLowerCase()}function Hp(e,t){return e.row===t.row?e.column-t.column:e.row-t.row}function Op(e,t,n,r){if(!t)return e;let o=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return e.replace(new RegExp(o,r?"g":"gi"),n)}function Il(e,t,n){var o,i;let r=new Set;for(let a=t.startRow+1;a<=t.endRow;a+=1)r.add((i=(o=qe(e,a,n))==null?void 0:o.displayText)!=null?i:"");return [...r].sort((a,s)=>a.localeCompare(s,void 0,{numeric:true}))}function dT(e,t,n){var o,i,a;let r=new Set;for(let s=t.startRow+1;s<=t.endRow;s+=1)(o=e.rowMetaByIndex.get(s))!=null&&o.hidden||r.add((a=(i=qe(e,s,n))==null?void 0:i.displayText)!=null?a:"");return [...r].sort((s,l)=>s.localeCompare(l,void 0,{numeric:true}))}function Vp(e,t,n,r){var a,s;let o=new Set(typeof r=="string"?[r]:r),i=[];for(let l=t.startRow+1;l<=t.endRow;l+=1)o.has((s=(a=qe(e,l,n))==null?void 0:a.displayText)!=null?s:"")||i.push(l);return i}function Gp(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(([s,l])=>{var d,u;return l.has((u=(d=qe(e,i,s))==null?void 0:d.displayText)!=null?u:"")})||o.push(i);return o}function jp(e,t,n,r){let o=Array.from({length:t.endRow-t.startRow},(i,a)=>t.startRow+a+1);return o.sort((i,a)=>{var u,p,f,b;let s=(p=(u=qe(e,i,n))==null?void 0:u.displayText)!=null?p:"",l=(b=(f=qe(e,a,n))==null?void 0:f.displayText)!=null?b:"";if(s===""&&l!=="")return 1;if(s!==""&&l==="")return -1;let d=s.localeCompare(l,void 0,{numeric:true,sensitivity:"base"});return (r==="desc"?-d:d)||i-a}),o}function Nl(e,t){let n=Kp(t.source,t.rowOffset,t.columnOffset),r=yo(t.sourceSheet,t.targetSheet)?qS(n,t.source):[n];return excel.rewriteFormulaReferences(e,o=>{var w;let i=excel.splitSheetQualifiedAddress(o),a=(w=i.sheetName)!=null?w:t.formulaSheet,s=excel.parseRangeAddress(i.address),l={startRow:s.startRow,startColumn:s.startColumn,endRow:s.startRow+s.rowCount-1,endColumn:s.startColumn+s.columnCount-1},d=l;if(yo(a,t.targetSheet)){for(let g of r)if(l=_p(l,g),!l)return {ok:false,address:"#REF!"}}let u=yo(a,t.sourceSheet)&&qp(t.source,l),p=u?t.targetSheet:a;if(u?l=Kp(l,t.rowOffset,t.columnOffset):yo(a,t.sourceSheet)&&(l=_p(l,t.source)),!u&&yo(t.formulaSheet,t.resultSheet)&&l.startRow===d.startRow&&l.endRow===d.endRow&&l.startColumn===d.startColumn&&l.endColumn===d.endColumn)return {ok:true,address:o};let f=XS(i.address,l);return {ok:true,address:`${i.sheetName||p!==t.resultSheet?`'${p.replace(/'/g,"''")}'!`:""}${f}`}})}function yo(e,t){return e.toLowerCase()===t.toLowerCase()}function qp(e,t){return e.startRow<=t.startRow&&e.endRow>=t.endRow&&e.startColumn<=t.startColumn&&e.endColumn>=t.endColumn}function Kp(e,t,n){return {startRow:e.startRow+t,endRow:e.endRow+t,startColumn:e.startColumn+n,endColumn:e.endColumn+n}}function qS(e,t){let n=Math.max(e.startRow,t.startRow),r=Math.min(e.endRow,t.endRow),o=Math.max(e.startColumn,t.startColumn),i=Math.min(e.endColumn,t.endColumn);if(n>r||o>i)return [e];let a=[];return e.startRow<n&&a.push(H(v({},e),{endRow:n-1})),r<e.endRow&&a.push(H(v({},e),{startRow:r+1})),e.startColumn<o&&a.push({startRow:n,endRow:r,startColumn:e.startColumn,endColumn:o-1}),i<e.endColumn&&a.push({startRow:n,endRow:r,startColumn:i+1,endColumn:e.endColumn}),a}function _p(e,t){if(qp(t,e))return null;let n=v({},e);return t.startColumn<=e.startColumn&&t.endColumn>=e.endColumn&&(t.startRow<=e.startRow&&t.endRow>=e.startRow&&(n.startRow=t.endRow+1),t.endRow>=e.endRow&&t.startRow<=e.endRow&&(n.endRow=t.startRow-1)),t.startRow<=e.startRow&&t.endRow>=e.endRow&&(t.startColumn<=e.startColumn&&t.endColumn>=e.startColumn&&(n.startColumn=t.endColumn+1),t.endColumn>=e.endColumn&&t.startColumn<=e.endColumn&&(n.endColumn=t.startColumn-1)),n}function XS(e,t){var d;let n=e.split(":").map(u=>/^(\$?)([A-Z]+)(\$?)(\d+)$/i.exec(u)),r=n[0],o=(d=n[1])!=null?d:r,i=Number(r[4])>Number(o[4]),a=excel.columnNameToIndex(r[2])>excel.columnNameToIndex(o[2]),s=(u,p,f)=>`${u[1]}${excel.columnIndexToName(f)}${u[3]}${p}`,l=s(r,i?t.endRow:t.startRow,a?t.endColumn:t.startColumn);return n.length===1?l:`${l}:${s(o,i?t.startRow:t.endRow,a?t.startColumn:t.endColumn)}`}var Xi=class e{constructor(t,n={}){B(this,"state",t);B(this,"activeTransaction",null);B(this,"activeTransactionSource",null);B(this,"transactionNeedsRefresh",false);B(this,"readOnlyValue");this.readOnlyValue=n.readOnly===true;}static async fromZip(t,n={}){let a=n,{readOnly:r}=a,o=Mn(a,["readOnly"]),i=await excel.ExcelWorkbook.fromZip(t,o);return e.fromWorkbook(i,{readOnly:r})}static async fromWorkbook(t,n={}){var s;let r=await t.toModel(),o=(s=r.sheets.find(l=>l.sheetViews.some(d=>d.tabSelected===true)))!=null?s:r.sheets[0];if(!o)throw new Error("SpreadsheetEditorRuntime: workbook has no sheets");let i=new excel.SpreadsheetFormulaEngine(o,{sheets:r.sheets}),a=i.calculate();return new e({workbook:t,model:r,activeSheetName:o.name,formulaResults:a,formulaEngine:i,activeSheet:fo(o,r.styles,{formulaResults:a,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(H(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 a;let r=Zp(this.state.model),o=await excel.ExcelWorkbook.fromModel(r,{mode:"inline"}),i=await e.fromWorkbook(o);await i.setActiveSheet(this.state.activeSheetName);try{let s=await i.runAgentTransaction(t,n),l=Zp(i.model()),d=excel.diffExcelWorkbookModels(r,l);return {result:s,summary:(a=s==null?void 0:s.summary)!=null?a:null,diff:d,diffSummary:a0(d),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}`);if(!this.readOnlyValue){for(let i of await this.state.workbook.worksheets.items()){let a=await i.name(),s=await i.sheetViews(),l=a===t;await i.setSheetViews(s.length>0?s.map(d=>H(v({},d),{tabSelected:l})):[{workbookViewId:0,tabSelected:l,selections:[]}]);}for(let i of this.state.model.sheets){let a=i.name===t;i.sheetViews=i.sheetViews.length>0?i.sheetViews.map(s=>H(v({},s),{tabSelected:a})):[{workbookViewId:0,tabSelected:a,selections:[]}];}}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=fo(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(a=>a.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(a=>a.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(a=>a.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=H(v({},this.state),{model:t,activeSheetName:n.name,formulaResults:o,formulaEngine:r,activeSheet:fo(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=$p(this.state.activeSheet,{query:t,replacement:n,matchCase:r});return o.length===0?0:(await this.runUserMutation({label:`Replace ${t}`},async i=>{var a;for(let s of o)s.formula!==void 0?await i.setCellFormula(this.state.activeSheetName,s.address,s.formula):await i.setCellValue(this.state.activeSheetName,s.address,(a=s.value)!=null?a:null);}),o.length)}async filterRows(t,n,r,o){let i={startRow:t,startColumn:r,endRow:n,endColumn:r},a=o===null?[]:Vp(this.state.activeSheet,H(v({},i),{startColumn:1,endColumn:this.state.activeSheet.maxColumn}),r,o);await this.runUserMutation({label:o===null?"Clear filter":"Filter rows"},async s=>{await s.runSnapshot("Filter rows","spreadsheet row filter",async()=>{await this.state.workbook.executeCode(`
1604
+ `).map(T=>T.split(" "));Ba(C,{text:N});return}let E=C.kind==="text-range"?nt(s,C):{anchor:{paraId:C.paraId,offset:C.offset},focus:{paraId:C.paraId,offset:C.offset}};Xn(E,x);}catch(x){console.warn("Unable to paste from the context menu",x);}},$a=(c="add",m,x="")=>{let C=document.createElement("div");C.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 N=document.createElement("h2");N.id="coco-word-comment-dialog-title",N.textContent=c==="edit"?"\u7F16\u8F91\u6279\u6CE8":c==="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 M=document.createElement("button");M.type="button",M.className="coco-word-dialog-button is-secondary",M.textContent="\u53D6\u6D88";let H=document.createElement("button");H.type="button",H.className="coco-word-dialog-button is-primary",H.textContent="\u786E\u5B9A";let z=()=>C.remove();M.addEventListener("click",z),C.addEventListener("click",j=>{j.target===C&&z();}),E.addEventListener("keydown",j=>{j.key==="Escape"&&z(),j.key==="Enter"&&(j.ctrlKey||j.metaKey)&&(j.preventDefault(),H.click());}),H.addEventListener("click",()=>{let j=T.value.trim();if(!j){T.focus();return}ke(c==="edit"&&m!==void 0?{kind:"edit-comment",commentId:m,body:j}:c==="reply"&&m!==void 0?{kind:"reply-comment",commentId:m,body:j}:{kind:"add-comment",body:j}),z();}),P.append(M,H),E.append(N,T,P),C.appendChild(E),(o!=null?o:document.body).appendChild(C),T.focus();},jh=()=>{var E,N,T;let c=(E=h!=null?h:ze(e))!=null?E:lt(e),m=Rt(c),x=(c==null?void 0:c.kind)==="text-range"||(c==null?void 0:c.kind)==="object"||(c==null?void 0:c.kind)==="table-cell-range",C=[{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:(c==null?void 0:c.kind)==="object"||typeof((N=navigator.clipboard)==null?void 0:N.readText)!="function",action:Gh},{label:"\u5220\u9664",disabled:!x,action:()=>Vh()}];if((c==null?void 0:c.kind)==="text-range"&&(C.push({label:"\u6DFB\u52A0\u6279\u6CE8",separatorBefore:true,action:$a}),C.push({label:"\u6807\u8BB0\u4E3A\u63D2\u5165\u4FEE\u8BA2",action:()=>ke({kind:"add-revision",revisionKind:"insert"})}),C.push({label:"\u6807\u8BB0\u4E3A\u5220\u9664\u4FEE\u8BA2",action:()=>ke({kind:"add-revision",revisionKind:"delete"})}),C.push({label:m.bold===true?"\u53D6\u6D88\u52A0\u7C97":"\u52A0\u7C97",separatorBefore:true,disabled:!Wt(s,c,{kind:"toggle-bold"}),action:()=>ke({kind:"toggle-bold"})}),C.push({label:"\u6E05\u9664\u6587\u672C\u683C\u5F0F",action:()=>ke({kind:"clear-text-format"})}),m.hyperlink!==null&&C.push({label:"\u79FB\u9664\u8D85\u94FE\u63A5",disabled:!Wt(s,c,{kind:"remove-hyperlink"}),action:()=>ke({kind:"remove-hyperlink"})})),(c==null?void 0:c.kind)==="caret"&&Wt(s,c,{kind:"insert-table",rows:2,columns:2})&&C.push({label:"\u63D2\u5165 2 \xD7 2 \u8868\u683C",separatorBefore:true,action:()=>ke({kind:"insert-table",rows:2,columns:2})}),(c==null?void 0:c.kind)==="object"&&c.objectKind==="image"&&(C.push({label:"\u56FE\u7247\u5DE6\u5BF9\u9F50",separatorBefore:true,action:()=>ke({kind:"set-image-alignment",objectId:c.objectId,alignment:"left"})}),C.push({label:"\u56FE\u7247\u5C45\u4E2D",action:()=>ke({kind:"set-image-alignment",objectId:c.objectId,alignment:"center"})}),C.push({label:"\u56FE\u7247\u53F3\u5BF9\u9F50",action:()=>ke({kind:"set-image-alignment",objectId:c.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};C.push({label:"\u9009\u62E9\u6574\u884C",separatorBefore:true,action:()=>se({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)}})}),C.push({label:"\u9009\u62E9\u6574\u5217",action:()=>se({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}})}),C.push({label:"\u5728\u4E0A\u65B9\u63D2\u5165\u884C",disabled:!Wt(s,c,{kind:"insert-table-row"}),action:()=>ke({kind:"insert-table-row",position:"before"})}),C.push({label:"\u5728\u4E0B\u65B9\u63D2\u5165\u884C",disabled:!Wt(s,c,{kind:"insert-table-row"}),action:()=>ke({kind:"insert-table-row",position:"after"})}),C.push({label:"\u5220\u9664\u5F53\u524D\u884C",disabled:!Wt(s,c,{kind:"delete-table-row"}),action:()=>ke({kind:"delete-table-row"})}),C.push({label:"\u5728\u5DE6\u4FA7\u63D2\u5165\u5217",disabled:!Wt(s,c,{kind:"insert-table-column"}),action:()=>ke({kind:"insert-table-column",position:"before"})}),C.push({label:"\u5728\u53F3\u4FA7\u63D2\u5165\u5217",disabled:!Wt(s,c,{kind:"insert-table-column"}),action:()=>ke({kind:"insert-table-column",position:"after"})}),C.push({label:"\u5220\u9664\u5F53\u524D\u5217",disabled:!Wt(s,c,{kind:"delete-table-column"}),action:()=>ke({kind:"delete-table-column"})}),C.push({label:"\u5220\u9664\u8868\u683C",separatorBefore:true,disabled:!Wt(s,c,{kind:"delete-table"}),action:()=>ke({kind:"delete-table"})});for(let[M,H]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"]])C.push({label:M,action:()=>ke({kind:"set-table-cell-vertical-alignment",alignment:H})});}return C.push({label:"\u64A4\u9500",separatorBefore:true,disabled:!K.length,action:()=>Ir()},{label:"\u91CD\u505A",disabled:!X.length,action:()=>Nr()}),C},Uh=c=>{var N,T;let m=c.target;if(m instanceof HTMLImageElement){let P=Nt(m),M=P==null?void 0:P.dataset.paraId,H=m.dataset.drawingId;if(P&&M&&H){let z={kind:"object",paraId:M,objectKind:"image",objectId:H,offset:Si(P,m)};return g={paraId:M,drawingId:H},_t(),se(z),z}}let x=In(m);if(x){if((h==null?void 0:h.kind)==="table-cell-range"&&h.tableId===x.tableId){let M=Math.min(h.anchor.rowIndex,h.focus.rowIndex),H=Math.max(h.anchor.rowIndex,h.focus.rowIndex),z=Math.min(h.anchor.columnIndex,h.focus.columnIndex),j=Math.max(h.anchor.columnIndex,h.focus.columnIndex);if(x.point.rowIndex>=M&&x.point.rowIndex<=H&&x.point.columnIndex>=z&&x.point.columnIndex<=j)return h}let P={kind:"table-cell-range",tableId:x.tableId,anchor:x.point,focus:x.point};return (N=Tt(e))==null||N.removeAllRanges(),se(P),P}let C=(T=uf(e,c.clientX,c.clientY))!=null?T:pt(e);if(!C)return h;if((h==null?void 0:h.kind)==="text-range"){let P=nt(s,h),M=ve(s,P.anchor.paraId),H=ve(s,P.focus.paraId),z=ve(s,C.paraId);if(M&&H&&z&&M.container===H.container&&M.container===z.container){let j=z.index>M.index||z.index===M.index&&C.offset>=P.anchor.offset,re=z.index<H.index||z.index===H.index&&C.offset<=P.focus.offset;if(j&&re)return h}}g=null,Pt(e),dt(e,C);let E=v({kind:"caret"},C);return se(E),E},gd=c=>{var C;if(d||n.contextMenu===false)return;c.preventDefault(),c.stopPropagation(),ut(),ht(),Uh(c);let m=document.createElement("div");m.className="coco-word-context-menu",m.setAttribute("role","menu"),m.contentEditable="false";for(let E of jh()){if(E.separatorBefore){let T=document.createElement("div");T.className="coco-word-context-menu-separator",T.setAttribute("role","separator"),m.appendChild(T);}let N=document.createElement("button");N.type="button",N.className="coco-word-context-menu-item",N.textContent=E.label,N.disabled=(C=E.disabled)!=null?C:false,N.setAttribute("role","menuitem"),N.addEventListener("mousedown",T=>T.preventDefault()),N.addEventListener("click",()=>{let T=E.action();ht(),T instanceof Promise&&T.catch(P=>console.warn("Context menu action failed",P));}),m.appendChild(N);}(o!=null?o:document.body).appendChild(m),Kt=m;let x=m.getBoundingClientRect();m.style.left=`${Math.max(4,Math.min(c.clientX,window.innerWidth-x.width-4))}px`,m.style.top=`${Math.max(4,Math.min(c.clientY,window.innerHeight-x.height-4))}px`;},bd=c=>{Kt&&!Kt.contains(c.target)&&ht();},wd=c=>{c.key==="Escape"&&ht();},xd=c=>{var E;if(d){c.preventDefault();return}if(c.inputType===B){c.preventDefault(),B=null,G!==null&&window.clearTimeout(G),G=null;return}if(c.inputType==="historyUndo"&&Ir()){c.preventDefault(),c.stopPropagation();return}if(c.inputType==="historyRedo"&&Nr()){c.preventDefault(),c.stopPropagation();return}if(c.isComposing||ie||oe||c.inputType==="insertCompositionText"||c.inputType==="deleteCompositionText"||c.inputType==="insertFromComposition")return;if(g&&c.inputType==="deleteContentBackward"){c.preventDefault();let N={paraId:g.paraId,offset:0};Pn(g.paraId,g.drawingId,N);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(S&&x&&(c.inputType==="insertText"||c.inputType==="deleteContentBackward"||c.inputType==="deleteContentForward")){if(x.kind==="caret"||x.kind==="text-range"&&x.anchor.paraId===x.focus.paraId){c.preventDefault(),c.inputType==="insertText"&&c.data?x.kind==="caret"?ke({kind:"insert-text",text:c.data}):ke({kind:"replace-range",anchor:x.anchor,focus:x.focus,text:c.data}):c.inputType==="deleteContentBackward"?x.kind==="text-range"&&x.anchor.offset!==x.focus.offset?ke({kind:"delete-range",anchor:x.anchor,focus:x.focus}):ke({kind:"delete-backward"}):c.inputType==="deleteContentForward"&&(x.kind==="text-range"&&x.anchor.offset!==x.focus.offset?ke({kind:"delete-range",anchor:x.anchor,focus:x.focus}):ke({kind:"delete-forward"}));return}if(x.kind==="text-range"&&(c.inputType==="deleteContentBackward"||c.inputType==="deleteContentForward")){c.preventDefault(),ke({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 N=Li(x.anchor.offset,x.focus.offset);if(Do(x.anchor.paraId)&&(c.inputType==="insertText"&&c.data||c.inputType==="deleteContentBackward"||c.inputType==="deleteContentForward")){g=null,Cr(x.anchor.paraId),Fo({anchor:{paraId:x.anchor.paraId,offset:N.from},focus:{paraId:x.focus.paraId,offset:N.to}}),se(x);return}if(c.inputType==="insertText"&&c.data){c.preventDefault(),g=null,se({kind:"caret",paraId:x.anchor.paraId,offset:N.from+c.data.length}),Tn(Gr(s,x.anchor.paraId,N.from,N.to,c.data),{paraId:x.anchor.paraId,offset:N.from+c.data.length},{localParaId:x.anchor.paraId});return}if(c.inputType==="deleteContentBackward"||c.inputType==="deleteContentForward"){if(c.preventDefault(),g=null,$o(x))return;se({kind:"caret",paraId:x.anchor.paraId,offset:N.from}),Tn(bn(s,x.anchor.paraId,N.from,N.to),{paraId:x.anchor.paraId,offset:N.from},{localParaId:x.anchor.paraId});return}}if((x==null?void 0:x.kind)==="text-range"&&x.anchor.paraId!==x.focus.paraId){let N=nt(s,x);if(c.inputType==="insertText"&&c.data){if(c.preventDefault(),g=null,Oo(N,c.data))return;id(N,c.data);return}if(c.inputType==="deleteContentBackward"||c.inputType==="deleteContentForward"){if(Oo(N,"")){c.preventDefault();return}if(!Th(N)&&Ch(N)){g=null,se({kind:"caret",paraId:N.anchor.paraId,offset:N.anchor.offset});return}c.preventDefault(),g=null,se({kind:"caret",paraId:N.anchor.paraId,offset:N.anchor.offset}),id(N,"");return}c.preventDefault(),se(x);return}let C=(x==null?void 0:x.kind)==="caret"?x:pt(e);if(C){if(g=null,se({kind:"caret",paraId:C.paraId,offset:C.offset}),c.inputType==="insertText"&&c.data&&c.data!==`
1605
+ `&&c.data!=="\r"&&Do(C.paraId)){Cr(C.paraId),Fo({anchor:C,focus:C});return}if(c.inputType==="deleteContentBackward"&&C.offset>0&&Do(C.paraId)){Cr(C.paraId),Fo({anchor:C,focus:C});return}if(c.inputType==="deleteContentForward"&&C.offset<Aa(C.paraId)&&Do(C.paraId)){Cr(C.paraId),Fo({anchor:C,focus:C});return}if(c.inputType==="insertText"&&(c.data===`
1606
+ `||c.data==="\r")||c.inputType==="insertParagraph"){if(c.preventDefault(),I){I=false,A!==null&&window.clearTimeout(A),A=null;return}Fa(C);}else if(c.inputType==="insertText"&&c.data)c.preventDefault(),Tn(on(s,C.paraId,C.offset,c.data),{paraId:C.paraId,offset:C.offset+c.data.length},{localParaId:C.paraId});else if(c.inputType==="deleteContentBackward"){if(c.preventDefault(),Rn(C,"delete-backward")||zo(v({kind:"caret"},C),"backward")||dd(C))return;let N=Z(s,C.paraId),T=N?ge(N):null,P=zr(s,C.paraId,C.offset),M={paraId:C.offset>0?C.paraId:(E=ls(s,C.paraId))!=null?E:C.paraId,offset:Math.max(0,C.offset-1)};(P==null?void 0:P.kind)==="image"?Tr(T,P,M):Tn(P,M,(P==null?void 0:P.kind)==="block"?{}:{localParaId:C.paraId});}else if(c.inputType==="deleteContentForward"){if(c.preventDefault(),Rn(C,"delete-forward")||zo(v({kind:"caret"},C),"forward")||cd(C))return;let N=Z(s,C.paraId),T=N?ge(N):null,P=Vr(s,C.paraId,C.offset),M={paraId:C.paraId,offset:C.offset};(P==null?void 0:P.kind)==="image"?Tr(T,P,M):Tn(P,M,{localParaId:C.paraId});}}},Vo=c=>{var M,H,z,j,re,ce,ye,Me;if(l)return;if(c.currentTarget===document){if(c.composedPath().includes(e)||lo.get(document)!==e)return}else ut();if(ie||c.isComposing||c.keyCode===229)return;if((c.ctrlKey||c.metaKey)&&!c.shiftKey&&c.key.toLowerCase()==="c"&&g&&typeof((M=navigator.clipboard)==null?void 0:M.write)=="function"&&typeof ClipboardItem!="undefined"){let _=g;c.preventDefault(),c.stopPropagation(),Oa(_).catch(Q=>{console.warn("Unable to copy the selected image",Q);});return}if(d){(c.ctrlKey||c.metaKey)&&(c.key.toLowerCase()==="z"||c.key.toLowerCase()==="y")&&(c.preventDefault(),c.stopPropagation());return}let x=(c.ctrlKey||c.metaKey)&&!c.shiftKey&&c.key.toLowerCase()==="z",C=(c.ctrlKey||c.metaKey)&&c.shiftKey&&c.key.toLowerCase()==="z"||(c.ctrlKey||c.metaKey)&&c.key.toLowerCase()==="y";(x||C)&&B&&(B=null,G!==null&&window.clearTimeout(G),G=null);let E=x||C?pt(e):null,N=(H=E==null?void 0:E.paraId)!=null?H:h&&"paraId"in h?h.paraId:null;if(x&&Ir()){Ql("historyUndo"),c.preventDefault(),c.stopPropagation();return}if(C&&Nr()){Ql("historyRedo"),c.preventDefault(),c.stopPropagation();return}if((c.ctrlKey||c.metaKey)&&!c.shiftKey&&c.key==="Enter"){let _=(z=h!=null?h:ze(e))!=null?z:lt(e);(_==null?void 0:_.kind)==="caret"&&ke({kind:"insert-page-break"})&&(c.preventDefault(),c.stopPropagation());return}if((x||C)&&(V!==null&&window.clearTimeout(V),Bo.disconnect(),V=window.setTimeout(()=>{var me,pe;V=null;let _=pt(e),Q=(me=_==null?void 0:_.paraId)!=null?me:N;if(!Q)return;let te=e.querySelector(`coco-word-native-p[data-para-id="${Q}"]`),ne=Z(s,Q);if(te&&ne&&ne.content.every(Y=>Y.kind==="text")){let Y=Ur(s,Q,(pe=te.textContent)!=null?pe:"");Y&&(u.push(Y),Re("deferred"));}De(Q,_!=null?_:void 0);},120)),(h==null?void 0:h.kind)==="table-cell-range"){if(c.key==="Escape"){c.preventDefault(),se(null);return}if(c.key==="Enter"||c.key==="F2"){let Q=(j=Oe(s,h.tableId))==null?void 0:j.table,te=Q?(re=tt(Q,h)[0])==null?void 0:re.cell:null,ne=te==null?void 0:te.paragraphs[0];if(ne){c.preventDefault();let me={paraId:ne.paraId,offset:Te(ne).length};dt(e,me),se(v({kind:"caret"},me));}return}let _=c.key==="ArrowLeft"?{row:0,column:-1}:c.key==="ArrowRight"?{row:0,column:1}:c.key==="ArrowUp"?{row:-1,column:0}:c.key==="ArrowDown"?{row:1,column:0}:null;if(_){let Q=(ce=Oe(s,h.tableId))==null?void 0:ce.table,te=Q?Math.max(1,...Q.rows.map(me=>me.cells.reduce((pe,Y)=>pe+Math.max(1,Y.gridSpan),0))):1,ne={rowIndex:Math.max(0,Math.min(((ye=Q==null?void 0:Q.rows.length)!=null?ye:1)-1,h.focus.rowIndex+_.row)),columnIndex:Math.max(0,Math.min(te-1,h.focus.columnIndex+_.column))};c.preventDefault(),se({kind:"table-cell-range",tableId:h.tableId,anchor:c.shiftKey?h.anchor:ne,focus:ne});return}}if(!c.shiftKey&&["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"].includes(c.key)&&($=null),g&&(c.key==="Backspace"||c.key==="Delete")){c.preventDefault();let _={paraId:g.paraId,offset:0};Pn(g.paraId,g.drawingId,_);return}if((h==null?void 0:h.kind)==="table-cell-range"&&(c.key==="Backspace"||c.key==="Delete")){c.preventDefault(),c.stopPropagation(),qn(h);return}if(c.key!=="Enter")return;let T=pt(e);if(!T)return;c.preventDefault(),c.stopPropagation();let P=Z(s,T.paraId);if((Me=P==null?void 0:P.format)!=null&&Me.hasNumbering&&P.format.numbering&&Te(P).length===0){g=null,se({kind:"caret",paraId:T.paraId,offset:0}),ke({kind:"remove-list"});return}g=null,I=true,A!==null&&window.clearTimeout(A),A=window.setTimeout(()=>{I=false,A=null;},0),Fa(T);},yd=c=>{if(!(l||c.composedPath().includes(e)||lo.get(document)!==e)){if(d){c.preventDefault(),c.stopPropagation();return}(c.inputType==="historyUndo"&&Ir()||c.inputType==="historyRedo"&&Nr())&&(c.preventDefault(),c.stopPropagation());}},za=(c,m)=>{let x=c.querySelector(":scope > .coco-word-native-revision-group-list"),C=c.querySelector(":scope > .coco-word-native-revision-group-toggle");if(!x||!C)return;c.classList.toggle("is-expanded",m),x.hidden=!m,C.setAttribute("aria-expanded",String(m));let E=C.querySelector(".coco-word-native-revision-group-affordance");E&&(E.textContent=m?"\u6536\u8D77":"\u5C55\u5F00");},vd=c=>{e.querySelectorAll(".coco-word-native-revision-group.is-expanded").forEach(m=>{m!==c&&za(m,false);});},Sd=c=>{var Me,_,Q,te,ne,me,pe,Y,Ie,He;let m=(Me=c.composedPath().find(be=>be instanceof HTMLButtonElement&&be.matches("[data-revision-action][data-revision-id]")))!=null?Me:c.target instanceof Element?c.target.closest("[data-revision-action][data-revision-id]"):null;if(m){c.preventDefault(),c.stopPropagation();let be=m.dataset.revisionId;be&&ke({kind:m.dataset.revisionAction==="accept"?"accept-revision":"reject-revision",revisionId:be,revisionKind:m.dataset.revisionKind});return}let x=(_=c.composedPath().find(be=>be instanceof HTMLButtonElement&&be.matches("[data-revision-group-toggle]")))!=null?_:c.target instanceof Element?c.target.closest("[data-revision-group-toggle]"):null;if(x){c.preventDefault(),c.stopPropagation();let be=x.closest(".coco-word-native-revision-group"),Fe=be==null?void 0:be.querySelector(":scope > .coco-word-native-revision-group-list");if(!be||!Fe)return;let ue=Fe.hidden;vd(be),za(be,ue);return}let C=(Q=c.composedPath().find(be=>be instanceof HTMLButtonElement&&be.matches("[data-comment-menu][data-comment-id]")))!=null?Q:c.target instanceof Element?c.target.closest("[data-comment-menu][data-comment-id]"):null;if(C){c.preventDefault(),c.stopPropagation();let be=C.dataset.commentId;if(!be)return;let Fe=(te=C.parentElement)==null?void 0:te.querySelector(`[data-comment-menu-for="${CSS.escape(be)}"]`);if(!Fe)return;e.querySelectorAll(".coco-word-native-comment-menu:not([hidden])").forEach(ue=>{ue!==Fe&&(ue.hidden=true);}),Fe.hidden=!Fe.hidden;return}let E=(ne=c.composedPath().find(be=>be instanceof HTMLButtonElement&&be.matches("[data-comment-action][data-comment-id]")))!=null?ne:c.target instanceof Element?c.target.closest("[data-comment-action][data-comment-id]"):null;if(E){c.preventDefault(),c.stopPropagation();let be=Number(E.dataset.commentId);if(!Number.isFinite(be))return;let Fe=E.closest(".coco-word-native-comment-bubble");E.dataset.commentAction==="edit"?$a("edit",be,(me=Fe==null?void 0:Fe.dataset.commentBody)!=null?me:""):E.dataset.commentAction==="reply"?$a("reply",be):ke({kind:"delete-comment",commentId:be});return}if(We){We=false,c.preventDefault(),c.stopPropagation();return}if(Kn){Kn=false,c.preventDefault(),c.stopPropagation();return}if(Ge){c.preventDefault(),c.stopPropagation(),at(true),queueMicrotask(()=>{Ge=false,at(true);});return}ut(),$=null;let N=c.target,T=N instanceof Element?N.closest(".coco-word-comment[data-comment-id]"):null,P=N instanceof Element?N.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,M=N instanceof Element?N.closest(".coco-word-native-comment-bubble, .coco-word-native-revision-bubble"):null,H=M!=null?M:T?e.querySelector(`.coco-word-native-comment-bubble[data-comment-id="${CSS.escape((pe=T.dataset.commentId)!=null?pe:"")}"]`):P?e.querySelector(`.coco-word-native-revision-bubble[data-revision-id="${CSS.escape((Y=P.dataset.revisionId)!=null?Y:"")}"][data-revision-kind="${CSS.escape((Ie=P.dataset.revisionKind)!=null?Ie:P.classList.contains("coco-word-revision-delete")?"delete":"insert")}"]`):null;if(H){let be=H.closest(".coco-word-native-revision-group");be&&(vd(be),za(be,true));let Fe=H.dataset.paraId,ue=Number(H.dataset.from),Je=Number(H.dataset.to);if(Fe&&Number.isFinite(ue)&&Number.isFinite(Je)){c.preventDefault(),c.stopPropagation(),e.querySelectorAll(".coco-word-native-comment-bubble.is-selected, .coco-word-native-revision-bubble.is-selected").forEach(Be=>Be.classList.remove("is-selected")),H.classList.add("is-selected");let he={kind:"text-range",anchor:{paraId:Fe,offset:ue},focus:{paraId:Fe,offset:Math.max(ue+1,Je)}};se(he);let we=T!=null?T:(()=>{var Ke,je,tn,An,Yn,Uo;let Be=M==null?void 0:M.closest("coco-word-native-page");if(!Be)return null;let le=H.dataset.revisionKind?`.coco-word-revision-insert[data-revision-id="${CSS.escape((Ke=H.dataset.revisionId)!=null?Ke:"")}"], .coco-word-revision-delete[data-revision-id="${CSS.escape((je=H.dataset.revisionId)!=null?je:"")}"], .coco-word-revision-format[data-revision-id="${CSS.escape((tn=H.dataset.revisionId)!=null?tn:"")}"], img[data-revision-id="${CSS.escape((An=H.dataset.revisionId)!=null?An:"")}"], coco-word-native-table[data-revision-id="${CSS.escape((Yn=H.dataset.revisionId)!=null?Yn:"")}"]`:`.coco-word-comment[data-comment-id="${CSS.escape((Uo=H.dataset.commentId)!=null?Uo:"")}"]`;return Be.querySelector(le)})();(!we||!ff(e,we))&&vn(e,he.anchor,he.focus);return}}let z=In(N);if(z){if(c.preventDefault(),c.stopPropagation(),g=null,Pt(e),(He=Tt(e))==null||He.removeAllRanges(),(h==null?void 0:h.kind)==="table-cell-range"&&h.tableId===z.tableId&&z.point.rowIndex>=Math.min(h.anchor.rowIndex,h.focus.rowIndex)&&z.point.rowIndex<=Math.max(h.anchor.rowIndex,h.focus.rowIndex)&&z.point.columnIndex>=Math.min(h.anchor.columnIndex,h.focus.columnIndex)&&z.point.columnIndex<=Math.max(h.anchor.columnIndex,h.focus.columnIndex))return;se({kind:"table-cell-range",tableId:z.tableId,anchor:z.point,focus:z.point});return}let j=N instanceof Element?N.closest("a.coco-word-hyperlink"):null;if(j){if(d)return;if(c.preventDefault(),(c.ctrlKey||c.metaKey)&&zv(j.dataset.hyperlinkTarget)){window.open(j.dataset.hyperlinkTarget,"_blank","noopener,noreferrer");return}}if(!(N instanceof HTMLImageElement)){let be=N instanceof Node?Nt(N):null,Fe=ze(e);if(g=null,Pt(e),be)return;if((Fe==null?void 0:Fe.kind)==="text-range"){se(Fe);return}let ue=pt(e);ue&&dt(e,ue),se(ue?{kind:"caret",paraId:ue.paraId,offset:ue.offset}:null);return}let re=Nt(N),ce=re==null?void 0:re.dataset.paraId,ye=N.dataset.drawingId;!re||!ce||!ye||(re.focus(),g={paraId:ce,drawingId:ye},Pt(e),_t(),se({kind:"object",paraId:ce,objectKind:"image",objectId:ye,offset:Si(re,N)}));},kd=c=>{var P;if(c.button!==0||(et=false,c.target instanceof Node&&Nt(c.target)&&(y=null),c.target instanceof HTMLImageElement))return;let m=c.target instanceof Element?c.target:null,x=m?Nt(m):null,C=(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&&!C&&!E&&(h==null?void 0:h.kind)==="text-range"?(Ge=true,at(true)):Ge=false;let N=In(c.target);if(N&&(Ge=false),!N){ft=null,Ce=true;return}Ce=false;let T=N.point;if(c.shiftKey){if((h==null?void 0:h.kind)==="table-cell-range"&&h.tableId===N.tableId)T=h.anchor;else if(h&&h.kind!=="table-cell-range"){let M=h.kind==="text-range"?h.anchor.paraId:h.paraId,H=rn(s,M);(H==null?void 0:H.table.tableId)===N.tableId&&(T={rowIndex:H.rowIndex,columnIndex:H.columnIndex});}c.preventDefault(),(P=Tt(e))==null||P.removeAllRanges(),ft={tableId:N.tableId,point:T},Qt=true,se({kind:"table-cell-range",tableId:N.tableId,anchor:T,focus:N.point});return}ft={tableId:N.tableId,point:N.point},Qt=false;},Cd=c=>{var x;if(Ce&&(c.buttons&1)!==0){return}if(!ft||(c.buttons&1)===0)return;let m=In(c.target);!m||m.tableId!==ft.tableId||!Qt&&m.point.rowIndex===ft.point.rowIndex&&m.point.columnIndex===ft.point.columnIndex||(c.preventDefault(),(x=Tt(e))==null||x.removeAllRanges(),Qt=true,se({kind:"table-cell-range",tableId:ft.tableId,anchor:ft.point,focus:m.point}));},Go=()=>{var m;if(Ce){let x=ze(e);(x==null?void 0:x.kind)==="text-range"&&(y=x,se(x),We=true),Ce=false;}if(Qt){(m=Tt(e))==null||m.removeAllRanges(),Nn(h),Kn=true,Qt=false,ft=null;return}ft=null;let c=ze(e);(c==null?void 0:c.kind)==="text-range"&&(y=c,g=null,Pt(e),se(c));},Ed=()=>{(ft||Ce)&&Go();},Id=()=>{var x;if(l||ie||oe||(h==null?void 0:h.kind)==="object"&&g||(h==null?void 0:h.kind)==="table-cell-range")return;if(We&&y){se(y),at(true);return}if(Ge){at(true);return}if(et){at(true);return}let c=document.activeElement;if(c instanceof HTMLElement&&c!==document.body&&c!==i&&!e.contains(c)){at();return}Ea();let m=(x=ze(e))!=null?x:lt(e);(m==null?void 0:m.kind)==="text-range"&&(y=m),m&&(ut(),se(m));},Nd=c=>{c.target;c.composedPath().some(E=>E instanceof Element&&E.matches("coco-word-native-page, coco-word-native-p, coco-word-native-table"))?et=false:(h==null?void 0:h.kind)==="text-range"&&(et=true),queueMicrotask(at);},Rr=c=>{let m=c.composedPath(),x=m.some(N=>N instanceof Element&&N.matches("coco-word-native-page, coco-word-native-p, coco-word-native-table")),C=m.some(N=>N instanceof HTMLButtonElement&&N.matches("[data-revision-action][data-revision-id], [data-revision-group-toggle]"));if(l||c.button!==0||x||C)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&&se(E),et=true,Ge=true,at(true),queueMicrotask(()=>at(true)),window.setTimeout(()=>at(true),0));},Td=c=>{Rr(c),window.setTimeout(()=>at(true),0);},Pd=c=>{d&&c.preventDefault();},jo=c=>{e.classList.toggle("is-hyperlink-navigation-mode",c.ctrlKey||c.metaKey);},Rd=()=>{e.classList.remove("is-hyperlink-navigation-mode");},Md=c=>{var M,H,z,j;if(d)return;let m=c;if(m.inputType===B){B=null,G!==null&&window.clearTimeout(G),G=null;return}if(m.isComposing||ie||m.inputType==="insertCompositionText"||m.inputType==="deleteCompositionText")return;if(oe){J!==null&&window.clearTimeout(J),Wa();return}if(Eh()||m.inputType==="historyUndo"&&Ih()||m.inputType==="historyRedo"&&Nh())return;let x=pt(e),C=(M=Nt(c.target))!=null?M:x?e.querySelector(`coco-word-native-p[data-para-id="${x.paraId}"]`):null;if(!C||!e.contains(C))return;let E=(H=C.dataset.paraId)!=null?H:"",N=Z(s,E);if(!N||N.content.some(re=>re.kind!=="text"))return;let T=Ur(s,E,(z=C.textContent)!=null?z:"");if(!T){(m.inputType==="historyUndo"||m.inputType==="historyRedo")&&pn(E);return}u.push(T);let P=ed(E,T);P&&u.push(P),$&&m.inputType!=="historyUndo"&&m.inputType!=="historyRedo"&&((j=$.afterParagraphs[0])==null?void 0:j.paraId)===E?($.changes.push(T),$.afterParagraphs=[ge(N)]):$=null,X.length=0,Pa(E),x&&se({kind:"caret",paraId:x.paraId,offset:x.offset}),P&&Ta(E,x!=null?x:void 0),Re("deferred");},Va=c=>{var x,C;if(l)return false;if(!c){let E=Tt(e);return E&&(e.contains(E.anchorNode)||e.contains(E.focusNode))&&E.removeAllRanges(),g=null,Pt(e),se(null),true}if(c.kind==="caret")return Z(s,c.paraId)?(g=null,Pt(e),dt(e,c),se(c),true):false;if(c.kind==="text-range")return !Z(s,c.anchor.paraId)||!Z(s,c.focus.paraId)?false:(g=null,Pt(e),vn(e,c.anchor,c.focus),se(c),true);if(c.kind==="table-cell-range"){let E=(x=Oe(s,c.tableId))==null?void 0:x.table;return !E||tt(E,c).length===0?false:(g=null,Pt(e),(C=Tt(e))==null||C.removeAllRanges(),se(c),true)}let m=e.querySelector(`coco-word-native-p[data-para-id="${c.paraId}"] img[data-drawing-id="${c.objectId}"]`);return !Z(s,c.paraId)||!m?false:(g={paraId:c.paraId,drawingId:c.objectId},Pt(e),_t(),se(c),true)},Ad=()=>{F!==null&&window.clearTimeout(F),L!==null&&window.clearTimeout(L),V!==null&&window.clearTimeout(V),ee!==null&&window.clearTimeout(ee),fe!==null&&window.clearTimeout(fe),A!==null&&window.clearTimeout(A),J!==null&&window.clearTimeout(J),G!==null&&window.clearTimeout(G),F=null,L=null,V=null,ee=null,fe=null,A=null,J=null,G=null;};return e.addEventListener("beforeinput",xd),e.addEventListener("compositionstart",nd),e.addEventListener("compositionend",rd),e.addEventListener("copy",Ha),e.addEventListener("cut",md),e.addEventListener("paste",hd),e.addEventListener("drop",Pd),e.addEventListener("keydown",Vo),e.addEventListener("mousedown",kd),e.addEventListener("click",Sd),e.addEventListener("mouseup",Go),e.addEventListener("input",Md),e.addEventListener("contextmenu",gd),document.addEventListener("keydown",Vo,true),document.addEventListener("beforeinput",yd,true),document.addEventListener("selectionchange",Id),document.addEventListener("focusin",Nd),document.addEventListener("pointerdown",Rr,true),document.addEventListener("pointerup",Rr,true),document.addEventListener("click",Td,true),document.addEventListener("keydown",jo,true),document.addEventListener("keyup",jo,true),document.addEventListener("mousemove",Cd),document.addEventListener("pointerdown",bd,true),document.addEventListener("keydown",wd,true),document.addEventListener("scroll",ht,true),window.addEventListener("resize",ht),window.addEventListener("mouseup",Ed),window.addEventListener("blur",Rd),Pe(),{kind:"native-word",get destroyed(){return l},isReadOnly(){return d},setReadOnly(c){l||d===c||(d=c,ht(),d&&(Ze==null||Ze(),Ze=null,ae=null,oe=null,$=null,ie=false),Pe(void 0,h!=null?h:void 0));},destroy(){l||(l=true,e.removeEventListener("beforeinput",xd),e.removeEventListener("compositionstart",nd),e.removeEventListener("compositionend",rd),e.removeEventListener("copy",Ha),e.removeEventListener("cut",md),e.removeEventListener("paste",hd),e.removeEventListener("drop",Pd),e.removeEventListener("keydown",Vo),e.removeEventListener("mousedown",kd),e.removeEventListener("click",Sd),e.removeEventListener("mouseup",Go),e.removeEventListener("input",Md),e.removeEventListener("contextmenu",gd),document.removeEventListener("keydown",Vo,true),document.removeEventListener("beforeinput",yd,true),document.removeEventListener("selectionchange",Id),document.removeEventListener("focusin",Nd),document.removeEventListener("pointerdown",Rr,true),document.removeEventListener("pointerup",Rr,true),document.removeEventListener("click",Td,true),document.removeEventListener("keydown",jo,true),document.removeEventListener("keyup",jo,true),document.removeEventListener("mousemove",Cd),document.removeEventListener("pointerdown",bd,true),document.removeEventListener("keydown",wd,true),document.removeEventListener("scroll",ht,true),window.removeEventListener("resize",ht),window.removeEventListener("mouseup",Ed),window.removeEventListener("blur",Rd),window.removeEventListener("resize",Ao),document.removeEventListener("scroll",Ao,true),Ze==null||Ze(),Ze=null,ht(),Ia(),Ea(),Ca.remove(),Ad(),Bo.disconnect(),lo.get(document)===e&&lo.delete(document),kt.change.clear(),kt.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(c){if(l)throw new Error("Cannot load a document into a destroyed Word editor");Ad(),Bo.disconnect(),a=c,ht(),Ia(),s=ss(a),u.length=0,f=[],b.clear();for(let m of _e(s))b.add(m.paraId);w=Date.now()>>>0,g=null,_n(),h=null,ae=null,oe=null,$=null,ie=false,U=null,B=null,K.length=0,X.length=0,Pe(),Ma();},getSourceView(){return a},getDocument(){return s},getSelection(){var c;return (c=h!=null?h:ze(e))!=null?c:lt(e)},setSelection(c){return Va(c)},focus(){var x;if(l)return false;let c=(x=h!=null?h:ze(e))!=null?x:lt(e);if(c)return Va(c);let m=_e(s)[0];return m?Va({kind:"caret",paraId:m.paraId,offset:0}):false},async insertImage(c,m={}){if(l)return false;let x=typeof c=="string"?c:await xp(c);return ke(v({kind:"insert-image",src:x},m))},search:vh,getSearchState(){return Mo()},findNext:Sh,replaceCurrent:Fh,replaceAll:Hh,clearSearch:Ia,getCommandState(){var m;let c=(m=h!=null?h:ze(e))!=null?m:lt(e);return Rt(c)},getChanges(){return u.slice()},canUndo(){return !l&&!d&&K.length>0},canRedo(){return !l&&!d&&X.length>0},undo:Ir,redo:Nr,canDispatch(c){var x;if(l||d)return false;let m=(x=h!=null?h:ze(e))!=null?x:lt(e);return Wt(s,m,c)},dispatch:ke,subscribe(c,m){if(l)return ()=>{};let x=m;return kt[c].add(x),()=>kt[c].delete(x)}}}function ge(e){return O(v({},e),{format:e.format?fo(e.format):null,content:e.content.map($v)})}function $v(e){return e.kind==="pageBreak"?{kind:"pageBreak"}:e.kind==="text"?v(v(O(v({},e),{format:e.format?fo(e.format):null}),e.marks?{marks:e.marks.map(t=>v({},t))}:{}),e.hyperlink?{hyperlink:v({},e.hyperlink)}:{}):e.kind==="field"?O(v({},e),{format:e.format?fo(e.format):null}):e.kind==="image"?v(v({},e),e.position?{position:fo(e.position)}:{}):v(v(v({},e),e.position?{position:fo(e.position)}:{}),e.paragraphs?{paragraphs:e.paragraphs.map(ge)}:{})}function fo(e){return JSON.parse(JSON.stringify(e))}function zv(e){return !!e&&/^(https?:|mailto:|tel:)/i.test(e.trim())}function lr(e){return "beforeBlocks"in e}function Vv(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 gp(e){var n;let t=ll;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 ll=t+1,ll}function ot(e){var n,r,o,i;let t=dl;for(let a of _e(e))for(let s of a.content)if(s.kind==="text"){for(let u of (n=s.marks)!=null?n:[]){if(u.kind!=="revision")continue;let f=Number(u.revisionId);Number.isInteger(f)&&(t=Math.max(t,f));}let l=s.formatRevision,d=Number(l==null?void 0:l.revisionId);Number.isInteger(d)&&(t=Math.max(t,d));}else if(s.kind==="image"){let l=Number((i=(r=s.revision)==null?void 0:r.revisionId)!=null?i:(o=s.formatRevision)==null?void 0:o.revisionId);Number.isInteger(l)&&(t=Math.max(t,l));}return dl=t+1,String(dl)}function Gv(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 bp(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 wp(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 vp(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 Ai(e,t){return t.every(n=>vp(e,n.paraId)===Te(n))}function Li(e,t){return {from:Math.max(0,Math.min(e,t)),to:Math.max(0,Math.max(e,t))}}function xp(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=Kr(e);if(!t)return "";sl=sl+1>>>0;let n=`${yp}${Date.now().toString(36)}-${sl.toString(36)}`;for(uo.set(n,t);uo.size>8;){let r=uo.keys().next().value;if(!r)break;uo.delete(r);}return n}function jv(e){var t;return e.startsWith(yp)?(t=uo.get(e))!=null?t:"":e}function Uv(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 Kv(e){let t=Su(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,a)=>{r.toBlob(s=>s?i(s):a(new Error("Unable to encode clipboard image")),"image/png");})}finally{n.close();}}function Bi(e){return e.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;")}function _v(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 qv(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 nt(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=ve(e,t.anchor.paraId),r=ve(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 Di(e,t){return `${e}:${t}`}function po(e,t,n={}){var f,p,b;let r=new Map,o=new Map,i=new Map,a=new Map,s=new Map,l=new Map,d=(f=n.minimumRows)!=null?f:100,u=(p=n.minimumColumns)!=null?p:26;for(let w of e.rows)i.set(w.index,w),d=Math.max(d,w.index);for(let w of e.columns){for(let g=w.min;g<=w.max;g++)a.set(g,w);u=Math.max(u,w.max);}for(let w of e.cells){let g=kp(w,t,n.formulaResults,n.date1904);r.set(w.address,g),o.set(Di(w.row,w.column),g),d=Math.max(d,w.row),u=Math.max(u,w.column);}for(let[w,g]of (b=n.formulaResults)!=null?b:[]){if(r.has(w)||g.error)continue;let h=excel.parseCellAddress(w),y={address:w,row:h.row,column:h.column,kind:"formula",value:null},S=kp(y,t,n.formulaResults,n.date1904);r.set(w,S),o.set(Di(h.row,h.column),S),d=Math.max(d,h.row),u=Math.max(u,h.column);}for(let w of e.mergedRanges){let g=excel.parseRangeAddress(w.address),h=g.startRow+g.rowCount-1,y=g.startColumn+g.columnCount-1,S={startRow:g.startRow,startColumn:g.startColumn,endRow:h,endColumn:y},k=excel.formatCellAddress(g.startRow,g.startColumn),I={address:w.address,range:S,masterAddress:k,source:w};s.set(k,I),d=Math.max(d,h),u=Math.max(u,y);for(let A=g.startRow;A<=h;A++)for(let F=g.startColumn;F<=y;F++){let L=excel.formatCellAddress(A,F);L!==k&&l.set(L,k);}}return {sheetId:e.id,sheetName:e.name,source:e,styles:t,cellsByAddress:r,cellsByRowColumn:o,rowMetaByIndex:i,columnMetaByIndex:a,mergeMasterByAddress:s,mergeFollowerByAddress:l,maxRow:d,maxColumn:u}}function qe(e,t,n){return e.cellsByRowColumn.get(Di(t,n))}function kp(e,t,n,r=false){var s,l;let o=n==null?void 0:n.get(e.address),i=o&&!o.error?o.value:void 0,a=Array.isArray(i)?(l=(s=i[0])==null?void 0:s[0])!=null?l:null:i!=null?i:e.value;return {row:e.row,column:e.column,address:e.address,kind:e.kind,value:a,displayText:Zv(e,t,a,o,r),formula:e.formula,styleId:e.styleId,source:e}}function Zv(e,t,n,r,o=false){return r!=null&&r.error?r.displayText:n!==null?Qv(n,Jv(e,t),o):""}function Jv(e,t){var n,r;return (r=t.cellFormats[(n=e.styleId)!=null?n:0])==null?void 0:r.numberFormatCode}function Qv(e,t,n=false){if(e===null)return "";if(typeof e!="number"||!t)return String(e);let r=t.toLowerCase();return r.includes("%")?`${Hi(e*100,Fi(t))}%`:r.includes("$")?`$${Hi(e,Fi(t),true)}`:eS(r)?tS(e,r,n):t.includes(",")?Hi(e,Fi(t),true):t.includes(".")?Hi(e,Fi(t)):String(e)}function Fi(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 Hi(e,t,n=false){return new Intl.NumberFormat("en-US",{minimumFractionDigits:t,maximumFractionDigits:t,useGrouping:n}).format(e)}function eS(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 tS(e,t,n){if(!Number.isFinite(e))return String(e);let r=Math.floor(e),o=e-r,i=Math.round(o*86400)%86400,a=Math.floor(i/3600),s=Math.floor(i%3600/60),l=i%60,d=a%12||12,u=a<12?"AM":"PM",f=F=>String(F).padStart(2,"0");if(t==="h:mm am/pm")return `${d}:${f(s)} ${u}`;if(t==="h:mm:ss am/pm")return `${d}:${f(s)}:${f(l)} ${u}`;if(t==="h:mm")return `${a}:${f(s)}`;if(t==="h:mm:ss")return `${a}:${f(s)}:${f(l)}`;if(t==="mm:ss")return `${f(s)}:${f(l)}`;if(t==="[h]:mm:ss")return `${Math.floor(e*24)}:${f(s)}:${f(l)}`;if(t==="mmss.0")return `${f(s)}${f(l)}.0`;let p=!n&&r===60,b=n?Date.UTC(1904,0,1):Date.UTC(1899,11,30),w=new Date(b+r*864e5),g=p?1900:w.getUTCFullYear(),h=p?2:w.getUTCMonth()+1,y=p?29:w.getUTCDate(),S=f(h),k=f(y),I=f(g%100),A=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][h-1];return t==="mm-dd-yy"?`${S}-${k}-${I}`:t==="d-mmm-yy"?`${y}-${A}-${I}`:t==="d-mmm"?`${y}-${A}`:t==="mmm-yy"?`${A}-${I}`:t==="m/d/yy h:mm"?`${h}/${y}/${I} ${a}:${f(s)}`:`${g}-${S}-${k}`}var rS=22,oS=96,iS=48,aS=24,sS=1.2,mo=7,Cp=5,Oi=class{constructor(t,n={}){D(this,"model",t);D(this,"defaultRowHeight");D(this,"defaultColumnWidth");D(this,"pointsToCssPixels");D(this,"maximumDigitWidth");D(this,"rowHeaderWidth");D(this,"columnHeaderHeight");D(this,"rowCount");D(this,"columnCount");D(this,"rowOffsets");D(this,"columnOffsets");D(this,"rowHeights");D(this,"columnWidths");var r,o,i,a,s,l;this.defaultRowHeight=(r=n.defaultRowHeight)!=null?r:rS,this.defaultColumnWidth=(o=n.defaultColumnWidth)!=null?o:oS,this.pointsToCssPixels=$i(n.pointsToCssPixels,sS),this.maximumDigitWidth=$i(n.maximumDigitWidth,mo),this.rowHeaderWidth=(i=n.rowHeaderWidth)!=null?i:iS,this.columnHeaderHeight=(a=n.columnHeaderHeight)!=null?a:aS,this.rowCount=Math.max((s=n.rowCount)!=null?s:0,t.maxRow),this.columnCount=Math.max((l=n.columnCount)!=null?l:0,t.maxColumn),this.rowHeights=lS(t,this.rowCount,this.defaultRowHeight,this.pointsToCssPixels),this.columnWidths=dS(t,this.columnCount,this.defaultColumnWidth,this.maximumDigitWidth),this.rowOffsets=Ep(this.rowHeights),this.columnOffsets=Ep(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}emuToCssPixels(t){return Number.isFinite(t)?(t!=null?t:0)/12700*this.pointsToCssPixels:0}cssPixelsToEmu(t){return Number.isFinite(t)?Math.round(t/this.pointsToCssPixels*12700):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 a=Math.max(i,this.columnAt(t)),s=Math.max(o,this.rowAt(n)),l=Math.max(a,Math.min(this.columnCount,this.columnAt(t+r.width)+1)),d=Math.max(s,Math.min(this.rowCount,this.rowAt(n+r.height)+1));return {startRow:s,startColumn:a,endRow:d,endColumn:l}}rowAt(t){return Np(Ip(this.rowOffsets,t),this.rowCount)}columnAt(t){return Np(Ip(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 lS(e,t,n,r){let o=[];for(let i=1;i<=t;i++){let a=e.rowMetaByIndex.get(i);o.push(a!=null&&a.hidden?0:(a==null?void 0:a.height)===void 0?n:a.height*r);}return o}function dS(e,t,n,r){let o=[];for(let i=1;i<=t;i++){let a=e.columnMetaByIndex.get(i);o.push(a!=null&&a.hidden?0:(a==null?void 0:a.width)===void 0?n:cS(a.width,r));}return o}function cS(e,t=mo){if(!Number.isFinite(e)||e<=0)return 0;let n=$i(t,mo);return Math.floor((256*e+Math.floor(128/n))/256*n)}function zi(e,t=mo){if(!Number.isFinite(e)||e<=0)return 0;let n=$i(t,mo),r=Math.floor((e-Cp)/n*100+.5)/100;return Math.floor((r*n+Cp)/n*256)/256}function $i(e,t){return Number.isFinite(e)&&(e!=null?e:0)>0?e:t}function Ep(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 Ip(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 Np(e,t){return Math.max(1,Math.min(t,e))}var Vi=class{constructor(t,n){D(this,"layout",t);D(this,"scroll");D(this,"freeze");D(this,"viewportSize");D(this,"viewports");var r,o,i,a,s,l,d,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,(a=(i=n.freeze)==null?void 0:i.frozenColumns)!=null?a:0)},this.scroll=fS(t,this.freeze,n.viewportSize,{x:(l=(s=n.scroll)==null?void 0:s.x)!=null?l:0,y:(u=(d=n.scroll)==null?void 0:d.y)!=null?u:0}),this.viewports=pS(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&&mS(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 Gi(e){var n;let t=(n=e.sheetViews[0])==null?void 0:n.pane;return uS(t)}function uS(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 fS(e,t,n,r){let o=e.getColumnX(t.frozenColumns+1),i=e.getRowY(t.frozenRows+1),a=Math.max(0,n.width-e.rowHeaderWidth-o),s=Math.max(0,n.height-e.columnHeaderHeight-i),l=Math.max(0,e.totalWidth()-o-a),d=Math.max(0,e.totalHeight()-i-s);return {x:Math.max(0,Math.min(l,r.x)),y:Math.max(0,Math.min(d,r.y))}}function pS(e,t,n,r){let o=e.rowHeaderWidth,i=e.columnHeaderHeight,a=e.getColumnX(r.frozenColumns+1),s=e.getRowY(r.frozenRows+1),l=a+n.x,d=s+n.y,u=Math.max(0,t.width-o),f=Math.max(0,t.height-i),p=o+a,b=i+s,w=Math.max(0,t.width-p),g=Math.max(0,t.height-b),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(a,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+a,y:0,width:Math.max(0,t.width-o-a),height:i},originX:l,originY:0,rows:{start:1,end:0},columns:ul(e,l,w,r.frozenColumns+1)}),r.frozenRows>0&&h.push({kind:"rowHeaderFrozen",screenRect:{x:0,y:i,width:o,height:Math.min(s,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+s,width:o,height:Math.max(0,t.height-i-s)},originX:0,originY:d,rows:cl(e,d,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:a,height:s},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:w,height:s},originX:l,originY:0,rows:{start:1,end:r.frozenRows},columns:ul(e,l,w,r.frozenColumns+1)}),r.frozenColumns>0&&h.push({kind:"frozenLeft",screenRect:{x:o,y:b,width:a,height:g},originX:0,originY:d,rows:cl(e,d,g,r.frozenRows+1),columns:{start:1,end:r.frozenColumns}}),h.push({kind:"main",screenRect:{x:p,y:b,width:w,height:g},originX:l,originY:d,rows:cl(e,d,g,r.frozenRows+1),columns:ul(e,l,w,r.frozenColumns+1)}),h.filter(y=>y.screenRect.width>0&&y.screenRect.height>0)}function cl(e,t,n,r){let o=e.getVisibleRange(0,t,{width:1,height:n},r,1);return {start:o.startRow,end:o.endRow}}function ul(e,t,n,r){let o=e.getVisibleRange(t,0,{width:n,height:1},1,r);return {start:o.startColumn,end:o.endColumn}}function mS(e,t){return t.x>=e.x&&t.y>=e.y&&t.x<e.x+e.width&&t.y<e.y+e.height}function ho(e,t,n){var l,d,u,f,p,b,w,g,h,y,S,k,I,A;let r=(l=e.cellFormats[t!=null?t:0])!=null?l:{},o=(u=e.fonts[(d=r.fontId)!=null?d:0])!=null?u:{},i=(f=o.size)!=null?f:11,a=(b=e.fills[(p=r.fillId)!=null?p:0])!=null?b:{},s=(g=e.borders[(w=r.borderId)!=null?w:0])!=null?g:{};return {font:hS(o.bold,o.italic,i,(h=o.name)!=null?h:"Arial"),fontSize:i,underline:o.underline===true,fontColor:(S=(y=o.color)==null?void 0:y.rgb)!=null?S:"#111827",fillColor:(I=(k=a.foregroundColor)==null?void 0:k.rgb)!=null?I:"#FFFFFF",wrapText:((A=r.alignment)==null?void 0:A.wrapText)===true,border:s,horizontalAlign:gS(r,n),verticalAlign:bS(r)}}function Tp(e,t){let n={};for(let s=t.startColumn;s<=t.endColumn;s++)(n.top)!=null||(n.top=ji(e,t.startRow,s,"top")),(n.bottom)!=null||(n.bottom=ji(e,t.endRow,s,"bottom"));for(let s=t.startRow;s<=t.endRow;s++)(n.left)!=null||(n.left=ji(e,s,t.startColumn,"left")),(n.right)!=null||(n.right=ji(e,s,t.endColumn,"right"));return n}function ji(e,t,n,r){var a,s,l,d;let o=qe(e,t,n),i=(s=e.styles.cellFormats[(a=o==null?void 0:o.styleId)!=null?a:0])!=null?s:{};return (d=e.styles.borders[(l=i.borderId)!=null?l:0])==null?void 0:d[r]}function hS(e,t,n,r){let o=[];return t&&o.push("italic"),e&&o.push("600"),o.push(`${n}pt`),o.push(qt(r,{families:[]})),o.join(" ")}function gS(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 bS(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 qi=class{constructor(t){D(this,"options",t);D(this,"baseCtx");D(this,"headerCtx");D(this,"overlayCtx");D(this,"cssWidth",1);D(this,"cssHeight",1);D(this,"scaleX",1);D(this,"scaleY",1);D(this,"headerFiltersEnabled",true);D(this,"headerFilterColumns",null);D(this,"activeHeaderFilterColumns",new Set);this.baseCtx=Ui(t.baseCanvas),this.headerCtx=Ui(t.headerCanvas),this.overlayCtx=Ui(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 a=Ui(i);this.scaleX=i.width/this.cssWidth,this.scaleY=i.height/this.cssHeight,a.setTransform(this.scaleX,0,0,this.scaleY,0,0),a.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(){Ki(this.overlayCtx,this.options.overlayCanvas);}renderSelection(t,n,r,o={}){this.clearOverlay();let i=this.overlayCtx;for(let a of n.viewports){if(!_i(a))continue;let s=Rp(r,{startRow:a.rows.start,endRow:a.rows.end,startColumn:a.columns.start,endColumn:a.columns.end});if(!s)continue;let l=t.getRangeLogicalRect(s),d=fl(l,a);go(i,a.screenRect,()=>{i.fillStyle="rgba(37, 99, 235, 0.08)",i.fillRect(d.x,d.y,d.width,d.height),i.strokeStyle="#2563EB",i.lineWidth=2/this.scaleX,i.setLineDash([]),wo(i,ml(d,1),this.scaleX,this.scaleY);});}o.showFillHandle&&this.drawFillHandle(t,n,r);}fillHandleRect(t,n,r){for(let o of n.viewports){if(!_i(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),a=7;return {x:i.x+i.width-a/2,y:i.y+i.height-a/2,width:a,height:a}}return null}renderCopiedRange(t,n,r){this.renderDashedRange(t,n,r,{stroke:"#1D4ED8"});}renderDashedRange(t,n,r,o){let i=this.overlayCtx;for(let a of n.viewports){if(!_i(a))continue;let s=Rp(r,{startRow:a.rows.start,endRow:a.rows.end,startColumn:a.columns.start,endColumn:a.columns.end});if(!s)continue;let l=t.getRangeLogicalRect(s),d=fl(l,a);go(i,a.screenRect,()=>{i.save(),o.fill&&(i.fillStyle=o.fill,i.fillRect(d.x,d.y,d.width,d.height)),i.strokeStyle=o.stroke,i.lineWidth=2/this.scaleX,i.setLineDash([4,3]),i.lineDashOffset=0,wo(i,ml(d,2),this.scaleX,this.scaleY),i.restore();});}}clearAll(t,n){Ki(this.baseCtx,this.options.baseCanvas),Ki(this.headerCtx,this.options.headerCanvas),Ki(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,wo(i,ml(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)_i(o)&&go(r,o.screenRect,()=>{for(let i=o.rows.start;i<=o.rows.end;i++)for(let a=o.columns.start;a<=o.columns.end;a++){let s=excel.formatCellAddress(i,a);if(!t.model.mergeFollowerByAddress.get(s)&&(this.drawCell(r,t,n,o,i,a,{drawBorder:false,reserveTrailingSpace:this.headerFiltersEnabled&&i===1}),this.headerFiltersEnabled&&i===1&&(this.headerFilterColumns===null||this.headerFilterColumns.has(a)))){let d=t.getCellLogicalRect(i,a),u={x:o.screenRect.x+d.x-o.originX,y:o.screenRect.y+d.y-o.originY,width:d.width,height:d.height};xS(r,u,this.scaleX,this.scaleY,this.activeHeaderFilterColumns.has(a));}}for(let i=o.rows.start;i<=o.rows.end;i++)for(let a=o.columns.start;a<=o.columns.end;a++){let s=excel.formatCellAddress(i,a);t.model.mergeFollowerByAddress.get(s)||this.drawCell(r,t,n,o,i,a,{drawContent:false});}});}drawCell(t,n,r,o,i,a,s={}){let l=qe(n.model,i,a),d=l?n.model.mergeMasterByAddress.get(l.address):void 0,u=d?fl(n.getRangeLogicalRect(d.range),o):r.cellScreenRect(i,a,o),f=ho(n.model.styles,l==null?void 0:l.styleId,l),p=d?Tp(n.model,d.range):f.border;if(s.drawContent!==false&&(t.fillStyle=f.fillColor,t.fillRect(u.x,u.y,u.width,u.height),t.strokeStyle="#E5E7EB",t.lineWidth=1/this.scaleX,wo(t,u,this.scaleX,this.scaleY)),s.drawBorder!==false&&yS(t,u,p,this.scaleX,this.scaleY),s.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 b=6,w=s.reserveTrailingSpace&&u.width>=28?22:0,g={x:u.x,y:u.y,width:Math.max(1,u.width-w),height:u.height},h=f.horizontalAlign==="right"?g.x+g.width-b:f.horizontalAlign==="center"?g.x+g.width/2:g.x+b;go(t,g,()=>{let y=f.wrapText||l.displayText.includes(`
1607
+ `)?SS(t,l.displayText,Math.max(1,g.width-b*2)):[l.displayText],S=f.fontSize*1.2,k=y.length*S,I=vS(u,f,b,k,S);for(let A=0;A<y.length;A++){let F=y[A],L=I+A*S;t.fillText(F,h,L),f.underline&&kS(t,F,h,L,f,this.scaleX,this.scaleY);}}),t.restore();}drawHeaders(t,n){let r=this.headerCtx;for(let o of n.viewports)go(r,o.screenRect,()=>{if(o.kind==="corner")pl(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 a=t.getCellLogicalRect(1,i),s={x:o.screenRect.x+a.x-o.originX,y:o.screenRect.y,width:a.width,height:o.screenRect.height};pl(r,s,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 a=t.getCellLogicalRect(i,1),s={x:o.screenRect.x,y:o.screenRect.y+a.y-o.originY,width:o.screenRect.width,height:a.height};pl(r,s,String(i),this.scaleX,this.scaleY);}});}};function xS(e,t,n,r,o=false){if(t.width<28)return;let i=t.x+t.width-10,a=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,a-3),e.lineTo(i+4,a-3),e.lineTo(i+1,a+1),e.lineTo(i+1,a+4),e.lineTo(i-1,a+3),e.lineTo(i-1,a+1),e.closePath(),e.stroke(),e.restore();}function Rp(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 Ui(e){let t=e.getContext("2d");if(!t)throw new Error("SpreadsheetCanvasRenderer: 2D canvas context is unavailable");return t}function Ki(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 go(e,t,n){e.save(),e.beginPath(),e.rect(t.x,t.y,t.width,t.height),e.clip(),n(),e.restore();}function _i(e){return e.kind==="main"||e.kind==="frozenTop"||e.kind==="frozenLeft"||e.kind==="frozenTopLeft"}function fl(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 pl(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,wo(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 yS(e,t,n,r,o){var i,a,s,l,d,u,f,p;!n.left&&!n.right&&!n.top&&!n.bottom||(e.save(),e.lineWidth=1/r,e.setLineDash([]),n.top&&(e.strokeStyle=(a=(i=n.top.color)==null?void 0:i.rgb)!=null?a:"#111827",bo(e,t.x,t.y,t.x+t.width,t.y,r,o)),n.right&&(e.strokeStyle=(l=(s=n.right.color)==null?void 0:s.rgb)!=null?l:"#111827",bo(e,t.x+t.width,t.y,t.x+t.width,t.y+t.height,r,o)),n.bottom&&(e.strokeStyle=(u=(d=n.bottom.color)==null?void 0:d.rgb)!=null?u:"#111827",bo(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",bo(e,t.x,t.y,t.x,t.y+t.height,r,o)),e.restore());}function vS(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 SS(e,t,n){let r=[];for(let o of t.split(/\r?\n/)){if(o===""){r.push("");continue}let i="";for(let a of o){let s=i+a;i&&e.measureText(s).width>n?(r.push(i),i=a):i=s;}i&&r.push(i);}return r.length>0?r:[""]}function bo(e,t,n,r,o,i,a){e.beginPath(),e.moveTo(kn(t,i),kn(n,a)),e.lineTo(kn(r,i),kn(o,a)),e.stroke();}function kS(e,t,n,r,o,i,a){let s=e.measureText(t),l=s.width,d=o.horizontalAlign==="right"?n-l:o.horizontalAlign==="center"?n-l/2:n,u=Math.max(2,(s.actualBoundingBoxDescent||o.fontSize*.18)+1);e.save(),e.strokeStyle=o.fontColor,e.lineWidth=1/i,bo(e,d,r+u,d+l,r+u,i,a),e.restore();}function ml(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 wo(e,t,n,r){let o=kn(t.x,n),i=kn(t.y,r),a=kn(t.x+t.width,n),s=kn(t.y+t.height,r);e.strokeRect(o,i,Math.max(0,a-o),Math.max(0,s-i));}function kn(e,t){return (Math.round(e*t)+.5)/t}function it(e,t){return {kind:"cell",active:{row:e,column:t},range:{startRow:e,startColumn:t,endRow:e,endColumn:t}}}function Xi(e,t){return {kind:"row",active:{row:e,column:1},range:{startRow:e,startColumn:1,endRow:e,endColumn:t.columnCount}}}function LN(e,t,n){let r=Le({startRow:e,startColumn:1,endRow:t,endColumn:n.columnCount});return {kind:"row",active:{row:r.startRow,column:1},range:r}}function Yi(e,t){return {kind:"column",active:{row:1,column:e},range:{startRow:1,startColumn:e,endRow:t.rowCount,endColumn:e}}}function WN(e,t,n){let r=Le({startRow:1,startColumn:e,endRow:n.rowCount,endColumn:t});return {kind:"column",active:{row:1,column:r.startColumn},range:r}}function Le(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 cr(e,t,n,r){var o,i;return e.kind==="row"?{kind:"row",active:e.active,range:Le({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:Le({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:Le({startRow:e.active.row,startColumn:e.active.column,endRow:t,endColumn:n})}}function BN(e,t,n,r){return it(dr(e.active.row+t,1,r.rowCount),dr(e.active.column+n,1,r.columnCount))}function ct(e,t){var r;if(e.kind!=="cell")return e;let n=(r=NS(e.active.row,e.active.column,t))!=null?r:e.active;return O(v({},e),{active:n,range:ES(e.range,t)})}function ES(e,t){let n=Le(e),r=true;for(;r;){r=false;for(let o of t.mergeMasterByAddress.values()){if(!IS(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 DN(e,t,n,r,o){let i=dr(Mp(e.active.row,t,n),1,r.rowCount),a=dr(e.active.column,1,r.columnCount);return e.kind==="row"?Xi(i,{columnCount:r.columnCount}):ct(it(i,a),o)}function FN(e,t,n,r,o){let i=dr(e.active.row,1,r.rowCount),a=dr(Mp(e.active.column,t,n),1,r.columnCount);return e.kind==="column"?Yi(a,{rowCount:r.rowCount}):ct(it(i,a),o)}function Mp(e,t,n){let r=t+n-1;return e<t?e:e>r?e-n:t}function IS(e,t){return !(e.endRow<t.startRow||e.startRow>t.endRow||e.endColumn<t.startColumn||e.startColumn>t.endColumn)}function NS(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 dr(e,t,n){return Math.max(t,Math.min(n,e))}var ur="application/x-coco-spreadsheet";function xo(e){return JSON.stringify(O(v({},e),{schema:1}))}function Ap(e){var r;let t=e.getData(ur);if(t.trimStart().startsWith("{"))return t;let n=(r=new RegExp(`\\bdata-coco-spreadsheet-payload\\s*=\\s*(["'])(.*?)\\1`,"is").exec(e.getData("text/html")))==null?void 0:r[2];if(!n)return null;if(n.length>33554432*3)throw new Error("\u590D\u5236\u7684\u5355\u5143\u683C\u6570\u636E\u8FC7\u5927\u3002");try{return decodeURIComponent(n)}catch(o){throw new Error("\u590D\u5236\u7684\u5355\u5143\u683C\u6570\u636E\u5DF2\u635F\u574F\uFF0C\u8BF7\u91CD\u65B0\u590D\u5236\u3002")}}function yo(e){var n;let t=Ap(e);if(t){if(t.length>33554432)throw new Error("\u590D\u5236\u7684\u5355\u5143\u683C\u6570\u636E\u8FC7\u5927\u3002");try{let r=JSON.parse(t);return typeof r.id=="string"?r.id:null}catch(r){throw new Error("\u590D\u5236\u7684\u5355\u5143\u683C\u6570\u636E\u5DF2\u635F\u574F\uFF0C\u8BF7\u91CD\u65B0\u590D\u5236\u3002")}}return e.getData(ur)||((n=/\bdata-coco-spreadsheet="([^"]+)"/i.exec(e.getData("text/html")))==null?void 0:n[1])||null}function wl(e){let t=Ap(e);if(!t)return null;if(t.length>33554432)throw new Error("\u590D\u5236\u7684\u5355\u5143\u683C\u6570\u636E\u8FC7\u5927\u3002");try{return RS(JSON.parse(t))}catch(n){throw new Error("\u590D\u5236\u7684\u5355\u5143\u683C\u6570\u636E\u683C\u5F0F\u65E0\u6548\uFF0C\u8BF7\u91CD\u65B0\u590D\u5236\u3002")}}function Ut(e){if(!e||typeof e!="object"||Array.isArray(e))throw new Error("Expected object");if(Object.keys(e).some(t=>t==="__proto__"||t==="constructor"||t==="prototype"))throw new Error("Invalid property");return e}function ln(e,t=32768){if(typeof e!="string"||e.length>t)throw new Error("Invalid string");return e}function Jt(e,t,n=1){if(typeof e!="number"||!Number.isInteger(e)||e<n||e>t)throw new Error("Invalid integer");return e}function TS(e){if(e===null||typeof e=="boolean"||typeof e=="string"||typeof e=="number"&&Number.isFinite(e))return e;throw new Error("Invalid cell value")}function hl(e,t,n,r){if(!Array.isArray(e)||e.length!==t)throw new Error("Invalid rows");return e.map(o=>{if(!Array.isArray(o)||o.length!==n)throw new Error("Invalid columns");return o.map(r)})}function gl(e){let t=ln(Ut(e).rgb,7);if(!/^#[0-9a-f]{6}$/i.test(t))throw new Error("Invalid color");return {rgb:t}}function bl(e,t,n,r){let o=Ut(e),i={};for(let a of t)o[a]!==void 0&&(i[a]=ln(o[a],a==="name"?1024:256));for(let a of n)if(o[a]!==void 0){let s=o[a];if(typeof s!="number"||!Number.isFinite(s)||Math.abs(s)>65535)throw new Error("Invalid style number");i[a]=s;}for(let a of r)if(o[a]!==void 0){if(typeof o[a]!="boolean")throw new Error("Invalid style boolean");i[a]=o[a];}return i}function PS(e){let t=Ut(e),n=bl(t.font,["name","scheme"],["size","family","charset"],["bold","italic","underline"]),r=Ut(t.font);r.color!==void 0&&(n.color=gl(r.color));let o=bl(t.fill,["patternType"],[],[]),i=Ut(t.fill);for(let l of ["foregroundColor","backgroundColor"])i[l]!==void 0&&(o[l]=gl(i[l]));let a=Ut(t.border),s={};for(let l of ["top","bottom","left","right","diagonal"])if(a[l]!==void 0){let d=Ut(a[l]);s[l]=v(v({},d.style!==void 0?{style:ln(d.style,64)}:{}),d.color!==void 0?{color:gl(d.color)}:{});}return v(v(v({font:n,fill:o,border:s},t.alignment!==void 0?{alignment:bl(t.alignment,["horizontal","vertical"],["textRotation","indent"],["wrapText","shrinkToFit"])}:{}),t.numberFormatId!==void 0?{numberFormatId:Jt(t.numberFormatId,65535,0)}:{}),t.numberFormatCode!==void 0?{numberFormatCode:ln(t.numberFormatCode,4096)}:{})}function RS(e){let t=Ut(e);if(t.schema!==1)throw new Error("Unsupported clipboard schema");let n=Ut(t.sourceRange),r={startRow:Jt(n.startRow,1048576),endRow:Jt(n.endRow,1048576),startColumn:Jt(n.startColumn,16384),endColumn:Jt(n.endColumn,16384)},o=r.endRow-r.startRow+1,i=r.endColumn-r.startColumn+1;if(o<1||i<1||o*i>1048576)throw new Error("Invalid range");let a=hl(t.values,o,i,TS),s=hl(t.formulas,o,i,p=>p===null?null:ln(p)),l=hl(t.styleIds,o,i,p=>p==null?void 0:Jt(p,1048576,0));if(!Array.isArray(t.merges)||t.merges.length>o*i)throw new Error("Invalid merges");let d=new Set,u=t.merges.map(p=>{let b=Ut(p),w={startRowOffset:Jt(b.startRowOffset,o-1,0),startColumnOffset:Jt(b.startColumnOffset,i-1,0),rowCount:Jt(b.rowCount,o),columnCount:Jt(b.columnCount,i)};if(w.startRowOffset+w.rowCount>o||w.startColumnOffset+w.columnCount>i)throw new Error("Merge out of range");for(let g=w.startRowOffset;g<w.startRowOffset+w.rowCount;g++)for(let h=w.startColumnOffset;h<w.startColumnOffset+w.columnCount;h++){let y=g*i+h;if(d.has(y))throw new Error("Overlapping merges");d.add(y);}return w}),f={};for(let[p,b]of Object.entries(Ut(t.styles))){if(p!=="default"&&!/^(0|[1-9]\d{0,6})$/.test(p))throw new Error("Invalid style key");f[p]=PS(b);}for(let p of l)for(let b of p)if(!Object.prototype.hasOwnProperty.call(f,b===void 0?"default":String(b)))throw new Error("Missing style definition");return O(v({schema:1,id:ln(t.id,256),sourceSheet:ln(t.sourceSheet,128)},t.sourceWorkbookId!==void 0?{sourceWorkbookId:ln(t.sourceWorkbookId,512)}:{}),{sourceRange:r,text:ln(t.text,33554432),values:a,formulas:s,styleIds:l,styles:f,merges:u})}function Zi(e,t,n={}){var s,l,d;let r=WS(e,t),o=OS(e,t),i={};for(let u of o)for(let f of u){let p=f===void 0?"default":String(f);(i[p])!=null||(i[p]=excel.captureExcelCellStyle(e.styles,f));}return O(v({schema:1,id:(d=(l=(s=globalThis.crypto)==null?void 0:s.randomUUID)==null?void 0:l.call(s))!=null?d:`clipboard-${Date.now()}-${Math.random()}`},n.sourceWorkbookId?{sourceWorkbookId:n.sourceWorkbookId}:{}),{sourceSheet:e.source.name,sourceRange:v({},t),text:r,values:FS(e,t),formulas:Array.from({length:t.endRow-t.startRow+1},(u,f)=>Array.from({length:t.endColumn-t.startColumn+1},(p,b)=>{var h,y;let w=t.startRow+f,g=t.startColumn+b;return e.mergeFollowerByAddress.has(excel.formatCellAddress(w,g))?null:(y=(h=qe(e,w,g))==null?void 0:h.formula)!=null?y:null})),styleIds:o,styles:i,merges:HS(e,t)})}function WS(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(BS(DS(e,r,i)));n.push(o.join(" "));}return n.join(`
1608
+ `)}function Wp(e){if(e==="")return [[null]];let t=[],n=[],r="",o=false,i=false;for(let a=0;a<e.length;a++){let s=e[a];i=false,s==='"'?o&&e[a+1]==='"'?(r+='"',a++):o||r===""?o=!o:r+=s:!o&&(s===" "||s===`
1609
+ `||s==="\r")?(n.push(Lp(r)),r="",s!==" "&&(t.push(n),n=[],i=true,s==="\r"&&e[a+1]===`
1610
+ `&&a++)):r+=s;}if(o)throw new Error("\u7C98\u8D34\u6570\u636E\u5305\u542B\u672A\u95ED\u5408\u7684\u5F15\u53F7\u3002");return i||(n.push(Lp(r)),t.push(n)),t}function yl(e){let t=r=>r.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),n=(r,o)=>{var s,l,d,u,f,p,b;let i=(d=e.styles)==null?void 0:d[String((l=(s=e.styleIds[r])==null?void 0:s[o])!=null?l:"default")];if(!i)return "";let a=[];i.font.name&&a.push(`font-family:'${i.font.name.replace(/['\\]/g,"\\$&")}'`),i.font.size&&a.push(`font-size:${i.font.size}pt`),i.font.bold&&a.push("font-weight:bold"),i.font.italic&&a.push("font-style:italic"),i.font.underline&&a.push("text-decoration:underline"),i.font.color&&a.push(`color:${i.font.color.rgb}`),i.fill.foregroundColor&&a.push(`background-color:${i.fill.foregroundColor.rgb}`),(u=i.alignment)!=null&&u.horizontal&&a.push(`text-align:${i.alignment.horizontal}`),(f=i.alignment)!=null&&f.vertical&&a.push(`vertical-align:${i.alignment.vertical==="center"?"middle":i.alignment.vertical}`);for(let w of ["top","bottom","left","right"]){let g=i.border[w];g!=null&&g.style&&g.style!=="none"&&a.push(`border-${w}:${g.style==="thick"?3:g.style==="medium"?2:1}px ${g.style==="double"?"double":/dash/i.test(g.style)?"dashed":/dot/i.test(g.style)?"dotted":"solid"} ${(b=(p=g.color)==null?void 0:p.rgb)!=null?b:"#000000"}`);}return a.join(";")};return `<table data-coco-spreadsheet="${t(e.id)}" data-coco-spreadsheet-payload="${encodeURIComponent(xo(e))}">${e.values.map((r,o)=>`<tr>${r.map((i,a)=>`<td style="${t(n(o,a))}">${t(String(i!=null?i:""))}</td>`).join("")}</tr>`).join("")}</table>`}function vl(e,t,n,r=false){return e.formulas.map(o=>o.map(i=>i===null||r?i:excel.shiftFormulaReferences(i,t-e.sourceRange.startRow,n-e.sourceRange.startColumn)))}function UN(e,t,n){let r=Math.max(1,n.length),o=Math.max(1,n.reduce((i,a)=>Math.max(i,a.length),0));return excel.formatRangeAddress(e,t,r,o)}function BS(e){return /[\t\r\n"]/.test(e)?`"${e.replace(/"/g,'""')}"`:e}function DS(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 FS(e,t){var r,o;let n=[];for(let i=t.startRow;i<=t.endRow;i++){let a=[];for(let s=t.startColumn;s<=t.endColumn;s++){let l=excel.formatCellAddress(i,s);a.push(e.mergeFollowerByAddress.has(l)?null:(o=(r=qe(e,i,s))==null?void 0:r.value)!=null?o:null);}n.push(a);}return n}function HS(e,t){let n=[];for(let r of e.mergeMasterByAddress.values())$S(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 OS(e,t){var r;let n=[];for(let o=t.startRow;o<=t.endRow;o++){let i=[];for(let a=t.startColumn;a<=t.endColumn;a++)i.push((r=qe(e,o,a))==null?void 0:r.styleId);n.push(i);}return n}function $S(e,t){return t.startRow>=e.startRow&&t.endRow<=e.endRow&&t.startColumn>=e.startColumn&&t.endColumn<=e.endColumn}function Lp(e){if(e==="")return null;let t=Number(e);return Number.isFinite(t)&&e.trim()!==""?t:e.toUpperCase()==="TRUE"?true:e.toUpperCase()==="FALSE"?false:e}function Dp(e,t,n){var s;let r=kl(t),o=kl(n),i=VS(r,o);if(Sl(r,e)||Sl(o,e))throw new Error("Auto fill does not support merged cells");let a=[];for(let l=o.startRow;l<=o.endRow;l++)for(let d=o.startColumn;d<=o.endColumn;d++){if(jS(l,d,r))continue;let u=i==="down"?r.startRow+Bp(l-r.startRow,Fp(r)):l,f=i==="right"?r.startColumn+Bp(d-r.startColumn,Hp(r)):d,p=qe(e,u,f),b=GS(e,r,i,l,d),w=p!=null&&p.formula?excel.shiftFormulaReferences(p.formula,l-u,d-f):void 0;a.push({row:l,column:d,value:w?null:(s=b!=null?b:p==null?void 0:p.source.value)!=null?s:null,formula:w,styleId:p==null?void 0:p.styleId});}return {direction:i,source:r,target:o,cells:a}}function Cl(e,t){return !Sl(kl(t),e)}function VS(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 GS(e,t,n,r,o){let i=n==="down"?Fp(t):Hp(t);if(i<2)return;let a=Array.from({length:i},(d,u)=>{let f=n==="down"?t.startRow+u:r,p=n==="right"?t.startColumn+u:o,b=qe(e,f,p);return b!=null&&b.formula||b==null?void 0:b.source.value});if(!a.every(d=>typeof d=="number"&&Number.isFinite(d)))return;let s=a[1]-a[0];if(!a.every((d,u)=>u===0||d===a[0]+s*u))return;let l=n==="down"?r-t.startRow:o-t.startColumn;return a[0]+s*l}function Sl(e,t){for(let n of t.mergeMasterByAddress.values())if(US(e,n.range))return true;return false}function kl(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 Fp(e){return e.endRow-e.startRow+1}function Hp(e){return e.endColumn-e.startColumn+1}function jS(e,t,n){return e>=n.startRow&&e<=n.endRow&&t>=n.startColumn&&t<=n.endColumn}function US(e,t){return !(e.endRow<t.startRow||e.startRow>t.endRow||e.endColumn<t.startColumn||e.startColumn>t.endColumn)}function Bp(e,t){return (e%t+t)%t}async function eT(e,t,n,r){await e.worksheets.getItem(t).getCell(n).setValue(r);}async function tT(e,t,n,r){await e.worksheets.getItem(t).getCell(n).setFormula(r);}async function nT(e,t,n,r,o){let i=o.length,a=o.reduce((l,d)=>Math.max(l,d.length),0),s=o.map(l=>{let d=l.slice();for(;d.length<a;)d.push(null);return d});await e.worksheets.getItem(t).getRange(excel.formatRangeAddress(n,r,i,a)).setValues(s);}async function rT(e,t,n,r,o,i){await e.worksheets.getItem(t).getRange(excel.formatRangeAddress(n,r,o,i)).clear();}async function oT(e,t,n,r){await e.worksheets.getItem(t).getRange(excel.formatCellAddress(n,1)).setRowHeight(r);}async function iT(e,t,n,r){await e.worksheets.getItem(t).getRange(excel.formatCellAddress(1,n)).setColumnWidth(zi(r));}function Gp(e,t){let n=t.query.trim();if(!n)return [];let r=[],o=[...e.cellsByAddress.values()].sort((i,a)=>i.row-a.row||i.column-a.column);for(let i of o)if(jp(i,t.matchCase===true).includes(El(n,t.matchCase===true)))if(i.formula){let a=n.startsWith("=")?n.slice(1):n;r.push({address:i.address,formula:Vp(i.formula,a,t.replacement,t.matchCase===true)});}else {let a=i.value===null?"":String(i.value);r.push({address:i.address,value:Vp(a,n,t.replacement,t.matchCase===true)});}return r}function sT(e,t){let n=El(t.query,t.matchCase===true);if(!n)return [];let r=[],o=[...e.cellsByAddress.values()].sort((i,a)=>i.row-a.row||i.column-a.column);for(let i of o)jp(i,t.matchCase===true).includes(n)&&r.push({row:i.row,column:i.column,address:i.address,text:i.displayText});return r}function lT(e,t,n="forward"){var r,o,i,a;return e.length===0?null:n==="backward"?(o=(r=[...e].reverse().find(s=>zp(s,t)<0))!=null?r:e[e.length-1])!=null?o:null:(a=(i=e.find(s=>zp(s,t)>0))!=null?i:e[0])!=null?a:null}function dT(e){return {startRow:e.row,startColumn:e.column,endRow:e.row,endColumn:e.column}}function jp(e,t){let n=[e.displayText,KS(e.value),e.formula?`=${e.formula}`:""].filter(Boolean);return El(n.join(`
1611
+ `),t)}function KS(e){return e===null?"":String(e)}function El(e,t){let n=e.trim();return t?n:n.toLocaleLowerCase()}function zp(e,t){return e.row===t.row?e.column-t.column:e.row-t.row}function Vp(e,t,n,r){if(!t)return e;let o=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return e.replace(new RegExp(o,r?"g":"gi"),n)}function Il(e,t,n){var o,i;let r=new Set;for(let a=t.startRow+1;a<=t.endRow;a+=1)r.add((i=(o=qe(e,a,n))==null?void 0:o.displayText)!=null?i:"");return [...r].sort((a,s)=>a.localeCompare(s,void 0,{numeric:true}))}function fT(e,t,n){var o,i,a;let r=new Set;for(let s=t.startRow+1;s<=t.endRow;s+=1)(o=e.rowMetaByIndex.get(s))!=null&&o.hidden||r.add((a=(i=qe(e,s,n))==null?void 0:i.displayText)!=null?a:"");return [...r].sort((s,l)=>s.localeCompare(l,void 0,{numeric:true}))}function Up(e,t,n,r){var a,s;let o=new Set(typeof r=="string"?[r]:r),i=[];for(let l=t.startRow+1;l<=t.endRow;l+=1)o.has((s=(a=qe(e,l,n))==null?void 0:a.displayText)!=null?s:"")||i.push(l);return i}function Kp(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(([s,l])=>{var d,u;return l.has((u=(d=qe(e,i,s))==null?void 0:d.displayText)!=null?u:"")})||o.push(i);return o}function _p(e,t,n,r){let o=Array.from({length:t.endRow-t.startRow},(i,a)=>t.startRow+a+1);return o.sort((i,a)=>{var u,f,p,b;let s=(f=(u=qe(e,i,n))==null?void 0:u.displayText)!=null?f:"",l=(b=(p=qe(e,a,n))==null?void 0:p.displayText)!=null?b:"";if(s===""&&l!=="")return 1;if(s!==""&&l==="")return -1;let d=s.localeCompare(l,void 0,{numeric:true,sensitivity:"base"});return (r==="desc"?-d:d)||i-a}),o}function Nl(e,t){let n=Xp(t.source,t.rowOffset,t.columnOffset),r=vo(t.sourceSheet,t.targetSheet)?ZS(n,t.source):[n];return excel.rewriteFormulaReferences(e,o=>{var w;let i=excel.splitSheetQualifiedAddress(o),a=(w=i.sheetName)!=null?w:t.formulaSheet,s=excel.parseRangeAddress(i.address),l={startRow:s.startRow,startColumn:s.startColumn,endRow:s.startRow+s.rowCount-1,endColumn:s.startColumn+s.columnCount-1},d=l;if(vo(a,t.targetSheet)){for(let g of r)if(l=Yp(l,g),!l)return {ok:false,address:"#REF!"}}let u=vo(a,t.sourceSheet)&&Zp(t.source,l),f=u?t.targetSheet:a;if(u?l=Xp(l,t.rowOffset,t.columnOffset):vo(a,t.sourceSheet)&&(l=Yp(l,t.source)),!u&&vo(t.formulaSheet,t.resultSheet)&&l.startRow===d.startRow&&l.endRow===d.endRow&&l.startColumn===d.startColumn&&l.endColumn===d.endColumn)return {ok:true,address:o};let p=JS(i.address,l);return {ok:true,address:`${i.sheetName||f!==t.resultSheet?`'${f.replace(/'/g,"''")}'!`:""}${p}`}})}function vo(e,t){return e.toLowerCase()===t.toLowerCase()}function Zp(e,t){return e.startRow<=t.startRow&&e.endRow>=t.endRow&&e.startColumn<=t.startColumn&&e.endColumn>=t.endColumn}function Xp(e,t,n){return {startRow:e.startRow+t,endRow:e.endRow+t,startColumn:e.startColumn+n,endColumn:e.endColumn+n}}function ZS(e,t){let n=Math.max(e.startRow,t.startRow),r=Math.min(e.endRow,t.endRow),o=Math.max(e.startColumn,t.startColumn),i=Math.min(e.endColumn,t.endColumn);if(n>r||o>i)return [e];let a=[];return e.startRow<n&&a.push(O(v({},e),{endRow:n-1})),r<e.endRow&&a.push(O(v({},e),{startRow:r+1})),e.startColumn<o&&a.push({startRow:n,endRow:r,startColumn:e.startColumn,endColumn:o-1}),i<e.endColumn&&a.push({startRow:n,endRow:r,startColumn:i+1,endColumn:e.endColumn}),a}function Yp(e,t){if(Zp(t,e))return null;let n=v({},e);return t.startColumn<=e.startColumn&&t.endColumn>=e.endColumn&&(t.startRow<=e.startRow&&t.endRow>=e.startRow&&(n.startRow=t.endRow+1),t.endRow>=e.endRow&&t.startRow<=e.endRow&&(n.endRow=t.startRow-1)),t.startRow<=e.startRow&&t.endRow>=e.endRow&&(t.startColumn<=e.startColumn&&t.endColumn>=e.startColumn&&(n.startColumn=t.endColumn+1),t.endColumn>=e.endColumn&&t.startColumn<=e.endColumn&&(n.endColumn=t.startColumn-1)),n}function JS(e,t){var d;let n=e.split(":").map(u=>/^(\$?)([A-Z]+)(\$?)(\d+)$/i.exec(u)),r=n[0],o=(d=n[1])!=null?d:r,i=Number(r[4])>Number(o[4]),a=excel.columnNameToIndex(r[2])>excel.columnNameToIndex(o[2]),s=(u,f,p)=>`${u[1]}${excel.columnIndexToName(p)}${u[3]}${f}`,l=s(r,i?t.endRow:t.startRow,a?t.endColumn:t.startColumn);return n.length===1?l:`${l}:${s(o,i?t.startRow:t.endRow,a?t.startColumn:t.endColumn)}`}var Ji=class e{constructor(t,n={}){D(this,"state",t);D(this,"activeTransaction",null);D(this,"activeTransactionSource",null);D(this,"transactionNeedsRefresh",false);D(this,"readOnlyValue");this.readOnlyValue=n.readOnly===true;}static async fromZip(t,n={}){let a=n,{readOnly:r}=a,o=Ln(a,["readOnly"]),i=await excel.ExcelWorkbook.fromZip(t,o);return e.fromWorkbook(i,{readOnly:r})}static async fromWorkbook(t,n={}){var s;let r=await t.toModel(),o=(s=r.sheets.find(l=>l.sheetViews.some(d=>d.tabSelected===true)))!=null?s:r.sheets[0];if(!o)throw new Error("SpreadsheetEditorRuntime: workbook has no sheets");let i=new excel.SpreadsheetFormulaEngine(o,{sheets:r.sheets}),a=i.calculate();return new e({workbook:t,model:r,activeSheetName:o.name,formulaResults:a,formulaEngine:i,activeSheet:po(o,r.styles,{formulaResults:a,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(O(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 a;let r=em(this.state.model),o=await excel.ExcelWorkbook.fromModel(r,{mode:"inline"}),i=await e.fromWorkbook(o);await i.setActiveSheet(this.state.activeSheetName);try{let s=await i.runAgentTransaction(t,n),l=em(i.model()),d=excel.diffExcelWorkbookModels(r,l);return {result:s,summary:(a=s==null?void 0:s.summary)!=null?a:null,diff:d,diffSummary:d0(d),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}`);if(!this.readOnlyValue){for(let i of await this.state.workbook.worksheets.items()){let a=await i.name(),s=await i.sheetViews(),l=a===t;await i.setSheetViews(s.length>0?s.map(d=>O(v({},d),{tabSelected:l})):[{workbookViewId:0,tabSelected:l,selections:[]}]);}for(let i of this.state.model.sheets){let a=i.name===t;i.sheetViews=i.sheetViews.length>0?i.sheetViews.map(s=>O(v({},s),{tabSelected:a})):[{workbookViewId:0,tabSelected:a,selections:[]}];}}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=po(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(a=>a.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(a=>a.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(a=>a.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=O(v({},this.state),{model:t,activeSheetName:n.name,formulaResults:o,formulaEngine:r,activeSheet:po(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=Gp(this.state.activeSheet,{query:t,replacement:n,matchCase:r});return o.length===0?0:(await this.runUserMutation({label:`Replace ${t}`},async i=>{var a;for(let s of o)s.formula!==void 0?await i.setCellFormula(this.state.activeSheetName,s.address,s.formula):await i.setCellValue(this.state.activeSheetName,s.address,(a=s.value)!=null?a:null);}),o.length)}async filterRows(t,n,r,o){let i={startRow:t,startColumn:r,endRow:n,endColumn:r},a=o===null?[]:Up(this.state.activeSheet,O(v({},i),{startColumn:1,endColumn:this.state.activeSheet.maxColumn}),r,o);await this.runUserMutation({label:o===null?"Clear filter":"Filter rows"},async s=>{await s.runSnapshot("Filter rows","spreadsheet row filter",async()=>{await this.state.workbook.executeCode(`
1558
1612
  const sheet = workbook.worksheets.getItem(args.sheetName);
1559
1613
  const hidden = new Set(args.hiddenRows);
1560
1614
  for (let index = args.startRow + 1; index <= args.endRow; index += 1) {
@@ -1568,7 +1622,7 @@ coco-word-native-table.coco-word-revision-delete {
1568
1622
  }
1569
1623
  }
1570
1624
  sheet.model.rows.sort((left, right) => left.index - right.index);
1571
- `,{sheetName:this.state.activeSheetName,startRow:t,endRow:n,hiddenRows:a});});});}async filterRowsByColumns(t,n,r){let o={startRow:t,endRow:n,endColumn:this.state.activeSheet.maxColumn},i=Gp(this.state.activeSheet,o,r);await this.runUserMutation({label:"Filter rows"},async a=>{await a.runSnapshot("Filter rows","spreadsheet row filter",async()=>{await this.state.workbook.executeCode(`
1625
+ `,{sheetName:this.state.activeSheetName,startRow:t,endRow:n,hiddenRows:a});});});}async filterRowsByColumns(t,n,r){let o={startRow:t,endRow:n,endColumn:this.state.activeSheet.maxColumn},i=Kp(this.state.activeSheet,o,r);await this.runUserMutation({label:"Filter rows"},async a=>{await a.runSnapshot("Filter rows","spreadsheet row filter",async()=>{await this.state.workbook.executeCode(`
1572
1626
  const sheet = workbook.worksheets.getItem(args.sheetName);
1573
1627
  const hidden = new Set(args.hiddenRows);
1574
1628
  for (let index = args.startRow + 1; index <= args.endRow; index += 1) {
@@ -1582,7 +1636,7 @@ coco-word-native-table.coco-word-revision-delete {
1582
1636
  }
1583
1637
  }
1584
1638
  sheet.model.rows.sort((left, right) => left.index - right.index);
1585
- `,{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},a=jp(this.state.activeSheet,i,r,o),s=new Map(a.map((d,u)=>[d,t+u+1])),l=this.state.activeSheet.source.cells.filter(d=>d.formula).map(d=>{var u;return [d.address,excel.rewriteFormulaForRowSort((u=d.formula)!=null?u:"",s,{sheetName:this.state.activeSheetName})]});await this.runUserMutation({label:o==="asc"?"Sort ascending":"Sort descending"},async d=>{await d.runSnapshot("Sort rows","spreadsheet row sort",async()=>{await this.state.workbook.executeCode(`
1639
+ `,{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},a=_p(this.state.activeSheet,i,r,o),s=new Map(a.map((d,u)=>[d,t+u+1])),l=this.state.activeSheet.source.cells.filter(d=>d.formula).map(d=>{var u;return [d.address,excel.rewriteFormulaForRowSort((u=d.formula)!=null?u:"",s,{sheetName:this.state.activeSheetName})]});await this.runUserMutation({label:o==="asc"?"Sort ascending":"Sort descending"},async d=>{await d.runSnapshot("Sort rows","spreadsheet row sort",async()=>{await this.state.workbook.executeCode(`
1586
1640
  const sheet = workbook.worksheets.getItem(args.sheetName);
1587
1641
  const rowMap = new Map(args.rowMap);
1588
1642
  const formulas = new Map(args.formulas);
@@ -1610,17 +1664,17 @@ coco-word-native-table.coco-word-revision-delete {
1610
1664
  }
1611
1665
  sheet.model.cells.sort((left, right) => left.row - right.row || left.column - right.column);
1612
1666
  sheet.model.rows.sort((left, right) => left.index - right.index);
1613
- `,{sheetName:this.state.activeSheetName,rowMap:[...s.entries()],formulas:l});});});}async setRangeValues(t,n,r){let o=r.length,i=r.reduce((s,l)=>Math.max(s,l.length),0);if(o===0||i===0)return;let a=r.map(s=>{let l=s.slice();for(;l.length<i;)l.push(null);return l});await this.runUserMutation({label:"Set range values"},async s=>{await s.setRangeValues(this.state.activeSheetName,excel.formatRangeAddress(t,n,o,i),a);});}async autoFillRange(t,n){let r=Lp(this.state.activeSheet,t,n);r.cells.length!==0&&await this.runUserMutation({label:"Auto fill"},async o=>{for(let i of r.cells){let a=excel.formatCellAddress(i.row,i.column);i.formula?await o.setCellFormula(this.state.activeSheetName,a,i.formula):await o.setCellValue(this.state.activeSheetName,a,i.value),await o.setRangeStyleId(this.state.activeSheetName,a,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,g;let i=(w=o.mode)!=null?w:"all",a=r.length,s=r.reduce((h,y)=>Math.max(h,y.length),0);if(a===0||s===0)return;let l=r.map(h=>{let y=h.slice();for(;y.length<s;)y.push(null);return y}),d=Math.max(1,a),u=Math.max(1,s),p={startRow:t,startColumn:n,endRow:t+d-1,endColumn:n+u-1},f=[...this.state.activeSheet.mergeMasterByAddress.values()].filter(h=>Pl(p,h.range)).map(h=>h.address);for(let h of f){let y=excel.parseRangeAddress(h);if(y.startRow<t||y.startColumn<n||y.startRow+y.rowCount>t+d||y.startColumn+y.columnCount>n+u)throw new Error("\u7C98\u8D34\u533A\u57DF\u4E0D\u80FD\u53EA\u8986\u76D6\u5408\u5E76\u5355\u5143\u683C\u7684\u4E00\u90E8\u5206\u3002")}let b=(g=o.formulas)!=null?g:l.map(h=>h.map(y=>typeof y=="string"&&y.startsWith("=")?y.slice(1):null));if(i==="all"&&b.some(h=>h.some(y=>y!==null&&y.trim()==="")))throw new Error("\u7C98\u8D34\u6570\u636E\u5305\u542B\u7A7A\u516C\u5F0F\u3002");await this.runUserMutation({label:i0(i)},async h=>{var y,S;if(i!=="formats"){if(i==="all")for(let E of f)await h.unmergeRange(this.state.activeSheetName,E);if(await h.setRangeValues(this.state.activeSheetName,excel.formatRangeAddress(t,n,d,u),l),i==="all")for(let E=0;E<b.length;E++)for(let N=0;N<b[E].length;N++){let A=b[E][N];A!=null&&await h.setCellFormula(this.state.activeSheetName,excel.formatCellAddress(t+E,n+N),A);}}i!=="values"&&await r0(h,this.state.activeSheetName,t,n,u,(y=o.styleIds)!=null?y:[]),i==="all"&&await o0(h,this.state.activeSheetName,t,n,(S=o.merges)!=null?S:[]);});}async pasteClipboard(t,n,r={}){var W,V,ee,pe,oe,we,me;let o=t.values.length,i=t.values.reduce((_,te)=>Math.max(_,te.length),0);if(!o||!i)return n;if(this.assertWritable(),!r.valuesOnly&&t.formulas.some(_=>_.some(te=>te!==null&&te.trim()==="")))throw new Error("\u7C98\u8D34\u6570\u636E\u5305\u542B\u7A7A\u516C\u5F0F\u3002");let a=this.state.activeSheet.mergeMasterByAddress.get(excel.formatCellAddress(n.startRow,n.startColumn));if(!r.cut&&o===1&&i===1&&a&&n.startRow===n.endRow&&n.startColumn===n.endColumn&&(n=v({},a.range)),!r.cut&&o===1&&i===1&&a&&a.range.endRow===n.endRow&&a.range.endColumn===n.endColumn){let _=excel.formatRangeAddress(n.startRow,n.startColumn,n.endRow-n.startRow+1,n.endColumn-n.startColumn+1),te=r.valuesOnly?[]:await this.resolveClipboardStyles(t);return await this.runUserMutation({label:"Paste into merged cell"},async D=>{var $,U;await D.setRangeValues(this.state.activeSheetName,_,Array.from({length:n.endRow-n.startRow+1},()=>Array(n.endColumn-n.startColumn+1).fill(null))),await D.setCellValue(this.state.activeSheetName,excel.formatCellAddress(n.startRow,n.startColumn),t.values[0][0]);let G=($=vl(t,n.startRow,n.startColumn)[0])==null?void 0:$[0];!r.valuesOnly&&G&&await D.setCellFormula(this.state.activeSheetName,excel.formatCellAddress(n.startRow,n.startColumn),G),!r.valuesOnly&&te.length&&await D.setRangeStyleId(this.state.activeSheetName,_,(U=te[0])==null?void 0:U[0]);}),n}let s=n.endRow-n.startRow+1,l=n.endColumn-n.startColumn+1,d=r.cut?o:Math.max(o,s),u=r.cut?i:Math.max(i,l);if(!r.cut&&(d%o||u%i))throw new Error("\u590D\u5236\u533A\u57DF\u4E0E\u7C98\u8D34\u533A\u57DF\u7684\u5927\u5C0F\u4E0D\u5339\u914D\u3002");let p=H(v({},n),{endRow:n.startRow+d-1,endColumn:n.startColumn+u-1}),f=Array.from({length:d},(_,te)=>Array.from({length:u},(D,G)=>{var $,U;return (U=($=t.values[te%o])==null?void 0:$[G%i])!=null?U:null})),b=t.styleIds.length?Array.from({length:d},(_,te)=>Array.from({length:u},(D,G)=>{var $;return ($=t.styleIds[te%o])==null?void 0:$[G%i]})):[],w=Array.from({length:d},()=>Array(u).fill(null)),g=[];for(let _=0;_<d;_+=o)for(let te=0;te<u;te+=i){let D=vl(t,n.startRow+_,n.startColumn+te,r.cut);for(let G=0;G<o;G++)for(let $=0;$<i;$++)w[_+G][te+$]=(V=(W=D[G])==null?void 0:W[$])!=null?V:null;g.push(...t.merges.map(G=>H(v({},G),{startRowOffset:G.startRowOffset+_,startColumnOffset:G.startColumnOffset+te})));}if(!r.cut){excel.formatRangeAddress(p.startRow,p.startColumn,d,u);for(let _ of this.state.activeSheet.mergeMasterByAddress.values())if(Pl(p,_.range)&&(_.range.startRow<p.startRow||_.range.startColumn<p.startColumn||_.range.endRow>p.endRow||_.range.endColumn>p.endColumn))throw new Error("\u7C98\u8D34\u533A\u57DF\u4E0D\u80FD\u53EA\u8986\u76D6\u5408\u5E76\u5355\u5143\u683C\u7684\u4E00\u90E8\u5206\u3002");if(!r.valuesOnly&&t.styleIds.length){let _=await this.resolveClipboardStyles(t);b=Array.from({length:d},(te,D)=>Array.from({length:u},(G,$)=>{var U;return (U=_[D%o])==null?void 0:U[$%i]}));}return await this.pasteRange(n.startRow,n.startColumn,f,{mode:r.valuesOnly?"values":"all",formulas:w,styleIds:b,merges:g}),p}let h=this.state.model.sheets.find(_=>_.name===t.sourceSheet);if(!h)throw new Error("\u526A\u5207\u6765\u6E90\u5DE5\u4F5C\u8868\u5DF2\u4E0D\u5B58\u5728\uFF0C\u8BF7\u91CD\u65B0\u590D\u5236\u3002");let y=t.sourceRange,S=this.state.activeSheetName,E=(_,te,D)=>_>=D.startRow&&_<=D.endRow&&te>=D.startColumn&&te<=D.endColumn;excel.formatRangeAddress(p.startRow,p.startColumn,d,u);for(let _ of this.state.activeSheet.mergeMasterByAddress.values())if(!(t.sourceSheet===S&&E(_.range.startRow,_.range.startColumn,y)&&E(_.range.endRow,_.range.endColumn,y))&&Pl(p,_.range)&&(!E(_.range.startRow,_.range.startColumn,p)||!E(_.range.endRow,_.range.endColumn,p)))throw new Error("\u7C98\u8D34\u533A\u57DF\u4E0D\u80FD\u53EA\u8986\u76D6\u5408\u5E76\u5355\u5143\u683C\u7684\u4E00\u90E8\u5206\u3002");let N=new Map(h.cells.map(_=>[_.address,_]));for(let _=0;_<o;_++)for(let te=0;te<i;te++){let D=N.get(excel.formatCellAddress(y.startRow+_,y.startColumn+te));if((D==null?void 0:D.styleId)!==((ee=t.styleIds[_])==null?void 0:ee[te]))throw new Error("\u526A\u5207\u6765\u6E90\u683C\u5F0F\u5DF2\u53D8\u5316\uFF0C\u8BF7\u91CD\u65B0\u526A\u5207\u3002");if(!t.merges.some(G=>_>=G.startRowOffset&&_<G.startRowOffset+G.rowCount&&te>=G.startColumnOffset&&te<G.startColumnOffset+G.columnCount&&(_!==G.startRowOffset||te!==G.startColumnOffset))&&(((pe=D==null?void 0:D.formula)!=null?pe:null)!==((we=(oe=t.formulas[_])==null?void 0:oe[te])!=null?we:null)||!(D!=null&&D.formula)&&((me=D==null?void 0:D.value)!=null?me:null)!==t.values[_][te]))throw new Error("\u526A\u5207\u6765\u6E90\u5185\u5BB9\u5DF2\u53D8\u5316\uFF0C\u8BF7\u91CD\u65B0\u526A\u5207\u3002")}if(t.sourceSheet===S&&y.startRow===n.startRow&&y.startColumn===n.startColumn)return p;let A=[];for(let _ of this.state.model.sheets)for(let te of _.cells){if(!te.formula)continue;let D=_.name===t.sourceSheet&&E(te.row,te.column,y);if(!D&&_.name===S&&E(te.row,te.column,p))continue;let G=D?S:_.name,$=Nl(te.formula,{sourceSheet:t.sourceSheet,targetSheet:S,source:y,formulaSheet:_.name,resultSheet:G,rowOffset:n.startRow-y.startRow,columnOffset:n.startColumn-y.startColumn});(D||$!==te.formula)&&A.push({sheet:G,address:D?excel.formatCellAddress(n.startRow+te.row-y.startRow,n.startColumn+te.column-y.startColumn):te.address,formula:$});}let O=this.state.model.definedNames.flatMap((_,te)=>{var $,U,X;let D=(X=(U=this.state.model.sheets[($=_.localSheetId)!=null?$:0])==null?void 0:U.name)!=null?X:t.sourceSheet,G=Nl(_.text,{sourceSheet:t.sourceSheet,targetSheet:S,source:y,formulaSheet:D,resultSheet:D,rowOffset:n.startRow-y.startRow,columnOffset:n.startColumn-y.startColumn});return G===_.text?[]:[{index:te,text:G}]});return await this.runUserMutation({label:"Move cells"},async _=>{for(let te of t.merges)await _.unmergeRange(t.sourceSheet,excel.formatRangeAddress(y.startRow+te.startRowOffset,y.startColumn+te.startColumnOffset,te.rowCount,te.columnCount));await _.clearRange(t.sourceSheet,excel.formatRangeAddress(y.startRow,y.startColumn,o,i)),await this.refresh(),await this.pasteRange(n.startRow,n.startColumn,f,{formulas:w,styleIds:b,merges:g});for(let te of A)await _.setCellFormula(te.sheet,te.address,te.formula);O.length&&await _.runSnapshot("Move named references","Cut updates defined-name references",async()=>{await this.state.workbook.executeCode(`
1667
+ `,{sheetName:this.state.activeSheetName,rowMap:[...s.entries()],formulas:l});});});}async setRangeValues(t,n,r){let o=r.length,i=r.reduce((s,l)=>Math.max(s,l.length),0);if(o===0||i===0)return;let a=r.map(s=>{let l=s.slice();for(;l.length<i;)l.push(null);return l});await this.runUserMutation({label:"Set range values"},async s=>{await s.setRangeValues(this.state.activeSheetName,excel.formatRangeAddress(t,n,o,i),a);});}async autoFillRange(t,n){let r=Dp(this.state.activeSheet,t,n);r.cells.length!==0&&await this.runUserMutation({label:"Auto fill"},async o=>{for(let i of r.cells){let a=excel.formatCellAddress(i.row,i.column);i.formula?await o.setCellFormula(this.state.activeSheetName,a,i.formula):await o.setCellValue(this.state.activeSheetName,a,i.value),await o.setRangeStyleId(this.state.activeSheetName,a,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,g;let i=(w=o.mode)!=null?w:"all",a=r.length,s=r.reduce((h,y)=>Math.max(h,y.length),0);if(a===0||s===0)return;let l=r.map(h=>{let y=h.slice();for(;y.length<s;)y.push(null);return y}),d=Math.max(1,a),u=Math.max(1,s),f={startRow:t,startColumn:n,endRow:t+d-1,endColumn:n+u-1},p=[...this.state.activeSheet.mergeMasterByAddress.values()].filter(h=>Pl(f,h.range)).map(h=>h.address);for(let h of p){let y=excel.parseRangeAddress(h);if(y.startRow<t||y.startColumn<n||y.startRow+y.rowCount>t+d||y.startColumn+y.columnCount>n+u)throw new Error("\u7C98\u8D34\u533A\u57DF\u4E0D\u80FD\u53EA\u8986\u76D6\u5408\u5E76\u5355\u5143\u683C\u7684\u4E00\u90E8\u5206\u3002")}let b=(g=o.formulas)!=null?g:l.map(h=>h.map(y=>typeof y=="string"&&y.startsWith("=")?y.slice(1):null));if(i==="all"&&b.some(h=>h.some(y=>y!==null&&y.trim()==="")))throw new Error("\u7C98\u8D34\u6570\u636E\u5305\u542B\u7A7A\u516C\u5F0F\u3002");await this.runUserMutation({label:l0(i)},async h=>{var y,S;if(i!=="formats"){if(i==="all")for(let k of p)await h.unmergeRange(this.state.activeSheetName,k);if(await h.setRangeValues(this.state.activeSheetName,excel.formatRangeAddress(t,n,d,u),l),i==="all")for(let k=0;k<b.length;k++)for(let I=0;I<b[k].length;I++){let A=b[k][I];A!=null&&await h.setCellFormula(this.state.activeSheetName,excel.formatCellAddress(t+k,n+I),A);}}i!=="values"&&await a0(h,this.state.activeSheetName,t,n,u,(y=o.styleIds)!=null?y:[]),i==="all"&&await s0(h,this.state.activeSheetName,t,n,(S=o.merges)!=null?S:[]);});}async pasteClipboard(t,n,r={}){var L,V,ee,fe,ae,oe,ie;let o=t.values.length,i=t.values.reduce((U,J)=>Math.max(U,J.length),0);if(!o||!i)return n;if(this.assertWritable(),!r.valuesOnly&&t.formulas.some(U=>U.some(J=>J!==null&&J.trim()==="")))throw new Error("\u7C98\u8D34\u6570\u636E\u5305\u542B\u7A7A\u516C\u5F0F\u3002");let a=this.state.activeSheet.mergeMasterByAddress.get(excel.formatCellAddress(n.startRow,n.startColumn));if(!r.cut&&o===1&&i===1&&a&&n.startRow===n.endRow&&n.startColumn===n.endColumn&&(n=v({},a.range)),!r.cut&&o===1&&i===1&&a&&a.range.endRow===n.endRow&&a.range.endColumn===n.endColumn){let U=excel.formatRangeAddress(n.startRow,n.startColumn,n.endRow-n.startRow+1,n.endColumn-n.startColumn+1),J=r.valuesOnly?[]:await this.resolveClipboardStyles(t);return await this.runUserMutation({label:"Paste into merged cell"},async B=>{var $,K;await B.setRangeValues(this.state.activeSheetName,U,Array.from({length:n.endRow-n.startRow+1},()=>Array(n.endColumn-n.startColumn+1).fill(null))),await B.setCellValue(this.state.activeSheetName,excel.formatCellAddress(n.startRow,n.startColumn),t.values[0][0]);let G=($=vl(t,n.startRow,n.startColumn)[0])==null?void 0:$[0];!r.valuesOnly&&G&&await B.setCellFormula(this.state.activeSheetName,excel.formatCellAddress(n.startRow,n.startColumn),G),!r.valuesOnly&&J.length&&await B.setRangeStyleId(this.state.activeSheetName,U,(K=J[0])==null?void 0:K[0]);}),n}let s=n.endRow-n.startRow+1,l=n.endColumn-n.startColumn+1,d=r.cut?o:Math.max(o,s),u=r.cut?i:Math.max(i,l);if(!r.cut&&(d%o||u%i))throw new Error("\u590D\u5236\u533A\u57DF\u4E0E\u7C98\u8D34\u533A\u57DF\u7684\u5927\u5C0F\u4E0D\u5339\u914D\u3002");let f=O(v({},n),{endRow:n.startRow+d-1,endColumn:n.startColumn+u-1}),p=Array.from({length:d},(U,J)=>Array.from({length:u},(B,G)=>{var $,K;return (K=($=t.values[J%o])==null?void 0:$[G%i])!=null?K:null})),b=t.styleIds.length?Array.from({length:d},(U,J)=>Array.from({length:u},(B,G)=>{var $;return ($=t.styleIds[J%o])==null?void 0:$[G%i]})):[],w=Array.from({length:d},()=>Array(u).fill(null)),g=[];for(let U=0;U<d;U+=o)for(let J=0;J<u;J+=i){let B=vl(t,n.startRow+U,n.startColumn+J,r.cut);for(let G=0;G<o;G++)for(let $=0;$<i;$++)w[U+G][J+$]=(V=(L=B[G])==null?void 0:L[$])!=null?V:null;g.push(...t.merges.map(G=>O(v({},G),{startRowOffset:G.startRowOffset+U,startColumnOffset:G.startColumnOffset+J})));}if(!r.cut){excel.formatRangeAddress(f.startRow,f.startColumn,d,u);for(let U of this.state.activeSheet.mergeMasterByAddress.values())if(Pl(f,U.range)&&(U.range.startRow<f.startRow||U.range.startColumn<f.startColumn||U.range.endRow>f.endRow||U.range.endColumn>f.endColumn))throw new Error("\u7C98\u8D34\u533A\u57DF\u4E0D\u80FD\u53EA\u8986\u76D6\u5408\u5E76\u5355\u5143\u683C\u7684\u4E00\u90E8\u5206\u3002");if(!r.valuesOnly&&t.styleIds.length){let U=await this.resolveClipboardStyles(t);b=Array.from({length:d},(J,B)=>Array.from({length:u},(G,$)=>{var K;return (K=U[B%o])==null?void 0:K[$%i]}));}return await this.pasteRange(n.startRow,n.startColumn,p,{mode:r.valuesOnly?"values":"all",formulas:w,styleIds:b,merges:g}),f}let h=this.state.model.sheets.find(U=>U.name===t.sourceSheet);if(!h)throw new Error("\u526A\u5207\u6765\u6E90\u5DE5\u4F5C\u8868\u5DF2\u4E0D\u5B58\u5728\uFF0C\u8BF7\u91CD\u65B0\u590D\u5236\u3002");let y=t.sourceRange,S=this.state.activeSheetName,k=(U,J,B)=>U>=B.startRow&&U<=B.endRow&&J>=B.startColumn&&J<=B.endColumn;excel.formatRangeAddress(f.startRow,f.startColumn,d,u);for(let U of this.state.activeSheet.mergeMasterByAddress.values())if(!(t.sourceSheet===S&&k(U.range.startRow,U.range.startColumn,y)&&k(U.range.endRow,U.range.endColumn,y))&&Pl(f,U.range)&&(!k(U.range.startRow,U.range.startColumn,f)||!k(U.range.endRow,U.range.endColumn,f)))throw new Error("\u7C98\u8D34\u533A\u57DF\u4E0D\u80FD\u53EA\u8986\u76D6\u5408\u5E76\u5355\u5143\u683C\u7684\u4E00\u90E8\u5206\u3002");let I=new Map(h.cells.map(U=>[U.address,U]));for(let U=0;U<o;U++)for(let J=0;J<i;J++){let B=I.get(excel.formatCellAddress(y.startRow+U,y.startColumn+J));if((B==null?void 0:B.styleId)!==((ee=t.styleIds[U])==null?void 0:ee[J]))throw new Error("\u526A\u5207\u6765\u6E90\u683C\u5F0F\u5DF2\u53D8\u5316\uFF0C\u8BF7\u91CD\u65B0\u526A\u5207\u3002");if(!t.merges.some(G=>U>=G.startRowOffset&&U<G.startRowOffset+G.rowCount&&J>=G.startColumnOffset&&J<G.startColumnOffset+G.columnCount&&(U!==G.startRowOffset||J!==G.startColumnOffset))&&(((fe=B==null?void 0:B.formula)!=null?fe:null)!==((oe=(ae=t.formulas[U])==null?void 0:ae[J])!=null?oe:null)||!(B!=null&&B.formula)&&((ie=B==null?void 0:B.value)!=null?ie:null)!==t.values[U][J]))throw new Error("\u526A\u5207\u6765\u6E90\u5185\u5BB9\u5DF2\u53D8\u5316\uFF0C\u8BF7\u91CD\u65B0\u526A\u5207\u3002")}if(t.sourceSheet===S&&y.startRow===n.startRow&&y.startColumn===n.startColumn)return f;let A=[];for(let U of this.state.model.sheets)for(let J of U.cells){if(!J.formula)continue;let B=U.name===t.sourceSheet&&k(J.row,J.column,y);if(!B&&U.name===S&&k(J.row,J.column,f))continue;let G=B?S:U.name,$=Nl(J.formula,{sourceSheet:t.sourceSheet,targetSheet:S,source:y,formulaSheet:U.name,resultSheet:G,rowOffset:n.startRow-y.startRow,columnOffset:n.startColumn-y.startColumn});(B||$!==J.formula)&&A.push({sheet:G,address:B?excel.formatCellAddress(n.startRow+J.row-y.startRow,n.startColumn+J.column-y.startColumn):J.address,formula:$});}let F=this.state.model.definedNames.flatMap((U,J)=>{var $,K,X;let B=(X=(K=this.state.model.sheets[($=U.localSheetId)!=null?$:0])==null?void 0:K.name)!=null?X:t.sourceSheet,G=Nl(U.text,{sourceSheet:t.sourceSheet,targetSheet:S,source:y,formulaSheet:B,resultSheet:B,rowOffset:n.startRow-y.startRow,columnOffset:n.startColumn-y.startColumn});return G===U.text?[]:[{index:J,text:G}]});return await this.runUserMutation({label:"Move cells"},async U=>{for(let J of t.merges)await U.unmergeRange(t.sourceSheet,excel.formatRangeAddress(y.startRow+J.startRowOffset,y.startColumn+J.startColumnOffset,J.rowCount,J.columnCount));await U.clearRange(t.sourceSheet,excel.formatRangeAddress(y.startRow,y.startColumn,o,i)),await this.refresh(),await this.pasteRange(n.startRow,n.startColumn,p,{formulas:w,styleIds:b,merges:g});for(let J of A)await U.setCellFormula(J.sheet,J.address,J.formula);F.length&&await U.runSnapshot("Move named references","Cut updates defined-name references",async()=>{await this.state.workbook.executeCode(`
1614
1668
  const names = workbook.names.items();
1615
1669
  for (const update of args.updates) names[update.index].setText(update.text);
1616
- `,{updates:O});});}),p}async resolveClipboardStyles(t){if(!t.styles)return t.styleIds;let n=this.state.model.styles,r=[...new Set(t.styleIds.flat().map(s=>s===void 0?"default":String(s)))],o=r.map(s=>{let l=t.styles[s];if(!l)throw new Error("\u526A\u8D34\u677F\u7F3A\u5C11\u5355\u5143\u683C\u683C\u5F0F\u5B9A\u4E49\uFF0C\u8BF7\u91CD\u65B0\u590D\u5236\u3002");return l}),i=await this.state.workbook.importCellStyles(o),a=new Map(r.map((s,l)=>[s,i[l]]));return t.styleIds.map(s=>s.map(l=>{let d=l===void 0?"default":String(l);return (l===void 0||n.cellFormats[l])&&excel.equalExcelCellStyles(t.styles[d],excel.captureExcelCellStyle(n,l))?l:a.get(d)}))}async clearRange(t,n,r,o){await this.runUserMutation({label:"Clear range"},async i=>{await i.setRangeValues(this.state.activeSheetName,excel.formatRangeAddress(t,n,r,o),Array.from({length:r},()=>Array(o).fill(null)));});}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,r){await this.runUserMutation({label:"Set column width"},async o=>{await o.setColumnWidth(this.state.activeSheetName,t,Hi(n,r));});}async setFreezePanes(t,n){let r=Yp(t),o=Yp(n),i=n0(this.state.activeSheet.source.sheetViews,r,o);await this.runUserMutation({label:r||o?"Freeze panes":"Unfreeze panes"},async a=>{await a.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 a=>{await a.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 a=>{await a.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 a=>{await a.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 a=>{await a.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 a=>{await a.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 a=>{await a.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 a=>{await a.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 a=>{await a.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),a=await this.cellStyleId(excel.formatCellAddress(t,n));await this.runUserMutation({label:"Merge range"},async s=>{await s.setRangeStyleId(this.state.activeSheetName,i,a),await s.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(a=>a.address===r),i=o?excel.formatCellAddress(o.range.startRow,o.range.startColumn):s0(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 s=>{await s.setRangeBorder(this.state.activeSheetName,excel.formatRangeAddress(t,n,r,o),{});});return}let a=t0();if(i==="all"){await this.runUserMutation({label:"Set all borders"},async s=>{await s.setRangeBorder(this.state.activeSheetName,excel.formatRangeAddress(t,n,r,o),{left:a,right:a,top:a,bottom:a});});return}await this.runUserMutation({label:`Set ${i} borders`},async s=>{await s.setRangeBorder(this.state.activeSheetName,excel.formatRangeAddress(t,n,r,o),{});for(let l=0;l<r;l++)for(let d=0;d<o;d++){let u={};i==="outer"?(l===0&&(u.top=a),l===r-1&&(u.bottom=a),d===0&&(u.left=a),d===o-1&&(u.right=a)):(d<o-1&&(u.right=a),l<r-1&&(u.bottom=a)),Object.keys(u).length!==0&&await s.setRangeBorder(this.state.activeSheetName,excel.formatCellAddress(t+l,n+d),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(f=>f.name===this.state.activeSheetName),i=o==null?void 0:o.charts[t];if(!o||!i)return;let a=o.drawings.findIndex(f=>f.path===i.drawingPath),s=a>=0?o.drawings[a]:o.drawings[0];if(!s)return;let l=s.anchors.findIndex(f=>{var b;return ((b=f.object)==null?void 0:b.kind)==="chart"&&(!i.relationshipId||f.object.relationshipId===i.relationshipId)});if(l<0)return;let u=(await this.state.workbook.worksheets.getItem(this.state.activeSheetName).drawings.items())[a>=0?a:0],p=u==null?void 0:u.anchors.getItem(l);p&&(p.from.setRow(n.from.row),p.from.setColumn(n.from.column),p.from.setRowOffset(n.from.rowOffset),p.from.setColumnOffset(n.from.columnOffset),n.to&&(p.to.setRow(n.to.row),p.to.setColumn(n.to.column),p.to.setRowOffset(n.to.rowOffset),p.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=fo(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(H(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 s=>{this.activeTransaction=s,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 mn("spreadsheet")}cellEditHistoryGroup(t,n,r){var i;let o={label:t};return r.mergeUndo?H(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 t0(){return {style:"thin",color:{rgb:"#111827"}}}function Yp(e){return Number.isFinite(e)?Math.max(0,Math.floor(e)):0}function n0(e,t,n){var i;if(!t&&!n)return e.map((a,s)=>H(v({},a),{pane:s===0?void 0:a.pane?v({},a.pane):void 0,selections:a.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 [H(v({},r),{pane:o,selections:r.selections.map(a=>v({},a))}),...e.slice(1).map(a=>H(v({},a),{pane:a.pane?v({},a.pane):void 0,selections:a.selections.map(s=>v({},s))}))]}async function r0(e,t,n,r,o,i){for(let a=0;a<i.length;a++){let s=i[a];if(s)for(let l=0;l<o;l++)await e.setRangeStyleId(t,excel.formatCellAddress(n+a,r+l),s[l]);}}async function o0(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 i0(e){switch(e){case "values":return "Paste values";case "formats":return "Paste formats";default:return "Paste range"}}function Zp(e){return JSON.parse(JSON.stringify(e))}function a0(e){var r,o,i,a,s,l;let t={total:0,added:0,modified:0,deleted:0},n=[];for(let d of e.sheets)for(let u of d.cells)t.total+=1,t[u.kind]+=1,!(n.length>=20)&&n.push({sheetName:(o=(r=d.afterName)!=null?r:d.beforeName)!=null?o:d.sheetId,address:u.address,kind:u.kind,before:(a=(i=u.before)==null?void 0:i.value)!=null?a:null,after:(l=(s=u.after)==null?void 0:s.value)!=null?l:null});return {changed:e.changed,changedSheets:e.sheets.length,sheetNames:e.sheets.map(d=>{var u,p;return (p=(u=d.afterName)!=null?u:d.beforeName)!=null?p:d.sheetId}),cellChanges:t,structuralChanged:e.sheets.some(d=>d.structuralChanged),objectChanged:e.sheets.some(d=>d.objectChanged),sampleCells:n}}function Pl(e,t){return !(e.endRow<t.startRow||e.startRow>t.endRow||e.endColumn<t.startColumn||e.startColumn>t.endColumn)}function s0(e){let t=excel.parseRangeAddress(e);return excel.formatCellAddress(t.startRow,t.startColumn)}async function IT(e,t,n={}){return {action:t,context:n,transaction:await e.previewAgentTransaction(Qp(t),r=>t.run(r,n))}}async function NT(e,t,n={}){return {action:t,context:n,transaction:await e.runAgentTransaction(Qp(t),r=>t.run(r,n))}}function Qp(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 Yi=class{constructor(t){B(this,"options",t);B(this,"active",false);B(this,"pendingCommit",Promise.resolve());B(this,"handleBlur",()=>{this.commit().catch(t=>{var n,r;return (r=(n=this.options).onError)==null?void 0:r.call(n,t)});});B(this,"handleKeyDown",t=>{t.isComposing||t.keyCode===229||(t.key==="Escape"?(t.preventDefault(),t.stopPropagation(),this.cancel()):(t.key==="Enter"||t.key==="Tab")&&!t.altKey&&!t.ctrlKey&&!t.metaKey&&(t.preventDefault(),t.stopPropagation(),this.commit({key:t.key,reverse:t.shiftKey}).catch(n=>{var r,o;return (o=(r=this.options).onError)==null?void 0:o.call(r,n)})));});t.textarea.addEventListener("keydown",this.handleKeyDown),t.textarea.addEventListener("blur",this.handleBlur);}open(t,n){this.active=true;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();}commit(t){if(!this.active)return this.pendingCommit;this.active=false;let n=this.options.textarea.value;try{this.pendingCommit=Promise.resolve(this.options.onCommit(n)),t&&(this.pendingCommit=this.pendingCommit.then(()=>{var r,o;return (o=(r=this.options).onNavigate)==null?void 0:o.call(r,t.key,t.reverse)}));}catch(r){this.pendingCommit=Promise.reject(r);}return this.close(),this.pendingCommit}cancel(){var t,n;this.active=false,this.close(),(n=(t=this.options).onCancel)==null||n.call(t);}close(){this.options.textarea.style.display="none";}destroy(){this.active=false,this.options.textarea.removeEventListener("keydown",this.handleKeyDown),this.options.textarea.removeEventListener("blur",this.handleBlur),this.close();}};function tm(e,t,n){return {x:Math.max(0,e.x+t),y:Math.max(0,e.y+n)}}function nm(e,t,n,r,o=12){let i=e.getColumnX(n.frozenColumns+1),a=e.getRowY(n.frozenRows+1),s=Math.max(0,t.width-e.rowHeaderWidth-i-o),l=Math.max(0,t.height-e.columnHeaderHeight-a-o),d=s,u=l,p=Math.max(0,e.totalWidth()-i),f=Math.max(0,e.totalHeight()-a);return {horizontal:em(p,d,s,r.x),vertical:em(f,u,l,r.y)}}function Zi(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 em(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)),a=Math.max(0,n-i),s=o<=0?0:Math.max(0,Math.min(o,r))/o*a;return {trackLength:n,thumbStart:s,thumbLength:i,maxScroll:o}}var AT=24,LT=12,WT=4;function Rl(e,t,n){for(let r of t){if(r.kind==="columnHeaderFrozen"||r.kind==="columnHeaderScrollable"){let o=l0(e,r,n);if(o)return o}if(r.kind==="rowHeaderFrozen"||r.kind==="rowHeaderScrollable"){let o=d0(e,r,n);if(o)return o}}return null}function rm(e,t){return H(v({},e),{startClientX:t.clientX,startClientY:t.clientY,currentSize:e.startSize,currentGuidePosition:e.guidePosition})}function Ml(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 H(v({},e),{currentSize:r,currentGuidePosition:e.guidePosition+r-e.startSize})}function l0(e,t,n){if(!om(t.screenRect,n,4))return null;for(let r=t.columns.start;r<=t.columns.end;r++){let o=e.getCellLogicalRect(1,r),a=t.screenRect.x+o.x-t.originX+o.width;if(Math.abs(n.x-a)<=4)return {kind:"column",index:r,startSize:e.getColumnWidth(r),guidePosition:a,minSize:24}}return null}function d0(e,t,n){if(!om(t.screenRect,n,4))return null;for(let r=t.rows.start;r<=t.rows.end;r++){let o=e.getCellLogicalRect(r,1),a=t.screenRect.y+o.y-t.originY+o.height;if(Math.abs(n.y-a)<=4)return {kind:"row",index:r,startSize:e.getRowHeight(r),guidePosition:a,minSize:12}}return null}function om(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 OT(e,t){var o,i,a,s,l,d;let n=c0(),r=Ae(t.range);for(let u=r.startRow;u<=r.endRow;u++)for(let p=r.startColumn;p<=r.endColumn;p++){let f=u0(e,u,p),b=(i=e.styles.fonts[(o=f.fontId)!=null?o:0])!=null?i:{},w=(s=e.styles.fills[(a=f.fillId)!=null?a:0])!=null?s:{},g=(d=e.styles.borders[(l=f.borderId)!=null?l:0])!=null?d:{};cn(n.bold,b.bold===true),cn(n.italic,b.italic===true),cn(n.underline,b.underline===true),cn(n.fontColor,b.color),cn(n.fillColor,w.foregroundColor),cn(n.numberFormatCode,f.numberFormatCode),cn(n.horizontal,f0(f)),cn(n.vertical,p0(f)),cn(n.border,g);}return {font:{bold:un(n.bold),italic:un(n.italic),underline:un(n.underline),color:un(n.fontColor)},fill:{foregroundColor:un(n.fillColor)},numberFormatCode:un(n.numberFormatCode),alignment:{horizontal:un(n.horizontal),vertical:un(n.vertical)},border:un(n.border)}}function c0(){return {bold:dn(),italic:dn(),underline:dn(),fontColor:dn(),fillColor:dn(),numberFormatCode:dn(),horizontal:dn(),vertical:dn(),border:dn()}}function dn(){return {hasValue:false,value:void 0,mixed:false}}function cn(e,t){if(!e.hasValue){e.hasValue=true,e.value=t;return}m0(e.value,t)||(e.mixed=true);}function un(e){return e.mixed?"mixed":e.value}function u0(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 f0(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 p0(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 m0(e,t){return JSON.stringify(e!=null?e:null)===JSON.stringify(t!=null?t:null)}function im(e,t,n,r,o){var b,w,g;let i=Ae(e.range),a=e.active,s=(b=e.focus)!=null?b:{row:i.endRow===a.row?i.startRow:i.endRow,column:i.endColumn===a.column?i.startColumn:i.endColumn},l=n.shift&&t!=="Tab"&&t!=="Enter"?s:a,u={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1],PageUp:[-((w=n.pageRows)!=null?w:20),0],PageDown:[(g=n.pageRows)!=null?g:20,0],Enter:[n.shift?-1:1,0],Tab:[0,n.shift?-1:1]}[t];if(!u&&t!=="Home"&&!(t==="End"&&n.command))return null;let p=l.row,f=l.column;if(t==="Home")f=1,n.command&&(p=1);else if(t==="End"){p=1,f=1;for(let h of r.source.cells)p=Math.max(p,h.row),f=Math.max(f,h.column);}else if(n.command&&t.startsWith("Arrow")){let h=u,y=h[0]?o.rowCount:o.columnCount,S=h[0]?p:f,E=h[0]||h[1],N=O=>{let W=r.cellsByAddress.get(excel.formatCellAddress(h[0]?O:p,h[1]?O:f));return !!(W!=null&&W.formula)||(W==null?void 0:W.value)!==void 0&&W.value!==null&&W.value!==""},A=Math.max(1,Math.min(y,S+E));if(N(S)&&N(A))for(;A+E>=1&&A+E<=y&&N(A+E);)A+=E;else for(;A>1&&A<y&&!N(A);)A+=E;h[0]?p=A:f=A;}else {let h=[...r.mergeMasterByAddress.values()].find(y=>p>=y.range.startRow&&p<=y.range.endRow&&f>=y.range.startColumn&&f<=y.range.endColumn);if(!n.shift&&h&&Math.abs(u[0])<=1&&Math.abs(u[1])<=1?(p=u[0]>0?h.range.endRow+1:u[0]<0?h.range.startRow-1:p,f=u[1]>0?h.range.endColumn+1:u[1]<0?h.range.startColumn-1:f):(p+=u[0],f+=u[1]),(t==="Tab"||t==="Enter")&&(i.startRow!==i.endRow||i.startColumn!==i.endColumn)&&!h)return t==="Tab"?(f>i.endColumn&&(f=i.startColumn,p++),f<i.startColumn&&(f=i.endColumn,p--)):(p>i.endRow&&(p=i.startRow,f++),p<i.startRow&&(p=i.endRow,f--)),p=p>i.endRow?i.startRow:p<i.startRow?i.endRow:p,f=f>i.endColumn?i.startColumn:f<i.startColumn?i.endColumn:f,{kind:e.kind,active:{row:p,column:f},range:i}}return p=Math.max(1,Math.min(o.rowCount,p)),f=Math.max(1,Math.min(o.columnCount,f)),n.shift&&t!=="Tab"&&t!=="Enter"?H(v({},ct(lr(e,p,f,o),r)),{focus:{row:p,column:f}}):ct(it(p,f),r)}function am(e,t,n){let{row:r,column:o}=e.active,i=[...t.cellsByAddress.values()].filter(p=>p.formula||p.value!==null&&p.value!==""),a={startRow:r,endRow:r,startColumn:o,endColumn:o},s=true;for(;s;){s=false;for(let p of i)p.row<a.startRow-1||p.row>a.endRow+1||p.column<a.startColumn-1||p.column>a.endColumn+1||p.row>=a.startRow&&p.row<=a.endRow&&p.column>=a.startColumn&&p.column<=a.endColumn||(a.startRow=Math.min(a.startRow,p.row),a.endRow=Math.max(a.endRow,p.row),a.startColumn=Math.min(a.startColumn,p.column),a.endColumn=Math.max(a.endColumn,p.column),s=true);}let l=!i.some(p=>p.row===r&&p.column===o),d=Ae(e.range),u=Object.keys(a).every(p=>a[p]===d[p]);return ct({kind:"cell",active:e.active,range:l||u?{startRow:1,startColumn:1,endRow:n.rowCount,endColumn:n.columnCount}:a},t)}var Ji=class{constructor(t,n){B(this,"host",t);B(this,"element",document.createElement("div"));B(this,"anchor",null);B(this,"handleOutsideInteraction",t=>{let n=t.composedPath();!n.includes(this.element)&&(!this.anchor||!n.includes(this.anchor))&&this.hide(false);});B(this,"handleResize",()=>{this.position();});this.element.setAttribute("role","dialog"),Object.assign(this.element.style,{position:"absolute",zIndex:"60",display:"none",width:"256px",maxWidth:"calc(100% - 8px)",boxSizing:"border-box",padding:"12px",border:"1px solid hsl(var(--border, 240 5.9% 90%))",borderRadius:"8px",background:"hsl(var(--popover, 0 0% 100%))",color:"hsl(var(--popover-foreground, 225 13% 10%))",boxShadow:"0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)",font:"13px Arial, sans-serif"});for(let r of ["pointerdown","click","dblclick","contextmenu"])this.element.addEventListener(r,o=>o.stopPropagation());this.element.addEventListener("keydown",r=>{r.stopPropagation(),r.key==="Escape"&&(r.preventDefault(),this.hide());}),n.appendChild(this.element);}show(t,n){if(this.anchor===t){this.hide();return}this.hide(false),this.anchor=t,t.setAttribute("aria-expanded","true"),t.setAttribute("aria-haspopup","dialog"),this.element.setAttribute("aria-label",n.title);let r=document.createElement("div");r.textContent=n.title,Object.assign(r.style,{fontSize:"14px",fontWeight:"600",lineHeight:"20px"});let o=document.createElement("div");o.textContent=n.description,o.title=n.description,Object.assign(o.style,{marginTop:"4px",fontSize:"12px",lineHeight:"18px",color:"hsl(var(--muted-foreground, 240 3.8% 46.1%))",overflowWrap:"anywhere",display:"-webkit-box",WebkitBoxOrient:"vertical",WebkitLineClamp:"2",overflow:"hidden"});let i=document.createElement("div");i.textContent="\u6B64\u64CD\u4F5C\u65E0\u6CD5\u64A4\u9500\u3002",Object.assign(i.style,{marginTop:"4px",fontSize:"12px",lineHeight:"18px",color:"hsl(var(--muted-foreground, 240 3.8% 46.1%))"});let a=document.createElement("div");Object.assign(a.style,{display:"flex",justifyContent:"flex-end",gap:"8px",marginTop:"12px"});let s=this.button("\u53D6\u6D88",false);s.addEventListener("click",()=>this.hide());let l=this.button("\u5220\u9664",true);l.addEventListener("click",()=>{this.anchor&&(this.hide(false),n.onConfirm());}),a.append(s,l),this.element.replaceChildren(r,o,i,a),this.element.style.display="block",this.position(),document.addEventListener("pointerdown",this.handleOutsideInteraction,true),document.addEventListener("focusin",this.handleOutsideInteraction,true),window.addEventListener("resize",this.handleResize),s.focus({preventScroll:true});}position(){if(!this.anchor)return;let t=this.host.getBoundingClientRect(),n=this.anchor.getBoundingClientRect(),r=this.element.getBoundingClientRect();this.element.style.left=`${Math.max(4,Math.min(n.left-t.left,t.width-r.width-4))}px`,this.element.style.top=`${Math.max(4,n.top-t.top-r.height-6)}px`;}hide(t=true){let n=this.anchor;this.anchor=null,this.element.style.display="none",n==null||n.removeAttribute("aria-expanded"),document.removeEventListener("pointerdown",this.handleOutsideInteraction,true),document.removeEventListener("focusin",this.handleOutsideInteraction,true),window.removeEventListener("resize",this.handleResize),t&&(n!=null&&n.isConnected)&&n.focus({preventScroll:true});}destroy(){this.hide(false),this.element.remove();}button(t,n){let r=document.createElement("button");return r.type="button",r.textContent=t,Object.assign(r.style,{height:"32px",padding:"0 12px",borderRadius:"8px",cursor:"pointer",font:"500 12px Arial, sans-serif",boxSizing:"border-box",border:n?"1px solid transparent":"1px solid hsl(var(--input, 240 5.9% 90%))",background:n?"hsl(var(--destructive, 0 84.2% 60.2%))":"hsl(var(--background, 0 0% 100%))",color:n?"hsl(var(--destructive-foreground, 0 0% 98%))":"inherit",boxShadow:"0 1px 2px 0 rgb(0 0 0 / 0.05)"}),r.addEventListener("mouseenter",()=>{r.style.filter="brightness(0.96)";}),r.addEventListener("mouseleave",()=>{r.style.filter="";}),r}};async function fP(e,t,n={}){let r=new Bl(e,n);return await r.loadWorkbook(t),r}var Bl=class{constructor(t,n){B(this,"host",t);B(this,"options",n);B(this,"renderRoot");B(this,"runtimeValue",null);B(this,"renderer",null);B(this,"layout",null);B(this,"viewport",null);B(this,"scroll",{x:0,y:0});B(this,"scrollbarState",null);B(this,"listeners",new Set);B(this,"stateListeners",new Set);B(this,"baseCanvas",document.createElement("canvas"));B(this,"headerCanvas",document.createElement("canvas"));B(this,"overlayCanvas",document.createElement("canvas"));B(this,"unsupportedObjectLayer",document.createElement("div"));B(this,"sheetTabs",document.createElement("div"));B(this,"horizontalScrollbar",document.createElement("div"));B(this,"verticalScrollbar",document.createElement("div"));B(this,"horizontalThumb",document.createElement("div"));B(this,"verticalThumb",document.createElement("div"));B(this,"cellEditorElement",document.createElement("textarea"));B(this,"resizeGuide",document.createElement("div"));B(this,"contextMenu",document.createElement("div"));B(this,"filterMenu",document.createElement("div"));B(this,"sheetDeleteConfirmation");B(this,"cellEditor");B(this,"resizeObserver");B(this,"disposed",false);B(this,"drag",null);B(this,"selectionState",it(1,1));B(this,"editingCell",null);B(this,"editingCellInitialValue",null);B(this,"pendingGridMutation",Promise.resolve());B(this,"editingCellStyle",null);B(this,"clipboardPayload",null);B(this,"clipboardCut",false);B(this,"clipboardActive",false);B(this,"nextPasteValuesOnly",false);B(this,"selecting",false);B(this,"resizeDrag",null);B(this,"autoFillDrag",null);B(this,"selectedChartIndex",null);B(this,"chartDrag",null);B(this,"columnFilters",new Map);B(this,"filterMenuColumn",null);B(this,"copiedRange",null);B(this,"formulaReferenceRanges",[]);B(this,"lastStateKey","");B(this,"transactionDepth",0);B(this,"transactionChanged",false);B(this,"readOnlyValue");B(this,"sheetActionPending",false);B(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.commit().catch(o=>this.reportError(o));}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=ct(it(r.row,r.column),o);}this.host.focus(),this.render();}});B(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 a=Array.from(this.filterMenu.querySelectorAll("input[data-filter-value]:checked")).map(s=>{var l;return (l=s.dataset.filterValue)!=null?l:""});this.columnFilters.set(o,a);}this.hideFilterMenu(),this.applyColumnFilters();});B(this,"handleDoubleClick",t=>{if(!this.viewport||!this.layout)return;let n=this.viewport.hitTest(this.eventPoint(t));if(n.kind==="cell"){if(this.selectionState=ct(it(n.row,n.column),this.runtime().activeSheet()),this.isReadOnly()){this.render();return}this.openCellEditor(),t.preventDefault();}});B(this,"handlePointerDown",t=>{var d;if(this.editingCell){if(this.eventPathContains(t,this.cellEditorElement))return;this.cellEditor.commit().catch(u=>this.reportError(u));}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=Rl(this.layout,this.viewport.viewports,n);if(o&&!this.isReadOnly()){this.resizeDrag=rm(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=Ae(this.selectionState.range),a=(d=this.renderer)==null?void 0:d.fillHandleRect(this.layout,this.viewport,i);if(!this.isReadOnly()&&a&&lm(a,n)&&Cl(this.runtime().activeSheet(),i)){this.autoFillDrag={source:i,preview:null},this.host.setPointerCapture(t.pointerId),t.preventDefault();return}let s=this.viewport.hitTest(n);if(s.kind!=="cell"&&s.kind!=="rowHeader"&&s.kind!=="columnHeader")return;this.host.focus({preventScroll:true});let l=this.runtime().activeSheet();s.kind==="cell"?this.selectionState=ct(it(s.row,s.column),l):s.kind==="rowHeader"?this.selectionState=Ki(s.row,{columnCount:this.layout.columnCount}):this.selectionState=_i(s.column,{rowCount:this.layout.rowCount}),this.selecting=true,this.host.setPointerCapture(t.pointerId),this.render(),t.preventDefault();});B(this,"handlePointerMove",t=>{if(!this.viewport||!this.layout)return;if(this.chartDrag){let o=this.eventPoint(t),i=o.x-this.chartDrag.pointer.x,a=o.y-this.chartDrag.pointer.y;this.chartDrag.previewRect=H(v({},this.chartDrag.startRect),{x:Math.max(0,this.chartDrag.startRect.x+i),y:Math.max(0,this.chartDrag.startRect.y+a)}),this.host.style.cursor="grabbing",this.render(),t.preventDefault();return}if(!this.resizeDrag&&!this.autoFillDrag&&!this.selecting&&!this.editingCell){let o=this.isReadOnly()?null:Rl(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=Ml(this.resizeDrag,t),this.updateResizeGuide(this.resizeDrag);return}if(this.autoFillDrag){let o=this.viewport.hitTest(this.eventPoint(t));this.autoFillDrag.preview=S0(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=ct(lr(this.selectionState,n.row,n.column,{rowCount:this.layout.rowCount,columnCount:this.layout.columnCount}),r):n.kind==="rowHeader"&&this.selectionState.kind==="row"?this.selectionState=lr(this.selectionState,n.row,1,{columnCount:this.layout.columnCount,rowCount:this.layout.rowCount}):n.kind==="columnHeader"&&this.selectionState.kind==="column"&&(this.selectionState=lr(this.selectionState,1,n.column,{columnCount:this.layout.columnCount,rowCount:this.layout.rowCount})),this.render(),t.preventDefault();});B(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=w0(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=Ml(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=H(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="");});B(this,"handlePointerLeave",()=>{!this.resizeDrag&&!this.autoFillDrag&&!this.chartDrag&&(this.host.style.cursor="");});B(this,"handleKeyDown",t=>{if(t.defaultPrevented||t.isComposing||t.keyCode===229||this.editingCell||this.isControlEvent(t))return;let n=t.ctrlKey||t.metaKey,r=t.key.toLowerCase();if(n&&!t.altKey){if(r==="c"||r==="x"||r==="v"){r==="v"&&(this.nextPasteValuesOnly=t.shiftKey);return}if(r==="z"||r==="y"&&!t.shiftKey){t.preventDefault(),this.isReadOnly()||(r==="y"||t.shiftKey?this.redo():this.undo()).catch(o=>this.reportError(o));return}if(r==="a"&&!t.shiftKey){t.preventDefault(),this.selectionState=am(this.selectionState,this.runtime().activeSheet(),this.gridBounds()),this.render();return}if(!t.shiftKey&&(r==="b"||r==="i"||r==="u")){t.preventDefault(),this.isReadOnly()||this.formatSelection(r==="b"?"bold":r==="i"?"italic":"underline").catch(o=>this.reportError(o));return}if(!t.shiftKey&&(r==="d"||r==="r")){t.preventDefault(),this.isReadOnly()||this.fillSelectionFromEdge(r==="d"?"down":"right").catch(o=>this.reportError(o));return}if(!t.shiftKey&&(t.key==="PageUp"||t.key==="PageDown")){t.preventDefault();let o=this.runtime().model().sheets.map(a=>a.name),i=o.indexOf(this.activeSheetName())+(t.key==="PageUp"?-1:1);o[i]&&this.setActiveSheet(o[i]).catch(a=>this.reportError(a));return}}if(!t.altKey&&(t.code==="Space"||t.key===" ")&&(n||t.shiftKey)){t.preventDefault();let{row:o,column:i}=this.selectionState.active,a=this.gridBounds();this.selectionState=n&&t.shiftKey?H(v({},it(o,i)),{range:{startRow:1,startColumn:1,endRow:a.rowCount,endColumn:a.columnCount}}):n?_i(i,a):Ki(o,a),this.render();return}if(t.key==="Delete"||t.key==="Backspace"){if(t.ctrlKey||t.metaKey||t.altKey||t.shiftKey||this.selectedChartIndex!==null)return;t.preventDefault(),this.isReadOnly()||this.clearSelection().catch(o=>this.reportError(o));return}if(t.key==="Escape"&&(this.copiedRange||this.clipboardActive)){this.cancelCopyOutline(),this.render(),t.preventDefault();return}if(t.key==="Enter"&&!n&&!t.shiftKey&&!t.altKey&&this.clipboardActive&&this.clipboardPayload&&!this.isReadOnly()){t.preventDefault();let o=new DataTransfer;o.setData("text/plain",this.clipboardPayload.text),o.setData(dr,this.clipboardPayload.id),this.pasteClipboardData(o,false,true).catch(i=>this.reportError(i));return}if(t.key==="F2"&&!n&&!t.altKey&&!t.shiftKey){if(this.isReadOnly())return;t.preventDefault(),this.openCellEditor().catch(o=>this.reportError(o));return}if(!(n&&!["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End"].includes(t.key))){if(!t.altKey&&this.navigateGrid(t.key,t.shiftKey,n)){t.preventDefault();return}!n&&!t.altKey&&Array.from(t.key).length===1&&!this.isReadOnly()&&(t.preventDefault(),this.openCellEditor(t.key).catch(o=>this.reportError(o)));}});B(this,"handleKeyUp",t=>{t.key.toLowerCase()==="v"&&(this.nextPasteValuesOnly=false);});B(this,"handleCopy",t=>{var o;if(this.editingCell||this.isControlEvent(t)||!t.clipboardData)return;let n=Ae(this.selectionState.range),r=qi(this.runtime().activeSheet(),n,{sourceWorkbookId:this.runtime().workbook().workbookId});this.clipboardPayload=r,this.clipboardCut=false,this.clipboardActive=true,this.copiedRange=n,(o=t.clipboardData)==null||o.setData("text/plain",r.text),t.clipboardData.setData(dr,wo(r)),t.clipboardData.setData("text/html",yl(r)),t.preventDefault(),this.render();});B(this,"handleCut",t=>{if(!(this.editingCell||this.isControlEvent(t))){if(this.isReadOnly()){t.preventDefault();return}this.handleCopy(t),t.defaultPrevented&&this.clipboardPayload&&(this.clipboardCut=true);}});B(this,"handlePaste",t=>{if(this.editingCell||this.isControlEvent(t))return;if(this.isReadOnly()){t.preventDefault();return}let n=t.clipboardData;if(!n)return;try{if(!n.types.includes("text/plain")&&!xo(n))return}catch(o){t.preventDefault(),this.reportError(o);return}t.preventDefault();let r=this.nextPasteValuesOnly;this.nextPasteValuesOnly=false,this.pasteClipboardData(n,r).catch(o=>this.reportError(o));});B(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=ct(it(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));});B(this,"handleDocumentPointerDown",t=>{let n=t.composedPath();n.includes(this.contextMenu)||n.includes(this.filterMenu)||(this.hideContextMenu(),this.hideFilterMenu());});B(this,"handleWheel",t=>{if(!this.runtimeValue)return;t.preventDefault();let n=tm(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=`
1670
+ `,{updates:F});});}),f}async resolveClipboardStyles(t){if(!t.styles)return t.styleIds;let n=this.state.model.styles,r=[...new Set(t.styleIds.flat().map(s=>s===void 0?"default":String(s)))],o=r.map(s=>{let l=t.styles[s];if(!l)throw new Error("\u526A\u8D34\u677F\u7F3A\u5C11\u5355\u5143\u683C\u683C\u5F0F\u5B9A\u4E49\uFF0C\u8BF7\u91CD\u65B0\u590D\u5236\u3002");return l}),i=await this.state.workbook.importCellStyles(o),a=new Map(r.map((s,l)=>[s,i[l]]));return t.styleIds.map(s=>s.map(l=>{let d=l===void 0?"default":String(l);return (l===void 0||n.cellFormats[l])&&excel.equalExcelCellStyles(t.styles[d],excel.captureExcelCellStyle(n,l))?l:a.get(d)}))}async clearRange(t,n,r,o){await this.runUserMutation({label:"Clear range"},async i=>{await i.setRangeValues(this.state.activeSheetName,excel.formatRangeAddress(t,n,r,o),Array.from({length:r},()=>Array(o).fill(null)));});}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,r){await this.runUserMutation({label:"Set column width"},async o=>{await o.setColumnWidth(this.state.activeSheetName,t,zi(n,r));});}async setFreezePanes(t,n){let r=Qp(t),o=Qp(n),i=i0(this.state.activeSheet.source.sheetViews,r,o);await this.runUserMutation({label:r||o?"Freeze panes":"Unfreeze panes"},async a=>{await a.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 a=>{await a.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 a=>{await a.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 a=>{await a.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 a=>{await a.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 a=>{await a.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 a=>{await a.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 a=>{await a.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 a=>{await a.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),a=await this.cellStyleId(excel.formatCellAddress(t,n));await this.runUserMutation({label:"Merge range"},async s=>{await s.setRangeStyleId(this.state.activeSheetName,i,a),await s.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(a=>a.address===r),i=o?excel.formatCellAddress(o.range.startRow,o.range.startColumn):c0(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 s=>{await s.setRangeBorder(this.state.activeSheetName,excel.formatRangeAddress(t,n,r,o),{});});return}let a=o0();if(i==="all"){await this.runUserMutation({label:"Set all borders"},async s=>{await s.setRangeBorder(this.state.activeSheetName,excel.formatRangeAddress(t,n,r,o),{left:a,right:a,top:a,bottom:a});});return}await this.runUserMutation({label:`Set ${i} borders`},async s=>{await s.setRangeBorder(this.state.activeSheetName,excel.formatRangeAddress(t,n,r,o),{});for(let l=0;l<r;l++)for(let d=0;d<o;d++){let u={};i==="outer"?(l===0&&(u.top=a),l===r-1&&(u.bottom=a),d===0&&(u.left=a),d===o-1&&(u.right=a)):(d<o-1&&(u.right=a),l<r-1&&(u.bottom=a)),Object.keys(u).length!==0&&await s.setRangeBorder(this.state.activeSheetName,excel.formatCellAddress(t+l,n+d),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 a=o.drawings.findIndex(p=>p.path===i.drawingPath),s=a>=0?o.drawings[a]:o.drawings[0];if(!s)return;let l=s.anchors.findIndex(p=>{var b;return ((b=p.object)==null?void 0:b.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())[a>=0?a: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=po(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(O(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 s=>{this.activeTransaction=s,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 mn("spreadsheet")}cellEditHistoryGroup(t,n,r){var i;let o={label:t};return r.mergeUndo?O(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 o0(){return {style:"thin",color:{rgb:"#111827"}}}function Qp(e){return Number.isFinite(e)?Math.max(0,Math.floor(e)):0}function i0(e,t,n){var i;if(!t&&!n)return e.map((a,s)=>O(v({},a),{pane:s===0?void 0:a.pane?v({},a.pane):void 0,selections:a.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 [O(v({},r),{pane:o,selections:r.selections.map(a=>v({},a))}),...e.slice(1).map(a=>O(v({},a),{pane:a.pane?v({},a.pane):void 0,selections:a.selections.map(s=>v({},s))}))]}async function a0(e,t,n,r,o,i){for(let a=0;a<i.length;a++){let s=i[a];if(s)for(let l=0;l<o;l++)await e.setRangeStyleId(t,excel.formatCellAddress(n+a,r+l),s[l]);}}async function s0(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 l0(e){switch(e){case "values":return "Paste values";case "formats":return "Paste formats";default:return "Paste range"}}function em(e){return JSON.parse(JSON.stringify(e))}function d0(e){var r,o,i,a,s,l;let t={total:0,added:0,modified:0,deleted:0},n=[];for(let d of e.sheets)for(let u of d.cells)t.total+=1,t[u.kind]+=1,!(n.length>=20)&&n.push({sheetName:(o=(r=d.afterName)!=null?r:d.beforeName)!=null?o:d.sheetId,address:u.address,kind:u.kind,before:(a=(i=u.before)==null?void 0:i.value)!=null?a:null,after:(l=(s=u.after)==null?void 0:s.value)!=null?l:null});return {changed:e.changed,changedSheets:e.sheets.length,sheetNames:e.sheets.map(d=>{var u,f;return (f=(u=d.afterName)!=null?u:d.beforeName)!=null?f:d.sheetId}),cellChanges:t,structuralChanged:e.sheets.some(d=>d.structuralChanged),objectChanged:e.sheets.some(d=>d.objectChanged),sampleCells:n}}function Pl(e,t){return !(e.endRow<t.startRow||e.startRow>t.endRow||e.endColumn<t.startColumn||e.startColumn>t.endColumn)}function c0(e){let t=excel.parseRangeAddress(e);return excel.formatCellAddress(t.startRow,t.startColumn)}async function PT(e,t,n={}){return {action:t,context:n,transaction:await e.previewAgentTransaction(nm(t),r=>t.run(r,n))}}async function RT(e,t,n={}){return {action:t,context:n,transaction:await e.runAgentTransaction(nm(t),r=>t.run(r,n))}}function nm(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 Qi=class{constructor(t){D(this,"options",t);D(this,"active",false);D(this,"pendingCommit",Promise.resolve());D(this,"handleBlur",()=>{this.commit().catch(t=>{var n,r;return (r=(n=this.options).onError)==null?void 0:r.call(n,t)});});D(this,"handleKeyDown",t=>{t.isComposing||t.keyCode===229||(t.key==="Escape"?(t.preventDefault(),t.stopPropagation(),this.cancel()):(t.key==="Enter"||t.key==="Tab")&&!t.altKey&&!t.ctrlKey&&!t.metaKey&&(t.preventDefault(),t.stopPropagation(),this.commit({key:t.key,reverse:t.shiftKey}).catch(n=>{var r,o;return (o=(r=this.options).onError)==null?void 0:o.call(r,n)})));});t.textarea.addEventListener("keydown",this.handleKeyDown),t.textarea.addEventListener("blur",this.handleBlur);}open(t,n){this.active=true;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();}commit(t){if(!this.active)return this.pendingCommit;this.active=false;let n=this.options.textarea.value;try{this.pendingCommit=Promise.resolve(this.options.onCommit(n)),t&&(this.pendingCommit=this.pendingCommit.then(()=>{var r,o;return (o=(r=this.options).onNavigate)==null?void 0:o.call(r,t.key,t.reverse)}));}catch(r){this.pendingCommit=Promise.reject(r);}return this.close(),this.pendingCommit}cancel(){var t,n;this.active=false,this.close(),(n=(t=this.options).onCancel)==null||n.call(t);}close(){this.options.textarea.style.display="none";}destroy(){this.active=false,this.options.textarea.removeEventListener("keydown",this.handleKeyDown),this.options.textarea.removeEventListener("blur",this.handleBlur),this.close();}};function om(e,t,n){return {x:Math.max(0,e.x+t),y:Math.max(0,e.y+n)}}function im(e,t,n,r,o=12){let i=e.getColumnX(n.frozenColumns+1),a=e.getRowY(n.frozenRows+1),s=Math.max(0,t.width-e.rowHeaderWidth-i-o),l=Math.max(0,t.height-e.columnHeaderHeight-a-o),d=s,u=l,f=Math.max(0,e.totalWidth()-i),p=Math.max(0,e.totalHeight()-a);return {horizontal:rm(f,d,s,r.x),vertical:rm(p,u,l,r.y)}}function ea(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 rm(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)),a=Math.max(0,n-i),s=o<=0?0:Math.max(0,Math.min(o,r))/o*a;return {trackLength:n,thumbStart:s,thumbLength:i,maxScroll:o}}var BT=24,DT=12,FT=4;function Rl(e,t,n){for(let r of t){if(r.kind==="columnHeaderFrozen"||r.kind==="columnHeaderScrollable"){let o=u0(e,r,n);if(o)return o}if(r.kind==="rowHeaderFrozen"||r.kind==="rowHeaderScrollable"){let o=f0(e,r,n);if(o)return o}}return null}function am(e,t){return O(v({},e),{startClientX:t.clientX,startClientY:t.clientY,currentSize:e.startSize,currentGuidePosition:e.guidePosition})}function Ml(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 O(v({},e),{currentSize:r,currentGuidePosition:e.guidePosition+r-e.startSize})}function u0(e,t,n){if(!sm(t.screenRect,n,4))return null;for(let r=t.columns.start;r<=t.columns.end;r++){let o=e.getCellLogicalRect(1,r),a=t.screenRect.x+o.x-t.originX+o.width;if(Math.abs(n.x-a)<=4)return {kind:"column",index:r,startSize:e.getColumnWidth(r),guidePosition:a,minSize:24}}return null}function f0(e,t,n){if(!sm(t.screenRect,n,4))return null;for(let r=t.rows.start;r<=t.rows.end;r++){let o=e.getCellLogicalRect(r,1),a=t.screenRect.y+o.y-t.originY+o.height;if(Math.abs(n.y-a)<=4)return {kind:"row",index:r,startSize:e.getRowHeight(r),guidePosition:a,minSize:12}}return null}function sm(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 VT(e,t){var o,i,a,s,l,d;let n=p0(),r=Le(t.range);for(let u=r.startRow;u<=r.endRow;u++)for(let f=r.startColumn;f<=r.endColumn;f++){let p=m0(e,u,f),b=(i=e.styles.fonts[(o=p.fontId)!=null?o:0])!=null?i:{},w=(s=e.styles.fills[(a=p.fillId)!=null?a:0])!=null?s:{},g=(d=e.styles.borders[(l=p.borderId)!=null?l:0])!=null?d:{};cn(n.bold,b.bold===true),cn(n.italic,b.italic===true),cn(n.underline,b.underline===true),cn(n.fontColor,b.color),cn(n.fillColor,w.foregroundColor),cn(n.numberFormatCode,p.numberFormatCode),cn(n.horizontal,h0(p)),cn(n.vertical,g0(p)),cn(n.border,g);}return {font:{bold:un(n.bold),italic:un(n.italic),underline:un(n.underline),color:un(n.fontColor)},fill:{foregroundColor:un(n.fillColor)},numberFormatCode:un(n.numberFormatCode),alignment:{horizontal:un(n.horizontal),vertical:un(n.vertical)},border:un(n.border)}}function p0(){return {bold:dn(),italic:dn(),underline:dn(),fontColor:dn(),fillColor:dn(),numberFormatCode:dn(),horizontal:dn(),vertical:dn(),border:dn()}}function dn(){return {hasValue:false,value:void 0,mixed:false}}function cn(e,t){if(!e.hasValue){e.hasValue=true,e.value=t;return}b0(e.value,t)||(e.mixed=true);}function un(e){return e.mixed?"mixed":e.value}function m0(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 h0(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 g0(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 b0(e,t){return JSON.stringify(e!=null?e:null)===JSON.stringify(t!=null?t:null)}function lm(e,t,n,r,o){var b,w,g;let i=Le(e.range),a=e.active,s=(b=e.focus)!=null?b:{row:i.endRow===a.row?i.startRow:i.endRow,column:i.endColumn===a.column?i.startColumn:i.endColumn},l=n.shift&&t!=="Tab"&&t!=="Enter"?s:a,u={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1],PageUp:[-((w=n.pageRows)!=null?w:20),0],PageDown:[(g=n.pageRows)!=null?g:20,0],Enter:[n.shift?-1:1,0],Tab:[0,n.shift?-1:1]}[t];if(!u&&t!=="Home"&&!(t==="End"&&n.command))return null;let f=l.row,p=l.column;if(t==="Home")p=1,n.command&&(f=1);else if(t==="End"){f=1,p=1;for(let h of r.source.cells)f=Math.max(f,h.row),p=Math.max(p,h.column);}else if(n.command&&t.startsWith("Arrow")){let h=u,y=h[0]?o.rowCount:o.columnCount,S=h[0]?f:p,k=h[0]||h[1],I=F=>{let L=r.cellsByAddress.get(excel.formatCellAddress(h[0]?F:f,h[1]?F:p));return !!(L!=null&&L.formula)||(L==null?void 0:L.value)!==void 0&&L.value!==null&&L.value!==""},A=Math.max(1,Math.min(y,S+k));if(I(S)&&I(A))for(;A+k>=1&&A+k<=y&&I(A+k);)A+=k;else for(;A>1&&A<y&&!I(A);)A+=k;h[0]?f=A:p=A;}else {let h=[...r.mergeMasterByAddress.values()].find(y=>f>=y.range.startRow&&f<=y.range.endRow&&p>=y.range.startColumn&&p<=y.range.endColumn);if(!n.shift&&h&&Math.abs(u[0])<=1&&Math.abs(u[1])<=1?(f=u[0]>0?h.range.endRow+1:u[0]<0?h.range.startRow-1:f,p=u[1]>0?h.range.endColumn+1:u[1]<0?h.range.startColumn-1:p):(f+=u[0],p+=u[1]),(t==="Tab"||t==="Enter")&&(i.startRow!==i.endRow||i.startColumn!==i.endColumn)&&!h)return t==="Tab"?(p>i.endColumn&&(p=i.startColumn,f++),p<i.startColumn&&(p=i.endColumn,f--)):(f>i.endRow&&(f=i.startRow,p++),f<i.startRow&&(f=i.endRow,p--)),f=f>i.endRow?i.startRow:f<i.startRow?i.endRow:f,p=p>i.endColumn?i.startColumn:p<i.startColumn?i.endColumn:p,{kind:e.kind,active:{row:f,column:p},range:i}}return f=Math.max(1,Math.min(o.rowCount,f)),p=Math.max(1,Math.min(o.columnCount,p)),n.shift&&t!=="Tab"&&t!=="Enter"?O(v({},ct(cr(e,f,p,o),r)),{focus:{row:f,column:p}}):ct(it(f,p),r)}function dm(e,t,n){let{row:r,column:o}=e.active,i=[...t.cellsByAddress.values()].filter(f=>f.formula||f.value!==null&&f.value!==""),a={startRow:r,endRow:r,startColumn:o,endColumn:o},s=true;for(;s;){s=false;for(let f of i)f.row<a.startRow-1||f.row>a.endRow+1||f.column<a.startColumn-1||f.column>a.endColumn+1||f.row>=a.startRow&&f.row<=a.endRow&&f.column>=a.startColumn&&f.column<=a.endColumn||(a.startRow=Math.min(a.startRow,f.row),a.endRow=Math.max(a.endRow,f.row),a.startColumn=Math.min(a.startColumn,f.column),a.endColumn=Math.max(a.endColumn,f.column),s=true);}let l=!i.some(f=>f.row===r&&f.column===o),d=Le(e.range),u=Object.keys(a).every(f=>a[f]===d[f]);return ct({kind:"cell",active:e.active,range:l||u?{startRow:1,startColumn:1,endRow:n.rowCount,endColumn:n.columnCount}:a},t)}var ta=class{constructor(t,n){D(this,"host",t);D(this,"element",document.createElement("div"));D(this,"anchor",null);D(this,"handleOutsideInteraction",t=>{let n=t.composedPath();!n.includes(this.element)&&(!this.anchor||!n.includes(this.anchor))&&this.hide(false);});D(this,"handleResize",()=>{this.position();});this.element.setAttribute("role","dialog"),Object.assign(this.element.style,{position:"absolute",zIndex:"60",display:"none",width:"256px",maxWidth:"calc(100% - 8px)",boxSizing:"border-box",padding:"12px",border:"1px solid hsl(var(--border, 240 5.9% 90%))",borderRadius:"8px",background:"hsl(var(--popover, 0 0% 100%))",color:"hsl(var(--popover-foreground, 225 13% 10%))",boxShadow:"0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)",font:"13px Arial, sans-serif"});for(let r of ["pointerdown","click","dblclick","contextmenu"])this.element.addEventListener(r,o=>o.stopPropagation());this.element.addEventListener("keydown",r=>{r.stopPropagation(),r.key==="Escape"&&(r.preventDefault(),this.hide());}),n.appendChild(this.element);}show(t,n){if(this.anchor===t){this.hide();return}this.hide(false),this.anchor=t,t.setAttribute("aria-expanded","true"),t.setAttribute("aria-haspopup","dialog"),this.element.setAttribute("aria-label",n.title);let r=document.createElement("div");r.textContent=n.title,Object.assign(r.style,{fontSize:"14px",fontWeight:"600",lineHeight:"20px"});let o=document.createElement("div");o.textContent=n.description,o.title=n.description,Object.assign(o.style,{marginTop:"4px",fontSize:"12px",lineHeight:"18px",color:"hsl(var(--muted-foreground, 240 3.8% 46.1%))",overflowWrap:"anywhere",display:"-webkit-box",WebkitBoxOrient:"vertical",WebkitLineClamp:"2",overflow:"hidden"});let i=document.createElement("div");i.textContent="\u6B64\u64CD\u4F5C\u65E0\u6CD5\u64A4\u9500\u3002",Object.assign(i.style,{marginTop:"4px",fontSize:"12px",lineHeight:"18px",color:"hsl(var(--muted-foreground, 240 3.8% 46.1%))"});let a=document.createElement("div");Object.assign(a.style,{display:"flex",justifyContent:"flex-end",gap:"8px",marginTop:"12px"});let s=this.button("\u53D6\u6D88",false);s.addEventListener("click",()=>this.hide());let l=this.button("\u5220\u9664",true);l.addEventListener("click",()=>{this.anchor&&(this.hide(false),n.onConfirm());}),a.append(s,l),this.element.replaceChildren(r,o,i,a),this.element.style.display="block",this.position(),document.addEventListener("pointerdown",this.handleOutsideInteraction,true),document.addEventListener("focusin",this.handleOutsideInteraction,true),window.addEventListener("resize",this.handleResize),s.focus({preventScroll:true});}position(){if(!this.anchor)return;let t=this.host.getBoundingClientRect(),n=this.anchor.getBoundingClientRect(),r=this.element.getBoundingClientRect();this.element.style.left=`${Math.max(4,Math.min(n.left-t.left,t.width-r.width-4))}px`,this.element.style.top=`${Math.max(4,n.top-t.top-r.height-6)}px`;}hide(t=true){let n=this.anchor;this.anchor=null,this.element.style.display="none",n==null||n.removeAttribute("aria-expanded"),document.removeEventListener("pointerdown",this.handleOutsideInteraction,true),document.removeEventListener("focusin",this.handleOutsideInteraction,true),window.removeEventListener("resize",this.handleResize),t&&(n!=null&&n.isConnected)&&n.focus({preventScroll:true});}destroy(){this.hide(false),this.element.remove();}button(t,n){let r=document.createElement("button");return r.type="button",r.textContent=t,Object.assign(r.style,{height:"32px",padding:"0 12px",borderRadius:"8px",cursor:"pointer",font:"500 12px Arial, sans-serif",boxSizing:"border-box",border:n?"1px solid transparent":"1px solid hsl(var(--input, 240 5.9% 90%))",background:n?"hsl(var(--destructive, 0 84.2% 60.2%))":"hsl(var(--background, 0 0% 100%))",color:n?"hsl(var(--destructive-foreground, 0 0% 98%))":"inherit",boxShadow:"0 1px 2px 0 rgb(0 0 0 / 0.05)"}),r.addEventListener("mouseenter",()=>{r.style.filter="brightness(0.96)";}),r.addEventListener("mouseleave",()=>{r.style.filter="";}),r}};async function hP(e,t,n={}){let r=new Bl(e,n);return await r.loadWorkbook(t),r}var Bl=class{constructor(t,n){D(this,"host",t);D(this,"options",n);D(this,"renderRoot");D(this,"runtimeValue",null);D(this,"renderer",null);D(this,"layout",null);D(this,"viewport",null);D(this,"scroll",{x:0,y:0});D(this,"scrollbarState",null);D(this,"listeners",new Set);D(this,"stateListeners",new Set);D(this,"baseCanvas",document.createElement("canvas"));D(this,"headerCanvas",document.createElement("canvas"));D(this,"overlayCanvas",document.createElement("canvas"));D(this,"unsupportedObjectLayer",document.createElement("div"));D(this,"sheetTabs",document.createElement("div"));D(this,"horizontalScrollbar",document.createElement("div"));D(this,"verticalScrollbar",document.createElement("div"));D(this,"horizontalThumb",document.createElement("div"));D(this,"verticalThumb",document.createElement("div"));D(this,"cellEditorElement",document.createElement("textarea"));D(this,"resizeGuide",document.createElement("div"));D(this,"contextMenu",document.createElement("div"));D(this,"filterMenu",document.createElement("div"));D(this,"sheetDeleteConfirmation");D(this,"cellEditor");D(this,"resizeObserver");D(this,"disposed",false);D(this,"drag",null);D(this,"selectionState",it(1,1));D(this,"editingCell",null);D(this,"editingCellInitialValue",null);D(this,"pendingGridMutation",Promise.resolve());D(this,"editingCellStyle",null);D(this,"clipboardPayload",null);D(this,"clipboardCut",false);D(this,"clipboardActive",false);D(this,"nextPasteValuesOnly",false);D(this,"selecting",false);D(this,"resizeDrag",null);D(this,"autoFillDrag",null);D(this,"selectedChartIndex",null);D(this,"chartDrag",null);D(this,"columnFilters",new Map);D(this,"filterMenuColumn",null);D(this,"copiedRange",null);D(this,"formulaReferenceRanges",[]);D(this,"lastStateKey","");D(this,"transactionDepth",0);D(this,"transactionChanged",false);D(this,"readOnlyValue");D(this,"sheetActionPending",false);D(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.commit().catch(o=>this.reportError(o));}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=ct(it(r.row,r.column),o);}this.host.focus(),this.render();}});D(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 a=Array.from(this.filterMenu.querySelectorAll("input[data-filter-value]:checked")).map(s=>{var l;return (l=s.dataset.filterValue)!=null?l:""});this.columnFilters.set(o,a);}this.hideFilterMenu(),this.applyColumnFilters();});D(this,"handleDoubleClick",t=>{if(!this.viewport||!this.layout)return;let n=this.viewport.hitTest(this.eventPoint(t));if(n.kind==="cell"){if(this.selectionState=ct(it(n.row,n.column),this.runtime().activeSheet()),this.isReadOnly()){this.render();return}this.openCellEditor(),t.preventDefault();}});D(this,"handlePointerDown",t=>{var d;if(this.editingCell){if(this.eventPathContains(t,this.cellEditorElement))return;this.cellEditor.commit().catch(u=>this.reportError(u));}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=Rl(this.layout,this.viewport.viewports,n);if(o&&!this.isReadOnly()){this.resizeDrag=am(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=Le(this.selectionState.range),a=(d=this.renderer)==null?void 0:d.fillHandleRect(this.layout,this.viewport,i);if(!this.isReadOnly()&&a&&um(a,n)&&Cl(this.runtime().activeSheet(),i)){this.autoFillDrag={source:i,preview:null},this.host.setPointerCapture(t.pointerId),t.preventDefault();return}let s=this.viewport.hitTest(n);if(s.kind!=="cell"&&s.kind!=="rowHeader"&&s.kind!=="columnHeader")return;this.host.focus({preventScroll:true});let l=this.runtime().activeSheet();s.kind==="cell"?this.selectionState=ct(it(s.row,s.column),l):s.kind==="rowHeader"?this.selectionState=Xi(s.row,{columnCount:this.layout.columnCount}):this.selectionState=Yi(s.column,{rowCount:this.layout.rowCount}),this.selecting=true,this.host.setPointerCapture(t.pointerId),this.render(),t.preventDefault();});D(this,"handlePointerMove",t=>{if(!this.viewport||!this.layout)return;if(this.chartDrag){let o=this.eventPoint(t),i=o.x-this.chartDrag.pointer.x,a=o.y-this.chartDrag.pointer.y;this.chartDrag.previewRect=O(v({},this.chartDrag.startRect),{x:Math.max(0,this.chartDrag.startRect.x+i),y:Math.max(0,this.chartDrag.startRect.y+a)}),this.host.style.cursor="grabbing",this.render(),t.preventDefault();return}if(!this.resizeDrag&&!this.autoFillDrag&&!this.selecting&&!this.editingCell){let o=this.isReadOnly()?null:Rl(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=Ml(this.resizeDrag,t),this.updateResizeGuide(this.resizeDrag);return}if(this.autoFillDrag){let o=this.viewport.hitTest(this.eventPoint(t));this.autoFillDrag.preview=E0(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=ct(cr(this.selectionState,n.row,n.column,{rowCount:this.layout.rowCount,columnCount:this.layout.columnCount}),r):n.kind==="rowHeader"&&this.selectionState.kind==="row"?this.selectionState=cr(this.selectionState,n.row,1,{columnCount:this.layout.columnCount,rowCount:this.layout.rowCount}):n.kind==="columnHeader"&&this.selectionState.kind==="column"&&(this.selectionState=cr(this.selectionState,1,n.column,{columnCount:this.layout.columnCount,rowCount:this.layout.rowCount})),this.render(),t.preventDefault();});D(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=v0(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=Ml(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=O(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="");});D(this,"handlePointerLeave",()=>{!this.resizeDrag&&!this.autoFillDrag&&!this.chartDrag&&(this.host.style.cursor="");});D(this,"handleKeyDown",t=>{if(t.defaultPrevented||t.isComposing||t.keyCode===229||this.editingCell||this.isControlEvent(t))return;let n=t.ctrlKey||t.metaKey,r=t.key.toLowerCase();if(n&&!t.altKey){if(r==="c"||r==="x"||r==="v"){r==="v"&&(this.nextPasteValuesOnly=t.shiftKey);return}if(r==="z"||r==="y"&&!t.shiftKey){t.preventDefault(),this.isReadOnly()||(r==="y"||t.shiftKey?this.redo():this.undo()).catch(o=>this.reportError(o));return}if(r==="a"&&!t.shiftKey){t.preventDefault(),this.selectionState=dm(this.selectionState,this.runtime().activeSheet(),this.gridBounds()),this.render();return}if(!t.shiftKey&&(r==="b"||r==="i"||r==="u")){t.preventDefault(),this.isReadOnly()||this.formatSelection(r==="b"?"bold":r==="i"?"italic":"underline").catch(o=>this.reportError(o));return}if(!t.shiftKey&&(r==="d"||r==="r")){t.preventDefault(),this.isReadOnly()||this.fillSelectionFromEdge(r==="d"?"down":"right").catch(o=>this.reportError(o));return}if(!t.shiftKey&&(t.key==="PageUp"||t.key==="PageDown")){t.preventDefault();let o=this.runtime().model().sheets.map(a=>a.name),i=o.indexOf(this.activeSheetName())+(t.key==="PageUp"?-1:1);o[i]&&this.setActiveSheet(o[i]).catch(a=>this.reportError(a));return}}if(!t.altKey&&(t.code==="Space"||t.key===" ")&&(n||t.shiftKey)){t.preventDefault();let{row:o,column:i}=this.selectionState.active,a=this.gridBounds();this.selectionState=n&&t.shiftKey?O(v({},it(o,i)),{range:{startRow:1,startColumn:1,endRow:a.rowCount,endColumn:a.columnCount}}):n?Yi(i,a):Xi(o,a),this.render();return}if(t.key==="Delete"||t.key==="Backspace"){if(t.ctrlKey||t.metaKey||t.altKey||t.shiftKey||this.selectedChartIndex!==null)return;t.preventDefault(),this.isReadOnly()||this.clearSelection().catch(o=>this.reportError(o));return}if(t.key==="Escape"&&(this.copiedRange||this.clipboardActive)){this.cancelCopyOutline(),this.render(),t.preventDefault();return}if(t.key==="Enter"&&!n&&!t.shiftKey&&!t.altKey&&this.clipboardActive&&this.clipboardPayload&&!this.isReadOnly()){t.preventDefault();let o=new DataTransfer;o.setData("text/plain",this.clipboardPayload.text),o.setData(ur,this.clipboardPayload.id),this.pasteClipboardData(o,false,true).catch(i=>this.reportError(i));return}if(t.key==="F2"&&!n&&!t.altKey&&!t.shiftKey){if(this.isReadOnly())return;t.preventDefault(),this.openCellEditor().catch(o=>this.reportError(o));return}if(!(n&&!["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End"].includes(t.key))){if(!t.altKey&&this.navigateGrid(t.key,t.shiftKey,n)){t.preventDefault();return}!n&&!t.altKey&&Array.from(t.key).length===1&&!this.isReadOnly()&&(t.preventDefault(),this.openCellEditor(t.key).catch(o=>this.reportError(o)));}});D(this,"handleKeyUp",t=>{t.key.toLowerCase()==="v"&&(this.nextPasteValuesOnly=false);});D(this,"handleCopy",t=>{var o;if(this.editingCell||this.isControlEvent(t)||!t.clipboardData)return;let n=Le(this.selectionState.range),r=Zi(this.runtime().activeSheet(),n,{sourceWorkbookId:this.runtime().workbook().workbookId});this.clipboardPayload=r,this.clipboardCut=false,this.clipboardActive=true,this.copiedRange=n,(o=t.clipboardData)==null||o.setData("text/plain",r.text),t.clipboardData.setData(ur,xo(r)),t.clipboardData.setData("text/html",yl(r)),t.preventDefault(),this.render();});D(this,"handleCut",t=>{if(!(this.editingCell||this.isControlEvent(t))){if(this.isReadOnly()){t.preventDefault();return}this.handleCopy(t),t.defaultPrevented&&this.clipboardPayload&&(this.clipboardCut=true);}});D(this,"handlePaste",t=>{if(this.editingCell||this.isControlEvent(t))return;if(this.isReadOnly()){t.preventDefault();return}let n=t.clipboardData;if(!n)return;try{if(!n.types.includes("text/plain")&&!yo(n))return}catch(o){t.preventDefault(),this.reportError(o);return}t.preventDefault();let r=this.nextPasteValuesOnly;this.nextPasteValuesOnly=false,this.pasteClipboardData(n,r).catch(o=>this.reportError(o));});D(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=ct(it(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));});D(this,"handleDocumentPointerDown",t=>{let n=t.composedPath();n.includes(this.contextMenu)||n.includes(this.filterMenu)||(this.hideContextMenu(),this.hideFilterMenu());});D(this,"handleWheel",t=>{if(!this.runtimeValue)return;t.preventDefault();let n=om(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=`
1617
1671
  :host { display: block; position: relative; min-width: 0; min-height: 0; }
1618
1672
  *, *::before, *::after { box-sizing: border-box; }
1619
1673
  button, input, textarea, select { font: 13px Arial, sans-serif; line-height: normal; }
1620
1674
  button { margin: 0; }
1621
- `,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",this.contextMenu.setAttribute("role","menu"),this.contextMenu.tabIndex=-1,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.contextMenu.addEventListener("keydown",o=>{var i;if(o.key==="Escape")this.hideContextMenu(),this.host.focus();else if(o.key==="ArrowDown"||o.key==="ArrowUp"){let a=Array.from(this.contextMenu.querySelectorAll("button:not(:disabled)")),s=a.indexOf(o.target);(i=a[(s+(o.key==="ArrowDown"?1:-1)+a.length)%a.length])==null||i.focus();}else return;o.preventDefault(),o.stopPropagation();}),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.sheetDeleteConfirmation=new Ji(t,this.renderRoot),this.cellEditor=new Yi({textarea:this.cellEditorElement,onCommit:async o=>this.commitCellEdit(o),onNavigate:(o,i)=>{this.navigateGrid(o,i),this.host.focus({preventScroll:true});},onError:o=>this.reportError(o),onCancel:()=>{this.editingCell=null,this.editingCellInitialValue=null,this.editingCellStyle=null,this.formulaReferenceRanges=[],this.render();}}),this.cellEditorElement.addEventListener("input",()=>{this.editingCell&&(this.formulaReferenceRanges=dm(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";for(let o of ["pointerdown","click","dblclick","contextmenu"])this.sheetTabs.addEventListener(o,i=>i.stopPropagation());n.showSheetTabs!==false&&this.renderRoot.appendChild(this.sheetTabs),this.renderer=new Ui({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("keyup",this.handleKeyUp),t.addEventListener("copy",this.handleCopy),t.addEventListener("cut",this.handleCut),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.renderTabs(),this.render());}selection(){return this.selectionState}cellState(t){var i,a,s,l;let n=this.runtime().activeSheet(),r=n.cellsByAddress.get(t);if(!r){let d=t.match(/^([A-Z]+)(\d+)$/i);if(!d)throw new Error(`SpreadsheetEditor: invalid cell address ${t}`);let u=y0(d[1]),p=Number(d[2]);return {address:t.toUpperCase(),row:p,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[(a=o.fontId)!=null?a:0],fill:n.styles.fills[(s=o.fillId)!=null?s:0],border:n.styles.borders[(l=o.borderId)!=null?l:0],alignment:o.alignment,numberFormatCode:o.numberFormatCode}:void 0}}freezeState(){return $i(this.runtime().activeSheet().source)}filterState(){return new Map([...this.columnFilters.entries()].map(([t,n])=>[t,[...n]]))}activeSheetName(){return this.runtime().activeSheetName()}setActiveSheet(t){return this.queueGridMutation(async()=>{await this.runtime().setActiveSheet(t),this.copiedRange=null,this.scroll={x:0,y:0},this.selectionState=ct(it(1,1),this.runtime().activeSheet()),this.render(),this.renderTabs(),this.isReadOnly()||await this.emitChange();})}async addSheet(t){await this.flushEdits(),await this.runtime().addSheet(t),this.copiedRange=null,this.scroll={x:0,y:0},this.selectionState=it(1,1),this.renderTabs(),this.render(),await this.emitChange();}async renameSheet(t,n){await this.flushEdits(),await this.runtime().renameSheet(t,n),this.copiedRange=null,this.renderTabs(),this.render(),await this.emitChange();}async copySheet(t,n){await this.flushEdits(),await this.runtime().copySheet(t,n),this.copiedRange=null,this.scroll={x:0,y:0},this.selectionState=it(1,1),this.renderTabs(),this.render(),await this.emitChange();}async deleteSheet(t){await this.flushEdits(),await this.runtime().deleteSheet(t),this.copiedRange=null,this.runtime().workbook().history().clear(),this.scroll={x:0,y:0},this.selectionState=it(1,1),this.renderTabs(),this.render(),await this.emitChange();}async moveSheet(t,n){await this.flushEdits(),await this.runtime().moveSheet(t,n),this.copiedRange=null,this.renderTabs(),this.render(),await this.emitChange();}async setCellValue(t,n){await this.flushEdits(),await this.runtime().setCellValue(t,n,{mergeUndo:true}),this.render(),await this.emitChange();}async setCellFormula(t,n){await this.flushEdits(),await this.runtime().setCellFormula(t,n,{mergeUndo:true}),this.render(),await this.emitChange();}formatSelection(t){let n=Ae(this.selectionState.range),r=excel.formatCellAddress(this.selectionState.active.row,this.selectionState.active.column);return this.queueGridMutation(async()=>this.applyFormat(t,n,r))}async setSelectionFontColor(t){await this.flushEdits();let n=Ae(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){await this.flushEdits();let n=Ae(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.flushEdits(),await this.applyAlignment(t);}async setSelectionVerticalAlign(t){await this.flushEdits();let n=Ae(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){await this.flushEdits();let n=Ae(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){await this.flushEdits();let n=Ae(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(),await this.flushEdits();let n=this.runtimeValue;this.runtimeValue=null,this.copiedRange=null,this.clipboardPayload=null,this.clipboardCut=false,this.clipboardActive=false,this.scroll={x:0,y:0},n&&await n.dispose(),this.runtimeValue=await Xi.fromZip(t,{workbookId:this.options.workbookId,mode:"inline",readOnly:this.readOnlyValue});let r=this.runtimeValue.activeSheet();this.selectionState=ct(it(1,1),r),await Pr(r.styles.cellFormats.map((o,i)=>mo(r.styles,i).font)),!this.disposed&&(this.host.setAttribute("aria-readonly",String(this.isReadOnly())),this.renderTabs(),this.render());}async toZip(){return await this.flushEdits(),this.runtime().toZip()}async flushEdits(){let t=this.pendingGridMutation;await this.cellEditor.commit(),await t;}canUndo(){return this.runtime().canUndo()}canRedo(){return this.runtime().canRedo()}undo(){return this.queueGridMutation(async()=>{this.runtime().canUndo()&&(await this.runtime().undo(),this.cancelCopyOutline(),this.renderTabs(),this.render(),await this.emitChange());})}redo(){return this.queueGridMutation(async()=>{this.runtime().canRedo()&&(await this.runtime().redo(),this.cancelCopyOutline(),this.renderTabs(),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){await this.flushEdits(),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;let t=this.flushEdits();this.disposed=true,this.cellEditor.destroy(),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("keyup",this.handleKeyUp),this.host.removeEventListener("copy",this.handleCopy),this.host.removeEventListener("cut",this.handleCut),this.host.removeEventListener("paste",this.handlePaste),this.host.removeEventListener("contextmenu",this.handleContextMenu),document.removeEventListener("pointerdown",this.handleDocumentPointerDown),this.sheetDeleteConfirmation.destroy(),this.contextMenu.remove(),this.filterMenu.remove(),this.unsupportedObjectLayer.remove(),this.host.replaceChildren();let n=this.runtimeValue;t.catch(r=>this.reportError(r)).finally(()=>{this.runtimeValue=null,n==null||n.dispose();});}render(){var p;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)),a=new Di(t.activeSheet(),{maximumDigitWidth:v0(t.activeSheet(),this.baseCanvas)}),s={width:Math.max(1,o-12),height:Math.max(1,i-12)},l=new Oi(a,{viewportSize:s,scroll:this.scroll,freeze:$i(t.activeSheet().source)});this.layout=a,this.viewport=l,this.scroll=l.scroll,this.scrollbarState=nm(a,s,$i(t.activeSheet().source),this.scroll),n.resize(o,i);let d=this.options.enableHeaderFilters===true&&!this.isReadOnly();n.setHeaderFiltersEnabled(d),n.setHeaderFilterColumns(d?Array.from({length:a.columnCount},(f,b)=>b+1):null),n.setActiveHeaderFilterColumns(Array.from(this.columnFilters.keys())),n.render(a,l);let u=Ae(this.selectionState.range);n.renderSelection(a,l,u,{showFillHandle:!this.isReadOnly()&&Cl(t.activeSheet(),u)}),this.updateCellEditorPosition(),(p=this.autoFillDrag)!=null&&p.preview&&n.renderDashedRange(a,l,this.autoFillDrag.preview,{stroke:"#16A34A",fill:"rgba(34, 197, 94, 0.08)"});for(let f of this.formulaReferenceRanges)n.renderDashedRange(a,l,f.range,{stroke:f.stroke});this.copiedRange&&n.renderCopiedRange(a,l,this.copiedRange),this.renderDrawingOverlays(a,l),this.emitStateIfChanged(t.activeSheetName()),this.updateScrollbars();}renderDrawingOverlays(t,n){var o,i,a;this.unsupportedObjectLayer.replaceChildren();let r=(o=this.runtimeValue)==null?void 0:o.activeSheet().source;if(r){for(let s of r.drawings)for(let l of s.anchors){let d=b0(l);if(!d)continue;let u=Ll(t,l);if(u)for(let p of Wl(u,n)){let f=document.createElement("div");f.setAttribute("aria-hidden","true"),Object.assign(f.style,v({position:"absolute",left:`${p.x}px`,top:`${p.y}px`,width:`${Math.max(1,p.width)}px`,height:`${Math.max(1,p.height)}px`,boxSizing:"border-box",pointerEvents:"none",opacity:d.dash==="dashed"?"0.72":"1"},d.orientation==="horizontal"?{borderTop:`1px ${d.dash} #4F9185`}:{borderLeft:`1px ${d.dash} #4F9185`})),this.unsupportedObjectLayer.appendChild(f);}}for(let s=0;s<r.charts.length;s+=1){let l=r.charts[s];if(!l)continue;let d=Al(r.drawings,l),u=((i=this.chartDrag)==null?void 0:i.chartIndex)===s?this.chartDrag.previewRect:Ll(t,d);if(u)for(let p of Wl(u,n)){let f=document.createElement("div");f.className="coco-spreadsheet-unsupported-chart",Object.assign(f.style,{position:"absolute",left:`${p.x}px`,top:`${p.y}px`,width:`${Math.max(1,p.width)}px`,height:`${Math.max(1,p.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":((a=this.chartDrag)==null?void 0:a.chartIndex)===s?"grabbing":"move",border:this.selectedChartIndex===s?"2px solid #2563eb":"1px dashed #94a3b8",boxShadow:this.selectedChartIndex===s?"0 0 0 1px rgba(37, 99, 235, 0.18)":"none"});let b=document.createElement("strong");b.textContent=l.title?`\u56FE\u8868\uFF1A${l.title}`:"\u56FE\u8868",b.style.color="#334155";let w=document.createElement("span");w.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",f.append(b,w,g),this.unsupportedObjectLayer.appendChild(f);}}}}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 a=Al(n.drawings,i),s=Ll(this.layout,a);if(s&&Wl(s,this.viewport).some(l=>lm(l,t)))return {chartIndex:o,logicalRect:s}}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";}fillSelectionFromEdge(t){let n=Ae(this.selectionState.range),r=v({},n);if(t==="down"){if(r.endRow=r.startRow,n.startRow===n.endRow){if(n.startRow===1)return Promise.resolve();r.startRow--,r.endRow--;}}else if(r.endColumn=r.startColumn,n.startColumn===n.endColumn){if(n.startColumn===1)return Promise.resolve();r.startColumn--,r.endColumn--;}return this.queueGridMutation(async()=>{let o=qi(this.runtime().activeSheet(),r);await this.runtime().pasteClipboard(o,n),this.cancelCopyOutline(),this.render(),await this.emitChange();})}gridBounds(){var t,n,r,o;return {rowCount:(n=(t=this.layout)==null?void 0:t.rowCount)!=null?n:this.runtime().activeSheet().maxRow,columnCount:(o=(r=this.layout)==null?void 0:r.columnCount)!=null?o:this.runtime().activeSheet().maxColumn}}navigateGrid(t,n=false,r=false){var a,s;let o=im(this.selectionState,t,{shift:n,command:r,pageRows:Math.max(1,Math.floor(this.host.getBoundingClientRect().height/((s=(a=this.layout)==null?void 0:a.defaultRowHeight)!=null?s:22))-3)},this.runtime().activeSheet(),this.gridBounds());if(!o)return false;this.selectionState=o;let i=this.layout;if(i&&this.viewport){let l=i.getCellLogicalRect(o.active.row,o.active.column),d=this.viewport.freeze,u=this.host.getBoundingClientRect(),{x:p,y:f}=this.scroll;o.active.column>d.frozenColumns&&(p=Math.max(l.x+l.width-(u.width-i.rowHeaderWidth-12),Math.min(p,l.x-i.getColumnX(d.frozenColumns+1)))),o.active.row>d.frozenRows&&(f=Math.max(l.y+l.height-(u.height-i.columnHeaderHeight-(this.options.showSheetTabs===false?0:40)-12),Math.min(f,l.y-i.getRowY(d.frozenRows+1)))),this.setScroll(Math.max(0,p),Math.max(0,f));}else this.render();return true}isControlEvent(t){return [this.cellEditorElement,this.sheetTabs,this.contextMenu,this.filterMenu].some(n=>this.eventPathContains(t,n))||t.composedPath().some(n=>n instanceof HTMLElement&&(n.isContentEditable||n.matches('input, textarea, select, button, [role="textbox"]')))}cancelCopyOutline(){this.copiedRange=null,this.clipboardCut=false,this.clipboardActive=false;}async pasteClipboardData(t,n=false,r=false){var f,b,w;if(!t.types.includes("text/plain")&&!xo(t))return Promise.resolve();let o=t.getData("text/plain"),i=xo(t),a=((f=this.clipboardPayload)==null?void 0:f.id)===i?this.clipboardPayload:void 0,s=(b=a!=null?a:wl(t))!=null?b:void 0,l=Ae(this.selectionState.range),d=this.selectionState,u=!!a&&this.clipboardCut&&!n,p=(w=s==null?void 0:s.values)!=null?w:Mp(o);return p.length?this.queueGridMutation(async()=>{let g,h=s!=null?s:{id:"external",text:o,values:p,sourceSheet:this.activeSheetName(),sourceRange:H(v({},l),{endRow:l.startRow+p.length-1,endColumn:l.startColumn+p.reduce((y,S)=>Math.max(y,S.length),0)-1}),formulas:p.map(y=>y.map(S=>typeof S=="string"&&S.startsWith("=")?S.slice(1):null)),styleIds:[],merges:[]};g=await this.runtime().pasteClipboard(h,l,{cut:u,valuesOnly:n}),(u||r)&&this.cancelCopyOutline(),this.selectionState===d&&(this.selectionState=ct({kind:"cell",active:{row:g.startRow,column:g.startColumn},range:g},this.runtime().activeSheet())),this.render(),await this.emitChange();}):Promise.resolve()}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:"Cut",action:()=>this.copySelection(true)},{label:"Paste",action:()=>this.pasteFromClipboard()},{label:"Clear cells",action:()=>this.clearSelection()},{label:"Clear format",action:()=>this.clearSelectionFormat()},{label:"Bold",action:()=>this.formatSelection("bold")},{label:"Italic",action:()=>this.formatSelection("italic")},{label:"Underline",action:()=>this.formatSelection("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.showContextMenu(o,t,n);}showContextMenu(t,n,r){var i;this.contextMenu.replaceChildren();for(let a of t){let s=document.createElement("button");s.type="button",s.textContent=a.label,s.setAttribute("role","menuitem"),a.title&&(s.title=a.title),s.disabled=a.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(),Promise.resolve().then(a.action).catch(l=>this.reportError(l));}),this.contextMenu.appendChild(s);}Object.assign(this.contextMenu.style,{left:`${n}px`,top:`${r}px`,display:"block"});let o=this.contextMenu.getBoundingClientRect();this.contextMenu.style.left=`${Math.max(4,Math.min(n,window.innerWidth-o.width-4))}px`,this.contextMenu.style.top=`${Math.max(4,Math.min(r,window.innerHeight-o.height-4))}px`,((i=this.contextMenu.querySelector("button:not(:disabled)"))!=null?i:this.contextMenu).focus();}openFilterMenu(t,n,r){var d;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},a=new Set((d=this.columnFilters.get(t))!=null?d:Il(o,i,t));this.filterMenuColumn=t,this.filterMenu.replaceChildren();let s=document.createElement("strong");s.textContent=`Filter ${t}`,s.style.display="block",s.style.marginBottom="6px",this.filterMenu.appendChild(s);for(let u of Il(o,i,t)){let p=document.createElement("label");p.style.display="block",p.style.padding="3px 0";let f=document.createElement("input");f.type="checkbox",f.checked=a.has(u),f.dataset.filterValue=u,f.style.marginRight="8px",p.append(f,u===""?"(blank)":u),this.filterMenu.appendChild(p);}let l=document.createElement("div");l.style.display="flex",l.style.gap="6px",l.style.marginTop="8px";for(let[u,p]of [["Apply","apply"],["Clear filter","clear"],["Cancel","cancel"]]){let f=document.createElement("button");f.type="button",f.textContent=u,f.dataset.filterAction=p,l.appendChild(f);}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){await this.flushEdits();let r=this.runtime().activeSheet();await this.runtime().sortRows(1,r.maxRow,t,n),this.render(),await this.emitChange();}async sortActiveColumn(t){await this.flushEdits(),await this.sortColumn(this.selectionState.active.column,t);}async filterColumn(t,n){await this.flushEdits(),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=Ae(this.selectionState.range);return t>=r.startRow&&t<=r.endRow&&n>=r.startColumn&&n<=r.endColumn}async copySelection(t=false){await this.flushEdits(),t&&this.assertWritable();let n=Ae(this.selectionState.range),r=qi(this.runtime().activeSheet(),n,{sourceWorkbookId:this.runtime().workbook().workbookId});this.clipboardPayload=r,this.clipboardCut=t,this.clipboardActive=true,this.copiedRange=n,this.render();try{typeof ClipboardItem!="undefined"&&navigator.clipboard.write?await navigator.clipboard.write([new ClipboardItem({"text/plain":new Blob([r.text],{type:"text/plain"}),"text/html":new Blob([yl(r)],{type:"text/html"})})]):await navigator.clipboard.writeText(r.text);}catch(o){throw this.cancelCopyOutline(),this.render(),new Error("\u65E0\u6CD5\u5199\u5165\u526A\u8D34\u677F\uFF0C\u8BF7\u4F7F\u7528 Ctrl/Command+C \u6216 X\u3002")}}async pasteFromClipboard(){await this.flushEdits();let t=new DataTransfer;try{if(navigator.clipboard.read){let n=await navigator.clipboard.read();for(let r of n)for(let o of ["text/plain","text/html"])r.types.includes(o)&&t.setData(o,await(await r.getType(o)).text());}else t.setData("text/plain",await navigator.clipboard.readText());}catch(n){throw new Error("\u65E0\u6CD5\u8BFB\u53D6\u526A\u8D34\u677F\uFF0C\u8BF7\u4F7F\u7528 Ctrl/Command+V\u3002")}await this.pasteClipboardData(t);}clearSelection(){let t=Ae(this.selectionState.range);return this.queueGridMutation(async()=>{await this.runtime().clearRange(t.startRow,t.startColumn,t.endRow-t.startRow+1,t.endColumn-t.startColumn+1),this.cancelCopyOutline(),this.render(),await this.emitChange();})}queueGridMutation(t){let n=this.flushEdits().then(t);this.pendingGridMutation=n;let r=()=>{this.pendingGridMutation===n&&(this.pendingGridMutation=Promise.resolve());};return n.then(r,r),n}async clearSelectionFormat(){await this.flushEdits();let t=Ae(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,n,r){var p,f;let o=n.endRow-n.startRow+1,i=n.endColumn-n.startColumn+1,a=this.runtime().activeSheet(),s=a.cellsByAddress.get(r),l=a.styles.cellFormats[(p=s==null?void 0:s.styleId)!=null?p:0],d=a.styles.fonts[(f=l==null?void 0:l.fontId)!=null?f:0],u=(d==null?void 0:d[t])!==true;t==="bold"&&await this.runtime().setRangeBold(n.startRow,n.startColumn,o,i,u),t==="italic"&&await this.runtime().setRangeItalic(n.startRow,n.startColumn,o,i,u),t==="underline"&&await this.runtime().setRangeUnderline(n.startRow,n.startColumn,o,i,u),this.cancelCopyOutline(),this.render(),await this.emitChange();}async applyAlignment(t){await this.flushEdits();let n=Ae(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(){await this.flushEdits();let t=Ae(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=ct(this.selectionState,this.runtime().activeSheet()),this.render(),await this.emitChange());}async unmergeSelection(){await this.flushEdits();let t=Ae(this.selectionState.range),n=[...this.runtime().activeSheet().mergeMasterByAddress.values()].filter(r=>k0(t,r.range)).map(r=>r.address);n.length!==0&&(await this.runtime().unmergeRanges(n),this.render(),await this.emitChange());}async freezeSelection(){await this.flushEdits();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){var n,r,o;if(await this.flushEdits(),t.currentSize===t.startSize){this.render();return}if(t.kind==="column")await this.runtime().setColumnWidth(t.index,t.currentSize,(n=this.layout)==null?void 0:n.maximumDigitWidth);else {let i=(o=(r=this.layout)==null?void 0:r.pointsToCssPixels)!=null?o:1.2;await this.runtime().setRowHeight(t.index,t.currentSize/i);}this.render(),await this.emitChange();}async openCellEditor(t){var b,w;if(await this.flushEdits(),this.disposed||this.isReadOnly()||!this.layout||!this.viewport)return;this.cancelCopyOutline();let n=this.selectionState.active,r=this.viewport.findViewport({x:this.layout.rowHeaderWidth+1,y:this.layout.columnHeaderHeight+1}),o=qe(this.runtime().activeSheet(),n.row,n.column),i=mo(this.runtime().activeSheet().styles,o==null?void 0:o.styleId,o);Object.assign(this.cellEditorElement.style,{font:i.font,color:i.fontColor,textDecoration:i.underline?"underline":"none",textAlign:i.horizontalAlign});let a=(b=this.viewport.viewports.find(g=>g.kind==="main"))!=null?b:r;if(!a)return;let s=Ae(this.selectionState.range),l=this.viewport.cellScreenRect(s.startRow,s.startColumn,a),d=this.viewport.cellScreenRect(s.endRow,s.endColumn,a),u={x:l.x,y:l.y,width:d.x+d.width-l.x,height:d.y+d.height-l.y};this.editingCell=n,this.editingCellStyle=i;let p=o!=null&&o.formula?`=${o.formula}`:(w=o==null?void 0:o.displayText)!=null?w:"";this.editingCellInitialValue=p;let f=t!=null?t:p;this.formulaReferenceRanges=dm(f),this.cellEditor.open(u,f),this.cellEditorElement.setSelectionRange(f.length,f.length),this.alignCellEditor(u,i),this.render();}async commitCellEdit(t){let n=this.editingCell,r=this.editingCellInitialValue;if(this.editingCell=null,this.editingCellInitialValue=null,this.editingCellStyle=null,this.formulaReferenceRanges=[],!n)return;if(t===r){this.render();return}this.assertWritable();let o=excel.formatCellAddress(n.row,n.column);t.startsWith("=")?await this.runtime().setCellFormula(o,t.slice(1)):await this.runtime().setCellValue(o,g0(t)),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 mn("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(d=>d.kind!=="columnHeaderFrozen"&&d.kind!=="columnHeaderScrollable"&&d.kind!=="rowHeaderFrozen"&&d.kind!=="rowHeaderScrollable"&&t.row>=d.rows.start&&t.row<=d.rows.end&&t.column>=d.columns.start&&t.column<=d.columns.end);if(!o){this.cellEditorElement.style.display="none";return}let i=Ae(this.selectionState.range),a=r.cellScreenRect(i.startRow,i.startColumn,o),s=r.cellScreenRect(i.endRow,i.endColumn,o),l={x:a.x,y:a.y,width:s.x+s.width-a.x,height:s.y+s.height-a.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 a=Math.max(0,t.height-r.scrollHeight),s=n.verticalAlign==="bottom"?i+a:n.verticalAlign==="middle"?i+a/2:i;r.style.paddingTop=`${s}px`;}async emitChange(){var n,r;if(this.transactionDepth>0){this.transactionChanged=true;return}let t={kind:"workbookChange",bytes:await this.runtime().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 a,s,l,d;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}:${(s=(a=this.editingCell)==null?void 0:a.row)!=null?s:0}:${(d=(l=this.editingCell)==null?void 0:l.column)!=null?d: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);}reportError(t){let n=t instanceof Error?t:new Error(String(t));this.options.onError?this.options.onError(n):console.error("[spreadsheet-editor]",n);}async runSheetUiAction(t){if(!this.sheetActionPending){this.sheetActionPending=true,this.hideContextMenu(),this.hideFilterMenu(),this.renderTabs();try{await this.flushEdits(),await t(),this.host.focus({preventScroll:!0});}catch(n){this.reportError(n);}finally{this.sheetActionPending=false,this.disposed||this.renderTabs();}}}async createSheetFromTabs(){let t=new Set(this.runtime().model().sheets.map(r=>r.name.toLowerCase())),n=1;for(;t.has(`sheet${n}`);)n+=1;await this.addSheet(`Sheet${n}`);}requestSheetDeletion(t,n){this.isReadOnly()||this.sheetActionPending||this.runtime().model().sheets.length<=1||(this.hideContextMenu(),this.hideFilterMenu(),this.sheetDeleteConfirmation.show(n,{title:"\u5220\u9664\u5DE5\u4F5C\u8868\uFF1F",description:t,onConfirm:()=>{this.runSheetUiAction(async()=>{this.isReadOnly()||this.runtime().model().sheets.length<=1||await this.deleteSheet(t);});}}));}renderTabs(){if(!(this.options.showSheetTabs===false||!this.runtimeValue)){this.sheetDeleteConfirmation.hide(false),this.sheetTabs.replaceChildren(),this.sheetTabs.setAttribute("role","group"),this.sheetTabs.setAttribute("aria-label","\u5DE5\u4F5C\u8868"),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=t.name===this.runtimeValue.activeSheetName(),r=document.createElement("button");r.type="button",r.textContent=t.name,r.setAttribute("aria-pressed",String(n)),r.disabled=this.sheetActionPending,r.dataset.active=String(n),Object.assign(r.style,{height:"32px",minWidth:"64px",padding:"0 14px",border:"0",borderTop:n?"2px solid #2563eb":"2px solid transparent",borderRadius:n&&!this.isReadOnly()?"3px 0 0 0":"3px 3px 0 0",background:n?"#ffffff":"transparent",color:n?"#1d4ed8":"#475569",font:"13px Arial, sans-serif",fontWeight:n?"600":"400",cursor:"pointer",whiteSpace:"nowrap"}),r.addEventListener("mouseenter",()=>{r.dataset.active!=="true"&&(r.style.background="#e2e8f0");}),r.addEventListener("mouseleave",()=>{r.dataset.active!=="true"&&(r.style.background="transparent");}),r.addEventListener("click",()=>{this.runSheetUiAction(()=>this.setActiveSheet(t.name));});let o=document.createElement("div");if(Object.assign(o.style,{display:"flex",alignItems:"center",flexShrink:"0"}),o.appendChild(r),n&&!this.isReadOnly()){let i=document.createElement("button"),a=this.runtimeValue.model().sheets.length<=1;i.type="button",i.setAttribute("aria-label",`\u5220\u9664\u5DE5\u4F5C\u8868\u201C${t.name}\u201D`),i.title=a?"\u5DE5\u4F5C\u7C3F\u81F3\u5C11\u4FDD\u7559\u4E00\u5F20\u5DE5\u4F5C\u8868":`\u5220\u9664\u5DE5\u4F5C\u8868\u201C${t.name}\u201D`,i.disabled=this.sheetActionPending||a,i.innerHTML='<svg width="14" height="14" viewBox="0 0 16 16" fill="none" aria-hidden="true"><path d="M2 4h12M6 4V2h4v2M3.5 4l.7 10h7.6l.7-10M6.5 7v4M9.5 7v4" stroke="currentColor" stroke-width="1.3" stroke-linecap="round" stroke-linejoin="round"/></svg>',Object.assign(i.style,{height:"32px",width:"24px",padding:"0",display:"grid",placeItems:"center",border:"0",borderTop:r.style.borderTop,background:r.style.background,borderRadius:"0 3px 0 0",color:"#64748b",cursor:i.disabled?"default":"pointer",opacity:i.disabled?"0.4":"1"}),i.addEventListener("mouseenter",()=>{i.disabled||(i.style.color="#dc2626");}),i.addEventListener("mouseleave",()=>{i.style.color="#64748b";}),i.addEventListener("click",()=>this.requestSheetDeletion(t.name,i)),o.appendChild(i);}this.sheetTabs.appendChild(o);}if(!this.isReadOnly()){let t=document.createElement("button");t.type="button",t.setAttribute("aria-label","\u65B0\u5EFA\u5DE5\u4F5C\u8868"),t.title="\u65B0\u5EFA\u5DE5\u4F5C\u8868",t.disabled=this.sheetActionPending,t.innerHTML='<svg width="18" height="18" viewBox="0 0 20 20" fill="none" aria-hidden="true"><path d="M10 4v12M4 10h12" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/></svg>',Object.assign(t.style,{width:"32px",height:"32px",display:"grid",placeItems:"center",flexShrink:"0",border:"0",borderRadius:"4px",background:"transparent",color:"#475569",cursor:"pointer"}),t.addEventListener("mouseenter",()=>{t.style.background="#e2e8f0";}),t.addEventListener("mouseleave",()=>{t.style.background="transparent";}),t.addEventListener("click",()=>{this.runSheetUiAction(()=>this.createSheetFromTabs());}),this.sheetTabs.appendChild(t);}}}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 a=t.getBoundingClientRect(),s=r?o.clientX-a.left:o.clientY-a.top;this.drag={axis:r?"horizontal":"vertical",pointer:s,thumb:i.thumbStart},t.setPointerCapture(o.pointerId),this.setScroll(r?Zi(i,s-i.thumbLength/2):this.scroll.x,r?this.scroll.y:Zi(i,s-i.thumbLength/2));}),t.addEventListener("pointermove",o=>{var u;let i=this.drag,a=(u=this.scrollbarState)==null?void 0:u[r?"horizontal":"vertical"];if(!i||!a||i.axis!==(r?"horizontal":"vertical"))return;let s=t.getBoundingClientRect(),l=r?o.clientX-s.left:o.clientY-s.top,d=Zi(a,i.thumb+l-i.pointer);this.setScroll(r?d:this.scroll.x,r?this.scroll.y:d);}),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 g0(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 lm(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 a;return ((a=i.object)==null?void 0:a.kind)==="chart"&&(!t.relationshipId||i.object.relationshipId===t.relationshipId)})}function b0(e){var o,i;if(((o=e.object)==null?void 0:o.kind)!=="shape")return null;let t=(i=e.object.name)!=null?i:"",n=t.match(/^coco-tianzige-(horizontal|vertical)-/);if(n!=null&&n[1])return {orientation:n[1],dash:"dashed"};if(/^coco-pinyin-guide-/.test(t))return {orientation:"horizontal",dash:"dashed"};let r=t.match(/^coco-(?:tianzige|pinyin)-outline-\d+-(top|bottom|vertical)(?:-|$)/);return r!=null&&r[1]?{orientation:r[1]==="vertical"?"vertical":"horizontal",dash:"solid"}:null}function Ll(e,t){var u,p;if(!t||t.kind==="absolute"||!t.from)return null;let n=Qi(t.from.column),r=Qi(t.from.row),o=t.to?Qi(t.to.column):n+5,i=t.to?Qi(t.to.row):r+12,a=e.getColumnX(n)+e.emuToCssPixels(t.from.columnOffset),s=e.getRowY(r)+e.emuToCssPixels(t.from.rowOffset),l=e.getColumnX(o)+e.emuToCssPixels((u=t.to)==null?void 0:u.columnOffset),d=e.getRowY(i)+e.emuToCssPixels((p=t.to)==null?void 0:p.rowOffset);return {x:a,y:s,width:Math.max(1,l-a),height:Math.max(1,d-s)}}function Wl(e,t){let n=[];for(let r of t.viewports){if(!x0(r))continue;let o=r.originX,i=r.originY,a=r.originX+r.screenRect.width,s=r.originY+r.screenRect.height,l=Math.max(e.x,o),d=Math.max(e.y,i),u=Math.min(e.x+e.width,a),p=Math.min(e.y+e.height,s);u<=l||p<=d||n.push({x:r.screenRect.x+l-r.originX,y:r.screenRect.y+d-r.originY,width:u-l,height:p-d});}return n}function w0(e,t,n){let r=(a,s)=>{let l=e.columnAt(Math.max(0,a)),d=e.rowAt(Math.max(0,s));return {column:l-1,row:d-1,columnOffset:e.cssPixelsToEmu(a-e.getColumnX(l)),rowOffset:e.cssPixelsToEmu(s-e.getRowY(d))}},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 x0(e){return e.kind==="main"||e.kind==="frozenTop"||e.kind==="frozenLeft"||e.kind==="frozenTopLeft"}function Qi(e){return Math.max(1,Math.floor(e!=null?e:0)+1)}function y0(e){let t=0;for(let n of e.toUpperCase())t=t*26+n.charCodeAt(0)-64;return t}function v0(e,t){var l,d,u,p,f;let n=t.getContext("2d");if(!n)return 7;let r=(l=e.styles.cellFormats[0])!=null?l:{},o=(u=e.styles.fonts[(d=r.fontId)!=null?d:0])!=null?u:{},i=((p=o.name)==null?void 0:p.trim())||"Arial",a=qt(i,{families:[]});n.save(),n.font=`${o.italic?"italic ":""}${o.bold?"600 ":""}${(f=o.size)!=null?f:11}pt ${a}, Arial, sans-serif`;let s=Math.max(...Array.from("0123456789",b=>n.measureText(b).width));return n.restore(),Number.isFinite(s)&&s>0?s:7}function S0(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?H(v({},e),{endRow:e.endRow+n}):H(v({},e),{endColumn:e.endColumn+r})}function k0(e,t){return !(e.endRow<t.startRow||e.startRow>t.endRow||e.endColumn<t.startColumn||e.startColumn>t.endColumn)}function dm(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 p,f,b;let a=o.split(":"),s=(p=a[0])!=null?p:"",l=(f=a[1])!=null?f:s,d=cm(s),u=cm(l);return !d||!u?[]:[{range:Ae({startRow:d.row,startColumn:d.column,endRow:u.row,endColumn:u.column}),stroke:(b=n[i%n.length])!=null?b:"#DC2626"}]})}function cm(e){var o,i;let t=e.replace(/\$/g,"").match(/^([A-Z]{1,3})(\d+)$/);if(!t)return null;let n=0;for(let a of (o=t[1])!=null?o:"")n=n*26+a.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 E0={width:9144e3,height:5143500},ta=new Set(["placeholder","textBox","geometricShape","line"]),mm=new WeakMap;function ko(e){var n;let t=(n=e.slideSize)!=null?n:E0;return {size:t,slides:e.slides.map(r=>I0(r,t))}}function I0(e,t){var l,d,u,p,f,b,w,g,h,y;let n=(d=(l=e.layout)==null?void 0:l.shapes)!=null?d:[],o=[...[...((f=(p=(u=e.layout)==null?void 0:u.master)==null?void 0:p.shapes)!=null?f:[]).map(S=>Dl(S,"master")),...n.map(S=>Dl(S,"layout"))].filter(T0),...e.shapes.map(S=>R0(S,e.layout))],i=o.flatMap(hm),a=(y=(w=e.background)!=null?w:(b=e.layout)==null?void 0:b.background)!=null?y:(h=(g=e.layout)==null?void 0:g.master)==null?void 0:h.background,s=a!=null?a:N0(o,t);return H(v({id:e.id,index:e.index,name:e.name,title:e.title,size:t},a?{background:a}:{}),{nodes:i.map((S,E)=>Co(S,{slideSize:t,index:E,background:a,backgroundFill:s})),groups:o.flatMap(S=>gm(S,{background:a,backgroundFill:s})),source:e})}function N0(e,t){var r;let n=e.find(o=>{var a;let i=So(o.geometry);return o.kind==="picture"&&!!((a=o.image)!=null&&a.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 Dl(e,t){var n;return H(v({},e),{id:`${t}:${e.id}`,children:(n=e.children)==null?void 0:n.map(r=>Dl(r,t))})}function T0(e){return e.placeholder?false:e.kind==="group"||e.kind==="picture"||e.kind==="geometricShape"||e.kind==="line"||e.kind==="textBox"}function hm(e){var t;return e.kind!=="group"?[e]:((t=e.children)!=null?t:[]).flatMap(n=>hm(bm(e,n)))}function gm(e,t={}){var n;return e.kind!=="group"?[]:[Co(e,{background:t.background,backgroundFill:t.backgroundFill}),...((n=e.children)!=null?n:[]).map(r=>bm(e,r)).flatMap(r=>gm(r,t))]}function bm(e,t){var N,A,O,W,V;let n=So(e.geometry),r=(N=e.raw)==null?void 0:N.groupTransform,o=So(t.geometry),i=(A=r==null?void 0:r.childLeft)!=null?A:n.left,a=(O=r==null?void 0:r.childTop)!=null?O:n.top,s=(r==null?void 0:r.childWidth)||n.width||1,l=(r==null?void 0:r.childHeight)||n.height||1,d=n.width/s,u=n.height/l,p=(o.left-i)*d,f=(o.top-a)*u,b=o.width*d,w=o.height*u,g=n.flipHorizontal?n.left+n.width-p-b:n.left+p,h=n.flipVertical?n.top+n.height-f-w:n.top+f,y=P0({left:g,top:h,width:b,height:w},n),S=wm(((W=n.rotation)!=null?W:0)+((V=o.rotation)!=null?V:0)),E=H(v({},t),{id:`${e.id}:${t.id}`,geometry:H(v({},t.geometry),{left:y.left,top:y.top,width:b,height:w,rotation:S,flipHorizontal:!!n.flipHorizontal!=!!o.flipHorizontal,flipVertical:!!n.flipVertical!=!!o.flipVertical}),children:t.children});return mm.set(E,{parentId:e.id,parentName:e.name,parentBounds:n,parentTransform:{childLeft:i,childTop:a,childWidth:s,childHeight:l}}),E}function P0(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,a=e.top+e.height/2,s=i-r,l=a-o,d=r+s*Math.cos(n)-l*Math.sin(n),u=o+s*Math.sin(n)+l*Math.cos(n);return H(v({},e),{left:d-e.width/2,top:u-e.height/2})}function wm(e){let t=(e%360+360)%360;return t===0?void 0:t}function R0(e,t){if(!e.placeholder)return e;let n=ppt.resolvePptEffectivePlaceholderProperties(e,t);return v(H(v({},e),{placeholder:n.placeholder,geometry:n.geometry,style:n.style}),e.text?{text:H(v({},e.text),{style:n.textStyle,body:n.textBody})}:{})}function Co(e,t={}){var d,u,p,f,b,w,g,h,y,S,E,N,A,O,W,V,ee;let n=xm(e),r=n.editText||n.editTextStyle||n.editTableCells||n.editGeometry||n.editShapeStyle,o=e.style,i=((d=e.raw)==null?void 0:d.useBackgroundFill)===true,a=i?void 0:(p=(u=e.style)==null?void 0:u.fillColor)!=null?p:L0(e,t),s=W0((f=e.text)==null?void 0:f.style,{fillColor:a,background:t.background}),l=So(e.geometry);return H(v({id:e.id,name:e.name,kind:e.kind,bounds:A0(e,l),text:(w=(b=e.text)==null?void 0:b.text)!=null?w:M0(e),textStyle:s,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:(S=e.image)==null?void 0:S.crop,imageFillRect:(E=e.image)==null?void 0:E.fillRect,imageOpacity:(N=e.image)==null?void 0:N.opacity,chart:e.chart,table:e.table,fillColor:a,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:(A=e.raw)==null?void 0:A.presetGeometry,presetAdjustments:(O=e.raw)==null?void 0:O.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:O0(e),source:e,children:((ee=e.children)!=null?ee:[]).map(pe=>Co(pe,{background:t.background,backgroundFill:t.backgroundFill}))})}function M0(e){if(e.table)return e.table.values.map(t=>t.join(" ")).join(`
1622
- `)}function A0(e,t){if(!e.table)return t;let n=um(e.table.columnWidths),r=um(e.table.rowHeights);return n===void 0&&r===void 0?t:v(v(v({},t),fm(t.width,n)?{width:n}:{}),fm(t.height,r)?{height:r}:{})}function um(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 fm(e,t){return t===void 0?false:!Number.isFinite(e)||e<=0?true:t/e>1.15}function L0(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 W0(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||!B0(n)?e:H(v({},e),{color:"#FFFFFF"})}function B0(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 gP(e){let t=xm(e);return t.editText||t.editTextStyle||t.editTableCells||t.editGeometry||t.editShapeStyle}function xm(e){if(F0(e))return {select:true,editText:false,editTextStyle:false,editTableCells:false,editGeometry:false,editShapeStyle:false,reason:"Inherited from layout/master",reasons:pm("\u7EE7\u627F\u81EA\u6BCD\u7248/\u7248\u5F0F\uFF0C\u5F53\u524D\u53EA\u652F\u6301\u67E5\u770B")};if(H0(e)){let n=!!e.text&&ta.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:vo({editText:n?void 0:ea(e),editTextStyle:n?void 0:ea(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:vo({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:vo({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=D0(e.kind);return {select:true,editText:false,editTextStyle:false,editTableCells:false,editGeometry:true,editShapeStyle:false,reason:"Limited editor support for this object type",reasons:vo({editText:n.text,editTextStyle:n.textStyle,editTableCells:"\u5F53\u524D\u5BF9\u8C61\u4E0D\u662F\u8868\u683C",editShapeStyle:n.shapeStyle})}}let t=!!e.text&&ta.has(e.kind);return ta.has(e.kind)?{select:true,editText:t,editTextStyle:t,editTableCells:false,editGeometry:true,editShapeStyle:true,reasons:vo({editText:t?void 0:ea(e),editTextStyle:t?void 0:ea(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:pm("\u5F53\u524D\u5BF9\u8C61\u7C7B\u578B\u6682\u4E0D\u652F\u6301\u5E38\u89C4\u7F16\u8F91")}}function vo(e){return Object.fromEntries(Object.entries(e).filter(t=>!!t[1]))}function pm(e){return {editText:e,editTextStyle:e,editTableCells:e,editGeometry:e,editShapeStyle:e}}function ea(e){return e.text?ta.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 D0(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 F0(e){return e.id.startsWith("layout:")||e.id.startsWith("master:")}function H0(e){return e.id.includes(":")}function ym(e,t){var b;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),a=n.height/(r.childHeight||n.height||1),s=$0(o.left+o.width/2,o.top+o.height/2,n),l=s.x-o.width/2,d=s.y-o.height/2,u=n.flipHorizontal?n.left+n.width-l-o.width:l-n.left,p=n.flipVertical?n.top+n.height-d-o.height:d-n.top,f={};return t.left!==void 0&&(f.left=u/i+r.childLeft),t.top!==void 0&&(f.top=p/a+r.childTop),t.width!==void 0&&(f.width=o.width/i),t.height!==void 0&&(f.height=o.height/a),t.rotation!==void 0&&(f.rotation=wm(t.rotation-((b=n.rotation)!=null?b:0))),t.flipHorizontal!==void 0&&(f.flipHorizontal=!!n.flipHorizontal!=!!t.flipHorizontal),t.flipVertical!==void 0&&(f.flipVertical=!!n.flipVertical!=!!t.flipVertical),f}function O0(e){return mm.get(e)}function $0(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,a=e-o,s=t-i;return {x:o+a*Math.cos(r)-s*Math.sin(r),y:i+a*Math.sin(r)+s*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 cr(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 Eo(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 vP(e,t={}){let n=await ppt.Presentation.fromZip(e,{presentationId:t.presentationId,mode:"inline"});return Sm(n,t)}async function SP(e,t={}){var r;let n=await ppt.Presentation.fromModel(e,{presentationId:(r=t.presentationId)!=null?r:e.id,mode:"inline"});return Sm(n,t)}async function Sm(e,t={}){let[n,r,o]=await Promise.all([e.toModel(),z0(e,t),V0(e)]);return {presentation:e,model:n,scene:ko(n),images:r,fonts:o}}async function z0(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 a;let i=await((a=t.resolveImagePreview)==null?void 0:a.call(t,{path:o.path,contentType:o.contentType,bytes:o.bytes}));return [o.path,i!=null?i:{url:URL.createObjectURL(new Blob([km(o.bytes)],{type:o.contentType})),contentType:o.contentType}]}));return Object.fromEntries(r)}async function V0(e){return typeof Blob=="undefined"||typeof URL=="undefined"||typeof URL.createObjectURL!="function"?[]:(await e.exportFonts()).map(n=>v(v({url:URL.createObjectURL(new Blob([km(n.bytes)],{type:n.contentType})),contentType:n.contentType,family:n.family},n.weight?{weight:n.weight}:{}),n.style?{style:n.style}:{}))}function km(e){let t=new Uint8Array(e.byteLength);return t.set(e),t.buffer}var na=class{constructor(t,n={}){B(this,"presentationValue");B(this,"modelValue");B(this,"sceneValue");B(this,"selectionValue",null);B(this,"revisionValue",0);B(this,"undoStack",[]);B(this,"redoStack",[]);B(this,"textBodyOverrides",new Map);B(this,"maxHistory");B(this,"readOnlyValue");B(this,"changeListeners",new Set);B(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 mn("ppt")}async applySelectionCommand(t){let n=cr(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=Eo(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 a,s;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=cr(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=_0(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&&j0(n)){let l=H(v({},n.textBody),{autoFit:"none",wrap:(s=(a=n.textBody)==null?void 0:a.wrap)!=null?s:"square"});await i.text.setBodyProperties(l),this.textBodyOverrides.set(G0(r.id,n.id),l);}await i.setGeometry(ym(n,t.geometry));return}await i.setStyle(t.style);}assertEditableSceneNodeForCommand(t){var o;let n=cr(this.sceneValue,t.slideIdOrIndex);if(!n)throw new Error(`PPT slide not found: ${String(t.slideIdOrIndex)}`);let r=(o=Eo(n,t.shapeIdOrName))!=null?o:K0(n,t.shapeIdOrName);if(!r)throw new Error(`PPT shape not found: ${t.shapeIdOrName}`);if(q0(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 d,u,p,f,b,w,g,h;this.assertEditableSceneNodeForCommand(t);let n=cr(this.sceneValue,t.slideIdOrIndex);if(!n)throw new Error(`PPT slide not found: ${String(t.slideIdOrIndex)}`);let r=Eo(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 a={left:typeof r.bounds.left=="number"?r.bounds.left+((u=(d=t.offset)==null?void 0:d.left)!=null?u:18e4):r.bounds.left,top:typeof r.bounds.top=="number"?r.bounds.top+((f=(p=t.offset)==null?void 0:p.top)!=null?f:18e4):r.bounds.top,width:(w=(b=t.offset)==null?void 0:b.width)!=null?w:r.bounds.width,height:(h=(g=t.offset)==null?void 0:g.height)!=null?h:r.bounds.height},l=await(await i.duplicate({geometry:a})).toModel();return {kind:"shape",slideId:n.id,shapeId:l.id}}async refreshAfterChange(t){this.modelValue=await this.presentationValue.toModel(),this.sceneValue=ko(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=ko(this.modelValue),this.applyTextBodyOverrides(),n){let i=this.sceneValue.slides.find(a=>a.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(a=>a.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 a=cr(this.sceneValue,o),s=a?Eo(a,i):null;!s||!s.text&&!((t=s.textParagraphs)!=null&&t.length)||(s.textBody=v(v({},s.textBody),r));}}};function G0(e,t){return `${e}\0${t}`}function j0(e){var t;return !!(e.capabilities.editGeometry&&U0(e)&&(e.text||(t=e.textParagraphs)!=null&&t.length))}function U0(e){return e.kind==="placeholder"||e.kind==="textBox"||e.kind==="geometricShape"}function K0(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 _0(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 q0(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 Em=24e4,No=91440,X0=91440,Fl=4,Im=7,ur=128,Y0=8,ra=2,Z0=2,oa=4;function WP(e,t,n={}){return new $l(e,t,n)}function J0(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 Cn(e,t,n){var d,u,p,f;let r=Math.max(No,(d=n.width)!=null?d:e.width),o=Math.max(No,(u=n.height)!=null?u:e.height),i=Math.min(Em,r),a=Math.min(Em,o),s=fa((p=n.left)!=null?p:e.left,-r+i,t.width-i),l=fa((f=n.top)!=null?f:e.top,-o+a,t.height-a);return H(v({},e),{left:s,top:l,width:r,height:o})}function fa(e,t,n){return Math.max(t,Math.min(n,e))}function ia(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(!Q0(i,t))continue;let a=n==="x"?i.bounds.left:i.bounds.top,s=n==="x"?i.bounds.width:i.bounds.height;o.push({value:a,kind:"shape",role:"start",referenceShapeId:i.id},{value:a+s/2,kind:"shape",role:"center",referenceShapeId:i.id},{value:a+s,kind:"shape",role:"end",referenceShapeId:i.id});}return o}function Q0(e,t){return e.id!==t&&e.kind!=="line"&&!e.locked&&!e.id.includes(":")&&e.capabilities.select&&e.capabilities.editGeometry&&e.bounds.width>No&&e.bounds.height>No}function aa(e,t,n,r={}){let o=null;for(let i of e)for(let a of t){if(r.matchRole!==false&&i.role!==a.role)continue;let s=Math.abs(i.value-a.value);s>n||(!o||s<o.distance)&&(o={source:i,target:a,distance:s});}return o}function Nm(e,t,n,r){let o=t/2,i=Math.abs(n.offset-o)<1?(r-e)*2:r-e;return Math.max(No,i)}function Vn(e){return !e.locked&&!e.id.includes(":")&&(e.capabilities.editGeometry||e.capabilities.editText||e.capabilities.editShapeStyle||e.capabilities.editTableCells)}function ek(e){let t=e.groupContext;return t?H(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 tk(e){var i,a;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=(a=(i=e.customGeometry.paths[0])==null?void 0:i.commands)!=null?a:[];return r.filter(s=>s.kind==="cubicBezierTo").length>=4&&r.some(s=>s.kind==="close")}var $l=class{constructor(t,n,r){B(this,"root");B(this,"sessionValue");B(this,"imageResources");B(this,"fontResources");B(this,"referencedFontFamilies");B(this,"slideList",document.createElement("div"));B(this,"canvas",document.createElement("div"));B(this,"contextMenu",document.createElement("div"));B(this,"snapGuides",document.createElement("div"));B(this,"options");B(this,"handleCanvasClick",()=>{this.dispatchCurrentSlideSelection();});B(this,"handleWindowMouseMove",t=>{this.updateDrag(t);});B(this,"handleWindowMouseUp",t=>{this.finishDrag(t);});B(this,"handleWindowKeyDown",t=>{this.handleKeyDown(t);});B(this,"handleWindowPointerDown",t=>{this.dismissContextMenu(t);});B(this,"handleWindowScroll",()=>this.hideContextMenu());B(this,"handleCanvasSelectStart",t=>this.handleSelectStart(t));B(this,"handleSlideListScroll",()=>this.scheduleThumbnailRender());B(this,"dragState",null);B(this,"suppressClickAfterDrag",false);B(this,"clipboardShape",null);B(this,"thumbnailFrame",0);B(this,"thumbnailRasterEpoch",0);B(this,"thumbnailCanvasCache",new Map);B(this,"pendingCommands",new Set);this.options=r,this.root=r.styleIsolation==="none"?t:t.attachShadow({mode:"open"}),this.sessionValue=new na(n,{readOnly:r.readOnly}),this.imageResources=n.images,this.fontResources=n.fonts,this.referencedFontFamilies=mk(n);let o=pk(this.fontResources,this.referencedFontFamilies);hk(this.scheduleFontRenderRefresh(o)),this.mount(),this.sessionValue.subscribe("change",async i=>{var a,s;this.thumbnailRasterEpoch++,this.render(),await((s=(a=this.options).onChange)==null?void 0:s.call(a,{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=`
1623
- ${uk(this.fontResources)}
1675
+ `,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",this.contextMenu.setAttribute("role","menu"),this.contextMenu.tabIndex=-1,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.contextMenu.addEventListener("keydown",o=>{var i;if(o.key==="Escape")this.hideContextMenu(),this.host.focus();else if(o.key==="ArrowDown"||o.key==="ArrowUp"){let a=Array.from(this.contextMenu.querySelectorAll("button:not(:disabled)")),s=a.indexOf(o.target);(i=a[(s+(o.key==="ArrowDown"?1:-1)+a.length)%a.length])==null||i.focus();}else return;o.preventDefault(),o.stopPropagation();}),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.sheetDeleteConfirmation=new ta(t,this.renderRoot),this.cellEditor=new Qi({textarea:this.cellEditorElement,onCommit:async o=>this.commitCellEdit(o),onNavigate:(o,i)=>{this.navigateGrid(o,i),this.host.focus({preventScroll:true});},onError:o=>this.reportError(o),onCancel:()=>{this.editingCell=null,this.editingCellInitialValue=null,this.editingCellStyle=null,this.formulaReferenceRanges=[],this.render();}}),this.cellEditorElement.addEventListener("input",()=>{this.editingCell&&(this.formulaReferenceRanges=fm(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";for(let o of ["pointerdown","click","dblclick","contextmenu"])this.sheetTabs.addEventListener(o,i=>i.stopPropagation());n.showSheetTabs!==false&&this.renderRoot.appendChild(this.sheetTabs),this.renderer=new qi({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("keyup",this.handleKeyUp),t.addEventListener("copy",this.handleCopy),t.addEventListener("cut",this.handleCut),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.renderTabs(),this.render());}selection(){return this.selectionState}cellState(t){var i,a,s,l;let n=this.runtime().activeSheet(),r=n.cellsByAddress.get(t);if(!r){let d=t.match(/^([A-Z]+)(\d+)$/i);if(!d)throw new Error(`SpreadsheetEditor: invalid cell address ${t}`);let u=k0(d[1]),f=Number(d[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[(a=o.fontId)!=null?a:0],fill:n.styles.fills[(s=o.fillId)!=null?s:0],border:n.styles.borders[(l=o.borderId)!=null?l:0],alignment:o.alignment,numberFormatCode:o.numberFormatCode}:void 0}}freezeState(){return Gi(this.runtime().activeSheet().source)}filterState(){return new Map([...this.columnFilters.entries()].map(([t,n])=>[t,[...n]]))}activeSheetName(){return this.runtime().activeSheetName()}setActiveSheet(t){return this.queueGridMutation(async()=>{await this.runtime().setActiveSheet(t),this.copiedRange=null,this.scroll={x:0,y:0},this.selectionState=ct(it(1,1),this.runtime().activeSheet()),this.render(),this.renderTabs(),this.isReadOnly()||await this.emitChange();})}async addSheet(t){await this.flushEdits(),await this.runtime().addSheet(t),this.copiedRange=null,this.scroll={x:0,y:0},this.selectionState=it(1,1),this.renderTabs(),this.render(),await this.emitChange();}async renameSheet(t,n){await this.flushEdits(),await this.runtime().renameSheet(t,n),this.copiedRange=null,this.renderTabs(),this.render(),await this.emitChange();}async copySheet(t,n){await this.flushEdits(),await this.runtime().copySheet(t,n),this.copiedRange=null,this.scroll={x:0,y:0},this.selectionState=it(1,1),this.renderTabs(),this.render(),await this.emitChange();}async deleteSheet(t){await this.flushEdits(),await this.runtime().deleteSheet(t),this.copiedRange=null,this.runtime().workbook().history().clear(),this.scroll={x:0,y:0},this.selectionState=it(1,1),this.renderTabs(),this.render(),await this.emitChange();}async moveSheet(t,n){await this.flushEdits(),await this.runtime().moveSheet(t,n),this.copiedRange=null,this.renderTabs(),this.render(),await this.emitChange();}async setCellValue(t,n){await this.flushEdits(),await this.runtime().setCellValue(t,n,{mergeUndo:true}),this.render(),await this.emitChange();}async setCellFormula(t,n){await this.flushEdits(),await this.runtime().setCellFormula(t,n,{mergeUndo:true}),this.render(),await this.emitChange();}formatSelection(t){let n=Le(this.selectionState.range),r=excel.formatCellAddress(this.selectionState.active.row,this.selectionState.active.column);return this.queueGridMutation(async()=>this.applyFormat(t,n,r))}async setSelectionFontColor(t){await this.flushEdits();let n=Le(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){await this.flushEdits();let n=Le(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.flushEdits(),await this.applyAlignment(t);}async setSelectionVerticalAlign(t){await this.flushEdits();let n=Le(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){await this.flushEdits();let n=Le(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){await this.flushEdits();let n=Le(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(),await this.flushEdits();let n=this.runtimeValue;this.runtimeValue=null,this.copiedRange=null,this.clipboardPayload=null,this.clipboardCut=false,this.clipboardActive=false,this.scroll={x:0,y:0},n&&await n.dispose(),this.runtimeValue=await Ji.fromZip(t,{workbookId:this.options.workbookId,mode:"inline",readOnly:this.readOnlyValue});let r=this.runtimeValue.activeSheet();this.selectionState=ct(it(1,1),r),await Mr(r.styles.cellFormats.map((o,i)=>ho(r.styles,i).font)),!this.disposed&&(this.host.setAttribute("aria-readonly",String(this.isReadOnly())),this.renderTabs(),this.render());}async toZip(){return await this.flushEdits(),this.runtime().toZip()}async flushEdits(){let t=this.pendingGridMutation;await this.cellEditor.commit(),await t;}canUndo(){return this.runtime().canUndo()}canRedo(){return this.runtime().canRedo()}undo(){return this.queueGridMutation(async()=>{this.runtime().canUndo()&&(await this.runtime().undo(),this.cancelCopyOutline(),this.renderTabs(),this.render(),await this.emitChange());})}redo(){return this.queueGridMutation(async()=>{this.runtime().canRedo()&&(await this.runtime().redo(),this.cancelCopyOutline(),this.renderTabs(),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){await this.flushEdits(),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;let t=this.flushEdits();this.disposed=true,this.cellEditor.destroy(),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("keyup",this.handleKeyUp),this.host.removeEventListener("copy",this.handleCopy),this.host.removeEventListener("cut",this.handleCut),this.host.removeEventListener("paste",this.handlePaste),this.host.removeEventListener("contextmenu",this.handleContextMenu),document.removeEventListener("pointerdown",this.handleDocumentPointerDown),this.sheetDeleteConfirmation.destroy(),this.contextMenu.remove(),this.filterMenu.remove(),this.unsupportedObjectLayer.remove(),this.host.replaceChildren();let n=this.runtimeValue;t.catch(r=>this.reportError(r)).finally(()=>{this.runtimeValue=null,n==null||n.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)),a=new Oi(t.activeSheet(),{maximumDigitWidth:C0(t.activeSheet(),this.baseCanvas)}),s={width:Math.max(1,o-12),height:Math.max(1,i-12)},l=new Vi(a,{viewportSize:s,scroll:this.scroll,freeze:Gi(t.activeSheet().source)});this.layout=a,this.viewport=l,this.scroll=l.scroll,this.scrollbarState=im(a,s,Gi(t.activeSheet().source),this.scroll),n.resize(o,i);let d=this.options.enableHeaderFilters===true&&!this.isReadOnly();n.setHeaderFiltersEnabled(d),n.setHeaderFilterColumns(d?Array.from({length:a.columnCount},(p,b)=>b+1):null),n.setActiveHeaderFilterColumns(Array.from(this.columnFilters.keys())),n.render(a,l);let u=Le(this.selectionState.range);n.renderSelection(a,l,u,{showFillHandle:!this.isReadOnly()&&Cl(t.activeSheet(),u)}),this.updateCellEditorPosition(),(f=this.autoFillDrag)!=null&&f.preview&&n.renderDashedRange(a,l,this.autoFillDrag.preview,{stroke:"#16A34A",fill:"rgba(34, 197, 94, 0.08)"});for(let p of this.formulaReferenceRanges)n.renderDashedRange(a,l,p.range,{stroke:p.stroke});this.copiedRange&&n.renderCopiedRange(a,l,this.copiedRange),this.renderDrawingOverlays(a,l),this.emitStateIfChanged(t.activeSheetName()),this.updateScrollbars();}renderDrawingOverlays(t,n){var o,i,a;this.unsupportedObjectLayer.replaceChildren();let r=(o=this.runtimeValue)==null?void 0:o.activeSheet().source;if(r){for(let s of r.drawings)for(let l of s.anchors){let d=y0(l);if(!d)continue;let u=Ll(t,l);if(u)for(let f of Wl(u,n)){let p=document.createElement("div");p.setAttribute("aria-hidden","true"),Object.assign(p.style,v({position:"absolute",left:`${f.x}px`,top:`${f.y}px`,width:`${Math.max(1,f.width)}px`,height:`${Math.max(1,f.height)}px`,boxSizing:"border-box",pointerEvents:"none",opacity:d.dash==="dashed"?"0.72":"1"},d.orientation==="horizontal"?{borderTop:`1px ${d.dash} #4F9185`}:{borderLeft:`1px ${d.dash} #4F9185`})),this.unsupportedObjectLayer.appendChild(p);}}for(let s=0;s<r.charts.length;s+=1){let l=r.charts[s];if(!l)continue;let d=Al(r.drawings,l),u=((i=this.chartDrag)==null?void 0:i.chartIndex)===s?this.chartDrag.previewRect:Ll(t,d);if(u)for(let f of Wl(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":((a=this.chartDrag)==null?void 0:a.chartIndex)===s?"grabbing":"move",border:this.selectedChartIndex===s?"2px solid #2563eb":"1px dashed #94a3b8",boxShadow:this.selectedChartIndex===s?"0 0 0 1px rgba(37, 99, 235, 0.18)":"none"});let b=document.createElement("strong");b.textContent=l.title?`\u56FE\u8868\uFF1A${l.title}`:"\u56FE\u8868",b.style.color="#334155";let w=document.createElement("span");w.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(b,w,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 a=Al(n.drawings,i),s=Ll(this.layout,a);if(s&&Wl(s,this.viewport).some(l=>um(l,t)))return {chartIndex:o,logicalRect:s}}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";}fillSelectionFromEdge(t){let n=Le(this.selectionState.range),r=v({},n);if(t==="down"){if(r.endRow=r.startRow,n.startRow===n.endRow){if(n.startRow===1)return Promise.resolve();r.startRow--,r.endRow--;}}else if(r.endColumn=r.startColumn,n.startColumn===n.endColumn){if(n.startColumn===1)return Promise.resolve();r.startColumn--,r.endColumn--;}return this.queueGridMutation(async()=>{let o=Zi(this.runtime().activeSheet(),r);await this.runtime().pasteClipboard(o,n),this.cancelCopyOutline(),this.render(),await this.emitChange();})}gridBounds(){var t,n,r,o;return {rowCount:(n=(t=this.layout)==null?void 0:t.rowCount)!=null?n:this.runtime().activeSheet().maxRow,columnCount:(o=(r=this.layout)==null?void 0:r.columnCount)!=null?o:this.runtime().activeSheet().maxColumn}}navigateGrid(t,n=false,r=false){var a,s;let o=lm(this.selectionState,t,{shift:n,command:r,pageRows:Math.max(1,Math.floor(this.host.getBoundingClientRect().height/((s=(a=this.layout)==null?void 0:a.defaultRowHeight)!=null?s:22))-3)},this.runtime().activeSheet(),this.gridBounds());if(!o)return false;this.selectionState=o;let i=this.layout;if(i&&this.viewport){let l=i.getCellLogicalRect(o.active.row,o.active.column),d=this.viewport.freeze,u=this.host.getBoundingClientRect(),{x:f,y:p}=this.scroll;o.active.column>d.frozenColumns&&(f=Math.max(l.x+l.width-(u.width-i.rowHeaderWidth-12),Math.min(f,l.x-i.getColumnX(d.frozenColumns+1)))),o.active.row>d.frozenRows&&(p=Math.max(l.y+l.height-(u.height-i.columnHeaderHeight-(this.options.showSheetTabs===false?0:40)-12),Math.min(p,l.y-i.getRowY(d.frozenRows+1)))),this.setScroll(Math.max(0,f),Math.max(0,p));}else this.render();return true}isControlEvent(t){return [this.cellEditorElement,this.sheetTabs,this.contextMenu,this.filterMenu].some(n=>this.eventPathContains(t,n))||t.composedPath().some(n=>n instanceof HTMLElement&&(n.isContentEditable||n.matches('input, textarea, select, button, [role="textbox"]')))}cancelCopyOutline(){this.copiedRange=null,this.clipboardCut=false,this.clipboardActive=false;}async pasteClipboardData(t,n=false,r=false){var p,b,w;if(!t.types.includes("text/plain")&&!yo(t))return Promise.resolve();let o=t.getData("text/plain"),i=yo(t),a=((p=this.clipboardPayload)==null?void 0:p.id)===i?this.clipboardPayload:void 0,s=(b=a!=null?a:wl(t))!=null?b:void 0,l=Le(this.selectionState.range),d=this.selectionState,u=!!a&&this.clipboardCut&&!n,f=(w=s==null?void 0:s.values)!=null?w:Wp(o);return f.length?this.queueGridMutation(async()=>{let g,h=s!=null?s:{id:"external",text:o,values:f,sourceSheet:this.activeSheetName(),sourceRange:O(v({},l),{endRow:l.startRow+f.length-1,endColumn:l.startColumn+f.reduce((y,S)=>Math.max(y,S.length),0)-1}),formulas:f.map(y=>y.map(S=>typeof S=="string"&&S.startsWith("=")?S.slice(1):null)),styleIds:[],merges:[]};g=await this.runtime().pasteClipboard(h,l,{cut:u,valuesOnly:n}),(u||r)&&this.cancelCopyOutline(),this.selectionState===d&&(this.selectionState=ct({kind:"cell",active:{row:g.startRow,column:g.startColumn},range:g},this.runtime().activeSheet())),this.render(),await this.emitChange();}):Promise.resolve()}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:"Cut",action:()=>this.copySelection(true)},{label:"Paste",action:()=>this.pasteFromClipboard()},{label:"Clear cells",action:()=>this.clearSelection()},{label:"Clear format",action:()=>this.clearSelectionFormat()},{label:"Bold",action:()=>this.formatSelection("bold")},{label:"Italic",action:()=>this.formatSelection("italic")},{label:"Underline",action:()=>this.formatSelection("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.showContextMenu(o,t,n);}showContextMenu(t,n,r){var i;this.contextMenu.replaceChildren();for(let a of t){let s=document.createElement("button");s.type="button",s.textContent=a.label,s.setAttribute("role","menuitem"),a.title&&(s.title=a.title),s.disabled=a.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(),Promise.resolve().then(a.action).catch(l=>this.reportError(l));}),this.contextMenu.appendChild(s);}Object.assign(this.contextMenu.style,{left:`${n}px`,top:`${r}px`,display:"block"});let o=this.contextMenu.getBoundingClientRect();this.contextMenu.style.left=`${Math.max(4,Math.min(n,window.innerWidth-o.width-4))}px`,this.contextMenu.style.top=`${Math.max(4,Math.min(r,window.innerHeight-o.height-4))}px`,((i=this.contextMenu.querySelector("button:not(:disabled)"))!=null?i:this.contextMenu).focus();}openFilterMenu(t,n,r){var d;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},a=new Set((d=this.columnFilters.get(t))!=null?d:Il(o,i,t));this.filterMenuColumn=t,this.filterMenu.replaceChildren();let s=document.createElement("strong");s.textContent=`Filter ${t}`,s.style.display="block",s.style.marginBottom="6px",this.filterMenu.appendChild(s);for(let u of Il(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=a.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){await this.flushEdits();let r=this.runtime().activeSheet();await this.runtime().sortRows(1,r.maxRow,t,n),this.render(),await this.emitChange();}async sortActiveColumn(t){await this.flushEdits(),await this.sortColumn(this.selectionState.active.column,t);}async filterColumn(t,n){await this.flushEdits(),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=Le(this.selectionState.range);return t>=r.startRow&&t<=r.endRow&&n>=r.startColumn&&n<=r.endColumn}async copySelection(t=false){await this.flushEdits(),t&&this.assertWritable();let n=Le(this.selectionState.range),r=Zi(this.runtime().activeSheet(),n,{sourceWorkbookId:this.runtime().workbook().workbookId});this.clipboardPayload=r,this.clipboardCut=t,this.clipboardActive=true,this.copiedRange=n,this.render();try{typeof ClipboardItem!="undefined"&&navigator.clipboard.write?await navigator.clipboard.write([new ClipboardItem({"text/plain":new Blob([r.text],{type:"text/plain"}),"text/html":new Blob([yl(r)],{type:"text/html"})})]):await navigator.clipboard.writeText(r.text);}catch(o){throw this.cancelCopyOutline(),this.render(),new Error("\u65E0\u6CD5\u5199\u5165\u526A\u8D34\u677F\uFF0C\u8BF7\u4F7F\u7528 Ctrl/Command+C \u6216 X\u3002")}}async pasteFromClipboard(){await this.flushEdits();let t=new DataTransfer;try{if(navigator.clipboard.read){let n=await navigator.clipboard.read();for(let r of n)for(let o of ["text/plain","text/html"])r.types.includes(o)&&t.setData(o,await(await r.getType(o)).text());}else t.setData("text/plain",await navigator.clipboard.readText());}catch(n){throw new Error("\u65E0\u6CD5\u8BFB\u53D6\u526A\u8D34\u677F\uFF0C\u8BF7\u4F7F\u7528 Ctrl/Command+V\u3002")}await this.pasteClipboardData(t);}clearSelection(){let t=Le(this.selectionState.range);return this.queueGridMutation(async()=>{await this.runtime().clearRange(t.startRow,t.startColumn,t.endRow-t.startRow+1,t.endColumn-t.startColumn+1),this.cancelCopyOutline(),this.render(),await this.emitChange();})}queueGridMutation(t){let n=this.flushEdits().then(t);this.pendingGridMutation=n;let r=()=>{this.pendingGridMutation===n&&(this.pendingGridMutation=Promise.resolve());};return n.then(r,r),n}async clearSelectionFormat(){await this.flushEdits();let t=Le(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,n,r){var f,p;let o=n.endRow-n.startRow+1,i=n.endColumn-n.startColumn+1,a=this.runtime().activeSheet(),s=a.cellsByAddress.get(r),l=a.styles.cellFormats[(f=s==null?void 0:s.styleId)!=null?f:0],d=a.styles.fonts[(p=l==null?void 0:l.fontId)!=null?p:0],u=(d==null?void 0:d[t])!==true;t==="bold"&&await this.runtime().setRangeBold(n.startRow,n.startColumn,o,i,u),t==="italic"&&await this.runtime().setRangeItalic(n.startRow,n.startColumn,o,i,u),t==="underline"&&await this.runtime().setRangeUnderline(n.startRow,n.startColumn,o,i,u),this.cancelCopyOutline(),this.render(),await this.emitChange();}async applyAlignment(t){await this.flushEdits();let n=Le(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(){await this.flushEdits();let t=Le(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=ct(this.selectionState,this.runtime().activeSheet()),this.render(),await this.emitChange());}async unmergeSelection(){await this.flushEdits();let t=Le(this.selectionState.range),n=[...this.runtime().activeSheet().mergeMasterByAddress.values()].filter(r=>I0(t,r.range)).map(r=>r.address);n.length!==0&&(await this.runtime().unmergeRanges(n),this.render(),await this.emitChange());}async freezeSelection(){await this.flushEdits();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){var n,r,o;if(await this.flushEdits(),t.currentSize===t.startSize){this.render();return}if(t.kind==="column")await this.runtime().setColumnWidth(t.index,t.currentSize,(n=this.layout)==null?void 0:n.maximumDigitWidth);else {let i=(o=(r=this.layout)==null?void 0:r.pointsToCssPixels)!=null?o:1.2;await this.runtime().setRowHeight(t.index,t.currentSize/i);}this.render(),await this.emitChange();}async openCellEditor(t){var b,w;if(await this.flushEdits(),this.disposed||this.isReadOnly()||!this.layout||!this.viewport)return;this.cancelCopyOutline();let n=this.selectionState.active,r=this.viewport.findViewport({x:this.layout.rowHeaderWidth+1,y:this.layout.columnHeaderHeight+1}),o=qe(this.runtime().activeSheet(),n.row,n.column),i=ho(this.runtime().activeSheet().styles,o==null?void 0:o.styleId,o);Object.assign(this.cellEditorElement.style,{font:i.font,color:i.fontColor,textDecoration:i.underline?"underline":"none",textAlign:i.horizontalAlign});let a=(b=this.viewport.viewports.find(g=>g.kind==="main"))!=null?b:r;if(!a)return;let s=Le(this.selectionState.range),l=this.viewport.cellScreenRect(s.startRow,s.startColumn,a),d=this.viewport.cellScreenRect(s.endRow,s.endColumn,a),u={x:l.x,y:l.y,width:d.x+d.width-l.x,height:d.y+d.height-l.y};this.editingCell=n,this.editingCellStyle=i;let f=o!=null&&o.formula?`=${o.formula}`:(w=o==null?void 0:o.displayText)!=null?w:"";this.editingCellInitialValue=f;let p=t!=null?t:f;this.formulaReferenceRanges=fm(p),this.cellEditor.open(u,p),this.cellEditorElement.setSelectionRange(p.length,p.length),this.alignCellEditor(u,i),this.render();}async commitCellEdit(t){let n=this.editingCell,r=this.editingCellInitialValue;if(this.editingCell=null,this.editingCellInitialValue=null,this.editingCellStyle=null,this.formulaReferenceRanges=[],!n)return;if(t===r){this.render();return}this.assertWritable();let o=excel.formatCellAddress(n.row,n.column);t.startsWith("=")?await this.runtime().setCellFormula(o,t.slice(1)):await this.runtime().setCellValue(o,x0(t)),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 mn("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(d=>d.kind!=="columnHeaderFrozen"&&d.kind!=="columnHeaderScrollable"&&d.kind!=="rowHeaderFrozen"&&d.kind!=="rowHeaderScrollable"&&t.row>=d.rows.start&&t.row<=d.rows.end&&t.column>=d.columns.start&&t.column<=d.columns.end);if(!o){this.cellEditorElement.style.display="none";return}let i=Le(this.selectionState.range),a=r.cellScreenRect(i.startRow,i.startColumn,o),s=r.cellScreenRect(i.endRow,i.endColumn,o),l={x:a.x,y:a.y,width:s.x+s.width-a.x,height:s.y+s.height-a.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 a=Math.max(0,t.height-r.scrollHeight),s=n.verticalAlign==="bottom"?i+a:n.verticalAlign==="middle"?i+a/2:i;r.style.paddingTop=`${s}px`;}async emitChange(){var n,r;if(this.transactionDepth>0){this.transactionChanged=true;return}let t={kind:"workbookChange",bytes:await this.runtime().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 a,s,l,d;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}:${(s=(a=this.editingCell)==null?void 0:a.row)!=null?s:0}:${(d=(l=this.editingCell)==null?void 0:l.column)!=null?d: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);}reportError(t){let n=t instanceof Error?t:new Error(String(t));this.options.onError?this.options.onError(n):console.error("[spreadsheet-editor]",n);}async runSheetUiAction(t){if(!this.sheetActionPending){this.sheetActionPending=true,this.hideContextMenu(),this.hideFilterMenu(),this.renderTabs();try{await this.flushEdits(),await t(),this.host.focus({preventScroll:!0});}catch(n){this.reportError(n);}finally{this.sheetActionPending=false,this.disposed||this.renderTabs();}}}async createSheetFromTabs(){let t=new Set(this.runtime().model().sheets.map(r=>r.name.toLowerCase())),n=1;for(;t.has(`sheet${n}`);)n+=1;await this.addSheet(`Sheet${n}`);}requestSheetDeletion(t,n){this.isReadOnly()||this.sheetActionPending||this.runtime().model().sheets.length<=1||(this.hideContextMenu(),this.hideFilterMenu(),this.sheetDeleteConfirmation.show(n,{title:"\u5220\u9664\u5DE5\u4F5C\u8868\uFF1F",description:t,onConfirm:()=>{this.runSheetUiAction(async()=>{this.isReadOnly()||this.runtime().model().sheets.length<=1||await this.deleteSheet(t);});}}));}renderTabs(){if(!(this.options.showSheetTabs===false||!this.runtimeValue)){this.sheetDeleteConfirmation.hide(false),this.sheetTabs.replaceChildren(),this.sheetTabs.setAttribute("role","group"),this.sheetTabs.setAttribute("aria-label","\u5DE5\u4F5C\u8868"),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=t.name===this.runtimeValue.activeSheetName(),r=document.createElement("button");r.type="button",r.textContent=t.name,r.setAttribute("aria-pressed",String(n)),r.disabled=this.sheetActionPending,r.dataset.active=String(n),Object.assign(r.style,{height:"32px",minWidth:"64px",padding:"0 14px",border:"0",borderTop:n?"2px solid #2563eb":"2px solid transparent",borderRadius:n&&!this.isReadOnly()?"3px 0 0 0":"3px 3px 0 0",background:n?"#ffffff":"transparent",color:n?"#1d4ed8":"#475569",font:"13px Arial, sans-serif",fontWeight:n?"600":"400",cursor:"pointer",whiteSpace:"nowrap"}),r.addEventListener("mouseenter",()=>{r.dataset.active!=="true"&&(r.style.background="#e2e8f0");}),r.addEventListener("mouseleave",()=>{r.dataset.active!=="true"&&(r.style.background="transparent");}),r.addEventListener("click",()=>{this.runSheetUiAction(()=>this.setActiveSheet(t.name));});let o=document.createElement("div");if(Object.assign(o.style,{display:"flex",alignItems:"center",flexShrink:"0"}),o.appendChild(r),n&&!this.isReadOnly()){let i=document.createElement("button"),a=this.runtimeValue.model().sheets.length<=1;i.type="button",i.setAttribute("aria-label",`\u5220\u9664\u5DE5\u4F5C\u8868\u201C${t.name}\u201D`),i.title=a?"\u5DE5\u4F5C\u7C3F\u81F3\u5C11\u4FDD\u7559\u4E00\u5F20\u5DE5\u4F5C\u8868":`\u5220\u9664\u5DE5\u4F5C\u8868\u201C${t.name}\u201D`,i.disabled=this.sheetActionPending||a,i.innerHTML='<svg width="14" height="14" viewBox="0 0 16 16" fill="none" aria-hidden="true"><path d="M2 4h12M6 4V2h4v2M3.5 4l.7 10h7.6l.7-10M6.5 7v4M9.5 7v4" stroke="currentColor" stroke-width="1.3" stroke-linecap="round" stroke-linejoin="round"/></svg>',Object.assign(i.style,{height:"32px",width:"24px",padding:"0",display:"grid",placeItems:"center",border:"0",borderTop:r.style.borderTop,background:r.style.background,borderRadius:"0 3px 0 0",color:"#64748b",cursor:i.disabled?"default":"pointer",opacity:i.disabled?"0.4":"1"}),i.addEventListener("mouseenter",()=>{i.disabled||(i.style.color="#dc2626");}),i.addEventListener("mouseleave",()=>{i.style.color="#64748b";}),i.addEventListener("click",()=>this.requestSheetDeletion(t.name,i)),o.appendChild(i);}this.sheetTabs.appendChild(o);}if(!this.isReadOnly()){let t=document.createElement("button");t.type="button",t.setAttribute("aria-label","\u65B0\u5EFA\u5DE5\u4F5C\u8868"),t.title="\u65B0\u5EFA\u5DE5\u4F5C\u8868",t.disabled=this.sheetActionPending,t.innerHTML='<svg width="18" height="18" viewBox="0 0 20 20" fill="none" aria-hidden="true"><path d="M10 4v12M4 10h12" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/></svg>',Object.assign(t.style,{width:"32px",height:"32px",display:"grid",placeItems:"center",flexShrink:"0",border:"0",borderRadius:"4px",background:"transparent",color:"#475569",cursor:"pointer"}),t.addEventListener("mouseenter",()=>{t.style.background="#e2e8f0";}),t.addEventListener("mouseleave",()=>{t.style.background="transparent";}),t.addEventListener("click",()=>{this.runSheetUiAction(()=>this.createSheetFromTabs());}),this.sheetTabs.appendChild(t);}}}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 a=t.getBoundingClientRect(),s=r?o.clientX-a.left:o.clientY-a.top;this.drag={axis:r?"horizontal":"vertical",pointer:s,thumb:i.thumbStart},t.setPointerCapture(o.pointerId),this.setScroll(r?ea(i,s-i.thumbLength/2):this.scroll.x,r?this.scroll.y:ea(i,s-i.thumbLength/2));}),t.addEventListener("pointermove",o=>{var u;let i=this.drag,a=(u=this.scrollbarState)==null?void 0:u[r?"horizontal":"vertical"];if(!i||!a||i.axis!==(r?"horizontal":"vertical"))return;let s=t.getBoundingClientRect(),l=r?o.clientX-s.left:o.clientY-s.top,d=ea(a,i.thumb+l-i.pointer);this.setScroll(r?d:this.scroll.x,r?this.scroll.y:d);}),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 x0(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 um(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 a;return ((a=i.object)==null?void 0:a.kind)==="chart"&&(!t.relationshipId||i.object.relationshipId===t.relationshipId)})}function y0(e){var o,i;if(((o=e.object)==null?void 0:o.kind)!=="shape")return null;let t=(i=e.object.name)!=null?i:"",n=t.match(/^coco-tianzige-(horizontal|vertical)-/);if(n!=null&&n[1])return {orientation:n[1],dash:"dashed"};if(/^coco-pinyin-guide-/.test(t))return {orientation:"horizontal",dash:"dashed"};let r=t.match(/^coco-(?:tianzige|pinyin)-outline-\d+-(top|bottom|vertical)(?:-|$)/);return r!=null&&r[1]?{orientation:r[1]==="vertical"?"vertical":"horizontal",dash:"solid"}:null}function Ll(e,t){var u,f;if(!t||t.kind==="absolute"||!t.from)return null;let n=na(t.from.column),r=na(t.from.row),o=t.to?na(t.to.column):n+5,i=t.to?na(t.to.row):r+12,a=e.getColumnX(n)+e.emuToCssPixels(t.from.columnOffset),s=e.getRowY(r)+e.emuToCssPixels(t.from.rowOffset),l=e.getColumnX(o)+e.emuToCssPixels((u=t.to)==null?void 0:u.columnOffset),d=e.getRowY(i)+e.emuToCssPixels((f=t.to)==null?void 0:f.rowOffset);return {x:a,y:s,width:Math.max(1,l-a),height:Math.max(1,d-s)}}function Wl(e,t){let n=[];for(let r of t.viewports){if(!S0(r))continue;let o=r.originX,i=r.originY,a=r.originX+r.screenRect.width,s=r.originY+r.screenRect.height,l=Math.max(e.x,o),d=Math.max(e.y,i),u=Math.min(e.x+e.width,a),f=Math.min(e.y+e.height,s);u<=l||f<=d||n.push({x:r.screenRect.x+l-r.originX,y:r.screenRect.y+d-r.originY,width:u-l,height:f-d});}return n}function v0(e,t,n){let r=(a,s)=>{let l=e.columnAt(Math.max(0,a)),d=e.rowAt(Math.max(0,s));return {column:l-1,row:d-1,columnOffset:e.cssPixelsToEmu(a-e.getColumnX(l)),rowOffset:e.cssPixelsToEmu(s-e.getRowY(d))}},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 S0(e){return e.kind==="main"||e.kind==="frozenTop"||e.kind==="frozenLeft"||e.kind==="frozenTopLeft"}function na(e){return Math.max(1,Math.floor(e!=null?e:0)+1)}function k0(e){let t=0;for(let n of e.toUpperCase())t=t*26+n.charCodeAt(0)-64;return t}function C0(e,t){var l,d,u,f,p;let n=t.getContext("2d");if(!n)return 7;let r=(l=e.styles.cellFormats[0])!=null?l:{},o=(u=e.styles.fonts[(d=r.fontId)!=null?d:0])!=null?u:{},i=((f=o.name)==null?void 0:f.trim())||"Arial",a=qt(i,{families:[]});n.save(),n.font=`${o.italic?"italic ":""}${o.bold?"600 ":""}${(p=o.size)!=null?p:11}pt ${a}, Arial, sans-serif`;let s=Math.max(...Array.from("0123456789",b=>n.measureText(b).width));return n.restore(),Number.isFinite(s)&&s>0?s:7}function E0(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?O(v({},e),{endRow:e.endRow+n}):O(v({},e),{endColumn:e.endColumn+r})}function I0(e,t){return !(e.endRow<t.startRow||e.startRow>t.endRow||e.endColumn<t.startColumn||e.startColumn>t.endColumn)}function fm(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,b;let a=o.split(":"),s=(f=a[0])!=null?f:"",l=(p=a[1])!=null?p:s,d=pm(s),u=pm(l);return !d||!u?[]:[{range:Le({startRow:d.row,startColumn:d.column,endRow:u.row,endColumn:u.column}),stroke:(b=n[i%n.length])!=null?b:"#DC2626"}]})}function pm(e){var o,i;let t=e.replace(/\$/g,"").match(/^([A-Z]{1,3})(\d+)$/);if(!t)return null;let n=0;for(let a of (o=t[1])!=null?o:"")n=n*26+a.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 T0={width:9144e3,height:5143500},oa=new Set(["placeholder","textBox","geometricShape","line"]),bm=new WeakMap;function Co(e){var n;let t=(n=e.slideSize)!=null?n:T0;return {size:t,slides:e.slides.map(r=>P0(r,t))}}function P0(e,t){var l,d,u,f,p,b,w,g,h,y;let n=(d=(l=e.layout)==null?void 0:l.shapes)!=null?d:[],o=[...[...((p=(f=(u=e.layout)==null?void 0:u.master)==null?void 0:f.shapes)!=null?p:[]).map(S=>Dl(S,"master")),...n.map(S=>Dl(S,"layout"))].filter(M0),...e.shapes.map(S=>L0(S,e.layout))],i=o.flatMap(wm),a=(y=(w=e.background)!=null?w:(b=e.layout)==null?void 0:b.background)!=null?y:(h=(g=e.layout)==null?void 0:g.master)==null?void 0:h.background,s=a!=null?a:R0(o,t);return O(v({id:e.id,index:e.index,name:e.name,title:e.title,size:t},a?{background:a}:{}),{nodes:i.map((S,k)=>Eo(S,{slideSize:t,index:k,background:a,backgroundFill:s})),groups:o.flatMap(S=>xm(S,{background:a,backgroundFill:s})),source:e})}function R0(e,t){var r;let n=e.find(o=>{var a;let i=ko(o.geometry);return o.kind==="picture"&&!!((a=o.image)!=null&&a.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 Dl(e,t){var n;return O(v({},e),{id:`${t}:${e.id}`,children:(n=e.children)==null?void 0:n.map(r=>Dl(r,t))})}function M0(e){return e.placeholder?false:e.kind==="group"||e.kind==="picture"||e.kind==="geometricShape"||e.kind==="line"||e.kind==="textBox"}function wm(e){var t;return e.kind!=="group"?[e]:((t=e.children)!=null?t:[]).flatMap(n=>wm(ym(e,n)))}function xm(e,t={}){var n;return e.kind!=="group"?[]:[Eo(e,{background:t.background,backgroundFill:t.backgroundFill}),...((n=e.children)!=null?n:[]).map(r=>ym(e,r)).flatMap(r=>xm(r,t))]}function ym(e,t){var I,A,F,L,V;let n=ko(e.geometry),r=(I=e.raw)==null?void 0:I.groupTransform,o=ko(t.geometry),i=(A=r==null?void 0:r.childLeft)!=null?A:n.left,a=(F=r==null?void 0:r.childTop)!=null?F:n.top,s=(r==null?void 0:r.childWidth)||n.width||1,l=(r==null?void 0:r.childHeight)||n.height||1,d=n.width/s,u=n.height/l,f=(o.left-i)*d,p=(o.top-a)*u,b=o.width*d,w=o.height*u,g=n.flipHorizontal?n.left+n.width-f-b:n.left+f,h=n.flipVertical?n.top+n.height-p-w:n.top+p,y=A0({left:g,top:h,width:b,height:w},n),S=vm(((L=n.rotation)!=null?L:0)+((V=o.rotation)!=null?V:0)),k=O(v({},t),{id:`${e.id}:${t.id}`,geometry:O(v({},t.geometry),{left:y.left,top:y.top,width:b,height:w,rotation:S,flipHorizontal:!!n.flipHorizontal!=!!o.flipHorizontal,flipVertical:!!n.flipVertical!=!!o.flipVertical}),children:t.children});return bm.set(k,{parentId:e.id,parentName:e.name,parentBounds:n,parentTransform:{childLeft:i,childTop:a,childWidth:s,childHeight:l}}),k}function A0(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,a=e.top+e.height/2,s=i-r,l=a-o,d=r+s*Math.cos(n)-l*Math.sin(n),u=o+s*Math.sin(n)+l*Math.cos(n);return O(v({},e),{left:d-e.width/2,top:u-e.height/2})}function vm(e){let t=(e%360+360)%360;return t===0?void 0:t}function L0(e,t){if(!e.placeholder)return e;let n=ppt.resolvePptEffectivePlaceholderProperties(e,t);return v(O(v({},e),{placeholder:n.placeholder,geometry:n.geometry,style:n.style}),e.text?{text:O(v({},e.text),{style:n.textStyle,body:n.textBody})}:{})}function Eo(e,t={}){var d,u,f,p,b,w,g,h,y,S,k,I,A,F,L,V,ee;let n=Sm(e),r=n.editText||n.editTextStyle||n.editTableCells||n.editGeometry||n.editShapeStyle,o=e.style,i=((d=e.raw)==null?void 0:d.useBackgroundFill)===true,a=i?void 0:(f=(u=e.style)==null?void 0:u.fillColor)!=null?f:D0(e,t),s=F0((p=e.text)==null?void 0:p.style,{fillColor:a,background:t.background}),l=ko(e.geometry);return O(v({id:e.id,name:e.name,kind:e.kind,bounds:B0(e,l),text:(w=(b=e.text)==null?void 0:b.text)!=null?w:W0(e),textStyle:s,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:(S=e.image)==null?void 0:S.crop,imageFillRect:(k=e.image)==null?void 0:k.fillRect,imageOpacity:(I=e.image)==null?void 0:I.opacity,chart:e.chart,table:e.table,fillColor:a,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:(A=e.raw)==null?void 0:A.presetGeometry,presetAdjustments:(F=e.raw)==null?void 0:F.presetAdjustments,customGeometry:(L=e.raw)==null?void 0:L.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:V0(e),source:e,children:((ee=e.children)!=null?ee:[]).map(fe=>Eo(fe,{background:t.background,backgroundFill:t.backgroundFill}))})}function W0(e){if(e.table)return e.table.values.map(t=>t.join(" ")).join(`
1676
+ `)}function B0(e,t){if(!e.table)return t;let n=mm(e.table.columnWidths),r=mm(e.table.rowHeights);return n===void 0&&r===void 0?t:v(v(v({},t),hm(t.width,n)?{width:n}:{}),hm(t.height,r)?{height:r}:{})}function mm(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 hm(e,t){return t===void 0?false:!Number.isFinite(e)||e<=0?true:t/e>1.15}function D0(e,t){var o;let n=ko(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 F0(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||!H0(n)?e:O(v({},e),{color:"#FFFFFF"})}function H0(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 xP(e){let t=Sm(e);return t.editText||t.editTextStyle||t.editTableCells||t.editGeometry||t.editShapeStyle}function Sm(e){if($0(e))return {select:true,editText:false,editTextStyle:false,editTableCells:false,editGeometry:false,editShapeStyle:false,reason:"Inherited from layout/master",reasons:gm("\u7EE7\u627F\u81EA\u6BCD\u7248/\u7248\u5F0F\uFF0C\u5F53\u524D\u53EA\u652F\u6301\u67E5\u770B")};if(z0(e)){let n=!!e.text&&oa.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:So({editText:n?void 0:ra(e),editTextStyle:n?void 0:ra(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:So({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:So({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=O0(e.kind);return {select:true,editText:false,editTextStyle:false,editTableCells:false,editGeometry:true,editShapeStyle:false,reason:"Limited editor support for this object type",reasons:So({editText:n.text,editTextStyle:n.textStyle,editTableCells:"\u5F53\u524D\u5BF9\u8C61\u4E0D\u662F\u8868\u683C",editShapeStyle:n.shapeStyle})}}let t=!!e.text&&oa.has(e.kind);return oa.has(e.kind)?{select:true,editText:t,editTextStyle:t,editTableCells:false,editGeometry:true,editShapeStyle:true,reasons:So({editText:t?void 0:ra(e),editTextStyle:t?void 0:ra(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:gm("\u5F53\u524D\u5BF9\u8C61\u7C7B\u578B\u6682\u4E0D\u652F\u6301\u5E38\u89C4\u7F16\u8F91")}}function So(e){return Object.fromEntries(Object.entries(e).filter(t=>!!t[1]))}function gm(e){return {editText:e,editTextStyle:e,editTableCells:e,editGeometry:e,editShapeStyle:e}}function ra(e){return e.text?oa.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 O0(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 $0(e){return e.id.startsWith("layout:")||e.id.startsWith("master:")}function z0(e){return e.id.includes(":")}function km(e,t){var b;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),a=n.height/(r.childHeight||n.height||1),s=G0(o.left+o.width/2,o.top+o.height/2,n),l=s.x-o.width/2,d=s.y-o.height/2,u=n.flipHorizontal?n.left+n.width-l-o.width:l-n.left,f=n.flipVertical?n.top+n.height-d-o.height:d-n.top,p={};return t.left!==void 0&&(p.left=u/i+r.childLeft),t.top!==void 0&&(p.top=f/a+r.childTop),t.width!==void 0&&(p.width=o.width/i),t.height!==void 0&&(p.height=o.height/a),t.rotation!==void 0&&(p.rotation=vm(t.rotation-((b=n.rotation)!=null?b:0))),t.flipHorizontal!==void 0&&(p.flipHorizontal=!!n.flipHorizontal!=!!t.flipHorizontal),t.flipVertical!==void 0&&(p.flipVertical=!!n.flipVertical!=!!t.flipVertical),p}function V0(e){return bm.get(e)}function G0(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,a=e-o,s=t-i;return {x:o+a*Math.cos(r)-s*Math.sin(r),y:i+a*Math.sin(r)+s*Math.cos(r)}}function ko(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 fr(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 Io(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 CP(e,t={}){let n=await ppt.Presentation.fromZip(e,{presentationId:t.presentationId,mode:"inline"});return Em(n,t)}async function EP(e,t={}){var r;let n=await ppt.Presentation.fromModel(e,{presentationId:(r=t.presentationId)!=null?r:e.id,mode:"inline"});return Em(n,t)}async function Em(e,t={}){let[n,r,o]=await Promise.all([e.toModel(),j0(e,t),U0(e)]);return {presentation:e,model:n,scene:Co(n),images:r,fonts:o}}async function j0(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 a;let i=await((a=t.resolveImagePreview)==null?void 0:a.call(t,{path:o.path,contentType:o.contentType,bytes:o.bytes}));return [o.path,i!=null?i:{url:URL.createObjectURL(new Blob([Im(o.bytes)],{type:o.contentType})),contentType:o.contentType}]}));return Object.fromEntries(r)}async function U0(e){return typeof Blob=="undefined"||typeof URL=="undefined"||typeof URL.createObjectURL!="function"?[]:(await e.exportFonts()).map(n=>v(v({url:URL.createObjectURL(new Blob([Im(n.bytes)],{type:n.contentType})),contentType:n.contentType,family:n.family},n.weight?{weight:n.weight}:{}),n.style?{style:n.style}:{}))}function Im(e){let t=new Uint8Array(e.byteLength);return t.set(e),t.buffer}var ia=class{constructor(t,n={}){D(this,"presentationValue");D(this,"modelValue");D(this,"sceneValue");D(this,"selectionValue",null);D(this,"revisionValue",0);D(this,"undoStack",[]);D(this,"redoStack",[]);D(this,"textBodyOverrides",new Map);D(this,"maxHistory");D(this,"readOnlyValue");D(this,"changeListeners",new Set);D(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 mn("ppt")}async applySelectionCommand(t){let n=fr(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=Io(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 a,s;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=fr(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=Y0(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&&_0(n)){let l=O(v({},n.textBody),{autoFit:"none",wrap:(s=(a=n.textBody)==null?void 0:a.wrap)!=null?s:"square"});await i.text.setBodyProperties(l),this.textBodyOverrides.set(K0(r.id,n.id),l);}await i.setGeometry(km(n,t.geometry));return}await i.setStyle(t.style);}assertEditableSceneNodeForCommand(t){var o;let n=fr(this.sceneValue,t.slideIdOrIndex);if(!n)throw new Error(`PPT slide not found: ${String(t.slideIdOrIndex)}`);let r=(o=Io(n,t.shapeIdOrName))!=null?o:X0(n,t.shapeIdOrName);if(!r)throw new Error(`PPT shape not found: ${t.shapeIdOrName}`);if(Z0(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 d,u,f,p,b,w,g,h;this.assertEditableSceneNodeForCommand(t);let n=fr(this.sceneValue,t.slideIdOrIndex);if(!n)throw new Error(`PPT slide not found: ${String(t.slideIdOrIndex)}`);let r=Io(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 a={left:typeof r.bounds.left=="number"?r.bounds.left+((u=(d=t.offset)==null?void 0:d.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:(w=(b=t.offset)==null?void 0:b.width)!=null?w:r.bounds.width,height:(h=(g=t.offset)==null?void 0:g.height)!=null?h:r.bounds.height},l=await(await i.duplicate({geometry:a})).toModel();return {kind:"shape",slideId:n.id,shapeId:l.id}}async refreshAfterChange(t){this.modelValue=await this.presentationValue.toModel(),this.sceneValue=Co(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=Co(this.modelValue),this.applyTextBodyOverrides(),n){let i=this.sceneValue.slides.find(a=>a.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(a=>a.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 a=fr(this.sceneValue,o),s=a?Io(a,i):null;!s||!s.text&&!((t=s.textParagraphs)!=null&&t.length)||(s.textBody=v(v({},s.textBody),r));}}};function K0(e,t){return `${e}\0${t}`}function _0(e){var t;return !!(e.capabilities.editGeometry&&q0(e)&&(e.text||(t=e.textParagraphs)!=null&&t.length))}function q0(e){return e.kind==="placeholder"||e.kind==="textBox"||e.kind==="geometricShape"}function X0(e,t){let n=e.source.shapes.find(r=>r.id===t||r.name===t);return n?Eo(n,{slideSize:e.size,background:e.background}):null}function Y0(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 Z0(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 Tm=24e4,To=91440,J0=91440,Fl=4,Pm=7,pr=128,Q0=8,aa=2,ek=2,sa=4;function FP(e,t,n={}){return new $l(e,t,n)}function tk(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 Cn(e,t,n){var d,u,f,p;let r=Math.max(To,(d=n.width)!=null?d:e.width),o=Math.max(To,(u=n.height)!=null?u:e.height),i=Math.min(Tm,r),a=Math.min(Tm,o),s=ha((f=n.left)!=null?f:e.left,-r+i,t.width-i),l=ha((p=n.top)!=null?p:e.top,-o+a,t.height-a);return O(v({},e),{left:s,top:l,width:r,height:o})}function ha(e,t,n){return Math.max(t,Math.min(n,e))}function la(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(!nk(i,t))continue;let a=n==="x"?i.bounds.left:i.bounds.top,s=n==="x"?i.bounds.width:i.bounds.height;o.push({value:a,kind:"shape",role:"start",referenceShapeId:i.id},{value:a+s/2,kind:"shape",role:"center",referenceShapeId:i.id},{value:a+s,kind:"shape",role:"end",referenceShapeId:i.id});}return o}function nk(e,t){return e.id!==t&&e.kind!=="line"&&!e.locked&&!e.id.includes(":")&&e.capabilities.select&&e.capabilities.editGeometry&&e.bounds.width>To&&e.bounds.height>To}function da(e,t,n,r={}){let o=null;for(let i of e)for(let a of t){if(r.matchRole!==false&&i.role!==a.role)continue;let s=Math.abs(i.value-a.value);s>n||(!o||s<o.distance)&&(o={source:i,target:a,distance:s});}return o}function Rm(e,t,n,r){let o=t/2,i=Math.abs(n.offset-o)<1?(r-e)*2:r-e;return Math.max(To,i)}function jn(e){return !e.locked&&!e.id.includes(":")&&(e.capabilities.editGeometry||e.capabilities.editText||e.capabilities.editShapeStyle||e.capabilities.editTableCells)}function rk(e){let t=e.groupContext;return t?O(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 ok(e){var i,a;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=(a=(i=e.customGeometry.paths[0])==null?void 0:i.commands)!=null?a:[];return r.filter(s=>s.kind==="cubicBezierTo").length>=4&&r.some(s=>s.kind==="close")}var $l=class{constructor(t,n,r){D(this,"root");D(this,"sessionValue");D(this,"imageResources");D(this,"fontResources");D(this,"referencedFontFamilies");D(this,"slideList",document.createElement("div"));D(this,"canvas",document.createElement("div"));D(this,"contextMenu",document.createElement("div"));D(this,"snapGuides",document.createElement("div"));D(this,"options");D(this,"handleCanvasClick",()=>{this.dispatchCurrentSlideSelection();});D(this,"handleWindowMouseMove",t=>{this.updateDrag(t);});D(this,"handleWindowMouseUp",t=>{this.finishDrag(t);});D(this,"handleWindowKeyDown",t=>{this.handleKeyDown(t);});D(this,"handleWindowPointerDown",t=>{this.dismissContextMenu(t);});D(this,"handleWindowScroll",()=>this.hideContextMenu());D(this,"handleCanvasSelectStart",t=>this.handleSelectStart(t));D(this,"handleSlideListScroll",()=>this.scheduleThumbnailRender());D(this,"dragState",null);D(this,"suppressClickAfterDrag",false);D(this,"clipboardShape",null);D(this,"thumbnailFrame",0);D(this,"thumbnailRasterEpoch",0);D(this,"thumbnailCanvasCache",new Map);D(this,"pendingCommands",new Set);this.options=r,this.root=r.styleIsolation==="none"?t:t.attachShadow({mode:"open"}),this.sessionValue=new ia(n,{readOnly:r.readOnly}),this.imageResources=n.images,this.fontResources=n.fonts,this.referencedFontFamilies=bk(n);let o=gk(this.fontResources,this.referencedFontFamilies);wk(this.scheduleFontRenderRefresh(o)),this.mount(),this.sessionValue.subscribe("change",async i=>{var a,s;this.thumbnailRasterEpoch++,this.render(),await((s=(a=this.options).onChange)==null?void 0:s.call(a,{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=`
1677
+ ${mk(this.fontResources)}
1624
1678
  :host, .coco-ppt-editor { box-sizing: border-box; width: 100%; height: 100%; min-height: 360px; }
1625
1679
  .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; }
1626
1680
  .coco-ppt-editor[data-show-slide-list="false"] { grid-template-columns: minmax(0, 1fr); }
@@ -1692,7 +1746,7 @@ coco-word-native-table.coco-word-revision-delete {
1692
1746
  .coco-ppt-context-menu button:disabled { color: #94a3b8; cursor: default; }
1693
1747
  .coco-ppt-context-menu span { color: #64748b; font-size: 11px; }
1694
1748
  .coco-ppt-context-menu hr { border: 0; border-top: 1px solid #e2e8f0; margin: 4px 0; }
1695
- `;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(()=>Pr([...this.fontResources.map(n=>n.family),...this.referencedFontFamilies].map(n=>`16px ${Jm(n)}`))).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 a=document.createElement("button");a.className="coco-ppt-thumb",a.type="button",a.dataset.slideId=i.id,a.dataset.slideIndex=String(i.index),a.dataset.selected=((u=this.sessionValue.selection())==null?void 0:u.slideId)===i.id?"true":"false";let s=document.createElement("div");s.className="coco-ppt-thumb-preview";let l=document.createElement("div");l.className="coco-ppt-thumb-placeholder";let d=document.createElement("span");return d.className="coco-ppt-thumb-number",d.textContent=String(i.index+1),a.append(s,l,d),a.addEventListener("click",()=>{this.dispatch({kind:"select-slide",slideIdOrIndex:i.id});}),a})),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=zl(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 a=o.querySelector(".coco-ppt-thumb-preview"),s=o.querySelector(".coco-ppt-thumb-placeholder");if(!a||!s)return;if(i<r.start||i>=r.end){a.replaceChildren(),delete o.dataset.previewRendered,delete o.dataset.previewMode,s.hidden=false;return}if(o.dataset.previewRendered==="true")return;let l=t[i];if(!l)return;let d=Hl(l),u=this.thumbnailCanvasCache.get(l.id);(u==null?void 0:u.fingerprint)===d?(a.replaceChildren(Pm(u.canvas)),o.dataset.previewMode="canvas"):(a.replaceChildren(this.renderThumbnailSlide(l)),o.dataset.previewMode="dom",this.rasterizeThumbnail(o,l)),o.dataset.previewRendered="true",s.hidden=true;});}visibleThumbnailRange(t){let n=ur*.5625+Y0,r=this.slideList.clientHeight||n*Math.min(t,5),o=Math.max(0,Math.floor(this.slideList.scrollTop/n)-ra),i=Math.ceil(r/n)+ra*2,a=this.sessionValue.selection(),s=(a==null?void 0:a.slideId)!==void 0?this.sessionValue.scene().slides.findIndex(u=>u.id===a.slideId):-1,l=s>=0?Math.min(o,Math.max(0,s-ra)):o,d=s>=0?Math.max(o+i,Math.min(t,s+ra+1)):o+i;return {start:l,end:Math.min(t,d)}}renderThumbnailSlide(t){let n=document.createElement("div");n.className="coco-ppt-thumb-slide";let o=ur*oa/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/oa})`,n.style.background=zl(t.background,this.imageResources),n.replaceChildren(...t.nodes.map(i=>this.renderNode(i,o,t,false))),n}async rasterizeThumbnail(t,n){var d,u;let r=this.thumbnailRasterEpoch,o=Hl(n);if(await Tm(),await Tm(),r!==this.thumbnailRasterEpoch||!t.isConnected)return;let i=t.querySelector(".coco-ppt-thumb-preview"),a=i==null?void 0:i.querySelector(".coco-ppt-thumb-slide");if(!i||!a)return;let s=await ik(a,ur,ur*(n.size.height/n.size.width),Z0,(u=(d=this.root.querySelector("style"))==null?void 0:d.textContent)!=null?u:"",ur*oa,ur*oa*(n.size.height/n.size.width));if(!s||r!==this.thumbnailRasterEpoch||!t.isConnected)return;let l=this.sessionValue.scene().slides.find(p=>p.id===n.id);!l||Hl(l)!==o||(this.thumbnailCanvasCache.set(n.id,{fingerprint:o,canvas:s}),i.replaceChildren(Pm(s)),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,S;let i=document.createElement("div"),a=rh(t),s=t.presetGeometry==="frame",l=a?oh(t):"horizontal",d=Math.max(a&&l==="vertical"?12:1,t.bounds.width*n),u=Math.max(a&&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-(a&&l==="vertical"?d/2:0)}px`,i.style.top=`${t.bounds.top*n-(a&&l==="horizontal"?u/2:0)}px`,i.style.width=`${d}px`,i.style.height=`${u}px`;let p=[];t.bounds.rotation&&p.push(`rotate(${t.bounds.rotation}deg)`),t.bounds.flipHorizontal&&p.push("scaleX(-1)"),t.bounds.flipVertical&&p.push("scaleY(-1)"),p.length>0&&(i.style.transform=p.join(" "));let f=sh(t),b=dC(t.presetGeometry),w=!!(b&&t.text&&!t.customGeometry&&!f);if(t.usesBackgroundFill&&t.backgroundFill?nC(i,t.backgroundFill,t,r,n,this.imageResources):t.customGeometry||f||w||t.kind==="table"||a||s?i.style.background="transparent":t.fillGradient&&t.fillGradient.colors.length>1?i.style.background=xr(t.fillGradient,wr(t)):t.fillColor&&(i.style.background=br(t.fillColor,wr(t))),Gk(t)&&(i.style.overflow="visible"),(t.presetGeometry==="roundRect"||t.presetGeometry==="round1Rect")&&(i.style.borderRadius=`${hr(t)*n}px`),t.presetGeometry==="round2DiagRect"){let E=`${hr(t)*n}px`;i.style.borderRadius=`${E} 0 ${E} 0`;}if(t.presetGeometry==="round2SameRect"){let E=`${hr(t)*n}px`;i.style.borderRadius=`${E} ${E} 0 0`;}if((t.presetGeometry==="ellipse"||J0(t)||tk(t))&&(i.style.borderRadius="9999px"),b&&!w&&!f&&(i.style.clipPath=b),s?(i.style.borderStyle="solid",i.style.borderWidth=`${rC(t,n)}px`,t.fillGradient&&t.fillGradient.colors.length>1?(i.style.borderImageSource=xr(t.fillGradient),i.style.borderImageSlice="1"):t.fillColor&&(i.style.borderColor=t.fillColor)):!t.customGeometry&&!f&&!w&&!a&&t.kind!=="picture"&&t.lineColor&&(i.style.borderStyle=Ul(t.lineDash),i.style.borderWidth=`${Math.max(1,((h=t.lineWidth)!=null?h:9525)*n)}px`,i.style.borderColor=br(t.lineColor,t.lineOpacity)),t.shadow&&(i.style.boxShadow=ch(t.shadow,n)),this.applyTextStyle(i,t,n),Wk(i,t,n),w&&b&&i.append(iC(t,n,b)),t.customGeometry&&t.kind!=="picture"&&i.append(kC(t)),f&&i.append(cC(t,n)),a)i.append(TC(t,n));else if(t.kind==="chart")i.append(HC(t));else if(t.kind==="table"){let E=AC(t,n,o);o&&(E.addEventListener("click",N=>{N.stopPropagation(),!this.consumeSuppressedClick()&&(this.notifyTableCellSelection(r,t,N),this.dispatch({kind:"select-shape",slideIdOrIndex:r.id,shapeIdOrName:t.id}));}),E.addEventListener("dblclick",N=>{if(this.isReadOnly())return;let A=Mm(N);if(!A||!t.capabilities.editTableCells)return;N.stopPropagation();let O=Number(A.dataset.row),W=Number(A.dataset.column);!Number.isInteger(O)||!Number.isInteger(W)||this.startTableCellEdit(A,r,t,O,W);})),i.append(E);}else if(t.kind==="picture"){let E=t.imagePath?this.imageResources[t.imagePath]:void 0,N=E==null?void 0:E.url;if(N&&Gl(E.contentType,t.imagePath)){if(wC(t,r))i.append(vC(t,N));else {let A=document.createElement("img");A.src=N,A.alt=(y=t.name)!=null?y:"",Nk(A,t),t.imageOpacity!==void 0&&(A.style.opacity=String(Math.max(0,Math.min(1,t.imageOpacity)))),i.append(A);}t.lineColor&&i.append(NC(t,n));}else i.dataset.unsupportedImage=t.imagePath?"true":"missing",E!=null&&E.contentType&&(i.dataset.imageContentType=E.contentType),t.imagePath&&(i.dataset.imagePath=t.imagePath),i.append(Rk(t,E==null?void 0:E.contentType));}else {let E=(S=t.text)!=null?S:"";if(t.customGeometry||f||w||Ak(t)){let N=document.createElement("div");N.className="coco-ppt-text-layer",Lk(N,t),Dm(N,t,n,E),i.append(N),Fm(N,t),Hm(N,t);}else Dm(i,t,n,E),Fm(i,t),Hm(i,t);}if(oC(t)&&i.append(IC(t,n)),!o)return i;let g=document.createElement("div");return g.className="coco-ppt-resize-handle",g.addEventListener("mousedown",E=>{this.isReadOnly()||!t.capabilities.editGeometry||(E.preventDefault(),E.stopPropagation(),this.startDrag(E,"resize",r,t,n,i));}),i.append(g),i.addEventListener("click",E=>{var A,O;if(this.hideContextMenu(),E.stopPropagation(),this.consumeSuppressedClick())return;if(E.altKey){let W=this.selection(),V=yk(r,E,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}),(O=(A=this.options).onObjectAction)==null||O.call(A,{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,E,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",E=>{var A;if(this.isReadOnly())return;E.preventDefault(),E.stopPropagation();let N=(A=this.pointerOperationNode(r,t,E,n))!=null?A:t;this.dispatch({kind:"select-shape",slideIdOrIndex:r.id,shapeIdOrName:N.id}).then(()=>this.showContextMenu(E,r,N));}),i.addEventListener("mousedown",E=>{var O,W;let N=(O=this.pointerOperationNode(r,t,E,n))!=null?O:t,A=(W=Ol(this.canvas,N.id))!=null?W:i;wk(A,E.target)||this.isReadOnly()||E.button!==0||!N.capabilities.editGeometry||(E.preventDefault(),E.stopPropagation(),this.startDrag(E,"move",r,N,n,A));}),i.addEventListener("dblclick",E=>{var A,O,W;if(this.isReadOnly())return;E.stopPropagation();let N=Wm(r,t,E,n);if(N){this.startTextEdit((A=Ol(this.canvas,N.id))!=null?A:i,r,N);return}if(!t.capabilities.editText){this.sessionValue.dispatch({kind:"select-shape",slideIdOrIndex:r.id,shapeIdOrName:t.id}).then(()=>this.renderSelection()),(W=(O=this.options).onObjectAction)==null||W.call(O,{action:"blocked-text-edit",slideId:r.id,shapeId:t.id,kind:t.kind,name:t.name,reason:kk(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:Wm(t,n,r,o)}notifyTableCellSelection(t,n,r){var s,l;let o=Mm(r);if(!o||!n.capabilities.editTableCells)return;let i=Number(o.dataset.row),a=Number(o.dataset.column);!Number.isInteger(i)||!Number.isInteger(a)||(l=(s=this.options).onTableCellSelectionChange)==null||l.call(s,{slideId:t.id,shapeId:n.id,row:i,column:a,text:jm(o,n,i,a)});}applyTextStyle(t,n,r){var a,s,l,d;let o=n.textStyle;o&&(Vl(t,xk(n,o),r),o.alignment&&(jl(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=(a=i.insetLeft)!=null?a:91440,p=(s=i.insetTop)!=null?s:45720,f=(l=i.insetRight)!=null?l:91440,b=(d=i.insetBottom)!=null?d:45720,w=Bk(n,r);t.style.padding=`${p*r+w}px ${f*r}px ${b*r}px ${u*r}px`,Qm(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 f,b,w,g;if(this.isReadOnly())return;let o=(f=r.text)!=null?f:"",i=gk(t),a=false;this.sessionValue.dispatch({kind:"select-shape",slideIdOrIndex:n.id,shapeIdOrName:r.id}).then(()=>this.renderSelection()),(w=(b=this.options).onTextEditStateChange)==null||w.call(b,{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 s=i.ownerDocument.getSelection();if(s){let h=i.ownerDocument.createRange();h.selectNodeContents(i),h.collapse(false),s.removeAllRanges(),s.addRange(h);}let l=h=>{var S,E,N,A,O;if(a)return;a=true,i.contentEditable="false",i.removeAttribute("role"),i.removeAttribute("aria-label"),delete t.dataset.editing,delete this.canvas.dataset.interactionMode,i.removeEventListener("blur",p),i.removeEventListener("keydown",d),i.removeEventListener("paste",u);let y=(S=i.textContent)!=null?S:"";if(!h){i.textContent=o,(N=(E=this.options).onTextEditStateChange)==null||N.call(E,{state:"cancel",slideId:n.id,shapeId:r.id,text:o}),this.render();return}(O=(A=this.options).onTextEditStateChange)==null||O.call(A,{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();},d=h=>{if(h.key==="Escape"){h.preventDefault(),l(false);return}h.key==="Enter"&&!h.shiftKey&&(h.preventDefault(),l(true));},u=h=>{var S;let y=(S=h.clipboardData)==null?void 0:S.getData("text/plain");y!==void 0&&(h.preventDefault(),Bm(i,y));},p=()=>l(true);i.addEventListener("blur",p),i.addEventListener("keydown",d),i.addEventListener("paste",u);}startTableCellEdit(t,n,r,o,i){var b,w,g;if(this.isReadOnly())return;let a=jm(t,r,o,i),s=false;this.sessionValue.dispatch({kind:"select-shape",slideIdOrIndex:n.id,shapeIdOrName:r.id}).then(()=>this.renderSelection()),(w=(b=this.options).onTableCellSelectionChange)==null||w.call(b,{slideId:n.id,shapeId:r.id,row:o,column:i,text:a}),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=a,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 d=h=>{var S;if(s)return;s=true,t.contentEditable="false",delete this.canvas.dataset.interactionMode,t.removeAttribute("role"),t.removeAttribute("aria-label"),t.removeEventListener("blur",f),t.removeEventListener("keydown",u),t.removeEventListener("paste",p);let y=(S=t.textContent)!=null?S:"";if(!h){t.textContent=a,t.dataset.cellText=a;return}y!==a?(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(),d(false);return}h.key==="Enter"&&!h.shiftKey&&(h.preventDefault(),d(true));},p=h=>{var S;let y=(S=h.clipboardData)==null?void 0:S.getData("text/plain");y!==void 0&&(h.preventDefault(),Bm(t,y));},f=()=>d(true);t.addEventListener("blur",f),t.addEventListener("keydown",u),t.addEventListener("paste",p);}startDrag(t,n,r,o,i,a){this.isReadOnly()||(n==="resize"&&nk(a,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:a,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:s}=t.altKey?{bounds:Cn(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=`${s.left*n.scale}px`,n.element.style.top=`${s.top*n.scale}px`;return}let{bounds:a}=t.altKey?{bounds:Cn(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=`${a.width*n.scale}px`,n.element.style.height=`${a.height*n.scale}px`;}async finishDrag(t){var s,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 a=t.altKey?Cn(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 a?a.bounds:a,preserveTextSizeOnResize:n.mode==="resize"}),"snapped"in a&&a.snapped){let d=this.currentSlide(),u=d==null?void 0:d.nodes.find(p=>p.id===n.shapeId);d&&u&&((l=(s=this.options).onObjectAction)==null||l.call(s,{action:"snap-geometry",slideId:d.id,shapeId:u.id,kind:u.kind,name:u.name,reason:this.snapActionReason(a,d)}));}}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=Cn(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,Im/t.scale),a=aa([{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"}],ia(o,t.shapeId,"x"),i),s=aa([{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"}],ia(o,t.shapeId,"y"),i),l=Cn(t.startBounds,t.slideSize,{left:a?a.target.value-a.source.offset:r.left,top:s?s.target.value-s.source.offset:r.top}),d=[...a?[{axis:"x",value:a.target.value,kind:a.target.kind,referenceShapeId:a.target.referenceShapeId}]:[],...s?[{axis:"y",value:s.target.value,kind:s.target.kind,referenceShapeId:s.target.referenceShapeId}]:[]];return this.renderSnapGuides(d,t.scale),{bounds:l,guides:d,snapped:d.length>0}}snapResizeBounds(t,n){let r=Cn(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,Im/t.scale),a=aa([{offset:r.width/2,value:r.left+r.width/2,role:"center"},{offset:r.width,value:r.left+r.width,role:"end"}],ia(o,t.shapeId,"x"),i,{matchRole:false}),s=aa([{offset:r.height/2,value:r.top+r.height/2,role:"center"},{offset:r.height,value:r.top+r.height,role:"end"}],ia(o,t.shapeId,"y"),i,{matchRole:false}),l=Cn(t.startBounds,t.slideSize,{width:a?Nm(r.left,r.width,a.source,a.target.value):r.width,height:s?Nm(r.top,r.height,s.source,s.target.value):r.height}),d=[...a?[{axis:"x",value:a.target.value,kind:a.target.kind,referenceShapeId:a.target.referenceShapeId}]:[],...s?[{axis:"y",value:s.target.value,kind:s.target.kind,referenceShapeId:s.target.referenceShapeId}]:[]];return this.renderSnapGuides(d,t.scale),{bounds:l,guides:d,snapped:d.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=Ol(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||Lm(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(d=>d.id===n.slideId),o=r==null?void 0:r.nodes.find(d=>d.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(!Vn(o))return;t.preventDefault(),this.deleteSelectedShape(r,o);return}let a=bk(t.key);if(!a||!o.capabilities.editGeometry)return;let s=X0*(t.shiftKey?10:1),l=Cn(o.bounds,r.size,{left:o.bounds.left+a.dx*s,top:o.bounds.top+a.dy*s});t.preventDefault(),this.dispatch({kind:"set-shape-geometry",slideIdOrIndex:r.id,shapeIdOrName:o.id,geometry:{left:l.left,top:l.top}}).then(()=>{var d,u;(u=(d=this.options).onObjectAction)==null||u.call(d,{action:"nudge-geometry",slideId:r.id,shapeId:o.id,kind:o.kind,name:o.name,reason:`\u5DF2\u79FB\u52A8\u5BF9\u8C61 ${a.label}${t.shiftKey?" 10\u6B65":" 1\u6B65"}`});});}handleSelectStart(t){this.isReadOnly()||Lm(t.target)||t.target instanceof HTMLElement&&t.target.closest('[contenteditable="true"]')||t.preventDefault();}copySelectedShape(t,n){var r,o;Vn(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,a;let o=this.selection();(a=(i=this.options).onObjectAction)==null||a.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){Vn(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){Vn(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){Vn(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=Vn(r),i=!!this.clipboardShape,a=u=>()=>{this.hideContextMenu(),u();};this.contextMenu.replaceChildren(fr("\u590D\u5236","Ctrl+C",o,a(()=>this.copySelectedShape(n,r))),fr("\u7C98\u8D34","Ctrl+V",i,a(()=>this.pasteClipboardShape(n,r))),fr("\u91CD\u590D","Ctrl+D",o,a(()=>this.duplicateSelectedShape(n,r))),Am(),fr("\u7F6E\u4E8E\u9876\u5C42","Ctrl+Shift+]",o,a(()=>this.bringSelectedShapeToFront(n,r))),fr("\u7F6E\u4E8E\u5E95\u5C42","Ctrl+Shift+[",o,a(()=>this.sendSelectedShapeToBack(n,r))),Am(),fr("\u5220\u9664","Del",o,a(()=>this.deleteSelectedShape(n,r))));let s=this.root instanceof ShadowRoot?this.root.host.getBoundingClientRect():this.root.getBoundingClientRect(),l=fa(t.clientX,s.left+4,window.innerWidth-170),d=fa(t.clientY,s.top+4,window.innerHeight-220);this.contextMenu.style.left=`${l}px`,this.contextMenu.style.top=`${d}px`,this.contextMenu.dataset.shapeId=r.id,this.contextMenu.dataset.open="true";}deleteSelectedShape(t,n){Vn(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 d,u;if((t==null?void 0:t.kind)!=="shape")return;let n=this.sessionValue.scene().slides.find(p=>p.id===t.slideId),r=(d=n==null?void 0:n.nodes.find(p=>p.id===t.shapeId))!=null?d:n==null?void 0:n.groups.find(p=>p.id===t.shapeId),o=r!=null&&r.groupContext?(u=n==null?void 0:n.groups.find(p=>{var f;return p.id===((f=r.groupContext)==null?void 0:f.parentId)}))!=null?u:ek(r):(r==null?void 0:r.kind)==="group"?r:null;if(!n||!o)return;let i=this.computeScale(n),a=document.createElement("div");a.className="coco-ppt-parent-group-outline",a.dataset.shapeId=o.id,a.dataset.selected=t.shapeId===o.id?"true":"false",a.title=`\u7236\u7EC4\uFF1A${o.name||o.id}`,a.style.left=`${o.bounds.left*i}px`,a.style.top=`${o.bounds.top*i}px`,a.style.width=`${o.bounds.width*i}px`,a.style.height=`${o.bounds.height*i}px`;let s=p=>{p.preventDefault(),p.stopPropagation(),this.startDrag(p,"move",n,o,i,a);};["top","right","bottom","left"].forEach(p=>{let f=document.createElement("div");f.className="coco-ppt-parent-group-edge",f.dataset.edge=p,f.title="\u62D6\u52A8\u7236\u7EC4",f.addEventListener("mousedown",s),a.append(f);});let l=document.createElement("div");l.className="coco-ppt-parent-group-handle",l.title="\u62D6\u52A8\u7236\u7EC4",l.addEventListener("mousedown",s),a.append(l),this.canvas.append(a);}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(a=>a.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 nk(e,t){var r,o;if(!rk(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 rk(e){var t;return !!(e.capabilities.editGeometry&&ok(e)&&(e.text||(t=e.textParagraphs)!=null&&t.length))}function ok(e){return e.kind==="placeholder"||e.kind==="textBox"||e.kind==="geometricShape"}function Tm(){return new Promise(e=>requestAnimationFrame(()=>e()))}async function ik(e,t,n,r,o,i=t,a=n){if(typeof XMLSerializer=="undefined"||typeof Blob=="undefined"||typeof URL=="undefined"||typeof URL.createObjectURL!="function")return null;await ak(e);let s=document.createElement("canvas");s.width=Math.max(1,Math.round(t*r)),s.height=Math.max(1,Math.round(n*r));let l=s.getContext("2d");if(!l)return null;let d=document.createElement("div");d.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),d.style.width=`${i}px`,d.style.height=`${a}px`,d.style.position="relative",d.style.overflow="hidden",d.style.background="#fff";let u=document.createElement("style");u.textContent=o;let p=e.cloneNode(true);await sk(p),p.style.position="relative",p.style.left="0",p.style.top="0",p.style.transform="none",d.append(u,p);let f=new XMLSerializer().serializeToString(d),b=`<svg xmlns="http://www.w3.org/2000/svg" width="${s.width}" height="${s.height}" viewBox="0 0 ${i} ${a}"><foreignObject width="100%" height="100%">${f}</foreignObject></svg>`,w=URL.createObjectURL(new Blob([b],{type:"image/svg+xml;charset=utf-8"}));try{let g=await ck(w);return l.drawImage(g,0,0,s.width,s.height),s}catch(g){return null}finally{URL.revokeObjectURL(w);}}function Pm(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 Hl(e){return JSON.stringify({size:e.size,background:e.background,nodes:e.nodes.map(t=>Xm(t))})}function Xm(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=>Xm(t))}}async function ak(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 sk(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 lk(r).catch(()=>{});o&&n.setAttribute("src",o);}));}async function lk(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 dk(n)}function dk(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 ck(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 uk(e){return e.filter(fk).map(n=>{var a,s;let r=Ek(n.family),o=(a=n.weight)!=null?a:400,i=(s=n.style)!=null?s:"normal";return `@font-face { font-family: ${r}; src: url(${Ik(n.url)}); font-weight: ${o}; font-style: ${i}; }`}).join(`
1696
- `)}function fk(e){return /font\/(ttf|otf|woff|woff2)|application\/font-(sfnt|woff|woff2)/i.test(e.contentType)}function pk(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=Ck(o);if(!i)continue;let a=`coco-ppt-google-font-${o.replace(/[^a-zA-Z0-9_-]/g,"_")}`,s=document.getElementById(a);if(s){r.push(Rm(s));continue}let l=document.createElement("link");l.id=a,l.rel="stylesheet",l.href=i,r.push(Rm(l)),document.head.append(l);}return Promise.all(r).then(()=>{})}function mk(e){let t=new Set,n=o=>{o!=null&&o.trim()&&t.add(o.trim());},r=o=>{var i,a,s,l,d,u,p,f;n((i=o.textStyle)==null?void 0:i.fontFamily);for(let b of (a=o.textParagraphs)!=null?a:[]){n((s=b.style)==null?void 0:s.bulletFontFamily);for(let w of (l=b.runs)!=null?l:[])n((d=w.style)==null?void 0:d.fontFamily);}for(let b of (p=(u=o.table)==null?void 0:u.cellStyles)!=null?p:[])for(let w of b)n((f=w==null?void 0:w.textStyle)==null?void 0:f.fontFamily);for(let b of o.children)r(b);};for(let o of e.scene.slides)for(let i of o.nodes)r(i);return [...t]}function hk(e){globalThis.__cocoPptFontRenderReady=e;}function Rm(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 gk(e){var t;return (t=e.querySelector(".coco-ppt-text-layer"))!=null?t:e}function Mm(e){let t=e.target;return t instanceof HTMLElement?t.closest("td[data-row][data-column]"):null}function fr(e,t,n,r){let o=document.createElement("button");o.type="button",o.disabled=!n;let i=document.createElement("strong");i.textContent=e;let a=document.createElement("span");return a.textContent=t,o.append(i,a),o.addEventListener("click",()=>{o.disabled||r();}),o}function Am(){return document.createElement("hr")}function bk(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 Lm(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 wk(e,t){return e.isContentEditable||t instanceof HTMLElement&&t.isContentEditable?true:!!e.querySelector('[contenteditable="true"]')}function xk(e,t){var s;let n=(s=e.textParagraphs)==null?void 0:s.filter(d=>d.runs.length>0);if(!(n!=null&&n.length)||!nh(e,n))return t;let l=t,{textGradient:r,textFill:o,textOutlineColor:i}=l;return Mn(l,["textGradient","textFill","textOutlineColor"])}function Wm(e,t,n,r){if(t.capabilities.editText||Sk(t))return null;let o=Ym(n,r);if(!o)return null;let i=e.nodes.findIndex(s=>s.id===t.id),a=e.nodes.slice(0,i<0?e.nodes.length:i);for(let s=a.length-1;s>=0;s--){let l=a[s];if(l.capabilities.editText&&Zm(o.x,o.y,l.bounds))return l}return null}function yk(e,t,n,r){let o=vk(e,t,n);if(o.length<2)return null;let a=(Math.max(0,o.findIndex(s=>s.id===r))+1)%o.length;return {node:o[a],index:a,count:o.length}}function vk(e,t,n){let r=Ym(t,n);if(!r)return [];let o=[];for(let i=e.nodes.length-1;i>=0;i--){let a=e.nodes[i];a.capabilities.select&&Zm(r.x,r.y,a.bounds)&&o.push(a);}return o}function Sk(e){return e.kind==="table"||e.kind==="chart"||e.kind==="smartArt"}function Ym(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 Zm(e,t,n){return e>=n.left&&e<=n.left+n.width&&t>=n.top&&t<=n.top+n.height}function Ol(e,t){for(let n of Array.from(e.querySelectorAll(".coco-ppt-node")))if(n.dataset.shapeId===t)return n;return null}function Bm(e,t){var a,s;let n=e.ownerDocument.getSelection();if(!n||n.rangeCount===0){e.textContent=`${(a=e.textContent)!=null?a:""}${t}`;return}let r=n.getRangeAt(0);if(!(e===r.commonAncestorContainer||e.contains(r.commonAncestorContainer))){e.textContent=`${(s=e.textContent)!=null?s:""}${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 kk(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 Ck(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 Jm(e){return qt(e,{families:["Calibri","Microsoft YaHei","Segoe UI"],generic:"sans-serif"})}function Ek(e){return `"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function Ik(e){return `"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function br(e,t){var s;if(t===void 0||t>=1)return e;let n=Math.max(0,Math.min(1,t)),r=(s=e.match(/^#([0-9a-fA-F]{6})$/))==null?void 0:s[1];if(!r)return e;let o=Number.parseInt(r.slice(0,2),16),i=Number.parseInt(r.slice(2,4),16),a=Number.parseInt(r.slice(4,6),16);return `rgba(${o}, ${i}, ${a}, ${n})`}function wr(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 Nk(e,t){if(t.imageFillRect){Pk(e,t);return}Tk(e,t);}function Tk(e,t){var d,u,p,f;let n=t.imageCrop;if(!n)return;let r=(d=n.left)!=null?d:0,o=(u=n.right)!=null?u:0,i=(p=n.top)!=null?p:0,a=(f=n.bottom)!=null?f:0,s=Math.max(.01,1-r-o),l=Math.max(.01,1-i-a);e.style.position="absolute",e.style.left=`${-r/s*100}%`,e.style.top=`${-i/l*100}%`,e.style.width=`${1/s*100}%`,e.style.height=`${1/l*100}%`;}function Pk(e,t){var s,l,d,u;let n=t.imageFillRect;if(!n)return;let r=(s=n.left)!=null?s:0,o=(l=n.right)!=null?l:0,i=(d=n.top)!=null?d:0,a=(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-a)*100}%`;}function Rk(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||Mk(t)||"IMAGE",n.title=e.imagePath?`Unsupported image: ${e.imagePath}`:"Missing image resource",n}function Mk(e){if(e)return e.includes("emf")?"EMF":e.includes("wmf")?"WMF":e.includes("svg")?"SVG":"IMAGE"}function Dm(e,t,n,r){var s,l;let o=(s=t.textParagraphs)==null?void 0:s.filter(d=>d.runs.length>0),i=Qm(t.textBody);if(!(o!=null&&o.length)||!nh(t,o)){!i&&((l=t.textStyle)==null?void 0:l.alignment)==="distributed"&&Array.from(r).length>1?Kk(e,r):e.textContent=r;return}let a=document.createElement("div");a.className="coco-ppt-rich-text",o.forEach(d=>{var f,b,w,g;let u=document.createElement("div");u.className="coco-ppt-paragraph",(f=d.style)!=null&&f.alignment&&jl(u,d.style.alignment),qk(u,d.style,n,{verticalText:i});let p=!i&&((b=d.style)==null?void 0:b.alignment)==="distributed"&&!((w=d.style)!=null&&w.bullet);if(p&&(u.style.display="flex",u.style.justifyContent="space-between",u.style.alignItems="baseline",u.style.width="100%"),(g=d.style)!=null&&g.bullet){u.dataset.bullet="true";let h=document.createElement("span");h.className="coco-ppt-bullet",h.textContent=d.style.bullet,d.style.bulletColor&&(h.style.color=d.style.bulletColor),Yk(h,d.style,n,d.text),u.append(h);}d.runs.forEach((h,y)=>{(p?Array.from(h.text):[h.text]).forEach(E=>{let N=document.createElement("span");N.textContent=E;let A=Qk(t,d,h,y);A&&Vl(N,A,n),u.append(N);});}),a.append(u);}),e.append(a);}function Qm(e){return (e==null?void 0:e.vertical)==="eastAsian"||(e==null?void 0:e.vertical)==="vertical"}function Fm(e,t){var n;((n=t.textBody)==null?void 0:n.wrap)==="none"&&eh(e);}function Hm(e,t){var n,r;((n=t.textBody)==null?void 0:n.autoFit)==="normal"&&(!t.text&&!((r=t.textParagraphs)!=null&&r.length)||(Ok(t)&&!zk(t)&&eh(e),requestAnimationFrame(()=>{var f;if(e.dataset.textResizePreview==="wrap")return;let o=e.clientWidth,i=e.clientHeight;if(o<=0||i<=0)return;let a=e.scrollWidth,s=e.scrollHeight,l=a>o?o/a:1,d=s>i?i/s:1,u=Math.max(.25,Math.min(1,l,d));if(u>=.995)return;let p=(f=e.querySelector(".coco-ppt-rich-text, .coco-ppt-distributed-text"))!=null?f:e;p.dataset.textResizePreview!=="wrap"&&(p.style.transformOrigin=Vk(t),p.style.transform=`scale(${u})`,p.style.width=`${100/u}%`);})));}function Ak(e){var t;return !!((e.text||(t=e.textParagraphs)!=null&&t.length)&&(e.bounds.flipHorizontal||e.bounds.flipVertical))}function Lk(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 eh(e){e.style.whiteSpace="nowrap",e.querySelectorAll(".coco-ppt-rich-text, .coco-ppt-paragraph").forEach(t=>{t.style.whiteSpace="nowrap";});}function Wk(e,t,n){var o,i,a;if(!Fk(t,n))return;let r=((a=(i=(o=t.textStyle)==null?void 0:o.fontSize)!=null?i:ha(t))!=null?a:28)*12700*n;e.style.letterSpacing=`${Math.max(1,Math.min(2.4,r*.035))}px`;}function Bk(e,t){var r,o;if(!Dk(e))return 0;let n=(o=(r=e.textStyle)==null?void 0:r.fontSize)!=null?o:ha(e);return n?n*12700*t*.18:0}function Dk(e){var i,a,s,l,d,u,p,f,b;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=(s=(a=e.textStyle)==null?void 0:a.fontFamily)!=null?s:th(e);if(!t||!/\bCuprum\b/i.test(t))return false;let n=(d=(l=e.textStyle)==null?void 0:l.fontSize)!=null?d:ha(e);if(!n||n<72)return false;let r=(u=e.textParagraphs)==null?void 0:u.filter(w=>{var h;return ((h=w.text)!=null?h:w.runs.map(y=>y.text).join("")).trim().length>0});if(r&&r.length!==1)return false;let o=((b=(f=(p=r==null?void 0:r[0])==null?void 0:p.text)!=null?f:e.text)!=null?b:"").trim();return o.length>=12&&!/[\u3400-\u9fff]/.test(o)}function Fk(e,t){var l,d,u,p,f,b,w,g,h,y,S,E,N,A,O,W,V,ee,pe,oe;if(((l=e.textBody)==null?void 0:l.wrap)!=="square"||Hk(e)||((b=(d=e.textStyle)==null?void 0:d.alignment)!=null?b:(f=(p=(u=e.textParagraphs)==null?void 0:u[0])==null?void 0:p.style)==null?void 0:f.alignment)!=="center")return false;let r=(g=(w=e.textStyle)==null?void 0:w.fontFamily)!=null?g:th(e);if(!r||!/\bJosefin Sans\b/i.test(r))return false;let o=((E=(S=(y=(h=e.textParagraphs)==null?void 0:h[0])==null?void 0:y.text)!=null?S:e.text)!=null?E:"").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=(A=(N=e.textStyle)==null?void 0:N.fontSize)!=null?A:ha(e);if(!i)return false;let a=(oe=(pe=(O=e.textStyle)==null?void 0:O.lineHeight)!=null?pe:(ee=(V=(W=e.textParagraphs)==null?void 0:W[0])==null?void 0:V.style)==null?void 0:ee.lineHeight)!=null?oe:1.2,s=i*12700*t*a;return e.bounds.height*t>=s*1.75}function Hk(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 ha(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 th(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 Ok(e){var r,o,i,a,s,l;let t=(r=e.textParagraphs)==null?void 0:r.filter(d=>d.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=(s=(a=t==null?void 0:t[0])==null?void 0:a.text)!=null?s:e.text)!=null?l:"";return n.length>0&&!n.includes(`
1697
- `)&&!n.includes("\r")}function $k(e){var o,i,a,s,l,d,u,p,f,b;if(((o=e.textBody)==null?void 0:o.wrap)!=="square"||((d=(i=e.textStyle)==null?void 0:i.alignment)!=null?d:(l=(s=(a=e.textParagraphs)==null?void 0:a[0])==null?void 0:s.style)==null?void 0:l.alignment)!=="center")return false;let t=((b=(f=(p=(u=e.textParagraphs)==null?void 0:u[0])==null?void 0:p.text)!=null?f:e.text)!=null?b:"").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 zk(e){var r,o,i,a,s,l,d;if($k(e))return true;if(((r=e.textBody)==null?void 0:r.wrap)!=="square")return false;let t=((s=(a=(i=(o=e.textParagraphs)==null?void 0:o[0])==null?void 0:i.text)!=null?a:e.text)!=null?s:"").trim();return t.length<18?false:((d=(l=t.match(/[\u3400-\u9fff]/g))==null?void 0:l.length)!=null?d:0)>=12?true:/[\s,。;、,.]/.test(t)}function Vk(e){var n,r,o,i,a;let t=(a=(n=e.textStyle)==null?void 0:n.alignment)!=null?a:(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 Gk(e){var t;return e.kind!=="textBox"||!e.text&&!((t=e.textParagraphs)!=null&&t.length)||e.customGeometry||sh(e)||rh(e)?false:!jk(e)&&!Uk(e)}function jk(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 Uk(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 Kk(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 nh(e,t){return t.some(n=>{var r;return !!((r=n.style)!=null&&r.bullet)||_k(n.style)||n.runs.some(o=>!!o.hyperlink||o.style!==void 0&&Jk(o.style,e.textStyle))})}function _k(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 qk(e,t,n,r={}){if(t){if(t.lineHeight!==void 0&&(e.style.lineHeight=String(Xk(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=sa(t.spaceBefore,n)),t.spaceAfter!==void 0&&(e.style.marginLeft=sa(t.spaceAfter,n));return}t.spaceBefore!==void 0&&(e.style.marginTop=sa(t.spaceBefore,n)),t.spaceAfter!==void 0&&(e.style.marginBottom=sa(t.spaceAfter,n));}}function Xk(e){var n;let t=(n=e.lineHeight)!=null?n:1.2;return e.bullet?t*1.15:t}function Yk(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`)),Zk(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 Zk(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 sa(e,t){return e>10?`${e*t}px`:`${e}em`}function Jk(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 Qk(e,t,n,r){var i,a,s,l;if(!eC(e,t,n,r))return Om(n,n.style);let o=tC(t.runs.slice(0,r));return Om(n,H(v({},n.style),{color:(a=(i=n.style)==null?void 0:i.color)!=null?a:"#000000",fontSize:(l=(s=n.style)==null?void 0:s.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 eC(e,t,n,r){var s,l,d;if(r<=0||(s=n.style)!=null&&s.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((d=i[1])!=null?d:"").filter(u=>/[\u3400-\u9fff]/.test(u)).length>2?false:t.runs.slice(0,r).some(u=>{let p=u.style;return (p==null?void 0:p.color)!==void 0||(p==null?void 0:p.fontSize)!==void 0})}function tC(e){var t;for(let n of e)if(((t=n.style)==null?void 0:t.fontSize)!==void 0)return n.style.fontSize}function Vl(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=Jm(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=xr(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=ch(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 jl(e,t){if(t==="distributed"){e.style.textAlign="justify",e.style.textAlignLast="justify";return}e.style.textAlign=t==="justify"?"justify":t;}function rh(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 oh(e){return e.bounds.height>e.bounds.width?"vertical":"horizontal"}function zl(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?xr(e.fillGradient):(n=e==null?void 0:e.fillColor)!=null?n:"#fff"}function nC(e,t,n,r,o,i){if(t!=null&&t.imagePath){let a=i[t.imagePath],s=a==null?void 0:a.url;if(s&&Gl(a.contentType,t.imagePath)){e.style.backgroundImage=`url("${s}")`,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=zl(t,i);}function hr(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 rC(e,t){var o,i,a;let n=(a=(o=e.presetAdjustments)==null?void 0:o.adj)!=null?a:(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 oC(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 iC(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=xr(e.fillGradient,wr(e)):e.fillColor&&(r.style.background=br(e.fillColor,wr(e))),e.lineColor&&(r.style.borderStyle=Ul(e.lineDash),r.style.borderWidth=`${Math.max(1,((o=e.lineWidth)!=null?o:9525)*t)}px`,r.style.borderColor=br(e.lineColor,e.lineOpacity)),r}function xr(e,t=1){return `linear-gradient(${ih(e)}deg, ${sC(e,t).join(", ")})`}function ih(e){return e.angle===void 0?160:aC(e.angle+90)}function aC(e){return (e%360+360)%360}function sC(e,t=1){return lC(e).map(n=>{let r=Math.max(0,Math.min(1,n.opacity*t)),o=r<1?ah(n.color,r):n.color;return n.position===void 0?o:`${o} ${n.position}%`})}function lC(e){return e.colors.map((t,n)=>{var a,s,l,d,u;let r=Kl(t),o=(a=e.positions)==null?void 0:a[n],i=Math.max(0,Math.min(1,(d=(l=(s=e.opacities)==null?void 0:s[n])!=null?l:r==null?void 0:r.opacity)!=null?d: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 ah(e,t){var a;let n=(a=e.match(/^#([0-9a-fA-F]{6})$/))==null?void 0:a[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 dC(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 Ul(e){return e==="dot"||e==="sysDot"?"dotted":e&&e!=="solid"?"dashed":"solid"}function ga(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 sh(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 cC(e,t){var f,b,w;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=uC(e,t,r,o);(e.shadow||i>0)&&(n.style.overflow="visible"),n.setAttribute("viewBox","0 0 100 100"),n.setAttribute("preserveAspectRatio","none");let a=e.fillGradient&&e.fillGradient.colors.length>1?`coco-ppt-preset-gradient-${e.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`:void 0,s=e.lineGradient&&e.lineGradient.colors.length>1?`coco-ppt-preset-line-gradient-${e.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`:void 0;if(a&&e.fillGradient&&Gn(n,a,e.fillGradient),s&&e.lineGradient&&Gn(n,s,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",$m(e)),(e.presetGeometry==="donut"||e.presetGeometry==="blockArc")&&g.setAttribute("fill-rule","evenodd"),g.setAttribute("fill",fC(e)),g.setAttribute("transform",`translate(${pr(i*.38)} ${pr(i)})`),g.setAttribute("stroke","none"),n.append(g);}let l=document.createElementNS("http://www.w3.org/2000/svg","path");l.setAttribute("d",$m(e)),(e.presetGeometry==="donut"||e.presetGeometry==="blockArc")&&l.setAttribute("fill-rule","evenodd");let d=e.lineColor||e.lineGradient?Math.max(.5,((f=e.lineWidth)!=null?f:9525)*t*100/Math.max(r,o)):0;l.setAttribute("fill",e.presetGeometry==="arc"?"none":a?`url(#${a})`:(b=e.fillColor)!=null?b:"none");let u=wr(e);u!==void 0&&e.presetGeometry!=="arc"&&l.setAttribute("fill-opacity",String(u)),l.setAttribute("stroke",s?`url(#${s})`:(w=e.lineColor)!=null?w:"none"),l.setAttribute("stroke-width",String(d)),e.lineOpacity!==void 0&&l.setAttribute("stroke-opacity",String(Math.max(0,Math.min(1,e.lineOpacity))));let p=ga(e.lineDash,d);return p&&l.setAttribute("stroke-dasharray",p),l.setAttribute("stroke-linejoin","round"),e.presetGeometry==="arc"&&(l.setAttribute("stroke-linecap","round"),bC(n,l,e)),n.append(l),n}function uC(e,t,n,r){var a,s;let o=(s=(a=e.threeD)==null?void 0:a.extrusionHeight)!=null?s: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 fC(e){var o,i,a,s,l;let t=(a=(i=(o=e.fillGradient)==null?void 0:o.colors[0])!=null?i:e.fillColor)!=null?a:"#64748B",n=Kl(t),r=((s=e.threeD)==null?void 0:s.material)==="translucentPowder"?.12:.18;return ah(pC((l=n==null?void 0:n.color)!=null?l:t,.8),r)}function pC(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),a=Number.parseInt(r.slice(4,6),16);return `#${gr(o*t)}${gr(i*t)}${gr(a*t)}`}function $m(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 mC(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 gC(e);default:return ""}}function mC(e){var g,h,y,S,E,N;let t=((h=(g=e.presetAdjustments)==null?void 0:g.adj1)!=null?h:0)/6e4,n=((S=(y=e.presetAdjustments)==null?void 0:y.adj2)!=null?S:54e5)/6e4,r=hC(n-t),o=t+r,i=48,a=Math.max(.08,Math.min(.42,((N=(E=e.presetAdjustments)==null?void 0:E.adj3)!=null?N:25e3)/1e5)),s=i*(1-a),l=Io(t,i),d=Io(o,i),u=Io(o,s),p=Io(t,s),f=Math.abs(r)>180?1:0,b=r>=0?1:0,w=b?0:1;return [`M ${l.x.toFixed(3)} ${l.y.toFixed(3)}`,`A ${i} ${i} 0 ${f} ${b} ${d.x.toFixed(3)} ${d.y.toFixed(3)}`,`L ${u.x.toFixed(3)} ${u.y.toFixed(3)}`,`A ${s.toFixed(3)} ${s.toFixed(3)} 0 ${f} ${w} ${p.x.toFixed(3)} ${p.y.toFixed(3)}`,"Z"].join(" ")}function hC(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 gC(e){var s,l,d,u,p,f,b,w;let t=zm((l=(s=e.presetAdjustments)==null?void 0:s.adj1)!=null?l:18e6),n=zm((u=(d=e.presetAdjustments)==null?void 0:d.adj2)!=null?u:0),r=((f=(p=e.presetAdjustments)==null?void 0:p.adj1)!=null?f:18e6)/6e4,a=((((w=(b=e.presetAdjustments)==null?void 0:b.adj2)!=null?w:0)/6e4-r)%360+360)%360>180?1:0;return `M ${t.x.toFixed(3)} ${t.y.toFixed(3)} A 48 48 0 ${a} 1 ${n.x.toFixed(3)} ${n.y.toFixed(3)}`}function zm(e){return Io(e/6e4,48)}function Io(e,t){let n=e/180*Math.PI;return {x:50+t*Math.cos(n),y:50+t*Math.sin(n)}}function bC(e,t,n){var a,s;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",(s=(a=n.lineColor)!=null?a:n.fillColor)!=null?s:"#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 wC(e,t){if(!e.customGeometry||xC(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 xC(e){var s,l;if(e.paths.length!==1)return false;let t=e.paths[0];if(!t)return false;let n=(s=t.width)!=null?s:0,r=(l=t.height)!=null?l:0;if(n<=0||r<=0)return false;let o=[];for(let d of t.commands)if(d.kind==="moveTo"||d.kind==="lineTo")o.push({x:d.x,y:d.y});else if(d.kind!=="close")return false;let i=yC(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(d=>i.some(u=>pa(u.x,d.x)&&pa(u.y,d.y)))}function yC(e){let t=[];for(let n of e)t.some(r=>pa(r.x,n.x)&&pa(r.y,n.y))||t.push(n);return t}function pa(e,t){return Math.abs(e-t)<=1}function vC(e,t){var u,p,f,b,w,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,(f=(p=(u=e.customGeometry)==null?void 0:u.paths[0])==null?void 0:p.width)!=null?f:e.bounds.width),o=Math.max(1,(g=(w=(b=e.customGeometry)==null?void 0:b.paths[0])==null?void 0:w.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,"_")}`,a=document.createElementNS("http://www.w3.org/2000/svg","defs"),s=document.createElementNS("http://www.w3.org/2000/svg","clipPath");s.setAttribute("id",i);for(let S of (y=(h=e.customGeometry)==null?void 0:h.paths)!=null?y:[]){let E=document.createElementNS("http://www.w3.org/2000/svg","path");E.setAttribute("d",dh(S.commands)),lh(S.commands)&&E.setAttribute("fill-rule","evenodd"),s.append(E);}a.append(s),n.append(a);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 d=SC(e,r,o);return l.setAttribute("x",String(d.x)),l.setAttribute("y",String(d.y)),l.setAttribute("width",String(d.width)),l.setAttribute("height",String(d.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 SC(e,t,n){var u,p,f,b,w,g,h,y;if(e.imageFillRect){let S=(u=e.imageFillRect.left)!=null?u:0,E=(p=e.imageFillRect.right)!=null?p:0,N=(f=e.imageFillRect.top)!=null?f:0,A=(b=e.imageFillRect.bottom)!=null?b:0;return {x:S*t,y:N*n,width:Math.max(.01,1-S-E)*t,height:Math.max(.01,1-N-A)*n}}let r=e.imageCrop;if(!r)return {x:0,y:0,width:t,height:n};let o=(w=r.left)!=null?w:0,i=(g=r.right)!=null?g:0,a=(h=r.top)!=null?h:0,s=(y=r.bottom)!=null?y:0,l=Math.max(.01,1-o-i),d=Math.max(.01,1-a-s);return {x:-o/l*t,y:-a/d*n,width:1/l*t,height:1/d*n}}function kC(e,t){var s,l,d,u,p,f,b,w,g,h;let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.classList.add("coco-ppt-custom-geometry");let r=(d=(l=(s=e.customGeometry)==null?void 0:s.paths[0])==null?void 0:l.width)!=null?d:e.bounds.width,o=(f=(p=(u=e.customGeometry)==null?void 0:u.paths[0])==null?void 0:p.height)!=null?f: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,a=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&&Gn(n,i,e.fillGradient),a&&e.lineGradient&&Gn(n,a,e.lineGradient);for(let y of (w=(b=e.customGeometry)==null?void 0:b.paths)!=null?w:[]){let S=EC(e,y),E=CC(y),N=E?document.createElementNS("http://www.w3.org/2000/svg","ellipse"):document.createElementNS("http://www.w3.org/2000/svg","path");E?(N.setAttribute("cx",String(E.cx)),N.setAttribute("cy",String(E.cy)),N.setAttribute("rx",String(E.rx)),N.setAttribute("ry",String(E.ry))):(N.setAttribute("d",dh(y.commands)),lh(y.commands)&&N.setAttribute("fill-rule","evenodd"));let A=!(e.kind==="line"&&e.lineDash);N.setAttribute("fill",A?i?`url(#${i})`:(g=e.fillColor)!=null?g:"none":"none");let O=wr(e);A&&O!==void 0&&N.setAttribute("fill-opacity",String(O)),N.setAttribute("stroke",a?`url(#${a})`:(h=e.lineColor)!=null?h:"none"),N.setAttribute("stroke-width",String(S)),e.lineOpacity!==void 0&&N.setAttribute("stroke-opacity",String(Math.max(0,Math.min(1,e.lineOpacity))));let W=ga(e.lineDash,S);W&&N.setAttribute("stroke-dasharray",W),N.setAttribute("stroke-linejoin","round"),N.setAttribute("stroke-linecap","round"),n.append(N);}return n}function CC(e){var u,p,f,b,w,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"||((p=r[1])==null?void 0:p.kind)!=="cubicBezierTo"||((f=r[2])==null?void 0:f.kind)!=="cubicBezierTo"||((b=r[3])==null?void 0:b.kind)!=="cubicBezierTo"||((w=r[4])==null?void 0:w.kind)!=="cubicBezierTo"||((g=r[5])==null?void 0:g.kind)!=="close")return;let o=t/2,i=n/2,a=[r[0],r[1],r[2],r[3],r[4]],s=[{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 a.every((h,y)=>h.kind!=="moveTo"&&h.kind!=="cubicBezierTo"?false:Math.abs(h.x-s[y].x)<=l&&Math.abs(h.y-s[y].y)<=l)?{cx:o,cy:i,rx:t/2,ry:n/2}:void 0}function lh(e){return e.filter(t=>t.kind==="moveTo").length>1}function EC(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(a=>a!==void 0&&Number.isFinite(a)&&a>0),i=o.length>0?Math.max(...o):1;return Math.max(.5,e.lineWidth*i)}function IC(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),a=i/2,s=`coco-ppt-line-gradient-${e.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`;n.setAttribute("viewBox",`0 0 ${r} ${o}`),n.setAttribute("preserveAspectRatio","none"),Gn(n,s,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-a))),l.setAttribute("ry",String(Math.max(0,o/2-a)))):(l.setAttribute("x",String(a)),l.setAttribute("y",String(a)),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,hr(e)*t-a))),l.setAttribute("ry",String(Math.max(0,hr(e)*t-a)))),l.setAttribute("fill","none"),l.setAttribute("stroke",`url(#${s})`),l.setAttribute("stroke-width",String(i)),e.lineOpacity!==void 0&&l.setAttribute("stroke-opacity",String(Math.max(0,Math.min(1,e.lineOpacity))));let d=ga(e.lineDash,i);return d&&l.setAttribute("stroke-dasharray",d),n.append(l),n}function NC(e,t){var u,p;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),a=e.kind!=="picture",s=a?i/2:0;a||(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-s))),l.setAttribute("ry",String(Math.max(0,o/2-s)));else {l.setAttribute("x",String(s)),l.setAttribute("y",String(s)),l.setAttribute("width",String(Math.max(0,r-s*2))),l.setAttribute("height",String(Math.max(0,o-s*2)));let f=e.presetGeometry==="roundRect"||e.presetGeometry==="round1Rect"?Math.max(0,hr(e)*t-s):0;l.setAttribute("rx",String(f)),l.setAttribute("ry",String(f));}l.setAttribute("fill","none"),l.setAttribute("stroke",(p=e.lineColor)!=null?p:"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 d=ga(e.lineDash,i);return d&&l.setAttribute("stroke-dasharray",d),n.append(l),n}function TC(e,t){var w,g;let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.classList.add("coco-ppt-line-geometry");let r=oh(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 a=Math.max(1,((w=e.lineWidth)!=null?w:9525)*t),s=e.lineGradient&&e.lineGradient.colors.length>1?`coco-ppt-connector-gradient-${e.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`:void 0;s&&e.lineGradient&&Gn(n,s,e.lineGradient);let l=s?`url(#${s})`:br((g=e.lineColor)!=null?g:"#000000",e.lineOpacity),d=PC(a),u=Math.max(5,a*3.2),p=Math.max(5,a*2.6),f=Vm(e.lineHeadEnd),b=Vm(e.lineTailEnd);if(r){let h=o/2,y=f?Math.min(i,u):0,S=b?Math.max(0,i-u):i;yr(n,h,y,h,S,l,a,e.lineOpacity,e.lineCap),e.lineHeadEnd==="oval"&&En(n,h,0,d,l),e.lineTailEnd==="oval"&&En(n,h,i,d,l),f&&ca(n,h,0,"up",u,p,l,e.lineOpacity),b&&ca(n,h,i,"down",u,p,l,e.lineOpacity);}else {let h=i/2,y=f?Math.min(o,u):0,S=b?Math.max(0,o-u):o;yr(n,y,h,S,h,l,a,e.lineOpacity,e.lineCap),e.lineHeadEnd==="oval"&&En(n,0,h,d,l),e.lineTailEnd==="oval"&&En(n,o,h,d,l),f&&ca(n,0,h,"left",u,p,l,e.lineOpacity),b&&ca(n,o,h,"right",u,p,l,e.lineOpacity);}return n}function PC(e){return Math.max(3,e*3)}function Vm(e){return e==="arrow"||e==="triangle"}function dh(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=RC(r,n);o&&(t.push(o.path),n=o.end);}else t.push("Z");return t.join(" ")}function RC(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=Gm(e.wR,e.hR,n),a={x:t.x-i.x,y:t.y-i.y},s=Gm(e.wR,e.hR,o),l={x:a.x+s.x,y:a.y+s.y},d=Math.abs(r)>180?1:0,u=r>=0?1:0;return {path:`A ${pr(e.wR)} ${pr(e.hR)} 0 ${d} ${u} ${pr(l.x)} ${pr(l.y)}`,end:l}}function Gm(e,t,n){let r=n/180*Math.PI;return {x:e*Math.cos(r),y:t*Math.sin(r)}}function pr(e){return Number.isInteger(e)?String(e):e.toFixed(3).replace(/\.?0+$/,"")}function Gn(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,a=Array.isArray(n)?void 0:n.opacities,s=document.createElementNS("http://www.w3.org/2000/svg","linearGradient"),l=Array.isArray(n)?{x1:0,y1:0,x2:100,y2:100}:MC(ih(n));s.setAttribute("id",t),s.setAttribute("x1",`${l.x1}%`),s.setAttribute("y1",`${l.y1}%`),s.setAttribute("x2",`${l.x2}%`),s.setAttribute("y2",`${l.y2}%`),o.map((d,u)=>{var w,g,h,y;let p=(w=i==null?void 0:i[u])!=null?w:u/Math.max(1,o.length-1)*100,f=Kl(d),b=Math.max(0,Math.min(1,(h=(g=a==null?void 0:a[u])!=null?g:f==null?void 0:f.opacity)!=null?h:1));return {color:(y=f==null?void 0:f.color)!=null?y:d,offset:Math.max(0,Math.min(100,p)),opacity:b}}).sort((d,u)=>d.offset-u.offset).forEach(d=>{let u=document.createElementNS("http://www.w3.org/2000/svg","stop");u.setAttribute("offset",`${d.offset}%`),u.setAttribute("stop-color",d.color),d.opacity<1&&u.setAttribute("stop-opacity",String(d.opacity)),s.append(u);}),r.append(s),e.append(r);}function MC(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:la(50-n*o),y1:la(50-r*o),x2:la(50+n*o),y2:la(50+r*o)}}function la(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:`#${gr(n)}${gr(r)}${gr(o)}`,opacity:i}}function gr(e){return Math.round(e).toString(16).padStart(2,"0").toUpperCase()}function AC(e,t,n=true){var d,u,p,f,b,w,g,h,y,S,E,N,A,O,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),a=Math.max(o.columnCount,...o.values.map(V=>V.length),1),s=(u=(d=o.columnWidths)==null?void 0:d.reduce((V,ee)=>V+ee,0))!=null?u:0;if(s>0){let V=document.createElement("colgroup");for(let ee=0;ee<a;ee++){let pe=document.createElement("col"),oe=(p=o.columnWidths)==null?void 0:p[ee];oe&&(pe.style.width=`${oe/s*100}%`),V.append(pe);}r.append(V);}let l=(b=(f=o.rowHeights)==null?void 0:f.reduce((V,ee)=>V+ee,0))!=null?b:0;for(let V=0;V<i;V++){let ee=document.createElement("tr"),pe=(w=o.rowHeights)==null?void 0:w[V];ee.style.height=l>0&&pe?`${pe/l*100}%`:`${100/i}%`;for(let oe=0;oe<a;oe++){let we=FC(o,V,oe);if(we!=null&&we.hMerge||we!=null&&we.vMerge)continue;let me=document.createElement("td"),_=(h=(g=o.cellStyles)==null?void 0:g[V])==null?void 0:h[oe];n&&(me.dataset.row=String(V),me.dataset.column=String(oe));let te=(S=(y=o.values[V])==null?void 0:y[oe])!=null?S:"";if(me.dataset.cellText=te,WC(me,te),we!=null&&we.columnSpan&&we.columnSpan>1&&(me.colSpan=we.columnSpan),we!=null&&we.rowSpan&&we.rowSpan>1&&(me.rowSpan=we.rowSpan),_!=null&&_.fillGradient&&_.fillGradient.colors.length>1?me.style.background=xr(_.fillGradient):_!=null&&_.fillColor&&!BC(_.fillColor)&&(me.style.background=_.fillColor),_!=null&&_.body){let D=_.body,G=(E=D.insetLeft)!=null?E:91440,$=(N=D.insetTop)!=null?N:45720,U=(A=D.insetRight)!=null?A:91440,X=(O=D.insetBottom)!=null?O:45720;me.style.padding=`${$*t}px ${U*t}px ${X*t}px ${G*t}px`,D.anchor==="middle"&&(me.style.verticalAlign="middle"),D.anchor==="bottom"&&(me.style.verticalAlign="bottom"),D.anchor==="top"&&(me.style.verticalAlign="top");}_!=null&&_.textStyle&&Vl(me,_.textStyle,t),(W=_==null?void 0:_.textStyle)!=null&&W.alignment&&jl(me,_.textStyle.alignment),LC(me,_,t),ee.append(me);}r.append(ee);}return r}function LC(e,t,n){let r=t==null?void 0:t.borders;r&&(da(e,"Left",r.left,n),da(e,"Right",r.right,n),da(e,"Top",r.top,n),da(e,"Bottom",r.bottom,n));}function da(e,t,n,r){var s,l;if(!n)return;let o=`border${t}Style`,i=`border${t}Width`,a=`border${t}Color`;if(n.hidden){e.style[o]="none",e.style[i]="0";return}e.style[o]=Ul(n.dash),e.style[i]=`${Math.max(1,((s=n.width)!=null?s:9525)*r)}px`,e.style[a]=br((l=n.color)!=null?l:"#94A3B8",n.opacity);}function WC(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 jm(e,t,n,r){var o,i,a,s,l;return (l=(s=(a=e.dataset.cellText)!=null?a:(i=(o=t.table)==null?void 0:o.values[n])==null?void 0:i[r])!=null?s:e.textContent)!=null?l:""}function BC(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 ch(e,t){var s,l,d;let n=((s=e.distance)!=null?s:0)*t,r=((l=e.direction)!=null?l:0)*Math.PI/180,o=Math.cos(r)*n,i=Math.sin(r)*n,a=((d=e.blur)!=null?d:0)*t;return `${o}px ${i}px ${a}px ${DC(e)}`}function DC(e){var l,d;let t=(l=e.color)!=null?l:"#000000",n=(d=e.opacity)!=null?d:.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),a=Number.parseInt(o.slice(2,4),16),s=Number.parseInt(o.slice(4,6),16);return `rgba(${i}, ${a}, ${s}, ${Math.max(0,Math.min(1,n))})`}function FC(e,t,n){var r;return (r=e.mergedCells)==null?void 0:r.find(o=>o.row===t&&o.column===n)}function HC(e){var h,y,S,E,N,A,O,W,V,ee,pe,oe,we,me,_,te;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 St(t,(y=e.name)!=null?y:"Chart",4,8,4,"#17202a"),t;let r=(E=(S=e.chart)==null?void 0:S.type)!=null?E:"",o=(N=e.chart)==null?void 0:N.grouping,i=OC(n.series,r,o),a=Math.max(...i,1),s=Math.min(...i,0),l=(O=(A=e.chart)==null?void 0:A.axes)==null?void 0:O.value,d=(V=(W=e.chart)==null?void 0:W.axes)==null?void 0:V.category,u=(ee=l==null?void 0:l.min)!=null?ee:s>=0?0:s,p=(pe=l==null?void 0:l.max)!=null?pe:s>=0?VC(a):a,f=$C(e),b=GC(u,p,l==null?void 0:l.majorUnit);if(r.includes("doughnut")||r.includes("pie"))return tE(t,n.series,f),t;if(r.includes("radar"))return iE(t,n.series,f,(oe=l==null?void 0:l.max)!=null?oe:a),t;(l==null?void 0:l.majorGridlines)!==false&&KC(t,f,b,e,l,d),(l==null?void 0:l.deleted)!==true&&(l==null?void 0:l.tickLabelPosition)!=="none"&&_C(t,f,u,p,b),jC(t,e,f);let w=n.series.filter(D=>{var G,$,U;return ((U=($=D.type)!=null?$:(G=e.chart)==null?void 0:G.type)!=null?U:"").includes("bar")}),g=n.series.filter(D=>{var G;return ((G=D.type)!=null?G:"").includes("line")});return w.length>0?(YC(t,w,f,u,p,e,o),_m(t,(me=(we=w[0])==null?void 0:we.categories)!=null?me:[],f),w.some(D=>D.showValueLabels)&&eE(t,w,f,u,p),g.length>0&&Um(t,g,f,u,p,void 0,e),g.some(D=>D.showValueLabels)&&qm(t,g,f,u,p)):(Um(t,n.series,f,u,p,["#22C7F2","#22C7F2","#94A3B8","#F59E0B"],e),_m(t,(te=(_=n.series.find(D=>{var G;return (G=D.categories)==null?void 0:G.length}))==null?void 0:_.categories)!=null?te:[],f),n.series.some(D=>D.showValueLabels)&&qm(t,n.series,f,u,p)),t}function OC(e,t,n){var a;let r=e.filter(s=>{var l;return ((l=s.type)!=null?l:t).includes("bar")});if(!fh(n)||r.length<=1)return e.flatMap(s=>s.values);let o=Math.max(...r.map(s=>s.values.length),1),i=[];for(let s=0;s<o;s++){let l=0,d=0;for(let u of r){let p=(a=u.values[s])!=null?a:0;p>=0?l+=p:d+=p;}i.push(l,d);}return i}function $C(e){var u,p,f,b,w,g,h,y,S,E,N,A,O,W,V,ee;let t=(u=e.chart)==null?void 0:u.plotLayout,n=(f=(p=e.chart)==null?void 0:p.type)!=null?f:"";if(!t)return ph((g=(w=(b=e.chart)==null?void 0:b.data)==null?void 0:w.series)!=null?g:[])?{left:7,top:8,width:88,height:40}:zC(e)?{left:18,top:8,width:72,height:40}:((S=(y=(h=e.chart)==null?void 0:h.axes)==null?void 0:y.value)==null?void 0:S.deleted)===true?{left:6,top:8,width:90,height:40}:{left:18,top:8,width:76,height:40};let o=((A=(N=(E=e.chart)==null?void 0:E.axes)==null?void 0:N.value)==null?void 0:A.deleted)!==true&&!n.includes("doughnut")&&!n.includes("pie")&&!n.includes("radar")?14:4,i=((O=t.x)!=null?O:.12)*100,a=((W=t.y)!=null?W:.13)*60,s=((V=t.width)!=null?V:.82)*100,l=((ee=t.height)!=null?ee:.67)*60,d=Math.max(o,Math.min(20,i));return {left:d,top:Math.max(3,Math.min(12,a)),width:Math.max(40,Math.min(92,Math.min(s,96-d))),height:Math.max(24,Math.min(50,l))}}function zC(e){var i,a,s,l,d,u,p,f;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=(s=(a=t.data)==null?void 0:a.series)!=null?s:[];if(r.length!==1)return false;let o=Math.max((u=(d=(l=r[0])==null?void 0:l.categories)==null?void 0:d.length)!=null?u:0,(f=(p=r[0])==null?void 0:p.values.length)!=null?f:0);return o>0&&o<=2}function VC(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 GC(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 jC(e,t,n){var d,u,p,f,b,w,g;let r=(f=(d=t.chart)==null?void 0:d.title)!=null?f:(p=(u=t.chart)==null?void 0:u.data)==null?void 0:p.title;r&&St(e,r,n.left+n.width*.5,Math.max(4,n.top-3.2),3.1,"#17202A","middle");let o=(g=(w=(b=t.chart)==null?void 0:b.data)==null?void 0:w.series)!=null?g:[],i=o.map(h=>h.name).filter(h=>!!h).slice(0,4);if(i.length===0)return;let a=["#C50D13","#0EA5E9","#F59E0B","#A3E635"],s=n.left+n.width*.78,l=Math.max(4,n.top-2.4);i.forEach((h,y)=>{var N,A,O,W,V,ee;let S=(N=o.find(pe=>pe.name===h))!=null?N:o[y],E=S?UC(e,S,y,a):a[y];S&&((A=S.type)!=null?A:"").includes("line")?(yr(e,s,l-1.1,s+2.3,l-1.1,E,.45),En(e,s+1.15,l-1.1,.45,(W=(O=S.marker)==null?void 0:O.fillColor)!=null?W:"#FFFFFF",(ee=(V=S.marker)==null?void 0:V.lineColor)!=null?ee:E,.32),St(e,h,s+2.8,l-.45,2.2,"#64748B")):(To(e,s,l-1.8,1.4,1.4,E),St(e,h,s+2,l-.45,2.2,"#64748B")),s+=Math.max(9,Array.from(h).length*2.2+4.5);});}function UC(e,t,n,r){var o,i;return ((o=t.type)!=null?o:"").includes("line")?(i=t.lineColor)!=null?i:r[n]:ba(e,t,n,r)}function KC(e,t,n,r,o,i){var l,d;let a=(l=o==null?void 0:o.gridlineColor)!=null?l:"#E8EDF3",s=Km(o==null?void 0:o.gridlineWidth,r,.35);for(let u=0;u<=n;u++){let p=t.top+t.height/n*u;yr(e,t.left,p,t.left+t.width,p,a,s);}yr(e,t.left,t.top+t.height,t.left+t.width,t.top+t.height,(d=i==null?void 0:i.lineColor)!=null?d:"#CBD5E1",Km(i==null?void 0:i.lineWidth,r,.45));}function _C(e,t,n,r,o){for(let i=0;i<=o;i++){let a=r-(r-n)/o*i,s=t.top+t.height/o*i+1;St(e,_l(a),t.left-1.8,s,3,"#9AA6B2","end");}}function _l(e){return Number.isInteger(e)?String(e):e.toFixed(1).replace(/\.0$/,"")}function Um(e,t,n,r,o,i=["#CBD5E1","#94A3B8","#F59E0B","#A3E635"],a){t.forEach((s,l)=>{var f,b,w,g,h,y,S;if(s.values.length===0)return;let d=s.values.map((E,N)=>{let A=n.left+(s.values.length===1?n.width/2:n.width*N/(s.values.length-1)),O=n.top+n.height-(E-r)/Math.max(1,o-r)*n.height;return {x:A,y:O}}),u=XC(d,s.smooth===true),p=(f=s.lineColor)!=null?f:i[l%i.length];if(gh(e,u,p,uh(s,a)),((b=s.marker)==null?void 0:b.symbol)!=="none"){let E=Math.max(.5,Math.min(1.6,((g=(w=s.marker)==null?void 0:w.size)!=null?g:5)*.18)),N=(y=(h=s.marker)==null?void 0:h.fillColor)!=null?y:p,A=(S=s.marker)==null?void 0:S.lineColor,O=qC(s,a);d.forEach(W=>En(e,W.x,W.y,E,N,A,O));}});}function qC(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 uh(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 XC(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],a=e[r+1],s=e[Math.min(e.length-1,r+2)],l={x:i.x+(a.x-o.x)/6,y:i.y+(a.y-o.y)/6},d={x:a.x-(s.x-i.x)/6,y:a.y-(s.y-i.y)/6};n.push(`C ${l.x} ${l.y} ${d.x} ${d.y} ${a.x} ${a.y}`);}return n.join(" ")}function YC(e,t,n,r,o,i,a){if(fh(a)&&t.length>1){JC(e,t,n,r,o,i);return}if(ph(t)){ZC(e,t,n,r,o,i);return}let s=["#C50D13","#0EA5E9","#F59E0B","#A3E635"],l=Math.max(...t.map(p=>p.values.length),1),d=n.width/l,u=Math.max(1,d*.48/Math.max(t.length,1));t.forEach((p,f)=>{let b=ba(e,p,f,s);p.values.forEach((w,g)=>{var E,N;let h=(w-r)/Math.max(1,o-r)*n.height,y=n.left+g*d+(d-u*t.length)/2+f*u,S=n.top+n.height-h;To(e,y,S,u,h,(N=(E=p.pointColors)==null?void 0:E[g])!=null?N:b,p.borderColor,ql(p,i));});});}function ZC(e,t,n,r,o,i){let a=["#C50D13","#0EA5E9","#F59E0B","#A3E635"],s=Math.max(...t.map(u=>u.values.length),1),l=n.width/s,d=Math.max(1,l*.34);t.forEach((u,p)=>{let f=ba(e,u,p,a);u.values.forEach((b,w)=>{var S,E;let g=ma(b,n,r,o),h=ma(0,n,r,o),y=n.left+w*l+(l-d)/2;To(e,y,Math.min(g,h),d,Math.max(.1,Math.abs(h-g)),(E=(S=u.pointColors)==null?void 0:S[w])!=null?E:f,u.borderColor,ql(u,i));});});}function JC(e,t,n,r,o,i){let a=["#C50D13","#0EA5E9","#F59E0B","#A3E635"],s=Math.max(...t.map(f=>f.values.length),1),l=n.width/s,d=Math.max(1,l*.46),u=new Array(s).fill(Math.max(0,r)),p=new Array(s).fill(Math.min(0,o));t.forEach((f,b)=>{let w=ba(e,f,b,a);f.values.forEach((g,h)=>{var O,W;let y=g>=0?u[h]:p[h],S=y+g,E=ma(y,n,r,o),N=ma(S,n,r,o),A=n.left+h*l+(l-d)/2;To(e,A,Math.min(E,N),d,Math.max(.1,Math.abs(N-E)),(W=(O=f.pointColors)==null?void 0:O[h])!=null?W:w,f.borderColor,ql(f,i)),g>=0?u[h]=S:p[h]=S;});});}function ma(e,t,n,r){return t.top+t.height-(e-n)/Math.max(1,r-n)*t.height}function fh(e){return e==="stacked"||e==="percentStacked"}function ph(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 ql(e,t){if(e.borderWidth)return mh(t!=null&&t.bounds.width?e.borderWidth/t.bounds.width*100:void 0,void 0)}function Km(e,t,n){var r;return (r=mh(e!==void 0&&t.bounds.width?e/t.bounds.width*100:void 0,n))!=null?r:n}function mh(e,t){return e===void 0?t:Math.max(.15,Math.min(1.4,e))}function ba(e,t,n,r){var o,i;if((o=t.fillGradient)!=null&&o.colors.length&&t.fillGradient.colors.length>1){let a=`coco-chart-gradient-${n}-${t.fillGradient.colors.join("-").replace(/[^a-zA-Z0-9_-]/g,"_")}`;return Gn(e,a,t.fillGradient),`url(#${a})`}return (i=t.fillColor)!=null?i:r[n%r.length]}function QC(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 _m(e,t,n){if(t.length===0)return;let r=n.width/t.length;t.forEach((o,i)=>{St(e,o,n.left+r*i+r/2,n.top+n.height+5.2,3.2,"#64748B","middle");});}function eE(e,t,n,r,o){let i=Math.max(...t.map(l=>l.values.length),1),a=n.width/i,s=Math.max(1,a*.48/Math.max(t.length,1));t.forEach((l,d)=>{l.showValueLabels&&l.values.forEach((u,p)=>{let f=(u-r)/Math.max(1,o-r)*n.height,b=n.left+p*a+(a-s*t.length)/2+d*s+s/2,w=n.top+n.height-f-2;St(e,String(u),b,w,3,"#A7AEB8","middle");});});}function qm(e,t,n,r,o){t.forEach(i=>{!i.showValueLabels||i.values.length===0||i.values.forEach((a,s)=>{let l=n.left+(i.values.length===1?n.width/2:n.width*s/(i.values.length-1)),d=n.top+n.height-(a-r)/Math.max(1,o-r)*n.height;St(e,String(a),l,Math.max(n.top+2,d-2.2),2.6,"#374151","middle");});});}function tE(e,t,n){var b;let r=t[0];if(!(r!=null&&r.values.length))return;let o=["#1D4ED8","#E3B363","#60A5FA","#94A3B8","#F59E0B","#22C7F2"],i=r.values.reduce((w,g)=>w+Math.max(0,g),0)||1,a=n.left+n.width*.42,s=n.top+n.height*.5,l=Math.min(n.width,n.height)*.34,d=l*.58,u=-90;r.values.forEach((w,g)=>{let h=Math.max(0,w)/i*360,y=u,S=u+h;if(aE(e,a,s,l,d,y,S,QC(r,g,o)),r.showCategoryNameLabels||r.showPercentLabels||r.showValueLabels){let E=nE(r,w,g,i);if(E.length>0){let N=rE(r,g,a,s,l+3.6,n,(y+S)/2);cE(e,E,N.x,N.y,1.9,"#334155",N.x>=a?"start":"end");}}u+=h;}),En(e,a,s,d*.92,"#FFFFFF");let p=oE(r.name);p&&St(e,p,a,s-1.8,1.8,"#64748B","middle");let f=r.values[0];f!==void 0&&St(e,hh(f,i),a,s+3.4,3.9,"#1E3A8A","middle"),sE(e,(b=r.categories)!=null?b:[],o,n.left+n.width*.72,n.top+9);}function nE(e,t,n,r){var a;let o=[],i=(a=e.categories)==null?void 0:a[n];return e.showCategoryNameLabels&&i&&o.push(i),e.showValueLabels&&o.push(_l(t)),e.showPercentLabels&&o.push(hh(t,r)),o}function rE(e,t,n,r,o,i,a){return mr(n,r,o,a)}function hh(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 oE(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 iE(e,t,n,r){var d;let o=t[0];if(!(o!=null&&o.values.length))return;let i=o.values.length,a=n.left+n.width*.48,s=n.top+n.height*.5,l=Math.min(n.width,n.height)*.35;for(let u=1;u<=4;u++)gh(e,lE(i,a,s,l*u/4),"#CBD5E1",.25);for(let u=0;u<i;u++){let p=ua(u,i,a,s,l);yr(e,a,s,p.x,p.y,"#E2E8F0",.25);}t.forEach((u,p)=>{var w;if(!u.values.length)return;let f=u.values.slice(0,i).map((g,h)=>ua(h,i,a,s,Math.max(0,g)/Math.max(1,r)*l)),b=document.createElementNS("http://www.w3.org/2000/svg","path");b.setAttribute("d",f.map((g,h)=>`${h===0?"M":"L"} ${g.x} ${g.y}`).join(" ")+" Z"),b.setAttribute("fill",p===0?"rgba(37, 99, 235, 0.08)":"none"),b.setAttribute("stroke",(w=u.lineColor)!=null?w:"#2563EB"),b.setAttribute("stroke-width",String(uh(u,void 0))),e.append(b),u.marker&&u.marker.symbol!=="none"&&f.forEach(g=>{var h;return En(e,g.x,g.y,.9,(h=u.lineColor)!=null?h:"#2563EB")}),u.showValueLabels&&u.values.slice(0,i).forEach((g,h)=>{var S;let y=f[h];St(e,_l(g),y.x,y.y-1.2,2.2,(S=u.lineColor)!=null?S:"#2563EB","middle");});}),((d=o.categories)!=null?d:[]).slice(0,i).forEach((u,p)=>{let f=ua(p,i,a,s,l+5);St(e,u,f.x,f.y+1,2.6,"#64748B","middle");});}function aE(e,t,n,r,o,i,a,s){let d=Math.max(.01,a-i)>180?1:0,u=mr(t,n,r,i),p=mr(t,n,r,a),f=mr(t,n,o,a),b=mr(t,n,o,i),w=document.createElementNS("http://www.w3.org/2000/svg","path");w.setAttribute("d",[`M ${u.x} ${u.y}`,`A ${r} ${r} 0 ${d} 1 ${p.x} ${p.y}`,`L ${f.x} ${f.y}`,`A ${o} ${o} 0 ${d} 0 ${b.x} ${b.y}`,"Z"].join(" ")),w.setAttribute("fill",s),e.append(w);}function sE(e,t,n,r,o){t.slice(0,6).forEach((i,a)=>{To(e,r,o+a*5,2.4,2.4,n[a%n.length]),St(e,i,r+3.6,o+a*5+2.2,2.7,"#334155");});}function lE(e,t,n,r,o){return Array.from({length:e},(i,a)=>{let s=ua(a,e,t,n,r);return `${a===0?"M":"L"} ${s.x} ${s.y}`}).join(" ")+(" Z")}function ua(e,t,n,r,o){return mr(n,r,o,-90+360*e/t)}function mr(e,t,n,r){let o=r*Math.PI/180;return {x:e+Math.cos(o)*n,y:t+Math.sin(o)*n}}function yr(e,t,n,r,o,i,a,s,l){let d=document.createElementNS("http://www.w3.org/2000/svg","line");d.setAttribute("x1",String(t)),d.setAttribute("y1",String(n)),d.setAttribute("x2",String(r)),d.setAttribute("y2",String(o)),d.setAttribute("stroke",i),d.setAttribute("stroke-width",String(a)),d.setAttribute("stroke-linecap",dE(l)),s!==void 0&&d.setAttribute("stroke-opacity",String(Math.max(0,Math.min(1,s)))),e.append(d);}function dE(e){return e==="rnd"?"round":e==="sq"?"square":"butt"}function gh(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 En(e,t,n,r,o,i,a){let s=document.createElementNS("http://www.w3.org/2000/svg","circle");s.setAttribute("cx",String(t)),s.setAttribute("cy",String(n)),s.setAttribute("r",String(r)),s.setAttribute("fill",o),i&&s.setAttribute("stroke",i),a!==void 0&&s.setAttribute("stroke-width",String(a)),e.append(s);}function ca(e,t,n,r,o,i,a,s){let l=i/2,d=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",d.map(p=>p.join(",")).join(" ")),u.setAttribute("fill",a),s!==void 0&&u.setAttribute("fill-opacity",String(Math.max(0,Math.min(1,s)))),e.append(u);}function To(e,t,n,r,o,i,a,s){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),a&&s!==void 0&&(l.setAttribute("stroke",a),l.setAttribute("stroke-width",String(s))),e.append(l);}function St(e,t,n,r,o,i,a="start"){let s=document.createElementNS("http://www.w3.org/2000/svg","text");s.setAttribute("x",String(n)),s.setAttribute("y",String(r)),s.setAttribute("font-size",String(o)),s.setAttribute("fill",i),s.setAttribute("text-anchor",a),s.textContent=t,e.append(s);}function cE(e,t,n,r,o,i,a="start"){t.forEach((s,l)=>{St(e,s,n,r+l*o*1.2,o,i,a);});}
1698
- exports.DEFAULT_PPT_SLIDE_SIZE=E0;exports.EditorReadOnlyError=mn;exports.NATIVE_BLOCK_CLIPBOARD_TYPE=yi;exports.PptEditorSession=na;exports.SPREADSHEET_CLIPBOARD_MIME=dr;exports.SPREADSHEET_COLUMN_RESIZE_MIN=AT;exports.SPREADSHEET_RESIZE_HIT_TOLERANCE=WT;exports.SPREADSHEET_ROW_RESIZE_MIN=LT;exports.SpreadsheetCanvasRenderer=Ui;exports.SpreadsheetCellEditor=Yi;exports.SpreadsheetEditorRuntime=Xi;exports.SpreadsheetLayout=Di;exports.SpreadsheetViewportManager=Oi;exports.adjacentNativeListNumbering=Fc;exports.allNativeParagraphs=_e;exports.analyzeNativeTableRowPagination=cs;exports.applyNativeWordChangesToPackage=lI;exports.applySpreadsheetAgentAction=NT;exports.applyWheelDelta=tm;exports.applyWordOoxmlPatches=oy;exports.bodyParagraphs=mf;exports.buildPptEditorViewFromModel=SP;exports.buildPptEditorViewFromPptx=vP;exports.buildPptEditorViewFromPresentation=Sm;exports.buildPptPresentationScene=ko;exports.buildPptSceneNode=Co;exports.buildPptSlideScene=I0;exports.buildSpreadsheetAutoFillPlan=Lp;exports.buildSpreadsheetClipboardPayload=qi;exports.buildSpreadsheetReplacePlan=$p;exports.buildSpreadsheetSheetRenderModel=fo;exports.buildWordEditorView=yE;exports.buildWordEditorViewFromDocx=wE;exports.buildWordEditorViewFromFlatOpc=xE;exports.buildWordEditorViewFromPackage=qa;exports.canDispatchNativeWordCommand=Wt;exports.clampScroll=dS;exports.clearNativeImageSelection=Pt;exports.clearSpreadsheetRange=eT;exports.clipboardHtml=yl;exports.clipboardToken=xo;exports.cloneNativeWordBlocks=rt;exports.collectNativeParagraphs=CE;exports.colorToCss=Zn;exports.computeScrollbarState=nm;exports.copybookGuideAppearance=b0;exports.createColumnRangeSelection=MN;exports.createColumnSelection=_i;exports.createNativeListNumbering=us;exports.createNativeParaId=Ln;exports.createNativeSelectionRange=Os;exports.createNativeTextRange=cf;exports.createNativeWordDocument=as;exports.createRowRangeSelection=RN;exports.createRowSelection=Ki;exports.createSelection=it;exports.createWordEditingPlugin=NI;exports.cssPixelsToExcelColumnWidth=Hi;exports.currentNativeCursor=mt;exports.currentNativeSelection=Ve;exports.defineNativeWordElements=Tu;exports.excelColumnWidthToCssPixels=sS;exports.expandRangeForMergedRanges=SS;exports.expandSelectionForMergedRanges=ct;exports.extendSelection=lr;exports.findNativeParagraph=Z;exports.findNativeParagraphLocation=ye;exports.findNativeTableCellLocation=rn;exports.findNativeTableLocation=Oe;exports.findPptSceneNode=Eo;exports.findPptSceneSlide=cr;exports.findSpreadsheetMatches=oT;exports.formatSpreadsheetDisplayValue=Yv;exports.formulasForPaste=vl;exports.freezeStateFromPane=lS;exports.freezeStateFromSheet=$i;exports.getNativeWordCommandState=sp;exports.getRenderCell=qe;exports.getWordChangeSet=TI;exports.getWordSelectionInfo=PI;exports.hitSpreadsheetResizeHandle=Rl;exports.imageOffset=xi;exports.isPptShapeEditable=gP;exports.layoutNativePageAnnotationBubbles=dx;exports.loadOfficeFonts=Pr;exports.measureNativeDocumentReflowFromParagraph=As;exports.moveSelection=AN;exports.nativeAddComment=vs;exports.nativeAddFormatRevision=cu;exports.nativeAddRevision=$t;exports.nativeAnchorLayoutMetadata=Bx;exports.nativeBlockClipboardText=Ks;exports.nativeClearRunFormat=lu;exports.nativeClearTableCellRange=qc;exports.nativeCopyBlockRange=ws;exports.nativeCursorFromPoint=lf;exports.nativeDeleteBackward=Or;exports.nativeDeleteComment=iu;exports.nativeDeleteForward=$r;exports.nativeDeleteImage=du;exports.nativeDeleteRange=bn;exports.nativeDeleteTable=Gc;exports.nativeDeleteTextRangeAcrossParagraphs=ui;exports.nativeDrawingWidthCss=Tx;exports.nativeEditTableStructure=jc;exports.nativeInsertImage=Zc;exports.nativeInsertPageBreak=Jc;exports.nativeInsertTable=Vc;exports.nativeInsertText=on;exports.nativeLineStrokeStyle=Ix;exports.nativeListIndent=Dc;exports.nativeListType=hn;exports.nativeMergeTableCells=Uc;exports.nativeNumberingAtLevel=fs;exports.nativePageBreakAt=ci;exports.nativeParagraphText=Ne;exports.nativeRangeContainsPageBreak=Qc;exports.nativeReplaceBlockRangeAcrossParagraphs=tu;exports.nativeReplaceRange=zr;exports.nativeReplaceRangeWithBlocks=nu;exports.nativeReplaceTableCellRangeContent=Yc;exports.nativeReplaceTableCellRangeText=Xc;exports.nativeReplaceTextRangeAcrossParagraphs=ru;exports.nativeReplaceTextRangeWithParagraphs=xs;exports.nativeResolveFormatRevision=su;exports.nativeResolveImageFormatRevision=fu;exports.nativeResolveImageRevision=uu;exports.nativeResolveRevision=au;exports.nativeSelection=Tt;exports.nativeSelectionFromCursor=lt;exports.nativeSetHyperlink=Ss;exports.nativeSetImageSize=eu;exports.nativeSetParagraphFormat=Jn;exports.nativeSetParagraphList=Vr;exports.nativeSetRunFormat=ys;exports.nativeSetTableCellFormat=gs;exports.nativeSetTableCellRangeFormat=_c;exports.nativeSplitParagraph=ks;exports.nativeSplitTableCell=Kc;exports.nativeSyncParagraphText=Gr;exports.nativeTableCellsInRange=tt;exports.nativeTableSupportsStructuralEditing=Hr;exports.nativeTextRangeIsBold=GE;exports.nativeUpdateComment=ou;exports.nextSpreadsheetMatch=iT;exports.normalizePptGeometry=So;exports.normalizeSelectionRange=Ae;exports.paginateNativeDocument=Mu;exports.parentNativeParagraph=Nt;exports.parseNativeBlockClipboard=bf;exports.parseNativeClipboardHtml=gf;exports.parseTsv=Mp;exports.planWordOoxmlPatch=ny;exports.planWordOoxmlPatches=ty;exports.pptSceneGeometryToSourceGeometry=ym;exports.pptSceneNodeCapabilities=xm;exports.previewSpreadsheetAgentAction=IT;exports.previousNativeParagraphId=ss;exports.rangeAddressForMatrix=VN;exports.rangeForSpreadsheetMatch=aT;exports.readSpreadsheetClipboardPayload=wl;exports.rebuildNativeTableFragmentsFromParagraph=Vt;exports.reflowNativeDocumentFromParagraph=Au;exports.refreshNativeNumberingLabels=ai;exports.refreshNativePageCommentBubbles=yn;exports.renderNativeBlock=Zr;exports.renderNativeDocument=Pu;exports.renderNativeImage=Ds;exports.renderNativeParagraph=Jr;exports.renderNativePptEditor=WP;exports.renderNativeTable=af;exports.renderNativeWordEditor=eN;exports.renderNormalizedDocumentHtmlPage=PE;exports.renderSpreadsheetEditor=fP;exports.resolveNativeSectionPageNumberStarts=gx;exports.resolveNativeTableCellBorders=$x;exports.resolveOfficeFontFamily=qt;exports.resolveParagraphStyle=Wr;exports.resolveRunStyle=Yn;exports.resolveSpreadsheetCellStyle=mo;exports.resolveSpreadsheetRangeBorder=Ep;exports.resolveTableCellStyle=ti;exports.resolveWordOoxmlPatchTargets=ry;exports.restoreNativeCursor=dt;exports.restoreNativeElementSelection=df;exports.restoreNativeTextSelection=vn;exports.rowColumnKey=Li;exports.scrollFromThumbPosition=Zi;exports.searchNativeWordDocument=zs;exports.selectNativeImage=uf;exports.selectionAfterColumnDeletion=WN;exports.selectionAfterRowDeletion=LN;exports.serializeNativeBlockClipboard=Us;exports.serializeNativeClipboardHtml=js;exports.serializeRangeToTsv=MS;exports.serializeSpreadsheetClipboardPayload=wo;exports.setColor=AI;exports.setFontSize=MI;exports.setParagraphAlign=LI;exports.setSpreadsheetCellFormula=JN;exports.setSpreadsheetCellValue=ZN;exports.setSpreadsheetColumnWidth=nT;exports.setSpreadsheetRangeValues=QN;exports.setSpreadsheetRowHeight=tT;exports.splitNativeTableRowAtBlockBoundary=WE;exports.splitNativeTableRowAtTextOffset=BE;exports.spreadsheetFilterValues=Il;exports.spreadsheetRowsForColumnFilters=Gp;exports.spreadsheetRowsForFilter=Vp;exports.spreadsheetSortRows=jp;exports.spreadsheetVisibleFilterValues=dT;exports.startSpreadsheetResizeDrag=rm;exports.summarizeEditorCoverage=kb;exports.summarizeNativeCoverage=kE;exports.summarizeNativeTablePagination=LE;exports.summarizeSpreadsheetSelectionFormat=OT;exports.supportsSpreadsheetAutoFill=Cl;exports.toggleBold=RI;exports.updateSpreadsheetResizeDrag=Ml;exports.wordEditingPluginKey=oo;
1749
+ `;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(()=>Mr([...this.fontResources.map(n=>n.family),...this.referencedFontFamilies].map(n=>`16px ${th(n)}`))).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 a=document.createElement("button");a.className="coco-ppt-thumb",a.type="button",a.dataset.slideId=i.id,a.dataset.slideIndex=String(i.index),a.dataset.selected=((u=this.sessionValue.selection())==null?void 0:u.slideId)===i.id?"true":"false";let s=document.createElement("div");s.className="coco-ppt-thumb-preview";let l=document.createElement("div");l.className="coco-ppt-thumb-placeholder";let d=document.createElement("span");return d.className="coco-ppt-thumb-number",d.textContent=String(i.index+1),a.append(s,l,d),a.addEventListener("click",()=>{this.dispatch({kind:"select-slide",slideIdOrIndex:i.id});}),a})),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=zl(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 a=o.querySelector(".coco-ppt-thumb-preview"),s=o.querySelector(".coco-ppt-thumb-placeholder");if(!a||!s)return;if(i<r.start||i>=r.end){a.replaceChildren(),delete o.dataset.previewRendered,delete o.dataset.previewMode,s.hidden=false;return}if(o.dataset.previewRendered==="true")return;let l=t[i];if(!l)return;let d=Hl(l),u=this.thumbnailCanvasCache.get(l.id);(u==null?void 0:u.fingerprint)===d?(a.replaceChildren(Am(u.canvas)),o.dataset.previewMode="canvas"):(a.replaceChildren(this.renderThumbnailSlide(l)),o.dataset.previewMode="dom",this.rasterizeThumbnail(o,l)),o.dataset.previewRendered="true",s.hidden=true;});}visibleThumbnailRange(t){let n=pr*.5625+Q0,r=this.slideList.clientHeight||n*Math.min(t,5),o=Math.max(0,Math.floor(this.slideList.scrollTop/n)-aa),i=Math.ceil(r/n)+aa*2,a=this.sessionValue.selection(),s=(a==null?void 0:a.slideId)!==void 0?this.sessionValue.scene().slides.findIndex(u=>u.id===a.slideId):-1,l=s>=0?Math.min(o,Math.max(0,s-aa)):o,d=s>=0?Math.max(o+i,Math.min(t,s+aa+1)):o+i;return {start:l,end:Math.min(t,d)}}renderThumbnailSlide(t){let n=document.createElement("div");n.className="coco-ppt-thumb-slide";let o=pr*sa/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/sa})`,n.style.background=zl(t.background,this.imageResources),n.replaceChildren(...t.nodes.map(i=>this.renderNode(i,o,t,false))),n}async rasterizeThumbnail(t,n){var d,u;let r=this.thumbnailRasterEpoch,o=Hl(n);if(await Mm(),await Mm(),r!==this.thumbnailRasterEpoch||!t.isConnected)return;let i=t.querySelector(".coco-ppt-thumb-preview"),a=i==null?void 0:i.querySelector(".coco-ppt-thumb-slide");if(!i||!a)return;let s=await lk(a,pr,pr*(n.size.height/n.size.width),ek,(u=(d=this.root.querySelector("style"))==null?void 0:d.textContent)!=null?u:"",pr*sa,pr*sa*(n.size.height/n.size.width));if(!s||r!==this.thumbnailRasterEpoch||!t.isConnected)return;let l=this.sessionValue.scene().slides.find(f=>f.id===n.id);!l||Hl(l)!==o||(this.thumbnailCanvasCache.set(n.id,{fingerprint:o,canvas:s}),i.replaceChildren(Am(s)),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,S;let i=document.createElement("div"),a=ah(t),s=t.presetGeometry==="frame",l=a?sh(t):"horizontal",d=Math.max(a&&l==="vertical"?12:1,t.bounds.width*n),u=Math.max(a&&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-(a&&l==="vertical"?d/2:0)}px`,i.style.top=`${t.bounds.top*n-(a&&l==="horizontal"?u/2:0)}px`,i.style.width=`${d}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=ch(t),b=fC(t.presetGeometry),w=!!(b&&t.text&&!t.customGeometry&&!p);if(t.usesBackgroundFill&&t.backgroundFill?iC(i,t.backgroundFill,t,r,n,this.imageResources):t.customGeometry||p||w||t.kind==="table"||a||s?i.style.background="transparent":t.fillGradient&&t.fillGradient.colors.length>1?i.style.background=vr(t.fillGradient,yr(t)):t.fillColor&&(i.style.background=xr(t.fillColor,yr(t))),Kk(t)&&(i.style.overflow="visible"),(t.presetGeometry==="roundRect"||t.presetGeometry==="round1Rect")&&(i.style.borderRadius=`${br(t)*n}px`),t.presetGeometry==="round2DiagRect"){let k=`${br(t)*n}px`;i.style.borderRadius=`${k} 0 ${k} 0`;}if(t.presetGeometry==="round2SameRect"){let k=`${br(t)*n}px`;i.style.borderRadius=`${k} ${k} 0 0`;}if((t.presetGeometry==="ellipse"||tk(t)||ok(t))&&(i.style.borderRadius="9999px"),b&&!w&&!p&&(i.style.clipPath=b),s?(i.style.borderStyle="solid",i.style.borderWidth=`${aC(t,n)}px`,t.fillGradient&&t.fillGradient.colors.length>1?(i.style.borderImageSource=vr(t.fillGradient),i.style.borderImageSlice="1"):t.fillColor&&(i.style.borderColor=t.fillColor)):!t.customGeometry&&!p&&!w&&!a&&t.kind!=="picture"&&t.lineColor&&(i.style.borderStyle=Ul(t.lineDash),i.style.borderWidth=`${Math.max(1,((h=t.lineWidth)!=null?h:9525)*n)}px`,i.style.borderColor=xr(t.lineColor,t.lineOpacity)),t.shadow&&(i.style.boxShadow=ph(t.shadow,n)),this.applyTextStyle(i,t,n),Fk(i,t,n),w&&b&&i.append(lC(t,n,b)),t.customGeometry&&t.kind!=="picture"&&i.append(IC(t)),p&&i.append(pC(t,n)),a)i.append(MC(t,n));else if(t.kind==="chart")i.append(zC(t));else if(t.kind==="table"){let k=BC(t,n,o);o&&(k.addEventListener("click",I=>{I.stopPropagation(),!this.consumeSuppressedClick()&&(this.notifyTableCellSelection(r,t,I),this.dispatch({kind:"select-shape",slideIdOrIndex:r.id,shapeIdOrName:t.id}));}),k.addEventListener("dblclick",I=>{if(this.isReadOnly())return;let A=Wm(I);if(!A||!t.capabilities.editTableCells)return;I.stopPropagation();let F=Number(A.dataset.row),L=Number(A.dataset.column);!Number.isInteger(F)||!Number.isInteger(L)||this.startTableCellEdit(A,r,t,F,L);})),i.append(k);}else if(t.kind==="picture"){let k=t.imagePath?this.imageResources[t.imagePath]:void 0,I=k==null?void 0:k.url;if(I&&Gl(k.contentType,t.imagePath)){if(vC(t,r))i.append(CC(t,I));else {let A=document.createElement("img");A.src=I,A.alt=(y=t.name)!=null?y:"",Rk(A,t),t.imageOpacity!==void 0&&(A.style.opacity=String(Math.max(0,Math.min(1,t.imageOpacity)))),i.append(A);}t.lineColor&&i.append(RC(t,n));}else i.dataset.unsupportedImage=t.imagePath?"true":"missing",k!=null&&k.contentType&&(i.dataset.imageContentType=k.contentType),t.imagePath&&(i.dataset.imagePath=t.imagePath),i.append(Lk(t,k==null?void 0:k.contentType));}else {let k=(S=t.text)!=null?S:"";if(t.customGeometry||p||w||Bk(t)){let I=document.createElement("div");I.className="coco-ppt-text-layer",Dk(I,t),Om(I,t,n,k),i.append(I),$m(I,t),zm(I,t);}else Om(i,t,n,k),$m(i,t),zm(i,t);}if(sC(t)&&i.append(PC(t,n)),!o)return i;let g=document.createElement("div");return g.className="coco-ppt-resize-handle",g.addEventListener("mousedown",k=>{this.isReadOnly()||!t.capabilities.editGeometry||(k.preventDefault(),k.stopPropagation(),this.startDrag(k,"resize",r,t,n,i));}),i.append(g),i.addEventListener("click",k=>{var A,F;if(this.hideContextMenu(),k.stopPropagation(),this.consumeSuppressedClick())return;if(k.altKey){let L=this.selection(),V=kk(r,k,n,(L==null?void 0:L.kind)==="shape"?L.shapeId:t.id);if(V){this.dispatch({kind:"select-shape",slideIdOrIndex:r.id,shapeIdOrName:V.node.id}),(F=(A=this.options).onObjectAction)==null||F.call(A,{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 I=this.pointerOperationNode(r,t,k,n);if(I){this.dispatch({kind:"select-shape",slideIdOrIndex:r.id,shapeIdOrName:I.id});return}this.dispatch({kind:"select-shape",slideIdOrIndex:r.id,shapeIdOrName:t.id});}),i.addEventListener("contextmenu",k=>{var A;if(this.isReadOnly())return;k.preventDefault(),k.stopPropagation();let I=(A=this.pointerOperationNode(r,t,k,n))!=null?A:t;this.dispatch({kind:"select-shape",slideIdOrIndex:r.id,shapeIdOrName:I.id}).then(()=>this.showContextMenu(k,r,I));}),i.addEventListener("mousedown",k=>{var F,L;let I=(F=this.pointerOperationNode(r,t,k,n))!=null?F:t,A=(L=Ol(this.canvas,I.id))!=null?L:i;vk(A,k.target)||this.isReadOnly()||k.button!==0||!I.capabilities.editGeometry||(k.preventDefault(),k.stopPropagation(),this.startDrag(k,"move",r,I,n,A));}),i.addEventListener("dblclick",k=>{var A,F,L;if(this.isReadOnly())return;k.stopPropagation();let I=Fm(r,t,k,n);if(I){this.startTextEdit((A=Ol(this.canvas,I.id))!=null?A:i,r,I);return}if(!t.capabilities.editText){this.sessionValue.dispatch({kind:"select-shape",slideIdOrIndex:r.id,shapeIdOrName:t.id}).then(()=>this.renderSelection()),(L=(F=this.options).onObjectAction)==null||L.call(F,{action:"blocked-text-edit",slideId:r.id,shapeId:t.id,kind:t.kind,name:t.name,reason:Ik(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:Fm(t,n,r,o)}notifyTableCellSelection(t,n,r){var s,l;let o=Wm(r);if(!o||!n.capabilities.editTableCells)return;let i=Number(o.dataset.row),a=Number(o.dataset.column);!Number.isInteger(i)||!Number.isInteger(a)||(l=(s=this.options).onTableCellSelectionChange)==null||l.call(s,{slideId:t.id,shapeId:n.id,row:i,column:a,text:_m(o,n,i,a)});}applyTextStyle(t,n,r){var a,s,l,d;let o=n.textStyle;o&&(Vl(t,Sk(n,o),r),o.alignment&&(jl(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=(a=i.insetLeft)!=null?a:91440,f=(s=i.insetTop)!=null?s:45720,p=(l=i.insetRight)!=null?l:91440,b=(d=i.insetBottom)!=null?d:45720,w=Hk(n,r);t.style.padding=`${f*r+w}px ${p*r}px ${b*r}px ${u*r}px`,nh(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,b,w,g;if(this.isReadOnly())return;let o=(p=r.text)!=null?p:"",i=xk(t),a=false;this.sessionValue.dispatch({kind:"select-shape",slideIdOrIndex:n.id,shapeIdOrName:r.id}).then(()=>this.renderSelection()),(w=(b=this.options).onTextEditStateChange)==null||w.call(b,{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 s=i.ownerDocument.getSelection();if(s){let h=i.ownerDocument.createRange();h.selectNodeContents(i),h.collapse(false),s.removeAllRanges(),s.addRange(h);}let l=h=>{var S,k,I,A,F;if(a)return;a=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",d),i.removeEventListener("paste",u);let y=(S=i.textContent)!=null?S:"";if(!h){i.textContent=o,(I=(k=this.options).onTextEditStateChange)==null||I.call(k,{state:"cancel",slideId:n.id,shapeId:r.id,text:o}),this.render();return}(F=(A=this.options).onTextEditStateChange)==null||F.call(A,{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();},d=h=>{if(h.key==="Escape"){h.preventDefault(),l(false);return}h.key==="Enter"&&!h.shiftKey&&(h.preventDefault(),l(true));},u=h=>{var S;let y=(S=h.clipboardData)==null?void 0:S.getData("text/plain");y!==void 0&&(h.preventDefault(),Hm(i,y));},f=()=>l(true);i.addEventListener("blur",f),i.addEventListener("keydown",d),i.addEventListener("paste",u);}startTableCellEdit(t,n,r,o,i){var b,w,g;if(this.isReadOnly())return;let a=_m(t,r,o,i),s=false;this.sessionValue.dispatch({kind:"select-shape",slideIdOrIndex:n.id,shapeIdOrName:r.id}).then(()=>this.renderSelection()),(w=(b=this.options).onTableCellSelectionChange)==null||w.call(b,{slideId:n.id,shapeId:r.id,row:o,column:i,text:a}),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=a,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 d=h=>{var S;if(s)return;s=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=(S=t.textContent)!=null?S:"";if(!h){t.textContent=a,t.dataset.cellText=a;return}y!==a?(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(),d(false);return}h.key==="Enter"&&!h.shiftKey&&(h.preventDefault(),d(true));},f=h=>{var S;let y=(S=h.clipboardData)==null?void 0:S.getData("text/plain");y!==void 0&&(h.preventDefault(),Hm(t,y));},p=()=>d(true);t.addEventListener("blur",p),t.addEventListener("keydown",u),t.addEventListener("paste",f);}startDrag(t,n,r,o,i,a){this.isReadOnly()||(n==="resize"&&ik(a,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:a,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:s}=t.altKey?{bounds:Cn(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=`${s.left*n.scale}px`,n.element.style.top=`${s.top*n.scale}px`;return}let{bounds:a}=t.altKey?{bounds:Cn(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=`${a.width*n.scale}px`,n.element.style.height=`${a.height*n.scale}px`;}async finishDrag(t){var s,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 a=t.altKey?Cn(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 a?a.bounds:a,preserveTextSizeOnResize:n.mode==="resize"}),"snapped"in a&&a.snapped){let d=this.currentSlide(),u=d==null?void 0:d.nodes.find(f=>f.id===n.shapeId);d&&u&&((l=(s=this.options).onObjectAction)==null||l.call(s,{action:"snap-geometry",slideId:d.id,shapeId:u.id,kind:u.kind,name:u.name,reason:this.snapActionReason(a,d)}));}}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=Cn(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,Pm/t.scale),a=da([{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"}],la(o,t.shapeId,"x"),i),s=da([{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"}],la(o,t.shapeId,"y"),i),l=Cn(t.startBounds,t.slideSize,{left:a?a.target.value-a.source.offset:r.left,top:s?s.target.value-s.source.offset:r.top}),d=[...a?[{axis:"x",value:a.target.value,kind:a.target.kind,referenceShapeId:a.target.referenceShapeId}]:[],...s?[{axis:"y",value:s.target.value,kind:s.target.kind,referenceShapeId:s.target.referenceShapeId}]:[]];return this.renderSnapGuides(d,t.scale),{bounds:l,guides:d,snapped:d.length>0}}snapResizeBounds(t,n){let r=Cn(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,Pm/t.scale),a=da([{offset:r.width/2,value:r.left+r.width/2,role:"center"},{offset:r.width,value:r.left+r.width,role:"end"}],la(o,t.shapeId,"x"),i,{matchRole:false}),s=da([{offset:r.height/2,value:r.top+r.height/2,role:"center"},{offset:r.height,value:r.top+r.height,role:"end"}],la(o,t.shapeId,"y"),i,{matchRole:false}),l=Cn(t.startBounds,t.slideSize,{width:a?Rm(r.left,r.width,a.source,a.target.value):r.width,height:s?Rm(r.top,r.height,s.source,s.target.value):r.height}),d=[...a?[{axis:"x",value:a.target.value,kind:a.target.kind,referenceShapeId:a.target.referenceShapeId}]:[],...s?[{axis:"y",value:s.target.value,kind:s.target.kind,referenceShapeId:s.target.referenceShapeId}]:[]];return this.renderSnapGuides(d,t.scale),{bounds:l,guides:d,snapped:d.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=Ol(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||Dm(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(d=>d.id===n.slideId),o=r==null?void 0:r.nodes.find(d=>d.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(!jn(o))return;t.preventDefault(),this.deleteSelectedShape(r,o);return}let a=yk(t.key);if(!a||!o.capabilities.editGeometry)return;let s=J0*(t.shiftKey?10:1),l=Cn(o.bounds,r.size,{left:o.bounds.left+a.dx*s,top:o.bounds.top+a.dy*s});t.preventDefault(),this.dispatch({kind:"set-shape-geometry",slideIdOrIndex:r.id,shapeIdOrName:o.id,geometry:{left:l.left,top:l.top}}).then(()=>{var d,u;(u=(d=this.options).onObjectAction)==null||u.call(d,{action:"nudge-geometry",slideId:r.id,shapeId:o.id,kind:o.kind,name:o.name,reason:`\u5DF2\u79FB\u52A8\u5BF9\u8C61 ${a.label}${t.shiftKey?" 10\u6B65":" 1\u6B65"}`});});}handleSelectStart(t){this.isReadOnly()||Dm(t.target)||t.target instanceof HTMLElement&&t.target.closest('[contenteditable="true"]')||t.preventDefault();}copySelectedShape(t,n){var r,o;jn(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,a;let o=this.selection();(a=(i=this.options).onObjectAction)==null||a.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){jn(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){jn(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){jn(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=jn(r),i=!!this.clipboardShape,a=u=>()=>{this.hideContextMenu(),u();};this.contextMenu.replaceChildren(mr("\u590D\u5236","Ctrl+C",o,a(()=>this.copySelectedShape(n,r))),mr("\u7C98\u8D34","Ctrl+V",i,a(()=>this.pasteClipboardShape(n,r))),mr("\u91CD\u590D","Ctrl+D",o,a(()=>this.duplicateSelectedShape(n,r))),Bm(),mr("\u7F6E\u4E8E\u9876\u5C42","Ctrl+Shift+]",o,a(()=>this.bringSelectedShapeToFront(n,r))),mr("\u7F6E\u4E8E\u5E95\u5C42","Ctrl+Shift+[",o,a(()=>this.sendSelectedShapeToBack(n,r))),Bm(),mr("\u5220\u9664","Del",o,a(()=>this.deleteSelectedShape(n,r))));let s=this.root instanceof ShadowRoot?this.root.host.getBoundingClientRect():this.root.getBoundingClientRect(),l=ha(t.clientX,s.left+4,window.innerWidth-170),d=ha(t.clientY,s.top+4,window.innerHeight-220);this.contextMenu.style.left=`${l}px`,this.contextMenu.style.top=`${d}px`,this.contextMenu.dataset.shapeId=r.id,this.contextMenu.dataset.open="true";}deleteSelectedShape(t,n){jn(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 d,u;if((t==null?void 0:t.kind)!=="shape")return;let n=this.sessionValue.scene().slides.find(f=>f.id===t.slideId),r=(d=n==null?void 0:n.nodes.find(f=>f.id===t.shapeId))!=null?d: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:rk(r):(r==null?void 0:r.kind)==="group"?r:null;if(!n||!o)return;let i=this.computeScale(n),a=document.createElement("div");a.className="coco-ppt-parent-group-outline",a.dataset.shapeId=o.id,a.dataset.selected=t.shapeId===o.id?"true":"false",a.title=`\u7236\u7EC4\uFF1A${o.name||o.id}`,a.style.left=`${o.bounds.left*i}px`,a.style.top=`${o.bounds.top*i}px`,a.style.width=`${o.bounds.width*i}px`,a.style.height=`${o.bounds.height*i}px`;let s=f=>{f.preventDefault(),f.stopPropagation(),this.startDrag(f,"move",n,o,i,a);};["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",s),a.append(p);});let l=document.createElement("div");l.className="coco-ppt-parent-group-handle",l.title="\u62D6\u52A8\u7236\u7EC4",l.addEventListener("mousedown",s),a.append(l),this.canvas.append(a);}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(a=>a.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 ik(e,t){var r,o;if(!ak(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 ak(e){var t;return !!(e.capabilities.editGeometry&&sk(e)&&(e.text||(t=e.textParagraphs)!=null&&t.length))}function sk(e){return e.kind==="placeholder"||e.kind==="textBox"||e.kind==="geometricShape"}function Mm(){return new Promise(e=>requestAnimationFrame(()=>e()))}async function lk(e,t,n,r,o,i=t,a=n){if(typeof XMLSerializer=="undefined"||typeof Blob=="undefined"||typeof URL=="undefined"||typeof URL.createObjectURL!="function")return null;await dk(e);let s=document.createElement("canvas");s.width=Math.max(1,Math.round(t*r)),s.height=Math.max(1,Math.round(n*r));let l=s.getContext("2d");if(!l)return null;let d=document.createElement("div");d.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),d.style.width=`${i}px`,d.style.height=`${a}px`,d.style.position="relative",d.style.overflow="hidden",d.style.background="#fff";let u=document.createElement("style");u.textContent=o;let f=e.cloneNode(true);await ck(f),f.style.position="relative",f.style.left="0",f.style.top="0",f.style.transform="none",d.append(u,f);let p=new XMLSerializer().serializeToString(d),b=`<svg xmlns="http://www.w3.org/2000/svg" width="${s.width}" height="${s.height}" viewBox="0 0 ${i} ${a}"><foreignObject width="100%" height="100%">${p}</foreignObject></svg>`,w=URL.createObjectURL(new Blob([b],{type:"image/svg+xml;charset=utf-8"}));try{let g=await pk(w);return l.drawImage(g,0,0,s.width,s.height),s}catch(g){return null}finally{URL.revokeObjectURL(w);}}function Am(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 Hl(e){return JSON.stringify({size:e.size,background:e.background,nodes:e.nodes.map(t=>Jm(t))})}function Jm(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=>Jm(t))}}async function dk(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 ck(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 uk(r).catch(()=>{});o&&n.setAttribute("src",o);}));}async function uk(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 fk(n)}function fk(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 pk(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 mk(e){return e.filter(hk).map(n=>{var a,s;let r=Tk(n.family),o=(a=n.weight)!=null?a:400,i=(s=n.style)!=null?s:"normal";return `@font-face { font-family: ${r}; src: url(${Pk(n.url)}); font-weight: ${o}; font-style: ${i}; }`}).join(`
1750
+ `)}function hk(e){return /font\/(ttf|otf|woff|woff2)|application\/font-(sfnt|woff|woff2)/i.test(e.contentType)}function gk(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=Nk(o);if(!i)continue;let a=`coco-ppt-google-font-${o.replace(/[^a-zA-Z0-9_-]/g,"_")}`,s=document.getElementById(a);if(s){r.push(Lm(s));continue}let l=document.createElement("link");l.id=a,l.rel="stylesheet",l.href=i,r.push(Lm(l)),document.head.append(l);}return Promise.all(r).then(()=>{})}function bk(e){let t=new Set,n=o=>{o!=null&&o.trim()&&t.add(o.trim());},r=o=>{var i,a,s,l,d,u,f,p;n((i=o.textStyle)==null?void 0:i.fontFamily);for(let b of (a=o.textParagraphs)!=null?a:[]){n((s=b.style)==null?void 0:s.bulletFontFamily);for(let w of (l=b.runs)!=null?l:[])n((d=w.style)==null?void 0:d.fontFamily);}for(let b of (f=(u=o.table)==null?void 0:u.cellStyles)!=null?f:[])for(let w of b)n((p=w==null?void 0:w.textStyle)==null?void 0:p.fontFamily);for(let b of o.children)r(b);};for(let o of e.scene.slides)for(let i of o.nodes)r(i);return [...t]}function wk(e){globalThis.__cocoPptFontRenderReady=e;}function Lm(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 xk(e){var t;return (t=e.querySelector(".coco-ppt-text-layer"))!=null?t:e}function Wm(e){let t=e.target;return t instanceof HTMLElement?t.closest("td[data-row][data-column]"):null}function mr(e,t,n,r){let o=document.createElement("button");o.type="button",o.disabled=!n;let i=document.createElement("strong");i.textContent=e;let a=document.createElement("span");return a.textContent=t,o.append(i,a),o.addEventListener("click",()=>{o.disabled||r();}),o}function Bm(){return document.createElement("hr")}function yk(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 Dm(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 vk(e,t){return e.isContentEditable||t instanceof HTMLElement&&t.isContentEditable?true:!!e.querySelector('[contenteditable="true"]')}function Sk(e,t){var s;let n=(s=e.textParagraphs)==null?void 0:s.filter(d=>d.runs.length>0);if(!(n!=null&&n.length)||!ih(e,n))return t;let l=t,{textGradient:r,textFill:o,textOutlineColor:i}=l;return Ln(l,["textGradient","textFill","textOutlineColor"])}function Fm(e,t,n,r){if(t.capabilities.editText||Ek(t))return null;let o=Qm(n,r);if(!o)return null;let i=e.nodes.findIndex(s=>s.id===t.id),a=e.nodes.slice(0,i<0?e.nodes.length:i);for(let s=a.length-1;s>=0;s--){let l=a[s];if(l.capabilities.editText&&eh(o.x,o.y,l.bounds))return l}return null}function kk(e,t,n,r){let o=Ck(e,t,n);if(o.length<2)return null;let a=(Math.max(0,o.findIndex(s=>s.id===r))+1)%o.length;return {node:o[a],index:a,count:o.length}}function Ck(e,t,n){let r=Qm(t,n);if(!r)return [];let o=[];for(let i=e.nodes.length-1;i>=0;i--){let a=e.nodes[i];a.capabilities.select&&eh(r.x,r.y,a.bounds)&&o.push(a);}return o}function Ek(e){return e.kind==="table"||e.kind==="chart"||e.kind==="smartArt"}function Qm(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 eh(e,t,n){return e>=n.left&&e<=n.left+n.width&&t>=n.top&&t<=n.top+n.height}function Ol(e,t){for(let n of Array.from(e.querySelectorAll(".coco-ppt-node")))if(n.dataset.shapeId===t)return n;return null}function Hm(e,t){var a,s;let n=e.ownerDocument.getSelection();if(!n||n.rangeCount===0){e.textContent=`${(a=e.textContent)!=null?a:""}${t}`;return}let r=n.getRangeAt(0);if(!(e===r.commonAncestorContainer||e.contains(r.commonAncestorContainer))){e.textContent=`${(s=e.textContent)!=null?s:""}${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 Ik(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 Nk(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 th(e){return qt(e,{families:["Calibri","Microsoft YaHei","Segoe UI"],generic:"sans-serif"})}function Tk(e){return `"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function Pk(e){return `"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function xr(e,t){var s;if(t===void 0||t>=1)return e;let n=Math.max(0,Math.min(1,t)),r=(s=e.match(/^#([0-9a-fA-F]{6})$/))==null?void 0:s[1];if(!r)return e;let o=Number.parseInt(r.slice(0,2),16),i=Number.parseInt(r.slice(2,4),16),a=Number.parseInt(r.slice(4,6),16);return `rgba(${o}, ${i}, ${a}, ${n})`}function yr(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 Rk(e,t){if(t.imageFillRect){Ak(e,t);return}Mk(e,t);}function Mk(e,t){var d,u,f,p;let n=t.imageCrop;if(!n)return;let r=(d=n.left)!=null?d:0,o=(u=n.right)!=null?u:0,i=(f=n.top)!=null?f:0,a=(p=n.bottom)!=null?p:0,s=Math.max(.01,1-r-o),l=Math.max(.01,1-i-a);e.style.position="absolute",e.style.left=`${-r/s*100}%`,e.style.top=`${-i/l*100}%`,e.style.width=`${1/s*100}%`,e.style.height=`${1/l*100}%`;}function Ak(e,t){var s,l,d,u;let n=t.imageFillRect;if(!n)return;let r=(s=n.left)!=null?s:0,o=(l=n.right)!=null?l:0,i=(d=n.top)!=null?d:0,a=(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-a)*100}%`;}function Lk(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||Wk(t)||"IMAGE",n.title=e.imagePath?`Unsupported image: ${e.imagePath}`:"Missing image resource",n}function Wk(e){if(e)return e.includes("emf")?"EMF":e.includes("wmf")?"WMF":e.includes("svg")?"SVG":"IMAGE"}function Om(e,t,n,r){var s,l;let o=(s=t.textParagraphs)==null?void 0:s.filter(d=>d.runs.length>0),i=nh(t.textBody);if(!(o!=null&&o.length)||!ih(t,o)){!i&&((l=t.textStyle)==null?void 0:l.alignment)==="distributed"&&Array.from(r).length>1?Xk(e,r):e.textContent=r;return}let a=document.createElement("div");a.className="coco-ppt-rich-text",o.forEach(d=>{var p,b,w,g;let u=document.createElement("div");u.className="coco-ppt-paragraph",(p=d.style)!=null&&p.alignment&&jl(u,d.style.alignment),Zk(u,d.style,n,{verticalText:i});let f=!i&&((b=d.style)==null?void 0:b.alignment)==="distributed"&&!((w=d.style)!=null&&w.bullet);if(f&&(u.style.display="flex",u.style.justifyContent="space-between",u.style.alignItems="baseline",u.style.width="100%"),(g=d.style)!=null&&g.bullet){u.dataset.bullet="true";let h=document.createElement("span");h.className="coco-ppt-bullet",h.textContent=d.style.bullet,d.style.bulletColor&&(h.style.color=d.style.bulletColor),Qk(h,d.style,n,d.text),u.append(h);}d.runs.forEach((h,y)=>{(f?Array.from(h.text):[h.text]).forEach(k=>{let I=document.createElement("span");I.textContent=k;let A=nC(t,d,h,y);A&&Vl(I,A,n),u.append(I);});}),a.append(u);}),e.append(a);}function nh(e){return (e==null?void 0:e.vertical)==="eastAsian"||(e==null?void 0:e.vertical)==="vertical"}function $m(e,t){var n;((n=t.textBody)==null?void 0:n.wrap)==="none"&&rh(e);}function zm(e,t){var n,r;((n=t.textBody)==null?void 0:n.autoFit)==="normal"&&(!t.text&&!((r=t.textParagraphs)!=null&&r.length)||(Vk(t)&&!jk(t)&&rh(e),requestAnimationFrame(()=>{var p;if(e.dataset.textResizePreview==="wrap")return;let o=e.clientWidth,i=e.clientHeight;if(o<=0||i<=0)return;let a=e.scrollWidth,s=e.scrollHeight,l=a>o?o/a:1,d=s>i?i/s:1,u=Math.max(.25,Math.min(1,l,d));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=Uk(t),f.style.transform=`scale(${u})`,f.style.width=`${100/u}%`);})));}function Bk(e){var t;return !!((e.text||(t=e.textParagraphs)!=null&&t.length)&&(e.bounds.flipHorizontal||e.bounds.flipVertical))}function Dk(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 rh(e){e.style.whiteSpace="nowrap",e.querySelectorAll(".coco-ppt-rich-text, .coco-ppt-paragraph").forEach(t=>{t.style.whiteSpace="nowrap";});}function Fk(e,t,n){var o,i,a;if(!$k(t,n))return;let r=((a=(i=(o=t.textStyle)==null?void 0:o.fontSize)!=null?i:wa(t))!=null?a:28)*12700*n;e.style.letterSpacing=`${Math.max(1,Math.min(2.4,r*.035))}px`;}function Hk(e,t){var r,o;if(!Ok(e))return 0;let n=(o=(r=e.textStyle)==null?void 0:r.fontSize)!=null?o:wa(e);return n?n*12700*t*.18:0}function Ok(e){var i,a,s,l,d,u,f,p,b;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=(s=(a=e.textStyle)==null?void 0:a.fontFamily)!=null?s:oh(e);if(!t||!/\bCuprum\b/i.test(t))return false;let n=(d=(l=e.textStyle)==null?void 0:l.fontSize)!=null?d:wa(e);if(!n||n<72)return false;let r=(u=e.textParagraphs)==null?void 0:u.filter(w=>{var h;return ((h=w.text)!=null?h:w.runs.map(y=>y.text).join("")).trim().length>0});if(r&&r.length!==1)return false;let o=((b=(p=(f=r==null?void 0:r[0])==null?void 0:f.text)!=null?p:e.text)!=null?b:"").trim();return o.length>=12&&!/[\u3400-\u9fff]/.test(o)}function $k(e,t){var l,d,u,f,p,b,w,g,h,y,S,k,I,A,F,L,V,ee,fe,ae;if(((l=e.textBody)==null?void 0:l.wrap)!=="square"||zk(e)||((b=(d=e.textStyle)==null?void 0:d.alignment)!=null?b:(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=(w=e.textStyle)==null?void 0:w.fontFamily)!=null?g:oh(e);if(!r||!/\bJosefin Sans\b/i.test(r))return false;let o=((k=(S=(y=(h=e.textParagraphs)==null?void 0:h[0])==null?void 0:y.text)!=null?S:e.text)!=null?k:"").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=(A=(I=e.textStyle)==null?void 0:I.fontSize)!=null?A:wa(e);if(!i)return false;let a=(ae=(fe=(F=e.textStyle)==null?void 0:F.lineHeight)!=null?fe:(ee=(V=(L=e.textParagraphs)==null?void 0:L[0])==null?void 0:V.style)==null?void 0:ee.lineHeight)!=null?ae:1.2,s=i*12700*t*a;return e.bounds.height*t>=s*1.75}function zk(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 wa(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 oh(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 Vk(e){var r,o,i,a,s,l;let t=(r=e.textParagraphs)==null?void 0:r.filter(d=>d.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=(s=(a=t==null?void 0:t[0])==null?void 0:a.text)!=null?s:e.text)!=null?l:"";return n.length>0&&!n.includes(`
1751
+ `)&&!n.includes("\r")}function Gk(e){var o,i,a,s,l,d,u,f,p,b;if(((o=e.textBody)==null?void 0:o.wrap)!=="square"||((d=(i=e.textStyle)==null?void 0:i.alignment)!=null?d:(l=(s=(a=e.textParagraphs)==null?void 0:a[0])==null?void 0:s.style)==null?void 0:l.alignment)!=="center")return false;let t=((b=(p=(f=(u=e.textParagraphs)==null?void 0:u[0])==null?void 0:f.text)!=null?p:e.text)!=null?b:"").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 jk(e){var r,o,i,a,s,l,d;if(Gk(e))return true;if(((r=e.textBody)==null?void 0:r.wrap)!=="square")return false;let t=((s=(a=(i=(o=e.textParagraphs)==null?void 0:o[0])==null?void 0:i.text)!=null?a:e.text)!=null?s:"").trim();return t.length<18?false:((d=(l=t.match(/[\u3400-\u9fff]/g))==null?void 0:l.length)!=null?d:0)>=12?true:/[\s,。;、,.]/.test(t)}function Uk(e){var n,r,o,i,a;let t=(a=(n=e.textStyle)==null?void 0:n.alignment)!=null?a:(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 Kk(e){var t;return e.kind!=="textBox"||!e.text&&!((t=e.textParagraphs)!=null&&t.length)||e.customGeometry||ch(e)||ah(e)?false:!_k(e)&&!qk(e)}function _k(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 qk(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 Xk(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 ih(e,t){return t.some(n=>{var r;return !!((r=n.style)!=null&&r.bullet)||Yk(n.style)||n.runs.some(o=>!!o.hyperlink||o.style!==void 0&&tC(o.style,e.textStyle))})}function Yk(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 Zk(e,t,n,r={}){if(t){if(t.lineHeight!==void 0&&(e.style.lineHeight=String(Jk(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=ca(t.spaceBefore,n)),t.spaceAfter!==void 0&&(e.style.marginLeft=ca(t.spaceAfter,n));return}t.spaceBefore!==void 0&&(e.style.marginTop=ca(t.spaceBefore,n)),t.spaceAfter!==void 0&&(e.style.marginBottom=ca(t.spaceAfter,n));}}function Jk(e){var n;let t=(n=e.lineHeight)!=null?n:1.2;return e.bullet?t*1.15:t}function Qk(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`)),eC(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 eC(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 ca(e,t){return e>10?`${e*t}px`:`${e}em`}function tC(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 nC(e,t,n,r){var i,a,s,l;if(!rC(e,t,n,r))return Vm(n,n.style);let o=oC(t.runs.slice(0,r));return Vm(n,O(v({},n.style),{color:(a=(i=n.style)==null?void 0:i.color)!=null?a:"#000000",fontSize:(l=(s=n.style)==null?void 0:s.fontSize)!=null?l:Math.max(12,Math.round((o!=null?o:28)*.72))}))}function Vm(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 rC(e,t,n,r){var s,l,d;if(r<=0||(s=n.style)!=null&&s.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((d=i[1])!=null?d:"").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 oC(e){var t;for(let n of e)if(((t=n.style)==null?void 0:t.fontSize)!==void 0)return n.style.fontSize}function Vl(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=th(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=vr(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=ph(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 jl(e,t){if(t==="distributed"){e.style.textAlign="justify",e.style.textAlignLast="justify";return}e.style.textAlign=t==="justify"?"justify":t;}function ah(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 sh(e){return e.bounds.height>e.bounds.width?"vertical":"horizontal"}function zl(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?vr(e.fillGradient):(n=e==null?void 0:e.fillColor)!=null?n:"#fff"}function iC(e,t,n,r,o,i){if(t!=null&&t.imagePath){let a=i[t.imagePath],s=a==null?void 0:a.url;if(s&&Gl(a.contentType,t.imagePath)){e.style.backgroundImage=`url("${s}")`,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=zl(t,i);}function br(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 aC(e,t){var o,i,a;let n=(a=(o=e.presetAdjustments)==null?void 0:o.adj)!=null?a:(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 sC(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 lC(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=vr(e.fillGradient,yr(e)):e.fillColor&&(r.style.background=xr(e.fillColor,yr(e))),e.lineColor&&(r.style.borderStyle=Ul(e.lineDash),r.style.borderWidth=`${Math.max(1,((o=e.lineWidth)!=null?o:9525)*t)}px`,r.style.borderColor=xr(e.lineColor,e.lineOpacity)),r}function vr(e,t=1){return `linear-gradient(${lh(e)}deg, ${cC(e,t).join(", ")})`}function lh(e){return e.angle===void 0?160:dC(e.angle+90)}function dC(e){return (e%360+360)%360}function cC(e,t=1){return uC(e).map(n=>{let r=Math.max(0,Math.min(1,n.opacity*t)),o=r<1?dh(n.color,r):n.color;return n.position===void 0?o:`${o} ${n.position}%`})}function uC(e){return e.colors.map((t,n)=>{var a,s,l,d,u;let r=Kl(t),o=(a=e.positions)==null?void 0:a[n],i=Math.max(0,Math.min(1,(d=(l=(s=e.opacities)==null?void 0:s[n])!=null?l:r==null?void 0:r.opacity)!=null?d: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 dh(e,t){var a;let n=(a=e.match(/^#([0-9a-fA-F]{6})$/))==null?void 0:a[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 fC(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 Ul(e){return e==="dot"||e==="sysDot"?"dotted":e&&e!=="solid"?"dashed":"solid"}function xa(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 ch(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 pC(e,t){var p,b,w;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=mC(e,t,r,o);(e.shadow||i>0)&&(n.style.overflow="visible"),n.setAttribute("viewBox","0 0 100 100"),n.setAttribute("preserveAspectRatio","none");let a=e.fillGradient&&e.fillGradient.colors.length>1?`coco-ppt-preset-gradient-${e.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`:void 0,s=e.lineGradient&&e.lineGradient.colors.length>1?`coco-ppt-preset-line-gradient-${e.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`:void 0;if(a&&e.fillGradient&&Un(n,a,e.fillGradient),s&&e.lineGradient&&Un(n,s,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",Gm(e)),(e.presetGeometry==="donut"||e.presetGeometry==="blockArc")&&g.setAttribute("fill-rule","evenodd"),g.setAttribute("fill",hC(e)),g.setAttribute("transform",`translate(${hr(i*.38)} ${hr(i)})`),g.setAttribute("stroke","none"),n.append(g);}let l=document.createElementNS("http://www.w3.org/2000/svg","path");l.setAttribute("d",Gm(e)),(e.presetGeometry==="donut"||e.presetGeometry==="blockArc")&&l.setAttribute("fill-rule","evenodd");let d=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":a?`url(#${a})`:(b=e.fillColor)!=null?b:"none");let u=yr(e);u!==void 0&&e.presetGeometry!=="arc"&&l.setAttribute("fill-opacity",String(u)),l.setAttribute("stroke",s?`url(#${s})`:(w=e.lineColor)!=null?w:"none"),l.setAttribute("stroke-width",String(d)),e.lineOpacity!==void 0&&l.setAttribute("stroke-opacity",String(Math.max(0,Math.min(1,e.lineOpacity))));let f=xa(e.lineDash,d);return f&&l.setAttribute("stroke-dasharray",f),l.setAttribute("stroke-linejoin","round"),e.presetGeometry==="arc"&&(l.setAttribute("stroke-linecap","round"),yC(n,l,e)),n.append(l),n}function mC(e,t,n,r){var a,s;let o=(s=(a=e.threeD)==null?void 0:a.extrusionHeight)!=null?s: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 hC(e){var o,i,a,s,l;let t=(a=(i=(o=e.fillGradient)==null?void 0:o.colors[0])!=null?i:e.fillColor)!=null?a:"#64748B",n=Kl(t),r=((s=e.threeD)==null?void 0:s.material)==="translucentPowder"?.12:.18;return dh(gC((l=n==null?void 0:n.color)!=null?l:t,.8),r)}function gC(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),a=Number.parseInt(r.slice(4,6),16);return `#${wr(o*t)}${wr(i*t)}${wr(a*t)}`}function Gm(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 bC(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 xC(e);default:return ""}}function bC(e){var g,h,y,S,k,I;let t=((h=(g=e.presetAdjustments)==null?void 0:g.adj1)!=null?h:0)/6e4,n=((S=(y=e.presetAdjustments)==null?void 0:y.adj2)!=null?S:54e5)/6e4,r=wC(n-t),o=t+r,i=48,a=Math.max(.08,Math.min(.42,((I=(k=e.presetAdjustments)==null?void 0:k.adj3)!=null?I:25e3)/1e5)),s=i*(1-a),l=No(t,i),d=No(o,i),u=No(o,s),f=No(t,s),p=Math.abs(r)>180?1:0,b=r>=0?1:0,w=b?0:1;return [`M ${l.x.toFixed(3)} ${l.y.toFixed(3)}`,`A ${i} ${i} 0 ${p} ${b} ${d.x.toFixed(3)} ${d.y.toFixed(3)}`,`L ${u.x.toFixed(3)} ${u.y.toFixed(3)}`,`A ${s.toFixed(3)} ${s.toFixed(3)} 0 ${p} ${w} ${f.x.toFixed(3)} ${f.y.toFixed(3)}`,"Z"].join(" ")}function wC(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 xC(e){var s,l,d,u,f,p,b,w;let t=jm((l=(s=e.presetAdjustments)==null?void 0:s.adj1)!=null?l:18e6),n=jm((u=(d=e.presetAdjustments)==null?void 0:d.adj2)!=null?u:0),r=((p=(f=e.presetAdjustments)==null?void 0:f.adj1)!=null?p:18e6)/6e4,a=((((w=(b=e.presetAdjustments)==null?void 0:b.adj2)!=null?w:0)/6e4-r)%360+360)%360>180?1:0;return `M ${t.x.toFixed(3)} ${t.y.toFixed(3)} A 48 48 0 ${a} 1 ${n.x.toFixed(3)} ${n.y.toFixed(3)}`}function jm(e){return No(e/6e4,48)}function No(e,t){let n=e/180*Math.PI;return {x:50+t*Math.cos(n),y:50+t*Math.sin(n)}}function yC(e,t,n){var a,s;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",(s=(a=n.lineColor)!=null?a:n.fillColor)!=null?s:"#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 vC(e,t){if(!e.customGeometry||SC(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 SC(e){var s,l;if(e.paths.length!==1)return false;let t=e.paths[0];if(!t)return false;let n=(s=t.width)!=null?s:0,r=(l=t.height)!=null?l:0;if(n<=0||r<=0)return false;let o=[];for(let d of t.commands)if(d.kind==="moveTo"||d.kind==="lineTo")o.push({x:d.x,y:d.y});else if(d.kind!=="close")return false;let i=kC(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(d=>i.some(u=>ga(u.x,d.x)&&ga(u.y,d.y)))}function kC(e){let t=[];for(let n of e)t.some(r=>ga(r.x,n.x)&&ga(r.y,n.y))||t.push(n);return t}function ga(e,t){return Math.abs(e-t)<=1}function CC(e,t){var u,f,p,b,w,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=(w=(b=e.customGeometry)==null?void 0:b.paths[0])==null?void 0:w.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,"_")}`,a=document.createElementNS("http://www.w3.org/2000/svg","defs"),s=document.createElementNS("http://www.w3.org/2000/svg","clipPath");s.setAttribute("id",i);for(let S of (y=(h=e.customGeometry)==null?void 0:h.paths)!=null?y:[]){let k=document.createElementNS("http://www.w3.org/2000/svg","path");k.setAttribute("d",fh(S.commands)),uh(S.commands)&&k.setAttribute("fill-rule","evenodd"),s.append(k);}a.append(s),n.append(a);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 d=EC(e,r,o);return l.setAttribute("x",String(d.x)),l.setAttribute("y",String(d.y)),l.setAttribute("width",String(d.width)),l.setAttribute("height",String(d.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 EC(e,t,n){var u,f,p,b,w,g,h,y;if(e.imageFillRect){let S=(u=e.imageFillRect.left)!=null?u:0,k=(f=e.imageFillRect.right)!=null?f:0,I=(p=e.imageFillRect.top)!=null?p:0,A=(b=e.imageFillRect.bottom)!=null?b:0;return {x:S*t,y:I*n,width:Math.max(.01,1-S-k)*t,height:Math.max(.01,1-I-A)*n}}let r=e.imageCrop;if(!r)return {x:0,y:0,width:t,height:n};let o=(w=r.left)!=null?w:0,i=(g=r.right)!=null?g:0,a=(h=r.top)!=null?h:0,s=(y=r.bottom)!=null?y:0,l=Math.max(.01,1-o-i),d=Math.max(.01,1-a-s);return {x:-o/l*t,y:-a/d*n,width:1/l*t,height:1/d*n}}function IC(e,t){var s,l,d,u,f,p,b,w,g,h;let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.classList.add("coco-ppt-custom-geometry");let r=(d=(l=(s=e.customGeometry)==null?void 0:s.paths[0])==null?void 0:l.width)!=null?d: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,a=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&&Un(n,i,e.fillGradient),a&&e.lineGradient&&Un(n,a,e.lineGradient);for(let y of (w=(b=e.customGeometry)==null?void 0:b.paths)!=null?w:[]){let S=TC(e,y),k=NC(y),I=k?document.createElementNS("http://www.w3.org/2000/svg","ellipse"):document.createElementNS("http://www.w3.org/2000/svg","path");k?(I.setAttribute("cx",String(k.cx)),I.setAttribute("cy",String(k.cy)),I.setAttribute("rx",String(k.rx)),I.setAttribute("ry",String(k.ry))):(I.setAttribute("d",fh(y.commands)),uh(y.commands)&&I.setAttribute("fill-rule","evenodd"));let A=!(e.kind==="line"&&e.lineDash);I.setAttribute("fill",A?i?`url(#${i})`:(g=e.fillColor)!=null?g:"none":"none");let F=yr(e);A&&F!==void 0&&I.setAttribute("fill-opacity",String(F)),I.setAttribute("stroke",a?`url(#${a})`:(h=e.lineColor)!=null?h:"none"),I.setAttribute("stroke-width",String(S)),e.lineOpacity!==void 0&&I.setAttribute("stroke-opacity",String(Math.max(0,Math.min(1,e.lineOpacity))));let L=xa(e.lineDash,S);L&&I.setAttribute("stroke-dasharray",L),I.setAttribute("stroke-linejoin","round"),I.setAttribute("stroke-linecap","round"),n.append(I);}return n}function NC(e){var u,f,p,b,w,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"||((b=r[3])==null?void 0:b.kind)!=="cubicBezierTo"||((w=r[4])==null?void 0:w.kind)!=="cubicBezierTo"||((g=r[5])==null?void 0:g.kind)!=="close")return;let o=t/2,i=n/2,a=[r[0],r[1],r[2],r[3],r[4]],s=[{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 a.every((h,y)=>h.kind!=="moveTo"&&h.kind!=="cubicBezierTo"?false:Math.abs(h.x-s[y].x)<=l&&Math.abs(h.y-s[y].y)<=l)?{cx:o,cy:i,rx:t/2,ry:n/2}:void 0}function uh(e){return e.filter(t=>t.kind==="moveTo").length>1}function TC(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(a=>a!==void 0&&Number.isFinite(a)&&a>0),i=o.length>0?Math.max(...o):1;return Math.max(.5,e.lineWidth*i)}function PC(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),a=i/2,s=`coco-ppt-line-gradient-${e.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`;n.setAttribute("viewBox",`0 0 ${r} ${o}`),n.setAttribute("preserveAspectRatio","none"),Un(n,s,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-a))),l.setAttribute("ry",String(Math.max(0,o/2-a)))):(l.setAttribute("x",String(a)),l.setAttribute("y",String(a)),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,br(e)*t-a))),l.setAttribute("ry",String(Math.max(0,br(e)*t-a)))),l.setAttribute("fill","none"),l.setAttribute("stroke",`url(#${s})`),l.setAttribute("stroke-width",String(i)),e.lineOpacity!==void 0&&l.setAttribute("stroke-opacity",String(Math.max(0,Math.min(1,e.lineOpacity))));let d=xa(e.lineDash,i);return d&&l.setAttribute("stroke-dasharray",d),n.append(l),n}function RC(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),a=e.kind!=="picture",s=a?i/2:0;a||(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-s))),l.setAttribute("ry",String(Math.max(0,o/2-s)));else {l.setAttribute("x",String(s)),l.setAttribute("y",String(s)),l.setAttribute("width",String(Math.max(0,r-s*2))),l.setAttribute("height",String(Math.max(0,o-s*2)));let p=e.presetGeometry==="roundRect"||e.presetGeometry==="round1Rect"?Math.max(0,br(e)*t-s):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 d=xa(e.lineDash,i);return d&&l.setAttribute("stroke-dasharray",d),n.append(l),n}function MC(e,t){var w,g;let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.classList.add("coco-ppt-line-geometry");let r=sh(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 a=Math.max(1,((w=e.lineWidth)!=null?w:9525)*t),s=e.lineGradient&&e.lineGradient.colors.length>1?`coco-ppt-connector-gradient-${e.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`:void 0;s&&e.lineGradient&&Un(n,s,e.lineGradient);let l=s?`url(#${s})`:xr((g=e.lineColor)!=null?g:"#000000",e.lineOpacity),d=AC(a),u=Math.max(5,a*3.2),f=Math.max(5,a*2.6),p=Um(e.lineHeadEnd),b=Um(e.lineTailEnd);if(r){let h=o/2,y=p?Math.min(i,u):0,S=b?Math.max(0,i-u):i;Sr(n,h,y,h,S,l,a,e.lineOpacity,e.lineCap),e.lineHeadEnd==="oval"&&En(n,h,0,d,l),e.lineTailEnd==="oval"&&En(n,h,i,d,l),p&&pa(n,h,0,"up",u,f,l,e.lineOpacity),b&&pa(n,h,i,"down",u,f,l,e.lineOpacity);}else {let h=i/2,y=p?Math.min(o,u):0,S=b?Math.max(0,o-u):o;Sr(n,y,h,S,h,l,a,e.lineOpacity,e.lineCap),e.lineHeadEnd==="oval"&&En(n,0,h,d,l),e.lineTailEnd==="oval"&&En(n,o,h,d,l),p&&pa(n,0,h,"left",u,f,l,e.lineOpacity),b&&pa(n,o,h,"right",u,f,l,e.lineOpacity);}return n}function AC(e){return Math.max(3,e*3)}function Um(e){return e==="arrow"||e==="triangle"}function fh(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=LC(r,n);o&&(t.push(o.path),n=o.end);}else t.push("Z");return t.join(" ")}function LC(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=Km(e.wR,e.hR,n),a={x:t.x-i.x,y:t.y-i.y},s=Km(e.wR,e.hR,o),l={x:a.x+s.x,y:a.y+s.y},d=Math.abs(r)>180?1:0,u=r>=0?1:0;return {path:`A ${hr(e.wR)} ${hr(e.hR)} 0 ${d} ${u} ${hr(l.x)} ${hr(l.y)}`,end:l}}function Km(e,t,n){let r=n/180*Math.PI;return {x:e*Math.cos(r),y:t*Math.sin(r)}}function hr(e){return Number.isInteger(e)?String(e):e.toFixed(3).replace(/\.?0+$/,"")}function Un(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,a=Array.isArray(n)?void 0:n.opacities,s=document.createElementNS("http://www.w3.org/2000/svg","linearGradient"),l=Array.isArray(n)?{x1:0,y1:0,x2:100,y2:100}:WC(lh(n));s.setAttribute("id",t),s.setAttribute("x1",`${l.x1}%`),s.setAttribute("y1",`${l.y1}%`),s.setAttribute("x2",`${l.x2}%`),s.setAttribute("y2",`${l.y2}%`),o.map((d,u)=>{var w,g,h,y;let f=(w=i==null?void 0:i[u])!=null?w:u/Math.max(1,o.length-1)*100,p=Kl(d),b=Math.max(0,Math.min(1,(h=(g=a==null?void 0:a[u])!=null?g:p==null?void 0:p.opacity)!=null?h:1));return {color:(y=p==null?void 0:p.color)!=null?y:d,offset:Math.max(0,Math.min(100,f)),opacity:b}}).sort((d,u)=>d.offset-u.offset).forEach(d=>{let u=document.createElementNS("http://www.w3.org/2000/svg","stop");u.setAttribute("offset",`${d.offset}%`),u.setAttribute("stop-color",d.color),d.opacity<1&&u.setAttribute("stop-opacity",String(d.opacity)),s.append(u);}),r.append(s),e.append(r);}function WC(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:ua(50-n*o),y1:ua(50-r*o),x2:ua(50+n*o),y2:ua(50+r*o)}}function ua(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:`#${wr(n)}${wr(r)}${wr(o)}`,opacity:i}}function wr(e){return Math.round(e).toString(16).padStart(2,"0").toUpperCase()}function BC(e,t,n=true){var d,u,f,p,b,w,g,h,y,S,k,I,A,F,L;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),a=Math.max(o.columnCount,...o.values.map(V=>V.length),1),s=(u=(d=o.columnWidths)==null?void 0:d.reduce((V,ee)=>V+ee,0))!=null?u:0;if(s>0){let V=document.createElement("colgroup");for(let ee=0;ee<a;ee++){let fe=document.createElement("col"),ae=(f=o.columnWidths)==null?void 0:f[ee];ae&&(fe.style.width=`${ae/s*100}%`),V.append(fe);}r.append(V);}let l=(b=(p=o.rowHeights)==null?void 0:p.reduce((V,ee)=>V+ee,0))!=null?b:0;for(let V=0;V<i;V++){let ee=document.createElement("tr"),fe=(w=o.rowHeights)==null?void 0:w[V];ee.style.height=l>0&&fe?`${fe/l*100}%`:`${100/i}%`;for(let ae=0;ae<a;ae++){let oe=$C(o,V,ae);if(oe!=null&&oe.hMerge||oe!=null&&oe.vMerge)continue;let ie=document.createElement("td"),U=(h=(g=o.cellStyles)==null?void 0:g[V])==null?void 0:h[ae];n&&(ie.dataset.row=String(V),ie.dataset.column=String(ae));let J=(S=(y=o.values[V])==null?void 0:y[ae])!=null?S:"";if(ie.dataset.cellText=J,FC(ie,J),oe!=null&&oe.columnSpan&&oe.columnSpan>1&&(ie.colSpan=oe.columnSpan),oe!=null&&oe.rowSpan&&oe.rowSpan>1&&(ie.rowSpan=oe.rowSpan),U!=null&&U.fillGradient&&U.fillGradient.colors.length>1?ie.style.background=vr(U.fillGradient):U!=null&&U.fillColor&&!HC(U.fillColor)&&(ie.style.background=U.fillColor),U!=null&&U.body){let B=U.body,G=(k=B.insetLeft)!=null?k:91440,$=(I=B.insetTop)!=null?I:45720,K=(A=B.insetRight)!=null?A:91440,X=(F=B.insetBottom)!=null?F:45720;ie.style.padding=`${$*t}px ${K*t}px ${X*t}px ${G*t}px`,B.anchor==="middle"&&(ie.style.verticalAlign="middle"),B.anchor==="bottom"&&(ie.style.verticalAlign="bottom"),B.anchor==="top"&&(ie.style.verticalAlign="top");}U!=null&&U.textStyle&&Vl(ie,U.textStyle,t),(L=U==null?void 0:U.textStyle)!=null&&L.alignment&&jl(ie,U.textStyle.alignment),DC(ie,U,t),ee.append(ie);}r.append(ee);}return r}function DC(e,t,n){let r=t==null?void 0:t.borders;r&&(fa(e,"Left",r.left,n),fa(e,"Right",r.right,n),fa(e,"Top",r.top,n),fa(e,"Bottom",r.bottom,n));}function fa(e,t,n,r){var s,l;if(!n)return;let o=`border${t}Style`,i=`border${t}Width`,a=`border${t}Color`;if(n.hidden){e.style[o]="none",e.style[i]="0";return}e.style[o]=Ul(n.dash),e.style[i]=`${Math.max(1,((s=n.width)!=null?s:9525)*r)}px`,e.style[a]=xr((l=n.color)!=null?l:"#94A3B8",n.opacity);}function FC(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 _m(e,t,n,r){var o,i,a,s,l;return (l=(s=(a=e.dataset.cellText)!=null?a:(i=(o=t.table)==null?void 0:o.values[n])==null?void 0:i[r])!=null?s:e.textContent)!=null?l:""}function HC(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 ph(e,t){var s,l,d;let n=((s=e.distance)!=null?s:0)*t,r=((l=e.direction)!=null?l:0)*Math.PI/180,o=Math.cos(r)*n,i=Math.sin(r)*n,a=((d=e.blur)!=null?d:0)*t;return `${o}px ${i}px ${a}px ${OC(e)}`}function OC(e){var l,d;let t=(l=e.color)!=null?l:"#000000",n=(d=e.opacity)!=null?d:.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),a=Number.parseInt(o.slice(2,4),16),s=Number.parseInt(o.slice(4,6),16);return `rgba(${i}, ${a}, ${s}, ${Math.max(0,Math.min(1,n))})`}function $C(e,t,n){var r;return (r=e.mergedCells)==null?void 0:r.find(o=>o.row===t&&o.column===n)}function zC(e){var h,y,S,k,I,A,F,L,V,ee,fe,ae,oe,ie,U,J;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 St(t,(y=e.name)!=null?y:"Chart",4,8,4,"#17202a"),t;let r=(k=(S=e.chart)==null?void 0:S.type)!=null?k:"",o=(I=e.chart)==null?void 0:I.grouping,i=VC(n.series,r,o),a=Math.max(...i,1),s=Math.min(...i,0),l=(F=(A=e.chart)==null?void 0:A.axes)==null?void 0:F.value,d=(V=(L=e.chart)==null?void 0:L.axes)==null?void 0:V.category,u=(ee=l==null?void 0:l.min)!=null?ee:s>=0?0:s,f=(fe=l==null?void 0:l.max)!=null?fe:s>=0?UC(a):a,p=GC(e),b=KC(u,f,l==null?void 0:l.majorUnit);if(r.includes("doughnut")||r.includes("pie"))return oE(t,n.series,p),t;if(r.includes("radar"))return lE(t,n.series,p,(ae=l==null?void 0:l.max)!=null?ae:a),t;(l==null?void 0:l.majorGridlines)!==false&&XC(t,p,b,e,l,d),(l==null?void 0:l.deleted)!==true&&(l==null?void 0:l.tickLabelPosition)!=="none"&&YC(t,p,u,f,b),_C(t,e,p);let w=n.series.filter(B=>{var G,$,K;return ((K=($=B.type)!=null?$:(G=e.chart)==null?void 0:G.type)!=null?K:"").includes("bar")}),g=n.series.filter(B=>{var G;return ((G=B.type)!=null?G:"").includes("line")});return w.length>0?(QC(t,w,p,u,f,e,o),Ym(t,(ie=(oe=w[0])==null?void 0:oe.categories)!=null?ie:[],p),w.some(B=>B.showValueLabels)&&rE(t,w,p,u,f),g.length>0&&qm(t,g,p,u,f,void 0,e),g.some(B=>B.showValueLabels)&&Zm(t,g,p,u,f)):(qm(t,n.series,p,u,f,["#22C7F2","#22C7F2","#94A3B8","#F59E0B"],e),Ym(t,(J=(U=n.series.find(B=>{var G;return (G=B.categories)==null?void 0:G.length}))==null?void 0:U.categories)!=null?J:[],p),n.series.some(B=>B.showValueLabels)&&Zm(t,n.series,p,u,f)),t}function VC(e,t,n){var a;let r=e.filter(s=>{var l;return ((l=s.type)!=null?l:t).includes("bar")});if(!hh(n)||r.length<=1)return e.flatMap(s=>s.values);let o=Math.max(...r.map(s=>s.values.length),1),i=[];for(let s=0;s<o;s++){let l=0,d=0;for(let u of r){let f=(a=u.values[s])!=null?a:0;f>=0?l+=f:d+=f;}i.push(l,d);}return i}function GC(e){var u,f,p,b,w,g,h,y,S,k,I,A,F,L,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 gh((g=(w=(b=e.chart)==null?void 0:b.data)==null?void 0:w.series)!=null?g:[])?{left:7,top:8,width:88,height:40}:jC(e)?{left:18,top:8,width:72,height:40}:((S=(y=(h=e.chart)==null?void 0:h.axes)==null?void 0:y.value)==null?void 0:S.deleted)===true?{left:6,top:8,width:90,height:40}:{left:18,top:8,width:76,height:40};let o=((A=(I=(k=e.chart)==null?void 0:k.axes)==null?void 0:I.value)==null?void 0:A.deleted)!==true&&!n.includes("doughnut")&&!n.includes("pie")&&!n.includes("radar")?14:4,i=((F=t.x)!=null?F:.12)*100,a=((L=t.y)!=null?L:.13)*60,s=((V=t.width)!=null?V:.82)*100,l=((ee=t.height)!=null?ee:.67)*60,d=Math.max(o,Math.min(20,i));return {left:d,top:Math.max(3,Math.min(12,a)),width:Math.max(40,Math.min(92,Math.min(s,96-d))),height:Math.max(24,Math.min(50,l))}}function jC(e){var i,a,s,l,d,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=(s=(a=t.data)==null?void 0:a.series)!=null?s:[];if(r.length!==1)return false;let o=Math.max((u=(d=(l=r[0])==null?void 0:l.categories)==null?void 0:d.length)!=null?u:0,(p=(f=r[0])==null?void 0:f.values.length)!=null?p:0);return o>0&&o<=2}function UC(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 KC(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 _C(e,t,n){var d,u,f,p,b,w,g;let r=(p=(d=t.chart)==null?void 0:d.title)!=null?p:(f=(u=t.chart)==null?void 0:u.data)==null?void 0:f.title;r&&St(e,r,n.left+n.width*.5,Math.max(4,n.top-3.2),3.1,"#17202A","middle");let o=(g=(w=(b=t.chart)==null?void 0:b.data)==null?void 0:w.series)!=null?g:[],i=o.map(h=>h.name).filter(h=>!!h).slice(0,4);if(i.length===0)return;let a=["#C50D13","#0EA5E9","#F59E0B","#A3E635"],s=n.left+n.width*.78,l=Math.max(4,n.top-2.4);i.forEach((h,y)=>{var I,A,F,L,V,ee;let S=(I=o.find(fe=>fe.name===h))!=null?I:o[y],k=S?qC(e,S,y,a):a[y];S&&((A=S.type)!=null?A:"").includes("line")?(Sr(e,s,l-1.1,s+2.3,l-1.1,k,.45),En(e,s+1.15,l-1.1,.45,(L=(F=S.marker)==null?void 0:F.fillColor)!=null?L:"#FFFFFF",(ee=(V=S.marker)==null?void 0:V.lineColor)!=null?ee:k,.32),St(e,h,s+2.8,l-.45,2.2,"#64748B")):(Po(e,s,l-1.8,1.4,1.4,k),St(e,h,s+2,l-.45,2.2,"#64748B")),s+=Math.max(9,Array.from(h).length*2.2+4.5);});}function qC(e,t,n,r){var o,i;return ((o=t.type)!=null?o:"").includes("line")?(i=t.lineColor)!=null?i:r[n]:ya(e,t,n,r)}function XC(e,t,n,r,o,i){var l,d;let a=(l=o==null?void 0:o.gridlineColor)!=null?l:"#E8EDF3",s=Xm(o==null?void 0:o.gridlineWidth,r,.35);for(let u=0;u<=n;u++){let f=t.top+t.height/n*u;Sr(e,t.left,f,t.left+t.width,f,a,s);}Sr(e,t.left,t.top+t.height,t.left+t.width,t.top+t.height,(d=i==null?void 0:i.lineColor)!=null?d:"#CBD5E1",Xm(i==null?void 0:i.lineWidth,r,.45));}function YC(e,t,n,r,o){for(let i=0;i<=o;i++){let a=r-(r-n)/o*i,s=t.top+t.height/o*i+1;St(e,_l(a),t.left-1.8,s,3,"#9AA6B2","end");}}function _l(e){return Number.isInteger(e)?String(e):e.toFixed(1).replace(/\.0$/,"")}function qm(e,t,n,r,o,i=["#CBD5E1","#94A3B8","#F59E0B","#A3E635"],a){t.forEach((s,l)=>{var p,b,w,g,h,y,S;if(s.values.length===0)return;let d=s.values.map((k,I)=>{let A=n.left+(s.values.length===1?n.width/2:n.width*I/(s.values.length-1)),F=n.top+n.height-(k-r)/Math.max(1,o-r)*n.height;return {x:A,y:F}}),u=JC(d,s.smooth===true),f=(p=s.lineColor)!=null?p:i[l%i.length];if(xh(e,u,f,mh(s,a)),((b=s.marker)==null?void 0:b.symbol)!=="none"){let k=Math.max(.5,Math.min(1.6,((g=(w=s.marker)==null?void 0:w.size)!=null?g:5)*.18)),I=(y=(h=s.marker)==null?void 0:h.fillColor)!=null?y:f,A=(S=s.marker)==null?void 0:S.lineColor,F=ZC(s,a);d.forEach(L=>En(e,L.x,L.y,k,I,A,F));}});}function ZC(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 mh(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 JC(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],a=e[r+1],s=e[Math.min(e.length-1,r+2)],l={x:i.x+(a.x-o.x)/6,y:i.y+(a.y-o.y)/6},d={x:a.x-(s.x-i.x)/6,y:a.y-(s.y-i.y)/6};n.push(`C ${l.x} ${l.y} ${d.x} ${d.y} ${a.x} ${a.y}`);}return n.join(" ")}function QC(e,t,n,r,o,i,a){if(hh(a)&&t.length>1){tE(e,t,n,r,o,i);return}if(gh(t)){eE(e,t,n,r,o,i);return}let s=["#C50D13","#0EA5E9","#F59E0B","#A3E635"],l=Math.max(...t.map(f=>f.values.length),1),d=n.width/l,u=Math.max(1,d*.48/Math.max(t.length,1));t.forEach((f,p)=>{let b=ya(e,f,p,s);f.values.forEach((w,g)=>{var k,I;let h=(w-r)/Math.max(1,o-r)*n.height,y=n.left+g*d+(d-u*t.length)/2+p*u,S=n.top+n.height-h;Po(e,y,S,u,h,(I=(k=f.pointColors)==null?void 0:k[g])!=null?I:b,f.borderColor,ql(f,i));});});}function eE(e,t,n,r,o,i){let a=["#C50D13","#0EA5E9","#F59E0B","#A3E635"],s=Math.max(...t.map(u=>u.values.length),1),l=n.width/s,d=Math.max(1,l*.34);t.forEach((u,f)=>{let p=ya(e,u,f,a);u.values.forEach((b,w)=>{var S,k;let g=ba(b,n,r,o),h=ba(0,n,r,o),y=n.left+w*l+(l-d)/2;Po(e,y,Math.min(g,h),d,Math.max(.1,Math.abs(h-g)),(k=(S=u.pointColors)==null?void 0:S[w])!=null?k:p,u.borderColor,ql(u,i));});});}function tE(e,t,n,r,o,i){let a=["#C50D13","#0EA5E9","#F59E0B","#A3E635"],s=Math.max(...t.map(p=>p.values.length),1),l=n.width/s,d=Math.max(1,l*.46),u=new Array(s).fill(Math.max(0,r)),f=new Array(s).fill(Math.min(0,o));t.forEach((p,b)=>{let w=ya(e,p,b,a);p.values.forEach((g,h)=>{var F,L;let y=g>=0?u[h]:f[h],S=y+g,k=ba(y,n,r,o),I=ba(S,n,r,o),A=n.left+h*l+(l-d)/2;Po(e,A,Math.min(k,I),d,Math.max(.1,Math.abs(I-k)),(L=(F=p.pointColors)==null?void 0:F[h])!=null?L:w,p.borderColor,ql(p,i)),g>=0?u[h]=S:f[h]=S;});});}function ba(e,t,n,r){return t.top+t.height-(e-n)/Math.max(1,r-n)*t.height}function hh(e){return e==="stacked"||e==="percentStacked"}function gh(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 ql(e,t){if(e.borderWidth)return bh(t!=null&&t.bounds.width?e.borderWidth/t.bounds.width*100:void 0,void 0)}function Xm(e,t,n){var r;return (r=bh(e!==void 0&&t.bounds.width?e/t.bounds.width*100:void 0,n))!=null?r:n}function bh(e,t){return e===void 0?t:Math.max(.15,Math.min(1.4,e))}function ya(e,t,n,r){var o,i;if((o=t.fillGradient)!=null&&o.colors.length&&t.fillGradient.colors.length>1){let a=`coco-chart-gradient-${n}-${t.fillGradient.colors.join("-").replace(/[^a-zA-Z0-9_-]/g,"_")}`;return Un(e,a,t.fillGradient),`url(#${a})`}return (i=t.fillColor)!=null?i:r[n%r.length]}function nE(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 Ym(e,t,n){if(t.length===0)return;let r=n.width/t.length;t.forEach((o,i)=>{St(e,o,n.left+r*i+r/2,n.top+n.height+5.2,3.2,"#64748B","middle");});}function rE(e,t,n,r,o){let i=Math.max(...t.map(l=>l.values.length),1),a=n.width/i,s=Math.max(1,a*.48/Math.max(t.length,1));t.forEach((l,d)=>{l.showValueLabels&&l.values.forEach((u,f)=>{let p=(u-r)/Math.max(1,o-r)*n.height,b=n.left+f*a+(a-s*t.length)/2+d*s+s/2,w=n.top+n.height-p-2;St(e,String(u),b,w,3,"#A7AEB8","middle");});});}function Zm(e,t,n,r,o){t.forEach(i=>{!i.showValueLabels||i.values.length===0||i.values.forEach((a,s)=>{let l=n.left+(i.values.length===1?n.width/2:n.width*s/(i.values.length-1)),d=n.top+n.height-(a-r)/Math.max(1,o-r)*n.height;St(e,String(a),l,Math.max(n.top+2,d-2.2),2.6,"#374151","middle");});});}function oE(e,t,n){var b;let r=t[0];if(!(r!=null&&r.values.length))return;let o=["#1D4ED8","#E3B363","#60A5FA","#94A3B8","#F59E0B","#22C7F2"],i=r.values.reduce((w,g)=>w+Math.max(0,g),0)||1,a=n.left+n.width*.42,s=n.top+n.height*.5,l=Math.min(n.width,n.height)*.34,d=l*.58,u=-90;r.values.forEach((w,g)=>{let h=Math.max(0,w)/i*360,y=u,S=u+h;if(dE(e,a,s,l,d,y,S,nE(r,g,o)),r.showCategoryNameLabels||r.showPercentLabels||r.showValueLabels){let k=iE(r,w,g,i);if(k.length>0){let I=aE(r,g,a,s,l+3.6,n,(y+S)/2);pE(e,k,I.x,I.y,1.9,"#334155",I.x>=a?"start":"end");}}u+=h;}),En(e,a,s,d*.92,"#FFFFFF");let f=sE(r.name);f&&St(e,f,a,s-1.8,1.8,"#64748B","middle");let p=r.values[0];p!==void 0&&St(e,wh(p,i),a,s+3.4,3.9,"#1E3A8A","middle"),cE(e,(b=r.categories)!=null?b:[],o,n.left+n.width*.72,n.top+9);}function iE(e,t,n,r){var a;let o=[],i=(a=e.categories)==null?void 0:a[n];return e.showCategoryNameLabels&&i&&o.push(i),e.showValueLabels&&o.push(_l(t)),e.showPercentLabels&&o.push(wh(t,r)),o}function aE(e,t,n,r,o,i,a){return gr(n,r,o,a)}function wh(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 sE(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 lE(e,t,n,r){var d;let o=t[0];if(!(o!=null&&o.values.length))return;let i=o.values.length,a=n.left+n.width*.48,s=n.top+n.height*.5,l=Math.min(n.width,n.height)*.35;for(let u=1;u<=4;u++)xh(e,uE(i,a,s,l*u/4),"#CBD5E1",.25);for(let u=0;u<i;u++){let f=ma(u,i,a,s,l);Sr(e,a,s,f.x,f.y,"#E2E8F0",.25);}t.forEach((u,f)=>{var w;if(!u.values.length)return;let p=u.values.slice(0,i).map((g,h)=>ma(h,i,a,s,Math.max(0,g)/Math.max(1,r)*l)),b=document.createElementNS("http://www.w3.org/2000/svg","path");b.setAttribute("d",p.map((g,h)=>`${h===0?"M":"L"} ${g.x} ${g.y}`).join(" ")+" Z"),b.setAttribute("fill",f===0?"rgba(37, 99, 235, 0.08)":"none"),b.setAttribute("stroke",(w=u.lineColor)!=null?w:"#2563EB"),b.setAttribute("stroke-width",String(mh(u,void 0))),e.append(b),u.marker&&u.marker.symbol!=="none"&&p.forEach(g=>{var h;return En(e,g.x,g.y,.9,(h=u.lineColor)!=null?h:"#2563EB")}),u.showValueLabels&&u.values.slice(0,i).forEach((g,h)=>{var S;let y=p[h];St(e,_l(g),y.x,y.y-1.2,2.2,(S=u.lineColor)!=null?S:"#2563EB","middle");});}),((d=o.categories)!=null?d:[]).slice(0,i).forEach((u,f)=>{let p=ma(f,i,a,s,l+5);St(e,u,p.x,p.y+1,2.6,"#64748B","middle");});}function dE(e,t,n,r,o,i,a,s){let d=Math.max(.01,a-i)>180?1:0,u=gr(t,n,r,i),f=gr(t,n,r,a),p=gr(t,n,o,a),b=gr(t,n,o,i),w=document.createElementNS("http://www.w3.org/2000/svg","path");w.setAttribute("d",[`M ${u.x} ${u.y}`,`A ${r} ${r} 0 ${d} 1 ${f.x} ${f.y}`,`L ${p.x} ${p.y}`,`A ${o} ${o} 0 ${d} 0 ${b.x} ${b.y}`,"Z"].join(" ")),w.setAttribute("fill",s),e.append(w);}function cE(e,t,n,r,o){t.slice(0,6).forEach((i,a)=>{Po(e,r,o+a*5,2.4,2.4,n[a%n.length]),St(e,i,r+3.6,o+a*5+2.2,2.7,"#334155");});}function uE(e,t,n,r,o){return Array.from({length:e},(i,a)=>{let s=ma(a,e,t,n,r);return `${a===0?"M":"L"} ${s.x} ${s.y}`}).join(" ")+(" Z")}function ma(e,t,n,r,o){return gr(n,r,o,-90+360*e/t)}function gr(e,t,n,r){let o=r*Math.PI/180;return {x:e+Math.cos(o)*n,y:t+Math.sin(o)*n}}function Sr(e,t,n,r,o,i,a,s,l){let d=document.createElementNS("http://www.w3.org/2000/svg","line");d.setAttribute("x1",String(t)),d.setAttribute("y1",String(n)),d.setAttribute("x2",String(r)),d.setAttribute("y2",String(o)),d.setAttribute("stroke",i),d.setAttribute("stroke-width",String(a)),d.setAttribute("stroke-linecap",fE(l)),s!==void 0&&d.setAttribute("stroke-opacity",String(Math.max(0,Math.min(1,s)))),e.append(d);}function fE(e){return e==="rnd"?"round":e==="sq"?"square":"butt"}function xh(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 En(e,t,n,r,o,i,a){let s=document.createElementNS("http://www.w3.org/2000/svg","circle");s.setAttribute("cx",String(t)),s.setAttribute("cy",String(n)),s.setAttribute("r",String(r)),s.setAttribute("fill",o),i&&s.setAttribute("stroke",i),a!==void 0&&s.setAttribute("stroke-width",String(a)),e.append(s);}function pa(e,t,n,r,o,i,a,s){let l=i/2,d=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",d.map(f=>f.join(",")).join(" ")),u.setAttribute("fill",a),s!==void 0&&u.setAttribute("fill-opacity",String(Math.max(0,Math.min(1,s)))),e.append(u);}function Po(e,t,n,r,o,i,a,s){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),a&&s!==void 0&&(l.setAttribute("stroke",a),l.setAttribute("stroke-width",String(s))),e.append(l);}function St(e,t,n,r,o,i,a="start"){let s=document.createElementNS("http://www.w3.org/2000/svg","text");s.setAttribute("x",String(n)),s.setAttribute("y",String(r)),s.setAttribute("font-size",String(o)),s.setAttribute("fill",i),s.setAttribute("text-anchor",a),s.textContent=t,e.append(s);}function pE(e,t,n,r,o,i,a="start"){t.forEach((s,l)=>{St(e,s,n,r+l*o*1.2,o,i,a);});}
1752
+ exports.DEFAULT_PPT_SLIDE_SIZE=T0;exports.EditorReadOnlyError=mn;exports.NATIVE_BLOCK_CLIPBOARD_TYPE=ki;exports.PptEditorSession=ia;exports.SPREADSHEET_CLIPBOARD_MIME=ur;exports.SPREADSHEET_COLUMN_RESIZE_MIN=BT;exports.SPREADSHEET_RESIZE_HIT_TOLERANCE=FT;exports.SPREADSHEET_ROW_RESIZE_MIN=DT;exports.SpreadsheetCanvasRenderer=qi;exports.SpreadsheetCellEditor=Qi;exports.SpreadsheetEditorRuntime=Ji;exports.SpreadsheetLayout=Oi;exports.SpreadsheetViewportManager=Vi;exports.adjacentNativeListNumbering=$c;exports.allNativeParagraphs=_e;exports.analyzeNativeTableRowPagination=us;exports.applyNativeWordChangesToPackage=uI;exports.applySpreadsheetAgentAction=RT;exports.applyWheelDelta=om;exports.applyWordOoxmlPatches=sy;exports.bodyParagraphs=bf;exports.buildPptEditorViewFromModel=EP;exports.buildPptEditorViewFromPptx=CP;exports.buildPptEditorViewFromPresentation=Em;exports.buildPptPresentationScene=Co;exports.buildPptSceneNode=Eo;exports.buildPptSlideScene=P0;exports.buildSpreadsheetAutoFillPlan=Dp;exports.buildSpreadsheetClipboardPayload=Zi;exports.buildSpreadsheetReplacePlan=Gp;exports.buildSpreadsheetSheetRenderModel=po;exports.buildWordEditorView=kE;exports.buildWordEditorViewFromDocx=vE;exports.buildWordEditorViewFromFlatOpc=SE;exports.buildWordEditorViewFromPackage=Ya;exports.canDispatchNativeWordCommand=Wt;exports.clampScroll=fS;exports.clearNativeImageSelection=Pt;exports.clearSpreadsheetRange=rT;exports.clipboardHtml=yl;exports.clipboardToken=yo;exports.cloneNativeWordBlocks=rt;exports.collectNativeParagraphs=NE;exports.colorToCss=Qn;exports.computeScrollbarState=im;exports.copybookGuideAppearance=y0;exports.createColumnRangeSelection=WN;exports.createColumnSelection=Yi;exports.createNativeListNumbering=fs;exports.createNativeParaId=Bn;exports.createNativeSelectionRange=Os;exports.createNativeTextRange=pf;exports.createNativeWordDocument=ss;exports.createRowRangeSelection=LN;exports.createRowSelection=Xi;exports.createSelection=it;exports.createWordEditingPlugin=RI;exports.cssPixelsToExcelColumnWidth=zi;exports.currentNativeCursor=pt;exports.currentNativeSelection=ze;exports.defineNativeWordElements=Ru;exports.excelColumnWidthToCssPixels=cS;exports.expandRangeForMergedRanges=ES;exports.expandSelectionForMergedRanges=ct;exports.extendSelection=cr;exports.findNativeParagraph=Z;exports.findNativeParagraphLocation=ve;exports.findNativeTableCellLocation=rn;exports.findNativeTableLocation=Oe;exports.findPptSceneNode=Io;exports.findPptSceneSlide=fr;exports.findSpreadsheetMatches=sT;exports.formatSpreadsheetDisplayValue=Qv;exports.formulasForPaste=vl;exports.freezeStateFromPane=uS;exports.freezeStateFromSheet=Gi;exports.getNativeWordCommandState=cp;exports.getRenderCell=qe;exports.getWordChangeSet=MI;exports.getWordSelectionInfo=AI;exports.hitSpreadsheetResizeHandle=Rl;exports.imageOffset=Si;exports.isPptShapeEditable=xP;exports.layoutNativePageAnnotationBubbles=mx;exports.loadOfficeFonts=Mr;exports.measureNativeDocumentReflowFromParagraph=As;exports.moveSelection=BN;exports.nativeAddComment=Ss;exports.nativeAddFormatRevision=pu;exports.nativeAddRevision=$t;exports.nativeAnchorLayoutMetadata=$x;exports.nativeBlockClipboardText=Ks;exports.nativeClearRunFormat=uu;exports.nativeClearTableCellRange=Zc;exports.nativeCopyBlockRange=xs;exports.nativeCursorFromPoint=uf;exports.nativeDeleteBackward=zr;exports.nativeDeleteComment=lu;exports.nativeDeleteForward=Vr;exports.nativeDeleteImage=fu;exports.nativeDeleteRange=bn;exports.nativeDeleteTable=Kc;exports.nativeDeleteTextRangeAcrossParagraphs=fi;exports.nativeDrawingWidthCss=Lx;exports.nativeEditTableStructure=_c;exports.nativeInsertImage=eu;exports.nativeInsertPageBreak=tu;exports.nativeInsertTable=Uc;exports.nativeInsertText=on;exports.nativeLineStrokeStyle=Mx;exports.nativeListIndent=Oc;exports.nativeListType=hn;exports.nativeMergeTableCells=qc;exports.nativeNumberingAtLevel=ps;exports.nativePageBreakAt=ui;exports.nativeParagraphText=Te;exports.nativeRangeContainsPageBreak=nu;exports.nativeReplaceBlockRangeAcrossParagraphs=ou;exports.nativeReplaceRange=Gr;exports.nativeReplaceRangeWithBlocks=iu;exports.nativeReplaceTableCellRangeContent=Qc;exports.nativeReplaceTableCellRangeText=Jc;exports.nativeReplaceTextRangeAcrossParagraphs=au;exports.nativeReplaceTextRangeWithParagraphs=ys;exports.nativeResolveFormatRevision=cu;exports.nativeResolveImageFormatRevision=hu;exports.nativeResolveImageRevision=mu;exports.nativeResolveRevision=du;exports.nativeSelection=Tt;exports.nativeSelectionFromCursor=lt;exports.nativeSetHyperlink=ks;exports.nativeSetImageSize=ru;exports.nativeSetParagraphFormat=er;exports.nativeSetParagraphList=jr;exports.nativeSetRunFormat=vs;exports.nativeSetTableCellFormat=bs;exports.nativeSetTableCellRangeFormat=Yc;exports.nativeSplitParagraph=Cs;exports.nativeSplitTableCell=Xc;exports.nativeSyncParagraphText=Ur;exports.nativeTableCellsInRange=tt;exports.nativeTableSupportsStructuralEditing=$r;exports.nativeTextRangeIsBold=KE;exports.nativeUpdateComment=su;exports.nextSpreadsheetMatch=lT;exports.normalizePptGeometry=ko;exports.normalizeSelectionRange=Le;exports.paginateNativeDocument=Lu;exports.parentNativeParagraph=Nt;exports.parseNativeBlockClipboard=yf;exports.parseNativeClipboardHtml=xf;exports.parseTsv=Wp;exports.planWordOoxmlPatch=iy;exports.planWordOoxmlPatches=oy;exports.pptSceneGeometryToSourceGeometry=km;exports.pptSceneNodeCapabilities=Sm;exports.previewSpreadsheetAgentAction=PT;exports.previousNativeParagraphId=ls;exports.rangeAddressForMatrix=UN;exports.rangeForSpreadsheetMatch=dT;exports.readSpreadsheetClipboardPayload=wl;exports.rebuildNativeTableFragmentsFromParagraph=Vt;exports.reflowNativeDocumentFromParagraph=Wu;exports.refreshNativeNumberingLabels=si;exports.refreshNativePageCommentBubbles=yn;exports.renderNativeBlock=Jr;exports.renderNativeDocument=Mu;exports.renderNativeImage=Ds;exports.renderNativeParagraph=Qr;exports.renderNativePptEditor=FP;exports.renderNativeTable=df;exports.renderNativeWordEditor=rN;exports.renderNormalizedDocumentHtmlPage=AE;exports.renderSpreadsheetEditor=hP;exports.resolveNativeSectionPageNumberStarts=vx;exports.resolveNativeTableCellBorders=Ux;exports.resolveOfficeFontFamily=qt;exports.resolveParagraphStyle=Dr;exports.resolveRunStyle=Jn;exports.resolveSpreadsheetCellStyle=ho;exports.resolveSpreadsheetRangeBorder=Tp;exports.resolveTableCellStyle=ni;exports.resolveWordOoxmlPatchTargets=ay;exports.restoreNativeCursor=dt;exports.restoreNativeElementSelection=ff;exports.restoreNativeTextSelection=vn;exports.rowColumnKey=Di;exports.scrollFromThumbPosition=ea;exports.searchNativeWordDocument=zs;exports.selectNativeImage=mf;exports.selectionAfterColumnDeletion=FN;exports.selectionAfterRowDeletion=DN;exports.serializeNativeBlockClipboard=Us;exports.serializeNativeClipboardHtml=js;exports.serializeRangeToTsv=WS;exports.serializeSpreadsheetClipboardPayload=xo;exports.setColor=BI;exports.setFontSize=WI;exports.setParagraphAlign=DI;exports.setSpreadsheetCellFormula=tT;exports.setSpreadsheetCellValue=eT;exports.setSpreadsheetColumnWidth=iT;exports.setSpreadsheetRangeValues=nT;exports.setSpreadsheetRowHeight=oT;exports.splitNativeTableRowAtBlockBoundary=FE;exports.splitNativeTableRowAtTextOffset=HE;exports.spreadsheetFilterValues=Il;exports.spreadsheetRowsForColumnFilters=Kp;exports.spreadsheetRowsForFilter=Up;exports.spreadsheetSortRows=_p;exports.spreadsheetVisibleFilterValues=fT;exports.startSpreadsheetResizeDrag=am;exports.summarizeEditorCoverage=Ib;exports.summarizeNativeCoverage=IE;exports.summarizeNativeTablePagination=DE;exports.summarizeSpreadsheetSelectionFormat=VT;exports.supportsSpreadsheetAutoFill=Cl;exports.toggleBold=LI;exports.updateSpreadsheetResizeDrag=Ml;exports.wordEditingPluginKey=io;